Merge branch 'for-linus/i2c-3.2' of git://git.fluff.org/bjdooks/linux
authorLinus Torvalds <torvalds@linux-foundation.org>
Tue, 1 Nov 2011 22:07:19 +0000 (15:07 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 1 Nov 2011 22:07:19 +0000 (15:07 -0700)
* 'for-linus/i2c-3.2' of git://git.fluff.org/bjdooks/linux: (47 commits)
  i2c-s3c2410: Add device tree support
  i2c-s3c2410: Keep a copy of platform data and use it
  i2c-nomadik: cosmetic coding style corrections
  i2c-au1550: dev_pm_ops conversion
  i2c-au1550: increase timeout waiting for master done
  i2c-au1550: remove unused ack_timeout
  i2c-au1550: remove usage of volatile keyword
  i2c-tegra: __iomem annotation fix
  i2c-eg20t: Add initialize processing in case i2c-error occurs
  i2c-eg20t: Fix flag setting issue
  i2c-eg20t: add stop sequence in case wait-event timeout occurs
  i2c-eg20t: Separate error processing
  i2c-eg20t: Fix 10bit access issue
  i2c-eg20t: Modify returned value s32 to long
  i2c-eg20t: Fix bus-idle waiting issue
  i2c-designware: Fix PCI core warning on suspend/resume
  i2c-designware: Add runtime power management support
  i2c-designware: Add support for Designware core behind PCI devices.
  i2c-designware: Push all register reads/writes into the core code.
  i2c-designware: Support multiple cores using same ISR
  ...

2032 files changed:
Documentation/ABI/testing/debugfs-ideapad [new file with mode: 0644]
Documentation/ABI/testing/sysfs-block
Documentation/ABI/testing/sysfs-platform-ideapad-laptop
Documentation/DocBook/media/dvb/dvbproperty.xml
Documentation/DocBook/media/dvb/intro.xml
Documentation/DocBook/media/v4l/compat.xml
Documentation/DocBook/media/v4l/dev-subdev.xml
Documentation/DocBook/media/v4l/v4l2.xml
Documentation/DocBook/media/v4l/vidioc-dqevent.xml
Documentation/DocBook/media/v4l/vidioc-queryctrl.xml
Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
Documentation/DocBook/writing-an-alsa-driver.tmpl
Documentation/devicetree/bindings/crypto/picochip-spacc.txt [new file with mode: 0644]
Documentation/devicetree/bindings/mmc/nvidia-sdhci.txt [new file with mode: 0644]
Documentation/devicetree/bindings/sound/soc/codecs/fsl-sgtl5000.txt [new file with mode: 0644]
Documentation/devicetree/bindings/sound/wm8510.txt [new file with mode: 0644]
Documentation/devicetree/bindings/sound/wm8523.txt [new file with mode: 0644]
Documentation/devicetree/bindings/sound/wm8580.txt [new file with mode: 0644]
Documentation/devicetree/bindings/sound/wm8711.txt [new file with mode: 0644]
Documentation/devicetree/bindings/sound/wm8728.txt [new file with mode: 0644]
Documentation/devicetree/bindings/sound/wm8731.txt [new file with mode: 0644]
Documentation/devicetree/bindings/sound/wm8737.txt [new file with mode: 0644]
Documentation/devicetree/bindings/sound/wm8741.txt [new file with mode: 0644]
Documentation/devicetree/bindings/sound/wm8750.txt [new file with mode: 0644]
Documentation/devicetree/bindings/sound/wm8753.txt [new file with mode: 0644]
Documentation/devicetree/bindings/sound/wm8770.txt [new file with mode: 0644]
Documentation/devicetree/bindings/sound/wm8776.txt [new file with mode: 0644]
Documentation/devicetree/bindings/sound/wm8804.txt [new file with mode: 0644]
Documentation/dvb/get_dvb_firmware
Documentation/dvb/it9137.txt [new file with mode: 0644]
Documentation/fault-injection/fault-injection.txt
Documentation/fb/udlfb.txt
Documentation/feature-removal-schedule.txt
Documentation/i2c/smbus-protocol
Documentation/kernel-parameters.txt
Documentation/networking/LICENSE.qlcnic
Documentation/power/regulator/machine.txt
Documentation/scsi/00-INDEX
Documentation/scsi/ChangeLog.megaraid_sas
Documentation/scsi/LICENSE.qla4xxx [new file with mode: 0644]
Documentation/scsi/bnx2fc.txt [new file with mode: 0644]
Documentation/sound/alsa/ALSA-Configuration.txt
Documentation/sound/alsa/HD-Audio-Controls.txt
Documentation/sound/alsa/HD-Audio-Models.txt
Documentation/sound/alsa/HD-Audio.txt
Documentation/sysctl/kernel.txt
Documentation/trace/postprocess/trace-vmscan-postprocess.pl
Documentation/video4linux/CARDLIST.tm6000 [moved from drivers/staging/tm6000/CARDLIST with 100% similarity]
Documentation/video4linux/gspca.txt
Documentation/video4linux/omap3isp.txt
Documentation/video4linux/v4l2-controls.txt
Documentation/virtual/kvm/api.txt
MAINTAINERS
arch/alpha/include/asm/unistd.h
arch/alpha/kernel/systbls.S
arch/arm/mach-at91/at91sam9260_devices.c
arch/arm/mach-ep93xx/edb93xx.c
arch/arm/mach-ep93xx/simone.c
arch/arm/mach-ep93xx/snappercl15.c
arch/arm/mach-imx/mach-mx27_3ds.c
arch/arm/mach-imx/mach-mx31_3ds.c
arch/arm/mach-lpc32xx/include/mach/gpio.h
arch/arm/mach-msm/devices-msm7x00.c
arch/arm/mach-msm/devices-qsd8x50.c
arch/arm/mach-msm/include/mach/mmc.h
arch/arm/mach-omap2/board-2430sdp.c
arch/arm/mach-omap2/board-3430sdp.c
arch/arm/mach-omap2/board-4430sdp.c
arch/arm/mach-omap2/board-am3517evm.c
arch/arm/mach-omap2/board-apollon.c
arch/arm/mach-omap2/board-cm-t35.c
arch/arm/mach-omap2/board-devkit8000.c
arch/arm/mach-omap2/board-h4.c
arch/arm/mach-omap2/board-igep0020.c
arch/arm/mach-omap2/board-ldp.c
arch/arm/mach-omap2/board-omap3beagle.c
arch/arm/mach-omap2/board-omap3evm.c
arch/arm/mach-omap2/board-omap3pandora.c
arch/arm/mach-omap2/board-omap3stalker.c
arch/arm/mach-omap2/board-omap3touchbook.c
arch/arm/mach-omap2/board-omap4panda.c
arch/arm/mach-omap2/board-overo.c
arch/arm/mach-omap2/board-rx51-peripherals.c
arch/arm/mach-omap2/board-rx51.c
arch/arm/mach-omap2/devices.c
arch/arm/mach-omap2/display.c
arch/arm/mach-omap2/iommu2.c
arch/arm/mach-omap2/omap_hwmod_44xx_data.c
arch/arm/mach-omap2/twl-common.c
arch/arm/mach-shmobile/board-ag5evm.c
arch/arm/mach-shmobile/board-mackerel.c
arch/arm/mach-tegra/include/mach/gpio.h
arch/arm/mach-u300/include/mach/gpio.h
arch/arm/mach-vexpress/include/mach/gpio.h [new file with mode: 0644]
arch/arm/plat-nomadik/include/plat/gpio-nomadik.h
arch/arm/plat-omap/Kconfig
arch/arm/plat-omap/Makefile
arch/arm/plat-omap/devices.c
arch/arm/plat-omap/include/plat/iommu.h
arch/arm/plat-omap/include/plat/iommu2.h
arch/arm/plat-omap/include/plat/iopgtable.h [moved from arch/arm/plat-omap/iopgtable.h with 82% similarity]
arch/arm/plat-omap/include/plat/iovmm.h
arch/arm/plat-omap/include/plat/mmc.h
arch/cris/arch-v10/kernel/kgdb.c
arch/cris/arch-v32/kernel/kgdb.c
arch/frv/kernel/gdb-stub.c
arch/h8300/include/asm/gpio-internal.h [moved from arch/h8300/include/asm/gpio.h with 100% similarity]
arch/h8300/platform/h8300h/irq.c
arch/h8300/platform/h8s/irq.c
arch/hexagon/Kconfig [new file with mode: 0644]
arch/hexagon/Makefile [new file with mode: 0644]
arch/hexagon/configs/comet_defconfig [new file with mode: 0644]
arch/hexagon/include/asm/Kbuild [new file with mode: 0644]
arch/hexagon/include/asm/asm-offsets.h [new file with mode: 0644]
arch/hexagon/include/asm/atomic.h [new file with mode: 0644]
arch/hexagon/include/asm/bitops.h [new file with mode: 0644]
arch/hexagon/include/asm/bitsperlong.h [new file with mode: 0644]
arch/hexagon/include/asm/byteorder.h [new file with mode: 0644]
arch/hexagon/include/asm/cache.h [new file with mode: 0644]
arch/hexagon/include/asm/cacheflush.h [new file with mode: 0644]
arch/hexagon/include/asm/checksum.h [new file with mode: 0644]
arch/hexagon/include/asm/delay.h [new file with mode: 0644]
arch/hexagon/include/asm/dma-mapping.h [new file with mode: 0644]
arch/hexagon/include/asm/dma.h [new file with mode: 0644]
arch/hexagon/include/asm/elf.h [new file with mode: 0644]
arch/hexagon/include/asm/fixmap.h [new file with mode: 0644]
arch/hexagon/include/asm/fpu.h [new file with mode: 0644]
arch/hexagon/include/asm/futex.h [new file with mode: 0644]
arch/hexagon/include/asm/hexagon_vm.h [new file with mode: 0644]
arch/hexagon/include/asm/intrinsics.h [new file with mode: 0644]
arch/hexagon/include/asm/io.h [new file with mode: 0644]
arch/hexagon/include/asm/irq.h [new file with mode: 0644]
arch/hexagon/include/asm/irqflags.h [new file with mode: 0644]
arch/hexagon/include/asm/kgdb.h [new file with mode: 0644]
arch/hexagon/include/asm/linkage.h [new file with mode: 0644]
arch/hexagon/include/asm/mem-layout.h [new file with mode: 0644]
arch/hexagon/include/asm/mmu.h [new file with mode: 0644]
arch/hexagon/include/asm/mmu_context.h [new file with mode: 0644]
arch/hexagon/include/asm/module.h [new file with mode: 0644]
arch/hexagon/include/asm/mutex.h [new file with mode: 0644]
arch/hexagon/include/asm/page.h [new file with mode: 0644]
arch/hexagon/include/asm/param.h [new file with mode: 0644]
arch/hexagon/include/asm/perf_event.h [new file with mode: 0644]
arch/hexagon/include/asm/pgalloc.h [new file with mode: 0644]
arch/hexagon/include/asm/pgtable.h [new file with mode: 0644]
arch/hexagon/include/asm/processor.h [new file with mode: 0644]
arch/hexagon/include/asm/ptrace.h [new file with mode: 0644]
arch/hexagon/include/asm/registers.h [new file with mode: 0644]
arch/hexagon/include/asm/setup.h [new file with mode: 0644]
arch/hexagon/include/asm/sigcontext.h [new file with mode: 0644]
arch/hexagon/include/asm/signal.h [new file with mode: 0644]
arch/hexagon/include/asm/smp.h [new file with mode: 0644]
arch/hexagon/include/asm/spinlock.h [new file with mode: 0644]
arch/hexagon/include/asm/spinlock_types.h [new file with mode: 0644]
arch/hexagon/include/asm/string.h [new file with mode: 0644]
arch/hexagon/include/asm/suspend.h [new file with mode: 0644]
arch/hexagon/include/asm/swab.h [new file with mode: 0644]
arch/hexagon/include/asm/syscall.h [new file with mode: 0644]
arch/hexagon/include/asm/system.h [new file with mode: 0644]
arch/hexagon/include/asm/thread_info.h [new file with mode: 0644]
arch/hexagon/include/asm/time.h [new file with mode: 0644]
arch/hexagon/include/asm/timer-regs.h [new file with mode: 0644]
arch/hexagon/include/asm/timex.h [new file with mode: 0644]
arch/hexagon/include/asm/tlb.h [new file with mode: 0644]
arch/hexagon/include/asm/tlbflush.h [new file with mode: 0644]
arch/hexagon/include/asm/traps.h [new file with mode: 0644]
arch/hexagon/include/asm/uaccess.h [new file with mode: 0644]
arch/hexagon/include/asm/unistd.h [new file with mode: 0644]
arch/hexagon/include/asm/user.h [new file with mode: 0644]
arch/hexagon/include/asm/vdso.h [new file with mode: 0644]
arch/hexagon/include/asm/vm_fault.h [new file with mode: 0644]
arch/hexagon/include/asm/vm_mmu.h [new file with mode: 0644]
arch/hexagon/kernel/Makefile [new file with mode: 0644]
arch/hexagon/kernel/asm-offsets.c [new file with mode: 0644]
arch/hexagon/kernel/dma.c [new file with mode: 0644]
arch/hexagon/kernel/head.S [new file with mode: 0644]
arch/hexagon/kernel/hexagon_ksyms.c [new file with mode: 0644]
arch/hexagon/kernel/init_task.c [new file with mode: 0644]
arch/hexagon/kernel/irq_cpu.c [new file with mode: 0644]
arch/hexagon/kernel/kgdb.c [new file with mode: 0644]
arch/hexagon/kernel/module.c [new file with mode: 0644]
arch/hexagon/kernel/process.c [new file with mode: 0644]
arch/hexagon/kernel/ptrace.c [new file with mode: 0644]
arch/hexagon/kernel/reset.c [new file with mode: 0644]
arch/hexagon/kernel/setup.c [new file with mode: 0644]
arch/hexagon/kernel/signal.c [new file with mode: 0644]
arch/hexagon/kernel/smp.c [new file with mode: 0644]
arch/hexagon/kernel/stacktrace.c [new file with mode: 0644]
arch/hexagon/kernel/syscall.c [new file with mode: 0644]
arch/hexagon/kernel/syscalltab.c [new file with mode: 0644]
arch/hexagon/kernel/time.c [new file with mode: 0644]
arch/hexagon/kernel/topology.c [new file with mode: 0644]
arch/hexagon/kernel/trampoline.S [new file with mode: 0644]
arch/hexagon/kernel/traps.c [new file with mode: 0644]
arch/hexagon/kernel/vdso.c [new file with mode: 0644]
arch/hexagon/kernel/vm_entry.S [new file with mode: 0644]
arch/hexagon/kernel/vm_events.c [new file with mode: 0644]
arch/hexagon/kernel/vm_init_segtable.S [new file with mode: 0644]
arch/hexagon/kernel/vm_ops.S [new file with mode: 0644]
arch/hexagon/kernel/vm_switch.S [new file with mode: 0644]
arch/hexagon/kernel/vm_vectors.S [new file with mode: 0644]
arch/hexagon/kernel/vmlinux.lds.S [new file with mode: 0644]
arch/hexagon/lib/Makefile [new file with mode: 0644]
arch/hexagon/lib/checksum.c [new file with mode: 0644]
arch/hexagon/lib/io.c [new file with mode: 0644]
arch/hexagon/lib/memcpy.S [new file with mode: 0644]
arch/hexagon/lib/memset.S [new file with mode: 0644]
arch/hexagon/mm/Makefile [new file with mode: 0644]
arch/hexagon/mm/cache.c [new file with mode: 0644]
arch/hexagon/mm/copy_from_user.S [new file with mode: 0644]
arch/hexagon/mm/copy_to_user.S [new file with mode: 0644]
arch/hexagon/mm/copy_user_template.S [new file with mode: 0644]
arch/hexagon/mm/init.c [new file with mode: 0644]
arch/hexagon/mm/ioremap.c [new file with mode: 0644]
arch/hexagon/mm/pgalloc.c [new file with mode: 0644]
arch/hexagon/mm/strnlen_user.S [new file with mode: 0644]
arch/hexagon/mm/uaccess.c [new file with mode: 0644]
arch/hexagon/mm/vm_fault.c [new file with mode: 0644]
arch/hexagon/mm/vm_tlb.c [new file with mode: 0644]
arch/ia64/kvm/kvm-ia64.c
arch/microblaze/include/asm/dma-mapping.h
arch/microblaze/include/asm/elf.h
arch/microblaze/include/asm/system.h
arch/microblaze/include/asm/uaccess.h
arch/microblaze/kernel/cpu/cpuinfo.c
arch/microblaze/kernel/dma.c
arch/microblaze/kernel/exceptions.c
arch/microblaze/kernel/process.c
arch/microblaze/kernel/ptrace.c
arch/microblaze/kernel/timer.c
arch/microblaze/lib/Makefile
arch/microblaze/lib/uaccess_old.S
arch/microblaze/lib/ucmpdi2.c [new file with mode: 0644]
arch/mips/alchemy/devboards/db1200/platform.c
arch/mips/alchemy/devboards/db1x00/platform.c
arch/mn10300/kernel/gdb-stub.c
arch/powerpc/include/asm/kvm.h
arch/powerpc/include/asm/kvm_book3s.h
arch/powerpc/include/asm/kvm_book3s_asm.h
arch/powerpc/include/asm/kvm_host.h
arch/powerpc/include/asm/kvm_ppc.h
arch/powerpc/include/asm/systbl.h
arch/powerpc/include/asm/unistd.h
arch/powerpc/kernel/asm-offsets.c
arch/powerpc/kernel/exceptions-64s.S
arch/powerpc/kvm/44x.c
arch/powerpc/kvm/Makefile
arch/powerpc/kvm/book3s_32_sr.S
arch/powerpc/kvm/book3s_64_mmu.c
arch/powerpc/kvm/book3s_64_slb.S
arch/powerpc/kvm/book3s_emulate.c
arch/powerpc/kvm/book3s_exports.c
arch/powerpc/kvm/book3s_hv.c
arch/powerpc/kvm/book3s_hv_rm_mmu.c
arch/powerpc/kvm/book3s_hv_rmhandlers.S
arch/powerpc/kvm/book3s_interrupts.S
arch/powerpc/kvm/book3s_pr.c
arch/powerpc/kvm/book3s_pr_papr.c [new file with mode: 0644]
arch/powerpc/kvm/book3s_rmhandlers.S
arch/powerpc/kvm/book3s_segment.S
arch/powerpc/kvm/booke.c
arch/powerpc/kvm/e500.c
arch/powerpc/kvm/powerpc.c
arch/powerpc/platforms/512x/mpc512x_shared.c
arch/powerpc/platforms/85xx/p1022_ds.c
arch/powerpc/platforms/86xx/mpc8610_hpcd.c
arch/powerpc/sysdev/fsl_soc.h
arch/s390/Kconfig
arch/s390/boot/compressed/misc.c
arch/s390/defconfig
arch/s390/include/asm/ccwdev.h
arch/s390/include/asm/compat.h
arch/s390/include/asm/ipl.h
arch/s390/include/asm/irq.h
arch/s390/include/asm/kexec.h
arch/s390/include/asm/kvm_host.h
arch/s390/include/asm/lowcore.h
arch/s390/include/asm/page.h
arch/s390/include/asm/pgtable.h
arch/s390/include/asm/processor.h
arch/s390/include/asm/ptrace.h
arch/s390/include/asm/qdio.h
arch/s390/include/asm/reset.h
arch/s390/include/asm/setup.h
arch/s390/include/asm/sfp-util.h
arch/s390/include/asm/smp.h
arch/s390/include/asm/spinlock.h
arch/s390/include/asm/syscall.h
arch/s390/include/asm/system.h
arch/s390/include/asm/thread_info.h
arch/s390/include/asm/timex.h
arch/s390/include/asm/tlbflush.h
arch/s390/kernel/Makefile
arch/s390/kernel/asm-offsets.c
arch/s390/kernel/base.S
arch/s390/kernel/compat_linux.c
arch/s390/kernel/compat_signal.c
arch/s390/kernel/compat_wrapper.S
arch/s390/kernel/crash_dump.c [new file with mode: 0644]
arch/s390/kernel/early.c
arch/s390/kernel/entry.S
arch/s390/kernel/entry.h
arch/s390/kernel/entry64.S
arch/s390/kernel/head.S
arch/s390/kernel/head31.S
arch/s390/kernel/head64.S
arch/s390/kernel/head_kdump.S [new file with mode: 0644]
arch/s390/kernel/ipl.c
arch/s390/kernel/irq.c
arch/s390/kernel/kprobes.c
arch/s390/kernel/machine_kexec.c
arch/s390/kernel/mem_detect.c
arch/s390/kernel/process.c
arch/s390/kernel/processor.c
arch/s390/kernel/ptrace.c
arch/s390/kernel/reipl.S
arch/s390/kernel/reipl64.S
arch/s390/kernel/setup.c
arch/s390/kernel/signal.c
arch/s390/kernel/smp.c
arch/s390/kernel/suspend.c
arch/s390/kernel/sysinfo.c
arch/s390/kernel/time.c
arch/s390/kernel/topology.c
arch/s390/kernel/traps.c
arch/s390/kernel/vtime.c
arch/s390/kvm/diag.c
arch/s390/kvm/interrupt.c
arch/s390/kvm/kvm-s390.c
arch/s390/kvm/sigp.c
arch/s390/lib/delay.c
arch/s390/lib/uaccess_pt.c
arch/s390/mm/fault.c
arch/s390/mm/maccess.c
arch/s390/mm/mmap.c
arch/s390/mm/pageattr.c
arch/s390/mm/pgtable.c
arch/s390/mm/vmem.c
arch/s390/oprofile/hwsampler.c
arch/sparc/kernel/visemul.c
arch/sparc/lib/memcpy.S
arch/x86/crypto/Makefile
arch/x86/crypto/aes_glue.c
arch/x86/crypto/blowfish-x86_64-asm_64.S [new file with mode: 0644]
arch/x86/crypto/blowfish_glue.c [new file with mode: 0644]
arch/x86/crypto/sha1_ssse3_asm.S [new file with mode: 0644]
arch/x86/crypto/sha1_ssse3_glue.c [new file with mode: 0644]
arch/x86/crypto/twofish-i586-asm_32.S
arch/x86/crypto/twofish-x86_64-asm_64-3way.S [new file with mode: 0644]
arch/x86/crypto/twofish-x86_64-asm_64.S
arch/x86/crypto/twofish_glue.c
arch/x86/crypto/twofish_glue_3way.c [new file with mode: 0644]
arch/x86/ia32/ia32entry.S
arch/x86/include/asm/apicdef.h
arch/x86/include/asm/cpufeature.h
arch/x86/include/asm/kvm_emulate.h
arch/x86/include/asm/kvm_host.h
arch/x86/include/asm/msr-index.h
arch/x86/include/asm/pci_x86.h
arch/x86/include/asm/unistd_32.h
arch/x86/include/asm/unistd_64.h
arch/x86/include/asm/vmx.h
arch/x86/kernel/syscall_table_32.S
arch/x86/kvm/emulate.c
arch/x86/kvm/i8254.c
arch/x86/kvm/i8259.c
arch/x86/kvm/irq.h
arch/x86/kvm/kvm_cache_regs.h
arch/x86/kvm/kvm_timer.h
arch/x86/kvm/lapic.c
arch/x86/kvm/lapic.h
arch/x86/kvm/mmu.c
arch/x86/kvm/mmu_audit.c
arch/x86/kvm/paging_tmpl.h
arch/x86/kvm/svm.c
arch/x86/kvm/trace.h
arch/x86/kvm/vmx.c
arch/x86/kvm/x86.c
arch/x86/lguest/boot.c
arch/x86/pci/ce4100.c
arch/x86/pci/common.c
arch/x86/pci/direct.c
arch/x86/pci/mmconfig_32.c
arch/x86/pci/mmconfig_64.c
arch/x86/pci/numaq_32.c
arch/x86/pci/olpc.c
arch/x86/pci/pcbios.c
block/genhd.c
crypto/Kconfig
crypto/Makefile
crypto/ablkcipher.c
crypto/aead.c
crypto/ahash.c
crypto/algapi.c
crypto/blkcipher.c
crypto/blowfish_common.c [moved from crypto/blowfish.c with 87% similarity]
crypto/blowfish_generic.c [new file with mode: 0644]
crypto/cryptd.c
crypto/crypto_user.c [new file with mode: 0644]
crypto/internal.h
crypto/pcompress.c
crypto/rng.c
crypto/sha1_generic.c
crypto/shash.c
crypto/tcrypt.c
crypto/testmgr.c
crypto/testmgr.h
crypto/wp512.c
drivers/acpi/apei/erst.c
drivers/acpi/osl.c
drivers/ata/libata-core.c
drivers/ata/libata-scsi.c
drivers/block/rbd.c
drivers/crypto/Kconfig
drivers/crypto/hifn_795x.c
drivers/crypto/n2_core.c
drivers/crypto/padlock-aes.c
drivers/crypto/picoxcell_crypto.c
drivers/crypto/talitos.c
drivers/edac/amd64_edac.c
drivers/edac/mce_amd.c
drivers/edac/mce_amd.h
drivers/firewire/core-transaction.c
drivers/firewire/net.c
drivers/firewire/ohci.c
drivers/firewire/sbp2.c
drivers/firmware/efivars.c
drivers/gpio/Kconfig
drivers/gpio/gpio-langwell.c
drivers/gpio/gpio-ml-ioh.c
drivers/gpio/gpio-mxc.c
drivers/gpio/gpio-nomadik.c
drivers/gpio/gpio-pch.c
drivers/gpio/gpio-pl061.c
drivers/hwmon/hwmon.c
drivers/hwmon/ibmaem.c
drivers/i2c/algos/i2c-algo-bit.c
drivers/i2c/algos/i2c-algo-pca.c
drivers/i2c/busses/Kconfig
drivers/i2c/busses/scx200_acb.c
drivers/infiniband/core/cm.c
drivers/infiniband/core/cm_msgs.h
drivers/infiniband/core/cma.c
drivers/infiniband/core/mad.c
drivers/infiniband/core/sysfs.c
drivers/infiniband/core/ucm.c
drivers/infiniband/core/ucma.c
drivers/infiniband/core/umem.c
drivers/infiniband/core/user_mad.c
drivers/infiniband/core/uverbs.h
drivers/infiniband/core/uverbs_cmd.c
drivers/infiniband/core/uverbs_main.c
drivers/infiniband/core/verbs.c
drivers/infiniband/hw/amso1100/c2_ae.c
drivers/infiniband/hw/amso1100/c2_intr.c
drivers/infiniband/hw/amso1100/c2_provider.c
drivers/infiniband/hw/cxgb3/iwch_cm.c
drivers/infiniband/hw/cxgb3/iwch_ev.c
drivers/infiniband/hw/cxgb3/iwch_provider.c
drivers/infiniband/hw/cxgb3/iwch_provider.h
drivers/infiniband/hw/cxgb3/iwch_qp.c
drivers/infiniband/hw/cxgb4/cm.c
drivers/infiniband/hw/cxgb4/cq.c
drivers/infiniband/hw/cxgb4/device.c
drivers/infiniband/hw/cxgb4/ev.c
drivers/infiniband/hw/cxgb4/iw_cxgb4.h
drivers/infiniband/hw/cxgb4/qp.c
drivers/infiniband/hw/ehca/ehca_eq.c
drivers/infiniband/hw/ehca/ehca_qp.c
drivers/infiniband/hw/ipath/ipath_init_chip.c
drivers/infiniband/hw/ipath/ipath_srq.c
drivers/infiniband/hw/ipath/ipath_user_pages.c
drivers/infiniband/hw/mlx4/main.c
drivers/infiniband/hw/mlx4/mlx4_ib.h
drivers/infiniband/hw/mlx4/qp.c
drivers/infiniband/hw/mlx4/srq.c
drivers/infiniband/hw/mthca/mthca_provider.c
drivers/infiniband/hw/nes/Makefile
drivers/infiniband/hw/nes/nes.c
drivers/infiniband/hw/nes/nes.h
drivers/infiniband/hw/nes/nes_cm.c
drivers/infiniband/hw/nes/nes_cm.h
drivers/infiniband/hw/nes/nes_hw.c
drivers/infiniband/hw/nes/nes_hw.h
drivers/infiniband/hw/nes/nes_mgt.c [new file with mode: 0644]
drivers/infiniband/hw/nes/nes_mgt.h [new file with mode: 0644]
drivers/infiniband/hw/nes/nes_nic.c
drivers/infiniband/hw/nes/nes_utils.c
drivers/infiniband/hw/nes/nes_verbs.c
drivers/infiniband/hw/nes/nes_verbs.h
drivers/infiniband/hw/qib/qib.h
drivers/infiniband/hw/qib/qib_driver.c
drivers/infiniband/hw/qib/qib_file_ops.c
drivers/infiniband/hw/qib/qib_iba6120.c
drivers/infiniband/hw/qib/qib_iba7220.c
drivers/infiniband/hw/qib/qib_iba7322.c
drivers/infiniband/hw/qib/qib_init.c
drivers/infiniband/hw/qib/qib_qp.c
drivers/infiniband/hw/qib/qib_qsfp.c
drivers/infiniband/hw/qib/qib_qsfp.h
drivers/infiniband/hw/qib/qib_rc.c
drivers/infiniband/hw/qib/qib_ruc.c
drivers/infiniband/hw/qib/qib_srq.c
drivers/infiniband/hw/qib/qib_sysfs.c
drivers/infiniband/hw/qib/qib_uc.c
drivers/infiniband/hw/qib/qib_user_pages.c
drivers/infiniband/hw/qib/qib_verbs.c
drivers/infiniband/hw/qib/qib_verbs.h
drivers/infiniband/ulp/ipoib/ipoib_cm.c
drivers/infiniband/ulp/ipoib/ipoib_fs.c
drivers/infiniband/ulp/iser/iscsi_iser.c
drivers/input/misc/Kconfig
drivers/input/misc/Makefile
drivers/input/misc/twl6040-vibra.c
drivers/iommu/Kconfig
drivers/iommu/Makefile
drivers/iommu/amd_iommu.c
drivers/iommu/intel-iommu.c
drivers/iommu/iommu.c
drivers/iommu/msm_iommu.c
drivers/iommu/omap-iommu-debug.c [moved from arch/arm/plat-omap/iommu-debug.c with 91% similarity]
drivers/iommu/omap-iommu.c [moved from arch/arm/plat-omap/iommu.c with 61% similarity]
drivers/iommu/omap-iovmm.c [moved from arch/arm/plat-omap/iovmm.c with 62% similarity]
drivers/isdn/hisax/callc.c
drivers/isdn/hisax/hisax.h
drivers/isdn/hisax/isdnl1.h
drivers/isdn/hisax/isdnl3.c
drivers/isdn/hisax/st5481_d.c
drivers/leds/Kconfig
drivers/leds/Makefile
drivers/leds/led-class.c
drivers/leds/led-triggers.c
drivers/leds/leds-gpio.c
drivers/leds/leds-lm3530.c
drivers/leds/leds-lp5521.c
drivers/leds/leds-renesas-tpu.c [new file with mode: 0644]
drivers/lguest/core.c
drivers/md/raid10.c
drivers/media/common/saa7146_core.c
drivers/media/common/saa7146_fops.c
drivers/media/common/saa7146_hlp.c
drivers/media/common/saa7146_i2c.c
drivers/media/common/saa7146_vbi.c
drivers/media/common/saa7146_video.c
drivers/media/common/tuners/Makefile
drivers/media/common/tuners/mt20xx.c
drivers/media/common/tuners/mxl5005s.c
drivers/media/common/tuners/tda18212.c
drivers/media/common/tuners/tda18271-common.c
drivers/media/common/tuners/tda18271-fe.c
drivers/media/common/tuners/tda18271-priv.h
drivers/media/common/tuners/tda827x.c
drivers/media/common/tuners/tuner-xc2028.c
drivers/media/common/tuners/tuner-xc2028.h
drivers/media/dvb/b2c2/Makefile
drivers/media/dvb/bt8xx/Makefile
drivers/media/dvb/ddbridge/Makefile
drivers/media/dvb/ddbridge/ddbridge-core.c
drivers/media/dvb/dm1105/Makefile
drivers/media/dvb/dvb-core/dvb_frontend.c
drivers/media/dvb/dvb-core/dvb_frontend.h
drivers/media/dvb/dvb-usb/Kconfig
drivers/media/dvb/dvb-usb/Makefile
drivers/media/dvb/dvb-usb/a800.c
drivers/media/dvb/dvb-usb/af9005-fe.c
drivers/media/dvb/dvb-usb/af9005.c
drivers/media/dvb/dvb-usb/af9015.c
drivers/media/dvb/dvb-usb/anysee.c
drivers/media/dvb/dvb-usb/anysee.h
drivers/media/dvb/dvb-usb/au6610.c
drivers/media/dvb/dvb-usb/az6027.c
drivers/media/dvb/dvb-usb/ce6230.c
drivers/media/dvb/dvb-usb/cinergyT2-core.c
drivers/media/dvb/dvb-usb/cxusb.c
drivers/media/dvb/dvb-usb/dib0700_core.c
drivers/media/dvb/dvb-usb/dib0700_devices.c
drivers/media/dvb/dvb-usb/dibusb-common.c
drivers/media/dvb/dvb-usb/dibusb-mb.c
drivers/media/dvb/dvb-usb/dibusb-mc.c
drivers/media/dvb/dvb-usb/digitv.c
drivers/media/dvb/dvb-usb/dtt200u.c
drivers/media/dvb/dvb-usb/dtv5100.c
drivers/media/dvb/dvb-usb/dvb-usb-dvb.c
drivers/media/dvb/dvb-usb/dvb-usb-ids.h
drivers/media/dvb/dvb-usb/dvb-usb-init.c
drivers/media/dvb/dvb-usb/dvb-usb-urb.c
drivers/media/dvb/dvb-usb/dvb-usb.h
drivers/media/dvb/dvb-usb/dw2102.c
drivers/media/dvb/dvb-usb/ec168.c
drivers/media/dvb/dvb-usb/friio.c
drivers/media/dvb/dvb-usb/gl861.c
drivers/media/dvb/dvb-usb/gp8psk-fe.c
drivers/media/dvb/dvb-usb/gp8psk.c
drivers/media/dvb/dvb-usb/it913x.c [new file with mode: 0644]
drivers/media/dvb/dvb-usb/lmedm04.c
drivers/media/dvb/dvb-usb/m920x.c
drivers/media/dvb/dvb-usb/mxl111sf-gpio.c [new file with mode: 0644]
drivers/media/dvb/dvb-usb/mxl111sf-gpio.h [new file with mode: 0644]
drivers/media/dvb/dvb-usb/mxl111sf-i2c.c [new file with mode: 0644]
drivers/media/dvb/dvb-usb/mxl111sf-i2c.h [new file with mode: 0644]
drivers/media/dvb/dvb-usb/mxl111sf-phy.c [new file with mode: 0644]
drivers/media/dvb/dvb-usb/mxl111sf-phy.h [new file with mode: 0644]
drivers/media/dvb/dvb-usb/mxl111sf-reg.h [new file with mode: 0644]
drivers/media/dvb/dvb-usb/mxl111sf-tuner.c [new file with mode: 0644]
drivers/media/dvb/dvb-usb/mxl111sf-tuner.h [new file with mode: 0644]
drivers/media/dvb/dvb-usb/mxl111sf.c [new file with mode: 0644]
drivers/media/dvb/dvb-usb/mxl111sf.h [new file with mode: 0644]
drivers/media/dvb/dvb-usb/nova-t-usb2.c
drivers/media/dvb/dvb-usb/opera1.c
drivers/media/dvb/dvb-usb/pctv452e.c [new file with mode: 0644]
drivers/media/dvb/dvb-usb/technisat-usb2.c
drivers/media/dvb/dvb-usb/ttusb2.c
drivers/media/dvb/dvb-usb/umt-010.c
drivers/media/dvb/dvb-usb/usb-urb.c
drivers/media/dvb/dvb-usb/vp702x.c
drivers/media/dvb/dvb-usb/vp7045.c
drivers/media/dvb/frontends/Kconfig
drivers/media/dvb/frontends/Makefile
drivers/media/dvb/frontends/a8293.c [new file with mode: 0644]
drivers/media/dvb/frontends/a8293.h [moved from drivers/media/common/tuners/tda18212_priv.h with 58% similarity]
drivers/media/dvb/frontends/cxd2820r.h
drivers/media/dvb/frontends/cxd2820r_c.c
drivers/media/dvb/frontends/cxd2820r_core.c
drivers/media/dvb/frontends/cxd2820r_priv.h
drivers/media/dvb/frontends/cxd2820r_t.c
drivers/media/dvb/frontends/cxd2820r_t2.c
drivers/media/dvb/frontends/dib0070.c
drivers/media/dvb/frontends/dib0090.c
drivers/media/dvb/frontends/dib7000m.c
drivers/media/dvb/frontends/dib7000p.c
drivers/media/dvb/frontends/dib8000.c
drivers/media/dvb/frontends/dib9000.c
drivers/media/dvb/frontends/dibx000_common.c
drivers/media/dvb/frontends/dibx000_common.h
drivers/media/dvb/frontends/drxd_hard.c
drivers/media/dvb/frontends/drxk_hard.c
drivers/media/dvb/frontends/it913x-fe-priv.h [new file with mode: 0644]
drivers/media/dvb/frontends/it913x-fe.c [new file with mode: 0644]
drivers/media/dvb/frontends/it913x-fe.h [new file with mode: 0644]
drivers/media/dvb/frontends/lnbp22.c [new file with mode: 0644]
drivers/media/dvb/frontends/lnbp22.h [new file with mode: 0644]
drivers/media/dvb/frontends/stb0899_algo.c
drivers/media/dvb/frontends/stb0899_drv.c
drivers/media/dvb/frontends/stv0288.c
drivers/media/dvb/frontends/stv090x.c
drivers/media/dvb/frontends/tda10048.c
drivers/media/dvb/frontends/tda10048.h
drivers/media/dvb/frontends/tda10071.c [new file with mode: 0644]
drivers/media/dvb/frontends/tda10071.h [new file with mode: 0644]
drivers/media/dvb/frontends/tda10071_priv.h [new file with mode: 0644]
drivers/media/dvb/frontends/tda18271c2dd.c
drivers/media/dvb/mantis/Makefile
drivers/media/dvb/mantis/hopper_cards.c
drivers/media/dvb/mantis/mantis_cards.c
drivers/media/dvb/mantis/mantis_common.h
drivers/media/dvb/mantis/mantis_dma.c
drivers/media/dvb/mantis/mantis_vp1041.c
drivers/media/dvb/ngene/Makefile
drivers/media/dvb/pluto2/Makefile
drivers/media/dvb/pt1/Makefile
drivers/media/dvb/siano/Makefile
drivers/media/dvb/ttpci/Makefile
drivers/media/dvb/ttpci/av7110_v4l.c
drivers/media/dvb/ttpci/budget-av.c
drivers/media/dvb/ttpci/budget-ci.c
drivers/media/dvb/ttpci/budget-core.c
drivers/media/dvb/ttpci/budget.h
drivers/media/dvb/ttpci/ttpci-eeprom.c
drivers/media/dvb/ttpci/ttpci-eeprom.h
drivers/media/dvb/ttusb-budget/Makefile
drivers/media/dvb/ttusb-dec/Makefile
drivers/media/radio/Makefile
drivers/media/radio/radio-si4713.c
drivers/media/radio/radio-wl1273.c
drivers/media/radio/si470x/radio-si470x-usb.c
drivers/media/radio/wl128x/fmdrv_v4l2.c
drivers/media/rc/Kconfig
drivers/media/rc/Makefile
drivers/media/rc/ati_remote.c [moved from drivers/input/misc/ati_remote.c with 77% similarity]
drivers/media/rc/ene_ir.c
drivers/media/rc/ene_ir.h
drivers/media/rc/imon.c
drivers/media/rc/ir-lirc-codec.c
drivers/media/rc/keymaps/Makefile
drivers/media/rc/keymaps/rc-ati-x10.c [new file with mode: 0644]
drivers/media/rc/keymaps/rc-medion-x10.c [new file with mode: 0644]
drivers/media/rc/keymaps/rc-pinnacle-pctv-hd.c
drivers/media/rc/keymaps/rc-snapstream-firefly.c [new file with mode: 0644]
drivers/media/rc/mceusb.c
drivers/media/rc/rc-core-priv.h
drivers/media/rc/rc-main.c
drivers/media/rc/redrat3.c
drivers/media/rc/winbond-cir.c
drivers/media/video/Kconfig
drivers/media/video/Makefile
drivers/media/video/adp1653.c
drivers/media/video/adv7175.c
drivers/media/video/atmel-isi.c
drivers/media/video/au0828/Makefile
drivers/media/video/bt819.c
drivers/media/video/bt8xx/Makefile
drivers/media/video/bt8xx/bttv-cards.c
drivers/media/video/bt8xx/bttv-driver.c
drivers/media/video/bt8xx/bttv-gpio.c
drivers/media/video/bt8xx/bttv-i2c.c
drivers/media/video/bt8xx/bttv-input.c
drivers/media/video/bt8xx/bttv-risc.c
drivers/media/video/bt8xx/bttv-vbi.c
drivers/media/video/bt8xx/bttvp.h
drivers/media/video/cx18/Makefile
drivers/media/video/cx18/cx18-driver.h
drivers/media/video/cx18/cx18-fileops.c
drivers/media/video/cx18/cx18-ioctl.c
drivers/media/video/cx18/cx18-mailbox.c
drivers/media/video/cx18/cx18-streams.c
drivers/media/video/cx231xx/Makefile
drivers/media/video/cx23885/Kconfig
drivers/media/video/cx23885/Makefile
drivers/media/video/cx23885/cx23885-alsa.c [new file with mode: 0644]
drivers/media/video/cx23885/cx23885-cards.c
drivers/media/video/cx23885/cx23885-core.c
drivers/media/video/cx23885/cx23885-dvb.c
drivers/media/video/cx23885/cx23885-i2c.c
drivers/media/video/cx23885/cx23885-reg.h
drivers/media/video/cx23885/cx23885-vbi.c
drivers/media/video/cx23885/cx23885-video.c
drivers/media/video/cx23885/cx23885.h
drivers/media/video/cx23885/cx23888-ir.c
drivers/media/video/cx25840/Makefile
drivers/media/video/cx25840/cx25840-audio.c
drivers/media/video/cx25840/cx25840-core.c
drivers/media/video/cx25840/cx25840-ir.c
drivers/media/video/cx88/Makefile
drivers/media/video/cx88/cx88-core.c
drivers/media/video/cx88/cx88-video.c
drivers/media/video/davinci/vpbe_display.c
drivers/media/video/davinci/vpbe_osd.c
drivers/media/video/em28xx/Kconfig
drivers/media/video/em28xx/Makefile
drivers/media/video/em28xx/em28xx-cards.c
drivers/media/video/em28xx/em28xx-core.c
drivers/media/video/em28xx/em28xx-dvb.c
drivers/media/video/em28xx/em28xx-input.c
drivers/media/video/em28xx/em28xx-video.c
drivers/media/video/em28xx/em28xx.h
drivers/media/video/et61x251/et61x251.h
drivers/media/video/et61x251/et61x251_core.c
drivers/media/video/et61x251/et61x251_tas5130d1b.c
drivers/media/video/gspca/Kconfig
drivers/media/video/gspca/Makefile
drivers/media/video/gspca/benq.c
drivers/media/video/gspca/conex.c
drivers/media/video/gspca/cpia1.c
drivers/media/video/gspca/etoms.c
drivers/media/video/gspca/finepix.c
drivers/media/video/gspca/gl860/Makefile
drivers/media/video/gspca/gl860/gl860.c
drivers/media/video/gspca/gspca.c
drivers/media/video/gspca/gspca.h
drivers/media/video/gspca/jeilinj.c
drivers/media/video/gspca/kinect.c
drivers/media/video/gspca/konica.c
drivers/media/video/gspca/m5602/Makefile
drivers/media/video/gspca/m5602/m5602_core.c
drivers/media/video/gspca/m5602/m5602_mt9m111.c
drivers/media/video/gspca/m5602/m5602_ov7660.c
drivers/media/video/gspca/m5602/m5602_ov9650.c
drivers/media/video/gspca/m5602/m5602_po1030.c
drivers/media/video/gspca/m5602/m5602_s5k4aa.c
drivers/media/video/gspca/m5602/m5602_s5k83a.c
drivers/media/video/gspca/mars.c
drivers/media/video/gspca/mr97310a.c
drivers/media/video/gspca/nw80x.c
drivers/media/video/gspca/ov519.c
drivers/media/video/gspca/ov534.c
drivers/media/video/gspca/ov534_9.c
drivers/media/video/gspca/pac207.c
drivers/media/video/gspca/pac7302.c
drivers/media/video/gspca/pac7311.c
drivers/media/video/gspca/se401.c
drivers/media/video/gspca/sn9c2028.c
drivers/media/video/gspca/sn9c20x.c
drivers/media/video/gspca/sonixj.c
drivers/media/video/gspca/spca1528.c
drivers/media/video/gspca/spca500.c
drivers/media/video/gspca/spca501.c
drivers/media/video/gspca/spca505.c
drivers/media/video/gspca/spca508.c
drivers/media/video/gspca/spca561.c
drivers/media/video/gspca/sq905.c
drivers/media/video/gspca/sq905c.c
drivers/media/video/gspca/sq930x.c
drivers/media/video/gspca/stk014.c
drivers/media/video/gspca/stv0680.c
drivers/media/video/gspca/stv06xx/Makefile
drivers/media/video/gspca/stv06xx/stv06xx.c
drivers/media/video/gspca/stv06xx/stv06xx.h
drivers/media/video/gspca/stv06xx/stv06xx_hdcs.c
drivers/media/video/gspca/stv06xx/stv06xx_pb0100.c
drivers/media/video/gspca/stv06xx/stv06xx_st6422.c
drivers/media/video/gspca/stv06xx/stv06xx_vv6410.c
drivers/media/video/gspca/stv06xx/stv06xx_vv6410.h
drivers/media/video/gspca/sunplus.c
drivers/media/video/gspca/t613.c
drivers/media/video/gspca/topro.c [new file with mode: 0644]
drivers/media/video/gspca/vc032x.c
drivers/media/video/gspca/vicam.c
drivers/media/video/gspca/w996Xcf.c
drivers/media/video/gspca/xirlink_cit.c
drivers/media/video/gspca/zc3xx.c
drivers/media/video/hdpvr/Makefile
drivers/media/video/hexium_gemini.c
drivers/media/video/hexium_orion.c
drivers/media/video/ivtv/Makefile
drivers/media/video/ivtv/ivtv-ioctl.c
drivers/media/video/m5mols/m5mols_core.c
drivers/media/video/marvell-ccic/mcam-core.c
drivers/media/video/marvell-ccic/mmp-driver.c
drivers/media/video/mem2mem_testdev.c
drivers/media/video/msp3400-driver.c
drivers/media/video/msp3400-driver.h
drivers/media/video/msp3400-kthreads.c
drivers/media/video/mt9m111.c
drivers/media/video/mt9p031.c [new file with mode: 0644]
drivers/media/video/mt9t001.c [new file with mode: 0644]
drivers/media/video/mx3_camera.c
drivers/media/video/mxb.c
drivers/media/video/noon010pc30.c
drivers/media/video/omap/omap_vout.c
drivers/media/video/omap3isp/Makefile
drivers/media/video/omap3isp/isp.c
drivers/media/video/omap3isp/isp.h
drivers/media/video/omap3isp/ispccdc.c
drivers/media/video/omap3isp/ispccp2.c
drivers/media/video/omap3isp/ispqueue.c
drivers/media/video/omap3isp/ispstat.c
drivers/media/video/omap3isp/ispvideo.c
drivers/media/video/pvrusb2/Makefile
drivers/media/video/pvrusb2/pvrusb2-hdw.c
drivers/media/video/pvrusb2/pvrusb2-hdw.h
drivers/media/video/pvrusb2/pvrusb2-v4l2.c
drivers/media/video/pwc/pwc-if.c
drivers/media/video/pwc/pwc-v4l.c
drivers/media/video/s5p-fimc/Makefile
drivers/media/video/s5p-fimc/fimc-capture.c
drivers/media/video/s5p-fimc/fimc-core.c
drivers/media/video/s5p-fimc/fimc-core.h
drivers/media/video/s5p-fimc/fimc-mdevice.c [new file with mode: 0644]
drivers/media/video/s5p-fimc/fimc-mdevice.h [new file with mode: 0644]
drivers/media/video/s5p-fimc/fimc-reg.c
drivers/media/video/s5p-fimc/mipi-csis.c
drivers/media/video/s5p-fimc/regs-fimc.h
drivers/media/video/s5p-mfc/s5p_mfc.c
drivers/media/video/s5p-mfc/s5p_mfc_dec.c
drivers/media/video/s5p-mfc/s5p_mfc_enc.c
drivers/media/video/s5p-mfc/s5p_mfc_opr.c
drivers/media/video/s5p-tv/Kconfig
drivers/media/video/s5p-tv/hdmi_drv.c
drivers/media/video/s5p-tv/mixer.h
drivers/media/video/s5p-tv/mixer_grp_layer.c
drivers/media/video/s5p-tv/mixer_reg.c
drivers/media/video/s5p-tv/mixer_video.c
drivers/media/video/s5p-tv/mixer_vp_layer.c
drivers/media/video/s5p-tv/regs-hdmi.h
drivers/media/video/s5p-tv/regs-mixer.h
drivers/media/video/s5p-tv/sdo_drv.c
drivers/media/video/saa7115.c
drivers/media/video/saa7134/Makefile
drivers/media/video/saa7164/Makefile
drivers/media/video/saa7164/saa7164-cards.c
drivers/media/video/saa7164/saa7164-dvb.c
drivers/media/video/saa7164/saa7164.h
drivers/media/video/sh_mobile_ceu_camera.c
drivers/media/video/sr030pc30.c
drivers/media/video/stk-webcam.c
drivers/media/video/tlg2300/Makefile
drivers/media/video/tm6000/Kconfig [moved from drivers/staging/tm6000/Kconfig with 100% similarity]
drivers/media/video/tm6000/Makefile [moved from drivers/staging/tm6000/Makefile with 100% similarity]
drivers/media/video/tm6000/tm6000-alsa.c [moved from drivers/staging/tm6000/tm6000-alsa.c with 97% similarity]
drivers/media/video/tm6000/tm6000-cards.c [moved from drivers/staging/tm6000/tm6000-cards.c with 97% similarity]
drivers/media/video/tm6000/tm6000-core.c [moved from drivers/staging/tm6000/tm6000-core.c with 91% similarity]
drivers/media/video/tm6000/tm6000-dvb.c [moved from drivers/staging/tm6000/tm6000-dvb.c with 95% similarity]
drivers/media/video/tm6000/tm6000-i2c.c [moved from drivers/staging/tm6000/tm6000-i2c.c with 95% similarity]
drivers/media/video/tm6000/tm6000-input.c [moved from drivers/staging/tm6000/tm6000-input.c with 99% similarity]
drivers/media/video/tm6000/tm6000-regs.h [moved from drivers/staging/tm6000/tm6000-regs.h with 99% similarity]
drivers/media/video/tm6000/tm6000-stds.c [new file with mode: 0644]
drivers/media/video/tm6000/tm6000-usb-isoc.h [moved from drivers/staging/tm6000/tm6000-usb-isoc.h with 97% similarity]
drivers/media/video/tm6000/tm6000-video.c [moved from drivers/staging/tm6000/tm6000-video.c with 96% similarity]
drivers/media/video/tm6000/tm6000.h [moved from drivers/staging/tm6000/tm6000.h with 98% similarity]
drivers/media/video/tvaudio.c
drivers/media/video/tvp5150_reg.h
drivers/media/video/tvp7002.c
drivers/media/video/usbvision/Makefile
drivers/media/video/uvc/uvc_driver.c
drivers/media/video/uvc/uvc_v4l2.c
drivers/media/video/uvc/uvc_video.c
drivers/media/video/uvc/uvcvideo.h
drivers/media/video/v4l2-ctrls.c
drivers/media/video/v4l2-ioctl.c
drivers/media/video/v4l2-mem2mem.c
drivers/media/video/v4l2-subdev.c
drivers/media/video/videobuf2-core.c
drivers/media/video/videobuf2-dma-contig.c
drivers/media/video/videobuf2-dma-sg.c
drivers/media/video/videobuf2-memops.c
drivers/media/video/vivi.c
drivers/media/video/vpx3220.c
drivers/media/video/zr364xx.c
drivers/message/fusion/mptbase.c
drivers/message/fusion/mptbase.h
drivers/message/fusion/mptsas.c
drivers/message/fusion/mptscsih.c
drivers/message/fusion/mptscsih.h
drivers/mfd/twl6040-core.c
drivers/mfd/wm8994-core.c
drivers/misc/Kconfig
drivers/misc/Makefile
drivers/misc/ad525x_dpot-i2c.c
drivers/misc/altera-stapl/Kconfig [moved from drivers/staging/altera-stapl/Kconfig with 77% similarity]
drivers/misc/altera-stapl/Makefile [new file with mode: 0644]
drivers/misc/altera-stapl/altera-comp.c [moved from drivers/staging/altera-stapl/altera-comp.c with 100% similarity]
drivers/misc/altera-stapl/altera-exprt.h [moved from drivers/staging/altera-stapl/altera-exprt.h with 100% similarity]
drivers/misc/altera-stapl/altera-jtag.c [moved from drivers/staging/altera-stapl/altera-jtag.c with 99% similarity]
drivers/misc/altera-stapl/altera-jtag.h [moved from drivers/staging/altera-stapl/altera-jtag.h with 100% similarity]
drivers/misc/altera-stapl/altera-lpt.c [moved from drivers/staging/altera-stapl/altera-lpt.c with 100% similarity]
drivers/misc/altera-stapl/altera.c [moved from drivers/staging/altera-stapl/altera.c with 99% similarity]
drivers/misc/fsa9480.c
drivers/misc/lis3lv02d/lis3lv02d.c
drivers/misc/lis3lv02d/lis3lv02d.h
drivers/misc/lis3lv02d/lis3lv02d_i2c.c
drivers/misc/lis3lv02d/lis3lv02d_spi.c
drivers/mmc/card/block.c
drivers/mmc/card/mmc_test.c
drivers/mmc/card/queue.c
drivers/mmc/card/sdio_uart.c
drivers/mmc/core/bus.c
drivers/mmc/core/core.c
drivers/mmc/core/core.h
drivers/mmc/core/debugfs.c
drivers/mmc/core/host.c
drivers/mmc/core/mmc.c
drivers/mmc/core/mmc_ops.c
drivers/mmc/core/mmc_ops.h
drivers/mmc/core/quirks.c
drivers/mmc/core/sd.c
drivers/mmc/core/sd_ops.c
drivers/mmc/core/sdio.c
drivers/mmc/core/sdio_bus.c
drivers/mmc/core/sdio_cis.c
drivers/mmc/core/sdio_irq.c
drivers/mmc/core/sdio_ops.c
drivers/mmc/host/Kconfig
drivers/mmc/host/at91_mci.c
drivers/mmc/host/atmel-mci-regs.h
drivers/mmc/host/atmel-mci.c
drivers/mmc/host/au1xmmc.c
drivers/mmc/host/dw_mmc.c
drivers/mmc/host/dw_mmc.h
drivers/mmc/host/imxmmc.c
drivers/mmc/host/mmc_spi.c
drivers/mmc/host/mmci.c
drivers/mmc/host/msm_sdcc.c
drivers/mmc/host/msm_sdcc.h
drivers/mmc/host/mvsdio.c
drivers/mmc/host/mxcmmc.c
drivers/mmc/host/mxs-mmc.c
drivers/mmc/host/omap_hsmmc.c
drivers/mmc/host/pxamci.c
drivers/mmc/host/s3cmci.c
drivers/mmc/host/sdhci-esdhc-imx.c
drivers/mmc/host/sdhci-of-esdhc.c
drivers/mmc/host/sdhci-of-hlwd.c
drivers/mmc/host/sdhci-pci.c
drivers/mmc/host/sdhci-pltfm.c
drivers/mmc/host/sdhci-pxav2.c
drivers/mmc/host/sdhci-pxav3.c
drivers/mmc/host/sdhci-s3c.c
drivers/mmc/host/sdhci-spear.c
drivers/mmc/host/sdhci-tegra.c
drivers/mmc/host/sdhci.c
drivers/mmc/host/sdhci.h
drivers/mmc/host/sdricoh_cs.c
drivers/mmc/host/sh_mmcif.c
drivers/mmc/host/sh_mobile_sdhi.c
drivers/mmc/host/tifm_sd.c
drivers/mmc/host/tmio_mmc.c
drivers/mmc/host/tmio_mmc.h
drivers/mmc/host/tmio_mmc_pio.c
drivers/mmc/host/via-sdmmc.c
drivers/mmc/host/wbsd.c
drivers/net/bonding/bond_3ad.c
drivers/net/bonding/bond_alb.c
drivers/net/bonding/bond_main.c
drivers/net/bonding/bonding.h
drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
drivers/net/ethernet/broadcom/bnx2x/bnx2x_hsi.h
drivers/net/ethernet/broadcom/bnx2x/bnx2x_link.c
drivers/net/ethernet/broadcom/bnx2x/bnx2x_link.h
drivers/net/ethernet/emulex/benet/be_cmds.c
drivers/net/ethernet/emulex/benet/be_main.c
drivers/net/ethernet/i825xx/Kconfig
drivers/net/ethernet/mellanox/mlx4/eq.c
drivers/net/ethernet/mellanox/mlx4/fw.c
drivers/net/ethernet/mellanox/mlx4/fw.h
drivers/net/ethernet/mellanox/mlx4/main.c
drivers/net/ethernet/mellanox/mlx4/mlx4.h
drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
drivers/net/ethernet/mellanox/mlx4/mr.c
drivers/net/ethernet/mellanox/mlx4/pd.c
drivers/net/ethernet/mellanox/mlx4/port.c
drivers/net/ethernet/mellanox/mlx4/qp.c
drivers/net/ethernet/mellanox/mlx4/srq.c
drivers/net/ethernet/qlogic/qlcnic/qlcnic.h
drivers/net/ethernet/qlogic/qlcnic/qlcnic_ethtool.c
drivers/net/ethernet/qlogic/qlcnic/qlcnic_hdr.h
drivers/net/ethernet/qlogic/qlcnic/qlcnic_hw.c
drivers/net/ethernet/qlogic/qlcnic/qlcnic_init.c
drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c
drivers/net/ethernet/sfc/efx.c
drivers/net/ethernet/sfc/efx.h
drivers/net/ethernet/sfc/falcon.c
drivers/net/ethernet/sfc/falcon_boards.c
drivers/net/ethernet/stmicro/stmmac/common.h
drivers/net/ethernet/stmicro/stmmac/descs.h
drivers/net/ethernet/stmicro/stmmac/norm_desc.c
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
drivers/net/wireless/at76c50x-usb.c
drivers/net/wireless/ath/ath.h
drivers/net/wireless/ath/ath5k/debug.h
drivers/net/wireless/ath/ath6kl/debug.h
drivers/net/wireless/b43/b43.h
drivers/net/wireless/b43legacy/b43legacy.h
drivers/pci/Kconfig
drivers/pci/Makefile
drivers/pci/ats.c [new file with mode: 0644]
drivers/pci/hotplug/acpiphp_glue.c
drivers/pci/iov.c
drivers/pci/pci-acpi.c
drivers/pci/pci.c
drivers/pci/pcie/pme.c
drivers/pci/probe.c
drivers/pci/quirks.c
drivers/pci/setup-bus.c
drivers/platform/x86/Kconfig
drivers/platform/x86/acer-wmi.c
drivers/platform/x86/asus-laptop.c
drivers/platform/x86/asus-wmi.c
drivers/platform/x86/dell-laptop.c
drivers/platform/x86/eeepc-laptop.c
drivers/platform/x86/hp_accel.c
drivers/platform/x86/ideapad-laptop.c
drivers/platform/x86/intel_scu_ipcutil.c
drivers/platform/x86/samsung-laptop.c
drivers/platform/x86/sony-laptop.c
drivers/platform/x86/topstar-laptop.c
drivers/platform/x86/toshiba_acpi.c
drivers/platform/x86/wmi.c
drivers/regulator/88pm8607.c
drivers/regulator/Kconfig
drivers/regulator/Makefile
drivers/regulator/aat2870-regulator.c
drivers/regulator/core.c
drivers/regulator/gpio-regulator.c [new file with mode: 0644]
drivers/regulator/max8649.c
drivers/regulator/max8952.c
drivers/regulator/tps65023-regulator.c
drivers/regulator/tps6507x-regulator.c
drivers/regulator/tps6586x-regulator.c
drivers/regulator/tps65912-regulator.c
drivers/regulator/wm8994-regulator.c
drivers/s390/block/dasd.c
drivers/s390/block/dasd_eckd.c
drivers/s390/block/dasd_fba.c
drivers/s390/block/dasd_int.h
drivers/s390/char/con3215.c
drivers/s390/char/raw3270.c
drivers/s390/char/sclp_cmd.c
drivers/s390/char/sclp_quiesce.c
drivers/s390/char/tape_34xx.c
drivers/s390/char/tape_3590.c
drivers/s390/char/tape_core.c
drivers/s390/char/vmur.c
drivers/s390/char/zcore.c
drivers/s390/cio/ccwgroup.c
drivers/s390/cio/ccwreq.c
drivers/s390/cio/chsc_sch.c
drivers/s390/cio/cio.c
drivers/s390/cio/css.h
drivers/s390/cio/device.c
drivers/s390/cio/device.h
drivers/s390/cio/io_sch.h
drivers/s390/cio/qdio.h
drivers/s390/cio/qdio_debug.c
drivers/s390/cio/qdio_main.c
drivers/s390/cio/qdio_setup.c
drivers/s390/cio/qdio_thinint.c
drivers/s390/kvm/kvm_virtio.c
drivers/s390/net/claw.c
drivers/s390/net/ctcm_main.c
drivers/s390/net/ctcm_sysfs.c
drivers/s390/net/lcs.c
drivers/s390/net/qeth_l3_main.c
drivers/s390/scsi/zfcp_dbf.c
drivers/s390/scsi/zfcp_def.h
drivers/s390/scsi/zfcp_ext.h
drivers/s390/scsi/zfcp_fsf.c
drivers/s390/scsi/zfcp_qdio.c
drivers/s390/scsi/zfcp_qdio.h
drivers/s390/scsi/zfcp_scsi.c
drivers/scsi/Kconfig
drivers/scsi/Makefile
drivers/scsi/aacraid/linit.c
drivers/scsi/aic94xx/aic94xx_scb.c
drivers/scsi/be2iscsi/be_cmds.c
drivers/scsi/be2iscsi/be_cmds.h
drivers/scsi/be2iscsi/be_iscsi.c
drivers/scsi/be2iscsi/be_iscsi.h
drivers/scsi/be2iscsi/be_main.c
drivers/scsi/be2iscsi/be_main.h
drivers/scsi/bnx2fc/bnx2fc.h
drivers/scsi/bnx2fc/bnx2fc_els.c
drivers/scsi/bnx2fc/bnx2fc_fcoe.c
drivers/scsi/bnx2fc/bnx2fc_hwi.c
drivers/scsi/bnx2fc/bnx2fc_io.c
drivers/scsi/bnx2fc/bnx2fc_tgt.c
drivers/scsi/bnx2i/bnx2i_iscsi.c
drivers/scsi/cxgbi/cxgb3i/cxgb3i.c
drivers/scsi/cxgbi/cxgb4i/cxgb4i.c
drivers/scsi/cxgbi/libcxgbi.c
drivers/scsi/cxgbi/libcxgbi.h
drivers/scsi/device_handler/scsi_dh.c
drivers/scsi/device_handler/scsi_dh_alua.c
drivers/scsi/device_handler/scsi_dh_rdac.c
drivers/scsi/fcoe/fcoe.c
drivers/scsi/fcoe/fcoe.h
drivers/scsi/fcoe/fcoe_transport.c
drivers/scsi/hpsa.c
drivers/scsi/ipr.c
drivers/scsi/ipr.h
drivers/scsi/isci/host.c
drivers/scsi/isci/host.h
drivers/scsi/isci/init.c
drivers/scsi/isci/isci.h
drivers/scsi/isci/phy.c
drivers/scsi/isci/port.c
drivers/scsi/isci/port_config.c
drivers/scsi/isci/registers.h
drivers/scsi/isci/remote_device.c
drivers/scsi/isci/remote_device.h
drivers/scsi/isci/request.c
drivers/scsi/isci/request.h
drivers/scsi/isci/sas.h
drivers/scsi/isci/task.c
drivers/scsi/isci/task.h
drivers/scsi/iscsi_tcp.c
drivers/scsi/libfc/fc_exch.c
drivers/scsi/libfc/fc_fcp.c
drivers/scsi/libiscsi.c
drivers/scsi/libsas/sas_discover.c
drivers/scsi/libsas/sas_expander.c
drivers/scsi/libsas/sas_host_smp.c
drivers/scsi/libsas/sas_init.c
drivers/scsi/libsas/sas_scsi_host.c
drivers/scsi/lpfc/lpfc.h
drivers/scsi/lpfc/lpfc_attr.c
drivers/scsi/lpfc/lpfc_crtn.h
drivers/scsi/lpfc/lpfc_ct.c
drivers/scsi/lpfc/lpfc_debugfs.c
drivers/scsi/lpfc/lpfc_els.c
drivers/scsi/lpfc/lpfc_hbadisc.c
drivers/scsi/lpfc/lpfc_hw4.h
drivers/scsi/lpfc/lpfc_init.c
drivers/scsi/lpfc/lpfc_logmsg.h
drivers/scsi/lpfc/lpfc_mbox.c
drivers/scsi/lpfc/lpfc_scsi.c
drivers/scsi/lpfc/lpfc_sli.c
drivers/scsi/lpfc/lpfc_sli.h
drivers/scsi/lpfc/lpfc_sli4.h
drivers/scsi/lpfc/lpfc_version.h
drivers/scsi/lpfc/lpfc_vport.c
drivers/scsi/mac_esp.c
drivers/scsi/megaraid/megaraid_sas.h
drivers/scsi/megaraid/megaraid_sas_base.c
drivers/scsi/megaraid/megaraid_sas_fp.c
drivers/scsi/megaraid/megaraid_sas_fusion.c
drivers/scsi/megaraid/megaraid_sas_fusion.h
drivers/scsi/mpt2sas/mpt2sas_base.c
drivers/scsi/mpt2sas/mpt2sas_base.h
drivers/scsi/mpt2sas/mpt2sas_ctl.c
drivers/scsi/mpt2sas/mpt2sas_scsih.c
drivers/scsi/mpt2sas/mpt2sas_transport.c
drivers/scsi/mvsas/mv_94xx.c
drivers/scsi/mvsas/mv_defs.h
drivers/scsi/mvsas/mv_init.c
drivers/scsi/mvsas/mv_sas.c
drivers/scsi/mvsas/mv_sas.h
drivers/scsi/mvumi.c [new file with mode: 0644]
drivers/scsi/mvumi.h [new file with mode: 0644]
drivers/scsi/pm8001/pm8001_hwi.c
drivers/scsi/pm8001/pm8001_init.c
drivers/scsi/pm8001/pm8001_sas.c
drivers/scsi/pm8001/pm8001_sas.h
drivers/scsi/qla2xxx/qla_attr.c
drivers/scsi/qla2xxx/qla_bsg.c
drivers/scsi/qla2xxx/qla_bsg.h
drivers/scsi/qla2xxx/qla_dbg.c
drivers/scsi/qla2xxx/qla_def.h
drivers/scsi/qla2xxx/qla_gbl.h
drivers/scsi/qla2xxx/qla_init.c
drivers/scsi/qla2xxx/qla_isr.c
drivers/scsi/qla2xxx/qla_mbx.c
drivers/scsi/qla2xxx/qla_nx.c
drivers/scsi/qla2xxx/qla_nx.h
drivers/scsi/qla2xxx/qla_os.c
drivers/scsi/qla4xxx/Kconfig
drivers/scsi/qla4xxx/Makefile
drivers/scsi/qla4xxx/ql4_attr.c
drivers/scsi/qla4xxx/ql4_bsg.c [new file with mode: 0644]
drivers/scsi/qla4xxx/ql4_bsg.h [new file with mode: 0644]
drivers/scsi/qla4xxx/ql4_def.h
drivers/scsi/qla4xxx/ql4_fw.h
drivers/scsi/qla4xxx/ql4_glbl.h
drivers/scsi/qla4xxx/ql4_init.c
drivers/scsi/qla4xxx/ql4_iocb.c
drivers/scsi/qla4xxx/ql4_isr.c
drivers/scsi/qla4xxx/ql4_mbx.c
drivers/scsi/qla4xxx/ql4_nvram.c
drivers/scsi/qla4xxx/ql4_nx.c
drivers/scsi/qla4xxx/ql4_os.c
drivers/scsi/qla4xxx/ql4_version.h
drivers/scsi/qlogicpti.c
drivers/scsi/scsi_error.c
drivers/scsi/scsi_sysfs.c
drivers/scsi/scsi_transport_iscsi.c
drivers/scsi/scsi_transport_sas.c
drivers/scsi/sd.c
drivers/spi/spi-altera.c
drivers/spi/spi-ath79.c
drivers/spi/spi-atmel.c
drivers/spi/spi-bfin-sport.c
drivers/spi/spi-bfin5xx.c
drivers/spi/spi-coldfire-qspi.c
drivers/spi/spi-davinci.c
drivers/spi/spi-dw-mid.c
drivers/spi/spi-dw-mmio.c
drivers/spi/spi-dw.c
drivers/spi/spi-dw.h
drivers/spi/spi-ep93xx.c
drivers/spi/spi-fsl-espi.c
drivers/spi/spi-gpio.c
drivers/spi/spi-imx.c
drivers/spi/spi-mpc512x-psc.c
drivers/spi/spi-mpc52xx-psc.c
drivers/spi/spi-mpc52xx.c
drivers/spi/spi-nuc900.c
drivers/spi/spi-oc-tiny.c
drivers/spi/spi-omap2-mcspi.c
drivers/spi/spi-pl022.c
drivers/spi/spi-ppc4xx.c
drivers/spi/spi-s3c24xx.c
drivers/spi/spi-sh-msiof.c
drivers/spi/spi-sh-sci.c
drivers/spi/spi-sh.c
drivers/spi/spi-stmp.c
drivers/spi/spi-tegra.c
drivers/spi/spi-ti-ssp.c
drivers/spi/spi-xilinx.c
drivers/staging/Kconfig
drivers/staging/Makefile
drivers/staging/altera-stapl/Makefile [deleted file]
drivers/staging/dt3155v4l/dt3155v4l.c
drivers/staging/iio/trigger.h
drivers/staging/tm6000/README [deleted file]
drivers/staging/tm6000/TODO [deleted file]
drivers/staging/tm6000/tm6000-stds.c [deleted file]
drivers/staging/xgifb/XGI_main_26.c
drivers/tty/serial/of_serial.c
drivers/video/68328fb.c
drivers/video/Kconfig
drivers/video/Makefile
drivers/video/acornfb.c
drivers/video/arkfb.c
drivers/video/atmel_lcdfb.c
drivers/video/aty/radeon_base.c
drivers/video/au1100fb.c
drivers/video/au1100fb.h
drivers/video/au1200fb.c
drivers/video/backlight/adp8860_bl.c
drivers/video/backlight/adp8870_bl.c
drivers/video/backlight/generic_bl.c
drivers/video/backlight/l4f00242t03.c
drivers/video/bf54x-lq043fb.c
drivers/video/bfin-lq035q1-fb.c
drivers/video/bfin-t350mcqb-fb.c
drivers/video/bfin_adv7393fb.c
drivers/video/carminefb.c
drivers/video/controlfb.c
drivers/video/da8xx-fb.c
drivers/video/fb-puv3.c
drivers/video/fb_defio.c
drivers/video/fbmem.c
drivers/video/fbmon.c
drivers/video/fbsysfs.c
drivers/video/fsl-diu-fb.c
drivers/video/g364fb.c
drivers/video/grvga.c [new file with mode: 0644]
drivers/video/gxt4500.c
drivers/video/hgafb.c
drivers/video/imsttfb.c
drivers/video/intelfb/intelfbhw.c
drivers/video/mb862xx/mb862xx-i2c.c
drivers/video/mb862xx/mb862xxfbdrv.c
drivers/video/modedb.c
drivers/video/msm/mddi.c
drivers/video/msm/mdp.c
drivers/video/mx3fb.c
drivers/video/mxsfb.c
drivers/video/neofb.c
drivers/video/nuc900fb.c
drivers/video/omap/Kconfig
drivers/video/omap/Makefile
drivers/video/omap/lcd_2430sdp.c [deleted file]
drivers/video/omap/lcd_apollon.c [deleted file]
drivers/video/omap/lcd_h4.c [deleted file]
drivers/video/omap/lcd_ldp.c [deleted file]
drivers/video/omap/lcd_omap3beagle.c [deleted file]
drivers/video/omap/lcd_omap3evm.c [deleted file]
drivers/video/omap/lcd_overo.c [deleted file]
drivers/video/omap2/displays/Kconfig
drivers/video/omap2/displays/Makefile
drivers/video/omap2/displays/panel-dvi.c [new file with mode: 0644]
drivers/video/omap2/displays/panel-generic-dpi.c
drivers/video/omap2/displays/panel-n8x0.c [new file with mode: 0644]
drivers/video/omap2/displays/panel-picodlp.c [new file with mode: 0644]
drivers/video/omap2/displays/panel-picodlp.h [new file with mode: 0644]
drivers/video/omap2/displays/panel-taal.c
drivers/video/omap2/dss/Kconfig
drivers/video/omap2/dss/Makefile
drivers/video/omap2/dss/core.c
drivers/video/omap2/dss/dispc.c
drivers/video/omap2/dss/dispc.h
drivers/video/omap2/dss/display.c
drivers/video/omap2/dss/dpi.c
drivers/video/omap2/dss/dsi.c
drivers/video/omap2/dss/dss.c
drivers/video/omap2/dss/dss.h
drivers/video/omap2/dss/dss_features.c
drivers/video/omap2/dss/dss_features.h
drivers/video/omap2/dss/hdmi.c
drivers/video/omap2/dss/hdmi_panel.c [moved from drivers/video/omap2/dss/hdmi_omap4_panel.c with 79% similarity]
drivers/video/omap2/dss/manager.c
drivers/video/omap2/dss/overlay.c
drivers/video/omap2/dss/rfbi.c
drivers/video/omap2/dss/sdi.c
drivers/video/omap2/dss/ti_hdmi.h [new file with mode: 0644]
drivers/video/omap2/dss/ti_hdmi_4xxx_ip.c [new file with mode: 0644]
drivers/video/omap2/dss/ti_hdmi_4xxx_ip.h [moved from drivers/video/omap2/dss/hdmi.h with 54% similarity]
drivers/video/omap2/dss/venc.c
drivers/video/omap2/omapfb/Kconfig
drivers/video/omap2/omapfb/omapfb-main.c
drivers/video/omap2/omapfb/omapfb-sysfs.c
drivers/video/platinumfb.c
drivers/video/pm2fb.c
drivers/video/pm3fb.c
drivers/video/ps3fb.c
drivers/video/pxa3xx-gcu.c
drivers/video/pxafb.c
drivers/video/s3c-fb.c
drivers/video/s3c2410fb.c
drivers/video/s3fb.c
drivers/video/sa1100fb.c
drivers/video/savage/savagefb_driver.c
drivers/video/sh_mobile_hdmi.c
drivers/video/sh_mobile_lcdcfb.c
drivers/video/sh_mobile_lcdcfb.h
drivers/video/sh_mobile_meram.c
drivers/video/sh_mobile_meram.h [deleted file]
drivers/video/sis/sis_main.c
drivers/video/skeletonfb.c
drivers/video/sm501fb.c
drivers/video/smscufx.c [new file with mode: 0644]
drivers/video/tmiofb.c
drivers/video/tridentfb.c
drivers/video/udlfb.c
drivers/video/valkyriefb.c
drivers/video/vfb.c
drivers/video/vga16fb.c
drivers/video/via/dvi.c
drivers/video/via/dvi.h
drivers/video/via/global.c
drivers/video/via/global.h
drivers/video/via/hw.c
drivers/video/via/hw.h
drivers/video/via/lcd.c
drivers/video/via/lcd.h
drivers/video/via/share.h
drivers/video/via/via-core.c
drivers/video/via/via_modesetting.c
drivers/video/via/via_modesetting.h
drivers/video/via/viafbdev.c
drivers/video/via/viamode.c
drivers/video/via/viamode.h
drivers/video/vt8500lcdfb.c
drivers/video/vt8623fb.c
drivers/video/xilinxfb.c
fs/Kconfig
fs/aio.c
fs/buffer.c
fs/ceph/addr.c
fs/ceph/caps.c
fs/ceph/inode.c
fs/ceph/ioctl.c
fs/ceph/ioctl.h
fs/ceph/mds_client.c
fs/ceph/super.c
fs/ceph/super.h
fs/compat.c
fs/ecryptfs/ecryptfs_kernel.h
fs/eventpoll.c
fs/exec.c
fs/ext2/ext2.h
fs/ext4/ext4.h
fs/ext4/inode.c
fs/fat/dir.c
fs/fat/fat.h
fs/gfs2/glock.h
fs/hpfs/hpfs_fn.h
fs/logfs/logfs.h
fs/logfs/super.c
fs/nilfs2/nilfs.h
fs/ntfs/debug.h
fs/ocfs2/super.h
fs/partitions/ldm.c
fs/pipe.c
fs/proc/base.c
fs/proc/task_mmu.c
fs/pstore/inode.c
fs/pstore/internal.h
fs/pstore/platform.c
fs/read_write.c
fs/super.c
fs/sysfs/dir.c
fs/udf/udfdecl.h
fs/ufs/ufs.h
fs/xfs/xfs_aops.c
fs/xfs/xfs_message.h
include/acpi/acpiosxf.h
include/asm-generic/bug.h
include/asm-generic/checksum.h
include/asm-generic/dma-mapping-common.h
include/asm-generic/gpio.h
include/asm-generic/page.h
include/asm-generic/rwsem.h [new file with mode: 0644]
include/crypto/algapi.h
include/crypto/blowfish.h [new file with mode: 0644]
include/crypto/sha.h
include/drm/drmP.h
include/linux/amba/pl061.h
include/linux/atmel-mci.h
include/linux/atmel_pdc.h
include/linux/audit.h
include/linux/blktrace_api.h
include/linux/ceph/libceph.h
include/linux/ceph/messenger.h
include/linux/compaction.h
include/linux/compat.h
include/linux/crash_dump.h
include/linux/crypto.h
include/linux/cryptouser.h [new file with mode: 0644]
include/linux/device.h
include/linux/dmar.h
include/linux/dvb/frontend.h
include/linux/dvb/version.h
include/linux/dynamic_debug.h
include/linux/elf.h
include/linux/ext3_fs.h
include/linux/fs.h
include/linux/fscache-cache.h
include/linux/fsl-diu-fb.h
include/linux/gameport.h
include/linux/genhd.h
include/linux/gpio.h
include/linux/huge_mm.h
include/linux/i2c.h
include/linux/if_vlan.h
include/linux/input.h
include/linux/iommu.h
include/linux/kallsyms.h
include/linux/kdb.h
include/linux/kernel.h
include/linux/kexec.h
include/linux/kmod.h
include/linux/kobject.h
include/linux/kthread.h
include/linux/kvm.h
include/linux/kvm_host.h
include/linux/libata.h
include/linux/lis3lv02d.h
include/linux/llist.h
include/linux/memblock.h
include/linux/memcontrol.h
include/linux/mfd/tps6586x.h
include/linux/mfd/twl6040.h
include/linux/mfd/wm8994/core.h
include/linux/mfd/wm8994/registers.h
include/linux/mlx4/device.h
include/linux/mlx4/qp.h
include/linux/mm.h
include/linux/mm_types.h
include/linux/mmc/card.h
include/linux/mmc/core.h
include/linux/mmc/dw_mmc.h
include/linux/mmc/host.h
include/linux/mmc/mmc.h
include/linux/mmc/sdhci.h
include/linux/mmc/sdio.h
include/linux/mmc/sh_mmcif.h
include/linux/mmc/sh_mobile_sdhi.h
include/linux/mmiotrace.h
include/linux/mmzone.h
include/linux/netdevice.h
include/linux/netlink.h
include/linux/of.h
include/linux/omap3isp.h
include/linux/oom.h
include/linux/pci-ats.h
include/linux/pci.h
include/linux/pci_ids.h
include/linux/pci_regs.h
include/linux/platform_data/leds-renesas-tpu.h [new file with mode: 0644]
include/linux/platform_device.h
include/linux/printk.h
include/linux/pstore.h
include/linux/quotaops.h
include/linux/regulator/consumer.h
include/linux/regulator/driver.h
include/linux/regulator/gpio-regulator.h [new file with mode: 0644]
include/linux/regulator/machine.h
include/linux/seq_file.h
include/linux/shrinker.h
include/linux/spi/l4f00242t03.h
include/linux/string.h
include/linux/swap.h
include/linux/syscalls.h
include/linux/trace_seq.h
include/linux/usb/Kbuild
include/linux/usb/ch9.h
include/linux/videodev2.h
include/linux/vmalloc.h
include/media/m5mols.h
include/media/mt9p031.h [new file with mode: 0644]
include/media/mt9t001.h [new file with mode: 0644]
include/media/omap3isp.h [new file with mode: 0644]
include/media/rc-core.h
include/media/rc-map.h
include/media/s5p_fimc.h
include/media/saa7146.h
include/media/v4l2-chip-ident.h
include/media/v4l2-ctrls.h
include/media/v4l2-mediabus.h
include/media/videobuf2-core.h
include/media/videobuf2-dma-contig.h
include/misc/altera.h [moved from drivers/staging/altera-stapl/altera.h with 100% similarity]
include/net/bluetooth/bluetooth.h
include/net/inet_timewait_sock.h
include/net/ipv6.h
include/net/netfilter/nf_log.h
include/net/sock.h
include/rdma/ib_user_verbs.h
include/rdma/ib_verbs.h
include/rdma/iw_cm.h
include/rdma/rdma_cm.h
include/rdma/rdma_user_cm.h
include/scsi/iscsi_if.h
include/scsi/libfc.h
include/scsi/libfcoe.h
include/scsi/libsas.h
include/scsi/sas.h
include/scsi/scsi_bsg_iscsi.h [new file with mode: 0644]
include/scsi/scsi_device.h
include/scsi/scsi_host.h
include/scsi/scsi_transport_iscsi.h
include/sound/adau1373.h [new file with mode: 0644]
include/sound/asound.h
include/sound/core.h
include/sound/info.h
include/sound/initval.h
include/sound/jack.h
include/sound/mpu401.h
include/sound/pcm.h
include/sound/saif.h [new file with mode: 0644]
include/sound/seq_kernel.h
include/sound/soc-dai.h
include/sound/soc-dapm.h
include/sound/soc.h
include/sound/tpa6130a2-plat.h
include/sound/wm1250-ev1.h [new file with mode: 0644]
include/sound/wm5100.h [new file with mode: 0644]
include/trace/events/asoc.h
include/trace/events/vmscan.h
include/video/omap-panel-dvi.h [new file with mode: 0644]
include/video/omap-panel-n8x0.h [new file with mode: 0644]
include/video/omap-panel-nokia-dsi.h
include/video/omap-panel-picodlp.h [new file with mode: 0644]
include/video/omapdss.h
include/video/sh_mobile_lcdc.h
include/video/udlfb.h
include/xen/hvc-console.h
include/xen/xenbus.h
ipc/mqueue.c
kernel/crash_dump.c
kernel/debug/gdbstub.c
kernel/events/core.c
kernel/exit.c
kernel/fork.c
kernel/irq/generic-chip.c
kernel/kexec.c
kernel/printk.c
kernel/stop_machine.c
kernel/sys_ni.c
kernel/sysctl.c
kernel/watchdog.c
lib/Kconfig.debug
lib/bitmap.c
lib/dma-debug.c
lib/fault-inject.c
lib/idr.c
lib/kstrtox.c
lib/kstrtox.h [new file with mode: 0644]
lib/percpu_counter.c
lib/radix-tree.c
lib/spinlock_debug.c
lib/string.c
lib/vsprintf.c
mm/Kconfig
mm/Makefile
mm/backing-dev.c
mm/compaction.c
mm/debug-pagealloc.c
mm/highmem.c
mm/huge_memory.c
mm/ksm.c
mm/memblock.c
mm/memcontrol.c
mm/memory-failure.c
mm/mempolicy.c
mm/migrate.c
mm/mlock.c
mm/mmap.c
mm/mremap.c
mm/oom_kill.c
mm/page-writeback.c
mm/page_alloc.c
mm/process_vm_access.c [new file with mode: 0644]
mm/rmap.c
mm/shmem.c
mm/slub.c
mm/swapfile.c
mm/thrash.c
mm/vmalloc.c
mm/vmscan.c
mm/vmstat.c
net/8021q/vlan_core.c
net/batman-adv/translation-table.c
net/batman-adv/types.h
net/ceph/Kconfig
net/ceph/ceph_common.c
net/ceph/messenger.c
net/ceph/mon_client.c
net/ceph/msgpool.c
net/ceph/osd_client.c
net/core/dev.c
net/dccp/ipv6.c
net/ipv4/tcp_minisocks.c
net/ipv6/addrconf.c
net/ipv6/inet6_connection_sock.c
net/ipv6/ip6_output.c
net/ipv6/route.c
net/ipv6/tcp_ipv6.c
net/nfc/nfc.h
net/rds/rds.h
net/sctp/ipv6.c
net/sunrpc/svc.c
scripts/checkpatch.pl
security/keys/compat.c
security/keys/encrypted-keys/encrypted.c
security/keys/keyctl.c
security/keys/trusted.c
sound/aoa/codecs/onyx.c
sound/arm/aaci.c
sound/arm/pxa2xx-ac97-lib.c
sound/core/control.c
sound/core/control_compat.c
sound/core/jack.c
sound/core/oss/mixer_oss.c
sound/core/pcm_lib.c
sound/core/pcm_native.c
sound/drivers/aloop.c
sound/drivers/ml403-ac97cr.c
sound/drivers/mpu401/mpu401.c
sound/drivers/mpu401/mpu401_uart.c
sound/drivers/mtpav.c
sound/drivers/serial-u16550.c
sound/firewire/cmp.c
sound/firewire/isight.c
sound/firewire/speakers.c
sound/isa/ad1816a/ad1816a.c
sound/isa/ad1816a/ad1816a_lib.c
sound/isa/als100.c
sound/isa/azt2320.c
sound/isa/cmi8330.c
sound/isa/cs423x/cs4231.c
sound/isa/cs423x/cs4236.c
sound/isa/es1688/es1688.c
sound/isa/es1688/es1688_lib.c
sound/isa/es18xx.c
sound/isa/galaxy/galaxy.c
sound/isa/gus/gus_main.c
sound/isa/gus/gusextreme.c
sound/isa/gus/gusmax.c
sound/isa/gus/interwave.c
sound/isa/msnd/msnd_pinnacle.c
sound/isa/opl3sa2.c
sound/isa/opti9xx/miro.c
sound/isa/opti9xx/opti92x-ad1848.c
sound/isa/sb/jazz16.c
sound/isa/sb/sb16.c
sound/isa/sb/sb_common.c
sound/isa/sc6000.c
sound/isa/sscape.c
sound/isa/wavefront/wavefront.c
sound/isa/wss/wss_lib.c
sound/mips/Kconfig
sound/mips/au1x00.c
sound/oss/sound_timer.c
sound/pci/als4000.c
sound/pci/au88x0/au88x0_mpu401.c
sound/pci/azt3328.c
sound/pci/cmipci.c
sound/pci/ctxfi/ctpcm.c
sound/pci/ctxfi/ctsrc.c
sound/pci/ctxfi/ctvmem.h
sound/pci/emu10k1/emupcm.c
sound/pci/es1938.c
sound/pci/es1968.c
sound/pci/fm801.c
sound/pci/hda/Makefile
sound/pci/hda/alc260_quirks.c
sound/pci/hda/alc262_quirks.c
sound/pci/hda/alc268_quirks.c [deleted file]
sound/pci/hda/alc269_quirks.c [deleted file]
sound/pci/hda/alc662_quirks.c [deleted file]
sound/pci/hda/alc680_quirks.c [deleted file]
sound/pci/hda/alc861_quirks.c [deleted file]
sound/pci/hda/alc861vd_quirks.c [deleted file]
sound/pci/hda/alc880_quirks.c
sound/pci/hda/alc882_quirks.c
sound/pci/hda/alc_quirks.c
sound/pci/hda/hda_codec.c
sound/pci/hda/hda_eld.c
sound/pci/hda/hda_hwdep.c
sound/pci/hda/hda_intel.c
sound/pci/hda/hda_local.h
sound/pci/hda/hda_proc.c
sound/pci/hda/hda_trace.h [new file with mode: 0644]
sound/pci/hda/patch_analog.c
sound/pci/hda/patch_conexant.c
sound/pci/hda/patch_hdmi.c
sound/pci/hda/patch_realtek.c
sound/pci/hda/patch_sigmatel.c
sound/pci/hda/patch_via.c
sound/pci/ice1712/ice1712.c
sound/pci/maestro3.c
sound/pci/oxygen/oxygen_lib.c
sound/pci/oxygen/xonar_pcm179x.c
sound/pci/riptide/riptide.c
sound/pci/rme9652/hdspm.c
sound/pci/sis7019.c
sound/pci/sonicvibes.c
sound/pci/trident/trident.c
sound/pci/via82xx.c
sound/pci/ymfpci/ymfpci.c
sound/pci/ymfpci/ymfpci_main.c
sound/ppc/keywest.c
sound/ppc/snd_ps3.c
sound/soc/Kconfig
sound/soc/Makefile
sound/soc/atmel/playpaq_wm8510.c
sound/soc/atmel/sam9g20_wm8731.c
sound/soc/atmel/snd-soc-afeb9260.c
sound/soc/au1x/Kconfig
sound/soc/au1x/Makefile
sound/soc/au1x/ac97c.c [new file with mode: 0644]
sound/soc/au1x/db1000.c [new file with mode: 0644]
sound/soc/au1x/db1200.c
sound/soc/au1x/dbdma2.c
sound/soc/au1x/dma.c [new file with mode: 0644]
sound/soc/au1x/i2sc.c [new file with mode: 0644]
sound/soc/au1x/psc-ac97.c
sound/soc/au1x/psc-i2s.c
sound/soc/au1x/psc.h
sound/soc/blackfin/Kconfig
sound/soc/blackfin/Makefile
sound/soc/blackfin/bf5xx-ac97-pcm.c
sound/soc/blackfin/bf5xx-i2s-pcm.c
sound/soc/blackfin/bfin-eval-adau1373.c [new file with mode: 0644]
sound/soc/codecs/88pm860x-codec.c
sound/soc/codecs/Kconfig
sound/soc/codecs/Makefile
sound/soc/codecs/ad193x.c
sound/soc/codecs/ad193x.h
sound/soc/codecs/ad1980.c
sound/soc/codecs/adau1373.c [new file with mode: 0644]
sound/soc/codecs/adau1373.h [new file with mode: 0644]
sound/soc/codecs/adau1701.c
sound/soc/codecs/adav80x.c
sound/soc/codecs/ads117x.h [deleted file]
sound/soc/codecs/ak4104.c
sound/soc/codecs/ak4535.c
sound/soc/codecs/ak4641.c
sound/soc/codecs/ak4642.c
sound/soc/codecs/ak4671.c
sound/soc/codecs/alc5623.c
sound/soc/codecs/cs4270.c
sound/soc/codecs/cs4271.c
sound/soc/codecs/cs42l51.c
sound/soc/codecs/da7210.c
sound/soc/codecs/lm4857.c
sound/soc/codecs/max98088.c
sound/soc/codecs/max98095.c
sound/soc/codecs/rt5631.c [new file with mode: 0644]
sound/soc/codecs/rt5631.h [new file with mode: 0644]
sound/soc/codecs/sgtl5000.c
sound/soc/codecs/sgtl5000.h
sound/soc/codecs/sn95031.c
sound/soc/codecs/ssm2602.c
sound/soc/codecs/ssm2602.h
sound/soc/codecs/sta32x.c
sound/soc/codecs/tlv320aic23.c
sound/soc/codecs/tlv320aic32x4.c
sound/soc/codecs/tlv320aic3x.c
sound/soc/codecs/tlv320dac33.c
sound/soc/codecs/tpa6130a2.c
sound/soc/codecs/twl4030.c
sound/soc/codecs/twl6040.c
sound/soc/codecs/twl6040.h
sound/soc/codecs/wl1273.c
sound/soc/codecs/wm1250-ev1.c
sound/soc/codecs/wm5100-tables.c [new file with mode: 0644]
sound/soc/codecs/wm5100.c [new file with mode: 0644]
sound/soc/codecs/wm5100.h [new file with mode: 0644]
sound/soc/codecs/wm8350.c
sound/soc/codecs/wm8400.c
sound/soc/codecs/wm8510.c
sound/soc/codecs/wm8523.c
sound/soc/codecs/wm8580.c
sound/soc/codecs/wm8711.c
sound/soc/codecs/wm8728.c
sound/soc/codecs/wm8731.c
sound/soc/codecs/wm8737.c
sound/soc/codecs/wm8741.c
sound/soc/codecs/wm8750.c
sound/soc/codecs/wm8753.c
sound/soc/codecs/wm8770.c
sound/soc/codecs/wm8776.c
sound/soc/codecs/wm8782.c
sound/soc/codecs/wm8804.c
sound/soc/codecs/wm8900.c
sound/soc/codecs/wm8904.c
sound/soc/codecs/wm8940.c
sound/soc/codecs/wm8960.c
sound/soc/codecs/wm8961.c
sound/soc/codecs/wm8962.c
sound/soc/codecs/wm8971.c
sound/soc/codecs/wm8974.c
sound/soc/codecs/wm8978.c
sound/soc/codecs/wm8983.c
sound/soc/codecs/wm8988.c
sound/soc/codecs/wm8990.c
sound/soc/codecs/wm8991.c
sound/soc/codecs/wm8993.c
sound/soc/codecs/wm8994-tables.c
sound/soc/codecs/wm8994.c
sound/soc/codecs/wm8994.h
sound/soc/codecs/wm8995.c
sound/soc/codecs/wm8996.c
sound/soc/codecs/wm9081.c
sound/soc/codecs/wm9090.c
sound/soc/codecs/wm_hubs.c
sound/soc/codecs/wm_hubs.h
sound/soc/davinci/davinci-evm.c
sound/soc/davinci/davinci-i2s.c
sound/soc/davinci/davinci-mcasp.c
sound/soc/davinci/davinci-pcm.c
sound/soc/ep93xx/edb93xx.c
sound/soc/ep93xx/ep93xx-ac97.c
sound/soc/ep93xx/ep93xx-pcm.c
sound/soc/ep93xx/simone.c
sound/soc/ep93xx/snappercl15.c
sound/soc/fsl/fsl_dma.c
sound/soc/fsl/fsl_ssi.c
sound/soc/fsl/mpc8610_hpcd.c
sound/soc/fsl/p1022_ds.c
sound/soc/imx/Kconfig
sound/soc/imx/imx-pcm-fiq.c
sound/soc/imx/imx-ssi.c
sound/soc/imx/imx-ssi.h
sound/soc/jz4740/jz4740-pcm.c
sound/soc/kirkwood/kirkwood-i2s.c
sound/soc/kirkwood/kirkwood-t5325.c
sound/soc/mid-x86/mfld_machine.c
sound/soc/mid-x86/sst_platform.c
sound/soc/mxs/Kconfig [new file with mode: 0644]
sound/soc/mxs/Makefile [new file with mode: 0644]
sound/soc/mxs/mxs-pcm.c [new file with mode: 0644]
sound/soc/mxs/mxs-pcm.h [new file with mode: 0644]
sound/soc/mxs/mxs-saif.c [new file with mode: 0644]
sound/soc/mxs/mxs-saif.h [new file with mode: 0644]
sound/soc/mxs/mxs-sgtl5000.c [new file with mode: 0644]
sound/soc/nuc900/nuc900-pcm.c
sound/soc/omap/Makefile
sound/soc/omap/am3517evm.c
sound/soc/omap/ams-delta.c
sound/soc/omap/igep0020.c
sound/soc/omap/mcpdm.c [deleted file]
sound/soc/omap/mcpdm.h [deleted file]
sound/soc/omap/n810.c
sound/soc/omap/omap-mcbsp.c
sound/soc/omap/omap-mcpdm.c
sound/soc/omap/omap-mcpdm.h [new file with mode: 0644]
sound/soc/omap/omap-pcm.c
sound/soc/omap/omap3evm.c
sound/soc/omap/omap3pandora.c
sound/soc/omap/osk5912.c
sound/soc/omap/overo.c
sound/soc/omap/rx51.c
sound/soc/omap/sdp3430.c
sound/soc/omap/sdp4430.c
sound/soc/omap/zoom2.c
sound/soc/pxa/Kconfig
sound/soc/pxa/corgi.c
sound/soc/pxa/e740_wm9705.c
sound/soc/pxa/e750_wm9705.c
sound/soc/pxa/e800_wm9712.c
sound/soc/pxa/magician.c
sound/soc/pxa/mioa701_wm9713.c
sound/soc/pxa/palm27x.c
sound/soc/pxa/poodle.c
sound/soc/pxa/raumfeld.c
sound/soc/pxa/saarb.c
sound/soc/pxa/spitz.c
sound/soc/pxa/tavorevb3.c
sound/soc/pxa/tosa.c
sound/soc/pxa/z2.c
sound/soc/pxa/zylonite.c
sound/soc/s6000/s6000-pcm.c
sound/soc/samsung/Kconfig
sound/soc/samsung/ac97.c
sound/soc/samsung/goni_wm8994.c
sound/soc/samsung/h1940_uda1380.c
sound/soc/samsung/i2s.c
sound/soc/samsung/jive_wm8750.c
sound/soc/samsung/neo1973_wm8753.c
sound/soc/samsung/pcm.c
sound/soc/samsung/rx1950_uda1380.c
sound/soc/samsung/s3c-i2s-v2.c
sound/soc/samsung/s3c2412-i2s.c
sound/soc/samsung/s3c24xx-i2s.c
sound/soc/samsung/s3c24xx_simtec.c
sound/soc/samsung/s3c24xx_simtec_hermes.c
sound/soc/samsung/s3c24xx_simtec_tlv320aic23.c
sound/soc/samsung/s3c24xx_uda134x.c
sound/soc/samsung/smartq_wm8987.c
sound/soc/samsung/smdk_wm8580.c
sound/soc/samsung/smdk_wm8580pcm.c
sound/soc/samsung/smdk_wm8994.c
sound/soc/samsung/spdif.c
sound/soc/samsung/speyside.c
sound/soc/samsung/speyside_wm8962.c
sound/soc/sh/fsi.c
sound/soc/sh/sh7760-ac97.c
sound/soc/sh/ssi.c
sound/soc/soc-cache.c
sound/soc/soc-core.c
sound/soc/soc-dapm.c
sound/soc/soc-io.c
sound/soc/soc-jack.c
sound/soc/soc-pcm.c
sound/soc/tegra/tegra_das.c
sound/soc/tegra/tegra_i2s.c
sound/soc/tegra/tegra_pcm.c
sound/soc/tegra/tegra_spdif.c
sound/soc/tegra/tegra_wm8903.c
sound/soc/tegra/trimslice.c
sound/soc/txx9/txx9aclc-ac97.c
sound/soc/txx9/txx9aclc-generic.c
sound/sparc/amd7930.c
sound/usb/6fire/firmware.c
sound/usb/Kconfig
sound/usb/Makefile
sound/usb/caiaq/device.c
sound/usb/caiaq/device.h
sound/usb/caiaq/input.c
sound/usb/card.c
sound/usb/card.h
sound/usb/clock.c
sound/usb/endpoint.c
sound/usb/endpoint.h
sound/usb/format.c
sound/usb/helper.c
sound/usb/helper.h
sound/usb/midi.c
sound/usb/mixer.c
sound/usb/mixer_quirks.c
sound/usb/pcm.c
sound/usb/pcm.h
sound/usb/quirks-table.h
sound/usb/quirks.c
sound/usb/stream.c [new file with mode: 0644]
sound/usb/stream.h [new file with mode: 0644]
sound/usb/urb.c [deleted file]
sound/usb/urb.h [deleted file]
sound/usb/usbaudio.h
virt/kvm/assigned-dev.c
virt/kvm/coalesced_mmio.c
virt/kvm/coalesced_mmio.h
virt/kvm/eventfd.c
virt/kvm/ioapic.c
virt/kvm/iommu.c
virt/kvm/kvm_main.c

diff --git a/Documentation/ABI/testing/debugfs-ideapad b/Documentation/ABI/testing/debugfs-ideapad
new file mode 100644 (file)
index 0000000..7079c0b
--- /dev/null
@@ -0,0 +1,19 @@
+What:          /sys/kernel/debug/ideapad/cfg
+Date:          Sep 2011
+KernelVersion: 3.2
+Contact:       Ike Panhc <ike.pan@canonical.com>
+Description:
+
+cfg shows the return value of _CFG method in VPC2004 device. It tells machine
+capability and what graphic component within the machine.
+
+
+What:          /sys/kernel/debug/ideapad/status
+Date:          Sep 2011
+KernelVersion: 3.2
+Contact:       Ike Panhc <ike.pan@canonical.com>
+Description:
+
+status shows infos we can read and tells its meaning and value.
+
+
index c1eb41cb9876083d3df79a6a995b692762acd21b..2b5d56127fce4d7f9a6f83b535cdfcf469f83e0b 100644 (file)
@@ -206,3 +206,16 @@ Description:
                when a discarded area is read the discard_zeroes_data
                parameter will be set to one. Otherwise it will be 0 and
                the result of reading a discarded area is undefined.
+What:          /sys/block/<disk>/alias
+Date:          Aug 2011
+Contact:       Nao Nishijima <nao.nishijima.xt@hitachi.com>
+Description:
+               A raw device name of a disk does not always point a same disk
+               each boot-up time. Therefore, users have to use persistent
+               device names, which udev creates when the kernel finds a disk,
+               instead of raw device name. However, kernel doesn't show those
+               persistent names on its messages (e.g. dmesg).
+               This file can store an alias of the disk and it would be
+               appeared in kernel messages if it is set. A disk can have an
+               alias which length is up to 255bytes. Users can use alphabets,
+               numbers, "-" and "_" in alias name. This file is writeonce.
index ff53183c3848d20ea357c276fb1bf930693cbd5c..814b01354c414caf71337d115b41fc92c89769b8 100644 (file)
@@ -5,19 +5,4 @@ Contact:       "Ike Panhc <ike.pan@canonical.com>"
 Description:
                Control the power of camera module. 1 means on, 0 means off.
 
-What:          /sys/devices/platform/ideapad/cfg
-Date:          Jun 2011
-KernelVersion: 3.1
-Contact:       "Ike Panhc <ike.pan@canonical.com>"
-Description:
-               Ideapad capability bits.
-               Bit 8-10: 1 - Intel graphic only
-                         2 - ATI graphic only
-                         3 - Nvidia graphic only
-                         4 - Intel and ATI graphic
-                         5 - Intel and Nvidia graphic
-               Bit 16: Bluetooth exist (1 for exist)
-               Bit 17: 3G exist (1 for exist)
-               Bit 18: Wifi exist (1 for exist)
-               Bit 19: Camera exist (1 for exist)
 
index 207e1a5bf8f027d8ae073fdabe107a8741598494..3bc8a61efe301a4b32bd89862efd28219e9315c4 100644 (file)
@@ -352,6 +352,7 @@ typedef enum fe_delivery_system {
        SYS_CMMB,
        SYS_DAB,
        SYS_DVBT2,
+       SYS_TURBO,
 } fe_delivery_system_t;
 </programlisting>
                </section>
@@ -809,6 +810,8 @@ typedef enum fe_hierarchy {
                        <listitem><para><link linkend="DTV-INVERSION"><constant>DTV_INVERSION</constant></link></para></listitem>
                        <listitem><para><link linkend="DTV-SYMBOL-RATE"><constant>DTV_SYMBOL_RATE</constant></link></para></listitem>
                        <listitem><para><link linkend="DTV-INNER-FEC"><constant>DTV_INNER_FEC</constant></link></para></listitem>
+                       <listitem><para><link linkend="DTV-VOLTAGE"><constant>DTV_VOLTAGE</constant></link></para></listitem>
+                       <listitem><para><link linkend="DTV-TONE"><constant>DTV_TONE</constant></link></para></listitem>
                </itemizedlist>
                <para>Future implementations might add those two missing parameters:</para>
                <itemizedlist mark='opencircle'>
@@ -818,25 +821,18 @@ typedef enum fe_hierarchy {
        </section>
        <section id="dvbs2-params">
                <title>DVB-S2 delivery system</title>
-               <para>The following parameters are valid for DVB-S2:</para>
+               <para>In addition to all parameters valid for DVB-S, DVB-S2 supports the following parameters:</para>
                <itemizedlist mark='opencircle'>
-                       <listitem><para><link linkend="DTV-API-VERSION"><constant>DTV_API_VERSION</constant></link></para></listitem>
-                       <listitem><para><link linkend="DTV-DELIVERY-SYSTEM"><constant>DTV_DELIVERY_SYSTEM</constant></link></para></listitem>
-                       <listitem><para><link linkend="DTV-TUNE"><constant>DTV_TUNE</constant></link></para></listitem>
-                       <listitem><para><link linkend="DTV-CLEAR"><constant>DTV_CLEAR</constant></link></para></listitem>
-                       <listitem><para><link linkend="DTV-FREQUENCY"><constant>DTV_FREQUENCY</constant></link></para></listitem>
-                       <listitem><para><link linkend="DTV-INVERSION"><constant>DTV_INVERSION</constant></link></para></listitem>
-                       <listitem><para><link linkend="DTV-SYMBOL-RATE"><constant>DTV_SYMBOL_RATE</constant></link></para></listitem>
-                       <listitem><para><link linkend="DTV-INNER-FEC"><constant>DTV_INNER_FEC</constant></link></para></listitem>
-                       <listitem><para><link linkend="DTV-VOLTAGE"><constant>DTV_VOLTAGE</constant></link></para></listitem>
-                       <listitem><para><link linkend="DTV-TONE"><constant>DTV_TONE</constant></link></para></listitem>
+                       <listitem><para><link linkend="DTV-MODULATION"><constant>DTV_MODULATION</constant></link></para></listitem>
                        <listitem><para><link linkend="DTV-PILOT"><constant>DTV_PILOT</constant></link></para></listitem>
                        <listitem><para><link linkend="DTV-ROLLOFF"><constant>DTV_ROLLOFF</constant></link></para></listitem>
                </itemizedlist>
-               <para>Future implementations might add those two missing parameters:</para>
+       </section>
+       <section id="turbo-params">
+               <title>Turbo code delivery system</title>
+               <para>In addition to all parameters valid for DVB-S, turbo code supports the following parameters:</para>
                <itemizedlist mark='opencircle'>
-                       <listitem><para><link linkend="DTV-DISEQC-MASTER"><constant>DTV_DISEQC_MASTER</constant></link></para></listitem>
-                       <listitem><para><link linkend="DTV-DISEQC-SLAVE-REPLY"><constant>DTV_DISEQC_SLAVE_REPLY</constant></link></para></listitem>
+                       <listitem><para><link linkend="DTV-MODULATION"><constant>DTV_MODULATION</constant></link></para></listitem>
                </itemizedlist>
        </section>
        <section id="isdbs-params">
index c75dc7cc3e9b6ec167b7fa7091532df7aeac4bd6..170064a3dc8f4b3db90bb348331ec777074f84c2 100644 (file)
@@ -205,7 +205,7 @@ a partial path like:</para>
 additional include file <emphasis
 role="tt">linux/dvb/version.h</emphasis> exists, which defines the
 constant <emphasis role="tt">DVB_API_VERSION</emphasis>. This document
-describes <emphasis role="tt">DVB_API_VERSION&#x00A0;3</emphasis>.
+describes <emphasis role="tt">DVB_API_VERSION 5.4</emphasis>.
 </para>
 
 </section>
index ce1004a7da5233f96d1a33636a11b24879ae69a1..91410b6e7e08cf6a3eaabb036fb3e90c4983f6e2 100644 (file)
@@ -2370,6 +2370,14 @@ that used it. It was originally scheduled for removal in 2.6.35.
         </listitem>
       </orderedlist>
     </section>
+    <section>
+      <title>V4L2 in Linux 3.2</title>
+      <orderedlist>
+        <listitem>
+         <para>V4L2_CTRL_FLAG_VOLATILE was added to signal volatile controls to userspace.</para>
+        </listitem>
+      </orderedlist>
+    </section>
 
     <section id="other">
       <title>Relation of V4L2 to other Linux multimedia APIs</title>
index 05c8fefcbcbe91fd01169472ee6fac5d6dbd8ab3..0916a7343a166b007f94da88fe8179b872b8be3b 100644 (file)
 
       <para>When satisfied with the try results, applications can set the active
       formats by setting the <structfield>which</structfield> argument to
-      <constant>V4L2_SUBDEV_FORMAT_TRY</constant>. Active formats are changed
+      <constant>V4L2_SUBDEV_FORMAT_ACTIVE</constant>. Active formats are changed
       exactly as try formats by drivers. To avoid modifying the hardware state
       during format negotiation, applications should negotiate try formats first
       and then modify the active settings using the try formats returned during
index 0d05e8747c12e24da9a2a4cebcdce4826e0858a4..40132c2776476a582bdf0eff818fc81c5f007c0f 100644 (file)
@@ -127,6 +127,13 @@ structs, ioctls) must be noted in more detail in the history chapter
 (compat.xml), along with the possible impact on existing drivers and
 applications. -->
 
+      <revision>
+       <revnumber>3.2</revnumber>
+       <date>2011-08-26</date>
+       <authorinitials>hv</authorinitials>
+       <revremark>Added V4L2_CTRL_FLAG_VOLATILE.</revremark>
+      </revision>
+
       <revision>
        <revnumber>3.1</revnumber>
        <date>2011-06-27</date>
@@ -410,7 +417,7 @@ and discussions on the V4L mailing list.</revremark>
 </partinfo>
 
 <title>Video for Linux Two API Specification</title>
- <subtitle>Revision 3.1</subtitle>
+ <subtitle>Revision 3.2</subtitle>
 
   <chapter id="common">
     &sub-common;
index 7769642ee431b11a83d423d260ea8ed1e87e66aa..e8714aa1643343de973e32f5abfa5e331b26bb7d 100644 (file)
            <entry>Event data for event V4L2_EVENT_CTRL.
             </entry>
          </row>
+         <row>
+           <entry></entry>
+           <entry>&v4l2-event-frame-sync;</entry>
+            <entry><structfield>frame</structfield></entry>
+           <entry>Event data for event V4L2_EVENT_FRAME_SYNC.</entry>
+         </row>
          <row>
            <entry></entry>
            <entry>__u8</entry>
       </tgroup>
     </table>
 
+    <table frame="none" pgwide="1" id="v4l2-event-vsync">
+      <title>struct <structname>v4l2_event_vsync</structname></title>
+      <tgroup cols="3">
+       &cs-str;
+       <tbody valign="top">
+         <row>
+           <entry>__u8</entry>
+           <entry><structfield>field</structfield></entry>
+           <entry>The upcoming field. See &v4l2-field;.</entry>
+         </row>
+       </tbody>
+      </tgroup>
+    </table>
+
+    <table frame="none" pgwide="1" id="v4l2-event-ctrl">
+      <title>struct <structname>v4l2_event_ctrl</structname></title>
+      <tgroup cols="4">
+       &cs-str;
+       <tbody valign="top">
+         <row>
+           <entry>__u32</entry>
+           <entry><structfield>changes</structfield></entry>
+           <entry></entry>
+           <entry>A bitmask that tells what has changed. See <xref linkend="changes-flags" />.</entry>
+         </row>
+         <row>
+           <entry>__u32</entry>
+           <entry><structfield>type</structfield></entry>
+           <entry></entry>
+           <entry>The type of the control. See &v4l2-ctrl-type;.</entry>
+         </row>
+         <row>
+           <entry>union (anonymous)</entry>
+           <entry></entry>
+           <entry></entry>
+           <entry></entry>
+         </row>
+         <row>
+           <entry></entry>
+           <entry>__s32</entry>
+           <entry><structfield>value</structfield></entry>
+           <entry>The 32-bit value of the control for 32-bit control types.
+               This is 0 for string controls since the value of a string
+               cannot be passed using &VIDIOC-DQEVENT;.</entry>
+         </row>
+         <row>
+           <entry></entry>
+           <entry>__s64</entry>
+           <entry><structfield>value64</structfield></entry>
+           <entry>The 64-bit value of the control for 64-bit control types.</entry>
+         </row>
+         <row>
+           <entry>__u32</entry>
+           <entry><structfield>flags</structfield></entry>
+           <entry></entry>
+           <entry>The control flags. See <xref linkend="control-flags" />.</entry>
+         </row>
+         <row>
+           <entry>__s32</entry>
+           <entry><structfield>minimum</structfield></entry>
+           <entry></entry>
+           <entry>The minimum value of the control. See &v4l2-queryctrl;.</entry>
+         </row>
+         <row>
+           <entry>__s32</entry>
+           <entry><structfield>maximum</structfield></entry>
+           <entry></entry>
+           <entry>The maximum value of the control. See &v4l2-queryctrl;.</entry>
+         </row>
+         <row>
+           <entry>__s32</entry>
+           <entry><structfield>step</structfield></entry>
+           <entry></entry>
+           <entry>The step value of the control. See &v4l2-queryctrl;.</entry>
+         </row>
+         <row>
+           <entry>__s32</entry>
+           <entry><structfield>default_value</structfield></entry>
+           <entry></entry>
+           <entry>The default value value of the control. See &v4l2-queryctrl;.</entry>
+         </row>
+       </tbody>
+      </tgroup>
+    </table>
+
+    <table frame="none" pgwide="1" id="v4l2-event-frame-sync">
+      <title>struct <structname>v4l2_event_frame_sync</structname></title>
+      <tgroup cols="3">
+       &cs-str;
+       <tbody valign="top">
+         <row>
+           <entry>__u32</entry>
+           <entry><structfield>frame_sequence</structfield></entry>
+           <entry>
+             The sequence number of the frame being received.
+           </entry>
+         </row>
+       </tbody>
+      </tgroup>
+    </table>
+
+    <table pgwide="1" frame="none" id="changes-flags">
+      <title>Changes</title>
+      <tgroup cols="3">
+       &cs-def;
+       <tbody valign="top">
+         <row>
+           <entry><constant>V4L2_EVENT_CTRL_CH_VALUE</constant></entry>
+           <entry>0x0001</entry>
+           <entry>This control event was triggered because the value of the control
+               changed. Special case: if a button control is pressed, then this
+               event is sent as well, even though there is not explicit value
+               associated with a button control.</entry>
+         </row>
+         <row>
+           <entry><constant>V4L2_EVENT_CTRL_CH_FLAGS</constant></entry>
+           <entry>0x0002</entry>
+           <entry>This control event was triggered because the control flags
+               changed.</entry>
+         </row>
+       </tbody>
+      </tgroup>
+    </table>
   </refsect1>
   <refsect1>
     &return-value;
index 677ea646c29fc71c6d8b9970cbb230d1784a46d1..0ac0057a51c4c9cb47da092159b955eb1ff11ad9 100644 (file)
@@ -406,6 +406,15 @@ flag is typically present for relative controls or action controls where
 writing a value will cause the device to carry out a given action
 (&eg; motor control) but no meaningful value can be returned.</entry>
          </row>
+         <row>
+           <entry><constant>V4L2_CTRL_FLAG_VOLATILE</constant></entry>
+           <entry>0x0080</entry>
+           <entry>This control is volatile, which means that the value of the control
+changes continuously. A typical example would be the current gain value if the device
+is in auto-gain mode. In such a case the hardware calculates the gain value based on
+the lighting conditions which can change over time. Note that setting a new value for
+a volatile control will have no effect. The new value will just be ignored.</entry>
+         </row>
        </tbody>
       </tgroup>
     </table>
index 69c0d8a2a3d2dd812847a30d59969209d8917127..5c70b616d8185c0645044b0e270398932a0d28c9 100644 (file)
                field of the oldest event.</para>
            </entry>
          </row>
+         <row>
+           <entry><constant>V4L2_EVENT_FRAME_SYNC</constant></entry>
+           <entry>4</entry>
+           <entry>
+             <para>Triggered immediately when the reception of a
+             frame has begun. This event has a
+             &v4l2-event-frame-sync; associated with it.</para>
+
+             <para>If the hardware needs to be stopped in the case of a
+             buffer underrun it might not be able to generate this event.
+             In such cases the <structfield>frame_sequence</structfield>
+             field in &v4l2-event-frame-sync; will not be incremented. This
+             causes two consecutive frame sequence numbers to have n times
+             frame interval in between them.</para>
+           </entry>
+         </row>
          <row>
            <entry><constant>V4L2_EVENT_PRIVATE_START</constant></entry>
            <entry>0x08000000</entry>
       </tgroup>
     </table>
 
-    <table frame="none" pgwide="1" id="v4l2-event-vsync">
-      <title>struct <structname>v4l2_event_vsync</structname></title>
-      <tgroup cols="3">
-       &cs-str;
-       <tbody valign="top">
-         <row>
-           <entry>__u8</entry>
-           <entry><structfield>field</structfield></entry>
-           <entry>The upcoming field. See &v4l2-field;.</entry>
-         </row>
-       </tbody>
-      </tgroup>
-    </table>
-
-    <table frame="none" pgwide="1" id="v4l2-event-ctrl">
-      <title>struct <structname>v4l2_event_ctrl</structname></title>
-      <tgroup cols="4">
-       &cs-str;
-       <tbody valign="top">
-         <row>
-           <entry>__u32</entry>
-           <entry><structfield>changes</structfield></entry>
-           <entry></entry>
-           <entry>A bitmask that tells what has changed. See <xref linkend="changes-flags" />.</entry>
-         </row>
-         <row>
-           <entry>__u32</entry>
-           <entry><structfield>type</structfield></entry>
-           <entry></entry>
-           <entry>The type of the control. See &v4l2-ctrl-type;.</entry>
-         </row>
-         <row>
-           <entry>union (anonymous)</entry>
-           <entry></entry>
-           <entry></entry>
-           <entry></entry>
-         </row>
-         <row>
-           <entry></entry>
-           <entry>__s32</entry>
-           <entry><structfield>value</structfield></entry>
-           <entry>The 32-bit value of the control for 32-bit control types.
-               This is 0 for string controls since the value of a string
-               cannot be passed using &VIDIOC-DQEVENT;.</entry>
-         </row>
-         <row>
-           <entry></entry>
-           <entry>__s64</entry>
-           <entry><structfield>value64</structfield></entry>
-           <entry>The 64-bit value of the control for 64-bit control types.</entry>
-         </row>
-         <row>
-           <entry>__u32</entry>
-           <entry><structfield>flags</structfield></entry>
-           <entry></entry>
-           <entry>The control flags. See <xref linkend="control-flags" />.</entry>
-         </row>
-         <row>
-           <entry>__s32</entry>
-           <entry><structfield>minimum</structfield></entry>
-           <entry></entry>
-           <entry>The minimum value of the control. See &v4l2-queryctrl;.</entry>
-         </row>
-         <row>
-           <entry>__s32</entry>
-           <entry><structfield>maximum</structfield></entry>
-           <entry></entry>
-           <entry>The maximum value of the control. See &v4l2-queryctrl;.</entry>
-         </row>
-         <row>
-           <entry>__s32</entry>
-           <entry><structfield>step</structfield></entry>
-           <entry></entry>
-           <entry>The step value of the control. See &v4l2-queryctrl;.</entry>
-         </row>
-         <row>
-           <entry>__s32</entry>
-           <entry><structfield>default_value</structfield></entry>
-           <entry></entry>
-           <entry>The default value value of the control. See &v4l2-queryctrl;.</entry>
-         </row>
-       </tbody>
-      </tgroup>
-    </table>
-
-    <table pgwide="1" frame="none" id="changes-flags">
-      <title>Changes</title>
-      <tgroup cols="3">
-       &cs-def;
-       <tbody valign="top">
-         <row>
-           <entry><constant>V4L2_EVENT_CTRL_CH_VALUE</constant></entry>
-           <entry>0x0001</entry>
-           <entry>This control event was triggered because the value of the control
-               changed. Special case: if a button control is pressed, then this
-               event is sent as well, even though there is not explicit value
-               associated with a button control.</entry>
-         </row>
-         <row>
-           <entry><constant>V4L2_EVENT_CTRL_CH_FLAGS</constant></entry>
-           <entry>0x0002</entry>
-           <entry>This control event was triggered because the control flags
-               changed.</entry>
-         </row>
-       </tbody>
-      </tgroup>
-    </table>
   </refsect1>
   <refsect1>
     &return-value;
index 598c22f3b3ac8f755b1595442698f9fc9294802a..5de23c00707828100ce750260ec71e727567d828 100644 (file)
@@ -4288,7 +4288,7 @@ struct _snd_pcm_runtime {
 <![CDATA[
   struct snd_rawmidi *rmidi;
   snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, port, info_flags,
-                      irq, irq_flags, &rmidi);
+                      irq, &rmidi);
 ]]>
           </programlisting>
         </informalexample>
@@ -4343,6 +4343,13 @@ struct _snd_pcm_runtime {
        by itself to start processing the output stream in the irq handler.
        </para>
 
+       <para>
+       If the MPU-401 interface shares its interrupt with the other logical
+       devices on the card, set <constant>MPU401_INFO_IRQ_HOOK</constant>
+       (see <link linkend="midi-interface-interrupt-handler"><citetitle>
+       below</citetitle></link>).
+       </para>
+
       <para>
         Usually, the port address corresponds to the command port and
         port + 1 corresponds to the data port. If not, you may change
@@ -4375,14 +4382,12 @@ struct _snd_pcm_runtime {
       </para>
 
       <para>
-        The 6th argument specifies the irq number for UART. If the irq
-      is already allocated, pass 0 to the 7th argument
-      (<parameter>irq_flags</parameter>). Otherwise, pass the flags
-      for irq allocation 
-      (<constant>SA_XXX</constant> bits) to it, and the irq will be
-      reserved by the mpu401-uart layer. If the card doesn't generate
-      UART interrupts, pass -1 as the irq number. Then a timer
-      interrupt will be invoked for polling. 
+       The 6th argument specifies the ISA irq number that will be
+       allocated.  If no interrupt is to be allocated (because your
+       code is already allocating a shared interrupt, or because the
+       device does not use interrupts), pass -1 instead.
+       For a MPU-401 device without an interrupt, a polling timer
+       will be used instead.
       </para>
     </section>
 
@@ -4390,12 +4395,13 @@ struct _snd_pcm_runtime {
       <title>Interrupt Handler</title>
       <para>
         When the interrupt is allocated in
-      <function>snd_mpu401_uart_new()</function>, the private
-      interrupt handler is used, hence you don't have anything else to do
-      than creating the mpu401 stuff. Otherwise, you have to call
-      <function>snd_mpu401_uart_interrupt()</function> explicitly when
-      a UART interrupt is invoked and checked in your own interrupt
-      handler.  
+      <function>snd_mpu401_uart_new()</function>, an exclusive ISA
+      interrupt handler is automatically used, hence you don't have
+      anything else to do than creating the mpu401 stuff.  Otherwise, you
+      have to set <constant>MPU401_INFO_IRQ_HOOK</constant>, and call
+      <function>snd_mpu401_uart_interrupt()</function> explicitly from your
+      own interrupt handler when it has determined that a UART interrupt
+      has occurred.
       </para>
 
       <para>
diff --git a/Documentation/devicetree/bindings/crypto/picochip-spacc.txt b/Documentation/devicetree/bindings/crypto/picochip-spacc.txt
new file mode 100644 (file)
index 0000000..d8609ec
--- /dev/null
@@ -0,0 +1,23 @@
+Picochip picoXcell SPAcc (Security Protocol Accelerator) bindings
+
+Picochip picoXcell devices contain crypto offload engines that may be used for
+IPSEC and femtocell layer 2 ciphering.
+
+Required properties:
+  - compatible : "picochip,spacc-ipsec" for the IPSEC offload engine
+    "picochip,spacc-l2" for the femtocell layer 2 ciphering engine.
+  - reg : Offset and length of the register set for this device
+  - interrupt-parent : The interrupt controller that controls the SPAcc
+    interrupt.
+  - interrupts : The interrupt line from the SPAcc.
+  - ref-clock : The input clock that drives the SPAcc.
+
+Example SPAcc node:
+
+spacc@10000 {
+       compatible = "picochip,spacc-ipsec";
+       reg = <0x100000 0x10000>;
+       interrupt-parent = <&vic0>;
+       interrupts = <24>;
+       ref-clock = <&ipsec_clk>, "ref";
+};
diff --git a/Documentation/devicetree/bindings/mmc/nvidia-sdhci.txt b/Documentation/devicetree/bindings/mmc/nvidia-sdhci.txt
new file mode 100644 (file)
index 0000000..7e51154
--- /dev/null
@@ -0,0 +1,27 @@
+* NVIDIA Tegra Secure Digital Host Controller
+
+This controller on Tegra family SoCs provides an interface for MMC, SD,
+and SDIO types of memory cards.
+
+Required properties:
+- compatible : Should be "nvidia,<chip>-sdhci"
+- reg : Should contain SD/MMC registers location and length
+- interrupts : Should contain SD/MMC interrupt
+
+Optional properties:
+- cd-gpios : Specify GPIOs for card detection
+- wp-gpios : Specify GPIOs for write protection
+- power-gpios : Specify GPIOs for power control
+- support-8bit : Boolean, indicates if 8-bit mode should be used.
+
+Example:
+
+sdhci@c8000200 {
+       compatible = "nvidia,tegra20-sdhci";
+       reg = <0xc8000200 0x200>;
+       interrupts = <47>;
+       cd-gpios = <&gpio 69 0>; /* gpio PI5 */
+       wp-gpios = <&gpio 57 0>; /* gpio PH1 */
+       power-gpios = <&gpio 155 0>; /* gpio PT3 */
+       support-8bit;
+};
diff --git a/Documentation/devicetree/bindings/sound/soc/codecs/fsl-sgtl5000.txt b/Documentation/devicetree/bindings/sound/soc/codecs/fsl-sgtl5000.txt
new file mode 100644 (file)
index 0000000..2c3cd41
--- /dev/null
@@ -0,0 +1,11 @@
+* Freescale SGTL5000 Stereo Codec
+
+Required properties:
+- compatible : "fsl,sgtl5000".
+
+Example:
+
+codec: sgtl5000@0a {
+       compatible = "fsl,sgtl5000";
+       reg = <0x0a>;
+};
diff --git a/Documentation/devicetree/bindings/sound/wm8510.txt b/Documentation/devicetree/bindings/sound/wm8510.txt
new file mode 100644 (file)
index 0000000..fa1a32b
--- /dev/null
@@ -0,0 +1,18 @@
+WM8510 audio CODEC
+
+This device supports both I2C and SPI (configured with pin strapping
+on the board).
+
+Required properties:
+
+  - compatible : "wlf,wm8510"
+
+  - reg : the I2C address of the device for I2C, the chip select
+          number for SPI.
+
+Example:
+
+codec: wm8510@1a {
+       compatible = "wlf,wm8510";
+       reg = <0x1a>;
+};
diff --git a/Documentation/devicetree/bindings/sound/wm8523.txt b/Documentation/devicetree/bindings/sound/wm8523.txt
new file mode 100644 (file)
index 0000000..0474618
--- /dev/null
@@ -0,0 +1,16 @@
+WM8523 audio CODEC
+
+This device supports I2C only.
+
+Required properties:
+
+  - compatible : "wlf,wm8523"
+
+  - reg : the I2C address of the device.
+
+Example:
+
+codec: wm8523@1a {
+       compatible = "wlf,wm8523";
+       reg = <0x1a>;
+};
diff --git a/Documentation/devicetree/bindings/sound/wm8580.txt b/Documentation/devicetree/bindings/sound/wm8580.txt
new file mode 100644 (file)
index 0000000..7d9821f
--- /dev/null
@@ -0,0 +1,16 @@
+WM8580 audio CODEC
+
+This device supports I2C only.
+
+Required properties:
+
+  - compatible : "wlf,wm8580"
+
+  - reg : the I2C address of the device.
+
+Example:
+
+codec: wm8580@1a {
+       compatible = "wlf,wm8580";
+       reg = <0x1a>;
+};
diff --git a/Documentation/devicetree/bindings/sound/wm8711.txt b/Documentation/devicetree/bindings/sound/wm8711.txt
new file mode 100644 (file)
index 0000000..8ed9998
--- /dev/null
@@ -0,0 +1,18 @@
+WM8711 audio CODEC
+
+This device supports both I2C and SPI (configured with pin strapping
+on the board).
+
+Required properties:
+
+  - compatible : "wlf,wm8711"
+
+  - reg : the I2C address of the device for I2C, the chip select
+          number for SPI.
+
+Example:
+
+codec: wm8711@1a {
+       compatible = "wlf,wm8711";
+       reg = <0x1a>;
+};
diff --git a/Documentation/devicetree/bindings/sound/wm8728.txt b/Documentation/devicetree/bindings/sound/wm8728.txt
new file mode 100644 (file)
index 0000000..a8b5c36
--- /dev/null
@@ -0,0 +1,18 @@
+WM8728 audio CODEC
+
+This device supports both I2C and SPI (configured with pin strapping
+on the board).
+
+Required properties:
+
+  - compatible : "wlf,wm8728"
+
+  - reg : the I2C address of the device for I2C, the chip select
+          number for SPI.
+
+Example:
+
+codec: wm8728@1a {
+       compatible = "wlf,wm8728";
+       reg = <0x1a>;
+};
diff --git a/Documentation/devicetree/bindings/sound/wm8731.txt b/Documentation/devicetree/bindings/sound/wm8731.txt
new file mode 100644 (file)
index 0000000..15f7004
--- /dev/null
@@ -0,0 +1,18 @@
+WM8731 audio CODEC
+
+This device supports both I2C and SPI (configured with pin strapping
+on the board).
+
+Required properties:
+
+  - compatible : "wlf,wm8731"
+
+  - reg : the I2C address of the device for I2C, the chip select
+          number for SPI.
+
+Example:
+
+codec: wm8731@1a {
+       compatible = "wlf,wm8731";
+       reg = <0x1a>;
+};
diff --git a/Documentation/devicetree/bindings/sound/wm8737.txt b/Documentation/devicetree/bindings/sound/wm8737.txt
new file mode 100644 (file)
index 0000000..4bc2cea
--- /dev/null
@@ -0,0 +1,18 @@
+WM8737 audio CODEC
+
+This device supports both I2C and SPI (configured with pin strapping
+on the board).
+
+Required properties:
+
+  - compatible : "wlf,wm8737"
+
+  - reg : the I2C address of the device for I2C, the chip select
+          number for SPI.
+
+Example:
+
+codec: wm8737@1a {
+       compatible = "wlf,wm8737";
+       reg = <0x1a>;
+};
diff --git a/Documentation/devicetree/bindings/sound/wm8741.txt b/Documentation/devicetree/bindings/sound/wm8741.txt
new file mode 100644 (file)
index 0000000..74bda58
--- /dev/null
@@ -0,0 +1,18 @@
+WM8741 audio CODEC
+
+This device supports both I2C and SPI (configured with pin strapping
+on the board).
+
+Required properties:
+
+  - compatible : "wlf,wm8741"
+
+  - reg : the I2C address of the device for I2C, the chip select
+          number for SPI.
+
+Example:
+
+codec: wm8741@1a {
+       compatible = "wlf,wm8741";
+       reg = <0x1a>;
+};
diff --git a/Documentation/devicetree/bindings/sound/wm8750.txt b/Documentation/devicetree/bindings/sound/wm8750.txt
new file mode 100644 (file)
index 0000000..8db239f
--- /dev/null
@@ -0,0 +1,18 @@
+WM8750 and WM8987 audio CODECs
+
+These devices support both I2C and SPI (configured with pin strapping
+on the board).
+
+Required properties:
+
+  - compatible : "wlf,wm8750" or "wlf,wm8987"
+
+  - reg : the I2C address of the device for I2C, the chip select
+          number for SPI.
+
+Example:
+
+codec: wm8750@1a {
+       compatible = "wlf,wm8750";
+       reg = <0x1a>;
+};
diff --git a/Documentation/devicetree/bindings/sound/wm8753.txt b/Documentation/devicetree/bindings/sound/wm8753.txt
new file mode 100644 (file)
index 0000000..e65277a
--- /dev/null
@@ -0,0 +1,18 @@
+WM8753 audio CODEC
+
+This device supports both I2C and SPI (configured with pin strapping
+on the board).
+
+Required properties:
+
+  - compatible : "wlf,wm8753"
+
+  - reg : the I2C address of the device for I2C, the chip select
+          number for SPI.
+
+Example:
+
+codec: wm8737@1a {
+       compatible = "wlf,wm8753";
+       reg = <0x1a>;
+};
diff --git a/Documentation/devicetree/bindings/sound/wm8770.txt b/Documentation/devicetree/bindings/sound/wm8770.txt
new file mode 100644 (file)
index 0000000..866e00c
--- /dev/null
@@ -0,0 +1,16 @@
+WM8770 audio CODEC
+
+This device supports SPI.
+
+Required properties:
+
+  - compatible : "wlf,wm8770"
+
+  - reg : the chip select number.
+
+Example:
+
+codec: wm8770@1 {
+       compatible = "wlf,wm8770";
+       reg = <1>;
+};
diff --git a/Documentation/devicetree/bindings/sound/wm8776.txt b/Documentation/devicetree/bindings/sound/wm8776.txt
new file mode 100644 (file)
index 0000000..3b9ca49
--- /dev/null
@@ -0,0 +1,18 @@
+WM8776 audio CODEC
+
+This device supports both I2C and SPI (configured with pin strapping
+on the board).
+
+Required properties:
+
+  - compatible : "wlf,wm8776"
+
+  - reg : the I2C address of the device for I2C, the chip select
+          number for SPI.
+
+Example:
+
+codec: wm8776@1a {
+       compatible = "wlf,wm8776";
+       reg = <0x1a>;
+};
diff --git a/Documentation/devicetree/bindings/sound/wm8804.txt b/Documentation/devicetree/bindings/sound/wm8804.txt
new file mode 100644 (file)
index 0000000..4d3a56f
--- /dev/null
@@ -0,0 +1,18 @@
+WM8804 audio CODEC
+
+This device supports both I2C and SPI (configured with pin strapping
+on the board).
+
+Required properties:
+
+  - compatible : "wlf,wm8804"
+
+  - reg : the I2C address of the device for I2C, the chip select
+          number for SPI.
+
+Example:
+
+codec: wm8804@1a {
+       compatible = "wlf,wm8804";
+       reg = <0x1a>;
+};
index c466f5831f15040912e447b70a9cc196cab9cfb7..e67be7afc78b481d4dc42553bc555690e34c898e 100755 (executable)
@@ -27,7 +27,8 @@ use IO::Handle;
                "or51211", "or51132_qam", "or51132_vsb", "bluebird",
                "opera1", "cx231xx", "cx18", "cx23885", "pvrusb2", "mpc718",
                "af9015", "ngene", "az6027", "lme2510_lg", "lme2510c_s7395",
-               "lme2510c_s7395_old", "drxk", "drxk_terratec_h5");
+               "lme2510c_s7395_old", "drxk", "drxk_terratec_h5", "tda10071",
+               "it9135" );
 
 # Check args
 syntax() if (scalar(@ARGV) != 1);
@@ -575,19 +576,10 @@ sub ngene {
 }
 
 sub az6027{
-    my $file = "AZ6027_Linux_Driver.tar.gz";
-    my $url = "http://linux.terratec.de/files/$file";
     my $firmware = "dvb-usb-az6027-03.fw";
+    my $url = "http://linux.terratec.de/files/TERRATEC_S7/$firmware";
 
-    wgetfile($file, $url);
-
-    #untar
-    if( system("tar xzvf $file $firmware")){
-        die "failed to untar firmware";
-    }
-    if( system("rm $file")){
-        die ("unable to remove unnecessary files");
-    }
+    wgetfile($firmware, $url);
 
     $firmware;
 }
@@ -665,6 +657,41 @@ sub drxk_terratec_h5 {
     "$fwfile"
 }
 
+sub it9135 {
+    my $url = "http://kworld.server261.com/kworld/CD/ITE_TiVme/V1.00/";
+    my $zipfile = "Driver_V10.323.1.0412.100412.zip";
+    my $hash = "79b597dc648698ed6820845c0c9d0d37";
+    my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 0);
+    my $drvfile = "Driver_V10.323.1.0412.100412/Data/x86/IT9135BDA.sys";
+    my $fwfile = "dvb-usb-it9137-01.fw";
+
+    checkstandard();
+
+    wgetfile($zipfile, $url . $zipfile);
+    verify($zipfile, $hash);
+    unzip($zipfile, $tmpdir);
+    extract("$tmpdir/$drvfile", 69632, 5731, "$fwfile");
+
+    "$fwfile"
+}
+
+sub tda10071 {
+    my $sourcefile = "PCTV_460e_reference.zip";
+    my $url = "ftp://ftp.pctvsystems.com/TV/driver/PCTV%2070e%2080e%20100e%20320e%20330e%20800e/";
+    my $hash = "4403de903bf2593464c8d74bbc200a57";
+    my $fwfile = "dvb-fe-tda10071.fw";
+    my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
+
+    checkstandard();
+
+    wgetfile($sourcefile, $url . $sourcefile);
+    verify($sourcefile, $hash);
+    unzip($sourcefile, $tmpdir);
+    extract("$tmpdir/PCTV\ 70e\ 80e\ 100e\ 320e\ 330e\ 800e/32\ bit/emOEM.sys", 0x67d38, 40504, $fwfile);
+
+    "$fwfile";
+}
+
 # ---------------------------------------------------------------
 # Utilities
 
diff --git a/Documentation/dvb/it9137.txt b/Documentation/dvb/it9137.txt
new file mode 100644 (file)
index 0000000..9e6726e
--- /dev/null
@@ -0,0 +1,9 @@
+To extract firmware for Kworld UB499-2T (id 1b80:e409) you need to copy the
+following file(s) to this directory.
+
+IT9135BDA.sys Dated Mon 22 Mar 2010 02:20:08 GMT
+
+extract using dd
+dd if=IT9135BDA.sys ibs=1 skip=69632 count=5731 of=dvb-usb-it9137-01.fw
+
+copy to default firmware location.
index 82a5d250d75e705f92b8c32ff634ca1b945ef008..ba4be8b77093f2ea0399ae7c6662471e987a98e0 100644 (file)
@@ -21,6 +21,11 @@ o fail_make_request
   /sys/block/<device>/make-it-fail or
   /sys/block/<device>/<partition>/make-it-fail. (generic_make_request())
 
+o fail_mmc_request
+
+  injects MMC data errors on devices permitted by setting
+  debugfs entries under /sys/kernel/debug/mmc0/fail_mmc_request
+
 Configure fault-injection capabilities behavior
 -----------------------------------------------
 
@@ -115,7 +120,8 @@ use the boot option:
 
        failslab=
        fail_page_alloc=
-       fail_make_request=<interval>,<probability>,<space>,<times>
+       fail_make_request=
+       mmc_core.fail_request=<interval>,<probability>,<space>,<times>
 
 How to add new fault injection capability
 -----------------------------------------
index 7fdde2a02a27be74e7e45508e449b5376b28abca..57d2f2908b12bcb01eae4669e3f0d50eeabf9d7e 100644 (file)
@@ -87,23 +87,38 @@ Special configuration for udlfb is usually unnecessary. There are a few
 options, however.
 
 From the command line, pass options to modprobe
-modprobe udlfb defio=1 console=1
+modprobe udlfb fb_defio=0 console=1 shadow=1
 
-Or for permanent option, create file like /etc/modprobe.d/options with text
-options udlfb defio=1 console=1
+Or modify options on the fly at /sys/module/udlfb/parameters directory via
+sudo nano fb_defio
+change the parameter in place, and save the file.
 
-Accepted options:
+Unplug/replug USB device to apply with new settings
+
+Or for permanent option, create file like /etc/modprobe.d/udlfb.conf with text
+options udlfb fb_defio=0 console=1 shadow=1
+
+Accepted boolean options:
 
 fb_defio       Make use of the fb_defio (CONFIG_FB_DEFERRED_IO) kernel
                module to track changed areas of the framebuffer by page faults.
-               Standard fbdev applications that use mmap but that do not
-               report damage, may be able to work with this enabled.
-               Disabled by default because of overhead and other issues.
-
-console                Allow fbcon to attach to udlfb provided framebuffers. This
-               is disabled by default because fbcon will aggressively consume
-               the first framebuffer it finds, which isn't usually what the
-               user wants in the case of USB displays.
+               Standard fbdev applications that use mmap but that do not
+               report damage, should be able to work with this enabled.
+               Disable when running with X server that supports reporting
+               changed regions via ioctl, as this method is simpler,
+               more stable, and higher performance.
+               default: fb_defio=1
+
+console        Allow fbcon to attach to udlfb provided framebuffers.
+               Can be disabled if fbcon and other clients
+               (e.g. X with --shared-vt) are in conflict.
+               default: console=1
+
+shadow         Allocate a 2nd framebuffer to shadow what's currently across
+               the USB bus in device memory. If any pixels are unchanged,
+               do not transmit. Spends host memory to save USB transfers.
+               Enabled by default. Only disable on very low memory systems.
+               default: shadow=1
 
 Sysfs Attributes
 ================
index d5ac362daef50f9b7fad5f3ea39188413fe6604a..7c799fc5b88e3525e611066d7be26c06226fd3db 100644 (file)
@@ -495,29 +495,6 @@ Who:       Jean Delvare <khali@linux-fr.org>
 
 ----------------------------
 
-What:  Support for UVCIOC_CTRL_ADD in the uvcvideo driver
-When:  3.2
-Why:   The information passed to the driver by this ioctl is now queried
-       dynamically from the device.
-Who:   Laurent Pinchart <laurent.pinchart@ideasonboard.com>
-
-----------------------------
-
-What:  Support for UVCIOC_CTRL_MAP_OLD in the uvcvideo driver
-When:  3.2
-Why:   Used only by applications compiled against older driver versions.
-       Superseded by UVCIOC_CTRL_MAP which supports V4L2 menu controls.
-Who:   Laurent Pinchart <laurent.pinchart@ideasonboard.com>
-
-----------------------------
-
-What:  Support for UVCIOC_CTRL_GET and UVCIOC_CTRL_SET in the uvcvideo driver
-When:  3.2
-Why:   Superseded by the UVCIOC_CTRL_QUERY ioctl.
-Who:   Laurent Pinchart <laurent.pinchart@ideasonboard.com>
-
-----------------------------
-
 What:  Support for driver specific ioctls in the pwc driver (everything
        defined in media/pwc-ioctl.h)
 When:  3.3
index 7c19d1a2bea0a4936a20bfaad6972800c8bf4794..49f5b680809d9bfa3a97973aae095bf601d3cfcc 100644 (file)
@@ -88,6 +88,10 @@ byte. But this time, the data is a complete word (16 bits).
 
 S Addr Wr [A] Comm [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P
 
+Note the convenience function i2c_smbus_read_word_swapped is
+available for reads where the two data bytes are the other way
+around (not SMBus compliant, but very popular.)
+
 
 SMBus Write Byte:  i2c_smbus_write_byte_data()
 ==============================================
@@ -108,6 +112,10 @@ specified through the Comm byte.
 
 S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] P
 
+Note the convenience function i2c_smbus_write_word_swapped is
+available for writes where the two data bytes are the other way
+around (not SMBus compliant, but very popular.)
+
 
 SMBus Process Call:  i2c_smbus_process_call()
 =============================================
index 93413ce96883cd1f62f5e0a1a8d556cbd6319aab..a0c5c5f4fce6e9587346a4a049c9725e5ca45de5 100644 (file)
@@ -741,10 +741,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
                        See Documentation/block/cfq-iosched.txt and
                        Documentation/block/deadline-iosched.txt for details.
 
-       elfcorehdr=     [IA-64,PPC,SH,X86]
+       elfcorehdr=[size[KMG]@]offset[KMG] [IA64,PPC,SH,X86,S390]
                        Specifies physical address of start of kernel core
-                       image elf header. Generally kexec loader will
-                       pass this option to capture kernel.
+                       image elf header and optionally the size. Generally
+                       kexec loader will pass this option to capture kernel.
                        See Documentation/kdump/kdump.txt for details.
 
        enable_mtrr_cleanup [X86]
@@ -973,6 +973,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
        ignore_loglevel [KNL]
                        Ignore loglevel setting - this will print /all/
                        kernel messages to the console. Useful for debugging.
+                       We also add it as printk module parameter, so users
+                       could change it dynamically, usually by
+                       /sys/module/printk/parameters/ignore_loglevel.
 
        ihash_entries=  [KNL]
                        Set number of hash buckets for inode cache.
@@ -1201,6 +1204,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
                        [KVM,Intel] Disable FlexPriority feature (TPR shadow).
                        Default is 1 (enabled)
 
+       kvm-intel.nested=
+                       [KVM,Intel] Enable VMX nesting (nVMX).
+                       Default is 0 (disabled)
+
        kvm-intel.unrestricted_guest=
                        [KVM,Intel] Disable unrestricted guest feature
                        (virtualized real and unpaged mode) on capable
@@ -1662,6 +1669,11 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
                        debugging driver suspend/resume hooks).  This may
                        not work reliably with all consoles, but is known
                        to work with serial and VGA consoles.
+                       To facilitate more flexible debugging, we also add
+                       console_suspend, a printk module parameter to control
+                       it. Users could use console_suspend (usually
+                       /sys/module/printk/parameters/console_suspend) to
+                       turn on/off it dynamically.
 
        noaliencache    [MM, NUMA, SLAB] Disables the allocation of alien
                        caches in the slab allocator.  Saves per-node memory,
index 29ad4b1064206ef8e4634470f45b9671a7d1cca9..e7fb2c6023bc896dec6dd348961dce06a7bff217 100644 (file)
@@ -1,61 +1,22 @@
-Copyright (c) 2009-2010 QLogic Corporation
+Copyright (c) 2009-2011 QLogic Corporation
 QLogic Linux qlcnic NIC Driver
 
-This program includes a device driver for Linux 2.6 that may be
-distributed with QLogic hardware specific firmware binary file.
 You may modify and redistribute the device driver code under the
 GNU General Public License (a copy of which is attached hereto as
 Exhibit A) published by the Free Software Foundation (version 2).
 
-You may redistribute the hardware specific firmware binary file
-under the following terms:
-
-       1. Redistribution of source code (only if applicable),
-          must retain the above copyright notice, this list of
-          conditions and the following disclaimer.
-
-       2. Redistribution in binary form must reproduce the above
-          copyright notice, this list of conditions and the
-          following disclaimer in the documentation and/or other
-          materials provided with the distribution.
-
-       3. The name of QLogic Corporation may not be used to
-          endorse or promote products derived from this software
-          without specific prior written permission
-
-REGARDLESS OF WHAT LICENSING MECHANISM IS USED OR APPLICABLE,
-THIS PROGRAM IS PROVIDED BY QLOGIC CORPORATION "AS IS'' AND ANY
-EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
-PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
-BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
-TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
-
-USER ACKNOWLEDGES AND AGREES THAT USE OF THIS PROGRAM WILL NOT
-CREATE OR GIVE GROUNDS FOR A LICENSE BY IMPLICATION, ESTOPPEL, OR
-OTHERWISE IN ANY INTELLECTUAL PROPERTY RIGHTS (PATENT, COPYRIGHT,
-TRADE SECRET, MASK WORK, OR OTHER PROPRIETARY RIGHT) EMBODIED IN
-ANY OTHER QLOGIC HARDWARE OR SOFTWARE EITHER SOLELY OR IN
-COMBINATION WITH THIS PROGRAM.
-
 
 EXHIBIT A
 
-                   GNU GENERAL PUBLIC LICENSE
-                      Version 2, June 1991
+                   GNU GENERAL PUBLIC LICENSE
+                      Version 2, June 1991
 
  Copyright (C) 1989, 1991 Free Software Foundation, Inc.
  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  Everyone is permitted to copy and distribute verbatim copies
  of this license document, but changing it is not allowed.
 
-                           Preamble
+                           Preamble
 
   The licenses for most software are designed to take away your
 freedom to share and change it.  By contrast, the GNU General Public
@@ -105,7 +66,7 @@ patent must be licensed for everyone's free use or not licensed at all.
   The precise terms and conditions for copying, distribution and
 modification follow.
 
-                   GNU GENERAL PUBLIC LICENSE
+                   GNU GENERAL PUBLIC LICENSE
    TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
 
   0. This License applies to any program or other work which contains
@@ -304,7 +265,7 @@ make exceptions for this.  Our decision will be guided by the two goals
 of preserving the free status of all derivatives of our free software and
 of promoting the sharing and reuse of software generally.
 
-                           NO WARRANTY
+                           NO WARRANTY
 
   11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
 FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
index b42419b52e444063841bcd6f0571ea0cde1eca84..ce63af0a8e35ecab32e2f326d13a9a2b33b62909 100644 (file)
@@ -16,7 +16,7 @@ initialisation code by creating a struct regulator_consumer_supply for
 each regulator.
 
 struct regulator_consumer_supply {
-       struct device *dev;     /* consumer */
+       const char *dev_name;   /* consumer dev_name() */
        const char *supply;     /* consumer supply - e.g. "vcc" */
 };
 
@@ -24,13 +24,13 @@ e.g. for the machine above
 
 static struct regulator_consumer_supply regulator1_consumers[] = {
 {
-       .dev    = &platform_consumerB_device.dev,
-       .supply = "Vcc",
+       .dev_name       = "dev_name(consumer B)",
+       .supply         = "Vcc",
 },};
 
 static struct regulator_consumer_supply regulator2_consumers[] = {
 {
-       .dev    = &platform_consumerA_device.dev,
+       .dev    = "dev_name(consumer A"),
        .supply = "Vcc",
 },};
 
@@ -43,6 +43,7 @@ to their supply regulator :-
 
 static struct regulator_init_data regulator1_data = {
        .constraints = {
+               .name = "Regulator-1",
                .min_uV = 3300000,
                .max_uV = 3300000,
                .valid_modes_mask = REGULATOR_MODE_NORMAL,
@@ -51,13 +52,19 @@ static struct regulator_init_data regulator1_data = {
        .consumer_supplies = regulator1_consumers,
 };
 
+The name field should be set to something that is usefully descriptive
+for the board for configuration of supplies for other regulators and
+for use in logging and other diagnostic output.  Normally the name
+used for the supply rail in the schematic is a good choice.  If no
+name is provided then the subsystem will choose one.
+
 Regulator-1 supplies power to Regulator-2. This relationship must be registered
 with the core so that Regulator-1 is also enabled when Consumer A enables its
 supply (Regulator-2). The supply regulator is set by the supply_regulator
-field below:-
+field below and co:-
 
 static struct regulator_init_data regulator2_data = {
-       .supply_regulator = "regulator_name",
+       .supply_regulator = "Regulator-1",
        .constraints = {
                .min_uV = 1800000,
                .max_uV = 2000000,
index c2e18e109858b288d29eafd9e9f7c8764a343dd8..b48ded55b555041bc638c0f003d6248217f60856 100644 (file)
@@ -28,6 +28,8 @@ LICENSE.FlashPoint
        - Licence of the Flashpoint driver
 LICENSE.qla2xxx
        - License for QLogic Linux Fibre Channel HBA Driver firmware.
+LICENSE.qla4xxx
+       - License for QLogic Linux iSCSI HBA Driver.
 Mylex.txt
        - info on driver for Mylex adapters
 NinjaSCSI.txt
index 1b6e27ddb7f3db06fd0dc935f953a66ae4cd77f2..64adb98b181c717f763bff24109bc8bf9aff104a 100644 (file)
@@ -1,3 +1,18 @@
+Release Date    : Wed. Oct 5, 2011 17:00:00 PST 2010 -
+                       (emaild-id:megaraidlinux@lsi.com)
+                       Adam Radford
+Current Version : 00.00.06.12-rc1
+Old Version     : 00.00.05.40-rc1
+    1. Continue booting immediately if FW in FAULT at driver load time.
+    2. Increase default cmds per lun to 256.
+    3. Fix mismatch in megasas_reset_fusion() mutex lock-unlock.
+    4. Remove some un-necessary code.
+    5. Clear state change interrupts for Fusion/Invader.
+    6. Clear FUSION_IN_RESET before enabling interrupts.
+    7. Add support for MegaRAID 9360/9380 12GB/s controllers.
+    8. Add multiple MSI-X vector/multiple reply queue support.
+    9. Add driver workaround for PERC5/1068 kdump kernel panic.
+-------------------------------------------------------------------------------
 Release Date    : Tue. Jul 26, 2011 17:00:00 PST 2010 -
                        (emaild-id:megaraidlinux@lsi.com)
                        Adam Radford
diff --git a/Documentation/scsi/LICENSE.qla4xxx b/Documentation/scsi/LICENSE.qla4xxx
new file mode 100644 (file)
index 0000000..494980e
--- /dev/null
@@ -0,0 +1,310 @@
+Copyright (c) 2003-2011 QLogic Corporation
+QLogic Linux iSCSI HBA Driver
+
+This program includes a device driver for Linux 3.x.
+You may modify and redistribute the device driver code under the
+GNU General Public License (a copy of which is attached hereto as
+Exhibit A) published by the Free Software Foundation (version 2).
+
+REGARDLESS OF WHAT LICENSING MECHANISM IS USED OR APPLICABLE,
+THIS PROGRAM IS PROVIDED BY QLOGIC CORPORATION "AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
+BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+
+USER ACKNOWLEDGES AND AGREES THAT USE OF THIS PROGRAM WILL NOT
+CREATE OR GIVE GROUNDS FOR A LICENSE BY IMPLICATION, ESTOPPEL, OR
+OTHERWISE IN ANY INTELLECTUAL PROPERTY RIGHTS (PATENT, COPYRIGHT,
+TRADE SECRET, MASK WORK, OR OTHER PROPRIETARY RIGHT) EMBODIED IN
+ANY OTHER QLOGIC HARDWARE OR SOFTWARE EITHER SOLELY OR IN
+COMBINATION WITH THIS PROGRAM.
+
+
+EXHIBIT A
+
+                   GNU GENERAL PUBLIC LICENSE
+                      Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                           Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                   GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+  2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) You must cause the modified files to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    b) You must cause any work that you distribute or publish, that in
+    whole or in part contains or is derived from the Program or any
+    part thereof, to be licensed as a whole at no charge to all third
+    parties under the terms of this License.
+
+    c) If the modified program normally reads commands interactively
+    when run, you must cause it, when started running for such
+    interactive use in the most ordinary way, to print or display an
+    announcement including an appropriate copyright notice and a
+    notice that there is no warranty (or else, saying that you provide
+    a warranty) and that users may redistribute the program under
+    these conditions, and telling the user how to view a copy of this
+    License.  (Exception: if the Program itself is interactive but
+    does not normally print such an announcement, your work based on
+    the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+    a) Accompany it with the complete corresponding machine-readable
+    source code, which must be distributed under the terms of Sections
+    1 and 2 above on a medium customarily used for software interchange; or,
+
+    b) Accompany it with a written offer, valid for at least three
+    years, to give any third party, for a charge no more than your
+    cost of physically performing source distribution, a complete
+    machine-readable copy of the corresponding source code, to be
+    distributed under the terms of Sections 1 and 2 above on a medium
+    customarily used for software interchange; or,
+
+    c) Accompany it with the information you received as to the offer
+    to distribute corresponding source code.  (This alternative is
+    allowed only for noncommercial distribution and only if you
+    received the program in object code or executable form with such
+    an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable.  However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+  5. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+  6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation.  If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+  10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission.  For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this.  Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+                           NO WARRANTY
+
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
diff --git a/Documentation/scsi/bnx2fc.txt b/Documentation/scsi/bnx2fc.txt
new file mode 100644 (file)
index 0000000..8082355
--- /dev/null
@@ -0,0 +1,75 @@
+Operating FCoE using bnx2fc
+===========================
+Broadcom FCoE offload through bnx2fc is full stateful hardware offload that
+cooperates with all interfaces provided by the Linux ecosystem for FC/FCoE and
+SCSI controllers.  As such, FCoE functionality, once enabled is largely
+transparent. Devices discovered on the SAN will be registered and unregistered
+automatically with the upper storage layers.
+
+Despite the fact that the Broadcom's FCoE offload is fully offloaded, it does
+depend on the state of the network interfaces to operate. As such, the network
+interface (e.g. eth0) associated with the FCoE offload initiator must be 'up'.
+It is recommended that the network interfaces be configured to be brought up
+automatically at boot time.
+
+Furthermore, the Broadcom FCoE offload solution creates VLAN interfaces to
+support the VLANs that have been discovered for FCoE operation (e.g.
+eth0.1001-fcoe).  Do not delete or disable these interfaces or FCoE operation
+will be disrupted.
+
+Driver Usage Model:
+===================
+
+1. Ensure that fcoe-utils package is installed.
+
+2. Configure the interfaces on which bnx2fc driver has to operate on.
+Here are the steps to configure:
+       a. cd /etc/fcoe
+       b. copy cfg-ethx to cfg-eth5 if FCoE has to be enabled on eth5.
+       c. Repeat this for all the interfaces where FCoE has to be enabled.
+       d. Edit all the cfg-eth files to set "no" for DCB_REQUIRED** field, and
+          "yes" for AUTO_VLAN.
+       e. Other configuration parameters should be left as default
+
+3. Ensure that "bnx2fc" is in SUPPORTED_DRIVERS list in /etc/fcoe/config.
+
+4. Start fcoe service. (service fcoe start). If Broadcom devices are present in
+the system, bnx2fc driver would automatically claim the interfaces, starts vlan
+discovery and log into the targets.
+
+5. "Symbolic Name" in 'fcoeadm -i' output would display if bnx2fc has claimed
+the interface.
+Eg:
+[root@bh2 ~]# fcoeadm -i
+    Description:      NetXtreme II BCM57712 10 Gigabit Ethernet
+    Revision:         01
+    Manufacturer:     Broadcom Corporation
+    Serial Number:    0010186FD558
+    Driver:           bnx2x 1.70.00-0
+    Number of Ports:  2
+
+        Symbolic Name:     bnx2fc v1.0.5 over eth5.4
+        OS Device Name:    host11
+        Node Name:         0x10000010186FD559
+        Port Name:         0x20000010186FD559
+        FabricName:        0x2001000DECB3B681
+        Speed:             10 Gbit
+        Supported Speed:   10 Gbit
+        MaxFrameSize:      2048
+        FC-ID (Port ID):   0x0F0377
+        State:             Online
+
+6. Verify the vlan discovery is performed by running ifconfig and notice
+<INTERFACE>.<VLAN>-fcoe interfaces are automatically created.
+
+Refer to fcoeadm manpage for more information on fcoeadm operations to
+create/destroy interfaces or to display lun/target information.
+
+NOTE:
+====
+** Broadcom FCoE capable devices implement a DCBX/LLDP client on-chip. Only one
+LLDP client is allowed per interface. For proper operation all host software
+based DCBX/LLDP clients (e.g. lldpad) must be disabled. To disable lldpad on a
+given interface, run the following command:
+
+lldptool set-lldp -i <interface_name> adminStatus=disabled
index 89757012c7ffda2d1babfd1dd9bc9d7e4d1604eb..936699e4f04b0abdf74788b66ace8ab1a16f66ff 100644 (file)
@@ -886,6 +886,12 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
                disable)
     power_save_controller - Reset HD-audio controller in power-saving mode
                (default = on)
+    align_buffer_size - Force rounding of buffer/period sizes to multiples
+                     of 128 bytes. This is more efficient in terms of memory
+                     access but isn't required by the HDA spec and prevents
+                     users from specifying exact period/buffer sizes.
+                     (default = on)
+    snoop      - Enable/disable snooping (default = on)
 
     This module supports multiple cards and autoprobe.
     
index 1482035243e677bfb21d2187e5fccb9cc01ce55c..e9621e349e1732b7d7dc75e2829b37f952f5a597 100644 (file)
@@ -98,3 +98,19 @@ Conexant codecs
 
 * Auto-Mute Mode
   See Reatek codecs.
+
+
+Analog codecs
+--------------
+
+* Channel Mode
+  This is an enum control to change the surround-channel setup,
+  appears only when the surround channels are available.
+  It gives the number of channels to be used, "2ch", "4ch" and "6ch".
+  According to the configuration, this also controls the
+  jack-retasking of multi-I/O jacks.
+
+* Independent HP
+  When this enum control is enabled, the headphone output is routed
+  from an individual stream (the third PCM such as hw:0,2) instead of
+  the primary stream.
index d70c93bdcadf16a8be454581c1cb611686102cf0..4f3443230d896b92c6a5aa7b37dfd5b63e272d9b 100644 (file)
@@ -29,9 +29,6 @@ ALC880
 
 ALC260
 ======
-  hp           HP machines
-  hp-3013      HP machines (3013-variant)
-  hp-dc7600    HP DC7600
   fujitsu      Fujitsu S7020
   acer         Acer TravelMate
   will         Will laptops (PB V7900)
@@ -46,15 +43,10 @@ ALC260
 ALC262
 ======
   fujitsu      Fujitsu Laptop
-  hp-bpc       HP xw4400/6400/8400/9400 laptops
-  hp-bpc-d7000 HP BPC D7000
-  hp-tc-t5735  HP Thin Client T5735
-  hp-rp5700    HP RP5700
   benq         Benq ED8
   benq-t31     Benq T31
   hippo                Hippo (ATI) with jack detection, Sony UX-90s
   hippo_1      Hippo (Benq) with jack detection
-  sony-assamd  Sony ASSAMD
   toshiba-s06  Toshiba S06
   toshiba-rx1  Toshiba RX1
   tyan         Tyan Thunder n6650W (S2915-E)
@@ -66,43 +58,15 @@ ALC262
 
 ALC267/268
 ==========
-  quanta-il1   Quanta IL1 mini-notebook
-  3stack       3-stack model
-  toshiba      Toshiba A205
-  acer         Acer laptops
-  acer-dmic    Acer laptops with digital-mic
-  acer-aspire  Acer Aspire One
-  dell         Dell OEM laptops (Vostro 1200)
-  zepto                Zepto laptops
-  test         for testing/debugging purpose, almost all controls can
-               adjusted.  Appearing only when compiled with
-               $CONFIG_SND_DEBUG=y
-  auto         auto-config reading BIOS (default)
+  N/A
 
 ALC269
 ======
-  basic                Basic preset
-  quanta       Quanta FL1
   laptop-amic  Laptops with analog-mic input
   laptop-dmic  Laptops with digital-mic input
-  fujitsu      FSC Amilo
-  lifebook     Fujitsu Lifebook S6420
-  auto         auto-config reading BIOS (default)
 
 ALC662/663/272
 ==============
-  3stack-dig   3-stack (2-channel) with SPDIF
-  3stack-6ch    3-stack (6-channel)
-  3stack-6ch-dig 3-stack (6-channel) with SPDIF
-  5stack-dig    5-stack with SPDIF
-  lenovo-101e   Lenovo laptop
-  eeepc-p701   ASUS Eeepc P701
-  eeepc-ep20   ASUS Eeepc EP20
-  ecs          ECS/Foxconn mobo
-  m51va                ASUS M51VA
-  g71v         ASUS G71V
-  h13          ASUS H13
-  g50v         ASUS G50V
   asus-mode1   ASUS
   asus-mode2   ASUS
   asus-mode3   ASUS
@@ -111,15 +75,10 @@ ALC662/663/272
   asus-mode6   ASUS
   asus-mode7   ASUS
   asus-mode8   ASUS
-  dell         Dell with ALC272
-  dell-zm1     Dell ZM1 with ALC272
-  samsung-nc10 Samsung NC10 mini notebook
-  auto         auto-config reading BIOS (default)
 
 ALC680
 ======
-  base         Base model (ASUS NX90)
-  auto         auto-config reading BIOS (default)
+  N/A
 
 ALC882/883/885/888/889
 ======================
@@ -175,28 +134,11 @@ ALC882/883/885/888/889
 
 ALC861/660
 ==========
-  3stack       3-jack
-  3stack-dig   3-jack with SPDIF I/O
-  6stack-dig   6-jack with SPDIF I/O
-  3stack-660   3-jack (for ALC660)
-  uniwill-m31  Uniwill M31 laptop
-  toshiba      Toshiba laptop support
-  asus         Asus laptop support
-  asus-laptop  ASUS F2/F3 laptops
-  auto         auto-config reading BIOS (default)
+  N/A
 
 ALC861VD/660VD
 ==============
-  3stack       3-jack
-  3stack-dig   3-jack with SPDIF OUT
-  6stack-dig   6-jack with SPDIF OUT
-  3stack-660   3-jack (for ALC660VD)
-  3stack-660-digout 3-jack with SPDIF OUT (for ALC660VD)
-  lenovo       Lenovo 3000 C200
-  dallas       Dallas laptops
-  hp           HP TX1000
-  asus-v1s     ASUS V1Sn
-  auto         auto-config reading BIOS (default)
+  N/A
 
 CMI9880
 =======
@@ -289,7 +231,6 @@ Conexant 5051
   hp-dv6736    HP dv6736
   hp-f700      HP Compaq Presario F700
   ideapad      Lenovo IdeaPad laptop
-  lenovo-x200  Lenovo X200 laptop
   toshiba      Toshiba Satellite M300
 
 Conexant 5066
index c82beb0076341856ca13b1e1dd125cc440ed439c..03e2771ddeef53545357cc4bfbde29a378f9206d 100644 (file)
@@ -447,7 +447,10 @@ The file needs to have a line `[codec]`.  The next line should contain
 three numbers indicating the codec vendor-id (0x12345678 in the
 example), the codec subsystem-id (0xabcd1234) and the address (2) of
 the codec.  The rest patch entries are applied to this specified codec
-until another codec entry is given.
+until another codec entry is given.  Passing 0 or a negative number to
+the first or the second value will make the check of the corresponding
+field be skipped.  It'll be useful for really broken devices that don't
+initialize SSID properly.
 
 The `[model]` line allows to change the model name of the each codec.
 In the example above, it will be changed to model=auto.
@@ -491,7 +494,7 @@ Also, the codec chip name can be rewritten via `[chip_name]` line.
 The hd-audio driver reads the file via request_firmware().  Thus,
 a patch file has to be located on the appropriate firmware path,
 typically, /lib/firmware.  For example, when you pass the option
-`patch=hda-init.fw`, the file /lib/firmware/hda-init-fw must be
+`patch=hda-init.fw`, the file /lib/firmware/hda-init.fw must be
 present.
 
 The patch module option is specific to each card instance, and you
@@ -524,6 +527,54 @@ power-saving.  See /sys/module/snd_hda_intel/parameters/power_save to
 check the current value.  If it's non-zero, the feature is turned on.
 
 
+Tracepoints
+~~~~~~~~~~~
+The hd-audio driver gives a few basic tracepoints.
+`hda:hda_send_cmd` traces each CORB write while `hda:hda_get_response`
+traces the response from RIRB (only when read from the codec driver).
+`hda:hda_bus_reset` traces the bus-reset due to fatal error, etc,
+`hda:hda_unsol_event` traces the unsolicited events, and
+`hda:hda_power_down` and `hda:hda_power_up` trace the power down/up
+via power-saving behavior.
+
+Enabling all tracepoints can be done like
+------------------------------------------------------------------------
+  # echo 1 > /sys/kernel/debug/tracing/events/hda/enable
+------------------------------------------------------------------------
+then after some commands, you can traces from
+/sys/kernel/debug/tracing/trace file.  For example, when you want to
+trace what codec command is sent, enable the tracepoint like:
+------------------------------------------------------------------------
+  # cat /sys/kernel/debug/tracing/trace
+  # tracer: nop
+  #
+  #       TASK-PID    CPU#    TIMESTAMP  FUNCTION
+  #          | |       |          |         |
+         <...>-7807  [002] 105147.774889: hda_send_cmd: [0:0] val=e3a019
+         <...>-7807  [002] 105147.774893: hda_send_cmd: [0:0] val=e39019
+         <...>-7807  [002] 105147.999542: hda_send_cmd: [0:0] val=e3a01a
+         <...>-7807  [002] 105147.999543: hda_send_cmd: [0:0] val=e3901a
+         <...>-26764 [001] 349222.837143: hda_send_cmd: [0:0] val=e3a019
+         <...>-26764 [001] 349222.837148: hda_send_cmd: [0:0] val=e39019
+         <...>-26764 [001] 349223.058539: hda_send_cmd: [0:0] val=e3a01a
+         <...>-26764 [001] 349223.058541: hda_send_cmd: [0:0] val=e3901a
+------------------------------------------------------------------------
+Here `[0:0]` indicates the card number and the codec address, and
+`val` shows the value sent to the codec, respectively.  The value is
+a packed value, and you can decode it via hda-decode-verb program
+included in hda-emu package below.  For example, the value e3a019 is
+to set the left output-amp value to 25.
+------------------------------------------------------------------------
+  % hda-decode-verb 0xe3a019
+  raw value = 0x00e3a019
+  cid = 0, nid = 0x0e, verb = 0x3a0, parm = 0x19
+  raw value: verb = 0x3a0, parm = 0x19
+  verbname = set_amp_gain_mute
+  amp raw val = 0xa019
+  output, left, idx=0, mute=0, val=25
+------------------------------------------------------------------------
+
+
 Development Tree
 ~~~~~~~~~~~~~~~~
 The latest development codes for HD-audio are found on sound git tree:
index 704e474a93df8539e093aa3569bb889faa1adb70..1f2463671a1a4d59d0981f0b877c2a1246da82db 100644 (file)
@@ -24,6 +24,7 @@ show up in /proc/sys/kernel:
 - bootloader_type           [ X86 only ]
 - bootloader_version        [ X86 only ]
 - callhome                  [ S390 only ]
+- cap_last_cap
 - core_pattern
 - core_pipe_limit
 - core_uses_pid
@@ -155,6 +156,13 @@ on has a service contract with IBM.
 
 ==============================================================
 
+cap_last_cap
+
+Highest valid capability of the running kernel.  Exports
+CAP_LAST_CAP from the kernel.
+
+==============================================================
+
 core_pattern:
 
 core_pattern is used to specify a core dumpfile pattern name.
index 12cecc83cd91c658c71524bba59762b83f810829..4a37c4759cd231f72a8b5f253deec9fdec334886 100644 (file)
@@ -379,10 +379,10 @@ EVENT_PROCESS:
 
                        # To closer match vmstat scanning statistics, only count isolate_both
                        # and isolate_inactive as scanning. isolate_active is rotation
-                       # isolate_inactive == 0
-                       # isolate_active   == 1
-                       # isolate_both     == 2
-                       if ($isolate_mode != 1) {
+                       # isolate_inactive == 1
+                       # isolate_active   == 2
+                       # isolate_both     == 3
+                       if ($isolate_mode != 2) {
                                $perprocesspid{$process_pid}->{HIGH_NR_SCANNED} += $nr_scanned;
                        }
                        $perprocesspid{$process_pid}->{HIGH_NR_CONTIG_DIRTY} += $nr_contig_dirty;
index 5bfa9a777d26c5696ee10b5bef0e23d1baea8190..b15e29f3112113416f238cb686047430caf17eeb 100644 (file)
@@ -8,6 +8,7 @@ xxxx            vend:prod
 ----
 spca501                0000:0000       MystFromOri Unknown Camera
 spca508                0130:0130       Clone Digital Webcam 11043
+zc3xx          03f0:1b07       HP Premium Starter Cam
 m5602          0402:5602       ALi Video Camera Controller
 spca501                040a:0002       Kodak DVC-325
 spca500                040a:0300       Kodak EZ200
@@ -190,6 +191,7 @@ ov519               05a9:0519       OV519 Microphone
 ov519          05a9:0530       OmniVision
 ov519          05a9:2800       OmniVision SuperCAM
 ov519          05a9:4519       Webcam Classic
+ov534_9                05a9:8065       OmniVision test kit ov538+ov9712
 ov519          05a9:8519       OmniVision
 ov519          05a9:a511       D-Link USB Digital Video Camera
 ov519          05a9:a518       D-Link DSB-C310 Webcam
@@ -199,6 +201,8 @@ gl860               05e3:0503       Genesys Logic PC Camera
 gl860          05e3:f191       Genesys Logic PC Camera
 spca561                060b:a001       Maxell Compact Pc PM3
 zc3xx          0698:2003       CTX M730V built in
+topro          06a2:0003       TP6800 PC Camera, CmoX CX0342 webcam
+topro          06a2:6810       Creative Qmax
 nw80x          06a5:0000       Typhoon Webcam 100 USB
 nw80x          06a5:d001       Divio based webcams
 nw80x          06a5:d800       Divio Chicony TwinkleCam, Trust SpaceCam
index 69be2c782b989b5616596be15c70b3dd42c4e669..5dd1439b61fd512b94b3404f959e824ab3816f4d 100644 (file)
@@ -70,10 +70,11 @@ Events
 The OMAP 3 ISP driver does support the V4L2 event interface on CCDC and
 statistics (AEWB, AF and histogram) subdevs.
 
-The CCDC subdev produces V4L2_EVENT_OMAP3ISP_HS_VS type event on HS_VS
-interrupt which is used to signal frame start. The event is triggered exactly
-when the reception of the first line of the frame starts in the CCDC module.
-The event can be subscribed on the CCDC subdev.
+The CCDC subdev produces V4L2_EVENT_FRAME_SYNC type event on HS_VS
+interrupt which is used to signal frame start. Earlier version of this
+driver used V4L2_EVENT_OMAP3ISP_HS_VS for this purpose. The event is
+triggered exactly when the reception of the first line of the frame starts
+in the CCDC module. The event can be subscribed on the CCDC subdev.
 
 (When using parallel interface one must pay account to correct configuration
 of the VS signal polarity. This is automatically correct when using the serial
index 9346fc8cbf2b2323e205f1f8669fd626cfc1047a..26aa0573933e8f5f970f7f18b3f53f0afd37eb6d 100644 (file)
@@ -285,11 +285,11 @@ implement g_volatile_ctrl like this:
 Note that you use the 'new value' union as well in g_volatile_ctrl. In general
 controls that need to implement g_volatile_ctrl are read-only controls.
 
-To mark a control as volatile you have to set the is_volatile flag:
+To mark a control as volatile you have to set V4L2_CTRL_FLAG_VOLATILE:
 
        ctrl = v4l2_ctrl_new_std(&sd->ctrl_handler, ...);
        if (ctrl)
-               ctrl->is_volatile = 1;
+               ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
 
 For try/s_ctrl the new values (i.e. as passed by the user) are filled in and
 you can modify them in try_ctrl or set them in s_ctrl. The 'cur' union
@@ -367,8 +367,7 @@ Driver specific controls can be created using v4l2_ctrl_new_custom():
 The last argument is the priv pointer which can be set to driver-specific
 private data.
 
-The v4l2_ctrl_config struct also has fields to set the is_private and is_volatile
-flags.
+The v4l2_ctrl_config struct also has a field to set the is_private flag.
 
 If the name field is not set, then the framework will assume this is a standard
 control and will fill in the name, type and flags fields accordingly.
@@ -496,18 +495,20 @@ Handling autogain/gain-type Controls with Auto Clusters
 
 A common type of control cluster is one that handles 'auto-foo/foo'-type
 controls. Typical examples are autogain/gain, autoexposure/exposure,
-autowhitebalance/red balance/blue balance. In all cases you have one controls
+autowhitebalance/red balance/blue balance. In all cases you have one control
 that determines whether another control is handled automatically by the hardware,
 or whether it is under manual control from the user.
 
 If the cluster is in automatic mode, then the manual controls should be
-marked inactive. When the volatile controls are read the g_volatile_ctrl
-operation should return the value that the hardware's automatic mode set up
-automatically.
+marked inactive and volatile. When the volatile controls are read the
+g_volatile_ctrl operation should return the value that the hardware's automatic
+mode set up automatically.
 
 If the cluster is put in manual mode, then the manual controls should become
-active again and the is_volatile flag should be ignored (so g_volatile_ctrl is
-no longer called while in manual mode).
+active again and the volatile flag is cleared (so g_volatile_ctrl is no longer
+called while in manual mode). In addition just before switching to manual mode
+the current values as determined by the auto mode are copied as the new manual
+values.
 
 Finally the V4L2_CTRL_FLAG_UPDATE should be set for the auto control since
 changing that control affects the control flags of the manual controls.
@@ -520,7 +521,11 @@ void v4l2_ctrl_auto_cluster(unsigned ncontrols, struct v4l2_ctrl **controls,
 
 The first two arguments are identical to v4l2_ctrl_cluster. The third argument
 tells the framework which value switches the cluster into manual mode. The
-last argument will optionally set the is_volatile flag for the non-auto controls.
+last argument will optionally set V4L2_CTRL_FLAG_VOLATILE for the non-auto controls.
+If it is false, then the manual controls are never volatile. You would typically
+use that if the hardware does not give you the option to read back to values as
+determined by the auto mode (e.g. if autogain is on, the hardware doesn't allow
+you to obtain the current gain value).
 
 The first control of the cluster is assumed to be the 'auto' control.
 
@@ -681,16 +686,6 @@ if there are no controls at all.
 count if nothing was done yet. If it is less than count then only the controls
 up to error_idx-1 were successfully applied.
 
-3) When attempting to read a button control the framework will return -EACCES
-instead of -EINVAL as stated in the spec. It seems to make more sense since
-button controls are write-only controls.
-
-4) Attempting to write to a read-only control will return -EACCES instead of
--EINVAL as the spec says.
-
-5) The spec does not mention what should happen when you try to set/get a
-control class controls. The framework will return -EACCES.
-
 
 Proposals for Extensions
 ========================
@@ -703,9 +698,3 @@ decimal. Useful for e.g. video_mute_yuv.
 2) It is possible to mark in the controls array which controls have been
 successfully written and which failed by for example adding a bit to the
 control ID. Not sure if it is worth the effort, though.
-
-3) Trying to set volatile inactive controls should result in -EACCESS.
-
-4) Add a new flag to mark volatile controls. Any application that wants
-to store the state of the controls can then skip volatile inactive controls.
-Currently it is not possible to detect such controls.
index b0e4b9cd6a663a412ab9772a220ea8447aa349dd..7945b0bd35e2ad50d7561ffa88a428c21175b50b 100644 (file)
@@ -175,10 +175,30 @@ Parameters: vcpu id (apic id on x86)
 Returns: vcpu fd on success, -1 on error
 
 This API adds a vcpu to a virtual machine.  The vcpu id is a small integer
-in the range [0, max_vcpus).  You can use KVM_CAP_NR_VCPUS of the
-KVM_CHECK_EXTENSION ioctl() to determine the value for max_vcpus at run-time.
+in the range [0, max_vcpus).
+
+The recommended max_vcpus value can be retrieved using the KVM_CAP_NR_VCPUS of
+the KVM_CHECK_EXTENSION ioctl() at run-time.
+The maximum possible value for max_vcpus can be retrieved using the
+KVM_CAP_MAX_VCPUS of the KVM_CHECK_EXTENSION ioctl() at run-time.
+
 If the KVM_CAP_NR_VCPUS does not exist, you should assume that max_vcpus is 4
 cpus max.
+If the KVM_CAP_MAX_VCPUS does not exist, you should assume that max_vcpus is
+same as the value returned from KVM_CAP_NR_VCPUS.
+
+On powerpc using book3s_hv mode, the vcpus are mapped onto virtual
+threads in one or more virtual CPU cores.  (This is because the
+hardware requires all the hardware threads in a CPU core to be in the
+same partition.)  The KVM_CAP_PPC_SMT capability indicates the number
+of vcpus per virtual core (vcore).  The vcore id is obtained by
+dividing the vcpu id by the number of vcpus per vcore.  The vcpus in a
+given vcore will always be in the same physical core as each other
+(though that might be a different physical core from time to time).
+Userspace can control the threading (SMT) mode of the guest by its
+allocation of vcpu ids.  For example, if userspace wants
+single-threaded guest vcpus, it should make all vcpu ids be a multiple
+of the number of vcpus per vcore.
 
 On powerpc using book3s_hv mode, the vcpus are mapped onto virtual
 threads in one or more virtual CPU cores.  (This is because the
@@ -1633,3 +1653,50 @@ developer registration required to access it).
                char padding[256];
        };
 };
+
+6. Capabilities that can be enabled
+
+There are certain capabilities that change the behavior of the virtual CPU when
+enabled. To enable them, please see section 4.37. Below you can find a list of
+capabilities and what their effect on the vCPU is when enabling them.
+
+The following information is provided along with the description:
+
+  Architectures: which instruction set architectures provide this ioctl.
+      x86 includes both i386 and x86_64.
+
+  Parameters: what parameters are accepted by the capability.
+
+  Returns: the return value.  General error numbers (EBADF, ENOMEM, EINVAL)
+      are not detailed, but errors with specific meanings are.
+
+6.1 KVM_CAP_PPC_OSI
+
+Architectures: ppc
+Parameters: none
+Returns: 0 on success; -1 on error
+
+This capability enables interception of OSI hypercalls that otherwise would
+be treated as normal system calls to be injected into the guest. OSI hypercalls
+were invented by Mac-on-Linux to have a standardized communication mechanism
+between the guest and the host.
+
+When this capability is enabled, KVM_EXIT_OSI can occur.
+
+6.2 KVM_CAP_PPC_PAPR
+
+Architectures: ppc
+Parameters: none
+Returns: 0 on success; -1 on error
+
+This capability enables interception of PAPR hypercalls. PAPR hypercalls are
+done using the hypercall instruction "sc 1".
+
+It also sets the guest privilege level to "supervisor" mode. Usually the guest
+runs in "hypervisor" privilege mode with a few missing features.
+
+In addition to the above, it changes the semantics of SDR1. In this mode, the
+HTAB address part of SDR1 contains an HVA instead of a GPA, as PAPR keeps the
+HTAB invisible to the guest.
+
+When this capability is enabled, KVM_EXIT_PAPR_HCALL can occur.
index 506fe49a4c78daea8b444e6a37da468b89956b9c..5d6941f8c4368b3df14099e79a29fd65d12be858 100644 (file)
@@ -316,6 +316,10 @@ W: http://wiki.analog.com/AD7879
 S:     Supported
 F:     drivers/input/touchscreen/ad7879.c
 
+ADDRESS SPACE LAYOUT RANDOMIZATION (ASLR)
+M:     Jiri Kosina <jkosina@suse.cz>
+S:     Maintained
+
 ADM1025 HARDWARE MONITOR DRIVER
 M:     Jean Delvare <khali@linux-fr.org>
 L:     lm-sensors@lm-sensors.org
@@ -529,6 +533,7 @@ S:  Maintained
 F:     drivers/infiniband/hw/amso1100/
 
 ANALOG DEVICES INC ASOC CODEC DRIVERS
+M:     Lars-Peter Clausen <lars@metafoo.de>
 L:     device-drivers-devel@blackfin.uclinux.org
 L:     alsa-devel@alsa-project.org (moderated for non-subscribers)
 W:     http://wiki.analog.com/
@@ -1084,6 +1089,24 @@ F:       arch/arm/plat-s5p/dev-fimc*
 F:     arch/arm/plat-samsung/include/plat/*fimc*
 F:     drivers/media/video/s5p-fimc/
 
+ARM/SAMSUNG S5P SERIES Multi Format Codec (MFC) SUPPORT
+M:     Kyungmin Park <kyungmin.park@samsung.com>
+M:     Kamil Debski <k.debski@samsung.com>
+L:     linux-arm-kernel@lists.infradead.org
+L:     linux-media@vger.kernel.org
+S:     Maintained
+F:     arch/arm/plat-s5p/dev-mfc.c
+F:     drivers/media/video/s5p-mfc/
+
+ARM/SAMSUNG S5P SERIES TV SUBSYSTEM SUPPORT
+M:     Kyungmin Park <kyungmin.park@samsung.com>
+M:     Tomasz Stanislawski <t.stanislaws@samsung.com>
+L:     linux-arm-kernel@lists.infradead.org
+L:     linux-media@vger.kernel.org
+S:     Maintained
+F:     arch/arm/plat-s5p/dev-tv.c
+F:     drivers/media/video/s5p-tv/
+
 ARM/SHMOBILE ARM ARCHITECTURE
 M:     Paul Mundt <lethal@linux-sh.org>
 M:     Magnus Damm <magnus.damm@gmail.com>
@@ -3208,6 +3231,13 @@ F:       Documentation/ide/
 F:     drivers/ide/
 F:     include/linux/ide.h
 
+IDEAPAD LAPTOP EXTRAS DRIVER
+M:     Ike Panhc <ike.pan@canonical.com>
+L:     platform-driver-x86@vger.kernel.org
+W:     http://launchpad.net/ideapad-laptop
+S:     Maintained
+F:     drivers/platform/x86/ideapad-laptop.c
+
 IDE/ATAPI DRIVERS
 M:     Borislav Petkov <petkovbb@gmail.com>
 L:     linux-ide@vger.kernel.org
@@ -3994,6 +4024,7 @@ M:        Eric Piel <eric.piel@tremplin-utc.net>
 S:     Maintained
 F:     Documentation/misc-devices/lis3lv02d
 F:     drivers/misc/lis3lv02d/
+F:     drivers/platform/x86/hp_accel.c
 
 LLC (802.2)
 M:     Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
@@ -4948,7 +4979,7 @@ F:        include/linux/i2c-algo-pca.h
 F:     include/linux/i2c-pca-platform.h
 
 PCI ERROR RECOVERY
-M:     Linas Vepstas <linas@austin.ibm.com>
+M:     Linas Vepstas <linasvepstas@gmail.com>
 L:     linux-pci@vger.kernel.org
 S:     Supported
 F:     Documentation/PCI/pci-error-recovery.txt
@@ -5328,6 +5359,12 @@ F:       fs/qnx4/
 F:     include/linux/qnx4_fs.h
 F:     include/linux/qnxtypes.h
 
+QUALCOMM HEXAGON ARCHITECTURE
+M:     Richard Kuo <rkuo@codeaurora.org>
+L:     linux-hexagon@vger.kernel.org
+S:     Supported
+F:     arch/hexagon/
+
 RADOS BLOCK DEVICE (RBD)
 F:     include/linux/qnxtypes.h
 M:     Yehuda Sadeh <yehuda@hq.newdream.net>
@@ -5969,6 +6006,12 @@ L:       netdev@vger.kernel.org
 S:     Supported
 F:     drivers/net/ethernet/smsc/smsc9420.*
 
+SMSC UFX6000 and UFX7000 USB to VGA DRIVER
+M:     Steve Glendinning <steve.glendinning@smsc.com>
+L:     linux-fbdev@vger.kernel.org
+S:     Supported
+F:     drivers/video/smscufx.c
+
 SN-IA64 (Itanium) SUB-PLATFORM
 M:     Jes Sorensen <jes@sgi.com>
 L:     linux-altix@sgi.com
@@ -6038,7 +6081,7 @@ M:        Jaroslav Kysela <perex@perex.cz>
 M:     Takashi Iwai <tiwai@suse.de>
 L:     alsa-devel@alsa-project.org (moderated for non-subscribers)
 W:     http://www.alsa-project.org/
-T:     git git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6.git
+T:     git git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git
 T:     git git://git.alsa-project.org/alsa-kernel.git
 S:     Maintained
 F:     Documentation/sound/
@@ -7259,6 +7302,7 @@ T:        git git://opensource.wolfsonmicro.com/linux-2.6-audioplus
 W:     http://opensource.wolfsonmicro.com/content/linux-drivers-wolfson-devices
 S:     Supported
 F:     Documentation/hwmon/wm83??
+F:     arch/arm/mach-s3c64xx/mach-crag6410*
 F:     drivers/leds/leds-wm83*.c
 F:     drivers/input/misc/wm831x-on.c
 F:     drivers/input/touchscreen/wm831x-ts.c
index 4ac48a095f3ace676d7f4651dedf21a84da9249b..2207fc61665d0526a03940d26d3c282240af58d6 100644 (file)
 #define __NR_clock_adjtime             499
 #define __NR_syncfs                    500
 #define __NR_setns                     501
+#define __NR_accept4                   502
+#define __NR_sendmmsg                  503
 
 #ifdef __KERNEL__
 
-#define NR_SYSCALLS                    502
+#define NR_SYSCALLS                    504
 
 #define __ARCH_WANT_IPC_PARSE_VERSION
 #define __ARCH_WANT_OLD_READDIR
index 6acea1f96de394d05ef0e13dbea2a29d85a7e0ee..e534e1c5bc11302327ba04825f906c3060bfb2e1 100644 (file)
@@ -520,6 +520,8 @@ sys_call_table:
        .quad sys_clock_adjtime
        .quad sys_syncfs                        /* 500 */
        .quad sys_setns
+       .quad sys_accept4
+       .quad sys_sendmmsg
 
        .size sys_call_table, . - sys_call_table
        .type sys_call_table, @object
index a53b3de9daa2ca33a9086af7e9dd43429da35557..3c2b580b9d758a62279cfe9c76b532ae16647bd6 100644 (file)
@@ -319,7 +319,7 @@ void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data)
        if (!data)
                return;
 
-       for (i = 0; i < ATMEL_MCI_MAX_NR_SLOTS; i++) {
+       for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
                if (data->slot[i].bus_width) {
                        /* input/irq */
                        if (data->slot[i].detect_pin) {
index c63a5ec1a8e30ac0ce67d85a53c83e9a0064e339..70ef8c527d2792957331ea066c26a8a56e2493de 100644 (file)
@@ -160,6 +160,11 @@ static void __init edb93xx_register_spi(void)
 /*************************************************************************
  * EDB93xx I2S
  *************************************************************************/
+static struct platform_device edb93xx_audio_device = {
+       .name           = "edb93xx-audio",
+       .id             = -1,
+};
+
 static int __init edb93xx_has_audio(void)
 {
        return (machine_is_edb9301() || machine_is_edb9302() ||
@@ -171,6 +176,7 @@ static void __init edb93xx_register_i2s(void)
 {
        if (edb93xx_has_audio()) {
                ep93xx_register_i2s();
+               platform_device_register(&edb93xx_audio_device);
        }
 }
 
index d6f286b4db9c1035247b5f0a878d573120c62a00..52e090dc9d2786cf9171eea814f026ace04fc026 100644 (file)
@@ -53,6 +53,17 @@ static struct i2c_board_info __initdata simone_i2c_board_info[] = {
        },
 };
 
+static struct platform_device simone_audio_device = {
+       .name           = "simone-audio",
+       .id             = -1,
+};
+
+static void __init simone_register_audio(void)
+{
+       ep93xx_register_ac97();
+       platform_device_register(&simone_audio_device);
+}
+
 static void __init simone_init_machine(void)
 {
        ep93xx_init_devices();
@@ -61,7 +72,7 @@ static void __init simone_init_machine(void)
        ep93xx_register_fb(&simone_fb_info);
        ep93xx_register_i2c(&simone_i2c_gpio_data, simone_i2c_board_info,
                            ARRAY_SIZE(simone_i2c_board_info));
-       ep93xx_register_ac97();
+       simone_register_audio();
 }
 
 MACHINE_START(SIM_ONE, "Simplemachines Sim.One Board")
index 2b4d4b0201dfbaecd8c6fa3fe656124bdf274fd6..8121e3aedc0a4693fac60000bc186d4edf4c343d 100644 (file)
@@ -150,6 +150,17 @@ static struct ep93xxfb_mach_info __initdata snappercl15_fb_info = {
        .bpp                    = 16,
 };
 
+static struct platform_device snappercl15_audio_device = {
+       .name           = "snappercl15-audio",
+       .id             = -1,
+};
+
+static void __init snappercl15_register_audio(void)
+{
+       ep93xx_register_i2s();
+       platform_device_register(&snappercl15_audio_device);
+}
+
 static void __init snappercl15_init_machine(void)
 {
        ep93xx_init_devices();
@@ -157,7 +168,7 @@ static void __init snappercl15_init_machine(void)
        ep93xx_register_i2c(&snappercl15_i2c_gpio_data, snappercl15_i2c_data,
                            ARRAY_SIZE(snappercl15_i2c_data));
        ep93xx_register_fb(&snappercl15_fb_info);
-       ep93xx_register_i2s();
+       snappercl15_register_audio();
        platform_device_register(&snappercl15_nand_device);
 }
 
index 2eafbac2c76356dad02db7bb13a08ec64f1b5726..377230497dcc5007166e89238de1024aabbc2b2f 100644 (file)
@@ -241,7 +241,7 @@ static struct regulator_init_data gpo_init = {
 };
 
 static struct regulator_consumer_supply vmmc1_consumers[] = {
-       REGULATOR_SUPPLY("lcd_2v8", NULL),
+       REGULATOR_SUPPLY("vcore", "spi0.0"),
 };
 
 static struct regulator_init_data vmmc1_init = {
@@ -257,7 +257,7 @@ static struct regulator_init_data vmmc1_init = {
 };
 
 static struct regulator_consumer_supply vgen_consumers[] = {
-       REGULATOR_SUPPLY("vdd_lcdio", NULL),
+       REGULATOR_SUPPLY("vdd", "spi0.0"),
 };
 
 static struct regulator_init_data vgen_init = {
@@ -348,8 +348,6 @@ static const struct imx_fb_platform_data mx27_3ds_fb_data __initconst = {
 static struct l4f00242t03_pdata mx27_3ds_lcd_pdata = {
        .reset_gpio             = LCD_RESET,
        .data_enable_gpio       = LCD_ENABLE,
-       .core_supply            = "lcd_2v8",
-       .io_supply              = "vdd_lcdio",
 };
 
 static struct spi_board_info mx27_3ds_spi_devs[] __initdata = {
index 589066fb3316ae794dc84ff98e67e37c1a716232..6484db525bd7934be102246e322dbb4af84a4baa 100644 (file)
@@ -285,8 +285,6 @@ static struct mx3fb_platform_data mx3fb_pdata __initdata = {
 static struct l4f00242t03_pdata mx31_3ds_l4f00242t03_pdata = {
        .reset_gpio             = IOMUX_TO_GPIO(MX31_PIN_LCS1),
        .data_enable_gpio       = IOMUX_TO_GPIO(MX31_PIN_SER_RS),
-       .core_supply            = "lcd_2v8",
-       .io_supply              = "vdd_lcdio",
 };
 
 /*
@@ -411,7 +409,7 @@ static struct regulator_init_data vmmc2_init = {
 };
 
 static struct regulator_consumer_supply vmmc1_consumers[] = {
-       REGULATOR_SUPPLY("lcd_2v8", NULL),
+       REGULATOR_SUPPLY("vcore", "spi0.0"),
        REGULATOR_SUPPLY("cmos_2v8", "soc-camera-pdrv.0"),
 };
 
@@ -428,7 +426,7 @@ static struct regulator_init_data vmmc1_init = {
 };
 
 static struct regulator_consumer_supply vgen_consumers[] = {
-       REGULATOR_SUPPLY("vdd_lcdio", NULL),
+       REGULATOR_SUPPLY("vdd", "spi0.0"),
 };
 
 static struct regulator_init_data vgen_init = {
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..40a8c178f10d9e85a2873c83247c3f2fe553f408 100644 (file)
@@ -0,0 +1 @@
+/* empty */
index c4f5e26feb4dc4d274a1b721b90fce08e6fffd96..993780f490ada952cf54f80aa184c7ed53c68985 100644 (file)
@@ -175,12 +175,6 @@ static struct resource resources_sdc1[] = {
                .flags  = IORESOURCE_IRQ,
                .name   = "cmd_irq",
        },
-       {
-               .start  = INT_SDC1_1,
-               .end    = INT_SDC1_1,
-               .flags  = IORESOURCE_IRQ,
-               .name   = "pio_irq",
-       },
        {
                .flags  = IORESOURCE_IRQ | IORESOURCE_DISABLED,
                .name   = "status_irq"
@@ -203,12 +197,6 @@ static struct resource resources_sdc2[] = {
                .end    = INT_SDC2_0,
                .flags  = IORESOURCE_IRQ,
                .name   = "cmd_irq",
-       },
-               {
-               .start  = INT_SDC2_1,
-               .end    = INT_SDC2_1,
-               .flags  = IORESOURCE_IRQ,
-               .name   = "pio_irq",
        },
        {
                .flags  = IORESOURCE_IRQ | IORESOURCE_DISABLED,
@@ -232,12 +220,6 @@ static struct resource resources_sdc3[] = {
                .end    = INT_SDC3_0,
                .flags  = IORESOURCE_IRQ,
                .name   = "cmd_irq",
-       },
-               {
-               .start  = INT_SDC3_1,
-               .end    = INT_SDC3_1,
-               .flags  = IORESOURCE_IRQ,
-               .name   = "pio_irq",
        },
        {
                .flags  = IORESOURCE_IRQ | IORESOURCE_DISABLED,
@@ -261,12 +243,6 @@ static struct resource resources_sdc4[] = {
                .end    = INT_SDC4_0,
                .flags  = IORESOURCE_IRQ,
                .name   = "cmd_irq",
-       },
-               {
-               .start  = INT_SDC4_1,
-               .end    = INT_SDC4_1,
-               .flags  = IORESOURCE_IRQ,
-               .name   = "pio_irq",
        },
        {
                .flags  = IORESOURCE_IRQ | IORESOURCE_DISABLED,
index 12d8deb78d9ca37b6a9bbe8fa6804301f3b1bae6..131633b12a34d7c52395fb01683aeb13abf5e35f 100644 (file)
@@ -139,12 +139,6 @@ static struct resource resources_sdc1[] = {
                .flags  = IORESOURCE_IRQ,
                .name   = "cmd_irq",
        },
-       {
-               .start  = INT_SDC1_1,
-               .end    = INT_SDC1_1,
-               .flags  = IORESOURCE_IRQ,
-               .name   = "pio_irq",
-       },
        {
                .flags  = IORESOURCE_IRQ | IORESOURCE_DISABLED,
                .name   = "status_irq"
@@ -167,12 +161,6 @@ static struct resource resources_sdc2[] = {
                .end    = INT_SDC2_0,
                .flags  = IORESOURCE_IRQ,
                .name   = "cmd_irq",
-       },
-               {
-               .start  = INT_SDC2_1,
-               .end    = INT_SDC2_1,
-               .flags  = IORESOURCE_IRQ,
-               .name   = "pio_irq",
        },
        {
                .flags  = IORESOURCE_IRQ | IORESOURCE_DISABLED,
@@ -196,12 +184,6 @@ static struct resource resources_sdc3[] = {
                .end    = INT_SDC3_0,
                .flags  = IORESOURCE_IRQ,
                .name   = "cmd_irq",
-       },
-               {
-               .start  = INT_SDC3_1,
-               .end    = INT_SDC3_1,
-               .flags  = IORESOURCE_IRQ,
-               .name   = "pio_irq",
        },
        {
                .flags  = IORESOURCE_IRQ | IORESOURCE_DISABLED,
@@ -225,12 +207,6 @@ static struct resource resources_sdc4[] = {
                .end    = INT_SDC4_0,
                .flags  = IORESOURCE_IRQ,
                .name   = "cmd_irq",
-       },
-               {
-               .start  = INT_SDC4_1,
-               .end    = INT_SDC4_1,
-               .flags  = IORESOURCE_IRQ,
-               .name   = "pio_irq",
        },
        {
                .flags  = IORESOURCE_IRQ | IORESOURCE_DISABLED,
index 5631b51cec465e78f90feec4cc52ae7a74d7b0be..ffcd9e3a6a7e81578f22624d839278c4906f3a99 100644 (file)
@@ -8,13 +8,6 @@
 #include <linux/mmc/card.h>
 #include <linux/mmc/sdio_func.h>
 
-struct embedded_sdio_data {
-       struct sdio_cis cis;
-       struct sdio_cccr cccr;
-       struct sdio_embedded_func *funcs;
-       int num_funcs;
-};
-
 struct msm_mmc_gpio {
        unsigned no;
        const char *name;
@@ -29,9 +22,9 @@ struct msm_mmc_platform_data {
        unsigned int ocr_mask;                  /* available voltages */
        u32 (*translate_vdd)(struct device *, unsigned int);
        unsigned int (*status)(struct device *);
-       struct embedded_sdio_data *embedded_sdio;
        int (*register_status_notify)(void (*callback)(int card_present, void *dev_id), void *dev_id);
        struct msm_mmc_gpio_data *gpio_data;
+       void (*init_card)(struct mmc_card *card);
 };
 
 #endif
index 87f43ade44050940ce7e9092de9b389d888444fc..f8ce84b69eb1ee2457f6efe878f34f5e44cc414a 100644 (file)
@@ -39,6 +39,9 @@
 #include <plat/usb.h>
 #include <plat/gpmc-smc91x.h>
 
+#include <video/omapdss.h>
+#include <video/omap-panel-generic-dpi.h>
+
 #include "mux.h"
 #include "hsmmc.h"
 #include "common-board-devices.h"
@@ -99,20 +102,72 @@ static struct platform_device sdp2430_flash_device = {
        .resource       = &sdp2430_flash_resource,
 };
 
-static struct platform_device sdp2430_lcd_device = {
-       .name           = "sdp2430_lcd",
-       .id             = -1,
-};
-
 static struct platform_device *sdp2430_devices[] __initdata = {
        &sdp2430_flash_device,
+};
+
+/* LCD */
+#define SDP2430_LCD_PANEL_BACKLIGHT_GPIO       91
+#define SDP2430_LCD_PANEL_ENABLE_GPIO          154
+
+static int sdp2430_panel_enable_lcd(struct omap_dss_device *dssdev)
+{
+       gpio_direction_output(SDP2430_LCD_PANEL_ENABLE_GPIO, 1);
+       gpio_direction_output(SDP2430_LCD_PANEL_BACKLIGHT_GPIO, 1);
+
+       return 0;
+}
+
+static void sdp2430_panel_disable_lcd(struct omap_dss_device *dssdev)
+{
+       gpio_direction_output(SDP2430_LCD_PANEL_ENABLE_GPIO, 0);
+       gpio_direction_output(SDP2430_LCD_PANEL_BACKLIGHT_GPIO, 0);
+}
+
+static struct panel_generic_dpi_data sdp2430_panel_data = {
+       .name                   = "nec_nl2432dr22-11b",
+       .platform_enable        = sdp2430_panel_enable_lcd,
+       .platform_disable       = sdp2430_panel_disable_lcd,
+};
+
+static struct omap_dss_device sdp2430_lcd_device = {
+       .name                   = "lcd",
+       .driver_name            = "generic_dpi_panel",
+       .type                   = OMAP_DISPLAY_TYPE_DPI,
+       .phy.dpi.data_lines     = 16,
+       .data                   = &sdp2430_panel_data,
+};
+
+static struct omap_dss_device *sdp2430_dss_devices[] = {
        &sdp2430_lcd_device,
 };
 
-static struct omap_lcd_config sdp2430_lcd_config __initdata = {
-       .ctrl_name      = "internal",
+static struct omap_dss_board_info sdp2430_dss_data = {
+       .num_devices    = ARRAY_SIZE(sdp2430_dss_devices),
+       .devices        = sdp2430_dss_devices,
+       .default_device = &sdp2430_lcd_device,
 };
 
+static void __init sdp2430_display_init(void)
+{
+       int r;
+
+       static struct gpio gpios[] __initdata = {
+               { SDP2430_LCD_PANEL_ENABLE_GPIO, GPIOF_OUT_INIT_LOW,
+                       "LCD reset" },
+               { SDP2430_LCD_PANEL_BACKLIGHT_GPIO, GPIOF_OUT_INIT_LOW,
+                       "LCD Backlight" },
+       };
+
+       r = gpio_request_array(gpios, ARRAY_SIZE(gpios));
+       if (r) {
+               pr_err("Cannot request LCD GPIOs, error %d\n", r);
+               return;
+       }
+
+       omap_display_init(&sdp2430_dss_data);
+}
+
 #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91x_MODULE)
 
 static struct omap_smc91x_platform_data board_smc91x_data = {
@@ -137,10 +192,6 @@ static inline void board_smc91x_init(void)
 
 #endif
 
-static struct omap_board_config_kernel sdp2430_config[] __initdata = {
-       {OMAP_TAG_LCD, &sdp2430_lcd_config},
-};
-
 static void __init omap_2430sdp_init_early(void)
 {
        omap2_init_common_infrastructure();
@@ -229,9 +280,6 @@ static void __init omap_2430sdp_init(void)
 {
        omap2430_mux_init(board_mux, OMAP_PACKAGE_ZAC);
 
-       omap_board_config = sdp2430_config;
-       omap_board_config_size = ARRAY_SIZE(sdp2430_config);
-
        omap2430_i2c_init();
 
        platform_add_devices(sdp2430_devices, ARRAY_SIZE(sdp2430_devices));
@@ -247,6 +295,8 @@ static void __init omap_2430sdp_init(void)
        /* Turn off secondary LCD backlight */
        gpio_request_one(SECONDARY_LCD_GPIO, GPIOF_OUT_INIT_LOW,
                         "Secondary LCD backlight");
+
+       sdp2430_display_init();
 }
 
 static void __init omap_2430sdp_map_io(void)
index 2430531b2239d6c9b369301833683558b4d53180..204beddcb949c4e0c2e31658d720c1b8a6cb11b3 100644 (file)
@@ -37,7 +37,7 @@
 #include <plat/dma.h>
 #include <plat/gpmc.h>
 #include <video/omapdss.h>
-#include <video/omap-panel-generic-dpi.h>
+#include <video/omap-panel-dvi.h>
 
 #include <plat/gpmc-smc91x.h>
 
@@ -186,8 +186,7 @@ static struct omap_dss_device sdp3430_lcd_device = {
        .platform_disable       = sdp3430_panel_disable_lcd,
 };
 
-static struct panel_generic_dpi_data dvi_panel = {
-       .name                   = "generic",
+static struct panel_dvi_platform_data dvi_panel = {
        .platform_enable        = sdp3430_panel_enable_dvi,
        .platform_disable       = sdp3430_panel_disable_dvi,
 };
@@ -195,7 +194,7 @@ static struct panel_generic_dpi_data dvi_panel = {
 static struct omap_dss_device sdp3430_dvi_device = {
        .name                   = "dvi",
        .type                   = OMAP_DISPLAY_TYPE_DPI,
-       .driver_name            = "generic_dpi_panel",
+       .driver_name            = "dvi",
        .data                   = &dvi_panel,
        .phy.dpi.data_lines     = 24,
 };
index be931105d681e27a413df624b92a9d403d572cfe..484cec54882a91e09469179dacfdb50611e1faa5 100644 (file)
@@ -38,6 +38,8 @@
 #include <plat/mmc.h>
 #include <plat/omap4-keypad.h>
 #include <video/omapdss.h>
+#include <video/omap-panel-nokia-dsi.h>
+#include <video/omap-panel-picodlp.h>
 #include <linux/wl12xx.h>
 
 #include "mux.h"
@@ -52,6 +54,8 @@
 #define OMAP4_SFH7741_ENABLE_GPIO              188
 #define HDMI_GPIO_HPD 60 /* Hot plug pin for HDMI */
 #define HDMI_GPIO_LS_OE 41 /* Level shifter for HDMI */
+#define DISPLAY_SEL_GPIO       59      /* LCD2/PicoDLP switch */
+#define DLP_POWER_ON_GPIO      40
 
 #define GPIO_WIFI_PMENA                54
 #define GPIO_WIFI_IRQ          53
@@ -340,11 +344,6 @@ static int __init omap_ethernet_init(void)
        return status;
 }
 
-static struct platform_device sdp4430_lcd_device = {
-       .name           = "sdp4430_lcd",
-       .id             = -1,
-};
-
 static struct regulator_consumer_supply sdp4430_vbat_supply[] = {
        REGULATOR_SUPPLY("vddvibl", "twl6040-vibra"),
        REGULATOR_SUPPLY("vddvibr", "twl6040-vibra"),
@@ -374,21 +373,12 @@ static struct platform_device sdp4430_vbat = {
 };
 
 static struct platform_device *sdp4430_devices[] __initdata = {
-       &sdp4430_lcd_device,
        &sdp4430_gpio_keys_device,
        &sdp4430_leds_gpio,
        &sdp4430_leds_pwm,
        &sdp4430_vbat,
 };
 
-static struct omap_lcd_config sdp4430_lcd_config __initdata = {
-       .ctrl_name      = "internal",
-};
-
-static struct omap_board_config_kernel sdp4430_config[] __initdata = {
-       { OMAP_TAG_LCD,         &sdp4430_lcd_config },
-};
-
 static void __init omap_4430sdp_init_early(void)
 {
        omap2_init_common_infrastructure();
@@ -648,37 +638,202 @@ static void sdp4430_panel_disable_hdmi(struct omap_dss_device *dssdev)
        gpio_free(HDMI_GPIO_HPD);
 }
 
-static struct omap_dss_device sdp4430_hdmi_device = {
-       .name = "hdmi",
-       .driver_name = "hdmi_panel",
-       .type = OMAP_DISPLAY_TYPE_HDMI,
-       .clocks = {
-               .dispc  = {
+static struct nokia_dsi_panel_data dsi1_panel = {
+               .name           = "taal",
+               .reset_gpio     = 102,
+               .use_ext_te     = false,
+               .ext_te_gpio    = 101,
+               .esd_interval   = 0,
+};
+
+static struct omap_dss_device sdp4430_lcd_device = {
+       .name                   = "lcd",
+       .driver_name            = "taal",
+       .type                   = OMAP_DISPLAY_TYPE_DSI,
+       .data                   = &dsi1_panel,
+       .phy.dsi                = {
+               .clk_lane       = 1,
+               .clk_pol        = 0,
+               .data1_lane     = 2,
+               .data1_pol      = 0,
+               .data2_lane     = 3,
+               .data2_pol      = 0,
+
+               .module         = 0,
+       },
+
+       .clocks = {
+               .dispc = {
+                       .channel = {
+                               /* Logic Clock = 172.8 MHz */
+                               .lck_div        = 1,
+                               /* Pixel Clock = 34.56 MHz */
+                               .pck_div        = 5,
+                               .lcd_clk_src    = OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC,
+                       },
                        .dispc_fclk_src = OMAP_DSS_CLK_SRC_FCK,
                },
-               .hdmi   = {
-                       .regn   = 15,
-                       .regm2  = 1,
+
+               .dsi = {
+                       .regn           = 16,   /* Fint = 2.4 MHz */
+                       .regm           = 180,  /* DDR Clock = 216 MHz */
+                       .regm_dispc     = 5,    /* PLL1_CLK1 = 172.8 MHz */
+                       .regm_dsi       = 5,    /* PLL1_CLK2 = 172.8 MHz */
+
+                       .lp_clk_div     = 10,   /* LP Clock = 8.64 MHz */
+                       .dsi_fclk_src   = OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI,
+               },
+       },
+       .channel                = OMAP_DSS_CHANNEL_LCD,
+};
+
+static struct nokia_dsi_panel_data dsi2_panel = {
+               .name           = "taal",
+               .reset_gpio     = 104,
+               .use_ext_te     = false,
+               .ext_te_gpio    = 103,
+               .esd_interval   = 0,
+};
+
+static struct omap_dss_device sdp4430_lcd2_device = {
+       .name                   = "lcd2",
+       .driver_name            = "taal",
+       .type                   = OMAP_DISPLAY_TYPE_DSI,
+       .data                   = &dsi2_panel,
+       .phy.dsi                = {
+               .clk_lane       = 1,
+               .clk_pol        = 0,
+               .data1_lane     = 2,
+               .data1_pol      = 0,
+               .data2_lane     = 3,
+               .data2_pol      = 0,
+
+               .module         = 1,
+       },
+
+       .clocks = {
+               .dispc = {
+                       .channel = {
+                               /* Logic Clock = 172.8 MHz */
+                               .lck_div        = 1,
+                               /* Pixel Clock = 34.56 MHz */
+                               .pck_div        = 5,
+                               .lcd_clk_src    = OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC,
+                       },
+                       .dispc_fclk_src = OMAP_DSS_CLK_SRC_FCK,
+               },
+
+               .dsi = {
+                       .regn           = 16,   /* Fint = 2.4 MHz */
+                       .regm           = 180,  /* DDR Clock = 216 MHz */
+                       .regm_dispc     = 5,    /* PLL1_CLK1 = 172.8 MHz */
+                       .regm_dsi       = 5,    /* PLL1_CLK2 = 172.8 MHz */
+
+                       .lp_clk_div     = 10,   /* LP Clock = 8.64 MHz */
+                       .dsi_fclk_src   = OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI,
                },
        },
+       .channel                = OMAP_DSS_CHANNEL_LCD2,
+};
+
+static void sdp4430_lcd_init(void)
+{
+       int r;
+
+       r = gpio_request_one(dsi1_panel.reset_gpio, GPIOF_DIR_OUT,
+               "lcd1_reset_gpio");
+       if (r)
+               pr_err("%s: Could not get lcd1_reset_gpio\n", __func__);
+
+       r = gpio_request_one(dsi2_panel.reset_gpio, GPIOF_DIR_OUT,
+               "lcd2_reset_gpio");
+       if (r)
+               pr_err("%s: Could not get lcd2_reset_gpio\n", __func__);
+}
+
+static struct omap_dss_device sdp4430_hdmi_device = {
+       .name = "hdmi",
+       .driver_name = "hdmi_panel",
+       .type = OMAP_DISPLAY_TYPE_HDMI,
        .platform_enable = sdp4430_panel_enable_hdmi,
        .platform_disable = sdp4430_panel_disable_hdmi,
        .channel = OMAP_DSS_CHANNEL_DIGIT,
 };
 
+static struct picodlp_panel_data sdp4430_picodlp_pdata = {
+       .picodlp_adapter_id     = 2,
+       .emu_done_gpio          = 44,
+       .pwrgood_gpio           = 45,
+};
+
+static void sdp4430_picodlp_init(void)
+{
+       int r;
+       const struct gpio picodlp_gpios[] = {
+               {DLP_POWER_ON_GPIO, GPIOF_OUT_INIT_LOW,
+                       "DLP POWER ON"},
+               {sdp4430_picodlp_pdata.emu_done_gpio, GPIOF_IN,
+                       "DLP EMU DONE"},
+               {sdp4430_picodlp_pdata.pwrgood_gpio, GPIOF_OUT_INIT_LOW,
+                       "DLP PWRGOOD"},
+       };
+
+       r = gpio_request_array(picodlp_gpios, ARRAY_SIZE(picodlp_gpios));
+       if (r)
+               pr_err("Cannot request PicoDLP GPIOs, error %d\n", r);
+}
+
+static int sdp4430_panel_enable_picodlp(struct omap_dss_device *dssdev)
+{
+       gpio_set_value(DISPLAY_SEL_GPIO, 0);
+       gpio_set_value(DLP_POWER_ON_GPIO, 1);
+
+       return 0;
+}
+
+static void sdp4430_panel_disable_picodlp(struct omap_dss_device *dssdev)
+{
+       gpio_set_value(DLP_POWER_ON_GPIO, 0);
+       gpio_set_value(DISPLAY_SEL_GPIO, 1);
+}
+
+static struct omap_dss_device sdp4430_picodlp_device = {
+       .name                   = "picodlp",
+       .driver_name            = "picodlp_panel",
+       .type                   = OMAP_DISPLAY_TYPE_DPI,
+       .phy.dpi.data_lines     = 24,
+       .channel                = OMAP_DSS_CHANNEL_LCD2,
+       .platform_enable        = sdp4430_panel_enable_picodlp,
+       .platform_disable       = sdp4430_panel_disable_picodlp,
+       .data                   = &sdp4430_picodlp_pdata,
+};
+
 static struct omap_dss_device *sdp4430_dss_devices[] = {
+       &sdp4430_lcd_device,
+       &sdp4430_lcd2_device,
        &sdp4430_hdmi_device,
+       &sdp4430_picodlp_device,
 };
 
 static struct omap_dss_board_info sdp4430_dss_data = {
        .num_devices    = ARRAY_SIZE(sdp4430_dss_devices),
        .devices        = sdp4430_dss_devices,
-       .default_device = &sdp4430_hdmi_device,
+       .default_device = &sdp4430_lcd_device,
 };
 
-void omap_4430sdp_display_init(void)
+static void omap_4430sdp_display_init(void)
 {
+       int r;
+
+       /* Enable LCD2 by default (instead of Pico DLP) */
+       r = gpio_request_one(DISPLAY_SEL_GPIO, GPIOF_OUT_INIT_HIGH,
+                       "display_sel");
+       if (r)
+               pr_err("%s: Could not get display_sel GPIO\n", __func__);
+
+       sdp4430_lcd_init();
        sdp4430_hdmi_mux_init();
+       sdp4430_picodlp_init();
        omap_display_init(&sdp4430_dss_data);
 }
 
@@ -802,9 +957,6 @@ static void __init omap_4430sdp_init(void)
                package = OMAP_PACKAGE_CBL;
        omap4_mux_init(board_mux, NULL, package);
 
-       omap_board_config = sdp4430_config;
-       omap_board_config_size = ARRAY_SIZE(sdp4430_config);
-
        omap4_i2c_init();
        omap_sfh7741prox_init();
        platform_add_devices(sdp4430_devices, ARRAY_SIZE(sdp4430_devices));
index 1325085e453d8ab62a31255f9bf2aaf1c32a0b7f..ab10f75984d88c6a281efd9cc463306a87d2ce62 100644 (file)
@@ -36,6 +36,7 @@
 #include <plat/usb.h>
 #include <video/omapdss.h>
 #include <video/omap-panel-generic-dpi.h>
+#include <video/omap-panel-dvi.h>
 
 #include "mux.h"
 #include "control.h"
@@ -333,8 +334,7 @@ static void am3517_evm_panel_disable_dvi(struct omap_dss_device *dssdev)
        dvi_enabled = 0;
 }
 
-static struct panel_generic_dpi_data dvi_panel = {
-       .name                   = "generic",
+static struct panel_dvi_platform_data dvi_panel = {
        .platform_enable        = am3517_evm_panel_enable_dvi,
        .platform_disable       = am3517_evm_panel_disable_dvi,
 };
@@ -342,7 +342,7 @@ static struct panel_generic_dpi_data dvi_panel = {
 static struct omap_dss_device am3517_evm_dvi_device = {
        .type                   = OMAP_DISPLAY_TYPE_DPI,
        .name                   = "dvi",
-       .driver_name            = "generic_dpi_panel",
+       .driver_name            = "dvi",
        .data                   = &dvi_panel,
        .phy.dpi.data_lines     = 24,
 };
index 67800e647d7a888799316bb2a68f3340cbe155da..ad55351e0cab58071011ed2f1b32dd11ccf921f3 100644 (file)
@@ -40,6 +40,9 @@
 #include <plat/common.h>
 #include <plat/gpmc.h>
 
+#include <video/omapdss.h>
+#include <video/omap-panel-generic-dpi.h>
+
 #include "mux.h"
 #include "control.h"
 
@@ -149,11 +152,6 @@ static struct platform_device apollon_smc91x_device = {
        .resource       = apollon_smc91x_resources,
 };
 
-static struct platform_device apollon_lcd_device = {
-       .name           = "apollon_lcd",
-       .id             = -1,
-};
-
 static struct omap_led_config apollon_led_config[] = {
        {
                .cdev   = {
@@ -191,7 +189,6 @@ static struct platform_device apollon_led_device = {
 static struct platform_device *apollon_devices[] __initdata = {
        &apollon_onenand_device,
        &apollon_smc91x_device,
-       &apollon_lcd_device,
        &apollon_led_device,
 };
 
@@ -265,12 +262,26 @@ static struct omap_usb_config apollon_usb_config __initdata = {
        .pins[0]        = 6,
 };
 
-static struct omap_lcd_config apollon_lcd_config __initdata = {
-       .ctrl_name      = "internal",
+static struct panel_generic_dpi_data apollon_panel_data = {
+       .name                   = "apollon",
 };
 
-static struct omap_board_config_kernel apollon_config[] __initdata = {
-       { OMAP_TAG_LCD,         &apollon_lcd_config },
+static struct omap_dss_device apollon_lcd_device = {
+       .name                   = "lcd",
+       .driver_name            = "generic_dpi_panel",
+       .type                   = OMAP_DISPLAY_TYPE_DPI,
+       .phy.dpi.data_lines     = 18,
+       .data                   = &apollon_panel_data,
+};
+
+static struct omap_dss_device *apollon_dss_devices[] = {
+       &apollon_lcd_device,
+};
+
+static struct omap_dss_board_info apollon_dss_data = {
+       .num_devices    = ARRAY_SIZE(apollon_dss_devices),
+       .devices        = apollon_dss_devices,
+       .default_device = &apollon_lcd_device,
 };
 
 static void __init omap_apollon_init_early(void)
@@ -314,8 +325,6 @@ static void __init omap_apollon_init(void)
        u32 v;
 
        omap2420_mux_init(board_mux, OMAP_PACKAGE_ZAC);
-       omap_board_config = apollon_config;
-       omap_board_config_size = ARRAY_SIZE(apollon_config);
 
        apollon_init_smc91x();
        apollon_led_init();
@@ -340,6 +349,8 @@ static void __init omap_apollon_init(void)
         */
        platform_add_devices(apollon_devices, ARRAY_SIZE(apollon_devices));
        omap_serial_init();
+
+       omap_display_init(&apollon_dss_data);
 }
 
 static void __init omap_apollon_map_io(void)
index 38179c17550359133b21f72c62af985c2d1b7113..6e0f0d2e39bc9d240028a5eb0a3456360f036835 100644 (file)
@@ -43,6 +43,7 @@
 #include <plat/usb.h>
 #include <video/omapdss.h>
 #include <video/omap-panel-generic-dpi.h>
+#include <video/omap-panel-dvi.h>
 #include <plat/mcspi.h>
 
 #include <mach/hardware.h>
@@ -242,8 +243,7 @@ static struct omap_dss_device cm_t35_lcd_device = {
        .phy.dpi.data_lines     = 18,
 };
 
-static struct panel_generic_dpi_data dvi_panel = {
-       .name                   = "generic",
+static struct panel_dvi_platform_data dvi_panel = {
        .platform_enable        = cm_t35_panel_enable_dvi,
        .platform_disable       = cm_t35_panel_disable_dvi,
 };
@@ -251,7 +251,7 @@ static struct panel_generic_dpi_data dvi_panel = {
 static struct omap_dss_device cm_t35_dvi_device = {
        .name                   = "dvi",
        .type                   = OMAP_DISPLAY_TYPE_DPI,
-       .driver_name            = "generic_dpi_panel",
+       .driver_name            = "dvi",
        .data                   = &dvi_panel,
        .phy.dpi.data_lines     = 24,
 };
index 99a42432ac93526a2b054f4fa31381037a149a7b..d9bfe54917e49761bdba53dd55495fd392b95857 100644 (file)
@@ -47,6 +47,7 @@
 #include <plat/usb.h>
 #include <video/omapdss.h>
 #include <video/omap-panel-generic-dpi.h>
+#include <video/omap-panel-dvi.h>
 
 #include <plat/mcspi.h>
 #include <linux/input/matrix_keypad.h>
@@ -139,7 +140,7 @@ static struct regulator_consumer_supply devkit8000_vio_supply[] = {
 };
 
 static struct panel_generic_dpi_data lcd_panel = {
-       .name                   = "generic",
+       .name                   = "innolux_at070tn83",
        .platform_enable        = devkit8000_panel_enable_lcd,
        .platform_disable       = devkit8000_panel_disable_lcd,
 };
@@ -152,8 +153,7 @@ static struct omap_dss_device devkit8000_lcd_device = {
        .phy.dpi.data_lines     = 24,
 };
 
-static struct panel_generic_dpi_data dvi_panel = {
-       .name                   = "generic",
+static struct panel_dvi_platform_data dvi_panel = {
        .platform_enable        = devkit8000_panel_enable_dvi,
        .platform_disable       = devkit8000_panel_disable_dvi,
 };
@@ -161,7 +161,7 @@ static struct panel_generic_dpi_data dvi_panel = {
 static struct omap_dss_device devkit8000_dvi_device = {
        .name                   = "dvi",
        .type                   = OMAP_DISPLAY_TYPE_DPI,
-       .driver_name            = "generic_dpi_panel",
+       .driver_name            = "dvi",
        .data                   = &dvi_panel,
        .phy.dpi.data_lines     = 24,
 };
@@ -267,7 +267,7 @@ static struct twl4030_gpio_platform_data devkit8000_gpio_data = {
 
 static struct regulator_consumer_supply devkit8000_vpll1_supplies[] = {
        REGULATOR_SUPPLY("vdds_dsi", "omapdss"),
-       REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi1"),
+       REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.0"),
 };
 
 /* VMMC1 for MMC1 pins CMD, CLK, DAT0..DAT3 (20 mA, plus card == max 220 mA) */
index 82421a4cfa928af257af4e02280c4e067d0a5317..8fcf79628ca183f1b716d754d763e3d56d68ad67 100644 (file)
@@ -39,6 +39,9 @@
 #include <plat/dma.h>
 #include <plat/gpmc.h>
 
+#include <video/omapdss.h>
+#include <video/omap-panel-generic-dpi.h>
+
 #include "mux.h"
 #include "control.h"
 
@@ -156,17 +159,33 @@ static struct platform_device h4_kp_device = {
        },
 };
 
-static struct platform_device h4_lcd_device = {
-       .name           = "lcd_h4",
-       .id             = -1,
-};
-
 static struct platform_device *h4_devices[] __initdata = {
        &h4_flash_device,
        &h4_kp_device,
+};
+
+static struct panel_generic_dpi_data h4_panel_data = {
+       .name                   = "h4",
+};
+
+static struct omap_dss_device h4_lcd_device = {
+       .name                   = "lcd",
+       .driver_name            = "generic_dpi_panel",
+       .type                   = OMAP_DISPLAY_TYPE_DPI,
+       .phy.dpi.data_lines     = 16,
+       .data                   = &h4_panel_data,
+};
+
+static struct omap_dss_device *h4_dss_devices[] = {
        &h4_lcd_device,
 };
 
+static struct omap_dss_board_info h4_dss_data = {
+       .num_devices    = ARRAY_SIZE(h4_dss_devices),
+       .devices        = h4_dss_devices,
+       .default_device = &h4_lcd_device,
+};
+
 /* 2420 Sysboot setup (2430 is different) */
 static u32 get_sysboot_value(void)
 {
@@ -270,10 +289,6 @@ static void __init h4_init_flash(void)
        h4_flash_resource.end   = base + SZ_64M - 1;
 }
 
-static struct omap_lcd_config h4_lcd_config __initdata = {
-       .ctrl_name      = "internal",
-};
-
 static struct omap_usb_config h4_usb_config __initdata = {
        /* S1.10 OFF -- usb "download port"
         * usb0 switched to Mini-B port and isp1105 transceiver;
@@ -285,10 +300,6 @@ static struct omap_usb_config h4_usb_config __initdata = {
        .hmc_mode       = 0x00,         /* 0:dev|otg 1:disable 2:disable */
 };
 
-static struct omap_board_config_kernel h4_config[] __initdata = {
-       { OMAP_TAG_LCD,         &h4_lcd_config },
-};
-
 static void __init omap_h4_init_early(void)
 {
        omap2_init_common_infrastructure();
@@ -330,9 +341,6 @@ static void __init omap_h4_init(void)
 {
        omap2420_mux_init(board_mux, OMAP_PACKAGE_ZAF);
 
-       omap_board_config = h4_config;
-       omap_board_config_size = ARRAY_SIZE(h4_config);
-
        /*
         * Make sure the serial ports are muxed on at this point.
         * You have to mux them off in device drivers later on
@@ -371,6 +379,8 @@ static void __init omap_h4_init(void)
        omap2_usbfs_init(&h4_usb_config);
        omap_serial_init();
        h4_init_flash();
+
+       omap_display_init(&h4_dss_data);
 }
 
 static void __init omap_h4_map_io(void)
index 7040352b16b4dc3b5b7655cf1cbf279b8dba4136..96f9ef34d2fbccc1a2b393efbe9f67dcafb5ce26 100644 (file)
@@ -32,7 +32,7 @@
 #include <plat/gpmc.h>
 #include <plat/usb.h>
 #include <video/omapdss.h>
-#include <video/omap-panel-generic-dpi.h>
+#include <video/omap-panel-dvi.h>
 #include <plat/onenand.h>
 
 #include "mux.h"
@@ -455,16 +455,16 @@ static void igep2_disable_dvi(struct omap_dss_device *dssdev)
        gpio_direction_output(IGEP2_GPIO_DVI_PUP, 0);
 }
 
-static struct panel_generic_dpi_data dvi_panel = {
-       .name                   = "generic",
+static struct panel_dvi_platform_data dvi_panel = {
        .platform_enable        = igep2_enable_dvi,
        .platform_disable       = igep2_disable_dvi,
+       .i2c_bus_num = 3,
 };
 
 static struct omap_dss_device igep2_dvi_device = {
        .type                   = OMAP_DISPLAY_TYPE_DPI,
        .name                   = "dvi",
-       .driver_name            = "generic_dpi_panel",
+       .driver_name            = "dvi",
        .data                   = &dvi_panel,
        .phy.dpi.data_lines     = 24,
 };
index abe8c7e496a2ff3850fd89d91c583e5f06c59d71..f8f8a68a4899ea34c527abad0f07dd6fb350b0fe 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/io.h>
 #include <linux/smsc911x.h>
 #include <linux/mmc/host.h>
+#include <linux/gpio.h>
 
 #include <mach/hardware.h>
 #include <asm/mach-types.h>
@@ -43,6 +44,9 @@
 #include <plat/usb.h>
 #include <plat/gpmc-smsc911x.h>
 
+#include <video/omapdss.h>
+#include <video/omap-panel-generic-dpi.h>
+
 #include "board-flash.h"
 #include "mux.h"
 #include "hsmmc.h"
@@ -179,29 +183,108 @@ static inline void __init ldp_init_smsc911x(void)
        gpmc_smsc911x_init(&smsc911x_cfg);
 }
 
-static struct platform_device ldp_lcd_device = {
-       .name           = "ldp_lcd",
-       .id             = -1,
+/* LCD */
+
+static int ldp_backlight_gpio;
+static int ldp_lcd_enable_gpio;
+
+#define LCD_PANEL_RESET_GPIO           55
+#define LCD_PANEL_QVGA_GPIO            56
+
+static int ldp_panel_enable_lcd(struct omap_dss_device *dssdev)
+{
+       if (gpio_is_valid(ldp_lcd_enable_gpio))
+               gpio_direction_output(ldp_lcd_enable_gpio, 1);
+       if (gpio_is_valid(ldp_backlight_gpio))
+               gpio_direction_output(ldp_backlight_gpio, 1);
+
+       return 0;
+}
+
+static void ldp_panel_disable_lcd(struct omap_dss_device *dssdev)
+{
+       if (gpio_is_valid(ldp_lcd_enable_gpio))
+               gpio_direction_output(ldp_lcd_enable_gpio, 0);
+       if (gpio_is_valid(ldp_backlight_gpio))
+               gpio_direction_output(ldp_backlight_gpio, 0);
+}
+
+static struct panel_generic_dpi_data ldp_panel_data = {
+       .name                   = "nec_nl2432dr22-11b",
+       .platform_enable        = ldp_panel_enable_lcd,
+       .platform_disable       = ldp_panel_disable_lcd,
 };
 
-static struct omap_lcd_config ldp_lcd_config __initdata = {
-       .ctrl_name      = "internal",
+static struct omap_dss_device ldp_lcd_device = {
+       .name                   = "lcd",
+       .driver_name            = "generic_dpi_panel",
+       .type                   = OMAP_DISPLAY_TYPE_DPI,
+       .phy.dpi.data_lines     = 18,
+       .data                   = &ldp_panel_data,
+};
+
+static struct omap_dss_device *ldp_dss_devices[] = {
+       &ldp_lcd_device,
 };
 
-static struct omap_board_config_kernel ldp_config[] __initdata = {
-       { OMAP_TAG_LCD,         &ldp_lcd_config },
+static struct omap_dss_board_info ldp_dss_data = {
+       .num_devices    = ARRAY_SIZE(ldp_dss_devices),
+       .devices        = ldp_dss_devices,
+       .default_device = &ldp_lcd_device,
 };
 
+static void __init ldp_display_init(void)
+{
+       int r;
+
+       static struct gpio gpios[] __initdata = {
+               {LCD_PANEL_RESET_GPIO, GPIOF_OUT_INIT_HIGH, "LCD RESET"},
+               {LCD_PANEL_QVGA_GPIO, GPIOF_OUT_INIT_HIGH, "LCD QVGA"},
+       };
+
+       r = gpio_request_array(gpios, ARRAY_SIZE(gpios));
+       if (r) {
+               pr_err("Cannot request LCD GPIOs, error %d\n", r);
+               return;
+       }
+
+       omap_display_init(&ldp_dss_data);
+}
+
 static void __init omap_ldp_init_early(void)
 {
        omap2_init_common_infrastructure();
        omap2_init_common_devices(NULL, NULL);
 }
 
+static int ldp_twl_gpio_setup(struct device *dev, unsigned gpio, unsigned ngpio)
+{
+       int r;
+
+       struct gpio gpios[] = {
+               {gpio + 7 , GPIOF_OUT_INIT_LOW, "LCD ENABLE"},
+               {gpio + 15, GPIOF_OUT_INIT_LOW, "LCD BACKLIGHT"},
+       };
+
+       r = gpio_request_array(gpios, ARRAY_SIZE(gpios));
+       if (r) {
+               pr_err("Cannot request LCD GPIOs, error %d\n", r);
+               ldp_backlight_gpio = -EINVAL;
+               ldp_lcd_enable_gpio = -EINVAL;
+               return r;
+       }
+
+       ldp_backlight_gpio = gpio + 15;
+       ldp_lcd_enable_gpio = gpio + 7;
+
+       return 0;
+}
+
 static struct twl4030_gpio_platform_data ldp_gpio_data = {
        .gpio_base      = OMAP_MAX_GPIO_LINES,
        .irq_base       = TWL4030_GPIO_IRQ_BASE,
        .irq_end        = TWL4030_GPIO_IRQ_END,
+       .setup          = ldp_twl_gpio_setup,
 };
 
 static struct regulator_consumer_supply ldp_vmmc1_supply[] = {
@@ -243,10 +326,31 @@ static struct regulator_init_data ldp_vaux1 = {
        .consumer_supplies              = ldp_vaux1_supplies,
 };
 
+static struct regulator_consumer_supply ldp_vpll2_supplies[] = {
+       REGULATOR_SUPPLY("vdds_dsi", "omapdss"),
+       REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi1"),
+};
+
+static struct regulator_init_data ldp_vpll2 = {
+       .constraints = {
+               .name                   = "VDVI",
+               .min_uV                 = 1800000,
+               .max_uV                 = 1800000,
+               .apply_uV               = true,
+               .valid_modes_mask       = REGULATOR_MODE_NORMAL
+                                       | REGULATOR_MODE_STANDBY,
+               .valid_ops_mask         = REGULATOR_CHANGE_MODE
+                                       | REGULATOR_CHANGE_STATUS,
+       },
+       .num_consumer_supplies  = ARRAY_SIZE(ldp_vpll2_supplies),
+       .consumer_supplies      = ldp_vpll2_supplies,
+};
+
 static struct twl4030_platform_data ldp_twldata = {
        /* platform_data for children goes here */
        .vmmc1          = &ldp_vmmc1,
        .vaux1          = &ldp_vaux1,
+       .vpll2          = &ldp_vpll2,
        .gpio           = &ldp_gpio_data,
        .keypad         = &ldp_kp_twl4030_data,
 };
@@ -272,7 +376,6 @@ static struct omap2_hsmmc_info mmc[] __initdata = {
 };
 
 static struct platform_device *ldp_devices[] __initdata = {
-       &ldp_lcd_device,
        &ldp_gpio_keys_device,
 };
 
@@ -317,8 +420,6 @@ static struct mtd_partition ldp_nand_partitions[] = {
 static void __init omap_ldp_init(void)
 {
        omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
-       omap_board_config = ldp_config;
-       omap_board_config_size = ARRAY_SIZE(ldp_config);
        ldp_init_smsc911x();
        omap_i2c_init();
        platform_add_devices(ldp_devices, ARRAY_SIZE(ldp_devices));
@@ -329,6 +430,7 @@ static void __init omap_ldp_init(void)
                ARRAY_SIZE(ldp_nand_partitions), ZOOM_NAND_CS, 0);
 
        omap2_hsmmc_init(mmc);
+       ldp_display_init();
 }
 
 MACHINE_START(OMAP_LDP, "OMAP LDP board")
index 1fde8a0474bbb077877697164026f330252a7dbf..928933ba28ce5a8cabf23e911f9ba76379973b45 100644 (file)
@@ -42,7 +42,7 @@
 #include <plat/board.h>
 #include <plat/common.h>
 #include <video/omapdss.h>
-#include <video/omap-panel-generic-dpi.h>
+#include <video/omap-panel-dvi.h>
 #include <plat/gpmc.h>
 #include <plat/nand.h>
 #include <plat/usb.h>
@@ -203,16 +203,16 @@ static void beagle_disable_dvi(struct omap_dss_device *dssdev)
                gpio_set_value(dssdev->reset_gpio, 0);
 }
 
-static struct panel_generic_dpi_data dvi_panel = {
-       .name = "generic",
+static struct panel_dvi_platform_data dvi_panel = {
        .platform_enable = beagle_enable_dvi,
        .platform_disable = beagle_disable_dvi,
+       .i2c_bus_num = 3,
 };
 
 static struct omap_dss_device beagle_dvi_device = {
        .type = OMAP_DISPLAY_TYPE_DPI,
        .name = "dvi",
-       .driver_name = "generic_dpi_panel",
+       .driver_name = "dvi",
        .data = &dvi_panel,
        .phy.dpi.data_lines = 24,
        .reset_gpio = -EINVAL,
index 15c69a0c1ce5050e20883ed124b262d3652ed4fd..0d5a9e46a6afce701007773d55a2ee9cf8f91917 100644 (file)
@@ -45,7 +45,7 @@
 #include <plat/common.h>
 #include <plat/mcspi.h>
 #include <video/omapdss.h>
-#include <video/omap-panel-generic-dpi.h>
+#include <video/omap-panel-dvi.h>
 
 #include "mux.h"
 #include "sdram-micron-mt46h32m32lf-6.h"
@@ -247,8 +247,7 @@ static void omap3_evm_disable_dvi(struct omap_dss_device *dssdev)
        dvi_enabled = 0;
 }
 
-static struct panel_generic_dpi_data dvi_panel = {
-       .name                   = "generic",
+static struct panel_dvi_platform_data dvi_panel = {
        .platform_enable        = omap3_evm_enable_dvi,
        .platform_disable       = omap3_evm_disable_dvi,
 };
@@ -256,7 +255,7 @@ static struct panel_generic_dpi_data dvi_panel = {
 static struct omap_dss_device omap3_evm_dvi_device = {
        .name                   = "dvi",
        .type                   = OMAP_DISPLAY_TYPE_DPI,
-       .driver_name            = "generic_dpi_panel",
+       .driver_name            = "dvi",
        .data                   = &dvi_panel,
        .phy.dpi.data_lines     = 24,
 };
index ace56938dd3b2816f6782264ddb3e2eb541e09cd..cca523eb73b4b90648750789a4c020a806ccee1e 100644 (file)
@@ -335,7 +335,7 @@ static struct regulator_consumer_supply pandora_vmmc3_supply[] = {
 static struct regulator_consumer_supply pandora_vdds_supplies[] = {
        REGULATOR_SUPPLY("vdds_sdi", "omapdss"),
        REGULATOR_SUPPLY("vdds_dsi", "omapdss"),
-       REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi1"),
+       REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.0"),
 };
 
 static struct regulator_consumer_supply pandora_vcc_lcd_supply[] = {
index ba13e1d5d0abecb251066987bd30a79094b11bf2..4732589ad97e7e4bacb368848c4491d697ff3b99 100644 (file)
@@ -41,6 +41,7 @@
 #include <plat/usb.h>
 #include <video/omapdss.h>
 #include <video/omap-panel-generic-dpi.h>
+#include <video/omap-panel-dvi.h>
 
 #include <plat/mcspi.h>
 #include <linux/input/matrix_keypad.h>
@@ -107,39 +108,6 @@ static void __init omap3_stalker_display_init(void)
        return;
 }
 
-static int omap3_stalker_enable_lcd(struct omap_dss_device *dssdev)
-{
-       if (dvi_enabled) {
-               printk(KERN_ERR "cannot enable LCD, DVI is enabled\n");
-               return -EINVAL;
-       }
-       gpio_set_value(DSS_ENABLE_GPIO, 1);
-       gpio_set_value(LCD_PANEL_BKLIGHT_GPIO, 1);
-       lcd_enabled = 1;
-       return 0;
-}
-
-static void omap3_stalker_disable_lcd(struct omap_dss_device *dssdev)
-{
-       gpio_set_value(DSS_ENABLE_GPIO, 0);
-       gpio_set_value(LCD_PANEL_BKLIGHT_GPIO, 0);
-       lcd_enabled = 0;
-}
-
-static struct panel_generic_dpi_data lcd_panel = {
-       .name                   = "generic",
-       .platform_enable        = omap3_stalker_enable_lcd,
-       .platform_disable       = omap3_stalker_disable_lcd,
-};
-
-static struct omap_dss_device omap3_stalker_lcd_device = {
-       .name                   = "lcd",
-       .driver_name            = "generic_dpi_panel",
-       .data                   = &lcd_panel,
-       .phy.dpi.data_lines     = 24,
-       .type                   = OMAP_DISPLAY_TYPE_DPI,
-};
-
 static int omap3_stalker_enable_tv(struct omap_dss_device *dssdev)
 {
        return 0;
@@ -179,8 +147,7 @@ static void omap3_stalker_disable_dvi(struct omap_dss_device *dssdev)
        dvi_enabled = 0;
 }
 
-static struct panel_generic_dpi_data dvi_panel = {
-       .name                   = "generic",
+static struct panel_dvi_platform_data dvi_panel = {
        .platform_enable        = omap3_stalker_enable_dvi,
        .platform_disable       = omap3_stalker_disable_dvi,
 };
@@ -188,13 +155,12 @@ static struct panel_generic_dpi_data dvi_panel = {
 static struct omap_dss_device omap3_stalker_dvi_device = {
        .name                   = "dvi",
        .type                   = OMAP_DISPLAY_TYPE_DPI,
-       .driver_name            = "generic_dpi_panel",
+       .driver_name            = "dvi",
        .data                   = &dvi_panel,
        .phy.dpi.data_lines     = 24,
 };
 
 static struct omap_dss_device *omap3_stalker_dss_devices[] = {
-       &omap3_stalker_lcd_device,
        &omap3_stalker_tv_device,
        &omap3_stalker_dvi_device,
 };
index 49e4bd207cb6924285c051f80b1b8c7d4b9fea78..abb68913e0474b6090c8c88a94bcf047f90a64eb 100644 (file)
@@ -104,15 +104,6 @@ static struct omap2_hsmmc_info mmc[] = {
        {}      /* Terminator */
 };
 
-static struct platform_device omap3_touchbook_lcd_device = {
-       .name           = "omap3touchbook_lcd",
-       .id             = -1,
-};
-
-static struct omap_lcd_config omap3_touchbook_lcd_config __initdata = {
-       .ctrl_name      = "internal",
-};
-
 static struct regulator_consumer_supply touchbook_vmmc1_supply[] = {
        REGULATOR_SUPPLY("vmmc", "omap_hsmmc.0"),
 };
@@ -165,14 +156,12 @@ static struct twl4030_gpio_platform_data touchbook_gpio_data = {
 static struct regulator_consumer_supply touchbook_vdac_supply[] = {
 {
        .supply         = "vdac",
-       .dev            = &omap3_touchbook_lcd_device.dev,
 },
 };
 
 static struct regulator_consumer_supply touchbook_vdvi_supply[] = {
 {
        .supply         = "vdvi",
-       .dev            = &omap3_touchbook_lcd_device.dev,
 },
 };
 
@@ -316,10 +305,6 @@ static struct platform_device keys_gpio = {
        },
 };
 
-static struct omap_board_config_kernel omap3_touchbook_config[] __initdata = {
-       { OMAP_TAG_LCD,         &omap3_touchbook_lcd_config },
-};
-
 #ifdef CONFIG_OMAP_MUX
 static struct omap_board_mux board_mux[] __initdata = {
        { .reg_offset = OMAP_MUX_TERMINATOR },
@@ -339,7 +324,6 @@ static void __init omap3_touchbook_init_irq(void)
 }
 
 static struct platform_device *omap3_touchbook_devices[] __initdata = {
-       &omap3_touchbook_lcd_device,
        &leds_gpio,
        &keys_gpio,
 };
@@ -376,8 +360,6 @@ early_param("tbr", early_touchbook_revision);
 static void __init omap3_touchbook_init(void)
 {
        omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
-       omap_board_config = omap3_touchbook_config;
-       omap_board_config_size = ARRAY_SIZE(omap3_touchbook_config);
 
        pm_power_off = omap3_touchbook_poweroff;
 
index 683bede73d540a060761850e60867f166db325e2..ed38d8fd090f122327b127f44f7bfe92a3cfebcc 100644 (file)
@@ -40,7 +40,7 @@
 #include <plat/common.h>
 #include <plat/usb.h>
 #include <plat/mmc.h>
-#include <video/omap-panel-generic-dpi.h>
+#include <video/omap-panel-dvi.h>
 
 #include "hsmmc.h"
 #include "control.h"
@@ -455,16 +455,16 @@ static void omap4_panda_disable_dvi(struct omap_dss_device *dssdev)
 }
 
 /* Using generic display panel */
-static struct panel_generic_dpi_data omap4_dvi_panel = {
-       .name                   = "generic",
+static struct panel_dvi_platform_data omap4_dvi_panel = {
        .platform_enable        = omap4_panda_enable_dvi,
        .platform_disable       = omap4_panda_disable_dvi,
+       .i2c_bus_num = 3,
 };
 
 struct omap_dss_device omap4_panda_dvi_device = {
        .type                   = OMAP_DISPLAY_TYPE_DPI,
        .name                   = "dvi",
-       .driver_name            = "generic_dpi_panel",
+       .driver_name            = "dvi",
        .data                   = &omap4_dvi_panel,
        .phy.dpi.data_lines     = 24,
        .reset_gpio             = PANDA_DVI_TFP410_POWER_DOWN_GPIO,
index e592fb134c4e8708798b33f61f9a88f747e4944d..ec0f60c1cb7c8bfda39469b812198f06af164cf0 100644 (file)
@@ -46,6 +46,7 @@
 #include <plat/common.h>
 #include <video/omapdss.h>
 #include <video/omap-panel-generic-dpi.h>
+#include <video/omap-panel-dvi.h>
 #include <plat/gpmc.h>
 #include <mach/hardware.h>
 #include <plat/nand.h>
@@ -182,16 +183,16 @@ static void overo_panel_disable_dvi(struct omap_dss_device *dssdev)
        dvi_enabled = 0;
 }
 
-static struct panel_generic_dpi_data dvi_panel = {
-       .name                   = "generic",
+static struct panel_dvi_platform_data dvi_panel = {
        .platform_enable        = overo_panel_enable_dvi,
        .platform_disable       = overo_panel_disable_dvi,
+       .i2c_bus_num            = 3,
 };
 
 static struct omap_dss_device overo_dvi_device = {
        .name                   = "dvi",
        .type                   = OMAP_DISPLAY_TYPE_DPI,
-       .driver_name            = "generic_dpi_panel",
+       .driver_name            = "dvi",
        .data                   = &dvi_panel,
        .phy.dpi.data_lines     = 24,
 };
index 5a886cd2c598c408f3e007e01a5f5e2b0ae9ca94..ba1aa07bdb29d325841b74da3117e76e60e5b668 100644 (file)
@@ -900,7 +900,6 @@ static struct twl4030_platform_data rx51_twldata __initdata = {
 };
 
 static struct tpa6130a2_platform_data rx51_tpa6130a2_data __initdata_or_module = {
-       .id                     = TPA6130A2,
        .power_gpio             = 98,
 };
 
index a6c473bbb3d6392d7b6cc2c03d42d2d1176c17a9..faa2a8e28de59502d24b20ee59520711c3fd03f0 100644 (file)
@@ -79,29 +79,6 @@ static struct cpuidle_params rx51_cpuidle_params[] = {
        {7505 + 15274, 484329, 1},
 };
 
-static struct omap_lcd_config rx51_lcd_config = {
-       .ctrl_name      = "internal",
-};
-
-static struct omap_fbmem_config rx51_fbmem0_config = {
-       .size = 752 * 1024,
-};
-
-static struct omap_fbmem_config rx51_fbmem1_config = {
-       .size = 752 * 1024,
-};
-
-static struct omap_fbmem_config rx51_fbmem2_config = {
-       .size = 752 * 1024,
-};
-
-static struct omap_board_config_kernel rx51_config[] = {
-       { OMAP_TAG_FBMEM,       &rx51_fbmem0_config },
-       { OMAP_TAG_FBMEM,       &rx51_fbmem1_config },
-       { OMAP_TAG_FBMEM,       &rx51_fbmem2_config },
-       { OMAP_TAG_LCD,         &rx51_lcd_config },
-};
-
 static void __init rx51_init_early(void)
 {
        struct omap_sdrc_params *sdrc_params;
@@ -128,8 +105,6 @@ static struct omap_musb_board_data musb_board_data = {
 static void __init rx51_init(void)
 {
        omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
-       omap_board_config = rx51_config;
-       omap_board_config_size = ARRAY_SIZE(rx51_config);
        omap3_pm_init_cpuidle(rx51_cpuidle_params);
        omap_serial_init();
        usb_musb_init(&musb_board_data);
index 5391079c868981ad10adfbf22471aa021c1460f6..ae8ea5b3b1a0f2dc53ef1029f1397804654f4c05 100644 (file)
@@ -329,6 +329,38 @@ static void omap_init_audio(void)
 static inline void omap_init_audio(void) {}
 #endif
 
+#if defined(CONFIG_SND_OMAP_SOC_MCPDM) || \
+               defined(CONFIG_SND_OMAP_SOC_MCPDM_MODULE)
+
+static struct omap_device_pm_latency omap_mcpdm_latency[] = {
+       {
+               .deactivate_func = omap_device_idle_hwmods,
+               .activate_func = omap_device_enable_hwmods,
+               .flags = OMAP_DEVICE_LATENCY_AUTO_ADJUST,
+       },
+};
+
+static void omap_init_mcpdm(void)
+{
+       struct omap_hwmod *oh;
+       struct omap_device *od;
+
+       oh = omap_hwmod_lookup("mcpdm");
+       if (!oh) {
+               printk(KERN_ERR "Could not look up mcpdm hw_mod\n");
+               return;
+       }
+
+       od = omap_device_build("omap-mcpdm", -1, oh, NULL, 0,
+                               omap_mcpdm_latency,
+                               ARRAY_SIZE(omap_mcpdm_latency), 0);
+       if (IS_ERR(od))
+               printk(KERN_ERR "Could not build omap_device for omap-mcpdm-dai\n");
+}
+#else
+static inline void omap_init_mcpdm(void) {}
+#endif
+
 #if defined(CONFIG_SPI_OMAP24XX) || defined(CONFIG_SPI_OMAP24XX_MODULE)
 
 #include <plat/mcspi.h>
@@ -682,6 +714,7 @@ static int __init omap2_init_devices(void)
         * in alphabetical order so they're easier to sort through.
         */
        omap_init_audio();
+       omap_init_mcpdm();
        omap_init_camera();
        omap_init_mbox();
        omap_init_mcspi();
index a5b7a236aa5bf97867136373068765447e7b9838..62510ec863c6293e7646f3161e928d50ff5206b8 100644 (file)
@@ -27,6 +27,8 @@
 #include <plat/omap_device.h>
 #include <plat/omap-pm.h>
 
+#include "control.h"
+
 static struct platform_device omap_display_device = {
        .name          = "omapdss",
        .id            = -1,
@@ -61,7 +63,7 @@ static const struct omap_dss_hwmod_data omap3_dss_hwmod_data[] __initdata = {
        { "dss_dispc", "omapdss_dispc", -1 },
        { "dss_rfbi", "omapdss_rfbi", -1 },
        { "dss_venc", "omapdss_venc", -1 },
-       { "dss_dsi1", "omapdss_dsi1", -1 },
+       { "dss_dsi1", "omapdss_dsi", 0 },
 };
 
 static const struct omap_dss_hwmod_data omap4_dss_hwmod_data[] __initdata = {
@@ -69,11 +71,58 @@ static const struct omap_dss_hwmod_data omap4_dss_hwmod_data[] __initdata = {
        { "dss_dispc", "omapdss_dispc", -1 },
        { "dss_rfbi", "omapdss_rfbi", -1 },
        { "dss_venc", "omapdss_venc", -1 },
-       { "dss_dsi1", "omapdss_dsi1", -1 },
-       { "dss_dsi2", "omapdss_dsi2", -1 },
+       { "dss_dsi1", "omapdss_dsi", 0 },
+       { "dss_dsi2", "omapdss_dsi", 1 },
        { "dss_hdmi", "omapdss_hdmi", -1 },
 };
 
+static int omap4_dsi_mux_pads(int dsi_id, unsigned lanes)
+{
+       u32 enable_mask, enable_shift;
+       u32 pipd_mask, pipd_shift;
+       u32 reg;
+
+       if (dsi_id == 0) {
+               enable_mask = OMAP4_DSI1_LANEENABLE_MASK;
+               enable_shift = OMAP4_DSI1_LANEENABLE_SHIFT;
+               pipd_mask = OMAP4_DSI1_PIPD_MASK;
+               pipd_shift = OMAP4_DSI1_PIPD_SHIFT;
+       } else if (dsi_id == 1) {
+               enable_mask = OMAP4_DSI2_LANEENABLE_MASK;
+               enable_shift = OMAP4_DSI2_LANEENABLE_SHIFT;
+               pipd_mask = OMAP4_DSI2_PIPD_MASK;
+               pipd_shift = OMAP4_DSI2_PIPD_SHIFT;
+       } else {
+               return -ENODEV;
+       }
+
+       reg = omap4_ctrl_pad_readl(OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_DSIPHY);
+
+       reg &= ~enable_mask;
+       reg &= ~pipd_mask;
+
+       reg |= (lanes << enable_shift) & enable_mask;
+       reg |= (lanes << pipd_shift) & pipd_mask;
+
+       omap4_ctrl_pad_writel(reg, OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_DSIPHY);
+
+       return 0;
+}
+
+static int omap_dsi_enable_pads(int dsi_id, unsigned lane_mask)
+{
+       if (cpu_is_omap44xx())
+               return omap4_dsi_mux_pads(dsi_id, lane_mask);
+
+       return 0;
+}
+
+static void omap_dsi_disable_pads(int dsi_id, unsigned lane_mask)
+{
+       if (cpu_is_omap44xx())
+               omap4_dsi_mux_pads(dsi_id, 0);
+}
+
 int __init omap_display_init(struct omap_dss_board_info *board_data)
 {
        int r = 0;
@@ -96,6 +145,11 @@ int __init omap_display_init(struct omap_dss_board_info *board_data)
                oh_count = ARRAY_SIZE(omap4_dss_hwmod_data);
        }
 
+       if (board_data->dsi_enable_pads == NULL)
+               board_data->dsi_enable_pads = omap_dsi_enable_pads;
+       if (board_data->dsi_disable_pads == NULL)
+               board_data->dsi_disable_pads = omap_dsi_disable_pads;
+
        pdata.board_data = board_data;
        pdata.board_data->get_context_loss_count =
                omap_pm_get_dev_context_loss_count;
index f286012783c6c99a9e1cbed453aecdeed43b5e3c..eefc37912ef37fce2b65236f0f4f60ee34c6b99d 100644 (file)
@@ -66,7 +66,7 @@
         ((pgsz) == MMU_CAM_PGSZ_4K)  ? 0xfffff000 : 0)
 
 
-static void __iommu_set_twl(struct iommu *obj, bool on)
+static void __iommu_set_twl(struct omap_iommu *obj, bool on)
 {
        u32 l = iommu_read_reg(obj, MMU_CNTL);
 
@@ -85,7 +85,7 @@ static void __iommu_set_twl(struct iommu *obj, bool on)
 }
 
 
-static int omap2_iommu_enable(struct iommu *obj)
+static int omap2_iommu_enable(struct omap_iommu *obj)
 {
        u32 l, pa;
        unsigned long timeout;
@@ -127,7 +127,7 @@ static int omap2_iommu_enable(struct iommu *obj)
        return 0;
 }
 
-static void omap2_iommu_disable(struct iommu *obj)
+static void omap2_iommu_disable(struct omap_iommu *obj)
 {
        u32 l = iommu_read_reg(obj, MMU_CNTL);
 
@@ -138,12 +138,12 @@ static void omap2_iommu_disable(struct iommu *obj)
        dev_dbg(obj->dev, "%s is shutting down\n", obj->name);
 }
 
-static void omap2_iommu_set_twl(struct iommu *obj, bool on)
+static void omap2_iommu_set_twl(struct omap_iommu *obj, bool on)
 {
        __iommu_set_twl(obj, false);
 }
 
-static u32 omap2_iommu_fault_isr(struct iommu *obj, u32 *ra)
+static u32 omap2_iommu_fault_isr(struct omap_iommu *obj, u32 *ra)
 {
        u32 stat, da;
        u32 errs = 0;
@@ -173,13 +173,13 @@ static u32 omap2_iommu_fault_isr(struct iommu *obj, u32 *ra)
        return errs;
 }
 
-static void omap2_tlb_read_cr(struct iommu *obj, struct cr_regs *cr)
+static void omap2_tlb_read_cr(struct omap_iommu *obj, struct cr_regs *cr)
 {
        cr->cam = iommu_read_reg(obj, MMU_READ_CAM);
        cr->ram = iommu_read_reg(obj, MMU_READ_RAM);
 }
 
-static void omap2_tlb_load_cr(struct iommu *obj, struct cr_regs *cr)
+static void omap2_tlb_load_cr(struct omap_iommu *obj, struct cr_regs *cr)
 {
        iommu_write_reg(obj, cr->cam | MMU_CAM_V, MMU_CAM);
        iommu_write_reg(obj, cr->ram, MMU_RAM);
@@ -193,7 +193,8 @@ static u32 omap2_cr_to_virt(struct cr_regs *cr)
        return cr->cam & mask;
 }
 
-static struct cr_regs *omap2_alloc_cr(struct iommu *obj, struct iotlb_entry *e)
+static struct cr_regs *omap2_alloc_cr(struct omap_iommu *obj,
+                                               struct iotlb_entry *e)
 {
        struct cr_regs *cr;
 
@@ -230,7 +231,8 @@ static u32 omap2_get_pte_attr(struct iotlb_entry *e)
        return attr;
 }
 
-static ssize_t omap2_dump_cr(struct iommu *obj, struct cr_regs *cr, char *buf)
+static ssize_t
+omap2_dump_cr(struct omap_iommu *obj, struct cr_regs *cr, char *buf)
 {
        char *p = buf;
 
@@ -254,7 +256,8 @@ static ssize_t omap2_dump_cr(struct iommu *obj, struct cr_regs *cr, char *buf)
                        goto out;                                       \
        } while (0)
 
-static ssize_t omap2_iommu_dump_ctx(struct iommu *obj, char *buf, ssize_t len)
+static ssize_t
+omap2_iommu_dump_ctx(struct omap_iommu *obj, char *buf, ssize_t len)
 {
        char *p = buf;
 
@@ -280,7 +283,7 @@ out:
        return p - buf;
 }
 
-static void omap2_iommu_save_ctx(struct iommu *obj)
+static void omap2_iommu_save_ctx(struct omap_iommu *obj)
 {
        int i;
        u32 *p = obj->ctx;
@@ -293,7 +296,7 @@ static void omap2_iommu_save_ctx(struct iommu *obj)
        BUG_ON(p[0] != IOMMU_ARCH_VERSION);
 }
 
-static void omap2_iommu_restore_ctx(struct iommu *obj)
+static void omap2_iommu_restore_ctx(struct omap_iommu *obj)
 {
        int i;
        u32 *p = obj->ctx;
@@ -343,13 +346,13 @@ static const struct iommu_functions omap2_iommu_ops = {
 
 static int __init omap2_iommu_init(void)
 {
-       return install_iommu_arch(&omap2_iommu_ops);
+       return omap_install_iommu_arch(&omap2_iommu_ops);
 }
 module_init(omap2_iommu_init);
 
 static void __exit omap2_iommu_exit(void)
 {
-       uninstall_iommu_arch(&omap2_iommu_ops);
+       omap_uninstall_iommu_arch(&omap2_iommu_ops);
 }
 module_exit(omap2_iommu_exit);
 
index 6201422c0606b5103c01e563f67060134658774d..79325c65c23cbcef5196a43852c246185da793a1 100644 (file)
@@ -5430,7 +5430,7 @@ static __initdata struct omap_hwmod *omap44xx_hwmods[] = {
        &omap44xx_mcbsp4_hwmod,
 
        /* mcpdm class */
-/*     &omap44xx_mcpdm_hwmod, */
+       &omap44xx_mcpdm_hwmod,
 
        /* mcspi class */
        &omap44xx_mcspi1_hwmod,
index daa056ed8738112305aba454898a7e18c3ed129c..5224357721686dc41d5a703a3ba02ae1e1e7bf6a 100644 (file)
@@ -99,7 +99,7 @@ static struct regulator_init_data omap3_vdac_idata = {
 
 static struct regulator_consumer_supply omap3_vpll2_supplies[] = {
        REGULATOR_SUPPLY("vdds_dsi", "omapdss"),
-       REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi1"),
+       REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.0"),
 };
 
 static struct regulator_init_data omap3_vpll2_idata = {
@@ -235,6 +235,12 @@ static struct regulator_init_data omap4_vana_idata = {
        },
 };
 
+static struct regulator_consumer_supply omap4_vcxio_supply[] = {
+       REGULATOR_SUPPLY("vdds_dsi", "omapdss_dss"),
+       REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.0"),
+       REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.1"),
+};
+
 static struct regulator_init_data omap4_vcxio_idata = {
        .constraints = {
                .min_uV                 = 1800000,
@@ -243,7 +249,10 @@ static struct regulator_init_data omap4_vcxio_idata = {
                                        | REGULATOR_MODE_STANDBY,
                .valid_ops_mask         = REGULATOR_CHANGE_MODE
                                        | REGULATOR_CHANGE_STATUS,
+               .always_on              = true,
        },
+       .num_consumer_supplies  = ARRAY_SIZE(omap4_vcxio_supply),
+       .consumer_supplies      = omap4_vcxio_supply,
 };
 
 static struct regulator_init_data omap4_vusb_idata = {
index 5fde49da399a3a09c3d80dde524a833480662079..475342bcc95c36356291d866776d6a498678e952 100644 (file)
@@ -355,14 +355,17 @@ static struct resource sdhi0_resources[] = {
                .flags  = IORESOURCE_MEM,
        },
        [1] = {
+               .name   = SH_MOBILE_SDHI_IRQ_CARD_DETECT,
                .start  = gic_spi(83),
                .flags  = IORESOURCE_IRQ,
        },
        [2] = {
+               .name   = SH_MOBILE_SDHI_IRQ_SDCARD,
                .start  = gic_spi(84),
                .flags  = IORESOURCE_IRQ,
        },
        [3] = {
+               .name   = SH_MOBILE_SDHI_IRQ_SDIO,
                .start  = gic_spi(85),
                .flags  = IORESOURCE_IRQ,
        },
@@ -398,14 +401,17 @@ static struct resource sdhi1_resources[] = {
                .flags  = IORESOURCE_MEM,
        },
        [1] = {
+               .name   = SH_MOBILE_SDHI_IRQ_CARD_DETECT,
                .start  = gic_spi(87),
                .flags  = IORESOURCE_IRQ,
        },
        [2] = {
+               .name   = SH_MOBILE_SDHI_IRQ_SDCARD,
                .start  = gic_spi(88),
                .flags  = IORESOURCE_IRQ,
        },
        [3] = {
+               .name   = SH_MOBILE_SDHI_IRQ_SDIO,
                .start  = gic_spi(89),
                .flags  = IORESOURCE_IRQ,
        },
index 7d073c121941773e195bbb99701323c2e1107aa2..3689ad2e9156b42711f4f63fb799292b7fc4595d 100644 (file)
@@ -1072,14 +1072,17 @@ static struct resource sdhi1_resources[] = {
                .flags  = IORESOURCE_MEM,
        },
        [1] = {
+               .name   = SH_MOBILE_SDHI_IRQ_CARD_DETECT,
                .start  = evt2irq(0x0e80), /* SDHI1_SDHI1I0 */
                .flags  = IORESOURCE_IRQ,
        },
        [2] = {
+               .name   = SH_MOBILE_SDHI_IRQ_SDCARD,
                .start  = evt2irq(0x0ea0), /* SDHI1_SDHI1I1 */
                .flags  = IORESOURCE_IRQ,
        },
        [3] = {
+               .name   = SH_MOBILE_SDHI_IRQ_SDIO,
                .start  = evt2irq(0x0ec0), /* SDHI1_SDHI1I2 */
                .flags  = IORESOURCE_IRQ,
        },
@@ -1123,14 +1126,17 @@ static struct resource sdhi2_resources[] = {
                .flags  = IORESOURCE_MEM,
        },
        [1] = {
+               .name   = SH_MOBILE_SDHI_IRQ_CARD_DETECT,
                .start  = evt2irq(0x1200), /* SDHI2_SDHI2I0 */
                .flags  = IORESOURCE_IRQ,
        },
        [2] = {
+               .name   = SH_MOBILE_SDHI_IRQ_SDCARD,
                .start  = evt2irq(0x1220), /* SDHI2_SDHI2I1 */
                .flags  = IORESOURCE_IRQ,
        },
        [3] = {
+               .name   = SH_MOBILE_SDHI_IRQ_SDIO,
                .start  = evt2irq(0x1240), /* SDHI2_SDHI2I2 */
                .flags  = IORESOURCE_IRQ,
        },
@@ -1591,6 +1597,7 @@ static void __init mackerel_init(void)
 
        sh7372_add_device_to_domain(&sh7372_a4lc, &lcdc_device);
        sh7372_add_device_to_domain(&sh7372_a4lc, &hdmi_lcdc_device);
+       sh7372_add_device_to_domain(&sh7372_a4lc, &meram_device);
        sh7372_add_device_to_domain(&sh7372_a4mp, &fsi_device);
        sh7372_add_device_to_domain(&sh7372_a3sp, &usbhs0_device);
        sh7372_add_device_to_domain(&sh7372_a3sp, &usbhs1_device);
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..40a8c178f10d9e85a2873c83247c3f2fe553f408 100644 (file)
@@ -0,0 +1 @@
+/* empty */
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..40a8c178f10d9e85a2873c83247c3f2fe553f408 100644 (file)
@@ -0,0 +1 @@
+/* empty */
diff --git a/arch/arm/mach-vexpress/include/mach/gpio.h b/arch/arm/mach-vexpress/include/mach/gpio.h
new file mode 100644 (file)
index 0000000..40a8c17
--- /dev/null
@@ -0,0 +1 @@
+/* empty */
index 3ba4d8f8073baf10279e3c69122c822c87d8bb1c..9605bf227df9e9ebca2ccda718f8e4aa7a81c9f8 100644 (file)
@@ -67,6 +67,9 @@ extern int nmk_gpio_get_mode(int gpio);
 extern void nmk_gpio_wakeups_suspend(void);
 extern void nmk_gpio_wakeups_resume(void);
 
+extern void nmk_gpio_clocks_enable(void);
+extern void nmk_gpio_clocks_disable(void);
+
 extern void nmk_gpio_read_pull(int gpio_bank, u32 *pull_up);
 
 /*
index 6f4edd3408c203815e3d496c7333bb05df24d746..aa59f4247dc53bba585fa7f93e050c10902a0708 100644 (file)
@@ -134,18 +134,6 @@ config OMAP_MBOX_KFIFO_SIZE
          This can also be changed at runtime (via the mbox_kfifo_size
          module parameter).
 
-config OMAP_IOMMU
-       tristate
-
-config OMAP_IOMMU_DEBUG
-       tristate "Export OMAP IOMMU internals in DebugFS"
-       depends on OMAP_IOMMU && DEBUG_FS
-       help
-         Select this to see extensive information about
-         the internal state of OMAP IOMMU in debugfs.
-
-         Say N unless you know you need this.
-
 config OMAP_IOMMU_IVA2
        bool
 
index f0233e6abcdff0e9d72fe4967df9be6a36e8e4e6..985262242f25d994399511fa964b434c47cb18d6 100644 (file)
@@ -18,8 +18,6 @@ obj-$(CONFIG_ARCH_OMAP3) += omap_device.o
 obj-$(CONFIG_ARCH_OMAP4) += omap_device.o
 
 obj-$(CONFIG_OMAP_MCBSP) += mcbsp.o
-obj-$(CONFIG_OMAP_IOMMU) += iommu.o iovmm.o
-obj-$(CONFIG_OMAP_IOMMU_DEBUG) += iommu-debug.o
 
 obj-$(CONFIG_CPU_FREQ) += cpu-omap.o
 obj-$(CONFIG_OMAP_DM_TIMER) += dmtimer.o
index 64c3bd4aa54ecbd43c9d4f6eeccaaf97fa0001e1..c46c47afa090cd636ae03932d97f3b005ab4072d 100644 (file)
@@ -73,41 +73,6 @@ void omap_mcbsp_register_board_cfg(struct resource *res, int res_count,
 
 /*-------------------------------------------------------------------------*/
 
-#if defined(CONFIG_SND_OMAP_SOC_MCPDM) || \
-               defined(CONFIG_SND_OMAP_SOC_MCPDM_MODULE)
-
-static struct resource mcpdm_resources[] = {
-       {
-               .name           = "mcpdm_mem",
-               .start          = OMAP44XX_MCPDM_BASE,
-               .end            = OMAP44XX_MCPDM_BASE + SZ_4K,
-               .flags          = IORESOURCE_MEM,
-       },
-       {
-               .name           = "mcpdm_irq",
-               .start          = OMAP44XX_IRQ_MCPDM,
-               .end            = OMAP44XX_IRQ_MCPDM,
-               .flags          = IORESOURCE_IRQ,
-       },
-};
-
-static struct platform_device omap_mcpdm_device = {
-       .name           = "omap-mcpdm",
-       .id             = -1,
-       .num_resources  = ARRAY_SIZE(mcpdm_resources),
-       .resource       = mcpdm_resources,
-};
-
-static void omap_init_mcpdm(void)
-{
-       (void) platform_device_register(&omap_mcpdm_device);
-}
-#else
-static inline void omap_init_mcpdm(void) {}
-#endif
-
-/*-------------------------------------------------------------------------*/
-
 #if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE) || \
        defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
 
@@ -290,7 +255,6 @@ static int __init omap_init_devices(void)
         * in alphabetical order so they're easier to sort through.
         */
        omap_init_rng();
-       omap_init_mcpdm();
        omap_init_uwire();
        return 0;
 }
index 174f1b9c8c0364c3284edb66ab390cbb49b9243c..a1d79ee192503e3c14fd19fddb1bd24af933e0ad 100644 (file)
@@ -25,16 +25,17 @@ struct iotlb_entry {
        };
 };
 
-struct iommu {
+struct omap_iommu {
        const char      *name;
        struct module   *owner;
        struct clk      *clk;
        void __iomem    *regbase;
        struct device   *dev;
        void            *isr_priv;
+       struct iommu_domain *domain;
 
        unsigned int    refcount;
-       struct mutex    iommu_lock;     /* global for this whole object */
+       spinlock_t      iommu_lock;     /* global for this whole object */
 
        /*
         * We don't change iopgd for a situation like pgd for a task,
@@ -48,8 +49,6 @@ struct iommu {
        struct list_head        mmap;
        struct mutex            mmap_lock; /* protect mmap */
 
-       int (*isr)(struct iommu *obj, u32 da, u32 iommu_errs, void *priv);
-
        void *ctx; /* iommu context: registres saved area */
        u32 da_start;
        u32 da_end;
@@ -81,25 +80,27 @@ struct iotlb_lock {
 struct iommu_functions {
        unsigned long   version;
 
-       int (*enable)(struct iommu *obj);
-       void (*disable)(struct iommu *obj);
-       void (*set_twl)(struct iommu *obj, bool on);
-       u32 (*fault_isr)(struct iommu *obj, u32 *ra);
+       int (*enable)(struct omap_iommu *obj);
+       void (*disable)(struct omap_iommu *obj);
+       void (*set_twl)(struct omap_iommu *obj, bool on);
+       u32 (*fault_isr)(struct omap_iommu *obj, u32 *ra);
 
-       void (*tlb_read_cr)(struct iommu *obj, struct cr_regs *cr);
-       void (*tlb_load_cr)(struct iommu *obj, struct cr_regs *cr);
+       void (*tlb_read_cr)(struct omap_iommu *obj, struct cr_regs *cr);
+       void (*tlb_load_cr)(struct omap_iommu *obj, struct cr_regs *cr);
 
-       struct cr_regs *(*alloc_cr)(struct iommu *obj, struct iotlb_entry *e);
+       struct cr_regs *(*alloc_cr)(struct omap_iommu *obj,
+                                                       struct iotlb_entry *e);
        int (*cr_valid)(struct cr_regs *cr);
        u32 (*cr_to_virt)(struct cr_regs *cr);
        void (*cr_to_e)(struct cr_regs *cr, struct iotlb_entry *e);
-       ssize_t (*dump_cr)(struct iommu *obj, struct cr_regs *cr, char *buf);
+       ssize_t (*dump_cr)(struct omap_iommu *obj, struct cr_regs *cr,
+                                                       char *buf);
 
        u32 (*get_pte_attr)(struct iotlb_entry *e);
 
-       void (*save_ctx)(struct iommu *obj);
-       void (*restore_ctx)(struct iommu *obj);
-       ssize_t (*dump_ctx)(struct iommu *obj, char *buf, ssize_t len);
+       void (*save_ctx)(struct omap_iommu *obj);
+       void (*restore_ctx)(struct omap_iommu *obj);
+       ssize_t (*dump_ctx)(struct omap_iommu *obj, char *buf, ssize_t len);
 };
 
 struct iommu_platform_data {
@@ -150,40 +151,31 @@ struct iommu_platform_data {
 /*
  * global functions
  */
-extern u32 iommu_arch_version(void);
-
-extern void iotlb_cr_to_e(struct cr_regs *cr, struct iotlb_entry *e);
-extern u32 iotlb_cr_to_virt(struct cr_regs *cr);
-
-extern int load_iotlb_entry(struct iommu *obj, struct iotlb_entry *e);
-extern void iommu_set_twl(struct iommu *obj, bool on);
-extern void flush_iotlb_page(struct iommu *obj, u32 da);
-extern void flush_iotlb_range(struct iommu *obj, u32 start, u32 end);
-extern void flush_iotlb_all(struct iommu *obj);
-
-extern int iopgtable_store_entry(struct iommu *obj, struct iotlb_entry *e);
-extern void iopgtable_lookup_entry(struct iommu *obj, u32 da, u32 **ppgd,
-                                  u32 **ppte);
-extern size_t iopgtable_clear_entry(struct iommu *obj, u32 iova);
-
-extern int iommu_set_da_range(struct iommu *obj, u32 start, u32 end);
-extern struct iommu *iommu_get(const char *name);
-extern void iommu_put(struct iommu *obj);
-extern int iommu_set_isr(const char *name,
-                        int (*isr)(struct iommu *obj, u32 da, u32 iommu_errs,
+extern u32 omap_iommu_arch_version(void);
+
+extern void omap_iotlb_cr_to_e(struct cr_regs *cr, struct iotlb_entry *e);
+
+extern int
+omap_iopgtable_store_entry(struct omap_iommu *obj, struct iotlb_entry *e);
+
+extern int omap_iommu_set_isr(const char *name,
+                int (*isr)(struct omap_iommu *obj, u32 da, u32 iommu_errs,
                                    void *priv),
                         void *isr_priv);
 
-extern void iommu_save_ctx(struct iommu *obj);
-extern void iommu_restore_ctx(struct iommu *obj);
+extern void omap_iommu_save_ctx(struct omap_iommu *obj);
+extern void omap_iommu_restore_ctx(struct omap_iommu *obj);
 
-extern int install_iommu_arch(const struct iommu_functions *ops);
-extern void uninstall_iommu_arch(const struct iommu_functions *ops);
+extern int omap_install_iommu_arch(const struct iommu_functions *ops);
+extern void omap_uninstall_iommu_arch(const struct iommu_functions *ops);
 
-extern int foreach_iommu_device(void *data,
+extern int omap_foreach_iommu_device(void *data,
                                int (*fn)(struct device *, void *));
 
-extern ssize_t iommu_dump_ctx(struct iommu *obj, char *buf, ssize_t len);
-extern size_t dump_tlb_entries(struct iommu *obj, char *buf, ssize_t len);
+extern ssize_t
+omap_iommu_dump_ctx(struct omap_iommu *obj, char *buf, ssize_t len);
+extern size_t
+omap_dump_tlb_entries(struct omap_iommu *obj, char *buf, ssize_t len);
+struct device *omap_find_iommu_device(const char *name);
 
 #endif /* __MACH_IOMMU_H */
index 10ad05f410e9ead9e16a834ad011a24a50aa6a68..d4116b595e400d580264a58740237964b7d82305 100644 (file)
 /*
  * register accessors
  */
-static inline u32 iommu_read_reg(struct iommu *obj, size_t offs)
+static inline u32 iommu_read_reg(struct omap_iommu *obj, size_t offs)
 {
        return __raw_readl(obj->regbase + offs);
 }
 
-static inline void iommu_write_reg(struct iommu *obj, u32 val, size_t offs)
+static inline void iommu_write_reg(struct omap_iommu *obj, u32 val, size_t offs)
 {
        __raw_writel(val, obj->regbase + offs);
 }
similarity index 82%
rename from arch/arm/plat-omap/iopgtable.h
rename to arch/arm/plat-omap/include/plat/iopgtable.h
index c3e93bb0911f1f405abc33d3eb85be7736b9e1a2..66a813977d52f453c155b45710028f087e1dec35 100644 (file)
 
 #define IOPAGE_MASK            IOPTE_MASK
 
+/**
+ * omap_iommu_translate() - va to pa translation
+ * @d:         omap iommu descriptor
+ * @va:                virtual address
+ * @mask:      omap iommu descriptor mask
+ *
+ * va to pa translation
+ */
+static inline phys_addr_t omap_iommu_translate(u32 d, u32 va, u32 mask)
+{
+       return (d & mask) | (va & (~mask));
+}
+
 /*
  * some descriptor attributes.
  */
 #define IOPGD_SUPER            (1 << 18 | 2 << 0)
 
 #define iopgd_is_table(x)      (((x) & 3) == IOPGD_TABLE)
+#define iopgd_is_section(x)    (((x) & (1 << 18 | 3)) == IOPGD_SECTION)
+#define iopgd_is_super(x)      (((x) & (1 << 18 | 3)) == IOPGD_SUPER)
 
 #define IOPTE_SMALL            (2 << 0)
 #define IOPTE_LARGE            (1 << 0)
 
+#define iopte_is_small(x)      (((x) & 2) == IOPTE_SMALL)
+#define iopte_is_large(x)      (((x) & 3) == IOPTE_LARGE)
+
 /* to find an entry in a page-table-directory */
 #define iopgd_index(da)                (((da) >> IOPGD_SHIFT) & (PTRS_PER_IOPGD - 1))
 #define iopgd_offset(obj, da)  ((obj)->iopgd + iopgd_index(da))
@@ -97,6 +115,6 @@ static inline u32 iotlb_init_entry(struct iotlb_entry *e, u32 da, u32 pa,
 }
 
 #define to_iommu(dev)                                                  \
-       (struct iommu *)platform_get_drvdata(to_platform_device(dev))
+       (struct omap_iommu *)platform_get_drvdata(to_platform_device(dev))
 
 #endif /* __PLAT_OMAP_IOMMU_H */
index e992b9655fbc4fb873d489846ce82e8644ea5ea6..6af1a91c0f36311996f91f2328cfe84da770064a 100644 (file)
 #ifndef __IOMMU_MMAP_H
 #define __IOMMU_MMAP_H
 
+#include <linux/iommu.h>
+
 struct iovm_struct {
-       struct iommu            *iommu; /* iommu object which this belongs to */
+       struct omap_iommu       *iommu; /* iommu object which this belongs to */
        u32                     da_start; /* area definition */
        u32                     da_end;
        u32                     flags; /* IOVMF_: see below */
@@ -70,20 +72,18 @@ struct iovm_struct {
 #define IOVMF_DA_FIXED         (1 << (4 + IOVMF_SW_SHIFT))
 
 
-extern struct iovm_struct *find_iovm_area(struct iommu *obj, u32 da);
-extern u32 iommu_vmap(struct iommu *obj, u32 da,
+extern struct iovm_struct *omap_find_iovm_area(struct omap_iommu *obj, u32 da);
+extern u32
+omap_iommu_vmap(struct iommu_domain *domain, struct omap_iommu *obj, u32 da,
                        const struct sg_table *sgt, u32 flags);
-extern struct sg_table *iommu_vunmap(struct iommu *obj, u32 da);
-extern u32 iommu_vmalloc(struct iommu *obj, u32 da, size_t bytes,
-                          u32 flags);
-extern void iommu_vfree(struct iommu *obj, const u32 da);
-extern u32 iommu_kmap(struct iommu *obj, u32 da, u32 pa, size_t bytes,
-                       u32 flags);
-extern void iommu_kunmap(struct iommu *obj, u32 da);
-extern u32 iommu_kmalloc(struct iommu *obj, u32 da, size_t bytes,
-                          u32 flags);
-extern void iommu_kfree(struct iommu *obj, u32 da);
-
-extern void *da_to_va(struct iommu *obj, u32 da);
+extern struct sg_table *omap_iommu_vunmap(struct iommu_domain *domain,
+                               struct omap_iommu *obj, u32 da);
+extern u32
+omap_iommu_vmalloc(struct iommu_domain *domain, struct omap_iommu *obj,
+                               u32 da, size_t bytes, u32 flags);
+extern void
+omap_iommu_vfree(struct iommu_domain *domain, struct omap_iommu *obj,
+                               const u32 da);
+extern void *omap_da_to_va(struct omap_iommu *obj, u32 da);
 
 #endif /* __IOMMU_MMAP_H */
index c7b874186c27017d58a38bc4209e1c225752d3f5..94cf70afb236bd5950e3ca0f7aaa5cfb86010cb4 100644 (file)
 
 #define OMAP_MMC_MAX_SLOTS     2
 
-#define OMAP_HSMMC_SUPPORTS_DUAL_VOLT  BIT(1)
+/*
+ * struct omap_mmc_dev_attr.flags possibilities
+ *
+ * OMAP_HSMMC_SUPPORTS_DUAL_VOLT: Some HSMMC controller instances can
+ *    operate with either 1.8Vdc or 3.0Vdc card voltages; this flag
+ *    should be set if this is the case.  See for example Section 22.5.3
+ *    "MMC/SD/SDIO1 Bus Voltage Selection" of the OMAP34xx Multimedia
+ *    Device Silicon Revision 3.1.x Revision ZR (July 2011) (SWPU223R).
+ *
+ * OMAP_HSMMC_BROKEN_MULTIBLOCK_READ: Multiple-block read transfers
+ *    don't work correctly on some MMC controller instances on some
+ *    OMAP3 SoCs; this flag should be set if this is the case.  See
+ *    for example Advisory 2.1.1.128 "MMC: Multiple Block Read
+ *    Operation Issue" in _OMAP3530/3525/3515/3503 Silicon Errata_
+ *    Revision F (October 2010) (SPRZ278F).
+ */
+#define OMAP_HSMMC_SUPPORTS_DUAL_VOLT          BIT(0)
+#define OMAP_HSMMC_BROKEN_MULTIBLOCK_READ      BIT(1)
 
 struct omap_mmc_dev_attr {
        u8 flags;
index b9f9c8ce216906ed4ee498667c00e5425e13011b..b579dd02e098eb666d21e4fcdc1d83ef0adbb65f 100644 (file)
@@ -694,7 +694,7 @@ mem2hex(char *buf, unsigned char *mem, int count)
                 /* Valid mem address. */
                 for (i = 0; i < count; i++) {
                         ch = *mem++;
-                       buf = pack_hex_byte(buf, ch);
+                       buf = hex_byte_pack(buf, ch);
                 }
         }
         
@@ -868,7 +868,7 @@ stub_is_stopped(int sigval)
        /* Send trap type (converted to signal) */
 
        *ptr++ = 'T';
-       ptr = pack_hex_byte(ptr, sigval);
+       ptr = hex_byte_pack(ptr, sigval);
 
        /* Send register contents. We probably only need to send the
         * PC, frame pointer and stack pointer here. Other registers will be
@@ -881,7 +881,7 @@ stub_is_stopped(int sigval)
                 status = read_register (regno, &reg_cont);
                 
                if (status == SUCCESS) {
-                       ptr = pack_hex_byte(ptr, regno);
+                       ptr = hex_byte_pack(ptr, regno);
                         *ptr++ = ':';
 
                         ptr = mem2hex(ptr, (unsigned char *)&reg_cont,
index c0343c3ea7f8e592ab4288ee6c56bf48e68ec0a7..8c1d35cdf00a3aa0c0a65305148a92d091ebeaef 100644 (file)
@@ -677,7 +677,7 @@ mem2hex(char *buf, unsigned char *mem, int count)
                 /* Valid mem address. */
                for (i = 0; i < count; i++) {
                        ch = *mem++;
-                       buf = pack_hex_byte(buf, ch);
+                       buf = hex_byte_pack(buf, ch);
                }
         }
         /* Terminate properly. */
@@ -695,7 +695,7 @@ mem2hex_nbo(char *buf, unsigned char *mem, int count)
        mem += count - 1;
        for (i = 0; i < count; i++) {
                ch = *mem--;
-               buf = pack_hex_byte(buf, ch);
+               buf = hex_byte_pack(buf, ch);
         }
 
         /* Terminate properly. */
@@ -880,7 +880,7 @@ stub_is_stopped(int sigval)
        /* Send trap type (converted to signal) */
 
        *ptr++ = 'T';
-       ptr = pack_hex_byte(ptr, sigval);
+       ptr = hex_byte_pack(ptr, sigval);
 
        if (((reg.exs & 0xff00) >> 8) == 0xc) {
 
@@ -988,26 +988,26 @@ stub_is_stopped(int sigval)
        }
        /* Only send PC, frame and stack pointer. */
        read_register(PC, &reg_cont);
-       ptr = pack_hex_byte(ptr, PC);
+       ptr = hex_byte_pack(ptr, PC);
        *ptr++ = ':';
        ptr = mem2hex(ptr, (unsigned char *)&reg_cont, register_size[PC]);
        *ptr++ = ';';
 
        read_register(R8, &reg_cont);
-       ptr = pack_hex_byte(ptr, R8);
+       ptr = hex_byte_pack(ptr, R8);
        *ptr++ = ':';
        ptr = mem2hex(ptr, (unsigned char *)&reg_cont, register_size[R8]);
        *ptr++ = ';';
 
        read_register(SP, &reg_cont);
-       ptr = pack_hex_byte(ptr, SP);
+       ptr = hex_byte_pack(ptr, SP);
        *ptr++ = ':';
        ptr = mem2hex(ptr, (unsigned char *)&reg_cont, register_size[SP]);
        *ptr++ = ';';
 
        /* Send ERP as well; this will save us an entire register fetch in some cases. */
         read_register(ERP, &reg_cont);
-       ptr = pack_hex_byte(ptr, ERP);
+       ptr = hex_byte_pack(ptr, ERP);
         *ptr++ = ':';
         ptr = mem2hex(ptr, (unsigned char *)&reg_cont, register_size[ERP]);
         *ptr++ = ';';
index a4dba6b20bd0b8f4e2cd9582bd97c9a39a8453b7..a6d5381c94fee5cb871099bea62b9db848b3efaa 100644 (file)
@@ -672,7 +672,7 @@ static unsigned char *mem2hex(const void *_mem, char *buf, int count, int may_fa
        if ((uint32_t)mem&1 && count>=1) {
                if (!gdbstub_read_byte(mem,ch))
                        return NULL;
-               buf = pack_hex_byte(buf, ch[0]);
+               buf = hex_byte_pack(buf, ch[0]);
                mem++;
                count--;
        }
@@ -680,8 +680,8 @@ static unsigned char *mem2hex(const void *_mem, char *buf, int count, int may_fa
        if ((uint32_t)mem&3 && count>=2) {
                if (!gdbstub_read_word(mem,(uint16_t *)ch))
                        return NULL;
-               buf = pack_hex_byte(buf, ch[0]);
-               buf = pack_hex_byte(buf, ch[1]);
+               buf = hex_byte_pack(buf, ch[0]);
+               buf = hex_byte_pack(buf, ch[1]);
                mem += 2;
                count -= 2;
        }
@@ -689,10 +689,10 @@ static unsigned char *mem2hex(const void *_mem, char *buf, int count, int may_fa
        while (count>=4) {
                if (!gdbstub_read_dword(mem,(uint32_t *)ch))
                        return NULL;
-               buf = pack_hex_byte(buf, ch[0]);
-               buf = pack_hex_byte(buf, ch[1]);
-               buf = pack_hex_byte(buf, ch[2]);
-               buf = pack_hex_byte(buf, ch[3]);
+               buf = hex_byte_pack(buf, ch[0]);
+               buf = hex_byte_pack(buf, ch[1]);
+               buf = hex_byte_pack(buf, ch[2]);
+               buf = hex_byte_pack(buf, ch[3]);
                mem += 4;
                count -= 4;
        }
@@ -700,8 +700,8 @@ static unsigned char *mem2hex(const void *_mem, char *buf, int count, int may_fa
        if (count>=2) {
                if (!gdbstub_read_word(mem,(uint16_t *)ch))
                        return NULL;
-               buf = pack_hex_byte(buf, ch[0]);
-               buf = pack_hex_byte(buf, ch[1]);
+               buf = hex_byte_pack(buf, ch[0]);
+               buf = hex_byte_pack(buf, ch[1]);
                mem += 2;
                count -= 2;
        }
@@ -709,7 +709,7 @@ static unsigned char *mem2hex(const void *_mem, char *buf, int count, int may_fa
        if (count>=1) {
                if (!gdbstub_read_byte(mem,ch))
                        return NULL;
-               buf = pack_hex_byte(buf, ch[0]);
+               buf = hex_byte_pack(buf, ch[0]);
        }
 
        *buf = 0;
@@ -1498,21 +1498,21 @@ void gdbstub(int sigval)
                ptr = mem2hex(title, ptr, sizeof(title) - 1,0);
 
                hx = hex_asc_hi(brr >> 24);
-               ptr = pack_hex_byte(ptr, hx);
+               ptr = hex_byte_pack(ptr, hx);
                hx = hex_asc_lo(brr >> 24);
-               ptr = pack_hex_byte(ptr, hx);
+               ptr = hex_byte_pack(ptr, hx);
                hx = hex_asc_hi(brr >> 16);
-               ptr = pack_hex_byte(ptr, hx);
+               ptr = hex_byte_pack(ptr, hx);
                hx = hex_asc_lo(brr >> 16);
-               ptr = pack_hex_byte(ptr, hx);
+               ptr = hex_byte_pack(ptr, hx);
                hx = hex_asc_hi(brr >> 8);
-               ptr = pack_hex_byte(ptr, hx);
+               ptr = hex_byte_pack(ptr, hx);
                hx = hex_asc_lo(brr >> 8);
-               ptr = pack_hex_byte(ptr, hx);
+               ptr = hex_byte_pack(ptr, hx);
                hx = hex_asc_hi(brr);
-               ptr = pack_hex_byte(ptr, hx);
+               ptr = hex_byte_pack(ptr, hx);
                hx = hex_asc_lo(brr);
-               ptr = pack_hex_byte(ptr, hx);
+               ptr = hex_byte_pack(ptr, hx);
 
                ptr = mem2hex(crlf, ptr, sizeof(crlf) - 1, 0);
                *ptr = 0;
@@ -1526,10 +1526,10 @@ void gdbstub(int sigval)
 
        /* Send trap type (converted to signal) */
        *ptr++ = 'T';
-       ptr = pack_hex_byte(ptr, sigval);
+       ptr = hex_byte_pack(ptr, sigval);
 
        /* Send Error PC */
-       ptr = pack_hex_byte(ptr, GDB_REG_PC);
+       ptr = hex_byte_pack(ptr, GDB_REG_PC);
        *ptr++ = ':';
        ptr = mem2hex(&__debug_frame->pc, ptr, 4, 0);
        *ptr++ = ';';
@@ -1537,7 +1537,7 @@ void gdbstub(int sigval)
        /*
         * Send frame pointer
         */
-       ptr = pack_hex_byte(ptr, GDB_REG_FP);
+       ptr = hex_byte_pack(ptr, GDB_REG_FP);
        *ptr++ = ':';
        ptr = mem2hex(&__debug_frame->fp, ptr, 4, 0);
        *ptr++ = ';';
@@ -1545,7 +1545,7 @@ void gdbstub(int sigval)
        /*
         * Send stack pointer
         */
-       ptr = pack_hex_byte(ptr, GDB_REG_SP);
+       ptr = hex_byte_pack(ptr, GDB_REG_SP);
        *ptr++ = ':';
        ptr = mem2hex(&__debug_frame->sp, ptr, 4, 0);
        *ptr++ = ';';
index e977345105d7d83707ad9d0557e5577368822885..bc4f51bceef5e3927682feba994c78dc16e98dc5 100644 (file)
@@ -11,7 +11,7 @@
 #include <asm/traps.h>
 #include <asm/irq.h>
 #include <asm/io.h>
-#include <asm/gpio.h>
+#include <asm/gpio-internal.h>
 #include <asm/regs306x.h>
 
 const int __initdata h8300_saved_vectors[] = {
index 8182f041f82956abb8be40d35a7fc5df0c952cfb..7b5f29febc0740a53d11ec410e892b813dee792a 100644 (file)
@@ -14,7 +14,7 @@
 #include <asm/traps.h>
 #include <asm/irq.h>
 #include <asm/io.h>
-#include <asm/gpio.h>
+#include <asm/gpio-internal.h>
 #include <asm/regs267x.h>
 
 /* saved vector list */
diff --git a/arch/hexagon/Kconfig b/arch/hexagon/Kconfig
new file mode 100644 (file)
index 0000000..02513c2
--- /dev/null
@@ -0,0 +1,220 @@
+# Hexagon configuration
+comment "Linux Kernel Configuration for Hexagon"
+
+config HEXAGON
+       def_bool y
+       select HAVE_OPROFILE
+       select USE_GENERIC_SMP_HELPERS if SMP
+       # Other pending projects/to-do items.
+       # select HAVE_REGS_AND_STACK_ACCESS_API
+       # select HAVE_HW_BREAKPOINT if PERF_EVENTS
+       # select ARCH_HAS_CPU_IDLE_WAIT
+       # select ARCH_WANT_OPTIONAL_GPIOLIB
+       # select ARCH_REQUIRE_GPIOLIB
+       # select HAVE_CLK
+       # select IRQ_PER_CPU
+       select HAVE_IRQ_WORK
+       # select GENERIC_PENDING_IRQ if SMP
+       select GENERIC_ATOMIC64
+       select HAVE_PERF_EVENTS
+       select HAVE_GENERIC_HARDIRQS
+       select GENERIC_HARDIRQS_NO__DO_IRQ
+       select GENERIC_HARDIRQS_NO_DEPRECATED
+       # GENERIC_ALLOCATOR is used by dma_alloc_coherent()
+       select GENERIC_ALLOCATOR
+       select GENERIC_IRQ_SHOW
+       select HAVE_ARCH_KGDB
+       select HAVE_ARCH_TRACEHOOK
+       select NO_IOPORT
+       # mostly generic routines, with some accelerated ones
+       ---help---
+         Qualcomm Hexagon is a processor architecture designed for high
+         performance and low power across a wide variety of applications.
+
+config HEXAGON_ARCH_V1
+       bool
+
+config HEXAGON_ARCH_V2
+       bool
+
+config HEXAGON_ARCH_V3
+       bool
+
+config HEXAGON_ARCH_V4
+       bool
+
+config FRAME_POINTER
+       def_bool y
+
+config LOCKDEP_SUPPORT
+       def_bool y
+
+config PCI
+       def_bool n
+
+config EARLY_PRINTK
+       def_bool y
+
+config KTIME_SCALAR
+       def_bool y
+
+config MMU
+       def_bool y
+
+config TRACE_IRQFLAGS_SUPPORT
+       def_bool y
+
+config GENERIC_CSUM
+       def_bool y
+
+#
+# Use the generic interrupt handling code in kernel/irq/:
+#
+config GENERIC_IRQ_PROBE
+       def_bool y
+
+config GENERIC_IOMAP
+       def_bool y
+
+#config ZONE_DMA
+#      bool
+#      default y
+
+config HAS_DMA
+       bool
+       select HAVE_DMA_ATTRS
+       default y
+
+config NEED_SG_DMA_LENGTH
+       def_bool y
+
+config RWSEM_GENERIC_SPINLOCK
+       def_bool n
+
+config RWSEM_XCHGADD_ALGORITHM
+       def_bool y
+
+config GENERIC_FIND_NEXT_BIT
+       def_bool y
+
+config GENERIC_HWEIGHT
+       def_bool y
+
+config GENERIC_TIME
+       def_bool y
+
+config GENERIC_CLOCKEVENTS
+       def_bool y
+
+config GENERIC_CLOCKEVENTS_BROADCAST
+       def_bool y
+
+config STACKTRACE_SUPPORT
+       def_bool y
+       select STACKTRACE
+
+config GENERIC_BUG
+       def_bool y
+       depends on BUG
+
+config BUG
+       def_bool y
+
+menu "Machine selection"
+
+choice
+       prompt "System type"
+       default HEXAGON_ARCH_V2
+
+config HEXAGON_COMET
+       bool "Comet Board"
+       select HEXAGON_ARCH_V2
+       ---help---
+         Support for the Comet platform.
+
+endchoice
+
+config HEXAGON_VM
+       def_bool y
+
+config CMDLINE
+       string "Default kernel command string"
+       default ""
+       help
+         On some platforms, there is currently no way for the boot loader
+         to pass arguments to the kernel. For these, you should supply some
+         command-line options at build time by entering them here.  At a
+         minimum, you should specify the memory size and the root device
+         (e.g., mem=64M root=/dev/nfs).
+
+config HEXAGON_ANGEL_TRAPS
+       bool "Use Angel Traps"
+       default n
+       ---help---
+         Enable angel debug traps (for printk's).
+
+config SMP
+       bool "Multi-Processing support"
+       ---help---
+         Enables SMP support in the kernel.  If unsure, say "Y"
+
+config NR_CPUS
+       int "Maximum number of CPUs" if SMP
+       range 2 6 if SMP
+       default "1" if !SMP
+       default "6" if SMP
+       ---help---
+         This allows you to specify the maximum number of CPUs which this
+         kernel will support.  The maximum supported value is 6 and the
+         minimum value which makes sense is 2.
+
+         This is purely to save memory - each supported CPU adds
+         approximately eight kilobytes to the kernel image.
+
+choice
+       prompt "Kernel page size"
+       default PAGE_SIZE_4KB
+       ---help---
+         Changes the default page size; use with caution.
+
+config PAGE_SIZE_4KB
+       bool "4KB"
+
+config PAGE_SIZE_16KB
+       bool "16KB"
+
+config PAGE_SIZE_64KB
+       bool "64KB"
+
+config PAGE_SIZE_256KB
+       bool "256KB"
+
+endchoice
+
+source "mm/Kconfig"
+
+source "kernel/Kconfig.hz"
+source "kernel/time/Kconfig"
+
+config GENERIC_GPIO
+       bool "Generic GPIO support"
+       default n
+
+endmenu
+
+source "init/Kconfig"
+source "drivers/Kconfig"
+source "fs/Kconfig"
+
+menu "Executable File Formats"
+source "fs/Kconfig.binfmt"
+endmenu
+
+source "net/Kconfig"
+source "security/Kconfig"
+source "crypto/Kconfig"
+source "lib/Kconfig"
+
+menu "Kernel hacking"
+source "lib/Kconfig.debug"
+endmenu
diff --git a/arch/hexagon/Makefile b/arch/hexagon/Makefile
new file mode 100644 (file)
index 0000000..0c4de87
--- /dev/null
@@ -0,0 +1,58 @@
+#  Makefile for the Hexagon arch
+
+KBUILD_DEFCONFIG = comet_defconfig
+
+# Do not use GP-relative jumps
+KBUILD_CFLAGS += -G0
+LDFLAGS_vmlinux += -G0
+
+# Do not use single-byte enums; these will overflow.
+KBUILD_CFLAGS += -fno-short-enums
+
+# Modules must use either long-calls, or use pic/plt.
+# Use long-calls for now, it's easier.  And faster.
+# CFLAGS_MODULE += -fPIC
+# LDFLAGS_MODULE += -shared
+CFLAGS_MODULE += -mlong-calls
+
+cflags-$(CONFIG_HEXAGON_ARCH_V1) += $(call cc-option,-mv1)
+cflags-$(CONFIG_HEXAGON_ARCH_V2) += $(call cc-option,-mv2)
+cflags-$(CONFIG_HEXAGON_ARCH_V3) += $(call cc-option,-mv3)
+cflags-$(CONFIG_HEXAGON_ARCH_V4) += $(call cc-option,-mv4)
+
+aflags-$(CONFIG_HEXAGON_ARCH_V1) += $(call cc-option,-mv1)
+aflags-$(CONFIG_HEXAGON_ARCH_V2) += $(call cc-option,-mv2)
+aflags-$(CONFIG_HEXAGON_ARCH_V3) += $(call cc-option,-mv3)
+aflags-$(CONFIG_HEXAGON_ARCH_V4) += $(call cc-option,-mv4)
+
+ldflags-$(CONFIG_HEXAGON_ARCH_V1) += $(call cc-option,-mv1)
+ldflags-$(CONFIG_HEXAGON_ARCH_V2) += $(call cc-option,-mv2)
+ldflags-$(CONFIG_HEXAGON_ARCH_V3) += $(call cc-option,-mv3)
+ldflags-$(CONFIG_HEXAGON_ARCH_V4) += $(call cc-option,-mv4)
+
+KBUILD_CFLAGS += $(cflags-y)
+KBUILD_AFLAGS += $(aflags-y)
+
+#  no KBUILD_LDFLAGS?
+LDFLAGS += $(ldflags-y)
+
+# Thread-info register will be r19.  This value is not configureable;
+# it is hard-coded in several files.
+TIR_NAME := r19
+KBUILD_CFLAGS += -ffixed-$(TIR_NAME) -DTHREADINFO_REG=$(TIR_NAME) -D__linux__
+KBUILD_AFLAGS += -DTHREADINFO_REG=$(TIR_NAME)
+
+LIBGCC := $(shell $(CC) $(KBUILD_CFLAGS) -print-libgcc-file-name)
+libs-y += $(LIBGCC)
+
+head-y := arch/hexagon/kernel/head.o \
+       arch/hexagon/kernel/init_task.o
+
+core-y += arch/hexagon/kernel/ \
+       arch/hexagon/mm/ \
+       arch/hexagon/lib/
+
+#      arch/hexagon/platform/common/
+#
+#core-$(CONFIG_HEXAGON_COMET)          += arch/hexagon/platform/comet/
+#machine-$(CONFIG_HEXAGON_COMET)               := comet
diff --git a/arch/hexagon/configs/comet_defconfig b/arch/hexagon/configs/comet_defconfig
new file mode 100644 (file)
index 0000000..e324f65
--- /dev/null
@@ -0,0 +1,85 @@
+CONFIG_SMP=y
+CONFIG_DEFAULT_MMAP_MIN_ADDR=0
+CONFIG_HZ_100=y
+CONFIG_EXPERIMENTAL=y
+CONFIG_CROSS_COMPILE="hexagon-"
+CONFIG_LOCALVERSION="-smp"
+# CONFIG_LOCALVERSION_AUTO is not set
+CONFIG_SYSVIPC=y
+CONFIG_POSIX_MQUEUE=y
+CONFIG_BSD_PROCESS_ACCT=y
+CONFIG_BSD_PROCESS_ACCT_V3=y
+CONFIG_TASKSTATS=y
+CONFIG_TASK_DELAY_ACCT=y
+CONFIG_IKCONFIG=y
+CONFIG_IKCONFIG_PROC=y
+CONFIG_LOG_BUF_SHIFT=18
+CONFIG_BLK_DEV_INITRD=y
+CONFIG_EMBEDDED=y
+# CONFIG_VM_EVENT_COUNTERS is not set
+# CONFIG_BLK_DEV_BSG is not set
+CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
+# CONFIG_STANDALONE is not set
+CONFIG_CONNECTOR=y
+CONFIG_BLK_DEV_LOOP=y
+CONFIG_BLK_DEV_NBD=y
+CONFIG_NETDEVICES=y
+CONFIG_MII=y
+CONFIG_PHYLIB=y
+CONFIG_NET_ETHERNET=y
+# CONFIG_NETDEV_1000 is not set
+# CONFIG_NETDEV_10000 is not set
+# CONFIG_INPUT_MOUSEDEV is not set
+# CONFIG_INPUT_KEYBOARD is not set
+# CONFIG_INPUT_MOUSE is not set
+# CONFIG_SERIO is not set
+# CONFIG_CONSOLE_TRANSLATIONS is not set
+CONFIG_LEGACY_PTY_COUNT=64
+# CONFIG_DEVKMEM is not set
+# CONFIG_HW_RANDOM is not set
+CONFIG_SPI=y
+CONFIG_SPI_DEBUG=y
+CONFIG_SPI_BITBANG=y
+# CONFIG_HWMON is not set
+# CONFIG_VGA_CONSOLE is not set
+# CONFIG_HID_SUPPORT is not set
+# CONFIG_USB_SUPPORT is not set
+CONFIG_EXT2_FS=y
+CONFIG_EXT2_FS_XATTR=y
+CONFIG_EXT2_FS_POSIX_ACL=y
+CONFIG_EXT2_FS_SECURITY=y
+CONFIG_EXT3_FS=y
+# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
+CONFIG_EXT3_FS_POSIX_ACL=y
+CONFIG_EXT3_FS_SECURITY=y
+CONFIG_QUOTA=y
+CONFIG_PROC_KCORE=y
+CONFIG_TMPFS=y
+CONFIG_TMPFS_POSIX_ACL=y
+# CONFIG_MISC_FILESYSTEMS is not set
+CONFIG_NFS_FS=y
+CONFIG_NFS_V3=y
+CONFIG_NFS_V3_ACL=y
+# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
+CONFIG_NET=y
+CONFIG_PACKET=y
+CONFIG_UNIX=y
+CONFIG_INET=y
+# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
+# CONFIG_INET_XFRM_MODE_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_BEET is not set
+# CONFIG_INET_LRO is not set
+# CONFIG_INET_DIAG is not set
+# CONFIG_IPV6 is not set
+CONFIG_CRYPTO_MD5=y
+# CONFIG_CRYPTO_ANSI_CPRNG is not set
+# CONFIG_CRYPTO_HW is not set
+CONFIG_CRC_CCITT=y
+CONFIG_CRC16=y
+CONFIG_CRC_T10DIF=y
+CONFIG_LIBCRC32C=y
+CONFIG_FRAME_WARN=0
+CONFIG_MAGIC_SYSRQ=y
+CONFIG_DEBUG_FS=y
+# CONFIG_SCHED_DEBUG is not set
+CONFIG_DEBUG_INFO=y
diff --git a/arch/hexagon/include/asm/Kbuild b/arch/hexagon/include/asm/Kbuild
new file mode 100644 (file)
index 0000000..9aa17f1
--- /dev/null
@@ -0,0 +1,58 @@
+include include/asm-generic/Kbuild.asm
+
+header-y += registers.h
+header-y += ucontext.h
+header-y += user.h
+
+generic-y += auxvec.h
+generic-y += bug.h
+generic-y += bugs.h
+generic-y += cpumask.h
+generic-y += cputime.h
+generic-y += current.h
+generic-y += device.h
+generic-y += div64.h
+generic-y += emergency-restart.h
+generic-y += errno.h
+generic-y += fb.h
+generic-y += fcntl.h
+generic-y += ftrace.h
+generic-y += hardirq.h
+generic-y += hw_irq.h
+generic-y += ioctl.h
+generic-y += ioctls.h
+generic-y += iomap.h
+generic-y += ipcbuf.h
+generic-y += ipc.h
+generic-y += irq_regs.h
+generic-y += kdebug.h
+generic-y += kmap_types.h
+generic-y += local64.h
+generic-y += local.h
+generic-y += local.h
+generic-y += mman.h
+generic-y += msgbuf.h
+generic-y += pci.h
+generic-y += percpu.h
+generic-y += poll.h
+generic-y += posix_types.h
+generic-y += resource.h
+generic-y += rwsem.h
+generic-y += scatterlist.h
+generic-y += sections.h
+generic-y += segment.h
+generic-y += sembuf.h
+generic-y += shmbuf.h
+generic-y += shmparam.h
+generic-y += siginfo.h
+generic-y += socket.h
+generic-y += sockios.h
+generic-y += statfs.h
+generic-y += stat.h
+generic-y += termbits.h
+generic-y += termios.h
+generic-y += topology.h
+generic-y += types.h
+generic-y += ucontext.h
+generic-y += unaligned.h
+generic-y += xor.h
diff --git a/arch/hexagon/include/asm/asm-offsets.h b/arch/hexagon/include/asm/asm-offsets.h
new file mode 100644 (file)
index 0000000..d370ee3
--- /dev/null
@@ -0,0 +1 @@
+#include <generated/asm-offsets.h>
diff --git a/arch/hexagon/include/asm/atomic.h b/arch/hexagon/include/asm/atomic.h
new file mode 100644 (file)
index 0000000..e220f90
--- /dev/null
@@ -0,0 +1,164 @@
+/*
+ * Atomic operations for the Hexagon architecture
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_ATOMIC_H
+#define _ASM_ATOMIC_H
+
+#include <linux/types.h>
+
+#define ATOMIC_INIT(i)         { (i) }
+#define atomic_set(v, i)       ((v)->counter = (i))
+
+/**
+ * atomic_read - reads a word, atomically
+ * @v: pointer to atomic value
+ *
+ * Assumes all word reads on our architecture are atomic.
+ */
+#define atomic_read(v)         ((v)->counter)
+
+/**
+ * atomic_xchg - atomic
+ * @v: pointer to memory to change
+ * @new: new value (technically passed in a register -- see xchg)
+ */
+#define atomic_xchg(v, new)    (xchg(&((v)->counter), (new)))
+
+
+/**
+ * atomic_cmpxchg - atomic compare-and-exchange values
+ * @v: pointer to value to change
+ * @old:  desired old value to match
+ * @new:  new value to put in
+ *
+ * Parameters are then pointer, value-in-register, value-in-register,
+ * and the output is the old value.
+ *
+ * Apparently this is complicated for archs that don't support
+ * the memw_locked like we do (or it's broken or whatever).
+ *
+ * Kind of the lynchpin of the rest of the generically defined routines.
+ * Remember V2 had that bug with dotnew predicate set by memw_locked.
+ *
+ * "old" is "expected" old val, __oldval is actual old value
+ */
+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
+{
+       int __oldval;
+
+       asm volatile(
+               "1:     %0 = memw_locked(%1);\n"
+               "       { P0 = cmp.eq(%0,%2);\n"
+               "         if (!P0.new) jump:nt 2f; }\n"
+               "       memw_locked(%1,P0) = %3;\n"
+               "       if (!P0) jump 1b;\n"
+               "2:\n"
+               : "=&r" (__oldval)
+               : "r" (&v->counter), "r" (old), "r" (new)
+               : "memory", "p0"
+       );
+
+       return __oldval;
+}
+
+static inline int atomic_add_return(int i, atomic_t *v)
+{
+       int output;
+
+       __asm__ __volatile__ (
+               "1:     %0 = memw_locked(%1);\n"
+               "       %0 = add(%0,%2);\n"
+               "       memw_locked(%1,P3)=%0;\n"
+               "       if !P3 jump 1b;\n"
+               : "=&r" (output)
+               : "r" (&v->counter), "r" (i)
+               : "memory", "p3"
+       );
+       return output;
+
+}
+
+#define atomic_add(i, v) atomic_add_return(i, (v))
+
+static inline int atomic_sub_return(int i, atomic_t *v)
+{
+       int output;
+       __asm__ __volatile__ (
+               "1:     %0 = memw_locked(%1);\n"
+               "       %0 = sub(%0,%2);\n"
+               "       memw_locked(%1,P3)=%0\n"
+               "       if !P3 jump 1b;\n"
+               : "=&r" (output)
+               : "r" (&v->counter), "r" (i)
+               : "memory", "p3"
+       );
+       return output;
+}
+
+#define atomic_sub(i, v) atomic_sub_return(i, (v))
+
+/**
+ * atomic_add_unless - add unless the number is a given value
+ * @v: pointer to value
+ * @a: amount to add
+ * @u: unless value is equal to u
+ *
+ * Returns 1 if the add happened, 0 if it didn't.
+ */
+static inline int __atomic_add_unless(atomic_t *v, int a, int u)
+{
+       int output, __oldval;
+       asm volatile(
+               "1:     %0 = memw_locked(%2);"
+               "       {"
+               "               p3 = cmp.eq(%0, %4);"
+               "               if (p3.new) jump:nt 2f;"
+               "               %0 = add(%0, %3);"
+               "               %1 = #0;"
+               "       }"
+               "       memw_locked(%2, p3) = %0;"
+               "       {"
+               "               if !p3 jump 1b;"
+               "               %1 = #1;"
+               "       }"
+               "2:"
+               : "=&r" (__oldval), "=&r" (output)
+               : "r" (v), "r" (a), "r" (u)
+               : "memory", "p3"
+       );
+       return output;
+}
+
+#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
+
+#define atomic_inc(v) atomic_add(1, (v))
+#define atomic_dec(v) atomic_sub(1, (v))
+
+#define atomic_inc_and_test(v) (atomic_add_return(1, (v)) == 0)
+#define atomic_dec_and_test(v) (atomic_sub_return(1, (v)) == 0)
+#define atomic_sub_and_test(i, v) (atomic_sub_return(i, (v)) == 0)
+#define atomic_add_negative(i, v) (atomic_add_return(i, (v)) < 0)
+
+
+#define atomic_inc_return(v) (atomic_add_return(1, v))
+#define atomic_dec_return(v) (atomic_sub_return(1, v))
+
+#endif
diff --git a/arch/hexagon/include/asm/bitops.h b/arch/hexagon/include/asm/bitops.h
new file mode 100644 (file)
index 0000000..d23461e
--- /dev/null
@@ -0,0 +1,301 @@
+/*
+ * Bit operations for the Hexagon architecture
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_BITOPS_H
+#define _ASM_BITOPS_H
+
+#include <linux/compiler.h>
+#include <asm/byteorder.h>
+#include <asm/system.h>
+#include <asm/atomic.h>
+
+#ifdef __KERNEL__
+
+#define smp_mb__before_clear_bit()     barrier()
+#define smp_mb__after_clear_bit()      barrier()
+
+/*
+ * The offset calculations for these are based on BITS_PER_LONG == 32
+ * (i.e. I get to shift by #5-2 (32 bits per long, 4 bytes per access),
+ * mask by 0x0000001F)
+ *
+ * Typically, R10 is clobbered for address, R11 bit nr, and R12 is temp
+ */
+
+/**
+ * test_and_clear_bit - clear a bit and return its old value
+ * @nr:  bit number to clear
+ * @addr:  pointer to memory
+ */
+static inline int test_and_clear_bit(int nr, volatile void *addr)
+{
+       int oldval;
+
+       __asm__ __volatile__ (
+       "       {R10 = %1; R11 = asr(%2,#5); }\n"
+       "       {R10 += asl(R11,#2); R11 = and(%2,#0x1f)}\n"
+       "1:     R12 = memw_locked(R10);\n"
+       "       { P0 = tstbit(R12,R11); R12 = clrbit(R12,R11); }\n"
+       "       memw_locked(R10,P1) = R12;\n"
+       "       {if !P1 jump 1b; %0 = mux(P0,#1,#0);}\n"
+       : "=&r" (oldval)
+       : "r" (addr), "r" (nr)
+       : "r10", "r11", "r12", "p0", "p1", "memory"
+       );
+
+       return oldval;
+}
+
+/**
+ * test_and_set_bit - set a bit and return its old value
+ * @nr:  bit number to set
+ * @addr:  pointer to memory
+ */
+static inline int test_and_set_bit(int nr, volatile void *addr)
+{
+       int oldval;
+
+       __asm__ __volatile__ (
+       "       {R10 = %1; R11 = asr(%2,#5); }\n"
+       "       {R10 += asl(R11,#2); R11 = and(%2,#0x1f)}\n"
+       "1:     R12 = memw_locked(R10);\n"
+       "       { P0 = tstbit(R12,R11); R12 = setbit(R12,R11); }\n"
+       "       memw_locked(R10,P1) = R12;\n"
+       "       {if !P1 jump 1b; %0 = mux(P0,#1,#0);}\n"
+       : "=&r" (oldval)
+       : "r" (addr), "r" (nr)
+       : "r10", "r11", "r12", "p0", "p1", "memory"
+       );
+
+
+       return oldval;
+
+}
+
+/**
+ * test_and_change_bit - toggle a bit and return its old value
+ * @nr:  bit number to set
+ * @addr:  pointer to memory
+ */
+static inline int test_and_change_bit(int nr, volatile void *addr)
+{
+       int oldval;
+
+       __asm__ __volatile__ (
+       "       {R10 = %1; R11 = asr(%2,#5); }\n"
+       "       {R10 += asl(R11,#2); R11 = and(%2,#0x1f)}\n"
+       "1:     R12 = memw_locked(R10);\n"
+       "       { P0 = tstbit(R12,R11); R12 = togglebit(R12,R11); }\n"
+       "       memw_locked(R10,P1) = R12;\n"
+       "       {if !P1 jump 1b; %0 = mux(P0,#1,#0);}\n"
+       : "=&r" (oldval)
+       : "r" (addr), "r" (nr)
+       : "r10", "r11", "r12", "p0", "p1", "memory"
+       );
+
+       return oldval;
+
+}
+
+/*
+ * Atomic, but doesn't care about the return value.
+ * Rewrite later to save a cycle or two.
+ */
+
+static inline void clear_bit(int nr, volatile void *addr)
+{
+       test_and_clear_bit(nr, addr);
+}
+
+static inline void set_bit(int nr, volatile void *addr)
+{
+       test_and_set_bit(nr, addr);
+}
+
+static inline void change_bit(int nr, volatile void *addr)
+{
+       test_and_change_bit(nr, addr);
+}
+
+
+/*
+ * These are allowed to be non-atomic.  In fact the generic flavors are
+ * in non-atomic.h.  Would it be better to use intrinsics for this?
+ *
+ * OK, writes in our architecture do not invalidate LL/SC, so this has to
+ * be atomic, particularly for things like slab_lock and slab_unlock.
+ *
+ */
+static inline void __clear_bit(int nr, volatile unsigned long *addr)
+{
+       test_and_clear_bit(nr, addr);
+}
+
+static inline void __set_bit(int nr, volatile unsigned long *addr)
+{
+       test_and_set_bit(nr, addr);
+}
+
+static inline void __change_bit(int nr, volatile unsigned long *addr)
+{
+       test_and_change_bit(nr, addr);
+}
+
+/*  Apparently, at least some of these are allowed to be non-atomic  */
+static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)
+{
+       return test_and_clear_bit(nr, addr);
+}
+
+static inline int __test_and_set_bit(int nr, volatile unsigned long *addr)
+{
+       return test_and_set_bit(nr, addr);
+}
+
+static inline int __test_and_change_bit(int nr, volatile unsigned long *addr)
+{
+       return test_and_change_bit(nr, addr);
+}
+
+static inline int __test_bit(int nr, const volatile unsigned long *addr)
+{
+       int retval;
+
+       asm volatile(
+       "{P0 = tstbit(%1,%2); if (P0.new) %0 = #1; if (!P0.new) %0 = #0;}\n"
+       : "=&r" (retval)
+       : "r" (addr[BIT_WORD(nr)]), "r" (nr % BITS_PER_LONG)
+       : "p0"
+       );
+
+       return retval;
+}
+
+#define test_bit(nr, addr) __test_bit(nr, addr)
+
+/*
+ * ffz - find first zero in word.
+ * @word: The word to search
+ *
+ * Undefined if no zero exists, so code should check against ~0UL first.
+ */
+static inline long ffz(int x)
+{
+       int r;
+
+       asm("%0 = ct1(%1);\n"
+               : "=&r" (r)
+               : "r" (x));
+       return r;
+}
+
+/*
+ * fls - find last (most-significant) bit set
+ * @x: the word to search
+ *
+ * This is defined the same way as ffs.
+ * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
+ */
+static inline long fls(int x)
+{
+       int r;
+
+       asm("{ %0 = cl0(%1);}\n"
+               "%0 = sub(#32,%0);\n"
+               : "=&r" (r)
+               : "r" (x)
+               : "p0");
+
+       return r;
+}
+
+/*
+ * ffs - find first bit set
+ * @x: the word to search
+ *
+ * This is defined the same way as
+ * the libc and compiler builtin ffs routines, therefore
+ * differs in spirit from the above ffz (man ffs).
+ */
+static inline long ffs(int x)
+{
+       int r;
+
+       asm("{ P0 = cmp.eq(%1,#0); %0 = ct0(%1);}\n"
+               "{ if P0 %0 = #0; if !P0 %0 = add(%0,#1);}\n"
+               : "=&r" (r)
+               : "r" (x)
+               : "p0");
+
+       return r;
+}
+
+/*
+ * __ffs - find first bit in word.
+ * @word: The word to search
+ *
+ * Undefined if no bit exists, so code should check against 0 first.
+ *
+ * bits_per_long assumed to be 32
+ * numbering starts at 0 I think (instead of 1 like ffs)
+ */
+static inline unsigned long __ffs(unsigned long word)
+{
+       int num;
+
+       asm("%0 = ct0(%1);\n"
+               : "=&r" (num)
+               : "r" (word));
+
+       return num;
+}
+
+/*
+ * __fls - find last (most-significant) set bit in a long word
+ * @word: the word to search
+ *
+ * Undefined if no set bit exists, so code should check against 0 first.
+ * bits_per_long assumed to be 32
+ */
+static inline unsigned long __fls(unsigned long word)
+{
+       int num;
+
+       asm("%0 = cl0(%1);\n"
+               "%0 = sub(#31,%0);\n"
+               : "=&r" (num)
+               : "r" (word));
+
+       return num;
+}
+
+#include <asm-generic/bitops/lock.h>
+#include <asm-generic/bitops/find.h>
+
+#include <asm-generic/bitops/fls64.h>
+#include <asm-generic/bitops/sched.h>
+#include <asm-generic/bitops/hweight.h>
+
+#include <asm-generic/bitops/le.h>
+#include <asm-generic/bitops/ext2-atomic.h>
+
+#endif /* __KERNEL__ */
+#endif
diff --git a/arch/hexagon/include/asm/bitsperlong.h b/arch/hexagon/include/asm/bitsperlong.h
new file mode 100644 (file)
index 0000000..2701cae
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef __ASM_HEXAGON_BITSPERLONG_H
+#define __ASM_HEXAGON_BITSPERLONG_H
+
+#define __BITS_PER_LONG 32
+
+#include <asm-generic/bitsperlong.h>
+
+#endif
diff --git a/arch/hexagon/include/asm/byteorder.h b/arch/hexagon/include/asm/byteorder.h
new file mode 100644 (file)
index 0000000..0e19b9f
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_BYTEORDER_H
+#define _ASM_BYTEORDER_H
+
+#if defined(__GNUC__) && !defined(__STRICT_ANSI__) || defined(__KERNEL__)
+#  define __BYTEORDER_HAS_U64__
+#endif
+
+#include <linux/byteorder/little_endian.h>
+
+#endif /* _ASM_BYTEORDER_H */
diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
new file mode 100644 (file)
index 0000000..0f01de2
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Cache definitions for the Hexagon architecture
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef __ASM_CACHE_H
+#define __ASM_CACHE_H
+
+/* Bytes per L1 cache line */
+#define L1_CACHE_SHIFT         (5)
+#define L1_CACHE_BYTES         (1 << L1_CACHE_SHIFT)
+
+#define __cacheline_aligned    __aligned(L1_CACHE_BYTES)
+#define ____cacheline_aligned  __aligned(L1_CACHE_BYTES)
+
+/* See http://kerneltrap.org/node/15100  */
+#define __read_mostly
+
+#endif
diff --git a/arch/hexagon/include/asm/cacheflush.h b/arch/hexagon/include/asm/cacheflush.h
new file mode 100644 (file)
index 0000000..6865c1b
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Cache flush operations for the Hexagon architecture
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_CACHEFLUSH_H
+#define _ASM_CACHEFLUSH_H
+
+#include <linux/cache.h>
+#include <linux/mm.h>
+#include <asm/string.h>
+#include <asm-generic/cacheflush.h>
+
+/* Cache flushing:
+ *
+ *  - flush_cache_all() flushes entire cache
+ *  - flush_cache_mm(mm) flushes the specified mm context's cache lines
+ *  - flush_cache_page(mm, vmaddr, pfn) flushes a single page
+ *  - flush_cache_range(vma, start, end) flushes a range of pages
+ *  - flush_icache_range(start, end) flush a range of instructions
+ *  - flush_dcache_page(pg) flushes(wback&invalidates) a page for dcache
+ *  - flush_icache_page(vma, pg) flushes(invalidates) a page for icache
+ *
+ *  Need to doublecheck which one is really needed for ptrace stuff to work.
+ */
+#define LINESIZE       32
+#define LINEBITS       5
+
+/*
+ * Flush Dcache range through current map.
+ */
+extern void flush_dcache_range(unsigned long start, unsigned long end);
+
+/*
+ * Flush Icache range through current map.
+ */
+#undef flush_icache_range
+extern void flush_icache_range(unsigned long start, unsigned long end);
+
+/*
+ * Memory-management related flushes are there to ensure in non-physically
+ * indexed cache schemes that stale lines belonging to a given ASID aren't
+ * in the cache to confuse things.  The prototype Hexagon Virtual Machine
+ * only uses a single ASID for all user-mode maps, which should
+ * mean that they aren't necessary.  A brute-force, flush-everything
+ * implementation, with the name xxxxx_hexagon() is present in
+ * arch/hexagon/mm/cache.c, but let's not wire it up until we know
+ * it is needed.
+ */
+extern void flush_cache_all_hexagon(void);
+
+/*
+ * This may or may not ever have to be non-null, depending on the
+ * virtual machine MMU.  For a native kernel, it's definitiely  a no-op
+ *
+ * This is also the place where deferred cache coherency stuff seems
+ * to happen, classically...  but instead we do it like ia64 and
+ * clean the cache when the PTE is set.
+ *
+ */
+static inline void update_mmu_cache(struct vm_area_struct *vma,
+                                       unsigned long address, pte_t *ptep)
+{
+       /*  generic_ptrace_pokedata doesn't wind up here, does it?  */
+}
+
+#undef copy_to_user_page
+static inline void copy_to_user_page(struct vm_area_struct *vma,
+                                            struct page *page,
+                                            unsigned long vaddr,
+                                            void *dst, void *src, int len)
+{
+       memcpy(dst, src, len);
+       if (vma->vm_flags & VM_EXEC) {
+               flush_icache_range((unsigned long) dst,
+               (unsigned long) dst + len);
+       }
+}
+
+
+extern void hexagon_inv_dcache_range(unsigned long start, unsigned long end);
+extern void hexagon_clean_dcache_range(unsigned long start, unsigned long end);
+
+#endif
diff --git a/arch/hexagon/include/asm/checksum.h b/arch/hexagon/include/asm/checksum.h
new file mode 100644 (file)
index 0000000..3ce4ecd
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_CHECKSUM_H
+#define _ASM_CHECKSUM_H
+
+#define do_csum        do_csum
+unsigned int do_csum(const void *voidptr, int len);
+
+/*
+ * the same as csum_partial, but copies from src while it
+ * checksums
+ *
+ * here even more important to align src and dst on a 32-bit (or even
+ * better 64-bit) boundary
+ */
+#define csum_partial_copy_nocheck csum_partial_copy_nocheck
+__wsum csum_partial_copy_nocheck(const void *src, void *dst,
+                                       int len, __wsum sum);
+
+/*
+ * computes the checksum of the TCP/UDP pseudo-header
+ * returns a 16-bit checksum, already complemented
+ */
+#define csum_tcpudp_nofold csum_tcpudp_nofold
+__wsum csum_tcpudp_nofold(unsigned long saddr, unsigned long daddr,
+       unsigned short len, unsigned short proto, __wsum sum);
+
+#define csum_tcpudp_magic csum_tcpudp_magic
+__sum16 csum_tcpudp_magic(unsigned long saddr, unsigned long daddr,
+       unsigned short len, unsigned short proto, __wsum sum);
+
+#include <asm-generic/checksum.h>
+
+#endif
diff --git a/arch/hexagon/include/asm/delay.h b/arch/hexagon/include/asm/delay.h
new file mode 100644 (file)
index 0000000..9ab12e9
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_DELAY_H
+#define _ASM_DELAY_H
+
+#include <asm/param.h>
+
+extern void __udelay(unsigned long usecs);
+
+#define udelay(usecs) __udelay((usecs))
+
+#endif /* _ASM_DELAY_H */
diff --git a/arch/hexagon/include/asm/dma-mapping.h b/arch/hexagon/include/asm/dma-mapping.h
new file mode 100644 (file)
index 0000000..448b224
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * DMA operations for the Hexagon architecture
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_DMA_MAPPING_H
+#define _ASM_DMA_MAPPING_H
+
+#include <linux/types.h>
+#include <linux/cache.h>
+#include <linux/mm.h>
+#include <linux/scatterlist.h>
+#include <linux/dma-mapping.h>
+#include <linux/dma-debug.h>
+#include <linux/dma-attrs.h>
+#include <asm/io.h>
+
+struct device;
+extern int bad_dma_address;
+
+extern struct dma_map_ops *dma_ops;
+
+#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
+#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
+
+static inline struct dma_map_ops *get_dma_ops(struct device *dev)
+{
+       if (unlikely(dev == NULL))
+               return NULL;
+
+       return dma_ops;
+}
+
+extern int dma_supported(struct device *dev, u64 mask);
+extern int dma_set_mask(struct device *dev, u64 mask);
+extern int dma_is_consistent(struct device *dev, dma_addr_t dma_handle);
+extern void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
+                          enum dma_data_direction direction);
+
+#include <asm-generic/dma-mapping-common.h>
+
+static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
+{
+       if (!dev->dma_mask)
+               return 0;
+       return addr + size - 1 <= *dev->dma_mask;
+}
+
+static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
+{
+       struct dma_map_ops *dma_ops = get_dma_ops(dev);
+
+       if (dma_ops->mapping_error)
+               return dma_ops->mapping_error(dev, dma_addr);
+
+       return (dma_addr == bad_dma_address);
+}
+
+static inline void *dma_alloc_coherent(struct device *dev, size_t size,
+                                      dma_addr_t *dma_handle, gfp_t flag)
+{
+       void *ret;
+       struct dma_map_ops *ops = get_dma_ops(dev);
+
+       BUG_ON(!dma_ops);
+
+       ret = ops->alloc_coherent(dev, size, dma_handle, flag);
+
+       debug_dma_alloc_coherent(dev, size, *dma_handle, ret);
+
+       return ret;
+}
+
+static inline void dma_free_coherent(struct device *dev, size_t size,
+                                    void *cpu_addr, dma_addr_t dma_handle)
+{
+       struct dma_map_ops *dma_ops = get_dma_ops(dev);
+
+       BUG_ON(!dma_ops);
+
+       dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
+
+       debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
+}
+
+#endif
diff --git a/arch/hexagon/include/asm/dma.h b/arch/hexagon/include/asm/dma.h
new file mode 100644 (file)
index 0000000..da6d2f6
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_DMA_H
+#define _ASM_DMA_H
+
+#include <asm/io.h>
+
+#define MAX_DMA_CHANNELS 1
+#define MAX_DMA_ADDRESS  (PAGE_OFFSET)
+
+extern size_t hexagon_coherent_pool_size;
+
+#endif
diff --git a/arch/hexagon/include/asm/elf.h b/arch/hexagon/include/asm/elf.h
new file mode 100644 (file)
index 0000000..37976a0
--- /dev/null
@@ -0,0 +1,229 @@
+/*
+ * ELF definitions for the Hexagon architecture
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef __ASM_ELF_H
+#define __ASM_ELF_H
+
+#include <asm/ptrace.h>
+#include <asm/user.h>
+
+/*
+ * This should really be in linux/elf-em.h.
+ */
+#define EM_HEXAGON     164   /* QUALCOMM Hexagon */
+
+struct elf32_hdr;
+
+/*
+ * ELF header e_flags defines.
+ */
+
+/*  should have stuff like "CPU type" and maybe "ABI version", etc  */
+
+/* Hexagon relocations */
+  /* V2 */
+#define R_HEXAGON_NONE           0
+#define R_HEXAGON_B22_PCREL      1
+#define R_HEXAGON_B15_PCREL      2
+#define R_HEXAGON_B7_PCREL       3
+#define R_HEXAGON_LO16           4
+#define R_HEXAGON_HI16           5
+#define R_HEXAGON_32             6
+#define R_HEXAGON_16             7
+#define R_HEXAGON_8              8
+#define R_HEXAGON_GPREL16_0      9
+#define R_HEXAGON_GPREL16_1     10
+#define R_HEXAGON_GPREL16_2     11
+#define R_HEXAGON_GPREL16_3     12
+#define R_HEXAGON_HL16          13
+  /* V3 */
+#define R_HEXAGON_B13_PCREL     14
+  /* V4 */
+#define R_HEXAGON_B9_PCREL      15
+  /* V4 (extenders) */
+#define R_HEXAGON_B32_PCREL_X   16
+#define R_HEXAGON_32_6_X        17
+  /* V4 (extended) */
+#define R_HEXAGON_B22_PCREL_X   18
+#define R_HEXAGON_B15_PCREL_X   19
+#define R_HEXAGON_B13_PCREL_X   20
+#define R_HEXAGON_B9_PCREL_X    21
+#define R_HEXAGON_B7_PCREL_X    22
+#define R_HEXAGON_16_X          23
+#define R_HEXAGON_12_X          24
+#define R_HEXAGON_11_X          25
+#define R_HEXAGON_10_X          26
+#define R_HEXAGON_9_X           27
+#define R_HEXAGON_8_X           28
+#define R_HEXAGON_7_X           29
+#define R_HEXAGON_6_X           30
+  /* V2 PIC */
+#define R_HEXAGON_32_PCREL      31
+#define R_HEXAGON_COPY          32
+#define R_HEXAGON_GLOB_DAT      33
+#define R_HEXAGON_JMP_SLOT      34
+#define R_HEXAGON_RELATIVE      35
+#define R_HEXAGON_PLT_B22_PCREL 36
+#define R_HEXAGON_GOTOFF_LO16   37
+#define R_HEXAGON_GOTOFF_HI16   38
+#define R_HEXAGON_GOTOFF_32     39
+#define R_HEXAGON_GOT_LO16      40
+#define R_HEXAGON_GOT_HI16      41
+#define R_HEXAGON_GOT_32        42
+#define R_HEXAGON_GOT_16        43
+
+/*
+ * ELF register definitions..
+ */
+typedef unsigned long elf_greg_t;
+
+typedef struct user_regs_struct elf_gregset_t;
+#define ELF_NGREG (sizeof(elf_gregset_t)/sizeof(unsigned long))
+
+/*  Placeholder  */
+typedef unsigned long elf_fpregset_t;
+
+/*
+ * Bypass the whole "regsets" thing for now and use the define.
+ */
+
+#define ELF_CORE_COPY_REGS(DEST, REGS) \
+do {                                   \
+       DEST.r0 = REGS->r00;            \
+       DEST.r1 = REGS->r01;            \
+       DEST.r2 = REGS->r02;            \
+       DEST.r3 = REGS->r03;            \
+       DEST.r4 = REGS->r04;            \
+       DEST.r5 = REGS->r05;            \
+       DEST.r6 = REGS->r06;            \
+       DEST.r7 = REGS->r07;            \
+       DEST.r8 = REGS->r08;            \
+       DEST.r9 = REGS->r09;            \
+       DEST.r10 = REGS->r10;           \
+       DEST.r11 = REGS->r11;           \
+       DEST.r12 = REGS->r12;           \
+       DEST.r13 = REGS->r13;           \
+       DEST.r14 = REGS->r14;           \
+       DEST.r15 = REGS->r15;           \
+       DEST.r16 = REGS->r16;           \
+       DEST.r17 = REGS->r17;           \
+       DEST.r18 = REGS->r18;           \
+       DEST.r19 = REGS->r19;           \
+       DEST.r20 = REGS->r20;           \
+       DEST.r21 = REGS->r21;           \
+       DEST.r22 = REGS->r22;           \
+       DEST.r23 = REGS->r23;           \
+       DEST.r24 = REGS->r24;           \
+       DEST.r25 = REGS->r25;           \
+       DEST.r26 = REGS->r26;           \
+       DEST.r27 = REGS->r27;           \
+       DEST.r28 = REGS->r28;           \
+       DEST.r29 = pt_psp(REGS);        \
+       DEST.r30 = REGS->r30;           \
+       DEST.r31 = REGS->r31;           \
+       DEST.sa0 = REGS->sa0;           \
+       DEST.lc0 = REGS->lc0;           \
+       DEST.sa1 = REGS->sa1;           \
+       DEST.lc1 = REGS->lc1;           \
+       DEST.m0 = REGS->m0;             \
+       DEST.m1 = REGS->m1;             \
+       DEST.usr = REGS->usr;           \
+       DEST.p3_0 = REGS->preds;        \
+       DEST.gp = REGS->gp;             \
+       DEST.ugp = REGS->ugp;           \
+       DEST.pc = pt_elr(REGS); \
+       DEST.cause = pt_cause(REGS);    \
+       DEST.badva = pt_badva(REGS);    \
+} while (0);
+
+
+
+/*
+ * This is used to ensure we don't load something for the wrong architecture.
+ * Checks the machine and ABI type.
+ */
+#define elf_check_arch(hdr)    ((hdr)->e_machine == EM_HEXAGON)
+
+/*
+ * These are used to set parameters in the core dumps.
+ */
+#define ELF_CLASS      ELFCLASS32
+#define ELF_DATA       ELFDATA2LSB
+#define ELF_ARCH       EM_HEXAGON
+
+#ifdef CONFIG_HEXAGON_ARCH_V2
+#define ELF_CORE_EFLAGS 0x1
+#endif
+
+#ifdef CONFIG_HEXAGON_ARCH_V3
+#define ELF_CORE_EFLAGS 0x2
+#endif
+
+#ifdef CONFIG_HEXAGON_ARCH_V4
+#define ELF_CORE_EFLAGS 0x3
+#endif
+
+/*
+ * Some architectures have ld.so set up a pointer to a function
+ * to be registered using atexit, to facilitate cleanup.  So that
+ * static executables will be well-behaved, we would null the register
+ * in question here, in the pt_regs structure passed.  For now,
+ * leave it a null macro.
+ */
+#define ELF_PLAT_INIT(regs, load_addr) do { } while (0)
+
+#define USE_ELF_CORE_DUMP
+#define CORE_DUMP_USE_REGSET
+
+/* Hrm is this going to cause problems for changing PAGE_SIZE?  */
+#define ELF_EXEC_PAGESIZE      4096
+
+/*
+ * This is the location that an ET_DYN program is loaded if exec'ed.  Typical
+ * use of this is to invoke "./ld.so someprog" to test out a new version of
+ * the loader.  We need to make sure that it is out of the way of the program
+ * that it will "exec", and that there is sufficient room for the brk.
+ */
+#define ELF_ET_DYN_BASE         0x08000000UL
+
+/*
+ * This yields a mask that user programs can use to figure out what
+ * instruction set this cpu supports.
+ */
+#define ELF_HWCAP      (0)
+
+/*
+ * This yields a string that ld.so will use to load implementation
+ * specific libraries for optimization.  This is more specific in
+ * intent than poking at uname or /proc/cpuinfo.
+ */
+#define ELF_PLATFORM  (NULL)
+
+#ifdef __KERNEL__
+#define SET_PERSONALITY(ex) set_personality(PER_LINUX)
+#endif
+
+#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
+struct linux_binprm;
+extern int arch_setup_additional_pages(struct linux_binprm *bprm,
+                                      int uses_interp);
+
+
+#endif
diff --git a/arch/hexagon/include/asm/fixmap.h b/arch/hexagon/include/asm/fixmap.h
new file mode 100644 (file)
index 0000000..b27f494
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Fixmap support for Hexagon - enough to support highmem features
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_FIXMAP_H
+#define _ASM_FIXMAP_H
+
+/*
+ * A lot of the fixmap info is already in mem-layout.h
+ */
+#include <asm/mem-layout.h>
+
+/*
+ * Full fixmap support involves set_fixmap() functions, but
+ * these may not be needed if all we're after is an area for
+ * highmem kernel mappings.
+ */
+#define        __fix_to_virt(x)        (FIXADDR_TOP - ((x) << PAGE_SHIFT))
+#define        __virt_to_fix(x)        ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
+
+extern void __this_fixmap_does_not_exist(void);
+
+/**
+ * fix_to_virt -- "index to address" translation.
+ *
+ * If anyone tries to use the idx directly without translation,
+ * we catch the bug with a NULL-deference kernel oops. Illegal
+ * ranges of incoming indices are caught too.
+ */
+static inline unsigned long fix_to_virt(const unsigned int idx)
+{
+       /*
+        * This branch gets completely eliminated after inlining,
+        * except when someone tries to use fixaddr indices in an
+        * illegal way. (such as mixing up address types or using
+        * out-of-range indices).
+        *
+        * If it doesn't get removed, the linker will complain
+        * loudly with a reasonably clear error message..
+        */
+       if (idx >= __end_of_fixed_addresses)
+               __this_fixmap_does_not_exist();
+
+       return __fix_to_virt(idx);
+}
+
+static inline unsigned long virt_to_fix(const unsigned long vaddr)
+{
+       BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
+       return __virt_to_fix(vaddr);
+}
+
+#define kmap_get_fixmap_pte(vaddr) \
+       pte_offset_kernel(pmd_offset(pud_offset(pgd_offset_k(vaddr), \
+                               (vaddr)), (vaddr)), (vaddr))
+
+#endif
diff --git a/arch/hexagon/include/asm/fpu.h b/arch/hexagon/include/asm/fpu.h
new file mode 100644 (file)
index 0000000..0e135ea
--- /dev/null
@@ -0,0 +1,4 @@
+/*
+ * If the FPU is used inside the kernel,
+ * kernel_fpu_end() will be defined here.
+ */
diff --git a/arch/hexagon/include/asm/futex.h b/arch/hexagon/include/asm/futex.h
new file mode 100644 (file)
index 0000000..7e597f8
--- /dev/null
@@ -0,0 +1,137 @@
+#ifndef _ASM_HEXAGON_FUTEX_H
+#define _ASM_HEXAGON_FUTEX_H
+
+#ifdef __KERNEL__
+
+#include <linux/futex.h>
+#include <linux/uaccess.h>
+#include <asm/errno.h>
+
+/* XXX TODO-- need to add sync barriers! */
+
+#define __futex_atomic_op(insn, ret, oldval, uaddr, oparg) \
+       __asm__ __volatile( \
+       "1: %0 = memw_locked(%3);\n" \
+           /* For example: %1 = %4 */ \
+           insn \
+       "2: memw_locked(%3,p2) = %1;\n" \
+       "   if !p2 jump 1b;\n" \
+       "   %1 = #0;\n" \
+       "3:\n" \
+       ".section .fixup,\"ax\"\n" \
+       "4: %1 = #%5;\n" \
+       "   jump 3b\n" \
+       ".previous\n" \
+       ".section __ex_table,\"a\"\n" \
+       ".long 1b,4b,2b,4b\n" \
+       ".previous\n" \
+       : "=&r" (oldval), "=&r" (ret), "+m" (*uaddr) \
+       : "r" (uaddr), "r" (oparg), "i" (-EFAULT) \
+       : "p2", "memory")
+
+
+static inline int
+futex_atomic_op_inuser(int encoded_op, int __user *uaddr)
+{
+       int op = (encoded_op >> 28) & 7;
+       int cmp = (encoded_op >> 24) & 15;
+       int oparg = (encoded_op << 8) >> 20;
+       int cmparg = (encoded_op << 20) >> 20;
+       int oldval = 0, ret;
+       if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28))
+               oparg = 1 << oparg;
+
+       if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
+               return -EFAULT;
+
+       pagefault_disable();
+
+       switch (op) {
+       case FUTEX_OP_SET:
+               __futex_atomic_op("%1 = %4\n", ret, oldval, uaddr, oparg);
+               break;
+       case FUTEX_OP_ADD:
+               __futex_atomic_op("%1 = add(%0,%4)\n", ret, oldval, uaddr,
+                                 oparg);
+               break;
+       case FUTEX_OP_OR:
+               __futex_atomic_op("%1 = or(%0,%4)\n", ret, oldval, uaddr,
+                                 oparg);
+               break;
+       case FUTEX_OP_ANDN:
+               __futex_atomic_op("%1 = not(%4); %1 = and(%0,%1)\n", ret,
+                                 oldval, uaddr, oparg);
+               break;
+       case FUTEX_OP_XOR:
+               __futex_atomic_op("%1 = xor(%0,%4)\n", ret, oldval, uaddr,
+                                 oparg);
+               break;
+       default:
+               ret = -ENOSYS;
+       }
+
+       pagefault_enable();
+
+       if (!ret) {
+               switch (cmp) {
+               case FUTEX_OP_CMP_EQ:
+                       ret = (oldval == cmparg);
+                       break;
+               case FUTEX_OP_CMP_NE:
+                       ret = (oldval != cmparg);
+                       break;
+               case FUTEX_OP_CMP_LT:
+                       ret = (oldval < cmparg);
+                       break;
+               case FUTEX_OP_CMP_GE:
+                       ret = (oldval >= cmparg);
+                       break;
+               case FUTEX_OP_CMP_LE:
+                       ret = (oldval <= cmparg);
+                       break;
+               case FUTEX_OP_CMP_GT:
+                       ret = (oldval > cmparg);
+                       break;
+               default:
+                       ret = -ENOSYS;
+               }
+       }
+       return ret;
+}
+
+static inline int
+futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, u32 oldval,
+                             u32 newval)
+{
+       int prev;
+       int ret;
+
+       if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
+               return -EFAULT;
+
+       __asm__ __volatile__ (
+       "1: %1 = memw_locked(%3)\n"
+       "   {\n"
+       "      p2 = cmp.eq(%1,%4)\n"
+       "      if !p2.new jump:NT 3f\n"
+       "   }\n"
+       "2: memw_locked(%3,p2) = %5\n"
+       "   if !p2 jump 1b\n"
+       "3:\n"
+       ".section .fixup,\"ax\"\n"
+       "4: %0 = #%6\n"
+       "   jump 3b\n"
+       ".previous\n"
+       ".section __ex_table,\"a\"\n"
+       ".long 1b,4b,2b,4b\n"
+       ".previous\n"
+       : "+r" (ret), "=&r" (prev), "+m" (*uaddr)
+       : "r" (uaddr), "r" (oldval), "r" (newval), "i"(-EFAULT)
+       : "p2", "memory");
+
+       *uval = prev;
+       return ret;
+}
+
+#endif /* __KERNEL__ */
+#endif /* _ASM_HEXAGON_FUTEX_H */
diff --git a/arch/hexagon/include/asm/hexagon_vm.h b/arch/hexagon/include/asm/hexagon_vm.h
new file mode 100644 (file)
index 0000000..182cb9d
--- /dev/null
@@ -0,0 +1,281 @@
+/*
+ * Declarations for to Hexagon Virtal Machine.
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef ASM_HEXAGON_VM_H
+#define ASM_HEXAGON_VM_H
+
+/*
+ * In principle, a Linux kernel for the VM could
+ * selectively define the virtual instructions
+ * as inline assembler macros, but for a first pass,
+ * we'll use subroutines for both the VM and the native
+ * kernels.  It's costing a subroutine call/return,
+ * but it makes for a single set of entry points
+ * for tracing/debugging.
+ */
+
+/*
+ * Lets make this stuff visible only if configured,
+ * so we can unconditionally include the file.
+ */
+
+#ifndef __ASSEMBLY__
+
+enum VM_CACHE_OPS {
+       ickill,
+       dckill,
+       l2kill,
+       dccleaninva,
+       icinva,
+       idsync,
+       fetch_cfg
+};
+
+enum VM_INT_OPS {
+       nop,
+       globen,
+       globdis,
+       locen,
+       locdis,
+       affinity,
+       get,
+       peek,
+       status,
+       post,
+       clear
+};
+
+extern void _K_VM_event_vector(void);
+
+void __vmrte(void);
+long __vmsetvec(void *);
+long __vmsetie(long);
+long __vmgetie(void);
+long __vmintop(enum VM_INT_OPS, long, long, long, long);
+long __vmclrmap(void *, unsigned long);
+long __vmnewmap(void *);
+long __vmcache(enum VM_CACHE_OPS op, unsigned long addr, unsigned long len);
+unsigned long long __vmgettime(void);
+long __vmsettime(unsigned long long);
+long __vmstart(void *, void *);
+void __vmstop(void);
+long __vmwait(void);
+void __vmyield(void);
+long __vmvpid(void);
+
+static inline long __vmcache_ickill(void)
+{
+       return __vmcache(ickill, 0, 0);
+}
+
+static inline long __vmcache_dckill(void)
+{
+       return __vmcache(dckill, 0, 0);
+}
+
+static inline long __vmcache_l2kill(void)
+{
+       return __vmcache(l2kill, 0, 0);
+}
+
+static inline long __vmcache_dccleaninva(unsigned long addr, unsigned long len)
+{
+       return __vmcache(dccleaninva, addr, len);
+}
+
+static inline long __vmcache_icinva(unsigned long addr, unsigned long len)
+{
+       return __vmcache(icinva, addr, len);
+}
+
+static inline long __vmcache_idsync(unsigned long addr,
+                                          unsigned long len)
+{
+       return __vmcache(idsync, addr, len);
+}
+
+static inline long __vmcache_fetch_cfg(unsigned long val)
+{
+       return __vmcache(fetch_cfg, val, 0);
+}
+
+/* interrupt operations  */
+
+static inline long __vmintop_nop(void)
+{
+       return __vmintop(nop, 0, 0, 0, 0);
+}
+
+static inline long __vmintop_globen(long i)
+{
+       return __vmintop(globen, i, 0, 0, 0);
+}
+
+static inline long __vmintop_globdis(long i)
+{
+       return __vmintop(globdis, i, 0, 0, 0);
+}
+
+static inline long __vmintop_locen(long i)
+{
+       return __vmintop(locen, i, 0, 0, 0);
+}
+
+static inline long __vmintop_locdis(long i)
+{
+       return __vmintop(locdis, i, 0, 0, 0);
+}
+
+static inline long __vmintop_affinity(long i, long cpu)
+{
+       return __vmintop(locdis, i, cpu, 0, 0);
+}
+
+static inline long __vmintop_get(void)
+{
+       return __vmintop(get, 0, 0, 0, 0);
+}
+
+static inline long __vmintop_peek(void)
+{
+       return __vmintop(peek, 0, 0, 0, 0);
+}
+
+static inline long __vmintop_status(long i)
+{
+       return __vmintop(status, i, 0, 0, 0);
+}
+
+static inline long __vmintop_post(long i)
+{
+       return __vmintop(post, i, 0, 0, 0);
+}
+
+static inline long __vmintop_clear(long i)
+{
+       return __vmintop(clear, i, 0, 0, 0);
+}
+
+#else /* Only assembly code should reference these */
+
+#define HVM_TRAP1_VMRTE                        1
+#define HVM_TRAP1_VMSETVEC             2
+#define HVM_TRAP1_VMSETIE              3
+#define HVM_TRAP1_VMGETIE              4
+#define HVM_TRAP1_VMINTOP              5
+#define HVM_TRAP1_VMCLRMAP             10
+#define HVM_TRAP1_VMNEWMAP             11
+#define HVM_TRAP1_FORMERLY_VMWIRE      12
+#define HVM_TRAP1_VMCACHE              13
+#define HVM_TRAP1_VMGETTIME            14
+#define HVM_TRAP1_VMSETTIME            15
+#define HVM_TRAP1_VMWAIT               16
+#define HVM_TRAP1_VMYIELD              17
+#define HVM_TRAP1_VMSTART              18
+#define HVM_TRAP1_VMSTOP               19
+#define HVM_TRAP1_VMVPID               20
+#define HVM_TRAP1_VMSETREGS            21
+#define HVM_TRAP1_VMGETREGS            22
+
+#endif /* __ASSEMBLY__ */
+
+/*
+ * Constants for virtual instruction parameters and return values
+ */
+
+/* vmsetie arguments */
+
+#define VM_INT_DISABLE 0
+#define VM_INT_ENABLE  1
+
+/* vmsetimask arguments */
+
+#define VM_INT_UNMASK  0
+#define VM_INT_MASK    1
+
+#define VM_NEWMAP_TYPE_LINEAR  0
+#define VM_NEWMAP_TYPE_PGTABLES        1
+
+
+/*
+ * Event Record definitions useful to both C and Assembler
+ */
+
+/* VMEST Layout */
+
+#define HVM_VMEST_UM_SFT       31
+#define HVM_VMEST_UM_MSK       1
+#define HVM_VMEST_IE_SFT       30
+#define HVM_VMEST_IE_MSK       1
+#define HVM_VMEST_EVENTNUM_SFT 16
+#define HVM_VMEST_EVENTNUM_MSK 0xff
+#define HVM_VMEST_CAUSE_SFT    0
+#define HVM_VMEST_CAUSE_MSK    0xffff
+
+/*
+ * The initial program gets to find a system environment descriptor
+ * on its stack when it begins exection. The first word is a version
+ * code to indicate what is there.  Zero means nothing more.
+ */
+
+#define HEXAGON_VM_SED_NULL    0
+
+/*
+ * Event numbers for vector binding
+ */
+
+#define HVM_EV_RESET           0
+#define HVM_EV_MACHCHECK       1
+#define HVM_EV_GENEX           2
+#define HVM_EV_TRAP            8
+#define HVM_EV_INTR            15
+/* These shoud be nuked as soon as we know the VM is up to spec v0.1.1 */
+#define HVM_EV_INTR_0          16
+#define HVM_MAX_INTR           240
+
+/*
+ * Cause values for General Exception
+ */
+
+#define HVM_GE_C_BUS   0x01
+#define HVM_GE_C_XPROT 0x11
+#define HVM_GE_C_XUSER 0x14
+#define HVM_GE_C_INVI  0x15
+#define HVM_GE_C_PRIVI 0x1B
+#define HVM_GE_C_XMAL  0x1C
+#define HVM_GE_C_RMAL  0x20
+#define HVM_GE_C_WMAL  0x21
+#define HVM_GE_C_RPROT 0x22
+#define HVM_GE_C_WPROT 0x23
+#define HVM_GE_C_RUSER 0x24
+#define HVM_GE_C_WUSER 0x25
+#define HVM_GE_C_CACHE 0x28
+
+/*
+ * Cause codes for Machine Check
+ */
+
+#define        HVM_MCHK_C_DOWN         0x00
+#define        HVM_MCHK_C_BADSP        0x01
+#define        HVM_MCHK_C_BADEX        0x02
+#define        HVM_MCHK_C_BADPT        0x03
+#define        HVM_MCHK_C_REGWR        0x29
+
+#endif
diff --git a/arch/hexagon/include/asm/intrinsics.h b/arch/hexagon/include/asm/intrinsics.h
new file mode 100644 (file)
index 0000000..1c02186
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_HEXAGON_INTRINSICS_H
+#define _ASM_HEXAGON_INTRINSICS_H
+
+#define HEXAGON_P_vrmpyhacc_PP __builtin_HEXAGON_M2_vrmac_s0
+#define HEXAGON_P_vrmpyh_PP    __builtin_HEXAGON_M2_vrmpy_s0
+#define HEXAGON_R_cl0_R                __builtin_HEXAGON_S2_cl0
+
+#endif
diff --git a/arch/hexagon/include/asm/io.h b/arch/hexagon/include/asm/io.h
new file mode 100644 (file)
index 0000000..b3acc2c
--- /dev/null
@@ -0,0 +1,326 @@
+/*
+ * IO definitions for the Hexagon architecture
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_IO_H
+#define _ASM_IO_H
+
+#ifdef __KERNEL__
+
+#include <linux/types.h>
+#include <linux/delay.h>
+#include <linux/vmalloc.h>
+#include <asm/string.h>
+#include <asm/mem-layout.h>
+#include <asm/iomap.h>
+#include <asm/page.h>
+#include <asm/cacheflush.h>
+#include <asm/tlbflush.h>
+
+/*
+ * We don't have PCI yet.
+ * _IO_BASE is pointing at what should be unused virtual space.
+ */
+#define IO_SPACE_LIMIT 0xffff
+#define _IO_BASE ((void __iomem *)0xfe000000)
+
+extern int remap_area_pages(unsigned long start, unsigned long phys_addr,
+                               unsigned long end, unsigned long flags);
+
+extern void __iounmap(const volatile void __iomem *addr);
+
+/* Defined in lib/io.c, needed for smc91x driver. */
+extern void __raw_readsw(const void __iomem *addr, void *data, int wordlen);
+extern void __raw_writesw(void __iomem *addr, const void *data, int wordlen);
+
+extern void __raw_readsl(const void __iomem *addr, void *data, int wordlen);
+extern void __raw_writesl(void __iomem *addr, const void *data, int wordlen);
+
+#define readsw(p, d, l)        __raw_readsw(p, d, l)
+#define writesw(p, d, l) __raw_writesw(p, d, l)
+
+#define readsl(p, d, l)   __raw_readsl(p, d, l)
+#define writesl(p, d, l)  __raw_writesl(p, d, l)
+
+/*
+ * virt_to_phys - map virtual address to physical
+ * @address:  address to map
+ */
+static inline unsigned long virt_to_phys(volatile void *address)
+{
+       return __pa(address);
+}
+
+/*
+ * phys_to_virt - map physical address to virtual
+ * @address: address to map
+ */
+static inline void *phys_to_virt(unsigned long address)
+{
+       return __va(address);
+}
+
+/*
+ * convert a physical pointer to a virtual kernel pointer for
+ * /dev/mem access.
+ */
+#define xlate_dev_kmem_ptr(p)    __va(p)
+#define xlate_dev_mem_ptr(p)    __va(p)
+
+/*
+ * IO port access primitives.  Hexagon doesn't have special IO access
+ * instructions; all I/O is memory mapped.
+ *
+ * in/out are used for "ports", but we don't have "port instructions",
+ * so these are really just memory mapped too.
+ */
+
+/*
+ * readb - read byte from memory mapped device
+ * @addr:  pointer to memory
+ *
+ * Operates on "I/O bus memory space"
+ */
+static inline u8 readb(const volatile void __iomem *addr)
+{
+       u8 val;
+       asm volatile(
+               "%0 = memb(%1);"
+               : "=&r" (val)
+               : "r" (addr)
+       );
+       return val;
+}
+
+static inline u16 readw(const volatile void __iomem *addr)
+{
+       u16 val;
+       asm volatile(
+               "%0 = memh(%1);"
+               : "=&r" (val)
+               : "r" (addr)
+       );
+       return val;
+}
+
+static inline u32 readl(const volatile void __iomem *addr)
+{
+       u32 val;
+       asm volatile(
+               "%0 = memw(%1);"
+               : "=&r" (val)
+               : "r" (addr)
+       );
+       return val;
+}
+
+/*
+ * writeb - write a byte to a memory location
+ * @data: data to write to
+ * @addr:  pointer to memory
+ *
+ */
+static inline void writeb(u8 data, volatile void __iomem *addr)
+{
+       asm volatile(
+               "memb(%0) = %1;"
+               :
+               : "r" (addr), "r" (data)
+               : "memory"
+       );
+}
+
+static inline void writew(u16 data, volatile void __iomem *addr)
+{
+       asm volatile(
+               "memh(%0) = %1;"
+               :
+               : "r" (addr), "r" (data)
+               : "memory"
+       );
+
+}
+
+static inline void writel(u32 data, volatile void __iomem *addr)
+{
+       asm volatile(
+               "memw(%0) = %1;"
+               :
+               : "r" (addr), "r" (data)
+               : "memory"
+       );
+}
+
+#define __raw_writeb writeb
+#define __raw_writew writew
+#define __raw_writel writel
+
+#define __raw_readb readb
+#define __raw_readw readw
+#define __raw_readl readl
+
+/*
+ * Need an mtype somewhere in here, for cache type deals?
+ * This is probably too long for an inline.
+ */
+void __iomem *ioremap_nocache(unsigned long phys_addr, unsigned long size);
+
+static inline void __iomem *ioremap(unsigned long phys_addr, unsigned long size)
+{
+       return ioremap_nocache(phys_addr, size);
+}
+
+static inline void iounmap(volatile void __iomem *addr)
+{
+       __iounmap(addr);
+}
+
+#define __raw_writel writel
+
+static inline void memcpy_fromio(void *dst, const volatile void __iomem *src,
+       int count)
+{
+       memcpy(dst, (void *) src, count);
+}
+
+static inline void memcpy_toio(volatile void __iomem *dst, const void *src,
+       int count)
+{
+       memcpy((void *) dst, src, count);
+}
+
+#define PCI_IO_ADDR    (volatile void __iomem *)
+
+/*
+ * inb - read byte from I/O port or something
+ * @port:  address in I/O space
+ *
+ * Operates on "I/O bus I/O space"
+ */
+static inline u8 inb(unsigned long port)
+{
+       return readb(_IO_BASE + (port & IO_SPACE_LIMIT));
+}
+
+static inline u16 inw(unsigned long port)
+{
+       return readw(_IO_BASE + (port & IO_SPACE_LIMIT));
+}
+
+static inline u32 inl(unsigned long port)
+{
+       return readl(_IO_BASE + (port & IO_SPACE_LIMIT));
+}
+
+/*
+ * outb - write a byte to a memory location
+ * @data: data to write to
+ * @addr:  address in I/O space
+ */
+static inline void outb(u8 data, unsigned long port)
+{
+       writeb(data, _IO_BASE + (port & IO_SPACE_LIMIT));
+}
+
+static inline void outw(u16 data, unsigned long port)
+{
+       writew(data, _IO_BASE + (port & IO_SPACE_LIMIT));
+}
+
+static inline void outl(u32 data, unsigned long port)
+{
+       writel(data, _IO_BASE + (port & IO_SPACE_LIMIT));
+}
+
+#define outb_p outb
+#define outw_p outw
+#define outl_p outl
+
+#define inb_p inb
+#define inw_p inw
+#define inl_p inl
+
+static inline void insb(unsigned long port, void *buffer, int count)
+{
+       if (count) {
+               u8 *buf = buffer;
+               do {
+                       u8 x = inb(port);
+                       *buf++ = x;
+               } while (--count);
+       }
+}
+
+static inline void insw(unsigned long port, void *buffer, int count)
+{
+       if (count) {
+               u16 *buf = buffer;
+               do {
+                       u16 x = inw(port);
+                       *buf++ = x;
+               } while (--count);
+       }
+}
+
+static inline void insl(unsigned long port, void *buffer, int count)
+{
+       if (count) {
+               u32 *buf = buffer;
+               do {
+                       u32 x = inw(port);
+                       *buf++ = x;
+               } while (--count);
+       }
+}
+
+static inline void outsb(unsigned long port, const void *buffer, int count)
+{
+       if (count) {
+               const u8 *buf = buffer;
+               do {
+                       outb(*buf++, port);
+               } while (--count);
+       }
+}
+
+static inline void outsw(unsigned long port, const void *buffer, int count)
+{
+       if (count) {
+               const u16 *buf = buffer;
+               do {
+                       outw(*buf++, port);
+               } while (--count);
+       }
+}
+
+static inline void outsl(unsigned long port, const void *buffer, int count)
+{
+       if (count) {
+               const u32 *buf = buffer;
+               do {
+                       outl(*buf++, port);
+               } while (--count);
+       }
+}
+
+#define flush_write_buffers() do { } while (0)
+
+#endif /* __KERNEL__ */
+
+#endif
diff --git a/arch/hexagon/include/asm/irq.h b/arch/hexagon/include/asm/irq.h
new file mode 100644 (file)
index 0000000..ded8c15
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_IRQ_H_
+#define _ASM_IRQ_H_
+
+/* Number of first-level interrupts associated with the CPU core. */
+#define HEXAGON_CPUINTS 32
+
+/*
+ * Must define NR_IRQS before including <asm-generic/irq.h>
+ * 64 == the two SIRC's, 176 == the two gpio's
+ *
+ * IRQ configuration is still in flux; defining this to a comfortably
+ * large number.
+ */
+#define NR_IRQS 512
+
+#include <asm-generic/irq.h>
+
+#endif
diff --git a/arch/hexagon/include/asm/irqflags.h b/arch/hexagon/include/asm/irqflags.h
new file mode 100644 (file)
index 0000000..ec15236
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * IRQ support for the Hexagon architecture
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_IRQFLAGS_H
+#define _ASM_IRQFLAGS_H
+
+#include <asm/hexagon_vm.h>
+#include <linux/types.h>
+
+static inline unsigned long arch_local_save_flags(void)
+{
+       return __vmgetie();
+}
+
+static inline unsigned long arch_local_irq_save(void)
+{
+       return __vmsetie(VM_INT_DISABLE);
+}
+
+static inline bool arch_irqs_disabled_flags(unsigned long flags)
+{
+       return !flags;
+}
+
+static inline bool arch_irqs_disabled(void)
+{
+       return !__vmgetie();
+}
+
+static inline void arch_local_irq_enable(void)
+{
+       __vmsetie(VM_INT_ENABLE);
+}
+
+static inline void arch_local_irq_disable(void)
+{
+       __vmsetie(VM_INT_DISABLE);
+}
+
+static inline void arch_local_irq_restore(unsigned long flags)
+{
+       __vmsetie(flags);
+}
+
+#endif
diff --git a/arch/hexagon/include/asm/kgdb.h b/arch/hexagon/include/asm/kgdb.h
new file mode 100644 (file)
index 0000000..9e87797
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * arch/hexagon/include/asm/kgdb.h - Hexagon KGDB Support
+ *
+ * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef __HEXAGON_KGDB_H__
+#define __HEXAGON_KGDB_H__
+
+#define BREAK_INSTR_SIZE 4
+#define CACHE_FLUSH_IS_SAFE   1
+#define BUFMAX       ((NUMREGBYTES * 2) + 512)
+
+static inline void arch_kgdb_breakpoint(void)
+{
+       asm("trap0(#0xDB)");
+}
+
+/* Registers:
+ * 32 gpr + sa0/1 + lc0/1 + m0/1 + gp + ugp + pred + pc = 42 total.
+ * vm regs = psp+elr+est+badva = 4
+ * syscall+restart = 2 more
+ * so 48 = 42 +4 + 2
+ */
+#define DBG_USER_REGS 42
+#define DBG_MAX_REG_NUM (DBG_USER_REGS + 6)
+#define NUMREGBYTES  (DBG_MAX_REG_NUM*4)
+
+#endif /* __HEXAGON_KGDB_H__ */
diff --git a/arch/hexagon/include/asm/linkage.h b/arch/hexagon/include/asm/linkage.h
new file mode 100644 (file)
index 0000000..a00b85f
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef __ASM_LINKAGE_H
+#define __ASM_LINKAGE_H
+
+#define __ALIGN                .align 4
+#define __ALIGN_STR    ".align 4"
+
+#endif
diff --git a/arch/hexagon/include/asm/mem-layout.h b/arch/hexagon/include/asm/mem-layout.h
new file mode 100644 (file)
index 0000000..72e5dcd
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * Memory layout definitions for the Hexagon architecture
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_HEXAGON_MEM_LAYOUT_H
+#define _ASM_HEXAGON_MEM_LAYOUT_H
+
+#include <linux/const.h>
+
+/*
+ * Have to do this for ginormous numbers, else they get printed as
+ * negative numbers, which the linker no likey when you try to
+ * assign it to the location counter.
+ */
+
+#define PAGE_OFFSET                    _AC(0xc0000000, UL)
+
+/*
+ * LOAD_ADDRESS is the physical/linear address of where in memory
+ * the kernel gets loaded. The 12 least significant bits must be zero (0)
+ * due to limitations on setting the EVB
+ *
+ */
+
+#ifndef LOAD_ADDRESS
+#define LOAD_ADDRESS                   0x00000000
+#endif
+
+#define TASK_SIZE                      (PAGE_OFFSET)
+
+/*  not sure how these are used yet  */
+#define STACK_TOP                      TASK_SIZE
+#define STACK_TOP_MAX                  TASK_SIZE
+
+#ifndef __ASSEMBLY__
+enum fixed_addresses {
+       FIX_KMAP_BEGIN,
+       FIX_KMAP_END,  /*  check for per-cpuism  */
+       __end_of_fixed_addresses
+};
+
+#define MIN_KERNEL_SEG 0x300   /* From 0xc0000000 */
+extern int max_kernel_seg;
+
+/*
+ * Start of vmalloc virtual address space for kernel;
+ * supposed to be based on the amount of physical memory available
+ */
+
+#define VMALLOC_START (PAGE_OFFSET + VMALLOC_OFFSET + \
+       (unsigned long)high_memory)
+
+/* Gap between physical ram and vmalloc space for guard purposes. */
+#define VMALLOC_OFFSET PAGE_SIZE
+
+/*
+ * Create the space between VMALLOC_START and FIXADDR_TOP backwards
+ * from the ... "top".
+ *
+ * Permanent IO mappings will live at 0xfexx_xxxx
+ * Hypervisor occupies the last 16MB page at 0xffxxxxxx
+ */
+
+#define FIXADDR_TOP     0xfe000000
+#define FIXADDR_SIZE    (__end_of_fixed_addresses << PAGE_SHIFT)
+#define FIXADDR_START   (FIXADDR_TOP - FIXADDR_SIZE)
+
+/*
+ * "permanent kernel mappings", defined as long-lasting mappings of
+ * high-memory page frames into the kernel address space.
+ */
+
+#define LAST_PKMAP     PTRS_PER_PTE
+#define LAST_PKMAP_MASK        (LAST_PKMAP - 1)
+#define PKMAP_NR(virt) ((virt - PKMAP_BASE) >> PAGE_SHIFT)
+#define PKMAP_ADDR(nr) (PKMAP_BASE + ((nr) << PAGE_SHIFT))
+
+/*
+ * To the "left" of the fixed map space is the kmap space
+ *
+ * "Permanent Kernel Mappings"; fancy (or less fancy) PTE table
+ * that looks like it's actually walked.
+ * Need to check the alignment/shift usage; some archs use
+ * PMD_MASK on this value
+ */
+#define PKMAP_BASE (FIXADDR_START-PAGE_SIZE*LAST_PKMAP)
+
+/*
+ * 2 pages of guard gap between where vmalloc area ends
+ * and pkmap_base begins.
+ */
+#define VMALLOC_END (PKMAP_BASE-PAGE_SIZE*2)
+#endif /*  !__ASSEMBLY__  */
+
+
+#endif /* _ASM_HEXAGON_MEM_LAYOUT_H */
diff --git a/arch/hexagon/include/asm/mmu.h b/arch/hexagon/include/asm/mmu.h
new file mode 100644 (file)
index 0000000..30a5d8d
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_MMU_H
+#define _ASM_MMU_H
+
+#include <asm/vdso.h>
+
+/*
+ * Architecture-specific state for a mm_struct.
+ * For the Hexagon Virtual Machine, it can be a copy
+ * of the pointer to the page table base.
+ */
+struct mm_context {
+       unsigned long long generation;
+       unsigned long ptbase;
+       struct hexagon_vdso *vdso;
+};
+
+typedef struct mm_context mm_context_t;
+
+#endif
diff --git a/arch/hexagon/include/asm/mmu_context.h b/arch/hexagon/include/asm/mmu_context.h
new file mode 100644 (file)
index 0000000..b4fe5a5
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * MM context support for the Hexagon architecture
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_MMU_CONTEXT_H
+#define _ASM_MMU_CONTEXT_H
+
+#include <asm/setup.h>
+#include <asm/page.h>
+#include <asm/pgalloc.h>
+#include <asm/mem-layout.h>
+
+static inline void destroy_context(struct mm_struct *mm)
+{
+}
+
+/*
+ * VM port hides all TLB management, so "lazy TLB" isn't very
+ * meaningful.  Even for ports to architectures with visble TLBs,
+ * this is almost invariably a null function.
+ */
+static inline void enter_lazy_tlb(struct mm_struct *mm,
+       struct task_struct *tsk)
+{
+}
+
+/*
+ * Architecture-specific actions, if any, for memory map deactivation.
+ */
+static inline void deactivate_mm(struct task_struct *tsk,
+       struct mm_struct *mm)
+{
+}
+
+/**
+ * init_new_context - initialize context related info for new mm_struct instance
+ * @tsk: pointer to a task struct
+ * @mm: pointer to a new mm struct
+ */
+static inline int init_new_context(struct task_struct *tsk,
+                                       struct mm_struct *mm)
+{
+       /* mm->context is set up by pgd_alloc */
+       return 0;
+}
+
+/*
+ *  Switch active mm context
+ */
+static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
+                               struct task_struct *tsk)
+{
+       int l1;
+
+       /*
+        * For virtual machine, we have to update system map if it's been
+        * touched.
+        */
+       if (next->context.generation < prev->context.generation) {
+               for (l1 = MIN_KERNEL_SEG; l1 <= max_kernel_seg; l1++)
+                       next->pgd[l1] = init_mm.pgd[l1];
+
+               next->context.generation = prev->context.generation;
+       }
+
+       __vmnewmap((void *)next->context.ptbase);
+}
+
+/*
+ *  Activate new memory map for task
+ */
+static inline void activate_mm(struct mm_struct *prev, struct mm_struct *next)
+{
+       unsigned long flags;
+
+       local_irq_save(flags);
+       switch_mm(prev, next, current_thread_info()->task);
+       local_irq_restore(flags);
+}
+
+/*  Generic hooks for arch_dup_mmap and arch_exit_mmap  */
+#include <asm-generic/mm_hooks.h>
+
+#endif
diff --git a/arch/hexagon/include/asm/module.h b/arch/hexagon/include/asm/module.h
new file mode 100644 (file)
index 0000000..72ba494
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_MODULE_H
+#define _ASM_MODULE_H
+
+#include <asm-generic/module.h>
+
+#define MODULE_ARCH_VERMAGIC __stringify(PROCESSOR_MODEL_NAME) " "
+
+#endif
diff --git a/arch/hexagon/include/asm/mutex.h b/arch/hexagon/include/asm/mutex.h
new file mode 100644 (file)
index 0000000..58b52de
--- /dev/null
@@ -0,0 +1,8 @@
+/*
+ * Pull in the generic implementation for the mutex fastpath.
+ *
+ * TODO: implement optimized primitives instead, or leave the generic
+ * implementation in place, or pick the atomic_xchg() based generic
+ * implementation. (see asm-generic/mutex-xchg.h for details)
+ */
+#include <asm-generic/mutex-xchg.h>
diff --git a/arch/hexagon/include/asm/page.h b/arch/hexagon/include/asm/page.h
new file mode 100644 (file)
index 0000000..edd9762
--- /dev/null
@@ -0,0 +1,157 @@
+/*
+ * Page management definitions for the Hexagon architecture
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_PAGE_H
+#define _ASM_PAGE_H
+
+#include <linux/const.h>
+
+/*  This is probably not the most graceful way to handle this.  */
+
+#ifdef CONFIG_PAGE_SIZE_4KB
+#define PAGE_SHIFT 12
+#define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_4KB
+#endif
+
+#ifdef CONFIG_PAGE_SIZE_16KB
+#define PAGE_SHIFT 14
+#define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_16KB
+#endif
+
+#ifdef CONFIG_PAGE_SIZE_64KB
+#define PAGE_SHIFT 16
+#define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_64KB
+#endif
+
+#ifdef CONFIG_PAGE_SIZE_256KB
+#define PAGE_SHIFT 18
+#define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_256KB
+#endif
+
+#ifdef CONFIG_PAGE_SIZE_1MB
+#define PAGE_SHIFT 20
+#define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_1MB
+#endif
+
+/*
+ *  These should be defined in hugetlb.h, but apparently not.
+ *  "Huge" for us should be 4MB or 16MB, which are both represented
+ *  in L1 PTE's.  Right now, it's set up for 4MB.
+ */
+#ifdef CONFIG_HUGETLB_PAGE
+#define HPAGE_SHIFT 22
+#define HPAGE_SIZE (1UL << HPAGE_SHIFT)
+#define HPAGE_MASK (~(HPAGE_SIZE-1))
+#define HUGETLB_PAGE_ORDER (HPAGE_SHIFT-PAGE_SHIFT)
+#define HVM_HUGEPAGE_SIZE 0x5
+#endif
+
+#define PAGE_SIZE  (1UL << PAGE_SHIFT)
+#define PAGE_MASK  (~((1 << PAGE_SHIFT) - 1))
+
+#ifdef __KERNEL__
+#ifndef __ASSEMBLY__
+
+/*
+ * This is for PFN_DOWN, which mm.h needs.  Seems the right place to pull it in.
+ */
+#include <linux/pfn.h>
+
+/*
+ * We implement a two-level architecture-specific page table structure.
+ * Null intermediate page table level (pmd, pud) definitions will come from
+ * asm-generic/pagetable-nopmd.h and asm-generic/pagetable-nopud.h
+ */
+typedef struct { unsigned long pte; } pte_t;
+typedef struct { unsigned long pgd; } pgd_t;
+typedef struct { unsigned long pgprot; } pgprot_t;
+typedef struct page *pgtable_t;
+
+#define pte_val(x)     ((x).pte)
+#define pgd_val(x)     ((x).pgd)
+#define pgprot_val(x)  ((x).pgprot)
+#define __pte(x)       ((pte_t) { (x) })
+#define __pgd(x)       ((pgd_t) { (x) })
+#define __pgprot(x)    ((pgprot_t) { (x) })
+
+/*
+ * We need a __pa and a __va routine for kernel space.
+ * MIPS says they're only used during mem_init.
+ * also, check if we need a PHYS_OFFSET.
+ */
+#define __pa(x) ((unsigned long)(x) - PAGE_OFFSET)
+#define __va(x) ((void *)((unsigned long)(x) + PAGE_OFFSET))
+
+/* The "page frame" descriptor is defined in linux/mm.h */
+struct page;
+
+/* Returns page frame descriptor for virtual address. */
+#define virt_to_page(kaddr) pfn_to_page(PFN_DOWN(__pa(kaddr)))
+
+/* Default vm area behavior is non-executable.  */
+#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | \
+                               VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
+
+#define pfn_valid(pfn) ((pfn) < max_mapnr)
+#define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
+
+/*  Need to not use a define for linesize; may move this to another file.  */
+static inline void clear_page(void *page)
+{
+       /*  This can only be done on pages with L1 WB cache */
+       asm volatile(
+               "       loop0(1f,%1);\n"
+               "1:     { dczeroa(%0);\n"
+               "         %0 = add(%0,#32); }:endloop0\n"
+               : "+r" (page)
+               : "r" (PAGE_SIZE/32)
+               : "lc0", "sa0", "memory"
+       );
+}
+
+#define copy_page(to, from)    memcpy((to), (from), PAGE_SIZE)
+
+/*
+ * Under assumption that kernel always "sees" user map...
+ */
+#define clear_user_page(page, vaddr, pg)       clear_page(page)
+#define copy_user_page(to, from, vaddr, pg)    copy_page(to, from)
+
+/*
+ * page_to_phys - convert page to physical address
+ * @page - pointer to page entry in mem_map
+ */
+#define page_to_phys(page)      (page_to_pfn(page) << PAGE_SHIFT)
+
+/*
+ * For port to Hexagon Virtual Machine, MAYBE we check for attempts
+ * to reference reserved HVM space, but in any case, the VM will be
+ * protected.
+ */
+#define kern_addr_valid(addr)   (1)
+
+#include <asm-generic/memory_model.h>
+/* XXX Todo: implement assembly-optimized version of getorder. */
+#include <asm-generic/getorder.h>
+
+#endif /* ifdef __ASSEMBLY__ */
+#endif /* ifdef __KERNEL__ */
+
+#endif
diff --git a/arch/hexagon/include/asm/param.h b/arch/hexagon/include/asm/param.h
new file mode 100644 (file)
index 0000000..285344b
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_PARAM_H
+#define _ASM_PARAM_H
+
+#define EXEC_PAGESIZE  16384
+
+#include <asm-generic/param.h>
+
+#endif
diff --git a/arch/hexagon/include/asm/perf_event.h b/arch/hexagon/include/asm/perf_event.h
new file mode 100644 (file)
index 0000000..6c2910f
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_PERF_EVENT_H
+#define _ASM_PERF_EVENT_H
+
+#define PERF_EVENT_INDEX_OFFSET        0
+
+#endif /* _ASM_PERF_EVENT_H */
diff --git a/arch/hexagon/include/asm/pgalloc.h b/arch/hexagon/include/asm/pgalloc.h
new file mode 100644 (file)
index 0000000..13443c7
--- /dev/null
@@ -0,0 +1,146 @@
+/*
+ * Page table support for the Hexagon architecture
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_PGALLOC_H
+#define _ASM_PGALLOC_H
+
+#include <asm/mem-layout.h>
+#include <asm/atomic.h>
+
+#define check_pgt_cache() do {} while (0)
+
+extern unsigned long long kmap_generation;
+
+/*
+ * Page table creation interface
+ */
+static inline pgd_t *pgd_alloc(struct mm_struct *mm)
+{
+       pgd_t *pgd;
+
+       pgd = (pgd_t *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
+
+       /*
+        * There may be better ways to do this, but to ensure
+        * that new address spaces always contain the kernel
+        * base mapping, and to ensure that the user area is
+        * initially marked invalid, initialize the new map
+        * map with a copy of the kernel's persistent map.
+        */
+
+       memcpy(pgd, swapper_pg_dir, PTRS_PER_PGD*sizeof(pgd_t *));
+       mm->context.generation = kmap_generation;
+
+       /* Physical version is what is passed to virtual machine on switch */
+       mm->context.ptbase = __pa(pgd);
+
+       return pgd;
+}
+
+static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
+{
+       free_page((unsigned long) pgd);
+}
+
+static inline struct page *pte_alloc_one(struct mm_struct *mm,
+                                        unsigned long address)
+{
+       struct page *pte;
+
+       pte = alloc_page(GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO);
+
+       if (pte)
+               pgtable_page_ctor(pte);
+
+       return pte;
+}
+
+/* _kernel variant gets to use a different allocator */
+static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
+                                         unsigned long address)
+{
+       gfp_t flags =  GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO;
+       return (pte_t *) __get_free_page(flags);
+}
+
+static inline void pte_free(struct mm_struct *mm, struct page *pte)
+{
+       pgtable_page_dtor(pte);
+       __free_page(pte);
+}
+
+static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
+{
+       free_page((unsigned long)pte);
+}
+
+static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
+                               pgtable_t pte)
+{
+       /*
+        * Conveniently, zero in 3 LSB means indirect 4K page table.
+        * Not so convenient when you're trying to vary the page size.
+        */
+       set_pmd(pmd, __pmd(((unsigned long)page_to_pfn(pte) << PAGE_SHIFT) |
+               HEXAGON_L1_PTE_SIZE));
+}
+
+/*
+ * Other architectures seem to have ways of making all processes
+ * share the same pmd's for their kernel mappings, but the v0.3
+ * Hexagon VM spec has a "monolithic" L1 table for user and kernel
+ * segments.  We track "generations" of the kernel map to minimize
+ * overhead, and update the "slave" copies of the kernel mappings
+ * as part of switch_mm.  However, we still need to update the
+ * kernel map of the active thread who's calling pmd_populate_kernel...
+ */
+static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
+                                      pte_t *pte)
+{
+       extern spinlock_t kmap_gen_lock;
+       pmd_t *ppmd;
+       int pmdindex;
+
+       spin_lock(&kmap_gen_lock);
+       kmap_generation++;
+       mm->context.generation = kmap_generation;
+       current->active_mm->context.generation = kmap_generation;
+       spin_unlock(&kmap_gen_lock);
+
+       set_pmd(pmd, __pmd(((unsigned long)__pa(pte)) | HEXAGON_L1_PTE_SIZE));
+
+       /*
+        * Now the "slave" copy of the current thread.
+        * This is pointer arithmetic, not byte addresses!
+        */
+       pmdindex = (pgd_t *)pmd - mm->pgd;
+       ppmd = (pmd_t *)current->active_mm->pgd + pmdindex;
+       set_pmd(ppmd, __pmd(((unsigned long)__pa(pte)) | HEXAGON_L1_PTE_SIZE));
+       if (pmdindex > max_kernel_seg)
+               max_kernel_seg = pmdindex;
+}
+
+#define __pte_free_tlb(tlb, pte, addr)         \
+do {                                           \
+       pgtable_page_dtor((pte));               \
+       tlb_remove_page((tlb), (pte));          \
+} while (0)
+
+#endif
diff --git a/arch/hexagon/include/asm/pgtable.h b/arch/hexagon/include/asm/pgtable.h
new file mode 100644 (file)
index 0000000..ca619bf
--- /dev/null
@@ -0,0 +1,518 @@
+/*
+ * Page table support for the Hexagon architecture
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_PGTABLE_H
+#define _ASM_PGTABLE_H
+
+/*
+ * Page table definitions for Qualcomm Hexagon processor.
+ */
+#include <linux/swap.h>
+#include <asm/page.h>
+#include <asm-generic/pgtable-nopmd.h>
+
+/* A handy thing to have if one has the RAM. Declared in head.S */
+extern unsigned long empty_zero_page;
+extern unsigned long zero_page_mask;
+
+/*
+ * The PTE model described here is that of the Hexagon Virtual Machine,
+ * which autonomously walks 2-level page tables.  At a lower level, we
+ * also describe the RISCish software-loaded TLB entry structure of
+ * the underlying Hexagon processor. A kernel built to run on the
+ * virtual machine has no need to know about the underlying hardware.
+ */
+#include <asm/vm_mmu.h>
+
+/*
+ * To maximize the comfort level for the PTE manipulation macros,
+ * define the "well known" architecture-specific bits.
+ */
+#define _PAGE_READ     __HVM_PTE_R
+#define _PAGE_WRITE    __HVM_PTE_W
+#define _PAGE_EXECUTE  __HVM_PTE_X
+#define _PAGE_USER     __HVM_PTE_U
+
+/*
+ * We have a total of 4 "soft" bits available in the abstract PTE.
+ * The two mandatory software bits are Dirty and Accessed.
+ * To make nonlinear swap work according to the more recent
+ * model, we want a low order "Present" bit to indicate whether
+ * the PTE describes MMU programming or swap space.
+ */
+#define _PAGE_PRESENT  (1<<0)
+#define _PAGE_DIRTY    (1<<1)
+#define _PAGE_ACCESSED (1<<2)
+
+/*
+ * _PAGE_FILE is only meaningful if _PAGE_PRESENT is false, while
+ * _PAGE_DIRTY is only meaningful if _PAGE_PRESENT is true.
+ * So we can overload the bit...
+ */
+#define _PAGE_FILE     _PAGE_DIRTY /* set:  pagecache, unset = swap */
+
+/*
+ * For now, let's say that Valid and Present are the same thing.
+ * Alternatively, we could say that it's the "or" of R, W, and X
+ * permissions.
+ */
+#define _PAGE_VALID    _PAGE_PRESENT
+
+/*
+ * We're not defining _PAGE_GLOBAL here, since there's no concept
+ * of global pages or ASIDs exposed to the Hexagon Virtual Machine,
+ * and we want to use the same page table structures and macros in
+ * the native kernel as we do in the virtual machine kernel.
+ * So we'll put up with a bit of inefficiency for now...
+ */
+
+/*
+ * Top "FOURTH" level (pgd), which for the Hexagon VM is really
+ * only the second from the bottom, pgd and pud both being collapsed.
+ * Each entry represents 4MB of virtual address space, 4K of table
+ * thus maps the full 4GB.
+ */
+#define PGDIR_SHIFT 22
+#define PTRS_PER_PGD 1024
+
+#define PGDIR_SIZE (1UL << PGDIR_SHIFT)
+#define PGDIR_MASK (~(PGDIR_SIZE-1))
+
+#ifdef CONFIG_PAGE_SIZE_4KB
+#define PTRS_PER_PTE 1024
+#endif
+
+#ifdef CONFIG_PAGE_SIZE_16KB
+#define PTRS_PER_PTE 256
+#endif
+
+#ifdef CONFIG_PAGE_SIZE_64KB
+#define PTRS_PER_PTE 64
+#endif
+
+#ifdef CONFIG_PAGE_SIZE_256KB
+#define PTRS_PER_PTE 16
+#endif
+
+#ifdef CONFIG_PAGE_SIZE_1MB
+#define PTRS_PER_PTE 4
+#endif
+
+/*  Any bigger and the PTE disappears.  */
+#define pgd_ERROR(e) \
+       printk(KERN_ERR "%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__,\
+               pgd_val(e))
+
+/*
+ * Page Protection Constants. Includes (in this variant) cache attributes.
+ */
+extern unsigned long _dflt_cache_att;
+
+#define PAGE_NONE      __pgprot(_PAGE_PRESENT | _PAGE_USER | \
+                               _dflt_cache_att)
+#define PAGE_READONLY  __pgprot(_PAGE_PRESENT | _PAGE_USER | \
+                               _PAGE_READ | _PAGE_EXECUTE | _dflt_cache_att)
+#define PAGE_COPY      PAGE_READONLY
+#define PAGE_EXEC      __pgprot(_PAGE_PRESENT | _PAGE_USER | \
+                               _PAGE_READ | _PAGE_EXECUTE | _dflt_cache_att)
+#define PAGE_COPY_EXEC PAGE_EXEC
+#define PAGE_SHARED    __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | \
+                               _PAGE_EXECUTE | _PAGE_WRITE | _dflt_cache_att)
+#define PAGE_KERNEL    __pgprot(_PAGE_PRESENT | _PAGE_READ | \
+                               _PAGE_WRITE | _PAGE_EXECUTE | _dflt_cache_att)
+
+
+/*
+ * Aliases for mapping mmap() protection bits to page protections.
+ * These get used for static initialization, so using the _dflt_cache_att
+ * variable for the default cache attribute isn't workable. If the
+ * default gets changed at boot time, the boot option code has to
+ * update data structures like the protaction_map[] array.
+ */
+#define CACHEDEF       (CACHE_DEFAULT << 6)
+
+/* Private (copy-on-write) page protections. */
+#define __P000 __pgprot(_PAGE_PRESENT | _PAGE_USER | CACHEDEF)
+#define __P001 __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | CACHEDEF)
+#define __P010 __P000  /* Write-only copy-on-write */
+#define __P011 __P001  /* Read/Write copy-on-write */
+#define __P100 __pgprot(_PAGE_PRESENT | _PAGE_USER | \
+                       _PAGE_EXECUTE | CACHEDEF)
+#define __P101 __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_EXECUTE | \
+                       _PAGE_READ | CACHEDEF)
+#define __P110 __P100  /* Write/execute copy-on-write */
+#define __P111 __P101  /* Read/Write/Execute, copy-on-write */
+
+/* Shared page protections. */
+#define __S000 __P000
+#define __S001 __P001
+#define __S010 __pgprot(_PAGE_PRESENT | _PAGE_USER | \
+                       _PAGE_WRITE | CACHEDEF)
+#define __S011 __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | \
+                       _PAGE_WRITE | CACHEDEF)
+#define __S100 __pgprot(_PAGE_PRESENT | _PAGE_USER | \
+                       _PAGE_EXECUTE | CACHEDEF)
+#define __S101 __P101
+#define __S110 __pgprot(_PAGE_PRESENT | _PAGE_USER | \
+                       _PAGE_EXECUTE | _PAGE_WRITE | CACHEDEF)
+#define __S111 __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | \
+                       _PAGE_EXECUTE | _PAGE_WRITE | CACHEDEF)
+
+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];  /* located in head.S */
+
+/* Seems to be zero even in architectures where the zero page is firewalled? */
+#define FIRST_USER_ADDRESS 0
+#define pte_special(pte)       0
+#define pte_mkspecial(pte)     (pte)
+
+/*  HUGETLB not working currently  */
+#ifdef CONFIG_HUGETLB_PAGE
+#define pte_mkhuge(pte) __pte((pte_val(pte) & ~0x3) | HVM_HUGEPAGE_SIZE)
+#endif
+
+/*
+ * For now, assume that higher-level code will do TLB/MMU invalidations
+ * and don't insert that overhead into this low-level function.
+ */
+extern void sync_icache_dcache(pte_t pte);
+
+#define pte_present_exec_user(pte) \
+       ((pte_val(pte) & (_PAGE_EXECUTE | _PAGE_USER)) == \
+       (_PAGE_EXECUTE | _PAGE_USER))
+
+static inline void set_pte(pte_t *ptep, pte_t pteval)
+{
+       /*  should really be using pte_exec, if it weren't declared later. */
+       if (pte_present_exec_user(pteval))
+               sync_icache_dcache(pteval);
+
+       *ptep = pteval;
+}
+
+/*
+ * For the Hexagon Virtual Machine MMU (or its emulation), a null/invalid
+ * L1 PTE (PMD/PGD) has 7 in the least significant bits. For the L2 PTE
+ * (Linux PTE), the key is to have bits 11..9 all zero.  We'd use 0x7
+ * as a universal null entry, but some of those least significant bits
+ * are interpreted by software.
+ */
+#define _NULL_PMD      0x7
+#define _NULL_PTE      0x0
+
+static inline void pmd_clear(pmd_t *pmd_entry_ptr)
+{
+        pmd_val(*pmd_entry_ptr) = _NULL_PMD;
+}
+
+/*
+ * Conveniently, a null PTE value is invalid.
+ */
+static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
+                               pte_t *ptep)
+{
+       pte_val(*ptep) = _NULL_PTE;
+}
+
+#ifdef NEED_PMD_INDEX_DESPITE_BEING_2_LEVEL
+/**
+ * pmd_index - returns the index of the entry in the PMD page
+ * which would control the given virtual address
+ */
+#define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))
+
+#endif
+
+/**
+ * pgd_index - returns the index of the entry in the PGD page
+ * which would control the given virtual address
+ *
+ * This returns the *index* for the address in the pgd_t
+ */
+#define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
+
+/*
+ * pgd_offset - find an offset in a page-table-directory
+ */
+#define pgd_offset(mm, addr) ((mm)->pgd + pgd_index(addr))
+
+/*
+ * pgd_offset_k - get kernel (init_mm) pgd entry pointer for addr
+ */
+#define pgd_offset_k(address) pgd_offset(&init_mm, address)
+
+/**
+ * pmd_none - check if pmd_entry is mapped
+ * @pmd_entry:  pmd entry
+ *
+ * MIPS checks it against that "invalid pte table" thing.
+ */
+static inline int pmd_none(pmd_t pmd)
+{
+       return pmd_val(pmd) == _NULL_PMD;
+}
+
+/**
+ * pmd_present - is there a page table behind this?
+ * Essentially the inverse of pmd_none.  We maybe
+ * save an inline instruction by defining it this
+ * way, instead of simply "!pmd_none".
+ */
+static inline int pmd_present(pmd_t pmd)
+{
+       return pmd_val(pmd) != (unsigned long)_NULL_PMD;
+}
+
+/**
+ * pmd_bad - check if a PMD entry is "bad". That might mean swapped out.
+ * As we have no known cause of badness, it's null, as it is for many
+ * architectures.
+ */
+static inline int pmd_bad(pmd_t pmd)
+{
+       return 0;
+}
+
+/*
+ * pmd_page - converts a PMD entry to a page pointer
+ */
+#define pmd_page(pmd)  (pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT))
+#define pmd_pgtable(pmd) pmd_page(pmd)
+
+/**
+ * pte_none - check if pte is mapped
+ * @pte: pte_t entry
+ */
+static inline int pte_none(pte_t pte)
+{
+       return pte_val(pte) == _NULL_PTE;
+};
+
+/*
+ * pte_present - check if page is present
+ */
+static inline int pte_present(pte_t pte)
+{
+       return pte_val(pte) & _PAGE_PRESENT;
+}
+
+/* mk_pte - make a PTE out of a page pointer and protection bits */
+#define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
+
+/* pte_page - returns a page (frame pointer/descriptor?) based on a PTE */
+#define pte_page(x) pfn_to_page(pte_pfn(x))
+
+/* pte_mkold - mark PTE as not recently accessed */
+static inline pte_t pte_mkold(pte_t pte)
+{
+       pte_val(pte) &= ~_PAGE_ACCESSED;
+       return pte;
+}
+
+/* pte_mkyoung - mark PTE as recently accessed */
+static inline pte_t pte_mkyoung(pte_t pte)
+{
+       pte_val(pte) |= _PAGE_ACCESSED;
+       return pte;
+}
+
+/* pte_mkclean - mark page as in sync with backing store */
+static inline pte_t pte_mkclean(pte_t pte)
+{
+       pte_val(pte) &= ~_PAGE_DIRTY;
+       return pte;
+}
+
+/* pte_mkdirty - mark page as modified */
+static inline pte_t pte_mkdirty(pte_t pte)
+{
+       pte_val(pte) |= _PAGE_DIRTY;
+       return pte;
+}
+
+/* pte_young - "is PTE marked as accessed"? */
+static inline int pte_young(pte_t pte)
+{
+       return pte_val(pte) & _PAGE_ACCESSED;
+}
+
+/* pte_dirty - "is PTE dirty?" */
+static inline int pte_dirty(pte_t pte)
+{
+       return pte_val(pte) & _PAGE_DIRTY;
+}
+
+/* pte_modify - set protection bits on PTE */
+static inline pte_t pte_modify(pte_t pte, pgprot_t prot)
+{
+       pte_val(pte) &= PAGE_MASK;
+       pte_val(pte) |= pgprot_val(prot);
+       return pte;
+}
+
+/* pte_wrprotect - mark page as not writable */
+static inline pte_t pte_wrprotect(pte_t pte)
+{
+       pte_val(pte) &= ~_PAGE_WRITE;
+       return pte;
+}
+
+/* pte_mkwrite - mark page as writable */
+static inline pte_t pte_mkwrite(pte_t pte)
+{
+       pte_val(pte) |= _PAGE_WRITE;
+       return pte;
+}
+
+/* pte_mkexec - mark PTE as executable */
+static inline pte_t pte_mkexec(pte_t pte)
+{
+       pte_val(pte) |= _PAGE_EXECUTE;
+       return pte;
+}
+
+/* pte_read - "is PTE marked as readable?" */
+static inline int pte_read(pte_t pte)
+{
+       return pte_val(pte) & _PAGE_READ;
+}
+
+/* pte_write - "is PTE marked as writable?" */
+static inline int pte_write(pte_t pte)
+{
+       return pte_val(pte) & _PAGE_WRITE;
+}
+
+
+/* pte_exec - "is PTE marked as executable?" */
+static inline int pte_exec(pte_t pte)
+{
+       return pte_val(pte) & _PAGE_EXECUTE;
+}
+
+/* __pte_to_swp_entry - extract swap entry from PTE */
+#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
+
+/* __swp_entry_to_pte - extract PTE from swap entry */
+#define __swp_entry_to_pte(x) ((pte_t) { (x).val })
+
+/* pfn_pte - convert page number and protection value to page table entry */
+#define pfn_pte(pfn, pgprot) __pte((pfn << PAGE_SHIFT) | pgprot_val(pgprot))
+
+/* pte_pfn - convert pte to page frame number */
+#define pte_pfn(pte) (pte_val(pte) >> PAGE_SHIFT)
+#define set_pmd(pmdptr, pmdval) (*(pmdptr) = (pmdval))
+
+/*
+ * set_pte_at - update page table and do whatever magic may be
+ * necessary to make the underlying hardware/firmware take note.
+ *
+ * VM may require a virtual instruction to alert the MMU.
+ */
+#define set_pte_at(mm, addr, ptep, pte) set_pte(ptep, pte)
+
+/*
+ * May need to invoke the virtual machine as well...
+ */
+#define pte_unmap(pte)         do { } while (0)
+#define pte_unmap_nested(pte)  do { } while (0)
+
+/*
+ * pte_offset_map - returns the linear address of the page table entry
+ * corresponding to an address
+ */
+#define pte_offset_map(dir, address)                                    \
+       ((pte_t *)page_address(pmd_page(*(dir))) + __pte_offset(address))
+
+#define pte_offset_map_nested(pmd, addr) pte_offset_map(pmd, addr)
+
+/* pte_offset_kernel - kernel version of pte_offset */
+#define pte_offset_kernel(dir, address) \
+       ((pte_t *) (unsigned long) __va(pmd_val(*dir) & PAGE_MASK) \
+                               +  __pte_offset(address))
+
+/* ZERO_PAGE - returns the globally shared zero page */
+#define ZERO_PAGE(vaddr) (virt_to_page(&empty_zero_page))
+
+#define __pte_offset(address) (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
+
+/* Nothing special about IO remapping at this point */
+#define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \
+       remap_pfn_range(vma, vaddr, pfn, size, prot)
+
+/*  I think this is in case we have page table caches; needed by init/main.c  */
+#define pgtable_cache_init()    do { } while (0)
+
+/*
+ * Swap/file PTE definitions.  If _PAGE_PRESENT is zero, the rest of the
+ * PTE is interpreted as swap information.  Depending on the _PAGE_FILE
+ * bit, the remaining free bits are eitehr interpreted as a file offset
+ * or a swap type/offset tuple.  Rather than have the TLB fill handler
+ * test _PAGE_PRESENT, we're going to reserve the permissions bits
+ * and set them to all zeros for swap entries, which speeds up the
+ * miss handler at the cost of 3 bits of offset.  That trade-off can
+ * be revisited if necessary, but Hexagon processor architecture and
+ * target applications suggest a lot of TLB misses and not much swap space.
+ *
+ * Format of swap PTE:
+ *     bit     0:      Present (zero)
+ *     bit     1:      _PAGE_FILE (zero)
+ *     bits    2-6:    swap type (arch independent layer uses 5 bits max)
+ *     bits    7-9:    bits 2:0 of offset
+ *     bits 10-12:     effectively _PAGE_PROTNONE (all zero)
+ *     bits 13-31:  bits 21:3 of swap offset
+ *
+ * Format of file PTE:
+ *     bit     0:      Present (zero)
+ *     bit     1:      _PAGE_FILE (zero)
+ *     bits    2-9:    bits 7:0 of offset
+ *     bits 10-12:     effectively _PAGE_PROTNONE (all zero)
+ *     bits 13-31:  bits 26:8 of swap offset
+ *
+ * The split offset makes some of the following macros a little gnarly,
+ * but there's plenty of precedent for this sort of thing.
+ */
+#define PTE_FILE_MAX_BITS     27
+
+/* Used for swap PTEs */
+#define __swp_type(swp_pte)            (((swp_pte).val >> 2) & 0x1f)
+
+#define __swp_offset(swp_pte) \
+       ((((swp_pte).val >> 7) & 0x7) | (((swp_pte).val >> 10) & 0x003ffff8))
+
+#define __swp_entry(type, offset) \
+       ((swp_entry_t)  { \
+               ((type << 2) | \
+                ((offset & 0x3ffff8) << 10) | ((offset & 0x7) << 7)) })
+
+/* Used for file PTEs */
+#define pte_file(pte) \
+       ((pte_val(pte) & (_PAGE_FILE | _PAGE_PRESENT)) == _PAGE_FILE)
+
+#define pte_to_pgoff(pte) \
+       (((pte_val(pte) >> 2) & 0xff) | ((pte_val(pte) >> 5) & 0x07ffff00))
+
+#define pgoff_to_pte(off) \
+       ((pte_t) { ((((off) & 0x7ffff00) << 5) | (((off) & 0xff) << 2)\
+       | _PAGE_FILE) })
+
+/*  Oh boy.  There are a lot of possible arch overrides found in this file.  */
+#include <asm-generic/pgtable.h>
+
+#endif
diff --git a/arch/hexagon/include/asm/processor.h b/arch/hexagon/include/asm/processor.h
new file mode 100644 (file)
index 0000000..20c5dda
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * Process/processor support for the Hexagon architecture
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_PROCESSOR_H
+#define _ASM_PROCESSOR_H
+
+#ifndef __ASSEMBLY__
+
+#include <asm/mem-layout.h>
+#include <asm/registers.h>
+#include <asm/hexagon_vm.h>
+
+/*  must be a macro  */
+#define current_text_addr() ({ __label__ _l; _l: &&_l; })
+
+/*  task_struct, defined elsewhere, is the "process descriptor" */
+struct task_struct;
+
+/*  this is defined in arch/process.c  */
+extern pid_t kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
+extern unsigned long thread_saved_pc(struct task_struct *tsk);
+
+extern void start_thread(struct pt_regs *, unsigned long, unsigned long);
+
+/*
+ * thread_struct is supposed to be for context switch data.
+ * Specifically, to hold the state necessary to perform switch_to...
+ */
+struct thread_struct {
+       void *switch_sp;
+};
+
+/*
+ * initializes thread_struct
+ * The only thing we have in there is switch_sp
+ * which doesn't really need to be initialized.
+ */
+
+#define INIT_THREAD { \
+}
+
+#define cpu_relax() __vmyield()
+
+/*
+ * "Unlazying all lazy status" occurs here.
+ */
+static inline void prepare_to_copy(struct task_struct *tsk)
+{
+}
+
+/*
+ * Decides where the kernel will search for a free chunk of vm space during
+ * mmaps.
+ * See also arch_get_unmapped_area.
+ * Doesn't affect if you have MAX_FIXED in the page flags set though...
+ *
+ * Apparently the convention is that ld.so will ask for "unmapped" private
+ * memory to be allocated SOMEWHERE, but it also asks for memory explicitly
+ * via MAP_FIXED at the lower * addresses starting at VA=0x0.
+ *
+ * If the two requests collide, you get authentic segfaulting action, so
+ * you have to kick the "unmapped" base requests higher up.
+ */
+#define TASK_UNMAPPED_BASE     (PAGE_ALIGN(TASK_SIZE/3))
+
+
+#define task_pt_regs(task) \
+       ((struct pt_regs *)(task_stack_page(task) + THREAD_SIZE) - 1)
+
+#define KSTK_EIP(tsk) (pt_elr(task_pt_regs(tsk)))
+#define KSTK_ESP(tsk) (pt_psp(task_pt_regs(tsk)))
+
+/*  Free all resources held by a thread; defined in process.c  */
+extern void release_thread(struct task_struct *dead_task);
+
+/* Get wait channel for task P.  */
+extern unsigned long get_wchan(struct task_struct *p);
+
+/*  The following stuff is pretty HEXAGON specific.  */
+
+/*  This is really just here for __switch_to.
+    Offsets are pulled via asm-offsets.c  */
+
+/*
+ * No real reason why VM and native switch stacks should be different.
+ * Ultimately this should merge.  Note that Rev C. ABI called out only
+ * R24-27 as callee saved GPRs needing explicit attention (R29-31 being
+ * dealt with automagically by allocframe), but the current ABI has
+ * more, R16-R27.  By saving more, the worst case is that we waste some
+ * cycles if building with the old compilers.
+ */
+
+struct hexagon_switch_stack {
+       unsigned long long      r1716;
+       unsigned long long      r1918;
+       unsigned long long      r2120;
+       unsigned long long      r2322;
+       unsigned long long      r2524;
+       unsigned long long      r2726;
+       unsigned long           fp;
+       unsigned long           lr;
+};
+
+#endif /* !__ASSEMBLY__ */
+
+#endif
diff --git a/arch/hexagon/include/asm/ptrace.h b/arch/hexagon/include/asm/ptrace.h
new file mode 100644 (file)
index 0000000..3d2f607
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Ptrace definitions for the Hexagon architecture
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_PTRACE_H
+#define _ASM_PTRACE_H
+
+#include <asm/registers.h>
+
+#define instruction_pointer(regs) pt_elr(regs)
+#define user_stack_pointer(regs) ((regs)->r29)
+
+#define profile_pc(regs) instruction_pointer(regs)
+
+/* kprobe-based event tracer support */
+extern int regs_query_register_offset(const char *name);
+extern const char *regs_query_register_name(unsigned int offset);
+
+#endif
diff --git a/arch/hexagon/include/asm/registers.h b/arch/hexagon/include/asm/registers.h
new file mode 100644 (file)
index 0000000..4dd741b
--- /dev/null
@@ -0,0 +1,236 @@
+/*
+ * Register definitions for the Hexagon architecture
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_REGISTERS_H
+#define _ASM_REGISTERS_H
+
+#define SP r29
+
+#ifndef __ASSEMBLY__
+
+/*  See kernel/entry.S for further documentation.  */
+
+/*
+ * Entry code copies the event record out of guest registers into
+ * this structure (which is on the stack).
+ */
+
+struct hvm_event_record {
+       unsigned long vmel;     /* Event Linkage (return address) */
+       unsigned long vmest;    /* Event context - pre-event SSR values */
+       unsigned long vmpsp;    /* Previous stack pointer */
+       unsigned long vmbadva;  /* Bad virtual address for addressing events */
+};
+
+struct pt_regs {
+       long restart_r0;        /* R0 checkpoint for syscall restart */
+       long syscall_nr;        /* Only used in system calls */
+       union {
+               struct {
+                       unsigned long usr;
+                       unsigned long preds;
+               };
+               long long int predsusr;
+       };
+       union {
+               struct {
+                       unsigned long m0;
+                       unsigned long m1;
+               };
+               long long int m1m0;
+       };
+       union {
+               struct {
+                       unsigned long sa1;
+                       unsigned long lc1;
+               };
+               long long int lc1sa1;
+       };
+       union {
+               struct {
+                       unsigned long sa0;
+                       unsigned long lc0;
+               };
+               long long int lc0sa0;
+       };
+       union {
+               struct {
+                       unsigned long gp;
+                       unsigned long ugp;
+               };
+               long long int ugpgp;
+       };
+       /*
+       * Be extremely careful with rearranging these, if at all.  Some code
+       * assumes the 32 registers exist exactly like this in memory;
+       * e.g. kernel/ptrace.c
+       * e.g. kernel/signal.c (restore_sigcontext)
+       */
+       union {
+               struct {
+                       unsigned long r00;
+                       unsigned long r01;
+               };
+               long long int r0100;
+       };
+       union {
+               struct {
+                       unsigned long r02;
+                       unsigned long r03;
+               };
+               long long int r0302;
+       };
+       union {
+               struct {
+                       unsigned long r04;
+                       unsigned long r05;
+               };
+               long long int r0504;
+       };
+       union {
+               struct {
+                       unsigned long r06;
+                       unsigned long r07;
+               };
+               long long int r0706;
+       };
+       union {
+               struct {
+                       unsigned long r08;
+                       unsigned long r09;
+               };
+               long long int r0908;
+       };
+       union {
+              struct {
+                       unsigned long r10;
+                       unsigned long r11;
+              };
+              long long int r1110;
+       };
+       union {
+              struct {
+                       unsigned long r12;
+                       unsigned long r13;
+              };
+              long long int r1312;
+       };
+       union {
+              struct {
+                       unsigned long r14;
+                       unsigned long r15;
+              };
+              long long int r1514;
+       };
+       union {
+               struct {
+                       unsigned long r16;
+                       unsigned long r17;
+               };
+               long long int r1716;
+       };
+       union {
+               struct {
+                       unsigned long r18;
+                       unsigned long r19;
+               };
+               long long int r1918;
+       };
+       union {
+               struct {
+                       unsigned long r20;
+                       unsigned long r21;
+               };
+               long long int r2120;
+       };
+       union {
+               struct {
+                       unsigned long r22;
+                       unsigned long r23;
+               };
+               long long int r2322;
+       };
+       union {
+               struct {
+                       unsigned long r24;
+                       unsigned long r25;
+               };
+               long long int r2524;
+       };
+       union {
+               struct {
+                       unsigned long r26;
+                       unsigned long r27;
+               };
+               long long int r2726;
+       };
+       union {
+               struct {
+                       unsigned long r28;
+                       unsigned long r29;
+              };
+              long long int r2928;
+       };
+       union {
+               struct {
+                       unsigned long r30;
+                       unsigned long r31;
+               };
+               long long int r3130;
+       };
+       /* VM dispatch pushes event record onto stack - we can build on it */
+       struct hvm_event_record hvmer;
+};
+
+/* Defines to conveniently access the values  */
+
+/*
+ * As of the VM spec 0.5, these registers are now set/retrieved via a
+ * VM call.  On the in-bound side, we just fetch the values
+ * at the entry points and stuff them into the old record in pt_regs.
+ * However, on the outbound side, probably at VM rte, we set the
+ * registers back.
+ */
+
+#define pt_elr(regs) ((regs)->hvmer.vmel)
+#define pt_set_elr(regs, val) ((regs)->hvmer.vmel = (val))
+#define pt_cause(regs) ((regs)->hvmer.vmest & (HVM_VMEST_CAUSE_MSK))
+#define user_mode(regs) \
+       (((regs)->hvmer.vmest & (HVM_VMEST_UM_MSK << HVM_VMEST_UM_SFT)) != 0)
+#define ints_enabled(regs) \
+       (((regs)->hvmer.vmest & (HVM_VMEST_IE_MSK << HVM_VMEST_IE_SFT)) != 0)
+#define pt_psp(regs) ((regs)->hvmer.vmpsp)
+#define pt_badva(regs) ((regs)->hvmer.vmbadva)
+
+#define pt_set_rte_sp(regs, sp) do {\
+       pt_psp(regs) = (sp);\
+       (regs)->SP = (unsigned long) &((regs)->hvmer);\
+       } while (0)
+
+#define pt_set_kmode(regs) \
+       (regs)->hvmer.vmest = (HVM_VMEST_IE_MSK << HVM_VMEST_IE_SFT)
+
+#define pt_set_usermode(regs) \
+       (regs)->hvmer.vmest = (HVM_VMEST_UM_MSK << HVM_VMEST_UM_SFT) \
+                           | (HVM_VMEST_IE_MSK << HVM_VMEST_IE_SFT)
+
+#endif  /*  ifndef __ASSEMBLY  */
+
+#endif
diff --git a/arch/hexagon/include/asm/setup.h b/arch/hexagon/include/asm/setup.h
new file mode 100644 (file)
index 0000000..3b754c5
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_SETUP_H
+#define _ASM_SETUP_H
+
+#include <linux/init.h>
+#include <asm-generic/setup.h>
+
+extern char external_cmdline_buffer;
+
+void __init setup_arch_memory(void);
+
+#endif
diff --git a/arch/hexagon/include/asm/sigcontext.h b/arch/hexagon/include/asm/sigcontext.h
new file mode 100644 (file)
index 0000000..ce6dcd9
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_SIGCONTEXT_H
+#define _ASM_SIGCONTEXT_H
+
+#include <asm/user.h>
+
+/*
+ * Signal context structure - contains all info to do with the state
+ * before the signal handler was invoked.  Note: only add new entries
+ * to the end of the structure.
+ */
+struct sigcontext {
+       struct user_regs_struct sc_regs;
+} __aligned(8);
+
+#endif
diff --git a/arch/hexagon/include/asm/signal.h b/arch/hexagon/include/asm/signal.h
new file mode 100644 (file)
index 0000000..471c056
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_SIGNAL_H
+#define _ASM_SIGNAL_H
+
+extern unsigned long __rt_sigtramp_template[2];
+
+#include <asm-generic/signal.h>
+
+#endif
diff --git a/arch/hexagon/include/asm/smp.h b/arch/hexagon/include/asm/smp.h
new file mode 100644 (file)
index 0000000..87c869a
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * SMP definitions for the Hexagon architecture
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef __ASM_SMP_H
+#define __ASM_SMP_H
+
+#include <linux/cpumask.h>
+
+#define raw_smp_processor_id() (current_thread_info()->cpu)
+
+enum ipi_message_type {
+       IPI_NOP = 0,
+       IPI_RESCHEDULE = 1,
+       IPI_CALL_FUNC,
+       IPI_CALL_FUNC_SINGLE,
+       IPI_CPU_STOP,
+       IPI_TIMER,
+};
+
+extern void send_ipi(const struct cpumask *cpumask, enum ipi_message_type msg);
+extern void smp_start_cpus(void);
+extern void arch_send_call_function_single_ipi(int cpu);
+extern void arch_send_call_function_ipi_mask(const struct cpumask *mask);
+
+extern void smp_vm_unmask_irq(void *info);
+
+#endif
diff --git a/arch/hexagon/include/asm/spinlock.h b/arch/hexagon/include/asm/spinlock.h
new file mode 100644 (file)
index 0000000..168a920
--- /dev/null
@@ -0,0 +1,186 @@
+/*
+ * Spinlock support for the Hexagon architecture
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_SPINLOCK_H
+#define _ASM_SPINLOCK_H
+
+#include <asm/irqflags.h>
+
+/*
+ * This file is pulled in for SMP builds.
+ * Really need to check all the barrier stuff for "true" SMP
+ */
+
+/*
+ * Read locks:
+ * - load the lock value
+ * - increment it
+ * - if the lock value is still negative, go back and try again.
+ * - unsuccessful store is unsuccessful.  Go back and try again.  Loser.
+ * - successful store new lock value if positive -> lock acquired
+ */
+static inline void arch_read_lock(arch_rwlock_t *lock)
+{
+       __asm__ __volatile__(
+               "1:     R6 = memw_locked(%0);\n"
+               "       { P3 = cmp.ge(R6,#0); R6 = add(R6,#1);}\n"
+               "       { if !P3 jump 1b; }\n"
+               "       memw_locked(%0,P3) = R6;\n"
+               "       { if !P3 jump 1b; }\n"
+               :
+               : "r" (&lock->lock)
+               : "memory", "r6", "p3"
+       );
+
+}
+
+static inline void arch_read_unlock(arch_rwlock_t *lock)
+{
+       __asm__ __volatile__(
+               "1:     R6 = memw_locked(%0);\n"
+               "       R6 = add(R6,#-1);\n"
+               "       memw_locked(%0,P3) = R6\n"
+               "       if !P3 jump 1b;\n"
+               :
+               : "r" (&lock->lock)
+               : "memory", "r6", "p3"
+       );
+
+}
+
+/*  I think this returns 0 on fail, 1 on success.  */
+static inline int arch_read_trylock(arch_rwlock_t *lock)
+{
+       int temp;
+       __asm__ __volatile__(
+               "       R6 = memw_locked(%1);\n"
+               "       { %0 = #0; P3 = cmp.ge(R6,#0); R6 = add(R6,#1);}\n"
+               "       { if !P3 jump 1f; }\n"
+               "       memw_locked(%1,P3) = R6;\n"
+               "       { %0 = P3 }\n"
+               "1:\n"
+               : "=&r" (temp)
+               : "r" (&lock->lock)
+               : "memory", "r6", "p3"
+       );
+       return temp;
+}
+
+static inline int arch_read_can_lock(arch_rwlock_t *rwlock)
+{
+       return rwlock->lock == 0;
+}
+
+static inline int arch_write_can_lock(arch_rwlock_t *rwlock)
+{
+       return rwlock->lock == 0;
+}
+
+/*  Stuffs a -1 in the lock value?  */
+static inline void arch_write_lock(arch_rwlock_t *lock)
+{
+       __asm__ __volatile__(
+               "1:     R6 = memw_locked(%0)\n"
+               "       { P3 = cmp.eq(R6,#0);  R6 = #-1;}\n"
+               "       { if !P3 jump 1b; }\n"
+               "       memw_locked(%0,P3) = R6;\n"
+               "       { if !P3 jump 1b; }\n"
+               :
+               : "r" (&lock->lock)
+               : "memory", "r6", "p3"
+       );
+}
+
+
+static inline int arch_write_trylock(arch_rwlock_t *lock)
+{
+       int temp;
+       __asm__ __volatile__(
+               "       R6 = memw_locked(%1)\n"
+               "       { %0 = #0; P3 = cmp.eq(R6,#0);  R6 = #-1;}\n"
+               "       { if !P3 jump 1f; }\n"
+               "       memw_locked(%1,P3) = R6;\n"
+               "       %0 = P3;\n"
+               "1:\n"
+               : "=&r" (temp)
+               : "r" (&lock->lock)
+               : "memory", "r6", "p3"
+       );
+       return temp;
+
+}
+
+static inline void arch_write_unlock(arch_rwlock_t *lock)
+{
+       smp_mb();
+       lock->lock = 0;
+}
+
+static inline void arch_spin_lock(arch_spinlock_t *lock)
+{
+       __asm__ __volatile__(
+               "1:     R6 = memw_locked(%0);\n"
+               "       P3 = cmp.eq(R6,#0);\n"
+               "       { if !P3 jump 1b; R6 = #1; }\n"
+               "       memw_locked(%0,P3) = R6;\n"
+               "       { if !P3 jump 1b; }\n"
+               :
+               : "r" (&lock->lock)
+               : "memory", "r6", "p3"
+       );
+
+}
+
+static inline void arch_spin_unlock(arch_spinlock_t *lock)
+{
+       smp_mb();
+       lock->lock = 0;
+}
+
+static inline unsigned int arch_spin_trylock(arch_spinlock_t *lock)
+{
+       int temp;
+       __asm__ __volatile__(
+               "       R6 = memw_locked(%1);\n"
+               "       P3 = cmp.eq(R6,#0);\n"
+               "       { if !P3 jump 1f; R6 = #1; %0 = #0; }\n"
+               "       memw_locked(%1,P3) = R6;\n"
+               "       %0 = P3;\n"
+               "1:\n"
+               : "=&r" (temp)
+               : "r" (&lock->lock)
+               : "memory", "r6", "p3"
+       );
+       return temp;
+}
+
+/*
+ * SMP spinlocks are intended to allow only a single CPU at the lock
+ */
+#define arch_spin_lock_flags(lock, flags) arch_spin_lock(lock)
+#define arch_spin_unlock_wait(lock) \
+       do {while (arch_spin_is_locked(lock)) cpu_relax(); } while (0)
+#define arch_spin_is_locked(x) ((x)->lock != 0)
+
+#define arch_read_lock_flags(lock, flags) arch_read_lock(lock)
+#define arch_write_lock_flags(lock, flags) arch_write_lock(lock)
+
+#endif
diff --git a/arch/hexagon/include/asm/spinlock_types.h b/arch/hexagon/include/asm/spinlock_types.h
new file mode 100644 (file)
index 0000000..5e937af
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Spinlock support for the Hexagon architecture
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_SPINLOCK_TYPES_H
+#define _ASM_SPINLOCK_TYPES_H
+
+#include <linux/version.h>
+
+#ifndef __LINUX_SPINLOCK_TYPES_H
+# error "please don't include this file directly"
+#endif
+
+typedef struct {
+       volatile unsigned int lock;
+} arch_spinlock_t;
+
+#define __ARCH_SPIN_LOCK_UNLOCKED      { 0 }
+
+typedef struct {
+       volatile unsigned int lock;
+} arch_rwlock_t;
+
+#define __ARCH_RW_LOCK_UNLOCKED                { 0 }
+
+#endif
diff --git a/arch/hexagon/include/asm/string.h b/arch/hexagon/include/asm/string.h
new file mode 100644 (file)
index 0000000..f4489c1
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_STRING_H_
+#define _ASM_STRING_H_
+
+#ifdef __KERNEL__
+#define __HAVE_ARCH_MEMCPY
+extern void *memcpy(void *__to, __const__ void *__from, size_t __n);
+
+/*  ToDo:  use dczeroa, accelerate the compiler-constant zero case  */
+#define __HAVE_ARCH_MEMSET
+extern void *memset(void *__to, int c, size_t __n);
+#endif
+
+
+#endif /* _ASM_STRING_H_ */
diff --git a/arch/hexagon/include/asm/suspend.h b/arch/hexagon/include/asm/suspend.h
new file mode 100644 (file)
index 0000000..089dd82
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_SUSPEND_H
+#define _ASM_SUSPEND_H
+
+static inline int arch_prepare_suspend(void)
+{
+       return 0;
+}
+
+#endif
diff --git a/arch/hexagon/include/asm/swab.h b/arch/hexagon/include/asm/swab.h
new file mode 100644 (file)
index 0000000..99cf0be
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_SWAB_H
+#define _ASM_SWAB_H
+
+#define __SWAB_64_THRU_32__
+
+#endif
diff --git a/arch/hexagon/include/asm/syscall.h b/arch/hexagon/include/asm/syscall.h
new file mode 100644 (file)
index 0000000..3e7d61d
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Syscall support for the Hexagon architecture
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_HEXAGON_SYSCALL_H
+#define _ASM_HEXAGON_SYSCALL_H
+
+typedef long (*syscall_fn)(unsigned long, unsigned long,
+       unsigned long, unsigned long,
+       unsigned long, unsigned long);
+
+asmlinkage int sys_execve(char __user *ufilename, char __user * __user *argv,
+                         char __user * __user *envp);
+asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
+                        unsigned long parent_tidp, unsigned long child_tidp);
+
+#define sys_execve     sys_execve
+#define sys_clone      sys_clone
+
+#include <asm-generic/syscalls.h>
+
+extern void *sys_call_table[];
+
+static inline long syscall_get_nr(struct task_struct *task,
+                                 struct pt_regs *regs)
+{
+       return regs->r06;
+}
+
+static inline void syscall_get_arguments(struct task_struct *task,
+                                        struct pt_regs *regs,
+                                        unsigned int i, unsigned int n,
+                                        unsigned long *args)
+{
+       BUG_ON(i + n > 6);
+       memcpy(args, &(&regs->r00)[i], n * sizeof(args[0]));
+}
+#endif
diff --git a/arch/hexagon/include/asm/system.h b/arch/hexagon/include/asm/system.h
new file mode 100644 (file)
index 0000000..323ed1d
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+ * System level definitions for the Hexagon architecture
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_SYSTEM_H
+#define _ASM_SYSTEM_H
+
+#include <linux/linkage.h>
+#include <linux/irqflags.h>
+#include <asm/atomic.h>
+#include <asm/hexagon_vm.h>
+
+struct thread_struct;
+
+extern struct task_struct *__switch_to(struct task_struct *,
+       struct task_struct *,
+       struct task_struct *);
+
+#define switch_to(p, n, r) do {\
+       r = __switch_to((p), (n), (r));\
+} while (0)
+
+
+#define rmb()                          barrier()
+#define read_barrier_depends()         barrier()
+#define wmb()                          barrier()
+#define mb()                           barrier()
+#define smp_rmb()                      barrier()
+#define smp_read_barrier_depends()     barrier()
+#define smp_wmb()                      barrier()
+#define smp_mb()                       barrier()
+#define smp_mb__before_atomic_dec()    barrier()
+#define smp_mb__after_atomic_dec()     barrier()
+#define smp_mb__before_atomic_inc()    barrier()
+#define smp_mb__after_atomic_inc()     barrier()
+
+/*
+ * __xchg - atomically exchange a register and a memory location
+ * @x: value to swap
+ * @ptr: pointer to memory
+ * @size:  size of the value
+ *
+ * Only 4 bytes supported currently.
+ *
+ * Note:  there was an errata for V2 about .new's and memw_locked.
+ *
+ */
+static inline unsigned long __xchg(unsigned long x, volatile void *ptr,
+                                  int size)
+{
+       unsigned long retval;
+
+       /*  Can't seem to use printk or panic here, so just stop  */
+       if (size != 4) do { asm volatile("brkpt;\n"); } while (1);
+
+       __asm__ __volatile__ (
+       "1:     %0 = memw_locked(%1);\n"    /*  load into retval */
+       "       memw_locked(%1,P0) = %2;\n" /*  store into memory */
+       "       if !P0 jump 1b;\n"
+       : "=&r" (retval)
+       : "r" (ptr), "r" (x)
+       : "memory", "p0"
+       );
+       return retval;
+}
+
+/*
+ * Atomically swap the contents of a register with memory.  Should be atomic
+ * between multiple CPU's and within interrupts on the same CPU.
+ */
+#define xchg(ptr, v) ((__typeof__(*(ptr)))__xchg((unsigned long)(v), (ptr), \
+       sizeof(*(ptr))))
+
+/*  Set a value and use a memory barrier.  Used by the scheduler somewhere.  */
+#define set_mb(var, value) \
+       do { var = value; mb(); } while (0)
+
+/*
+ *  see rt-mutex-design.txt; cmpxchg supposedly checks if *ptr == A and swaps.
+ *  looks just like atomic_cmpxchg on our arch currently with a bunch of
+ *  variable casting.
+ */
+#define __HAVE_ARCH_CMPXCHG 1
+
+#define cmpxchg(ptr, old, new)                                 \
+({                                                             \
+       __typeof__(ptr) __ptr = (ptr);                          \
+       __typeof__(*(ptr)) __old = (old);                       \
+       __typeof__(*(ptr)) __new = (new);                       \
+       __typeof__(*(ptr)) __oldval = 0;                        \
+                                                               \
+       asm volatile(                                           \
+               "1:     %0 = memw_locked(%1);\n"                \
+               "       { P0 = cmp.eq(%0,%2);\n"                \
+               "         if (!P0.new) jump:nt 2f; }\n"         \
+               "       memw_locked(%1,p0) = %3;\n"             \
+               "       if (!P0) jump 1b;\n"                    \
+               "2:\n"                                          \
+               : "=&r" (__oldval)                              \
+               : "r" (__ptr), "r" (__old), "r" (__new)         \
+               : "memory", "p0"                                \
+       );                                                      \
+       __oldval;                                               \
+})
+
+/*  Should probably shoot for an 8-byte aligned stack pointer  */
+#define STACK_MASK (~7)
+#define arch_align_stack(x) (x & STACK_MASK)
+
+#endif
diff --git a/arch/hexagon/include/asm/thread_info.h b/arch/hexagon/include/asm/thread_info.h
new file mode 100644 (file)
index 0000000..9c2934f
--- /dev/null
@@ -0,0 +1,154 @@
+/*
+ * Thread support for the Hexagon architecture
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_THREAD_INFO_H
+#define _ASM_THREAD_INFO_H
+
+#ifdef __KERNEL__
+
+#ifndef __ASSEMBLY__
+#include <asm/processor.h>
+#include <asm/registers.h>
+#include <asm/page.h>
+#endif
+
+#define THREAD_SHIFT           12
+#define THREAD_SIZE            (1<<THREAD_SHIFT)
+
+#if THREAD_SHIFT >= PAGE_SHIFT
+#define THREAD_SIZE_ORDER      (THREAD_SHIFT - PAGE_SHIFT)
+#else  /*  don't use standard allocator  */
+#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
+extern struct thread_info *alloc_thread_info_node(struct task_struct *tsk, int node);
+extern void free_thread_info(struct thread_info *ti);
+#endif
+
+
+#ifndef __ASSEMBLY__
+
+typedef struct {
+       unsigned long seg;
+} mm_segment_t;
+
+/*
+ * This is union'd with the "bottom" of the kernel stack.
+ * It keeps track of thread info which is handy for routines
+ * to access quickly.
+ */
+
+struct thread_info {
+       struct task_struct      *task;          /* main task structure */
+       struct exec_domain      *exec_domain;   /* execution domain */
+       unsigned long           flags;          /* low level flags */
+       __u32                   cpu;            /* current cpu */
+       int                     preempt_count;  /* 0=>preemptible,<0=>BUG */
+       mm_segment_t            addr_limit;     /* segmentation sux */
+       /*
+        * used for syscalls somehow;
+        * seems to have a function pointer and four arguments
+        */
+       struct restart_block    restart_block;
+       /* Points to the current pt_regs frame  */
+       struct pt_regs          *regs;
+       /*
+        * saved kernel sp at switch_to time;
+        * not sure if this is used (it's not in the VM model it seems;
+        * see thread_struct)
+        */
+       unsigned long           sp;
+};
+
+#else /* !__ASSEMBLY__ */
+
+#include <asm/asm-offsets.h>
+
+#endif  /* __ASSEMBLY__  */
+
+/*  looks like "linux/hardirq.h" uses this.  */
+
+#define PREEMPT_ACTIVE         0x10000000
+
+#ifndef __ASSEMBLY__
+
+#define INIT_THREAD_INFO(tsk)                   \
+{                                               \
+       .task           = &tsk,                 \
+       .exec_domain    = &default_exec_domain, \
+       .flags          = 0,                    \
+       .cpu            = 0,                    \
+       .preempt_count  = 1,                    \
+       .addr_limit     = KERNEL_DS,            \
+       .restart_block = {                      \
+               .fn = do_no_restart_syscall,    \
+       },                                      \
+       .sp = 0,                                \
+       .regs = NULL,                   \
+}
+
+#define init_thread_info        (init_thread_union.thread_info)
+#define init_stack              (init_thread_union.stack)
+
+/* Tacky preprocessor trickery */
+#define        qqstr(s) qstr(s)
+#define qstr(s) #s
+#define QUOTED_THREADINFO_REG qqstr(THREADINFO_REG)
+
+register struct thread_info *__current_thread_info asm(QUOTED_THREADINFO_REG);
+#define current_thread_info()  __current_thread_info
+
+#endif /* __ASSEMBLY__ */
+
+/*
+ * thread information flags
+ * - these are process state flags that various assembly files
+ *   may need to access
+ * - pending work-to-be-done flags are in LSW
+ * - other flags in MSW
+ */
+
+#define TIF_SYSCALL_TRACE       0       /* syscall trace active */
+#define TIF_NOTIFY_RESUME       1       /* resumption notification requested */
+#define TIF_SIGPENDING          2       /* signal pending */
+#define TIF_NEED_RESCHED        3       /* rescheduling necessary */
+#define TIF_SINGLESTEP          4       /* restore ss @ return to usr mode */
+#define TIF_IRET                5       /* return with iret */
+#define TIF_RESTORE_SIGMASK     6       /* restore sig mask in do_signal() */
+/* true if poll_idle() is polling TIF_NEED_RESCHED */
+#define TIF_POLLING_NRFLAG      16
+#define TIF_MEMDIE              17      /* OOM killer killed process */
+
+#define _TIF_SYSCALL_TRACE      (1 << TIF_SYSCALL_TRACE)
+#define _TIF_NOTIFY_RESUME      (1 << TIF_NOTIFY_RESUME)
+#define _TIF_SIGPENDING         (1 << TIF_SIGPENDING)
+#define _TIF_NEED_RESCHED       (1 << TIF_NEED_RESCHED)
+#define _TIF_SINGLESTEP         (1 << TIF_SINGLESTEP)
+#define _TIF_IRET               (1 << TIF_IRET)
+#define _TIF_RESTORE_SIGMASK    (1 << TIF_RESTORE_SIGMASK)
+#define _TIF_POLLING_NRFLAG     (1 << TIF_POLLING_NRFLAG)
+
+/* work to do on interrupt/exception return - All but TIF_SYSCALL_TRACE */
+#define _TIF_WORK_MASK          (0x0000FFFF & ~_TIF_SYSCALL_TRACE)
+
+/* work to do on any return to u-space */
+#define _TIF_ALLWORK_MASK       0x0000FFFF
+
+#endif /* __KERNEL__ */
+
+#endif
diff --git a/arch/hexagon/include/asm/time.h b/arch/hexagon/include/asm/time.h
new file mode 100644 (file)
index 0000000..081b82c
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef ASM_TIME_H
+#define ASM_TIME_H
+
+extern cycles_t        pcycle_freq_mhz;
+extern cycles_t        thread_freq_mhz;
+extern cycles_t        sleep_clk_freq;
+
+void setup_percpu_clockdev(void);
+void ipi_timer(void);
+
+#endif
diff --git a/arch/hexagon/include/asm/timer-regs.h b/arch/hexagon/include/asm/timer-regs.h
new file mode 100644 (file)
index 0000000..d80db23
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Timer support for Hexagon
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_TIMER_REGS_H
+#define _ASM_TIMER_REGS_H
+
+/*  This stuff should go into a platform specific file  */
+#define TCX0_CLK_RATE          19200
+#define TIMER_ENABLE           0
+#define TIMER_CLR_ON_MATCH     1
+
+/*
+ * 8x50 HDD Specs 5-8.  Simulator co-sim not fixed until
+ * release 1.1, and then it's "adjustable" and probably not defaulted.
+ */
+#define RTOS_TIMER_INT         3
+#ifdef CONFIG_HEXAGON_COMET
+#define RTOS_TIMER_REGS_ADDR   0xAB000000UL
+#endif
+#define SLEEP_CLK_RATE         32000
+
+#endif
diff --git a/arch/hexagon/include/asm/timex.h b/arch/hexagon/include/asm/timex.h
new file mode 100644 (file)
index 0000000..b11c62b
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_TIMEX_H
+#define _ASM_TIMEX_H
+
+#include <asm-generic/timex.h>
+#include <asm/timer-regs.h>
+
+/* Using TCX0 as our clock.  CLOCK_TICK_RATE scheduled to be removed. */
+#define CLOCK_TICK_RATE              TCX0_CLK_RATE
+
+#define ARCH_HAS_READ_CURRENT_TIMER
+
+static inline int read_current_timer(unsigned long *timer_val)
+{
+       *timer_val = (unsigned long) __vmgettime();
+       return 0;
+}
+
+#endif
diff --git a/arch/hexagon/include/asm/tlb.h b/arch/hexagon/include/asm/tlb.h
new file mode 100644 (file)
index 0000000..473abde
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_TLB_H
+#define _ASM_TLB_H
+
+#include <linux/pagemap.h>
+#include <asm/tlbflush.h>
+
+/*
+ * We don't need any special per-pte or per-vma handling...
+ */
+#define tlb_start_vma(tlb, vma)                                do { } while (0)
+#define tlb_end_vma(tlb, vma)                          do { } while (0)
+#define __tlb_remove_tlb_entry(tlb, ptep, address)     do { } while (0)
+
+/*
+ * .. because we flush the whole mm when it fills up
+ */
+#define tlb_flush(tlb)         flush_tlb_mm((tlb)->mm)
+
+#include <asm-generic/tlb.h>
+
+#endif
diff --git a/arch/hexagon/include/asm/tlbflush.h b/arch/hexagon/include/asm/tlbflush.h
new file mode 100644 (file)
index 0000000..b89a902
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * TLB flush support for Hexagon
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_TLBFLUSH_H
+#define _ASM_TLBFLUSH_H
+
+#include <linux/mm.h>
+#include <asm/processor.h>
+
+/*
+ * TLB flushing -- in "SMP", these routines get defined to be the
+ * ones from smp.c, else they are some local flavors.
+ */
+
+/*
+ * These functions are commonly macros, but in the interests of
+ * VM vs. native implementation and code size, we simply declare
+ * the function prototypes here.
+ */
+extern void tlb_flush_all(void);
+extern void flush_tlb_mm(struct mm_struct *mm);
+extern void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr);
+extern void flush_tlb_range(struct vm_area_struct *vma,
+                               unsigned long start, unsigned long end);
+extern void flush_tlb_kernel_range(unsigned long start, unsigned long end);
+extern void flush_tlb_one(unsigned long);
+
+/*
+ * "This is called in munmap when we have freed up some page-table pages.
+ * We don't need to do anything here..."
+ *
+ * The VM kernel doesn't walk page tables, and they are passed to the VMM
+ * by logical address. There doesn't seem to be any possibility that they
+ * could be referenced by the VM kernel based on a stale mapping, since
+ * they would only be located by consulting the mm structure, and they
+ * will have been purged from that structure by the munmap.  Seems like
+ * a noop on HVM as well.
+ */
+#define flush_tlb_pgtables(mm, start, end)
+
+#endif
diff --git a/arch/hexagon/include/asm/traps.h b/arch/hexagon/include/asm/traps.h
new file mode 100644 (file)
index 0000000..6a407f6
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Trap support for Hexagon
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_HEXAGON_TRAPS_H
+#define _ASM_HEXAGON_TRAPS_H
+
+#include <asm/registers.h>
+
+extern int die(const char *str, struct pt_regs *regs, long err);
+extern int die_if_kernel(char *str, struct pt_regs *regs, long err);
+
+#endif /* _ASM_HEXAGON_TRAPS_H */
diff --git a/arch/hexagon/include/asm/uaccess.h b/arch/hexagon/include/asm/uaccess.h
new file mode 100644 (file)
index 0000000..7e706ea
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * User memory access support for Hexagon
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_UACCESS_H
+#define _ASM_UACCESS_H
+/*
+ * User space memory access functions
+ */
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <asm/segment.h>
+#include <asm/sections.h>
+
+/*
+ * access_ok: - Checks if a user space pointer is valid
+ * @type: Type of access: %VERIFY_READ or %VERIFY_WRITE.  Note that
+ *        %VERIFY_WRITE is a superset of %VERIFY_READ - if it is safe
+ *        to write to a block, it is always safe to read from it.
+ * @addr: User space pointer to start of block to check
+ * @size: Size of block to check
+ *
+ * Context: User context only.  This function may sleep.
+ *
+ * Checks if a pointer to a block of memory in user space is valid.
+ *
+ * Returns true (nonzero) if the memory block *may* be valid, false (zero)
+ * if it is definitely invalid.
+ *
+ * User address space in Hexagon, like x86, goes to 0xbfffffff, so the
+ * simple MSB-based tests used by MIPS won't work.  Some further
+ * optimization is probably possible here, but for now, keep it
+ * reasonably simple and not *too* slow.  After all, we've got the
+ * MMU for backup.
+ */
+#define VERIFY_READ     0
+#define VERIFY_WRITE    1
+
+#define __access_ok(addr, size) \
+       ((get_fs().seg == KERNEL_DS.seg) || \
+       (((unsigned long)addr < get_fs().seg) && \
+         (unsigned long)size < (get_fs().seg - (unsigned long)addr)))
+
+/*
+ * When a kernel-mode page fault is taken, the faulting instruction
+ * address is checked against a table of exception_table_entries.
+ * Each entry is a tuple of the address of an instruction that may
+ * be authorized to fault, and the address at which execution should
+ * be resumed instead of the faulting instruction, so as to effect
+ * a workaround.
+ */
+
+/*  Assembly somewhat optimized copy routines  */
+unsigned long __copy_from_user_hexagon(void *to, const void __user *from,
+                                    unsigned long n);
+unsigned long __copy_to_user_hexagon(void __user *to, const void *from,
+                                  unsigned long n);
+
+#define __copy_from_user(to, from, n) __copy_from_user_hexagon(to, from, n)
+#define __copy_to_user(to, from, n) __copy_to_user_hexagon(to, from, n)
+
+/*
+ * XXX todo: some additonal performance gain is possible by
+ * implementing __copy_to/from_user_inatomic, which is much
+ * like __copy_to/from_user, but performs slightly less checking.
+ */
+
+__kernel_size_t __clear_user_hexagon(void __user *dest, unsigned long count);
+#define __clear_user(a, s) __clear_user_hexagon((a), (s))
+
+#define __strncpy_from_user(dst, src, n) hexagon_strncpy_from_user(dst, src, n)
+
+/*  get around the ifndef in asm-generic/uaccess.h  */
+#define __strnlen_user __strnlen_user
+
+extern long __strnlen_user(const char __user *src, long n);
+
+static inline long hexagon_strncpy_from_user(char *dst, const char __user *src,
+                                            long n);
+
+#include <asm-generic/uaccess.h>
+
+/*  Todo:  an actual accelerated version of this.  */
+static inline long hexagon_strncpy_from_user(char *dst, const char __user *src,
+                                            long n)
+{
+       long res = __strnlen_user(src, n);
+
+       /* return from strnlen can't be zero -- that would be rubbish. */
+
+       if (res > n) {
+               copy_from_user(dst, src, n);
+               return n;
+       } else {
+               copy_from_user(dst, src, res);
+               return res-1;
+       }
+}
+
+#endif
diff --git a/arch/hexagon/include/asm/unistd.h b/arch/hexagon/include/asm/unistd.h
new file mode 100644 (file)
index 0000000..4d0ecde
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Syscall support for Hexagon
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#if !defined(_ASM_HEXAGON_UNISTD_H) || defined(__SYSCALL)
+#define _ASM_HEXAGON_UNISTD_H
+
+/*
+ *  The kernel pulls this unistd.h in three different ways:
+ *  1.  the "normal" way which gets all the __NR defines
+ *  2.  with __SYSCALL defined to produce function declarations
+ *  3.  with __SYSCALL defined to produce syscall table initialization
+ *  See also:  syscalltab.c
+ */
+
+#define sys_mmap2 sys_mmap_pgoff
+
+#include <asm-generic/unistd.h>
+
+#endif
diff --git a/arch/hexagon/include/asm/user.h b/arch/hexagon/include/asm/user.h
new file mode 100644 (file)
index 0000000..3a55078
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef HEXAGON_ASM_USER_H
+#define HEXAGON_ASM_USER_H
+
+/*
+ * Layout for registers passed in elf core dumps to userspace.
+ *
+ * Basically a rearranged subset of "pt_regs".
+ *
+ * Interested parties:  libc, gdb...
+ */
+
+struct user_regs_struct {
+       unsigned long r0;
+       unsigned long r1;
+       unsigned long r2;
+       unsigned long r3;
+       unsigned long r4;
+       unsigned long r5;
+       unsigned long r6;
+       unsigned long r7;
+       unsigned long r8;
+       unsigned long r9;
+       unsigned long r10;
+       unsigned long r11;
+       unsigned long r12;
+       unsigned long r13;
+       unsigned long r14;
+       unsigned long r15;
+       unsigned long r16;
+       unsigned long r17;
+       unsigned long r18;
+       unsigned long r19;
+       unsigned long r20;
+       unsigned long r21;
+       unsigned long r22;
+       unsigned long r23;
+       unsigned long r24;
+       unsigned long r25;
+       unsigned long r26;
+       unsigned long r27;
+       unsigned long r28;
+       unsigned long r29;
+       unsigned long r30;
+       unsigned long r31;
+       unsigned long sa0;
+       unsigned long lc0;
+       unsigned long sa1;
+       unsigned long lc1;
+       unsigned long m0;
+       unsigned long m1;
+       unsigned long usr;
+       unsigned long p3_0;
+       unsigned long gp;
+       unsigned long ugp;
+       unsigned long pc;
+       unsigned long cause;
+       unsigned long badva;
+       unsigned long pad1;  /* pad out to 48 words total */
+       unsigned long pad2;  /* pad out to 48 words total */
+       unsigned long pad3;  /* pad out to 48 words total */
+};
+
+#endif
diff --git a/arch/hexagon/include/asm/vdso.h b/arch/hexagon/include/asm/vdso.h
new file mode 100644 (file)
index 0000000..2d95cbb
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * vDSO implementation for Hexagon
+ *
+ * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef __ASM_VDSO_H
+#define __ASM_VDSO_H
+
+#include <linux/types.h>
+
+struct hexagon_vdso {
+       u32 rt_signal_trampoline[2];
+};
+
+#endif /* __ASM_VDSO_H */
diff --git a/arch/hexagon/include/asm/vm_fault.h b/arch/hexagon/include/asm/vm_fault.h
new file mode 100644 (file)
index 0000000..cacda36
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_HEXAGON_VM_FAULT_H
+#define _ASM_HEXAGON_VM_FAULT_H
+
+extern void execute_protection_fault(struct pt_regs *);
+extern void write_protection_fault(struct pt_regs *);
+extern void read_protection_fault(struct pt_regs *);
+
+#endif
diff --git a/arch/hexagon/include/asm/vm_mmu.h b/arch/hexagon/include/asm/vm_mmu.h
new file mode 100644 (file)
index 0000000..580462d
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * Hexagon VM page table entry definitions
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef _ASM_VM_MMU_H
+#define _ASM_VM_MMU_H
+
+/*
+ * Shift, mask, and other constants for the Hexagon Virtual Machine
+ * page tables.
+ *
+ * Virtual machine MMU allows first-level entries to either be
+ * single-level lookup PTEs for very large pages, or PDEs pointing
+ * to second-level PTEs for smaller pages. If PTE is single-level,
+ * the least significant bits cannot be used as software bits to encode
+ * virtual memory subsystem information about the page, and that state
+ * must be maintained in some parallel data structure.
+ */
+
+/* S or Page Size field in PDE */
+#define        __HVM_PDE_S             (0x7 << 0)
+#define __HVM_PDE_S_4KB                0
+#define __HVM_PDE_S_16KB       1
+#define __HVM_PDE_S_64KB       2
+#define __HVM_PDE_S_256KB      3
+#define __HVM_PDE_S_1MB                4
+#define __HVM_PDE_S_4MB                5
+#define __HVM_PDE_S_16MB       6
+#define __HVM_PDE_S_INVALID    7
+
+/* Masks for L2 page table pointer, as function of page size */
+#define __HVM_PDE_PTMASK_4KB   0xfffff000
+#define __HVM_PDE_PTMASK_16KB  0xfffffc00
+#define __HVM_PDE_PTMASK_64KB  0xffffff00
+#define __HVM_PDE_PTMASK_256KB 0xffffffc0
+#define __HVM_PDE_PTMASK_1MB   0xfffffff0
+
+/*
+ * Virtual Machine PTE Bits/Fields
+ */
+#define __HVM_PTE_T            (1<<4)
+#define __HVM_PTE_U            (1<<5)
+#define        __HVM_PTE_C             (0x7<<6)
+#define __HVM_PTE_CVAL(pte)    (((pte) & __HVM_PTE_C) >> 6)
+#define __HVM_PTE_R            (1<<9)
+#define __HVM_PTE_W            (1<<10)
+#define __HVM_PTE_X            (1<<11)
+
+/*
+ * Cache Attributes, to be shifted as necessary for virtual/physical PTEs
+ */
+
+#define __HEXAGON_C_WB         0x0     /* Write-back, no L2 */
+#define        __HEXAGON_C_WT          0x1     /* Write-through, no L2 */
+#define        __HEXAGON_C_DEV         0x4     /* Device register space */
+#define        __HEXAGON_C_WT_L2       0x5     /* Write-through, with L2 */
+/* this really should be #if CONFIG_HEXAGON_ARCH = 2 but that's not defined */
+#if defined(CONFIG_HEXAGON_COMET) || defined(CONFIG_QDSP6_ST1)
+#define __HEXAGON_C_UNC                __HEXAGON_C_DEV
+#else
+#define        __HEXAGON_C_UNC         0x6     /* Uncached memory */
+#endif
+#define        __HEXAGON_C_WB_L2       0x7     /* Write-back, with L2 */
+
+/*
+ * This can be overriden, but we're defaulting to the most aggressive
+ * cache policy, the better to find bugs sooner.
+ */
+
+#define        CACHE_DEFAULT   __HEXAGON_C_WB_L2
+
+/* Masks for physical page address, as a function of page size */
+
+#define __HVM_PTE_PGMASK_4KB   0xfffff000
+#define __HVM_PTE_PGMASK_16KB  0xffffc000
+#define __HVM_PTE_PGMASK_64KB  0xffff0000
+#define __HVM_PTE_PGMASK_256KB 0xfffc0000
+#define __HVM_PTE_PGMASK_1MB   0xfff00000
+
+/* Masks for single-level large page lookups */
+
+#define __HVM_PTE_PGMASK_4MB   0xffc00000
+#define __HVM_PTE_PGMASK_16MB  0xff000000
+
+/*
+ * "Big kernel page mappings" (see vm_init_segtable.S)
+ * are currently 16MB
+ */
+
+#define BIG_KERNEL_PAGE_SHIFT 24
+#define BIG_KERNEL_PAGE_SIZE (1 << BIG_KERNEL_PAGE_SHIFT)
+
+
+
+#endif /* _ASM_VM_MMU_H */
diff --git a/arch/hexagon/kernel/Makefile b/arch/hexagon/kernel/Makefile
new file mode 100644 (file)
index 0000000..3689f37
--- /dev/null
@@ -0,0 +1,18 @@
+extra-y := head.o vmlinux.lds init_task.o
+
+obj-$(CONFIG_SMP) += smp.o topology.o
+
+obj-y += setup.o irq_cpu.o traps.o syscalltab.o signal.o time.o
+obj-y += process.o syscall.o trampoline.o reset.o ptrace.o
+obj-y += vdso.o
+
+obj-$(CONFIG_KGDB)    += kgdb.o
+obj-$(CONFIG_MODULES) += module.o hexagon_ksyms.o
+
+# Modules required to work with the Hexagon Virtual Machine
+obj-y += vm_entry.o vm_events.o vm_switch.o vm_ops.o vm_init_segtable.o
+obj-y += vm_vectors.o
+
+obj-$(CONFIG_HAS_DMA) += dma.o
+
+obj-$(CONFIG_STACKTRACE) += stacktrace.o
diff --git a/arch/hexagon/kernel/asm-offsets.c b/arch/hexagon/kernel/asm-offsets.c
new file mode 100644 (file)
index 0000000..89ffa51
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 1996 David S. Miller
+ * Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003 Ralf Baechle
+ * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
+ * Kevin Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
+ * Copyright (C) 2000 MIPS Technologies, Inc.
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <linux/compat.h>
+#include <linux/types.h>
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <linux/interrupt.h>
+#include <linux/kbuild.h>
+#include <asm/ptrace.h>
+#include <asm/processor.h>
+
+/*  This file is used to produce asm/linkerscript constants from header
+    files typically used in c.  Specifically, it generates asm-offsets.h  */
+
+int main(void)
+{
+       COMMENT("This is a comment.");
+       /*  might get these from somewhere else.  */
+       DEFINE(_PAGE_SIZE, PAGE_SIZE);
+       DEFINE(_PAGE_SHIFT, PAGE_SHIFT);
+       BLANK();
+
+       COMMENT("Hexagon pt_regs definitions");
+       OFFSET(_PT_SYSCALL_NR, pt_regs, syscall_nr);
+       OFFSET(_PT_UGPGP, pt_regs, ugpgp);
+       OFFSET(_PT_R3130, pt_regs, r3130);
+       OFFSET(_PT_R2928, pt_regs, r2928);
+       OFFSET(_PT_R2726, pt_regs, r2726);
+       OFFSET(_PT_R2524, pt_regs, r2524);
+       OFFSET(_PT_R2322, pt_regs, r2322);
+       OFFSET(_PT_R2120, pt_regs, r2120);
+       OFFSET(_PT_R1918, pt_regs, r1918);
+       OFFSET(_PT_R1716, pt_regs, r1716);
+       OFFSET(_PT_R1514, pt_regs, r1514);
+       OFFSET(_PT_R1312, pt_regs, r1312);
+       OFFSET(_PT_R1110, pt_regs, r1110);
+       OFFSET(_PT_R0908, pt_regs, r0908);
+       OFFSET(_PT_R0706, pt_regs, r0706);
+       OFFSET(_PT_R0504, pt_regs, r0504);
+       OFFSET(_PT_R0302, pt_regs, r0302);
+       OFFSET(_PT_R0100, pt_regs, r0100);
+       OFFSET(_PT_LC0SA0, pt_regs, lc0sa0);
+       OFFSET(_PT_LC1SA1, pt_regs, lc1sa1);
+       OFFSET(_PT_M1M0, pt_regs, m1m0);
+       OFFSET(_PT_PREDSUSR, pt_regs, predsusr);
+       OFFSET(_PT_EVREC, pt_regs, hvmer);
+       OFFSET(_PT_ER_VMEL, pt_regs, hvmer.vmel);
+       OFFSET(_PT_ER_VMEST, pt_regs, hvmer.vmest);
+       OFFSET(_PT_ER_VMPSP, pt_regs, hvmer.vmpsp);
+       OFFSET(_PT_ER_VMBADVA, pt_regs, hvmer.vmbadva);
+       DEFINE(_PT_REGS_SIZE, sizeof(struct pt_regs));
+       BLANK();
+
+       COMMENT("Hexagon thread_info definitions");
+       OFFSET(_THREAD_INFO_FLAGS, thread_info, flags);
+       OFFSET(_THREAD_INFO_PT_REGS, thread_info, regs);
+       OFFSET(_THREAD_INFO_SP, thread_info, sp);
+       DEFINE(_THREAD_SIZE, THREAD_SIZE);
+       BLANK();
+
+       COMMENT("Hexagon hexagon_switch_stack definitions");
+       OFFSET(_SWITCH_R1716, hexagon_switch_stack, r1716);
+       OFFSET(_SWITCH_R1918, hexagon_switch_stack, r1918);
+       OFFSET(_SWITCH_R2120, hexagon_switch_stack, r2120);
+       OFFSET(_SWITCH_R2322, hexagon_switch_stack, r2322);
+
+       OFFSET(_SWITCH_R2524, hexagon_switch_stack, r2524);
+       OFFSET(_SWITCH_R2726, hexagon_switch_stack, r2726);
+       OFFSET(_SWITCH_FP, hexagon_switch_stack, fp);
+       OFFSET(_SWITCH_LR, hexagon_switch_stack, lr);
+       DEFINE(_SWITCH_STACK_SIZE, sizeof(struct hexagon_switch_stack));
+       BLANK();
+
+       COMMENT("Hexagon task_struct definitions");
+       OFFSET(_TASK_THREAD_INFO, task_struct, stack);
+       OFFSET(_TASK_STRUCT_THREAD, task_struct, thread);
+
+       COMMENT("Hexagon thread_struct definitions");
+       OFFSET(_THREAD_STRUCT_SWITCH_SP, thread_struct, switch_sp);
+
+       return 0;
+}
diff --git a/arch/hexagon/kernel/dma.c b/arch/hexagon/kernel/dma.c
new file mode 100644 (file)
index 0000000..e711ace
--- /dev/null
@@ -0,0 +1,220 @@
+/*
+ * DMA implementation for Hexagon
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <linux/dma-mapping.h>
+#include <linux/bootmem.h>
+#include <linux/genalloc.h>
+#include <asm/dma-mapping.h>
+
+struct dma_map_ops *dma_ops;
+EXPORT_SYMBOL(dma_ops);
+
+int bad_dma_address;  /*  globals are automatically initialized to zero  */
+
+int dma_supported(struct device *dev, u64 mask)
+{
+       if (mask == DMA_BIT_MASK(32))
+               return 1;
+       else
+               return 0;
+}
+EXPORT_SYMBOL(dma_supported);
+
+int dma_set_mask(struct device *dev, u64 mask)
+{
+       if (!dev->dma_mask || !dma_supported(dev, mask))
+               return -EIO;
+
+       *dev->dma_mask = mask;
+
+       return 0;
+}
+EXPORT_SYMBOL(dma_set_mask);
+
+static struct gen_pool *coherent_pool;
+
+
+/* Allocates from a pool of uncached memory that was reserved at boot time */
+
+void *hexagon_dma_alloc_coherent(struct device *dev, size_t size,
+                                dma_addr_t *dma_addr, gfp_t flag)
+{
+       void *ret;
+
+       if (coherent_pool == NULL) {
+               coherent_pool = gen_pool_create(PAGE_SHIFT, -1);
+
+               if (coherent_pool == NULL)
+                       panic("Can't create %s() memory pool!", __func__);
+               else
+                       gen_pool_add(coherent_pool,
+                               (PAGE_OFFSET + (max_low_pfn << PAGE_SHIFT)),
+                               hexagon_coherent_pool_size, -1);
+       }
+
+       ret = (void *) gen_pool_alloc(coherent_pool, size);
+
+       if (ret) {
+               memset(ret, 0, size);
+               *dma_addr = (dma_addr_t) (ret - PAGE_OFFSET);
+       } else
+               *dma_addr = ~0;
+
+       return ret;
+}
+
+static void hexagon_free_coherent(struct device *dev, size_t size, void *vaddr,
+                                 dma_addr_t dma_addr)
+{
+       gen_pool_free(coherent_pool, (unsigned long) vaddr, size);
+}
+
+static int check_addr(const char *name, struct device *hwdev,
+                     dma_addr_t bus, size_t size)
+{
+       if (hwdev && hwdev->dma_mask && !dma_capable(hwdev, bus, size)) {
+               if (*hwdev->dma_mask >= DMA_BIT_MASK(32))
+                       printk(KERN_ERR
+                               "%s: overflow %Lx+%zu of device mask %Lx\n",
+                               name, (long long)bus, size,
+                               (long long)*hwdev->dma_mask);
+               return 0;
+       }
+       return 1;
+}
+
+static int hexagon_map_sg(struct device *hwdev, struct scatterlist *sg,
+                         int nents, enum dma_data_direction dir,
+                         struct dma_attrs *attrs)
+{
+       struct scatterlist *s;
+       int i;
+
+       WARN_ON(nents == 0 || sg[0].length == 0);
+
+       for_each_sg(sg, s, nents, i) {
+               s->dma_address = sg_phys(s);
+               if (!check_addr("map_sg", hwdev, s->dma_address, s->length))
+                       return 0;
+
+               s->dma_length = s->length;
+
+               flush_dcache_range(PAGE_OFFSET + s->dma_address,
+                                  PAGE_OFFSET + s->dma_address + s->length);
+       }
+
+       return nents;
+}
+
+/*
+ * address is virtual
+ */
+static inline void dma_sync(void *addr, size_t size,
+                           enum dma_data_direction dir)
+{
+       switch (dir) {
+       case DMA_TO_DEVICE:
+               hexagon_clean_dcache_range((unsigned long) addr,
+               (unsigned long) addr + size);
+               break;
+       case DMA_FROM_DEVICE:
+               hexagon_inv_dcache_range((unsigned long) addr,
+               (unsigned long) addr + size);
+               break;
+       case DMA_BIDIRECTIONAL:
+               flush_dcache_range((unsigned long) addr,
+               (unsigned long) addr + size);
+               break;
+       default:
+               BUG();
+       }
+}
+
+static inline void *dma_addr_to_virt(dma_addr_t dma_addr)
+{
+       return phys_to_virt((unsigned long) dma_addr);
+}
+
+/**
+ * hexagon_map_page() - maps an address for device DMA
+ * @dev:       pointer to DMA device
+ * @page:      pointer to page struct of DMA memory
+ * @offset:    offset within page
+ * @size:      size of memory to map
+ * @dir:       transfer direction
+ * @attrs:     pointer to DMA attrs (not used)
+ *
+ * Called to map a memory address to a DMA address prior
+ * to accesses to/from device.
+ *
+ * We don't particularly have many hoops to jump through
+ * so far.  Straight translation between phys and virtual.
+ *
+ * DMA is not cache coherent so sync is necessary; this
+ * seems to be a convenient place to do it.
+ *
+ */
+static dma_addr_t hexagon_map_page(struct device *dev, struct page *page,
+                                  unsigned long offset, size_t size,
+                                  enum dma_data_direction dir,
+                                  struct dma_attrs *attrs)
+{
+       dma_addr_t bus = page_to_phys(page) + offset;
+       WARN_ON(size == 0);
+
+       if (!check_addr("map_single", dev, bus, size))
+               return bad_dma_address;
+
+       dma_sync(dma_addr_to_virt(bus), size, dir);
+
+       return bus;
+}
+
+static void hexagon_sync_single_for_cpu(struct device *dev,
+                                       dma_addr_t dma_handle, size_t size,
+                                       enum dma_data_direction dir)
+{
+       dma_sync(dma_addr_to_virt(dma_handle), size, dir);
+}
+
+static void hexagon_sync_single_for_device(struct device *dev,
+                                       dma_addr_t dma_handle, size_t size,
+                                       enum dma_data_direction dir)
+{
+       dma_sync(dma_addr_to_virt(dma_handle), size, dir);
+}
+
+struct dma_map_ops hexagon_dma_ops = {
+       .alloc_coherent = hexagon_dma_alloc_coherent,
+       .free_coherent  = hexagon_free_coherent,
+       .map_sg         = hexagon_map_sg,
+       .map_page       = hexagon_map_page,
+       .sync_single_for_cpu = hexagon_sync_single_for_cpu,
+       .sync_single_for_device = hexagon_sync_single_for_device,
+       .is_phys        = 1,
+};
+
+void __init hexagon_dma_init(void)
+{
+       if (dma_ops)
+               return;
+
+       dma_ops = &hexagon_dma_ops;
+}
diff --git a/arch/hexagon/kernel/head.S b/arch/hexagon/kernel/head.S
new file mode 100644 (file)
index 0000000..8e6b819
--- /dev/null
@@ -0,0 +1,162 @@
+/*
+ * Early kernel startup code for Hexagon
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <linux/linkage.h>
+#include <linux/init.h>
+#include <asm/asm-offsets.h>
+#include <asm/mem-layout.h>
+#include <asm/vm_mmu.h>
+#include <asm/page.h>
+
+       __INIT
+ENTRY(stext)
+       /*
+        * VMM will already have set up true vector page, MMU, etc.
+        * To set up initial kernel identity map, we have to pass
+        * the VMM a pointer to some canonical page tables. In
+        * this implementation, we're assuming that we've got
+        * them precompiled. Generate value in R24, as we'll need
+        * it again shortly.
+        */
+       r24.L = #LO(swapper_pg_dir)
+       r24.H = #HI(swapper_pg_dir)
+
+       /*
+        * Symbol is kernel segment address, but we need
+        * the logical/physical address.
+        */
+       r24 = asl(r24, #2)
+       r24 = lsr(r24, #2)
+
+       r0 = r24
+
+       /*
+        * Initialize a 16MB PTE to make the virtual and physical
+        * addresses where the kernel was loaded be identical.
+        */
+#define PTE_BITS ( __HVM_PTE_R | __HVM_PTE_W | __HVM_PTE_X     \
+                 | __HEXAGON_C_WB_L2 << 6                      \
+                 | __HVM_PDE_S_4MB)
+
+       r1 = pc
+       r2.H = #0xffc0
+       r2.L = #0x0000
+       r1 = and(r1,r2)         /* round PC to 4MB boundary     */
+       r2 = lsr(r1, #22)       /* 4MB page number              */
+       r2 = asl(r2, #2)        /* times sizeof(PTE) (4bytes)   */
+       r0 = add(r0,r2)         /* r0 = address of correct PTE  */
+       r2 = #PTE_BITS
+       r1 = add(r1,r2)         /* r1 = 4MB PTE for the first entry     */
+       r2.h = #0x0040
+       r2.l = #0x0000          /* 4MB  */
+       memw(r0 ++ #4) = r1
+       r1 = add(r1, r2)
+       memw(r0 ++ #4) = r1
+
+       r0 = r24
+
+       /*
+        * The subroutine wrapper around the virtual instruction touches
+        * no memory, so we should be able to use it even here.
+        */
+       call    __vmnewmap;
+
+       /*  Jump into virtual address range.  */
+
+       r31.h = #hi(__head_s_vaddr_target)
+       r31.l = #lo(__head_s_vaddr_target)
+       jumpr r31
+
+       /*  Insert trippy space effects.  */
+
+__head_s_vaddr_target:
+       /*
+        * Tear down VA=PA translation now that we are running
+        * in the desgnated kernel segments.
+        */
+       r0 = #__HVM_PDE_S_INVALID
+       r1 = r24
+       loop0(1f,#0x100)
+1:
+       {
+               memw(R1 ++ #4) = R0
+       }:endloop0
+
+       r0 = r24
+       call __vmnewmap
+
+       /*  Go ahead and install the trap0 return so angel calls work  */
+       r0.h = #hi(_K_provisional_vec)
+       r0.l = #lo(_K_provisional_vec)
+       call __vmsetvec
+
+       /*
+        * OK, at this point we should start to be much more careful,
+        * we're going to enter C code and start touching memory
+        * in all sorts of places.
+        * This means:
+        *      SGP needs to be OK
+        *      Need to lock shared resources
+        *      A bunch of other things that will cause
+        *      all kinds of painful bugs
+        */
+
+       /*
+        * Stack pointer should be pointed at the init task's
+        * thread stack, which should have been declared in arch/init_task.c.
+        * So uhhhhh...
+        * It's accessible via the init_thread_union, which is a union
+        * of a thread_info struct and a stack; of course, the top
+        * of the stack is not for you.  The end of the stack
+        * is simply init_thread_union + THREAD_SIZE.
+        */
+
+       {r29.H = #HI(init_thread_union); r0.H = #HI(_THREAD_SIZE); }
+       {r29.L = #LO(init_thread_union); r0.L = #LO(_THREAD_SIZE); }
+
+       /*  initialize the register used to point to current_thread_info */
+       /*  Fixme:  THREADINFO_REG can't be R2 because of that memset thing. */
+       {r29 = add(r29,r0); THREADINFO_REG = r29; }
+
+       /*  Hack:  zero bss; */
+       { r0.L = #LO(__bss_start);  r1 = #0; r2.l = #LO(__bss_stop); }
+       { r0.H = #HI(__bss_start);           r2.h = #HI(__bss_stop); }
+
+       r2 = sub(r2,r0);
+       call memset;
+
+       /* Time to make the doughnuts.   */
+       call start_kernel
+
+       /*
+        * Should not reach here.
+        */
+1:
+       jump 1b
+
+.p2align PAGE_SHIFT
+ENTRY(external_cmdline_buffer)
+        .fill _PAGE_SIZE,1,0
+
+.data
+.p2align PAGE_SHIFT
+ENTRY(empty_zero_page)
+        .fill _PAGE_SIZE,1,0
diff --git a/arch/hexagon/kernel/hexagon_ksyms.c b/arch/hexagon/kernel/hexagon_ksyms.c
new file mode 100644 (file)
index 0000000..7f18924
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Export of symbols defined in assembly files and/or libgcc.
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <asm/hexagon_vm.h>
+#include <asm/uaccess.h>
+
+EXPORT_SYMBOL(__copy_from_user_hexagon);
+EXPORT_SYMBOL(__copy_to_user_hexagon);
+EXPORT_SYMBOL(__vmgetie);
+EXPORT_SYMBOL(__vmsetie);
+EXPORT_SYMBOL(memcpy);
+EXPORT_SYMBOL(memset);
+
+#define DECLARE_EXPORT(name)     \
+       extern void name(void); EXPORT_SYMBOL(name)
+
+/* Symbols found in libgcc that assorted kernel modules need */
+DECLARE_EXPORT(__hexagon_memcpy_likely_aligned_min32bytes_mult8bytes);
+
+DECLARE_EXPORT(__hexagon_divsi3);
+DECLARE_EXPORT(__hexagon_modsi3);
+DECLARE_EXPORT(__hexagon_udivsi3);
+DECLARE_EXPORT(__hexagon_umodsi3);
diff --git a/arch/hexagon/kernel/init_task.c b/arch/hexagon/kernel/init_task.c
new file mode 100644 (file)
index 0000000..73283d3
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Init task definition
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/init_task.h>
+#include <linux/fs.h>
+#include <linux/mqueue.h>
+#include <asm/thread_info.h>
+#include <asm/uaccess.h>
+#include <asm/pgtable.h>
+
+static struct signal_struct init_signals = INIT_SIGNALS(init_signals);
+static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
+
+/*
+ * Initial thread structure.
+ *
+ * We need to make sure that this is 8192-byte aligned due to the
+ * way process stacks are handled. This is done by making sure
+ * the linker maps this in the .text segment right after head.S,
+ * and making head.S ensure the proper alignment.
+ */
+union thread_union init_thread_union
+       __attribute__((__section__(".data.init_task"),
+               __aligned__(THREAD_SIZE))) = {
+                       INIT_THREAD_INFO(init_task)
+               };
+
+/*
+ * Initial task structure.
+ *
+ * All other task structs will be allocated on slabs in fork.c
+ */
+struct task_struct init_task = INIT_TASK(init_task);
+EXPORT_SYMBOL(init_task);
diff --git a/arch/hexagon/kernel/irq_cpu.c b/arch/hexagon/kernel/irq_cpu.c
new file mode 100644 (file)
index 0000000..d4416a1
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * First-level interrupt controller model for Hexagon.
+ *
+ * Copyright (c) 2010-2011 Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <linux/interrupt.h>
+#include <asm/irq.h>
+#include <asm/hexagon_vm.h>
+
+static void mask_irq(struct irq_data *data)
+{
+       __vmintop_locdis((long) data->irq);
+}
+
+static void mask_irq_num(unsigned int irq)
+{
+       __vmintop_locdis((long) irq);
+}
+
+static void unmask_irq(struct irq_data *data)
+{
+       __vmintop_locen((long) data->irq);
+}
+
+/*  This is actually all we need for handle_fasteoi_irq  */
+static void eoi_irq(struct irq_data *data)
+{
+       __vmintop_globen((long) data->irq);
+}
+
+/* Power mamangement wake call. We don't need this, however,
+ * if this is absent, then an -ENXIO error is returned to the
+ * msm_serial driver, and it fails to correctly initialize.
+ * This is a bug in the msm_serial driver, but, for now, we
+ * work around it here, by providing this bogus handler.
+ * XXX FIXME!!! remove this when msm_serial is fixed.
+ */
+static int set_wake(struct irq_data *data, unsigned int on)
+{
+       return 0;
+}
+
+static struct irq_chip hexagon_irq_chip = {
+       .name           = "HEXAGON",
+       .irq_mask       = mask_irq,
+       .irq_unmask     = unmask_irq,
+       .irq_set_wake   = set_wake,
+       .irq_eoi        = eoi_irq
+};
+
+/**
+ * The hexagon core comes with a first-level interrupt controller
+ * with 32 total possible interrupts.  When the core is embedded
+ * into different systems/platforms, it is typically wrapped by
+ * macro cells that provide one or more second-level interrupt
+ * controllers that are cascaded into one or more of the first-level
+ * interrupts handled here. The precise wiring of these other
+ * irqs varies from platform to platform, and are set up & configured
+ * in the platform-specific files.
+ *
+ * The first-level interrupt controller is wrapped by the VM, which
+ * virtualizes the interrupt controller for us.  It provides a very
+ * simple, fast & efficient API, and so the fasteoi handler is
+ * appropriate for this case.
+ */
+void __init init_IRQ(void)
+{
+       int irq;
+
+       for (irq = 0; irq < HEXAGON_CPUINTS; irq++) {
+               mask_irq_num(irq);
+               irq_set_chip_and_handler(irq, &hexagon_irq_chip,
+                                                handle_fasteoi_irq);
+       }
+}
diff --git a/arch/hexagon/kernel/kgdb.c b/arch/hexagon/kernel/kgdb.c
new file mode 100644 (file)
index 0000000..fe4aa1b
--- /dev/null
@@ -0,0 +1,254 @@
+/*
+ * arch/hexagon/kernel/kgdb.c - Hexagon KGDB Support
+ *
+ * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <linux/kdebug.h>
+#include <linux/kgdb.h>
+
+/* All registers are 4 bytes, for now */
+#define GDB_SIZEOF_REG 4
+
+/* The register names are used during printing of the regs;
+ * Keep these at three letters to pretty-print. */
+struct dbg_reg_def_t dbg_reg_def[DBG_MAX_REG_NUM] = {
+       { " r0", GDB_SIZEOF_REG, offsetof(struct pt_regs, r00)},
+       { " r1", GDB_SIZEOF_REG, offsetof(struct pt_regs, r01)},
+       { " r2", GDB_SIZEOF_REG, offsetof(struct pt_regs, r02)},
+       { " r3", GDB_SIZEOF_REG, offsetof(struct pt_regs, r03)},
+       { " r4", GDB_SIZEOF_REG, offsetof(struct pt_regs, r04)},
+       { " r5", GDB_SIZEOF_REG, offsetof(struct pt_regs, r05)},
+       { " r6", GDB_SIZEOF_REG, offsetof(struct pt_regs, r06)},
+       { " r7", GDB_SIZEOF_REG, offsetof(struct pt_regs, r07)},
+       { " r8", GDB_SIZEOF_REG, offsetof(struct pt_regs, r08)},
+       { " r9", GDB_SIZEOF_REG, offsetof(struct pt_regs, r09)},
+       { "r10", GDB_SIZEOF_REG, offsetof(struct pt_regs, r10)},
+       { "r11", GDB_SIZEOF_REG, offsetof(struct pt_regs, r11)},
+       { "r12", GDB_SIZEOF_REG, offsetof(struct pt_regs, r12)},
+       { "r13", GDB_SIZEOF_REG, offsetof(struct pt_regs, r13)},
+       { "r14", GDB_SIZEOF_REG, offsetof(struct pt_regs, r14)},
+       { "r15", GDB_SIZEOF_REG, offsetof(struct pt_regs, r15)},
+       { "r16", GDB_SIZEOF_REG, offsetof(struct pt_regs, r16)},
+       { "r17", GDB_SIZEOF_REG, offsetof(struct pt_regs, r17)},
+       { "r18", GDB_SIZEOF_REG, offsetof(struct pt_regs, r18)},
+       { "r19", GDB_SIZEOF_REG, offsetof(struct pt_regs, r19)},
+       { "r20", GDB_SIZEOF_REG, offsetof(struct pt_regs, r20)},
+       { "r21", GDB_SIZEOF_REG, offsetof(struct pt_regs, r21)},
+       { "r22", GDB_SIZEOF_REG, offsetof(struct pt_regs, r22)},
+       { "r23", GDB_SIZEOF_REG, offsetof(struct pt_regs, r23)},
+       { "r24", GDB_SIZEOF_REG, offsetof(struct pt_regs, r24)},
+       { "r25", GDB_SIZEOF_REG, offsetof(struct pt_regs, r25)},
+       { "r26", GDB_SIZEOF_REG, offsetof(struct pt_regs, r26)},
+       { "r27", GDB_SIZEOF_REG, offsetof(struct pt_regs, r27)},
+       { "r28", GDB_SIZEOF_REG, offsetof(struct pt_regs, r28)},
+       { "r29", GDB_SIZEOF_REG, offsetof(struct pt_regs, r29)},
+       { "r30", GDB_SIZEOF_REG, offsetof(struct pt_regs, r30)},
+       { "r31", GDB_SIZEOF_REG, offsetof(struct pt_regs, r31)},
+
+       { "usr", GDB_SIZEOF_REG, offsetof(struct pt_regs, usr)},
+       { "preds", GDB_SIZEOF_REG, offsetof(struct pt_regs, preds)},
+       { " m0", GDB_SIZEOF_REG, offsetof(struct pt_regs, m0)},
+       { " m1", GDB_SIZEOF_REG, offsetof(struct pt_regs, m1)},
+       { "sa0", GDB_SIZEOF_REG, offsetof(struct pt_regs, sa0)},
+       { "sa1", GDB_SIZEOF_REG, offsetof(struct pt_regs, sa1)},
+       { "lc0", GDB_SIZEOF_REG, offsetof(struct pt_regs, lc0)},
+       { "lc1", GDB_SIZEOF_REG, offsetof(struct pt_regs, lc1)},
+       { " gp", GDB_SIZEOF_REG, offsetof(struct pt_regs, gp)},
+       { "ugp", GDB_SIZEOF_REG, offsetof(struct pt_regs, ugp)},
+       { "psp", GDB_SIZEOF_REG, offsetof(struct pt_regs, hvmer.vmpsp)},
+       { "elr", GDB_SIZEOF_REG, offsetof(struct pt_regs, hvmer.vmel)},
+       { "est", GDB_SIZEOF_REG, offsetof(struct pt_regs, hvmer.vmest)},
+       { "badva", GDB_SIZEOF_REG, offsetof(struct pt_regs, hvmer.vmbadva)},
+       { "restart_r0", GDB_SIZEOF_REG, offsetof(struct pt_regs, restart_r0)},
+       { "syscall_nr", GDB_SIZEOF_REG, offsetof(struct pt_regs, syscall_nr)},
+};
+
+struct kgdb_arch arch_kgdb_ops = {
+       /* trap0(#0xDB) 0x0cdb0054 */
+       .gdb_bpt_instr = {0x54, 0x00, 0xdb, 0x0c},
+};
+
+char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
+{
+       if (regno >= DBG_MAX_REG_NUM || regno < 0)
+               return NULL;
+
+       *((unsigned long *) mem) = *((unsigned long *) ((void *)regs +
+               dbg_reg_def[regno].offset));
+
+       return dbg_reg_def[regno].name;
+}
+
+int dbg_set_reg(int regno, void *mem, struct pt_regs *regs)
+{
+       if (regno >= DBG_MAX_REG_NUM || regno < 0)
+               return -EINVAL;
+
+       *((unsigned long *) ((void *)regs + dbg_reg_def[regno].offset)) =
+               *((unsigned long *) mem);
+
+       return 0;
+}
+
+void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc)
+{
+       instruction_pointer(regs) = pc;
+}
+
+#ifdef CONFIG_SMP
+
+/**
+ * kgdb_roundup_cpus - Get other CPUs into a holding pattern
+ * @flags: Current IRQ state
+ *
+ * On SMP systems, we need to get the attention of the other CPUs
+ * and get them be in a known state.  This should do what is needed
+ * to get the other CPUs to call kgdb_wait(). Note that on some arches,
+ * the NMI approach is not used for rounding up all the CPUs. For example,
+ * in case of MIPS, smp_call_function() is used to roundup CPUs. In
+ * this case, we have to make sure that interrupts are enabled before
+ * calling smp_call_function(). The argument to this function is
+ * the flags that will be used when restoring the interrupts. There is
+ * local_irq_save() call before kgdb_roundup_cpus().
+ *
+ * On non-SMP systems, this is not called.
+ */
+
+static void hexagon_kgdb_nmi_hook(void *ignored)
+{
+       kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs());
+}
+
+void kgdb_roundup_cpus(unsigned long flags)
+{
+       local_irq_enable();
+       smp_call_function(hexagon_kgdb_nmi_hook, NULL, 0);
+       local_irq_disable();
+}
+#endif
+
+
+/*  Not yet working  */
+void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs,
+                                struct task_struct *task)
+{
+       struct pt_regs *thread_regs;
+
+       if (task == NULL)
+               return;
+
+       /* Initialize to zero */
+       memset(gdb_regs, 0, NUMREGBYTES);
+
+       /* Otherwise, we have only some registers from switch_to() */
+       thread_regs = task_pt_regs(task);
+       gdb_regs[0] = thread_regs->r00;
+}
+
+/**
+ * kgdb_arch_handle_exception - Handle architecture specific GDB packets.
+ * @vector: The error vector of the exception that happened.
+ * @signo: The signal number of the exception that happened.
+ * @err_code: The error code of the exception that happened.
+ * @remcom_in_buffer: The buffer of the packet we have read.
+ * @remcom_out_buffer: The buffer of %BUFMAX bytes to write a packet into.
+ * @regs: The &struct pt_regs of the current process.
+ *
+ * This function MUST handle the 'c' and 's' command packets,
+ * as well packets to set / remove a hardware breakpoint, if used.
+ * If there are additional packets which the hardware needs to handle,
+ * they are handled here.  The code should return -1 if it wants to
+ * process more packets, and a %0 or %1 if it wants to exit from the
+ * kgdb callback.
+ *
+ * Not yet working.
+ */
+int kgdb_arch_handle_exception(int vector, int signo, int err_code,
+                              char *remcom_in_buffer, char *remcom_out_buffer,
+                              struct pt_regs *linux_regs)
+{
+       switch (remcom_in_buffer[0]) {
+       case 's':
+       case 'c':
+               return 0;
+       }
+       /* Stay in the debugger. */
+       return -1;
+}
+
+static int __kgdb_notify(struct die_args *args, unsigned long cmd)
+{
+       /* cpu roundup */
+       if (atomic_read(&kgdb_active) != -1) {
+               kgdb_nmicallback(smp_processor_id(), args->regs);
+               return NOTIFY_STOP;
+       }
+
+       if (user_mode(args->regs))
+               return NOTIFY_DONE;
+
+       if (kgdb_handle_exception(args->trapnr & 0xff, args->signr, args->err,
+                                   args->regs))
+               return NOTIFY_DONE;
+
+       return NOTIFY_STOP;
+}
+
+static int
+kgdb_notify(struct notifier_block *self, unsigned long cmd, void *ptr)
+{
+       unsigned long flags;
+       int ret;
+
+       local_irq_save(flags);
+       ret = __kgdb_notify(ptr, cmd);
+       local_irq_restore(flags);
+
+       return ret;
+}
+
+static struct notifier_block kgdb_notifier = {
+       .notifier_call = kgdb_notify,
+
+       /*
+        * Lowest-prio notifier priority, we want to be notified last:
+        */
+       .priority = -INT_MAX,
+};
+
+/**
+ * kgdb_arch_init - Perform any architecture specific initalization.
+ *
+ * This function will handle the initalization of any architecture
+ * specific callbacks.
+ */
+int kgdb_arch_init(void)
+{
+       return register_die_notifier(&kgdb_notifier);
+}
+
+/**
+ * kgdb_arch_exit - Perform any architecture specific uninitalization.
+ *
+ * This function will handle the uninitalization of any architecture
+ * specific callbacks, for dynamic registration and unregistration.
+ */
+void kgdb_arch_exit(void)
+{
+       unregister_die_notifier(&kgdb_notifier);
+}
diff --git a/arch/hexagon/kernel/module.c b/arch/hexagon/kernel/module.c
new file mode 100644 (file)
index 0000000..61a76ba
--- /dev/null
@@ -0,0 +1,162 @@
+/*
+ * Kernel module loader for Hexagon
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <asm/module.h>
+#include <linux/elf.h>
+#include <linux/module.h>
+#include <linux/moduleloader.h>
+#include <linux/vmalloc.h>
+
+#if 0
+#define DEBUGP printk
+#else
+#define DEBUGP(fmt , ...)
+#endif
+
+/*
+ * module_frob_arch_sections - tweak got/plt sections.
+ * @hdr - pointer to elf header
+ * @sechdrs - pointer to elf load section headers
+ * @secstrings - symbol names
+ * @mod - pointer to module
+ */
+int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
+                               char *secstrings,
+                               struct module *mod)
+{
+       unsigned int i;
+       int found = 0;
+
+       /* Look for .plt and/or .got.plt and/or .init.plt sections */
+       for (i = 0; i < hdr->e_shnum; i++) {
+               DEBUGP("Section %d is %s\n", i,
+                      secstrings + sechdrs[i].sh_name);
+               if (strcmp(secstrings + sechdrs[i].sh_name, ".plt") == 0)
+                       found = i+1;
+               if (strcmp(secstrings + sechdrs[i].sh_name, ".got.plt") == 0)
+                       found = i+1;
+               if (strcmp(secstrings + sechdrs[i].sh_name, ".rela.plt") == 0)
+                       found = i+1;
+       }
+
+       /* At this time, we don't support modules comiled with -shared */
+       if (found) {
+               printk(KERN_WARNING
+                       "Module '%s' contains unexpected .plt/.got sections.\n",
+                       mod->name);
+               /*  return -ENOEXEC;  */
+       }
+
+       return 0;
+}
+
+/*
+ * apply_relocate_add - perform rela relocations.
+ * @sechdrs - pointer to section headers
+ * @strtab - some sort of start address?
+ * @symindex - symbol index offset or something?
+ * @relsec - address to relocate to?
+ * @module - pointer to module
+ *
+ * Perform rela relocations.
+ */
+int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab,
+                       unsigned int symindex, unsigned int relsec,
+                       struct module *module)
+{
+       unsigned int i;
+       Elf32_Sym *sym;
+       uint32_t *location;
+       uint32_t value;
+       unsigned int nrelocs = sechdrs[relsec].sh_size / sizeof(Elf32_Rela);
+       Elf32_Rela *rela = (void *)sechdrs[relsec].sh_addr;
+       Elf32_Word sym_info = sechdrs[relsec].sh_info;
+       Elf32_Sym *sym_base = (Elf32_Sym *) sechdrs[symindex].sh_addr;
+       void *loc_base = (void *) sechdrs[sym_info].sh_addr;
+
+       DEBUGP("Applying relocations in section %u to section %u base=%p\n",
+              relsec, sym_info, loc_base);
+
+       for (i = 0; i < nrelocs; i++) {
+
+               /* Symbol to relocate */
+               sym = sym_base + ELF32_R_SYM(rela[i].r_info);
+
+               /* Where to make the change */
+               location = loc_base + rela[i].r_offset;
+
+               /* `Everything is relative'. */
+               value = sym->st_value + rela[i].r_addend;
+
+               DEBUGP("%d: value=%08x loc=%p reloc=%d symbol=%s\n",
+                      i, value, location, ELF32_R_TYPE(rela[i].r_info),
+                      sym->st_name ?
+                      &strtab[sym->st_name] : "(anonymous)");
+
+               switch (ELF32_R_TYPE(rela[i].r_info)) {
+               case R_HEXAGON_B22_PCREL: {
+                       int dist = (int)(value - (uint32_t)location);
+                       if ((dist < -0x00800000) ||
+                           (dist >= 0x00800000)) {
+                               printk(KERN_ERR
+                                      "%s: %s: %08x=%08x-%08x %s\n",
+                                      module->name,
+                                      "R_HEXAGON_B22_PCREL reloc out of range",
+                                      dist, value, (uint32_t)location,
+                                      sym->st_name ?
+                                      &strtab[sym->st_name] : "(anonymous)");
+                               return -ENOEXEC;
+                       }
+                       DEBUGP("B22_PCREL contents: %08X.\n", *location);
+                       *location &= ~0x01ff3fff;
+                       *location |= 0x00003fff & dist;
+                       *location |= 0x01ff0000 & (dist<<2);
+                       DEBUGP("Contents after reloc: %08x\n", *location);
+                       break;
+               }
+               case R_HEXAGON_HI16:
+                       value = (value>>16) & 0xffff;
+                       /* fallthrough */
+               case R_HEXAGON_LO16:
+                       *location &= ~0x00c03fff;
+                       *location |= value & 0x3fff;
+                       *location |= (value & 0xc000) << 8;
+                       break;
+               case R_HEXAGON_32:
+                       *location = value;
+                       break;
+               case R_HEXAGON_32_PCREL:
+                       *location = value - (uint32_t)location;
+                       break;
+               case R_HEXAGON_PLT_B22_PCREL:
+               case R_HEXAGON_GOTOFF_LO16:
+               case R_HEXAGON_GOTOFF_HI16:
+                       printk(KERN_ERR "%s: GOT/PLT relocations unsupported\n",
+                              module->name);
+                       return -ENOEXEC;
+               default:
+                       printk(KERN_ERR "%s: unknown relocation: %u\n",
+                              module->name,
+                              ELF32_R_TYPE(rela[i].r_info));
+                       return -ENOEXEC;
+               }
+       }
+       return 0;
+}
diff --git a/arch/hexagon/kernel/process.c b/arch/hexagon/kernel/process.c
new file mode 100644 (file)
index 0000000..18c4f0b
--- /dev/null
@@ -0,0 +1,279 @@
+/*
+ * Process creation support for Hexagon
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <linux/sched.h>
+#include <linux/types.h>
+#include <linux/module.h>
+#include <linux/tick.h>
+#include <linux/uaccess.h>
+#include <linux/slab.h>
+
+/*
+ * Kernel thread creation.  The desired kernel function is "wrapped"
+ * in the kernel_thread_helper function, which does cleanup
+ * afterwards.
+ */
+static void __noreturn kernel_thread_helper(void *arg, int (*fn)(void *))
+{
+       do_exit(fn(arg));
+}
+
+int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
+{
+       struct pt_regs regs;
+
+       memset(&regs, 0, sizeof(regs));
+       /*
+        * Yes, we're exploting illicit knowledge of the ABI here.
+        */
+       regs.r00 = (unsigned long) arg;
+       regs.r01 = (unsigned long) fn;
+       pt_set_elr(&regs, (unsigned long)kernel_thread_helper);
+       pt_set_kmode(&regs);
+
+       return do_fork(flags|CLONE_VM|CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
+}
+EXPORT_SYMBOL(kernel_thread);
+
+/*
+ * Program thread launch.  Often defined as a macro in processor.h,
+ * but we're shooting for a small footprint and it's not an inner-loop
+ * performance-critical operation.
+ *
+ * The Hexagon ABI specifies that R28 is zero'ed before program launch,
+ * so that gets automatically done here.  If we ever stop doing that here,
+ * we'll probably want to define the ELF_PLAT_INIT macro.
+ */
+void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp)
+{
+       /* Set to run with user-mode data segmentation */
+       set_fs(USER_DS);
+       /* We want to zero all data-containing registers. Is this overkill? */
+       memset(regs, 0, sizeof(*regs));
+       /* We might want to also zero all Processor registers here */
+       pt_set_usermode(regs);
+       pt_set_elr(regs, pc);
+       pt_set_rte_sp(regs, sp);
+}
+
+/*
+ *  Spin, or better still, do a hardware or VM wait instruction
+ *  If hardware or VM offer wait termination even though interrupts
+ *  are disabled.
+ */
+static void default_idle(void)
+{
+       __vmwait();
+}
+
+void (*idle_sleep)(void) = default_idle;
+
+void cpu_idle(void)
+{
+       while (1) {
+               tick_nohz_stop_sched_tick(1);
+               local_irq_disable();
+               while (!need_resched()) {
+                       idle_sleep();
+                       /*  interrupts wake us up, but aren't serviced  */
+                       local_irq_enable();     /* service interrupt   */
+                       local_irq_disable();
+               }
+               local_irq_enable();
+               tick_nohz_restart_sched_tick();
+               schedule();
+       }
+}
+
+/*
+ *  Return saved PC of a blocked thread
+ */
+unsigned long thread_saved_pc(struct task_struct *tsk)
+{
+       return 0;
+}
+
+/*
+ * Copy architecture-specific thread state
+ */
+int copy_thread(unsigned long clone_flags, unsigned long usp,
+               unsigned long unused, struct task_struct *p,
+               struct pt_regs *regs)
+{
+       struct thread_info *ti = task_thread_info(p);
+       struct hexagon_switch_stack *ss;
+       struct pt_regs *childregs;
+       asmlinkage void ret_from_fork(void);
+
+       childregs = (struct pt_regs *) (((unsigned long) ti + THREAD_SIZE) -
+                                       sizeof(*childregs));
+
+       memcpy(childregs, regs, sizeof(*childregs));
+       ti->regs = childregs;
+
+       /*
+        * Establish kernel stack pointer and initial PC for new thread
+        */
+       ss = (struct hexagon_switch_stack *) ((unsigned long) childregs -
+                                                   sizeof(*ss));
+       ss->lr = (unsigned long)ret_from_fork;
+       p->thread.switch_sp = ss;
+
+       /* If User mode thread, set pt_reg stack pointer as per parameter */
+       if (user_mode(childregs)) {
+               pt_set_rte_sp(childregs, usp);
+
+               /* Child sees zero return value */
+               childregs->r00 = 0;
+
+               /*
+                * The clone syscall has the C signature:
+                * int [r0] clone(int flags [r0],
+                *           void *child_frame [r1],
+                *           void *parent_tid [r2],
+                *           void *child_tid [r3],
+                *           void *thread_control_block [r4]);
+                * ugp is used to provide TLS support.
+                */
+               if (clone_flags & CLONE_SETTLS)
+                       childregs->ugp = childregs->r04;
+
+               /*
+                * Parent sees new pid -- not necessary, not even possible at
+                * this point in the fork process
+                * Might also want to set things like ti->addr_limit
+                */
+       } else {
+               /*
+                * If kernel thread, resume stack is kernel stack base.
+                * Note that this is pointer arithmetic on pt_regs *
+                */
+               pt_set_rte_sp(childregs, (unsigned long)(childregs + 1));
+               /*
+                * We need the current thread_info fast path pointer
+                * set up in pt_regs.  The register to be used is
+                * parametric for assembler code, but the mechanism
+                * doesn't drop neatly into C.  Needs to be fixed.
+                */
+               childregs->THREADINFO_REG = (unsigned long) ti;
+       }
+
+       /*
+        * thread_info pointer is pulled out of task_struct "stack"
+        * field on switch_to.
+        */
+       p->stack = (void *)ti;
+
+       return 0;
+}
+
+/*
+ * Release any architecture-specific resources locked by thread
+ */
+void release_thread(struct task_struct *dead_task)
+{
+}
+
+/*
+ * Free any architecture-specific thread data structures, etc.
+ */
+void exit_thread(void)
+{
+}
+
+/*
+ * Some archs flush debug and FPU info here
+ */
+void flush_thread(void)
+{
+}
+
+/*
+ * The "wait channel" terminology is archaic, but what we want
+ * is an identification of the point at which the scheduler
+ * was invoked by a blocked thread.
+ */
+unsigned long get_wchan(struct task_struct *p)
+{
+       unsigned long fp, pc;
+       unsigned long stack_page;
+       int count = 0;
+       if (!p || p == current || p->state == TASK_RUNNING)
+               return 0;
+
+       stack_page = (unsigned long)task_stack_page(p);
+       fp = ((struct hexagon_switch_stack *)p->thread.switch_sp)->fp;
+       do {
+               if (fp < (stack_page + sizeof(struct thread_info)) ||
+                       fp >= (THREAD_SIZE - 8 + stack_page))
+                       return 0;
+               pc = ((unsigned long *)fp)[1];
+               if (!in_sched_functions(pc))
+                       return pc;
+               fp = *(unsigned long *) fp;
+       } while (count++ < 16);
+
+       return 0;
+}
+
+/*
+ * Borrowed from PowerPC -- basically allow smaller kernel stacks if we
+ * go crazy with the page sizes.
+ */
+#if THREAD_SHIFT < PAGE_SHIFT
+
+static struct kmem_cache *thread_info_cache;
+
+struct thread_info *alloc_thread_info_node(struct task_struct *tsk, int node)
+{
+       struct thread_info *ti;
+
+       ti = kmem_cache_alloc_node(thread_info_cache, GFP_KERNEL, node);
+       if (unlikely(ti == NULL))
+               return NULL;
+#ifdef CONFIG_DEBUG_STACK_USAGE
+       memset(ti, 0, THREAD_SIZE);
+#endif
+       return ti;
+}
+
+void free_thread_info(struct thread_info *ti)
+{
+       kmem_cache_free(thread_info_cache, ti);
+}
+
+/*  Weak symbol; called by init/main.c  */
+
+void thread_info_cache_init(void)
+{
+       thread_info_cache = kmem_cache_create("thread_info", THREAD_SIZE,
+                                             THREAD_SIZE, 0, NULL);
+       BUG_ON(thread_info_cache == NULL);
+}
+
+#endif /* THREAD_SHIFT < PAGE_SHIFT */
+
+/*
+ * Required placeholder.
+ */
+int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
+{
+       return 0;
+}
diff --git a/arch/hexagon/kernel/ptrace.c b/arch/hexagon/kernel/ptrace.c
new file mode 100644 (file)
index 0000000..bea3f08
--- /dev/null
@@ -0,0 +1,180 @@
+/*
+ * Ptrace support for Hexagon
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <generated/compile.h>
+
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <linux/smp.h>
+#include <linux/errno.h>
+#include <linux/ptrace.h>
+#include <linux/regset.h>
+#include <linux/user.h>
+
+#include <asm/system.h>
+#include <asm/user.h>
+
+static int genregs_get(struct task_struct *target,
+                  const struct user_regset *regset,
+                  unsigned int pos, unsigned int count,
+                  void *kbuf, void __user *ubuf)
+{
+       int ret;
+       unsigned int dummy;
+       struct pt_regs *regs = task_pt_regs(target);
+
+
+       if (!regs)
+               return -EIO;
+
+       /* The general idea here is that the copyout must happen in
+        * exactly the same order in which the userspace expects these
+        * regs. Now, the sequence in userspace does not match the
+        * sequence in the kernel, so everything past the 32 gprs
+        * happens one at a time.
+        */
+       ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
+                                 &regs->r00, 0, 32*sizeof(unsigned long));
+
+#define ONEXT(KPT_REG, USR_REG) \
+       if (!ret) \
+               ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, \
+                       KPT_REG, offsetof(struct user_regs_struct, USR_REG), \
+                       offsetof(struct user_regs_struct, USR_REG) + \
+                                sizeof(unsigned long));
+
+       /* Must be exactly same sequence as struct user_regs_struct */
+       ONEXT(&regs->sa0, sa0);
+       ONEXT(&regs->lc0, lc0);
+       ONEXT(&regs->sa1, sa1);
+       ONEXT(&regs->lc1, lc1);
+       ONEXT(&regs->m0, m0);
+       ONEXT(&regs->m1, m1);
+       ONEXT(&regs->usr, usr);
+       ONEXT(&regs->preds, p3_0);
+       ONEXT(&regs->gp, gp);
+       ONEXT(&regs->ugp, ugp);
+       ONEXT(&pt_elr(regs), pc);
+       dummy = pt_cause(regs);
+       ONEXT(&dummy, cause);
+       ONEXT(&pt_badva(regs), badva);
+
+       /* Pad the rest with zeros, if needed */
+       if (!ret)
+               ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
+                                       offsetof(struct user_regs_struct, pad1), -1);
+       return ret;
+}
+
+static int genregs_set(struct task_struct *target,
+                  const struct user_regset *regset,
+                  unsigned int pos, unsigned int count,
+                  const void *kbuf, const void __user *ubuf)
+{
+       int ret;
+       unsigned long bucket;
+       struct pt_regs *regs = task_pt_regs(target);
+
+       if (!regs)
+               return -EIO;
+
+       ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
+                                &regs->r00, 0, 32*sizeof(unsigned long));
+
+#define INEXT(KPT_REG, USR_REG) \
+       if (!ret) \
+               ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, \
+                       KPT_REG, offsetof(struct user_regs_struct, USR_REG), \
+                       offsetof(struct user_regs_struct, USR_REG) + \
+                               sizeof(unsigned long));
+
+       /* Must be exactly same sequence as struct user_regs_struct */
+       INEXT(&regs->sa0, sa0);
+       INEXT(&regs->lc0, lc0);
+       INEXT(&regs->sa1, sa1);
+       INEXT(&regs->lc1, lc1);
+       INEXT(&regs->m0, m0);
+       INEXT(&regs->m1, m1);
+       INEXT(&regs->usr, usr);
+       INEXT(&regs->preds, p3_0);
+       INEXT(&regs->gp, gp);
+       INEXT(&regs->ugp, ugp);
+       INEXT(&pt_elr(regs), pc);
+
+       /* CAUSE and BADVA aren't writeable. */
+       INEXT(&bucket, cause);
+       INEXT(&bucket, badva);
+
+       /* Ignore the rest, if needed */
+       if (!ret)
+               ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
+                                       offsetof(struct user_regs_struct, pad1), -1);
+
+       if (ret)
+               return ret;
+
+       /*
+        * This is special; SP is actually restored by the VM via the
+        * special event record which is set by the special trap.
+        */
+       regs->hvmer.vmpsp = regs->r29;
+       return 0;
+}
+
+enum hexagon_regset {
+       REGSET_GENERAL,
+};
+
+static const struct user_regset hexagon_regsets[] = {
+       [REGSET_GENERAL] = {
+               .core_note_type = NT_PRSTATUS,
+               .n = ELF_NGREG,
+               .size = sizeof(unsigned long),
+               .align = sizeof(unsigned long),
+               .get = genregs_get,
+               .set = genregs_set,
+       },
+};
+
+static const struct user_regset_view hexagon_user_view = {
+       .name = UTS_MACHINE,
+       .e_machine = ELF_ARCH,
+       .ei_osabi = ELF_OSABI,
+       .regsets = hexagon_regsets,
+       .n = ARRAY_SIZE(hexagon_regsets)
+};
+
+const struct user_regset_view *task_user_regset_view(struct task_struct *task)
+{
+       return &hexagon_user_view;
+}
+
+void ptrace_disable(struct task_struct *child)
+{
+       /* Boilerplate - resolves to null inline if no HW single-step */
+       user_disable_single_step(child);
+}
+
+long arch_ptrace(struct task_struct *child, long request,
+                unsigned long addr, unsigned long data)
+{
+       return ptrace_request(child, request, addr, data);
+}
diff --git a/arch/hexagon/kernel/reset.c b/arch/hexagon/kernel/reset.c
new file mode 100644 (file)
index 0000000..4d72fc5
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <linux/smp.h>
+#include <asm/hexagon_vm.h>
+
+void machine_power_off(void)
+{
+       smp_send_stop();
+       __vmstop();
+}
+
+void machine_halt(void)
+{
+}
+
+void machine_restart(char *cmd)
+{
+}
+
+void pm_power_off(void)
+{
+}
diff --git a/arch/hexagon/kernel/setup.c b/arch/hexagon/kernel/setup.c
new file mode 100644 (file)
index 0000000..1202f78
--- /dev/null
@@ -0,0 +1,145 @@
+/*
+ * Arch related setup for Hexagon
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <linux/init.h>
+#include <linux/bootmem.h>
+#include <linux/mmzone.h>
+#include <linux/mm.h>
+#include <linux/seq_file.h>
+#include <linux/console.h>
+#include <linux/of_fdt.h>
+#include <asm/io.h>
+#include <asm/sections.h>
+#include <asm/setup.h>
+#include <asm/processor.h>
+#include <asm/hexagon_vm.h>
+#include <asm/vm_mmu.h>
+#include <asm/time.h>
+#ifdef CONFIG_OF
+#include <asm/prom.h>
+#endif
+
+char cmd_line[COMMAND_LINE_SIZE];
+static char default_command_line[COMMAND_LINE_SIZE] __initdata = CONFIG_CMDLINE;
+
+int on_simulator;
+
+void __cpuinit calibrate_delay(void)
+{
+       loops_per_jiffy = thread_freq_mhz * 1000000 / HZ;
+}
+
+/*
+ * setup_arch -  high level architectural setup routine
+ * @cmdline_p: pointer to pointer to command-line arguments
+ */
+
+void __init setup_arch(char **cmdline_p)
+{
+       char *p = &external_cmdline_buffer;
+
+       /*
+        * These will eventually be pulled in via either some hypervisor
+        * or devicetree description.  Hardwiring for now.
+        */
+       pcycle_freq_mhz = 600;
+       thread_freq_mhz = 100;
+       sleep_clk_freq = 32000;
+
+       /*
+        * Set up event bindings to handle exceptions and interrupts.
+        */
+       __vmsetvec(_K_VM_event_vector);
+
+       /*
+        * Simulator has a few differences from the hardware.
+        * For now, check uninitialized-but-mapped memory
+        * prior to invoking setup_arch_memory().
+        */
+       if (*(int *)((unsigned long)_end + 8) == 0x1f1f1f1f)
+               on_simulator = 1;
+       else
+               on_simulator = 0;
+
+       if (p[0] != '\0')
+               strlcpy(boot_command_line, p, COMMAND_LINE_SIZE);
+       else
+               strlcpy(boot_command_line, default_command_line,
+                       COMMAND_LINE_SIZE);
+
+       /*
+        * boot_command_line and the value set up by setup_arch
+        * are both picked up by the init code. If no reason to
+        * make them different, pass the same pointer back.
+        */
+       strlcpy(cmd_line, boot_command_line, COMMAND_LINE_SIZE);
+       *cmdline_p = cmd_line;
+
+       parse_early_param();
+
+       setup_arch_memory();
+
+#ifdef CONFIG_SMP
+       smp_start_cpus();
+#endif
+}
+
+/*
+ * Functions for dumping CPU info via /proc
+ * Probably should move to kernel/proc.c or something.
+ */
+static void *c_start(struct seq_file *m, loff_t *pos)
+{
+       return *pos < nr_cpu_ids ? (void *)((unsigned long) *pos + 1) : NULL;
+}
+
+static void *c_next(struct seq_file *m, void *v, loff_t *pos)
+{
+       ++*pos;
+       return c_start(m, pos);
+}
+
+static void c_stop(struct seq_file *m, void *v)
+{
+}
+
+/*
+ * Eventually this will dump information about
+ * CPU properties like ISA level, TLB size, etc.
+ */
+static int show_cpuinfo(struct seq_file *m, void *v)
+{
+       int cpu = (unsigned long) v - 1;
+
+       seq_printf(m, "processor\t: %d\n", cpu);
+       seq_printf(m, "model name\t: Hexagon Virtual Machine\n");
+       seq_printf(m, "BogoMips\t: %lu.%02lu\n",
+               (loops_per_jiffy * HZ) / 500000,
+               ((loops_per_jiffy * HZ) / 5000) % 100);
+       seq_printf(m, "\n");
+       return 0;
+}
+
+const struct seq_operations cpuinfo_op = {
+       .start  = &c_start,
+       .next   = &c_next,
+       .stop   = &c_stop,
+       .show   = &show_cpuinfo,
+};
diff --git a/arch/hexagon/kernel/signal.c b/arch/hexagon/kernel/signal.c
new file mode 100644 (file)
index 0000000..b45be31
--- /dev/null
@@ -0,0 +1,345 @@
+/*
+ * Signal support for Hexagon processor
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <linux/linkage.h>
+#include <linux/syscalls.h>
+#include <linux/freezer.h>
+#include <linux/tracehook.h>
+#include <asm/registers.h>
+#include <asm/thread_info.h>
+#include <asm/unistd.h>
+#include <asm/uaccess.h>
+#include <asm/ucontext.h>
+#include <asm/cacheflush.h>
+#include <asm/signal.h>
+#include <asm/vdso.h>
+
+#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
+
+struct rt_sigframe {
+       unsigned long tramp[2];
+       struct siginfo info;
+       struct ucontext uc;
+};
+
+static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
+                         size_t frame_size)
+{
+       unsigned long sp = regs->r29;
+
+       /* Switch to signal stack if appropriate */
+       if ((ka->sa.sa_flags & SA_ONSTACK) && (sas_ss_flags(sp) == 0))
+               sp = current->sas_ss_sp + current->sas_ss_size;
+
+       return (void __user *)((sp - frame_size) & ~(sizeof(long long) - 1));
+}
+
+static int setup_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
+{
+       unsigned long tmp;
+       int err = 0;
+
+       err |= copy_to_user(&sc->sc_regs.r0, &regs->r00,
+                           32*sizeof(unsigned long));
+
+       err |= __put_user(regs->sa0, &sc->sc_regs.sa0);
+       err |= __put_user(regs->lc0, &sc->sc_regs.lc0);
+       err |= __put_user(regs->sa1, &sc->sc_regs.sa1);
+       err |= __put_user(regs->lc1, &sc->sc_regs.lc1);
+       err |= __put_user(regs->m0, &sc->sc_regs.m0);
+       err |= __put_user(regs->m1, &sc->sc_regs.m1);
+       err |= __put_user(regs->usr, &sc->sc_regs.usr);
+       err |= __put_user(regs->preds, &sc->sc_regs.p3_0);
+       err |= __put_user(regs->gp, &sc->sc_regs.gp);
+       err |= __put_user(regs->ugp, &sc->sc_regs.ugp);
+
+       tmp = pt_elr(regs); err |= __put_user(tmp, &sc->sc_regs.pc);
+       tmp = pt_cause(regs); err |= __put_user(tmp, &sc->sc_regs.cause);
+       tmp = pt_badva(regs); err |= __put_user(tmp, &sc->sc_regs.badva);
+
+       return err;
+}
+
+static int restore_sigcontext(struct pt_regs *regs,
+                             struct sigcontext __user *sc)
+{
+       unsigned long tmp;
+       int err = 0;
+
+       err |= copy_from_user(&regs->r00, &sc->sc_regs.r0,
+                             32 * sizeof(unsigned long));
+
+       err |= __get_user(regs->sa0, &sc->sc_regs.sa0);
+       err |= __get_user(regs->lc0, &sc->sc_regs.lc0);
+       err |= __get_user(regs->sa1, &sc->sc_regs.sa1);
+       err |= __get_user(regs->lc1, &sc->sc_regs.lc1);
+       err |= __get_user(regs->m0, &sc->sc_regs.m0);
+       err |= __get_user(regs->m1, &sc->sc_regs.m1);
+       err |= __get_user(regs->usr, &sc->sc_regs.usr);
+       err |= __get_user(regs->preds, &sc->sc_regs.p3_0);
+       err |= __get_user(regs->gp, &sc->sc_regs.gp);
+       err |= __get_user(regs->ugp, &sc->sc_regs.ugp);
+
+       err |= __get_user(tmp, &sc->sc_regs.pc); pt_set_elr(regs, tmp);
+
+       return err;
+}
+
+/*
+ * Setup signal stack frame with siginfo structure
+ */
+static int setup_rt_frame(int signr, struct k_sigaction *ka, siginfo_t *info,
+                         sigset_t *set,  struct pt_regs *regs)
+{
+       int err = 0;
+       struct rt_sigframe __user *frame;
+       struct hexagon_vdso *vdso = current->mm->context.vdso;
+
+       frame = get_sigframe(ka, regs, sizeof(struct rt_sigframe));
+
+       if (!access_ok(VERIFY_WRITE, frame, sizeof(struct rt_sigframe)))
+               goto    sigsegv;
+
+       if (copy_siginfo_to_user(&frame->info, info))
+               goto    sigsegv;
+
+       /* The on-stack signal trampoline is no longer executed;
+        * however, the libgcc signal frame unwinding code checks for
+        * the presence of these two numeric magic values.
+        */
+       err |= __put_user(0x7800d166, &frame->tramp[0]);
+       err |= __put_user(0x5400c004, &frame->tramp[1]);
+       err |= setup_sigcontext(regs, &frame->uc.uc_mcontext);
+       err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
+       if (err)
+               goto sigsegv;
+
+       /* Load r0/r1 pair with signumber/siginfo pointer... */
+       regs->r0100 = ((unsigned long long)((unsigned long)&frame->info) << 32)
+               | (unsigned long long)signr;
+       regs->r02 = (unsigned long) &frame->uc;
+       regs->r31 = (unsigned long) vdso->rt_signal_trampoline;
+       pt_psp(regs) = (unsigned long) frame;
+       pt_set_elr(regs, (unsigned long)ka->sa.sa_handler);
+
+       return 0;
+
+sigsegv:
+       force_sigsegv(signr, current);
+       return -EFAULT;
+}
+
+/*
+ * Setup invocation of signal handler
+ */
+static int handle_signal(int sig, siginfo_t *info, struct k_sigaction *ka,
+                        sigset_t *oldset, struct pt_regs *regs)
+{
+       int rc;
+
+       /*
+        * If we're handling a signal that aborted a system call,
+        * set up the error return value before adding the signal
+        * frame to the stack.
+        */
+
+       if (regs->syscall_nr >= 0) {
+               switch (regs->r00) {
+               case -ERESTART_RESTARTBLOCK:
+               case -ERESTARTNOHAND:
+                       regs->r00 = -EINTR;
+                       break;
+               case -ERESTARTSYS:
+                       if (!(ka->sa.sa_flags & SA_RESTART)) {
+                               regs->r00 = -EINTR;
+                               break;
+                       }
+                       /* Fall through */
+               case -ERESTARTNOINTR:
+                       regs->r06 = regs->syscall_nr;
+                       pt_set_elr(regs, pt_elr(regs) - 4);
+                       regs->r00 = regs->restart_r0;
+                       break;
+               default:
+                       break;
+               }
+       }
+
+       /*
+        * Set up the stack frame; not doing the SA_SIGINFO thing.  We
+        * only set up the rt_frame flavor.
+        */
+       rc = setup_rt_frame(sig, ka, info, oldset, regs);
+
+       /* If there was an error on setup, no signal was delivered. */
+       if (rc)
+               return rc;
+
+       spin_lock_irq(&current->sighand->siglock);
+       sigorsets(&current->blocked, &current->blocked, &ka->sa.sa_mask);
+       if (!(ka->sa.sa_flags & SA_NODEFER))
+               sigaddset(&current->blocked, sig);
+       recalc_sigpending();
+       spin_unlock_irq(&current->sighand->siglock);
+
+       return 0;
+}
+
+/*
+ * Called from return-from-event code.
+ */
+static void do_signal(struct pt_regs *regs)
+{
+       struct k_sigaction sigact;
+       siginfo_t info;
+       int signo;
+
+       if (!user_mode(regs))
+               return;
+
+       if (try_to_freeze())
+               goto no_signal;
+
+       signo = get_signal_to_deliver(&info, &sigact, regs, NULL);
+
+       if (signo > 0) {
+               sigset_t *oldset;
+
+               if (test_thread_flag(TIF_RESTORE_SIGMASK))
+                       oldset = &current->saved_sigmask;
+               else
+                       oldset = &current->blocked;
+
+               if (handle_signal(signo, &info, &sigact, oldset, regs) == 0) {
+                       /*
+                        * Successful delivery case.  The saved sigmask is
+                        * stored in the signal frame, and will be restored
+                        * by sigreturn.  We can clear the TIF flag.
+                        */
+                       clear_thread_flag(TIF_RESTORE_SIGMASK);
+
+                       tracehook_signal_handler(signo, &info, &sigact, regs,
+                               test_thread_flag(TIF_SINGLESTEP));
+               }
+               return;
+       }
+
+no_signal:
+       /*
+        * If we came from a system call, handle the restart.
+        */
+       if (regs->syscall_nr >= 0) {
+               switch (regs->r00) {
+               case -ERESTARTNOHAND:
+               case -ERESTARTSYS:
+               case -ERESTARTNOINTR:
+                       regs->r06 = regs->syscall_nr;
+                       break;
+               case -ERESTART_RESTARTBLOCK:
+                       regs->r06 = __NR_restart_syscall;
+                       break;
+               default:
+                       goto no_restart;
+               }
+               pt_set_elr(regs, pt_elr(regs) - 4);
+               regs->r00 = regs->restart_r0;
+       }
+
+no_restart:
+       /* If there's no signal to deliver, put the saved sigmask back */
+       if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
+               clear_thread_flag(TIF_RESTORE_SIGMASK);
+               sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
+       }
+}
+
+void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags)
+{
+       if (thread_info_flags & _TIF_SIGPENDING)
+               do_signal(regs);
+
+       if (thread_info_flags & _TIF_NOTIFY_RESUME) {
+               clear_thread_flag(TIF_NOTIFY_RESUME);
+               if (current->replacement_session_keyring)
+                       key_replace_session_keyring();
+       }
+}
+
+/*
+ * Architecture-specific wrappers for signal-related system calls
+ */
+asmlinkage int sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss)
+{
+       struct pt_regs *regs = current_thread_info()->regs;
+
+       return do_sigaltstack(uss, uoss, regs->r29);
+}
+
+asmlinkage int sys_rt_sigreturn(void)
+{
+       struct pt_regs *regs = current_thread_info()->regs;
+       struct rt_sigframe __user *frame;
+       sigset_t blocked;
+
+       frame = (struct rt_sigframe __user *)pt_psp(regs);
+       if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
+               goto badframe;
+       if (__copy_from_user(&blocked, &frame->uc.uc_sigmask, sizeof(blocked)))
+               goto badframe;
+
+       sigdelsetmask(&blocked, ~_BLOCKABLE);
+       spin_lock_irq(&current->sighand->siglock);
+       current->blocked = blocked;
+       recalc_sigpending();
+       spin_unlock_irq(&current->sighand->siglock);
+
+       if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
+               goto badframe;
+
+       /* Restore the user's stack as well */
+       pt_psp(regs) = regs->r29;
+
+       /*
+        * Leave a trace in the stack frame that this was a sigreturn.
+        * If the system call is to replay, we've already restored the
+        * number in the GPR slot and it will be regenerated on the
+        * new system call trap entry. Note that if restore_sigcontext()
+        * did something other than a bulk copy of the pt_regs struct,
+        * we could avoid this assignment by simply not overwriting
+        * regs->syscall_nr.
+        */
+       regs->syscall_nr = __NR_rt_sigreturn;
+
+       /*
+        * If we were meticulous, we'd only call this if we knew that
+        * we were actually going to use an alternate stack, and we'd
+        * consider any error to be fatal.  What we do here, in common
+        * with many other architectures, is call it blindly and only
+        * consider the -EFAULT return case to be proof of a problem.
+        */
+       if (do_sigaltstack(&frame->uc.uc_stack, NULL, pt_psp(regs)) == -EFAULT)
+               goto badframe;
+
+       return 0;
+
+badframe:
+       force_sig(SIGSEGV, current);
+       return 0;
+}
diff --git a/arch/hexagon/kernel/smp.c b/arch/hexagon/kernel/smp.c
new file mode 100644 (file)
index 0000000..c871a2c
--- /dev/null
@@ -0,0 +1,276 @@
+/*
+ * SMP support for Hexagon
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <linux/err.h>
+#include <linux/errno.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <linux/percpu.h>
+#include <linux/sched.h>
+#include <linux/smp.h>
+#include <linux/spinlock.h>
+
+#include <asm/system.h>  /*  xchg  */
+#include <asm/time.h>    /*  timer_interrupt  */
+#include <asm/hexagon_vm.h>
+
+#define BASE_IPI_IRQ 26
+
+/*
+ * cpu_possible_map needs to be filled out prior to setup_per_cpu_areas
+ * (which is prior to any of our smp_prepare_cpu crap), in order to set
+ * up the...  per_cpu areas.
+ */
+
+struct ipi_data {
+       unsigned long bits;
+};
+
+static DEFINE_PER_CPU(struct ipi_data, ipi_data);
+
+static inline void __handle_ipi(unsigned long *ops, struct ipi_data *ipi,
+                               int cpu)
+{
+       unsigned long msg = 0;
+       do {
+               msg = find_next_bit(ops, BITS_PER_LONG, msg+1);
+
+               switch (msg) {
+
+               case IPI_TIMER:
+                       ipi_timer();
+                       break;
+
+               case IPI_CALL_FUNC:
+                       generic_smp_call_function_interrupt();
+                       break;
+
+               case IPI_CALL_FUNC_SINGLE:
+                       generic_smp_call_function_single_interrupt();
+                       break;
+
+               case IPI_CPU_STOP:
+                       /*
+                        * call vmstop()
+                        */
+                       __vmstop();
+                       break;
+
+               case IPI_RESCHEDULE:
+                       scheduler_ipi();
+                       break;
+               }
+       } while (msg < BITS_PER_LONG);
+}
+
+/*  Used for IPI call from other CPU's to unmask int  */
+void smp_vm_unmask_irq(void *info)
+{
+       __vmintop_locen((long) info);
+}
+
+
+/*
+ * This is based on Alpha's IPI stuff.
+ * Supposed to take (int, void*) as args now.
+ * Specifically, first arg is irq, second is the irq_desc.
+ */
+
+irqreturn_t handle_ipi(int irq, void *desc)
+{
+       int cpu = smp_processor_id();
+       struct ipi_data *ipi = &per_cpu(ipi_data, cpu);
+       unsigned long ops;
+
+       while ((ops = xchg(&ipi->bits, 0)) != 0)
+               __handle_ipi(&ops, ipi, cpu);
+       return IRQ_HANDLED;
+}
+
+void send_ipi(const struct cpumask *cpumask, enum ipi_message_type msg)
+{
+       unsigned long flags;
+       unsigned long cpu;
+       unsigned long retval;
+
+       local_irq_save(flags);
+
+       for_each_cpu(cpu, cpumask) {
+               struct ipi_data *ipi = &per_cpu(ipi_data, cpu);
+
+               set_bit(msg, &ipi->bits);
+               /*  Possible barrier here  */
+               retval = __vmintop_post(BASE_IPI_IRQ+cpu);
+
+               if (retval != 0) {
+                       printk(KERN_ERR "interrupt %ld not configured?\n",
+                               BASE_IPI_IRQ+cpu);
+               }
+       }
+
+       local_irq_restore(flags);
+}
+
+static struct irqaction ipi_intdesc = {
+       .handler = handle_ipi,
+       .flags = IRQF_TRIGGER_RISING,
+       .name = "ipi_handler"
+};
+
+void __init smp_prepare_boot_cpu(void)
+{
+}
+
+/*
+ * interrupts should already be disabled from the VM
+ * SP should already be correct; need to set THREADINFO_REG
+ * to point to current thread info
+ */
+
+void __cpuinit start_secondary(void)
+{
+       unsigned int cpu;
+       unsigned long thread_ptr;
+
+       /*  Calculate thread_info pointer from stack pointer  */
+       __asm__ __volatile__(
+               "%0 = SP;\n"
+               : "=r" (thread_ptr)
+       );
+
+       thread_ptr = thread_ptr & ~(THREAD_SIZE-1);
+
+       __asm__ __volatile__(
+               QUOTED_THREADINFO_REG " = %0;\n"
+               :
+               : "r" (thread_ptr)
+       );
+
+       /*  Set the memory struct  */
+       atomic_inc(&init_mm.mm_count);
+       current->active_mm = &init_mm;
+
+       cpu = smp_processor_id();
+
+       setup_irq(BASE_IPI_IRQ + cpu, &ipi_intdesc);
+
+       /*  Register the clock_event dummy  */
+       setup_percpu_clockdev();
+
+       printk(KERN_INFO "%s cpu %d\n", __func__, current_thread_info()->cpu);
+
+       set_cpu_online(cpu, true);
+       while (!cpumask_test_cpu(cpu, cpu_active_mask))
+               cpu_relax();
+       local_irq_enable();
+
+       cpu_idle();
+}
+
+
+/*
+ * called once for each present cpu
+ * apparently starts up the CPU and then
+ * maintains control until "cpu_online(cpu)" is set.
+ */
+
+int __cpuinit __cpu_up(unsigned int cpu)
+{
+       struct task_struct *idle;
+       struct thread_info *thread;
+       void *stack_start;
+
+       /*  Create new init task for the CPU  */
+       idle = fork_idle(cpu);
+       if (IS_ERR(idle))
+               panic(KERN_ERR "fork_idle failed\n");
+
+       thread = (struct thread_info *)idle->stack;
+       thread->cpu = cpu;
+
+       /*  Boot to the head.  */
+       stack_start =  ((void *) thread) + THREAD_SIZE;
+       __vmstart(start_secondary, stack_start);
+
+       while (!cpu_isset(cpu, cpu_online_map))
+               barrier();
+
+       return 0;
+}
+
+void __init smp_cpus_done(unsigned int max_cpus)
+{
+}
+
+void __init smp_prepare_cpus(unsigned int max_cpus)
+{
+       int i;
+
+       /*
+        * should eventually have some sort of machine
+        * descriptor that has this stuff
+        */
+
+       /*  Right now, let's just fake it. */
+       for (i = 0; i < max_cpus; i++)
+               cpu_set(i, cpu_present_map);
+
+       /*  Also need to register the interrupts for IPI  */
+       if (max_cpus > 1)
+               setup_irq(BASE_IPI_IRQ, &ipi_intdesc);
+}
+
+void smp_send_reschedule(int cpu)
+{
+       send_ipi(cpumask_of(cpu), IPI_RESCHEDULE);
+}
+
+void smp_send_stop(void)
+{
+       struct cpumask targets;
+       cpumask_copy(&targets, cpu_online_mask);
+       cpumask_clear_cpu(smp_processor_id(), &targets);
+       send_ipi(&targets, IPI_CPU_STOP);
+}
+
+void arch_send_call_function_single_ipi(int cpu)
+{
+       send_ipi(cpumask_of(cpu), IPI_CALL_FUNC_SINGLE);
+}
+
+void arch_send_call_function_ipi_mask(const struct cpumask *mask)
+{
+       send_ipi(mask, IPI_CALL_FUNC);
+}
+
+int setup_profiling_timer(unsigned int multiplier)
+{
+       return -EINVAL;
+}
+
+void smp_start_cpus(void)
+{
+       int i;
+
+       for (i = 0; i < NR_CPUS; i++)
+               cpu_set(i, cpu_possible_map);
+}
diff --git a/arch/hexagon/kernel/stacktrace.c b/arch/hexagon/kernel/stacktrace.c
new file mode 100644 (file)
index 0000000..11c597b
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Stacktrace support for Hexagon
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <linux/sched.h>
+#include <linux/stacktrace.h>
+#include <linux/thread_info.h>
+#include <linux/module.h>
+
+register unsigned long current_frame_pointer asm("r30");
+
+struct stackframe {
+       unsigned long fp;
+       unsigned long rets;
+};
+
+/*
+ * Save stack-backtrace addresses into a stack_trace buffer.
+ */
+void save_stack_trace(struct stack_trace *trace)
+{
+       unsigned long low, high;
+       unsigned long fp;
+       struct stackframe *frame;
+       int skip = trace->skip;
+
+       low = (unsigned long)task_stack_page(current);
+       high = low + THREAD_SIZE;
+       fp = current_frame_pointer;
+
+       while (fp >= low && fp <= (high - sizeof(*frame))) {
+               frame = (struct stackframe *)fp;
+
+               if (skip) {
+                       skip--;
+               } else {
+                       trace->entries[trace->nr_entries++] = frame->rets;
+                       if (trace->nr_entries >= trace->max_entries)
+                               break;
+               }
+
+               /*
+                * The next frame must be at a higher address than the
+                * current frame.
+                */
+               low = fp + sizeof(*frame);
+               fp = frame->fp;
+       }
+}
+EXPORT_SYMBOL_GPL(save_stack_trace);
diff --git a/arch/hexagon/kernel/syscall.c b/arch/hexagon/kernel/syscall.c
new file mode 100644 (file)
index 0000000..620dd18
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * Hexagon system calls
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <linux/file.h>
+#include <linux/fs.h>
+#include <linux/linkage.h>
+#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+#include <linux/syscalls.h>
+#include <linux/unistd.h>
+#include <asm/mman.h>
+#include <asm/registers.h>
+
+/*
+ * System calls with architecture-specific wrappers.
+ * See signal.c for signal-related system call wrappers.
+ */
+
+asmlinkage int sys_execve(char __user *ufilename,
+                         const char __user *const __user *argv,
+                         const char __user *const __user *envp)
+{
+       struct pt_regs *pregs = current_thread_info()->regs;
+       char *filename;
+       int retval;
+
+       filename = getname(ufilename);
+       retval = PTR_ERR(filename);
+       if (IS_ERR(filename))
+               return retval;
+
+       retval = do_execve(filename, argv, envp, pregs);
+       putname(filename);
+
+       return retval;
+}
+
+asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
+                        unsigned long parent_tidp, unsigned long child_tidp)
+{
+       struct pt_regs *pregs = current_thread_info()->regs;
+
+       if (!newsp)
+               newsp = pregs->SP;
+       return do_fork(clone_flags, newsp, pregs, 0, (int __user *)parent_tidp,
+                      (int __user *)child_tidp);
+}
+
+/*
+ * Do a system call from the kernel, so as to have a proper pt_regs
+ * and recycle the sys_execvpe infrustructure.
+ */
+int kernel_execve(const char *filename,
+                 const char *const argv[], const char *const envp[])
+{
+       register unsigned long __a0 asm("r0") = (unsigned long) filename;
+       register unsigned long __a1 asm("r1") = (unsigned long) argv;
+       register unsigned long __a2 asm("r2") = (unsigned long) envp;
+       int retval;
+
+       __asm__ volatile(
+               "       R6 = #%4;\n"
+               "       trap0(#1);\n"
+               "       %0 = R0;\n"
+               : "=r" (retval)
+               : "r" (__a0), "r" (__a1), "r" (__a2), "i" (__NR_execve)
+       );
+
+       return retval;
+}
+EXPORT_SYMBOL(kernel_execve);
diff --git a/arch/hexagon/kernel/syscalltab.c b/arch/hexagon/kernel/syscalltab.c
new file mode 100644 (file)
index 0000000..c550f41
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * System call table for Hexagon
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <linux/syscalls.h>
+#include <linux/signal.h>
+#include <linux/unistd.h>
+
+#include <asm/syscall.h>
+
+#undef __SYSCALL
+#define __SYSCALL(nr, call) [nr] = (call),
+
+void *sys_call_table[__NR_syscalls] = {
+#include <asm/unistd.h>
+};
diff --git a/arch/hexagon/kernel/time.c b/arch/hexagon/kernel/time.c
new file mode 100644 (file)
index 0000000..6bee15c
--- /dev/null
@@ -0,0 +1,250 @@
+/*
+ * Time related functions for Hexagon architecture
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <linux/init.h>
+#include <linux/clockchips.h>
+#include <linux/clocksource.h>
+#include <linux/interrupt.h>
+#include <linux/err.h>
+#include <linux/platform_device.h>
+#include <linux/ioport.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
+
+#include <asm/timer-regs.h>
+#include <asm/hexagon_vm.h>
+
+/*
+ * For the clocksource we need:
+ *     pcycle frequency (600MHz)
+ * For the loops_per_jiffy we need:
+ *     thread/cpu frequency (100MHz)
+ * And for the timer, we need:
+ *     sleep clock rate
+ */
+
+cycles_t       pcycle_freq_mhz;
+cycles_t       thread_freq_mhz;
+cycles_t       sleep_clk_freq;
+
+static struct resource rtos_timer_resources[] = {
+       {
+               .start  = RTOS_TIMER_REGS_ADDR,
+               .end    = RTOS_TIMER_REGS_ADDR+PAGE_SIZE-1,
+               .flags  = IORESOURCE_MEM,
+       },
+};
+
+static struct platform_device rtos_timer_device = {
+       .name           = "rtos_timer",
+       .id             = -1,
+       .num_resources  = ARRAY_SIZE(rtos_timer_resources),
+       .resource       = rtos_timer_resources,
+};
+
+/*  A lot of this stuff should move into a platform specific section.  */
+struct adsp_hw_timer_struct {
+       u32 match;   /*  Match value  */
+       u32 count;
+       u32 enable;  /*  [1] - CLR_ON_MATCH_EN, [0] - EN  */
+       u32 clear;   /*  one-shot register that clears the count  */
+};
+
+/*  Look for "TCX0" for related constants.  */
+static __iomem struct adsp_hw_timer_struct *rtos_timer;
+
+static cycle_t timer_get_cycles(struct clocksource *cs)
+{
+       return (cycle_t) __vmgettime();
+}
+
+static struct clocksource hexagon_clocksource = {
+       .name           = "pcycles",
+       .rating         = 250,
+       .read           = timer_get_cycles,
+       .mask           = CLOCKSOURCE_MASK(64),
+       .flags          = CLOCK_SOURCE_IS_CONTINUOUS,
+};
+
+static int set_next_event(unsigned long delta, struct clock_event_device *evt)
+{
+       /*  Assuming the timer will be disabled when we enter here.  */
+
+       iowrite32(1, &rtos_timer->clear);
+       iowrite32(0, &rtos_timer->clear);
+
+       iowrite32(delta, &rtos_timer->match);
+       iowrite32(1 << TIMER_ENABLE, &rtos_timer->enable);
+       return 0;
+}
+
+/*
+ * Sets the mode (periodic, shutdown, oneshot, etc) of a timer.
+ */
+static void set_mode(enum clock_event_mode mode,
+       struct clock_event_device *evt)
+{
+       switch (mode) {
+       case CLOCK_EVT_MODE_SHUTDOWN:
+               /* XXX implement me */
+       default:
+               break;
+       }
+}
+
+#ifdef CONFIG_SMP
+/*  Broadcast mechanism  */
+static void broadcast(const struct cpumask *mask)
+{
+       send_ipi(mask, IPI_TIMER);
+}
+#endif
+
+static struct clock_event_device hexagon_clockevent_dev = {
+       .name           = "clockevent",
+       .features       = CLOCK_EVT_FEAT_ONESHOT,
+       .rating         = 400,
+       .irq            = RTOS_TIMER_INT,
+       .set_next_event = set_next_event,
+       .set_mode       = set_mode,
+#ifdef CONFIG_SMP
+       .broadcast      = broadcast,
+#endif
+};
+
+#ifdef CONFIG_SMP
+static DEFINE_PER_CPU(struct clock_event_device, clock_events);
+
+void setup_percpu_clockdev(void)
+{
+       int cpu = smp_processor_id();
+       struct clock_event_device *ce_dev = &hexagon_clockevent_dev;
+       struct clock_event_device *dummy_clock_dev =
+               &per_cpu(clock_events, cpu);
+
+       memcpy(dummy_clock_dev, ce_dev, sizeof(*dummy_clock_dev));
+       INIT_LIST_HEAD(&dummy_clock_dev->list);
+
+       dummy_clock_dev->features = CLOCK_EVT_FEAT_DUMMY;
+       dummy_clock_dev->cpumask = cpumask_of(cpu);
+       dummy_clock_dev->mode = CLOCK_EVT_MODE_UNUSED;
+
+       clockevents_register_device(dummy_clock_dev);
+}
+
+/*  Called from smp.c for each CPU's timer ipi call  */
+void ipi_timer(void)
+{
+       int cpu = smp_processor_id();
+       struct clock_event_device *ce_dev = &per_cpu(clock_events, cpu);
+
+       ce_dev->event_handler(ce_dev);
+}
+#endif /* CONFIG_SMP */
+
+static irqreturn_t timer_interrupt(int irq, void *devid)
+{
+       struct clock_event_device *ce_dev = &hexagon_clockevent_dev;
+
+       iowrite32(0, &rtos_timer->enable);
+       ce_dev->event_handler(ce_dev);
+
+       return IRQ_HANDLED;
+}
+
+/*  This should also be pulled from devtree  */
+static struct irqaction rtos_timer_intdesc = {
+       .handler = timer_interrupt,
+       .flags = IRQF_TIMER | IRQF_TRIGGER_RISING,
+       .name = "rtos_timer"
+};
+
+/*
+ * time_init_deferred - called by start_kernel to set up timer/clock source
+ *
+ * Install the IRQ handler for the clock, setup timers.
+ * This is done late, as that way, we can use ioremap().
+ *
+ * This runs just before the delay loop is calibrated, and
+ * is used for delay calibration.
+ */
+void __init time_init_deferred(void)
+{
+       struct resource *resource = NULL;
+       struct clock_event_device *ce_dev = &hexagon_clockevent_dev;
+       struct device_node *dn;
+       struct resource r;
+       int err;
+
+       ce_dev->cpumask = cpu_all_mask;
+
+       if (!resource)
+               resource = rtos_timer_device.resource;
+
+       /*  ioremap here means this has to run later, after paging init  */
+       rtos_timer = ioremap(resource->start, resource->end
+               - resource->start + 1);
+
+       if (!rtos_timer) {
+               release_mem_region(resource->start, resource->end
+                       - resource->start + 1);
+       }
+       clocksource_register_khz(&hexagon_clocksource, pcycle_freq_mhz * 1000);
+
+       /*  Note: the sim generic RTOS clock is apparently really 18750Hz  */
+
+       /*
+        * Last arg is some guaranteed seconds for which the conversion will
+        * work without overflow.
+        */
+       clockevents_calc_mult_shift(ce_dev, sleep_clk_freq, 4);
+
+       ce_dev->max_delta_ns = clockevent_delta2ns(0x7fffffff, ce_dev);
+       ce_dev->min_delta_ns = clockevent_delta2ns(0xf, ce_dev);
+
+#ifdef CONFIG_SMP
+       setup_percpu_clockdev();
+#endif
+
+       clockevents_register_device(ce_dev);
+       setup_irq(ce_dev->irq, &rtos_timer_intdesc);
+}
+
+void __init time_init(void)
+{
+       late_time_init = time_init_deferred;
+}
+
+/*
+ * This could become parametric or perhaps even computed at run-time,
+ * but for now we take the observed simulator jitter.
+ */
+static long long fudgefactor = 350;  /* Maybe lower if kernel optimized. */
+
+void __udelay(unsigned long usecs)
+{
+       unsigned long long start = __vmgettime();
+       unsigned long long finish = (pcycle_freq_mhz * usecs) - fudgefactor;
+
+       while ((__vmgettime() - start) < finish)
+               cpu_relax(); /*  not sure how this improves readability  */
+}
+EXPORT_SYMBOL(__udelay);
diff --git a/arch/hexagon/kernel/topology.c b/arch/hexagon/kernel/topology.c
new file mode 100644 (file)
index 0000000..ba44751
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * CPU topology for Hexagon
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <linux/cpu.h>
+#include <linux/cpumask.h>
+#include <linux/init.h>
+#include <linux/node.h>
+#include <linux/nodemask.h>
+#include <linux/percpu.h>
+
+/*  Swiped from MIPS.  */
+
+static DEFINE_PER_CPU(struct cpu, cpu_devices);
+
+static int __init topology_init(void)
+{
+       int i, ret;
+
+       for_each_present_cpu(i) {
+
+               /*
+                * register_cpu takes a per_cpu pointer and
+                * just points it at another per_cpu struct...
+                */
+
+               ret = register_cpu(&per_cpu(cpu_devices, i), i);
+               if (ret)
+                       printk(KERN_WARNING "topology_init: register_cpu %d "
+                              "failed (%d)\n", i, ret);
+       }
+
+       return 0;
+}
+
+subsys_initcall(topology_init);
diff --git a/arch/hexagon/kernel/trampoline.S b/arch/hexagon/kernel/trampoline.S
new file mode 100644 (file)
index 0000000..06c36c0
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/*
+ * Trampoline sequences to be copied onto user stack.
+ * This consumes a little more space than hand-assembling
+ * immediate constants for use in C, but is more portable
+ * to future tweaks to the Hexagon instruction set.
+ */
+
+#include <asm/unistd.h>
+
+/*  Sig trampolines - call sys_sigreturn or sys_rt_sigreturn as appropriate */
+
+/*  plain sigreturn is gone.  */
+
+       .globl __rt_sigtramp_template
+__rt_sigtramp_template:
+       r6 = #__NR_rt_sigreturn;
+       trap0(#1);
diff --git a/arch/hexagon/kernel/traps.c b/arch/hexagon/kernel/traps.c
new file mode 100644 (file)
index 0000000..f08857d
--- /dev/null
@@ -0,0 +1,454 @@
+/*
+ * Kernel traps/events for Hexagon processor
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <linux/init.h>
+#include <linux/sched.h>
+#include <linux/module.h>
+#include <linux/kallsyms.h>
+#include <linux/kdebug.h>
+#include <linux/syscalls.h>
+#include <linux/signal.h>
+#include <linux/tracehook.h>
+#include <asm/traps.h>
+#include <asm/vm_fault.h>
+#include <asm/syscall.h>
+#include <asm/registers.h>
+#include <asm/unistd.h>
+#include <asm/sections.h>
+#ifdef CONFIG_KGDB
+# include <linux/kgdb.h>
+#endif
+
+#define TRAP_SYSCALL   1
+#define TRAP_DEBUG     0xdb
+
+void __init trap_init(void)
+{
+}
+
+#ifdef CONFIG_GENERIC_BUG
+/* Maybe should resemble arch/sh/kernel/traps.c ?? */
+int is_valid_bugaddr(unsigned long addr)
+{
+       return 1;
+}
+#endif /* CONFIG_GENERIC_BUG */
+
+static const char *ex_name(int ex)
+{
+       switch (ex) {
+       case HVM_GE_C_XPROT:
+       case HVM_GE_C_XUSER:
+               return "Execute protection fault";
+       case HVM_GE_C_RPROT:
+       case HVM_GE_C_RUSER:
+               return "Read protection fault";
+       case HVM_GE_C_WPROT:
+       case HVM_GE_C_WUSER:
+               return "Write protection fault";
+       case HVM_GE_C_XMAL:
+               return "Misaligned instruction";
+       case HVM_GE_C_RMAL:
+               return "Misaligned data load";
+       case HVM_GE_C_WMAL:
+               return "Misaligned data store";
+       case HVM_GE_C_INVI:
+       case HVM_GE_C_PRIVI:
+               return "Illegal instruction";
+       case HVM_GE_C_BUS:
+               return "Precise bus error";
+       case HVM_GE_C_CACHE:
+               return "Cache error";
+
+       case 0xdb:
+               return "Debugger trap";
+
+       default:
+               return "Unrecognized exception";
+       }
+}
+
+static void do_show_stack(struct task_struct *task, unsigned long *fp,
+                         unsigned long ip)
+{
+       int kstack_depth_to_print = 24;
+       unsigned long offset, size;
+       const char *name = NULL;
+       unsigned long *newfp;
+       unsigned long low, high;
+       char tmpstr[128];
+       char *modname;
+       int i;
+
+       if (task == NULL)
+               task = current;
+
+       printk(KERN_INFO "CPU#%d, %s/%d, Call Trace:\n",
+              raw_smp_processor_id(), task->comm,
+              task_pid_nr(task));
+
+       if (fp == NULL) {
+               if (task == current) {
+                       asm("%0 = r30" : "=r" (fp));
+               } else {
+                       fp = (unsigned long *)
+                            ((struct hexagon_switch_stack *)
+                            task->thread.switch_sp)->fp;
+               }
+       }
+
+       if ((((unsigned long) fp) & 0x3) || ((unsigned long) fp < 0x1000)) {
+               printk(KERN_INFO "-- Corrupt frame pointer %p\n", fp);
+               return;
+       }
+
+       /* Saved link reg is one word above FP */
+       if (!ip)
+               ip = *(fp+1);
+
+       /* Expect kernel stack to be in-bounds */
+       low = (unsigned long)task_stack_page(task);
+       high = low + THREAD_SIZE - 8;
+       low += sizeof(struct thread_info);
+
+       for (i = 0; i < kstack_depth_to_print; i++) {
+
+               name = kallsyms_lookup(ip, &size, &offset, &modname, tmpstr);
+
+               printk(KERN_INFO "[%p] 0x%lx: %s + 0x%lx", fp, ip, name,
+                       offset);
+               if (((unsigned long) fp < low) || (high < (unsigned long) fp))
+                       printk(KERN_CONT " (FP out of bounds!)");
+               if (modname)
+                       printk(KERN_CONT " [%s] ", modname);
+               printk(KERN_CONT "\n");
+
+               newfp = (unsigned long *) *fp;
+
+               if (((unsigned long) newfp) & 0x3) {
+                       printk(KERN_INFO "-- Corrupt frame pointer %p\n",
+                               newfp);
+                       break;
+               }
+
+               /* Attempt to continue past exception. */
+               if (0 == newfp) {
+                       struct pt_regs *regs = (struct pt_regs *) (((void *)fp)
+                                               + 8);
+
+                       if (regs->syscall_nr != -1) {
+                               printk(KERN_INFO "-- trap0 -- syscall_nr: %ld",
+                                       regs->syscall_nr);
+                               printk(KERN_CONT "  psp: %lx  elr: %lx\n",
+                                        pt_psp(regs), pt_elr(regs));
+                               break;
+                       } else {
+                               /* really want to see more ... */
+                               kstack_depth_to_print += 6;
+                               printk(KERN_INFO "-- %s (0x%lx)  badva: %lx\n",
+                                       ex_name(pt_cause(regs)), pt_cause(regs),
+                                       pt_badva(regs));
+                       }
+
+                       newfp = (unsigned long *) regs->r30;
+                       ip = pt_elr(regs);
+               } else {
+                       ip = *(newfp + 1);
+               }
+
+               /* If link reg is null, we are done. */
+               if (ip == 0x0)
+                       break;
+
+               /* If newfp isn't larger, we're tracing garbage. */
+               if (newfp > fp)
+                       fp = newfp;
+               else
+                       break;
+       }
+}
+
+void show_stack(struct task_struct *task, unsigned long *fp)
+{
+       /* Saved link reg is one word above FP */
+       do_show_stack(task, fp, 0);
+}
+
+void dump_stack(void)
+{
+       unsigned long *fp;
+       asm("%0 = r30" : "=r" (fp));
+       show_stack(current, fp);
+}
+EXPORT_SYMBOL(dump_stack);
+
+int die(const char *str, struct pt_regs *regs, long err)
+{
+       static struct {
+               spinlock_t lock;
+               int counter;
+       } die = {
+               .lock = __SPIN_LOCK_UNLOCKED(die.lock),
+               .counter = 0
+       };
+
+       console_verbose();
+       oops_enter();
+
+       spin_lock_irq(&die.lock);
+       bust_spinlocks(1);
+       printk(KERN_EMERG "Oops: %s[#%d]:\n", str, ++die.counter);
+
+       if (notify_die(DIE_OOPS, str, regs, err, pt_cause(regs), SIGSEGV) ==
+           NOTIFY_STOP)
+               return 1;
+
+       print_modules();
+       show_regs(regs);
+       do_show_stack(current, &regs->r30, pt_elr(regs));
+
+       bust_spinlocks(0);
+       add_taint(TAINT_DIE);
+
+       spin_unlock_irq(&die.lock);
+
+       if (in_interrupt())
+               panic("Fatal exception in interrupt");
+
+       if (panic_on_oops)
+               panic("Fatal exception");
+
+       oops_exit();
+       do_exit(err);
+       return 0;
+}
+
+int die_if_kernel(char *str, struct pt_regs *regs, long err)
+{
+       if (!user_mode(regs))
+               return die(str, regs, err);
+       else
+               return 0;
+}
+
+/*
+ * It's not clear that misaligned fetches are ever recoverable.
+ */
+static void misaligned_instruction(struct pt_regs *regs)
+{
+       die_if_kernel("Misaligned Instruction", regs, 0);
+       force_sig(SIGBUS, current);
+}
+
+/*
+ * Misaligned loads and stores, on the other hand, can be
+ * emulated, and probably should be, some day.  But for now
+ * they will be considered fatal.
+ */
+static void misaligned_data_load(struct pt_regs *regs)
+{
+       die_if_kernel("Misaligned Data Load", regs, 0);
+       force_sig(SIGBUS, current);
+}
+
+static void misaligned_data_store(struct pt_regs *regs)
+{
+       die_if_kernel("Misaligned Data Store", regs, 0);
+       force_sig(SIGBUS, current);
+}
+
+static void illegal_instruction(struct pt_regs *regs)
+{
+       die_if_kernel("Illegal Instruction", regs, 0);
+       force_sig(SIGILL, current);
+}
+
+/*
+ * Precise bus errors may be recoverable with a a retry,
+ * but for now, treat them as irrecoverable.
+ */
+static void precise_bus_error(struct pt_regs *regs)
+{
+       die_if_kernel("Precise Bus Error", regs, 0);
+       force_sig(SIGBUS, current);
+}
+
+/*
+ * If anything is to be done here other than panic,
+ * it will probably be complex and migrate to another
+ * source module.  For now, just die.
+ */
+static void cache_error(struct pt_regs *regs)
+{
+       die("Cache Error", regs, 0);
+}
+
+/*
+ * General exception handler
+ */
+void do_genex(struct pt_regs *regs)
+{
+       /*
+        * Decode Cause and Dispatch
+        */
+       switch (pt_cause(regs)) {
+       case HVM_GE_C_XPROT:
+       case HVM_GE_C_XUSER:
+               execute_protection_fault(regs);
+               break;
+       case HVM_GE_C_RPROT:
+       case HVM_GE_C_RUSER:
+               read_protection_fault(regs);
+               break;
+       case HVM_GE_C_WPROT:
+       case HVM_GE_C_WUSER:
+               write_protection_fault(regs);
+               break;
+       case HVM_GE_C_XMAL:
+               misaligned_instruction(regs);
+               break;
+       case HVM_GE_C_RMAL:
+               misaligned_data_load(regs);
+               break;
+       case HVM_GE_C_WMAL:
+               misaligned_data_store(regs);
+               break;
+       case HVM_GE_C_INVI:
+       case HVM_GE_C_PRIVI:
+               illegal_instruction(regs);
+               break;
+       case HVM_GE_C_BUS:
+               precise_bus_error(regs);
+               break;
+       case HVM_GE_C_CACHE:
+               cache_error(regs);
+               break;
+       default:
+               /* Halt and catch fire */
+               panic("Unrecognized exception 0x%lx\n", pt_cause(regs));
+               break;
+       }
+}
+
+/* Indirect system call dispatch */
+long sys_syscall(void)
+{
+       printk(KERN_ERR "sys_syscall invoked!\n");
+       return -ENOSYS;
+}
+
+void do_trap0(struct pt_regs *regs)
+{
+       unsigned long syscallret = 0;
+       syscall_fn syscall;
+
+       switch (pt_cause(regs)) {
+       case TRAP_SYSCALL:
+               /* System call is trap0 #1 */
+
+               /* allow strace to catch syscall args  */
+               if (unlikely(test_thread_flag(TIF_SYSCALL_TRACE) &&
+                       tracehook_report_syscall_entry(regs)))
+                       return;  /*  return -ENOSYS somewhere?  */
+
+               /* Interrupts should be re-enabled for syscall processing */
+               __vmsetie(VM_INT_ENABLE);
+
+               /*
+                * System call number is in r6, arguments in r0..r5.
+                * Fortunately, no Linux syscall has more than 6 arguments,
+                * and Hexagon ABI passes first 6 arguments in registers.
+                * 64-bit arguments are passed in odd/even register pairs.
+                * Fortunately, we have no system calls that take more
+                * than three arguments with more than one 64-bit value.
+                * Should that change, we'd need to redesign to copy
+                * between user and kernel stacks.
+                */
+               regs->syscall_nr = regs->r06;
+
+               /*
+                * GPR R0 carries the first parameter, and is also used
+                * to report the return value.  We need a backup of
+                * the user's value in case we need to do a late restart
+                * of the system call.
+                */
+               regs->restart_r0 = regs->r00;
+
+               if ((unsigned long) regs->syscall_nr >= __NR_syscalls) {
+                       regs->r00 = -1;
+               } else {
+                       syscall = (syscall_fn)
+                                 (sys_call_table[regs->syscall_nr]);
+                       syscallret = syscall(regs->r00, regs->r01,
+                                  regs->r02, regs->r03,
+                                  regs->r04, regs->r05);
+               }
+
+               /*
+                * If it was a sigreturn system call, don't overwrite
+                * r0 value in stack frame with return value.
+                *
+                * __NR_sigreturn doesn't seem to exist in new unistd.h
+                */
+
+               if (regs->syscall_nr != __NR_rt_sigreturn)
+                       regs->r00 = syscallret;
+
+               /* allow strace to get the syscall return state  */
+               if (unlikely(test_thread_flag(TIF_SYSCALL_TRACE)))
+                       tracehook_report_syscall_exit(regs, 0);
+
+               break;
+       case TRAP_DEBUG:
+               /* Trap0 0xdb is debug breakpoint */
+               if (user_mode(regs)) {
+                       struct siginfo info;
+
+                       info.si_signo = SIGTRAP;
+                       info.si_errno = 0;
+                       /*
+                        * Some architecures add some per-thread state
+                        * to distinguish between breakpoint traps and
+                        * trace traps.  We may want to do that, and
+                        * set the si_code value appropriately, or we
+                        * may want to use a different trap0 flavor.
+                        */
+                       info.si_code = TRAP_BRKPT;
+                       info.si_addr = (void __user *) pt_elr(regs);
+                       send_sig_info(SIGTRAP, &info, current);
+               } else {
+#ifdef CONFIG_KGDB
+                       kgdb_handle_exception(pt_cause(regs), SIGTRAP,
+                                             TRAP_BRKPT, regs);
+#endif
+               }
+               break;
+       }
+       /* Ignore other trap0 codes for now, especially 0 (Angel calls) */
+}
+
+/*
+ * Machine check exception handler
+ */
+void do_machcheck(struct pt_regs *regs)
+{
+       /* Halt and catch fire */
+       __vmstop();
+}
diff --git a/arch/hexagon/kernel/vdso.c b/arch/hexagon/kernel/vdso.c
new file mode 100644 (file)
index 0000000..16277c3
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * vDSO implementation for Hexagon
+ *
+ * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <linux/err.h>
+#include <linux/mm.h>
+#include <linux/vmalloc.h>
+
+#include <asm/vdso.h>
+
+static struct page *vdso_page;
+
+/* Create a vDSO page holding the signal trampoline.
+ * We want this for a non-executable stack.
+ */
+static int __init vdso_init(void)
+{
+       struct hexagon_vdso *vdso;
+
+       vdso_page = alloc_page(GFP_KERNEL);
+       if (!vdso_page)
+               panic("Cannot allocate vdso");
+
+       vdso = vmap(&vdso_page, 1, 0, PAGE_KERNEL);
+       if (!vdso)
+               panic("Cannot map vdso");
+       clear_page(vdso);
+
+       /* Install the signal trampoline; currently looks like this:
+        *      r6 = #__NR_rt_sigreturn;
+        *      trap0(#1);
+        */
+       vdso->rt_signal_trampoline[0] = __rt_sigtramp_template[0];
+       vdso->rt_signal_trampoline[1] = __rt_sigtramp_template[1];
+
+       vunmap(vdso);
+
+       return 0;
+}
+arch_initcall(vdso_init);
+
+/*
+ * Called from binfmt_elf.  Create a VMA for the vDSO page.
+ */
+int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
+{
+       int ret;
+       unsigned long vdso_base;
+       struct mm_struct *mm = current->mm;
+
+       down_write(&mm->mmap_sem);
+
+       /* Try to get it loaded right near ld.so/glibc. */
+       vdso_base = STACK_TOP;
+
+       vdso_base = get_unmapped_area(NULL, vdso_base, PAGE_SIZE, 0, 0);
+       if (IS_ERR_VALUE(vdso_base)) {
+               ret = vdso_base;
+               goto up_fail;
+       }
+
+       /* MAYWRITE to allow gdb to COW and set breakpoints. */
+       ret = install_special_mapping(mm, vdso_base, PAGE_SIZE,
+                                     VM_READ|VM_EXEC|
+                                     VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC|
+                                     VM_ALWAYSDUMP,
+                                     &vdso_page);
+
+       if (ret)
+               goto up_fail;
+
+       mm->context.vdso = (void *)vdso_base;
+
+up_fail:
+       up_write(&mm->mmap_sem);
+       return ret;
+}
+
+const char *arch_vma_name(struct vm_area_struct *vma)
+{
+       if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
+               return "[vdso]";
+       return NULL;
+}
diff --git a/arch/hexagon/kernel/vm_entry.S b/arch/hexagon/kernel/vm_entry.S
new file mode 100644 (file)
index 0000000..5b99066
--- /dev/null
@@ -0,0 +1,269 @@
+/*
+ * Event entry/exit for Hexagon
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <asm/asm-offsets.h>  /*  assembly-safer versions of C defines */
+#include <asm/mem-layout.h>   /*  sigh, except for page_offset  */
+#include <asm/hexagon_vm.h>
+#include <asm/thread_info.h>
+
+/*
+ * Entry into guest-mode Linux under Hexagon Virtual Machine.
+ * Stack pointer points to event record - build pt_regs on top of it,
+ * set up a plausible C stack frame, and dispatch to the C handler.
+ * On return, do vmrte virtual instruction with SP where we started.
+ *
+ * VM Spec 0.5 uses a trap to fetch HVM record now.
+ */
+
+/*
+ * Save full register state, while setting up thread_info struct
+ * pointer derived from kernel stack pointer in THREADINFO_REG
+ * register, putting prior thread_info.regs pointer in a callee-save
+ * register (R24, which had better not ever be assigned to THREADINFO_REG),
+ * and updating thread_info.regs to point to current stack frame,
+ * so as to support nested events in kernel mode.
+ *
+ * As this is common code, we set the pt_regs system call number
+ * to -1 for all events.  It will be replaced with the system call
+ * number in the case where we decode a system call (trap0(#1)).
+ */
+
+#define save_pt_regs()\
+       memd(R0 + #_PT_R3130) = R31:30; \
+       { memw(R0 + #_PT_R2928) = R28; \
+         R31 = memw(R0 + #_PT_ER_VMPSP); }\
+       { memw(R0 + #(_PT_R2928 + 4)) = R31; \
+         R31 = ugp; } \
+       { memd(R0 + #_PT_R2726) = R27:26; \
+         R30 = gp ; } \
+       memd(R0 + #_PT_R2524) = R25:24; \
+       memd(R0 + #_PT_R2322) = R23:22; \
+       memd(R0 + #_PT_R2120) = R21:20; \
+       memd(R0 + #_PT_R1918) = R19:18; \
+       memd(R0 + #_PT_R1716) = R17:16; \
+       memd(R0 + #_PT_R1514) = R15:14; \
+       memd(R0 + #_PT_R1312) = R13:12; \
+       { memd(R0 + #_PT_R1110) = R11:10; \
+         R15 = lc0; } \
+       { memd(R0 + #_PT_R0908) = R9:8; \
+         R14 = sa0; } \
+       { memd(R0 + #_PT_R0706) = R7:6; \
+         R13 = lc1; } \
+       { memd(R0 + #_PT_R0504) = R5:4; \
+         R12 = sa1; } \
+       { memd(R0 + #_PT_UGPGP) = R31:30; \
+         R11 = m1; \
+         R2.H = #HI(_THREAD_SIZE); } \
+       { memd(R0 + #_PT_LC0SA0) = R15:14; \
+         R10 = m0; \
+         R2.L = #LO(_THREAD_SIZE); } \
+       { memd(R0 + #_PT_LC1SA1) = R13:12; \
+         R15 = p3:0; \
+         R2 = neg(R2); } \
+       { memd(R0 + #_PT_M1M0) = R11:10; \
+         R14  = usr; \
+         R2 = and(R0,R2); } \
+       { memd(R0 + #_PT_PREDSUSR) =  R15:14; \
+         THREADINFO_REG = R2; } \
+       { r24 = memw(THREADINFO_REG + #_THREAD_INFO_PT_REGS); \
+         memw(THREADINFO_REG + #_THREAD_INFO_PT_REGS) = R0; \
+         R2 = #-1; } \
+       { memw(R0 + #_PT_SYSCALL_NR) = R2; \
+         R30 = #0; }
+
+/*
+ * Restore registers and thread_info.regs state. THREADINFO_REG
+ * is assumed to still be sane, and R24 to have been correctly
+ * preserved. Don't restore R29 (SP) until later.
+ */
+
+#define restore_pt_regs() \
+       { memw(THREADINFO_REG + #_THREAD_INFO_PT_REGS) = R24; \
+         R15:14 = memd(R0 + #_PT_PREDSUSR); } \
+       { R11:10 = memd(R0 + #_PT_M1M0); \
+         p3:0 = R15; } \
+       { R13:12 = memd(R0 + #_PT_LC1SA1); \
+         usr = R14; } \
+       { R15:14 = memd(R0 + #_PT_LC0SA0); \
+         m1 = R11; } \
+       { R3:2 = memd(R0 + #_PT_R0302); \
+         m0 = R10; } \
+       { R5:4 = memd(R0 + #_PT_R0504); \
+         lc1 = R13; } \
+       { R7:6 = memd(R0 + #_PT_R0706); \
+         sa1 = R12; } \
+       { R9:8 = memd(R0 + #_PT_R0908); \
+         lc0 = R15; } \
+       { R11:10 = memd(R0 + #_PT_R1110); \
+         sa0 = R14; } \
+       { R13:12 = memd(R0 + #_PT_R1312); \
+         R15:14 = memd(R0 + #_PT_R1514); } \
+       { R17:16 = memd(R0 + #_PT_R1716); \
+         R19:18 = memd(R0 + #_PT_R1918); } \
+       { R21:20 = memd(R0 + #_PT_R2120); \
+         R23:22 = memd(R0 + #_PT_R2322); } \
+       { R25:24 = memd(R0 + #_PT_R2524); \
+         R27:26 = memd(R0 + #_PT_R2726); } \
+       R31:30 = memd(R0 + #_PT_UGPGP); \
+       { R28 = memw(R0 + #_PT_R2928); \
+         ugp = R31; } \
+       { R31:30 = memd(R0 + #_PT_R3130); \
+         gp = R30; }
+
+       /*
+        * Clears off enough space for the rest of pt_regs; evrec is a part
+        * of pt_regs in HVM mode.  Save R0/R1, set handler's address in R1.
+        * R0 is the address of pt_regs and is the parameter to save_pt_regs.
+        */
+
+/*
+ * Since the HVM isn't automagically pushing the EVREC onto the stack anymore,
+ * we'll subract the entire size out and then fill it in ourselves.
+ * Need to save off R0, R1, R2, R3 immediately.
+ */
+
+#define        vm_event_entry(CHandler) \
+       { \
+               R29 = add(R29, #-(_PT_REGS_SIZE)); \
+               memd(R29 + #(_PT_R0100 + -_PT_REGS_SIZE)) = R1:0; \
+       } \
+       { \
+               memd(R29 +#_PT_R0302) = R3:2; \
+       } \
+       trap1(#HVM_TRAP1_VMGETREGS); \
+       { \
+               memd(R29 + #_PT_ER_VMEL) = R1:0; \
+               R0 = R29; \
+               R1.L = #LO(CHandler); \
+       } \
+       { \
+               memd(R29 + #_PT_ER_VMPSP) = R3:2; \
+               R1.H = #HI(CHandler); \
+               jump event_dispatch; \
+       }
+
+.text
+       /*
+        * Do bulk save/restore in one place.
+        * Adds a jump to dispatch latency, but
+        * saves hundreds of bytes.
+        */
+
+event_dispatch:
+       save_pt_regs()
+       callr   r1
+
+       /*
+        * If we were in kernel mode, we don't need to check scheduler
+        * or signals if CONFIG_PREEMPT is not set.  If set, then it has
+        * to jump to a need_resched kind of block.
+        * BTW, CONFIG_PREEMPT is not supported yet.
+        */
+
+#ifdef CONFIG_PREEMPT
+       R0 = #VM_INT_DISABLE
+       trap1(#HVM_TRAP1_VMSETIE)
+#endif
+
+       /*  "Nested control path" -- if the previous mode was kernel  */
+       R0 = memw(R29 + #_PT_ER_VMEST);
+       P0 = tstbit(R0, #HVM_VMEST_UM_SFT);
+       if !P0 jump restore_all;
+       /*
+        * Returning from system call, normally coming back from user mode
+        */
+return_from_syscall:
+       /*  Disable interrupts while checking TIF  */
+       R0 = #VM_INT_DISABLE
+       trap1(#HVM_TRAP1_VMSETIE)
+
+       /*
+        * Coming back from the C-world, our thread info pointer
+        * should be in the designated register (usually R19)
+        */
+       R1.L = #LO(_TIF_ALLWORK_MASK)
+       {
+               R1.H = #HI(_TIF_ALLWORK_MASK);
+               R0 = memw(THREADINFO_REG + #_THREAD_INFO_FLAGS);
+       }
+
+       /*
+        * Compare against the "return to userspace" _TIF_WORK_MASK
+        */
+       R1 = and(R1,R0);
+       { P0 = cmp.eq(R1,#0); if (!P0.new) jump:t work_pending;}
+       jump restore_all;  /*  we're outta here!  */
+
+work_pending:
+       {
+               P0 = tstbit(R1, #TIF_NEED_RESCHED);
+               if (!P0.new) jump:nt work_notifysig;
+       }
+       call schedule
+       jump return_from_syscall;  /*  check for more work  */
+
+work_notifysig:
+       /*  this is the part that's kind of fuzzy.  */
+       R1 = and(R0, #(_TIF_SIGPENDING | _TIF_NOTIFY_RESUME));
+       P0 = cmp.eq(R1, #0);
+       if P0 jump restore_all
+       R1 = R0;        /* unsigned long thread_info_flags */
+       R0 = R29;       /* regs should still be at top of stack  */
+       call do_notify_resume
+
+restore_all:
+       /* Disable interrupts, if they weren't already, before reg restore.  */
+       R0 = #VM_INT_DISABLE
+       trap1(#HVM_TRAP1_VMSETIE)
+
+       /*  do the setregs here for VM 0.5  */
+       /*  R29 here should already be pointing at pt_regs  */
+       R1:0 = memd(R29 + #_PT_ER_VMEL);
+       R3:2 = memd(R29 + #_PT_ER_VMPSP);
+       trap1(#HVM_TRAP1_VMSETREGS);
+
+       R0 = R29
+       restore_pt_regs()
+       R1:0 = memd(R29 + #_PT_R0100);
+       R29 = add(R29, #_PT_REGS_SIZE);
+       trap1(#HVM_TRAP1_VMRTE)
+       /* Notreached */
+
+       .globl _K_enter_genex
+_K_enter_genex:
+       vm_event_entry(do_genex)
+
+       .globl _K_enter_interrupt
+_K_enter_interrupt:
+       vm_event_entry(arch_do_IRQ)
+
+       .globl _K_enter_trap0
+_K_enter_trap0:
+       vm_event_entry(do_trap0)
+
+       .globl _K_enter_machcheck
+_K_enter_machcheck:
+       vm_event_entry(do_machcheck)
+
+
+       .globl ret_from_fork
+ret_from_fork:
+       call schedule_tail
+       jump return_from_syscall
diff --git a/arch/hexagon/kernel/vm_events.c b/arch/hexagon/kernel/vm_events.c
new file mode 100644 (file)
index 0000000..986a081
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * Mostly IRQ support for Hexagon
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <linux/kernel.h>
+#include <asm/registers.h>
+#include <linux/irq.h>
+#include <linux/hardirq.h>
+#include <asm/system.h>
+
+/*
+ * show_regs - print pt_regs structure
+ * @regs: pointer to pt_regs
+ *
+ * To-do:  add all the accessor definitions to registers.h
+ *
+ * Will make this routine a lot easier to write.
+ */
+void show_regs(struct pt_regs *regs)
+{
+       printk(KERN_EMERG "restart_r0: \t0x%08lx   syscall_nr: %ld\n",
+              regs->restart_r0, regs->syscall_nr);
+       printk(KERN_EMERG "preds: \t\t0x%08lx\n", regs->preds);
+       printk(KERN_EMERG "lc0: \t0x%08lx   sa0: 0x%08lx   m0:  0x%08lx\n",
+              regs->lc0, regs->sa0, regs->m0);
+       printk(KERN_EMERG "lc1: \t0x%08lx   sa1: 0x%08lx   m1:  0x%08lx\n",
+              regs->lc1, regs->sa1, regs->m1);
+       printk(KERN_EMERG "gp: \t0x%08lx   ugp: 0x%08lx   usr: 0x%08lx\n",
+              regs->gp, regs->ugp, regs->usr);
+       printk(KERN_EMERG "r0: \t0x%08lx %08lx %08lx %08lx\n", regs->r00,
+               regs->r01,
+               regs->r02,
+               regs->r03);
+       printk(KERN_EMERG "r4:  \t0x%08lx %08lx %08lx %08lx\n", regs->r04,
+               regs->r05,
+               regs->r06,
+               regs->r07);
+       printk(KERN_EMERG "r8:  \t0x%08lx %08lx %08lx %08lx\n", regs->r08,
+               regs->r09,
+               regs->r10,
+               regs->r11);
+       printk(KERN_EMERG "r12: \t0x%08lx %08lx %08lx %08lx\n", regs->r12,
+               regs->r13,
+               regs->r14,
+               regs->r15);
+       printk(KERN_EMERG "r16: \t0x%08lx %08lx %08lx %08lx\n", regs->r16,
+               regs->r17,
+               regs->r18,
+               regs->r19);
+       printk(KERN_EMERG "r20: \t0x%08lx %08lx %08lx %08lx\n", regs->r20,
+               regs->r21,
+               regs->r22,
+               regs->r23);
+       printk(KERN_EMERG "r24: \t0x%08lx %08lx %08lx %08lx\n", regs->r24,
+               regs->r25,
+               regs->r26,
+               regs->r27);
+       printk(KERN_EMERG "r28: \t0x%08lx %08lx %08lx %08lx\n", regs->r28,
+               regs->r29,
+               regs->r30,
+               regs->r31);
+
+       printk(KERN_EMERG "elr: \t0x%08lx   cause: 0x%08lx   user_mode: %d\n",
+               pt_elr(regs), pt_cause(regs), user_mode(regs));
+       printk(KERN_EMERG "psp: \t0x%08lx   badva: 0x%08lx   int_enabled: %d\n",
+               pt_psp(regs), pt_badva(regs), ints_enabled(regs));
+}
+
+void dummy_handler(struct pt_regs *regs)
+{
+       unsigned int elr = pt_elr(regs);
+       printk(KERN_ERR "Unimplemented handler; ELR=0x%08x\n", elr);
+}
+
+
+void arch_do_IRQ(struct pt_regs *regs)
+{
+       int irq = pt_cause(regs);
+       struct pt_regs *old_regs = set_irq_regs(regs);
+
+       irq_enter();
+       generic_handle_irq(irq);
+       irq_exit();
+       set_irq_regs(old_regs);
+}
diff --git a/arch/hexagon/kernel/vm_init_segtable.S b/arch/hexagon/kernel/vm_init_segtable.S
new file mode 100644 (file)
index 0000000..aebb35b
--- /dev/null
@@ -0,0 +1,442 @@
+/*
+ * Initial page table for Linux kernel under Hexagon VM,
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/*
+ * These tables are pre-computed and linked into kernel.
+ */
+
+#include <asm/vm_mmu.h>
+/*  #include <asm/iomap.h>  */
+
+/*
+ * Start with mapping PA=0 to both VA=0x0 and VA=0xc000000 as 16MB large pages.
+ * No user mode access, RWX, write-back cache.  The entry needs
+ * to be replicated for all 4 virtual segments mapping to the page.
+ */
+
+/* "Big Kernel Page"  */
+#define BKP(pa) (((pa) & __HVM_PTE_PGMASK_4MB)         \
+               | __HVM_PTE_R | __HVM_PTE_W | __HVM_PTE_X       \
+               | __HEXAGON_C_WB_L2 << 6                        \
+               | __HVM_PDE_S_16MB)
+
+/*  No cache version  */
+
+#define BKPG_IO(pa) (((pa) & __HVM_PTE_PGMASK_16MB) \
+                       | __HVM_PTE_R | __HVM_PTE_W | __HVM_PTE_X \
+                       | __HVM_PDE_S_16MB | __HEXAGON_C_DEV << 6 )
+
+#define FOURK_IO(pa) (((pa) & __HVM_PTE_PGMASK_4KB) \
+                       | __HVM_PTE_R | __HVM_PTE_W | __HVM_PTE_X \
+                       | __HEXAGON_C_DEV << 6 )
+
+#define L2_PTR(pa) (((pa) & __HVM_PTE_PGMASK_4KB) \
+                       | __HVM_PDE_S_4KB  )
+
+#define X __HVM_PDE_S_INVALID
+
+       .p2align 12
+       .globl swapper_pg_dir
+       .globl _K_init_segtable
+swapper_pg_dir:
+/* VA 0x00000000 */
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X
+       .word X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X
+       .word X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X
+       .word X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X
+       .word X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X
+       .word X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X
+       .word X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X
+       .word X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X
+/* VA 0x40000000 */
+       .word X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X
+       .word X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X
+       .word X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X
+       .word X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X
+       .word X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X
+       .word X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X
+       .word X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X
+       .word X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X
+/* VA 0x80000000 */
+       .word X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X
+       .word X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X
+       .word X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X
+       .word X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X
+       .word X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X
+/*0xa8*/.word X,X,X,X
+#ifdef CONFIG_COMET_EARLY_UART_DEBUG
+UART_PTE_ENTRY:
+/*0xa9*/.word BKPG_IO(0xa9000000),BKPG_IO(0xa9000000),BKPG_IO(0xa9000000),BKPG_IO(0xa9000000)
+#else
+/*0xa9*/.word X,X,X,X
+#endif
+/*0xaa*/.word X,X,X,X
+/*0xab*/.word X,X,X,X
+/*0xac*/.word X,X,X,X
+/*0xad*/.word X,X,X,X
+/*0xae*/.word X,X,X,X
+/*0xaf*/.word X,X,X,X
+/*0xb0*/.word X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X
+       .word X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X
+_K_init_segtable:
+/* VA 0xC0000000 */
+       .word BKP(0x00000000), BKP(0x00400000), BKP(0x00800000), BKP(0x00c00000)
+       .word BKP(0x01000000), BKP(0x01400000), BKP(0x01800000), BKP(0x01c00000)
+       .word BKP(0x02000000), BKP(0x02400000), BKP(0x02800000), BKP(0x02c00000)
+       .word BKP(0x03000000), BKP(0x03400000), BKP(0x03800000), BKP(0x03c00000)
+       .word BKP(0x04000000), BKP(0x04400000), BKP(0x04800000), BKP(0x04c00000)
+       .word BKP(0x05000000), BKP(0x05400000), BKP(0x05800000), BKP(0x05c00000)
+       .word BKP(0x06000000), BKP(0x06400000), BKP(0x06800000), BKP(0x06c00000)
+       .word BKP(0x07000000), BKP(0x07400000), BKP(0x07800000), BKP(0x07c00000)
+
+       .word BKP(0x08000000), BKP(0x08400000), BKP(0x08800000), BKP(0x08c00000)
+       .word BKP(0x09000000), BKP(0x09400000), BKP(0x09800000), BKP(0x09c00000)
+       .word BKP(0x0a000000), BKP(0x0a400000), BKP(0x0a800000), BKP(0x0ac00000)
+       .word BKP(0x0b000000), BKP(0x0b400000), BKP(0x0b800000), BKP(0x0bc00000)
+       .word BKP(0x0c000000), BKP(0x0c400000), BKP(0x0c800000), BKP(0x0cc00000)
+       .word BKP(0x0d000000), BKP(0x0d400000), BKP(0x0d800000), BKP(0x0dc00000)
+       .word BKP(0x0e000000), BKP(0x0e400000), BKP(0x0e800000), BKP(0x0ec00000)
+       .word BKP(0x0f000000), BKP(0x0f400000), BKP(0x0f800000), BKP(0x0fc00000)
+
+       .word BKP(0x10000000), BKP(0x10400000), BKP(0x10800000), BKP(0x10c00000)
+       .word BKP(0x11000000), BKP(0x11400000), BKP(0x11800000), BKP(0x11c00000)
+       .word BKP(0x12000000), BKP(0x12400000), BKP(0x12800000), BKP(0x12c00000)
+       .word BKP(0x13000000), BKP(0x13400000), BKP(0x13800000), BKP(0x13c00000)
+       .word BKP(0x14000000), BKP(0x14400000), BKP(0x14800000), BKP(0x14c00000)
+       .word BKP(0x15000000), BKP(0x15400000), BKP(0x15800000), BKP(0x15c00000)
+       .word BKP(0x16000000), BKP(0x16400000), BKP(0x16800000), BKP(0x16c00000)
+       .word BKP(0x17000000), BKP(0x17400000), BKP(0x17800000), BKP(0x17c00000)
+
+       .word BKP(0x18000000), BKP(0x18400000), BKP(0x18800000), BKP(0x18c00000)
+       .word BKP(0x19000000), BKP(0x19400000), BKP(0x19800000), BKP(0x19c00000)
+       .word BKP(0x1a000000), BKP(0x1a400000), BKP(0x1a800000), BKP(0x1ac00000)
+       .word BKP(0x1b000000), BKP(0x1b400000), BKP(0x1b800000), BKP(0x1bc00000)
+       .word BKP(0x1c000000), BKP(0x1c400000), BKP(0x1c800000), BKP(0x1cc00000)
+       .word BKP(0x1d000000), BKP(0x1d400000), BKP(0x1d800000), BKP(0x1dc00000)
+       .word BKP(0x1e000000), BKP(0x1e400000), BKP(0x1e800000), BKP(0x1ec00000)
+       .word BKP(0x1f000000), BKP(0x1f400000), BKP(0x1f800000), BKP(0x1fc00000)
+
+       .word BKP(0x20000000), BKP(0x20400000), BKP(0x20800000), BKP(0x20c00000)
+       .word BKP(0x21000000), BKP(0x21400000), BKP(0x21800000), BKP(0x21c00000)
+       .word BKP(0x22000000), BKP(0x22400000), BKP(0x22800000), BKP(0x22c00000)
+       .word BKP(0x23000000), BKP(0x23400000), BKP(0x23800000), BKP(0x23c00000)
+       .word BKP(0x24000000), BKP(0x24400000), BKP(0x24800000), BKP(0x24c00000)
+       .word BKP(0x25000000), BKP(0x25400000), BKP(0x25800000), BKP(0x25c00000)
+       .word BKP(0x26000000), BKP(0x26400000), BKP(0x26800000), BKP(0x26c00000)
+       .word BKP(0x27000000), BKP(0x27400000), BKP(0x27800000), BKP(0x27c00000)
+
+       .word BKP(0x28000000), BKP(0x28400000), BKP(0x28800000), BKP(0x28c00000)
+       .word BKP(0x29000000), BKP(0x29400000), BKP(0x29800000), BKP(0x29c00000)
+       .word BKP(0x2a000000), BKP(0x2a400000), BKP(0x2a800000), BKP(0x2ac00000)
+       .word BKP(0x2b000000), BKP(0x2b400000), BKP(0x2b800000), BKP(0x2bc00000)
+       .word BKP(0x2c000000), BKP(0x2c400000), BKP(0x2c800000), BKP(0x2cc00000)
+       .word BKP(0x2d000000), BKP(0x2d400000), BKP(0x2d800000), BKP(0x2dc00000)
+       .word BKP(0x2e000000), BKP(0x2e400000), BKP(0x2e800000), BKP(0x2ec00000)
+       .word BKP(0x2f000000), BKP(0x2f400000), BKP(0x2f800000), BKP(0x2fc00000)
+
+       .word BKP(0x30000000), BKP(0x30400000), BKP(0x30800000), BKP(0x30c00000)
+       .word BKP(0x31000000), BKP(0x31400000), BKP(0x31800000), BKP(0x31c00000)
+       .word BKP(0x32000000), BKP(0x32400000), BKP(0x32800000), BKP(0x32c00000)
+       .word BKP(0x33000000), BKP(0x33400000), BKP(0x33800000), BKP(0x33c00000)
+       .word BKP(0x34000000), BKP(0x34400000), BKP(0x34800000), BKP(0x34c00000)
+       .word BKP(0x35000000), BKP(0x35400000), BKP(0x35800000), BKP(0x35c00000)
+       .word BKP(0x36000000), BKP(0x36400000), BKP(0x36800000), BKP(0x36c00000)
+       .word BKP(0x37000000), BKP(0x37400000), BKP(0x37800000), BKP(0x37c00000)
+
+       .word BKP(0x38000000), BKP(0x38400000), BKP(0x38800000), BKP(0x38c00000)
+       .word BKP(0x39000000), BKP(0x39400000), BKP(0x39800000), BKP(0x39c00000)
+       .word BKP(0x3a000000), BKP(0x3a400000), BKP(0x3a800000), BKP(0x3ac00000)
+       .word BKP(0x3b000000), BKP(0x3b400000), BKP(0x3b800000), BKP(0x3bc00000)
+       .word BKP(0x3c000000), BKP(0x3c400000), BKP(0x3c800000), BKP(0x3cc00000)
+       .word BKP(0x3d000000), BKP(0x3d400000), BKP(0x3d800000), BKP(0x3dc00000)
+_K_io_map:
+       .word X,X,X,X /* 0x3e000000 - device IO early remap */
+       .word X,X,X,X /* 0x3f000000 - hypervisor space*/
+
+#if 0
+/*
+ * This is in here as an example for devices which need to be mapped really
+ * early.
+ */
+       .p2align 12
+       .globl _K_io_kmap
+       .globl _K_init_devicetable
+_K_init_devicetable:  /*  Should be 4MB worth of entries  */
+       .word FOURK_IO(MSM_GPIO1_PHYS),FOURK_IO(MSM_GPIO2_PHYS),FOURK_IO(MSM_SIRC_PHYS),X
+       .word FOURK_IO(TLMM_GPIO1_PHYS),X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+       .word X,X,X,X
+#endif
diff --git a/arch/hexagon/kernel/vm_ops.S b/arch/hexagon/kernel/vm_ops.S
new file mode 100644 (file)
index 0000000..24d7fca
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * Hexagon VM instruction support
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <linux/linkage.h>
+#include <asm/hexagon_vm.h>
+
+/*
+ * C wrappers for virtual machine "instructions".  These
+ * could be, and perhaps some day will be, handled as in-line
+ * macros, but for tracing/debugging it's handy to have
+ * a single point of invocation for each of them.
+ * Conveniently, they take paramters and return values
+ * consistent with the ABI calling convention.
+ */
+
+ENTRY(__vmrte)
+       trap1(#HVM_TRAP1_VMRTE);
+       jumpr   R31;
+
+ENTRY(__vmsetvec)
+       trap1(#HVM_TRAP1_VMSETVEC);
+       jumpr   R31;
+
+ENTRY(__vmsetie)
+       trap1(#HVM_TRAP1_VMSETIE);
+       jumpr   R31;
+
+ENTRY(__vmgetie)
+       trap1(#HVM_TRAP1_VMGETIE);
+       jumpr   R31;
+
+ENTRY(__vmintop)
+       trap1(#HVM_TRAP1_VMINTOP);
+       jumpr   R31;
+
+ENTRY(__vmclrmap)
+       trap1(#HVM_TRAP1_VMCLRMAP);
+       jumpr   R31;
+
+ENTRY(__vmnewmap)
+       r1 = #VM_NEWMAP_TYPE_PGTABLES;
+       trap1(#HVM_TRAP1_VMNEWMAP);
+       jumpr   R31;
+
+ENTRY(__vmcache)
+       trap1(#HVM_TRAP1_VMCACHE);
+       jumpr   R31;
+
+ENTRY(__vmgettime)
+       trap1(#HVM_TRAP1_VMGETTIME);
+       jumpr   R31;
+
+ENTRY(__vmsettime)
+       trap1(#HVM_TRAP1_VMSETTIME);
+       jumpr   R31;
+
+ENTRY(__vmwait)
+       trap1(#HVM_TRAP1_VMWAIT);
+       jumpr   R31;
+
+ENTRY(__vmyield)
+       trap1(#HVM_TRAP1_VMYIELD);
+       jumpr   R31;
+
+ENTRY(__vmstart)
+       trap1(#HVM_TRAP1_VMSTART);
+       jumpr   R31;
+
+ENTRY(__vmstop)
+       trap1(#HVM_TRAP1_VMSTOP);
+       jumpr   R31;
+
+ENTRY(__vmvpid)
+       trap1(#HVM_TRAP1_VMVPID);
+       jumpr   R31;
+
+/*  Probably not actually going to use these; see vm_entry.S  */
+
+ENTRY(__vmsetregs)
+       trap1(#HVM_TRAP1_VMSETREGS);
+       jumpr   R31;
+
+ENTRY(__vmgetregs)
+       trap1(#HVM_TRAP1_VMGETREGS);
+       jumpr   R31;
diff --git a/arch/hexagon/kernel/vm_switch.S b/arch/hexagon/kernel/vm_switch.S
new file mode 100644 (file)
index 0000000..0decf2f
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * Context switch support for Hexagon
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <asm/asm-offsets.h>
+
+.text
+
+/*
+ * The register used as a fast-path thread information pointer
+ * is determined as a kernel configuration option.  If it happens
+ * to be a callee-save register, we're going to be saving and
+ * restoring it twice here.
+ *
+ * This code anticipates a revised ABI where R20-23 are added
+ * to the set of callee-save registers, but this should be
+ * backward compatible to legacy tools.
+ */
+
+
+/*
+ *     void switch_to(struct task_struct *prev,
+ *             struct task_struct *next, struct task_struct *last);
+ */
+       .p2align 2
+       .globl __switch_to
+       .type   __switch_to, @function
+
+/*
+ * When we exit the wormhole, we need to store the previous task
+ * in the new R0's pointer.  Technically it should be R2, but they should
+ * be the same; seems like a legacy thing.  In short, don't butcher
+ * R0, let it go back out unmolested.
+ */
+
+__switch_to:
+       /*
+        * Push callee-saves onto "prev" stack.
+        * Here, we're sneaky because the LR and FP
+        * storage of the thread_stack structure
+        * is automagically allocated by allocframe,
+        * so we pass struct size less 8.
+        */
+       allocframe(#(_SWITCH_STACK_SIZE - 8));
+       memd(R29+#(_SWITCH_R2726))=R27:26;
+       memd(R29+#(_SWITCH_R2524))=R25:24;
+       memd(R29+#(_SWITCH_R2322))=R23:22;
+       memd(R29+#(_SWITCH_R2120))=R21:20;
+       memd(R29+#(_SWITCH_R1918))=R19:18;
+       memd(R29+#(_SWITCH_R1716))=R17:16;
+       /* Stash thread_info pointer in task_struct */
+       memw(R0+#_TASK_THREAD_INFO) = THREADINFO_REG;
+       memw(R0 +#(_TASK_STRUCT_THREAD + _THREAD_STRUCT_SWITCH_SP)) = R29;
+       /* Switch to "next" stack and restore callee saves from there */
+       R29 = memw(R1 + #(_TASK_STRUCT_THREAD + _THREAD_STRUCT_SWITCH_SP));
+       {
+           R27:26 = memd(R29+#(_SWITCH_R2726));
+           R25:24 = memd(R29+#(_SWITCH_R2524));
+       }
+       {
+           R23:22 = memd(R29+#(_SWITCH_R2322));
+           R21:20 = memd(R29+#(_SWITCH_R2120));
+       }
+       {
+           R19:18 = memd(R29+#(_SWITCH_R1918));
+           R17:16 = memd(R29+#(_SWITCH_R1716));
+       }
+       {
+           /* THREADINFO_REG is currently one of the callee-saved regs
+            * above, and so be sure to re-load it last.
+            */
+           THREADINFO_REG = memw(R1 + #_TASK_THREAD_INFO);
+           R31:30 = memd(R29+#_SWITCH_FP);
+       }
+       {
+           R29 = add(R29,#_SWITCH_STACK_SIZE);
+           jumpr R31;
+       }
+       .size   __switch_to, .-__switch_to
diff --git a/arch/hexagon/kernel/vm_vectors.S b/arch/hexagon/kernel/vm_vectors.S
new file mode 100644 (file)
index 0000000..97a4b50
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Event jump tables
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <asm/hexagon_vm.h>
+
+.text
+
+/*  This is registered early on to allow angel  */
+.global _K_provisional_vec
+_K_provisional_vec:
+       jump 1f;
+       jump 1f;
+       jump 1f;
+       jump 1f;
+       jump 1f;
+       trap1(#HVM_TRAP1_VMRTE)
+       jump 1f;
+       jump 1f;
+
+
+.global _K_VM_event_vector
+_K_VM_event_vector:
+1:
+       jump 1b;  /*  Reset  */
+       jump _K_enter_machcheck;
+       jump _K_enter_genex;
+       jump 1b;  /*  3 Rsvd  */
+       jump 1b;  /*  4 Rsvd  */
+       jump _K_enter_trap0;
+       jump 1b;  /*  6 Rsvd  */
+       jump _K_enter_interrupt;
diff --git a/arch/hexagon/kernel/vmlinux.lds.S b/arch/hexagon/kernel/vmlinux.lds.S
new file mode 100644 (file)
index 0000000..071d3c3
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Linker script for Hexagon kernel
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#define LOAD_OFFSET PAGE_OFFSET
+
+#include <asm-generic/vmlinux.lds.h>
+#include <asm/asm-offsets.h>   /*  Most of the kernel defines are here  */
+#include <asm/mem-layout.h>    /*  except for page_offset  */
+#include <asm/cache.h>         /*  and now we're pulling cache line size  */
+OUTPUT_ARCH(hexagon)
+ENTRY(stext)
+
+jiffies = jiffies_64;
+
+/*
+See asm-generic/vmlinux.lds.h for expansion of some of these macros.
+See asm-generic/sections.h for seemingly required labels.
+*/
+
+#define PAGE_SIZE _PAGE_SIZE
+
+/*  This LOAD_OFFSET is temporary for debugging on the simulator; it may change
+    for hypervisor pseudo-physical memory.  */
+
+
+SECTIONS
+{
+       . = PAGE_OFFSET + LOAD_ADDRESS;
+
+       __init_begin = .;
+       HEAD_TEXT_SECTION
+       INIT_TEXT_SECTION(PAGE_SIZE)
+       PERCPU_SECTION(L1_CACHE_BYTES)
+       __init_end = .;
+
+        . = ALIGN(_PAGE_SIZE);
+       _stext = .;
+       .text : AT(ADDR(.text) - LOAD_OFFSET) {
+               _text = .;
+               TEXT_TEXT
+               SCHED_TEXT
+               LOCK_TEXT
+               KPROBES_TEXT
+               *(.fixup)
+       }
+       _etext = .;
+
+       INIT_DATA_SECTION(PAGE_SIZE)
+
+       _sdata = .;
+               RW_DATA_SECTION(32,PAGE_SIZE,PAGE_SIZE)
+               RO_DATA_SECTION(PAGE_SIZE)
+       _edata = .;
+
+       EXCEPTION_TABLE(16)
+       NOTES
+
+       BSS_SECTION(_PAGE_SIZE, _PAGE_SIZE, _PAGE_SIZE)
+
+       _end = .;
+
+       /DISCARD/ : {
+               EXIT_TEXT
+               EXIT_DATA
+               EXIT_CALL
+       }
+
+       STABS_DEBUG
+       DWARF_DEBUG
+
+}
diff --git a/arch/hexagon/lib/Makefile b/arch/hexagon/lib/Makefile
new file mode 100644 (file)
index 0000000..874655e
--- /dev/null
@@ -0,0 +1,4 @@
+#
+# Makefile for hexagon-specific library files.
+#
+obj-y = checksum.o io.o memcpy.o memset.o
diff --git a/arch/hexagon/lib/checksum.c b/arch/hexagon/lib/checksum.c
new file mode 100644 (file)
index 0000000..9300552
--- /dev/null
@@ -0,0 +1,203 @@
+/*
+ * Checksum functions for Hexagon
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/*  This was derived from arch/alpha/lib/checksum.c  */
+
+
+#include <linux/module.h>
+#include <linux/string.h>
+
+#include <asm/byteorder.h>
+#include <net/checksum.h>
+#include <linux/uaccess.h>
+#include <asm/intrinsics.h>
+
+
+/*  Vector value operations  */
+#define SIGN(x, y)     ((0x8000ULL*x)<<y)
+#define CARRY(x, y)    ((0x0002ULL*x)<<y)
+#define SELECT(x, y)   ((0x0001ULL*x)<<y)
+
+#define VR_NEGATE(a, b, c, d)  (SIGN(a, 48) + SIGN(b, 32) + SIGN(c, 16) \
+       + SIGN(d, 0))
+#define VR_CARRY(a, b, c, d)   (CARRY(a, 48) + CARRY(b, 32) + CARRY(c, 16) \
+       + CARRY(d, 0))
+#define VR_SELECT(a, b, c, d)  (SELECT(a, 48) + SELECT(b, 32) + SELECT(c, 16) \
+       + SELECT(d, 0))
+
+
+/* optimized HEXAGON V3 intrinsic version */
+static inline unsigned short from64to16(u64 x)
+{
+       u64 sum;
+
+       sum = HEXAGON_P_vrmpyh_PP(x^VR_NEGATE(1, 1, 1, 1),
+                            VR_SELECT(1, 1, 1, 1));
+       sum += VR_CARRY(0, 0, 1, 0);
+       sum = HEXAGON_P_vrmpyh_PP(sum, VR_SELECT(0, 0, 1, 1));
+
+       return 0xFFFF & sum;
+}
+
+/*
+ * computes the checksum of the TCP/UDP pseudo-header
+ * returns a 16-bit checksum, already complemented.
+ */
+__sum16 csum_tcpudp_magic(unsigned long saddr, unsigned long daddr,
+                         unsigned short len, unsigned short proto,
+                         __wsum sum)
+{
+       return (__force __sum16)~from64to16(
+               (__force u64)saddr + (__force u64)daddr +
+               (__force u64)sum + ((len + proto) << 8));
+}
+
+__wsum csum_tcpudp_nofold(unsigned long saddr, unsigned long daddr,
+                         unsigned short len, unsigned short proto,
+                         __wsum sum)
+{
+       u64 result;
+
+       result = (__force u64)saddr + (__force u64)daddr +
+                (__force u64)sum + ((len + proto) << 8);
+
+       /* Fold down to 32-bits so we don't lose in the typedef-less
+          network stack.  */
+       /* 64 to 33 */
+       result = (result & 0xffffffffUL) + (result >> 32);
+       /* 33 to 32 */
+       result = (result & 0xffffffffUL) + (result >> 32);
+       return (__force __wsum)result;
+}
+EXPORT_SYMBOL(csum_tcpudp_nofold);
+
+/*
+ * Do a 64-bit checksum on an arbitrary memory area..
+ *
+ * This isn't a great routine, but it's not _horrible_ either. The
+ * inner loop could be unrolled a bit further, and there are better
+ * ways to do the carry, but this is reasonable.
+ */
+
+/* optimized HEXAGON intrinsic version, with over read fixed */
+unsigned int do_csum(const void *voidptr, int len)
+{
+       u64 sum0, sum1, x0, x1, *ptr8_o, *ptr8_e, *ptr8;
+       int i, start, mid, end, mask;
+       const char *ptr = voidptr;
+       unsigned short *ptr2;
+       unsigned int *ptr4;
+
+       if (len <= 0)
+               return 0;
+
+       start = 0xF & (16-(((int) ptr) & 0xF)) ;
+       mask  = 0x7fffffffUL >> HEXAGON_R_cl0_R(len);
+       start = start & mask ;
+
+       mid = len - start;
+       end = mid & 0xF;
+       mid = mid>>4;
+       sum0 = mid << 18;
+       sum1 = 0;
+
+       if (start & 1)
+               sum0 += (u64) (ptr[0] << 8);
+       ptr2 = (unsigned short *) &ptr[start & 1];
+       if (start & 2)
+               sum1 += (u64) ptr2[0];
+       ptr4 = (unsigned int *) &ptr[start & 3];
+       if (start & 4) {
+               sum0 = HEXAGON_P_vrmpyhacc_PP(sum0,
+                       VR_NEGATE(0, 0, 1, 1)^((u64)ptr4[0]),
+                       VR_SELECT(0, 0, 1, 1));
+               sum0 += VR_SELECT(0, 0, 1, 0);
+       }
+       ptr8 = (u64 *) &ptr[start & 7];
+       if (start & 8) {
+               sum1 = HEXAGON_P_vrmpyhacc_PP(sum1,
+                       VR_NEGATE(1, 1, 1, 1)^(ptr8[0]),
+                       VR_SELECT(1, 1, 1, 1));
+               sum1 += VR_CARRY(0, 0, 1, 0);
+       }
+       ptr8_o = (u64 *) (ptr + start);
+       ptr8_e = (u64 *) (ptr + start + 8);
+
+       if (mid) {
+               x0 = *ptr8_e; ptr8_e += 2;
+               x1 = *ptr8_o; ptr8_o += 2;
+               if (mid > 1)
+                       for (i = 0; i < mid-1; i++) {
+                               sum0 = HEXAGON_P_vrmpyhacc_PP(sum0,
+                                       x0^VR_NEGATE(1, 1, 1, 1),
+                                       VR_SELECT(1, 1, 1, 1));
+                               sum1 = HEXAGON_P_vrmpyhacc_PP(sum1,
+                                       x1^VR_NEGATE(1, 1, 1, 1),
+                                       VR_SELECT(1, 1, 1, 1));
+                               x0 = *ptr8_e; ptr8_e += 2;
+                               x1 = *ptr8_o; ptr8_o += 2;
+                       }
+               sum0 = HEXAGON_P_vrmpyhacc_PP(sum0, x0^VR_NEGATE(1, 1, 1, 1),
+                       VR_SELECT(1, 1, 1, 1));
+               sum1 = HEXAGON_P_vrmpyhacc_PP(sum1, x1^VR_NEGATE(1, 1, 1, 1),
+                       VR_SELECT(1, 1, 1, 1));
+       }
+
+       ptr4 = (unsigned int *) &ptr[start + (mid * 16) + (end & 8)];
+       if (end & 4) {
+               sum1 = HEXAGON_P_vrmpyhacc_PP(sum1,
+                       VR_NEGATE(0, 0, 1, 1)^((u64)ptr4[0]),
+                       VR_SELECT(0, 0, 1, 1));
+               sum1 += VR_SELECT(0, 0, 1, 0);
+       }
+       ptr2 = (unsigned short *) &ptr[start + (mid * 16) + (end & 12)];
+       if (end & 2)
+               sum0 += (u64) ptr2[0];
+
+       if (end & 1)
+               sum1 += (u64) ptr[start + (mid * 16) + (end & 14)];
+
+       ptr8 = (u64 *) &ptr[start + (mid * 16)];
+       if (end & 8) {
+               sum0 = HEXAGON_P_vrmpyhacc_PP(sum0,
+                       VR_NEGATE(1, 1, 1, 1)^(ptr8[0]),
+                       VR_SELECT(1, 1, 1, 1));
+               sum0 += VR_CARRY(0, 0, 1, 0);
+       }
+       sum0 = HEXAGON_P_vrmpyh_PP((sum0+sum1)^VR_NEGATE(0, 0, 0, 1),
+               VR_SELECT(0, 0, 1, 1));
+       sum0 += VR_NEGATE(0, 0, 0, 1);
+       sum0 = HEXAGON_P_vrmpyh_PP(sum0, VR_SELECT(0, 0, 1, 1));
+
+       if (start & 1)
+               sum0 = (sum0 << 8) | (0xFF & (sum0 >> 8));
+
+       return 0xFFFF & sum0;
+}
+
+/*
+ * copy from ds while checksumming, otherwise like csum_partial
+ */
+__wsum
+csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum)
+{
+       memcpy(dst, src, len);
+       return csum_partial(dst, len, sum);
+}
diff --git a/arch/hexagon/lib/io.c b/arch/hexagon/lib/io.c
new file mode 100644 (file)
index 0000000..8ae47ba
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * I/O access functions for Hexagon
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <asm/io.h>
+
+/*  These are all FIFO routines!  */
+
+/*
+ * __raw_readsw - read words a short at a time
+ * @addr:  source address
+ * @data:  data address
+ * @len: number of shorts to read
+ */
+void __raw_readsw(const void __iomem *addr, void *data, int len)
+{
+       const volatile short int *src = (short int *) addr;
+       short int *dst = (short int *) data;
+
+       if ((u32)data & 0x1)
+               panic("unaligned pointer to readsw");
+
+       while (len-- > 0)
+               *dst++ = *src;
+
+}
+
+/*
+ * __raw_writesw - read words a short at a time
+ * @addr:  source address
+ * @data:  data address
+ * @len: number of shorts to read
+ */
+void __raw_writesw(void __iomem *addr, const void *data, int len)
+{
+       const short int *src = (short int *)data;
+       volatile short int *dst = (short int *)addr;
+
+       if ((u32)data & 0x1)
+               panic("unaligned pointer to writesw");
+
+       while (len-- > 0)
+               *dst = *src++;
+
+
+}
+
+/*  Pretty sure len is pre-adjusted for the length of the access already */
+void __raw_readsl(const void __iomem *addr, void *data, int len)
+{
+       const volatile long *src = (long *) addr;
+       long *dst = (long *) data;
+
+       if ((u32)data & 0x3)
+               panic("unaligned pointer to readsl");
+
+       while (len-- > 0)
+               *dst++ = *src;
+
+
+}
+
+void __raw_writesl(void __iomem *addr, const void *data, int len)
+{
+       const long *src = (long *)data;
+       volatile long *dst = (long *)addr;
+
+       if ((u32)data & 0x3)
+               panic("unaligned pointer to writesl");
+
+       while (len-- > 0)
+               *dst = *src++;
+
+
+}
diff --git a/arch/hexagon/lib/memcpy.S b/arch/hexagon/lib/memcpy.S
new file mode 100644 (file)
index 0000000..2101c33
--- /dev/null
@@ -0,0 +1,543 @@
+/*
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/*
+ * Description
+ *
+ *   library function for memcpy where length bytes are copied from
+ *   ptr_in to ptr_out. ptr_out is returned unchanged.
+ *   Allows any combination of alignment on input and output pointers
+ *   and length from 0 to 2^32-1
+ *
+ * Restrictions
+ *   The arrays should not overlap, the program will produce undefined output
+ *   if they do.
+ *   For blocks less than 16 bytes a byte by byte copy is performed. For
+ *   8byte alignments, and length multiples, a dword copy is performed up to
+ *   96bytes
+ * History
+ *
+ *   DJH  5/15/09 Initial version 1.0
+ *   DJH  6/ 1/09 Version 1.1 modified ABI to inlcude R16-R19
+ *   DJH  7/12/09 Version 1.2 optimized codesize down to 760 was 840
+ *   DJH 10/14/09 Version 1.3 added special loop for aligned case, was
+ *                            overreading bloated codesize back up to 892
+ *   DJH  4/20/10 Version 1.4 fixed Ldword_loop_epilog loop to prevent loads
+ *                            occuring if only 1 left outstanding, fixes bug
+ *                            # 3888, corrected for all alignments. Peeled off
+ *                            1 32byte chunk from kernel loop and extended 8byte
+ *                            loop at end to solve all combinations and prevent
+ *                            over read.  Fixed Ldword_loop_prolog to prevent
+ *                            overread for blocks less than 48bytes. Reduced
+ *                            codesize to 752 bytes
+ *   DJH  4/21/10 version 1.5 1.4 fix broke code for input block ends not
+ *                            aligned to dword boundaries,underwriting by 1
+ *                            byte, added detection for this and fixed. A
+ *                            little bloat.
+ *   DJH  4/23/10 version 1.6 corrected stack error, R20 was not being restored
+ *                            always, fixed the error of R20 being modified
+ *                            before it was being saved
+ * Natural c model
+ * ===============
+ * void * memcpy(char * ptr_out, char * ptr_in, int length) {
+ *   int i;
+ *   if(length) for(i=0; i < length; i++) { ptr_out[i] = ptr_in[i]; }
+ *   return(ptr_out);
+ * }
+ *
+ * Optimized memcpy function
+ * =========================
+ * void * memcpy(char * ptr_out, char * ptr_in, int len) {
+ *   int i, prolog, kernel, epilog, mask;
+ *   u8 offset;
+ *   s64 data0, dataF8, data70;
+ *
+ *   s64 * ptr8_in;
+ *   s64 * ptr8_out;
+ *   s32 * ptr4;
+ *   s16 * ptr2;
+ *
+ *   offset = ((int) ptr_in) & 7;
+ *   ptr8_in = (s64 *) &ptr_in[-offset];   //read in the aligned pointers
+ *
+ *   data70 = *ptr8_in++;
+ *   dataF8 = *ptr8_in++;
+ *
+ *   data0 = HEXAGON_P_valignb_PPp(dataF8, data70, offset);
+ *
+ *   prolog = 32 - ((int) ptr_out);
+ *   mask  = 0x7fffffff >> HEXAGON_R_cl0_R(len);
+ *   prolog = prolog & mask;
+ *   kernel = len - prolog;
+ *   epilog = kernel & 0x1F;
+ *   kernel = kernel>>5;
+ *
+ *   if (prolog & 1) { ptr_out[0] = (u8) data0; data0 >>= 8; ptr_out += 1;}
+ *   ptr2 = (s16 *) &ptr_out[0];
+ *   if (prolog & 2) { ptr2[0] = (u16) data0;  data0 >>= 16; ptr_out += 2;}
+ *   ptr4 = (s32 *) &ptr_out[0];
+ *   if (prolog & 4) { ptr4[0] = (u32) data0;  data0 >>= 32; ptr_out += 4;}
+ *
+ *   offset = offset + (prolog & 7);
+ *   if (offset >= 8) {
+ *     data70 = dataF8;
+ *     dataF8 = *ptr8_in++;
+ *   }
+ *   offset = offset & 0x7;
+ *
+ *   prolog = prolog >> 3;
+ *   if (prolog) for (i=0; i < prolog; i++) {
+ *       data0 = HEXAGON_P_valignb_PPp(dataF8, data70, offset);
+ *       ptr8_out = (s64 *) &ptr_out[0]; *ptr8_out = data0; ptr_out += 8;
+ *       data70 = dataF8;
+ *       dataF8 = *ptr8_in++;
+ *   }
+ *   if(kernel) { kernel -= 1; epilog += 32; }
+ *   if(kernel) for(i=0; i < kernel; i++) {
+ *       data0 = HEXAGON_P_valignb_PPp(dataF8, data70, offset);
+ *       ptr8_out = (s64 *) &ptr_out[0]; *ptr8_out = data0; ptr_out += 8;
+ *       data70 = *ptr8_in++;
+ *
+ *       data0 = HEXAGON_P_valignb_PPp(data70, dataF8, offset);
+ *       ptr8_out = (s64 *) &ptr_out[0]; *ptr8_out = data0; ptr_out += 8;
+ *       dataF8 = *ptr8_in++;
+ *
+ *       data0 = HEXAGON_P_valignb_PPp(dataF8, data70, offset);
+ *       ptr8_out = (s64 *) &ptr_out[0]; *ptr8_out = data0; ptr_out += 8;
+ *       data70 = *ptr8_in++;
+ *
+ *       data0 = HEXAGON_P_valignb_PPp(data70, dataF8, offset);
+ *       ptr8_out = (s64 *) &ptr_out[0]; *ptr8_out = data0; ptr_out += 8;
+ *       dataF8 = *ptr8_in++;
+ *   }
+ *   epilogdws = epilog >> 3;
+ *   if (epilogdws) for (i=0; i < epilogdws; i++) {
+ *       data0 = HEXAGON_P_valignb_PPp(dataF8, data70, offset);
+ *       ptr8_out = (s64 *) &ptr_out[0]; *ptr8_out = data0; ptr_out += 8;
+ *       data70 = dataF8;
+ *       dataF8 = *ptr8_in++;
+ *   }
+ *   data0 = HEXAGON_P_valignb_PPp(dataF8, data70, offset);
+ *
+ *   ptr4 = (s32 *) &ptr_out[0];
+ *   if (epilog & 4) { ptr4[0] = (u32) data0; data0 >>= 32; ptr_out += 4;}
+ *   ptr2 = (s16 *) &ptr_out[0];
+ *   if (epilog & 2) { ptr2[0] = (u16) data0; data0 >>= 16; ptr_out += 2;}
+ *   if (epilog & 1) { *ptr_out++ = (u8) data0; }
+ *
+ *   return(ptr_out - length);
+ * }
+ *
+ * Codesize : 784 bytes
+ */
+
+
+#define ptr_out                R0      /*  destination  pounter  */
+#define ptr_in         R1      /*  source pointer  */
+#define len            R2      /*  length of copy in bytes  */
+
+#define data70         R13:12  /*  lo 8 bytes of non-aligned transfer  */
+#define dataF8         R11:10  /*  hi 8 bytes of non-aligned transfer  */
+#define ldata0         R7:6    /*  even 8 bytes chunks  */
+#define ldata1         R25:24  /*  odd 8 bytes chunks  */
+#define data1          R7      /*  lower 8 bytes of ldata1  */
+#define data0          R6      /*  lower 8 bytes of ldata0  */
+
+#define ifbyte         p0      /*  if transfer has bytes in epilog/prolog  */
+#define ifhword                p0      /*  if transfer has shorts in epilog/prolog  */
+#define ifword         p0      /*  if transfer has words in epilog/prolog  */
+#define noprolog       p0      /*  no prolog, xfer starts at 32byte  */
+#define nokernel       p1      /*  no 32byte multiple block in the transfer  */
+#define noepilog       p0      /*  no epilog, xfer ends on 32byte boundary  */
+#define align          p2      /*  alignment of input rel to 8byte boundary  */
+#define kernel1                p0      /*  kernel count == 1  */
+
+#define dalign         R25     /*  rel alignment of input to output data  */
+#define star3          R16     /*  number bytes in prolog - dwords  */
+#define rest           R8      /*  length - prolog bytes  */
+#define back           R7      /*  nr bytes > dword boundary in src block  */
+#define epilog         R3      /*  bytes in epilog  */
+#define inc            R15:14  /*  inc kernel by -1 and defetch ptr by 32  */
+#define kernel         R4      /*  number of 32byte chunks in kernel  */
+#define ptr_in_p_128   R5      /*  pointer for prefetch of input data  */
+#define mask           R8      /*  mask used to determine prolog size  */
+#define shift          R8      /*  used to work a shifter to extract bytes  */
+#define shift2         R5      /*  in epilog to workshifter to extract bytes */
+#define prolog         R15     /*  bytes in  prolog  */
+#define epilogdws      R15     /*  number dwords in epilog  */
+#define shiftb         R14     /*  used to extract bytes  */
+#define offset         R9      /*  same as align in reg  */
+#define ptr_out_p_32   R17     /*  pointer to output dczero  */
+#define align888       R14     /*  if simple dword loop can be used  */
+#define len8           R9      /*  number of dwords in length  */
+#define over           R20     /*  nr of bytes > last inp buf dword boundary */
+
+#define ptr_in_p_128kernel     R5:4    /*  packed fetch pointer & kernel cnt */
+
+       .section .text
+       .p2align 4
+        .global memcpy
+        .type memcpy, @function
+memcpy:
+{
+       p2 = cmp.eq(len, #0);           /*  =0 */
+       align888 = or(ptr_in, ptr_out); /*  %8 < 97 */
+       p0 = cmp.gtu(len, #23);         /*  %1, <24 */
+       p1 = cmp.eq(ptr_in, ptr_out);   /*  attempt to overwrite self */
+}
+{
+       p1 = or(p2, p1);
+       p3 = cmp.gtu(len, #95);         /*  %8 < 97 */
+       align888 = or(align888, len);   /*  %8 < 97 */
+       len8 = lsr(len, #3);            /*  %8 < 97 */
+}
+{
+       dcfetch(ptr_in);                /*  zero/ptrin=ptrout causes fetch */
+       p2 = bitsclr(align888, #7);     /*  %8 < 97  */
+       if(p1) jumpr r31;               /*  =0  */
+}
+{
+       p2 = and(p2,!p3);                       /*  %8 < 97  */
+       if (p2.new) len = add(len, #-8);        /*  %8 < 97  */
+       if (p2.new) jump:NT .Ldwordaligned;     /*  %8 < 97  */
+}
+{
+       if(!p0) jump .Lbytes23orless;   /*  %1, <24  */
+       mask.l = #LO(0x7fffffff);
+       /*  all bytes before line multiples of data  */
+       prolog = sub(#0, ptr_out);
+}
+{
+       /*  save r31 on stack, decrement sp by 16  */
+       allocframe(#24);
+       mask.h = #HI(0x7fffffff);
+       ptr_in_p_128 = add(ptr_in, #32);
+       back = cl0(len);
+}
+{
+       memd(sp+#0) = R17:16;           /*  save r16,r17 on stack6  */
+       r31.l = #LO(.Lmemcpy_return);   /*  set up final return pointer  */
+       prolog &= lsr(mask, back);
+       offset = and(ptr_in, #7);
+}
+{
+       memd(sp+#8) = R25:24;           /*  save r25,r24 on stack  */
+       dalign = sub(ptr_out, ptr_in);
+       r31.h = #HI(.Lmemcpy_return);   /*  set up final return pointer  */
+}
+{
+       /*  see if there if input buffer end if aligned  */
+       over = add(len, ptr_in);
+       back = add(len, offset);
+       memd(sp+#16) = R21:20;          /*  save r20,r21 on stack  */
+}
+{
+       noprolog = bitsclr(prolog, #7);
+       prolog = and(prolog, #31);
+       dcfetch(ptr_in_p_128);
+       ptr_in_p_128 = add(ptr_in_p_128, #32);
+}
+{
+       kernel = sub(len, prolog);
+       shift = asl(prolog, #3);
+       star3 = and(prolog, #7);
+       ptr_in = and(ptr_in, #-8);
+}
+{
+       prolog = lsr(prolog, #3);
+       epilog = and(kernel, #31);
+       ptr_out_p_32 = add(ptr_out, prolog);
+       over = and(over, #7);
+}
+{
+       p3 = cmp.gtu(back, #8);
+       kernel = lsr(kernel, #5);
+       dcfetch(ptr_in_p_128);
+       ptr_in_p_128 = add(ptr_in_p_128, #32);
+}
+{
+       p1 = cmp.eq(prolog, #0);
+       if(!p1.new) prolog = add(prolog, #1);
+       dcfetch(ptr_in_p_128);  /*  reserve the line 64bytes on  */
+       ptr_in_p_128 = add(ptr_in_p_128, #32);
+}
+{
+       nokernel = cmp.eq(kernel,#0);
+       dcfetch(ptr_in_p_128);  /* reserve the line 64bytes on  */
+       ptr_in_p_128 = add(ptr_in_p_128, #32);
+       shiftb = and(shift, #8);
+}
+{
+       dcfetch(ptr_in_p_128);          /*  reserve the line 64bytes on  */
+       ptr_in_p_128 = add(ptr_in_p_128, #32);
+       if(nokernel) jump .Lskip64;
+       p2 = cmp.eq(kernel, #1);        /*  skip ovr if kernel == 0  */
+}
+{
+       dczeroa(ptr_out_p_32);
+       /*  don't advance pointer  */
+       if(!p2) ptr_out_p_32 = add(ptr_out_p_32, #32);
+}
+{
+       dalign = and(dalign, #31);
+       dczeroa(ptr_out_p_32);
+}
+.Lskip64:
+{
+       data70 = memd(ptr_in++#16);
+       if(p3) dataF8 = memd(ptr_in+#8);
+       if(noprolog) jump .Lnoprolog32;
+       align = offset;
+}
+/*  upto initial 7 bytes  */
+{
+       ldata0 = valignb(dataF8, data70, align);
+       ifbyte = tstbit(shift,#3);
+       offset = add(offset, star3);
+}
+{
+       if(ifbyte) memb(ptr_out++#1) = data0;
+       ldata0 = lsr(ldata0, shiftb);
+       shiftb = and(shift, #16);
+       ifhword = tstbit(shift,#4);
+}
+{
+       if(ifhword) memh(ptr_out++#2) = data0;
+       ldata0 = lsr(ldata0, shiftb);
+       ifword = tstbit(shift,#5);
+       p2 = cmp.gtu(offset, #7);
+}
+{
+       if(ifword) memw(ptr_out++#4) = data0;
+       if(p2) data70 = dataF8;
+       if(p2) dataF8 = memd(ptr_in++#8);       /*  another 8 bytes  */
+       align = offset;
+}
+.Lnoprolog32:
+{
+       p3 = sp1loop0(.Ldword_loop_prolog, prolog)
+       rest = sub(len, star3); /*  whats left after the loop  */
+       p0 = cmp.gt(over, #0);
+}
+       if(p0) rest = add(rest, #16);
+.Ldword_loop_prolog:
+{
+       if(p3) memd(ptr_out++#8) = ldata0;
+       ldata0 = valignb(dataF8, data70, align);
+       p0 = cmp.gt(rest, #16);
+}
+{
+       data70 = dataF8;
+       if(p0) dataF8 = memd(ptr_in++#8);
+       rest = add(rest, #-8);
+}:endloop0
+.Lkernel:
+{
+       /*  kernel is at least 32bytes  */
+       p3 = cmp.gtu(kernel, #0);
+       /*  last itn. remove edge effects  */
+       if(p3.new) kernel = add(kernel, #-1);
+       /*  dealt with in last dword loop  */
+       if(p3.new) epilog = add(epilog, #32);
+}
+{
+       nokernel = cmp.eq(kernel, #0);          /*  after adjustment, recheck */
+       if(nokernel.new) jump:NT .Lepilog;      /*  likely not taken  */
+       inc = combine(#32, #-1);
+       p3 = cmp.gtu(dalign, #24);
+}
+{
+       if(p3) jump .Lodd_alignment;
+}
+{
+       loop0(.Loword_loop_25to31, kernel);
+       kernel1 = cmp.gtu(kernel, #1);
+       rest = kernel;
+}
+       .falign
+.Loword_loop_25to31:
+{
+       dcfetch(ptr_in_p_128);  /*  prefetch 4 lines ahead  */
+       if(kernel1) ptr_out_p_32 = add(ptr_out_p_32, #32);
+}
+{
+       dczeroa(ptr_out_p_32);  /*  reserve the next 32bytes in cache  */
+       p3 = cmp.eq(kernel, rest);
+}
+{
+       /*  kernel -= 1  */
+       ptr_in_p_128kernel = vaddw(ptr_in_p_128kernel, inc);
+       /*  kill write on first iteration  */
+       if(!p3) memd(ptr_out++#8) = ldata1;
+       ldata1 = valignb(dataF8, data70, align);
+       data70 = memd(ptr_in++#8);
+}
+{
+       memd(ptr_out++#8) = ldata0;
+       ldata0 = valignb(data70, dataF8, align);
+       dataF8 = memd(ptr_in++#8);
+}
+{
+       memd(ptr_out++#8) = ldata1;
+       ldata1 = valignb(dataF8, data70, align);
+       data70 = memd(ptr_in++#8);
+}
+{
+       memd(ptr_out++#8) = ldata0;
+       ldata0 = valignb(data70, dataF8, align);
+       dataF8 = memd(ptr_in++#8);
+       kernel1 = cmp.gtu(kernel, #1);
+}:endloop0
+{
+       memd(ptr_out++#8) = ldata1;
+       jump .Lepilog;
+}
+.Lodd_alignment:
+{
+       loop0(.Loword_loop_00to24, kernel);
+       kernel1 = cmp.gtu(kernel, #1);
+       rest = add(kernel, #-1);
+}
+       .falign
+.Loword_loop_00to24:
+{
+       dcfetch(ptr_in_p_128);  /*  prefetch 4 lines ahead  */
+       ptr_in_p_128kernel = vaddw(ptr_in_p_128kernel, inc);
+       if(kernel1) ptr_out_p_32 = add(ptr_out_p_32, #32);
+}
+{
+       dczeroa(ptr_out_p_32);  /*  reserve the next 32bytes in cache  */
+}
+{
+       memd(ptr_out++#8) = ldata0;
+       ldata0 = valignb(dataF8, data70, align);
+       data70 = memd(ptr_in++#8);
+}
+{
+       memd(ptr_out++#8) = ldata0;
+       ldata0 = valignb(data70, dataF8, align);
+       dataF8 = memd(ptr_in++#8);
+}
+{
+       memd(ptr_out++#8) = ldata0;
+       ldata0 = valignb(dataF8, data70, align);
+       data70 = memd(ptr_in++#8);
+}
+{
+       memd(ptr_out++#8) = ldata0;
+       ldata0 = valignb(data70, dataF8, align);
+       dataF8 = memd(ptr_in++#8);
+       kernel1 = cmp.gtu(kernel, #1);
+}:endloop0
+.Lepilog:
+{
+       noepilog = cmp.eq(epilog,#0);
+       epilogdws = lsr(epilog, #3);
+       kernel = and(epilog, #7);
+}
+{
+       if(noepilog) jumpr r31;
+       if(noepilog) ptr_out = sub(ptr_out, len);
+       p3 = cmp.eq(epilogdws, #0);
+       shift2 = asl(epilog, #3);
+}
+{
+       shiftb = and(shift2, #32);
+       ifword = tstbit(epilog,#2);
+       if(p3) jump .Lepilog60;
+       if(!p3) epilog = add(epilog, #-16);
+}
+{
+       loop0(.Ldword_loop_epilog, epilogdws);
+       /*  stop criteria is lsbs unless = 0 then its 8  */
+       p3 = cmp.eq(kernel, #0);
+       if(p3.new) kernel= #8;
+       p1 = cmp.gt(over, #0);
+}
+       /*  if not aligned to end of buffer execute 1 more iteration  */
+       if(p1) kernel= #0;
+.Ldword_loop_epilog:
+{
+       memd(ptr_out++#8) = ldata0;
+       ldata0 = valignb(dataF8, data70, align);
+       p3 = cmp.gt(epilog, kernel);
+}
+{
+       data70 = dataF8;
+       if(p3) dataF8 = memd(ptr_in++#8);
+       epilog = add(epilog, #-8);
+}:endloop0
+/* copy last 7 bytes */
+.Lepilog60:
+{
+       if(ifword) memw(ptr_out++#4) = data0;
+       ldata0 = lsr(ldata0, shiftb);
+       ifhword = tstbit(epilog,#1);
+       shiftb = and(shift2, #16);
+}
+{
+       if(ifhword) memh(ptr_out++#2) = data0;
+       ldata0 = lsr(ldata0, shiftb);
+       ifbyte = tstbit(epilog,#0);
+       if(ifbyte.new) len = add(len, #-1);
+}
+{
+       if(ifbyte) memb(ptr_out) = data0;
+       ptr_out = sub(ptr_out, len);    /*  return dest pointer  */
+        jumpr r31;
+}
+/*  do byte copy for small n  */
+.Lbytes23orless:
+{
+       p3 = sp1loop0(.Lbyte_copy, len);
+       len = add(len, #-1);
+}
+.Lbyte_copy:
+{
+       data0 = memb(ptr_in++#1);
+       if(p3) memb(ptr_out++#1) = data0;
+}:endloop0
+{
+       memb(ptr_out) = data0;
+       ptr_out = sub(ptr_out, len);
+       jumpr r31;
+}
+/*  do dword copies for aligned in, out and length  */
+.Ldwordaligned:
+{
+       p3 = sp1loop0(.Ldword_copy, len8);
+}
+.Ldword_copy:
+{
+       if(p3) memd(ptr_out++#8) = ldata0;
+       ldata0 = memd(ptr_in++#8);
+}:endloop0
+{
+       memd(ptr_out) = ldata0;
+       ptr_out = sub(ptr_out, len);
+       jumpr r31;      /*  return to function caller  */
+}
+.Lmemcpy_return:
+       r21:20 = memd(sp+#16);  /*  restore r20+r21  */
+{
+       r25:24 = memd(sp+#8);   /*  restore r24+r25  */
+       r17:16 = memd(sp+#0);   /*  restore r16+r17  */
+}
+       deallocframe;   /*  restore r31 and incrment stack by 16  */
+       jumpr r31
diff --git a/arch/hexagon/lib/memset.S b/arch/hexagon/lib/memset.S
new file mode 100644 (file)
index 0000000..26d9614
--- /dev/null
@@ -0,0 +1,315 @@
+/*
+ * Copyright (c) 2011 Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+
+/* HEXAGON assembly optimized memset */
+/* Replaces the standard library function memset */
+
+
+        .macro HEXAGON_OPT_FUNC_BEGIN name
+       .text
+       .p2align 4
+       .globl \name
+       .type  \name, @function
+\name:
+       .endm
+
+       .macro HEXAGON_OPT_FUNC_FINISH name
+       .size  \name, . - \name
+       .endm
+
+/* FUNCTION: memset (v2 version) */
+#if __HEXAGON_ARCH__ < 3
+HEXAGON_OPT_FUNC_BEGIN memset
+       {
+               r6 = #8
+               r7 = extractu(r0, #3 , #0)
+               p0 = cmp.eq(r2, #0)
+               p1 = cmp.gtu(r2, #7)
+       }
+       {
+               r4 = vsplatb(r1)
+               r8 = r0           /* leave r0 intact for return val  */
+               r9 = sub(r6, r7)  /* bytes until double alignment  */
+               if p0 jumpr r31   /* count == 0, so return  */
+       }
+       {
+               r3 = #0
+               r7 = #0
+               p0 = tstbit(r9, #0)
+               if p1 jump 2f /* skip byte loop */
+       }
+
+/* less than 8 bytes to set, so just set a byte at a time and return  */
+
+               loop0(1f, r2) /* byte loop */
+       .falign
+1: /* byte loop */
+       {
+               memb(r8++#1) = r4
+       }:endloop0
+               jumpr r31
+       .falign
+2: /* skip byte loop */
+       {
+               r6 = #1
+               p0 = tstbit(r9, #1)
+               p1 = cmp.eq(r2, #1)
+               if !p0 jump 3f /* skip initial byte store */
+       }
+       {
+               memb(r8++#1) = r4
+               r3:2 = sub(r3:2, r7:6)
+               if p1 jumpr r31
+       }
+       .falign
+3: /* skip initial byte store */
+       {
+               r6 = #2
+               p0 = tstbit(r9, #2)
+               p1 = cmp.eq(r2, #2)
+               if !p0 jump 4f /* skip initial half store */
+       }
+       {
+               memh(r8++#2) = r4
+               r3:2 = sub(r3:2, r7:6)
+               if p1 jumpr r31
+       }
+       .falign
+4: /* skip initial half store */
+       {
+               r6 = #4
+               p0 = cmp.gtu(r2, #7)
+               p1 = cmp.eq(r2, #4)
+               if !p0 jump 5f /* skip initial word store */
+       }
+       {
+               memw(r8++#4) = r4
+               r3:2 = sub(r3:2, r7:6)
+               p0 = cmp.gtu(r2, #11)
+               if p1 jumpr r31
+       }
+       .falign
+5: /* skip initial word store */
+       {
+               r10 = lsr(r2, #3)
+               p1 = cmp.eq(r3, #1)
+               if !p0 jump 7f /* skip double loop */
+       }
+       {
+               r5 = r4
+               r6 = #8
+               loop0(6f, r10) /* double loop */
+       }
+
+/* set bytes a double word at a time  */
+
+       .falign
+6: /* double loop */
+       {
+               memd(r8++#8) = r5:4
+               r3:2 = sub(r3:2, r7:6)
+               p1 = cmp.eq(r2, #8)
+       }:endloop0
+       .falign
+7: /* skip double loop */
+       {
+               p0 = tstbit(r2, #2)
+               if p1 jumpr r31
+       }
+       {
+               r6 = #4
+               p0 = tstbit(r2, #1)
+               p1 = cmp.eq(r2, #4)
+               if !p0 jump 8f /* skip final word store */
+       }
+       {
+               memw(r8++#4) = r4
+               r3:2 = sub(r3:2, r7:6)
+               if p1 jumpr r31
+       }
+       .falign
+8: /* skip final word store */
+       {
+               p1 = cmp.eq(r2, #2)
+               if !p0 jump 9f /* skip final half store */
+       }
+       {
+               memh(r8++#2) = r4
+               if p1 jumpr r31
+       }
+       .falign
+9: /* skip final half store */
+       {
+               memb(r8++#1) = r4
+               jumpr r31
+       }
+HEXAGON_OPT_FUNC_FINISH memset
+#endif
+
+
+/*  FUNCTION: memset (v3 and higher version)  */
+#if __HEXAGON_ARCH__ >= 3
+HEXAGON_OPT_FUNC_BEGIN memset
+       {
+               r7=vsplatb(r1)
+               r6 = r0
+               if (r2==#0) jump:nt .L1
+       }
+       {
+               r5:4=combine(r7,r7)
+               p0 = cmp.gtu(r2,#8)
+               if (p0.new) jump:nt .L3
+       }
+       {
+               r3 = r0
+               loop0(.L47,r2)
+       }
+       .falign
+.L47:
+       {
+               memb(r3++#1) = r1
+       }:endloop0 /* start=.L47 */
+               jumpr r31
+.L3:
+       {
+               p0 = tstbit(r0,#0)
+               if (!p0.new) jump:nt .L8
+               p1 = cmp.eq(r2, #1)
+       }
+       {
+               r6 = add(r0, #1)
+               r2 = add(r2,#-1)
+               memb(r0) = r1
+               if (p1) jump .L1
+       }
+.L8:
+       {
+               p0 = tstbit(r6,#1)
+               if (!p0.new) jump:nt .L10
+       }
+       {
+               r2 = add(r2,#-2)
+               memh(r6++#2) = r7
+               p0 = cmp.eq(r2, #2)
+               if (p0.new) jump:nt .L1
+       }
+.L10:
+       {
+               p0 = tstbit(r6,#2)
+               if (!p0.new) jump:nt .L12
+       }
+       {
+               r2 = add(r2,#-4)
+               memw(r6++#4) = r7
+               p0 = cmp.eq(r2, #4)
+               if (p0.new) jump:nt .L1
+       }
+.L12:
+       {
+               p0 = cmp.gtu(r2,#127)
+               if (!p0.new) jump:nt .L14
+       }
+               r3 = and(r6,#31)
+               if (r3==#0) jump:nt .L17
+       {
+               memd(r6++#8) = r5:4
+               r2 = add(r2,#-8)
+       }
+               r3 = and(r6,#31)
+               if (r3==#0) jump:nt .L17
+       {
+               memd(r6++#8) = r5:4
+               r2 = add(r2,#-8)
+       }
+               r3 = and(r6,#31)
+               if (r3==#0) jump:nt .L17
+       {
+               memd(r6++#8) = r5:4
+               r2 = add(r2,#-8)
+       }
+.L17:
+       {
+               r3 = lsr(r2,#5)
+               if (r1!=#0) jump:nt .L18
+       }
+       {
+               r8 = r3
+               r3 = r6
+               loop0(.L46,r3)
+       }
+       .falign
+.L46:
+       {
+               dczeroa(r6)
+               r6 = add(r6,#32)
+               r2 = add(r2,#-32)
+       }:endloop0 /* start=.L46 */
+.L14:
+       {
+               p0 = cmp.gtu(r2,#7)
+               if (!p0.new) jump:nt .L28
+               r8 = lsr(r2,#3)
+       }
+               loop0(.L44,r8)
+       .falign
+.L44:
+       {
+               memd(r6++#8) = r5:4
+               r2 = add(r2,#-8)
+       }:endloop0 /* start=.L44 */
+.L28:
+       {
+               p0 = tstbit(r2,#2)
+               if (!p0.new) jump:nt .L33
+       }
+       {
+               r2 = add(r2,#-4)
+               memw(r6++#4) = r7
+       }
+.L33:
+       {
+               p0 = tstbit(r2,#1)
+               if (!p0.new) jump:nt .L35
+       }
+       {
+               r2 = add(r2,#-2)
+               memh(r6++#2) = r7
+       }
+.L35:
+               p0 = cmp.eq(r2,#1)
+               if (p0) memb(r6) = r1
+.L1:
+               jumpr r31
+.L18:
+               loop0(.L45,r3)
+       .falign
+.L45:
+               dczeroa(r6)
+       {
+               memd(r6++#8) = r5:4
+               r2 = add(r2,#-32)
+       }
+               memd(r6++#8) = r5:4
+               memd(r6++#8) = r5:4
+       {
+               memd(r6++#8) = r5:4
+       }:endloop0 /* start=.L45  */
+               jump .L14
+HEXAGON_OPT_FUNC_FINISH memset
+#endif
diff --git a/arch/hexagon/mm/Makefile b/arch/hexagon/mm/Makefile
new file mode 100644 (file)
index 0000000..1a0be4d
--- /dev/null
@@ -0,0 +1,6 @@
+#
+# Makefile for Hexagon memory management subsystem
+#
+
+obj-y := init.o pgalloc.o ioremap.o uaccess.o vm_fault.o cache.o
+obj-y += copy_to_user.o copy_from_user.o strnlen_user.o vm_tlb.o
diff --git a/arch/hexagon/mm/cache.c b/arch/hexagon/mm/cache.c
new file mode 100644 (file)
index 0000000..c5cf6ee
--- /dev/null
@@ -0,0 +1,128 @@
+/*
+ * Cache management functions for Hexagon
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <linux/mm.h>
+#include <asm/cacheflush.h>
+#include <asm/hexagon_vm.h>
+
+#define spanlines(start, end) \
+       (((end - (start & ~(LINESIZE - 1))) >> LINEBITS) + 1)
+
+void flush_dcache_range(unsigned long start, unsigned long end)
+{
+       unsigned long lines = spanlines(start, end-1);
+       unsigned long i, flags;
+
+       start &= ~(LINESIZE - 1);
+
+       local_irq_save(flags);
+
+       for (i = 0; i < lines; i++) {
+               __asm__ __volatile__ (
+               "       dccleaninva(%0);        "
+               :
+               : "r" (start)
+               );
+               start += LINESIZE;
+       }
+       local_irq_restore(flags);
+}
+
+void flush_icache_range(unsigned long start, unsigned long end)
+{
+       unsigned long lines = spanlines(start, end-1);
+       unsigned long i, flags;
+
+       start &= ~(LINESIZE - 1);
+
+       local_irq_save(flags);
+
+       for (i = 0; i < lines; i++) {
+               __asm__ __volatile__ (
+                       "       dccleana(%0); "
+                       "       icinva(%0);     "
+                       :
+                       : "r" (start)
+               );
+               start += LINESIZE;
+       }
+       __asm__ __volatile__ (
+               "isync"
+       );
+       local_irq_restore(flags);
+}
+
+void hexagon_clean_dcache_range(unsigned long start, unsigned long end)
+{
+       unsigned long lines = spanlines(start, end-1);
+       unsigned long i, flags;
+
+       start &= ~(LINESIZE - 1);
+
+       local_irq_save(flags);
+
+       for (i = 0; i < lines; i++) {
+               __asm__ __volatile__ (
+               "       dccleana(%0);   "
+               :
+               : "r" (start)
+               );
+               start += LINESIZE;
+       }
+       local_irq_restore(flags);
+}
+
+void hexagon_inv_dcache_range(unsigned long start, unsigned long end)
+{
+       unsigned long lines = spanlines(start, end-1);
+       unsigned long i, flags;
+
+       start &= ~(LINESIZE - 1);
+
+       local_irq_save(flags);
+
+       for (i = 0; i < lines; i++) {
+               __asm__ __volatile__ (
+               "       dcinva(%0);     "
+               :
+               : "r" (start)
+               );
+               start += LINESIZE;
+       }
+       local_irq_restore(flags);
+}
+
+
+
+
+/*
+ * This is just really brutal and shouldn't be used anyways,
+ * especially on V2.  Left here just in case.
+ */
+void flush_cache_all_hexagon(void)
+{
+       unsigned long flags;
+       local_irq_save(flags);
+       __vmcache_ickill();
+       __vmcache_dckill();
+       __vmcache_l2kill();
+       local_irq_restore(flags);
+       mb();
+}
diff --git a/arch/hexagon/mm/copy_from_user.S b/arch/hexagon/mm/copy_from_user.S
new file mode 100644 (file)
index 0000000..8eb1d4d
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ * User memory copy functions for kernel
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/*
+ * The right way to do this involves valignb
+ * The easy way to do this is only speed up src/dest similar alignment.
+ */
+
+/*
+ * Copy to/from user are the same, except that for packets with a load and
+ * a store, I don't know how to tell which kind of exception we got.
+ * Therefore, we duplicate the function, and handle faulting addresses
+ * differently for each function
+ */
+
+/*
+ * copy from user: loads can fault
+ */
+#define src_sav r13
+#define dst_sav r12
+#define src_dst_sav r13:12
+#define d_dbuf r15:14
+#define w_dbuf r15
+
+#define dst r0
+#define src r1
+#define bytes r2
+#define loopcount r5
+
+#define FUNCNAME __copy_from_user_hexagon
+#include "copy_user_template.S"
+
+       /* LOAD FAULTS from COPY_FROM_USER */
+
+       /* Alignment loop.  r2 has been updated. Return it. */
+       .falign
+1009:
+2009:
+4009:
+       {
+               r0 = r2
+               jumpr r31
+       }
+       /* Normal copy loops. Do epilog. Use src-src_sav to compute distance */
+       /* X - (A - B) == X + B - A */
+       .falign
+8089:
+       {
+               memd(dst) = d_dbuf
+               r2 += sub(src_sav,src)
+       }
+       {
+               r0 = r2
+               jumpr r31
+       }
+       .falign
+4089:
+       {
+               memw(dst) = w_dbuf
+               r2 += sub(src_sav,src)
+       }
+       {
+               r0 = r2
+               jumpr r31
+       }
+       .falign
+2089:
+       {
+               memh(dst) = w_dbuf
+               r2 += sub(src_sav,src)
+       }
+       {
+               r0 = r2
+               jumpr r31
+       }
+       .falign
+1089:
+       {
+               memb(dst) = w_dbuf
+               r2 += sub(src_sav,src)
+       }
+       {
+               r0 = r2
+               jumpr r31
+       }
+
+       /* COPY FROM USER: only loads can fail */
+
+       .section __ex_table,"a"
+       .long 1000b,1009b
+       .long 2000b,2009b
+       .long 4000b,4009b
+       .long 8080b,8089b
+       .long 4080b,4089b
+       .long 2080b,2089b
+       .long 1080b,1089b
+       .previous
diff --git a/arch/hexagon/mm/copy_to_user.S b/arch/hexagon/mm/copy_to_user.S
new file mode 100644 (file)
index 0000000..cb9740e
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * User memory copying routines for the Hexagon Kernel
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/* The right way to do this involves valignb
+ * The easy way to do this is only speed up src/dest similar alignment.
+ */
+
+/*
+ * Copy to/from user are the same, except that for packets with a load and
+ * a store, I don't know how to tell which kind of exception we got.
+ * Therefore, we duplicate the function, and handle faulting addresses
+ * differently for each function
+ */
+
+/*
+ * copy to user: stores can fault
+ */
+#define src_sav r13
+#define dst_sav r12
+#define src_dst_sav r13:12
+#define d_dbuf r15:14
+#define w_dbuf r15
+
+#define dst r0
+#define src r1
+#define bytes r2
+#define loopcount r5
+
+#define FUNCNAME __copy_to_user_hexagon
+#include "copy_user_template.S"
+
+       /* STORE FAULTS from COPY_TO_USER */
+       .falign
+1109:
+2109:
+4109:
+       /* Alignment loop.  r2 has been updated.  Return it. */
+       {
+               r0 = r2
+               jumpr r31
+       }
+       /* Normal copy loops.  Use dst-dst_sav to compute distance */
+       /* dst holds best write, no need to unwind any loops */
+       /* X - (A - B) == X + B - A */
+       .falign
+8189:
+8199:
+4189:
+4199:
+2189:
+2199:
+1189:
+1199:
+       {
+               r2 += sub(dst_sav,dst)
+       }
+       {
+               r0 = r2
+               jumpr r31
+       }
+
+       /* COPY TO USER: only stores can fail */
+       .section __ex_table,"a"
+       .long 1100b,1109b
+       .long 2100b,2109b
+       .long 4100b,4109b
+       .long 8180b,8189b
+       .long 8190b,8199b
+       .long 4180b,4189b
+       .long 4190b,4199b
+       .long 2180b,2189b
+       .long 2190b,2199b
+       .long 1180b,1189b
+       .long 1190b,1199b
+       .previous
diff --git a/arch/hexagon/mm/copy_user_template.S b/arch/hexagon/mm/copy_user_template.S
new file mode 100644 (file)
index 0000000..08d7d7b
--- /dev/null
@@ -0,0 +1,185 @@
+/*
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/* Numerology:
+ * WXYZ
+ * W: width in bytes
+ * X: Load=0, Store=1
+ * Y: Location 0=preamble,8=loop,9=epilog
+ * Z: Location=0,handler=9
+ */
+       .text
+       .global FUNCNAME
+       .type FUNCNAME, @function
+       .p2align 5
+FUNCNAME:
+       {
+               p0 = cmp.gtu(bytes,#0)
+               if (!p0.new) jump:nt .Ldone
+               r3 = or(dst,src)
+               r4 = xor(dst,src)
+       }
+       {
+               p1 = cmp.gtu(bytes,#15)
+               p0 = bitsclr(r3,#7)
+               if (!p0.new) jump:nt .Loop_not_aligned_8
+               src_dst_sav = combine(src,dst)
+       }
+
+       {
+               loopcount = lsr(bytes,#3)
+               if (!p1) jump .Lsmall
+       }
+       p3=sp1loop0(.Loop8,loopcount)
+.Loop8:
+8080:
+8180:
+       {
+               if (p3) memd(dst++#8) = d_dbuf
+               d_dbuf = memd(src++#8)
+       }:endloop0
+8190:
+       {
+               memd(dst++#8) = d_dbuf
+               bytes -= asl(loopcount,#3)
+               jump .Lsmall
+       }
+
+.Loop_not_aligned_8:
+       {
+               p0 = bitsclr(r4,#7)
+               if (p0.new) jump:nt .Lalign
+       }
+       {
+               p0 = bitsclr(r3,#3)
+               if (!p0.new) jump:nt .Loop_not_aligned_4
+               p1 = cmp.gtu(bytes,#7)
+       }
+
+       {
+               if (!p1) jump .Lsmall
+               loopcount = lsr(bytes,#2)
+       }
+       p3=sp1loop0(.Loop4,loopcount)
+.Loop4:
+4080:
+4180:
+       {
+               if (p3) memw(dst++#4) = w_dbuf
+               w_dbuf = memw(src++#4)
+       }:endloop0
+4190:
+       {
+               memw(dst++#4) = w_dbuf
+               bytes -= asl(loopcount,#2)
+               jump .Lsmall
+       }
+
+.Loop_not_aligned_4:
+       {
+               p0 = bitsclr(r3,#1)
+               if (!p0.new) jump:nt .Loop_not_aligned
+               p1 = cmp.gtu(bytes,#3)
+       }
+
+       {
+               if (!p1) jump .Lsmall
+               loopcount = lsr(bytes,#1)
+       }
+       p3=sp1loop0(.Loop2,loopcount)
+.Loop2:
+2080:
+2180:
+       {
+               if (p3) memh(dst++#2) = w_dbuf
+               w_dbuf = memuh(src++#2)
+       }:endloop0
+2190:
+       {
+               memh(dst++#2) = w_dbuf
+               bytes -= asl(loopcount,#1)
+               jump .Lsmall
+       }
+
+.Loop_not_aligned: /* Works for as small as one byte */
+       p3=sp1loop0(.Loop1,bytes)
+.Loop1:
+1080:
+1180:
+       {
+               if (p3) memb(dst++#1) = w_dbuf
+               w_dbuf = memub(src++#1)
+       }:endloop0
+       /* Done */
+1190:
+       {
+               memb(dst) = w_dbuf
+               jumpr r31
+               r0 = #0
+       }
+
+.Lsmall:
+       {
+               p0 = cmp.gtu(bytes,#0)
+               if (p0.new) jump:nt .Loop_not_aligned
+       }
+.Ldone:
+       {
+               r0 = #0
+               jumpr r31
+       }
+       .falign
+.Lalign:
+1000:
+       {
+               if (p0.new) w_dbuf = memub(src)
+               p0 = tstbit(src,#0)
+               if (!p1) jump .Lsmall
+       }
+1100:
+       {
+               if (p0) memb(dst++#1) = w_dbuf
+               if (p0) bytes = add(bytes,#-1)
+               if (p0) src = add(src,#1)
+       }
+2000:
+       {
+               if (p0.new) w_dbuf = memuh(src)
+               p0 = tstbit(src,#1)
+               if (!p1) jump .Lsmall
+       }
+2100:
+       {
+               if (p0) memh(dst++#2) = w_dbuf
+               if (p0) bytes = add(bytes,#-2)
+               if (p0) src = add(src,#2)
+       }
+4000:
+       {
+               if (p0.new) w_dbuf = memw(src)
+               p0 = tstbit(src,#2)
+               if (!p1) jump .Lsmall
+       }
+4100:
+       {
+               if (p0) memw(dst++#4) = w_dbuf
+               if (p0) bytes = add(bytes,#-4)
+               if (p0) src = add(src,#4)
+               jump FUNCNAME
+       }
+       .size FUNCNAME,.-FUNCNAME
diff --git a/arch/hexagon/mm/init.c b/arch/hexagon/mm/init.c
new file mode 100644 (file)
index 0000000..b57d741
--- /dev/null
@@ -0,0 +1,276 @@
+/*
+ * Memory subsystem initialization for Hexagon
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <linux/init.h>
+#include <linux/mm.h>
+#include <linux/bootmem.h>
+#include <asm/atomic.h>
+#include <linux/highmem.h>
+#include <asm/tlb.h>
+#include <asm/sections.h>
+#include <asm/vm_mmu.h>
+
+/*
+ * Define a startpg just past the end of the kernel image and a lastpg
+ * that corresponds to the end of real or simulated platform memory.
+ */
+#define bootmem_startpg (PFN_UP(((unsigned long) _end) - PAGE_OFFSET))
+
+unsigned long bootmem_lastpg;  /*  Should be set by platform code  */
+
+/*  Set as variable to limit PMD copies  */
+int max_kernel_seg = 0x303;
+
+/*  think this should be (page_size-1) the way it's used...*/
+unsigned long zero_page_mask;
+
+/*  indicate pfn's of high memory  */
+unsigned long highstart_pfn, highend_pfn;
+
+/* struct mmu_gather defined in asm-generic.h;  */
+DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
+
+/* Default cache attribute for newly created page tables */
+unsigned long _dflt_cache_att = CACHEDEF;
+
+/*
+ * The current "generation" of kernel map, which should not roll
+ * over until Hell freezes over.  Actual bound in years needs to be
+ * calculated to confirm.
+ */
+DEFINE_SPINLOCK(kmap_gen_lock);
+
+/*  checkpatch says don't init this to 0.  */
+unsigned long long kmap_generation;
+
+/*
+ * mem_init - initializes memory
+ *
+ * Frees up bootmem
+ * Fixes up more stuff for HIGHMEM
+ * Calculates and displays memory available/used
+ */
+void __init mem_init(void)
+{
+       /*  No idea where this is actually declared.  Seems to evade LXR.  */
+       totalram_pages += free_all_bootmem();
+       num_physpages = bootmem_lastpg; /*  seriously, what?  */
+
+       printk(KERN_INFO "totalram_pages = %ld\n", totalram_pages);
+
+       /*
+        *  To-Do:  someone somewhere should wipe out the bootmem map
+        *  after we're done?
+        */
+
+       /*
+        * This can be moved to some more virtual-memory-specific
+        * initialization hook at some point.  Set the init_mm
+        * descriptors "context" value to point to the initial
+        * kernel segment table's physical address.
+        */
+       init_mm.context.ptbase = __pa(init_mm.pgd);
+}
+
+/*
+ * free_initmem - frees memory used by stuff declared with __init
+ *
+ * Todo:  free pages between __init_begin and __init_end; possibly
+ * some devtree related stuff as well.
+ */
+void __init_refok free_initmem(void)
+{
+}
+
+/*
+ * free_initrd_mem - frees...  initrd memory.
+ * @start - start of init memory
+ * @end - end of init memory
+ *
+ * Apparently has to be passed the address of the initrd memory.
+ *
+ * Wrapped by #ifdef CONFIG_BLKDEV_INITRD
+ */
+void free_initrd_mem(unsigned long start, unsigned long end)
+{
+}
+
+void sync_icache_dcache(pte_t pte)
+{
+       unsigned long addr;
+       struct page *page;
+
+       page = pte_page(pte);
+       addr = (unsigned long) page_address(page);
+
+       __vmcache_idsync(addr, PAGE_SIZE);
+}
+
+/*
+ * In order to set up page allocator "nodes",
+ * somebody has to call free_area_init() for UMA.
+ *
+ * In this mode, we only have one pg_data_t
+ * structure: contig_mem_data.
+ */
+void __init paging_init(void)
+{
+       unsigned long zones_sizes[MAX_NR_ZONES] = {0, };
+
+       /*
+        *  This is not particularly well documented anywhere, but
+        *  give ZONE_NORMAL all the memory, including the big holes
+        *  left by the kernel+bootmem_map which are already left as reserved
+        *  in the bootmem_map; free_area_init should see those bits and
+        *  adjust accordingly.
+        */
+
+       zones_sizes[ZONE_NORMAL] = max_low_pfn;
+
+       free_area_init(zones_sizes);  /*  sets up the zonelists and mem_map  */
+
+       /*
+        * Start of high memory area.  Will probably need something more
+        * fancy if we...  get more fancy.
+        */
+       high_memory = (void *)((bootmem_lastpg + 1) << PAGE_SHIFT);
+}
+
+#ifndef DMA_RESERVE
+#define DMA_RESERVE            (4)
+#endif
+
+#define DMA_CHUNKSIZE          (1<<22)
+#define DMA_RESERVED_BYTES     (DMA_RESERVE * DMA_CHUNKSIZE)
+
+/*
+ * Pick out the memory size.  We look for mem=size,
+ * where size is "size[KkMm]"
+ */
+static int __init early_mem(char *p)
+{
+       unsigned long size;
+       char *endp;
+
+       size = memparse(p, &endp);
+
+       bootmem_lastpg = PFN_DOWN(size);
+
+       return 0;
+}
+early_param("mem", early_mem);
+
+size_t hexagon_coherent_pool_size = (size_t) (DMA_RESERVE << 22);
+
+void __init setup_arch_memory(void)
+{
+       int bootmap_size;
+       /*  XXX Todo: this probably should be cleaned up  */
+       u32 *segtable = (u32 *) &swapper_pg_dir[0];
+       u32 *segtable_end;
+
+       /*
+        * Set up boot memory allocator
+        *
+        * The Gorman book also talks about these functions.
+        * This needs to change for highmem setups.
+        */
+
+       /* Memory size needs to be a multiple of 16M */
+       bootmem_lastpg = PFN_DOWN((bootmem_lastpg << PAGE_SHIFT) &
+               ~((BIG_KERNEL_PAGE_SIZE) - 1));
+
+       /*
+        * Reserve the top DMA_RESERVE bytes of RAM for DMA (uncached)
+        * memory allocation
+        */
+       bootmap_size = init_bootmem(bootmem_startpg, bootmem_lastpg -
+                                   PFN_DOWN(DMA_RESERVED_BYTES));
+
+       printk(KERN_INFO "bootmem_startpg:  0x%08lx\n", bootmem_startpg);
+       printk(KERN_INFO "bootmem_lastpg:  0x%08lx\n", bootmem_lastpg);
+       printk(KERN_INFO "bootmap_size:  %d\n", bootmap_size);
+       printk(KERN_INFO "max_low_pfn:  0x%08lx\n", max_low_pfn);
+
+       /*
+        * The default VM page tables (will be) populated with
+        * VA=PA+PAGE_OFFSET mapping.  We go in and invalidate entries
+        * higher than what we have memory for.
+        */
+
+       /*  this is pointer arithmetic; each entry covers 4MB  */
+       segtable = segtable + (PAGE_OFFSET >> 22);
+
+       /*  this actually only goes to the end of the first gig  */
+       segtable_end = segtable + (1<<(30-22));
+
+       /*  Move forward to the start of empty pages  */
+       segtable += bootmem_lastpg >> (22-PAGE_SHIFT);
+
+       {
+           int i;
+
+           for (i = 1 ; i <= DMA_RESERVE ; i++)
+               segtable[-i] = ((segtable[-i] & __HVM_PTE_PGMASK_4MB)
+                               | __HVM_PTE_R | __HVM_PTE_W | __HVM_PTE_X
+                               | __HEXAGON_C_UNC << 6
+                               | __HVM_PDE_S_4MB);
+       }
+
+       printk(KERN_INFO "clearing segtable from %p to %p\n", segtable,
+               segtable_end);
+       while (segtable < (segtable_end-8))
+               *(segtable++) = __HVM_PDE_S_INVALID;
+       /* stop the pointer at the device I/O 4MB page  */
+
+       printk(KERN_INFO "segtable = %p (should be equal to _K_io_map)\n",
+               segtable);
+
+#if 0
+       /*  Other half of the early device table from vm_init_segtable. */
+       printk(KERN_INFO "&_K_init_devicetable = 0x%08x\n",
+               (unsigned long) _K_init_devicetable-PAGE_OFFSET);
+       *segtable = ((u32) (unsigned long) _K_init_devicetable-PAGE_OFFSET) |
+               __HVM_PDE_S_4KB;
+       printk(KERN_INFO "*segtable = 0x%08x\n", *segtable);
+#endif
+
+       /*
+        * Free all the memory that wasn't taken up by the bootmap, the DMA
+        * reserve, or kernel itself.
+        */
+       free_bootmem(PFN_PHYS(bootmem_startpg)+bootmap_size,
+                    PFN_PHYS(bootmem_lastpg - bootmem_startpg) - bootmap_size -
+                    DMA_RESERVED_BYTES);
+
+       /*
+        *  The bootmem allocator seemingly just lives to feed memory
+        *  to the paging system
+        */
+       printk(KERN_INFO "PAGE_SIZE=%lu\n", PAGE_SIZE);
+       paging_init();  /*  See Gorman Book, 2.3  */
+
+       /*
+        *  At this point, the page allocator is kind of initialized, but
+        *  apparently no pages are available (just like with the bootmem
+        *  allocator), and need to be freed themselves via mem_init(),
+        *  which is called by start_kernel() later on in the process
+        */
+}
diff --git a/arch/hexagon/mm/ioremap.c b/arch/hexagon/mm/ioremap.c
new file mode 100644 (file)
index 0000000..3a37bc3
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * I/O remap functions for Hexagon
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <linux/io.h>
+#include <linux/vmalloc.h>
+
+void __iomem *ioremap_nocache(unsigned long phys_addr, unsigned long size)
+{
+       unsigned long last_addr, addr;
+       unsigned long offset = phys_addr & ~PAGE_MASK;
+       struct vm_struct *area;
+
+       pgprot_t prot = __pgprot(_PAGE_PRESENT|_PAGE_READ|_PAGE_WRITE
+                                       |(__HEXAGON_C_DEV << 6));
+
+       last_addr = phys_addr + size - 1;
+
+       /*  Wrapping not allowed  */
+       if (!size || (last_addr < phys_addr))
+               return NULL;
+
+       /*  Rounds up to next page size, including whole-page offset */
+       size = PAGE_ALIGN(offset + size);
+
+       area = get_vm_area(size, VM_IOREMAP);
+       addr = (unsigned long)area->addr;
+
+       if (ioremap_page_range(addr, addr+size, phys_addr, prot)) {
+               vunmap((void *)addr);
+               return NULL;
+       }
+
+       return (void __iomem *) (offset + addr);
+}
+
+void __iounmap(const volatile void __iomem *addr)
+{
+       vunmap((void *) ((unsigned long) addr & PAGE_MASK));
+}
diff --git a/arch/hexagon/mm/pgalloc.c b/arch/hexagon/mm/pgalloc.c
new file mode 100644 (file)
index 0000000..b175e2d
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <linux/init.h>
+
+void __init pgtable_cache_init(void)
+{
+}
diff --git a/arch/hexagon/mm/strnlen_user.S b/arch/hexagon/mm/strnlen_user.S
new file mode 100644 (file)
index 0000000..5c6a16c
--- /dev/null
@@ -0,0 +1,139 @@
+/*
+ * User string length functions for kernel
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#define isrc   r0
+#define max    r1      /*  Do not change!  */
+
+#define end    r2
+#define tmp1   r3
+
+#define obo    r6      /*  off-by-one  */
+#define start  r7
+#define mod8   r8
+#define dbuf    r15:14
+#define dcmp   r13:12
+
+/*
+ * The vector mask version of this turned out *really* badly.
+ * The hardware loop version also turned out *really* badly.
+ * Seems straight pointer arithmetic basically wins here.
+ */
+
+#define fname __strnlen_user
+
+       .text
+       .global fname
+       .type fname, @function
+       .p2align 5  /*  why?  */
+fname:
+       {
+               mod8 = and(isrc,#7);
+               end = add(isrc,max);
+               start = isrc;
+       }
+       {
+               P0 = cmp.eq(mod8,#0);
+               mod8 = and(end,#7);
+               dcmp = #0;
+               if (P0.new) jump:t dw_loop;     /*  fire up the oven  */
+       }
+
+alignment_loop:
+fail_1:        {
+               tmp1 = memb(start++#1);
+       }
+       {
+               P0 = cmp.eq(tmp1,#0);
+               if (P0.new) jump:nt exit_found;
+               P1 = cmp.gtu(end,start);
+               mod8 = and(start,#7);
+       }
+       {
+               if (!P1) jump exit_error;  /*  hit the end  */
+               P0 = cmp.eq(mod8,#0);
+       }
+       {
+               if (!P0) jump alignment_loop;
+       }
+
+
+
+dw_loop:
+fail_2:        {
+               dbuf = memd(start);
+               obo = add(start,#1);
+       }
+       {
+               P0 = vcmpb.eq(dbuf,dcmp);
+       }
+       {
+               tmp1 = P0;
+               P0 = cmp.gtu(end,start);
+       }
+       {
+               tmp1 = ct0(tmp1);
+               mod8 = and(end,#7);
+               if (!P0) jump end_check;
+       }
+       {
+               P0 = cmp.eq(tmp1,#32);
+               if (!P0.new) jump:nt exit_found;
+               if (!P0.new) start = add(obo,tmp1);
+       }
+       {
+               start = add(start,#8);
+               jump dw_loop;
+       }       /*  might be nice to combine these jumps...   */
+
+
+end_check:
+       {
+               P0 = cmp.gt(tmp1,mod8);
+               if (P0.new) jump:nt exit_error; /*  neverfound!  */
+               start = add(obo,tmp1);
+       }
+
+exit_found:
+       {
+               R0 = sub(start,isrc);
+               jumpr R31;
+       }
+
+exit_error:
+       {
+               R0 = add(max,#1);
+               jumpr R31;
+       }
+
+       /*  Uh, what does the "fixup" return here?  */
+       .falign
+fix_1:
+       {
+               R0 = #0;
+               jumpr R31;
+       }
+
+       .size fname,.-fname
+
+
+.section __ex_table,"a"
+.long fail_1,fix_1
+.long fail_2,fix_1
+.previous
diff --git a/arch/hexagon/mm/uaccess.c b/arch/hexagon/mm/uaccess.c
new file mode 100644 (file)
index 0000000..e748108
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/*
+ * Support for user memory access from kernel.  This will
+ * probably be inlined for performance at some point, but
+ * for ease of debug, and to a lesser degree for code size,
+ * we implement here as subroutines.
+ */
+#include <linux/types.h>
+#include <asm/uaccess.h>
+#include <asm/pgtable.h>
+
+/*
+ * For clear_user(), exploit previously defined copy_to_user function
+ * and the fact that we've got a handy zero page defined in kernel/head.S
+ *
+ * dczero here would be even faster.
+ */
+__kernel_size_t __clear_user_hexagon(void __user *dest, unsigned long count)
+{
+       long uncleared;
+
+       while (count > PAGE_SIZE) {
+               uncleared = __copy_to_user_hexagon(dest, &empty_zero_page,
+                                               PAGE_SIZE);
+               if (uncleared)
+                       return count - (PAGE_SIZE - uncleared);
+               count -= PAGE_SIZE;
+               dest += PAGE_SIZE;
+       }
+       if (count)
+               count = __copy_to_user_hexagon(dest, &empty_zero_page, count);
+
+       return count;
+}
+
+unsigned long clear_user_hexagon(void __user *dest, unsigned long count)
+{
+       if (!access_ok(VERIFY_WRITE, dest, count))
+               return count;
+       else
+               return __clear_user_hexagon(dest, count);
+}
diff --git a/arch/hexagon/mm/vm_fault.c b/arch/hexagon/mm/vm_fault.c
new file mode 100644 (file)
index 0000000..c10b76f
--- /dev/null
@@ -0,0 +1,187 @@
+/*
+ * Memory fault handling for Hexagon
+ *
+ * Copyright (c) 2010-2011 Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/*
+ * Page fault handling for the Hexagon Virtual Machine.
+ * Can also be called by a native port emulating the HVM
+ * execptions.
+ */
+
+#include <asm/pgtable.h>
+#include <asm/traps.h>
+#include <asm/uaccess.h>
+#include <linux/mm.h>
+#include <linux/signal.h>
+#include <linux/module.h>
+#include <linux/hardirq.h>
+
+/*
+ * Decode of hardware exception sends us to one of several
+ * entry points.  At each, we generate canonical arguments
+ * for handling by the abstract memory management code.
+ */
+#define FLT_IFETCH     -1
+#define FLT_LOAD        0
+#define FLT_STORE       1
+
+
+/*
+ * Canonical page fault handler
+ */
+void do_page_fault(unsigned long address, long cause, struct pt_regs *regs)
+{
+       struct vm_area_struct *vma;
+       struct mm_struct *mm = current->mm;
+       siginfo_t info;
+       int si_code = SEGV_MAPERR;
+       int fault;
+       const struct exception_table_entry *fixup;
+
+       /*
+        * If we're in an interrupt or have no user context,
+        * then must not take the fault.
+        */
+       if (unlikely(in_interrupt() || !mm))
+               goto no_context;
+
+       local_irq_enable();
+
+       down_read(&mm->mmap_sem);
+       vma = find_vma(mm, address);
+       if (!vma)
+               goto bad_area;
+
+       if (vma->vm_start <= address)
+               goto good_area;
+
+       if (!(vma->vm_flags & VM_GROWSDOWN))
+               goto bad_area;
+
+       if (expand_stack(vma, address))
+               goto bad_area;
+
+good_area:
+       /* Address space is OK.  Now check access rights. */
+       si_code = SEGV_ACCERR;
+
+       switch (cause) {
+       case FLT_IFETCH:
+               if (!(vma->vm_flags & VM_EXEC))
+                       goto bad_area;
+               break;
+       case FLT_LOAD:
+               if (!(vma->vm_flags & VM_READ))
+                       goto bad_area;
+               break;
+       case FLT_STORE:
+               if (!(vma->vm_flags & VM_WRITE))
+                       goto bad_area;
+               break;
+       }
+
+       fault = handle_mm_fault(mm, vma, address, (cause > 0));
+
+       /* The most common case -- we are done. */
+       if (likely(!(fault & VM_FAULT_ERROR))) {
+               if (fault & VM_FAULT_MAJOR)
+                       current->maj_flt++;
+               else
+                       current->min_flt++;
+
+               up_read(&mm->mmap_sem);
+               return;
+       }
+
+       up_read(&mm->mmap_sem);
+
+       /* Handle copyin/out exception cases */
+       if (!user_mode(regs))
+               goto no_context;
+
+       if (fault & VM_FAULT_OOM) {
+               pagefault_out_of_memory();
+               return;
+       }
+
+       /* User-mode address is in the memory map, but we are
+        * unable to fix up the page fault.
+        */
+       if (fault & VM_FAULT_SIGBUS) {
+               info.si_signo = SIGBUS;
+               info.si_code = BUS_ADRERR;
+       }
+       /* Address is not in the memory map */
+       else {
+               info.si_signo = SIGSEGV;
+               info.si_code = SEGV_ACCERR;
+       }
+       info.si_errno = 0;
+       info.si_addr = (void __user *)address;
+       force_sig_info(info.si_code, &info, current);
+       return;
+
+bad_area:
+       up_read(&mm->mmap_sem);
+
+       if (user_mode(regs)) {
+               info.si_signo = SIGSEGV;
+               info.si_errno = 0;
+               info.si_code = si_code;
+               info.si_addr = (void *)address;
+               force_sig_info(SIGSEGV, &info, current);
+               return;
+       }
+       /* Kernel-mode fault falls through */
+
+no_context:
+       fixup = search_exception_tables(pt_elr(regs));
+       if (fixup) {
+               pt_set_elr(regs, fixup->fixup);
+               return;
+       }
+
+       /* Things are looking very, very bad now */
+       bust_spinlocks(1);
+       printk(KERN_EMERG "Unable to handle kernel paging request at "
+               "virtual address 0x%08lx, regs %p\n", address, regs);
+       die("Bad Kernel VA", regs, SIGKILL);
+}
+
+
+void read_protection_fault(struct pt_regs *regs)
+{
+       unsigned long badvadr = pt_badva(regs);
+
+       do_page_fault(badvadr, FLT_LOAD, regs);
+}
+
+void write_protection_fault(struct pt_regs *regs)
+{
+       unsigned long badvadr = pt_badva(regs);
+
+       do_page_fault(badvadr, FLT_STORE, regs);
+}
+
+void execute_protection_fault(struct pt_regs *regs)
+{
+       unsigned long badvadr = pt_badva(regs);
+
+       do_page_fault(badvadr, FLT_IFETCH, regs);
+}
diff --git a/arch/hexagon/mm/vm_tlb.c b/arch/hexagon/mm/vm_tlb.c
new file mode 100644 (file)
index 0000000..c6ff415
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * Hexagon Virtual Machine TLB functions
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/*
+ * The Hexagon Virtual Machine conceals the real workings of
+ * the TLB, but there are one or two functions that need to
+ * be instantiated for it, differently from a native build.
+ */
+#include <linux/mm.h>
+#include <asm/page.h>
+#include <asm/hexagon_vm.h>
+
+/*
+ * Initial VM implementation has only one map active at a time, with
+ * TLB purgings on changes.  So either we're nuking the current map,
+ * or it's a no-op.  This operation is messy on true SMPs where other
+ * processors must be induced to flush the copies in their local TLBs,
+ * but Hexagon thread-based virtual processors share the same MMU.
+ */
+void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
+                       unsigned long end)
+{
+       struct mm_struct *mm = vma->vm_mm;
+
+       if (mm->context.ptbase == current->active_mm->context.ptbase)
+               __vmclrmap((void *)start, end - start);
+}
+
+/*
+ * Flush a page from the kernel virtual map - used by highmem
+ */
+void flush_tlb_one(unsigned long vaddr)
+{
+       __vmclrmap((void *)vaddr, PAGE_SIZE);
+}
+
+/*
+ * Flush all TLBs across all CPUs, virtual or real.
+ * A single Hexagon core has 6 thread contexts but
+ * only one TLB.
+ */
+void tlb_flush_all(void)
+{
+       /*  should probably use that fixaddr end or whateve label  */
+       __vmclrmap(0, 0xffff0000);
+}
+
+/*
+ * Flush TLB entries associated with a given mm_struct mapping.
+ */
+void flush_tlb_mm(struct mm_struct *mm)
+{
+       /* Current Virtual Machine has only one map active at a time */
+       if (current->active_mm->context.ptbase == mm->context.ptbase)
+               tlb_flush_all();
+}
+
+/*
+ * Flush TLB state associated with a page of a vma.
+ */
+void flush_tlb_page(struct vm_area_struct *vma, unsigned long vaddr)
+{
+       struct mm_struct *mm = vma->vm_mm;
+
+       if (mm->context.ptbase  == current->active_mm->context.ptbase)
+               __vmclrmap((void *)vaddr, PAGE_SIZE);
+}
+
+/*
+ * Flush TLB entries associated with a kernel address range.
+ * Like flush range, but without the check on the vma->vm_mm.
+ */
+void flush_tlb_kernel_range(unsigned long start, unsigned long end)
+{
+               __vmclrmap((void *)start, end - start);
+}
index 8213efe1998c16eade6966acd1cf1b5b22d489a8..43f4c92816ef9760f68849611cea83ea8d0799aa 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/uaccess.h>
 #include <linux/iommu.h>
 #include <linux/intel-iommu.h>
+#include <linux/pci.h>
 
 #include <asm/pgtable.h>
 #include <asm/gcc_intrin.h>
@@ -204,7 +205,7 @@ int kvm_dev_ioctl_check_extension(long ext)
                r = KVM_COALESCED_MMIO_PAGE_OFFSET;
                break;
        case KVM_CAP_IOMMU:
-               r = iommu_found();
+               r = iommu_present(&pci_bus_type);
                break;
        default:
                r = 0;
index a569514cf19f49b73962432c98c0da9880e3c216..3a3e5b8868544718c7b9b9c0af796f2aed4a6625 100644 (file)
 #include <linux/dma-attrs.h>
 #include <asm/io.h>
 #include <asm-generic/dma-coherent.h>
+#include <asm/cacheflush.h>
 
 #define DMA_ERROR_CODE         (~(dma_addr_t)0x0)
 
 #define __dma_alloc_coherent(dev, gfp, size, handle)   NULL
 #define __dma_free_coherent(size, addr)                ((void)0)
-#define __dma_sync(addr, size, rw)             ((void)0)
 
 static inline unsigned long device_to_mask(struct device *dev)
 {
@@ -95,6 +95,22 @@ static inline int dma_set_mask(struct device *dev, u64 dma_mask)
 
 #include <asm-generic/dma-mapping-common.h>
 
+static inline void __dma_sync(unsigned long paddr,
+                             size_t size, enum dma_data_direction direction)
+{
+       switch (direction) {
+       case DMA_TO_DEVICE:
+       case DMA_BIDIRECTIONAL:
+               flush_dcache_range(paddr, paddr + size);
+               break;
+       case DMA_FROM_DEVICE:
+               invalidate_dcache_range(paddr, paddr + size);
+               break;
+       default:
+               BUG();
+       }
+}
+
 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
 {
        struct dma_map_ops *ops = get_dma_ops(dev);
@@ -135,7 +151,7 @@ static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
                enum dma_data_direction direction)
 {
        BUG_ON(direction == DMA_NONE);
-       __dma_sync(vaddr, size, (int)direction);
+       __dma_sync(virt_to_phys(vaddr), size, (int)direction);
 }
 
 #endif /* _ASM_MICROBLAZE_DMA_MAPPING_H */
index 098dfdde4b061e067c56ad2a5ce0016a98fa8ff1..834849f59ae8a5474e80d2e13cd4a3f0a9e2976f 100644 (file)
  * I've snaffled the value from the microblaze binutils source code
  * /binutils/microblaze/include/elf/microblaze.h
  */
-#define EM_XILINX_MICROBLAZE   0xbaab
-#define ELF_ARCH               EM_XILINX_MICROBLAZE
+#define EM_MICROBLAZE          189
+#define EM_MICROBLAZE_OLD      0xbaab
+#define ELF_ARCH               EM_MICROBLAZE
 
 /*
  * This is used to ensure we don't load something for the wrong architecture.
  */
-#define elf_check_arch(x)      ((x)->e_machine == EM_XILINX_MICROBLAZE)
+#define elf_check_arch(x)      ((x)->e_machine == EM_MICROBLAZE \
+                                || (x)->e_machine == EM_MICROBLAZE_OLD)
 
 /*
  * These are used to set parameters in the core dumps.
index e6a2284571dcfc46646582d4a5327e1797887011..5a433cbaafb3296f1c9df2239e9b4ed513b95418 100644 (file)
@@ -17,8 +17,6 @@
 #include <asm-generic/cmpxchg.h>
 #include <asm-generic/cmpxchg-local.h>
 
-#define __ARCH_WANT_INTERRUPTS_ON_CTXSW
-
 struct task_struct;
 struct thread_info;
 
@@ -96,11 +94,4 @@ extern struct dentry *of_debugfs_root;
 
 #define arch_align_stack(x) (x)
 
-/*
- * MicroBlaze doesn't handle unaligned accesses in hardware.
- *
- * Based on this we force the IP header alignment in network drivers.
- */
-#define NET_IP_ALIGN   2
-
 #endif /* _ASM_MICROBLAZE_SYSTEM_H */
index 5bb95a11880d27f3deb10d86ab7c837a3aad7b78..072b0077abf95a4ae9494c47900913cfd79ccd71 100644 (file)
@@ -95,7 +95,7 @@ static inline int ___range_ok(unsigned long addr, unsigned long size)
  *  - "addr", "addr + size" and "size" are all below the limit
  */
 #define access_ok(type, addr, size) \
-       (get_fs().seg > (((unsigned long)(addr)) | \
+       (get_fs().seg >= (((unsigned long)(addr)) | \
                (size) | ((unsigned long)(addr) + (size))))
 
 /* || printk("access_ok failed for %s at 0x%08lx (size %d), seg 0x%08x\n",
index 44394d80a6836c4118254eab4ce24d7b9c2b91ab..54194b28574af687f32734a0c0a53452bcc5caba 100644 (file)
@@ -34,6 +34,7 @@ const struct cpu_ver_key cpu_ver_lookup[] = {
        {"8.00.a", 0x12},
        {"8.00.b", 0x13},
        {"8.10.a", 0x14},
+       {"8.20.a", 0x15},
        {NULL, 0},
 };
 
index 393e6b2db688545aac0a1784f25ad51d73d89567..dc6416d265d616e1ac65382b5174c81c1b22d723 100644 (file)
@@ -11,7 +11,6 @@
 #include <linux/gfp.h>
 #include <linux/dma-debug.h>
 #include <asm/bug.h>
-#include <asm/cacheflush.h>
 
 /*
  * Generic direct DMA implementation
  * can set archdata.dma_data to an unsigned long holding the offset. By
  * default the offset is PCI_DRAM_OFFSET.
  */
-static inline void __dma_sync_page(unsigned long paddr, unsigned long offset,
-                               size_t size, enum dma_data_direction direction)
-{
-       switch (direction) {
-       case DMA_TO_DEVICE:
-       case DMA_BIDIRECTIONAL:
-               flush_dcache_range(paddr + offset, paddr + offset + size);
-               break;
-       case DMA_FROM_DEVICE:
-               invalidate_dcache_range(paddr + offset, paddr + offset + size);
-               break;
-       default:
-               BUG();
-       }
-}
 
 static unsigned long get_dma_direct_offset(struct device *dev)
 {
@@ -91,7 +75,7 @@ static int dma_direct_map_sg(struct device *dev, struct scatterlist *sgl,
        /* FIXME this part of code is untested */
        for_each_sg(sgl, sg, nents, i) {
                sg->dma_address = sg_phys(sg) + get_dma_direct_offset(dev);
-               __dma_sync_page(page_to_phys(sg_page(sg)), sg->offset,
+               __dma_sync(page_to_phys(sg_page(sg)) + sg->offset,
                                                        sg->length, direction);
        }
 
@@ -116,7 +100,7 @@ static inline dma_addr_t dma_direct_map_page(struct device *dev,
                                             enum dma_data_direction direction,
                                             struct dma_attrs *attrs)
 {
-       __dma_sync_page(page_to_phys(page), offset, size, direction);
+       __dma_sync(page_to_phys(page) + offset, size, direction);
        return page_to_phys(page) + offset + get_dma_direct_offset(dev);
 }
 
@@ -131,7 +115,63 @@ static inline void dma_direct_unmap_page(struct device *dev,
  * phys_to_virt is here because in __dma_sync_page is __virt_to_phys and
  * dma_address is physical address
  */
-       __dma_sync_page(dma_address, 0 , size, direction);
+       __dma_sync(dma_address, size, direction);
+}
+
+static inline void
+dma_direct_sync_single_for_cpu(struct device *dev,
+                              dma_addr_t dma_handle, size_t size,
+                              enum dma_data_direction direction)
+{
+       /*
+        * It's pointless to flush the cache as the memory segment
+        * is given to the CPU
+        */
+
+       if (direction == DMA_FROM_DEVICE)
+               __dma_sync(dma_handle, size, direction);
+}
+
+static inline void
+dma_direct_sync_single_for_device(struct device *dev,
+                                 dma_addr_t dma_handle, size_t size,
+                                 enum dma_data_direction direction)
+{
+       /*
+        * It's pointless to invalidate the cache if the device isn't
+        * supposed to write to the relevant region
+        */
+
+       if (direction == DMA_TO_DEVICE)
+               __dma_sync(dma_handle, size, direction);
+}
+
+static inline void
+dma_direct_sync_sg_for_cpu(struct device *dev,
+                          struct scatterlist *sgl, int nents,
+                          enum dma_data_direction direction)
+{
+       struct scatterlist *sg;
+       int i;
+
+       /* FIXME this part of code is untested */
+       if (direction == DMA_FROM_DEVICE)
+               for_each_sg(sgl, sg, nents, i)
+                       __dma_sync(sg->dma_address, sg->length, direction);
+}
+
+static inline void
+dma_direct_sync_sg_for_device(struct device *dev,
+                             struct scatterlist *sgl, int nents,
+                             enum dma_data_direction direction)
+{
+       struct scatterlist *sg;
+       int i;
+
+       /* FIXME this part of code is untested */
+       if (direction == DMA_TO_DEVICE)
+               for_each_sg(sgl, sg, nents, i)
+                       __dma_sync(sg->dma_address, sg->length, direction);
 }
 
 struct dma_map_ops dma_direct_ops = {
@@ -142,6 +182,10 @@ struct dma_map_ops dma_direct_ops = {
        .dma_supported  = dma_direct_dma_supported,
        .map_page       = dma_direct_map_page,
        .unmap_page     = dma_direct_unmap_page,
+       .sync_single_for_cpu            = dma_direct_sync_single_for_cpu,
+       .sync_single_for_device         = dma_direct_sync_single_for_device,
+       .sync_sg_for_cpu                = dma_direct_sync_sg_for_cpu,
+       .sync_sg_for_device             = dma_direct_sync_sg_for_device,
 };
 EXPORT_SYMBOL(dma_direct_ops);
 
index 66fad23012216e86cb2f91bdfff053f0e080f208..6348dc82f4289f48b36843ad4e94b81ff0e7e36e 100644 (file)
@@ -119,7 +119,7 @@ asmlinkage void full_exception(struct pt_regs *regs, unsigned int type,
        case MICROBLAZE_DIV_ZERO_EXCEPTION:
                if (user_mode(regs)) {
                        pr_debug("Divide by zero exception in user mode\n");
-                       _exception(SIGILL, regs, FPE_INTDIV, addr);
+                       _exception(SIGFPE, regs, FPE_INTDIV, addr);
                        return;
                }
                printk(KERN_WARNING "Divide by zero exception " \
index dbb812421d8a15629dd051cd931aea24c625c58f..95cc295976a73279878ddd103aeb6777c263c9a6 100644 (file)
@@ -179,6 +179,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
 
        ti->cpu_context.msr = (childregs->msr|MSR_VM);
        ti->cpu_context.msr &= ~MSR_UMS; /* switch_to to kernel mode */
+       ti->cpu_context.msr &= ~MSR_IE;
 #endif
        ti->cpu_context.r15 = (unsigned long)ret_from_fork - 8;
 
index 6a8e0cc5c57d40dbfc165c5df15c86b9cece0277..043cb58f9c443e72843fa44a9ebd399442a965b5 100644 (file)
@@ -148,7 +148,7 @@ asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
                ret = -1L;
 
        if (unlikely(current->audit_context))
-               audit_syscall_entry(EM_XILINX_MICROBLAZE, regs->r12,
+               audit_syscall_entry(EM_MICROBLAZE, regs->r12,
                                    regs->r5, regs->r6,
                                    regs->r7, regs->r8);
 
index e5550ce4e0eb783f5e6a4f29e7526c1cf3cbc6b0..af74b1113aabb32fb3849a952109ffba07eacdcf 100644 (file)
@@ -308,7 +308,8 @@ unsigned long long notrace sched_clock(void)
 {
        if (timer_initialized) {
                struct clocksource *cs = &clocksource_microblaze;
-               cycle_t cyc = cnt32_to_63(cs->read(NULL));
+
+               cycle_t cyc = cnt32_to_63(cs->read(NULL)) & LLONG_MAX;
                return clocksource_cyc2ns(cyc, cs->mult, cs->shift);
        }
        return 0;
index 10c320aa908b2325963264271c3673175feb931f..c13067b243c3925e486bef404a1ac80aba5ebc6a 100644 (file)
@@ -25,5 +25,6 @@ lib-y += lshrdi3.o
 lib-y += modsi3.o
 lib-y += muldi3.o
 lib-y += mulsi3.o
+lib-y += ucmpdi2.o
 lib-y += udivsi3.o
 lib-y += umodsi3.o
index 5810cec54a7a36e356d5c48b4ad29923ee0829e4..f037266cdaf3e358676c0428e83393c16dd410cb 100644 (file)
@@ -10,6 +10,7 @@
 
 #include <linux/errno.h>
 #include <linux/linkage.h>
+#include <asm/page.h>
 
 /*
  * int __strncpy_user(char *to, char *from, int len);
@@ -33,8 +34,8 @@ __strncpy_user:
         * r3 - temp count
         * r4 - temp val
         */
+       beqid   r7,3f
        addik   r3,r7,0         /* temp_count = len */
-       beqi    r3,3f
 1:
        lbu     r4,r6,r0
        sb      r4,r5,r0
@@ -76,8 +77,8 @@ __strncpy_user:
 .type  __strnlen_user, @function
 .align 4;
 __strnlen_user:
+       beqid   r6,3f
        addik   r3,r6,0
-       beqi    r3,3f
 1:
        lbu     r4,r5,r0
        beqid   r4,2f           /* break on NUL */
@@ -102,6 +103,49 @@ __strnlen_user:
        .section        __ex_table,"a"
        .word   1b,4b
 
+/* Loop unrolling for __copy_tofrom_user */
+#define COPY(offset)   \
+1:     lwi     r4 , r6, 0x0000 + offset;       \
+2:     lwi     r19, r6, 0x0004 + offset;       \
+3:     lwi     r20, r6, 0x0008 + offset;       \
+4:     lwi     r21, r6, 0x000C + offset;       \
+5:     lwi     r22, r6, 0x0010 + offset;       \
+6:     lwi     r23, r6, 0x0014 + offset;       \
+7:     lwi     r24, r6, 0x0018 + offset;       \
+8:     lwi     r25, r6, 0x001C + offset;       \
+9:     swi     r4 , r5, 0x0000 + offset;       \
+10:    swi     r19, r5, 0x0004 + offset;       \
+11:    swi     r20, r5, 0x0008 + offset;       \
+12:    swi     r21, r5, 0x000C + offset;       \
+13:    swi     r22, r5, 0x0010 + offset;       \
+14:    swi     r23, r5, 0x0014 + offset;       \
+15:    swi     r24, r5, 0x0018 + offset;       \
+16:    swi     r25, r5, 0x001C + offset;       \
+       .section __ex_table,"a";                \
+       .word   1b, 0f;                         \
+       .word   2b, 0f;                         \
+       .word   3b, 0f;                         \
+       .word   4b, 0f;                         \
+       .word   5b, 0f;                         \
+       .word   6b, 0f;                         \
+       .word   7b, 0f;                         \
+       .word   8b, 0f;                         \
+       .word   9b, 0f;                         \
+       .word   10b, 0f;                        \
+       .word   11b, 0f;                        \
+       .word   12b, 0f;                        \
+       .word   13b, 0f;                        \
+       .word   14b, 0f;                        \
+       .word   15b, 0f;                        \
+       .word   16b, 0f;                        \
+       .text
+
+#define COPY_80(offset)        \
+       COPY(0x00 + offset);\
+       COPY(0x20 + offset);\
+       COPY(0x40 + offset);\
+       COPY(0x60 + offset);
+
 /*
  * int __copy_tofrom_user(char *to, char *from, int len)
  * Return:
@@ -119,34 +163,79 @@ __copy_tofrom_user:
         * r7, r3 - count
         * r4 - tempval
         */
-       beqid   r7, 3f /* zero size is not likely */
-       andi    r3, r7, 0x3 /* filter add count */
-       bneid   r3, 4f /* if is odd value then byte copying */
+       beqid   r7, 0f /* zero size is not likely */
        or      r3, r5, r6 /* find if is any to/from unaligned */
-       andi    r3, r3, 0x3 /* mask unaligned */
-       bneid   r3, 1f /* it is unaligned -> then jump */
+       or      r3, r3, r7 /* find if count is unaligned */
+       andi    r3, r3, 0x3 /* mask last 3 bits */
+       bneid   r3, bu1 /* if r3 is not zero then byte copying */
+       or      r3, r0, r0
+
+       rsubi   r3, r7, PAGE_SIZE /* detect PAGE_SIZE */
+       beqid   r3, page;
        or      r3, r0, r0
 
-/* at least one 4 byte copy */
-5:     lw      r4, r6, r3
-6:     sw      r4, r5, r3
+w1:    lw      r4, r6, r3 /* at least one 4 byte copy */
+w2:    sw      r4, r5, r3
        addik   r7, r7, -4
-       bneid   r7, 5b
+       bneid   r7, w1
        addik   r3, r3, 4
        addik   r3, r7, 0
        rtsd    r15, 8
        nop
-4:     or      r3, r0, r0
-1:     lbu     r4,r6,r3
-2:     sb      r4,r5,r3
+
+       .section        __ex_table,"a"
+       .word   w1, 0f;
+       .word   w2, 0f;
+       .text
+
+.align 4 /* Alignment is important to keep icache happy */
+page:  /* Create room on stack and save registers for storign values */
+       addik   r1, r1, -32
+       swi     r19, r1, 4
+       swi     r20, r1, 8
+       swi     r21, r1, 12
+       swi     r22, r1, 16
+       swi     r23, r1, 20
+       swi     r24, r1, 24
+       swi     r25, r1, 28
+loop:  /* r4, r19, r20, r21, r22, r23, r24, r25 are used for storing values */
+       /* Loop unrolling to get performance boost */
+       COPY_80(0x000);
+       COPY_80(0x080);
+       COPY_80(0x100);
+       COPY_80(0x180);
+       /* copy loop */
+       addik   r6, r6, 0x200
+       addik   r7, r7, -0x200
+       bneid   r7, loop
+       addik   r5, r5, 0x200
+       /* Restore register content */
+       lwi     r19, r1, 4
+       lwi     r20, r1, 8
+       lwi     r21, r1, 12
+       lwi     r22, r1, 16
+       lwi     r23, r1, 20
+       lwi     r24, r1, 24
+       lwi     r25, r1, 28
+       addik   r1, r1, 32
+       /* return back */
+       addik   r3, r7, 0
+       rtsd    r15, 8
+       nop
+
+.align 4 /* Alignment is important to keep icache happy */
+bu1:   lbu     r4,r6,r3
+bu2:   sb      r4,r5,r3
        addik   r7,r7,-1
-       bneid   r7,1b
+       bneid   r7,bu1
        addik   r3,r3,1         /* delay slot */
-3:
+0:
        addik   r3,r7,0
        rtsd    r15,8
        nop
        .size   __copy_tofrom_user, . - __copy_tofrom_user
 
        .section        __ex_table,"a"
-       .word   1b,3b,2b,3b,5b,3b,6b,3b
+       .word   bu1, 0b;
+       .word   bu2, 0b;
+       .text
diff --git a/arch/microblaze/lib/ucmpdi2.c b/arch/microblaze/lib/ucmpdi2.c
new file mode 100644 (file)
index 0000000..63ca105
--- /dev/null
@@ -0,0 +1,20 @@
+#include <linux/module.h>
+
+#include "libgcc.h"
+
+word_type __ucmpdi2(unsigned long long a, unsigned long long b)
+{
+       const DWunion au = {.ll = a};
+       const DWunion bu = {.ll = b};
+
+       if ((unsigned int) au.s.high < (unsigned int) bu.s.high)
+               return 0;
+       else if ((unsigned int) au.s.high > (unsigned int) bu.s.high)
+               return 2;
+       if ((unsigned int) au.s.low < (unsigned int) bu.s.low)
+               return 0;
+       else if ((unsigned int) au.s.low > (unsigned int) bu.s.low)
+               return 2;
+       return 1;
+}
+EXPORT_SYMBOL(__ucmpdi2);
index fbb55935b99e71ee3be1475657ca8fdfdf981ee5..dda090bf74e6bb1a9f47a8492324fd167b5b06ad 100644 (file)
@@ -422,6 +422,7 @@ static struct resource au1200_psc1_res[] = {
        },
 };
 
+/* AC97 or I2S device */
 static struct platform_device db1200_audio_dev = {
        /* name assigned later based on switch setting */
        .id             = 1,    /* PSC ID */
@@ -429,19 +430,32 @@ static struct platform_device db1200_audio_dev = {
        .resource       = au1200_psc1_res,
 };
 
+/* DB1200 ASoC card device */
+static struct platform_device db1200_sound_dev = {
+       /* name assigned later based on switch setting */
+       .id             = 1,    /* PSC ID */
+};
+
 static struct platform_device db1200_stac_dev = {
        .name           = "ac97-codec",
        .id             = 1,    /* on PSC1 */
 };
 
+static struct platform_device db1200_audiodma_dev = {
+       .name           = "au1xpsc-pcm",
+       .id             = 1,    /* PSC ID */
+};
+
 static struct platform_device *db1200_devs[] __initdata = {
        NULL,           /* PSC0, selected by S6.8 */
        &db1200_ide_dev,
        &db1200_eth_dev,
        &db1200_rtc_dev,
        &db1200_nand_dev,
+       &db1200_audiodma_dev,
        &db1200_audio_dev,
        &db1200_stac_dev,
+       &db1200_sound_dev,
 };
 
 static int __init db1200_dev_init(void)
@@ -501,10 +515,12 @@ static int __init db1200_dev_init(void)
        if (sw == BCSR_SWITCHES_DIP_8) {
                bcsr_mod(BCSR_RESETS, 0, BCSR_RESETS_PSC1MUX);
                db1200_audio_dev.name = "au1xpsc_i2s";
+               db1200_sound_dev.name = "db1200-i2s";
                printk(KERN_INFO " S6.7 ON : PSC1 mode I2S\n");
        } else {
                bcsr_mod(BCSR_RESETS, BCSR_RESETS_PSC1MUX, 0);
                db1200_audio_dev.name = "au1xpsc_ac97";
+               db1200_sound_dev.name = "db1200-ac97";
                printk(KERN_INFO " S6.7 OFF: PSC1 mode AC97\n");
        }
 
index 978d5ab3d6781781eb5cb2d5acb117b3c443a81c..7057d28f73016dffb4136fb7d5856c1e19f66dac 100644 (file)
  */
 
 #include <linux/init.h>
+#include <linux/interrupt.h>
 #include <linux/platform_device.h>
 
+#include <asm/mach-au1x00/au1000.h>
+#include <asm/mach-au1x00/au1000_dma.h>
 #include <asm/mach-au1x00/au1xxx.h>
 #include <asm/mach-db1x00/bcsr.h>
 #include "../platform.h"
 #endif
 #endif
 
+static struct resource alchemy_ac97c_res[] = {
+       [0] = {
+               .start  = AU1000_AC97_PHYS_ADDR,
+               .end    = AU1000_AC97_PHYS_ADDR + 0xfff,
+               .flags  = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start  = DMA_ID_AC97C_TX,
+               .end    = DMA_ID_AC97C_TX,
+               .flags  = IORESOURCE_DMA,
+       },
+       [2] = {
+               .start  = DMA_ID_AC97C_RX,
+               .end    = DMA_ID_AC97C_RX,
+               .flags  = IORESOURCE_DMA,
+       },
+};
+
+static struct platform_device alchemy_ac97c_dev = {
+       .name           = "alchemy-ac97c",
+       .id             = -1,
+       .resource       = alchemy_ac97c_res,
+       .num_resources  = ARRAY_SIZE(alchemy_ac97c_res),
+};
+
+static struct platform_device alchemy_ac97c_dma_dev = {
+       .name           = "alchemy-pcm-dma",
+       .id             = 0,
+};
+
+static struct platform_device db1x00_codec_dev = {
+       .name           = "ac97-codec",
+       .id             = -1,
+};
+
+static struct platform_device db1x00_audio_dev = {
+       .name           = "db1000-audio",
+};
+
 static int __init db1xxx_dev_init(void)
 {
 #ifdef DB1XXX_HAS_PCMCIA
@@ -113,6 +155,12 @@ static int __init db1xxx_dev_init(void)
                                    1);
 #endif
        db1x_register_norflash(BOARD_FLASH_SIZE, BOARD_FLASH_WIDTH, F_SWAPPED);
+
+       platform_device_register(&db1x00_codec_dev);
+       platform_device_register(&alchemy_ac97c_dma_dev);
+       platform_device_register(&alchemy_ac97c_dev);
+       platform_device_register(&db1x00_audio_dev);
+
        return 0;
 }
 device_initcall(db1xxx_dev_init);
index 538266b2c9bc6cd0d87e9886d4f2509e61847664..522eb8a9b60df09fe9b768b954ed7534edf68b91 100644 (file)
@@ -798,7 +798,7 @@ unsigned char *mem2hex(const void *_mem, char *buf, int count, int may_fault)
        if ((u32) mem & 1 && count >= 1) {
                if (gdbstub_read_byte(mem, ch) != 0)
                        return 0;
-               buf = pack_hex_byte(buf, ch[0]);
+               buf = hex_byte_pack(buf, ch[0]);
                mem++;
                count--;
        }
@@ -806,8 +806,8 @@ unsigned char *mem2hex(const void *_mem, char *buf, int count, int may_fault)
        if ((u32) mem & 3 && count >= 2) {
                if (gdbstub_read_word(mem, ch) != 0)
                        return 0;
-               buf = pack_hex_byte(buf, ch[0]);
-               buf = pack_hex_byte(buf, ch[1]);
+               buf = hex_byte_pack(buf, ch[0]);
+               buf = hex_byte_pack(buf, ch[1]);
                mem += 2;
                count -= 2;
        }
@@ -815,10 +815,10 @@ unsigned char *mem2hex(const void *_mem, char *buf, int count, int may_fault)
        while (count >= 4) {
                if (gdbstub_read_dword(mem, ch) != 0)
                        return 0;
-               buf = pack_hex_byte(buf, ch[0]);
-               buf = pack_hex_byte(buf, ch[1]);
-               buf = pack_hex_byte(buf, ch[2]);
-               buf = pack_hex_byte(buf, ch[3]);
+               buf = hex_byte_pack(buf, ch[0]);
+               buf = hex_byte_pack(buf, ch[1]);
+               buf = hex_byte_pack(buf, ch[2]);
+               buf = hex_byte_pack(buf, ch[3]);
                mem += 4;
                count -= 4;
        }
@@ -826,8 +826,8 @@ unsigned char *mem2hex(const void *_mem, char *buf, int count, int may_fault)
        if (count >= 2) {
                if (gdbstub_read_word(mem, ch) != 0)
                        return 0;
-               buf = pack_hex_byte(buf, ch[0]);
-               buf = pack_hex_byte(buf, ch[1]);
+               buf = hex_byte_pack(buf, ch[0]);
+               buf = hex_byte_pack(buf, ch[1]);
                mem += 2;
                count -= 2;
        }
@@ -835,7 +835,7 @@ unsigned char *mem2hex(const void *_mem, char *buf, int count, int may_fault)
        if (count >= 1) {
                if (gdbstub_read_byte(mem, ch) != 0)
                        return 0;
-               buf = pack_hex_byte(buf, ch[0]);
+               buf = hex_byte_pack(buf, ch[0]);
        }
 
        *buf = 0;
@@ -1273,13 +1273,13 @@ static int gdbstub(struct pt_regs *regs, enum exception_code excep)
                ptr = mem2hex(title, ptr, sizeof(title) - 1, 0);
 
                hx = hex_asc_hi(excep >> 8);
-               ptr = pack_hex_byte(ptr, hx);
+               ptr = hex_byte_pack(ptr, hx);
                hx = hex_asc_lo(excep >> 8);
-               ptr = pack_hex_byte(ptr, hx);
+               ptr = hex_byte_pack(ptr, hx);
                hx = hex_asc_hi(excep);
-               ptr = pack_hex_byte(ptr, hx);
+               ptr = hex_byte_pack(ptr, hx);
                hx = hex_asc_lo(excep);
-               ptr = pack_hex_byte(ptr, hx);
+               ptr = hex_byte_pack(ptr, hx);
 
                ptr = mem2hex(crlf, ptr, sizeof(crlf) - 1, 0);
                *ptr = 0;
@@ -1291,21 +1291,21 @@ static int gdbstub(struct pt_regs *regs, enum exception_code excep)
                ptr = mem2hex(tbcberr, ptr, sizeof(tbcberr) - 1, 0);
 
                hx = hex_asc_hi(bcberr >> 24);
-               ptr = pack_hex_byte(ptr, hx);
+               ptr = hex_byte_pack(ptr, hx);
                hx = hex_asc_lo(bcberr >> 24);
-               ptr = pack_hex_byte(ptr, hx);
+               ptr = hex_byte_pack(ptr, hx);
                hx = hex_asc_hi(bcberr >> 16);
-               ptr = pack_hex_byte(ptr, hx);
+               ptr = hex_byte_pack(ptr, hx);
                hx = hex_asc_lo(bcberr >> 16);
-               ptr = pack_hex_byte(ptr, hx);
+               ptr = hex_byte_pack(ptr, hx);
                hx = hex_asc_hi(bcberr >> 8);
-               ptr = pack_hex_byte(ptr, hx);
+               ptr = hex_byte_pack(ptr, hx);
                hx = hex_asc_lo(bcberr >> 8);
-               ptr = pack_hex_byte(ptr, hx);
+               ptr = hex_byte_pack(ptr, hx);
                hx = hex_asc_hi(bcberr);
-               ptr = pack_hex_byte(ptr, hx);
+               ptr = hex_byte_pack(ptr, hx);
                hx = hex_asc_lo(bcberr);
-               ptr = pack_hex_byte(ptr, hx);
+               ptr = hex_byte_pack(ptr, hx);
 
                ptr = mem2hex(crlf, ptr, sizeof(crlf) - 1, 0);
                *ptr = 0;
@@ -1321,12 +1321,12 @@ static int gdbstub(struct pt_regs *regs, enum exception_code excep)
         * Send trap type (converted to signal)
         */
        *ptr++ = 'T';
-       ptr = pack_hex_byte(ptr, sigval);
+       ptr = hex_byte_pack(ptr, sigval);
 
        /*
         * Send Error PC
         */
-       ptr = pack_hex_byte(ptr, GDB_REGID_PC);
+       ptr = hex_byte_pack(ptr, GDB_REGID_PC);
        *ptr++ = ':';
        ptr = mem2hex(&regs->pc, ptr, 4, 0);
        *ptr++ = ';';
@@ -1334,7 +1334,7 @@ static int gdbstub(struct pt_regs *regs, enum exception_code excep)
        /*
         * Send frame pointer
         */
-       ptr = pack_hex_byte(ptr, GDB_REGID_FP);
+       ptr = hex_byte_pack(ptr, GDB_REGID_FP);
        *ptr++ = ':';
        ptr = mem2hex(&regs->a3, ptr, 4, 0);
        *ptr++ = ';';
@@ -1343,7 +1343,7 @@ static int gdbstub(struct pt_regs *regs, enum exception_code excep)
         * Send stack pointer
         */
        ssp = (unsigned long) (regs + 1);
-       ptr = pack_hex_byte(ptr, GDB_REGID_SP);
+       ptr = hex_byte_pack(ptr, GDB_REGID_SP);
        *ptr++ = ':';
        ptr = mem2hex(&ssp, ptr, 4, 0);
        *ptr++ = ';';
index a4f6c85431f8cc4d6edaa3e97ea454a0f4437946..08fe69edcd103f7882a3e172b7c5a55764009550 100644 (file)
@@ -148,6 +148,12 @@ struct kvm_regs {
 #define KVM_SREGS_E_UPDATE_DEC         (1 << 2)
 #define KVM_SREGS_E_UPDATE_DBSR                (1 << 3)
 
+/*
+ * Book3S special bits to indicate contents in the struct by maintaining
+ * backwards compatibility with older structs. If adding a new field,
+ * please make sure to add a flag for that new field */
+#define KVM_SREGS_S_HIOR               (1 << 0)
+
 /*
  * In KVM_SET_SREGS, reserved/pad fields must be left untouched from a
  * previous KVM_GET_REGS.
@@ -173,6 +179,8 @@ struct kvm_sregs {
                                __u64 ibat[8]; 
                                __u64 dbat[8]; 
                        } ppc32;
+                       __u64 flags; /* KVM_SREGS_S_ */
+                       __u64 hior;
                } s;
                struct {
                        union {
@@ -276,6 +284,11 @@ struct kvm_guest_debug_arch {
 #define KVM_INTERRUPT_UNSET    -2U
 #define KVM_INTERRUPT_SET_LEVEL        -3U
 
+#define KVM_CPU_440            1
+#define KVM_CPU_E500V2         2
+#define KVM_CPU_3S_32          3
+#define KVM_CPU_3S_64          4
+
 /* for KVM_CAP_SPAPR_TCE */
 struct kvm_create_spapr_tce {
        __u64 liobn;
index 98da010252a3b40c4383e7be3075a755b5f58929..a384ffdf33de0af850ca03f18aab3e6c36515540 100644 (file)
@@ -90,6 +90,8 @@ struct kvmppc_vcpu_book3s {
 #endif
        int context_id[SID_CONTEXTS];
 
+       bool hior_sregs;                /* HIOR is set by SREGS, not PVR */
+
        struct hlist_head hpte_hash_pte[HPTEG_HASH_NUM_PTE];
        struct hlist_head hpte_hash_pte_long[HPTEG_HASH_NUM_PTE_LONG];
        struct hlist_head hpte_hash_vpte[HPTEG_HASH_NUM_VPTE];
@@ -139,15 +141,14 @@ extern void kvmppc_giveup_ext(struct kvm_vcpu *vcpu, ulong msr);
 extern int kvmppc_emulate_paired_single(struct kvm_run *run, struct kvm_vcpu *vcpu);
 extern pfn_t kvmppc_gfn_to_pfn(struct kvm_vcpu *vcpu, gfn_t gfn);
 
-extern void kvmppc_handler_lowmem_trampoline(void);
-extern void kvmppc_handler_trampoline_enter(void);
-extern void kvmppc_rmcall(ulong srr0, ulong srr1);
+extern void kvmppc_entry_trampoline(void);
 extern void kvmppc_hv_entry_trampoline(void);
 extern void kvmppc_load_up_fpu(void);
 extern void kvmppc_load_up_altivec(void);
 extern void kvmppc_load_up_vsx(void);
 extern u32 kvmppc_alignment_dsisr(struct kvm_vcpu *vcpu, unsigned int inst);
 extern ulong kvmppc_alignment_dar(struct kvm_vcpu *vcpu, unsigned int inst);
+extern int kvmppc_h_pr(struct kvm_vcpu *vcpu, unsigned long cmd);
 
 static inline struct kvmppc_vcpu_book3s *to_book3s(struct kvm_vcpu *vcpu)
 {
@@ -382,6 +383,39 @@ static inline bool kvmppc_critical_section(struct kvm_vcpu *vcpu)
 }
 #endif
 
+static inline unsigned long compute_tlbie_rb(unsigned long v, unsigned long r,
+                                            unsigned long pte_index)
+{
+       unsigned long rb, va_low;
+
+       rb = (v & ~0x7fUL) << 16;               /* AVA field */
+       va_low = pte_index >> 3;
+       if (v & HPTE_V_SECONDARY)
+               va_low = ~va_low;
+       /* xor vsid from AVA */
+       if (!(v & HPTE_V_1TB_SEG))
+               va_low ^= v >> 12;
+       else
+               va_low ^= v >> 24;
+       va_low &= 0x7ff;
+       if (v & HPTE_V_LARGE) {
+               rb |= 1;                        /* L field */
+               if (cpu_has_feature(CPU_FTR_ARCH_206) &&
+                   (r & 0xff000)) {
+                       /* non-16MB large page, must be 64k */
+                       /* (masks depend on page size) */
+                       rb |= 0x1000;           /* page encoding in LP field */
+                       rb |= (va_low & 0x7f) << 16; /* 7b of VA in AVA/LP field */
+                       rb |= (va_low & 0xfe);  /* AVAL field (P7 doesn't seem to care) */
+               }
+       } else {
+               /* 4kB page */
+               rb |= (va_low & 0x7ff) << 12;   /* remaining 11b of VA */
+       }
+       rb |= (v >> 54) & 0x300;                /* B field */
+       return rb;
+}
+
 /* Magic register values loaded into r3 and r4 before the 'sc' assembly
  * instruction for the OSI hypercalls */
 #define OSI_SC_MAGIC_R3                        0x113724FA
index ef7b3688c3b6101531c4412d4e15eba3541802fb..1f2f5b6156bd01e6aa3a3752d4899f2ab0175f53 100644 (file)
@@ -75,6 +75,8 @@ struct kvmppc_host_state {
        ulong scratch0;
        ulong scratch1;
        u8 in_guest;
+       u8 restore_hid5;
+       u8 napping;
 
 #ifdef CONFIG_KVM_BOOK3S_64_HV
        struct kvm_vcpu *kvm_vcpu;
index cc22b282d75554a5c2dfc62be49b4408adb3711b..bf8af5d5d5dc6e6ad0a8799f69394b17c4e44300 100644 (file)
@@ -198,21 +198,29 @@ struct kvm_arch {
  */
 struct kvmppc_vcore {
        int n_runnable;
-       int n_blocked;
+       int n_busy;
        int num_threads;
        int entry_exit_count;
        int n_woken;
        int nap_count;
+       int napping_threads;
        u16 pcpu;
-       u8 vcore_running;
+       u8 vcore_state;
        u8 in_guest;
        struct list_head runnable_threads;
        spinlock_t lock;
+       wait_queue_head_t wq;
 };
 
 #define VCORE_ENTRY_COUNT(vc)  ((vc)->entry_exit_count & 0xff)
 #define VCORE_EXIT_COUNT(vc)   ((vc)->entry_exit_count >> 8)
 
+/* Values for vcore_state */
+#define VCORE_INACTIVE 0
+#define VCORE_RUNNING  1
+#define VCORE_EXITING  2
+#define VCORE_SLEEPING 3
+
 struct kvmppc_pte {
        ulong eaddr;
        u64 vpage;
@@ -258,14 +266,6 @@ struct kvm_vcpu_arch {
        ulong host_stack;
        u32 host_pid;
 #ifdef CONFIG_PPC_BOOK3S
-       ulong host_msr;
-       ulong host_r2;
-       void *host_retip;
-       ulong trampoline_lowmem;
-       ulong trampoline_enter;
-       ulong highmem_handler;
-       ulong rmcall;
-       ulong host_paca_phys;
        struct kvmppc_slb slb[64];
        int slb_max;            /* 1 + index of last valid entry in slb[] */
        int slb_nr;             /* total number of entries in SLB */
@@ -389,6 +389,9 @@ struct kvm_vcpu_arch {
        u8 dcr_is_write;
        u8 osi_needed;
        u8 osi_enabled;
+       u8 papr_enabled;
+       u8 sane;
+       u8 cpu_type;
        u8 hcall_needed;
 
        u32 cpr0_cfgaddr; /* holds the last set cpr0_cfgaddr */
@@ -408,11 +411,13 @@ struct kvm_vcpu_arch {
        struct dtl *dtl;
        struct dtl *dtl_end;
 
+       wait_queue_head_t *wqp;
        struct kvmppc_vcore *vcore;
        int ret;
        int trap;
        int state;
        int ptid;
+       bool timer_running;
        wait_queue_head_t cpu_run;
 
        struct kvm_vcpu_arch_shared *shared;
@@ -428,8 +433,9 @@ struct kvm_vcpu_arch {
 #endif
 };
 
-#define KVMPPC_VCPU_BUSY_IN_HOST       0
-#define KVMPPC_VCPU_BLOCKED            1
+/* Values for vcpu->arch.state */
+#define KVMPPC_VCPU_STOPPED            0
+#define KVMPPC_VCPU_BUSY_IN_HOST       1
 #define KVMPPC_VCPU_RUNNABLE           2
 
 #endif /* __POWERPC_KVM_HOST_H__ */
index d121f49d62b85186bc4f3eabe1af64ceab501534..46efd1a265c958775f390a4b72d53d40c8890e3a 100644 (file)
@@ -66,6 +66,7 @@ extern int kvmppc_emulate_instruction(struct kvm_run *run,
 extern int kvmppc_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu);
 extern void kvmppc_emulate_dec(struct kvm_vcpu *vcpu);
 extern u32 kvmppc_get_dec(struct kvm_vcpu *vcpu, u64 tb);
+extern int kvmppc_sanity_check(struct kvm_vcpu *vcpu);
 
 /* Core-specific hooks */
 
index fa0d27a400de917ee45a7a85dd75c2dbbaabb745..559ae1ee67061ca08ccbd69c24aa60e1019dc1a1 100644 (file)
@@ -354,3 +354,5 @@ COMPAT_SYS_SPU(clock_adjtime)
 SYSCALL_SPU(syncfs)
 COMPAT_SYS_SPU(sendmmsg)
 SYSCALL_SPU(setns)
+COMPAT_SYS(process_vm_readv)
+COMPAT_SYS(process_vm_writev)
index b8b3f599362b70167ab8db7c49038ad08f2b02f2..d3d1b5efd7eb1204405fde26c701e7c52b925fd9 100644 (file)
 #define __NR_syncfs            348
 #define __NR_sendmmsg          349
 #define __NR_setns             350
+#define __NR_process_vm_readv  351
+#define __NR_process_vm_writev 352
 
 #ifdef __KERNEL__
 
-#define __NR_syscalls          351
+#define __NR_syscalls          353
 
 #define __NR__exit __NR_exit
 #define NR_syscalls    __NR_syscalls
index 5f078bc2063e96c9b281283c553d65ac67dfaea5..69f7ffe7f6749479d5280d5317b3697e150259f4 100644 (file)
@@ -44,6 +44,7 @@
 #include <asm/compat.h>
 #include <asm/mmu.h>
 #include <asm/hvcall.h>
+#include <asm/xics.h>
 #endif
 #ifdef CONFIG_PPC_ISERIES
 #include <asm/iseries/alpaca.h>
@@ -449,8 +450,6 @@ int main(void)
 #ifdef CONFIG_PPC_BOOK3S
        DEFINE(VCPU_KVM, offsetof(struct kvm_vcpu, kvm));
        DEFINE(VCPU_VCPUID, offsetof(struct kvm_vcpu, vcpu_id));
-       DEFINE(VCPU_HOST_RETIP, offsetof(struct kvm_vcpu, arch.host_retip));
-       DEFINE(VCPU_HOST_MSR, offsetof(struct kvm_vcpu, arch.host_msr));
        DEFINE(VCPU_PURR, offsetof(struct kvm_vcpu, arch.purr));
        DEFINE(VCPU_SPURR, offsetof(struct kvm_vcpu, arch.spurr));
        DEFINE(VCPU_DSCR, offsetof(struct kvm_vcpu, arch.dscr));
@@ -458,14 +457,12 @@ int main(void)
        DEFINE(VCPU_UAMOR, offsetof(struct kvm_vcpu, arch.uamor));
        DEFINE(VCPU_CTRL, offsetof(struct kvm_vcpu, arch.ctrl));
        DEFINE(VCPU_DABR, offsetof(struct kvm_vcpu, arch.dabr));
-       DEFINE(VCPU_TRAMPOLINE_LOWMEM, offsetof(struct kvm_vcpu, arch.trampoline_lowmem));
-       DEFINE(VCPU_TRAMPOLINE_ENTER, offsetof(struct kvm_vcpu, arch.trampoline_enter));
-       DEFINE(VCPU_HIGHMEM_HANDLER, offsetof(struct kvm_vcpu, arch.highmem_handler));
-       DEFINE(VCPU_RMCALL, offsetof(struct kvm_vcpu, arch.rmcall));
        DEFINE(VCPU_HFLAGS, offsetof(struct kvm_vcpu, arch.hflags));
        DEFINE(VCPU_DEC, offsetof(struct kvm_vcpu, arch.dec));
        DEFINE(VCPU_DEC_EXPIRES, offsetof(struct kvm_vcpu, arch.dec_expires));
        DEFINE(VCPU_PENDING_EXC, offsetof(struct kvm_vcpu, arch.pending_exceptions));
+       DEFINE(VCPU_CEDED, offsetof(struct kvm_vcpu, arch.ceded));
+       DEFINE(VCPU_PRODDED, offsetof(struct kvm_vcpu, arch.prodded));
        DEFINE(VCPU_VPA, offsetof(struct kvm_vcpu, arch.vpa));
        DEFINE(VCPU_MMCR, offsetof(struct kvm_vcpu, arch.mmcr));
        DEFINE(VCPU_PMC, offsetof(struct kvm_vcpu, arch.pmc));
@@ -481,6 +478,7 @@ int main(void)
        DEFINE(VCORE_ENTRY_EXIT, offsetof(struct kvmppc_vcore, entry_exit_count));
        DEFINE(VCORE_NAP_COUNT, offsetof(struct kvmppc_vcore, nap_count));
        DEFINE(VCORE_IN_GUEST, offsetof(struct kvmppc_vcore, in_guest));
+       DEFINE(VCORE_NAPPING_THREADS, offsetof(struct kvmppc_vcore, napping_threads));
        DEFINE(VCPU_SVCPU, offsetof(struct kvmppc_vcpu_book3s, shadow_vcpu) -
                           offsetof(struct kvmppc_vcpu_book3s, vcpu));
        DEFINE(VCPU_SLB_E, offsetof(struct kvmppc_slb, orige));
@@ -537,6 +535,8 @@ int main(void)
        HSTATE_FIELD(HSTATE_SCRATCH0, scratch0);
        HSTATE_FIELD(HSTATE_SCRATCH1, scratch1);
        HSTATE_FIELD(HSTATE_IN_GUEST, in_guest);
+       HSTATE_FIELD(HSTATE_RESTORE_HID5, restore_hid5);
+       HSTATE_FIELD(HSTATE_NAPPING, napping);
 
 #ifdef CONFIG_KVM_BOOK3S_64_HV
        HSTATE_FIELD(HSTATE_KVM_VCPU, kvm_vcpu);
@@ -549,6 +549,7 @@ int main(void)
        HSTATE_FIELD(HSTATE_DSCR, host_dscr);
        HSTATE_FIELD(HSTATE_DABR, dabr);
        HSTATE_FIELD(HSTATE_DECEXP, dec_expires);
+       DEFINE(IPI_PRIORITY, IPI_PRIORITY);
 #endif /* CONFIG_KVM_BOOK3S_64_HV */
 
 #else /* CONFIG_PPC_BOOK3S */
index 41b02c792aa387b43c16f8d861564be1482cde01..29ddd8b1c274eb2f32931da320a1c690c2fd1215 100644 (file)
@@ -427,16 +427,6 @@ slb_miss_user_pseries:
        b       .                               /* prevent spec. execution */
 #endif /* __DISABLED__ */
 
-/* KVM's trampoline code needs to be close to the interrupt handlers */
-
-#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
-#ifdef CONFIG_KVM_BOOK3S_PR
-#include "../kvm/book3s_rmhandlers.S"
-#else
-#include "../kvm/book3s_hv_rmhandlers.S"
-#endif
-#endif
-
        .align  7
        .globl  __end_interrupts
 __end_interrupts:
index da3a1225c0ac10117918f105799f8d60b20665ce..ca1f88b3dc596fb099c8fba2a9659fbe047592f5 100644 (file)
@@ -78,6 +78,8 @@ int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu)
        for (i = 0; i < ARRAY_SIZE(vcpu_44x->shadow_refs); i++)
                vcpu_44x->shadow_refs[i].gtlb_index = -1;
 
+       vcpu->arch.cpu_type = KVM_CPU_440;
+
        return 0;
 }
 
index 08428e2c188d675eb16b58ab18acbcb85323ca7b..3688aeecc4b24e1762a7289dc8d61a54a44c1ac7 100644 (file)
@@ -43,18 +43,22 @@ kvm-book3s_64-objs-$(CONFIG_KVM_BOOK3S_64_PR) := \
        fpu.o \
        book3s_paired_singles.o \
        book3s_pr.o \
+       book3s_pr_papr.o \
        book3s_emulate.o \
        book3s_interrupts.o \
        book3s_mmu_hpte.o \
        book3s_64_mmu_host.o \
        book3s_64_mmu.o \
        book3s_32_mmu.o
+kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_PR) := \
+       book3s_rmhandlers.o
 
 kvm-book3s_64-objs-$(CONFIG_KVM_BOOK3S_64_HV) := \
        book3s_hv.o \
        book3s_hv_interrupts.o \
        book3s_64_mmu_hv.o
 kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HV) := \
+       book3s_hv_rmhandlers.o \
        book3s_hv_rm_mmu.o \
        book3s_64_vio_hv.o \
        book3s_hv_builtin.o
index 3608471ad2d816185c522adf1518d4cc6222c44b..7e06a6fc8d07cdf34c72801b74db507607aaa40f 100644 (file)
@@ -31,7 +31,7 @@
         * R1 = host R1
         * R2 = host R2
         * R3 = shadow vcpu
-        * all other volatile GPRS = free
+        * all other volatile GPRS = free except R4, R6
         * SVCPU[CR]  = guest CR
         * SVCPU[XER] = guest XER
         * SVCPU[CTR] = guest CTR
index c6d3e194b6b4c2d42a4904c0d887e387cc0a50a7..b871721c0050e8e3f04353f80c925f63c89afded 100644 (file)
@@ -128,7 +128,13 @@ static hva_t kvmppc_mmu_book3s_64_get_pteg(
        dprintk("MMU: page=0x%x sdr1=0x%llx pteg=0x%llx vsid=0x%llx\n",
                page, vcpu_book3s->sdr1, pteg, slbe->vsid);
 
-       r = gfn_to_hva(vcpu_book3s->vcpu.kvm, pteg >> PAGE_SHIFT);
+       /* When running a PAPR guest, SDR1 contains a HVA address instead
+           of a GPA */
+       if (vcpu_book3s->vcpu.arch.papr_enabled)
+               r = pteg;
+       else
+               r = gfn_to_hva(vcpu_book3s->vcpu.kvm, pteg >> PAGE_SHIFT);
+
        if (kvm_is_error_hva(r))
                return r;
        return r | (pteg & ~PAGE_MASK);
index 04e7d3bbfe8bb8d36144a5ab7af95d4bb503d007..f2e6e48ea463c9cdb404bb384ce672244f0e795f 100644 (file)
@@ -53,7 +53,7 @@ slb_exit_skip_ ## num:
         * R1 = host R1
         * R2 = host R2
         * R3 = shadow vcpu
-        * all other volatile GPRS = free
+        * all other volatile GPRS = free except R4, R6
         * SVCPU[CR]  = guest CR
         * SVCPU[XER] = guest XER
         * SVCPU[CTR] = guest CTR
index 46684655708949cdd4dac48588b5e30865848668..0c9dc62532d02c78c2480d569fc014cb637713b1 100644 (file)
  * function pointers, so let's just disable the define. */
 #undef mfsrin
 
+enum priv_level {
+       PRIV_PROBLEM = 0,
+       PRIV_SUPER = 1,
+       PRIV_HYPER = 2,
+};
+
+static bool spr_allowed(struct kvm_vcpu *vcpu, enum priv_level level)
+{
+       /* PAPR VMs only access supervisor SPRs */
+       if (vcpu->arch.papr_enabled && (level > PRIV_SUPER))
+               return false;
+
+       /* Limit user space to its own small SPR set */
+       if ((vcpu->arch.shared->msr & MSR_PR) && level > PRIV_PROBLEM)
+               return false;
+
+       return true;
+}
+
 int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
                            unsigned int inst, int *advance)
 {
@@ -296,6 +315,8 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)
 
        switch (sprn) {
        case SPRN_SDR1:
+               if (!spr_allowed(vcpu, PRIV_HYPER))
+                       goto unprivileged;
                to_book3s(vcpu)->sdr1 = spr_val;
                break;
        case SPRN_DSISR:
@@ -390,6 +411,7 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)
        case SPRN_PMC4_GEKKO:
        case SPRN_WPAR_GEKKO:
                break;
+unprivileged:
        default:
                printk(KERN_INFO "KVM: invalid SPR write: %d\n", sprn);
 #ifndef DEBUG_SPR
@@ -421,6 +443,8 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt)
                break;
        }
        case SPRN_SDR1:
+               if (!spr_allowed(vcpu, PRIV_HYPER))
+                       goto unprivileged;
                kvmppc_set_gpr(vcpu, rt, to_book3s(vcpu)->sdr1);
                break;
        case SPRN_DSISR:
@@ -449,6 +473,10 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt)
        case SPRN_HID5:
                kvmppc_set_gpr(vcpu, rt, to_book3s(vcpu)->hid[5]);
                break;
+       case SPRN_CFAR:
+       case SPRN_PURR:
+               kvmppc_set_gpr(vcpu, rt, 0);
+               break;
        case SPRN_GQR0:
        case SPRN_GQR1:
        case SPRN_GQR2:
@@ -476,6 +504,7 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt)
                kvmppc_set_gpr(vcpu, rt, 0);
                break;
        default:
+unprivileged:
                printk(KERN_INFO "KVM: invalid SPR read: %d\n", sprn);
 #ifndef DEBUG_SPR
                emulated = EMULATE_FAIL;
index 88c8f26add023e7d2cd6669f1e521f0f832d6ba0..f7f63a00ab1f5cfb5359618dffe8f58cecde42b0 100644 (file)
@@ -23,9 +23,7 @@
 #ifdef CONFIG_KVM_BOOK3S_64_HV
 EXPORT_SYMBOL_GPL(kvmppc_hv_entry_trampoline);
 #else
-EXPORT_SYMBOL_GPL(kvmppc_handler_trampoline_enter);
-EXPORT_SYMBOL_GPL(kvmppc_handler_lowmem_trampoline);
-EXPORT_SYMBOL_GPL(kvmppc_rmcall);
+EXPORT_SYMBOL_GPL(kvmppc_entry_trampoline);
 EXPORT_SYMBOL_GPL(kvmppc_load_up_fpu);
 #ifdef CONFIG_ALTIVEC
 EXPORT_SYMBOL_GPL(kvmppc_load_up_altivec);
index cc0d7f1b19ab474f62c702192f8fb44ff8ecf216..4644c7986d8020c681ec1c03c9bc747e055a335f 100644 (file)
@@ -62,6 +62,8 @@
 /* #define EXIT_DEBUG_SIMPLE */
 /* #define EXIT_DEBUG_INT */
 
+static void kvmppc_end_cede(struct kvm_vcpu *vcpu);
+
 void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
 {
        local_paca->kvm_hstate.kvm_vcpu = vcpu;
@@ -72,40 +74,10 @@ void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu)
 {
 }
 
-static void kvmppc_vcpu_blocked(struct kvm_vcpu *vcpu);
-static void kvmppc_vcpu_unblocked(struct kvm_vcpu *vcpu);
-
-void kvmppc_vcpu_block(struct kvm_vcpu *vcpu)
-{
-       u64 now;
-       unsigned long dec_nsec;
-
-       now = get_tb();
-       if (now >= vcpu->arch.dec_expires && !kvmppc_core_pending_dec(vcpu))
-               kvmppc_core_queue_dec(vcpu);
-       if (vcpu->arch.pending_exceptions)
-               return;
-       if (vcpu->arch.dec_expires != ~(u64)0) {
-               dec_nsec = (vcpu->arch.dec_expires - now) * NSEC_PER_SEC /
-                       tb_ticks_per_sec;
-               hrtimer_start(&vcpu->arch.dec_timer, ktime_set(0, dec_nsec),
-                             HRTIMER_MODE_REL);
-       }
-
-       kvmppc_vcpu_blocked(vcpu);
-
-       kvm_vcpu_block(vcpu);
-       vcpu->stat.halt_wakeup++;
-
-       if (vcpu->arch.dec_expires != ~(u64)0)
-               hrtimer_try_to_cancel(&vcpu->arch.dec_timer);
-
-       kvmppc_vcpu_unblocked(vcpu);
-}
-
 void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 msr)
 {
        vcpu->arch.shregs.msr = msr;
+       kvmppc_end_cede(vcpu);
 }
 
 void kvmppc_set_pvr(struct kvm_vcpu *vcpu, u32 pvr)
@@ -257,15 +229,6 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)
 
        switch (req) {
        case H_CEDE:
-               vcpu->arch.shregs.msr |= MSR_EE;
-               vcpu->arch.ceded = 1;
-               smp_mb();
-               if (!vcpu->arch.prodded)
-                       kvmppc_vcpu_block(vcpu);
-               else
-                       vcpu->arch.prodded = 0;
-               smp_mb();
-               vcpu->arch.ceded = 0;
                break;
        case H_PROD:
                target = kvmppc_get_gpr(vcpu, 4);
@@ -388,20 +351,6 @@ static int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
                break;
        }
 
-
-       if (!(r & RESUME_HOST)) {
-               /* To avoid clobbering exit_reason, only check for signals if
-                * we aren't already exiting to userspace for some other
-                * reason. */
-               if (signal_pending(tsk)) {
-                       vcpu->stat.signal_exits++;
-                       run->exit_reason = KVM_EXIT_INTR;
-                       r = -EINTR;
-               } else {
-                       kvmppc_core_deliver_interrupts(vcpu);
-               }
-       }
-
        return r;
 }
 
@@ -479,13 +428,9 @@ struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id)
        kvmppc_mmu_book3s_hv_init(vcpu);
 
        /*
-        * Some vcpus may start out in stopped state.  If we initialize
-        * them to busy-in-host state they will stop other vcpus in the
-        * vcore from running.  Instead we initialize them to blocked
-        * state, effectively considering them to be stopped until we
-        * see the first run ioctl for them.
+        * We consider the vcpu stopped until we see the first run ioctl for it.
         */
-       vcpu->arch.state = KVMPPC_VCPU_BLOCKED;
+       vcpu->arch.state = KVMPPC_VCPU_STOPPED;
 
        init_waitqueue_head(&vcpu->arch.cpu_run);
 
@@ -496,6 +441,7 @@ struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id)
                if (vcore) {
                        INIT_LIST_HEAD(&vcore->runnable_threads);
                        spin_lock_init(&vcore->lock);
+                       init_waitqueue_head(&vcore->wq);
                }
                kvm->arch.vcores[core] = vcore;
        }
@@ -506,10 +452,12 @@ struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id)
 
        spin_lock(&vcore->lock);
        ++vcore->num_threads;
-       ++vcore->n_blocked;
        spin_unlock(&vcore->lock);
        vcpu->arch.vcore = vcore;
 
+       vcpu->arch.cpu_type = KVM_CPU_3S_64;
+       kvmppc_sanity_check(vcpu);
+
        return vcpu;
 
 free_vcpu:
@@ -524,30 +472,31 @@ void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)
        kfree(vcpu);
 }
 
-static void kvmppc_vcpu_blocked(struct kvm_vcpu *vcpu)
+static void kvmppc_set_timer(struct kvm_vcpu *vcpu)
 {
-       struct kvmppc_vcore *vc = vcpu->arch.vcore;
+       unsigned long dec_nsec, now;
 
-       spin_lock(&vc->lock);
-       vcpu->arch.state = KVMPPC_VCPU_BLOCKED;
-       ++vc->n_blocked;
-       if (vc->n_runnable > 0 &&
-           vc->n_runnable + vc->n_blocked == vc->num_threads) {
-               vcpu = list_first_entry(&vc->runnable_threads, struct kvm_vcpu,
-                                       arch.run_list);
-               wake_up(&vcpu->arch.cpu_run);
+       now = get_tb();
+       if (now > vcpu->arch.dec_expires) {
+               /* decrementer has already gone negative */
+               kvmppc_core_queue_dec(vcpu);
+               kvmppc_core_deliver_interrupts(vcpu);
+               return;
        }
-       spin_unlock(&vc->lock);
+       dec_nsec = (vcpu->arch.dec_expires - now) * NSEC_PER_SEC
+                  / tb_ticks_per_sec;
+       hrtimer_start(&vcpu->arch.dec_timer, ktime_set(0, dec_nsec),
+                     HRTIMER_MODE_REL);
+       vcpu->arch.timer_running = 1;
 }
 
-static void kvmppc_vcpu_unblocked(struct kvm_vcpu *vcpu)
+static void kvmppc_end_cede(struct kvm_vcpu *vcpu)
 {
-       struct kvmppc_vcore *vc = vcpu->arch.vcore;
-
-       spin_lock(&vc->lock);
-       vcpu->arch.state = KVMPPC_VCPU_BUSY_IN_HOST;
-       --vc->n_blocked;
-       spin_unlock(&vc->lock);
+       vcpu->arch.ceded = 0;
+       if (vcpu->arch.timer_running) {
+               hrtimer_try_to_cancel(&vcpu->arch.dec_timer);
+               vcpu->arch.timer_running = 0;
+       }
 }
 
 extern int __kvmppc_vcore_entry(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu);
@@ -562,6 +511,7 @@ static void kvmppc_remove_runnable(struct kvmppc_vcore *vc,
                return;
        vcpu->arch.state = KVMPPC_VCPU_BUSY_IN_HOST;
        --vc->n_runnable;
+       ++vc->n_busy;
        /* decrement the physical thread id of each following vcpu */
        v = vcpu;
        list_for_each_entry_continue(v, &vc->runnable_threads, arch.run_list)
@@ -575,15 +525,20 @@ static void kvmppc_start_thread(struct kvm_vcpu *vcpu)
        struct paca_struct *tpaca;
        struct kvmppc_vcore *vc = vcpu->arch.vcore;
 
+       if (vcpu->arch.timer_running) {
+               hrtimer_try_to_cancel(&vcpu->arch.dec_timer);
+               vcpu->arch.timer_running = 0;
+       }
        cpu = vc->pcpu + vcpu->arch.ptid;
        tpaca = &paca[cpu];
        tpaca->kvm_hstate.kvm_vcpu = vcpu;
        tpaca->kvm_hstate.kvm_vcore = vc;
+       tpaca->kvm_hstate.napping = 0;
+       vcpu->cpu = vc->pcpu;
        smp_wmb();
 #ifdef CONFIG_PPC_ICP_NATIVE
        if (vcpu->arch.ptid) {
                tpaca->cpu_start = 0x80;
-               tpaca->kvm_hstate.in_guest = KVM_GUEST_MODE_GUEST;
                wmb();
                xics_wake_cpu(cpu);
                ++vc->n_woken;
@@ -631,9 +586,10 @@ static int on_primary_thread(void)
  */
 static int kvmppc_run_core(struct kvmppc_vcore *vc)
 {
-       struct kvm_vcpu *vcpu, *vnext;
+       struct kvm_vcpu *vcpu, *vcpu0, *vnext;
        long ret;
        u64 now;
+       int ptid;
 
        /* don't start if any threads have a signal pending */
        list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list)
@@ -652,29 +608,50 @@ static int kvmppc_run_core(struct kvmppc_vcore *vc)
                goto out;
        }
 
+       /*
+        * Assign physical thread IDs, first to non-ceded vcpus
+        * and then to ceded ones.
+        */
+       ptid = 0;
+       vcpu0 = NULL;
+       list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) {
+               if (!vcpu->arch.ceded) {
+                       if (!ptid)
+                               vcpu0 = vcpu;
+                       vcpu->arch.ptid = ptid++;
+               }
+       }
+       if (!vcpu0)
+               return 0;               /* nothing to run */
+       list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list)
+               if (vcpu->arch.ceded)
+                       vcpu->arch.ptid = ptid++;
+
        vc->n_woken = 0;
        vc->nap_count = 0;
        vc->entry_exit_count = 0;
-       vc->vcore_running = 1;
+       vc->vcore_state = VCORE_RUNNING;
        vc->in_guest = 0;
        vc->pcpu = smp_processor_id();
+       vc->napping_threads = 0;
        list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list)
                kvmppc_start_thread(vcpu);
-       vcpu = list_first_entry(&vc->runnable_threads, struct kvm_vcpu,
-                               arch.run_list);
 
+       preempt_disable();
        spin_unlock(&vc->lock);
 
-       preempt_disable();
        kvm_guest_enter();
-       __kvmppc_vcore_entry(NULL, vcpu);
+       __kvmppc_vcore_entry(NULL, vcpu0);
 
-       /* wait for secondary threads to finish writing their state to memory */
        spin_lock(&vc->lock);
+       /* disable sending of IPIs on virtual external irqs */
+       list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list)
+               vcpu->cpu = -1;
+       /* wait for secondary threads to finish writing their state to memory */
        if (vc->nap_count < vc->n_woken)
                kvmppc_wait_for_nap(vc);
        /* prevent other vcpu threads from doing kvmppc_start_thread() now */
-       vc->vcore_running = 2;
+       vc->vcore_state = VCORE_EXITING;
        spin_unlock(&vc->lock);
 
        /* make sure updates to secondary vcpu structs are visible now */
@@ -690,22 +667,26 @@ static int kvmppc_run_core(struct kvmppc_vcore *vc)
                if (now < vcpu->arch.dec_expires &&
                    kvmppc_core_pending_dec(vcpu))
                        kvmppc_core_dequeue_dec(vcpu);
-               if (!vcpu->arch.trap) {
-                       if (signal_pending(vcpu->arch.run_task)) {
-                               vcpu->arch.kvm_run->exit_reason = KVM_EXIT_INTR;
-                               vcpu->arch.ret = -EINTR;
-                       }
-                       continue;               /* didn't get to run */
-               }
-               ret = kvmppc_handle_exit(vcpu->arch.kvm_run, vcpu,
-                                        vcpu->arch.run_task);
+
+               ret = RESUME_GUEST;
+               if (vcpu->arch.trap)
+                       ret = kvmppc_handle_exit(vcpu->arch.kvm_run, vcpu,
+                                                vcpu->arch.run_task);
+
                vcpu->arch.ret = ret;
                vcpu->arch.trap = 0;
+
+               if (vcpu->arch.ceded) {
+                       if (ret != RESUME_GUEST)
+                               kvmppc_end_cede(vcpu);
+                       else
+                               kvmppc_set_timer(vcpu);
+               }
        }
 
        spin_lock(&vc->lock);
  out:
-       vc->vcore_running = 0;
+       vc->vcore_state = VCORE_INACTIVE;
        list_for_each_entry_safe(vcpu, vnext, &vc->runnable_threads,
                                 arch.run_list) {
                if (vcpu->arch.ret != RESUME_GUEST) {
@@ -717,82 +698,130 @@ static int kvmppc_run_core(struct kvmppc_vcore *vc)
        return 1;
 }
 
-static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
+/*
+ * Wait for some other vcpu thread to execute us, and
+ * wake us up when we need to handle something in the host.
+ */
+static void kvmppc_wait_for_exec(struct kvm_vcpu *vcpu, int wait_state)
 {
-       int ptid;
-       int wait_state;
-       struct kvmppc_vcore *vc;
        DEFINE_WAIT(wait);
 
-       /* No need to go into the guest when all we do is going out */
-       if (signal_pending(current)) {
-               kvm_run->exit_reason = KVM_EXIT_INTR;
-               return -EINTR;
+       prepare_to_wait(&vcpu->arch.cpu_run, &wait, wait_state);
+       if (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE)
+               schedule();
+       finish_wait(&vcpu->arch.cpu_run, &wait);
+}
+
+/*
+ * All the vcpus in this vcore are idle, so wait for a decrementer
+ * or external interrupt to one of the vcpus.  vc->lock is held.
+ */
+static void kvmppc_vcore_blocked(struct kvmppc_vcore *vc)
+{
+       DEFINE_WAIT(wait);
+       struct kvm_vcpu *v;
+       int all_idle = 1;
+
+       prepare_to_wait(&vc->wq, &wait, TASK_INTERRUPTIBLE);
+       vc->vcore_state = VCORE_SLEEPING;
+       spin_unlock(&vc->lock);
+       list_for_each_entry(v, &vc->runnable_threads, arch.run_list) {
+               if (!v->arch.ceded || v->arch.pending_exceptions) {
+                       all_idle = 0;
+                       break;
+               }
        }
+       if (all_idle)
+               schedule();
+       finish_wait(&vc->wq, &wait);
+       spin_lock(&vc->lock);
+       vc->vcore_state = VCORE_INACTIVE;
+}
 
-       /* On PPC970, check that we have an RMA region */
-       if (!vcpu->kvm->arch.rma && cpu_has_feature(CPU_FTR_ARCH_201))
-               return -EPERM;
+static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
+{
+       int n_ceded;
+       int prev_state;
+       struct kvmppc_vcore *vc;
+       struct kvm_vcpu *v, *vn;
 
        kvm_run->exit_reason = 0;
        vcpu->arch.ret = RESUME_GUEST;
        vcpu->arch.trap = 0;
 
-       flush_fp_to_thread(current);
-       flush_altivec_to_thread(current);
-       flush_vsx_to_thread(current);
-
        /*
         * Synchronize with other threads in this virtual core
         */
        vc = vcpu->arch.vcore;
        spin_lock(&vc->lock);
-       /* This happens the first time this is called for a vcpu */
-       if (vcpu->arch.state == KVMPPC_VCPU_BLOCKED)
-               --vc->n_blocked;
-       vcpu->arch.state = KVMPPC_VCPU_RUNNABLE;
-       ptid = vc->n_runnable;
+       vcpu->arch.ceded = 0;
        vcpu->arch.run_task = current;
        vcpu->arch.kvm_run = kvm_run;
-       vcpu->arch.ptid = ptid;
+       prev_state = vcpu->arch.state;
+       vcpu->arch.state = KVMPPC_VCPU_RUNNABLE;
        list_add_tail(&vcpu->arch.run_list, &vc->runnable_threads);
        ++vc->n_runnable;
 
-       wait_state = TASK_INTERRUPTIBLE;
-       while (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE) {
-               if (signal_pending(current)) {
-                       if (!vc->vcore_running) {
-                               kvm_run->exit_reason = KVM_EXIT_INTR;
-                               vcpu->arch.ret = -EINTR;
-                               break;
-                       }
-                       /* have to wait for vcore to stop executing guest */
-                       wait_state = TASK_UNINTERRUPTIBLE;
-                       smp_send_reschedule(vc->pcpu);
+       /*
+        * This happens the first time this is called for a vcpu.
+        * If the vcore is already running, we may be able to start
+        * this thread straight away and have it join in.
+        */
+       if (prev_state == KVMPPC_VCPU_STOPPED) {
+               if (vc->vcore_state == VCORE_RUNNING &&
+                   VCORE_EXIT_COUNT(vc) == 0) {
+                       vcpu->arch.ptid = vc->n_runnable - 1;
+                       kvmppc_start_thread(vcpu);
                }
 
-               if (!vc->vcore_running &&
-                   vc->n_runnable + vc->n_blocked == vc->num_threads) {
-                       /* we can run now */
-                       if (kvmppc_run_core(vc))
-                               continue;
-               }
+       } else if (prev_state == KVMPPC_VCPU_BUSY_IN_HOST)
+               --vc->n_busy;
 
-               if (vc->vcore_running == 1 && VCORE_EXIT_COUNT(vc) == 0)
-                       kvmppc_start_thread(vcpu);
+       while (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE &&
+              !signal_pending(current)) {
+               if (vc->n_busy || vc->vcore_state != VCORE_INACTIVE) {
+                       spin_unlock(&vc->lock);
+                       kvmppc_wait_for_exec(vcpu, TASK_INTERRUPTIBLE);
+                       spin_lock(&vc->lock);
+                       continue;
+               }
+               n_ceded = 0;
+               list_for_each_entry(v, &vc->runnable_threads, arch.run_list)
+                       n_ceded += v->arch.ceded;
+               if (n_ceded == vc->n_runnable)
+                       kvmppc_vcore_blocked(vc);
+               else
+                       kvmppc_run_core(vc);
+
+               list_for_each_entry_safe(v, vn, &vc->runnable_threads,
+                                        arch.run_list) {
+                       kvmppc_core_deliver_interrupts(v);
+                       if (signal_pending(v->arch.run_task)) {
+                               kvmppc_remove_runnable(vc, v);
+                               v->stat.signal_exits++;
+                               v->arch.kvm_run->exit_reason = KVM_EXIT_INTR;
+                               v->arch.ret = -EINTR;
+                               wake_up(&v->arch.cpu_run);
+                       }
+               }
+       }
 
-               /* wait for other threads to come in, or wait for vcore */
-               prepare_to_wait(&vcpu->arch.cpu_run, &wait, wait_state);
-               spin_unlock(&vc->lock);
-               schedule();
-               finish_wait(&vcpu->arch.cpu_run, &wait);
-               spin_lock(&vc->lock);
+       if (signal_pending(current)) {
+               if (vc->vcore_state == VCORE_RUNNING ||
+                   vc->vcore_state == VCORE_EXITING) {
+                       spin_unlock(&vc->lock);
+                       kvmppc_wait_for_exec(vcpu, TASK_UNINTERRUPTIBLE);
+                       spin_lock(&vc->lock);
+               }
+               if (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE) {
+                       kvmppc_remove_runnable(vc, vcpu);
+                       vcpu->stat.signal_exits++;
+                       kvm_run->exit_reason = KVM_EXIT_INTR;
+                       vcpu->arch.ret = -EINTR;
+               }
        }
 
-       if (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE)
-               kvmppc_remove_runnable(vc, vcpu);
        spin_unlock(&vc->lock);
-
        return vcpu->arch.ret;
 }
 
@@ -800,6 +829,26 @@ int kvmppc_vcpu_run(struct kvm_run *run, struct kvm_vcpu *vcpu)
 {
        int r;
 
+       if (!vcpu->arch.sane) {
+               run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
+               return -EINVAL;
+       }
+
+       /* No need to go into the guest when all we'll do is come back out */
+       if (signal_pending(current)) {
+               run->exit_reason = KVM_EXIT_INTR;
+               return -EINTR;
+       }
+
+       /* On PPC970, check that we have an RMA region */
+       if (!vcpu->kvm->arch.rma && cpu_has_feature(CPU_FTR_ARCH_201))
+               return -EPERM;
+
+       flush_fp_to_thread(current);
+       flush_altivec_to_thread(current);
+       flush_vsx_to_thread(current);
+       vcpu->arch.wqp = &vcpu->arch.vcore->wq;
+
        do {
                r = kvmppc_run_vcpu(run, vcpu);
 
index fcfe6b0555587b3afca7991fc66935deac69248e..bacb0cfa3602023ec28755766899d5433a20bf5c 100644 (file)
@@ -110,39 +110,6 @@ long kvmppc_h_enter(struct kvm_vcpu *vcpu, unsigned long flags,
        return H_SUCCESS;
 }
 
-static unsigned long compute_tlbie_rb(unsigned long v, unsigned long r,
-                                     unsigned long pte_index)
-{
-       unsigned long rb, va_low;
-
-       rb = (v & ~0x7fUL) << 16;               /* AVA field */
-       va_low = pte_index >> 3;
-       if (v & HPTE_V_SECONDARY)
-               va_low = ~va_low;
-       /* xor vsid from AVA */
-       if (!(v & HPTE_V_1TB_SEG))
-               va_low ^= v >> 12;
-       else
-               va_low ^= v >> 24;
-       va_low &= 0x7ff;
-       if (v & HPTE_V_LARGE) {
-               rb |= 1;                        /* L field */
-               if (cpu_has_feature(CPU_FTR_ARCH_206) &&
-                   (r & 0xff000)) {
-                       /* non-16MB large page, must be 64k */
-                       /* (masks depend on page size) */
-                       rb |= 0x1000;           /* page encoding in LP field */
-                       rb |= (va_low & 0x7f) << 16; /* 7b of VA in AVA/LP field */
-                       rb |= (va_low & 0xfe);  /* AVAL field (P7 doesn't seem to care) */
-               }
-       } else {
-               /* 4kB page */
-               rb |= (va_low & 0x7ff) << 12;   /* remaining 11b of VA */
-       }
-       rb |= (v >> 54) & 0x300;                /* B field */
-       return rb;
-}
-
 #define LOCK_TOKEN     (*(u32 *)(&get_paca()->lock_token))
 
 static inline int try_lock_tlbie(unsigned int *lock)
index de2950135e6ef2e152948983c631e302469ba281..f422231d92353771bcf663eb6dbb9393bcb161aa 100644 (file)
 #include <asm/ppc_asm.h>
 #include <asm/kvm_asm.h>
 #include <asm/reg.h>
+#include <asm/mmu.h>
 #include <asm/page.h>
+#include <asm/ptrace.h>
+#include <asm/hvcall.h>
 #include <asm/asm-offsets.h>
 #include <asm/exception-64s.h>
 
@@ -49,7 +52,7 @@ kvmppc_skip_Hinterrupt:
        b       .
 
 /*
- * Call kvmppc_handler_trampoline_enter in real mode.
+ * Call kvmppc_hv_entry in real mode.
  * Must be called with interrupts hard-disabled.
  *
  * Input Registers:
@@ -89,6 +92,12 @@ _GLOBAL(kvmppc_hv_entry_trampoline)
 kvm_start_guest:
        ld      r1,PACAEMERGSP(r13)
        subi    r1,r1,STACK_FRAME_OVERHEAD
+       ld      r2,PACATOC(r13)
+
+       /* were we napping due to cede? */
+       lbz     r0,HSTATE_NAPPING(r13)
+       cmpwi   r0,0
+       bne     kvm_end_cede
 
        /* get vcpu pointer */
        ld      r4, HSTATE_KVM_VCPU(r13)
@@ -276,15 +285,9 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
        cmpwi   r0,0
        beq     20b
 
-       /* Set LPCR.  Set the MER bit if there is a pending external irq. */
+       /* Set LPCR and RMOR. */
 10:    ld      r8,KVM_LPCR(r9)
-       ld      r0,VCPU_PENDING_EXC(r4)
-       li      r7,(1 << BOOK3S_IRQPRIO_EXTERNAL)
-       oris    r7,r7,(1 << BOOK3S_IRQPRIO_EXTERNAL_LEVEL)@h
-       and.    r0,r0,r7
-       beq     11f
-       ori     r8,r8,LPCR_MER
-11:    mtspr   SPRN_LPCR,r8
+       mtspr   SPRN_LPCR,r8
        ld      r8,KVM_RMOR(r9)
        mtspr   SPRN_RMOR,r8
        isync
@@ -448,19 +451,50 @@ toc_tlbie_lock:
        mtctr   r6
        mtxer   r7
 
-       /* Move SRR0 and SRR1 into the respective regs */
+kvmppc_cede_reentry:           /* r4 = vcpu, r13 = paca */
        ld      r6, VCPU_SRR0(r4)
        ld      r7, VCPU_SRR1(r4)
-       mtspr   SPRN_SRR0, r6
-       mtspr   SPRN_SRR1, r7
-
        ld      r10, VCPU_PC(r4)
+       ld      r11, VCPU_MSR(r4)       /* r11 = vcpu->arch.msr & ~MSR_HV */
 
-       ld      r11, VCPU_MSR(r4)       /* r10 = vcpu->arch.msr & ~MSR_HV */
        rldicl  r11, r11, 63 - MSR_HV_LG, 1
        rotldi  r11, r11, 1 + MSR_HV_LG
        ori     r11, r11, MSR_ME
 
+       /* Check if we can deliver an external or decrementer interrupt now */
+       ld      r0,VCPU_PENDING_EXC(r4)
+       li      r8,(1 << BOOK3S_IRQPRIO_EXTERNAL)
+       oris    r8,r8,(1 << BOOK3S_IRQPRIO_EXTERNAL_LEVEL)@h
+       and     r0,r0,r8
+       cmpdi   cr1,r0,0
+       andi.   r0,r11,MSR_EE
+       beq     cr1,11f
+BEGIN_FTR_SECTION
+       mfspr   r8,SPRN_LPCR
+       ori     r8,r8,LPCR_MER
+       mtspr   SPRN_LPCR,r8
+       isync
+END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
+       beq     5f
+       li      r0,BOOK3S_INTERRUPT_EXTERNAL
+12:    mr      r6,r10
+       mr      r10,r0
+       mr      r7,r11
+       li      r11,(MSR_ME << 1) | 1   /* synthesize MSR_SF | MSR_ME */
+       rotldi  r11,r11,63
+       b       5f
+11:    beq     5f
+       mfspr   r0,SPRN_DEC
+       cmpwi   r0,0
+       li      r0,BOOK3S_INTERRUPT_DECREMENTER
+       blt     12b
+
+       /* Move SRR0 and SRR1 into the respective regs */
+5:     mtspr   SPRN_SRR0, r6
+       mtspr   SPRN_SRR1, r7
+       li      r0,0
+       stb     r0,VCPU_CEDED(r4)       /* cancel cede */
+
 fast_guest_return:
        mtspr   SPRN_HSRR0,r10
        mtspr   SPRN_HSRR1,r11
@@ -574,21 +608,20 @@ kvmppc_interrupt:
        /* See if this is something we can handle in real mode */
        cmpwi   r12,BOOK3S_INTERRUPT_SYSCALL
        beq     hcall_try_real_mode
-hcall_real_cont:
 
        /* Check for mediated interrupts (could be done earlier really ...) */
 BEGIN_FTR_SECTION
        cmpwi   r12,BOOK3S_INTERRUPT_EXTERNAL
        bne+    1f
-       ld      r5,VCPU_KVM(r9)
-       ld      r5,KVM_LPCR(r5)
        andi.   r0,r11,MSR_EE
        beq     1f
+       mfspr   r5,SPRN_LPCR
        andi.   r0,r5,LPCR_MER
        bne     bounce_ext_interrupt
 1:
 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
 
+hcall_real_cont:               /* r9 = vcpu, r12 = trap, r13 = paca */
        /* Save DEC */
        mfspr   r5,SPRN_DEC
        mftb    r6
@@ -682,7 +715,7 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_201)
        slbia
        ptesync
 
-hdec_soon:
+hdec_soon:                     /* r9 = vcpu, r12 = trap, r13 = paca */
 BEGIN_FTR_SECTION
        b       32f
 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
@@ -700,6 +733,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
        addi    r0,r3,0x100
        stwcx.  r0,0,r6
        bne     41b
+       lwsync
 
        /*
         * At this point we have an interrupt that we have to pass
@@ -713,18 +747,39 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
         * interrupt, since the other threads will already be on their
         * way here in that case.
         */
+       cmpwi   r3,0x100        /* Are we the first here? */
+       bge     43f
+       cmpwi   r3,1            /* Are any other threads in the guest? */
+       ble     43f
        cmpwi   r12,BOOK3S_INTERRUPT_HV_DECREMENTER
        beq     40f
-       cmpwi   r3,0x100        /* Are we the first here? */
-       bge     40f
-       cmpwi   r3,1
-       ble     40f
        li      r0,0
        mtspr   SPRN_HDEC,r0
 40:
+       /*
+        * Send an IPI to any napping threads, since an HDEC interrupt
+        * doesn't wake CPUs up from nap.
+        */
+       lwz     r3,VCORE_NAPPING_THREADS(r5)
+       lwz     r4,VCPU_PTID(r9)
+       li      r0,1
+       sldi    r0,r0,r4
+       andc.   r3,r3,r0                /* no sense IPI'ing ourselves */
+       beq     43f
+       mulli   r4,r4,PACA_SIZE         /* get paca for thread 0 */
+       subf    r6,r4,r13
+42:    andi.   r0,r3,1
+       beq     44f
+       ld      r8,HSTATE_XICS_PHYS(r6) /* get thread's XICS reg addr */
+       li      r0,IPI_PRIORITY
+       li      r7,XICS_QIRR
+       stbcix  r0,r7,r8                /* trigger the IPI */
+44:    srdi.   r3,r3,1
+       addi    r6,r6,PACA_SIZE
+       bne     42b
 
        /* Secondary threads wait for primary to do partition switch */
-       ld      r4,VCPU_KVM(r9)         /* pointer to struct kvm */
+43:    ld      r4,VCPU_KVM(r9)         /* pointer to struct kvm */
        ld      r5,HSTATE_KVM_VCORE(r13)
        lwz     r3,VCPU_PTID(r9)
        cmpwi   r3,0
@@ -1077,7 +1132,6 @@ hcall_try_real_mode:
 hcall_real_fallback:
        li      r12,BOOK3S_INTERRUPT_SYSCALL
        ld      r9, HSTATE_KVM_VCPU(r13)
-       ld      r11, VCPU_MSR(r9)
 
        b       hcall_real_cont
 
@@ -1139,7 +1193,7 @@ hcall_real_table:
        .long   0               /* 0xd4 */
        .long   0               /* 0xd8 */
        .long   0               /* 0xdc */
-       .long   0               /* 0xe0 */
+       .long   .kvmppc_h_cede - hcall_real_table
        .long   0               /* 0xe4 */
        .long   0               /* 0xe8 */
        .long   0               /* 0xec */
@@ -1168,7 +1222,8 @@ bounce_ext_interrupt:
        mtspr   SPRN_SRR0,r10
        mtspr   SPRN_SRR1,r11
        li      r10,BOOK3S_INTERRUPT_EXTERNAL
-       LOAD_REG_IMMEDIATE(r11,MSR_SF | MSR_ME);
+       li      r11,(MSR_ME << 1) | 1   /* synthesize MSR_SF | MSR_ME */
+       rotldi  r11,r11,63
        b       fast_guest_return
 
 _GLOBAL(kvmppc_h_set_dabr)
@@ -1177,6 +1232,178 @@ _GLOBAL(kvmppc_h_set_dabr)
        li      r3,0
        blr
 
+_GLOBAL(kvmppc_h_cede)
+       ori     r11,r11,MSR_EE
+       std     r11,VCPU_MSR(r3)
+       li      r0,1
+       stb     r0,VCPU_CEDED(r3)
+       sync                    /* order setting ceded vs. testing prodded */
+       lbz     r5,VCPU_PRODDED(r3)
+       cmpwi   r5,0
+       bne     1f
+       li      r0,0            /* set trap to 0 to say hcall is handled */
+       stw     r0,VCPU_TRAP(r3)
+       li      r0,H_SUCCESS
+       std     r0,VCPU_GPR(r3)(r3)
+BEGIN_FTR_SECTION
+       b       2f              /* just send it up to host on 970 */
+END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_206)
+
+       /*
+        * Set our bit in the bitmask of napping threads unless all the
+        * other threads are already napping, in which case we send this
+        * up to the host.
+        */
+       ld      r5,HSTATE_KVM_VCORE(r13)
+       lwz     r6,VCPU_PTID(r3)
+       lwz     r8,VCORE_ENTRY_EXIT(r5)
+       clrldi  r8,r8,56
+       li      r0,1
+       sld     r0,r0,r6
+       addi    r6,r5,VCORE_NAPPING_THREADS
+31:    lwarx   r4,0,r6
+       or      r4,r4,r0
+       popcntw r7,r4
+       cmpw    r7,r8
+       bge     2f
+       stwcx.  r4,0,r6
+       bne     31b
+       li      r0,1
+       stb     r0,HSTATE_NAPPING(r13)
+       /* order napping_threads update vs testing entry_exit_count */
+       lwsync
+       mr      r4,r3
+       lwz     r7,VCORE_ENTRY_EXIT(r5)
+       cmpwi   r7,0x100
+       bge     33f             /* another thread already exiting */
+
+/*
+ * Although not specifically required by the architecture, POWER7
+ * preserves the following registers in nap mode, even if an SMT mode
+ * switch occurs: SLB entries, PURR, SPURR, AMOR, UAMOR, AMR, SPRG0-3,
+ * DAR, DSISR, DABR, DABRX, DSCR, PMCx, MMCRx, SIAR, SDAR.
+ */
+       /* Save non-volatile GPRs */
+       std     r14, VCPU_GPR(r14)(r3)
+       std     r15, VCPU_GPR(r15)(r3)
+       std     r16, VCPU_GPR(r16)(r3)
+       std     r17, VCPU_GPR(r17)(r3)
+       std     r18, VCPU_GPR(r18)(r3)
+       std     r19, VCPU_GPR(r19)(r3)
+       std     r20, VCPU_GPR(r20)(r3)
+       std     r21, VCPU_GPR(r21)(r3)
+       std     r22, VCPU_GPR(r22)(r3)
+       std     r23, VCPU_GPR(r23)(r3)
+       std     r24, VCPU_GPR(r24)(r3)
+       std     r25, VCPU_GPR(r25)(r3)
+       std     r26, VCPU_GPR(r26)(r3)
+       std     r27, VCPU_GPR(r27)(r3)
+       std     r28, VCPU_GPR(r28)(r3)
+       std     r29, VCPU_GPR(r29)(r3)
+       std     r30, VCPU_GPR(r30)(r3)
+       std     r31, VCPU_GPR(r31)(r3)
+
+       /* save FP state */
+       bl      .kvmppc_save_fp
+
+       /*
+        * Take a nap until a decrementer or external interrupt occurs,
+        * with PECE1 (wake on decr) and PECE0 (wake on external) set in LPCR
+        */
+       li      r0,0x80
+       stb     r0,PACAPROCSTART(r13)
+       mfspr   r5,SPRN_LPCR
+       ori     r5,r5,LPCR_PECE0 | LPCR_PECE1
+       mtspr   SPRN_LPCR,r5
+       isync
+       li      r0, 0
+       std     r0, HSTATE_SCRATCH0(r13)
+       ptesync
+       ld      r0, HSTATE_SCRATCH0(r13)
+1:     cmpd    r0, r0
+       bne     1b
+       nap
+       b       .
+
+kvm_end_cede:
+       /* Woken by external or decrementer interrupt */
+       ld      r1, HSTATE_HOST_R1(r13)
+       ld      r2, PACATOC(r13)
+
+       /* If we're a secondary thread and we got here by an IPI, ack it */
+       ld      r4,HSTATE_KVM_VCPU(r13)
+       lwz     r3,VCPU_PTID(r4)
+       cmpwi   r3,0
+       beq     27f
+       mfspr   r3,SPRN_SRR1
+       rlwinm  r3,r3,44-31,0x7         /* extract wake reason field */
+       cmpwi   r3,4                    /* was it an external interrupt? */
+       bne     27f
+       ld      r5, HSTATE_XICS_PHYS(r13)
+       li      r0,0xff
+       li      r6,XICS_QIRR
+       li      r7,XICS_XIRR
+       lwzcix  r8,r5,r7                /* ack the interrupt */
+       sync
+       stbcix  r0,r5,r6                /* clear it */
+       stwcix  r8,r5,r7                /* EOI it */
+27:
+       /* load up FP state */
+       bl      kvmppc_load_fp
+
+       /* Load NV GPRS */
+       ld      r14, VCPU_GPR(r14)(r4)
+       ld      r15, VCPU_GPR(r15)(r4)
+       ld      r16, VCPU_GPR(r16)(r4)
+       ld      r17, VCPU_GPR(r17)(r4)
+       ld      r18, VCPU_GPR(r18)(r4)
+       ld      r19, VCPU_GPR(r19)(r4)
+       ld      r20, VCPU_GPR(r20)(r4)
+       ld      r21, VCPU_GPR(r21)(r4)
+       ld      r22, VCPU_GPR(r22)(r4)
+       ld      r23, VCPU_GPR(r23)(r4)
+       ld      r24, VCPU_GPR(r24)(r4)
+       ld      r25, VCPU_GPR(r25)(r4)
+       ld      r26, VCPU_GPR(r26)(r4)
+       ld      r27, VCPU_GPR(r27)(r4)
+       ld      r28, VCPU_GPR(r28)(r4)
+       ld      r29, VCPU_GPR(r29)(r4)
+       ld      r30, VCPU_GPR(r30)(r4)
+       ld      r31, VCPU_GPR(r31)(r4)
+
+       /* clear our bit in vcore->napping_threads */
+33:    ld      r5,HSTATE_KVM_VCORE(r13)
+       lwz     r3,VCPU_PTID(r4)
+       li      r0,1
+       sld     r0,r0,r3
+       addi    r6,r5,VCORE_NAPPING_THREADS
+32:    lwarx   r7,0,r6
+       andc    r7,r7,r0
+       stwcx.  r7,0,r6
+       bne     32b
+       li      r0,0
+       stb     r0,HSTATE_NAPPING(r13)
+
+       /* see if any other thread is already exiting */
+       lwz     r0,VCORE_ENTRY_EXIT(r5)
+       cmpwi   r0,0x100
+       blt     kvmppc_cede_reentry     /* if not go back to guest */
+
+       /* some threads are exiting, so go to the guest exit path */
+       b       hcall_real_fallback
+
+       /* cede when already previously prodded case */
+1:     li      r0,0
+       stb     r0,VCPU_PRODDED(r3)
+       sync                    /* order testing prodded vs. clearing ceded */
+       stb     r0,VCPU_CEDED(r3)
+       li      r3,H_SUCCESS
+       blr
+
+       /* we've ceded but we want to give control to the host */
+2:     li      r3,H_TOO_HARD
+       blr
+
 secondary_too_late:
        ld      r5,HSTATE_KVM_VCORE(r13)
        HMT_LOW
@@ -1194,14 +1421,20 @@ secondary_too_late:
        slbmte  r6,r5
 1:     addi    r11,r11,16
        .endr
-       b       50f
 
 secondary_nap:
-       /* Clear any pending IPI */
-50:    ld      r5, HSTATE_XICS_PHYS(r13)
+       /* Clear any pending IPI - assume we're a secondary thread */
+       ld      r5, HSTATE_XICS_PHYS(r13)
+       li      r7, XICS_XIRR
+       lwzcix  r3, r5, r7              /* ack any pending interrupt */
+       rlwinm. r0, r3, 0, 0xffffff     /* any pending? */
+       beq     37f
+       sync
        li      r0, 0xff
        li      r6, XICS_QIRR
-       stbcix  r0, r5, r6
+       stbcix  r0, r5, r6              /* clear the IPI */
+       stwcix  r3, r5, r7              /* EOI it */
+37:    sync
 
        /* increment the nap count and then go to nap mode */
        ld      r4, HSTATE_KVM_VCORE(r13)
@@ -1211,13 +1444,12 @@ secondary_nap:
        addi    r3, r3, 1
        stwcx.  r3, 0, r4
        bne     51b
-       isync
 
+       li      r3, LPCR_PECE0
        mfspr   r4, SPRN_LPCR
-       li      r0, LPCR_PECE
-       andc    r4, r4, r0
-       ori     r4, r4, LPCR_PECE0      /* exit nap on interrupt */
+       rlwimi  r4, r3, 0, LPCR_PECE0 | LPCR_PECE1
        mtspr   SPRN_LPCR, r4
+       isync
        li      r0, 0
        std     r0, HSTATE_SCRATCH0(r13)
        ptesync
index c54b0e30cf3f1c7331f90e78e80e71a88ee6d20c..0a8515a5c0422db7dc27890d4651267a62a6531c 100644 (file)
 #define ULONG_SIZE             8
 #define FUNC(name)             GLUE(.,name)
 
-#define GET_SHADOW_VCPU_R13
-
-#define DISABLE_INTERRUPTS     \
-       mfmsr   r0;             \
-       rldicl  r0,r0,48,1;     \
-       rotldi  r0,r0,16;       \
-       mtmsrd  r0,1;           \
-
 #elif defined(CONFIG_PPC_BOOK3S_32)
 
 #define ULONG_SIZE              4
 #define FUNC(name)             name
 
-#define GET_SHADOW_VCPU_R13    \
-       lwz     r13, (THREAD + THREAD_KVM_SVCPU)(r2)
-
-#define DISABLE_INTERRUPTS     \
-       mfmsr   r0;             \
-       rlwinm  r0,r0,0,17,15;  \
-       mtmsr   r0;             \
-
 #endif /* CONFIG_PPC_BOOK3S_XX */
 
 
@@ -108,44 +92,17 @@ kvm_start_entry:
 
 kvm_start_lightweight:
 
-       GET_SHADOW_VCPU_R13
-       PPC_LL  r3, VCPU_HIGHMEM_HANDLER(r4)
-       PPC_STL r3, HSTATE_VMHANDLER(r13)
-
-       PPC_LL  r10, VCPU_SHADOW_MSR(r4)        /* r10 = vcpu->arch.shadow_msr */
-
-       DISABLE_INTERRUPTS
-
 #ifdef CONFIG_PPC_BOOK3S_64
-       /* Some guests may need to have dcbz set to 32 byte length.
-        *
-        * Usually we ensure that by patching the guest's instructions
-        * to trap on dcbz and emulate it in the hypervisor.
-        *
-        * If we can, we should tell the CPU to use 32 byte dcbz though,
-        * because that's a lot faster.
-        */
-
        PPC_LL  r3, VCPU_HFLAGS(r4)
-       rldicl. r3, r3, 0, 63           /* CR = ((r3 & 1) == 0) */
-       beq     no_dcbz32_on
-
-       mfspr   r3,SPRN_HID5
-       ori     r3, r3, 0x80            /* XXX HID5_dcbz32 = 0x80 */
-       mtspr   SPRN_HID5,r3
-
-no_dcbz32_on:
-
+       rldicl  r3, r3, 0, 63           /* r3 &= 1 */
+       stb     r3, HSTATE_RESTORE_HID5(r13)
 #endif /* CONFIG_PPC_BOOK3S_64 */
 
-       PPC_LL  r6, VCPU_RMCALL(r4)
-       mtctr   r6
-
-       PPC_LL  r3, VCPU_TRAMPOLINE_ENTER(r4)
-       LOAD_REG_IMMEDIATE(r4, MSR_KERNEL & ~(MSR_IR | MSR_DR))
+       PPC_LL  r4, VCPU_SHADOW_MSR(r4) /* get shadow_msr */
 
        /* Jump to segment patching handler and into our guest */
-       bctr
+       bl      FUNC(kvmppc_entry_trampoline)
+       nop
 
 /*
  * This is the handler in module memory. It gets jumped at from the
@@ -170,21 +127,6 @@ kvmppc_handler_highmem:
        /* R7 = vcpu */
        PPC_LL  r7, GPR4(r1)
 
-#ifdef CONFIG_PPC_BOOK3S_64
-
-       PPC_LL  r5, VCPU_HFLAGS(r7)
-       rldicl. r5, r5, 0, 63           /* CR = ((r5 & 1) == 0) */
-       beq     no_dcbz32_off
-
-       li      r4, 0
-       mfspr   r5,SPRN_HID5
-       rldimi  r5,r4,6,56
-       mtspr   SPRN_HID5,r5
-
-no_dcbz32_off:
-
-#endif /* CONFIG_PPC_BOOK3S_64 */
-
        PPC_STL r14, VCPU_GPR(r14)(r7)
        PPC_STL r15, VCPU_GPR(r15)(r7)
        PPC_STL r16, VCPU_GPR(r16)(r7)
@@ -204,67 +146,6 @@ no_dcbz32_off:
        PPC_STL r30, VCPU_GPR(r30)(r7)
        PPC_STL r31, VCPU_GPR(r31)(r7)
 
-       /* Restore host msr -> SRR1 */
-       PPC_LL  r6, VCPU_HOST_MSR(r7)
-
-       /*
-        * For some interrupts, we need to call the real Linux
-        * handler, so it can do work for us. This has to happen
-        * as if the interrupt arrived from the kernel though,
-        * so let's fake it here where most state is restored.
-        *
-        * Call Linux for hardware interrupts/decrementer
-        * r3 = address of interrupt handler (exit reason)
-        */
-
-       cmpwi   r12, BOOK3S_INTERRUPT_EXTERNAL
-       beq     call_linux_handler
-       cmpwi   r12, BOOK3S_INTERRUPT_DECREMENTER
-       beq     call_linux_handler
-       cmpwi   r12, BOOK3S_INTERRUPT_PERFMON
-       beq     call_linux_handler
-
-       /* Back to EE=1 */
-       mtmsr   r6
-       sync
-       b       kvm_return_point
-
-call_linux_handler:
-
-       /*
-        * If we land here we need to jump back to the handler we
-        * came from.
-        *
-        * We have a page that we can access from real mode, so let's
-        * jump back to that and use it as a trampoline to get back into the
-        * interrupt handler!
-        *
-        * R3 still contains the exit code,
-        * R5 VCPU_HOST_RETIP and
-        * R6 VCPU_HOST_MSR
-        */
-
-       /* Restore host IP -> SRR0 */
-       PPC_LL  r5, VCPU_HOST_RETIP(r7)
-
-       /* XXX Better move to a safe function?
-        *     What if we get an HTAB flush in between mtsrr0 and mtsrr1? */
-
-       mtlr    r12
-
-       PPC_LL  r4, VCPU_TRAMPOLINE_LOWMEM(r7)
-       mtsrr0  r4
-       LOAD_REG_IMMEDIATE(r3, MSR_KERNEL & ~(MSR_IR | MSR_DR))
-       mtsrr1  r3
-
-       RFI
-
-.global kvm_return_point
-kvm_return_point:
-
-       /* Jump back to lightweight entry if we're supposed to */
-       /* go back into the guest */
-
        /* Pass the exit number as 3rd argument to kvmppc_handle_exit */
        mr      r5, r12
 
index 0c0d3f274437bae8f3871b23dbae1ded443eb9b5..d417511abfb120f6992058e26547576d570bfcd9 100644 (file)
@@ -150,16 +150,22 @@ void kvmppc_set_pvr(struct kvm_vcpu *vcpu, u32 pvr)
 #ifdef CONFIG_PPC_BOOK3S_64
        if ((pvr >= 0x330000) && (pvr < 0x70330000)) {
                kvmppc_mmu_book3s_64_init(vcpu);
-               to_book3s(vcpu)->hior = 0xfff00000;
+               if (!to_book3s(vcpu)->hior_sregs)
+                       to_book3s(vcpu)->hior = 0xfff00000;
                to_book3s(vcpu)->msr_mask = 0xffffffffffffffffULL;
+               vcpu->arch.cpu_type = KVM_CPU_3S_64;
        } else
 #endif
        {
                kvmppc_mmu_book3s_32_init(vcpu);
-               to_book3s(vcpu)->hior = 0;
+               if (!to_book3s(vcpu)->hior_sregs)
+                       to_book3s(vcpu)->hior = 0;
                to_book3s(vcpu)->msr_mask = 0xffffffffULL;
+               vcpu->arch.cpu_type = KVM_CPU_3S_32;
        }
 
+       kvmppc_sanity_check(vcpu);
+
        /* If we are in hypervisor level on 970, we can tell the CPU to
         * treat DCBZ as 32 bytes store */
        vcpu->arch.hflags &= ~BOOK3S_HFLAG_DCBZ32;
@@ -646,7 +652,27 @@ program_interrupt:
                break;
        }
        case BOOK3S_INTERRUPT_SYSCALL:
-               if (vcpu->arch.osi_enabled &&
+               if (vcpu->arch.papr_enabled &&
+                   (kvmppc_get_last_inst(vcpu) == 0x44000022) &&
+                   !(vcpu->arch.shared->msr & MSR_PR)) {
+                       /* SC 1 papr hypercalls */
+                       ulong cmd = kvmppc_get_gpr(vcpu, 3);
+                       int i;
+
+                       if (kvmppc_h_pr(vcpu, cmd) == EMULATE_DONE) {
+                               r = RESUME_GUEST;
+                               break;
+                       }
+
+                       run->papr_hcall.nr = cmd;
+                       for (i = 0; i < 9; ++i) {
+                               ulong gpr = kvmppc_get_gpr(vcpu, 4 + i);
+                               run->papr_hcall.args[i] = gpr;
+                       }
+                       run->exit_reason = KVM_EXIT_PAPR_HCALL;
+                       vcpu->arch.hcall_needed = 1;
+                       r = RESUME_HOST;
+               } else if (vcpu->arch.osi_enabled &&
                    (((u32)kvmppc_get_gpr(vcpu, 3)) == OSI_SC_MAGIC_R3) &&
                    (((u32)kvmppc_get_gpr(vcpu, 4)) == OSI_SC_MAGIC_R4)) {
                        /* MOL hypercalls */
@@ -770,6 +796,9 @@ int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
                }
        }
 
+       if (sregs->u.s.flags & KVM_SREGS_S_HIOR)
+               sregs->u.s.hior = to_book3s(vcpu)->hior;
+
        return 0;
 }
 
@@ -806,6 +835,11 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
        /* Flush the MMU after messing with the segments */
        kvmppc_mmu_pte_flush(vcpu, 0, 0);
 
+       if (sregs->u.s.flags & KVM_SREGS_S_HIOR) {
+               to_book3s(vcpu)->hior_sregs = true;
+               to_book3s(vcpu)->hior = sregs->u.s.hior;
+       }
+
        return 0;
 }
 
@@ -841,8 +875,6 @@ struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id)
        if (!p)
                goto uninit_vcpu;
 
-       vcpu->arch.host_retip = kvm_return_point;
-       vcpu->arch.host_msr = mfmsr();
 #ifdef CONFIG_PPC_BOOK3S_64
        /* default to book3s_64 (970fx) */
        vcpu->arch.pvr = 0x3C0301;
@@ -853,16 +885,6 @@ struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id)
        kvmppc_set_pvr(vcpu, vcpu->arch.pvr);
        vcpu->arch.slb_nr = 64;
 
-       /* remember where some real-mode handlers are */
-       vcpu->arch.trampoline_lowmem = __pa(kvmppc_handler_lowmem_trampoline);
-       vcpu->arch.trampoline_enter = __pa(kvmppc_handler_trampoline_enter);
-       vcpu->arch.highmem_handler = (ulong)kvmppc_handler_highmem;
-#ifdef CONFIG_PPC_BOOK3S_64
-       vcpu->arch.rmcall = *(ulong*)kvmppc_rmcall;
-#else
-       vcpu->arch.rmcall = (ulong)kvmppc_rmcall;
-#endif
-
        vcpu->arch.shadow_msr = MSR_USER64;
 
        err = kvmppc_mmu_init(vcpu);
@@ -908,6 +930,12 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 #endif
        ulong ext_msr;
 
+       /* Check if we can run the vcpu at all */
+       if (!vcpu->arch.sane) {
+               kvm_run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
+               return -EINVAL;
+       }
+
        /* No need to go into the guest when all we do is going out */
        if (signal_pending(current)) {
                kvm_run->exit_reason = KVM_EXIT_INTR;
diff --git a/arch/powerpc/kvm/book3s_pr_papr.c b/arch/powerpc/kvm/book3s_pr_papr.c
new file mode 100644 (file)
index 0000000..b958932
--- /dev/null
@@ -0,0 +1,158 @@
+/*
+ * Copyright (C) 2011. Freescale Inc. All rights reserved.
+ *
+ * Authors:
+ *    Alexander Graf <agraf@suse.de>
+ *    Paul Mackerras <paulus@samba.org>
+ *
+ * Description:
+ *
+ * Hypercall handling for running PAPR guests in PR KVM on Book 3S
+ * processors.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ */
+
+#include <asm/uaccess.h>
+#include <asm/kvm_ppc.h>
+#include <asm/kvm_book3s.h>
+
+static unsigned long get_pteg_addr(struct kvm_vcpu *vcpu, long pte_index)
+{
+       struct kvmppc_vcpu_book3s *vcpu_book3s = to_book3s(vcpu);
+       unsigned long pteg_addr;
+
+       pte_index <<= 4;
+       pte_index &= ((1 << ((vcpu_book3s->sdr1 & 0x1f) + 11)) - 1) << 7 | 0x70;
+       pteg_addr = vcpu_book3s->sdr1 & 0xfffffffffffc0000ULL;
+       pteg_addr |= pte_index;
+
+       return pteg_addr;
+}
+
+static int kvmppc_h_pr_enter(struct kvm_vcpu *vcpu)
+{
+       long flags = kvmppc_get_gpr(vcpu, 4);
+       long pte_index = kvmppc_get_gpr(vcpu, 5);
+       unsigned long pteg[2 * 8];
+       unsigned long pteg_addr, i, *hpte;
+
+       pte_index &= ~7UL;
+       pteg_addr = get_pteg_addr(vcpu, pte_index);
+
+       copy_from_user(pteg, (void __user *)pteg_addr, sizeof(pteg));
+       hpte = pteg;
+
+       if (likely((flags & H_EXACT) == 0)) {
+               pte_index &= ~7UL;
+               for (i = 0; ; ++i) {
+                       if (i == 8)
+                               return H_PTEG_FULL;
+                       if ((*hpte & HPTE_V_VALID) == 0)
+                               break;
+                       hpte += 2;
+               }
+       } else {
+               i = kvmppc_get_gpr(vcpu, 5) & 7UL;
+               hpte += i * 2;
+       }
+
+       hpte[0] = kvmppc_get_gpr(vcpu, 6);
+       hpte[1] = kvmppc_get_gpr(vcpu, 7);
+       copy_to_user((void __user *)pteg_addr, pteg, sizeof(pteg));
+       kvmppc_set_gpr(vcpu, 3, H_SUCCESS);
+       kvmppc_set_gpr(vcpu, 4, pte_index | i);
+
+       return EMULATE_DONE;
+}
+
+static int kvmppc_h_pr_remove(struct kvm_vcpu *vcpu)
+{
+       unsigned long flags= kvmppc_get_gpr(vcpu, 4);
+       unsigned long pte_index = kvmppc_get_gpr(vcpu, 5);
+       unsigned long avpn = kvmppc_get_gpr(vcpu, 6);
+       unsigned long v = 0, pteg, rb;
+       unsigned long pte[2];
+
+       pteg = get_pteg_addr(vcpu, pte_index);
+       copy_from_user(pte, (void __user *)pteg, sizeof(pte));
+
+       if ((pte[0] & HPTE_V_VALID) == 0 ||
+           ((flags & H_AVPN) && (pte[0] & ~0x7fUL) != avpn) ||
+           ((flags & H_ANDCOND) && (pte[0] & avpn) != 0)) {
+               kvmppc_set_gpr(vcpu, 3, H_NOT_FOUND);
+               return EMULATE_DONE;
+       }
+
+       copy_to_user((void __user *)pteg, &v, sizeof(v));
+
+       rb = compute_tlbie_rb(pte[0], pte[1], pte_index);
+       vcpu->arch.mmu.tlbie(vcpu, rb, rb & 1 ? true : false);
+
+       kvmppc_set_gpr(vcpu, 3, H_SUCCESS);
+       kvmppc_set_gpr(vcpu, 4, pte[0]);
+       kvmppc_set_gpr(vcpu, 5, pte[1]);
+
+       return EMULATE_DONE;
+}
+
+static int kvmppc_h_pr_protect(struct kvm_vcpu *vcpu)
+{
+       unsigned long flags = kvmppc_get_gpr(vcpu, 4);
+       unsigned long pte_index = kvmppc_get_gpr(vcpu, 5);
+       unsigned long avpn = kvmppc_get_gpr(vcpu, 6);
+       unsigned long rb, pteg, r, v;
+       unsigned long pte[2];
+
+       pteg = get_pteg_addr(vcpu, pte_index);
+       copy_from_user(pte, (void __user *)pteg, sizeof(pte));
+
+       if ((pte[0] & HPTE_V_VALID) == 0 ||
+           ((flags & H_AVPN) && (pte[0] & ~0x7fUL) != avpn)) {
+               kvmppc_set_gpr(vcpu, 3, H_NOT_FOUND);
+               return EMULATE_DONE;
+       }
+
+       v = pte[0];
+       r = pte[1];
+       r &= ~(HPTE_R_PP0 | HPTE_R_PP | HPTE_R_N | HPTE_R_KEY_HI |
+              HPTE_R_KEY_LO);
+       r |= (flags << 55) & HPTE_R_PP0;
+       r |= (flags << 48) & HPTE_R_KEY_HI;
+       r |= flags & (HPTE_R_PP | HPTE_R_N | HPTE_R_KEY_LO);
+
+       pte[1] = r;
+
+       rb = compute_tlbie_rb(v, r, pte_index);
+       vcpu->arch.mmu.tlbie(vcpu, rb, rb & 1 ? true : false);
+       copy_to_user((void __user *)pteg, pte, sizeof(pte));
+
+       kvmppc_set_gpr(vcpu, 3, H_SUCCESS);
+
+       return EMULATE_DONE;
+}
+
+int kvmppc_h_pr(struct kvm_vcpu *vcpu, unsigned long cmd)
+{
+       switch (cmd) {
+       case H_ENTER:
+               return kvmppc_h_pr_enter(vcpu);
+       case H_REMOVE:
+               return kvmppc_h_pr_remove(vcpu);
+       case H_PROTECT:
+               return kvmppc_h_pr_protect(vcpu);
+       case H_BULK_REMOVE:
+               /* We just flush all PTEs, so user space can
+                  handle the HPT modifications */
+               kvmppc_mmu_pte_flush(vcpu, 0, 0);
+               break;
+       case H_CEDE:
+               kvm_vcpu_block(vcpu);
+               vcpu->stat.halt_wakeup++;
+               return EMULATE_DONE;
+       }
+
+       return EMULATE_FAIL;
+}
index c1f877c4a884655dfccb58d00c803c395a9695d7..34187585c50731717bb4ccec8660d0a4740ccf85 100644 (file)
@@ -20,6 +20,7 @@
 #include <asm/ppc_asm.h>
 #include <asm/kvm_asm.h>
 #include <asm/reg.h>
+#include <asm/mmu.h>
 #include <asm/page.h>
 #include <asm/asm-offsets.h>
 
 
 #if defined(CONFIG_PPC_BOOK3S_64)
 
-#define LOAD_SHADOW_VCPU(reg)  GET_PACA(reg)                                   
-#define MSR_NOIRQ              MSR_KERNEL & ~(MSR_IR | MSR_DR)
 #define FUNC(name)             GLUE(.,name)
+#define MTMSR_EERI(reg)                mtmsrd  (reg),1
 
+       .globl  kvmppc_skip_interrupt
 kvmppc_skip_interrupt:
        /*
         * Here all GPRs are unchanged from when the interrupt happened
@@ -51,6 +52,7 @@ kvmppc_skip_interrupt:
        rfid
        b       .
 
+       .globl  kvmppc_skip_Hinterrupt
 kvmppc_skip_Hinterrupt:
        /*
         * Here all GPRs are unchanged from when the interrupt happened
@@ -65,8 +67,8 @@ kvmppc_skip_Hinterrupt:
 
 #elif defined(CONFIG_PPC_BOOK3S_32)
 
-#define MSR_NOIRQ              MSR_KERNEL
 #define FUNC(name)             name
+#define MTMSR_EERI(reg)                mtmsr   (reg)
 
 .macro INTERRUPT_TRAMPOLINE intno
 
@@ -167,40 +169,24 @@ kvmppc_handler_skip_ins:
 #endif
 
 /*
- * This trampoline brings us back to a real mode handler
- *
- * Input Registers:
- *
- * R5 = SRR0
- * R6 = SRR1
- * LR = real-mode IP
+ * Call kvmppc_handler_trampoline_enter in real mode
  *
+ * On entry, r4 contains the guest shadow MSR
  */
-.global kvmppc_handler_lowmem_trampoline
-kvmppc_handler_lowmem_trampoline:
-
-       mtsrr0  r5
+_GLOBAL(kvmppc_entry_trampoline)
+       mfmsr   r5
+       LOAD_REG_ADDR(r7, kvmppc_handler_trampoline_enter)
+       toreal(r7)
+
+       li      r9, MSR_RI
+       ori     r9, r9, MSR_EE
+       andc    r9, r5, r9      /* Clear EE and RI in MSR value */
+       li      r6, MSR_IR | MSR_DR
+       ori     r6, r6, MSR_EE
+       andc    r6, r5, r6      /* Clear EE, DR and IR in MSR value */
+       MTMSR_EERI(r9)          /* Clear EE and RI in MSR */
+       mtsrr0  r7              /* before we set srr0/1 */
        mtsrr1  r6
-       blr
-kvmppc_handler_lowmem_trampoline_end:
-
-/*
- * Call a function in real mode
- *
- * Input Registers:
- *
- * R3 = function
- * R4 = MSR
- * R5 = scratch register
- *
- */
-_GLOBAL(kvmppc_rmcall)
-       LOAD_REG_IMMEDIATE(r5, MSR_NOIRQ)
-       mtmsr   r5              /* Disable relocation and interrupts, so mtsrr
-                                  doesn't get interrupted */
-       sync
-       mtsrr0  r3
-       mtsrr1  r4
        RFI
 
 #if defined(CONFIG_PPC_BOOK3S_32)
index aed32e51721254823b8a9e38170774f1b9e8a202..0676ae249b9fd033c87a2c361ea6a9c78ce81952 100644 (file)
@@ -23,6 +23,7 @@
 
 #define GET_SHADOW_VCPU(reg)    \
        mr      reg, r13
+#define MTMSR_EERI(reg)                mtmsrd  (reg),1
 
 #elif defined(CONFIG_PPC_BOOK3S_32)
 
@@ -30,6 +31,7 @@
        tophys(reg, r2);                        \
        lwz     reg, (THREAD + THREAD_KVM_SVCPU)(reg);  \
        tophys(reg, reg)
+#define MTMSR_EERI(reg)                mtmsr   (reg)
 
 #endif
 
@@ -57,10 +59,12 @@ kvmppc_handler_trampoline_enter:
        /* Required state:
         *
         * MSR = ~IR|DR
-        * R13 = PACA
         * R1 = host R1
         * R2 = host R2
-        * R10 = guest MSR
+        * R4 = guest shadow MSR
+        * R5 = normal host MSR
+        * R6 = current host MSR (EE, IR, DR off)
+        * LR = highmem guest exit code
         * all other volatile GPRS = free
         * SVCPU[CR] = guest CR
         * SVCPU[XER] = guest XER
@@ -71,15 +75,15 @@ kvmppc_handler_trampoline_enter:
        /* r3 = shadow vcpu */
        GET_SHADOW_VCPU(r3)
 
+       /* Save guest exit handler address and MSR */
+       mflr    r0
+       PPC_STL r0, HSTATE_VMHANDLER(r3)
+       PPC_STL r5, HSTATE_HOST_MSR(r3)
+
        /* Save R1/R2 in the PACA (64-bit) or shadow_vcpu (32-bit) */
        PPC_STL r1, HSTATE_HOST_R1(r3)
        PPC_STL r2, HSTATE_HOST_R2(r3)
 
-       /* Move SRR0 and SRR1 into the respective regs */
-       PPC_LL  r9, SVCPU_PC(r3)
-       mtsrr0  r9
-       mtsrr1  r10
-
        /* Activate guest mode, so faults get handled by KVM */
        li      r11, KVM_GUEST_MODE_GUEST
        stb     r11, HSTATE_IN_GUEST(r3)
@@ -87,17 +91,46 @@ kvmppc_handler_trampoline_enter:
        /* Switch to guest segment. This is subarch specific. */
        LOAD_GUEST_SEGMENTS
 
+#ifdef CONFIG_PPC_BOOK3S_64
+       /* Some guests may need to have dcbz set to 32 byte length.
+        *
+        * Usually we ensure that by patching the guest's instructions
+        * to trap on dcbz and emulate it in the hypervisor.
+        *
+        * If we can, we should tell the CPU to use 32 byte dcbz though,
+        * because that's a lot faster.
+        */
+       lbz     r0, HSTATE_RESTORE_HID5(r3)
+       cmpwi   r0, 0
+       beq     no_dcbz32_on
+
+       mfspr   r0,SPRN_HID5
+       ori     r0, r0, 0x80            /* XXX HID5_dcbz32 = 0x80 */
+       mtspr   SPRN_HID5,r0
+no_dcbz32_on:
+
+#endif /* CONFIG_PPC_BOOK3S_64 */
+
        /* Enter guest */
 
-       PPC_LL  r4, SVCPU_CTR(r3)
-       PPC_LL  r5, SVCPU_LR(r3)
-       lwz     r6, SVCPU_CR(r3)
-       lwz     r7, SVCPU_XER(r3)
+       PPC_LL  r8, SVCPU_CTR(r3)
+       PPC_LL  r9, SVCPU_LR(r3)
+       lwz     r10, SVCPU_CR(r3)
+       lwz     r11, SVCPU_XER(r3)
+
+       mtctr   r8
+       mtlr    r9
+       mtcr    r10
+       mtxer   r11
 
-       mtctr   r4
-       mtlr    r5
-       mtcr    r6
-       mtxer   r7
+       /* Move SRR0 and SRR1 into the respective regs */
+       PPC_LL  r9, SVCPU_PC(r3)
+       /* First clear RI in our current MSR value */
+       li      r0, MSR_RI
+       andc    r6, r6, r0
+       MTMSR_EERI(r6)
+       mtsrr0  r9
+       mtsrr1  r4
 
        PPC_LL  r0, SVCPU_R0(r3)
        PPC_LL  r1, SVCPU_R1(r3)
@@ -213,11 +246,16 @@ END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
        beq     ld_last_inst
        cmpwi   r12, BOOK3S_INTERRUPT_PROGRAM
        beq     ld_last_inst
+       cmpwi   r12, BOOK3S_INTERRUPT_SYSCALL
+       beq     ld_last_prev_inst
        cmpwi   r12, BOOK3S_INTERRUPT_ALIGNMENT
        beq-    ld_last_inst
 
        b       no_ld_last_inst
 
+ld_last_prev_inst:
+       addi    r3, r3, -4
+
 ld_last_inst:
        /* Save off the guest instruction we're at */
 
@@ -254,6 +292,43 @@ no_ld_last_inst:
        /* Switch back to host MMU */
        LOAD_HOST_SEGMENTS
 
+#ifdef CONFIG_PPC_BOOK3S_64
+
+       lbz     r5, HSTATE_RESTORE_HID5(r13)
+       cmpwi   r5, 0
+       beq     no_dcbz32_off
+
+       li      r4, 0
+       mfspr   r5,SPRN_HID5
+       rldimi  r5,r4,6,56
+       mtspr   SPRN_HID5,r5
+
+no_dcbz32_off:
+
+#endif /* CONFIG_PPC_BOOK3S_64 */
+
+       /*
+        * For some interrupts, we need to call the real Linux
+        * handler, so it can do work for us. This has to happen
+        * as if the interrupt arrived from the kernel though,
+        * so let's fake it here where most state is restored.
+        *
+        * Having set up SRR0/1 with the address where we want
+        * to continue with relocation on (potentially in module
+        * space), we either just go straight there with rfi[d],
+        * or we jump to an interrupt handler with bctr if there
+        * is an interrupt to be handled first.  In the latter
+        * case, the rfi[d] at the end of the interrupt handler
+        * will get us back to where we want to continue.
+        */
+
+       cmpwi   r12, BOOK3S_INTERRUPT_EXTERNAL
+       beq     1f
+       cmpwi   r12, BOOK3S_INTERRUPT_DECREMENTER
+       beq     1f
+       cmpwi   r12, BOOK3S_INTERRUPT_PERFMON
+1:     mtctr   r12
+
        /* Register usage at this point:
         *
         * R1       = host R1
@@ -264,13 +339,15 @@ no_ld_last_inst:
         *
         */
 
-       /* RFI into the highmem handler */
-       mfmsr   r7
-       ori     r7, r7, MSR_IR|MSR_DR|MSR_RI|MSR_ME     /* Enable paging */
-       mtsrr1  r7
-       /* Load highmem handler address */
+       PPC_LL  r6, HSTATE_HOST_MSR(r13)
        PPC_LL  r8, HSTATE_VMHANDLER(r13)
+
+       /* Restore host msr -> SRR1 */
+       mtsrr1  r6
+       /* Load highmem handler address */
        mtsrr0  r8
 
+       /* RFI into the highmem handler, or jump to interrupt handler */
+       beqctr
        RFI
 kvmppc_handler_trampoline_exit_end:
index ee45fa01220ef11679ea081cdb5c9ccf4e1ab4d0..bb6c988f010aa29b0732d628788547456e6b577c 100644 (file)
@@ -316,6 +316,11 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 {
        int ret;
 
+       if (!vcpu->arch.sane) {
+               kvm_run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
+               return -EINVAL;
+       }
+
        local_irq_disable();
        kvm_guest_enter();
        ret = __kvmppc_vcpu_run(kvm_run, vcpu);
@@ -618,6 +623,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
 int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
 {
        int i;
+       int r;
 
        vcpu->arch.pc = 0;
        vcpu->arch.shared->msr = 0;
@@ -634,7 +640,9 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
 
        kvmppc_init_timing_stats(vcpu);
 
-       return kvmppc_core_vcpu_setup(vcpu);
+       r = kvmppc_core_vcpu_setup(vcpu);
+       kvmppc_sanity_check(vcpu);
+       return r;
 }
 
 int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
index 797a7447c268aff9f0ee603ab8c22c0546ba4d4c..26d20903f2bc5c8cce1a94637f58ea9dea73a696 100644 (file)
@@ -73,6 +73,8 @@ int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu)
        /* Since booke kvm only support one core, update all vcpus' PIR to 0 */
        vcpu->vcpu_id = 0;
 
+       vcpu->arch.cpu_type = KVM_CPU_E500V2;
+
        return 0;
 }
 
index a107c9be0fb1c01a9cdbe5488706f91ef35732c9..0d843c6ba3154fe21a0abd4f857d32ee0250e2b4 100644 (file)
 
 int kvm_arch_vcpu_runnable(struct kvm_vcpu *v)
 {
-#ifndef CONFIG_KVM_BOOK3S_64_HV
        return !(v->arch.shared->msr & MSR_WE) ||
               !!(v->arch.pending_exceptions);
-#else
-       return !(v->arch.ceded) || !!(v->arch.pending_exceptions);
-#endif
 }
 
 int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
@@ -95,6 +91,31 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
        return r;
 }
 
+int kvmppc_sanity_check(struct kvm_vcpu *vcpu)
+{
+       int r = false;
+
+       /* We have to know what CPU to virtualize */
+       if (!vcpu->arch.pvr)
+               goto out;
+
+       /* PAPR only works with book3s_64 */
+       if ((vcpu->arch.cpu_type != KVM_CPU_3S_64) && vcpu->arch.papr_enabled)
+               goto out;
+
+#ifdef CONFIG_KVM_BOOK3S_64_HV
+       /* HV KVM can only do PAPR mode for now */
+       if (!vcpu->arch.papr_enabled)
+               goto out;
+#endif
+
+       r = true;
+
+out:
+       vcpu->arch.sane = r;
+       return r ? 0 : -EINVAL;
+}
+
 int kvmppc_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu)
 {
        enum emulation_result er;
@@ -188,6 +209,8 @@ int kvm_dev_ioctl_check_extension(long ext)
        case KVM_CAP_PPC_BOOKE_SREGS:
 #else
        case KVM_CAP_PPC_SEGSTATE:
+       case KVM_CAP_PPC_HIOR:
+       case KVM_CAP_PPC_PAPR:
 #endif
        case KVM_CAP_PPC_UNSET_IRQ:
        case KVM_CAP_PPC_IRQ_LEVEL:
@@ -258,6 +281,7 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id)
 {
        struct kvm_vcpu *vcpu;
        vcpu = kvmppc_core_vcpu_create(kvm, id);
+       vcpu->arch.wqp = &vcpu->wq;
        if (!IS_ERR(vcpu))
                kvmppc_create_vcpu_debugfs(vcpu, id);
        return vcpu;
@@ -289,8 +313,8 @@ static void kvmppc_decrementer_func(unsigned long data)
 
        kvmppc_core_queue_dec(vcpu);
 
-       if (waitqueue_active(&vcpu->wq)) {
-               wake_up_interruptible(&vcpu->wq);
+       if (waitqueue_active(vcpu->arch.wqp)) {
+               wake_up_interruptible(vcpu->arch.wqp);
                vcpu->stat.halt_wakeup++;
        }
 }
@@ -543,13 +567,15 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
 
 int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu, struct kvm_interrupt *irq)
 {
-       if (irq->irq == KVM_INTERRUPT_UNSET)
+       if (irq->irq == KVM_INTERRUPT_UNSET) {
                kvmppc_core_dequeue_external(vcpu, irq);
-       else
-               kvmppc_core_queue_external(vcpu, irq);
+               return 0;
+       }
+
+       kvmppc_core_queue_external(vcpu, irq);
 
-       if (waitqueue_active(&vcpu->wq)) {
-               wake_up_interruptible(&vcpu->wq);
+       if (waitqueue_active(vcpu->arch.wqp)) {
+               wake_up_interruptible(vcpu->arch.wqp);
                vcpu->stat.halt_wakeup++;
        } else if (vcpu->cpu != -1) {
                smp_send_reschedule(vcpu->cpu);
@@ -571,11 +597,18 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
                r = 0;
                vcpu->arch.osi_enabled = true;
                break;
+       case KVM_CAP_PPC_PAPR:
+               r = 0;
+               vcpu->arch.papr_enabled = true;
+               break;
        default:
                r = -EINVAL;
                break;
        }
 
+       if (!r)
+               r = kvmppc_sanity_check(vcpu);
+
        return r;
 }
 
index e41ebbdb3e123fb8413c89559ff156ac7f89f245..cfe958e94e1ef6b741ef4783a0790f20adbb67fa 100644 (file)
@@ -66,8 +66,8 @@ struct fsl_diu_shared_fb {
        bool            in_use;
 };
 
-unsigned int mpc512x_get_pixel_format(unsigned int bits_per_pixel,
-                                     int monitor_port)
+u32 mpc512x_get_pixel_format(enum fsl_diu_monitor_port port,
+                            unsigned int bits_per_pixel)
 {
        switch (bits_per_pixel) {
        case 32:
@@ -80,11 +80,12 @@ unsigned int mpc512x_get_pixel_format(unsigned int bits_per_pixel,
        return 0x00000400;
 }
 
-void mpc512x_set_gamma_table(int monitor_port, char *gamma_table_base)
+void mpc512x_set_gamma_table(enum fsl_diu_monitor_port port,
+                            char *gamma_table_base)
 {
 }
 
-void mpc512x_set_monitor_port(int monitor_port)
+void mpc512x_set_monitor_port(enum fsl_diu_monitor_port port)
 {
 }
 
@@ -182,14 +183,10 @@ void mpc512x_set_pixel_clock(unsigned int pixclock)
        iounmap(ccm);
 }
 
-ssize_t mpc512x_show_monitor_port(int monitor_port, char *buf)
+enum fsl_diu_monitor_port
+mpc512x_valid_monitor_port(enum fsl_diu_monitor_port port)
 {
-       return sprintf(buf, "0 - 5121 LCD\n");
-}
-
-int mpc512x_set_sysfs_monitor_port(int val)
-{
-       return 0;
+       return FSL_DIU_PORT_DVI;
 }
 
 static struct fsl_diu_shared_fb __attribute__ ((__aligned__(8))) diu_shared_fb;
@@ -256,7 +253,7 @@ void __init mpc512x_init_diu(void)
        }
 
        mode = in_be32(&diu_reg->diu_mode);
-       if (mode != MFB_MODE1) {
+       if (mode == MFB_MODE0) {
                pr_info("%s: DIU OFF\n", __func__);
                goto out;
        }
@@ -332,8 +329,7 @@ void __init mpc512x_setup_diu(void)
        diu_ops.set_gamma_table         = mpc512x_set_gamma_table;
        diu_ops.set_monitor_port        = mpc512x_set_monitor_port;
        diu_ops.set_pixel_clock         = mpc512x_set_pixel_clock;
-       diu_ops.show_monitor_port       = mpc512x_show_monitor_port;
-       diu_ops.set_sysfs_monitor_port  = mpc512x_set_sysfs_monitor_port;
+       diu_ops.valid_monitor_port      = mpc512x_valid_monitor_port;
        diu_ops.release_bootmem         = mpc512x_release_bootmem;
 #endif
 }
index 266b3aadfe5e2671d9ab11d1100dfcfcef52829b..c01c7277888c1e3655fddd6be2dfe2da21705182 100644 (file)
@@ -93,8 +93,8 @@
  * The Area Descriptor is a 32-bit value that determine which bits in each
  * pixel are to be used for each color.
  */
-static unsigned int p1022ds_get_pixel_format(unsigned int bits_per_pixel,
-       int monitor_port)
+static u32 p1022ds_get_pixel_format(enum fsl_diu_monitor_port port,
+                                   unsigned int bits_per_pixel)
 {
        switch (bits_per_pixel) {
        case 32:
@@ -118,7 +118,8 @@ static unsigned int p1022ds_get_pixel_format(unsigned int bits_per_pixel,
  * On some boards, the gamma table for some ports may need to be modified.
  * This is not the case on the P1022DS, so we do nothing.
 */
-static void p1022ds_set_gamma_table(int monitor_port, char *gamma_table_base)
+static void p1022ds_set_gamma_table(enum fsl_diu_monitor_port port,
+                                   char *gamma_table_base)
 {
 }
 
@@ -126,7 +127,7 @@ static void p1022ds_set_gamma_table(int monitor_port, char *gamma_table_base)
  * p1022ds_set_monitor_port: switch the output to a different monitor port
  *
  */
-static void p1022ds_set_monitor_port(int monitor_port)
+static void p1022ds_set_monitor_port(enum fsl_diu_monitor_port port)
 {
        struct device_node *pixis_node;
        void __iomem *pixis;
@@ -145,19 +146,21 @@ static void p1022ds_set_monitor_port(int monitor_port)
        }
        brdcfg1 = pixis + 9;    /* BRDCFG1 is at offset 9 in the ngPIXIS */
 
-       switch (monitor_port) {
-       case 0: /* DVI */
+       switch (port) {
+       case FSL_DIU_PORT_DVI:
+               printk(KERN_INFO "%s:%u\n", __func__, __LINE__);
                /* Enable the DVI port, disable the DFP and the backlight */
                clrsetbits_8(brdcfg1, PX_BRDCFG1_DFPEN | PX_BRDCFG1_BACKLIGHT,
                             PX_BRDCFG1_DVIEN);
                break;
-       case 1: /* Single link LVDS */
+       case FSL_DIU_PORT_LVDS:
+               printk(KERN_INFO "%s:%u\n", __func__, __LINE__);
                /* Enable the DFP port, disable the DVI and the backlight */
                clrsetbits_8(brdcfg1, PX_BRDCFG1_DVIEN | PX_BRDCFG1_BACKLIGHT,
                             PX_BRDCFG1_DFPEN);
                break;
        default:
-               pr_err("p1022ds: unsupported monitor port %i\n", monitor_port);
+               pr_err("p1022ds: unsupported monitor port %i\n", port);
        }
 
        iounmap(pixis);
@@ -214,23 +217,18 @@ void p1022ds_set_pixel_clock(unsigned int pixclock)
 }
 
 /**
- * p1022ds_show_monitor_port: show the current monitor
- *
- * This function returns a string indicating whether the current monitor is
- * set to DVI or LVDS.
- */
-ssize_t p1022ds_show_monitor_port(int monitor_port, char *buf)
-{
-       return sprintf(buf, "%c0 - DVI\n%c1 - Single link LVDS\n",
-               monitor_port == 0 ? '*' : ' ', monitor_port == 1 ? '*' : ' ');
-}
-
-/**
- * p1022ds_set_sysfs_monitor_port: set the monitor port for sysfs
+ * p1022ds_valid_monitor_port: set the monitor port for sysfs
  */
-int p1022ds_set_sysfs_monitor_port(int val)
+enum fsl_diu_monitor_port
+p1022ds_valid_monitor_port(enum fsl_diu_monitor_port port)
 {
-       return val < 2 ? val : 0;
+       switch (port) {
+       case FSL_DIU_PORT_DVI:
+       case FSL_DIU_PORT_LVDS:
+               return port;
+       default:
+               return FSL_DIU_PORT_DVI; /* Dual-link LVDS is not supported */
+       }
 }
 
 #endif
@@ -305,8 +303,7 @@ static void __init p1022_ds_setup_arch(void)
        diu_ops.set_gamma_table         = p1022ds_set_gamma_table;
        diu_ops.set_monitor_port        = p1022ds_set_monitor_port;
        diu_ops.set_pixel_clock         = p1022ds_set_pixel_clock;
-       diu_ops.show_monitor_port       = p1022ds_show_monitor_port;
-       diu_ops.set_sysfs_monitor_port  = p1022ds_set_sysfs_monitor_port;
+       diu_ops.valid_monitor_port      = p1022ds_valid_monitor_port;
 #endif
 
 #ifdef CONFIG_SMP
index 74e018ef724b0acc0aed5574e0bc483f2be37b83..13fa9a6403e6fc8820554126b113038209e7fb91 100644 (file)
@@ -152,10 +152,10 @@ machine_device_initcall(mpc86xx_hpcd, mpc8610_declare_of_platform_devices);
        (c2 << AD_COMP_2_SHIFT) | (c1 << AD_COMP_1_SHIFT) | \
        (c0 << AD_COMP_0_SHIFT) | (size << AD_PIXEL_S_SHIFT))
 
-unsigned int mpc8610hpcd_get_pixel_format(unsigned int bits_per_pixel,
-                                               int monitor_port)
+u32 mpc8610hpcd_get_pixel_format(enum fsl_diu_monitor_port port,
+                                unsigned int bits_per_pixel)
 {
-       static const unsigned long pixelformat[][3] = {
+       static const u32 pixelformat[][3] = {
                {
                        MAKE_AD(3, 0, 2, 1, 3, 8, 8, 8, 8),
                        MAKE_AD(4, 2, 0, 1, 2, 8, 8, 8, 0),
@@ -170,7 +170,8 @@ unsigned int mpc8610hpcd_get_pixel_format(unsigned int bits_per_pixel,
        unsigned int arch_monitor;
 
        /* The DVI port is mis-wired on revision 1 of this board. */
-       arch_monitor = ((*pixis_arch == 0x01) && (monitor_port == 0))? 0 : 1;
+       arch_monitor =
+               ((*pixis_arch == 0x01) && (port == FSL_DIU_PORT_DVI)) ? 0 : 1;
 
        switch (bits_per_pixel) {
        case 32:
@@ -185,10 +186,11 @@ unsigned int mpc8610hpcd_get_pixel_format(unsigned int bits_per_pixel,
        }
 }
 
-void mpc8610hpcd_set_gamma_table(int monitor_port, char *gamma_table_base)
+void mpc8610hpcd_set_gamma_table(enum fsl_diu_monitor_port port,
+                                char *gamma_table_base)
 {
        int i;
-       if (monitor_port == 2) {                /* dual link LVDS */
+       if (port == FSL_DIU_PORT_DLVDS) {
                for (i = 0; i < 256*3; i++)
                        gamma_table_base[i] = (gamma_table_base[i] << 2) |
                                         ((gamma_table_base[i] >> 6) & 0x03);
@@ -199,17 +201,21 @@ void mpc8610hpcd_set_gamma_table(int monitor_port, char *gamma_table_base)
 #define PX_BRDCFG0_DLINK       (1 << 4)
 #define PX_BRDCFG0_DIU_MASK    (PX_BRDCFG0_DVISEL | PX_BRDCFG0_DLINK)
 
-void mpc8610hpcd_set_monitor_port(int monitor_port)
+void mpc8610hpcd_set_monitor_port(enum fsl_diu_monitor_port port)
 {
-       static const u8 bdcfg[] = {
-               PX_BRDCFG0_DVISEL | PX_BRDCFG0_DLINK,
-               PX_BRDCFG0_DLINK,
-               0,
-       };
-
-       if (monitor_port < 3)
+       switch (port) {
+       case FSL_DIU_PORT_DVI:
                clrsetbits_8(pixis_bdcfg0, PX_BRDCFG0_DIU_MASK,
-                            bdcfg[monitor_port]);
+                            PX_BRDCFG0_DVISEL | PX_BRDCFG0_DLINK);
+               break;
+       case FSL_DIU_PORT_LVDS:
+               clrsetbits_8(pixis_bdcfg0, PX_BRDCFG0_DIU_MASK,
+                            PX_BRDCFG0_DLINK);
+               break;
+       case FSL_DIU_PORT_DLVDS:
+               clrbits8(pixis_bdcfg0, PX_BRDCFG0_DIU_MASK);
+               break;
+       }
 }
 
 /**
@@ -262,20 +268,10 @@ void mpc8610hpcd_set_pixel_clock(unsigned int pixclock)
        iounmap(guts);
 }
 
-ssize_t mpc8610hpcd_show_monitor_port(int monitor_port, char *buf)
-{
-       return snprintf(buf, PAGE_SIZE,
-                       "%c0 - DVI\n"
-                       "%c1 - Single link LVDS\n"
-                       "%c2 - Dual link LVDS\n",
-                       monitor_port == 0 ? '*' : ' ',
-                       monitor_port == 1 ? '*' : ' ',
-                       monitor_port == 2 ? '*' : ' ');
-}
-
-int mpc8610hpcd_set_sysfs_monitor_port(int val)
+enum fsl_diu_monitor_port
+mpc8610hpcd_valid_monitor_port(enum fsl_diu_monitor_port port)
 {
-       return val < 3 ? val : 0;
+       return port;
 }
 
 #endif
@@ -307,8 +303,7 @@ static void __init mpc86xx_hpcd_setup_arch(void)
        diu_ops.set_gamma_table         = mpc8610hpcd_set_gamma_table;
        diu_ops.set_monitor_port        = mpc8610hpcd_set_monitor_port;
        diu_ops.set_pixel_clock         = mpc8610hpcd_set_pixel_clock;
-       diu_ops.show_monitor_port       = mpc8610hpcd_show_monitor_port;
-       diu_ops.set_sysfs_monitor_port  = mpc8610hpcd_set_sysfs_monitor_port;
+       diu_ops.valid_monitor_port      = mpc8610hpcd_valid_monitor_port;
 #endif
 
        pixis_node = of_find_compatible_node(NULL, NULL, "fsl,fpga-pixis");
index 2ece02beb8ffed1a0828877d02adf251d779ed96..c6d00736f07f559f677e25344c15c09943a3b25e 100644 (file)
@@ -22,15 +22,24 @@ struct device_node;
 extern void fsl_rstcr_restart(char *cmd);
 
 #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
+
+/* The different ports that the DIU can be connected to */
+enum fsl_diu_monitor_port {
+       FSL_DIU_PORT_DVI,       /* DVI */
+       FSL_DIU_PORT_LVDS,      /* Single-link LVDS */
+       FSL_DIU_PORT_DLVDS      /* Dual-link LVDS */
+};
+
 struct platform_diu_data_ops {
-       unsigned int (*get_pixel_format) (unsigned int bits_per_pixel,
-               int monitor_port);
-       void (*set_gamma_table) (int monitor_port, char *gamma_table_base);
-       void (*set_monitor_port) (int monitor_port);
-       void (*set_pixel_clock) (unsigned int pixclock);
-       ssize_t (*show_monitor_port) (int monitor_port, char *buf);
-       int (*set_sysfs_monitor_port) (int val);
-       void (*release_bootmem) (void);
+       u32 (*get_pixel_format)(enum fsl_diu_monitor_port port,
+               unsigned int bpp);
+       void (*set_gamma_table)(enum fsl_diu_monitor_port port,
+               char *gamma_table_base);
+       void (*set_monitor_port)(enum fsl_diu_monitor_port port);
+       void (*set_pixel_clock)(unsigned int pixclock);
+       enum fsl_diu_monitor_port (*valid_monitor_port)
+               (enum fsl_diu_monitor_port port);
+       void (*release_bootmem)(void);
 };
 
 extern struct platform_diu_data_ops diu_ops;
index 6b99fc3f9b6380f529ea5e65737194b079d47044..a9fbd43395f71814d85a284a63900dc5a7dcc018 100644 (file)
@@ -569,6 +569,16 @@ config KEXEC
          current kernel, and to start another kernel.  It is like a reboot
          but is independent of hardware/microcode support.
 
+config CRASH_DUMP
+       bool "kernel crash dumps"
+       depends on 64BIT
+       help
+         Generate crash dump after being started by kexec.
+         Crash dump kernels are loaded in the main kernel with kexec-tools
+         into a specially reserved region and then later executed after
+         a crash by kdump/kexec.
+         For more details see Documentation/kdump/kdump.txt
+
 config ZFCPDUMP
        def_bool n
        prompt "zfcpdump support"
index 028f23ea81d1c26fbe51df7494bc0689ddc3860e..465eca756feb8d9ce36d70b10d6abd6cd850ad4e 100644 (file)
@@ -61,7 +61,7 @@ static unsigned long free_mem_end_ptr;
 
 extern _sclp_print_early(const char *);
 
-int puts(const char *s)
+static int puts(const char *s)
 {
        _sclp_print_early(s);
        return 0;
index 29c82c640a8829a49ce82f3a61a2cfddfd4ae91d..6cf8e26b313780a4addc668018f3a658880be257 100644 (file)
@@ -68,7 +68,7 @@ CONFIG_NET_CLS_RSVP6=m
 CONFIG_NET_CLS_ACT=y
 CONFIG_NET_ACT_POLICE=y
 CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
-# CONFIG_FIRMWARE_IN_KERNEL is not set
+CONFIG_DEVTMPFS=y
 CONFIG_BLK_DEV_LOOP=m
 CONFIG_BLK_DEV_NBD=m
 CONFIG_BLK_DEV_RAM=y
index 623f2fb71774af7a352df0075f8253e776c15839..9381c92cc779b14afbf940fe5b4f56f54ad7d125 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/device.h>
 #include <linux/mod_devicetable.h>
 #include <asm/fcx.h>
+#include <asm/irq.h>
 
 /* structs from asm/cio.h */
 struct irb;
@@ -127,6 +128,7 @@ enum uc_todo {
  * @restore: callback for restoring after hibernation
  * @uc_handler: callback for unit check handler
  * @driver: embedded device driver structure
+ * @int_class: interruption class to use for accounting interrupts
  */
 struct ccw_driver {
        struct ccw_device_id *ids;
@@ -144,6 +146,7 @@ struct ccw_driver {
        int (*restore)(struct ccw_device *);
        enum uc_todo (*uc_handler) (struct ccw_device *, struct irb *);
        struct device_driver driver;
+       enum interruption_class int_class;
 };
 
 extern struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv,
index cdb9b78f6c082e277f6726344bf8dfebc25f3fe0..2e49748b27dab5ca3e62c2b4f63909c50058a593 100644 (file)
@@ -12,6 +12,7 @@
 #define PSW32_MASK_IO          0x02000000UL
 #define PSW32_MASK_EXT         0x01000000UL
 #define PSW32_MASK_KEY         0x00F00000UL
+#define PSW32_MASK_BASE                0x00080000UL    /* Always one */
 #define PSW32_MASK_MCHECK      0x00040000UL
 #define PSW32_MASK_WAIT                0x00020000UL
 #define PSW32_MASK_PSTATE      0x00010000UL
 #define PSW32_MASK_CC          0x00003000UL
 #define PSW32_MASK_PM          0x00000f00UL
 
-#define PSW32_ADDR_AMODE31     0x80000000UL
+#define PSW32_MASK_USER                0x00003F00UL
+
+#define PSW32_ADDR_AMODE       0x80000000UL
 #define PSW32_ADDR_INSN                0x7FFFFFFFUL
 
-#define PSW32_BASE_BITS                0x00080000UL
+#define PSW32_DEFAULT_KEY      (((u32) PAGE_DEFAULT_ACC) << 20)
 
 #define PSW32_ASC_PRIMARY      0x00000000UL
 #define PSW32_ASC_ACCREG       0x00004000UL
 #define PSW32_ASC_SECONDARY    0x00008000UL
 #define PSW32_ASC_HOME         0x0000C000UL
 
-#define PSW32_MASK_MERGE(CURRENT,NEW) \
-       (((CURRENT) & ~(PSW32_MASK_CC|PSW32_MASK_PM)) | \
-        ((NEW) & (PSW32_MASK_CC|PSW32_MASK_PM)))
-
-extern long psw32_user_bits;
+extern u32 psw32_user_bits;
 
 #define COMPAT_USER_HZ         100
 #define COMPAT_UTS_MACHINE     "s390\0\0\0\0"
index 97cc4403fabfe6a0a4ad0b21a4b9b5fa41df6e28..6940abfbe1d93aaab0189bb8e77a0b2b99f8caa7 100644 (file)
@@ -168,5 +168,6 @@ enum diag308_rc {
 
 extern int diag308(unsigned long subcode, void *addr);
 extern void diag308_reset(void);
+extern void store_status(void);
 
 #endif /* _ASM_S390_IPL_H */
index ba7b01c726a37eb024900e69db673542cc86db02..ba6d85f88d50018798b95c697ed5cf75d67b0183 100644 (file)
@@ -8,7 +8,8 @@ enum interruption_class {
        EXTERNAL_INTERRUPT,
        IO_INTERRUPT,
        EXTINT_CLK,
-       EXTINT_IPI,
+       EXTINT_EXC,
+       EXTINT_EMS,
        EXTINT_TMR,
        EXTINT_TLA,
        EXTINT_PFL,
@@ -17,8 +18,8 @@ enum interruption_class {
        EXTINT_SCP,
        EXTINT_IUC,
        EXTINT_CPM,
+       IOINT_CIO,
        IOINT_QAI,
-       IOINT_QDI,
        IOINT_DAS,
        IOINT_C15,
        IOINT_C70,
@@ -28,6 +29,7 @@ enum interruption_class {
        IOINT_CLW,
        IOINT_CTC,
        IOINT_APB,
+       IOINT_CSC,
        NMI_NMI,
        NR_IRQS,
 };
index bb729b84a21e4c3c48b3a290676236c12d6a4616..cf4e47b0948c3c9b25aa5d6f310566667615d14a 100644 (file)
 /* Not more than 2GB */
 #define KEXEC_CONTROL_MEMORY_LIMIT (1UL<<31)
 
+/* Maximum address we can use for the crash control pages */
+#define KEXEC_CRASH_CONTROL_MEMORY_LIMIT (-1UL)
+
 /* Allocate one page for the pdp and the second for the code */
 #define KEXEC_CONTROL_PAGE_SIZE 4096
 
+/* Alignment of crashkernel memory */
+#define KEXEC_CRASH_MEM_ALIGN HPAGE_SIZE
+
 /* The native architecture */
 #define KEXEC_ARCH KEXEC_ARCH_S390
 
index 00ff00dfb24ce34917772a231d9607a56e15e9e9..24e18473d926548ec3e54732093902178a6838e9 100644 (file)
@@ -119,6 +119,7 @@ struct kvm_vcpu_stat {
        u32 instruction_lctlg;
        u32 exit_program_interruption;
        u32 exit_instr_and_program;
+       u32 deliver_external_call;
        u32 deliver_emergency_signal;
        u32 deliver_service_signal;
        u32 deliver_virtio_interrupt;
@@ -138,11 +139,13 @@ struct kvm_vcpu_stat {
        u32 instruction_stfl;
        u32 instruction_tprot;
        u32 instruction_sigp_sense;
+       u32 instruction_sigp_external_call;
        u32 instruction_sigp_emergency;
        u32 instruction_sigp_stop;
        u32 instruction_sigp_arch;
        u32 instruction_sigp_prefix;
        u32 instruction_sigp_restart;
+       u32 diagnose_10;
        u32 diagnose_44;
 };
 
@@ -174,6 +177,10 @@ struct kvm_s390_prefix_info {
        __u32 address;
 };
 
+struct kvm_s390_extcall_info {
+       __u16 code;
+};
+
 struct kvm_s390_emerg_info {
        __u16 code;
 };
@@ -186,6 +193,7 @@ struct kvm_s390_interrupt_info {
                struct kvm_s390_ext_info ext;
                struct kvm_s390_pgm_info pgm;
                struct kvm_s390_emerg_info emerg;
+               struct kvm_s390_extcall_info extcall;
                struct kvm_s390_prefix_info prefix;
        };
 };
index e85c911aabf04d4660059900fba13dd75e269cb4..9e13c7d56cc1cbf31c80b9b91a334b7a3659452f 100644 (file)
@@ -151,10 +151,8 @@ struct _lowcore {
         */
        __u32   ipib;                           /* 0x0e00 */
        __u32   ipib_checksum;                  /* 0x0e04 */
-
-       /* 64 bit save area */
-       __u64   save_area_64;                   /* 0x0e08 */
-       __u8    pad_0x0e10[0x0f00-0x0e10];      /* 0x0e10 */
+       __u32   vmcore_info;                    /* 0x0e08 */
+       __u8    pad_0x0e0c[0x0f00-0x0e0c];      /* 0x0e0c */
 
        /* Extended facility list */
        __u64   stfle_fac_list[32];             /* 0x0f00 */
@@ -290,9 +288,7 @@ struct _lowcore {
         */
        __u64   ipib;                           /* 0x0e00 */
        __u32   ipib_checksum;                  /* 0x0e08 */
-
-       /* 64 bit save area */
-       __u64   save_area_64;                   /* 0x0e0c */
+       __u64   vmcore_info;                    /* 0x0e0c */
        __u8    pad_0x0e14[0x0f00-0x0e14];      /* 0x0e14 */
 
        /* Extended facility list */
index accb372ddc7e4095e768a3756b6fafeb418ee4ac..f7ec548c2b9d4dbe1fec8496043c8e5bb36bbeb7 100644 (file)
@@ -177,6 +177,7 @@ static inline int page_test_and_clear_young(unsigned long pfn)
 struct page;
 void arch_free_page(struct page *page, int order);
 void arch_alloc_page(struct page *page, int order);
+void arch_set_page_states(int make_stable);
 
 static inline int devmem_is_allowed(unsigned long pfn)
 {
index c0cb794bb3657f24f994aab96544ade30b4d70a8..34ede0ea85a9d0ae6d03a8c52b3bb3f43cb4e1ac 100644 (file)
@@ -696,7 +696,9 @@ void gmap_disable(struct gmap *gmap);
 int gmap_map_segment(struct gmap *gmap, unsigned long from,
                     unsigned long to, unsigned long length);
 int gmap_unmap_segment(struct gmap *gmap, unsigned long to, unsigned long len);
+unsigned long __gmap_fault(unsigned long address, struct gmap *);
 unsigned long gmap_fault(unsigned long address, struct gmap *);
+void gmap_discard(unsigned long from, unsigned long to, struct gmap *);
 
 /*
  * Certain architectures need to do special things when PTEs
index a4b6229e5d4b703f9cf6da874e13f7dc1cc468fb..5f33d37d032c81a988310f8e539c7986f0ea4c6b 100644 (file)
@@ -33,6 +33,8 @@ static inline void get_cpu_id(struct cpuid *ptr)
 
 extern void s390_adjust_jiffies(void);
 extern int get_cpu_capability(unsigned int *);
+extern const struct seq_operations cpuinfo_op;
+extern int sysctl_ieee_emulation_warnings;
 
 /*
  * User space process size: 2GB for 31 bit, 4TB or 8PT for 64 bit.
@@ -118,17 +120,17 @@ struct stack_frame {
 /*
  * Do necessary setup to start up a new thread.
  */
-#define start_thread(regs, new_psw, new_stackp) do {           \
-       regs->psw.mask  = psw_user_bits;                        \
-       regs->psw.addr  = new_psw | PSW_ADDR_AMODE;             \
-       regs->gprs[15]  = new_stackp;                           \
+#define start_thread(regs, new_psw, new_stackp) do {                   \
+       regs->psw.mask  = psw_user_bits | PSW_MASK_EA | PSW_MASK_BA;    \
+       regs->psw.addr  = new_psw | PSW_ADDR_AMODE;                     \
+       regs->gprs[15]  = new_stackp;                                   \
 } while (0)
 
-#define start_thread31(regs, new_psw, new_stackp) do {         \
-       regs->psw.mask  = psw_user32_bits;                      \
-       regs->psw.addr  = new_psw | PSW_ADDR_AMODE;             \
-       regs->gprs[15]  = new_stackp;                           \
-       crst_table_downgrade(current->mm, 1UL << 31);           \
+#define start_thread31(regs, new_psw, new_stackp) do {                 \
+       regs->psw.mask  = psw_user_bits | PSW_MASK_BA;                  \
+       regs->psw.addr  = new_psw | PSW_ADDR_AMODE;                     \
+       regs->gprs[15]  = new_stackp;                                   \
+       crst_table_downgrade(current->mm, 1UL << 31);                   \
 } while (0)
 
 /* Forward declaration, a strange C thing */
@@ -187,7 +189,6 @@ static inline void __load_psw(psw_t psw)
  * Set PSW mask to specified value, while leaving the
  * PSW addr pointing to the next instruction.
  */
-
 static inline void __load_psw_mask (unsigned long mask)
 {
        unsigned long addr;
@@ -212,26 +213,37 @@ static inline void __load_psw_mask (unsigned long mask)
                : "=&d" (addr), "=Q" (psw) : "Q" (psw) : "memory", "cc");
 #endif /* __s390x__ */
 }
+
 /*
- * Function to stop a processor until an interruption occurred
+ * Rewind PSW instruction address by specified number of bytes.
  */
-static inline void enabled_wait(void)
+static inline unsigned long __rewind_psw(psw_t psw, unsigned long ilc)
 {
-       __load_psw_mask(PSW_BASE_BITS | PSW_MASK_IO | PSW_MASK_EXT |
-                       PSW_MASK_MCHECK | PSW_MASK_WAIT | PSW_DEFAULT_KEY);
-}
+#ifndef __s390x__
+       if (psw.addr & PSW_ADDR_AMODE)
+               /* 31 bit mode */
+               return (psw.addr - ilc) | PSW_ADDR_AMODE;
+       /* 24 bit mode */
+       return (psw.addr - ilc) & ((1UL << 24) - 1);
+#else
+       unsigned long mask;
 
+       mask = (psw.mask & PSW_MASK_EA) ? -1UL :
+              (psw.mask & PSW_MASK_BA) ? (1UL << 31) - 1 :
+                                         (1UL << 24) - 1;
+       return (psw.addr - ilc) & mask;
+#endif
+}
 /*
  * Function to drop a processor into disabled wait state
  */
-
 static inline void ATTRIB_NORET disabled_wait(unsigned long code)
 {
         unsigned long ctl_buf;
         psw_t dw_psw;
 
-        dw_psw.mask = PSW_BASE_BITS | PSW_MASK_WAIT;
+       dw_psw.mask = PSW_MASK_BASE | PSW_MASK_WAIT | PSW_MASK_BA | PSW_MASK_EA;
         dw_psw.addr = code;
         /* 
          * Store status and then load disabled wait psw,
index 62fd80c9e98cbb6b2944cba67398ee746870d1c3..a65846340d51d74c453bcc29f089c7932b3bff6d 100644 (file)
@@ -230,17 +230,21 @@ typedef struct
 #define PSW_MASK_IO            0x02000000UL
 #define PSW_MASK_EXT           0x01000000UL
 #define PSW_MASK_KEY           0x00F00000UL
+#define PSW_MASK_BASE          0x00080000UL    /* always one */
 #define PSW_MASK_MCHECK                0x00040000UL
 #define PSW_MASK_WAIT          0x00020000UL
 #define PSW_MASK_PSTATE                0x00010000UL
 #define PSW_MASK_ASC           0x0000C000UL
 #define PSW_MASK_CC            0x00003000UL
 #define PSW_MASK_PM            0x00000F00UL
+#define PSW_MASK_EA            0x00000000UL
+#define PSW_MASK_BA            0x00000000UL
+
+#define PSW_MASK_USER          0x00003F00UL
 
 #define PSW_ADDR_AMODE         0x80000000UL
 #define PSW_ADDR_INSN          0x7FFFFFFFUL
 
-#define PSW_BASE_BITS          0x00080000UL
 #define PSW_DEFAULT_KEY                (((unsigned long) PAGE_DEFAULT_ACC) << 20)
 
 #define PSW_ASC_PRIMARY                0x00000000UL
@@ -254,6 +258,7 @@ typedef struct
 #define PSW_MASK_DAT           0x0400000000000000UL
 #define PSW_MASK_IO            0x0200000000000000UL
 #define PSW_MASK_EXT           0x0100000000000000UL
+#define PSW_MASK_BASE          0x0000000000000000UL
 #define PSW_MASK_KEY           0x00F0000000000000UL
 #define PSW_MASK_MCHECK                0x0004000000000000UL
 #define PSW_MASK_WAIT          0x0002000000000000UL
@@ -261,12 +266,14 @@ typedef struct
 #define PSW_MASK_ASC           0x0000C00000000000UL
 #define PSW_MASK_CC            0x0000300000000000UL
 #define PSW_MASK_PM            0x00000F0000000000UL
+#define PSW_MASK_EA            0x0000000100000000UL
+#define PSW_MASK_BA            0x0000000080000000UL
+
+#define PSW_MASK_USER          0x00003F0180000000UL
 
 #define PSW_ADDR_AMODE         0x0000000000000000UL
 #define PSW_ADDR_INSN          0xFFFFFFFFFFFFFFFFUL
 
-#define PSW_BASE_BITS          0x0000000180000000UL
-#define PSW_BASE32_BITS                0x0000000080000000UL
 #define PSW_DEFAULT_KEY                (((unsigned long) PAGE_DEFAULT_ACC) << 52)
 
 #define PSW_ASC_PRIMARY                0x0000000000000000UL
@@ -279,18 +286,7 @@ typedef struct
 #ifdef __KERNEL__
 extern long psw_kernel_bits;
 extern long psw_user_bits;
-#ifdef CONFIG_64BIT
-extern long psw_user32_bits;
 #endif
-#endif
-
-/* This macro merges a NEW PSW mask specified by the user into
-   the currently active PSW mask CURRENT, modifying only those
-   bits in CURRENT that the user may be allowed to change: this
-   is the condition code and the program mask bits.  */
-#define PSW_MASK_MERGE(CURRENT,NEW) \
-       (((CURRENT) & ~(PSW_MASK_CC|PSW_MASK_PM)) | \
-        ((NEW) & (PSW_MASK_CC|PSW_MASK_PM)))
 
 /*
  * The s390_regs structure is used to define the elf_gregset_t.
@@ -328,8 +324,7 @@ struct pt_regs
        psw_t psw;
        unsigned long gprs[NUM_GPRS];
        unsigned long orig_gpr2;
-       unsigned short ilc;
-       unsigned short svcnr;
+       unsigned int svc_code;
 };
 
 /*
@@ -487,6 +482,8 @@ typedef struct
 #define PTRACE_POKETEXT_AREA         0x5004
 #define PTRACE_POKEDATA_AREA         0x5005
 #define PTRACE_GET_LAST_BREAK        0x5006
+#define PTRACE_PEEK_SYSTEM_CALL       0x5007
+#define PTRACE_POKE_SYSTEM_CALL              0x5008
 
 /*
  * PT_PROT definition is loosely based on hppa bsd definition in
index 21993623da9a576f0d97c0c6784c20512f73adff..e63d13dd3bf5b9de0e0a7a53289a341773260f49 100644 (file)
@@ -46,6 +46,8 @@ struct qdesfmt0 {
        u32      : 16;
 } __attribute__ ((packed));
 
+#define QDR_AC_MULTI_BUFFER_ENABLE 0x01
+
 /**
  * struct qdr - queue description record (QDR)
  * @qfmt: queue format
@@ -256,6 +258,8 @@ struct slsb {
        u8 val[QDIO_MAX_BUFFERS_PER_Q];
 } __attribute__ ((packed, aligned(256)));
 
+#define CHSC_AC2_MULTI_BUFFER_AVAILABLE        0x0080
+#define CHSC_AC2_MULTI_BUFFER_ENABLED  0x0040
 #define CHSC_AC2_DATA_DIV_AVAILABLE    0x0010
 #define CHSC_AC2_DATA_DIV_ENABLED      0x0002
 
@@ -357,6 +361,7 @@ typedef void qdio_handler_t(struct ccw_device *, unsigned int, int,
 struct qdio_initialize {
        struct ccw_device *cdev;
        unsigned char q_format;
+       unsigned char qdr_ac;
        unsigned char adapter_name[8];
        unsigned int qib_param_field_format;
        unsigned char *qib_param_field;
index f584f4a525814821ea25a9a061ca5dc0d5e03df6..3d6ad4ad2a3f536a28d72164d43d57b887cb2724 100644 (file)
@@ -17,5 +17,5 @@ struct reset_call {
 
 extern void register_reset_call(struct reset_call *reset);
 extern void unregister_reset_call(struct reset_call *reset);
-extern void s390_reset_system(void);
+extern void s390_reset_system(void (*func)(void *), void *data);
 #endif /* _ASM_S390_RESET_H */
index d5e2ef10537d9a93882e3bc38b857cb2edf4f764..5a099714df0459b9470e3d158e0b163bf8ce770b 100644 (file)
 #define IPL_DEVICE        (*(unsigned long *)  (0x10404))
 #define INITRD_START      (*(unsigned long *)  (0x1040C))
 #define INITRD_SIZE       (*(unsigned long *)  (0x10414))
+#define OLDMEM_BASE      (*(unsigned long *)  (0x1041C))
+#define OLDMEM_SIZE      (*(unsigned long *)  (0x10424))
 #else /* __s390x__ */
 #define IPL_DEVICE        (*(unsigned long *)  (0x10400))
 #define INITRD_START      (*(unsigned long *)  (0x10408))
 #define INITRD_SIZE       (*(unsigned long *)  (0x10410))
+#define OLDMEM_BASE      (*(unsigned long *)  (0x10418))
+#define OLDMEM_SIZE      (*(unsigned long *)  (0x10420))
 #endif /* __s390x__ */
 #define COMMAND_LINE      ((char *)            (0x10480))
 
 #define CHUNK_READ_WRITE 0
 #define CHUNK_READ_ONLY  1
+#define CHUNK_OLDMEM    4
+#define CHUNK_CRASHK    5
 
 struct mem_chunk {
        unsigned long addr;
@@ -48,6 +54,8 @@ extern int memory_end_set;
 extern unsigned long memory_end;
 
 void detect_memory_layout(struct mem_chunk chunk[]);
+void create_mem_hole(struct mem_chunk memory_chunk[], unsigned long addr,
+                    unsigned long size, int type);
 
 #define PRIMARY_SPACE_MODE     0
 #define ACCESS_REGISTER_MODE   1
@@ -106,6 +114,7 @@ extern unsigned int user_mode;
 #endif /* __s390x__ */
 
 #define ZFCPDUMP_HSA_SIZE      (32UL<<20)
+#define ZFCPDUMP_HSA_SIZE_MAX  (64UL<<20)
 
 /*
  * Console mode. Override with conmode=
@@ -134,10 +143,14 @@ extern char kernel_nss_name[];
 #define IPL_DEVICE        0x10404
 #define INITRD_START      0x1040C
 #define INITRD_SIZE       0x10414
+#define OLDMEM_BASE      0x1041C
+#define OLDMEM_SIZE      0x10424
 #else /* __s390x__ */
 #define IPL_DEVICE        0x10400
 #define INITRD_START      0x10408
 #define INITRD_SIZE       0x10410
+#define OLDMEM_BASE      0x10418
+#define OLDMEM_SIZE      0x10420
 #endif /* __s390x__ */
 #define COMMAND_LINE      0x10480
 
index 0addc6466d958aede3954efeb6b7071077344e6c..ca3f8814e3614050d5714843fea3a97c90db8bca 100644 (file)
@@ -72,6 +72,6 @@ extern unsigned long __udiv_qrnnd (unsigned int *, unsigned int,
 
 #define UDIV_NEEDS_NORMALIZATION 0
 
-#define abort() return 0
+#define abort() BUG()
 
 #define __BYTE_ORDER __BIG_ENDIAN
index 045e009fc16443e1ed6816c6d2375abbbbeeae4b..ab47a69fdf071de639bf12914b83316488105d93 100644 (file)
@@ -33,6 +33,7 @@ extern struct save_area *zfcpdump_save_areas[NR_CPUS + 1];
 extern void smp_switch_to_ipl_cpu(void (*func)(void *), void *);
 extern void smp_switch_to_cpu(void (*)(void *), void *, unsigned long sp,
                              int from, int to);
+extern void smp_restart_with_online_cpu(void);
 extern void smp_restart_cpu(void);
 
 /*
@@ -64,6 +65,10 @@ static inline void smp_switch_to_ipl_cpu(void (*func)(void *), void *data)
        func(data);
 }
 
+static inline void smp_restart_with_online_cpu(void)
+{
+}
+
 #define smp_vcpu_scheduled     (1)
 
 #endif /* CONFIG_SMP */
index 56612fc8186ef25251ab235458b187bcda73f2b2..fd94dfec8d081a0f3da4d740f48c4cc2cc68fd66 100644 (file)
@@ -13,6 +13,8 @@
 
 #include <linux/smp.h>
 
+extern int spin_retry;
+
 static inline int
 _raw_compare_and_swap(volatile unsigned int *lock,
                      unsigned int old, unsigned int new)
index 5c0246b955d80e411250623c400c3387f23568b7..b239ff53b189fd90c66003d350c183785620ad95 100644 (file)
@@ -13,6 +13,7 @@
 #define _ASM_SYSCALL_H 1
 
 #include <linux/sched.h>
+#include <linux/err.h>
 #include <asm/ptrace.h>
 
 /*
@@ -25,7 +26,8 @@ extern const unsigned int sys_call_table[];
 static inline long syscall_get_nr(struct task_struct *task,
                                  struct pt_regs *regs)
 {
-       return regs->svcnr ? regs->svcnr : -1;
+       return test_tsk_thread_flag(task, TIF_SYSCALL) ?
+               (regs->svc_code & 0xffff) : -1;
 }
 
 static inline void syscall_rollback(struct task_struct *task,
@@ -37,7 +39,7 @@ static inline void syscall_rollback(struct task_struct *task,
 static inline long syscall_get_error(struct task_struct *task,
                                     struct pt_regs *regs)
 {
-       return (regs->gprs[2] >= -4096UL) ? -regs->gprs[2] : 0;
+       return IS_ERR_VALUE(regs->gprs[2]) ? regs->gprs[2] : 0;
 }
 
 static inline long syscall_get_return_value(struct task_struct *task,
index 6582f69f23899b4989c05b9aacf0fb6de4bed4c2..ef573c1d71a796664d4afe1ebe4280d70b476657 100644 (file)
@@ -20,6 +20,8 @@
 
 struct task_struct;
 
+extern int sysctl_userprocess_debug;
+
 extern struct task_struct *__switch_to(void *, void *);
 extern void update_per_regs(struct task_struct *task);
 
@@ -114,6 +116,8 @@ extern void pfault_fini(void);
 extern void cmma_init(void);
 extern int memcpy_real(void *, void *, size_t);
 extern void copy_to_absolute_zero(void *dest, void *src, size_t count);
+extern int copy_to_user_real(void __user *dest, void *src, size_t count);
+extern int copy_from_user_real(void *dest, void __user *src, size_t count);
 
 #define finish_arch_switch(prev) do {                                       \
        set_fs(current->thread.mm_segment);                                  \
@@ -210,8 +214,10 @@ __set_psw_mask(unsigned long mask)
        __load_psw_mask(mask | (arch_local_save_flags() & ~(-1UL >> 8)));
 }
 
-#define local_mcck_enable()  __set_psw_mask(psw_kernel_bits)
-#define local_mcck_disable() __set_psw_mask(psw_kernel_bits & ~PSW_MASK_MCHECK)
+#define local_mcck_enable() \
+       __set_psw_mask(psw_kernel_bits | PSW_MASK_DAT | PSW_MASK_MCHECK)
+#define local_mcck_disable() \
+       __set_psw_mask(psw_kernel_bits | PSW_MASK_DAT)
 
 #ifdef CONFIG_SMP
 
index 1a5dbb6f1495468c4c16dfc4695f4aaa10aa9698..a23183423b14193d3aa1ca4787a826b3c3698f9d 100644 (file)
@@ -48,6 +48,7 @@ struct thread_info {
        unsigned int            cpu;            /* current CPU */
        int                     preempt_count;  /* 0 => preemptable, <0 => BUG */
        struct restart_block    restart_block;
+       unsigned int            system_call;
        __u64                   user_timer;
        __u64                   system_timer;
        unsigned long           last_break;     /* last breaking-event-address. */
@@ -84,10 +85,10 @@ static inline struct thread_info *current_thread_info(void)
 /*
  * thread information flags bit numbers
  */
+#define TIF_SYSCALL            0       /* inside a system call */
 #define TIF_NOTIFY_RESUME      1       /* callback before returning to user */
 #define TIF_SIGPENDING         2       /* signal pending */
 #define TIF_NEED_RESCHED       3       /* rescheduling necessary */
-#define TIF_RESTART_SVC                4       /* restart svc with new svc number */
 #define TIF_PER_TRAP           6       /* deliver sigtrap on return to user */
 #define TIF_MCCK_PENDING       7       /* machine check handling is pending */
 #define TIF_SYSCALL_TRACE      8       /* syscall trace active */
@@ -103,11 +104,11 @@ static inline struct thread_info *current_thread_info(void)
 #define TIF_SINGLE_STEP                20      /* This task is single stepped */
 #define TIF_FREEZE             21      /* thread is freezing for suspend */
 
+#define _TIF_SYSCALL           (1<<TIF_SYSCALL)
 #define _TIF_NOTIFY_RESUME     (1<<TIF_NOTIFY_RESUME)
 #define _TIF_RESTORE_SIGMASK   (1<<TIF_RESTORE_SIGMASK)
 #define _TIF_SIGPENDING                (1<<TIF_SIGPENDING)
 #define _TIF_NEED_RESCHED      (1<<TIF_NEED_RESCHED)
-#define _TIF_RESTART_SVC       (1<<TIF_RESTART_SVC)
 #define _TIF_PER_TRAP          (1<<TIF_PER_TRAP)
 #define _TIF_MCCK_PENDING      (1<<TIF_MCCK_PENDING)
 #define _TIF_SYSCALL_TRACE     (1<<TIF_SYSCALL_TRACE)
@@ -117,7 +118,7 @@ static inline struct thread_info *current_thread_info(void)
 #define _TIF_SIE               (1<<TIF_SIE)
 #define _TIF_POLLING_NRFLAG    (1<<TIF_POLLING_NRFLAG)
 #define _TIF_31BIT             (1<<TIF_31BIT)
-#define _TIF_SINGLE_STEP       (1<<TIF_FREEZE)
+#define _TIF_SINGLE_STEP       (1<<TIF_SINGLE_STEP)
 #define _TIF_FREEZE            (1<<TIF_FREEZE)
 
 #ifdef CONFIG_64BIT
index 88829a40af6f56e4dd67d70ceb289e0fe9faf13b..d610bef9c5e91a425ad01a683525f46ba0c055e1 100644 (file)
@@ -86,6 +86,17 @@ static inline void get_clock_ext(char *clk)
        asm volatile("stcke %0" : "=Q" (*clk) : : "cc");
 }
 
+static inline unsigned long long get_clock_fast(void)
+{
+       unsigned long long clk;
+
+       if (test_facility(25))
+               asm volatile(".insn     s,0xb27c0000,%0" : "=Q" (clk) : : "cc");
+       else
+               clk = get_clock();
+       return clk;
+}
+
 static inline unsigned long long get_clock_xt(void)
 {
        unsigned char clk[16];
index 30444538238290fb5b064e8d9e9ce54fcc9c1259..1d8648cf2fea81eb7a6fdbe5129fd22478b074c2 100644 (file)
@@ -59,6 +59,7 @@ static inline void __tlb_flush_full(struct mm_struct *mm)
 }
 #else
 #define __tlb_flush_full(mm)   __tlb_flush_local()
+#define __tlb_flush_global()   __tlb_flush_local()
 #endif
 
 /*
index df3732249baafa3f0c30474d26da5243412890d1..dd4f076409190c22a0154e9bac693e7b2a75f3b9 100644 (file)
@@ -48,6 +48,7 @@ obj-$(CONFIG_FUNCTION_TRACER) += $(if $(CONFIG_64BIT),mcount64.o,mcount.o)
 obj-$(CONFIG_DYNAMIC_FTRACE)   += ftrace.o
 obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o
 obj-$(CONFIG_FTRACE_SYSCALLS)  += ftrace.o
+obj-$(CONFIG_CRASH_DUMP)       += crash_dump.o
 
 # Kexec part
 S390_KEXEC_OBJS := machine_kexec.o crash.o
index 2b45591e15821db1a62d2206653980a5e5b52cc1..751318765e2e95ba1a2d5c56e683e13de0eb9925 100644 (file)
@@ -45,8 +45,7 @@ int main(void)
        DEFINE(__PT_PSW, offsetof(struct pt_regs, psw));
        DEFINE(__PT_GPRS, offsetof(struct pt_regs, gprs));
        DEFINE(__PT_ORIG_GPR2, offsetof(struct pt_regs, orig_gpr2));
-       DEFINE(__PT_ILC, offsetof(struct pt_regs, ilc));
-       DEFINE(__PT_SVCNR, offsetof(struct pt_regs, svcnr));
+       DEFINE(__PT_SVC_CODE, offsetof(struct pt_regs, svc_code));
        DEFINE(__PT_SIZE, sizeof(struct pt_regs));
        BLANK();
        DEFINE(__SF_BACKCHAIN, offsetof(struct stack_frame, back_chain));
@@ -141,7 +140,6 @@ int main(void)
        DEFINE(__LC_FPREGS_SAVE_AREA, offsetof(struct _lowcore, floating_pt_save_area));
        DEFINE(__LC_GPREGS_SAVE_AREA, offsetof(struct _lowcore, gpregs_save_area));
        DEFINE(__LC_CREGS_SAVE_AREA, offsetof(struct _lowcore, cregs_save_area));
-       DEFINE(__LC_SAVE_AREA_64, offsetof(struct _lowcore, save_area_64));
 #ifdef CONFIG_32BIT
        DEFINE(SAVE_AREA_BASE, offsetof(struct _lowcore, extended_save_area_addr));
 #else /* CONFIG_32BIT */
index 255435663bf820299734afdce573fa52050e9d87..f8828d38fa6ec62d3ccd82f46c5228a21e519955 100644 (file)
@@ -86,6 +86,8 @@ s390_base_pgm_handler_fn:
 ENTRY(diag308_reset)
        larl    %r4,.Lctlregs           # Save control registers
        stctg   %c0,%c15,0(%r4)
+       larl    %r4,.Lfpctl             # Floating point control register
+       stfpc   0(%r4)
        larl    %r4,.Lrestart_psw       # Setup restart PSW at absolute 0
        lghi    %r3,0
        lg      %r4,0(%r4)              # Save PSW
@@ -99,6 +101,8 @@ ENTRY(diag308_reset)
        sam64                           # Switch to 64 bit addressing mode
        larl    %r4,.Lctlregs           # Restore control registers
        lctlg   %c0,%c15,0(%r4)
+       larl    %r4,.Lfpctl             # Restore floating point ctl register
+       lfpc    0(%r4)
        br      %r14
 .align 16
 .Lrestart_psw:
@@ -110,6 +114,8 @@ ENTRY(diag308_reset)
        .rept   16
        .quad   0
        .endr
+.Lfpctl:
+       .long   0
        .previous
 
 #else /* CONFIG_64BIT */
index 53acaa86dd94f353e36beb03f5c9e904c14d42d3..84a982898448e04aeb971d3915ea9121610729af 100644 (file)
 
 #include "compat_linux.h"
 
-long psw_user32_bits   = (PSW_BASE32_BITS | PSW_MASK_DAT | PSW_ASC_HOME |
-                          PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK |
-                          PSW_MASK_PSTATE | PSW_DEFAULT_KEY);
-long psw32_user_bits   = (PSW32_BASE_BITS | PSW32_MASK_DAT | PSW32_ASC_HOME |
-                          PSW32_MASK_IO | PSW32_MASK_EXT | PSW32_MASK_MCHECK |
-                          PSW32_MASK_PSTATE);
+u32 psw32_user_bits = PSW32_MASK_DAT | PSW32_MASK_IO | PSW32_MASK_EXT |
+                     PSW32_DEFAULT_KEY | PSW32_MASK_BASE | PSW32_MASK_MCHECK |
+                     PSW32_MASK_PSTATE | PSW32_ASC_HOME;
  
 /* For this source file, we want overflow handling. */
 
@@ -365,12 +362,7 @@ asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
        if (set) {
                if (copy_from_user (&s32, set, sizeof(compat_sigset_t)))
                        return -EFAULT;
-               switch (_NSIG_WORDS) {
-               case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
-               case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
-               case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
-               case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
-               }
+               s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
        }
        set_fs (KERNEL_DS);
        ret = sys_rt_sigprocmask(how,
@@ -380,12 +372,8 @@ asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
        set_fs (old_fs);
        if (ret) return ret;
        if (oset) {
-               switch (_NSIG_WORDS) {
-               case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
-               case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
-               case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
-               case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
-               }
+               s32.sig[1] = (s.sig[0] >> 32);
+               s32.sig[0] = s.sig[0];
                if (copy_to_user (oset, &s32, sizeof(compat_sigset_t)))
                        return -EFAULT;
        }
@@ -404,12 +392,8 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
        ret = sys_rt_sigpending((sigset_t __force __user *) &s, sigsetsize);
        set_fs (old_fs);
        if (!ret) {
-               switch (_NSIG_WORDS) {
-               case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
-               case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
-               case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
-               case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
-               }
+               s32.sig[1] = (s.sig[0] >> 32);
+               s32.sig[0] = s.sig[0];
                if (copy_to_user (set, &s32, sizeof(compat_sigset_t)))
                        return -EFAULT;
        }
index a9a285b8c4ad3ccdfafcaf2b1412de4900e2b219..4f68c81d3ffaafb7ee1db39e7c63375e0d08422b 100644 (file)
@@ -141,7 +141,8 @@ int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from)
                        break;
                case __SI_FAULT >> 16:
                        err |= __get_user(tmp, &from->si_addr);
-                       to->si_addr = (void __user *)(u64) (tmp & PSW32_ADDR_INSN);
+                       to->si_addr = (void __force __user *)
+                               (u64) (tmp & PSW32_ADDR_INSN);
                        break;
                case __SI_POLL >> 16:
                        err |= __get_user(to->si_band, &from->si_band);
@@ -213,16 +214,8 @@ sys32_rt_sigaction(int sig, const struct sigaction32 __user *act,
                ret = get_user(sa_handler, &act->sa_handler);
                ret |= __copy_from_user(&set32, &act->sa_mask,
                                        sizeof(compat_sigset_t));
-               switch (_NSIG_WORDS) {
-               case 4: new_ka.sa.sa_mask.sig[3] = set32.sig[6]
-                               | (((long)set32.sig[7]) << 32);
-               case 3: new_ka.sa.sa_mask.sig[2] = set32.sig[4]
-                               | (((long)set32.sig[5]) << 32);
-               case 2: new_ka.sa.sa_mask.sig[1] = set32.sig[2]
-                               | (((long)set32.sig[3]) << 32);
-               case 1: new_ka.sa.sa_mask.sig[0] = set32.sig[0]
-                               | (((long)set32.sig[1]) << 32);
-               }
+               new_ka.sa.sa_mask.sig[0] =
+                       set32.sig[0] | (((long)set32.sig[1]) << 32);
                ret |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
                
                if (ret)
@@ -233,20 +226,8 @@ sys32_rt_sigaction(int sig, const struct sigaction32 __user *act,
        ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
 
        if (!ret && oact) {
-               switch (_NSIG_WORDS) {
-               case 4:
-                       set32.sig[7] = (old_ka.sa.sa_mask.sig[3] >> 32);
-                       set32.sig[6] = old_ka.sa.sa_mask.sig[3];
-               case 3:
-                       set32.sig[5] = (old_ka.sa.sa_mask.sig[2] >> 32);
-                       set32.sig[4] = old_ka.sa.sa_mask.sig[2];
-               case 2:
-                       set32.sig[3] = (old_ka.sa.sa_mask.sig[1] >> 32);
-                       set32.sig[2] = old_ka.sa.sa_mask.sig[1];
-               case 1:
-                       set32.sig[1] = (old_ka.sa.sa_mask.sig[0] >> 32);
-                       set32.sig[0] = old_ka.sa.sa_mask.sig[0];
-               }
+               set32.sig[1] = (old_ka.sa.sa_mask.sig[0] >> 32);
+               set32.sig[0] = old_ka.sa.sa_mask.sig[0];
                ret = put_user((unsigned long)old_ka.sa.sa_handler, &oact->sa_handler);
                ret |= __copy_to_user(&oact->sa_mask, &set32,
                                      sizeof(compat_sigset_t));
@@ -300,9 +281,10 @@ static int save_sigregs32(struct pt_regs *regs, _sigregs32 __user *sregs)
        _s390_regs_common32 regs32;
        int err, i;
 
-       regs32.psw.mask = PSW32_MASK_MERGE(psw32_user_bits,
-                                          (__u32)(regs->psw.mask >> 32));
-       regs32.psw.addr = PSW32_ADDR_AMODE31 | (__u32) regs->psw.addr;
+       regs32.psw.mask = psw32_user_bits |
+               ((__u32)(regs->psw.mask >> 32) & PSW32_MASK_USER);
+       regs32.psw.addr = (__u32) regs->psw.addr |
+               (__u32)(regs->psw.mask & PSW_MASK_BA);
        for (i = 0; i < NUM_GPRS; i++)
                regs32.gprs[i] = (__u32) regs->gprs[i];
        save_access_regs(current->thread.acrs);
@@ -327,8 +309,9 @@ static int restore_sigregs32(struct pt_regs *regs,_sigregs32 __user *sregs)
        err = __copy_from_user(&regs32, &sregs->regs, sizeof(regs32));
        if (err)
                return err;
-       regs->psw.mask = PSW_MASK_MERGE(regs->psw.mask,
-                                       (__u64)regs32.psw.mask << 32);
+       regs->psw.mask = (regs->psw.mask & ~PSW_MASK_USER) |
+               (__u64)(regs32.psw.mask & PSW32_MASK_USER) << 32 |
+               (__u64)(regs32.psw.addr & PSW32_ADDR_AMODE);
        regs->psw.addr = (__u64)(regs32.psw.addr & PSW32_ADDR_INSN);
        for (i = 0; i < NUM_GPRS; i++)
                regs->gprs[i] = (__u64) regs32.gprs[i];
@@ -342,7 +325,7 @@ static int restore_sigregs32(struct pt_regs *regs,_sigregs32 __user *sregs)
                return err;
 
        restore_fp_regs(&current->thread.fp_regs);
-       regs->svcnr = 0;        /* disable syscall checks */
+       clear_thread_flag(TIF_SYSCALL); /* No longer in a system call */
        return 0;
 }
 
@@ -496,11 +479,11 @@ static int setup_frame32(int sig, struct k_sigaction *ka,
        /* Set up to return from userspace.  If provided, use a stub
           already in userspace.  */
        if (ka->sa.sa_flags & SA_RESTORER) {
-               regs->gprs[14] = (__u64) ka->sa.sa_restorer;
+               regs->gprs[14] = (__u64) ka->sa.sa_restorer | PSW32_ADDR_AMODE;
        } else {
-               regs->gprs[14] = (__u64) frame->retcode;
+               regs->gprs[14] = (__u64) frame->retcode | PSW32_ADDR_AMODE;
                if (__put_user(S390_SYSCALL_OPCODE | __NR_sigreturn,
-                              (u16 __user *)(frame->retcode)))
+                              (u16 __force __user *)(frame->retcode)))
                        goto give_sigsegv;
         }
 
@@ -509,11 +492,12 @@ static int setup_frame32(int sig, struct k_sigaction *ka,
                goto give_sigsegv;
 
        /* Set up registers for signal handler */
-       regs->gprs[15] = (__u64) frame;
-       regs->psw.addr = (__u64) ka->sa.sa_handler;
+       regs->gprs[15] = (__force __u64) frame;
+       regs->psw.mask |= PSW_MASK_BA;          /* force amode 31 */
+       regs->psw.addr = (__force __u64) ka->sa.sa_handler;
 
        regs->gprs[2] = map_signal(sig);
-       regs->gprs[3] = (__u64) &frame->sc;
+       regs->gprs[3] = (__force __u64) &frame->sc;
 
        /* We forgot to include these in the sigcontext.
           To avoid breaking binary compatibility, they are passed as args. */
@@ -521,7 +505,7 @@ static int setup_frame32(int sig, struct k_sigaction *ka,
        regs->gprs[5] = current->thread.prot_addr;
 
        /* Place signal number on stack to allow backtrace from handler.  */
-       if (__put_user(regs->gprs[2], (int __user *) &frame->signo))
+       if (__put_user(regs->gprs[2], (int __force __user *) &frame->signo))
                goto give_sigsegv;
        return 0;
 
@@ -564,20 +548,21 @@ static int setup_rt_frame32(int sig, struct k_sigaction *ka, siginfo_t *info,
        } else {
                regs->gprs[14] = (__u64) frame->retcode;
                err |= __put_user(S390_SYSCALL_OPCODE | __NR_rt_sigreturn,
-                                 (u16 __user *)(frame->retcode));
+                                 (u16 __force __user *)(frame->retcode));
        }
 
        /* Set up backchain. */
-       if (__put_user(regs->gprs[15], (unsigned int __user *) frame))
+       if (__put_user(regs->gprs[15], (unsigned int __force __user *) frame))
                goto give_sigsegv;
 
        /* Set up registers for signal handler */
-       regs->gprs[15] = (__u64) frame;
+       regs->gprs[15] = (__force __u64) frame;
+       regs->psw.mask |= PSW_MASK_BA;          /* force amode 31 */
        regs->psw.addr = (__u64) ka->sa.sa_handler;
 
        regs->gprs[2] = map_signal(sig);
-       regs->gprs[3] = (__u64) &frame->info;
-       regs->gprs[4] = (__u64) &frame->uc;
+       regs->gprs[3] = (__force __u64) &frame->info;
+       regs->gprs[4] = (__force __u64) &frame->uc;
        return 0;
 
 give_sigsegv:
index 7526db6bf501f8a5394f56dfc0cadfc343ef82e6..5006a1d9f5d0ed6d3abd95f3cca652d87689dcef 100644 (file)
@@ -1623,8 +1623,7 @@ ENTRY(sys_syncfs_wrapper)
        lgfr    %r2,%r2                 # int
        jg      sys_syncfs
 
-       .globl  sys_setns_wrapper
-sys_setns_wrapper:
+ENTRY(sys_setns_wrapper)
        lgfr    %r2,%r2                 # int
        lgfr    %r3,%r3                 # int
        jg      sys_setns
diff --git a/arch/s390/kernel/crash_dump.c b/arch/s390/kernel/crash_dump.c
new file mode 100644 (file)
index 0000000..39f8fd4
--- /dev/null
@@ -0,0 +1,426 @@
+/*
+ * S390 kdump implementation
+ *
+ * Copyright IBM Corp. 2011
+ * Author(s): Michael Holzheu <holzheu@linux.vnet.ibm.com>
+ */
+
+#include <linux/crash_dump.h>
+#include <asm/lowcore.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/gfp.h>
+#include <linux/slab.h>
+#include <linux/crash_dump.h>
+#include <linux/bootmem.h>
+#include <linux/elf.h>
+#include <asm/ipl.h>
+
+#define PTR_ADD(x, y) (((char *) (x)) + ((unsigned long) (y)))
+#define PTR_SUB(x, y) (((char *) (x)) - ((unsigned long) (y)))
+#define PTR_DIFF(x, y) ((unsigned long)(((char *) (x)) - ((unsigned long) (y))))
+
+/*
+ * Copy one page from "oldmem"
+ *
+ * For the kdump reserved memory this functions performs a swap operation:
+ *  - [OLDMEM_BASE - OLDMEM_BASE + OLDMEM_SIZE] is mapped to [0 - OLDMEM_SIZE].
+ *  - [0 - OLDMEM_SIZE] is mapped to [OLDMEM_BASE - OLDMEM_BASE + OLDMEM_SIZE]
+ */
+ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
+                        size_t csize, unsigned long offset, int userbuf)
+{
+       unsigned long src;
+
+       if (!csize)
+               return 0;
+
+       src = (pfn << PAGE_SHIFT) + offset;
+       if (src < OLDMEM_SIZE)
+               src += OLDMEM_BASE;
+       else if (src > OLDMEM_BASE &&
+                src < OLDMEM_BASE + OLDMEM_SIZE)
+               src -= OLDMEM_BASE;
+       if (userbuf)
+               copy_to_user_real((void __force __user *) buf, (void *) src,
+                                 csize);
+       else
+               memcpy_real(buf, (void *) src, csize);
+       return csize;
+}
+
+/*
+ * Copy memory from old kernel
+ */
+static int copy_from_oldmem(void *dest, void *src, size_t count)
+{
+       unsigned long copied = 0;
+       int rc;
+
+       if ((unsigned long) src < OLDMEM_SIZE) {
+               copied = min(count, OLDMEM_SIZE - (unsigned long) src);
+               rc = memcpy_real(dest, src + OLDMEM_BASE, copied);
+               if (rc)
+                       return rc;
+       }
+       return memcpy_real(dest + copied, src + copied, count - copied);
+}
+
+/*
+ * Alloc memory and panic in case of ENOMEM
+ */
+static void *kzalloc_panic(int len)
+{
+       void *rc;
+
+       rc = kzalloc(len, GFP_KERNEL);
+       if (!rc)
+               panic("s390 kdump kzalloc (%d) failed", len);
+       return rc;
+}
+
+/*
+ * Get memory layout and create hole for oldmem
+ */
+static struct mem_chunk *get_memory_layout(void)
+{
+       struct mem_chunk *chunk_array;
+
+       chunk_array = kzalloc_panic(MEMORY_CHUNKS * sizeof(struct mem_chunk));
+       detect_memory_layout(chunk_array);
+       create_mem_hole(chunk_array, OLDMEM_BASE, OLDMEM_SIZE, CHUNK_CRASHK);
+       return chunk_array;
+}
+
+/*
+ * Initialize ELF note
+ */
+static void *nt_init(void *buf, Elf64_Word type, void *desc, int d_len,
+                    const char *name)
+{
+       Elf64_Nhdr *note;
+       u64 len;
+
+       note = (Elf64_Nhdr *)buf;
+       note->n_namesz = strlen(name) + 1;
+       note->n_descsz = d_len;
+       note->n_type = type;
+       len = sizeof(Elf64_Nhdr);
+
+       memcpy(buf + len, name, note->n_namesz);
+       len = roundup(len + note->n_namesz, 4);
+
+       memcpy(buf + len, desc, note->n_descsz);
+       len = roundup(len + note->n_descsz, 4);
+
+       return PTR_ADD(buf, len);
+}
+
+/*
+ * Initialize prstatus note
+ */
+static void *nt_prstatus(void *ptr, struct save_area *sa)
+{
+       struct elf_prstatus nt_prstatus;
+       static int cpu_nr = 1;
+
+       memset(&nt_prstatus, 0, sizeof(nt_prstatus));
+       memcpy(&nt_prstatus.pr_reg.gprs, sa->gp_regs, sizeof(sa->gp_regs));
+       memcpy(&nt_prstatus.pr_reg.psw, sa->psw, sizeof(sa->psw));
+       memcpy(&nt_prstatus.pr_reg.acrs, sa->acc_regs, sizeof(sa->acc_regs));
+       nt_prstatus.pr_pid = cpu_nr;
+       cpu_nr++;
+
+       return nt_init(ptr, NT_PRSTATUS, &nt_prstatus, sizeof(nt_prstatus),
+                        "CORE");
+}
+
+/*
+ * Initialize fpregset (floating point) note
+ */
+static void *nt_fpregset(void *ptr, struct save_area *sa)
+{
+       elf_fpregset_t nt_fpregset;
+
+       memset(&nt_fpregset, 0, sizeof(nt_fpregset));
+       memcpy(&nt_fpregset.fpc, &sa->fp_ctrl_reg, sizeof(sa->fp_ctrl_reg));
+       memcpy(&nt_fpregset.fprs, &sa->fp_regs, sizeof(sa->fp_regs));
+
+       return nt_init(ptr, NT_PRFPREG, &nt_fpregset, sizeof(nt_fpregset),
+                      "CORE");
+}
+
+/*
+ * Initialize timer note
+ */
+static void *nt_s390_timer(void *ptr, struct save_area *sa)
+{
+       return nt_init(ptr, NT_S390_TIMER, &sa->timer, sizeof(sa->timer),
+                        KEXEC_CORE_NOTE_NAME);
+}
+
+/*
+ * Initialize TOD clock comparator note
+ */
+static void *nt_s390_tod_cmp(void *ptr, struct save_area *sa)
+{
+       return nt_init(ptr, NT_S390_TODCMP, &sa->clk_cmp,
+                      sizeof(sa->clk_cmp), KEXEC_CORE_NOTE_NAME);
+}
+
+/*
+ * Initialize TOD programmable register note
+ */
+static void *nt_s390_tod_preg(void *ptr, struct save_area *sa)
+{
+       return nt_init(ptr, NT_S390_TODPREG, &sa->tod_reg,
+                      sizeof(sa->tod_reg), KEXEC_CORE_NOTE_NAME);
+}
+
+/*
+ * Initialize control register note
+ */
+static void *nt_s390_ctrs(void *ptr, struct save_area *sa)
+{
+       return nt_init(ptr, NT_S390_CTRS, &sa->ctrl_regs,
+                      sizeof(sa->ctrl_regs), KEXEC_CORE_NOTE_NAME);
+}
+
+/*
+ * Initialize prefix register note
+ */
+static void *nt_s390_prefix(void *ptr, struct save_area *sa)
+{
+       return nt_init(ptr, NT_S390_PREFIX, &sa->pref_reg,
+                        sizeof(sa->pref_reg), KEXEC_CORE_NOTE_NAME);
+}
+
+/*
+ * Fill ELF notes for one CPU with save area registers
+ */
+void *fill_cpu_elf_notes(void *ptr, struct save_area *sa)
+{
+       ptr = nt_prstatus(ptr, sa);
+       ptr = nt_fpregset(ptr, sa);
+       ptr = nt_s390_timer(ptr, sa);
+       ptr = nt_s390_tod_cmp(ptr, sa);
+       ptr = nt_s390_tod_preg(ptr, sa);
+       ptr = nt_s390_ctrs(ptr, sa);
+       ptr = nt_s390_prefix(ptr, sa);
+       return ptr;
+}
+
+/*
+ * Initialize prpsinfo note (new kernel)
+ */
+static void *nt_prpsinfo(void *ptr)
+{
+       struct elf_prpsinfo prpsinfo;
+
+       memset(&prpsinfo, 0, sizeof(prpsinfo));
+       prpsinfo.pr_sname = 'R';
+       strcpy(prpsinfo.pr_fname, "vmlinux");
+       return nt_init(ptr, NT_PRPSINFO, &prpsinfo, sizeof(prpsinfo),
+                      KEXEC_CORE_NOTE_NAME);
+}
+
+/*
+ * Initialize vmcoreinfo note (new kernel)
+ */
+static void *nt_vmcoreinfo(void *ptr)
+{
+       char nt_name[11], *vmcoreinfo;
+       Elf64_Nhdr note;
+       void *addr;
+
+       if (copy_from_oldmem(&addr, &S390_lowcore.vmcore_info, sizeof(addr)))
+               return ptr;
+       memset(nt_name, 0, sizeof(nt_name));
+       if (copy_from_oldmem(&note, addr, sizeof(note)))
+               return ptr;
+       if (copy_from_oldmem(nt_name, addr + sizeof(note), sizeof(nt_name) - 1))
+               return ptr;
+       if (strcmp(nt_name, "VMCOREINFO") != 0)
+               return ptr;
+       vmcoreinfo = kzalloc_panic(note.n_descsz + 1);
+       if (copy_from_oldmem(vmcoreinfo, addr + 24, note.n_descsz))
+               return ptr;
+       vmcoreinfo[note.n_descsz + 1] = 0;
+       return nt_init(ptr, 0, vmcoreinfo, note.n_descsz, "VMCOREINFO");
+}
+
+/*
+ * Initialize ELF header (new kernel)
+ */
+static void *ehdr_init(Elf64_Ehdr *ehdr, int mem_chunk_cnt)
+{
+       memset(ehdr, 0, sizeof(*ehdr));
+       memcpy(ehdr->e_ident, ELFMAG, SELFMAG);
+       ehdr->e_ident[EI_CLASS] = ELFCLASS64;
+       ehdr->e_ident[EI_DATA] = ELFDATA2MSB;
+       ehdr->e_ident[EI_VERSION] = EV_CURRENT;
+       memset(ehdr->e_ident + EI_PAD, 0, EI_NIDENT - EI_PAD);
+       ehdr->e_type = ET_CORE;
+       ehdr->e_machine = EM_S390;
+       ehdr->e_version = EV_CURRENT;
+       ehdr->e_phoff = sizeof(Elf64_Ehdr);
+       ehdr->e_ehsize = sizeof(Elf64_Ehdr);
+       ehdr->e_phentsize = sizeof(Elf64_Phdr);
+       ehdr->e_phnum = mem_chunk_cnt + 1;
+       return ehdr + 1;
+}
+
+/*
+ * Return CPU count for ELF header (new kernel)
+ */
+static int get_cpu_cnt(void)
+{
+       int i, cpus = 0;
+
+       for (i = 0; zfcpdump_save_areas[i]; i++) {
+               if (zfcpdump_save_areas[i]->pref_reg == 0)
+                       continue;
+               cpus++;
+       }
+       return cpus;
+}
+
+/*
+ * Return memory chunk count for ELF header (new kernel)
+ */
+static int get_mem_chunk_cnt(void)
+{
+       struct mem_chunk *chunk_array, *mem_chunk;
+       int i, cnt = 0;
+
+       chunk_array = get_memory_layout();
+       for (i = 0; i < MEMORY_CHUNKS; i++) {
+               mem_chunk = &chunk_array[i];
+               if (chunk_array[i].type != CHUNK_READ_WRITE &&
+                   chunk_array[i].type != CHUNK_READ_ONLY)
+                       continue;
+               if (mem_chunk->size == 0)
+                       continue;
+               cnt++;
+       }
+       kfree(chunk_array);
+       return cnt;
+}
+
+/*
+ * Relocate pointer in order to allow vmcore code access the data
+ */
+static inline unsigned long relocate(unsigned long addr)
+{
+       return OLDMEM_BASE + addr;
+}
+
+/*
+ * Initialize ELF loads (new kernel)
+ */
+static int loads_init(Elf64_Phdr *phdr, u64 loads_offset)
+{
+       struct mem_chunk *chunk_array, *mem_chunk;
+       int i;
+
+       chunk_array = get_memory_layout();
+       for (i = 0; i < MEMORY_CHUNKS; i++) {
+               mem_chunk = &chunk_array[i];
+               if (mem_chunk->size == 0)
+                       break;
+               if (chunk_array[i].type != CHUNK_READ_WRITE &&
+                   chunk_array[i].type != CHUNK_READ_ONLY)
+                       continue;
+               else
+                       phdr->p_filesz = mem_chunk->size;
+               phdr->p_type = PT_LOAD;
+               phdr->p_offset = mem_chunk->addr;
+               phdr->p_vaddr = mem_chunk->addr;
+               phdr->p_paddr = mem_chunk->addr;
+               phdr->p_memsz = mem_chunk->size;
+               phdr->p_flags = PF_R | PF_W | PF_X;
+               phdr->p_align = PAGE_SIZE;
+               phdr++;
+       }
+       kfree(chunk_array);
+       return i;
+}
+
+/*
+ * Initialize notes (new kernel)
+ */
+static void *notes_init(Elf64_Phdr *phdr, void *ptr, u64 notes_offset)
+{
+       struct save_area *sa;
+       void *ptr_start = ptr;
+       int i;
+
+       ptr = nt_prpsinfo(ptr);
+
+       for (i = 0; zfcpdump_save_areas[i]; i++) {
+               sa = zfcpdump_save_areas[i];
+               if (sa->pref_reg == 0)
+                       continue;
+               ptr = fill_cpu_elf_notes(ptr, sa);
+       }
+       ptr = nt_vmcoreinfo(ptr);
+       memset(phdr, 0, sizeof(*phdr));
+       phdr->p_type = PT_NOTE;
+       phdr->p_offset = relocate(notes_offset);
+       phdr->p_filesz = (unsigned long) PTR_SUB(ptr, ptr_start);
+       phdr->p_memsz = phdr->p_filesz;
+       return ptr;
+}
+
+/*
+ * Create ELF core header (new kernel)
+ */
+static void s390_elf_corehdr_create(char **elfcorebuf, size_t *elfcorebuf_sz)
+{
+       Elf64_Phdr *phdr_notes, *phdr_loads;
+       int mem_chunk_cnt;
+       void *ptr, *hdr;
+       u32 alloc_size;
+       u64 hdr_off;
+
+       mem_chunk_cnt = get_mem_chunk_cnt();
+
+       alloc_size = 0x1000 + get_cpu_cnt() * 0x300 +
+               mem_chunk_cnt * sizeof(Elf64_Phdr);
+       hdr = kzalloc_panic(alloc_size);
+       /* Init elf header */
+       ptr = ehdr_init(hdr, mem_chunk_cnt);
+       /* Init program headers */
+       phdr_notes = ptr;
+       ptr = PTR_ADD(ptr, sizeof(Elf64_Phdr));
+       phdr_loads = ptr;
+       ptr = PTR_ADD(ptr, sizeof(Elf64_Phdr) * mem_chunk_cnt);
+       /* Init notes */
+       hdr_off = PTR_DIFF(ptr, hdr);
+       ptr = notes_init(phdr_notes, ptr, ((unsigned long) hdr) + hdr_off);
+       /* Init loads */
+       hdr_off = PTR_DIFF(ptr, hdr);
+       loads_init(phdr_loads, ((unsigned long) hdr) + hdr_off);
+       *elfcorebuf_sz = hdr_off;
+       *elfcorebuf = (void *) relocate((unsigned long) hdr);
+       BUG_ON(*elfcorebuf_sz > alloc_size);
+}
+
+/*
+ * Create kdump ELF core header in new kernel, if it has not been passed via
+ * the "elfcorehdr" kernel parameter
+ */
+static int setup_kdump_elfcorehdr(void)
+{
+       size_t elfcorebuf_sz;
+       char *elfcorebuf;
+
+       if (!OLDMEM_BASE || is_kdump_kernel())
+               return -EINVAL;
+       s390_elf_corehdr_create(&elfcorebuf, &elfcorebuf_sz);
+       elfcorehdr_addr = (unsigned long long) elfcorebuf;
+       elfcorehdr_size = elfcorebuf_sz;
+       return 0;
+}
+
+subsys_initcall(setup_kdump_elfcorehdr);
index f297456dba7a9eb3282fe0377097e99f97a488d0..37394b3413e2776dfd24586f0578045e488bd054 100644 (file)
@@ -252,7 +252,7 @@ static noinline __init void setup_lowcore_early(void)
 {
        psw_t psw;
 
-       psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
+       psw.mask = PSW_MASK_BASE | PSW_DEFAULT_KEY | PSW_MASK_EA | PSW_MASK_BA;
        psw.addr = PSW_ADDR_AMODE | (unsigned long) s390_base_ext_handler;
        S390_lowcore.external_new_psw = psw;
        psw.addr = PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler;
index 02ec8fe7d03fe575c3969e14b750b3a6bf81c0b6..b13157057e027127be5c82f37bc0531f5b1204de 100644 (file)
@@ -43,16 +43,15 @@ SP_R13           =  STACK_FRAME_OVERHEAD + __PT_GPRS + 52
 SP_R14      =  STACK_FRAME_OVERHEAD + __PT_GPRS + 56
 SP_R15      =  STACK_FRAME_OVERHEAD + __PT_GPRS + 60
 SP_ORIG_R2   = STACK_FRAME_OVERHEAD + __PT_ORIG_GPR2
-SP_ILC      =  STACK_FRAME_OVERHEAD + __PT_ILC
-SP_SVCNR     = STACK_FRAME_OVERHEAD + __PT_SVCNR
+SP_SVC_CODE  = STACK_FRAME_OVERHEAD + __PT_SVC_CODE
 SP_SIZE      = STACK_FRAME_OVERHEAD + __PT_SIZE
 
 _TIF_WORK_SVC = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
-                _TIF_MCCK_PENDING | _TIF_RESTART_SVC | _TIF_PER_TRAP )
+                _TIF_MCCK_PENDING | _TIF_PER_TRAP )
 _TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
                 _TIF_MCCK_PENDING)
-_TIF_SYSCALL = (_TIF_SYSCALL_TRACE>>8 | _TIF_SYSCALL_AUDIT>>8 | \
-               _TIF_SECCOMP>>8 | _TIF_SYSCALL_TRACEPOINT>>8)
+_TIF_TRACE    = (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | \
+                _TIF_SYSCALL_TRACEPOINT)
 
 STACK_SHIFT = PAGE_SHIFT + THREAD_ORDER
 STACK_SIZE  = 1 << STACK_SHIFT
@@ -228,9 +227,10 @@ ENTRY(system_call)
 sysc_saveall:
        SAVE_ALL_SVC __LC_SVC_OLD_PSW,__LC_SAVE_AREA
        CREATE_STACK_FRAME __LC_SAVE_AREA
-       mvc     SP_PSW(8,%r15),__LC_SVC_OLD_PSW
-       mvc     SP_ILC(4,%r15),__LC_SVC_ILC
        l       %r12,__LC_THREAD_INFO   # load pointer to thread_info struct
+       mvc     SP_PSW(8,%r15),__LC_SVC_OLD_PSW
+       mvc     SP_SVC_CODE(4,%r15),__LC_SVC_ILC
+       oi      __TI_flags+3(%r12),_TIF_SYSCALL
 sysc_vtime:
        UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
 sysc_stime:
@@ -239,17 +239,17 @@ sysc_update:
        mvc     __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
 sysc_do_svc:
        xr      %r7,%r7
-       icm     %r7,3,SP_SVCNR(%r15)    # load svc number and test for svc 0
+       icm     %r7,3,SP_SVC_CODE+2(%r15)# load svc number and test for svc 0
        bnz     BASED(sysc_nr_ok)       # svc number > 0
        # svc 0: system call number in %r1
        cl      %r1,BASED(.Lnr_syscalls)
        bnl     BASED(sysc_nr_ok)
-       sth     %r1,SP_SVCNR(%r15)
+       sth     %r1,SP_SVC_CODE+2(%r15)
        lr      %r7,%r1           # copy svc number to %r7
 sysc_nr_ok:
        sll     %r7,2             # svc number *4
        l       %r10,BASED(.Lsysc_table)
-       tm      __TI_flags+2(%r12),_TIF_SYSCALL
+       tm      __TI_flags+2(%r12),_TIF_TRACE >> 8
        mvc     SP_ARGS(4,%r15),SP_R7(%r15)
        l       %r8,0(%r7,%r10)   # get system call addr.
        bnz     BASED(sysc_tracesys)
@@ -259,23 +259,19 @@ sysc_nr_ok:
 sysc_return:
        LOCKDEP_SYS_EXIT
 sysc_tif:
+       tm      SP_PSW+1(%r15),0x01     # returning to user ?
+       bno     BASED(sysc_restore)
        tm      __TI_flags+3(%r12),_TIF_WORK_SVC
        bnz     BASED(sysc_work)  # there is work to do (signals etc.)
+       ni      __TI_flags+3(%r12),255-_TIF_SYSCALL
 sysc_restore:
        RESTORE_ALL __LC_RETURN_PSW,1
 sysc_done:
 
-#
-# There is work to do, but first we need to check if we return to userspace.
-#
-sysc_work:
-       tm      SP_PSW+1(%r15),0x01     # returning to user ?
-       bno     BASED(sysc_restore)
-
 #
 # One of the work bits is on. Find out which one.
 #
-sysc_work_tif:
+sysc_work:
        tm      __TI_flags+3(%r12),_TIF_MCCK_PENDING
        bo      BASED(sysc_mcck_pending)
        tm      __TI_flags+3(%r12),_TIF_NEED_RESCHED
@@ -284,8 +280,6 @@ sysc_work_tif:
        bo      BASED(sysc_sigpending)
        tm      __TI_flags+3(%r12),_TIF_NOTIFY_RESUME
        bo      BASED(sysc_notify_resume)
-       tm      __TI_flags+3(%r12),_TIF_RESTART_SVC
-       bo      BASED(sysc_restart)
        tm      __TI_flags+3(%r12),_TIF_PER_TRAP
        bo      BASED(sysc_singlestep)
        b       BASED(sysc_return)      # beware of critical section cleanup
@@ -314,11 +308,14 @@ sysc_sigpending:
        la      %r2,SP_PTREGS(%r15)     # load pt_regs
        l       %r1,BASED(.Ldo_signal)
        basr    %r14,%r1                # call do_signal
-       tm      __TI_flags+3(%r12),_TIF_RESTART_SVC
-       bo      BASED(sysc_restart)
-       tm      __TI_flags+3(%r12),_TIF_PER_TRAP
-       bo      BASED(sysc_singlestep)
-       b       BASED(sysc_return)
+       tm      __TI_flags+3(%r12),_TIF_SYSCALL
+       bno     BASED(sysc_return)
+       lm      %r2,%r6,SP_R2(%r15)     # load svc arguments
+       xr      %r7,%r7                 # svc 0 returns -ENOSYS
+       clc     SP_SVC_CODE+2(2,%r15),BASED(.Lnr_syscalls+2)
+       bnl     BASED(sysc_nr_ok)       # invalid svc number -> do svc 0
+       icm     %r7,3,SP_SVC_CODE+2(%r15)# load new svc number
+       b       BASED(sysc_nr_ok)       # restart svc
 
 #
 # _TIF_NOTIFY_RESUME is set, call do_notify_resume
@@ -329,24 +326,11 @@ sysc_notify_resume:
        la      %r14,BASED(sysc_return)
        br      %r1                     # call do_notify_resume
 
-
-#
-# _TIF_RESTART_SVC is set, set up registers and restart svc
-#
-sysc_restart:
-       ni      __TI_flags+3(%r12),255-_TIF_RESTART_SVC # clear TIF_RESTART_SVC
-       l       %r7,SP_R2(%r15)         # load new svc number
-       mvc     SP_R2(4,%r15),SP_ORIG_R2(%r15) # restore first argument
-       lm      %r2,%r6,SP_R2(%r15)     # load svc arguments
-       sth     %r7,SP_SVCNR(%r15)
-       b       BASED(sysc_nr_ok)       # restart svc
-
 #
 # _TIF_PER_TRAP is set, call do_per_trap
 #
 sysc_singlestep:
-       ni      __TI_flags+3(%r12),255-_TIF_PER_TRAP # clear TIF_PER_TRAP
-       xc      SP_SVCNR(2,%r15),SP_SVCNR(%r15)         # clear svc number
+       ni      __TI_flags+3(%r12),255-(_TIF_SYSCALL | _TIF_PER_TRAP)
        la      %r2,SP_PTREGS(%r15)     # address of register-save area
        l       %r1,BASED(.Lhandle_per) # load adr. of per handler
        la      %r14,BASED(sysc_return) # load adr. of system return
@@ -361,7 +345,7 @@ sysc_tracesys:
        la      %r2,SP_PTREGS(%r15)     # load pt_regs
        la      %r3,0
        xr      %r0,%r0
-       icm     %r0,3,SP_SVCNR(%r15)
+       icm     %r0,3,SP_SVC_CODE(%r15)
        st      %r0,SP_R2(%r15)
        basr    %r14,%r1
        cl      %r2,BASED(.Lnr_syscalls)
@@ -376,7 +360,7 @@ sysc_tracego:
        basr    %r14,%r8                # call sys_xxx
        st      %r2,SP_R2(%r15)         # store return value
 sysc_tracenogo:
-       tm      __TI_flags+2(%r12),_TIF_SYSCALL
+       tm      __TI_flags+2(%r12),_TIF_TRACE >> 8
        bz      BASED(sysc_return)
        l       %r1,BASED(.Ltrace_exit)
        la      %r2,SP_PTREGS(%r15)     # load pt_regs
@@ -454,7 +438,6 @@ ENTRY(pgm_check_handler)
        bnz     BASED(pgm_per)          # got per exception -> special case
        SAVE_ALL_PGM __LC_PGM_OLD_PSW,__LC_SAVE_AREA
        CREATE_STACK_FRAME __LC_SAVE_AREA
-       xc      SP_ILC(4,%r15),SP_ILC(%r15)
        mvc     SP_PSW(8,%r15),__LC_PGM_OLD_PSW
        l       %r12,__LC_THREAD_INFO   # load pointer to thread_info struct
        tm      SP_PSW+1(%r15),0x01     # interrupting from user ?
@@ -530,9 +513,10 @@ pgm_exit2:
 pgm_svcper:
        SAVE_ALL_PGM __LC_SVC_OLD_PSW,__LC_SAVE_AREA
        CREATE_STACK_FRAME __LC_SAVE_AREA
-       mvc     SP_PSW(8,%r15),__LC_SVC_OLD_PSW
-       mvc     SP_ILC(4,%r15),__LC_SVC_ILC
        l       %r12,__LC_THREAD_INFO   # load pointer to thread_info struct
+       mvc     SP_PSW(8,%r15),__LC_SVC_OLD_PSW
+       mvc     SP_SVC_CODE(4,%r15),__LC_SVC_ILC
+       oi      __TI_flags+3(%r12),(_TIF_SYSCALL | _TIF_PER_TRAP)
        UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
        UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
        mvc     __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
@@ -540,7 +524,6 @@ pgm_svcper:
        mvc     __THREAD_per_cause(2,%r8),__LC_PER_CAUSE
        mvc     __THREAD_per_address(4,%r8),__LC_PER_ADDRESS
        mvc     __THREAD_per_paid(1,%r8),__LC_PER_PAID
-       oi      __TI_flags+3(%r12),_TIF_PER_TRAP # set TIF_PER_TRAP
        stosm   __SF_EMPTY(%r15),0x03   # reenable interrupts
        lm      %r2,%r6,SP_R2(%r15)     # load svc arguments
        b       BASED(sysc_do_svc)
@@ -550,7 +533,6 @@ pgm_svcper:
 #
 kernel_per:
        REENABLE_IRQS
-       xc      SP_SVCNR(2,%r15),SP_SVCNR(%r15)
        la      %r2,SP_PTREGS(%r15)     # address of register-save area
        l       %r1,BASED(.Lhandle_per) # load adr. of per handler
        basr    %r14,%r1                # branch to do_single_step
@@ -853,13 +835,13 @@ restart_go:
 # PSW restart interrupt handler
 #
 ENTRY(psw_restart_int_handler)
-       st      %r15,__LC_SAVE_AREA_64(%r0)     # save r15
+       st      %r15,__LC_SAVE_AREA+48(%r0)     # save r15
        basr    %r15,0
 0:     l       %r15,.Lrestart_stack-0b(%r15)   # load restart stack
        l       %r15,0(%r15)
        ahi     %r15,-SP_SIZE                   # make room for pt_regs
        stm     %r0,%r14,SP_R0(%r15)            # store gprs %r0-%r14 to stack
-       mvc     SP_R15(4,%r15),__LC_SAVE_AREA_64(%r0)# store saved %r15 to stack
+       mvc     SP_R15(4,%r15),__LC_SAVE_AREA+48(%r0)# store saved %r15 to stack
        mvc     SP_PSW(8,%r15),__LC_RST_OLD_PSW(%r0) # store restart old psw
        xc      __SF_BACKCHAIN(4,%r15),__SF_BACKCHAIN(%r15) # set backchain to 0
        basr    %r14,0
@@ -965,9 +947,11 @@ cleanup_system_call:
        s       %r15,BASED(.Lc_spsize)  # make room for registers & psw
        st      %r15,12(%r12)
        CREATE_STACK_FRAME __LC_SAVE_AREA
-       mvc     SP_PSW(8,%r15),__LC_SVC_OLD_PSW
-       mvc     SP_ILC(4,%r15),__LC_SVC_ILC
        mvc     0(4,%r12),__LC_THREAD_INFO
+       l       %r12,__LC_THREAD_INFO
+       mvc     SP_PSW(8,%r15),__LC_SVC_OLD_PSW
+       mvc     SP_SVC_CODE(4,%r15),__LC_SVC_ILC
+       oi      __TI_flags+3(%r12),_TIF_SYSCALL
 cleanup_vtime:
        clc     __LC_RETURN_PSW+4(4),BASED(cleanup_system_call_insn+12)
        bhe     BASED(cleanup_stime)
index 66729eb7bbc5458a5fb4ed18d15882d92b59a529..ef8fb1d6e8d72ed51ebac3906456c9eef95e5166 100644 (file)
@@ -5,24 +5,33 @@
 #include <linux/signal.h>
 #include <asm/ptrace.h>
 
+
+extern void (*pgm_check_table[128])(struct pt_regs *, long, unsigned long);
+extern void *restart_stack;
+
+asmlinkage long do_syscall_trace_enter(struct pt_regs *regs);
+asmlinkage void do_syscall_trace_exit(struct pt_regs *regs);
+
 void do_protection_exception(struct pt_regs *, long, unsigned long);
 void do_dat_exception(struct pt_regs *, long, unsigned long);
 void do_asce_exception(struct pt_regs *, long, unsigned long);
 
-extern int sysctl_userprocess_debug;
-
 void do_per_trap(struct pt_regs *regs);
 void syscall_trace(struct pt_regs *regs, int entryexit);
 void kernel_stack_overflow(struct pt_regs * regs);
 void do_signal(struct pt_regs *regs);
 int handle_signal32(unsigned long sig, struct k_sigaction *ka,
                    siginfo_t *info, sigset_t *oldset, struct pt_regs *regs);
+void do_notify_resume(struct pt_regs *regs);
 
 void do_extint(struct pt_regs *regs, unsigned int, unsigned int, unsigned long);
+void do_restart(void);
 int __cpuinit start_secondary(void *cpuvoid);
 void __init startup_init(void);
 void die(const char * str, struct pt_regs * regs, long err);
 
+void __init time_init(void);
+
 struct s390_mmap_arg_struct;
 struct fadvise64_64_args;
 struct old_sigaction;
index 713da07605389ffc3d9c4c137c01e268437581e1..83a93747e2fd42f133ea9a165829243a6c1b2b24 100644 (file)
@@ -43,19 +43,18 @@ SP_R13           =  STACK_FRAME_OVERHEAD + __PT_GPRS + 104
 SP_R14      =  STACK_FRAME_OVERHEAD + __PT_GPRS + 112
 SP_R15      =  STACK_FRAME_OVERHEAD + __PT_GPRS + 120
 SP_ORIG_R2   = STACK_FRAME_OVERHEAD + __PT_ORIG_GPR2
-SP_ILC      =  STACK_FRAME_OVERHEAD + __PT_ILC
-SP_SVCNR      =        STACK_FRAME_OVERHEAD + __PT_SVCNR
+SP_SVC_CODE  = STACK_FRAME_OVERHEAD + __PT_SVC_CODE
 SP_SIZE      = STACK_FRAME_OVERHEAD + __PT_SIZE
 
 STACK_SHIFT = PAGE_SHIFT + THREAD_ORDER
 STACK_SIZE  = 1 << STACK_SHIFT
 
 _TIF_WORK_SVC = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
-                _TIF_MCCK_PENDING | _TIF_RESTART_SVC | _TIF_PER_TRAP )
+                _TIF_MCCK_PENDING | _TIF_PER_TRAP )
 _TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
                 _TIF_MCCK_PENDING)
-_TIF_SYSCALL = (_TIF_SYSCALL_TRACE>>8 | _TIF_SYSCALL_AUDIT>>8 | \
-               _TIF_SECCOMP>>8 | _TIF_SYSCALL_TRACEPOINT>>8)
+_TIF_TRACE    = (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | \
+                _TIF_SYSCALL_TRACEPOINT)
 _TIF_EXIT_SIE = (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_MCCK_PENDING)
 
 #define BASED(name) name-system_call(%r13)
@@ -249,9 +248,10 @@ ENTRY(system_call)
 sysc_saveall:
        SAVE_ALL_SVC __LC_SVC_OLD_PSW,__LC_SAVE_AREA
        CREATE_STACK_FRAME __LC_SAVE_AREA
-       mvc     SP_PSW(16,%r15),__LC_SVC_OLD_PSW
-       mvc     SP_ILC(4,%r15),__LC_SVC_ILC
        lg      %r12,__LC_THREAD_INFO   # load pointer to thread_info struct
+       mvc     SP_PSW(16,%r15),__LC_SVC_OLD_PSW
+       mvc     SP_SVC_CODE(4,%r15),__LC_SVC_ILC
+       oi      __TI_flags+7(%r12),_TIF_SYSCALL
 sysc_vtime:
        UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
 sysc_stime:
@@ -260,14 +260,14 @@ sysc_update:
        mvc     __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
        LAST_BREAK
 sysc_do_svc:
-       llgh    %r7,SP_SVCNR(%r15)
+       llgh    %r7,SP_SVC_CODE+2(%r15)
        slag    %r7,%r7,2       # shift and test for svc 0
        jnz     sysc_nr_ok
        # svc 0: system call number in %r1
        llgfr   %r1,%r1         # clear high word in r1
        cghi    %r1,NR_syscalls
        jnl     sysc_nr_ok
-       sth     %r1,SP_SVCNR(%r15)
+       sth     %r1,SP_SVC_CODE+2(%r15)
        slag    %r7,%r1,2       # shift and test for svc 0
 sysc_nr_ok:
        larl    %r10,sys_call_table
@@ -277,7 +277,7 @@ sysc_nr_ok:
        larl    %r10,sys_call_table_emu  # use 31 bit emulation system calls
 sysc_noemu:
 #endif
-       tm      __TI_flags+6(%r12),_TIF_SYSCALL
+       tm      __TI_flags+6(%r12),_TIF_TRACE >> 8
        mvc     SP_ARGS(8,%r15),SP_R7(%r15)
        lgf     %r8,0(%r7,%r10) # load address of system call routine
        jnz     sysc_tracesys
@@ -287,23 +287,19 @@ sysc_noemu:
 sysc_return:
        LOCKDEP_SYS_EXIT
 sysc_tif:
+       tm      SP_PSW+1(%r15),0x01     # returning to user ?
+       jno     sysc_restore
        tm      __TI_flags+7(%r12),_TIF_WORK_SVC
        jnz     sysc_work       # there is work to do (signals etc.)
+       ni      __TI_flags+7(%r12),255-_TIF_SYSCALL
 sysc_restore:
        RESTORE_ALL __LC_RETURN_PSW,1
 sysc_done:
 
-#
-# There is work to do, but first we need to check if we return to userspace.
-#
-sysc_work:
-       tm      SP_PSW+1(%r15),0x01     # returning to user ?
-       jno     sysc_restore
-
 #
 # One of the work bits is on. Find out which one.
 #
-sysc_work_tif:
+sysc_work:
        tm      __TI_flags+7(%r12),_TIF_MCCK_PENDING
        jo      sysc_mcck_pending
        tm      __TI_flags+7(%r12),_TIF_NEED_RESCHED
@@ -312,8 +308,6 @@ sysc_work_tif:
        jo      sysc_sigpending
        tm      __TI_flags+7(%r12),_TIF_NOTIFY_RESUME
        jo      sysc_notify_resume
-       tm      __TI_flags+7(%r12),_TIF_RESTART_SVC
-       jo      sysc_restart
        tm      __TI_flags+7(%r12),_TIF_PER_TRAP
        jo      sysc_singlestep
        j       sysc_return             # beware of critical section cleanup
@@ -339,11 +333,15 @@ sysc_sigpending:
        ni      __TI_flags+7(%r12),255-_TIF_PER_TRAP # clear TIF_PER_TRAP
        la      %r2,SP_PTREGS(%r15)     # load pt_regs
        brasl   %r14,do_signal          # call do_signal
-       tm      __TI_flags+7(%r12),_TIF_RESTART_SVC
-       jo      sysc_restart
-       tm      __TI_flags+7(%r12),_TIF_PER_TRAP
-       jo      sysc_singlestep
-       j       sysc_return
+       tm      __TI_flags+7(%r12),_TIF_SYSCALL
+       jno     sysc_return
+       lmg     %r2,%r6,SP_R2(%r15)     # load svc arguments
+       lghi    %r7,0                   # svc 0 returns -ENOSYS
+       lh      %r1,SP_SVC_CODE+2(%r15) # load new svc number
+       cghi    %r1,NR_syscalls
+       jnl     sysc_nr_ok              # invalid svc number -> do svc 0
+       slag    %r7,%r1,2
+       j       sysc_nr_ok              # restart svc
 
 #
 # _TIF_NOTIFY_RESUME is set, call do_notify_resume
@@ -353,24 +351,11 @@ sysc_notify_resume:
        larl    %r14,sysc_return
        jg      do_notify_resume        # call do_notify_resume
 
-#
-# _TIF_RESTART_SVC is set, set up registers and restart svc
-#
-sysc_restart:
-       ni      __TI_flags+7(%r12),255-_TIF_RESTART_SVC # clear TIF_RESTART_SVC
-       lg      %r7,SP_R2(%r15)         # load new svc number
-       mvc     SP_R2(8,%r15),SP_ORIG_R2(%r15) # restore first argument
-       lmg     %r2,%r6,SP_R2(%r15)     # load svc arguments
-       sth     %r7,SP_SVCNR(%r15)
-       slag    %r7,%r7,2
-       j       sysc_nr_ok              # restart svc
-
 #
 # _TIF_PER_TRAP is set, call do_per_trap
 #
 sysc_singlestep:
-       ni      __TI_flags+7(%r12),255-_TIF_PER_TRAP    # clear TIF_PER_TRAP
-       xc      SP_SVCNR(2,%r15),SP_SVCNR(%r15)         # clear svc number
+       ni      __TI_flags+7(%r12),255-(_TIF_SYSCALL | _TIF_PER_TRAP)
        la      %r2,SP_PTREGS(%r15)     # address of register-save area
        larl    %r14,sysc_return        # load adr. of system return
        jg      do_per_trap
@@ -382,7 +367,7 @@ sysc_singlestep:
 sysc_tracesys:
        la      %r2,SP_PTREGS(%r15)     # load pt_regs
        la      %r3,0
-       llgh    %r0,SP_SVCNR(%r15)
+       llgh    %r0,SP_SVC_CODE+2(%r15)
        stg     %r0,SP_R2(%r15)
        brasl   %r14,do_syscall_trace_enter
        lghi    %r0,NR_syscalls
@@ -397,7 +382,7 @@ sysc_tracego:
        basr    %r14,%r8                # call sys_xxx
        stg     %r2,SP_R2(%r15)         # store return value
 sysc_tracenogo:
-       tm      __TI_flags+6(%r12),_TIF_SYSCALL
+       tm      __TI_flags+6(%r12),_TIF_TRACE >> 8
        jz      sysc_return
        la      %r2,SP_PTREGS(%r15)     # load pt_regs
        larl    %r14,sysc_return        # return point is sysc_return
@@ -470,7 +455,6 @@ ENTRY(pgm_check_handler)
        jnz     pgm_per                  # got per exception -> special case
        SAVE_ALL_PGM __LC_PGM_OLD_PSW,__LC_SAVE_AREA
        CREATE_STACK_FRAME __LC_SAVE_AREA
-       xc      SP_ILC(4,%r15),SP_ILC(%r15)
        mvc     SP_PSW(16,%r15),__LC_PGM_OLD_PSW
        lg      %r12,__LC_THREAD_INFO   # load pointer to thread_info struct
        HANDLE_SIE_INTERCEPT
@@ -550,9 +534,10 @@ pgm_exit2:
 pgm_svcper:
        SAVE_ALL_PGM __LC_SVC_OLD_PSW,__LC_SAVE_AREA
        CREATE_STACK_FRAME __LC_SAVE_AREA
-       mvc     SP_PSW(16,%r15),__LC_SVC_OLD_PSW
-       mvc     SP_ILC(4,%r15),__LC_SVC_ILC
        lg      %r12,__LC_THREAD_INFO   # load pointer to thread_info struct
+       mvc     SP_PSW(16,%r15),__LC_SVC_OLD_PSW
+       mvc     SP_SVC_CODE(4,%r15),__LC_SVC_ILC
+       oi      __TI_flags+7(%r12),(_TIF_SYSCALL | _TIF_PER_TRAP)
        UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
        UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
        mvc     __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
@@ -561,7 +546,6 @@ pgm_svcper:
        mvc     __THREAD_per_cause(2,%r8),__LC_PER_CAUSE
        mvc     __THREAD_per_address(8,%r8),__LC_PER_ADDRESS
        mvc     __THREAD_per_paid(1,%r8),__LC_PER_PAID
-       oi      __TI_flags+7(%r12),_TIF_PER_TRAP # set TIF_PER_TRAP
        stosm   __SF_EMPTY(%r15),0x03   # reenable interrupts
        lmg     %r2,%r6,SP_R2(%r15)     # load svc arguments
        j       sysc_do_svc
@@ -571,7 +555,6 @@ pgm_svcper:
 #
 kernel_per:
        REENABLE_IRQS
-       xc      SP_SVCNR(2,%r15),SP_SVCNR(%r15) # clear svc number
        la      %r2,SP_PTREGS(%r15)     # address of register-save area
        brasl   %r14,do_per_trap
        j       pgm_exit
@@ -869,12 +852,12 @@ restart_go:
 # PSW restart interrupt handler
 #
 ENTRY(psw_restart_int_handler)
-       stg     %r15,__LC_SAVE_AREA_64(%r0)     # save r15
+       stg     %r15,__LC_SAVE_AREA+120(%r0)    # save r15
        larl    %r15,restart_stack              # load restart stack
        lg      %r15,0(%r15)
        aghi    %r15,-SP_SIZE                   # make room for pt_regs
        stmg    %r0,%r14,SP_R0(%r15)            # store gprs %r0-%r14 to stack
-       mvc     SP_R15(8,%r15),__LC_SAVE_AREA_64(%r0)# store saved %r15 to stack
+       mvc     SP_R15(8,%r15),__LC_SAVE_AREA+120(%r0)# store saved %r15 to stack
        mvc     SP_PSW(16,%r15),__LC_RST_OLD_PSW(%r0)# store restart old psw
        xc      __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15) # set backchain to 0
        brasl   %r14,do_restart
@@ -972,9 +955,11 @@ cleanup_system_call:
        stg     %r15,32(%r12)
        stg     %r11,0(%r12)
        CREATE_STACK_FRAME __LC_SAVE_AREA
-       mvc     SP_PSW(16,%r15),__LC_SVC_OLD_PSW
-       mvc     SP_ILC(4,%r15),__LC_SVC_ILC
        mvc     8(8,%r12),__LC_THREAD_INFO
+       lg      %r12,__LC_THREAD_INFO
+       mvc     SP_PSW(16,%r15),__LC_SVC_OLD_PSW
+       mvc     SP_SVC_CODE(4,%r15),__LC_SVC_ILC
+       oi      __TI_flags+7(%r12),_TIF_SYSCALL
 cleanup_vtime:
        clc     __LC_RETURN_PSW+8(8),BASED(cleanup_system_call_insn+24)
        jhe     cleanup_stime
@@ -1096,6 +1081,7 @@ sie_exit:
        lghi    %r2,0
        br      %r14
 sie_fault:
+       lctlg   %c1,%c1,__LC_USER_ASCE          # load primary asce
        lg      %r14,__LC_THREAD_INFO           # pointer thread_info struct
        ni      __TI_flags+6(%r14),255-(_TIF_SIE>>8)
        lg      %r14,__SF_EMPTY+8(%r15)         # load guest register save area
index 2d781bab37bbcefd69fd9af74e49a66ac0f42293..900068d2bf929d3222ed9f82aceaccc2edb18660 100644 (file)
@@ -449,10 +449,28 @@ ENTRY(start)
 #
        .org    0x10000
 ENTRY(startup)
+       j       .Lep_startup_normal
+       .org    0x10008
+#
+# This is a list of s390 kernel entry points. At address 0x1000f the number of
+# valid entry points is stored.
+#
+# IMPORTANT: Do not change this table, it is s390 kernel ABI!
+#
+       .ascii  "S390EP"
+       .byte   0x00,0x01
+#
+# kdump startup-code at 0x10010, running in 64 bit absolute addressing mode
+#
+       .org    0x10010
+ENTRY(startup_kdump)
+       j       .Lep_startup_kdump
+.Lep_startup_normal:
        basr    %r13,0                  # get base
 .LPG0:
        xc      0x200(256),0x200        # partially clear lowcore
        xc      0x300(256),0x300
+       xc      0xe00(256),0xe00
        stck    __LC_LAST_UPDATE_CLOCK
        spt     5f-.LPG0(%r13)
        mvc     __LC_LAST_UPDATE_TIMER(8),5f-.LPG0(%r13)
@@ -534,6 +552,8 @@ ENTRY(startup)
        .align  8
 5:     .long   0x7fffffff,0xffffffff
 
+#include "head_kdump.S"
+
 #
 # params at 10400 (setup.h)
 #
@@ -541,6 +561,8 @@ ENTRY(startup)
        .long   0,0                     # IPL_DEVICE
        .long   0,0                     # INITRD_START
        .long   0,0                     # INITRD_SIZE
+       .long   0,0                     # OLDMEM_BASE
+       .long   0,0                     # OLDMEM_SIZE
 
        .org    COMMAND_LINE
        .byte   "root=/dev/ram0 ro"
index f21954b44dc1ec1c5a80249b855bd4214cd528d8..d3f1ab7d90ada12d5a7a4a59bc98bcfa245c3c71 100644 (file)
@@ -92,7 +92,7 @@ ENTRY(_stext)
 .LPG3:
 # check control registers
        stctl   %c0,%c15,0(%r15)
-       oi      2(%r15),0x40            # enable sigp emergency signal
+       oi      2(%r15),0x60            # enable sigp emergency & external call
        oi      0(%r15),0x10            # switch on low address protection
        lctl    %c0,%c15,0(%r15)
 
index ae5d492b069e3c92396395dc8bf6395f4785b420..99348c0eaa4105a8e8e000be3182911da58b61a7 100644 (file)
@@ -90,7 +90,7 @@ ENTRY(_stext)
 .LPG3:
 # check control registers
        stctg   %c0,%c15,0(%r15)
-       oi      6(%r15),0x40            # enable sigp emergency signal
+       oi      6(%r15),0x60            # enable sigp emergency & external call
        oi      4(%r15),0x10            # switch on low address proctection
        lctlg   %c0,%c15,0(%r15)
 
diff --git a/arch/s390/kernel/head_kdump.S b/arch/s390/kernel/head_kdump.S
new file mode 100644 (file)
index 0000000..e1ac389
--- /dev/null
@@ -0,0 +1,119 @@
+/*
+ * S390 kdump lowlevel functions (new kernel)
+ *
+ * Copyright IBM Corp. 2011
+ * Author(s): Michael Holzheu <holzheu@linux.vnet.ibm.com>
+ */
+
+#define DATAMOVER_ADDR 0x4000
+#define COPY_PAGE_ADDR 0x6000
+
+#ifdef CONFIG_CRASH_DUMP
+
+#
+# kdump entry (new kernel - not yet relocated)
+#
+# Note: This code has to be position independent
+#
+
+.align 2
+.Lep_startup_kdump:
+       lhi     %r1,2                           # mode 2 = esame (dump)
+       sigp    %r1,%r0,0x12                    # Switch to esame mode
+       sam64                                   # Switch to 64 bit addressing
+       basr    %r13,0
+.Lbase:
+       larl    %r2,.Lbase_addr                 # Check, if we have been
+       lg      %r2,0(%r2)                      # already relocated:
+       clgr    %r2,%r13                        #
+       jne     .Lrelocate                      # No : Start data mover
+       lghi    %r2,0                           # Yes: Start kdump kernel
+       brasl   %r14,startup_kdump_relocated
+
+.Lrelocate:
+       larl    %r4,startup
+       lg      %r2,0x418(%r4)                  # Get kdump base
+       lg      %r3,0x420(%r4)                  # Get kdump size
+
+       larl    %r10,.Lcopy_start               # Source of data mover
+       lghi    %r8,DATAMOVER_ADDR              # Target of data mover
+       mvc     0(256,%r8),0(%r10)              # Copy data mover code
+
+       agr     %r8,%r2                         # Copy data mover to
+       mvc     0(256,%r8),0(%r10)              # reserved mem
+
+       lghi    %r14,DATAMOVER_ADDR             # Jump to copied data mover
+       basr    %r14,%r14
+.Lbase_addr:
+       .quad   .Lbase
+
+#
+# kdump data mover code (runs at address DATAMOVER_ADDR)
+#
+# r2: kdump base address
+# r3: kdump size
+#
+.Lcopy_start:
+       basr    %r13,0                          # Base
+0:
+       lgr     %r11,%r2                        # Save kdump base address
+       lgr     %r12,%r2
+       agr     %r12,%r3                        # Compute kdump end address
+
+       lghi    %r5,0
+       lghi    %r10,COPY_PAGE_ADDR             # Load copy page address
+1:
+       mvc     0(256,%r10),0(%r5)              # Copy old kernel to tmp
+       mvc     0(256,%r5),0(%r11)              # Copy new kernel to old
+       mvc     0(256,%r11),0(%r10)             # Copy tmp to new
+       aghi    %r11,256
+       aghi    %r5,256
+       clgr    %r11,%r12
+       jl      1b
+
+       lg      %r14,.Lstartup_kdump-0b(%r13)
+       basr    %r14,%r14                       # Start relocated kernel
+.Lstartup_kdump:
+       .long   0x00000000,0x00000000 + startup_kdump_relocated
+.Lcopy_end:
+
+#
+# Startup of kdump (relocated new kernel)
+#
+.align 2
+startup_kdump_relocated:
+       basr    %r13,0
+0:
+       mvc     0(8,%r0),.Lrestart_psw-0b(%r13) # Setup restart PSW
+       mvc     464(16,%r0),.Lpgm_psw-0b(%r13)  # Setup pgm check PSW
+       lhi     %r1,1                           # Start new kernel
+       diag    %r1,%r1,0x308                   # with diag 308
+
+.Lno_diag308:                                  # No diag 308
+       sam31                                   # Switch to 31 bit addr mode
+       sr      %r1,%r1                         # Erase register r1
+       sr      %r2,%r2                         # Erase register r2
+       sigp    %r1,%r2,0x12                    # Switch to 31 bit arch mode
+       lpsw    0                               # Start new kernel...
+.align 8
+.Lrestart_psw:
+       .long   0x00080000,0x80000000 + startup
+.Lpgm_psw:
+       .quad   0x0000000180000000,0x0000000000000000 + .Lno_diag308
+#else
+.align 2
+.Lep_startup_kdump:
+#ifdef CONFIG_64BIT
+       larl    %r13,startup_kdump_crash
+       lpswe   0(%r13)
+.align 8
+startup_kdump_crash:
+       .quad   0x0002000080000000,0x0000000000000000 + startup_kdump_crash
+#else
+       basr    %r13,0
+0:     lpsw    startup_kdump_crash-0b(%r13)
+.align 8
+startup_kdump_crash:
+       .long   0x000a0000,0x00000000 + startup_kdump_crash
+#endif /* CONFIG_64BIT */
+#endif /* CONFIG_CRASH_DUMP */
index 48c710206366308270e70a846c268c9e5cc8ea9f..affa8e68124a18f6daad5ee18b03d4f8f0ce098e 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/ctype.h>
 #include <linux/fs.h>
 #include <linux/gfp.h>
+#include <linux/crash_dump.h>
 #include <asm/ipl.h>
 #include <asm/smp.h>
 #include <asm/setup.h>
@@ -26,6 +27,7 @@
 #include <asm/sclp.h>
 #include <asm/sigp.h>
 #include <asm/checksum.h>
+#include "entry.h"
 
 #define IPL_PARM_BLOCK_VERSION 0
 
@@ -275,8 +277,8 @@ static ssize_t ipl_type_show(struct kobject *kobj, struct kobj_attribute *attr,
 static struct kobj_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type);
 
 /* VM IPL PARM routines */
-size_t reipl_get_ascii_vmparm(char *dest, size_t size,
-                                  const struct ipl_parameter_block *ipb)
+static size_t reipl_get_ascii_vmparm(char *dest, size_t size,
+                                    const struct ipl_parameter_block *ipb)
 {
        int i;
        size_t len;
@@ -338,8 +340,8 @@ static size_t scpdata_length(const char* buf, size_t count)
        return count;
 }
 
-size_t reipl_append_ascii_scpdata(char *dest, size_t size,
-                                 const struct ipl_parameter_block *ipb)
+static size_t reipl_append_ascii_scpdata(char *dest, size_t size,
+                                        const struct ipl_parameter_block *ipb)
 {
        size_t count;
        size_t i;
@@ -1738,7 +1740,11 @@ static struct kobj_attribute on_restart_attr =
 
 void do_restart(void)
 {
+       smp_restart_with_online_cpu();
        smp_send_stop();
+#ifdef CONFIG_CRASH_DUMP
+       crash_kexec(NULL);
+#endif
        on_restart_trigger.action->fn(&on_restart_trigger);
        stop_run(&on_restart_trigger);
 }
@@ -2009,7 +2015,7 @@ static void do_reset_calls(void)
 
 u32 dump_prefix_page;
 
-void s390_reset_system(void)
+void s390_reset_system(void (*func)(void *), void *data)
 {
        struct _lowcore *lc;
 
@@ -2028,15 +2034,19 @@ void s390_reset_system(void)
        __ctl_clear_bit(0,28);
 
        /* Set new machine check handler */
-       S390_lowcore.mcck_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
+       S390_lowcore.mcck_new_psw.mask = psw_kernel_bits | PSW_MASK_DAT;
        S390_lowcore.mcck_new_psw.addr =
                PSW_ADDR_AMODE | (unsigned long) s390_base_mcck_handler;
 
        /* Set new program check handler */
-       S390_lowcore.program_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
+       S390_lowcore.program_new_psw.mask = psw_kernel_bits | PSW_MASK_DAT;
        S390_lowcore.program_new_psw.addr =
                PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler;
 
+       /* Store status at absolute zero */
+       store_status();
+
        do_reset_calls();
+       if (func)
+               func(data);
 }
-
index 1f4050d45f78766c8fc43cc54b628b873e079b38..b9a7fdd9c814c95060ae982edbb557cbd2e46a50 100644 (file)
@@ -33,7 +33,8 @@ static const struct irq_class intrclass_names[] = {
        {.name = "EXT" },
        {.name = "I/O" },
        {.name = "CLK", .desc = "[EXT] Clock Comparator" },
-       {.name = "IPI", .desc = "[EXT] Signal Processor" },
+       {.name = "EXC", .desc = "[EXT] External Call" },
+       {.name = "EMS", .desc = "[EXT] Emergency Signal" },
        {.name = "TMR", .desc = "[EXT] CPU Timer" },
        {.name = "TAL", .desc = "[EXT] Timing Alert" },
        {.name = "PFL", .desc = "[EXT] Pseudo Page Fault" },
@@ -42,8 +43,8 @@ static const struct irq_class intrclass_names[] = {
        {.name = "SCP", .desc = "[EXT] Service Call" },
        {.name = "IUC", .desc = "[EXT] IUCV" },
        {.name = "CPM", .desc = "[EXT] CPU Measurement" },
+       {.name = "CIO", .desc = "[I/O] Common I/O Layer Interrupt" },
        {.name = "QAI", .desc = "[I/O] QDIO Adapter Interrupt" },
-       {.name = "QDI", .desc = "[I/O] QDIO Interrupt" },
        {.name = "DAS", .desc = "[I/O] DASD" },
        {.name = "C15", .desc = "[I/O] 3215" },
        {.name = "C70", .desc = "[I/O] 3270" },
@@ -53,6 +54,7 @@ static const struct irq_class intrclass_names[] = {
        {.name = "CLW", .desc = "[I/O] CLAW" },
        {.name = "CTC", .desc = "[I/O] CTC" },
        {.name = "APB", .desc = "[I/O] AP Bus" },
+       {.name = "CSC", .desc = "[I/O] CHSC Subchannel" },
        {.name = "NMI", .desc = "[NMI] Machine Check" },
 };
 
index 1d05d669107c0ba89e4364a5b247b34d276ae0de..64b761aef004a29a33eec80f49cd26fc5ec7c7ec 100644 (file)
@@ -635,7 +635,7 @@ void __kprobes jprobe_return(void)
        asm volatile(".word 0x0002");
 }
 
-void __kprobes jprobe_return_end(void)
+static void __used __kprobes jprobe_return_end(void)
 {
        asm volatile("bcr 0,0");
 }
index b09b9c62573e7bb77c145670dbd3e0e777ea8cdd..3cd0f25ab015cc7ef7633f73ab528b2ae34185df 100644 (file)
@@ -1,10 +1,11 @@
 /*
  * arch/s390/kernel/machine_kexec.c
  *
- * Copyright IBM Corp. 2005,2006
+ * Copyright IBM Corp. 2005,2011
  *
  * Author(s): Rolf Adelsberger,
  *           Heiko Carstens <heiko.carstens@de.ibm.com>
+ *           Michael Holzheu <holzheu@linux.vnet.ibm.com>
  */
 
 #include <linux/device.h>
 #include <asm/smp.h>
 #include <asm/reset.h>
 #include <asm/ipl.h>
+#include <asm/diag.h>
+#include <asm/asm-offsets.h>
 
 typedef void (*relocate_kernel_t)(kimage_entry_t *, unsigned long);
 
 extern const unsigned char relocate_kernel[];
 extern const unsigned long long relocate_kernel_len;
 
+#ifdef CONFIG_CRASH_DUMP
+
+void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
+
+/*
+ * Create ELF notes for one CPU
+ */
+static void add_elf_notes(int cpu)
+{
+       struct save_area *sa = (void *) 4608 + store_prefix();
+       void *ptr;
+
+       memcpy((void *) (4608UL + sa->pref_reg), sa, sizeof(*sa));
+       ptr = (u64 *) per_cpu_ptr(crash_notes, cpu);
+       ptr = fill_cpu_elf_notes(ptr, sa);
+       memset(ptr, 0, sizeof(struct elf_note));
+}
+
+/*
+ * Store status of next available physical CPU
+ */
+static int store_status_next(int start_cpu, int this_cpu)
+{
+       struct save_area *sa = (void *) 4608 + store_prefix();
+       int cpu, rc;
+
+       for (cpu = start_cpu; cpu < 65536; cpu++) {
+               if (cpu == this_cpu)
+                       continue;
+               do {
+                       rc = raw_sigp(cpu, sigp_stop_and_store_status);
+               } while (rc == sigp_busy);
+               if (rc != sigp_order_code_accepted)
+                       continue;
+               if (sa->pref_reg)
+                       return cpu;
+       }
+       return -1;
+}
+
+/*
+ * Initialize CPU ELF notes
+ */
+void setup_regs(void)
+{
+       unsigned long sa = S390_lowcore.prefixreg_save_area + SAVE_AREA_BASE;
+       int cpu, this_cpu, phys_cpu = 0, first = 1;
+
+       this_cpu = stap();
+
+       if (!S390_lowcore.prefixreg_save_area)
+               first = 0;
+       for_each_online_cpu(cpu) {
+               if (first) {
+                       add_elf_notes(cpu);
+                       first = 0;
+                       continue;
+               }
+               phys_cpu = store_status_next(phys_cpu, this_cpu);
+               if (phys_cpu == -1)
+                       break;
+               add_elf_notes(cpu);
+               phys_cpu++;
+       }
+       /* Copy dump CPU store status info to absolute zero */
+       memcpy((void *) SAVE_AREA_BASE, (void *) sa, sizeof(struct save_area));
+}
+
+#endif
+
+/*
+ * Start kdump: We expect here that a store status has been done on our CPU
+ */
+static void __do_machine_kdump(void *image)
+{
+#ifdef CONFIG_CRASH_DUMP
+       int (*start_kdump)(int) = (void *)((struct kimage *) image)->start;
+
+       __load_psw_mask(PSW_MASK_BASE | PSW_DEFAULT_KEY | PSW_MASK_EA | PSW_MASK_BA);
+       setup_regs();
+       start_kdump(1);
+#endif
+}
+
+/*
+ * Check if kdump checksums are valid: We call purgatory with parameter "0"
+ */
+static int kdump_csum_valid(struct kimage *image)
+{
+#ifdef CONFIG_CRASH_DUMP
+       int (*start_kdump)(int) = (void *)image->start;
+       int rc;
+
+       __arch_local_irq_stnsm(0xfb); /* disable DAT */
+       rc = start_kdump(0);
+       __arch_local_irq_stosm(0x04); /* enable DAT */
+       return rc ? 0 : -EINVAL;
+#else
+       return -EINVAL;
+#endif
+}
+
+/*
+ * Map or unmap crashkernel memory
+ */
+static void crash_map_pages(int enable)
+{
+       unsigned long size = resource_size(&crashk_res);
+
+       BUG_ON(crashk_res.start % KEXEC_CRASH_MEM_ALIGN ||
+              size % KEXEC_CRASH_MEM_ALIGN);
+       if (enable)
+               vmem_add_mapping(crashk_res.start, size);
+       else
+               vmem_remove_mapping(crashk_res.start, size);
+}
+
+/*
+ * Map crashkernel memory
+ */
+void crash_map_reserved_pages(void)
+{
+       crash_map_pages(1);
+}
+
+/*
+ * Unmap crashkernel memory
+ */
+void crash_unmap_reserved_pages(void)
+{
+       crash_map_pages(0);
+}
+
+/*
+ * Give back memory to hypervisor before new kdump is loaded
+ */
+static int machine_kexec_prepare_kdump(void)
+{
+#ifdef CONFIG_CRASH_DUMP
+       if (MACHINE_IS_VM)
+               diag10_range(PFN_DOWN(crashk_res.start),
+                            PFN_DOWN(crashk_res.end - crashk_res.start + 1));
+       return 0;
+#else
+       return -EINVAL;
+#endif
+}
+
 int machine_kexec_prepare(struct kimage *image)
 {
        void *reboot_code_buffer;
@@ -35,6 +186,9 @@ int machine_kexec_prepare(struct kimage *image)
        if (ipl_flags & IPL_NSS_VALID)
                return -ENOSYS;
 
+       if (image->type == KEXEC_TYPE_CRASH)
+               return machine_kexec_prepare_kdump();
+
        /* We don't support anything but the default image type for now. */
        if (image->type != KEXEC_TYPE_DEFAULT)
                return -EINVAL;
@@ -51,27 +205,53 @@ void machine_kexec_cleanup(struct kimage *image)
 {
 }
 
+void arch_crash_save_vmcoreinfo(void)
+{
+       VMCOREINFO_SYMBOL(lowcore_ptr);
+       VMCOREINFO_LENGTH(lowcore_ptr, NR_CPUS);
+}
+
 void machine_shutdown(void)
 {
 }
 
-static void __machine_kexec(void *data)
+/*
+ * Do normal kexec
+ */
+static void __do_machine_kexec(void *data)
 {
        relocate_kernel_t data_mover;
        struct kimage *image = data;
 
-       pfault_fini();
-       s390_reset_system();
-
        data_mover = (relocate_kernel_t) page_to_phys(image->control_code_page);
 
        /* Call the moving routine */
        (*data_mover)(&image->head, image->start);
-       for (;;);
 }
 
+/*
+ * Reset system and call either kdump or normal kexec
+ */
+static void __machine_kexec(void *data)
+{
+       struct kimage *image = data;
+
+       pfault_fini();
+       if (image->type == KEXEC_TYPE_CRASH)
+               s390_reset_system(__do_machine_kdump, data);
+       else
+               s390_reset_system(__do_machine_kexec, data);
+       disabled_wait((unsigned long) __builtin_return_address(0));
+}
+
+/*
+ * Do either kdump or normal kexec. In case of kdump we first ask
+ * purgatory, if kdump checksums are valid.
+ */
 void machine_kexec(struct kimage *image)
 {
+       if (image->type == KEXEC_TYPE_CRASH && !kdump_csum_valid(image))
+               return;
        tracer_disable();
        smp_send_stop();
        smp_switch_to_ipl_cpu(__machine_kexec, image);
index 0fbe4e32f7ba298c83b22dfe831b66545fba8ace..19b4568f4ceec4ada5aa86db7251a2b8dc0afa75 100644 (file)
@@ -62,3 +62,72 @@ void detect_memory_layout(struct mem_chunk chunk[])
        arch_local_irq_restore(flags);
 }
 EXPORT_SYMBOL(detect_memory_layout);
+
+/*
+ * Create memory hole with given address, size, and type
+ */
+void create_mem_hole(struct mem_chunk chunks[], unsigned long addr,
+                    unsigned long size, int type)
+{
+       unsigned long start, end, new_size;
+       int i;
+
+       for (i = 0; i < MEMORY_CHUNKS; i++) {
+               if (chunks[i].size == 0)
+                       continue;
+               if (addr + size < chunks[i].addr)
+                       continue;
+               if (addr >= chunks[i].addr + chunks[i].size)
+                       continue;
+               start = max(addr, chunks[i].addr);
+               end = min(addr + size, chunks[i].addr + chunks[i].size);
+               new_size = end - start;
+               if (new_size == 0)
+                       continue;
+               if (start == chunks[i].addr &&
+                   end == chunks[i].addr + chunks[i].size) {
+                       /* Remove chunk */
+                       chunks[i].type = type;
+               } else if (start == chunks[i].addr) {
+                       /* Make chunk smaller at start */
+                       if (i >= MEMORY_CHUNKS - 1)
+                               panic("Unable to create memory hole");
+                       memmove(&chunks[i + 1], &chunks[i],
+                               sizeof(struct mem_chunk) *
+                               (MEMORY_CHUNKS - (i + 1)));
+                       chunks[i + 1].addr = chunks[i].addr + new_size;
+                       chunks[i + 1].size = chunks[i].size - new_size;
+                       chunks[i].size = new_size;
+                       chunks[i].type = type;
+                       i += 1;
+               } else if (end == chunks[i].addr + chunks[i].size) {
+                       /* Make chunk smaller at end */
+                       if (i >= MEMORY_CHUNKS - 1)
+                               panic("Unable to create memory hole");
+                       memmove(&chunks[i + 1], &chunks[i],
+                               sizeof(struct mem_chunk) *
+                               (MEMORY_CHUNKS - (i + 1)));
+                       chunks[i + 1].addr = start;
+                       chunks[i + 1].size = new_size;
+                       chunks[i + 1].type = type;
+                       chunks[i].size -= new_size;
+                       i += 1;
+               } else {
+                       /* Create memory hole */
+                       if (i >= MEMORY_CHUNKS - 2)
+                               panic("Unable to create memory hole");
+                       memmove(&chunks[i + 2], &chunks[i],
+                               sizeof(struct mem_chunk) *
+                               (MEMORY_CHUNKS - (i + 2)));
+                       chunks[i + 1].addr = addr;
+                       chunks[i + 1].size = size;
+                       chunks[i + 1].type = type;
+                       chunks[i + 2].addr = addr + size;
+                       chunks[i + 2].size =
+                               chunks[i].addr + chunks[i].size - (addr + size);
+                       chunks[i + 2].type = chunks[i].type;
+                       chunks[i].size = addr - chunks[i].addr;
+                       i += 2;
+               }
+       }
+}
index 541a7509faebd47f7b9d5a72a1f779c3efa2e1f4..9451b210a1b4f17e180ea0332b1108e154feaf87 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/sched.h>
 #include <linux/kernel.h>
 #include <linux/mm.h>
+#include <linux/elfcore.h>
 #include <linux/smp.h>
 #include <linux/slab.h>
 #include <linux/interrupt.h>
@@ -117,7 +118,8 @@ int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
        struct pt_regs regs;
 
        memset(&regs, 0, sizeof(regs));
-       regs.psw.mask = psw_kernel_bits | PSW_MASK_IO | PSW_MASK_EXT;
+       regs.psw.mask = psw_kernel_bits |
+               PSW_MASK_DAT | PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK;
        regs.psw.addr = (unsigned long) kernel_thread_starter | PSW_ADDR_AMODE;
        regs.gprs[9] = (unsigned long) fn;
        regs.gprs[10] = (unsigned long) arg;
index 311e9d7128884795733f2915448f98b62f60dc2e..6e0073e43f5448e8910fae02e973aecfdf1594f8 100644 (file)
@@ -74,7 +74,7 @@ static int show_cpuinfo(struct seq_file *m, void *v)
 
 static void *c_start(struct seq_file *m, loff_t *pos)
 {
-       return *pos < NR_CPUS ? (void *)((unsigned long) *pos + 1) : NULL;
+       return *pos < nr_cpu_ids ? (void *)((unsigned long) *pos + 1) : NULL;
 }
 
 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
index ef86ad2439868ffd4889b56f378f19e5c1f11968..450931a45b684b2044106921a66a4702e1eb93f1 100644 (file)
@@ -42,34 +42,37 @@ enum s390_regset {
        REGSET_GENERAL,
        REGSET_FP,
        REGSET_LAST_BREAK,
+       REGSET_SYSTEM_CALL,
        REGSET_GENERAL_EXTENDED,
 };
 
 void update_per_regs(struct task_struct *task)
 {
-       static const struct per_regs per_single_step = {
-               .control = PER_EVENT_IFETCH,
-               .start = 0,
-               .end = PSW_ADDR_INSN,
-       };
        struct pt_regs *regs = task_pt_regs(task);
        struct thread_struct *thread = &task->thread;
-       const struct per_regs *new;
-       struct per_regs old;
-
-       /* TIF_SINGLE_STEP overrides the user specified PER registers. */
-       new = test_tsk_thread_flag(task, TIF_SINGLE_STEP) ?
-               &per_single_step : &thread->per_user;
+       struct per_regs old, new;
+
+       /* Copy user specified PER registers */
+       new.control = thread->per_user.control;
+       new.start = thread->per_user.start;
+       new.end = thread->per_user.end;
+
+       /* merge TIF_SINGLE_STEP into user specified PER registers. */
+       if (test_tsk_thread_flag(task, TIF_SINGLE_STEP)) {
+               new.control |= PER_EVENT_IFETCH;
+               new.start = 0;
+               new.end = PSW_ADDR_INSN;
+       }
 
        /* Take care of the PER enablement bit in the PSW. */
-       if (!(new->control & PER_EVENT_MASK)) {
+       if (!(new.control & PER_EVENT_MASK)) {
                regs->psw.mask &= ~PSW_MASK_PER;
                return;
        }
        regs->psw.mask |= PSW_MASK_PER;
        __ctl_store(old, 9, 11);
-       if (memcmp(new, &old, sizeof(struct per_regs)) != 0)
-               __ctl_load(*new, 9, 11);
+       if (memcmp(&new, &old, sizeof(struct per_regs)) != 0)
+               __ctl_load(new, 9, 11);
 }
 
 void user_enable_single_step(struct task_struct *task)
@@ -166,8 +169,8 @@ static unsigned long __peek_user(struct task_struct *child, addr_t addr)
                 */
                tmp = *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr);
                if (addr == (addr_t) &dummy->regs.psw.mask)
-                       /* Remove per bit from user psw. */
-                       tmp &= ~PSW_MASK_PER;
+                       /* Return a clean psw mask. */
+                       tmp = psw_user_bits | (tmp & PSW_MASK_USER);
 
        } else if (addr < (addr_t) &dummy->regs.orig_gpr2) {
                /*
@@ -289,18 +292,17 @@ static int __poke_user(struct task_struct *child, addr_t addr, addr_t data)
                 * psw and gprs are stored on the stack
                 */
                if (addr == (addr_t) &dummy->regs.psw.mask &&
-#ifdef CONFIG_COMPAT
-                   data != PSW_MASK_MERGE(psw_user32_bits, data) &&
-#endif
-                   data != PSW_MASK_MERGE(psw_user_bits, data))
+                   ((data & ~PSW_MASK_USER) != psw_user_bits ||
+                    ((data & PSW_MASK_EA) && !(data & PSW_MASK_BA))))
                        /* Invalid psw mask. */
                        return -EINVAL;
-#ifndef CONFIG_64BIT
                if (addr == (addr_t) &dummy->regs.psw.addr)
-                       /* I'd like to reject addresses without the
-                          high order bit but older gdb's rely on it */
-                       data |= PSW_ADDR_AMODE;
-#endif
+                       /*
+                        * The debugger changed the instruction address,
+                        * reset system call restart, see signal.c:do_signal
+                        */
+                       task_thread_info(child)->system_call = 0;
+
                *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr) = data;
 
        } else if (addr < (addr_t) (&dummy->regs.orig_gpr2)) {
@@ -495,21 +497,21 @@ static u32 __peek_user_compat(struct task_struct *child, addr_t addr)
        __u32 tmp;
 
        if (addr < (addr_t) &dummy32->regs.acrs) {
+               struct pt_regs *regs = task_pt_regs(child);
                /*
                 * psw and gprs are stored on the stack
                 */
                if (addr == (addr_t) &dummy32->regs.psw.mask) {
                        /* Fake a 31 bit psw mask. */
-                       tmp = (__u32)(task_pt_regs(child)->psw.mask >> 32);
-                       tmp = PSW32_MASK_MERGE(psw32_user_bits, tmp);
+                       tmp = (__u32)(regs->psw.mask >> 32);
+                       tmp = psw32_user_bits | (tmp & PSW32_MASK_USER);
                } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
                        /* Fake a 31 bit psw address. */
-                       tmp = (__u32) task_pt_regs(child)->psw.addr |
-                               PSW32_ADDR_AMODE31;
+                       tmp = (__u32) regs->psw.addr |
+                               (__u32)(regs->psw.mask & PSW_MASK_BA);
                } else {
                        /* gpr 0-15 */
-                       tmp = *(__u32 *)((addr_t) &task_pt_regs(child)->psw +
-                                        addr*2 + 4);
+                       tmp = *(__u32 *)((addr_t) &regs->psw + addr*2 + 4);
                }
        } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
                /*
@@ -594,24 +596,32 @@ static int __poke_user_compat(struct task_struct *child,
        addr_t offset;
 
        if (addr < (addr_t) &dummy32->regs.acrs) {
+               struct pt_regs *regs = task_pt_regs(child);
                /*
                 * psw, gprs, acrs and orig_gpr2 are stored on the stack
                 */
                if (addr == (addr_t) &dummy32->regs.psw.mask) {
                        /* Build a 64 bit psw mask from 31 bit mask. */
-                       if (tmp != PSW32_MASK_MERGE(psw32_user_bits, tmp))
+                       if ((tmp & ~PSW32_MASK_USER) != psw32_user_bits)
                                /* Invalid psw mask. */
                                return -EINVAL;
-                       task_pt_regs(child)->psw.mask =
-                               PSW_MASK_MERGE(psw_user32_bits, (__u64) tmp << 32);
+                       regs->psw.mask = (regs->psw.mask & ~PSW_MASK_USER) |
+                               (regs->psw.mask & PSW_MASK_BA) |
+                               (__u64)(tmp & PSW32_MASK_USER) << 32;
                } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
                        /* Build a 64 bit psw address from 31 bit address. */
-                       task_pt_regs(child)->psw.addr =
-                               (__u64) tmp & PSW32_ADDR_INSN;
+                       regs->psw.addr = (__u64) tmp & PSW32_ADDR_INSN;
+                       /* Transfer 31 bit amode bit to psw mask. */
+                       regs->psw.mask = (regs->psw.mask & ~PSW_MASK_BA) |
+                               (__u64)(tmp & PSW32_ADDR_AMODE);
+                       /*
+                        * The debugger changed the instruction address,
+                        * reset system call restart, see signal.c:do_signal
+                        */
+                       task_thread_info(child)->system_call = 0;
                } else {
                        /* gpr 0-15 */
-                       *(__u32*)((addr_t) &task_pt_regs(child)->psw
-                                 + addr*2 + 4) = tmp;
+                       *(__u32*)((addr_t) &regs->psw + addr*2 + 4) = tmp;
                }
        } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
                /*
@@ -735,7 +745,7 @@ asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
                 * debugger stored an invalid system call number. Skip
                 * the system call and the system call restart handling.
                 */
-               regs->svcnr = 0;
+               clear_thread_flag(TIF_SYSCALL);
                ret = -1;
        }
 
@@ -897,6 +907,26 @@ static int s390_last_break_get(struct task_struct *target,
 
 #endif
 
+static int s390_system_call_get(struct task_struct *target,
+                               const struct user_regset *regset,
+                               unsigned int pos, unsigned int count,
+                               void *kbuf, void __user *ubuf)
+{
+       unsigned int *data = &task_thread_info(target)->system_call;
+       return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
+                                  data, 0, sizeof(unsigned int));
+}
+
+static int s390_system_call_set(struct task_struct *target,
+                               const struct user_regset *regset,
+                               unsigned int pos, unsigned int count,
+                               const void *kbuf, const void __user *ubuf)
+{
+       unsigned int *data = &task_thread_info(target)->system_call;
+       return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
+                                 data, 0, sizeof(unsigned int));
+}
+
 static const struct user_regset s390_regsets[] = {
        [REGSET_GENERAL] = {
                .core_note_type = NT_PRSTATUS,
@@ -923,6 +953,14 @@ static const struct user_regset s390_regsets[] = {
                .get = s390_last_break_get,
        },
 #endif
+       [REGSET_SYSTEM_CALL] = {
+               .core_note_type = NT_S390_SYSTEM_CALL,
+               .n = 1,
+               .size = sizeof(unsigned int),
+               .align = sizeof(unsigned int),
+               .get = s390_system_call_get,
+               .set = s390_system_call_set,
+       },
 };
 
 static const struct user_regset_view user_s390_view = {
@@ -1102,6 +1140,14 @@ static const struct user_regset s390_compat_regsets[] = {
                .align = sizeof(long),
                .get = s390_compat_last_break_get,
        },
+       [REGSET_SYSTEM_CALL] = {
+               .core_note_type = NT_S390_SYSTEM_CALL,
+               .n = 1,
+               .size = sizeof(compat_uint_t),
+               .align = sizeof(compat_uint_t),
+               .get = s390_system_call_get,
+               .set = s390_system_call_set,
+       },
        [REGSET_GENERAL_EXTENDED] = {
                .core_note_type = NT_S390_HIGH_GPRS,
                .n = sizeof(s390_compat_regs_high) / sizeof(compat_long_t),
index 303d961c3bb5ca8ac7b5a4f2eac9395dc9cf8d5d..ad67c214be047df4c6ddb02f65b0b645de152258 100644 (file)
@@ -9,6 +9,12 @@
 #include <linux/linkage.h>
 #include <asm/asm-offsets.h>
 
+#
+# store_status: Empty implementation until kdump is supported on 31 bit
+#
+ENTRY(store_status)
+               br      %r14
+
 #
 # do_reipl_asm
 # Parameter: r2 = schid of reipl device
index e690975403f43c9a8ac9d5dd2e8fa0ae3429722a..732a793ec53a65a173d17245cfeadd0bc970fa24 100644 (file)
 #
 ENTRY(store_status)
        /* Save register one and load save area base */
-       stg     %r1,__LC_SAVE_AREA_64(%r0)
+       stg     %r1,__LC_SAVE_AREA+120(%r0)
        lghi    %r1,SAVE_AREA_BASE
        /* General purpose registers */
        stmg    %r0,%r15,__LC_GPREGS_SAVE_AREA-SAVE_AREA_BASE(%r1)
-       lg      %r2,__LC_SAVE_AREA_64(%r0)
+       lg      %r2,__LC_SAVE_AREA+120(%r0)
        stg     %r2,__LC_GPREGS_SAVE_AREA-SAVE_AREA_BASE+8(%r1)
        /* Control registers */
        stctg   %c0,%c15,__LC_CREGS_SAVE_AREA-SAVE_AREA_BASE(%r1)
@@ -62,8 +62,11 @@ ENTRY(store_status)
        larl    %r2,store_status
        stg     %r2,__LC_PSW_SAVE_AREA-SAVE_AREA_BASE + 8(%r1)
        br      %r14
-.align 8
+
+       .section .bss
+       .align  8
 .Lclkcmp:      .quad   0x0000000000000000
+       .previous
 
 #
 # do_reipl_asm
index 7b371c37061de424892068ea7838a946f4f95e14..8ac6bfa2786cbe139d9964b1f4ab374e4302e2e8 100644 (file)
@@ -42,6 +42,9 @@
 #include <linux/reboot.h>
 #include <linux/topology.h>
 #include <linux/ftrace.h>
+#include <linux/kexec.h>
+#include <linux/crash_dump.h>
+#include <linux/memory.h>
 
 #include <asm/ipl.h>
 #include <asm/uaccess.h>
 #include <asm/ebcdic.h>
 #include <asm/compat.h>
 #include <asm/kvm_virtio.h>
+#include <asm/diag.h>
 
-long psw_kernel_bits   = (PSW_BASE_BITS | PSW_MASK_DAT | PSW_ASC_PRIMARY |
-                          PSW_MASK_MCHECK | PSW_DEFAULT_KEY);
-long psw_user_bits     = (PSW_BASE_BITS | PSW_MASK_DAT | PSW_ASC_HOME |
-                          PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK |
-                          PSW_MASK_PSTATE | PSW_DEFAULT_KEY);
+long psw_kernel_bits   = PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_ASC_PRIMARY |
+                         PSW_MASK_EA | PSW_MASK_BA;
+long psw_user_bits     = PSW_MASK_DAT | PSW_MASK_IO | PSW_MASK_EXT |
+                         PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_MASK_MCHECK |
+                         PSW_MASK_PSTATE | PSW_ASC_HOME;
 
 /*
  * User copy operations.
@@ -274,22 +278,14 @@ early_param("mem", early_parse_mem);
 unsigned int user_mode = HOME_SPACE_MODE;
 EXPORT_SYMBOL_GPL(user_mode);
 
-static int set_amode_and_uaccess(unsigned long user_amode,
-                                unsigned long user32_amode)
+static int set_amode_primary(void)
 {
-       psw_user_bits = PSW_BASE_BITS | PSW_MASK_DAT | user_amode |
-                       PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK |
-                       PSW_MASK_PSTATE | PSW_DEFAULT_KEY;
+       psw_kernel_bits = (psw_kernel_bits & ~PSW_MASK_ASC) | PSW_ASC_HOME;
+       psw_user_bits = (psw_user_bits & ~PSW_MASK_ASC) | PSW_ASC_PRIMARY;
 #ifdef CONFIG_COMPAT
-       psw_user32_bits = PSW_BASE32_BITS | PSW_MASK_DAT | user_amode |
-                         PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK |
-                         PSW_MASK_PSTATE | PSW_DEFAULT_KEY;
-       psw32_user_bits = PSW32_BASE_BITS | PSW32_MASK_DAT | user32_amode |
-                         PSW32_MASK_IO | PSW32_MASK_EXT | PSW32_MASK_MCHECK |
-                         PSW32_MASK_PSTATE;
+       psw32_user_bits =
+               (psw32_user_bits & ~PSW32_MASK_ASC) | PSW32_ASC_PRIMARY;
 #endif
-       psw_kernel_bits = PSW_BASE_BITS | PSW_MASK_DAT | PSW_ASC_HOME |
-                         PSW_MASK_MCHECK | PSW_DEFAULT_KEY;
 
        if (MACHINE_HAS_MVCOS) {
                memcpy(&uaccess, &uaccess_mvcos_switch, sizeof(uaccess));
@@ -325,7 +321,7 @@ early_param("user_mode", early_parse_user_mode);
 static void setup_addressing_mode(void)
 {
        if (user_mode == PRIMARY_SPACE_MODE) {
-               if (set_amode_and_uaccess(PSW_ASC_PRIMARY, PSW32_ASC_PRIMARY))
+               if (set_amode_primary())
                        pr_info("Address spaces switched, "
                                "mvcos available\n");
                else
@@ -344,24 +340,25 @@ setup_lowcore(void)
         */
        BUILD_BUG_ON(sizeof(struct _lowcore) != LC_PAGES * 4096);
        lc = __alloc_bootmem_low(LC_PAGES * PAGE_SIZE, LC_PAGES * PAGE_SIZE, 0);
-       lc->restart_psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
+       lc->restart_psw.mask = psw_kernel_bits;
        lc->restart_psw.addr =
                PSW_ADDR_AMODE | (unsigned long) psw_restart_int_handler;
-       if (user_mode != HOME_SPACE_MODE)
-               lc->restart_psw.mask |= PSW_ASC_HOME;
-       lc->external_new_psw.mask = psw_kernel_bits;
+       lc->external_new_psw.mask = psw_kernel_bits |
+               PSW_MASK_DAT | PSW_MASK_MCHECK;
        lc->external_new_psw.addr =
                PSW_ADDR_AMODE | (unsigned long) ext_int_handler;
-       lc->svc_new_psw.mask = psw_kernel_bits | PSW_MASK_IO | PSW_MASK_EXT;
+       lc->svc_new_psw.mask = psw_kernel_bits |
+               PSW_MASK_DAT | PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK;
        lc->svc_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) system_call;
-       lc->program_new_psw.mask = psw_kernel_bits;
+       lc->program_new_psw.mask = psw_kernel_bits |
+               PSW_MASK_DAT | PSW_MASK_MCHECK;
        lc->program_new_psw.addr =
-               PSW_ADDR_AMODE | (unsigned long)pgm_check_handler;
-       lc->mcck_new_psw.mask =
-               psw_kernel_bits & ~PSW_MASK_MCHECK & ~PSW_MASK_DAT;
+               PSW_ADDR_AMODE | (unsigned long) pgm_check_handler;
+       lc->mcck_new_psw.mask = psw_kernel_bits;
        lc->mcck_new_psw.addr =
                PSW_ADDR_AMODE | (unsigned long) mcck_int_handler;
-       lc->io_new_psw.mask = psw_kernel_bits;
+       lc->io_new_psw.mask = psw_kernel_bits |
+               PSW_MASK_DAT | PSW_MASK_MCHECK;
        lc->io_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) io_int_handler;
        lc->clock_comparator = -1ULL;
        lc->kernel_stack = ((unsigned long) &init_thread_union) + THREAD_SIZE;
@@ -435,10 +432,14 @@ static void __init setup_resources(void)
        for (i = 0; i < MEMORY_CHUNKS; i++) {
                if (!memory_chunk[i].size)
                        continue;
+               if (memory_chunk[i].type == CHUNK_OLDMEM ||
+                   memory_chunk[i].type == CHUNK_CRASHK)
+                       continue;
                res = alloc_bootmem_low(sizeof(*res));
                res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
                switch (memory_chunk[i].type) {
                case CHUNK_READ_WRITE:
+               case CHUNK_CRASHK:
                        res->name = "System RAM";
                        break;
                case CHUNK_READ_ONLY:
@@ -479,6 +480,7 @@ static void __init setup_memory_end(void)
        unsigned long max_mem;
        int i;
 
+
 #ifdef CONFIG_ZFCPDUMP
        if (ipl_info.type == IPL_TYPE_FCP_DUMP) {
                memory_end = ZFCPDUMP_HSA_SIZE;
@@ -545,11 +547,201 @@ static void __init setup_restart_psw(void)
         * Setup restart PSW for absolute zero lowcore. This is necesary
         * if PSW restart is done on an offline CPU that has lowcore zero
         */
-       psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
+       psw.mask = PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_MASK_EA | PSW_MASK_BA;
        psw.addr = PSW_ADDR_AMODE | (unsigned long) psw_restart_int_handler;
        copy_to_absolute_zero(&S390_lowcore.restart_psw, &psw, sizeof(psw));
 }
 
+static void __init setup_vmcoreinfo(void)
+{
+#ifdef CONFIG_KEXEC
+       unsigned long ptr = paddr_vmcoreinfo_note();
+
+       copy_to_absolute_zero(&S390_lowcore.vmcore_info, &ptr, sizeof(ptr));
+#endif
+}
+
+#ifdef CONFIG_CRASH_DUMP
+
+/*
+ * Find suitable location for crashkernel memory
+ */
+static unsigned long __init find_crash_base(unsigned long crash_size,
+                                           char **msg)
+{
+       unsigned long crash_base;
+       struct mem_chunk *chunk;
+       int i;
+
+       if (memory_chunk[0].size < crash_size) {
+               *msg = "first memory chunk must be at least crashkernel size";
+               return 0;
+       }
+       if (is_kdump_kernel() && (crash_size == OLDMEM_SIZE))
+               return OLDMEM_BASE;
+
+       for (i = MEMORY_CHUNKS - 1; i >= 0; i--) {
+               chunk = &memory_chunk[i];
+               if (chunk->size == 0)
+                       continue;
+               if (chunk->type != CHUNK_READ_WRITE)
+                       continue;
+               if (chunk->size < crash_size)
+                       continue;
+               crash_base = (chunk->addr + chunk->size) - crash_size;
+               if (crash_base < crash_size)
+                       continue;
+               if (crash_base < ZFCPDUMP_HSA_SIZE_MAX)
+                       continue;
+               if (crash_base < (unsigned long) INITRD_START + INITRD_SIZE)
+                       continue;
+               return crash_base;
+       }
+       *msg = "no suitable area found";
+       return 0;
+}
+
+/*
+ * Check if crash_base and crash_size is valid
+ */
+static int __init verify_crash_base(unsigned long crash_base,
+                                   unsigned long crash_size,
+                                   char **msg)
+{
+       struct mem_chunk *chunk;
+       int i;
+
+       /*
+        * Because we do the swap to zero, we must have at least 'crash_size'
+        * bytes free space before crash_base
+        */
+       if (crash_size > crash_base) {
+               *msg = "crashkernel offset must be greater than size";
+               return -EINVAL;
+       }
+
+       /* First memory chunk must be at least crash_size */
+       if (memory_chunk[0].size < crash_size) {
+               *msg = "first memory chunk must be at least crashkernel size";
+               return -EINVAL;
+       }
+       /* Check if we fit into the respective memory chunk */
+       for (i = 0; i < MEMORY_CHUNKS; i++) {
+               chunk = &memory_chunk[i];
+               if (chunk->size == 0)
+                       continue;
+               if (crash_base < chunk->addr)
+                       continue;
+               if (crash_base >= chunk->addr + chunk->size)
+                       continue;
+               /* we have found the memory chunk */
+               if (crash_base + crash_size > chunk->addr + chunk->size) {
+                       *msg = "selected memory chunk is too small for "
+                               "crashkernel memory";
+                       return -EINVAL;
+               }
+               return 0;
+       }
+       *msg = "invalid memory range specified";
+       return -EINVAL;
+}
+
+/*
+ * Reserve kdump memory by creating a memory hole in the mem_chunk array
+ */
+static void __init reserve_kdump_bootmem(unsigned long addr, unsigned long size,
+                                        int type)
+{
+
+       create_mem_hole(memory_chunk, addr, size, type);
+}
+
+/*
+ * When kdump is enabled, we have to ensure that no memory from
+ * the area [0 - crashkernel memory size] and
+ * [crashk_res.start - crashk_res.end] is set offline.
+ */
+static int kdump_mem_notifier(struct notifier_block *nb,
+                             unsigned long action, void *data)
+{
+       struct memory_notify *arg = data;
+
+       if (arg->start_pfn < PFN_DOWN(resource_size(&crashk_res)))
+               return NOTIFY_BAD;
+       if (arg->start_pfn > PFN_DOWN(crashk_res.end))
+               return NOTIFY_OK;
+       if (arg->start_pfn + arg->nr_pages - 1 < PFN_DOWN(crashk_res.start))
+               return NOTIFY_OK;
+       return NOTIFY_BAD;
+}
+
+static struct notifier_block kdump_mem_nb = {
+       .notifier_call = kdump_mem_notifier,
+};
+
+#endif
+
+/*
+ * Make sure that oldmem, where the dump is stored, is protected
+ */
+static void reserve_oldmem(void)
+{
+#ifdef CONFIG_CRASH_DUMP
+       if (!OLDMEM_BASE)
+               return;
+
+       reserve_kdump_bootmem(OLDMEM_BASE, OLDMEM_SIZE, CHUNK_OLDMEM);
+       reserve_kdump_bootmem(OLDMEM_SIZE, memory_end - OLDMEM_SIZE,
+                             CHUNK_OLDMEM);
+       if (OLDMEM_BASE + OLDMEM_SIZE == real_memory_size)
+               saved_max_pfn = PFN_DOWN(OLDMEM_BASE) - 1;
+       else
+               saved_max_pfn = PFN_DOWN(real_memory_size) - 1;
+#endif
+}
+
+/*
+ * Reserve memory for kdump kernel to be loaded with kexec
+ */
+static void __init reserve_crashkernel(void)
+{
+#ifdef CONFIG_CRASH_DUMP
+       unsigned long long crash_base, crash_size;
+       char *msg;
+       int rc;
+
+       rc = parse_crashkernel(boot_command_line, memory_end, &crash_size,
+                              &crash_base);
+       if (rc || crash_size == 0)
+               return;
+       crash_base = ALIGN(crash_base, KEXEC_CRASH_MEM_ALIGN);
+       crash_size = ALIGN(crash_size, KEXEC_CRASH_MEM_ALIGN);
+       if (register_memory_notifier(&kdump_mem_nb))
+               return;
+       if (!crash_base)
+               crash_base = find_crash_base(crash_size, &msg);
+       if (!crash_base) {
+               pr_info("crashkernel reservation failed: %s\n", msg);
+               unregister_memory_notifier(&kdump_mem_nb);
+               return;
+       }
+       if (verify_crash_base(crash_base, crash_size, &msg)) {
+               pr_info("crashkernel reservation failed: %s\n", msg);
+               unregister_memory_notifier(&kdump_mem_nb);
+               return;
+       }
+       if (!OLDMEM_BASE && MACHINE_IS_VM)
+               diag10_range(PFN_DOWN(crash_base), PFN_DOWN(crash_size));
+       crashk_res.start = crash_base;
+       crashk_res.end = crash_base + crash_size - 1;
+       insert_resource(&iomem_resource, &crashk_res);
+       reserve_kdump_bootmem(crash_base, crash_size, CHUNK_CRASHK);
+       pr_info("Reserving %lluMB of memory at %lluMB "
+               "for crashkernel (System RAM: %luMB)\n",
+               crash_size >> 20, crash_base >> 20, memory_end >> 20);
+#endif
+}
+
 static void __init
 setup_memory(void)
 {
@@ -580,6 +772,14 @@ setup_memory(void)
                if (PFN_PHYS(start_pfn) + bmap_size > INITRD_START) {
                        start = PFN_PHYS(start_pfn) + bmap_size + PAGE_SIZE;
 
+#ifdef CONFIG_CRASH_DUMP
+                       if (OLDMEM_BASE) {
+                               /* Move initrd behind kdump oldmem */
+                               if (start + INITRD_SIZE > OLDMEM_BASE &&
+                                   start < OLDMEM_BASE + OLDMEM_SIZE)
+                                       start = OLDMEM_BASE + OLDMEM_SIZE;
+                       }
+#endif
                        if (start + INITRD_SIZE > memory_end) {
                                pr_err("initrd extends beyond end of "
                                       "memory (0x%08lx > 0x%08lx) "
@@ -610,7 +810,8 @@ setup_memory(void)
        for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
                unsigned long start_chunk, end_chunk, pfn;
 
-               if (memory_chunk[i].type != CHUNK_READ_WRITE)
+               if (memory_chunk[i].type != CHUNK_READ_WRITE &&
+                   memory_chunk[i].type != CHUNK_CRASHK)
                        continue;
                start_chunk = PFN_DOWN(memory_chunk[i].addr);
                end_chunk = start_chunk + PFN_DOWN(memory_chunk[i].size);
@@ -644,6 +845,15 @@ setup_memory(void)
        reserve_bootmem(start_pfn << PAGE_SHIFT, bootmap_size,
                        BOOTMEM_DEFAULT);
 
+#ifdef CONFIG_CRASH_DUMP
+       if (crashk_res.start)
+               reserve_bootmem(crashk_res.start,
+                               crashk_res.end - crashk_res.start + 1,
+                               BOOTMEM_DEFAULT);
+       if (is_kdump_kernel())
+               reserve_bootmem(elfcorehdr_addr - OLDMEM_BASE,
+                               PAGE_ALIGN(elfcorehdr_size), BOOTMEM_DEFAULT);
+#endif
 #ifdef CONFIG_BLK_DEV_INITRD
        if (INITRD_START && INITRD_SIZE) {
                if (INITRD_START + INITRD_SIZE <= memory_end) {
@@ -812,8 +1022,11 @@ setup_arch(char **cmdline_p)
        setup_ipl();
        setup_memory_end();
        setup_addressing_mode();
+       reserve_oldmem();
+       reserve_crashkernel();
        setup_memory();
        setup_resources();
+       setup_vmcoreinfo();
        setup_restart_psw();
        setup_lowcore();
 
index 9a40e1cc5ec3f5e2b5ce15268b35862d22aff28e..05a85bc14c98a2556e86bf40cec7e76de2dc2423 100644 (file)
@@ -30,6 +30,7 @@
 #include <asm/ucontext.h>
 #include <asm/uaccess.h>
 #include <asm/lowcore.h>
+#include <asm/compat.h>
 #include "entry.h"
 
 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
@@ -116,7 +117,8 @@ static int save_sigregs(struct pt_regs *regs, _sigregs __user *sregs)
 
        /* Copy a 'clean' PSW mask to the user to avoid leaking
           information about whether PER is currently on.  */
-       user_sregs.regs.psw.mask = PSW_MASK_MERGE(psw_user_bits, regs->psw.mask);
+       user_sregs.regs.psw.mask = psw_user_bits |
+               (regs->psw.mask & PSW_MASK_USER);
        user_sregs.regs.psw.addr = regs->psw.addr;
        memcpy(&user_sregs.regs.gprs, &regs->gprs, sizeof(sregs->regs.gprs));
        memcpy(&user_sregs.regs.acrs, current->thread.acrs,
@@ -143,9 +145,13 @@ static int restore_sigregs(struct pt_regs *regs, _sigregs __user *sregs)
        err = __copy_from_user(&user_sregs, sregs, sizeof(_sigregs));
        if (err)
                return err;
-       regs->psw.mask = PSW_MASK_MERGE(regs->psw.mask,
-                                       user_sregs.regs.psw.mask);
-       regs->psw.addr = PSW_ADDR_AMODE | user_sregs.regs.psw.addr;
+       /* Use regs->psw.mask instead of psw_user_bits to preserve PER bit. */
+       regs->psw.mask = (regs->psw.mask & ~PSW_MASK_USER) |
+               (user_sregs.regs.psw.mask & PSW_MASK_USER);
+       /* Check for invalid amode */
+       if (regs->psw.mask & PSW_MASK_EA)
+               regs->psw.mask |= PSW_MASK_BA;
+       regs->psw.addr = user_sregs.regs.psw.addr;
        memcpy(&regs->gprs, &user_sregs.regs.gprs, sizeof(sregs->regs.gprs));
        memcpy(&current->thread.acrs, &user_sregs.regs.acrs,
               sizeof(sregs->regs.acrs));
@@ -156,7 +162,7 @@ static int restore_sigregs(struct pt_regs *regs, _sigregs __user *sregs)
        current->thread.fp_regs.fpc &= FPC_VALID_MASK;
 
        restore_fp_regs(&current->thread.fp_regs);
-       regs->svcnr = 0;        /* disable syscall checks */
+       clear_thread_flag(TIF_SYSCALL); /* No longer in a system call */
        return 0;
 }
 
@@ -288,6 +294,7 @@ static int setup_frame(int sig, struct k_sigaction *ka,
 
        /* Set up registers for signal handler */
        regs->gprs[15] = (unsigned long) frame;
+       regs->psw.mask |= PSW_MASK_EA | PSW_MASK_BA;    /* 64 bit amode */
        regs->psw.addr = (unsigned long) ka->sa.sa_handler | PSW_ADDR_AMODE;
 
        regs->gprs[2] = map_signal(sig);
@@ -356,6 +363,7 @@ static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
 
        /* Set up registers for signal handler */
        regs->gprs[15] = (unsigned long) frame;
+       regs->psw.mask |= PSW_MASK_EA | PSW_MASK_BA;    /* 64 bit amode */
        regs->psw.addr = (unsigned long) ka->sa.sa_handler | PSW_ADDR_AMODE;
 
        regs->gprs[2] = map_signal(sig);
@@ -401,7 +409,6 @@ static int handle_signal(unsigned long sig, struct k_sigaction *ka,
  */
 void do_signal(struct pt_regs *regs)
 {
-       unsigned long retval = 0, continue_addr = 0, restart_addr = 0;
        siginfo_t info;
        int signr;
        struct k_sigaction ka;
@@ -421,54 +428,45 @@ void do_signal(struct pt_regs *regs)
        else
                oldset = &current->blocked;
 
-       /* Are we from a system call? */
-       if (regs->svcnr) {
-               continue_addr = regs->psw.addr;
-               restart_addr = continue_addr - regs->ilc;
-               retval = regs->gprs[2];
-
-               /* Prepare for system call restart.  We do this here so that a
-                  debugger will see the already changed PSW. */
-               switch (retval) {
-               case -ERESTARTNOHAND:
-               case -ERESTARTSYS:
-               case -ERESTARTNOINTR:
-                       regs->gprs[2] = regs->orig_gpr2;
-                       regs->psw.addr = restart_addr;
-                       break;
-               case -ERESTART_RESTARTBLOCK:
-                       regs->gprs[2] = -EINTR;
-               }
-               regs->svcnr = 0;        /* Don't deal with this again. */
-       }
-
-       /* Get signal to deliver.  When running under ptrace, at this point
-          the debugger may change all our registers ... */
+       /*
+        * Get signal to deliver. When running under ptrace, at this point
+        * the debugger may change all our registers, including the system
+        * call information.
+        */
+       current_thread_info()->system_call =
+               test_thread_flag(TIF_SYSCALL) ? regs->svc_code : 0;
        signr = get_signal_to_deliver(&info, &ka, regs, NULL);
 
-       /* Depending on the signal settings we may need to revert the
-          decision to restart the system call. */
-       if (signr > 0 && regs->psw.addr == restart_addr) {
-               if (retval == -ERESTARTNOHAND
-                   || (retval == -ERESTARTSYS
-                        && !(current->sighand->action[signr-1].sa.sa_flags
-                             & SA_RESTART))) {
-                       regs->gprs[2] = -EINTR;
-                       regs->psw.addr = continue_addr;
-               }
-       }
-
        if (signr > 0) {
                /* Whee!  Actually deliver the signal.  */
-               int ret;
-#ifdef CONFIG_COMPAT
-               if (is_compat_task()) {
-                       ret = handle_signal32(signr, &ka, &info, oldset, regs);
-               }
-               else
-#endif
-                       ret = handle_signal(signr, &ka, &info, oldset, regs);
-               if (!ret) {
+               if (current_thread_info()->system_call) {
+                       regs->svc_code = current_thread_info()->system_call;
+                       /* Check for system call restarting. */
+                       switch (regs->gprs[2]) {
+                       case -ERESTART_RESTARTBLOCK:
+                       case -ERESTARTNOHAND:
+                               regs->gprs[2] = -EINTR;
+                               break;
+                       case -ERESTARTSYS:
+                               if (!(ka.sa.sa_flags & SA_RESTART)) {
+                                       regs->gprs[2] = -EINTR;
+                                       break;
+                               }
+                       /* fallthrough */
+                       case -ERESTARTNOINTR:
+                               regs->gprs[2] = regs->orig_gpr2;
+                               regs->psw.addr =
+                                       __rewind_psw(regs->psw,
+                                                    regs->svc_code >> 16);
+                               break;
+                       }
+                       /* No longer in a system call */
+                       clear_thread_flag(TIF_SYSCALL);
+               }
+
+               if ((is_compat_task() ?
+                    handle_signal32(signr, &ka, &info, oldset, regs) :
+                    handle_signal(signr, &ka, &info, oldset, regs)) == 0) {
                        /*
                         * A signal was successfully delivered; the saved
                         * sigmask will have been stored in the signal frame,
@@ -482,11 +480,32 @@ void do_signal(struct pt_regs *regs)
                         * Let tracing know that we've done the handler setup.
                         */
                        tracehook_signal_handler(signr, &info, &ka, regs,
-                                       test_thread_flag(TIF_SINGLE_STEP));
+                                        test_thread_flag(TIF_SINGLE_STEP));
                }
                return;
        }
 
+       /* No handlers present - check for system call restart */
+       if (current_thread_info()->system_call) {
+               regs->svc_code = current_thread_info()->system_call;
+               switch (regs->gprs[2]) {
+               case -ERESTART_RESTARTBLOCK:
+                       /* Restart with sys_restart_syscall */
+                       regs->svc_code = __NR_restart_syscall;
+               /* fallthrough */
+               case -ERESTARTNOHAND:
+               case -ERESTARTSYS:
+               case -ERESTARTNOINTR:
+                       /* Restart system call with magic TIF bit. */
+                       regs->gprs[2] = regs->orig_gpr2;
+                       set_thread_flag(TIF_SYSCALL);
+                       break;
+               default:
+                       clear_thread_flag(TIF_SYSCALL);
+                       break;
+               }
+       }
+
        /*
         * If there's no signal to deliver, we just put the saved sigmask back.
         */
@@ -494,13 +513,6 @@ void do_signal(struct pt_regs *regs)
                clear_thread_flag(TIF_RESTORE_SIGMASK);
                sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
        }
-
-       /* Restart a different system call. */
-       if (retval == -ERESTART_RESTARTBLOCK
-           && regs->psw.addr == continue_addr) {
-               regs->gprs[2] = __NR_restart_syscall;
-               set_thread_flag(TIF_RESTART_SVC);
-       }
 }
 
 void do_notify_resume(struct pt_regs *regs)
index 6ab16ac64d294687b90815328f90060362abc8de..3ea872890da219cf6cea900dccdf444a003e35d8 100644 (file)
@@ -38,6 +38,7 @@
 #include <linux/timex.h>
 #include <linux/bootmem.h>
 #include <linux/slab.h>
+#include <linux/crash_dump.h>
 #include <asm/asm-offsets.h>
 #include <asm/ipl.h>
 #include <asm/setup.h>
@@ -97,6 +98,29 @@ static inline int cpu_stopped(int cpu)
        return raw_cpu_stopped(cpu_logical_map(cpu));
 }
 
+/*
+ * Ensure that PSW restart is done on an online CPU
+ */
+void smp_restart_with_online_cpu(void)
+{
+       int cpu;
+
+       for_each_online_cpu(cpu) {
+               if (stap() == __cpu_logical_map[cpu]) {
+                       /* We are online: Enable DAT again and return */
+                       __load_psw_mask(psw_kernel_bits | PSW_MASK_DAT);
+                       return;
+               }
+       }
+       /* We are not online: Do PSW restart on an online CPU */
+       while (sigp(cpu, sigp_restart) == sigp_busy)
+               cpu_relax();
+       /* And stop ourself */
+       while (raw_sigp(stap(), sigp_stop) == sigp_busy)
+               cpu_relax();
+       for (;;);
+}
+
 void smp_switch_to_ipl_cpu(void (*func)(void *), void *data)
 {
        struct _lowcore *lc, *current_lc;
@@ -106,14 +130,16 @@ void smp_switch_to_ipl_cpu(void (*func)(void *), void *data)
 
        if (smp_processor_id() == 0)
                func(data);
-       __load_psw_mask(PSW_BASE_BITS | PSW_DEFAULT_KEY);
+       __load_psw_mask(PSW_DEFAULT_KEY | PSW_MASK_BASE |
+                       PSW_MASK_EA | PSW_MASK_BA);
        /* Disable lowcore protection */
        __ctl_clear_bit(0, 28);
        current_lc = lowcore_ptr[smp_processor_id()];
        lc = lowcore_ptr[0];
        if (!lc)
                lc = current_lc;
-       lc->restart_psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
+       lc->restart_psw.mask =
+               PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_MASK_EA | PSW_MASK_BA;
        lc->restart_psw.addr = PSW_ADDR_AMODE | (unsigned long) smp_restart_cpu;
        if (!cpu_online(0))
                smp_switch_to_cpu(func, data, 0, stap(), __cpu_logical_map[0]);
@@ -135,7 +161,7 @@ void smp_send_stop(void)
        int cpu, rc;
 
        /* Disable all interrupts/machine checks */
-       __load_psw_mask(psw_kernel_bits & ~PSW_MASK_MCHECK);
+       __load_psw_mask(psw_kernel_bits | PSW_MASK_DAT);
        trace_hardirqs_off();
 
        /* stop all processors */
@@ -161,7 +187,10 @@ static void do_ext_call_interrupt(unsigned int ext_int_code,
 {
        unsigned long bits;
 
-       kstat_cpu(smp_processor_id()).irqs[EXTINT_IPI]++;
+       if (ext_int_code == 0x1202)
+               kstat_cpu(smp_processor_id()).irqs[EXTINT_EXC]++;
+       else
+               kstat_cpu(smp_processor_id()).irqs[EXTINT_EMS]++;
        /*
         * handle bit signal external calls
         */
@@ -183,12 +212,19 @@ static void do_ext_call_interrupt(unsigned int ext_int_code,
  */
 static void smp_ext_bitcall(int cpu, int sig)
 {
+       int order;
+
        /*
         * Set signaling bit in lowcore of target cpu and kick it
         */
        set_bit(sig, (unsigned long *) &lowcore_ptr[cpu]->ext_call_fast);
-       while (sigp(cpu, sigp_emergency_signal) == sigp_busy)
+       while (1) {
+               order = smp_vcpu_scheduled(cpu) ?
+                       sigp_external_call : sigp_emergency_signal;
+               if (sigp(cpu, order) != sigp_busy)
+                       break;
                udelay(10);
+       }
 }
 
 void arch_send_call_function_ipi_mask(const struct cpumask *mask)
@@ -281,11 +317,13 @@ void smp_ctl_clear_bit(int cr, int bit)
 }
 EXPORT_SYMBOL(smp_ctl_clear_bit);
 
-#ifdef CONFIG_ZFCPDUMP
+#if defined(CONFIG_ZFCPDUMP) || defined(CONFIG_CRASH_DUMP)
 
 static void __init smp_get_save_area(unsigned int cpu, unsigned int phy_cpu)
 {
-       if (ipl_info.type != IPL_TYPE_FCP_DUMP)
+       if (ipl_info.type != IPL_TYPE_FCP_DUMP && !OLDMEM_BASE)
+               return;
+       if (is_kdump_kernel())
                return;
        if (cpu >= NR_CPUS) {
                pr_warning("CPU %i exceeds the maximum %i and is excluded from "
@@ -403,6 +441,18 @@ static void __init smp_detect_cpus(void)
        info = kmalloc(sizeof(*info), GFP_KERNEL);
        if (!info)
                panic("smp_detect_cpus failed to allocate memory\n");
+#ifdef CONFIG_CRASH_DUMP
+       if (OLDMEM_BASE && !is_kdump_kernel()) {
+               struct save_area *save_area;
+
+               save_area = kmalloc(sizeof(*save_area), GFP_KERNEL);
+               if (!save_area)
+                       panic("could not allocate memory for save area\n");
+               copy_oldmem_page(1, (void *) save_area, sizeof(*save_area),
+                                0x200, 0);
+               zfcpdump_save_areas[0] = save_area;
+       }
+#endif
        /* Use sigp detection algorithm if sclp doesn't work. */
        if (sclp_get_cpu_info(info)) {
                smp_use_sigp_detection = 1;
@@ -463,7 +513,8 @@ int __cpuinit start_secondary(void *cpuvoid)
        set_cpu_online(smp_processor_id(), true);
        ipi_call_unlock();
        __ctl_clear_bit(0, 28); /* Disable lowcore protection */
-       S390_lowcore.restart_psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
+       S390_lowcore.restart_psw.mask =
+               PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_MASK_EA | PSW_MASK_BA;
        S390_lowcore.restart_psw.addr =
                PSW_ADDR_AMODE | (unsigned long) psw_restart_int_handler;
        __ctl_set_bit(0, 28); /* Enable lowcore protection */
@@ -511,7 +562,8 @@ static int __cpuinit smp_alloc_lowcore(int cpu)
        memset((char *)lowcore + 512, 0, sizeof(*lowcore) - 512);
        lowcore->async_stack = async_stack + ASYNC_SIZE;
        lowcore->panic_stack = panic_stack + PAGE_SIZE;
-       lowcore->restart_psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
+       lowcore->restart_psw.mask =
+               PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_MASK_EA | PSW_MASK_BA;
        lowcore->restart_psw.addr =
                PSW_ADDR_AMODE | (unsigned long) restart_int_handler;
        if (user_mode != HOME_SPACE_MODE)
@@ -712,6 +764,9 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
        /* request the 0x1201 emergency signal external interrupt */
        if (register_external_interrupt(0x1201, do_ext_call_interrupt) != 0)
                panic("Couldn't request external interrupt 0x1201");
+       /* request the 0x1202 external call external interrupt */
+       if (register_external_interrupt(0x1202, do_ext_call_interrupt) != 0)
+               panic("Couldn't request external interrupt 0x1202");
 
        /* Reallocate current lowcore, but keep its contents. */
        lowcore = (void *) __get_free_pages(GFP_KERNEL | GFP_DMA, LC_ORDER);
index b6f9afed74ec8e3c7e1082c82185e491b8b213aa..47df775c844d48aa69c648fb17b488186beab8e7 100644 (file)
@@ -7,6 +7,7 @@
  */
 
 #include <linux/pfn.h>
+#include <linux/suspend.h>
 #include <linux/mm.h>
 #include <asm/system.h>
 
index 5c9e439bf3f6d21983ebbdaa706bb7cfb8e3a6a6..2a94b774695c069241ed413f50a0f9b8b183c656 100644 (file)
@@ -442,7 +442,7 @@ void s390_adjust_jiffies(void)
                 */
                FP_UNPACK_SP(SA, &fmil);
                if ((info->capability >> 23) == 0)
-                       FP_FROM_INT_S(SB, info->capability, 32, int);
+                       FP_FROM_INT_S(SB, (long) info->capability, 64, long);
                else
                        FP_UNPACK_SP(SB, &info->capability);
                FP_DIV_S(SR, SA, SB);
index 8d65bd0383fcf53ce6776ce5a23af13757e2101b..ebbfab3c6e5ac542019d175c520beddb9197b432 100644 (file)
@@ -48,6 +48,7 @@
 #include <asm/timer.h>
 #include <asm/etr.h>
 #include <asm/cio.h>
+#include "entry.h"
 
 /* change this if you have some constant time drift */
 #define USECS_PER_JIFFY     ((unsigned long) 1000000/HZ)
index 0cd340b72632c4a42fc19d43615e66f76a0c3a7e..77b8942b9a153af398cf9cf0e2dfd8eb7c5629ef 100644 (file)
@@ -299,8 +299,8 @@ out:
 }
 __initcall(init_topology_update);
 
-static void alloc_masks(struct sysinfo_15_1_x *info, struct mask_info *mask,
-                       int offset)
+static void __init alloc_masks(struct sysinfo_15_1_x *info,
+                              struct mask_info *mask, int offset)
 {
        int i, nr_masks;
 
index ffabcd9d33635dbcff5f35077ee5853bee8f8758..a9807dd862765a92ae8c2f4a2addc46b67186336 100644 (file)
@@ -200,7 +200,7 @@ void show_registers(struct pt_regs *regs)
               mask_bits(regs, PSW_MASK_PSTATE), mask_bits(regs, PSW_MASK_ASC),
               mask_bits(regs, PSW_MASK_CC), mask_bits(regs, PSW_MASK_PM));
 #ifdef CONFIG_64BIT
-       printk(" EA:%x", mask_bits(regs, PSW_BASE_BITS));
+       printk(" EA:%x", mask_bits(regs, PSW_MASK_EA | PSW_MASK_BA));
 #endif
        printk("\n%s GPRS: " FOURLONG, mode,
               regs->gprs[0], regs->gprs[1], regs->gprs[2], regs->gprs[3]);
@@ -334,7 +334,8 @@ void __kprobes do_per_trap(struct pt_regs *regs)
        info.si_signo = SIGTRAP;
        info.si_errno = 0;
        info.si_code = TRAP_HWBKPT;
-       info.si_addr = (void *) current->thread.per_event.address;
+       info.si_addr =
+               (void __force __user *) current->thread.per_event.address;
        force_sig_info(SIGTRAP, &info, current);
 }
 
index 2d6228f60cd69ec9d5e6ee2f670cbf93cc608c42..bb48977f54697bdb1d68b34da3cc239947659ea2 100644 (file)
@@ -170,7 +170,8 @@ void __kprobes vtime_stop_cpu(void)
        psw_t psw;
 
        /* Wait for external, I/O or machine check interrupt. */
-       psw.mask = psw_kernel_bits | PSW_MASK_WAIT | PSW_MASK_IO | PSW_MASK_EXT;
+       psw.mask = psw_kernel_bits | PSW_MASK_WAIT |
+               PSW_MASK_DAT | PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK;
 
        idle->nohz_delay = 0;
 
@@ -183,7 +184,8 @@ void __kprobes vtime_stop_cpu(void)
                 *      set_cpu_timer(VTIMER_MAX_SLICE);
                 *      idle->idle_enter = get_clock();
                 *      __load_psw_mask(psw_kernel_bits | PSW_MASK_WAIT |
-                *                         PSW_MASK_IO | PSW_MASK_EXT);
+                *                         PSW_MASK_DAT | PSW_MASK_IO |
+                *                         PSW_MASK_EXT | PSW_MASK_MCHECK);
                 * The difference is that the inline assembly makes sure that
                 * the last three instruction are stpt, stck and lpsw in that
                 * order. This is done to increase the precision.
@@ -216,7 +218,8 @@ void __kprobes vtime_stop_cpu(void)
                 *      vq->idle = get_cpu_timer();
                 *      idle->idle_enter = get_clock();
                 *      __load_psw_mask(psw_kernel_bits | PSW_MASK_WAIT |
-                *                         PSW_MASK_IO | PSW_MASK_EXT);
+                *                         PSW_MASK_DAT | PSW_MASK_IO |
+                *                         PSW_MASK_EXT | PSW_MASK_MCHECK);
                 * The difference is that the inline assembly makes sure that
                 * the last three instruction are stpt, stck and lpsw in that
                 * order. This is done to increase the precision.
@@ -458,7 +461,7 @@ void add_virt_timer_periodic(void *new)
 }
 EXPORT_SYMBOL(add_virt_timer_periodic);
 
-int __mod_vtimer(struct vtimer_list *timer, __u64 expires, int periodic)
+static int __mod_vtimer(struct vtimer_list *timer, __u64 expires, int periodic)
 {
        struct vtimer_queue *vq;
        unsigned long flags;
index 9e4c84187cf504fc0fdffed9afb80ce3a393b05a..87cedd61be0467fdd4085308e55967acb9210ef3 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * diag.c - handling diagnose instructions
  *
- * Copyright IBM Corp. 2008
+ * Copyright IBM Corp. 2008,2011
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License (version 2 only)
 #include <linux/kvm_host.h>
 #include "kvm-s390.h"
 
+static int diag_release_pages(struct kvm_vcpu *vcpu)
+{
+       unsigned long start, end;
+       unsigned long prefix  = vcpu->arch.sie_block->prefix;
+
+       start = vcpu->arch.guest_gprs[(vcpu->arch.sie_block->ipa & 0xf0) >> 4];
+       end = vcpu->arch.guest_gprs[vcpu->arch.sie_block->ipa & 0xf] + 4096;
+
+       if (start & ~PAGE_MASK || end & ~PAGE_MASK || start > end
+           || start < 2 * PAGE_SIZE)
+               return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
+
+       VCPU_EVENT(vcpu, 5, "diag release pages %lX %lX", start, end);
+       vcpu->stat.diagnose_10++;
+
+       /* we checked for start > end above */
+       if (end < prefix || start >= prefix + 2 * PAGE_SIZE) {
+               gmap_discard(start, end, vcpu->arch.gmap);
+       } else {
+               if (start < prefix)
+                       gmap_discard(start, prefix, vcpu->arch.gmap);
+               if (end >= prefix)
+                       gmap_discard(prefix + 2 * PAGE_SIZE,
+                                    end, vcpu->arch.gmap);
+       }
+       return 0;
+}
+
 static int __diag_time_slice_end(struct kvm_vcpu *vcpu)
 {
        VCPU_EVENT(vcpu, 5, "%s", "diag time slice end");
@@ -57,6 +85,8 @@ int kvm_s390_handle_diag(struct kvm_vcpu *vcpu)
        int code = (vcpu->arch.sie_block->ipb & 0xfff0000) >> 16;
 
        switch (code) {
+       case 0x10:
+               return diag_release_pages(vcpu);
        case 0x44:
                return __diag_time_slice_end(vcpu);
        case 0x308:
index c9aeb4b4d0b84e67c9cc5ae1bf6648d31ea7c6dd..87c16705b381396f796e7fbacbb079d62cab8d9d 100644 (file)
@@ -38,6 +38,11 @@ static int __interrupt_is_deliverable(struct kvm_vcpu *vcpu,
                                      struct kvm_s390_interrupt_info *inti)
 {
        switch (inti->type) {
+       case KVM_S390_INT_EXTERNAL_CALL:
+               if (psw_extint_disabled(vcpu))
+                       return 0;
+               if (vcpu->arch.sie_block->gcr[0] & 0x2000ul)
+                       return 1;
        case KVM_S390_INT_EMERGENCY:
                if (psw_extint_disabled(vcpu))
                        return 0;
@@ -98,6 +103,7 @@ static void __set_intercept_indicator(struct kvm_vcpu *vcpu,
                                      struct kvm_s390_interrupt_info *inti)
 {
        switch (inti->type) {
+       case KVM_S390_INT_EXTERNAL_CALL:
        case KVM_S390_INT_EMERGENCY:
        case KVM_S390_INT_SERVICE:
        case KVM_S390_INT_VIRTIO:
@@ -143,6 +149,28 @@ static void __do_deliver_interrupt(struct kvm_vcpu *vcpu,
                        exception = 1;
                break;
 
+       case KVM_S390_INT_EXTERNAL_CALL:
+               VCPU_EVENT(vcpu, 4, "%s", "interrupt: sigp ext call");
+               vcpu->stat.deliver_external_call++;
+               rc = put_guest_u16(vcpu, __LC_EXT_INT_CODE, 0x1202);
+               if (rc == -EFAULT)
+                       exception = 1;
+
+               rc = put_guest_u16(vcpu, __LC_CPU_ADDRESS, inti->extcall.code);
+               if (rc == -EFAULT)
+                       exception = 1;
+
+               rc = copy_to_guest(vcpu, __LC_EXT_OLD_PSW,
+                        &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
+               if (rc == -EFAULT)
+                       exception = 1;
+
+               rc = copy_from_guest(vcpu, &vcpu->arch.sie_block->gpsw,
+                       __LC_EXT_NEW_PSW, sizeof(psw_t));
+               if (rc == -EFAULT)
+                       exception = 1;
+               break;
+
        case KVM_S390_INT_SERVICE:
                VCPU_EVENT(vcpu, 4, "interrupt: sclp parm:%x",
                           inti->ext.ext_params);
@@ -522,6 +550,7 @@ int kvm_s390_inject_vm(struct kvm *kvm,
                break;
        case KVM_S390_PROGRAM_INT:
        case KVM_S390_SIGP_STOP:
+       case KVM_S390_INT_EXTERNAL_CALL:
        case KVM_S390_INT_EMERGENCY:
        default:
                kfree(inti);
@@ -581,6 +610,7 @@ int kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu,
                break;
        case KVM_S390_SIGP_STOP:
        case KVM_S390_RESTART:
+       case KVM_S390_INT_EXTERNAL_CALL:
        case KVM_S390_INT_EMERGENCY:
                VCPU_EVENT(vcpu, 3, "inject: type %x", s390int->type);
                inti->type = s390int->type;
index dc2b580e27bcfc45e0a883ffd61992d4647eb64c..0bd3bea1e4cdfc40069a474d37f74459903803ce 100644 (file)
@@ -46,6 +46,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
        { "instruction_lctlg", VCPU_STAT(instruction_lctlg) },
        { "instruction_lctl", VCPU_STAT(instruction_lctl) },
        { "deliver_emergency_signal", VCPU_STAT(deliver_emergency_signal) },
+       { "deliver_external_call", VCPU_STAT(deliver_external_call) },
        { "deliver_service_signal", VCPU_STAT(deliver_service_signal) },
        { "deliver_virtio_interrupt", VCPU_STAT(deliver_virtio_interrupt) },
        { "deliver_stop_signal", VCPU_STAT(deliver_stop_signal) },
@@ -64,11 +65,13 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
        { "instruction_stfl", VCPU_STAT(instruction_stfl) },
        { "instruction_tprot", VCPU_STAT(instruction_tprot) },
        { "instruction_sigp_sense", VCPU_STAT(instruction_sigp_sense) },
+       { "instruction_sigp_external_call", VCPU_STAT(instruction_sigp_external_call) },
        { "instruction_sigp_emergency", VCPU_STAT(instruction_sigp_emergency) },
        { "instruction_sigp_stop", VCPU_STAT(instruction_sigp_stop) },
        { "instruction_sigp_set_arch", VCPU_STAT(instruction_sigp_arch) },
        { "instruction_sigp_set_prefix", VCPU_STAT(instruction_sigp_prefix) },
        { "instruction_sigp_restart", VCPU_STAT(instruction_sigp_restart) },
+       { "diagnose_10", VCPU_STAT(diagnose_10) },
        { "diagnose_44", VCPU_STAT(diagnose_44) },
        { NULL }
 };
@@ -175,6 +178,8 @@ int kvm_arch_init_vm(struct kvm *kvm)
        if (rc)
                goto out_err;
 
+       rc = -ENOMEM;
+
        kvm->arch.sca = (struct sca_block *) get_zeroed_page(GFP_KERNEL);
        if (!kvm->arch.sca)
                goto out_err;
@@ -312,11 +317,17 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
 struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm,
                                      unsigned int id)
 {
-       struct kvm_vcpu *vcpu = kzalloc(sizeof(struct kvm_vcpu), GFP_KERNEL);
-       int rc = -ENOMEM;
+       struct kvm_vcpu *vcpu;
+       int rc = -EINVAL;
+
+       if (id >= KVM_MAX_VCPUS)
+               goto out;
 
+       rc = -ENOMEM;
+
+       vcpu = kzalloc(sizeof(struct kvm_vcpu), GFP_KERNEL);
        if (!vcpu)
-               goto out_nomem;
+               goto out;
 
        vcpu->arch.sie_block = (struct kvm_s390_sie_block *)
                                        get_zeroed_page(GFP_KERNEL);
@@ -352,7 +363,7 @@ out_free_sie_block:
        free_page((unsigned long)(vcpu->arch.sie_block));
 out_free_cpu:
        kfree(vcpu);
-out_nomem:
+out:
        return ERR_PTR(rc);
 }
 
@@ -386,6 +397,7 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
 {
        memcpy(&vcpu->arch.guest_acrs, &sregs->acrs, sizeof(sregs->acrs));
        memcpy(&vcpu->arch.sie_block->gcr, &sregs->crs, sizeof(sregs->crs));
+       restore_access_regs(vcpu->arch.guest_acrs);
        return 0;
 }
 
@@ -401,6 +413,7 @@ int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
 {
        memcpy(&vcpu->arch.guest_fpregs.fprs, &fpu->fprs, sizeof(fpu->fprs));
        vcpu->arch.guest_fpregs.fpc = fpu->fpc;
+       restore_fp_regs(&vcpu->arch.guest_fpregs);
        return 0;
 }
 
index d6a50c1fb2e68dbb9f45654ab6fab1af6f760585..f815118835f3c3221932c5e01c86847cc1ec9ba8 100644 (file)
@@ -87,6 +87,7 @@ static int __sigp_emergency(struct kvm_vcpu *vcpu, u16 cpu_addr)
                return -ENOMEM;
 
        inti->type = KVM_S390_INT_EMERGENCY;
+       inti->emerg.code = vcpu->vcpu_id;
 
        spin_lock(&fi->lock);
        li = fi->local_int[cpu_addr];
@@ -103,9 +104,47 @@ static int __sigp_emergency(struct kvm_vcpu *vcpu, u16 cpu_addr)
                wake_up_interruptible(&li->wq);
        spin_unlock_bh(&li->lock);
        rc = 0; /* order accepted */
+       VCPU_EVENT(vcpu, 4, "sent sigp emerg to cpu %x", cpu_addr);
+unlock:
+       spin_unlock(&fi->lock);
+       return rc;
+}
+
+static int __sigp_external_call(struct kvm_vcpu *vcpu, u16 cpu_addr)
+{
+       struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int;
+       struct kvm_s390_local_interrupt *li;
+       struct kvm_s390_interrupt_info *inti;
+       int rc;
+
+       if (cpu_addr >= KVM_MAX_VCPUS)
+               return 3; /* not operational */
+
+       inti = kzalloc(sizeof(*inti), GFP_KERNEL);
+       if (!inti)
+               return -ENOMEM;
+
+       inti->type = KVM_S390_INT_EXTERNAL_CALL;
+       inti->extcall.code = vcpu->vcpu_id;
+
+       spin_lock(&fi->lock);
+       li = fi->local_int[cpu_addr];
+       if (li == NULL) {
+               rc = 3; /* not operational */
+               kfree(inti);
+               goto unlock;
+       }
+       spin_lock_bh(&li->lock);
+       list_add_tail(&inti->list, &li->list);
+       atomic_set(&li->active, 1);
+       atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags);
+       if (waitqueue_active(&li->wq))
+               wake_up_interruptible(&li->wq);
+       spin_unlock_bh(&li->lock);
+       rc = 0; /* order accepted */
+       VCPU_EVENT(vcpu, 4, "sent sigp ext call to cpu %x", cpu_addr);
 unlock:
        spin_unlock(&fi->lock);
-       VCPU_EVENT(vcpu, 4, "sent sigp emerg to cpu %x", cpu_addr);
        return rc;
 }
 
@@ -267,6 +306,10 @@ int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu)
                rc = __sigp_sense(vcpu, cpu_addr,
                                  &vcpu->arch.guest_gprs[r1]);
                break;
+       case SIGP_EXTERNAL_CALL:
+               vcpu->stat.instruction_sigp_external_call++;
+               rc = __sigp_external_call(vcpu, cpu_addr);
+               break;
        case SIGP_EMERGENCY:
                vcpu->stat.instruction_sigp_emergency++;
                rc = __sigp_emergency(vcpu, cpu_addr);
index a65229d91c92be055931de197528c67d3403837c..db92f044024c4508993fd4b0e7c67c9b74e37b0e 100644 (file)
@@ -32,7 +32,8 @@ static void __udelay_disabled(unsigned long long usecs)
        u64 clock_saved;
        u64 end;
 
-       mask = psw_kernel_bits | PSW_MASK_WAIT | PSW_MASK_EXT;
+       mask = psw_kernel_bits | PSW_MASK_DAT | PSW_MASK_WAIT |
+               PSW_MASK_EXT | PSW_MASK_MCHECK;
        end = get_clock() + (usecs << 12);
        clock_saved = local_tick_disable();
        __ctl_store(cr0_saved, 0, 0);
index 74833831417fcb3585831e52a000b5fded8d8217..342ae35a5ba90ddbcf89ef2a6dc5b8676de2faff 100644 (file)
@@ -342,7 +342,8 @@ int futex_atomic_op_pt(int op, u32 __user *uaddr, int oparg, int *old)
        if (segment_eq(get_fs(), KERNEL_DS))
                return __futex_atomic_op_pt(op, uaddr, oparg, old);
        spin_lock(&current->mm->page_table_lock);
-       uaddr = (int __user *) __dat_user_addr((unsigned long) uaddr);
+       uaddr = (u32 __force __user *)
+               __dat_user_addr((__force unsigned long) uaddr);
        if (!uaddr) {
                spin_unlock(&current->mm->page_table_lock);
                return -EFAULT;
@@ -378,7 +379,8 @@ int futex_atomic_cmpxchg_pt(u32 *uval, u32 __user *uaddr,
        if (segment_eq(get_fs(), KERNEL_DS))
                return __futex_atomic_cmpxchg_pt(uval, uaddr, oldval, newval);
        spin_lock(&current->mm->page_table_lock);
-       uaddr = (int __user *) __dat_user_addr((unsigned long) uaddr);
+       uaddr = (u32 __force __user *)
+               __dat_user_addr((__force unsigned long) uaddr);
        if (!uaddr) {
                spin_unlock(&current->mm->page_table_lock);
                return -EFAULT;
index 9564fc779b27a6071cfe08fac6932aa8e08eb23a..1766def5bc3fc7f4717904313c69b2a7879b6d86 100644 (file)
@@ -307,7 +307,7 @@ static inline int do_exception(struct pt_regs *regs, int access,
 
 #ifdef CONFIG_PGSTE
        if (test_tsk_thread_flag(current, TIF_SIE) && S390_lowcore.gmap) {
-               address = gmap_fault(address,
+               address = __gmap_fault(address,
                                     (struct gmap *) S390_lowcore.gmap);
                if (address == -EFAULT) {
                        fault = VM_FAULT_BADMAP;
@@ -393,7 +393,7 @@ void __kprobes do_protection_exception(struct pt_regs *regs, long pgm_int_code,
        int fault;
 
        /* Protection exception is suppressing, decrement psw address. */
-       regs->psw.addr -= (pgm_int_code >> 16);
+       regs->psw.addr = __rewind_psw(regs->psw, pgm_int_code >> 16);
        /*
         * Check for low-address protection.  This needs to be treated
         * as a special case because the translation exception code
@@ -454,7 +454,7 @@ int __handle_fault(unsigned long uaddr, unsigned long pgm_int_code, int write)
        struct pt_regs regs;
        int access, fault;
 
-       regs.psw.mask = psw_kernel_bits;
+       regs.psw.mask = psw_kernel_bits | PSW_MASK_DAT | PSW_MASK_MCHECK;
        if (!irqs_disabled())
                regs.psw.mask |= PSW_MASK_IO | PSW_MASK_EXT;
        regs.psw.addr = (unsigned long) __builtin_return_address(0);
index 5dbbaa6e594c8192302a23525bfcbfb05685c50e..1cb8427bedfb3862ca4ac57e7d2064757a3db2e3 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/kernel.h>
 #include <linux/types.h>
 #include <linux/errno.h>
+#include <linux/gfp.h>
 #include <asm/system.h>
 
 /*
@@ -60,6 +61,9 @@ long probe_kernel_write(void *dst, const void *src, size_t size)
        return copied < 0 ? -EFAULT : 0;
 }
 
+/*
+ * Copy memory in real mode (kernel to kernel)
+ */
 int memcpy_real(void *dest, void *src, size_t count)
 {
        register unsigned long _dest asm("2") = (unsigned long) dest;
@@ -101,3 +105,55 @@ void copy_to_absolute_zero(void *dest, void *src, size_t count)
        __ctl_load(cr0, 0, 0);
        preempt_enable();
 }
+
+/*
+ * Copy memory from kernel (real) to user (virtual)
+ */
+int copy_to_user_real(void __user *dest, void *src, size_t count)
+{
+       int offs = 0, size, rc;
+       char *buf;
+
+       buf = (char *) __get_free_page(GFP_KERNEL);
+       if (!buf)
+               return -ENOMEM;
+       rc = -EFAULT;
+       while (offs < count) {
+               size = min(PAGE_SIZE, count - offs);
+               if (memcpy_real(buf, src + offs, size))
+                       goto out;
+               if (copy_to_user(dest + offs, buf, size))
+                       goto out;
+               offs += size;
+       }
+       rc = 0;
+out:
+       free_page((unsigned long) buf);
+       return rc;
+}
+
+/*
+ * Copy memory from user (virtual) to kernel (real)
+ */
+int copy_from_user_real(void *dest, void __user *src, size_t count)
+{
+       int offs = 0, size, rc;
+       char *buf;
+
+       buf = (char *) __get_free_page(GFP_KERNEL);
+       if (!buf)
+               return -ENOMEM;
+       rc = -EFAULT;
+       while (offs < count) {
+               size = min(PAGE_SIZE, count - offs);
+               if (copy_from_user(buf, src + offs, size))
+                       goto out;
+               if (memcpy_real(dest + offs, buf, size))
+                       goto out;
+               offs += size;
+       }
+       rc = 0;
+out:
+       free_page((unsigned long) buf);
+       return rc;
+}
index c9a9f7f1818818cddc4eac89b57fa7e8d6cb65fb..f09c74881b7e5b2c12d323265f289e0681eec66b 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <linux/personality.h>
 #include <linux/mm.h>
+#include <linux/mman.h>
 #include <linux/module.h>
 #include <linux/random.h>
 #include <asm/pgalloc.h>
index d013ed39743b1bfe57faaa31f51c933f31d5639a..b36537a5f43e33e3a1a6cc9907efcf3920e8d583 100644 (file)
@@ -5,6 +5,7 @@
 #include <linux/module.h>
 #include <linux/mm.h>
 #include <linux/hugetlb.h>
+#include <asm/cacheflush.h>
 #include <asm/pgtable.h>
 
 static void change_page_attr(unsigned long addr, int numpages,
index 5d56c2b95b14a1298c4b3dffa0759e69588fa7c4..301c84d3b542f05fc10eaa432804b834556b2781 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *    Copyright IBM Corp. 2007,2009
+ *    Copyright IBM Corp. 2007,2011
  *    Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
  */
 
@@ -222,6 +222,7 @@ void gmap_free(struct gmap *gmap)
 
        /* Free all segment & region tables. */
        down_read(&gmap->mm->mmap_sem);
+       spin_lock(&gmap->mm->page_table_lock);
        list_for_each_entry_safe(page, next, &gmap->crst_list, lru) {
                table = (unsigned long *) page_to_phys(page);
                if ((*table & _REGION_ENTRY_TYPE_MASK) == 0)
@@ -230,6 +231,7 @@ void gmap_free(struct gmap *gmap)
                                gmap_unlink_segment(gmap, table);
                __free_pages(page, ALLOC_ORDER);
        }
+       spin_unlock(&gmap->mm->page_table_lock);
        up_read(&gmap->mm->mmap_sem);
        list_del(&gmap->list);
        kfree(gmap);
@@ -256,6 +258,9 @@ void gmap_disable(struct gmap *gmap)
 }
 EXPORT_SYMBOL_GPL(gmap_disable);
 
+/*
+ * gmap_alloc_table is assumed to be called with mmap_sem held
+ */
 static int gmap_alloc_table(struct gmap *gmap,
                               unsigned long *table, unsigned long init)
 {
@@ -267,14 +272,12 @@ static int gmap_alloc_table(struct gmap *gmap,
                return -ENOMEM;
        new = (unsigned long *) page_to_phys(page);
        crst_table_init(new, init);
-       down_read(&gmap->mm->mmap_sem);
        if (*table & _REGION_ENTRY_INV) {
                list_add(&page->lru, &gmap->crst_list);
                *table = (unsigned long) new | _REGION_ENTRY_LENGTH |
                        (*table & _REGION_ENTRY_TYPE_MASK);
        } else
                __free_pages(page, ALLOC_ORDER);
-       up_read(&gmap->mm->mmap_sem);
        return 0;
 }
 
@@ -299,6 +302,7 @@ int gmap_unmap_segment(struct gmap *gmap, unsigned long to, unsigned long len)
 
        flush = 0;
        down_read(&gmap->mm->mmap_sem);
+       spin_lock(&gmap->mm->page_table_lock);
        for (off = 0; off < len; off += PMD_SIZE) {
                /* Walk the guest addr space page table */
                table = gmap->table + (((to + off) >> 53) & 0x7ff);
@@ -320,6 +324,7 @@ int gmap_unmap_segment(struct gmap *gmap, unsigned long to, unsigned long len)
                *table = _SEGMENT_ENTRY_INV;
        }
 out:
+       spin_unlock(&gmap->mm->page_table_lock);
        up_read(&gmap->mm->mmap_sem);
        if (flush)
                gmap_flush_tlb(gmap);
@@ -350,6 +355,7 @@ int gmap_map_segment(struct gmap *gmap, unsigned long from,
 
        flush = 0;
        down_read(&gmap->mm->mmap_sem);
+       spin_lock(&gmap->mm->page_table_lock);
        for (off = 0; off < len; off += PMD_SIZE) {
                /* Walk the gmap address space page table */
                table = gmap->table + (((to + off) >> 53) & 0x7ff);
@@ -373,19 +379,24 @@ int gmap_map_segment(struct gmap *gmap, unsigned long from,
                flush |= gmap_unlink_segment(gmap, table);
                *table = _SEGMENT_ENTRY_INV | _SEGMENT_ENTRY_RO | (from + off);
        }
+       spin_unlock(&gmap->mm->page_table_lock);
        up_read(&gmap->mm->mmap_sem);
        if (flush)
                gmap_flush_tlb(gmap);
        return 0;
 
 out_unmap:
+       spin_unlock(&gmap->mm->page_table_lock);
        up_read(&gmap->mm->mmap_sem);
        gmap_unmap_segment(gmap, to, len);
        return -ENOMEM;
 }
 EXPORT_SYMBOL_GPL(gmap_map_segment);
 
-unsigned long gmap_fault(unsigned long address, struct gmap *gmap)
+/*
+ * this function is assumed to be called with mmap_sem held
+ */
+unsigned long __gmap_fault(unsigned long address, struct gmap *gmap)
 {
        unsigned long *table, vmaddr, segment;
        struct mm_struct *mm;
@@ -445,16 +456,75 @@ unsigned long gmap_fault(unsigned long address, struct gmap *gmap)
                page = pmd_page(*pmd);
                mp = (struct gmap_pgtable *) page->index;
                rmap->entry = table;
+               spin_lock(&mm->page_table_lock);
                list_add(&rmap->list, &mp->mapper);
+               spin_unlock(&mm->page_table_lock);
                /* Set gmap segment table entry to page table. */
                *table = pmd_val(*pmd) & PAGE_MASK;
                return vmaddr | (address & ~PMD_MASK);
        }
        return -EFAULT;
+}
 
+unsigned long gmap_fault(unsigned long address, struct gmap *gmap)
+{
+       unsigned long rc;
+
+       down_read(&gmap->mm->mmap_sem);
+       rc = __gmap_fault(address, gmap);
+       up_read(&gmap->mm->mmap_sem);
+
+       return rc;
 }
 EXPORT_SYMBOL_GPL(gmap_fault);
 
+void gmap_discard(unsigned long from, unsigned long to, struct gmap *gmap)
+{
+
+       unsigned long *table, address, size;
+       struct vm_area_struct *vma;
+       struct gmap_pgtable *mp;
+       struct page *page;
+
+       down_read(&gmap->mm->mmap_sem);
+       address = from;
+       while (address < to) {
+               /* Walk the gmap address space page table */
+               table = gmap->table + ((address >> 53) & 0x7ff);
+               if (unlikely(*table & _REGION_ENTRY_INV)) {
+                       address = (address + PMD_SIZE) & PMD_MASK;
+                       continue;
+               }
+               table = (unsigned long *)(*table & _REGION_ENTRY_ORIGIN);
+               table = table + ((address >> 42) & 0x7ff);
+               if (unlikely(*table & _REGION_ENTRY_INV)) {
+                       address = (address + PMD_SIZE) & PMD_MASK;
+                       continue;
+               }
+               table = (unsigned long *)(*table & _REGION_ENTRY_ORIGIN);
+               table = table + ((address >> 31) & 0x7ff);
+               if (unlikely(*table & _REGION_ENTRY_INV)) {
+                       address = (address + PMD_SIZE) & PMD_MASK;
+                       continue;
+               }
+               table = (unsigned long *)(*table & _REGION_ENTRY_ORIGIN);
+               table = table + ((address >> 20) & 0x7ff);
+               if (unlikely(*table & _SEGMENT_ENTRY_INV)) {
+                       address = (address + PMD_SIZE) & PMD_MASK;
+                       continue;
+               }
+               page = pfn_to_page(*table >> PAGE_SHIFT);
+               mp = (struct gmap_pgtable *) page->index;
+               vma = find_vma(gmap->mm, mp->vmaddr);
+               size = min(to - address, PMD_SIZE - (address & ~PMD_MASK));
+               zap_page_range(vma, mp->vmaddr | (address & ~PMD_MASK),
+                              size, NULL);
+               address = (address + PMD_SIZE) & PMD_MASK;
+       }
+       up_read(&gmap->mm->mmap_sem);
+}
+EXPORT_SYMBOL_GPL(gmap_discard);
+
 void gmap_unmap_notifier(struct mm_struct *mm, unsigned long *table)
 {
        struct gmap_rmap *rmap, *next;
@@ -662,8 +732,9 @@ void page_table_free_rcu(struct mmu_gather *tlb, unsigned long *table)
 
 void __tlb_remove_table(void *_table)
 {
-       void *table = (void *)((unsigned long) _table & PAGE_MASK);
-       unsigned type = (unsigned long) _table & ~PAGE_MASK;
+       const unsigned long mask = (FRAG_MASK << 4) | FRAG_MASK;
+       void *table = (void *)((unsigned long) _table & ~mask);
+       unsigned type = (unsigned long) _table & mask;
 
        if (type)
                __page_table_free_rcu(table, type);
index 781ff51695602cf215bf462fe2c1d9358d26575d..4799383e2df9551c45ad69f08f57455bb9771dc0 100644 (file)
@@ -335,6 +335,9 @@ void __init vmem_map_init(void)
        ro_start = ((unsigned long)&_stext) & PAGE_MASK;
        ro_end = PFN_ALIGN((unsigned long)&_eshared);
        for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
+               if (memory_chunk[i].type == CHUNK_CRASHK ||
+                   memory_chunk[i].type == CHUNK_OLDMEM)
+                       continue;
                start = memory_chunk[i].addr;
                end = memory_chunk[i].addr + memory_chunk[i].size;
                if (start >= ro_end || end <= ro_start)
@@ -368,6 +371,9 @@ static int __init vmem_convert_memory_chunk(void)
        for (i = 0; i < MEMORY_CHUNKS; i++) {
                if (!memory_chunk[i].size)
                        continue;
+               if (memory_chunk[i].type == CHUNK_CRASHK ||
+                   memory_chunk[i].type == CHUNK_OLDMEM)
+                       continue;
                seg = kzalloc(sizeof(*seg), GFP_KERNEL);
                if (!seg)
                        panic("Out of memory...\n");
index 4552ce40c81a5086ad550e21092c78b36ad3b7c3..f43c0e4282af5e46033b4a97349cf1fce4d88c26 100644 (file)
@@ -994,7 +994,7 @@ allocate_error:
  *
  * Returns 0 on success, !0 on failure.
  */
-int hwsampler_deallocate()
+int hwsampler_deallocate(void)
 {
        int rc;
 
@@ -1035,7 +1035,7 @@ unsigned long hwsampler_get_sample_overflow_count(unsigned int cpu)
        return cb->sample_overflow;
 }
 
-int hwsampler_setup()
+int hwsampler_setup(void)
 {
        int rc;
        int cpu;
@@ -1102,7 +1102,7 @@ setup_exit:
        return rc;
 }
 
-int hwsampler_shutdown()
+int hwsampler_shutdown(void)
 {
        int rc;
 
@@ -1203,7 +1203,7 @@ start_all_exit:
  *
  * Returns 0 on success, !0 on failure.
  */
-int hwsampler_stop_all()
+int hwsampler_stop_all(void)
 {
        int tmp_rc, rc, cpu;
        struct hws_cpu_buffer *cb;
index 32b626c9d815601e445b0d47e76cc0ebbab84e75..73370674ccff49f797af2e8143e3ead2c34d233c 100644 (file)
@@ -713,17 +713,17 @@ static void pcmp(struct pt_regs *regs, unsigned int insn, unsigned int opf)
                        s16 b = (rs2 >> (i * 16)) & 0xffff;
 
                        if (a > b)
-                               rd_val |= 1 << i;
+                               rd_val |= 8 >> i;
                }
                break;
 
        case FCMPGT32_OPF:
                for (i = 0; i < 2; i++) {
-                       s32 a = (rs1 >> (i * 32)) & 0xffff;
-                       s32 b = (rs2 >> (i * 32)) & 0xffff;
+                       s32 a = (rs1 >> (i * 32)) & 0xffffffff;
+                       s32 b = (rs2 >> (i * 32)) & 0xffffffff;
 
                        if (a > b)
-                               rd_val |= 1 << i;
+                               rd_val |= 2 >> i;
                }
                break;
 
@@ -733,17 +733,17 @@ static void pcmp(struct pt_regs *regs, unsigned int insn, unsigned int opf)
                        s16 b = (rs2 >> (i * 16)) & 0xffff;
 
                        if (a <= b)
-                               rd_val |= 1 << i;
+                               rd_val |= 8 >> i;
                }
                break;
 
        case FCMPLE32_OPF:
                for (i = 0; i < 2; i++) {
-                       s32 a = (rs1 >> (i * 32)) & 0xffff;
-                       s32 b = (rs2 >> (i * 32)) & 0xffff;
+                       s32 a = (rs1 >> (i * 32)) & 0xffffffff;
+                       s32 b = (rs2 >> (i * 32)) & 0xffffffff;
 
                        if (a <= b)
-                               rd_val |= 1 << i;
+                               rd_val |= 2 >> i;
                }
                break;
 
@@ -753,17 +753,17 @@ static void pcmp(struct pt_regs *regs, unsigned int insn, unsigned int opf)
                        s16 b = (rs2 >> (i * 16)) & 0xffff;
 
                        if (a != b)
-                               rd_val |= 1 << i;
+                               rd_val |= 8 >> i;
                }
                break;
 
        case FCMPNE32_OPF:
                for (i = 0; i < 2; i++) {
-                       s32 a = (rs1 >> (i * 32)) & 0xffff;
-                       s32 b = (rs2 >> (i * 32)) & 0xffff;
+                       s32 a = (rs1 >> (i * 32)) & 0xffffffff;
+                       s32 b = (rs2 >> (i * 32)) & 0xffffffff;
 
                        if (a != b)
-                               rd_val |= 1 << i;
+                               rd_val |= 2 >> i;
                }
                break;
 
@@ -773,17 +773,17 @@ static void pcmp(struct pt_regs *regs, unsigned int insn, unsigned int opf)
                        s16 b = (rs2 >> (i * 16)) & 0xffff;
 
                        if (a == b)
-                               rd_val |= 1 << i;
+                               rd_val |= 8 >> i;
                }
                break;
 
        case FCMPEQ32_OPF:
                for (i = 0; i < 2; i++) {
-                       s32 a = (rs1 >> (i * 32)) & 0xffff;
-                       s32 b = (rs2 >> (i * 32)) & 0xffff;
+                       s32 a = (rs1 >> (i * 32)) & 0xffffffff;
+                       s32 b = (rs2 >> (i * 32)) & 0xffffffff;
 
                        if (a == b)
-                               rd_val |= 1 << i;
+                               rd_val |= 2 >> i;
                }
                break;
        }
index 34fe65751737dba67b9df52f55fe165e6d2202e4..4d8c497517bd6f3f17110f2a3b4e6b6fe204e39e 100644 (file)
@@ -7,40 +7,12 @@
  * Copyright (C) 1996 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  */
 
-#ifdef __KERNEL__
-
-#define FUNC(x)                                                                                        \
+#define FUNC(x)                \
        .globl  x;              \
        .type   x,@function;    \
-       .align  4;                                                                                      \
+       .align  4;              \
 x:
 
-#undef FASTER_REVERSE
-#undef FASTER_NONALIGNED
-#define FASTER_ALIGNED
-
-/* In kernel these functions don't return a value.
- * One should use macros in asm/string.h for that purpose.
- * We return 0, so that bugs are more apparent.
- */
-#define SETUP_RETL
-#define RETL_INSN      clr     %o0
-
-#else
-
-/* libc */
-
-#include "DEFS.h"
-
-#define FASTER_REVERSE
-#define FASTER_NONALIGNED
-#define FASTER_ALIGNED
-
-#define SETUP_RETL     mov     %o0, %g6
-#define RETL_INSN      mov     %g6, %o0
-
-#endif
-
 /* Both these macros have to start with exactly the same insn */
 #define MOVE_BIGCHUNK(src, dst, offset, t0, t1, t2, t3, t4, t5, t6, t7) \
        ldd     [%src + (offset) + 0x00], %t0; \
@@ -164,30 +136,6 @@ x:
        .text
        .align  4
 
-#ifdef FASTER_REVERSE
-
-70:    /* rdword_align */
-
-       andcc           %o1, 1, %g0
-       be              4f
-        andcc          %o1, 2, %g0
-
-       ldub            [%o1 - 1], %g2
-       sub             %o1, 1, %o1
-       stb             %g2, [%o0 - 1]
-       sub             %o2, 1, %o2
-       be              3f
-        sub            %o0, 1, %o0
-4:
-       lduh            [%o1 - 2], %g2
-       sub             %o1, 2, %o1
-       sth             %g2, [%o0 - 2]
-       sub             %o2, 2, %o2
-       b               3f
-        sub            %o0, 2, %o0
-
-#endif /* FASTER_REVERSE */
-
 0:
        retl
         nop            ! Only bcopy returns here and it retuns void...
@@ -198,7 +146,7 @@ FUNC(__memmove)
 #endif
 FUNC(memmove)
        cmp             %o0, %o1
-       SETUP_RETL
+       mov             %o0, %g7
        bleu            9f
         sub            %o0, %o1, %o4
 
@@ -207,8 +155,6 @@ FUNC(memmove)
        bleu            0f
         andcc          %o4, 3, %o5
 
-#ifndef FASTER_REVERSE
-
        add             %o1, %o2, %o1
        add             %o0, %o2, %o0
        sub             %o1, 1, %o1
@@ -224,295 +170,7 @@ FUNC(memmove)
         sub            %o0, 1, %o0
 
        retl
-        RETL_INSN
-
-#else /* FASTER_REVERSE */
-
-       add             %o1, %o2, %o1
-       add             %o0, %o2, %o0
-       bne             77f
-        cmp            %o2, 15
-       bleu            91f
-        andcc          %o1, 3, %g0
-       bne             70b
-3:
-        andcc          %o1, 4, %g0
-
-       be              2f
-        mov            %o2, %g1
-
-       ld              [%o1 - 4], %o4
-       sub             %g1, 4, %g1
-       st              %o4, [%o0 - 4]
-       sub             %o1, 4, %o1
-       sub             %o0, 4, %o0
-2:
-       andcc           %g1, 0xffffff80, %g7
-       be              3f
-        andcc          %o0, 4, %g0
-
-       be              74f + 4
-5:
-       RMOVE_BIGCHUNK(o1, o0, 0x00, o2, o3, o4, o5, g2, g3, g4, g5)
-       RMOVE_BIGCHUNK(o1, o0, 0x20, o2, o3, o4, o5, g2, g3, g4, g5)
-       RMOVE_BIGCHUNK(o1, o0, 0x40, o2, o3, o4, o5, g2, g3, g4, g5)
-       RMOVE_BIGCHUNK(o1, o0, 0x60, o2, o3, o4, o5, g2, g3, g4, g5)
-       subcc           %g7, 128, %g7
-       sub             %o1, 128, %o1
-       bne             5b
-        sub            %o0, 128, %o0
-3:
-       andcc           %g1, 0x70, %g7
-       be              72f
-        andcc          %g1, 8, %g0
-
-       sethi           %hi(72f), %o5
-       srl             %g7, 1, %o4
-       add             %g7, %o4, %o4
-       sub             %o1, %g7, %o1
-       sub             %o5, %o4, %o5
-       jmpl            %o5 + %lo(72f), %g0
-        sub            %o0, %g7, %o0
-
-71:    /* rmemcpy_table */
-       RMOVE_LASTCHUNK(o1, o0, 0x60, g2, g3, g4, g5)
-       RMOVE_LASTCHUNK(o1, o0, 0x50, g2, g3, g4, g5)
-       RMOVE_LASTCHUNK(o1, o0, 0x40, g2, g3, g4, g5)
-       RMOVE_LASTCHUNK(o1, o0, 0x30, g2, g3, g4, g5)
-       RMOVE_LASTCHUNK(o1, o0, 0x20, g2, g3, g4, g5)
-       RMOVE_LASTCHUNK(o1, o0, 0x10, g2, g3, g4, g5)
-       RMOVE_LASTCHUNK(o1, o0, 0x00, g2, g3, g4, g5)
-
-72:    /* rmemcpy_table_end */
-
-       be              73f
-        andcc          %g1, 4, %g0
-
-       ldd             [%o1 - 0x08], %g2
-       sub             %o0, 8, %o0
-       sub             %o1, 8, %o1
-       st              %g2, [%o0]
-       st              %g3, [%o0 + 0x04]
-
-73:    /* rmemcpy_last7 */
-
-       be              1f
-        andcc          %g1, 2, %g0
-
-       ld              [%o1 - 4], %g2
-       sub             %o1, 4, %o1
-       st              %g2, [%o0 - 4]
-       sub             %o0, 4, %o0
-1:
-       be              1f
-        andcc          %g1, 1, %g0
-
-       lduh            [%o1 - 2], %g2
-       sub             %o1, 2, %o1
-       sth             %g2, [%o0 - 2]
-       sub             %o0, 2, %o0
-1:
-       be              1f
-        nop
-
-       ldub            [%o1 - 1], %g2
-       stb             %g2, [%o0 - 1]
-1:
-       retl
-        RETL_INSN
-
-74:    /* rldd_std */
-       RMOVE_BIGALIGNCHUNK(o1, o0, 0x00, o2, o3, o4, o5, g2, g3, g4, g5)
-       RMOVE_BIGALIGNCHUNK(o1, o0, 0x20, o2, o3, o4, o5, g2, g3, g4, g5)
-       RMOVE_BIGALIGNCHUNK(o1, o0, 0x40, o2, o3, o4, o5, g2, g3, g4, g5)
-       RMOVE_BIGALIGNCHUNK(o1, o0, 0x60, o2, o3, o4, o5, g2, g3, g4, g5)
-       subcc           %g7, 128, %g7
-       sub             %o1, 128, %o1
-       bne             74b
-        sub            %o0, 128, %o0
-
-       andcc           %g1, 0x70, %g7
-       be              72b
-        andcc          %g1, 8, %g0
-
-       sethi           %hi(72b), %o5
-       srl             %g7, 1, %o4
-       add             %g7, %o4, %o4
-       sub             %o1, %g7, %o1
-       sub             %o5, %o4, %o5
-       jmpl            %o5 + %lo(72b), %g0
-        sub            %o0, %g7, %o0
-
-75:    /* rshort_end */
-
-       and             %o2, 0xe, %o3
-2:
-       sethi           %hi(76f), %o5
-       sll             %o3, 3, %o4
-       sub             %o0, %o3, %o0
-       sub             %o5, %o4, %o5
-       sub             %o1, %o3, %o1
-       jmpl            %o5 + %lo(76f), %g0
-        andcc          %o2, 1, %g0
-
-       RMOVE_SHORTCHUNK(o1, o0, 0x0c, g2, g3)
-       RMOVE_SHORTCHUNK(o1, o0, 0x0a, g2, g3)
-       RMOVE_SHORTCHUNK(o1, o0, 0x08, g2, g3)
-       RMOVE_SHORTCHUNK(o1, o0, 0x06, g2, g3)
-       RMOVE_SHORTCHUNK(o1, o0, 0x04, g2, g3)
-       RMOVE_SHORTCHUNK(o1, o0, 0x02, g2, g3)
-       RMOVE_SHORTCHUNK(o1, o0, 0x00, g2, g3)
-
-76:    /* rshort_table_end */
-
-       be              1f
-        nop
-       ldub            [%o1 - 1], %g2
-       stb             %g2, [%o0 - 1]
-1:
-       retl
-        RETL_INSN
-
-91:    /* rshort_aligned_end */
-
-       bne             75b
-        andcc          %o2, 8, %g0
-
-       be              1f
-        andcc          %o2, 4, %g0
-
-       ld              [%o1 - 0x08], %g2
-       ld              [%o1 - 0x04], %g3
-       sub             %o1, 8, %o1
-       st              %g2, [%o0 - 0x08]
-       st              %g3, [%o0 - 0x04]
-       sub             %o0, 8, %o0
-1:
-       b               73b
-        mov            %o2, %g1
-
-77:    /* rnon_aligned */
-       cmp             %o2, 15
-       bleu            75b
-        andcc          %o0, 3, %g0
-       be              64f
-        andcc          %o0, 1, %g0
-       be              63f
-        andcc          %o0, 2, %g0
-       ldub            [%o1 - 1], %g5
-       sub             %o1, 1, %o1
-       stb             %g5, [%o0 - 1]
-       sub             %o0, 1, %o0
-       be              64f
-        sub            %o2, 1, %o2
-63:
-       ldub            [%o1 - 1], %g5
-       sub             %o1, 2, %o1
-       stb             %g5, [%o0 - 1]
-       sub             %o0, 2, %o0
-       ldub            [%o1], %g5
-       sub             %o2, 2, %o2
-       stb             %g5, [%o0]
-64:    
-       and             %o1, 3, %g2
-       and             %o1, -4, %o1
-       and             %o2, 0xc, %g3
-       add             %o1, 4, %o1
-       cmp             %g3, 4
-       sll             %g2, 3, %g4
-       mov             32, %g2
-       be              4f
-        sub            %g2, %g4, %g7
-
-       blu             3f
-        cmp            %g3, 8
-
-       be              2f
-        srl            %o2, 2, %g3
-
-       ld              [%o1 - 4], %o3
-       add             %o0, -8, %o0
-       ld              [%o1 - 8], %o4
-       add             %o1, -16, %o1
-       b               7f
-        add            %g3, 1, %g3
-2:
-       ld              [%o1 - 4], %o4
-       add             %o0, -4, %o0
-       ld              [%o1 - 8], %g1
-       add             %o1, -12, %o1
-       b               8f
-        add            %g3, 2, %g3
-3:
-       ld              [%o1 - 4], %o5
-       add             %o0, -12, %o0
-       ld              [%o1 - 8], %o3
-       add             %o1, -20, %o1
-       b               6f
-        srl            %o2, 2, %g3
-4:
-       ld              [%o1 - 4], %g1
-       srl             %o2, 2, %g3
-       ld              [%o1 - 8], %o5
-       add             %o1, -24, %o1
-       add             %o0, -16, %o0
-       add             %g3, -1, %g3
-
-       ld              [%o1 + 12], %o3
-5:
-       sll             %o5, %g4, %g2
-       srl             %g1, %g7, %g5
-       or              %g2, %g5, %g2
-       st              %g2, [%o0 + 12]
-6:
-       ld              [%o1 + 8], %o4
-       sll             %o3, %g4, %g2
-       srl             %o5, %g7, %g5
-       or              %g2, %g5, %g2
-       st              %g2, [%o0 + 8]
-7:
-       ld              [%o1 + 4], %g1
-       sll             %o4, %g4, %g2
-       srl             %o3, %g7, %g5
-       or              %g2, %g5, %g2
-       st              %g2, [%o0 + 4]
-8:
-       ld              [%o1], %o5
-       sll             %g1, %g4, %g2
-       srl             %o4, %g7, %g5
-       addcc           %g3, -4, %g3
-       or              %g2, %g5, %g2
-       add             %o1, -16, %o1
-       st              %g2, [%o0]
-       add             %o0, -16, %o0
-       bne,a           5b      
-        ld             [%o1 + 12], %o3
-       sll             %o5, %g4, %g2
-       srl             %g1, %g7, %g5
-       srl             %g4, 3, %g3
-       or              %g2, %g5, %g2
-       add             %o1, %g3, %o1
-       andcc           %o2, 2, %g0
-       st              %g2, [%o0 + 12]
-       be              1f
-        andcc          %o2, 1, %g0
-       
-       ldub            [%o1 + 15], %g5
-       add             %o1, -2, %o1
-       stb             %g5, [%o0 + 11]
-       add             %o0, -2, %o0
-       ldub            [%o1 + 16], %g5
-       stb             %g5, [%o0 + 12]
-1:
-       be              1f
-        nop
-       ldub            [%o1 + 15], %g5
-       stb             %g5, [%o0 + 11]
-1:
-       retl
-        RETL_INSN
-
-#endif /* FASTER_REVERSE */
+        mov            %g7, %o0
 
 /* NOTE: This code is executed just for the cases,
          where %src (=%o1) & 3 is != 0.
@@ -546,7 +204,7 @@ FUNC(memmove)
 FUNC(memcpy)   /* %o0=dst %o1=src %o2=len */
 
        sub             %o0, %o1, %o4
-       SETUP_RETL
+       mov             %o0, %g7
 9:
        andcc           %o4, 3, %o5
 0:
@@ -569,7 +227,7 @@ FUNC(memcpy)        /* %o0=dst %o1=src %o2=len */
        add             %o1, 4, %o1
        add             %o0, 4, %o0
 2:
-       andcc           %g1, 0xffffff80, %g7
+       andcc           %g1, 0xffffff80, %g0
        be              3f
         andcc          %o0, 4, %g0
 
@@ -579,22 +237,23 @@ FUNC(memcpy)      /* %o0=dst %o1=src %o2=len */
        MOVE_BIGCHUNK(o1, o0, 0x20, o2, o3, o4, o5, g2, g3, g4, g5)
        MOVE_BIGCHUNK(o1, o0, 0x40, o2, o3, o4, o5, g2, g3, g4, g5)
        MOVE_BIGCHUNK(o1, o0, 0x60, o2, o3, o4, o5, g2, g3, g4, g5)
-       subcc           %g7, 128, %g7
+       sub             %g1, 128, %g1
        add             %o1, 128, %o1
-       bne             5b
+       cmp             %g1, 128
+       bge             5b
         add            %o0, 128, %o0
 3:
-       andcc           %g1, 0x70, %g7
+       andcc           %g1, 0x70, %g4
        be              80f
         andcc          %g1, 8, %g0
 
        sethi           %hi(80f), %o5
-       srl             %g7, 1, %o4
-       add             %g7, %o4, %o4
-       add             %o1, %g7, %o1
+       srl             %g4, 1, %o4
+       add             %g4, %o4, %o4
+       add             %o1, %g4, %o1
        sub             %o5, %o4, %o5
        jmpl            %o5 + %lo(80f), %g0
-        add            %o0, %g7, %o0
+        add            %o0, %g4, %o0
 
 79:    /* memcpy_table */
 
@@ -641,43 +300,28 @@ FUNC(memcpy)      /* %o0=dst %o1=src %o2=len */
        stb             %g2, [%o0]
 1:
        retl
-        RETL_INSN
+        mov            %g7, %o0
 
 82:    /* ldd_std */
        MOVE_BIGALIGNCHUNK(o1, o0, 0x00, o2, o3, o4, o5, g2, g3, g4, g5)
        MOVE_BIGALIGNCHUNK(o1, o0, 0x20, o2, o3, o4, o5, g2, g3, g4, g5)
        MOVE_BIGALIGNCHUNK(o1, o0, 0x40, o2, o3, o4, o5, g2, g3, g4, g5)
        MOVE_BIGALIGNCHUNK(o1, o0, 0x60, o2, o3, o4, o5, g2, g3, g4, g5)
-       subcc           %g7, 128, %g7
+       subcc           %g1, 128, %g1
        add             %o1, 128, %o1
-       bne             82b
+       cmp             %g1, 128
+       bge             82b
         add            %o0, 128, %o0
 
-#ifndef FASTER_ALIGNED
-
-       andcc           %g1, 0x70, %g7
-       be              80b
-        andcc          %g1, 8, %g0
-
-       sethi           %hi(80b), %o5
-       srl             %g7, 1, %o4
-       add             %g7, %o4, %o4
-       add             %o1, %g7, %o1
-       sub             %o5, %o4, %o5
-       jmpl            %o5 + %lo(80b), %g0
-        add            %o0, %g7, %o0
-
-#else /* FASTER_ALIGNED */
-
-       andcc           %g1, 0x70, %g7
+       andcc           %g1, 0x70, %g4
        be              84f
         andcc          %g1, 8, %g0
 
        sethi           %hi(84f), %o5
-       add             %o1, %g7, %o1
-       sub             %o5, %g7, %o5
+       add             %o1, %g4, %o1
+       sub             %o5, %g4, %o5
        jmpl            %o5 + %lo(84f), %g0
-        add            %o0, %g7, %o0
+        add            %o0, %g4, %o0
 
 83:    /* amemcpy_table */
 
@@ -721,382 +365,132 @@ FUNC(memcpy)    /* %o0=dst %o1=src %o2=len */
        stb             %g2, [%o0]
 1:
        retl
-        RETL_INSN
-
-#endif /* FASTER_ALIGNED */
+        mov            %g7, %o0
 
 86:    /* non_aligned */
        cmp             %o2, 6
        bleu            88f
+        nop
 
-#ifdef FASTER_NONALIGNED
-
-        cmp            %o2, 256
-       bcc             87f
-
-#endif /* FASTER_NONALIGNED */
-
-        andcc          %o0, 3, %g0
+       save            %sp, -96, %sp
+       andcc           %i0, 3, %g0
        be              61f
-        andcc          %o0, 1, %g0
+        andcc          %i0, 1, %g0
        be              60f
-        andcc          %o0, 2, %g0
+        andcc          %i0, 2, %g0
 
-       ldub            [%o1], %g5
-       add             %o1, 1, %o1
-       stb             %g5, [%o0]
-       sub             %o2, 1, %o2
+       ldub            [%i1], %g5
+       add             %i1, 1, %i1
+       stb             %g5, [%i0]
+       sub             %i2, 1, %i2
        bne             61f
-        add            %o0, 1, %o0
+        add            %i0, 1, %i0
 60:
-       ldub            [%o1], %g3
-       add             %o1, 2, %o1
-       stb             %g3, [%o0]
-       sub             %o2, 2, %o2
-       ldub            [%o1 - 1], %g3
-       add             %o0, 2, %o0
-       stb             %g3, [%o0 - 1]
+       ldub            [%i1], %g3
+       add             %i1, 2, %i1
+       stb             %g3, [%i0]
+       sub             %i2, 2, %i2
+       ldub            [%i1 - 1], %g3
+       add             %i0, 2, %i0
+       stb             %g3, [%i0 - 1]
 61:
-       and             %o1, 3, %g2
-       and             %o2, 0xc, %g3
-       and             %o1, -4, %o1
+       and             %i1, 3, %g2
+       and             %i2, 0xc, %g3
+       and             %i1, -4, %i1
        cmp             %g3, 4
        sll             %g2, 3, %g4
        mov             32, %g2
        be              4f
-        sub            %g2, %g4, %g7
+        sub            %g2, %g4, %l0
        
        blu             3f
         cmp            %g3, 0x8
 
        be              2f
-        srl            %o2, 2, %g3
+        srl            %i2, 2, %g3
 
-       ld              [%o1], %o3
-       add             %o0, -8, %o0
-       ld              [%o1 + 4], %o4
+       ld              [%i1], %i3
+       add             %i0, -8, %i0
+       ld              [%i1 + 4], %i4
        b               8f
         add            %g3, 1, %g3
 2:
-       ld              [%o1], %o4
-       add             %o0, -12, %o0
-       ld              [%o1 + 4], %o5
+       ld              [%i1], %i4
+       add             %i0, -12, %i0
+       ld              [%i1 + 4], %i5
        add             %g3, 2, %g3
        b               9f
-        add            %o1, -4, %o1
+        add            %i1, -4, %i1
 3:
-       ld              [%o1], %g1
-       add             %o0, -4, %o0
-       ld              [%o1 + 4], %o3
-       srl             %o2, 2, %g3
+       ld              [%i1], %g1
+       add             %i0, -4, %i0
+       ld              [%i1 + 4], %i3
+       srl             %i2, 2, %g3
        b               7f
-        add            %o1, 4, %o1
+        add            %i1, 4, %i1
 4:
-       ld              [%o1], %o5
-       cmp             %o2, 7
-       ld              [%o1 + 4], %g1
-       srl             %o2, 2, %g3
+       ld              [%i1], %i5
+       cmp             %i2, 7
+       ld              [%i1 + 4], %g1
+       srl             %i2, 2, %g3
        bleu            10f
-        add            %o1, 8, %o1
+        add            %i1, 8, %i1
 
-       ld              [%o1], %o3
+       ld              [%i1], %i3
        add             %g3, -1, %g3
 5:
-       sll             %o5, %g4, %g2
-       srl             %g1, %g7, %g5
+       sll             %i5, %g4, %g2
+       srl             %g1, %l0, %g5
        or              %g2, %g5, %g2
-       st              %g2, [%o0]
+       st              %g2, [%i0]
 7:
-       ld              [%o1 + 4], %o4
+       ld              [%i1 + 4], %i4
        sll             %g1, %g4, %g2
-       srl             %o3, %g7, %g5
+       srl             %i3, %l0, %g5
        or              %g2, %g5, %g2
-       st              %g2, [%o0 + 4]
+       st              %g2, [%i0 + 4]
 8:
-       ld              [%o1 + 8], %o5
-       sll             %o3, %g4, %g2
-       srl             %o4, %g7, %g5
+       ld              [%i1 + 8], %i5
+       sll             %i3, %g4, %g2
+       srl             %i4, %l0, %g5
        or              %g2, %g5, %g2
-       st              %g2, [%o0 + 8]
+       st              %g2, [%i0 + 8]
 9:
-       ld              [%o1 + 12], %g1
-       sll             %o4, %g4, %g2
-       srl             %o5, %g7, %g5
+       ld              [%i1 + 12], %g1
+       sll             %i4, %g4, %g2
+       srl             %i5, %l0, %g5
        addcc           %g3, -4, %g3
        or              %g2, %g5, %g2
-       add             %o1, 16, %o1
-       st              %g2, [%o0 + 12]
-       add             %o0, 16, %o0
+       add             %i1, 16, %i1
+       st              %g2, [%i0 + 12]
+       add             %i0, 16, %i0
        bne,a           5b
-        ld             [%o1], %o3
+        ld             [%i1], %i3
 10:
-       sll             %o5, %g4, %g2
-       srl             %g1, %g7, %g5
-       srl             %g7, 3, %g3
+       sll             %i5, %g4, %g2
+       srl             %g1, %l0, %g5
+       srl             %l0, 3, %g3
        or              %g2, %g5, %g2
-       sub             %o1, %g3, %o1
-       andcc           %o2, 2, %g0
-       st              %g2, [%o0]
+       sub             %i1, %g3, %i1
+       andcc           %i2, 2, %g0
+       st              %g2, [%i0]
        be              1f
-        andcc          %o2, 1, %g0
-
-       ldub            [%o1], %g2
-       add             %o1, 2, %o1
-       stb             %g2, [%o0 + 4]
-       add             %o0, 2, %o0
-       ldub            [%o1 - 1], %g2
-       stb             %g2, [%o0 + 3]
+        andcc          %i2, 1, %g0
+
+       ldub            [%i1], %g2
+       add             %i1, 2, %i1
+       stb             %g2, [%i0 + 4]
+       add             %i0, 2, %i0
+       ldub            [%i1 - 1], %g2
+       stb             %g2, [%i0 + 3]
 1:
        be              1f
         nop
-       ldub            [%o1], %g2
-       stb             %g2, [%o0 + 4]
-1:
-       retl
-        RETL_INSN
-
-#ifdef FASTER_NONALIGNED
-
-87:    /* faster_nonaligned */
-
-       andcc           %o1, 3, %g0
-       be              3f
-        andcc          %o1, 1, %g0
-
-       be              4f
-        andcc          %o1, 2, %g0
-
-       ldub            [%o1], %g2
-       add             %o1, 1, %o1
-       stb             %g2, [%o0]
-       sub             %o2, 1, %o2
-       bne             3f
-        add            %o0, 1, %o0
-4:
-       lduh            [%o1], %g2
-       add             %o1, 2, %o1
-       srl             %g2, 8, %g3
-       sub             %o2, 2, %o2
-       stb             %g3, [%o0]
-       add             %o0, 2, %o0
-       stb             %g2, [%o0 - 1]
-3:
-        andcc          %o1, 4, %g0
-
-       bne             2f
-        cmp            %o5, 1
-
-       ld              [%o1], %o4
-       srl             %o4, 24, %g2
-       stb             %g2, [%o0]
-       srl             %o4, 16, %g3
-       stb             %g3, [%o0 + 1]
-       srl             %o4, 8, %g2
-       stb             %g2, [%o0 + 2]
-       sub             %o2, 4, %o2
-       stb             %o4, [%o0 + 3]
-       add             %o1, 4, %o1
-       add             %o0, 4, %o0
-2:
-       be              33f
-        cmp            %o5, 2
-       be              32f
-        sub            %o2, 4, %o2
-31:
-       ld              [%o1], %g2
-       add             %o1, 4, %o1
-       srl             %g2, 24, %g3
-       and             %o0, 7, %g5
-       stb             %g3, [%o0]
-       cmp             %g5, 7
-       sll             %g2, 8, %g1
-       add             %o0, 4, %o0
-       be              41f
-        and            %o2, 0xffffffc0, %o3
-       ld              [%o0 - 7], %o4
-4:
-       SMOVE_CHUNK(o1, o0, 0x00, g2, g3, g4, g5, o4, o5, g7, g1, 8, 24, -3)
-       SMOVE_CHUNK(o1, o0, 0x10, g2, g3, g4, g5, o4, o5, g7, g1, 8, 24, -3)
-       SMOVE_CHUNK(o1, o0, 0x20, g2, g3, g4, g5, o4, o5, g7, g1, 8, 24, -3)
-       SMOVE_CHUNK(o1, o0, 0x30, g2, g3, g4, g5, o4, o5, g7, g1, 8, 24, -3)
-       subcc           %o3, 64, %o3
-       add             %o1, 64, %o1
-       bne             4b
-        add            %o0, 64, %o0
-
-       andcc           %o2, 0x30, %o3
-       be,a            1f
-        srl            %g1, 16, %g2
-4:
-       SMOVE_CHUNK(o1, o0, 0x00, g2, g3, g4, g5, o4, o5, g7, g1, 8, 24, -3)
-       subcc           %o3, 16, %o3
-       add             %o1, 16, %o1
-       bne             4b
-        add            %o0, 16, %o0
-
-       srl             %g1, 16, %g2
-1:
-       st              %o4, [%o0 - 7]
-       sth             %g2, [%o0 - 3]
-       srl             %g1, 8, %g4
-       b               88f
-        stb            %g4, [%o0 - 1]
-32:
-       ld              [%o1], %g2
-       add             %o1, 4, %o1
-       srl             %g2, 16, %g3
-       and             %o0, 7, %g5
-       sth             %g3, [%o0]
-       cmp             %g5, 6
-       sll             %g2, 16, %g1
-       add             %o0, 4, %o0
-       be              42f
-        and            %o2, 0xffffffc0, %o3
-       ld              [%o0 - 6], %o4
-4:
-       SMOVE_CHUNK(o1, o0, 0x00, g2, g3, g4, g5, o4, o5, g7, g1, 16, 16, -2)
-       SMOVE_CHUNK(o1, o0, 0x10, g2, g3, g4, g5, o4, o5, g7, g1, 16, 16, -2)
-       SMOVE_CHUNK(o1, o0, 0x20, g2, g3, g4, g5, o4, o5, g7, g1, 16, 16, -2)
-       SMOVE_CHUNK(o1, o0, 0x30, g2, g3, g4, g5, o4, o5, g7, g1, 16, 16, -2)
-       subcc           %o3, 64, %o3
-       add             %o1, 64, %o1
-       bne             4b
-        add            %o0, 64, %o0
-
-       andcc           %o2, 0x30, %o3
-       be,a            1f
-        srl            %g1, 16, %g2
-4:
-       SMOVE_CHUNK(o1, o0, 0x00, g2, g3, g4, g5, o4, o5, g7, g1, 16, 16, -2)
-       subcc           %o3, 16, %o3
-       add             %o1, 16, %o1
-       bne             4b
-        add            %o0, 16, %o0
-
-       srl             %g1, 16, %g2
-1:
-       st              %o4, [%o0 - 6]
-       b               88f
-        sth            %g2, [%o0 - 2]
-33:
-       ld              [%o1], %g2
-       sub             %o2, 4, %o2
-       srl             %g2, 24, %g3
-       and             %o0, 7, %g5
-       stb             %g3, [%o0]
-       cmp             %g5, 5
-       srl             %g2, 8, %g4
-       sll             %g2, 24, %g1
-       sth             %g4, [%o0 + 1]
-       add             %o1, 4, %o1
-       be              43f
-        and            %o2, 0xffffffc0, %o3
-
-       ld              [%o0 - 1], %o4
-       add             %o0, 4, %o0
-4:
-       SMOVE_CHUNK(o1, o0, 0x00, g2, g3, g4, g5, o4, o5, g7, g1, 24, 8, -1)
-       SMOVE_CHUNK(o1, o0, 0x10, g2, g3, g4, g5, o4, o5, g7, g1, 24, 8, -1)
-       SMOVE_CHUNK(o1, o0, 0x20, g2, g3, g4, g5, o4, o5, g7, g1, 24, 8, -1)
-       SMOVE_CHUNK(o1, o0, 0x30, g2, g3, g4, g5, o4, o5, g7, g1, 24, 8, -1)
-       subcc           %o3, 64, %o3
-       add             %o1, 64, %o1
-       bne             4b
-        add            %o0, 64, %o0
-
-       andcc           %o2, 0x30, %o3
-       be,a            1f
-        srl            %g1, 24, %g2
-4:
-       SMOVE_CHUNK(o1, o0, 0x00, g2, g3, g4, g5, o4, o5, g7, g1, 24, 8, -1)
-       subcc           %o3, 16, %o3
-       add             %o1, 16, %o1
-       bne             4b
-        add            %o0, 16, %o0
-
-       srl             %g1, 24, %g2
-1:
-       st              %o4, [%o0 - 5]
-       b               88f
-        stb            %g2, [%o0 - 1]
-41:
-       SMOVE_ALIGNCHUNK(o1, o0, 0x00, g2, g3, g4, g5, o4, o5, g7, g1, 8, 24, -3)
-       SMOVE_ALIGNCHUNK(o1, o0, 0x10, g2, g3, g4, g5, o4, o5, g7, g1, 8, 24, -3)
-       SMOVE_ALIGNCHUNK(o1, o0, 0x20, g2, g3, g4, g5, o4, o5, g7, g1, 8, 24, -3)
-       SMOVE_ALIGNCHUNK(o1, o0, 0x30, g2, g3, g4, g5, o4, o5, g7, g1, 8, 24, -3)
-       subcc           %o3, 64, %o3
-       add             %o1, 64, %o1
-       bne             41b
-        add            %o0, 64, %o0
-        
-       andcc           %o2, 0x30, %o3
-       be,a            1f
-        srl            %g1, 16, %g2
-4:
-       SMOVE_ALIGNCHUNK(o1, o0, 0x00, g2, g3, g4, g5, o4, o5, g7, g1, 8, 24, -3)
-       subcc           %o3, 16, %o3
-       add             %o1, 16, %o1
-       bne             4b
-        add            %o0, 16, %o0
-
-       srl             %g1, 16, %g2
+       ldub            [%i1], %g2
+       stb             %g2, [%i0 + 4]
 1:
-       sth             %g2, [%o0 - 3]
-       srl             %g1, 8, %g4
-       b               88f
-        stb            %g4, [%o0 - 1]
-43:
-       SMOVE_ALIGNCHUNK(o1, o0, 0x00, g2, g3, g4, g5, o4, o5, g7, g1, 24, 8, 3)
-       SMOVE_ALIGNCHUNK(o1, o0, 0x10, g2, g3, g4, g5, o4, o5, g7, g1, 24, 8, 3)
-       SMOVE_ALIGNCHUNK(o1, o0, 0x20, g2, g3, g4, g5, o4, o5, g7, g1, 24, 8, 3)
-       SMOVE_ALIGNCHUNK(o1, o0, 0x30, g2, g3, g4, g5, o4, o5, g7, g1, 24, 8, 3)
-       subcc           %o3, 64, %o3
-       add             %o1, 64, %o1
-       bne             43b
-        add            %o0, 64, %o0
-
-       andcc           %o2, 0x30, %o3
-       be,a            1f
-        srl            %g1, 24, %g2
-4:
-       SMOVE_ALIGNCHUNK(o1, o0, 0x00, g2, g3, g4, g5, o4, o5, g7, g1, 24, 8, 3)
-       subcc           %o3, 16, %o3
-       add             %o1, 16, %o1
-       bne             4b
-        add            %o0, 16, %o0
-
-       srl             %g1, 24, %g2
-1:
-       stb             %g2, [%o0 + 3]
-       b               88f
-        add            %o0, 4, %o0
-42:
-       SMOVE_ALIGNCHUNK(o1, o0, 0x00, g2, g3, g4, g5, o4, o5, g7, g1, 16, 16, -2)
-       SMOVE_ALIGNCHUNK(o1, o0, 0x10, g2, g3, g4, g5, o4, o5, g7, g1, 16, 16, -2)
-       SMOVE_ALIGNCHUNK(o1, o0, 0x20, g2, g3, g4, g5, o4, o5, g7, g1, 16, 16, -2)
-       SMOVE_ALIGNCHUNK(o1, o0, 0x30, g2, g3, g4, g5, o4, o5, g7, g1, 16, 16, -2)
-       subcc           %o3, 64, %o3
-       add             %o1, 64, %o1
-       bne             42b
-        add            %o0, 64, %o0
-        
-       andcc           %o2, 0x30, %o3
-       be,a            1f
-        srl            %g1, 16, %g2
-4:
-       SMOVE_ALIGNCHUNK(o1, o0, 0x00, g2, g3, g4, g5, o4, o5, g7, g1, 16, 16, -2)
-       subcc           %o3, 16, %o3
-       add             %o1, 16, %o1
-       bne             4b
-        add            %o0, 16, %o0
-
-       srl             %g1, 16, %g2
-1:
-       sth             %g2, [%o0 - 2]
-
-       /* Fall through */
-        
-#endif /* FASTER_NONALIGNED */
+       ret
+        restore        %g7, %g0, %o0
 
 88:    /* short_end */
 
@@ -1127,7 +521,7 @@ FUNC(memcpy)       /* %o0=dst %o1=src %o2=len */
        stb             %g2, [%o0]
 1:
        retl
-        RETL_INSN
+        mov            %g7, %o0
 
 90:    /* short_aligned_end */
        bne             88b
index c04f1b7a91397e6901ade2e09e498066b5697df2..3537d4b91f7407cd3e01c99ffd035a8beb2d629c 100644 (file)
@@ -7,21 +7,33 @@ obj-$(CONFIG_CRYPTO_TWOFISH_586) += twofish-i586.o
 obj-$(CONFIG_CRYPTO_SALSA20_586) += salsa20-i586.o
 
 obj-$(CONFIG_CRYPTO_AES_X86_64) += aes-x86_64.o
+obj-$(CONFIG_CRYPTO_BLOWFISH_X86_64) += blowfish-x86_64.o
 obj-$(CONFIG_CRYPTO_TWOFISH_X86_64) += twofish-x86_64.o
+obj-$(CONFIG_CRYPTO_TWOFISH_X86_64_3WAY) += twofish-x86_64-3way.o
 obj-$(CONFIG_CRYPTO_SALSA20_X86_64) += salsa20-x86_64.o
 obj-$(CONFIG_CRYPTO_AES_NI_INTEL) += aesni-intel.o
 obj-$(CONFIG_CRYPTO_GHASH_CLMUL_NI_INTEL) += ghash-clmulni-intel.o
 
 obj-$(CONFIG_CRYPTO_CRC32C_INTEL) += crc32c-intel.o
+obj-$(CONFIG_CRYPTO_SHA1_SSSE3) += sha1-ssse3.o
 
 aes-i586-y := aes-i586-asm_32.o aes_glue.o
 twofish-i586-y := twofish-i586-asm_32.o twofish_glue.o
 salsa20-i586-y := salsa20-i586-asm_32.o salsa20_glue.o
 
 aes-x86_64-y := aes-x86_64-asm_64.o aes_glue.o
+blowfish-x86_64-y := blowfish-x86_64-asm_64.o blowfish_glue.o
 twofish-x86_64-y := twofish-x86_64-asm_64.o twofish_glue.o
+twofish-x86_64-3way-y := twofish-x86_64-asm_64-3way.o twofish_glue_3way.o
 salsa20-x86_64-y := salsa20-x86_64-asm_64.o salsa20_glue.o
 
 aesni-intel-y := aesni-intel_asm.o aesni-intel_glue.o fpu.o
 
 ghash-clmulni-intel-y := ghash-clmulni-intel_asm.o ghash-clmulni-intel_glue.o
+
+# enable AVX support only when $(AS) can actually assemble the instructions
+ifeq ($(call as-instr,vpxor %xmm0$(comma)%xmm1$(comma)%xmm2,yes,no),yes)
+AFLAGS_sha1_ssse3_asm.o += -DSHA1_ENABLE_AVX_SUPPORT
+CFLAGS_sha1_ssse3_glue.o += -DSHA1_ENABLE_AVX_SUPPORT
+endif
+sha1-ssse3-y := sha1_ssse3_asm.o sha1_ssse3_glue.o
index 49ae9fe32b22079dc22c8d0bf121410285010d3d..b0b6950cc8c8850d68366b869ca39e4250827013 100644 (file)
@@ -4,6 +4,7 @@
  */
 
 #include <crypto/aes.h>
+#include <asm/aes.h>
 
 asmlinkage void aes_enc_blk(struct crypto_aes_ctx *ctx, u8 *out, const u8 *in);
 asmlinkage void aes_dec_blk(struct crypto_aes_ctx *ctx, u8 *out, const u8 *in);
diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
new file mode 100644 (file)
index 0000000..391d245
--- /dev/null
@@ -0,0 +1,390 @@
+/*
+ * Blowfish Cipher Algorithm (x86_64)
+ *
+ * Copyright (C) 2011 Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
+ * USA
+ *
+ */
+
+.file "blowfish-x86_64-asm.S"
+.text
+
+/* structure of crypto context */
+#define p      0
+#define s0     ((16 + 2) * 4)
+#define s1     ((16 + 2 + (1 * 256)) * 4)
+#define s2     ((16 + 2 + (2 * 256)) * 4)
+#define s3     ((16 + 2 + (3 * 256)) * 4)
+
+/* register macros */
+#define CTX %rdi
+#define RIO %rsi
+
+#define RX0 %rax
+#define RX1 %rbx
+#define RX2 %rcx
+#define RX3 %rdx
+
+#define RX0d %eax
+#define RX1d %ebx
+#define RX2d %ecx
+#define RX3d %edx
+
+#define RX0bl %al
+#define RX1bl %bl
+#define RX2bl %cl
+#define RX3bl %dl
+
+#define RX0bh %ah
+#define RX1bh %bh
+#define RX2bh %ch
+#define RX3bh %dh
+
+#define RT0 %rbp
+#define RT1 %rsi
+#define RT2 %r8
+#define RT3 %r9
+
+#define RT0d %ebp
+#define RT1d %esi
+#define RT2d %r8d
+#define RT3d %r9d
+
+#define RKEY %r10
+
+/***********************************************************************
+ * 1-way blowfish
+ ***********************************************************************/
+#define F() \
+       rorq $16,               RX0; \
+       movzbl RX0bh,           RT0d; \
+       movzbl RX0bl,           RT1d; \
+       rolq $16,               RX0; \
+       movl s0(CTX,RT0,4),     RT0d; \
+       addl s1(CTX,RT1,4),     RT0d; \
+       movzbl RX0bh,           RT1d; \
+       movzbl RX0bl,           RT2d; \
+       rolq $32,               RX0; \
+       xorl s2(CTX,RT1,4),     RT0d; \
+       addl s3(CTX,RT2,4),     RT0d; \
+       xorq RT0,               RX0;
+
+#define add_roundkey_enc(n) \
+       xorq p+4*(n)(CTX),      RX0;
+
+#define round_enc(n) \
+       add_roundkey_enc(n); \
+       \
+       F(); \
+       F();
+
+#define add_roundkey_dec(n) \
+       movq p+4*(n-1)(CTX),    RT0; \
+       rorq $32,               RT0; \
+       xorq RT0,               RX0;
+
+#define round_dec(n) \
+       add_roundkey_dec(n); \
+       \
+       F(); \
+       F(); \
+
+#define read_block() \
+       movq (RIO),             RX0; \
+       rorq $32,               RX0; \
+       bswapq                  RX0;
+
+#define write_block() \
+       bswapq                  RX0; \
+       movq RX0,               (RIO);
+
+#define xor_block() \
+       bswapq                  RX0; \
+       xorq RX0,               (RIO);
+
+.align 8
+.global __blowfish_enc_blk
+.type   __blowfish_enc_blk,@function;
+
+__blowfish_enc_blk:
+       /* input:
+        *      %rdi: ctx, CTX
+        *      %rsi: dst
+        *      %rdx: src
+        *      %rcx: bool, if true: xor output
+        */
+       movq %rbp, %r11;
+
+       movq %rsi, %r10;
+       movq %rdx, RIO;
+
+       read_block();
+
+       round_enc(0);
+       round_enc(2);
+       round_enc(4);
+       round_enc(6);
+       round_enc(8);
+       round_enc(10);
+       round_enc(12);
+       round_enc(14);
+       add_roundkey_enc(16);
+
+       movq %r11, %rbp;
+
+       movq %r10, RIO;
+       test %cl, %cl;
+       jnz __enc_xor;
+
+       write_block();
+       ret;
+__enc_xor:
+       xor_block();
+       ret;
+
+.align 8
+.global blowfish_dec_blk
+.type   blowfish_dec_blk,@function;
+
+blowfish_dec_blk:
+       /* input:
+        *      %rdi: ctx, CTX
+        *      %rsi: dst
+        *      %rdx: src
+        */
+       movq %rbp, %r11;
+
+       movq %rsi, %r10;
+       movq %rdx, RIO;
+
+       read_block();
+
+       round_dec(17);
+       round_dec(15);
+       round_dec(13);
+       round_dec(11);
+       round_dec(9);
+       round_dec(7);
+       round_dec(5);
+       round_dec(3);
+       add_roundkey_dec(1);
+
+       movq %r10, RIO;
+       write_block();
+
+       movq %r11, %rbp;
+
+       ret;
+
+/**********************************************************************
+  4-way blowfish, four blocks parallel
+ **********************************************************************/
+
+/* F() for 4-way. Slower when used alone/1-way, but faster when used
+ * parallel/4-way (tested on AMD Phenom II & Intel Xeon E7330).
+ */
+#define F4(x) \
+       movzbl x ## bh,         RT1d; \
+       movzbl x ## bl,         RT3d; \
+       rorq $16,               x; \
+       movzbl x ## bh,         RT0d; \
+       movzbl x ## bl,         RT2d; \
+       rorq $16,               x; \
+       movl s0(CTX,RT0,4),     RT0d; \
+       addl s1(CTX,RT2,4),     RT0d; \
+       xorl s2(CTX,RT1,4),     RT0d; \
+       addl s3(CTX,RT3,4),     RT0d; \
+       xorq RT0,               x;
+
+#define add_preloaded_roundkey4() \
+       xorq RKEY,              RX0; \
+       xorq RKEY,              RX1; \
+       xorq RKEY,              RX2; \
+       xorq RKEY,              RX3;
+
+#define preload_roundkey_enc(n) \
+       movq p+4*(n)(CTX),      RKEY;
+
+#define add_roundkey_enc4(n) \
+       add_preloaded_roundkey4(); \
+       preload_roundkey_enc(n + 2);
+
+#define round_enc4(n) \
+       add_roundkey_enc4(n); \
+       \
+       F4(RX0); \
+       F4(RX1); \
+       F4(RX2); \
+       F4(RX3); \
+       \
+       F4(RX0); \
+       F4(RX1); \
+       F4(RX2); \
+       F4(RX3);
+
+#define preload_roundkey_dec(n) \
+       movq p+4*((n)-1)(CTX),  RKEY; \
+       rorq $32,               RKEY;
+
+#define add_roundkey_dec4(n) \
+       add_preloaded_roundkey4(); \
+       preload_roundkey_dec(n - 2);
+
+#define round_dec4(n) \
+       add_roundkey_dec4(n); \
+       \
+       F4(RX0); \
+       F4(RX1); \
+       F4(RX2); \
+       F4(RX3); \
+       \
+       F4(RX0); \
+       F4(RX1); \
+       F4(RX2); \
+       F4(RX3);
+
+#define read_block4() \
+       movq (RIO),             RX0; \
+       rorq $32,               RX0; \
+       bswapq                  RX0; \
+       \
+       movq 8(RIO),            RX1; \
+       rorq $32,               RX1; \
+       bswapq                  RX1; \
+       \
+       movq 16(RIO),           RX2; \
+       rorq $32,               RX2; \
+       bswapq                  RX2; \
+       \
+       movq 24(RIO),           RX3; \
+       rorq $32,               RX3; \
+       bswapq                  RX3;
+
+#define write_block4() \
+       bswapq                  RX0; \
+       movq RX0,               (RIO); \
+       \
+       bswapq                  RX1; \
+       movq RX1,               8(RIO); \
+       \
+       bswapq                  RX2; \
+       movq RX2,               16(RIO); \
+       \
+       bswapq                  RX3; \
+       movq RX3,               24(RIO);
+
+#define xor_block4() \
+       bswapq                  RX0; \
+       xorq RX0,               (RIO); \
+       \
+       bswapq                  RX1; \
+       xorq RX1,               8(RIO); \
+       \
+       bswapq                  RX2; \
+       xorq RX2,               16(RIO); \
+       \
+       bswapq                  RX3; \
+       xorq RX3,               24(RIO);
+
+.align 8
+.global __blowfish_enc_blk_4way
+.type   __blowfish_enc_blk_4way,@function;
+
+__blowfish_enc_blk_4way:
+       /* input:
+        *      %rdi: ctx, CTX
+        *      %rsi: dst
+        *      %rdx: src
+        *      %rcx: bool, if true: xor output
+        */
+       pushq %rbp;
+       pushq %rbx;
+       pushq %rcx;
+
+       preload_roundkey_enc(0);
+
+       movq %rsi, %r11;
+       movq %rdx, RIO;
+
+       read_block4();
+
+       round_enc4(0);
+       round_enc4(2);
+       round_enc4(4);
+       round_enc4(6);
+       round_enc4(8);
+       round_enc4(10);
+       round_enc4(12);
+       round_enc4(14);
+       add_preloaded_roundkey4();
+
+       popq %rbp;
+       movq %r11, RIO;
+
+       test %bpl, %bpl;
+       jnz __enc_xor4;
+
+       write_block4();
+
+       popq %rbx;
+       popq %rbp;
+       ret;
+
+__enc_xor4:
+       xor_block4();
+
+       popq %rbx;
+       popq %rbp;
+       ret;
+
+.align 8
+.global blowfish_dec_blk_4way
+.type   blowfish_dec_blk_4way,@function;
+
+blowfish_dec_blk_4way:
+       /* input:
+        *      %rdi: ctx, CTX
+        *      %rsi: dst
+        *      %rdx: src
+        */
+       pushq %rbp;
+       pushq %rbx;
+       preload_roundkey_dec(17);
+
+       movq %rsi, %r11;
+       movq %rdx, RIO;
+
+       read_block4();
+
+       round_dec4(17);
+       round_dec4(15);
+       round_dec4(13);
+       round_dec4(11);
+       round_dec4(9);
+       round_dec4(7);
+       round_dec4(5);
+       round_dec4(3);
+       add_preloaded_roundkey4();
+
+       movq %r11, RIO;
+       write_block4();
+
+       popq %rbx;
+       popq %rbp;
+
+       ret;
+
diff --git a/arch/x86/crypto/blowfish_glue.c b/arch/x86/crypto/blowfish_glue.c
new file mode 100644 (file)
index 0000000..b05aa16
--- /dev/null
@@ -0,0 +1,492 @@
+/*
+ * Glue Code for assembler optimized version of Blowfish
+ *
+ * Copyright (c) 2011 Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
+ *
+ * CBC & ECB parts based on code (crypto/cbc.c,ecb.c) by:
+ *   Copyright (c) 2006 Herbert Xu <herbert@gondor.apana.org.au>
+ * CTR part based on code (crypto/ctr.c) by:
+ *   (C) Copyright IBM Corp. 2007 - Joy Latten <latten@us.ibm.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
+ * USA
+ *
+ */
+
+#include <crypto/blowfish.h>
+#include <linux/crypto.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <crypto/algapi.h>
+
+/* regular block cipher functions */
+asmlinkage void __blowfish_enc_blk(struct bf_ctx *ctx, u8 *dst, const u8 *src,
+                                  bool xor);
+asmlinkage void blowfish_dec_blk(struct bf_ctx *ctx, u8 *dst, const u8 *src);
+
+/* 4-way parallel cipher functions */
+asmlinkage void __blowfish_enc_blk_4way(struct bf_ctx *ctx, u8 *dst,
+                                       const u8 *src, bool xor);
+asmlinkage void blowfish_dec_blk_4way(struct bf_ctx *ctx, u8 *dst,
+                                     const u8 *src);
+
+static inline void blowfish_enc_blk(struct bf_ctx *ctx, u8 *dst, const u8 *src)
+{
+       __blowfish_enc_blk(ctx, dst, src, false);
+}
+
+static inline void blowfish_enc_blk_xor(struct bf_ctx *ctx, u8 *dst,
+                                       const u8 *src)
+{
+       __blowfish_enc_blk(ctx, dst, src, true);
+}
+
+static inline void blowfish_enc_blk_4way(struct bf_ctx *ctx, u8 *dst,
+                                        const u8 *src)
+{
+       __blowfish_enc_blk_4way(ctx, dst, src, false);
+}
+
+static inline void blowfish_enc_blk_xor_4way(struct bf_ctx *ctx, u8 *dst,
+                                     const u8 *src)
+{
+       __blowfish_enc_blk_4way(ctx, dst, src, true);
+}
+
+static void blowfish_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+{
+       blowfish_enc_blk(crypto_tfm_ctx(tfm), dst, src);
+}
+
+static void blowfish_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+{
+       blowfish_dec_blk(crypto_tfm_ctx(tfm), dst, src);
+}
+
+static struct crypto_alg bf_alg = {
+       .cra_name               =       "blowfish",
+       .cra_driver_name        =       "blowfish-asm",
+       .cra_priority           =       200,
+       .cra_flags              =       CRYPTO_ALG_TYPE_CIPHER,
+       .cra_blocksize          =       BF_BLOCK_SIZE,
+       .cra_ctxsize            =       sizeof(struct bf_ctx),
+       .cra_alignmask          =       3,
+       .cra_module             =       THIS_MODULE,
+       .cra_list               =       LIST_HEAD_INIT(bf_alg.cra_list),
+       .cra_u                  =       {
+               .cipher = {
+                       .cia_min_keysize        =       BF_MIN_KEY_SIZE,
+                       .cia_max_keysize        =       BF_MAX_KEY_SIZE,
+                       .cia_setkey             =       blowfish_setkey,
+                       .cia_encrypt            =       blowfish_encrypt,
+                       .cia_decrypt            =       blowfish_decrypt,
+               }
+       }
+};
+
+static int ecb_crypt(struct blkcipher_desc *desc, struct blkcipher_walk *walk,
+                    void (*fn)(struct bf_ctx *, u8 *, const u8 *),
+                    void (*fn_4way)(struct bf_ctx *, u8 *, const u8 *))
+{
+       struct bf_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
+       unsigned int bsize = BF_BLOCK_SIZE;
+       unsigned int nbytes;
+       int err;
+
+       err = blkcipher_walk_virt(desc, walk);
+
+       while ((nbytes = walk->nbytes)) {
+               u8 *wsrc = walk->src.virt.addr;
+               u8 *wdst = walk->dst.virt.addr;
+
+               /* Process four block batch */
+               if (nbytes >= bsize * 4) {
+                       do {
+                               fn_4way(ctx, wdst, wsrc);
+
+                               wsrc += bsize * 4;
+                               wdst += bsize * 4;
+                               nbytes -= bsize * 4;
+                       } while (nbytes >= bsize * 4);
+
+                       if (nbytes < bsize)
+                               goto done;
+               }
+
+               /* Handle leftovers */
+               do {
+                       fn(ctx, wdst, wsrc);
+
+                       wsrc += bsize;
+                       wdst += bsize;
+                       nbytes -= bsize;
+               } while (nbytes >= bsize);
+
+done:
+               err = blkcipher_walk_done(desc, walk, nbytes);
+       }
+
+       return err;
+}
+
+static int ecb_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
+                      struct scatterlist *src, unsigned int nbytes)
+{
+       struct blkcipher_walk walk;
+
+       blkcipher_walk_init(&walk, dst, src, nbytes);
+       return ecb_crypt(desc, &walk, blowfish_enc_blk, blowfish_enc_blk_4way);
+}
+
+static int ecb_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
+                      struct scatterlist *src, unsigned int nbytes)
+{
+       struct blkcipher_walk walk;
+
+       blkcipher_walk_init(&walk, dst, src, nbytes);
+       return ecb_crypt(desc, &walk, blowfish_dec_blk, blowfish_dec_blk_4way);
+}
+
+static struct crypto_alg blk_ecb_alg = {
+       .cra_name               = "ecb(blowfish)",
+       .cra_driver_name        = "ecb-blowfish-asm",
+       .cra_priority           = 300,
+       .cra_flags              = CRYPTO_ALG_TYPE_BLKCIPHER,
+       .cra_blocksize          = BF_BLOCK_SIZE,
+       .cra_ctxsize            = sizeof(struct bf_ctx),
+       .cra_alignmask          = 0,
+       .cra_type               = &crypto_blkcipher_type,
+       .cra_module             = THIS_MODULE,
+       .cra_list               = LIST_HEAD_INIT(blk_ecb_alg.cra_list),
+       .cra_u = {
+               .blkcipher = {
+                       .min_keysize    = BF_MIN_KEY_SIZE,
+                       .max_keysize    = BF_MAX_KEY_SIZE,
+                       .setkey         = blowfish_setkey,
+                       .encrypt        = ecb_encrypt,
+                       .decrypt        = ecb_decrypt,
+               },
+       },
+};
+
+static unsigned int __cbc_encrypt(struct blkcipher_desc *desc,
+                                 struct blkcipher_walk *walk)
+{
+       struct bf_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
+       unsigned int bsize = BF_BLOCK_SIZE;
+       unsigned int nbytes = walk->nbytes;
+       u64 *src = (u64 *)walk->src.virt.addr;
+       u64 *dst = (u64 *)walk->dst.virt.addr;
+       u64 *iv = (u64 *)walk->iv;
+
+       do {
+               *dst = *src ^ *iv;
+               blowfish_enc_blk(ctx, (u8 *)dst, (u8 *)dst);
+               iv = dst;
+
+               src += 1;
+               dst += 1;
+               nbytes -= bsize;
+       } while (nbytes >= bsize);
+
+       *(u64 *)walk->iv = *iv;
+       return nbytes;
+}
+
+static int cbc_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
+                      struct scatterlist *src, unsigned int nbytes)
+{
+       struct blkcipher_walk walk;
+       int err;
+
+       blkcipher_walk_init(&walk, dst, src, nbytes);
+       err = blkcipher_walk_virt(desc, &walk);
+
+       while ((nbytes = walk.nbytes)) {
+               nbytes = __cbc_encrypt(desc, &walk);
+               err = blkcipher_walk_done(desc, &walk, nbytes);
+       }
+
+       return err;
+}
+
+static unsigned int __cbc_decrypt(struct blkcipher_desc *desc,
+                                 struct blkcipher_walk *walk)
+{
+       struct bf_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
+       unsigned int bsize = BF_BLOCK_SIZE;
+       unsigned int nbytes = walk->nbytes;
+       u64 *src = (u64 *)walk->src.virt.addr;
+       u64 *dst = (u64 *)walk->dst.virt.addr;
+       u64 ivs[4 - 1];
+       u64 last_iv;
+
+       /* Start of the last block. */
+       src += nbytes / bsize - 1;
+       dst += nbytes / bsize - 1;
+
+       last_iv = *src;
+
+       /* Process four block batch */
+       if (nbytes >= bsize * 4) {
+               do {
+                       nbytes -= bsize * 4 - bsize;
+                       src -= 4 - 1;
+                       dst -= 4 - 1;
+
+                       ivs[0] = src[0];
+                       ivs[1] = src[1];
+                       ivs[2] = src[2];
+
+                       blowfish_dec_blk_4way(ctx, (u8 *)dst, (u8 *)src);
+
+                       dst[1] ^= ivs[0];
+                       dst[2] ^= ivs[1];
+                       dst[3] ^= ivs[2];
+
+                       nbytes -= bsize;
+                       if (nbytes < bsize)
+                               goto done;
+
+                       *dst ^= *(src - 1);
+                       src -= 1;
+                       dst -= 1;
+               } while (nbytes >= bsize * 4);
+
+               if (nbytes < bsize)
+                       goto done;
+       }
+
+       /* Handle leftovers */
+       for (;;) {
+               blowfish_dec_blk(ctx, (u8 *)dst, (u8 *)src);
+
+               nbytes -= bsize;
+               if (nbytes < bsize)
+                       break;
+
+               *dst ^= *(src - 1);
+               src -= 1;
+               dst -= 1;
+       }
+
+done:
+       *dst ^= *(u64 *)walk->iv;
+       *(u64 *)walk->iv = last_iv;
+
+       return nbytes;
+}
+
+static int cbc_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
+                      struct scatterlist *src, unsigned int nbytes)
+{
+       struct blkcipher_walk walk;
+       int err;
+
+       blkcipher_walk_init(&walk, dst, src, nbytes);
+       err = blkcipher_walk_virt(desc, &walk);
+
+       while ((nbytes = walk.nbytes)) {
+               nbytes = __cbc_decrypt(desc, &walk);
+               err = blkcipher_walk_done(desc, &walk, nbytes);
+       }
+
+       return err;
+}
+
+static struct crypto_alg blk_cbc_alg = {
+       .cra_name               = "cbc(blowfish)",
+       .cra_driver_name        = "cbc-blowfish-asm",
+       .cra_priority           = 300,
+       .cra_flags              = CRYPTO_ALG_TYPE_BLKCIPHER,
+       .cra_blocksize          = BF_BLOCK_SIZE,
+       .cra_ctxsize            = sizeof(struct bf_ctx),
+       .cra_alignmask          = 0,
+       .cra_type               = &crypto_blkcipher_type,
+       .cra_module             = THIS_MODULE,
+       .cra_list               = LIST_HEAD_INIT(blk_cbc_alg.cra_list),
+       .cra_u = {
+               .blkcipher = {
+                       .min_keysize    = BF_MIN_KEY_SIZE,
+                       .max_keysize    = BF_MAX_KEY_SIZE,
+                       .ivsize         = BF_BLOCK_SIZE,
+                       .setkey         = blowfish_setkey,
+                       .encrypt        = cbc_encrypt,
+                       .decrypt        = cbc_decrypt,
+               },
+       },
+};
+
+static void ctr_crypt_final(struct bf_ctx *ctx, struct blkcipher_walk *walk)
+{
+       u8 *ctrblk = walk->iv;
+       u8 keystream[BF_BLOCK_SIZE];
+       u8 *src = walk->src.virt.addr;
+       u8 *dst = walk->dst.virt.addr;
+       unsigned int nbytes = walk->nbytes;
+
+       blowfish_enc_blk(ctx, keystream, ctrblk);
+       crypto_xor(keystream, src, nbytes);
+       memcpy(dst, keystream, nbytes);
+
+       crypto_inc(ctrblk, BF_BLOCK_SIZE);
+}
+
+static unsigned int __ctr_crypt(struct blkcipher_desc *desc,
+                               struct blkcipher_walk *walk)
+{
+       struct bf_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
+       unsigned int bsize = BF_BLOCK_SIZE;
+       unsigned int nbytes = walk->nbytes;
+       u64 *src = (u64 *)walk->src.virt.addr;
+       u64 *dst = (u64 *)walk->dst.virt.addr;
+       u64 ctrblk = be64_to_cpu(*(__be64 *)walk->iv);
+       __be64 ctrblocks[4];
+
+       /* Process four block batch */
+       if (nbytes >= bsize * 4) {
+               do {
+                       if (dst != src) {
+                               dst[0] = src[0];
+                               dst[1] = src[1];
+                               dst[2] = src[2];
+                               dst[3] = src[3];
+                       }
+
+                       /* create ctrblks for parallel encrypt */
+                       ctrblocks[0] = cpu_to_be64(ctrblk++);
+                       ctrblocks[1] = cpu_to_be64(ctrblk++);
+                       ctrblocks[2] = cpu_to_be64(ctrblk++);
+                       ctrblocks[3] = cpu_to_be64(ctrblk++);
+
+                       blowfish_enc_blk_xor_4way(ctx, (u8 *)dst,
+                                                 (u8 *)ctrblocks);
+
+                       src += 4;
+                       dst += 4;
+               } while ((nbytes -= bsize * 4) >= bsize * 4);
+
+               if (nbytes < bsize)
+                       goto done;
+       }
+
+       /* Handle leftovers */
+       do {
+               if (dst != src)
+                       *dst = *src;
+
+               ctrblocks[0] = cpu_to_be64(ctrblk++);
+
+               blowfish_enc_blk_xor(ctx, (u8 *)dst, (u8 *)ctrblocks);
+
+               src += 1;
+               dst += 1;
+       } while ((nbytes -= bsize) >= bsize);
+
+done:
+       *(__be64 *)walk->iv = cpu_to_be64(ctrblk);
+       return nbytes;
+}
+
+static int ctr_crypt(struct blkcipher_desc *desc, struct scatterlist *dst,
+                    struct scatterlist *src, unsigned int nbytes)
+{
+       struct blkcipher_walk walk;
+       int err;
+
+       blkcipher_walk_init(&walk, dst, src, nbytes);
+       err = blkcipher_walk_virt_block(desc, &walk, BF_BLOCK_SIZE);
+
+       while ((nbytes = walk.nbytes) >= BF_BLOCK_SIZE) {
+               nbytes = __ctr_crypt(desc, &walk);
+               err = blkcipher_walk_done(desc, &walk, nbytes);
+       }
+
+       if (walk.nbytes) {
+               ctr_crypt_final(crypto_blkcipher_ctx(desc->tfm), &walk);
+               err = blkcipher_walk_done(desc, &walk, 0);
+       }
+
+       return err;
+}
+
+static struct crypto_alg blk_ctr_alg = {
+       .cra_name               = "ctr(blowfish)",
+       .cra_driver_name        = "ctr-blowfish-asm",
+       .cra_priority           = 300,
+       .cra_flags              = CRYPTO_ALG_TYPE_BLKCIPHER,
+       .cra_blocksize          = 1,
+       .cra_ctxsize            = sizeof(struct bf_ctx),
+       .cra_alignmask          = 0,
+       .cra_type               = &crypto_blkcipher_type,
+       .cra_module             = THIS_MODULE,
+       .cra_list               = LIST_HEAD_INIT(blk_ctr_alg.cra_list),
+       .cra_u = {
+               .blkcipher = {
+                       .min_keysize    = BF_MIN_KEY_SIZE,
+                       .max_keysize    = BF_MAX_KEY_SIZE,
+                       .ivsize         = BF_BLOCK_SIZE,
+                       .setkey         = blowfish_setkey,
+                       .encrypt        = ctr_crypt,
+                       .decrypt        = ctr_crypt,
+               },
+       },
+};
+
+static int __init init(void)
+{
+       int err;
+
+       err = crypto_register_alg(&bf_alg);
+       if (err)
+               goto bf_err;
+       err = crypto_register_alg(&blk_ecb_alg);
+       if (err)
+               goto ecb_err;
+       err = crypto_register_alg(&blk_cbc_alg);
+       if (err)
+               goto cbc_err;
+       err = crypto_register_alg(&blk_ctr_alg);
+       if (err)
+               goto ctr_err;
+
+       return 0;
+
+ctr_err:
+       crypto_unregister_alg(&blk_cbc_alg);
+cbc_err:
+       crypto_unregister_alg(&blk_ecb_alg);
+ecb_err:
+       crypto_unregister_alg(&bf_alg);
+bf_err:
+       return err;
+}
+
+static void __exit fini(void)
+{
+       crypto_unregister_alg(&blk_ctr_alg);
+       crypto_unregister_alg(&blk_cbc_alg);
+       crypto_unregister_alg(&blk_ecb_alg);
+       crypto_unregister_alg(&bf_alg);
+}
+
+module_init(init);
+module_exit(fini);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Blowfish Cipher Algorithm, asm optimized");
+MODULE_ALIAS("blowfish");
+MODULE_ALIAS("blowfish-asm");
diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
new file mode 100644 (file)
index 0000000..b2c2f57
--- /dev/null
@@ -0,0 +1,558 @@
+/*
+ * This is a SIMD SHA-1 implementation. It requires the Intel(R) Supplemental
+ * SSE3 instruction set extensions introduced in Intel Core Microarchitecture
+ * processors. CPUs supporting Intel(R) AVX extensions will get an additional
+ * boost.
+ *
+ * This work was inspired by the vectorized implementation of Dean Gaudet.
+ * Additional information on it can be found at:
+ *    http://www.arctic.org/~dean/crypto/sha1.html
+ *
+ * It was improved upon with more efficient vectorization of the message
+ * scheduling. This implementation has also been optimized for all current and
+ * several future generations of Intel CPUs.
+ *
+ * See this article for more information about the implementation details:
+ *   http://software.intel.com/en-us/articles/improving-the-performance-of-the-secure-hash-algorithm-1/
+ *
+ * Copyright (C) 2010, Intel Corp.
+ *   Authors: Maxim Locktyukhin <maxim.locktyukhin@intel.com>
+ *            Ronen Zohar <ronen.zohar@intel.com>
+ *
+ * Converted to AT&T syntax and adapted for inclusion in the Linux kernel:
+ *   Author: Mathias Krause <minipli@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#define CTX    %rdi    // arg1
+#define BUF    %rsi    // arg2
+#define CNT    %rdx    // arg3
+
+#define REG_A  %ecx
+#define REG_B  %esi
+#define REG_C  %edi
+#define REG_D  %ebp
+#define REG_E  %edx
+
+#define REG_T1 %eax
+#define REG_T2 %ebx
+
+#define K_BASE         %r8
+#define HASH_PTR       %r9
+#define BUFFER_PTR     %r10
+#define BUFFER_END     %r11
+
+#define W_TMP1 %xmm0
+#define W_TMP2 %xmm9
+
+#define W0     %xmm1
+#define W4     %xmm2
+#define W8     %xmm3
+#define W12    %xmm4
+#define W16    %xmm5
+#define W20    %xmm6
+#define W24    %xmm7
+#define W28    %xmm8
+
+#define XMM_SHUFB_BSWAP        %xmm10
+
+/* we keep window of 64 w[i]+K pre-calculated values in a circular buffer */
+#define WK(t)  (((t) & 15) * 4)(%rsp)
+#define W_PRECALC_AHEAD        16
+
+/*
+ * This macro implements the SHA-1 function's body for single 64-byte block
+ * param: function's name
+ */
+.macro SHA1_VECTOR_ASM  name
+       .global \name
+       .type   \name, @function
+       .align 32
+\name:
+       push    %rbx
+       push    %rbp
+       push    %r12
+
+       mov     %rsp, %r12
+       sub     $64, %rsp               # allocate workspace
+       and     $~15, %rsp              # align stack
+
+       mov     CTX, HASH_PTR
+       mov     BUF, BUFFER_PTR
+
+       shl     $6, CNT                 # multiply by 64
+       add     BUF, CNT
+       mov     CNT, BUFFER_END
+
+       lea     K_XMM_AR(%rip), K_BASE
+       xmm_mov BSWAP_SHUFB_CTL(%rip), XMM_SHUFB_BSWAP
+
+       SHA1_PIPELINED_MAIN_BODY
+
+       # cleanup workspace
+       mov     $8, %ecx
+       mov     %rsp, %rdi
+       xor     %rax, %rax
+       rep stosq
+
+       mov     %r12, %rsp              # deallocate workspace
+
+       pop     %r12
+       pop     %rbp
+       pop     %rbx
+       ret
+
+       .size   \name, .-\name
+.endm
+
+/*
+ * This macro implements 80 rounds of SHA-1 for one 64-byte block
+ */
+.macro SHA1_PIPELINED_MAIN_BODY
+       INIT_REGALLOC
+
+       mov       (HASH_PTR), A
+       mov      4(HASH_PTR), B
+       mov      8(HASH_PTR), C
+       mov     12(HASH_PTR), D
+       mov     16(HASH_PTR), E
+
+  .set i, 0
+  .rept W_PRECALC_AHEAD
+       W_PRECALC i
+    .set i, (i+1)
+  .endr
+
+.align 4
+1:
+       RR F1,A,B,C,D,E,0
+       RR F1,D,E,A,B,C,2
+       RR F1,B,C,D,E,A,4
+       RR F1,E,A,B,C,D,6
+       RR F1,C,D,E,A,B,8
+
+       RR F1,A,B,C,D,E,10
+       RR F1,D,E,A,B,C,12
+       RR F1,B,C,D,E,A,14
+       RR F1,E,A,B,C,D,16
+       RR F1,C,D,E,A,B,18
+
+       RR F2,A,B,C,D,E,20
+       RR F2,D,E,A,B,C,22
+       RR F2,B,C,D,E,A,24
+       RR F2,E,A,B,C,D,26
+       RR F2,C,D,E,A,B,28
+
+       RR F2,A,B,C,D,E,30
+       RR F2,D,E,A,B,C,32
+       RR F2,B,C,D,E,A,34
+       RR F2,E,A,B,C,D,36
+       RR F2,C,D,E,A,B,38
+
+       RR F3,A,B,C,D,E,40
+       RR F3,D,E,A,B,C,42
+       RR F3,B,C,D,E,A,44
+       RR F3,E,A,B,C,D,46
+       RR F3,C,D,E,A,B,48
+
+       RR F3,A,B,C,D,E,50
+       RR F3,D,E,A,B,C,52
+       RR F3,B,C,D,E,A,54
+       RR F3,E,A,B,C,D,56
+       RR F3,C,D,E,A,B,58
+
+       add     $64, BUFFER_PTR         # move to the next 64-byte block
+       cmp     BUFFER_END, BUFFER_PTR  # if the current is the last one use
+       cmovae  K_BASE, BUFFER_PTR      # dummy source to avoid buffer overrun
+
+       RR F4,A,B,C,D,E,60
+       RR F4,D,E,A,B,C,62
+       RR F4,B,C,D,E,A,64
+       RR F4,E,A,B,C,D,66
+       RR F4,C,D,E,A,B,68
+
+       RR F4,A,B,C,D,E,70
+       RR F4,D,E,A,B,C,72
+       RR F4,B,C,D,E,A,74
+       RR F4,E,A,B,C,D,76
+       RR F4,C,D,E,A,B,78
+
+       UPDATE_HASH   (HASH_PTR), A
+       UPDATE_HASH  4(HASH_PTR), B
+       UPDATE_HASH  8(HASH_PTR), C
+       UPDATE_HASH 12(HASH_PTR), D
+       UPDATE_HASH 16(HASH_PTR), E
+
+       RESTORE_RENAMED_REGS
+       cmp     K_BASE, BUFFER_PTR      # K_BASE means, we reached the end
+       jne     1b
+.endm
+
+.macro INIT_REGALLOC
+  .set A, REG_A
+  .set B, REG_B
+  .set C, REG_C
+  .set D, REG_D
+  .set E, REG_E
+  .set T1, REG_T1
+  .set T2, REG_T2
+.endm
+
+.macro RESTORE_RENAMED_REGS
+       # order is important (REG_C is where it should be)
+       mov     B, REG_B
+       mov     D, REG_D
+       mov     A, REG_A
+       mov     E, REG_E
+.endm
+
+.macro SWAP_REG_NAMES  a, b
+  .set _T, \a
+  .set \a, \b
+  .set \b, _T
+.endm
+
+.macro F1  b, c, d
+       mov     \c, T1
+       SWAP_REG_NAMES \c, T1
+       xor     \d, T1
+       and     \b, T1
+       xor     \d, T1
+.endm
+
+.macro F2  b, c, d
+       mov     \d, T1
+       SWAP_REG_NAMES \d, T1
+       xor     \c, T1
+       xor     \b, T1
+.endm
+
+.macro F3  b, c ,d
+       mov     \c, T1
+       SWAP_REG_NAMES \c, T1
+       mov     \b, T2
+       or      \b, T1
+       and     \c, T2
+       and     \d, T1
+       or      T2, T1
+.endm
+
+.macro F4  b, c, d
+       F2 \b, \c, \d
+.endm
+
+.macro UPDATE_HASH  hash, val
+       add     \hash, \val
+       mov     \val, \hash
+.endm
+
+/*
+ * RR does two rounds of SHA-1 back to back with W[] pre-calc
+ *   t1 = F(b, c, d);   e += w(i)
+ *   e += t1;           b <<= 30;   d  += w(i+1);
+ *   t1 = F(a, b, c);
+ *   d += t1;           a <<= 5;
+ *   e += a;
+ *   t1 = e;            a >>= 7;
+ *   t1 <<= 5;
+ *   d += t1;
+ */
+.macro RR  F, a, b, c, d, e, round
+       add     WK(\round), \e
+       \F   \b, \c, \d         # t1 = F(b, c, d);
+       W_PRECALC (\round + W_PRECALC_AHEAD)
+       rol     $30, \b
+       add     T1, \e
+       add     WK(\round + 1), \d
+
+       \F   \a, \b, \c
+       W_PRECALC (\round + W_PRECALC_AHEAD + 1)
+       rol     $5, \a
+       add     \a, \e
+       add     T1, \d
+       ror     $7, \a          # (a <<r 5) >>r 7) => a <<r 30)
+
+       mov     \e, T1
+       SWAP_REG_NAMES \e, T1
+
+       rol     $5, T1
+       add     T1, \d
+
+       # write:  \a, \b
+       # rotate: \a<=\d, \b<=\e, \c<=\a, \d<=\b, \e<=\c
+.endm
+
+.macro W_PRECALC  r
+  .set i, \r
+
+  .if (i < 20)
+    .set K_XMM, 0
+  .elseif (i < 40)
+    .set K_XMM, 16
+  .elseif (i < 60)
+    .set K_XMM, 32
+  .elseif (i < 80)
+    .set K_XMM, 48
+  .endif
+
+  .if ((i < 16) || ((i >= 80) && (i < (80 + W_PRECALC_AHEAD))))
+    .set i, ((\r) % 80)            # pre-compute for the next iteration
+    .if (i == 0)
+       W_PRECALC_RESET
+    .endif
+       W_PRECALC_00_15
+  .elseif (i<32)
+       W_PRECALC_16_31
+  .elseif (i < 80)   // rounds 32-79
+       W_PRECALC_32_79
+  .endif
+.endm
+
+.macro W_PRECALC_RESET
+  .set W,          W0
+  .set W_minus_04, W4
+  .set W_minus_08, W8
+  .set W_minus_12, W12
+  .set W_minus_16, W16
+  .set W_minus_20, W20
+  .set W_minus_24, W24
+  .set W_minus_28, W28
+  .set W_minus_32, W
+.endm
+
+.macro W_PRECALC_ROTATE
+  .set W_minus_32, W_minus_28
+  .set W_minus_28, W_minus_24
+  .set W_minus_24, W_minus_20
+  .set W_minus_20, W_minus_16
+  .set W_minus_16, W_minus_12
+  .set W_minus_12, W_minus_08
+  .set W_minus_08, W_minus_04
+  .set W_minus_04, W
+  .set W,          W_minus_32
+.endm
+
+.macro W_PRECALC_SSSE3
+
+.macro W_PRECALC_00_15
+       W_PRECALC_00_15_SSSE3
+.endm
+.macro W_PRECALC_16_31
+       W_PRECALC_16_31_SSSE3
+.endm
+.macro W_PRECALC_32_79
+       W_PRECALC_32_79_SSSE3
+.endm
+
+/* message scheduling pre-compute for rounds 0-15 */
+.macro W_PRECALC_00_15_SSSE3
+  .if ((i & 3) == 0)
+       movdqu  (i*4)(BUFFER_PTR), W_TMP1
+  .elseif ((i & 3) == 1)
+       pshufb  XMM_SHUFB_BSWAP, W_TMP1
+       movdqa  W_TMP1, W
+  .elseif ((i & 3) == 2)
+       paddd   (K_BASE), W_TMP1
+  .elseif ((i & 3) == 3)
+       movdqa  W_TMP1, WK(i&~3)
+       W_PRECALC_ROTATE
+  .endif
+.endm
+
+/* message scheduling pre-compute for rounds 16-31
+ *
+ * - calculating last 32 w[i] values in 8 XMM registers
+ * - pre-calculate K+w[i] values and store to mem, for later load by ALU add
+ *   instruction
+ *
+ * some "heavy-lifting" vectorization for rounds 16-31 due to w[i]->w[i-3]
+ * dependency, but improves for 32-79
+ */
+.macro W_PRECALC_16_31_SSSE3
+  # blended scheduling of vector and scalar instruction streams, one 4-wide
+  # vector iteration / 4 scalar rounds
+  .if ((i & 3) == 0)
+       movdqa  W_minus_12, W
+       palignr $8, W_minus_16, W       # w[i-14]
+       movdqa  W_minus_04, W_TMP1
+       psrldq  $4, W_TMP1              # w[i-3]
+       pxor    W_minus_08, W
+  .elseif ((i & 3) == 1)
+       pxor    W_minus_16, W_TMP1
+       pxor    W_TMP1, W
+       movdqa  W, W_TMP2
+       movdqa  W, W_TMP1
+       pslldq  $12, W_TMP2
+  .elseif ((i & 3) == 2)
+       psrld   $31, W
+       pslld   $1, W_TMP1
+       por     W, W_TMP1
+       movdqa  W_TMP2, W
+       psrld   $30, W_TMP2
+       pslld   $2, W
+  .elseif ((i & 3) == 3)
+       pxor    W, W_TMP1
+       pxor    W_TMP2, W_TMP1
+       movdqa  W_TMP1, W
+       paddd   K_XMM(K_BASE), W_TMP1
+       movdqa  W_TMP1, WK(i&~3)
+       W_PRECALC_ROTATE
+  .endif
+.endm
+
+/* message scheduling pre-compute for rounds 32-79
+ *
+ * in SHA-1 specification: w[i] = (w[i-3] ^ w[i-8]  ^ w[i-14] ^ w[i-16]) rol 1
+ * instead we do equal:    w[i] = (w[i-6] ^ w[i-16] ^ w[i-28] ^ w[i-32]) rol 2
+ * allows more efficient vectorization since w[i]=>w[i-3] dependency is broken
+ */
+.macro W_PRECALC_32_79_SSSE3
+  .if ((i & 3) == 0)
+       movdqa  W_minus_04, W_TMP1
+       pxor    W_minus_28, W           # W is W_minus_32 before xor
+       palignr $8, W_minus_08, W_TMP1
+  .elseif ((i & 3) == 1)
+       pxor    W_minus_16, W
+       pxor    W_TMP1, W
+       movdqa  W, W_TMP1
+  .elseif ((i & 3) == 2)
+       psrld   $30, W
+       pslld   $2, W_TMP1
+       por     W, W_TMP1
+  .elseif ((i & 3) == 3)
+       movdqa  W_TMP1, W
+       paddd   K_XMM(K_BASE), W_TMP1
+       movdqa  W_TMP1, WK(i&~3)
+       W_PRECALC_ROTATE
+  .endif
+.endm
+
+.endm          // W_PRECALC_SSSE3
+
+
+#define K1     0x5a827999
+#define K2     0x6ed9eba1
+#define K3     0x8f1bbcdc
+#define K4     0xca62c1d6
+
+.section .rodata
+.align 16
+
+K_XMM_AR:
+       .long K1, K1, K1, K1
+       .long K2, K2, K2, K2
+       .long K3, K3, K3, K3
+       .long K4, K4, K4, K4
+
+BSWAP_SHUFB_CTL:
+       .long 0x00010203
+       .long 0x04050607
+       .long 0x08090a0b
+       .long 0x0c0d0e0f
+
+
+.section .text
+
+W_PRECALC_SSSE3
+.macro xmm_mov a, b
+       movdqu  \a,\b
+.endm
+
+/* SSSE3 optimized implementation:
+ *  extern "C" void sha1_transform_ssse3(u32 *digest, const char *data, u32 *ws,
+ *                                       unsigned int rounds);
+ */
+SHA1_VECTOR_ASM     sha1_transform_ssse3
+
+#ifdef SHA1_ENABLE_AVX_SUPPORT
+
+.macro W_PRECALC_AVX
+
+.purgem W_PRECALC_00_15
+.macro  W_PRECALC_00_15
+    W_PRECALC_00_15_AVX
+.endm
+.purgem W_PRECALC_16_31
+.macro  W_PRECALC_16_31
+    W_PRECALC_16_31_AVX
+.endm
+.purgem W_PRECALC_32_79
+.macro  W_PRECALC_32_79
+    W_PRECALC_32_79_AVX
+.endm
+
+.macro W_PRECALC_00_15_AVX
+  .if ((i & 3) == 0)
+       vmovdqu (i*4)(BUFFER_PTR), W_TMP1
+  .elseif ((i & 3) == 1)
+       vpshufb XMM_SHUFB_BSWAP, W_TMP1, W
+  .elseif ((i & 3) == 2)
+       vpaddd  (K_BASE), W, W_TMP1
+  .elseif ((i & 3) == 3)
+       vmovdqa W_TMP1, WK(i&~3)
+       W_PRECALC_ROTATE
+  .endif
+.endm
+
+.macro W_PRECALC_16_31_AVX
+  .if ((i & 3) == 0)
+       vpalignr $8, W_minus_16, W_minus_12, W  # w[i-14]
+       vpsrldq $4, W_minus_04, W_TMP1          # w[i-3]
+       vpxor   W_minus_08, W, W
+       vpxor   W_minus_16, W_TMP1, W_TMP1
+  .elseif ((i & 3) == 1)
+       vpxor   W_TMP1, W, W
+       vpslldq $12, W, W_TMP2
+       vpslld  $1, W, W_TMP1
+  .elseif ((i & 3) == 2)
+       vpsrld  $31, W, W
+       vpor    W, W_TMP1, W_TMP1
+       vpslld  $2, W_TMP2, W
+       vpsrld  $30, W_TMP2, W_TMP2
+  .elseif ((i & 3) == 3)
+       vpxor   W, W_TMP1, W_TMP1
+       vpxor   W_TMP2, W_TMP1, W
+       vpaddd  K_XMM(K_BASE), W, W_TMP1
+       vmovdqu W_TMP1, WK(i&~3)
+       W_PRECALC_ROTATE
+  .endif
+.endm
+
+.macro W_PRECALC_32_79_AVX
+  .if ((i & 3) == 0)
+       vpalignr $8, W_minus_08, W_minus_04, W_TMP1
+       vpxor   W_minus_28, W, W                # W is W_minus_32 before xor
+  .elseif ((i & 3) == 1)
+       vpxor   W_minus_16, W_TMP1, W_TMP1
+       vpxor   W_TMP1, W, W
+  .elseif ((i & 3) == 2)
+       vpslld  $2, W, W_TMP1
+       vpsrld  $30, W, W
+       vpor    W, W_TMP1, W
+  .elseif ((i & 3) == 3)
+       vpaddd  K_XMM(K_BASE), W, W_TMP1
+       vmovdqu W_TMP1, WK(i&~3)
+       W_PRECALC_ROTATE
+  .endif
+.endm
+
+.endm    // W_PRECALC_AVX
+
+W_PRECALC_AVX
+.purgem xmm_mov
+.macro xmm_mov a, b
+       vmovdqu \a,\b
+.endm
+
+
+/* AVX optimized implementation:
+ *  extern "C" void sha1_transform_avx(u32 *digest, const char *data, u32 *ws,
+ *                                     unsigned int rounds);
+ */
+SHA1_VECTOR_ASM     sha1_transform_avx
+
+#endif
diff --git a/arch/x86/crypto/sha1_ssse3_glue.c b/arch/x86/crypto/sha1_ssse3_glue.c
new file mode 100644 (file)
index 0000000..f916499
--- /dev/null
@@ -0,0 +1,240 @@
+/*
+ * Cryptographic API.
+ *
+ * Glue code for the SHA1 Secure Hash Algorithm assembler implementation using
+ * Supplemental SSE3 instructions.
+ *
+ * This file is based on sha1_generic.c
+ *
+ * Copyright (c) Alan Smithee.
+ * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk>
+ * Copyright (c) Jean-Francois Dive <jef@linuxbe.org>
+ * Copyright (c) Mathias Krause <minipli@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ */
+
+#define pr_fmt(fmt)    KBUILD_MODNAME ": " fmt
+
+#include <crypto/internal/hash.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/mm.h>
+#include <linux/cryptohash.h>
+#include <linux/types.h>
+#include <crypto/sha.h>
+#include <asm/byteorder.h>
+#include <asm/i387.h>
+#include <asm/xcr.h>
+#include <asm/xsave.h>
+
+
+asmlinkage void sha1_transform_ssse3(u32 *digest, const char *data,
+                                    unsigned int rounds);
+#ifdef SHA1_ENABLE_AVX_SUPPORT
+asmlinkage void sha1_transform_avx(u32 *digest, const char *data,
+                                  unsigned int rounds);
+#endif
+
+static asmlinkage void (*sha1_transform_asm)(u32 *, const char *, unsigned int);
+
+
+static int sha1_ssse3_init(struct shash_desc *desc)
+{
+       struct sha1_state *sctx = shash_desc_ctx(desc);
+
+       *sctx = (struct sha1_state){
+               .state = { SHA1_H0, SHA1_H1, SHA1_H2, SHA1_H3, SHA1_H4 },
+       };
+
+       return 0;
+}
+
+static int __sha1_ssse3_update(struct shash_desc *desc, const u8 *data,
+                              unsigned int len, unsigned int partial)
+{
+       struct sha1_state *sctx = shash_desc_ctx(desc);
+       unsigned int done = 0;
+
+       sctx->count += len;
+
+       if (partial) {
+               done = SHA1_BLOCK_SIZE - partial;
+               memcpy(sctx->buffer + partial, data, done);
+               sha1_transform_asm(sctx->state, sctx->buffer, 1);
+       }
+
+       if (len - done >= SHA1_BLOCK_SIZE) {
+               const unsigned int rounds = (len - done) / SHA1_BLOCK_SIZE;
+
+               sha1_transform_asm(sctx->state, data + done, rounds);
+               done += rounds * SHA1_BLOCK_SIZE;
+       }
+
+       memcpy(sctx->buffer, data + done, len - done);
+
+       return 0;
+}
+
+static int sha1_ssse3_update(struct shash_desc *desc, const u8 *data,
+                            unsigned int len)
+{
+       struct sha1_state *sctx = shash_desc_ctx(desc);
+       unsigned int partial = sctx->count % SHA1_BLOCK_SIZE;
+       int res;
+
+       /* Handle the fast case right here */
+       if (partial + len < SHA1_BLOCK_SIZE) {
+               sctx->count += len;
+               memcpy(sctx->buffer + partial, data, len);
+
+               return 0;
+       }
+
+       if (!irq_fpu_usable()) {
+               res = crypto_sha1_update(desc, data, len);
+       } else {
+               kernel_fpu_begin();
+               res = __sha1_ssse3_update(desc, data, len, partial);
+               kernel_fpu_end();
+       }
+
+       return res;
+}
+
+
+/* Add padding and return the message digest. */
+static int sha1_ssse3_final(struct shash_desc *desc, u8 *out)
+{
+       struct sha1_state *sctx = shash_desc_ctx(desc);
+       unsigned int i, index, padlen;
+       __be32 *dst = (__be32 *)out;
+       __be64 bits;
+       static const u8 padding[SHA1_BLOCK_SIZE] = { 0x80, };
+
+       bits = cpu_to_be64(sctx->count << 3);
+
+       /* Pad out to 56 mod 64 and append length */
+       index = sctx->count % SHA1_BLOCK_SIZE;
+       padlen = (index < 56) ? (56 - index) : ((SHA1_BLOCK_SIZE+56) - index);
+       if (!irq_fpu_usable()) {
+               crypto_sha1_update(desc, padding, padlen);
+               crypto_sha1_update(desc, (const u8 *)&bits, sizeof(bits));
+       } else {
+               kernel_fpu_begin();
+               /* We need to fill a whole block for __sha1_ssse3_update() */
+               if (padlen <= 56) {
+                       sctx->count += padlen;
+                       memcpy(sctx->buffer + index, padding, padlen);
+               } else {
+                       __sha1_ssse3_update(desc, padding, padlen, index);
+               }
+               __sha1_ssse3_update(desc, (const u8 *)&bits, sizeof(bits), 56);
+               kernel_fpu_end();
+       }
+
+       /* Store state in digest */
+       for (i = 0; i < 5; i++)
+               dst[i] = cpu_to_be32(sctx->state[i]);
+
+       /* Wipe context */
+       memset(sctx, 0, sizeof(*sctx));
+
+       return 0;
+}
+
+static int sha1_ssse3_export(struct shash_desc *desc, void *out)
+{
+       struct sha1_state *sctx = shash_desc_ctx(desc);
+
+       memcpy(out, sctx, sizeof(*sctx));
+
+       return 0;
+}
+
+static int sha1_ssse3_import(struct shash_desc *desc, const void *in)
+{
+       struct sha1_state *sctx = shash_desc_ctx(desc);
+
+       memcpy(sctx, in, sizeof(*sctx));
+
+       return 0;
+}
+
+static struct shash_alg alg = {
+       .digestsize     =       SHA1_DIGEST_SIZE,
+       .init           =       sha1_ssse3_init,
+       .update         =       sha1_ssse3_update,
+       .final          =       sha1_ssse3_final,
+       .export         =       sha1_ssse3_export,
+       .import         =       sha1_ssse3_import,
+       .descsize       =       sizeof(struct sha1_state),
+       .statesize      =       sizeof(struct sha1_state),
+       .base           =       {
+               .cra_name       =       "sha1",
+               .cra_driver_name=       "sha1-ssse3",
+               .cra_priority   =       150,
+               .cra_flags      =       CRYPTO_ALG_TYPE_SHASH,
+               .cra_blocksize  =       SHA1_BLOCK_SIZE,
+               .cra_module     =       THIS_MODULE,
+       }
+};
+
+#ifdef SHA1_ENABLE_AVX_SUPPORT
+static bool __init avx_usable(void)
+{
+       u64 xcr0;
+
+       if (!cpu_has_avx || !cpu_has_osxsave)
+               return false;
+
+       xcr0 = xgetbv(XCR_XFEATURE_ENABLED_MASK);
+       if ((xcr0 & (XSTATE_SSE | XSTATE_YMM)) != (XSTATE_SSE | XSTATE_YMM)) {
+               pr_info("AVX detected but unusable.\n");
+
+               return false;
+       }
+
+       return true;
+}
+#endif
+
+static int __init sha1_ssse3_mod_init(void)
+{
+       /* test for SSSE3 first */
+       if (cpu_has_ssse3)
+               sha1_transform_asm = sha1_transform_ssse3;
+
+#ifdef SHA1_ENABLE_AVX_SUPPORT
+       /* allow AVX to override SSSE3, it's a little faster */
+       if (avx_usable())
+               sha1_transform_asm = sha1_transform_avx;
+#endif
+
+       if (sha1_transform_asm) {
+               pr_info("Using %s optimized SHA-1 implementation\n",
+                       sha1_transform_asm == sha1_transform_ssse3 ? "SSSE3"
+                                                                  : "AVX");
+               return crypto_register_shash(&alg);
+       }
+       pr_info("Neither AVX nor SSSE3 is available/usable.\n");
+
+       return -ENODEV;
+}
+
+static void __exit sha1_ssse3_mod_fini(void)
+{
+       crypto_unregister_shash(&alg);
+}
+
+module_init(sha1_ssse3_mod_init);
+module_exit(sha1_ssse3_mod_fini);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm, Supplemental SSE3 accelerated");
+
+MODULE_ALIAS("sha1");
index 575331cb2a8aa1e7b3becd10f4df475edee4bbc6..658af4bb35c9ff852033d0f4858824e92d4f623b 100644 (file)
@@ -26,7 +26,7 @@
 
 #define in_blk    12  /* input byte array address parameter*/
 #define out_blk   8  /* output byte array address parameter*/
-#define tfm       4  /* Twofish context structure */
+#define ctx       4  /* Twofish context structure */
 
 #define a_offset       0
 #define b_offset       4
@@ -229,8 +229,8 @@ twofish_enc_blk:
        push    %esi
        push    %edi
 
-       mov     tfm + 16(%esp), %ebp    /* abuse the base pointer: set new base bointer to the crypto tfm */
-       add     $crypto_tfm_ctx_offset, %ebp    /* ctx address */
+       mov     ctx + 16(%esp), %ebp    /* abuse the base pointer: set new base
+                                        * pointer to the ctx address */
        mov     in_blk+16(%esp),%edi    /* input address in edi */
 
        mov     (%edi),         %eax
@@ -285,8 +285,8 @@ twofish_dec_blk:
        push    %edi
 
 
-       mov     tfm + 16(%esp), %ebp    /* abuse the base pointer: set new base bointer to the crypto tfm */
-       add     $crypto_tfm_ctx_offset, %ebp    /* ctx address */
+       mov     ctx + 16(%esp), %ebp    /* abuse the base pointer: set new base
+                                        * pointer to the ctx address */
        mov     in_blk+16(%esp),%edi    /* input address in edi */
 
        mov     (%edi),         %eax
diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
new file mode 100644 (file)
index 0000000..5b012a2
--- /dev/null
@@ -0,0 +1,316 @@
+/*
+ * Twofish Cipher 3-way parallel algorithm (x86_64)
+ *
+ * Copyright (C) 2011 Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
+ * USA
+ *
+ */
+
+.file "twofish-x86_64-asm-3way.S"
+.text
+
+/* structure of crypto context */
+#define s0     0
+#define s1     1024
+#define s2     2048
+#define s3     3072
+#define w      4096
+#define k      4128
+
+/**********************************************************************
+  3-way twofish
+ **********************************************************************/
+#define CTX %rdi
+#define RIO %rdx
+
+#define RAB0 %rax
+#define RAB1 %rbx
+#define RAB2 %rcx
+
+#define RAB0d %eax
+#define RAB1d %ebx
+#define RAB2d %ecx
+
+#define RAB0bh %ah
+#define RAB1bh %bh
+#define RAB2bh %ch
+
+#define RAB0bl %al
+#define RAB1bl %bl
+#define RAB2bl %cl
+
+#define RCD0 %r8
+#define RCD1 %r9
+#define RCD2 %r10
+
+#define RCD0d %r8d
+#define RCD1d %r9d
+#define RCD2d %r10d
+
+#define RX0 %rbp
+#define RX1 %r11
+#define RX2 %r12
+
+#define RX0d %ebp
+#define RX1d %r11d
+#define RX2d %r12d
+
+#define RY0 %r13
+#define RY1 %r14
+#define RY2 %r15
+
+#define RY0d %r13d
+#define RY1d %r14d
+#define RY2d %r15d
+
+#define RT0 %rdx
+#define RT1 %rsi
+
+#define RT0d %edx
+#define RT1d %esi
+
+#define do16bit_ror(rot, op1, op2, T0, T1, tmp1, tmp2, ab, dst) \
+       movzbl ab ## bl,                tmp2 ## d; \
+       movzbl ab ## bh,                tmp1 ## d; \
+       rorq $(rot),                    ab; \
+       op1##l T0(CTX, tmp2, 4),        dst ## d; \
+       op2##l T1(CTX, tmp1, 4),        dst ## d;
+
+/*
+ * Combined G1 & G2 function. Reordered with help of rotates to have moves
+ * at begining.
+ */
+#define g1g2_3(ab, cd, Tx0, Tx1, Tx2, Tx3, Ty0, Ty1, Ty2, Ty3, x, y) \
+       /* G1,1 && G2,1 */ \
+       do16bit_ror(32, mov, xor, Tx0, Tx1, RT0, x ## 0, ab ## 0, x ## 0); \
+       do16bit_ror(48, mov, xor, Ty1, Ty2, RT0, y ## 0, ab ## 0, y ## 0); \
+       \
+       do16bit_ror(32, mov, xor, Tx0, Tx1, RT0, x ## 1, ab ## 1, x ## 1); \
+       do16bit_ror(48, mov, xor, Ty1, Ty2, RT0, y ## 1, ab ## 1, y ## 1); \
+       \
+       do16bit_ror(32, mov, xor, Tx0, Tx1, RT0, x ## 2, ab ## 2, x ## 2); \
+       do16bit_ror(48, mov, xor, Ty1, Ty2, RT0, y ## 2, ab ## 2, y ## 2); \
+       \
+       /* G1,2 && G2,2 */ \
+       do16bit_ror(32, xor, xor, Tx2, Tx3, RT0, RT1, ab ## 0, x ## 0); \
+       do16bit_ror(16, xor, xor, Ty3, Ty0, RT0, RT1, ab ## 0, y ## 0); \
+       xchgq cd ## 0, ab ## 0; \
+       \
+       do16bit_ror(32, xor, xor, Tx2, Tx3, RT0, RT1, ab ## 1, x ## 1); \
+       do16bit_ror(16, xor, xor, Ty3, Ty0, RT0, RT1, ab ## 1, y ## 1); \
+       xchgq cd ## 1, ab ## 1; \
+       \
+       do16bit_ror(32, xor, xor, Tx2, Tx3, RT0, RT1, ab ## 2, x ## 2); \
+       do16bit_ror(16, xor, xor, Ty3, Ty0, RT0, RT1, ab ## 2, y ## 2); \
+       xchgq cd ## 2, ab ## 2;
+
+#define enc_round_end(ab, x, y, n) \
+       addl y ## d,                    x ## d; \
+       addl x ## d,                    y ## d; \
+       addl k+4*(2*(n))(CTX),          x ## d; \
+       xorl ab ## d,                   x ## d; \
+       addl k+4*(2*(n)+1)(CTX),        y ## d; \
+       shrq $32,                       ab; \
+       roll $1,                        ab ## d; \
+       xorl y ## d,                    ab ## d; \
+       shlq $32,                       ab; \
+       rorl $1,                        x ## d; \
+       orq x,                          ab;
+
+#define dec_round_end(ba, x, y, n) \
+       addl y ## d,                    x ## d; \
+       addl x ## d,                    y ## d; \
+       addl k+4*(2*(n))(CTX),          x ## d; \
+       addl k+4*(2*(n)+1)(CTX),        y ## d; \
+       xorl ba ## d,                   y ## d; \
+       shrq $32,                       ba; \
+       roll $1,                        ba ## d; \
+       xorl x ## d,                    ba ## d; \
+       shlq $32,                       ba; \
+       rorl $1,                        y ## d; \
+       orq y,                          ba;
+
+#define encrypt_round3(ab, cd, n) \
+       g1g2_3(ab, cd, s0, s1, s2, s3, s0, s1, s2, s3, RX, RY); \
+       \
+       enc_round_end(ab ## 0, RX0, RY0, n); \
+       enc_round_end(ab ## 1, RX1, RY1, n); \
+       enc_round_end(ab ## 2, RX2, RY2, n);
+
+#define decrypt_round3(ba, dc, n) \
+       g1g2_3(ba, dc, s1, s2, s3, s0, s3, s0, s1, s2, RY, RX); \
+       \
+       dec_round_end(ba ## 0, RX0, RY0, n); \
+       dec_round_end(ba ## 1, RX1, RY1, n); \
+       dec_round_end(ba ## 2, RX2, RY2, n);
+
+#define encrypt_cycle3(ab, cd, n) \
+       encrypt_round3(ab, cd, n*2); \
+       encrypt_round3(ab, cd, (n*2)+1);
+
+#define decrypt_cycle3(ba, dc, n) \
+       decrypt_round3(ba, dc, (n*2)+1); \
+       decrypt_round3(ba, dc, (n*2));
+
+#define inpack3(in, n, xy, m) \
+       movq 4*(n)(in),                 xy ## 0; \
+       xorq w+4*m(CTX),                xy ## 0; \
+       \
+       movq 4*(4+(n))(in),             xy ## 1; \
+       xorq w+4*m(CTX),                xy ## 1; \
+       \
+       movq 4*(8+(n))(in),             xy ## 2; \
+       xorq w+4*m(CTX),                xy ## 2;
+
+#define outunpack3(op, out, n, xy, m) \
+       xorq w+4*m(CTX),                xy ## 0; \
+       op ## q xy ## 0,                4*(n)(out); \
+       \
+       xorq w+4*m(CTX),                xy ## 1; \
+       op ## q xy ## 1,                4*(4+(n))(out); \
+       \
+       xorq w+4*m(CTX),                xy ## 2; \
+       op ## q xy ## 2,                4*(8+(n))(out);
+
+#define inpack_enc3() \
+       inpack3(RIO, 0, RAB, 0); \
+       inpack3(RIO, 2, RCD, 2);
+
+#define outunpack_enc3(op) \
+       outunpack3(op, RIO, 2, RAB, 6); \
+       outunpack3(op, RIO, 0, RCD, 4);
+
+#define inpack_dec3() \
+       inpack3(RIO, 0, RAB, 4); \
+       rorq $32,                       RAB0; \
+       rorq $32,                       RAB1; \
+       rorq $32,                       RAB2; \
+       inpack3(RIO, 2, RCD, 6); \
+       rorq $32,                       RCD0; \
+       rorq $32,                       RCD1; \
+       rorq $32,                       RCD2;
+
+#define outunpack_dec3() \
+       rorq $32,                       RCD0; \
+       rorq $32,                       RCD1; \
+       rorq $32,                       RCD2; \
+       outunpack3(mov, RIO, 0, RCD, 0); \
+       rorq $32,                       RAB0; \
+       rorq $32,                       RAB1; \
+       rorq $32,                       RAB2; \
+       outunpack3(mov, RIO, 2, RAB, 2);
+
+.align 8
+.global __twofish_enc_blk_3way
+.type   __twofish_enc_blk_3way,@function;
+
+__twofish_enc_blk_3way:
+       /* input:
+        *      %rdi: ctx, CTX
+        *      %rsi: dst
+        *      %rdx: src, RIO
+        *      %rcx: bool, if true: xor output
+        */
+       pushq %r15;
+       pushq %r14;
+       pushq %r13;
+       pushq %r12;
+       pushq %rbp;
+       pushq %rbx;
+
+       pushq %rcx; /* bool xor */
+       pushq %rsi; /* dst */
+
+       inpack_enc3();
+
+       encrypt_cycle3(RAB, RCD, 0);
+       encrypt_cycle3(RAB, RCD, 1);
+       encrypt_cycle3(RAB, RCD, 2);
+       encrypt_cycle3(RAB, RCD, 3);
+       encrypt_cycle3(RAB, RCD, 4);
+       encrypt_cycle3(RAB, RCD, 5);
+       encrypt_cycle3(RAB, RCD, 6);
+       encrypt_cycle3(RAB, RCD, 7);
+
+       popq RIO; /* dst */
+       popq %rbp; /* bool xor */
+
+       testb %bpl, %bpl;
+       jnz __enc_xor3;
+
+       outunpack_enc3(mov);
+
+       popq %rbx;
+       popq %rbp;
+       popq %r12;
+       popq %r13;
+       popq %r14;
+       popq %r15;
+       ret;
+
+__enc_xor3:
+       outunpack_enc3(xor);
+
+       popq %rbx;
+       popq %rbp;
+       popq %r12;
+       popq %r13;
+       popq %r14;
+       popq %r15;
+       ret;
+
+.global twofish_dec_blk_3way
+.type   twofish_dec_blk_3way,@function;
+
+twofish_dec_blk_3way:
+       /* input:
+        *      %rdi: ctx, CTX
+        *      %rsi: dst
+        *      %rdx: src, RIO
+        */
+       pushq %r15;
+       pushq %r14;
+       pushq %r13;
+       pushq %r12;
+       pushq %rbp;
+       pushq %rbx;
+
+       pushq %rsi; /* dst */
+
+       inpack_dec3();
+
+       decrypt_cycle3(RAB, RCD, 7);
+       decrypt_cycle3(RAB, RCD, 6);
+       decrypt_cycle3(RAB, RCD, 5);
+       decrypt_cycle3(RAB, RCD, 4);
+       decrypt_cycle3(RAB, RCD, 3);
+       decrypt_cycle3(RAB, RCD, 2);
+       decrypt_cycle3(RAB, RCD, 1);
+       decrypt_cycle3(RAB, RCD, 0);
+
+       popq RIO; /* dst */
+
+       outunpack_dec3();
+
+       popq %rbx;
+       popq %rbp;
+       popq %r12;
+       popq %r13;
+       popq %r14;
+       popq %r15;
+       ret;
+
index 573aa102542e5a58714dc1b2b973b4f3e0d10a83..7bcf3fcc366839003db944ea5450c4c533d2a451 100644 (file)
 twofish_enc_blk:
        pushq    R1
 
-       /* %rdi contains the crypto tfm address */
+       /* %rdi contains the ctx address */
        /* %rsi contains the output address */
        /* %rdx contains the input address */
-       add     $crypto_tfm_ctx_offset, %rdi    /* set ctx address */
        /* ctx address is moved to free one non-rex register
        as target for the 8bit high operations */
        mov     %rdi,           %r11
@@ -274,10 +273,9 @@ twofish_enc_blk:
 twofish_dec_blk:
        pushq    R1
 
-       /* %rdi contains the crypto tfm address */
+       /* %rdi contains the ctx address */
        /* %rsi contains the output address */
        /* %rdx contains the input address */
-       add     $crypto_tfm_ctx_offset, %rdi    /* set ctx address */
        /* ctx address is moved to free one non-rex register
        as target for the 8bit high operations */
        mov     %rdi,           %r11
index cefaf8b9aa18142ff6bb6586f572a6209519d86f..dc6b3fb817fcfd6b36cb1cdf9ac111d6492d4218 100644 (file)
 #include <linux/module.h>
 #include <linux/types.h>
 
-asmlinkage void twofish_enc_blk(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
-asmlinkage void twofish_dec_blk(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
+asmlinkage void twofish_enc_blk(struct twofish_ctx *ctx, u8 *dst,
+                               const u8 *src);
+EXPORT_SYMBOL_GPL(twofish_enc_blk);
+asmlinkage void twofish_dec_blk(struct twofish_ctx *ctx, u8 *dst,
+                               const u8 *src);
+EXPORT_SYMBOL_GPL(twofish_dec_blk);
 
 static void twofish_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
 {
-       twofish_enc_blk(tfm, dst, src);
+       twofish_enc_blk(crypto_tfm_ctx(tfm), dst, src);
 }
 
 static void twofish_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
 {
-       twofish_dec_blk(tfm, dst, src);
+       twofish_dec_blk(crypto_tfm_ctx(tfm), dst, src);
 }
 
 static struct crypto_alg alg = {
diff --git a/arch/x86/crypto/twofish_glue_3way.c b/arch/x86/crypto/twofish_glue_3way.c
new file mode 100644 (file)
index 0000000..5ede9c4
--- /dev/null
@@ -0,0 +1,472 @@
+/*
+ * Glue Code for 3-way parallel assembler optimized version of Twofish
+ *
+ * Copyright (c) 2011 Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
+ *
+ * CBC & ECB parts based on code (crypto/cbc.c,ecb.c) by:
+ *   Copyright (c) 2006 Herbert Xu <herbert@gondor.apana.org.au>
+ * CTR part based on code (crypto/ctr.c) by:
+ *   (C) Copyright IBM Corp. 2007 - Joy Latten <latten@us.ibm.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
+ * USA
+ *
+ */
+
+#include <linux/crypto.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <crypto/algapi.h>
+#include <crypto/twofish.h>
+#include <crypto/b128ops.h>
+
+/* regular block cipher functions from twofish_x86_64 module */
+asmlinkage void twofish_enc_blk(struct twofish_ctx *ctx, u8 *dst,
+                               const u8 *src);
+asmlinkage void twofish_dec_blk(struct twofish_ctx *ctx, u8 *dst,
+                               const u8 *src);
+
+/* 3-way parallel cipher functions */
+asmlinkage void __twofish_enc_blk_3way(struct twofish_ctx *ctx, u8 *dst,
+                                      const u8 *src, bool xor);
+asmlinkage void twofish_dec_blk_3way(struct twofish_ctx *ctx, u8 *dst,
+                                    const u8 *src);
+
+static inline void twofish_enc_blk_3way(struct twofish_ctx *ctx, u8 *dst,
+                                       const u8 *src)
+{
+       __twofish_enc_blk_3way(ctx, dst, src, false);
+}
+
+static inline void twofish_enc_blk_xor_3way(struct twofish_ctx *ctx, u8 *dst,
+                                           const u8 *src)
+{
+       __twofish_enc_blk_3way(ctx, dst, src, true);
+}
+
+static int ecb_crypt(struct blkcipher_desc *desc, struct blkcipher_walk *walk,
+                    void (*fn)(struct twofish_ctx *, u8 *, const u8 *),
+                    void (*fn_3way)(struct twofish_ctx *, u8 *, const u8 *))
+{
+       struct twofish_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
+       unsigned int bsize = TF_BLOCK_SIZE;
+       unsigned int nbytes;
+       int err;
+
+       err = blkcipher_walk_virt(desc, walk);
+
+       while ((nbytes = walk->nbytes)) {
+               u8 *wsrc = walk->src.virt.addr;
+               u8 *wdst = walk->dst.virt.addr;
+
+               /* Process three block batch */
+               if (nbytes >= bsize * 3) {
+                       do {
+                               fn_3way(ctx, wdst, wsrc);
+
+                               wsrc += bsize * 3;
+                               wdst += bsize * 3;
+                               nbytes -= bsize * 3;
+                       } while (nbytes >= bsize * 3);
+
+                       if (nbytes < bsize)
+                               goto done;
+               }
+
+               /* Handle leftovers */
+               do {
+                       fn(ctx, wdst, wsrc);
+
+                       wsrc += bsize;
+                       wdst += bsize;
+                       nbytes -= bsize;
+               } while (nbytes >= bsize);
+
+done:
+               err = blkcipher_walk_done(desc, walk, nbytes);
+       }
+
+       return err;
+}
+
+static int ecb_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
+                      struct scatterlist *src, unsigned int nbytes)
+{
+       struct blkcipher_walk walk;
+
+       blkcipher_walk_init(&walk, dst, src, nbytes);
+       return ecb_crypt(desc, &walk, twofish_enc_blk, twofish_enc_blk_3way);
+}
+
+static int ecb_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
+                      struct scatterlist *src, unsigned int nbytes)
+{
+       struct blkcipher_walk walk;
+
+       blkcipher_walk_init(&walk, dst, src, nbytes);
+       return ecb_crypt(desc, &walk, twofish_dec_blk, twofish_dec_blk_3way);
+}
+
+static struct crypto_alg blk_ecb_alg = {
+       .cra_name               = "ecb(twofish)",
+       .cra_driver_name        = "ecb-twofish-3way",
+       .cra_priority           = 300,
+       .cra_flags              = CRYPTO_ALG_TYPE_BLKCIPHER,
+       .cra_blocksize          = TF_BLOCK_SIZE,
+       .cra_ctxsize            = sizeof(struct twofish_ctx),
+       .cra_alignmask          = 0,
+       .cra_type               = &crypto_blkcipher_type,
+       .cra_module             = THIS_MODULE,
+       .cra_list               = LIST_HEAD_INIT(blk_ecb_alg.cra_list),
+       .cra_u = {
+               .blkcipher = {
+                       .min_keysize    = TF_MIN_KEY_SIZE,
+                       .max_keysize    = TF_MAX_KEY_SIZE,
+                       .setkey         = twofish_setkey,
+                       .encrypt        = ecb_encrypt,
+                       .decrypt        = ecb_decrypt,
+               },
+       },
+};
+
+static unsigned int __cbc_encrypt(struct blkcipher_desc *desc,
+                                 struct blkcipher_walk *walk)
+{
+       struct twofish_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
+       unsigned int bsize = TF_BLOCK_SIZE;
+       unsigned int nbytes = walk->nbytes;
+       u128 *src = (u128 *)walk->src.virt.addr;
+       u128 *dst = (u128 *)walk->dst.virt.addr;
+       u128 *iv = (u128 *)walk->iv;
+
+       do {
+               u128_xor(dst, src, iv);
+               twofish_enc_blk(ctx, (u8 *)dst, (u8 *)dst);
+               iv = dst;
+
+               src += 1;
+               dst += 1;
+               nbytes -= bsize;
+       } while (nbytes >= bsize);
+
+       u128_xor((u128 *)walk->iv, (u128 *)walk->iv, iv);
+       return nbytes;
+}
+
+static int cbc_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
+                      struct scatterlist *src, unsigned int nbytes)
+{
+       struct blkcipher_walk walk;
+       int err;
+
+       blkcipher_walk_init(&walk, dst, src, nbytes);
+       err = blkcipher_walk_virt(desc, &walk);
+
+       while ((nbytes = walk.nbytes)) {
+               nbytes = __cbc_encrypt(desc, &walk);
+               err = blkcipher_walk_done(desc, &walk, nbytes);
+       }
+
+       return err;
+}
+
+static unsigned int __cbc_decrypt(struct blkcipher_desc *desc,
+                                 struct blkcipher_walk *walk)
+{
+       struct twofish_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
+       unsigned int bsize = TF_BLOCK_SIZE;
+       unsigned int nbytes = walk->nbytes;
+       u128 *src = (u128 *)walk->src.virt.addr;
+       u128 *dst = (u128 *)walk->dst.virt.addr;
+       u128 ivs[3 - 1];
+       u128 last_iv;
+
+       /* Start of the last block. */
+       src += nbytes / bsize - 1;
+       dst += nbytes / bsize - 1;
+
+       last_iv = *src;
+
+       /* Process three block batch */
+       if (nbytes >= bsize * 3) {
+               do {
+                       nbytes -= bsize * (3 - 1);
+                       src -= 3 - 1;
+                       dst -= 3 - 1;
+
+                       ivs[0] = src[0];
+                       ivs[1] = src[1];
+
+                       twofish_dec_blk_3way(ctx, (u8 *)dst, (u8 *)src);
+
+                       u128_xor(dst + 1, dst + 1, ivs + 0);
+                       u128_xor(dst + 2, dst + 2, ivs + 1);
+
+                       nbytes -= bsize;
+                       if (nbytes < bsize)
+                               goto done;
+
+                       u128_xor(dst, dst, src - 1);
+                       src -= 1;
+                       dst -= 1;
+               } while (nbytes >= bsize * 3);
+
+               if (nbytes < bsize)
+                       goto done;
+       }
+
+       /* Handle leftovers */
+       for (;;) {
+               twofish_dec_blk(ctx, (u8 *)dst, (u8 *)src);
+
+               nbytes -= bsize;
+               if (nbytes < bsize)
+                       break;
+
+               u128_xor(dst, dst, src - 1);
+               src -= 1;
+               dst -= 1;
+       }
+
+done:
+       u128_xor(dst, dst, (u128 *)walk->iv);
+       *(u128 *)walk->iv = last_iv;
+
+       return nbytes;
+}
+
+static int cbc_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
+                      struct scatterlist *src, unsigned int nbytes)
+{
+       struct blkcipher_walk walk;
+       int err;
+
+       blkcipher_walk_init(&walk, dst, src, nbytes);
+       err = blkcipher_walk_virt(desc, &walk);
+
+       while ((nbytes = walk.nbytes)) {
+               nbytes = __cbc_decrypt(desc, &walk);
+               err = blkcipher_walk_done(desc, &walk, nbytes);
+       }
+
+       return err;
+}
+
+static struct crypto_alg blk_cbc_alg = {
+       .cra_name               = "cbc(twofish)",
+       .cra_driver_name        = "cbc-twofish-3way",
+       .cra_priority           = 300,
+       .cra_flags              = CRYPTO_ALG_TYPE_BLKCIPHER,
+       .cra_blocksize          = TF_BLOCK_SIZE,
+       .cra_ctxsize            = sizeof(struct twofish_ctx),
+       .cra_alignmask          = 0,
+       .cra_type               = &crypto_blkcipher_type,
+       .cra_module             = THIS_MODULE,
+       .cra_list               = LIST_HEAD_INIT(blk_cbc_alg.cra_list),
+       .cra_u = {
+               .blkcipher = {
+                       .min_keysize    = TF_MIN_KEY_SIZE,
+                       .max_keysize    = TF_MAX_KEY_SIZE,
+                       .ivsize         = TF_BLOCK_SIZE,
+                       .setkey         = twofish_setkey,
+                       .encrypt        = cbc_encrypt,
+                       .decrypt        = cbc_decrypt,
+               },
+       },
+};
+
+static inline void u128_to_be128(be128 *dst, const u128 *src)
+{
+       dst->a = cpu_to_be64(src->a);
+       dst->b = cpu_to_be64(src->b);
+}
+
+static inline void be128_to_u128(u128 *dst, const be128 *src)
+{
+       dst->a = be64_to_cpu(src->a);
+       dst->b = be64_to_cpu(src->b);
+}
+
+static inline void u128_inc(u128 *i)
+{
+       i->b++;
+       if (!i->b)
+               i->a++;
+}
+
+static void ctr_crypt_final(struct blkcipher_desc *desc,
+                           struct blkcipher_walk *walk)
+{
+       struct twofish_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
+       u8 *ctrblk = walk->iv;
+       u8 keystream[TF_BLOCK_SIZE];
+       u8 *src = walk->src.virt.addr;
+       u8 *dst = walk->dst.virt.addr;
+       unsigned int nbytes = walk->nbytes;
+
+       twofish_enc_blk(ctx, keystream, ctrblk);
+       crypto_xor(keystream, src, nbytes);
+       memcpy(dst, keystream, nbytes);
+
+       crypto_inc(ctrblk, TF_BLOCK_SIZE);
+}
+
+static unsigned int __ctr_crypt(struct blkcipher_desc *desc,
+                               struct blkcipher_walk *walk)
+{
+       struct twofish_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
+       unsigned int bsize = TF_BLOCK_SIZE;
+       unsigned int nbytes = walk->nbytes;
+       u128 *src = (u128 *)walk->src.virt.addr;
+       u128 *dst = (u128 *)walk->dst.virt.addr;
+       u128 ctrblk;
+       be128 ctrblocks[3];
+
+       be128_to_u128(&ctrblk, (be128 *)walk->iv);
+
+       /* Process three block batch */
+       if (nbytes >= bsize * 3) {
+               do {
+                       if (dst != src) {
+                               dst[0] = src[0];
+                               dst[1] = src[1];
+                               dst[2] = src[2];
+                       }
+
+                       /* create ctrblks for parallel encrypt */
+                       u128_to_be128(&ctrblocks[0], &ctrblk);
+                       u128_inc(&ctrblk);
+                       u128_to_be128(&ctrblocks[1], &ctrblk);
+                       u128_inc(&ctrblk);
+                       u128_to_be128(&ctrblocks[2], &ctrblk);
+                       u128_inc(&ctrblk);
+
+                       twofish_enc_blk_xor_3way(ctx, (u8 *)dst,
+                                                (u8 *)ctrblocks);
+
+                       src += 3;
+                       dst += 3;
+                       nbytes -= bsize * 3;
+               } while (nbytes >= bsize * 3);
+
+               if (nbytes < bsize)
+                       goto done;
+       }
+
+       /* Handle leftovers */
+       do {
+               if (dst != src)
+                       *dst = *src;
+
+               u128_to_be128(&ctrblocks[0], &ctrblk);
+               u128_inc(&ctrblk);
+
+               twofish_enc_blk(ctx, (u8 *)ctrblocks, (u8 *)ctrblocks);
+               u128_xor(dst, dst, (u128 *)ctrblocks);
+
+               src += 1;
+               dst += 1;
+               nbytes -= bsize;
+       } while (nbytes >= bsize);
+
+done:
+       u128_to_be128((be128 *)walk->iv, &ctrblk);
+       return nbytes;
+}
+
+static int ctr_crypt(struct blkcipher_desc *desc, struct scatterlist *dst,
+                    struct scatterlist *src, unsigned int nbytes)
+{
+       struct blkcipher_walk walk;
+       int err;
+
+       blkcipher_walk_init(&walk, dst, src, nbytes);
+       err = blkcipher_walk_virt_block(desc, &walk, TF_BLOCK_SIZE);
+
+       while ((nbytes = walk.nbytes) >= TF_BLOCK_SIZE) {
+               nbytes = __ctr_crypt(desc, &walk);
+               err = blkcipher_walk_done(desc, &walk, nbytes);
+       }
+
+       if (walk.nbytes) {
+               ctr_crypt_final(desc, &walk);
+               err = blkcipher_walk_done(desc, &walk, 0);
+       }
+
+       return err;
+}
+
+static struct crypto_alg blk_ctr_alg = {
+       .cra_name               = "ctr(twofish)",
+       .cra_driver_name        = "ctr-twofish-3way",
+       .cra_priority           = 300,
+       .cra_flags              = CRYPTO_ALG_TYPE_BLKCIPHER,
+       .cra_blocksize          = 1,
+       .cra_ctxsize            = sizeof(struct twofish_ctx),
+       .cra_alignmask          = 0,
+       .cra_type               = &crypto_blkcipher_type,
+       .cra_module             = THIS_MODULE,
+       .cra_list               = LIST_HEAD_INIT(blk_ctr_alg.cra_list),
+       .cra_u = {
+               .blkcipher = {
+                       .min_keysize    = TF_MIN_KEY_SIZE,
+                       .max_keysize    = TF_MAX_KEY_SIZE,
+                       .ivsize         = TF_BLOCK_SIZE,
+                       .setkey         = twofish_setkey,
+                       .encrypt        = ctr_crypt,
+                       .decrypt        = ctr_crypt,
+               },
+       },
+};
+
+int __init init(void)
+{
+       int err;
+
+       err = crypto_register_alg(&blk_ecb_alg);
+       if (err)
+               goto ecb_err;
+       err = crypto_register_alg(&blk_cbc_alg);
+       if (err)
+               goto cbc_err;
+       err = crypto_register_alg(&blk_ctr_alg);
+       if (err)
+               goto ctr_err;
+
+       return 0;
+
+ctr_err:
+       crypto_unregister_alg(&blk_cbc_alg);
+cbc_err:
+       crypto_unregister_alg(&blk_ecb_alg);
+ecb_err:
+       return err;
+}
+
+void __exit fini(void)
+{
+       crypto_unregister_alg(&blk_ctr_alg);
+       crypto_unregister_alg(&blk_cbc_alg);
+       crypto_unregister_alg(&blk_ecb_alg);
+}
+
+module_init(init);
+module_exit(fini);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Twofish Cipher Algorithm, 3-way parallel asm optimized");
+MODULE_ALIAS("twofish");
+MODULE_ALIAS("twofish-asm");
index 54edb207ff3a0cb181811219cdc46500c8ba66d5..a6253ec1b28461e12d6f650683c6d05c99a7a7cc 100644 (file)
@@ -850,4 +850,6 @@ ia32_sys_call_table:
        .quad sys_syncfs
        .quad compat_sys_sendmmsg       /* 345 */
        .quad sys_setns
+       .quad compat_sys_process_vm_readv
+       .quad compat_sys_process_vm_writev
 ia32_syscall_end:
index 34595d5e1038615eeac0ac943a15e9bcf9f4e0d9..3925d80078642d76f1890202d55037e9442b3f03 100644 (file)
 #define                APIC_TIMER_BASE_CLKIN           0x0
 #define                APIC_TIMER_BASE_TMBASE          0x1
 #define                APIC_TIMER_BASE_DIV             0x2
+#define                APIC_LVT_TIMER_ONESHOT          (0 << 17)
 #define                APIC_LVT_TIMER_PERIODIC         (1 << 17)
+#define                APIC_LVT_TIMER_TSCDEADLINE      (2 << 17)
 #define                APIC_LVT_MASKED                 (1 << 16)
 #define                APIC_LVT_LEVEL_TRIGGER          (1 << 15)
 #define                APIC_LVT_REMOTE_IRR             (1 << 14)
index aa6a488cd075152abffb6f1b809fca7ad573c0ee..f3444f700f3619eedcc8f3fa050586148e80ad70 100644 (file)
 #define X86_FEATURE_X2APIC     (4*32+21) /* x2APIC */
 #define X86_FEATURE_MOVBE      (4*32+22) /* MOVBE instruction */
 #define X86_FEATURE_POPCNT      (4*32+23) /* POPCNT instruction */
+#define X86_FEATURE_TSC_DEADLINE_TIMER (4*32+24) /* Tsc deadline timer */
 #define X86_FEATURE_AES                (4*32+25) /* AES instructions */
 #define X86_FEATURE_XSAVE      (4*32+26) /* XSAVE/XRSTOR/XSETBV/XGETBV */
 #define X86_FEATURE_OSXSAVE    (4*32+27) /* "" XSAVE enabled in the OS */
@@ -258,7 +259,9 @@ extern const char * const x86_power_flags[32];
 #define cpu_has_xmm            boot_cpu_has(X86_FEATURE_XMM)
 #define cpu_has_xmm2           boot_cpu_has(X86_FEATURE_XMM2)
 #define cpu_has_xmm3           boot_cpu_has(X86_FEATURE_XMM3)
+#define cpu_has_ssse3          boot_cpu_has(X86_FEATURE_SSSE3)
 #define cpu_has_aes            boot_cpu_has(X86_FEATURE_AES)
+#define cpu_has_avx            boot_cpu_has(X86_FEATURE_AVX)
 #define cpu_has_ht             boot_cpu_has(X86_FEATURE_HT)
 #define cpu_has_mp             boot_cpu_has(X86_FEATURE_MP)
 #define cpu_has_nx             boot_cpu_has(X86_FEATURE_NX)
@@ -286,6 +289,7 @@ extern const char * const x86_power_flags[32];
 #define cpu_has_xmm4_2         boot_cpu_has(X86_FEATURE_XMM4_2)
 #define cpu_has_x2apic         boot_cpu_has(X86_FEATURE_X2APIC)
 #define cpu_has_xsave          boot_cpu_has(X86_FEATURE_XSAVE)
+#define cpu_has_osxsave                boot_cpu_has(X86_FEATURE_OSXSAVE)
 #define cpu_has_hypervisor     boot_cpu_has(X86_FEATURE_HYPERVISOR)
 #define cpu_has_pclmulqdq      boot_cpu_has(X86_FEATURE_PCLMULQDQ)
 #define cpu_has_perfctr_core   boot_cpu_has(X86_FEATURE_PERFCTR_CORE)
index 6040d115ef513348378fb7c6637e3ab29c6e3fac..a026507893e9b566f0578a3955472c4b1f524559 100644 (file)
@@ -262,7 +262,7 @@ struct x86_emulate_ctxt {
        struct operand dst;
        bool has_seg_override;
        u8 seg_override;
-       unsigned int d;
+       u64 d;
        int (*execute)(struct x86_emulate_ctxt *ctxt);
        int (*check_perm)(struct x86_emulate_ctxt *ctxt);
        /* modrm */
@@ -275,6 +275,8 @@ struct x86_emulate_ctxt {
        unsigned long _eip;
        /* Fields above regs are cleared together. */
        unsigned long regs[NR_VCPU_REGS];
+       struct operand memop;
+       struct operand *memopp;
        struct fetch_cache fetch;
        struct read_cache io_read;
        struct read_cache mem_read;
index dd51c83aa5de78c99757c5dcae6fa84a4940e5ea..b4973f4dab9832da8569ef17d264406ac5c668d7 100644 (file)
@@ -26,7 +26,8 @@
 #include <asm/mtrr.h>
 #include <asm/msr-index.h>
 
-#define KVM_MAX_VCPUS 64
+#define KVM_MAX_VCPUS 254
+#define KVM_SOFT_MAX_VCPUS 64
 #define KVM_MEMORY_SLOTS 32
 /* memory slots that does not exposed to userspace */
 #define KVM_PRIVATE_MEM_SLOTS 4
@@ -264,6 +265,7 @@ struct kvm_mmu {
        void (*new_cr3)(struct kvm_vcpu *vcpu);
        void (*set_cr3)(struct kvm_vcpu *vcpu, unsigned long root);
        unsigned long (*get_cr3)(struct kvm_vcpu *vcpu);
+       u64 (*get_pdptr)(struct kvm_vcpu *vcpu, int index);
        int (*page_fault)(struct kvm_vcpu *vcpu, gva_t gva, u32 err,
                          bool prefault);
        void (*inject_page_fault)(struct kvm_vcpu *vcpu,
@@ -411,8 +413,9 @@ struct kvm_vcpu_arch {
        u32  tsc_catchup_mult;
        s8   tsc_catchup_shift;
 
-       bool nmi_pending;
-       bool nmi_injected;
+       atomic_t nmi_queued;  /* unprocessed asynchronous NMIs */
+       unsigned nmi_pending; /* NMI queued after currently running handler */
+       bool nmi_injected;    /* Trying to inject an NMI this entry */
 
        struct mtrr_state_type mtrr_state;
        u32 pat;
@@ -628,14 +631,13 @@ struct kvm_x86_ops {
        void (*write_tsc_offset)(struct kvm_vcpu *vcpu, u64 offset);
 
        u64 (*compute_tsc_offset)(struct kvm_vcpu *vcpu, u64 target_tsc);
+       u64 (*read_l1_tsc)(struct kvm_vcpu *vcpu);
 
        void (*get_exit_info)(struct kvm_vcpu *vcpu, u64 *info1, u64 *info2);
 
        int (*check_intercept)(struct kvm_vcpu *vcpu,
                               struct x86_instruction_info *info,
                               enum x86_intercept_stage stage);
-
-       const struct trace_print_flags *exit_reasons_str;
 };
 
 struct kvm_arch_async_pf {
@@ -672,6 +674,8 @@ u8 kvm_get_guest_memory_type(struct kvm_vcpu *vcpu, gfn_t gfn);
 
 extern bool tdp_enabled;
 
+u64 vcpu_tsc_khz(struct kvm_vcpu *vcpu);
+
 /* control of guest tsc rate supported? */
 extern bool kvm_has_tsc_control;
 /* minimum supported tsc_khz for guests */
index d52609aeeab8d7f5bba8711c3043f22e937a9d54..a6962d9161a0f23dcd2759cc30f0290305cc144c 100644 (file)
 #define MSR_IA32_APICBASE_ENABLE       (1<<11)
 #define MSR_IA32_APICBASE_BASE         (0xfffff<<12)
 
+#define MSR_IA32_TSCDEADLINE           0x000006e0
+
 #define MSR_IA32_UCODE_WRITE           0x00000079
 #define MSR_IA32_UCODE_REV             0x0000008b
 
index 704526734bef3536adcfed591de79159b2313329..e381978068533292e67ef9dfc613b1b939671bbb 100644 (file)
@@ -99,10 +99,10 @@ struct pci_raw_ops {
                                                int reg, int len, u32 val);
 };
 
-extern struct pci_raw_ops *raw_pci_ops;
-extern struct pci_raw_ops *raw_pci_ext_ops;
+extern const struct pci_raw_ops *raw_pci_ops;
+extern const struct pci_raw_ops *raw_pci_ext_ops;
 
-extern struct pci_raw_ops pci_direct_conf1;
+extern const struct pci_raw_ops pci_direct_conf1;
 extern bool port_cf9_safe;
 
 /* arch_initcall level */
index 593485b38ab38cc501e3f975209aabfb3f710106..599c77d38f332f06fdf1e34f7449e2b7b5c81203 100644 (file)
 #define __NR_syncfs             344
 #define __NR_sendmmsg          345
 #define __NR_setns             346
+#define __NR_process_vm_readv  347
+#define __NR_process_vm_writev 348
 
 #ifdef __KERNEL__
 
-#define NR_syscalls 347
+#define NR_syscalls 349
 
 #define __ARCH_WANT_IPC_PARSE_VERSION
 #define __ARCH_WANT_OLD_READDIR
index 0a6ba337a2eb7922f60ef2293d76aced631b3f5c..0431f193c3f29f4f3cdb7fce9d84ca3d23b92571 100644 (file)
@@ -682,6 +682,10 @@ __SYSCALL(__NR_sendmmsg, sys_sendmmsg)
 __SYSCALL(__NR_setns, sys_setns)
 #define __NR_getcpu                            309
 __SYSCALL(__NR_getcpu, sys_getcpu)
+#define __NR_process_vm_readv                  310
+__SYSCALL(__NR_process_vm_readv, sys_process_vm_readv)
+#define __NR_process_vm_writev                 311
+__SYSCALL(__NR_process_vm_writev, sys_process_vm_writev)
 
 #ifndef __NO_STUBS
 #define __ARCH_WANT_OLD_READDIR
index 2caf290e989560874c1462da33018c8918894eff..31f180c21ce9171dd24780fa37f3c04f4a753b30 100644 (file)
@@ -350,6 +350,18 @@ enum vmcs_field {
 #define DEBUG_REG_ACCESS_REG(eq)        (((eq) >> 8) & 0xf) /* 11:8, general purpose reg. */
 
 
+/*
+ * Exit Qualifications for APIC-Access
+ */
+#define APIC_ACCESS_OFFSET              0xfff   /* 11:0, offset within the APIC page */
+#define APIC_ACCESS_TYPE                0xf000  /* 15:12, access type */
+#define TYPE_LINEAR_APIC_INST_READ      (0 << 12)
+#define TYPE_LINEAR_APIC_INST_WRITE     (1 << 12)
+#define TYPE_LINEAR_APIC_INST_FETCH     (2 << 12)
+#define TYPE_LINEAR_APIC_EVENT          (3 << 12)
+#define TYPE_PHYSICAL_APIC_EVENT        (10 << 12)
+#define TYPE_PHYSICAL_APIC_INST         (15 << 12)
+
 /* segment AR */
 #define SEGMENT_AR_L_MASK (1 << 13)
 
index bc19be332bc99544ccbe426975b8b0cdb136f293..9a0e31293920a51568b8ec6e6d3b204cfa0b98a1 100644 (file)
@@ -346,3 +346,5 @@ ENTRY(sys_call_table)
        .long sys_syncfs
        .long sys_sendmmsg              /* 345 */
        .long sys_setns
+       .long sys_process_vm_readv
+       .long sys_process_vm_writev
index 8b4cc5f067de5977595d2cf43d139b10acf9e2d0..f1e3be18a08ff9507ee98f1020896167efe36932 100644 (file)
 #include "x86.h"
 #include "tss.h"
 
+/*
+ * Operand types
+ */
+#define OpNone             0ull
+#define OpImplicit         1ull  /* No generic decode */
+#define OpReg              2ull  /* Register */
+#define OpMem              3ull  /* Memory */
+#define OpAcc              4ull  /* Accumulator: AL/AX/EAX/RAX */
+#define OpDI               5ull  /* ES:DI/EDI/RDI */
+#define OpMem64            6ull  /* Memory, 64-bit */
+#define OpImmUByte         7ull  /* Zero-extended 8-bit immediate */
+#define OpDX               8ull  /* DX register */
+#define OpCL               9ull  /* CL register (for shifts) */
+#define OpImmByte         10ull  /* 8-bit sign extended immediate */
+#define OpOne             11ull  /* Implied 1 */
+#define OpImm             12ull  /* Sign extended immediate */
+#define OpMem16           13ull  /* Memory operand (16-bit). */
+#define OpMem32           14ull  /* Memory operand (32-bit). */
+#define OpImmU            15ull  /* Immediate operand, zero extended */
+#define OpSI              16ull  /* SI/ESI/RSI */
+#define OpImmFAddr        17ull  /* Immediate far address */
+#define OpMemFAddr        18ull  /* Far address in memory */
+#define OpImmU16          19ull  /* Immediate operand, 16 bits, zero extended */
+#define OpES              20ull  /* ES */
+#define OpCS              21ull  /* CS */
+#define OpSS              22ull  /* SS */
+#define OpDS              23ull  /* DS */
+#define OpFS              24ull  /* FS */
+#define OpGS              25ull  /* GS */
+
+#define OpBits             5  /* Width of operand field */
+#define OpMask             ((1ull << OpBits) - 1)
+
 /*
  * Opcode effective-address decode tables.
  * Note that we only emulate instructions that have at least one memory
 /* Operand sizes: 8-bit operands or specified/overridden size. */
 #define ByteOp      (1<<0)     /* 8-bit operands. */
 /* Destination operand type. */
-#define ImplicitOps (1<<1)     /* Implicit in opcode. No generic decode. */
-#define DstReg      (2<<1)     /* Register operand. */
-#define DstMem      (3<<1)     /* Memory operand. */
-#define DstAcc      (4<<1)     /* Destination Accumulator */
-#define DstDI       (5<<1)     /* Destination is in ES:(E)DI */
-#define DstMem64    (6<<1)     /* 64bit memory operand */
-#define DstImmUByte (7<<1)     /* 8-bit unsigned immediate operand */
-#define DstDX       (8<<1)     /* Destination is in DX register */
-#define DstMask     (0xf<<1)
+#define DstShift    1
+#define ImplicitOps (OpImplicit << DstShift)
+#define DstReg      (OpReg << DstShift)
+#define DstMem      (OpMem << DstShift)
+#define DstAcc      (OpAcc << DstShift)
+#define DstDI       (OpDI << DstShift)
+#define DstMem64    (OpMem64 << DstShift)
+#define DstImmUByte (OpImmUByte << DstShift)
+#define DstDX       (OpDX << DstShift)
+#define DstMask     (OpMask << DstShift)
 /* Source operand type. */
-#define SrcNone     (0<<5)     /* No source operand. */
-#define SrcReg      (1<<5)     /* Register operand. */
-#define SrcMem      (2<<5)     /* Memory operand. */
-#define SrcMem16    (3<<5)     /* Memory operand (16-bit). */
-#define SrcMem32    (4<<5)     /* Memory operand (32-bit). */
-#define SrcImm      (5<<5)     /* Immediate operand. */
-#define SrcImmByte  (6<<5)     /* 8-bit sign-extended immediate operand. */
-#define SrcOne      (7<<5)     /* Implied '1' */
-#define SrcImmUByte (8<<5)      /* 8-bit unsigned immediate operand. */
-#define SrcImmU     (9<<5)      /* Immediate operand, unsigned */
-#define SrcSI       (0xa<<5)   /* Source is in the DS:RSI */
-#define SrcImmFAddr (0xb<<5)   /* Source is immediate far address */
-#define SrcMemFAddr (0xc<<5)   /* Source is far address in memory */
-#define SrcAcc      (0xd<<5)   /* Source Accumulator */
-#define SrcImmU16   (0xe<<5)    /* Immediate operand, unsigned, 16 bits */
-#define SrcDX       (0xf<<5)   /* Source is in DX register */
-#define SrcMask     (0xf<<5)
-/* Generic ModRM decode. */
-#define ModRM       (1<<9)
-/* Destination is only written; never read. */
-#define Mov         (1<<10)
+#define SrcShift    6
+#define SrcNone     (OpNone << SrcShift)
+#define SrcReg      (OpReg << SrcShift)
+#define SrcMem      (OpMem << SrcShift)
+#define SrcMem16    (OpMem16 << SrcShift)
+#define SrcMem32    (OpMem32 << SrcShift)
+#define SrcImm      (OpImm << SrcShift)
+#define SrcImmByte  (OpImmByte << SrcShift)
+#define SrcOne      (OpOne << SrcShift)
+#define SrcImmUByte (OpImmUByte << SrcShift)
+#define SrcImmU     (OpImmU << SrcShift)
+#define SrcSI       (OpSI << SrcShift)
+#define SrcImmFAddr (OpImmFAddr << SrcShift)
+#define SrcMemFAddr (OpMemFAddr << SrcShift)
+#define SrcAcc      (OpAcc << SrcShift)
+#define SrcImmU16   (OpImmU16 << SrcShift)
+#define SrcDX       (OpDX << SrcShift)
+#define SrcMask     (OpMask << SrcShift)
 #define BitOp       (1<<11)
 #define MemAbs      (1<<12)      /* Memory operand is absolute displacement */
 #define String      (1<<13)     /* String instruction (rep capable) */
 #define Prefix      (3<<15)     /* Instruction varies with 66/f2/f3 prefix */
 #define RMExt       (4<<15)     /* Opcode extension in ModRM r/m if mod == 3 */
 #define Sse         (1<<18)     /* SSE Vector instruction */
+/* Generic ModRM decode. */
+#define ModRM       (1<<19)
+/* Destination is only written; never read. */
+#define Mov         (1<<20)
 /* Misc flags */
 #define Prot        (1<<21) /* instruction generates #UD if not in prot-mode */
 #define VendorSpecific (1<<22) /* Vendor specific instruction */
 #define Priv        (1<<27) /* instruction generates #GP if current CPL != 0 */
 #define No64       (1<<28)
 /* Source 2 operand type */
-#define Src2None    (0<<29)
-#define Src2CL      (1<<29)
-#define Src2ImmByte (2<<29)
-#define Src2One     (3<<29)
-#define Src2Imm     (4<<29)
-#define Src2Mask    (7<<29)
+#define Src2Shift   (29)
+#define Src2None    (OpNone << Src2Shift)
+#define Src2CL      (OpCL << Src2Shift)
+#define Src2ImmByte (OpImmByte << Src2Shift)
+#define Src2One     (OpOne << Src2Shift)
+#define Src2Imm     (OpImm << Src2Shift)
+#define Src2ES      (OpES << Src2Shift)
+#define Src2CS      (OpCS << Src2Shift)
+#define Src2SS      (OpSS << Src2Shift)
+#define Src2DS      (OpDS << Src2Shift)
+#define Src2FS      (OpFS << Src2Shift)
+#define Src2GS      (OpGS << Src2Shift)
+#define Src2Mask    (OpMask << Src2Shift)
 
 #define X2(x...) x, x
 #define X3(x...) X2(x), x
 #define X16(x...) X8(x), X8(x)
 
 struct opcode {
-       u32 flags;
-       u8 intercept;
+       u64 flags : 56;
+       u64 intercept : 8;
        union {
                int (*execute)(struct x86_emulate_ctxt *ctxt);
                struct opcode *group;
@@ -205,105 +247,100 @@ struct gprefix {
 #define ON64(x)
 #endif
 
-#define ____emulate_2op(_op, _src, _dst, _eflags, _x, _y, _suffix, _dsttype) \
+#define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype)  \
        do {                                                            \
                __asm__ __volatile__ (                                  \
                        _PRE_EFLAGS("0", "4", "2")                      \
                        _op _suffix " %"_x"3,%1; "                      \
                        _POST_EFLAGS("0", "4", "2")                     \
-                       : "=m" (_eflags), "+q" (*(_dsttype*)&(_dst).val),\
+                       : "=m" ((ctxt)->eflags),                        \
+                         "+q" (*(_dsttype*)&(ctxt)->dst.val),          \
                          "=&r" (_tmp)                                  \
-                       : _y ((_src).val), "i" (EFLAGS_MASK));          \
+                       : _y ((ctxt)->src.val), "i" (EFLAGS_MASK));     \
        } while (0)
 
 
 /* Raw emulation: instruction has two explicit operands. */
-#define __emulate_2op_nobyte(_op,_src,_dst,_eflags,_wx,_wy,_lx,_ly,_qx,_qy) \
+#define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy)         \
        do {                                                            \
                unsigned long _tmp;                                     \
                                                                        \
-               switch ((_dst).bytes) {                                 \
+               switch ((ctxt)->dst.bytes) {                            \
                case 2:                                                 \
-                       ____emulate_2op(_op,_src,_dst,_eflags,_wx,_wy,"w",u16);\
+                       ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16);      \
                        break;                                          \
                case 4:                                                 \
-                       ____emulate_2op(_op,_src,_dst,_eflags,_lx,_ly,"l",u32);\
+                       ____emulate_2op(ctxt,_op,_lx,_ly,"l",u32);      \
                        break;                                          \
                case 8:                                                 \
-                       ON64(____emulate_2op(_op,_src,_dst,_eflags,_qx,_qy,"q",u64)); \
+                       ON64(____emulate_2op(ctxt,_op,_qx,_qy,"q",u64)); \
                        break;                                          \
                }                                                       \
        } while (0)
 
-#define __emulate_2op(_op,_src,_dst,_eflags,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
+#define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy)                     \
        do {                                                                 \
                unsigned long _tmp;                                          \
-               switch ((_dst).bytes) {                                      \
+               switch ((ctxt)->dst.bytes) {                                 \
                case 1:                                                      \
-                       ____emulate_2op(_op,_src,_dst,_eflags,_bx,_by,"b",u8); \
+                       ____emulate_2op(ctxt,_op,_bx,_by,"b",u8);            \
                        break;                                               \
                default:                                                     \
-                       __emulate_2op_nobyte(_op, _src, _dst, _eflags,       \
+                       __emulate_2op_nobyte(ctxt, _op,                      \
                                             _wx, _wy, _lx, _ly, _qx, _qy);  \
                        break;                                               \
                }                                                            \
        } while (0)
 
 /* Source operand is byte-sized and may be restricted to just %cl. */
-#define emulate_2op_SrcB(_op, _src, _dst, _eflags)                      \
-       __emulate_2op(_op, _src, _dst, _eflags,                         \
-                     "b", "c", "b", "c", "b", "c", "b", "c")
+#define emulate_2op_SrcB(ctxt, _op)                                    \
+       __emulate_2op(ctxt, _op, "b", "c", "b", "c", "b", "c", "b", "c")
 
 /* Source operand is byte, word, long or quad sized. */
-#define emulate_2op_SrcV(_op, _src, _dst, _eflags)                      \
-       __emulate_2op(_op, _src, _dst, _eflags,                         \
-                     "b", "q", "w", "r", _LO32, "r", "", "r")
+#define emulate_2op_SrcV(ctxt, _op)                                    \
+       __emulate_2op(ctxt, _op, "b", "q", "w", "r", _LO32, "r", "", "r")
 
 /* Source operand is word, long or quad sized. */
-#define emulate_2op_SrcV_nobyte(_op, _src, _dst, _eflags)               \
-       __emulate_2op_nobyte(_op, _src, _dst, _eflags,                  \
-                            "w", "r", _LO32, "r", "", "r")
+#define emulate_2op_SrcV_nobyte(ctxt, _op)                             \
+       __emulate_2op_nobyte(ctxt, _op, "w", "r", _LO32, "r", "", "r")
 
 /* Instruction has three operands and one operand is stored in ECX register */
-#define __emulate_2op_cl(_op, _cl, _src, _dst, _eflags, _suffix, _type)        \
+#define __emulate_2op_cl(ctxt, _op, _suffix, _type)            \
        do {                                                            \
                unsigned long _tmp;                                     \
-               _type _clv  = (_cl).val;                                \
-               _type _srcv = (_src).val;                               \
-               _type _dstv = (_dst).val;                               \
+               _type _clv  = (ctxt)->src2.val;                         \
+               _type _srcv = (ctxt)->src.val;                          \
+               _type _dstv = (ctxt)->dst.val;                          \
                                                                        \
                __asm__ __volatile__ (                                  \
                        _PRE_EFLAGS("0", "5", "2")                      \
                        _op _suffix " %4,%1 \n"                         \
                        _POST_EFLAGS("0", "5", "2")                     \
-                       : "=m" (_eflags), "+r" (_dstv), "=&r" (_tmp)    \
+                       : "=m" ((ctxt)->eflags), "+r" (_dstv), "=&r" (_tmp) \
                        : "c" (_clv) , "r" (_srcv), "i" (EFLAGS_MASK)   \
                        );                                              \
                                                                        \
-               (_cl).val  = (unsigned long) _clv;                      \
-               (_src).val = (unsigned long) _srcv;                     \
-               (_dst).val = (unsigned long) _dstv;                     \
+               (ctxt)->src2.val  = (unsigned long) _clv;               \
+               (ctxt)->src2.val = (unsigned long) _srcv;               \
+               (ctxt)->dst.val = (unsigned long) _dstv;                \
        } while (0)
 
-#define emulate_2op_cl(_op, _cl, _src, _dst, _eflags)                  \
+#define emulate_2op_cl(ctxt, _op)                                      \
        do {                                                            \
-               switch ((_dst).bytes) {                                 \
+               switch ((ctxt)->dst.bytes) {                            \
                case 2:                                                 \
-                       __emulate_2op_cl(_op, _cl, _src, _dst, _eflags, \
-                                        "w", unsigned short);          \
+                       __emulate_2op_cl(ctxt, _op, "w", u16);          \
                        break;                                          \
                case 4:                                                 \
-                       __emulate_2op_cl(_op, _cl, _src, _dst, _eflags, \
-                                        "l", unsigned int);            \
+                       __emulate_2op_cl(ctxt, _op, "l", u32);          \
                        break;                                          \
                case 8:                                                 \
-                       ON64(__emulate_2op_cl(_op, _cl, _src, _dst, _eflags, \
-                                             "q", unsigned long));     \
+                       ON64(__emulate_2op_cl(ctxt, _op, "q", ulong));  \
                        break;                                          \
                }                                                       \
        } while (0)
 
-#define __emulate_1op(_op, _dst, _eflags, _suffix)                     \
+#define __emulate_1op(ctxt, _op, _suffix)                              \
        do {                                                            \
                unsigned long _tmp;                                     \
                                                                        \
@@ -311,39 +348,27 @@ struct gprefix {
                        _PRE_EFLAGS("0", "3", "2")                      \
                        _op _suffix " %1; "                             \
                        _POST_EFLAGS("0", "3", "2")                     \
-                       : "=m" (_eflags), "+m" ((_dst).val),            \
+                       : "=m" ((ctxt)->eflags), "+m" ((ctxt)->dst.val), \
                          "=&r" (_tmp)                                  \
                        : "i" (EFLAGS_MASK));                           \
        } while (0)
 
 /* Instruction has only one explicit operand (no source operand). */
-#define emulate_1op(_op, _dst, _eflags)                                    \
+#define emulate_1op(ctxt, _op)                                         \
        do {                                                            \
-               switch ((_dst).bytes) {                                 \
-               case 1: __emulate_1op(_op, _dst, _eflags, "b"); break;  \
-               case 2: __emulate_1op(_op, _dst, _eflags, "w"); break;  \
-               case 4: __emulate_1op(_op, _dst, _eflags, "l"); break;  \
-               case 8: ON64(__emulate_1op(_op, _dst, _eflags, "q")); break; \
+               switch ((ctxt)->dst.bytes) {                            \
+               case 1: __emulate_1op(ctxt, _op, "b"); break;           \
+               case 2: __emulate_1op(ctxt, _op, "w"); break;           \
+               case 4: __emulate_1op(ctxt, _op, "l"); break;           \
+               case 8: ON64(__emulate_1op(ctxt, _op, "q")); break;     \
                }                                                       \
        } while (0)
 
-#define __emulate_1op_rax_rdx(_op, _src, _rax, _rdx, _eflags, _suffix)         \
-       do {                                                            \
-               unsigned long _tmp;                                     \
-                                                                       \
-               __asm__ __volatile__ (                                  \
-                       _PRE_EFLAGS("0", "4", "1")                      \
-                       _op _suffix " %5; "                             \
-                       _POST_EFLAGS("0", "4", "1")                     \
-                       : "=m" (_eflags), "=&r" (_tmp),                 \
-                         "+a" (_rax), "+d" (_rdx)                      \
-                       : "i" (EFLAGS_MASK), "m" ((_src).val),          \
-                         "a" (_rax), "d" (_rdx));                      \
-       } while (0)
-
-#define __emulate_1op_rax_rdx_ex(_op, _src, _rax, _rdx, _eflags, _suffix, _ex) \
+#define __emulate_1op_rax_rdx(ctxt, _op, _suffix, _ex)                 \
        do {                                                            \
                unsigned long _tmp;                                     \
+               ulong *rax = &(ctxt)->regs[VCPU_REGS_RAX];              \
+               ulong *rdx = &(ctxt)->regs[VCPU_REGS_RDX];              \
                                                                        \
                __asm__ __volatile__ (                                  \
                        _PRE_EFLAGS("0", "5", "1")                      \
@@ -356,53 +381,27 @@ struct gprefix {
                        "jmp 2b \n\t"                                   \
                        ".popsection \n\t"                              \
                        _ASM_EXTABLE(1b, 3b)                            \
-                       : "=m" (_eflags), "=&r" (_tmp),                 \
-                         "+a" (_rax), "+d" (_rdx), "+qm"(_ex)          \
-                       : "i" (EFLAGS_MASK), "m" ((_src).val),          \
-                         "a" (_rax), "d" (_rdx));                      \
+                       : "=m" ((ctxt)->eflags), "=&r" (_tmp),          \
+                         "+a" (*rax), "+d" (*rdx), "+qm"(_ex)          \
+                       : "i" (EFLAGS_MASK), "m" ((ctxt)->src.val),     \
+                         "a" (*rax), "d" (*rdx));                      \
        } while (0)
 
 /* instruction has only one source operand, destination is implicit (e.g. mul, div, imul, idiv) */
-#define emulate_1op_rax_rdx(_op, _src, _rax, _rdx, _eflags)            \
+#define emulate_1op_rax_rdx(ctxt, _op, _ex)    \
        do {                                                            \
-               switch((_src).bytes) {                                  \
+               switch((ctxt)->src.bytes) {                             \
                case 1:                                                 \
-                       __emulate_1op_rax_rdx(_op, _src, _rax, _rdx,    \
-                                             _eflags, "b");            \
+                       __emulate_1op_rax_rdx(ctxt, _op, "b", _ex);     \
                        break;                                          \
                case 2:                                                 \
-                       __emulate_1op_rax_rdx(_op, _src, _rax, _rdx,    \
-                                             _eflags, "w");            \
+                       __emulate_1op_rax_rdx(ctxt, _op, "w", _ex);     \
                        break;                                          \
                case 4:                                                 \
-                       __emulate_1op_rax_rdx(_op, _src, _rax, _rdx,    \
-                                             _eflags, "l");            \
-                       break;                                          \
-               case 8:                                                 \
-                       ON64(__emulate_1op_rax_rdx(_op, _src, _rax, _rdx, \
-                                                  _eflags, "q"));      \
-                       break;                                          \
-               }                                                       \
-       } while (0)
-
-#define emulate_1op_rax_rdx_ex(_op, _src, _rax, _rdx, _eflags, _ex)    \
-       do {                                                            \
-               switch((_src).bytes) {                                  \
-               case 1:                                                 \
-                       __emulate_1op_rax_rdx_ex(_op, _src, _rax, _rdx, \
-                                                _eflags, "b", _ex);    \
-                       break;                                          \
-               case 2:                                                 \
-                       __emulate_1op_rax_rdx_ex(_op, _src, _rax, _rdx, \
-                                                _eflags, "w", _ex);    \
-                       break;                                          \
-               case 4:                                                 \
-                       __emulate_1op_rax_rdx_ex(_op, _src, _rax, _rdx, \
-                                                _eflags, "l", _ex);    \
+                       __emulate_1op_rax_rdx(ctxt, _op, "l", _ex);     \
                        break;                                          \
                case 8: ON64(                                           \
-                       __emulate_1op_rax_rdx_ex(_op, _src, _rax, _rdx, \
-                                                _eflags, "q", _ex));   \
+                       __emulate_1op_rax_rdx(ctxt, _op, "q", _ex));    \
                        break;                                          \
                }                                                       \
        } while (0)
@@ -651,41 +650,50 @@ static int segmented_read_std(struct x86_emulate_ctxt *ctxt,
        return ctxt->ops->read_std(ctxt, linear, data, size, &ctxt->exception);
 }
 
-static int do_insn_fetch_byte(struct x86_emulate_ctxt *ctxt,
-                             unsigned long eip, u8 *dest)
+/*
+ * Fetch the next byte of the instruction being emulated which is pointed to
+ * by ctxt->_eip, then increment ctxt->_eip.
+ *
+ * Also prefetch the remaining bytes of the instruction without crossing page
+ * boundary if they are not in fetch_cache yet.
+ */
+static int do_insn_fetch_byte(struct x86_emulate_ctxt *ctxt, u8 *dest)
 {
        struct fetch_cache *fc = &ctxt->fetch;
        int rc;
        int size, cur_size;
 
-       if (eip == fc->end) {
+       if (ctxt->_eip == fc->end) {
                unsigned long linear;
-               struct segmented_address addr = { .seg=VCPU_SREG_CS, .ea=eip};
+               struct segmented_address addr = { .seg = VCPU_SREG_CS,
+                                                 .ea  = ctxt->_eip };
                cur_size = fc->end - fc->start;
-               size = min(15UL - cur_size, PAGE_SIZE - offset_in_page(eip));
+               size = min(15UL - cur_size,
+                          PAGE_SIZE - offset_in_page(ctxt->_eip));
                rc = __linearize(ctxt, addr, size, false, true, &linear);
-               if (rc != X86EMUL_CONTINUE)
+               if (unlikely(rc != X86EMUL_CONTINUE))
                        return rc;
                rc = ctxt->ops->fetch(ctxt, linear, fc->data + cur_size,
                                      size, &ctxt->exception);
-               if (rc != X86EMUL_CONTINUE)
+               if (unlikely(rc != X86EMUL_CONTINUE))
                        return rc;
                fc->end += size;
        }
-       *dest = fc->data[eip - fc->start];
+       *dest = fc->data[ctxt->_eip - fc->start];
+       ctxt->_eip++;
        return X86EMUL_CONTINUE;
 }
 
 static int do_insn_fetch(struct x86_emulate_ctxt *ctxt,
-                        unsigned long eip, void *dest, unsigned size)
+                        void *dest, unsigned size)
 {
        int rc;
 
        /* x86 instructions are limited to 15 bytes. */
-       if (eip + size - ctxt->eip > 15)
+       if (unlikely(ctxt->_eip + size - ctxt->eip > 15))
                return X86EMUL_UNHANDLEABLE;
        while (size--) {
-               rc = do_insn_fetch_byte(ctxt, eip++, dest++);
+               rc = do_insn_fetch_byte(ctxt, dest++);
                if (rc != X86EMUL_CONTINUE)
                        return rc;
        }
@@ -693,20 +701,18 @@ static int do_insn_fetch(struct x86_emulate_ctxt *ctxt,
 }
 
 /* Fetch next part of the instruction being emulated. */
-#define insn_fetch(_type, _size, _eip)                                 \
+#define insn_fetch(_type, _ctxt)                                       \
 ({     unsigned long _x;                                               \
-       rc = do_insn_fetch(ctxt, (_eip), &_x, (_size));                 \
+       rc = do_insn_fetch(_ctxt, &_x, sizeof(_type));                  \
        if (rc != X86EMUL_CONTINUE)                                     \
                goto done;                                              \
-       (_eip) += (_size);                                              \
        (_type)_x;                                                      \
 })
 
-#define insn_fetch_arr(_arr, _size, _eip)                              \
-({     rc = do_insn_fetch(ctxt, (_eip), _arr, (_size));                \
+#define insn_fetch_arr(_arr, _size, _ctxt)                             \
+({     rc = do_insn_fetch(_ctxt, _arr, (_size));                       \
        if (rc != X86EMUL_CONTINUE)                                     \
                goto done;                                              \
-       (_eip) += (_size);                                              \
 })
 
 /*
@@ -894,7 +900,7 @@ static int decode_modrm(struct x86_emulate_ctxt *ctxt,
                ctxt->modrm_rm = base_reg = (ctxt->rex_prefix & 1) << 3; /* REG.B */
        }
 
-       ctxt->modrm = insn_fetch(u8, 1, ctxt->_eip);
+       ctxt->modrm = insn_fetch(u8, ctxt);
        ctxt->modrm_mod |= (ctxt->modrm & 0xc0) >> 6;
        ctxt->modrm_reg |= (ctxt->modrm & 0x38) >> 3;
        ctxt->modrm_rm |= (ctxt->modrm & 0x07);
@@ -928,13 +934,13 @@ static int decode_modrm(struct x86_emulate_ctxt *ctxt,
                switch (ctxt->modrm_mod) {
                case 0:
                        if (ctxt->modrm_rm == 6)
-                               modrm_ea += insn_fetch(u16, 2, ctxt->_eip);
+                               modrm_ea += insn_fetch(u16, ctxt);
                        break;
                case 1:
-                       modrm_ea += insn_fetch(s8, 1, ctxt->_eip);
+                       modrm_ea += insn_fetch(s8, ctxt);
                        break;
                case 2:
-                       modrm_ea += insn_fetch(u16, 2, ctxt->_eip);
+                       modrm_ea += insn_fetch(u16, ctxt);
                        break;
                }
                switch (ctxt->modrm_rm) {
@@ -971,13 +977,13 @@ static int decode_modrm(struct x86_emulate_ctxt *ctxt,
        } else {
                /* 32/64-bit ModR/M decode. */
                if ((ctxt->modrm_rm & 7) == 4) {
-                       sib = insn_fetch(u8, 1, ctxt->_eip);
+                       sib = insn_fetch(u8, ctxt);
                        index_reg |= (sib >> 3) & 7;
                        base_reg |= sib & 7;
                        scale = sib >> 6;
 
                        if ((base_reg & 7) == 5 && ctxt->modrm_mod == 0)
-                               modrm_ea += insn_fetch(s32, 4, ctxt->_eip);
+                               modrm_ea += insn_fetch(s32, ctxt);
                        else
                                modrm_ea += ctxt->regs[base_reg];
                        if (index_reg != 4)
@@ -990,13 +996,13 @@ static int decode_modrm(struct x86_emulate_ctxt *ctxt,
                switch (ctxt->modrm_mod) {
                case 0:
                        if (ctxt->modrm_rm == 5)
-                               modrm_ea += insn_fetch(s32, 4, ctxt->_eip);
+                               modrm_ea += insn_fetch(s32, ctxt);
                        break;
                case 1:
-                       modrm_ea += insn_fetch(s8, 1, ctxt->_eip);
+                       modrm_ea += insn_fetch(s8, ctxt);
                        break;
                case 2:
-                       modrm_ea += insn_fetch(s32, 4, ctxt->_eip);
+                       modrm_ea += insn_fetch(s32, ctxt);
                        break;
                }
        }
@@ -1013,13 +1019,13 @@ static int decode_abs(struct x86_emulate_ctxt *ctxt,
        op->type = OP_MEM;
        switch (ctxt->ad_bytes) {
        case 2:
-               op->addr.mem.ea = insn_fetch(u16, 2, ctxt->_eip);
+               op->addr.mem.ea = insn_fetch(u16, ctxt);
                break;
        case 4:
-               op->addr.mem.ea = insn_fetch(u32, 4, ctxt->_eip);
+               op->addr.mem.ea = insn_fetch(u32, ctxt);
                break;
        case 8:
-               op->addr.mem.ea = insn_fetch(u64, 8, ctxt->_eip);
+               op->addr.mem.ea = insn_fetch(u64, ctxt);
                break;
        }
 done:
@@ -1452,15 +1458,18 @@ static int em_popf(struct x86_emulate_ctxt *ctxt)
        return emulate_popf(ctxt, &ctxt->dst.val, ctxt->op_bytes);
 }
 
-static int emulate_push_sreg(struct x86_emulate_ctxt *ctxt, int seg)
+static int em_push_sreg(struct x86_emulate_ctxt *ctxt)
 {
+       int seg = ctxt->src2.val;
+
        ctxt->src.val = get_segment_selector(ctxt, seg);
 
        return em_push(ctxt);
 }
 
-static int emulate_pop_sreg(struct x86_emulate_ctxt *ctxt, int seg)
+static int em_pop_sreg(struct x86_emulate_ctxt *ctxt)
 {
+       int seg = ctxt->src2.val;
        unsigned long selector;
        int rc;
 
@@ -1674,64 +1683,74 @@ static int em_grp2(struct x86_emulate_ctxt *ctxt)
 {
        switch (ctxt->modrm_reg) {
        case 0: /* rol */
-               emulate_2op_SrcB("rol", ctxt->src, ctxt->dst, ctxt->eflags);
+               emulate_2op_SrcB(ctxt, "rol");
                break;
        case 1: /* ror */
-               emulate_2op_SrcB("ror", ctxt->src, ctxt->dst, ctxt->eflags);
+               emulate_2op_SrcB(ctxt, "ror");
                break;
        case 2: /* rcl */
-               emulate_2op_SrcB("rcl", ctxt->src, ctxt->dst, ctxt->eflags);
+               emulate_2op_SrcB(ctxt, "rcl");
                break;
        case 3: /* rcr */
-               emulate_2op_SrcB("rcr", ctxt->src, ctxt->dst, ctxt->eflags);
+               emulate_2op_SrcB(ctxt, "rcr");
                break;
        case 4: /* sal/shl */
        case 6: /* sal/shl */
-               emulate_2op_SrcB("sal", ctxt->src, ctxt->dst, ctxt->eflags);
+               emulate_2op_SrcB(ctxt, "sal");
                break;
        case 5: /* shr */
-               emulate_2op_SrcB("shr", ctxt->src, ctxt->dst, ctxt->eflags);
+               emulate_2op_SrcB(ctxt, "shr");
                break;
        case 7: /* sar */
-               emulate_2op_SrcB("sar", ctxt->src, ctxt->dst, ctxt->eflags);
+               emulate_2op_SrcB(ctxt, "sar");
                break;
        }
        return X86EMUL_CONTINUE;
 }
 
-static int em_grp3(struct x86_emulate_ctxt *ctxt)
+static int em_not(struct x86_emulate_ctxt *ctxt)
+{
+       ctxt->dst.val = ~ctxt->dst.val;
+       return X86EMUL_CONTINUE;
+}
+
+static int em_neg(struct x86_emulate_ctxt *ctxt)
+{
+       emulate_1op(ctxt, "neg");
+       return X86EMUL_CONTINUE;
+}
+
+static int em_mul_ex(struct x86_emulate_ctxt *ctxt)
+{
+       u8 ex = 0;
+
+       emulate_1op_rax_rdx(ctxt, "mul", ex);
+       return X86EMUL_CONTINUE;
+}
+
+static int em_imul_ex(struct x86_emulate_ctxt *ctxt)
+{
+       u8 ex = 0;
+
+       emulate_1op_rax_rdx(ctxt, "imul", ex);
+       return X86EMUL_CONTINUE;
+}
+
+static int em_div_ex(struct x86_emulate_ctxt *ctxt)
 {
-       unsigned long *rax = &ctxt->regs[VCPU_REGS_RAX];
-       unsigned long *rdx = &ctxt->regs[VCPU_REGS_RDX];
        u8 de = 0;
 
-       switch (ctxt->modrm_reg) {
-       case 0 ... 1:   /* test */
-               emulate_2op_SrcV("test", ctxt->src, ctxt->dst, ctxt->eflags);
-               break;
-       case 2: /* not */
-               ctxt->dst.val = ~ctxt->dst.val;
-               break;
-       case 3: /* neg */
-               emulate_1op("neg", ctxt->dst, ctxt->eflags);
-               break;
-       case 4: /* mul */
-               emulate_1op_rax_rdx("mul", ctxt->src, *rax, *rdx, ctxt->eflags);
-               break;
-       case 5: /* imul */
-               emulate_1op_rax_rdx("imul", ctxt->src, *rax, *rdx, ctxt->eflags);
-               break;
-       case 6: /* div */
-               emulate_1op_rax_rdx_ex("div", ctxt->src, *rax, *rdx,
-                                      ctxt->eflags, de);
-               break;
-       case 7: /* idiv */
-               emulate_1op_rax_rdx_ex("idiv", ctxt->src, *rax, *rdx,
-                                      ctxt->eflags, de);
-               break;
-       default:
-               return X86EMUL_UNHANDLEABLE;
-       }
+       emulate_1op_rax_rdx(ctxt, "div", de);
+       if (de)
+               return emulate_de(ctxt);
+       return X86EMUL_CONTINUE;
+}
+
+static int em_idiv_ex(struct x86_emulate_ctxt *ctxt)
+{
+       u8 de = 0;
+
+       emulate_1op_rax_rdx(ctxt, "idiv", de);
        if (de)
                return emulate_de(ctxt);
        return X86EMUL_CONTINUE;
@@ -1743,10 +1762,10 @@ static int em_grp45(struct x86_emulate_ctxt *ctxt)
 
        switch (ctxt->modrm_reg) {
        case 0: /* inc */
-               emulate_1op("inc", ctxt->dst, ctxt->eflags);
+               emulate_1op(ctxt, "inc");
                break;
        case 1: /* dec */
-               emulate_1op("dec", ctxt->dst, ctxt->eflags);
+               emulate_1op(ctxt, "dec");
                break;
        case 2: /* call near abs */ {
                long int old_eip;
@@ -1812,8 +1831,9 @@ static int em_ret_far(struct x86_emulate_ctxt *ctxt)
        return rc;
 }
 
-static int emulate_load_segment(struct x86_emulate_ctxt *ctxt, int seg)
+static int em_lseg(struct x86_emulate_ctxt *ctxt)
 {
+       int seg = ctxt->src2.val;
        unsigned short sel;
        int rc;
 
@@ -2452,7 +2472,7 @@ static int em_das(struct x86_emulate_ctxt *ctxt)
        ctxt->src.type = OP_IMM;
        ctxt->src.val = 0;
        ctxt->src.bytes = 1;
-       emulate_2op_SrcV("or", ctxt->src, ctxt->dst, ctxt->eflags);
+       emulate_2op_SrcV(ctxt, "or");
        ctxt->eflags &= ~(X86_EFLAGS_AF | X86_EFLAGS_CF);
        if (cf)
                ctxt->eflags |= X86_EFLAGS_CF;
@@ -2502,49 +2522,49 @@ static int em_ret_near_imm(struct x86_emulate_ctxt *ctxt)
 
 static int em_add(struct x86_emulate_ctxt *ctxt)
 {
-       emulate_2op_SrcV("add", ctxt->src, ctxt->dst, ctxt->eflags);
+       emulate_2op_SrcV(ctxt, "add");
        return X86EMUL_CONTINUE;
 }
 
 static int em_or(struct x86_emulate_ctxt *ctxt)
 {
-       emulate_2op_SrcV("or", ctxt->src, ctxt->dst, ctxt->eflags);
+       emulate_2op_SrcV(ctxt, "or");
        return X86EMUL_CONTINUE;
 }
 
 static int em_adc(struct x86_emulate_ctxt *ctxt)
 {
-       emulate_2op_SrcV("adc", ctxt->src, ctxt->dst, ctxt->eflags);
+       emulate_2op_SrcV(ctxt, "adc");
        return X86EMUL_CONTINUE;
 }
 
 static int em_sbb(struct x86_emulate_ctxt *ctxt)
 {
-       emulate_2op_SrcV("sbb", ctxt->src, ctxt->dst, ctxt->eflags);
+       emulate_2op_SrcV(ctxt, "sbb");
        return X86EMUL_CONTINUE;
 }
 
 static int em_and(struct x86_emulate_ctxt *ctxt)
 {
-       emulate_2op_SrcV("and", ctxt->src, ctxt->dst, ctxt->eflags);
+       emulate_2op_SrcV(ctxt, "and");
        return X86EMUL_CONTINUE;
 }
 
 static int em_sub(struct x86_emulate_ctxt *ctxt)
 {
-       emulate_2op_SrcV("sub", ctxt->src, ctxt->dst, ctxt->eflags);
+       emulate_2op_SrcV(ctxt, "sub");
        return X86EMUL_CONTINUE;
 }
 
 static int em_xor(struct x86_emulate_ctxt *ctxt)
 {
-       emulate_2op_SrcV("xor", ctxt->src, ctxt->dst, ctxt->eflags);
+       emulate_2op_SrcV(ctxt, "xor");
        return X86EMUL_CONTINUE;
 }
 
 static int em_cmp(struct x86_emulate_ctxt *ctxt)
 {
-       emulate_2op_SrcV("cmp", ctxt->src, ctxt->dst, ctxt->eflags);
+       emulate_2op_SrcV(ctxt, "cmp");
        /* Disable writeback. */
        ctxt->dst.type = OP_NONE;
        return X86EMUL_CONTINUE;
@@ -2552,7 +2572,9 @@ static int em_cmp(struct x86_emulate_ctxt *ctxt)
 
 static int em_test(struct x86_emulate_ctxt *ctxt)
 {
-       emulate_2op_SrcV("test", ctxt->src, ctxt->dst, ctxt->eflags);
+       emulate_2op_SrcV(ctxt, "test");
+       /* Disable writeback. */
+       ctxt->dst.type = OP_NONE;
        return X86EMUL_CONTINUE;
 }
 
@@ -2570,7 +2592,7 @@ static int em_xchg(struct x86_emulate_ctxt *ctxt)
 
 static int em_imul(struct x86_emulate_ctxt *ctxt)
 {
-       emulate_2op_SrcV_nobyte("imul", ctxt->src, ctxt->dst, ctxt->eflags);
+       emulate_2op_SrcV_nobyte(ctxt, "imul");
        return X86EMUL_CONTINUE;
 }
 
@@ -3025,9 +3047,14 @@ static struct opcode group1A[] = {
 };
 
 static struct opcode group3[] = {
-       D(DstMem | SrcImm | ModRM), D(DstMem | SrcImm | ModRM),
-       D(DstMem | SrcNone | ModRM | Lock), D(DstMem | SrcNone | ModRM | Lock),
-       X4(D(SrcMem | ModRM)),
+       I(DstMem | SrcImm | ModRM, em_test),
+       I(DstMem | SrcImm | ModRM, em_test),
+       I(DstMem | SrcNone | ModRM | Lock, em_not),
+       I(DstMem | SrcNone | ModRM | Lock, em_neg),
+       I(SrcMem | ModRM, em_mul_ex),
+       I(SrcMem | ModRM, em_imul_ex),
+       I(SrcMem | ModRM, em_div_ex),
+       I(SrcMem | ModRM, em_idiv_ex),
 };
 
 static struct opcode group4[] = {
@@ -3090,16 +3117,20 @@ static struct gprefix pfx_0f_6f_0f_7f = {
 static struct opcode opcode_table[256] = {
        /* 0x00 - 0x07 */
        I6ALU(Lock, em_add),
-       D(ImplicitOps | Stack | No64), D(ImplicitOps | Stack | No64),
+       I(ImplicitOps | Stack | No64 | Src2ES, em_push_sreg),
+       I(ImplicitOps | Stack | No64 | Src2ES, em_pop_sreg),
        /* 0x08 - 0x0F */
        I6ALU(Lock, em_or),
-       D(ImplicitOps | Stack | No64), N,
+       I(ImplicitOps | Stack | No64 | Src2CS, em_push_sreg),
+       N,
        /* 0x10 - 0x17 */
        I6ALU(Lock, em_adc),
-       D(ImplicitOps | Stack | No64), D(ImplicitOps | Stack | No64),
+       I(ImplicitOps | Stack | No64 | Src2SS, em_push_sreg),
+       I(ImplicitOps | Stack | No64 | Src2SS, em_pop_sreg),
        /* 0x18 - 0x1F */
        I6ALU(Lock, em_sbb),
-       D(ImplicitOps | Stack | No64), D(ImplicitOps | Stack | No64),
+       I(ImplicitOps | Stack | No64 | Src2DS, em_push_sreg),
+       I(ImplicitOps | Stack | No64 | Src2DS, em_pop_sreg),
        /* 0x20 - 0x27 */
        I6ALU(Lock, em_and), N, N,
        /* 0x28 - 0x2F */
@@ -3167,7 +3198,8 @@ static struct opcode opcode_table[256] = {
        D2bv(DstMem | SrcImmByte | ModRM),
        I(ImplicitOps | Stack | SrcImmU16, em_ret_near_imm),
        I(ImplicitOps | Stack, em_ret),
-       D(DstReg | SrcMemFAddr | ModRM | No64), D(DstReg | SrcMemFAddr | ModRM | No64),
+       I(DstReg | SrcMemFAddr | ModRM | No64 | Src2ES, em_lseg),
+       I(DstReg | SrcMemFAddr | ModRM | No64 | Src2DS, em_lseg),
        G(ByteOp, group11), G(0, group11),
        /* 0xC8 - 0xCF */
        N, N, N, I(ImplicitOps | Stack, em_ret_far),
@@ -3242,20 +3274,22 @@ static struct opcode twobyte_table[256] = {
        /* 0x90 - 0x9F */
        X16(D(ByteOp | DstMem | SrcNone | ModRM| Mov)),
        /* 0xA0 - 0xA7 */
-       D(ImplicitOps | Stack), D(ImplicitOps | Stack),
+       I(Stack | Src2FS, em_push_sreg), I(Stack | Src2FS, em_pop_sreg),
        DI(ImplicitOps, cpuid), D(DstMem | SrcReg | ModRM | BitOp),
        D(DstMem | SrcReg | Src2ImmByte | ModRM),
        D(DstMem | SrcReg | Src2CL | ModRM), N, N,
        /* 0xA8 - 0xAF */
-       D(ImplicitOps | Stack), D(ImplicitOps | Stack),
+       I(Stack | Src2GS, em_push_sreg), I(Stack | Src2GS, em_pop_sreg),
        DI(ImplicitOps, rsm), D(DstMem | SrcReg | ModRM | BitOp | Lock),
        D(DstMem | SrcReg | Src2ImmByte | ModRM),
        D(DstMem | SrcReg | Src2CL | ModRM),
        D(ModRM), I(DstReg | SrcMem | ModRM, em_imul),
        /* 0xB0 - 0xB7 */
        D2bv(DstMem | SrcReg | ModRM | Lock),
-       D(DstReg | SrcMemFAddr | ModRM), D(DstMem | SrcReg | ModRM | BitOp | Lock),
-       D(DstReg | SrcMemFAddr | ModRM), D(DstReg | SrcMemFAddr | ModRM),
+       I(DstReg | SrcMemFAddr | ModRM | Src2SS, em_lseg),
+       D(DstMem | SrcReg | ModRM | BitOp | Lock),
+       I(DstReg | SrcMemFAddr | ModRM | Src2FS, em_lseg),
+       I(DstReg | SrcMemFAddr | ModRM | Src2GS, em_lseg),
        D(ByteOp | DstReg | SrcMem | ModRM | Mov), D(DstReg | SrcMem16 | ModRM | Mov),
        /* 0xB8 - 0xBF */
        N, N,
@@ -3309,13 +3343,13 @@ static int decode_imm(struct x86_emulate_ctxt *ctxt, struct operand *op,
        /* NB. Immediates are sign-extended as necessary. */
        switch (op->bytes) {
        case 1:
-               op->val = insn_fetch(s8, 1, ctxt->_eip);
+               op->val = insn_fetch(s8, ctxt);
                break;
        case 2:
-               op->val = insn_fetch(s16, 2, ctxt->_eip);
+               op->val = insn_fetch(s16, ctxt);
                break;
        case 4:
-               op->val = insn_fetch(s32, 4, ctxt->_eip);
+               op->val = insn_fetch(s32, ctxt);
                break;
        }
        if (!sign_extension) {
@@ -3335,6 +3369,125 @@ done:
        return rc;
 }
 
+static int decode_operand(struct x86_emulate_ctxt *ctxt, struct operand *op,
+                         unsigned d)
+{
+       int rc = X86EMUL_CONTINUE;
+
+       switch (d) {
+       case OpReg:
+               decode_register_operand(ctxt, op,
+                        op == &ctxt->dst &&
+                        ctxt->twobyte && (ctxt->b == 0xb6 || ctxt->b == 0xb7));
+               break;
+       case OpImmUByte:
+               rc = decode_imm(ctxt, op, 1, false);
+               break;
+       case OpMem:
+               ctxt->memop.bytes = (ctxt->d & ByteOp) ? 1 : ctxt->op_bytes;
+       mem_common:
+               *op = ctxt->memop;
+               ctxt->memopp = op;
+               if ((ctxt->d & BitOp) && op == &ctxt->dst)
+                       fetch_bit_operand(ctxt);
+               op->orig_val = op->val;
+               break;
+       case OpMem64:
+               ctxt->memop.bytes = 8;
+               goto mem_common;
+       case OpAcc:
+               op->type = OP_REG;
+               op->bytes = (ctxt->d & ByteOp) ? 1 : ctxt->op_bytes;
+               op->addr.reg = &ctxt->regs[VCPU_REGS_RAX];
+               fetch_register_operand(op);
+               op->orig_val = op->val;
+               break;
+       case OpDI:
+               op->type = OP_MEM;
+               op->bytes = (ctxt->d & ByteOp) ? 1 : ctxt->op_bytes;
+               op->addr.mem.ea =
+                       register_address(ctxt, ctxt->regs[VCPU_REGS_RDI]);
+               op->addr.mem.seg = VCPU_SREG_ES;
+               op->val = 0;
+               break;
+       case OpDX:
+               op->type = OP_REG;
+               op->bytes = 2;
+               op->addr.reg = &ctxt->regs[VCPU_REGS_RDX];
+               fetch_register_operand(op);
+               break;
+       case OpCL:
+               op->bytes = 1;
+               op->val = ctxt->regs[VCPU_REGS_RCX] & 0xff;
+               break;
+       case OpImmByte:
+               rc = decode_imm(ctxt, op, 1, true);
+               break;
+       case OpOne:
+               op->bytes = 1;
+               op->val = 1;
+               break;
+       case OpImm:
+               rc = decode_imm(ctxt, op, imm_size(ctxt), true);
+               break;
+       case OpMem16:
+               ctxt->memop.bytes = 2;
+               goto mem_common;
+       case OpMem32:
+               ctxt->memop.bytes = 4;
+               goto mem_common;
+       case OpImmU16:
+               rc = decode_imm(ctxt, op, 2, false);
+               break;
+       case OpImmU:
+               rc = decode_imm(ctxt, op, imm_size(ctxt), false);
+               break;
+       case OpSI:
+               op->type = OP_MEM;
+               op->bytes = (ctxt->d & ByteOp) ? 1 : ctxt->op_bytes;
+               op->addr.mem.ea =
+                       register_address(ctxt, ctxt->regs[VCPU_REGS_RSI]);
+               op->addr.mem.seg = seg_override(ctxt);
+               op->val = 0;
+               break;
+       case OpImmFAddr:
+               op->type = OP_IMM;
+               op->addr.mem.ea = ctxt->_eip;
+               op->bytes = ctxt->op_bytes + 2;
+               insn_fetch_arr(op->valptr, op->bytes, ctxt);
+               break;
+       case OpMemFAddr:
+               ctxt->memop.bytes = ctxt->op_bytes + 2;
+               goto mem_common;
+       case OpES:
+               op->val = VCPU_SREG_ES;
+               break;
+       case OpCS:
+               op->val = VCPU_SREG_CS;
+               break;
+       case OpSS:
+               op->val = VCPU_SREG_SS;
+               break;
+       case OpDS:
+               op->val = VCPU_SREG_DS;
+               break;
+       case OpFS:
+               op->val = VCPU_SREG_FS;
+               break;
+       case OpGS:
+               op->val = VCPU_SREG_GS;
+               break;
+       case OpImplicit:
+               /* Special instructions do their own operand decoding. */
+       default:
+               op->type = OP_NONE; /* Disable writeback. */
+               break;
+       }
+
+done:
+       return rc;
+}
+
 int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len)
 {
        int rc = X86EMUL_CONTINUE;
@@ -3342,8 +3495,9 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len)
        int def_op_bytes, def_ad_bytes, goffset, simd_prefix;
        bool op_prefix = false;
        struct opcode opcode;
-       struct operand memop = { .type = OP_NONE }, *memopp = NULL;
 
+       ctxt->memop.type = OP_NONE;
+       ctxt->memopp = NULL;
        ctxt->_eip = ctxt->eip;
        ctxt->fetch.start = ctxt->_eip;
        ctxt->fetch.end = ctxt->fetch.start + insn_len;
@@ -3366,7 +3520,7 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len)
                break;
 #endif
        default:
-               return -1;
+               return EMULATION_FAILED;
        }
 
        ctxt->op_bytes = def_op_bytes;
@@ -3374,7 +3528,7 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len)
 
        /* Legacy prefixes. */
        for (;;) {
-               switch (ctxt->b = insn_fetch(u8, 1, ctxt->_eip)) {
+               switch (ctxt->b = insn_fetch(u8, ctxt)) {
                case 0x66:      /* operand-size override */
                        op_prefix = true;
                        /* switch between 2/4 bytes */
@@ -3430,7 +3584,7 @@ done_prefixes:
        /* Two-byte opcode? */
        if (ctxt->b == 0x0f) {
                ctxt->twobyte = 1;
-               ctxt->b = insn_fetch(u8, 1, ctxt->_eip);
+               ctxt->b = insn_fetch(u8, ctxt);
                opcode = twobyte_table[ctxt->b];
        }
        ctxt->d = opcode.flags;
@@ -3438,13 +3592,13 @@ done_prefixes:
        while (ctxt->d & GroupMask) {
                switch (ctxt->d & GroupMask) {
                case Group:
-                       ctxt->modrm = insn_fetch(u8, 1, ctxt->_eip);
+                       ctxt->modrm = insn_fetch(u8, ctxt);
                        --ctxt->_eip;
                        goffset = (ctxt->modrm >> 3) & 7;
                        opcode = opcode.u.group[goffset];
                        break;
                case GroupDual:
-                       ctxt->modrm = insn_fetch(u8, 1, ctxt->_eip);
+                       ctxt->modrm = insn_fetch(u8, ctxt);
                        --ctxt->_eip;
                        goffset = (ctxt->modrm >> 3) & 7;
                        if ((ctxt->modrm >> 6) == 3)
@@ -3458,7 +3612,7 @@ done_prefixes:
                        break;
                case Prefix:
                        if (ctxt->rep_prefix && op_prefix)
-                               return X86EMUL_UNHANDLEABLE;
+                               return EMULATION_FAILED;
                        simd_prefix = op_prefix ? 0x66 : ctxt->rep_prefix;
                        switch (simd_prefix) {
                        case 0x00: opcode = opcode.u.gprefix->pfx_no; break;
@@ -3468,10 +3622,10 @@ done_prefixes:
                        }
                        break;
                default:
-                       return X86EMUL_UNHANDLEABLE;
+                       return EMULATION_FAILED;
                }
 
-               ctxt->d &= ~GroupMask;
+               ctxt->d &= ~(u64)GroupMask;
                ctxt->d |= opcode.flags;
        }
 
@@ -3481,10 +3635,10 @@ done_prefixes:
 
        /* Unrecognised? */
        if (ctxt->d == 0 || (ctxt->d & Undefined))
-               return -1;
+               return EMULATION_FAILED;
 
        if (!(ctxt->d & VendorSpecific) && ctxt->only_vendor_specific_insn)
-               return -1;
+               return EMULATION_FAILED;
 
        if (mode == X86EMUL_MODE_PROT64 && (ctxt->d & Stack))
                ctxt->op_bytes = 8;
@@ -3501,96 +3655,27 @@ done_prefixes:
 
        /* ModRM and SIB bytes. */
        if (ctxt->d & ModRM) {
-               rc = decode_modrm(ctxt, &memop);
+               rc = decode_modrm(ctxt, &ctxt->memop);
                if (!ctxt->has_seg_override)
                        set_seg_override(ctxt, ctxt->modrm_seg);
        } else if (ctxt->d & MemAbs)
-               rc = decode_abs(ctxt, &memop);
+               rc = decode_abs(ctxt, &ctxt->memop);
        if (rc != X86EMUL_CONTINUE)
                goto done;
 
        if (!ctxt->has_seg_override)
                set_seg_override(ctxt, VCPU_SREG_DS);
 
-       memop.addr.mem.seg = seg_override(ctxt);
+       ctxt->memop.addr.mem.seg = seg_override(ctxt);
 
-       if (memop.type == OP_MEM && ctxt->ad_bytes != 8)
-               memop.addr.mem.ea = (u32)memop.addr.mem.ea;
+       if (ctxt->memop.type == OP_MEM && ctxt->ad_bytes != 8)
+               ctxt->memop.addr.mem.ea = (u32)ctxt->memop.addr.mem.ea;
 
        /*
         * Decode and fetch the source operand: register, memory
         * or immediate.
         */
-       switch (ctxt->d & SrcMask) {
-       case SrcNone:
-               break;
-       case SrcReg:
-               decode_register_operand(ctxt, &ctxt->src, 0);
-               break;
-       case SrcMem16:
-               memop.bytes = 2;
-               goto srcmem_common;
-       case SrcMem32:
-               memop.bytes = 4;
-               goto srcmem_common;
-       case SrcMem:
-               memop.bytes = (ctxt->d & ByteOp) ? 1 :
-                                                          ctxt->op_bytes;
-       srcmem_common:
-               ctxt->src = memop;
-               memopp = &ctxt->src;
-               break;
-       case SrcImmU16:
-               rc = decode_imm(ctxt, &ctxt->src, 2, false);
-               break;
-       case SrcImm:
-               rc = decode_imm(ctxt, &ctxt->src, imm_size(ctxt), true);
-               break;
-       case SrcImmU:
-               rc = decode_imm(ctxt, &ctxt->src, imm_size(ctxt), false);
-               break;
-       case SrcImmByte:
-               rc = decode_imm(ctxt, &ctxt->src, 1, true);
-               break;
-       case SrcImmUByte:
-               rc = decode_imm(ctxt, &ctxt->src, 1, false);
-               break;
-       case SrcAcc:
-               ctxt->src.type = OP_REG;
-               ctxt->src.bytes = (ctxt->d & ByteOp) ? 1 : ctxt->op_bytes;
-               ctxt->src.addr.reg = &ctxt->regs[VCPU_REGS_RAX];
-               fetch_register_operand(&ctxt->src);
-               break;
-       case SrcOne:
-               ctxt->src.bytes = 1;
-               ctxt->src.val = 1;
-               break;
-       case SrcSI:
-               ctxt->src.type = OP_MEM;
-               ctxt->src.bytes = (ctxt->d & ByteOp) ? 1 : ctxt->op_bytes;
-               ctxt->src.addr.mem.ea =
-                       register_address(ctxt, ctxt->regs[VCPU_REGS_RSI]);
-               ctxt->src.addr.mem.seg = seg_override(ctxt);
-               ctxt->src.val = 0;
-               break;
-       case SrcImmFAddr:
-               ctxt->src.type = OP_IMM;
-               ctxt->src.addr.mem.ea = ctxt->_eip;
-               ctxt->src.bytes = ctxt->op_bytes + 2;
-               insn_fetch_arr(ctxt->src.valptr, ctxt->src.bytes, ctxt->_eip);
-               break;
-       case SrcMemFAddr:
-               memop.bytes = ctxt->op_bytes + 2;
-               goto srcmem_common;
-               break;
-       case SrcDX:
-               ctxt->src.type = OP_REG;
-               ctxt->src.bytes = 2;
-               ctxt->src.addr.reg = &ctxt->regs[VCPU_REGS_RDX];
-               fetch_register_operand(&ctxt->src);
-               break;
-       }
-
+       rc = decode_operand(ctxt, &ctxt->src, (ctxt->d >> SrcShift) & OpMask);
        if (rc != X86EMUL_CONTINUE)
                goto done;
 
@@ -3598,85 +3683,18 @@ done_prefixes:
         * Decode and fetch the second source operand: register, memory
         * or immediate.
         */
-       switch (ctxt->d & Src2Mask) {
-       case Src2None:
-               break;
-       case Src2CL:
-               ctxt->src2.bytes = 1;
-               ctxt->src2.val = ctxt->regs[VCPU_REGS_RCX] & 0xff;
-               break;
-       case Src2ImmByte:
-               rc = decode_imm(ctxt, &ctxt->src2, 1, true);
-               break;
-       case Src2One:
-               ctxt->src2.bytes = 1;
-               ctxt->src2.val = 1;
-               break;
-       case Src2Imm:
-               rc = decode_imm(ctxt, &ctxt->src2, imm_size(ctxt), true);
-               break;
-       }
-
+       rc = decode_operand(ctxt, &ctxt->src2, (ctxt->d >> Src2Shift) & OpMask);
        if (rc != X86EMUL_CONTINUE)
                goto done;
 
        /* Decode and fetch the destination operand: register or memory. */
-       switch (ctxt->d & DstMask) {
-       case DstReg:
-               decode_register_operand(ctxt, &ctxt->dst,
-                        ctxt->twobyte && (ctxt->b == 0xb6 || ctxt->b == 0xb7));
-               break;
-       case DstImmUByte:
-               ctxt->dst.type = OP_IMM;
-               ctxt->dst.addr.mem.ea = ctxt->_eip;
-               ctxt->dst.bytes = 1;
-               ctxt->dst.val = insn_fetch(u8, 1, ctxt->_eip);
-               break;
-       case DstMem:
-       case DstMem64:
-               ctxt->dst = memop;
-               memopp = &ctxt->dst;
-               if ((ctxt->d & DstMask) == DstMem64)
-                       ctxt->dst.bytes = 8;
-               else
-                       ctxt->dst.bytes = (ctxt->d & ByteOp) ? 1 : ctxt->op_bytes;
-               if (ctxt->d & BitOp)
-                       fetch_bit_operand(ctxt);
-               ctxt->dst.orig_val = ctxt->dst.val;
-               break;
-       case DstAcc:
-               ctxt->dst.type = OP_REG;
-               ctxt->dst.bytes = (ctxt->d & ByteOp) ? 1 : ctxt->op_bytes;
-               ctxt->dst.addr.reg = &ctxt->regs[VCPU_REGS_RAX];
-               fetch_register_operand(&ctxt->dst);
-               ctxt->dst.orig_val = ctxt->dst.val;
-               break;
-       case DstDI:
-               ctxt->dst.type = OP_MEM;
-               ctxt->dst.bytes = (ctxt->d & ByteOp) ? 1 : ctxt->op_bytes;
-               ctxt->dst.addr.mem.ea =
-                       register_address(ctxt, ctxt->regs[VCPU_REGS_RDI]);
-               ctxt->dst.addr.mem.seg = VCPU_SREG_ES;
-               ctxt->dst.val = 0;
-               break;
-       case DstDX:
-               ctxt->dst.type = OP_REG;
-               ctxt->dst.bytes = 2;
-               ctxt->dst.addr.reg = &ctxt->regs[VCPU_REGS_RDX];
-               fetch_register_operand(&ctxt->dst);
-               break;
-       case ImplicitOps:
-               /* Special instructions do their own operand decoding. */
-       default:
-               ctxt->dst.type = OP_NONE; /* Disable writeback. */
-               break;
-       }
+       rc = decode_operand(ctxt, &ctxt->dst, (ctxt->d >> DstShift) & OpMask);
 
 done:
-       if (memopp && memopp->type == OP_MEM && ctxt->rip_relative)
-               memopp->addr.mem.ea += ctxt->_eip;
+       if (ctxt->memopp && ctxt->memopp->type == OP_MEM && ctxt->rip_relative)
+               ctxt->memopp->addr.mem.ea += ctxt->_eip;
 
-       return (rc == X86EMUL_UNHANDLEABLE) ? EMULATION_FAILED : EMULATION_OK;
+       return (rc != X86EMUL_CONTINUE) ? EMULATION_FAILED : EMULATION_OK;
 }
 
 static bool string_insn_completed(struct x86_emulate_ctxt *ctxt)
@@ -3825,32 +3843,11 @@ special_insn:
                goto twobyte_insn;
 
        switch (ctxt->b) {
-       case 0x06:              /* push es */
-               rc = emulate_push_sreg(ctxt, VCPU_SREG_ES);
-               break;
-       case 0x07:              /* pop es */
-               rc = emulate_pop_sreg(ctxt, VCPU_SREG_ES);
-               break;
-       case 0x0e:              /* push cs */
-               rc = emulate_push_sreg(ctxt, VCPU_SREG_CS);
-               break;
-       case 0x16:              /* push ss */
-               rc = emulate_push_sreg(ctxt, VCPU_SREG_SS);
-               break;
-       case 0x17:              /* pop ss */
-               rc = emulate_pop_sreg(ctxt, VCPU_SREG_SS);
-               break;
-       case 0x1e:              /* push ds */
-               rc = emulate_push_sreg(ctxt, VCPU_SREG_DS);
-               break;
-       case 0x1f:              /* pop ds */
-               rc = emulate_pop_sreg(ctxt, VCPU_SREG_DS);
-               break;
        case 0x40 ... 0x47: /* inc r16/r32 */
-               emulate_1op("inc", ctxt->dst, ctxt->eflags);
+               emulate_1op(ctxt, "inc");
                break;
        case 0x48 ... 0x4f: /* dec r16/r32 */
-               emulate_1op("dec", ctxt->dst, ctxt->eflags);
+               emulate_1op(ctxt, "dec");
                break;
        case 0x63:              /* movsxd */
                if (ctxt->mode != X86EMUL_MODE_PROT64)
@@ -3891,12 +3888,6 @@ special_insn:
        case 0xc0 ... 0xc1:
                rc = em_grp2(ctxt);
                break;
-       case 0xc4:              /* les */
-               rc = emulate_load_segment(ctxt, VCPU_SREG_ES);
-               break;
-       case 0xc5:              /* lds */
-               rc = emulate_load_segment(ctxt, VCPU_SREG_DS);
-               break;
        case 0xcc:              /* int3 */
                rc = emulate_int(ctxt, 3);
                break;
@@ -3953,9 +3944,6 @@ special_insn:
                /* complement carry flag from eflags reg */
                ctxt->eflags ^= EFLG_CF;
                break;
-       case 0xf6 ... 0xf7:     /* Grp3 */
-               rc = em_grp3(ctxt);
-               break;
        case 0xf8: /* clc */
                ctxt->eflags &= ~EFLG_CF;
                break;
@@ -4103,36 +4091,24 @@ twobyte_insn:
        case 0x90 ... 0x9f:     /* setcc r/m8 */
                ctxt->dst.val = test_cc(ctxt->b, ctxt->eflags);
                break;
-       case 0xa0:        /* push fs */
-               rc = emulate_push_sreg(ctxt, VCPU_SREG_FS);
-               break;
-       case 0xa1:       /* pop fs */
-               rc = emulate_pop_sreg(ctxt, VCPU_SREG_FS);
-               break;
        case 0xa3:
              bt:               /* bt */
                ctxt->dst.type = OP_NONE;
                /* only subword offset */
                ctxt->src.val &= (ctxt->dst.bytes << 3) - 1;
-               emulate_2op_SrcV_nobyte("bt", ctxt->src, ctxt->dst, ctxt->eflags);
+               emulate_2op_SrcV_nobyte(ctxt, "bt");
                break;
        case 0xa4: /* shld imm8, r, r/m */
        case 0xa5: /* shld cl, r, r/m */
-               emulate_2op_cl("shld", ctxt->src2, ctxt->src, ctxt->dst, ctxt->eflags);
-               break;
-       case 0xa8:      /* push gs */
-               rc = emulate_push_sreg(ctxt, VCPU_SREG_GS);
-               break;
-       case 0xa9:      /* pop gs */
-               rc = emulate_pop_sreg(ctxt, VCPU_SREG_GS);
+               emulate_2op_cl(ctxt, "shld");
                break;
        case 0xab:
              bts:              /* bts */
-               emulate_2op_SrcV_nobyte("bts", ctxt->src, ctxt->dst, ctxt->eflags);
+               emulate_2op_SrcV_nobyte(ctxt, "bts");
                break;
        case 0xac: /* shrd imm8, r, r/m */
        case 0xad: /* shrd cl, r, r/m */
-               emulate_2op_cl("shrd", ctxt->src2, ctxt->src, ctxt->dst, ctxt->eflags);
+               emulate_2op_cl(ctxt, "shrd");
                break;
        case 0xae:              /* clflush */
                break;
@@ -4143,7 +4119,7 @@ twobyte_insn:
                 */
                ctxt->src.orig_val = ctxt->src.val;
                ctxt->src.val = ctxt->regs[VCPU_REGS_RAX];
-               emulate_2op_SrcV("cmp", ctxt->src, ctxt->dst, ctxt->eflags);
+               emulate_2op_SrcV(ctxt, "cmp");
                if (ctxt->eflags & EFLG_ZF) {
                        /* Success: write back to memory. */
                        ctxt->dst.val = ctxt->src.orig_val;
@@ -4153,18 +4129,9 @@ twobyte_insn:
                        ctxt->dst.addr.reg = (unsigned long *)&ctxt->regs[VCPU_REGS_RAX];
                }
                break;
-       case 0xb2:              /* lss */
-               rc = emulate_load_segment(ctxt, VCPU_SREG_SS);
-               break;
        case 0xb3:
              btr:              /* btr */
-               emulate_2op_SrcV_nobyte("btr", ctxt->src, ctxt->dst, ctxt->eflags);
-               break;
-       case 0xb4:              /* lfs */
-               rc = emulate_load_segment(ctxt, VCPU_SREG_FS);
-               break;
-       case 0xb5:              /* lgs */
-               rc = emulate_load_segment(ctxt, VCPU_SREG_GS);
+               emulate_2op_SrcV_nobyte(ctxt, "btr");
                break;
        case 0xb6 ... 0xb7:     /* movzx */
                ctxt->dst.bytes = ctxt->op_bytes;
@@ -4185,7 +4152,7 @@ twobyte_insn:
                break;
        case 0xbb:
              btc:              /* btc */
-               emulate_2op_SrcV_nobyte("btc", ctxt->src, ctxt->dst, ctxt->eflags);
+               emulate_2op_SrcV_nobyte(ctxt, "btc");
                break;
        case 0xbc: {            /* bsf */
                u8 zf;
@@ -4217,7 +4184,7 @@ twobyte_insn:
                                                        (s16) ctxt->src.val;
                break;
        case 0xc0 ... 0xc1:     /* xadd */
-               emulate_2op_SrcV("add", ctxt->src, ctxt->dst, ctxt->eflags);
+               emulate_2op_SrcV(ctxt, "add");
                /* Write back the register source. */
                ctxt->src.val = ctxt->dst.orig_val;
                write_register_operand(&ctxt->src);
index efad7238505888866900fd19d6a101acecef2a51..76e3f1cd03696997964db7814de98a578a9eb4a7 100644 (file)
@@ -713,14 +713,16 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags)
        kvm_register_irq_mask_notifier(kvm, 0, &pit->mask_notifier);
 
        kvm_iodevice_init(&pit->dev, &pit_dev_ops);
-       ret = kvm_io_bus_register_dev(kvm, KVM_PIO_BUS, &pit->dev);
+       ret = kvm_io_bus_register_dev(kvm, KVM_PIO_BUS, KVM_PIT_BASE_ADDRESS,
+                                     KVM_PIT_MEM_LENGTH, &pit->dev);
        if (ret < 0)
                goto fail;
 
        if (flags & KVM_PIT_SPEAKER_DUMMY) {
                kvm_iodevice_init(&pit->speaker_dev, &speaker_dev_ops);
                ret = kvm_io_bus_register_dev(kvm, KVM_PIO_BUS,
-                                               &pit->speaker_dev);
+                                             KVM_SPEAKER_BASE_ADDRESS, 4,
+                                             &pit->speaker_dev);
                if (ret < 0)
                        goto fail_unregister;
        }
index 19fe855e79536e3c8f6e7aa733a41ce98bf5e192..cac4746d7ffb643b7fcd54451fb2d994f2f53c9b 100644 (file)
@@ -34,6 +34,9 @@
 #include <linux/kvm_host.h>
 #include "trace.h"
 
+#define pr_pic_unimpl(fmt, ...)        \
+       pr_err_ratelimited("kvm: pic: " fmt, ## __VA_ARGS__)
+
 static void pic_irq_request(struct kvm *kvm, int level);
 
 static void pic_lock(struct kvm_pic *s)
@@ -306,10 +309,10 @@ static void pic_ioport_write(void *opaque, u32 addr, u32 val)
                        }
                        s->init_state = 1;
                        if (val & 0x02)
-                               printk(KERN_ERR "single mode not supported");
+                               pr_pic_unimpl("single mode not supported");
                        if (val & 0x08)
-                               printk(KERN_ERR
-                                      "level sensitive irq not supported");
+                               pr_pic_unimpl(
+                                       "level sensitive irq not supported");
                } else if (val & 0x08) {
                        if (val & 0x04)
                                s->poll = 1;
@@ -459,22 +462,15 @@ static int picdev_in_range(gpa_t addr)
        }
 }
 
-static inline struct kvm_pic *to_pic(struct kvm_io_device *dev)
-{
-       return container_of(dev, struct kvm_pic, dev);
-}
-
-static int picdev_write(struct kvm_io_device *this,
+static int picdev_write(struct kvm_pic *s,
                         gpa_t addr, int len, const void *val)
 {
-       struct kvm_pic *s = to_pic(this);
        unsigned char data = *(unsigned char *)val;
        if (!picdev_in_range(addr))
                return -EOPNOTSUPP;
 
        if (len != 1) {
-               if (printk_ratelimit())
-                       printk(KERN_ERR "PIC: non byte write\n");
+               pr_pic_unimpl("non byte write\n");
                return 0;
        }
        pic_lock(s);
@@ -494,17 +490,15 @@ static int picdev_write(struct kvm_io_device *this,
        return 0;
 }
 
-static int picdev_read(struct kvm_io_device *this,
+static int picdev_read(struct kvm_pic *s,
                       gpa_t addr, int len, void *val)
 {
-       struct kvm_pic *s = to_pic(this);
        unsigned char data = 0;
        if (!picdev_in_range(addr))
                return -EOPNOTSUPP;
 
        if (len != 1) {
-               if (printk_ratelimit())
-                       printk(KERN_ERR "PIC: non byte read\n");
+               pr_pic_unimpl("non byte read\n");
                return 0;
        }
        pic_lock(s);
@@ -525,6 +519,48 @@ static int picdev_read(struct kvm_io_device *this,
        return 0;
 }
 
+static int picdev_master_write(struct kvm_io_device *dev,
+                              gpa_t addr, int len, const void *val)
+{
+       return picdev_write(container_of(dev, struct kvm_pic, dev_master),
+                           addr, len, val);
+}
+
+static int picdev_master_read(struct kvm_io_device *dev,
+                             gpa_t addr, int len, void *val)
+{
+       return picdev_read(container_of(dev, struct kvm_pic, dev_master),
+                           addr, len, val);
+}
+
+static int picdev_slave_write(struct kvm_io_device *dev,
+                             gpa_t addr, int len, const void *val)
+{
+       return picdev_write(container_of(dev, struct kvm_pic, dev_slave),
+                           addr, len, val);
+}
+
+static int picdev_slave_read(struct kvm_io_device *dev,
+                            gpa_t addr, int len, void *val)
+{
+       return picdev_read(container_of(dev, struct kvm_pic, dev_slave),
+                           addr, len, val);
+}
+
+static int picdev_eclr_write(struct kvm_io_device *dev,
+                            gpa_t addr, int len, const void *val)
+{
+       return picdev_write(container_of(dev, struct kvm_pic, dev_eclr),
+                           addr, len, val);
+}
+
+static int picdev_eclr_read(struct kvm_io_device *dev,
+                           gpa_t addr, int len, void *val)
+{
+       return picdev_read(container_of(dev, struct kvm_pic, dev_eclr),
+                           addr, len, val);
+}
+
 /*
  * callback when PIC0 irq status changed
  */
@@ -537,9 +573,19 @@ static void pic_irq_request(struct kvm *kvm, int level)
        s->output = level;
 }
 
-static const struct kvm_io_device_ops picdev_ops = {
-       .read     = picdev_read,
-       .write    = picdev_write,
+static const struct kvm_io_device_ops picdev_master_ops = {
+       .read     = picdev_master_read,
+       .write    = picdev_master_write,
+};
+
+static const struct kvm_io_device_ops picdev_slave_ops = {
+       .read     = picdev_slave_read,
+       .write    = picdev_slave_write,
+};
+
+static const struct kvm_io_device_ops picdev_eclr_ops = {
+       .read     = picdev_eclr_read,
+       .write    = picdev_eclr_write,
 };
 
 struct kvm_pic *kvm_create_pic(struct kvm *kvm)
@@ -560,16 +606,39 @@ struct kvm_pic *kvm_create_pic(struct kvm *kvm)
        /*
         * Initialize PIO device
         */
-       kvm_iodevice_init(&s->dev, &picdev_ops);
+       kvm_iodevice_init(&s->dev_master, &picdev_master_ops);
+       kvm_iodevice_init(&s->dev_slave, &picdev_slave_ops);
+       kvm_iodevice_init(&s->dev_eclr, &picdev_eclr_ops);
        mutex_lock(&kvm->slots_lock);
-       ret = kvm_io_bus_register_dev(kvm, KVM_PIO_BUS, &s->dev);
+       ret = kvm_io_bus_register_dev(kvm, KVM_PIO_BUS, 0x20, 2,
+                                     &s->dev_master);
+       if (ret < 0)
+               goto fail_unlock;
+
+       ret = kvm_io_bus_register_dev(kvm, KVM_PIO_BUS, 0xa0, 2, &s->dev_slave);
+       if (ret < 0)
+               goto fail_unreg_2;
+
+       ret = kvm_io_bus_register_dev(kvm, KVM_PIO_BUS, 0x4d0, 2, &s->dev_eclr);
+       if (ret < 0)
+               goto fail_unreg_1;
+
        mutex_unlock(&kvm->slots_lock);
-       if (ret < 0) {
-               kfree(s);
-               return NULL;
-       }
 
        return s;
+
+fail_unreg_1:
+       kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS, &s->dev_slave);
+
+fail_unreg_2:
+       kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS, &s->dev_master);
+
+fail_unlock:
+       mutex_unlock(&kvm->slots_lock);
+
+       kfree(s);
+
+       return NULL;
 }
 
 void kvm_destroy_pic(struct kvm *kvm)
@@ -577,7 +646,9 @@ void kvm_destroy_pic(struct kvm *kvm)
        struct kvm_pic *vpic = kvm->arch.vpic;
 
        if (vpic) {
-               kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS, &vpic->dev);
+               kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS, &vpic->dev_master);
+               kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS, &vpic->dev_slave);
+               kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS, &vpic->dev_eclr);
                kvm->arch.vpic = NULL;
                kfree(vpic);
        }
index 53e2d084bffb5bad24ca4fe36534467a239ff6fb..2086f2bfba33db1d11a119ef57fa82aa01763804 100644 (file)
@@ -66,7 +66,9 @@ struct kvm_pic {
        struct kvm *kvm;
        struct kvm_kpic_state pics[2]; /* 0 is master pic, 1 is slave pic */
        int output;             /* intr from master PIC */
-       struct kvm_io_device dev;
+       struct kvm_io_device dev_master;
+       struct kvm_io_device dev_slave;
+       struct kvm_io_device dev_eclr;
        void (*ack_notifier)(void *opaque, int irq);
        unsigned long irq_states[16];
 };
index 3377d53fcd369146c2994f0d34458274c1b1a526..544076c4f44bc330ba28b74b07ad3966e990168f 100644 (file)
@@ -45,13 +45,6 @@ static inline u64 kvm_pdptr_read(struct kvm_vcpu *vcpu, int index)
        return vcpu->arch.walk_mmu->pdptrs[index];
 }
 
-static inline u64 kvm_pdptr_read_mmu(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, int index)
-{
-       load_pdptrs(vcpu, mmu, mmu->get_cr3(vcpu));
-
-       return mmu->pdptrs[index];
-}
-
 static inline ulong kvm_read_cr0_bits(struct kvm_vcpu *vcpu, ulong mask)
 {
        ulong tmask = mask & KVM_POSSIBLE_CR0_GUEST_BITS;
index 64bc6ea78d90961c2f3095fd62c3e130d3cf98aa..497dbaa366d4eb07397e75f27d29f08e249baa2c 100644 (file)
@@ -2,6 +2,8 @@
 struct kvm_timer {
        struct hrtimer timer;
        s64 period;                             /* unit: ns */
+       u32 timer_mode_mask;
+       u64 tscdeadline;
        atomic_t pending;                       /* accumulated triggered timers */
        bool reinject;
        struct kvm_timer_ops *t_ops;
index 57dcbd4308fa8f69efec6462a52a13b594bfbeb8..54abb40199d67d45ed9b1dc752ebc8cd83a6d509 100644 (file)
@@ -68,6 +68,9 @@
 #define VEC_POS(v) ((v) & (32 - 1))
 #define REG_POS(v) (((v) >> 5) << 4)
 
+static unsigned int min_timer_period_us = 500;
+module_param(min_timer_period_us, uint, S_IRUGO | S_IWUSR);
+
 static inline u32 apic_get_reg(struct kvm_lapic *apic, int reg_off)
 {
        return *((u32 *) (apic->regs + reg_off));
@@ -135,9 +138,23 @@ static inline int apic_lvt_vector(struct kvm_lapic *apic, int lvt_type)
        return apic_get_reg(apic, lvt_type) & APIC_VECTOR_MASK;
 }
 
+static inline int apic_lvtt_oneshot(struct kvm_lapic *apic)
+{
+       return ((apic_get_reg(apic, APIC_LVTT) &
+               apic->lapic_timer.timer_mode_mask) == APIC_LVT_TIMER_ONESHOT);
+}
+
 static inline int apic_lvtt_period(struct kvm_lapic *apic)
 {
-       return apic_get_reg(apic, APIC_LVTT) & APIC_LVT_TIMER_PERIODIC;
+       return ((apic_get_reg(apic, APIC_LVTT) &
+               apic->lapic_timer.timer_mode_mask) == APIC_LVT_TIMER_PERIODIC);
+}
+
+static inline int apic_lvtt_tscdeadline(struct kvm_lapic *apic)
+{
+       return ((apic_get_reg(apic, APIC_LVTT) &
+               apic->lapic_timer.timer_mode_mask) ==
+                       APIC_LVT_TIMER_TSCDEADLINE);
 }
 
 static inline int apic_lvt_nmi_mode(u32 lvt_val)
@@ -166,7 +183,7 @@ static inline int apic_x2apic_mode(struct kvm_lapic *apic)
 }
 
 static unsigned int apic_lvt_mask[APIC_LVT_NUM] = {
-       LVT_MASK | APIC_LVT_TIMER_PERIODIC,     /* LVTT */
+       LVT_MASK ,      /* part LVTT mask, timer mode mask added at runtime */
        LVT_MASK | APIC_MODE_MASK,      /* LVTTHMR */
        LVT_MASK | APIC_MODE_MASK,      /* LVTPC */
        LINT_MASK, LINT_MASK,   /* LVT0-1 */
@@ -316,8 +333,8 @@ int kvm_apic_match_logical_addr(struct kvm_lapic *apic, u8 mda)
                        result = 1;
                break;
        default:
-               printk(KERN_WARNING "Bad DFR vcpu %d: %08x\n",
-                      apic->vcpu->vcpu_id, apic_get_reg(apic, APIC_DFR));
+               apic_debug("Bad DFR vcpu %d: %08x\n",
+                          apic->vcpu->vcpu_id, apic_get_reg(apic, APIC_DFR));
                break;
        }
 
@@ -354,8 +371,8 @@ int kvm_apic_match_dest(struct kvm_vcpu *vcpu, struct kvm_lapic *source,
                result = (target != source);
                break;
        default:
-               printk(KERN_WARNING "Bad dest shorthand value %x\n",
-                      short_hand);
+               apic_debug("kvm: apic: Bad dest shorthand value %x\n",
+                          short_hand);
                break;
        }
 
@@ -401,11 +418,11 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
                break;
 
        case APIC_DM_REMRD:
-               printk(KERN_DEBUG "Ignoring delivery mode 3\n");
+               apic_debug("Ignoring delivery mode 3\n");
                break;
 
        case APIC_DM_SMI:
-               printk(KERN_DEBUG "Ignoring guest SMI\n");
+               apic_debug("Ignoring guest SMI\n");
                break;
 
        case APIC_DM_NMI:
@@ -565,11 +582,13 @@ static u32 __apic_read(struct kvm_lapic *apic, unsigned int offset)
                        val = kvm_apic_id(apic) << 24;
                break;
        case APIC_ARBPRI:
-               printk(KERN_WARNING "Access APIC ARBPRI register "
-                      "which is for P6\n");
+               apic_debug("Access APIC ARBPRI register which is for P6\n");
                break;
 
        case APIC_TMCCT:        /* Timer CCR */
+               if (apic_lvtt_tscdeadline(apic))
+                       return 0;
+
                val = apic_get_tmcct(apic);
                break;
 
@@ -664,29 +683,40 @@ static void update_divide_count(struct kvm_lapic *apic)
 
 static void start_apic_timer(struct kvm_lapic *apic)
 {
-       ktime_t now = apic->lapic_timer.timer.base->get_time();
-
-       apic->lapic_timer.period = (u64)apic_get_reg(apic, APIC_TMICT) *
-                   APIC_BUS_CYCLE_NS * apic->divide_count;
+       ktime_t now;
        atomic_set(&apic->lapic_timer.pending, 0);
 
-       if (!apic->lapic_timer.period)
-               return;
-       /*
-        * Do not allow the guest to program periodic timers with small
-        * interval, since the hrtimers are not throttled by the host
-        * scheduler.
-        */
-       if (apic_lvtt_period(apic)) {
-               if (apic->lapic_timer.period < NSEC_PER_MSEC/2)
-                       apic->lapic_timer.period = NSEC_PER_MSEC/2;
-       }
+       if (apic_lvtt_period(apic) || apic_lvtt_oneshot(apic)) {
+               /* lapic timer in oneshot or peroidic mode */
+               now = apic->lapic_timer.timer.base->get_time();
+               apic->lapic_timer.period = (u64)apic_get_reg(apic, APIC_TMICT)
+                           * APIC_BUS_CYCLE_NS * apic->divide_count;
+
+               if (!apic->lapic_timer.period)
+                       return;
+               /*
+                * Do not allow the guest to program periodic timers with small
+                * interval, since the hrtimers are not throttled by the host
+                * scheduler.
+                */
+               if (apic_lvtt_period(apic)) {
+                       s64 min_period = min_timer_period_us * 1000LL;
+
+                       if (apic->lapic_timer.period < min_period) {
+                               pr_info_ratelimited(
+                                   "kvm: vcpu %i: requested %lld ns "
+                                   "lapic timer period limited to %lld ns\n",
+                                   apic->vcpu->vcpu_id,
+                                   apic->lapic_timer.period, min_period);
+                               apic->lapic_timer.period = min_period;
+                       }
+               }
 
-       hrtimer_start(&apic->lapic_timer.timer,
-                     ktime_add_ns(now, apic->lapic_timer.period),
-                     HRTIMER_MODE_ABS);
+               hrtimer_start(&apic->lapic_timer.timer,
+                             ktime_add_ns(now, apic->lapic_timer.period),
+                             HRTIMER_MODE_ABS);
 
-       apic_debug("%s: bus cycle is %" PRId64 "ns, now 0x%016"
+               apic_debug("%s: bus cycle is %" PRId64 "ns, now 0x%016"
                           PRIx64 ", "
                           "timer initial count 0x%x, period %lldns, "
                           "expire @ 0x%016" PRIx64 ".\n", __func__,
@@ -695,6 +725,30 @@ static void start_apic_timer(struct kvm_lapic *apic)
                           apic->lapic_timer.period,
                           ktime_to_ns(ktime_add_ns(now,
                                        apic->lapic_timer.period)));
+       } else if (apic_lvtt_tscdeadline(apic)) {
+               /* lapic timer in tsc deadline mode */
+               u64 guest_tsc, tscdeadline = apic->lapic_timer.tscdeadline;
+               u64 ns = 0;
+               struct kvm_vcpu *vcpu = apic->vcpu;
+               unsigned long this_tsc_khz = vcpu_tsc_khz(vcpu);
+               unsigned long flags;
+
+               if (unlikely(!tscdeadline || !this_tsc_khz))
+                       return;
+
+               local_irq_save(flags);
+
+               now = apic->lapic_timer.timer.base->get_time();
+               guest_tsc = kvm_x86_ops->read_l1_tsc(vcpu);
+               if (likely(tscdeadline > guest_tsc)) {
+                       ns = (tscdeadline - guest_tsc) * 1000000ULL;
+                       do_div(ns, this_tsc_khz);
+               }
+               hrtimer_start(&apic->lapic_timer.timer,
+                       ktime_add_ns(now, ns), HRTIMER_MODE_ABS);
+
+               local_irq_restore(flags);
+       }
 }
 
 static void apic_manage_nmi_watchdog(struct kvm_lapic *apic, u32 lvt0_val)
@@ -782,7 +836,6 @@ static int apic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val)
 
        case APIC_LVT0:
                apic_manage_nmi_watchdog(apic, val);
-       case APIC_LVTT:
        case APIC_LVTTHMR:
        case APIC_LVTPC:
        case APIC_LVT1:
@@ -796,7 +849,22 @@ static int apic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val)
 
                break;
 
+       case APIC_LVTT:
+               if ((apic_get_reg(apic, APIC_LVTT) &
+                   apic->lapic_timer.timer_mode_mask) !=
+                  (val & apic->lapic_timer.timer_mode_mask))
+                       hrtimer_cancel(&apic->lapic_timer.timer);
+
+               if (!apic_sw_enabled(apic))
+                       val |= APIC_LVT_MASKED;
+               val &= (apic_lvt_mask[0] | apic->lapic_timer.timer_mode_mask);
+               apic_set_reg(apic, APIC_LVTT, val);
+               break;
+
        case APIC_TMICT:
+               if (apic_lvtt_tscdeadline(apic))
+                       break;
+
                hrtimer_cancel(&apic->lapic_timer.timer);
                apic_set_reg(apic, APIC_TMICT, val);
                start_apic_timer(apic);
@@ -804,14 +872,14 @@ static int apic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val)
 
        case APIC_TDCR:
                if (val & 4)
-                       printk(KERN_ERR "KVM_WRITE:TDCR %x\n", val);
+                       apic_debug("KVM_WRITE:TDCR %x\n", val);
                apic_set_reg(apic, APIC_TDCR, val);
                update_divide_count(apic);
                break;
 
        case APIC_ESR:
                if (apic_x2apic_mode(apic) && val != 0) {
-                       printk(KERN_ERR "KVM_WRITE:ESR not zero %x\n", val);
+                       apic_debug("KVM_WRITE:ESR not zero %x\n", val);
                        ret = 1;
                }
                break;
@@ -864,6 +932,15 @@ static int apic_mmio_write(struct kvm_io_device *this,
        return 0;
 }
 
+void kvm_lapic_set_eoi(struct kvm_vcpu *vcpu)
+{
+       struct kvm_lapic *apic = vcpu->arch.apic;
+
+       if (apic)
+               apic_reg_write(vcpu->arch.apic, APIC_EOI, 0);
+}
+EXPORT_SYMBOL_GPL(kvm_lapic_set_eoi);
+
 void kvm_free_lapic(struct kvm_vcpu *vcpu)
 {
        if (!vcpu->arch.apic)
@@ -883,6 +960,32 @@ void kvm_free_lapic(struct kvm_vcpu *vcpu)
  *----------------------------------------------------------------------
  */
 
+u64 kvm_get_lapic_tscdeadline_msr(struct kvm_vcpu *vcpu)
+{
+       struct kvm_lapic *apic = vcpu->arch.apic;
+       if (!apic)
+               return 0;
+
+       if (apic_lvtt_oneshot(apic) || apic_lvtt_period(apic))
+               return 0;
+
+       return apic->lapic_timer.tscdeadline;
+}
+
+void kvm_set_lapic_tscdeadline_msr(struct kvm_vcpu *vcpu, u64 data)
+{
+       struct kvm_lapic *apic = vcpu->arch.apic;
+       if (!apic)
+               return;
+
+       if (apic_lvtt_oneshot(apic) || apic_lvtt_period(apic))
+               return;
+
+       hrtimer_cancel(&apic->lapic_timer.timer);
+       apic->lapic_timer.tscdeadline = data;
+       start_apic_timer(apic);
+}
+
 void kvm_lapic_set_tpr(struct kvm_vcpu *vcpu, unsigned long cr8)
 {
        struct kvm_lapic *apic = vcpu->arch.apic;
index 52c9e6b9e725ecca8b0cc385ddaa43bd9e10952c..138e8cc6fea600ef42a515cf08d6d2c4a6f7a60b 100644 (file)
@@ -26,6 +26,7 @@ int kvm_get_apic_interrupt(struct kvm_vcpu *vcpu);
 void kvm_lapic_reset(struct kvm_vcpu *vcpu);
 u64 kvm_lapic_get_cr8(struct kvm_vcpu *vcpu);
 void kvm_lapic_set_tpr(struct kvm_vcpu *vcpu, unsigned long cr8);
+void kvm_lapic_set_eoi(struct kvm_vcpu *vcpu);
 void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64 value);
 u64 kvm_lapic_get_base(struct kvm_vcpu *vcpu);
 void kvm_apic_set_version(struct kvm_vcpu *vcpu);
@@ -41,6 +42,9 @@ int kvm_lapic_enabled(struct kvm_vcpu *vcpu);
 bool kvm_apic_present(struct kvm_vcpu *vcpu);
 int kvm_lapic_find_highest_irr(struct kvm_vcpu *vcpu);
 
+u64 kvm_get_lapic_tscdeadline_msr(struct kvm_vcpu *vcpu);
+void kvm_set_lapic_tscdeadline_msr(struct kvm_vcpu *vcpu, u64 data);
+
 void kvm_lapic_set_vapic_addr(struct kvm_vcpu *vcpu, gpa_t vapic_addr);
 void kvm_lapic_sync_from_vapic(struct kvm_vcpu *vcpu);
 void kvm_lapic_sync_to_vapic(struct kvm_vcpu *vcpu);
index 8e8da7960dbeed8be684c770a1ba4cc0c7653e08..f1b36cf3e3d0aff4ee1d587deb044a9618d51869 100644 (file)
@@ -2770,7 +2770,7 @@ static int mmu_alloc_shadow_roots(struct kvm_vcpu *vcpu)
 
                ASSERT(!VALID_PAGE(root));
                if (vcpu->arch.mmu.root_level == PT32E_ROOT_LEVEL) {
-                       pdptr = kvm_pdptr_read_mmu(vcpu, &vcpu->arch.mmu, i);
+                       pdptr = vcpu->arch.mmu.get_pdptr(vcpu, i);
                        if (!is_present_gpte(pdptr)) {
                                vcpu->arch.mmu.pae_root[i] = 0;
                                continue;
@@ -3318,6 +3318,7 @@ static int init_kvm_tdp_mmu(struct kvm_vcpu *vcpu)
        context->direct_map = true;
        context->set_cr3 = kvm_x86_ops->set_tdp_cr3;
        context->get_cr3 = get_cr3;
+       context->get_pdptr = kvm_pdptr_read;
        context->inject_page_fault = kvm_inject_page_fault;
        context->nx = is_nx(vcpu);
 
@@ -3376,6 +3377,7 @@ static int init_kvm_softmmu(struct kvm_vcpu *vcpu)
 
        vcpu->arch.walk_mmu->set_cr3           = kvm_x86_ops->set_cr3;
        vcpu->arch.walk_mmu->get_cr3           = get_cr3;
+       vcpu->arch.walk_mmu->get_pdptr         = kvm_pdptr_read;
        vcpu->arch.walk_mmu->inject_page_fault = kvm_inject_page_fault;
 
        return r;
@@ -3386,6 +3388,7 @@ static int init_kvm_nested_mmu(struct kvm_vcpu *vcpu)
        struct kvm_mmu *g_context = &vcpu->arch.nested_mmu;
 
        g_context->get_cr3           = get_cr3;
+       g_context->get_pdptr         = kvm_pdptr_read;
        g_context->inject_page_fault = kvm_inject_page_fault;
 
        /*
index 2460a265be235e6adbab8c35ec27c79644dcf3e0..746ec259d02490bf7b7ce552560ff37e170d9825 100644 (file)
@@ -121,16 +121,16 @@ static void audit_mappings(struct kvm_vcpu *vcpu, u64 *sptep, int level)
 
 static void inspect_spte_has_rmap(struct kvm *kvm, u64 *sptep)
 {
+       static DEFINE_RATELIMIT_STATE(ratelimit_state, 5 * HZ, 10);
        unsigned long *rmapp;
        struct kvm_mmu_page *rev_sp;
        gfn_t gfn;
 
-
        rev_sp = page_header(__pa(sptep));
        gfn = kvm_mmu_page_get_gfn(rev_sp, sptep - rev_sp->spt);
 
        if (!gfn_to_memslot(kvm, gfn)) {
-               if (!printk_ratelimit())
+               if (!__ratelimit(&ratelimit_state))
                        return;
                audit_printk(kvm, "no memslot for gfn %llx\n", gfn);
                audit_printk(kvm, "index %ld of sp (gfn=%llx)\n",
@@ -141,7 +141,7 @@ static void inspect_spte_has_rmap(struct kvm *kvm, u64 *sptep)
 
        rmapp = gfn_to_rmap(kvm, gfn, rev_sp->role.level);
        if (!*rmapp) {
-               if (!printk_ratelimit())
+               if (!__ratelimit(&ratelimit_state))
                        return;
                audit_printk(kvm, "no rmap for writable spte %llx\n",
                             *sptep);
index 507e2b844cfa96be64ee518e922916479f66a6d7..92994100638b26749519bc69d9c59b5a4ba10cc7 100644 (file)
@@ -147,7 +147,7 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
        gfn_t table_gfn;
        unsigned index, pt_access, uninitialized_var(pte_access);
        gpa_t pte_gpa;
-       bool eperm;
+       bool eperm, last_gpte;
        int offset;
        const int write_fault = access & PFERR_WRITE_MASK;
        const int user_fault  = access & PFERR_USER_MASK;
@@ -163,7 +163,7 @@ retry_walk:
 
 #if PTTYPE == 64
        if (walker->level == PT32E_ROOT_LEVEL) {
-               pte = kvm_pdptr_read_mmu(vcpu, mmu, (addr >> 30) & 3);
+               pte = mmu->get_pdptr(vcpu, (addr >> 30) & 3);
                trace_kvm_mmu_paging_element(pte, walker->level);
                if (!is_present_gpte(pte))
                        goto error;
@@ -221,6 +221,17 @@ retry_walk:
                        eperm = true;
 #endif
 
+               last_gpte = FNAME(is_last_gpte)(walker, vcpu, mmu, pte);
+               if (last_gpte) {
+                       pte_access = pt_access &
+                                    FNAME(gpte_access)(vcpu, pte, true);
+                       /* check if the kernel is fetching from user page */
+                       if (unlikely(pte_access & PT_USER_MASK) &&
+                           kvm_read_cr4_bits(vcpu, X86_CR4_SMEP))
+                               if (fetch_fault && !user_fault)
+                                       eperm = true;
+               }
+
                if (!eperm && unlikely(!(pte & PT_ACCESSED_MASK))) {
                        int ret;
                        trace_kvm_mmu_set_accessed_bit(table_gfn, index,
@@ -238,18 +249,12 @@ retry_walk:
 
                walker->ptes[walker->level - 1] = pte;
 
-               if (FNAME(is_last_gpte)(walker, vcpu, mmu, pte)) {
+               if (last_gpte) {
                        int lvl = walker->level;
                        gpa_t real_gpa;
                        gfn_t gfn;
                        u32 ac;
 
-                       /* check if the kernel is fetching from user page */
-                       if (unlikely(pte_access & PT_USER_MASK) &&
-                           kvm_read_cr4_bits(vcpu, X86_CR4_SMEP))
-                               if (fetch_fault && !user_fault)
-                                       eperm = true;
-
                        gfn = gpte_to_gfn_lvl(pte, lvl);
                        gfn += (addr & PT_LVL_OFFSET_MASK(lvl)) >> PAGE_SHIFT;
 
@@ -295,7 +300,6 @@ retry_walk:
                walker->ptes[walker->level - 1] = pte;
        }
 
-       pte_access = pt_access & FNAME(gpte_access)(vcpu, pte, true);
        walker->pt_access = pt_access;
        walker->pte_access = pte_access;
        pgprintk("%s: pte %llx pte_access %x pt_access %x\n",
index 475d1c948501c0cdd8b12cfe6b0d3ac283811e3d..e32243eac2f48874ac494f5f8a27ed7fb605ebc4 100644 (file)
@@ -1084,7 +1084,6 @@ static void init_vmcb(struct vcpu_svm *svm)
        if (npt_enabled) {
                /* Setup VMCB for Nested Paging */
                control->nested_ctl = 1;
-               clr_intercept(svm, INTERCEPT_TASK_SWITCH);
                clr_intercept(svm, INTERCEPT_INVLPG);
                clr_exception_intercept(svm, PF_VECTOR);
                clr_cr_intercept(svm, INTERCEPT_CR3_READ);
@@ -1844,6 +1843,20 @@ static unsigned long nested_svm_get_tdp_cr3(struct kvm_vcpu *vcpu)
        return svm->nested.nested_cr3;
 }
 
+static u64 nested_svm_get_tdp_pdptr(struct kvm_vcpu *vcpu, int index)
+{
+       struct vcpu_svm *svm = to_svm(vcpu);
+       u64 cr3 = svm->nested.nested_cr3;
+       u64 pdpte;
+       int ret;
+
+       ret = kvm_read_guest_page(vcpu->kvm, gpa_to_gfn(cr3), &pdpte,
+                                 offset_in_page(cr3) + index * 8, 8);
+       if (ret)
+               return 0;
+       return pdpte;
+}
+
 static void nested_svm_set_tdp_cr3(struct kvm_vcpu *vcpu,
                                   unsigned long root)
 {
@@ -1875,6 +1888,7 @@ static int nested_svm_init_mmu_context(struct kvm_vcpu *vcpu)
 
        vcpu->arch.mmu.set_cr3           = nested_svm_set_tdp_cr3;
        vcpu->arch.mmu.get_cr3           = nested_svm_get_tdp_cr3;
+       vcpu->arch.mmu.get_pdptr         = nested_svm_get_tdp_pdptr;
        vcpu->arch.mmu.inject_page_fault = nested_svm_inject_npf_exit;
        vcpu->arch.mmu.shadow_root_level = get_npt_level();
        vcpu->arch.walk_mmu              = &vcpu->arch.nested_mmu;
@@ -2182,7 +2196,8 @@ static int nested_svm_vmexit(struct vcpu_svm *svm)
                                       vmcb->control.exit_info_1,
                                       vmcb->control.exit_info_2,
                                       vmcb->control.exit_int_info,
-                                      vmcb->control.exit_int_info_err);
+                                      vmcb->control.exit_int_info_err,
+                                      KVM_ISA_SVM);
 
        nested_vmcb = nested_svm_map(svm, svm->nested.vmcb, &page);
        if (!nested_vmcb)
@@ -2894,15 +2909,20 @@ static int cr8_write_interception(struct vcpu_svm *svm)
        return 0;
 }
 
+u64 svm_read_l1_tsc(struct kvm_vcpu *vcpu)
+{
+       struct vmcb *vmcb = get_host_vmcb(to_svm(vcpu));
+       return vmcb->control.tsc_offset +
+               svm_scale_tsc(vcpu, native_read_tsc());
+}
+
 static int svm_get_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 *data)
 {
        struct vcpu_svm *svm = to_svm(vcpu);
 
        switch (ecx) {
        case MSR_IA32_TSC: {
-               struct vmcb *vmcb = get_host_vmcb(svm);
-
-               *data = vmcb->control.tsc_offset +
+               *data = svm->vmcb->control.tsc_offset +
                        svm_scale_tsc(vcpu, native_read_tsc());
 
                break;
@@ -3314,8 +3334,6 @@ static int handle_exit(struct kvm_vcpu *vcpu)
        struct kvm_run *kvm_run = vcpu->run;
        u32 exit_code = svm->vmcb->control.exit_code;
 
-       trace_kvm_exit(exit_code, vcpu, KVM_ISA_SVM);
-
        if (!is_cr_intercept(svm, INTERCEPT_CR0_WRITE))
                vcpu->arch.cr0 = svm->vmcb->save.cr0;
        if (npt_enabled)
@@ -3335,7 +3353,8 @@ static int handle_exit(struct kvm_vcpu *vcpu)
                                        svm->vmcb->control.exit_info_1,
                                        svm->vmcb->control.exit_info_2,
                                        svm->vmcb->control.exit_int_info,
-                                       svm->vmcb->control.exit_int_info_err);
+                                       svm->vmcb->control.exit_int_info_err,
+                                       KVM_ISA_SVM);
 
                vmexit = nested_svm_exit_special(svm);
 
@@ -3768,6 +3787,8 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
        vcpu->arch.regs[VCPU_REGS_RSP] = svm->vmcb->save.rsp;
        vcpu->arch.regs[VCPU_REGS_RIP] = svm->vmcb->save.rip;
 
+       trace_kvm_exit(svm->vmcb->control.exit_code, vcpu, KVM_ISA_SVM);
+
        if (unlikely(svm->vmcb->control.exit_code == SVM_EXIT_NMI))
                kvm_before_handle_nmi(&svm->vcpu);
 
@@ -3897,60 +3918,6 @@ static void svm_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry)
        }
 }
 
-static const struct trace_print_flags svm_exit_reasons_str[] = {
-       { SVM_EXIT_READ_CR0,                    "read_cr0" },
-       { SVM_EXIT_READ_CR3,                    "read_cr3" },
-       { SVM_EXIT_READ_CR4,                    "read_cr4" },
-       { SVM_EXIT_READ_CR8,                    "read_cr8" },
-       { SVM_EXIT_WRITE_CR0,                   "write_cr0" },
-       { SVM_EXIT_WRITE_CR3,                   "write_cr3" },
-       { SVM_EXIT_WRITE_CR4,                   "write_cr4" },
-       { SVM_EXIT_WRITE_CR8,                   "write_cr8" },
-       { SVM_EXIT_READ_DR0,                    "read_dr0" },
-       { SVM_EXIT_READ_DR1,                    "read_dr1" },
-       { SVM_EXIT_READ_DR2,                    "read_dr2" },
-       { SVM_EXIT_READ_DR3,                    "read_dr3" },
-       { SVM_EXIT_WRITE_DR0,                   "write_dr0" },
-       { SVM_EXIT_WRITE_DR1,                   "write_dr1" },
-       { SVM_EXIT_WRITE_DR2,                   "write_dr2" },
-       { SVM_EXIT_WRITE_DR3,                   "write_dr3" },
-       { SVM_EXIT_WRITE_DR5,                   "write_dr5" },
-       { SVM_EXIT_WRITE_DR7,                   "write_dr7" },
-       { SVM_EXIT_EXCP_BASE + DB_VECTOR,       "DB excp" },
-       { SVM_EXIT_EXCP_BASE + BP_VECTOR,       "BP excp" },
-       { SVM_EXIT_EXCP_BASE + UD_VECTOR,       "UD excp" },
-       { SVM_EXIT_EXCP_BASE + PF_VECTOR,       "PF excp" },
-       { SVM_EXIT_EXCP_BASE + NM_VECTOR,       "NM excp" },
-       { SVM_EXIT_EXCP_BASE + MC_VECTOR,       "MC excp" },
-       { SVM_EXIT_INTR,                        "interrupt" },
-       { SVM_EXIT_NMI,                         "nmi" },
-       { SVM_EXIT_SMI,                         "smi" },
-       { SVM_EXIT_INIT,                        "init" },
-       { SVM_EXIT_VINTR,                       "vintr" },
-       { SVM_EXIT_CPUID,                       "cpuid" },
-       { SVM_EXIT_INVD,                        "invd" },
-       { SVM_EXIT_HLT,                         "hlt" },
-       { SVM_EXIT_INVLPG,                      "invlpg" },
-       { SVM_EXIT_INVLPGA,                     "invlpga" },
-       { SVM_EXIT_IOIO,                        "io" },
-       { SVM_EXIT_MSR,                         "msr" },
-       { SVM_EXIT_TASK_SWITCH,                 "task_switch" },
-       { SVM_EXIT_SHUTDOWN,                    "shutdown" },
-       { SVM_EXIT_VMRUN,                       "vmrun" },
-       { SVM_EXIT_VMMCALL,                     "hypercall" },
-       { SVM_EXIT_VMLOAD,                      "vmload" },
-       { SVM_EXIT_VMSAVE,                      "vmsave" },
-       { SVM_EXIT_STGI,                        "stgi" },
-       { SVM_EXIT_CLGI,                        "clgi" },
-       { SVM_EXIT_SKINIT,                      "skinit" },
-       { SVM_EXIT_WBINVD,                      "wbinvd" },
-       { SVM_EXIT_MONITOR,                     "monitor" },
-       { SVM_EXIT_MWAIT,                       "mwait" },
-       { SVM_EXIT_XSETBV,                      "xsetbv" },
-       { SVM_EXIT_NPF,                         "npf" },
-       { -1, NULL }
-};
-
 static int svm_get_lpage_level(void)
 {
        return PT_PDPE_LEVEL;
@@ -4223,7 +4190,6 @@ static struct kvm_x86_ops svm_x86_ops = {
        .get_mt_mask = svm_get_mt_mask,
 
        .get_exit_info = svm_get_exit_info,
-       .exit_reasons_str = svm_exit_reasons_str,
 
        .get_lpage_level = svm_get_lpage_level,
 
@@ -4239,6 +4205,7 @@ static struct kvm_x86_ops svm_x86_ops = {
        .write_tsc_offset = svm_write_tsc_offset,
        .adjust_tsc_offset = svm_adjust_tsc_offset,
        .compute_tsc_offset = svm_compute_tsc_offset,
+       .read_l1_tsc = svm_read_l1_tsc,
 
        .set_tdp_cr3 = set_tdp_cr3,
 
index 3ff898c104f722e27a9d162d12eb96fa4d72e07d..911d2641f14c5cba355abc25e00f38f07ced1df9 100644 (file)
@@ -2,6 +2,8 @@
 #define _TRACE_KVM_H
 
 #include <linux/tracepoint.h>
+#include <asm/vmx.h>
+#include <asm/svm.h>
 
 #undef TRACE_SYSTEM
 #define TRACE_SYSTEM kvm
@@ -181,6 +183,95 @@ TRACE_EVENT(kvm_apic,
 #define KVM_ISA_VMX   1
 #define KVM_ISA_SVM   2
 
+#define VMX_EXIT_REASONS \
+       { EXIT_REASON_EXCEPTION_NMI,            "EXCEPTION_NMI" }, \
+       { EXIT_REASON_EXTERNAL_INTERRUPT,       "EXTERNAL_INTERRUPT" }, \
+       { EXIT_REASON_TRIPLE_FAULT,             "TRIPLE_FAULT" }, \
+       { EXIT_REASON_PENDING_INTERRUPT,        "PENDING_INTERRUPT" }, \
+       { EXIT_REASON_NMI_WINDOW,               "NMI_WINDOW" }, \
+       { EXIT_REASON_TASK_SWITCH,              "TASK_SWITCH" }, \
+       { EXIT_REASON_CPUID,                    "CPUID" }, \
+       { EXIT_REASON_HLT,                      "HLT" }, \
+       { EXIT_REASON_INVLPG,                   "INVLPG" }, \
+       { EXIT_REASON_RDPMC,                    "RDPMC" }, \
+       { EXIT_REASON_RDTSC,                    "RDTSC" }, \
+       { EXIT_REASON_VMCALL,                   "VMCALL" }, \
+       { EXIT_REASON_VMCLEAR,                  "VMCLEAR" }, \
+       { EXIT_REASON_VMLAUNCH,                 "VMLAUNCH" }, \
+       { EXIT_REASON_VMPTRLD,                  "VMPTRLD" }, \
+       { EXIT_REASON_VMPTRST,                  "VMPTRST" }, \
+       { EXIT_REASON_VMREAD,                   "VMREAD" }, \
+       { EXIT_REASON_VMRESUME,                 "VMRESUME" }, \
+       { EXIT_REASON_VMWRITE,                  "VMWRITE" }, \
+       { EXIT_REASON_VMOFF,                    "VMOFF" }, \
+       { EXIT_REASON_VMON,                     "VMON" }, \
+       { EXIT_REASON_CR_ACCESS,                "CR_ACCESS" }, \
+       { EXIT_REASON_DR_ACCESS,                "DR_ACCESS" }, \
+       { EXIT_REASON_IO_INSTRUCTION,           "IO_INSTRUCTION" }, \
+       { EXIT_REASON_MSR_READ,                 "MSR_READ" }, \
+       { EXIT_REASON_MSR_WRITE,                "MSR_WRITE" }, \
+       { EXIT_REASON_MWAIT_INSTRUCTION,        "MWAIT_INSTRUCTION" }, \
+       { EXIT_REASON_MONITOR_INSTRUCTION,      "MONITOR_INSTRUCTION" }, \
+       { EXIT_REASON_PAUSE_INSTRUCTION,        "PAUSE_INSTRUCTION" }, \
+       { EXIT_REASON_MCE_DURING_VMENTRY,       "MCE_DURING_VMENTRY" }, \
+       { EXIT_REASON_TPR_BELOW_THRESHOLD,      "TPR_BELOW_THRESHOLD" },        \
+       { EXIT_REASON_APIC_ACCESS,              "APIC_ACCESS" }, \
+       { EXIT_REASON_EPT_VIOLATION,            "EPT_VIOLATION" }, \
+       { EXIT_REASON_EPT_MISCONFIG,            "EPT_MISCONFIG" }, \
+       { EXIT_REASON_WBINVD,                   "WBINVD" }
+
+#define SVM_EXIT_REASONS \
+       { SVM_EXIT_READ_CR0,                    "read_cr0" }, \
+       { SVM_EXIT_READ_CR3,                    "read_cr3" }, \
+       { SVM_EXIT_READ_CR4,                    "read_cr4" }, \
+       { SVM_EXIT_READ_CR8,                    "read_cr8" }, \
+       { SVM_EXIT_WRITE_CR0,                   "write_cr0" }, \
+       { SVM_EXIT_WRITE_CR3,                   "write_cr3" }, \
+       { SVM_EXIT_WRITE_CR4,                   "write_cr4" }, \
+       { SVM_EXIT_WRITE_CR8,                   "write_cr8" }, \
+       { SVM_EXIT_READ_DR0,                    "read_dr0" }, \
+       { SVM_EXIT_READ_DR1,                    "read_dr1" }, \
+       { SVM_EXIT_READ_DR2,                    "read_dr2" }, \
+       { SVM_EXIT_READ_DR3,                    "read_dr3" }, \
+       { SVM_EXIT_WRITE_DR0,                   "write_dr0" }, \
+       { SVM_EXIT_WRITE_DR1,                   "write_dr1" }, \
+       { SVM_EXIT_WRITE_DR2,                   "write_dr2" }, \
+       { SVM_EXIT_WRITE_DR3,                   "write_dr3" }, \
+       { SVM_EXIT_WRITE_DR5,                   "write_dr5" }, \
+       { SVM_EXIT_WRITE_DR7,                   "write_dr7" }, \
+       { SVM_EXIT_EXCP_BASE + DB_VECTOR,       "DB excp" }, \
+       { SVM_EXIT_EXCP_BASE + BP_VECTOR,       "BP excp" }, \
+       { SVM_EXIT_EXCP_BASE + UD_VECTOR,       "UD excp" }, \
+       { SVM_EXIT_EXCP_BASE + PF_VECTOR,       "PF excp" }, \
+       { SVM_EXIT_EXCP_BASE + NM_VECTOR,       "NM excp" }, \
+       { SVM_EXIT_EXCP_BASE + MC_VECTOR,       "MC excp" }, \
+       { SVM_EXIT_INTR,                        "interrupt" }, \
+       { SVM_EXIT_NMI,                         "nmi" }, \
+       { SVM_EXIT_SMI,                         "smi" }, \
+       { SVM_EXIT_INIT,                        "init" }, \
+       { SVM_EXIT_VINTR,                       "vintr" }, \
+       { SVM_EXIT_CPUID,                       "cpuid" }, \
+       { SVM_EXIT_INVD,                        "invd" }, \
+       { SVM_EXIT_HLT,                         "hlt" }, \
+       { SVM_EXIT_INVLPG,                      "invlpg" }, \
+       { SVM_EXIT_INVLPGA,                     "invlpga" }, \
+       { SVM_EXIT_IOIO,                        "io" }, \
+       { SVM_EXIT_MSR,                         "msr" }, \
+       { SVM_EXIT_TASK_SWITCH,                 "task_switch" }, \
+       { SVM_EXIT_SHUTDOWN,                    "shutdown" }, \
+       { SVM_EXIT_VMRUN,                       "vmrun" }, \
+       { SVM_EXIT_VMMCALL,                     "hypercall" }, \
+       { SVM_EXIT_VMLOAD,                      "vmload" }, \
+       { SVM_EXIT_VMSAVE,                      "vmsave" }, \
+       { SVM_EXIT_STGI,                        "stgi" }, \
+       { SVM_EXIT_CLGI,                        "clgi" }, \
+       { SVM_EXIT_SKINIT,                      "skinit" }, \
+       { SVM_EXIT_WBINVD,                      "wbinvd" }, \
+       { SVM_EXIT_MONITOR,                     "monitor" }, \
+       { SVM_EXIT_MWAIT,                       "mwait" }, \
+       { SVM_EXIT_XSETBV,                      "xsetbv" }, \
+       { SVM_EXIT_NPF,                         "npf" }
+
 /*
  * Tracepoint for kvm guest exit:
  */
@@ -205,8 +296,9 @@ TRACE_EVENT(kvm_exit,
        ),
 
        TP_printk("reason %s rip 0x%lx info %llx %llx",
-                ftrace_print_symbols_seq(p, __entry->exit_reason,
-                                         kvm_x86_ops->exit_reasons_str),
+                (__entry->isa == KVM_ISA_VMX) ?
+                __print_symbolic(__entry->exit_reason, VMX_EXIT_REASONS) :
+                __print_symbolic(__entry->exit_reason, SVM_EXIT_REASONS),
                 __entry->guest_rip, __entry->info1, __entry->info2)
 );
 
@@ -486,9 +578,9 @@ TRACE_EVENT(kvm_nested_intercepts,
 TRACE_EVENT(kvm_nested_vmexit,
            TP_PROTO(__u64 rip, __u32 exit_code,
                     __u64 exit_info1, __u64 exit_info2,
-                    __u32 exit_int_info, __u32 exit_int_info_err),
+                    __u32 exit_int_info, __u32 exit_int_info_err, __u32 isa),
            TP_ARGS(rip, exit_code, exit_info1, exit_info2,
-                   exit_int_info, exit_int_info_err),
+                   exit_int_info, exit_int_info_err, isa),
 
        TP_STRUCT__entry(
                __field(        __u64,          rip                     )
@@ -497,6 +589,7 @@ TRACE_EVENT(kvm_nested_vmexit,
                __field(        __u64,          exit_info2              )
                __field(        __u32,          exit_int_info           )
                __field(        __u32,          exit_int_info_err       )
+               __field(        __u32,          isa                     )
        ),
 
        TP_fast_assign(
@@ -506,12 +599,14 @@ TRACE_EVENT(kvm_nested_vmexit,
                __entry->exit_info2             = exit_info2;
                __entry->exit_int_info          = exit_int_info;
                __entry->exit_int_info_err      = exit_int_info_err;
+               __entry->isa                    = isa;
        ),
        TP_printk("rip: 0x%016llx reason: %s ext_inf1: 0x%016llx "
                  "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x",
                  __entry->rip,
-                 ftrace_print_symbols_seq(p, __entry->exit_code,
-                                          kvm_x86_ops->exit_reasons_str),
+                (__entry->isa == KVM_ISA_VMX) ?
+                __print_symbolic(__entry->exit_code, VMX_EXIT_REASONS) :
+                __print_symbolic(__entry->exit_code, SVM_EXIT_REASONS),
                  __entry->exit_info1, __entry->exit_info2,
                  __entry->exit_int_info, __entry->exit_int_info_err)
 );
@@ -522,9 +617,9 @@ TRACE_EVENT(kvm_nested_vmexit,
 TRACE_EVENT(kvm_nested_vmexit_inject,
            TP_PROTO(__u32 exit_code,
                     __u64 exit_info1, __u64 exit_info2,
-                    __u32 exit_int_info, __u32 exit_int_info_err),
+                    __u32 exit_int_info, __u32 exit_int_info_err, __u32 isa),
            TP_ARGS(exit_code, exit_info1, exit_info2,
-                   exit_int_info, exit_int_info_err),
+                   exit_int_info, exit_int_info_err, isa),
 
        TP_STRUCT__entry(
                __field(        __u32,          exit_code               )
@@ -532,6 +627,7 @@ TRACE_EVENT(kvm_nested_vmexit_inject,
                __field(        __u64,          exit_info2              )
                __field(        __u32,          exit_int_info           )
                __field(        __u32,          exit_int_info_err       )
+               __field(        __u32,          isa                     )
        ),
 
        TP_fast_assign(
@@ -540,12 +636,14 @@ TRACE_EVENT(kvm_nested_vmexit_inject,
                __entry->exit_info2             = exit_info2;
                __entry->exit_int_info          = exit_int_info;
                __entry->exit_int_info_err      = exit_int_info_err;
+               __entry->isa                    = isa;
        ),
 
        TP_printk("reason: %s ext_inf1: 0x%016llx "
                  "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x",
-                 ftrace_print_symbols_seq(p, __entry->exit_code,
-                                          kvm_x86_ops->exit_reasons_str),
+                (__entry->isa == KVM_ISA_VMX) ?
+                __print_symbolic(__entry->exit_code, VMX_EXIT_REASONS) :
+                __print_symbolic(__entry->exit_code, SVM_EXIT_REASONS),
                __entry->exit_info1, __entry->exit_info2,
                __entry->exit_int_info, __entry->exit_int_info_err)
 );
index e65a158dee645331f990ed31523becddd0bb307f..a0d6bd9ad442f1746bfa66eaabe86641470b7d0f 100644 (file)
@@ -71,6 +71,9 @@ module_param(vmm_exclusive, bool, S_IRUGO);
 static int __read_mostly yield_on_hlt = 1;
 module_param(yield_on_hlt, bool, S_IRUGO);
 
+static int __read_mostly fasteoi = 1;
+module_param(fasteoi, bool, S_IRUGO);
+
 /*
  * If nested=1, nested virtualization is supported, i.e., guests may use
  * VMX and be a hypervisor for its own guests. If nested=0, guests may not
@@ -1747,6 +1750,21 @@ static u64 guest_read_tsc(void)
        return host_tsc + tsc_offset;
 }
 
+/*
+ * Like guest_read_tsc, but always returns L1's notion of the timestamp
+ * counter, even if a nested guest (L2) is currently running.
+ */
+u64 vmx_read_l1_tsc(struct kvm_vcpu *vcpu)
+{
+       u64 host_tsc, tsc_offset;
+
+       rdtscll(host_tsc);
+       tsc_offset = is_guest_mode(vcpu) ?
+               to_vmx(vcpu)->nested.vmcs01_tsc_offset :
+               vmcs_read64(TSC_OFFSET);
+       return host_tsc + tsc_offset;
+}
+
 /*
  * Empty call-back. Needs to be implemented when VMX enables the SET_TSC_KHZ
  * ioctl. In this case the call-back should update internal vmx state to make
@@ -1762,15 +1780,23 @@ static void vmx_set_tsc_khz(struct kvm_vcpu *vcpu, u32 user_tsc_khz)
  */
 static void vmx_write_tsc_offset(struct kvm_vcpu *vcpu, u64 offset)
 {
-       vmcs_write64(TSC_OFFSET, offset);
-       if (is_guest_mode(vcpu))
+       if (is_guest_mode(vcpu)) {
                /*
-                * We're here if L1 chose not to trap the TSC MSR. Since
-                * prepare_vmcs12() does not copy tsc_offset, we need to also
-                * set the vmcs12 field here.
+                * We're here if L1 chose not to trap WRMSR to TSC. According
+                * to the spec, this should set L1's TSC; The offset that L1
+                * set for L2 remains unchanged, and still needs to be added
+                * to the newly set TSC to get L2's TSC.
                 */
-               get_vmcs12(vcpu)->tsc_offset = offset -
-                       to_vmx(vcpu)->nested.vmcs01_tsc_offset;
+               struct vmcs12 *vmcs12;
+               to_vmx(vcpu)->nested.vmcs01_tsc_offset = offset;
+               /* recalculate vmcs02.TSC_OFFSET: */
+               vmcs12 = get_vmcs12(vcpu);
+               vmcs_write64(TSC_OFFSET, offset +
+                       (nested_cpu_has(vmcs12, CPU_BASED_USE_TSC_OFFSETING) ?
+                        vmcs12->tsc_offset : 0));
+       } else {
+               vmcs_write64(TSC_OFFSET, offset);
+       }
 }
 
 static void vmx_adjust_tsc_offset(struct kvm_vcpu *vcpu, s64 adjustment)
@@ -2736,8 +2762,8 @@ static void enter_lmode(struct kvm_vcpu *vcpu)
 
        guest_tr_ar = vmcs_read32(GUEST_TR_AR_BYTES);
        if ((guest_tr_ar & AR_TYPE_MASK) != AR_TYPE_BUSY_64_TSS) {
-               printk(KERN_DEBUG "%s: tss fixup for long mode. \n",
-                      __func__);
+               pr_debug_ratelimited("%s: tss fixup for long mode. \n",
+                                    __func__);
                vmcs_write32(GUEST_TR_AR_BYTES,
                             (guest_tr_ar & ~AR_TYPE_MASK)
                             | AR_TYPE_BUSY_64_TSS);
@@ -4115,8 +4141,7 @@ static int handle_exception(struct kvm_vcpu *vcpu)
                error_code = vmcs_read32(VM_EXIT_INTR_ERROR_CODE);
        if (is_page_fault(intr_info)) {
                /* EPT won't cause page fault directly */
-               if (enable_ept)
-                       BUG();
+               BUG_ON(enable_ept);
                cr2 = vmcs_readl(EXIT_QUALIFICATION);
                trace_kvm_page_fault(cr2, error_code);
 
@@ -4518,6 +4543,24 @@ static int handle_xsetbv(struct kvm_vcpu *vcpu)
 
 static int handle_apic_access(struct kvm_vcpu *vcpu)
 {
+       if (likely(fasteoi)) {
+               unsigned long exit_qualification = vmcs_readl(EXIT_QUALIFICATION);
+               int access_type, offset;
+
+               access_type = exit_qualification & APIC_ACCESS_TYPE;
+               offset = exit_qualification & APIC_ACCESS_OFFSET;
+               /*
+                * Sane guest uses MOV to write EOI, with written value
+                * not cared. So make a short-circuit here by avoiding
+                * heavy instruction emulation.
+                */
+               if ((access_type == TYPE_LINEAR_APIC_INST_WRITE) &&
+                   (offset == APIC_EOI)) {
+                       kvm_lapic_set_eoi(vcpu);
+                       skip_emulated_instruction(vcpu);
+                       return 1;
+               }
+       }
        return emulate_instruction(vcpu, 0) == EMULATE_DONE;
 }
 
@@ -5591,8 +5634,8 @@ static bool nested_vmx_exit_handled(struct kvm_vcpu *vcpu)
                return 0;
 
        if (unlikely(vmx->fail)) {
-               printk(KERN_INFO "%s failed vm entry %x\n",
-                      __func__, vmcs_read32(VM_INSTRUCTION_ERROR));
+               pr_info_ratelimited("%s failed vm entry %x\n", __func__,
+                                   vmcs_read32(VM_INSTRUCTION_ERROR));
                return 1;
        }
 
@@ -5696,8 +5739,6 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu)
        u32 exit_reason = vmx->exit_reason;
        u32 vectoring_info = vmx->idt_vectoring_info;
 
-       trace_kvm_exit(exit_reason, vcpu, KVM_ISA_VMX);
-
        /* If guest state is invalid, start emulating */
        if (vmx->emulation_required && emulate_invalid_guest_state)
                return handle_invalid_guest_state(vcpu);
@@ -6101,6 +6142,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
        vmx->loaded_vmcs->launched = 1;
 
        vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
+       trace_kvm_exit(vmx->exit_reason, vcpu, KVM_ISA_VMX);
 
        vmx_complete_atomic_exit(vmx);
        vmx_recover_nmi_blocking(vmx);
@@ -6241,49 +6283,6 @@ static u64 vmx_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio)
        return ret;
 }
 
-#define _ER(x) { EXIT_REASON_##x, #x }
-
-static const struct trace_print_flags vmx_exit_reasons_str[] = {
-       _ER(EXCEPTION_NMI),
-       _ER(EXTERNAL_INTERRUPT),
-       _ER(TRIPLE_FAULT),
-       _ER(PENDING_INTERRUPT),
-       _ER(NMI_WINDOW),
-       _ER(TASK_SWITCH),
-       _ER(CPUID),
-       _ER(HLT),
-       _ER(INVLPG),
-       _ER(RDPMC),
-       _ER(RDTSC),
-       _ER(VMCALL),
-       _ER(VMCLEAR),
-       _ER(VMLAUNCH),
-       _ER(VMPTRLD),
-       _ER(VMPTRST),
-       _ER(VMREAD),
-       _ER(VMRESUME),
-       _ER(VMWRITE),
-       _ER(VMOFF),
-       _ER(VMON),
-       _ER(CR_ACCESS),
-       _ER(DR_ACCESS),
-       _ER(IO_INSTRUCTION),
-       _ER(MSR_READ),
-       _ER(MSR_WRITE),
-       _ER(MWAIT_INSTRUCTION),
-       _ER(MONITOR_INSTRUCTION),
-       _ER(PAUSE_INSTRUCTION),
-       _ER(MCE_DURING_VMENTRY),
-       _ER(TPR_BELOW_THRESHOLD),
-       _ER(APIC_ACCESS),
-       _ER(EPT_VIOLATION),
-       _ER(EPT_MISCONFIG),
-       _ER(WBINVD),
-       { -1, NULL }
-};
-
-#undef _ER
-
 static int vmx_get_lpage_level(void)
 {
        if (enable_ept && !cpu_has_vmx_ept_1g_page())
@@ -6514,8 +6513,11 @@ static void prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)
 
        set_cr4_guest_host_mask(vmx);
 
-       vmcs_write64(TSC_OFFSET,
-               vmx->nested.vmcs01_tsc_offset + vmcs12->tsc_offset);
+       if (vmcs12->cpu_based_vm_exec_control & CPU_BASED_USE_TSC_OFFSETING)
+               vmcs_write64(TSC_OFFSET,
+                       vmx->nested.vmcs01_tsc_offset + vmcs12->tsc_offset);
+       else
+               vmcs_write64(TSC_OFFSET, vmx->nested.vmcs01_tsc_offset);
 
        if (enable_vpid) {
                /*
@@ -6610,9 +6612,8 @@ static int nested_vmx_run(struct kvm_vcpu *vcpu, bool launch)
        if (vmcs12->vm_entry_msr_load_count > 0 ||
            vmcs12->vm_exit_msr_load_count > 0 ||
            vmcs12->vm_exit_msr_store_count > 0) {
-               if (printk_ratelimit())
-                       printk(KERN_WARNING
-                         "%s: VMCS MSR_{LOAD,STORE} unsupported\n", __func__);
+               pr_warn_ratelimited("%s: VMCS MSR_{LOAD,STORE} unsupported\n",
+                                   __func__);
                nested_vmx_failValid(vcpu, VMXERR_ENTRY_INVALID_CONTROL_FIELD);
                return 1;
        }
@@ -6922,7 +6923,7 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu)
 
        load_vmcs12_host_state(vcpu, vmcs12);
 
-       /* Update TSC_OFFSET if vmx_adjust_tsc_offset() was used while L2 ran */
+       /* Update TSC_OFFSET if TSC was changed while L2 ran */
        vmcs_write64(TSC_OFFSET, vmx->nested.vmcs01_tsc_offset);
 
        /* This is needed for same reason as it was needed in prepare_vmcs02 */
@@ -7039,7 +7040,6 @@ static struct kvm_x86_ops vmx_x86_ops = {
        .get_mt_mask = vmx_get_mt_mask,
 
        .get_exit_info = vmx_get_exit_info,
-       .exit_reasons_str = vmx_exit_reasons_str,
 
        .get_lpage_level = vmx_get_lpage_level,
 
@@ -7055,6 +7055,7 @@ static struct kvm_x86_ops vmx_x86_ops = {
        .write_tsc_offset = vmx_write_tsc_offset,
        .adjust_tsc_offset = vmx_adjust_tsc_offset,
        .compute_tsc_offset = vmx_compute_tsc_offset,
+       .read_l1_tsc = vmx_read_l1_tsc,
 
        .set_tdp_cr3 = vmx_set_cr3,
 
index 84a28ea45fa494b76fd89cf1d9698cd8c4b14d9f..c38efd7b792eec9aab414892c23818446ad3fad0 100644 (file)
@@ -44,6 +44,7 @@
 #include <linux/perf_event.h>
 #include <linux/uaccess.h>
 #include <linux/hash.h>
+#include <linux/pci.h>
 #include <trace/events/kvm.h>
 
 #define CREATE_TRACE_POINTS
@@ -83,6 +84,7 @@ static u64 __read_mostly efer_reserved_bits = ~((u64)EFER_SCE);
 static void update_cr8_intercept(struct kvm_vcpu *vcpu);
 static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
                                    struct kvm_cpuid_entry2 __user *entries);
+static void process_nmi(struct kvm_vcpu *vcpu);
 
 struct kvm_x86_ops *kvm_x86_ops;
 EXPORT_SYMBOL_GPL(kvm_x86_ops);
@@ -359,8 +361,8 @@ void kvm_propagate_fault(struct kvm_vcpu *vcpu, struct x86_exception *fault)
 
 void kvm_inject_nmi(struct kvm_vcpu *vcpu)
 {
-       kvm_make_request(KVM_REQ_EVENT, vcpu);
-       vcpu->arch.nmi_pending = 1;
+       atomic_inc(&vcpu->arch.nmi_queued);
+       kvm_make_request(KVM_REQ_NMI, vcpu);
 }
 EXPORT_SYMBOL_GPL(kvm_inject_nmi);
 
@@ -599,6 +601,8 @@ static bool guest_cpuid_has_fsgsbase(struct kvm_vcpu *vcpu)
 static void update_cpuid(struct kvm_vcpu *vcpu)
 {
        struct kvm_cpuid_entry2 *best;
+       struct kvm_lapic *apic = vcpu->arch.apic;
+       u32 timer_mode_mask;
 
        best = kvm_find_cpuid_entry(vcpu, 1, 0);
        if (!best)
@@ -610,6 +614,16 @@ static void update_cpuid(struct kvm_vcpu *vcpu)
                if (kvm_read_cr4_bits(vcpu, X86_CR4_OSXSAVE))
                        best->ecx |= bit(X86_FEATURE_OSXSAVE);
        }
+
+       if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
+               best->function == 0x1) {
+               best->ecx |= bit(X86_FEATURE_TSC_DEADLINE_TIMER);
+               timer_mode_mask = 3 << 17;
+       } else
+               timer_mode_mask = 1 << 17;
+
+       if (apic)
+               apic->lapic_timer.timer_mode_mask = timer_mode_mask;
 }
 
 int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
@@ -825,6 +839,7 @@ static u32 msrs_to_save[] = {
 static unsigned num_msrs_to_save;
 
 static u32 emulated_msrs[] = {
+       MSR_IA32_TSCDEADLINE,
        MSR_IA32_MISC_ENABLE,
        MSR_IA32_MCG_STATUS,
        MSR_IA32_MCG_CTL,
@@ -1000,7 +1015,7 @@ static inline int kvm_tsc_changes_freq(void)
        return ret;
 }
 
-static u64 vcpu_tsc_khz(struct kvm_vcpu *vcpu)
+u64 vcpu_tsc_khz(struct kvm_vcpu *vcpu)
 {
        if (vcpu->arch.virtual_tsc_khz)
                return vcpu->arch.virtual_tsc_khz;
@@ -1098,7 +1113,7 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
 
        /* Keep irq disabled to prevent changes to the clock */
        local_irq_save(flags);
-       kvm_get_msr(v, MSR_IA32_TSC, &tsc_timestamp);
+       tsc_timestamp = kvm_x86_ops->read_l1_tsc(v);
        kernel_ns = get_kernel_ns();
        this_tsc_khz = vcpu_tsc_khz(v);
        if (unlikely(this_tsc_khz == 0)) {
@@ -1564,6 +1579,9 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data)
                break;
        case APIC_BASE_MSR ... APIC_BASE_MSR + 0x3ff:
                return kvm_x2apic_msr_write(vcpu, msr, data);
+       case MSR_IA32_TSCDEADLINE:
+               kvm_set_lapic_tscdeadline_msr(vcpu, data);
+               break;
        case MSR_IA32_MISC_ENABLE:
                vcpu->arch.ia32_misc_enable_msr = data;
                break;
@@ -1825,6 +1843,9 @@ static int get_msr_hyperv(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
                return kvm_hv_vapic_msr_read(vcpu, APIC_ICR, pdata);
        case HV_X64_MSR_TPR:
                return kvm_hv_vapic_msr_read(vcpu, APIC_TASKPRI, pdata);
+       case HV_X64_MSR_APIC_ASSIST_PAGE:
+               data = vcpu->arch.hv_vapic;
+               break;
        default:
                pr_unimpl(vcpu, "Hyper-V unhandled rdmsr: 0x%x\n", msr);
                return 1;
@@ -1839,7 +1860,6 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
 
        switch (msr) {
        case MSR_IA32_PLATFORM_ID:
-       case MSR_IA32_UCODE_REV:
        case MSR_IA32_EBL_CR_POWERON:
        case MSR_IA32_DEBUGCTLMSR:
        case MSR_IA32_LASTBRANCHFROMIP:
@@ -1860,6 +1880,9 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
        case MSR_FAM10H_MMIO_CONF_BASE:
                data = 0;
                break;
+       case MSR_IA32_UCODE_REV:
+               data = 0x100000000ULL;
+               break;
        case MSR_MTRRcap:
                data = 0x500 | KVM_NR_VAR_MTRR;
                break;
@@ -1888,6 +1911,9 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
        case APIC_BASE_MSR ... APIC_BASE_MSR + 0x3ff:
                return kvm_x2apic_msr_read(vcpu, msr, pdata);
                break;
+       case MSR_IA32_TSCDEADLINE:
+               data = kvm_get_lapic_tscdeadline_msr(vcpu);
+               break;
        case MSR_IA32_MISC_ENABLE:
                data = vcpu->arch.ia32_misc_enable_msr;
                break;
@@ -2086,6 +2112,9 @@ int kvm_dev_ioctl_check_extension(long ext)
                r = !kvm_x86_ops->cpu_has_accelerated_tpr();
                break;
        case KVM_CAP_NR_VCPUS:
+               r = KVM_SOFT_MAX_VCPUS;
+               break;
+       case KVM_CAP_MAX_VCPUS:
                r = KVM_MAX_VCPUS;
                break;
        case KVM_CAP_NR_MEMSLOTS:
@@ -2095,7 +2124,7 @@ int kvm_dev_ioctl_check_extension(long ext)
                r = 0;
                break;
        case KVM_CAP_IOMMU:
-               r = iommu_found();
+               r = iommu_present(&pci_bus_type);
                break;
        case KVM_CAP_MCE:
                r = KVM_MAX_MCE_BANKS;
@@ -2210,7 +2239,7 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
                s64 tsc_delta;
                u64 tsc;
 
-               kvm_get_msr(vcpu, MSR_IA32_TSC, &tsc);
+               tsc = kvm_x86_ops->read_l1_tsc(vcpu);
                tsc_delta = !vcpu->arch.last_guest_tsc ? 0 :
                             tsc - vcpu->arch.last_guest_tsc;
 
@@ -2234,7 +2263,7 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
 {
        kvm_x86_ops->vcpu_put(vcpu);
        kvm_put_guest_fpu(vcpu);
-       kvm_get_msr(vcpu, MSR_IA32_TSC, &vcpu->arch.last_guest_tsc);
+       vcpu->arch.last_guest_tsc = kvm_x86_ops->read_l1_tsc(vcpu);
 }
 
 static int is_efer_nx(void)
@@ -2819,6 +2848,7 @@ static int kvm_vcpu_ioctl_x86_set_mce(struct kvm_vcpu *vcpu,
 static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct kvm_vcpu *vcpu,
                                               struct kvm_vcpu_events *events)
 {
+       process_nmi(vcpu);
        events->exception.injected =
                vcpu->arch.exception.pending &&
                !kvm_exception_is_soft(vcpu->arch.exception.nr);
@@ -2836,7 +2866,7 @@ static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct kvm_vcpu *vcpu,
                        KVM_X86_SHADOW_INT_MOV_SS | KVM_X86_SHADOW_INT_STI);
 
        events->nmi.injected = vcpu->arch.nmi_injected;
-       events->nmi.pending = vcpu->arch.nmi_pending;
+       events->nmi.pending = vcpu->arch.nmi_pending != 0;
        events->nmi.masked = kvm_x86_ops->get_nmi_mask(vcpu);
        events->nmi.pad = 0;
 
@@ -2856,6 +2886,7 @@ static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu,
                              | KVM_VCPUEVENT_VALID_SHADOW))
                return -EINVAL;
 
+       process_nmi(vcpu);
        vcpu->arch.exception.pending = events->exception.injected;
        vcpu->arch.exception.nr = events->exception.nr;
        vcpu->arch.exception.has_error_code = events->exception.has_error_code;
@@ -3556,7 +3587,11 @@ long kvm_arch_vm_ioctl(struct file *filp,
                        if (r) {
                                mutex_lock(&kvm->slots_lock);
                                kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS,
-                                                         &vpic->dev);
+                                                         &vpic->dev_master);
+                               kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS,
+                                                         &vpic->dev_slave);
+                               kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS,
+                                                         &vpic->dev_eclr);
                                mutex_unlock(&kvm->slots_lock);
                                kfree(vpic);
                                goto create_irqchip_unlock;
@@ -4045,84 +4080,105 @@ static int vcpu_mmio_gva_to_gpa(struct kvm_vcpu *vcpu, unsigned long gva,
        return 0;
 }
 
-static int emulator_read_emulated(struct x86_emulate_ctxt *ctxt,
-                                 unsigned long addr,
-                                 void *val,
-                                 unsigned int bytes,
-                                 struct x86_exception *exception)
+int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
+                       const void *val, int bytes)
 {
-       struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
-       gpa_t gpa;
-       int handled, ret;
+       int ret;
 
+       ret = kvm_write_guest(vcpu->kvm, gpa, val, bytes);
+       if (ret < 0)
+               return 0;
+       kvm_mmu_pte_write(vcpu, gpa, val, bytes, 1);
+       return 1;
+}
+
+struct read_write_emulator_ops {
+       int (*read_write_prepare)(struct kvm_vcpu *vcpu, void *val,
+                                 int bytes);
+       int (*read_write_emulate)(struct kvm_vcpu *vcpu, gpa_t gpa,
+                                 void *val, int bytes);
+       int (*read_write_mmio)(struct kvm_vcpu *vcpu, gpa_t gpa,
+                              int bytes, void *val);
+       int (*read_write_exit_mmio)(struct kvm_vcpu *vcpu, gpa_t gpa,
+                                   void *val, int bytes);
+       bool write;
+};
+
+static int read_prepare(struct kvm_vcpu *vcpu, void *val, int bytes)
+{
        if (vcpu->mmio_read_completed) {
                memcpy(val, vcpu->mmio_data, bytes);
                trace_kvm_mmio(KVM_TRACE_MMIO_READ, bytes,
                               vcpu->mmio_phys_addr, *(u64 *)val);
                vcpu->mmio_read_completed = 0;
-               return X86EMUL_CONTINUE;
+               return 1;
        }
 
-       ret = vcpu_mmio_gva_to_gpa(vcpu, addr, &gpa, exception, false);
-
-       if (ret < 0)
-               return X86EMUL_PROPAGATE_FAULT;
-
-       if (ret)
-               goto mmio;
-
-       if (kvm_read_guest_virt(ctxt, addr, val, bytes, exception)
-           == X86EMUL_CONTINUE)
-               return X86EMUL_CONTINUE;
+       return 0;
+}
 
-mmio:
-       /*
-        * Is this MMIO handled locally?
-        */
-       handled = vcpu_mmio_read(vcpu, gpa, bytes, val);
+static int read_emulate(struct kvm_vcpu *vcpu, gpa_t gpa,
+                       void *val, int bytes)
+{
+       return !kvm_read_guest(vcpu->kvm, gpa, val, bytes);
+}
 
-       if (handled == bytes)
-               return X86EMUL_CONTINUE;
+static int write_emulate(struct kvm_vcpu *vcpu, gpa_t gpa,
+                        void *val, int bytes)
+{
+       return emulator_write_phys(vcpu, gpa, val, bytes);
+}
 
-       gpa += handled;
-       bytes -= handled;
-       val += handled;
+static int write_mmio(struct kvm_vcpu *vcpu, gpa_t gpa, int bytes, void *val)
+{
+       trace_kvm_mmio(KVM_TRACE_MMIO_WRITE, bytes, gpa, *(u64 *)val);
+       return vcpu_mmio_write(vcpu, gpa, bytes, val);
+}
 
+static int read_exit_mmio(struct kvm_vcpu *vcpu, gpa_t gpa,
+                         void *val, int bytes)
+{
        trace_kvm_mmio(KVM_TRACE_MMIO_READ_UNSATISFIED, bytes, gpa, 0);
-
-       vcpu->mmio_needed = 1;
-       vcpu->run->exit_reason = KVM_EXIT_MMIO;
-       vcpu->run->mmio.phys_addr = vcpu->mmio_phys_addr = gpa;
-       vcpu->mmio_size = bytes;
-       vcpu->run->mmio.len = min(vcpu->mmio_size, 8);
-       vcpu->run->mmio.is_write = vcpu->mmio_is_write = 0;
-       vcpu->mmio_index = 0;
-
        return X86EMUL_IO_NEEDED;
 }
 
-int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
-                       const void *val, int bytes)
+static int write_exit_mmio(struct kvm_vcpu *vcpu, gpa_t gpa,
+                          void *val, int bytes)
 {
-       int ret;
-
-       ret = kvm_write_guest(vcpu->kvm, gpa, val, bytes);
-       if (ret < 0)
-               return 0;
-       kvm_mmu_pte_write(vcpu, gpa, val, bytes, 1);
-       return 1;
+       memcpy(vcpu->mmio_data, val, bytes);
+       memcpy(vcpu->run->mmio.data, vcpu->mmio_data, 8);
+       return X86EMUL_CONTINUE;
 }
 
-static int emulator_write_emulated_onepage(unsigned long addr,
-                                          const void *val,
-                                          unsigned int bytes,
-                                          struct x86_exception *exception,
-                                          struct kvm_vcpu *vcpu)
+static struct read_write_emulator_ops read_emultor = {
+       .read_write_prepare = read_prepare,
+       .read_write_emulate = read_emulate,
+       .read_write_mmio = vcpu_mmio_read,
+       .read_write_exit_mmio = read_exit_mmio,
+};
+
+static struct read_write_emulator_ops write_emultor = {
+       .read_write_emulate = write_emulate,
+       .read_write_mmio = write_mmio,
+       .read_write_exit_mmio = write_exit_mmio,
+       .write = true,
+};
+
+static int emulator_read_write_onepage(unsigned long addr, void *val,
+                                      unsigned int bytes,
+                                      struct x86_exception *exception,
+                                      struct kvm_vcpu *vcpu,
+                                      struct read_write_emulator_ops *ops)
 {
        gpa_t gpa;
        int handled, ret;
+       bool write = ops->write;
 
-       ret = vcpu_mmio_gva_to_gpa(vcpu, addr, &gpa, exception, true);
+       if (ops->read_write_prepare &&
+                 ops->read_write_prepare(vcpu, val, bytes))
+               return X86EMUL_CONTINUE;
+
+       ret = vcpu_mmio_gva_to_gpa(vcpu, addr, &gpa, exception, write);
 
        if (ret < 0)
                return X86EMUL_PROPAGATE_FAULT;
@@ -4131,15 +4187,14 @@ static int emulator_write_emulated_onepage(unsigned long addr,
        if (ret)
                goto mmio;
 
-       if (emulator_write_phys(vcpu, gpa, val, bytes))
+       if (ops->read_write_emulate(vcpu, gpa, val, bytes))
                return X86EMUL_CONTINUE;
 
 mmio:
-       trace_kvm_mmio(KVM_TRACE_MMIO_WRITE, bytes, gpa, *(u64 *)val);
        /*
         * Is this MMIO handled locally?
         */
-       handled = vcpu_mmio_write(vcpu, gpa, bytes, val);
+       handled = ops->read_write_mmio(vcpu, gpa, bytes, val);
        if (handled == bytes)
                return X86EMUL_CONTINUE;
 
@@ -4148,23 +4203,20 @@ mmio:
        val += handled;
 
        vcpu->mmio_needed = 1;
-       memcpy(vcpu->mmio_data, val, bytes);
        vcpu->run->exit_reason = KVM_EXIT_MMIO;
        vcpu->run->mmio.phys_addr = vcpu->mmio_phys_addr = gpa;
        vcpu->mmio_size = bytes;
        vcpu->run->mmio.len = min(vcpu->mmio_size, 8);
-       vcpu->run->mmio.is_write = vcpu->mmio_is_write = 1;
-       memcpy(vcpu->run->mmio.data, vcpu->mmio_data, 8);
+       vcpu->run->mmio.is_write = vcpu->mmio_is_write = write;
        vcpu->mmio_index = 0;
 
-       return X86EMUL_CONTINUE;
+       return ops->read_write_exit_mmio(vcpu, gpa, val, bytes);
 }
 
-int emulator_write_emulated(struct x86_emulate_ctxt *ctxt,
-                           unsigned long addr,
-                           const void *val,
-                           unsigned int bytes,
-                           struct x86_exception *exception)
+int emulator_read_write(struct x86_emulate_ctxt *ctxt, unsigned long addr,
+                       void *val, unsigned int bytes,
+                       struct x86_exception *exception,
+                       struct read_write_emulator_ops *ops)
 {
        struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
 
@@ -4173,16 +4225,38 @@ int emulator_write_emulated(struct x86_emulate_ctxt *ctxt,
                int rc, now;
 
                now = -addr & ~PAGE_MASK;
-               rc = emulator_write_emulated_onepage(addr, val, now, exception,
-                                                    vcpu);
+               rc = emulator_read_write_onepage(addr, val, now, exception,
+                                                vcpu, ops);
+
                if (rc != X86EMUL_CONTINUE)
                        return rc;
                addr += now;
                val += now;
                bytes -= now;
        }
-       return emulator_write_emulated_onepage(addr, val, bytes, exception,
-                                              vcpu);
+
+       return emulator_read_write_onepage(addr, val, bytes, exception,
+                                          vcpu, ops);
+}
+
+static int emulator_read_emulated(struct x86_emulate_ctxt *ctxt,
+                                 unsigned long addr,
+                                 void *val,
+                                 unsigned int bytes,
+                                 struct x86_exception *exception)
+{
+       return emulator_read_write(ctxt, addr, val, bytes,
+                                  exception, &read_emultor);
+}
+
+int emulator_write_emulated(struct x86_emulate_ctxt *ctxt,
+                           unsigned long addr,
+                           const void *val,
+                           unsigned int bytes,
+                           struct x86_exception *exception)
+{
+       return emulator_read_write(ctxt, addr, (void *)val, bytes,
+                                  exception, &write_emultor);
 }
 
 #define CMPXCHG_TYPE(t, ptr, old, new) \
@@ -4712,7 +4786,7 @@ int kvm_inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq, int inc_eip)
        kvm_set_rflags(vcpu, ctxt->eflags);
 
        if (irq == NMI_VECTOR)
-               vcpu->arch.nmi_pending = false;
+               vcpu->arch.nmi_pending = 0;
        else
                vcpu->arch.interrupt.pending = false;
 
@@ -4788,7 +4862,7 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu,
 
                trace_kvm_emulate_insn_start(vcpu);
                ++vcpu->stat.insn_emulation;
-               if (r)  {
+               if (r != EMULATION_OK)  {
                        if (emulation_type & EMULTYPE_TRAP_UD)
                                return EMULATE_FAIL;
                        if (reexecute_instruction(vcpu, cr2))
@@ -5521,7 +5595,7 @@ static void inject_pending_event(struct kvm_vcpu *vcpu)
        /* try to inject new event if pending */
        if (vcpu->arch.nmi_pending) {
                if (kvm_x86_ops->nmi_allowed(vcpu)) {
-                       vcpu->arch.nmi_pending = false;
+                       --vcpu->arch.nmi_pending;
                        vcpu->arch.nmi_injected = true;
                        kvm_x86_ops->set_nmi(vcpu);
                }
@@ -5553,10 +5627,26 @@ static void kvm_put_guest_xcr0(struct kvm_vcpu *vcpu)
        }
 }
 
+static void process_nmi(struct kvm_vcpu *vcpu)
+{
+       unsigned limit = 2;
+
+       /*
+        * x86 is limited to one NMI running, and one NMI pending after it.
+        * If an NMI is already in progress, limit further NMIs to just one.
+        * Otherwise, allow two (and we'll inject the first one immediately).
+        */
+       if (kvm_x86_ops->get_nmi_mask(vcpu) || vcpu->arch.nmi_injected)
+               limit = 1;
+
+       vcpu->arch.nmi_pending += atomic_xchg(&vcpu->arch.nmi_queued, 0);
+       vcpu->arch.nmi_pending = min(vcpu->arch.nmi_pending, limit);
+       kvm_make_request(KVM_REQ_EVENT, vcpu);
+}
+
 static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
 {
        int r;
-       bool nmi_pending;
        bool req_int_win = !irqchip_in_kernel(vcpu->kvm) &&
                vcpu->run->request_interrupt_window;
 
@@ -5596,6 +5686,8 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
                }
                if (kvm_check_request(KVM_REQ_STEAL_UPDATE, vcpu))
                        record_steal_time(vcpu);
+               if (kvm_check_request(KVM_REQ_NMI, vcpu))
+                       process_nmi(vcpu);
 
        }
 
@@ -5603,19 +5695,11 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
        if (unlikely(r))
                goto out;
 
-       /*
-        * An NMI can be injected between local nmi_pending read and
-        * vcpu->arch.nmi_pending read inside inject_pending_event().
-        * But in that case, KVM_REQ_EVENT will be set, which makes
-        * the race described above benign.
-        */
-       nmi_pending = ACCESS_ONCE(vcpu->arch.nmi_pending);
-
        if (kvm_check_request(KVM_REQ_EVENT, vcpu) || req_int_win) {
                inject_pending_event(vcpu);
 
                /* enable NMI/IRQ window open exits if needed */
-               if (nmi_pending)
+               if (vcpu->arch.nmi_pending)
                        kvm_x86_ops->enable_nmi_window(vcpu);
                else if (kvm_cpu_has_interrupt(vcpu) || req_int_win)
                        kvm_x86_ops->enable_irq_window(vcpu);
@@ -5678,7 +5762,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
        if (hw_breakpoint_active())
                hw_breakpoint_restore();
 
-       kvm_get_msr(vcpu, MSR_IA32_TSC, &vcpu->arch.last_guest_tsc);
+       vcpu->arch.last_guest_tsc = kvm_x86_ops->read_l1_tsc(vcpu);
 
        vcpu->mode = OUTSIDE_GUEST_MODE;
        smp_wmb();
@@ -6323,7 +6407,8 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
 
 int kvm_arch_vcpu_reset(struct kvm_vcpu *vcpu)
 {
-       vcpu->arch.nmi_pending = false;
+       atomic_set(&vcpu->arch.nmi_queued, 0);
+       vcpu->arch.nmi_pending = 0;
        vcpu->arch.nmi_injected = false;
 
        vcpu->arch.switch_db_regs = 0;
@@ -6598,7 +6683,7 @@ int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu)
                !vcpu->arch.apf.halted)
                || !list_empty_careful(&vcpu->async_pf.done)
                || vcpu->arch.mp_state == KVM_MP_STATE_SIPI_RECEIVED
-               || vcpu->arch.nmi_pending ||
+               || atomic_read(&vcpu->arch.nmi_queued) ||
                (kvm_arch_interrupt_allowed(vcpu) &&
                 kvm_cpu_has_interrupt(vcpu));
 }
index 13ee258442ae2b58cb195374c02c1a213f8333ee..f63da5ef217c40deb6af93e0924246fc68f94008 100644 (file)
@@ -70,6 +70,7 @@
 #include <asm/i387.h>
 #include <asm/stackprotector.h>
 #include <asm/reboot.h>                /* for struct machine_ops */
+#include <asm/kvm_para.h>
 
 /*G:010
  * Welcome to the Guest!
@@ -455,6 +456,15 @@ static void lguest_cpuid(unsigned int *ax, unsigned int *bx,
                *ax &= 0xFFFFF0FF;
                *ax |= 0x00000500;
                break;
+
+       /*
+        * This is used to detect if we're running under KVM.  We might be,
+        * but that's a Host matter, not us.  So say we're not.
+        */
+       case KVM_CPUID_SIGNATURE:
+               *bx = *cx = *dx = 0;
+               break;
+
        /*
         * 0x80000000 returns the highest Extended Function, so we futureproof
         * like we do above by limiting it to known fields.
index 99176094500b02aab75b8f8ba591ac50220b1186..41bd2a2d2c50f61a4948f954f296631c8dfd7961 100644 (file)
@@ -304,7 +304,7 @@ static int ce4100_conf_write(unsigned int seg, unsigned int bus,
        return pci_direct_conf1.write(seg, bus, devfn, reg, len, value);
 }
 
-struct pci_raw_ops ce4100_pci_conf = {
+static const struct pci_raw_ops ce4100_pci_conf = {
        .read = ce4100_conf_read,
        .write = ce4100_conf_write,
 };
index 92df322e0b571a09c49aa236e7dae3118fe353cb..7962ccb4d9b26aeb3354d2ab1814d9d04a69d695 100644 (file)
@@ -33,8 +33,8 @@ int noioapicreroute = 1;
 int pcibios_last_bus = -1;
 unsigned long pirq_table_addr;
 struct pci_bus *pci_root_bus;
-struct pci_raw_ops *raw_pci_ops;
-struct pci_raw_ops *raw_pci_ext_ops;
+const struct pci_raw_ops *__read_mostly raw_pci_ops;
+const struct pci_raw_ops *__read_mostly raw_pci_ext_ops;
 
 int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
                                                int reg, int len, u32 *val)
index 4f2c70439d7fbb352993c4b8b9f3a76d39dfc438..15460590b8c551c023e7cd0eb1df768cdb572d45 100644 (file)
@@ -79,7 +79,7 @@ static int pci_conf1_write(unsigned int seg, unsigned int bus,
 
 #undef PCI_CONF1_ADDRESS
 
-struct pci_raw_ops pci_direct_conf1 = {
+const struct pci_raw_ops pci_direct_conf1 = {
        .read =         pci_conf1_read,
        .write =        pci_conf1_write,
 };
@@ -175,7 +175,7 @@ static int pci_conf2_write(unsigned int seg, unsigned int bus,
 
 #undef PCI_CONF2_ADDRESS
 
-struct pci_raw_ops pci_direct_conf2 = {
+static const struct pci_raw_ops pci_direct_conf2 = {
        .read =         pci_conf2_read,
        .write =        pci_conf2_write,
 };
@@ -191,7 +191,7 @@ struct pci_raw_ops pci_direct_conf2 = {
  * This should be close to trivial, but it isn't, because there are buggy
  * chipsets (yes, you guessed it, by Intel and Compaq) that have no class ID.
  */
-static int __init pci_sanity_check(struct pci_raw_ops *o)
+static int __init pci_sanity_check(const struct pci_raw_ops *o)
 {
        u32 x = 0;
        int year, devfn;
index a3d9c54792aef245843eef8da9a7025d7179cd85..5372e86834c03dbda433db01811c9a6be072622f 100644 (file)
@@ -117,7 +117,7 @@ static int pci_mmcfg_write(unsigned int seg, unsigned int bus,
        return 0;
 }
 
-static struct pci_raw_ops pci_mmcfg = {
+static const struct pci_raw_ops pci_mmcfg = {
        .read =         pci_mmcfg_read,
        .write =        pci_mmcfg_write,
 };
index e783841bd1d7c42ea8ca4607d884ffe1e65ba97f..915a493502cbb44410ed26dd9f24cbd9422bfe4d 100644 (file)
@@ -81,7 +81,7 @@ static int pci_mmcfg_write(unsigned int seg, unsigned int bus,
        return 0;
 }
 
-static struct pci_raw_ops pci_mmcfg = {
+static const struct pci_raw_ops pci_mmcfg = {
        .read =         pci_mmcfg_read,
        .write =        pci_mmcfg_write,
 };
index 512a88c4150139027709645e797746f0555c5fb7..51abf02f9226687c234945e1ff39fb9a8c13695b 100644 (file)
@@ -110,7 +110,7 @@ static int pci_conf1_mq_write(unsigned int seg, unsigned int bus,
 
 #undef PCI_CONF1_MQ_ADDRESS
 
-static struct pci_raw_ops pci_direct_conf1_mq = {
+static const struct pci_raw_ops pci_direct_conf1_mq = {
        .read   = pci_conf1_mq_read,
        .write  = pci_conf1_mq_write
 };
index 5262603b04d9d0b849df61ab98890705c1bed155..7043a4f0e98ab258c06116e675bac65d19080a7e 100644 (file)
@@ -301,7 +301,7 @@ static int pci_olpc_write(unsigned int seg, unsigned int bus,
        return 0;
 }
 
-static struct pci_raw_ops pci_olpc_conf = {
+static const struct pci_raw_ops pci_olpc_conf = {
        .read = pci_olpc_read,
        .write = pci_olpc_write,
 };
index f68553551467a0cbe6dd11a2cba04c6afaff5172..db0e9a51e611dcaeb66b8b7b961312ac2f0795c1 100644 (file)
@@ -303,7 +303,7 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
  * Function table for BIOS32 access
  */
 
-static struct pci_raw_ops pci_bios_access = {
+static const struct pci_raw_ops pci_bios_access = {
        .read =         pci_bios_read,
        .write =        pci_bios_write
 };
@@ -312,7 +312,7 @@ static struct pci_raw_ops pci_bios_access = {
  * Try to find PCI BIOS.
  */
 
-static struct pci_raw_ops * __devinit pci_find_bios(void)
+static const struct pci_raw_ops * __devinit pci_find_bios(void)
 {
        union bios32 *check;
        unsigned char sum;
index e2f67902dd024ed2f07abdfc190c73558d2ddb7b..94855a9717de2237b1eeb72449c32ef12d4a5fef 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/mutex.h>
 #include <linux/idr.h>
 #include <linux/log2.h>
+#include <linux/ctype.h>
 
 #include "blk.h"
 
@@ -909,6 +910,74 @@ static int __init genhd_device_init(void)
 
 subsys_initcall(genhd_device_init);
 
+static ssize_t alias_show(struct device *dev,
+                              struct device_attribute *attr, char *buf)
+{
+       struct gendisk *disk = dev_to_disk(dev);
+       ssize_t ret = 0;
+
+       if (disk->alias)
+               ret = snprintf(buf, ALIAS_LEN, "%s\n", disk->alias);
+       return ret;
+}
+
+static ssize_t alias_store(struct device *dev, struct device_attribute *attr,
+                          const char *buf, size_t count)
+{
+       struct gendisk *disk = dev_to_disk(dev);
+       char *alias;
+       char *envp[] = { NULL, NULL };
+       unsigned char c;
+       int i;
+       ssize_t ret = count;
+
+       if (!count)
+               return -EINVAL;
+
+       if (count >= ALIAS_LEN) {
+               printk(KERN_ERR "alias: alias is too long\n");
+               return -EINVAL;
+       }
+
+       /* Validation check */
+       for (i = 0; i < count; i++) {
+               c = buf[i];
+               if (i == count - 1 && c == '\n')
+                       break;
+               if (!isalnum(c) && c != '_' && c != '-') {
+                       printk(KERN_ERR "alias: invalid alias\n");
+                       return -EINVAL;
+               }
+       }
+
+       if (disk->alias) {
+               printk(KERN_INFO "alias: %s is already assigned (%s)\n",
+                      disk->disk_name, disk->alias);
+               return -EINVAL;
+       }
+
+       alias = kasprintf(GFP_KERNEL, "%s", buf);
+       if (!alias)
+               return -ENOMEM;
+
+       if (alias[count - 1] == '\n')
+               alias[count - 1] = '\0';
+
+       envp[0] = kasprintf(GFP_KERNEL, "ALIAS=%s", alias);
+       if (!envp[0]) {
+               kfree(alias);
+               return -ENOMEM;
+       }
+
+       disk->alias = alias;
+       printk(KERN_INFO "alias: assigned %s to %s\n", alias, disk->disk_name);
+
+       kobject_uevent_env(&dev->kobj, KOBJ_ADD, envp);
+
+       kfree(envp[0]);
+       return ret;
+}
+
 static ssize_t disk_range_show(struct device *dev,
                               struct device_attribute *attr, char *buf)
 {
@@ -968,6 +1037,7 @@ static ssize_t disk_discard_alignment_show(struct device *dev,
        return sprintf(buf, "%d\n", queue_discard_alignment(disk->queue));
 }
 
+static DEVICE_ATTR(alias, S_IRUGO|S_IWUSR, alias_show, alias_store);
 static DEVICE_ATTR(range, S_IRUGO, disk_range_show, NULL);
 static DEVICE_ATTR(ext_range, S_IRUGO, disk_ext_range_show, NULL);
 static DEVICE_ATTR(removable, S_IRUGO, disk_removable_show, NULL);
@@ -990,6 +1060,7 @@ static struct device_attribute dev_attr_fail_timeout =
 #endif
 
 static struct attribute *disk_attrs[] = {
+       &dev_attr_alias.attr,
        &dev_attr_range.attr,
        &dev_attr_ext_range.attr,
        &dev_attr_removable.attr,
index ae27b7534ea7d14ee0c5f493e3eaf6e8f123eaa2..527a857d10b61a4bd4d23d243cf43e2551d4faed 100644 (file)
@@ -100,6 +100,14 @@ config CRYPTO_MANAGER2
        select CRYPTO_BLKCIPHER2
        select CRYPTO_PCOMP2
 
+config CRYPTO_USER
+       tristate "Userspace cryptographic algorithm configuration"
+       depends on NET
+       select CRYPTO_MANAGER
+       help
+         Userapace configuration for cryptographic instantiations such as
+         cbc(aes).
+
 config CRYPTO_MANAGER_DISABLE_TESTS
        bool "Disable run-time self tests"
        default y
@@ -407,6 +415,16 @@ config CRYPTO_SHA1
        help
          SHA-1 secure hash standard (FIPS 180-1/DFIPS 180-2).
 
+config CRYPTO_SHA1_SSSE3
+       tristate "SHA1 digest algorithm (SSSE3/AVX)"
+       depends on X86 && 64BIT
+       select CRYPTO_SHA1
+       select CRYPTO_HASH
+       help
+         SHA-1 secure hash standard (FIPS 180-1/DFIPS 180-2) implemented
+         using Supplemental SSE3 (SSSE3) instructions or Advanced Vector
+         Extensions (AVX), when available.
+
 config CRYPTO_SHA256
        tristate "SHA224 and SHA256 digest algorithm"
        select CRYPTO_HASH
@@ -590,6 +608,7 @@ config CRYPTO_ARC4
 config CRYPTO_BLOWFISH
        tristate "Blowfish cipher algorithm"
        select CRYPTO_ALGAPI
+       select CRYPTO_BLOWFISH_COMMON
        help
          Blowfish cipher algorithm, by Bruce Schneier.
 
@@ -600,6 +619,30 @@ config CRYPTO_BLOWFISH
          See also:
          <http://www.schneier.com/blowfish.html>
 
+config CRYPTO_BLOWFISH_COMMON
+       tristate
+       help
+         Common parts of the Blowfish cipher algorithm shared by the
+         generic c and the assembler implementations.
+
+         See also:
+         <http://www.schneier.com/blowfish.html>
+
+config CRYPTO_BLOWFISH_X86_64
+       tristate "Blowfish cipher algorithm (x86_64)"
+       depends on (X86 || UML_X86) && 64BIT
+       select CRYPTO_ALGAPI
+       select CRYPTO_BLOWFISH_COMMON
+       help
+         Blowfish cipher algorithm (x86_64), by Bruce Schneier.
+
+         This is a variable key length cipher which can use keys from 32
+         bits to 448 bits in length.  It's fast, simple and specifically
+         designed for use on "large microprocessors".
+
+         See also:
+         <http://www.schneier.com/blowfish.html>
+
 config CRYPTO_CAMELLIA
        tristate "Camellia cipher algorithms"
        depends on CRYPTO
@@ -793,6 +836,26 @@ config CRYPTO_TWOFISH_X86_64
          See also:
          <http://www.schneier.com/twofish.html>
 
+config CRYPTO_TWOFISH_X86_64_3WAY
+       tristate "Twofish cipher algorithm (x86_64, 3-way parallel)"
+       depends on (X86 || UML_X86) && 64BIT
+       select CRYPTO_ALGAPI
+       select CRYPTO_TWOFISH_COMMON
+       select CRYPTO_TWOFISH_X86_64
+       help
+         Twofish cipher algorithm (x86_64, 3-way parallel).
+
+         Twofish was submitted as an AES (Advanced Encryption Standard)
+         candidate cipher by researchers at CounterPane Systems.  It is a
+         16 round block cipher supporting key sizes of 128, 192, and 256
+         bits.
+
+         This module provides Twofish cipher algorithm that processes three
+         blocks parallel, utilizing resources of out-of-order CPUs better.
+
+         See also:
+         <http://www.schneier.com/twofish.html>
+
 comment "Compression"
 
 config CRYPTO_DEFLATE
index ce5a813d36398254b0b213add68c0e34dbf59efa..9e6eee2c05db0735363915db0742e01ff2dabf5f 100644 (file)
@@ -31,6 +31,7 @@ obj-$(CONFIG_CRYPTO_PCOMP2) += pcompress.o
 cryptomgr-y := algboss.o testmgr.o
 
 obj-$(CONFIG_CRYPTO_MANAGER2) += cryptomgr.o
+obj-$(CONFIG_CRYPTO_USER) += crypto_user.o
 obj-$(CONFIG_CRYPTO_HMAC) += hmac.o
 obj-$(CONFIG_CRYPTO_VMAC) += vmac.o
 obj-$(CONFIG_CRYPTO_XCBC) += xcbc.o
@@ -60,7 +61,8 @@ obj-$(CONFIG_CRYPTO_PCRYPT) += pcrypt.o
 obj-$(CONFIG_CRYPTO_CRYPTD) += cryptd.o
 obj-$(CONFIG_CRYPTO_DES) += des_generic.o
 obj-$(CONFIG_CRYPTO_FCRYPT) += fcrypt.o
-obj-$(CONFIG_CRYPTO_BLOWFISH) += blowfish.o
+obj-$(CONFIG_CRYPTO_BLOWFISH) += blowfish_generic.o
+obj-$(CONFIG_CRYPTO_BLOWFISH_COMMON) += blowfish_common.o
 obj-$(CONFIG_CRYPTO_TWOFISH) += twofish_generic.o
 obj-$(CONFIG_CRYPTO_TWOFISH_COMMON) += twofish_common.o
 obj-$(CONFIG_CRYPTO_SERPENT) += serpent.o
index fdc67d38660bc08269697c50b3424fc85059e1e8..a816f24f2d527993aea1fb724680857e77a06ff2 100644 (file)
@@ -23,6 +23,8 @@
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/seq_file.h>
+#include <linux/cryptouser.h>
+#include <net/netlink.h>
 
 #include <crypto/scatterwalk.h>
 
@@ -381,6 +383,28 @@ static int crypto_init_ablkcipher_ops(struct crypto_tfm *tfm, u32 type,
        return 0;
 }
 
+static int crypto_ablkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
+{
+       struct crypto_report_blkcipher rblkcipher;
+
+       snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "ablkcipher");
+       snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
+                alg->cra_ablkcipher.geniv ?: "<default>");
+
+       rblkcipher.blocksize = alg->cra_blocksize;
+       rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize;
+       rblkcipher.max_keysize = alg->cra_ablkcipher.max_keysize;
+       rblkcipher.ivsize = alg->cra_ablkcipher.ivsize;
+
+       NLA_PUT(skb, CRYPTOCFGA_REPORT_BLKCIPHER,
+               sizeof(struct crypto_report_blkcipher), &rblkcipher);
+
+       return 0;
+
+nla_put_failure:
+       return -EMSGSIZE;
+}
+
 static void crypto_ablkcipher_show(struct seq_file *m, struct crypto_alg *alg)
        __attribute__ ((unused));
 static void crypto_ablkcipher_show(struct seq_file *m, struct crypto_alg *alg)
@@ -403,6 +427,7 @@ const struct crypto_type crypto_ablkcipher_type = {
 #ifdef CONFIG_PROC_FS
        .show = crypto_ablkcipher_show,
 #endif
+       .report = crypto_ablkcipher_report,
 };
 EXPORT_SYMBOL_GPL(crypto_ablkcipher_type);
 
@@ -432,6 +457,28 @@ static int crypto_init_givcipher_ops(struct crypto_tfm *tfm, u32 type,
        return 0;
 }
 
+static int crypto_givcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
+{
+       struct crypto_report_blkcipher rblkcipher;
+
+       snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "givcipher");
+       snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
+                alg->cra_ablkcipher.geniv ?: "<built-in>");
+
+       rblkcipher.blocksize = alg->cra_blocksize;
+       rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize;
+       rblkcipher.max_keysize = alg->cra_ablkcipher.max_keysize;
+       rblkcipher.ivsize = alg->cra_ablkcipher.ivsize;
+
+       NLA_PUT(skb, CRYPTOCFGA_REPORT_BLKCIPHER,
+               sizeof(struct crypto_report_blkcipher), &rblkcipher);
+
+       return 0;
+
+nla_put_failure:
+       return -EMSGSIZE;
+}
+
 static void crypto_givcipher_show(struct seq_file *m, struct crypto_alg *alg)
        __attribute__ ((unused));
 static void crypto_givcipher_show(struct seq_file *m, struct crypto_alg *alg)
@@ -454,6 +501,7 @@ const struct crypto_type crypto_givcipher_type = {
 #ifdef CONFIG_PROC_FS
        .show = crypto_givcipher_show,
 #endif
+       .report = crypto_givcipher_report,
 };
 EXPORT_SYMBOL_GPL(crypto_givcipher_type);
 
index 6729e8ff68e7346762734538cecda2b8f9909b6d..701556ffaaef0e6ca21256b52a8b594904852f9e 100644 (file)
@@ -21,6 +21,8 @@
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/seq_file.h>
+#include <linux/cryptouser.h>
+#include <net/netlink.h>
 
 #include "internal.h"
 
@@ -109,6 +111,28 @@ static int crypto_init_aead_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
        return 0;
 }
 
+static int crypto_aead_report(struct sk_buff *skb, struct crypto_alg *alg)
+{
+       struct crypto_report_aead raead;
+       struct aead_alg *aead = &alg->cra_aead;
+
+       snprintf(raead.type, CRYPTO_MAX_ALG_NAME, "%s", "aead");
+       snprintf(raead.geniv, CRYPTO_MAX_ALG_NAME, "%s",
+                aead->geniv ?: "<built-in>");
+
+       raead.blocksize = alg->cra_blocksize;
+       raead.maxauthsize = aead->maxauthsize;
+       raead.ivsize = aead->ivsize;
+
+       NLA_PUT(skb, CRYPTOCFGA_REPORT_AEAD,
+               sizeof(struct crypto_report_aead), &raead);
+
+       return 0;
+
+nla_put_failure:
+       return -EMSGSIZE;
+}
+
 static void crypto_aead_show(struct seq_file *m, struct crypto_alg *alg)
        __attribute__ ((unused));
 static void crypto_aead_show(struct seq_file *m, struct crypto_alg *alg)
@@ -130,6 +154,7 @@ const struct crypto_type crypto_aead_type = {
 #ifdef CONFIG_PROC_FS
        .show = crypto_aead_show,
 #endif
+       .report = crypto_aead_report,
 };
 EXPORT_SYMBOL_GPL(crypto_aead_type);
 
@@ -165,6 +190,28 @@ static int crypto_init_nivaead_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
        return 0;
 }
 
+static int crypto_nivaead_report(struct sk_buff *skb, struct crypto_alg *alg)
+{
+       struct crypto_report_aead raead;
+       struct aead_alg *aead = &alg->cra_aead;
+
+       snprintf(raead.type, CRYPTO_MAX_ALG_NAME, "%s", "nivaead");
+       snprintf(raead.geniv, CRYPTO_MAX_ALG_NAME, "%s", aead->geniv);
+
+       raead.blocksize = alg->cra_blocksize;
+       raead.maxauthsize = aead->maxauthsize;
+       raead.ivsize = aead->ivsize;
+
+       NLA_PUT(skb, CRYPTOCFGA_REPORT_AEAD,
+               sizeof(struct crypto_report_aead), &raead);
+
+       return 0;
+
+nla_put_failure:
+       return -EMSGSIZE;
+}
+
+
 static void crypto_nivaead_show(struct seq_file *m, struct crypto_alg *alg)
        __attribute__ ((unused));
 static void crypto_nivaead_show(struct seq_file *m, struct crypto_alg *alg)
@@ -186,6 +233,7 @@ const struct crypto_type crypto_nivaead_type = {
 #ifdef CONFIG_PROC_FS
        .show = crypto_nivaead_show,
 #endif
+       .report = crypto_nivaead_report,
 };
 EXPORT_SYMBOL_GPL(crypto_nivaead_type);
 
index f669822a7a443c81a04c8fb61d8d382a64546542..a3e6ef99394a9e78c7408ea4db65caa652004a1d 100644 (file)
@@ -21,6 +21,8 @@
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/seq_file.h>
+#include <linux/cryptouser.h>
+#include <net/netlink.h>
 
 #include "internal.h"
 
@@ -397,6 +399,24 @@ static unsigned int crypto_ahash_extsize(struct crypto_alg *alg)
        return sizeof(struct crypto_shash *);
 }
 
+static int crypto_ahash_report(struct sk_buff *skb, struct crypto_alg *alg)
+{
+       struct crypto_report_hash rhash;
+
+       snprintf(rhash.type, CRYPTO_MAX_ALG_NAME, "%s", "ahash");
+
+       rhash.blocksize = alg->cra_blocksize;
+       rhash.digestsize = __crypto_hash_alg_common(alg)->digestsize;
+
+       NLA_PUT(skb, CRYPTOCFGA_REPORT_HASH,
+               sizeof(struct crypto_report_hash), &rhash);
+
+       return 0;
+
+nla_put_failure:
+       return -EMSGSIZE;
+}
+
 static void crypto_ahash_show(struct seq_file *m, struct crypto_alg *alg)
        __attribute__ ((unused));
 static void crypto_ahash_show(struct seq_file *m, struct crypto_alg *alg)
@@ -415,6 +435,7 @@ const struct crypto_type crypto_ahash_type = {
 #ifdef CONFIG_PROC_FS
        .show = crypto_ahash_show,
 #endif
+       .report = crypto_ahash_report,
        .maskclear = ~CRYPTO_ALG_TYPE_MASK,
        .maskset = CRYPTO_ALG_TYPE_AHASH_MASK,
        .type = CRYPTO_ALG_TYPE_AHASH,
index c3cf1a69a47a8dcaa57e62410c9823ee4e2d045b..54dd4e33b5d61a5049713ee74ad9dc94d40670b6 100644 (file)
@@ -22,8 +22,6 @@
 
 #include "internal.h"
 
-static void crypto_remove_final(struct list_head *list);
-
 static LIST_HEAD(crypto_template_list);
 
 void crypto_larval_error(const char *name, u32 type, u32 mask)
@@ -129,9 +127,8 @@ static void crypto_remove_spawn(struct crypto_spawn *spawn,
        BUG_ON(!list_empty(&inst->alg.cra_users));
 }
 
-static void crypto_remove_spawns(struct crypto_alg *alg,
-                                struct list_head *list,
-                                struct crypto_alg *nalg)
+void crypto_remove_spawns(struct crypto_alg *alg, struct list_head *list,
+                         struct crypto_alg *nalg)
 {
        u32 new_type = (nalg ?: alg)->cra_flags;
        struct crypto_spawn *spawn, *n;
@@ -177,6 +174,7 @@ static void crypto_remove_spawns(struct crypto_alg *alg,
                        crypto_remove_spawn(spawn, list);
        }
 }
+EXPORT_SYMBOL_GPL(crypto_remove_spawns);
 
 static struct crypto_larval *__crypto_register_alg(struct crypto_alg *alg)
 {
@@ -321,7 +319,7 @@ unlock:
 }
 EXPORT_SYMBOL_GPL(crypto_alg_tested);
 
-static void crypto_remove_final(struct list_head *list)
+void crypto_remove_final(struct list_head *list)
 {
        struct crypto_alg *alg;
        struct crypto_alg *n;
@@ -331,6 +329,7 @@ static void crypto_remove_final(struct list_head *list)
                crypto_alg_put(alg);
        }
 }
+EXPORT_SYMBOL_GPL(crypto_remove_final);
 
 static void crypto_wait_for_test(struct crypto_larval *larval)
 {
@@ -493,6 +492,7 @@ int crypto_register_instance(struct crypto_template *tmpl,
                goto err;
 
        inst->alg.cra_module = tmpl->module;
+       inst->alg.cra_flags |= CRYPTO_ALG_INSTANCE;
 
        down_write(&crypto_alg_sem);
 
index 7a7219266e3cc343d1a9a63a492a9cd38e876db5..2572d26001364b6206b300ecbc42ca18dfca9182 100644 (file)
@@ -24,6 +24,8 @@
 #include <linux/seq_file.h>
 #include <linux/slab.h>
 #include <linux/string.h>
+#include <linux/cryptouser.h>
+#include <net/netlink.h>
 
 #include "internal.h"
 
@@ -492,6 +494,28 @@ static int crypto_init_blkcipher_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
                return crypto_init_blkcipher_ops_async(tfm);
 }
 
+static int crypto_blkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
+{
+       struct crypto_report_blkcipher rblkcipher;
+
+       snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "blkcipher");
+       snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
+                alg->cra_blkcipher.geniv ?: "<default>");
+
+       rblkcipher.blocksize = alg->cra_blocksize;
+       rblkcipher.min_keysize = alg->cra_blkcipher.min_keysize;
+       rblkcipher.max_keysize = alg->cra_blkcipher.max_keysize;
+       rblkcipher.ivsize = alg->cra_blkcipher.ivsize;
+
+       NLA_PUT(skb, CRYPTOCFGA_REPORT_BLKCIPHER,
+               sizeof(struct crypto_report_blkcipher), &rblkcipher);
+
+       return 0;
+
+nla_put_failure:
+       return -EMSGSIZE;
+}
+
 static void crypto_blkcipher_show(struct seq_file *m, struct crypto_alg *alg)
        __attribute__ ((unused));
 static void crypto_blkcipher_show(struct seq_file *m, struct crypto_alg *alg)
@@ -511,6 +535,7 @@ const struct crypto_type crypto_blkcipher_type = {
 #ifdef CONFIG_PROC_FS
        .show = crypto_blkcipher_show,
 #endif
+       .report = crypto_blkcipher_report,
 };
 EXPORT_SYMBOL_GPL(crypto_blkcipher_type);
 
similarity index 87%
rename from crypto/blowfish.c
rename to crypto/blowfish_common.c
index a67d52ee05800cd5ade61ab0b1fc6d3c8c435b0c..f636aab0209fc2ebd28399252fded219a2b3a652 100644 (file)
@@ -1,6 +1,9 @@
 /*
  * Cryptographic API.
  *
+ * Common Blowfish algorithm parts shared between the c and assembler
+ * implementations.
+ *
  * Blowfish Cipher Algorithm, by Bruce Schneier.
  * http://www.counterpane.com/blowfish.html
  *
 #include <asm/byteorder.h>
 #include <linux/crypto.h>
 #include <linux/types.h>
-
-#define BF_BLOCK_SIZE 8
-#define BF_MIN_KEY_SIZE 4
-#define BF_MAX_KEY_SIZE 56
-
-struct bf_ctx {
-       u32 p[18];
-       u32 s[1024];
-};
+#include <crypto/blowfish.h>
 
 static const u32 bf_pbox[16 + 2] = {
        0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
@@ -309,9 +304,9 @@ static const u32 bf_sbox[256 * 4] = {
 #define GET32_0(x) (((x) >> (24)) & (0xff))
 
 #define bf_F(x) (((S[GET32_0(x)] + S[256 + GET32_1(x)]) ^ \
-          S[512 + GET32_2(x)]) + S[768 + GET32_3(x)])
+               S[512 + GET32_2(x)]) + S[768 + GET32_3(x)])
 
-#define ROUND(a, b, n)  b ^= P[n]; a ^= bf_F (b)
+#define ROUND(a, b, n) ({ b ^= P[n]; a ^= bf_F(b); })
 
 /*
  * The blowfish encipher, processes 64-bit blocks.
@@ -348,57 +343,10 @@ static void encrypt_block(struct bf_ctx *bctx, u32 *dst, u32 *src)
        dst[1] = yl;
 }
 
-static void bf_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
-{
-       const __be32 *in_blk = (const __be32 *)src;
-       __be32 *const out_blk = (__be32 *)dst;
-       u32 in32[2], out32[2];
-
-       in32[0] = be32_to_cpu(in_blk[0]);
-       in32[1] = be32_to_cpu(in_blk[1]);
-       encrypt_block(crypto_tfm_ctx(tfm), out32, in32);
-       out_blk[0] = cpu_to_be32(out32[0]);
-       out_blk[1] = cpu_to_be32(out32[1]);
-}
-
-static void bf_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
-{
-       struct bf_ctx *ctx = crypto_tfm_ctx(tfm);
-       const __be32 *in_blk = (const __be32 *)src;
-       __be32 *const out_blk = (__be32 *)dst;
-       const u32 *P = ctx->p;
-       const u32 *S = ctx->s;
-       u32 yl = be32_to_cpu(in_blk[0]);
-       u32 yr = be32_to_cpu(in_blk[1]);
-
-       ROUND(yr, yl, 17);
-       ROUND(yl, yr, 16);
-       ROUND(yr, yl, 15);
-       ROUND(yl, yr, 14);
-       ROUND(yr, yl, 13);
-       ROUND(yl, yr, 12);
-       ROUND(yr, yl, 11);
-       ROUND(yl, yr, 10);
-       ROUND(yr, yl, 9);
-       ROUND(yl, yr, 8);
-       ROUND(yr, yl, 7);
-       ROUND(yl, yr, 6);
-       ROUND(yr, yl, 5);
-       ROUND(yl, yr, 4);
-       ROUND(yr, yl, 3);
-       ROUND(yl, yr, 2);
-
-       yl ^= P[1];
-       yr ^= P[0];
-
-       out_blk[0] = cpu_to_be32(yr);
-       out_blk[1] = cpu_to_be32(yl);
-}
-
 /*
  * Calculates the blowfish S and P boxes for encryption and decryption.
  */
-static int bf_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
+int blowfish_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
 {
        struct bf_ctx *ctx = crypto_tfm_ctx(tfm);
        u32 *P = ctx->p;
@@ -448,35 +396,7 @@ static int bf_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
        /* Bruce says not to bother with the weak key check. */
        return 0;
 }
-
-static struct crypto_alg alg = {
-       .cra_name               =       "blowfish",
-       .cra_flags              =       CRYPTO_ALG_TYPE_CIPHER,
-       .cra_blocksize          =       BF_BLOCK_SIZE,
-       .cra_ctxsize            =       sizeof(struct bf_ctx),
-       .cra_alignmask          =       3,
-       .cra_module             =       THIS_MODULE,
-       .cra_list               =       LIST_HEAD_INIT(alg.cra_list),
-       .cra_u                  =       { .cipher = {
-       .cia_min_keysize        =       BF_MIN_KEY_SIZE,
-       .cia_max_keysize        =       BF_MAX_KEY_SIZE,
-       .cia_setkey             =       bf_setkey,
-       .cia_encrypt            =       bf_encrypt,
-       .cia_decrypt            =       bf_decrypt } }
-};
-
-static int __init blowfish_mod_init(void)
-{
-       return crypto_register_alg(&alg);
-}
-
-static void __exit blowfish_mod_fini(void)
-{
-       crypto_unregister_alg(&alg);
-}
-
-module_init(blowfish_mod_init);
-module_exit(blowfish_mod_fini);
+EXPORT_SYMBOL_GPL(blowfish_setkey);
 
 MODULE_LICENSE("GPL");
-MODULE_DESCRIPTION("Blowfish Cipher Algorithm");
+MODULE_DESCRIPTION("Blowfish Cipher common functions");
diff --git a/crypto/blowfish_generic.c b/crypto/blowfish_generic.c
new file mode 100644 (file)
index 0000000..6f269b5
--- /dev/null
@@ -0,0 +1,142 @@
+/*
+ * Cryptographic API.
+ *
+ * Blowfish Cipher Algorithm, by Bruce Schneier.
+ * http://www.counterpane.com/blowfish.html
+ *
+ * Adapted from Kerneli implementation.
+ *
+ * Copyright (c) Herbert Valerio Riedel <hvr@hvrlab.org>
+ * Copyright (c) Kyle McMartin <kyle@debian.org>
+ * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ */
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/mm.h>
+#include <asm/byteorder.h>
+#include <linux/crypto.h>
+#include <linux/types.h>
+#include <crypto/blowfish.h>
+
+/*
+ * Round loop unrolling macros, S is a pointer to a S-Box array
+ * organized in 4 unsigned longs at a row.
+ */
+#define GET32_3(x) (((x) & 0xff))
+#define GET32_2(x) (((x) >> (8)) & (0xff))
+#define GET32_1(x) (((x) >> (16)) & (0xff))
+#define GET32_0(x) (((x) >> (24)) & (0xff))
+
+#define bf_F(x) (((S[GET32_0(x)] + S[256 + GET32_1(x)]) ^ \
+               S[512 + GET32_2(x)]) + S[768 + GET32_3(x)])
+
+#define ROUND(a, b, n) ({ b ^= P[n]; a ^= bf_F(b); })
+
+static void bf_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+{
+       struct bf_ctx *ctx = crypto_tfm_ctx(tfm);
+       const __be32 *in_blk = (const __be32 *)src;
+       __be32 *const out_blk = (__be32 *)dst;
+       const u32 *P = ctx->p;
+       const u32 *S = ctx->s;
+       u32 yl = be32_to_cpu(in_blk[0]);
+       u32 yr = be32_to_cpu(in_blk[1]);
+
+       ROUND(yr, yl, 0);
+       ROUND(yl, yr, 1);
+       ROUND(yr, yl, 2);
+       ROUND(yl, yr, 3);
+       ROUND(yr, yl, 4);
+       ROUND(yl, yr, 5);
+       ROUND(yr, yl, 6);
+       ROUND(yl, yr, 7);
+       ROUND(yr, yl, 8);
+       ROUND(yl, yr, 9);
+       ROUND(yr, yl, 10);
+       ROUND(yl, yr, 11);
+       ROUND(yr, yl, 12);
+       ROUND(yl, yr, 13);
+       ROUND(yr, yl, 14);
+       ROUND(yl, yr, 15);
+
+       yl ^= P[16];
+       yr ^= P[17];
+
+       out_blk[0] = cpu_to_be32(yr);
+       out_blk[1] = cpu_to_be32(yl);
+}
+
+static void bf_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+{
+       struct bf_ctx *ctx = crypto_tfm_ctx(tfm);
+       const __be32 *in_blk = (const __be32 *)src;
+       __be32 *const out_blk = (__be32 *)dst;
+       const u32 *P = ctx->p;
+       const u32 *S = ctx->s;
+       u32 yl = be32_to_cpu(in_blk[0]);
+       u32 yr = be32_to_cpu(in_blk[1]);
+
+       ROUND(yr, yl, 17);
+       ROUND(yl, yr, 16);
+       ROUND(yr, yl, 15);
+       ROUND(yl, yr, 14);
+       ROUND(yr, yl, 13);
+       ROUND(yl, yr, 12);
+       ROUND(yr, yl, 11);
+       ROUND(yl, yr, 10);
+       ROUND(yr, yl, 9);
+       ROUND(yl, yr, 8);
+       ROUND(yr, yl, 7);
+       ROUND(yl, yr, 6);
+       ROUND(yr, yl, 5);
+       ROUND(yl, yr, 4);
+       ROUND(yr, yl, 3);
+       ROUND(yl, yr, 2);
+
+       yl ^= P[1];
+       yr ^= P[0];
+
+       out_blk[0] = cpu_to_be32(yr);
+       out_blk[1] = cpu_to_be32(yl);
+}
+
+static struct crypto_alg alg = {
+       .cra_name               =       "blowfish",
+       .cra_driver_name        =       "blowfish-generic",
+       .cra_priority           =       100,
+       .cra_flags              =       CRYPTO_ALG_TYPE_CIPHER,
+       .cra_blocksize          =       BF_BLOCK_SIZE,
+       .cra_ctxsize            =       sizeof(struct bf_ctx),
+       .cra_alignmask          =       3,
+       .cra_module             =       THIS_MODULE,
+       .cra_list               =       LIST_HEAD_INIT(alg.cra_list),
+       .cra_u                  =       { .cipher = {
+       .cia_min_keysize        =       BF_MIN_KEY_SIZE,
+       .cia_max_keysize        =       BF_MAX_KEY_SIZE,
+       .cia_setkey             =       blowfish_setkey,
+       .cia_encrypt            =       bf_encrypt,
+       .cia_decrypt            =       bf_decrypt } }
+};
+
+static int __init blowfish_mod_init(void)
+{
+       return crypto_register_alg(&alg);
+}
+
+static void __exit blowfish_mod_fini(void)
+{
+       crypto_unregister_alg(&alg);
+}
+
+module_init(blowfish_mod_init);
+module_exit(blowfish_mod_fini);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Blowfish Cipher Algorithm");
+MODULE_ALIAS("blowfish");
index e46d21ae26bc0538003cf72b42fe1a8e90eb51cd..671d4d6d14df106b3b0278364340ef3290d7a185 100644 (file)
@@ -945,7 +945,7 @@ static void __exit cryptd_exit(void)
        crypto_unregister_template(&cryptd_tmpl);
 }
 
-module_init(cryptd_init);
+subsys_initcall(cryptd_init);
 module_exit(cryptd_exit);
 
 MODULE_LICENSE("GPL");
diff --git a/crypto/crypto_user.c b/crypto/crypto_user.c
new file mode 100644 (file)
index 0000000..2abca78
--- /dev/null
@@ -0,0 +1,438 @@
+/*
+ * Crypto user configuration API.
+ *
+ * Copyright (C) 2011 secunet Security Networks AG
+ * Copyright (C) 2011 Steffen Klassert <steffen.klassert@secunet.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <linux/module.h>
+#include <linux/crypto.h>
+#include <linux/cryptouser.h>
+#include <net/netlink.h>
+#include <linux/security.h>
+#include <net/net_namespace.h>
+#include "internal.h"
+
+DEFINE_MUTEX(crypto_cfg_mutex);
+
+/* The crypto netlink socket */
+static struct sock *crypto_nlsk;
+
+struct crypto_dump_info {
+       struct sk_buff *in_skb;
+       struct sk_buff *out_skb;
+       u32 nlmsg_seq;
+       u16 nlmsg_flags;
+};
+
+static struct crypto_alg *crypto_alg_match(struct crypto_user_alg *p, int exact)
+{
+       struct crypto_alg *q, *alg = NULL;
+
+       down_read(&crypto_alg_sem);
+
+       if (list_empty(&crypto_alg_list))
+               return NULL;
+
+       list_for_each_entry(q, &crypto_alg_list, cra_list) {
+               int match = 0;
+
+               if ((q->cra_flags ^ p->cru_type) & p->cru_mask)
+                       continue;
+
+               if (strlen(p->cru_driver_name))
+                       match = !strcmp(q->cra_driver_name,
+                                       p->cru_driver_name);
+               else if (!exact)
+                       match = !strcmp(q->cra_name, p->cru_name);
+
+               if (match) {
+                       alg = q;
+                       break;
+               }
+       }
+
+       up_read(&crypto_alg_sem);
+
+       return alg;
+}
+
+static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg)
+{
+       struct crypto_report_cipher rcipher;
+
+       snprintf(rcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "cipher");
+
+       rcipher.blocksize = alg->cra_blocksize;
+       rcipher.min_keysize = alg->cra_cipher.cia_min_keysize;
+       rcipher.max_keysize = alg->cra_cipher.cia_max_keysize;
+
+       NLA_PUT(skb, CRYPTOCFGA_REPORT_CIPHER,
+               sizeof(struct crypto_report_cipher), &rcipher);
+
+       return 0;
+
+nla_put_failure:
+       return -EMSGSIZE;
+}
+
+static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg)
+{
+       struct crypto_report_comp rcomp;
+
+       snprintf(rcomp.type, CRYPTO_MAX_ALG_NAME, "%s", "compression");
+
+       NLA_PUT(skb, CRYPTOCFGA_REPORT_COMPRESS,
+               sizeof(struct crypto_report_comp), &rcomp);
+
+       return 0;
+
+nla_put_failure:
+       return -EMSGSIZE;
+}
+
+static int crypto_report_one(struct crypto_alg *alg,
+                            struct crypto_user_alg *ualg, struct sk_buff *skb)
+{
+       memcpy(&ualg->cru_name, &alg->cra_name, sizeof(ualg->cru_name));
+       memcpy(&ualg->cru_driver_name, &alg->cra_driver_name,
+              sizeof(ualg->cru_driver_name));
+       memcpy(&ualg->cru_module_name, module_name(alg->cra_module),
+              CRYPTO_MAX_ALG_NAME);
+
+       ualg->cru_flags = alg->cra_flags;
+       ualg->cru_refcnt = atomic_read(&alg->cra_refcnt);
+
+       NLA_PUT_U32(skb, CRYPTOCFGA_PRIORITY_VAL, alg->cra_priority);
+
+       if (alg->cra_flags & CRYPTO_ALG_LARVAL) {
+               struct crypto_report_larval rl;
+
+               snprintf(rl.type, CRYPTO_MAX_ALG_NAME, "%s", "larval");
+
+               NLA_PUT(skb, CRYPTOCFGA_REPORT_LARVAL,
+                       sizeof(struct crypto_report_larval), &rl);
+
+               goto out;
+       }
+
+       if (alg->cra_type && alg->cra_type->report) {
+               if (alg->cra_type->report(skb, alg))
+                       goto nla_put_failure;
+
+               goto out;
+       }
+
+       switch (alg->cra_flags & (CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_LARVAL)) {
+       case CRYPTO_ALG_TYPE_CIPHER:
+               if (crypto_report_cipher(skb, alg))
+                       goto nla_put_failure;
+
+               break;
+       case CRYPTO_ALG_TYPE_COMPRESS:
+               if (crypto_report_comp(skb, alg))
+                       goto nla_put_failure;
+
+               break;
+       }
+
+out:
+       return 0;
+
+nla_put_failure:
+       return -EMSGSIZE;
+}
+
+static int crypto_report_alg(struct crypto_alg *alg,
+                            struct crypto_dump_info *info)
+{
+       struct sk_buff *in_skb = info->in_skb;
+       struct sk_buff *skb = info->out_skb;
+       struct nlmsghdr *nlh;
+       struct crypto_user_alg *ualg;
+       int err = 0;
+
+       nlh = nlmsg_put(skb, NETLINK_CB(in_skb).pid, info->nlmsg_seq,
+                       CRYPTO_MSG_GETALG, sizeof(*ualg), info->nlmsg_flags);
+       if (!nlh) {
+               err = -EMSGSIZE;
+               goto out;
+       }
+
+       ualg = nlmsg_data(nlh);
+
+       err = crypto_report_one(alg, ualg, skb);
+       if (err) {
+               nlmsg_cancel(skb, nlh);
+               goto out;
+       }
+
+       nlmsg_end(skb, nlh);
+
+out:
+       return err;
+}
+
+static int crypto_report(struct sk_buff *in_skb, struct nlmsghdr *in_nlh,
+                        struct nlattr **attrs)
+{
+       struct crypto_user_alg *p = nlmsg_data(in_nlh);
+       struct crypto_alg *alg;
+       struct sk_buff *skb;
+       struct crypto_dump_info info;
+       int err;
+
+       if (!p->cru_driver_name)
+               return -EINVAL;
+
+       alg = crypto_alg_match(p, 1);
+       if (!alg)
+               return -ENOENT;
+
+       skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
+       if (!skb)
+               return -ENOMEM;
+
+       info.in_skb = in_skb;
+       info.out_skb = skb;
+       info.nlmsg_seq = in_nlh->nlmsg_seq;
+       info.nlmsg_flags = 0;
+
+       err = crypto_report_alg(alg, &info);
+       if (err)
+               return err;
+
+       return nlmsg_unicast(crypto_nlsk, skb, NETLINK_CB(in_skb).pid);
+}
+
+static int crypto_dump_report(struct sk_buff *skb, struct netlink_callback *cb)
+{
+       struct crypto_alg *alg;
+       struct crypto_dump_info info;
+       int err;
+
+       if (cb->args[0])
+               goto out;
+
+       cb->args[0] = 1;
+
+       info.in_skb = cb->skb;
+       info.out_skb = skb;
+       info.nlmsg_seq = cb->nlh->nlmsg_seq;
+       info.nlmsg_flags = NLM_F_MULTI;
+
+       list_for_each_entry(alg, &crypto_alg_list, cra_list) {
+               err = crypto_report_alg(alg, &info);
+               if (err)
+                       goto out_err;
+       }
+
+out:
+       return skb->len;
+out_err:
+       return err;
+}
+
+static int crypto_dump_report_done(struct netlink_callback *cb)
+{
+       return 0;
+}
+
+static int crypto_update_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
+                            struct nlattr **attrs)
+{
+       struct crypto_alg *alg;
+       struct crypto_user_alg *p = nlmsg_data(nlh);
+       struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
+       LIST_HEAD(list);
+
+       if (priority && !strlen(p->cru_driver_name))
+               return -EINVAL;
+
+       alg = crypto_alg_match(p, 1);
+       if (!alg)
+               return -ENOENT;
+
+       down_write(&crypto_alg_sem);
+
+       crypto_remove_spawns(alg, &list, NULL);
+
+       if (priority)
+               alg->cra_priority = nla_get_u32(priority);
+
+       up_write(&crypto_alg_sem);
+
+       crypto_remove_final(&list);
+
+       return 0;
+}
+
+static int crypto_del_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
+                         struct nlattr **attrs)
+{
+       struct crypto_alg *alg;
+       struct crypto_user_alg *p = nlmsg_data(nlh);
+
+       alg = crypto_alg_match(p, 1);
+       if (!alg)
+               return -ENOENT;
+
+       /* We can not unregister core algorithms such as aes-generic.
+        * We would loose the reference in the crypto_alg_list to this algorithm
+        * if we try to unregister. Unregistering such an algorithm without
+        * removing the module is not possible, so we restrict to crypto
+        * instances that are build from templates. */
+       if (!(alg->cra_flags & CRYPTO_ALG_INSTANCE))
+               return -EINVAL;
+
+       if (atomic_read(&alg->cra_refcnt) != 1)
+               return -EBUSY;
+
+       return crypto_unregister_alg(alg);
+}
+
+static int crypto_add_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
+                         struct nlattr **attrs)
+{
+       int exact;
+       const char *name;
+       struct crypto_alg *alg;
+       struct crypto_user_alg *p = nlmsg_data(nlh);
+       struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
+
+       if (strlen(p->cru_driver_name))
+               exact = 1;
+
+       if (priority && !exact)
+               return -EINVAL;
+
+       alg = crypto_alg_match(p, exact);
+       if (alg)
+               return -EEXIST;
+
+       if (strlen(p->cru_driver_name))
+               name = p->cru_driver_name;
+       else
+               name = p->cru_name;
+
+       alg = crypto_alg_mod_lookup(name, p->cru_type, p->cru_mask);
+       if (IS_ERR(alg))
+               return PTR_ERR(alg);
+
+       down_write(&crypto_alg_sem);
+
+       if (priority)
+               alg->cra_priority = nla_get_u32(priority);
+
+       up_write(&crypto_alg_sem);
+
+       crypto_mod_put(alg);
+
+       return 0;
+}
+
+#define MSGSIZE(type) sizeof(struct type)
+
+static const int crypto_msg_min[CRYPTO_NR_MSGTYPES] = {
+       [CRYPTO_MSG_NEWALG      - CRYPTO_MSG_BASE] = MSGSIZE(crypto_user_alg),
+       [CRYPTO_MSG_DELALG      - CRYPTO_MSG_BASE] = MSGSIZE(crypto_user_alg),
+       [CRYPTO_MSG_UPDATEALG   - CRYPTO_MSG_BASE] = MSGSIZE(crypto_user_alg),
+       [CRYPTO_MSG_GETALG      - CRYPTO_MSG_BASE] = MSGSIZE(crypto_user_alg),
+};
+
+static const struct nla_policy crypto_policy[CRYPTOCFGA_MAX+1] = {
+       [CRYPTOCFGA_PRIORITY_VAL]   = { .type = NLA_U32},
+};
+
+#undef MSGSIZE
+
+static struct crypto_link {
+       int (*doit)(struct sk_buff *, struct nlmsghdr *, struct nlattr **);
+       int (*dump)(struct sk_buff *, struct netlink_callback *);
+       int (*done)(struct netlink_callback *);
+} crypto_dispatch[CRYPTO_NR_MSGTYPES] = {
+       [CRYPTO_MSG_NEWALG      - CRYPTO_MSG_BASE] = { .doit = crypto_add_alg},
+       [CRYPTO_MSG_DELALG      - CRYPTO_MSG_BASE] = { .doit = crypto_del_alg},
+       [CRYPTO_MSG_UPDATEALG   - CRYPTO_MSG_BASE] = { .doit = crypto_update_alg},
+       [CRYPTO_MSG_GETALG      - CRYPTO_MSG_BASE] = { .doit = crypto_report,
+                                                      .dump = crypto_dump_report,
+                                                      .done = crypto_dump_report_done},
+};
+
+static int crypto_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
+{
+       struct nlattr *attrs[CRYPTOCFGA_MAX+1];
+       struct crypto_link *link;
+       int type, err;
+
+       type = nlh->nlmsg_type;
+       if (type > CRYPTO_MSG_MAX)
+               return -EINVAL;
+
+       type -= CRYPTO_MSG_BASE;
+       link = &crypto_dispatch[type];
+
+       if (security_netlink_recv(skb, CAP_NET_ADMIN))
+               return -EPERM;
+
+       if ((type == (CRYPTO_MSG_GETALG - CRYPTO_MSG_BASE) &&
+           (nlh->nlmsg_flags & NLM_F_DUMP))) {
+               if (link->dump == NULL)
+                       return -EINVAL;
+
+               return netlink_dump_start(crypto_nlsk, skb, nlh,
+                                         link->dump, link->done, 0);
+       }
+
+       err = nlmsg_parse(nlh, crypto_msg_min[type], attrs, CRYPTOCFGA_MAX,
+                         crypto_policy);
+       if (err < 0)
+               return err;
+
+       if (link->doit == NULL)
+               return -EINVAL;
+
+       return link->doit(skb, nlh, attrs);
+}
+
+static void crypto_netlink_rcv(struct sk_buff *skb)
+{
+       mutex_lock(&crypto_cfg_mutex);
+       netlink_rcv_skb(skb, &crypto_user_rcv_msg);
+       mutex_unlock(&crypto_cfg_mutex);
+}
+
+static int __init crypto_user_init(void)
+{
+       crypto_nlsk = netlink_kernel_create(&init_net, NETLINK_CRYPTO,
+                                           0, crypto_netlink_rcv,
+                                           NULL, THIS_MODULE);
+       if (!crypto_nlsk)
+               return -ENOMEM;
+
+       return 0;
+}
+
+static void __exit crypto_user_exit(void)
+{
+       netlink_kernel_release(crypto_nlsk);
+}
+
+module_init(crypto_user_init);
+module_exit(crypto_user_exit);
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Steffen Klassert <steffen.klassert@secunet.com>");
+MODULE_DESCRIPTION("Crypto userspace configuration API");
index d4384b08ab29563b9d529666c2c01f5766c4cd5f..b865ca1a8613b33baa9b64ffa6c32b89039f3bf8 100644 (file)
@@ -86,6 +86,9 @@ struct crypto_alg *crypto_larval_lookup(const char *name, u32 type, u32 mask);
 void crypto_larval_error(const char *name, u32 type, u32 mask);
 void crypto_alg_tested(const char *name, int err);
 
+void crypto_remove_spawns(struct crypto_alg *alg, struct list_head *list,
+                         struct crypto_alg *nalg);
+void crypto_remove_final(struct list_head *list);
 void crypto_shoot_alg(struct crypto_alg *alg);
 struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type,
                                      u32 mask);
index f7c4a7d7412ee69600ddd018a3099e9e8bb51e69..fefda78a6a2aa925d29e776dc87a956a605a2ab2 100644 (file)
@@ -24,6 +24,8 @@
 #include <linux/module.h>
 #include <linux/seq_file.h>
 #include <linux/string.h>
+#include <linux/cryptouser.h>
+#include <net/netlink.h>
 
 #include <crypto/compress.h>
 #include <crypto/internal/compress.h>
@@ -46,6 +48,21 @@ static int crypto_pcomp_init_tfm(struct crypto_tfm *tfm)
        return 0;
 }
 
+static int crypto_pcomp_report(struct sk_buff *skb, struct crypto_alg *alg)
+{
+       struct crypto_report_comp rpcomp;
+
+       snprintf(rpcomp.type, CRYPTO_MAX_ALG_NAME, "%s", "pcomp");
+
+       NLA_PUT(skb, CRYPTOCFGA_REPORT_COMPRESS,
+               sizeof(struct crypto_report_comp), &rpcomp);
+
+       return 0;
+
+nla_put_failure:
+       return -EMSGSIZE;
+}
+
 static void crypto_pcomp_show(struct seq_file *m, struct crypto_alg *alg)
        __attribute__ ((unused));
 static void crypto_pcomp_show(struct seq_file *m, struct crypto_alg *alg)
@@ -60,6 +77,7 @@ static const struct crypto_type crypto_pcomp_type = {
 #ifdef CONFIG_PROC_FS
        .show           = crypto_pcomp_show,
 #endif
+       .report         = crypto_pcomp_report,
        .maskclear      = ~CRYPTO_ALG_TYPE_MASK,
        .maskset        = CRYPTO_ALG_TYPE_MASK,
        .type           = CRYPTO_ALG_TYPE_PCOMPRESS,
index 45229ae782be91d4bec33185bccdee77ce95f1d5..feb7de00f437380fc8e95a3bf21398c9b4b1ce23 100644 (file)
@@ -21,6 +21,8 @@
 #include <linux/seq_file.h>
 #include <linux/slab.h>
 #include <linux/string.h>
+#include <linux/cryptouser.h>
+#include <net/netlink.h>
 
 static DEFINE_MUTEX(crypto_default_rng_lock);
 struct crypto_rng *crypto_default_rng;
@@ -58,6 +60,23 @@ static int crypto_init_rng_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
        return 0;
 }
 
+static int crypto_rng_report(struct sk_buff *skb, struct crypto_alg *alg)
+{
+       struct crypto_report_rng rrng;
+
+       snprintf(rrng.type, CRYPTO_MAX_ALG_NAME, "%s", "rng");
+
+       rrng.seedsize = alg->cra_rng.seedsize;
+
+       NLA_PUT(skb, CRYPTOCFGA_REPORT_RNG,
+               sizeof(struct crypto_report_rng), &rrng);
+
+       return 0;
+
+nla_put_failure:
+       return -EMSGSIZE;
+}
+
 static void crypto_rng_show(struct seq_file *m, struct crypto_alg *alg)
        __attribute__ ((unused));
 static void crypto_rng_show(struct seq_file *m, struct crypto_alg *alg)
@@ -78,6 +97,7 @@ const struct crypto_type crypto_rng_type = {
 #ifdef CONFIG_PROC_FS
        .show = crypto_rng_show,
 #endif
+       .report = crypto_rng_report,
 };
 EXPORT_SYMBOL_GPL(crypto_rng_type);
 
index 00ae60eb925435efe5295a9d7315283bd258e613..42794803c480531a60cc465657741a42ea5485dc 100644 (file)
@@ -36,7 +36,7 @@ static int sha1_init(struct shash_desc *desc)
        return 0;
 }
 
-static int sha1_update(struct shash_desc *desc, const u8 *data,
+int crypto_sha1_update(struct shash_desc *desc, const u8 *data,
                        unsigned int len)
 {
        struct sha1_state *sctx = shash_desc_ctx(desc);
@@ -71,6 +71,7 @@ static int sha1_update(struct shash_desc *desc, const u8 *data,
 
        return 0;
 }
+EXPORT_SYMBOL(crypto_sha1_update);
 
 
 /* Add padding and return the message digest. */
@@ -87,10 +88,10 @@ static int sha1_final(struct shash_desc *desc, u8 *out)
        /* Pad out to 56 mod 64 */
        index = sctx->count & 0x3f;
        padlen = (index < 56) ? (56 - index) : ((64+56) - index);
-       sha1_update(desc, padding, padlen);
+       crypto_sha1_update(desc, padding, padlen);
 
        /* Append length */
-       sha1_update(desc, (const u8 *)&bits, sizeof(bits));
+       crypto_sha1_update(desc, (const u8 *)&bits, sizeof(bits));
 
        /* Store state in digest */
        for (i = 0; i < 5; i++)
@@ -121,7 +122,7 @@ static int sha1_import(struct shash_desc *desc, const void *in)
 static struct shash_alg alg = {
        .digestsize     =       SHA1_DIGEST_SIZE,
        .init           =       sha1_init,
-       .update         =       sha1_update,
+       .update         =       crypto_sha1_update,
        .final          =       sha1_final,
        .export         =       sha1_export,
        .import         =       sha1_import,
index 76f74b96315119c039970519597251ff1e729c39..ea8a9c6e21e371170606863ecb5f8cc7a5030ea8 100644 (file)
@@ -17,6 +17,8 @@
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/seq_file.h>
+#include <linux/cryptouser.h>
+#include <net/netlink.h>
 
 #include "internal.h"
 
@@ -522,6 +524,24 @@ static unsigned int crypto_shash_extsize(struct crypto_alg *alg)
        return alg->cra_ctxsize;
 }
 
+static int crypto_shash_report(struct sk_buff *skb, struct crypto_alg *alg)
+{
+       struct crypto_report_hash rhash;
+       struct shash_alg *salg = __crypto_shash_alg(alg);
+
+       snprintf(rhash.type, CRYPTO_MAX_ALG_NAME, "%s", "shash");
+       rhash.blocksize = alg->cra_blocksize;
+       rhash.digestsize = salg->digestsize;
+
+       NLA_PUT(skb, CRYPTOCFGA_REPORT_HASH,
+               sizeof(struct crypto_report_hash), &rhash);
+
+       return 0;
+
+nla_put_failure:
+       return -EMSGSIZE;
+}
+
 static void crypto_shash_show(struct seq_file *m, struct crypto_alg *alg)
        __attribute__ ((unused));
 static void crypto_shash_show(struct seq_file *m, struct crypto_alg *alg)
@@ -541,6 +561,7 @@ static const struct crypto_type crypto_shash_type = {
 #ifdef CONFIG_PROC_FS
        .show = crypto_shash_show,
 #endif
+       .report = crypto_shash_report,
        .maskclear = ~CRYPTO_ALG_TYPE_MASK,
        .maskset = CRYPTO_ALG_TYPE_MASK,
        .type = CRYPTO_ALG_TYPE_SHASH,
index 2222617b3bedc631e28c5599bdbd5a7cef595413..0c4e80f34651bd01dabaed7632a42922fa3dca7e 100644 (file)
@@ -782,11 +782,13 @@ static int do_test(int m)
        case 7:
                ret += tcrypt_test("ecb(blowfish)");
                ret += tcrypt_test("cbc(blowfish)");
+               ret += tcrypt_test("ctr(blowfish)");
                break;
 
        case 8:
                ret += tcrypt_test("ecb(twofish)");
                ret += tcrypt_test("cbc(twofish)");
+               ret += tcrypt_test("ctr(twofish)");
                break;
 
        case 9:
@@ -1039,6 +1041,10 @@ static int do_test(int m)
                                speed_template_16_24_32);
                test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
                                speed_template_16_24_32);
+               test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
+                               speed_template_16_24_32);
+               test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
+                               speed_template_16_24_32);
                break;
 
        case 203:
@@ -1050,6 +1056,10 @@ static int do_test(int m)
                                  speed_template_8_32);
                test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
                                  speed_template_8_32);
+               test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
+                                 speed_template_8_32);
+               test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
+                                 speed_template_8_32);
                break;
 
        case 204:
index b6b93d41635149692f473d19fdc53118d4de29fe..e91c1eb1722a9b3c604f53d84cec306615761fd6 100644 (file)
@@ -1755,6 +1755,36 @@ static const struct alg_test_desc alg_test_descs[] = {
                                }
                        }
                }
+       }, {
+               .alg = "ctr(blowfish)",
+               .test = alg_test_skcipher,
+               .suite = {
+                       .cipher = {
+                               .enc = {
+                                       .vecs = bf_ctr_enc_tv_template,
+                                       .count = BF_CTR_ENC_TEST_VECTORS
+                               },
+                               .dec = {
+                                       .vecs = bf_ctr_dec_tv_template,
+                                       .count = BF_CTR_DEC_TEST_VECTORS
+                               }
+                       }
+               }
+       }, {
+               .alg = "ctr(twofish)",
+               .test = alg_test_skcipher,
+               .suite = {
+                       .cipher = {
+                               .enc = {
+                                       .vecs = tf_ctr_enc_tv_template,
+                                       .count = TF_CTR_ENC_TEST_VECTORS
+                               },
+                               .dec = {
+                                       .vecs = tf_ctr_dec_tv_template,
+                                       .count = TF_CTR_DEC_TEST_VECTORS
+                               }
+                       }
+               }
        }, {
                .alg = "cts(cbc(aes))",
                .test = alg_test_skcipher,
index 27adc92842bae0699da45335adabad7b9cd80fe9..37b4d8f4544750e520cda8cc56af887f632701a0 100644 (file)
@@ -2391,10 +2391,12 @@ static struct cipher_testvec des3_ede_cbc_dec_tv_template[] = {
 /*
  * Blowfish test vectors.
  */
-#define BF_ENC_TEST_VECTORS    6
-#define BF_DEC_TEST_VECTORS    6
-#define BF_CBC_ENC_TEST_VECTORS        1
-#define BF_CBC_DEC_TEST_VECTORS        1
+#define BF_ENC_TEST_VECTORS    7
+#define BF_DEC_TEST_VECTORS    7
+#define BF_CBC_ENC_TEST_VECTORS        2
+#define BF_CBC_DEC_TEST_VECTORS        2
+#define BF_CTR_ENC_TEST_VECTORS        2
+#define BF_CTR_DEC_TEST_VECTORS        2
 
 static struct cipher_testvec bf_enc_tv_template[] = {
        { /* DES test vectors from OpenSSL */
@@ -2448,6 +2450,24 @@ static struct cipher_testvec bf_enc_tv_template[] = {
                .ilen   = 8,
                .result = "\xc0\x45\x04\x01\x2e\x4e\x1f\x53",
                .rlen   = 8,
+       }, { /* Generated with Crypto++ */
+               .key    = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
+                         "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A"
+                         "\x27\x04\xE1\x27\x04\xE1\xBE\x9B"
+                         "\x78\xBE\x9B\x78\x55\x32\x0F\x55",
+               .klen   = 32,
+               .input  = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
+                         "\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
+                         "\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
+                         "\xAC\x20\xB7\x4E\xE5\x59\xF0\x87"
+                         "\x1E\x92\x29\xC0\x34\xCB\x62\xF9",
+               .ilen   = 40,
+               .result = "\x96\x87\x3D\x0C\x7B\xFB\xBD\x1F"
+                         "\xE3\xC1\x99\x6D\x39\xD4\xC2\x7D"
+                         "\xD7\x87\xA1\xF2\xDF\x51\x71\x26"
+                         "\xC2\xF4\x6D\xFF\xF6\xCD\x6B\x40"
+                         "\xE1\xB3\xBF\xD4\x38\x2B\xC8\x3B",
+               .rlen   = 40,
        },
 };
 
@@ -2503,6 +2523,24 @@ static struct cipher_testvec bf_dec_tv_template[] = {
                .ilen   = 8,
                .result = "\xfe\xdc\xba\x98\x76\x54\x32\x10",
                .rlen   = 8,
+       }, { /* Generated with Crypto++ */
+               .key    = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
+                         "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A"
+                         "\x27\x04\xE1\x27\x04\xE1\xBE\x9B"
+                         "\x78\xBE\x9B\x78\x55\x32\x0F\x55",
+               .klen   = 32,
+               .input  = "\x96\x87\x3D\x0C\x7B\xFB\xBD\x1F"
+                         "\xE3\xC1\x99\x6D\x39\xD4\xC2\x7D"
+                         "\xD7\x87\xA1\xF2\xDF\x51\x71\x26"
+                         "\xC2\xF4\x6D\xFF\xF6\xCD\x6B\x40"
+                         "\xE1\xB3\xBF\xD4\x38\x2B\xC8\x3B",
+               .ilen   = 40,
+               .result = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
+                         "\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
+                         "\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
+                         "\xAC\x20\xB7\x4E\xE5\x59\xF0\x87"
+                         "\x1E\x92\x29\xC0\x34\xCB\x62\xF9",
+               .rlen   = 40,
        },
 };
 
@@ -2522,6 +2560,25 @@ static struct cipher_testvec bf_cbc_enc_tv_template[] = {
                          "\x58\xde\xb9\xe7\x15\x46\x16\xd9"
                          "\x59\xf1\x65\x2b\xd5\xff\x92\xcc",
                .rlen   = 32,
+       }, { /* Generated with Crypto++ */
+               .key    = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
+                         "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A"
+                         "\x27\x04\xE1\x27\x04\xE1\xBE\x9B"
+                         "\x78\xBE\x9B\x78\x55\x32\x0F\x55",
+               .klen   = 32,
+               .iv     = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F",
+               .input  = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
+                         "\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
+                         "\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
+                         "\xAC\x20\xB7\x4E\xE5\x59\xF0\x87"
+                         "\x1E\x92\x29\xC0\x34\xCB\x62\xF9",
+               .ilen   = 40,
+               .result = "\xB4\xFE\xA5\xBB\x3D\x2C\x27\x06"
+                         "\x06\x2B\x3A\x92\xB2\xF5\x5E\x62"
+                         "\x84\xCD\xF7\x66\x7E\x41\x6C\x8E"
+                         "\x1B\xD9\x02\xB6\x48\xB0\x87\x25"
+                         "\x01\x9C\x93\x63\x51\x60\x82\xD2",
+               .rlen   = 40,
        },
 };
 
@@ -2541,16 +2598,125 @@ static struct cipher_testvec bf_cbc_dec_tv_template[] = {
                          "\x68\x65\x20\x74\x69\x6d\x65\x20"
                          "\x66\x6f\x72\x20\x00\x00\x00\x00",
                .rlen   = 32,
+       }, { /* Generated with Crypto++ */
+               .key    = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
+                         "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A"
+                         "\x27\x04\xE1\x27\x04\xE1\xBE\x9B"
+                         "\x78\xBE\x9B\x78\x55\x32\x0F\x55",
+               .klen   = 32,
+               .iv     = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F",
+               .input  = "\xB4\xFE\xA5\xBB\x3D\x2C\x27\x06"
+                         "\x06\x2B\x3A\x92\xB2\xF5\x5E\x62"
+                         "\x84\xCD\xF7\x66\x7E\x41\x6C\x8E"
+                         "\x1B\xD9\x02\xB6\x48\xB0\x87\x25"
+                         "\x01\x9C\x93\x63\x51\x60\x82\xD2",
+               .ilen   = 40,
+               .result = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
+                         "\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
+                         "\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
+                         "\xAC\x20\xB7\x4E\xE5\x59\xF0\x87"
+                         "\x1E\x92\x29\xC0\x34\xCB\x62\xF9",
+               .rlen   = 40,
+       },
+};
+
+static struct cipher_testvec bf_ctr_enc_tv_template[] = {
+       { /* Generated with Crypto++ */
+               .key    = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
+                         "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A"
+                         "\x27\x04\xE1\x27\x04\xE1\xBE\x9B"
+                         "\x78\xBE\x9B\x78\x55\x32\x0F\x55",
+               .klen   = 32,
+               .iv     = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F",
+               .input  = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
+                         "\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
+                         "\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
+                         "\xAC\x20\xB7\x4E\xE5\x59\xF0\x87"
+                         "\x1E\x92\x29\xC0\x34\xCB\x62\xF9",
+               .ilen   = 40,
+               .result = "\xC7\xA3\xDF\xB9\x05\xF4\x9E\x8D"
+                         "\x9E\xDF\x38\x18\x83\x07\xEF\xC1"
+                         "\x93\x3C\xAA\xAA\xFE\x06\x42\xCC"
+                         "\x0D\x70\x86\x5A\x44\xAD\x85\x17"
+                         "\xE4\x1F\x5E\xA5\x89\xAC\x32\xBC",
+               .rlen   = 40,
+       }, { /* Generated with Crypto++ */
+               .key    = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
+                         "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A"
+                         "\x27\x04\xE1\x27\x04\xE1\xBE\x9B"
+                         "\x78\xBE\x9B\x78\x55\x32\x0F\x55",
+               .klen   = 32,
+               .iv     = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F",
+               .input  = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
+                         "\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
+                         "\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
+                         "\xAC\x20\xB7\x4E\xE5\x59\xF0\x87"
+                         "\x1E\x92\x29\xC0\x34\xCB\x62\xF9"
+                         "\x6D\x04\x9B",
+               .ilen   = 43,
+               .result = "\xC7\xA3\xDF\xB9\x05\xF4\x9E\x8D"
+                         "\x9E\xDF\x38\x18\x83\x07\xEF\xC1"
+                         "\x93\x3C\xAA\xAA\xFE\x06\x42\xCC"
+                         "\x0D\x70\x86\x5A\x44\xAD\x85\x17"
+                         "\xE4\x1F\x5E\xA5\x89\xAC\x32\xBC"
+                         "\x3D\xA7\xE9",
+               .rlen   = 43,
+       },
+};
+
+static struct cipher_testvec bf_ctr_dec_tv_template[] = {
+       { /* Generated with Crypto++ */
+               .key    = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
+                         "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A"
+                         "\x27\x04\xE1\x27\x04\xE1\xBE\x9B"
+                         "\x78\xBE\x9B\x78\x55\x32\x0F\x55",
+               .klen   = 32,
+               .iv     = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F",
+               .input  = "\xC7\xA3\xDF\xB9\x05\xF4\x9E\x8D"
+                         "\x9E\xDF\x38\x18\x83\x07\xEF\xC1"
+                         "\x93\x3C\xAA\xAA\xFE\x06\x42\xCC"
+                         "\x0D\x70\x86\x5A\x44\xAD\x85\x17"
+                         "\xE4\x1F\x5E\xA5\x89\xAC\x32\xBC",
+               .ilen   = 40,
+               .result = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
+                         "\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
+                         "\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
+                         "\xAC\x20\xB7\x4E\xE5\x59\xF0\x87"
+                         "\x1E\x92\x29\xC0\x34\xCB\x62\xF9",
+               .rlen   = 40,
+       }, { /* Generated with Crypto++ */
+               .key    = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
+                         "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A"
+                         "\x27\x04\xE1\x27\x04\xE1\xBE\x9B"
+                         "\x78\xBE\x9B\x78\x55\x32\x0F\x55",
+               .klen   = 32,
+               .iv     = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F",
+               .input  = "\xC7\xA3\xDF\xB9\x05\xF4\x9E\x8D"
+                         "\x9E\xDF\x38\x18\x83\x07\xEF\xC1"
+                         "\x93\x3C\xAA\xAA\xFE\x06\x42\xCC"
+                         "\x0D\x70\x86\x5A\x44\xAD\x85\x17"
+                         "\xE4\x1F\x5E\xA5\x89\xAC\x32\xBC"
+                         "\x3D\xA7\xE9",
+               .ilen   = 43,
+               .result = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
+                         "\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
+                         "\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
+                         "\xAC\x20\xB7\x4E\xE5\x59\xF0\x87"
+                         "\x1E\x92\x29\xC0\x34\xCB\x62\xF9"
+                         "\x6D\x04\x9B",
+               .rlen   = 43,
        },
 };
 
 /*
  * Twofish test vectors.
  */
-#define TF_ENC_TEST_VECTORS            3
-#define TF_DEC_TEST_VECTORS            3
-#define TF_CBC_ENC_TEST_VECTORS                4
-#define TF_CBC_DEC_TEST_VECTORS                4
+#define TF_ENC_TEST_VECTORS            4
+#define TF_DEC_TEST_VECTORS            4
+#define TF_CBC_ENC_TEST_VECTORS                5
+#define TF_CBC_DEC_TEST_VECTORS                5
+#define TF_CTR_ENC_TEST_VECTORS                2
+#define TF_CTR_DEC_TEST_VECTORS                2
 
 static struct cipher_testvec tf_enc_tv_template[] = {
        {
@@ -2582,6 +2748,30 @@ static struct cipher_testvec tf_enc_tv_template[] = {
                .result = "\x37\x52\x7b\xe0\x05\x23\x34\xb8"
                          "\x9f\x0c\xfc\xca\xe8\x7c\xfa\x20",
                .rlen   = 16,
+       }, { /* Generated with Crypto++ */
+               .key    = "\x3F\x85\x62\x3F\x1C\xF9\xD6\x1C"
+                         "\xF9\xD6\xB3\x90\x6D\x4A\x90\x6D"
+                         "\x4A\x27\x04\xE1\x27\x04\xE1\xBE"
+                         "\x9B\x78\xBE\x9B\x78\x55\x32\x0F",
+               .klen   = 32,
+               .input  = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
+                         "\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
+                         "\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
+                         "\xAC\x20\xB7\x4E\xE5\x59\xF0\x87"
+                         "\x1E\x92\x29\xC0\x34\xCB\x62\xF9"
+                         "\x6D\x04\x9B\x0F\xA6\x3D\xD4\x48"
+                         "\xDF\x76\x0D\x81\x18\xAF\x23\xBA"
+                         "\x51\xE8\x5C\xF3\x8A\x21\x95\x2C",
+               .ilen   = 64,
+               .result = "\x88\xCB\x1E\xC2\xAF\x8A\x97\xFF"
+                         "\xF6\x90\x46\x9C\x4A\x0F\x08\xDC"
+                         "\xDE\xAB\xAD\xFA\xFC\xA8\xC2\x3D"
+                         "\xE0\xE4\x8B\x3F\xD5\xA3\xF7\x14"
+                         "\x34\x9E\xB6\x08\xB2\xDD\xA8\xF5"
+                         "\xDF\xFA\xC7\xE8\x09\x50\x76\x08"
+                         "\xA2\xB6\x6A\x59\xC0\x2B\x6D\x05"
+                         "\x89\xF6\x82\xF0\xD3\xDB\x06\x02",
+               .rlen   = 64,
        },
 };
 
@@ -2615,6 +2805,30 @@ static struct cipher_testvec tf_dec_tv_template[] = {
                .ilen   = 16,
                .result = zeroed_string,
                .rlen   = 16,
+       }, { /* Generated with Crypto++ */
+               .key    = "\x3F\x85\x62\x3F\x1C\xF9\xD6\x1C"
+                         "\xF9\xD6\xB3\x90\x6D\x4A\x90\x6D"
+                         "\x4A\x27\x04\xE1\x27\x04\xE1\xBE"
+                         "\x9B\x78\xBE\x9B\x78\x55\x32\x0F",
+               .klen   = 32,
+               .input  = "\x88\xCB\x1E\xC2\xAF\x8A\x97\xFF"
+                         "\xF6\x90\x46\x9C\x4A\x0F\x08\xDC"
+                         "\xDE\xAB\xAD\xFA\xFC\xA8\xC2\x3D"
+                         "\xE0\xE4\x8B\x3F\xD5\xA3\xF7\x14"
+                         "\x34\x9E\xB6\x08\xB2\xDD\xA8\xF5"
+                         "\xDF\xFA\xC7\xE8\x09\x50\x76\x08"
+                         "\xA2\xB6\x6A\x59\xC0\x2B\x6D\x05"
+                         "\x89\xF6\x82\xF0\xD3\xDB\x06\x02",
+               .ilen   = 64,
+               .result = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
+                         "\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
+                         "\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
+                         "\xAC\x20\xB7\x4E\xE5\x59\xF0\x87"
+                         "\x1E\x92\x29\xC0\x34\xCB\x62\xF9"
+                         "\x6D\x04\x9B\x0F\xA6\x3D\xD4\x48"
+                         "\xDF\x76\x0D\x81\x18\xAF\x23\xBA"
+                         "\x51\xE8\x5C\xF3\x8A\x21\x95\x2C",
+               .rlen   = 64,
        },
 };
 
@@ -2661,6 +2875,32 @@ static struct cipher_testvec tf_cbc_enc_tv_template[] = {
                          "\x05\xef\x8c\x61\xa8\x11\x58\x26"
                          "\x34\xba\x5c\xb7\x10\x6a\xa6\x41",
                .rlen   = 48,
+       }, { /* Generated with Crypto++ */
+               .key    = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
+                         "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A"
+                         "\x27\x04\xE1\x27\x04\xE1\xBE\x9B"
+                         "\x78\xBE\x9B\x78\x55\x32\x0F\x55",
+               .klen   = 32,
+               .iv     = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F"
+                         "\xC4\x29\x8E\xF3\x35\x9A\xFF\x64",
+               .input  = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
+                         "\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
+                         "\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
+                         "\xAC\x20\xB7\x4E\xE5\x59\xF0\x87"
+                         "\x1E\x92\x29\xC0\x34\xCB\x62\xF9"
+                         "\x6D\x04\x9B\x0F\xA6\x3D\xD4\x48"
+                         "\xDF\x76\x0D\x81\x18\xAF\x23\xBA"
+                         "\x51\xE8\x5C\xF3\x8A\x21\x95\x2C",
+               .ilen   = 64,
+               .result = "\xC8\xFF\xF2\x53\xA6\x27\x09\xD1"
+                         "\x33\x38\xC2\xC0\x0C\x14\x7E\xB5"
+                         "\x26\x1B\x05\x0C\x05\x12\x3F\xC0"
+                         "\xF9\x1C\x02\x28\x40\x96\x6F\xD0"
+                         "\x3D\x32\xDF\xDA\x56\x00\x6E\xEE"
+                         "\x5B\x2A\x72\x9D\xC2\x4D\x19\xBC"
+                         "\x8C\x53\xFA\x87\x6F\xDD\x81\xA3"
+                         "\xB1\xD3\x44\x65\xDF\xE7\x63\x38",
+               .rlen   = 64,
        },
 };
 
@@ -2707,6 +2947,148 @@ static struct cipher_testvec tf_cbc_dec_tv_template[] = {
                .ilen   = 48,
                .result = zeroed_string,
                .rlen   = 48,
+       }, { /* Generated with Crypto++ */
+               .key    = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
+                         "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A"
+                         "\x27\x04\xE1\x27\x04\xE1\xBE\x9B"
+                         "\x78\xBE\x9B\x78\x55\x32\x0F\x55",
+               .klen   = 32,
+               .iv     = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F"
+                         "\xC4\x29\x8E\xF3\x35\x9A\xFF\x64",
+               .input  = "\xC8\xFF\xF2\x53\xA6\x27\x09\xD1"
+                         "\x33\x38\xC2\xC0\x0C\x14\x7E\xB5"
+                         "\x26\x1B\x05\x0C\x05\x12\x3F\xC0"
+                         "\xF9\x1C\x02\x28\x40\x96\x6F\xD0"
+                         "\x3D\x32\xDF\xDA\x56\x00\x6E\xEE"
+                         "\x5B\x2A\x72\x9D\xC2\x4D\x19\xBC"
+                         "\x8C\x53\xFA\x87\x6F\xDD\x81\xA3"
+                         "\xB1\xD3\x44\x65\xDF\xE7\x63\x38",
+               .ilen   = 64,
+               .result = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
+                         "\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
+                         "\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
+                         "\xAC\x20\xB7\x4E\xE5\x59\xF0\x87"
+                         "\x1E\x92\x29\xC0\x34\xCB\x62\xF9"
+                         "\x6D\x04\x9B\x0F\xA6\x3D\xD4\x48"
+                         "\xDF\x76\x0D\x81\x18\xAF\x23\xBA"
+                         "\x51\xE8\x5C\xF3\x8A\x21\x95\x2C",
+               .rlen   = 64,
+       },
+};
+
+static struct cipher_testvec tf_ctr_enc_tv_template[] = {
+       { /* Generated with Crypto++ */
+               .key    = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
+                         "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A"
+                         "\x27\x04\xE1\x27\x04\xE1\xBE\x9B"
+                         "\x78\xBE\x9B\x78\x55\x32\x0F\x55",
+               .klen   = 32,
+               .iv     = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F"
+                         "\xC4\x29\x8E\xF3\x35\x9A\xFF\x64",
+               .input  = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
+                         "\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
+                         "\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
+                         "\xAC\x20\xB7\x4E\xE5\x59\xF0\x87"
+                         "\x1E\x92\x29\xC0\x34\xCB\x62\xF9"
+                         "\x6D\x04\x9B\x0F\xA6\x3D\xD4\x48"
+                         "\xDF\x76\x0D\x81\x18\xAF\x23\xBA"
+                         "\x51\xE8\x5C\xF3\x8A\x21\x95\x2C",
+               .ilen   = 64,
+               .result = "\xDF\xDD\x69\xFA\xB0\x2E\xFD\xFE"
+                         "\x70\x9E\xC5\x4B\xC9\xD4\xA1\x30"
+                         "\x26\x9B\x89\xA1\xEE\x43\xE0\x52"
+                         "\x55\x17\x4E\xC7\x0E\x33\x1F\xF1"
+                         "\x9F\x8D\x40\x9F\x24\xFD\x92\xA0"
+                         "\xBC\x8F\x35\xDD\x67\x38\xD8\xAA"
+                         "\xCF\xF8\x48\xCA\xFB\xE4\x5C\x60"
+                         "\x01\x41\x21\x12\x38\xAB\x52\x4F",
+               .rlen   = 64,
+       }, { /* Generated with Crypto++ */
+               .key    = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
+                         "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A"
+                         "\x27\x04\xE1\x27\x04\xE1\xBE\x9B"
+                         "\x78\xBE\x9B\x78\x55\x32\x0F\x55",
+               .klen   = 32,
+               .iv     = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F"
+                         "\xC4\x29\x8E\xF3\x35\x9A\xFF\x64",
+               .input  = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
+                         "\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
+                         "\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
+                         "\xAC\x20\xB7\x4E\xE5\x59\xF0\x87"
+                         "\x1E\x92\x29\xC0\x34\xCB\x62\xF9"
+                         "\x6D\x04\x9B\x0F\xA6\x3D\xD4\x48"
+                         "\xDF\x76\x0D\x81\x18\xAF\x23\xBA"
+                         "\x51\xE8\x5C\xF3\x8A\x21\x95\x2C"
+                         "\xC3\x37\xCE",
+               .ilen   = 67,
+               .result = "\xDF\xDD\x69\xFA\xB0\x2E\xFD\xFE"
+                         "\x70\x9E\xC5\x4B\xC9\xD4\xA1\x30"
+                         "\x26\x9B\x89\xA1\xEE\x43\xE0\x52"
+                         "\x55\x17\x4E\xC7\x0E\x33\x1F\xF1"
+                         "\x9F\x8D\x40\x9F\x24\xFD\x92\xA0"
+                         "\xBC\x8F\x35\xDD\x67\x38\xD8\xAA"
+                         "\xCF\xF8\x48\xCA\xFB\xE4\x5C\x60"
+                         "\x01\x41\x21\x12\x38\xAB\x52\x4F"
+                         "\xA8\x57\x20",
+               .rlen   = 67,
+       },
+};
+
+static struct cipher_testvec tf_ctr_dec_tv_template[] = {
+       { /* Generated with Crypto++ */
+               .key    = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
+                         "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A"
+                         "\x27\x04\xE1\x27\x04\xE1\xBE\x9B"
+                         "\x78\xBE\x9B\x78\x55\x32\x0F\x55",
+               .klen   = 32,
+               .iv     = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F"
+                         "\xC4\x29\x8E\xF3\x35\x9A\xFF\x64",
+               .input  = "\xDF\xDD\x69\xFA\xB0\x2E\xFD\xFE"
+                         "\x70\x9E\xC5\x4B\xC9\xD4\xA1\x30"
+                         "\x26\x9B\x89\xA1\xEE\x43\xE0\x52"
+                         "\x55\x17\x4E\xC7\x0E\x33\x1F\xF1"
+                         "\x9F\x8D\x40\x9F\x24\xFD\x92\xA0"
+                         "\xBC\x8F\x35\xDD\x67\x38\xD8\xAA"
+                         "\xCF\xF8\x48\xCA\xFB\xE4\x5C\x60"
+                         "\x01\x41\x21\x12\x38\xAB\x52\x4F",
+               .ilen   = 64,
+               .result = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
+                         "\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
+                         "\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
+                         "\xAC\x20\xB7\x4E\xE5\x59\xF0\x87"
+                         "\x1E\x92\x29\xC0\x34\xCB\x62\xF9"
+                         "\x6D\x04\x9B\x0F\xA6\x3D\xD4\x48"
+                         "\xDF\x76\x0D\x81\x18\xAF\x23\xBA"
+                         "\x51\xE8\x5C\xF3\x8A\x21\x95\x2C",
+               .rlen   = 64,
+       }, { /* Generated with Crypto++ */
+               .key    = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
+                         "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A"
+                         "\x27\x04\xE1\x27\x04\xE1\xBE\x9B"
+                         "\x78\xBE\x9B\x78\x55\x32\x0F\x55",
+               .klen   = 32,
+               .iv     = "\xE2\x24\x89\xEE\x53\xB8\x1D\x5F"
+                         "\xC4\x29\x8E\xF3\x35\x9A\xFF\x64",
+               .input  = "\xDF\xDD\x69\xFA\xB0\x2E\xFD\xFE"
+                         "\x70\x9E\xC5\x4B\xC9\xD4\xA1\x30"
+                         "\x26\x9B\x89\xA1\xEE\x43\xE0\x52"
+                         "\x55\x17\x4E\xC7\x0E\x33\x1F\xF1"
+                         "\x9F\x8D\x40\x9F\x24\xFD\x92\xA0"
+                         "\xBC\x8F\x35\xDD\x67\x38\xD8\xAA"
+                         "\xCF\xF8\x48\xCA\xFB\xE4\x5C\x60"
+                         "\x01\x41\x21\x12\x38\xAB\x52\x4F"
+                         "\xA8\x57\x20",
+               .ilen   = 67,
+               .result = "\x56\xED\x84\x1B\x8F\x26\xBD\x31"
+                         "\xC8\x5F\xF6\x6A\x01\x98\x0C\xA3"
+                         "\x3A\xD1\x45\xDC\x73\x0A\x7E\x15"
+                         "\xAC\x20\xB7\x4E\xE5\x59\xF0\x87"
+                         "\x1E\x92\x29\xC0\x34\xCB\x62\xF9"
+                         "\x6D\x04\x9B\x0F\xA6\x3D\xD4\x48"
+                         "\xDF\x76\x0D\x81\x18\xAF\x23\xBA"
+                         "\x51\xE8\x5C\xF3\x8A\x21\x95\x2C"
+                         "\xC3\x37\xCE",
+               .rlen   = 67,
        },
 };
 
index 723427273687011b3c4e8fd995e1ec8d1f6546d8..71719a2be25afa5ca341bd65306ec976b52d42b2 100644 (file)
@@ -762,11 +762,17 @@ static const u64 C7[256] = {
        0x86228644a411c286ULL,
 };
 
-static const u64 rc[WHIRLPOOL_ROUNDS + 1] = {
-       0x0000000000000000ULL, 0x1823c6e887b8014fULL, 0x36a6d2f5796f9152ULL,
-       0x60bc9b8ea30c7b35ULL, 0x1de0d7c22e4bfe57ULL, 0x157737e59ff04adaULL,
-       0x58c9290ab1a06b85ULL, 0xbd5d10f4cb3e0567ULL, 0xe427418ba77d95d8ULL,
-       0xfbee7c66dd17479eULL, 0xca2dbf07ad5a8333ULL,
+static const u64 rc[WHIRLPOOL_ROUNDS] = {
+       0x1823c6e887b8014fULL,
+       0x36a6d2f5796f9152ULL,
+       0x60bc9b8ea30c7b35ULL,
+       0x1de0d7c22e4bfe57ULL,
+       0x157737e59ff04adaULL,
+       0x58c9290ab1a06b85ULL,
+       0xbd5d10f4cb3e0567ULL,
+       0xe427418ba77d95d8ULL,
+       0xfbee7c66dd17479eULL,
+       0xca2dbf07ad5a8333ULL,
 };
 
 /**
@@ -793,7 +799,7 @@ static void wp512_process_buffer(struct wp512_ctx *wctx) {
        state[6] = block[6] ^ (K[6] = wctx->hash[6]);
        state[7] = block[7] ^ (K[7] = wctx->hash[7]);
 
-       for (r = 1; r <= WHIRLPOOL_ROUNDS; r++) {
+       for (r = 0; r < WHIRLPOOL_ROUNDS; r++) {
 
                L[0] = C0[(int)(K[0] >> 56)       ] ^
                           C1[(int)(K[7] >> 48) & 0xff] ^
index 2ca59dc69f7f6b034660bfdc04462230880456f9..127408069ca7fa745953fd5a8e164cd74779c680 100644 (file)
@@ -933,7 +933,7 @@ static int erst_open_pstore(struct pstore_info *psi);
 static int erst_close_pstore(struct pstore_info *psi);
 static ssize_t erst_reader(u64 *id, enum pstore_type_id *type,
                           struct timespec *time, struct pstore_info *psi);
-static u64 erst_writer(enum pstore_type_id type, unsigned int part,
+static int erst_writer(enum pstore_type_id type, u64 *id, unsigned int part,
                       size_t size, struct pstore_info *psi);
 static int erst_clearer(enum pstore_type_id type, u64 id,
                        struct pstore_info *psi);
@@ -1040,11 +1040,12 @@ out:
        return (rc < 0) ? rc : (len - sizeof(*rcd));
 }
 
-static u64 erst_writer(enum pstore_type_id type, unsigned int part,
+static int erst_writer(enum pstore_type_id type, u64 *id, unsigned int part,
                       size_t size, struct pstore_info *psi)
 {
        struct cper_pstore_record *rcd = (struct cper_pstore_record *)
                                        (erst_info.buf - sizeof(*rcd));
+       int ret;
 
        memset(rcd, 0, sizeof(*rcd));
        memcpy(rcd->hdr.signature, CPER_SIG_RECORD, CPER_SIG_SIZE);
@@ -1079,9 +1080,10 @@ static u64 erst_writer(enum pstore_type_id type, unsigned int part,
        }
        rcd->sec_hdr.section_severity = CPER_SEV_FATAL;
 
-       erst_write(&rcd->hdr);
+       ret = erst_write(&rcd->hdr);
+       *id = rcd->hdr.record_id;
 
-       return rcd->hdr.record_id;
+       return ret;
 }
 
 static int erst_clearer(enum pstore_type_id type, u64 id,
@@ -1165,7 +1167,7 @@ static int __init erst_init(void)
                goto err_release_erange;
 
        buf = kmalloc(erst_erange.size, GFP_KERNEL);
-       mutex_init(&erst_info.buf_mutex);
+       spin_lock_init(&erst_info.buf_lock);
        if (buf) {
                erst_info.buf = buf + sizeof(struct cper_pstore_record);
                erst_info.bufsize = erst_erange.size -
index fa32f584229f47f8965d56f6e4d61054796d8d39..f31c5c5f1b7e083351e013649f1e1d73fdd74fa6 100644 (file)
@@ -80,7 +80,8 @@ static acpi_osd_handler acpi_irq_handler;
 static void *acpi_irq_context;
 static struct workqueue_struct *kacpid_wq;
 static struct workqueue_struct *kacpi_notify_wq;
-static struct workqueue_struct *kacpi_hotplug_wq;
+struct workqueue_struct *kacpi_hotplug_wq;
+EXPORT_SYMBOL(kacpi_hotplug_wq);
 
 struct acpi_res_list {
        resource_size_t start;
index 32fc41c1da305ad42829b88f8c5a47eb6e1e8c1c..c04ad68cb602f20f734b25130e5dfbc7ac72bfd2 100644 (file)
@@ -6713,6 +6713,7 @@ EXPORT_SYMBOL_GPL(ata_scsi_queuecmd);
 EXPORT_SYMBOL_GPL(ata_scsi_slave_config);
 EXPORT_SYMBOL_GPL(ata_scsi_slave_destroy);
 EXPORT_SYMBOL_GPL(ata_scsi_change_queue_depth);
+EXPORT_SYMBOL_GPL(__ata_change_queue_depth);
 EXPORT_SYMBOL_GPL(sata_scr_valid);
 EXPORT_SYMBOL_GPL(sata_scr_read);
 EXPORT_SYMBOL_GPL(sata_scr_write);
index 46d087f086075f0d2eb5aae43b3e5e6f4d231f4c..19ba77032ac27ed94d0ca54aa23ccb5e2e8eb3fa 100644 (file)
@@ -1215,25 +1215,15 @@ void ata_scsi_slave_destroy(struct scsi_device *sdev)
 }
 
 /**
- *     ata_scsi_change_queue_depth - SCSI callback for queue depth config
- *     @sdev: SCSI device to configure queue depth for
- *     @queue_depth: new queue depth
- *     @reason: calling context
- *
- *     This is libata standard hostt->change_queue_depth callback.
- *     SCSI will call into this callback when user tries to set queue
- *     depth via sysfs.
+ *     __ata_change_queue_depth - helper for ata_scsi_change_queue_depth
  *
- *     LOCKING:
- *     SCSI layer (we don't care)
+ *     libsas and libata have different approaches for associating a sdev to
+ *     its ata_port.
  *
- *     RETURNS:
- *     Newly configured queue depth.
  */
-int ata_scsi_change_queue_depth(struct scsi_device *sdev, int queue_depth,
-                               int reason)
+int __ata_change_queue_depth(struct ata_port *ap, struct scsi_device *sdev,
+                            int queue_depth, int reason)
 {
-       struct ata_port *ap = ata_shost_to_port(sdev->host);
        struct ata_device *dev;
        unsigned long flags;
 
@@ -1268,6 +1258,30 @@ int ata_scsi_change_queue_depth(struct scsi_device *sdev, int queue_depth,
        return queue_depth;
 }
 
+/**
+ *     ata_scsi_change_queue_depth - SCSI callback for queue depth config
+ *     @sdev: SCSI device to configure queue depth for
+ *     @queue_depth: new queue depth
+ *     @reason: calling context
+ *
+ *     This is libata standard hostt->change_queue_depth callback.
+ *     SCSI will call into this callback when user tries to set queue
+ *     depth via sysfs.
+ *
+ *     LOCKING:
+ *     SCSI layer (we don't care)
+ *
+ *     RETURNS:
+ *     Newly configured queue depth.
+ */
+int ata_scsi_change_queue_depth(struct scsi_device *sdev, int queue_depth,
+                               int reason)
+{
+       struct ata_port *ap = ata_shost_to_port(sdev->host);
+
+       return __ata_change_queue_depth(ap, sdev, queue_depth, reason);
+}
+
 /**
  *     ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command
  *     @qc: Storage for translated ATA taskfile
index fe3c3249cec4a47e7198404e0343004e457b3b2d..65cc424359b05e735703b1b9a74277cb1f1359a9 100644 (file)
@@ -260,7 +260,7 @@ static struct rbd_client *rbd_client_create(struct ceph_options *opt,
        kref_init(&rbdc->kref);
        INIT_LIST_HEAD(&rbdc->node);
 
-       rbdc->client = ceph_create_client(opt, rbdc);
+       rbdc->client = ceph_create_client(opt, rbdc, 0, 0);
        if (IS_ERR(rbdc->client))
                goto out_rbdc;
        opt = NULL; /* Now rbdc->client is responsible for opt */
index e0b25de1e339249773287c13d8f457d1f9e94352..6d16b4b0d7a09bb2b2b3d6d77a230401388b89d6 100644 (file)
@@ -200,6 +200,7 @@ config CRYPTO_DEV_HIFN_795X
        select CRYPTO_BLKCIPHER
        select HW_RANDOM if CRYPTO_DEV_HIFN_795X_RNG
        depends on PCI
+       depends on !ARCH_DMA_ADDR_T_64BIT
        help
          This option allows you to have support for HIFN 795x crypto adapters.
 
@@ -266,7 +267,7 @@ config CRYPTO_DEV_OMAP_AES
 
 config CRYPTO_DEV_PICOXCELL
        tristate "Support for picoXcell IPSEC and Layer2 crypto engines"
-       depends on ARCH_PICOXCELL
+       depends on ARCH_PICOXCELL && HAVE_CLK
        select CRYPTO_AES
        select CRYPTO_AUTHENC
        select CRYPTO_ALGAPI
index a84250a5dd5111f08f79c58c9ff34875b744ff65..fe765f49de589a1229205447e476678da5d0ff6b 100644 (file)
@@ -2744,10 +2744,8 @@ static int __init hifn_init(void)
        unsigned int freq;
        int err;
 
-       if (sizeof(dma_addr_t) > 4) {
-               printk(KERN_INFO "HIFN supports only 32-bit addresses.\n");
-               return -EINVAL;
-       }
+       /* HIFN supports only 32-bit addresses */
+       BUILD_BUG_ON(sizeof(dma_addr_t) != 4);
 
        if (strncmp(hifn_pll_ref, "ext", 3) &&
            strncmp(hifn_pll_ref, "pci", 3)) {
index d0183ddb3076d1dec3b668e355e2967eb5046bc7..8944dabc0e3c79cae9e960a89cbb7b937072912a 100644 (file)
@@ -1006,9 +1006,9 @@ static int n2_do_ecb(struct ablkcipher_request *req, bool encrypt)
 
        spin_unlock_irqrestore(&qp->lock, flags);
 
+out:
        put_cpu();
 
-out:
        n2_chunk_complete(req, NULL);
        return err;
 }
@@ -1096,9 +1096,9 @@ static int n2_do_chaining(struct ablkcipher_request *req, bool encrypt)
 
        spin_unlock_irqrestore(&qp->lock, flags);
 
+out:
        put_cpu();
 
-out:
        n2_chunk_complete(req, err ? NULL : final_iv_addr);
        return err;
 }
index db33d300aa232a4dec0c4234b2ab768a5dfc7023..29b9469f83789eb42ee8c5d47ca7901d85fb70af 100644 (file)
@@ -508,10 +508,8 @@ static int __init padlock_init(void)
        int ret;
        struct cpuinfo_x86 *c = &cpu_data(0);
 
-       if (!cpu_has_xcrypt) {
-               printk(KERN_NOTICE PFX "VIA PadLock not detected.\n");
+       if (!cpu_has_xcrypt)
                return -ENODEV;
-       }
 
        if (!cpu_has_xcrypt_enabled) {
                printk(KERN_NOTICE PFX "VIA PadLock detected, but not enabled. Hmm, strange...\n");
index 230b5b8cda1f9b2ff82bbd410a5f27eb026b805f..a2b553eabbdb6db38839ba1f14cc26a61edb31d2 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/io.h>
 #include <linux/list.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/pm.h>
 #include <linux/rtnetlink.h>
@@ -1241,8 +1242,8 @@ static void spacc_spacc_complete(unsigned long data)
        spin_unlock_irqrestore(&engine->hw_lock, flags);
 
        list_for_each_entry_safe(req, tmp, &completed, list) {
-               req->complete(req);
                list_del(&req->list);
+               req->complete(req);
        }
 }
 
@@ -1657,10 +1658,33 @@ static struct spacc_alg l2_engine_algs[] = {
        },
 };
 
-static int __devinit spacc_probe(struct platform_device *pdev,
-                                unsigned max_ctxs, size_t cipher_pg_sz,
-                                size_t hash_pg_sz, size_t fifo_sz,
-                                struct spacc_alg *algs, size_t num_algs)
+#ifdef CONFIG_OF
+static const struct of_device_id spacc_of_id_table[] = {
+       { .compatible = "picochip,spacc-ipsec" },
+       { .compatible = "picochip,spacc-l2" },
+       {}
+};
+#else /* CONFIG_OF */
+#define spacc_of_id_table NULL
+#endif /* CONFIG_OF */
+
+static bool spacc_is_compatible(struct platform_device *pdev,
+                               const char *spacc_type)
+{
+       const struct platform_device_id *platid = platform_get_device_id(pdev);
+
+       if (platid && !strcmp(platid->name, spacc_type))
+               return true;
+
+#ifdef CONFIG_OF
+       if (of_device_is_compatible(pdev->dev.of_node, spacc_type))
+               return true;
+#endif /* CONFIG_OF */
+
+       return false;
+}
+
+static int __devinit spacc_probe(struct platform_device *pdev)
 {
        int i, err, ret = -EINVAL;
        struct resource *mem, *irq;
@@ -1669,13 +1693,25 @@ static int __devinit spacc_probe(struct platform_device *pdev,
        if (!engine)
                return -ENOMEM;
 
-       engine->max_ctxs        = max_ctxs;
-       engine->cipher_pg_sz    = cipher_pg_sz;
-       engine->hash_pg_sz      = hash_pg_sz;
-       engine->fifo_sz         = fifo_sz;
-       engine->algs            = algs;
-       engine->num_algs        = num_algs;
-       engine->name            = dev_name(&pdev->dev);
+       if (spacc_is_compatible(pdev, "picochip,spacc-ipsec")) {
+               engine->max_ctxs        = SPACC_CRYPTO_IPSEC_MAX_CTXS;
+               engine->cipher_pg_sz    = SPACC_CRYPTO_IPSEC_CIPHER_PG_SZ;
+               engine->hash_pg_sz      = SPACC_CRYPTO_IPSEC_HASH_PG_SZ;
+               engine->fifo_sz         = SPACC_CRYPTO_IPSEC_FIFO_SZ;
+               engine->algs            = ipsec_engine_algs;
+               engine->num_algs        = ARRAY_SIZE(ipsec_engine_algs);
+       } else if (spacc_is_compatible(pdev, "picochip,spacc-l2")) {
+               engine->max_ctxs        = SPACC_CRYPTO_L2_MAX_CTXS;
+               engine->cipher_pg_sz    = SPACC_CRYPTO_L2_CIPHER_PG_SZ;
+               engine->hash_pg_sz      = SPACC_CRYPTO_L2_HASH_PG_SZ;
+               engine->fifo_sz         = SPACC_CRYPTO_L2_FIFO_SZ;
+               engine->algs            = l2_engine_algs;
+               engine->num_algs        = ARRAY_SIZE(l2_engine_algs);
+       } else {
+               return -EINVAL;
+       }
+
+       engine->name = dev_name(&pdev->dev);
 
        mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
@@ -1711,7 +1747,7 @@ static int __devinit spacc_probe(struct platform_device *pdev,
 
        spin_lock_init(&engine->hw_lock);
 
-       engine->clk = clk_get(&pdev->dev, NULL);
+       engine->clk = clk_get(&pdev->dev, "ref");
        if (IS_ERR(engine->clk)) {
                dev_info(&pdev->dev, "clk unavailable\n");
                device_remove_file(&pdev->dev, &dev_attr_stat_irq_thresh);
@@ -1800,72 +1836,33 @@ static int __devexit spacc_remove(struct platform_device *pdev)
        return 0;
 }
 
-static int __devinit ipsec_probe(struct platform_device *pdev)
-{
-       return spacc_probe(pdev, SPACC_CRYPTO_IPSEC_MAX_CTXS,
-                          SPACC_CRYPTO_IPSEC_CIPHER_PG_SZ,
-                          SPACC_CRYPTO_IPSEC_HASH_PG_SZ,
-                          SPACC_CRYPTO_IPSEC_FIFO_SZ, ipsec_engine_algs,
-                          ARRAY_SIZE(ipsec_engine_algs));
-}
-
-static struct platform_driver ipsec_driver = {
-       .probe          = ipsec_probe,
-       .remove         = __devexit_p(spacc_remove),
-       .driver         = {
-               .name   = "picoxcell-ipsec",
-#ifdef CONFIG_PM
-               .pm     = &spacc_pm_ops,
-#endif /* CONFIG_PM */
-       },
+static const struct platform_device_id spacc_id_table[] = {
+       { "picochip,spacc-ipsec", },
+       { "picochip,spacc-l2", },
 };
 
-static int __devinit l2_probe(struct platform_device *pdev)
-{
-       return spacc_probe(pdev, SPACC_CRYPTO_L2_MAX_CTXS,
-                          SPACC_CRYPTO_L2_CIPHER_PG_SZ,
-                          SPACC_CRYPTO_L2_HASH_PG_SZ, SPACC_CRYPTO_L2_FIFO_SZ,
-                          l2_engine_algs, ARRAY_SIZE(l2_engine_algs));
-}
-
-static struct platform_driver l2_driver = {
-       .probe          = l2_probe,
+static struct platform_driver spacc_driver = {
+       .probe          = spacc_probe,
        .remove         = __devexit_p(spacc_remove),
        .driver         = {
-               .name   = "picoxcell-l2",
+               .name   = "picochip,spacc",
 #ifdef CONFIG_PM
                .pm     = &spacc_pm_ops,
 #endif /* CONFIG_PM */
+               .of_match_table = spacc_of_id_table,
        },
+       .id_table       = spacc_id_table,
 };
 
 static int __init spacc_init(void)
 {
-       int ret = platform_driver_register(&ipsec_driver);
-       if (ret) {
-               pr_err("failed to register ipsec spacc driver");
-               goto out;
-       }
-
-       ret = platform_driver_register(&l2_driver);
-       if (ret) {
-               pr_err("failed to register l2 spacc driver");
-               goto l2_failed;
-       }
-
-       return 0;
-
-l2_failed:
-       platform_driver_unregister(&ipsec_driver);
-out:
-       return ret;
+       return platform_driver_register(&spacc_driver);
 }
 module_init(spacc_init);
 
 static void __exit spacc_exit(void)
 {
-       platform_driver_unregister(&ipsec_driver);
-       platform_driver_unregister(&l2_driver);
+       platform_driver_unregister(&spacc_driver);
 }
 module_exit(spacc_exit);
 
index 8a0bb417aa1120da0af3173b2a81acee64b0a348..dbe76b5df9cf2550b2e2621e2b051cf490396f76 100644 (file)
@@ -416,7 +416,7 @@ static void talitos_done(unsigned long data)
 /*
  * locate current (offending) descriptor
  */
-static struct talitos_desc *current_desc(struct device *dev, int ch)
+static u32 current_desc_hdr(struct device *dev, int ch)
 {
        struct talitos_private *priv = dev_get_drvdata(dev);
        int tail = priv->chan[ch].tail;
@@ -428,23 +428,25 @@ static struct talitos_desc *current_desc(struct device *dev, int ch)
                tail = (tail + 1) & (priv->fifo_len - 1);
                if (tail == priv->chan[ch].tail) {
                        dev_err(dev, "couldn't locate current descriptor\n");
-                       return NULL;
+                       return 0;
                }
        }
 
-       return priv->chan[ch].fifo[tail].desc;
+       return priv->chan[ch].fifo[tail].desc->hdr;
 }
 
 /*
  * user diagnostics; report root cause of error based on execution unit status
  */
-static void report_eu_error(struct device *dev, int ch,
-                           struct talitos_desc *desc)
+static void report_eu_error(struct device *dev, int ch, u32 desc_hdr)
 {
        struct talitos_private *priv = dev_get_drvdata(dev);
        int i;
 
-       switch (desc->hdr & DESC_HDR_SEL0_MASK) {
+       if (!desc_hdr)
+               desc_hdr = in_be32(priv->reg + TALITOS_DESCBUF(ch));
+
+       switch (desc_hdr & DESC_HDR_SEL0_MASK) {
        case DESC_HDR_SEL0_AFEU:
                dev_err(dev, "AFEUISR 0x%08x_%08x\n",
                        in_be32(priv->reg + TALITOS_AFEUISR),
@@ -488,7 +490,7 @@ static void report_eu_error(struct device *dev, int ch,
                break;
        }
 
-       switch (desc->hdr & DESC_HDR_SEL1_MASK) {
+       switch (desc_hdr & DESC_HDR_SEL1_MASK) {
        case DESC_HDR_SEL1_MDEUA:
        case DESC_HDR_SEL1_MDEUB:
                dev_err(dev, "MDEUISR 0x%08x_%08x\n",
@@ -550,7 +552,7 @@ static void talitos_error(unsigned long data, u32 isr, u32 isr_lo)
                if (v_lo & TALITOS_CCPSR_LO_IEU)
                        dev_err(dev, "invalid execution unit error\n");
                if (v_lo & TALITOS_CCPSR_LO_EU)
-                       report_eu_error(dev, ch, current_desc(dev, ch));
+                       report_eu_error(dev, ch, current_desc_hdr(dev, ch));
                if (v_lo & TALITOS_CCPSR_LO_GB)
                        dev_err(dev, "gather boundary error\n");
                if (v_lo & TALITOS_CCPSR_LO_GRL)
index 9a8bebcf6b177fa79e9635ecde71f05b2578e798..c9eee6d33e9a70cf5f851570c48ff3086b93c39a 100644 (file)
@@ -114,10 +114,22 @@ static int f10_read_dct_pci_cfg(struct amd64_pvt *pvt, int addr, u32 *val,
        return __amd64_read_pci_cfg_dword(pvt->F2, addr, val, func);
 }
 
+/*
+ * Select DCT to which PCI cfg accesses are routed
+ */
+static void f15h_select_dct(struct amd64_pvt *pvt, u8 dct)
+{
+       u32 reg = 0;
+
+       amd64_read_pci_cfg(pvt->F1, DCT_CFG_SEL, &reg);
+       reg &= 0xfffffffe;
+       reg |= dct;
+       amd64_write_pci_cfg(pvt->F1, DCT_CFG_SEL, reg);
+}
+
 static int f15_read_dct_pci_cfg(struct amd64_pvt *pvt, int addr, u32 *val,
                                 const char *func)
 {
-       u32 reg = 0;
        u8 dct  = 0;
 
        if (addr >= 0x140 && addr <= 0x1a0) {
@@ -125,10 +137,7 @@ static int f15_read_dct_pci_cfg(struct amd64_pvt *pvt, int addr, u32 *val,
                addr -= 0x100;
        }
 
-       amd64_read_pci_cfg(pvt->F1, DCT_CFG_SEL, &reg);
-       reg &= 0xfffffffe;
-       reg |= dct;
-       amd64_write_pci_cfg(pvt->F1, DCT_CFG_SEL, reg);
+       f15h_select_dct(pvt, dct);
 
        return __amd64_read_pci_cfg_dword(pvt->F2, addr, val, func);
 }
@@ -198,6 +207,10 @@ static int amd64_set_scrub_rate(struct mem_ctl_info *mci, u32 bw)
        if (boot_cpu_data.x86 == 0xf)
                min_scrubrate = 0x0;
 
+       /* F15h Erratum #505 */
+       if (boot_cpu_data.x86 == 0x15)
+               f15h_select_dct(pvt, 0);
+
        return __amd64_set_scrub_rate(pvt->F3, bw, min_scrubrate);
 }
 
@@ -207,6 +220,10 @@ static int amd64_get_scrub_rate(struct mem_ctl_info *mci)
        u32 scrubval = 0;
        int i, retval = -EINVAL;
 
+       /* F15h Erratum #505 */
+       if (boot_cpu_data.x86 == 0x15)
+               f15h_select_dct(pvt, 0);
+
        amd64_read_pci_cfg(pvt->F3, SCRCTRL, &scrubval);
 
        scrubval = scrubval & 0x001F;
@@ -751,10 +768,10 @@ static int get_channel_from_ecc_syndrome(struct mem_ctl_info *, u16);
  * Determine if the DIMMs have ECC enabled. ECC is enabled ONLY if all the DIMMs
  * are ECC capable.
  */
-static enum edac_type amd64_determine_edac_cap(struct amd64_pvt *pvt)
+static unsigned long amd64_determine_edac_cap(struct amd64_pvt *pvt)
 {
        u8 bit;
-       enum dev_type edac_cap = EDAC_FLAG_NONE;
+       unsigned long edac_cap = EDAC_FLAG_NONE;
 
        bit = (boot_cpu_data.x86 > 0xf || pvt->ext_model >= K8_REV_F)
                ? 19
@@ -1953,11 +1970,9 @@ static inline void __amd64_decode_bus_error(struct mem_ctl_info *mci,
                amd64_handle_ue(mci, m);
 }
 
-void amd64_decode_bus_error(int node_id, struct mce *m, u32 nbcfg)
+void amd64_decode_bus_error(int node_id, struct mce *m)
 {
-       struct mem_ctl_info *mci = mcis[node_id];
-
-       __amd64_decode_bus_error(mci, m);
+       __amd64_decode_bus_error(mcis[node_id], m);
 }
 
 /*
index 795cfbc0bf50ff39b3f3911b6596d3353f90d4ef..d0864d9c38ad18b4b44026f22cd83549cd75b45c 100644 (file)
@@ -9,7 +9,7 @@ static u8 xec_mask       = 0xf;
 static u8 nb_err_cpumask = 0xf;
 
 static bool report_gart_errors;
-static void (*nb_bus_decoder)(int node_id, struct mce *m, u32 nbcfg);
+static void (*nb_bus_decoder)(int node_id, struct mce *m);
 
 void amd_report_gart_errors(bool v)
 {
@@ -17,13 +17,13 @@ void amd_report_gart_errors(bool v)
 }
 EXPORT_SYMBOL_GPL(amd_report_gart_errors);
 
-void amd_register_ecc_decoder(void (*f)(int, struct mce *, u32))
+void amd_register_ecc_decoder(void (*f)(int, struct mce *))
 {
        nb_bus_decoder = f;
 }
 EXPORT_SYMBOL_GPL(amd_register_ecc_decoder);
 
-void amd_unregister_ecc_decoder(void (*f)(int, struct mce *, u32))
+void amd_unregister_ecc_decoder(void (*f)(int, struct mce *))
 {
        if (nb_bus_decoder) {
                WARN_ON(nb_bus_decoder != f);
@@ -592,31 +592,14 @@ static bool nb_noop_mce(u16 ec, u8 xec)
        return false;
 }
 
-void amd_decode_nb_mce(int node_id, struct mce *m, u32 nbcfg)
+void amd_decode_nb_mce(struct mce *m)
 {
        struct cpuinfo_x86 *c = &boot_cpu_data;
-       u16 ec   = EC(m->status);
-       u8 xec   = XEC(m->status, 0x1f);
-       u32 nbsh = (u32)(m->status >> 32);
-       int core = -1;
-
-       pr_emerg(HW_ERR "Northbridge Error (node %d", node_id);
-
-       /* F10h, revD can disable ErrCpu[3:0] through ErrCpuVal */
-       if (c->x86 == 0x10 && c->x86_model > 7) {
-               if (nbsh & NBSH_ERR_CPU_VAL)
-                       core = nbsh & nb_err_cpumask;
-       } else {
-               u8 assoc_cpus = nbsh & nb_err_cpumask;
-
-               if (assoc_cpus > 0)
-                       core = fls(assoc_cpus) - 1;
-       }
+       int node_id = amd_get_nb_id(m->extcpu);
+       u16 ec = EC(m->status);
+       u8 xec = XEC(m->status, 0x1f);
 
-       if (core >= 0)
-               pr_cont(", core %d): ", core);
-       else
-               pr_cont("): ");
+       pr_emerg(HW_ERR "Northbridge Error (node %d): ", node_id);
 
        switch (xec) {
        case 0x2:
@@ -648,7 +631,7 @@ void amd_decode_nb_mce(int node_id, struct mce *m, u32 nbcfg)
 
        if (c->x86 == 0xf || c->x86 == 0x10 || c->x86 == 0x15)
                if ((xec == 0x8 || xec == 0x0) && nb_bus_decoder)
-                       nb_bus_decoder(node_id, m, nbcfg);
+                       nb_bus_decoder(node_id, m);
 
        return;
 
@@ -764,13 +747,13 @@ int amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)
 {
        struct mce *m = (struct mce *)data;
        struct cpuinfo_x86 *c = &boot_cpu_data;
-       int node, ecc;
+       int ecc;
 
        if (amd_filter_mce(m))
                return NOTIFY_STOP;
 
-       pr_emerg(HW_ERR "MC%d_STATUS[%s|%s|%s|%s|%s",
-               m->bank,
+       pr_emerg(HW_ERR "CPU:%d\tMC%d_STATUS[%s|%s|%s|%s|%s",
+               m->extcpu, m->bank,
                ((m->status & MCI_STATUS_OVER)  ? "Over"  : "-"),
                ((m->status & MCI_STATUS_UC)    ? "UE"    : "CE"),
                ((m->status & MCI_STATUS_MISCV) ? "MiscV" : "-"),
@@ -789,6 +772,8 @@ int amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)
 
        pr_cont("]: 0x%016llx\n", m->status);
 
+       if (m->status & MCI_STATUS_ADDRV)
+               pr_emerg(HW_ERR "\tMC%d_ADDR: 0x%016llx\n", m->bank, m->addr);
 
        switch (m->bank) {
        case 0:
@@ -811,8 +796,7 @@ int amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)
                break;
 
        case 4:
-               node = amd_get_nb_id(m->extcpu);
-               amd_decode_nb_mce(node, m, 0);
+               amd_decode_nb_mce(m);
                break;
 
        case 5:
index 795a3206acf5f83759f6c9d35e7938fc84e96aed..0106747e240c764bcc3a1507e44850f412073537 100644 (file)
@@ -86,9 +86,9 @@ struct amd_decoder_ops {
 };
 
 void amd_report_gart_errors(bool);
-void amd_register_ecc_decoder(void (*f)(int, struct mce *, u32));
-void amd_unregister_ecc_decoder(void (*f)(int, struct mce *, u32));
-void amd_decode_nb_mce(int, struct mce *, u32);
+void amd_register_ecc_decoder(void (*f)(int, struct mce *));
+void amd_unregister_ecc_decoder(void (*f)(int, struct mce *));
+void amd_decode_nb_mce(struct mce *);
 int amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data);
 
 #endif /* _EDAC_MCE_AMD_H */
index 334b82a3542c18ddbc4c138deafdf1931068434d..855ab3f5936fb8a4e69c640def0294d89aec914c 100644 (file)
@@ -1046,8 +1046,8 @@ static void update_split_timeout(struct fw_card *card)
 
        cycles = card->split_timeout_hi * 8000 + (card->split_timeout_lo >> 19);
 
-       cycles = max(cycles, 800u); /* minimum as per the spec */
-       cycles = min(cycles, 3u * 8000u); /* maximum OHCI timeout */
+       /* minimum per IEEE 1394, maximum which doesn't overflow OHCI */
+       cycles = clamp(cycles, 800u, 3u * 8000u);
 
        card->split_timeout_cycles = cycles;
        card->split_timeout_jiffies = DIV_ROUND_UP(cycles * HZ, 8000);
index 03a7a85d0424895e9e73301b36637e9848f70d69..a20f45b1e7e5a79509f08da27384705bbc915a19 100644 (file)
@@ -502,11 +502,7 @@ static struct fwnet_peer *fwnet_peer_find_by_node_id(struct fwnet_device *dev,
 static unsigned fwnet_max_payload(unsigned max_rec, unsigned speed)
 {
        max_rec = min(max_rec, speed + 8);
-       max_rec = min(max_rec, 0xbU); /* <= 4096 */
-       if (max_rec < 8) {
-               fw_notify("max_rec %x out of range\n", max_rec);
-               max_rec = 8;
-       }
+       max_rec = clamp(max_rec, 8U, 11U); /* 512...4096 */
 
        return (1 << (max_rec + 1)) - RFC2374_FRAG_HDR_SIZE;
 }
@@ -1125,17 +1121,12 @@ static int fwnet_broadcast_start(struct fwnet_device *dev)
        unsigned u;
 
        if (dev->local_fifo == FWNET_NO_FIFO_ADDR) {
-               /* outside OHCI posted write area? */
-               static const struct fw_address_region region = {
-                       .start = 0xffff00000000ULL,
-                       .end   = CSR_REGISTER_BASE,
-               };
-
                dev->handler.length = 4096;
                dev->handler.address_callback = fwnet_receive_packet;
                dev->handler.callback_data = dev;
 
-               retval = fw_core_add_address_handler(&dev->handler, &region);
+               retval = fw_core_add_address_handler(&dev->handler,
+                                       &fw_high_memory_region);
                if (retval < 0)
                        goto failed_initial;
 
index fd7170a9ad2cc4c21d0bbcf6099f9db8d2ce4884..6628feaa76229009f1bf5f62b3419d9e79dcea35 100644 (file)
@@ -42,6 +42,7 @@
 #include <linux/string.h>
 #include <linux/time.h>
 #include <linux/vmalloc.h>
+#include <linux/workqueue.h>
 
 #include <asm/byteorder.h>
 #include <asm/page.h>
@@ -125,6 +126,7 @@ struct context {
        struct fw_ohci *ohci;
        u32 regs;
        int total_allocation;
+       u32 current_bus;
        bool running;
        bool flushing;
 
@@ -226,7 +228,7 @@ struct fw_ohci {
 
        __le32    *self_id_cpu;
        dma_addr_t self_id_bus;
-       struct tasklet_struct bus_reset_tasklet;
+       struct work_struct bus_reset_work;
 
        u32 self_id_buffer[512];
 };
@@ -263,6 +265,8 @@ static char ohci_driver_name[] = KBUILD_MODNAME;
 #define PCI_DEVICE_ID_AGERE_FW643      0x5901
 #define PCI_DEVICE_ID_JMICRON_JMB38X_FW        0x2380
 #define PCI_DEVICE_ID_TI_TSB12LV22     0x8009
+#define PCI_DEVICE_ID_TI_TSB12LV26     0x8020
+#define PCI_DEVICE_ID_TI_TSB82AA2      0x8025
 #define PCI_VENDOR_ID_PINNACLE_SYSTEMS 0x11bd
 
 #define QUIRK_CYCLE_TIMER              1
@@ -270,6 +274,7 @@ static char ohci_driver_name[] = KBUILD_MODNAME;
 #define QUIRK_BE_HEADERS               4
 #define QUIRK_NO_1394A                 8
 #define QUIRK_NO_MSI                   16
+#define QUIRK_TI_SLLZ059               32
 
 /* In case of multiple matches in ohci_quirks[], only the first one is used. */
 static const struct {
@@ -299,6 +304,12 @@ static const struct {
        {PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_TSB12LV22, PCI_ANY_ID,
                QUIRK_CYCLE_TIMER | QUIRK_RESET_PACKET | QUIRK_NO_1394A},
 
+       {PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_TSB12LV26, PCI_ANY_ID,
+               QUIRK_RESET_PACKET | QUIRK_TI_SLLZ059},
+
+       {PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_TSB82AA2, PCI_ANY_ID,
+               QUIRK_RESET_PACKET | QUIRK_TI_SLLZ059},
+
        {PCI_VENDOR_ID_TI, PCI_ANY_ID, PCI_ANY_ID,
                QUIRK_RESET_PACKET},
 
@@ -315,6 +326,7 @@ MODULE_PARM_DESC(quirks, "Chip quirks (default = 0"
        ", AR/selfID endianess = "      __stringify(QUIRK_BE_HEADERS)
        ", no 1394a enhancements = "    __stringify(QUIRK_NO_1394A)
        ", disable MSI = "              __stringify(QUIRK_NO_MSI)
+       ", TI SLLZ059 erratum = "       __stringify(QUIRK_TI_SLLZ059)
        ")");
 
 #define OHCI_PARAM_DEBUG_AT_AR         1
@@ -859,7 +871,7 @@ static __le32 *handle_ar_packet(struct ar_context *ctx, __le32 *buffer)
         *
         * Alas some chips sometimes emit bus reset packets with a
         * wrong generation.  We set the correct generation for these
-        * at a slightly incorrect time (in bus_reset_tasklet).
+        * at a slightly incorrect time (in bus_reset_work).
         */
        if (evt == OHCI1394_evt_bus_reset) {
                if (!(ohci->quirks & QUIRK_RESET_PACKET))
@@ -1046,6 +1058,7 @@ static void context_tasklet(unsigned long data)
                address = le32_to_cpu(last->branch_address);
                z = address & 0xf;
                address &= ~0xf;
+               ctx->current_bus = address;
 
                /* If the branch address points to a buffer outside of the
                 * current buffer, advance to the next buffer. */
@@ -1713,9 +1726,94 @@ static u32 update_bus_time(struct fw_ohci *ohci)
        return ohci->bus_time | cycle_time_seconds;
 }
 
-static void bus_reset_tasklet(unsigned long data)
+static int get_status_for_port(struct fw_ohci *ohci, int port_index)
+{
+       int reg;
+
+       mutex_lock(&ohci->phy_reg_mutex);
+       reg = write_phy_reg(ohci, 7, port_index);
+       if (reg >= 0)
+               reg = read_phy_reg(ohci, 8);
+       mutex_unlock(&ohci->phy_reg_mutex);
+       if (reg < 0)
+               return reg;
+
+       switch (reg & 0x0f) {
+       case 0x06:
+               return 2;       /* is child node (connected to parent node) */
+       case 0x0e:
+               return 3;       /* is parent node (connected to child node) */
+       }
+       return 1;               /* not connected */
+}
+
+static int get_self_id_pos(struct fw_ohci *ohci, u32 self_id,
+       int self_id_count)
+{
+       int i;
+       u32 entry;
+
+       for (i = 0; i < self_id_count; i++) {
+               entry = ohci->self_id_buffer[i];
+               if ((self_id & 0xff000000) == (entry & 0xff000000))
+                       return -1;
+               if ((self_id & 0xff000000) < (entry & 0xff000000))
+                       return i;
+       }
+       return i;
+}
+
+/*
+ * TI TSB82AA2B and TSB12LV26 do not receive the selfID of a locally
+ * attached TSB41BA3D phy; see http://www.ti.com/litv/pdf/sllz059.
+ * Construct the selfID from phy register contents.
+ * FIXME:  How to determine the selfID.i flag?
+ */
+static int find_and_insert_self_id(struct fw_ohci *ohci, int self_id_count)
+{
+       int reg, i, pos, status;
+       /* link active 1, speed 3, bridge 0, contender 1, more packets 0 */
+       u32 self_id = 0x8040c800;
+
+       reg = reg_read(ohci, OHCI1394_NodeID);
+       if (!(reg & OHCI1394_NodeID_idValid)) {
+               fw_notify("node ID not valid, new bus reset in progress\n");
+               return -EBUSY;
+       }
+       self_id |= ((reg & 0x3f) << 24); /* phy ID */
+
+       reg = ohci_read_phy_reg(&ohci->card, 4);
+       if (reg < 0)
+               return reg;
+       self_id |= ((reg & 0x07) << 8); /* power class */
+
+       reg = ohci_read_phy_reg(&ohci->card, 1);
+       if (reg < 0)
+               return reg;
+       self_id |= ((reg & 0x3f) << 16); /* gap count */
+
+       for (i = 0; i < 3; i++) {
+               status = get_status_for_port(ohci, i);
+               if (status < 0)
+                       return status;
+               self_id |= ((status & 0x3) << (6 - (i * 2)));
+       }
+
+       pos = get_self_id_pos(ohci, self_id, self_id_count);
+       if (pos >= 0) {
+               memmove(&(ohci->self_id_buffer[pos+1]),
+                       &(ohci->self_id_buffer[pos]),
+                       (self_id_count - pos) * sizeof(*ohci->self_id_buffer));
+               ohci->self_id_buffer[pos] = self_id;
+               self_id_count++;
+       }
+       return self_id_count;
+}
+
+static void bus_reset_work(struct work_struct *work)
 {
-       struct fw_ohci *ohci = (struct fw_ohci *)data;
+       struct fw_ohci *ohci =
+               container_of(work, struct fw_ohci, bus_reset_work);
        int self_id_count, i, j, reg;
        int generation, new_generation;
        unsigned long flags;
@@ -1753,21 +1851,50 @@ static void bus_reset_tasklet(unsigned long data)
         * bit extra to get the actual number of self IDs.
         */
        self_id_count = (reg >> 3) & 0xff;
-       if (self_id_count == 0 || self_id_count > 252) {
+
+       if (self_id_count > 252) {
                fw_notify("inconsistent self IDs\n");
                return;
        }
+
        generation = (cond_le32_to_cpu(ohci->self_id_cpu[0]) >> 16) & 0xff;
        rmb();
 
        for (i = 1, j = 0; j < self_id_count; i += 2, j++) {
                if (ohci->self_id_cpu[i] != ~ohci->self_id_cpu[i + 1]) {
-                       fw_notify("inconsistent self IDs\n");
-                       return;
+                       /*
+                        * If the invalid data looks like a cycle start packet,
+                        * it's likely to be the result of the cycle master
+                        * having a wrong gap count.  In this case, the self IDs
+                        * so far are valid and should be processed so that the
+                        * bus manager can then correct the gap count.
+                        */
+                       if (cond_le32_to_cpu(ohci->self_id_cpu[i])
+                                                       == 0xffff008f) {
+                               fw_notify("ignoring spurious self IDs\n");
+                               self_id_count = j;
+                               break;
+                       } else {
+                               fw_notify("inconsistent self IDs\n");
+                               return;
+                       }
                }
                ohci->self_id_buffer[j] =
                                cond_le32_to_cpu(ohci->self_id_cpu[i]);
        }
+
+       if (ohci->quirks & QUIRK_TI_SLLZ059) {
+               self_id_count = find_and_insert_self_id(ohci, self_id_count);
+               if (self_id_count < 0) {
+                       fw_notify("could not construct local self ID\n");
+                       return;
+               }
+       }
+
+       if (self_id_count == 0) {
+               fw_notify("inconsistent self IDs\n");
+               return;
+       }
        rmb();
 
        /*
@@ -1887,7 +2014,7 @@ static irqreturn_t irq_handler(int irq, void *data)
        log_irqs(event);
 
        if (event & OHCI1394_selfIDComplete)
-               tasklet_schedule(&ohci->bus_reset_tasklet);
+               queue_work(fw_workqueue, &ohci->bus_reset_work);
 
        if (event & OHCI1394_RQPkt)
                tasklet_schedule(&ohci->ar_request_ctx.tasklet);
@@ -1934,7 +2061,8 @@ static irqreturn_t irq_handler(int irq, void *data)
                reg_read(ohci, OHCI1394_PostedWriteAddressLo);
                reg_write(ohci, OHCI1394_IntEventClear,
                          OHCI1394_postedWriteErr);
-               fw_error("PCI posted write error\n");
+               if (printk_ratelimit())
+                       fw_error("PCI posted write error\n");
        }
 
        if (unlikely(event & OHCI1394_cycleTooLong)) {
@@ -2048,6 +2176,28 @@ static int configure_1394a_enhancements(struct fw_ohci *ohci)
        return 0;
 }
 
+static int probe_tsb41ba3d(struct fw_ohci *ohci)
+{
+       /* TI vendor ID = 0x080028, TSB41BA3D product ID = 0x833005 (sic) */
+       static const u8 id[] = { 0x08, 0x00, 0x28, 0x83, 0x30, 0x05, };
+       int reg, i;
+
+       reg = read_phy_reg(ohci, 2);
+       if (reg < 0)
+               return reg;
+       if ((reg & PHY_EXTENDED_REGISTERS) != PHY_EXTENDED_REGISTERS)
+               return 0;
+
+       for (i = ARRAY_SIZE(id) - 1; i >= 0; i--) {
+               reg = read_paged_phy_reg(ohci, 1, i + 10);
+               if (reg < 0)
+                       return reg;
+               if (reg != id[i])
+                       return 0;
+       }
+       return 1;
+}
+
 static int ohci_enable(struct fw_card *card,
                       const __be32 *config_rom, size_t length)
 {
@@ -2085,6 +2235,16 @@ static int ohci_enable(struct fw_card *card,
                return -EIO;
        }
 
+       if (ohci->quirks & QUIRK_TI_SLLZ059) {
+               ret = probe_tsb41ba3d(ohci);
+               if (ret < 0)
+                       return ret;
+               if (ret)
+                       fw_notify("local TSB41BA3D phy\n");
+               else
+                       ohci->quirks &= ~QUIRK_TI_SLLZ059;
+       }
+
        reg_write(ohci, OHCI1394_HCControlClear,
                  OHCI1394_HCControl_noByteSwapData);
 
@@ -2260,7 +2420,7 @@ static int ohci_set_config_rom(struct fw_card *card,
         * then set up the real values for the two registers.
         *
         * We use ohci->lock to avoid racing with the code that sets
-        * ohci->next_config_rom to NULL (see bus_reset_tasklet).
+        * ohci->next_config_rom to NULL (see bus_reset_work).
         */
 
        next_config_rom =
@@ -2539,6 +2699,7 @@ static int handle_ir_packet_per_buffer(struct context *context,
        struct iso_context *ctx =
                container_of(context, struct iso_context, context);
        struct descriptor *pd;
+       u32 buffer_dma;
        __le32 *ir_header;
        void *p;
 
@@ -2549,6 +2710,16 @@ static int handle_ir_packet_per_buffer(struct context *context,
                /* Descriptor(s) not done yet, stop iteration */
                return 0;
 
+       while (!(d->control & cpu_to_le16(DESCRIPTOR_BRANCH_ALWAYS))) {
+               d++;
+               buffer_dma = le32_to_cpu(d->data_address);
+               dma_sync_single_range_for_cpu(context->ohci->card.device,
+                                             buffer_dma & PAGE_MASK,
+                                             buffer_dma & ~PAGE_MASK,
+                                             le16_to_cpu(d->req_count),
+                                             DMA_FROM_DEVICE);
+       }
+
        p = last + 1;
        copy_iso_headers(ctx, p);
 
@@ -2571,11 +2742,19 @@ static int handle_ir_buffer_fill(struct context *context,
 {
        struct iso_context *ctx =
                container_of(context, struct iso_context, context);
+       u32 buffer_dma;
 
        if (!last->transfer_status)
                /* Descriptor(s) not done yet, stop iteration */
                return 0;
 
+       buffer_dma = le32_to_cpu(last->data_address);
+       dma_sync_single_range_for_cpu(context->ohci->card.device,
+                                     buffer_dma & PAGE_MASK,
+                                     buffer_dma & ~PAGE_MASK,
+                                     le16_to_cpu(last->req_count),
+                                     DMA_FROM_DEVICE);
+
        if (le16_to_cpu(last->control) & DESCRIPTOR_IRQ_ALWAYS)
                ctx->base.callback.mc(&ctx->base,
                                      le32_to_cpu(last->data_address) +
@@ -2586,6 +2765,43 @@ static int handle_ir_buffer_fill(struct context *context,
        return 1;
 }
 
+static inline void sync_it_packet_for_cpu(struct context *context,
+                                         struct descriptor *pd)
+{
+       __le16 control;
+       u32 buffer_dma;
+
+       /* only packets beginning with OUTPUT_MORE* have data buffers */
+       if (pd->control & cpu_to_le16(DESCRIPTOR_BRANCH_ALWAYS))
+               return;
+
+       /* skip over the OUTPUT_MORE_IMMEDIATE descriptor */
+       pd += 2;
+
+       /*
+        * If the packet has a header, the first OUTPUT_MORE/LAST descriptor's
+        * data buffer is in the context program's coherent page and must not
+        * be synced.
+        */
+       if ((le32_to_cpu(pd->data_address) & PAGE_MASK) ==
+           (context->current_bus          & PAGE_MASK)) {
+               if (pd->control & cpu_to_le16(DESCRIPTOR_BRANCH_ALWAYS))
+                       return;
+               pd++;
+       }
+
+       do {
+               buffer_dma = le32_to_cpu(pd->data_address);
+               dma_sync_single_range_for_cpu(context->ohci->card.device,
+                                             buffer_dma & PAGE_MASK,
+                                             buffer_dma & ~PAGE_MASK,
+                                             le16_to_cpu(pd->req_count),
+                                             DMA_TO_DEVICE);
+               control = pd->control;
+               pd++;
+       } while (!(control & cpu_to_le16(DESCRIPTOR_BRANCH_ALWAYS)));
+}
+
 static int handle_it_packet(struct context *context,
                            struct descriptor *d,
                            struct descriptor *last)
@@ -2602,6 +2818,8 @@ static int handle_it_packet(struct context *context,
                /* Descriptor(s) not done yet, stop iteration */
                return 0;
 
+       sync_it_packet_for_cpu(context, d);
+
        i = ctx->header_length;
        if (i + 4 < PAGE_SIZE) {
                /* Present this value as big-endian to match the receive code */
@@ -2971,6 +3189,10 @@ static int queue_iso_transmit(struct iso_context *ctx,
                page_bus = page_private(buffer->pages[page]);
                pd[i].data_address = cpu_to_le32(page_bus + offset);
 
+               dma_sync_single_range_for_device(ctx->context.ohci->card.device,
+                                                page_bus, offset, length,
+                                                DMA_TO_DEVICE);
+
                payload_index += length;
        }
 
@@ -2995,6 +3217,7 @@ static int queue_iso_packet_per_buffer(struct iso_context *ctx,
                                       struct fw_iso_buffer *buffer,
                                       unsigned long payload)
 {
+       struct device *device = ctx->context.ohci->card.device;
        struct descriptor *d, *pd;
        dma_addr_t d_bus, page_bus;
        u32 z, header_z, rest;
@@ -3049,6 +3272,10 @@ static int queue_iso_packet_per_buffer(struct iso_context *ctx,
                        page_bus = page_private(buffer->pages[page]);
                        pd->data_address = cpu_to_le32(page_bus + offset);
 
+                       dma_sync_single_range_for_device(device, page_bus,
+                                                        offset, length,
+                                                        DMA_FROM_DEVICE);
+
                        offset = (offset + length) & ~PAGE_MASK;
                        rest -= length;
                        if (offset == 0)
@@ -3108,6 +3335,10 @@ static int queue_iso_buffer_fill(struct iso_context *ctx,
                page_bus = page_private(buffer->pages[page]);
                d->data_address = cpu_to_le32(page_bus + offset);
 
+               dma_sync_single_range_for_device(ctx->context.ohci->card.device,
+                                                page_bus, offset, length,
+                                                DMA_FROM_DEVICE);
+
                rest -= length;
                offset = 0;
                page++;
@@ -3239,8 +3470,7 @@ static int __devinit pci_probe(struct pci_dev *dev,
        spin_lock_init(&ohci->lock);
        mutex_init(&ohci->phy_reg_mutex);
 
-       tasklet_init(&ohci->bus_reset_tasklet,
-                    bus_reset_tasklet, (unsigned long)ohci);
+       INIT_WORK(&ohci->bus_reset_work, bus_reset_work);
 
        err = pci_request_region(dev, 0, ohci_driver_name);
        if (err) {
@@ -3382,6 +3612,7 @@ static void pci_remove(struct pci_dev *dev)
        ohci = pci_get_drvdata(dev);
        reg_write(ohci, OHCI1394_IntMaskClear, ~0);
        flush_writes(ohci);
+       cancel_work_sync(&ohci->bus_reset_work);
        fw_core_remove_card(&ohci->card);
 
        /*
index 17cef864506a7b6778b109dd0d0b570514eab6eb..68375bc3aef66cdf6c08662a7502aef42ef08f81 100644 (file)
@@ -154,12 +154,16 @@ struct sbp2_logical_unit {
        bool blocked;
 };
 
+static void sbp2_queue_work(struct sbp2_logical_unit *lu, unsigned long delay)
+{
+       queue_delayed_work(fw_workqueue, &lu->work, delay);
+}
+
 /*
  * We create one struct sbp2_target per IEEE 1212 Unit Directory
  * and one struct Scsi_Host per sbp2_target.
  */
 struct sbp2_target {
-       struct kref kref;
        struct fw_unit *unit;
        const char *bus_id;
        struct list_head lu_list;
@@ -772,71 +776,6 @@ static int sbp2_lun2int(u16 lun)
        return scsilun_to_int(&eight_bytes_lun);
 }
 
-static void sbp2_release_target(struct kref *kref)
-{
-       struct sbp2_target *tgt = container_of(kref, struct sbp2_target, kref);
-       struct sbp2_logical_unit *lu, *next;
-       struct Scsi_Host *shost =
-               container_of((void *)tgt, struct Scsi_Host, hostdata[0]);
-       struct scsi_device *sdev;
-       struct fw_device *device = target_device(tgt);
-
-       /* prevent deadlocks */
-       sbp2_unblock(tgt);
-
-       list_for_each_entry_safe(lu, next, &tgt->lu_list, link) {
-               sdev = scsi_device_lookup(shost, 0, 0, sbp2_lun2int(lu->lun));
-               if (sdev) {
-                       scsi_remove_device(sdev);
-                       scsi_device_put(sdev);
-               }
-               if (lu->login_id != INVALID_LOGIN_ID) {
-                       int generation, node_id;
-                       /*
-                        * tgt->node_id may be obsolete here if we failed
-                        * during initial login or after a bus reset where
-                        * the topology changed.
-                        */
-                       generation = device->generation;
-                       smp_rmb(); /* node_id vs. generation */
-                       node_id    = device->node_id;
-                       sbp2_send_management_orb(lu, node_id, generation,
-                                                SBP2_LOGOUT_REQUEST,
-                                                lu->login_id, NULL);
-               }
-               fw_core_remove_address_handler(&lu->address_handler);
-               list_del(&lu->link);
-               kfree(lu);
-       }
-       scsi_remove_host(shost);
-       fw_notify("released %s, target %d:0:0\n", tgt->bus_id, shost->host_no);
-
-       fw_unit_put(tgt->unit);
-       scsi_host_put(shost);
-       fw_device_put(device);
-}
-
-static void sbp2_target_get(struct sbp2_target *tgt)
-{
-       kref_get(&tgt->kref);
-}
-
-static void sbp2_target_put(struct sbp2_target *tgt)
-{
-       kref_put(&tgt->kref, sbp2_release_target);
-}
-
-/*
- * Always get the target's kref when scheduling work on one its units.
- * Each workqueue job is responsible to call sbp2_target_put() upon return.
- */
-static void sbp2_queue_work(struct sbp2_logical_unit *lu, unsigned long delay)
-{
-       sbp2_target_get(lu->tgt);
-       if (!queue_delayed_work(fw_workqueue, &lu->work, delay))
-               sbp2_target_put(lu->tgt);
-}
-
 /*
  * Write retransmit retry values into the BUSY_TIMEOUT register.
  * - The single-phase retry protocol is supported by all SBP-2 devices, but the
@@ -877,7 +816,7 @@ static void sbp2_login(struct work_struct *work)
        int generation, node_id, local_node_id;
 
        if (fw_device_is_shutdown(device))
-               goto out;
+               return;
 
        generation    = device->generation;
        smp_rmb();    /* node IDs must not be older than generation */
@@ -899,7 +838,7 @@ static void sbp2_login(struct work_struct *work)
                        /* Let any waiting I/O fail from now on. */
                        sbp2_unblock(lu->tgt);
                }
-               goto out;
+               return;
        }
 
        tgt->node_id      = node_id;
@@ -925,7 +864,8 @@ static void sbp2_login(struct work_struct *work)
        if (lu->has_sdev) {
                sbp2_cancel_orbs(lu);
                sbp2_conditionally_unblock(lu);
-               goto out;
+
+               return;
        }
 
        if (lu->tgt->workarounds & SBP2_WORKAROUND_DELAY_INQUIRY)
@@ -957,7 +897,8 @@ static void sbp2_login(struct work_struct *work)
        lu->has_sdev = true;
        scsi_device_put(sdev);
        sbp2_allow_block(lu);
-       goto out;
+
+       return;
 
  out_logout_login:
        smp_rmb(); /* generation may have changed */
@@ -971,8 +912,57 @@ static void sbp2_login(struct work_struct *work)
         * lu->work already.  Reset the work from reconnect to login.
         */
        PREPARE_DELAYED_WORK(&lu->work, sbp2_login);
- out:
-       sbp2_target_put(tgt);
+}
+
+static void sbp2_reconnect(struct work_struct *work)
+{
+       struct sbp2_logical_unit *lu =
+               container_of(work, struct sbp2_logical_unit, work.work);
+       struct sbp2_target *tgt = lu->tgt;
+       struct fw_device *device = target_device(tgt);
+       int generation, node_id, local_node_id;
+
+       if (fw_device_is_shutdown(device))
+               return;
+
+       generation    = device->generation;
+       smp_rmb();    /* node IDs must not be older than generation */
+       node_id       = device->node_id;
+       local_node_id = device->card->node_id;
+
+       if (sbp2_send_management_orb(lu, node_id, generation,
+                                    SBP2_RECONNECT_REQUEST,
+                                    lu->login_id, NULL) < 0) {
+               /*
+                * If reconnect was impossible even though we are in the
+                * current generation, fall back and try to log in again.
+                *
+                * We could check for "Function rejected" status, but
+                * looking at the bus generation as simpler and more general.
+                */
+               smp_rmb(); /* get current card generation */
+               if (generation == device->card->generation ||
+                   lu->retries++ >= 5) {
+                       fw_error("%s: failed to reconnect\n", tgt->bus_id);
+                       lu->retries = 0;
+                       PREPARE_DELAYED_WORK(&lu->work, sbp2_login);
+               }
+               sbp2_queue_work(lu, DIV_ROUND_UP(HZ, 5));
+
+               return;
+       }
+
+       tgt->node_id      = node_id;
+       tgt->address_high = local_node_id << 16;
+       smp_wmb();        /* node IDs must not be older than generation */
+       lu->generation    = generation;
+
+       fw_notify("%s: reconnected to LUN %04x (%d retries)\n",
+                 tgt->bus_id, lu->lun, lu->retries);
+
+       sbp2_agent_reset(lu);
+       sbp2_cancel_orbs(lu);
+       sbp2_conditionally_unblock(lu);
 }
 
 static int sbp2_add_logical_unit(struct sbp2_target *tgt, int lun_entry)
@@ -1120,6 +1110,7 @@ static void sbp2_init_workarounds(struct sbp2_target *tgt, u32 model,
 }
 
 static struct scsi_host_template scsi_driver_template;
+static int sbp2_remove(struct device *dev);
 
 static int sbp2_probe(struct device *dev)
 {
@@ -1141,7 +1132,6 @@ static int sbp2_probe(struct device *dev)
        tgt = (struct sbp2_target *)shost->hostdata;
        dev_set_drvdata(&unit->device, tgt);
        tgt->unit = unit;
-       kref_init(&tgt->kref);
        INIT_LIST_HEAD(&tgt->lu_list);
        tgt->bus_id = dev_name(&unit->device);
        tgt->guid = (u64)device->config_rom[3] << 32 | device->config_rom[4];
@@ -1154,9 +1144,6 @@ static int sbp2_probe(struct device *dev)
        if (scsi_add_host(shost, &unit->device) < 0)
                goto fail_shost_put;
 
-       fw_device_get(device);
-       fw_unit_get(unit);
-
        /* implicit directory ID */
        tgt->directory_id = ((unit->directory - device->config_rom) * 4
                             + CSR_CONFIG_ROM) & 0xffffff;
@@ -1166,7 +1153,7 @@ static int sbp2_probe(struct device *dev)
 
        if (sbp2_scan_unit_dir(tgt, unit->directory, &model,
                               &firmware_revision) < 0)
-               goto fail_tgt_put;
+               goto fail_remove;
 
        sbp2_clamp_management_orb_timeout(tgt);
        sbp2_init_workarounds(tgt, model, firmware_revision);
@@ -1177,16 +1164,17 @@ static int sbp2_probe(struct device *dev)
         * specifies the max payload size as 2 ^ (max_payload + 2), so
         * if we set this to max_speed + 7, we get the right value.
         */
-       tgt->max_payload = min(device->max_speed + 7, 10U);
-       tgt->max_payload = min(tgt->max_payload, device->card->max_receive - 1);
+       tgt->max_payload = min3(device->max_speed + 7, 10U,
+                               device->card->max_receive - 1);
 
        /* Do the login in a workqueue so we can easily reschedule retries. */
        list_for_each_entry(lu, &tgt->lu_list, link)
                sbp2_queue_work(lu, DIV_ROUND_UP(HZ, 5));
+
        return 0;
 
- fail_tgt_put:
-       sbp2_target_put(tgt);
+ fail_remove:
+       sbp2_remove(dev);
        return -ENOMEM;
 
  fail_shost_put:
@@ -1194,71 +1182,6 @@ static int sbp2_probe(struct device *dev)
        return -ENOMEM;
 }
 
-static int sbp2_remove(struct device *dev)
-{
-       struct fw_unit *unit = fw_unit(dev);
-       struct sbp2_target *tgt = dev_get_drvdata(&unit->device);
-       struct sbp2_logical_unit *lu;
-
-       list_for_each_entry(lu, &tgt->lu_list, link)
-               cancel_delayed_work_sync(&lu->work);
-
-       sbp2_target_put(tgt);
-       return 0;
-}
-
-static void sbp2_reconnect(struct work_struct *work)
-{
-       struct sbp2_logical_unit *lu =
-               container_of(work, struct sbp2_logical_unit, work.work);
-       struct sbp2_target *tgt = lu->tgt;
-       struct fw_device *device = target_device(tgt);
-       int generation, node_id, local_node_id;
-
-       if (fw_device_is_shutdown(device))
-               goto out;
-
-       generation    = device->generation;
-       smp_rmb();    /* node IDs must not be older than generation */
-       node_id       = device->node_id;
-       local_node_id = device->card->node_id;
-
-       if (sbp2_send_management_orb(lu, node_id, generation,
-                                    SBP2_RECONNECT_REQUEST,
-                                    lu->login_id, NULL) < 0) {
-               /*
-                * If reconnect was impossible even though we are in the
-                * current generation, fall back and try to log in again.
-                *
-                * We could check for "Function rejected" status, but
-                * looking at the bus generation as simpler and more general.
-                */
-               smp_rmb(); /* get current card generation */
-               if (generation == device->card->generation ||
-                   lu->retries++ >= 5) {
-                       fw_error("%s: failed to reconnect\n", tgt->bus_id);
-                       lu->retries = 0;
-                       PREPARE_DELAYED_WORK(&lu->work, sbp2_login);
-               }
-               sbp2_queue_work(lu, DIV_ROUND_UP(HZ, 5));
-               goto out;
-       }
-
-       tgt->node_id      = node_id;
-       tgt->address_high = local_node_id << 16;
-       smp_wmb();        /* node IDs must not be older than generation */
-       lu->generation    = generation;
-
-       fw_notify("%s: reconnected to LUN %04x (%d retries)\n",
-                 tgt->bus_id, lu->lun, lu->retries);
-
-       sbp2_agent_reset(lu);
-       sbp2_cancel_orbs(lu);
-       sbp2_conditionally_unblock(lu);
- out:
-       sbp2_target_put(tgt);
-}
-
 static void sbp2_update(struct fw_unit *unit)
 {
        struct sbp2_target *tgt = dev_get_drvdata(&unit->device);
@@ -1277,6 +1200,51 @@ static void sbp2_update(struct fw_unit *unit)
        }
 }
 
+static int sbp2_remove(struct device *dev)
+{
+       struct fw_unit *unit = fw_unit(dev);
+       struct fw_device *device = fw_parent_device(unit);
+       struct sbp2_target *tgt = dev_get_drvdata(&unit->device);
+       struct sbp2_logical_unit *lu, *next;
+       struct Scsi_Host *shost =
+               container_of((void *)tgt, struct Scsi_Host, hostdata[0]);
+       struct scsi_device *sdev;
+
+       /* prevent deadlocks */
+       sbp2_unblock(tgt);
+
+       list_for_each_entry_safe(lu, next, &tgt->lu_list, link) {
+               cancel_delayed_work_sync(&lu->work);
+               sdev = scsi_device_lookup(shost, 0, 0, sbp2_lun2int(lu->lun));
+               if (sdev) {
+                       scsi_remove_device(sdev);
+                       scsi_device_put(sdev);
+               }
+               if (lu->login_id != INVALID_LOGIN_ID) {
+                       int generation, node_id;
+                       /*
+                        * tgt->node_id may be obsolete here if we failed
+                        * during initial login or after a bus reset where
+                        * the topology changed.
+                        */
+                       generation = device->generation;
+                       smp_rmb(); /* node_id vs. generation */
+                       node_id    = device->node_id;
+                       sbp2_send_management_orb(lu, node_id, generation,
+                                                SBP2_LOGOUT_REQUEST,
+                                                lu->login_id, NULL);
+               }
+               fw_core_remove_address_handler(&lu->address_handler);
+               list_del(&lu->link);
+               kfree(lu);
+       }
+       scsi_remove_host(shost);
+       fw_notify("released %s, target %d:0:0\n", tgt->bus_id, shost->host_no);
+
+       scsi_host_put(shost);
+       return 0;
+}
+
 #define SBP2_UNIT_SPEC_ID_ENTRY        0x0000609e
 #define SBP2_SW_VERSION_ENTRY  0x00010483
 
index eb80b549ed8d17dc0d46a0d6d85a9ccbee0a25d0..8370f72d87ff5ed955789973845629f406f6734e 100644 (file)
@@ -490,8 +490,8 @@ static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type,
        return 0;
 }
 
-static u64 efi_pstore_write(enum pstore_type_id type, unsigned int part,
-                           size_t size, struct pstore_info *psi)
+static int efi_pstore_write(enum pstore_type_id type, u64 *id,
+               unsigned int part, size_t size, struct pstore_info *psi)
 {
        char name[DUMP_NAME_LEN];
        char stub_name[DUMP_NAME_LEN];
@@ -499,7 +499,7 @@ static u64 efi_pstore_write(enum pstore_type_id type, unsigned int part,
        efi_guid_t vendor = LINUX_EFI_CRASH_GUID;
        struct efivars *efivars = psi->data;
        struct efivar_entry *entry, *found = NULL;
-       int i;
+       int i, ret = 0;
 
        sprintf(stub_name, "dump-type%u-%u-", type, part);
        sprintf(name, "%s%lu", stub_name, get_seconds());
@@ -548,18 +548,19 @@ static u64 efi_pstore_write(enum pstore_type_id type, unsigned int part,
                efivar_unregister(found);
 
        if (size)
-               efivar_create_sysfs_entry(efivars,
+               ret = efivar_create_sysfs_entry(efivars,
                                          utf16_strsize(efi_name,
                                                        DUMP_NAME_LEN * 2),
                                          efi_name, &vendor);
 
-       return part;
+       *id = part;
+       return ret;
 };
 
 static int efi_pstore_erase(enum pstore_type_id type, u64 id,
                            struct pstore_info *psi)
 {
-       efi_pstore_write(type, id, 0, psi);
+       efi_pstore_write(type, &id, (unsigned int)id, 0, psi);
 
        return 0;
 }
@@ -580,8 +581,8 @@ static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type,
        return -1;
 }
 
-static u64 efi_pstore_write(enum pstore_type_id type, unsigned int part,
-                           size_t size, struct pstore_info *psi)
+static int efi_pstore_write(enum pstore_type_id type, u64 *id,
+               unsigned int part, size_t size, struct pstore_info *psi)
 {
        return 0;
 }
@@ -978,7 +979,7 @@ int register_efivars(struct efivars *efivars,
        if (efivars->efi_pstore_info.buf) {
                efivars->efi_pstore_info.bufsize = 1024;
                efivars->efi_pstore_info.data = efivars;
-               mutex_init(&efivars->efi_pstore_info.buf_mutex);
+               spin_lock_init(&efivars->efi_pstore_info.buf_lock);
                pstore_register(&efivars->efi_pstore_info);
        }
 
index 4caa3d37bbde5783164f47cc68e278bb4d243c0d..cb0bd078efc030887f31548b4c6f8d97abfa3eaf 100644 (file)
@@ -397,6 +397,7 @@ config GPIO_LANGWELL
 config GPIO_PCH
        tristate "Intel EG20T PCH / OKI SEMICONDUCTOR ML7223 IOH GPIO"
        depends on PCI && X86
+       select GENERIC_IRQ_CHIP
        help
          This driver is for PCH(Platform controller Hub) GPIO of Intel Topcliff
          which is an IOH(Input/Output Hub) for x86 embedded processor.
@@ -411,6 +412,7 @@ config GPIO_PCH
 config GPIO_ML_IOH
        tristate "OKI SEMICONDUCTOR ML7213 IOH GPIO support"
        depends on PCI
+       select GENERIC_IRQ_CHIP
        help
          ML7213 is companion chip for Intel Atom E6xx series.
          This driver can be used for OKI SEMICONDUCTOR ML7213 IOH(Input/Output
index d2eb57c60e0ed874c2e68790c14ac2d0d0531ada..00692e89ef878ac20834354df75f173d40fe68b8 100644 (file)
@@ -59,6 +59,7 @@ enum GPIO_REG {
        GRER,           /* rising edge detect */
        GFER,           /* falling edge detect */
        GEDR,           /* edge detect result */
+       GAFR,           /* alt function */
 };
 
 struct lnw_gpio {
@@ -81,6 +82,31 @@ static void __iomem *gpio_reg(struct gpio_chip *chip, unsigned offset,
        return ptr;
 }
 
+static void __iomem *gpio_reg_2bit(struct gpio_chip *chip, unsigned offset,
+                                  enum GPIO_REG reg_type)
+{
+       struct lnw_gpio *lnw = container_of(chip, struct lnw_gpio, chip);
+       unsigned nreg = chip->ngpio / 32;
+       u8 reg = offset / 16;
+       void __iomem *ptr;
+
+       ptr = (void __iomem *)(lnw->reg_base + reg_type * nreg * 4 + reg * 4);
+       return ptr;
+}
+
+static int lnw_gpio_request(struct gpio_chip *chip, unsigned offset)
+{
+       void __iomem *gafr = gpio_reg_2bit(chip, offset, GAFR);
+       u32 value = readl(gafr);
+       int shift = (offset % 16) << 1, af = (value >> shift) & 3;
+
+       if (af) {
+               value &= ~(3 << shift);
+               writel(value, gafr);
+       }
+       return 0;
+}
+
 static int lnw_gpio_get(struct gpio_chip *chip, unsigned offset)
 {
        void __iomem *gplr = gpio_reg(chip, offset, GPLR);
@@ -321,6 +347,7 @@ static int __devinit lnw_gpio_probe(struct pci_dev *pdev,
        lnw->reg_base = base;
        lnw->irq_base = irq_base;
        lnw->chip.label = dev_name(&pdev->dev);
+       lnw->chip.request = lnw_gpio_request;
        lnw->chip.direction_input = lnw_gpio_direction_input;
        lnw->chip.direction_output = lnw_gpio_direction_output;
        lnw->chip.get = lnw_gpio_get;
index a9016f56ed7e012f7f66fb08ce32e55a1301f4b7..3aa6beec8c1e71b1e08527b43c6dbbd9e3f8f037 100644 (file)
 #include <linux/slab.h>
 #include <linux/pci.h>
 #include <linux/gpio.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+
+#define IOH_EDGE_FALLING       0
+#define IOH_EDGE_RISING                BIT(0)
+#define IOH_LEVEL_L            BIT(1)
+#define IOH_LEVEL_H            (BIT(0) | BIT(1))
+#define IOH_EDGE_BOTH          BIT(2)
+#define IOH_IM_MASK            (BIT(0) | BIT(1) | BIT(2))
+
+#define IOH_IRQ_BASE           0
 
 #define PCI_VENDOR_ID_ROHM             0x10DB
 
@@ -46,12 +57,22 @@ struct ioh_regs {
 
 /**
  * struct ioh_gpio_reg_data - The register store data.
+ * @ien_reg    To store contents of interrupt enable register.
+ * @imask_reg: To store contents of interrupt mask regist
  * @po_reg:    To store contents of PO register.
  * @pm_reg:    To store contents of PM register.
+ * @im0_reg:   To store contents of interrupt mode regist0
+ * @im1_reg:   To store contents of interrupt mode regist1
+ * @use_sel_reg: To store contents of GPIO_USE_SEL0~3
  */
 struct ioh_gpio_reg_data {
+       u32 ien_reg;
+       u32 imask_reg;
        u32 po_reg;
        u32 pm_reg;
+       u32 im0_reg;
+       u32 im1_reg;
+       u32 use_sel_reg;
 };
 
 /**
@@ -62,7 +83,11 @@ struct ioh_gpio_reg_data {
  * @gpio:                      Data for GPIO infrastructure.
  * @ioh_gpio_reg:              Memory mapped Register data is saved here
  *                             when suspend.
+ * @gpio_use_sel:              Save GPIO_USE_SEL1~4 register for PM
  * @ch:                                Indicate GPIO channel
+ * @irq_base:          Save base of IRQ number for interrupt
+ * @spinlock:          Used for register access protection in
+ *                             interrupt context ioh_irq_type and PM;
  */
 struct ioh_gpio {
        void __iomem *base;
@@ -70,8 +95,11 @@ struct ioh_gpio {
        struct device *dev;
        struct gpio_chip gpio;
        struct ioh_gpio_reg_data ioh_gpio_reg;
+       u32 gpio_use_sel;
        struct mutex lock;
        int ch;
+       int irq_base;
+       spinlock_t spinlock;
 };
 
 static const int num_ports[] = {6, 12, 16, 16, 15, 16, 16, 12};
@@ -145,8 +173,25 @@ static int ioh_gpio_direction_input(struct gpio_chip *gpio, unsigned nr)
  */
 static void ioh_gpio_save_reg_conf(struct ioh_gpio *chip)
 {
-       chip->ioh_gpio_reg.po_reg = ioread32(&chip->reg->regs[chip->ch].po);
-       chip->ioh_gpio_reg.pm_reg = ioread32(&chip->reg->regs[chip->ch].pm);
+       int i;
+
+       for (i = 0; i < 8; i ++, chip++) {
+               chip->ioh_gpio_reg.po_reg =
+                                       ioread32(&chip->reg->regs[chip->ch].po);
+               chip->ioh_gpio_reg.pm_reg =
+                                       ioread32(&chip->reg->regs[chip->ch].pm);
+               chip->ioh_gpio_reg.ien_reg =
+                                      ioread32(&chip->reg->regs[chip->ch].ien);
+               chip->ioh_gpio_reg.imask_reg =
+                                    ioread32(&chip->reg->regs[chip->ch].imask);
+               chip->ioh_gpio_reg.im0_reg =
+                                     ioread32(&chip->reg->regs[chip->ch].im_0);
+               chip->ioh_gpio_reg.im1_reg =
+                                     ioread32(&chip->reg->regs[chip->ch].im_1);
+               if (i < 4)
+                       chip->ioh_gpio_reg.use_sel_reg =
+                                          ioread32(&chip->reg->ioh_sel_reg[i]);
+       }
 }
 
 /*
@@ -154,13 +199,34 @@ static void ioh_gpio_save_reg_conf(struct ioh_gpio *chip)
  */
 static void ioh_gpio_restore_reg_conf(struct ioh_gpio *chip)
 {
-       /* to store contents of PO register */
-       iowrite32(chip->ioh_gpio_reg.po_reg, &chip->reg->regs[chip->ch].po);
-       /* to store contents of PM register */
-       iowrite32(chip->ioh_gpio_reg.pm_reg, &chip->reg->regs[chip->ch].pm);
+       int i;
+
+       for (i = 0; i < 8; i ++, chip++) {
+               iowrite32(chip->ioh_gpio_reg.po_reg,
+                         &chip->reg->regs[chip->ch].po);
+               iowrite32(chip->ioh_gpio_reg.pm_reg,
+                         &chip->reg->regs[chip->ch].pm);
+               iowrite32(chip->ioh_gpio_reg.ien_reg,
+                         &chip->reg->regs[chip->ch].ien);
+               iowrite32(chip->ioh_gpio_reg.imask_reg,
+                         &chip->reg->regs[chip->ch].imask);
+               iowrite32(chip->ioh_gpio_reg.im0_reg,
+                         &chip->reg->regs[chip->ch].im_0);
+               iowrite32(chip->ioh_gpio_reg.im1_reg,
+                         &chip->reg->regs[chip->ch].im_1);
+               if (i < 4)
+                       iowrite32(chip->ioh_gpio_reg.use_sel_reg,
+                                 &chip->reg->ioh_sel_reg[i]);
+       }
 }
 #endif
 
+static int ioh_gpio_to_irq(struct gpio_chip *gpio, unsigned offset)
+{
+       struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio);
+       return chip->irq_base + offset;
+}
+
 static void ioh_gpio_setup(struct ioh_gpio *chip, int num_port)
 {
        struct gpio_chip *gpio = &chip->gpio;
@@ -175,16 +241,148 @@ static void ioh_gpio_setup(struct ioh_gpio *chip, int num_port)
        gpio->base = -1;
        gpio->ngpio = num_port;
        gpio->can_sleep = 0;
+       gpio->to_irq = ioh_gpio_to_irq;
+}
+
+static int ioh_irq_type(struct irq_data *d, unsigned int type)
+{
+       u32 im;
+       u32 *im_reg;
+       u32 ien;
+       u32 im_pos;
+       int ch;
+       unsigned long flags;
+       u32 val;
+       int irq = d->irq;
+       struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
+       struct ioh_gpio *chip = gc->private;
+
+       ch = irq - chip->irq_base;
+       if (irq <= chip->irq_base + 7) {
+               im_reg = &chip->reg->regs[chip->ch].im_0;
+               im_pos = ch;
+       } else {
+               im_reg = &chip->reg->regs[chip->ch].im_1;
+               im_pos = ch - 8;
+       }
+       dev_dbg(chip->dev, "%s:irq=%d type=%d ch=%d pos=%d type=%d\n",
+               __func__, irq, type, ch, im_pos, type);
+
+       spin_lock_irqsave(&chip->spinlock, flags);
+
+       switch (type) {
+       case IRQ_TYPE_EDGE_RISING:
+               val = IOH_EDGE_RISING;
+               break;
+       case IRQ_TYPE_EDGE_FALLING:
+               val = IOH_EDGE_FALLING;
+               break;
+       case IRQ_TYPE_EDGE_BOTH:
+               val = IOH_EDGE_BOTH;
+               break;
+       case IRQ_TYPE_LEVEL_HIGH:
+               val = IOH_LEVEL_H;
+               break;
+       case IRQ_TYPE_LEVEL_LOW:
+               val = IOH_LEVEL_L;
+               break;
+       case IRQ_TYPE_PROBE:
+               goto end;
+       default:
+               dev_warn(chip->dev, "%s: unknown type(%dd)",
+                       __func__, type);
+               goto end;
+       }
+
+       /* Set interrupt mode */
+       im = ioread32(im_reg) & ~(IOH_IM_MASK << (im_pos * 4));
+       iowrite32(im | (val << (im_pos * 4)), im_reg);
+
+       /* iclr */
+       iowrite32(BIT(ch), &chip->reg->regs[chip->ch].iclr);
+
+       /* IMASKCLR */
+       iowrite32(BIT(ch), &chip->reg->regs[chip->ch].imaskclr);
+
+       /* Enable interrupt */
+       ien = ioread32(&chip->reg->regs[chip->ch].ien);
+       iowrite32(ien | BIT(ch), &chip->reg->regs[chip->ch].ien);
+end:
+       spin_unlock_irqrestore(&chip->spinlock, flags);
+
+       return 0;
+}
+
+static void ioh_irq_unmask(struct irq_data *d)
+{
+       struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
+       struct ioh_gpio *chip = gc->private;
+
+       iowrite32(1 << (d->irq - chip->irq_base),
+                 &chip->reg->regs[chip->ch].imaskclr);
+}
+
+static void ioh_irq_mask(struct irq_data *d)
+{
+       struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
+       struct ioh_gpio *chip = gc->private;
+
+       iowrite32(1 << (d->irq - chip->irq_base),
+                 &chip->reg->regs[chip->ch].imask);
+}
+
+static irqreturn_t ioh_gpio_handler(int irq, void *dev_id)
+{
+       struct ioh_gpio *chip = dev_id;
+       u32 reg_val;
+       int i, j;
+       int ret = IRQ_NONE;
+
+       for (i = 0; i < 8; i++) {
+               reg_val = ioread32(&chip->reg->regs[i].istatus);
+               for (j = 0; j < num_ports[i]; j++) {
+                       if (reg_val & BIT(j)) {
+                               dev_dbg(chip->dev,
+                                       "%s:[%d]:irq=%d status=0x%x\n",
+                                       __func__, j, irq, reg_val);
+                               iowrite32(BIT(j),
+                                         &chip->reg->regs[chip->ch].iclr);
+                               generic_handle_irq(chip->irq_base + j);
+                               ret = IRQ_HANDLED;
+                       }
+               }
+       }
+       return ret;
+}
+
+static __devinit void ioh_gpio_alloc_generic_chip(struct ioh_gpio *chip,
+                               unsigned int irq_start, unsigned int num)
+{
+       struct irq_chip_generic *gc;
+       struct irq_chip_type *ct;
+
+       gc = irq_alloc_generic_chip("ioh_gpio", 1, irq_start, chip->base,
+                                   handle_simple_irq);
+       gc->private = chip;
+       ct = gc->chip_types;
+
+       ct->chip.irq_mask = ioh_irq_mask;
+       ct->chip.irq_unmask = ioh_irq_unmask;
+       ct->chip.irq_set_type = ioh_irq_type;
+
+       irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE,
+                              IRQ_NOREQUEST | IRQ_NOPROBE, 0);
 }
 
 static int __devinit ioh_gpio_probe(struct pci_dev *pdev,
                                    const struct pci_device_id *id)
 {
        int ret;
-       int i;
+       int i, j;
        struct ioh_gpio *chip;
        void __iomem *base;
        void __iomem *chip_save;
+       int irq_base;
 
        ret = pci_enable_device(pdev);
        if (ret) {
@@ -228,10 +426,41 @@ static int __devinit ioh_gpio_probe(struct pci_dev *pdev,
        }
 
        chip = chip_save;
+       for (j = 0; j < 8; j++, chip++) {
+               irq_base = irq_alloc_descs(-1, IOH_IRQ_BASE, num_ports[j],
+                                          NUMA_NO_NODE);
+               if (irq_base < 0) {
+                       dev_warn(&pdev->dev,
+                               "ml_ioh_gpio: Failed to get IRQ base num\n");
+                       chip->irq_base = -1;
+                       goto err_irq_alloc_descs;
+               }
+               chip->irq_base = irq_base;
+               ioh_gpio_alloc_generic_chip(chip, irq_base, num_ports[j]);
+       }
+
+       chip = chip_save;
+       ret = request_irq(pdev->irq, ioh_gpio_handler,
+                            IRQF_SHARED, KBUILD_MODNAME, chip);
+       if (ret != 0) {
+               dev_err(&pdev->dev,
+                       "%s request_irq failed\n", __func__);
+               goto err_request_irq;
+       }
+
        pci_set_drvdata(pdev, chip);
 
        return 0;
 
+err_request_irq:
+       chip = chip_save;
+err_irq_alloc_descs:
+       while (--j >= 0) {
+               chip--;
+               irq_free_descs(chip->irq_base, num_ports[j]);
+       }
+
+       chip = chip_save;
 err_gpiochip_add:
        while (--i >= 0) {
                chip--;
@@ -264,7 +493,11 @@ static void __devexit ioh_gpio_remove(struct pci_dev *pdev)
        void __iomem *chip_save;
 
        chip_save = chip;
+
+       free_irq(pdev->irq, chip);
+
        for (i = 0; i < 8; i++, chip++) {
+               irq_free_descs(chip->irq_base, num_ports[i]);
                err = gpiochip_remove(&chip->gpio);
                if (err)
                        dev_err(&pdev->dev, "Failed gpiochip_remove\n");
@@ -282,9 +515,11 @@ static int ioh_gpio_suspend(struct pci_dev *pdev, pm_message_t state)
 {
        s32 ret;
        struct ioh_gpio *chip = pci_get_drvdata(pdev);
+       unsigned long flags;
 
+       spin_lock_irqsave(&chip->spinlock, flags);
        ioh_gpio_save_reg_conf(chip);
-       ioh_gpio_restore_reg_conf(chip);
+       spin_unlock_irqrestore(&chip->spinlock, flags);
 
        ret = pci_save_state(pdev);
        if (ret) {
@@ -304,6 +539,7 @@ static int ioh_gpio_resume(struct pci_dev *pdev)
 {
        s32 ret;
        struct ioh_gpio *chip = pci_get_drvdata(pdev);
+       unsigned long flags;
 
        ret = pci_enable_wake(pdev, PCI_D0, 0);
 
@@ -315,9 +551,11 @@ static int ioh_gpio_resume(struct pci_dev *pdev)
        }
        pci_restore_state(pdev);
 
+       spin_lock_irqsave(&chip->spinlock, flags);
        iowrite32(0x01, &chip->reg->srst);
        iowrite32(0x00, &chip->reg->srst);
        ioh_gpio_restore_reg_conf(chip);
+       spin_unlock_irqrestore(&chip->spinlock, flags);
 
        return 0;
 }
index 4340acae3bd3791d713b61022c13d8ed13ed4718..82f7b65baf7216a337b44ba46af2a956cde6cdb8 100644 (file)
@@ -30,6 +30,7 @@
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <asm-generic/bug.h>
+#include <asm/mach/irq.h>
 
 enum mxc_gpio_hwtype {
        IMX1_GPIO,      /* runs on i.mx1 */
@@ -232,10 +233,15 @@ static void mx3_gpio_irq_handler(u32 irq, struct irq_desc *desc)
 {
        u32 irq_stat;
        struct mxc_gpio_port *port = irq_get_handler_data(irq);
+       struct irq_chip *chip = irq_get_chip(irq);
+
+       chained_irq_enter(chip, desc);
 
        irq_stat = readl(port->base + GPIO_ISR) & readl(port->base + GPIO_IMR);
 
        mxc_gpio_irq_handler(port, irq_stat);
+
+       chained_irq_exit(chip, desc);
 }
 
 /* MX2 has one interrupt *for all* gpio ports */
index 740caed2b278bc4defd03dccb5444885ec6804d2..1ebedfb6d46dba7cb7c30e2a9400f6400e8b9159 100644 (file)
@@ -59,7 +59,6 @@ struct nmk_gpio_chip {
        u32 rwimsc;
        u32 fwimsc;
        u32 slpm;
-       u32 enabled;
        u32 pull_up;
 };
 
@@ -277,6 +276,8 @@ static void nmk_gpio_glitch_slpm_init(unsigned int *slpm)
                if (!chip)
                        break;
 
+               clk_enable(chip->clk);
+
                slpm[i] = readl(chip->addr + NMK_GPIO_SLPC);
                writel(temp, chip->addr + NMK_GPIO_SLPC);
        }
@@ -293,6 +294,8 @@ static void nmk_gpio_glitch_slpm_restore(unsigned int *slpm)
                        break;
 
                writel(slpm[i], chip->addr + NMK_GPIO_SLPC);
+
+               clk_disable(chip->clk);
        }
 }
 
@@ -337,10 +340,12 @@ static int __nmk_config_pins(pin_cfg_t *cfgs, int num, bool sleep)
                        break;
                }
 
+               clk_enable(nmk_chip->clk);
                spin_lock(&nmk_chip->lock);
                __nmk_config_pin(nmk_chip, pin - nmk_chip->chip.base,
                                 cfgs[i], sleep, glitch ? slpm : NULL);
                spin_unlock(&nmk_chip->lock);
+               clk_disable(nmk_chip->clk);
        }
 
        if (glitch)
@@ -425,6 +430,7 @@ int nmk_gpio_set_slpm(int gpio, enum nmk_gpio_slpm mode)
        if (!nmk_chip)
                return -EINVAL;
 
+       clk_enable(nmk_chip->clk);
        spin_lock_irqsave(&nmk_gpio_slpm_lock, flags);
        spin_lock(&nmk_chip->lock);
 
@@ -432,6 +438,7 @@ int nmk_gpio_set_slpm(int gpio, enum nmk_gpio_slpm mode)
 
        spin_unlock(&nmk_chip->lock);
        spin_unlock_irqrestore(&nmk_gpio_slpm_lock, flags);
+       clk_disable(nmk_chip->clk);
 
        return 0;
 }
@@ -458,9 +465,11 @@ int nmk_gpio_set_pull(int gpio, enum nmk_gpio_pull pull)
        if (!nmk_chip)
                return -EINVAL;
 
+       clk_enable(nmk_chip->clk);
        spin_lock_irqsave(&nmk_chip->lock, flags);
        __nmk_gpio_set_pull(nmk_chip, gpio - nmk_chip->chip.base, pull);
        spin_unlock_irqrestore(&nmk_chip->lock, flags);
+       clk_disable(nmk_chip->clk);
 
        return 0;
 }
@@ -484,9 +493,11 @@ int nmk_gpio_set_mode(int gpio, int gpio_mode)
        if (!nmk_chip)
                return -EINVAL;
 
+       clk_enable(nmk_chip->clk);
        spin_lock_irqsave(&nmk_chip->lock, flags);
        __nmk_gpio_set_mode(nmk_chip, gpio - nmk_chip->chip.base, gpio_mode);
        spin_unlock_irqrestore(&nmk_chip->lock, flags);
+       clk_disable(nmk_chip->clk);
 
        return 0;
 }
@@ -503,9 +514,13 @@ int nmk_gpio_get_mode(int gpio)
 
        bit = 1 << (gpio - nmk_chip->chip.base);
 
+       clk_enable(nmk_chip->clk);
+
        afunc = readl(nmk_chip->addr + NMK_GPIO_AFSLA) & bit;
        bfunc = readl(nmk_chip->addr + NMK_GPIO_AFSLB) & bit;
 
+       clk_disable(nmk_chip->clk);
+
        return (afunc ? NMK_GPIO_ALT_A : 0) | (bfunc ? NMK_GPIO_ALT_B : 0);
 }
 EXPORT_SYMBOL(nmk_gpio_get_mode);
@@ -526,7 +541,10 @@ static void nmk_gpio_irq_ack(struct irq_data *d)
        nmk_chip = irq_data_get_irq_chip_data(d);
        if (!nmk_chip)
                return;
+
+       clk_enable(nmk_chip->clk);
        writel(nmk_gpio_get_bitmask(gpio), nmk_chip->addr + NMK_GPIO_IC);
+       clk_disable(nmk_chip->clk);
 }
 
 enum nmk_gpio_irq_type {
@@ -587,11 +605,7 @@ static int nmk_gpio_irq_maskunmask(struct irq_data *d, bool enable)
        if (!nmk_chip)
                return -EINVAL;
 
-       if (enable)
-               nmk_chip->enabled |= bitmask;
-       else
-               nmk_chip->enabled &= ~bitmask;
-
+       clk_enable(nmk_chip->clk);
        spin_lock_irqsave(&nmk_gpio_slpm_lock, flags);
        spin_lock(&nmk_chip->lock);
 
@@ -602,6 +616,7 @@ static int nmk_gpio_irq_maskunmask(struct irq_data *d, bool enable)
 
        spin_unlock(&nmk_chip->lock);
        spin_unlock_irqrestore(&nmk_gpio_slpm_lock, flags);
+       clk_disable(nmk_chip->clk);
 
        return 0;
 }
@@ -629,10 +644,11 @@ static int nmk_gpio_irq_set_wake(struct irq_data *d, unsigned int on)
                return -EINVAL;
        bitmask = nmk_gpio_get_bitmask(gpio);
 
+       clk_enable(nmk_chip->clk);
        spin_lock_irqsave(&nmk_gpio_slpm_lock, flags);
        spin_lock(&nmk_chip->lock);
 
-       if (!(nmk_chip->enabled & bitmask))
+       if (irqd_irq_disabled(d))
                __nmk_gpio_set_wake(nmk_chip, gpio, on);
 
        if (on)
@@ -642,13 +658,15 @@ static int nmk_gpio_irq_set_wake(struct irq_data *d, unsigned int on)
 
        spin_unlock(&nmk_chip->lock);
        spin_unlock_irqrestore(&nmk_gpio_slpm_lock, flags);
+       clk_disable(nmk_chip->clk);
 
        return 0;
 }
 
 static int nmk_gpio_irq_set_type(struct irq_data *d, unsigned int type)
 {
-       bool enabled, wake = irqd_is_wakeup_set(d);
+       bool enabled = !irqd_irq_disabled(d);
+       bool wake = irqd_is_wakeup_set(d);
        int gpio;
        struct nmk_gpio_chip *nmk_chip;
        unsigned long flags;
@@ -665,8 +683,7 @@ static int nmk_gpio_irq_set_type(struct irq_data *d, unsigned int type)
        if (type & IRQ_TYPE_LEVEL_LOW)
                return -EINVAL;
 
-       enabled = nmk_chip->enabled & bitmask;
-
+       clk_enable(nmk_chip->clk);
        spin_lock_irqsave(&nmk_chip->lock, flags);
 
        if (enabled)
@@ -690,10 +707,28 @@ static int nmk_gpio_irq_set_type(struct irq_data *d, unsigned int type)
                __nmk_gpio_irq_modify(nmk_chip, gpio, WAKE, true);
 
        spin_unlock_irqrestore(&nmk_chip->lock, flags);
+       clk_disable(nmk_chip->clk);
 
        return 0;
 }
 
+static unsigned int nmk_gpio_irq_startup(struct irq_data *d)
+{
+       struct nmk_gpio_chip *nmk_chip = irq_data_get_irq_chip_data(d);
+
+       clk_enable(nmk_chip->clk);
+       nmk_gpio_irq_unmask(d);
+       return 0;
+}
+
+static void nmk_gpio_irq_shutdown(struct irq_data *d)
+{
+       struct nmk_gpio_chip *nmk_chip = irq_data_get_irq_chip_data(d);
+
+       nmk_gpio_irq_mask(d);
+       clk_disable(nmk_chip->clk);
+}
+
 static struct irq_chip nmk_gpio_irq_chip = {
        .name           = "Nomadik-GPIO",
        .irq_ack        = nmk_gpio_irq_ack,
@@ -701,6 +736,8 @@ static struct irq_chip nmk_gpio_irq_chip = {
        .irq_unmask     = nmk_gpio_irq_unmask,
        .irq_set_type   = nmk_gpio_irq_set_type,
        .irq_set_wake   = nmk_gpio_irq_set_wake,
+       .irq_startup    = nmk_gpio_irq_startup,
+       .irq_shutdown   = nmk_gpio_irq_shutdown,
 };
 
 static void __nmk_gpio_irq_handler(unsigned int irq, struct irq_desc *desc,
@@ -727,7 +764,11 @@ static void __nmk_gpio_irq_handler(unsigned int irq, struct irq_desc *desc,
 static void nmk_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
 {
        struct nmk_gpio_chip *nmk_chip = irq_get_handler_data(irq);
-       u32 status = readl(nmk_chip->addr + NMK_GPIO_IS);
+       u32 status;
+
+       clk_enable(nmk_chip->clk);
+       status = readl(nmk_chip->addr + NMK_GPIO_IS);
+       clk_disable(nmk_chip->clk);
 
        __nmk_gpio_irq_handler(irq, desc, status);
 }
@@ -773,7 +814,12 @@ static int nmk_gpio_make_input(struct gpio_chip *chip, unsigned offset)
        struct nmk_gpio_chip *nmk_chip =
                container_of(chip, struct nmk_gpio_chip, chip);
 
+       clk_enable(nmk_chip->clk);
+
        writel(1 << offset, nmk_chip->addr + NMK_GPIO_DIRC);
+
+       clk_disable(nmk_chip->clk);
+
        return 0;
 }
 
@@ -782,8 +828,15 @@ static int nmk_gpio_get_input(struct gpio_chip *chip, unsigned offset)
        struct nmk_gpio_chip *nmk_chip =
                container_of(chip, struct nmk_gpio_chip, chip);
        u32 bit = 1 << offset;
+       int value;
+
+       clk_enable(nmk_chip->clk);
 
-       return (readl(nmk_chip->addr + NMK_GPIO_DAT) & bit) != 0;
+       value = (readl(nmk_chip->addr + NMK_GPIO_DAT) & bit) != 0;
+
+       clk_disable(nmk_chip->clk);
+
+       return value;
 }
 
 static void nmk_gpio_set_output(struct gpio_chip *chip, unsigned offset,
@@ -792,7 +845,11 @@ static void nmk_gpio_set_output(struct gpio_chip *chip, unsigned offset,
        struct nmk_gpio_chip *nmk_chip =
                container_of(chip, struct nmk_gpio_chip, chip);
 
+       clk_enable(nmk_chip->clk);
+
        __nmk_gpio_set_output(nmk_chip, offset, val);
+
+       clk_disable(nmk_chip->clk);
 }
 
 static int nmk_gpio_make_output(struct gpio_chip *chip, unsigned offset,
@@ -801,8 +858,12 @@ static int nmk_gpio_make_output(struct gpio_chip *chip, unsigned offset,
        struct nmk_gpio_chip *nmk_chip =
                container_of(chip, struct nmk_gpio_chip, chip);
 
+       clk_enable(nmk_chip->clk);
+
        __nmk_gpio_make_output(nmk_chip, offset, val);
 
+       clk_disable(nmk_chip->clk);
+
        return 0;
 }
 
@@ -833,6 +894,8 @@ static void nmk_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
                [NMK_GPIO_ALT_C]        = "altC",
        };
 
+       clk_enable(nmk_chip->clk);
+
        for (i = 0; i < chip->ngpio; i++, gpio++) {
                const char *label = gpiochip_is_requested(chip, i);
                bool pull;
@@ -877,6 +940,8 @@ static void nmk_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
 
                seq_printf(s, "\n");
        }
+
+       clk_disable(nmk_chip->clk);
 }
 
 #else
@@ -894,6 +959,34 @@ static struct gpio_chip nmk_gpio_template = {
        .can_sleep              = 0,
 };
 
+void nmk_gpio_clocks_enable(void)
+{
+       int i;
+
+       for (i = 0; i < NUM_BANKS; i++) {
+               struct nmk_gpio_chip *chip = nmk_gpio_chips[i];
+
+               if (!chip)
+                       continue;
+
+               clk_enable(chip->clk);
+       }
+}
+
+void nmk_gpio_clocks_disable(void)
+{
+       int i;
+
+       for (i = 0; i < NUM_BANKS; i++) {
+               struct nmk_gpio_chip *chip = nmk_gpio_chips[i];
+
+               if (!chip)
+                       continue;
+
+               clk_disable(chip->clk);
+       }
+}
+
 /*
  * Called from the suspend/resume path to only keep the real wakeup interrupts
  * (those that have had set_irq_wake() called on them) as wakeup interrupts,
@@ -913,6 +1006,8 @@ void nmk_gpio_wakeups_suspend(void)
                if (!chip)
                        break;
 
+               clk_enable(chip->clk);
+
                chip->rwimsc = readl(chip->addr + NMK_GPIO_RWIMSC);
                chip->fwimsc = readl(chip->addr + NMK_GPIO_FWIMSC);
 
@@ -927,6 +1022,8 @@ void nmk_gpio_wakeups_suspend(void)
                        /* 0 -> wakeup enable */
                        writel(~chip->real_wake, chip->addr + NMK_GPIO_SLPC);
                }
+
+               clk_disable(chip->clk);
        }
 }
 
@@ -940,11 +1037,15 @@ void nmk_gpio_wakeups_resume(void)
                if (!chip)
                        break;
 
+               clk_enable(chip->clk);
+
                writel(chip->rwimsc, chip->addr + NMK_GPIO_RWIMSC);
                writel(chip->fwimsc, chip->addr + NMK_GPIO_FWIMSC);
 
                if (chip->sleepmode)
                        writel(chip->slpm, chip->addr + NMK_GPIO_SLPC);
+
+               clk_disable(chip->clk);
        }
 }
 
@@ -1011,8 +1112,6 @@ static int __devinit nmk_gpio_probe(struct platform_device *dev)
                goto out_release;
        }
 
-       clk_enable(clk);
-
        nmk_chip = kzalloc(sizeof(*nmk_chip), GFP_KERNEL);
        if (!nmk_chip) {
                ret = -ENOMEM;
index 36919e77c495cb97c3ae3a5896a6d7dabdce38df..1e8a4a5388108b756e132203d11115401d7f58c8 100644 (file)
 #include <linux/kernel.h>
 #include <linux/pci.h>
 #include <linux/gpio.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
 
-#define PCH_GPIO_ALL_PINS      0xfff /* Mask for GPIO pins 0 to 11 */
-#define GPIO_NUM_PINS  12      /* Specifies number of GPIO PINS GPIO0-GPIO11 */
+#define PCH_EDGE_FALLING       0
+#define PCH_EDGE_RISING                BIT(0)
+#define PCH_LEVEL_L            BIT(1)
+#define PCH_LEVEL_H            (BIT(0) | BIT(1))
+#define PCH_EDGE_BOTH          BIT(2)
+#define PCH_IM_MASK            (BIT(0) | BIT(1) | BIT(2))
+
+#define PCH_IRQ_BASE           24
 
 struct pch_regs {
        u32     ien;
@@ -33,18 +41,43 @@ struct pch_regs {
        u32     pm;
        u32     im0;
        u32     im1;
-       u32     reserved[4];
+       u32     reserved[3];
+       u32     gpio_use_sel;
        u32     reset;
 };
 
+enum pch_type_t {
+       INTEL_EG20T_PCH,
+       OKISEMI_ML7223m_IOH, /* OKISEMI ML7223 IOH PCIe Bus-m */
+       OKISEMI_ML7223n_IOH  /* OKISEMI ML7223 IOH PCIe Bus-n */
+};
+
+/* Specifies number of GPIO PINS */
+static int gpio_pins[] = {
+       [INTEL_EG20T_PCH] = 12,
+       [OKISEMI_ML7223m_IOH] = 8,
+       [OKISEMI_ML7223n_IOH] = 8,
+};
+
 /**
  * struct pch_gpio_reg_data - The register store data.
+ * @ien_reg:   To store contents of IEN register.
+ * @imask_reg: To store contents of IMASK register.
  * @po_reg:    To store contents of PO register.
  * @pm_reg:    To store contents of PM register.
+ * @im0_reg:   To store contents of IM0 register.
+ * @im1_reg:   To store contents of IM1 register.
+ * @gpio_use_sel_reg : To store contents of GPIO_USE_SEL register.
+ *                    (Only ML7223 Bus-n)
  */
 struct pch_gpio_reg_data {
+       u32 ien_reg;
+       u32 imask_reg;
        u32 po_reg;
        u32 pm_reg;
+       u32 im0_reg;
+       u32 im1_reg;
+       u32 gpio_use_sel_reg;
 };
 
 /**
@@ -55,6 +88,12 @@ struct pch_gpio_reg_data {
  * @gpio:                      Data for GPIO infrastructure.
  * @pch_gpio_reg:              Memory mapped Register data is saved here
  *                             when suspend.
+ * @lock:                      Used for register access protection
+ * @irq_base:          Save base of IRQ number for interrupt
+ * @ioh:               IOH ID
+ * @spinlock:          Used for register access protection in
+ *                             interrupt context pch_irq_mask,
+ *                             pch_irq_unmask and pch_irq_type;
  */
 struct pch_gpio {
        void __iomem *base;
@@ -63,6 +102,9 @@ struct pch_gpio {
        struct gpio_chip gpio;
        struct pch_gpio_reg_data pch_gpio_reg;
        struct mutex lock;
+       int irq_base;
+       enum pch_type_t ioh;
+       spinlock_t spinlock;
 };
 
 static void pch_gpio_set(struct gpio_chip *gpio, unsigned nr, int val)
@@ -96,7 +138,7 @@ static int pch_gpio_direction_output(struct gpio_chip *gpio, unsigned nr,
        u32 reg_val;
 
        mutex_lock(&chip->lock);
-       pm = ioread32(&chip->reg->pm) & PCH_GPIO_ALL_PINS;
+       pm = ioread32(&chip->reg->pm) & ((1 << gpio_pins[chip->ioh]) - 1);
        pm |= (1 << nr);
        iowrite32(pm, &chip->reg->pm);
 
@@ -118,7 +160,7 @@ static int pch_gpio_direction_input(struct gpio_chip *gpio, unsigned nr)
        u32 pm;
 
        mutex_lock(&chip->lock);
-       pm = ioread32(&chip->reg->pm) & PCH_GPIO_ALL_PINS; /*bits 0-11*/
+       pm = ioread32(&chip->reg->pm) & ((1 << gpio_pins[chip->ioh]) - 1);
        pm &= ~(1 << nr);
        iowrite32(pm, &chip->reg->pm);
        mutex_unlock(&chip->lock);
@@ -131,8 +173,16 @@ static int pch_gpio_direction_input(struct gpio_chip *gpio, unsigned nr)
  */
 static void pch_gpio_save_reg_conf(struct pch_gpio *chip)
 {
+       chip->pch_gpio_reg.ien_reg = ioread32(&chip->reg->ien);
+       chip->pch_gpio_reg.imask_reg = ioread32(&chip->reg->imask);
        chip->pch_gpio_reg.po_reg = ioread32(&chip->reg->po);
        chip->pch_gpio_reg.pm_reg = ioread32(&chip->reg->pm);
+       chip->pch_gpio_reg.im0_reg = ioread32(&chip->reg->im0);
+       if (chip->ioh == INTEL_EG20T_PCH)
+               chip->pch_gpio_reg.im1_reg = ioread32(&chip->reg->im1);
+       if (chip->ioh == OKISEMI_ML7223n_IOH)
+               chip->pch_gpio_reg.gpio_use_sel_reg =\
+                                           ioread32(&chip->reg->gpio_use_sel);
 }
 
 /*
@@ -140,10 +190,24 @@ static void pch_gpio_save_reg_conf(struct pch_gpio *chip)
  */
 static void pch_gpio_restore_reg_conf(struct pch_gpio *chip)
 {
+       iowrite32(chip->pch_gpio_reg.ien_reg, &chip->reg->ien);
+       iowrite32(chip->pch_gpio_reg.imask_reg, &chip->reg->imask);
        /* to store contents of PO register */
        iowrite32(chip->pch_gpio_reg.po_reg, &chip->reg->po);
        /* to store contents of PM register */
        iowrite32(chip->pch_gpio_reg.pm_reg, &chip->reg->pm);
+       iowrite32(chip->pch_gpio_reg.im0_reg, &chip->reg->im0);
+       if (chip->ioh == INTEL_EG20T_PCH)
+               iowrite32(chip->pch_gpio_reg.im1_reg, &chip->reg->im1);
+       if (chip->ioh == OKISEMI_ML7223n_IOH)
+               iowrite32(chip->pch_gpio_reg.gpio_use_sel_reg,
+                         &chip->reg->gpio_use_sel);
+}
+
+static int pch_gpio_to_irq(struct gpio_chip *gpio, unsigned offset)
+{
+       struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio);
+       return chip->irq_base + offset;
 }
 
 static void pch_gpio_setup(struct pch_gpio *chip)
@@ -158,8 +222,132 @@ static void pch_gpio_setup(struct pch_gpio *chip)
        gpio->set = pch_gpio_set;
        gpio->dbg_show = NULL;
        gpio->base = -1;
-       gpio->ngpio = GPIO_NUM_PINS;
+       gpio->ngpio = gpio_pins[chip->ioh];
        gpio->can_sleep = 0;
+       gpio->to_irq = pch_gpio_to_irq;
+}
+
+static int pch_irq_type(struct irq_data *d, unsigned int type)
+{
+       u32 im;
+       u32 *im_reg;
+       u32 ien;
+       u32 im_pos;
+       int ch;
+       unsigned long flags;
+       u32 val;
+       int irq = d->irq;
+       struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
+       struct pch_gpio *chip = gc->private;
+
+       ch = irq - chip->irq_base;
+       if (irq <= chip->irq_base + 7) {
+               im_reg = &chip->reg->im0;
+               im_pos = ch;
+       } else {
+               im_reg = &chip->reg->im1;
+               im_pos = ch - 8;
+       }
+       dev_dbg(chip->dev, "%s:irq=%d type=%d ch=%d pos=%d\n",
+               __func__, irq, type, ch, im_pos);
+
+       spin_lock_irqsave(&chip->spinlock, flags);
+
+       switch (type) {
+       case IRQ_TYPE_EDGE_RISING:
+               val = PCH_EDGE_RISING;
+               break;
+       case IRQ_TYPE_EDGE_FALLING:
+               val = PCH_EDGE_FALLING;
+               break;
+       case IRQ_TYPE_EDGE_BOTH:
+               val = PCH_EDGE_BOTH;
+               break;
+       case IRQ_TYPE_LEVEL_HIGH:
+               val = PCH_LEVEL_H;
+               break;
+       case IRQ_TYPE_LEVEL_LOW:
+               val = PCH_LEVEL_L;
+               break;
+       case IRQ_TYPE_PROBE:
+               goto end;
+       default:
+               dev_warn(chip->dev, "%s: unknown type(%dd)",
+                       __func__, type);
+               goto end;
+       }
+
+       /* Set interrupt mode */
+       im = ioread32(im_reg) & ~(PCH_IM_MASK << (im_pos * 4));
+       iowrite32(im | (val << (im_pos * 4)), im_reg);
+
+       /* iclr */
+       iowrite32(BIT(ch), &chip->reg->iclr);
+
+       /* IMASKCLR */
+       iowrite32(BIT(ch), &chip->reg->imaskclr);
+
+       /* Enable interrupt */
+       ien = ioread32(&chip->reg->ien);
+       iowrite32(ien | BIT(ch), &chip->reg->ien);
+end:
+       spin_unlock_irqrestore(&chip->spinlock, flags);
+
+       return 0;
+}
+
+static void pch_irq_unmask(struct irq_data *d)
+{
+       struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
+       struct pch_gpio *chip = gc->private;
+
+       iowrite32(1 << (d->irq - chip->irq_base), &chip->reg->imaskclr);
+}
+
+static void pch_irq_mask(struct irq_data *d)
+{
+       struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
+       struct pch_gpio *chip = gc->private;
+
+       iowrite32(1 << (d->irq - chip->irq_base), &chip->reg->imask);
+}
+
+static irqreturn_t pch_gpio_handler(int irq, void *dev_id)
+{
+       struct pch_gpio *chip = dev_id;
+       u32 reg_val = ioread32(&chip->reg->istatus);
+       int i;
+       int ret = IRQ_NONE;
+
+       for (i = 0; i < gpio_pins[chip->ioh]; i++) {
+               if (reg_val & BIT(i)) {
+                       dev_dbg(chip->dev, "%s:[%d]:irq=%d  status=0x%x\n",
+                               __func__, i, irq, reg_val);
+                       iowrite32(BIT(i), &chip->reg->iclr);
+                       generic_handle_irq(chip->irq_base + i);
+                       ret = IRQ_HANDLED;
+               }
+       }
+       return ret;
+}
+
+static __devinit void pch_gpio_alloc_generic_chip(struct pch_gpio *chip,
+                               unsigned int irq_start, unsigned int num)
+{
+       struct irq_chip_generic *gc;
+       struct irq_chip_type *ct;
+
+       gc = irq_alloc_generic_chip("pch_gpio", 1, irq_start, chip->base,
+                                   handle_simple_irq);
+       gc->private = chip;
+       ct = gc->chip_types;
+
+       ct->chip.irq_mask = pch_irq_mask;
+       ct->chip.irq_unmask = pch_irq_unmask;
+       ct->chip.irq_set_type = pch_irq_type;
+
+       irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE,
+                              IRQ_NOREQUEST | IRQ_NOPROBE, 0);
 }
 
 static int __devinit pch_gpio_probe(struct pci_dev *pdev,
@@ -167,6 +355,7 @@ static int __devinit pch_gpio_probe(struct pci_dev *pdev,
 {
        s32 ret;
        struct pch_gpio *chip;
+       int irq_base;
 
        chip = kzalloc(sizeof(*chip), GFP_KERNEL);
        if (chip == NULL)
@@ -192,6 +381,13 @@ static int __devinit pch_gpio_probe(struct pci_dev *pdev,
                goto err_iomap;
        }
 
+       if (pdev->device == 0x8803)
+               chip->ioh = INTEL_EG20T_PCH;
+       else if (pdev->device == 0x8014)
+               chip->ioh = OKISEMI_ML7223m_IOH;
+       else if (pdev->device == 0x8043)
+               chip->ioh = OKISEMI_ML7223n_IOH;
+
        chip->reg = chip->base;
        pci_set_drvdata(pdev, chip);
        mutex_init(&chip->lock);
@@ -202,8 +398,36 @@ static int __devinit pch_gpio_probe(struct pci_dev *pdev,
                goto err_gpiochip_add;
        }
 
+       irq_base = irq_alloc_descs(-1, 0, gpio_pins[chip->ioh], NUMA_NO_NODE);
+       if (irq_base < 0) {
+               dev_warn(&pdev->dev, "PCH gpio: Failed to get IRQ base num\n");
+               chip->irq_base = -1;
+               goto end;
+       }
+       chip->irq_base = irq_base;
+
+       ret = request_irq(pdev->irq, pch_gpio_handler,
+                            IRQF_SHARED, KBUILD_MODNAME, chip);
+       if (ret != 0) {
+               dev_err(&pdev->dev,
+                       "%s request_irq failed\n", __func__);
+               goto err_request_irq;
+       }
+
+       pch_gpio_alloc_generic_chip(chip, irq_base, gpio_pins[chip->ioh]);
+
+       /* Initialize interrupt ien register */
+       iowrite32(0, &chip->reg->ien);
+end:
        return 0;
 
+err_request_irq:
+       irq_free_descs(irq_base, gpio_pins[chip->ioh]);
+
+       ret = gpiochip_remove(&chip->gpio);
+       if (ret)
+               dev_err(&pdev->dev, "%s gpiochip_remove failed\n", __func__);
+
 err_gpiochip_add:
        pci_iounmap(pdev, chip->base);
 
@@ -224,6 +448,12 @@ static void __devexit pch_gpio_remove(struct pci_dev *pdev)
        int err;
        struct pch_gpio *chip = pci_get_drvdata(pdev);
 
+       if (chip->irq_base != -1) {
+               free_irq(pdev->irq, chip);
+
+               irq_free_descs(chip->irq_base, gpio_pins[chip->ioh]);
+       }
+
        err = gpiochip_remove(&chip->gpio);
        if (err)
                dev_err(&pdev->dev, "Failed gpiochip_remove\n");
@@ -239,9 +469,11 @@ static int pch_gpio_suspend(struct pci_dev *pdev, pm_message_t state)
 {
        s32 ret;
        struct pch_gpio *chip = pci_get_drvdata(pdev);
+       unsigned long flags;
 
+       spin_lock_irqsave(&chip->spinlock, flags);
        pch_gpio_save_reg_conf(chip);
-       pch_gpio_restore_reg_conf(chip);
+       spin_unlock_irqrestore(&chip->spinlock, flags);
 
        ret = pci_save_state(pdev);
        if (ret) {
@@ -261,6 +493,7 @@ static int pch_gpio_resume(struct pci_dev *pdev)
 {
        s32 ret;
        struct pch_gpio *chip = pci_get_drvdata(pdev);
+       unsigned long flags;
 
        ret = pci_enable_wake(pdev, PCI_D0, 0);
 
@@ -272,9 +505,11 @@ static int pch_gpio_resume(struct pci_dev *pdev)
        }
        pci_restore_state(pdev);
 
+       spin_lock_irqsave(&chip->spinlock, flags);
        iowrite32(0x01, &chip->reg->reset);
        iowrite32(0x00, &chip->reg->reset);
        pch_gpio_restore_reg_conf(chip);
+       spin_unlock_irqrestore(&chip->spinlock, flags);
 
        return 0;
 }
@@ -287,6 +522,7 @@ static int pch_gpio_resume(struct pci_dev *pdev)
 static DEFINE_PCI_DEVICE_TABLE(pch_gpio_pcidev_id) = {
        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x8803) },
        { PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8014) },
+       { PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8043) },
        { 0, }
 };
 MODULE_DEVICE_TABLE(pci, pch_gpio_pcidev_id);
index 2c5a18f32bf30f8dcd6b351f05196ce6e40f26ca..093c90bd3c1d1b1d888ce2465831c95d125e0036 100644 (file)
@@ -118,7 +118,7 @@ static int pl061_to_irq(struct gpio_chip *gc, unsigned offset)
 {
        struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc);
 
-       if (chip->irq_base == (unsigned) -1)
+       if (chip->irq_base == NO_IRQ)
                return -EINVAL;
 
        return chip->irq_base + offset;
@@ -246,6 +246,18 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
        if (chip == NULL)
                return -ENOMEM;
 
+       pdata = dev->dev.platform_data;
+       if (pdata) {
+               chip->gc.base = pdata->gpio_base;
+               chip->irq_base = pdata->irq_base;
+       } else if (dev->dev.of_node) {
+               chip->gc.base = -1;
+               chip->irq_base = NO_IRQ;
+       } else {
+               ret = -ENODEV;
+               goto free_mem;
+       }
+
        if (!request_mem_region(dev->res.start,
                                resource_size(&dev->res), "pl061")) {
                ret = -EBUSY;
@@ -267,14 +279,11 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
        chip->gc.get = pl061_get_value;
        chip->gc.set = pl061_set_value;
        chip->gc.to_irq = pl061_to_irq;
-       chip->gc.base = pdata->gpio_base;
        chip->gc.ngpio = PL061_GPIO_NR;
        chip->gc.label = dev_name(&dev->dev);
        chip->gc.dev = &dev->dev;
        chip->gc.owner = THIS_MODULE;
 
-       chip->irq_base = pdata->irq_base;
-
        ret = gpiochip_add(&chip->gc);
        if (ret)
                goto iounmap;
@@ -283,7 +292,7 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
         * irq_chip support
         */
 
-       if (chip->irq_base == (unsigned) -1)
+       if (chip->irq_base == NO_IRQ)
                return 0;
 
        writeb(0, chip->base + GPIOIE); /* disable irqs */
@@ -307,11 +316,13 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
        list_add(&chip->list, chip_list);
 
        for (i = 0; i < PL061_GPIO_NR; i++) {
-               if (pdata->directions & (1 << i))
-                       pl061_direction_output(&chip->gc, i,
-                                       pdata->values & (1 << i));
-               else
-                       pl061_direction_input(&chip->gc, i);
+               if (pdata) {
+                       if (pdata->directions & (1 << i))
+                               pl061_direction_output(&chip->gc, i,
+                                               pdata->values & (1 << i));
+                       else
+                               pl061_direction_input(&chip->gc, i);
+               }
 
                irq_set_chip_and_handler(i + chip->irq_base, &pl061_irqchip,
                                         handle_simple_irq);
index a61e7815a2a9153f7ad82e8dc2ff49273763c19a..6460487e41b50f8c99b96ea61c09a566cf0aa170 100644 (file)
@@ -27,8 +27,7 @@
 
 static struct class *hwmon_class;
 
-static DEFINE_IDR(hwmon_idr);
-static DEFINE_SPINLOCK(idr_lock);
+static DEFINE_IDA(hwmon_ida);
 
 /**
  * hwmon_device_register - register w/ hwmon
@@ -42,30 +41,17 @@ static DEFINE_SPINLOCK(idr_lock);
 struct device *hwmon_device_register(struct device *dev)
 {
        struct device *hwdev;
-       int id, err;
-
-again:
-       if (unlikely(idr_pre_get(&hwmon_idr, GFP_KERNEL) == 0))
-               return ERR_PTR(-ENOMEM);
-
-       spin_lock(&idr_lock);
-       err = idr_get_new(&hwmon_idr, NULL, &id);
-       spin_unlock(&idr_lock);
+       int id;
 
-       if (unlikely(err == -EAGAIN))
-               goto again;
-       else if (unlikely(err))
-               return ERR_PTR(err);
+       id = ida_simple_get(&hwmon_ida, 0, 0, GFP_KERNEL);
+       if (id < 0)
+               return ERR_PTR(id);
 
-       id = id & MAX_ID_MASK;
        hwdev = device_create(hwmon_class, dev, MKDEV(0, 0), NULL,
                              HWMON_ID_FORMAT, id);
 
-       if (IS_ERR(hwdev)) {
-               spin_lock(&idr_lock);
-               idr_remove(&hwmon_idr, id);
-               spin_unlock(&idr_lock);
-       }
+       if (IS_ERR(hwdev))
+               ida_simple_remove(&hwmon_ida, id);
 
        return hwdev;
 }
@@ -81,9 +67,7 @@ void hwmon_device_unregister(struct device *dev)
 
        if (likely(sscanf(dev_name(dev), HWMON_ID_FORMAT, &id) == 1)) {
                device_unregister(dev);
-               spin_lock(&idr_lock);
-               idr_remove(&hwmon_idr, id);
-               spin_unlock(&idr_lock);
+               ida_simple_remove(&hwmon_ida, id);
        } else
                dev_dbg(dev->parent,
                        "hwmon_device_unregister() failed: bad class ID!\n");
index c316294c48b47ba848f5844270e0394d13e2be87..783d0c17b762dc504babef2e5a039c033b3d8f77 100644 (file)
@@ -88,8 +88,7 @@
 #define AEM_MIN_POWER_INTERVAL 200
 #define UJ_PER_MJ              1000L
 
-static DEFINE_IDR(aem_idr);
-static DEFINE_SPINLOCK(aem_idr_lock);
+static DEFINE_IDA(aem_ida);
 
 static struct platform_driver aem_driver = {
        .driver = {
@@ -356,38 +355,6 @@ static void aem_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data)
        complete(&data->read_complete);
 }
 
-/* ID functions */
-
-/* Obtain an id */
-static int aem_idr_get(int *id)
-{
-       int i, err;
-
-again:
-       if (unlikely(!idr_pre_get(&aem_idr, GFP_KERNEL)))
-               return -ENOMEM;
-
-       spin_lock(&aem_idr_lock);
-       err = idr_get_new(&aem_idr, NULL, &i);
-       spin_unlock(&aem_idr_lock);
-
-       if (unlikely(err == -EAGAIN))
-               goto again;
-       else if (unlikely(err))
-               return err;
-
-       *id = i & MAX_ID_MASK;
-       return 0;
-}
-
-/* Release an object ID */
-static void aem_idr_put(int id)
-{
-       spin_lock(&aem_idr_lock);
-       idr_remove(&aem_idr, id);
-       spin_unlock(&aem_idr_lock);
-}
-
 /* Sensor support functions */
 
 /* Read a sensor value */
@@ -530,7 +497,7 @@ static void aem_delete(struct aem_data *data)
        ipmi_destroy_user(data->ipmi.user);
        platform_set_drvdata(data->pdev, NULL);
        platform_device_unregister(data->pdev);
-       aem_idr_put(data->id);
+       ida_simple_remove(&aem_ida, data->id);
        kfree(data);
 }
 
@@ -587,7 +554,8 @@ static int aem_init_aem1_inst(struct aem_ipmi_data *probe, u8 module_handle)
                data->power_period[i] = AEM_DEFAULT_POWER_INTERVAL;
 
        /* Create sub-device for this fw instance */
-       if (aem_idr_get(&data->id))
+       data->id = ida_simple_get(&aem_ida, 0, 0, GFP_KERNEL);
+       if (data->id < 0)
                goto id_err;
 
        data->pdev = platform_device_alloc(DRVNAME, data->id);
@@ -638,7 +606,7 @@ ipmi_err:
        platform_set_drvdata(data->pdev, NULL);
        platform_device_unregister(data->pdev);
 dev_err:
-       aem_idr_put(data->id);
+       ida_simple_remove(&aem_ida, data->id);
 id_err:
        kfree(data);
 
@@ -720,7 +688,8 @@ static int aem_init_aem2_inst(struct aem_ipmi_data *probe,
                data->power_period[i] = AEM_DEFAULT_POWER_INTERVAL;
 
        /* Create sub-device for this fw instance */
-       if (aem_idr_get(&data->id))
+       data->id = ida_simple_get(&aem_ida, 0, 0, GFP_KERNEL);
+       if (data->id < 0)
                goto id_err;
 
        data->pdev = platform_device_alloc(DRVNAME, data->id);
@@ -771,7 +740,7 @@ ipmi_err:
        platform_set_drvdata(data->pdev, NULL);
        platform_device_unregister(data->pdev);
 dev_err:
-       aem_idr_put(data->id);
+       ida_simple_remove(&aem_ida, data->id);
 id_err:
        kfree(data);
 
index d6d58684712bc8b68cafb662316fe123e53b270d..85584a547c25201a1375bf92b074af571d37be0e 100644 (file)
@@ -47,8 +47,8 @@
 /* ----- global variables ---------------------------------------------        */
 
 static int bit_test;   /* see if the line-setting functions work       */
-module_param(bit_test, bool, 0);
-MODULE_PARM_DESC(bit_test, "Test the lines of the bus to see if it is stuck");
+module_param(bit_test, int, S_IRUGO);
+MODULE_PARM_DESC(bit_test, "lines testing - 0 off; 1 report; 2 fail if stuck");
 
 #ifdef DEBUG
 static int i2c_debug = 1;
@@ -250,7 +250,9 @@ static int test_bus(struct i2c_adapter *i2c_adap)
        sda = getsda(adap);
        scl = (adap->getscl == NULL) ? 1 : getscl(adap);
        if (!scl || !sda) {
-               printk(KERN_WARNING "%s: bus seems to be busy\n", name);
+               printk(KERN_WARNING
+                      "%s: bus seems to be busy (scl=%d, sda=%d)\n",
+                      name, scl, sda);
                goto bailout;
        }
 
@@ -441,7 +443,7 @@ static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
                                        acknak(i2c_adap, 0);
                                dev_err(&i2c_adap->dev, "readbytes: invalid "
                                        "block length (%d)\n", inval);
-                               return -EREMOTEIO;
+                               return -EPROTO;
                        }
                        /* The original count value accounts for the extra
                           bytes, that is, either 1 for a regular transaction,
@@ -470,7 +472,7 @@ static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
  * reads, writes as well as 10bit-addresses.
  * returns:
  *  0 everything went okay, the chip ack'ed, or IGNORE_NAK flag was set
- * -x an error occurred (like: -EREMOTEIO if the device did not answer, or
+ * -x an error occurred (like: -ENXIO if the device did not answer, or
  *     -ETIMEDOUT, for example if the lines are stuck...)
  */
 static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
@@ -493,14 +495,14 @@ static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
                if ((ret != 1) && !nak_ok)  {
                        dev_err(&i2c_adap->dev,
                                "died at extended address code\n");
-                       return -EREMOTEIO;
+                       return -ENXIO;
                }
                /* the remaining 8 bit address */
                ret = i2c_outb(i2c_adap, msg->addr & 0x7f);
                if ((ret != 1) && !nak_ok) {
                        /* the chip did not ack / xmission error occurred */
                        dev_err(&i2c_adap->dev, "died at 2nd address code\n");
-                       return -EREMOTEIO;
+                       return -ENXIO;
                }
                if (flags & I2C_M_RD) {
                        bit_dbg(3, &i2c_adap->dev, "emitting repeated "
@@ -512,7 +514,7 @@ static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
                        if ((ret != 1) && !nak_ok) {
                                dev_err(&i2c_adap->dev,
                                        "died at repeated address code\n");
-                               return -EREMOTEIO;
+                               return -EIO;
                        }
                }
        } else {                /* normal 7bit address  */
@@ -570,7 +572,7 @@ static int bit_xfer(struct i2c_adapter *i2c_adap,
                                        ret, ret == 1 ? "" : "s");
                        if (ret < pmsg->len) {
                                if (ret >= 0)
-                                       ret = -EREMOTEIO;
+                                       ret = -EIO;
                                goto bailout;
                        }
                } else {
@@ -581,7 +583,7 @@ static int bit_xfer(struct i2c_adapter *i2c_adap,
                                        ret, ret == 1 ? "" : "s");
                        if (ret < pmsg->len) {
                                if (ret >= 0)
-                                       ret = -EREMOTEIO;
+                                       ret = -EIO;
                                goto bailout;
                        }
                }
@@ -624,7 +626,7 @@ static int __i2c_bit_add_bus(struct i2c_adapter *adap,
 
        if (bit_test) {
                ret = test_bus(adap);
-               if (ret < 0)
+               if (bit_test >= 2 && ret < 0)
                        return -ENODEV;
        }
 
index 4ca9cf9cde73db2ab35538bd0cdd058b0d8505ea..beb9ffe2564bc77ffb474ef1346a49c2600c89a5 100644 (file)
@@ -196,7 +196,7 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
                } else {
                        dev_dbg(&i2c_adap->dev, "bus is not idle. status is "
                                "%#04x\n", state);
-                       return -EAGAIN;
+                       return -EBUSY;
                }
        }
 
@@ -224,7 +224,7 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
        }
 
        curmsg = 0;
-       ret = -EREMOTEIO;
+       ret = -EIO;
        while (curmsg < num) {
                state = pca_status(adap);
 
@@ -259,6 +259,7 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
                case 0x20: /* SLA+W has been transmitted; NOT ACK has been received */
                        DEB2("NOT ACK received after SLA+W\n");
                        pca_stop(adap);
+                       ret = -ENXIO;
                        goto out;
 
                case 0x40: /* SLA+R has been transmitted; ACK has been received */
@@ -283,6 +284,7 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
                case 0x48: /* SLA+R has been transmitted; NOT ACK has been received */
                        DEB2("NOT ACK received after SLA+R\n");
                        pca_stop(adap);
+                       ret = -ENXIO;
                        goto out;
 
                case 0x30: /* Data byte in I2CDAT has been transmitted; NOT ACK has been received */
index 1d7ce9c18bfffc06f28ff291c8e8a02c5d5012dc..b2b85629d074a9343c153225dba2c6aa4b0bc424 100644 (file)
@@ -799,7 +799,7 @@ config I2C_ACORN
 
 config I2C_ELEKTOR
        tristate "Elektor ISA card"
-       depends on ISA && BROKEN_ON_SMP
+       depends on ISA && HAS_IOPORT && BROKEN_ON_SMP
        select I2C_ALGOPCF
        help
          This supports the PCF8584 ISA bus I2C adapter.  Say Y if you own
index 986e5f62debe95c2d5ba0fa8886be20fa250e176..91e349c884c5c9ec73fc42b6fecd4964afc7ff12 100644 (file)
@@ -550,7 +550,7 @@ static int __devexit scx200_remove(struct platform_device *pdev)
        return 0;
 }
 
-static struct platform_driver scx200_pci_drv = {
+static struct platform_driver scx200_pci_driver = {
        .driver = {
                .name = "cs5535-smb",
                .owner = THIS_MODULE,
@@ -593,14 +593,14 @@ static int __init scx200_acb_init(void)
                return 0;
 
        /* No ISA devices; register the platform driver for PCI-based devices */
-       return platform_driver_register(&scx200_pci_drv);
+       return platform_driver_register(&scx200_pci_driver);
 }
 
 static void __exit scx200_acb_cleanup(void)
 {
        struct scx200_acb_iface *iface;
 
-       platform_driver_unregister(&scx200_pci_drv);
+       platform_driver_unregister(&scx200_pci_driver);
 
        mutex_lock(&scx200_acb_list_mutex);
        while ((iface = scx200_acb_list) != NULL) {
index fc0f2bd9ca82518b50653e794d68ac35237d40e7..4104ea2427c24dd935a265a0d0148cc6e871d6ca 100644 (file)
@@ -889,6 +889,8 @@ retest:
                break;
        case IB_CM_ESTABLISHED:
                spin_unlock_irq(&cm_id_priv->lock);
+               if (cm_id_priv->qp_type == IB_QPT_XRC_TGT)
+                       break;
                ib_send_cm_dreq(cm_id, NULL, 0);
                goto retest;
        case IB_CM_DREQ_SENT:
@@ -1008,7 +1010,6 @@ static void cm_format_req(struct cm_req_msg *req_msg,
        req_msg->service_id = param->service_id;
        req_msg->local_ca_guid = cm_id_priv->id.device->node_guid;
        cm_req_set_local_qpn(req_msg, cpu_to_be32(param->qp_num));
-       cm_req_set_resp_res(req_msg, param->responder_resources);
        cm_req_set_init_depth(req_msg, param->initiator_depth);
        cm_req_set_remote_resp_timeout(req_msg,
                                       param->remote_cm_response_timeout);
@@ -1017,12 +1018,16 @@ static void cm_format_req(struct cm_req_msg *req_msg,
        cm_req_set_starting_psn(req_msg, cpu_to_be32(param->starting_psn));
        cm_req_set_local_resp_timeout(req_msg,
                                      param->local_cm_response_timeout);
-       cm_req_set_retry_count(req_msg, param->retry_count);
        req_msg->pkey = param->primary_path->pkey;
        cm_req_set_path_mtu(req_msg, param->primary_path->mtu);
-       cm_req_set_rnr_retry_count(req_msg, param->rnr_retry_count);
        cm_req_set_max_cm_retries(req_msg, param->max_cm_retries);
-       cm_req_set_srq(req_msg, param->srq);
+
+       if (param->qp_type != IB_QPT_XRC_INI) {
+               cm_req_set_resp_res(req_msg, param->responder_resources);
+               cm_req_set_retry_count(req_msg, param->retry_count);
+               cm_req_set_rnr_retry_count(req_msg, param->rnr_retry_count);
+               cm_req_set_srq(req_msg, param->srq);
+       }
 
        if (pri_path->hop_limit <= 1) {
                req_msg->primary_local_lid = pri_path->slid;
@@ -1080,7 +1085,8 @@ static int cm_validate_req_param(struct ib_cm_req_param *param)
        if (!param->primary_path)
                return -EINVAL;
 
-       if (param->qp_type != IB_QPT_RC && param->qp_type != IB_QPT_UC)
+       if (param->qp_type != IB_QPT_RC && param->qp_type != IB_QPT_UC &&
+           param->qp_type != IB_QPT_XRC_INI)
                return -EINVAL;
 
        if (param->private_data &&
@@ -1601,18 +1607,24 @@ static void cm_format_rep(struct cm_rep_msg *rep_msg,
        cm_format_mad_hdr(&rep_msg->hdr, CM_REP_ATTR_ID, cm_id_priv->tid);
        rep_msg->local_comm_id = cm_id_priv->id.local_id;
        rep_msg->remote_comm_id = cm_id_priv->id.remote_id;
-       cm_rep_set_local_qpn(rep_msg, cpu_to_be32(param->qp_num));
        cm_rep_set_starting_psn(rep_msg, cpu_to_be32(param->starting_psn));
        rep_msg->resp_resources = param->responder_resources;
-       rep_msg->initiator_depth = param->initiator_depth;
        cm_rep_set_target_ack_delay(rep_msg,
                                    cm_id_priv->av.port->cm_dev->ack_delay);
        cm_rep_set_failover(rep_msg, param->failover_accepted);
-       cm_rep_set_flow_ctrl(rep_msg, param->flow_control);
        cm_rep_set_rnr_retry_count(rep_msg, param->rnr_retry_count);
-       cm_rep_set_srq(rep_msg, param->srq);
        rep_msg->local_ca_guid = cm_id_priv->id.device->node_guid;
 
+       if (cm_id_priv->qp_type != IB_QPT_XRC_TGT) {
+               rep_msg->initiator_depth = param->initiator_depth;
+               cm_rep_set_flow_ctrl(rep_msg, param->flow_control);
+               cm_rep_set_srq(rep_msg, param->srq);
+               cm_rep_set_local_qpn(rep_msg, cpu_to_be32(param->qp_num));
+       } else {
+               cm_rep_set_srq(rep_msg, 1);
+               cm_rep_set_local_eecn(rep_msg, cpu_to_be32(param->qp_num));
+       }
+
        if (param->private_data && param->private_data_len)
                memcpy(rep_msg->private_data, param->private_data,
                       param->private_data_len);
@@ -1660,7 +1672,7 @@ int ib_send_cm_rep(struct ib_cm_id *cm_id,
        cm_id_priv->initiator_depth = param->initiator_depth;
        cm_id_priv->responder_resources = param->responder_resources;
        cm_id_priv->rq_psn = cm_rep_get_starting_psn(rep_msg);
-       cm_id_priv->local_qpn = cm_rep_get_local_qpn(rep_msg);
+       cm_id_priv->local_qpn = cpu_to_be32(param->qp_num & 0xFFFFFF);
 
 out:   spin_unlock_irqrestore(&cm_id_priv->lock, flags);
        return ret;
@@ -1731,7 +1743,7 @@ error:    spin_unlock_irqrestore(&cm_id_priv->lock, flags);
 }
 EXPORT_SYMBOL(ib_send_cm_rtu);
 
-static void cm_format_rep_event(struct cm_work *work)
+static void cm_format_rep_event(struct cm_work *work, enum ib_qp_type qp_type)
 {
        struct cm_rep_msg *rep_msg;
        struct ib_cm_rep_event_param *param;
@@ -1740,7 +1752,7 @@ static void cm_format_rep_event(struct cm_work *work)
        param = &work->cm_event.param.rep_rcvd;
        param->remote_ca_guid = rep_msg->local_ca_guid;
        param->remote_qkey = be32_to_cpu(rep_msg->local_qkey);
-       param->remote_qpn = be32_to_cpu(cm_rep_get_local_qpn(rep_msg));
+       param->remote_qpn = be32_to_cpu(cm_rep_get_qpn(rep_msg, qp_type));
        param->starting_psn = be32_to_cpu(cm_rep_get_starting_psn(rep_msg));
        param->responder_resources = rep_msg->initiator_depth;
        param->initiator_depth = rep_msg->resp_resources;
@@ -1808,7 +1820,7 @@ static int cm_rep_handler(struct cm_work *work)
                return -EINVAL;
        }
 
-       cm_format_rep_event(work);
+       cm_format_rep_event(work, cm_id_priv->qp_type);
 
        spin_lock_irq(&cm_id_priv->lock);
        switch (cm_id_priv->id.state) {
@@ -1823,7 +1835,7 @@ static int cm_rep_handler(struct cm_work *work)
 
        cm_id_priv->timewait_info->work.remote_id = rep_msg->local_comm_id;
        cm_id_priv->timewait_info->remote_ca_guid = rep_msg->local_ca_guid;
-       cm_id_priv->timewait_info->remote_qpn = cm_rep_get_local_qpn(rep_msg);
+       cm_id_priv->timewait_info->remote_qpn = cm_rep_get_qpn(rep_msg, cm_id_priv->qp_type);
 
        spin_lock(&cm.lock);
        /* Check for duplicate REP. */
@@ -1850,7 +1862,7 @@ static int cm_rep_handler(struct cm_work *work)
 
        cm_id_priv->id.state = IB_CM_REP_RCVD;
        cm_id_priv->id.remote_id = rep_msg->local_comm_id;
-       cm_id_priv->remote_qpn = cm_rep_get_local_qpn(rep_msg);
+       cm_id_priv->remote_qpn = cm_rep_get_qpn(rep_msg, cm_id_priv->qp_type);
        cm_id_priv->initiator_depth = rep_msg->resp_resources;
        cm_id_priv->responder_resources = rep_msg->initiator_depth;
        cm_id_priv->sq_psn = cm_rep_get_starting_psn(rep_msg);
@@ -3492,7 +3504,8 @@ static int cm_init_qp_rtr_attr(struct cm_id_private *cm_id_priv,
                qp_attr->path_mtu = cm_id_priv->path_mtu;
                qp_attr->dest_qp_num = be32_to_cpu(cm_id_priv->remote_qpn);
                qp_attr->rq_psn = be32_to_cpu(cm_id_priv->rq_psn);
-               if (cm_id_priv->qp_type == IB_QPT_RC) {
+               if (cm_id_priv->qp_type == IB_QPT_RC ||
+                   cm_id_priv->qp_type == IB_QPT_XRC_TGT) {
                        *qp_attr_mask |= IB_QP_MAX_DEST_RD_ATOMIC |
                                         IB_QP_MIN_RNR_TIMER;
                        qp_attr->max_dest_rd_atomic =
@@ -3537,15 +3550,21 @@ static int cm_init_qp_rts_attr(struct cm_id_private *cm_id_priv,
                if (cm_id_priv->id.lap_state == IB_CM_LAP_UNINIT) {
                        *qp_attr_mask = IB_QP_STATE | IB_QP_SQ_PSN;
                        qp_attr->sq_psn = be32_to_cpu(cm_id_priv->sq_psn);
-                       if (cm_id_priv->qp_type == IB_QPT_RC) {
-                               *qp_attr_mask |= IB_QP_TIMEOUT | IB_QP_RETRY_CNT |
-                                                IB_QP_RNR_RETRY |
+                       switch (cm_id_priv->qp_type) {
+                       case IB_QPT_RC:
+                       case IB_QPT_XRC_INI:
+                               *qp_attr_mask |= IB_QP_RETRY_CNT | IB_QP_RNR_RETRY |
                                                 IB_QP_MAX_QP_RD_ATOMIC;
-                               qp_attr->timeout = cm_id_priv->av.timeout;
                                qp_attr->retry_cnt = cm_id_priv->retry_count;
                                qp_attr->rnr_retry = cm_id_priv->rnr_retry_count;
-                               qp_attr->max_rd_atomic =
-                                       cm_id_priv->initiator_depth;
+                               qp_attr->max_rd_atomic = cm_id_priv->initiator_depth;
+                               /* fall through */
+                       case IB_QPT_XRC_TGT:
+                               *qp_attr_mask |= IB_QP_TIMEOUT;
+                               qp_attr->timeout = cm_id_priv->av.timeout;
+                               break;
+                       default:
+                               break;
                        }
                        if (cm_id_priv->alt_av.ah_attr.dlid) {
                                *qp_attr_mask |= IB_QP_PATH_MIG_STATE;
index 7e63c08f697c33f3dcbd806a9a122cae1867c3cb..505db2a59e7f4f46b85422c94955459b6b00b85a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004 Intel Corporation.  All rights reserved.
+ * Copyright (c) 2004, 2011 Intel Corporation.  All rights reserved.
  * Copyright (c) 2004 Topspin Corporation.  All rights reserved.
  * Copyright (c) 2004 Voltaire Corporation.  All rights reserved.
  *
@@ -86,7 +86,7 @@ struct cm_req_msg {
        __be16 pkey;
        /* path MTU:4, RDC exists:1, RNR retry count:3. */
        u8 offset50;
-       /* max CM Retries:4, SRQ:1, rsvd:3 */
+       /* max CM Retries:4, SRQ:1, extended transport type:3 */
        u8 offset51;
 
        __be16 primary_local_lid;
@@ -175,6 +175,11 @@ static inline enum ib_qp_type cm_req_get_qp_type(struct cm_req_msg *req_msg)
        switch(transport_type) {
        case 0: return IB_QPT_RC;
        case 1: return IB_QPT_UC;
+       case 3:
+               switch (req_msg->offset51 & 0x7) {
+               case 1: return IB_QPT_XRC_TGT;
+               default: return 0;
+               }
        default: return 0;
        }
 }
@@ -188,6 +193,12 @@ static inline void cm_req_set_qp_type(struct cm_req_msg *req_msg,
                                                  req_msg->offset40) &
                                                   0xFFFFFFF9) | 0x2);
                break;
+       case IB_QPT_XRC_INI:
+               req_msg->offset40 = cpu_to_be32((be32_to_cpu(
+                                                req_msg->offset40) &
+                                                  0xFFFFFFF9) | 0x6);
+               req_msg->offset51 = (req_msg->offset51 & 0xF8) | 1;
+               break;
        default:
                req_msg->offset40 = cpu_to_be32(be32_to_cpu(
                                                 req_msg->offset40) &
@@ -527,6 +538,23 @@ static inline void cm_rep_set_local_qpn(struct cm_rep_msg *rep_msg, __be32 qpn)
                            (be32_to_cpu(rep_msg->offset12) & 0x000000FF));
 }
 
+static inline __be32 cm_rep_get_local_eecn(struct cm_rep_msg *rep_msg)
+{
+       return cpu_to_be32(be32_to_cpu(rep_msg->offset16) >> 8);
+}
+
+static inline void cm_rep_set_local_eecn(struct cm_rep_msg *rep_msg, __be32 eecn)
+{
+       rep_msg->offset16 = cpu_to_be32((be32_to_cpu(eecn) << 8) |
+                           (be32_to_cpu(rep_msg->offset16) & 0x000000FF));
+}
+
+static inline __be32 cm_rep_get_qpn(struct cm_rep_msg *rep_msg, enum ib_qp_type qp_type)
+{
+       return (qp_type == IB_QPT_XRC_INI) ?
+               cm_rep_get_local_eecn(rep_msg) : cm_rep_get_local_qpn(rep_msg);
+}
+
 static inline __be32 cm_rep_get_starting_psn(struct cm_rep_msg *rep_msg)
 {
        return cpu_to_be32(be32_to_cpu(rep_msg->offset20) >> 8);
index ca4c5dcd7133365f09dc60d83f623d4b5412ec4d..872b1842598a3693e5ed647bbf7917d6c072f0b2 100644 (file)
@@ -81,6 +81,7 @@ static DEFINE_IDR(sdp_ps);
 static DEFINE_IDR(tcp_ps);
 static DEFINE_IDR(udp_ps);
 static DEFINE_IDR(ipoib_ps);
+static DEFINE_IDR(ib_ps);
 
 struct cma_device {
        struct list_head        list;
@@ -1179,6 +1180,15 @@ static void cma_set_req_event_data(struct rdma_cm_event *event,
        event->param.conn.qp_num = req_data->remote_qpn;
 }
 
+static int cma_check_req_qp_type(struct rdma_cm_id *id, struct ib_cm_event *ib_event)
+{
+       return (((ib_event->event == IB_CM_REQ_RECEIVED) ||
+                (ib_event->param.req_rcvd.qp_type == id->qp_type)) ||
+               ((ib_event->event == IB_CM_SIDR_REQ_RECEIVED) &&
+                (id->qp_type == IB_QPT_UD)) ||
+               (!id->qp_type));
+}
+
 static int cma_req_handler(struct ib_cm_id *cm_id, struct ib_cm_event *ib_event)
 {
        struct rdma_id_private *listen_id, *conn_id;
@@ -1186,13 +1196,16 @@ static int cma_req_handler(struct ib_cm_id *cm_id, struct ib_cm_event *ib_event)
        int offset, ret;
 
        listen_id = cm_id->context;
+       if (!cma_check_req_qp_type(&listen_id->id, ib_event))
+               return -EINVAL;
+
        if (cma_disable_callback(listen_id, RDMA_CM_LISTEN))
                return -ECONNABORTED;
 
        memset(&event, 0, sizeof event);
        offset = cma_user_data_offset(listen_id->id.ps);
        event.event = RDMA_CM_EVENT_CONNECT_REQUEST;
-       if (listen_id->id.qp_type == IB_QPT_UD) {
+       if (ib_event->event == IB_CM_SIDR_REQ_RECEIVED) {
                conn_id = cma_new_udp_id(&listen_id->id, ib_event);
                event.param.ud.private_data = ib_event->private_data + offset;
                event.param.ud.private_data_len =
@@ -1328,6 +1341,8 @@ static int cma_iw_handler(struct iw_cm_id *iw_id, struct iw_cm_event *iw_event)
                switch (iw_event->status) {
                case 0:
                        event.event = RDMA_CM_EVENT_ESTABLISHED;
+                       event.param.conn.initiator_depth = iw_event->ird;
+                       event.param.conn.responder_resources = iw_event->ord;
                        break;
                case -ECONNRESET:
                case -ECONNREFUSED:
@@ -1343,6 +1358,8 @@ static int cma_iw_handler(struct iw_cm_id *iw_id, struct iw_cm_event *iw_event)
                break;
        case IW_CM_EVENT_ESTABLISHED:
                event.event = RDMA_CM_EVENT_ESTABLISHED;
+               event.param.conn.initiator_depth = iw_event->ird;
+               event.param.conn.responder_resources = iw_event->ord;
                break;
        default:
                BUG_ON(1);
@@ -1433,8 +1450,8 @@ static int iw_conn_req_handler(struct iw_cm_id *cm_id,
        event.event = RDMA_CM_EVENT_CONNECT_REQUEST;
        event.param.conn.private_data = iw_event->private_data;
        event.param.conn.private_data_len = iw_event->private_data_len;
-       event.param.conn.initiator_depth = attr.max_qp_init_rd_atom;
-       event.param.conn.responder_resources = attr.max_qp_rd_atom;
+       event.param.conn.initiator_depth = iw_event->ird;
+       event.param.conn.responder_resources = iw_event->ord;
 
        /*
         * Protect against the user destroying conn_id from another thread
@@ -2234,6 +2251,9 @@ static int cma_get_port(struct rdma_id_private *id_priv)
        case RDMA_PS_IPOIB:
                ps = &ipoib_ps;
                break;
+       case RDMA_PS_IB:
+               ps = &ib_ps;
+               break;
        default:
                return -EPROTONOSUPPORT;
        }
@@ -2569,7 +2589,7 @@ static int cma_connect_ib(struct rdma_id_private *id_priv,
        req.service_id = cma_get_service_id(id_priv->id.ps,
                                            (struct sockaddr *) &route->addr.dst_addr);
        req.qp_num = id_priv->qp_num;
-       req.qp_type = IB_QPT_RC;
+       req.qp_type = id_priv->id.qp_type;
        req.starting_psn = id_priv->seq_num;
        req.responder_resources = conn_param->responder_resources;
        req.initiator_depth = conn_param->initiator_depth;
@@ -2616,14 +2636,16 @@ static int cma_connect_iw(struct rdma_id_private *id_priv,
        if (ret)
                goto out;
 
-       iw_param.ord = conn_param->initiator_depth;
-       iw_param.ird = conn_param->responder_resources;
-       iw_param.private_data = conn_param->private_data;
-       iw_param.private_data_len = conn_param->private_data_len;
-       if (id_priv->id.qp)
+       if (conn_param) {
+               iw_param.ord = conn_param->initiator_depth;
+               iw_param.ird = conn_param->responder_resources;
+               iw_param.private_data = conn_param->private_data;
+               iw_param.private_data_len = conn_param->private_data_len;
+               iw_param.qpn = id_priv->id.qp ? id_priv->qp_num : conn_param->qp_num;
+       } else {
+               memset(&iw_param, 0, sizeof iw_param);
                iw_param.qpn = id_priv->qp_num;
-       else
-               iw_param.qpn = conn_param->qp_num;
+       }
        ret = iw_cm_connect(cm_id, &iw_param);
 out:
        if (ret) {
@@ -2765,14 +2787,20 @@ int rdma_accept(struct rdma_cm_id *id, struct rdma_conn_param *conn_param)
 
        switch (rdma_node_get_transport(id->device->node_type)) {
        case RDMA_TRANSPORT_IB:
-               if (id->qp_type == IB_QPT_UD)
-                       ret = cma_send_sidr_rep(id_priv, IB_SIDR_SUCCESS,
-                                               conn_param->private_data,
-                                               conn_param->private_data_len);
-               else if (conn_param)
-                       ret = cma_accept_ib(id_priv, conn_param);
-               else
-                       ret = cma_rep_recv(id_priv);
+               if (id->qp_type == IB_QPT_UD) {
+                       if (conn_param)
+                               ret = cma_send_sidr_rep(id_priv, IB_SIDR_SUCCESS,
+                                                       conn_param->private_data,
+                                                       conn_param->private_data_len);
+                       else
+                               ret = cma_send_sidr_rep(id_priv, IB_SIDR_SUCCESS,
+                                                       NULL, 0);
+               } else {
+                       if (conn_param)
+                               ret = cma_accept_ib(id_priv, conn_param);
+                       else
+                               ret = cma_rep_recv(id_priv);
+               }
                break;
        case RDMA_TRANSPORT_IWARP:
                ret = cma_accept_iw(id_priv, conn_param);
@@ -3460,6 +3488,7 @@ static void __exit cma_cleanup(void)
        idr_destroy(&tcp_ps);
        idr_destroy(&udp_ps);
        idr_destroy(&ipoib_ps);
+       idr_destroy(&ib_ps);
 }
 
 module_init(cma_init);
index b4d8672a3e4ef539481a4089cc25f8c7b8f38901..056389229ea7d03573e8dfa7b29520ed18a671fd 100644 (file)
@@ -1596,6 +1596,9 @@ find_mad_agent(struct ib_mad_port_private *port_priv,
                                        mad->mad_hdr.class_version].class;
                        if (!class)
                                goto out;
+                       if (convert_mgmt_class(mad->mad_hdr.mgmt_class) >=
+                           IB_MGMT_MAX_METHODS)
+                               goto out;
                        method = class->method_table[convert_mgmt_class(
                                                        mad->mad_hdr.mgmt_class)];
                        if (method)
index 9ab5df72df7bf3b3c93dfb7ef6dc21b9810592a3..2b59b72b57f9bc4fad122f085164a42a27356a6b 100644 (file)
@@ -185,17 +185,35 @@ static ssize_t rate_show(struct ib_port *p, struct port_attribute *unused,
        if (ret)
                return ret;
 
+       rate = (25 * attr.active_speed) / 10;
+
        switch (attr.active_speed) {
-       case 2: speed = " DDR"; break;
-       case 4: speed = " QDR"; break;
+       case 2:
+               speed = " DDR";
+               break;
+       case 4:
+               speed = " QDR";
+               break;
+       case 8:
+               speed = " FDR10";
+               rate = 10;
+               break;
+       case 16:
+               speed = " FDR";
+               rate = 14;
+               break;
+       case 32:
+               speed = " EDR";
+               rate = 25;
+               break;
        }
 
-       rate = 25 * ib_width_enum_to_int(attr.active_width) * attr.active_speed;
+       rate *= ib_width_enum_to_int(attr.active_width);
        if (rate < 0)
                return -EINVAL;
 
        return sprintf(buf, "%d%s Gb/sec (%dX%s)\n",
-                      rate / 10, rate % 10 ? ".5" : "",
+                      rate, (attr.active_speed == 1) ? ".5" : "",
                       ib_width_enum_to_int(attr.active_width), speed);
 }
 
index 08f948df8fa98aa933406172ee9e390ac3d3bc4e..b8a0b4a7811b08dcbe71c07efedc8858a551b023 100644 (file)
@@ -1122,7 +1122,7 @@ static ssize_t ib_ucm_write(struct file *filp, const char __user *buf,
        if (copy_from_user(&hdr, buf, sizeof(hdr)))
                return -EFAULT;
 
-       if (hdr.cmd < 0 || hdr.cmd >= ARRAY_SIZE(ucm_cmd_table))
+       if (hdr.cmd >= ARRAY_SIZE(ucm_cmd_table))
                return -EINVAL;
 
        if (hdr.in + sizeof(hdr) > len)
index 71be5eebd683a52605096ecf7745ee0d93af758d..b69307f4f6d0aad0ba3e8fbd3e832aecad8c9119 100644 (file)
@@ -276,7 +276,7 @@ static int ucma_event_handler(struct rdma_cm_id *cm_id,
        ucma_set_event_context(ctx, event, uevent);
        uevent->resp.event = event->event;
        uevent->resp.status = event->status;
-       if (cm_id->ps == RDMA_PS_UDP || cm_id->ps == RDMA_PS_IPOIB)
+       if (cm_id->qp_type == IB_QPT_UD)
                ucma_copy_ud_event(&uevent->resp.param.ud, &event->param.ud);
        else
                ucma_copy_conn_event(&uevent->resp.param.conn,
@@ -377,6 +377,9 @@ static int ucma_get_qp_type(struct rdma_ucm_create_id *cmd, enum ib_qp_type *qp_
        case RDMA_PS_IPOIB:
                *qp_type = IB_QPT_UD;
                return 0;
+       case RDMA_PS_IB:
+               *qp_type = cmd->qp_type;
+               return 0;
        default:
                return -EINVAL;
        }
@@ -1270,7 +1273,7 @@ static ssize_t ucma_write(struct file *filp, const char __user *buf,
        if (copy_from_user(&hdr, buf, sizeof(hdr)))
                return -EFAULT;
 
-       if (hdr.cmd < 0 || hdr.cmd >= ARRAY_SIZE(ucma_cmd_table))
+       if (hdr.cmd >= ARRAY_SIZE(ucma_cmd_table))
                return -EINVAL;
 
        if (hdr.in + sizeof(hdr) > len)
index b645e558876f89e49797c0971b4f55a9799c3522..9155f91d66bfb654c4118dfbf64175c067aa9d18 100644 (file)
@@ -136,7 +136,7 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
 
        down_write(&current->mm->mmap_sem);
 
-       locked     = npages + current->mm->locked_vm;
+       locked     = npages + current->mm->pinned_vm;
        lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
 
        if ((locked > lock_limit) && !capable(CAP_IPC_LOCK)) {
@@ -206,7 +206,7 @@ out:
                __ib_umem_release(context->device, umem, 0);
                kfree(umem);
        } else
-               current->mm->locked_vm = locked;
+               current->mm->pinned_vm = locked;
 
        up_write(&current->mm->mmap_sem);
        if (vma_list)
@@ -222,7 +222,7 @@ static void ib_umem_account(struct work_struct *work)
        struct ib_umem *umem = container_of(work, struct ib_umem, work);
 
        down_write(&umem->mm->mmap_sem);
-       umem->mm->locked_vm -= umem->diff;
+       umem->mm->pinned_vm -= umem->diff;
        up_write(&umem->mm->mmap_sem);
        mmput(umem->mm);
        kfree(umem);
index 8d261b6ea5feaef85091726c81df2230d38e56b0..07db22997e97a3288ffb0ed2282b7347ce7b02da 100644 (file)
@@ -458,8 +458,7 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
                goto err;
        }
 
-       if (packet->mad.hdr.id < 0 ||
-           packet->mad.hdr.id >= IB_UMAD_MAX_AGENTS) {
+       if (packet->mad.hdr.id >= IB_UMAD_MAX_AGENTS) {
                ret = -EINVAL;
                goto err;
        }
@@ -703,7 +702,7 @@ static int ib_umad_unreg_agent(struct ib_umad_file *file, u32 __user *arg)
        mutex_lock(&file->port->file_mutex);
        mutex_lock(&file->mutex);
 
-       if (id < 0 || id >= IB_UMAD_MAX_AGENTS || !__get_agent(file, id)) {
+       if (id >= IB_UMAD_MAX_AGENTS || !__get_agent(file, id)) {
                ret = -EINVAL;
                goto out;
        }
index a078e5624d22f700c0a526538e6e2926f5d2775f..5bcb2afd3dcb503871b01841c102eb45dce16cdc 100644 (file)
@@ -76,6 +76,8 @@ struct ib_uverbs_device {
        struct ib_device                       *ib_dev;
        int                                     devnum;
        struct cdev                             cdev;
+       struct rb_root                          xrcd_tree;
+       struct mutex                            xrcd_tree_mutex;
 };
 
 struct ib_uverbs_event_file {
@@ -120,6 +122,16 @@ struct ib_uevent_object {
        u32                     events_reported;
 };
 
+struct ib_uxrcd_object {
+       struct ib_uobject       uobject;
+       atomic_t                refcnt;
+};
+
+struct ib_usrq_object {
+       struct ib_uevent_object uevent;
+       struct ib_uxrcd_object *uxrcd;
+};
+
 struct ib_uqp_object {
        struct ib_uevent_object uevent;
        struct list_head        mcast_list;
@@ -142,6 +154,7 @@ extern struct idr ib_uverbs_ah_idr;
 extern struct idr ib_uverbs_cq_idr;
 extern struct idr ib_uverbs_qp_idr;
 extern struct idr ib_uverbs_srq_idr;
+extern struct idr ib_uverbs_xrcd_idr;
 
 void idr_remove_uobj(struct idr *idp, struct ib_uobject *uobj);
 
@@ -161,6 +174,7 @@ void ib_uverbs_qp_event_handler(struct ib_event *event, void *context_ptr);
 void ib_uverbs_srq_event_handler(struct ib_event *event, void *context_ptr);
 void ib_uverbs_event_handler(struct ib_event_handler *handler,
                             struct ib_event *event);
+void ib_uverbs_dealloc_xrcd(struct ib_uverbs_device *dev, struct ib_xrcd *xrcd);
 
 #define IB_UVERBS_DECLARE_CMD(name)                                    \
        ssize_t ib_uverbs_##name(struct ib_uverbs_file *file,           \
@@ -181,6 +195,7 @@ IB_UVERBS_DECLARE_CMD(poll_cq);
 IB_UVERBS_DECLARE_CMD(req_notify_cq);
 IB_UVERBS_DECLARE_CMD(destroy_cq);
 IB_UVERBS_DECLARE_CMD(create_qp);
+IB_UVERBS_DECLARE_CMD(open_qp);
 IB_UVERBS_DECLARE_CMD(query_qp);
 IB_UVERBS_DECLARE_CMD(modify_qp);
 IB_UVERBS_DECLARE_CMD(destroy_qp);
@@ -195,5 +210,8 @@ IB_UVERBS_DECLARE_CMD(create_srq);
 IB_UVERBS_DECLARE_CMD(modify_srq);
 IB_UVERBS_DECLARE_CMD(query_srq);
 IB_UVERBS_DECLARE_CMD(destroy_srq);
+IB_UVERBS_DECLARE_CMD(create_xsrq);
+IB_UVERBS_DECLARE_CMD(open_xrcd);
+IB_UVERBS_DECLARE_CMD(close_xrcd);
 
 #endif /* UVERBS_H */
index c42699285f8eb0d67745c359afadc6e125e7815d..254f1649c73438db02a916543e81d9ef1667f5e4 100644 (file)
@@ -47,6 +47,7 @@ static struct lock_class_key cq_lock_key;
 static struct lock_class_key qp_lock_key;
 static struct lock_class_key ah_lock_key;
 static struct lock_class_key srq_lock_key;
+static struct lock_class_key xrcd_lock_key;
 
 #define INIT_UDATA(udata, ibuf, obuf, ilen, olen)                      \
        do {                                                            \
@@ -255,6 +256,18 @@ static void put_srq_read(struct ib_srq *srq)
        put_uobj_read(srq->uobject);
 }
 
+static struct ib_xrcd *idr_read_xrcd(int xrcd_handle, struct ib_ucontext *context,
+                                    struct ib_uobject **uobj)
+{
+       *uobj = idr_read_uobj(&ib_uverbs_xrcd_idr, xrcd_handle, context, 0);
+       return *uobj ? (*uobj)->object : NULL;
+}
+
+static void put_xrcd_read(struct ib_uobject *uobj)
+{
+       put_uobj_read(uobj);
+}
+
 ssize_t ib_uverbs_get_context(struct ib_uverbs_file *file,
                              const char __user *buf,
                              int in_len, int out_len)
@@ -298,6 +311,7 @@ ssize_t ib_uverbs_get_context(struct ib_uverbs_file *file,
        INIT_LIST_HEAD(&ucontext->qp_list);
        INIT_LIST_HEAD(&ucontext->srq_list);
        INIT_LIST_HEAD(&ucontext->ah_list);
+       INIT_LIST_HEAD(&ucontext->xrcd_list);
        ucontext->closing = 0;
 
        resp.num_comp_vectors = file->device->num_comp_vectors;
@@ -579,6 +593,310 @@ ssize_t ib_uverbs_dealloc_pd(struct ib_uverbs_file *file,
        return in_len;
 }
 
+struct xrcd_table_entry {
+       struct rb_node  node;
+       struct ib_xrcd *xrcd;
+       struct inode   *inode;
+};
+
+static int xrcd_table_insert(struct ib_uverbs_device *dev,
+                           struct inode *inode,
+                           struct ib_xrcd *xrcd)
+{
+       struct xrcd_table_entry *entry, *scan;
+       struct rb_node **p = &dev->xrcd_tree.rb_node;
+       struct rb_node *parent = NULL;
+
+       entry = kmalloc(sizeof *entry, GFP_KERNEL);
+       if (!entry)
+               return -ENOMEM;
+
+       entry->xrcd  = xrcd;
+       entry->inode = inode;
+
+       while (*p) {
+               parent = *p;
+               scan = rb_entry(parent, struct xrcd_table_entry, node);
+
+               if (inode < scan->inode) {
+                       p = &(*p)->rb_left;
+               } else if (inode > scan->inode) {
+                       p = &(*p)->rb_right;
+               } else {
+                       kfree(entry);
+                       return -EEXIST;
+               }
+       }
+
+       rb_link_node(&entry->node, parent, p);
+       rb_insert_color(&entry->node, &dev->xrcd_tree);
+       igrab(inode);
+       return 0;
+}
+
+static struct xrcd_table_entry *xrcd_table_search(struct ib_uverbs_device *dev,
+                                                 struct inode *inode)
+{
+       struct xrcd_table_entry *entry;
+       struct rb_node *p = dev->xrcd_tree.rb_node;
+
+       while (p) {
+               entry = rb_entry(p, struct xrcd_table_entry, node);
+
+               if (inode < entry->inode)
+                       p = p->rb_left;
+               else if (inode > entry->inode)
+                       p = p->rb_right;
+               else
+                       return entry;
+       }
+
+       return NULL;
+}
+
+static struct ib_xrcd *find_xrcd(struct ib_uverbs_device *dev, struct inode *inode)
+{
+       struct xrcd_table_entry *entry;
+
+       entry = xrcd_table_search(dev, inode);
+       if (!entry)
+               return NULL;
+
+       return entry->xrcd;
+}
+
+static void xrcd_table_delete(struct ib_uverbs_device *dev,
+                             struct inode *inode)
+{
+       struct xrcd_table_entry *entry;
+
+       entry = xrcd_table_search(dev, inode);
+       if (entry) {
+               iput(inode);
+               rb_erase(&entry->node, &dev->xrcd_tree);
+               kfree(entry);
+       }
+}
+
+ssize_t ib_uverbs_open_xrcd(struct ib_uverbs_file *file,
+                           const char __user *buf, int in_len,
+                           int out_len)
+{
+       struct ib_uverbs_open_xrcd      cmd;
+       struct ib_uverbs_open_xrcd_resp resp;
+       struct ib_udata                 udata;
+       struct ib_uxrcd_object         *obj;
+       struct ib_xrcd                 *xrcd = NULL;
+       struct file                    *f = NULL;
+       struct inode                   *inode = NULL;
+       int                             ret = 0;
+       int                             new_xrcd = 0;
+
+       if (out_len < sizeof resp)
+               return -ENOSPC;
+
+       if (copy_from_user(&cmd, buf, sizeof cmd))
+               return -EFAULT;
+
+       INIT_UDATA(&udata, buf + sizeof cmd,
+                  (unsigned long) cmd.response + sizeof resp,
+                  in_len - sizeof cmd, out_len - sizeof  resp);
+
+       mutex_lock(&file->device->xrcd_tree_mutex);
+
+       if (cmd.fd != -1) {
+               /* search for file descriptor */
+               f = fget(cmd.fd);
+               if (!f) {
+                       ret = -EBADF;
+                       goto err_tree_mutex_unlock;
+               }
+
+               inode = f->f_dentry->d_inode;
+               if (!inode) {
+                       ret = -EBADF;
+                       goto err_tree_mutex_unlock;
+               }
+
+               xrcd = find_xrcd(file->device, inode);
+               if (!xrcd && !(cmd.oflags & O_CREAT)) {
+                       /* no file descriptor. Need CREATE flag */
+                       ret = -EAGAIN;
+                       goto err_tree_mutex_unlock;
+               }
+
+               if (xrcd && cmd.oflags & O_EXCL) {
+                       ret = -EINVAL;
+                       goto err_tree_mutex_unlock;
+               }
+       }
+
+       obj = kmalloc(sizeof *obj, GFP_KERNEL);
+       if (!obj) {
+               ret = -ENOMEM;
+               goto err_tree_mutex_unlock;
+       }
+
+       init_uobj(&obj->uobject, 0, file->ucontext, &xrcd_lock_key);
+
+       down_write(&obj->uobject.mutex);
+
+       if (!xrcd) {
+               xrcd = file->device->ib_dev->alloc_xrcd(file->device->ib_dev,
+                                                       file->ucontext, &udata);
+               if (IS_ERR(xrcd)) {
+                       ret = PTR_ERR(xrcd);
+                       goto err;
+               }
+
+               xrcd->inode   = inode;
+               xrcd->device  = file->device->ib_dev;
+               atomic_set(&xrcd->usecnt, 0);
+               mutex_init(&xrcd->tgt_qp_mutex);
+               INIT_LIST_HEAD(&xrcd->tgt_qp_list);
+               new_xrcd = 1;
+       }
+
+       atomic_set(&obj->refcnt, 0);
+       obj->uobject.object = xrcd;
+       ret = idr_add_uobj(&ib_uverbs_xrcd_idr, &obj->uobject);
+       if (ret)
+               goto err_idr;
+
+       memset(&resp, 0, sizeof resp);
+       resp.xrcd_handle = obj->uobject.id;
+
+       if (inode) {
+               if (new_xrcd) {
+                       /* create new inode/xrcd table entry */
+                       ret = xrcd_table_insert(file->device, inode, xrcd);
+                       if (ret)
+                               goto err_insert_xrcd;
+               }
+               atomic_inc(&xrcd->usecnt);
+       }
+
+       if (copy_to_user((void __user *) (unsigned long) cmd.response,
+                        &resp, sizeof resp)) {
+               ret = -EFAULT;
+               goto err_copy;
+       }
+
+       if (f)
+               fput(f);
+
+       mutex_lock(&file->mutex);
+       list_add_tail(&obj->uobject.list, &file->ucontext->xrcd_list);
+       mutex_unlock(&file->mutex);
+
+       obj->uobject.live = 1;
+       up_write(&obj->uobject.mutex);
+
+       mutex_unlock(&file->device->xrcd_tree_mutex);
+       return in_len;
+
+err_copy:
+       if (inode) {
+               if (new_xrcd)
+                       xrcd_table_delete(file->device, inode);
+               atomic_dec(&xrcd->usecnt);
+       }
+
+err_insert_xrcd:
+       idr_remove_uobj(&ib_uverbs_xrcd_idr, &obj->uobject);
+
+err_idr:
+       ib_dealloc_xrcd(xrcd);
+
+err:
+       put_uobj_write(&obj->uobject);
+
+err_tree_mutex_unlock:
+       if (f)
+               fput(f);
+
+       mutex_unlock(&file->device->xrcd_tree_mutex);
+
+       return ret;
+}
+
+ssize_t ib_uverbs_close_xrcd(struct ib_uverbs_file *file,
+                            const char __user *buf, int in_len,
+                            int out_len)
+{
+       struct ib_uverbs_close_xrcd cmd;
+       struct ib_uobject           *uobj;
+       struct ib_xrcd              *xrcd = NULL;
+       struct inode                *inode = NULL;
+       struct ib_uxrcd_object      *obj;
+       int                         live;
+       int                         ret = 0;
+
+       if (copy_from_user(&cmd, buf, sizeof cmd))
+               return -EFAULT;
+
+       mutex_lock(&file->device->xrcd_tree_mutex);
+       uobj = idr_write_uobj(&ib_uverbs_xrcd_idr, cmd.xrcd_handle, file->ucontext);
+       if (!uobj) {
+               ret = -EINVAL;
+               goto out;
+       }
+
+       xrcd  = uobj->object;
+       inode = xrcd->inode;
+       obj   = container_of(uobj, struct ib_uxrcd_object, uobject);
+       if (atomic_read(&obj->refcnt)) {
+               put_uobj_write(uobj);
+               ret = -EBUSY;
+               goto out;
+       }
+
+       if (!inode || atomic_dec_and_test(&xrcd->usecnt)) {
+               ret = ib_dealloc_xrcd(uobj->object);
+               if (!ret)
+                       uobj->live = 0;
+       }
+
+       live = uobj->live;
+       if (inode && ret)
+               atomic_inc(&xrcd->usecnt);
+
+       put_uobj_write(uobj);
+
+       if (ret)
+               goto out;
+
+       if (inode && !live)
+               xrcd_table_delete(file->device, inode);
+
+       idr_remove_uobj(&ib_uverbs_xrcd_idr, uobj);
+       mutex_lock(&file->mutex);
+       list_del(&uobj->list);
+       mutex_unlock(&file->mutex);
+
+       put_uobj(uobj);
+       ret = in_len;
+
+out:
+       mutex_unlock(&file->device->xrcd_tree_mutex);
+       return ret;
+}
+
+void ib_uverbs_dealloc_xrcd(struct ib_uverbs_device *dev,
+                           struct ib_xrcd *xrcd)
+{
+       struct inode *inode;
+
+       inode = xrcd->inode;
+       if (inode && !atomic_dec_and_test(&xrcd->usecnt))
+               return;
+
+       ib_dealloc_xrcd(xrcd);
+
+       if (inode)
+               xrcd_table_delete(dev, inode);
+}
+
 ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file,
                         const char __user *buf, int in_len,
                         int out_len)
@@ -1052,9 +1370,12 @@ ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file,
        struct ib_uverbs_create_qp_resp resp;
        struct ib_udata                 udata;
        struct ib_uqp_object           *obj;
-       struct ib_pd                   *pd;
-       struct ib_cq                   *scq, *rcq;
-       struct ib_srq                  *srq;
+       struct ib_device               *device;
+       struct ib_pd                   *pd = NULL;
+       struct ib_xrcd                 *xrcd = NULL;
+       struct ib_uobject              *uninitialized_var(xrcd_uobj);
+       struct ib_cq                   *scq = NULL, *rcq = NULL;
+       struct ib_srq                  *srq = NULL;
        struct ib_qp                   *qp;
        struct ib_qp_init_attr          attr;
        int ret;
@@ -1076,15 +1397,39 @@ ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file,
        init_uobj(&obj->uevent.uobject, cmd.user_handle, file->ucontext, &qp_lock_key);
        down_write(&obj->uevent.uobject.mutex);
 
-       srq = cmd.is_srq ? idr_read_srq(cmd.srq_handle, file->ucontext) : NULL;
-       pd  = idr_read_pd(cmd.pd_handle, file->ucontext);
-       scq = idr_read_cq(cmd.send_cq_handle, file->ucontext, 0);
-       rcq = cmd.recv_cq_handle == cmd.send_cq_handle ?
-               scq : idr_read_cq(cmd.recv_cq_handle, file->ucontext, 1);
+       if (cmd.qp_type == IB_QPT_XRC_TGT) {
+               xrcd = idr_read_xrcd(cmd.pd_handle, file->ucontext, &xrcd_uobj);
+               if (!xrcd) {
+                       ret = -EINVAL;
+                       goto err_put;
+               }
+               device = xrcd->device;
+       } else {
+               pd  = idr_read_pd(cmd.pd_handle, file->ucontext);
+               scq = idr_read_cq(cmd.send_cq_handle, file->ucontext, 0);
+               if (!pd || !scq) {
+                       ret = -EINVAL;
+                       goto err_put;
+               }
 
-       if (!pd || !scq || !rcq || (cmd.is_srq && !srq)) {
-               ret = -EINVAL;
-               goto err_put;
+               if (cmd.qp_type == IB_QPT_XRC_INI) {
+                       cmd.max_recv_wr = cmd.max_recv_sge = 0;
+               } else {
+                       if (cmd.is_srq) {
+                               srq = idr_read_srq(cmd.srq_handle, file->ucontext);
+                               if (!srq || srq->srq_type != IB_SRQT_BASIC) {
+                                       ret = -EINVAL;
+                                       goto err_put;
+                               }
+                       }
+                       rcq = (cmd.recv_cq_handle == cmd.send_cq_handle) ?
+                              scq : idr_read_cq(cmd.recv_cq_handle, file->ucontext, 1);
+                       if (!rcq) {
+                               ret = -EINVAL;
+                               goto err_put;
+                       }
+               }
+               device = pd->device;
        }
 
        attr.event_handler = ib_uverbs_qp_event_handler;
@@ -1092,6 +1437,7 @@ ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file,
        attr.send_cq       = scq;
        attr.recv_cq       = rcq;
        attr.srq           = srq;
+       attr.xrcd          = xrcd;
        attr.sq_sig_type   = cmd.sq_sig_all ? IB_SIGNAL_ALL_WR : IB_SIGNAL_REQ_WR;
        attr.qp_type       = cmd.qp_type;
        attr.create_flags  = 0;
@@ -1106,26 +1452,34 @@ ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file,
        INIT_LIST_HEAD(&obj->uevent.event_list);
        INIT_LIST_HEAD(&obj->mcast_list);
 
-       qp = pd->device->create_qp(pd, &attr, &udata);
+       if (cmd.qp_type == IB_QPT_XRC_TGT)
+               qp = ib_create_qp(pd, &attr);
+       else
+               qp = device->create_qp(pd, &attr, &udata);
+
        if (IS_ERR(qp)) {
                ret = PTR_ERR(qp);
                goto err_put;
        }
 
-       qp->device        = pd->device;
-       qp->pd            = pd;
-       qp->send_cq       = attr.send_cq;
-       qp->recv_cq       = attr.recv_cq;
-       qp->srq           = attr.srq;
-       qp->uobject       = &obj->uevent.uobject;
-       qp->event_handler = attr.event_handler;
-       qp->qp_context    = attr.qp_context;
-       qp->qp_type       = attr.qp_type;
-       atomic_inc(&pd->usecnt);
-       atomic_inc(&attr.send_cq->usecnt);
-       atomic_inc(&attr.recv_cq->usecnt);
-       if (attr.srq)
-               atomic_inc(&attr.srq->usecnt);
+       if (cmd.qp_type != IB_QPT_XRC_TGT) {
+               qp->real_qp       = qp;
+               qp->device        = device;
+               qp->pd            = pd;
+               qp->send_cq       = attr.send_cq;
+               qp->recv_cq       = attr.recv_cq;
+               qp->srq           = attr.srq;
+               qp->event_handler = attr.event_handler;
+               qp->qp_context    = attr.qp_context;
+               qp->qp_type       = attr.qp_type;
+               atomic_inc(&pd->usecnt);
+               atomic_inc(&attr.send_cq->usecnt);
+               if (attr.recv_cq)
+                       atomic_inc(&attr.recv_cq->usecnt);
+               if (attr.srq)
+                       atomic_inc(&attr.srq->usecnt);
+       }
+       qp->uobject = &obj->uevent.uobject;
 
        obj->uevent.uobject.object = qp;
        ret = idr_add_uobj(&ib_uverbs_qp_idr, &obj->uevent.uobject);
@@ -1147,9 +1501,13 @@ ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file,
                goto err_copy;
        }
 
-       put_pd_read(pd);
-       put_cq_read(scq);
-       if (rcq != scq)
+       if (xrcd)
+               put_xrcd_read(xrcd_uobj);
+       if (pd)
+               put_pd_read(pd);
+       if (scq)
+               put_cq_read(scq);
+       if (rcq && rcq != scq)
                put_cq_read(rcq);
        if (srq)
                put_srq_read(srq);
@@ -1171,6 +1529,8 @@ err_destroy:
        ib_destroy_qp(qp);
 
 err_put:
+       if (xrcd)
+               put_xrcd_read(xrcd_uobj);
        if (pd)
                put_pd_read(pd);
        if (scq)
@@ -1184,6 +1544,98 @@ err_put:
        return ret;
 }
 
+ssize_t ib_uverbs_open_qp(struct ib_uverbs_file *file,
+                         const char __user *buf, int in_len, int out_len)
+{
+       struct ib_uverbs_open_qp        cmd;
+       struct ib_uverbs_create_qp_resp resp;
+       struct ib_udata                 udata;
+       struct ib_uqp_object           *obj;
+       struct ib_xrcd                 *xrcd;
+       struct ib_uobject              *uninitialized_var(xrcd_uobj);
+       struct ib_qp                   *qp;
+       struct ib_qp_open_attr          attr;
+       int ret;
+
+       if (out_len < sizeof resp)
+               return -ENOSPC;
+
+       if (copy_from_user(&cmd, buf, sizeof cmd))
+               return -EFAULT;
+
+       INIT_UDATA(&udata, buf + sizeof cmd,
+                  (unsigned long) cmd.response + sizeof resp,
+                  in_len - sizeof cmd, out_len - sizeof resp);
+
+       obj = kmalloc(sizeof *obj, GFP_KERNEL);
+       if (!obj)
+               return -ENOMEM;
+
+       init_uobj(&obj->uevent.uobject, cmd.user_handle, file->ucontext, &qp_lock_key);
+       down_write(&obj->uevent.uobject.mutex);
+
+       xrcd = idr_read_xrcd(cmd.pd_handle, file->ucontext, &xrcd_uobj);
+       if (!xrcd) {
+               ret = -EINVAL;
+               goto err_put;
+       }
+
+       attr.event_handler = ib_uverbs_qp_event_handler;
+       attr.qp_context    = file;
+       attr.qp_num        = cmd.qpn;
+       attr.qp_type       = cmd.qp_type;
+
+       obj->uevent.events_reported = 0;
+       INIT_LIST_HEAD(&obj->uevent.event_list);
+       INIT_LIST_HEAD(&obj->mcast_list);
+
+       qp = ib_open_qp(xrcd, &attr);
+       if (IS_ERR(qp)) {
+               ret = PTR_ERR(qp);
+               goto err_put;
+       }
+
+       qp->uobject = &obj->uevent.uobject;
+
+       obj->uevent.uobject.object = qp;
+       ret = idr_add_uobj(&ib_uverbs_qp_idr, &obj->uevent.uobject);
+       if (ret)
+               goto err_destroy;
+
+       memset(&resp, 0, sizeof resp);
+       resp.qpn       = qp->qp_num;
+       resp.qp_handle = obj->uevent.uobject.id;
+
+       if (copy_to_user((void __user *) (unsigned long) cmd.response,
+                        &resp, sizeof resp)) {
+               ret = -EFAULT;
+               goto err_remove;
+       }
+
+       put_xrcd_read(xrcd_uobj);
+
+       mutex_lock(&file->mutex);
+       list_add_tail(&obj->uevent.uobject.list, &file->ucontext->qp_list);
+       mutex_unlock(&file->mutex);
+
+       obj->uevent.uobject.live = 1;
+
+       up_write(&obj->uevent.uobject.mutex);
+
+       return in_len;
+
+err_remove:
+       idr_remove_uobj(&ib_uverbs_qp_idr, &obj->uevent.uobject);
+
+err_destroy:
+       ib_destroy_qp(qp);
+
+err_put:
+       put_xrcd_read(xrcd_uobj);
+       put_uobj_write(&obj->uevent.uobject);
+       return ret;
+}
+
 ssize_t ib_uverbs_query_qp(struct ib_uverbs_file *file,
                           const char __user *buf, int in_len,
                           int out_len)
@@ -1284,6 +1736,20 @@ out:
        return ret ? ret : in_len;
 }
 
+/* Remove ignored fields set in the attribute mask */
+static int modify_qp_mask(enum ib_qp_type qp_type, int mask)
+{
+       switch (qp_type) {
+       case IB_QPT_XRC_INI:
+               return mask & ~(IB_QP_MAX_DEST_RD_ATOMIC | IB_QP_MIN_RNR_TIMER);
+       case IB_QPT_XRC_TGT:
+               return mask & ~(IB_QP_MAX_QP_RD_ATOMIC | IB_QP_RETRY_CNT |
+                               IB_QP_RNR_RETRY);
+       default:
+               return mask;
+       }
+}
+
 ssize_t ib_uverbs_modify_qp(struct ib_uverbs_file *file,
                            const char __user *buf, int in_len,
                            int out_len)
@@ -1356,7 +1822,12 @@ ssize_t ib_uverbs_modify_qp(struct ib_uverbs_file *file,
        attr->alt_ah_attr.ah_flags          = cmd.alt_dest.is_global ? IB_AH_GRH : 0;
        attr->alt_ah_attr.port_num          = cmd.alt_dest.port_num;
 
-       ret = qp->device->modify_qp(qp, attr, cmd.attr_mask, &udata);
+       if (qp->real_qp == qp) {
+               ret = qp->device->modify_qp(qp, attr,
+                       modify_qp_mask(qp->qp_type, cmd.attr_mask), &udata);
+       } else {
+               ret = ib_modify_qp(qp, attr, modify_qp_mask(qp->qp_type, cmd.attr_mask));
+       }
 
        put_qp_read(qp);
 
@@ -1553,7 +2024,7 @@ ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file,
        }
 
        resp.bad_wr = 0;
-       ret = qp->device->post_send(qp, wr, &bad_wr);
+       ret = qp->device->post_send(qp->real_qp, wr, &bad_wr);
        if (ret)
                for (next = wr; next; next = next->next) {
                        ++resp.bad_wr;
@@ -1691,7 +2162,7 @@ ssize_t ib_uverbs_post_recv(struct ib_uverbs_file *file,
                goto out;
 
        resp.bad_wr = 0;
-       ret = qp->device->post_recv(qp, wr, &bad_wr);
+       ret = qp->device->post_recv(qp->real_qp, wr, &bad_wr);
 
        put_qp_read(qp);
 
@@ -1975,107 +2446,199 @@ out_put:
        return ret ? ret : in_len;
 }
 
-ssize_t ib_uverbs_create_srq(struct ib_uverbs_file *file,
-                            const char __user *buf, int in_len,
-                            int out_len)
+int __uverbs_create_xsrq(struct ib_uverbs_file *file,
+                        struct ib_uverbs_create_xsrq *cmd,
+                        struct ib_udata *udata)
 {
-       struct ib_uverbs_create_srq      cmd;
        struct ib_uverbs_create_srq_resp resp;
-       struct ib_udata                  udata;
-       struct ib_uevent_object         *obj;
+       struct ib_usrq_object           *obj;
        struct ib_pd                    *pd;
        struct ib_srq                   *srq;
+       struct ib_uobject               *uninitialized_var(xrcd_uobj);
        struct ib_srq_init_attr          attr;
        int ret;
 
-       if (out_len < sizeof resp)
-               return -ENOSPC;
-
-       if (copy_from_user(&cmd, buf, sizeof cmd))
-               return -EFAULT;
-
-       INIT_UDATA(&udata, buf + sizeof cmd,
-                  (unsigned long) cmd.response + sizeof resp,
-                  in_len - sizeof cmd, out_len - sizeof resp);
-
        obj = kmalloc(sizeof *obj, GFP_KERNEL);
        if (!obj)
                return -ENOMEM;
 
-       init_uobj(&obj->uobject, cmd.user_handle, file->ucontext, &srq_lock_key);
-       down_write(&obj->uobject.mutex);
+       init_uobj(&obj->uevent.uobject, cmd->user_handle, file->ucontext, &srq_lock_key);
+       down_write(&obj->uevent.uobject.mutex);
 
-       pd  = idr_read_pd(cmd.pd_handle, file->ucontext);
+       pd  = idr_read_pd(cmd->pd_handle, file->ucontext);
        if (!pd) {
                ret = -EINVAL;
                goto err;
        }
 
+       if (cmd->srq_type == IB_SRQT_XRC) {
+               attr.ext.xrc.cq  = idr_read_cq(cmd->cq_handle, file->ucontext, 0);
+               if (!attr.ext.xrc.cq) {
+                       ret = -EINVAL;
+                       goto err_put_pd;
+               }
+
+               attr.ext.xrc.xrcd  = idr_read_xrcd(cmd->xrcd_handle, file->ucontext, &xrcd_uobj);
+               if (!attr.ext.xrc.xrcd) {
+                       ret = -EINVAL;
+                       goto err_put_cq;
+               }
+
+               obj->uxrcd = container_of(xrcd_uobj, struct ib_uxrcd_object, uobject);
+               atomic_inc(&obj->uxrcd->refcnt);
+       }
+
        attr.event_handler  = ib_uverbs_srq_event_handler;
        attr.srq_context    = file;
-       attr.attr.max_wr    = cmd.max_wr;
-       attr.attr.max_sge   = cmd.max_sge;
-       attr.attr.srq_limit = cmd.srq_limit;
+       attr.srq_type       = cmd->srq_type;
+       attr.attr.max_wr    = cmd->max_wr;
+       attr.attr.max_sge   = cmd->max_sge;
+       attr.attr.srq_limit = cmd->srq_limit;
 
-       obj->events_reported     = 0;
-       INIT_LIST_HEAD(&obj->event_list);
+       obj->uevent.events_reported = 0;
+       INIT_LIST_HEAD(&obj->uevent.event_list);
 
-       srq = pd->device->create_srq(pd, &attr, &udata);
+       srq = pd->device->create_srq(pd, &attr, udata);
        if (IS_ERR(srq)) {
                ret = PTR_ERR(srq);
                goto err_put;
        }
 
-       srq->device        = pd->device;
-       srq->pd            = pd;
-       srq->uobject       = &obj->uobject;
+       srq->device        = pd->device;
+       srq->pd            = pd;
+       srq->srq_type      = cmd->srq_type;
+       srq->uobject       = &obj->uevent.uobject;
        srq->event_handler = attr.event_handler;
        srq->srq_context   = attr.srq_context;
+
+       if (cmd->srq_type == IB_SRQT_XRC) {
+               srq->ext.xrc.cq   = attr.ext.xrc.cq;
+               srq->ext.xrc.xrcd = attr.ext.xrc.xrcd;
+               atomic_inc(&attr.ext.xrc.cq->usecnt);
+               atomic_inc(&attr.ext.xrc.xrcd->usecnt);
+       }
+
        atomic_inc(&pd->usecnt);
        atomic_set(&srq->usecnt, 0);
 
-       obj->uobject.object = srq;
-       ret = idr_add_uobj(&ib_uverbs_srq_idr, &obj->uobject);
+       obj->uevent.uobject.object = srq;
+       ret = idr_add_uobj(&ib_uverbs_srq_idr, &obj->uevent.uobject);
        if (ret)
                goto err_destroy;
 
        memset(&resp, 0, sizeof resp);
-       resp.srq_handle = obj->uobject.id;
+       resp.srq_handle = obj->uevent.uobject.id;
        resp.max_wr     = attr.attr.max_wr;
        resp.max_sge    = attr.attr.max_sge;
+       if (cmd->srq_type == IB_SRQT_XRC)
+               resp.srqn = srq->ext.xrc.srq_num;
 
-       if (copy_to_user((void __user *) (unsigned long) cmd.response,
+       if (copy_to_user((void __user *) (unsigned long) cmd->response,
                         &resp, sizeof resp)) {
                ret = -EFAULT;
                goto err_copy;
        }
 
+       if (cmd->srq_type == IB_SRQT_XRC) {
+               put_uobj_read(xrcd_uobj);
+               put_cq_read(attr.ext.xrc.cq);
+       }
        put_pd_read(pd);
 
        mutex_lock(&file->mutex);
-       list_add_tail(&obj->uobject.list, &file->ucontext->srq_list);
+       list_add_tail(&obj->uevent.uobject.list, &file->ucontext->srq_list);
        mutex_unlock(&file->mutex);
 
-       obj->uobject.live = 1;
+       obj->uevent.uobject.live = 1;
 
-       up_write(&obj->uobject.mutex);
+       up_write(&obj->uevent.uobject.mutex);
 
-       return in_len;
+       return 0;
 
 err_copy:
-       idr_remove_uobj(&ib_uverbs_srq_idr, &obj->uobject);
+       idr_remove_uobj(&ib_uverbs_srq_idr, &obj->uevent.uobject);
 
 err_destroy:
        ib_destroy_srq(srq);
 
 err_put:
+       if (cmd->srq_type == IB_SRQT_XRC) {
+               atomic_dec(&obj->uxrcd->refcnt);
+               put_uobj_read(xrcd_uobj);
+       }
+
+err_put_cq:
+       if (cmd->srq_type == IB_SRQT_XRC)
+               put_cq_read(attr.ext.xrc.cq);
+
+err_put_pd:
        put_pd_read(pd);
 
 err:
-       put_uobj_write(&obj->uobject);
+       put_uobj_write(&obj->uevent.uobject);
        return ret;
 }
 
+ssize_t ib_uverbs_create_srq(struct ib_uverbs_file *file,
+                            const char __user *buf, int in_len,
+                            int out_len)
+{
+       struct ib_uverbs_create_srq      cmd;
+       struct ib_uverbs_create_xsrq     xcmd;
+       struct ib_uverbs_create_srq_resp resp;
+       struct ib_udata                  udata;
+       int ret;
+
+       if (out_len < sizeof resp)
+               return -ENOSPC;
+
+       if (copy_from_user(&cmd, buf, sizeof cmd))
+               return -EFAULT;
+
+       xcmd.response    = cmd.response;
+       xcmd.user_handle = cmd.user_handle;
+       xcmd.srq_type    = IB_SRQT_BASIC;
+       xcmd.pd_handle   = cmd.pd_handle;
+       xcmd.max_wr      = cmd.max_wr;
+       xcmd.max_sge     = cmd.max_sge;
+       xcmd.srq_limit   = cmd.srq_limit;
+
+       INIT_UDATA(&udata, buf + sizeof cmd,
+                  (unsigned long) cmd.response + sizeof resp,
+                  in_len - sizeof cmd, out_len - sizeof resp);
+
+       ret = __uverbs_create_xsrq(file, &xcmd, &udata);
+       if (ret)
+               return ret;
+
+       return in_len;
+}
+
+ssize_t ib_uverbs_create_xsrq(struct ib_uverbs_file *file,
+                             const char __user *buf, int in_len, int out_len)
+{
+       struct ib_uverbs_create_xsrq     cmd;
+       struct ib_uverbs_create_srq_resp resp;
+       struct ib_udata                  udata;
+       int ret;
+
+       if (out_len < sizeof resp)
+               return -ENOSPC;
+
+       if (copy_from_user(&cmd, buf, sizeof cmd))
+               return -EFAULT;
+
+       INIT_UDATA(&udata, buf + sizeof cmd,
+                  (unsigned long) cmd.response + sizeof resp,
+                  in_len - sizeof cmd, out_len - sizeof resp);
+
+       ret = __uverbs_create_xsrq(file, &cmd, &udata);
+       if (ret)
+               return ret;
+
+       return in_len;
+}
+
 ssize_t ib_uverbs_modify_srq(struct ib_uverbs_file *file,
                             const char __user *buf, int in_len,
                             int out_len)
index 56898b6578a49e4e4b3d006763b6f6a861a78d93..879636746373d34d0cc22ff595f4adeb80091679 100644 (file)
@@ -72,6 +72,7 @@ DEFINE_IDR(ib_uverbs_ah_idr);
 DEFINE_IDR(ib_uverbs_cq_idr);
 DEFINE_IDR(ib_uverbs_qp_idr);
 DEFINE_IDR(ib_uverbs_srq_idr);
+DEFINE_IDR(ib_uverbs_xrcd_idr);
 
 static DEFINE_SPINLOCK(map_lock);
 static DECLARE_BITMAP(dev_map, IB_UVERBS_MAX_DEVICES);
@@ -107,6 +108,10 @@ static ssize_t (*uverbs_cmd_table[])(struct ib_uverbs_file *file,
        [IB_USER_VERBS_CMD_MODIFY_SRQ]          = ib_uverbs_modify_srq,
        [IB_USER_VERBS_CMD_QUERY_SRQ]           = ib_uverbs_query_srq,
        [IB_USER_VERBS_CMD_DESTROY_SRQ]         = ib_uverbs_destroy_srq,
+       [IB_USER_VERBS_CMD_OPEN_XRCD]           = ib_uverbs_open_xrcd,
+       [IB_USER_VERBS_CMD_CLOSE_XRCD]          = ib_uverbs_close_xrcd,
+       [IB_USER_VERBS_CMD_CREATE_XSRQ]         = ib_uverbs_create_xsrq,
+       [IB_USER_VERBS_CMD_OPEN_QP]             = ib_uverbs_open_qp
 };
 
 static void ib_uverbs_add_one(struct ib_device *device);
@@ -202,8 +207,12 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,
                        container_of(uobj, struct ib_uqp_object, uevent.uobject);
 
                idr_remove_uobj(&ib_uverbs_qp_idr, uobj);
-               ib_uverbs_detach_umcast(qp, uqp);
-               ib_destroy_qp(qp);
+               if (qp != qp->real_qp) {
+                       ib_close_qp(qp);
+               } else {
+                       ib_uverbs_detach_umcast(qp, uqp);
+                       ib_destroy_qp(qp);
+               }
                ib_uverbs_release_uevent(file, &uqp->uevent);
                kfree(uqp);
        }
@@ -241,6 +250,18 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,
                kfree(uobj);
        }
 
+       mutex_lock(&file->device->xrcd_tree_mutex);
+       list_for_each_entry_safe(uobj, tmp, &context->xrcd_list, list) {
+               struct ib_xrcd *xrcd = uobj->object;
+               struct ib_uxrcd_object *uxrcd =
+                       container_of(uobj, struct ib_uxrcd_object, uobject);
+
+               idr_remove_uobj(&ib_uverbs_xrcd_idr, uobj);
+               ib_uverbs_dealloc_xrcd(file->device, xrcd);
+               kfree(uxrcd);
+       }
+       mutex_unlock(&file->device->xrcd_tree_mutex);
+
        list_for_each_entry_safe(uobj, tmp, &context->pd_list, list) {
                struct ib_pd *pd = uobj->object;
 
@@ -557,8 +578,7 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
        if (hdr.in_words * 4 != count)
                return -EINVAL;
 
-       if (hdr.command < 0                             ||
-           hdr.command >= ARRAY_SIZE(uverbs_cmd_table) ||
+       if (hdr.command >= ARRAY_SIZE(uverbs_cmd_table) ||
            !uverbs_cmd_table[hdr.command])
                return -EINVAL;
 
@@ -741,6 +761,8 @@ static void ib_uverbs_add_one(struct ib_device *device)
 
        kref_init(&uverbs_dev->ref);
        init_completion(&uverbs_dev->comp);
+       uverbs_dev->xrcd_tree = RB_ROOT;
+       mutex_init(&uverbs_dev->xrcd_tree_mutex);
 
        spin_lock(&map_lock);
        devnum = find_first_zero_bit(dev_map, IB_UVERBS_MAX_DEVICES);
index af7a8b08b2e95abe26704c747ba68bea63e97937..42517500b223e98b0e9dd265e799233057dde9f4 100644 (file)
@@ -39,6 +39,7 @@
 #include <linux/errno.h>
 #include <linux/err.h>
 #include <linux/string.h>
+#include <linux/slab.h>
 
 #include <rdma/ib_verbs.h>
 #include <rdma/ib_cache.h>
@@ -77,6 +78,31 @@ enum ib_rate mult_to_ib_rate(int mult)
 }
 EXPORT_SYMBOL(mult_to_ib_rate);
 
+int ib_rate_to_mbps(enum ib_rate rate)
+{
+       switch (rate) {
+       case IB_RATE_2_5_GBPS: return 2500;
+       case IB_RATE_5_GBPS:   return 5000;
+       case IB_RATE_10_GBPS:  return 10000;
+       case IB_RATE_20_GBPS:  return 20000;
+       case IB_RATE_30_GBPS:  return 30000;
+       case IB_RATE_40_GBPS:  return 40000;
+       case IB_RATE_60_GBPS:  return 60000;
+       case IB_RATE_80_GBPS:  return 80000;
+       case IB_RATE_120_GBPS: return 120000;
+       case IB_RATE_14_GBPS:  return 14062;
+       case IB_RATE_56_GBPS:  return 56250;
+       case IB_RATE_112_GBPS: return 112500;
+       case IB_RATE_168_GBPS: return 168750;
+       case IB_RATE_25_GBPS:  return 25781;
+       case IB_RATE_100_GBPS: return 103125;
+       case IB_RATE_200_GBPS: return 206250;
+       case IB_RATE_300_GBPS: return 309375;
+       default:               return -1;
+       }
+}
+EXPORT_SYMBOL(ib_rate_to_mbps);
+
 enum rdma_transport_type
 rdma_node_get_transport(enum rdma_node_type node_type)
 {
@@ -250,6 +276,13 @@ struct ib_srq *ib_create_srq(struct ib_pd *pd,
                srq->uobject       = NULL;
                srq->event_handler = srq_init_attr->event_handler;
                srq->srq_context   = srq_init_attr->srq_context;
+               srq->srq_type      = srq_init_attr->srq_type;
+               if (srq->srq_type == IB_SRQT_XRC) {
+                       srq->ext.xrc.xrcd = srq_init_attr->ext.xrc.xrcd;
+                       srq->ext.xrc.cq   = srq_init_attr->ext.xrc.cq;
+                       atomic_inc(&srq->ext.xrc.xrcd->usecnt);
+                       atomic_inc(&srq->ext.xrc.cq->usecnt);
+               }
                atomic_inc(&pd->usecnt);
                atomic_set(&srq->usecnt, 0);
        }
@@ -279,16 +312,29 @@ EXPORT_SYMBOL(ib_query_srq);
 int ib_destroy_srq(struct ib_srq *srq)
 {
        struct ib_pd *pd;
+       enum ib_srq_type srq_type;
+       struct ib_xrcd *uninitialized_var(xrcd);
+       struct ib_cq *uninitialized_var(cq);
        int ret;
 
        if (atomic_read(&srq->usecnt))
                return -EBUSY;
 
        pd = srq->pd;
+       srq_type = srq->srq_type;
+       if (srq_type == IB_SRQT_XRC) {
+               xrcd = srq->ext.xrc.xrcd;
+               cq = srq->ext.xrc.cq;
+       }
 
        ret = srq->device->destroy_srq(srq);
-       if (!ret)
+       if (!ret) {
                atomic_dec(&pd->usecnt);
+               if (srq_type == IB_SRQT_XRC) {
+                       atomic_dec(&xrcd->usecnt);
+                       atomic_dec(&cq->usecnt);
+               }
+       }
 
        return ret;
 }
@@ -296,28 +342,123 @@ EXPORT_SYMBOL(ib_destroy_srq);
 
 /* Queue pairs */
 
+static void __ib_shared_qp_event_handler(struct ib_event *event, void *context)
+{
+       struct ib_qp *qp = context;
+
+       list_for_each_entry(event->element.qp, &qp->open_list, open_list)
+               event->element.qp->event_handler(event, event->element.qp->qp_context);
+}
+
+static void __ib_insert_xrcd_qp(struct ib_xrcd *xrcd, struct ib_qp *qp)
+{
+       mutex_lock(&xrcd->tgt_qp_mutex);
+       list_add(&qp->xrcd_list, &xrcd->tgt_qp_list);
+       mutex_unlock(&xrcd->tgt_qp_mutex);
+}
+
+static struct ib_qp *__ib_open_qp(struct ib_qp *real_qp,
+                                 void (*event_handler)(struct ib_event *, void *),
+                                 void *qp_context)
+{
+       struct ib_qp *qp;
+       unsigned long flags;
+
+       qp = kzalloc(sizeof *qp, GFP_KERNEL);
+       if (!qp)
+               return ERR_PTR(-ENOMEM);
+
+       qp->real_qp = real_qp;
+       atomic_inc(&real_qp->usecnt);
+       qp->device = real_qp->device;
+       qp->event_handler = event_handler;
+       qp->qp_context = qp_context;
+       qp->qp_num = real_qp->qp_num;
+       qp->qp_type = real_qp->qp_type;
+
+       spin_lock_irqsave(&real_qp->device->event_handler_lock, flags);
+       list_add(&qp->open_list, &real_qp->open_list);
+       spin_unlock_irqrestore(&real_qp->device->event_handler_lock, flags);
+
+       return qp;
+}
+
+struct ib_qp *ib_open_qp(struct ib_xrcd *xrcd,
+                        struct ib_qp_open_attr *qp_open_attr)
+{
+       struct ib_qp *qp, *real_qp;
+
+       if (qp_open_attr->qp_type != IB_QPT_XRC_TGT)
+               return ERR_PTR(-EINVAL);
+
+       qp = ERR_PTR(-EINVAL);
+       mutex_lock(&xrcd->tgt_qp_mutex);
+       list_for_each_entry(real_qp, &xrcd->tgt_qp_list, xrcd_list) {
+               if (real_qp->qp_num == qp_open_attr->qp_num) {
+                       qp = __ib_open_qp(real_qp, qp_open_attr->event_handler,
+                                         qp_open_attr->qp_context);
+                       break;
+               }
+       }
+       mutex_unlock(&xrcd->tgt_qp_mutex);
+       return qp;
+}
+EXPORT_SYMBOL(ib_open_qp);
+
 struct ib_qp *ib_create_qp(struct ib_pd *pd,
                           struct ib_qp_init_attr *qp_init_attr)
 {
-       struct ib_qp *qp;
+       struct ib_qp *qp, *real_qp;
+       struct ib_device *device;
 
-       qp = pd->device->create_qp(pd, qp_init_attr, NULL);
+       device = pd ? pd->device : qp_init_attr->xrcd->device;
+       qp = device->create_qp(pd, qp_init_attr, NULL);
 
        if (!IS_ERR(qp)) {
-               qp->device        = pd->device;
-               qp->pd            = pd;
-               qp->send_cq       = qp_init_attr->send_cq;
-               qp->recv_cq       = qp_init_attr->recv_cq;
-               qp->srq           = qp_init_attr->srq;
-               qp->uobject       = NULL;
-               qp->event_handler = qp_init_attr->event_handler;
-               qp->qp_context    = qp_init_attr->qp_context;
-               qp->qp_type       = qp_init_attr->qp_type;
-               atomic_inc(&pd->usecnt);
-               atomic_inc(&qp_init_attr->send_cq->usecnt);
-               atomic_inc(&qp_init_attr->recv_cq->usecnt);
-               if (qp_init_attr->srq)
-                       atomic_inc(&qp_init_attr->srq->usecnt);
+               qp->device     = device;
+               qp->real_qp    = qp;
+               qp->uobject    = NULL;
+               qp->qp_type    = qp_init_attr->qp_type;
+
+               if (qp_init_attr->qp_type == IB_QPT_XRC_TGT) {
+                       qp->event_handler = __ib_shared_qp_event_handler;
+                       qp->qp_context = qp;
+                       qp->pd = NULL;
+                       qp->send_cq = qp->recv_cq = NULL;
+                       qp->srq = NULL;
+                       qp->xrcd = qp_init_attr->xrcd;
+                       atomic_inc(&qp_init_attr->xrcd->usecnt);
+                       INIT_LIST_HEAD(&qp->open_list);
+                       atomic_set(&qp->usecnt, 0);
+
+                       real_qp = qp;
+                       qp = __ib_open_qp(real_qp, qp_init_attr->event_handler,
+                                         qp_init_attr->qp_context);
+                       if (!IS_ERR(qp))
+                               __ib_insert_xrcd_qp(qp_init_attr->xrcd, real_qp);
+                       else
+                               real_qp->device->destroy_qp(real_qp);
+               } else {
+                       qp->event_handler = qp_init_attr->event_handler;
+                       qp->qp_context = qp_init_attr->qp_context;
+                       if (qp_init_attr->qp_type == IB_QPT_XRC_INI) {
+                               qp->recv_cq = NULL;
+                               qp->srq = NULL;
+                       } else {
+                               qp->recv_cq = qp_init_attr->recv_cq;
+                               atomic_inc(&qp_init_attr->recv_cq->usecnt);
+                               qp->srq = qp_init_attr->srq;
+                               if (qp->srq)
+                                       atomic_inc(&qp_init_attr->srq->usecnt);
+                       }
+
+                       qp->pd      = pd;
+                       qp->send_cq = qp_init_attr->send_cq;
+                       qp->xrcd    = NULL;
+
+                       atomic_inc(&pd->usecnt);
+                       atomic_inc(&qp_init_attr->send_cq->usecnt);
+               }
        }
 
        return qp;
@@ -326,8 +467,8 @@ EXPORT_SYMBOL(ib_create_qp);
 
 static const struct {
        int                     valid;
-       enum ib_qp_attr_mask    req_param[IB_QPT_RAW_ETHERTYPE + 1];
-       enum ib_qp_attr_mask    opt_param[IB_QPT_RAW_ETHERTYPE + 1];
+       enum ib_qp_attr_mask    req_param[IB_QPT_MAX];
+       enum ib_qp_attr_mask    opt_param[IB_QPT_MAX];
 } qp_state_table[IB_QPS_ERR + 1][IB_QPS_ERR + 1] = {
        [IB_QPS_RESET] = {
                [IB_QPS_RESET] = { .valid = 1 },
@@ -343,6 +484,12 @@ static const struct {
                                [IB_QPT_RC]  = (IB_QP_PKEY_INDEX                |
                                                IB_QP_PORT                      |
                                                IB_QP_ACCESS_FLAGS),
+                               [IB_QPT_XRC_INI] = (IB_QP_PKEY_INDEX            |
+                                               IB_QP_PORT                      |
+                                               IB_QP_ACCESS_FLAGS),
+                               [IB_QPT_XRC_TGT] = (IB_QP_PKEY_INDEX            |
+                                               IB_QP_PORT                      |
+                                               IB_QP_ACCESS_FLAGS),
                                [IB_QPT_SMI] = (IB_QP_PKEY_INDEX                |
                                                IB_QP_QKEY),
                                [IB_QPT_GSI] = (IB_QP_PKEY_INDEX                |
@@ -365,6 +512,12 @@ static const struct {
                                [IB_QPT_RC]  = (IB_QP_PKEY_INDEX                |
                                                IB_QP_PORT                      |
                                                IB_QP_ACCESS_FLAGS),
+                               [IB_QPT_XRC_INI] = (IB_QP_PKEY_INDEX            |
+                                               IB_QP_PORT                      |
+                                               IB_QP_ACCESS_FLAGS),
+                               [IB_QPT_XRC_TGT] = (IB_QP_PKEY_INDEX            |
+                                               IB_QP_PORT                      |
+                                               IB_QP_ACCESS_FLAGS),
                                [IB_QPT_SMI] = (IB_QP_PKEY_INDEX                |
                                                IB_QP_QKEY),
                                [IB_QPT_GSI] = (IB_QP_PKEY_INDEX                |
@@ -384,6 +537,16 @@ static const struct {
                                                IB_QP_RQ_PSN                    |
                                                IB_QP_MAX_DEST_RD_ATOMIC        |
                                                IB_QP_MIN_RNR_TIMER),
+                               [IB_QPT_XRC_INI] = (IB_QP_AV                    |
+                                               IB_QP_PATH_MTU                  |
+                                               IB_QP_DEST_QPN                  |
+                                               IB_QP_RQ_PSN),
+                               [IB_QPT_XRC_TGT] = (IB_QP_AV                    |
+                                               IB_QP_PATH_MTU                  |
+                                               IB_QP_DEST_QPN                  |
+                                               IB_QP_RQ_PSN                    |
+                                               IB_QP_MAX_DEST_RD_ATOMIC        |
+                                               IB_QP_MIN_RNR_TIMER),
                        },
                        .opt_param = {
                                 [IB_QPT_UD]  = (IB_QP_PKEY_INDEX               |
@@ -394,6 +557,12 @@ static const struct {
                                 [IB_QPT_RC]  = (IB_QP_ALT_PATH                 |
                                                 IB_QP_ACCESS_FLAGS             |
                                                 IB_QP_PKEY_INDEX),
+                                [IB_QPT_XRC_INI] = (IB_QP_ALT_PATH             |
+                                                IB_QP_ACCESS_FLAGS             |
+                                                IB_QP_PKEY_INDEX),
+                                [IB_QPT_XRC_TGT] = (IB_QP_ALT_PATH             |
+                                                IB_QP_ACCESS_FLAGS             |
+                                                IB_QP_PKEY_INDEX),
                                 [IB_QPT_SMI] = (IB_QP_PKEY_INDEX               |
                                                 IB_QP_QKEY),
                                 [IB_QPT_GSI] = (IB_QP_PKEY_INDEX               |
@@ -414,6 +583,13 @@ static const struct {
                                                IB_QP_RNR_RETRY                 |
                                                IB_QP_SQ_PSN                    |
                                                IB_QP_MAX_QP_RD_ATOMIC),
+                               [IB_QPT_XRC_INI] = (IB_QP_TIMEOUT               |
+                                               IB_QP_RETRY_CNT                 |
+                                               IB_QP_RNR_RETRY                 |
+                                               IB_QP_SQ_PSN                    |
+                                               IB_QP_MAX_QP_RD_ATOMIC),
+                               [IB_QPT_XRC_TGT] = (IB_QP_TIMEOUT               |
+                                               IB_QP_SQ_PSN),
                                [IB_QPT_SMI] = IB_QP_SQ_PSN,
                                [IB_QPT_GSI] = IB_QP_SQ_PSN,
                        },
@@ -429,6 +605,15 @@ static const struct {
                                                 IB_QP_ACCESS_FLAGS             |
                                                 IB_QP_MIN_RNR_TIMER            |
                                                 IB_QP_PATH_MIG_STATE),
+                                [IB_QPT_XRC_INI] = (IB_QP_CUR_STATE            |
+                                                IB_QP_ALT_PATH                 |
+                                                IB_QP_ACCESS_FLAGS             |
+                                                IB_QP_PATH_MIG_STATE),
+                                [IB_QPT_XRC_TGT] = (IB_QP_CUR_STATE            |
+                                                IB_QP_ALT_PATH                 |
+                                                IB_QP_ACCESS_FLAGS             |
+                                                IB_QP_MIN_RNR_TIMER            |
+                                                IB_QP_PATH_MIG_STATE),
                                 [IB_QPT_SMI] = (IB_QP_CUR_STATE                |
                                                 IB_QP_QKEY),
                                 [IB_QPT_GSI] = (IB_QP_CUR_STATE                |
@@ -453,6 +638,15 @@ static const struct {
                                                IB_QP_ALT_PATH                  |
                                                IB_QP_PATH_MIG_STATE            |
                                                IB_QP_MIN_RNR_TIMER),
+                               [IB_QPT_XRC_INI] = (IB_QP_CUR_STATE             |
+                                               IB_QP_ACCESS_FLAGS              |
+                                               IB_QP_ALT_PATH                  |
+                                               IB_QP_PATH_MIG_STATE),
+                               [IB_QPT_XRC_TGT] = (IB_QP_CUR_STATE             |
+                                               IB_QP_ACCESS_FLAGS              |
+                                               IB_QP_ALT_PATH                  |
+                                               IB_QP_PATH_MIG_STATE            |
+                                               IB_QP_MIN_RNR_TIMER),
                                [IB_QPT_SMI] = (IB_QP_CUR_STATE                 |
                                                IB_QP_QKEY),
                                [IB_QPT_GSI] = (IB_QP_CUR_STATE                 |
@@ -465,6 +659,8 @@ static const struct {
                                [IB_QPT_UD]  = IB_QP_EN_SQD_ASYNC_NOTIFY,
                                [IB_QPT_UC]  = IB_QP_EN_SQD_ASYNC_NOTIFY,
                                [IB_QPT_RC]  = IB_QP_EN_SQD_ASYNC_NOTIFY,
+                               [IB_QPT_XRC_INI] = IB_QP_EN_SQD_ASYNC_NOTIFY,
+                               [IB_QPT_XRC_TGT] = IB_QP_EN_SQD_ASYNC_NOTIFY, /* ??? */
                                [IB_QPT_SMI] = IB_QP_EN_SQD_ASYNC_NOTIFY,
                                [IB_QPT_GSI] = IB_QP_EN_SQD_ASYNC_NOTIFY
                        }
@@ -487,6 +683,15 @@ static const struct {
                                                IB_QP_ACCESS_FLAGS              |
                                                IB_QP_MIN_RNR_TIMER             |
                                                IB_QP_PATH_MIG_STATE),
+                               [IB_QPT_XRC_INI] = (IB_QP_CUR_STATE             |
+                                               IB_QP_ALT_PATH                  |
+                                               IB_QP_ACCESS_FLAGS              |
+                                               IB_QP_PATH_MIG_STATE),
+                               [IB_QPT_XRC_TGT] = (IB_QP_CUR_STATE             |
+                                               IB_QP_ALT_PATH                  |
+                                               IB_QP_ACCESS_FLAGS              |
+                                               IB_QP_MIN_RNR_TIMER             |
+                                               IB_QP_PATH_MIG_STATE),
                                [IB_QPT_SMI] = (IB_QP_CUR_STATE                 |
                                                IB_QP_QKEY),
                                [IB_QPT_GSI] = (IB_QP_CUR_STATE                 |
@@ -515,6 +720,25 @@ static const struct {
                                                IB_QP_PKEY_INDEX                |
                                                IB_QP_MIN_RNR_TIMER             |
                                                IB_QP_PATH_MIG_STATE),
+                               [IB_QPT_XRC_INI] = (IB_QP_PORT                  |
+                                               IB_QP_AV                        |
+                                               IB_QP_TIMEOUT                   |
+                                               IB_QP_RETRY_CNT                 |
+                                               IB_QP_RNR_RETRY                 |
+                                               IB_QP_MAX_QP_RD_ATOMIC          |
+                                               IB_QP_ALT_PATH                  |
+                                               IB_QP_ACCESS_FLAGS              |
+                                               IB_QP_PKEY_INDEX                |
+                                               IB_QP_PATH_MIG_STATE),
+                               [IB_QPT_XRC_TGT] = (IB_QP_PORT                  |
+                                               IB_QP_AV                        |
+                                               IB_QP_TIMEOUT                   |
+                                               IB_QP_MAX_DEST_RD_ATOMIC        |
+                                               IB_QP_ALT_PATH                  |
+                                               IB_QP_ACCESS_FLAGS              |
+                                               IB_QP_PKEY_INDEX                |
+                                               IB_QP_MIN_RNR_TIMER             |
+                                               IB_QP_PATH_MIG_STATE),
                                [IB_QPT_SMI] = (IB_QP_PKEY_INDEX                |
                                                IB_QP_QKEY),
                                [IB_QPT_GSI] = (IB_QP_PKEY_INDEX                |
@@ -579,7 +803,7 @@ int ib_modify_qp(struct ib_qp *qp,
                 struct ib_qp_attr *qp_attr,
                 int qp_attr_mask)
 {
-       return qp->device->modify_qp(qp, qp_attr, qp_attr_mask, NULL);
+       return qp->device->modify_qp(qp->real_qp, qp_attr, qp_attr_mask, NULL);
 }
 EXPORT_SYMBOL(ib_modify_qp);
 
@@ -589,11 +813,59 @@ int ib_query_qp(struct ib_qp *qp,
                struct ib_qp_init_attr *qp_init_attr)
 {
        return qp->device->query_qp ?
-               qp->device->query_qp(qp, qp_attr, qp_attr_mask, qp_init_attr) :
+               qp->device->query_qp(qp->real_qp, qp_attr, qp_attr_mask, qp_init_attr) :
                -ENOSYS;
 }
 EXPORT_SYMBOL(ib_query_qp);
 
+int ib_close_qp(struct ib_qp *qp)
+{
+       struct ib_qp *real_qp;
+       unsigned long flags;
+
+       real_qp = qp->real_qp;
+       if (real_qp == qp)
+               return -EINVAL;
+
+       spin_lock_irqsave(&real_qp->device->event_handler_lock, flags);
+       list_del(&qp->open_list);
+       spin_unlock_irqrestore(&real_qp->device->event_handler_lock, flags);
+
+       atomic_dec(&real_qp->usecnt);
+       kfree(qp);
+
+       return 0;
+}
+EXPORT_SYMBOL(ib_close_qp);
+
+static int __ib_destroy_shared_qp(struct ib_qp *qp)
+{
+       struct ib_xrcd *xrcd;
+       struct ib_qp *real_qp;
+       int ret;
+
+       real_qp = qp->real_qp;
+       xrcd = real_qp->xrcd;
+
+       mutex_lock(&xrcd->tgt_qp_mutex);
+       ib_close_qp(qp);
+       if (atomic_read(&real_qp->usecnt) == 0)
+               list_del(&real_qp->xrcd_list);
+       else
+               real_qp = NULL;
+       mutex_unlock(&xrcd->tgt_qp_mutex);
+
+       if (real_qp) {
+               ret = ib_destroy_qp(real_qp);
+               if (!ret)
+                       atomic_dec(&xrcd->usecnt);
+               else
+                       __ib_insert_xrcd_qp(xrcd, real_qp);
+       }
+
+       return 0;
+}
+
 int ib_destroy_qp(struct ib_qp *qp)
 {
        struct ib_pd *pd;
@@ -601,16 +873,25 @@ int ib_destroy_qp(struct ib_qp *qp)
        struct ib_srq *srq;
        int ret;
 
-       pd  = qp->pd;
-       scq = qp->send_cq;
-       rcq = qp->recv_cq;
-       srq = qp->srq;
+       if (atomic_read(&qp->usecnt))
+               return -EBUSY;
+
+       if (qp->real_qp != qp)
+               return __ib_destroy_shared_qp(qp);
+
+       pd   = qp->pd;
+       scq  = qp->send_cq;
+       rcq  = qp->recv_cq;
+       srq  = qp->srq;
 
        ret = qp->device->destroy_qp(qp);
        if (!ret) {
-               atomic_dec(&pd->usecnt);
-               atomic_dec(&scq->usecnt);
-               atomic_dec(&rcq->usecnt);
+               if (pd)
+                       atomic_dec(&pd->usecnt);
+               if (scq)
+                       atomic_dec(&scq->usecnt);
+               if (rcq)
+                       atomic_dec(&rcq->usecnt);
                if (srq)
                        atomic_dec(&srq->usecnt);
        }
@@ -920,3 +1201,42 @@ int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid)
        return qp->device->detach_mcast(qp, gid, lid);
 }
 EXPORT_SYMBOL(ib_detach_mcast);
+
+struct ib_xrcd *ib_alloc_xrcd(struct ib_device *device)
+{
+       struct ib_xrcd *xrcd;
+
+       if (!device->alloc_xrcd)
+               return ERR_PTR(-ENOSYS);
+
+       xrcd = device->alloc_xrcd(device, NULL, NULL);
+       if (!IS_ERR(xrcd)) {
+               xrcd->device = device;
+               xrcd->inode = NULL;
+               atomic_set(&xrcd->usecnt, 0);
+               mutex_init(&xrcd->tgt_qp_mutex);
+               INIT_LIST_HEAD(&xrcd->tgt_qp_list);
+       }
+
+       return xrcd;
+}
+EXPORT_SYMBOL(ib_alloc_xrcd);
+
+int ib_dealloc_xrcd(struct ib_xrcd *xrcd)
+{
+       struct ib_qp *qp;
+       int ret;
+
+       if (atomic_read(&xrcd->usecnt))
+               return -EBUSY;
+
+       while (!list_empty(&xrcd->tgt_qp_list)) {
+               qp = list_entry(xrcd->tgt_qp_list.next, struct ib_qp, xrcd_list);
+               ret = ib_destroy_qp(qp);
+               if (ret)
+                       return ret;
+       }
+
+       return xrcd->device->dealloc_xrcd(xrcd);
+}
+EXPORT_SYMBOL(ib_dealloc_xrcd);
index 24f9e3a90e8eade353ca579dedecbc834b9cdd04..32d34e88d5cf70a99f5bfa717ad4b47c76b53d73 100644 (file)
@@ -288,6 +288,11 @@ void c2_ae_event(struct c2_dev *c2dev, u32 mq_index)
                cm_event.private_data_len =
                        be32_to_cpu(req->private_data_length);
                cm_event.private_data = req->private_data;
+               /*
+                * Until ird/ord negotiation via MPAv2 support is added, send
+                * max supported values
+                */
+               cm_event.ird = cm_event.ord = 128;
 
                if (cm_id->event_handler)
                        cm_id->event_handler(cm_id, &cm_event);
index 0ebe4e806b86c7a712142aa53fcb117a3d4d8158..8951db4ae29d42ad2b12d4281c67c911748c2f78 100644 (file)
@@ -183,6 +183,11 @@ static void handle_vq(struct c2_dev *c2dev, u32 mq_index)
        case IW_CM_EVENT_ESTABLISHED:
                c2_set_qp_state(req->qp,
                                C2_QP_STATE_RTS);
+               /*
+                * Until ird/ord negotiation via MPAv2 support is added, send
+                * max supported values
+                */
+               cm_event.ird = cm_event.ord = 128;
        case IW_CM_EVENT_CLOSE:
 
                /*
index f101bb73be631c684227e4a456fceb7bbd658722..12f923d64e42d075a68edd778fb0c9246919eca5 100644 (file)
@@ -753,10 +753,7 @@ static struct net_device *c2_pseudo_netdev_init(struct c2_dev *c2dev)
        memcpy_fromio(netdev->dev_addr, c2dev->kva + C2_REGS_RDMA_ENADDR, 6);
 
        /* Print out the MAC address */
-       pr_debug("%s: MAC %02X:%02X:%02X:%02X:%02X:%02X\n",
-               netdev->name,
-               netdev->dev_addr[0], netdev->dev_addr[1], netdev->dev_addr[2],
-               netdev->dev_addr[3], netdev->dev_addr[4], netdev->dev_addr[5]);
+       pr_debug("%s: MAC %pM\n", netdev->name, netdev->dev_addr);
 
 #if 0
        /* Disable network packets */
index 6cd642aaa4dec710473008e54a954b2232d8e8b6..de6d0774e60990f644e39ca815159f68b5a065d1 100644 (file)
@@ -753,6 +753,11 @@ static void connect_request_upcall(struct iwch_ep *ep)
        event.private_data_len = ep->plen;
        event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
        event.provider_data = ep;
+       /*
+        * Until ird/ord negotiation via MPAv2 support is added, send max
+        * supported values
+        */
+       event.ird = event.ord = 8;
        if (state_read(&ep->parent_ep->com) != DEAD) {
                get_ep(&ep->com);
                ep->parent_ep->com.cm_id->event_handler(
@@ -770,6 +775,11 @@ static void established_upcall(struct iwch_ep *ep)
        PDBG("%s ep %p\n", __func__, ep);
        memset(&event, 0, sizeof(event));
        event.event = IW_CM_EVENT_ESTABLISHED;
+       /*
+        * Until ird/ord negotiation via MPAv2 support is added, send max
+        * supported values
+        */
+       event.ird = event.ord = 8;
        if (ep->com.cm_id) {
                PDBG("%s ep %p tid %d\n", __func__, ep, ep->hwtid);
                ep->com.cm_id->event_handler(ep->com.cm_id, &event);
index 71e0d845da3d976588542aebd2803e9d4a6ef2e9..abcc9e76962bc11bf442118c546cf49c399271b3 100644 (file)
@@ -46,6 +46,7 @@ static void post_qp_event(struct iwch_dev *rnicp, struct iwch_cq *chp,
        struct ib_event event;
        struct iwch_qp_attributes attrs;
        struct iwch_qp *qhp;
+       unsigned long flag;
 
        spin_lock(&rnicp->lock);
        qhp = get_qhp(rnicp, CQE_QPID(rsp_msg->cqe));
@@ -94,7 +95,9 @@ static void post_qp_event(struct iwch_dev *rnicp, struct iwch_cq *chp,
        if (qhp->ibqp.event_handler)
                (*qhp->ibqp.event_handler)(&event, qhp->ibqp.qp_context);
 
+       spin_lock_irqsave(&chp->comp_handler_lock, flag);
        (*chp->ibcq.comp_handler)(&chp->ibcq, chp->ibcq.cq_context);
+       spin_unlock_irqrestore(&chp->comp_handler_lock, flag);
 
        if (atomic_dec_and_test(&qhp->refcnt))
                wake_up(&qhp->wait);
@@ -107,6 +110,7 @@ void iwch_ev_dispatch(struct cxio_rdev *rdev_p, struct sk_buff *skb)
        struct iwch_cq *chp;
        struct iwch_qp *qhp;
        u32 cqid = RSPQ_CQID(rsp_msg);
+       unsigned long flag;
 
        rnicp = (struct iwch_dev *) rdev_p->ulp;
        spin_lock(&rnicp->lock);
@@ -170,7 +174,9 @@ void iwch_ev_dispatch(struct cxio_rdev *rdev_p, struct sk_buff *skb)
                 */
                if (qhp->ep && SQ_TYPE(rsp_msg->cqe))
                        dst_confirm(qhp->ep->dst);
+               spin_lock_irqsave(&chp->comp_handler_lock, flag);
                (*chp->ibcq.comp_handler)(&chp->ibcq, chp->ibcq.cq_context);
+               spin_unlock_irqrestore(&chp->comp_handler_lock, flag);
                break;
 
        case TPT_ERR_STAG:
index c7d9411f295427e9fe1ad946ebce3bfba212bb5f..37c224fc3ad9b8f31e0886507fc43f543ee547b0 100644 (file)
@@ -190,6 +190,7 @@ static struct ib_cq *iwch_create_cq(struct ib_device *ibdev, int entries, int ve
        chp->rhp = rhp;
        chp->ibcq.cqe = 1 << chp->cq.size_log2;
        spin_lock_init(&chp->lock);
+       spin_lock_init(&chp->comp_handler_lock);
        atomic_set(&chp->refcnt, 1);
        init_waitqueue_head(&chp->wait);
        if (insert_handle(rhp, &rhp->cqidr, chp, chp->cq.cqid)) {
index 9a342c9b220d240afebce55e5abfac6f67ee4953..87c14b0c5ac0c9514d9df59ddd39da08cfef8342 100644 (file)
@@ -103,6 +103,7 @@ struct iwch_cq {
        struct iwch_dev *rhp;
        struct t3_cq cq;
        spinlock_t lock;
+       spinlock_t comp_handler_lock;
        atomic_t refcnt;
        wait_queue_head_t wait;
        u32 __user *user_rptr_addr;
index ecd313f359a45ac6d90c0184ae1ccea3eeda7a6c..bea5839d89ee6b5f57b40aea7dc6b30f18e2fe68 100644 (file)
@@ -822,8 +822,11 @@ static void __flush_qp(struct iwch_qp *qhp, struct iwch_cq *rchp,
        flushed = cxio_flush_rq(&qhp->wq, &rchp->cq, count);
        spin_unlock(&qhp->lock);
        spin_unlock_irqrestore(&rchp->lock, *flag);
-       if (flushed)
+       if (flushed) {
+               spin_lock_irqsave(&rchp->comp_handler_lock, *flag);
                (*rchp->ibcq.comp_handler)(&rchp->ibcq, rchp->ibcq.cq_context);
+               spin_unlock_irqrestore(&rchp->comp_handler_lock, *flag);
+       }
 
        /* locking hierarchy: cq lock first, then qp lock. */
        spin_lock_irqsave(&schp->lock, *flag);
@@ -833,8 +836,11 @@ static void __flush_qp(struct iwch_qp *qhp, struct iwch_cq *rchp,
        flushed = cxio_flush_sq(&qhp->wq, &schp->cq, count);
        spin_unlock(&qhp->lock);
        spin_unlock_irqrestore(&schp->lock, *flag);
-       if (flushed)
+       if (flushed) {
+               spin_lock_irqsave(&schp->comp_handler_lock, *flag);
                (*schp->ibcq.comp_handler)(&schp->ibcq, schp->ibcq.cq_context);
+               spin_unlock_irqrestore(&schp->comp_handler_lock, *flag);
+       }
 
        /* deref */
        if (atomic_dec_and_test(&qhp->refcnt))
@@ -853,11 +859,15 @@ static void flush_qp(struct iwch_qp *qhp, unsigned long *flag)
        if (qhp->ibqp.uobject) {
                cxio_set_wq_in_error(&qhp->wq);
                cxio_set_cq_in_error(&rchp->cq);
+               spin_lock_irqsave(&rchp->comp_handler_lock, *flag);
                (*rchp->ibcq.comp_handler)(&rchp->ibcq, rchp->ibcq.cq_context);
+               spin_unlock_irqrestore(&rchp->comp_handler_lock, *flag);
                if (schp != rchp) {
                        cxio_set_cq_in_error(&schp->cq);
+                       spin_lock_irqsave(&schp->comp_handler_lock, *flag);
                        (*schp->ibcq.comp_handler)(&schp->ibcq,
                                                   schp->ibcq.cq_context);
+                       spin_unlock_irqrestore(&schp->comp_handler_lock, *flag);
                }
                return;
        }
index 77f769d9227da31c0c410db2910a957a797b26c6..b36cdac9c558a35aa78f2061e9f7435dc1504754 100644 (file)
@@ -103,7 +103,8 @@ MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
 static int mpa_rev = 1;
 module_param(mpa_rev, int, 0644);
 MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
-                "1 is spec compliant. (default=1)");
+               "1 is RFC0544 spec compliant, 2 is IETF MPA Peer Connect Draft"
+               " compliant (default=1)");
 
 static int markers_enabled;
 module_param(markers_enabled, int, 0644);
@@ -497,17 +498,21 @@ static int send_connect(struct c4iw_ep *ep)
        return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
 }
 
-static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb)
+static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
+               u8 mpa_rev_to_use)
 {
        int mpalen, wrlen;
        struct fw_ofld_tx_data_wr *req;
        struct mpa_message *mpa;
+       struct mpa_v2_conn_params mpa_v2_params;
 
        PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
 
        BUG_ON(skb_cloned(skb));
 
        mpalen = sizeof(*mpa) + ep->plen;
+       if (mpa_rev_to_use == 2)
+               mpalen += sizeof(struct mpa_v2_conn_params);
        wrlen = roundup(mpalen + sizeof *req, 16);
        skb = get_skb(skb, wrlen, GFP_KERNEL);
        if (!skb) {
@@ -533,12 +538,39 @@ static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb)
        mpa = (struct mpa_message *)(req + 1);
        memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
        mpa->flags = (crc_enabled ? MPA_CRC : 0) |
-                    (markers_enabled ? MPA_MARKERS : 0);
+                    (markers_enabled ? MPA_MARKERS : 0) |
+                    (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
        mpa->private_data_size = htons(ep->plen);
-       mpa->revision = mpa_rev;
+       mpa->revision = mpa_rev_to_use;
+       if (mpa_rev_to_use == 1)
+               ep->tried_with_mpa_v1 = 1;
+
+       if (mpa_rev_to_use == 2) {
+               mpa->private_data_size +=
+                       htons(sizeof(struct mpa_v2_conn_params));
+               mpa_v2_params.ird = htons((u16)ep->ird);
+               mpa_v2_params.ord = htons((u16)ep->ord);
+
+               if (peer2peer) {
+                       mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
+                       if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
+                               mpa_v2_params.ord |=
+                                       htons(MPA_V2_RDMA_WRITE_RTR);
+                       else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
+                               mpa_v2_params.ord |=
+                                       htons(MPA_V2_RDMA_READ_RTR);
+               }
+               memcpy(mpa->private_data, &mpa_v2_params,
+                      sizeof(struct mpa_v2_conn_params));
 
-       if (ep->plen)
-               memcpy(mpa->private_data, ep->mpa_pkt + sizeof(*mpa), ep->plen);
+               if (ep->plen)
+                       memcpy(mpa->private_data +
+                              sizeof(struct mpa_v2_conn_params),
+                              ep->mpa_pkt + sizeof(*mpa), ep->plen);
+       } else
+               if (ep->plen)
+                       memcpy(mpa->private_data,
+                                       ep->mpa_pkt + sizeof(*mpa), ep->plen);
 
        /*
         * Reference the mpa skb.  This ensures the data area
@@ -562,10 +594,13 @@ static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
        struct fw_ofld_tx_data_wr *req;
        struct mpa_message *mpa;
        struct sk_buff *skb;
+       struct mpa_v2_conn_params mpa_v2_params;
 
        PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
 
        mpalen = sizeof(*mpa) + plen;
+       if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
+               mpalen += sizeof(struct mpa_v2_conn_params);
        wrlen = roundup(mpalen + sizeof *req, 16);
 
        skb = get_skb(NULL, wrlen, GFP_KERNEL);
@@ -595,8 +630,29 @@ static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
        mpa->flags = MPA_REJECT;
        mpa->revision = mpa_rev;
        mpa->private_data_size = htons(plen);
-       if (plen)
-               memcpy(mpa->private_data, pdata, plen);
+
+       if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
+               mpa->flags |= MPA_ENHANCED_RDMA_CONN;
+               mpa->private_data_size +=
+                       htons(sizeof(struct mpa_v2_conn_params));
+               mpa_v2_params.ird = htons(((u16)ep->ird) |
+                                         (peer2peer ? MPA_V2_PEER2PEER_MODEL :
+                                          0));
+               mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
+                                         (p2p_type ==
+                                          FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
+                                          MPA_V2_RDMA_WRITE_RTR : p2p_type ==
+                                          FW_RI_INIT_P2PTYPE_READ_REQ ?
+                                          MPA_V2_RDMA_READ_RTR : 0) : 0));
+               memcpy(mpa->private_data, &mpa_v2_params,
+                      sizeof(struct mpa_v2_conn_params));
+
+               if (ep->plen)
+                       memcpy(mpa->private_data +
+                              sizeof(struct mpa_v2_conn_params), pdata, plen);
+       } else
+               if (plen)
+                       memcpy(mpa->private_data, pdata, plen);
 
        /*
         * Reference the mpa skb again.  This ensures the data area
@@ -617,10 +673,13 @@ static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
        struct fw_ofld_tx_data_wr *req;
        struct mpa_message *mpa;
        struct sk_buff *skb;
+       struct mpa_v2_conn_params mpa_v2_params;
 
        PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
 
        mpalen = sizeof(*mpa) + plen;
+       if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
+               mpalen += sizeof(struct mpa_v2_conn_params);
        wrlen = roundup(mpalen + sizeof *req, 16);
 
        skb = get_skb(NULL, wrlen, GFP_KERNEL);
@@ -649,10 +708,36 @@ static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
        memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
        mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
                     (markers_enabled ? MPA_MARKERS : 0);
-       mpa->revision = mpa_rev;
+       mpa->revision = ep->mpa_attr.version;
        mpa->private_data_size = htons(plen);
-       if (plen)
-               memcpy(mpa->private_data, pdata, plen);
+
+       if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
+               mpa->flags |= MPA_ENHANCED_RDMA_CONN;
+               mpa->private_data_size +=
+                       htons(sizeof(struct mpa_v2_conn_params));
+               mpa_v2_params.ird = htons((u16)ep->ird);
+               mpa_v2_params.ord = htons((u16)ep->ord);
+               if (peer2peer && (ep->mpa_attr.p2p_type !=
+                                       FW_RI_INIT_P2PTYPE_DISABLED)) {
+                       mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
+
+                       if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
+                               mpa_v2_params.ord |=
+                                       htons(MPA_V2_RDMA_WRITE_RTR);
+                       else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
+                               mpa_v2_params.ord |=
+                                       htons(MPA_V2_RDMA_READ_RTR);
+               }
+
+               memcpy(mpa->private_data, &mpa_v2_params,
+                      sizeof(struct mpa_v2_conn_params));
+
+               if (ep->plen)
+                       memcpy(mpa->private_data +
+                              sizeof(struct mpa_v2_conn_params), pdata, plen);
+       } else
+               if (plen)
+                       memcpy(mpa->private_data, pdata, plen);
 
        /*
         * Reference the mpa skb.  This ensures the data area
@@ -695,7 +780,10 @@ static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
 
        /* start MPA negotiation */
        send_flowc(ep, NULL);
-       send_mpa_req(ep, skb);
+       if (ep->retry_with_mpa_v1)
+               send_mpa_req(ep, skb, 1);
+       else
+               send_mpa_req(ep, skb, mpa_rev);
 
        return 0;
 }
@@ -769,8 +857,19 @@ static void connect_reply_upcall(struct c4iw_ep *ep, int status)
        event.remote_addr = ep->com.remote_addr;
 
        if ((status == 0) || (status == -ECONNREFUSED)) {
-               event.private_data_len = ep->plen;
-               event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
+               if (!ep->tried_with_mpa_v1) {
+                       /* this means MPA_v2 is used */
+                       event.private_data_len = ep->plen -
+                               sizeof(struct mpa_v2_conn_params);
+                       event.private_data = ep->mpa_pkt +
+                               sizeof(struct mpa_message) +
+                               sizeof(struct mpa_v2_conn_params);
+               } else {
+                       /* this means MPA_v1 is used */
+                       event.private_data_len = ep->plen;
+                       event.private_data = ep->mpa_pkt +
+                               sizeof(struct mpa_message);
+               }
        }
 
        PDBG("%s ep %p tid %u status %d\n", __func__, ep,
@@ -793,9 +892,22 @@ static void connect_request_upcall(struct c4iw_ep *ep)
        event.event = IW_CM_EVENT_CONNECT_REQUEST;
        event.local_addr = ep->com.local_addr;
        event.remote_addr = ep->com.remote_addr;
-       event.private_data_len = ep->plen;
-       event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
        event.provider_data = ep;
+       if (!ep->tried_with_mpa_v1) {
+               /* this means MPA_v2 is used */
+               event.ord = ep->ord;
+               event.ird = ep->ird;
+               event.private_data_len = ep->plen -
+                       sizeof(struct mpa_v2_conn_params);
+               event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
+                       sizeof(struct mpa_v2_conn_params);
+       } else {
+               /* this means MPA_v1 is used. Send max supported */
+               event.ord = c4iw_max_read_depth;
+               event.ird = c4iw_max_read_depth;
+               event.private_data_len = ep->plen;
+               event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
+       }
        if (state_read(&ep->parent_ep->com) != DEAD) {
                c4iw_get_ep(&ep->com);
                ep->parent_ep->com.cm_id->event_handler(
@@ -813,6 +925,8 @@ static void established_upcall(struct c4iw_ep *ep)
        PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
        memset(&event, 0, sizeof(event));
        event.event = IW_CM_EVENT_ESTABLISHED;
+       event.ird = ep->ird;
+       event.ord = ep->ord;
        if (ep->com.cm_id) {
                PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
                ep->com.cm_id->event_handler(ep->com.cm_id, &event);
@@ -848,7 +962,10 @@ static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
 static void process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
 {
        struct mpa_message *mpa;
+       struct mpa_v2_conn_params *mpa_v2_params;
        u16 plen;
+       u16 resp_ird, resp_ord;
+       u8 rtr_mismatch = 0, insuff_ird = 0;
        struct c4iw_qp_attributes attrs;
        enum c4iw_qp_attr_mask mask;
        int err;
@@ -888,7 +1005,9 @@ static void process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
        mpa = (struct mpa_message *) ep->mpa_pkt;
 
        /* Validate MPA header. */
-       if (mpa->revision != mpa_rev) {
+       if (mpa->revision > mpa_rev) {
+               printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
+                      " Received = %d\n", __func__, mpa_rev, mpa->revision);
                err = -EPROTO;
                goto err;
        }
@@ -938,13 +1057,66 @@ static void process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
        ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
        ep->mpa_attr.recv_marker_enabled = markers_enabled;
        ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
-       ep->mpa_attr.version = mpa_rev;
-       ep->mpa_attr.p2p_type = peer2peer ? p2p_type :
-                                           FW_RI_INIT_P2PTYPE_DISABLED;
+       ep->mpa_attr.version = mpa->revision;
+       ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
+
+       if (mpa->revision == 2) {
+               ep->mpa_attr.enhanced_rdma_conn =
+                       mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
+               if (ep->mpa_attr.enhanced_rdma_conn) {
+                       mpa_v2_params = (struct mpa_v2_conn_params *)
+                               (ep->mpa_pkt + sizeof(*mpa));
+                       resp_ird = ntohs(mpa_v2_params->ird) &
+                               MPA_V2_IRD_ORD_MASK;
+                       resp_ord = ntohs(mpa_v2_params->ord) &
+                               MPA_V2_IRD_ORD_MASK;
+
+                       /*
+                        * This is a double-check. Ideally, below checks are
+                        * not required since ird/ord stuff has been taken
+                        * care of in c4iw_accept_cr
+                        */
+                       if ((ep->ird < resp_ord) || (ep->ord > resp_ird)) {
+                               err = -ENOMEM;
+                               ep->ird = resp_ord;
+                               ep->ord = resp_ird;
+                               insuff_ird = 1;
+                       }
+
+                       if (ntohs(mpa_v2_params->ird) &
+                                       MPA_V2_PEER2PEER_MODEL) {
+                               if (ntohs(mpa_v2_params->ord) &
+                                               MPA_V2_RDMA_WRITE_RTR)
+                                       ep->mpa_attr.p2p_type =
+                                               FW_RI_INIT_P2PTYPE_RDMA_WRITE;
+                               else if (ntohs(mpa_v2_params->ord) &
+                                               MPA_V2_RDMA_READ_RTR)
+                                       ep->mpa_attr.p2p_type =
+                                               FW_RI_INIT_P2PTYPE_READ_REQ;
+                       }
+               }
+       } else if (mpa->revision == 1)
+               if (peer2peer)
+                       ep->mpa_attr.p2p_type = p2p_type;
+
        PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
-            "xmit_marker_enabled=%d, version=%d\n", __func__,
-            ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
-            ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version);
+            "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
+            "%d\n", __func__, ep->mpa_attr.crc_enabled,
+            ep->mpa_attr.recv_marker_enabled,
+            ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
+            ep->mpa_attr.p2p_type, p2p_type);
+
+       /*
+        * If responder's RTR does not match with that of initiator, assign
+        * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
+        * generated when moving QP to RTS state.
+        * A TERM message will be sent after QP has moved to RTS state
+        */
+       if ((ep->mpa_attr.version == 2) &&
+                       (ep->mpa_attr.p2p_type != p2p_type)) {
+               ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
+               rtr_mismatch = 1;
+       }
 
        attrs.mpa_attr = ep->mpa_attr;
        attrs.max_ird = ep->ird;
@@ -961,6 +1133,39 @@ static void process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
                             ep->com.qp, mask, &attrs, 1);
        if (err)
                goto err;
+
+       /*
+        * If responder's RTR requirement did not match with what initiator
+        * supports, generate TERM message
+        */
+       if (rtr_mismatch) {
+               printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
+               attrs.layer_etype = LAYER_MPA | DDP_LLP;
+               attrs.ecode = MPA_NOMATCH_RTR;
+               attrs.next_state = C4IW_QP_STATE_TERMINATE;
+               err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
+                               C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
+               err = -ENOMEM;
+               goto out;
+       }
+
+       /*
+        * Generate TERM if initiator IRD is not sufficient for responder
+        * provided ORD. Currently, we do the same behaviour even when
+        * responder provided IRD is also not sufficient as regards to
+        * initiator ORD.
+        */
+       if (insuff_ird) {
+               printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
+                               __func__);
+               attrs.layer_etype = LAYER_MPA | DDP_LLP;
+               attrs.ecode = MPA_INSUFF_IRD;
+               attrs.next_state = C4IW_QP_STATE_TERMINATE;
+               err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
+                               C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
+               err = -ENOMEM;
+               goto out;
+       }
        goto out;
 err:
        state_set(&ep->com, ABORTING);
@@ -973,6 +1178,7 @@ out:
 static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
 {
        struct mpa_message *mpa;
+       struct mpa_v2_conn_params *mpa_v2_params;
        u16 plen;
 
        PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
@@ -1013,7 +1219,9 @@ static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
        /*
         * Validate MPA Header.
         */
-       if (mpa->revision != mpa_rev) {
+       if (mpa->revision > mpa_rev) {
+               printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
+                      " Received = %d\n", __func__, mpa_rev, mpa->revision);
                abort_connection(ep, skb, GFP_KERNEL);
                return;
        }
@@ -1056,9 +1264,37 @@ static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
        ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
        ep->mpa_attr.recv_marker_enabled = markers_enabled;
        ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
-       ep->mpa_attr.version = mpa_rev;
-       ep->mpa_attr.p2p_type = peer2peer ? p2p_type :
-                                           FW_RI_INIT_P2PTYPE_DISABLED;
+       ep->mpa_attr.version = mpa->revision;
+       if (mpa->revision == 1)
+               ep->tried_with_mpa_v1 = 1;
+       ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
+
+       if (mpa->revision == 2) {
+               ep->mpa_attr.enhanced_rdma_conn =
+                       mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
+               if (ep->mpa_attr.enhanced_rdma_conn) {
+                       mpa_v2_params = (struct mpa_v2_conn_params *)
+                               (ep->mpa_pkt + sizeof(*mpa));
+                       ep->ird = ntohs(mpa_v2_params->ird) &
+                               MPA_V2_IRD_ORD_MASK;
+                       ep->ord = ntohs(mpa_v2_params->ord) &
+                               MPA_V2_IRD_ORD_MASK;
+                       if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
+                               if (peer2peer) {
+                                       if (ntohs(mpa_v2_params->ord) &
+                                                       MPA_V2_RDMA_WRITE_RTR)
+                                               ep->mpa_attr.p2p_type =
+                                               FW_RI_INIT_P2PTYPE_RDMA_WRITE;
+                                       else if (ntohs(mpa_v2_params->ord) &
+                                                       MPA_V2_RDMA_READ_RTR)
+                                               ep->mpa_attr.p2p_type =
+                                               FW_RI_INIT_P2PTYPE_READ_REQ;
+                               }
+               }
+       } else if (mpa->revision == 1)
+               if (peer2peer)
+                       ep->mpa_attr.p2p_type = p2p_type;
+
        PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
             "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
             ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
@@ -1550,6 +1786,112 @@ static int is_neg_adv_abort(unsigned int status)
               status == CPL_ERR_PERSIST_NEG_ADVICE;
 }
 
+static int c4iw_reconnect(struct c4iw_ep *ep)
+{
+       int err = 0;
+       struct rtable *rt;
+       struct net_device *pdev;
+       struct neighbour *neigh;
+       int step;
+
+       PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
+       init_timer(&ep->timer);
+
+       /*
+        * Allocate an active TID to initiate a TCP connection.
+        */
+       ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
+       if (ep->atid == -1) {
+               printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
+               err = -ENOMEM;
+               goto fail2;
+       }
+
+       /* find a route */
+       rt = find_route(ep->com.dev,
+                       ep->com.cm_id->local_addr.sin_addr.s_addr,
+                       ep->com.cm_id->remote_addr.sin_addr.s_addr,
+                       ep->com.cm_id->local_addr.sin_port,
+                       ep->com.cm_id->remote_addr.sin_port, 0);
+       if (!rt) {
+               printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
+               err = -EHOSTUNREACH;
+               goto fail3;
+       }
+       ep->dst = &rt->dst;
+
+       neigh = dst_get_neighbour(ep->dst);
+
+       /* get a l2t entry */
+       if (neigh->dev->flags & IFF_LOOPBACK) {
+               PDBG("%s LOOPBACK\n", __func__);
+               pdev = ip_dev_find(&init_net,
+                                  ep->com.cm_id->remote_addr.sin_addr.s_addr);
+               ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
+                                       neigh, pdev, 0);
+               ep->mtu = pdev->mtu;
+               ep->tx_chan = cxgb4_port_chan(pdev);
+               ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
+               step = ep->com.dev->rdev.lldi.ntxq /
+                       ep->com.dev->rdev.lldi.nchan;
+               ep->txq_idx = cxgb4_port_idx(pdev) * step;
+               step = ep->com.dev->rdev.lldi.nrxq /
+                       ep->com.dev->rdev.lldi.nchan;
+               ep->ctrlq_idx = cxgb4_port_idx(pdev);
+               ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[
+                       cxgb4_port_idx(pdev) * step];
+               dev_put(pdev);
+       } else {
+               ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
+                                       neigh, neigh->dev, 0);
+               ep->mtu = dst_mtu(ep->dst);
+               ep->tx_chan = cxgb4_port_chan(neigh->dev);
+               ep->smac_idx = (cxgb4_port_viid(neigh->dev) & 0x7F) << 1;
+               step = ep->com.dev->rdev.lldi.ntxq /
+                       ep->com.dev->rdev.lldi.nchan;
+               ep->txq_idx = cxgb4_port_idx(neigh->dev) * step;
+               ep->ctrlq_idx = cxgb4_port_idx(neigh->dev);
+               step = ep->com.dev->rdev.lldi.nrxq /
+                       ep->com.dev->rdev.lldi.nchan;
+               ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[
+                       cxgb4_port_idx(neigh->dev) * step];
+       }
+       if (!ep->l2t) {
+               printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
+               err = -ENOMEM;
+               goto fail4;
+       }
+
+       PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
+            __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
+            ep->l2t->idx);
+
+       state_set(&ep->com, CONNECTING);
+       ep->tos = 0;
+
+       /* send connect request to rnic */
+       err = send_connect(ep);
+       if (!err)
+               goto out;
+
+       cxgb4_l2t_release(ep->l2t);
+fail4:
+       dst_release(ep->dst);
+fail3:
+       cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
+fail2:
+       /*
+        * remember to send notification to upper layer.
+        * We are in here so the upper layer is not aware that this is
+        * re-connect attempt and so, upper layer is still waiting for
+        * response of 1st connect request.
+        */
+       connect_reply_upcall(ep, -ECONNRESET);
+       c4iw_put_ep(&ep->com);
+out:
+       return err;
+}
+
 static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
 {
        struct cpl_abort_req_rss *req = cplhdr(skb);
@@ -1573,8 +1915,11 @@ static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
 
        /*
         * Wake up any threads in rdma_init() or rdma_fini().
+        * However, this is not needed if com state is just
+        * MPA_REQ_SENT
         */
-       c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
+       if (ep->com.state != MPA_REQ_SENT)
+               c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
 
        mutex_lock(&ep->com.mutex);
        switch (ep->com.state) {
@@ -1585,7 +1930,21 @@ static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
                break;
        case MPA_REQ_SENT:
                stop_ep_timer(ep);
-               connect_reply_upcall(ep, -ECONNRESET);
+               if (mpa_rev == 2 && ep->tried_with_mpa_v1)
+                       connect_reply_upcall(ep, -ECONNRESET);
+               else {
+                       /*
+                        * we just don't send notification upwards because we
+                        * want to retry with mpa_v1 without upper layers even
+                        * knowing it.
+                        *
+                        * do some housekeeping so as to re-initiate the
+                        * connection
+                        */
+                       PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
+                            mpa_rev);
+                       ep->retry_with_mpa_v1 = 1;
+               }
                break;
        case MPA_REP_SENT:
                break;
@@ -1621,7 +1980,9 @@ static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
        dst_confirm(ep->dst);
        if (ep->com.state != ABORTING) {
                __state_set(&ep->com, DEAD);
-               release = 1;
+               /* we don't release if we want to retry with mpa_v1 */
+               if (!ep->retry_with_mpa_v1)
+                       release = 1;
        }
        mutex_unlock(&ep->com.mutex);
 
@@ -1641,6 +2002,15 @@ static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
 out:
        if (release)
                release_ep_resources(ep);
+
+       /* retry with mpa-v1 */
+       if (ep && ep->retry_with_mpa_v1) {
+               cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
+               dst_release(ep->dst);
+               cxgb4_l2t_release(ep->l2t);
+               c4iw_reconnect(ep);
+       }
+
        return 0;
 }
 
@@ -1792,18 +2162,40 @@ int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
                goto err;
        }
 
-       cm_id->add_ref(cm_id);
-       ep->com.cm_id = cm_id;
-       ep->com.qp = qp;
+       if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
+               if (conn_param->ord > ep->ird) {
+                       ep->ird = conn_param->ird;
+                       ep->ord = conn_param->ord;
+                       send_mpa_reject(ep, conn_param->private_data,
+                                       conn_param->private_data_len);
+                       abort_connection(ep, NULL, GFP_KERNEL);
+                       err = -ENOMEM;
+                       goto err;
+               }
+               if (conn_param->ird > ep->ord) {
+                       if (!ep->ord)
+                               conn_param->ird = 1;
+                       else {
+                               abort_connection(ep, NULL, GFP_KERNEL);
+                               err = -ENOMEM;
+                               goto err;
+                       }
+               }
 
+       }
        ep->ird = conn_param->ird;
        ep->ord = conn_param->ord;
 
-       if (peer2peer && ep->ird == 0)
-               ep->ird = 1;
+       if (ep->mpa_attr.version != 2)
+               if (peer2peer && ep->ird == 0)
+                       ep->ird = 1;
 
        PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
 
+       cm_id->add_ref(cm_id);
+       ep->com.cm_id = cm_id;
+       ep->com.qp = qp;
+
        /* bind QP to EP and move to RTS */
        attrs.mpa_attr = ep->mpa_attr;
        attrs.max_ird = ep->ird;
@@ -1944,6 +2336,8 @@ int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
                       ep->com.dev->rdev.lldi.nchan;
                ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[
                              cxgb4_port_idx(neigh->dev) * step];
+               ep->retry_with_mpa_v1 = 0;
+               ep->tried_with_mpa_v1 = 0;
        }
        if (!ep->l2t) {
                printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
@@ -2323,8 +2717,11 @@ static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
 
        /*
         * Wake up any threads in rdma_init() or rdma_fini().
+        * However, this is not needed if com state is just
+        * MPA_REQ_SENT
         */
-       c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
+       if (ep->com.state != MPA_REQ_SENT)
+               c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
        sched(dev, skb);
        return 0;
 }
index 1720dc790d13d1367594478a95ad1c9148bb91b1..f35a935267e77e7a58c3be85437cbcb1a1f35cb7 100644 (file)
@@ -185,7 +185,7 @@ static void insert_recv_cqe(struct t4_wq *wq, struct t4_cq *cq)
                                 V_CQE_OPCODE(FW_RI_SEND) |
                                 V_CQE_TYPE(0) |
                                 V_CQE_SWCQE(1) |
-                                V_CQE_QPID(wq->rq.qid));
+                                V_CQE_QPID(wq->sq.qid));
        cqe.bits_type_ts = cpu_to_be64(V_CQE_GENBIT((u64)cq->gen));
        cq->sw_queue[cq->sw_pidx] = cqe;
        t4_swcq_produce(cq);
@@ -818,6 +818,7 @@ struct ib_cq *c4iw_create_cq(struct ib_device *ibdev, int entries,
        chp->cq.size--;                         /* status page */
        chp->ibcq.cqe = entries - 2;
        spin_lock_init(&chp->lock);
+       spin_lock_init(&chp->comp_handler_lock);
        atomic_set(&chp->refcnt, 1);
        init_waitqueue_head(&chp->wait);
        ret = insert_handle(rhp, &rhp->cqidr, chp, chp->cq.cqid);
index 40a13cc633a342befeeb452d713df087bb219149..6d0df6ec161b21f1a03347c12f5d7805ce5cbe70 100644 (file)
@@ -376,10 +376,8 @@ struct uld_ctx {
        struct c4iw_dev *dev;
 };
 
-static void c4iw_remove(struct uld_ctx *ctx)
+static void c4iw_dealloc(struct uld_ctx *ctx)
 {
-       PDBG("%s c4iw_dev %p\n", __func__,  ctx->dev);
-       c4iw_unregister_device(ctx->dev);
        c4iw_rdev_close(&ctx->dev->rdev);
        idr_destroy(&ctx->dev->cqidr);
        idr_destroy(&ctx->dev->qpidr);
@@ -389,11 +387,30 @@ static void c4iw_remove(struct uld_ctx *ctx)
        ctx->dev = NULL;
 }
 
+static void c4iw_remove(struct uld_ctx *ctx)
+{
+       PDBG("%s c4iw_dev %p\n", __func__,  ctx->dev);
+       c4iw_unregister_device(ctx->dev);
+       c4iw_dealloc(ctx);
+}
+
+static int rdma_supported(const struct cxgb4_lld_info *infop)
+{
+       return infop->vr->stag.size > 0 && infop->vr->pbl.size > 0 &&
+              infop->vr->rq.size > 0 && infop->vr->qp.size > 0 &&
+              infop->vr->cq.size > 0 && infop->vr->ocq.size > 0;
+}
+
 static struct c4iw_dev *c4iw_alloc(const struct cxgb4_lld_info *infop)
 {
        struct c4iw_dev *devp;
        int ret;
 
+       if (!rdma_supported(infop)) {
+               printk(KERN_INFO MOD "%s: RDMA not supported on this device.\n",
+                      pci_name(infop->pdev));
+               return ERR_PTR(-ENOSYS);
+       }
        devp = (struct c4iw_dev *)ib_alloc_device(sizeof(*devp));
        if (!devp) {
                printk(KERN_ERR MOD "Cannot allocate ib device\n");
@@ -414,7 +431,6 @@ static struct c4iw_dev *c4iw_alloc(const struct cxgb4_lld_info *infop)
 
        ret = c4iw_rdev_open(&devp->rdev);
        if (ret) {
-               mutex_unlock(&dev_mutex);
                printk(KERN_ERR MOD "Unable to open CXIO rdev err %d\n", ret);
                ib_dealloc_device(&devp->ibdev);
                return ERR_PTR(ret);
@@ -519,15 +535,24 @@ static int c4iw_uld_state_change(void *handle, enum cxgb4_state new_state)
        case CXGB4_STATE_UP:
                printk(KERN_INFO MOD "%s: Up\n", pci_name(ctx->lldi.pdev));
                if (!ctx->dev) {
-                       int ret = 0;
+                       int ret;
 
                        ctx->dev = c4iw_alloc(&ctx->lldi);
-                       if (!IS_ERR(ctx->dev))
-                               ret = c4iw_register_device(ctx->dev);
-                       if (IS_ERR(ctx->dev) || ret)
+                       if (IS_ERR(ctx->dev)) {
+                               printk(KERN_ERR MOD
+                                      "%s: initialization failed: %ld\n",
+                                      pci_name(ctx->lldi.pdev),
+                                      PTR_ERR(ctx->dev));
+                               ctx->dev = NULL;
+                               break;
+                       }
+                       ret = c4iw_register_device(ctx->dev);
+                       if (ret) {
                                printk(KERN_ERR MOD
                                       "%s: RDMA registration failed: %d\n",
                                       pci_name(ctx->lldi.pdev), ret);
+                               c4iw_dealloc(ctx);
+                       }
                }
                break;
        case CXGB4_STATE_DOWN:
index c13041a0aeba90b033b7b338e26ecc80efc42753..397cb36cf1037d7cc14b34130d804c8bc68edd07 100644 (file)
@@ -42,6 +42,7 @@ static void post_qp_event(struct c4iw_dev *dev, struct c4iw_cq *chp,
 {
        struct ib_event event;
        struct c4iw_qp_attributes attrs;
+       unsigned long flag;
 
        if ((qhp->attr.state == C4IW_QP_STATE_ERROR) ||
            (qhp->attr.state == C4IW_QP_STATE_TERMINATE)) {
@@ -72,7 +73,9 @@ static void post_qp_event(struct c4iw_dev *dev, struct c4iw_cq *chp,
        if (qhp->ibqp.event_handler)
                (*qhp->ibqp.event_handler)(&event, qhp->ibqp.qp_context);
 
+       spin_lock_irqsave(&chp->comp_handler_lock, flag);
        (*chp->ibcq.comp_handler)(&chp->ibcq, chp->ibcq.cq_context);
+       spin_unlock_irqrestore(&chp->comp_handler_lock, flag);
 }
 
 void c4iw_ev_dispatch(struct c4iw_dev *dev, struct t4_cqe *err_cqe)
@@ -183,11 +186,14 @@ out:
 int c4iw_ev_handler(struct c4iw_dev *dev, u32 qid)
 {
        struct c4iw_cq *chp;
+       unsigned long flag;
 
        chp = get_chp(dev, qid);
-       if (chp)
+       if (chp) {
+               spin_lock_irqsave(&chp->comp_handler_lock, flag);
                (*chp->ibcq.comp_handler)(&chp->ibcq, chp->ibcq.cq_context);
-       else
+               spin_unlock_irqrestore(&chp->comp_handler_lock, flag);
+       } else
                PDBG("%s unknown cqid 0x%x\n", __func__, qid);
        return 0;
 }
index 4f045375c8e27b8fb7dc93776c9b1a7e6eb7a4da..1357c5bf209b55c2392fb1a49e69adbadd3411c8 100644 (file)
@@ -309,6 +309,7 @@ struct c4iw_cq {
        struct c4iw_dev *rhp;
        struct t4_cq cq;
        spinlock_t lock;
+       spinlock_t comp_handler_lock;
        atomic_t refcnt;
        wait_queue_head_t wait;
 };
@@ -323,6 +324,7 @@ struct c4iw_mpa_attributes {
        u8 recv_marker_enabled;
        u8 xmit_marker_enabled;
        u8 crc_enabled;
+       u8 enhanced_rdma_conn;
        u8 version;
        u8 p2p_type;
 };
@@ -349,6 +351,8 @@ struct c4iw_qp_attributes {
        u8 is_terminate_local;
        struct c4iw_mpa_attributes mpa_attr;
        struct c4iw_ep *llp_stream_handle;
+       u8 layer_etype;
+       u8 ecode;
 };
 
 struct c4iw_qp {
@@ -501,11 +505,18 @@ enum c4iw_mmid_state {
 #define MPA_KEY_REP "MPA ID Rep Frame"
 
 #define MPA_MAX_PRIVATE_DATA   256
+#define MPA_ENHANCED_RDMA_CONN 0x10
 #define MPA_REJECT             0x20
 #define MPA_CRC                        0x40
 #define MPA_MARKERS            0x80
 #define MPA_FLAGS_MASK         0xE0
 
+#define MPA_V2_PEER2PEER_MODEL          0x8000
+#define MPA_V2_ZERO_LEN_FPDU_RTR        0x4000
+#define MPA_V2_RDMA_WRITE_RTR           0x8000
+#define MPA_V2_RDMA_READ_RTR            0x4000
+#define MPA_V2_IRD_ORD_MASK             0x3FFF
+
 #define c4iw_put_ep(ep) { \
        PDBG("put_ep (via %s:%u) ep %p refcnt %d\n", __func__, __LINE__,  \
             ep, atomic_read(&((ep)->kref.refcount))); \
@@ -528,6 +539,11 @@ struct mpa_message {
        u8 private_data[0];
 };
 
+struct mpa_v2_conn_params {
+       __be16 ird;
+       __be16 ord;
+};
+
 struct terminate_message {
        u8 layer_etype;
        u8 ecode;
@@ -580,7 +596,10 @@ enum c4iw_ddp_ecodes {
 
 enum c4iw_mpa_ecodes {
        MPA_CRC_ERR             = 0x02,
-       MPA_MARKER_ERR          = 0x03
+       MPA_MARKER_ERR          = 0x03,
+       MPA_LOCAL_CATA          = 0x05,
+       MPA_INSUFF_IRD          = 0x06,
+       MPA_NOMATCH_RTR         = 0x07,
 };
 
 enum c4iw_ep_state {
@@ -651,6 +670,8 @@ struct c4iw_ep {
        u16 txq_idx;
        u16 ctrlq_idx;
        u8 tos;
+       u8 retry_with_mpa_v1;
+       u8 tried_with_mpa_v1;
 };
 
 static inline struct c4iw_ep *to_ep(struct iw_cm_id *cm_id)
index a41578e48c7b0bb366795bfd3da1dd961f3d42d1..d6ccc7e848028f44c4eb6dcb3771191174e64a86 100644 (file)
@@ -917,7 +917,11 @@ static void post_terminate(struct c4iw_qp *qhp, struct t4_cqe *err_cqe,
        wqe->u.terminate.type = FW_RI_TYPE_TERMINATE;
        wqe->u.terminate.immdlen = cpu_to_be32(sizeof *term);
        term = (struct terminate_message *)wqe->u.terminate.termmsg;
-       build_term_codes(err_cqe, &term->layer_etype, &term->ecode);
+       if (qhp->attr.layer_etype == (LAYER_MPA|DDP_LLP)) {
+               term->layer_etype = qhp->attr.layer_etype;
+               term->ecode = qhp->attr.ecode;
+       } else
+               build_term_codes(err_cqe, &term->layer_etype, &term->ecode);
        c4iw_ofld_send(&qhp->rhp->rdev, skb);
 }
 
@@ -941,8 +945,11 @@ static void __flush_qp(struct c4iw_qp *qhp, struct c4iw_cq *rchp,
        flushed = c4iw_flush_rq(&qhp->wq, &rchp->cq, count);
        spin_unlock(&qhp->lock);
        spin_unlock_irqrestore(&rchp->lock, flag);
-       if (flushed)
+       if (flushed) {
+               spin_lock_irqsave(&rchp->comp_handler_lock, flag);
                (*rchp->ibcq.comp_handler)(&rchp->ibcq, rchp->ibcq.cq_context);
+               spin_unlock_irqrestore(&rchp->comp_handler_lock, flag);
+       }
 
        /* locking hierarchy: cq lock first, then qp lock. */
        spin_lock_irqsave(&schp->lock, flag);
@@ -952,13 +959,17 @@ static void __flush_qp(struct c4iw_qp *qhp, struct c4iw_cq *rchp,
        flushed = c4iw_flush_sq(&qhp->wq, &schp->cq, count);
        spin_unlock(&qhp->lock);
        spin_unlock_irqrestore(&schp->lock, flag);
-       if (flushed)
+       if (flushed) {
+               spin_lock_irqsave(&schp->comp_handler_lock, flag);
                (*schp->ibcq.comp_handler)(&schp->ibcq, schp->ibcq.cq_context);
+               spin_unlock_irqrestore(&schp->comp_handler_lock, flag);
+       }
 }
 
 static void flush_qp(struct c4iw_qp *qhp)
 {
        struct c4iw_cq *rchp, *schp;
+       unsigned long flag;
 
        rchp = get_chp(qhp->rhp, qhp->attr.rcq);
        schp = get_chp(qhp->rhp, qhp->attr.scq);
@@ -966,8 +977,16 @@ static void flush_qp(struct c4iw_qp *qhp)
        if (qhp->ibqp.uobject) {
                t4_set_wq_in_error(&qhp->wq);
                t4_set_cq_in_error(&rchp->cq);
-               if (schp != rchp)
+               spin_lock_irqsave(&rchp->comp_handler_lock, flag);
+               (*rchp->ibcq.comp_handler)(&rchp->ibcq, rchp->ibcq.cq_context);
+               spin_unlock_irqrestore(&rchp->comp_handler_lock, flag);
+               if (schp != rchp) {
                        t4_set_cq_in_error(&schp->cq);
+                       spin_lock_irqsave(&schp->comp_handler_lock, flag);
+                       (*schp->ibcq.comp_handler)(&schp->ibcq,
+                                       schp->ibcq.cq_context);
+                       spin_unlock_irqrestore(&schp->comp_handler_lock, flag);
+               }
                return;
        }
        __flush_qp(qhp, rchp, schp);
@@ -1012,6 +1031,7 @@ out:
 
 static void build_rtr_msg(u8 p2p_type, struct fw_ri_init *init)
 {
+       PDBG("%s p2p_type = %d\n", __func__, p2p_type);
        memset(&init->u, 0, sizeof init->u);
        switch (p2p_type) {
        case FW_RI_INIT_P2PTYPE_RDMA_WRITE:
@@ -1206,12 +1226,16 @@ int c4iw_modify_qp(struct c4iw_dev *rhp, struct c4iw_qp *qhp,
                                disconnect = 1;
                                c4iw_get_ep(&qhp->ep->com);
                        }
+                       if (qhp->ibqp.uobject)
+                               t4_set_wq_in_error(&qhp->wq);
                        ret = rdma_fini(rhp, qhp, ep);
                        if (ret)
                                goto err;
                        break;
                case C4IW_QP_STATE_TERMINATE:
                        set_state(qhp, C4IW_QP_STATE_TERMINATE);
+                       qhp->attr.layer_etype = attrs->layer_etype;
+                       qhp->attr.ecode = attrs->ecode;
                        if (qhp->ibqp.uobject)
                                t4_set_wq_in_error(&qhp->wq);
                        ep = qhp->ep;
@@ -1222,6 +1246,8 @@ int c4iw_modify_qp(struct c4iw_dev *rhp, struct c4iw_qp *qhp,
                        break;
                case C4IW_QP_STATE_ERROR:
                        set_state(qhp, C4IW_QP_STATE_ERROR);
+                       if (qhp->ibqp.uobject)
+                               t4_set_wq_in_error(&qhp->wq);
                        if (!internal) {
                                abort = 1;
                                disconnect = 1;
@@ -1334,7 +1360,10 @@ int c4iw_destroy_qp(struct ib_qp *ib_qp)
        rhp = qhp->rhp;
 
        attrs.next_state = C4IW_QP_STATE_ERROR;
-       c4iw_modify_qp(rhp, qhp, C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
+       if (qhp->attr.state == C4IW_QP_STATE_TERMINATE)
+               c4iw_modify_qp(rhp, qhp, C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
+       else
+               c4iw_modify_qp(rhp, qhp, C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
        wait_event(qhp->wait, !qhp->ep);
 
        remove_handle(rhp, &rhp->qpidr, qhp->wq.sq.qid);
index d9b1bb40f480f7d9662ec96b0695a825858cf0c3..818d721fc4489186fee9d7c6b1fa7e79835f412a 100644 (file)
@@ -125,7 +125,7 @@ int ehca_create_eq(struct ehca_shca *shca,
                tasklet_init(&eq->interrupt_task, ehca_tasklet_eq, (long)shca);
 
                ret = ibmebus_request_irq(eq->ist, ehca_interrupt_eq,
-                                         IRQF_DISABLED, "ehca_eq",
+                                         0, "ehca_eq",
                                          (void *)shca);
                if (ret < 0)
                        ehca_err(ib_dev, "Can't map interrupt handler.");
@@ -133,7 +133,7 @@ int ehca_create_eq(struct ehca_shca *shca,
                tasklet_init(&eq->interrupt_task, ehca_tasklet_neq, (long)shca);
 
                ret = ibmebus_request_irq(eq->ist, ehca_interrupt_neq,
-                                         IRQF_DISABLED, "ehca_neq",
+                                         0, "ehca_neq",
                                          (void *)shca);
                if (ret < 0)
                        ehca_err(ib_dev, "Can't map interrupt handler.");
index 32fb34201aba1b27d0ee2910ba70d958f46d5eb2..964f85520798b81605cf65ea516ef5465e7dc8ad 100644 (file)
@@ -977,6 +977,9 @@ struct ib_srq *ehca_create_srq(struct ib_pd *pd,
        struct hcp_modify_qp_control_block *mqpcb;
        u64 hret, update_mask;
 
+       if (srq_init_attr->srq_type != IB_SRQT_BASIC)
+               return ERR_PTR(-ENOSYS);
+
        /* For common attributes, internal_create_qp() takes its info
         * out of qp_init_attr, so copy all common attrs there.
         */
index 7c1eebe8c7c945e44d72a30ad7e9a4b8c02965d8..824a4d508836835c3e1b74b48f1b3cfc8ec7934e 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/pci.h>
 #include <linux/netdevice.h>
 #include <linux/slab.h>
+#include <linux/stat.h>
 #include <linux/vmalloc.h>
 
 #include "ipath_kernel.h"
index 386e2c717c53b4b03707c8a21fd027cf8121199f..26271984b71741ba5ac556822529aeef9533e766 100644 (file)
@@ -107,6 +107,11 @@ struct ib_srq *ipath_create_srq(struct ib_pd *ibpd,
        u32 sz;
        struct ib_srq *ret;
 
+       if (srq_init_attr->srq_type != IB_SRQT_BASIC) {
+               ret = ERR_PTR(-ENOSYS);
+               goto done;
+       }
+
        if (srq_init_attr->attr.max_wr == 0) {
                ret = ERR_PTR(-EINVAL);
                goto done;
index cfed5399f0746acc71e48f1c4d723c81774cc5e4..dc66c450691602f572b53e53a8dbacfca16e9c4b 100644 (file)
@@ -79,7 +79,7 @@ static int __ipath_get_user_pages(unsigned long start_page, size_t num_pages,
                        goto bail_release;
        }
 
-       current->mm->locked_vm += num_pages;
+       current->mm->pinned_vm += num_pages;
 
        ret = 0;
        goto bail;
@@ -178,7 +178,7 @@ void ipath_release_user_pages(struct page **p, size_t num_pages)
 
        __ipath_release_user_pages(p, num_pages, 1);
 
-       current->mm->locked_vm -= num_pages;
+       current->mm->pinned_vm -= num_pages;
 
        up_write(&current->mm->mmap_sem);
 }
@@ -195,7 +195,7 @@ static void user_pages_account(struct work_struct *_work)
                container_of(_work, struct ipath_user_pages_work, work);
 
        down_write(&work->mm->mmap_sem);
-       work->mm->locked_vm -= work->num_pages;
+       work->mm->pinned_vm -= work->num_pages;
        up_write(&work->mm->mmap_sem);
        mmput(work->mm);
        kfree(work);
index fa643f4f4e28343ff08f1c38af5373a2c5bd719e..77f3dbc0aaa1629783bfadb84d0ac5ad754e8207 100644 (file)
@@ -128,6 +128,8 @@ static int mlx4_ib_query_device(struct ib_device *ibdev,
            (dev->dev->caps.bmme_flags & MLX4_BMME_FLAG_REMOTE_INV) &&
            (dev->dev->caps.bmme_flags & MLX4_BMME_FLAG_FAST_REG_WR))
                props->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS;
+       if (dev->dev->caps.flags & MLX4_DEV_CAP_FLAG_XRC)
+               props->device_cap_flags |= IB_DEVICE_XRC;
 
        props->vendor_id           = be32_to_cpup((__be32 *) (out_mad->data + 36)) &
                0xffffff;
@@ -181,8 +183,12 @@ mlx4_ib_port_link_layer(struct ib_device *device, u8 port_num)
 
 static int ib_link_query_port(struct ib_device *ibdev, u8 port,
                              struct ib_port_attr *props,
+                             struct ib_smp *in_mad,
                              struct ib_smp *out_mad)
 {
+       int ext_active_speed;
+       int err;
+
        props->lid              = be16_to_cpup((__be16 *) (out_mad->data + 16));
        props->lmc              = out_mad->data[34] & 0x7;
        props->sm_lid           = be16_to_cpup((__be16 *) (out_mad->data + 18));
@@ -203,6 +209,39 @@ static int ib_link_query_port(struct ib_device *ibdev, u8 port,
        props->max_vl_num       = out_mad->data[37] >> 4;
        props->init_type_reply  = out_mad->data[41] >> 4;
 
+       /* Check if extended speeds (EDR/FDR/...) are supported */
+       if (props->port_cap_flags & IB_PORT_EXTENDED_SPEEDS_SUP) {
+               ext_active_speed = out_mad->data[62] >> 4;
+
+               switch (ext_active_speed) {
+               case 1:
+                       props->active_speed = 16; /* FDR */
+                       break;
+               case 2:
+                       props->active_speed = 32; /* EDR */
+                       break;
+               }
+       }
+
+       /* If reported active speed is QDR, check if is FDR-10 */
+       if (props->active_speed == 4) {
+               if (to_mdev(ibdev)->dev->caps.ext_port_cap[port] &
+                   MLX_EXT_PORT_CAP_FLAG_EXTENDED_PORT_INFO) {
+                       init_query_mad(in_mad);
+                       in_mad->attr_id = MLX4_ATTR_EXTENDED_PORT_INFO;
+                       in_mad->attr_mod = cpu_to_be32(port);
+
+                       err = mlx4_MAD_IFC(to_mdev(ibdev), 1, 1, port,
+                                          NULL, NULL, in_mad, out_mad);
+                       if (err)
+                               return err;
+
+                       /* Checking LinkSpeedActive for FDR-10 */
+                       if (out_mad->data[15] & 0x1)
+                               props->active_speed = 8;
+               }
+       }
+
        return 0;
 }
 
@@ -227,7 +266,7 @@ static int eth_link_query_port(struct ib_device *ibdev, u8 port,
        props->pkey_tbl_len     = 1;
        props->bad_pkey_cntr    = be16_to_cpup((__be16 *) (out_mad->data + 46));
        props->qkey_viol_cntr   = be16_to_cpup((__be16 *) (out_mad->data + 48));
-       props->max_mtu          = IB_MTU_2048;
+       props->max_mtu          = IB_MTU_4096;
        props->subnet_timeout   = 0;
        props->max_vl_num       = out_mad->data[37] >> 4;
        props->init_type_reply  = 0;
@@ -274,7 +313,7 @@ static int mlx4_ib_query_port(struct ib_device *ibdev, u8 port,
                goto out;
 
        err = mlx4_ib_port_link_layer(ibdev, port) == IB_LINK_LAYER_INFINIBAND ?
-               ib_link_query_port(ibdev, port, props, out_mad) :
+               ib_link_query_port(ibdev, port, props, in_mad, out_mad) :
                eth_link_query_port(ibdev, port, props, out_mad);
 
 out:
@@ -566,6 +605,57 @@ static int mlx4_ib_dealloc_pd(struct ib_pd *pd)
        return 0;
 }
 
+static struct ib_xrcd *mlx4_ib_alloc_xrcd(struct ib_device *ibdev,
+                                         struct ib_ucontext *context,
+                                         struct ib_udata *udata)
+{
+       struct mlx4_ib_xrcd *xrcd;
+       int err;
+
+       if (!(to_mdev(ibdev)->dev->caps.flags & MLX4_DEV_CAP_FLAG_XRC))
+               return ERR_PTR(-ENOSYS);
+
+       xrcd = kmalloc(sizeof *xrcd, GFP_KERNEL);
+       if (!xrcd)
+               return ERR_PTR(-ENOMEM);
+
+       err = mlx4_xrcd_alloc(to_mdev(ibdev)->dev, &xrcd->xrcdn);
+       if (err)
+               goto err1;
+
+       xrcd->pd = ib_alloc_pd(ibdev);
+       if (IS_ERR(xrcd->pd)) {
+               err = PTR_ERR(xrcd->pd);
+               goto err2;
+       }
+
+       xrcd->cq = ib_create_cq(ibdev, NULL, NULL, xrcd, 1, 0);
+       if (IS_ERR(xrcd->cq)) {
+               err = PTR_ERR(xrcd->cq);
+               goto err3;
+       }
+
+       return &xrcd->ibxrcd;
+
+err3:
+       ib_dealloc_pd(xrcd->pd);
+err2:
+       mlx4_xrcd_free(to_mdev(ibdev)->dev, xrcd->xrcdn);
+err1:
+       kfree(xrcd);
+       return ERR_PTR(err);
+}
+
+static int mlx4_ib_dealloc_xrcd(struct ib_xrcd *xrcd)
+{
+       ib_destroy_cq(to_mxrcd(xrcd)->cq);
+       ib_dealloc_pd(to_mxrcd(xrcd)->pd);
+       mlx4_xrcd_free(to_mdev(xrcd->device)->dev, to_mxrcd(xrcd)->xrcdn);
+       kfree(xrcd);
+
+       return 0;
+}
+
 static int add_gid_entry(struct ib_qp *ibqp, union ib_gid *gid)
 {
        struct mlx4_ib_qp *mqp = to_mqp(ibqp);
@@ -1044,7 +1134,9 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
                (1ull << IB_USER_VERBS_CMD_CREATE_SRQ)          |
                (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ)          |
                (1ull << IB_USER_VERBS_CMD_QUERY_SRQ)           |
-               (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ);
+               (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ)         |
+               (1ull << IB_USER_VERBS_CMD_CREATE_XSRQ)         |
+               (1ull << IB_USER_VERBS_CMD_OPEN_QP);
 
        ibdev->ib_dev.query_device      = mlx4_ib_query_device;
        ibdev->ib_dev.query_port        = mlx4_ib_query_port;
@@ -1093,6 +1185,14 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
        ibdev->ib_dev.unmap_fmr         = mlx4_ib_unmap_fmr;
        ibdev->ib_dev.dealloc_fmr       = mlx4_ib_fmr_dealloc;
 
+       if (dev->caps.flags & MLX4_DEV_CAP_FLAG_XRC) {
+               ibdev->ib_dev.alloc_xrcd = mlx4_ib_alloc_xrcd;
+               ibdev->ib_dev.dealloc_xrcd = mlx4_ib_dealloc_xrcd;
+               ibdev->ib_dev.uverbs_cmd_mask |=
+                       (1ull << IB_USER_VERBS_CMD_OPEN_XRCD) |
+                       (1ull << IB_USER_VERBS_CMD_CLOSE_XRCD);
+       }
+
        spin_lock_init(&iboe->lock);
 
        if (init_node_data(ibdev))
index e4bf2cff86626057a2a9a78bf2b160685d276d65..ed80345c99ae159a458ed952514620bb35aca968 100644 (file)
@@ -56,6 +56,13 @@ struct mlx4_ib_pd {
        u32                     pdn;
 };
 
+struct mlx4_ib_xrcd {
+       struct ib_xrcd          ibxrcd;
+       u32                     xrcdn;
+       struct ib_pd           *pd;
+       struct ib_cq           *cq;
+};
+
 struct mlx4_ib_cq_buf {
        struct mlx4_buf         buf;
        struct mlx4_mtt         mtt;
@@ -138,6 +145,7 @@ struct mlx4_ib_qp {
        struct mlx4_mtt         mtt;
        int                     buf_size;
        struct mutex            mutex;
+       u16                     xrcdn;
        u32                     flags;
        u8                      port;
        u8                      alt_port;
@@ -211,6 +219,11 @@ static inline struct mlx4_ib_pd *to_mpd(struct ib_pd *ibpd)
        return container_of(ibpd, struct mlx4_ib_pd, ibpd);
 }
 
+static inline struct mlx4_ib_xrcd *to_mxrcd(struct ib_xrcd *ibxrcd)
+{
+       return container_of(ibxrcd, struct mlx4_ib_xrcd, ibxrcd);
+}
+
 static inline struct mlx4_ib_cq *to_mcq(struct ib_cq *ibcq)
 {
        return container_of(ibcq, struct mlx4_ib_cq, ibcq);
index 3a91d9d8dc518fc278b819e594978477aaeeff56..a16f0c8e6f3f692a10b166f6577ebffe663346d5 100644 (file)
@@ -302,15 +302,14 @@ static int send_wqe_overhead(enum ib_qp_type type, u32 flags)
 }
 
 static int set_rq_size(struct mlx4_ib_dev *dev, struct ib_qp_cap *cap,
-                      int is_user, int has_srq, struct mlx4_ib_qp *qp)
+                      int is_user, int has_rq, struct mlx4_ib_qp *qp)
 {
        /* Sanity check RQ size before proceeding */
        if (cap->max_recv_wr  > dev->dev->caps.max_wqes  ||
            cap->max_recv_sge > dev->dev->caps.max_rq_sg)
                return -EINVAL;
 
-       if (has_srq) {
-               /* QPs attached to an SRQ should have no RQ */
+       if (!has_rq) {
                if (cap->max_recv_wr)
                        return -EINVAL;
 
@@ -463,6 +462,14 @@ static int set_user_sq_size(struct mlx4_ib_dev *dev,
        return 0;
 }
 
+static int qp_has_rq(struct ib_qp_init_attr *attr)
+{
+       if (attr->qp_type == IB_QPT_XRC_INI || attr->qp_type == IB_QPT_XRC_TGT)
+               return 0;
+
+       return !attr->srq;
+}
+
 static int create_qp_common(struct mlx4_ib_dev *dev, struct ib_pd *pd,
                            struct ib_qp_init_attr *init_attr,
                            struct ib_udata *udata, int sqpn, struct mlx4_ib_qp *qp)
@@ -479,7 +486,7 @@ static int create_qp_common(struct mlx4_ib_dev *dev, struct ib_pd *pd,
        if (init_attr->sq_sig_type == IB_SIGNAL_ALL_WR)
                qp->sq_signal_bits = cpu_to_be32(MLX4_WQE_CTRL_CQ_UPDATE);
 
-       err = set_rq_size(dev, &init_attr->cap, !!pd->uobject, !!init_attr->srq, qp);
+       err = set_rq_size(dev, &init_attr->cap, !!pd->uobject, qp_has_rq(init_attr), qp);
        if (err)
                goto err;
 
@@ -513,7 +520,7 @@ static int create_qp_common(struct mlx4_ib_dev *dev, struct ib_pd *pd,
                if (err)
                        goto err_mtt;
 
-               if (!init_attr->srq) {
+               if (qp_has_rq(init_attr)) {
                        err = mlx4_ib_db_map_user(to_mucontext(pd->uobject->context),
                                                  ucmd.db_addr, &qp->db);
                        if (err)
@@ -532,7 +539,7 @@ static int create_qp_common(struct mlx4_ib_dev *dev, struct ib_pd *pd,
                if (err)
                        goto err;
 
-               if (!init_attr->srq) {
+               if (qp_has_rq(init_attr)) {
                        err = mlx4_db_alloc(dev->dev, &qp->db, 0);
                        if (err)
                                goto err;
@@ -575,6 +582,9 @@ static int create_qp_common(struct mlx4_ib_dev *dev, struct ib_pd *pd,
        if (err)
                goto err_qpn;
 
+       if (init_attr->qp_type == IB_QPT_XRC_TGT)
+               qp->mqp.qpn |= (1 << 23);
+
        /*
         * Hardware wants QPN written in big-endian order (after
         * shifting) for send doorbell.  Precompute this value to save
@@ -592,9 +602,8 @@ err_qpn:
 
 err_wrid:
        if (pd->uobject) {
-               if (!init_attr->srq)
-                       mlx4_ib_db_unmap_user(to_mucontext(pd->uobject->context),
-                                             &qp->db);
+               if (qp_has_rq(init_attr))
+                       mlx4_ib_db_unmap_user(to_mucontext(pd->uobject->context), &qp->db);
        } else {
                kfree(qp->sq.wrid);
                kfree(qp->rq.wrid);
@@ -610,7 +619,7 @@ err_buf:
                mlx4_buf_free(dev->dev, qp->buf_size, &qp->buf);
 
 err_db:
-       if (!pd->uobject && !init_attr->srq)
+       if (!pd->uobject && qp_has_rq(init_attr))
                mlx4_db_free(dev->dev, &qp->db);
 
 err:
@@ -671,6 +680,33 @@ static void del_gid_entries(struct mlx4_ib_qp *qp)
        }
 }
 
+static struct mlx4_ib_pd *get_pd(struct mlx4_ib_qp *qp)
+{
+       if (qp->ibqp.qp_type == IB_QPT_XRC_TGT)
+               return to_mpd(to_mxrcd(qp->ibqp.xrcd)->pd);
+       else
+               return to_mpd(qp->ibqp.pd);
+}
+
+static void get_cqs(struct mlx4_ib_qp *qp,
+                   struct mlx4_ib_cq **send_cq, struct mlx4_ib_cq **recv_cq)
+{
+       switch (qp->ibqp.qp_type) {
+       case IB_QPT_XRC_TGT:
+               *send_cq = to_mcq(to_mxrcd(qp->ibqp.xrcd)->cq);
+               *recv_cq = *send_cq;
+               break;
+       case IB_QPT_XRC_INI:
+               *send_cq = to_mcq(qp->ibqp.send_cq);
+               *recv_cq = *send_cq;
+               break;
+       default:
+               *send_cq = to_mcq(qp->ibqp.send_cq);
+               *recv_cq = to_mcq(qp->ibqp.recv_cq);
+               break;
+       }
+}
+
 static void destroy_qp_common(struct mlx4_ib_dev *dev, struct mlx4_ib_qp *qp,
                              int is_user)
 {
@@ -682,8 +718,7 @@ static void destroy_qp_common(struct mlx4_ib_dev *dev, struct mlx4_ib_qp *qp,
                        printk(KERN_WARNING "mlx4_ib: modify QP %06x to RESET failed.\n",
                               qp->mqp.qpn);
 
-       send_cq = to_mcq(qp->ibqp.send_cq);
-       recv_cq = to_mcq(qp->ibqp.recv_cq);
+       get_cqs(qp, &send_cq, &recv_cq);
 
        mlx4_ib_lock_cqs(send_cq, recv_cq);
 
@@ -706,7 +741,7 @@ static void destroy_qp_common(struct mlx4_ib_dev *dev, struct mlx4_ib_qp *qp,
        mlx4_mtt_cleanup(dev->dev, &qp->mtt);
 
        if (is_user) {
-               if (!qp->ibqp.srq)
+               if (qp->rq.wqe_cnt)
                        mlx4_ib_db_unmap_user(to_mucontext(qp->ibqp.uobject->context),
                                              &qp->db);
                ib_umem_release(qp->umem);
@@ -714,7 +749,7 @@ static void destroy_qp_common(struct mlx4_ib_dev *dev, struct mlx4_ib_qp *qp,
                kfree(qp->sq.wrid);
                kfree(qp->rq.wrid);
                mlx4_buf_free(dev->dev, qp->buf_size, &qp->buf);
-               if (!qp->ibqp.srq)
+               if (qp->rq.wqe_cnt)
                        mlx4_db_free(dev->dev, &qp->db);
        }
 
@@ -725,10 +760,10 @@ struct ib_qp *mlx4_ib_create_qp(struct ib_pd *pd,
                                struct ib_qp_init_attr *init_attr,
                                struct ib_udata *udata)
 {
-       struct mlx4_ib_dev *dev = to_mdev(pd->device);
        struct mlx4_ib_sqp *sqp;
        struct mlx4_ib_qp *qp;
        int err;
+       u16 xrcdn = 0;
 
        /*
         * We only support LSO and multicast loopback blocking, and
@@ -739,10 +774,20 @@ struct ib_qp *mlx4_ib_create_qp(struct ib_pd *pd,
                return ERR_PTR(-EINVAL);
 
        if (init_attr->create_flags &&
-           (pd->uobject || init_attr->qp_type != IB_QPT_UD))
+           (udata || init_attr->qp_type != IB_QPT_UD))
                return ERR_PTR(-EINVAL);
 
        switch (init_attr->qp_type) {
+       case IB_QPT_XRC_TGT:
+               pd = to_mxrcd(init_attr->xrcd)->pd;
+               xrcdn = to_mxrcd(init_attr->xrcd)->xrcdn;
+               init_attr->send_cq = to_mxrcd(init_attr->xrcd)->cq;
+               /* fall through */
+       case IB_QPT_XRC_INI:
+               if (!(to_mdev(pd->device)->dev->caps.flags & MLX4_DEV_CAP_FLAG_XRC))
+                       return ERR_PTR(-ENOSYS);
+               init_attr->recv_cq = init_attr->send_cq;
+               /* fall through */
        case IB_QPT_RC:
        case IB_QPT_UC:
        case IB_QPT_UD:
@@ -751,13 +796,14 @@ struct ib_qp *mlx4_ib_create_qp(struct ib_pd *pd,
                if (!qp)
                        return ERR_PTR(-ENOMEM);
 
-               err = create_qp_common(dev, pd, init_attr, udata, 0, qp);
+               err = create_qp_common(to_mdev(pd->device), pd, init_attr, udata, 0, qp);
                if (err) {
                        kfree(qp);
                        return ERR_PTR(err);
                }
 
                qp->ibqp.qp_num = qp->mqp.qpn;
+               qp->xrcdn = xrcdn;
 
                break;
        }
@@ -765,7 +811,7 @@ struct ib_qp *mlx4_ib_create_qp(struct ib_pd *pd,
        case IB_QPT_GSI:
        {
                /* Userspace is not allowed to create special QPs: */
-               if (pd->uobject)
+               if (udata)
                        return ERR_PTR(-EINVAL);
 
                sqp = kzalloc(sizeof *sqp, GFP_KERNEL);
@@ -774,8 +820,8 @@ struct ib_qp *mlx4_ib_create_qp(struct ib_pd *pd,
 
                qp = &sqp->qp;
 
-               err = create_qp_common(dev, pd, init_attr, udata,
-                                      dev->dev->caps.sqp_start +
+               err = create_qp_common(to_mdev(pd->device), pd, init_attr, udata,
+                                      to_mdev(pd->device)->dev->caps.sqp_start +
                                       (init_attr->qp_type == IB_QPT_SMI ? 0 : 2) +
                                       init_attr->port_num - 1,
                                       qp);
@@ -801,11 +847,13 @@ int mlx4_ib_destroy_qp(struct ib_qp *qp)
 {
        struct mlx4_ib_dev *dev = to_mdev(qp->device);
        struct mlx4_ib_qp *mqp = to_mqp(qp);
+       struct mlx4_ib_pd *pd;
 
        if (is_qp0(dev, mqp))
                mlx4_CLOSE_PORT(dev->dev, mqp->port);
 
-       destroy_qp_common(dev, mqp, !!qp->pd->uobject);
+       pd = get_pd(mqp);
+       destroy_qp_common(dev, mqp, !!pd->ibpd.uobject);
 
        if (is_sqp(dev, mqp))
                kfree(to_msqp(mqp));
@@ -821,6 +869,8 @@ static int to_mlx4_st(enum ib_qp_type type)
        case IB_QPT_RC:         return MLX4_QP_ST_RC;
        case IB_QPT_UC:         return MLX4_QP_ST_UC;
        case IB_QPT_UD:         return MLX4_QP_ST_UD;
+       case IB_QPT_XRC_INI:
+       case IB_QPT_XRC_TGT:    return MLX4_QP_ST_XRC;
        case IB_QPT_SMI:
        case IB_QPT_GSI:        return MLX4_QP_ST_MLX;
        default:                return -1;
@@ -959,6 +1009,8 @@ static int __mlx4_ib_modify_qp(struct ib_qp *ibqp,
 {
        struct mlx4_ib_dev *dev = to_mdev(ibqp->device);
        struct mlx4_ib_qp *qp = to_mqp(ibqp);
+       struct mlx4_ib_pd *pd;
+       struct mlx4_ib_cq *send_cq, *recv_cq;
        struct mlx4_qp_context *context;
        enum mlx4_qp_optpar optpar = 0;
        int sqd_event;
@@ -1014,8 +1066,10 @@ static int __mlx4_ib_modify_qp(struct ib_qp *ibqp,
                context->sq_size_stride = ilog2(qp->sq.wqe_cnt) << 3;
        context->sq_size_stride |= qp->sq.wqe_shift - 4;
 
-       if (cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT)
+       if (cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT) {
                context->sq_size_stride |= !!qp->sq_no_prefetch << 7;
+               context->xrcd = cpu_to_be32((u32) qp->xrcdn);
+       }
 
        if (qp->ibqp.uobject)
                context->usr_page = cpu_to_be32(to_mucontext(ibqp->uobject->context)->uar.index);
@@ -1079,8 +1133,12 @@ static int __mlx4_ib_modify_qp(struct ib_qp *ibqp,
                optpar |= MLX4_QP_OPTPAR_ALT_ADDR_PATH;
        }
 
-       context->pd         = cpu_to_be32(to_mpd(ibqp->pd)->pdn);
-       context->params1    = cpu_to_be32(MLX4_IB_ACK_REQ_FREQ << 28);
+       pd = get_pd(qp);
+       get_cqs(qp, &send_cq, &recv_cq);
+       context->pd       = cpu_to_be32(pd->pdn);
+       context->cqn_send = cpu_to_be32(send_cq->mcq.cqn);
+       context->cqn_recv = cpu_to_be32(recv_cq->mcq.cqn);
+       context->params1  = cpu_to_be32(MLX4_IB_ACK_REQ_FREQ << 28);
 
        /* Set "fast registration enabled" for all kernel QPs */
        if (!qp->ibqp.uobject)
@@ -1106,8 +1164,6 @@ static int __mlx4_ib_modify_qp(struct ib_qp *ibqp,
        if (attr_mask & IB_QP_SQ_PSN)
                context->next_send_psn = cpu_to_be32(attr->sq_psn);
 
-       context->cqn_send = cpu_to_be32(to_mcq(ibqp->send_cq)->mcq.cqn);
-
        if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) {
                if (attr->max_dest_rd_atomic)
                        context->params2 |=
@@ -1130,8 +1186,6 @@ static int __mlx4_ib_modify_qp(struct ib_qp *ibqp,
        if (attr_mask & IB_QP_RQ_PSN)
                context->rnr_nextrecvpsn |= cpu_to_be32(attr->rq_psn);
 
-       context->cqn_recv = cpu_to_be32(to_mcq(ibqp->recv_cq)->mcq.cqn);
-
        if (attr_mask & IB_QP_QKEY) {
                context->qkey = cpu_to_be32(attr->qkey);
                optpar |= MLX4_QP_OPTPAR_Q_KEY;
@@ -1140,7 +1194,7 @@ static int __mlx4_ib_modify_qp(struct ib_qp *ibqp,
        if (ibqp->srq)
                context->srqn = cpu_to_be32(1 << 24 | to_msrq(ibqp->srq)->msrq.srqn);
 
-       if (!ibqp->srq && cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT)
+       if (qp->rq.wqe_cnt && cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT)
                context->db_rec_addr = cpu_to_be64(qp->db.dma);
 
        if (cur_state == IB_QPS_INIT &&
@@ -1225,17 +1279,17 @@ static int __mlx4_ib_modify_qp(struct ib_qp *ibqp,
         * entries and reinitialize the QP.
         */
        if (new_state == IB_QPS_RESET && !ibqp->uobject) {
-               mlx4_ib_cq_clean(to_mcq(ibqp->recv_cq), qp->mqp.qpn,
+               mlx4_ib_cq_clean(recv_cq, qp->mqp.qpn,
                                 ibqp->srq ? to_msrq(ibqp->srq): NULL);
-               if (ibqp->send_cq != ibqp->recv_cq)
-                       mlx4_ib_cq_clean(to_mcq(ibqp->send_cq), qp->mqp.qpn, NULL);
+               if (send_cq != recv_cq)
+                       mlx4_ib_cq_clean(send_cq, qp->mqp.qpn, NULL);
 
                qp->rq.head = 0;
                qp->rq.tail = 0;
                qp->sq.head = 0;
                qp->sq.tail = 0;
                qp->sq_next_wqe = 0;
-               if (!ibqp->srq)
+               if (qp->rq.wqe_cnt)
                        *qp->db.db  = 0;
        }
 
@@ -1547,14 +1601,13 @@ static void set_masked_atomic_seg(struct mlx4_wqe_masked_atomic_seg *aseg,
 }
 
 static void set_datagram_seg(struct mlx4_wqe_datagram_seg *dseg,
-                            struct ib_send_wr *wr, __be16 *vlan)
+                            struct ib_send_wr *wr)
 {
        memcpy(dseg->av, &to_mah(wr->wr.ud.ah)->av, sizeof (struct mlx4_av));
        dseg->dqpn = cpu_to_be32(wr->wr.ud.remote_qpn);
        dseg->qkey = cpu_to_be32(wr->wr.ud.remote_qkey);
        dseg->vlan = to_mah(wr->wr.ud.ah)->av.eth.vlan;
        memcpy(dseg->mac, to_mah(wr->wr.ud.ah)->av.eth.mac, 6);
-       *vlan = dseg->vlan;
 }
 
 static void set_mlx_icrc_seg(void *dseg)
@@ -1657,7 +1710,6 @@ int mlx4_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
        __be32 uninitialized_var(lso_hdr_sz);
        __be32 blh;
        int i;
-       __be16 vlan = cpu_to_be16(0xffff);
 
        spin_lock_irqsave(&qp->sq.lock, flags);
 
@@ -1761,7 +1813,7 @@ int mlx4_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
                        break;
 
                case IB_QPT_UD:
-                       set_datagram_seg(wqe, wr, &vlan);
+                       set_datagram_seg(wqe, wr);
                        wqe  += sizeof (struct mlx4_wqe_datagram_seg);
                        size += sizeof (struct mlx4_wqe_datagram_seg) / 16;
 
@@ -1824,11 +1876,6 @@ int mlx4_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
                ctrl->fence_size = (wr->send_flags & IB_SEND_FENCE ?
                                    MLX4_WQE_CTRL_FENCE : 0) | size;
 
-               if (be16_to_cpu(vlan) < 0x1000) {
-                       ctrl->ins_vlan = 1 << 6;
-                       ctrl->vlan_tag = vlan;
-               }
-
                /*
                 * Make sure descriptor is fully written before
                 * setting ownership bit (because HW can start
index 818b7ecace5e3c812b7f7500ba44a13ac46ef397..39542f3703b80dac2dd288e2e92ff793040316ad 100644 (file)
@@ -76,6 +76,8 @@ struct ib_srq *mlx4_ib_create_srq(struct ib_pd *pd,
        struct mlx4_ib_srq *srq;
        struct mlx4_wqe_srq_next_seg *next;
        struct mlx4_wqe_data_seg *scatter;
+       u32 cqn;
+       u16 xrcdn;
        int desc_size;
        int buf_size;
        int err;
@@ -174,12 +176,18 @@ struct ib_srq *mlx4_ib_create_srq(struct ib_pd *pd,
                }
        }
 
-       err = mlx4_srq_alloc(dev->dev, to_mpd(pd)->pdn, &srq->mtt,
+       cqn = (init_attr->srq_type == IB_SRQT_XRC) ?
+               to_mcq(init_attr->ext.xrc.cq)->mcq.cqn : 0;
+       xrcdn = (init_attr->srq_type == IB_SRQT_XRC) ?
+               to_mxrcd(init_attr->ext.xrc.xrcd)->xrcdn :
+               (u16) dev->dev->caps.reserved_xrcds;
+       err = mlx4_srq_alloc(dev->dev, to_mpd(pd)->pdn, cqn, xrcdn, &srq->mtt,
                             srq->db.dma, &srq->msrq);
        if (err)
                goto err_wrid;
 
        srq->msrq.event = mlx4_ib_srq_event;
+       srq->ibsrq.ext.xrc.srq_num = srq->msrq.srqn;
 
        if (pd->uobject)
                if (ib_copy_to_udata(udata, &srq->msrq.srqn, sizeof (__u32))) {
index 365fe0e14192ce7ecc715d609327758c03db54b8..cb9a0b976804fa879f997eff4f6d60b5e9b6ff00 100644 (file)
@@ -438,6 +438,9 @@ static struct ib_srq *mthca_create_srq(struct ib_pd *pd,
        struct mthca_srq *srq;
        int err;
 
+       if (init_attr->srq_type != IB_SRQT_BASIC)
+               return ERR_PTR(-ENOSYS);
+
        srq = kmalloc(sizeof *srq, GFP_KERNEL);
        if (!srq)
                return ERR_PTR(-ENOMEM);
index 35148513c47ebc762fed61a1b979fae975cf5527..97820c23ecef7a9776fa6abd2d369a84fa778fd9 100644 (file)
@@ -1,3 +1,3 @@
 obj-$(CONFIG_INFINIBAND_NES) += iw_nes.o
 
-iw_nes-objs := nes.o nes_hw.o nes_nic.o nes_utils.o nes_verbs.o nes_cm.o
+iw_nes-objs := nes.o nes_hw.o nes_nic.o nes_utils.o nes_verbs.o nes_cm.o nes_mgt.o
index 2d668c69f6d958bcd9ba275967c8bbc1f3a93b9d..5965b3df8f2f6ee0c10dbbc9b7f8218823161ccc 100644 (file)
@@ -84,7 +84,7 @@ module_param(send_first, int, 0644);
 MODULE_PARM_DESC(send_first, "Send RDMA Message First on Active Connection");
 
 
-unsigned int nes_drv_opt = 0;
+unsigned int nes_drv_opt = NES_DRV_OPT_DISABLE_INT_MOD | NES_DRV_OPT_ENABLE_PAU;
 module_param(nes_drv_opt, int, 0644);
 MODULE_PARM_DESC(nes_drv_opt, "Driver option parameters");
 
@@ -130,9 +130,6 @@ static struct notifier_block nes_net_notifier = {
        .notifier_call = nes_net_event
 };
 
-
-
-
 /**
  * nes_inetaddr_event
  */
@@ -321,6 +318,9 @@ void nes_rem_ref(struct ib_qp *ibqp)
        }
 
        if (atomic_dec_and_test(&nesqp->refcount)) {
+               if (nesqp->pau_mode)
+                       nes_destroy_pau_qp(nesdev, nesqp);
+
                /* Destroy the QP */
                cqp_request = nes_get_cqp_request(nesdev);
                if (cqp_request == NULL) {
index 6fe79876009e4e070ee01ea00528594ab65f52d5..568b4f11380ae545d264a48e6fae51784ddf5533 100644 (file)
 #define NES_DRV_OPT_NO_INLINE_DATA       0x00000080
 #define NES_DRV_OPT_DISABLE_INT_MOD      0x00000100
 #define NES_DRV_OPT_DISABLE_VIRT_WQ      0x00000200
+#define NES_DRV_OPT_ENABLE_PAU           0x00000400
 
 #define NES_AEQ_EVENT_TIMEOUT         2500
 #define NES_DISCONNECT_EVENT_TIMEOUT  2000
 #define NES_DBG_IW_RX       0x00020000
 #define NES_DBG_IW_TX       0x00040000
 #define NES_DBG_SHUTDOWN    0x00080000
+#define NES_DBG_PAU         0x00100000
 #define NES_DBG_RSVD1       0x10000000
 #define NES_DBG_RSVD2       0x20000000
 #define NES_DBG_RSVD3       0x40000000
@@ -162,6 +164,7 @@ do { \
 #include "nes_context.h"
 #include "nes_user.h"
 #include "nes_cm.h"
+#include "nes_mgt.h"
 
 extern int max_mtu;
 #define max_frame_len (max_mtu+ETH_HLEN)
@@ -202,6 +205,8 @@ extern atomic_t cm_nodes_created;
 extern atomic_t cm_nodes_destroyed;
 extern atomic_t cm_accel_dropped_pkts;
 extern atomic_t cm_resets_recvd;
+extern atomic_t pau_qps_created;
+extern atomic_t pau_qps_destroyed;
 
 extern u32 int_mod_timer_init;
 extern u32 int_mod_cq_depth_256;
@@ -273,6 +278,14 @@ struct nes_device {
        u8                     link_recheck;
 };
 
+/* Receive skb private area - must fit in skb->cb area */
+struct nes_rskb_cb {
+       u64                    busaddr;
+       u32                    maplen;
+       u32                    seqnum;
+       u8                     *data_start;
+       struct nes_qp          *nesqp;
+};
 
 static inline __le32 get_crc_value(struct nes_v4_quad *nes_quad)
 {
@@ -305,8 +318,8 @@ set_wqe_32bit_value(__le32 *wqe_words, u32 index, u32 value)
 static inline void
 nes_fill_init_cqp_wqe(struct nes_hw_cqp_wqe *cqp_wqe, struct nes_device *nesdev)
 {
-       set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_COMP_CTX_LOW_IDX,
-                       (u64)((unsigned long) &nesdev->cqp));
+       cqp_wqe->wqe_words[NES_CQP_WQE_COMP_CTX_LOW_IDX]       = 0;
+       cqp_wqe->wqe_words[NES_CQP_WQE_COMP_CTX_HIGH_IDX]      = 0;
        cqp_wqe->wqe_words[NES_CQP_WQE_COMP_SCRATCH_LOW_IDX]   = 0;
        cqp_wqe->wqe_words[NES_CQP_WQE_COMP_SCRATCH_HIGH_IDX]  = 0;
        cqp_wqe->wqe_words[NES_CQP_STAG_WQE_PBL_BLK_COUNT_IDX] = 0;
index c118663e44377b2bba3cfb8d1bf246928a131004..dfce9ea98a39b3f0f68e6d152d438554ebe8ee84 100644 (file)
@@ -77,26 +77,19 @@ atomic_t cm_nodes_destroyed;
 atomic_t cm_accel_dropped_pkts;
 atomic_t cm_resets_recvd;
 
-static inline int mini_cm_accelerated(struct nes_cm_core *,
-       struct nes_cm_node *);
-static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *,
-       struct nes_vnic *, struct nes_cm_info *);
+static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
+static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
 static int mini_cm_del_listen(struct nes_cm_core *, struct nes_cm_listener *);
-static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *,
-       struct nes_vnic *, u16, void *, struct nes_cm_info *);
+static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *, struct nes_vnic *, u16, void *, struct nes_cm_info *);
 static int mini_cm_close(struct nes_cm_core *, struct nes_cm_node *);
-static int mini_cm_accept(struct nes_cm_core *, struct ietf_mpa_frame *,
-       struct nes_cm_node *);
-static int mini_cm_reject(struct nes_cm_core *, struct ietf_mpa_frame *,
-       struct nes_cm_node *);
-static int mini_cm_recv_pkt(struct nes_cm_core *, struct nes_vnic *,
-       struct sk_buff *);
+static int mini_cm_accept(struct nes_cm_core *, struct nes_cm_node *);
+static int mini_cm_reject(struct nes_cm_core *, struct nes_cm_node *);
+static int mini_cm_recv_pkt(struct nes_cm_core *, struct nes_vnic *, struct sk_buff *);
 static int mini_cm_dealloc_core(struct nes_cm_core *);
 static int mini_cm_get(struct nes_cm_core *);
 static int mini_cm_set(struct nes_cm_core *, u32, u32);
 
-static void form_cm_frame(struct sk_buff *, struct nes_cm_node *,
-       void *, u32, void *, u32, u8);
+static void form_cm_frame(struct sk_buff *, struct nes_cm_node *, void *, u32, void *, u32, u8);
 static int add_ref_cm_node(struct nes_cm_node *);
 static int rem_ref_cm_node(struct nes_cm_core *, struct nes_cm_node *);
 
@@ -111,16 +104,14 @@ static int send_syn(struct nes_cm_node *, u32, struct sk_buff *);
 static int send_reset(struct nes_cm_node *, struct sk_buff *);
 static int send_ack(struct nes_cm_node *cm_node, struct sk_buff *skb);
 static int send_fin(struct nes_cm_node *cm_node, struct sk_buff *skb);
-static void process_packet(struct nes_cm_node *, struct sk_buff *,
-       struct nes_cm_core *);
+static void process_packet(struct nes_cm_node *, struct sk_buff *, struct nes_cm_core *);
 
 static void active_open_err(struct nes_cm_node *, struct sk_buff *, int);
 static void passive_open_err(struct nes_cm_node *, struct sk_buff *, int);
 static void cleanup_retrans_entry(struct nes_cm_node *);
 static void handle_rcv_mpa(struct nes_cm_node *, struct sk_buff *);
 static void free_retrans_entry(struct nes_cm_node *cm_node);
-static int handle_tcp_options(struct nes_cm_node *cm_node, struct tcphdr *tcph,
-       struct sk_buff *skb, int optionsize, int passive);
+static int handle_tcp_options(struct nes_cm_node *cm_node, struct tcphdr *tcph, struct sk_buff *skb, int optionsize, int passive);
 
 /* CM event handler functions */
 static void cm_event_connected(struct nes_cm_event *);
@@ -130,6 +121,12 @@ static void cm_event_mpa_req(struct nes_cm_event *);
 static void cm_event_mpa_reject(struct nes_cm_event *);
 static void handle_recv_entry(struct nes_cm_node *cm_node, u32 rem_node);
 
+/* MPA build functions */
+static int cm_build_mpa_frame(struct nes_cm_node *, u8 **, u16 *, u8 *, u8);
+static void build_mpa_v2(struct nes_cm_node *, void *, u8);
+static void build_mpa_v1(struct nes_cm_node *, void *, u8);
+static void build_rdma0_msg(struct nes_cm_node *, struct nes_qp **);
+
 static void print_core(struct nes_cm_core *core);
 
 /* External CM API Interface */
@@ -159,12 +156,21 @@ atomic_t cm_connecteds;
 atomic_t cm_connect_reqs;
 atomic_t cm_rejects;
 
+int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
+{
+       return add_ref_cm_node(cm_node);
+}
+
+int nes_rem_ref_cm_node(struct nes_cm_node *cm_node)
+{
+       return rem_ref_cm_node(cm_node->cm_core, cm_node);
+}
 
 /**
  * create_event
  */
-static struct nes_cm_event *create_event(struct nes_cm_node *cm_node,
-               enum nes_cm_event_type type)
+static struct nes_cm_event *create_event(struct nes_cm_node *  cm_node,
+                                        enum nes_cm_event_type type)
 {
        struct nes_cm_event *event;
 
@@ -186,10 +192,10 @@ static struct nes_cm_event *create_event(struct nes_cm_node *cm_node,
        event->cm_info.cm_id = cm_node->cm_id;
 
        nes_debug(NES_DBG_CM, "cm_node=%p Created event=%p, type=%u, "
-               "dst_addr=%08x[%x], src_addr=%08x[%x]\n",
-               cm_node, event, type, event->cm_info.loc_addr,
-               event->cm_info.loc_port, event->cm_info.rem_addr,
-               event->cm_info.rem_port);
+                 "dst_addr=%08x[%x], src_addr=%08x[%x]\n",
+                 cm_node, event, type, event->cm_info.loc_addr,
+                 event->cm_info.loc_port, event->cm_info.rem_addr,
+                 event->cm_info.rem_port);
 
        nes_cm_post_event(event);
        return event;
@@ -201,14 +207,19 @@ static struct nes_cm_event *create_event(struct nes_cm_node *cm_node,
  */
 static int send_mpa_request(struct nes_cm_node *cm_node, struct sk_buff *skb)
 {
+       u8 start_addr = 0;
+       u8 *start_ptr = &start_addr;
+       u8 **start_buff = &start_ptr;
+       u16 buff_len = 0;
+
        if (!skb) {
                nes_debug(NES_DBG_CM, "skb set to NULL\n");
                return -1;
        }
 
        /* send an MPA Request frame */
-       form_cm_frame(skb, cm_node, NULL, 0, &cm_node->mpa_frame,
-                       cm_node->mpa_frame_size, SET_ACK);
+       cm_build_mpa_frame(cm_node, start_buff, &buff_len, NULL, MPA_KEY_REQUEST);
+       form_cm_frame(skb, cm_node, NULL, 0, *start_buff, buff_len, SET_ACK);
 
        return schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 1, 0);
 }
@@ -217,7 +228,11 @@ static int send_mpa_request(struct nes_cm_node *cm_node, struct sk_buff *skb)
 
 static int send_mpa_reject(struct nes_cm_node *cm_node)
 {
-       struct sk_buff  *skb = NULL;
+       struct sk_buff *skb = NULL;
+       u8 start_addr = 0;
+       u8 *start_ptr = &start_addr;
+       u8 **start_buff = &start_ptr;
+       u16 buff_len = 0;
 
        skb = dev_alloc_skb(MAX_CM_BUFFER);
        if (!skb) {
@@ -226,8 +241,8 @@ static int send_mpa_reject(struct nes_cm_node *cm_node)
        }
 
        /* send an MPA reject frame */
-       form_cm_frame(skb, cm_node, NULL, 0, &cm_node->mpa_frame,
-                       cm_node->mpa_frame_size, SET_ACK | SET_FIN);
+       cm_build_mpa_frame(cm_node, start_buff, &buff_len, NULL, MPA_KEY_REPLY);
+       form_cm_frame(skb, cm_node, NULL, 0, *start_buff, buff_len, SET_ACK | SET_FIN);
 
        cm_node->state = NES_CM_STATE_FIN_WAIT1;
        return schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 1, 0);
@@ -239,24 +254,31 @@ static int send_mpa_reject(struct nes_cm_node *cm_node)
  * IETF MPA frame
  */
 static int parse_mpa(struct nes_cm_node *cm_node, u8 *buffer, u32 *type,
-               u32 len)
+                    u32 len)
 {
-       struct ietf_mpa_frame *mpa_frame;
+       struct ietf_mpa_v1 *mpa_frame;
+       struct ietf_mpa_v2 *mpa_v2_frame;
+       struct ietf_rtr_msg *rtr_msg;
+       int mpa_hdr_len;
+       int priv_data_len;
 
        *type = NES_MPA_REQUEST_ACCEPT;
 
        /* assume req frame is in tcp data payload */
-       if (len < sizeof(struct ietf_mpa_frame)) {
+       if (len < sizeof(struct ietf_mpa_v1)) {
                nes_debug(NES_DBG_CM, "The received ietf buffer was too small (%x)\n", len);
                return -EINVAL;
        }
 
-       mpa_frame = (struct ietf_mpa_frame *)buffer;
-       cm_node->mpa_frame_size = ntohs(mpa_frame->priv_data_len);
+       /* points to the beginning of the frame, which could be MPA V1 or V2 */
+       mpa_frame = (struct ietf_mpa_v1 *)buffer;
+       mpa_hdr_len = sizeof(struct ietf_mpa_v1);
+       priv_data_len = ntohs(mpa_frame->priv_data_len);
+
        /* make sure mpa private data len is less than 512 bytes */
-       if (cm_node->mpa_frame_size > IETF_MAX_PRIV_DATA_LEN) {
+       if (priv_data_len > IETF_MAX_PRIV_DATA_LEN) {
                nes_debug(NES_DBG_CM, "The received Length of Private"
-                       " Data field exceeds 512 octets\n");
+                         " Data field exceeds 512 octets\n");
                return -EINVAL;
        }
        /*
@@ -264,11 +286,22 @@ static int parse_mpa(struct nes_cm_node *cm_node, u8 *buffer, u32 *type,
         * received MPA version and MPA key information
         *
         */
-       if (mpa_frame->rev != mpa_version) {
+       if (mpa_frame->rev != IETF_MPA_V1 && mpa_frame->rev != IETF_MPA_V2) {
+               nes_debug(NES_DBG_CM, "The received mpa version"
+                         " is not supported\n");
+               return -EINVAL;
+       }
+       /*
+       * backwards compatibility only
+       */
+       if (mpa_frame->rev > cm_node->mpa_frame_rev) {
                nes_debug(NES_DBG_CM, "The received mpa version"
-                               " can not be interoperated\n");
+                       " can not be interoperated\n");
                return -EINVAL;
+       } else {
+               cm_node->mpa_frame_rev = mpa_frame->rev;
        }
+
        if (cm_node->state != NES_CM_STATE_MPAREQ_SENT) {
                if (memcmp(mpa_frame->key, IEFT_MPA_KEY_REQ, IETF_MPA_KEY_SIZE)) {
                        nes_debug(NES_DBG_CM, "Unexpected MPA Key received \n");
@@ -281,25 +314,75 @@ static int parse_mpa(struct nes_cm_node *cm_node, u8 *buffer, u32 *type,
                }
        }
 
-       if (cm_node->mpa_frame_size + sizeof(struct ietf_mpa_frame) != len) {
+
+       if (priv_data_len + mpa_hdr_len != len) {
                nes_debug(NES_DBG_CM, "The received ietf buffer was not right"
-                               " complete (%x + %x != %x)\n",
-                               cm_node->mpa_frame_size,
-                               (u32)sizeof(struct ietf_mpa_frame), len);
+                       " complete (%x + %x != %x)\n",
+                       priv_data_len, mpa_hdr_len, len);
                return -EINVAL;
        }
        /* make sure it does not exceed the max size */
        if (len > MAX_CM_BUFFER) {
                nes_debug(NES_DBG_CM, "The received ietf buffer was too large"
-                               " (%x + %x != %x)\n",
-                               cm_node->mpa_frame_size,
-                               (u32)sizeof(struct ietf_mpa_frame), len);
+                       " (%x + %x != %x)\n",
+                       priv_data_len, mpa_hdr_len, len);
                return -EINVAL;
        }
 
+       cm_node->mpa_frame_size = priv_data_len;
+
+       switch (mpa_frame->rev) {
+       case IETF_MPA_V2: {
+               u16 ird_size;
+               u16 ord_size;
+               mpa_v2_frame = (struct ietf_mpa_v2 *)buffer;
+               mpa_hdr_len += IETF_RTR_MSG_SIZE;
+               cm_node->mpa_frame_size -= IETF_RTR_MSG_SIZE;
+               rtr_msg = &mpa_v2_frame->rtr_msg;
+
+               /* parse rtr message */
+               rtr_msg->ctrl_ird = ntohs(rtr_msg->ctrl_ird);
+               rtr_msg->ctrl_ord = ntohs(rtr_msg->ctrl_ord);
+               ird_size = rtr_msg->ctrl_ird & IETF_NO_IRD_ORD;
+               ord_size = rtr_msg->ctrl_ord & IETF_NO_IRD_ORD;
+
+               if (!(rtr_msg->ctrl_ird & IETF_PEER_TO_PEER)) {
+                       /* send reset */
+                       return -EINVAL;
+               }
+
+               if (cm_node->state != NES_CM_STATE_MPAREQ_SENT) {
+                       /* responder */
+                       if (cm_node->ord_size > ird_size)
+                               cm_node->ord_size = ird_size;
+               } else {
+                       /* initiator */
+                       if (cm_node->ord_size > ird_size)
+                               cm_node->ord_size = ird_size;
+
+                       if (cm_node->ird_size < ord_size) {
+                               /* no resources available */
+                               /* send terminate message */
+                               return -EINVAL;
+                       }
+               }
+
+               if (rtr_msg->ctrl_ord & IETF_RDMA0_READ) {
+                       cm_node->send_rdma0_op = SEND_RDMA_READ_ZERO;
+               } else if (rtr_msg->ctrl_ord & IETF_RDMA0_WRITE) {
+                       cm_node->send_rdma0_op = SEND_RDMA_WRITE_ZERO;
+               } else {        /* Not supported RDMA0 operation */
+                       return -EINVAL;
+               }
+               break;
+       }
+       case IETF_MPA_V1:
+       default:
+               break;
+       }
+
        /* copy entire MPA frame to our cm_node's frame */
-       memcpy(cm_node->mpa_frame_buf, buffer + sizeof(struct ietf_mpa_frame),
-                       cm_node->mpa_frame_size);
+       memcpy(cm_node->mpa_frame_buf, buffer + mpa_hdr_len, cm_node->mpa_frame_size);
 
        if (mpa_frame->flags & IETF_MPA_FLAGS_REJECT)
                *type = NES_MPA_REQUEST_REJECT;
@@ -312,8 +395,8 @@ static int parse_mpa(struct nes_cm_node *cm_node, u8 *buffer, u32 *type,
  * node info to build.
  */
 static void form_cm_frame(struct sk_buff *skb,
-       struct nes_cm_node *cm_node, void *options, u32 optionsize,
-       void *data, u32 datasize, u8 flags)
+                         struct nes_cm_node *cm_node, void *options, u32 optionsize,
+                         void *data, u32 datasize, u8 flags)
 {
        struct tcphdr *tcph;
        struct iphdr *iph;
@@ -322,14 +405,14 @@ static void form_cm_frame(struct sk_buff *skb,
        u16 packetsize = sizeof(*iph);
 
        packetsize += sizeof(*tcph);
-       packetsize +=  optionsize + datasize;
+       packetsize += optionsize + datasize;
 
+       skb_trim(skb, 0);
        memset(skb->data, 0x00, ETH_HLEN + sizeof(*iph) + sizeof(*tcph));
 
-       skb->len = 0;
        buf = skb_put(skb, packetsize + ETH_HLEN);
 
-       ethh = (struct ethhdr *) buf;
+       ethh = (struct ethhdr *)buf;
        buf += ETH_HLEN;
 
        iph = (struct iphdr *)buf;
@@ -337,7 +420,7 @@ static void form_cm_frame(struct sk_buff *skb,
        tcph = (struct tcphdr *)buf;
        skb_reset_mac_header(skb);
        skb_set_network_header(skb, ETH_HLEN);
-       skb_set_transport_header(skb, ETH_HLEN+sizeof(*iph));
+       skb_set_transport_header(skb, ETH_HLEN + sizeof(*iph));
        buf += sizeof(*tcph);
 
        skb->ip_summed = CHECKSUM_PARTIAL;
@@ -350,14 +433,14 @@ static void form_cm_frame(struct sk_buff *skb,
        ethh->h_proto = htons(0x0800);
 
        iph->version = IPVERSION;
-       iph->ihl = 5;           /* 5 * 4Byte words, IP headr len */
+       iph->ihl = 5;           /* 5 * 4Byte words, IP headr len */
        iph->tos = 0;
        iph->tot_len = htons(packetsize);
        iph->id = htons(++cm_node->tcp_cntxt.loc_id);
 
        iph->frag_off = htons(0x4000);
        iph->ttl = 0x40;
-       iph->protocol = 0x06;   /* IPPROTO_TCP */
+       iph->protocol = 0x06;   /* IPPROTO_TCP */
 
        iph->saddr = htonl(cm_node->loc_addr);
        iph->daddr = htonl(cm_node->rem_addr);
@@ -370,14 +453,16 @@ static void form_cm_frame(struct sk_buff *skb,
                cm_node->tcp_cntxt.loc_ack_num = cm_node->tcp_cntxt.rcv_nxt;
                tcph->ack_seq = htonl(cm_node->tcp_cntxt.loc_ack_num);
                tcph->ack = 1;
-       } else
+       } else {
                tcph->ack_seq = 0;
+       }
 
        if (flags & SET_SYN) {
                cm_node->tcp_cntxt.loc_seq_num++;
                tcph->syn = 1;
-       } else
+       } else {
                cm_node->tcp_cntxt.loc_seq_num += datasize;
+       }
 
        if (flags & SET_FIN) {
                cm_node->tcp_cntxt.loc_seq_num++;
@@ -398,10 +483,8 @@ static void form_cm_frame(struct sk_buff *skb,
 
        skb_shinfo(skb)->nr_frags = 0;
        cm_packets_created++;
-
 }
 
-
 /**
  * print_core - dump a cm core
  */
@@ -413,7 +496,7 @@ static void print_core(struct nes_cm_core *core)
                return;
        nes_debug(NES_DBG_CM, "---------------------------------------------\n");
 
-       nes_debug(NES_DBG_CM, "State         : %u \n",  core->state);
+       nes_debug(NES_DBG_CM, "State         : %u \n", core->state);
 
        nes_debug(NES_DBG_CM, "Listen Nodes  : %u \n", atomic_read(&core->listen_node_cnt));
        nes_debug(NES_DBG_CM, "Active Nodes  : %u \n", atomic_read(&core->node_cnt));
@@ -423,6 +506,147 @@ static void print_core(struct nes_cm_core *core)
        nes_debug(NES_DBG_CM, "-------------- end core ---------------\n");
 }
 
+/**
+ * cm_build_mpa_frame - build a MPA V1 frame or MPA V2 frame
+ */
+static int cm_build_mpa_frame(struct nes_cm_node *cm_node, u8 **start_buff,
+                             u16 *buff_len, u8 *pci_mem, u8 mpa_key)
+{
+       int ret = 0;
+
+       *start_buff = (pci_mem) ? pci_mem : &cm_node->mpa_frame_buf[0];
+
+       switch (cm_node->mpa_frame_rev) {
+       case IETF_MPA_V1:
+               *start_buff = (u8 *)*start_buff + sizeof(struct ietf_rtr_msg);
+               *buff_len = sizeof(struct ietf_mpa_v1) + cm_node->mpa_frame_size;
+               build_mpa_v1(cm_node, *start_buff, mpa_key);
+               break;
+       case IETF_MPA_V2:
+               *buff_len = sizeof(struct ietf_mpa_v2) + cm_node->mpa_frame_size;
+               build_mpa_v2(cm_node, *start_buff, mpa_key);
+               break;
+       default:
+               ret = -EINVAL;
+       }
+       return ret;
+}
+
+/**
+ * build_mpa_v2 - build a MPA V2 frame
+ */
+static void build_mpa_v2(struct nes_cm_node *cm_node,
+                        void *start_addr, u8 mpa_key)
+{
+       struct ietf_mpa_v2 *mpa_frame = (struct ietf_mpa_v2 *)start_addr;
+       struct ietf_rtr_msg *rtr_msg = &mpa_frame->rtr_msg;
+
+       /* initialize the upper 5 bytes of the frame */
+       build_mpa_v1(cm_node, start_addr, mpa_key);
+       mpa_frame->flags |= IETF_MPA_V2_FLAG; /* set a bit to indicate MPA V2 */
+       mpa_frame->priv_data_len += htons(IETF_RTR_MSG_SIZE);
+
+       /* initialize RTR msg */
+       rtr_msg->ctrl_ird = (cm_node->ird_size > IETF_NO_IRD_ORD) ?
+                           IETF_NO_IRD_ORD : cm_node->ird_size;
+       rtr_msg->ctrl_ord = (cm_node->ord_size > IETF_NO_IRD_ORD) ?
+                           IETF_NO_IRD_ORD : cm_node->ord_size;
+
+       rtr_msg->ctrl_ird |= IETF_PEER_TO_PEER;
+       rtr_msg->ctrl_ird |= IETF_FLPDU_ZERO_LEN;
+
+       switch (mpa_key) {
+       case MPA_KEY_REQUEST:
+               rtr_msg->ctrl_ord |= IETF_RDMA0_WRITE;
+               rtr_msg->ctrl_ord |= IETF_RDMA0_READ;
+               break;
+       case MPA_KEY_REPLY:
+               switch (cm_node->send_rdma0_op) {
+               case SEND_RDMA_WRITE_ZERO:
+                       rtr_msg->ctrl_ord |= IETF_RDMA0_WRITE;
+                       break;
+               case SEND_RDMA_READ_ZERO:
+                       rtr_msg->ctrl_ord |= IETF_RDMA0_READ;
+                       break;
+               }
+       }
+       rtr_msg->ctrl_ird = htons(rtr_msg->ctrl_ird);
+       rtr_msg->ctrl_ord = htons(rtr_msg->ctrl_ord);
+}
+
+/**
+ * build_mpa_v1 - build a MPA V1 frame
+ */
+static void build_mpa_v1(struct nes_cm_node *cm_node, void *start_addr, u8 mpa_key)
+{
+       struct ietf_mpa_v1 *mpa_frame = (struct ietf_mpa_v1 *)start_addr;
+
+       switch (mpa_key) {
+       case MPA_KEY_REQUEST:
+               memcpy(mpa_frame->key, IEFT_MPA_KEY_REQ, IETF_MPA_KEY_SIZE);
+               break;
+       case MPA_KEY_REPLY:
+               memcpy(mpa_frame->key, IEFT_MPA_KEY_REP, IETF_MPA_KEY_SIZE);
+               break;
+       }
+       mpa_frame->flags = IETF_MPA_FLAGS_CRC;
+       mpa_frame->rev = cm_node->mpa_frame_rev;
+       mpa_frame->priv_data_len = htons(cm_node->mpa_frame_size);
+}
+
+static void build_rdma0_msg(struct nes_cm_node *cm_node, struct nes_qp **nesqp_addr)
+{
+       u64 u64temp;
+       struct nes_qp *nesqp = *nesqp_addr;
+       struct nes_hw_qp_wqe *wqe = &nesqp->hwqp.sq_vbase[0];
+
+       u64temp = (unsigned long)nesqp;
+       u64temp |= NES_SW_CONTEXT_ALIGN >> 1;
+       set_wqe_64bit_value(wqe->wqe_words, NES_IWARP_SQ_WQE_COMP_CTX_LOW_IDX, u64temp);
+
+       wqe->wqe_words[NES_IWARP_SQ_WQE_FRAG0_LOW_IDX] = 0;
+       wqe->wqe_words[NES_IWARP_SQ_WQE_FRAG0_HIGH_IDX] = 0;
+
+       switch (cm_node->send_rdma0_op) {
+       case SEND_RDMA_WRITE_ZERO:
+               nes_debug(NES_DBG_CM, "Sending first write.\n");
+               wqe->wqe_words[NES_IWARP_SQ_WQE_MISC_IDX] =
+                       cpu_to_le32(NES_IWARP_SQ_OP_RDMAW);
+               wqe->wqe_words[NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX] = 0;
+               wqe->wqe_words[NES_IWARP_SQ_WQE_LENGTH0_IDX] = 0;
+               wqe->wqe_words[NES_IWARP_SQ_WQE_STAG0_IDX] = 0;
+               break;
+
+       case SEND_RDMA_READ_ZERO:
+       default:
+               if (cm_node->send_rdma0_op != SEND_RDMA_READ_ZERO) {
+                       printk(KERN_ERR "%s[%u]: Unsupported RDMA0 len operation=%u\n",
+                                __func__, __LINE__, cm_node->send_rdma0_op);
+                       WARN_ON(1);
+               }
+               nes_debug(NES_DBG_CM, "Sending first rdma operation.\n");
+               wqe->wqe_words[NES_IWARP_SQ_WQE_MISC_IDX] =
+                       cpu_to_le32(NES_IWARP_SQ_OP_RDMAR);
+               wqe->wqe_words[NES_IWARP_SQ_WQE_RDMA_TO_LOW_IDX] = 1;
+               wqe->wqe_words[NES_IWARP_SQ_WQE_RDMA_TO_HIGH_IDX] = 0;
+               wqe->wqe_words[NES_IWARP_SQ_WQE_RDMA_LENGTH_IDX] = 0;
+               wqe->wqe_words[NES_IWARP_SQ_WQE_RDMA_STAG_IDX] = 1;
+               wqe->wqe_words[NES_IWARP_SQ_WQE_STAG0_IDX] = 1;
+               break;
+       }
+
+       if (nesqp->sq_kmapped) {
+               nesqp->sq_kmapped = 0;
+               kunmap(nesqp->page);
+       }
+
+       /*use the reserved spot on the WQ for the extra first WQE*/
+       nesqp->nesqp_context->ird_ord_sizes &= cpu_to_le32(~(NES_QPCONTEXT_ORDIRD_LSMM_PRESENT |
+                                                            NES_QPCONTEXT_ORDIRD_WRPDU |
+                                                            NES_QPCONTEXT_ORDIRD_ALSMM));
+       nesqp->skip_lsmm = 1;
+       nesqp->hwqp.sq_tail = 0;
+}
 
 /**
  * schedule_nes_timer
@@ -430,10 +654,10 @@ static void print_core(struct nes_cm_core *core)
  *                     rem_ref_cm_node(cm_core, cm_node);add_ref_cm_node(cm_node);
  */
 int schedule_nes_timer(struct nes_cm_node *cm_node, struct sk_buff *skb,
-               enum nes_timer_type type, int send_retrans,
-               int close_when_complete)
+                      enum nes_timer_type type, int send_retrans,
+                      int close_when_complete)
 {
-       unsigned long  flags;
+       unsigned long flags;
        struct nes_cm_core *cm_core = cm_node->cm_core;
        struct nes_timer_entry *new_send;
        int ret = 0;
@@ -454,7 +678,7 @@ int schedule_nes_timer(struct nes_cm_node *cm_node, struct sk_buff *skb,
        new_send->close_when_complete = close_when_complete;
 
        if (type == NES_TIMER_TYPE_CLOSE) {
-               new_send->timetosend += (HZ/10);
+               new_send->timetosend += (HZ / 10);
                if (cm_node->recv_entry) {
                        kfree(new_send);
                        WARN_ON(1);
@@ -475,7 +699,7 @@ int schedule_nes_timer(struct nes_cm_node *cm_node, struct sk_buff *skb,
                ret = nes_nic_cm_xmit(new_send->skb, cm_node->netdev);
                if (ret != NETDEV_TX_OK) {
                        nes_debug(NES_DBG_CM, "Error sending packet %p "
-                               "(jiffies = %lu)\n", new_send, jiffies);
+                                 "(jiffies = %lu)\n", new_send, jiffies);
                        new_send->timetosend = jiffies;
                        ret = NETDEV_TX_OK;
                } else {
@@ -504,6 +728,7 @@ static void nes_retrans_expired(struct nes_cm_node *cm_node)
        struct iw_cm_id *cm_id = cm_node->cm_id;
        enum nes_cm_node_state state = cm_node->state;
        cm_node->state = NES_CM_STATE_CLOSED;
+
        switch (state) {
        case NES_CM_STATE_SYN_RCVD:
        case NES_CM_STATE_CLOSING:
@@ -536,10 +761,10 @@ static void handle_recv_entry(struct nes_cm_node *cm_node, u32 rem_node)
                spin_lock_irqsave(&nesqp->lock, qplockflags);
                if (nesqp->cm_id) {
                        nes_debug(NES_DBG_CM, "QP%u: cm_id = %p, "
-                               "refcount = %d: HIT A "
-                               "NES_TIMER_TYPE_CLOSE with something "
-                               "to do!!!\n", nesqp->hwqp.qp_id, cm_id,
-                               atomic_read(&nesqp->refcount));
+                                 "refcount = %d: HIT A "
+                                 "NES_TIMER_TYPE_CLOSE with something "
+                                 "to do!!!\n", nesqp->hwqp.qp_id, cm_id,
+                                 atomic_read(&nesqp->refcount));
                        nesqp->hw_tcp_state = NES_AEQE_TCP_STATE_CLOSED;
                        nesqp->last_aeq = NES_AEQE_AEID_RESET_SENT;
                        nesqp->ibqp_state = IB_QPS_ERR;
@@ -548,10 +773,10 @@ static void handle_recv_entry(struct nes_cm_node *cm_node, u32 rem_node)
                } else {
                        spin_unlock_irqrestore(&nesqp->lock, qplockflags);
                        nes_debug(NES_DBG_CM, "QP%u: cm_id = %p, "
-                               "refcount = %d: HIT A "
-                               "NES_TIMER_TYPE_CLOSE with nothing "
-                               "to do!!!\n", nesqp->hwqp.qp_id, cm_id,
-                               atomic_read(&nesqp->refcount));
+                                 "refcount = %d: HIT A "
+                                 "NES_TIMER_TYPE_CLOSE with nothing "
+                                 "to do!!!\n", nesqp->hwqp.qp_id, cm_id,
+                                 atomic_read(&nesqp->refcount));
                }
        } else if (rem_node) {
                /* TIME_WAIT state */
@@ -580,11 +805,12 @@ static void nes_cm_timer_tick(unsigned long pass)
        int ret = NETDEV_TX_OK;
 
        struct list_head timer_list;
+
        INIT_LIST_HEAD(&timer_list);
        spin_lock_irqsave(&cm_core->ht_lock, flags);
 
        list_for_each_safe(list_node, list_core_temp,
-                               &cm_core->connected_nodes) {
+                          &cm_core->connected_nodes) {
                cm_node = container_of(list_node, struct nes_cm_node, list);
                if ((cm_node->recv_entry) || (cm_node->send_entry)) {
                        add_ref_cm_node(cm_node);
@@ -595,18 +821,19 @@ static void nes_cm_timer_tick(unsigned long pass)
 
        list_for_each_safe(list_node, list_core_temp, &timer_list) {
                cm_node = container_of(list_node, struct nes_cm_node,
-                                       timer_entry);
+                                      timer_entry);
                recv_entry = cm_node->recv_entry;
 
                if (recv_entry) {
                        if (time_after(recv_entry->timetosend, jiffies)) {
                                if (nexttimeout > recv_entry->timetosend ||
-                                               !settimer) {
+                                   !settimer) {
                                        nexttimeout = recv_entry->timetosend;
                                        settimer = 1;
                                }
-                       } else
+                       } else {
                                handle_recv_entry(cm_node, 1);
+                       }
                }
 
                spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
@@ -617,8 +844,8 @@ static void nes_cm_timer_tick(unsigned long pass)
                        if (time_after(send_entry->timetosend, jiffies)) {
                                if (cm_node->state != NES_CM_STATE_TSA) {
                                        if ((nexttimeout >
-                                               send_entry->timetosend) ||
-                                               !settimer) {
+                                            send_entry->timetosend) ||
+                                           !settimer) {
                                                nexttimeout =
                                                        send_entry->timetosend;
                                                settimer = 1;
@@ -630,13 +857,13 @@ static void nes_cm_timer_tick(unsigned long pass)
                        }
 
                        if ((cm_node->state == NES_CM_STATE_TSA) ||
-                               (cm_node->state == NES_CM_STATE_CLOSED)) {
+                           (cm_node->state == NES_CM_STATE_CLOSED)) {
                                free_retrans_entry(cm_node);
                                break;
                        }
 
                        if (!send_entry->retranscount ||
-                               !send_entry->retrycount) {
+                           !send_entry->retrycount) {
                                cm_packets_dropped++;
                                free_retrans_entry(cm_node);
 
@@ -645,28 +872,28 @@ static void nes_cm_timer_tick(unsigned long pass)
                                nes_retrans_expired(cm_node);
                                cm_node->state = NES_CM_STATE_CLOSED;
                                spin_lock_irqsave(&cm_node->retrans_list_lock,
-                                       flags);
+                                                 flags);
                                break;
                        }
                        atomic_inc(&send_entry->skb->users);
                        cm_packets_retrans++;
                        nes_debug(NES_DBG_CM, "Retransmitting send_entry %p "
-                               "for node %p, jiffies = %lu, time to send = "
-                               "%lu, retranscount = %u, send_entry->seq_num = "
-                               "0x%08X, cm_node->tcp_cntxt.rem_ack_num = "
-                               "0x%08X\n", send_entry, cm_node, jiffies,
-                               send_entry->timetosend,
-                               send_entry->retranscount,
-                               send_entry->seq_num,
-                               cm_node->tcp_cntxt.rem_ack_num);
+                                 "for node %p, jiffies = %lu, time to send = "
+                                 "%lu, retranscount = %u, send_entry->seq_num = "
+                                 "0x%08X, cm_node->tcp_cntxt.rem_ack_num = "
+                                 "0x%08X\n", send_entry, cm_node, jiffies,
+                                 send_entry->timetosend,
+                                 send_entry->retranscount,
+                                 send_entry->seq_num,
+                                 cm_node->tcp_cntxt.rem_ack_num);
 
                        spin_unlock_irqrestore(&cm_node->retrans_list_lock,
-                               flags);
+                                              flags);
                        ret = nes_nic_cm_xmit(send_entry->skb, cm_node->netdev);
                        spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
                        if (ret != NETDEV_TX_OK) {
                                nes_debug(NES_DBG_CM, "rexmit failed for "
-                                       "node=%p\n", cm_node);
+                                         "node=%p\n", cm_node);
                                cm_packets_bounced++;
                                send_entry->retrycount--;
                                nexttimeout = jiffies + NES_SHORT_TIME;
@@ -676,18 +903,18 @@ static void nes_cm_timer_tick(unsigned long pass)
                                cm_packets_sent++;
                        }
                        nes_debug(NES_DBG_CM, "Packet Sent: retrans count = "
-                               "%u, retry count = %u.\n",
-                               send_entry->retranscount,
-                               send_entry->retrycount);
+                                 "%u, retry count = %u.\n",
+                                 send_entry->retranscount,
+                                 send_entry->retrycount);
                        if (send_entry->send_retrans) {
                                send_entry->retranscount--;
                                timetosend = (NES_RETRY_TIMEOUT <<
-                                       (NES_DEFAULT_RETRANS - send_entry->retranscount));
+                                             (NES_DEFAULT_RETRANS - send_entry->retranscount));
 
                                send_entry->timetosend = jiffies +
-                                       min(timetosend, NES_MAX_TIMEOUT);
+                                                        min(timetosend, NES_MAX_TIMEOUT);
                                if (nexttimeout > send_entry->timetosend ||
-                                       !settimer) {
+                                   !settimer) {
                                        nexttimeout = send_entry->timetosend;
                                        settimer = 1;
                                }
@@ -696,11 +923,11 @@ static void nes_cm_timer_tick(unsigned long pass)
                                close_when_complete =
                                        send_entry->close_when_complete;
                                nes_debug(NES_DBG_CM, "cm_node=%p state=%d\n",
-                                       cm_node, cm_node->state);
+                                         cm_node, cm_node->state);
                                free_retrans_entry(cm_node);
                                if (close_when_complete)
                                        rem_ref_cm_node(cm_node->cm_core,
-                                               cm_node);
+                                                       cm_node);
                        }
                } while (0);
 
@@ -710,7 +937,7 @@ static void nes_cm_timer_tick(unsigned long pass)
 
        if (settimer) {
                if (!timer_pending(&cm_core->tcp_timer)) {
-                       cm_core->tcp_timer.expires  = nexttimeout;
+                       cm_core->tcp_timer.expires = nexttimeout;
                        add_timer(&cm_core->tcp_timer);
                }
        }
@@ -721,13 +948,13 @@ static void nes_cm_timer_tick(unsigned long pass)
  * send_syn
  */
 static int send_syn(struct nes_cm_node *cm_node, u32 sendack,
-       struct sk_buff *skb)
+                   struct sk_buff *skb)
 {
        int ret;
        int flags = SET_SYN;
        char optionsbuffer[sizeof(struct option_mss) +
-               sizeof(struct option_windowscale) + sizeof(struct option_base) +
-               TCP_OPTIONS_PADDING];
+                          sizeof(struct option_windowscale) + sizeof(struct option_base) +
+                          TCP_OPTIONS_PADDING];
 
        int optionssize = 0;
        /* Sending MSS option */
@@ -854,7 +1081,7 @@ static int send_fin(struct nes_cm_node *cm_node, struct sk_buff *skb)
  * find_node - find a cm node that matches the reference cm node
  */
 static struct nes_cm_node *find_node(struct nes_cm_core *cm_core,
-               u16 rem_port, nes_addr_t rem_addr, u16 loc_port, nes_addr_t loc_addr)
+                                    u16 rem_port, nes_addr_t rem_addr, u16 loc_port, nes_addr_t loc_addr)
 {
        unsigned long flags;
        struct list_head *hte;
@@ -868,12 +1095,12 @@ static struct nes_cm_node *find_node(struct nes_cm_core *cm_core,
        list_for_each_entry(cm_node, hte, list) {
                /* compare quad, return node handle if a match */
                nes_debug(NES_DBG_CM, "finding node %x:%x =? %x:%x ^ %x:%x =? %x:%x\n",
-                               cm_node->loc_addr, cm_node->loc_port,
-                               loc_addr, loc_port,
-                               cm_node->rem_addr, cm_node->rem_port,
-                               rem_addr, rem_port);
+                         cm_node->loc_addr, cm_node->loc_port,
+                         loc_addr, loc_port,
+                         cm_node->rem_addr, cm_node->rem_port,
+                         rem_addr, rem_port);
                if ((cm_node->loc_addr == loc_addr) && (cm_node->loc_port == loc_port) &&
-                               (cm_node->rem_addr == rem_addr) && (cm_node->rem_port == rem_port)) {
+                   (cm_node->rem_addr == rem_addr) && (cm_node->rem_port == rem_port)) {
                        add_ref_cm_node(cm_node);
                        spin_unlock_irqrestore(&cm_core->ht_lock, flags);
                        return cm_node;
@@ -890,7 +1117,7 @@ static struct nes_cm_node *find_node(struct nes_cm_core *cm_core,
  * find_listener - find a cm node listening on this addr-port pair
  */
 static struct nes_cm_listener *find_listener(struct nes_cm_core *cm_core,
-               nes_addr_t dst_addr, u16 dst_port, enum nes_cm_listener_state listener_state)
+                                            nes_addr_t dst_addr, u16 dst_port, enum nes_cm_listener_state listener_state)
 {
        unsigned long flags;
        struct nes_cm_listener *listen_node;
@@ -900,9 +1127,9 @@ static struct nes_cm_listener *find_listener(struct nes_cm_core *cm_core,
        list_for_each_entry(listen_node, &cm_core->listen_list.list, list) {
                /* compare node pair, return node handle if a match */
                if (((listen_node->loc_addr == dst_addr) ||
-                               listen_node->loc_addr == 0x00000000) &&
-                               (listen_node->loc_port == dst_port) &&
-                               (listener_state & listen_node->listener_state)) {
+                    listen_node->loc_addr == 0x00000000) &&
+                   (listen_node->loc_port == dst_port) &&
+                   (listener_state & listen_node->listener_state)) {
                        atomic_inc(&listen_node->ref_count);
                        spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
                        return listen_node;
@@ -927,7 +1154,7 @@ static int add_hte_node(struct nes_cm_core *cm_core, struct nes_cm_node *cm_node
                return -EINVAL;
 
        nes_debug(NES_DBG_CM, "Adding Node %p to Active Connection HT\n",
-               cm_node);
+                 cm_node);
 
        spin_lock_irqsave(&cm_core->ht_lock, flags);
 
@@ -946,7 +1173,7 @@ static int add_hte_node(struct nes_cm_core *cm_core, struct nes_cm_node *cm_node
  * mini_cm_dec_refcnt_listen
  */
 static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
-       struct nes_cm_listener *listener, int free_hanging_nodes)
+                                    struct nes_cm_listener *listener, int free_hanging_nodes)
 {
        int ret = -EINVAL;
        int err = 0;
@@ -957,8 +1184,8 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
        struct list_head reset_list;
 
        nes_debug(NES_DBG_CM, "attempting listener= %p free_nodes= %d, "
-               "refcnt=%d\n", listener, free_hanging_nodes,
-               atomic_read(&listener->ref_count));
+                 "refcnt=%d\n", listener, free_hanging_nodes,
+                 atomic_read(&listener->ref_count));
        /* free non-accelerated child nodes for this listener */
        INIT_LIST_HEAD(&reset_list);
        if (free_hanging_nodes) {
@@ -966,7 +1193,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
                list_for_each_safe(list_pos, list_temp,
                                   &g_cm_core->connected_nodes) {
                        cm_node = container_of(list_pos, struct nes_cm_node,
-                               list);
+                                              list);
                        if ((cm_node->listener == listener) &&
                            (!cm_node->accelerated)) {
                                add_ref_cm_node(cm_node);
@@ -978,7 +1205,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
 
        list_for_each_safe(list_pos, list_temp, &reset_list) {
                cm_node = container_of(list_pos, struct nes_cm_node,
-                               reset_entry);
+                                      reset_entry);
                {
                        struct nes_cm_node *loopback = cm_node->loopbackpartner;
                        enum nes_cm_node_state old_state;
@@ -990,7 +1217,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
                                        err = send_reset(cm_node, NULL);
                                        if (err) {
                                                cm_node->state =
-                                                        NES_CM_STATE_CLOSED;
+                                                       NES_CM_STATE_CLOSED;
                                                WARN_ON(1);
                                        } else {
                                                old_state = cm_node->state;
@@ -1035,10 +1262,9 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
 
                spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
 
-               if (listener->nesvnic) {
+               if (listener->nesvnic)
                        nes_manage_apbvt(listener->nesvnic, listener->loc_port,
-                                       PCI_FUNC(listener->nesvnic->nesdev->pcidev->devfn), NES_MANAGE_APBVT_DEL);
-               }
+                                        PCI_FUNC(listener->nesvnic->nesdev->pcidev->devfn), NES_MANAGE_APBVT_DEL);
 
                nes_debug(NES_DBG_CM, "destroying listener (%p)\n", listener);
 
@@ -1052,8 +1278,8 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
        if (listener) {
                if (atomic_read(&listener->pend_accepts_cnt) > 0)
                        nes_debug(NES_DBG_CM, "destroying listener (%p)"
-                                       " with non-zero pending accepts=%u\n",
-                                       listener, atomic_read(&listener->pend_accepts_cnt));
+                                 " with non-zero pending accepts=%u\n",
+                                 listener, atomic_read(&listener->pend_accepts_cnt));
        }
 
        return ret;
@@ -1064,7 +1290,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
  * mini_cm_del_listen
  */
 static int mini_cm_del_listen(struct nes_cm_core *cm_core,
-               struct nes_cm_listener *listener)
+                             struct nes_cm_listener *listener)
 {
        listener->listener_state = NES_CM_LISTENER_PASSIVE_STATE;
        listener->cm_id = NULL; /* going to be destroyed pretty soon */
@@ -1076,9 +1302,10 @@ static int mini_cm_del_listen(struct nes_cm_core *cm_core,
  * mini_cm_accelerated
  */
 static inline int mini_cm_accelerated(struct nes_cm_core *cm_core,
-               struct nes_cm_node *cm_node)
+                                     struct nes_cm_node *cm_node)
 {
        u32 was_timer_set;
+
        cm_node->accelerated = 1;
 
        if (cm_node->accept_pend) {
@@ -1112,7 +1339,7 @@ static int nes_addr_resolve_neigh(struct nes_vnic *nesvnic, u32 dst_ip, int arpi
        rt = ip_route_output(&init_net, htonl(dst_ip), 0, 0, 0);
        if (IS_ERR(rt)) {
                printk(KERN_ERR "%s: ip_route_output_key failed for 0x%08X\n",
-                               __func__, dst_ip);
+                      __func__, dst_ip);
                return rc;
        }
 
@@ -1130,7 +1357,7 @@ static int nes_addr_resolve_neigh(struct nes_vnic *nesvnic, u32 dst_ip, int arpi
 
                        if (arpindex >= 0) {
                                if (!memcmp(nesadapter->arp_table[arpindex].mac_addr,
-                                                       neigh->ha, ETH_ALEN)){
+                                           neigh->ha, ETH_ALEN)) {
                                        /* Mac address same as in nes_arp_table */
                                        neigh_release(neigh);
                                        ip_rt_put(rt);
@@ -1138,8 +1365,8 @@ static int nes_addr_resolve_neigh(struct nes_vnic *nesvnic, u32 dst_ip, int arpi
                                }
 
                                nes_manage_arp_cache(nesvnic->netdev,
-                                               nesadapter->arp_table[arpindex].mac_addr,
-                                               dst_ip, NES_ARP_DELETE);
+                                                    nesadapter->arp_table[arpindex].mac_addr,
+                                                    dst_ip, NES_ARP_DELETE);
                        }
 
                        nes_manage_arp_cache(nesvnic->netdev, neigh->ha,
@@ -1161,8 +1388,8 @@ static int nes_addr_resolve_neigh(struct nes_vnic *nesvnic, u32 dst_ip, int arpi
  * make_cm_node - create a new instance of a cm node
  */
 static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
-               struct nes_vnic *nesvnic, struct nes_cm_info *cm_info,
-               struct nes_cm_listener *listener)
+                                       struct nes_vnic *nesvnic, struct nes_cm_info *cm_info,
+                                       struct nes_cm_listener *listener)
 {
        struct nes_cm_node *cm_node;
        struct timespec ts;
@@ -1181,7 +1408,12 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
        cm_node->rem_addr = cm_info->rem_addr;
        cm_node->loc_port = cm_info->loc_port;
        cm_node->rem_port = cm_info->rem_port;
-       cm_node->send_write0 = send_first;
+
+       cm_node->mpa_frame_rev = mpa_version;
+       cm_node->send_rdma0_op = SEND_RDMA_READ_ZERO;
+       cm_node->ird_size = IETF_NO_IRD_ORD;
+       cm_node->ord_size = IETF_NO_IRD_ORD;
+
        nes_debug(NES_DBG_CM, "Make node addresses : loc = %pI4:%x, rem = %pI4:%x\n",
                  &cm_node->loc_addr, cm_node->loc_port,
                  &cm_node->rem_addr, cm_node->rem_port);
@@ -1191,7 +1423,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
        memcpy(cm_node->loc_mac, nesvnic->netdev->dev_addr, ETH_ALEN);
 
        nes_debug(NES_DBG_CM, "listener=%p, cm_id=%p\n", cm_node->listener,
-                       cm_node->cm_id);
+                 cm_node->cm_id);
 
        spin_lock_init(&cm_node->retrans_list_lock);
 
@@ -1202,11 +1434,11 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
        cm_node->tcp_cntxt.loc_id = NES_CM_DEF_LOCAL_ID;
        cm_node->tcp_cntxt.rcv_wscale = NES_CM_DEFAULT_RCV_WND_SCALE;
        cm_node->tcp_cntxt.rcv_wnd = NES_CM_DEFAULT_RCV_WND_SCALED >>
-                       NES_CM_DEFAULT_RCV_WND_SCALE;
+                                    NES_CM_DEFAULT_RCV_WND_SCALE;
        ts = current_kernel_time();
        cm_node->tcp_cntxt.loc_seq_num = htonl(ts.tv_nsec);
        cm_node->tcp_cntxt.mss = nesvnic->max_frame_size - sizeof(struct iphdr) -
-                       sizeof(struct tcphdr) - ETH_HLEN - VLAN_HLEN;
+                                sizeof(struct tcphdr) - ETH_HLEN - VLAN_HLEN;
        cm_node->tcp_cntxt.rcv_nxt = 0;
        /* get a unique session ID , add thread_id to an upcounter to handle race */
        atomic_inc(&cm_core->node_cnt);
@@ -1222,12 +1454,11 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
        cm_node->loopbackpartner = NULL;
 
        /* get the mac addr for the remote node */
-       if (ipv4_is_loopback(htonl(cm_node->rem_addr)))
+       if (ipv4_is_loopback(htonl(cm_node->rem_addr))) {
                arpindex = nes_arp_table(nesdev, ntohl(nesvnic->local_ipaddr), NULL, NES_ARP_RESOLVE);
-       else {
+       else {
                oldarpindex = nes_arp_table(nesdev, cm_node->rem_addr, NULL, NES_ARP_RESOLVE);
                arpindex = nes_addr_resolve_neigh(nesvnic, cm_info->rem_addr, oldarpindex);
-
        }
        if (arpindex < 0) {
                kfree(cm_node);
@@ -1260,7 +1491,7 @@ static int add_ref_cm_node(struct nes_cm_node *cm_node)
  * rem_ref_cm_node - destroy an instance of a cm node
  */
 static int rem_ref_cm_node(struct nes_cm_core *cm_core,
-       struct nes_cm_node *cm_node)
+                          struct nes_cm_node *cm_node)
 {
        unsigned long flags;
        struct nes_qp *nesqp;
@@ -1291,9 +1522,9 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
        } else {
                if (cm_node->apbvt_set && cm_node->nesvnic) {
                        nes_manage_apbvt(cm_node->nesvnic, cm_node->loc_port,
-                               PCI_FUNC(
-                               cm_node->nesvnic->nesdev->pcidev->devfn),
-                               NES_MANAGE_APBVT_DEL);
+                                        PCI_FUNC(
+                                                cm_node->nesvnic->nesdev->pcidev->devfn),
+                                        NES_MANAGE_APBVT_DEL);
                }
        }
 
@@ -1314,7 +1545,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
  * process_options
  */
 static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
-       u32 optionsize, u32 syn_packet)
+                          u32 optionsize, u32 syn_packet)
 {
        u32 tmp;
        u32 offset = 0;
@@ -1332,15 +1563,15 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
                        continue;
                case OPTION_NUMBER_MSS:
                        nes_debug(NES_DBG_CM, "%s: MSS Length: %d Offset: %d "
-                               "Size: %d\n", __func__,
-                               all_options->as_mss.length, offset, optionsize);
+                                 "Size: %d\n", __func__,
+                                 all_options->as_mss.length, offset, optionsize);
                        got_mss_option = 1;
                        if (all_options->as_mss.length != 4) {
                                return 1;
                        } else {
                                tmp = ntohs(all_options->as_mss.mss);
                                if (tmp > 0 && tmp <
-                                       cm_node->tcp_cntxt.mss)
+                                   cm_node->tcp_cntxt.mss)
                                        cm_node->tcp_cntxt.mss = tmp;
                        }
                        break;
@@ -1348,12 +1579,9 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
                        cm_node->tcp_cntxt.snd_wscale =
                                all_options->as_windowscale.shiftcount;
                        break;
-               case OPTION_NUMBER_WRITE0:
-                       cm_node->send_write0 = 1;
-                       break;
                default:
                        nes_debug(NES_DBG_CM, "TCP Option not understood: %x\n",
-                               all_options->as_base.optionnum);
+                                 all_options->as_base.optionnum);
                        break;
                }
                offset += all_options->as_base.length;
@@ -1372,8 +1600,8 @@ static void drop_packet(struct sk_buff *skb)
 static void handle_fin_pkt(struct nes_cm_node *cm_node)
 {
        nes_debug(NES_DBG_CM, "Received FIN, cm_node = %p, state = %u. "
-               "refcnt=%d\n", cm_node, cm_node->state,
-               atomic_read(&cm_node->ref_count));
+                 "refcnt=%d\n", cm_node, cm_node->state,
+                 atomic_read(&cm_node->ref_count));
        switch (cm_node->state) {
        case NES_CM_STATE_SYN_RCVD:
        case NES_CM_STATE_SYN_SENT:
@@ -1439,7 +1667,20 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
                nes_debug(NES_DBG_CM, "%s[%u] create abort for cm_node=%p "
                        "listener=%p state=%d\n", __func__, __LINE__, cm_node,
                        cm_node->listener, cm_node->state);
-               active_open_err(cm_node, skb, reset);
+               switch (cm_node->mpa_frame_rev) {
+               case IETF_MPA_V2:
+                       cm_node->mpa_frame_rev = IETF_MPA_V1;
+                       /* send a syn and goto syn sent state */
+                       cm_node->state = NES_CM_STATE_SYN_SENT;
+                       if (send_syn(cm_node, 0, NULL)) {
+                               active_open_err(cm_node, skb, reset);
+                       }
+                       break;
+               case IETF_MPA_V1:
+               default:
+                       active_open_err(cm_node, skb, reset);
+                       break;
+               }
                break;
        case NES_CM_STATE_MPAREQ_RCVD:
                atomic_inc(&cm_node->passive_state);
@@ -1475,21 +1716,21 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
 
 static void handle_rcv_mpa(struct nes_cm_node *cm_node, struct sk_buff *skb)
 {
-
-       int     ret = 0;
+       int ret = 0;
        int datasize = skb->len;
        u8 *dataloc = skb->data;
 
        enum nes_cm_event_type type = NES_CM_EVENT_UNKNOWN;
-       u32     res_type;
+       u32 res_type;
+
        ret = parse_mpa(cm_node, dataloc, &res_type, datasize);
        if (ret) {
                nes_debug(NES_DBG_CM, "didn't like MPA Request\n");
                if (cm_node->state == NES_CM_STATE_MPAREQ_SENT) {
                        nes_debug(NES_DBG_CM, "%s[%u] create abort for "
-                               "cm_node=%p listener=%p state=%d\n", __func__,
-                               __LINE__, cm_node, cm_node->listener,
-                               cm_node->state);
+                                 "cm_node=%p listener=%p state=%d\n", __func__,
+                                 __LINE__, cm_node, cm_node->listener,
+                                 cm_node->state);
                        active_open_err(cm_node, skb, 1);
                } else {
                        passive_open_err(cm_node, skb, 1);
@@ -1499,16 +1740,15 @@ static void handle_rcv_mpa(struct nes_cm_node *cm_node, struct sk_buff *skb)
 
        switch (cm_node->state) {
        case NES_CM_STATE_ESTABLISHED:
-               if (res_type == NES_MPA_REQUEST_REJECT) {
+               if (res_type == NES_MPA_REQUEST_REJECT)
                        /*BIG problem as we are receiving the MPA.. So should
-                       * not be REJECT.. This is Passive Open.. We can
-                       * only receive it Reject for Active Open...*/
+                        * not be REJECT.. This is Passive Open.. We can
+                        * only receive it Reject for Active Open...*/
                        WARN_ON(1);
-               }
                cm_node->state = NES_CM_STATE_MPAREQ_RCVD;
                type = NES_CM_EVENT_MPA_REQ;
                atomic_set(&cm_node->passive_state,
-                               NES_PASSIVE_STATE_INDICATED);
+                          NES_PASSIVE_STATE_INDICATED);
                break;
        case NES_CM_STATE_MPAREQ_SENT:
                cleanup_retrans_entry(cm_node);
@@ -1535,8 +1775,8 @@ static void indicate_pkt_err(struct nes_cm_node *cm_node, struct sk_buff *skb)
        case NES_CM_STATE_SYN_SENT:
        case NES_CM_STATE_MPAREQ_SENT:
                nes_debug(NES_DBG_CM, "%s[%u] create abort for cm_node=%p "
-                       "listener=%p state=%d\n", __func__, __LINE__, cm_node,
-                       cm_node->listener, cm_node->state);
+                         "listener=%p state=%d\n", __func__, __LINE__, cm_node,
+                         cm_node->listener, cm_node->state);
                active_open_err(cm_node, skb, 1);
                break;
        case NES_CM_STATE_ESTABLISHED:
@@ -1550,11 +1790,11 @@ static void indicate_pkt_err(struct nes_cm_node *cm_node, struct sk_buff *skb)
 }
 
 static int check_syn(struct nes_cm_node *cm_node, struct tcphdr *tcph,
-       struct sk_buff *skb)
+                    struct sk_buff *skb)
 {
        int err;
 
-       err = ((ntohl(tcph->ack_seq) == cm_node->tcp_cntxt.loc_seq_num))? 0 : 1;
+       err = ((ntohl(tcph->ack_seq) == cm_node->tcp_cntxt.loc_seq_num)) ? 0 : 1;
        if (err)
                active_open_err(cm_node, skb, 1);
 
@@ -1562,7 +1802,7 @@ static int check_syn(struct nes_cm_node *cm_node, struct tcphdr *tcph,
 }
 
 static int check_seq(struct nes_cm_node *cm_node, struct tcphdr *tcph,
-       struct sk_buff *skb)
+                    struct sk_buff *skb)
 {
        int err = 0;
        u32 seq;
@@ -1570,21 +1810,22 @@ static int check_seq(struct nes_cm_node *cm_node, struct tcphdr *tcph,
        u32 loc_seq_num = cm_node->tcp_cntxt.loc_seq_num;
        u32 rcv_nxt = cm_node->tcp_cntxt.rcv_nxt;
        u32 rcv_wnd;
+
        seq = ntohl(tcph->seq);
        ack_seq = ntohl(tcph->ack_seq);
        rcv_wnd = cm_node->tcp_cntxt.rcv_wnd;
        if (ack_seq != loc_seq_num)
                err = 1;
-       else if (!between(seq, rcv_nxt, (rcv_nxt+rcv_wnd)))
+       else if (!between(seq, rcv_nxt, (rcv_nxt + rcv_wnd)))
                err = 1;
        if (err) {
                nes_debug(NES_DBG_CM, "%s[%u] create abort for cm_node=%p "
-                       "listener=%p state=%d\n", __func__, __LINE__, cm_node,
-                       cm_node->listener, cm_node->state);
+                         "listener=%p state=%d\n", __func__, __LINE__, cm_node,
+                         cm_node->listener, cm_node->state);
                indicate_pkt_err(cm_node, skb);
                nes_debug(NES_DBG_CM, "seq ERROR cm_node =%p seq=0x%08X "
-                       "rcv_nxt=0x%08X rcv_wnd=0x%x\n", cm_node, seq, rcv_nxt,
-                       rcv_wnd);
+                         "rcv_nxt=0x%08X rcv_wnd=0x%x\n", cm_node, seq, rcv_nxt,
+                         rcv_wnd);
        }
        return err;
 }
@@ -1594,9 +1835,8 @@ static int check_seq(struct nes_cm_node *cm_node, struct tcphdr *tcph,
  * is created with a listener or it may comein as rexmitted packet which in
  * that case will be just dropped.
  */
-
 static void handle_syn_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
-       struct tcphdr *tcph)
+                          struct tcphdr *tcph)
 {
        int ret;
        u32 inc_sequence;
@@ -1615,15 +1855,15 @@ static void handle_syn_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
        case NES_CM_STATE_LISTENING:
                /* Passive OPEN */
                if (atomic_read(&cm_node->listener->pend_accepts_cnt) >
-                               cm_node->listener->backlog) {
+                   cm_node->listener->backlog) {
                        nes_debug(NES_DBG_CM, "drop syn due to backlog "
-                               "pressure \n");
+                                 "pressure \n");
                        cm_backlog_drops++;
                        passive_open_err(cm_node, skb, 0);
                        break;
                }
                ret = handle_tcp_options(cm_node, tcph, skb, optionsize,
-                       1);
+                                        1);
                if (ret) {
                        passive_open_err(cm_node, skb, 0);
                        /* drop pkt */
@@ -1657,9 +1897,8 @@ static void handle_syn_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
 }
 
 static void handle_synack_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
-       struct tcphdr *tcph)
+                             struct tcphdr *tcph)
 {
-
        int ret;
        u32 inc_sequence;
        int optionsize;
@@ -1678,7 +1917,7 @@ static void handle_synack_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
                ret = handle_tcp_options(cm_node, tcph, skb, optionsize, 0);
                if (ret) {
                        nes_debug(NES_DBG_CM, "cm_node=%p tcp_options failed\n",
-                               cm_node);
+                                 cm_node);
                        break;
                }
                cleanup_retrans_entry(cm_node);
@@ -1717,12 +1956,13 @@ static void handle_synack_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
 }
 
 static int handle_ack_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
-       struct tcphdr *tcph)
+                         struct tcphdr *tcph)
 {
        int datasize = 0;
        u32 inc_sequence;
        int ret = 0;
        int optionsize;
+
        optionsize = (tcph->doff << 2) - sizeof(struct tcphdr);
 
        if (check_seq(cm_node, tcph, skb))
@@ -1743,8 +1983,9 @@ static int handle_ack_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
                if (datasize) {
                        cm_node->tcp_cntxt.rcv_nxt = inc_sequence + datasize;
                        handle_rcv_mpa(cm_node, skb);
-               } else  /* rcvd ACK only */
+               } else { /* rcvd ACK only */
                        dev_kfree_skb_any(skb);
+               }
                break;
        case NES_CM_STATE_ESTABLISHED:
                /* Passive OPEN */
@@ -1752,16 +1993,18 @@ static int handle_ack_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
                if (datasize) {
                        cm_node->tcp_cntxt.rcv_nxt = inc_sequence + datasize;
                        handle_rcv_mpa(cm_node, skb);
-               } else
+               } else {
                        drop_packet(skb);
+               }
                break;
        case NES_CM_STATE_MPAREQ_SENT:
                cm_node->tcp_cntxt.rem_ack_num = ntohl(tcph->ack_seq);
                if (datasize) {
                        cm_node->tcp_cntxt.rcv_nxt = inc_sequence + datasize;
                        handle_rcv_mpa(cm_node, skb);
-               } else  /* Could be just an ack pkt.. */
+               } else { /* Could be just an ack pkt.. */
                        dev_kfree_skb_any(skb);
+               }
                break;
        case NES_CM_STATE_LISTENING:
                cleanup_retrans_entry(cm_node);
@@ -1802,14 +2045,15 @@ static int handle_ack_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
 
 
 static int handle_tcp_options(struct nes_cm_node *cm_node, struct tcphdr *tcph,
-       struct sk_buff *skb, int optionsize, int passive)
+                             struct sk_buff *skb, int optionsize, int passive)
 {
        u8 *optionsloc = (u8 *)&tcph[1];
+
        if (optionsize) {
                if (process_options(cm_node, optionsloc, optionsize,
-                       (u32)tcph->syn)) {
+                                   (u32)tcph->syn)) {
                        nes_debug(NES_DBG_CM, "%s: Node %p, Sending RESET\n",
-                               __func__, cm_node);
+                                 __func__, cm_node);
                        if (passive)
                                passive_open_err(cm_node, skb, 1);
                        else
@@ -1819,7 +2063,7 @@ static int handle_tcp_options(struct nes_cm_node *cm_node, struct tcphdr *tcph,
        }
 
        cm_node->tcp_cntxt.snd_wnd = ntohs(tcph->window) <<
-                       cm_node->tcp_cntxt.snd_wscale;
+                                    cm_node->tcp_cntxt.snd_wscale;
 
        if (cm_node->tcp_cntxt.snd_wnd > cm_node->tcp_cntxt.max_snd_wnd)
                cm_node->tcp_cntxt.max_snd_wnd = cm_node->tcp_cntxt.snd_wnd;
@@ -1830,18 +2074,18 @@ static int handle_tcp_options(struct nes_cm_node *cm_node, struct tcphdr *tcph,
  * active_open_err() will send reset() if flag set..
  * It will also send ABORT event.
  */
-
 static void active_open_err(struct nes_cm_node *cm_node, struct sk_buff *skb,
-       int reset)
+                           int reset)
 {
        cleanup_retrans_entry(cm_node);
        if (reset) {
                nes_debug(NES_DBG_CM, "ERROR active err called for cm_node=%p, "
-                               "state=%d\n", cm_node, cm_node->state);
+                         "state=%d\n", cm_node, cm_node->state);
                add_ref_cm_node(cm_node);
                send_reset(cm_node, skb);
-       } else
+       } else {
                dev_kfree_skb_any(skb);
+       }
 
        cm_node->state = NES_CM_STATE_CLOSED;
        create_event(cm_node, NES_CM_EVENT_ABORTED);
@@ -1851,15 +2095,14 @@ static void active_open_err(struct nes_cm_node *cm_node, struct sk_buff *skb,
  * passive_open_err() will either do a reset() or will free up the skb and
  * remove the cm_node.
  */
-
 static void passive_open_err(struct nes_cm_node *cm_node, struct sk_buff *skb,
-       int reset)
+                            int reset)
 {
        cleanup_retrans_entry(cm_node);
        cm_node->state = NES_CM_STATE_CLOSED;
        if (reset) {
                nes_debug(NES_DBG_CM, "passive_open_err sending RST for "
-                       "cm_node=%p state =%d\n", cm_node, cm_node->state);
+                         "cm_node=%p state =%d\n", cm_node, cm_node->state);
                send_reset(cm_node, skb);
        } else {
                dev_kfree_skb_any(skb);
@@ -1874,6 +2117,7 @@ static void passive_open_err(struct nes_cm_node *cm_node, struct sk_buff *skb,
 static void free_retrans_entry(struct nes_cm_node *cm_node)
 {
        struct nes_timer_entry *send_entry;
+
        send_entry = cm_node->send_entry;
        if (send_entry) {
                cm_node->send_entry = NULL;
@@ -1897,26 +2141,28 @@ static void cleanup_retrans_entry(struct nes_cm_node *cm_node)
  * Returns skb if to be freed, else it will return NULL if already used..
  */
 static void process_packet(struct nes_cm_node *cm_node, struct sk_buff *skb,
-       struct nes_cm_core *cm_core)
+                          struct nes_cm_core *cm_core)
 {
-       enum nes_tcpip_pkt_type pkt_type = NES_PKT_TYPE_UNKNOWN;
+       enum nes_tcpip_pkt_type pkt_type = NES_PKT_TYPE_UNKNOWN;
        struct tcphdr *tcph = tcp_hdr(skb);
-       u32     fin_set = 0;
+       u32 fin_set = 0;
        int ret = 0;
+
        skb_pull(skb, ip_hdr(skb)->ihl << 2);
 
        nes_debug(NES_DBG_CM, "process_packet: cm_node=%p state =%d syn=%d "
-               "ack=%d rst=%d fin=%d\n", cm_node, cm_node->state, tcph->syn,
-               tcph->ack, tcph->rst, tcph->fin);
+                 "ack=%d rst=%d fin=%d\n", cm_node, cm_node->state, tcph->syn,
+                 tcph->ack, tcph->rst, tcph->fin);
 
-       if (tcph->rst)
+       if (tcph->rst) {
                pkt_type = NES_PKT_TYPE_RST;
-       else if (tcph->syn) {
+       else if (tcph->syn) {
                pkt_type = NES_PKT_TYPE_SYN;
                if (tcph->ack)
                        pkt_type = NES_PKT_TYPE_SYNACK;
-       } else if (tcph->ack)
+       } else if (tcph->ack) {
                pkt_type = NES_PKT_TYPE_ACK;
+       }
        if (tcph->fin)
                fin_set = 1;
 
@@ -1947,17 +2193,17 @@ static void process_packet(struct nes_cm_node *cm_node, struct sk_buff *skb,
  * mini_cm_listen - create a listen node with params
  */
 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *cm_core,
-       struct nes_vnic *nesvnic, struct nes_cm_info *cm_info)
+                                             struct nes_vnic *nesvnic, struct nes_cm_info *cm_info)
 {
        struct nes_cm_listener *listener;
        unsigned long flags;
 
        nes_debug(NES_DBG_CM, "Search for 0x%08x : 0x%04x\n",
-               cm_info->loc_addr, cm_info->loc_port);
+                 cm_info->loc_addr, cm_info->loc_port);
 
        /* cannot have multiple matching listeners */
        listener = find_listener(cm_core, htonl(cm_info->loc_addr),
-                       htons(cm_info->loc_port), NES_CM_LISTENER_EITHER_STATE);
+                                htons(cm_info->loc_port), NES_CM_LISTENER_EITHER_STATE);
        if (listener && listener->listener_state == NES_CM_LISTENER_ACTIVE_STATE) {
                /* find automatically incs ref count ??? */
                atomic_dec(&listener->ref_count);
@@ -2003,9 +2249,9 @@ static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *cm_core,
        }
 
        nes_debug(NES_DBG_CM, "Api - listen(): addr=0x%08X, port=0x%04x,"
-                       " listener = %p, backlog = %d, cm_id = %p.\n",
-                       cm_info->loc_addr, cm_info->loc_port,
-                       listener, listener->backlog, listener->cm_id);
+                 " listener = %p, backlog = %d, cm_id = %p.\n",
+                 cm_info->loc_addr, cm_info->loc_port,
+                 listener, listener->backlog, listener->cm_id);
 
        return listener;
 }
@@ -2015,26 +2261,20 @@ static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *cm_core,
  * mini_cm_connect - make a connection node with params
  */
 static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
-       struct nes_vnic *nesvnic, u16 private_data_len,
-       void *private_data, struct nes_cm_info *cm_info)
+                                          struct nes_vnic *nesvnic, u16 private_data_len,
+                                          void *private_data, struct nes_cm_info *cm_info)
 {
        int ret = 0;
        struct nes_cm_node *cm_node;
        struct nes_cm_listener *loopbackremotelistener;
        struct nes_cm_node *loopbackremotenode;
        struct nes_cm_info loopback_cm_info;
-       u16 mpa_frame_size = sizeof(struct ietf_mpa_frame) + private_data_len;
-       struct ietf_mpa_frame *mpa_frame = NULL;
+       u8 *start_buff;
 
        /* create a CM connection node */
        cm_node = make_cm_node(cm_core, nesvnic, cm_info, NULL);
        if (!cm_node)
                return NULL;
-       mpa_frame = &cm_node->mpa_frame;
-       memcpy(mpa_frame->key, IEFT_MPA_KEY_REQ, IETF_MPA_KEY_SIZE);
-       mpa_frame->flags = IETF_MPA_FLAGS_CRC;
-       mpa_frame->rev =  IETF_MPA_VERSION;
-       mpa_frame->priv_data_len = htons(private_data_len);
 
        /* set our node side to client (active) side */
        cm_node->tcp_cntxt.client = 1;
@@ -2042,8 +2282,8 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
 
        if (cm_info->loc_addr == cm_info->rem_addr) {
                loopbackremotelistener = find_listener(cm_core,
-                               ntohl(nesvnic->local_ipaddr), cm_node->rem_port,
-                               NES_CM_LISTENER_ACTIVE_STATE);
+                                                      ntohl(nesvnic->local_ipaddr), cm_node->rem_port,
+                                                      NES_CM_LISTENER_ACTIVE_STATE);
                if (loopbackremotelistener == NULL) {
                        create_event(cm_node, NES_CM_EVENT_ABORTED);
                } else {
@@ -2052,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
                        loopback_cm_info.rem_port = cm_info->loc_port;
                        loopback_cm_info.cm_id = loopbackremotelistener->cm_id;
                        loopbackremotenode = make_cm_node(cm_core, nesvnic,
-                               &loopback_cm_info, loopbackremotelistener);
+                                                         &loopback_cm_info, loopbackremotelistener);
                        if (!loopbackremotenode) {
                                rem_ref_cm_node(cm_node->cm_core, cm_node);
                                return NULL;
@@ -2063,7 +2303,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
                                NES_CM_DEFAULT_RCV_WND_SCALE;
                        cm_node->loopbackpartner = loopbackremotenode;
                        memcpy(loopbackremotenode->mpa_frame_buf, private_data,
-                               private_data_len);
+                              private_data_len);
                        loopbackremotenode->mpa_frame_size = private_data_len;
 
                        /* we are done handling this state. */
@@ -2091,12 +2331,10 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
                return cm_node;
        }
 
-       /* set our node side to client (active) side */
-       cm_node->tcp_cntxt.client = 1;
-       /* init our MPA frame ptr */
-       memcpy(mpa_frame->priv_data, private_data, private_data_len);
+       start_buff = &cm_node->mpa_frame_buf[0] + sizeof(struct ietf_mpa_v2);
+       cm_node->mpa_frame_size = private_data_len;
 
-       cm_node->mpa_frame_size = mpa_frame_size;
+       memcpy(start_buff, private_data, private_data_len);
 
        /* send a syn and goto syn sent state */
        cm_node->state = NES_CM_STATE_SYN_SENT;
@@ -2105,18 +2343,19 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
        if (ret) {
                /* error in sending the syn free up the cm_node struct */
                nes_debug(NES_DBG_CM, "Api - connect() FAILED: dest "
-                       "addr=0x%08X, port=0x%04x, cm_node=%p, cm_id = %p.\n",
-                       cm_node->rem_addr, cm_node->rem_port, cm_node,
-                       cm_node->cm_id);
+                         "addr=0x%08X, port=0x%04x, cm_node=%p, cm_id = %p.\n",
+                         cm_node->rem_addr, cm_node->rem_port, cm_node,
+                         cm_node->cm_id);
                rem_ref_cm_node(cm_node->cm_core, cm_node);
                cm_node = NULL;
        }
 
-       if (cm_node)
+       if (cm_node) {
                nes_debug(NES_DBG_CM, "Api - connect(): dest addr=0x%08X,"
-                       "port=0x%04x, cm_node=%p, cm_id = %p.\n",
-                       cm_node->rem_addr, cm_node->rem_port, cm_node,
-                       cm_node->cm_id);
+                         "port=0x%04x, cm_node=%p, cm_id = %p.\n",
+                         cm_node->rem_addr, cm_node->rem_port, cm_node,
+                         cm_node->cm_id);
+       }
 
        return cm_node;
 }
@@ -2126,8 +2365,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
  * mini_cm_accept - accept a connection
  * This function is never called
  */
-static int mini_cm_accept(struct nes_cm_core *cm_core,
-       struct ietf_mpa_frame *mpa_frame, struct nes_cm_node *cm_node)
+static int mini_cm_accept(struct nes_cm_core *cm_core, struct nes_cm_node *cm_node)
 {
        return 0;
 }
@@ -2136,8 +2374,7 @@ static int mini_cm_accept(struct nes_cm_core *cm_core,
 /**
  * mini_cm_reject - reject and teardown a connection
  */
-static int mini_cm_reject(struct nes_cm_core *cm_core,
-       struct ietf_mpa_frame *mpa_frame, struct nes_cm_node *cm_node)
+static int mini_cm_reject(struct nes_cm_core *cm_core, struct nes_cm_node *cm_node)
 {
        int ret = 0;
        int err = 0;
@@ -2147,7 +2384,7 @@ static int mini_cm_reject(struct nes_cm_core *cm_core,
        struct nes_cm_node *loopback = cm_node->loopbackpartner;
 
        nes_debug(NES_DBG_CM, "%s cm_node=%p type=%d state=%d\n",
-               __func__, cm_node, cm_node->tcp_cntxt.client, cm_node->state);
+                 __func__, cm_node, cm_node->tcp_cntxt.client, cm_node->state);
 
        if (cm_node->tcp_cntxt.client)
                return ret;
@@ -2168,8 +2405,9 @@ static int mini_cm_reject(struct nes_cm_core *cm_core,
                                        err = send_reset(cm_node, NULL);
                                        if (err)
                                                WARN_ON(1);
-                               } else
+                               } else {
                                        cm_id->add_ref(cm_id);
+                               }
                        }
                }
        } else {
@@ -2244,7 +2482,7 @@ static int mini_cm_close(struct nes_cm_core *cm_core, struct nes_cm_node *cm_nod
        case NES_CM_STATE_TSA:
                if (cm_node->send_entry)
                        printk(KERN_ERR "ERROR Close got called from STATE_TSA "
-                               "send_entry=%p\n", cm_node->send_entry);
+                              "send_entry=%p\n", cm_node->send_entry);
                ret = rem_ref_cm_node(cm_core, cm_node);
                break;
        }
@@ -2257,7 +2495,7 @@ static int mini_cm_close(struct nes_cm_core *cm_core, struct nes_cm_node *cm_nod
  * node state machine
  */
 static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
-       struct nes_vnic *nesvnic, struct sk_buff *skb)
+                           struct nes_vnic *nesvnic, struct sk_buff *skb)
 {
        struct nes_cm_node *cm_node = NULL;
        struct nes_cm_listener *listener = NULL;
@@ -2269,9 +2507,8 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
 
        if (!skb)
                return 0;
-       if (skb->len < sizeof(struct iphdr) + sizeof(struct tcphdr)) {
+       if (skb->len < sizeof(struct iphdr) + sizeof(struct tcphdr))
                return 0;
-       }
 
        iph = (struct iphdr *)skb->data;
        tcph = (struct tcphdr *)(skb->data + sizeof(struct iphdr));
@@ -2289,8 +2526,8 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
 
        do {
                cm_node = find_node(cm_core,
-                       nfo.rem_port, nfo.rem_addr,
-                       nfo.loc_port, nfo.loc_addr);
+                                   nfo.rem_port, nfo.rem_addr,
+                                   nfo.loc_port, nfo.loc_addr);
 
                if (!cm_node) {
                        /* Only type of packet accepted are for */
@@ -2300,8 +2537,8 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
                                break;
                        }
                        listener = find_listener(cm_core, nfo.loc_addr,
-                               nfo.loc_port,
-                               NES_CM_LISTENER_ACTIVE_STATE);
+                                                nfo.loc_port,
+                                                NES_CM_LISTENER_ACTIVE_STATE);
                        if (!listener) {
                                nfo.cm_id = NULL;
                                nfo.conn_type = 0;
@@ -2312,10 +2549,10 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
                        nfo.cm_id = listener->cm_id;
                        nfo.conn_type = listener->conn_type;
                        cm_node = make_cm_node(cm_core, nesvnic, &nfo,
-                               listener);
+                                              listener);
                        if (!cm_node) {
                                nes_debug(NES_DBG_CM, "Unable to allocate "
-                                       "node\n");
+                                         "node\n");
                                cm_packets_dropped++;
                                atomic_dec(&listener->ref_count);
                                dev_kfree_skb_any(skb);
@@ -2331,9 +2568,13 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
                        }
                        add_ref_cm_node(cm_node);
                } else if (cm_node->state == NES_CM_STATE_TSA) {
-                       rem_ref_cm_node(cm_core, cm_node);
-                       atomic_inc(&cm_accel_dropped_pkts);
-                       dev_kfree_skb_any(skb);
+                       if (cm_node->nesqp->pau_mode)
+                               nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
+                       else {
+                               rem_ref_cm_node(cm_core, cm_node);
+                               atomic_inc(&cm_accel_dropped_pkts);
+                               dev_kfree_skb_any(skb);
+                       }
                        break;
                }
                skb_reset_network_header(skb);
@@ -2363,7 +2604,7 @@ static struct nes_cm_core *nes_cm_alloc_core(void)
        init_timer(&cm_core->tcp_timer);
        cm_core->tcp_timer.function = nes_cm_timer_tick;
 
-       cm_core->mtu   = NES_CM_DEFAULT_MTU;
+       cm_core->mtu = NES_CM_DEFAULT_MTU;
        cm_core->state = NES_CM_STATE_INITED;
        cm_core->free_tx_pkt_max = NES_CM_DEFAULT_FREE_PKTS;
 
@@ -2401,9 +2642,8 @@ static int mini_cm_dealloc_core(struct nes_cm_core *cm_core)
 
        barrier();
 
-       if (timer_pending(&cm_core->tcp_timer)) {
+       if (timer_pending(&cm_core->tcp_timer))
                del_timer(&cm_core->tcp_timer);
-       }
 
        destroy_workqueue(cm_core->event_wq);
        destroy_workqueue(cm_core->disconn_wq);
@@ -2458,8 +2698,8 @@ static int nes_cm_init_tsa_conn(struct nes_qp *nesqp, struct nes_cm_node *cm_nod
                return -EINVAL;
 
        nesqp->nesqp_context->misc |= cpu_to_le32(NES_QPCONTEXT_MISC_IPV4 |
-                       NES_QPCONTEXT_MISC_NO_NAGLE | NES_QPCONTEXT_MISC_DO_NOT_FRAG |
-                       NES_QPCONTEXT_MISC_DROS);
+                                                 NES_QPCONTEXT_MISC_NO_NAGLE | NES_QPCONTEXT_MISC_DO_NOT_FRAG |
+                                                 NES_QPCONTEXT_MISC_DROS);
 
        if (cm_node->tcp_cntxt.snd_wscale || cm_node->tcp_cntxt.rcv_wscale)
                nesqp->nesqp_context->misc |= cpu_to_le32(NES_QPCONTEXT_MISC_WSCALE);
@@ -2469,15 +2709,15 @@ static int nes_cm_init_tsa_conn(struct nes_qp *nesqp, struct nes_cm_node *cm_nod
        nesqp->nesqp_context->mss |= cpu_to_le32(((u32)cm_node->tcp_cntxt.mss) << 16);
 
        nesqp->nesqp_context->tcp_state_flow_label |= cpu_to_le32(
-                       (u32)NES_QPCONTEXT_TCPSTATE_EST << NES_QPCONTEXT_TCPFLOW_TCP_STATE_SHIFT);
+               (u32)NES_QPCONTEXT_TCPSTATE_EST << NES_QPCONTEXT_TCPFLOW_TCP_STATE_SHIFT);
 
        nesqp->nesqp_context->pd_index_wscale |= cpu_to_le32(
-                       (cm_node->tcp_cntxt.snd_wscale << NES_QPCONTEXT_PDWSCALE_SND_WSCALE_SHIFT) &
-                       NES_QPCONTEXT_PDWSCALE_SND_WSCALE_MASK);
+               (cm_node->tcp_cntxt.snd_wscale << NES_QPCONTEXT_PDWSCALE_SND_WSCALE_SHIFT) &
+               NES_QPCONTEXT_PDWSCALE_SND_WSCALE_MASK);
 
        nesqp->nesqp_context->pd_index_wscale |= cpu_to_le32(
-                       (cm_node->tcp_cntxt.rcv_wscale << NES_QPCONTEXT_PDWSCALE_RCV_WSCALE_SHIFT) &
-                       NES_QPCONTEXT_PDWSCALE_RCV_WSCALE_MASK);
+               (cm_node->tcp_cntxt.rcv_wscale << NES_QPCONTEXT_PDWSCALE_RCV_WSCALE_SHIFT) &
+               NES_QPCONTEXT_PDWSCALE_RCV_WSCALE_MASK);
 
        nesqp->nesqp_context->keepalive = cpu_to_le32(0x80);
        nesqp->nesqp_context->ts_recent = 0;
@@ -2486,24 +2726,24 @@ static int nes_cm_init_tsa_conn(struct nes_qp *nesqp, struct nes_cm_node *cm_nod
        nesqp->nesqp_context->snd_wnd = cpu_to_le32(cm_node->tcp_cntxt.snd_wnd);
        nesqp->nesqp_context->rcv_nxt = cpu_to_le32(cm_node->tcp_cntxt.rcv_nxt);
        nesqp->nesqp_context->rcv_wnd = cpu_to_le32(cm_node->tcp_cntxt.rcv_wnd <<
-                       cm_node->tcp_cntxt.rcv_wscale);
+                                                   cm_node->tcp_cntxt.rcv_wscale);
        nesqp->nesqp_context->snd_max = cpu_to_le32(cm_node->tcp_cntxt.loc_seq_num);
        nesqp->nesqp_context->snd_una = cpu_to_le32(cm_node->tcp_cntxt.loc_seq_num);
        nesqp->nesqp_context->srtt = 0;
        nesqp->nesqp_context->rttvar = cpu_to_le32(0x6);
        nesqp->nesqp_context->ssthresh = cpu_to_le32(0x3FFFC000);
-       nesqp->nesqp_context->cwnd = cpu_to_le32(2*cm_node->tcp_cntxt.mss);
+       nesqp->nesqp_context->cwnd = cpu_to_le32(2 * cm_node->tcp_cntxt.mss);
        nesqp->nesqp_context->snd_wl1 = cpu_to_le32(cm_node->tcp_cntxt.rcv_nxt);
        nesqp->nesqp_context->snd_wl2 = cpu_to_le32(cm_node->tcp_cntxt.loc_seq_num);
        nesqp->nesqp_context->max_snd_wnd = cpu_to_le32(cm_node->tcp_cntxt.max_snd_wnd);
 
        nes_debug(NES_DBG_CM, "QP%u: rcv_nxt = 0x%08X, snd_nxt = 0x%08X,"
-                       " Setting MSS to %u, PDWscale = 0x%08X, rcv_wnd = %u, context misc = 0x%08X.\n",
-                       nesqp->hwqp.qp_id, le32_to_cpu(nesqp->nesqp_context->rcv_nxt),
-                       le32_to_cpu(nesqp->nesqp_context->snd_nxt),
-                       cm_node->tcp_cntxt.mss, le32_to_cpu(nesqp->nesqp_context->pd_index_wscale),
-                       le32_to_cpu(nesqp->nesqp_context->rcv_wnd),
-                       le32_to_cpu(nesqp->nesqp_context->misc));
+                 " Setting MSS to %u, PDWscale = 0x%08X, rcv_wnd = %u, context misc = 0x%08X.\n",
+                 nesqp->hwqp.qp_id, le32_to_cpu(nesqp->nesqp_context->rcv_nxt),
+                 le32_to_cpu(nesqp->nesqp_context->snd_nxt),
+                 cm_node->tcp_cntxt.mss, le32_to_cpu(nesqp->nesqp_context->pd_index_wscale),
+                 le32_to_cpu(nesqp->nesqp_context->rcv_wnd),
+                 le32_to_cpu(nesqp->nesqp_context->misc));
        nes_debug(NES_DBG_CM, "  snd_wnd  = 0x%08X.\n", le32_to_cpu(nesqp->nesqp_context->snd_wnd));
        nes_debug(NES_DBG_CM, "  snd_cwnd = 0x%08X.\n", le32_to_cpu(nesqp->nesqp_context->cwnd));
        nes_debug(NES_DBG_CM, "  max_swnd = 0x%08X.\n", le32_to_cpu(nesqp->nesqp_context->max_snd_wnd));
@@ -2524,7 +2764,7 @@ int nes_cm_disconn(struct nes_qp *nesqp)
 
        work = kzalloc(sizeof *work, GFP_ATOMIC);
        if (!work)
-               return -ENOMEM; /* Timer will clean up */
+               return -ENOMEM;  /* Timer will clean up */
 
        nes_add_ref(&nesqp->ibqp);
        work->nesqp = nesqp;
@@ -2544,7 +2784,7 @@ static void nes_disconnect_worker(struct work_struct *work)
 
        kfree(dwork);
        nes_debug(NES_DBG_CM, "processing AEQE id 0x%04X for QP%u.\n",
-                       nesqp->last_aeq, nesqp->hwqp.qp_id);
+                 nesqp->last_aeq, nesqp->hwqp.qp_id);
        nes_cm_disconn_true(nesqp);
        nes_rem_ref(&nesqp->ibqp);
 }
@@ -2580,7 +2820,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
        /* make sure we havent already closed this connection */
        if (!cm_id) {
                nes_debug(NES_DBG_CM, "QP%u disconnect_worker cmid is NULL\n",
-                               nesqp->hwqp.qp_id);
+                         nesqp->hwqp.qp_id);
                spin_unlock_irqrestore(&nesqp->lock, flags);
                return -1;
        }
@@ -2589,7 +2829,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
        nes_debug(NES_DBG_CM, "Disconnecting QP%u\n", nesqp->hwqp.qp_id);
 
        original_hw_tcp_state = nesqp->hw_tcp_state;
-       original_ibqp_state   = nesqp->ibqp_state;
+       original_ibqp_state = nesqp->ibqp_state;
        last_ae = nesqp->last_aeq;
 
        if (nesqp->term_flags) {
@@ -2647,16 +2887,16 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
                        cm_event.private_data_len = 0;
 
                        nes_debug(NES_DBG_CM, "Generating a CM Disconnect Event"
-                               " for  QP%u, SQ Head = %u, SQ Tail = %u. "
-                               "cm_id = %p, refcount = %u.\n",
-                               nesqp->hwqp.qp_id, nesqp->hwqp.sq_head,
-                               nesqp->hwqp.sq_tail, cm_id,
-                               atomic_read(&nesqp->refcount));
+                                 " for  QP%u, SQ Head = %u, SQ Tail = %u. "
+                                 "cm_id = %p, refcount = %u.\n",
+                                 nesqp->hwqp.qp_id, nesqp->hwqp.sq_head,
+                                 nesqp->hwqp.sq_tail, cm_id,
+                                 atomic_read(&nesqp->refcount));
 
                        ret = cm_id->event_handler(cm_id, &cm_event);
                        if (ret)
                                nes_debug(NES_DBG_CM, "OFA CM event_handler "
-                                       "returned, ret=%d\n", ret);
+                                         "returned, ret=%d\n", ret);
                }
 
                if (issue_close) {
@@ -2674,9 +2914,8 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
                        cm_event.private_data_len = 0;
 
                        ret = cm_id->event_handler(cm_id, &cm_event);
-                       if (ret) {
+                       if (ret)
                                nes_debug(NES_DBG_CM, "OFA CM event_handler returned, ret=%d\n", ret);
-                       }
 
                        cm_id->rem_ref(cm_id);
                }
@@ -2716,8 +2955,8 @@ static int nes_disconnect(struct nes_qp *nesqp, int abrupt)
                        if (nesqp->lsmm_mr)
                                nesibdev->ibdev.dereg_mr(nesqp->lsmm_mr);
                        pci_free_consistent(nesdev->pcidev,
-                                       nesqp->private_data_len+sizeof(struct ietf_mpa_frame),
-                                       nesqp->ietf_frame, nesqp->ietf_frame_pbase);
+                                           nesqp->private_data_len + nesqp->ietf_frame_size,
+                                           nesqp->ietf_frame, nesqp->ietf_frame_pbase);
                }
        }
 
@@ -2756,6 +2995,12 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
        struct ib_phys_buf ibphysbuf;
        struct nes_pd *nespd;
        u64 tagged_offset;
+       u8 mpa_frame_offset = 0;
+       struct ietf_mpa_v2 *mpa_v2_frame;
+       u8 start_addr = 0;
+       u8 *start_ptr = &start_addr;
+       u8 **start_buff = &start_ptr;
+       u16 buff_len = 0;
 
        ibqp = nes_get_qp(cm_id->device, conn_param->qpn);
        if (!ibqp)
@@ -2796,53 +3041,49 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
        nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
                        netdev_refcnt_read(nesvnic->netdev));
 
+       nesqp->ietf_frame_size = sizeof(struct ietf_mpa_v2);
        /* allocate the ietf frame and space for private data */
        nesqp->ietf_frame = pci_alloc_consistent(nesdev->pcidev,
-               sizeof(struct ietf_mpa_frame) + conn_param->private_data_len,
-               &nesqp->ietf_frame_pbase);
+                                                nesqp->ietf_frame_size + conn_param->private_data_len,
+                                                &nesqp->ietf_frame_pbase);
 
        if (!nesqp->ietf_frame) {
-               nes_debug(NES_DBG_CM, "Unable to allocate memory for private "
-                       "data\n");
+               nes_debug(NES_DBG_CM, "Unable to allocate memory for private data\n");
                return -ENOMEM;
        }
+       mpa_v2_frame = (struct ietf_mpa_v2 *)nesqp->ietf_frame;
 
+       if (cm_node->mpa_frame_rev == IETF_MPA_V1)
+               mpa_frame_offset = 4;
 
-       /* setup the MPA frame */
-       nesqp->private_data_len = conn_param->private_data_len;
-       memcpy(nesqp->ietf_frame->key, IEFT_MPA_KEY_REP, IETF_MPA_KEY_SIZE);
-
-       memcpy(nesqp->ietf_frame->priv_data, conn_param->private_data,
-                       conn_param->private_data_len);
+       memcpy(mpa_v2_frame->priv_data, conn_param->private_data,
+              conn_param->private_data_len);
 
-       nesqp->ietf_frame->priv_data_len =
-               cpu_to_be16(conn_param->private_data_len);
-       nesqp->ietf_frame->rev = mpa_version;
-       nesqp->ietf_frame->flags = IETF_MPA_FLAGS_CRC;
+       cm_build_mpa_frame(cm_node, start_buff, &buff_len, nesqp->ietf_frame, MPA_KEY_REPLY);
+       nesqp->private_data_len = conn_param->private_data_len;
 
        /* setup our first outgoing iWarp send WQE (the IETF frame response) */
        wqe = &nesqp->hwqp.sq_vbase[0];
 
        if (cm_id->remote_addr.sin_addr.s_addr !=
-                       cm_id->local_addr.sin_addr.s_addr) {
+           cm_id->local_addr.sin_addr.s_addr) {
                u64temp = (unsigned long)nesqp;
                nesibdev = nesvnic->nesibdev;
                nespd = nesqp->nespd;
-               ibphysbuf.addr = nesqp->ietf_frame_pbase;
-               ibphysbuf.size = conn_param->private_data_len +
-                                       sizeof(struct ietf_mpa_frame);
-               tagged_offset = (u64)(unsigned long)nesqp->ietf_frame;
+               ibphysbuf.addr = nesqp->ietf_frame_pbase + mpa_frame_offset;
+               ibphysbuf.size = buff_len;
+               tagged_offset = (u64)(unsigned long)*start_buff;
                ibmr = nesibdev->ibdev.reg_phys_mr((struct ib_pd *)nespd,
-                                               &ibphysbuf, 1,
-                                               IB_ACCESS_LOCAL_WRITE,
-                                               &tagged_offset);
+                                                  &ibphysbuf, 1,
+                                                  IB_ACCESS_LOCAL_WRITE,
+                                                  &tagged_offset);
                if (!ibmr) {
                        nes_debug(NES_DBG_CM, "Unable to register memory region"
-                                       "for lSMM for cm_node = %p \n",
-                                       cm_node);
+                                 "for lSMM for cm_node = %p \n",
+                                 cm_node);
                        pci_free_consistent(nesdev->pcidev,
-                               nesqp->private_data_len+sizeof(struct ietf_mpa_frame),
-                               nesqp->ietf_frame, nesqp->ietf_frame_pbase);
+                                           nesqp->private_data_len + nesqp->ietf_frame_size,
+                                           nesqp->ietf_frame, nesqp->ietf_frame_pbase);
                        return -ENOMEM;
                }
 
@@ -2850,22 +3091,20 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
                ibmr->device = nespd->ibpd.device;
                nesqp->lsmm_mr = ibmr;
 
-               u64temp |= NES_SW_CONTEXT_ALIGN>>1;
+               u64temp |= NES_SW_CONTEXT_ALIGN >> 1;
                set_wqe_64bit_value(wqe->wqe_words,
-                       NES_IWARP_SQ_WQE_COMP_CTX_LOW_IDX,
-                       u64temp);
+                                   NES_IWARP_SQ_WQE_COMP_CTX_LOW_IDX,
+                                   u64temp);
                wqe->wqe_words[NES_IWARP_SQ_WQE_MISC_IDX] =
                        cpu_to_le32(NES_IWARP_SQ_WQE_STREAMING |
-                       NES_IWARP_SQ_WQE_WRPDU);
+                                   NES_IWARP_SQ_WQE_WRPDU);
                wqe->wqe_words[NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX] =
-                       cpu_to_le32(conn_param->private_data_len +
-                       sizeof(struct ietf_mpa_frame));
+                       cpu_to_le32(buff_len);
                set_wqe_64bit_value(wqe->wqe_words,
-                                       NES_IWARP_SQ_WQE_FRAG0_LOW_IDX,
-                                       (u64)(unsigned long)nesqp->ietf_frame);
+                                   NES_IWARP_SQ_WQE_FRAG0_LOW_IDX,
+                                   (u64)(unsigned long)(*start_buff));
                wqe->wqe_words[NES_IWARP_SQ_WQE_LENGTH0_IDX] =
-                       cpu_to_le32(conn_param->private_data_len +
-                       sizeof(struct ietf_mpa_frame));
+                       cpu_to_le32(buff_len);
                wqe->wqe_words[NES_IWARP_SQ_WQE_STAG0_IDX] = ibmr->lkey;
                if (nesqp->sq_kmapped) {
                        nesqp->sq_kmapped = 0;
@@ -2874,7 +3113,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
 
                nesqp->nesqp_context->ird_ord_sizes |=
                        cpu_to_le32(NES_QPCONTEXT_ORDIRD_LSMM_PRESENT |
-                       NES_QPCONTEXT_ORDIRD_WRPDU);
+                                   NES_QPCONTEXT_ORDIRD_WRPDU);
        } else {
                nesqp->nesqp_context->ird_ord_sizes |=
                        cpu_to_le32(NES_QPCONTEXT_ORDIRD_WRPDU);
@@ -2888,11 +3127,11 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
 
        /*  nesqp->cm_node = (void *)cm_id->provider_data; */
        cm_id->provider_data = nesqp;
-       nesqp->active_conn   = 0;
+       nesqp->active_conn = 0;
 
        if (cm_node->state == NES_CM_STATE_TSA)
                nes_debug(NES_DBG_CM, "Already state = TSA for cm_node=%p\n",
-                       cm_node);
+                         cm_node);
 
        nes_cm_init_tsa_conn(nesqp, cm_node);
 
@@ -2909,13 +3148,13 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
                        cpu_to_le32(ntohl(cm_id->remote_addr.sin_addr.s_addr));
 
        nesqp->nesqp_context->misc2 |= cpu_to_le32(
-                       (u32)PCI_FUNC(nesdev->pcidev->devfn) <<
-                       NES_QPCONTEXT_MISC2_SRC_IP_SHIFT);
+               (u32)PCI_FUNC(nesdev->pcidev->devfn) <<
+               NES_QPCONTEXT_MISC2_SRC_IP_SHIFT);
 
        nesqp->nesqp_context->arp_index_vlan |=
                cpu_to_le32(nes_arp_table(nesdev,
-                       le32_to_cpu(nesqp->nesqp_context->ip0), NULL,
-                       NES_ARP_RESOLVE) << 16);
+                                         le32_to_cpu(nesqp->nesqp_context->ip0), NULL,
+                                         NES_ARP_RESOLVE) << 16);
 
        nesqp->nesqp_context->ts_val_delta = cpu_to_le32(
                jiffies - nes_read_indexed(nesdev, NES_IDX_TCP_NOW));
@@ -2941,7 +3180,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
        crc_value = get_crc_value(&nes_quad);
        nesqp->hte_index = cpu_to_be32(crc_value ^ 0xffffffff);
        nes_debug(NES_DBG_CM, "HTE Index = 0x%08X, CRC = 0x%08X\n",
-               nesqp->hte_index, nesqp->hte_index & adapter->hte_index_mask);
+                 nesqp->hte_index, nesqp->hte_index & adapter->hte_index_mask);
 
        nesqp->hte_index &= adapter->hte_index_mask;
        nesqp->nesqp_context->hte_index = cpu_to_le32(nesqp->hte_index);
@@ -2949,17 +3188,15 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
        cm_node->cm_core->api->accelerated(cm_node->cm_core, cm_node);
 
        nes_debug(NES_DBG_CM, "QP%u, Destination IP = 0x%08X:0x%04X, local = "
-                       "0x%08X:0x%04X, rcv_nxt=0x%08X, snd_nxt=0x%08X, mpa + "
-                       "private data length=%zu.\n", nesqp->hwqp.qp_id,
-                       ntohl(cm_id->remote_addr.sin_addr.s_addr),
-                       ntohs(cm_id->remote_addr.sin_port),
-                       ntohl(cm_id->local_addr.sin_addr.s_addr),
-                       ntohs(cm_id->local_addr.sin_port),
-                       le32_to_cpu(nesqp->nesqp_context->rcv_nxt),
-                       le32_to_cpu(nesqp->nesqp_context->snd_nxt),
-                       conn_param->private_data_len +
-                       sizeof(struct ietf_mpa_frame));
-
+                 "0x%08X:0x%04X, rcv_nxt=0x%08X, snd_nxt=0x%08X, mpa + "
+                 "private data length=%u.\n", nesqp->hwqp.qp_id,
+                 ntohl(cm_id->remote_addr.sin_addr.s_addr),
+                 ntohs(cm_id->remote_addr.sin_port),
+                 ntohl(cm_id->local_addr.sin_addr.s_addr),
+                 ntohs(cm_id->local_addr.sin_port),
+                 le32_to_cpu(nesqp->nesqp_context->rcv_nxt),
+                 le32_to_cpu(nesqp->nesqp_context->snd_nxt),
+                 buff_len);
 
        /* notify OF layer that accept event was successful */
        cm_id->add_ref(cm_id);
@@ -2980,12 +3217,12 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
                        nesqp->private_data_len;
                /* copy entire MPA frame to our cm_node's frame */
                memcpy(cm_node->loopbackpartner->mpa_frame_buf,
-                       nesqp->ietf_frame->priv_data, nesqp->private_data_len);
+                      conn_param->private_data, conn_param->private_data_len);
                create_event(cm_node->loopbackpartner, NES_CM_EVENT_CONNECTED);
        }
        if (ret)
                printk(KERN_ERR "%s[%u] OFA CM event_handler returned, "
-                       "ret=%d\n", __func__, __LINE__, ret);
+                      "ret=%d\n", __func__, __LINE__, ret);
 
        return 0;
 }
@@ -2998,34 +3235,28 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
 {
        struct nes_cm_node *cm_node;
        struct nes_cm_node *loopback;
-
        struct nes_cm_core *cm_core;
+       u8 *start_buff;
 
        atomic_inc(&cm_rejects);
-       cm_node = (struct nes_cm_node *) cm_id->provider_data;
+       cm_node = (struct nes_cm_node *)cm_id->provider_data;
        loopback = cm_node->loopbackpartner;
        cm_core = cm_node->cm_core;
        cm_node->cm_id = cm_id;
-       cm_node->mpa_frame_size = sizeof(struct ietf_mpa_frame) + pdata_len;
 
-       if (cm_node->mpa_frame_size > MAX_CM_BUFFER)
+       if (pdata_len + sizeof(struct ietf_mpa_v2) > MAX_CM_BUFFER)
                return -EINVAL;
 
-       memcpy(&cm_node->mpa_frame.key[0], IEFT_MPA_KEY_REP, IETF_MPA_KEY_SIZE);
        if (loopback) {
                memcpy(&loopback->mpa_frame.priv_data, pdata, pdata_len);
                loopback->mpa_frame.priv_data_len = pdata_len;
-               loopback->mpa_frame_size = sizeof(struct ietf_mpa_frame) +
-                               pdata_len;
+               loopback->mpa_frame_size = pdata_len;
        } else {
-               memcpy(&cm_node->mpa_frame.priv_data, pdata, pdata_len);
-               cm_node->mpa_frame.priv_data_len = cpu_to_be16(pdata_len);
+               start_buff = &cm_node->mpa_frame_buf[0] + sizeof(struct ietf_mpa_v2);
+               cm_node->mpa_frame_size = pdata_len;
+               memcpy(start_buff, pdata, pdata_len);
        }
-
-       cm_node->mpa_frame.rev = mpa_version;
-       cm_node->mpa_frame.flags = IETF_MPA_FLAGS_CRC | IETF_MPA_FLAGS_REJECT;
-
-       return cm_core->api->reject(cm_core, &cm_node->mpa_frame, cm_node);
+       return cm_core->api->reject(cm_core, cm_node);
 }
 
 
@@ -3052,7 +3283,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
        nesvnic = to_nesvnic(nesqp->ibqp.device);
        if (!nesvnic)
                return -EINVAL;
-       nesdev  = nesvnic->nesdev;
+       nesdev = nesvnic->nesdev;
        if (!nesdev)
                return -EINVAL;
 
@@ -3060,12 +3291,12 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
                return -EINVAL;
 
        nes_debug(NES_DBG_CM, "QP%u, current IP = 0x%08X, Destination IP = "
-               "0x%08X:0x%04X, local = 0x%08X:0x%04X.\n", nesqp->hwqp.qp_id,
-               ntohl(nesvnic->local_ipaddr),
-               ntohl(cm_id->remote_addr.sin_addr.s_addr),
-               ntohs(cm_id->remote_addr.sin_port),
-               ntohl(cm_id->local_addr.sin_addr.s_addr),
-               ntohs(cm_id->local_addr.sin_port));
+                 "0x%08X:0x%04X, local = 0x%08X:0x%04X.\n", nesqp->hwqp.qp_id,
+                 ntohl(nesvnic->local_ipaddr),
+                 ntohl(cm_id->remote_addr.sin_addr.s_addr),
+                 ntohs(cm_id->remote_addr.sin_port),
+                 ntohl(cm_id->local_addr.sin_addr.s_addr),
+                 ntohs(cm_id->local_addr.sin_port));
 
        atomic_inc(&cm_connects);
        nesqp->active_conn = 1;
@@ -3079,12 +3310,12 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
        nesqp->nesqp_context->ird_ord_sizes |= cpu_to_le32((u32)conn_param->ord);
        nes_debug(NES_DBG_CM, "requested ord = 0x%08X.\n", (u32)conn_param->ord);
        nes_debug(NES_DBG_CM, "mpa private data len =%u\n",
-               conn_param->private_data_len);
+                 conn_param->private_data_len);
 
        if (cm_id->local_addr.sin_addr.s_addr !=
-               cm_id->remote_addr.sin_addr.s_addr) {
+           cm_id->remote_addr.sin_addr.s_addr) {
                nes_manage_apbvt(nesvnic, ntohs(cm_id->local_addr.sin_port),
-                       PCI_FUNC(nesdev->pcidev->devfn), NES_MANAGE_APBVT_ADD);
+                                PCI_FUNC(nesdev->pcidev->devfn), NES_MANAGE_APBVT_ADD);
                apbvt_set = 1;
        }
 
@@ -3100,13 +3331,13 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
 
        /* create a connect CM node connection */
        cm_node = g_cm_core->api->connect(g_cm_core, nesvnic,
-               conn_param->private_data_len, (void *)conn_param->private_data,
-               &cm_info);
+                                         conn_param->private_data_len, (void *)conn_param->private_data,
+                                         &cm_info);
        if (!cm_node) {
                if (apbvt_set)
                        nes_manage_apbvt(nesvnic, ntohs(cm_id->local_addr.sin_port),
-                               PCI_FUNC(nesdev->pcidev->devfn),
-                               NES_MANAGE_APBVT_DEL);
+                                        PCI_FUNC(nesdev->pcidev->devfn),
+                                        NES_MANAGE_APBVT_DEL);
 
                cm_id->rem_ref(cm_id);
                return -ENOMEM;
@@ -3156,7 +3387,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
        cm_node = g_cm_core->api->listen(g_cm_core, nesvnic, &cm_info);
        if (!cm_node) {
                printk(KERN_ERR "%s[%u] Error returned from listen API call\n",
-                               __func__, __LINE__);
+                      __func__, __LINE__);
                return -ENOMEM;
        }
 
@@ -3164,12 +3395,12 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
 
        if (!cm_node->reused_node) {
                err = nes_manage_apbvt(nesvnic,
-                       ntohs(cm_id->local_addr.sin_port),
-                       PCI_FUNC(nesvnic->nesdev->pcidev->devfn),
-                       NES_MANAGE_APBVT_ADD);
+                                      ntohs(cm_id->local_addr.sin_port),
+                                      PCI_FUNC(nesvnic->nesdev->pcidev->devfn),
+                                      NES_MANAGE_APBVT_ADD);
                if (err) {
                        printk(KERN_ERR "nes_manage_apbvt call returned %d.\n",
-                               err);
+                              err);
                        g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
                        return err;
                }
@@ -3206,13 +3437,13 @@ int nes_destroy_listen(struct iw_cm_id *cm_id)
 int nes_cm_recv(struct sk_buff *skb, struct net_device *netdevice)
 {
        int rc = 0;
+
        cm_packets_received++;
-       if ((g_cm_core) && (g_cm_core->api)) {
+       if ((g_cm_core) && (g_cm_core->api))
                rc = g_cm_core->api->recv_pkt(g_cm_core, netdev_priv(netdevice), skb);
-       } else {
+       else
                nes_debug(NES_DBG_CM, "Unable to process packet for CM,"
-                               " cm is not setup properly.\n");
-       }
+                         " cm is not setup properly.\n");
 
        return rc;
 }
@@ -3227,11 +3458,10 @@ int nes_cm_start(void)
        nes_debug(NES_DBG_CM, "\n");
        /* create the primary CM core, pass this handle to subsequent core inits */
        g_cm_core = nes_cm_alloc_core();
-       if (g_cm_core) {
+       if (g_cm_core)
                return 0;
-       } else {
+       else
                return -ENOMEM;
-       }
 }
 
 
@@ -3252,7 +3482,6 @@ int nes_cm_stop(void)
  */
 static void cm_event_connected(struct nes_cm_event *event)
 {
-       u64 u64temp;
        struct nes_qp *nesqp;
        struct nes_vnic *nesvnic;
        struct nes_device *nesdev;
@@ -3261,7 +3490,6 @@ static void cm_event_connected(struct nes_cm_event *event)
        struct ib_qp_attr attr;
        struct iw_cm_id *cm_id;
        struct iw_cm_event cm_event;
-       struct nes_hw_qp_wqe *wqe;
        struct nes_v4_quad nes_quad;
        u32 crc_value;
        int ret;
@@ -3275,17 +3503,16 @@ static void cm_event_connected(struct nes_cm_event *event)
        nesdev = nesvnic->nesdev;
        nesadapter = nesdev->nesadapter;
 
-       if (nesqp->destroyed) {
+       if (nesqp->destroyed)
                return;
-       }
        atomic_inc(&cm_connecteds);
        nes_debug(NES_DBG_CM, "QP%u attempting to connect to  0x%08X:0x%04X on"
-                       " local port 0x%04X. jiffies = %lu.\n",
-                       nesqp->hwqp.qp_id,
-                       ntohl(cm_id->remote_addr.sin_addr.s_addr),
-                       ntohs(cm_id->remote_addr.sin_port),
-                       ntohs(cm_id->local_addr.sin_port),
-                       jiffies);
+                 " local port 0x%04X. jiffies = %lu.\n",
+                 nesqp->hwqp.qp_id,
+                 ntohl(cm_id->remote_addr.sin_addr.s_addr),
+                 ntohs(cm_id->remote_addr.sin_port),
+                 ntohs(cm_id->local_addr.sin_port),
+                 jiffies);
 
        nes_cm_init_tsa_conn(nesqp, cm_node);
 
@@ -3316,40 +3543,12 @@ static void cm_event_connected(struct nes_cm_event *event)
                        NES_QPCONTEXT_ORDIRD_IWARP_MODE_SHIFT);
 
        /* Adjust tail for not having a LSMM */
-       nesqp->hwqp.sq_tail = 1;
+       /*nesqp->hwqp.sq_tail = 1;*/
 
-#if defined(NES_SEND_FIRST_WRITE)
-       if (cm_node->send_write0) {
-               nes_debug(NES_DBG_CM, "Sending first write.\n");
-               wqe = &nesqp->hwqp.sq_vbase[0];
-               u64temp = (unsigned long)nesqp;
-               u64temp |= NES_SW_CONTEXT_ALIGN>>1;
-               set_wqe_64bit_value(wqe->wqe_words,
-                               NES_IWARP_SQ_WQE_COMP_CTX_LOW_IDX, u64temp);
-               wqe->wqe_words[NES_IWARP_SQ_WQE_MISC_IDX] =
-                       cpu_to_le32(NES_IWARP_SQ_OP_RDMAW);
-               wqe->wqe_words[NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX] = 0;
-               wqe->wqe_words[NES_IWARP_SQ_WQE_FRAG0_LOW_IDX] = 0;
-               wqe->wqe_words[NES_IWARP_SQ_WQE_FRAG0_HIGH_IDX] = 0;
-               wqe->wqe_words[NES_IWARP_SQ_WQE_LENGTH0_IDX] = 0;
-               wqe->wqe_words[NES_IWARP_SQ_WQE_STAG0_IDX] = 0;
+       build_rdma0_msg(cm_node, &nesqp);
 
-               if (nesqp->sq_kmapped) {
-                       nesqp->sq_kmapped = 0;
-                       kunmap(nesqp->page);
-               }
-
-               /* use the reserved spot on the WQ for the extra first WQE */
-               nesqp->nesqp_context->ird_ord_sizes &=
-                       cpu_to_le32(~(NES_QPCONTEXT_ORDIRD_LSMM_PRESENT |
-                                               NES_QPCONTEXT_ORDIRD_WRPDU |
-                                               NES_QPCONTEXT_ORDIRD_ALSMM));
-               nesqp->skip_lsmm = 1;
-               nesqp->hwqp.sq_tail = 0;
-               nes_write32(nesdev->regs + NES_WQE_ALLOC,
-                               (1 << 24) | 0x00800000 | nesqp->hwqp.qp_id);
-       }
-#endif
+       nes_write32(nesdev->regs + NES_WQE_ALLOC,
+                   (1 << 24) | 0x00800000 | nesqp->hwqp.qp_id);
 
        memset(&nes_quad, 0, sizeof(nes_quad));
 
@@ -3366,13 +3565,13 @@ static void cm_event_connected(struct nes_cm_event *event)
        crc_value = get_crc_value(&nes_quad);
        nesqp->hte_index = cpu_to_be32(crc_value ^ 0xffffffff);
        nes_debug(NES_DBG_CM, "HTE Index = 0x%08X, After CRC = 0x%08X\n",
-                       nesqp->hte_index, nesqp->hte_index & nesadapter->hte_index_mask);
+                 nesqp->hte_index, nesqp->hte_index & nesadapter->hte_index_mask);
 
        nesqp->hte_index &= nesadapter->hte_index_mask;
        nesqp->nesqp_context->hte_index = cpu_to_le32(nesqp->hte_index);
 
        nesqp->ietf_frame = &cm_node->mpa_frame;
-       nesqp->private_data_len = (u8) cm_node->mpa_frame_size;
+       nesqp->private_data_len = (u8)cm_node->mpa_frame_size;
        cm_node->cm_core->api->accelerated(cm_node->cm_core, cm_node);
 
        /* notify OF layer we successfully created the requested connection */
@@ -3384,7 +3583,9 @@ static void cm_event_connected(struct nes_cm_event *event)
        cm_event.remote_addr = cm_id->remote_addr;
 
        cm_event.private_data = (void *)event->cm_node->mpa_frame_buf;
-       cm_event.private_data_len = (u8) event->cm_node->mpa_frame_size;
+       cm_event.private_data_len = (u8)event->cm_node->mpa_frame_size;
+       cm_event.ird = cm_node->ird_size;
+       cm_event.ord = cm_node->ord_size;
 
        cm_event.local_addr.sin_addr.s_addr = event->cm_info.rem_addr;
        ret = cm_id->event_handler(cm_id, &cm_event);
@@ -3392,12 +3593,12 @@ static void cm_event_connected(struct nes_cm_event *event)
 
        if (ret)
                printk(KERN_ERR "%s[%u] OFA CM event_handler returned, "
-                       "ret=%d\n", __func__, __LINE__, ret);
+                      "ret=%d\n", __func__, __LINE__, ret);
        attr.qp_state = IB_QPS_RTS;
        nes_modify_qp(&nesqp->ibqp, &attr, IB_QP_STATE, NULL);
 
        nes_debug(NES_DBG_CM, "Exiting connect thread for QP%u. jiffies = "
-               "%lu\n", nesqp->hwqp.qp_id, jiffies);
+                 "%lu\n", nesqp->hwqp.qp_id, jiffies);
 
        return;
 }
@@ -3418,16 +3619,14 @@ static void cm_event_connect_error(struct nes_cm_event *event)
                return;
 
        cm_id = event->cm_node->cm_id;
-       if (!cm_id) {
+       if (!cm_id)
                return;
-       }
 
        nes_debug(NES_DBG_CM, "cm_node=%p, cm_id=%p\n", event->cm_node, cm_id);
        nesqp = cm_id->provider_data;
 
-       if (!nesqp) {
+       if (!nesqp)
                return;
-       }
 
        /* notify OF layer about this connection error event */
        /* cm_id->rem_ref(cm_id); */
@@ -3442,14 +3641,14 @@ static void cm_event_connect_error(struct nes_cm_event *event)
        cm_event.private_data_len = 0;
 
        nes_debug(NES_DBG_CM, "call CM_EVENT REJECTED, local_addr=%08x, "
-               "remove_addr=%08x\n", cm_event.local_addr.sin_addr.s_addr,
-               cm_event.remote_addr.sin_addr.s_addr);
+                 "remove_addr=%08x\n", cm_event.local_addr.sin_addr.s_addr,
+                 cm_event.remote_addr.sin_addr.s_addr);
 
        ret = cm_id->event_handler(cm_id, &cm_event);
        nes_debug(NES_DBG_CM, "OFA CM event_handler returned, ret=%d\n", ret);
        if (ret)
                printk(KERN_ERR "%s[%u] OFA CM event_handler returned, "
-                       "ret=%d\n", __func__, __LINE__, ret);
+                      "ret=%d\n", __func__, __LINE__, ret);
        cm_id->rem_ref(cm_id);
 
        rem_ref_cm_node(event->cm_node->cm_core, event->cm_node);
@@ -3519,7 +3718,7 @@ static void cm_event_reset(struct nes_cm_event *event)
  */
 static void cm_event_mpa_req(struct nes_cm_event *event)
 {
-       struct iw_cm_id   *cm_id;
+       struct iw_cm_id *cm_id;
        struct iw_cm_event cm_event;
        int ret;
        struct nes_cm_node *cm_node;
@@ -3531,7 +3730,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
 
        atomic_inc(&cm_connect_reqs);
        nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
-                       cm_node, cm_id, jiffies);
+                 cm_node, cm_id, jiffies);
 
        cm_event.event = IW_CM_EVENT_CONNECT_REQUEST;
        cm_event.status = 0;
@@ -3545,19 +3744,21 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
        cm_event.remote_addr.sin_port = htons(event->cm_info.rem_port);
        cm_event.remote_addr.sin_addr.s_addr = htonl(event->cm_info.rem_addr);
        cm_event.private_data = cm_node->mpa_frame_buf;
-       cm_event.private_data_len  = (u8) cm_node->mpa_frame_size;
+       cm_event.private_data_len = (u8)cm_node->mpa_frame_size;
+       cm_event.ird = cm_node->ird_size;
+       cm_event.ord = cm_node->ord_size;
 
        ret = cm_id->event_handler(cm_id, &cm_event);
        if (ret)
                printk(KERN_ERR "%s[%u] OFA CM event_handler returned, ret=%d\n",
-                               __func__, __LINE__, ret);
+                      __func__, __LINE__, ret);
        return;
 }
 
 
 static void cm_event_mpa_reject(struct nes_cm_event *event)
 {
-       struct iw_cm_id   *cm_id;
+       struct iw_cm_id *cm_id;
        struct iw_cm_event cm_event;
        struct nes_cm_node *cm_node;
        int ret;
@@ -3569,7 +3770,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
 
        atomic_inc(&cm_connect_reqs);
        nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
-                       cm_node, cm_id, jiffies);
+                 cm_node, cm_id, jiffies);
 
        cm_event.event = IW_CM_EVENT_CONNECT_REPLY;
        cm_event.status = -ECONNREFUSED;
@@ -3584,17 +3785,17 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
        cm_event.remote_addr.sin_addr.s_addr = htonl(event->cm_info.rem_addr);
 
        cm_event.private_data = cm_node->mpa_frame_buf;
-       cm_event.private_data_len = (u8) cm_node->mpa_frame_size;
+       cm_event.private_data_len = (u8)cm_node->mpa_frame_size;
 
        nes_debug(NES_DBG_CM, "call CM_EVENT_MPA_REJECTED, local_addr=%08x, "
-                       "remove_addr=%08x\n",
-                       cm_event.local_addr.sin_addr.s_addr,
-                       cm_event.remote_addr.sin_addr.s_addr);
+                 "remove_addr=%08x\n",
+                 cm_event.local_addr.sin_addr.s_addr,
+                 cm_event.remote_addr.sin_addr.s_addr);
 
        ret = cm_id->event_handler(cm_id, &cm_event);
        if (ret)
                printk(KERN_ERR "%s[%u] OFA CM event_handler returned, ret=%d\n",
-                               __func__, __LINE__, ret);
+                      __func__, __LINE__, ret);
 
        return;
 }
@@ -3613,7 +3814,7 @@ static int nes_cm_post_event(struct nes_cm_event *event)
        event->cm_info.cm_id->add_ref(event->cm_info.cm_id);
        INIT_WORK(&event->event_work, nes_cm_event_handler);
        nes_debug(NES_DBG_CM, "cm_node=%p queue_work, event=%p\n",
-               event->cm_node, event);
+                 event->cm_node, event);
 
        queue_work(event->cm_node->cm_core->event_wq, &event->event_work);
 
@@ -3630,7 +3831,7 @@ static int nes_cm_post_event(struct nes_cm_event *event)
 static void nes_cm_event_handler(struct work_struct *work)
 {
        struct nes_cm_event *event = container_of(work, struct nes_cm_event,
-                       event_work);
+                                                 event_work);
        struct nes_cm_core *cm_core;
 
        if ((!event) || (!event->cm_node) || (!event->cm_node->cm_core))
@@ -3638,29 +3839,29 @@ static void nes_cm_event_handler(struct work_struct *work)
 
        cm_core = event->cm_node->cm_core;
        nes_debug(NES_DBG_CM, "event=%p, event->type=%u, events posted=%u\n",
-               event, event->type, atomic_read(&cm_core->events_posted));
+                 event, event->type, atomic_read(&cm_core->events_posted));
 
        switch (event->type) {
        case NES_CM_EVENT_MPA_REQ:
                cm_event_mpa_req(event);
                nes_debug(NES_DBG_CM, "cm_node=%p CM Event: MPA REQUEST\n",
-                       event->cm_node);
+                         event->cm_node);
                break;
        case NES_CM_EVENT_RESET:
                nes_debug(NES_DBG_CM, "cm_node = %p CM Event: RESET\n",
-                       event->cm_node);
+                         event->cm_node);
                cm_event_reset(event);
                break;
        case NES_CM_EVENT_CONNECTED:
                if ((!event->cm_node->cm_id) ||
-                       (event->cm_node->state != NES_CM_STATE_TSA))
+                   (event->cm_node->state != NES_CM_STATE_TSA))
                        break;
                cm_event_connected(event);
                nes_debug(NES_DBG_CM, "CM Event: CONNECTED\n");
                break;
        case NES_CM_EVENT_MPA_REJECT:
                if ((!event->cm_node->cm_id) ||
-                               (event->cm_node->state == NES_CM_STATE_TSA))
+                   (event->cm_node->state == NES_CM_STATE_TSA))
                        break;
                cm_event_mpa_reject(event);
                nes_debug(NES_DBG_CM, "CM Event: REJECT\n");
@@ -3668,7 +3869,7 @@ static void nes_cm_event_handler(struct work_struct *work)
 
        case NES_CM_EVENT_ABORTED:
                if ((!event->cm_node->cm_id) ||
-                       (event->cm_node->state == NES_CM_STATE_TSA))
+                   (event->cm_node->state == NES_CM_STATE_TSA))
                        break;
                cm_event_connect_error(event);
                nes_debug(NES_DBG_CM, "CM Event: ABORTED\n");
index d9825fda70a1359226c2fe2f1a766d15bb92bf72..bdfa1fbb35fcea66d1190cc94b237554c029006b 100644 (file)
 #define IETF_MPA_KEY_SIZE 16
 #define IETF_MPA_VERSION  1
 #define IETF_MAX_PRIV_DATA_LEN 512
-#define IETF_MPA_FRAME_SIZE     20
+#define IETF_MPA_FRAME_SIZE    20
+#define IETF_RTR_MSG_SIZE      4
+#define IETF_MPA_V2_FLAG       0x10
+
+/* IETF RTR MSG Fields               */
+#define IETF_PEER_TO_PEER       0x8000
+#define IETF_FLPDU_ZERO_LEN     0x4000
+#define IETF_RDMA0_WRITE        0x8000
+#define IETF_RDMA0_READ         0x4000
+#define IETF_NO_IRD_ORD         0x3FFF
 
 enum ietf_mpa_flags {
        IETF_MPA_FLAGS_MARKERS = 0x80,  /* receive Markers */
@@ -56,7 +65,7 @@ enum ietf_mpa_flags {
        IETF_MPA_FLAGS_REJECT  = 0x20,  /* Reject */
 };
 
-struct ietf_mpa_frame {
+struct ietf_mpa_v1 {
        u8 key[IETF_MPA_KEY_SIZE];
        u8 flags;
        u8 rev;
@@ -66,6 +75,20 @@ struct ietf_mpa_frame {
 
 #define ietf_mpa_req_resp_frame ietf_mpa_frame
 
+struct ietf_rtr_msg {
+       __be16 ctrl_ird;
+       __be16 ctrl_ord;
+};
+
+struct ietf_mpa_v2 {
+       u8 key[IETF_MPA_KEY_SIZE];
+       u8 flags;
+       u8 rev;
+        __be16 priv_data_len;
+       struct ietf_rtr_msg rtr_msg;
+       u8 priv_data[0];
+};
+
 struct nes_v4_quad {
        u32 rsvd0;
        __le32 DstIpAdrIndex;   /* Only most significant 5 bits are valid */
@@ -171,8 +194,7 @@ struct nes_timer_entry {
 
 #define NES_CM_DEF_SEQ2      0x18ed5740
 #define NES_CM_DEF_LOCAL_ID2 0xb807
-#define        MAX_CM_BUFFER   (IETF_MPA_FRAME_SIZE + IETF_MAX_PRIV_DATA_LEN)
-
+#define        MAX_CM_BUFFER   (IETF_MPA_FRAME_SIZE + IETF_RTR_MSG_SIZE + IETF_MAX_PRIV_DATA_LEN)
 
 typedef u32 nes_addr_t;
 
@@ -204,6 +226,21 @@ enum nes_cm_node_state {
        NES_CM_STATE_CLOSED
 };
 
+enum mpa_frame_version {
+       IETF_MPA_V1 = 1,
+       IETF_MPA_V2 = 2
+};
+
+enum mpa_frame_key {
+       MPA_KEY_REQUEST,
+       MPA_KEY_REPLY
+};
+
+enum send_rdma0 {
+       SEND_RDMA_READ_ZERO = 1,
+       SEND_RDMA_WRITE_ZERO = 2
+};
+
 enum nes_tcpip_pkt_type {
        NES_PKT_TYPE_UNKNOWN,
        NES_PKT_TYPE_SYN,
@@ -245,9 +282,9 @@ struct nes_cm_tcp_context {
 
 
 enum nes_cm_listener_state {
-       NES_CM_LISTENER_PASSIVE_STATE=1,
-       NES_CM_LISTENER_ACTIVE_STATE=2,
-       NES_CM_LISTENER_EITHER_STATE=3
+       NES_CM_LISTENER_PASSIVE_STATE = 1,
+       NES_CM_LISTENER_ACTIVE_STATE = 2,
+       NES_CM_LISTENER_EITHER_STATE = 3
 };
 
 struct nes_cm_listener {
@@ -283,16 +320,20 @@ struct nes_cm_node {
 
        struct nes_cm_node        *loopbackpartner;
 
-       struct nes_timer_entry  *send_entry;
-
+       struct nes_timer_entry    *send_entry;
+       struct nes_timer_entry    *recv_entry;
        spinlock_t                retrans_list_lock;
-       struct nes_timer_entry  *recv_entry;
+       enum send_rdma0           send_rdma0_op;
 
-       int                       send_write0;
        union {
-               struct ietf_mpa_frame mpa_frame;
-               u8                    mpa_frame_buf[MAX_CM_BUFFER];
+               struct ietf_mpa_v1 mpa_frame;
+               struct ietf_mpa_v2 mpa_v2_frame;
+               u8                 mpa_frame_buf[MAX_CM_BUFFER];
        };
+       enum mpa_frame_version    mpa_frame_rev;
+       u16                       ird_size;
+       u16                       ord_size;
+
        u16                       mpa_frame_size;
        struct iw_cm_id           *cm_id;
        struct list_head          list;
@@ -399,10 +440,8 @@ struct nes_cm_ops {
                        struct nes_vnic *, u16, void *,
                        struct nes_cm_info *);
        int (*close)(struct nes_cm_core *, struct nes_cm_node *);
-       int (*accept)(struct nes_cm_core *, struct ietf_mpa_frame *,
-                       struct nes_cm_node *);
-       int (*reject)(struct nes_cm_core *, struct ietf_mpa_frame *,
-                       struct nes_cm_node *);
+       int (*accept)(struct nes_cm_core *, struct nes_cm_node *);
+       int (*reject)(struct nes_cm_core *, struct nes_cm_node *);
        int (*recv_pkt)(struct nes_cm_core *, struct nes_vnic *,
                        struct sk_buff *);
        int (*destroy_cm_core)(struct nes_cm_core *);
@@ -422,5 +461,7 @@ int nes_destroy_listen(struct iw_cm_id *);
 int nes_cm_recv(struct sk_buff *, struct net_device *);
 int nes_cm_start(void);
 int nes_cm_stop(void);
+int nes_add_ref_cm_node(struct nes_cm_node *cm_node);
+int nes_rem_ref_cm_node(struct nes_cm_node *cm_node);
 
 #endif                 /* NES_CM_H */
index be36cbeae63078cabcd642816a79e56c5ca6c9ad..7c0ff19ce382d71db8f39e93e7697fdda0f56ce6 100644 (file)
@@ -110,6 +110,14 @@ static unsigned char *nes_tcp_state_str[] = {
 };
 #endif
 
+static inline void print_ip(struct nes_cm_node *cm_node)
+{
+       unsigned char *rem_addr;
+       if (cm_node) {
+               rem_addr = (unsigned char *)&cm_node->rem_addr;
+               printk(KERN_ERR PFX "Remote IP addr: %pI4\n", rem_addr);
+       }
+}
 
 /**
  * nes_nic_init_timer_defaults
@@ -1555,6 +1563,7 @@ static void nes_replenish_nic_rq(struct nes_vnic *nesvnic)
        struct nes_hw_nic_rq_wqe *nic_rqe;
        struct nes_hw_nic *nesnic;
        struct nes_device *nesdev;
+       struct nes_rskb_cb *cb;
        u32 rx_wqes_posted = 0;
 
        nesnic = &nesvnic->nic;
@@ -1580,6 +1589,9 @@ static void nes_replenish_nic_rq(struct nes_vnic *nesvnic)
 
                        bus_address = pci_map_single(nesdev->pcidev,
                                        skb->data, nesvnic->max_frame_size, PCI_DMA_FROMDEVICE);
+                       cb = (struct nes_rskb_cb *)&skb->cb[0];
+                       cb->busaddr = bus_address;
+                       cb->maplen = nesvnic->max_frame_size;
 
                        nic_rqe = &nesnic->rq_vbase[nesvnic->nic.rq_head];
                        nic_rqe->wqe_words[NES_NIC_RQ_WQE_LENGTH_1_0_IDX] =
@@ -1669,6 +1681,7 @@ int nes_init_nic_qp(struct nes_device *nesdev, struct net_device *netdev)
        u32 cqp_head;
        u32 counter;
        u32 wqe_count;
+       struct nes_rskb_cb *cb;
        u8 jumbomode=0;
 
        /* Allocate fragment, SQ, RQ, and CQ; Reuse CEQ based on the PCI function */
@@ -1845,6 +1858,9 @@ int nes_init_nic_qp(struct nes_device *nesdev, struct net_device *netdev)
 
                pmem = pci_map_single(nesdev->pcidev, skb->data,
                                nesvnic->max_frame_size, PCI_DMA_FROMDEVICE);
+               cb = (struct nes_rskb_cb *)&skb->cb[0];
+               cb->busaddr = pmem;
+               cb->maplen = nesvnic->max_frame_size;
 
                nic_rqe = &nesvnic->nic.rq_vbase[counter];
                nic_rqe->wqe_words[NES_NIC_RQ_WQE_LENGTH_1_0_IDX] = cpu_to_le32(nesvnic->max_frame_size);
@@ -1873,6 +1889,13 @@ int nes_init_nic_qp(struct nes_device *nesdev, struct net_device *netdev)
                        jumbomode = 1;
                nes_nic_init_timer_defaults(nesdev, jumbomode);
        }
+       if ((nesdev->nesadapter->allow_unaligned_fpdus) &&
+               (nes_init_mgt_qp(nesdev, netdev, nesvnic))) {
+                       nes_debug(NES_DBG_INIT, "%s: Out of memory for pau nic\n", netdev->name);
+                       nes_destroy_nic_qp(nesvnic);
+               return -ENOMEM;
+       }
+
        nesvnic->lro_mgr.max_aggr       = nes_lro_max_aggr;
        nesvnic->lro_mgr.max_desc       = NES_MAX_LRO_DESCRIPTORS;
        nesvnic->lro_mgr.lro_arr        = nesvnic->lro_desc;
@@ -1895,28 +1918,29 @@ void nes_destroy_nic_qp(struct nes_vnic *nesvnic)
        struct nes_device *nesdev = nesvnic->nesdev;
        struct nes_hw_cqp_wqe *cqp_wqe;
        struct nes_hw_nic_sq_wqe *nic_sqe;
-       struct nes_hw_nic_rq_wqe *nic_rqe;
        __le16 *wqe_fragment_length;
        u16  wqe_fragment_index;
-       u64 wqe_frag;
        u32 cqp_head;
        u32 wqm_cfg0;
        unsigned long flags;
+       struct sk_buff *rx_skb;
+       struct nes_rskb_cb *cb;
        int ret;
 
+       if (nesdev->nesadapter->allow_unaligned_fpdus)
+               nes_destroy_mgt(nesvnic);
+
        /* clear wqe stall before destroying NIC QP */
        wqm_cfg0 = nes_read_indexed(nesdev, NES_IDX_WQM_CONFIG0);
        nes_write_indexed(nesdev, NES_IDX_WQM_CONFIG0, wqm_cfg0 & 0xFFFF7FFF);
 
        /* Free remaining NIC receive buffers */
        while (nesvnic->nic.rq_head != nesvnic->nic.rq_tail) {
-               nic_rqe   = &nesvnic->nic.rq_vbase[nesvnic->nic.rq_tail];
-               wqe_frag  = (u64)le32_to_cpu(
-                       nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_LOW_IDX]);
-               wqe_frag |= ((u64)le32_to_cpu(
-                       nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX]))<<32;
-               pci_unmap_single(nesdev->pcidev, (dma_addr_t)wqe_frag,
-                               nesvnic->max_frame_size, PCI_DMA_FROMDEVICE);
+               rx_skb = nesvnic->nic.rx_skb[nesvnic->nic.rq_tail];
+               cb = (struct nes_rskb_cb *)&rx_skb->cb[0];
+               pci_unmap_single(nesdev->pcidev, cb->busaddr, cb->maplen,
+                       PCI_DMA_FROMDEVICE);
+
                dev_kfree_skb(nesvnic->nic.rx_skb[nesvnic->nic.rq_tail++]);
                nesvnic->nic.rq_tail &= (nesvnic->nic.rq_size - 1);
        }
@@ -2775,6 +2799,7 @@ void nes_nic_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *cq)
        struct nes_hw_nic_sq_wqe *nic_sqe;
        struct sk_buff *skb;
        struct sk_buff *rx_skb;
+       struct nes_rskb_cb *cb;
        __le16 *wqe_fragment_length;
        u32 head;
        u32 cq_size;
@@ -2859,6 +2884,8 @@ void nes_nic_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *cq)
                                bus_address += ((u64)le32_to_cpu(nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX])) << 32;
                                pci_unmap_single(nesdev->pcidev, bus_address,
                                                nesvnic->max_frame_size, PCI_DMA_FROMDEVICE);
+                               cb = (struct nes_rskb_cb *)&rx_skb->cb[0];
+                               cb->busaddr = 0;
                                /* rx_skb->tail = rx_skb->data + rx_pkt_size; */
                                /* rx_skb->len = rx_pkt_size; */
                                rx_skb->len = 0;  /* TODO: see if this is necessary */
@@ -2983,6 +3010,7 @@ skip_rx_indicate0:
 }
 
 
+
 /**
  * nes_cqp_ce_handler
  */
@@ -2997,6 +3025,8 @@ static void nes_cqp_ce_handler(struct nes_device *nesdev, struct nes_hw_cq *cq)
        u32 cq_size;
        u32 cqe_count=0;
        u32 error_code;
+       u32 opcode;
+       u32 ctx_index;
        /* u32 counter; */
 
        head = cq->cq_head;
@@ -3007,12 +3037,9 @@ static void nes_cqp_ce_handler(struct nes_device *nesdev, struct nes_hw_cq *cq)
                /* nes_debug(NES_DBG_CQP, "head=%u cqe_words=%08X\n", head,
                          le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_CQE_OPCODE_IDX])); */
 
-               if (le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_CQE_OPCODE_IDX]) & NES_CQE_VALID) {
-                       u64temp = (((u64)(le32_to_cpu(cq->cq_vbase[head].
-                                       cqe_words[NES_CQE_COMP_COMP_CTX_HIGH_IDX]))) << 32) |
-                                       ((u64)(le32_to_cpu(cq->cq_vbase[head].
-                                       cqe_words[NES_CQE_COMP_COMP_CTX_LOW_IDX])));
-                       cqp = *((struct nes_hw_cqp **)&u64temp);
+               opcode = le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_CQE_OPCODE_IDX]);
+               if (opcode & NES_CQE_VALID) {
+                       cqp = &nesdev->cqp;
 
                        error_code = le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_CQE_ERROR_CODE_IDX]);
                        if (error_code) {
@@ -3021,15 +3048,14 @@ static void nes_cqp_ce_handler(struct nes_device *nesdev, struct nes_hw_cq *cq)
                                                le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_CQE_OPCODE_IDX])&0x3f,
                                                (u16)(error_code >> 16),
                                                (u16)error_code);
-                               nes_debug(NES_DBG_CQP, "cqp: qp_id=%u, sq_head=%u, sq_tail=%u\n",
-                                               cqp->qp_id, cqp->sq_head, cqp->sq_tail);
                        }
 
-                       u64temp = (((u64)(le32_to_cpu(nesdev->cqp.sq_vbase[cqp->sq_tail].
-                                       wqe_words[NES_CQP_WQE_COMP_SCRATCH_HIGH_IDX]))) << 32) |
-                                       ((u64)(le32_to_cpu(nesdev->cqp.sq_vbase[cqp->sq_tail].
-                                       wqe_words[NES_CQP_WQE_COMP_SCRATCH_LOW_IDX])));
-                       cqp_request = *((struct nes_cqp_request **)&u64temp);
+                       u64temp = (((u64)(le32_to_cpu(cq->cq_vbase[head].
+                                       cqe_words[NES_CQE_COMP_COMP_CTX_HIGH_IDX]))) << 32) |
+                                       ((u64)(le32_to_cpu(cq->cq_vbase[head].
+                                       cqe_words[NES_CQE_COMP_COMP_CTX_LOW_IDX])));
+
+                       cqp_request = (struct nes_cqp_request *)(unsigned long)u64temp;
                        if (cqp_request) {
                                if (cqp_request->waiting) {
                                        /* nes_debug(NES_DBG_CQP, "%s: Waking up requestor\n"); */
@@ -3075,9 +3101,15 @@ static void nes_cqp_ce_handler(struct nes_device *nesdev, struct nes_hw_cq *cq)
                cqp_wqe = &nesdev->cqp.sq_vbase[head];
                memcpy(cqp_wqe, &cqp_request->cqp_wqe, sizeof(*cqp_wqe));
                barrier();
-               cqp_wqe->wqe_words[NES_CQP_WQE_COMP_SCRATCH_LOW_IDX] =
+
+               opcode = cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX];
+               if ((opcode & NES_CQP_OPCODE_MASK) == NES_CQP_DOWNLOAD_SEGMENT)
+                       ctx_index = NES_CQP_WQE_DL_COMP_CTX_LOW_IDX;
+               else
+                       ctx_index = NES_CQP_WQE_COMP_CTX_LOW_IDX;
+               cqp_wqe->wqe_words[ctx_index] =
                        cpu_to_le32((u32)((unsigned long)cqp_request));
-               cqp_wqe->wqe_words[NES_CQP_WQE_COMP_SCRATCH_HIGH_IDX] =
+               cqp_wqe->wqe_words[ctx_index + 1] =
                        cpu_to_le32((u32)(upper_32_bits((unsigned long)cqp_request)));
                nes_debug(NES_DBG_CQP, "CQP request %p (opcode 0x%02X) put on CQPs SQ wqe%u.\n",
                                cqp_request, le32_to_cpu(cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX])&0x3f, head);
@@ -3093,7 +3125,6 @@ static void nes_cqp_ce_handler(struct nes_device *nesdev, struct nes_hw_cq *cq)
        nes_read32(nesdev->regs+NES_CQE_ALLOC);
 }
 
-
 static u8 *locate_mpa(u8 *pkt, u32 aeq_info)
 {
        if (aeq_info & NES_AEQE_Q2_DATA_ETHERNET) {
@@ -3553,9 +3584,9 @@ static void nes_process_iwarp_aeqe(struct nes_device *nesdev,
 
        aeqe_cq_id = le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX]);
        if (aeq_info & NES_AEQE_QP) {
-               if ((!nes_is_resource_allocated(nesadapter, nesadapter->allocated_qps,
-                               aeqe_cq_id)) ||
-                               (atomic_read(&nesqp->close_timer_started)))
+               if (!nes_is_resource_allocated(nesadapter,
+                               nesadapter->allocated_qps,
+                               aeqe_cq_id))
                        return;
        }
 
@@ -3566,8 +3597,7 @@ static void nes_process_iwarp_aeqe(struct nes_device *nesdev,
 
                        if (atomic_inc_return(&nesqp->close_timer_started) == 1) {
                                if ((tcp_state == NES_AEQE_TCP_STATE_CLOSE_WAIT) &&
-                                       (nesqp->ibqp_state == IB_QPS_RTS) &&
-                                       ((nesadapter->eeprom_version >> 16) != NES_A0)) {
+                                       (nesqp->ibqp_state == IB_QPS_RTS)) {
                                        spin_lock_irqsave(&nesqp->lock, flags);
                                        nesqp->hw_iwarp_state = iwarp_state;
                                        nesqp->hw_tcp_state = tcp_state;
@@ -3594,9 +3624,10 @@ static void nes_process_iwarp_aeqe(struct nes_device *nesdev,
                                return;
                        }
                        spin_lock_irqsave(&nesqp->lock, flags);
-                       nesqp->hw_iwarp_state = NES_AEQE_IWARP_STATE_CLOSING;
+                       nesqp->hw_iwarp_state = iwarp_state;
+                       nesqp->hw_tcp_state = tcp_state;
+                       nesqp->last_aeq = async_event_id;
                        spin_unlock_irqrestore(&nesqp->lock, flags);
-                       nes_hw_modify_qp(nesdev, nesqp, NES_CQP_QP_IWARP_STATE_CLOSING, 0, 0);
                        nes_cm_disconn(nesqp);
                        break;
 
@@ -3694,7 +3725,9 @@ static void nes_process_iwarp_aeqe(struct nes_device *nesdev,
                case NES_AEQE_AEID_ROE_INVALID_RDMA_WRITE_OR_READ_RESP:
                        printk(KERN_ERR PFX "QP[%u] async_event_id=0x%04X IB_EVENT_QP_FATAL\n",
                                        nesqp->hwqp.qp_id, async_event_id);
-                       nes_terminate_connection(nesdev, nesqp, aeqe, IB_EVENT_QP_FATAL);
+                       print_ip(nesqp->cm_node);
+                       if (!atomic_read(&nesqp->close_timer_started))
+                               nes_terminate_connection(nesdev, nesqp, aeqe, IB_EVENT_QP_FATAL);
                        break;
 
                case NES_AEQE_AEID_CQ_OPERATION_ERROR:
index c3241479ec0e3c027d2e482b32ba87c9de42ca65..0b590e152c6abeeb84e78130a68d62ab742eca5f 100644 (file)
 #define NES_MULTICAST_PF_MAX 8
 #define NES_A0 3
 
+#define NES_ENABLE_PAU 0x07000001
+#define NES_DISABLE_PAU 0x07000000
+#define NES_PAU_COUNTER 10
+#define NES_CQP_OPCODE_MASK 0x3f
+
 enum pci_regs {
        NES_INT_STAT = 0x0000,
        NES_INT_MASK = 0x0004,
@@ -73,8 +78,10 @@ enum indexed_regs {
        NES_IDX_QP_CONTROL = 0x0040,
        NES_IDX_FLM_CONTROL = 0x0080,
        NES_IDX_INT_CPU_STATUS = 0x00a0,
+       NES_IDX_GPR_TRIGGER = 0x00bc,
        NES_IDX_GPIO_CONTROL = 0x00f0,
        NES_IDX_GPIO_DATA = 0x00f4,
+       NES_IDX_GPR2 = 0x010c,
        NES_IDX_TCP_CONFIG0 = 0x01e4,
        NES_IDX_TCP_TIMER_CONFIG = 0x01ec,
        NES_IDX_TCP_NOW = 0x01f0,
@@ -202,6 +209,7 @@ enum nes_cqp_opcodes {
        NES_CQP_REGISTER_SHARED_STAG = 0x0c,
        NES_CQP_DEALLOCATE_STAG = 0x0d,
        NES_CQP_MANAGE_ARP_CACHE = 0x0f,
+       NES_CQP_DOWNLOAD_SEGMENT = 0x10,
        NES_CQP_SUSPEND_QPS = 0x11,
        NES_CQP_UPLOAD_CONTEXT = 0x13,
        NES_CQP_CREATE_CEQ = 0x16,
@@ -210,7 +218,8 @@ enum nes_cqp_opcodes {
        NES_CQP_DESTROY_AEQ = 0x1b,
        NES_CQP_LMI_ACCESS = 0x20,
        NES_CQP_FLUSH_WQES = 0x22,
-       NES_CQP_MANAGE_APBVT = 0x23
+       NES_CQP_MANAGE_APBVT = 0x23,
+       NES_CQP_MANAGE_QUAD_HASH = 0x25
 };
 
 enum nes_cqp_wqe_word_idx {
@@ -222,6 +231,14 @@ enum nes_cqp_wqe_word_idx {
        NES_CQP_WQE_COMP_SCRATCH_HIGH_IDX = 5,
 };
 
+enum nes_cqp_wqe_word_download_idx { /* format differs from other cqp ops */
+       NES_CQP_WQE_DL_OPCODE_IDX = 0,
+       NES_CQP_WQE_DL_COMP_CTX_LOW_IDX = 1,
+       NES_CQP_WQE_DL_COMP_CTX_HIGH_IDX = 2,
+       NES_CQP_WQE_DL_LENGTH_0_TOTAL_IDX = 3
+       /* For index values 4-15 use NES_NIC_SQ_WQE_ values */
+};
+
 enum nes_cqp_cq_wqeword_idx {
        NES_CQP_CQ_WQE_PBL_LOW_IDX = 6,
        NES_CQP_CQ_WQE_PBL_HIGH_IDX = 7,
@@ -242,6 +259,7 @@ enum nes_cqp_stag_wqeword_idx {
        NES_CQP_STAG_WQE_PBL_LEN_IDX = 14
 };
 
+#define NES_CQP_OP_LOGICAL_PORT_SHIFT 26
 #define NES_CQP_OP_IWARP_STATE_SHIFT 28
 #define NES_CQP_OP_TERMLEN_SHIFT     28
 
@@ -599,6 +617,7 @@ enum nes_nic_sq_wqe_bits {
 
 enum nes_nic_cqe_word_idx {
        NES_NIC_CQE_ACCQP_ID_IDX = 0,
+       NES_NIC_CQE_HASH_RCVNXT = 1,
        NES_NIC_CQE_TAG_PKT_TYPE_IDX = 2,
        NES_NIC_CQE_MISC_IDX = 3,
 };
@@ -1005,6 +1024,11 @@ struct nes_arp_entry {
 #define NES_NIC_CQ_DOWNWARD_TREND   16
 #define NES_PFT_SIZE               48
 
+#define NES_MGT_WQ_COUNT 32
+#define NES_MGT_CTX_SIZE ((NES_NIC_CTX_RQ_SIZE_32) | (NES_NIC_CTX_SQ_SIZE_32))
+#define NES_MGT_QP_OFFSET 36
+#define NES_MGT_QP_COUNT 4
+
 struct nes_hw_tune_timer {
     /* u16 cq_count; */
     u16 threshold_low;
@@ -1118,6 +1142,7 @@ struct nes_adapter {
        u32 et_rate_sample_interval;
        u32 timer_int_limit;
        u32 wqm_quanta;
+       u8 allow_unaligned_fpdus;
 
        /* Adapter base MAC address */
        u32 mac_addr_low;
@@ -1251,6 +1276,14 @@ struct nes_vnic {
        enum ib_event_type delayed_event;
        enum ib_event_type last_dispatched_event;
        spinlock_t port_ibevent_lock;
+       u32 mgt_mem_size;
+       void *mgt_vbase;
+       dma_addr_t mgt_pbase;
+       struct nes_vnic_mgt *mgtvnic[NES_MGT_QP_COUNT];
+       struct task_struct *mgt_thread;
+       wait_queue_head_t mgt_wait_queue;
+       struct sk_buff_head mgt_skb_list;
+
 };
 
 struct nes_ib_device {
diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
new file mode 100644 (file)
index 0000000..b3b2a24
--- /dev/null
@@ -0,0 +1,1162 @@
+/*
+ * Copyright (c) 2006 - 2009 Intel-NE, Inc.  All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#include <linux/skbuff.h>
+#include <linux/etherdevice.h>
+#include <linux/kthread.h>
+#include <linux/ip.h>
+#include <linux/tcp.h>
+#include <net/tcp.h>
+#include "nes.h"
+#include "nes_mgt.h"
+
+atomic_t pau_qps_created;
+atomic_t pau_qps_destroyed;
+
+static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
+{
+       unsigned long flags;
+       dma_addr_t bus_address;
+       struct sk_buff *skb;
+       struct nes_hw_nic_rq_wqe *nic_rqe;
+       struct nes_hw_mgt *nesmgt;
+       struct nes_device *nesdev;
+       struct nes_rskb_cb *cb;
+       u32 rx_wqes_posted = 0;
+
+       nesmgt = &mgtvnic->mgt;
+       nesdev = mgtvnic->nesvnic->nesdev;
+       spin_lock_irqsave(&nesmgt->rq_lock, flags);
+       if (nesmgt->replenishing_rq != 0) {
+               if (((nesmgt->rq_size - 1) == atomic_read(&mgtvnic->rx_skbs_needed)) &&
+                   (atomic_read(&mgtvnic->rx_skb_timer_running) == 0)) {
+                       atomic_set(&mgtvnic->rx_skb_timer_running, 1);
+                       spin_unlock_irqrestore(&nesmgt->rq_lock, flags);
+                       mgtvnic->rq_wqes_timer.expires = jiffies + (HZ / 2);      /* 1/2 second */
+                       add_timer(&mgtvnic->rq_wqes_timer);
+               } else {
+                       spin_unlock_irqrestore(&nesmgt->rq_lock, flags);
+               }
+               return;
+       }
+       nesmgt->replenishing_rq = 1;
+       spin_unlock_irqrestore(&nesmgt->rq_lock, flags);
+       do {
+               skb = dev_alloc_skb(mgtvnic->nesvnic->max_frame_size);
+               if (skb) {
+                       skb->dev = mgtvnic->nesvnic->netdev;
+
+                       bus_address = pci_map_single(nesdev->pcidev,
+                                                    skb->data, mgtvnic->nesvnic->max_frame_size, PCI_DMA_FROMDEVICE);
+                       cb = (struct nes_rskb_cb *)&skb->cb[0];
+                       cb->busaddr = bus_address;
+                       cb->maplen = mgtvnic->nesvnic->max_frame_size;
+
+                       nic_rqe = &nesmgt->rq_vbase[mgtvnic->mgt.rq_head];
+                       nic_rqe->wqe_words[NES_NIC_RQ_WQE_LENGTH_1_0_IDX] =
+                               cpu_to_le32(mgtvnic->nesvnic->max_frame_size);
+                       nic_rqe->wqe_words[NES_NIC_RQ_WQE_LENGTH_3_2_IDX] = 0;
+                       nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_LOW_IDX] =
+                               cpu_to_le32((u32)bus_address);
+                       nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX] =
+                               cpu_to_le32((u32)((u64)bus_address >> 32));
+                       nesmgt->rx_skb[nesmgt->rq_head] = skb;
+                       nesmgt->rq_head++;
+                       nesmgt->rq_head &= nesmgt->rq_size - 1;
+                       atomic_dec(&mgtvnic->rx_skbs_needed);
+                       barrier();
+                       if (++rx_wqes_posted == 255) {
+                               nes_write32(nesdev->regs + NES_WQE_ALLOC, (rx_wqes_posted << 24) | nesmgt->qp_id);
+                               rx_wqes_posted = 0;
+                       }
+               } else {
+                       spin_lock_irqsave(&nesmgt->rq_lock, flags);
+                       if (((nesmgt->rq_size - 1) == atomic_read(&mgtvnic->rx_skbs_needed)) &&
+                           (atomic_read(&mgtvnic->rx_skb_timer_running) == 0)) {
+                               atomic_set(&mgtvnic->rx_skb_timer_running, 1);
+                               spin_unlock_irqrestore(&nesmgt->rq_lock, flags);
+                               mgtvnic->rq_wqes_timer.expires = jiffies + (HZ / 2);      /* 1/2 second */
+                               add_timer(&mgtvnic->rq_wqes_timer);
+                       } else {
+                               spin_unlock_irqrestore(&nesmgt->rq_lock, flags);
+                       }
+                       break;
+               }
+       } while (atomic_read(&mgtvnic->rx_skbs_needed));
+       barrier();
+       if (rx_wqes_posted)
+               nes_write32(nesdev->regs + NES_WQE_ALLOC, (rx_wqes_posted << 24) | nesmgt->qp_id);
+       nesmgt->replenishing_rq = 0;
+}
+
+/**
+ * nes_mgt_rq_wqes_timeout
+ */
+static void nes_mgt_rq_wqes_timeout(unsigned long parm)
+{
+       struct nes_vnic_mgt *mgtvnic = (struct nes_vnic_mgt *)parm;
+
+       atomic_set(&mgtvnic->rx_skb_timer_running, 0);
+       if (atomic_read(&mgtvnic->rx_skbs_needed))
+               nes_replenish_mgt_rq(mgtvnic);
+}
+
+/**
+ * nes_mgt_free_skb - unmap and free skb
+ */
+static void nes_mgt_free_skb(struct nes_device *nesdev, struct sk_buff *skb, u32 dir)
+{
+       struct nes_rskb_cb *cb;
+
+       cb = (struct nes_rskb_cb *)&skb->cb[0];
+       pci_unmap_single(nesdev->pcidev, cb->busaddr, cb->maplen, dir);
+       cb->busaddr = 0;
+       dev_kfree_skb_any(skb);
+}
+
+/**
+ * nes_download_callback - handle download completions
+ */
+static void nes_download_callback(struct nes_device *nesdev, struct nes_cqp_request *cqp_request)
+{
+       struct pau_fpdu_info *fpdu_info = cqp_request->cqp_callback_pointer;
+       struct nes_qp *nesqp = fpdu_info->nesqp;
+       struct sk_buff *skb;
+       int i;
+
+       for (i = 0; i < fpdu_info->frag_cnt; i++) {
+               skb = fpdu_info->frags[i].skb;
+               if (fpdu_info->frags[i].cmplt) {
+                       nes_mgt_free_skb(nesdev, skb, PCI_DMA_TODEVICE);
+                       nes_rem_ref_cm_node(nesqp->cm_node);
+               }
+       }
+
+       if (fpdu_info->hdr_vbase)
+               pci_free_consistent(nesdev->pcidev, fpdu_info->hdr_len,
+                                   fpdu_info->hdr_vbase, fpdu_info->hdr_pbase);
+       kfree(fpdu_info);
+}
+
+/**
+ * nes_get_seq - Get the seq, ack_seq and window from the packet
+ */
+static u32 nes_get_seq(struct sk_buff *skb, u32 *ack, u16 *wnd, u32 *fin_rcvd, u32 *rst_rcvd)
+{
+       struct nes_rskb_cb *cb = (struct nes_rskb_cb *)&skb->cb[0];
+       struct iphdr *iph = (struct iphdr *)(cb->data_start + ETH_HLEN);
+       struct tcphdr *tcph = (struct tcphdr *)(((char *)iph) + (4 * iph->ihl));
+
+       *ack = be32_to_cpu(tcph->ack_seq);
+       *wnd = be16_to_cpu(tcph->window);
+       *fin_rcvd = tcph->fin;
+       *rst_rcvd = tcph->rst;
+       return be32_to_cpu(tcph->seq);
+}
+
+/**
+ * nes_get_next_skb - Get the next skb based on where current skb is in the queue
+ */
+static struct sk_buff *nes_get_next_skb(struct nes_device *nesdev, struct nes_qp *nesqp,
+                                       struct sk_buff *skb, u32 nextseq, u32 *ack,
+                                       u16 *wnd, u32 *fin_rcvd, u32 *rst_rcvd)
+{
+       u32 seq;
+       bool processacks;
+       struct sk_buff *old_skb;
+
+       if (skb) {
+               /* Continue processing fpdu */
+               if (skb->next == (struct sk_buff *)&nesqp->pau_list)
+                       goto out;
+               skb = skb->next;
+               processacks = false;
+       } else {
+               /* Starting a new one */
+               if (skb_queue_empty(&nesqp->pau_list))
+                       goto out;
+               skb = skb_peek(&nesqp->pau_list);
+               processacks = true;
+       }
+
+       while (1) {
+               seq = nes_get_seq(skb, ack, wnd, fin_rcvd, rst_rcvd);
+               if (seq == nextseq) {
+                       if (skb->len || processacks)
+                               break;
+               } else if (after(seq, nextseq)) {
+                       goto out;
+               }
+
+               if (skb->next == (struct sk_buff *)&nesqp->pau_list)
+                       goto out;
+
+               old_skb = skb;
+               skb = skb->next;
+               skb_unlink(old_skb, &nesqp->pau_list);
+               nes_mgt_free_skb(nesdev, old_skb, PCI_DMA_TODEVICE);
+               nes_rem_ref_cm_node(nesqp->cm_node);
+       }
+       return skb;
+
+out:
+       return NULL;
+}
+
+/**
+ * get_fpdu_info - Find the next complete fpdu and return its fragments.
+ */
+static int get_fpdu_info(struct nes_device *nesdev, struct nes_qp *nesqp,
+                        struct pau_fpdu_info **pau_fpdu_info)
+{
+       struct sk_buff *skb;
+       struct iphdr *iph;
+       struct tcphdr *tcph;
+       struct nes_rskb_cb *cb;
+       struct pau_fpdu_info *fpdu_info = NULL;
+       struct pau_fpdu_frag frags[MAX_FPDU_FRAGS];
+       unsigned long flags;
+       u32 fpdu_len = 0;
+       u32 tmp_len;
+       int frag_cnt = 0;
+       u32 tot_len;
+       u32 frag_tot;
+       u32 ack;
+       u32 fin_rcvd;
+       u32 rst_rcvd;
+       u16 wnd;
+       int i;
+       int rc = 0;
+
+       *pau_fpdu_info = NULL;
+
+       spin_lock_irqsave(&nesqp->pau_lock, flags);
+       skb = nes_get_next_skb(nesdev, nesqp, NULL, nesqp->pau_rcv_nxt, &ack, &wnd, &fin_rcvd, &rst_rcvd);
+       if (!skb) {
+               spin_unlock_irqrestore(&nesqp->pau_lock, flags);
+               goto out;
+       }
+       cb = (struct nes_rskb_cb *)&skb->cb[0];
+       if (skb->len) {
+               fpdu_len = be16_to_cpu(*(__be16 *) skb->data) + MPA_FRAMING;
+               fpdu_len = (fpdu_len + 3) & 0xfffffffc;
+               tmp_len = fpdu_len;
+
+               /* See if we have all of the fpdu */
+               frag_tot = 0;
+               memset(&frags, 0, sizeof frags);
+               for (i = 0; i < MAX_FPDU_FRAGS; i++) {
+                       frags[i].physaddr = cb->busaddr;
+                       frags[i].physaddr += skb->data - cb->data_start;
+                       frags[i].frag_len = min(tmp_len, skb->len);
+                       frags[i].skb = skb;
+                       frags[i].cmplt = (skb->len == frags[i].frag_len);
+                       frag_tot += frags[i].frag_len;
+                       frag_cnt++;
+
+                       tmp_len -= frags[i].frag_len;
+                       if (tmp_len == 0)
+                               break;
+
+                       skb = nes_get_next_skb(nesdev, nesqp, skb,
+                                              nesqp->pau_rcv_nxt + frag_tot, &ack, &wnd, &fin_rcvd, &rst_rcvd);
+                       if (!skb) {
+                               spin_unlock_irqrestore(&nesqp->pau_lock, flags);
+                               goto out;
+                       } else if (rst_rcvd) {
+                               /* rst received in the middle of fpdu */
+                               for (; i >= 0; i--) {
+                                       skb_unlink(frags[i].skb, &nesqp->pau_list);
+                                       nes_mgt_free_skb(nesdev, frags[i].skb, PCI_DMA_TODEVICE);
+                               }
+                               cb = (struct nes_rskb_cb *)&skb->cb[0];
+                               frags[0].physaddr = cb->busaddr;
+                               frags[0].physaddr += skb->data - cb->data_start;
+                               frags[0].frag_len = skb->len;
+                               frags[0].skb = skb;
+                               frags[0].cmplt = true;
+                               frag_cnt = 1;
+                               break;
+                       }
+
+                       cb = (struct nes_rskb_cb *)&skb->cb[0];
+               }
+       } else {
+               /* no data */
+               frags[0].physaddr = cb->busaddr;
+               frags[0].frag_len = 0;
+               frags[0].skb = skb;
+               frags[0].cmplt = true;
+               frag_cnt = 1;
+       }
+
+       spin_unlock_irqrestore(&nesqp->pau_lock, flags);
+
+       /* Found one */
+       fpdu_info = kzalloc(sizeof(*fpdu_info), GFP_ATOMIC);
+       if (fpdu_info == NULL) {
+               nes_debug(NES_DBG_PAU, "Failed to alloc a fpdu_info.\n");
+               rc = -ENOMEM;
+               goto out;
+       }
+
+       fpdu_info->cqp_request = nes_get_cqp_request(nesdev);
+       if (fpdu_info->cqp_request == NULL) {
+               nes_debug(NES_DBG_PAU, "Failed to get a cqp_request.\n");
+               rc = -ENOMEM;
+               goto out;
+       }
+
+       cb = (struct nes_rskb_cb *)&frags[0].skb->cb[0];
+       iph = (struct iphdr *)(cb->data_start + ETH_HLEN);
+       tcph = (struct tcphdr *)(((char *)iph) + (4 * iph->ihl));
+       fpdu_info->hdr_len = (((unsigned char *)tcph) + 4 * (tcph->doff)) - cb->data_start;
+       fpdu_info->data_len = fpdu_len;
+       tot_len = fpdu_info->hdr_len + fpdu_len - ETH_HLEN;
+
+       if (frags[0].cmplt) {
+               fpdu_info->hdr_pbase = cb->busaddr;
+               fpdu_info->hdr_vbase = NULL;
+       } else {
+               fpdu_info->hdr_vbase = pci_alloc_consistent(nesdev->pcidev,
+                                                           fpdu_info->hdr_len, &fpdu_info->hdr_pbase);
+               if (!fpdu_info->hdr_vbase) {
+                       nes_debug(NES_DBG_PAU, "Unable to allocate memory for pau first frag\n");
+                       rc = -ENOMEM;
+                       goto out;
+               }
+
+               /* Copy hdrs, adjusting len and seqnum */
+               memcpy(fpdu_info->hdr_vbase, cb->data_start, fpdu_info->hdr_len);
+               iph = (struct iphdr *)(fpdu_info->hdr_vbase + ETH_HLEN);
+               tcph = (struct tcphdr *)(((char *)iph) + (4 * iph->ihl));
+       }
+
+       iph->tot_len = cpu_to_be16(tot_len);
+       iph->saddr = cpu_to_be32(0x7f000001);
+
+       tcph->seq = cpu_to_be32(nesqp->pau_rcv_nxt);
+       tcph->ack_seq = cpu_to_be32(ack);
+       tcph->window = cpu_to_be16(wnd);
+
+       nesqp->pau_rcv_nxt += fpdu_len + fin_rcvd;
+
+       memcpy(fpdu_info->frags, frags, sizeof(fpdu_info->frags));
+       fpdu_info->frag_cnt = frag_cnt;
+       fpdu_info->nesqp = nesqp;
+       *pau_fpdu_info = fpdu_info;
+
+       /* Update skb's for next pass */
+       for (i = 0; i < frag_cnt; i++) {
+               cb = (struct nes_rskb_cb *)&frags[i].skb->cb[0];
+               skb_pull(frags[i].skb, frags[i].frag_len);
+
+               if (frags[i].skb->len == 0) {
+                       /* Pull skb off the list - it will be freed in the callback */
+                       spin_lock_irqsave(&nesqp->pau_lock, flags);
+                       skb_unlink(frags[i].skb, &nesqp->pau_list);
+                       spin_unlock_irqrestore(&nesqp->pau_lock, flags);
+               } else {
+                       /* Last skb still has data so update the seq */
+                       iph = (struct iphdr *)(cb->data_start + ETH_HLEN);
+                       tcph = (struct tcphdr *)(((char *)iph) + (4 * iph->ihl));
+                       tcph->seq = cpu_to_be32(nesqp->pau_rcv_nxt);
+               }
+       }
+
+out:
+       if (rc) {
+               if (fpdu_info) {
+                       if (fpdu_info->cqp_request)
+                               nes_put_cqp_request(nesdev, fpdu_info->cqp_request);
+                       kfree(fpdu_info);
+               }
+       }
+       return rc;
+}
+
+/**
+ * forward_fpdu - send complete fpdus, one at a time
+ */
+static int forward_fpdus(struct nes_vnic *nesvnic, struct nes_qp *nesqp)
+{
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct pau_fpdu_info *fpdu_info;
+       struct nes_hw_cqp_wqe *cqp_wqe;
+       struct nes_cqp_request *cqp_request;
+       u64 u64tmp;
+       u32 u32tmp;
+       int rc;
+
+       while (1) {
+               rc = get_fpdu_info(nesdev, nesqp, &fpdu_info);
+               if (fpdu_info == NULL)
+                       return rc;
+
+               cqp_request = fpdu_info->cqp_request;
+               cqp_wqe = &cqp_request->cqp_wqe;
+               nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
+               set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_DL_OPCODE_IDX,
+                                   NES_CQP_DOWNLOAD_SEGMENT |
+                                   (((u32)nesvnic->logical_port) << NES_CQP_OP_LOGICAL_PORT_SHIFT));
+
+               u32tmp = fpdu_info->hdr_len << 16;
+               u32tmp |= fpdu_info->hdr_len + (u32)fpdu_info->data_len;
+               set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_DL_LENGTH_0_TOTAL_IDX,
+                                   u32tmp);
+
+               u32tmp = (fpdu_info->frags[1].frag_len << 16) | fpdu_info->frags[0].frag_len;
+               set_wqe_32bit_value(cqp_wqe->wqe_words, NES_NIC_SQ_WQE_LENGTH_2_1_IDX,
+                                   u32tmp);
+
+               u32tmp = (fpdu_info->frags[3].frag_len << 16) | fpdu_info->frags[2].frag_len;
+               set_wqe_32bit_value(cqp_wqe->wqe_words, NES_NIC_SQ_WQE_LENGTH_4_3_IDX,
+                                   u32tmp);
+
+               u64tmp = (u64)fpdu_info->hdr_pbase;
+               set_wqe_32bit_value(cqp_wqe->wqe_words, NES_NIC_SQ_WQE_FRAG0_LOW_IDX,
+                                   lower_32_bits(u64tmp));
+               set_wqe_32bit_value(cqp_wqe->wqe_words, NES_NIC_SQ_WQE_FRAG0_HIGH_IDX,
+                                   upper_32_bits(u64tmp >> 32));
+
+               set_wqe_32bit_value(cqp_wqe->wqe_words, NES_NIC_SQ_WQE_FRAG1_LOW_IDX,
+                                   lower_32_bits(fpdu_info->frags[0].physaddr));
+               set_wqe_32bit_value(cqp_wqe->wqe_words, NES_NIC_SQ_WQE_FRAG1_HIGH_IDX,
+                                   upper_32_bits(fpdu_info->frags[0].physaddr));
+
+               set_wqe_32bit_value(cqp_wqe->wqe_words, NES_NIC_SQ_WQE_FRAG2_LOW_IDX,
+                                   lower_32_bits(fpdu_info->frags[1].physaddr));
+               set_wqe_32bit_value(cqp_wqe->wqe_words, NES_NIC_SQ_WQE_FRAG2_HIGH_IDX,
+                                   upper_32_bits(fpdu_info->frags[1].physaddr));
+
+               set_wqe_32bit_value(cqp_wqe->wqe_words, NES_NIC_SQ_WQE_FRAG3_LOW_IDX,
+                                   lower_32_bits(fpdu_info->frags[2].physaddr));
+               set_wqe_32bit_value(cqp_wqe->wqe_words, NES_NIC_SQ_WQE_FRAG3_HIGH_IDX,
+                                   upper_32_bits(fpdu_info->frags[2].physaddr));
+
+               set_wqe_32bit_value(cqp_wqe->wqe_words, NES_NIC_SQ_WQE_FRAG4_LOW_IDX,
+                                   lower_32_bits(fpdu_info->frags[3].physaddr));
+               set_wqe_32bit_value(cqp_wqe->wqe_words, NES_NIC_SQ_WQE_FRAG4_HIGH_IDX,
+                                   upper_32_bits(fpdu_info->frags[3].physaddr));
+
+               cqp_request->cqp_callback_pointer = fpdu_info;
+               cqp_request->callback = 1;
+               cqp_request->cqp_callback = nes_download_callback;
+
+               atomic_set(&cqp_request->refcount, 1);
+               nes_post_cqp_request(nesdev, cqp_request);
+       }
+
+       return 0;
+}
+
+static void process_fpdus(struct nes_vnic *nesvnic, struct nes_qp *nesqp)
+{
+       int again = 1;
+       unsigned long flags;
+
+       do {
+               /* Ignore rc - if it failed, tcp retries will cause it to try again */
+               forward_fpdus(nesvnic, nesqp);
+
+               spin_lock_irqsave(&nesqp->pau_lock, flags);
+               if (nesqp->pau_pending) {
+                       nesqp->pau_pending = 0;
+               } else {
+                       nesqp->pau_busy = 0;
+                       again = 0;
+               }
+
+               spin_unlock_irqrestore(&nesqp->pau_lock, flags);
+       } while (again);
+}
+
+/**
+ * queue_fpdus - Handle fpdu's that hw passed up to sw
+ */
+static void queue_fpdus(struct sk_buff *skb, struct nes_vnic *nesvnic, struct nes_qp *nesqp)
+{
+       struct sk_buff *tmpskb;
+       struct nes_rskb_cb *cb;
+       struct iphdr *iph;
+       struct tcphdr *tcph;
+       unsigned char *tcph_end;
+       u32 rcv_nxt;
+       u32 rcv_wnd;
+       u32 seqnum;
+       u32 len;
+       bool process_it = false;
+       unsigned long flags;
+
+       /* Move data ptr to after tcp header */
+       iph = (struct iphdr *)skb->data;
+       tcph = (struct tcphdr *)(((char *)iph) + (4 * iph->ihl));
+       seqnum = be32_to_cpu(tcph->seq);
+       tcph_end = (((char *)tcph) + (4 * tcph->doff));
+
+       len = be16_to_cpu(iph->tot_len);
+       if (skb->len > len)
+               skb_trim(skb, len);
+       skb_pull(skb, tcph_end - skb->data);
+
+       /* Initialize tracking values */
+       cb = (struct nes_rskb_cb *)&skb->cb[0];
+       cb->seqnum = seqnum;
+
+       /* Make sure data is in the receive window */
+       rcv_nxt = nesqp->pau_rcv_nxt;
+       rcv_wnd = le32_to_cpu(nesqp->nesqp_context->rcv_wnd);
+       if (!between(seqnum, rcv_nxt, (rcv_nxt + rcv_wnd))) {
+               nes_mgt_free_skb(nesvnic->nesdev, skb, PCI_DMA_TODEVICE);
+               nes_rem_ref_cm_node(nesqp->cm_node);
+               return;
+       }
+
+       spin_lock_irqsave(&nesqp->pau_lock, flags);
+
+       if (nesqp->pau_busy)
+               nesqp->pau_pending = 1;
+       else
+               nesqp->pau_busy = 1;
+
+       /* Queue skb by sequence number */
+       if (skb_queue_len(&nesqp->pau_list) == 0) {
+               skb_queue_head(&nesqp->pau_list, skb);
+       } else {
+               tmpskb = nesqp->pau_list.next;
+               while (tmpskb != (struct sk_buff *)&nesqp->pau_list) {
+                       cb = (struct nes_rskb_cb *)&tmpskb->cb[0];
+                       if (before(seqnum, cb->seqnum))
+                               break;
+                       tmpskb = tmpskb->next;
+               }
+               skb_insert(tmpskb, skb, &nesqp->pau_list);
+       }
+       if (nesqp->pau_state == PAU_READY)
+               process_it = true;
+       spin_unlock_irqrestore(&nesqp->pau_lock, flags);
+
+       if (process_it)
+               process_fpdus(nesvnic, nesqp);
+
+       return;
+}
+
+/**
+ * mgt_thread - Handle mgt skbs in a safe context
+ */
+static int mgt_thread(void *context)
+{
+       struct nes_vnic *nesvnic = context;
+       struct sk_buff *skb;
+       struct nes_rskb_cb *cb;
+
+       while (!kthread_should_stop()) {
+               wait_event_interruptible(nesvnic->mgt_wait_queue,
+                                        skb_queue_len(&nesvnic->mgt_skb_list) || kthread_should_stop());
+               while ((skb_queue_len(&nesvnic->mgt_skb_list)) && !kthread_should_stop()) {
+                       skb = skb_dequeue(&nesvnic->mgt_skb_list);
+                       cb = (struct nes_rskb_cb *)&skb->cb[0];
+                       cb->data_start = skb->data - ETH_HLEN;
+                       cb->busaddr = pci_map_single(nesvnic->nesdev->pcidev, cb->data_start,
+                                                    nesvnic->max_frame_size, PCI_DMA_TODEVICE);
+                       queue_fpdus(skb, nesvnic, cb->nesqp);
+               }
+       }
+
+       /* Closing down so delete any entries on the queue */
+       while (skb_queue_len(&nesvnic->mgt_skb_list)) {
+               skb = skb_dequeue(&nesvnic->mgt_skb_list);
+               cb = (struct nes_rskb_cb *)&skb->cb[0];
+               nes_rem_ref_cm_node(cb->nesqp->cm_node);
+               dev_kfree_skb_any(skb);
+       }
+       return 0;
+}
+
+/**
+ * nes_queue_skbs - Queue skb so it can be handled in a thread context
+ */
+void nes_queue_mgt_skbs(struct sk_buff *skb, struct nes_vnic *nesvnic, struct nes_qp *nesqp)
+{
+       struct nes_rskb_cb *cb;
+
+       cb = (struct nes_rskb_cb *)&skb->cb[0];
+       cb->nesqp = nesqp;
+       skb_queue_tail(&nesvnic->mgt_skb_list, skb);
+       wake_up_interruptible(&nesvnic->mgt_wait_queue);
+}
+
+void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
+{
+       struct sk_buff *skb;
+       unsigned long flags;
+       atomic_inc(&pau_qps_destroyed);
+
+       /* Free packets that have not yet been forwarded */
+       /* Lock is acquired by skb_dequeue when removing the skb */
+       spin_lock_irqsave(&nesqp->pau_lock, flags);
+       while (skb_queue_len(&nesqp->pau_list)) {
+               skb = skb_dequeue(&nesqp->pau_list);
+               nes_mgt_free_skb(nesdev, skb, PCI_DMA_TODEVICE);
+               nes_rem_ref_cm_node(nesqp->cm_node);
+       }
+       spin_unlock_irqrestore(&nesqp->pau_lock, flags);
+}
+
+static void nes_chg_qh_handler(struct nes_device *nesdev, struct nes_cqp_request *cqp_request)
+{
+       struct pau_qh_chg *qh_chg = cqp_request->cqp_callback_pointer;
+       struct nes_cqp_request *new_request;
+       struct nes_hw_cqp_wqe *cqp_wqe;
+       struct nes_adapter *nesadapter;
+       struct nes_qp *nesqp;
+       struct nes_v4_quad nes_quad;
+       u32 crc_value;
+       u64 u64temp;
+
+       nesadapter = nesdev->nesadapter;
+       nesqp = qh_chg->nesqp;
+
+       /* Should we handle the bad completion */
+       if (cqp_request->major_code) {
+               printk(KERN_ERR PFX "Invalid cqp_request major_code=0x%x\n",
+                      cqp_request->major_code);
+               WARN_ON(1);
+       }
+
+       switch (nesqp->pau_state) {
+       case PAU_DEL_QH:
+               /* Old hash code deleted, now set the new one */
+               nesqp->pau_state = PAU_ADD_LB_QH;
+               new_request = nes_get_cqp_request(nesdev);
+               if (new_request == NULL) {
+                       nes_debug(NES_DBG_PAU, "Failed to get a new_request.\n");
+                       WARN_ON(1);
+                       return;
+               }
+
+               memset(&nes_quad, 0, sizeof(nes_quad));
+               nes_quad.DstIpAdrIndex =
+                       cpu_to_le32((u32)PCI_FUNC(nesdev->pcidev->devfn) << 24);
+               nes_quad.SrcIpadr = cpu_to_be32(0x7f000001);
+               nes_quad.TcpPorts[0] = swab16(nesqp->nesqp_context->tcpPorts[1]);
+               nes_quad.TcpPorts[1] = swab16(nesqp->nesqp_context->tcpPorts[0]);
+
+               /* Produce hash key */
+               crc_value = get_crc_value(&nes_quad);
+               nesqp->hte_index = cpu_to_be32(crc_value ^ 0xffffffff);
+               nes_debug(NES_DBG_PAU, "new HTE Index = 0x%08X, CRC = 0x%08X\n",
+                         nesqp->hte_index, nesqp->hte_index & nesadapter->hte_index_mask);
+
+               nesqp->hte_index &= nesadapter->hte_index_mask;
+               nesqp->nesqp_context->hte_index = cpu_to_le32(nesqp->hte_index);
+               nesqp->nesqp_context->ip0 = cpu_to_le32(0x7f000001);
+               nesqp->nesqp_context->rcv_nxt = cpu_to_le32(nesqp->pau_rcv_nxt);
+
+               cqp_wqe = &new_request->cqp_wqe;
+               nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
+               set_wqe_32bit_value(cqp_wqe->wqe_words,
+                                   NES_CQP_WQE_OPCODE_IDX, NES_CQP_MANAGE_QUAD_HASH |
+                                   NES_CQP_QP_TYPE_IWARP | NES_CQP_QP_CONTEXT_VALID | NES_CQP_QP_IWARP_STATE_RTS);
+               set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX, nesqp->hwqp.qp_id);
+               u64temp = (u64)nesqp->nesqp_context_pbase;
+               set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_QP_WQE_CONTEXT_LOW_IDX, u64temp);
+
+               nes_debug(NES_DBG_PAU, "Waiting for CQP completion for adding the quad hash.\n");
+
+               new_request->cqp_callback_pointer = qh_chg;
+               new_request->callback = 1;
+               new_request->cqp_callback = nes_chg_qh_handler;
+               atomic_set(&new_request->refcount, 1);
+               nes_post_cqp_request(nesdev, new_request);
+               break;
+
+       case PAU_ADD_LB_QH:
+               /* Start processing the queued fpdu's */
+               nesqp->pau_state = PAU_READY;
+               process_fpdus(qh_chg->nesvnic, qh_chg->nesqp);
+               kfree(qh_chg);
+               break;
+       }
+}
+
+/**
+ * nes_change_quad_hash
+ */
+static int nes_change_quad_hash(struct nes_device *nesdev,
+                               struct nes_vnic *nesvnic, struct nes_qp *nesqp)
+{
+       struct nes_cqp_request *cqp_request = NULL;
+       struct pau_qh_chg *qh_chg = NULL;
+       u64 u64temp;
+       struct nes_hw_cqp_wqe *cqp_wqe;
+       int ret = 0;
+
+       cqp_request = nes_get_cqp_request(nesdev);
+       if (cqp_request == NULL) {
+               nes_debug(NES_DBG_PAU, "Failed to get a cqp_request.\n");
+               ret = -ENOMEM;
+               goto chg_qh_err;
+       }
+
+       qh_chg = kmalloc(sizeof *qh_chg, GFP_ATOMIC);
+       if (qh_chg == NULL) {
+               nes_debug(NES_DBG_PAU, "Failed to get a cqp_request.\n");
+               ret = -ENOMEM;
+               goto chg_qh_err;
+       }
+       qh_chg->nesdev = nesdev;
+       qh_chg->nesvnic = nesvnic;
+       qh_chg->nesqp = nesqp;
+       nesqp->pau_state = PAU_DEL_QH;
+
+       cqp_wqe = &cqp_request->cqp_wqe;
+       nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
+       set_wqe_32bit_value(cqp_wqe->wqe_words,
+                           NES_CQP_WQE_OPCODE_IDX, NES_CQP_MANAGE_QUAD_HASH | NES_CQP_QP_DEL_HTE |
+                           NES_CQP_QP_TYPE_IWARP | NES_CQP_QP_CONTEXT_VALID | NES_CQP_QP_IWARP_STATE_RTS);
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX, nesqp->hwqp.qp_id);
+       u64temp = (u64)nesqp->nesqp_context_pbase;
+       set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_QP_WQE_CONTEXT_LOW_IDX, u64temp);
+
+       nes_debug(NES_DBG_PAU, "Waiting for CQP completion for deleting the quad hash.\n");
+
+       cqp_request->cqp_callback_pointer = qh_chg;
+       cqp_request->callback = 1;
+       cqp_request->cqp_callback = nes_chg_qh_handler;
+       atomic_set(&cqp_request->refcount, 1);
+       nes_post_cqp_request(nesdev, cqp_request);
+
+       return ret;
+
+chg_qh_err:
+       kfree(qh_chg);
+       if (cqp_request)
+               nes_put_cqp_request(nesdev, cqp_request);
+       return ret;
+}
+
+/**
+ * nes_mgt_ce_handler
+ * This management code deals with any packed and unaligned (pau) fpdu's
+ * that the hardware cannot handle.
+ */
+static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *cq)
+{
+       struct nes_vnic_mgt *mgtvnic = container_of(cq, struct nes_vnic_mgt, mgt_cq);
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       u32 head;
+       u32 cq_size;
+       u32 cqe_count = 0;
+       u32 cqe_misc;
+       u32 qp_id = 0;
+       u32 skbs_needed;
+       unsigned long context;
+       struct nes_qp *nesqp;
+       struct sk_buff *rx_skb;
+       struct nes_rskb_cb *cb;
+
+       head = cq->cq_head;
+       cq_size = cq->cq_size;
+
+       while (1) {
+               cqe_misc = le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_NIC_CQE_MISC_IDX]);
+               if (!(cqe_misc & NES_NIC_CQE_VALID))
+                       break;
+
+               nesqp = NULL;
+               if (cqe_misc & NES_NIC_CQE_ACCQP_VALID) {
+                       qp_id = le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_NIC_CQE_ACCQP_ID_IDX]);
+                       qp_id &= 0x001fffff;
+                       if (qp_id < nesadapter->max_qp) {
+                               context = (unsigned long)nesadapter->qp_table[qp_id - NES_FIRST_QPN];
+                               nesqp = (struct nes_qp *)context;
+                       }
+               }
+
+               if (nesqp) {
+                       if (nesqp->pau_mode == false) {
+                               nesqp->pau_mode = true; /* First time for this qp */
+                               nesqp->pau_rcv_nxt = le32_to_cpu(
+                                       cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
+                               skb_queue_head_init(&nesqp->pau_list);
+                               spin_lock_init(&nesqp->pau_lock);
+                               atomic_inc(&pau_qps_created);
+                               nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
+                       }
+
+                       rx_skb = mgtvnic->mgt.rx_skb[mgtvnic->mgt.rq_tail];
+                       rx_skb->len = 0;
+                       skb_put(rx_skb, cqe_misc & 0x0000ffff);
+                       rx_skb->protocol = eth_type_trans(rx_skb, mgtvnic->nesvnic->netdev);
+                       cb = (struct nes_rskb_cb *)&rx_skb->cb[0];
+                       pci_unmap_single(nesdev->pcidev, cb->busaddr, cb->maplen, PCI_DMA_FROMDEVICE);
+                       cb->busaddr = 0;
+                       mgtvnic->mgt.rq_tail++;
+                       mgtvnic->mgt.rq_tail &= mgtvnic->mgt.rq_size - 1;
+
+                       nes_add_ref_cm_node(nesqp->cm_node);
+                       nes_queue_mgt_skbs(rx_skb, mgtvnic->nesvnic, nesqp);
+               } else {
+                       printk(KERN_ERR PFX "Invalid QP %d for packed/unaligned handling\n", qp_id);
+               }
+
+               cq->cq_vbase[head].cqe_words[NES_NIC_CQE_MISC_IDX] = 0;
+               cqe_count++;
+               if (++head >= cq_size)
+                       head = 0;
+
+               if (cqe_count == 255) {
+                       /* Replenish mgt CQ */
+                       nes_write32(nesdev->regs + NES_CQE_ALLOC, cq->cq_number | (cqe_count << 16));
+                       nesdev->currcq_count += cqe_count;
+                       cqe_count = 0;
+               }
+
+               skbs_needed = atomic_inc_return(&mgtvnic->rx_skbs_needed);
+               if (skbs_needed > (mgtvnic->mgt.rq_size >> 1))
+                       nes_replenish_mgt_rq(mgtvnic);
+       }
+
+       cq->cq_head = head;
+       nes_write32(nesdev->regs + NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT |
+                   cq->cq_number | (cqe_count << 16));
+       nes_read32(nesdev->regs + NES_CQE_ALLOC);
+       nesdev->currcq_count += cqe_count;
+}
+
+/**
+ * nes_init_mgt_qp
+ */
+int nes_init_mgt_qp(struct nes_device *nesdev, struct net_device *netdev, struct nes_vnic *nesvnic)
+{
+       struct nes_vnic_mgt *mgtvnic;
+       u32 counter;
+       void *vmem;
+       dma_addr_t pmem;
+       struct nes_hw_cqp_wqe *cqp_wqe;
+       u32 cqp_head;
+       unsigned long flags;
+       struct nes_hw_nic_qp_context *mgt_context;
+       u64 u64temp;
+       struct nes_hw_nic_rq_wqe *mgt_rqe;
+       struct sk_buff *skb;
+       u32 wqe_count;
+       struct nes_rskb_cb *cb;
+       u32 mgt_mem_size;
+       void *mgt_vbase;
+       dma_addr_t mgt_pbase;
+       int i;
+       int ret;
+
+       /* Allocate space the all mgt QPs once */
+       mgtvnic = kzalloc(NES_MGT_QP_COUNT * sizeof(struct nes_vnic_mgt), GFP_KERNEL);
+       if (mgtvnic == NULL) {
+               nes_debug(NES_DBG_INIT, "Unable to allocate memory for mgt structure\n");
+               return -ENOMEM;
+       }
+
+       /* Allocate fragment, RQ, and CQ; Reuse CEQ based on the PCI function */
+       /* We are not sending from this NIC so sq is not allocated */
+       mgt_mem_size = 256 +
+                      (NES_MGT_WQ_COUNT * sizeof(struct nes_hw_nic_rq_wqe)) +
+                      (NES_MGT_WQ_COUNT * sizeof(struct nes_hw_nic_cqe)) +
+                      sizeof(struct nes_hw_nic_qp_context);
+       mgt_mem_size = (mgt_mem_size + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
+       mgt_vbase = pci_alloc_consistent(nesdev->pcidev, NES_MGT_QP_COUNT * mgt_mem_size, &mgt_pbase);
+       if (!mgt_vbase) {
+               kfree(mgtvnic);
+               nes_debug(NES_DBG_INIT, "Unable to allocate memory for mgt host descriptor rings\n");
+               return -ENOMEM;
+       }
+
+       nesvnic->mgt_mem_size = NES_MGT_QP_COUNT * mgt_mem_size;
+       nesvnic->mgt_vbase = mgt_vbase;
+       nesvnic->mgt_pbase = mgt_pbase;
+
+       skb_queue_head_init(&nesvnic->mgt_skb_list);
+       init_waitqueue_head(&nesvnic->mgt_wait_queue);
+       nesvnic->mgt_thread = kthread_run(mgt_thread, nesvnic, "nes_mgt_thread");
+
+       for (i = 0; i < NES_MGT_QP_COUNT; i++) {
+               mgtvnic->nesvnic = nesvnic;
+               mgtvnic->mgt.qp_id = nesdev->mac_index + NES_MGT_QP_OFFSET + i;
+               memset(mgt_vbase, 0, mgt_mem_size);
+               nes_debug(NES_DBG_INIT, "Allocated mgt QP structures at %p (phys = %016lX), size = %u.\n",
+                         mgt_vbase, (unsigned long)mgt_pbase, mgt_mem_size);
+
+               vmem = (void *)(((unsigned long)mgt_vbase + (256 - 1)) &
+                               ~(unsigned long)(256 - 1));
+               pmem = (dma_addr_t)(((unsigned long long)mgt_pbase + (256 - 1)) &
+                                   ~(unsigned long long)(256 - 1));
+
+               spin_lock_init(&mgtvnic->mgt.rq_lock);
+
+               /* setup the RQ */
+               mgtvnic->mgt.rq_vbase = vmem;
+               mgtvnic->mgt.rq_pbase = pmem;
+               mgtvnic->mgt.rq_head = 0;
+               mgtvnic->mgt.rq_tail = 0;
+               mgtvnic->mgt.rq_size = NES_MGT_WQ_COUNT;
+
+               /* setup the CQ */
+               vmem += (NES_MGT_WQ_COUNT * sizeof(struct nes_hw_nic_rq_wqe));
+               pmem += (NES_MGT_WQ_COUNT * sizeof(struct nes_hw_nic_rq_wqe));
+
+               mgtvnic->mgt_cq.cq_number = mgtvnic->mgt.qp_id;
+               mgtvnic->mgt_cq.cq_vbase = vmem;
+               mgtvnic->mgt_cq.cq_pbase = pmem;
+               mgtvnic->mgt_cq.cq_head = 0;
+               mgtvnic->mgt_cq.cq_size = NES_MGT_WQ_COUNT;
+
+               mgtvnic->mgt_cq.ce_handler = nes_mgt_ce_handler;
+
+               /* Send CreateCQ request to CQP */
+               spin_lock_irqsave(&nesdev->cqp.lock, flags);
+               cqp_head = nesdev->cqp.sq_head;
+
+               cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
+               nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
+
+               cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(
+                       NES_CQP_CREATE_CQ | NES_CQP_CQ_CEQ_VALID |
+                       ((u32)mgtvnic->mgt_cq.cq_size << 16));
+               cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(
+                       mgtvnic->mgt_cq.cq_number | ((u32)nesdev->ceq_index << 16));
+               u64temp = (u64)mgtvnic->mgt_cq.cq_pbase;
+               set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_CQ_WQE_PBL_LOW_IDX, u64temp);
+               cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX] = 0;
+               u64temp = (unsigned long)&mgtvnic->mgt_cq;
+               cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_LOW_IDX] = cpu_to_le32((u32)(u64temp >> 1));
+               cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX] =
+                       cpu_to_le32(((u32)((u64temp) >> 33)) & 0x7FFFFFFF);
+               cqp_wqe->wqe_words[NES_CQP_CQ_WQE_DOORBELL_INDEX_HIGH_IDX] = 0;
+
+               if (++cqp_head >= nesdev->cqp.sq_size)
+                       cqp_head = 0;
+               cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
+               nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
+
+               /* Send CreateQP request to CQP */
+               mgt_context = (void *)(&mgtvnic->mgt_cq.cq_vbase[mgtvnic->mgt_cq.cq_size]);
+               mgt_context->context_words[NES_NIC_CTX_MISC_IDX] =
+                       cpu_to_le32((u32)NES_MGT_CTX_SIZE |
+                                   ((u32)PCI_FUNC(nesdev->pcidev->devfn) << 12));
+               nes_debug(NES_DBG_INIT, "RX_WINDOW_BUFFER_PAGE_TABLE_SIZE = 0x%08X, RX_WINDOW_BUFFER_SIZE = 0x%08X\n",
+                         nes_read_indexed(nesdev, NES_IDX_RX_WINDOW_BUFFER_PAGE_TABLE_SIZE),
+                         nes_read_indexed(nesdev, NES_IDX_RX_WINDOW_BUFFER_SIZE));
+               if (nes_read_indexed(nesdev, NES_IDX_RX_WINDOW_BUFFER_SIZE) != 0)
+                       mgt_context->context_words[NES_NIC_CTX_MISC_IDX] |= cpu_to_le32(NES_NIC_BACK_STORE);
+
+               u64temp = (u64)mgtvnic->mgt.rq_pbase;
+               mgt_context->context_words[NES_NIC_CTX_SQ_LOW_IDX] = cpu_to_le32((u32)u64temp);
+               mgt_context->context_words[NES_NIC_CTX_SQ_HIGH_IDX] = cpu_to_le32((u32)(u64temp >> 32));
+               u64temp = (u64)mgtvnic->mgt.rq_pbase;
+               mgt_context->context_words[NES_NIC_CTX_RQ_LOW_IDX] = cpu_to_le32((u32)u64temp);
+               mgt_context->context_words[NES_NIC_CTX_RQ_HIGH_IDX] = cpu_to_le32((u32)(u64temp >> 32));
+
+               cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_CREATE_QP |
+                                                                        NES_CQP_QP_TYPE_NIC);
+               cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(mgtvnic->mgt.qp_id);
+               u64temp = (u64)mgtvnic->mgt_cq.cq_pbase +
+                         (mgtvnic->mgt_cq.cq_size * sizeof(struct nes_hw_nic_cqe));
+               set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_QP_WQE_CONTEXT_LOW_IDX, u64temp);
+
+               if (++cqp_head >= nesdev->cqp.sq_size)
+                       cqp_head = 0;
+               nesdev->cqp.sq_head = cqp_head;
+
+               barrier();
+
+               /* Ring doorbell (2 WQEs) */
+               nes_write32(nesdev->regs + NES_WQE_ALLOC, 0x02800000 | nesdev->cqp.qp_id);
+
+               spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
+               nes_debug(NES_DBG_INIT, "Waiting for create MGT QP%u to complete.\n",
+                         mgtvnic->mgt.qp_id);
+
+               ret = wait_event_timeout(nesdev->cqp.waitq, (nesdev->cqp.sq_tail == cqp_head),
+                                        NES_EVENT_TIMEOUT);
+               nes_debug(NES_DBG_INIT, "Create MGT QP%u completed, wait_event_timeout ret = %u.\n",
+                         mgtvnic->mgt.qp_id, ret);
+               if (!ret) {
+                       nes_debug(NES_DBG_INIT, "MGT QP%u create timeout expired\n", mgtvnic->mgt.qp_id);
+                       if (i == 0) {
+                               pci_free_consistent(nesdev->pcidev, nesvnic->mgt_mem_size, nesvnic->mgt_vbase,
+                                                   nesvnic->mgt_pbase);
+                               kfree(mgtvnic);
+                       } else {
+                               nes_destroy_mgt(nesvnic);
+                       }
+                       return -EIO;
+               }
+
+               /* Populate the RQ */
+               for (counter = 0; counter < (NES_MGT_WQ_COUNT - 1); counter++) {
+                       skb = dev_alloc_skb(nesvnic->max_frame_size);
+                       if (!skb) {
+                               nes_debug(NES_DBG_INIT, "%s: out of memory for receive skb\n", netdev->name);
+                               return -ENOMEM;
+                       }
+
+                       skb->dev = netdev;
+
+                       pmem = pci_map_single(nesdev->pcidev, skb->data,
+                                             nesvnic->max_frame_size, PCI_DMA_FROMDEVICE);
+                       cb = (struct nes_rskb_cb *)&skb->cb[0];
+                       cb->busaddr = pmem;
+                       cb->maplen = nesvnic->max_frame_size;
+
+                       mgt_rqe = &mgtvnic->mgt.rq_vbase[counter];
+                       mgt_rqe->wqe_words[NES_NIC_RQ_WQE_LENGTH_1_0_IDX] = cpu_to_le32((u32)nesvnic->max_frame_size);
+                       mgt_rqe->wqe_words[NES_NIC_RQ_WQE_LENGTH_3_2_IDX] = 0;
+                       mgt_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_LOW_IDX] = cpu_to_le32((u32)pmem);
+                       mgt_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX] = cpu_to_le32((u32)((u64)pmem >> 32));
+                       mgtvnic->mgt.rx_skb[counter] = skb;
+               }
+
+               init_timer(&mgtvnic->rq_wqes_timer);
+               mgtvnic->rq_wqes_timer.function = nes_mgt_rq_wqes_timeout;
+               mgtvnic->rq_wqes_timer.data = (unsigned long)mgtvnic;
+
+               wqe_count = NES_MGT_WQ_COUNT - 1;
+               mgtvnic->mgt.rq_head = wqe_count;
+               barrier();
+               do {
+                       counter = min(wqe_count, ((u32)255));
+                       wqe_count -= counter;
+                       nes_write32(nesdev->regs + NES_WQE_ALLOC, (counter << 24) | mgtvnic->mgt.qp_id);
+               } while (wqe_count);
+
+               nes_write32(nesdev->regs + NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT |
+                           mgtvnic->mgt_cq.cq_number);
+               nes_read32(nesdev->regs + NES_CQE_ALLOC);
+
+               mgt_vbase += mgt_mem_size;
+               mgt_pbase += mgt_mem_size;
+               nesvnic->mgtvnic[i] = mgtvnic++;
+       }
+       return 0;
+}
+
+
+void nes_destroy_mgt(struct nes_vnic *nesvnic)
+{
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct nes_vnic_mgt *mgtvnic;
+       struct nes_vnic_mgt *first_mgtvnic;
+       unsigned long flags;
+       struct nes_hw_cqp_wqe *cqp_wqe;
+       u32 cqp_head;
+       struct sk_buff *rx_skb;
+       int i;
+       int ret;
+
+       kthread_stop(nesvnic->mgt_thread);
+
+       /* Free remaining NIC receive buffers */
+       first_mgtvnic = nesvnic->mgtvnic[0];
+       for (i = 0; i < NES_MGT_QP_COUNT; i++) {
+               mgtvnic = nesvnic->mgtvnic[i];
+               if (mgtvnic == NULL)
+                       continue;
+
+               while (mgtvnic->mgt.rq_head != mgtvnic->mgt.rq_tail) {
+                       rx_skb = mgtvnic->mgt.rx_skb[mgtvnic->mgt.rq_tail];
+                       nes_mgt_free_skb(nesdev, rx_skb, PCI_DMA_FROMDEVICE);
+                       mgtvnic->mgt.rq_tail++;
+                       mgtvnic->mgt.rq_tail &= (mgtvnic->mgt.rq_size - 1);
+               }
+
+               spin_lock_irqsave(&nesdev->cqp.lock, flags);
+
+               /* Destroy NIC QP */
+               cqp_head = nesdev->cqp.sq_head;
+               cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
+               nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
+
+               set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
+                                   (NES_CQP_DESTROY_QP | NES_CQP_QP_TYPE_NIC));
+               set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX,
+                                   mgtvnic->mgt.qp_id);
+
+               if (++cqp_head >= nesdev->cqp.sq_size)
+                       cqp_head = 0;
+
+               cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
+
+               /* Destroy NIC CQ */
+               nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
+               set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
+                                   (NES_CQP_DESTROY_CQ | ((u32)mgtvnic->mgt_cq.cq_size << 16)));
+               set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX,
+                                   (mgtvnic->mgt_cq.cq_number | ((u32)nesdev->ceq_index << 16)));
+
+               if (++cqp_head >= nesdev->cqp.sq_size)
+                       cqp_head = 0;
+
+               nesdev->cqp.sq_head = cqp_head;
+               barrier();
+
+               /* Ring doorbell (2 WQEs) */
+               nes_write32(nesdev->regs + NES_WQE_ALLOC, 0x02800000 | nesdev->cqp.qp_id);
+
+               spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
+               nes_debug(NES_DBG_SHUTDOWN, "Waiting for CQP, cqp_head=%u, cqp.sq_head=%u,"
+                         " cqp.sq_tail=%u, cqp.sq_size=%u\n",
+                         cqp_head, nesdev->cqp.sq_head,
+                         nesdev->cqp.sq_tail, nesdev->cqp.sq_size);
+
+               ret = wait_event_timeout(nesdev->cqp.waitq, (nesdev->cqp.sq_tail == cqp_head),
+                                        NES_EVENT_TIMEOUT);
+
+               nes_debug(NES_DBG_SHUTDOWN, "Destroy MGT QP returned, wait_event_timeout ret = %u, cqp_head=%u,"
+                         " cqp.sq_head=%u, cqp.sq_tail=%u\n",
+                         ret, cqp_head, nesdev->cqp.sq_head, nesdev->cqp.sq_tail);
+               if (!ret)
+                       nes_debug(NES_DBG_SHUTDOWN, "MGT QP%u destroy timeout expired\n",
+                                 mgtvnic->mgt.qp_id);
+
+               nesvnic->mgtvnic[i] = NULL;
+       }
+
+       if (nesvnic->mgt_vbase) {
+               pci_free_consistent(nesdev->pcidev, nesvnic->mgt_mem_size, nesvnic->mgt_vbase,
+                                   nesvnic->mgt_pbase);
+               nesvnic->mgt_vbase = NULL;
+               nesvnic->mgt_pbase = 0;
+       }
+
+       kfree(first_mgtvnic);
+}
diff --git a/drivers/infiniband/hw/nes/nes_mgt.h b/drivers/infiniband/hw/nes/nes_mgt.h
new file mode 100644 (file)
index 0000000..8c8af25
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+* Copyright (c) 2010 Intel-NE, Inc.  All rights reserved.
+*
+* This software is available to you under a choice of one of two
+* licenses.  You may choose to be licensed under the terms of the GNU
+* General Public License (GPL) Version 2, available from the file
+* COPYING in the main directory of this source tree, or the
+* OpenIB.org BSD license below:
+*
+*     Redistribution and use in source and binary forms, with or
+*     without modification, are permitted provided that the following
+*     conditions are met:
+*
+*      - Redistributions of source code must retain the above
+*        copyright notice, this list of conditions and the following
+*        disclaimer.
+*
+*      - Redistributions in binary form must reproduce the above
+*        copyright notice, this list of conditions and the following
+*        disclaimer in the documentation and/or other materials
+*        provided with the distribution.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+* SOFTWARE.
+*/
+
+#ifndef __NES_MGT_H
+#define __NES_MGT_H
+
+#define MPA_FRAMING 6  /* length is 2 bytes, crc is 4 bytes */
+
+int nes_init_mgt_qp(struct nes_device *nesdev, struct net_device *netdev, struct nes_vnic *nesvnic);
+void nes_queue_mgt_skbs(struct sk_buff *skb, struct nes_vnic *nesvnic, struct nes_qp *nesqp);
+void nes_destroy_mgt(struct nes_vnic *nesvnic);
+void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp);
+
+struct nes_hw_mgt {
+       struct nes_hw_nic_rq_wqe *rq_vbase;     /* virtual address of rq */
+       dma_addr_t rq_pbase;                    /* PCI memory for host rings */
+       struct sk_buff *rx_skb[NES_NIC_WQ_SIZE];
+       u16 qp_id;
+       u16 sq_head;
+       u16 rq_head;
+       u16 rq_tail;
+       u16 rq_size;
+       u8 replenishing_rq;
+       u8 reserved;
+       spinlock_t rq_lock;
+};
+
+struct nes_vnic_mgt {
+       struct nes_vnic        *nesvnic;
+       struct nes_hw_mgt      mgt;
+       struct nes_hw_nic_cq   mgt_cq;
+       atomic_t               rx_skbs_needed;
+       struct timer_list      rq_wqes_timer;
+       atomic_t               rx_skb_timer_running;
+};
+
+#define MAX_FPDU_FRAGS 4
+struct pau_fpdu_frag {
+       struct sk_buff         *skb;
+       u64                    physaddr;
+       u32                    frag_len;
+       bool                   cmplt;
+};
+
+struct pau_fpdu_info {
+       struct nes_qp          *nesqp;
+       struct nes_cqp_request *cqp_request;
+       void                   *hdr_vbase;
+       dma_addr_t             hdr_pbase;
+       int                    hdr_len;
+       u16                    data_len;
+       u16                    frag_cnt;
+       struct pau_fpdu_frag   frags[MAX_FPDU_FRAGS];
+};
+
+enum pau_qh_state {
+       PAU_DEL_QH,
+       PAU_ADD_LB_QH,
+       PAU_READY
+};
+
+struct pau_qh_chg {
+       struct nes_device *nesdev;
+       struct nes_vnic *nesvnic;
+       struct nes_qp *nesqp;
+};
+
+#endif          /* __NES_MGT_H */
index 47b2ee4c01e280311a23a9566faea954e2e2c130..c00d2f3f8966b5084ec5b5875845884b6b294789 100644 (file)
@@ -1091,6 +1091,8 @@ static const char nes_ethtool_stringset[][ETH_GSTRING_LEN] = {
        "LRO aggregated",
        "LRO flushed",
        "LRO no_desc",
+       "PAU CreateQPs",
+       "PAU DestroyQPs",
 };
 #define NES_ETHTOOL_STAT_COUNT  ARRAY_SIZE(nes_ethtool_stringset)
 
@@ -1306,6 +1308,8 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
        target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
        target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
        target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
+       target_stat_values[++index] = atomic_read(&pau_qps_created);
+       target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
 }
 
 /**
index f9c417c6b3b370cd98051584929c86358c46dc24..cd10968bfa22efbd04736b64172fb5b44d65df0d 100644 (file)
 
 #include "nes.h"
 
-
-
 static u16 nes_read16_eeprom(void __iomem *addr, u16 offset);
 
 u32 mh_detected;
 u32 mh_pauses_sent;
 
+u32 nes_set_pau(struct nes_device *nesdev)
+{
+       u32 ret = 0;
+       u32 counter;
+
+       nes_write_indexed(nesdev, NES_IDX_GPR2, NES_ENABLE_PAU);
+       nes_write_indexed(nesdev, NES_IDX_GPR_TRIGGER, 1);
+
+       for (counter = 0; counter < NES_PAU_COUNTER; counter++) {
+               udelay(30);
+               if (!nes_read_indexed(nesdev, NES_IDX_GPR2)) {
+                       printk(KERN_INFO PFX "PAU is supported.\n");
+                       break;
+               }
+               nes_write_indexed(nesdev, NES_IDX_GPR_TRIGGER, 1);
+       }
+       if (counter == NES_PAU_COUNTER) {
+               printk(KERN_INFO PFX "PAU is not supported.\n");
+               return -EPERM;
+       }
+       return ret;
+}
+
 /**
  * nes_read_eeprom_values -
  */
@@ -187,6 +208,11 @@ int nes_read_eeprom_values(struct nes_device *nesdev, struct nes_adapter *nesada
                if (((major_ver == 3) && (minor_ver >= 16)) || (major_ver > 3))
                        nesadapter->send_term_ok = 1;
 
+               if (nes_drv_opt & NES_DRV_OPT_ENABLE_PAU) {
+                       if (!nes_set_pau(nesdev))
+                               nesadapter->allow_unaligned_fpdus = 1;
+               }
+
                nesadapter->firmware_version = (((u32)(u8)(eeprom_data>>8))  <<  16) +
                                (u32)((u8)eeprom_data);
 
@@ -594,6 +620,7 @@ void nes_put_cqp_request(struct nes_device *nesdev,
                nes_free_cqp_request(nesdev, cqp_request);
 }
 
+
 /**
  * nes_post_cqp_request
  */
@@ -604,6 +631,8 @@ void nes_post_cqp_request(struct nes_device *nesdev,
        unsigned long flags;
        u32 cqp_head;
        u64 u64temp;
+       u32 opcode;
+       int ctx_index = NES_CQP_WQE_COMP_CTX_LOW_IDX;
 
        spin_lock_irqsave(&nesdev->cqp.lock, flags);
 
@@ -614,17 +643,20 @@ void nes_post_cqp_request(struct nes_device *nesdev,
                nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
                cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
                memcpy(cqp_wqe, &cqp_request->cqp_wqe, sizeof(*cqp_wqe));
+               opcode = le32_to_cpu(cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX]);
+               if ((opcode & NES_CQP_OPCODE_MASK) == NES_CQP_DOWNLOAD_SEGMENT)
+                       ctx_index = NES_CQP_WQE_DL_COMP_CTX_LOW_IDX;
                barrier();
                u64temp = (unsigned long)cqp_request;
-               set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_COMP_SCRATCH_LOW_IDX,
-                                   u64temp);
+               set_wqe_64bit_value(cqp_wqe->wqe_words, ctx_index, u64temp);
                nes_debug(NES_DBG_CQP, "CQP request (opcode 0x%02X), line 1 = 0x%08X put on CQPs SQ,"
-                               " request = %p, cqp_head = %u, cqp_tail = %u, cqp_size = %u,"
-                               " waiting = %d, refcount = %d.\n",
-                               le32_to_cpu(cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX])&0x3f,
-                               le32_to_cpu(cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX]), cqp_request,
-                               nesdev->cqp.sq_head, nesdev->cqp.sq_tail, nesdev->cqp.sq_size,
-                               cqp_request->waiting, atomic_read(&cqp_request->refcount));
+                       " request = %p, cqp_head = %u, cqp_tail = %u, cqp_size = %u,"
+                       " waiting = %d, refcount = %d.\n",
+                       opcode & NES_CQP_OPCODE_MASK,
+                       le32_to_cpu(cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX]), cqp_request,
+                       nesdev->cqp.sq_head, nesdev->cqp.sq_tail, nesdev->cqp.sq_size,
+                       cqp_request->waiting, atomic_read(&cqp_request->refcount));
+
                barrier();
 
                /* Ring doorbell (1 WQEs) */
@@ -645,7 +677,6 @@ void nes_post_cqp_request(struct nes_device *nesdev,
        return;
 }
 
-
 /**
  * nes_arp_table
  */
index 9f2f7d4b119754853a6003f8fc8b7dd24473ccad..5095bc41c6ccdd9203f6259a3a1be294aca9b563 100644 (file)
@@ -1458,7 +1458,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
        struct ib_qp_attr attr;
        struct iw_cm_id *cm_id;
        struct iw_cm_event cm_event;
-       int ret;
+       int ret = 0;
 
        atomic_inc(&sw_qps_destroyed);
        nesqp->destroyed = 1;
@@ -1511,7 +1511,6 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
                if ((nesqp->nesrcq) && (nesqp->nesrcq != nesqp->nesscq))
                        nes_clean_cq(nesqp, nesqp->nesrcq);
        }
-
        nes_rem_ref(&nesqp->ibqp);
        return 0;
 }
@@ -2338,8 +2337,10 @@ static struct ib_mr *nes_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
 
        skip_pages = ((u32)region->offset) >> 12;
 
-       if (ib_copy_from_udata(&req, udata, sizeof(req)))
+       if (ib_copy_from_udata(&req, udata, sizeof(req))) {
+               ib_umem_release(region);
                return ERR_PTR(-EFAULT);
+       }
        nes_debug(NES_DBG_MR, "Memory Registration type = %08X.\n", req.reg_type);
 
        switch (req.reg_type) {
@@ -2631,6 +2632,7 @@ static struct ib_mr *nes_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
                        return &nesmr->ibmr;
        }
 
+       ib_umem_release(region);
        return ERR_PTR(-ENOSYS);
 }
 
index 2df9993e0cac513da2d216cfdf801f06cc73f879..fe6b6e92fa901de9d4354de95783610cc271d571 100644 (file)
@@ -139,7 +139,8 @@ struct nes_qp {
        struct nes_cq         *nesrcq;
        struct nes_pd         *nespd;
        void *cm_node; /* handle of the node this QP is associated with */
-       struct ietf_mpa_frame *ietf_frame;
+       void                  *ietf_frame;
+       u8                    ietf_frame_size;
        dma_addr_t            ietf_frame_pbase;
        struct ib_mr          *lsmm_mr;
        struct nes_hw_qp      hwqp;
@@ -154,6 +155,7 @@ struct nes_qp {
        u32                   mmap_sq_db_index;
        u32                   mmap_rq_db_index;
        spinlock_t            lock;
+       spinlock_t            pau_lock;
        struct nes_qp_context *nesqp_context;
        dma_addr_t            nesqp_context_pbase;
        void                  *pbl_vbase;
@@ -161,6 +163,8 @@ struct nes_qp {
        struct page           *page;
        struct timer_list     terminate_timer;
        enum ib_event_type    terminate_eventtype;
+       struct sk_buff_head   pau_list;
+       u32                   pau_rcv_nxt;
        u16                   active_conn:1;
        u16                   skip_lsmm:1;
        u16                   user_mode:1;
@@ -168,7 +172,8 @@ struct nes_qp {
        u16                   flush_issued:1;
        u16                   destroyed:1;
        u16                   sig_all:1;
-       u16                   rsvd:9;
+       u16                   pau_mode:1;
+       u16                   rsvd:8;
        u16                   private_data_len;
        u16                   term_sq_flush_code;
        u16                   term_rq_flush_code;
@@ -176,5 +181,8 @@ struct nes_qp {
        u8                    hw_tcp_state;
        u8                    term_flags;
        u8                    sq_kmapped;
+       u8                    pau_busy;
+       u8                    pau_pending;
+       u8                    pau_state;
 };
 #endif                 /* NES_VERBS_H */
index c9624ea872098a6c5b36b285620d63633eade977..b881bdc401f58624fb9db27e44c1e5c223074893 100644 (file)
@@ -171,7 +171,9 @@ struct qib_ctxtdata {
        /* how many alloc_pages() chunks in rcvegrbuf_pages */
        u32 rcvegrbuf_chunks;
        /* how many egrbufs per chunk */
-       u32 rcvegrbufs_perchunk;
+       u16 rcvegrbufs_perchunk;
+       /* ilog2 of above */
+       u16 rcvegrbufs_perchunk_shift;
        /* order for rcvegrbuf_pages */
        size_t rcvegrbuf_size;
        /* rcvhdrq size (for freeing) */
@@ -221,6 +223,9 @@ struct qib_ctxtdata {
        /* ctxt rcvhdrq head offset */
        u32 head;
        u32 pkt_count;
+       /* lookaside fields */
+       struct qib_qp *lookaside_qp;
+       u32 lookaside_qpn;
        /* QPs waiting for context processing */
        struct list_head qp_wait_list;
 };
@@ -807,6 +812,10 @@ struct qib_devdata {
         * supports, less gives more pio bufs/ctxt, etc.
         */
        u32 cfgctxts;
+       /*
+        * number of ctxts available for PSM open
+        */
+       u32 freectxts;
 
        /*
         * hint that we should update pioavailshadow before
@@ -936,7 +945,9 @@ struct qib_devdata {
        /* chip address space used by 4k pio buffers */
        u32 align4k;
        /* size of each rcvegrbuffer */
-       u32 rcvegrbufsize;
+       u16 rcvegrbufsize;
+       /* log2 of above */
+       u16 rcvegrbufsize_shift;
        /* localbus width (1, 2,4,8,16,32) from config space  */
        u32 lbus_width;
        /* localbus speed in MHz */
index 23e584f4c36c772c2647e72f3e60c962a74c23aa..9a9047f385ae55b059339874fbf74fe8755911ce 100644 (file)
@@ -279,10 +279,10 @@ bail:
  */
 static inline void *qib_get_egrbuf(const struct qib_ctxtdata *rcd, u32 etail)
 {
-       const u32 chunk = etail / rcd->rcvegrbufs_perchunk;
-       const u32 idx =  etail % rcd->rcvegrbufs_perchunk;
+       const u32 chunk = etail >> rcd->rcvegrbufs_perchunk_shift;
+       const u32 idx =  etail & ((u32)rcd->rcvegrbufs_perchunk - 1);
 
-       return rcd->rcvegrbuf[chunk] + idx * rcd->dd->rcvegrbufsize;
+       return rcd->rcvegrbuf[chunk] + (idx << rcd->dd->rcvegrbufsize_shift);
 }
 
 /*
@@ -310,7 +310,6 @@ static u32 qib_rcv_hdrerr(struct qib_ctxtdata *rcd, struct qib_pportdata *ppd,
                u32 opcode;
                u32 psn;
                int diff;
-               unsigned long flags;
 
                /* Sanity check packet */
                if (tlen < 24)
@@ -365,7 +364,6 @@ static u32 qib_rcv_hdrerr(struct qib_ctxtdata *rcd, struct qib_pportdata *ppd,
 
                        switch (qp->ibqp.qp_type) {
                        case IB_QPT_RC:
-                               spin_lock_irqsave(&qp->s_lock, flags);
                                ruc_res =
                                        qib_ruc_check_hdr(
                                                ibp, hdr,
@@ -373,11 +371,8 @@ static u32 qib_rcv_hdrerr(struct qib_ctxtdata *rcd, struct qib_pportdata *ppd,
                                                qp,
                                                be32_to_cpu(ohdr->bth[0]));
                                if (ruc_res) {
-                                       spin_unlock_irqrestore(&qp->s_lock,
-                                                              flags);
                                        goto unlock;
                                }
-                               spin_unlock_irqrestore(&qp->s_lock, flags);
 
                                /* Only deal with RDMA Writes for now */
                                if (opcode <
@@ -547,6 +542,15 @@ move_along:
                        updegr = 0;
                }
        }
+       /*
+        * Notify qib_destroy_qp() if it is waiting
+        * for lookaside_qp to finish.
+        */
+       if (rcd->lookaside_qp) {
+               if (atomic_dec_and_test(&rcd->lookaside_qp->refcount))
+                       wake_up(&rcd->lookaside_qp->wait);
+               rcd->lookaside_qp = NULL;
+       }
 
        rcd->head = l;
        rcd->pkt_count += i;
index 26253039d2c7117a1d45f3c9afd13ee804406c93..77633666f81c385edafc326a815797896a919068 100644 (file)
@@ -1284,6 +1284,7 @@ static int setup_ctxt(struct qib_pportdata *ppd, int ctxt,
        strlcpy(rcd->comm, current->comm, sizeof(rcd->comm));
        ctxt_fp(fp) = rcd;
        qib_stats.sps_ctxts++;
+       dd->freectxts++;
        ret = 0;
        goto bail;
 
@@ -1792,6 +1793,7 @@ static int qib_close(struct inode *in, struct file *fp)
                if (dd->pageshadow)
                        unlock_expected_tids(rcd);
                qib_stats.sps_ctxts--;
+               dd->freectxts--;
        }
 
        mutex_unlock(&qib_mutex);
index d8ca0a0b970d39879e7d981acbf5cb1647dca424..781a802a321f069d3a8b6552713a3cb550d52803 100644 (file)
@@ -3273,6 +3273,8 @@ static int init_6120_variables(struct qib_devdata *dd)
        /* we always allocate at least 2048 bytes for eager buffers */
        ret = ib_mtu_enum_to_int(qib_ibmtu);
        dd->rcvegrbufsize = ret != -1 ? max(ret, 2048) : QIB_DEFAULT_MTU;
+       BUG_ON(!is_power_of_2(dd->rcvegrbufsize));
+       dd->rcvegrbufsize_shift = ilog2(dd->rcvegrbufsize);
 
        qib_6120_tidtemplate(dd);
 
index e1f947446c2a5bac53c28699c3ac3792924fea9b..3f1d562ba89824694808a6bd91f1f94dbaa12e4b 100644 (file)
@@ -4085,6 +4085,8 @@ static int qib_init_7220_variables(struct qib_devdata *dd)
        /* we always allocate at least 2048 bytes for eager buffers */
        ret = ib_mtu_enum_to_int(qib_ibmtu);
        dd->rcvegrbufsize = ret != -1 ? max(ret, 2048) : QIB_DEFAULT_MTU;
+       BUG_ON(!is_power_of_2(dd->rcvegrbufsize));
+       dd->rcvegrbufsize_shift = ilog2(dd->rcvegrbufsize);
 
        qib_7220_tidtemplate(dd);
 
index 5ea9ece23b33996bedbcb652ecb2bb116c5c5ec2..efd0a110091f754570ac6133cf5973a0cf5104c8 100644 (file)
@@ -2310,12 +2310,15 @@ static int qib_7322_bringup_serdes(struct qib_pportdata *ppd)
        val = ppd->cpspec->ibcctrl_a | (QLOGIC_IB_IBCC_LINKINITCMD_DISABLE <<
                QLOGIC_IB_IBCC_LINKINITCMD_SHIFT);
 
+       ppd->cpspec->ibcctrl_a = val;
        /*
         * Reset the PCS interface to the serdes (and also ibc, which is still
         * in reset from above).  Writes new value of ibcctrl_a as last step.
         */
        qib_7322_mini_pcs_reset(ppd);
        qib_write_kreg(dd, kr_scratch, 0ULL);
+       /* clear the linkinit cmds */
+       ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0, LinkInitCmd);
 
        if (!ppd->cpspec->ibcctrl_b) {
                unsigned lse = ppd->link_speed_enabled;
@@ -2387,11 +2390,6 @@ static int qib_7322_bringup_serdes(struct qib_pportdata *ppd)
        qib_write_kreg_port(ppd, krp_rcvctrl, ppd->p_rcvctrl);
        spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
 
-       /* Hold the link state machine for mezz boards */
-       if (IS_QMH(dd) || IS_QME(dd))
-               qib_set_ib_7322_lstate(ppd, 0,
-                                      QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
-
        /* Also enable IBSTATUSCHG interrupt.  */
        val = qib_read_kreg_port(ppd, krp_errmask);
        qib_write_kreg_port(ppd, krp_errmask,
@@ -2853,9 +2851,8 @@ static irqreturn_t qib_7322intr(int irq, void *data)
                for (i = 0; i < dd->first_user_ctxt; i++) {
                        if (ctxtrbits & rmask) {
                                ctxtrbits &= ~rmask;
-                               if (dd->rcd[i]) {
+                               if (dd->rcd[i])
                                        qib_kreceive(dd->rcd[i], NULL, &npkts);
-                               }
                        }
                        rmask <<= 1;
                }
@@ -5230,6 +5227,8 @@ static int qib_7322_ib_updown(struct qib_pportdata *ppd, int ibup, u64 ibcs)
                                     QIBL_IB_AUTONEG_INPROG)))
                        set_7322_ibspeed_fast(ppd, ppd->link_speed_enabled);
                if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG)) {
+                       struct qib_qsfp_data *qd =
+                               &ppd->cpspec->qsfp_data;
                        /* unlock the Tx settings, speed may change */
                        qib_write_kreg_port(ppd, krp_tx_deemph_override,
                                SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
@@ -5237,6 +5236,12 @@ static int qib_7322_ib_updown(struct qib_pportdata *ppd, int ibup, u64 ibcs)
                        qib_cancel_sends(ppd);
                        /* on link down, ensure sane pcs state */
                        qib_7322_mini_pcs_reset(ppd);
+                       /* schedule the qsfp refresh which should turn the link
+                          off */
+                       if (ppd->dd->flags & QIB_HAS_QSFP) {
+                               qd->t_insert = get_jiffies_64();
+                               schedule_work(&qd->work);
+                       }
                        spin_lock_irqsave(&ppd->sdma_lock, flags);
                        if (__qib_sdma_running(ppd))
                                __qib_sdma_process_event(ppd,
@@ -5587,43 +5592,79 @@ static void qsfp_7322_event(struct work_struct *work)
        struct qib_qsfp_data *qd;
        struct qib_pportdata *ppd;
        u64 pwrup;
+       unsigned long flags;
        int ret;
        u32 le2;
 
        qd = container_of(work, struct qib_qsfp_data, work);
        ppd = qd->ppd;
-       pwrup = qd->t_insert + msecs_to_jiffies(QSFP_PWR_LAG_MSEC);
+       pwrup = qd->t_insert +
+               msecs_to_jiffies(QSFP_PWR_LAG_MSEC - QSFP_MODPRS_LAG_MSEC);
 
-       /*
-        * Some QSFP's not only do not respond until the full power-up
-        * time, but may behave badly if we try. So hold off responding
-        * to insertion.
-        */
-       while (1) {
-               u64 now = get_jiffies_64();
-               if (time_after64(now, pwrup))
-                       break;
-               msleep(20);
-       }
-       ret = qib_refresh_qsfp_cache(ppd, &qd->cache);
-       /*
-        * Need to change LE2 back to defaults if we couldn't
-        * read the cable type (to handle cable swaps), so do this
-        * even on failure to read cable information.  We don't
-        * get here for QME, so IS_QME check not needed here.
-        */
-       if (!ret && !ppd->dd->cspec->r1) {
-               if (QSFP_IS_ACTIVE_FAR(qd->cache.tech))
-                       le2 = LE2_QME;
-               else if (qd->cache.atten[1] >= qib_long_atten &&
-                        QSFP_IS_CU(qd->cache.tech))
-                       le2 = LE2_5m;
-               else
+       /* Delay for 20 msecs to allow ModPrs resistor to setup */
+       mdelay(QSFP_MODPRS_LAG_MSEC);
+
+       if (!qib_qsfp_mod_present(ppd)) {
+               ppd->cpspec->qsfp_data.modpresent = 0;
+               /* Set the physical link to disabled */
+               qib_set_ib_7322_lstate(ppd, 0,
+                                      QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
+               spin_lock_irqsave(&ppd->lflags_lock, flags);
+               ppd->lflags &= ~QIBL_LINKV;
+               spin_unlock_irqrestore(&ppd->lflags_lock, flags);
+       } else {
+               /*
+                * Some QSFP's not only do not respond until the full power-up
+                * time, but may behave badly if we try. So hold off responding
+                * to insertion.
+                */
+               while (1) {
+                       u64 now = get_jiffies_64();
+                       if (time_after64(now, pwrup))
+                               break;
+                       msleep(20);
+               }
+
+               ret = qib_refresh_qsfp_cache(ppd, &qd->cache);
+
+               /*
+                * Need to change LE2 back to defaults if we couldn't
+                * read the cable type (to handle cable swaps), so do this
+                * even on failure to read cable information.  We don't
+                * get here for QME, so IS_QME check not needed here.
+                */
+               if (!ret && !ppd->dd->cspec->r1) {
+                       if (QSFP_IS_ACTIVE_FAR(qd->cache.tech))
+                               le2 = LE2_QME;
+                       else if (qd->cache.atten[1] >= qib_long_atten &&
+                                QSFP_IS_CU(qd->cache.tech))
+                               le2 = LE2_5m;
+                       else
+                               le2 = LE2_DEFAULT;
+               } else
                        le2 = LE2_DEFAULT;
-       } else
-               le2 = LE2_DEFAULT;
-       ibsd_wr_allchans(ppd, 13, (le2 << 7), BMASK(9, 7));
-       init_txdds_table(ppd, 0);
+               ibsd_wr_allchans(ppd, 13, (le2 << 7), BMASK(9, 7));
+               /*
+                * We always change parameteters, since we can choose
+                * values for cables without eeproms, and the cable may have
+                * changed from a cable with full or partial eeprom content
+                * to one with partial or no content.
+                */
+               init_txdds_table(ppd, 0);
+               /* The physical link is being re-enabled only when the
+                * previous state was DISABLED and the VALID bit is not
+                * set. This should only happen when  the cable has been
+                * physically pulled. */
+               if (!ppd->cpspec->qsfp_data.modpresent &&
+                   (ppd->lflags & (QIBL_LINKV | QIBL_IB_LINK_DISABLED))) {
+                       ppd->cpspec->qsfp_data.modpresent = 1;
+                       qib_set_ib_7322_lstate(ppd, 0,
+                               QLOGIC_IB_IBCC_LINKINITCMD_SLEEP);
+                       spin_lock_irqsave(&ppd->lflags_lock, flags);
+                       ppd->lflags |= QIBL_LINKV;
+                       spin_unlock_irqrestore(&ppd->lflags_lock, flags);
+               }
+       }
 }
 
 /*
@@ -5727,7 +5768,8 @@ static void set_no_qsfp_atten(struct qib_devdata *dd, int change)
                        /* now change the IBC and serdes, overriding generic */
                        init_txdds_table(ppd, 1);
                        /* Re-enable the physical state machine on mezz boards
-                        * now that the correct settings have been set. */
+                        * now that the correct settings have been set.
+                        * QSFP boards are handles by the QSFP event handler */
                        if (IS_QMH(dd) || IS_QME(dd))
                                qib_set_ib_7322_lstate(ppd, 0,
                                            QLOGIC_IB_IBCC_LINKINITCMD_SLEEP);
@@ -6205,6 +6247,8 @@ static int qib_init_7322_variables(struct qib_devdata *dd)
 
        /* we always allocate at least 2048 bytes for eager buffers */
        dd->rcvegrbufsize = max(mtu, 2048);
+       BUG_ON(!is_power_of_2(dd->rcvegrbufsize));
+       dd->rcvegrbufsize_shift = ilog2(dd->rcvegrbufsize);
 
        qib_7322_tidtemplate(dd);
 
@@ -7147,7 +7191,8 @@ static void find_best_ent(struct qib_pportdata *ppd,
                }
        }
 
-       /* Lookup serdes setting by cable type and attenuation */
+       /* Active cables don't have attenuation so we only set SERDES
+        * settings to account for the attenuation of the board traces. */
        if (!override && QSFP_IS_ACTIVE(qd->tech)) {
                *sdr_dds = txdds_sdr + ppd->dd->board_atten;
                *ddr_dds = txdds_ddr + ppd->dd->board_atten;
@@ -7464,12 +7509,6 @@ static int serdes_7322_init_new(struct qib_pportdata *ppd)
        u32 le_val, rxcaldone;
        int chan, chan_done = (1 << SERDES_CHANS) - 1;
 
-       /*
-        * Initialize the Tx DDS tables.  Also done every QSFP event,
-        * for adapters with QSFP
-        */
-       init_txdds_table(ppd, 0);
-
        /* Clear cmode-override, may be set from older driver */
        ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 0 << 14, 1 << 14);
 
@@ -7655,6 +7694,12 @@ static int serdes_7322_init_new(struct qib_pportdata *ppd)
        /* VGA output common mode */
        ibsd_wr_allchans(ppd, 12, (3 << 2), BMASK(3, 2));
 
+       /*
+        * Initialize the Tx DDS tables.  Also done every QSFP event,
+        * for adapters with QSFP
+        */
+       init_txdds_table(ppd, 0);
+
        return 0;
 }
 
index a01f3fce8eb3f10616efe2e31e6ec2b660df9c65..b093a0b53b2f1ac79b08c73495bc8cf368f03eb2 100644 (file)
@@ -183,6 +183,9 @@ struct qib_ctxtdata *qib_create_ctxtdata(struct qib_pportdata *ppd, u32 ctxt)
                rcd->rcvegrbuf_chunks = (rcd->rcvegrcnt +
                        rcd->rcvegrbufs_perchunk - 1) /
                        rcd->rcvegrbufs_perchunk;
+               BUG_ON(!is_power_of_2(rcd->rcvegrbufs_perchunk));
+               rcd->rcvegrbufs_perchunk_shift =
+                       ilog2(rcd->rcvegrbufs_perchunk);
        }
        return rcd;
 }
@@ -398,6 +401,7 @@ static void enable_chip(struct qib_devdata *dd)
                if (rcd)
                        dd->f_rcvctrl(rcd->ppd, rcvmask, i);
        }
+       dd->freectxts = dd->cfgctxts - dd->first_user_ctxt;
 }
 
 static void verify_interrupt(unsigned long opaque)
@@ -581,10 +585,6 @@ int qib_init(struct qib_devdata *dd, int reinit)
                        continue;
                }
 
-               /* let link come up, and enable IBC */
-               spin_lock_irqsave(&ppd->lflags_lock, flags);
-               ppd->lflags &= ~QIBL_IB_LINK_DISABLED;
-               spin_unlock_irqrestore(&ppd->lflags_lock, flags);
                portok++;
        }
 
index e16751f8639e7c44cbb4edadb46b3a805a71c196..7e7e16fbee990848d0f206aec041b596cf6c77bf 100644 (file)
@@ -34,6 +34,7 @@
 
 #include <linux/err.h>
 #include <linux/vmalloc.h>
+#include <linux/jhash.h>
 
 #include "qib.h"
 
@@ -204,6 +205,13 @@ static void free_qpn(struct qib_qpn_table *qpt, u32 qpn)
                clear_bit(qpn & BITS_PER_PAGE_MASK, map->page);
 }
 
+static inline unsigned qpn_hash(struct qib_ibdev *dev, u32 qpn)
+{
+       return jhash_1word(qpn, dev->qp_rnd) &
+               (dev->qp_table_size - 1);
+}
+
+
 /*
  * Put the QP into the hash table.
  * The hash table holds a reference to the QP.
@@ -211,22 +219,23 @@ static void free_qpn(struct qib_qpn_table *qpt, u32 qpn)
 static void insert_qp(struct qib_ibdev *dev, struct qib_qp *qp)
 {
        struct qib_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
-       unsigned n = qp->ibqp.qp_num % dev->qp_table_size;
        unsigned long flags;
+       unsigned n = qpn_hash(dev, qp->ibqp.qp_num);
 
        spin_lock_irqsave(&dev->qpt_lock, flags);
+       atomic_inc(&qp->refcount);
 
        if (qp->ibqp.qp_num == 0)
-               ibp->qp0 = qp;
+               rcu_assign_pointer(ibp->qp0, qp);
        else if (qp->ibqp.qp_num == 1)
-               ibp->qp1 = qp;
+               rcu_assign_pointer(ibp->qp1, qp);
        else {
                qp->next = dev->qp_table[n];
-               dev->qp_table[n] = qp;
+               rcu_assign_pointer(dev->qp_table[n], qp);
        }
-       atomic_inc(&qp->refcount);
 
        spin_unlock_irqrestore(&dev->qpt_lock, flags);
+       synchronize_rcu();
 }
 
 /*
@@ -236,29 +245,32 @@ static void insert_qp(struct qib_ibdev *dev, struct qib_qp *qp)
 static void remove_qp(struct qib_ibdev *dev, struct qib_qp *qp)
 {
        struct qib_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
-       struct qib_qp *q, **qpp;
+       unsigned n = qpn_hash(dev, qp->ibqp.qp_num);
        unsigned long flags;
 
-       qpp = &dev->qp_table[qp->ibqp.qp_num % dev->qp_table_size];
-
        spin_lock_irqsave(&dev->qpt_lock, flags);
 
        if (ibp->qp0 == qp) {
-               ibp->qp0 = NULL;
                atomic_dec(&qp->refcount);
+               rcu_assign_pointer(ibp->qp0, NULL);
        } else if (ibp->qp1 == qp) {
-               ibp->qp1 = NULL;
                atomic_dec(&qp->refcount);
-       } else
+               rcu_assign_pointer(ibp->qp1, NULL);
+       } else {
+               struct qib_qp *q, **qpp;
+
+               qpp = &dev->qp_table[n];
                for (; (q = *qpp) != NULL; qpp = &q->next)
                        if (q == qp) {
-                               *qpp = qp->next;
-                               qp->next = NULL;
                                atomic_dec(&qp->refcount);
+                               rcu_assign_pointer(*qpp, qp->next);
+                               qp->next = NULL;
                                break;
                        }
+       }
 
        spin_unlock_irqrestore(&dev->qpt_lock, flags);
+       synchronize_rcu();
 }
 
 /**
@@ -280,21 +292,24 @@ unsigned qib_free_all_qps(struct qib_devdata *dd)
 
                if (!qib_mcast_tree_empty(ibp))
                        qp_inuse++;
-               if (ibp->qp0)
+               rcu_read_lock();
+               if (rcu_dereference(ibp->qp0))
                        qp_inuse++;
-               if (ibp->qp1)
+               if (rcu_dereference(ibp->qp1))
                        qp_inuse++;
+               rcu_read_unlock();
        }
 
        spin_lock_irqsave(&dev->qpt_lock, flags);
        for (n = 0; n < dev->qp_table_size; n++) {
                qp = dev->qp_table[n];
-               dev->qp_table[n] = NULL;
+               rcu_assign_pointer(dev->qp_table[n], NULL);
 
                for (; qp; qp = qp->next)
                        qp_inuse++;
        }
        spin_unlock_irqrestore(&dev->qpt_lock, flags);
+       synchronize_rcu();
 
        return qp_inuse;
 }
@@ -309,25 +324,28 @@ unsigned qib_free_all_qps(struct qib_devdata *dd)
  */
 struct qib_qp *qib_lookup_qpn(struct qib_ibport *ibp, u32 qpn)
 {
-       struct qib_ibdev *dev = &ppd_from_ibp(ibp)->dd->verbs_dev;
-       unsigned long flags;
-       struct qib_qp *qp;
+       struct qib_qp *qp = NULL;
 
-       spin_lock_irqsave(&dev->qpt_lock, flags);
+       if (unlikely(qpn <= 1)) {
+               rcu_read_lock();
+               if (qpn == 0)
+                       qp = rcu_dereference(ibp->qp0);
+               else
+                       qp = rcu_dereference(ibp->qp1);
+       } else {
+               struct qib_ibdev *dev = &ppd_from_ibp(ibp)->dd->verbs_dev;
+               unsigned n = qpn_hash(dev, qpn);
 
-       if (qpn == 0)
-               qp = ibp->qp0;
-       else if (qpn == 1)
-               qp = ibp->qp1;
-       else
-               for (qp = dev->qp_table[qpn % dev->qp_table_size]; qp;
-                    qp = qp->next)
+               rcu_read_lock();
+               for (qp = dev->qp_table[n]; rcu_dereference(qp); qp = qp->next)
                        if (qp->ibqp.qp_num == qpn)
                                break;
+       }
        if (qp)
-               atomic_inc(&qp->refcount);
+               if (unlikely(!atomic_inc_not_zero(&qp->refcount)))
+                       qp = NULL;
 
-       spin_unlock_irqrestore(&dev->qpt_lock, flags);
+       rcu_read_unlock();
        return qp;
 }
 
@@ -765,8 +783,10 @@ int qib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
                }
        }
 
-       if (attr_mask & IB_QP_PATH_MTU)
+       if (attr_mask & IB_QP_PATH_MTU) {
                qp->path_mtu = pmtu;
+               qp->pmtu = ib_mtu_enum_to_int(pmtu);
+       }
 
        if (attr_mask & IB_QP_RETRY_CNT) {
                qp->s_retry_cnt = attr->retry_cnt;
@@ -781,8 +801,12 @@ int qib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
        if (attr_mask & IB_QP_MIN_RNR_TIMER)
                qp->r_min_rnr_timer = attr->min_rnr_timer;
 
-       if (attr_mask & IB_QP_TIMEOUT)
+       if (attr_mask & IB_QP_TIMEOUT) {
                qp->timeout = attr->timeout;
+               qp->timeout_jiffies =
+                       usecs_to_jiffies((4096UL * (1UL << qp->timeout)) /
+                               1000UL);
+       }
 
        if (attr_mask & IB_QP_QKEY)
                qp->qkey = attr->qkey;
@@ -1013,6 +1037,10 @@ struct ib_qp *qib_create_qp(struct ib_pd *ibpd,
                        ret = ERR_PTR(-ENOMEM);
                        goto bail_swq;
                }
+               RCU_INIT_POINTER(qp->next, NULL);
+               qp->timeout_jiffies =
+                       usecs_to_jiffies((4096UL * (1UL << qp->timeout)) /
+                               1000UL);
                if (init_attr->srq)
                        sz = 0;
                else {
index 3374a52232c1a312f40ca6380f010f6c5ead9670..e06c4ed383f14598674ce8a0847c9780a6231c46 100644 (file)
@@ -273,18 +273,12 @@ int qib_refresh_qsfp_cache(struct qib_pportdata *ppd, struct qib_qsfp_cache *cp)
        int ret;
        int idx;
        u16 cks;
-       u32 mask;
        u8 peek[4];
 
        /* ensure sane contents on invalid reads, for cable swaps */
        memset(cp, 0, sizeof(*cp));
 
-       mask = QSFP_GPIO_MOD_PRS_N;
-       if (ppd->hw_pidx)
-               mask <<= QSFP_GPIO_PORT2_SHIFT;
-
-       ret = ppd->dd->f_gpio_mod(ppd->dd, 0, 0, 0);
-       if (ret & mask) {
+       if (!qib_qsfp_mod_present(ppd)) {
                ret = -ENODEV;
                goto bail;
        }
@@ -444,6 +438,19 @@ const char * const qib_qsfp_devtech[16] = {
 
 static const char *pwr_codes = "1.5W2.0W2.5W3.5W";
 
+int qib_qsfp_mod_present(struct qib_pportdata *ppd)
+{
+       u32 mask;
+       int ret;
+
+       mask = QSFP_GPIO_MOD_PRS_N <<
+               (ppd->hw_pidx * QSFP_GPIO_PORT2_SHIFT);
+       ret = ppd->dd->f_gpio_mod(ppd->dd, 0, 0, 0);
+
+       return !((ret & mask) >>
+                ((ppd->hw_pidx * QSFP_GPIO_PORT2_SHIFT) + 3));
+}
+
 /*
  * Initialize structures that control access to QSFP. Called once per port
  * on cards that support QSFP.
@@ -452,7 +459,6 @@ void qib_qsfp_init(struct qib_qsfp_data *qd,
                   void (*fevent)(struct work_struct *))
 {
        u32 mask, highs;
-       int pins;
 
        struct qib_devdata *dd = qd->ppd->dd;
 
@@ -480,8 +486,7 @@ void qib_qsfp_init(struct qib_qsfp_data *qd,
                mask <<= QSFP_GPIO_PORT2_SHIFT;
 
        /* Do not try to wait here. Better to let event handle it */
-       pins = dd->f_gpio_mod(dd, 0, 0, 0);
-       if (pins & mask)
+       if (!qib_qsfp_mod_present(qd->ppd))
                goto bail;
        /* We see a module, but it may be unwise to look yet. Just schedule */
        qd->t_insert = get_jiffies_64();
index c109bbdc90ac98fc5d9d10cb3c7f4865590c330b..46002a9417c0ac73f1b38ed709f487eeb8c9d8fa 100644 (file)
@@ -34,6 +34,7 @@
 
 #define QSFP_DEV 0xA0
 #define QSFP_PWR_LAG_MSEC 2000
+#define QSFP_MODPRS_LAG_MSEC 20
 
 /*
  * Below are masks for various QSFP signals, for Port 1.
@@ -177,10 +178,12 @@ struct qib_qsfp_data {
        struct work_struct work;
        struct qib_qsfp_cache cache;
        u64 t_insert;
+       u8 modpresent;
 };
 
 extern int qib_refresh_qsfp_cache(struct qib_pportdata *ppd,
                                  struct qib_qsfp_cache *cp);
+extern int qib_qsfp_mod_present(struct qib_pportdata *ppd);
 extern void qib_qsfp_init(struct qib_qsfp_data *qd,
                          void (*fevent)(struct work_struct *));
 extern void qib_qsfp_deinit(struct qib_qsfp_data *qd);
index eca0c41f12269cfc18a43ab9f0b0ad58fc136aff..afaf4ac79f42d78a640501d0d0912dc6ec3e2ae0 100644 (file)
@@ -59,8 +59,7 @@ static void start_timer(struct qib_qp *qp)
        qp->s_flags |= QIB_S_TIMER;
        qp->s_timer.function = rc_timeout;
        /* 4.096 usec. * (1 << qp->timeout) */
-       qp->s_timer.expires = jiffies +
-               usecs_to_jiffies((4096UL * (1UL << qp->timeout)) / 1000UL);
+       qp->s_timer.expires = jiffies + qp->timeout_jiffies;
        add_timer(&qp->s_timer);
 }
 
@@ -239,7 +238,7 @@ int qib_make_rc_req(struct qib_qp *qp)
        u32 len;
        u32 bth0;
        u32 bth2;
-       u32 pmtu = ib_mtu_enum_to_int(qp->path_mtu);
+       u32 pmtu = qp->pmtu;
        char newreq;
        unsigned long flags;
        int ret = 0;
@@ -1519,9 +1518,7 @@ read_middle:
                 * 4.096 usec. * (1 << qp->timeout)
                 */
                qp->s_flags |= QIB_S_TIMER;
-               mod_timer(&qp->s_timer, jiffies +
-                       usecs_to_jiffies((4096UL * (1UL << qp->timeout)) /
-                                        1000UL));
+               mod_timer(&qp->s_timer, jiffies + qp->timeout_jiffies);
                if (qp->s_flags & QIB_S_WAIT_ACK) {
                        qp->s_flags &= ~QIB_S_WAIT_ACK;
                        qib_schedule_send(qp);
@@ -1732,7 +1729,7 @@ static int qib_rc_rcv_error(struct qib_other_headers *ohdr,
                 * same request.
                 */
                offset = ((psn - e->psn) & QIB_PSN_MASK) *
-                       ib_mtu_enum_to_int(qp->path_mtu);
+                       qp->pmtu;
                len = be32_to_cpu(reth->length);
                if (unlikely(offset + len != e->rdma_sge.sge_length))
                        goto unlock_done;
@@ -1876,7 +1873,7 @@ void qib_rc_rcv(struct qib_ctxtdata *rcd, struct qib_ib_header *hdr,
        u32 psn;
        u32 pad;
        struct ib_wc wc;
-       u32 pmtu = ib_mtu_enum_to_int(qp->path_mtu);
+       u32 pmtu = qp->pmtu;
        int diff;
        struct ib_reth *reth;
        unsigned long flags;
@@ -1892,10 +1889,8 @@ void qib_rc_rcv(struct qib_ctxtdata *rcd, struct qib_ib_header *hdr,
        }
 
        opcode = be32_to_cpu(ohdr->bth[0]);
-       spin_lock_irqsave(&qp->s_lock, flags);
        if (qib_ruc_check_hdr(ibp, hdr, has_grh, qp, opcode))
-               goto sunlock;
-       spin_unlock_irqrestore(&qp->s_lock, flags);
+               return;
 
        psn = be32_to_cpu(ohdr->bth[2]);
        opcode >>= 24;
@@ -1955,8 +1950,6 @@ void qib_rc_rcv(struct qib_ctxtdata *rcd, struct qib_ib_header *hdr,
                break;
        }
 
-       memset(&wc, 0, sizeof wc);
-
        if (qp->state == IB_QPS_RTR && !(qp->r_flags & QIB_R_COMM_EST)) {
                qp->r_flags |= QIB_R_COMM_EST;
                if (qp->ibqp.event_handler) {
@@ -2009,16 +2002,19 @@ send_middle:
                        goto rnr_nak;
                qp->r_rcv_len = 0;
                if (opcode == OP(SEND_ONLY))
-                       goto send_last;
-               /* FALLTHROUGH */
+                       goto no_immediate_data;
+               /* FALLTHROUGH for SEND_ONLY_WITH_IMMEDIATE */
        case OP(SEND_LAST_WITH_IMMEDIATE):
 send_last_imm:
                wc.ex.imm_data = ohdr->u.imm_data;
                hdrsize += 4;
                wc.wc_flags = IB_WC_WITH_IMM;
-               /* FALLTHROUGH */
+               goto send_last;
        case OP(SEND_LAST):
        case OP(RDMA_WRITE_LAST):
+no_immediate_data:
+               wc.wc_flags = 0;
+               wc.ex.imm_data = 0;
 send_last:
                /* Get the number of bytes the message was padded by. */
                pad = (be32_to_cpu(ohdr->bth[0]) >> 20) & 3;
@@ -2051,6 +2047,12 @@ send_last:
                wc.src_qp = qp->remote_qpn;
                wc.slid = qp->remote_ah_attr.dlid;
                wc.sl = qp->remote_ah_attr.sl;
+               /* zero fields that are N/A */
+               wc.vendor_err = 0;
+               wc.pkey_index = 0;
+               wc.dlid_path_bits = 0;
+               wc.port_num = 0;
+               wc.csum_ok = 0;
                /* Signal completion event if the solicited bit is set. */
                qib_cq_enter(to_icq(qp->ibqp.recv_cq), &wc,
                             (ohdr->bth[0] &
@@ -2089,7 +2091,7 @@ send_last:
                if (opcode == OP(RDMA_WRITE_FIRST))
                        goto send_middle;
                else if (opcode == OP(RDMA_WRITE_ONLY))
-                       goto send_last;
+                       goto no_immediate_data;
                ret = qib_get_rwqe(qp, 1);
                if (ret < 0)
                        goto nack_op_err;
index eb78d9367f06a6e358c7f3d504ed443bf6783983..b4b37e47321a9a27cb9b6afd2c1b0637c82b1c45 100644 (file)
@@ -260,12 +260,15 @@ static int gid_ok(union ib_gid *gid, __be64 gid_prefix, __be64 id)
 
 /*
  *
- * This should be called with the QP s_lock held.
+ * This should be called with the QP r_lock held.
+ *
+ * The s_lock will be acquired around the qib_migrate_qp() call.
  */
 int qib_ruc_check_hdr(struct qib_ibport *ibp, struct qib_ib_header *hdr,
                      int has_grh, struct qib_qp *qp, u32 bth0)
 {
        __be64 guid;
+       unsigned long flags;
 
        if (qp->s_mig_state == IB_MIG_ARMED && (bth0 & IB_BTH_MIG_REQ)) {
                if (!has_grh) {
@@ -295,7 +298,9 @@ int qib_ruc_check_hdr(struct qib_ibport *ibp, struct qib_ib_header *hdr,
                if (be16_to_cpu(hdr->lrh[3]) != qp->alt_ah_attr.dlid ||
                    ppd_from_ibp(ibp)->port != qp->alt_ah_attr.port_num)
                        goto err;
+               spin_lock_irqsave(&qp->s_lock, flags);
                qib_migrate_qp(qp);
+               spin_unlock_irqrestore(&qp->s_lock, flags);
        } else {
                if (!has_grh) {
                        if (qp->remote_ah_attr.ah_flags & IB_AH_GRH)
index c3ec8efc2ed810b2b0823a9cc4beec979b20886f..d6235931a1ba867afdd87806317891122ff38f51 100644 (file)
@@ -107,6 +107,11 @@ struct ib_srq *qib_create_srq(struct ib_pd *ibpd,
        u32 sz;
        struct ib_srq *ret;
 
+       if (srq_init_attr->srq_type != IB_SRQT_BASIC) {
+               ret = ERR_PTR(-ENOSYS);
+               goto done;
+       }
+
        if (srq_init_attr->attr.max_sge == 0 ||
            srq_init_attr->attr.max_sge > ib_qib_max_srq_sges ||
            srq_init_attr->attr.max_wr == 0 ||
index 14d129de43207e9385449402e6e5506068e656a6..78fbd56879d417610fc4b88dd4898741b56843d3 100644 (file)
@@ -515,8 +515,7 @@ static ssize_t show_nfreectxts(struct device *device,
        struct qib_devdata *dd = dd_from_dev(dev);
 
        /* Return the number of free user ports (contexts) available. */
-       return scnprintf(buf, PAGE_SIZE, "%u\n", dd->cfgctxts -
-               dd->first_user_ctxt - (u32)qib_stats.sps_ctxts);
+       return scnprintf(buf, PAGE_SIZE, "%u\n", dd->freectxts);
 }
 
 static ssize_t show_serial(struct device *device,
index 32ccf3c824ca5545bdf5972123016dca5fb110d4..847e7afdfd946ddc92697cac49713a0d21e9fca7 100644 (file)
@@ -51,7 +51,7 @@ int qib_make_uc_req(struct qib_qp *qp)
        u32 hwords;
        u32 bth0;
        u32 len;
-       u32 pmtu = ib_mtu_enum_to_int(qp->path_mtu);
+       u32 pmtu = qp->pmtu;
        int ret = 0;
 
        spin_lock_irqsave(&qp->s_lock, flags);
@@ -243,13 +243,12 @@ void qib_uc_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr,
                int has_grh, void *data, u32 tlen, struct qib_qp *qp)
 {
        struct qib_other_headers *ohdr;
-       unsigned long flags;
        u32 opcode;
        u32 hdrsize;
        u32 psn;
        u32 pad;
        struct ib_wc wc;
-       u32 pmtu = ib_mtu_enum_to_int(qp->path_mtu);
+       u32 pmtu = qp->pmtu;
        struct ib_reth *reth;
        int ret;
 
@@ -263,14 +262,11 @@ void qib_uc_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr,
        }
 
        opcode = be32_to_cpu(ohdr->bth[0]);
-       spin_lock_irqsave(&qp->s_lock, flags);
        if (qib_ruc_check_hdr(ibp, hdr, has_grh, qp, opcode))
-               goto sunlock;
-       spin_unlock_irqrestore(&qp->s_lock, flags);
+               return;
 
        psn = be32_to_cpu(ohdr->bth[2]);
        opcode >>= 24;
-       memset(&wc, 0, sizeof wc);
 
        /* Compare the PSN verses the expected PSN. */
        if (unlikely(qib_cmp24(psn, qp->r_psn) != 0)) {
@@ -370,7 +366,7 @@ send_first:
                }
                qp->r_rcv_len = 0;
                if (opcode == OP(SEND_ONLY))
-                       goto send_last;
+                       goto no_immediate_data;
                else if (opcode == OP(SEND_ONLY_WITH_IMMEDIATE))
                        goto send_last_imm;
                /* FALLTHROUGH */
@@ -389,8 +385,11 @@ send_last_imm:
                wc.ex.imm_data = ohdr->u.imm_data;
                hdrsize += 4;
                wc.wc_flags = IB_WC_WITH_IMM;
-               /* FALLTHROUGH */
+               goto send_last;
        case OP(SEND_LAST):
+no_immediate_data:
+               wc.ex.imm_data = 0;
+               wc.wc_flags = 0;
 send_last:
                /* Get the number of bytes the message was padded by. */
                pad = (be32_to_cpu(ohdr->bth[0]) >> 20) & 3;
@@ -418,6 +417,12 @@ last_imm:
                wc.src_qp = qp->remote_qpn;
                wc.slid = qp->remote_ah_attr.dlid;
                wc.sl = qp->remote_ah_attr.sl;
+               /* zero fields that are N/A */
+               wc.vendor_err = 0;
+               wc.pkey_index = 0;
+               wc.dlid_path_bits = 0;
+               wc.port_num = 0;
+               wc.csum_ok = 0;
                /* Signal completion event if the solicited bit is set. */
                qib_cq_enter(to_icq(qp->ibqp.recv_cq), &wc,
                             (ohdr->bth[0] &
@@ -546,6 +551,4 @@ op_err:
        qib_rc_error(qp, IB_WC_LOC_QP_OP_ERR);
        return;
 
-sunlock:
-       spin_unlock_irqrestore(&qp->s_lock, flags);
 }
index 7689e49c13c9c80fe6857659bb24dff02c9b16f1..2bc1d2b96298dd5d59029cb141d83a715ab51f54 100644 (file)
@@ -74,7 +74,7 @@ static int __qib_get_user_pages(unsigned long start_page, size_t num_pages,
                        goto bail_release;
        }
 
-       current->mm->locked_vm += num_pages;
+       current->mm->pinned_vm += num_pages;
 
        ret = 0;
        goto bail;
@@ -151,7 +151,7 @@ void qib_release_user_pages(struct page **p, size_t num_pages)
        __qib_release_user_pages(p, num_pages, 1);
 
        if (current->mm) {
-               current->mm->locked_vm -= num_pages;
+               current->mm->pinned_vm -= num_pages;
                up_write(&current->mm->mmap_sem);
        }
 }
index 9fab404888505be57b9fdbc1f813f3ae28e290c1..9627cb7371250e0bd37355912cd866ff50cfaaa7 100644 (file)
 #include <linux/utsname.h>
 #include <linux/rculist.h>
 #include <linux/mm.h>
+#include <linux/random.h>
 
 #include "qib.h"
 #include "qib_common.h"
 
-static unsigned int ib_qib_qp_table_size = 251;
+static unsigned int ib_qib_qp_table_size = 256;
 module_param_named(qp_table_size, ib_qib_qp_table_size, uint, S_IRUGO);
 MODULE_PARM_DESC(qp_table_size, "QP table size");
 
@@ -659,17 +660,25 @@ void qib_ib_rcv(struct qib_ctxtdata *rcd, void *rhdr, void *data, u32 tlen)
                if (atomic_dec_return(&mcast->refcount) <= 1)
                        wake_up(&mcast->wait);
        } else {
-               qp = qib_lookup_qpn(ibp, qp_num);
-               if (!qp)
-                       goto drop;
+               if (rcd->lookaside_qp) {
+                       if (rcd->lookaside_qpn != qp_num) {
+                               if (atomic_dec_and_test(
+                                       &rcd->lookaside_qp->refcount))
+                                       wake_up(
+                                        &rcd->lookaside_qp->wait);
+                                       rcd->lookaside_qp = NULL;
+                               }
+               }
+               if (!rcd->lookaside_qp) {
+                       qp = qib_lookup_qpn(ibp, qp_num);
+                       if (!qp)
+                               goto drop;
+                       rcd->lookaside_qp = qp;
+                       rcd->lookaside_qpn = qp_num;
+               } else
+                       qp = rcd->lookaside_qp;
                ibp->n_unicast_rcv++;
                qib_qp_rcv(rcd, hdr, lnh == QIB_LRH_GRH, data, tlen, qp);
-               /*
-                * Notify qib_destroy_qp() if it is waiting
-                * for us to finish.
-                */
-               if (atomic_dec_and_test(&qp->refcount))
-                       wake_up(&qp->wait);
        }
        return;
 
@@ -1974,6 +1983,8 @@ static void init_ibport(struct qib_pportdata *ppd)
        ibp->z_excessive_buffer_overrun_errors =
                cntrs.excessive_buffer_overrun_errors;
        ibp->z_vl15_dropped = cntrs.vl15_dropped;
+       RCU_INIT_POINTER(ibp->qp0, NULL);
+       RCU_INIT_POINTER(ibp->qp1, NULL);
 }
 
 /**
@@ -1990,12 +2001,15 @@ int qib_register_ib_device(struct qib_devdata *dd)
        int ret;
 
        dev->qp_table_size = ib_qib_qp_table_size;
-       dev->qp_table = kzalloc(dev->qp_table_size * sizeof *dev->qp_table,
+       get_random_bytes(&dev->qp_rnd, sizeof(dev->qp_rnd));
+       dev->qp_table = kmalloc(dev->qp_table_size * sizeof *dev->qp_table,
                                GFP_KERNEL);
        if (!dev->qp_table) {
                ret = -ENOMEM;
                goto err_qpt;
        }
+       for (i = 0; i < dev->qp_table_size; i++)
+               RCU_INIT_POINTER(dev->qp_table[i], NULL);
 
        for (i = 0; i < dd->num_pports; i++)
                init_ibport(ppd + i);
index 95e5b47223b33d0d2f6a0b81b35ab25bf8de7ad0..0c19ef0c41233de4efaf25db3eb1886213a3407b 100644 (file)
@@ -485,6 +485,7 @@ struct qib_qp {
        u8 alt_timeout;         /* Alternate path timeout for this QP */
        u8 port_num;
        enum ib_mtu path_mtu;
+       u32 pmtu;               /* decoded from path_mtu */
        u32 remote_qpn;
        u32 qkey;               /* QKEY for this QP (for UD or RD) */
        u32 s_size;             /* send work queue size */
@@ -495,6 +496,7 @@ struct qib_qp {
        u32 s_last;             /* last completed entry */
        u32 s_ssn;              /* SSN of tail entry */
        u32 s_lsn;              /* limit sequence number (credit) */
+       unsigned long timeout_jiffies;  /* computed from timeout */
        struct qib_swqe *s_wq;  /* send work queue */
        struct qib_swqe *s_wqe;
        struct qib_rq r_rq;             /* receive work queue */
@@ -723,7 +725,8 @@ struct qib_ibdev {
        dma_addr_t pio_hdrs_phys;
        /* list of QPs waiting for RNR timer */
        spinlock_t pending_lock; /* protect wait lists, PMA counters, etc. */
-       unsigned qp_table_size; /* size of the hash table */
+       u32 qp_table_size; /* size of the hash table */
+       u32 qp_rnd; /* random bytes for hash */
        spinlock_t qpt_lock;
 
        u32 n_piowait;
index c74548a586ea48db6ee10ad5d61042158d7530b2..231c2f2f52f8ecac55741169701a37fe44bf2a86 100644 (file)
@@ -84,7 +84,7 @@ static void ipoib_cm_dma_unmap_rx(struct ipoib_dev_priv *priv, int frags,
        ib_dma_unmap_single(priv->ca, mapping[0], IPOIB_CM_HEAD_SIZE, DMA_FROM_DEVICE);
 
        for (i = 0; i < frags; ++i)
-               ib_dma_unmap_single(priv->ca, mapping[i + 1], PAGE_SIZE, DMA_FROM_DEVICE);
+               ib_dma_unmap_page(priv->ca, mapping[i + 1], PAGE_SIZE, DMA_FROM_DEVICE);
 }
 
 static int ipoib_cm_post_receive_srq(struct net_device *dev, int id)
@@ -183,7 +183,7 @@ partial_error:
        ib_dma_unmap_single(priv->ca, mapping[0], IPOIB_CM_HEAD_SIZE, DMA_FROM_DEVICE);
 
        for (; i > 0; --i)
-               ib_dma_unmap_single(priv->ca, mapping[i], PAGE_SIZE, DMA_FROM_DEVICE);
+               ib_dma_unmap_page(priv->ca, mapping[i], PAGE_SIZE, DMA_FROM_DEVICE);
 
        dev_kfree_skb_any(skb);
        return NULL;
@@ -1497,6 +1497,7 @@ static void ipoib_cm_create_srq(struct net_device *dev, int max_sge)
 {
        struct ipoib_dev_priv *priv = netdev_priv(dev);
        struct ib_srq_init_attr srq_init_attr = {
+               .srq_type = IB_SRQT_BASIC,
                .attr = {
                        .max_wr  = ipoib_recvq_size,
                        .max_sge = max_sge
index 86eae229dc49eb5c12d517f4c6c8d60a139160e6..0e2fe4631ba86f03d5fc26dbf208e68a61169a42 100644 (file)
@@ -212,16 +212,15 @@ static int ipoib_path_seq_show(struct seq_file *file, void *iter_ptr)
                   gid_buf, path.pathrec.dlid ? "yes" : "no");
 
        if (path.pathrec.dlid) {
-               rate = ib_rate_to_mult(path.pathrec.rate) * 25;
+               rate = ib_rate_to_mbps(path.pathrec.rate);
 
                seq_printf(file,
                           "  DLID:     0x%04x\n"
                           "  SL: %12d\n"
-                          "  rate: %*d%s Gb/sec\n",
+                          "  rate: %8d.%d Gb/sec\n",
                           be16_to_cpu(path.pathrec.dlid),
                           path.pathrec.sl,
-                          10 - ((rate % 10) ? 2 : 0),
-                          rate / 10, rate % 10 ? ".5" : "");
+                          rate / 1000, rate % 1000);
        }
 
        seq_putc(file, '\n');
index 9c61b9c2c597a9e515af791faa6e16f87a95cfc3..84e8c293a71550990e044bce646c55e462dde836 100644 (file)
@@ -632,6 +632,59 @@ iscsi_iser_ep_disconnect(struct iscsi_endpoint *ep)
        iser_conn_terminate(ib_conn);
 }
 
+static mode_t iser_attr_is_visible(int param_type, int param)
+{
+       switch (param_type) {
+       case ISCSI_HOST_PARAM:
+               switch (param) {
+               case ISCSI_HOST_PARAM_NETDEV_NAME:
+               case ISCSI_HOST_PARAM_HWADDRESS:
+               case ISCSI_HOST_PARAM_INITIATOR_NAME:
+                       return S_IRUGO;
+               default:
+                       return 0;
+               }
+       case ISCSI_PARAM:
+               switch (param) {
+               case ISCSI_PARAM_MAX_RECV_DLENGTH:
+               case ISCSI_PARAM_MAX_XMIT_DLENGTH:
+               case ISCSI_PARAM_HDRDGST_EN:
+               case ISCSI_PARAM_DATADGST_EN:
+               case ISCSI_PARAM_CONN_ADDRESS:
+               case ISCSI_PARAM_CONN_PORT:
+               case ISCSI_PARAM_EXP_STATSN:
+               case ISCSI_PARAM_PERSISTENT_ADDRESS:
+               case ISCSI_PARAM_PERSISTENT_PORT:
+               case ISCSI_PARAM_PING_TMO:
+               case ISCSI_PARAM_RECV_TMO:
+               case ISCSI_PARAM_INITIAL_R2T_EN:
+               case ISCSI_PARAM_MAX_R2T:
+               case ISCSI_PARAM_IMM_DATA_EN:
+               case ISCSI_PARAM_FIRST_BURST:
+               case ISCSI_PARAM_MAX_BURST:
+               case ISCSI_PARAM_PDU_INORDER_EN:
+               case ISCSI_PARAM_DATASEQ_INORDER_EN:
+               case ISCSI_PARAM_TARGET_NAME:
+               case ISCSI_PARAM_TPGT:
+               case ISCSI_PARAM_USERNAME:
+               case ISCSI_PARAM_PASSWORD:
+               case ISCSI_PARAM_USERNAME_IN:
+               case ISCSI_PARAM_PASSWORD_IN:
+               case ISCSI_PARAM_FAST_ABORT:
+               case ISCSI_PARAM_ABORT_TMO:
+               case ISCSI_PARAM_LU_RESET_TMO:
+               case ISCSI_PARAM_TGT_RESET_TMO:
+               case ISCSI_PARAM_IFACE_NAME:
+               case ISCSI_PARAM_INITIATOR_NAME:
+                       return S_IRUGO;
+               default:
+                       return 0;
+               }
+       }
+
+       return 0;
+}
+
 static struct scsi_host_template iscsi_iser_sht = {
        .module                 = THIS_MODULE,
        .name                   = "iSCSI Initiator over iSER, v." DRV_VER,
@@ -653,32 +706,6 @@ static struct iscsi_transport iscsi_iser_transport = {
        .owner                  = THIS_MODULE,
        .name                   = "iser",
        .caps                   = CAP_RECOVERY_L0 | CAP_MULTI_R2T,
-       .param_mask             = ISCSI_MAX_RECV_DLENGTH |
-                                 ISCSI_MAX_XMIT_DLENGTH |
-                                 ISCSI_HDRDGST_EN |
-                                 ISCSI_DATADGST_EN |
-                                 ISCSI_INITIAL_R2T_EN |
-                                 ISCSI_MAX_R2T |
-                                 ISCSI_IMM_DATA_EN |
-                                 ISCSI_FIRST_BURST |
-                                 ISCSI_MAX_BURST |
-                                 ISCSI_PDU_INORDER_EN |
-                                 ISCSI_DATASEQ_INORDER_EN |
-                                 ISCSI_CONN_PORT |
-                                 ISCSI_CONN_ADDRESS |
-                                 ISCSI_EXP_STATSN |
-                                 ISCSI_PERSISTENT_PORT |
-                                 ISCSI_PERSISTENT_ADDRESS |
-                                 ISCSI_TARGET_NAME | ISCSI_TPGT |
-                                 ISCSI_USERNAME | ISCSI_PASSWORD |
-                                 ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN |
-                                 ISCSI_FAST_ABORT | ISCSI_ABORT_TMO |
-                                 ISCSI_LU_RESET_TMO | ISCSI_TGT_RESET_TMO |
-                                 ISCSI_PING_TMO | ISCSI_RECV_TMO |
-                                 ISCSI_IFACE_NAME | ISCSI_INITIATOR_NAME,
-       .host_param_mask        = ISCSI_HOST_HWADDRESS |
-                                 ISCSI_HOST_NETDEV_NAME |
-                                 ISCSI_HOST_INITIATOR_NAME,
        /* session management */
        .create_session         = iscsi_iser_session_create,
        .destroy_session        = iscsi_iser_session_destroy,
@@ -686,6 +713,7 @@ static struct iscsi_transport iscsi_iser_transport = {
        .create_conn            = iscsi_iser_conn_create,
        .bind_conn              = iscsi_iser_conn_bind,
        .destroy_conn           = iscsi_iser_conn_destroy,
+       .attr_is_visible        = iser_attr_is_visible,
        .set_param              = iscsi_iser_set_param,
        .get_conn_param         = iscsi_conn_get_param,
        .get_ep_param           = iscsi_iser_get_ep_param,
index a1aa35a053b732a7496ab23c0740ddac42e840b2..56aa465d1b9975d663504490740922183db64449 100644 (file)
@@ -217,22 +217,6 @@ config INPUT_ATLAS_BTNS
          To compile this driver as a module, choose M here: the module will
          be called atlas_btns.
 
-config INPUT_ATI_REMOTE
-       tristate "ATI / X10 USB RF remote control"
-       depends on USB_ARCH_HAS_HCD
-       select USB
-       help
-         Say Y here if you want to use an ATI or X10 "Lola" USB remote control.
-         These are RF remotes with USB receivers.
-         The ATI remote comes with many of ATI's All-In-Wonder video cards.
-         The X10 "Lola" remote is available at:
-            <http://www.x10.com/products/lola_sg1.htm>
-         This driver provides mouse pointer, left and right mouse buttons,
-         and maps all the other remote buttons to keypress events.
-
-         To compile this driver as a module, choose M here: the module will be
-         called ati_remote.
-
 config INPUT_ATI_REMOTE2
        tristate "ATI / Philips USB RF remote control"
        depends on USB_ARCH_HAS_HCD
index 53a8d0faad52fcebec83d70056ddc7ffd592a264..62dcd79d548f8bf0acab7e88f517a61047357ddc 100644 (file)
@@ -13,7 +13,6 @@ obj-$(CONFIG_INPUT_ADXL34X)           += adxl34x.o
 obj-$(CONFIG_INPUT_ADXL34X_I2C)                += adxl34x-i2c.o
 obj-$(CONFIG_INPUT_ADXL34X_SPI)                += adxl34x-spi.o
 obj-$(CONFIG_INPUT_APANEL)             += apanel.o
-obj-$(CONFIG_INPUT_ATI_REMOTE)         += ati_remote.o
 obj-$(CONFIG_INPUT_ATI_REMOTE2)                += ati_remote2.o
 obj-$(CONFIG_INPUT_ATLAS_BTNS)         += atlas_btns.o
 obj-$(CONFIG_INPUT_BFIN_ROTARY)                += bfin_rotary.o
index 23855e12a30b362ef124b3c83b404d59c732c11d..ad153a417eed98a7fff70945f684becc76581b96 100644 (file)
@@ -74,12 +74,12 @@ static irqreturn_t twl6040_vib_irq_handler(int irq, void *data)
        if (status & TWL6040_VIBLOCDET) {
                dev_warn(info->dev, "Left Vibrator overcurrent detected\n");
                twl6040_clear_bits(twl6040, TWL6040_REG_VIBCTLL,
-                                  TWL6040_VIBENAL);
+                                  TWL6040_VIBENA);
        }
        if (status & TWL6040_VIBROCDET) {
                dev_warn(info->dev, "Right Vibrator overcurrent detected\n");
                twl6040_clear_bits(twl6040, TWL6040_REG_VIBCTLR,
-                                  TWL6040_VIBENAR);
+                                  TWL6040_VIBENA);
        }
 
        return IRQ_HANDLED;
@@ -97,23 +97,23 @@ static void twl6040_vibra_enable(struct vibra_info *info)
        }
 
        twl6040_power(info->twl6040, 1);
-       if (twl6040->rev <= TWL6040_REV_ES1_1) {
+       if (twl6040_get_revid(twl6040) <= TWL6040_REV_ES1_1) {
                /*
                 * ERRATA: Disable overcurrent protection for at least
                 * 3ms when enabling vibrator drivers to avoid false
                 * overcurrent detection
                 */
                twl6040_reg_write(twl6040, TWL6040_REG_VIBCTLL,
-                                 TWL6040_VIBENAL | TWL6040_VIBCTRLL);
+                                 TWL6040_VIBENA | TWL6040_VIBCTRL);
                twl6040_reg_write(twl6040, TWL6040_REG_VIBCTLR,
-                                 TWL6040_VIBENAR | TWL6040_VIBCTRLR);
+                                 TWL6040_VIBENA | TWL6040_VIBCTRL);
                usleep_range(3000, 3500);
        }
 
        twl6040_reg_write(twl6040, TWL6040_REG_VIBCTLL,
-                         TWL6040_VIBENAL);
+                         TWL6040_VIBENA);
        twl6040_reg_write(twl6040, TWL6040_REG_VIBCTLR,
-                         TWL6040_VIBENAR);
+                         TWL6040_VIBENA);
 
        info->enabled = true;
 }
@@ -201,6 +201,13 @@ static int vibra_play(struct input_dev *input, void *data,
        struct vibra_info *info = input_get_drvdata(input);
        int ret;
 
+       /* Do not allow effect, while the routing is set to use audio */
+       ret = twl6040_get_vibralr_status(info->twl6040);
+       if (ret & TWL6040_VIBSEL) {
+               dev_info(&input->dev, "Vibra is configured for audio\n");
+               return -EBUSY;
+       }
+
        info->weak_speed = effect->u.rumble.weak_magnitude;
        info->strong_speed = effect->u.rumble.strong_magnitude;
        info->direction = effect->direction < EFFECT_DIR_180_DEG ? 1 : -1;
index 7d7eaa15e7734efd9a07af167cf3453b65b406c4..5414253b185a3ada15daa7c4adc423d65dfe0285 100644 (file)
@@ -112,4 +112,23 @@ config IRQ_REMAP
          To use x2apic mode in the CPU's which support x2APIC enhancements or
          to support platforms with CPU's having > 8 bit APIC ID, say Y.
 
+# OMAP IOMMU support
+config OMAP_IOMMU
+       bool "OMAP IOMMU Support"
+       depends on ARCH_OMAP
+       select IOMMU_API
+
+config OMAP_IOVMM
+       tristate "OMAP IO Virtual Memory Manager Support"
+       depends on OMAP_IOMMU
+
+config OMAP_IOMMU_DEBUG
+       tristate "Export OMAP IOMMU/IOVMM internals in DebugFS"
+       depends on OMAP_IOVMM && DEBUG_FS
+       help
+         Select this to see extensive information about
+         the internal state of OMAP IOMMU/IOVMM in debugfs.
+
+         Say N unless you know you need this.
+
 endif # IOMMU_SUPPORT
index 6394994a2b9dafff89522e1bb22ad021c09d30fb..2f4448794bc793133d5f1e8a3145be4c1cc685b3 100644 (file)
@@ -4,3 +4,6 @@ obj-$(CONFIG_AMD_IOMMU) += amd_iommu.o amd_iommu_init.o
 obj-$(CONFIG_DMAR_TABLE) += dmar.o
 obj-$(CONFIG_INTEL_IOMMU) += iova.o intel-iommu.o
 obj-$(CONFIG_IRQ_REMAP) += intr_remapping.o
+obj-$(CONFIG_OMAP_IOMMU) += omap-iommu.o
+obj-$(CONFIG_OMAP_IOVMM) += omap-iovmm.o
+obj-$(CONFIG_OMAP_IOMMU_DEBUG) += omap-iommu-debug.o
index 0e4227f457af38c9e1c6fc6bf1e065b94e1e9c4f..4ee277a8521a49eb41b5056daebf13cadc3d68dd 100644 (file)
@@ -1283,7 +1283,7 @@ static int alloc_new_range(struct dma_ops_domain *dma_dom,
                if (!pte || !IOMMU_PTE_PRESENT(*pte))
                        continue;
 
-               dma_ops_reserve_addresses(dma_dom, i << PAGE_SHIFT, 1);
+               dma_ops_reserve_addresses(dma_dom, i >> PAGE_SHIFT, 1);
        }
 
        update_domain(&dma_dom->domain);
@@ -2495,7 +2495,7 @@ static unsigned device_dma_ops_init(void)
 
 void __init amd_iommu_init_api(void)
 {
-       register_iommu(&amd_iommu_ops);
+       bus_set_iommu(&pci_bus_type, &amd_iommu_ops);
 }
 
 int __init amd_iommu_init_dma_ops(void)
index be1953c239b0f557348da28b23d8bd2b2d72653f..bb161d2fa03cbc7bbef23977cb5fc7c530329ef2 100644 (file)
@@ -3642,7 +3642,7 @@ int __init intel_iommu_init(void)
 
        init_iommu_pm_ops();
 
-       register_iommu(&intel_iommu_ops);
+       bus_set_iommu(&pci_bus_type, &intel_iommu_ops);
 
        bus_register_notifier(&pci_bus_type, &device_nb);
 
index 6e6b6a11b3ced64d1c90e3c9d35d25823f6b5ccf..2fb2963df55376a3a8efbf09490457e08b28b836 100644 (file)
@@ -16,6 +16,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  */
 
+#include <linux/device.h>
+#include <linux/kernel.h>
 #include <linux/bug.h>
 #include <linux/types.h>
 #include <linux/module.h>
 #include <linux/errno.h>
 #include <linux/iommu.h>
 
-static struct iommu_ops *iommu_ops;
+static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
+{
+}
 
-void register_iommu(struct iommu_ops *ops)
+/**
+ * bus_set_iommu - set iommu-callbacks for the bus
+ * @bus: bus.
+ * @ops: the callbacks provided by the iommu-driver
+ *
+ * This function is called by an iommu driver to set the iommu methods
+ * used for a particular bus. Drivers for devices on that bus can use
+ * the iommu-api after these ops are registered.
+ * This special function is needed because IOMMUs are usually devices on
+ * the bus itself, so the iommu drivers are not initialized when the bus
+ * is set up. With this function the iommu-driver can set the iommu-ops
+ * afterwards.
+ */
+int bus_set_iommu(struct bus_type *bus, struct iommu_ops *ops)
 {
-       if (iommu_ops)
-               BUG();
+       if (bus->iommu_ops != NULL)
+               return -EBUSY;
+
+       bus->iommu_ops = ops;
+
+       /* Do IOMMU specific setup for this bus-type */
+       iommu_bus_init(bus, ops);
 
-       iommu_ops = ops;
+       return 0;
 }
+EXPORT_SYMBOL_GPL(bus_set_iommu);
 
-bool iommu_found(void)
+bool iommu_present(struct bus_type *bus)
 {
-       return iommu_ops != NULL;
+       return bus->iommu_ops != NULL;
 }
-EXPORT_SYMBOL_GPL(iommu_found);
+EXPORT_SYMBOL_GPL(iommu_present);
 
-struct iommu_domain *iommu_domain_alloc(void)
+/**
+ * iommu_set_fault_handler() - set a fault handler for an iommu domain
+ * @domain: iommu domain
+ * @handler: fault handler
+ *
+ * This function should be used by IOMMU users which want to be notified
+ * whenever an IOMMU fault happens.
+ *
+ * The fault handler itself should return 0 on success, and an appropriate
+ * error code otherwise.
+ */
+void iommu_set_fault_handler(struct iommu_domain *domain,
+                                       iommu_fault_handler_t handler)
+{
+       BUG_ON(!domain);
+
+       domain->handler = handler;
+}
+EXPORT_SYMBOL_GPL(iommu_set_fault_handler);
+
+struct iommu_domain *iommu_domain_alloc(struct bus_type *bus)
 {
        struct iommu_domain *domain;
        int ret;
 
+       if (bus == NULL || bus->iommu_ops == NULL)
+               return NULL;
+
        domain = kmalloc(sizeof(*domain), GFP_KERNEL);
        if (!domain)
                return NULL;
 
-       ret = iommu_ops->domain_init(domain);
+       domain->ops = bus->iommu_ops;
+
+       ret = domain->ops->domain_init(domain);
        if (ret)
                goto out_free;
 
@@ -63,62 +111,78 @@ EXPORT_SYMBOL_GPL(iommu_domain_alloc);
 
 void iommu_domain_free(struct iommu_domain *domain)
 {
-       iommu_ops->domain_destroy(domain);
+       if (likely(domain->ops->domain_destroy != NULL))
+               domain->ops->domain_destroy(domain);
+
        kfree(domain);
 }
 EXPORT_SYMBOL_GPL(iommu_domain_free);
 
 int iommu_attach_device(struct iommu_domain *domain, struct device *dev)
 {
-       return iommu_ops->attach_dev(domain, dev);
+       if (unlikely(domain->ops->attach_dev == NULL))
+               return -ENODEV;
+
+       return domain->ops->attach_dev(domain, dev);
 }
 EXPORT_SYMBOL_GPL(iommu_attach_device);
 
 void iommu_detach_device(struct iommu_domain *domain, struct device *dev)
 {
-       iommu_ops->detach_dev(domain, dev);
+       if (unlikely(domain->ops->detach_dev == NULL))
+               return;
+
+       domain->ops->detach_dev(domain, dev);
 }
 EXPORT_SYMBOL_GPL(iommu_detach_device);
 
 phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain,
                               unsigned long iova)
 {
-       return iommu_ops->iova_to_phys(domain, iova);
+       if (unlikely(domain->ops->iova_to_phys == NULL))
+               return 0;
+
+       return domain->ops->iova_to_phys(domain, iova);
 }
 EXPORT_SYMBOL_GPL(iommu_iova_to_phys);
 
 int iommu_domain_has_cap(struct iommu_domain *domain,
                         unsigned long cap)
 {
-       return iommu_ops->domain_has_cap(domain, cap);
+       if (unlikely(domain->ops->domain_has_cap == NULL))
+               return 0;
+
+       return domain->ops->domain_has_cap(domain, cap);
 }
 EXPORT_SYMBOL_GPL(iommu_domain_has_cap);
 
 int iommu_map(struct iommu_domain *domain, unsigned long iova,
              phys_addr_t paddr, int gfp_order, int prot)
 {
-       unsigned long invalid_mask;
        size_t size;
 
-       size         = 0x1000UL << gfp_order;
-       invalid_mask = size - 1;
+       if (unlikely(domain->ops->map == NULL))
+               return -ENODEV;
 
-       BUG_ON((iova | paddr) & invalid_mask);
+       size         = PAGE_SIZE << gfp_order;
 
-       return iommu_ops->map(domain, iova, paddr, gfp_order, prot);
+       BUG_ON(!IS_ALIGNED(iova | paddr, size));
+
+       return domain->ops->map(domain, iova, paddr, gfp_order, prot);
 }
 EXPORT_SYMBOL_GPL(iommu_map);
 
 int iommu_unmap(struct iommu_domain *domain, unsigned long iova, int gfp_order)
 {
-       unsigned long invalid_mask;
        size_t size;
 
-       size         = 0x1000UL << gfp_order;
-       invalid_mask = size - 1;
+       if (unlikely(domain->ops->unmap == NULL))
+               return -ENODEV;
+
+       size         = PAGE_SIZE << gfp_order;
 
-       BUG_ON(iova & invalid_mask);
+       BUG_ON(!IS_ALIGNED(iova, size));
 
-       return iommu_ops->unmap(domain, iova, gfp_order);
+       return domain->ops->unmap(domain, iova, gfp_order);
 }
 EXPORT_SYMBOL_GPL(iommu_unmap);
index 1a584e077c61fa36b00f0dc273b600a87ea1b726..5865dd2e28f928b0cf55ff1c5ebddfe5786e1d16 100644 (file)
@@ -543,6 +543,13 @@ static int msm_iommu_unmap(struct iommu_domain *domain, unsigned long va,
        }
 
        ret = __flush_iotlb(domain);
+
+       /*
+        * the IOMMU API requires us to return the order of the unmapped
+        * page (on success).
+        */
+       if (!ret)
+               ret = order;
 fail:
        spin_unlock_irqrestore(&msm_iommu_lock, flags);
        return ret;
@@ -721,7 +728,7 @@ static void __init setup_iommu_tex_classes(void)
 static int __init msm_iommu_init(void)
 {
        setup_iommu_tex_classes();
-       register_iommu(&msm_iommu_ops);
+       bus_set_iommu(&platform_bus_type, &msm_iommu_ops);
        return 0;
 }
 
similarity index 91%
rename from arch/arm/plat-omap/iommu-debug.c
rename to drivers/iommu/omap-iommu-debug.c
index f07cf2f08e09479045d3b7e3c8c6b1c0458c59f9..9c192e79f806836be3ef688821c897be30dd6142 100644 (file)
@@ -21,7 +21,7 @@
 #include <plat/iommu.h>
 #include <plat/iovmm.h>
 
-#include "iopgtable.h"
+#include <plat/iopgtable.h>
 
 #define MAXCOLUMN 100 /* for short messages */
 
@@ -32,7 +32,7 @@ static struct dentry *iommu_debug_root;
 static ssize_t debug_read_ver(struct file *file, char __user *userbuf,
                              size_t count, loff_t *ppos)
 {
-       u32 ver = iommu_arch_version();
+       u32 ver = omap_iommu_arch_version();
        char buf[MAXCOLUMN], *p = buf;
 
        p += sprintf(p, "H/W version: %d.%d\n", (ver >> 4) & 0xf , ver & 0xf);
@@ -43,7 +43,7 @@ static ssize_t debug_read_ver(struct file *file, char __user *userbuf,
 static ssize_t debug_read_regs(struct file *file, char __user *userbuf,
                               size_t count, loff_t *ppos)
 {
-       struct iommu *obj = file->private_data;
+       struct omap_iommu *obj = file->private_data;
        char *p, *buf;
        ssize_t bytes;
 
@@ -54,7 +54,7 @@ static ssize_t debug_read_regs(struct file *file, char __user *userbuf,
 
        mutex_lock(&iommu_debug_lock);
 
-       bytes = iommu_dump_ctx(obj, p, count);
+       bytes = omap_iommu_dump_ctx(obj, p, count);
        bytes = simple_read_from_buffer(userbuf, count, ppos, buf, bytes);
 
        mutex_unlock(&iommu_debug_lock);
@@ -66,7 +66,7 @@ static ssize_t debug_read_regs(struct file *file, char __user *userbuf,
 static ssize_t debug_read_tlb(struct file *file, char __user *userbuf,
                              size_t count, loff_t *ppos)
 {
-       struct iommu *obj = file->private_data;
+       struct omap_iommu *obj = file->private_data;
        char *p, *buf;
        ssize_t bytes, rest;
 
@@ -80,7 +80,7 @@ static ssize_t debug_read_tlb(struct file *file, char __user *userbuf,
        p += sprintf(p, "%8s %8s\n", "cam:", "ram:");
        p += sprintf(p, "-----------------------------------------\n");
        rest = count - (p - buf);
-       p += dump_tlb_entries(obj, p, rest);
+       p += omap_dump_tlb_entries(obj, p, rest);
 
        bytes = simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
 
@@ -96,7 +96,7 @@ static ssize_t debug_write_pagetable(struct file *file,
        struct iotlb_entry e;
        struct cr_regs cr;
        int err;
-       struct iommu *obj = file->private_data;
+       struct omap_iommu *obj = file->private_data;
        char buf[MAXCOLUMN], *p = buf;
 
        count = min(count, sizeof(buf));
@@ -113,8 +113,8 @@ static ssize_t debug_write_pagetable(struct file *file,
                return -EINVAL;
        }
 
-       iotlb_cr_to_e(&cr, &e);
-       err = iopgtable_store_entry(obj, &e);
+       omap_iotlb_cr_to_e(&cr, &e);
+       err = omap_iopgtable_store_entry(obj, &e);
        if (err)
                dev_err(obj->dev, "%s: fail to store cr\n", __func__);
 
@@ -136,7 +136,7 @@ static ssize_t debug_write_pagetable(struct file *file,
                __err;                                          \
        })
 
-static ssize_t dump_ioptable(struct iommu *obj, char *buf, ssize_t len)
+static ssize_t dump_ioptable(struct omap_iommu *obj, char *buf, ssize_t len)
 {
        int i;
        u32 *iopgd;
@@ -183,7 +183,7 @@ out:
 static ssize_t debug_read_pagetable(struct file *file, char __user *userbuf,
                                    size_t count, loff_t *ppos)
 {
-       struct iommu *obj = file->private_data;
+       struct omap_iommu *obj = file->private_data;
        char *p, *buf;
        size_t bytes;
 
@@ -211,7 +211,7 @@ static ssize_t debug_read_pagetable(struct file *file, char __user *userbuf,
 static ssize_t debug_read_mmap(struct file *file, char __user *userbuf,
                               size_t count, loff_t *ppos)
 {
-       struct iommu *obj = file->private_data;
+       struct omap_iommu *obj = file->private_data;
        char *p, *buf;
        struct iovm_struct *tmp;
        int uninitialized_var(i);
@@ -253,7 +253,7 @@ static ssize_t debug_read_mmap(struct file *file, char __user *userbuf,
 static ssize_t debug_read_mem(struct file *file, char __user *userbuf,
                              size_t count, loff_t *ppos)
 {
-       struct iommu *obj = file->private_data;
+       struct omap_iommu *obj = file->private_data;
        char *p, *buf;
        struct iovm_struct *area;
        ssize_t bytes;
@@ -267,7 +267,7 @@ static ssize_t debug_read_mem(struct file *file, char __user *userbuf,
 
        mutex_lock(&iommu_debug_lock);
 
-       area = find_iovm_area(obj, (u32)ppos);
+       area = omap_find_iovm_area(obj, (u32)ppos);
        if (IS_ERR(area)) {
                bytes = -EINVAL;
                goto err_out;
@@ -286,7 +286,7 @@ err_out:
 static ssize_t debug_write_mem(struct file *file, const char __user *userbuf,
                               size_t count, loff_t *ppos)
 {
-       struct iommu *obj = file->private_data;
+       struct omap_iommu *obj = file->private_data;
        struct iovm_struct *area;
        char *p, *buf;
 
@@ -304,7 +304,7 @@ static ssize_t debug_write_mem(struct file *file, const char __user *userbuf,
                goto err_out;
        }
 
-       area = find_iovm_area(obj, (u32)ppos);
+       area = omap_find_iovm_area(obj, (u32)ppos);
        if (IS_ERR(area)) {
                count = -EINVAL;
                goto err_out;
@@ -360,7 +360,7 @@ DEBUG_FOPS(mem);
 static int iommu_debug_register(struct device *dev, void *data)
 {
        struct platform_device *pdev = to_platform_device(dev);
-       struct iommu *obj = platform_get_drvdata(pdev);
+       struct omap_iommu *obj = platform_get_drvdata(pdev);
        struct dentry *d, *parent;
 
        if (!obj || !obj->dev)
@@ -396,7 +396,7 @@ static int __init iommu_debug_init(void)
                return -ENOMEM;
        iommu_debug_root = d;
 
-       err = foreach_iommu_device(d, iommu_debug_register);
+       err = omap_foreach_iommu_device(d, iommu_debug_register);
        if (err)
                goto err_out;
        return 0;
similarity index 61%
rename from arch/arm/plat-omap/iommu.c
rename to drivers/iommu/omap-iommu.c
index 34fc31ee9081ff8624d77dfb664ebe059d4c9343..8f32b2bf758777686c4bf9c7a85df3edaf9ac3af 100644 (file)
 #include <linux/ioport.h>
 #include <linux/clk.h>
 #include <linux/platform_device.h>
+#include <linux/iommu.h>
+#include <linux/mutex.h>
+#include <linux/spinlock.h>
 
 #include <asm/cacheflush.h>
 
 #include <plat/iommu.h>
 
-#include "iopgtable.h"
+#include <plat/iopgtable.h>
 
 #define for_each_iotlb_cr(obj, n, __i, cr)                             \
        for (__i = 0;                                                   \
             (__i < (n)) && (cr = __iotlb_read_cr((obj), __i), true);   \
             __i++)
 
+/**
+ * struct omap_iommu_domain - omap iommu domain
+ * @pgtable:   the page table
+ * @iommu_dev: an omap iommu device attached to this domain. only a single
+ *             iommu device can be attached for now.
+ * @lock:      domain lock, should be taken when attaching/detaching
+ */
+struct omap_iommu_domain {
+       u32 *pgtable;
+       struct omap_iommu *iommu_dev;
+       spinlock_t lock;
+};
+
 /* accommodate the difference between omap1 and omap2/3 */
 static const struct iommu_functions *arch_iommu;
 
@@ -37,13 +53,13 @@ static struct platform_driver omap_iommu_driver;
 static struct kmem_cache *iopte_cachep;
 
 /**
- * install_iommu_arch - Install archtecure specific iommu functions
+ * omap_install_iommu_arch - Install archtecure specific iommu functions
  * @ops:       a pointer to architecture specific iommu functions
  *
  * There are several kind of iommu algorithm(tlb, pagetable) among
  * omap series. This interface installs such an iommu algorighm.
  **/
-int install_iommu_arch(const struct iommu_functions *ops)
+int omap_install_iommu_arch(const struct iommu_functions *ops)
 {
        if (arch_iommu)
                return -EBUSY;
@@ -51,53 +67,53 @@ int install_iommu_arch(const struct iommu_functions *ops)
        arch_iommu = ops;
        return 0;
 }
-EXPORT_SYMBOL_GPL(install_iommu_arch);
+EXPORT_SYMBOL_GPL(omap_install_iommu_arch);
 
 /**
- * uninstall_iommu_arch - Uninstall archtecure specific iommu functions
+ * omap_uninstall_iommu_arch - Uninstall archtecure specific iommu functions
  * @ops:       a pointer to architecture specific iommu functions
  *
  * This interface uninstalls the iommu algorighm installed previously.
  **/
-void uninstall_iommu_arch(const struct iommu_functions *ops)
+void omap_uninstall_iommu_arch(const struct iommu_functions *ops)
 {
        if (arch_iommu != ops)
                pr_err("%s: not your arch\n", __func__);
 
        arch_iommu = NULL;
 }
-EXPORT_SYMBOL_GPL(uninstall_iommu_arch);
+EXPORT_SYMBOL_GPL(omap_uninstall_iommu_arch);
 
 /**
- * iommu_save_ctx - Save registers for pm off-mode support
+ * omap_iommu_save_ctx - Save registers for pm off-mode support
  * @obj:       target iommu
  **/
-void iommu_save_ctx(struct iommu *obj)
+void omap_iommu_save_ctx(struct omap_iommu *obj)
 {
        arch_iommu->save_ctx(obj);
 }
-EXPORT_SYMBOL_GPL(iommu_save_ctx);
+EXPORT_SYMBOL_GPL(omap_iommu_save_ctx);
 
 /**
- * iommu_restore_ctx - Restore registers for pm off-mode support
+ * omap_iommu_restore_ctx - Restore registers for pm off-mode support
  * @obj:       target iommu
  **/
-void iommu_restore_ctx(struct iommu *obj)
+void omap_iommu_restore_ctx(struct omap_iommu *obj)
 {
        arch_iommu->restore_ctx(obj);
 }
-EXPORT_SYMBOL_GPL(iommu_restore_ctx);
+EXPORT_SYMBOL_GPL(omap_iommu_restore_ctx);
 
 /**
- * iommu_arch_version - Return running iommu arch version
+ * omap_iommu_arch_version - Return running iommu arch version
  **/
-u32 iommu_arch_version(void)
+u32 omap_iommu_arch_version(void)
 {
        return arch_iommu->version;
 }
-EXPORT_SYMBOL_GPL(iommu_arch_version);
+EXPORT_SYMBOL_GPL(omap_iommu_arch_version);
 
-static int iommu_enable(struct iommu *obj)
+static int iommu_enable(struct omap_iommu *obj)
 {
        int err;
 
@@ -115,7 +131,7 @@ static int iommu_enable(struct iommu *obj)
        return err;
 }
 
-static void iommu_disable(struct iommu *obj)
+static void iommu_disable(struct omap_iommu *obj)
 {
        if (!obj)
                return;
@@ -130,13 +146,13 @@ static void iommu_disable(struct iommu *obj)
 /*
  *     TLB operations
  */
-void iotlb_cr_to_e(struct cr_regs *cr, struct iotlb_entry *e)
+void omap_iotlb_cr_to_e(struct cr_regs *cr, struct iotlb_entry *e)
 {
        BUG_ON(!cr || !e);
 
        arch_iommu->cr_to_e(cr, e);
 }
-EXPORT_SYMBOL_GPL(iotlb_cr_to_e);
+EXPORT_SYMBOL_GPL(omap_iotlb_cr_to_e);
 
 static inline int iotlb_cr_valid(struct cr_regs *cr)
 {
@@ -146,7 +162,7 @@ static inline int iotlb_cr_valid(struct cr_regs *cr)
        return arch_iommu->cr_valid(cr);
 }
 
-static inline struct cr_regs *iotlb_alloc_cr(struct iommu *obj,
+static inline struct cr_regs *iotlb_alloc_cr(struct omap_iommu *obj,
                                             struct iotlb_entry *e)
 {
        if (!e)
@@ -155,23 +171,22 @@ static inline struct cr_regs *iotlb_alloc_cr(struct iommu *obj,
        return arch_iommu->alloc_cr(obj, e);
 }
 
-u32 iotlb_cr_to_virt(struct cr_regs *cr)
+static u32 iotlb_cr_to_virt(struct cr_regs *cr)
 {
        return arch_iommu->cr_to_virt(cr);
 }
-EXPORT_SYMBOL_GPL(iotlb_cr_to_virt);
 
 static u32 get_iopte_attr(struct iotlb_entry *e)
 {
        return arch_iommu->get_pte_attr(e);
 }
 
-static u32 iommu_report_fault(struct iommu *obj, u32 *da)
+static u32 iommu_report_fault(struct omap_iommu *obj, u32 *da)
 {
        return arch_iommu->fault_isr(obj, da);
 }
 
-static void iotlb_lock_get(struct iommu *obj, struct iotlb_lock *l)
+static void iotlb_lock_get(struct omap_iommu *obj, struct iotlb_lock *l)
 {
        u32 val;
 
@@ -182,7 +197,7 @@ static void iotlb_lock_get(struct iommu *obj, struct iotlb_lock *l)
 
 }
 
-static void iotlb_lock_set(struct iommu *obj, struct iotlb_lock *l)
+static void iotlb_lock_set(struct omap_iommu *obj, struct iotlb_lock *l)
 {
        u32 val;
 
@@ -192,12 +207,12 @@ static void iotlb_lock_set(struct iommu *obj, struct iotlb_lock *l)
        iommu_write_reg(obj, val, MMU_LOCK);
 }
 
-static void iotlb_read_cr(struct iommu *obj, struct cr_regs *cr)
+static void iotlb_read_cr(struct omap_iommu *obj, struct cr_regs *cr)
 {
        arch_iommu->tlb_read_cr(obj, cr);
 }
 
-static void iotlb_load_cr(struct iommu *obj, struct cr_regs *cr)
+static void iotlb_load_cr(struct omap_iommu *obj, struct cr_regs *cr)
 {
        arch_iommu->tlb_load_cr(obj, cr);
 
@@ -211,7 +226,7 @@ static void iotlb_load_cr(struct iommu *obj, struct cr_regs *cr)
  * @cr:                contents of cam and ram register
  * @buf:       output buffer
  **/
-static inline ssize_t iotlb_dump_cr(struct iommu *obj, struct cr_regs *cr,
+static inline ssize_t iotlb_dump_cr(struct omap_iommu *obj, struct cr_regs *cr,
                                    char *buf)
 {
        BUG_ON(!cr || !buf);
@@ -220,7 +235,7 @@ static inline ssize_t iotlb_dump_cr(struct iommu *obj, struct cr_regs *cr,
 }
 
 /* only used in iotlb iteration for-loop */
-static struct cr_regs __iotlb_read_cr(struct iommu *obj, int n)
+static struct cr_regs __iotlb_read_cr(struct omap_iommu *obj, int n)
 {
        struct cr_regs cr;
        struct iotlb_lock l;
@@ -238,7 +253,8 @@ static struct cr_regs __iotlb_read_cr(struct iommu *obj, int n)
  * @obj:       target iommu
  * @e:         an iommu tlb entry info
  **/
-int load_iotlb_entry(struct iommu *obj, struct iotlb_entry *e)
+#ifdef PREFETCH_IOTLB
+static int load_iotlb_entry(struct omap_iommu *obj, struct iotlb_entry *e)
 {
        int err = 0;
        struct iotlb_lock l;
@@ -294,7 +310,20 @@ out:
        clk_disable(obj->clk);
        return err;
 }
-EXPORT_SYMBOL_GPL(load_iotlb_entry);
+
+#else /* !PREFETCH_IOTLB */
+
+static int load_iotlb_entry(struct omap_iommu *obj, struct iotlb_entry *e)
+{
+       return 0;
+}
+
+#endif /* !PREFETCH_IOTLB */
+
+static int prefetch_iotlb_entry(struct omap_iommu *obj, struct iotlb_entry *e)
+{
+       return load_iotlb_entry(obj, e);
+}
 
 /**
  * flush_iotlb_page - Clear an iommu tlb entry
@@ -303,7 +332,7 @@ EXPORT_SYMBOL_GPL(load_iotlb_entry);
  *
  * Clear an iommu tlb entry which includes 'da' address.
  **/
-void flush_iotlb_page(struct iommu *obj, u32 da)
+static void flush_iotlb_page(struct omap_iommu *obj, u32 da)
 {
        int i;
        struct cr_regs cr;
@@ -332,33 +361,12 @@ void flush_iotlb_page(struct iommu *obj, u32 da)
        if (i == obj->nr_tlb_entries)
                dev_dbg(obj->dev, "%s: no page for %08x\n", __func__, da);
 }
-EXPORT_SYMBOL_GPL(flush_iotlb_page);
-
-/**
- * flush_iotlb_range - Clear an iommu tlb entries
- * @obj:       target iommu
- * @start:     iommu device virtual address(start)
- * @end:       iommu device virtual address(end)
- *
- * Clear an iommu tlb entry which includes 'da' address.
- **/
-void flush_iotlb_range(struct iommu *obj, u32 start, u32 end)
-{
-       u32 da = start;
-
-       while (da < end) {
-               flush_iotlb_page(obj, da);
-               /* FIXME: Optimize for multiple page size */
-               da += IOPTE_SIZE;
-       }
-}
-EXPORT_SYMBOL_GPL(flush_iotlb_range);
 
 /**
  * flush_iotlb_all - Clear all iommu tlb entries
  * @obj:       target iommu
  **/
-void flush_iotlb_all(struct iommu *obj)
+static void flush_iotlb_all(struct omap_iommu *obj)
 {
        struct iotlb_lock l;
 
@@ -372,28 +380,10 @@ void flush_iotlb_all(struct iommu *obj)
 
        clk_disable(obj->clk);
 }
-EXPORT_SYMBOL_GPL(flush_iotlb_all);
-
-/**
- * iommu_set_twl - enable/disable table walking logic
- * @obj:       target iommu
- * @on:                enable/disable
- *
- * Function used to enable/disable TWL. If one wants to work
- * exclusively with locked TLB entries and receive notifications
- * for TLB miss then call this function to disable TWL.
- */
-void iommu_set_twl(struct iommu *obj, bool on)
-{
-       clk_enable(obj->clk);
-       arch_iommu->set_twl(obj, on);
-       clk_disable(obj->clk);
-}
-EXPORT_SYMBOL_GPL(iommu_set_twl);
 
-#if defined(CONFIG_OMAP_IOMMU_DEBUG_MODULE)
+#if defined(CONFIG_OMAP_IOMMU_DEBUG) || defined(CONFIG_OMAP_IOMMU_DEBUG_MODULE)
 
-ssize_t iommu_dump_ctx(struct iommu *obj, char *buf, ssize_t bytes)
+ssize_t omap_iommu_dump_ctx(struct omap_iommu *obj, char *buf, ssize_t bytes)
 {
        if (!obj || !buf)
                return -EINVAL;
@@ -406,9 +396,10 @@ ssize_t iommu_dump_ctx(struct iommu *obj, char *buf, ssize_t bytes)
 
        return bytes;
 }
-EXPORT_SYMBOL_GPL(iommu_dump_ctx);
+EXPORT_SYMBOL_GPL(omap_iommu_dump_ctx);
 
-static int __dump_tlb_entries(struct iommu *obj, struct cr_regs *crs, int num)
+static int
+__dump_tlb_entries(struct omap_iommu *obj, struct cr_regs *crs, int num)
 {
        int i;
        struct iotlb_lock saved;
@@ -431,11 +422,11 @@ static int __dump_tlb_entries(struct iommu *obj, struct cr_regs *crs, int num)
 }
 
 /**
- * dump_tlb_entries - dump cr arrays to given buffer
+ * omap_dump_tlb_entries - dump cr arrays to given buffer
  * @obj:       target iommu
  * @buf:       output buffer
  **/
-size_t dump_tlb_entries(struct iommu *obj, char *buf, ssize_t bytes)
+size_t omap_dump_tlb_entries(struct omap_iommu *obj, char *buf, ssize_t bytes)
 {
        int i, num;
        struct cr_regs *cr;
@@ -455,14 +446,14 @@ size_t dump_tlb_entries(struct iommu *obj, char *buf, ssize_t bytes)
 
        return p - buf;
 }
-EXPORT_SYMBOL_GPL(dump_tlb_entries);
+EXPORT_SYMBOL_GPL(omap_dump_tlb_entries);
 
-int foreach_iommu_device(void *data, int (*fn)(struct device *, void *))
+int omap_foreach_iommu_device(void *data, int (*fn)(struct device *, void *))
 {
        return driver_for_each_device(&omap_iommu_driver.driver,
                                      NULL, data, fn);
 }
-EXPORT_SYMBOL_GPL(foreach_iommu_device);
+EXPORT_SYMBOL_GPL(omap_foreach_iommu_device);
 
 #endif /* CONFIG_OMAP_IOMMU_DEBUG_MODULE */
 
@@ -495,7 +486,7 @@ static void iopte_free(u32 *iopte)
        kmem_cache_free(iopte_cachep, iopte);
 }
 
-static u32 *iopte_alloc(struct iommu *obj, u32 *iopgd, u32 da)
+static u32 *iopte_alloc(struct omap_iommu *obj, u32 *iopgd, u32 da)
 {
        u32 *iopte;
 
@@ -533,7 +524,7 @@ pte_ready:
        return iopte;
 }
 
-static int iopgd_alloc_section(struct iommu *obj, u32 da, u32 pa, u32 prot)
+static int iopgd_alloc_section(struct omap_iommu *obj, u32 da, u32 pa, u32 prot)
 {
        u32 *iopgd = iopgd_offset(obj, da);
 
@@ -548,7 +539,7 @@ static int iopgd_alloc_section(struct iommu *obj, u32 da, u32 pa, u32 prot)
        return 0;
 }
 
-static int iopgd_alloc_super(struct iommu *obj, u32 da, u32 pa, u32 prot)
+static int iopgd_alloc_super(struct omap_iommu *obj, u32 da, u32 pa, u32 prot)
 {
        u32 *iopgd = iopgd_offset(obj, da);
        int i;
@@ -565,7 +556,7 @@ static int iopgd_alloc_super(struct iommu *obj, u32 da, u32 pa, u32 prot)
        return 0;
 }
 
-static int iopte_alloc_page(struct iommu *obj, u32 da, u32 pa, u32 prot)
+static int iopte_alloc_page(struct omap_iommu *obj, u32 da, u32 pa, u32 prot)
 {
        u32 *iopgd = iopgd_offset(obj, da);
        u32 *iopte = iopte_alloc(obj, iopgd, da);
@@ -582,7 +573,7 @@ static int iopte_alloc_page(struct iommu *obj, u32 da, u32 pa, u32 prot)
        return 0;
 }
 
-static int iopte_alloc_large(struct iommu *obj, u32 da, u32 pa, u32 prot)
+static int iopte_alloc_large(struct omap_iommu *obj, u32 da, u32 pa, u32 prot)
 {
        u32 *iopgd = iopgd_offset(obj, da);
        u32 *iopte = iopte_alloc(obj, iopgd, da);
@@ -603,9 +594,10 @@ static int iopte_alloc_large(struct iommu *obj, u32 da, u32 pa, u32 prot)
        return 0;
 }
 
-static int iopgtable_store_entry_core(struct iommu *obj, struct iotlb_entry *e)
+static int
+iopgtable_store_entry_core(struct omap_iommu *obj, struct iotlb_entry *e)
 {
-       int (*fn)(struct iommu *, u32, u32, u32);
+       int (*fn)(struct omap_iommu *, u32, u32, u32);
        u32 prot;
        int err;
 
@@ -641,23 +633,21 @@ static int iopgtable_store_entry_core(struct iommu *obj, struct iotlb_entry *e)
 }
 
 /**
- * iopgtable_store_entry - Make an iommu pte entry
+ * omap_iopgtable_store_entry - Make an iommu pte entry
  * @obj:       target iommu
  * @e:         an iommu tlb entry info
  **/
-int iopgtable_store_entry(struct iommu *obj, struct iotlb_entry *e)
+int omap_iopgtable_store_entry(struct omap_iommu *obj, struct iotlb_entry *e)
 {
        int err;
 
        flush_iotlb_page(obj, e->da);
        err = iopgtable_store_entry_core(obj, e);
-#ifdef PREFETCH_IOTLB
        if (!err)
-               load_iotlb_entry(obj, e);
-#endif
+               prefetch_iotlb_entry(obj, e);
        return err;
 }
-EXPORT_SYMBOL_GPL(iopgtable_store_entry);
+EXPORT_SYMBOL_GPL(omap_iopgtable_store_entry);
 
 /**
  * iopgtable_lookup_entry - Lookup an iommu pte entry
@@ -666,7 +656,8 @@ EXPORT_SYMBOL_GPL(iopgtable_store_entry);
  * @ppgd:      iommu pgd entry pointer to be returned
  * @ppte:      iommu pte entry pointer to be returned
  **/
-void iopgtable_lookup_entry(struct iommu *obj, u32 da, u32 **ppgd, u32 **ppte)
+static void
+iopgtable_lookup_entry(struct omap_iommu *obj, u32 da, u32 **ppgd, u32 **ppte)
 {
        u32 *iopgd, *iopte = NULL;
 
@@ -680,9 +671,8 @@ out:
        *ppgd = iopgd;
        *ppte = iopte;
 }
-EXPORT_SYMBOL_GPL(iopgtable_lookup_entry);
 
-static size_t iopgtable_clear_entry_core(struct iommu *obj, u32 da)
+static size_t iopgtable_clear_entry_core(struct omap_iommu *obj, u32 da)
 {
        size_t bytes;
        u32 *iopgd = iopgd_offset(obj, da);
@@ -735,7 +725,7 @@ out:
  * @obj:       target iommu
  * @da:                iommu device virtual address
  **/
-size_t iopgtable_clear_entry(struct iommu *obj, u32 da)
+static size_t iopgtable_clear_entry(struct omap_iommu *obj, u32 da)
 {
        size_t bytes;
 
@@ -748,9 +738,8 @@ size_t iopgtable_clear_entry(struct iommu *obj, u32 da)
 
        return bytes;
 }
-EXPORT_SYMBOL_GPL(iopgtable_clear_entry);
 
-static void iopgtable_clear_entry_all(struct iommu *obj)
+static void iopgtable_clear_entry_all(struct omap_iommu *obj)
 {
        int i;
 
@@ -785,7 +774,8 @@ static irqreturn_t iommu_fault_handler(int irq, void *data)
 {
        u32 da, errs;
        u32 *iopgd, *iopte;
-       struct iommu *obj = data;
+       struct omap_iommu *obj = data;
+       struct iommu_domain *domain = obj->domain;
 
        if (!obj->refcount)
                return IRQ_NONE;
@@ -797,7 +787,7 @@ static irqreturn_t iommu_fault_handler(int irq, void *data)
                return IRQ_HANDLED;
 
        /* Fault callback or TLB/PTE Dynamic loading */
-       if (obj->isr && !obj->isr(obj, da, errs, obj->isr_priv))
+       if (!report_iommu_fault(domain, obj->dev, da, 0))
                return IRQ_HANDLED;
 
        iommu_disable(obj);
@@ -821,7 +811,7 @@ static irqreturn_t iommu_fault_handler(int irq, void *data)
 
 static int device_match_by_alias(struct device *dev, void *data)
 {
-       struct iommu *obj = to_iommu(dev);
+       struct omap_iommu *obj = to_iommu(dev);
        const char *name = data;
 
        pr_debug("%s: %s %s\n", __func__, obj->name, name);
@@ -830,57 +820,55 @@ static int device_match_by_alias(struct device *dev, void *data)
 }
 
 /**
- * iommu_set_da_range - Set a valid device address range
- * @obj:               target iommu
- * @start              Start of valid range
- * @end                        End of valid range
- **/
-int iommu_set_da_range(struct iommu *obj, u32 start, u32 end)
+ * omap_find_iommu_device() - find an omap iommu device by name
+ * @name:      name of the iommu device
+ *
+ * The generic iommu API requires the caller to provide the device
+ * he wishes to attach to a certain iommu domain.
+ *
+ * Drivers generally should not bother with this as it should just
+ * be taken care of by the DMA-API using dev_archdata.
+ *
+ * This function is provided as an interim solution until the latter
+ * materializes, and omap3isp is fully migrated to the DMA-API.
+ */
+struct device *omap_find_iommu_device(const char *name)
 {
-
-       if (!obj)
-               return -EFAULT;
-
-       if (end < start || !PAGE_ALIGN(start | end))
-               return -EINVAL;
-
-       obj->da_start = start;
-       obj->da_end = end;
-
-       return 0;
+       return driver_find_device(&omap_iommu_driver.driver, NULL,
+                               (void *)name,
+                               device_match_by_alias);
 }
-EXPORT_SYMBOL_GPL(iommu_set_da_range);
+EXPORT_SYMBOL_GPL(omap_find_iommu_device);
 
 /**
- * iommu_get - Get iommu handler
- * @name:      target iommu name
+ * omap_iommu_attach() - attach iommu device to an iommu domain
+ * @dev:       target omap iommu device
+ * @iopgd:     page table
  **/
-struct iommu *iommu_get(const char *name)
+static struct omap_iommu *omap_iommu_attach(struct device *dev, u32 *iopgd)
 {
        int err = -ENOMEM;
-       struct device *dev;
-       struct iommu *obj;
-
-       dev = driver_find_device(&omap_iommu_driver.driver, NULL, (void *)name,
-                                device_match_by_alias);
-       if (!dev)
-               return ERR_PTR(-ENODEV);
-
-       obj = to_iommu(dev);
+       struct omap_iommu *obj = to_iommu(dev);
 
-       mutex_lock(&obj->iommu_lock);
+       spin_lock(&obj->iommu_lock);
 
-       if (obj->refcount++ == 0) {
-               err = iommu_enable(obj);
-               if (err)
-                       goto err_enable;
-               flush_iotlb_all(obj);
+       /* an iommu device can only be attached once */
+       if (++obj->refcount > 1) {
+               dev_err(dev, "%s: already attached!\n", obj->name);
+               err = -EBUSY;
+               goto err_enable;
        }
 
+       obj->iopgd = iopgd;
+       err = iommu_enable(obj);
+       if (err)
+               goto err_enable;
+       flush_iotlb_all(obj);
+
        if (!try_module_get(obj->owner))
                goto err_module;
 
-       mutex_unlock(&obj->iommu_lock);
+       spin_unlock(&obj->iommu_lock);
 
        dev_dbg(obj->dev, "%s: %s\n", __func__, obj->name);
        return obj;
@@ -890,59 +878,32 @@ err_module:
                iommu_disable(obj);
 err_enable:
        obj->refcount--;
-       mutex_unlock(&obj->iommu_lock);
+       spin_unlock(&obj->iommu_lock);
        return ERR_PTR(err);
 }
-EXPORT_SYMBOL_GPL(iommu_get);
 
 /**
- * iommu_put - Put back iommu handler
+ * omap_iommu_detach - release iommu device
  * @obj:       target iommu
  **/
-void iommu_put(struct iommu *obj)
+static void omap_iommu_detach(struct omap_iommu *obj)
 {
        if (!obj || IS_ERR(obj))
                return;
 
-       mutex_lock(&obj->iommu_lock);
+       spin_lock(&obj->iommu_lock);
 
        if (--obj->refcount == 0)
                iommu_disable(obj);
 
        module_put(obj->owner);
 
-       mutex_unlock(&obj->iommu_lock);
-
-       dev_dbg(obj->dev, "%s: %s\n", __func__, obj->name);
-}
-EXPORT_SYMBOL_GPL(iommu_put);
-
-int iommu_set_isr(const char *name,
-                 int (*isr)(struct iommu *obj, u32 da, u32 iommu_errs,
-                            void *priv),
-                 void *isr_priv)
-{
-       struct device *dev;
-       struct iommu *obj;
+       obj->iopgd = NULL;
 
-       dev = driver_find_device(&omap_iommu_driver.driver, NULL, (void *)name,
-                                device_match_by_alias);
-       if (!dev)
-               return -ENODEV;
+       spin_unlock(&obj->iommu_lock);
 
-       obj = to_iommu(dev);
-       mutex_lock(&obj->iommu_lock);
-       if (obj->refcount != 0) {
-               mutex_unlock(&obj->iommu_lock);
-               return -EBUSY;
-       }
-       obj->isr = isr;
-       obj->isr_priv = isr_priv;
-       mutex_unlock(&obj->iommu_lock);
-
-       return 0;
+       dev_dbg(obj->dev, "%s: %s\n", __func__, obj->name);
 }
-EXPORT_SYMBOL_GPL(iommu_set_isr);
 
 /*
  *     OMAP Device MMU(IOMMU) detection
@@ -950,9 +911,8 @@ EXPORT_SYMBOL_GPL(iommu_set_isr);
 static int __devinit omap_iommu_probe(struct platform_device *pdev)
 {
        int err = -ENODEV;
-       void *p;
        int irq;
-       struct iommu *obj;
+       struct omap_iommu *obj;
        struct resource *res;
        struct iommu_platform_data *pdata = pdev->dev.platform_data;
 
@@ -974,7 +934,7 @@ static int __devinit omap_iommu_probe(struct platform_device *pdev)
        obj->da_start = pdata->da_start;
        obj->da_end = pdata->da_end;
 
-       mutex_init(&obj->iommu_lock);
+       spin_lock_init(&obj->iommu_lock);
        mutex_init(&obj->mmap_lock);
        spin_lock_init(&obj->page_table_lock);
        INIT_LIST_HEAD(&obj->mmap);
@@ -1009,22 +969,9 @@ static int __devinit omap_iommu_probe(struct platform_device *pdev)
                goto err_irq;
        platform_set_drvdata(pdev, obj);
 
-       p = (void *)__get_free_pages(GFP_KERNEL, get_order(IOPGD_TABLE_SIZE));
-       if (!p) {
-               err = -ENOMEM;
-               goto err_pgd;
-       }
-       memset(p, 0, IOPGD_TABLE_SIZE);
-       clean_dcache_area(p, IOPGD_TABLE_SIZE);
-       obj->iopgd = p;
-
-       BUG_ON(!IS_ALIGNED((unsigned long)obj->iopgd, IOPGD_TABLE_SIZE));
-
        dev_info(&pdev->dev, "%s registered\n", obj->name);
        return 0;
 
-err_pgd:
-       free_irq(irq, obj);
 err_irq:
        iounmap(obj->regbase);
 err_ioremap:
@@ -1040,12 +987,11 @@ static int __devexit omap_iommu_remove(struct platform_device *pdev)
 {
        int irq;
        struct resource *res;
-       struct iommu *obj = platform_get_drvdata(pdev);
+       struct omap_iommu *obj = platform_get_drvdata(pdev);
 
        platform_set_drvdata(pdev, NULL);
 
        iopgtable_clear_entry_all(obj);
-       free_pages((unsigned long)obj->iopgd, get_order(IOPGD_TABLE_SIZE));
 
        irq = platform_get_irq(pdev, 0);
        free_irq(irq, obj);
@@ -1072,6 +1018,201 @@ static void iopte_cachep_ctor(void *iopte)
        clean_dcache_area(iopte, IOPTE_TABLE_SIZE);
 }
 
+static int omap_iommu_map(struct iommu_domain *domain, unsigned long da,
+                        phys_addr_t pa, int order, int prot)
+{
+       struct omap_iommu_domain *omap_domain = domain->priv;
+       struct omap_iommu *oiommu = omap_domain->iommu_dev;
+       struct device *dev = oiommu->dev;
+       size_t bytes = PAGE_SIZE << order;
+       struct iotlb_entry e;
+       int omap_pgsz;
+       u32 ret, flags;
+
+       /* we only support mapping a single iommu page for now */
+       omap_pgsz = bytes_to_iopgsz(bytes);
+       if (omap_pgsz < 0) {
+               dev_err(dev, "invalid size to map: %d\n", bytes);
+               return -EINVAL;
+       }
+
+       dev_dbg(dev, "mapping da 0x%lx to pa 0x%x size 0x%x\n", da, pa, bytes);
+
+       flags = omap_pgsz | prot;
+
+       iotlb_init_entry(&e, da, pa, flags);
+
+       ret = omap_iopgtable_store_entry(oiommu, &e);
+       if (ret)
+               dev_err(dev, "omap_iopgtable_store_entry failed: %d\n", ret);
+
+       return ret;
+}
+
+static int omap_iommu_unmap(struct iommu_domain *domain, unsigned long da,
+                           int order)
+{
+       struct omap_iommu_domain *omap_domain = domain->priv;
+       struct omap_iommu *oiommu = omap_domain->iommu_dev;
+       struct device *dev = oiommu->dev;
+       size_t unmap_size;
+
+       dev_dbg(dev, "unmapping da 0x%lx order %d\n", da, order);
+
+       unmap_size = iopgtable_clear_entry(oiommu, da);
+
+       return unmap_size ? get_order(unmap_size) : -EINVAL;
+}
+
+static int
+omap_iommu_attach_dev(struct iommu_domain *domain, struct device *dev)
+{
+       struct omap_iommu_domain *omap_domain = domain->priv;
+       struct omap_iommu *oiommu;
+       int ret = 0;
+
+       spin_lock(&omap_domain->lock);
+
+       /* only a single device is supported per domain for now */
+       if (omap_domain->iommu_dev) {
+               dev_err(dev, "iommu domain is already attached\n");
+               ret = -EBUSY;
+               goto out;
+       }
+
+       /* get a handle to and enable the omap iommu */
+       oiommu = omap_iommu_attach(dev, omap_domain->pgtable);
+       if (IS_ERR(oiommu)) {
+               ret = PTR_ERR(oiommu);
+               dev_err(dev, "can't get omap iommu: %d\n", ret);
+               goto out;
+       }
+
+       omap_domain->iommu_dev = oiommu;
+       oiommu->domain = domain;
+
+out:
+       spin_unlock(&omap_domain->lock);
+       return ret;
+}
+
+static void omap_iommu_detach_dev(struct iommu_domain *domain,
+                                struct device *dev)
+{
+       struct omap_iommu_domain *omap_domain = domain->priv;
+       struct omap_iommu *oiommu = to_iommu(dev);
+
+       spin_lock(&omap_domain->lock);
+
+       /* only a single device is supported per domain for now */
+       if (omap_domain->iommu_dev != oiommu) {
+               dev_err(dev, "invalid iommu device\n");
+               goto out;
+       }
+
+       iopgtable_clear_entry_all(oiommu);
+
+       omap_iommu_detach(oiommu);
+
+       omap_domain->iommu_dev = NULL;
+
+out:
+       spin_unlock(&omap_domain->lock);
+}
+
+static int omap_iommu_domain_init(struct iommu_domain *domain)
+{
+       struct omap_iommu_domain *omap_domain;
+
+       omap_domain = kzalloc(sizeof(*omap_domain), GFP_KERNEL);
+       if (!omap_domain) {
+               pr_err("kzalloc failed\n");
+               goto out;
+       }
+
+       omap_domain->pgtable = kzalloc(IOPGD_TABLE_SIZE, GFP_KERNEL);
+       if (!omap_domain->pgtable) {
+               pr_err("kzalloc failed\n");
+               goto fail_nomem;
+       }
+
+       /*
+        * should never fail, but please keep this around to ensure
+        * we keep the hardware happy
+        */
+       BUG_ON(!IS_ALIGNED((long)omap_domain->pgtable, IOPGD_TABLE_SIZE));
+
+       clean_dcache_area(omap_domain->pgtable, IOPGD_TABLE_SIZE);
+       spin_lock_init(&omap_domain->lock);
+
+       domain->priv = omap_domain;
+
+       return 0;
+
+fail_nomem:
+       kfree(omap_domain);
+out:
+       return -ENOMEM;
+}
+
+/* assume device was already detached */
+static void omap_iommu_domain_destroy(struct iommu_domain *domain)
+{
+       struct omap_iommu_domain *omap_domain = domain->priv;
+
+       domain->priv = NULL;
+
+       kfree(omap_domain->pgtable);
+       kfree(omap_domain);
+}
+
+static phys_addr_t omap_iommu_iova_to_phys(struct iommu_domain *domain,
+                                         unsigned long da)
+{
+       struct omap_iommu_domain *omap_domain = domain->priv;
+       struct omap_iommu *oiommu = omap_domain->iommu_dev;
+       struct device *dev = oiommu->dev;
+       u32 *pgd, *pte;
+       phys_addr_t ret = 0;
+
+       iopgtable_lookup_entry(oiommu, da, &pgd, &pte);
+
+       if (pte) {
+               if (iopte_is_small(*pte))
+                       ret = omap_iommu_translate(*pte, da, IOPTE_MASK);
+               else if (iopte_is_large(*pte))
+                       ret = omap_iommu_translate(*pte, da, IOLARGE_MASK);
+               else
+                       dev_err(dev, "bogus pte 0x%x", *pte);
+       } else {
+               if (iopgd_is_section(*pgd))
+                       ret = omap_iommu_translate(*pgd, da, IOSECTION_MASK);
+               else if (iopgd_is_super(*pgd))
+                       ret = omap_iommu_translate(*pgd, da, IOSUPER_MASK);
+               else
+                       dev_err(dev, "bogus pgd 0x%x", *pgd);
+       }
+
+       return ret;
+}
+
+static int omap_iommu_domain_has_cap(struct iommu_domain *domain,
+                                   unsigned long cap)
+{
+       return 0;
+}
+
+static struct iommu_ops omap_iommu_ops = {
+       .domain_init    = omap_iommu_domain_init,
+       .domain_destroy = omap_iommu_domain_destroy,
+       .attach_dev     = omap_iommu_attach_dev,
+       .detach_dev     = omap_iommu_detach_dev,
+       .map            = omap_iommu_map,
+       .unmap          = omap_iommu_unmap,
+       .iova_to_phys   = omap_iommu_iova_to_phys,
+       .domain_has_cap = omap_iommu_domain_has_cap,
+};
+
 static int __init omap_iommu_init(void)
 {
        struct kmem_cache *p;
@@ -1084,6 +1225,8 @@ static int __init omap_iommu_init(void)
                return -ENOMEM;
        iopte_cachep = p;
 
+       bus_set_iommu(&platform_bus_type, &omap_iommu_ops);
+
        return platform_driver_register(&omap_iommu_driver);
 }
 module_init(omap_iommu_init);
similarity index 62%
rename from arch/arm/plat-omap/iovmm.c
rename to drivers/iommu/omap-iovmm.c
index 79e7fedb8602ae1a50bd704921ad432a878f9765..e8fdb8830f698184b08cb2a919b1358648ea4efb 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/vmalloc.h>
 #include <linux/device.h>
 #include <linux/scatterlist.h>
+#include <linux/iommu.h>
 
 #include <asm/cacheflush.h>
 #include <asm/mach/map.h>
 #include <plat/iommu.h>
 #include <plat/iovmm.h>
 
-#include "iopgtable.h"
-
-/*
- * A device driver needs to create address mappings between:
- *
- * - iommu/device address
- * - physical address
- * - mpu virtual address
- *
- * There are 4 possible patterns for them:
- *
- *    |iova/                     mapping               iommu_          page
- *    | da     pa      va      (d)-(p)-(v)             function        type
- *  ---------------------------------------------------------------------------
- *  1 | c      c       c        1 - 1 - 1        _kmap() / _kunmap()   s
- *  2 | c      c,a     c        1 - 1 - 1      _kmalloc()/ _kfree()    s
- *  3 | c      d       c        1 - n - 1        _vmap() / _vunmap()   s
- *  4 | c      d,a     c        1 - n - 1      _vmalloc()/ _vfree()    n*
- *
- *
- *     'iova': device iommu virtual address
- *     'da':   alias of 'iova'
- *     'pa':   physical address
- *     'va':   mpu virtual address
- *
- *     'c':    contiguous memory area
- *     'd':    discontiguous memory area
- *     'a':    anonymous memory allocation
- *     '()':   optional feature
- *
- *     'n':    a normal page(4KB) size is used.
- *     's':    multiple iommu superpage(16MB, 1MB, 64KB, 4KB) size is used.
- *
- *     '*':    not yet, but feasible.
- */
+#include <plat/iopgtable.h>
 
 static struct kmem_cache *iovm_area_cachep;
 
+/* return the offset of the first scatterlist entry in a sg table */
+static unsigned int sgtable_offset(const struct sg_table *sgt)
+{
+       if (!sgt || !sgt->nents)
+               return 0;
+
+       return sgt->sgl->offset;
+}
+
 /* return total bytes of sg buffers */
 static size_t sgtable_len(const struct sg_table *sgt)
 {
@@ -72,11 +48,17 @@ static size_t sgtable_len(const struct sg_table *sgt)
        for_each_sg(sgt->sgl, sg, sgt->nents, i) {
                size_t bytes;
 
-               bytes = sg->length;
+               bytes = sg->length + sg->offset;
 
                if (!iopgsz_ok(bytes)) {
-                       pr_err("%s: sg[%d] not iommu pagesize(%x)\n",
-                              __func__, i, bytes);
+                       pr_err("%s: sg[%d] not iommu pagesize(%u %u)\n",
+                              __func__, i, bytes, sg->offset);
+                       return 0;
+               }
+
+               if (i && sg->offset) {
+                       pr_err("%s: sg[%d] offset not allowed in internal "
+                                       "entries\n", __func__, i);
                        return 0;
                }
 
@@ -197,8 +179,8 @@ static void *vmap_sg(const struct sg_table *sgt)
                u32 pa;
                int err;
 
-               pa = sg_phys(sg);
-               bytes = sg->length;
+               pa = sg_phys(sg) - sg->offset;
+               bytes = sg->length + sg->offset;
 
                BUG_ON(bytes != PAGE_SIZE);
 
@@ -224,7 +206,8 @@ static inline void vunmap_sg(const void *va)
        vunmap(va);
 }
 
-static struct iovm_struct *__find_iovm_area(struct iommu *obj, const u32 da)
+static struct iovm_struct *__find_iovm_area(struct omap_iommu *obj,
+                                                       const u32 da)
 {
        struct iovm_struct *tmp;
 
@@ -246,12 +229,12 @@ static struct iovm_struct *__find_iovm_area(struct iommu *obj, const u32 da)
 }
 
 /**
- * find_iovm_area  -  find iovma which includes @da
+ * omap_find_iovm_area  -  find iovma which includes @da
  * @da:                iommu device virtual address
  *
  * Find the existing iovma starting at @da
  */
-struct iovm_struct *find_iovm_area(struct iommu *obj, u32 da)
+struct iovm_struct *omap_find_iovm_area(struct omap_iommu *obj, u32 da)
 {
        struct iovm_struct *area;
 
@@ -261,13 +244,13 @@ struct iovm_struct *find_iovm_area(struct iommu *obj, u32 da)
 
        return area;
 }
-EXPORT_SYMBOL_GPL(find_iovm_area);
+EXPORT_SYMBOL_GPL(omap_find_iovm_area);
 
 /*
  * This finds the hole(area) which fits the requested address and len
  * in iovmas mmap, and returns the new allocated iovma.
  */
-static struct iovm_struct *alloc_iovm_area(struct iommu *obj, u32 da,
+static struct iovm_struct *alloc_iovm_area(struct omap_iommu *obj, u32 da,
                                           size_t bytes, u32 flags)
 {
        struct iovm_struct *new, *tmp;
@@ -342,7 +325,7 @@ found:
        return new;
 }
 
-static void free_iovm_area(struct iommu *obj, struct iovm_struct *area)
+static void free_iovm_area(struct omap_iommu *obj, struct iovm_struct *area)
 {
        size_t bytes;
 
@@ -358,14 +341,14 @@ static void free_iovm_area(struct iommu *obj, struct iovm_struct *area)
 }
 
 /**
- * da_to_va - convert (d) to (v)
+ * omap_da_to_va - convert (d) to (v)
  * @obj:       objective iommu
  * @da:                iommu device virtual address
  * @va:                mpu virtual address
  *
  * Returns mpu virtual addr which corresponds to a given device virtual addr
  */
-void *da_to_va(struct iommu *obj, u32 da)
+void *omap_da_to_va(struct omap_iommu *obj, u32 da)
 {
        void *va = NULL;
        struct iovm_struct *area;
@@ -383,7 +366,7 @@ out:
 
        return va;
 }
-EXPORT_SYMBOL_GPL(da_to_va);
+EXPORT_SYMBOL_GPL(omap_da_to_va);
 
 static void sgtable_fill_vmalloc(struct sg_table *sgt, void *_va)
 {
@@ -397,7 +380,7 @@ static void sgtable_fill_vmalloc(struct sg_table *sgt, void *_va)
                const size_t bytes = PAGE_SIZE;
 
                /*
-                * iommu 'superpage' isn't supported with 'iommu_vmalloc()'
+                * iommu 'superpage' isn't supported with 'omap_iommu_vmalloc()'
                 */
                pg = vmalloc_to_page(va);
                BUG_ON(!pg);
@@ -418,74 +401,39 @@ static inline void sgtable_drain_vmalloc(struct sg_table *sgt)
        BUG_ON(!sgt);
 }
 
-static void sgtable_fill_kmalloc(struct sg_table *sgt, u32 pa, u32 da,
-                                                               size_t len)
-{
-       unsigned int i;
-       struct scatterlist *sg;
-
-       for_each_sg(sgt->sgl, sg, sgt->nents, i) {
-               unsigned bytes;
-
-               bytes = max_alignment(da | pa);
-               bytes = min_t(unsigned, bytes, iopgsz_max(len));
-
-               BUG_ON(!iopgsz_ok(bytes));
-
-               sg_set_buf(sg, phys_to_virt(pa), bytes);
-               /*
-                * 'pa' is cotinuous(linear).
-                */
-               pa += bytes;
-               da += bytes;
-               len -= bytes;
-       }
-       BUG_ON(len);
-}
-
-static inline void sgtable_drain_kmalloc(struct sg_table *sgt)
-{
-       /*
-        * Actually this is not necessary at all, just exists for
-        * consistency of the code readability
-        */
-       BUG_ON(!sgt);
-}
-
 /* create 'da' <-> 'pa' mapping from 'sgt' */
-static int map_iovm_area(struct iommu *obj, struct iovm_struct *new,
-                        const struct sg_table *sgt, u32 flags)
+static int map_iovm_area(struct iommu_domain *domain, struct iovm_struct *new,
+                       const struct sg_table *sgt, u32 flags)
 {
        int err;
        unsigned int i, j;
        struct scatterlist *sg;
        u32 da = new->da_start;
+       int order;
 
-       if (!obj || !sgt)
+       if (!domain || !sgt)
                return -EINVAL;
 
        BUG_ON(!sgtable_ok(sgt));
 
        for_each_sg(sgt->sgl, sg, sgt->nents, i) {
                u32 pa;
-               int pgsz;
                size_t bytes;
-               struct iotlb_entry e;
 
-               pa = sg_phys(sg);
-               bytes = sg->length;
+               pa = sg_phys(sg) - sg->offset;
+               bytes = sg->length + sg->offset;
 
                flags &= ~IOVMF_PGSZ_MASK;
-               pgsz = bytes_to_iopgsz(bytes);
-               if (pgsz < 0)
+
+               if (bytes_to_iopgsz(bytes) < 0)
                        goto err_out;
-               flags |= pgsz;
+
+               order = get_order(bytes);
 
                pr_debug("%s: [%d] %08x %08x(%x)\n", __func__,
                         i, da, pa, bytes);
 
-               iotlb_init_entry(&e, da, pa, flags);
-               err = iopgtable_store_entry(obj, &e);
+               err = iommu_map(domain, da, pa, order, flags);
                if (err)
                        goto err_out;
 
@@ -499,9 +447,11 @@ err_out:
        for_each_sg(sgt->sgl, sg, i, j) {
                size_t bytes;
 
-               bytes = iopgtable_clear_entry(obj, da);
+               bytes = sg->length + sg->offset;
+               order = get_order(bytes);
 
-               BUG_ON(!iopgsz_ok(bytes));
+               /* ignore failures.. we're already handling one */
+               iommu_unmap(domain, da, order);
 
                da += bytes;
        }
@@ -509,22 +459,31 @@ err_out:
 }
 
 /* release 'da' <-> 'pa' mapping */
-static void unmap_iovm_area(struct iommu *obj, struct iovm_struct *area)
+static void unmap_iovm_area(struct iommu_domain *domain, struct omap_iommu *obj,
+                                               struct iovm_struct *area)
 {
        u32 start;
        size_t total = area->da_end - area->da_start;
+       const struct sg_table *sgt = area->sgt;
+       struct scatterlist *sg;
+       int i, err;
 
+       BUG_ON(!sgtable_ok(sgt));
        BUG_ON((!total) || !IS_ALIGNED(total, PAGE_SIZE));
 
        start = area->da_start;
-       while (total > 0) {
+       for_each_sg(sgt->sgl, sg, sgt->nents, i) {
                size_t bytes;
+               int order;
+
+               bytes = sg->length + sg->offset;
+               order = get_order(bytes);
+
+               err = iommu_unmap(domain, start, order);
+               if (err < 0)
+                       break;
 
-               bytes = iopgtable_clear_entry(obj, start);
-               if (bytes == 0)
-                       bytes = PAGE_SIZE;
-               else
-                       dev_dbg(obj->dev, "%s: unmap %08x(%x) %08x\n",
+               dev_dbg(obj->dev, "%s: unmap %08x(%x) %08x\n",
                                __func__, start, bytes, area->flags);
 
                BUG_ON(!IS_ALIGNED(bytes, PAGE_SIZE));
@@ -536,7 +495,8 @@ static void unmap_iovm_area(struct iommu *obj, struct iovm_struct *area)
 }
 
 /* template function for all unmapping */
-static struct sg_table *unmap_vm_area(struct iommu *obj, const u32 da,
+static struct sg_table *unmap_vm_area(struct iommu_domain *domain,
+                                     struct omap_iommu *obj, const u32 da,
                                      void (*fn)(const void *), u32 flags)
 {
        struct sg_table *sgt = NULL;
@@ -562,7 +522,7 @@ static struct sg_table *unmap_vm_area(struct iommu *obj, const u32 da,
        }
        sgt = (struct sg_table *)area->sgt;
 
-       unmap_iovm_area(obj, area);
+       unmap_iovm_area(domain, obj, area);
 
        fn(area->va);
 
@@ -577,8 +537,9 @@ out:
        return sgt;
 }
 
-static u32 map_iommu_region(struct iommu *obj, u32 da,
-             const struct sg_table *sgt, void *va, size_t bytes, u32 flags)
+static u32 map_iommu_region(struct iommu_domain *domain, struct omap_iommu *obj,
+                               u32 da, const struct sg_table *sgt, void *va,
+                               size_t bytes, u32 flags)
 {
        int err = -ENOMEM;
        struct iovm_struct *new;
@@ -593,7 +554,7 @@ static u32 map_iommu_region(struct iommu *obj, u32 da,
        new->va = va;
        new->sgt = sgt;
 
-       if (map_iovm_area(obj, new, sgt, new->flags))
+       if (map_iovm_area(domain, new, sgt, new->flags))
                goto err_map;
 
        mutex_unlock(&obj->mmap_lock);
@@ -610,14 +571,16 @@ err_alloc_iovma:
        return err;
 }
 
-static inline u32 __iommu_vmap(struct iommu *obj, u32 da,
-                const struct sg_table *sgt, void *va, size_t bytes, u32 flags)
+static inline u32
+__iommu_vmap(struct iommu_domain *domain, struct omap_iommu *obj,
+                               u32 da, const struct sg_table *sgt,
+                               void *va, size_t bytes, u32 flags)
 {
-       return map_iommu_region(obj, da, sgt, va, bytes, flags);
+       return map_iommu_region(domain, obj, da, sgt, va, bytes, flags);
 }
 
 /**
- * iommu_vmap  -  (d)-(p)-(v) address mapper
+ * omap_iommu_vmap  -  (d)-(p)-(v) address mapper
  * @obj:       objective iommu
  * @sgt:       address of scatter gather table
  * @flags:     iovma and page property
@@ -625,8 +588,8 @@ static inline u32 __iommu_vmap(struct iommu *obj, u32 da,
  * Creates 1-n-1 mapping with given @sgt and returns @da.
  * All @sgt element must be io page size aligned.
  */
-u32 iommu_vmap(struct iommu *obj, u32 da, const struct sg_table *sgt,
-                u32 flags)
+u32 omap_iommu_vmap(struct iommu_domain *domain, struct omap_iommu *obj, u32 da,
+               const struct sg_table *sgt, u32 flags)
 {
        size_t bytes;
        void *va = NULL;
@@ -648,38 +611,41 @@ u32 iommu_vmap(struct iommu *obj, u32 da, const struct sg_table *sgt,
        flags |= IOVMF_DISCONT;
        flags |= IOVMF_MMIO;
 
-       da = __iommu_vmap(obj, da, sgt, va, bytes, flags);
+       da = __iommu_vmap(domain, obj, da, sgt, va, bytes, flags);
        if (IS_ERR_VALUE(da))
                vunmap_sg(va);
 
-       return da;
+       return da + sgtable_offset(sgt);
 }
-EXPORT_SYMBOL_GPL(iommu_vmap);
+EXPORT_SYMBOL_GPL(omap_iommu_vmap);
 
 /**
- * iommu_vunmap  -  release virtual mapping obtained by 'iommu_vmap()'
+ * omap_iommu_vunmap  -  release virtual mapping obtained by 'omap_iommu_vmap()'
  * @obj:       objective iommu
  * @da:                iommu device virtual address
  *
  * Free the iommu virtually contiguous memory area starting at
- * @da, which was returned by 'iommu_vmap()'.
+ * @da, which was returned by 'omap_iommu_vmap()'.
  */
-struct sg_table *iommu_vunmap(struct iommu *obj, u32 da)
+struct sg_table *
+omap_iommu_vunmap(struct iommu_domain *domain, struct omap_iommu *obj, u32 da)
 {
        struct sg_table *sgt;
        /*
-        * 'sgt' is allocated before 'iommu_vmalloc()' is called.
+        * 'sgt' is allocated before 'omap_iommu_vmalloc()' is called.
         * Just returns 'sgt' to the caller to free
         */
-       sgt = unmap_vm_area(obj, da, vunmap_sg, IOVMF_DISCONT | IOVMF_MMIO);
+       da &= PAGE_MASK;
+       sgt = unmap_vm_area(domain, obj, da, vunmap_sg,
+                                       IOVMF_DISCONT | IOVMF_MMIO);
        if (!sgt)
                dev_dbg(obj->dev, "%s: No sgt\n", __func__);
        return sgt;
 }
-EXPORT_SYMBOL_GPL(iommu_vunmap);
+EXPORT_SYMBOL_GPL(omap_iommu_vunmap);
 
 /**
- * iommu_vmalloc  -  (d)-(p)-(v) address allocator and mapper
+ * omap_iommu_vmalloc  -  (d)-(p)-(v) address allocator and mapper
  * @obj:       objective iommu
  * @da:                contiguous iommu virtual memory
  * @bytes:     allocation size
@@ -688,7 +654,9 @@ EXPORT_SYMBOL_GPL(iommu_vunmap);
  * Allocate @bytes linearly and creates 1-n-1 mapping and returns
  * @da again, which might be adjusted if 'IOVMF_DA_FIXED' is not set.
  */
-u32 iommu_vmalloc(struct iommu *obj, u32 da, size_t bytes, u32 flags)
+u32
+omap_iommu_vmalloc(struct iommu_domain *domain, struct omap_iommu *obj, u32 da,
+                                               size_t bytes, u32 flags)
 {
        void *va;
        struct sg_table *sgt;
@@ -712,7 +680,7 @@ u32 iommu_vmalloc(struct iommu *obj, u32 da, size_t bytes, u32 flags)
        }
        sgtable_fill_vmalloc(sgt, va);
 
-       da = __iommu_vmap(obj, da, sgt, va, bytes, flags);
+       da = __iommu_vmap(domain, obj, da, sgt, va, bytes, flags);
        if (IS_ERR_VALUE(da))
                goto err_iommu_vmap;
 
@@ -725,158 +693,28 @@ err_sgt_alloc:
        vfree(va);
        return da;
 }
-EXPORT_SYMBOL_GPL(iommu_vmalloc);
+EXPORT_SYMBOL_GPL(omap_iommu_vmalloc);
 
 /**
- * iommu_vfree  -  release memory allocated by 'iommu_vmalloc()'
+ * omap_iommu_vfree  -  release memory allocated by 'omap_iommu_vmalloc()'
  * @obj:       objective iommu
  * @da:                iommu device virtual address
  *
  * Frees the iommu virtually continuous memory area starting at
- * @da, as obtained from 'iommu_vmalloc()'.
+ * @da, as obtained from 'omap_iommu_vmalloc()'.
  */
-void iommu_vfree(struct iommu *obj, const u32 da)
+void omap_iommu_vfree(struct iommu_domain *domain, struct omap_iommu *obj,
+                                                               const u32 da)
 {
        struct sg_table *sgt;
 
-       sgt = unmap_vm_area(obj, da, vfree, IOVMF_DISCONT | IOVMF_ALLOC);
+       sgt = unmap_vm_area(domain, obj, da, vfree,
+                                               IOVMF_DISCONT | IOVMF_ALLOC);
        if (!sgt)
                dev_dbg(obj->dev, "%s: No sgt\n", __func__);
        sgtable_free(sgt);
 }
-EXPORT_SYMBOL_GPL(iommu_vfree);
-
-static u32 __iommu_kmap(struct iommu *obj, u32 da, u32 pa, void *va,
-                         size_t bytes, u32 flags)
-{
-       struct sg_table *sgt;
-
-       sgt = sgtable_alloc(bytes, flags, da, pa);
-       if (IS_ERR(sgt))
-               return PTR_ERR(sgt);
-
-       sgtable_fill_kmalloc(sgt, pa, da, bytes);
-
-       da = map_iommu_region(obj, da, sgt, va, bytes, flags);
-       if (IS_ERR_VALUE(da)) {
-               sgtable_drain_kmalloc(sgt);
-               sgtable_free(sgt);
-       }
-
-       return da;
-}
-
-/**
- * iommu_kmap  -  (d)-(p)-(v) address mapper
- * @obj:       objective iommu
- * @da:                contiguous iommu virtual memory
- * @pa:                contiguous physical memory
- * @flags:     iovma and page property
- *
- * Creates 1-1-1 mapping and returns @da again, which can be
- * adjusted if 'IOVMF_DA_FIXED' is not set.
- */
-u32 iommu_kmap(struct iommu *obj, u32 da, u32 pa, size_t bytes,
-                u32 flags)
-{
-       void *va;
-
-       if (!obj || !obj->dev || !bytes)
-               return -EINVAL;
-
-       bytes = PAGE_ALIGN(bytes);
-
-       va = ioremap(pa, bytes);
-       if (!va)
-               return -ENOMEM;
-
-       flags |= IOVMF_LINEAR;
-       flags |= IOVMF_MMIO;
-
-       da = __iommu_kmap(obj, da, pa, va, bytes, flags);
-       if (IS_ERR_VALUE(da))
-               iounmap(va);
-
-       return da;
-}
-EXPORT_SYMBOL_GPL(iommu_kmap);
-
-/**
- * iommu_kunmap  -  release virtual mapping obtained by 'iommu_kmap()'
- * @obj:       objective iommu
- * @da:                iommu device virtual address
- *
- * Frees the iommu virtually contiguous memory area starting at
- * @da, which was passed to and was returned by'iommu_kmap()'.
- */
-void iommu_kunmap(struct iommu *obj, u32 da)
-{
-       struct sg_table *sgt;
-       typedef void (*func_t)(const void *);
-
-       sgt = unmap_vm_area(obj, da, (func_t)iounmap,
-                           IOVMF_LINEAR | IOVMF_MMIO);
-       if (!sgt)
-               dev_dbg(obj->dev, "%s: No sgt\n", __func__);
-       sgtable_free(sgt);
-}
-EXPORT_SYMBOL_GPL(iommu_kunmap);
-
-/**
- * iommu_kmalloc  -  (d)-(p)-(v) address allocator and mapper
- * @obj:       objective iommu
- * @da:                contiguous iommu virtual memory
- * @bytes:     bytes for allocation
- * @flags:     iovma and page property
- *
- * Allocate @bytes linearly and creates 1-1-1 mapping and returns
- * @da again, which might be adjusted if 'IOVMF_DA_FIXED' is not set.
- */
-u32 iommu_kmalloc(struct iommu *obj, u32 da, size_t bytes, u32 flags)
-{
-       void *va;
-       u32 pa;
-
-       if (!obj || !obj->dev || !bytes)
-               return -EINVAL;
-
-       bytes = PAGE_ALIGN(bytes);
-
-       va = kmalloc(bytes, GFP_KERNEL | GFP_DMA);
-       if (!va)
-               return -ENOMEM;
-       pa = virt_to_phys(va);
-
-       flags |= IOVMF_LINEAR;
-       flags |= IOVMF_ALLOC;
-
-       da = __iommu_kmap(obj, da, pa, va, bytes, flags);
-       if (IS_ERR_VALUE(da))
-               kfree(va);
-
-       return da;
-}
-EXPORT_SYMBOL_GPL(iommu_kmalloc);
-
-/**
- * iommu_kfree  -  release virtual mapping obtained by 'iommu_kmalloc()'
- * @obj:       objective iommu
- * @da:                iommu device virtual address
- *
- * Frees the iommu virtually contiguous memory area starting at
- * @da, which was passed to and was returned by'iommu_kmalloc()'.
- */
-void iommu_kfree(struct iommu *obj, u32 da)
-{
-       struct sg_table *sgt;
-
-       sgt = unmap_vm_area(obj, da, kfree, IOVMF_LINEAR | IOVMF_ALLOC);
-       if (!sgt)
-               dev_dbg(obj->dev, "%s: No sgt\n", __func__);
-       sgtable_free(sgt);
-}
-EXPORT_SYMBOL_GPL(iommu_kfree);
-
+EXPORT_SYMBOL_GPL(omap_iommu_vfree);
 
 static int __init iovmm_init(void)
 {
index 37e685eafd24a015ba5a61c62193bbceb82eb054..c4897e1075d8ce9bf9ade33fa76b41e1814ec49b 100644 (file)
@@ -65,7 +65,7 @@ hisax_findcard(int driverid)
        return (struct IsdnCardState *) 0;
 }
 
-static __attribute__((format(printf, 3, 4))) void
+static __printf(3, 4) void
 link_debug(struct Channel *chanp, int direction, char *fmt, ...)
 {
        va_list args;
@@ -1068,7 +1068,7 @@ init_d_st(struct Channel *chanp)
        return 0;
 }
 
-static __attribute__((format(printf, 2, 3))) void
+static __printf(2, 3) void
 callc_debug(struct FsmInst *fi, char *fmt, ...)
 {
        va_list args;
index 0a5c42a3f125667b8705c110270c727d82c6c91b..aff45a11a92d49f7f5f5dc245a9c709faee38396 100644 (file)
@@ -1287,9 +1287,9 @@ int jiftime(char *s, long mark);
 
 int HiSax_command(isdn_ctrl * ic);
 int HiSax_writebuf_skb(int id, int chan, int ack, struct sk_buff *skb);
-__attribute__((format(printf, 3, 4)))
+__printf(3, 4)
 void HiSax_putstatus(struct IsdnCardState *cs, char *head, char *fmt, ...);
-__attribute__((format(printf, 3, 0)))
+__printf(3, 0)
 void VHiSax_putstatus(struct IsdnCardState *cs, char *head, char *fmt, va_list args);
 void HiSax_reportcard(int cardnr, int sel);
 int QuickHex(char *txt, u_char * p, int cnt);
index 425d86116f2bbb40c62200e2c23218f6c0ea015c..66ddcab19bbae757415ba0ae40cb41947f08b2fd 100644 (file)
@@ -21,7 +21,7 @@
 #define B_XMTBUFREADY  1
 #define B_ACKPENDING   2
 
-__attribute__((format(printf, 2, 3)))
+__printf(2, 3)
 void debugl1(struct IsdnCardState *cs, char *fmt, ...);
 void DChannel_proc_xmt(struct IsdnCardState *cs);
 void DChannel_proc_rcv(struct IsdnCardState *cs);
index ad291f21b201394d5e0340d29e0e51d1feb8d2b1..1c24e4457b6fc628b2d1ceeb318c3e30f71aa832 100644 (file)
@@ -66,7 +66,7 @@ static char *strL3Event[] =
        "EV_TIMEOUT",
 };
 
-static __attribute__((format(printf, 2, 3))) void
+static __printf(2, 3) void
 l3m_debug(struct FsmInst *fi, char *fmt, ...)
 {
        va_list args;
index 44082637a09fbcfe71701dc69c07fdbcca9c54c4..db247b79e561eb66277b5918fa4642defcdd7363 100644 (file)
@@ -167,7 +167,7 @@ static struct FsmNode L1FnList[] __initdata =
        {ST_L1_F8, EV_IND_RSY,           l1_ignore},
 };
 
-static __attribute__((format(printf, 2, 3)))
+static __printf(2, 3)
 void l1m_debug(struct FsmInst *fi, char *fmt, ...)
 {
        va_list args;
@@ -270,7 +270,7 @@ static char *strDoutEvent[] =
        "EV_DOUT_UNDERRUN",
 };
 
-static __attribute__((format(printf, 2, 3)))
+static __printf(2, 3)
 void dout_debug(struct FsmInst *fi, char *fmt, ...)
 {
        va_list args;
index dc7caaddecf489eccba08cab59a0e649b927edc6..ff203a421863835ff1b908352ebdb3f25c2ce403 100644 (file)
@@ -375,6 +375,18 @@ config LEDS_ASIC3
          cannot be used. This driver supports hardware blinking with an on+off
          period from 62ms to 125s. Say Y to enable LEDs on the HP iPAQ hx4700.
 
+config LEDS_RENESAS_TPU
+       bool "LED support for Renesas TPU"
+       depends on LEDS_CLASS && HAVE_CLK && GENERIC_GPIO
+       help
+         This option enables build of the LED TPU platform driver,
+         suitable to drive any TPU channel on newer Renesas SoCs.
+         The driver controls the GPIO pin connected to the LED via
+         the GPIO framework and expects the LED to be connected to
+         a pin that can be driven in both GPIO mode and using TPU
+         pin function. The latter to support brightness control.
+         Brightness control is supported but hardware blinking is not.
+
 config LEDS_TRIGGERS
        bool "LED Trigger support"
        depends on LEDS_CLASS
index a0a1b89d78a8f6a6e6db088451590c343562f9f7..e4f6bf568880d284cc4743e4cb6231b450d57296 100644 (file)
@@ -42,6 +42,7 @@ obj-$(CONFIG_LEDS_MC13783)            += leds-mc13783.o
 obj-$(CONFIG_LEDS_NS2)                 += leds-ns2.o
 obj-$(CONFIG_LEDS_NETXBIG)             += leds-netxbig.o
 obj-$(CONFIG_LEDS_ASIC3)               += leds-asic3.o
+obj-$(CONFIG_LEDS_RENESAS_TPU)         += leds-renesas-tpu.o
 
 # LED SPI Drivers
 obj-$(CONFIG_LEDS_DAC124S085)          += leds-dac124s085.o
index dc3d3d83191a043de95e7e7b41a5aa47cf57100c..661b692573e7790e7d75a4b815cd7741dfe47c74 100644 (file)
@@ -267,9 +267,14 @@ void led_blink_set(struct led_classdev *led_cdev,
                   unsigned long *delay_on,
                   unsigned long *delay_off)
 {
+       del_timer_sync(&led_cdev->blink_timer);
+
        if (led_cdev->blink_set &&
-           !led_cdev->blink_set(led_cdev, delay_on, delay_off))
+           !led_cdev->blink_set(led_cdev, delay_on, delay_off)) {
+               led_cdev->blink_delay_on = *delay_on;
+               led_cdev->blink_delay_off = *delay_off;
                return;
+       }
 
        /* blink with 1 Hz as default if nothing specified */
        if (!*delay_on && !*delay_off)
index 4bebae733349b90f84230d1b4454942cc9744451..6f1ff93d7cec32862e5cdc7b998586381c401f1c 100644 (file)
@@ -261,9 +261,12 @@ void led_trigger_register_simple(const char *name, struct led_trigger **tp)
        if (trigger) {
                trigger->name = name;
                err = led_trigger_register(trigger);
-               if (err < 0)
+               if (err < 0) {
+                       kfree(trigger);
+                       trigger = NULL;
                        printk(KERN_WARNING "LED trigger %s failed to register"
                                " (%d)\n", name, err);
+               }
        } else
                printk(KERN_WARNING "LED trigger %s failed to register"
                        " (no memory)\n", name);
index 3d8bc327a68d215dcd17694b71f7397692818c4f..504cc26c7e4be9a4ea87ee708e3afd135846b68c 100644 (file)
@@ -121,7 +121,7 @@ static int __devinit create_gpio_led(const struct gpio_led *template,
        }
        led_dat->cdev.brightness_set = gpio_led_set;
        if (template->default_state == LEDS_GPIO_DEFSTATE_KEEP)
-               state = !!gpio_get_value(led_dat->gpio) ^ led_dat->active_low;
+               state = !!gpio_get_value_cansleep(led_dat->gpio) ^ led_dat->active_low;
        else
                state = (template->default_state == LEDS_GPIO_DEFSTATE_ON);
        led_dat->cdev.brightness = state ? LED_FULL : LED_OFF;
index 3dd7090a9a9b1f59c922b1e31c271d8581e38f0c..4dc510fdfa06d8d778ea845d7e4d796f54d359f4 100644 (file)
@@ -421,7 +421,6 @@ err_class_register:
 err_reg_init:
        regulator_put(drvdata->regulator);
 err_regulator_get:
-       i2c_set_clientdata(client, NULL);
        kfree(drvdata);
 err_out:
        return err;
@@ -449,7 +448,7 @@ MODULE_DEVICE_TABLE(i2c, lm3530_id);
 
 static struct i2c_driver lm3530_i2c_driver = {
        .probe = lm3530_probe,
-       .remove = lm3530_remove,
+       .remove = __devexit_p(lm3530_remove),
        .id_table = lm3530_id,
        .driver = {
                .name = LM3530_NAME,
index 9fc122c81f06cfc350ff224d432c1ed0dddeadd8..cb641f1b33429ab2776cb300194b4e0fd00d3fdb 100644 (file)
@@ -97,6 +97,9 @@
 /* Status */
 #define LP5521_EXT_CLK_USED            0x08
 
+/* default R channel current register value */
+#define LP5521_REG_R_CURR_DEFAULT      0xAF
+
 struct lp5521_engine {
        int             id;
        u8              mode;
@@ -175,14 +178,14 @@ static int lp5521_set_engine_mode(struct lp5521_engine *engine, u8 mode)
                mode = LP5521_CMD_DIRECT;
 
        ret = lp5521_read(client, LP5521_REG_OP_MODE, &engine_state);
+       if (ret < 0)
+               return ret;
 
        /* set mode only for this engine */
        engine_state &= ~(engine->engine_mask);
        mode &= engine->engine_mask;
        engine_state |= mode;
-       ret |= lp5521_write(client, LP5521_REG_OP_MODE, engine_state);
-
-       return ret;
+       return lp5521_write(client, LP5521_REG_OP_MODE, engine_state);
 }
 
 static int lp5521_load_program(struct lp5521_engine *eng, const u8 *pattern)
@@ -643,6 +646,7 @@ static int __devinit lp5521_probe(struct i2c_client *client,
        struct lp5521_chip              *chip;
        struct lp5521_platform_data     *pdata;
        int ret, i, led;
+       u8 buf;
 
        chip = kzalloc(sizeof(*chip), GFP_KERNEL);
        if (!chip)
@@ -681,6 +685,20 @@ static int __devinit lp5521_probe(struct i2c_client *client,
                                     * Exact value is not available. 10 - 20ms
                                     * appears to be enough for reset.
                                     */
+
+       /*
+        * Make sure that the chip is reset by reading back the r channel
+        * current reg. This is dummy read is required on some platforms -
+        * otherwise further access to the R G B channels in the
+        * LP5521_REG_ENABLE register will not have any effect - strange!
+        */
+       lp5521_read(client, LP5521_REG_R_CURRENT, &buf);
+       if (buf != LP5521_REG_R_CURR_DEFAULT) {
+               dev_err(&client->dev, "error in reseting chip\n");
+               goto fail2;
+       }
+       usleep_range(10000, 20000);
+
        ret = lp5521_detect(client);
 
        if (ret) {
diff --git a/drivers/leds/leds-renesas-tpu.c b/drivers/leds/leds-renesas-tpu.c
new file mode 100644 (file)
index 0000000..3ee540e
--- /dev/null
@@ -0,0 +1,357 @@
+/*
+ * LED control using Renesas TPU
+ *
+ *  Copyright (C) 2011 Magnus Damm
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/spinlock.h>
+#include <linux/printk.h>
+#include <linux/ioport.h>
+#include <linux/io.h>
+#include <linux/clk.h>
+#include <linux/leds.h>
+#include <linux/platform_data/leds-renesas-tpu.h>
+#include <linux/gpio.h>
+#include <linux/err.h>
+#include <linux/slab.h>
+#include <linux/pm_runtime.h>
+#include <linux/workqueue.h>
+
+enum r_tpu_pin { R_TPU_PIN_UNUSED, R_TPU_PIN_GPIO, R_TPU_PIN_GPIO_FN };
+enum r_tpu_timer { R_TPU_TIMER_UNUSED, R_TPU_TIMER_ON };
+
+struct r_tpu_priv {
+       struct led_classdev ldev;
+       void __iomem *mapbase;
+       struct clk *clk;
+       struct platform_device *pdev;
+       enum r_tpu_pin pin_state;
+       enum r_tpu_timer timer_state;
+       unsigned long min_rate;
+       unsigned int refresh_rate;
+       struct work_struct work;
+       enum led_brightness new_brightness;
+};
+
+static DEFINE_SPINLOCK(r_tpu_lock);
+
+#define TSTR -1 /* Timer start register (shared register) */
+#define TCR  0 /* Timer control register (+0x00) */
+#define TMDR 1 /* Timer mode register (+0x04) */
+#define TIOR 2 /* Timer I/O control register (+0x08) */
+#define TIER 3 /* Timer interrupt enable register (+0x0c) */
+#define TSR  4 /* Timer status register (+0x10) */
+#define TCNT 5 /* Timer counter (+0x14) */
+#define TGRA 6 /* Timer general register A (+0x18) */
+#define TGRB 7 /* Timer general register B (+0x1c) */
+#define TGRC 8 /* Timer general register C (+0x20) */
+#define TGRD 9 /* Timer general register D (+0x24) */
+
+static inline unsigned short r_tpu_read(struct r_tpu_priv *p, int reg_nr)
+{
+       struct led_renesas_tpu_config *cfg = p->pdev->dev.platform_data;
+       void __iomem *base = p->mapbase;
+       unsigned long offs = reg_nr << 2;
+
+       if (reg_nr == TSTR)
+               return ioread16(base - cfg->channel_offset);
+
+       return ioread16(base + offs);
+}
+
+static inline void r_tpu_write(struct r_tpu_priv *p, int reg_nr,
+                              unsigned short value)
+{
+       struct led_renesas_tpu_config *cfg = p->pdev->dev.platform_data;
+       void __iomem *base = p->mapbase;
+       unsigned long offs = reg_nr << 2;
+
+       if (reg_nr == TSTR) {
+               iowrite16(value, base - cfg->channel_offset);
+               return;
+       }
+
+       iowrite16(value, base + offs);
+}
+
+static void r_tpu_start_stop_ch(struct r_tpu_priv *p, int start)
+{
+       struct led_renesas_tpu_config *cfg = p->pdev->dev.platform_data;
+       unsigned long flags, value;
+
+       /* start stop register shared by multiple timer channels */
+       spin_lock_irqsave(&r_tpu_lock, flags);
+       value = r_tpu_read(p, TSTR);
+
+       if (start)
+               value |= 1 << cfg->timer_bit;
+       else
+               value &= ~(1 << cfg->timer_bit);
+
+       r_tpu_write(p, TSTR, value);
+       spin_unlock_irqrestore(&r_tpu_lock, flags);
+}
+
+static int r_tpu_enable(struct r_tpu_priv *p, enum led_brightness brightness)
+{
+       struct led_renesas_tpu_config *cfg = p->pdev->dev.platform_data;
+       int prescaler[] = { 1, 4, 16, 64 };
+       int k, ret;
+       unsigned long rate, tmp;
+
+       if (p->timer_state == R_TPU_TIMER_ON)
+               return 0;
+
+       /* wake up device and enable clock */
+       pm_runtime_get_sync(&p->pdev->dev);
+       ret = clk_enable(p->clk);
+       if (ret) {
+               dev_err(&p->pdev->dev, "cannot enable clock\n");
+               return ret;
+       }
+
+       /* make sure channel is disabled */
+       r_tpu_start_stop_ch(p, 0);
+
+       /* get clock rate after enabling it */
+       rate = clk_get_rate(p->clk);
+
+       /* pick the lowest acceptable rate */
+       for (k = 0; k < ARRAY_SIZE(prescaler); k++)
+               if ((rate / prescaler[k]) < p->min_rate)
+                       break;
+
+       if (!k) {
+               dev_err(&p->pdev->dev, "clock rate mismatch\n");
+               goto err0;
+       }
+       dev_dbg(&p->pdev->dev, "rate = %lu, prescaler %u\n",
+               rate, prescaler[k - 1]);
+
+       /* clear TCNT on TGRB match, count on rising edge, set prescaler */
+       r_tpu_write(p, TCR, 0x0040 | (k - 1));
+
+       /* output 0 until TGRA, output 1 until TGRB */
+       r_tpu_write(p, TIOR, 0x0002);
+
+       rate /= prescaler[k - 1] * p->refresh_rate;
+       r_tpu_write(p, TGRB, rate);
+       dev_dbg(&p->pdev->dev, "TRGB = 0x%04lx\n", rate);
+
+       tmp = (cfg->max_brightness - brightness) * rate;
+       r_tpu_write(p, TGRA, tmp / cfg->max_brightness);
+       dev_dbg(&p->pdev->dev, "TRGA = 0x%04lx\n", tmp / cfg->max_brightness);
+
+       /* PWM mode */
+       r_tpu_write(p, TMDR, 0x0002);
+
+       /* enable channel */
+       r_tpu_start_stop_ch(p, 1);
+
+       p->timer_state = R_TPU_TIMER_ON;
+       return 0;
+ err0:
+       clk_disable(p->clk);
+       pm_runtime_put_sync(&p->pdev->dev);
+       return -ENOTSUPP;
+}
+
+static void r_tpu_disable(struct r_tpu_priv *p)
+{
+       if (p->timer_state == R_TPU_TIMER_UNUSED)
+               return;
+
+       /* disable channel */
+       r_tpu_start_stop_ch(p, 0);
+
+       /* stop clock and mark device as idle */
+       clk_disable(p->clk);
+       pm_runtime_put_sync(&p->pdev->dev);
+
+       p->timer_state = R_TPU_TIMER_UNUSED;
+}
+
+static void r_tpu_set_pin(struct r_tpu_priv *p, enum r_tpu_pin new_state,
+                         enum led_brightness brightness)
+{
+       struct led_renesas_tpu_config *cfg = p->pdev->dev.platform_data;
+
+       if (p->pin_state == new_state) {
+               if (p->pin_state == R_TPU_PIN_GPIO)
+                       gpio_set_value(cfg->pin_gpio, brightness);
+               return;
+       }
+
+       if (p->pin_state == R_TPU_PIN_GPIO)
+               gpio_free(cfg->pin_gpio);
+
+       if (p->pin_state == R_TPU_PIN_GPIO_FN)
+               gpio_free(cfg->pin_gpio_fn);
+
+       if (new_state == R_TPU_PIN_GPIO) {
+               gpio_request(cfg->pin_gpio, cfg->name);
+               gpio_direction_output(cfg->pin_gpio, !!brightness);
+       }
+       if (new_state == R_TPU_PIN_GPIO_FN)
+               gpio_request(cfg->pin_gpio_fn, cfg->name);
+
+       p->pin_state = new_state;
+}
+
+static void r_tpu_work(struct work_struct *work)
+{
+       struct r_tpu_priv *p = container_of(work, struct r_tpu_priv, work);
+       enum led_brightness brightness = p->new_brightness;
+
+       r_tpu_disable(p);
+
+       /* off and maximum are handled as GPIO pins, in between PWM */
+       if ((brightness == 0) || (brightness == p->ldev.max_brightness))
+               r_tpu_set_pin(p, R_TPU_PIN_GPIO, brightness);
+       else {
+               r_tpu_set_pin(p, R_TPU_PIN_GPIO_FN, 0);
+               r_tpu_enable(p, brightness);
+       }
+}
+
+static void r_tpu_set_brightness(struct led_classdev *ldev,
+                                enum led_brightness brightness)
+{
+       struct r_tpu_priv *p = container_of(ldev, struct r_tpu_priv, ldev);
+       p->new_brightness = brightness;
+       schedule_work(&p->work);
+}
+
+static int __devinit r_tpu_probe(struct platform_device *pdev)
+{
+       struct led_renesas_tpu_config *cfg = pdev->dev.platform_data;
+       struct r_tpu_priv *p;
+       struct resource *res;
+       int ret = -ENXIO;
+
+       if (!cfg) {
+               dev_err(&pdev->dev, "missing platform data\n");
+               goto err0;
+       }
+
+       p = kzalloc(sizeof(*p), GFP_KERNEL);
+       if (p == NULL) {
+               dev_err(&pdev->dev, "failed to allocate driver data\n");
+               ret = -ENOMEM;
+               goto err0;
+       }
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!res) {
+               dev_err(&pdev->dev, "failed to get I/O memory\n");
+               goto err1;
+       }
+
+       /* map memory, let mapbase point to our channel */
+       p->mapbase = ioremap_nocache(res->start, resource_size(res));
+       if (p->mapbase == NULL) {
+               dev_err(&pdev->dev, "failed to remap I/O memory\n");
+               goto err1;
+       }
+
+       /* get hold of clock */
+       p->clk = clk_get(&pdev->dev, NULL);
+       if (IS_ERR(p->clk)) {
+               dev_err(&pdev->dev, "cannot get clock\n");
+               ret = PTR_ERR(p->clk);
+               goto err2;
+       }
+
+       p->pdev = pdev;
+       p->pin_state = R_TPU_PIN_UNUSED;
+       p->timer_state = R_TPU_TIMER_UNUSED;
+       p->refresh_rate = cfg->refresh_rate ? cfg->refresh_rate : 100;
+       r_tpu_set_pin(p, R_TPU_PIN_GPIO, LED_OFF);
+       platform_set_drvdata(pdev, p);
+
+       INIT_WORK(&p->work, r_tpu_work);
+
+       p->ldev.name = cfg->name;
+       p->ldev.brightness = LED_OFF;
+       p->ldev.max_brightness = cfg->max_brightness;
+       p->ldev.brightness_set = r_tpu_set_brightness;
+       p->ldev.flags |= LED_CORE_SUSPENDRESUME;
+       ret = led_classdev_register(&pdev->dev, &p->ldev);
+       if (ret < 0)
+               goto err3;
+
+       /* max_brightness may be updated by the LED core code */
+       p->min_rate = p->ldev.max_brightness * p->refresh_rate;
+
+       pm_runtime_enable(&pdev->dev);
+       return 0;
+
+ err3:
+       r_tpu_set_pin(p, R_TPU_PIN_UNUSED, LED_OFF);
+       clk_put(p->clk);
+ err2:
+       iounmap(p->mapbase);
+ err1:
+       kfree(p);
+ err0:
+       return ret;
+}
+
+static int __devexit r_tpu_remove(struct platform_device *pdev)
+{
+       struct r_tpu_priv *p = platform_get_drvdata(pdev);
+
+       r_tpu_set_brightness(&p->ldev, LED_OFF);
+       led_classdev_unregister(&p->ldev);
+       cancel_work_sync(&p->work);
+       r_tpu_disable(p);
+       r_tpu_set_pin(p, R_TPU_PIN_UNUSED, LED_OFF);
+
+       pm_runtime_disable(&pdev->dev);
+       clk_put(p->clk);
+
+       iounmap(p->mapbase);
+       kfree(p);
+       return 0;
+}
+
+static struct platform_driver r_tpu_device_driver = {
+       .probe          = r_tpu_probe,
+       .remove         = __devexit_p(r_tpu_remove),
+       .driver         = {
+               .name   = "leds-renesas-tpu",
+       }
+};
+
+static int __init r_tpu_init(void)
+{
+       return platform_driver_register(&r_tpu_device_driver);
+}
+
+static void __exit r_tpu_exit(void)
+{
+       platform_driver_unregister(&r_tpu_device_driver);
+}
+
+module_init(r_tpu_init);
+module_exit(r_tpu_exit);
+
+MODULE_AUTHOR("Magnus Damm");
+MODULE_DESCRIPTION("Renesas TPU LED Driver");
+MODULE_LICENSE("GPL v2");
index 2535933c49f83cb9fa8b7488caddf6a20dd8db09..b5fdcb78a75b8620e61288c5717f450b2c588592 100644 (file)
@@ -232,6 +232,13 @@ int run_guest(struct lg_cpu *cpu, unsigned long __user *user)
                        }
                }
 
+               /*
+                * All long-lived kernel loops need to check with this horrible
+                * thing called the freezer.  If the Host is trying to suspend,
+                * it stops us.
+                */
+               try_to_freeze();
+
                /* Check for signals */
                if (signal_pending(current))
                        return -ERESTARTSYS;
@@ -245,13 +252,6 @@ int run_guest(struct lg_cpu *cpu, unsigned long __user *user)
                if (irq < LGUEST_IRQS)
                        try_deliver_interrupt(cpu, irq, more);
 
-               /*
-                * All long-lived kernel loops need to check with this horrible
-                * thing called the freezer.  If the Host is trying to suspend,
-                * it stops us.
-                */
-               try_to_freeze();
-
                /*
                 * Just make absolutely sure the Guest is still alive.  One of
                 * those hypercalls could have been fatal, for example.
@@ -313,7 +313,7 @@ static int __init init(void)
        int err;
 
        /* Lguest can't run under Xen, VMI or itself.  It does Tricky Stuff. */
-       if (paravirt_enabled()) {
+       if (get_kernel_rpl() != 0) {
                printk("lguest is afraid of being a guest\n");
                return -EPERM;
        }
index 132c18ef86658ce29bafdaa82773eacf52534bc5..c025a8276dc18b5844e7a6870b42236ac45bd86c 100644 (file)
@@ -1355,7 +1355,7 @@ static int raid10_add_disk(struct mddev *mddev, struct md_rdev *rdev)
                struct mirror_info *p = &conf->mirrors[mirror];
                if (p->recovery_disabled == mddev->recovery_disabled)
                        continue;
-               if (!p->rdev)
+               if (p->rdev)
                        continue;
 
                disk_stack_limits(mddev->gendisk, rdev->bdev,
index 9af2140b57a4c94c6b2571e7fb718747338ab62e..f5d53a2023442fbfe1bb8c9bf77817e0fd051174 100644 (file)
@@ -18,6 +18,8 @@
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <media/saa7146.h>
 
 LIST_HEAD(saa7146_devices);
@@ -35,10 +37,9 @@ static void dump_registers(struct saa7146_dev* dev)
 {
        int i = 0;
 
-       INFO((" @ %li jiffies:\n",jiffies));
-       for(i = 0; i <= 0x148; i+=4) {
-               printk("0x%03x: 0x%08x\n",i,saa7146_read(dev,i));
-       }
+       pr_info(" @ %li jiffies:\n", jiffies);
+       for (i = 0; i <= 0x148; i += 4)
+               pr_info("0x%03x: 0x%08x\n", i, saa7146_read(dev, i));
 }
 #endif
 
@@ -72,9 +73,8 @@ static inline int saa7146_wait_for_debi_done_sleep(struct saa7146_dev *dev,
                if (saa7146_read(dev, MC2) & 2)
                        break;
                if (err) {
-                       printk(KERN_ERR "%s: %s timed out while waiting for "
-                                       "registers getting programmed\n",
-                                       dev->name, __func__);
+                       pr_err("%s: %s timed out while waiting for registers getting programmed\n",
+                              dev->name, __func__);
                        return -ETIMEDOUT;
                }
                msleep(1);
@@ -88,8 +88,8 @@ static inline int saa7146_wait_for_debi_done_sleep(struct saa7146_dev *dev,
                        break;
                saa7146_read(dev, MC2);
                if (err) {
-                       DEB_S(("%s: %s timed out while waiting for transfer "
-                               "completion\n", dev->name, __func__));
+                       DEB_S("%s: %s timed out while waiting for transfer completion\n",
+                             dev->name, __func__);
                        return -ETIMEDOUT;
                }
                msleep(1);
@@ -109,9 +109,8 @@ static inline int saa7146_wait_for_debi_done_busyloop(struct saa7146_dev *dev,
                if (saa7146_read(dev, MC2) & 2)
                        break;
                if (!loops--) {
-                       printk(KERN_ERR "%s: %s timed out while waiting for "
-                                       "registers getting programmed\n",
-                                       dev->name, __func__);
+                       pr_err("%s: %s timed out while waiting for registers getting programmed\n",
+                              dev->name, __func__);
                        return -ETIMEDOUT;
                }
                udelay(1);
@@ -124,8 +123,8 @@ static inline int saa7146_wait_for_debi_done_busyloop(struct saa7146_dev *dev,
                        break;
                saa7146_read(dev, MC2);
                if (!loops--) {
-                       DEB_S(("%s: %s timed out while waiting for transfer "
-                               "completion\n", dev->name, __func__));
+                       DEB_S("%s: %s timed out while waiting for transfer completion\n",
+                             dev->name, __func__);
                        return -ETIMEDOUT;
                }
                udelay(5);
@@ -264,7 +263,9 @@ int saa7146_pgtable_build_single(struct pci_dev *pci, struct saa7146_pgtable *pt
        ptr = pt->cpu;
        for (i = 0; i < sglen; i++, list++) {
 /*
-               printk("i:%d, adr:0x%08x, len:%d, offset:%d\n", i,sg_dma_address(list), sg_dma_len(list), list->offset);
+               pr_debug("i:%d, adr:0x%08x, len:%d, offset:%d\n",
+                        i, sg_dma_address(list), sg_dma_len(list),
+                        list->offset);
 */
                for (p = 0; p * 4096 < list->length; p++, ptr++) {
                        *ptr = cpu_to_le32(sg_dma_address(list) + p * 4096);
@@ -281,9 +282,9 @@ int saa7146_pgtable_build_single(struct pci_dev *pci, struct saa7146_pgtable *pt
 
 /*
        ptr = pt->cpu;
-       printk("offset: %d\n",pt->offset);
+       pr_debug("offset: %d\n", pt->offset);
        for(i=0;i<5;i++) {
-               printk("ptr1 %d: 0x%08x\n",i,ptr[i]);
+               pr_debug("ptr1 %d: 0x%08x\n", i, ptr[i]);
        }
 */
        return 0;
@@ -314,7 +315,7 @@ static irqreturn_t interrupt_hw(int irq, void *dev_id)
                }
        }
        if (0 != (isr & (MASK_27))) {
-               DEB_INT(("irq: RPS0 (0x%08x).\n",isr));
+               DEB_INT("irq: RPS0 (0x%08x)\n", isr);
                if (dev->vv_data && dev->vv_callback)
                        dev->vv_callback(dev,isr);
                isr &= ~MASK_27;
@@ -333,14 +334,15 @@ static irqreturn_t interrupt_hw(int irq, void *dev_id)
                } else {
                        u32 psr = saa7146_read(dev, PSR);
                        u32 ssr = saa7146_read(dev, SSR);
-                       printk(KERN_WARNING "%s: unexpected i2c irq: isr %08x psr %08x ssr %08x\n",
-                              dev->name, isr, psr, ssr);
+                       pr_warn("%s: unexpected i2c irq: isr %08x psr %08x ssr %08x\n",
+                               dev->name, isr, psr, ssr);
                }
                isr &= ~(MASK_16|MASK_17);
        }
        if( 0 != isr ) {
-               ERR(("warning: interrupt enabled, but not handled properly.(0x%08x)\n",isr));
-               ERR(("disabling interrupt source(s)!\n"));
+               ERR("warning: interrupt enabled, but not handled properly.(0x%08x)\n",
+                   isr);
+               ERR("disabling interrupt source(s)!\n");
                SAA7146_IER_DISABLE(dev,isr);
        }
        saa7146_write(dev, ISR, ack_isr);
@@ -360,15 +362,15 @@ static int saa7146_init_one(struct pci_dev *pci, const struct pci_device_id *ent
        /* clear out mem for sure */
        dev = kzalloc(sizeof(struct saa7146_dev), GFP_KERNEL);
        if (!dev) {
-               ERR(("out of memory.\n"));
+               ERR("out of memory\n");
                goto out;
        }
 
-       DEB_EE(("pci:%p\n",pci));
+       DEB_EE("pci:%p\n", pci);
 
        err = pci_enable_device(pci);
        if (err < 0) {
-               ERR(("pci_enable_device() failed.\n"));
+               ERR("pci_enable_device() failed\n");
                goto err_free;
        }
 
@@ -389,7 +391,7 @@ static int saa7146_init_one(struct pci_dev *pci, const struct pci_device_id *ent
        dev->mem = ioremap(pci_resource_start(pci, 0),
                           pci_resource_len(pci, 0));
        if (!dev->mem) {
-               ERR(("ioremap() failed.\n"));
+               ERR("ioremap() failed\n");
                err = -ENODEV;
                goto err_release;
        }
@@ -414,7 +416,7 @@ static int saa7146_init_one(struct pci_dev *pci, const struct pci_device_id *ent
        err = request_irq(pci->irq, interrupt_hw, IRQF_SHARED | IRQF_DISABLED,
                          dev->name, dev);
        if (err < 0) {
-               ERR(("request_irq() failed.\n"));
+               ERR("request_irq() failed\n");
                goto err_unmap;
        }
 
@@ -444,7 +446,9 @@ static int saa7146_init_one(struct pci_dev *pci, const struct pci_device_id *ent
        /* create a nice device name */
        sprintf(dev->name, "saa7146 (%d)", saa7146_num);
 
-       INFO(("found saa7146 @ mem %p (revision %d, irq %d) (0x%04x,0x%04x).\n", dev->mem, dev->revision, pci->irq, pci->subsystem_vendor, pci->subsystem_device));
+       pr_info("found saa7146 @ mem %p (revision %d, irq %d) (0x%04x,0x%04x)\n",
+               dev->mem, dev->revision, pci->irq,
+               pci->subsystem_vendor, pci->subsystem_device);
        dev->ext = ext;
 
        mutex_init(&dev->v4l2_lock);
@@ -464,12 +468,12 @@ static int saa7146_init_one(struct pci_dev *pci, const struct pci_device_id *ent
        err = -ENODEV;
 
        if (ext->probe && ext->probe(dev)) {
-               DEB_D(("ext->probe() failed for %p. skipping device.\n",dev));
+               DEB_D("ext->probe() failed for %p. skipping device.\n", dev);
                goto err_free_i2c;
        }
 
        if (ext->attach(dev, pci_ext)) {
-               DEB_D(("ext->attach() failed for %p. skipping device.\n",dev));
+               DEB_D("ext->attach() failed for %p. skipping device.\n", dev);
                goto err_free_i2c;
        }
        /* V4L extensions will set the pci drvdata to the v4l2_device in the
@@ -521,7 +525,7 @@ static void saa7146_remove_one(struct pci_dev *pdev)
                { NULL, 0 }
        }, *p;
 
-       DEB_EE(("dev:%p\n",dev));
+       DEB_EE("dev:%p\n", dev);
 
        dev->ext->detach(dev);
        /* Zero the PCI drvdata after use. */
@@ -552,21 +556,21 @@ static void saa7146_remove_one(struct pci_dev *pdev)
 
 int saa7146_register_extension(struct saa7146_extension* ext)
 {
-       DEB_EE(("ext:%p\n",ext));
+       DEB_EE("ext:%p\n", ext);
 
        ext->driver.name = ext->name;
        ext->driver.id_table = ext->pci_tbl;
        ext->driver.probe = saa7146_init_one;
        ext->driver.remove = saa7146_remove_one;
 
-       printk("saa7146: register extension '%s'.\n",ext->name);
+       pr_info("register extension '%s'\n", ext->name);
        return pci_register_driver(&ext->driver);
 }
 
 int saa7146_unregister_extension(struct saa7146_extension* ext)
 {
-       DEB_EE(("ext:%p\n",ext));
-       printk("saa7146: unregister extension '%s'.\n",ext->name);
+       DEB_EE("ext:%p\n", ext);
+       pr_info("unregister extension '%s'\n", ext->name);
        pci_unregister_driver(&ext->driver);
        return 0;
 }
index 1bd3dd762c6b9a9c955bbbb3f1035a709fd8bb83..a92546144eaa30dc33695104374841b73b5b2bda 100644 (file)
@@ -1,3 +1,5 @@
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <media/saa7146_vv.h>
 
 /****************************************************************************/
@@ -9,21 +11,23 @@ int saa7146_res_get(struct saa7146_fh *fh, unsigned int bit)
        struct saa7146_vv *vv = dev->vv_data;
 
        if (fh->resources & bit) {
-               DEB_D(("already allocated! want: 0x%02x, cur:0x%02x\n",bit,vv->resources));
+               DEB_D("already allocated! want: 0x%02x, cur:0x%02x\n",
+                     bit, vv->resources);
                /* have it already allocated */
                return 1;
        }
 
        /* is it free? */
        if (vv->resources & bit) {
-               DEB_D(("locked! vv->resources:0x%02x, we want:0x%02x\n",vv->resources,bit));
+               DEB_D("locked! vv->resources:0x%02x, we want:0x%02x\n",
+                     vv->resources, bit);
                /* no, someone else uses it */
                return 0;
        }
        /* it's free, grab it */
-       fh->resources  |= bit;
+       fh->resources |= bit;
        vv->resources |= bit;
-       DEB_D(("res: get 0x%02x, cur:0x%02x\n",bit,vv->resources));
+       DEB_D("res: get 0x%02x, cur:0x%02x\n", bit, vv->resources);
        return 1;
 }
 
@@ -34,9 +38,9 @@ void saa7146_res_free(struct saa7146_fh *fh, unsigned int bits)
 
        BUG_ON((fh->resources & bits) != bits);
 
-       fh->resources  &= ~bits;
+       fh->resources &= ~bits;
        vv->resources &= ~bits;
-       DEB_D(("res: put 0x%02x, cur:0x%02x\n",bits,vv->resources));
+       DEB_D("res: put 0x%02x, cur:0x%02x\n", bits, vv->resources);
 }
 
 
@@ -47,7 +51,7 @@ void saa7146_dma_free(struct saa7146_dev *dev,struct videobuf_queue *q,
                                                struct saa7146_buf *buf)
 {
        struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
-       DEB_EE(("dev:%p, buf:%p\n",dev,buf));
+       DEB_EE("dev:%p, buf:%p\n", dev, buf);
 
        BUG_ON(in_interrupt());
 
@@ -66,18 +70,19 @@ int saa7146_buffer_queue(struct saa7146_dev *dev,
                         struct saa7146_buf *buf)
 {
        assert_spin_locked(&dev->slock);
-       DEB_EE(("dev:%p, dmaq:%p, buf:%p\n", dev, q, buf));
+       DEB_EE("dev:%p, dmaq:%p, buf:%p\n", dev, q, buf);
 
        BUG_ON(!q);
 
        if (NULL == q->curr) {
                q->curr = buf;
-               DEB_D(("immediately activating buffer %p\n", buf));
+               DEB_D("immediately activating buffer %p\n", buf);
                buf->activate(dev,buf,NULL);
        } else {
                list_add_tail(&buf->vb.queue,&q->queue);
                buf->vb.state = VIDEOBUF_QUEUED;
-               DEB_D(("adding buffer %p to queue. (active buffer present)\n", buf));
+               DEB_D("adding buffer %p to queue. (active buffer present)\n",
+                     buf);
        }
        return 0;
 }
@@ -87,14 +92,14 @@ void saa7146_buffer_finish(struct saa7146_dev *dev,
                           int state)
 {
        assert_spin_locked(&dev->slock);
-       DEB_EE(("dev:%p, dmaq:%p, state:%d\n", dev, q, state));
-       DEB_EE(("q->curr:%p\n",q->curr));
+       DEB_EE("dev:%p, dmaq:%p, state:%d\n", dev, q, state);
+       DEB_EE("q->curr:%p\n", q->curr);
 
        BUG_ON(!q->curr);
 
        /* finish current buffer */
        if (NULL == q->curr) {
-               DEB_D(("aiii. no current buffer\n"));
+               DEB_D("aiii. no current buffer\n");
                return;
        }
 
@@ -112,7 +117,7 @@ void saa7146_buffer_next(struct saa7146_dev *dev,
 
        BUG_ON(!q);
 
-       DEB_INT(("dev:%p, dmaq:%p, vbi:%d\n", dev, q, vbi));
+       DEB_INT("dev:%p, dmaq:%p, vbi:%d\n", dev, q, vbi);
 
        assert_spin_locked(&dev->slock);
        if (!list_empty(&q->queue)) {
@@ -122,10 +127,11 @@ void saa7146_buffer_next(struct saa7146_dev *dev,
                if (!list_empty(&q->queue))
                        next = list_entry(q->queue.next,struct saa7146_buf, vb.queue);
                q->curr = buf;
-               DEB_INT(("next buffer: buf:%p, prev:%p, next:%p\n", buf, q->queue.prev,q->queue.next));
+               DEB_INT("next buffer: buf:%p, prev:%p, next:%p\n",
+                       buf, q->queue.prev, q->queue.next);
                buf->activate(dev,buf,next);
        } else {
-               DEB_INT(("no next buffer. stopping.\n"));
+               DEB_INT("no next buffer. stopping.\n");
                if( 0 != vbi ) {
                        /* turn off video-dma3 */
                        saa7146_write(dev,MC1, MASK_20);
@@ -162,11 +168,11 @@ void saa7146_buffer_timeout(unsigned long data)
        struct saa7146_dev *dev = q->dev;
        unsigned long flags;
 
-       DEB_EE(("dev:%p, dmaq:%p\n", dev, q));
+       DEB_EE("dev:%p, dmaq:%p\n", dev, q);
 
        spin_lock_irqsave(&dev->slock,flags);
        if (q->curr) {
-               DEB_D(("timeout on %p\n", q->curr));
+               DEB_D("timeout on %p\n", q->curr);
                saa7146_buffer_finish(dev,q,VIDEOBUF_ERROR);
        }
 
@@ -194,12 +200,12 @@ static int fops_open(struct file *file)
 
        enum v4l2_buf_type type;
 
-       DEB_EE(("file:%p, dev:%s\n", file, video_device_node_name(vdev)));
+       DEB_EE("file:%p, dev:%s\n", file, video_device_node_name(vdev));
 
        if (mutex_lock_interruptible(&saa7146_devices_lock))
                return -ERESTARTSYS;
 
-       DEB_D(("using: %p\n",dev));
+       DEB_D("using: %p\n", dev);
 
        type = vdev->vfl_type == VFL_TYPE_GRABBER
             ? V4L2_BUF_TYPE_VIDEO_CAPTURE
@@ -207,7 +213,7 @@ static int fops_open(struct file *file)
 
        /* check if an extension is registered */
        if( NULL == dev->ext ) {
-               DEB_S(("no extension registered for this device.\n"));
+               DEB_S("no extension registered for this device\n");
                result = -ENODEV;
                goto out;
        }
@@ -215,7 +221,7 @@ static int fops_open(struct file *file)
        /* allocate per open data */
        fh = kzalloc(sizeof(*fh),GFP_KERNEL);
        if (NULL == fh) {
-               DEB_S(("cannot allocate memory for per open data.\n"));
+               DEB_S("cannot allocate memory for per open data\n");
                result = -ENOMEM;
                goto out;
        }
@@ -225,13 +231,13 @@ static int fops_open(struct file *file)
        fh->type = type;
 
        if( fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
-               DEB_S(("initializing vbi...\n"));
+               DEB_S("initializing vbi...\n");
                if (dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE)
                        result = saa7146_vbi_uops.open(dev,file);
                if (dev->ext_vv_data->vbi_fops.open)
                        dev->ext_vv_data->vbi_fops.open(file);
        } else {
-               DEB_S(("initializing video...\n"));
+               DEB_S("initializing video...\n");
                result = saa7146_video_uops.open(dev,file);
        }
 
@@ -259,7 +265,7 @@ static int fops_release(struct file *file)
        struct saa7146_fh  *fh  = file->private_data;
        struct saa7146_dev *dev = fh->dev;
 
-       DEB_EE(("file:%p\n", file));
+       DEB_EE("file:%p\n", file);
 
        if (mutex_lock_interruptible(&saa7146_devices_lock))
                return -ERESTARTSYS;
@@ -289,12 +295,14 @@ static int fops_mmap(struct file *file, struct vm_area_struct * vma)
 
        switch (fh->type) {
        case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
-               DEB_EE(("V4L2_BUF_TYPE_VIDEO_CAPTURE: file:%p, vma:%p\n",file, vma));
+               DEB_EE("V4L2_BUF_TYPE_VIDEO_CAPTURE: file:%p, vma:%p\n",
+                      file, vma);
                q = &fh->video_q;
                break;
                }
        case V4L2_BUF_TYPE_VBI_CAPTURE: {
-               DEB_EE(("V4L2_BUF_TYPE_VBI_CAPTURE: file:%p, vma:%p\n",file, vma));
+               DEB_EE("V4L2_BUF_TYPE_VBI_CAPTURE: file:%p, vma:%p\n",
+                      file, vma);
                q = &fh->vbi_q;
                break;
                }
@@ -312,14 +320,14 @@ static unsigned int fops_poll(struct file *file, struct poll_table_struct *wait)
        struct videobuf_buffer *buf = NULL;
        struct videobuf_queue *q;
 
-       DEB_EE(("file:%p, poll:%p\n",file, wait));
+       DEB_EE("file:%p, poll:%p\n", file, wait);
 
        if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) {
                if( 0 == fh->vbi_q.streaming )
                        return videobuf_poll_stream(file, &fh->vbi_q, wait);
                q = &fh->vbi_q;
        } else {
-               DEB_D(("using video queue.\n"));
+               DEB_D("using video queue\n");
                q = &fh->video_q;
        }
 
@@ -327,17 +335,17 @@ static unsigned int fops_poll(struct file *file, struct poll_table_struct *wait)
                buf = list_entry(q->stream.next, struct videobuf_buffer, stream);
 
        if (!buf) {
-               DEB_D(("buf == NULL!\n"));
+               DEB_D("buf == NULL!\n");
                return POLLERR;
        }
 
        poll_wait(file, &buf->done, wait);
        if (buf->state == VIDEOBUF_DONE || buf->state == VIDEOBUF_ERROR) {
-               DEB_D(("poll succeeded!\n"));
+               DEB_D("poll succeeded!\n");
                return POLLIN|POLLRDNORM;
        }
 
-       DEB_D(("nothing to poll for, buf->state:%d\n",buf->state));
+       DEB_D("nothing to poll for, buf->state:%d\n", buf->state);
        return 0;
 }
 
@@ -346,18 +354,20 @@ static ssize_t fops_read(struct file *file, char __user *data, size_t count, lof
        struct saa7146_fh *fh = file->private_data;
 
        switch (fh->type) {
-       case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
-//             DEB_EE(("V4L2_BUF_TYPE_VIDEO_CAPTURE: file:%p, data:%p, count:%lun", file, data, (unsigned long)count));
+       case V4L2_BUF_TYPE_VIDEO_CAPTURE:
+/*
+               DEB_EE("V4L2_BUF_TYPE_VIDEO_CAPTURE: file:%p, data:%p, count:%lun",
+                      file, data, (unsigned long)count);
+*/
                return saa7146_video_uops.read(file,data,count,ppos);
-               }
-       case V4L2_BUF_TYPE_VBI_CAPTURE: {
-//             DEB_EE(("V4L2_BUF_TYPE_VBI_CAPTURE: file:%p, data:%p, count:%lu\n", file, data, (unsigned long)count));
+       case V4L2_BUF_TYPE_VBI_CAPTURE:
+/*
+               DEB_EE("V4L2_BUF_TYPE_VBI_CAPTURE: file:%p, data:%p, count:%lu\n",
+                      file, data, (unsigned long)count);
+*/
                if (fh->dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE)
                        return saa7146_vbi_uops.read(file,data,count,ppos);
-               else
-                       return -EINVAL;
-               }
-               break;
+               return -EINVAL;
        default:
                BUG();
                return 0;
@@ -398,22 +408,22 @@ static void vv_callback(struct saa7146_dev *dev, unsigned long status)
 {
        u32 isr = status;
 
-       DEB_INT(("dev:%p, isr:0x%08x\n",dev,(u32)status));
+       DEB_INT("dev:%p, isr:0x%08x\n", dev, (u32)status);
 
        if (0 != (isr & (MASK_27))) {
-               DEB_INT(("irq: RPS0 (0x%08x).\n",isr));
+               DEB_INT("irq: RPS0 (0x%08x)\n", isr);
                saa7146_video_uops.irq_done(dev,isr);
        }
 
        if (0 != (isr & (MASK_28))) {
                u32 mc2 = saa7146_read(dev, MC2);
                if( 0 != (mc2 & MASK_15)) {
-                       DEB_INT(("irq: RPS1 vbi workaround (0x%08x).\n",isr));
+                       DEB_INT("irq: RPS1 vbi workaround (0x%08x)\n", isr);
                        wake_up(&dev->vv_data->vbi_wq);
                        saa7146_write(dev,MC2, MASK_31);
                        return;
                }
-               DEB_INT(("irq: RPS1 (0x%08x).\n",isr));
+               DEB_INT("irq: RPS1 (0x%08x)\n", isr);
                saa7146_vbi_uops.irq_done(dev,isr);
        }
 }
@@ -429,13 +439,13 @@ int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv)
 
        vv = kzalloc(sizeof(struct saa7146_vv), GFP_KERNEL);
        if (vv == NULL) {
-               ERR(("out of memory. aborting.\n"));
+               ERR("out of memory. aborting.\n");
                return -ENOMEM;
        }
        ext_vv->ops = saa7146_video_ioctl_ops;
        ext_vv->core_ops = &saa7146_video_ioctl_ops;
 
-       DEB_EE(("dev:%p\n",dev));
+       DEB_EE("dev:%p\n", dev);
 
        /* set default values for video parts of the saa7146 */
        saa7146_write(dev, BCS_CTRL, 0x80400040);
@@ -450,7 +460,7 @@ int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv)
 
        vv->d_clipping.cpu_addr = pci_alloc_consistent(dev->pci, SAA7146_CLIPPING_MEM, &vv->d_clipping.dma_handle);
        if( NULL == vv->d_clipping.cpu_addr ) {
-               ERR(("out of memory. aborting.\n"));
+               ERR("out of memory. aborting.\n");
                kfree(vv);
                return -1;
        }
@@ -471,7 +481,7 @@ int saa7146_vv_release(struct saa7146_dev* dev)
 {
        struct saa7146_vv *vv = dev->vv_data;
 
-       DEB_EE(("dev:%p\n",dev));
+       DEB_EE("dev:%p\n", dev);
 
        v4l2_device_unregister(&dev->v4l2_dev);
        pci_free_consistent(dev->pci, SAA7146_CLIPPING_MEM, vv->d_clipping.cpu_addr, vv->d_clipping.dma_handle);
@@ -490,7 +500,7 @@ int saa7146_register_device(struct video_device **vid, struct saa7146_dev* dev,
        int err;
        int i;
 
-       DEB_EE(("dev:%p, name:'%s', type:%d\n",dev,name,type));
+       DEB_EE("dev:%p, name:'%s', type:%d\n", dev, name, type);
 
        // released by vfd->release
        vfd = video_device_alloc();
@@ -509,13 +519,13 @@ int saa7146_register_device(struct video_device **vid, struct saa7146_dev* dev,
 
        err = video_register_device(vfd, type, -1);
        if (err < 0) {
-               ERR(("cannot register v4l2 device. skipping.\n"));
+               ERR("cannot register v4l2 device. skipping.\n");
                video_device_release(vfd);
                return err;
        }
 
-       INFO(("%s: registered device %s [v4l2]\n",
-               dev->name, video_device_node_name(vfd)));
+       pr_info("%s: registered device %s [v4l2]\n",
+               dev->name, video_device_node_name(vfd));
 
        *vid = vfd;
        return 0;
@@ -524,7 +534,7 @@ EXPORT_SYMBOL_GPL(saa7146_register_device);
 
 int saa7146_unregister_device(struct video_device **vid, struct saa7146_dev* dev)
 {
-       DEB_EE(("dev:%p\n",dev));
+       DEB_EE("dev:%p\n", dev);
 
        video_unregister_device(*vid);
        *vid = NULL;
index 1d1d8d200755a2c9af0ca241b983dd55f1a672a4..79ad73accb27426a058c03ef4481be174988eda0 100644 (file)
@@ -1,3 +1,5 @@
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/kernel.h>
 #include <media/saa7146_vv.h>
 
@@ -711,8 +713,8 @@ static int calculate_video_dma_grab_packed(struct saa7146_dev* dev, struct saa71
 
        int depth = sfmt->depth;
 
-       DEB_CAP(("[size=%dx%d,fields=%s]\n",
-               width,height,v4l2_field_names[field]));
+       DEB_CAP("[size=%dx%d,fields=%s]\n",
+               width, height, v4l2_field_names[field]);
 
        if( bytesperline != 0) {
                vdma1.pitch = bytesperline*2;
@@ -837,8 +839,8 @@ static int calculate_video_dma_grab_planar(struct saa7146_dev* dev, struct saa71
        BUG_ON(0 == buf->pt[1].dma);
        BUG_ON(0 == buf->pt[2].dma);
 
-       DEB_CAP(("[size=%dx%d,fields=%s]\n",
-               width,height,v4l2_field_names[field]));
+       DEB_CAP("[size=%dx%d,fields=%s]\n",
+               width, height, v4l2_field_names[field]);
 
        /* fixme: look at bytesperline! */
 
@@ -998,12 +1000,12 @@ void saa7146_set_capture(struct saa7146_dev *dev, struct saa7146_buf *buf, struc
        struct saa7146_vv *vv = dev->vv_data;
        u32 vdma1_prot_addr;
 
-       DEB_CAP(("buf:%p, next:%p\n",buf,next));
+       DEB_CAP("buf:%p, next:%p\n", buf, next);
 
        vdma1_prot_addr = saa7146_read(dev, PROT_ADDR1);
        if( 0 == vdma1_prot_addr ) {
                /* clear out beginning of streaming bit (rps register 0)*/
-               DEB_CAP(("forcing sync to new frame\n"));
+               DEB_CAP("forcing sync to new frame\n");
                saa7146_write(dev, MC2, MASK_27 );
        }
 
index b2ba9dc0dd6dc1cd81bbc5c242b7ed3f1f6fb449..22027198129d375ed063b0d3bbeb7073b5130d32 100644 (file)
@@ -1,8 +1,10 @@
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <media/saa7146_vv.h>
 
 static u32 saa7146_i2c_func(struct i2c_adapter *adapter)
 {
-//fm   DEB_I2C(("'%s'.\n", adapter->name));
+       /* DEB_I2C("'%s'\n", adapter->name); */
 
        return    I2C_FUNC_I2C
                | I2C_FUNC_SMBUS_QUICK
@@ -14,9 +16,7 @@ static u32 saa7146_i2c_func(struct i2c_adapter *adapter)
 static inline u32 saa7146_i2c_status(struct saa7146_dev *dev)
 {
        u32 iicsta = saa7146_read(dev, I2C_STATUS);
-/*
-       DEB_I2C(("status: 0x%08x\n",iicsta));
-*/
+       /* DEB_I2C("status: 0x%08x\n", iicsta); */
        return iicsta;
 }
 
@@ -39,10 +39,11 @@ static int saa7146_i2c_msg_prepare(const struct i2c_msg *m, int num, __le32 *op)
           plus one extra byte to address the device */
        mem = 1 + ((mem-1) / 3);
 
-       /* we assume that op points to a memory of at least SAA7146_I2C_MEM bytes
-          size. if we exceed this limit... */
-       if ( (4*mem) > SAA7146_I2C_MEM ) {
-//fm           DEB_I2C(("cannot prepare i2c-message.\n"));
+       /* we assume that op points to a memory of at least
+        * SAA7146_I2C_MEM bytes size. if we exceed this limit...
+        */
+       if ((4 * mem) > SAA7146_I2C_MEM) {
+               /* DEB_I2C("cannot prepare i2c-message\n"); */
                return -ENOMEM;
        }
 
@@ -123,7 +124,7 @@ static int saa7146_i2c_reset(struct saa7146_dev *dev)
        if ( 0 != ( status & SAA7146_I2C_BUSY) ) {
 
                /* yes, kill ongoing operation */
-               DEB_I2C(("busy_state detected.\n"));
+               DEB_I2C("busy_state detected\n");
 
                /* set "ABORT-OPERATION"-bit (bit 7)*/
                saa7146_write(dev, I2C_STATUS, (dev->i2c_bitrate | MASK_07));
@@ -141,7 +142,7 @@ static int saa7146_i2c_reset(struct saa7146_dev *dev)
 
        if ( dev->i2c_bitrate != status ) {
 
-               DEB_I2C(("error_state detected. status:0x%08x\n",status));
+               DEB_I2C("error_state detected. status:0x%08x\n", status);
 
                /* Repeat the abort operation. This seems to be necessary
                   after serious protocol errors caused by e.g. the SAA7740 */
@@ -164,7 +165,7 @@ static int saa7146_i2c_reset(struct saa7146_dev *dev)
        /* if any error is still present, a fatal error has occurred ... */
        status = saa7146_i2c_status(dev);
        if ( dev->i2c_bitrate != status ) {
-               DEB_I2C(("fatal error. status:0x%08x\n",status));
+               DEB_I2C("fatal error. status:0x%08x\n", status);
                return -1;
        }
 
@@ -181,7 +182,8 @@ static int saa7146_i2c_writeout(struct saa7146_dev *dev, __le32 *dword, int shor
        unsigned long timeout;
 
        /* write out i2c-command */
-       DEB_I2C(("before: 0x%08x (status: 0x%08x), %d\n",*dword,saa7146_read(dev, I2C_STATUS), dev->i2c_op));
+       DEB_I2C("before: 0x%08x (status: 0x%08x), %d\n",
+               *dword, saa7146_read(dev, I2C_STATUS), dev->i2c_op);
 
        if( 0 != (SAA7146_USE_I2C_IRQ & dev->ext->flags)) {
 
@@ -202,7 +204,7 @@ static int saa7146_i2c_writeout(struct saa7146_dev *dev, __le32 *dword, int shor
                                /* a signal arrived */
                                return -ERESTARTSYS;
 
-                       printk(KERN_WARNING "%s %s [irq]: timed out waiting for end of xfer\n",
+                       pr_warn("%s %s [irq]: timed out waiting for end of xfer\n",
                                dev->name, __func__);
                        return -EIO;
                }
@@ -220,7 +222,7 @@ static int saa7146_i2c_writeout(struct saa7146_dev *dev, __le32 *dword, int shor
                                break;
                        }
                        if (time_after(jiffies,timeout)) {
-                               printk(KERN_WARNING "%s %s: timed out waiting for MC2\n",
+                               pr_warn("%s %s: timed out waiting for MC2\n",
                                        dev->name, __func__);
                                return -EIO;
                        }
@@ -237,7 +239,7 @@ static int saa7146_i2c_writeout(struct saa7146_dev *dev, __le32 *dword, int shor
                                /* this is normal when probing the bus
                                 * (no answer from nonexisistant device...)
                                 */
-                               printk(KERN_WARNING "%s %s [poll]: timed out waiting for end of xfer\n",
+                               pr_warn("%s %s [poll]: timed out waiting for end of xfer\n",
                                        dev->name, __func__);
                                return -EIO;
                        }
@@ -257,24 +259,24 @@ static int saa7146_i2c_writeout(struct saa7146_dev *dev, __le32 *dword, int shor
                if ( 0 == (status & SAA7146_I2C_ERR) ||
                     0 == (status & SAA7146_I2C_BUSY) ) {
                        /* it may take some time until ERR goes high - ignore */
-                       DEB_I2C(("unexpected i2c status %04x\n", status));
+                       DEB_I2C("unexpected i2c status %04x\n", status);
                }
                if( 0 != (status & SAA7146_I2C_SPERR) ) {
-                       DEB_I2C(("error due to invalid start/stop condition.\n"));
+                       DEB_I2C("error due to invalid start/stop condition\n");
                }
                if( 0 != (status & SAA7146_I2C_DTERR) ) {
-                       DEB_I2C(("error in data transmission.\n"));
+                       DEB_I2C("error in data transmission\n");
                }
                if( 0 != (status & SAA7146_I2C_DRERR) ) {
-                       DEB_I2C(("error when receiving data.\n"));
+                       DEB_I2C("error when receiving data\n");
                }
                if( 0 != (status & SAA7146_I2C_AL) ) {
-                       DEB_I2C(("error because arbitration lost.\n"));
+                       DEB_I2C("error because arbitration lost\n");
                }
 
                /* we handle address-errors here */
                if( 0 != (status & SAA7146_I2C_APERR) ) {
-                       DEB_I2C(("error in address phase.\n"));
+                       DEB_I2C("error in address phase\n");
                        return -EREMOTEIO;
                }
 
@@ -284,7 +286,7 @@ static int saa7146_i2c_writeout(struct saa7146_dev *dev, __le32 *dword, int shor
        /* read back data, just in case we were reading ... */
        *dword = cpu_to_le32(saa7146_read(dev, I2C_TRANSFER));
 
-       DEB_I2C(("after: 0x%08x\n",*dword));
+       DEB_I2C("after: 0x%08x\n", *dword);
        return 0;
 }
 
@@ -299,7 +301,7 @@ static int saa7146_i2c_transfer(struct saa7146_dev *dev, const struct i2c_msg *m
                return -ERESTARTSYS;
 
        for(i=0;i<num;i++) {
-               DEB_I2C(("msg:%d/%d\n",i+1,num));
+               DEB_I2C("msg:%d/%d\n", i+1, num);
        }
 
        /* prepare the message(s), get number of u32s to transfer */
@@ -316,7 +318,7 @@ static int saa7146_i2c_transfer(struct saa7146_dev *dev, const struct i2c_msg *m
                /* reset the i2c-device if necessary */
                err = saa7146_i2c_reset(dev);
                if ( 0 > err ) {
-                       DEB_I2C(("could not reset i2c-device.\n"));
+                       DEB_I2C("could not reset i2c-device\n");
                        goto out;
                }
 
@@ -336,7 +338,7 @@ static int saa7146_i2c_transfer(struct saa7146_dev *dev, const struct i2c_msg *m
                                   address error and trust the saa7146 address error detection. */
                                if (-EREMOTEIO == err && 0 != (SAA7146_USE_I2C_IRQ & dev->ext->flags))
                                        goto out;
-                               DEB_I2C(("error while sending message(s). starting again.\n"));
+                               DEB_I2C("error while sending message(s). starting again\n");
                                break;
                        }
                }
@@ -356,13 +358,13 @@ static int saa7146_i2c_transfer(struct saa7146_dev *dev, const struct i2c_msg *m
 
        /* if any things had to be read, get the results */
        if ( 0 != saa7146_i2c_msg_cleanup(msgs, num, buffer)) {
-               DEB_I2C(("could not cleanup i2c-message.\n"));
+               DEB_I2C("could not cleanup i2c-message\n");
                err = -1;
                goto out;
        }
 
        /* return the number of delivered messages */
-       DEB_I2C(("transmission successful. (msg:%d).\n",err));
+       DEB_I2C("transmission successful. (msg:%d)\n", err);
 out:
        /* another bug in revision 0: the i2c-registers get uploaded randomly by other
           uploads, so we better clear them out before continuing */
@@ -370,7 +372,7 @@ out:
                __le32 zero = 0;
                saa7146_i2c_reset(dev);
                if( 0 != saa7146_i2c_writeout(dev, &zero, short_delay)) {
-                       INFO(("revision 0 error. this should never happen.\n"));
+                       pr_info("revision 0 error. this should never happen\n");
                }
        }
 
@@ -400,7 +402,7 @@ static struct i2c_algorithm saa7146_algo = {
 
 int saa7146_i2c_adapter_prepare(struct saa7146_dev *dev, struct i2c_adapter *i2c_adapter, u32 bitrate)
 {
-       DEB_EE(("bitrate: 0x%08x\n",bitrate));
+       DEB_EE("bitrate: 0x%08x\n", bitrate);
 
        /* enable i2c-port pins */
        saa7146_write(dev, MC1, (MASK_08 | MASK_24));
index afe85801d6ca8480309db96d77c9215b200dbd63..b2e7183437399c9b53fafd751c52100846f91f3c 100644 (file)
@@ -14,7 +14,7 @@ static int vbi_workaround(struct saa7146_dev *dev)
 
        DECLARE_WAITQUEUE(wait, current);
 
-       DEB_VBI(("dev:%p\n",dev));
+       DEB_VBI("dev:%p\n", dev);
 
        /* once again, a bug in the saa7146: the brs acquisition
           is buggy and especially the BXO-counter does not work
@@ -40,14 +40,14 @@ static int vbi_workaround(struct saa7146_dev *dev)
        WRITE_RPS1(0xc000008c);
        /* wait for vbi_a or vbi_b*/
        if ( 0 != (SAA7146_USE_PORT_B_FOR_VBI & dev->ext_vv_data->flags)) {
-               DEB_D(("...using port b\n"));
+               DEB_D("...using port b\n");
                WRITE_RPS1(CMD_PAUSE | CMD_OAN | CMD_SIG1 | CMD_E_FID_B);
                WRITE_RPS1(CMD_PAUSE | CMD_OAN | CMD_SIG1 | CMD_O_FID_B);
 /*
                WRITE_RPS1(CMD_PAUSE | MASK_09);
 */
        } else {
-               DEB_D(("...using port a\n"));
+               DEB_D("...using port a\n");
                WRITE_RPS1(CMD_PAUSE | MASK_10);
        }
        /* upload brs */
@@ -103,7 +103,7 @@ static int vbi_workaround(struct saa7146_dev *dev)
 
                schedule();
 
-               DEB_VBI(("brs bug workaround %d/1.\n",i));
+               DEB_VBI("brs bug workaround %d/1\n", i);
 
                remove_wait_queue(&vv->vbi_wq, &wait);
                current->state = TASK_RUNNING;
@@ -116,7 +116,8 @@ static int vbi_workaround(struct saa7146_dev *dev)
 
                if(signal_pending(current)) {
 
-                       DEB_VBI(("aborted (rps:0x%08x).\n",saa7146_read(dev,RPS_ADDR1)));
+                       DEB_VBI("aborted (rps:0x%08x)\n",
+                               saa7146_read(dev, RPS_ADDR1));
 
                        /* stop rps1 for sure */
                        saa7146_write(dev, MC1, MASK_29);
@@ -207,7 +208,7 @@ static int buffer_activate(struct saa7146_dev *dev,
        struct saa7146_vv *vv = dev->vv_data;
        buf->vb.state = VIDEOBUF_ACTIVE;
 
-       DEB_VBI(("dev:%p, buf:%p, next:%p\n",dev,buf,next));
+       DEB_VBI("dev:%p, buf:%p, next:%p\n", dev, buf, next);
        saa7146_set_vbi_capture(dev,buf,next);
 
        mod_timer(&vv->vbi_q.timeout, jiffies+BUFFER_TIMEOUT);
@@ -228,10 +229,10 @@ static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,e
        llength = vbi_pixel_to_capture;
        size = lines * llength;
 
-       DEB_VBI(("vb:%p\n",vb));
+       DEB_VBI("vb:%p\n", vb);
 
        if (0 != buf->vb.baddr  &&  buf->vb.bsize < size) {
-               DEB_VBI(("size mismatch.\n"));
+               DEB_VBI("size mismatch\n");
                return -EINVAL;
        }
 
@@ -263,7 +264,7 @@ static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,e
        return 0;
 
  oops:
-       DEB_VBI(("error out.\n"));
+       DEB_VBI("error out\n");
        saa7146_dma_free(dev,q,buf);
 
        return err;
@@ -279,7 +280,7 @@ static int buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned
        *size = lines * llength;
        *count = 2;
 
-       DEB_VBI(("count:%d, size:%d\n",*count,*size));
+       DEB_VBI("count:%d, size:%d\n", *count, *size);
 
        return 0;
 }
@@ -292,7 +293,7 @@ static void buffer_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
        struct saa7146_vv *vv = dev->vv_data;
        struct saa7146_buf *buf = (struct saa7146_buf *)vb;
 
-       DEB_VBI(("vb:%p\n",vb));
+       DEB_VBI("vb:%p\n", vb);
        saa7146_buffer_queue(dev,&vv->vbi_q,buf);
 }
 
@@ -303,7 +304,7 @@ static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
        struct saa7146_dev *dev = fh->dev;
        struct saa7146_buf *buf = (struct saa7146_buf *)vb;
 
-       DEB_VBI(("vb:%p\n",vb));
+       DEB_VBI("vb:%p\n", vb);
        saa7146_dma_free(dev,q,buf);
 }
 
@@ -321,7 +322,7 @@ static void vbi_stop(struct saa7146_fh *fh, struct file *file)
        struct saa7146_dev *dev = fh->dev;
        struct saa7146_vv *vv = dev->vv_data;
        unsigned long flags;
-       DEB_VBI(("dev:%p, fh:%p\n",dev, fh));
+       DEB_VBI("dev:%p, fh:%p\n", dev, fh);
 
        spin_lock_irqsave(&dev->slock,flags);
 
@@ -354,14 +355,14 @@ static void vbi_read_timeout(unsigned long data)
        struct saa7146_fh *fh = file->private_data;
        struct saa7146_dev *dev = fh->dev;
 
-       DEB_VBI(("dev:%p, fh:%p\n",dev, fh));
+       DEB_VBI("dev:%p, fh:%p\n", dev, fh);
 
        vbi_stop(fh, file);
 }
 
 static void vbi_init(struct saa7146_dev *dev, struct saa7146_vv *vv)
 {
-       DEB_VBI(("dev:%p\n",dev));
+       DEB_VBI("dev:%p\n", dev);
 
        INIT_LIST_HEAD(&vv->vbi_q.queue);
 
@@ -380,11 +381,11 @@ static int vbi_open(struct saa7146_dev *dev, struct file *file)
        u32 arbtr_ctrl  = saa7146_read(dev, PCI_BT_V1);
        int ret = 0;
 
-       DEB_VBI(("dev:%p, fh:%p\n",dev,fh));
+       DEB_VBI("dev:%p, fh:%p\n", dev, fh);
 
        ret = saa7146_res_get(fh, RESOURCE_DMA3_BRS);
        if (0 == ret) {
-               DEB_S(("cannot get vbi RESOURCE_DMA3_BRS resource\n"));
+               DEB_S("cannot get vbi RESOURCE_DMA3_BRS resource\n");
                return -EBUSY;
        }
 
@@ -425,7 +426,7 @@ static int vbi_open(struct saa7146_dev *dev, struct file *file)
                saa7146_write(dev, BRS_CTRL, 0x00000001);
 
                if (0 != (ret = vbi_workaround(dev))) {
-                       DEB_VBI(("vbi workaround failed!\n"));
+                       DEB_VBI("vbi workaround failed!\n");
                        /* return ret;*/
                }
        }
@@ -439,7 +440,7 @@ static void vbi_close(struct saa7146_dev *dev, struct file *file)
 {
        struct saa7146_fh *fh = file->private_data;
        struct saa7146_vv *vv = dev->vv_data;
-       DEB_VBI(("dev:%p, fh:%p\n",dev,fh));
+       DEB_VBI("dev:%p, fh:%p\n", dev, fh);
 
        if( fh == vv->vbi_streaming ) {
                vbi_stop(fh, file);
@@ -453,13 +454,13 @@ static void vbi_irq_done(struct saa7146_dev *dev, unsigned long status)
        spin_lock(&dev->slock);
 
        if (vv->vbi_q.curr) {
-               DEB_VBI(("dev:%p, curr:%p\n",dev,vv->vbi_q.curr));
+               DEB_VBI("dev:%p, curr:%p\n", dev, vv->vbi_q.curr);
                /* this must be += 2, one count for each field */
                vv->vbi_fieldcount+=2;
                vv->vbi_q.curr->vb.field_count = vv->vbi_fieldcount;
                saa7146_buffer_finish(dev,&vv->vbi_q,VIDEOBUF_DONE);
        } else {
-               DEB_VBI(("dev:%p\n",dev));
+               DEB_VBI("dev:%p\n", dev);
        }
        saa7146_buffer_next(dev,&vv->vbi_q,1);
 
@@ -473,7 +474,7 @@ static ssize_t vbi_read(struct file *file, char __user *data, size_t count, loff
        struct saa7146_vv *vv = dev->vv_data;
        ssize_t ret = 0;
 
-       DEB_VBI(("dev:%p, fh:%p\n",dev,fh));
+       DEB_VBI("dev:%p, fh:%p\n", dev, fh);
 
        if( NULL == vv->vbi_streaming ) {
                // fixme: check if dma3 is available
@@ -482,7 +483,8 @@ static ssize_t vbi_read(struct file *file, char __user *data, size_t count, loff
        }
 
        if( fh != vv->vbi_streaming ) {
-               DEB_VBI(("open %p is already using vbi capture.",vv->vbi_streaming));
+               DEB_VBI("open %p is already using vbi capture\n",
+                       vv->vbi_streaming);
                return -EBUSY;
        }
 
index 9aafa4e969a8c741c95f01bd01efa6d4bcf12019..384b358d30379dfcdef7a99428bea28c24f7b77f 100644 (file)
@@ -1,3 +1,5 @@
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <media/saa7146_vv.h>
 #include <media/v4l2-chip-ident.h>
 
@@ -94,7 +96,7 @@ struct saa7146_format* saa7146_format_by_fourcc(struct saa7146_dev *dev, int fou
                }
        }
 
-       DEB_D(("unknown pixelformat:'%4.4s'\n",(char *)&fourcc));
+       DEB_D("unknown pixelformat:'%4.4s'\n", (char *)&fourcc);
        return NULL;
 }
 
@@ -107,32 +109,32 @@ int saa7146_start_preview(struct saa7146_fh *fh)
        struct v4l2_format fmt;
        int ret = 0, err = 0;
 
-       DEB_EE(("dev:%p, fh:%p\n",dev,fh));
+       DEB_EE("dev:%p, fh:%p\n", dev, fh);
 
        /* check if we have overlay informations */
        if( NULL == fh->ov.fh ) {
-               DEB_D(("no overlay data available. try S_FMT first.\n"));
+               DEB_D("no overlay data available. try S_FMT first.\n");
                return -EAGAIN;
        }
 
        /* check if streaming capture is running */
        if (IS_CAPTURE_ACTIVE(fh) != 0) {
-               DEB_D(("streaming capture is active.\n"));
+               DEB_D("streaming capture is active\n");
                return -EBUSY;
        }
 
        /* check if overlay is running */
        if (IS_OVERLAY_ACTIVE(fh) != 0) {
                if (vv->video_fh == fh) {
-                       DEB_D(("overlay is already active.\n"));
+                       DEB_D("overlay is already active\n");
                        return 0;
                }
-               DEB_D(("overlay is already active in another open.\n"));
+               DEB_D("overlay is already active in another open\n");
                return -EBUSY;
        }
 
        if (0 == saa7146_res_get(fh, RESOURCE_DMA1_HPS|RESOURCE_DMA2_CLP)) {
-               DEB_D(("cannot get necessary overlay resources\n"));
+               DEB_D("cannot get necessary overlay resources\n");
                return -EBUSY;
        }
 
@@ -145,13 +147,13 @@ int saa7146_start_preview(struct saa7146_fh *fh)
        fh->ov.win = fmt.fmt.win;
        vv->ov_data = &fh->ov;
 
-       DEB_D(("%dx%d+%d+%d %s field=%s\n",
-               fh->ov.win.w.width,fh->ov.win.w.height,
-               fh->ov.win.w.left,fh->ov.win.w.top,
-               vv->ov_fmt->name,v4l2_field_names[fh->ov.win.field]));
+       DEB_D("%dx%d+%d+%d %s field=%s\n",
+             fh->ov.win.w.width, fh->ov.win.w.height,
+             fh->ov.win.w.left, fh->ov.win.w.top,
+             vv->ov_fmt->name, v4l2_field_names[fh->ov.win.field]);
 
        if (0 != (ret = saa7146_enable_overlay(fh))) {
-               DEB_D(("enabling overlay failed: %d\n",ret));
+               DEB_D("enabling overlay failed: %d\n", ret);
                saa7146_res_free(vv->video_fh, RESOURCE_DMA1_HPS|RESOURCE_DMA2_CLP);
                return ret;
        }
@@ -168,22 +170,22 @@ int saa7146_stop_preview(struct saa7146_fh *fh)
        struct saa7146_dev *dev = fh->dev;
        struct saa7146_vv *vv = dev->vv_data;
 
-       DEB_EE(("dev:%p, fh:%p\n",dev,fh));
+       DEB_EE("dev:%p, fh:%p\n", dev, fh);
 
        /* check if streaming capture is running */
        if (IS_CAPTURE_ACTIVE(fh) != 0) {
-               DEB_D(("streaming capture is active.\n"));
+               DEB_D("streaming capture is active\n");
                return -EBUSY;
        }
 
        /* check if overlay is running at all */
        if ((vv->video_status & STATUS_OVERLAY) == 0) {
-               DEB_D(("no active overlay.\n"));
+               DEB_D("no active overlay\n");
                return 0;
        }
 
        if (vv->video_fh != fh) {
-               DEB_D(("overlay is active, but in another open.\n"));
+               DEB_D("overlay is active, but in another open\n");
                return -EBUSY;
        }
 
@@ -268,7 +270,7 @@ static int saa7146_pgtable_build(struct saa7146_dev *dev, struct saa7146_buf *bu
        int length = dma->sglen;
        struct saa7146_format *sfmt = saa7146_format_by_fourcc(dev,buf->fmt->pixelformat);
 
-       DEB_EE(("dev:%p, buf:%p, sg_len:%d\n",dev,buf,length));
+       DEB_EE("dev:%p, buf:%p, sg_len:%d\n", dev, buf, length);
 
        if( 0 != IS_PLANAR(sfmt->trans)) {
                struct saa7146_pgtable *pt1 = &buf->pt[0];
@@ -288,7 +290,8 @@ static int saa7146_pgtable_build(struct saa7146_dev *dev, struct saa7146_buf *bu
                                m3 = ((size+(size/2)+PAGE_SIZE)/PAGE_SIZE)-1;
                                o1 = size%PAGE_SIZE;
                                o2 = (size+(size/4))%PAGE_SIZE;
-                               DEB_CAP(("size:%d, m1:%d, m2:%d, m3:%d, o1:%d, o2:%d\n",size,m1,m2,m3,o1,o2));
+                               DEB_CAP("size:%d, m1:%d, m2:%d, m3:%d, o1:%d, o2:%d\n",
+                                       size, m1, m2, m3, o1, o2);
                                break;
                        }
                        case 16: {
@@ -298,7 +301,8 @@ static int saa7146_pgtable_build(struct saa7146_dev *dev, struct saa7146_buf *bu
                                m3 = ((2*size+PAGE_SIZE)/PAGE_SIZE)-1;
                                o1 = size%PAGE_SIZE;
                                o2 = (size+(size/2))%PAGE_SIZE;
-                               DEB_CAP(("size:%d, m1:%d, m2:%d, m3:%d, o1:%d, o2:%d\n",size,m1,m2,m3,o1,o2));
+                               DEB_CAP("size:%d, m1:%d, m2:%d, m3:%d, o1:%d, o2:%d\n",
+                                       size, m1, m2, m3, o1, o2);
                                break;
                        }
                        default: {
@@ -387,23 +391,23 @@ static int video_begin(struct saa7146_fh *fh)
        unsigned int resource;
        int ret = 0, err = 0;
 
-       DEB_EE(("dev:%p, fh:%p\n",dev,fh));
+       DEB_EE("dev:%p, fh:%p\n", dev, fh);
 
        if ((vv->video_status & STATUS_CAPTURE) != 0) {
                if (vv->video_fh == fh) {
-                       DEB_S(("already capturing.\n"));
+                       DEB_S("already capturing\n");
                        return 0;
                }
-               DEB_S(("already capturing in another open.\n"));
+               DEB_S("already capturing in another open\n");
                return -EBUSY;
        }
 
        if ((vv->video_status & STATUS_OVERLAY) != 0) {
-               DEB_S(("warning: suspending overlay video for streaming capture.\n"));
+               DEB_S("warning: suspending overlay video for streaming capture\n");
                vv->ov_suspend = vv->video_fh;
                err = saa7146_stop_preview(vv->video_fh); /* side effect: video_status is now 0, video_fh is NULL */
                if (0 != err) {
-                       DEB_D(("suspending video failed. aborting\n"));
+                       DEB_D("suspending video failed. aborting\n");
                        return err;
                }
        }
@@ -420,7 +424,7 @@ static int video_begin(struct saa7146_fh *fh)
 
        ret = saa7146_res_get(fh, resource);
        if (0 == ret) {
-               DEB_S(("cannot get capture resource %d\n",resource));
+               DEB_S("cannot get capture resource %d\n", resource);
                if (vv->ov_suspend != NULL) {
                        saa7146_start_preview(vv->ov_suspend);
                        vv->ov_suspend = NULL;
@@ -448,15 +452,15 @@ static int video_end(struct saa7146_fh *fh, struct file *file)
        unsigned long flags;
        unsigned int resource;
        u32 dmas = 0;
-       DEB_EE(("dev:%p, fh:%p\n",dev,fh));
+       DEB_EE("dev:%p, fh:%p\n", dev, fh);
 
        if ((vv->video_status & STATUS_CAPTURE) != STATUS_CAPTURE) {
-               DEB_S(("not capturing.\n"));
+               DEB_S("not capturing\n");
                return 0;
        }
 
        if (vv->video_fh != fh) {
-               DEB_S(("capturing, but in another open.\n"));
+               DEB_S("capturing, but in another open\n");
                return -EBUSY;
        }
 
@@ -530,7 +534,7 @@ static int vidioc_s_fbuf(struct file *file, void *fh, struct v4l2_framebuffer *f
        struct saa7146_vv *vv = dev->vv_data;
        struct saa7146_format *fmt;
 
-       DEB_EE(("VIDIOC_S_FBUF\n"));
+       DEB_EE("VIDIOC_S_FBUF\n");
 
        if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO))
                return -EPERM;
@@ -542,13 +546,13 @@ static int vidioc_s_fbuf(struct file *file, void *fh, struct v4l2_framebuffer *f
 
        /* planar formats are not allowed for overlay video, clipping and video dma would clash */
        if (fmt->flags & FORMAT_IS_PLANAR)
-               DEB_S(("planar pixelformat '%4.4s' not allowed for overlay\n",
-                                       (char *)&fmt->pixelformat));
+               DEB_S("planar pixelformat '%4.4s' not allowed for overlay\n",
+                     (char *)&fmt->pixelformat);
 
        /* check if overlay is running */
        if (IS_OVERLAY_ACTIVE(fh) != 0) {
                if (vv->video_fh != fh) {
-                       DEB_D(("refusing to change framebuffer informations while overlay is active in another open.\n"));
+                       DEB_D("refusing to change framebuffer informations while overlay is active in another open\n");
                        return -EBUSY;
                }
        }
@@ -559,7 +563,7 @@ static int vidioc_s_fbuf(struct file *file, void *fh, struct v4l2_framebuffer *f
 
        if (vv->ov_fb.fmt.bytesperline < vv->ov_fb.fmt.width) {
                vv->ov_fb.fmt.bytesperline = vv->ov_fb.fmt.width * fmt->depth / 8;
-               DEB_D(("setting bytesperline to %d\n", vv->ov_fb.fmt.bytesperline));
+               DEB_D("setting bytesperline to %d\n", vv->ov_fb.fmt.bytesperline);
        }
        return 0;
 }
@@ -588,7 +592,7 @@ static int vidioc_queryctrl(struct file *file, void *fh, struct v4l2_queryctrl *
        if (ctrl == NULL)
                return -EINVAL;
 
-       DEB_EE(("VIDIOC_QUERYCTRL: id:%d\n", c->id));
+       DEB_EE("VIDIOC_QUERYCTRL: id:%d\n", c->id);
        *c = *ctrl;
        return 0;
 }
@@ -607,25 +611,25 @@ static int vidioc_g_ctrl(struct file *file, void *fh, struct v4l2_control *c)
        case V4L2_CID_BRIGHTNESS:
                value = saa7146_read(dev, BCS_CTRL);
                c->value = 0xff & (value >> 24);
-               DEB_D(("V4L2_CID_BRIGHTNESS: %d\n", c->value));
+               DEB_D("V4L2_CID_BRIGHTNESS: %d\n", c->value);
                break;
        case V4L2_CID_CONTRAST:
                value = saa7146_read(dev, BCS_CTRL);
                c->value = 0x7f & (value >> 16);
-               DEB_D(("V4L2_CID_CONTRAST: %d\n", c->value));
+               DEB_D("V4L2_CID_CONTRAST: %d\n", c->value);
                break;
        case V4L2_CID_SATURATION:
                value = saa7146_read(dev, BCS_CTRL);
                c->value = 0x7f & (value >> 0);
-               DEB_D(("V4L2_CID_SATURATION: %d\n", c->value));
+               DEB_D("V4L2_CID_SATURATION: %d\n", c->value);
                break;
        case V4L2_CID_VFLIP:
                c->value = vv->vflip;
-               DEB_D(("V4L2_CID_VFLIP: %d\n", c->value));
+               DEB_D("V4L2_CID_VFLIP: %d\n", c->value);
                break;
        case V4L2_CID_HFLIP:
                c->value = vv->hflip;
-               DEB_D(("V4L2_CID_HFLIP: %d\n", c->value));
+               DEB_D("V4L2_CID_HFLIP: %d\n", c->value);
                break;
        default:
                return -EINVAL;
@@ -641,7 +645,7 @@ static int vidioc_s_ctrl(struct file *file, void *fh, struct v4l2_control *c)
 
        ctrl = ctrl_by_id(c->id);
        if (NULL == ctrl) {
-               DEB_D(("unknown control %d\n", c->id));
+               DEB_D("unknown control %d\n", c->id);
                return -EINVAL;
        }
 
@@ -686,14 +690,14 @@ static int vidioc_s_ctrl(struct file *file, void *fh, struct v4l2_control *c)
        case V4L2_CID_HFLIP:
                /* fixme: we can support changing VFLIP and HFLIP here... */
                if (IS_CAPTURE_ACTIVE(fh) != 0) {
-                       DEB_D(("V4L2_CID_HFLIP while active capture.\n"));
+                       DEB_D("V4L2_CID_HFLIP while active capture\n");
                        return -EBUSY;
                }
                vv->hflip = c->value;
                break;
        case V4L2_CID_VFLIP:
                if (IS_CAPTURE_ACTIVE(fh) != 0) {
-                       DEB_D(("V4L2_CID_VFLIP while active capture.\n"));
+                       DEB_D("V4L2_CID_VFLIP while active capture\n");
                        return -EBUSY;
                }
                vv->vflip = c->value;
@@ -748,7 +752,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_forma
        int maxw, maxh;
        int calc_bpl;
 
-       DEB_EE(("V4L2_BUF_TYPE_VIDEO_CAPTURE: dev:%p, fh:%p\n", dev, fh));
+       DEB_EE("V4L2_BUF_TYPE_VIDEO_CAPTURE: dev:%p, fh:%p\n", dev, fh);
 
        fmt = saa7146_format_by_fourcc(dev, f->fmt.pix.pixelformat);
        if (NULL == fmt)
@@ -777,7 +781,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_forma
                vv->last_field = V4L2_FIELD_INTERLACED;
                break;
        default:
-               DEB_D(("no known field mode '%d'.\n", field));
+               DEB_D("no known field mode '%d'\n", field);
                return -EINVAL;
        }
 
@@ -796,8 +800,9 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_forma
                f->fmt.pix.bytesperline = calc_bpl;
 
        f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * f->fmt.pix.height;
-       DEB_D(("w:%d, h:%d, bytesperline:%d, sizeimage:%d\n", f->fmt.pix.width,
-                       f->fmt.pix.height, f->fmt.pix.bytesperline, f->fmt.pix.sizeimage));
+       DEB_D("w:%d, h:%d, bytesperline:%d, sizeimage:%d\n",
+             f->fmt.pix.width, f->fmt.pix.height,
+             f->fmt.pix.bytesperline, f->fmt.pix.sizeimage);
 
        return 0;
 }
@@ -811,22 +816,23 @@ static int vidioc_try_fmt_vid_overlay(struct file *file, void *fh, struct v4l2_f
        enum v4l2_field field;
        int maxw, maxh;
 
-       DEB_EE(("dev:%p\n", dev));
+       DEB_EE("dev:%p\n", dev);
 
        if (NULL == vv->ov_fb.base) {
-               DEB_D(("no fb base set.\n"));
+               DEB_D("no fb base set\n");
                return -EINVAL;
        }
        if (NULL == vv->ov_fmt) {
-               DEB_D(("no fb fmt set.\n"));
+               DEB_D("no fb fmt set\n");
                return -EINVAL;
        }
        if (win->w.width < 48 || win->w.height < 32) {
-               DEB_D(("min width/height. (%d,%d)\n", win->w.width, win->w.height));
+               DEB_D("min width/height. (%d,%d)\n",
+                     win->w.width, win->w.height);
                return -EINVAL;
        }
        if (win->clipcount > 16) {
-               DEB_D(("clipcount too big.\n"));
+               DEB_D("clipcount too big\n");
                return -EINVAL;
        }
 
@@ -848,7 +854,7 @@ static int vidioc_try_fmt_vid_overlay(struct file *file, void *fh, struct v4l2_f
        case V4L2_FIELD_INTERLACED:
                break;
        default:
-               DEB_D(("no known field mode '%d'.\n", field));
+               DEB_D("no known field mode '%d'\n", field);
                return -EINVAL;
        }
 
@@ -868,16 +874,17 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *__fh, struct v4l2_forma
        struct saa7146_vv *vv = dev->vv_data;
        int err;
 
-       DEB_EE(("V4L2_BUF_TYPE_VIDEO_CAPTURE: dev:%p, fh:%p\n", dev, fh));
+       DEB_EE("V4L2_BUF_TYPE_VIDEO_CAPTURE: dev:%p, fh:%p\n", dev, fh);
        if (IS_CAPTURE_ACTIVE(fh) != 0) {
-               DEB_EE(("streaming capture is active\n"));
+               DEB_EE("streaming capture is active\n");
                return -EBUSY;
        }
        err = vidioc_try_fmt_vid_cap(file, fh, f);
        if (0 != err)
                return err;
        fh->video_fmt = f->fmt.pix;
-       DEB_EE(("set to pixelformat '%4.4s'\n", (char *)&fh->video_fmt.pixelformat));
+       DEB_EE("set to pixelformat '%4.4s'\n",
+              (char *)&fh->video_fmt.pixelformat);
        return 0;
 }
 
@@ -888,7 +895,7 @@ static int vidioc_s_fmt_vid_overlay(struct file *file, void *__fh, struct v4l2_f
        struct saa7146_vv *vv = dev->vv_data;
        int err;
 
-       DEB_EE(("V4L2_BUF_TYPE_VIDEO_OVERLAY: dev:%p, fh:%p\n", dev, fh));
+       DEB_EE("V4L2_BUF_TYPE_VIDEO_OVERLAY: dev:%p, fh:%p\n", dev, fh);
        err = vidioc_try_fmt_vid_overlay(file, fh, f);
        if (0 != err)
                return err;
@@ -931,7 +938,7 @@ static int vidioc_g_std(struct file *file, void *fh, v4l2_std_id *norm)
                if (e->index < 0 )
                        return -EINVAL;
                if( e->index < dev->ext_vv_data->num_stds ) {
-                       DEB_EE(("VIDIOC_ENUMSTD: index:%d\n",e->index));
+                       DEB_EE("VIDIOC_ENUMSTD: index:%d\n", e->index);
                        v4l2_video_std_construct(e, dev->ext_vv_data->stds[e->index].id, dev->ext_vv_data->stds[e->index].name);
                        return 0;
                }
@@ -946,10 +953,10 @@ static int vidioc_s_std(struct file *file, void *fh, v4l2_std_id *id)
        int found = 0;
        int err, i;
 
-       DEB_EE(("VIDIOC_S_STD\n"));
+       DEB_EE("VIDIOC_S_STD\n");
 
        if ((vv->video_status & STATUS_CAPTURE) == STATUS_CAPTURE) {
-               DEB_D(("cannot change video standard while streaming capture is active\n"));
+               DEB_D("cannot change video standard while streaming capture is active\n");
                return -EBUSY;
        }
 
@@ -957,7 +964,7 @@ static int vidioc_s_std(struct file *file, void *fh, v4l2_std_id *id)
                vv->ov_suspend = vv->video_fh;
                err = saa7146_stop_preview(vv->video_fh); /* side effect: video_status is now 0, video_fh is NULL */
                if (0 != err) {
-                       DEB_D(("suspending video failed. aborting\n"));
+                       DEB_D("suspending video failed. aborting\n");
                        return err;
                }
        }
@@ -978,11 +985,11 @@ static int vidioc_s_std(struct file *file, void *fh, v4l2_std_id *id)
        }
 
        if (!found) {
-               DEB_EE(("VIDIOC_S_STD: standard not found.\n"));
+               DEB_EE("VIDIOC_S_STD: standard not found\n");
                return -EINVAL;
        }
 
-       DEB_EE(("VIDIOC_S_STD: set to standard to '%s'\n", vv->standard->name));
+       DEB_EE("VIDIOC_S_STD: set to standard to '%s'\n", vv->standard->name);
        return 0;
 }
 
@@ -990,7 +997,7 @@ static int vidioc_overlay(struct file *file, void *fh, unsigned int on)
 {
        int err;
 
-       DEB_D(("VIDIOC_OVERLAY on:%d\n", on));
+       DEB_D("VIDIOC_OVERLAY on:%d\n", on);
        if (on)
                err = saa7146_start_preview(fh);
        else
@@ -1047,7 +1054,7 @@ static int vidioc_streamon(struct file *file, void *__fh, enum v4l2_buf_type typ
        struct saa7146_fh *fh = __fh;
        int err;
 
-       DEB_D(("VIDIOC_STREAMON, type:%d\n", type));
+       DEB_D("VIDIOC_STREAMON, type:%d\n", type);
 
        err = video_begin(fh);
        if (err)
@@ -1066,18 +1073,18 @@ static int vidioc_streamoff(struct file *file, void *__fh, enum v4l2_buf_type ty
        struct saa7146_vv *vv = dev->vv_data;
        int err;
 
-       DEB_D(("VIDIOC_STREAMOFF, type:%d\n", type));
+       DEB_D("VIDIOC_STREAMOFF, type:%d\n", type);
 
        /* ugly: we need to copy some checks from video_end(),
           because videobuf_streamoff() relies on the capture running.
           check and fix this */
        if ((vv->video_status & STATUS_CAPTURE) != STATUS_CAPTURE) {
-               DEB_S(("not capturing.\n"));
+               DEB_S("not capturing\n");
                return 0;
        }
 
        if (vv->video_fh != fh) {
-               DEB_S(("capturing, but in another open.\n"));
+               DEB_S("capturing, but in another open\n");
                return -EBUSY;
        }
 
@@ -1087,7 +1094,7 @@ static int vidioc_streamoff(struct file *file, void *__fh, enum v4l2_buf_type ty
        else if (type == V4L2_BUF_TYPE_VBI_CAPTURE)
                err = videobuf_streamoff(&fh->vbi_q);
        if (0 != err) {
-               DEB_D(("warning: videobuf_streamoff() failed.\n"));
+               DEB_D("warning: videobuf_streamoff() failed\n");
                video_end(fh, file);
        } else {
                err = video_end(fh, file);
@@ -1174,25 +1181,27 @@ static int buffer_prepare(struct videobuf_queue *q,
        struct saa7146_buf *buf = (struct saa7146_buf *)vb;
        int size,err = 0;
 
-       DEB_CAP(("vbuf:%p\n",vb));
+       DEB_CAP("vbuf:%p\n", vb);
 
        /* sanity checks */
        if (fh->video_fmt.width  < 48 ||
            fh->video_fmt.height < 32 ||
            fh->video_fmt.width  > vv->standard->h_max_out ||
            fh->video_fmt.height > vv->standard->v_max_out) {
-               DEB_D(("w (%d) / h (%d) out of bounds.\n",fh->video_fmt.width,fh->video_fmt.height));
+               DEB_D("w (%d) / h (%d) out of bounds\n",
+                     fh->video_fmt.width, fh->video_fmt.height);
                return -EINVAL;
        }
 
        size = fh->video_fmt.sizeimage;
        if (0 != buf->vb.baddr && buf->vb.bsize < size) {
-               DEB_D(("size mismatch.\n"));
+               DEB_D("size mismatch\n");
                return -EINVAL;
        }
 
-       DEB_CAP(("buffer_prepare [size=%dx%d,bytes=%d,fields=%s]\n",
-               fh->video_fmt.width,fh->video_fmt.height,size,v4l2_field_names[fh->video_fmt.field]));
+       DEB_CAP("buffer_prepare [size=%dx%d,bytes=%d,fields=%s]\n",
+               fh->video_fmt.width, fh->video_fmt.height,
+               size, v4l2_field_names[fh->video_fmt.field]);
        if (buf->vb.width  != fh->video_fmt.width  ||
            buf->vb.bytesperline != fh->video_fmt.bytesperline ||
            buf->vb.height != fh->video_fmt.height ||
@@ -1238,7 +1247,7 @@ static int buffer_prepare(struct videobuf_queue *q,
        return 0;
 
  oops:
-       DEB_D(("error out.\n"));
+       DEB_D("error out\n");
        saa7146_dma_free(dev,q,buf);
 
        return err;
@@ -1259,7 +1268,7 @@ static int buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned
                *count = (max_memory*1048576) / *size;
        }
 
-       DEB_CAP(("%d buffers, %d bytes each.\n",*count,*size));
+       DEB_CAP("%d buffers, %d bytes each\n", *count, *size);
 
        return 0;
 }
@@ -1272,7 +1281,7 @@ static void buffer_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
        struct saa7146_vv *vv = dev->vv_data;
        struct saa7146_buf *buf = (struct saa7146_buf *)vb;
 
-       DEB_CAP(("vbuf:%p\n",vb));
+       DEB_CAP("vbuf:%p\n", vb);
        saa7146_buffer_queue(fh->dev,&vv->video_q,buf);
 }
 
@@ -1283,7 +1292,7 @@ static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
        struct saa7146_dev *dev = fh->dev;
        struct saa7146_buf *buf = (struct saa7146_buf *)vb;
 
-       DEB_CAP(("vbuf:%p\n",vb));
+       DEB_CAP("vbuf:%p\n", vb);
 
        saa7146_dma_free(dev,q,buf);
 
@@ -1347,18 +1356,14 @@ static void video_close(struct saa7146_dev *dev, struct file *file)
        struct saa7146_fh *fh = file->private_data;
        struct saa7146_vv *vv = dev->vv_data;
        struct videobuf_queue *q = &fh->video_q;
-       int err;
 
-       if (IS_CAPTURE_ACTIVE(fh) != 0) {
-               err = video_end(fh, file);
-       } else if (IS_OVERLAY_ACTIVE(fh) != 0) {
-               err = saa7146_stop_preview(fh);
-       }
+       if (IS_CAPTURE_ACTIVE(fh) != 0)
+               video_end(fh, file);
+       else if (IS_OVERLAY_ACTIVE(fh) != 0)
+               saa7146_stop_preview(fh);
 
        videobuf_stop(q);
-
        /* hmm, why is this function declared void? */
-       /* return err */
 }
 
 
@@ -1368,7 +1373,7 @@ static void video_irq_done(struct saa7146_dev *dev, unsigned long st)
        struct saa7146_dmaqueue *q = &vv->video_q;
 
        spin_lock(&dev->slock);
-       DEB_CAP(("called.\n"));
+       DEB_CAP("called\n");
 
        /* only finish the buffer if we have one... */
        if( NULL != q->curr ) {
@@ -1386,15 +1391,15 @@ static ssize_t video_read(struct file *file, char __user *data, size_t count, lo
        struct saa7146_vv *vv = dev->vv_data;
        ssize_t ret = 0;
 
-       DEB_EE(("called.\n"));
+       DEB_EE("called\n");
 
        if ((vv->video_status & STATUS_CAPTURE) != 0) {
                /* fixme: should we allow read() captures while streaming capture? */
                if (vv->video_fh == fh) {
-                       DEB_S(("already capturing.\n"));
+                       DEB_S("already capturing\n");
                        return -EBUSY;
                }
-               DEB_S(("already capturing in another open.\n"));
+               DEB_S("already capturing in another open\n");
                return -EBUSY;
        }
 
index 20d24fca2cfbae8bea894665b7918bb890748d66..196c12a55f9aa7e3d1fefa80d54d6a605c5425ee 100644 (file)
@@ -28,5 +28,5 @@ obj-$(CONFIG_MEDIA_TUNER_MAX2165) += max2165.o
 obj-$(CONFIG_MEDIA_TUNER_TDA18218) += tda18218.o
 obj-$(CONFIG_MEDIA_TUNER_TDA18212) += tda18212.o
 
-EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
-EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
+ccflags-y += -Idrivers/media/dvb/dvb-core
+ccflags-y += -Idrivers/media/dvb/frontends
index d0e70e10a7178214d8cee4a7892f4c73ea2d232f..0e74e97e0d1ab24c0e9ebf1eb56b8bef2b5f0d54 100644 (file)
@@ -430,11 +430,10 @@ static void mt2050_set_antenna(struct dvb_frontend *fe, unsigned char antenna)
 {
        struct microtune_priv *priv = fe->tuner_priv;
        unsigned char buf[2];
-       int ret;
 
        buf[0] = 6;
        buf[1] = antenna ? 0x11 : 0x10;
-       ret=tuner_i2c_xfer_send(&priv->i2c_props,buf,2);
+       tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
        tuner_dbg("mt2050: enabled antenna connector %d\n", antenna);
 }
 
@@ -574,21 +573,20 @@ static int mt2050_init(struct dvb_frontend *fe)
 {
        struct microtune_priv *priv = fe->tuner_priv;
        unsigned char buf[2];
-       int ret;
 
-       buf[0]=6;
-       buf[1]=0x10;
-       ret=tuner_i2c_xfer_send(&priv->i2c_props,buf,2); //  power
+       buf[0] = 6;
+       buf[1] = 0x10;
+       tuner_i2c_xfer_send(&priv->i2c_props, buf, 2); /* power */
 
-       buf[0]=0x0f;
-       buf[1]=0x0f;
-       ret=tuner_i2c_xfer_send(&priv->i2c_props,buf,2); // m1lo
+       buf[0] = 0x0f;
+       buf[1] = 0x0f;
+       tuner_i2c_xfer_send(&priv->i2c_props, buf, 2); /* m1lo */
 
-       buf[0]=0x0d;
-       ret=tuner_i2c_xfer_send(&priv->i2c_props,buf,1);
-       tuner_i2c_xfer_recv(&priv->i2c_props,buf,1);
+       buf[0] = 0x0d;
+       tuner_i2c_xfer_send(&priv->i2c_props, buf, 1);
+       tuner_i2c_xfer_recv(&priv->i2c_props, buf, 1);
 
-       tuner_dbg("mt2050: sro is %x\n",buf[0]);
+       tuner_dbg("mt2050: sro is %x\n", buf[0]);
 
        memcpy(&fe->ops.tuner_ops, &mt2050_tuner_ops, sizeof(struct dvb_tuner_ops));
 
index 56fe75c94deb7c6cded17507b957921077102d5b..54be9e6faaaf394c8be9020a39119af149058d28 100644 (file)
@@ -309,7 +309,6 @@ static u16 MXL_ControlWrite_Group(struct dvb_frontend *fe, u16 controlNum,
 static u16 MXL_SetGPIO(struct dvb_frontend *fe, u8 GPIO_Num, u8 GPIO_Val);
 static u16 MXL_GetInitRegister(struct dvb_frontend *fe, u8 *RegNum,
        u8 *RegVal, int *count);
-static u32 MXL_GetXtalInt(u32 Xtal_Freq);
 static u16 MXL_TuneRF(struct dvb_frontend *fe, u32 RF_Freq);
 static void MXL_SynthIFLO_Calc(struct dvb_frontend *fe);
 static void MXL_SynthRFTGLO_Calc(struct dvb_frontend *fe);
@@ -2307,14 +2306,6 @@ static u16 MXL_IFSynthInit(struct dvb_frontend *fe)
        return status ;
 }
 
-static u32 MXL_GetXtalInt(u32 Xtal_Freq)
-{
-       if ((Xtal_Freq % 1000000) == 0)
-               return (Xtal_Freq / 10000);
-       else
-               return (((Xtal_Freq / 1000000) + 1)*100);
-}
-
 static u16 MXL_TuneRF(struct dvb_frontend *fe, u32 RF_Freq)
 {
        struct mxl5005s_state *state = fe->tuner_priv;
@@ -2324,13 +2315,10 @@ static u16 MXL_TuneRF(struct dvb_frontend *fe, u32 RF_Freq)
        u32 Kdbl_RF = 2;
        u32 tg_divval;
        u32 tg_lo;
-       u32 Xtal_Int;
 
        u32 Fref_TG;
        u32 Fvco;
 
-       Xtal_Int = MXL_GetXtalInt(state->Fxtal);
-
        state->RF_IN = RF_Freq;
 
        MXL_SynthRFTGLO_Calc(fe);
@@ -2779,6 +2767,16 @@ static u16 MXL_TuneRF(struct dvb_frontend *fe, u32 RF_Freq)
        tg_lo = (((Fmax/10 - Fvco)/100)*32) / ((Fmax-Fmin)/1000)+8;
 
        /* below equation is same as above but much harder to debug.
+        *
+        * static u32 MXL_GetXtalInt(u32 Xtal_Freq)
+        * {
+        *      if ((Xtal_Freq % 1000000) == 0)
+        *              return (Xtal_Freq / 10000);
+        *      else
+        *              return (((Xtal_Freq / 1000000) + 1)*100);
+        * }
+        *
+        * u32 Xtal_Int = MXL_GetXtalInt(state->Fxtal);
         * tg_lo = ( ((Fmax/10000 * Xtal_Int)/100) -
         * ((state->TG_LO/10000)*divider_val *
         * (state->Fxtal/10000)/100) )*32/((Fmax-Fmin)/10000 *
index 1f1db20d46b1dfd5224f4eb6122217f87b772373..e29cc2bc113a91604f03b009a7f2877dd4a7d0e2 100644 (file)
  *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include "tda18212_priv.h"
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include "tda18212.h"
+
+struct tda18212_priv {
+       struct tda18212_config *cfg;
+       struct i2c_adapter *i2c;
+};
+
+#define dbg(fmt, arg...)                                       \
+do {                                                           \
+       if (debug)                                              \
+               pr_info("%s: " fmt, __func__, ##arg);           \
+} while (0)
 
 static int debug;
 module_param(debug, int, 0644);
@@ -46,7 +59,8 @@ static int tda18212_wr_regs(struct tda18212_priv *priv, u8 reg, u8 *val,
        if (ret == 1) {
                ret = 0;
        } else {
-               warn("i2c wr failed ret:%d reg:%02x len:%d", ret, reg, len);
+               pr_warn("i2c wr failed ret:%d reg:%02x len:%d\n",
+                       ret, reg, len);
                ret = -EREMOTEIO;
        }
        return ret;
@@ -77,7 +91,8 @@ static int tda18212_rd_regs(struct tda18212_priv *priv, u8 reg, u8 *val,
                memcpy(val, buf, len);
                ret = 0;
        } else {
-               warn("i2c rd failed ret:%d reg:%02x len:%d", ret, reg, len);
+               pr_warn("i2c rd failed ret:%d reg:%02x len:%d\n",
+                       ret, reg, len);
                ret = -EREMOTEIO;
        }
 
@@ -129,8 +144,8 @@ static int tda18212_set_params(struct dvb_frontend *fe,
                { 0x92, 0x53, 0x03 }, /* DVB-C */
        };
 
-       dbg("%s: delsys=%d RF=%d BW=%d", __func__,
-               c->delivery_system, c->frequency, c->bandwidth_hz);
+       dbg("delsys=%d RF=%d BW=%d\n",
+           c->delivery_system, c->frequency, c->bandwidth_hz);
 
        if (fe->ops.i2c_gate_ctrl)
                fe->ops.i2c_gate_ctrl(fe, 1); /* open I2C-gate */
@@ -196,7 +211,7 @@ exit:
        return ret;
 
 error:
-       dbg("%s: failed:%d", __func__, ret);
+       dbg("failed:%d\n", ret);
        goto exit;
 }
 
@@ -245,13 +260,13 @@ struct dvb_frontend *tda18212_attach(struct dvb_frontend *fe,
        if (fe->ops.i2c_gate_ctrl)
                fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */
 
-       dbg("%s: ret:%d chip ID:%02x", __func__, ret, val);
+       dbg("ret:%d chip ID:%02x\n", ret, val);
        if (ret || val != 0xc7) {
                kfree(priv);
                return NULL;
        }
 
-       info("NXP TDA18212HN successfully identified.");
+       pr_info("NXP TDA18212HN successfully identified\n");
 
        memcpy(&fe->ops.tuner_ops, &tda18212_tuner_ops,
                sizeof(struct dvb_tuner_ops));
index aae40e52af5b1f3edf36c11154b6d04e41fd8273..39c645787b628fb47f4d9512fa9bf2d1df72cab7 100644 (file)
@@ -676,10 +676,28 @@ fail:
        return ret;
 }
 
-/*
- * Overrides for Emacs so that we follow Linus's tabbing style.
- * ---------------------------------------------------------------------------
- * Local variables:
- * c-basic-offset: 8
- * End:
- */
+int _tda_printk(struct tda18271_priv *state, const char *level,
+               const char *func, const char *fmt, ...)
+{
+       struct va_format vaf;
+       va_list args;
+       int rtn;
+
+       va_start(args, fmt);
+
+       vaf.fmt = fmt;
+       vaf.va = &args;
+
+       if (state)
+               rtn = printk("%s%s: [%d-%04x|%c] %pV",
+                            level, func, i2c_adapter_id(state->i2c_props.adap),
+                            state->i2c_props.addr,
+                            (state->role == TDA18271_MASTER) ? 'M' : 'S',
+                            &vaf);
+       else
+               rtn = printk("%s%s: %pV", level, func, &vaf);
+
+       va_end(args);
+
+       return rtn;
+}
index 57022e88e338adcc6e998c834b91f6bc63c4ef70..63cc4004e211e9654044b612400460bb93832bf9 100644 (file)
@@ -1230,7 +1230,7 @@ static int tda18271_set_config(struct dvb_frontend *fe, void *priv_cfg)
        return 0;
 }
 
-static struct dvb_tuner_ops tda18271_tuner_ops = {
+static const struct dvb_tuner_ops tda18271_tuner_ops = {
        .info = {
                .name = "NXP TDA18271HD",
                .frequency_min  =  45000000,
index 9589ab0576d2b90eb5b118cad9daa715ecaaf353..94340f47562bbe36c01a5035a0633ff1c2149c72 100644 (file)
@@ -136,29 +136,26 @@ extern int tda18271_debug;
 #define DBG_ADV  8
 #define DBG_CAL  16
 
-#define tda_printk(st, kern, fmt, arg...) do {\
-       if (st) { \
-               struct tda18271_priv *state = st; \
-               printk(kern "%s: [%d-%04x|%s] " fmt, __func__, \
-                       i2c_adapter_id(state->i2c_props.adap), \
-                       state->i2c_props.addr, \
-                       (state->role == TDA18271_MASTER) \
-                       ? "M" : "S", ##arg); \
-       } else \
-               printk(kern "%s: " fmt, __func__, ##arg); \
+__attribute__((format(printf, 4, 5)))
+int _tda_printk(struct tda18271_priv *state, const char *level,
+               const char *func, const char *fmt, ...);
+
+#define tda_printk(st, lvl, fmt, arg...)                       \
+       _tda_printk(st, lvl, __func__, fmt, ##arg)
+
+#define tda_dprintk(st, lvl, fmt, arg...)                      \
+do {                                                           \
+       if (tda18271_debug & lvl)                               \
+               tda_printk(st, KERN_DEBUG, fmt, ##arg);         \
 } while (0)
 
-#define tda_dprintk(st, lvl, fmt, arg...) do {\
-       if (tda18271_debug & lvl) \
-               tda_printk(st, KERN_DEBUG, fmt, ##arg); } while (0)
-
-#define tda_info(fmt, arg...)     printk(KERN_INFO     fmt, ##arg)
-#define tda_warn(fmt, arg...) tda_printk(priv, KERN_WARNING, fmt, ##arg)
-#define tda_err(fmt, arg...)  tda_printk(priv, KERN_ERR,     fmt, ##arg)
-#define tda_dbg(fmt, arg...)  tda_dprintk(priv, DBG_INFO,    fmt, ##arg)
-#define tda_map(fmt, arg...)  tda_dprintk(priv, DBG_MAP,     fmt, ##arg)
-#define tda_reg(fmt, arg...)  tda_dprintk(priv, DBG_REG,     fmt, ##arg)
-#define tda_cal(fmt, arg...)  tda_dprintk(priv, DBG_CAL,     fmt, ##arg)
+#define tda_info(fmt, arg...)  pr_info(fmt, ##arg)
+#define tda_warn(fmt, arg...)  tda_printk(priv, KERN_WARNING, fmt, ##arg)
+#define tda_err(fmt, arg...)   tda_printk(priv, KERN_ERR,     fmt, ##arg)
+#define tda_dbg(fmt, arg...)   tda_dprintk(priv, DBG_INFO,    fmt, ##arg)
+#define tda_map(fmt, arg...)   tda_dprintk(priv, DBG_MAP,     fmt, ##arg)
+#define tda_reg(fmt, arg...)   tda_dprintk(priv, DBG_REG,     fmt, ##arg)
+#define tda_cal(fmt, arg...)   tda_dprintk(priv, DBG_CAL,     fmt, ##arg)
 
 #define tda_fail(ret)                                                       \
 ({                                                                          \
index b21b6ea68b2501164fa503ac77f6ffb02f9b3aba..e0d5b43772b81e997ab6cd15199ae137c7bcb599 100644 (file)
@@ -176,7 +176,7 @@ static int tda827xo_set_params(struct dvb_frontend *fe,
                if_freq = 5000000;
                break;
        }
-       tuner_freq = params->frequency + if_freq;
+       tuner_freq = params->frequency;
 
        i = 0;
        while (tda827x_table[i].lomax < tuner_freq) {
@@ -185,6 +185,8 @@ static int tda827xo_set_params(struct dvb_frontend *fe,
                i++;
        }
 
+       tuner_freq += if_freq;
+
        N = ((tuner_freq + 125000) / 250000) << (tda827x_table[i].spd + 2);
        buf[0] = 0;
        buf[1] = (N>>8) | 0x40;
@@ -540,7 +542,7 @@ static int tda827xa_set_params(struct dvb_frontend *fe,
                if_freq = 5000000;
                break;
        }
-       tuner_freq = params->frequency + if_freq;
+       tuner_freq = params->frequency;
 
        if (fe->ops.info.type == FE_QAM) {
                dprintk("%s select tda827xa_dvbc\n", __func__);
@@ -554,6 +556,8 @@ static int tda827xa_set_params(struct dvb_frontend *fe,
                i++;
        }
 
+       tuner_freq += if_freq;
+
        N = ((tuner_freq + 31250) / 62500) << frequency_map[i].spd;
        buf[0] = 0;            // subaddress
        buf[1] = N >> 8;
index 16fba6b59616034382bbf09018795fb29cc4eba1..3acbaa04e1b3b3c6a4711211b5bf9acfe1e1dbe8 100644 (file)
@@ -614,6 +614,13 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type,
                        p += len;
                        size -= len;
                }
+
+               /* silently fail if the frontend doesn't support I2C flush */
+               rc = do_tuner_callback(fe, XC2028_I2C_FLUSH, 0);
+               if ((rc < 0) && (rc != -EINVAL)) {
+                       tuner_err("error executing flush: %d\n", rc);
+                       return rc;
+               }
        }
        return 0;
 }
@@ -933,11 +940,16 @@ static int generic_set_freq(struct dvb_frontend *fe, u32 freq /* in HZ */,
         * that xc2028 will be in a safe state.
         * Maybe this might also be needed for DTV.
         */
-       if (new_type == V4L2_TUNER_ANALOG_TV) {
+       switch (new_type) {
+       case V4L2_TUNER_ANALOG_TV:
                rc = send_seq(priv, {0x00, 0x00});
 
-               /* Analog modes require offset = 0 */
-       } else {
+               /* Analog mode requires offset = 0 */
+               break;
+       case V4L2_TUNER_RADIO:
+               /* Radio mode requires offset = 0 */
+               break;
+       case V4L2_TUNER_DIGITAL_TV:
                /*
                 * Digital modes require an offset to adjust to the
                 * proper frequency. The offset depends on what
index 9778c96a5006b03f88b5659c2b043c3024f9698f..9ebfb2d0ff149b70451dfc5a0ec3133c51fdee0e 100644 (file)
@@ -54,6 +54,7 @@ struct xc2028_config {
 /* xc2028 commands for callback */
 #define XC2028_TUNER_RESET     0
 #define XC2028_RESET_CLK       1
+#define XC2028_I2C_FLUSH       2
 
 #if defined(CONFIG_MEDIA_TUNER_XC2028) || (defined(CONFIG_MEDIA_TUNER_XC2028_MODULE) && defined(MODULE))
 extern struct dvb_frontend *xc2028_attach(struct dvb_frontend *fe,
index b97cf7208a182a409ac14cdff121a56d91a55f97..3d04a8dba99e962d30572de670a7f1816fdbb363 100644 (file)
@@ -12,5 +12,5 @@ obj-$(CONFIG_DVB_B2C2_FLEXCOP_PCI) += b2c2-flexcop-pci.o
 b2c2-flexcop-usb-objs = flexcop-usb.o
 obj-$(CONFIG_DVB_B2C2_FLEXCOP_USB) += b2c2-flexcop-usb.o
 
-EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
-EXTRA_CFLAGS += -Idrivers/media/common/tuners/
+ccflags-y += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
+ccflags-y += -Idrivers/media/common/tuners/
index d98f1d49ffa89bab91f5c936189b7adc445f1c80..0713b3af205071361fbd42218f090c85133faff8 100644 (file)
@@ -1,6 +1,6 @@
 obj-$(CONFIG_DVB_BT8XX) += bt878.o dvb-bt8xx.o dst.o dst_ca.o
 
-EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
-EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
-EXTRA_CFLAGS += -Idrivers/media/video/bt8xx
-EXTRA_CFLAGS += -Idrivers/media/common/tuners
+ccflags-y += -Idrivers/media/dvb/dvb-core
+ccflags-y += -Idrivers/media/dvb/frontends
+ccflags-y += -Idrivers/media/video/bt8xx
+ccflags-y += -Idrivers/media/common/tuners
index de4fe193c3efc76524f4ea07a13fe7e07b35f5b6..cf7214edf65ffc7fe6a7214d2238224919ee397b 100644 (file)
@@ -6,9 +6,9 @@ ddbridge-objs := ddbridge-core.o
 
 obj-$(CONFIG_DVB_DDBRIDGE) += ddbridge.o
 
-EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/
-EXTRA_CFLAGS += -Idrivers/media/dvb/frontends/
-EXTRA_CFLAGS += -Idrivers/media/common/tuners/
+ccflags-y += -Idrivers/media/dvb/dvb-core/
+ccflags-y += -Idrivers/media/dvb/frontends/
+ccflags-y += -Idrivers/media/common/tuners/
 
 # For the staging CI driver cxd2099
-EXTRA_CFLAGS += -Idrivers/staging/cxd2099/
+ccflags-y += -Idrivers/staging/cxd2099/
index 573d540f213e3365566c72753dd4709ee4b765fc..ba9a643b9c6a6f7241cdebf9557b8fb188992b91 100644 (file)
@@ -507,15 +507,14 @@ static u32 ddb_input_avail(struct ddb_input *input)
        return 0;
 }
 
-static size_t ddb_input_read(struct ddb_input *input, u8 *buf, size_t count)
+static ssize_t ddb_input_read(struct ddb_input *input, u8 *buf, size_t count)
 {
        struct ddb *dev = input->port->dev;
        u32 left = count;
-       u32 idx, off, free, stat = input->stat;
+       u32 idx, free, stat = input->stat;
        int ret;
 
        idx = (stat >> 11) & 0x1f;
-       off = (stat & 0x7ff) << 7;
 
        while (left) {
                if (input->cbuf == idx)
@@ -525,6 +524,8 @@ static size_t ddb_input_read(struct ddb_input *input, u8 *buf, size_t count)
                        free = left;
                ret = copy_to_user(buf, input->vbuf[input->cbuf] +
                                   input->coff, free);
+               if (ret)
+                       return -EFAULT;
                input->coff += free;
                if (input->coff == input->dma_buf_size) {
                        input->coff = 0;
@@ -939,6 +940,8 @@ static ssize_t ts_read(struct file *file, char *buf,
                                break;
                }
                read = ddb_input_read(input, buf, left);
+               if (read < 0)
+                       return read;
                left -= read;
                buf += read;
        }
@@ -1438,7 +1441,7 @@ static long ddb_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
        struct ddb *dev = file->private_data;
        void *parg = (void *)arg;
-       int res = -EFAULT;
+       int res;
 
        switch (cmd) {
        case IOCTL_DDB_FLASHIO:
@@ -1447,29 +1450,29 @@ static long ddb_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                u8 *rbuf, *wbuf;
 
                if (copy_from_user(&fio, parg, sizeof(fio)))
-                       break;
-               if (fio.write_len + fio.read_len > 1028) {
-                       printk(KERN_ERR "IOBUF too small\n");
-                       return -ENOMEM;
-               }
+                       return -EFAULT;
+
+               if (fio.write_len > 1028 || fio.read_len > 1028)
+                       return -EINVAL;
+               if (fio.write_len + fio.read_len > 1028)
+                       return -EINVAL;
+
                wbuf = &dev->iobuf[0];
-               if (!wbuf)
-                       return -ENOMEM;
                rbuf = wbuf + fio.write_len;
-               if (copy_from_user(wbuf, fio.write_buf, fio.write_len)) {
-                       vfree(wbuf);
-                       break;
-               }
-               res = flashio(dev, wbuf, fio.write_len,
-                             rbuf, fio.read_len);
+
+               if (copy_from_user(wbuf, fio.write_buf, fio.write_len))
+                       return -EFAULT;
+               res = flashio(dev, wbuf, fio.write_len, rbuf, fio.read_len);
+               if (res)
+                       return res;
                if (copy_to_user(fio.read_buf, rbuf, fio.read_len))
-                       res = -EFAULT;
+                       return -EFAULT;
                break;
        }
        default:
-               break;
+               return -ENOTTY;
        }
-       return res;
+       return 0;
 }
 
 static const struct file_operations ddb_fops = {
index 8ac28b0546af8d8ddc9a081d6f322da66b39e52c..95a008b71fe539aae8db1d4276bc9f137460c2c5 100644 (file)
@@ -1,3 +1,3 @@
 obj-$(CONFIG_DVB_DM1105) += dm1105.o
 
-EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends
+ccflags-y += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends
index efe9c30605e890688b6a7557156436fe0c4611a9..2c0acdb4d81144b00b1381742505d18f208addb2 100644 (file)
@@ -149,30 +149,25 @@ static void dvb_frontend_add_event(struct dvb_frontend *fe, fe_status_t status)
 
        dprintk ("%s\n", __func__);
 
-       if (mutex_lock_interruptible (&events->mtx))
-               return;
+       if ((status & FE_HAS_LOCK) && fe->ops.get_frontend)
+               fe->ops.get_frontend(fe, &fepriv->parameters_out);
 
-       wp = (events->eventw + 1) % MAX_EVENT;
+       mutex_lock(&events->mtx);
 
+       wp = (events->eventw + 1) % MAX_EVENT;
        if (wp == events->eventr) {
                events->overflow = 1;
                events->eventr = (events->eventr + 1) % MAX_EVENT;
        }
 
        e = &events->events[events->eventw];
-
-       if (status & FE_HAS_LOCK)
-               if (fe->ops.get_frontend)
-                       fe->ops.get_frontend(fe, &fepriv->parameters_out);
-
+       e->status = status;
        e->parameters = fepriv->parameters_out;
 
        events->eventw = wp;
 
        mutex_unlock(&events->mtx);
 
-       e->status = status;
-
        wake_up_interruptible (&events->wait_queue);
 }
 
@@ -207,19 +202,24 @@ static int dvb_frontend_get_event(struct dvb_frontend *fe,
                        return ret;
        }
 
-       if (mutex_lock_interruptible (&events->mtx))
-               return -ERESTARTSYS;
-
-       memcpy (event, &events->events[events->eventr],
-               sizeof(struct dvb_frontend_event));
-
+       mutex_lock(&events->mtx);
+       *event = events->events[events->eventr];
        events->eventr = (events->eventr + 1) % MAX_EVENT;
-
        mutex_unlock(&events->mtx);
 
        return 0;
 }
 
+static void dvb_frontend_clear_events(struct dvb_frontend *fe)
+{
+       struct dvb_frontend_private *fepriv = fe->frontend_priv;
+       struct dvb_fe_events *events = &fepriv->events;
+
+       mutex_lock(&events->mtx);
+       events->eventr = events->eventw;
+       mutex_unlock(&events->mtx);
+}
+
 static void dvb_frontend_init(struct dvb_frontend *fe)
 {
        dprintk ("DVB: initialising adapter %i frontend %i (%s)...\n",
@@ -537,7 +537,6 @@ static int dvb_frontend_thread(void *data)
 {
        struct dvb_frontend *fe = data;
        struct dvb_frontend_private *fepriv = fe->frontend_priv;
-       unsigned long timeout;
        fe_status_t s;
        enum dvbfe_algo algo;
 
@@ -558,7 +557,7 @@ static int dvb_frontend_thread(void *data)
        while (1) {
                up(&fepriv->sem);           /* is locked when we enter the thread... */
 restart:
-               timeout = wait_event_interruptible_timeout(fepriv->wait_queue,
+               wait_event_interruptible_timeout(fepriv->wait_queue,
                        dvb_frontend_should_wakeup(fe) || kthread_should_stop()
                                || freezing(current),
                        fepriv->delay);
@@ -577,12 +576,10 @@ restart:
 
                if (fepriv->reinitialise) {
                        dvb_frontend_init(fe);
-                       if (fepriv->tone != -1) {
+                       if (fe->ops.set_tone && fepriv->tone != -1)
                                fe->ops.set_tone(fe, fepriv->tone);
-                       }
-                       if (fepriv->voltage != -1) {
+                       if (fe->ops.set_voltage && fepriv->voltage != -1)
                                fe->ops.set_voltage(fe, fepriv->voltage);
-                       }
                        fepriv->reinitialise = 0;
                }
 
@@ -1019,6 +1016,29 @@ static int is_legacy_delivery_system(fe_delivery_system_t s)
        return 0;
 }
 
+/* Initialize the cache with some default values derived from the
+ * legacy frontend_info structure.
+ */
+static void dtv_property_cache_init(struct dvb_frontend *fe,
+                                   struct dtv_frontend_properties *c)
+{
+       switch (fe->ops.info.type) {
+       case FE_QPSK:
+               c->modulation = QPSK;   /* implied for DVB-S in legacy API */
+               c->rolloff = ROLLOFF_35;/* implied for DVB-S */
+               c->delivery_system = SYS_DVBS;
+               break;
+       case FE_QAM:
+               c->delivery_system = SYS_DVBC_ANNEX_AC;
+               break;
+       case FE_OFDM:
+               c->delivery_system = SYS_DVBT;
+               break;
+       case FE_ATSC:
+               break;
+       }
+}
+
 /* Synchronise the legacy tuning parameters into the cache, so that demodulator
  * drivers can use a single set_frontend tuning function, regardless of whether
  * it's being used for the legacy or new API, reducing code and complexity.
@@ -1032,17 +1052,13 @@ static void dtv_property_cache_sync(struct dvb_frontend *fe,
 
        switch (fe->ops.info.type) {
        case FE_QPSK:
-               c->modulation = QPSK;   /* implied for DVB-S in legacy API */
-               c->rolloff = ROLLOFF_35;/* implied for DVB-S */
                c->symbol_rate = p->u.qpsk.symbol_rate;
                c->fec_inner = p->u.qpsk.fec_inner;
-               c->delivery_system = SYS_DVBS;
                break;
        case FE_QAM:
                c->symbol_rate = p->u.qam.symbol_rate;
                c->fec_inner = p->u.qam.fec_inner;
                c->modulation = p->u.qam.modulation;
-               c->delivery_system = SYS_DVBC_ANNEX_AC;
                break;
        case FE_OFDM:
                if (p->u.ofdm.bandwidth == BANDWIDTH_6_MHZ)
@@ -1060,7 +1076,6 @@ static void dtv_property_cache_sync(struct dvb_frontend *fe,
                c->transmission_mode = p->u.ofdm.transmission_mode;
                c->guard_interval = p->u.ofdm.guard_interval;
                c->hierarchy = p->u.ofdm.hierarchy_information;
-               c->delivery_system = SYS_DVBT;
                break;
        case FE_ATSC:
                c->modulation = p->u.vsb.modulation;
@@ -1132,16 +1147,13 @@ static void dtv_property_adv_params_sync(struct dvb_frontend *fe)
        p->frequency = c->frequency;
        p->inversion = c->inversion;
 
-       switch(c->modulation) {
-       case PSK_8:
-       case APSK_16:
-       case APSK_32:
-       case QPSK:
+       if (c->delivery_system == SYS_DSS ||
+           c->delivery_system == SYS_DVBS ||
+           c->delivery_system == SYS_DVBS2 ||
+           c->delivery_system == SYS_ISDBS ||
+           c->delivery_system == SYS_TURBO) {
                p->u.qpsk.symbol_rate = c->symbol_rate;
                p->u.qpsk.fec_inner = c->fec_inner;
-               break;
-       default:
-               break;
        }
 
        /* Fake out a generic DVB-T request so we pass validation in the ioctl */
@@ -1824,9 +1836,17 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
 
                        memcpy (&fepriv->parameters_in, parg,
                                sizeof (struct dvb_frontend_parameters));
+                       dtv_property_cache_init(fe, c);
                        dtv_property_cache_sync(fe, c, &fepriv->parameters_in);
                }
 
+               /*
+                * Initialize output parameters to match the values given by
+                * the user. FE_SET_FRONTEND triggers an initial frontend event
+                * with status = 0, which copies output parameters to userspace.
+                */
+               fepriv->parameters_out = fepriv->parameters_in;
+
                memset(&fetunesettings, 0, sizeof(struct dvb_frontend_tune_settings));
                memcpy(&fetunesettings.parameters, parg,
                       sizeof (struct dvb_frontend_parameters));
@@ -1884,8 +1904,9 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
                /* Request the search algorithm to search */
                fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN;
 
-               dvb_frontend_wakeup(fe);
+               dvb_frontend_clear_events(fe);
                dvb_frontend_add_event(fe, 0);
+               dvb_frontend_wakeup(fe);
                fepriv->status = 0;
                err = 0;
                break;
index 5590eb6eb4082a8967e6821c3fff64d1332655c6..67bbfa728016f72ef600bd683d84ef422930362e 100644 (file)
@@ -209,6 +209,7 @@ struct dvb_tuner_ops {
 
        int (*get_frequency)(struct dvb_frontend *fe, u32 *frequency);
        int (*get_bandwidth)(struct dvb_frontend *fe, u32 *bandwidth);
+       int (*get_if_frequency)(struct dvb_frontend *fe, u32 *frequency);
 
 #define TUNER_STATUS_LOCKED 1
 #define TUNER_STATUS_STEREO 2
index 5d73dec8ac0724a557a8ba8a223e8edc0c9e2651..58257165761e1b016a58b30019a9388d395400b2 100644 (file)
@@ -258,6 +258,19 @@ config DVB_USB_AF9005_REMOTE
          Say Y here to support the default remote control decoding for the
          Afatech AF9005 based receiver.
 
+config DVB_USB_PCTV452E
+       tristate "Pinnacle PCTV HDTV Pro USB device/TT Connect S2-3600"
+       depends on DVB_USB
+       select TTPCI_EEPROM
+       select DVB_LNBP22 if !DVB_FE_CUSTOMISE
+       select DVB_STB0899 if !DVB_FE_CUSTOMISE
+       select DVB_STB6100 if !DVB_FE_CUSTOMISE
+       help
+         Support for external USB adapter designed by Pinnacle,
+         shipped under the brand name 'PCTV HDTV Pro USB'.
+         Also supports TT Connect S2-3600/3650 cards.
+         Say Y if you own such a device and want to use it.
+
 config DVB_USB_DW2102
        tristate "DvbWorld & TeVii DVB-S/S2 USB2.0 support"
        depends on DVB_USB
@@ -374,3 +387,18 @@ config DVB_USB_TECHNISAT_USB2
        select DVB_STV6110x if !DVB_FE_CUSTOMISE
        help
          Say Y here to support the Technisat USB2 DVB-S/S2 device
+
+config DVB_USB_IT913X
+       tristate "it913x driver"
+       depends on DVB_USB
+       select DVB_IT913X_FE
+       help
+         Say Y here to support the it913x device
+
+config DVB_USB_MXL111SF
+       tristate "MxL111SF DTV USB2.0 support"
+       depends on DVB_USB
+       select DVB_LGDT3305 if !DVB_FE_CUSTOMISE
+       select VIDEO_TVEEPROM
+       help
+         Say Y here to support the MxL111SF USB2.0 DTV receiver.
index 4bac13da0c39eb55ecff23fe52b41b39be1d324c..7d0710bb19781529c4da939a603fc541522b880d 100644 (file)
@@ -64,6 +64,9 @@ obj-$(CONFIG_DVB_USB_AF9005_REMOTE) += dvb-usb-af9005-remote.o
 dvb-usb-anysee-objs = anysee.o
 obj-$(CONFIG_DVB_USB_ANYSEE) += dvb-usb-anysee.o
 
+dvb-usb-pctv452e-objs = pctv452e.o
+obj-$(CONFIG_DVB_USB_PCTV452E) += dvb-usb-pctv452e.o
+
 dvb-usb-dw2102-objs = dw2102.o
 obj-$(CONFIG_DVB_USB_DW2102) += dvb-usb-dw2102.o
 
@@ -94,7 +97,15 @@ obj-$(CONFIG_DVB_USB_LME2510) += dvb-usb-lmedm04.o
 dvb-usb-technisat-usb2-objs = technisat-usb2.o
 obj-$(CONFIG_DVB_USB_TECHNISAT_USB2) += dvb-usb-technisat-usb2.o
 
-EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
+dvb-usb-it913x-objs := it913x.o
+obj-$(CONFIG_DVB_USB_IT913X) += dvb-usb-it913x.o
+
+dvb-usb-mxl111sf-objs = mxl111sf.o mxl111sf-phy.o mxl111sf-i2c.o mxl111sf-gpio.o
+obj-$(CONFIG_DVB_USB_MXL111SF) += dvb-usb-mxl111sf.o
+obj-$(CONFIG_DVB_USB_MXL111SF) += mxl111sf-tuner.o
+
+ccflags-y += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
 # due to tuner-xc3028
-EXTRA_CFLAGS += -Idrivers/media/common/tuners
+ccflags-y += -Idrivers/media/common/tuners
+EXTRA_CFLAGS += -Idrivers/media/dvb/ttpci
 
index b95a95e1784056b0a8ed13f3e7db3c711ab1cc0c..2aef3c89e9fa1e0710363fe7c24b181bd8a69bc4 100644 (file)
@@ -127,6 +127,8 @@ static struct dvb_usb_device_properties a800_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
                        .pid_filter_count = 32,
                        .streaming_ctrl   = dibusb2_0_streaming_ctrl,
@@ -147,7 +149,7 @@ static struct dvb_usb_device_properties a800_properties = {
                                        }
                                }
                        },
-
+               }},
                        .size_of_priv     = sizeof(struct dibusb_state),
                },
        },
index 6ad94745bbdd1f90bcd895e84f4a784870237cad..3263e9749d09dfd610e467da5a583f84c26dc2d1 100644 (file)
@@ -63,11 +63,9 @@ static int af9005_write_word_agc(struct dvb_usb_device *d, u16 reghi,
                                 u16 reglo, u8 pos, u8 len, u16 value)
 {
        int ret;
-       u8 temp;
 
        if ((ret = af9005_write_ofdm_register(d, reglo, (u8) (value & 0xff))))
                return ret;
-       temp = (u8) ((value & 0x0300) >> 8);
        return af9005_write_register_bits(d, reghi, pos, len,
                                          (u8) ((value & 0x300) >> 8));
 }
index 0351c0e52dd2170d763b8bf7e3f2628602972dc3..bd51a764351b8483878e04f070206c878c5fc575 100644 (file)
@@ -815,7 +815,7 @@ static int af9005_frontend_attach(struct dvb_usb_adapter *adap)
                        debug_dump(buf, 8, printk);
                }
        }
-       adap->fe = af9005_fe_attach(adap->dev);
+       adap->fe_adap[0].fe = af9005_fe_attach(adap->dev);
        return 0;
 }
 
@@ -999,6 +999,8 @@ static struct dvb_usb_device_properties af9005_properties = {
        .num_adapters = 1,
        .adapter = {
                    {
+                   .num_frontends = 1,
+                   .fe = {{
                     .caps =
                     DVB_USB_ADAP_HAS_PID_FILTER |
                     DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
@@ -1018,6 +1020,7 @@ static struct dvb_usb_device_properties af9005_properties = {
                                               }
                                      }
                                },
+                    }},
                     }
                    },
        .power_ctrl = af9005_power_ctrl,
index d7ad05fc383b7a8422fb8d1b8425bb87862790ed..c6c275bac08e7e3c82cd9318b75ab789c0447ba6 100644 (file)
@@ -744,29 +744,31 @@ static const struct af9015_rc_setup af9015_rc_setup_hashes[] = {
 };
 
 static const struct af9015_rc_setup af9015_rc_setup_usbids[] = {
-       { (USB_VID_TERRATEC << 16) + USB_PID_TERRATEC_CINERGY_T_STICK_RC,
+       { (USB_VID_TERRATEC << 16) | USB_PID_TERRATEC_CINERGY_T_STICK_RC,
                RC_MAP_TERRATEC_SLIM_2 },
-       { (USB_VID_TERRATEC << 16) + USB_PID_TERRATEC_CINERGY_T_STICK_DUAL_RC,
+       { (USB_VID_TERRATEC << 16) | USB_PID_TERRATEC_CINERGY_T_STICK_DUAL_RC,
                RC_MAP_TERRATEC_SLIM },
-       { (USB_VID_VISIONPLUS << 16) + USB_PID_AZUREWAVE_AD_TU700,
+       { (USB_VID_VISIONPLUS << 16) | USB_PID_AZUREWAVE_AD_TU700,
                RC_MAP_AZUREWAVE_AD_TU700 },
-       { (USB_VID_VISIONPLUS << 16) + USB_PID_TINYTWIN,
+       { (USB_VID_VISIONPLUS << 16) | USB_PID_TINYTWIN,
                RC_MAP_AZUREWAVE_AD_TU700 },
-       { (USB_VID_MSI_2 << 16) + USB_PID_MSI_DIGI_VOX_MINI_III,
+       { (USB_VID_MSI_2 << 16) | USB_PID_MSI_DIGI_VOX_MINI_III,
                RC_MAP_MSI_DIGIVOX_III },
-       { (USB_VID_MSI_2 << 16) + USB_PID_MSI_DIGIVOX_DUO,
+       { (USB_VID_MSI_2 << 16) | USB_PID_MSI_DIGIVOX_DUO,
                RC_MAP_MSI_DIGIVOX_III },
-       { (USB_VID_LEADTEK << 16) + USB_PID_WINFAST_DTV_DONGLE_GOLD,
+       { (USB_VID_LEADTEK << 16) | USB_PID_WINFAST_DTV_DONGLE_GOLD,
                RC_MAP_LEADTEK_Y04G0051 },
-       { (USB_VID_AVERMEDIA << 16) + USB_PID_AVERMEDIA_VOLAR_X,
+       { (USB_VID_LEADTEK << 16) | USB_PID_WINFAST_DTV2000DS,
+               RC_MAP_LEADTEK_Y04G0051 },
+       { (USB_VID_AVERMEDIA << 16) | USB_PID_AVERMEDIA_VOLAR_X,
                RC_MAP_AVERMEDIA_M135A },
-       { (USB_VID_AFATECH << 16) + USB_PID_TREKSTOR_DVBT,
+       { (USB_VID_AFATECH << 16) | USB_PID_TREKSTOR_DVBT,
                RC_MAP_TREKSTOR },
-       { (USB_VID_KWORLD_2 << 16) + USB_PID_TINYTWIN_2,
+       { (USB_VID_KWORLD_2 << 16) | USB_PID_TINYTWIN_2,
                RC_MAP_DIGITALNOW_TINYTWIN },
-       { (USB_VID_GTEK << 16) + USB_PID_TINYTWIN_3,
+       { (USB_VID_GTEK << 16) | USB_PID_TINYTWIN_3,
                RC_MAP_DIGITALNOW_TINYTWIN },
-       { (USB_VID_KWORLD_2 << 16) + USB_PID_SVEON_STV22,
+       { (USB_VID_KWORLD_2 << 16) | USB_PID_SVEON_STV22,
                RC_MAP_MSI_DIGIVOX_III },
        { }
 };
@@ -859,13 +861,13 @@ static int af9015_read_config(struct usb_device *udev)
        for (i = 0; i < af9015_properties_count; i++) {
                /* USB1.1 set smaller buffersize and disable 2nd adapter */
                if (udev->speed == USB_SPEED_FULL) {
-                       af9015_properties[i].adapter[0].stream.u.bulk.buffersize
+                       af9015_properties[i].adapter[0].fe[0].stream.u.bulk.buffersize
                                = TS_USB11_FRAME_SIZE;
                        /* disable 2nd adapter because we don't have
                           PID-filters */
                        af9015_config.dual_mode = 0;
                } else {
-                       af9015_properties[i].adapter[0].stream.u.bulk.buffersize
+                       af9015_properties[i].adapter[0].fe[0].stream.u.bulk.buffersize
                                = TS_USB20_FRAME_SIZE;
                }
        }
@@ -1111,10 +1113,10 @@ static int af9015_af9013_frontend_attach(struct dvb_usb_adapter *adap)
        }
 
        /* attach demodulator */
-       adap->fe = dvb_attach(af9013_attach, &af9015_af9013_config[adap->id],
+       adap->fe_adap[0].fe = dvb_attach(af9013_attach, &af9015_af9013_config[adap->id],
                &adap->dev->i2c_adap);
 
-       return adap->fe == NULL ? -ENODEV : 0;
+       return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
 }
 
 static struct mt2060_config af9015_mt2060_config = {
@@ -1188,49 +1190,49 @@ static int af9015_tuner_attach(struct dvb_usb_adapter *adap)
        switch (af9015_af9013_config[adap->id].tuner) {
        case AF9013_TUNER_MT2060:
        case AF9013_TUNER_MT2060_2:
-               ret = dvb_attach(mt2060_attach, adap->fe, &adap->dev->i2c_adap,
+               ret = dvb_attach(mt2060_attach, adap->fe_adap[0].fe, &adap->dev->i2c_adap,
                        &af9015_mt2060_config,
                        af9015_config.mt2060_if1[adap->id])
                        == NULL ? -ENODEV : 0;
                break;
        case AF9013_TUNER_QT1010:
        case AF9013_TUNER_QT1010A:
-               ret = dvb_attach(qt1010_attach, adap->fe, &adap->dev->i2c_adap,
+               ret = dvb_attach(qt1010_attach, adap->fe_adap[0].fe, &adap->dev->i2c_adap,
                        &af9015_qt1010_config) == NULL ? -ENODEV : 0;
                break;
        case AF9013_TUNER_TDA18271:
-               ret = dvb_attach(tda18271_attach, adap->fe, 0xc0,
+               ret = dvb_attach(tda18271_attach, adap->fe_adap[0].fe, 0xc0,
                        &adap->dev->i2c_adap,
                        &af9015_tda18271_config) == NULL ? -ENODEV : 0;
                break;
        case AF9013_TUNER_TDA18218:
-               ret = dvb_attach(tda18218_attach, adap->fe,
+               ret = dvb_attach(tda18218_attach, adap->fe_adap[0].fe,
                        &adap->dev->i2c_adap,
                        &af9015_tda18218_config) == NULL ? -ENODEV : 0;
                break;
        case AF9013_TUNER_MXL5003D:
-               ret = dvb_attach(mxl5005s_attach, adap->fe,
+               ret = dvb_attach(mxl5005s_attach, adap->fe_adap[0].fe,
                        &adap->dev->i2c_adap,
                        &af9015_mxl5003_config) == NULL ? -ENODEV : 0;
                break;
        case AF9013_TUNER_MXL5005D:
        case AF9013_TUNER_MXL5005R:
-               ret = dvb_attach(mxl5005s_attach, adap->fe,
+               ret = dvb_attach(mxl5005s_attach, adap->fe_adap[0].fe,
                        &adap->dev->i2c_adap,
                        &af9015_mxl5005_config) == NULL ? -ENODEV : 0;
                break;
        case AF9013_TUNER_ENV77H11D5:
-               ret = dvb_attach(dvb_pll_attach, adap->fe, 0xc0,
+               ret = dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0xc0,
                        &adap->dev->i2c_adap,
                        DVB_PLL_TDA665X) == NULL ? -ENODEV : 0;
                break;
        case AF9013_TUNER_MC44S803:
-               ret = dvb_attach(mc44s803_attach, adap->fe,
+               ret = dvb_attach(mc44s803_attach, adap->fe_adap[0].fe,
                        &adap->dev->i2c_adap,
                        &af9015_mc44s803_config) == NULL ? -ENODEV : 0;
                break;
        case AF9013_TUNER_MXL5007T:
-               ret = dvb_attach(mxl5007t_attach, adap->fe,
+               ret = dvb_attach(mxl5007t_attach, adap->fe_adap[0].fe,
                        &adap->dev->i2c_adap,
                        0xc0, &af9015_mxl5007t_config) == NULL ? -ENODEV : 0;
                break;
@@ -1304,6 +1306,8 @@ static struct dvb_usb_device_properties af9015_properties[] = {
                .num_adapters = 2,
                .adapter = {
                        {
+                       .num_frontends = 1,
+                       .fe = {{
                                .caps = DVB_USB_ADAP_HAS_PID_FILTER |
                                DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
 
@@ -1319,8 +1323,11 @@ static struct dvb_usb_device_properties af9015_properties[] = {
                                        .count = 6,
                                        .endpoint = 0x84,
                                },
+                       }},
                        },
                        {
+                       .num_frontends = 1,
+                       .fe = {{
                                .frontend_attach =
                                        af9015_af9013_frontend_attach,
                                .tuner_attach    = af9015_tuner_attach,
@@ -1335,6 +1342,7 @@ static struct dvb_usb_device_properties af9015_properties[] = {
                                                }
                                        }
                                },
+                       }},
                        }
                },
 
@@ -1432,6 +1440,8 @@ static struct dvb_usb_device_properties af9015_properties[] = {
                .num_adapters = 2,
                .adapter = {
                        {
+                       .num_frontends = 1,
+                       .fe = {{
                                .caps = DVB_USB_ADAP_HAS_PID_FILTER |
                                DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
 
@@ -1447,8 +1457,11 @@ static struct dvb_usb_device_properties af9015_properties[] = {
                                        .count = 6,
                                        .endpoint = 0x84,
                                },
+                       }},
                        },
                        {
+                       .num_frontends = 1,
+                       .fe = {{
                                .frontend_attach =
                                        af9015_af9013_frontend_attach,
                                .tuner_attach    = af9015_tuner_attach,
@@ -1463,6 +1476,7 @@ static struct dvb_usb_device_properties af9015_properties[] = {
                                                }
                                        }
                                },
+                       }},
                        }
                },
 
@@ -1549,6 +1563,8 @@ static struct dvb_usb_device_properties af9015_properties[] = {
                .num_adapters = 2,
                .adapter = {
                        {
+                       .num_frontends = 1,
+                       .fe = {{
                                .caps = DVB_USB_ADAP_HAS_PID_FILTER |
                                DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
 
@@ -1564,8 +1580,11 @@ static struct dvb_usb_device_properties af9015_properties[] = {
                                        .count = 6,
                                        .endpoint = 0x84,
                                },
+                       }},
                        },
                        {
+                       .num_frontends = 1,
+                       .fe = {{
                                .frontend_attach =
                                        af9015_af9013_frontend_attach,
                                .tuner_attach    = af9015_tuner_attach,
@@ -1580,6 +1599,7 @@ static struct dvb_usb_device_properties af9015_properties[] = {
                                                }
                                        }
                                },
+                       }},
                        }
                },
 
index 2cbf19a52e38d5124be4b7f805e70f4ce6e8d62f..5f2278b73ee9c4375cea917d8bc45fd75e9827b7 100644 (file)
@@ -446,6 +446,114 @@ static struct isl6423_config anysee_isl6423_config = {
  * IOE[5] STV0903 1=enabled
  */
 
+static int anysee_frontend_ctrl(struct dvb_frontend *fe, int onoff)
+{
+       struct dvb_usb_adapter *adap = fe->dvb->priv;
+       struct anysee_state *state = adap->dev->priv;
+       int ret;
+
+       deb_info("%s: fe=%d onoff=%d\n", __func__, fe->id, onoff);
+
+       /* no frontend sleep control */
+       if (onoff == 0)
+               return 0;
+
+       switch (state->hw) {
+       case ANYSEE_HW_507FA: /* 15 */
+               /* E30 Combo Plus */
+               /* E30 C Plus */
+
+               if ((fe->id ^ dvb_usb_anysee_delsys) == 0)  {
+                       /* disable DVB-T demod on IOD[0] */
+                       ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 0),
+                               0x01);
+                       if (ret)
+                               goto error;
+
+                       /* enable DVB-C demod on IOD[5] */
+                       ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 5),
+                               0x20);
+                       if (ret)
+                               goto error;
+
+                       /* enable DVB-C tuner on IOE[0] */
+                       ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 0),
+                               0x01);
+                       if (ret)
+                               goto error;
+               } else {
+                       /* disable DVB-C demod on IOD[5] */
+                       ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 5),
+                               0x20);
+                       if (ret)
+                               goto error;
+
+                       /* enable DVB-T demod on IOD[0] */
+                       ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0),
+                               0x01);
+                       if (ret)
+                               goto error;
+
+                       /* enable DVB-T tuner on IOE[0] */
+                       ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 0),
+                               0x01);
+                       if (ret)
+                               goto error;
+               }
+
+               break;
+       case ANYSEE_HW_508TC: /* 18 */
+       case ANYSEE_HW_508PTC: /* 21 */
+               /* E7 TC */
+               /* E7 PTC */
+
+               if ((fe->id ^ dvb_usb_anysee_delsys) == 0)  {
+                       /* disable DVB-T demod on IOD[6] */
+                       ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 6),
+                               0x40);
+                       if (ret)
+                               goto error;
+
+                       /* enable DVB-C demod on IOD[5] */
+                       ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 5),
+                               0x20);
+                       if (ret)
+                               goto error;
+
+                       /* enable IF route on IOE[0] */
+                       ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 0),
+                               0x01);
+                       if (ret)
+                               goto error;
+               } else {
+                       /* disable DVB-C demod on IOD[5] */
+                       ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 5),
+                               0x20);
+                       if (ret)
+                               goto error;
+
+                       /* enable DVB-T demod on IOD[6] */
+                       ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 6),
+                               0x40);
+                       if (ret)
+                               goto error;
+
+                       /* enable IF route on IOE[0] */
+                       ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 0),
+                               0x01);
+                       if (ret)
+                               goto error;
+               }
+
+               break;
+       default:
+               ret = 0;
+       }
+
+error:
+       return ret;
+}
+
 static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
 {
        int ret;
@@ -466,41 +574,54 @@ static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
                }
        };
 
-       /* Check which hardware we have.
-        * We must do this call two times to get reliable values (hw bug).
-        */
-       ret = anysee_get_hw_info(adap->dev, hw_info);
-       if (ret)
-               goto error;
+       /* detect hardware only once */
+       if (adap->fe_adap[0].fe == NULL) {
+               /* Check which hardware we have.
+                * We must do this call two times to get reliable values (hw bug).
+                */
+               ret = anysee_get_hw_info(adap->dev, hw_info);
+               if (ret)
+                       goto error;
 
-       ret = anysee_get_hw_info(adap->dev, hw_info);
-       if (ret)
-               goto error;
+               ret = anysee_get_hw_info(adap->dev, hw_info);
+               if (ret)
+                       goto error;
 
-       /* Meaning of these info bytes are guessed. */
-       info("firmware version:%d.%d hardware id:%d",
-               hw_info[1], hw_info[2], hw_info[0]);
+               /* Meaning of these info bytes are guessed. */
+               info("firmware version:%d.%d hardware id:%d",
+                       hw_info[1], hw_info[2], hw_info[0]);
 
-       state->hw = hw_info[0];
+               state->hw = hw_info[0];
+       }
+
+       /* set current frondend ID for devices having two frondends */
+       if (adap->fe_adap[0].fe)
+               state->fe_id++;
 
        switch (state->hw) {
        case ANYSEE_HW_507T: /* 2 */
                /* E30 */
 
+               if (state->fe_id)
+                       break;
+
                /* attach demod */
-               adap->fe = dvb_attach(mt352_attach, &anysee_mt352_config,
+               adap->fe_adap[0].fe = dvb_attach(mt352_attach, &anysee_mt352_config,
                        &adap->dev->i2c_adap);
-               if (adap->fe)
+               if (adap->fe_adap[0].fe)
                        break;
 
                /* attach demod */
-               adap->fe = dvb_attach(zl10353_attach, &anysee_zl10353_config,
+               adap->fe_adap[0].fe = dvb_attach(zl10353_attach, &anysee_zl10353_config,
                        &adap->dev->i2c_adap);
 
                break;
        case ANYSEE_HW_507CD: /* 6 */
                /* E30 Plus */
 
+               if (state->fe_id)
+                       break;
+
                /* enable DVB-T demod on IOD[0] */
                ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01);
                if (ret)
@@ -512,33 +633,39 @@ static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
                        goto error;
 
                /* attach demod */
-               adap->fe = dvb_attach(zl10353_attach, &anysee_zl10353_config,
-                       &adap->dev->i2c_adap);
+               adap->fe_adap[0].fe = dvb_attach(zl10353_attach,
+                       &anysee_zl10353_config, &adap->dev->i2c_adap);
 
                break;
        case ANYSEE_HW_507DC: /* 10 */
                /* E30 C Plus */
 
+               if (state->fe_id)
+                       break;
+
                /* enable DVB-C demod on IOD[0] */
                ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01);
                if (ret)
                        goto error;
 
                /* attach demod */
-               adap->fe = dvb_attach(tda10023_attach, &anysee_tda10023_config,
-                       &adap->dev->i2c_adap, 0x48);
+               adap->fe_adap[0].fe = dvb_attach(tda10023_attach,
+                       &anysee_tda10023_config, &adap->dev->i2c_adap, 0x48);
 
                break;
        case ANYSEE_HW_507SI: /* 11 */
                /* E30 S2 Plus */
 
+               if (state->fe_id)
+                       break;
+
                /* enable DVB-S/S2 demod on IOD[0] */
                ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01);
                if (ret)
                        goto error;
 
                /* attach demod */
-               adap->fe = dvb_attach(cx24116_attach, &anysee_cx24116_config,
+               adap->fe_adap[0].fe = dvb_attach(cx24116_attach, &anysee_cx24116_config,
                        &adap->dev->i2c_adap);
 
                break;
@@ -564,55 +691,59 @@ static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
                if (ret)
                        goto error;
 
-               if (dvb_usb_anysee_delsys) {
-                       /* disable DVB-C demod on IOD[5] */
-                       ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 5),
-                               0x20);
+               if ((state->fe_id ^ dvb_usb_anysee_delsys) == 0)  {
+                       /* disable DVB-T demod on IOD[0] */
+                       ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 0),
+                               0x01);
                        if (ret)
                                goto error;
 
-                       /* enable DVB-T demod on IOD[0] */
-                       ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0),
-                               0x01);
+                       /* enable DVB-C demod on IOD[5] */
+                       ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 5),
+                               0x20);
                        if (ret)
                                goto error;
 
                        /* attach demod */
                        if (tmp == 0xc7) {
                                /* TDA18212 config */
-                               adap->fe = dvb_attach(zl10353_attach,
-                                       &anysee_zl10353_tda18212_config2,
-                                       &adap->dev->i2c_adap);
+                               adap->fe_adap[state->fe_id].fe = dvb_attach(
+                                       tda10023_attach,
+                                       &anysee_tda10023_tda18212_config,
+                                       &adap->dev->i2c_adap, 0x48);
                        } else {
                                /* PLL config */
-                               adap->fe = dvb_attach(zl10353_attach,
-                                       &anysee_zl10353_config,
-                                       &adap->dev->i2c_adap);
+                               adap->fe_adap[state->fe_id].fe = dvb_attach(
+                                       tda10023_attach,
+                                       &anysee_tda10023_config,
+                                       &adap->dev->i2c_adap, 0x48);
                        }
                } else {
-                       /* disable DVB-T demod on IOD[0] */
-                       ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 0),
-                               0x01);
+                       /* disable DVB-C demod on IOD[5] */
+                       ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 5),
+                               0x20);
                        if (ret)
                                goto error;
 
-                       /* enable DVB-C demod on IOD[5] */
-                       ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 5),
-                               0x20);
+                       /* enable DVB-T demod on IOD[0] */
+                       ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0),
+                               0x01);
                        if (ret)
                                goto error;
 
                        /* attach demod */
                        if (tmp == 0xc7) {
                                /* TDA18212 config */
-                               adap->fe = dvb_attach(tda10023_attach,
-                                       &anysee_tda10023_tda18212_config,
-                                       &adap->dev->i2c_adap, 0x48);
+                               adap->fe_adap[state->fe_id].fe = dvb_attach(
+                                       zl10353_attach,
+                                       &anysee_zl10353_tda18212_config2,
+                                       &adap->dev->i2c_adap);
                        } else {
                                /* PLL config */
-                               adap->fe = dvb_attach(tda10023_attach,
-                                       &anysee_tda10023_config,
-                                       &adap->dev->i2c_adap, 0x48);
+                               adap->fe_adap[state->fe_id].fe = dvb_attach(
+                                       zl10353_attach,
+                                       &anysee_zl10353_config,
+                                       &adap->dev->i2c_adap);
                        }
                }
 
@@ -627,52 +758,40 @@ static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
                if (ret)
                        goto error;
 
-               if (dvb_usb_anysee_delsys) {
-                       /* disable DVB-C demod on IOD[5] */
-                       ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 5),
-                               0x20);
-                       if (ret)
-                               goto error;
-
-                       /* enable DVB-T demod on IOD[6] */
-                       ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 6),
+               if ((state->fe_id ^ dvb_usb_anysee_delsys) == 0)  {
+                       /* disable DVB-T demod on IOD[6] */
+                       ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 6),
                                0x40);
                        if (ret)
                                goto error;
 
-                       /* enable IF route on IOE[0] */
-                       ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 0),
-                               0x01);
+                       /* enable DVB-C demod on IOD[5] */
+                       ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 5),
+                               0x20);
                        if (ret)
                                goto error;
 
                        /* attach demod */
-                       adap->fe = dvb_attach(zl10353_attach,
-                               &anysee_zl10353_tda18212_config,
-                               &adap->dev->i2c_adap);
+                       adap->fe_adap[state->fe_id].fe = dvb_attach(tda10023_attach,
+                               &anysee_tda10023_tda18212_config,
+                               &adap->dev->i2c_adap, 0x48);
                } else {
-                       /* disable DVB-T demod on IOD[6] */
-                       ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 6),
-                               0x40);
-                       if (ret)
-                               goto error;
-
-                       /* enable DVB-C demod on IOD[5] */
-                       ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 5),
+                       /* disable DVB-C demod on IOD[5] */
+                       ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 5),
                                0x20);
                        if (ret)
                                goto error;
 
-                       /* enable IF route on IOE[0] */
-                       ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 0),
-                               0x01);
+                       /* enable DVB-T demod on IOD[6] */
+                       ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 6),
+                               0x40);
                        if (ret)
                                goto error;
 
                        /* attach demod */
-                       adap->fe = dvb_attach(tda10023_attach,
-                               &anysee_tda10023_tda18212_config,
-                               &adap->dev->i2c_adap, 0x48);
+                       adap->fe_adap[state->fe_id].fe = dvb_attach(zl10353_attach,
+                               &anysee_zl10353_tda18212_config,
+                               &adap->dev->i2c_adap);
                }
 
                break;
@@ -681,6 +800,9 @@ static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
                /* E7 S2 */
                /* E7 PS2 */
 
+               if (state->fe_id)
+                       break;
+
                /* enable transport stream on IOA[7] */
                ret = anysee_wr_reg_mask(adap->dev, REG_IOA, (1 << 7), 0x80);
                if (ret)
@@ -692,13 +814,13 @@ static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
                        goto error;
 
                /* attach demod */
-               adap->fe = dvb_attach(stv0900_attach, &anysee_stv0900_config,
+               adap->fe_adap[0].fe = dvb_attach(stv0900_attach, &anysee_stv0900_config,
                        &adap->dev->i2c_adap, 0);
 
                break;
        }
 
-       if (!adap->fe) {
+       if (!adap->fe_adap[0].fe) {
                /* we have no frontend :-( */
                ret = -ENODEV;
                err("Unsupported Anysee version. " \
@@ -713,14 +835,14 @@ static int anysee_tuner_attach(struct dvb_usb_adapter *adap)
        struct anysee_state *state = adap->dev->priv;
        struct dvb_frontend *fe;
        int ret;
-       deb_info("%s:\n", __func__);
+       deb_info("%s: fe=%d\n", __func__, state->fe_id);
 
        switch (state->hw) {
        case ANYSEE_HW_507T: /* 2 */
                /* E30 */
 
                /* attach tuner */
-               fe = dvb_attach(dvb_pll_attach, adap->fe, (0xc2 >> 1),
+               fe = dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, (0xc2 >> 1),
                        NULL, DVB_PLL_THOMSON_DTT7579);
 
                break;
@@ -728,7 +850,7 @@ static int anysee_tuner_attach(struct dvb_usb_adapter *adap)
                /* E30 Plus */
 
                /* attach tuner */
-               fe = dvb_attach(dvb_pll_attach, adap->fe, (0xc2 >> 1),
+               fe = dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, (0xc2 >> 1),
                        &adap->dev->i2c_adap, DVB_PLL_THOMSON_DTT7579);
 
                break;
@@ -736,7 +858,7 @@ static int anysee_tuner_attach(struct dvb_usb_adapter *adap)
                /* E30 C Plus */
 
                /* attach tuner */
-               fe = dvb_attach(dvb_pll_attach, adap->fe, (0xc0 >> 1),
+               fe = dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, (0xc0 >> 1),
                        &adap->dev->i2c_adap, DVB_PLL_SAMSUNG_DTOS403IH102A);
 
                break;
@@ -744,28 +866,14 @@ static int anysee_tuner_attach(struct dvb_usb_adapter *adap)
                /* E30 S2 Plus */
 
                /* attach LNB controller */
-               fe = dvb_attach(isl6423_attach, adap->fe, &adap->dev->i2c_adap,
-                       &anysee_isl6423_config);
+               fe = dvb_attach(isl6423_attach, adap->fe_adap[0].fe,
+                       &adap->dev->i2c_adap, &anysee_isl6423_config);
 
                break;
        case ANYSEE_HW_507FA: /* 15 */
                /* E30 Combo Plus */
                /* E30 C Plus */
 
-               if (dvb_usb_anysee_delsys) {
-                       /* enable DVB-T tuner on IOE[0] */
-                       ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 0),
-                               0x01);
-                       if (ret)
-                               goto error;
-               } else {
-                       /* enable DVB-C tuner on IOE[0] */
-                       ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 0),
-                               0x01);
-                       if (ret)
-                               goto error;
-               }
-
                /* Try first attach TDA18212 silicon tuner on IOE[4], if that
                 * fails attach old simple PLL. */
 
@@ -775,8 +883,8 @@ static int anysee_tuner_attach(struct dvb_usb_adapter *adap)
                        goto error;
 
                /* attach tuner */
-               fe = dvb_attach(tda18212_attach, adap->fe, &adap->dev->i2c_adap,
-                       &anysee_tda18212_config);
+               fe = dvb_attach(tda18212_attach, adap->fe_adap[state->fe_id].fe,
+                       &adap->dev->i2c_adap, &anysee_tda18212_config);
                if (fe)
                        break;
 
@@ -786,8 +894,9 @@ static int anysee_tuner_attach(struct dvb_usb_adapter *adap)
                        goto error;
 
                /* attach tuner */
-               fe = dvb_attach(dvb_pll_attach, adap->fe, (0xc0 >> 1),
-                       &adap->dev->i2c_adap, DVB_PLL_SAMSUNG_DTOS403IH102A);
+               fe = dvb_attach(dvb_pll_attach, adap->fe_adap[state->fe_id].fe,
+                       (0xc0 >> 1), &adap->dev->i2c_adap,
+                       DVB_PLL_SAMSUNG_DTOS403IH102A);
 
                break;
        case ANYSEE_HW_508TC: /* 18 */
@@ -801,8 +910,8 @@ static int anysee_tuner_attach(struct dvb_usb_adapter *adap)
                        goto error;
 
                /* attach tuner */
-               fe = dvb_attach(tda18212_attach, adap->fe, &adap->dev->i2c_adap,
-                       &anysee_tda18212_config);
+               fe = dvb_attach(tda18212_attach, adap->fe_adap[state->fe_id].fe,
+                       &adap->dev->i2c_adap, &anysee_tda18212_config);
 
                break;
        case ANYSEE_HW_508S2: /* 19 */
@@ -811,12 +920,12 @@ static int anysee_tuner_attach(struct dvb_usb_adapter *adap)
                /* E7 PS2 */
 
                /* attach tuner */
-               fe = dvb_attach(stv6110_attach, adap->fe,
+               fe = dvb_attach(stv6110_attach, adap->fe_adap[0].fe,
                        &anysee_stv6110_config, &adap->dev->i2c_adap);
 
                if (fe) {
                        /* attach LNB controller */
-                       fe = dvb_attach(isl6423_attach, adap->fe,
+                       fe = dvb_attach(isl6423_attach, adap->fe_adap[0].fe,
                                &adap->dev->i2c_adap, &anysee_isl6423_config);
                }
 
@@ -918,6 +1027,23 @@ static struct dvb_usb_device_properties anysee_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends    = 2,
+               .frontend_ctrl    = anysee_frontend_ctrl,
+               .fe = {{
+                       .streaming_ctrl   = anysee_streaming_ctrl,
+                       .frontend_attach  = anysee_frontend_attach,
+                       .tuner_attach     = anysee_tuner_attach,
+                       .stream = {
+                               .type = USB_BULK,
+                               .count = 8,
+                               .endpoint = 0x82,
+                               .u = {
+                                       .bulk = {
+                                               .buffersize = (16*512),
+                                       }
+                               }
+                       },
+               }, {
                        .streaming_ctrl   = anysee_streaming_ctrl,
                        .frontend_attach  = anysee_frontend_attach,
                        .tuner_attach     = anysee_tuner_attach,
@@ -931,6 +1057,7 @@ static struct dvb_usb_device_properties anysee_properties = {
                                        }
                                }
                        },
+               }},
                }
        },
 
index ad6ccd1ea2d9bdabe67a3a88e7e22262db72e425..57ee500b8c0e1c16d8c41e8bf51d40b1e6058014 100644 (file)
@@ -59,6 +59,7 @@ enum cmd {
 struct anysee_state {
        u8 hw; /* PCB ID */
        u8 seq;
+       u8 fe_id:1; /* frondend ID */
 };
 
 #define ANYSEE_HW_507T    2 /* E30 */
index 2351077ff2b375888806010ef3152685fa442357..b77994967b9b3ebeee3de4a4fe20229000947740 100644 (file)
@@ -140,9 +140,9 @@ static struct zl10353_config au6610_zl10353_config = {
 
 static int au6610_zl10353_frontend_attach(struct dvb_usb_adapter *adap)
 {
-       adap->fe = dvb_attach(zl10353_attach, &au6610_zl10353_config,
+       adap->fe_adap[0].fe = dvb_attach(zl10353_attach, &au6610_zl10353_config,
                &adap->dev->i2c_adap);
-       if (adap->fe == NULL)
+       if (adap->fe_adap[0].fe == NULL)
                return -ENODEV;
 
        return 0;
@@ -155,7 +155,7 @@ static struct qt1010_config au6610_qt1010_config = {
 static int au6610_qt1010_tuner_attach(struct dvb_usb_adapter *adap)
 {
        return dvb_attach(qt1010_attach,
-                         adap->fe, &adap->dev->i2c_adap,
+                         adap->fe_adap[0].fe, &adap->dev->i2c_adap,
                          &au6610_qt1010_config) == NULL ? -ENODEV : 0;
 }
 
@@ -204,6 +204,8 @@ static struct dvb_usb_device_properties au6610_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .frontend_attach  = au6610_zl10353_frontend_attach,
                        .tuner_attach     = au6610_qt1010_tuner_attach,
 
@@ -219,6 +221,7 @@ static struct dvb_usb_device_properties au6610_properties = {
                                        }
                                }
                        },
+               }},
                }
        },
 
index 57e2444d51ab965947946f2786dab848f0f656eb..bf67b4dfd82b487106ae8d082cae12017b7211be 100644 (file)
@@ -40,7 +40,6 @@ static const struct stb0899_s1_reg az6027_stb0899_s1_init_1[] = {
        { STB0899_DISRX_ST0             , 0x04 },
        { STB0899_DISRX_ST1             , 0x00 },
        { STB0899_DISPARITY             , 0x00 },
-       { STB0899_DISFIFO               , 0x00 },
        { STB0899_DISSTATUS             , 0x20 },
        { STB0899_DISF22                , 0x99 },
        { STB0899_DISF22RX              , 0xa8 },
@@ -782,7 +781,6 @@ static int az6027_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
 {
 
        u8 buf;
-       int ret;
        struct dvb_usb_adapter *adap = fe->dvb->priv;
 
        struct i2c_msg i2c_msg = {
@@ -800,17 +798,17 @@ static int az6027_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
        switch (voltage) {
        case SEC_VOLTAGE_13:
                buf = 1;
-               ret = i2c_transfer(&adap->dev->i2c_adap, &i2c_msg, 1);
+               i2c_transfer(&adap->dev->i2c_adap, &i2c_msg, 1);
                break;
 
        case SEC_VOLTAGE_18:
                buf = 2;
-               ret = i2c_transfer(&adap->dev->i2c_adap, &i2c_msg, 1);
+               i2c_transfer(&adap->dev->i2c_adap, &i2c_msg, 1);
                break;
 
        case SEC_VOLTAGE_OFF:
                buf = 0;
-               ret = i2c_transfer(&adap->dev->i2c_adap, &i2c_msg, 1);
+               i2c_transfer(&adap->dev->i2c_adap, &i2c_msg, 1);
                break;
 
        default:
@@ -910,16 +908,16 @@ static int az6027_frontend_attach(struct dvb_usb_adapter *adap)
        az6027_frontend_reset(adap);
 
        deb_info("adap = %p, dev = %p\n", adap, adap->dev);
-       adap->fe = stb0899_attach(&az6027_stb0899_config, &adap->dev->i2c_adap);
+       adap->fe_adap[0].fe = stb0899_attach(&az6027_stb0899_config, &adap->dev->i2c_adap);
 
-       if (adap->fe) {
+       if (adap->fe_adap[0].fe) {
                deb_info("found STB0899 DVB-S/DVB-S2 frontend @0x%02x", az6027_stb0899_config.demod_address);
-               if (stb6100_attach(adap->fe, &az6027_stb6100_config, &adap->dev->i2c_adap)) {
+               if (stb6100_attach(adap->fe_adap[0].fe, &az6027_stb6100_config, &adap->dev->i2c_adap)) {
                        deb_info("found STB6100 DVB-S/DVB-S2 frontend @0x%02x", az6027_stb6100_config.tuner_address);
-                       adap->fe->ops.set_voltage = az6027_set_voltage;
+                       adap->fe_adap[0].fe->ops.set_voltage = az6027_set_voltage;
                        az6027_ci_init(adap);
                } else {
-                       adap->fe = NULL;
+                       adap->fe_adap[0].fe = NULL;
                }
        } else
                warn("no front-end attached\n");
@@ -954,7 +952,6 @@ static int az6027_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int n
 {
        struct dvb_usb_device *d = i2c_get_adapdata(adap);
        int i = 0, j = 0, len = 0;
-       int ret;
        u16 index;
        u16 value;
        int length;
@@ -990,7 +987,7 @@ static int az6027_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int n
                                index = (((msg[i].buf[0] << 8) & 0xff00) | (msg[i].buf[1] & 0x00ff));
                                value = msg[i].addr + (msg[i].len << 8);
                                length = msg[i + 1].len + 6;
-                               ret = az6027_usb_in_op(d, req, value, index, data, length);
+                               az6027_usb_in_op(d, req, value, index, data, length);
                                len = msg[i + 1].len;
                                for (j = 0; j < len; j++)
                                        msg[i + 1].buf[j] = data[j + 5];
@@ -1017,7 +1014,7 @@ static int az6027_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int n
                                index = 0x0;
                                value = msg[i].addr;
                                length = msg[i].len + 6;
-                               ret = az6027_usb_in_op(d, req, value, index, data, length);
+                               az6027_usb_in_op(d, req, value, index, data, length);
                                len = msg[i].len;
                                for (j = 0; j < len; j++)
                                        msg[i].buf[j] = data[j + 5];
@@ -1106,6 +1103,8 @@ static struct dvb_usb_device_properties az6027_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .streaming_ctrl   = az6027_streaming_ctrl,
                        .frontend_attach  = az6027_frontend_attach,
 
@@ -1120,6 +1119,7 @@ static struct dvb_usb_device_properties az6027_properties = {
                                        }
                                }
                        },
+               }},
                }
        },
 /*
index 6d1a3041540d1c74142949b86d9014a2a2c81788..57afb5a9157e9ec5d5bc9aaae834800a3656c66f 100644 (file)
@@ -186,9 +186,9 @@ static struct zl10353_config ce6230_zl10353_config = {
 static int ce6230_zl10353_frontend_attach(struct dvb_usb_adapter *adap)
 {
        deb_info("%s:\n", __func__);
-       adap->fe = dvb_attach(zl10353_attach, &ce6230_zl10353_config,
+       adap->fe_adap[0].fe = dvb_attach(zl10353_attach, &ce6230_zl10353_config,
                &adap->dev->i2c_adap);
-       if (adap->fe == NULL)
+       if (adap->fe_adap[0].fe == NULL)
                return -ENODEV;
        return 0;
 }
@@ -214,7 +214,7 @@ static int ce6230_mxl5003s_tuner_attach(struct dvb_usb_adapter *adap)
 {
        int ret;
        deb_info("%s:\n", __func__);
-       ret = dvb_attach(mxl5005s_attach, adap->fe, &adap->dev->i2c_adap,
+       ret = dvb_attach(mxl5005s_attach, adap->fe_adap[0].fe, &adap->dev->i2c_adap,
                        &ce6230_mxl5003s_config) == NULL ? -ENODEV : 0;
        return ret;
 }
@@ -273,6 +273,8 @@ static struct dvb_usb_device_properties ce6230_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .frontend_attach  = ce6230_zl10353_frontend_attach,
                        .tuner_attach     = ce6230_mxl5003s_tuner_attach,
                        .stream = {
@@ -285,6 +287,7 @@ static struct dvb_usb_device_properties ce6230_properties = {
                                        }
                                }
                        },
+               }},
                }
        },
 
index 16f2ce2bc15a7a73108913a787527d6a022a725d..f9d905002ec93114349aec49f7b0ca0c51320ff7 100644 (file)
@@ -69,7 +69,7 @@ static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
        char state[3];
        int ret;
 
-       adap->fe = cinergyt2_fe_attach(adap->dev);
+       adap->fe_adap[0].fe = cinergyt2_fe_attach(adap->dev);
 
        ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state,
                                sizeof(state), 0);
@@ -198,6 +198,8 @@ static struct dvb_usb_device_properties cinergyt2_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .streaming_ctrl   = cinergyt2_streaming_ctrl,
                        .frontend_attach  = cinergyt2_frontend_attach,
 
@@ -212,6 +214,7 @@ static struct dvb_usb_device_properties cinergyt2_properties = {
                                        }
                                }
                        },
+               }},
                }
        },
 
index acb5fb2d2e73574f81cb8c6535353f0f4c1f2ada..9f2a02c483779db28f3a754a0215f72484ac8fca 100644 (file)
@@ -347,7 +347,7 @@ static void cxusb_d680_dmb_drain_message(struct dvb_usb_device *d)
 
 static void cxusb_d680_dmb_drain_video(struct dvb_usb_device *d)
 {
-       struct usb_data_stream_properties *p = &d->props.adapter[0].stream;
+       struct usb_data_stream_properties *p = &d->props.adapter[0].fe[0].stream;
        const int timeout = 100;
        const int junk_len = p->u.bulk.buffersize;
        u8        *junk;
@@ -725,7 +725,7 @@ static struct max2165_config mygica_d689_max2165_cfg = {
 /* Callbacks for DVB USB */
 static int cxusb_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap)
 {
-       dvb_attach(simple_tuner_attach, adap->fe,
+       dvb_attach(simple_tuner_attach, adap->fe_adap[0].fe,
                   &adap->dev->i2c_adap, 0x61,
                   TUNER_PHILIPS_FMD1216ME_MK3);
        return 0;
@@ -733,27 +733,27 @@ static int cxusb_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap)
 
 static int cxusb_dee1601_tuner_attach(struct dvb_usb_adapter *adap)
 {
-       dvb_attach(dvb_pll_attach, adap->fe, 0x61,
+       dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x61,
                   NULL, DVB_PLL_THOMSON_DTT7579);
        return 0;
 }
 
 static int cxusb_lgz201_tuner_attach(struct dvb_usb_adapter *adap)
 {
-       dvb_attach(dvb_pll_attach, adap->fe, 0x61, NULL, DVB_PLL_LG_Z201);
+       dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x61, NULL, DVB_PLL_LG_Z201);
        return 0;
 }
 
 static int cxusb_dtt7579_tuner_attach(struct dvb_usb_adapter *adap)
 {
-       dvb_attach(dvb_pll_attach, adap->fe, 0x60,
+       dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
                   NULL, DVB_PLL_THOMSON_DTT7579);
        return 0;
 }
 
 static int cxusb_lgh064f_tuner_attach(struct dvb_usb_adapter *adap)
 {
-       dvb_attach(simple_tuner_attach, adap->fe,
+       dvb_attach(simple_tuner_attach, adap->fe_adap[0].fe,
                   &adap->dev->i2c_adap, 0x61, TUNER_LG_TDVS_H06XF);
        return 0;
 }
@@ -795,9 +795,9 @@ static int cxusb_dvico_xc3028_tuner_attach(struct dvb_usb_adapter *adap)
        };
 
        /* FIXME: generalize & move to common area */
-       adap->fe->callback = dvico_bluebird_xc2028_callback;
+       adap->fe_adap[0].fe->callback = dvico_bluebird_xc2028_callback;
 
-       fe = dvb_attach(xc2028_attach, adap->fe, &cfg);
+       fe = dvb_attach(xc2028_attach, adap->fe_adap[0].fe, &cfg);
        if (fe == NULL || fe->ops.tuner_ops.set_config == NULL)
                return -EIO;
 
@@ -808,7 +808,7 @@ static int cxusb_dvico_xc3028_tuner_attach(struct dvb_usb_adapter *adap)
 
 static int cxusb_mxl5003s_tuner_attach(struct dvb_usb_adapter *adap)
 {
-       dvb_attach(mxl5005s_attach, adap->fe,
+       dvb_attach(mxl5005s_attach, adap->fe_adap[0].fe,
                   &adap->dev->i2c_adap, &aver_a868r_tuner);
        return 0;
 }
@@ -816,7 +816,7 @@ static int cxusb_mxl5003s_tuner_attach(struct dvb_usb_adapter *adap)
 static int cxusb_d680_dmb_tuner_attach(struct dvb_usb_adapter *adap)
 {
        struct dvb_frontend *fe;
-       fe = dvb_attach(mxl5005s_attach, adap->fe,
+       fe = dvb_attach(mxl5005s_attach, adap->fe_adap[0].fe,
                        &adap->dev->i2c_adap, &d680_dmb_tuner);
        return (fe == NULL) ? -EIO : 0;
 }
@@ -824,7 +824,7 @@ static int cxusb_d680_dmb_tuner_attach(struct dvb_usb_adapter *adap)
 static int cxusb_mygica_d689_tuner_attach(struct dvb_usb_adapter *adap)
 {
        struct dvb_frontend *fe;
-       fe = dvb_attach(max2165_attach, adap->fe,
+       fe = dvb_attach(max2165_attach, adap->fe_adap[0].fe,
                        &adap->dev->i2c_adap, &mygica_d689_max2165_cfg);
        return (fe == NULL) ? -EIO : 0;
 }
@@ -837,8 +837,9 @@ static int cxusb_cx22702_frontend_attach(struct dvb_usb_adapter *adap)
 
        cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, &b, 1);
 
-       if ((adap->fe = dvb_attach(cx22702_attach, &cxusb_cx22702_config,
-                                  &adap->dev->i2c_adap)) != NULL)
+       adap->fe_adap[0].fe = dvb_attach(cx22702_attach, &cxusb_cx22702_config,
+                                        &adap->dev->i2c_adap);
+       if ((adap->fe_adap[0].fe) != NULL)
                return 0;
 
        return -EIO;
@@ -851,8 +852,10 @@ static int cxusb_lgdt3303_frontend_attach(struct dvb_usb_adapter *adap)
 
        cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
 
-       if ((adap->fe = dvb_attach(lgdt330x_attach, &cxusb_lgdt3303_config,
-                                  &adap->dev->i2c_adap)) != NULL)
+       adap->fe_adap[0].fe = dvb_attach(lgdt330x_attach,
+                                        &cxusb_lgdt3303_config,
+                                        &adap->dev->i2c_adap);
+       if ((adap->fe_adap[0].fe) != NULL)
                return 0;
 
        return -EIO;
@@ -860,9 +863,9 @@ static int cxusb_lgdt3303_frontend_attach(struct dvb_usb_adapter *adap)
 
 static int cxusb_aver_lgdt3303_frontend_attach(struct dvb_usb_adapter *adap)
 {
-       adap->fe = dvb_attach(lgdt330x_attach, &cxusb_aver_lgdt3303_config,
+       adap->fe_adap[0].fe = dvb_attach(lgdt330x_attach, &cxusb_aver_lgdt3303_config,
                              &adap->dev->i2c_adap);
-       if (adap->fe != NULL)
+       if (adap->fe_adap[0].fe != NULL)
                return 0;
 
        return -EIO;
@@ -876,8 +879,9 @@ static int cxusb_mt352_frontend_attach(struct dvb_usb_adapter *adap)
 
        cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
 
-       if ((adap->fe = dvb_attach(mt352_attach, &cxusb_mt352_config,
-                                  &adap->dev->i2c_adap)) != NULL)
+       adap->fe_adap[0].fe = dvb_attach(mt352_attach, &cxusb_mt352_config,
+                                        &adap->dev->i2c_adap);
+       if ((adap->fe_adap[0].fe) != NULL)
                return 0;
 
        return -EIO;
@@ -890,11 +894,15 @@ static int cxusb_dee1601_frontend_attach(struct dvb_usb_adapter *adap)
 
        cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
 
-       if (((adap->fe = dvb_attach(mt352_attach, &cxusb_dee1601_config,
-                                   &adap->dev->i2c_adap)) != NULL) ||
-               ((adap->fe = dvb_attach(zl10353_attach,
-                                       &cxusb_zl10353_dee1601_config,
-                                       &adap->dev->i2c_adap)) != NULL))
+       adap->fe_adap[0].fe = dvb_attach(mt352_attach, &cxusb_dee1601_config,
+                                        &adap->dev->i2c_adap);
+       if ((adap->fe_adap[0].fe) != NULL)
+               return 0;
+
+       adap->fe_adap[0].fe = dvb_attach(zl10353_attach,
+                                        &cxusb_zl10353_dee1601_config,
+                                        &adap->dev->i2c_adap);
+       if ((adap->fe_adap[0].fe) != NULL)
                return 0;
 
        return -EIO;
@@ -917,9 +925,11 @@ static int cxusb_dualdig4_frontend_attach(struct dvb_usb_adapter *adap)
        cxusb_bluebird_gpio_pulse(adap->dev, 0x01, 1);
        cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);
 
-       if ((adap->fe = dvb_attach(zl10353_attach,
-                                  &cxusb_zl10353_xc3028_config_no_i2c_gate,
-                                  &adap->dev->i2c_adap)) == NULL)
+       adap->fe_adap[0].fe =
+               dvb_attach(zl10353_attach,
+                          &cxusb_zl10353_xc3028_config_no_i2c_gate,
+                          &adap->dev->i2c_adap);
+       if ((adap->fe_adap[0].fe) == NULL)
                return -EIO;
 
        /* try to determine if there is no IR decoder on the I2C bus */
@@ -1031,9 +1041,9 @@ static int cxusb_dualdig4_rev2_frontend_attach(struct dvb_usb_adapter *adap)
                return -ENODEV;
        }
 
-       adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80,
+       adap->fe_adap[0].fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80,
                              &cxusb_dualdig4_rev2_config);
-       if (adap->fe == NULL)
+       if (adap->fe_adap[0].fe == NULL)
                return -EIO;
 
        return 0;
@@ -1084,15 +1094,15 @@ static int cxusb_dualdig4_rev2_tuner_attach(struct dvb_usb_adapter *adap)
 {
        struct dib0700_adapter_state *st = adap->priv;
        struct i2c_adapter *tun_i2c =
-               dib7000p_get_i2c_master(adap->fe,
+               dib7000p_get_i2c_master(adap->fe_adap[0].fe,
                                        DIBX000_I2C_INTERFACE_TUNER, 1);
 
-       if (dvb_attach(dib0070_attach, adap->fe, tun_i2c,
+       if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c,
            &dib7070p_dib0070_config) == NULL)
                return -ENODEV;
 
-       st->set_param_save = adap->fe->ops.tuner_ops.set_params;
-       adap->fe->ops.tuner_ops.set_params = dib7070_set_param_override;
+       st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
+       adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7070_set_param_override;
        return 0;
 }
 
@@ -1108,14 +1118,16 @@ static int cxusb_nano2_frontend_attach(struct dvb_usb_adapter *adap)
        cxusb_bluebird_gpio_pulse(adap->dev, 0x01, 1);
        cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);
 
-       if ((adap->fe = dvb_attach(zl10353_attach,
-                                  &cxusb_zl10353_xc3028_config,
-                                  &adap->dev->i2c_adap)) != NULL)
+       adap->fe_adap[0].fe = dvb_attach(zl10353_attach,
+                                        &cxusb_zl10353_xc3028_config,
+                                        &adap->dev->i2c_adap);
+       if ((adap->fe_adap[0].fe) != NULL)
                return 0;
 
-       if ((adap->fe = dvb_attach(mt352_attach,
-                                  &cxusb_mt352_xc3028_config,
-                                  &adap->dev->i2c_adap)) != NULL)
+       adap->fe_adap[0].fe = dvb_attach(mt352_attach,
+                                        &cxusb_mt352_xc3028_config,
+                                        &adap->dev->i2c_adap);
+       if ((adap->fe_adap[0].fe) != NULL)
                return 0;
 
        return -EIO;
@@ -1150,7 +1162,7 @@ static int cxusb_d680_dmb_frontend_attach(struct dvb_usb_adapter *adap)
        usb_clear_halt(d->udev,
                usb_rcvbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
        usb_clear_halt(d->udev,
-               usb_rcvbulkpipe(d->udev, d->props.adapter[0].stream.endpoint));
+               usb_rcvbulkpipe(d->udev, d->props.adapter[0].fe[0].stream.endpoint));
 
        /* Drain USB pipes to avoid hang after reboot */
        for (n = 0;  n < 5;  n++) {
@@ -1172,8 +1184,8 @@ static int cxusb_d680_dmb_frontend_attach(struct dvb_usb_adapter *adap)
        msleep(100);
 
        /* Attach frontend */
-       adap->fe = dvb_attach(lgs8gxx_attach, &d680_lgs8gl5_cfg, &d->i2c_adap);
-       if (adap->fe == NULL)
+       adap->fe_adap[0].fe = dvb_attach(lgs8gxx_attach, &d680_lgs8gl5_cfg, &d->i2c_adap);
+       if (adap->fe_adap[0].fe == NULL)
                return -EIO;
 
        return 0;
@@ -1207,7 +1219,7 @@ static int cxusb_mygica_d689_frontend_attach(struct dvb_usb_adapter *adap)
        usb_clear_halt(d->udev,
                usb_rcvbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
        usb_clear_halt(d->udev,
-               usb_rcvbulkpipe(d->udev, d->props.adapter[0].stream.endpoint));
+               usb_rcvbulkpipe(d->udev, d->props.adapter[0].fe[0].stream.endpoint));
 
 
        /* Reset the tuner */
@@ -1223,9 +1235,9 @@ static int cxusb_mygica_d689_frontend_attach(struct dvb_usb_adapter *adap)
        msleep(100);
 
        /* Attach frontend */
-       adap->fe = dvb_attach(atbm8830_attach, &mygica_d689_atbm8830_cfg,
+       adap->fe_adap[0].fe = dvb_attach(atbm8830_attach, &mygica_d689_atbm8830_cfg,
                &d->i2c_adap);
-       if (adap->fe == NULL)
+       if (adap->fe_adap[0].fe == NULL)
                return -EIO;
 
        return 0;
@@ -1383,6 +1395,8 @@ static struct dvb_usb_device_properties cxusb_medion_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .streaming_ctrl   = cxusb_streaming_ctrl,
                        .frontend_attach  = cxusb_cx22702_frontend_attach,
                        .tuner_attach     = cxusb_fmd1216me_tuner_attach,
@@ -1397,7 +1411,7 @@ static struct dvb_usb_device_properties cxusb_medion_properties = {
                                        }
                                }
                        },
-
+               }},
                },
        },
        .power_ctrl       = cxusb_power_ctrl,
@@ -1429,6 +1443,8 @@ static struct dvb_usb_device_properties cxusb_bluebird_lgh064f_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .streaming_ctrl   = cxusb_streaming_ctrl,
                        .frontend_attach  = cxusb_lgdt3303_frontend_attach,
                        .tuner_attach     = cxusb_lgh064f_tuner_attach,
@@ -1444,6 +1460,7 @@ static struct dvb_usb_device_properties cxusb_bluebird_lgh064f_properties = {
                                        }
                                }
                        },
+               }},
                },
        },
 
@@ -1483,6 +1500,8 @@ static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .streaming_ctrl   = cxusb_streaming_ctrl,
                        .frontend_attach  = cxusb_dee1601_frontend_attach,
                        .tuner_attach     = cxusb_dee1601_tuner_attach,
@@ -1497,6 +1516,7 @@ static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties = {
                                        }
                                }
                        },
+               }},
                },
        },
 
@@ -1544,6 +1564,8 @@ static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties = {
        .num_adapters = 2,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .streaming_ctrl   = cxusb_streaming_ctrl,
                        .frontend_attach  = cxusb_mt352_frontend_attach,
                        .tuner_attach     = cxusb_lgz201_tuner_attach,
@@ -1559,6 +1581,7 @@ static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties = {
                                        }
                                }
                        },
+               }},
                },
        },
        .power_ctrl       = cxusb_bluebird_power_ctrl,
@@ -1596,6 +1619,8 @@ static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .streaming_ctrl   = cxusb_streaming_ctrl,
                        .frontend_attach  = cxusb_mt352_frontend_attach,
                        .tuner_attach     = cxusb_dtt7579_tuner_attach,
@@ -1611,6 +1636,7 @@ static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties = {
                                        }
                                }
                        },
+               }},
                },
        },
        .power_ctrl       = cxusb_bluebird_power_ctrl,
@@ -1645,6 +1671,8 @@ static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .streaming_ctrl   = cxusb_streaming_ctrl,
                        .frontend_attach  = cxusb_dualdig4_frontend_attach,
                        .tuner_attach     = cxusb_dvico_xc3028_tuner_attach,
@@ -1659,6 +1687,7 @@ static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_properties = {
                                        }
                                }
                        },
+               }},
                },
        },
 
@@ -1695,6 +1724,8 @@ static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .streaming_ctrl   = cxusb_streaming_ctrl,
                        .frontend_attach  = cxusb_nano2_frontend_attach,
                        .tuner_attach     = cxusb_dvico_xc3028_tuner_attach,
@@ -1709,6 +1740,7 @@ static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties = {
                                        }
                                }
                        },
+               }},
                },
        },
 
@@ -1747,6 +1779,8 @@ static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_prope
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .streaming_ctrl   = cxusb_streaming_ctrl,
                        .frontend_attach  = cxusb_nano2_frontend_attach,
                        .tuner_attach     = cxusb_dvico_xc3028_tuner_attach,
@@ -1761,6 +1795,7 @@ static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_prope
                                        }
                                }
                        },
+               }},
                },
        },
 
@@ -1796,6 +1831,8 @@ static struct dvb_usb_device_properties cxusb_aver_a868r_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .streaming_ctrl   = cxusb_aver_streaming_ctrl,
                        .frontend_attach  = cxusb_aver_lgdt3303_frontend_attach,
                        .tuner_attach     = cxusb_mxl5003s_tuner_attach,
@@ -1810,7 +1847,7 @@ static struct dvb_usb_device_properties cxusb_aver_a868r_properties = {
                                        }
                                }
                        },
-
+               }},
                },
        },
        .power_ctrl       = cxusb_aver_power_ctrl,
@@ -1839,10 +1876,12 @@ struct dvb_usb_device_properties cxusb_bluebird_dualdig4_rev2_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .size_of_priv    = sizeof(struct dib0700_adapter_state),
+               .num_frontends = 1,
+               .fe = {{
                        .streaming_ctrl  = cxusb_streaming_ctrl,
                        .frontend_attach = cxusb_dualdig4_rev2_frontend_attach,
                        .tuner_attach    = cxusb_dualdig4_rev2_tuner_attach,
-                       .size_of_priv    = sizeof(struct dib0700_adapter_state),
                        /* parameter for the MPEG2-data transfer */
                        .stream = {
                                .type = USB_BULK,
@@ -1854,6 +1893,7 @@ struct dvb_usb_device_properties cxusb_bluebird_dualdig4_rev2_properties = {
                                        }
                                }
                        },
+               }},
                },
        },
 
@@ -1889,6 +1929,8 @@ static struct dvb_usb_device_properties cxusb_d680_dmb_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .streaming_ctrl   = cxusb_d680_dmb_streaming_ctrl,
                        .frontend_attach  = cxusb_d680_dmb_frontend_attach,
                        .tuner_attach     = cxusb_d680_dmb_tuner_attach,
@@ -1904,6 +1946,7 @@ static struct dvb_usb_device_properties cxusb_d680_dmb_properties = {
                                        }
                                }
                        },
+               }},
                },
        },
 
@@ -1940,6 +1983,8 @@ static struct dvb_usb_device_properties cxusb_mygica_d689_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .streaming_ctrl   = cxusb_d680_dmb_streaming_ctrl,
                        .frontend_attach  = cxusb_mygica_d689_frontend_attach,
                        .tuner_attach     = cxusb_mygica_d689_tuner_attach,
@@ -1955,6 +2000,7 @@ static struct dvb_usb_device_properties cxusb_mygica_d689_properties = {
                                        }
                                }
                        },
+               }},
                },
        },
 
index 5eb91b4f8fd08ff98c38dc9e4f90e77d086879a6..156cbfc9c79db710de6b9b119c55eaf823476f09 100644 (file)
@@ -30,6 +30,11 @@ int dib0700_get_version(struct dvb_usb_device *d, u32 *hwversion,
        struct dib0700_state *st = d->priv;
        int ret;
 
+       if (mutex_lock_interruptible(&d->usb_mutex) < 0) {
+               err("could not acquire lock");
+               return 0;
+       }
+
        ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0),
                                  REQUEST_GET_VERSION,
                                  USB_TYPE_VENDOR | USB_DIR_IN, 0, 0,
@@ -46,6 +51,7 @@ int dib0700_get_version(struct dvb_usb_device *d, u32 *hwversion,
        if (fwtype != NULL)
                *fwtype     = (st->buf[12] << 24) | (st->buf[13] << 16) |
                        (st->buf[14] << 8) | st->buf[15];
+       mutex_unlock(&d->usb_mutex);
        return ret;
 }
 
@@ -108,7 +114,12 @@ int dib0700_ctrl_rd(struct dvb_usb_device *d, u8 *tx, u8 txlen, u8 *rx, u8 rxlen
 int dib0700_set_gpio(struct dvb_usb_device *d, enum dib07x0_gpios gpio, u8 gpio_dir, u8 gpio_val)
 {
        struct dib0700_state *st = d->priv;
-       s16 ret;
+       int ret;
+
+       if (mutex_lock_interruptible(&d->usb_mutex) < 0) {
+               err("could not acquire lock");
+               return 0;
+       }
 
        st->buf[0] = REQUEST_SET_GPIO;
        st->buf[1] = gpio;
@@ -116,6 +127,7 @@ int dib0700_set_gpio(struct dvb_usb_device *d, enum dib07x0_gpios gpio, u8 gpio_
 
        ret = dib0700_ctrl_wr(d, st->buf, 3);
 
+       mutex_unlock(&d->usb_mutex);
        return ret;
 }
 
@@ -125,6 +137,11 @@ static int dib0700_set_usb_xfer_len(struct dvb_usb_device *d, u16 nb_ts_packets)
        int ret;
 
        if (st->fw_version >= 0x10201) {
+               if (mutex_lock_interruptible(&d->usb_mutex) < 0) {
+                       err("could not acquire lock");
+                       return 0;
+               }
+
                st->buf[0] = REQUEST_SET_USB_XFER_LEN;
                st->buf[1] = (nb_ts_packets >> 8) & 0xff;
                st->buf[2] = nb_ts_packets & 0xff;
@@ -132,6 +149,7 @@ static int dib0700_set_usb_xfer_len(struct dvb_usb_device *d, u16 nb_ts_packets)
                deb_info("set the USB xfer len to %i Ts packet\n", nb_ts_packets);
 
                ret = dib0700_ctrl_wr(d, st->buf, 3);
+               mutex_unlock(&d->usb_mutex);
        } else {
                deb_info("this firmware does not allow to change the USB xfer len\n");
                ret = -EIO;
@@ -208,6 +226,10 @@ static int dib0700_i2c_xfer_new(struct i2c_adapter *adap, struct i2c_msg *msg,
 
                } else {
                        /* Write request */
+                       if (mutex_lock_interruptible(&d->usb_mutex) < 0) {
+                               err("could not acquire lock");
+                               return 0;
+                       }
                        st->buf[0] = REQUEST_NEW_I2C_WRITE;
                        st->buf[1] = msg[i].addr << 1;
                        st->buf[2] = (en_start << 7) | (en_stop << 6) |
@@ -227,6 +249,7 @@ static int dib0700_i2c_xfer_new(struct i2c_adapter *adap, struct i2c_msg *msg,
                                                 USB_TYPE_VENDOR | USB_DIR_OUT,
                                                 0, 0, st->buf, msg[i].len + 4,
                                                 USB_CTRL_GET_TIMEOUT);
+                       mutex_unlock(&d->usb_mutex);
                        if (result < 0) {
                                deb_info("i2c write error (status = %d)\n", result);
                                break;
@@ -249,6 +272,10 @@ static int dib0700_i2c_xfer_legacy(struct i2c_adapter *adap,
 
        if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
                return -EAGAIN;
+       if (mutex_lock_interruptible(&d->usb_mutex) < 0) {
+               err("could not acquire lock");
+               return 0;
+       }
 
        for (i = 0; i < num; i++) {
                /* fill in the address */
@@ -279,6 +306,7 @@ static int dib0700_i2c_xfer_legacy(struct i2c_adapter *adap,
                                break;
                }
        }
+       mutex_unlock(&d->usb_mutex);
        mutex_unlock(&d->i2c_mutex);
 
        return i;
@@ -337,7 +365,12 @@ static int dib0700_set_clock(struct dvb_usb_device *d, u8 en_pll,
        u16 pll_loopdiv, u16 free_div, u16 dsuScaler)
 {
        struct dib0700_state *st = d->priv;
-       s16 ret;
+       int ret;
+
+       if (mutex_lock_interruptible(&d->usb_mutex) < 0) {
+               err("could not acquire lock");
+               return 0;
+       }
 
        st->buf[0] = REQUEST_SET_CLOCK;
        st->buf[1] = (en_pll << 7) | (pll_src << 6) |
@@ -352,6 +385,7 @@ static int dib0700_set_clock(struct dvb_usb_device *d, u8 en_pll,
        st->buf[9] =  dsuScaler         & 0xff; /* LSB */
 
        ret = dib0700_ctrl_wr(d, st->buf, 10);
+       mutex_unlock(&d->usb_mutex);
 
        return ret;
 }
@@ -360,10 +394,16 @@ int dib0700_set_i2c_speed(struct dvb_usb_device *d, u16 scl_kHz)
 {
        struct dib0700_state *st = d->priv;
        u16 divider;
+       int ret;
 
        if (scl_kHz == 0)
                return -EINVAL;
 
+       if (mutex_lock_interruptible(&d->usb_mutex) < 0) {
+               err("could not acquire lock");
+               return 0;
+       }
+
        st->buf[0] = REQUEST_SET_I2C_PARAM;
        divider = (u16) (30000 / scl_kHz);
        st->buf[1] = 0;
@@ -379,7 +419,11 @@ int dib0700_set_i2c_speed(struct dvb_usb_device *d, u16 scl_kHz)
        deb_info("setting I2C speed: %04x %04x %04x (%d kHz).",
                (st->buf[2] << 8) | (st->buf[3]), (st->buf[4] << 8) |
                st->buf[5], (st->buf[6] << 8) | st->buf[7], scl_kHz);
-       return dib0700_ctrl_wr(d, st->buf, 8);
+
+       ret = dib0700_ctrl_wr(d, st->buf, 8);
+       mutex_unlock(&d->usb_mutex);
+
+       return ret;
 }
 
 
@@ -484,13 +528,13 @@ int dib0700_download_firmware(struct usb_device *udev, const struct firmware *fw
                for (adap_num = 0; adap_num < dib0700_devices[i].num_adapters;
                                adap_num++) {
                        if (fw_version >= 0x10201) {
-                               dib0700_devices[i].adapter[adap_num].stream.u.bulk.buffersize = 188*nb_packet_buffer_size;
+                               dib0700_devices[i].adapter[adap_num].fe[0].stream.u.bulk.buffersize = 188*nb_packet_buffer_size;
                        } else {
                                /* for fw version older than 1.20.1,
                                 * the buffersize has to be n times 512 */
-                               dib0700_devices[i].adapter[adap_num].stream.u.bulk.buffersize = ((188*nb_packet_buffer_size+188/2)/512)*512;
-                               if (dib0700_devices[i].adapter[adap_num].stream.u.bulk.buffersize < 512)
-                                       dib0700_devices[i].adapter[adap_num].stream.u.bulk.buffersize = 512;
+                               dib0700_devices[i].adapter[adap_num].fe[0].stream.u.bulk.buffersize = ((188*nb_packet_buffer_size+188/2)/512)*512;
+                               if (dib0700_devices[i].adapter[adap_num].fe[0].stream.u.bulk.buffersize < 512)
+                                       dib0700_devices[i].adapter[adap_num].fe[0].stream.u.bulk.buffersize = 512;
                        }
                }
        }
@@ -515,6 +559,11 @@ int dib0700_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
                }
        }
 
+       if (mutex_lock_interruptible(&adap->dev->usb_mutex) < 0) {
+               err("could not acquire lock");
+               return 0;
+       }
+
        st->buf[0] = REQUEST_ENABLE_VIDEO;
        /* this bit gives a kind of command,
         * rather than enabling something or not */
@@ -530,25 +579,28 @@ int dib0700_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
        deb_info("modifying (%d) streaming state for %d\n", onoff, adap->id);
 
        st->channel_state &= ~0x3;
-       if ((adap->stream.props.endpoint != 2)
-                       && (adap->stream.props.endpoint != 3)) {
-               deb_info("the endpoint number (%i) is not correct, use the adapter id instead", adap->stream.props.endpoint);
+       if ((adap->fe_adap[0].stream.props.endpoint != 2)
+                       && (adap->fe_adap[0].stream.props.endpoint != 3)) {
+               deb_info("the endpoint number (%i) is not correct, use the adapter id instead", adap->fe_adap[0].stream.props.endpoint);
                if (onoff)
                        st->channel_state |=    1 << (adap->id);
                else
                        st->channel_state |=    1 << ~(adap->id);
        } else {
                if (onoff)
-                       st->channel_state |=    1 << (adap->stream.props.endpoint-2);
+                       st->channel_state |=    1 << (adap->fe_adap[0].stream.props.endpoint-2);
                else
-                       st->channel_state |=    1 << (3-adap->stream.props.endpoint);
+                       st->channel_state |=    1 << (3-adap->fe_adap[0].stream.props.endpoint);
        }
 
        st->buf[2] |= st->channel_state;
 
        deb_info("data for streaming: %x %x\n", st->buf[1], st->buf[2]);
 
-       return dib0700_ctrl_wr(adap->dev, st->buf, 4);
+       ret = dib0700_ctrl_wr(adap->dev, st->buf, 4);
+       mutex_unlock(&adap->dev->usb_mutex);
+
+       return ret;
 }
 
 int dib0700_change_protocol(struct rc_dev *rc, u64 rc_type)
@@ -557,6 +609,11 @@ int dib0700_change_protocol(struct rc_dev *rc, u64 rc_type)
        struct dib0700_state *st = d->priv;
        int new_proto, ret;
 
+       if (mutex_lock_interruptible(&d->usb_mutex) < 0) {
+               err("could not acquire lock");
+               return 0;
+       }
+
        st->buf[0] = REQUEST_SET_RC;
        st->buf[1] = 0;
        st->buf[2] = 0;
@@ -567,23 +624,29 @@ int dib0700_change_protocol(struct rc_dev *rc, u64 rc_type)
        else if (rc_type == RC_TYPE_NEC)
                new_proto = 0;
        else if (rc_type == RC_TYPE_RC6) {
-               if (st->fw_version < 0x10200)
-                       return -EINVAL;
+               if (st->fw_version < 0x10200) {
+                       ret = -EINVAL;
+                       goto out;
+               }
 
                new_proto = 2;
-       } else
-               return -EINVAL;
+       } else {
+               ret = -EINVAL;
+               goto out;
+       }
 
        st->buf[1] = new_proto;
 
        ret = dib0700_ctrl_wr(d, st->buf, 3);
        if (ret < 0) {
                err("ir protocol setup failed");
-               return ret;
+               goto out;
        }
 
        d->props.rc.core.protocol = rc_type;
 
+out:
+       mutex_unlock(&d->usb_mutex);
        return ret;
 }
 
index d0ea5b64f6b4e10f6e028b99915d3100c94d61a3..f313182eb9d5ed0f2b9ff7fd6f248c9f4f98df7a 100644 (file)
@@ -101,7 +101,7 @@ static int bristol_frontend_attach(struct dvb_usb_adapter *adap)
                }
        }
        st->mt2060_if1[adap->id] = 1220;
-       return (adap->fe = dvb_attach(dib3000mc_attach, &adap->dev->i2c_adap,
+       return (adap->fe_adap[0].fe = dvb_attach(dib3000mc_attach, &adap->dev->i2c_adap,
                (10 + adap->id) << 1, &bristol_dib3000mc_config[adap->id])) == NULL ? -ENODEV : 0;
 }
 
@@ -118,15 +118,16 @@ static int eeprom_read(struct i2c_adapter *adap,u8 adrs,u8 *pval)
 static int bristol_tuner_attach(struct dvb_usb_adapter *adap)
 {
        struct i2c_adapter *prim_i2c = &adap->dev->i2c_adap;
-       struct i2c_adapter *tun_i2c = dib3000mc_get_tuner_i2c_master(adap->fe, 1);
+       struct i2c_adapter *tun_i2c = dib3000mc_get_tuner_i2c_master(adap->fe_adap[0].fe, 1);
        s8 a;
        int if1=1220;
        if (adap->dev->udev->descriptor.idVendor  == cpu_to_le16(USB_VID_HAUPPAUGE) &&
                adap->dev->udev->descriptor.idProduct == cpu_to_le16(USB_PID_HAUPPAUGE_NOVA_T_500_2)) {
                if (!eeprom_read(prim_i2c,0x59 + adap->id,&a)) if1=1220+a;
        }
-       return dvb_attach(mt2060_attach,adap->fe, tun_i2c,&bristol_mt2060_config[adap->id],
-               if1) == NULL ? -ENODEV : 0;
+       return dvb_attach(mt2060_attach, adap->fe_adap[0].fe, tun_i2c,
+                         &bristol_mt2060_config[adap->id], if1) == NULL ?
+                         -ENODEV : 0;
 }
 
 /* STK7700D: Pinnacle/Terratec/Hauppauge Dual DVB-T Diversity */
@@ -279,10 +280,12 @@ static int stk7700P2_frontend_attach(struct dvb_usb_adapter *adap)
                }
        }
 
-       adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap,0x80+(adap->id << 1),
-                               &stk7700d_dib7000p_mt2266_config[adap->id]);
+       adap->fe_adap[0].fe =
+               dvb_attach(dib7000p_attach, &adap->dev->i2c_adap,
+                          0x80 + (adap->id << 1),
+                          &stk7700d_dib7000p_mt2266_config[adap->id]);
 
-       return adap->fe == NULL ? -ENODEV : 0;
+       return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
 }
 
 static int stk7700d_frontend_attach(struct dvb_usb_adapter *adap)
@@ -306,17 +309,19 @@ static int stk7700d_frontend_attach(struct dvb_usb_adapter *adap)
                }
        }
 
-       adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap,0x80+(adap->id << 1),
-                               &stk7700d_dib7000p_mt2266_config[adap->id]);
+       adap->fe_adap[0].fe =
+               dvb_attach(dib7000p_attach, &adap->dev->i2c_adap,
+                          0x80 + (adap->id << 1),
+                          &stk7700d_dib7000p_mt2266_config[adap->id]);
 
-       return adap->fe == NULL ? -ENODEV : 0;
+       return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
 }
 
 static int stk7700d_tuner_attach(struct dvb_usb_adapter *adap)
 {
        struct i2c_adapter *tun_i2c;
-       tun_i2c = dib7000p_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_TUNER, 1);
-       return dvb_attach(mt2266_attach, adap->fe, tun_i2c,
+       tun_i2c = dib7000p_get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_TUNER, 1);
+       return dvb_attach(mt2266_attach, adap->fe_adap[0].fe, tun_i2c,
                &stk7700d_mt2266_config[adap->id]) == NULL ? -ENODEV : 0;
 }
 
@@ -396,8 +401,8 @@ static int stk7700ph_xc3028_callback(void *ptr, int component,
        switch (command) {
        case XC2028_TUNER_RESET:
                /* Send the tuner in then out of reset */
-               dib7000p_set_gpio(adap->fe, 8, 0, 0); msleep(10);
-               dib7000p_set_gpio(adap->fe, 8, 0, 1);
+               dib7000p_set_gpio(adap->fe_adap[0].fe, 8, 0, 0); msleep(10);
+               dib7000p_set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
                break;
        case XC2028_RESET_CLK:
                break;
@@ -447,25 +452,25 @@ static int stk7700ph_frontend_attach(struct dvb_usb_adapter *adap)
                return -ENODEV;
        }
 
-       adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80,
+       adap->fe_adap[0].fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80,
                &stk7700ph_dib7700_xc3028_config);
 
-       return adap->fe == NULL ? -ENODEV : 0;
+       return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
 }
 
 static int stk7700ph_tuner_attach(struct dvb_usb_adapter *adap)
 {
        struct i2c_adapter *tun_i2c;
 
-       tun_i2c = dib7000p_get_i2c_master(adap->fe,
+       tun_i2c = dib7000p_get_i2c_master(adap->fe_adap[0].fe,
                DIBX000_I2C_INTERFACE_TUNER, 1);
 
        stk7700ph_xc3028_config.i2c_adap = tun_i2c;
 
        /* FIXME: generalize & move to common area */
-       adap->fe->callback = stk7700ph_xc3028_callback;
+       adap->fe_adap[0].fe->callback = stk7700ph_xc3028_callback;
 
-       return dvb_attach(xc2028_attach, adap->fe, &stk7700ph_xc3028_config)
+       return dvb_attach(xc2028_attach, adap->fe_adap[0].fe, &stk7700ph_xc3028_config)
                == NULL ? -ENODEV : 0;
 }
 
@@ -685,12 +690,12 @@ static int stk7700p_frontend_attach(struct dvb_usb_adapter *adap)
        st->mt2060_if1[0] = 1220;
 
        if (dib7000pc_detection(&adap->dev->i2c_adap)) {
-               adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 18, &stk7700p_dib7000p_config);
+               adap->fe_adap[0].fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 18, &stk7700p_dib7000p_config);
                st->is_dib7000pc = 1;
        } else
-               adap->fe = dvb_attach(dib7000m_attach, &adap->dev->i2c_adap, 18, &stk7700p_dib7000m_config);
+               adap->fe_adap[0].fe = dvb_attach(dib7000m_attach, &adap->dev->i2c_adap, 18, &stk7700p_dib7000m_config);
 
-       return adap->fe == NULL ? -ENODEV : 0;
+       return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
 }
 
 static struct mt2060_config stk7700p_mt2060_config = {
@@ -709,11 +714,11 @@ static int stk7700p_tuner_attach(struct dvb_usb_adapter *adap)
                if (!eeprom_read(prim_i2c,0x58,&a)) if1=1220+a;
        }
        if (st->is_dib7000pc)
-               tun_i2c = dib7000p_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_TUNER, 1);
+               tun_i2c = dib7000p_get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_TUNER, 1);
        else
-               tun_i2c = dib7000m_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_TUNER, 1);
+               tun_i2c = dib7000m_get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_TUNER, 1);
 
-       return dvb_attach(mt2060_attach, adap->fe, tun_i2c, &stk7700p_mt2060_config,
+       return dvb_attach(mt2060_attach, adap->fe_adap[0].fe, tun_i2c, &stk7700p_mt2060_config,
                if1) == NULL ? -ENODEV : 0;
 }
 
@@ -843,33 +848,33 @@ static int dib7770_set_param_override(struct dvb_frontend *fe,
 static int dib7770p_tuner_attach(struct dvb_usb_adapter *adap)
 {
         struct dib0700_adapter_state *st = adap->priv;
-        struct i2c_adapter *tun_i2c = dib7000p_get_i2c_master(adap->fe,
+        struct i2c_adapter *tun_i2c = dib7000p_get_i2c_master(adap->fe_adap[0].fe,
                         DIBX000_I2C_INTERFACE_TUNER, 1);
 
-        if (dvb_attach(dib0070_attach, adap->fe, tun_i2c,
-                                &dib7770p_dib0070_config) == NULL)
+        if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c,
+                       &dib7770p_dib0070_config) == NULL)
                 return -ENODEV;
 
-        st->set_param_save = adap->fe->ops.tuner_ops.set_params;
-        adap->fe->ops.tuner_ops.set_params = dib7770_set_param_override;
+        st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
+        adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7770_set_param_override;
         return 0;
 }
 
 static int dib7070p_tuner_attach(struct dvb_usb_adapter *adap)
 {
        struct dib0700_adapter_state *st = adap->priv;
-       struct i2c_adapter *tun_i2c = dib7000p_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_TUNER, 1);
+       struct i2c_adapter *tun_i2c = dib7000p_get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_TUNER, 1);
 
        if (adap->id == 0) {
-               if (dvb_attach(dib0070_attach, adap->fe, tun_i2c, &dib7070p_dib0070_config[0]) == NULL)
+               if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c, &dib7070p_dib0070_config[0]) == NULL)
                        return -ENODEV;
        } else {
-               if (dvb_attach(dib0070_attach, adap->fe, tun_i2c, &dib7070p_dib0070_config[1]) == NULL)
+               if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c, &dib7070p_dib0070_config[1]) == NULL)
                        return -ENODEV;
        }
 
-       st->set_param_save = adap->fe->ops.tuner_ops.set_params;
-       adap->fe->ops.tuner_ops.set_params = dib7070_set_param_override;
+       st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
+       adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7070_set_param_override;
        return 0;
 }
 
@@ -878,26 +883,26 @@ static int stk7700p_pid_filter(struct dvb_usb_adapter *adapter, int index,
 {
        struct dib0700_state *st = adapter->dev->priv;
        if (st->is_dib7000pc)
-               return dib7000p_pid_filter(adapter->fe, index, pid, onoff);
-       return dib7000m_pid_filter(adapter->fe, index, pid, onoff);
+               return dib7000p_pid_filter(adapter->fe_adap[0].fe, index, pid, onoff);
+       return dib7000m_pid_filter(adapter->fe_adap[0].fe, index, pid, onoff);
 }
 
 static int stk7700p_pid_filter_ctrl(struct dvb_usb_adapter *adapter, int onoff)
 {
        struct dib0700_state *st = adapter->dev->priv;
        if (st->is_dib7000pc)
-               return dib7000p_pid_filter_ctrl(adapter->fe, onoff);
-       return dib7000m_pid_filter_ctrl(adapter->fe, onoff);
+               return dib7000p_pid_filter_ctrl(adapter->fe_adap[0].fe, onoff);
+       return dib7000m_pid_filter_ctrl(adapter->fe_adap[0].fe, onoff);
 }
 
 static int stk70x0p_pid_filter(struct dvb_usb_adapter *adapter, int index, u16 pid, int onoff)
 {
-    return dib7000p_pid_filter(adapter->fe, index, pid, onoff);
+       return dib7000p_pid_filter(adapter->fe_adap[0].fe, index, pid, onoff);
 }
 
 static int stk70x0p_pid_filter_ctrl(struct dvb_usb_adapter *adapter, int onoff)
 {
-    return dib7000p_pid_filter_ctrl(adapter->fe, onoff);
+       return dib7000p_pid_filter_ctrl(adapter->fe_adap[0].fe, onoff);
 }
 
 static struct dibx000_bandwidth_config dib7070_bw_config_12_mhz = {
@@ -955,9 +960,9 @@ static int stk7070p_frontend_attach(struct dvb_usb_adapter *adap)
                return -ENODEV;
        }
 
-       adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80,
+       adap->fe_adap[0].fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80,
                &dib7070p_dib7000p_config);
-       return adap->fe == NULL ? -ENODEV : 0;
+       return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
 }
 
 /* STK7770P */
@@ -1007,9 +1012,9 @@ static int stk7770p_frontend_attach(struct dvb_usb_adapter *adap)
                return -ENODEV;
        }
 
-       adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80,
+       adap->fe_adap[0].fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80,
                &dib7770p_dib7000p_config);
-       return adap->fe == NULL ? -ENODEV : 0;
+       return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
 }
 
 /* DIB807x generic */
@@ -1225,34 +1230,34 @@ static int dib807x_set_param_override(struct dvb_frontend *fe,
 static int dib807x_tuner_attach(struct dvb_usb_adapter *adap)
 {
        struct dib0700_adapter_state *st = adap->priv;
-       struct i2c_adapter *tun_i2c = dib8000_get_i2c_master(adap->fe,
+       struct i2c_adapter *tun_i2c = dib8000_get_i2c_master(adap->fe_adap[0].fe,
                        DIBX000_I2C_INTERFACE_TUNER, 1);
 
        if (adap->id == 0) {
-               if (dvb_attach(dib0070_attach, adap->fe, tun_i2c,
+               if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c,
                                &dib807x_dib0070_config[0]) == NULL)
                        return -ENODEV;
        } else {
-               if (dvb_attach(dib0070_attach, adap->fe, tun_i2c,
+               if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c,
                                &dib807x_dib0070_config[1]) == NULL)
                        return -ENODEV;
        }
 
-       st->set_param_save = adap->fe->ops.tuner_ops.set_params;
-       adap->fe->ops.tuner_ops.set_params = dib807x_set_param_override;
+       st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
+       adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib807x_set_param_override;
        return 0;
 }
 
 static int stk80xx_pid_filter(struct dvb_usb_adapter *adapter, int index,
        u16 pid, int onoff)
 {
-       return dib8000_pid_filter(adapter->fe, index, pid, onoff);
+       return dib8000_pid_filter(adapter->fe_adap[0].fe, index, pid, onoff);
 }
 
 static int stk80xx_pid_filter_ctrl(struct dvb_usb_adapter *adapter,
                int onoff)
 {
-       return dib8000_pid_filter_ctrl(adapter->fe, onoff);
+       return dib8000_pid_filter_ctrl(adapter->fe_adap[0].fe, onoff);
 }
 
 /* STK807x */
@@ -1276,10 +1281,10 @@ static int stk807x_frontend_attach(struct dvb_usb_adapter *adap)
        dib8000_i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
                                0x80);
 
-       adap->fe = dvb_attach(dib8000_attach, &adap->dev->i2c_adap, 0x80,
+       adap->fe_adap[0].fe = dvb_attach(dib8000_attach, &adap->dev->i2c_adap, 0x80,
                              &dib807x_dib8000_config[0]);
 
-       return adap->fe == NULL ?  -ENODEV : 0;
+       return adap->fe_adap[0].fe == NULL ?  -ENODEV : 0;
 }
 
 /* STK807xPVR */
@@ -1305,10 +1310,10 @@ static int stk807xpvr_frontend_attach0(struct dvb_usb_adapter *adap)
        /* initialize IC 0 */
        dib8000_i2c_enumeration(&adap->dev->i2c_adap, 1, 0x22, 0x80);
 
-       adap->fe = dvb_attach(dib8000_attach, &adap->dev->i2c_adap, 0x80,
+       adap->fe_adap[0].fe = dvb_attach(dib8000_attach, &adap->dev->i2c_adap, 0x80,
                              &dib807x_dib8000_config[0]);
 
-       return adap->fe == NULL ? -ENODEV : 0;
+       return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
 }
 
 static int stk807xpvr_frontend_attach1(struct dvb_usb_adapter *adap)
@@ -1316,10 +1321,10 @@ static int stk807xpvr_frontend_attach1(struct dvb_usb_adapter *adap)
        /* initialize IC 1 */
        dib8000_i2c_enumeration(&adap->dev->i2c_adap, 1, 0x12, 0x82);
 
-       adap->fe = dvb_attach(dib8000_attach, &adap->dev->i2c_adap, 0x82,
+       adap->fe_adap[0].fe = dvb_attach(dib8000_attach, &adap->dev->i2c_adap, 0x82,
                              &dib807x_dib8000_config[1]);
 
-       return adap->fe == NULL ? -ENODEV : 0;
+       return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
 }
 
 /* STK8096GP */
@@ -1546,13 +1551,13 @@ static int dib8096_set_param_override(struct dvb_frontend *fe,
 static int dib809x_tuner_attach(struct dvb_usb_adapter *adap)
 {
        struct dib0700_adapter_state *st = adap->priv;
-       struct i2c_adapter *tun_i2c = dib8000_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_TUNER, 1);
+       struct i2c_adapter *tun_i2c = dib8000_get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_TUNER, 1);
 
-       if (dvb_attach(dib0090_register, adap->fe, tun_i2c, &dib809x_dib0090_config) == NULL)
+       if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c, &dib809x_dib0090_config) == NULL)
                return -ENODEV;
 
-       st->set_param_save = adap->fe->ops.tuner_ops.set_params;
-       adap->fe->ops.tuner_ops.set_params = dib8096_set_param_override;
+       st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
+       adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib8096_set_param_override;
        return 0;
 }
 
@@ -1575,30 +1580,30 @@ static int stk809x_frontend_attach(struct dvb_usb_adapter *adap)
 
        dib8000_i2c_enumeration(&adap->dev->i2c_adap, 1, 18, 0x80);
 
-       adap->fe = dvb_attach(dib8000_attach, &adap->dev->i2c_adap, 0x80, &dib809x_dib8000_config[0]);
+       adap->fe_adap[0].fe = dvb_attach(dib8000_attach, &adap->dev->i2c_adap, 0x80, &dib809x_dib8000_config[0]);
 
-       return adap->fe == NULL ?  -ENODEV : 0;
+       return adap->fe_adap[0].fe == NULL ?  -ENODEV : 0;
 }
 
 static int nim8096md_tuner_attach(struct dvb_usb_adapter *adap)
 {
        struct dib0700_adapter_state *st = adap->priv;
        struct i2c_adapter *tun_i2c;
-       struct dvb_frontend *fe_slave  = dib8000_get_slave_frontend(adap->fe, 1);
+       struct dvb_frontend *fe_slave  = dib8000_get_slave_frontend(adap->fe_adap[0].fe, 1);
 
        if (fe_slave) {
                tun_i2c = dib8000_get_i2c_master(fe_slave, DIBX000_I2C_INTERFACE_TUNER, 1);
                if (dvb_attach(dib0090_register, fe_slave, tun_i2c, &dib809x_dib0090_config) == NULL)
                        return -ENODEV;
-               fe_slave->dvb = adap->fe->dvb;
+               fe_slave->dvb = adap->fe_adap[0].fe->dvb;
                fe_slave->ops.tuner_ops.set_params = dib8096_set_param_override;
        }
-       tun_i2c = dib8000_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_TUNER, 1);
-       if (dvb_attach(dib0090_register, adap->fe, tun_i2c, &dib809x_dib0090_config) == NULL)
+       tun_i2c = dib8000_get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_TUNER, 1);
+       if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c, &dib809x_dib0090_config) == NULL)
                return -ENODEV;
 
-       st->set_param_save = adap->fe->ops.tuner_ops.set_params;
-       adap->fe->ops.tuner_ops.set_params = dib8096_set_param_override;
+       st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
+       adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib8096_set_param_override;
 
        return 0;
 }
@@ -1626,12 +1631,12 @@ static int nim8096md_frontend_attach(struct dvb_usb_adapter *adap)
 
        dib8000_i2c_enumeration(&adap->dev->i2c_adap, 2, 18, 0x80);
 
-       adap->fe = dvb_attach(dib8000_attach, &adap->dev->i2c_adap, 0x80, &dib809x_dib8000_config[0]);
-       if (adap->fe == NULL)
+       adap->fe_adap[0].fe = dvb_attach(dib8000_attach, &adap->dev->i2c_adap, 0x80, &dib809x_dib8000_config[0]);
+       if (adap->fe_adap[0].fe == NULL)
                return -ENODEV;
 
        fe_slave = dvb_attach(dib8000_attach, &adap->dev->i2c_adap, 0x82, &dib809x_dib8000_config[1]);
-       dib8000_set_slave_frontend(adap->fe, fe_slave);
+       dib8000_set_slave_frontend(adap->fe_adap[0].fe, fe_slave);
 
        return fe_slave == NULL ?  -ENODEV : 0;
 }
@@ -1639,12 +1644,12 @@ static int nim8096md_frontend_attach(struct dvb_usb_adapter *adap)
 /* STK9090M */
 static int dib90x0_pid_filter(struct dvb_usb_adapter *adapter, int index, u16 pid, int onoff)
 {
-       return dib9000_fw_pid_filter(adapter->fe, index, pid, onoff);
+       return dib9000_fw_pid_filter(adapter->fe_adap[0].fe, index, pid, onoff);
 }
 
 static int dib90x0_pid_filter_ctrl(struct dvb_usb_adapter *adapter, int onoff)
 {
-       return dib9000_fw_pid_filter_ctrl(adapter->fe, onoff);
+       return dib9000_fw_pid_filter_ctrl(adapter->fe_adap[0].fe, onoff);
 }
 
 static int dib90x0_tuner_reset(struct dvb_frontend *fe, int onoff)
@@ -1856,15 +1861,15 @@ static int stk9090m_frontend_attach(struct dvb_usb_adapter *adap)
        stk9090m_config.microcode_B_fe_size = state->frontend_firmware->size;
        stk9090m_config.microcode_B_fe_buffer = state->frontend_firmware->data;
 
-       adap->fe = dvb_attach(dib9000_attach, &adap->dev->i2c_adap, 0x80, &stk9090m_config);
+       adap->fe_adap[0].fe = dvb_attach(dib9000_attach, &adap->dev->i2c_adap, 0x80, &stk9090m_config);
 
-       return adap->fe == NULL ?  -ENODEV : 0;
+       return adap->fe_adap[0].fe == NULL ?  -ENODEV : 0;
 }
 
 static int dib9090_tuner_attach(struct dvb_usb_adapter *adap)
 {
        struct dib0700_adapter_state *state = adap->priv;
-       struct i2c_adapter *i2c = dib9000_get_tuner_interface(adap->fe);
+       struct i2c_adapter *i2c = dib9000_get_tuner_interface(adap->fe_adap[0].fe);
        u16 data_dib190[10] = {
                1, 0x1374,
                2, 0x01a2,
@@ -1873,13 +1878,13 @@ static int dib9090_tuner_attach(struct dvb_usb_adapter *adap)
                8, 0x0486,
        };
 
-       if (dvb_attach(dib0090_fw_register, adap->fe, i2c, &dib9090_dib0090_config) == NULL)
+       if (dvb_attach(dib0090_fw_register, adap->fe_adap[0].fe, i2c, &dib9090_dib0090_config) == NULL)
                return -ENODEV;
-       i2c = dib9000_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_GPIO_1_2, 0);
+       i2c = dib9000_get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_GPIO_1_2, 0);
        if (dib01x0_pmu_update(i2c, data_dib190, 10) != 0)
                return -ENODEV;
        dib0700_set_i2c_speed(adap->dev, 2000);
-       if (dib9000_firmware_post_pll_init(adap->fe) < 0)
+       if (dib9000_firmware_post_pll_init(adap->fe_adap[0].fe) < 0)
                return -ENODEV;
        release_firmware(state->frontend_firmware);
        return 0;
@@ -1925,16 +1930,16 @@ static int nim9090md_frontend_attach(struct dvb_usb_adapter *adap)
        nim9090md_config[1].microcode_B_fe_buffer = state->frontend_firmware->data;
 
        dib9000_i2c_enumeration(&adap->dev->i2c_adap, 1, 0x20, 0x80);
-       adap->fe = dvb_attach(dib9000_attach, &adap->dev->i2c_adap, 0x80, &nim9090md_config[0]);
+       adap->fe_adap[0].fe = dvb_attach(dib9000_attach, &adap->dev->i2c_adap, 0x80, &nim9090md_config[0]);
 
-       if (adap->fe == NULL)
+       if (adap->fe_adap[0].fe == NULL)
                return -ENODEV;
 
-       i2c = dib9000_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_GPIO_3_4, 0);
+       i2c = dib9000_get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_GPIO_3_4, 0);
        dib9000_i2c_enumeration(i2c, 1, 0x12, 0x82);
 
        fe_slave = dvb_attach(dib9000_attach, i2c, 0x82, &nim9090md_config[1]);
-       dib9000_set_slave_frontend(adap->fe, fe_slave);
+       dib9000_set_slave_frontend(adap->fe_adap[0].fe, fe_slave);
 
        return fe_slave == NULL ?  -ENODEV : 0;
 }
@@ -1951,26 +1956,26 @@ static int nim9090md_tuner_attach(struct dvb_usb_adapter *adap)
                0, 0x00ef,
                8, 0x0406,
        };
-       i2c = dib9000_get_tuner_interface(adap->fe);
-       if (dvb_attach(dib0090_fw_register, adap->fe, i2c, &nim9090md_dib0090_config[0]) == NULL)
+       i2c = dib9000_get_tuner_interface(adap->fe_adap[0].fe);
+       if (dvb_attach(dib0090_fw_register, adap->fe_adap[0].fe, i2c, &nim9090md_dib0090_config[0]) == NULL)
                return -ENODEV;
-       i2c = dib9000_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_GPIO_1_2, 0);
+       i2c = dib9000_get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_GPIO_1_2, 0);
        if (dib01x0_pmu_update(i2c, data_dib190, 10) < 0)
                return -ENODEV;
        dib0700_set_i2c_speed(adap->dev, 2000);
-       if (dib9000_firmware_post_pll_init(adap->fe) < 0)
+       if (dib9000_firmware_post_pll_init(adap->fe_adap[0].fe) < 0)
                return -ENODEV;
 
-       fe_slave = dib9000_get_slave_frontend(adap->fe, 1);
+       fe_slave = dib9000_get_slave_frontend(adap->fe_adap[0].fe, 1);
        if (fe_slave != NULL) {
-               i2c = dib9000_get_component_bus_interface(adap->fe);
+               i2c = dib9000_get_component_bus_interface(adap->fe_adap[0].fe);
                dib9000_set_i2c_adapter(fe_slave, i2c);
 
                i2c = dib9000_get_tuner_interface(fe_slave);
                if (dvb_attach(dib0090_fw_register, fe_slave, i2c, &nim9090md_dib0090_config[1]) == NULL)
                        return -ENODEV;
-               fe_slave->dvb = adap->fe->dvb;
-               dib9000_fw_set_component_bus_speed(adap->fe, 2000);
+               fe_slave->dvb = adap->fe_adap[0].fe->dvb;
+               dib9000_fw_set_component_bus_speed(adap->fe_adap[0].fe, 2000);
                if (dib9000_firmware_post_pll_init(fe_slave) < 0)
                        return -ENODEV;
        }
@@ -2393,23 +2398,23 @@ static int nim7090_frontend_attach(struct dvb_usb_adapter *adap)
                err("%s: dib7000p_i2c_enumeration failed.  Cannot continue\n", __func__);
                return -ENODEV;
        }
-       adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80, &nim7090_dib7000p_config);
+       adap->fe_adap[0].fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80, &nim7090_dib7000p_config);
 
-       return adap->fe == NULL ?  -ENODEV : 0;
+       return adap->fe_adap[0].fe == NULL ?  -ENODEV : 0;
 }
 
 static int nim7090_tuner_attach(struct dvb_usb_adapter *adap)
 {
        struct dib0700_adapter_state *st = adap->priv;
-       struct i2c_adapter *tun_i2c = dib7090_get_i2c_tuner(adap->fe);
+       struct i2c_adapter *tun_i2c = dib7090_get_i2c_tuner(adap->fe_adap[0].fe);
 
-       if (dvb_attach(dib0090_register, adap->fe, tun_i2c, &nim7090_dib0090_config) == NULL)
+       if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c, &nim7090_dib0090_config) == NULL)
                return -ENODEV;
 
-       dib7000p_set_gpio(adap->fe, 8, 0, 1);
+       dib7000p_set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
 
-       st->set_param_save = adap->fe->ops.tuner_ops.set_params;
-       adap->fe->ops.tuner_ops.set_params = dib7090_agc_startup;
+       st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
+       adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7090_agc_startup;
        return 0;
 }
 
@@ -2439,11 +2444,11 @@ static int tfe7090pvr_frontend0_attach(struct dvb_usb_adapter *adap)
        }
 
        dib0700_set_i2c_speed(adap->dev, 340);
-       adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x90, &tfe7090pvr_dib7000p_config[0]);
-       if (adap->fe == NULL)
+       adap->fe_adap[0].fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x90, &tfe7090pvr_dib7000p_config[0]);
+       if (adap->fe_adap[0].fe == NULL)
                return -ENODEV;
 
-       dib7090_slave_reset(adap->fe);
+       dib7090_slave_reset(adap->fe_adap[0].fe);
 
        return 0;
 }
@@ -2452,50 +2457,50 @@ static int tfe7090pvr_frontend1_attach(struct dvb_usb_adapter *adap)
 {
        struct i2c_adapter *i2c;
 
-       if (adap->dev->adapter[0].fe == NULL) {
+       if (adap->dev->adapter[0].fe_adap[0].fe == NULL) {
                err("the master dib7090 has to be initialized first");
                return -ENODEV; /* the master device has not been initialized */
        }
 
-       i2c = dib7000p_get_i2c_master(adap->dev->adapter[0].fe, DIBX000_I2C_INTERFACE_GPIO_6_7, 1);
+       i2c = dib7000p_get_i2c_master(adap->dev->adapter[0].fe_adap[0].fe, DIBX000_I2C_INTERFACE_GPIO_6_7, 1);
        if (dib7000p_i2c_enumeration(i2c, 1, 0x10, &tfe7090pvr_dib7000p_config[1]) != 0) {
                err("%s: dib7000p_i2c_enumeration failed.  Cannot continue\n", __func__);
                return -ENODEV;
        }
 
-       adap->fe = dvb_attach(dib7000p_attach, i2c, 0x92, &tfe7090pvr_dib7000p_config[1]);
+       adap->fe_adap[0].fe = dvb_attach(dib7000p_attach, i2c, 0x92, &tfe7090pvr_dib7000p_config[1]);
        dib0700_set_i2c_speed(adap->dev, 200);
 
-       return adap->fe == NULL ? -ENODEV : 0;
+       return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
 }
 
 static int tfe7090pvr_tuner0_attach(struct dvb_usb_adapter *adap)
 {
        struct dib0700_adapter_state *st = adap->priv;
-       struct i2c_adapter *tun_i2c = dib7090_get_i2c_tuner(adap->fe);
+       struct i2c_adapter *tun_i2c = dib7090_get_i2c_tuner(adap->fe_adap[0].fe);
 
-       if (dvb_attach(dib0090_register, adap->fe, tun_i2c, &tfe7090pvr_dib0090_config[0]) == NULL)
+       if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c, &tfe7090pvr_dib0090_config[0]) == NULL)
                return -ENODEV;
 
-       dib7000p_set_gpio(adap->fe, 8, 0, 1);
+       dib7000p_set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
 
-       st->set_param_save = adap->fe->ops.tuner_ops.set_params;
-       adap->fe->ops.tuner_ops.set_params = dib7090_agc_startup;
+       st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
+       adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7090_agc_startup;
        return 0;
 }
 
 static int tfe7090pvr_tuner1_attach(struct dvb_usb_adapter *adap)
 {
        struct dib0700_adapter_state *st = adap->priv;
-       struct i2c_adapter *tun_i2c = dib7090_get_i2c_tuner(adap->fe);
+       struct i2c_adapter *tun_i2c = dib7090_get_i2c_tuner(adap->fe_adap[0].fe);
 
-       if (dvb_attach(dib0090_register, adap->fe, tun_i2c, &tfe7090pvr_dib0090_config[1]) == NULL)
+       if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c, &tfe7090pvr_dib0090_config[1]) == NULL)
                return -ENODEV;
 
-       dib7000p_set_gpio(adap->fe, 8, 0, 1);
+       dib7000p_set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
 
-       st->set_param_save = adap->fe->ops.tuner_ops.set_params;
-       adap->fe->ops.tuner_ops.set_params = dib7090_agc_startup;
+       st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
+       adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7090_agc_startup;
        return 0;
 }
 
@@ -2555,14 +2560,14 @@ static int stk7070pd_frontend_attach0(struct dvb_usb_adapter *adap)
                return -ENODEV;
        }
 
-       adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80, &stk7070pd_dib7000p_config[0]);
-       return adap->fe == NULL ? -ENODEV : 0;
+       adap->fe_adap[0].fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80, &stk7070pd_dib7000p_config[0]);
+       return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
 }
 
 static int stk7070pd_frontend_attach1(struct dvb_usb_adapter *adap)
 {
-       adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x82, &stk7070pd_dib7000p_config[1]);
-       return adap->fe == NULL ? -ENODEV : 0;
+       adap->fe_adap[0].fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x82, &stk7070pd_dib7000p_config[1]);
+       return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
 }
 
 /* S5H1411 */
@@ -2617,9 +2622,9 @@ static int s5h1411_frontend_attach(struct dvb_usb_adapter *adap)
        dib0700_set_gpio(adap->dev, GPIO2, GPIO_OUT, 1);
 
        /* GPIOs are initialized, do the attach */
-       adap->fe = dvb_attach(s5h1411_attach, &pinnacle_801e_config,
+       adap->fe_adap[0].fe = dvb_attach(s5h1411_attach, &pinnacle_801e_config,
                              &adap->dev->i2c_adap);
-       return adap->fe == NULL ? -ENODEV : 0;
+       return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
 }
 
 static int dib0700_xc5000_tuner_callback(void *priv, int component,
@@ -2649,9 +2654,9 @@ static struct xc5000_config s5h1411_xc5000_tunerconfig = {
 static int xc5000_tuner_attach(struct dvb_usb_adapter *adap)
 {
        /* FIXME: generalize & move to common area */
-       adap->fe->callback = dib0700_xc5000_tuner_callback;
+       adap->fe_adap[0].fe->callback = dib0700_xc5000_tuner_callback;
 
-       return dvb_attach(xc5000_attach, adap->fe, &adap->dev->i2c_adap,
+       return dvb_attach(xc5000_attach, adap->fe_adap[0].fe, &adap->dev->i2c_adap,
                          &s5h1411_xc5000_tunerconfig)
                == NULL ? -ENODEV : 0;
 }
@@ -2663,9 +2668,9 @@ static int dib0700_xc4000_tuner_callback(void *priv, int component,
 
        if (command == XC4000_TUNER_RESET) {
                /* Reset the tuner */
-               dib7000p_set_gpio(adap->fe, 8, 0, 0);
+               dib7000p_set_gpio(adap->fe_adap[0].fe, 8, 0, 0);
                msleep(10);
-               dib7000p_set_gpio(adap->fe, 8, 0, 1);
+               dib7000p_set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
        } else {
                err("xc4000: unknown tuner callback command: %d\n", command);
                return -EINVAL;
@@ -2771,11 +2776,11 @@ static int pctv340e_frontend_attach(struct dvb_usb_adapter *adap)
                return -ENODEV;
        }
 
-       adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x12,
+       adap->fe_adap[0].fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x12,
                              &pctv_340e_config);
        st->is_dib7000pc = 1;
 
-       return adap->fe == NULL ? -ENODEV : 0;
+       return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
 }
 
 static struct xc4000_config dib7000p_xc4000_tunerconfig = {
@@ -2791,7 +2796,7 @@ static int xc4000_tuner_attach(struct dvb_usb_adapter *adap)
        struct i2c_adapter *tun_i2c;
 
        /* The xc4000 is not on the main i2c bus */
-       tun_i2c = dib7000p_get_i2c_master(adap->fe,
+       tun_i2c = dib7000p_get_i2c_master(adap->fe_adap[0].fe,
                                          DIBX000_I2C_INTERFACE_TUNER, 1);
        if (tun_i2c == NULL) {
                printk(KERN_ERR "Could not reach tuner i2c bus\n");
@@ -2799,9 +2804,9 @@ static int xc4000_tuner_attach(struct dvb_usb_adapter *adap)
        }
 
        /* Setup the reset callback */
-       adap->fe->callback = dib0700_xc4000_tuner_callback;
+       adap->fe_adap[0].fe->callback = dib0700_xc4000_tuner_callback;
 
-       return dvb_attach(xc4000_attach, adap->fe, tun_i2c,
+       return dvb_attach(xc4000_attach, adap->fe_adap[0].fe, tun_i2c,
                          &dib7000p_xc4000_tunerconfig)
                == NULL ? -ENODEV : 0;
 }
@@ -2857,16 +2862,16 @@ static int lgdt3305_frontend_attach(struct dvb_usb_adapter *adap)
        dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
        msleep(30);
 
-       adap->fe = dvb_attach(lgdt3305_attach,
+       adap->fe_adap[0].fe = dvb_attach(lgdt3305_attach,
                              &hcw_lgdt3305_config,
                              &adap->dev->i2c_adap);
 
-       return adap->fe == NULL ? -ENODEV : 0;
+       return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
 }
 
 static int mxl5007t_tuner_attach(struct dvb_usb_adapter *adap)
 {
-       return dvb_attach(mxl5007t_attach, adap->fe,
+       return dvb_attach(mxl5007t_attach, adap->fe_adap[0].fe,
                          &adap->dev->i2c_adap, 0x60,
                          &hcw_mxl5007t_config) == NULL ? -ENODEV : 0;
 }
@@ -2989,6 +2994,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                .num_adapters = 1,
                .adapter = {
                        {
+                       .num_frontends = 1,
+                       .fe = {{
                                .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
                                .pid_filter_count = 32,
                                .pid_filter       = stk7700p_pid_filter,
@@ -2997,6 +3004,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                                .tuner_attach     = stk7700p_tuner_attach,
 
                                DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
+                       }},
                        },
                },
 
@@ -3050,15 +3058,21 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                .num_adapters = 2,
                .adapter = {
                        {
+                       .num_frontends = 1,
+                       .fe = {{
                                .frontend_attach  = bristol_frontend_attach,
                                .tuner_attach     = bristol_tuner_attach,
 
                                DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
+                       }},
                        }, {
+                       .num_frontends = 1,
+                       .fe = {{
                                .frontend_attach  = bristol_frontend_attach,
                                .tuner_attach     = bristol_tuner_attach,
 
                                DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
+                       }},
                        }
                },
 
@@ -3084,6 +3098,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                .num_adapters = 2,
                .adapter = {
                        {
+                       .num_frontends = 1,
+                       .fe = {{
                                .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
                                .pid_filter_count = 32,
                                .pid_filter       = stk70x0p_pid_filter,
@@ -3092,7 +3108,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                                .tuner_attach     = stk7700d_tuner_attach,
 
                                DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
+                       }},
                        }, {
+                       .num_frontends = 1,
+                       .fe = {{
                                .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
                                .pid_filter_count = 32,
                                .pid_filter       = stk70x0p_pid_filter,
@@ -3101,6 +3120,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                                .tuner_attach     = stk7700d_tuner_attach,
 
                                DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
+                       }},
                        }
                },
 
@@ -3143,6 +3163,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                .num_adapters = 1,
                .adapter = {
                        {
+                       .num_frontends = 1,
+                       .fe = {{
                                .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
                                .pid_filter_count = 32,
                                .pid_filter       = stk70x0p_pid_filter,
@@ -3151,6 +3173,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                                .tuner_attach     = stk7700d_tuner_attach,
 
                                DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
+                       }},
                        },
                },
 
@@ -3185,6 +3208,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                .num_adapters = 1,
                .adapter = {
                        {
+                       .num_frontends = 1,
+                       .fe = {{
                                .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
                                .pid_filter_count = 32,
                                .pid_filter       = stk70x0p_pid_filter,
@@ -3193,7 +3218,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                                .tuner_attach     = dib7070p_tuner_attach,
 
                                DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
-
+                       }},
                                .size_of_priv     = sizeof(struct dib0700_adapter_state),
                        },
                },
@@ -3261,6 +3286,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                .num_adapters = 1,
                .adapter = {
                        {
+                       .num_frontends = 1,
+                       .fe = {{
                                .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
                                .pid_filter_count = 32,
                                .pid_filter       = stk70x0p_pid_filter,
@@ -3269,7 +3296,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                                .tuner_attach     = dib7070p_tuner_attach,
 
                                DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
-
+                       }},
                                .size_of_priv     = sizeof(struct dib0700_adapter_state),
                        },
                },
@@ -3305,6 +3332,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                .num_adapters = 2,
                .adapter = {
                        {
+                       .num_frontends = 1,
+                       .fe = {{
                                .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
                                .pid_filter_count = 32,
                                .pid_filter       = stk70x0p_pid_filter,
@@ -3313,9 +3342,11 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                                .tuner_attach     = dib7070p_tuner_attach,
 
                                DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
-
+                       }},
                                .size_of_priv     = sizeof(struct dib0700_adapter_state),
                        }, {
+                       .num_frontends = 1,
+                       .fe = {{
                                .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
                                .pid_filter_count = 32,
                                .pid_filter       = stk70x0p_pid_filter,
@@ -3324,7 +3355,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                                .tuner_attach     = dib7070p_tuner_attach,
 
                                DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
-
+                       }},
                                .size_of_priv     = sizeof(struct dib0700_adapter_state),
                        }
                },
@@ -3373,6 +3404,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                .num_adapters = 2,
                .adapter = {
                        {
+                       .num_frontends = 1,
+                       .fe = {{
                                .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
                                .pid_filter_count = 32,
                                .pid_filter       = stk70x0p_pid_filter,
@@ -3381,9 +3414,11 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                                .tuner_attach     = dib7070p_tuner_attach,
 
                                DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
-
+                       }},
                                .size_of_priv     = sizeof(struct dib0700_adapter_state),
                        }, {
+                       .num_frontends = 1,
+                       .fe = {{
                                .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
                                .pid_filter_count = 32,
                                .pid_filter       = stk70x0p_pid_filter,
@@ -3392,7 +3427,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                                .tuner_attach     = dib7070p_tuner_attach,
 
                                DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
-
+                       }},
                                .size_of_priv     = sizeof(struct dib0700_adapter_state),
                        }
                },
@@ -3420,6 +3455,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                .num_adapters = 1,
                .adapter = {
                        {
+                       .num_frontends = 1,
+                       .fe = {{
                                .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
                                .pid_filter_count = 32,
                                .pid_filter       = stk70x0p_pid_filter,
@@ -3428,7 +3465,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                                .tuner_attach     = stk7700ph_tuner_attach,
 
                                DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
-
+                       }},
                                .size_of_priv = sizeof(struct
                                                dib0700_adapter_state),
                        },
@@ -3488,11 +3525,13 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                .num_adapters = 1,
                .adapter = {
                        {
+                       .num_frontends = 1,
+                       .fe = {{
                                .frontend_attach  = s5h1411_frontend_attach,
                                .tuner_attach     = xc5000_tuner_attach,
 
                                DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
-
+                       }},
                                .size_of_priv = sizeof(struct
                                                dib0700_adapter_state),
                        },
@@ -3524,11 +3563,13 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                .num_adapters = 1,
                .adapter = {
                        {
+                       .num_frontends = 1,
+                       .fe = {{
                                .frontend_attach  = lgdt3305_frontend_attach,
                                .tuner_attach     = mxl5007t_tuner_attach,
 
                                DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
-
+                       }},
                                .size_of_priv = sizeof(struct
                                                dib0700_adapter_state),
                        },
@@ -3550,6 +3591,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                .num_adapters = 1,
                .adapter = {
                        {
+                       .num_frontends = 1,
+                       .fe = {{
                                .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
                                .pid_filter_count = 32,
                                .pid_filter       = stk70x0p_pid_filter,
@@ -3558,7 +3601,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                                .tuner_attach     = dib7770p_tuner_attach,
 
                                DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
-
+                       }},
                                .size_of_priv =
                                        sizeof(struct dib0700_adapter_state),
                        },
@@ -3600,6 +3643,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                .num_adapters = 1,
                .adapter = {
                        {
+                       .num_frontends = 1,
+                       .fe = {{
                                .caps  = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
                                .pid_filter_count = 32,
                                .pid_filter = stk80xx_pid_filter,
@@ -3608,7 +3653,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                                .tuner_attach     = dib807x_tuner_attach,
 
                                DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
-
+                       }},
                                .size_of_priv =
                                        sizeof(struct dib0700_adapter_state),
                        },
@@ -3644,6 +3689,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                .num_adapters = 2,
                .adapter = {
                        {
+                       .num_frontends = 1,
+                       .fe = {{
                                .caps  = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
                                .pid_filter_count = 32,
                                .pid_filter = stk80xx_pid_filter,
@@ -3652,11 +3699,13 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                                .tuner_attach     = dib807x_tuner_attach,
 
                                DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
-
+                       }},
                                .size_of_priv =
                                        sizeof(struct dib0700_adapter_state),
                        },
                        {
+                       .num_frontends = 1,
+                       .fe = {{
                                .caps  = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
                                .pid_filter_count = 32,
                                .pid_filter = stk80xx_pid_filter,
@@ -3665,7 +3714,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                                .tuner_attach     = dib807x_tuner_attach,
 
                                DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
-
+                       }},
                                .size_of_priv =
                                        sizeof(struct dib0700_adapter_state),
                        },
@@ -3693,6 +3742,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                .num_adapters = 1,
                .adapter = {
                        {
+                       .num_frontends = 1,
+                       .fe = {{
                                .caps  = DVB_USB_ADAP_HAS_PID_FILTER |
                                        DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
                                .pid_filter_count = 32,
@@ -3702,7 +3753,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                                .tuner_attach     = dib809x_tuner_attach,
 
                                DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
-
+                       }},
                                .size_of_priv =
                                        sizeof(struct dib0700_adapter_state),
                        },
@@ -3730,6 +3781,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                .num_adapters = 1,
                .adapter = {
                        {
+                       .num_frontends = 1,
+                       .fe = {{
                                .caps  = DVB_USB_ADAP_HAS_PID_FILTER |
                                        DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
                                .pid_filter_count = 32,
@@ -3739,7 +3792,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                                .tuner_attach     = dib9090_tuner_attach,
 
                                DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
-
+                       }},
                                .size_of_priv =
                                        sizeof(struct dib0700_adapter_state),
                        },
@@ -3767,6 +3820,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                .num_adapters = 1,
                .adapter = {
                        {
+                       .num_frontends = 1,
+                       .fe = {{
                                .caps  = DVB_USB_ADAP_HAS_PID_FILTER |
                                        DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
                                .pid_filter_count = 32,
@@ -3776,7 +3831,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                                .tuner_attach     = nim8096md_tuner_attach,
 
                                DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
-
+                       }},
                                .size_of_priv =
                                        sizeof(struct dib0700_adapter_state),
                        },
@@ -3804,6 +3859,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                .num_adapters = 1,
                .adapter = {
                        {
+                       .num_frontends = 1,
+                       .fe = {{
                                .caps  = DVB_USB_ADAP_HAS_PID_FILTER |
                                        DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
                                .pid_filter_count = 32,
@@ -3813,7 +3870,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                                .tuner_attach     = nim9090md_tuner_attach,
 
                                DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
-
+                       }},
                                .size_of_priv =
                                        sizeof(struct dib0700_adapter_state),
                        },
@@ -3841,6 +3898,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                .num_adapters = 1,
                .adapter = {
                        {
+                       .num_frontends = 1,
+                       .fe = {{
                                .caps  = DVB_USB_ADAP_HAS_PID_FILTER |
                                        DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
                                .pid_filter_count = 32,
@@ -3850,7 +3909,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                                .tuner_attach     = nim7090_tuner_attach,
 
                                DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
-
+                       }},
                                .size_of_priv =
                                        sizeof(struct dib0700_adapter_state),
                        },
@@ -3878,6 +3937,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                .num_adapters = 2,
                .adapter = {
                        {
+                       .num_frontends = 1,
+                       .fe = {{
                                .caps  = DVB_USB_ADAP_HAS_PID_FILTER |
                                        DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
                                .pid_filter_count = 32,
@@ -3887,11 +3948,13 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                                .tuner_attach     = tfe7090pvr_tuner0_attach,
 
                                DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
-
+                       }},
                                .size_of_priv =
                                        sizeof(struct dib0700_adapter_state),
                        },
                        {
+                       .num_frontends = 1,
+                       .fe = {{
                                .caps  = DVB_USB_ADAP_HAS_PID_FILTER |
                                        DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
                                .pid_filter_count = 32,
@@ -3901,7 +3964,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                                .tuner_attach     = tfe7090pvr_tuner1_attach,
 
                                DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
-
+                       }},
                                .size_of_priv =
                                        sizeof(struct dib0700_adapter_state),
                        },
@@ -3929,11 +3992,13 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                .num_adapters = 1,
                .adapter = {
                        {
+                       .num_frontends = 1,
+                       .fe = {{
                                .frontend_attach  = pctv340e_frontend_attach,
                                .tuner_attach     = xc4000_tuner_attach,
 
                                DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
-
+                       }},
                                .size_of_priv = sizeof(struct
                                                dib0700_adapter_state),
                        },
index 4c2a689c820e88c46f56348bd3d637a4fe497541..a76bbb29ca36eeb0c5a3cfc0b42fe9a7ae422df8 100644 (file)
@@ -23,7 +23,7 @@ int dibusb_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
        if (adap->priv != NULL) {
                struct dibusb_state *st = adap->priv;
                if (st->ops.fifo_ctrl != NULL)
-                       if (st->ops.fifo_ctrl(adap->fe,onoff)) {
+                       if (st->ops.fifo_ctrl(adap->fe_adap[0].fe, onoff)) {
                                err("error while controlling the fifo of the demod.");
                                return -ENODEV;
                        }
@@ -37,7 +37,8 @@ int dibusb_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid, int onof
        if (adap->priv != NULL) {
                struct dibusb_state *st = adap->priv;
                if (st->ops.pid_ctrl != NULL)
-                       st->ops.pid_ctrl(adap->fe,index,pid,onoff);
+                       st->ops.pid_ctrl(adap->fe_adap[0].fe,
+                                        index, pid, onoff);
        }
        return 0;
 }
@@ -48,7 +49,7 @@ int dibusb_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
        if (adap->priv != NULL) {
                struct dibusb_state *st = adap->priv;
                if (st->ops.pid_parse != NULL)
-                       if (st->ops.pid_parse(adap->fe,onoff) < 0)
+                       if (st->ops.pid_parse(adap->fe_adap[0].fe, onoff) < 0)
                                err("could not handle pid_parser");
        }
        return 0;
@@ -254,8 +255,16 @@ int dibusb_dib3000mc_frontend_attach(struct dvb_usb_adapter *adap)
                msleep(1000);
        }
 
-       if ((adap->fe = dvb_attach(dib3000mc_attach, &adap->dev->i2c_adap, DEFAULT_DIB3000P_I2C_ADDRESS,  &mod3000p_dib3000p_config)) != NULL ||
-               (adap->fe = dvb_attach(dib3000mc_attach, &adap->dev->i2c_adap, DEFAULT_DIB3000MC_I2C_ADDRESS, &mod3000p_dib3000p_config)) != NULL) {
+       adap->fe_adap[0].fe = dvb_attach(dib3000mc_attach,
+                                        &adap->dev->i2c_adap,
+                                        DEFAULT_DIB3000P_I2C_ADDRESS,
+                                        &mod3000p_dib3000p_config);
+       if ((adap->fe_adap[0].fe) == NULL)
+               adap->fe_adap[0].fe = dvb_attach(dib3000mc_attach,
+                                                &adap->dev->i2c_adap,
+                                                DEFAULT_DIB3000MC_I2C_ADDRESS,
+                                                &mod3000p_dib3000p_config);
+       if ((adap->fe_adap[0].fe) != NULL) {
                if (adap->priv != NULL) {
                        struct dibusb_state *st = adap->priv;
                        st->ops.pid_parse = dib3000mc_pid_parse;
@@ -309,15 +318,15 @@ int dibusb_dib3000mc_tuner_attach(struct dvb_usb_adapter *adap)
                }
        }
 
-       tun_i2c = dib3000mc_get_tuner_i2c_master(adap->fe, 1);
-       if (dvb_attach(mt2060_attach, adap->fe, tun_i2c, &stk3000p_mt2060_config, if1) == NULL) {
+       tun_i2c = dib3000mc_get_tuner_i2c_master(adap->fe_adap[0].fe, 1);
+       if (dvb_attach(mt2060_attach, adap->fe_adap[0].fe, tun_i2c, &stk3000p_mt2060_config, if1) == NULL) {
                /* not found - use panasonic pll parameters */
-               if (dvb_attach(dvb_pll_attach, adap->fe, 0x60, tun_i2c, DVB_PLL_ENV57H1XD5) == NULL)
+               if (dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60, tun_i2c, DVB_PLL_ENV57H1XD5) == NULL)
                        return -ENOMEM;
        } else {
                st->mt2060_present = 1;
                /* set the correct parameters for the dib3000p */
-               dib3000mc_set_config(adap->fe, &stk3000p_dib3000p_config);
+               dib3000mc_set_config(adap->fe_adap[0].fe, &stk3000p_dib3000p_config);
        }
        return 0;
 }
index 04d91bdd35629b282d0aa1b68b9e3941808b7368..7270791f8340ebb654e49916973f9275fc53704c 100644 (file)
@@ -31,11 +31,12 @@ static int dibusb_dib3000mb_frontend_attach(struct dvb_usb_adapter *adap)
 
        demod_cfg.demod_address = 0x8;
 
-       if ((adap->fe = dvb_attach(dib3000mb_attach, &demod_cfg,
-                                  &adap->dev->i2c_adap, &st->ops)) == NULL)
+       adap->fe_adap[0].fe = dvb_attach(dib3000mb_attach, &demod_cfg,
+                                        &adap->dev->i2c_adap, &st->ops);
+       if ((adap->fe_adap[0].fe) == NULL)
                return -ENODEV;
 
-       adap->fe->ops.i2c_gate_ctrl = dib3000mb_i2c_gate_ctrl;
+       adap->fe_adap[0].fe->ops.i2c_gate_ctrl = dib3000mb_i2c_gate_ctrl;
 
        return 0;
 }
@@ -46,7 +47,7 @@ static int dibusb_thomson_tuner_attach(struct dvb_usb_adapter *adap)
 
        st->tuner_addr = 0x61;
 
-       dvb_attach(dvb_pll_attach, adap->fe, 0x61, &adap->dev->i2c_adap,
+       dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x61, &adap->dev->i2c_adap,
                   DVB_PLL_TUA6010XS);
        return 0;
 }
@@ -57,7 +58,7 @@ static int dibusb_panasonic_tuner_attach(struct dvb_usb_adapter *adap)
 
        st->tuner_addr = 0x60;
 
-       dvb_attach(dvb_pll_attach, adap->fe, 0x60, &adap->dev->i2c_adap,
+       dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60, &adap->dev->i2c_adap,
                   DVB_PLL_TDA665X);
        return 0;
 }
@@ -78,16 +79,16 @@ static int dibusb_tuner_probe_and_attach(struct dvb_usb_adapter *adap)
        /* the Panasonic sits on I2C addrass 0x60, the Thomson on 0x61 */
        msg[0].addr = msg[1].addr = st->tuner_addr = 0x60;
 
-       if (adap->fe->ops.i2c_gate_ctrl)
-               adap->fe->ops.i2c_gate_ctrl(adap->fe,1);
+       if (adap->fe_adap[0].fe->ops.i2c_gate_ctrl)
+               adap->fe_adap[0].fe->ops.i2c_gate_ctrl(adap->fe_adap[0].fe, 1);
 
        if (i2c_transfer(&adap->dev->i2c_adap, msg, 2) != 2) {
                err("tuner i2c write failed.");
                ret = -EREMOTEIO;
        }
 
-       if (adap->fe->ops.i2c_gate_ctrl)
-               adap->fe->ops.i2c_gate_ctrl(adap->fe,0);
+       if (adap->fe_adap[0].fe->ops.i2c_gate_ctrl)
+               adap->fe_adap[0].fe->ops.i2c_gate_ctrl(adap->fe_adap[0].fe, 0);
 
        if (b2[0] == 0xfe) {
                info("This device has the Thomson Cable onboard. Which is default.");
@@ -185,6 +186,8 @@ static struct dvb_usb_device_properties dibusb1_1_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
                        .pid_filter_count = 16,
 
@@ -205,6 +208,7 @@ static struct dvb_usb_device_properties dibusb1_1_properties = {
                                        }
                                }
                        },
+               }},
                        .size_of_priv     = sizeof(struct dibusb_state),
                }
        },
@@ -272,6 +276,8 @@ static struct dvb_usb_device_properties dibusb1_1_an2235_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .caps = DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF | DVB_USB_ADAP_HAS_PID_FILTER,
                        .pid_filter_count = 16,
 
@@ -292,6 +298,7 @@ static struct dvb_usb_device_properties dibusb1_1_an2235_properties = {
                                        }
                                }
                        },
+               }},
                        .size_of_priv     = sizeof(struct dibusb_state),
                },
        },
@@ -338,6 +345,8 @@ static struct dvb_usb_device_properties dibusb2_0b_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
                        .pid_filter_count = 16,
 
@@ -358,6 +367,7 @@ static struct dvb_usb_device_properties dibusb2_0b_properties = {
                                        }
                                }
                        },
+               }},
                        .size_of_priv     = sizeof(struct dibusb_state),
                }
        },
@@ -398,6 +408,8 @@ static struct dvb_usb_device_properties artec_t1_usb2_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
                        .pid_filter_count = 16,
 
@@ -417,6 +429,7 @@ static struct dvb_usb_device_properties artec_t1_usb2_properties = {
                                        }
                                }
                        },
+               }},
                        .size_of_priv     = sizeof(struct dibusb_state),
                }
        },
index c1d9094b61e59f696cdbfbfb8c3da2fed0eaebf7..9c165e2569d439b1be14b709e364232cb61b1b4d 100644 (file)
@@ -57,6 +57,8 @@ static struct dvb_usb_device_properties dibusb_mc_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
                        .pid_filter_count = 32,
                        .streaming_ctrl   = dibusb2_0_streaming_ctrl,
@@ -76,6 +78,7 @@ static struct dvb_usb_device_properties dibusb_mc_properties = {
                                        }
                                }
                        },
+               }},
                        .size_of_priv     = sizeof(struct dibusb_state),
                }
        },
index f6344cdd360f7acd99a2c3c93b022269d9acc6a8..f7184111aa6459a9573454a6d56bb08b28347a34 100644 (file)
@@ -137,11 +137,16 @@ static int digitv_frontend_attach(struct dvb_usb_adapter *adap)
 {
        struct digitv_state *st = adap->dev->priv;
 
-       if ((adap->fe = dvb_attach(mt352_attach, &digitv_mt352_config, &adap->dev->i2c_adap)) != NULL) {
+       adap->fe_adap[0].fe = dvb_attach(mt352_attach, &digitv_mt352_config,
+                                        &adap->dev->i2c_adap);
+       if ((adap->fe_adap[0].fe) != NULL) {
                st->is_nxt6000 = 0;
                return 0;
        }
-       if ((adap->fe = dvb_attach(nxt6000_attach, &digitv_nxt6000_config, &adap->dev->i2c_adap)) != NULL) {
+       adap->fe_adap[0].fe = dvb_attach(nxt6000_attach,
+                                        &digitv_nxt6000_config,
+                                        &adap->dev->i2c_adap);
+       if ((adap->fe_adap[0].fe) != NULL) {
                st->is_nxt6000 = 1;
                return 0;
        }
@@ -152,11 +157,11 @@ static int digitv_tuner_attach(struct dvb_usb_adapter *adap)
 {
        struct digitv_state *st = adap->dev->priv;
 
-       if (!dvb_attach(dvb_pll_attach, adap->fe, 0x60, NULL, DVB_PLL_TDED4))
+       if (!dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60, NULL, DVB_PLL_TDED4))
                return -ENODEV;
 
        if (st->is_nxt6000)
-               adap->fe->ops.tuner_ops.set_params = digitv_nxt6000_tuner_set_params;
+               adap->fe_adap[0].fe->ops.tuner_ops.set_params = digitv_nxt6000_tuner_set_params;
 
        return 0;
 }
@@ -292,6 +297,8 @@ static struct dvb_usb_device_properties digitv_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .frontend_attach  = digitv_frontend_attach,
                        .tuner_attach     = digitv_tuner_attach,
 
@@ -306,6 +313,7 @@ static struct dvb_usb_device_properties digitv_properties = {
                                        }
                                }
                        },
+               }},
                }
        },
        .identify_state   = digitv_identify_state,
index ecd86eca2548099cbb22413ea52d170924cab110..106dfd55ff9c574c60c700a2fe8b276b9d6fb5e2 100644 (file)
@@ -90,7 +90,7 @@ static int dtt200u_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
 
 static int dtt200u_frontend_attach(struct dvb_usb_adapter *adap)
 {
-       adap->fe = dtt200u_fe_attach(adap->dev);
+       adap->fe_adap[0].fe = dtt200u_fe_attach(adap->dev);
        return 0;
 }
 
@@ -140,6 +140,8 @@ static struct dvb_usb_device_properties dtt200u_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_NEED_PID_FILTERING,
                        .pid_filter_count = 15,
 
@@ -157,6 +159,7 @@ static struct dvb_usb_device_properties dtt200u_properties = {
                        }
                }
        },
+               }},
                }
        },
        .power_ctrl      = dtt200u_power_ctrl,
@@ -187,6 +190,8 @@ static struct dvb_usb_device_properties wt220u_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_NEED_PID_FILTERING,
                        .pid_filter_count = 15,
 
@@ -204,6 +209,7 @@ static struct dvb_usb_device_properties wt220u_properties = {
                        }
                }
        },
+               }},
                }
        },
        .power_ctrl      = dtt200u_power_ctrl,
@@ -234,6 +240,8 @@ static struct dvb_usb_device_properties wt220u_fc_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_NEED_PID_FILTERING,
                        .pid_filter_count = 15,
 
@@ -251,6 +259,7 @@ static struct dvb_usb_device_properties wt220u_fc_properties = {
                        }
                }
        },
+               }},
                }
        },
        .power_ctrl      = dtt200u_power_ctrl,
@@ -281,6 +290,8 @@ static struct dvb_usb_device_properties wt220u_zl0353_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_NEED_PID_FILTERING,
                        .pid_filter_count = 15,
 
@@ -298,6 +309,7 @@ static struct dvb_usb_device_properties wt220u_zl0353_properties = {
                                        }
                                }
                        },
+               }},
                }
        },
        .power_ctrl      = dtt200u_power_ctrl,
index 078ce92ca4367bd8058846834ebcd883b08fc930..7373132163d20fb9ae99e2726015657144e8a4c1 100644 (file)
@@ -115,13 +115,13 @@ static struct zl10353_config dtv5100_zl10353_config = {
 
 static int dtv5100_frontend_attach(struct dvb_usb_adapter *adap)
 {
-       adap->fe = dvb_attach(zl10353_attach, &dtv5100_zl10353_config,
+       adap->fe_adap[0].fe = dvb_attach(zl10353_attach, &dtv5100_zl10353_config,
                              &adap->dev->i2c_adap);
-       if (adap->fe == NULL)
+       if (adap->fe_adap[0].fe == NULL)
                return -EIO;
 
        /* disable i2c gate, or it won't work... is this safe? */
-       adap->fe->ops.i2c_gate_ctrl = NULL;
+       adap->fe_adap[0].fe->ops.i2c_gate_ctrl = NULL;
 
        return 0;
 }
@@ -133,7 +133,7 @@ static struct qt1010_config dtv5100_qt1010_config = {
 static int dtv5100_tuner_attach(struct dvb_usb_adapter *adap)
 {
        return dvb_attach(qt1010_attach,
-                         adap->fe, &adap->dev->i2c_adap,
+                         adap->fe_adap[0].fe, &adap->dev->i2c_adap,
                          &dtv5100_qt1010_config) == NULL ? -ENODEV : 0;
 }
 
@@ -180,6 +180,8 @@ static struct dvb_usb_device_properties dtv5100_properties = {
 
        .num_adapters = 1,
        .adapter = {{
+               .num_frontends = 1,
+               .fe = {{
                .frontend_attach = dtv5100_frontend_attach,
                .tuner_attach    = dtv5100_tuner_attach,
 
@@ -193,6 +195,7 @@ static struct dvb_usb_device_properties dtv5100_properties = {
                                }
                        }
                },
+               }},
        } },
 
        .i2c_algo = &dtv5100_i2c_algo,
index b3cb626ed56e8a9f3d41748e7691be33f6f0f3fa..ba4a7517354ff96f52e94f4830c1c0a1c2efc137 100644 (file)
@@ -17,15 +17,20 @@ static int dvb_usb_ctrl_feed(struct dvb_demux_feed *dvbdmxfeed, int onoff)
        if (adap == NULL)
                return -ENODEV;
 
+       if ((adap->active_fe < 0) ||
+           (adap->active_fe >= adap->num_frontends_initialized)) {
+               return -EINVAL;
+       }
+
        newfeedcount = adap->feedcount + (onoff ? 1 : -1);
 
        /* stop feed before setting a new pid if there will be no pid anymore */
        if (newfeedcount == 0) {
                deb_ts("stop feeding\n");
-               usb_urb_kill(&adap->stream);
+               usb_urb_kill(&adap->fe_adap[adap->active_fe].stream);
 
-               if (adap->props.streaming_ctrl != NULL) {
-                       ret = adap->props.streaming_ctrl(adap, 0);
+               if (adap->props.fe[adap->active_fe].streaming_ctrl != NULL) {
+                       ret = adap->props.fe[adap->active_fe].streaming_ctrl(adap, 0);
                        if (ret < 0) {
                                err("error while stopping stream.");
                                return ret;
@@ -36,36 +41,37 @@ static int dvb_usb_ctrl_feed(struct dvb_demux_feed *dvbdmxfeed, int onoff)
        adap->feedcount = newfeedcount;
 
        /* activate the pid on the device specific pid_filter */
-       deb_ts("setting pid (%s): %5d %04x at index %d '%s'\n",adap->pid_filtering ?
-               "yes" : "no", dvbdmxfeed->pid,dvbdmxfeed->pid,dvbdmxfeed->index,onoff ?
-               "on" : "off");
-       if (adap->props.caps & DVB_USB_ADAP_HAS_PID_FILTER &&
-               adap->pid_filtering &&
-               adap->props.pid_filter != NULL)
-               adap->props.pid_filter(adap, dvbdmxfeed->index, dvbdmxfeed->pid,onoff);
+       deb_ts("setting pid (%s): %5d %04x at index %d '%s'\n",
+               adap->fe_adap[adap->active_fe].pid_filtering ?
+               "yes" : "no", dvbdmxfeed->pid, dvbdmxfeed->pid,
+               dvbdmxfeed->index, onoff ? "on" : "off");
+       if (adap->props.fe[adap->active_fe].caps & DVB_USB_ADAP_HAS_PID_FILTER &&
+               adap->fe_adap[adap->active_fe].pid_filtering &&
+               adap->props.fe[adap->active_fe].pid_filter != NULL)
+               adap->props.fe[adap->active_fe].pid_filter(adap, dvbdmxfeed->index, dvbdmxfeed->pid, onoff);
 
        /* start the feed if this was the first feed and there is still a feed
         * for reception.
         */
        if (adap->feedcount == onoff && adap->feedcount > 0) {
                deb_ts("submitting all URBs\n");
-               usb_urb_submit(&adap->stream);
+               usb_urb_submit(&adap->fe_adap[adap->active_fe].stream);
 
                deb_ts("controlling pid parser\n");
-               if (adap->props.caps & DVB_USB_ADAP_HAS_PID_FILTER &&
-                       adap->props.caps &
+               if (adap->props.fe[adap->active_fe].caps & DVB_USB_ADAP_HAS_PID_FILTER &&
+                       adap->props.fe[adap->active_fe].caps &
                        DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF &&
-                       adap->props.pid_filter_ctrl != NULL) {
-                       ret = adap->props.pid_filter_ctrl(adap,
-                               adap->pid_filtering);
+                       adap->props.fe[adap->active_fe].pid_filter_ctrl != NULL) {
+                       ret = adap->props.fe[adap->active_fe].pid_filter_ctrl(adap,
+                               adap->fe_adap[adap->active_fe].pid_filtering);
                        if (ret < 0) {
                                err("could not handle pid_parser");
                                return ret;
                        }
                }
                deb_ts("start feeding\n");
-               if (adap->props.streaming_ctrl != NULL) {
-                       ret = adap->props.streaming_ctrl(adap, 1);
+               if (adap->props.fe[adap->active_fe].streaming_ctrl != NULL) {
+                       ret = adap->props.fe[adap->active_fe].streaming_ctrl(adap, 1);
                        if (ret < 0) {
                                err("error while enabling fifo.");
                                return ret;
@@ -90,6 +96,7 @@ static int dvb_usb_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
 
 int dvb_usb_adapter_dvb_init(struct dvb_usb_adapter *adap, short *adapter_nums)
 {
+       int i;
        int ret = dvb_register_adapter(&adap->dvb_adap, adap->dev->desc->name,
                                       adap->dev->owner, &adap->dev->udev->dev,
                                       adapter_nums);
@@ -112,7 +119,12 @@ int dvb_usb_adapter_dvb_init(struct dvb_usb_adapter *adap, short *adapter_nums)
        adap->demux.dmx.capabilities = DMX_TS_FILTERING | DMX_SECTION_FILTERING;
        adap->demux.priv             = adap;
 
-       adap->demux.feednum          = adap->demux.filternum = adap->max_feed_count;
+       adap->demux.filternum        = 0;
+       for (i = 0; i < adap->props.num_frontends; i++) {
+               if (adap->demux.filternum < adap->fe_adap[i].max_feed_count)
+                       adap->demux.filternum = adap->fe_adap[i].max_feed_count;
+       }
+       adap->demux.feednum          = adap->demux.filternum;
        adap->demux.start_feed       = dvb_usb_start_feed;
        adap->demux.stop_feed        = dvb_usb_stop_feed;
        adap->demux.write_to_decoder = NULL;
@@ -156,14 +168,33 @@ int dvb_usb_adapter_dvb_exit(struct dvb_usb_adapter *adap)
        return 0;
 }
 
+static int dvb_usb_set_active_fe(struct dvb_frontend *fe, int onoff)
+{
+       struct dvb_usb_adapter *adap = fe->dvb->priv;
+
+       int ret = (adap->props.frontend_ctrl) ?
+               adap->props.frontend_ctrl(fe, onoff) : 0;
+
+       if (ret < 0) {
+               err("frontend_ctrl request failed");
+               return ret;
+       }
+       if (onoff)
+               adap->active_fe = fe->id;
+
+       return 0;
+}
+
 static int dvb_usb_fe_wakeup(struct dvb_frontend *fe)
 {
        struct dvb_usb_adapter *adap = fe->dvb->priv;
 
        dvb_usb_device_power_ctrl(adap->dev, 1);
 
-       if (adap->fe_init)
-               adap->fe_init(fe);
+       dvb_usb_set_active_fe(fe, 1);
+
+       if (adap->fe_adap[fe->id].fe_init)
+               adap->fe_adap[fe->id].fe_init(fe);
 
        return 0;
 }
@@ -172,45 +203,81 @@ static int dvb_usb_fe_sleep(struct dvb_frontend *fe)
 {
        struct dvb_usb_adapter *adap = fe->dvb->priv;
 
-       if (adap->fe_sleep)
-               adap->fe_sleep(fe);
+       if (adap->fe_adap[fe->id].fe_sleep)
+               adap->fe_adap[fe->id].fe_sleep(fe);
+
+       dvb_usb_set_active_fe(fe, 0);
 
        return dvb_usb_device_power_ctrl(adap->dev, 0);
 }
 
 int dvb_usb_adapter_frontend_init(struct dvb_usb_adapter *adap)
 {
-       if (adap->props.frontend_attach == NULL) {
-               err("strange: '%s' #%d doesn't want to attach a frontend.",adap->dev->desc->name, adap->id);
-               return 0;
-       }
+       int ret, i;
 
-       /* re-assign sleep and wakeup functions */
-       if (adap->props.frontend_attach(adap) == 0 && adap->fe != NULL) {
-               adap->fe_init  = adap->fe->ops.init;  adap->fe->ops.init  = dvb_usb_fe_wakeup;
-               adap->fe_sleep = adap->fe->ops.sleep; adap->fe->ops.sleep = dvb_usb_fe_sleep;
+       /* register all given adapter frontends */
+       for (i = 0; i < adap->props.num_frontends; i++) {
 
-               if (dvb_register_frontend(&adap->dvb_adap, adap->fe)) {
-                       err("Frontend registration failed.");
-                       dvb_frontend_detach(adap->fe);
-                       adap->fe = NULL;
-                       return -ENODEV;
+               if (adap->props.fe[i].frontend_attach == NULL) {
+                       err("strange: '%s' #%d,%d "
+                           "doesn't want to attach a frontend.",
+                           adap->dev->desc->name, adap->id, i);
+
+                       return 0;
+               }
+
+               ret = adap->props.fe[i].frontend_attach(adap);
+               if (ret || adap->fe_adap[i].fe == NULL) {
+                       /* only print error when there is no FE at all */
+                       if (i == 0)
+                               err("no frontend was attached by '%s'",
+                                       adap->dev->desc->name);
+
+                       return 0;
+               }
+
+               adap->fe_adap[i].fe->id = i;
+
+               /* re-assign sleep and wakeup functions */
+               adap->fe_adap[i].fe_init = adap->fe_adap[i].fe->ops.init;
+               adap->fe_adap[i].fe->ops.init  = dvb_usb_fe_wakeup;
+               adap->fe_adap[i].fe_sleep = adap->fe_adap[i].fe->ops.sleep;
+               adap->fe_adap[i].fe->ops.sleep = dvb_usb_fe_sleep;
+
+               if (dvb_register_frontend(&adap->dvb_adap, adap->fe_adap[i].fe)) {
+                       err("Frontend %d registration failed.", i);
+                       dvb_frontend_detach(adap->fe_adap[i].fe);
+                       adap->fe_adap[i].fe = NULL;
+                       /* In error case, do not try register more FEs,
+                        * still leaving already registered FEs alive. */
+                       if (i == 0)
+                               return -ENODEV;
+                       else
+                               return 0;
                }
 
                /* only attach the tuner if the demod is there */
-               if (adap->props.tuner_attach != NULL)
-                       adap->props.tuner_attach(adap);
-       } else
-               err("no frontend was attached by '%s'",adap->dev->desc->name);
+               if (adap->props.fe[i].tuner_attach != NULL)
+                       adap->props.fe[i].tuner_attach(adap);
+
+               adap->num_frontends_initialized++;
+       }
 
        return 0;
 }
 
 int dvb_usb_adapter_frontend_exit(struct dvb_usb_adapter *adap)
 {
-       if (adap->fe != NULL) {
-               dvb_unregister_frontend(adap->fe);
-               dvb_frontend_detach(adap->fe);
+       int i = adap->num_frontends_initialized - 1;
+
+       /* unregister all given adapter frontends */
+       for (; i >= 0; i--) {
+               if (adap->fe_adap[i].fe != NULL) {
+                       dvb_unregister_frontend(adap->fe_adap[i].fe);
+                       dvb_frontend_detach(adap->fe_adap[i].fe);
+               }
        }
+       adap->num_frontends_initialized = 0;
+
        return 0;
 }
index 2a79b8fb3e8dc283ddb8ee8a466b9696440eb620..2ad33ba92ba2de1150a86fdf4ccf9f9be89949fb 100644 (file)
 #define USB_PID_KWORLD_PC160_2T                                0xc160
 #define USB_PID_KWORLD_PC160_T                         0xc161
 #define USB_PID_KWORLD_UB383_T                         0xe383
+#define USB_PID_KWORLD_UB499_2T_T09                    0xe409
 #define USB_PID_KWORLD_VSTREAM_COLD                    0x17de
 #define USB_PID_KWORLD_VSTREAM_WARM                    0x17df
 #define USB_PID_TERRATEC_CINERGY_T_USB_XE              0x0055
 #define USB_PID_PCTV_200E                              0x020e
 #define USB_PID_PCTV_400E                              0x020f
 #define USB_PID_PCTV_450E                              0x0222
+#define USB_PID_PCTV_452E                              0x021f
+#define USB_PID_TECHNOTREND_CONNECT_S2_3600            0x3007
+#define USB_PID_TECHNOTREND_CONNECT_S2_3650_CI         0x300a
 #define USB_PID_NEBULA_DIGITV                          0x0201
 #define USB_PID_DVICO_BLUEBIRD_LGDT                    0xd820
 #define USB_PID_DVICO_BLUEBIRD_LG064F_COLD             0xd500
index 2e3ea0fa28e01768fc4a1291919897b7aa2509c6..169196ec2d4eceb0b4ef0616bdcd55e7a626624b 100644 (file)
@@ -29,7 +29,7 @@ MODULE_PARM_DESC(force_pid_filter_usage, "force all dvb-usb-devices to use a PID
 static int dvb_usb_adapter_init(struct dvb_usb_device *d, short *adapter_nrs)
 {
        struct dvb_usb_adapter *adap;
-       int ret, n;
+       int ret, n, o;
 
        for (n = 0; n < d->props.num_adapters; n++) {
                adap = &d->adapter[n];
@@ -38,31 +38,42 @@ static int dvb_usb_adapter_init(struct dvb_usb_device *d, short *adapter_nrs)
 
                memcpy(&adap->props, &d->props.adapter[n], sizeof(struct dvb_usb_adapter_properties));
 
+       for (o = 0; o < adap->props.num_frontends; o++) {
+               struct dvb_usb_adapter_fe_properties *props = &adap->props.fe[o];
                /* speed - when running at FULL speed we need a HW PID filter */
-               if (d->udev->speed == USB_SPEED_FULL && !(adap->props.caps & DVB_USB_ADAP_HAS_PID_FILTER)) {
+               if (d->udev->speed == USB_SPEED_FULL && !(props->caps & DVB_USB_ADAP_HAS_PID_FILTER)) {
                        err("This USB2.0 device cannot be run on a USB1.1 port. (it lacks a hardware PID filter)");
                        return -ENODEV;
                }
 
-               if ((d->udev->speed == USB_SPEED_FULL && adap->props.caps & DVB_USB_ADAP_HAS_PID_FILTER) ||
-                       (adap->props.caps & DVB_USB_ADAP_NEED_PID_FILTERING)) {
-                       info("will use the device's hardware PID filter (table count: %d).", adap->props.pid_filter_count);
-                       adap->pid_filtering  = 1;
-                       adap->max_feed_count = adap->props.pid_filter_count;
+               if ((d->udev->speed == USB_SPEED_FULL && props->caps & DVB_USB_ADAP_HAS_PID_FILTER) ||
+                       (props->caps & DVB_USB_ADAP_NEED_PID_FILTERING)) {
+                       info("will use the device's hardware PID filter (table count: %d).", props->pid_filter_count);
+                       adap->fe_adap[o].pid_filtering  = 1;
+                       adap->fe_adap[o].max_feed_count = props->pid_filter_count;
                } else {
                        info("will pass the complete MPEG2 transport stream to the software demuxer.");
-                       adap->pid_filtering  = 0;
-                       adap->max_feed_count = 255;
+                       adap->fe_adap[o].pid_filtering  = 0;
+                       adap->fe_adap[o].max_feed_count = 255;
                }
 
-               if (!adap->pid_filtering &&
+               if (!adap->fe_adap[o].pid_filtering &&
                        dvb_usb_force_pid_filter_usage &&
-                       adap->props.caps & DVB_USB_ADAP_HAS_PID_FILTER) {
+                       props->caps & DVB_USB_ADAP_HAS_PID_FILTER) {
                        info("pid filter enabled by module option.");
-                       adap->pid_filtering  = 1;
-                       adap->max_feed_count = adap->props.pid_filter_count;
+                       adap->fe_adap[o].pid_filtering  = 1;
+                       adap->fe_adap[o].max_feed_count = props->pid_filter_count;
                }
 
+               if (props->size_of_priv > 0) {
+                       adap->fe_adap[o].priv = kzalloc(props->size_of_priv, GFP_KERNEL);
+                       if (adap->fe_adap[o].priv == NULL) {
+                               err("no memory for priv for adapter %d fe %d.", n, o);
+                               return -ENOMEM;
+                       }
+               }
+       }
+
                if (adap->props.size_of_priv > 0) {
                        adap->priv = kzalloc(adap->props.size_of_priv, GFP_KERNEL);
                        if (adap->priv == NULL) {
@@ -77,6 +88,10 @@ static int dvb_usb_adapter_init(struct dvb_usb_device *d, short *adapter_nrs)
                        return ret;
                }
 
+               /* use exclusive FE lock if there is multiple shared FEs */
+               if (adap->fe_adap[1].fe)
+                       adap->dvb_adap.mfe_shared = 1;
+
                d->num_adapters_initialized++;
                d->state |= DVB_USB_STATE_DVB;
        }
index bb46ba6a35739d042ef133faf435c549e1b66e9a..53a5c30b51b2665e3c43fb01868c8ce2f62f1703 100644 (file)
@@ -82,16 +82,28 @@ static void dvb_usb_data_complete_204(struct usb_data_stream *stream, u8 *buffer
 
 int dvb_usb_adapter_stream_init(struct dvb_usb_adapter *adap)
 {
-       adap->stream.udev      = adap->dev->udev;
-       if (adap->props.caps & DVB_USB_ADAP_RECEIVES_204_BYTE_TS)
-               adap->stream.complete = dvb_usb_data_complete_204;
-       else
-       adap->stream.complete  = dvb_usb_data_complete;
-       adap->stream.user_priv = adap;
-       return usb_urb_init(&adap->stream, &adap->props.stream);
+       int i, ret = 0;
+       for (i = 0; i < adap->props.num_frontends; i++) {
+
+               adap->fe_adap[i].stream.udev      = adap->dev->udev;
+               if (adap->props.fe[i].caps & DVB_USB_ADAP_RECEIVES_204_BYTE_TS)
+                       adap->fe_adap[i].stream.complete =
+                               dvb_usb_data_complete_204;
+               else
+               adap->fe_adap[i].stream.complete  = dvb_usb_data_complete;
+               adap->fe_adap[i].stream.user_priv = adap;
+               ret = usb_urb_init(&adap->fe_adap[i].stream,
+                                  &adap->props.fe[i].stream);
+               if (ret < 0)
+                       break;
+       }
+       return ret;
 }
 
 int dvb_usb_adapter_stream_exit(struct dvb_usb_adapter *adap)
 {
-       return usb_urb_exit(&adap->stream);
+       int i;
+       for (i = 0; i < adap->props.num_frontends; i++)
+               usb_urb_exit(&adap->fe_adap[i].stream);
+       return 0;
 }
index 7d35d078342b41522443868a2436fadc550ad92c..6d7d13f9ce68236579a77777169a888783b04d2f 100644 (file)
@@ -124,6 +124,8 @@ struct usb_data_stream_properties {
  * @caps: capabilities of the DVB USB device.
  * @pid_filter_count: number of PID filter position in the optional hardware
  *  PID-filter.
+ * @num_frontends: number of frontends of the DVB USB adapter.
+ * @frontend_ctrl: called to power on/off active frontend.
  * @streaming_ctrl: called to start and stop the MPEG2-TS streaming of the
  *  device (not URB submitting/killing).
  * @pid_filter_ctrl: called to en/disable the PID filter, if any.
@@ -134,7 +136,7 @@ struct usb_data_stream_properties {
  *  pll_desc and pll_init_buf of struct dvb_usb_device).
  * @stream: configuration of the USB streaming
  */
-struct dvb_usb_adapter_properties {
+struct dvb_usb_adapter_fe_properties {
 #define DVB_USB_ADAP_HAS_PID_FILTER               0x01
 #define DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF 0x02
 #define DVB_USB_ADAP_NEED_PID_FILTERING           0x04
@@ -152,9 +154,18 @@ struct dvb_usb_adapter_properties {
        struct usb_data_stream_properties stream;
 
        int size_of_priv;
+};
+
+#define MAX_NO_OF_FE_PER_ADAP 2
+struct dvb_usb_adapter_properties {
+       int size_of_priv;
 
+       int (*frontend_ctrl)   (struct dvb_frontend *, int);
        int (*fe_ioctl_override) (struct dvb_frontend *,
                                  unsigned int, void *, unsigned int);
+
+       int num_frontends;
+       struct dvb_usb_adapter_fe_properties fe[MAX_NO_OF_FE_PER_ADAP];
 };
 
 /**
@@ -345,6 +356,20 @@ struct usb_data_stream {
  *
  * @stream: the usb data stream.
  */
+struct dvb_usb_fe_adapter {
+       struct dvb_frontend *fe;
+
+       int (*fe_init)  (struct dvb_frontend *);
+       int (*fe_sleep) (struct dvb_frontend *);
+
+       struct usb_data_stream stream;
+
+       int pid_filtering;
+       int max_feed_count;
+
+       void *priv;
+};
+
 struct dvb_usb_adapter {
        struct dvb_usb_device *dev;
        struct dvb_usb_adapter_properties props;
@@ -356,20 +381,16 @@ struct dvb_usb_adapter {
        u8  id;
 
        int feedcount;
-       int pid_filtering;
 
        /* dvb */
        struct dvb_adapter   dvb_adap;
        struct dmxdev        dmxdev;
        struct dvb_demux     demux;
        struct dvb_net       dvb_net;
-       struct dvb_frontend *fe;
-       int                  max_feed_count;
-
-       int (*fe_init)  (struct dvb_frontend *);
-       int (*fe_sleep) (struct dvb_frontend *);
 
-       struct usb_data_stream stream;
+       struct dvb_usb_fe_adapter fe_adap[MAX_NO_OF_FE_PER_ADAP];
+       int active_fe;
+       int num_frontends_initialized;
 
        void *priv;
 };
index 058b2318abedf37d4e21af0b56383b3131d5abbc..f103ec1fe82ed0e89b9c0f4918682a367f072f33 100644 (file)
@@ -992,18 +992,18 @@ static int dw2104_frontend_attach(struct dvb_usb_adapter *d)
        struct dvb_tuner_ops *tuner_ops = NULL;
 
        if (demod_probe & 4) {
-               d->fe = dvb_attach(stv0900_attach, &dw2104a_stv0900_config,
+               d->fe_adap[0].fe = dvb_attach(stv0900_attach, &dw2104a_stv0900_config,
                                &d->dev->i2c_adap, 0);
-               if (d->fe != NULL) {
-                       if (dvb_attach(stb6100_attach, d->fe,
+               if (d->fe_adap[0].fe != NULL) {
+                       if (dvb_attach(stb6100_attach, d->fe_adap[0].fe,
                                        &dw2104a_stb6100_config,
                                        &d->dev->i2c_adap)) {
-                               tuner_ops = &d->fe->ops.tuner_ops;
+                               tuner_ops = &d->fe_adap[0].fe->ops.tuner_ops;
                                tuner_ops->set_frequency = stb6100_set_freq;
                                tuner_ops->get_frequency = stb6100_get_freq;
                                tuner_ops->set_bandwidth = stb6100_set_bandw;
                                tuner_ops->get_bandwidth = stb6100_get_bandw;
-                               d->fe->ops.set_voltage = dw210x_set_voltage;
+                               d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
                                info("Attached STV0900+STB6100!\n");
                                return 0;
                        }
@@ -1011,13 +1011,13 @@ static int dw2104_frontend_attach(struct dvb_usb_adapter *d)
        }
 
        if (demod_probe & 2) {
-               d->fe = dvb_attach(stv0900_attach, &dw2104_stv0900_config,
+               d->fe_adap[0].fe = dvb_attach(stv0900_attach, &dw2104_stv0900_config,
                                &d->dev->i2c_adap, 0);
-               if (d->fe != NULL) {
-                       if (dvb_attach(stv6110_attach, d->fe,
+               if (d->fe_adap[0].fe != NULL) {
+                       if (dvb_attach(stv6110_attach, d->fe_adap[0].fe,
                                        &dw2104_stv6110_config,
                                        &d->dev->i2c_adap)) {
-                               d->fe->ops.set_voltage = dw210x_set_voltage;
+                               d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
                                info("Attached STV0900+STV6110A!\n");
                                return 0;
                        }
@@ -1025,19 +1025,19 @@ static int dw2104_frontend_attach(struct dvb_usb_adapter *d)
        }
 
        if (demod_probe & 1) {
-               d->fe = dvb_attach(cx24116_attach, &dw2104_config,
+               d->fe_adap[0].fe = dvb_attach(cx24116_attach, &dw2104_config,
                                &d->dev->i2c_adap);
-               if (d->fe != NULL) {
-                       d->fe->ops.set_voltage = dw210x_set_voltage;
+               if (d->fe_adap[0].fe != NULL) {
+                       d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
                        info("Attached cx24116!\n");
                        return 0;
                }
        }
 
-       d->fe = dvb_attach(ds3000_attach, &dw2104_ds3000_config,
+       d->fe_adap[0].fe = dvb_attach(ds3000_attach, &dw2104_ds3000_config,
                        &d->dev->i2c_adap);
-       if (d->fe != NULL) {
-               d->fe->ops.set_voltage = dw210x_set_voltage;
+       if (d->fe_adap[0].fe != NULL) {
+               d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
                info("Attached DS3000!\n");
                return 0;
        }
@@ -1053,22 +1053,22 @@ static int dw2102_frontend_attach(struct dvb_usb_adapter *d)
 {
        if (dw2102_properties.i2c_algo == &dw2102_serit_i2c_algo) {
                /*dw2102_properties.adapter->tuner_attach = NULL;*/
-               d->fe = dvb_attach(si21xx_attach, &serit_sp1511lhb_config,
+               d->fe_adap[0].fe = dvb_attach(si21xx_attach, &serit_sp1511lhb_config,
                                        &d->dev->i2c_adap);
-               if (d->fe != NULL) {
-                       d->fe->ops.set_voltage = dw210x_set_voltage;
+               if (d->fe_adap[0].fe != NULL) {
+                       d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
                        info("Attached si21xx!\n");
                        return 0;
                }
        }
 
        if (dw2102_properties.i2c_algo == &dw2102_earda_i2c_algo) {
-               d->fe = dvb_attach(stv0288_attach, &earda_config,
+               d->fe_adap[0].fe = dvb_attach(stv0288_attach, &earda_config,
                                        &d->dev->i2c_adap);
-               if (d->fe != NULL) {
-                       if (dvb_attach(stb6000_attach, d->fe, 0x61,
+               if (d->fe_adap[0].fe != NULL) {
+                       if (dvb_attach(stb6000_attach, d->fe_adap[0].fe, 0x61,
                                        &d->dev->i2c_adap)) {
-                               d->fe->ops.set_voltage = dw210x_set_voltage;
+                               d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
                                info("Attached stv0288!\n");
                                return 0;
                        }
@@ -1077,10 +1077,10 @@ static int dw2102_frontend_attach(struct dvb_usb_adapter *d)
 
        if (dw2102_properties.i2c_algo == &dw2102_i2c_algo) {
                /*dw2102_properties.adapter->tuner_attach = dw2102_tuner_attach;*/
-               d->fe = dvb_attach(stv0299_attach, &sharp_z0194a_config,
+               d->fe_adap[0].fe = dvb_attach(stv0299_attach, &sharp_z0194a_config,
                                        &d->dev->i2c_adap);
-               if (d->fe != NULL) {
-                       d->fe->ops.set_voltage = dw210x_set_voltage;
+               if (d->fe_adap[0].fe != NULL) {
+                       d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
                        info("Attached stv0299!\n");
                        return 0;
                }
@@ -1090,9 +1090,9 @@ static int dw2102_frontend_attach(struct dvb_usb_adapter *d)
 
 static int dw3101_frontend_attach(struct dvb_usb_adapter *d)
 {
-       d->fe = dvb_attach(tda10023_attach, &dw3101_tda10023_config,
+       d->fe_adap[0].fe = dvb_attach(tda10023_attach, &dw3101_tda10023_config,
                                &d->dev->i2c_adap, 0x48);
-       if (d->fe != NULL) {
+       if (d->fe_adap[0].fe != NULL) {
                info("Attached tda10023!\n");
                return 0;
        }
@@ -1101,12 +1101,12 @@ static int dw3101_frontend_attach(struct dvb_usb_adapter *d)
 
 static int zl100313_frontend_attach(struct dvb_usb_adapter *d)
 {
-       d->fe = dvb_attach(mt312_attach, &zl313_config,
+       d->fe_adap[0].fe = dvb_attach(mt312_attach, &zl313_config,
                        &d->dev->i2c_adap);
-       if (d->fe != NULL) {
-               if (dvb_attach(zl10039_attach, d->fe, 0x60,
+       if (d->fe_adap[0].fe != NULL) {
+               if (dvb_attach(zl10039_attach, d->fe_adap[0].fe, 0x60,
                                &d->dev->i2c_adap)) {
-                       d->fe->ops.set_voltage = dw210x_set_voltage;
+                       d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
                        info("Attached zl100313+zl10039!\n");
                        return 0;
                }
@@ -1119,16 +1119,16 @@ static int stv0288_frontend_attach(struct dvb_usb_adapter *d)
 {
        u8 obuf[] = {7, 1};
 
-       d->fe = dvb_attach(stv0288_attach, &earda_config,
+       d->fe_adap[0].fe = dvb_attach(stv0288_attach, &earda_config,
                        &d->dev->i2c_adap);
 
-       if (d->fe == NULL)
+       if (d->fe_adap[0].fe == NULL)
                return -EIO;
 
-       if (NULL == dvb_attach(stb6000_attach, d->fe, 0x61, &d->dev->i2c_adap))
+       if (NULL == dvb_attach(stb6000_attach, d->fe_adap[0].fe, 0x61, &d->dev->i2c_adap))
                return -EIO;
 
-       d->fe->ops.set_voltage = dw210x_set_voltage;
+       d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
 
        dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
 
@@ -1143,14 +1143,14 @@ static int ds3000_frontend_attach(struct dvb_usb_adapter *d)
        struct s6x0_state *st = (struct s6x0_state *)d->dev->priv;
        u8 obuf[] = {7, 1};
 
-       d->fe = dvb_attach(ds3000_attach, &dw2104_ds3000_config,
+       d->fe_adap[0].fe = dvb_attach(ds3000_attach, &dw2104_ds3000_config,
                        &d->dev->i2c_adap);
 
-       if (d->fe == NULL)
+       if (d->fe_adap[0].fe == NULL)
                return -EIO;
 
-       st->old_set_voltage = d->fe->ops.set_voltage;
-       d->fe->ops.set_voltage = s660_set_voltage;
+       st->old_set_voltage = d->fe_adap[0].fe->ops.set_voltage;
+       d->fe_adap[0].fe->ops.set_voltage = s660_set_voltage;
 
        dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
 
@@ -1163,12 +1163,12 @@ static int prof_7500_frontend_attach(struct dvb_usb_adapter *d)
 {
        u8 obuf[] = {7, 1};
 
-       d->fe = dvb_attach(stv0900_attach, &prof_7500_stv0900_config,
+       d->fe_adap[0].fe = dvb_attach(stv0900_attach, &prof_7500_stv0900_config,
                                        &d->dev->i2c_adap, 0);
-       if (d->fe == NULL)
+       if (d->fe_adap[0].fe == NULL)
                return -EIO;
 
-       d->fe->ops.set_voltage = dw210x_set_voltage;
+       d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
 
        dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
 
@@ -1204,9 +1204,9 @@ static int su3000_frontend_attach(struct dvb_usb_adapter *d)
        if (dvb_usb_generic_rw(d->dev, obuf, 1, ibuf, 1, 0) < 0)
                err("command 0x51 transfer failed.");
 
-       d->fe = dvb_attach(ds3000_attach, &su3000_ds3000_config,
+       d->fe_adap[0].fe = dvb_attach(ds3000_attach, &su3000_ds3000_config,
                                        &d->dev->i2c_adap);
-       if (d->fe == NULL)
+       if (d->fe_adap[0].fe == NULL)
                return -EIO;
 
        info("Attached DS3000!\n");
@@ -1216,14 +1216,14 @@ static int su3000_frontend_attach(struct dvb_usb_adapter *d)
 
 static int dw2102_tuner_attach(struct dvb_usb_adapter *adap)
 {
-       dvb_attach(dvb_pll_attach, adap->fe, 0x60,
+       dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
                &adap->dev->i2c_adap, DVB_PLL_OPERA1);
        return 0;
 }
 
 static int dw3101_tuner_attach(struct dvb_usb_adapter *adap)
 {
-       dvb_attach(dvb_pll_attach, adap->fe, 0x60,
+       dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
                &adap->dev->i2c_adap, DVB_PLL_TUA6034);
 
        return 0;
@@ -1535,7 +1535,7 @@ static int dw2102_load_firmware(struct usb_device *dev,
                                        DW210X_READ_MSG);
                        if ((reset16[0] == 0xa1) || (reset16[0] == 0x80)) {
                                dw2102_properties.i2c_algo = &dw2102_i2c_algo;
-                               dw2102_properties.adapter->tuner_attach = &dw2102_tuner_attach;
+                               dw2102_properties.adapter->fe[0].tuner_attach = &dw2102_tuner_attach;
                                break;
                        } else {
                                /* check STV0288 frontend  */
@@ -1591,6 +1591,8 @@ static struct dvb_usb_device_properties dw2102_properties = {
        .read_mac_address = dw210x_read_mac_address,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .frontend_attach = dw2102_frontend_attach,
                        .stream = {
                                .type = USB_BULK,
@@ -1602,6 +1604,7 @@ static struct dvb_usb_device_properties dw2102_properties = {
                                        }
                                }
                        },
+               }},
                }
        },
        .num_device_descs = 3,
@@ -1642,6 +1645,8 @@ static struct dvb_usb_device_properties dw2104_properties = {
        .read_mac_address = dw210x_read_mac_address,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .frontend_attach = dw2104_frontend_attach,
                        .stream = {
                                .type = USB_BULK,
@@ -1653,6 +1658,7 @@ static struct dvb_usb_device_properties dw2104_properties = {
                                        }
                                }
                        },
+               }},
                }
        },
        .num_device_descs = 2,
@@ -1689,6 +1695,8 @@ static struct dvb_usb_device_properties dw3101_properties = {
        .read_mac_address = dw210x_read_mac_address,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .frontend_attach = dw3101_frontend_attach,
                        .tuner_attach = dw3101_tuner_attach,
                        .stream = {
@@ -1701,6 +1709,7 @@ static struct dvb_usb_device_properties dw3101_properties = {
                                        }
                                }
                        },
+               }},
                }
        },
        .num_device_descs = 1,
@@ -1733,6 +1742,8 @@ static struct dvb_usb_device_properties s6x0_properties = {
        .read_mac_address = s6x0_read_mac_address,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .frontend_attach = zl100313_frontend_attach,
                        .stream = {
                                .type = USB_BULK,
@@ -1744,6 +1755,7 @@ static struct dvb_usb_device_properties s6x0_properties = {
                                        }
                                }
                        },
+               }},
                }
        },
        .num_device_descs = 1,
@@ -1810,6 +1822,8 @@ static struct dvb_usb_device_properties su3000_properties = {
 
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .streaming_ctrl   = su3000_streaming_ctrl,
                        .frontend_attach  = su3000_frontend_attach,
                        .stream = {
@@ -1822,6 +1836,7 @@ static struct dvb_usb_device_properties su3000_properties = {
                                        }
                                }
                        }
+               }},
                }
        },
        .num_device_descs = 3,
@@ -1855,7 +1870,7 @@ static int dw2102_probe(struct usb_interface *intf,
        p1100->devices[0] = d1100;
        p1100->rc.legacy.rc_map_table = rc_map_tbs_table;
        p1100->rc.legacy.rc_map_size = ARRAY_SIZE(rc_map_tbs_table);
-       p1100->adapter->frontend_attach = stv0288_frontend_attach;
+       p1100->adapter->fe[0].frontend_attach = stv0288_frontend_attach;
 
        s660 = kzalloc(sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
        if (!s660) {
@@ -1869,7 +1884,7 @@ static int dw2102_probe(struct usb_interface *intf,
        s660->devices[0] = d660;
        s660->devices[1] = d480_1;
        s660->devices[2] = d480_2;
-       s660->adapter->frontend_attach = ds3000_frontend_attach;
+       s660->adapter->fe[0].frontend_attach = ds3000_frontend_attach;
 
        p7500 = kzalloc(sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
        if (!p7500) {
@@ -1883,7 +1898,7 @@ static int dw2102_probe(struct usb_interface *intf,
        p7500->devices[0] = d7500;
        p7500->rc.legacy.rc_map_table = rc_map_tbs_table;
        p7500->rc.legacy.rc_map_size = ARRAY_SIZE(rc_map_tbs_table);
-       p7500->adapter->frontend_attach = prof_7500_frontend_attach;
+       p7500->adapter->fe[0].frontend_attach = prof_7500_frontend_attach;
 
        if (0 == dvb_usb_device_init(intf, &dw2102_properties,
                        THIS_MODULE, NULL, adapter_nr) ||
index 1ba3e5dbee106b40049e2505b77e0b182cddcec4..78442fe4aa5ee60ac4a026c78abd35db8c37f4e3 100644 (file)
@@ -200,9 +200,9 @@ static struct ec100_config ec168_ec100_config = {
 static int ec168_ec100_frontend_attach(struct dvb_usb_adapter *adap)
 {
        deb_info("%s:\n", __func__);
-       adap->fe = dvb_attach(ec100_attach, &ec168_ec100_config,
+       adap->fe_adap[0].fe = dvb_attach(ec100_attach, &ec168_ec100_config,
                &adap->dev->i2c_adap);
-       if (adap->fe == NULL)
+       if (adap->fe_adap[0].fe == NULL)
                return -ENODEV;
 
        return 0;
@@ -228,7 +228,7 @@ static struct mxl5005s_config ec168_mxl5003s_config = {
 static int ec168_mxl5003s_tuner_attach(struct dvb_usb_adapter *adap)
 {
        deb_info("%s:\n", __func__);
-       return dvb_attach(mxl5005s_attach, adap->fe, &adap->dev->i2c_adap,
+       return dvb_attach(mxl5005s_attach, adap->fe_adap[0].fe, &adap->dev->i2c_adap,
                &ec168_mxl5003s_config) == NULL ? -ENODEV : 0;
 }
 
@@ -382,6 +382,8 @@ static struct dvb_usb_device_properties ec168_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .streaming_ctrl   = ec168_streaming_ctrl,
                        .frontend_attach  = ec168_ec100_frontend_attach,
                        .tuner_attach     = ec168_mxl5003s_tuner_attach,
@@ -395,6 +397,7 @@ static struct dvb_usb_device_properties ec168_properties = {
                                        }
                                }
                        },
+               }},
                }
        },
 
index 76159aed9bb084180d3276ec4feecbb630041e32..b092dc2137cd59798c0abaee9224f33219c33113 100644 (file)
@@ -403,8 +403,8 @@ static int friio_frontend_attach(struct dvb_usb_adapter *adap)
        if (friio_initialize(adap->dev) < 0)
                return -EIO;
 
-       adap->fe = jdvbt90502_attach(adap->dev);
-       if (adap->fe == NULL)
+       adap->fe_adap[0].fe = jdvbt90502_attach(adap->dev);
+       if (adap->fe_adap[0].fe == NULL)
                return -EIO;
 
        return 0;
@@ -473,6 +473,8 @@ static struct dvb_usb_device_properties friio_properties = {
                /* caps:0 =>  no pid filter, 188B TS packet */
                /* GL861 has a HW pid filter, but no info available. */
                {
+               .num_frontends = 1,
+               .fe = {{
                        .caps  = 0,
 
                        .frontend_attach  = friio_frontend_attach,
@@ -490,6 +492,7 @@ static struct dvb_usb_device_properties friio_properties = {
                                        }
                                }
                        },
+               }},
                }
        },
        .i2c_algo = &gl861_i2c_algo,
index 6f596ed41761ce927c6b2c6ba51e4aa40192f343..63681df244c4668e7a5b1aa4889be0ecfdb38603 100644 (file)
@@ -103,9 +103,9 @@ static struct zl10353_config gl861_zl10353_config = {
 static int gl861_frontend_attach(struct dvb_usb_adapter *adap)
 {
 
-       adap->fe = dvb_attach(zl10353_attach, &gl861_zl10353_config,
+       adap->fe_adap[0].fe = dvb_attach(zl10353_attach, &gl861_zl10353_config,
                &adap->dev->i2c_adap);
-       if (adap->fe == NULL)
+       if (adap->fe_adap[0].fe == NULL)
                return -EIO;
 
        return 0;
@@ -118,7 +118,7 @@ static struct qt1010_config gl861_qt1010_config = {
 static int gl861_tuner_attach(struct dvb_usb_adapter *adap)
 {
        return dvb_attach(qt1010_attach,
-                         adap->fe, &adap->dev->i2c_adap,
+                         adap->fe_adap[0].fe, &adap->dev->i2c_adap,
                          &gl861_qt1010_config) == NULL ? -ENODEV : 0;
 }
 
@@ -167,6 +167,8 @@ static struct dvb_usb_device_properties gl861_properties = {
 
        .num_adapters = 1,
        .adapter = {{
+               .num_frontends = 1,
+               .fe = {{
 
                .frontend_attach  = gl861_frontend_attach,
                .tuner_attach     = gl861_tuner_attach,
@@ -181,6 +183,7 @@ static struct dvb_usb_device_properties gl861_properties = {
                                }
                        }
                },
+               }},
        } },
        .i2c_algo         = &gl861_i2c_algo,
 
index 60d11e57e7d0fc5ee7b132c25eb45e02ef2679fb..5426267980c7567af09ed9646e58533e76e8df12 100644 (file)
@@ -144,19 +144,25 @@ static int gp8psk_fe_set_frontend(struct dvb_frontend* fe,
        cmd[6] = (freq >> 16) & 0xff;
        cmd[7] = (freq >> 24) & 0xff;
 
+       /* backwards compatibility: DVB-S + 8-PSK were used for Turbo-FEC */
+       if (c->delivery_system == SYS_DVBS && c->modulation == PSK_8)
+               c->delivery_system = SYS_TURBO;
+
        switch (c->delivery_system) {
        case SYS_DVBS:
-               /* Allow QPSK and 8PSK (even for DVB-S) */
-               if (c->modulation != QPSK && c->modulation != PSK_8) {
+               if (c->modulation != QPSK) {
                        deb_fe("%s: unsupported modulation selected (%d)\n",
                                __func__, c->modulation);
                        return -EOPNOTSUPP;
                }
                c->fec_inner = FEC_AUTO;
                break;
-       case SYS_DVBS2:
+       case SYS_DVBS2: /* kept for backwards compatibility */
                deb_fe("%s: DVB-S2 delivery system selected\n", __func__);
                break;
+       case SYS_TURBO:
+               deb_fe("%s: Turbo-FEC delivery system selected\n", __func__);
+               break;
 
        default:
                deb_fe("%s: unsupported delivery system selected (%d)\n",
@@ -189,7 +195,10 @@ static int gp8psk_fe_set_frontend(struct dvb_frontend* fe,
                default:
                        cmd[9] = 5; break;
                }
-               cmd[8] = ADV_MOD_DVB_QPSK;
+               if (c->delivery_system == SYS_TURBO)
+                       cmd[8] = ADV_MOD_TURBO_QPSK;
+               else
+                       cmd[8] = ADV_MOD_DVB_QPSK;
                break;
        case PSK_8: /* PSK_8 is for compatibility with DN */
                cmd[8] = ADV_MOD_TURBO_8PSK;
index 1cb3d9a66e02d6d09a694ee3cd0764b5250b45c1..5f71284703d07f88d2527b8216e82914a7e0ceb7 100644 (file)
@@ -230,7 +230,7 @@ static int gp8psk_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
 
 static int gp8psk_frontend_attach(struct dvb_usb_adapter *adap)
 {
-       adap->fe = gp8psk_fe_attach(adap->dev);
+       adap->fe_adap[0].fe = gp8psk_fe_attach(adap->dev);
        return 0;
 }
 
@@ -268,6 +268,8 @@ static struct dvb_usb_device_properties gp8psk_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .streaming_ctrl   = gp8psk_streaming_ctrl,
                        .frontend_attach  = gp8psk_frontend_attach,
                        /* parameter for the MPEG2-data transfer */
@@ -281,6 +283,7 @@ static struct dvb_usb_device_properties gp8psk_properties = {
                                        }
                                }
                        },
+               }},
                }
        },
        .power_ctrl       = gp8psk_power_ctrl,
diff --git a/drivers/media/dvb/dvb-usb/it913x.c b/drivers/media/dvb/dvb-usb/it913x.c
new file mode 100644 (file)
index 0000000..f027a2c
--- /dev/null
@@ -0,0 +1,651 @@
+/* DVB USB compliant linux driver for IT9137
+ *
+ * Copyright (C) 2011 Malcolm Priestley (tvboxspy@gmail.com)
+ * IT9137 (C) ITE Tech Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * see Documentation/dvb/README.dvb-usb for more information
+ * see Documentation/dvb/it9137.txt for firmware information
+ *
+ */
+#define DVB_USB_LOG_PREFIX "it913x"
+
+#include <linux/usb.h>
+#include <linux/usb/input.h>
+#include <media/rc-core.h>
+
+#include "dvb-usb.h"
+#include "it913x-fe.h"
+
+/* debug */
+static int dvb_usb_it913x_debug;
+#define l_dprintk(var, level, args...) do { \
+       if ((var >= level)) \
+               printk(KERN_DEBUG DVB_USB_LOG_PREFIX ": " args); \
+} while (0)
+
+#define deb_info(level, args...) l_dprintk(dvb_usb_it913x_debug, level, args)
+#define debug_data_snipet(level, name, p) \
+        deb_info(level, name" (%02x%02x%02x%02x%02x%02x%02x%02x)", \
+               *p, *(p+1), *(p+2), *(p+3), *(p+4), \
+                       *(p+5), *(p+6), *(p+7));
+
+
+module_param_named(debug, dvb_usb_it913x_debug, int, 0644);
+MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able))."
+                       DVB_USB_DEBUG_STATUS);
+
+static int pid_filter;
+module_param_named(pid, pid_filter, int, 0644);
+MODULE_PARM_DESC(pid, "set default 0=on 1=off");
+
+int cmd_counter;
+
+DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
+
+struct it913x_state {
+       u8 id;
+};
+
+static int it913x_bulk_write(struct usb_device *dev,
+                               u8 *snd, int len, u8 pipe)
+{
+       int ret, actual_l;
+
+       ret = usb_bulk_msg(dev, usb_sndbulkpipe(dev, pipe),
+                               snd, len , &actual_l, 100);
+       return ret;
+}
+
+static int it913x_bulk_read(struct usb_device *dev,
+                               u8 *rev, int len, u8 pipe)
+{
+       int ret, actual_l;
+
+       ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, pipe),
+                                rev, len , &actual_l, 200);
+       return ret;
+}
+
+static u16 check_sum(u8 *p, u8 len)
+{
+       u16 sum = 0;
+       u8 i = 1;
+       while (i < len)
+               sum += (i++ & 1) ? (*p++) << 8 : *p++;
+       return ~sum;
+}
+
+static int it913x_io(struct usb_device *udev, u8 mode, u8 pro,
+                       u8 cmd, u32 reg, u8 addr, u8 *data, u8 len)
+{
+       int ret = 0, i, buf_size = 1;
+       u8 *buff;
+       u8 rlen;
+       u16 chk_sum;
+
+       buff = kzalloc(256, GFP_KERNEL);
+       if (!buff) {
+               info("USB Buffer Failed");
+               return -ENOMEM;
+       }
+
+       buff[buf_size++] = pro;
+       buff[buf_size++] = cmd;
+       buff[buf_size++] = cmd_counter;
+
+       switch (mode) {
+       case READ_LONG:
+       case WRITE_LONG:
+               buff[buf_size++] = len;
+               buff[buf_size++] = 2;
+               buff[buf_size++] = (reg >> 24);
+               buff[buf_size++] = (reg >> 16) & 0xff;
+               buff[buf_size++] = (reg >> 8) & 0xff;
+               buff[buf_size++] = reg & 0xff;
+       break;
+       case READ_SHORT:
+               buff[buf_size++] = addr;
+               break;
+       case WRITE_SHORT:
+               buff[buf_size++] = len;
+               buff[buf_size++] = addr;
+               buff[buf_size++] = (reg >> 8) & 0xff;
+               buff[buf_size++] = reg & 0xff;
+       break;
+       case READ_DATA:
+       case WRITE_DATA:
+               break;
+       case WRITE_CMD:
+               mode = 7;
+               break;
+       default:
+               kfree(buff);
+               return -EINVAL;
+       }
+
+       if (mode & 1) {
+               for (i = 0; i < len ; i++)
+                       buff[buf_size++] = data[i];
+       }
+       chk_sum = check_sum(&buff[1], buf_size);
+
+       buff[buf_size++] = chk_sum >> 8;
+       buff[0] = buf_size;
+       buff[buf_size++] = (chk_sum & 0xff);
+
+       ret = it913x_bulk_write(udev, buff, buf_size , 0x02);
+
+       ret |= it913x_bulk_read(udev, buff, (mode & 1) ?
+                       5 : len + 5 , 0x01);
+
+       rlen = (mode & 0x1) ? 0x1 : len;
+
+       if (mode & 1)
+               ret |= buff[2];
+       else
+               memcpy(data, &buff[3], rlen);
+
+       cmd_counter++;
+
+       kfree(buff);
+
+       return (ret < 0) ? -ENODEV : 0;
+}
+
+static int it913x_wr_reg(struct usb_device *udev, u8 pro, u32 reg , u8 data)
+{
+       int ret;
+       u8 b[1];
+       b[0] = data;
+       ret = it913x_io(udev, WRITE_LONG, pro,
+                       CMD_DEMOD_WRITE, reg, 0, b, sizeof(b));
+
+       return ret;
+}
+
+static int it913x_read_reg(struct usb_device *udev, u32 reg)
+{
+       int ret;
+       u8 data[1];
+
+       ret = it913x_io(udev, READ_LONG, DEV_0,
+                       CMD_DEMOD_READ, reg, 0, &data[0], 1);
+
+       return (ret < 0) ? ret : data[0];
+}
+
+static u32 it913x_query(struct usb_device *udev, u8 pro)
+{
+       int ret;
+       u32 res = 0;
+       u8 data[4];
+       ret = it913x_io(udev, READ_LONG, pro, CMD_DEMOD_READ,
+               0x1222, 0, &data[0], 1);
+       if (data[0] == 0x1) {
+               ret = it913x_io(udev, READ_SHORT, pro,
+                       CMD_QUERYINFO, 0, 0x1, &data[0], 4);
+               res = (data[0] << 24) + (data[1] << 16) +
+                       (data[2] << 8) + data[3];
+       }
+
+       return (ret < 0) ? 0 : res;
+}
+
+static int it913x_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
+{
+       int ret = 0;
+       u8 pro = (adap->id == 0) ? DEV_0_DMOD : DEV_1_DMOD;
+
+       if (mutex_lock_interruptible(&adap->dev->i2c_mutex) < 0)
+                       return -EAGAIN;
+       deb_info(1, "PID_C  (%02x)", onoff);
+
+       if (!onoff)
+               ret = it913x_wr_reg(adap->dev->udev, pro, PID_RST, 0x1);
+
+       mutex_unlock(&adap->dev->i2c_mutex);
+       return ret;
+}
+
+static int it913x_pid_filter(struct dvb_usb_adapter *adap,
+               int index, u16 pid, int onoff)
+{
+       struct usb_device *udev = adap->dev->udev;
+       int ret = 0;
+       u8 pro = (adap->id == 0) ? DEV_0_DMOD : DEV_1_DMOD;
+
+       if (pid_filter > 0)
+               return 0;
+
+       if (mutex_lock_interruptible(&adap->dev->i2c_mutex) < 0)
+                       return -EAGAIN;
+       deb_info(1, "PID_F  (%02x)", onoff);
+       if (onoff) {
+               ret = it913x_wr_reg(udev, pro, PID_EN, 0x1);
+
+               ret |= it913x_wr_reg(udev, pro, PID_LSB, (u8)(pid & 0xff));
+
+               ret |= it913x_wr_reg(udev, pro, PID_MSB, (u8)(pid >> 8));
+
+               ret |= it913x_wr_reg(udev, pro, PID_INX_EN, (u8)onoff);
+
+               ret |= it913x_wr_reg(udev, pro, PID_INX, (u8)(index & 0x1f));
+
+       }
+
+       mutex_unlock(&adap->dev->i2c_mutex);
+       return 0;
+}
+
+
+static int it913x_return_status(struct usb_device *udev)
+{
+       u32 firm = 0;
+
+       firm = it913x_query(udev, DEV_0);
+       if (firm > 0)
+               info("Firmware Version %d", firm);
+
+       return (firm > 0) ? firm : 0;
+}
+
+static int it913x_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
+                                int num)
+{
+       struct dvb_usb_device *d = i2c_get_adapdata(adap);
+       static u8 data[256];
+       int ret;
+       u32 reg;
+       u8 pro;
+       if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
+                       return -EAGAIN;
+
+       debug_data_snipet(1, "Message out", msg[0].buf);
+       deb_info(2, "num of messages %d address %02x", num, msg[0].addr);
+
+       pro = (msg[0].addr & 0x2) ?  DEV_0_DMOD : 0x0;
+       pro |= (msg[0].addr & 0x20) ? DEV_1 : DEV_0;
+       memcpy(data, msg[0].buf, msg[0].len);
+       reg = (data[0] << 24) + (data[1] << 16) +
+                       (data[2] << 8) + data[3];
+       if (num == 2) {
+               ret = it913x_io(d->udev, READ_LONG, pro,
+                       CMD_DEMOD_READ, reg, 0, data, msg[1].len);
+               memcpy(msg[1].buf, data, msg[1].len);
+       } else
+               ret = it913x_io(d->udev, WRITE_LONG, pro, CMD_DEMOD_WRITE,
+                       reg, 0, &data[4], msg[0].len - 4);
+
+       mutex_unlock(&d->i2c_mutex);
+
+       return ret;
+}
+
+static u32 it913x_i2c_func(struct i2c_adapter *adapter)
+{
+       return I2C_FUNC_I2C;
+}
+
+static struct i2c_algorithm it913x_i2c_algo = {
+       .master_xfer   = it913x_i2c_xfer,
+       .functionality = it913x_i2c_func,
+};
+
+/* Callbacks for DVB USB */
+#define IT913X_POLL 250
+static int it913x_rc_query(struct dvb_usb_device *d)
+{
+       u8 ibuf[4];
+       int ret;
+       u32 key;
+       /* Avoid conflict with frontends*/
+       if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
+                       return -EAGAIN;
+
+       ret = it913x_io(d->udev, READ_LONG, PRO_LINK, CMD_IR_GET,
+               0, 0, &ibuf[0], sizeof(ibuf));
+
+       if ((ibuf[2] + ibuf[3]) == 0xff) {
+               key = ibuf[2];
+               key += ibuf[0] << 8;
+               deb_info(1, "INT Key =%08x", key);
+               if (d->rc_dev != NULL)
+                       rc_keydown(d->rc_dev, key, 0);
+       }
+       mutex_unlock(&d->i2c_mutex);
+
+       return ret;
+}
+static int it913x_identify_state(struct usb_device *udev,
+               struct dvb_usb_device_properties *props,
+               struct dvb_usb_device_description **desc,
+               int *cold)
+{
+       int ret = 0, firm_no;
+       u8 reg, adap, ep, tun0, tun1;
+
+       firm_no = it913x_return_status(udev);
+
+       ep = it913x_read_reg(udev, 0x49ac);
+       adap = it913x_read_reg(udev, 0x49c5);
+       tun0 = it913x_read_reg(udev, 0x49d0);
+       info("No. Adapters=%x Endpoints=%x Tuner Type=%x", adap, ep, tun0);
+
+       if (firm_no > 0) {
+               *cold = 0;
+               return 0;
+       }
+
+       if (adap > 2) {
+               tun1 = it913x_read_reg(udev, 0x49e0);
+               ret = it913x_wr_reg(udev, DEV_0, GPIOH1_EN, 0x1);
+               ret |= it913x_wr_reg(udev, DEV_0, GPIOH1_ON, 0x1);
+               ret |= it913x_wr_reg(udev, DEV_0, GPIOH1_O, 0x1);
+               msleep(50); /* Delay noticed reset cycle ? */
+               ret |= it913x_wr_reg(udev, DEV_0, GPIOH1_O, 0x0);
+               msleep(50);
+               reg = it913x_read_reg(udev, GPIOH1_O);
+               if (reg == 0) {
+                       ret |= it913x_wr_reg(udev, DEV_0,  GPIOH1_O, 0x1);
+                       ret |= it913x_return_status(udev);
+                       if (ret != 0)
+                               ret = it913x_wr_reg(udev, DEV_0,
+                                       GPIOH1_O, 0x0);
+               }
+       } else
+               props->num_adapters = 1;
+
+       reg = it913x_read_reg(udev, IO_MUX_POWER_CLK);
+
+       ret |= it913x_wr_reg(udev, DEV_0, 0x4bfb, CHIP2_I2C_ADDR);
+
+       ret |= it913x_wr_reg(udev, DEV_0,  CLK_O_EN, 0x1);
+
+       *cold = 1;
+
+       return (ret < 0) ? -ENODEV : 0;
+}
+
+static int it913x_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
+{
+       int ret = 0;
+       u8 pro = (adap->id == 0) ? DEV_0_DMOD : DEV_1_DMOD;
+
+       if (mutex_lock_interruptible(&adap->dev->i2c_mutex) < 0)
+                       return -EAGAIN;
+       deb_info(1, "STM  (%02x)", onoff);
+
+       if (!onoff)
+               ret = it913x_wr_reg(adap->dev->udev, pro, PID_RST, 0x1);
+
+
+       mutex_unlock(&adap->dev->i2c_mutex);
+
+       return ret;
+}
+
+
+static int it913x_download_firmware(struct usb_device *udev,
+                                       const struct firmware *fw)
+{
+       int ret = 0, i;
+       u8 packet_size, dlen, tun1;
+       u8 *fw_data;
+
+       packet_size = 0x29;
+
+       tun1 = it913x_read_reg(udev, 0x49e0);
+
+       ret = it913x_wr_reg(udev, DEV_0,  I2C_CLK, I2C_CLK_100);
+
+       info("FRM Starting Firmware Download");
+       /* This uses scatter write firmware headers follow */
+       /* 03 XX 00     XX = chip number? */ 
+
+       for (i = 0; i < fw->size; i += packet_size) {
+                       if (i > 0)
+                               packet_size = 0x39;
+                       fw_data = (u8 *)(fw->data + i);
+                       dlen = ((i + packet_size) > fw->size)
+                               ? (fw->size - i) : packet_size;
+                       ret |= it913x_io(udev, WRITE_DATA, DEV_0,
+                               CMD_SCATTER_WRITE, 0, 0, fw_data, dlen);
+                       udelay(1000);
+       }
+
+       ret |= it913x_io(udev, WRITE_CMD, DEV_0,
+                       CMD_BOOT, 0, 0, NULL, 0);
+
+       msleep(100);
+
+       if (ret < 0)
+               info("FRM Firmware Download Failed (%04x)" , ret);
+       else
+               info("FRM Firmware Download Completed - Resetting Device");
+
+       ret |= it913x_return_status(udev);
+
+       msleep(30);
+
+       ret |= it913x_wr_reg(udev, DEV_0,  I2C_CLK, I2C_CLK_400);
+
+       /* Tuner function */
+       ret |= it913x_wr_reg(udev, DEV_0_DMOD , 0xec4c, 0xa0);
+
+       ret |= it913x_wr_reg(udev, DEV_0,  PADODPU, 0x0);
+       ret |= it913x_wr_reg(udev, DEV_0,  AGC_O_D, 0x0);
+       if (tun1 > 0) {
+               ret |= it913x_wr_reg(udev, DEV_1,  PADODPU, 0x0);
+               ret |= it913x_wr_reg(udev, DEV_1,  AGC_O_D, 0x0);
+       }
+
+       return (ret < 0) ? -ENODEV : 0;
+}
+
+static int it913x_name(struct dvb_usb_adapter *adap)
+{
+       const char *desc = adap->dev->desc->name;
+       char *fe_name[] = {"_1", "_2", "_3", "_4"};
+       char *name = adap->fe_adap[0].fe->ops.info.name;
+
+       strlcpy(name, desc, 128);
+       strlcat(name, fe_name[adap->id], 128);
+
+       return 0;
+}
+
+static int it913x_frontend_attach(struct dvb_usb_adapter *adap)
+{
+       struct usb_device *udev = adap->dev->udev;
+       int ret = 0;
+       u8 adf = it913x_read_reg(udev, IO_MUX_POWER_CLK);
+       u8 adap_addr = I2C_BASE_ADDR + (adap->id << 5);
+       u16 ep_size = adap->props.fe[0].stream.u.bulk.buffersize;
+
+       adap->fe_adap[0].fe = dvb_attach(it913x_fe_attach,
+               &adap->dev->i2c_adap, adap_addr, adf, IT9137);
+
+       if (adap->id == 0 && adap->fe_adap[0].fe) {
+               ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2_SW_RST, 0x1);
+               ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2IF2_SW_RST, 0x1);
+               ret = it913x_wr_reg(udev, DEV_0, EP0_TX_EN, 0x0f);
+               ret = it913x_wr_reg(udev, DEV_0, EP0_TX_NAK, 0x1b);
+               ret = it913x_wr_reg(udev, DEV_0, EP0_TX_EN, 0x2f);
+               ret = it913x_wr_reg(udev, DEV_0, EP4_TX_LEN_LSB,
+                                       ep_size & 0xff);
+               ret = it913x_wr_reg(udev, DEV_0, EP4_TX_LEN_MSB, ep_size >> 8);
+               ret = it913x_wr_reg(udev, DEV_0, EP4_MAX_PKT, 0x80);
+       } else if (adap->id == 1 && adap->fe_adap[0].fe) {
+               ret = it913x_wr_reg(udev, DEV_0, EP0_TX_EN, 0x6f);
+               ret = it913x_wr_reg(udev, DEV_0, EP5_TX_LEN_LSB,
+                                       ep_size & 0xff);
+               ret = it913x_wr_reg(udev, DEV_0, EP5_TX_LEN_MSB, ep_size >> 8);
+               ret = it913x_wr_reg(udev, DEV_0, EP5_MAX_PKT, 0x80);
+               ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2IF2_EN, 0x1);
+               ret = it913x_wr_reg(udev, DEV_1_DMOD, MP2IF_SERIAL, 0x1);
+               ret = it913x_wr_reg(udev, DEV_1, TOP_HOSTB_SER_MODE, 0x1);
+               ret = it913x_wr_reg(udev, DEV_0_DMOD, TSIS_ENABLE, 0x1);
+               ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2_SW_RST, 0x0);
+               ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2IF2_SW_RST, 0x0);
+               ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2IF2_HALF_PSB, 0x0);
+               ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2IF_STOP_EN, 0x1);
+               ret = it913x_wr_reg(udev, DEV_1_DMOD, MPEG_FULL_SPEED, 0x0);
+               ret = it913x_wr_reg(udev, DEV_1_DMOD, MP2IF_STOP_EN, 0x0);
+       } else
+               return -ENODEV;
+
+       ret = it913x_name(adap);
+
+       return ret;
+}
+
+/* DVB USB Driver */
+static struct dvb_usb_device_properties it913x_properties;
+
+static int it913x_probe(struct usb_interface *intf,
+               const struct usb_device_id *id)
+{
+       cmd_counter = 0;
+       if (0 == dvb_usb_device_init(intf, &it913x_properties,
+                                    THIS_MODULE, NULL, adapter_nr)) {
+               info("DEV registering device driver");
+               return 0;
+       }
+
+       info("DEV it913x Error");
+       return -ENODEV;
+
+}
+
+static struct usb_device_id it913x_table[] = {
+       { USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_UB499_2T_T09) },
+       {}              /* Terminating entry */
+};
+
+MODULE_DEVICE_TABLE(usb, it913x_table);
+
+static struct dvb_usb_device_properties it913x_properties = {
+       .caps = DVB_USB_IS_AN_I2C_ADAPTER,
+       .usb_ctrl = DEVICE_SPECIFIC,
+       .download_firmware = it913x_download_firmware,
+       .firmware = "dvb-usb-it9137-01.fw",
+       .no_reconnect = 1,
+       .size_of_priv = sizeof(struct it913x_state),
+       .num_adapters = 2,
+       .adapter = {
+               {
+               .num_frontends = 1,
+               .fe = {{
+                       .caps = DVB_USB_ADAP_HAS_PID_FILTER|
+                               DVB_USB_ADAP_NEED_PID_FILTERING|
+                               DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
+                       .streaming_ctrl   = it913x_streaming_ctrl,
+                       .pid_filter_count = 31,
+                       .pid_filter = it913x_pid_filter,
+                       .pid_filter_ctrl  = it913x_pid_filter_ctrl,
+                       .frontend_attach  = it913x_frontend_attach,
+                       /* parameter for the MPEG2-data transfer */
+                       .stream = {
+                               .type = USB_BULK,
+                               .count = 10,
+                               .endpoint = 0x04,
+                               .u = {/* Keep Low if PID filter on */
+                                       .bulk = {
+                                               .buffersize = 3584,
+
+                                       }
+                               }
+                       }
+               }},
+               },
+                       {
+               .num_frontends = 1,
+               .fe = {{
+                       .caps = DVB_USB_ADAP_HAS_PID_FILTER|
+                               DVB_USB_ADAP_NEED_PID_FILTERING|
+                               DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
+                       .streaming_ctrl   = it913x_streaming_ctrl,
+                       .pid_filter_count = 31,
+                       .pid_filter = it913x_pid_filter,
+                       .pid_filter_ctrl  = it913x_pid_filter_ctrl,
+                       .frontend_attach  = it913x_frontend_attach,
+                       /* parameter for the MPEG2-data transfer */
+                       .stream = {
+                               .type = USB_BULK,
+                               .count = 5,
+                               .endpoint = 0x05,
+                               .u = {
+                                       .bulk = {
+                                               .buffersize = 3584,
+
+                                       }
+                               }
+                       }
+               }},
+               }
+       },
+       .identify_state   = it913x_identify_state,
+       .rc.core = {
+               .protocol       = RC_TYPE_NEC,
+               .module_name    = "it913x",
+               .rc_query       = it913x_rc_query,
+               .rc_interval    = IT913X_POLL,
+               .allowed_protos = RC_TYPE_NEC,
+               .rc_codes       = RC_MAP_KWORLD_315U,
+       },
+       .i2c_algo         = &it913x_i2c_algo,
+       .num_device_descs = 1,
+       .devices = {
+               {   "Kworld UB499-2T T09(IT9137)",
+                       { &it913x_table[0], NULL },
+                       },
+
+       }
+};
+
+static struct usb_driver it913x_driver = {
+       .name           = "it913x",
+       .probe          = it913x_probe,
+       .disconnect     = dvb_usb_device_exit,
+       .id_table       = it913x_table,
+};
+
+/* module stuff */
+static int __init it913x_module_init(void)
+{
+       int result = usb_register(&it913x_driver);
+       if (result) {
+               err("usb_register failed. Error number %d", result);
+               return result;
+       }
+
+       return 0;
+}
+
+static void __exit it913x_module_exit(void)
+{
+       /* deregister this driver from the USB subsystem */
+       usb_deregister(&it913x_driver);
+}
+
+module_init(it913x_module_init);
+module_exit(it913x_module_exit);
+
+MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>");
+MODULE_DESCRIPTION("it913x USB 2 Driver");
+MODULE_VERSION("1.06");
+MODULE_LICENSE("GPL");
index 37b146961ae2d00d185e5b7c992096e66531a2f0..b9228240f5ce4c84b8ae1ef8659c52a4ace9fda3 100644 (file)
@@ -162,7 +162,7 @@ static int lme2510_usb_talk(struct dvb_usb_device *d,
        int ret = 0;
 
        if (st->usb_buffer == NULL) {
-               st->usb_buffer = kmalloc(512, GFP_KERNEL);
+               st->usb_buffer = kmalloc(64, GFP_KERNEL);
                if (st->usb_buffer == NULL) {
                        info("MEM Error no memory");
                        return -ENOMEM;
@@ -175,8 +175,8 @@ static int lme2510_usb_talk(struct dvb_usb_device *d,
        if (ret < 0)
                return -EAGAIN;
 
-       /* the read/write capped at 512 */
-       memcpy(buff, wbuf, (wlen > 512) ? 512 : wlen);
+       /* the read/write capped at 64 */
+       memcpy(buff, wbuf, (wlen < 64) ? wlen : 64);
 
        ret |= usb_clear_halt(d->udev, usb_sndbulkpipe(d->udev, 0x01));
 
@@ -186,8 +186,8 @@ static int lme2510_usb_talk(struct dvb_usb_device *d,
 
        ret |= usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x01));
 
-       ret |= lme2510_bulk_read(d->udev, buff, (rlen > 512) ?
-                       512 : rlen , 0x01);
+       ret |= lme2510_bulk_read(d->udev, buff, (rlen < 64) ?
+                       rlen : 64 , 0x01);
 
        if (rlen > 0)
                memcpy(rbuf, buff, rlen);
@@ -333,7 +333,7 @@ static int lme2510_int_read(struct dvb_usb_adapter *adap)
        if (lme_int->lme_urb == NULL)
                        return -ENOMEM;
 
-       lme_int->buffer = usb_alloc_coherent(adap->dev->udev, 5000, GFP_ATOMIC,
+       lme_int->buffer = usb_alloc_coherent(adap->dev->udev, 128, GFP_ATOMIC,
                                        &lme_int->lme_urb->transfer_dma);
 
        if (lme_int->buffer == NULL)
@@ -343,10 +343,10 @@ static int lme2510_int_read(struct dvb_usb_adapter *adap)
                                adap->dev->udev,
                                usb_rcvintpipe(adap->dev->udev, 0xa),
                                lme_int->buffer,
-                               4096,
+                               128,
                                lme2510_int_response,
                                adap,
-                               11);
+                               8);
 
        lme_int->lme_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
 
@@ -580,7 +580,7 @@ static int lme2510_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
 {
        struct dvb_usb_device *d = i2c_get_adapdata(adap);
        struct lme2510_state *st = d->priv;
-       static u8 obuf[64], ibuf[512];
+       static u8 obuf[64], ibuf[64];
        int i, read, read_o;
        u16 len;
        u8 gate = st->i2c_gate;
@@ -621,7 +621,7 @@ static int lme2510_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
                        len = msg[i].len+3;
                }
 
-               if (lme2510_msg(d, obuf, len, ibuf, 512) < 0) {
+               if (lme2510_msg(d, obuf, len, ibuf, 64) < 0) {
                        deb_info(1, "i2c transfer failed.");
                        return -EAGAIN;
                }
@@ -941,7 +941,7 @@ static int lme_name(struct dvb_usb_adapter *adap)
        const char *desc = adap->dev->desc->name;
        char *fe_name[] = {"", " LG TDQY-P001F", " SHARP:BS2F7HZ7395",
                                " SHARP:BS2F7HZ0194"};
-       char *name = adap->fe->ops.info.name;
+       char *name = adap->fe_adap[0].fe->ops.info.name;
 
        strlcpy(name, desc, 128);
        strlcat(name, fe_name[st->tuner_config], 128);
@@ -958,10 +958,10 @@ static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter *adap)
        st->i2c_talk_onoff = 1;
 
        st->i2c_gate = 4;
-       adap->fe = dvb_attach(tda10086_attach, &tda10086_config,
+       adap->fe_adap[0].fe = dvb_attach(tda10086_attach, &tda10086_config,
                &adap->dev->i2c_adap);
 
-       if (adap->fe) {
+       if (adap->fe_adap[0].fe) {
                info("TUN Found Frontend TDA10086");
                st->i2c_tuner_gate_w = 4;
                st->i2c_tuner_gate_r = 4;
@@ -975,9 +975,9 @@ static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter *adap)
        }
 
        st->i2c_gate = 4;
-       adap->fe = dvb_attach(stv0299_attach, &sharp_z0194_config,
+       adap->fe_adap[0].fe = dvb_attach(stv0299_attach, &sharp_z0194_config,
                        &adap->dev->i2c_adap);
-       if (adap->fe) {
+       if (adap->fe_adap[0].fe) {
                info("FE Found Stv0299");
                st->i2c_tuner_gate_w = 4;
                st->i2c_tuner_gate_r = 5;
@@ -991,9 +991,9 @@ static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter *adap)
        }
 
        st->i2c_gate = 5;
-       adap->fe = dvb_attach(stv0288_attach, &lme_config,
+       adap->fe_adap[0].fe = dvb_attach(stv0288_attach, &lme_config,
                        &adap->dev->i2c_adap);
-       if (adap->fe) {
+       if (adap->fe_adap[0].fe) {
                info("FE Found Stv0288");
                st->i2c_tuner_gate_w = 4;
                st->i2c_tuner_gate_r = 5;
@@ -1010,15 +1010,15 @@ static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter *adap)
 
 
 end:   if (ret) {
-               if (adap->fe) {
-                       dvb_frontend_detach(adap->fe);
-                       adap->fe = NULL;
+               if (adap->fe_adap[0].fe) {
+                       dvb_frontend_detach(adap->fe_adap[0].fe);
+                       adap->fe_adap[0].fe = NULL;
                }
                adap->dev->props.rc.core.rc_codes = NULL;
                return -ENODEV;
        }
 
-       adap->fe->ops.set_voltage = dm04_lme2510_set_voltage;
+       adap->fe_adap[0].fe->ops.set_voltage = dm04_lme2510_set_voltage;
        ret = lme_name(adap);
        return ret;
 }
@@ -1031,17 +1031,17 @@ static int dm04_lme2510_tuner(struct dvb_usb_adapter *adap)
 
        switch (st->tuner_config) {
        case TUNER_LG:
-               if (dvb_attach(tda826x_attach, adap->fe, 0xc0,
+               if (dvb_attach(tda826x_attach, adap->fe_adap[0].fe, 0xc0,
                        &adap->dev->i2c_adap, 1))
                        ret = st->tuner_config;
                break;
        case TUNER_S7395:
-               if (dvb_attach(ix2505v_attach , adap->fe, &lme_tuner,
+               if (dvb_attach(ix2505v_attach , adap->fe_adap[0].fe, &lme_tuner,
                        &adap->dev->i2c_adap))
                        ret = st->tuner_config;
                break;
        case TUNER_S0194:
-               if (dvb_attach(dvb_pll_attach , adap->fe, 0xc0,
+               if (dvb_attach(dvb_pll_attach , adap->fe_adap[0].fe, 0xc0,
                        &adap->dev->i2c_adap, DVB_PLL_OPERA1))
                        ret = st->tuner_config;
                break;
@@ -1145,6 +1145,8 @@ static struct dvb_usb_device_properties lme2510_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .caps = DVB_USB_ADAP_HAS_PID_FILTER|
                                DVB_USB_ADAP_NEED_PID_FILTERING|
                                DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
@@ -1166,6 +1168,7 @@ static struct dvb_usb_device_properties lme2510_properties = {
                                        }
                                }
                        }
+               }},
                }
        },
        .rc.core = {
@@ -1193,6 +1196,8 @@ static struct dvb_usb_device_properties lme2510c_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .caps = DVB_USB_ADAP_HAS_PID_FILTER|
                                DVB_USB_ADAP_NEED_PID_FILTERING|
                                DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
@@ -1214,6 +1219,7 @@ static struct dvb_usb_device_properties lme2510c_properties = {
                                        }
                                }
                        }
+               }},
                }
        },
        .rc.core = {
@@ -1241,7 +1247,7 @@ static void *lme2510_exit_int(struct dvb_usb_device *d)
        void *buffer = NULL;
 
        if (adap != NULL) {
-               lme2510_kill_urb(&adap->stream);
+               lme2510_kill_urb(&adap->fe_adap[0].stream);
                adap->feedcount = 0;
        }
 
@@ -1255,7 +1261,7 @@ static void *lme2510_exit_int(struct dvb_usb_device *d)
 
        if (st->lme_urb != NULL) {
                usb_kill_urb(st->lme_urb);
-               usb_free_coherent(d->udev, 5000, st->buffer,
+               usb_free_coherent(d->udev, 128, st->buffer,
                                  st->lme_urb->transfer_dma);
                info("Interrupt Service Stopped");
        }
@@ -1306,5 +1312,5 @@ module_exit(lme2510_module_exit);
 
 MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>");
 MODULE_DESCRIPTION("LME2510(C) DVB-S USB2.0");
-MODULE_VERSION("1.88");
+MODULE_VERSION("1.90");
 MODULE_LICENSE("GPL");
index 9456792f219be5530baf9830257a8f3efb28737f..a1e1287c949edcf4f150d2779e3e9f59efcb4531 100644 (file)
@@ -86,12 +86,12 @@ static int m920x_init(struct dvb_usb_device *d, struct m920x_inits *rc_seq)
        }
 
        for (i = 0; i < d->props.num_adapters; i++)
-               flags |= d->adapter[i].props.caps;
+               flags |= d->adapter[i].props.fe[0].caps;
 
        /* Some devices(Dposh) might crash if we attempt touch at all. */
        if (flags & DVB_USB_ADAP_HAS_PID_FILTER) {
                for (i = 0; i < d->props.num_adapters; i++) {
-                       epi = d->adapter[i].props.stream.endpoint - 0x81;
+                       epi = d->adapter[i].props.fe[0].stream.endpoint - 0x81;
 
                        if (epi < 0 || epi >= M9206_MAX_ADAPTERS) {
                                printk(KERN_INFO "m920x: Unexpected adapter endpoint!\n");
@@ -292,7 +292,7 @@ static int m920x_update_filters(struct dvb_usb_adapter *adap)
        struct m920x_state *m = adap->dev->priv;
        int enabled = m->filtering_enabled[adap->id];
        int i, ret = 0, filter = 0;
-       int ep = adap->props.stream.endpoint;
+       int ep = adap->props.fe[0].stream.endpoint;
 
        for (i = 0; i < M9206_MAX_FILTERS; i++)
                if (m->filters[adap->id][i] == 8192)
@@ -501,9 +501,10 @@ static int m920x_mt352_frontend_attach(struct dvb_usb_adapter *adap)
 {
        deb("%s\n",__func__);
 
-       if ((adap->fe = dvb_attach(mt352_attach,
-                                  &m920x_mt352_config,
-                                  &adap->dev->i2c_adap)) == NULL)
+       adap->fe_adap[0].fe = dvb_attach(mt352_attach,
+                                        &m920x_mt352_config,
+                                        &adap->dev->i2c_adap);
+       if ((adap->fe_adap[0].fe) == NULL)
                return -EIO;
 
        return 0;
@@ -513,9 +514,10 @@ static int m920x_tda10046_08_frontend_attach(struct dvb_usb_adapter *adap)
 {
        deb("%s\n",__func__);
 
-       if ((adap->fe = dvb_attach(tda10046_attach,
-                                  &m920x_tda10046_08_config,
-                                  &adap->dev->i2c_adap)) == NULL)
+       adap->fe_adap[0].fe = dvb_attach(tda10046_attach,
+                                        &m920x_tda10046_08_config,
+                                        &adap->dev->i2c_adap);
+       if ((adap->fe_adap[0].fe) == NULL)
                return -EIO;
 
        return 0;
@@ -525,9 +527,10 @@ static int m920x_tda10046_0b_frontend_attach(struct dvb_usb_adapter *adap)
 {
        deb("%s\n",__func__);
 
-       if ((adap->fe = dvb_attach(tda10046_attach,
-                                  &m920x_tda10046_0b_config,
-                                  &adap->dev->i2c_adap)) == NULL)
+       adap->fe_adap[0].fe = dvb_attach(tda10046_attach,
+                                        &m920x_tda10046_0b_config,
+                                        &adap->dev->i2c_adap);
+       if ((adap->fe_adap[0].fe) == NULL)
                return -EIO;
 
        return 0;
@@ -537,7 +540,7 @@ static int m920x_qt1010_tuner_attach(struct dvb_usb_adapter *adap)
 {
        deb("%s\n",__func__);
 
-       if (dvb_attach(qt1010_attach, adap->fe, &adap->dev->i2c_adap, &m920x_qt1010_config) == NULL)
+       if (dvb_attach(qt1010_attach, adap->fe_adap[0].fe, &adap->dev->i2c_adap, &m920x_qt1010_config) == NULL)
                return -ENODEV;
 
        return 0;
@@ -547,7 +550,7 @@ static int m920x_tda8275_60_tuner_attach(struct dvb_usb_adapter *adap)
 {
        deb("%s\n",__func__);
 
-       if (dvb_attach(tda827x_attach, adap->fe, 0x60, &adap->dev->i2c_adap, NULL) == NULL)
+       if (dvb_attach(tda827x_attach, adap->fe_adap[0].fe, 0x60, &adap->dev->i2c_adap, NULL) == NULL)
                return -ENODEV;
 
        return 0;
@@ -557,7 +560,7 @@ static int m920x_tda8275_61_tuner_attach(struct dvb_usb_adapter *adap)
 {
        deb("%s\n",__func__);
 
-       if (dvb_attach(tda827x_attach, adap->fe, 0x61, &adap->dev->i2c_adap, NULL) == NULL)
+       if (dvb_attach(tda827x_attach, adap->fe_adap[0].fe, 0x61, &adap->dev->i2c_adap, NULL) == NULL)
                return -ENODEV;
 
        return 0;
@@ -565,7 +568,7 @@ static int m920x_tda8275_61_tuner_attach(struct dvb_usb_adapter *adap)
 
 static int m920x_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap)
 {
-       dvb_attach(simple_tuner_attach, adap->fe,
+       dvb_attach(simple_tuner_attach, adap->fe_adap[0].fe,
                   &adap->dev->i2c_adap, 0x61,
                   TUNER_PHILIPS_FMD1216ME_MK3);
        return 0;
@@ -807,6 +810,9 @@ static struct dvb_usb_device_properties megasky_properties = {
        .identify_state   = m920x_identify_state,
        .num_adapters = 1,
        .adapter = {{
+               .num_frontends = 1,
+               .fe = {{
+
                .caps = DVB_USB_ADAP_HAS_PID_FILTER |
                        DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
 
@@ -827,6 +833,7 @@ static struct dvb_usb_device_properties megasky_properties = {
                                }
                        }
                },
+               }},
        }},
        .i2c_algo         = &m920x_i2c_algo,
 
@@ -851,6 +858,9 @@ static struct dvb_usb_device_properties digivox_mini_ii_properties = {
        .identify_state   = m920x_identify_state,
        .num_adapters = 1,
        .adapter = {{
+               .num_frontends = 1,
+               .fe = {{
+
                .caps = DVB_USB_ADAP_HAS_PID_FILTER |
                        DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
 
@@ -871,6 +881,7 @@ static struct dvb_usb_device_properties digivox_mini_ii_properties = {
                                }
                        }
                },
+               }},
        }},
        .i2c_algo         = &m920x_i2c_algo,
 
@@ -910,6 +921,9 @@ static struct dvb_usb_device_properties tvwalkertwin_properties = {
        .identify_state   = m920x_identify_state,
        .num_adapters = 2,
        .adapter = {{
+               .num_frontends = 1,
+               .fe = {{
+
                .caps = DVB_USB_ADAP_HAS_PID_FILTER |
                        DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
 
@@ -929,7 +943,11 @@ static struct dvb_usb_device_properties tvwalkertwin_properties = {
                                         .buffersize = 512,
                                 }
                        }
+               }},
                }},{
+               .num_frontends = 1,
+               .fe = {{
+
                .caps = DVB_USB_ADAP_HAS_PID_FILTER |
                        DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
 
@@ -949,6 +967,7 @@ static struct dvb_usb_device_properties tvwalkertwin_properties = {
                                         .buffersize = 512,
                                 }
                        }
+               }},
                },
        }},
        .i2c_algo         = &m920x_i2c_algo,
@@ -974,6 +993,8 @@ static struct dvb_usb_device_properties dposh_properties = {
        .identify_state   = m920x_identify_state,
        .num_adapters = 1,
        .adapter = {{
+               .num_frontends = 1,
+               .fe = {{
                /* Hardware pid filters don't work with this device/firmware */
 
                .frontend_attach  = m920x_mt352_frontend_attach,
@@ -989,6 +1010,7 @@ static struct dvb_usb_device_properties dposh_properties = {
                                 }
                        }
                },
+               }},
        }},
        .i2c_algo         = &m920x_i2c_algo,
 
@@ -1019,6 +1041,9 @@ static struct dvb_usb_device_properties pinnacle_pctv310e_properties = {
        .identify_state   = m920x_identify_state,
        .num_adapters = 1,
        .adapter = {{
+               .num_frontends = 1,
+               .fe = {{
+
                .caps = DVB_USB_ADAP_HAS_PID_FILTER |
                        DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
 
@@ -1041,6 +1066,7 @@ static struct dvb_usb_device_properties pinnacle_pctv310e_properties = {
                                }
                        }
                },
+               }},
        } },
        .i2c_algo         = &m920x_i2c_algo,
 
diff --git a/drivers/media/dvb/dvb-usb/mxl111sf-gpio.c b/drivers/media/dvb/dvb-usb/mxl111sf-gpio.c
new file mode 100644 (file)
index 0000000..e4121cb
--- /dev/null
@@ -0,0 +1,763 @@
+/*
+ *  mxl111sf-gpio.c - driver for the MaxLinear MXL111SF
+ *
+ *  Copyright (C) 2010 Michael Krufky <mkrufky@kernellabs.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include "mxl111sf-gpio.h"
+#include "mxl111sf-i2c.h"
+#include "mxl111sf.h"
+
+/* ------------------------------------------------------------------------- */
+
+#define MXL_GPIO_MUX_REG_0 0x84
+#define MXL_GPIO_MUX_REG_1 0x89
+#define MXL_GPIO_MUX_REG_2 0x82
+
+#define MXL_GPIO_DIR_INPUT  0
+#define MXL_GPIO_DIR_OUTPUT 1
+
+
+static int mxl111sf_set_gpo_state(struct mxl111sf_state *state, u8 pin, u8 val)
+{
+       int ret;
+       u8 tmp;
+
+       mxl_debug_adv("(%d, %d)", pin, val);
+
+       if ((pin > 0) && (pin < 8)) {
+               ret = mxl111sf_read_reg(state, 0x19, &tmp);
+               if (mxl_fail(ret))
+                       goto fail;
+               tmp &= ~(1 << (pin - 1));
+               tmp |= (val << (pin - 1));
+               ret = mxl111sf_write_reg(state, 0x19, tmp);
+               if (mxl_fail(ret))
+                       goto fail;
+       } else if (pin <= 10) {
+               if (pin == 0)
+                       pin += 7;
+               ret = mxl111sf_read_reg(state, 0x30, &tmp);
+               if (mxl_fail(ret))
+                       goto fail;
+               tmp &= ~(1 << (pin - 3));
+               tmp |= (val << (pin - 3));
+               ret = mxl111sf_write_reg(state, 0x30, tmp);
+               if (mxl_fail(ret))
+                       goto fail;
+       } else
+               ret = -EINVAL;
+fail:
+       return ret;
+}
+
+static int mxl111sf_get_gpi_state(struct mxl111sf_state *state, u8 pin, u8 *val)
+{
+       int ret;
+       u8 tmp;
+
+       mxl_debug("(0x%02x)", pin);
+
+       *val = 0;
+
+       switch (pin) {
+       case 0:
+       case 1:
+       case 2:
+       case 3:
+               ret = mxl111sf_read_reg(state, 0x23, &tmp);
+               if (mxl_fail(ret))
+                       goto fail;
+               *val = (tmp >> (pin + 4)) & 0x01;
+               break;
+       case 4:
+       case 5:
+       case 6:
+       case 7:
+               ret = mxl111sf_read_reg(state, 0x2f, &tmp);
+               if (mxl_fail(ret))
+                       goto fail;
+               *val = (tmp >> pin) & 0x01;
+               break;
+       case 8:
+       case 9:
+       case 10:
+               ret = mxl111sf_read_reg(state, 0x22, &tmp);
+               if (mxl_fail(ret))
+                       goto fail;
+               *val = (tmp >> (pin - 3)) & 0x01;
+               break;
+       default:
+               return -EINVAL; /* invalid pin */
+       }
+fail:
+       return ret;
+}
+
+struct mxl_gpio_cfg {
+       u8 pin;
+       u8 dir;
+       u8 val;
+};
+
+static int mxl111sf_config_gpio_pins(struct mxl111sf_state *state,
+                                    struct mxl_gpio_cfg *gpio_cfg)
+{
+       int ret;
+       u8 tmp;
+
+       mxl_debug_adv("(%d, %d)", gpio_cfg->pin, gpio_cfg->dir);
+
+       switch (gpio_cfg->pin) {
+       case 0:
+       case 1:
+       case 2:
+       case 3:
+               ret = mxl111sf_read_reg(state, MXL_GPIO_MUX_REG_0, &tmp);
+               if (mxl_fail(ret))
+                       goto fail;
+               tmp &= ~(1 << (gpio_cfg->pin + 4));
+               tmp |= (gpio_cfg->dir << (gpio_cfg->pin + 4));
+               ret = mxl111sf_write_reg(state, MXL_GPIO_MUX_REG_0, tmp);
+               if (mxl_fail(ret))
+                       goto fail;
+               break;
+       case 4:
+       case 5:
+       case 6:
+       case 7:
+               ret = mxl111sf_read_reg(state, MXL_GPIO_MUX_REG_1, &tmp);
+               if (mxl_fail(ret))
+                       goto fail;
+               tmp &= ~(1 << gpio_cfg->pin);
+               tmp |= (gpio_cfg->dir << gpio_cfg->pin);
+               ret = mxl111sf_write_reg(state, MXL_GPIO_MUX_REG_1, tmp);
+               if (mxl_fail(ret))
+                       goto fail;
+               break;
+       case 8:
+       case 9:
+       case 10:
+               ret = mxl111sf_read_reg(state, MXL_GPIO_MUX_REG_2, &tmp);
+               if (mxl_fail(ret))
+                       goto fail;
+               tmp &= ~(1 << (gpio_cfg->pin - 3));
+               tmp |= (gpio_cfg->dir << (gpio_cfg->pin - 3));
+               ret = mxl111sf_write_reg(state, MXL_GPIO_MUX_REG_2, tmp);
+               if (mxl_fail(ret))
+                       goto fail;
+               break;
+       default:
+               return -EINVAL; /* invalid pin */
+       }
+
+       ret = (MXL_GPIO_DIR_OUTPUT == gpio_cfg->dir) ?
+               mxl111sf_set_gpo_state(state,
+                                      gpio_cfg->pin, gpio_cfg->val) :
+               mxl111sf_get_gpi_state(state,
+                                      gpio_cfg->pin, &gpio_cfg->val);
+       mxl_fail(ret);
+fail:
+       return ret;
+}
+
+static int mxl111sf_hw_do_set_gpio(struct mxl111sf_state *state,
+                                  int gpio, int direction, int val)
+{
+       struct mxl_gpio_cfg gpio_config = {
+               .pin = gpio,
+               .dir = direction,
+               .val = val,
+       };
+
+       mxl_debug("(%d, %d, %d)", gpio, direction, val);
+
+       return mxl111sf_config_gpio_pins(state, &gpio_config);
+}
+
+/* ------------------------------------------------------------------------- */
+
+#define PIN_MUX_MPEG_MODE_MASK          0x40   /* 0x17 <6> */
+#define PIN_MUX_MPEG_PAR_EN_MASK        0x01   /* 0x18 <0> */
+#define PIN_MUX_MPEG_SER_EN_MASK        0x02   /* 0x18 <1> */
+#define PIN_MUX_MPG_IN_MUX_MASK         0x80   /* 0x3D <7> */
+#define PIN_MUX_BT656_ENABLE_MASK       0x04   /* 0x12 <2> */
+#define PIN_MUX_I2S_ENABLE_MASK         0x40   /* 0x15 <6> */
+#define PIN_MUX_SPI_MODE_MASK           0x10   /* 0x3D <4> */
+#define PIN_MUX_MCLK_EN_CTRL_MASK       0x10   /* 0x82 <4> */
+#define PIN_MUX_MPSYN_EN_CTRL_MASK      0x20   /* 0x82 <5> */
+#define PIN_MUX_MDVAL_EN_CTRL_MASK      0x40   /* 0x82 <6> */
+#define PIN_MUX_MPERR_EN_CTRL_MASK      0x80   /* 0x82 <7> */
+#define PIN_MUX_MDAT_EN_0_MASK          0x10   /* 0x84 <4> */
+#define PIN_MUX_MDAT_EN_1_MASK          0x20   /* 0x84 <5> */
+#define PIN_MUX_MDAT_EN_2_MASK          0x40   /* 0x84 <6> */
+#define PIN_MUX_MDAT_EN_3_MASK          0x80   /* 0x84 <7> */
+#define PIN_MUX_MDAT_EN_4_MASK          0x10   /* 0x89 <4> */
+#define PIN_MUX_MDAT_EN_5_MASK          0x20   /* 0x89 <5> */
+#define PIN_MUX_MDAT_EN_6_MASK          0x40   /* 0x89 <6> */
+#define PIN_MUX_MDAT_EN_7_MASK          0x80   /* 0x89 <7> */
+
+int mxl111sf_config_pin_mux_modes(struct mxl111sf_state *state,
+                                 enum mxl111sf_mux_config pin_mux_config)
+{
+       u8 r12, r15, r17, r18, r3D, r82, r84, r89;
+       int ret;
+
+       mxl_debug("(%d)", pin_mux_config);
+
+       ret = mxl111sf_read_reg(state, 0x17, &r17);
+       if (mxl_fail(ret))
+               goto fail;
+       ret = mxl111sf_read_reg(state, 0x18, &r18);
+       if (mxl_fail(ret))
+               goto fail;
+       ret = mxl111sf_read_reg(state, 0x12, &r12);
+       if (mxl_fail(ret))
+               goto fail;
+       ret = mxl111sf_read_reg(state, 0x15, &r15);
+       if (mxl_fail(ret))
+               goto fail;
+       ret = mxl111sf_read_reg(state, 0x82, &r82);
+       if (mxl_fail(ret))
+               goto fail;
+       ret = mxl111sf_read_reg(state, 0x84, &r84);
+       if (mxl_fail(ret))
+               goto fail;
+       ret = mxl111sf_read_reg(state, 0x89, &r89);
+       if (mxl_fail(ret))
+               goto fail;
+       ret = mxl111sf_read_reg(state, 0x3D, &r3D);
+       if (mxl_fail(ret))
+               goto fail;
+
+       switch (pin_mux_config) {
+       case PIN_MUX_TS_OUT_PARALLEL:
+               /* mpeg_mode = 1 */
+               r17 |= PIN_MUX_MPEG_MODE_MASK;
+               /* mpeg_par_en = 1 */
+               r18 |= PIN_MUX_MPEG_PAR_EN_MASK;
+               /* mpeg_ser_en = 0 */
+               r18 &= ~PIN_MUX_MPEG_SER_EN_MASK;
+               /* mpg_in_mux = 0 */
+               r3D &= ~PIN_MUX_MPG_IN_MUX_MASK;
+               /* bt656_enable = 0 */
+               r12 &= ~PIN_MUX_BT656_ENABLE_MASK;
+               /* i2s_enable = 0 */
+               r15 &= ~PIN_MUX_I2S_ENABLE_MASK;
+               /* spi_mode = 0 */
+               r3D &= ~PIN_MUX_SPI_MODE_MASK;
+               /* mclk_en_ctrl = 1 */
+               r82 |= PIN_MUX_MCLK_EN_CTRL_MASK;
+               /* mperr_en_ctrl = 1 */
+               r82 |= PIN_MUX_MPERR_EN_CTRL_MASK;
+               /* mdval_en_ctrl = 1 */
+               r82 |= PIN_MUX_MDVAL_EN_CTRL_MASK;
+               /* mpsyn_en_ctrl = 1 */
+               r82 |= PIN_MUX_MPSYN_EN_CTRL_MASK;
+               /* mdat_en_ctrl[3:0] = 0xF */
+               r84 |= 0xF0;
+               /* mdat_en_ctrl[7:4] = 0xF */
+               r89 |= 0xF0;
+               break;
+       case PIN_MUX_TS_OUT_SERIAL:
+               /* mpeg_mode = 1 */
+               r17 |= PIN_MUX_MPEG_MODE_MASK;
+               /* mpeg_par_en = 0 */
+               r18 &= ~PIN_MUX_MPEG_PAR_EN_MASK;
+               /* mpeg_ser_en = 1 */
+               r18 |= PIN_MUX_MPEG_SER_EN_MASK;
+               /* mpg_in_mux = 0 */
+               r3D &= ~PIN_MUX_MPG_IN_MUX_MASK;
+               /* bt656_enable = 0 */
+               r12 &= ~PIN_MUX_BT656_ENABLE_MASK;
+               /* i2s_enable = 0 */
+               r15 &= ~PIN_MUX_I2S_ENABLE_MASK;
+               /* spi_mode = 0 */
+               r3D &= ~PIN_MUX_SPI_MODE_MASK;
+               /* mclk_en_ctrl = 1 */
+               r82 |= PIN_MUX_MCLK_EN_CTRL_MASK;
+               /* mperr_en_ctrl = 1 */
+               r82 |= PIN_MUX_MPERR_EN_CTRL_MASK;
+               /* mdval_en_ctrl = 1 */
+               r82 |= PIN_MUX_MDVAL_EN_CTRL_MASK;
+               /* mpsyn_en_ctrl = 1 */
+               r82 |= PIN_MUX_MPSYN_EN_CTRL_MASK;
+               /* mdat_en_ctrl[3:0] = 0xF */
+               r84 |= 0xF0;
+               /* mdat_en_ctrl[7:4] = 0xF */
+               r89 |= 0xF0;
+               break;
+       case PIN_MUX_GPIO_MODE:
+               /* mpeg_mode = 0 */
+               r17 &= ~PIN_MUX_MPEG_MODE_MASK;
+               /* mpeg_par_en = 0 */
+               r18 &= ~PIN_MUX_MPEG_PAR_EN_MASK;
+               /* mpeg_ser_en = 0 */
+               r18 &= ~PIN_MUX_MPEG_SER_EN_MASK;
+               /* mpg_in_mux = 0 */
+               r3D &= ~PIN_MUX_MPG_IN_MUX_MASK;
+               /* bt656_enable = 0 */
+               r12 &= ~PIN_MUX_BT656_ENABLE_MASK;
+               /* i2s_enable = 0 */
+               r15 &= ~PIN_MUX_I2S_ENABLE_MASK;
+               /* spi_mode = 0 */
+               r3D &= ~PIN_MUX_SPI_MODE_MASK;
+               /* mclk_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MCLK_EN_CTRL_MASK;
+               /* mperr_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MPERR_EN_CTRL_MASK;
+               /* mdval_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MDVAL_EN_CTRL_MASK;
+               /* mpsyn_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MPSYN_EN_CTRL_MASK;
+               /* mdat_en_ctrl[3:0] = 0x0 */
+               r84 &= 0x0F;
+               /* mdat_en_ctrl[7:4] = 0x0 */
+               r89 &= 0x0F;
+               break;
+       case PIN_MUX_TS_SERIAL_IN_MODE_0:
+               /* mpeg_mode = 0 */
+               r17 &= ~PIN_MUX_MPEG_MODE_MASK;
+               /* mpeg_par_en = 0 */
+               r18 &= ~PIN_MUX_MPEG_PAR_EN_MASK;
+               /* mpeg_ser_en = 1 */
+               r18 |= PIN_MUX_MPEG_SER_EN_MASK;
+               /* mpg_in_mux = 0 */
+               r3D &= ~PIN_MUX_MPG_IN_MUX_MASK;
+               /* bt656_enable = 0 */
+               r12 &= ~PIN_MUX_BT656_ENABLE_MASK;
+               /* i2s_enable = 0 */
+               r15 &= ~PIN_MUX_I2S_ENABLE_MASK;
+               /* spi_mode = 0 */
+               r3D &= ~PIN_MUX_SPI_MODE_MASK;
+               /* mclk_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MCLK_EN_CTRL_MASK;
+               /* mperr_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MPERR_EN_CTRL_MASK;
+               /* mdval_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MDVAL_EN_CTRL_MASK;
+               /* mpsyn_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MPSYN_EN_CTRL_MASK;
+               /* mdat_en_ctrl[3:0] = 0x0 */
+               r84 &= 0x0F;
+               /* mdat_en_ctrl[7:4] = 0x0 */
+               r89 &= 0x0F;
+               break;
+       case PIN_MUX_TS_SERIAL_IN_MODE_1:
+               /* mpeg_mode = 0 */
+               r17 &= ~PIN_MUX_MPEG_MODE_MASK;
+               /* mpeg_par_en = 0 */
+               r18 &= ~PIN_MUX_MPEG_PAR_EN_MASK;
+               /* mpeg_ser_en = 1 */
+               r18 |= PIN_MUX_MPEG_SER_EN_MASK;
+               /* mpg_in_mux = 1 */
+               r3D |= PIN_MUX_MPG_IN_MUX_MASK;
+               /* bt656_enable = 0 */
+               r12 &= ~PIN_MUX_BT656_ENABLE_MASK;
+               /* i2s_enable = 0 */
+               r15 &= ~PIN_MUX_I2S_ENABLE_MASK;
+               /* spi_mode = 0 */
+               r3D &= ~PIN_MUX_SPI_MODE_MASK;
+               /* mclk_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MCLK_EN_CTRL_MASK;
+               /* mperr_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MPERR_EN_CTRL_MASK;
+               /* mdval_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MDVAL_EN_CTRL_MASK;
+               /* mpsyn_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MPSYN_EN_CTRL_MASK;
+               /* mdat_en_ctrl[3:0] = 0x0 */
+               r84 &= 0x0F;
+               /* mdat_en_ctrl[7:4] = 0x0 */
+               r89 &= 0x0F;
+               break;
+       case PIN_MUX_TS_SPI_IN_MODE_1:
+               /* mpeg_mode = 0 */
+               r17 &= ~PIN_MUX_MPEG_MODE_MASK;
+               /* mpeg_par_en = 0 */
+               r18 &= ~PIN_MUX_MPEG_PAR_EN_MASK;
+               /* mpeg_ser_en = 1 */
+               r18 |= PIN_MUX_MPEG_SER_EN_MASK;
+               /* mpg_in_mux = 1 */
+               r3D |= PIN_MUX_MPG_IN_MUX_MASK;
+               /* bt656_enable = 0 */
+               r12 &= ~PIN_MUX_BT656_ENABLE_MASK;
+               /* i2s_enable = 1 */
+               r15 |= PIN_MUX_I2S_ENABLE_MASK;
+               /* spi_mode = 1 */
+               r3D |= PIN_MUX_SPI_MODE_MASK;
+               /* mclk_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MCLK_EN_CTRL_MASK;
+               /* mperr_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MPERR_EN_CTRL_MASK;
+               /* mdval_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MDVAL_EN_CTRL_MASK;
+               /* mpsyn_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MPSYN_EN_CTRL_MASK;
+               /* mdat_en_ctrl[3:0] = 0x0 */
+               r84 &= 0x0F;
+               /* mdat_en_ctrl[7:4] = 0x0 */
+               r89 &= 0x0F;
+               break;
+       case PIN_MUX_TS_SPI_IN_MODE_0:
+               /* mpeg_mode = 0 */
+               r17 &= ~PIN_MUX_MPEG_MODE_MASK;
+               /* mpeg_par_en = 0 */
+               r18 &= ~PIN_MUX_MPEG_PAR_EN_MASK;
+               /* mpeg_ser_en = 1 */
+               r18 |= PIN_MUX_MPEG_SER_EN_MASK;
+               /* mpg_in_mux = 0 */
+               r3D &= ~PIN_MUX_MPG_IN_MUX_MASK;
+               /* bt656_enable = 0 */
+               r12 &= ~PIN_MUX_BT656_ENABLE_MASK;
+               /* i2s_enable = 1 */
+               r15 |= PIN_MUX_I2S_ENABLE_MASK;
+               /* spi_mode = 1 */
+               r3D |= PIN_MUX_SPI_MODE_MASK;
+               /* mclk_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MCLK_EN_CTRL_MASK;
+               /* mperr_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MPERR_EN_CTRL_MASK;
+               /* mdval_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MDVAL_EN_CTRL_MASK;
+               /* mpsyn_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MPSYN_EN_CTRL_MASK;
+               /* mdat_en_ctrl[3:0] = 0x0 */
+               r84 &= 0x0F;
+               /* mdat_en_ctrl[7:4] = 0x0 */
+               r89 &= 0x0F;
+               break;
+       case PIN_MUX_TS_PARALLEL_IN:
+               /* mpeg_mode = 0 */
+               r17 &= ~PIN_MUX_MPEG_MODE_MASK;
+               /* mpeg_par_en = 1 */
+               r18 |= PIN_MUX_MPEG_PAR_EN_MASK;
+               /* mpeg_ser_en = 0 */
+               r18 &= ~PIN_MUX_MPEG_SER_EN_MASK;
+               /* mpg_in_mux = 0 */
+               r3D &= ~PIN_MUX_MPG_IN_MUX_MASK;
+               /* bt656_enable = 0 */
+               r12 &= ~PIN_MUX_BT656_ENABLE_MASK;
+               /* i2s_enable = 0 */
+               r15 &= ~PIN_MUX_I2S_ENABLE_MASK;
+               /* spi_mode = 0 */
+               r3D &= ~PIN_MUX_SPI_MODE_MASK;
+               /* mclk_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MCLK_EN_CTRL_MASK;
+               /* mperr_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MPERR_EN_CTRL_MASK;
+               /* mdval_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MDVAL_EN_CTRL_MASK;
+               /* mpsyn_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MPSYN_EN_CTRL_MASK;
+               /* mdat_en_ctrl[3:0] = 0x0 */
+               r84 &= 0x0F;
+               /* mdat_en_ctrl[7:4] = 0x0 */
+               r89 &= 0x0F;
+               break;
+       case PIN_MUX_BT656_I2S_MODE:
+               /* mpeg_mode = 0 */
+               r17 &= ~PIN_MUX_MPEG_MODE_MASK;
+               /* mpeg_par_en = 0 */
+               r18 &= ~PIN_MUX_MPEG_PAR_EN_MASK;
+               /* mpeg_ser_en = 0 */
+               r18 &= ~PIN_MUX_MPEG_SER_EN_MASK;
+               /* mpg_in_mux = 0 */
+               r3D &= ~PIN_MUX_MPG_IN_MUX_MASK;
+               /* bt656_enable = 1 */
+               r12 |= PIN_MUX_BT656_ENABLE_MASK;
+               /* i2s_enable = 1 */
+               r15 |= PIN_MUX_I2S_ENABLE_MASK;
+               /* spi_mode = 0 */
+               r3D &= ~PIN_MUX_SPI_MODE_MASK;
+               /* mclk_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MCLK_EN_CTRL_MASK;
+               /* mperr_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MPERR_EN_CTRL_MASK;
+               /* mdval_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MDVAL_EN_CTRL_MASK;
+               /* mpsyn_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MPSYN_EN_CTRL_MASK;
+               /* mdat_en_ctrl[3:0] = 0x0 */
+               r84 &= 0x0F;
+               /* mdat_en_ctrl[7:4] = 0x0 */
+               r89 &= 0x0F;
+               break;
+       case PIN_MUX_DEFAULT:
+       default:
+               /* mpeg_mode = 1 */
+               r17 |= PIN_MUX_MPEG_MODE_MASK;
+               /* mpeg_par_en = 0 */
+               r18 &= ~PIN_MUX_MPEG_PAR_EN_MASK;
+               /* mpeg_ser_en = 0 */
+               r18 &= ~PIN_MUX_MPEG_SER_EN_MASK;
+               /* mpg_in_mux = 0 */
+               r3D &= ~PIN_MUX_MPG_IN_MUX_MASK;
+               /* bt656_enable = 0 */
+               r12 &= ~PIN_MUX_BT656_ENABLE_MASK;
+               /* i2s_enable = 0 */
+               r15 &= ~PIN_MUX_I2S_ENABLE_MASK;
+               /* spi_mode = 0 */
+               r3D &= ~PIN_MUX_SPI_MODE_MASK;
+               /* mclk_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MCLK_EN_CTRL_MASK;
+               /* mperr_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MPERR_EN_CTRL_MASK;
+               /* mdval_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MDVAL_EN_CTRL_MASK;
+               /* mpsyn_en_ctrl = 0 */
+               r82 &= ~PIN_MUX_MPSYN_EN_CTRL_MASK;
+               /* mdat_en_ctrl[3:0] = 0x0 */
+               r84 &= 0x0F;
+               /* mdat_en_ctrl[7:4] = 0x0 */
+               r89 &= 0x0F;
+               break;
+       }
+
+       ret = mxl111sf_write_reg(state, 0x17, r17);
+       if (mxl_fail(ret))
+               goto fail;
+       ret = mxl111sf_write_reg(state, 0x18, r18);
+       if (mxl_fail(ret))
+               goto fail;
+       ret = mxl111sf_write_reg(state, 0x12, r12);
+       if (mxl_fail(ret))
+               goto fail;
+       ret = mxl111sf_write_reg(state, 0x15, r15);
+       if (mxl_fail(ret))
+               goto fail;
+       ret = mxl111sf_write_reg(state, 0x82, r82);
+       if (mxl_fail(ret))
+               goto fail;
+       ret = mxl111sf_write_reg(state, 0x84, r84);
+       if (mxl_fail(ret))
+               goto fail;
+       ret = mxl111sf_write_reg(state, 0x89, r89);
+       if (mxl_fail(ret))
+               goto fail;
+       ret = mxl111sf_write_reg(state, 0x3D, r3D);
+       if (mxl_fail(ret))
+               goto fail;
+fail:
+       return ret;
+}
+
+/* ------------------------------------------------------------------------- */
+
+static int mxl111sf_hw_set_gpio(struct mxl111sf_state *state, int gpio, int val)
+{
+       return mxl111sf_hw_do_set_gpio(state, gpio, MXL_GPIO_DIR_OUTPUT, val);
+}
+
+static int mxl111sf_hw_gpio_initialize(struct mxl111sf_state *state)
+{
+       u8 gpioval = 0x07; /* write protect enabled, signal LEDs off */
+       int i, ret;
+
+       mxl_debug("()");
+
+       for (i = 3; i < 8; i++) {
+               ret = mxl111sf_hw_set_gpio(state, i, (gpioval >> i) & 0x01);
+               if (mxl_fail(ret))
+                       break;
+       }
+
+       return ret;
+}
+
+#define PCA9534_I2C_ADDR (0x40 >> 1)
+static int pca9534_set_gpio(struct mxl111sf_state *state, int gpio, int val)
+{
+       u8 w[2] = { 1, 0 };
+       u8 r = 0;
+       struct i2c_msg msg[] = {
+               { .addr = PCA9534_I2C_ADDR,
+                 .flags = 0, .buf = w, .len = 1 },
+               { .addr = PCA9534_I2C_ADDR,
+                 .flags = I2C_M_RD, .buf = &r, .len = 1 },
+       };
+
+       mxl_debug("(%d, %d)", gpio, val);
+
+       /* read current GPIO levels from flip-flop */
+       i2c_transfer(&state->d->i2c_adap, msg, 2);
+
+       /* prepare write buffer with current GPIO levels */
+       msg[0].len = 2;
+#if 0
+       w[0] = 1;
+#endif
+       w[1] = r;
+
+       /* clear the desired GPIO */
+       w[1] &= ~(1 << gpio);
+
+       /* set the desired GPIO value */
+       w[1] |= ((val ? 1 : 0) << gpio);
+
+       /* write new GPIO levels to flip-flop */
+       i2c_transfer(&state->d->i2c_adap, &msg[0], 1);
+
+       return 0;
+}
+
+static int pca9534_init_port_expander(struct mxl111sf_state *state)
+{
+       u8 w[2] = { 1, 0x07 }; /* write protect enabled, signal LEDs off */
+
+       struct i2c_msg msg = {
+               .addr = PCA9534_I2C_ADDR,
+               .flags = 0, .buf = w, .len = 2
+       };
+
+       mxl_debug("()");
+
+       i2c_transfer(&state->d->i2c_adap, &msg, 1);
+
+       /* configure all pins as outputs */
+       w[0] = 3;
+       w[1] = 0;
+
+       i2c_transfer(&state->d->i2c_adap, &msg, 1);
+
+       return 0;
+}
+
+int mxl111sf_set_gpio(struct mxl111sf_state *state, int gpio, int val)
+{
+       mxl_debug("(%d, %d)", gpio, val);
+
+       switch (state->gpio_port_expander) {
+       default:
+               mxl_printk(KERN_ERR,
+                          "gpio_port_expander undefined, assuming PCA9534");
+               /* fall-thru */
+       case mxl111sf_PCA9534:
+               return pca9534_set_gpio(state, gpio, val);
+       case mxl111sf_gpio_hw:
+               return mxl111sf_hw_set_gpio(state, gpio, val);
+       }
+}
+
+static int mxl111sf_probe_port_expander(struct mxl111sf_state *state)
+{
+       int ret;
+       u8 w = 1;
+       u8 r = 0;
+       struct i2c_msg msg[] = {
+               { .flags = 0,        .buf = &w, .len = 1 },
+               { .flags = I2C_M_RD, .buf = &r, .len = 1 },
+       };
+
+       mxl_debug("()");
+
+       msg[0].addr = 0x70 >> 1;
+       msg[1].addr = 0x70 >> 1;
+
+       /* read current GPIO levels from flip-flop */
+       ret = i2c_transfer(&state->d->i2c_adap, msg, 2);
+       if (ret == 2) {
+               state->port_expander_addr = msg[0].addr;
+               state->gpio_port_expander = mxl111sf_PCA9534;
+               mxl_debug("found port expander at 0x%02x",
+                         state->port_expander_addr);
+               return 0;
+       }
+
+       msg[0].addr = 0x40 >> 1;
+       msg[1].addr = 0x40 >> 1;
+
+       ret = i2c_transfer(&state->d->i2c_adap, msg, 2);
+       if (ret == 2) {
+               state->port_expander_addr = msg[0].addr;
+               state->gpio_port_expander = mxl111sf_PCA9534;
+               mxl_debug("found port expander at 0x%02x",
+                         state->port_expander_addr);
+               return 0;
+       }
+       state->port_expander_addr = 0xff;
+       state->gpio_port_expander = mxl111sf_gpio_hw;
+       mxl_debug("using hardware gpio");
+       return 0;
+}
+
+int mxl111sf_init_port_expander(struct mxl111sf_state *state)
+{
+       mxl_debug("()");
+
+       if (0x00 == state->port_expander_addr)
+               mxl111sf_probe_port_expander(state);
+
+       switch (state->gpio_port_expander) {
+       default:
+               mxl_printk(KERN_ERR,
+                          "gpio_port_expander undefined, assuming PCA9534");
+               /* fall-thru */
+       case mxl111sf_PCA9534:
+               return pca9534_init_port_expander(state);
+       case mxl111sf_gpio_hw:
+               return mxl111sf_hw_gpio_initialize(state);
+       }
+}
+
+/* ------------------------------------------------------------------------ */
+
+int mxl111sf_gpio_mode_switch(struct mxl111sf_state *state, unsigned int mode)
+{
+/*     GPO:
+ *     3 - ATSC/MH#   | 1 = ATSC transport, 0 = MH transport      | default 0
+ *     4 - ATSC_RST## | 1 = ATSC enable, 0 = ATSC Reset           | default 0
+ *     5 - ATSC_EN    | 1 = ATSC power enable, 0 = ATSC power off | default 0
+ *     6 - MH_RESET#  | 1 = MH enable, 0 = MH Reset               | default 0
+ *     7 - MH_EN      | 1 = MH power enable, 0 = MH power off     | default 0
+ */
+       mxl_debug("(%d)", mode);
+
+       switch (mode) {
+       case MXL111SF_GPIO_MOD_MH:
+               mxl111sf_set_gpio(state, 4, 0);
+               mxl111sf_set_gpio(state, 5, 0);
+               msleep(50);
+               mxl111sf_set_gpio(state, 7, 1);
+               msleep(50);
+               mxl111sf_set_gpio(state, 6, 1);
+               msleep(50);
+
+               mxl111sf_set_gpio(state, 3, 0);
+               break;
+       case MXL111SF_GPIO_MOD_ATSC:
+               mxl111sf_set_gpio(state, 6, 0);
+               mxl111sf_set_gpio(state, 7, 0);
+               msleep(50);
+               mxl111sf_set_gpio(state, 5, 1);
+               msleep(50);
+               mxl111sf_set_gpio(state, 4, 1);
+               msleep(50);
+               mxl111sf_set_gpio(state, 3, 1);
+               break;
+       default: /* DVBT / STANDBY */
+               mxl111sf_init_port_expander(state);
+               break;
+       }
+       return 0;
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/drivers/media/dvb/dvb-usb/mxl111sf-gpio.h b/drivers/media/dvb/dvb-usb/mxl111sf-gpio.h
new file mode 100644 (file)
index 0000000..0220f54
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ *  mxl111sf-gpio.h - driver for the MaxLinear MXL111SF
+ *
+ *  Copyright (C) 2010 Michael Krufky <mkrufky@kernellabs.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef _DVB_USB_MXL111SF_GPIO_H_
+#define _DVB_USB_MXL111SF_GPIO_H_
+
+#include "mxl111sf.h"
+
+int mxl111sf_set_gpio(struct mxl111sf_state *state, int gpio, int val);
+int mxl111sf_init_port_expander(struct mxl111sf_state *state);
+
+#define MXL111SF_GPIO_MOD_DVBT 0
+#define MXL111SF_GPIO_MOD_MH   1
+#define MXL111SF_GPIO_MOD_ATSC 2
+int mxl111sf_gpio_mode_switch(struct mxl111sf_state *state, unsigned int mode);
+
+enum mxl111sf_mux_config {
+       PIN_MUX_DEFAULT = 0,
+       PIN_MUX_TS_OUT_PARALLEL,
+       PIN_MUX_TS_OUT_SERIAL,
+       PIN_MUX_GPIO_MODE,
+       PIN_MUX_TS_SERIAL_IN_MODE_0,
+       PIN_MUX_TS_SERIAL_IN_MODE_1,
+       PIN_MUX_TS_SPI_IN_MODE_0,
+       PIN_MUX_TS_SPI_IN_MODE_1,
+       PIN_MUX_TS_PARALLEL_IN,
+       PIN_MUX_BT656_I2S_MODE,
+};
+
+int mxl111sf_config_pin_mux_modes(struct mxl111sf_state *state,
+                                 enum mxl111sf_mux_config pin_mux_config);
+
+#endif /* _DVB_USB_MXL111SF_GPIO_H_ */
+
+/*
+ * Local variables:
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/drivers/media/dvb/dvb-usb/mxl111sf-i2c.c b/drivers/media/dvb/dvb-usb/mxl111sf-i2c.c
new file mode 100644 (file)
index 0000000..2e8c288
--- /dev/null
@@ -0,0 +1,851 @@
+/*
+ *  mxl111sf-i2c.c - driver for the MaxLinear MXL111SF
+ *
+ *  Copyright (C) 2010 Michael Krufky <mkrufky@kernellabs.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include "mxl111sf-i2c.h"
+#include "mxl111sf.h"
+
+/* SW-I2C ----------------------------------------------------------------- */
+
+#define SW_I2C_ADDR            0x1a
+#define SW_I2C_EN              0x02
+#define SW_SCL_OUT             0x04
+#define SW_SDA_OUT             0x08
+#define SW_SDA_IN              0x04
+
+#define SW_I2C_BUSY_ADDR       0x2f
+#define SW_I2C_BUSY            0x02
+
+static int mxl111sf_i2c_bitbang_sendbyte(struct mxl111sf_state *state,
+                                        u8 byte)
+{
+       int i, ret;
+       u8 data = 0;
+
+       mxl_i2c("(0x%02x)", byte);
+
+       ret = mxl111sf_read_reg(state, SW_I2C_BUSY_ADDR, &data);
+       if (mxl_fail(ret))
+               goto fail;
+
+       for (i = 0; i < 8; i++) {
+
+               data = (byte & (0x80 >> i)) ? SW_SDA_OUT : 0;
+
+               ret = mxl111sf_write_reg(state, SW_I2C_ADDR,
+                                        0x10 | SW_I2C_EN | data);
+               if (mxl_fail(ret))
+                       goto fail;
+
+               ret = mxl111sf_write_reg(state, SW_I2C_ADDR,
+                                        0x10 | SW_I2C_EN | data | SW_SCL_OUT);
+               if (mxl_fail(ret))
+                       goto fail;
+
+               ret = mxl111sf_write_reg(state, SW_I2C_ADDR,
+                                        0x10 | SW_I2C_EN | data);
+               if (mxl_fail(ret))
+                       goto fail;
+       }
+
+       /* last bit was 0 so we need to release SDA */
+       if (!(byte & 1)) {
+               ret = mxl111sf_write_reg(state, SW_I2C_ADDR,
+                                        0x10 | SW_I2C_EN | SW_SDA_OUT);
+               if (mxl_fail(ret))
+                       goto fail;
+       }
+
+       /* CLK high for ACK readback */
+       ret = mxl111sf_write_reg(state, SW_I2C_ADDR,
+                                0x10 | SW_I2C_EN | SW_SCL_OUT | SW_SDA_OUT);
+       if (mxl_fail(ret))
+               goto fail;
+
+       ret = mxl111sf_read_reg(state, SW_I2C_BUSY_ADDR, &data);
+       if (mxl_fail(ret))
+               goto fail;
+
+       /* drop the CLK after getting ACK, SDA will go high right away */
+       ret = mxl111sf_write_reg(state, SW_I2C_ADDR,
+                                0x10 | SW_I2C_EN | SW_SDA_OUT);
+       if (mxl_fail(ret))
+               goto fail;
+
+       if (data & SW_SDA_IN)
+               ret = -EIO;
+fail:
+       return ret;
+}
+
+static int mxl111sf_i2c_bitbang_recvbyte(struct mxl111sf_state *state,
+                                        u8 *pbyte)
+{
+       int i, ret;
+       u8 byte = 0;
+       u8 data = 0;
+
+       mxl_i2c("()");
+
+       *pbyte = 0;
+
+       ret = mxl111sf_write_reg(state, SW_I2C_ADDR,
+                                0x10 | SW_I2C_EN | SW_SDA_OUT);
+       if (mxl_fail(ret))
+               goto fail;
+
+       for (i = 0; i < 8; i++) {
+               ret = mxl111sf_write_reg(state, SW_I2C_ADDR,
+                                        0x10 | SW_I2C_EN |
+                                        SW_SCL_OUT | SW_SDA_OUT);
+               if (mxl_fail(ret))
+                       goto fail;
+
+               ret = mxl111sf_read_reg(state, SW_I2C_BUSY_ADDR, &data);
+               if (mxl_fail(ret))
+                       goto fail;
+
+               if (data & SW_SDA_IN)
+                       byte |= (0x80 >> i);
+
+               ret = mxl111sf_write_reg(state, SW_I2C_ADDR,
+                                        0x10 | SW_I2C_EN | SW_SDA_OUT);
+               if (mxl_fail(ret))
+                       goto fail;
+       }
+       *pbyte = byte;
+fail:
+       return ret;
+}
+
+static int mxl111sf_i2c_start(struct mxl111sf_state *state)
+{
+       int ret;
+
+       mxl_i2c("()");
+
+       ret = mxl111sf_write_reg(state, SW_I2C_ADDR,
+                                0x10 | SW_I2C_EN | SW_SCL_OUT | SW_SDA_OUT);
+       if (mxl_fail(ret))
+               goto fail;
+
+       ret = mxl111sf_write_reg(state, SW_I2C_ADDR,
+                                0x10 | SW_I2C_EN | SW_SCL_OUT);
+       if (mxl_fail(ret))
+               goto fail;
+
+       ret = mxl111sf_write_reg(state, SW_I2C_ADDR,
+                                0x10 | SW_I2C_EN); /* start */
+       mxl_fail(ret);
+fail:
+       return ret;
+}
+
+static int mxl111sf_i2c_stop(struct mxl111sf_state *state)
+{
+       int ret;
+
+       mxl_i2c("()");
+
+       ret = mxl111sf_write_reg(state, SW_I2C_ADDR,
+                                0x10 | SW_I2C_EN); /* stop */
+       if (mxl_fail(ret))
+               goto fail;
+
+       ret = mxl111sf_write_reg(state, SW_I2C_ADDR,
+                                0x10 | SW_I2C_EN | SW_SCL_OUT);
+       if (mxl_fail(ret))
+               goto fail;
+
+       ret = mxl111sf_write_reg(state, SW_I2C_ADDR,
+                                0x10 | SW_I2C_EN | SW_SCL_OUT | SW_SDA_OUT);
+       if (mxl_fail(ret))
+               goto fail;
+
+       ret = mxl111sf_write_reg(state, SW_I2C_ADDR,
+                                0x10 | SW_SCL_OUT | SW_SDA_OUT);
+       mxl_fail(ret);
+fail:
+       return ret;
+}
+
+static int mxl111sf_i2c_ack(struct mxl111sf_state *state)
+{
+       int ret;
+       u8 b = 0;
+
+       mxl_i2c("()");
+
+       ret = mxl111sf_read_reg(state, SW_I2C_BUSY_ADDR, &b);
+       if (mxl_fail(ret))
+               goto fail;
+
+       ret = mxl111sf_write_reg(state, SW_I2C_ADDR,
+                                0x10 | SW_I2C_EN);
+       if (mxl_fail(ret))
+               goto fail;
+
+       /* pull SDA low */
+       ret = mxl111sf_write_reg(state, SW_I2C_ADDR,
+                                0x10 | SW_I2C_EN | SW_SCL_OUT);
+       if (mxl_fail(ret))
+               goto fail;
+
+       ret = mxl111sf_write_reg(state, SW_I2C_ADDR,
+                                0x10 | SW_I2C_EN | SW_SDA_OUT);
+       mxl_fail(ret);
+fail:
+       return ret;
+}
+
+static int mxl111sf_i2c_nack(struct mxl111sf_state *state)
+{
+       int ret;
+
+       mxl_i2c("()");
+
+       /* SDA high to signal last byte read from slave */
+       ret = mxl111sf_write_reg(state, SW_I2C_ADDR,
+                                0x10 | SW_I2C_EN | SW_SCL_OUT | SW_SDA_OUT);
+       if (mxl_fail(ret))
+               goto fail;
+
+       ret = mxl111sf_write_reg(state, SW_I2C_ADDR,
+                                0x10 | SW_I2C_EN | SW_SDA_OUT);
+       mxl_fail(ret);
+fail:
+       return ret;
+}
+
+/* ------------------------------------------------------------------------ */
+
+static int mxl111sf_i2c_sw_xfer_msg(struct mxl111sf_state *state,
+                                   struct i2c_msg *msg)
+{
+       int i, ret;
+
+       mxl_i2c("()");
+
+       if (msg->flags & I2C_M_RD) {
+
+               ret = mxl111sf_i2c_start(state);
+               if (mxl_fail(ret))
+                       goto fail;
+
+               ret = mxl111sf_i2c_bitbang_sendbyte(state,
+                                                   (msg->addr << 1) | 0x01);
+               if (mxl_fail(ret)) {
+                       mxl111sf_i2c_stop(state);
+                       goto fail;
+               }
+
+               for (i = 0; i < msg->len; i++) {
+                       ret = mxl111sf_i2c_bitbang_recvbyte(state,
+                                                           &msg->buf[i]);
+                       if (mxl_fail(ret)) {
+                               mxl111sf_i2c_stop(state);
+                               goto fail;
+                       }
+
+                       if (i < msg->len - 1)
+                               mxl111sf_i2c_ack(state);
+               }
+
+               mxl111sf_i2c_nack(state);
+
+               ret = mxl111sf_i2c_stop(state);
+               if (mxl_fail(ret))
+                       goto fail;
+
+       } else {
+
+               ret = mxl111sf_i2c_start(state);
+               if (mxl_fail(ret))
+                       goto fail;
+
+               ret = mxl111sf_i2c_bitbang_sendbyte(state,
+                                                   (msg->addr << 1) & 0xfe);
+               if (mxl_fail(ret)) {
+                       mxl111sf_i2c_stop(state);
+                       goto fail;
+               }
+
+               for (i = 0; i < msg->len; i++) {
+                       ret = mxl111sf_i2c_bitbang_sendbyte(state,
+                                                           msg->buf[i]);
+                       if (mxl_fail(ret)) {
+                               mxl111sf_i2c_stop(state);
+                               goto fail;
+                       }
+               }
+
+               /* FIXME: we only want to do this on the last transaction */
+               mxl111sf_i2c_stop(state);
+       }
+fail:
+       return ret;
+}
+
+/* HW-I2C ----------------------------------------------------------------- */
+
+#define USB_WRITE_I2C_CMD     0x99
+#define USB_READ_I2C_CMD      0xdd
+#define USB_END_I2C_CMD       0xfe
+
+#define USB_WRITE_I2C_CMD_LEN   26
+#define USB_READ_I2C_CMD_LEN    24
+
+#define I2C_MUX_REG           0x30
+#define I2C_CONTROL_REG       0x00
+#define I2C_SLAVE_ADDR_REG    0x08
+#define I2C_DATA_REG          0x0c
+#define I2C_INT_STATUS_REG    0x10
+
+static int mxl111sf_i2c_send_data(struct mxl111sf_state *state,
+                                 u8 index, u8 *wdata)
+{
+       int ret = mxl111sf_ctrl_msg(state->d, wdata[0],
+                                   &wdata[1], 25, NULL, 0);
+       mxl_fail(ret);
+
+       return ret;
+}
+
+static int mxl111sf_i2c_get_data(struct mxl111sf_state *state,
+                                u8 index, u8 *wdata, u8 *rdata)
+{
+       int ret = mxl111sf_ctrl_msg(state->d, wdata[0],
+                                   &wdata[1], 25, rdata, 24);
+       mxl_fail(ret);
+
+       return ret;
+}
+
+static u8 mxl111sf_i2c_check_status(struct mxl111sf_state *state)
+{
+       u8 status = 0;
+       u8 buf[26];
+
+       mxl_i2c_adv("()");
+
+       buf[0] = USB_READ_I2C_CMD;
+       buf[1] = 0x00;
+
+       buf[2] = I2C_INT_STATUS_REG;
+       buf[3] = 0x00;
+       buf[4] = 0x00;
+
+       buf[5] = USB_END_I2C_CMD;
+
+       mxl111sf_i2c_get_data(state, 0, buf, buf);
+
+       if (buf[1] & 0x04)
+               status = 1;
+
+       return status;
+}
+
+static u8 mxl111sf_i2c_check_fifo(struct mxl111sf_state *state)
+{
+       u8 status = 0;
+       u8 buf[26];
+
+       mxl_i2c("()");
+
+       buf[0] = USB_READ_I2C_CMD;
+       buf[1] = 0x00;
+
+       buf[2] = I2C_MUX_REG;
+       buf[3] = 0x00;
+       buf[4] = 0x00;
+
+       buf[5] = I2C_INT_STATUS_REG;
+       buf[6] = 0x00;
+       buf[7] = 0x00;
+       buf[8] = USB_END_I2C_CMD;
+
+       mxl111sf_i2c_get_data(state, 0, buf, buf);
+
+       if (0x08 == (buf[1] & 0x08))
+               status = 1;
+
+       if ((buf[5] & 0x02) == 0x02)
+               mxl_i2c("(buf[5] & 0x02) == 0x02"); /* FIXME */
+
+       return status;
+}
+
+static int mxl111sf_i2c_readagain(struct mxl111sf_state *state,
+                                 u8 count, u8 *rbuf)
+{
+       u8 i2c_w_data[26];
+       u8 i2c_r_data[24];
+       u8 i = 0;
+       u8 fifo_status = 0;
+       int ret;
+       int status = 0;
+
+       mxl_i2c("read %d bytes", count);
+
+       while ((fifo_status == 0) && (i++ < 5))
+               fifo_status = mxl111sf_i2c_check_fifo(state);
+
+       i2c_w_data[0] = 0xDD;
+       i2c_w_data[1] = 0x00;
+
+       for (i = 2; i < 26; i++)
+               i2c_w_data[i] = 0xFE;
+
+       for (i = 0; i < count; i++) {
+               i2c_w_data[2+(i*3)] = 0x0C;
+               i2c_w_data[3+(i*3)] = 0x00;
+               i2c_w_data[4+(i*3)] = 0x00;
+       }
+
+       ret = mxl111sf_i2c_get_data(state, 0, i2c_w_data, i2c_r_data);
+
+       /* Check for I2C NACK status */
+       if (mxl111sf_i2c_check_status(state) == 1) {
+               mxl_i2c("error!");
+       } else {
+               for (i = 0; i < count; i++) {
+                       rbuf[i] = i2c_r_data[(i*3)+1];
+                       mxl_i2c("%02x\t %02x",
+                               i2c_r_data[(i*3)+1],
+                               i2c_r_data[(i*3)+2]);
+               }
+
+               status = 1;
+       }
+
+       return status;
+}
+
+#define HWI2C400 1
+static int mxl111sf_i2c_hw_xfer_msg(struct mxl111sf_state *state,
+                                   struct i2c_msg *msg)
+{
+       int i, k, ret = 0;
+       u16 index = 0;
+       u8 buf[26];
+       u8 i2c_r_data[24];
+       u16 block_len;
+       u16 left_over_len;
+       u8 rd_status[8];
+       u8 ret_status;
+       u8 readbuff[26];
+
+       mxl_i2c("addr: 0x%02x, read buff len: %d, write buff len: %d",
+               msg->addr, (msg->flags & I2C_M_RD) ? msg->len : 0,
+               (!(msg->flags & I2C_M_RD)) ? msg->len : 0);
+
+       for (index = 0; index < 26; index++)
+               buf[index] = USB_END_I2C_CMD;
+
+       /* command to indicate data payload is destined for I2C interface */
+       buf[0] = USB_WRITE_I2C_CMD;
+       buf[1] = 0x00;
+
+       /* enable I2C interface */
+       buf[2] = I2C_MUX_REG;
+       buf[3] = 0x80;
+       buf[4] = 0x00;
+
+       /* enable I2C interface */
+       buf[5] = I2C_MUX_REG;
+       buf[6] = 0x81;
+       buf[7] = 0x00;
+
+       /* set Timeout register on I2C interface */
+       buf[8] = 0x14;
+       buf[9] = 0xff;
+       buf[10] = 0x00;
+#if 0
+       /* enable Interrupts on I2C interface */
+       buf[8] = 0x24;
+       buf[9] = 0xF7;
+       buf[10] = 0x00;
+#endif
+       buf[11] = 0x24;
+       buf[12] = 0xF7;
+       buf[13] = 0x00;
+
+       ret = mxl111sf_i2c_send_data(state, 0, buf);
+
+       /* write data on I2C bus */
+       if (!(msg->flags & I2C_M_RD) && (msg->len > 0)) {
+               mxl_i2c("%d\t%02x", msg->len, msg->buf[0]);
+
+               /* control register on I2C interface to initialize I2C bus */
+               buf[2] = I2C_CONTROL_REG;
+               buf[3] = 0x5E;
+               buf[4] = (HWI2C400) ? 0x03 : 0x0D;
+
+               /* I2C Slave device Address */
+               buf[5] = I2C_SLAVE_ADDR_REG;
+               buf[6] = (msg->addr);
+               buf[7] = 0x00;
+               buf[8] = USB_END_I2C_CMD;
+               ret = mxl111sf_i2c_send_data(state, 0, buf);
+
+               /* check for slave device status */
+               if (mxl111sf_i2c_check_status(state) == 1) {
+                       mxl_i2c("NACK writing slave address %02x",
+                               msg->addr);
+                       /* if NACK, stop I2C bus and exit */
+                       buf[2] = I2C_CONTROL_REG;
+                       buf[3] = 0x4E;
+                       buf[4] = (HWI2C400) ? 0x03 : 0x0D;
+                       ret = -EIO;
+                       goto exit;
+               }
+
+               /* I2C interface can do I2C operations in block of 8 bytes of
+                  I2C data. calculation to figure out number of blocks of i2c
+                  data required to program */
+               block_len = (msg->len / 8);
+               left_over_len = (msg->len % 8);
+               index = 0;
+
+               mxl_i2c("block_len %d, left_over_len %d",
+                       block_len, left_over_len);
+
+               for (index = 0; index < block_len; index++) {
+                       for (i = 0; i < 8; i++) {
+                               /* write data on I2C interface */
+                               buf[2+(i*3)] = I2C_DATA_REG;
+                               buf[3+(i*3)] = msg->buf[(index*8)+i];
+                               buf[4+(i*3)] = 0x00;
+                       }
+
+                       ret = mxl111sf_i2c_send_data(state, 0, buf);
+
+                       /* check for I2C NACK status */
+                       if (mxl111sf_i2c_check_status(state) == 1) {
+                               mxl_i2c("NACK writing slave address %02x",
+                                       msg->addr);
+
+                               /* if NACK, stop I2C bus and exit */
+                               buf[2] = I2C_CONTROL_REG;
+                               buf[3] = 0x4E;
+                               buf[4] = (HWI2C400) ? 0x03 : 0x0D;
+                               ret = -EIO;
+                               goto exit;
+                       }
+
+               }
+
+               if (left_over_len) {
+                       for (k = 0; k < 26; k++)
+                               buf[k] = USB_END_I2C_CMD;
+
+                       buf[0] = 0x99;
+                       buf[1] = 0x00;
+
+                       for (i = 0; i < left_over_len; i++) {
+                               buf[2+(i*3)] = I2C_DATA_REG;
+                               buf[3+(i*3)] = msg->buf[(index*8)+i];
+                               mxl_i2c("index = %d %d data %d",
+                                       index, i, msg->buf[(index*8)+i]);
+                               buf[4+(i*3)] = 0x00;
+                       }
+                       ret = mxl111sf_i2c_send_data(state, 0, buf);
+
+                       /* check for I2C NACK status */
+                       if (mxl111sf_i2c_check_status(state) == 1) {
+                               mxl_i2c("NACK writing slave address %02x",
+                                       msg->addr);
+
+                               /* if NACK, stop I2C bus and exit */
+                               buf[2] = I2C_CONTROL_REG;
+                               buf[3] = 0x4E;
+                               buf[4] = (HWI2C400) ? 0x03 : 0x0D;
+                               ret = -EIO;
+                               goto exit;
+                       }
+
+               }
+
+               /* issue I2C STOP after write */
+               buf[2] = I2C_CONTROL_REG;
+               buf[3] = 0x4E;
+               buf[4] = (HWI2C400) ? 0x03 : 0x0D;
+
+       }
+
+       /* read data from I2C bus */
+       if ((msg->flags & I2C_M_RD) && (msg->len > 0)) {
+               mxl_i2c("read buf len %d", msg->len);
+
+               /* command to indicate data payload is
+                  destined for I2C interface */
+               buf[2] = I2C_CONTROL_REG;
+               buf[3] = 0xDF;
+               buf[4] = (HWI2C400) ? 0x03 : 0x0D;
+
+               /* I2C xfer length */
+               buf[5] = 0x14;
+               buf[6] = (msg->len & 0xFF);
+               buf[7] = 0;
+
+               /* I2C slave device Address */
+               buf[8] = I2C_SLAVE_ADDR_REG;
+               buf[9] = msg->addr;
+               buf[10] = 0x00;
+               buf[11] = USB_END_I2C_CMD;
+               ret = mxl111sf_i2c_send_data(state, 0, buf);
+
+               /* check for I2C NACK status */
+               if (mxl111sf_i2c_check_status(state) == 1) {
+                       mxl_i2c("NACK reading slave address %02x",
+                               msg->addr);
+
+                       /* if NACK, stop I2C bus and exit */
+                       buf[2] = I2C_CONTROL_REG;
+                       buf[3] = 0xC7;
+                       buf[4] = (HWI2C400) ? 0x03 : 0x0D;
+                       ret = -EIO;
+                       goto exit;
+               }
+
+               /* I2C interface can do I2C operations in block of 8 bytes of
+                  I2C data. calculation to figure out number of blocks of
+                  i2c data required to program */
+               block_len = ((msg->len) / 8);
+               left_over_len = ((msg->len) % 8);
+               index = 0;
+
+               mxl_i2c("block_len %d, left_over_len %d",
+                       block_len, left_over_len);
+
+               /* command to read data from I2C interface */
+               buf[0] = USB_READ_I2C_CMD;
+               buf[1] = 0x00;
+
+               for (index = 0; index < block_len; index++) {
+                       /* setup I2C read request packet on I2C interface */
+                       for (i = 0; i < 8; i++) {
+                               buf[2+(i*3)] = I2C_DATA_REG;
+                               buf[3+(i*3)] = 0x00;
+                               buf[4+(i*3)] = 0x00;
+                       }
+
+                       ret = mxl111sf_i2c_get_data(state, 0, buf, i2c_r_data);
+
+                       /* check for I2C NACK status */
+                       if (mxl111sf_i2c_check_status(state) == 1) {
+                               mxl_i2c("NACK reading slave address %02x",
+                                       msg->addr);
+
+                               /* if NACK, stop I2C bus and exit */
+                               buf[2] = I2C_CONTROL_REG;
+                               buf[3] = 0xC7;
+                               buf[4] = (HWI2C400) ? 0x03 : 0x0D;
+                               ret = -EIO;
+                               goto exit;
+                       }
+
+                       /* copy data from i2c data payload to read buffer */
+                       for (i = 0; i < 8; i++) {
+                               rd_status[i] = i2c_r_data[(i*3)+2];
+
+                               if (rd_status[i] == 0x04) {
+                                       if (i < 7) {
+                                               mxl_i2c("i2c fifo empty!"
+                                                       " @ %d", i);
+                                               msg->buf[(index*8)+i] =
+                                                       i2c_r_data[(i*3)+1];
+                                               /* read again */
+                                               ret_status =
+                                                       mxl111sf_i2c_readagain(
+                                                               state, 8-(i+1),
+                                                               readbuff);
+                                               if (ret_status == 1) {
+                                                       for (k = 0;
+                                                            k < 8-(i+1);
+                                                            k++) {
+
+                                       msg->buf[(index*8)+(k+i+1)] =
+                                               readbuff[k];
+                                       mxl_i2c("read data: %02x\t %02x",
+                                               msg->buf[(index*8)+(k+i)],
+                                               (index*8)+(k+i));
+                                       mxl_i2c("read data: %02x\t %02x",
+                                               msg->buf[(index*8)+(k+i+1)],
+                                               readbuff[k]);
+
+                                                       }
+                                                       goto stop_copy;
+                                               } else {
+                                                       mxl_i2c("readagain "
+                                                               "ERROR!");
+                                               }
+                                       } else {
+                                               msg->buf[(index*8)+i] =
+                                                       i2c_r_data[(i*3)+1];
+                                       }
+                               } else {
+                                       msg->buf[(index*8)+i] =
+                                               i2c_r_data[(i*3)+1];
+                               }
+                       }
+stop_copy:
+                       ;
+
+               }
+
+               if (left_over_len) {
+                       for (k = 0; k < 26; k++)
+                               buf[k] = USB_END_I2C_CMD;
+
+                       buf[0] = 0xDD;
+                       buf[1] = 0x00;
+
+                       for (i = 0; i < left_over_len; i++) {
+                               buf[2+(i*3)] = I2C_DATA_REG;
+                               buf[3+(i*3)] = 0x00;
+                               buf[4+(i*3)] = 0x00;
+                       }
+                       ret = mxl111sf_i2c_get_data(state, 0, buf,
+                                                   i2c_r_data);
+
+                       /* check for I2C NACK status */
+                       if (mxl111sf_i2c_check_status(state) == 1) {
+                               mxl_i2c("NACK reading slave address %02x",
+                                       msg->addr);
+
+                               /* if NACK, stop I2C bus and exit */
+                               buf[2] = I2C_CONTROL_REG;
+                               buf[3] = 0xC7;
+                               buf[4] = (HWI2C400) ? 0x03 : 0x0D;
+                               ret = -EIO;
+                               goto exit;
+                       }
+
+                       for (i = 0; i < left_over_len; i++) {
+                               msg->buf[(block_len*8)+i] =
+                                       i2c_r_data[(i*3)+1];
+                               mxl_i2c("read data: %02x\t %02x",
+                                       i2c_r_data[(i*3)+1],
+                                       i2c_r_data[(i*3)+2]);
+                       }
+               }
+
+               /* indicate I2C interface to issue NACK
+                  after next I2C read op */
+               buf[0] = USB_WRITE_I2C_CMD;
+               buf[1] = 0x00;
+
+               /* control register */
+               buf[2] = I2C_CONTROL_REG;
+               buf[3] = 0x17;
+               buf[4] = (HWI2C400) ? 0x03 : 0x0D;
+
+               buf[5] = USB_END_I2C_CMD;
+               ret = mxl111sf_i2c_send_data(state, 0, buf);
+
+               /* control register */
+               buf[2] = I2C_CONTROL_REG;
+               buf[3] = 0xC7;
+               buf[4] = (HWI2C400) ? 0x03 : 0x0D;
+
+       }
+exit:
+       /* STOP and disable I2C MUX */
+       buf[0] = USB_WRITE_I2C_CMD;
+       buf[1] = 0x00;
+
+       /* de-initilize I2C BUS */
+       buf[5] = USB_END_I2C_CMD;
+       mxl111sf_i2c_send_data(state, 0, buf);
+
+       /* Control Register */
+       buf[2] = I2C_CONTROL_REG;
+       buf[3] = 0xDF;
+       buf[4] = 0x03;
+
+       /* disable I2C interface */
+       buf[5] = I2C_MUX_REG;
+       buf[6] = 0x00;
+       buf[7] = 0x00;
+
+       /* de-initilize I2C BUS */
+       buf[8] = USB_END_I2C_CMD;
+       mxl111sf_i2c_send_data(state, 0, buf);
+
+       /* disable I2C interface */
+       buf[2] = I2C_MUX_REG;
+       buf[3] = 0x81;
+       buf[4] = 0x00;
+
+       /* disable I2C interface */
+       buf[5] = I2C_MUX_REG;
+       buf[6] = 0x00;
+       buf[7] = 0x00;
+
+       /* disable I2C interface */
+       buf[8] = I2C_MUX_REG;
+       buf[9] = 0x00;
+       buf[10] = 0x00;
+
+       buf[11] = USB_END_I2C_CMD;
+       mxl111sf_i2c_send_data(state, 0, buf);
+
+       return ret;
+}
+
+/* ------------------------------------------------------------------------ */
+
+int mxl111sf_i2c_xfer(struct i2c_adapter *adap,
+                     struct i2c_msg msg[], int num)
+{
+       struct dvb_usb_device *d = i2c_get_adapdata(adap);
+       struct mxl111sf_state *state = d->priv;
+       int hwi2c = (state->chip_rev > MXL111SF_V6);
+       int i, ret;
+
+       if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
+               return -EAGAIN;
+
+       for (i = 0; i < num; i++) {
+               ret = (hwi2c) ?
+                       mxl111sf_i2c_hw_xfer_msg(state, &msg[i]) :
+                       mxl111sf_i2c_sw_xfer_msg(state, &msg[i]);
+               if (mxl_fail(ret)) {
+                       mxl_debug_adv("failed with error %d on i2c "
+                                     "transaction %d of %d, %sing %d bytes "
+                                     "to/from 0x%02x", ret, i+1, num,
+                                     (msg[i].flags & I2C_M_RD) ?
+                                     "read" : "writ",
+                                     msg[i].len, msg[i].addr);
+
+                       break;
+               }
+       }
+
+       mutex_unlock(&d->i2c_mutex);
+
+       return i == num ? num : -EREMOTEIO;
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/drivers/media/dvb/dvb-usb/mxl111sf-i2c.h b/drivers/media/dvb/dvb-usb/mxl111sf-i2c.h
new file mode 100644 (file)
index 0000000..a57a45f
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ *  mxl111sf-i2c.h - driver for the MaxLinear MXL111SF
+ *
+ *  Copyright (C) 2010 Michael Krufky <mkrufky@kernellabs.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef _DVB_USB_MXL111SF_I2C_H_
+#define _DVB_USB_MXL111SF_I2C_H_
+
+#include <linux/i2c.h>
+
+int mxl111sf_i2c_xfer(struct i2c_adapter *adap,
+                     struct i2c_msg msg[], int num);
+
+#endif /* _DVB_USB_MXL111SF_I2C_H_ */
+
+/*
+ * Local variables:
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/drivers/media/dvb/dvb-usb/mxl111sf-phy.c b/drivers/media/dvb/dvb-usb/mxl111sf-phy.c
new file mode 100644 (file)
index 0000000..91dc1fc
--- /dev/null
@@ -0,0 +1,342 @@
+/*
+ *  mxl111sf-phy.c - driver for the MaxLinear MXL111SF
+ *
+ *  Copyright (C) 2010 Michael Krufky <mkrufky@kernellabs.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include "mxl111sf-phy.h"
+#include "mxl111sf-reg.h"
+
+int mxl111sf_init_tuner_demod(struct mxl111sf_state *state)
+{
+       struct mxl111sf_reg_ctrl_info mxl_111_overwrite_default[] = {
+               {0x07, 0xff, 0x0c},
+               {0x58, 0xff, 0x9d},
+               {0x09, 0xff, 0x00},
+               {0x06, 0xff, 0x06},
+               {0xc8, 0xff, 0x40}, /* ED_LE_WIN_OLD = 0 */
+               {0x8d, 0x01, 0x01}, /* NEGATE_Q */
+               {0x32, 0xff, 0xac}, /* DIG_RFREFSELECT = 12 */
+               {0x42, 0xff, 0x43}, /* DIG_REG_AMP = 4 */
+               {0x74, 0xff, 0xc4}, /* SSPUR_FS_PRIO = 4 */
+               {0x71, 0xff, 0xe6}, /* SPUR_ROT_PRIO_VAL = 1 */
+               {0x83, 0xff, 0x64}, /* INF_FILT1_THD_SC = 100 */
+               {0x85, 0xff, 0x64}, /* INF_FILT2_THD_SC = 100 */
+               {0x88, 0xff, 0xf0}, /* INF_THD = 240 */
+               {0x6f, 0xf0, 0xb0}, /* DFE_DLY = 11 */
+               {0x00, 0xff, 0x01}, /* Change to page 1 */
+               {0x81, 0xff, 0x11}, /* DSM_FERR_BYPASS = 1 */
+               {0xf4, 0xff, 0x07}, /* DIG_FREQ_CORR = 1 */
+               {0xd4, 0x1f, 0x0f}, /* SPUR_TEST_NOISE_TH = 15 */
+               {0xd6, 0xff, 0x0c}, /* SPUR_TEST_NOISE_PAPR = 12 */
+               {0x00, 0xff, 0x00}, /* Change to page 0 */
+               {0,    0,    0}
+       };
+
+       mxl_debug("()");
+
+       return mxl111sf_ctrl_program_regs(state, mxl_111_overwrite_default);
+}
+
+int mxl1x1sf_soft_reset(struct mxl111sf_state *state)
+{
+       int ret;
+       mxl_debug("()");
+
+       ret = mxl111sf_write_reg(state, 0xff, 0x00); /* AIC */
+       if (mxl_fail(ret))
+               goto fail;
+       ret = mxl111sf_write_reg(state, 0x02, 0x01); /* get out of reset */
+       mxl_fail(ret);
+fail:
+       return ret;
+}
+
+int mxl1x1sf_set_device_mode(struct mxl111sf_state *state, int mode)
+{
+       int ret;
+
+       mxl_debug("(%s)", MXL_SOC_MODE == mode ?
+               "MXL_SOC_MODE" : "MXL_TUNER_MODE");
+
+       /* set device mode */
+       ret = mxl111sf_write_reg(state, 0x03,
+                                MXL_SOC_MODE == mode ? 0x01 : 0x00);
+       if (mxl_fail(ret))
+               goto fail;
+
+       ret = mxl111sf_write_reg_mask(state,
+                                     0x7d, 0x40, MXL_SOC_MODE == mode ?
+                                     0x00 : /* enable impulse noise filter,
+                                               INF_BYP = 0 */
+                                     0x40); /* disable impulse noise filter,
+                                               INF_BYP = 1 */
+       if (mxl_fail(ret))
+               goto fail;
+
+       state->device_mode = mode;
+fail:
+       return ret;
+}
+
+/* power up tuner */
+int mxl1x1sf_top_master_ctrl(struct mxl111sf_state *state, int onoff)
+{
+       mxl_debug("(%d)", onoff);
+
+       return mxl111sf_write_reg(state, 0x01, onoff ? 0x01 : 0x00);
+}
+
+int mxl111sf_disable_656_port(struct mxl111sf_state *state)
+{
+       mxl_debug("()");
+
+       return mxl111sf_write_reg_mask(state, 0x12, 0x04, 0x00);
+}
+
+int mxl111sf_enable_usb_output(struct mxl111sf_state *state)
+{
+       mxl_debug("()");
+
+       return mxl111sf_write_reg_mask(state, 0x17, 0x40, 0x00);
+}
+
+/* initialize TSIF as input port of MxL1X1SF for MPEG2 data transfer */
+int mxl111sf_config_mpeg_in(struct mxl111sf_state *state,
+                           unsigned int parallel_serial,
+                           unsigned int msb_lsb_1st,
+                           unsigned int clock_phase,
+                           unsigned int mpeg_valid_pol,
+                           unsigned int mpeg_sync_pol)
+{
+       int ret;
+       u8 mode, tmp;
+
+       mxl_debug("(%u,%u,%u,%u,%u)", parallel_serial, msb_lsb_1st,
+                 clock_phase, mpeg_valid_pol, mpeg_sync_pol);
+
+       /* Enable PIN MUX */
+       ret = mxl111sf_write_reg(state, V6_PIN_MUX_MODE_REG, V6_ENABLE_PIN_MUX);
+       mxl_fail(ret);
+
+       /* Configure MPEG Clock phase */
+       mxl111sf_read_reg(state, V6_MPEG_IN_CLK_INV_REG, &mode);
+
+       if (clock_phase == TSIF_NORMAL)
+               mode &= ~V6_INVERTED_CLK_PHASE;
+       else
+               mode |= V6_INVERTED_CLK_PHASE;
+
+       ret = mxl111sf_write_reg(state, V6_MPEG_IN_CLK_INV_REG, mode);
+       mxl_fail(ret);
+
+       /* Configure data input mode, MPEG Valid polarity, MPEG Sync polarity
+        * Get current configuration */
+       ret = mxl111sf_read_reg(state, V6_MPEG_IN_CTRL_REG, &mode);
+       mxl_fail(ret);
+
+       /* Data Input mode */
+       if (parallel_serial == TSIF_INPUT_PARALLEL) {
+               /* Disable serial mode */
+               mode &= ~V6_MPEG_IN_DATA_SERIAL;
+
+               /* Enable Parallel mode */
+               mode |= V6_MPEG_IN_DATA_PARALLEL;
+       } else {
+               /* Disable Parallel mode */
+               mode &= ~V6_MPEG_IN_DATA_PARALLEL;
+
+               /* Enable Serial Mode */
+               mode |= V6_MPEG_IN_DATA_SERIAL;
+
+               /* If serial interface is chosen, configure
+                  MSB or LSB order in transmission */
+               ret = mxl111sf_read_reg(state,
+                                       V6_MPEG_INOUT_BIT_ORDER_CTRL_REG,
+                                       &tmp);
+               mxl_fail(ret);
+
+               if (msb_lsb_1st == MPEG_SER_MSB_FIRST_ENABLED)
+                       tmp |= V6_MPEG_SER_MSB_FIRST;
+               else
+                       tmp &= ~V6_MPEG_SER_MSB_FIRST;
+
+               ret = mxl111sf_write_reg(state,
+                                        V6_MPEG_INOUT_BIT_ORDER_CTRL_REG,
+                                        tmp);
+               mxl_fail(ret);
+       }
+
+       /* MPEG Sync polarity */
+       if (mpeg_sync_pol == TSIF_NORMAL)
+               mode &= ~V6_INVERTED_MPEG_SYNC;
+       else
+               mode |= V6_INVERTED_MPEG_SYNC;
+
+       /* MPEG Valid polarity */
+       if (mpeg_valid_pol == 0)
+               mode &= ~V6_INVERTED_MPEG_VALID;
+       else
+               mode |= V6_INVERTED_MPEG_VALID;
+
+       ret = mxl111sf_write_reg(state, V6_MPEG_IN_CTRL_REG, mode);
+       mxl_fail(ret);
+
+       return ret;
+}
+
+int mxl111sf_init_i2s_port(struct mxl111sf_state *state, u8 sample_size)
+{
+       static struct mxl111sf_reg_ctrl_info init_i2s[] = {
+               {0x1b, 0xff, 0x1e}, /* pin mux mode, Choose 656/I2S input */
+               {0x15, 0x60, 0x60}, /* Enable I2S */
+               {0x17, 0xe0, 0x20}, /* Input, MPEG MODE USB,
+                                      Inverted 656 Clock, I2S_SOFT_RESET,
+                                      0 : Normal operation, 1 : Reset State */
+#if 0
+               {0x12, 0x01, 0x00}, /* AUDIO_IRQ_CLR (Overflow Indicator) */
+#endif
+               {0x00, 0xff, 0x02}, /* Change to Control Page */
+               {0x26, 0x0d, 0x0d}, /* I2S_MODE & BT656_SRC_SEL for FPGA only */
+               {0x00, 0xff, 0x00},
+               {0,    0,    0}
+       };
+       int ret;
+
+       mxl_debug("(0x%02x)", sample_size);
+
+       ret = mxl111sf_ctrl_program_regs(state, init_i2s);
+       if (mxl_fail(ret))
+               goto fail;
+
+       ret = mxl111sf_write_reg(state, V6_I2S_NUM_SAMPLES_REG, sample_size);
+       mxl_fail(ret);
+fail:
+       return ret;
+}
+
+int mxl111sf_disable_i2s_port(struct mxl111sf_state *state)
+{
+       static struct mxl111sf_reg_ctrl_info disable_i2s[] = {
+               {0x15, 0x40, 0x00},
+               {0,    0,    0}
+       };
+
+       mxl_debug("()");
+
+       return mxl111sf_ctrl_program_regs(state, disable_i2s);
+}
+
+int mxl111sf_config_i2s(struct mxl111sf_state *state,
+                       u8 msb_start_pos, u8 data_width)
+{
+       int ret;
+       u8 tmp;
+
+       mxl_debug("(0x%02x, 0x%02x)", msb_start_pos, data_width);
+
+       ret = mxl111sf_read_reg(state, V6_I2S_STREAM_START_BIT_REG, &tmp);
+       if (mxl_fail(ret))
+               goto fail;
+
+       tmp &= 0xe0;
+       tmp |= msb_start_pos;
+       ret = mxl111sf_write_reg(state, V6_I2S_STREAM_START_BIT_REG, tmp);
+       if (mxl_fail(ret))
+               goto fail;
+
+       ret = mxl111sf_read_reg(state, V6_I2S_STREAM_END_BIT_REG, &tmp);
+       if (mxl_fail(ret))
+               goto fail;
+
+       tmp &= 0xe0;
+       tmp |= data_width;
+       ret = mxl111sf_write_reg(state, V6_I2S_STREAM_END_BIT_REG, tmp);
+       mxl_fail(ret);
+fail:
+       return ret;
+}
+
+int mxl111sf_config_spi(struct mxl111sf_state *state, int onoff)
+{
+       u8 val;
+       int ret;
+
+       mxl_debug("(%d)", onoff);
+
+       ret = mxl111sf_write_reg(state, 0x00, 0x02);
+       if (mxl_fail(ret))
+               goto fail;
+
+       ret = mxl111sf_read_reg(state, V8_SPI_MODE_REG, &val);
+       if (mxl_fail(ret))
+               goto fail;
+
+       if (onoff)
+               val |= 0x04;
+       else
+               val &= ~0x04;
+
+       ret = mxl111sf_write_reg(state, V8_SPI_MODE_REG, val);
+       if (mxl_fail(ret))
+               goto fail;
+
+       ret = mxl111sf_write_reg(state, 0x00, 0x00);
+       if (mxl_fail(ret))
+               goto fail;
+fail:
+       return ret;
+}
+
+int mxl111sf_idac_config(struct mxl111sf_state *state,
+                        u8 control_mode, u8 current_setting,
+                        u8 current_value, u8 hysteresis_value)
+{
+       int ret;
+       u8 val;
+       /* current value will be set for both automatic & manual IDAC control */
+       val = current_value;
+
+       if (control_mode == IDAC_MANUAL_CONTROL) {
+               /* enable manual control of IDAC */
+               val |= IDAC_MANUAL_CONTROL_BIT_MASK;
+
+               if (current_setting == IDAC_CURRENT_SINKING_ENABLE)
+                       /* enable current sinking in manual mode */
+                       val |= IDAC_CURRENT_SINKING_BIT_MASK;
+               else
+                       /* disable current sinking in manual mode */
+                       val &= ~IDAC_CURRENT_SINKING_BIT_MASK;
+       } else {
+               /* disable manual control of IDAC */
+               val &= ~IDAC_MANUAL_CONTROL_BIT_MASK;
+
+               /* set hysteresis value  reg: 0x0B<5:0> */
+               ret = mxl111sf_write_reg(state, V6_IDAC_HYSTERESIS_REG,
+                                        (hysteresis_value & 0x3F));
+       }
+
+       ret = mxl111sf_write_reg(state, V6_IDAC_SETTINGS_REG, val);
+
+       return val;
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/drivers/media/dvb/dvb-usb/mxl111sf-phy.h b/drivers/media/dvb/dvb-usb/mxl111sf-phy.h
new file mode 100644 (file)
index 0000000..f075607
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ *  mxl111sf-phy.h - driver for the MaxLinear MXL111SF
+ *
+ *  Copyright (C) 2010 Michael Krufky <mkrufky@kernellabs.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef _DVB_USB_MXL111SF_PHY_H_
+#define _DVB_USB_MXL111SF_PHY_H_
+
+#include "mxl111sf.h"
+
+int mxl1x1sf_soft_reset(struct mxl111sf_state *state);
+int mxl1x1sf_set_device_mode(struct mxl111sf_state *state, int mode);
+int mxl1x1sf_top_master_ctrl(struct mxl111sf_state *state, int onoff);
+int mxl111sf_disable_656_port(struct mxl111sf_state *state);
+int mxl111sf_init_tuner_demod(struct mxl111sf_state *state);
+int mxl111sf_enable_usb_output(struct mxl111sf_state *state);
+int mxl111sf_config_mpeg_in(struct mxl111sf_state *state,
+                           unsigned int parallel_serial,
+                           unsigned int msb_lsb_1st,
+                           unsigned int clock_phase,
+                           unsigned int mpeg_valid_pol,
+                           unsigned int mpeg_sync_pol);
+int mxl111sf_config_i2s(struct mxl111sf_state *state,
+                       u8 msb_start_pos, u8 data_width);
+int mxl111sf_init_i2s_port(struct mxl111sf_state *state, u8 sample_size);
+int mxl111sf_disable_i2s_port(struct mxl111sf_state *state);
+int mxl111sf_config_spi(struct mxl111sf_state *state, int onoff);
+int mxl111sf_idac_config(struct mxl111sf_state *state,
+                        u8 control_mode, u8 current_setting,
+                        u8 current_value, u8 hysteresis_value);
+
+#endif /* _DVB_USB_MXL111SF_PHY_H_ */
+
+/*
+ * Local variables:
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/drivers/media/dvb/dvb-usb/mxl111sf-reg.h b/drivers/media/dvb/dvb-usb/mxl111sf-reg.h
new file mode 100644 (file)
index 0000000..17831b0
--- /dev/null
@@ -0,0 +1,179 @@
+/*
+ *  mxl111sf-reg.h - driver for the MaxLinear MXL111SF
+ *
+ *  Copyright (C) 2010 Michael Krufky <mkrufky@kernellabs.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef _DVB_USB_MXL111SF_REG_H_
+#define _DVB_USB_MXL111SF_REG_H_
+
+#define CHIP_ID_REG                  0xFC
+#define TOP_CHIP_REV_ID_REG          0xFA
+
+#define V6_SNR_RB_LSB_REG            0x27
+#define V6_SNR_RB_MSB_REG            0x28
+
+#define V6_N_ACCUMULATE_REG          0x11
+#define V6_RS_AVG_ERRORS_LSB_REG     0x2C
+#define V6_RS_AVG_ERRORS_MSB_REG     0x2D
+
+#define V6_IRQ_STATUS_REG            0x24
+#define  IRQ_MASK_FEC_LOCK       0x10
+
+#define V6_SYNC_LOCK_REG             0x28
+#define SYNC_LOCK_MASK           0x10
+
+#define V6_RS_LOCK_DET_REG           0x28
+#define  RS_LOCK_DET_MASK        0x08
+
+#define V6_INITACQ_NODETECT_REG    0x20
+#define V6_FORCE_NFFT_CPSIZE_REG   0x20
+
+#define V6_CODE_RATE_TPS_REG       0x29
+#define V6_CODE_RATE_TPS_MASK      0x07
+
+
+#define V6_CP_LOCK_DET_REG        0x28
+#define V6_CP_LOCK_DET_MASK       0x04
+
+#define V6_TPS_HIERACHY_REG        0x29
+#define V6_TPS_HIERARCHY_INFO_MASK  0x40
+
+#define V6_MODORDER_TPS_REG        0x2A
+#define V6_PARAM_CONSTELLATION_MASK   0x30
+
+#define V6_MODE_TPS_REG            0x2A
+#define V6_PARAM_FFT_MODE_MASK        0x0C
+
+
+#define V6_CP_TPS_REG             0x29
+#define V6_PARAM_GI_MASK              0x30
+
+#define V6_TPS_LOCK_REG           0x2A
+#define V6_PARAM_TPS_LOCK_MASK        0x40
+
+#define V6_FEC_PER_COUNT_REG      0x2E
+#define V6_FEC_PER_SCALE_REG      0x2B
+#define V6_FEC_PER_SCALE_MASK        0x03
+#define V6_FEC_PER_CLR_REG        0x20
+#define V6_FEC_PER_CLR_MASK          0x01
+
+#define V6_PIN_MUX_MODE_REG       0x1B
+#define V6_ENABLE_PIN_MUX            0x1E
+
+#define V6_I2S_NUM_SAMPLES_REG    0x16
+
+#define V6_MPEG_IN_CLK_INV_REG    0x17
+#define V6_MPEG_IN_CTRL_REG       0x18
+
+#define V6_INVERTED_CLK_PHASE       0x20
+#define V6_MPEG_IN_DATA_PARALLEL    0x01
+#define V6_MPEG_IN_DATA_SERIAL      0x02
+
+#define V6_INVERTED_MPEG_SYNC       0x04
+#define V6_INVERTED_MPEG_VALID      0x08
+
+#define TSIF_INPUT_PARALLEL         0
+#define TSIF_INPUT_SERIAL           1
+#define TSIF_NORMAL                 0
+
+#define V6_MPEG_INOUT_BIT_ORDER_CTRL_REG  0x19
+#define V6_MPEG_SER_MSB_FIRST                0x80
+#define MPEG_SER_MSB_FIRST_ENABLED        0x01
+
+#define V6_656_I2S_BUFF_STATUS_REG   0x2F
+#define V6_656_OVERFLOW_MASK_BIT         0x08
+#define V6_I2S_OVERFLOW_MASK_BIT         0x01
+
+#define V6_I2S_STREAM_START_BIT_REG  0x14
+#define V6_I2S_STREAM_END_BIT_REG    0x15
+#define I2S_RIGHT_JUSTIFIED     0
+#define I2S_LEFT_JUSTIFIED      1
+#define I2S_DATA_FORMAT         2
+
+#define V6_TUNER_LOOP_THRU_CONTROL_REG  0x09
+#define V6_ENABLE_LOOP_THRU               0x01
+
+#define TOTAL_NUM_IF_OUTPUT_FREQ       16
+
+#define TUNER_NORMAL_IF_SPECTRUM       0x0
+#define TUNER_INVERT_IF_SPECTRUM       0x10
+
+#define V6_TUNER_IF_SEL_REG              0x06
+#define V6_TUNER_IF_FCW_REG              0x3C
+#define V6_TUNER_IF_FCW_BYP_REG          0x3D
+#define V6_RF_LOCK_STATUS_REG            0x23
+
+#define NUM_DIG_TV_CHANNEL     1000
+
+#define V6_DIG_CLK_FREQ_SEL_REG  0x07
+#define V6_REF_SYNTH_INT_REG     0x5C
+#define V6_REF_SYNTH_REMAIN_REG  0x58
+#define V6_DIG_RFREFSELECT_REG   0x32
+#define V6_XTAL_CLK_OUT_GAIN_REG   0x31
+#define V6_TUNER_LOOP_THRU_CTRL_REG      0x09
+#define V6_DIG_XTAL_ENABLE_REG  0x06
+#define V6_DIG_XTAL_BIAS_REG  0x66
+#define V6_XTAL_CAP_REG    0x08
+
+#define V6_GPO_CTRL_REG     0x18
+#define MXL_GPO_0           0x00
+#define MXL_GPO_1           0x01
+#define V6_GPO_0_MASK       0x10
+#define V6_GPO_1_MASK       0x20
+
+#define V6_111SF_GPO_CTRL_REG     0x19
+#define MXL_111SF_GPO_1               0x00
+#define MXL_111SF_GPO_2               0x01
+#define MXL_111SF_GPO_3               0x02
+#define MXL_111SF_GPO_4               0x03
+#define MXL_111SF_GPO_5               0x04
+#define MXL_111SF_GPO_6               0x05
+#define MXL_111SF_GPO_7               0x06
+
+#define MXL_111SF_GPO_0_MASK          0x01
+#define MXL_111SF_GPO_1_MASK          0x02
+#define MXL_111SF_GPO_2_MASK          0x04
+#define MXL_111SF_GPO_3_MASK          0x08
+#define MXL_111SF_GPO_4_MASK          0x10
+#define MXL_111SF_GPO_5_MASK          0x20
+#define MXL_111SF_GPO_6_MASK          0x40
+
+#define V6_ATSC_CONFIG_REG  0x0A
+
+#define MXL_MODE_REG    0x03
+#define START_TUNE_REG  0x1C
+
+#define V6_IDAC_HYSTERESIS_REG    0x0B
+#define V6_IDAC_SETTINGS_REG      0x0C
+#define IDAC_MANUAL_CONTROL             1
+#define IDAC_CURRENT_SINKING_ENABLE     1
+#define IDAC_MANUAL_CONTROL_BIT_MASK      0x80
+#define IDAC_CURRENT_SINKING_BIT_MASK     0x40
+
+#define V8_SPI_MODE_REG  0xE9
+
+#define V6_DIG_RF_PWR_LSB_REG  0x46
+#define V6_DIG_RF_PWR_MSB_REG  0x47
+
+#endif /* _DVB_USB_MXL111SF_REG_H_ */
+
+/*
+ * Local variables:
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/drivers/media/dvb/dvb-usb/mxl111sf-tuner.c b/drivers/media/dvb/dvb-usb/mxl111sf-tuner.c
new file mode 100644 (file)
index 0000000..a634105
--- /dev/null
@@ -0,0 +1,476 @@
+/*
+ *  mxl111sf-tuner.c - driver for the MaxLinear MXL111SF CMOS tuner
+ *
+ *  Copyright (C) 2010 Michael Krufky <mkrufky@kernellabs.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include "mxl111sf-tuner.h"
+#include "mxl111sf-phy.h"
+#include "mxl111sf-reg.h"
+
+/* debug */
+static int mxl111sf_tuner_debug;
+module_param_named(debug, mxl111sf_tuner_debug, int, 0644);
+MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able)).");
+
+#define mxl_dbg(fmt, arg...) \
+       if (mxl111sf_tuner_debug) \
+               mxl_printk(KERN_DEBUG, fmt, ##arg)
+
+/* ------------------------------------------------------------------------ */
+
+struct mxl111sf_tuner_state {
+       struct mxl111sf_state *mxl_state;
+
+       struct mxl111sf_tuner_config *cfg;
+
+       u32 frequency;
+       u32 bandwidth;
+};
+
+static int mxl111sf_tuner_read_reg(struct mxl111sf_tuner_state *state,
+                                  u8 addr, u8 *data)
+{
+       return (state->cfg->read_reg) ?
+               state->cfg->read_reg(state->mxl_state, addr, data) :
+               -EINVAL;
+}
+
+static int mxl111sf_tuner_write_reg(struct mxl111sf_tuner_state *state,
+                                   u8 addr, u8 data)
+{
+       return (state->cfg->write_reg) ?
+               state->cfg->write_reg(state->mxl_state, addr, data) :
+               -EINVAL;
+}
+
+static int mxl111sf_tuner_program_regs(struct mxl111sf_tuner_state *state,
+                              struct mxl111sf_reg_ctrl_info *ctrl_reg_info)
+{
+       return (state->cfg->program_regs) ?
+               state->cfg->program_regs(state->mxl_state, ctrl_reg_info) :
+               -EINVAL;
+}
+
+static int mxl1x1sf_tuner_top_master_ctrl(struct mxl111sf_tuner_state *state,
+                                         int onoff)
+{
+       return (state->cfg->top_master_ctrl) ?
+               state->cfg->top_master_ctrl(state->mxl_state, onoff) :
+               -EINVAL;
+}
+
+/* ------------------------------------------------------------------------ */
+
+static struct mxl111sf_reg_ctrl_info mxl_phy_tune_rf[] = {
+       {0x1d, 0x7f, 0x00}, /* channel bandwidth section 1/2/3,
+                              DIG_MODEINDEX, _A, _CSF, */
+       {0x1e, 0xff, 0x00}, /* channel frequency (lo and fractional) */
+       {0x1f, 0xff, 0x00}, /* channel frequency (hi for integer portion) */
+       {0,    0,    0}
+};
+
+/* ------------------------------------------------------------------------ */
+
+static struct mxl111sf_reg_ctrl_info *mxl111sf_calc_phy_tune_regs(u32 freq,
+                                                                 u8 bw)
+{
+       u8 filt_bw;
+
+       /* set channel bandwidth */
+       switch (bw) {
+       case 0: /* ATSC */
+               filt_bw = 25;
+               break;
+       case 1: /* QAM */
+               filt_bw = 69;
+               break;
+       case 6:
+               filt_bw = 21;
+               break;
+       case 7:
+               filt_bw = 42;
+               break;
+       case 8:
+               filt_bw = 63;
+               break;
+       default:
+               err("%s: invalid bandwidth setting!", __func__);
+               return NULL;
+       }
+
+       /* calculate RF channel */
+       freq /= 1000000;
+
+       freq *= 64;
+#if 0
+       /* do round */
+       freq += 0.5;
+#endif
+       /* set bandwidth */
+       mxl_phy_tune_rf[0].data = filt_bw;
+
+       /* set RF */
+       mxl_phy_tune_rf[1].data = (freq & 0xff);
+       mxl_phy_tune_rf[2].data = (freq >> 8) & 0xff;
+
+       /* start tune */
+       return mxl_phy_tune_rf;
+}
+
+static int mxl1x1sf_tuner_set_if_output_freq(struct mxl111sf_tuner_state *state)
+{
+       int ret;
+       u8 ctrl;
+#if 0
+       u16 iffcw;
+       u32 if_freq;
+#endif
+       mxl_dbg("(IF polarity = %d, IF freq = 0x%02x)",
+               state->cfg->invert_spectrum, state->cfg->if_freq);
+
+       /* set IF polarity */
+       ctrl = state->cfg->invert_spectrum;
+
+       ctrl |= state->cfg->if_freq;
+
+       ret = mxl111sf_tuner_write_reg(state, V6_TUNER_IF_SEL_REG, ctrl);
+       if (mxl_fail(ret))
+               goto fail;
+
+#if 0
+       if_freq /= 1000000;
+
+       /* do round */
+       if_freq += 0.5;
+
+       if (MXL_IF_LO == state->cfg->if_freq) {
+               ctrl = 0x08;
+               iffcw = (u16)(if_freq / (108 * 4096));
+       } else if (MXL_IF_HI == state->cfg->if_freq) {
+               ctrl = 0x08;
+               iffcw = (u16)(if_freq / (216 * 4096));
+       } else {
+               ctrl = 0;
+               iffcw = 0;
+       }
+
+       ctrl |= (iffcw >> 8);
+#endif
+       ret = mxl111sf_tuner_read_reg(state, V6_TUNER_IF_FCW_BYP_REG, &ctrl);
+       if (mxl_fail(ret))
+               goto fail;
+
+       ctrl &= 0xf0;
+       ctrl |= 0x90;
+
+       ret = mxl111sf_tuner_write_reg(state, V6_TUNER_IF_FCW_BYP_REG, ctrl);
+       if (mxl_fail(ret))
+               goto fail;
+
+#if 0
+       ctrl = iffcw & 0x00ff;
+#endif
+       ret = mxl111sf_tuner_write_reg(state, V6_TUNER_IF_FCW_REG, ctrl);
+       mxl_fail(ret);
+fail:
+       return ret;
+}
+
+static int mxl1x1sf_tune_rf(struct dvb_frontend *fe, u32 freq, u8 bw)
+{
+       struct mxl111sf_tuner_state *state = fe->tuner_priv;
+       static struct mxl111sf_reg_ctrl_info *reg_ctrl_array;
+       int ret;
+       u8 mxl_mode;
+
+       mxl_dbg("(freq = %d, bw = 0x%x)", freq, bw);
+
+       /* stop tune */
+       ret = mxl111sf_tuner_write_reg(state, START_TUNE_REG, 0);
+       if (mxl_fail(ret))
+               goto fail;
+
+       /* check device mode */
+       ret = mxl111sf_tuner_read_reg(state, MXL_MODE_REG, &mxl_mode);
+       if (mxl_fail(ret))
+               goto fail;
+
+       /* Fill out registers for channel tune */
+       reg_ctrl_array = mxl111sf_calc_phy_tune_regs(freq, bw);
+       if (!reg_ctrl_array)
+               return -EINVAL;
+
+       ret = mxl111sf_tuner_program_regs(state, reg_ctrl_array);
+       if (mxl_fail(ret))
+               goto fail;
+
+       if ((mxl_mode & MXL_DEV_MODE_MASK) == MXL_TUNER_MODE) {
+               /* IF tuner mode only */
+               mxl1x1sf_tuner_top_master_ctrl(state, 0);
+               mxl1x1sf_tuner_top_master_ctrl(state, 1);
+               mxl1x1sf_tuner_set_if_output_freq(state);
+       }
+
+       ret = mxl111sf_tuner_write_reg(state, START_TUNE_REG, 1);
+       if (mxl_fail(ret))
+               goto fail;
+
+       if (state->cfg->ant_hunt)
+               state->cfg->ant_hunt(fe);
+fail:
+       return ret;
+}
+
+static int mxl1x1sf_tuner_get_lock_status(struct mxl111sf_tuner_state *state,
+                                         int *rf_synth_lock,
+                                         int *ref_synth_lock)
+{
+       int ret;
+       u8 data;
+
+       *rf_synth_lock = 0;
+       *ref_synth_lock = 0;
+
+       ret = mxl111sf_tuner_read_reg(state, V6_RF_LOCK_STATUS_REG, &data);
+       if (mxl_fail(ret))
+               goto fail;
+
+       *ref_synth_lock = ((data & 0x03) == 0x03) ? 1 : 0;
+       *rf_synth_lock  = ((data & 0x0c) == 0x0c) ? 1 : 0;
+fail:
+       return ret;
+}
+
+#if 0
+static int mxl1x1sf_tuner_loop_thru_ctrl(struct mxl111sf_tuner_state *state,
+                                        int onoff)
+{
+       return mxl111sf_tuner_write_reg(state, V6_TUNER_LOOP_THRU_CTRL_REG,
+                                       onoff ? 1 : 0);
+}
+#endif
+
+/* ------------------------------------------------------------------------ */
+
+static int mxl111sf_tuner_set_params(struct dvb_frontend *fe,
+                                    struct dvb_frontend_parameters *params)
+{
+       struct mxl111sf_tuner_state *state = fe->tuner_priv;
+       int ret;
+       u8 bw;
+
+       mxl_dbg("()");
+
+       if (fe->ops.info.type == FE_ATSC) {
+               switch (params->u.vsb.modulation) {
+               case VSB_8:
+               case VSB_16:
+                       bw = 0; /* ATSC */
+                       break;
+               case QAM_64:
+               case QAM_256:
+                       bw = 1; /* US CABLE */
+                       break;
+               default:
+                       err("%s: modulation not set!", __func__);
+                       return -EINVAL;
+               }
+       } else if (fe->ops.info.type == FE_OFDM) {
+               switch (params->u.ofdm.bandwidth) {
+               case BANDWIDTH_6_MHZ:
+                       bw = 6;
+                       break;
+               case BANDWIDTH_7_MHZ:
+                       bw = 7;
+                       break;
+               case BANDWIDTH_8_MHZ:
+                       bw = 8;
+                       break;
+               default:
+                       err("%s: bandwidth not set!", __func__);
+                       return -EINVAL;
+               }
+       } else {
+               err("%s: modulation type not supported!", __func__);
+               return -EINVAL;
+       }
+       ret = mxl1x1sf_tune_rf(fe, params->frequency, bw);
+       if (mxl_fail(ret))
+               goto fail;
+
+       state->frequency = params->frequency;
+       state->bandwidth = (fe->ops.info.type == FE_OFDM) ?
+               params->u.ofdm.bandwidth : 0;
+fail:
+       return ret;
+}
+
+/* ------------------------------------------------------------------------ */
+
+#if 0
+static int mxl111sf_tuner_init(struct dvb_frontend *fe)
+{
+       struct mxl111sf_tuner_state *state = fe->tuner_priv;
+       int ret;
+
+       /* wake from standby handled by usb driver */
+
+       return ret;
+}
+
+static int mxl111sf_tuner_sleep(struct dvb_frontend *fe)
+{
+       struct mxl111sf_tuner_state *state = fe->tuner_priv;
+       int ret;
+
+       /* enter standby mode handled by usb driver */
+
+       return ret;
+}
+#endif
+
+/* ------------------------------------------------------------------------ */
+
+static int mxl111sf_tuner_get_status(struct dvb_frontend *fe, u32 *status)
+{
+       struct mxl111sf_tuner_state *state = fe->tuner_priv;
+       int rf_locked, ref_locked, ret;
+
+       *status = 0;
+
+       ret = mxl1x1sf_tuner_get_lock_status(state, &rf_locked, &ref_locked);
+       if (mxl_fail(ret))
+               goto fail;
+       mxl_info("%s%s", rf_locked ? "rf locked " : "",
+                ref_locked ? "ref locked" : "");
+
+       if ((rf_locked) || (ref_locked))
+               *status |= TUNER_STATUS_LOCKED;
+fail:
+       return ret;
+}
+
+static int mxl111sf_get_rf_strength(struct dvb_frontend *fe, u16 *strength)
+{
+       struct mxl111sf_tuner_state *state = fe->tuner_priv;
+       u8 val1, val2;
+       int ret;
+
+       *strength = 0;
+
+       ret = mxl111sf_tuner_write_reg(state, 0x00, 0x02);
+       if (mxl_fail(ret))
+               goto fail;
+       ret = mxl111sf_tuner_read_reg(state, V6_DIG_RF_PWR_LSB_REG, &val1);
+       if (mxl_fail(ret))
+               goto fail;
+       ret = mxl111sf_tuner_read_reg(state, V6_DIG_RF_PWR_MSB_REG, &val2);
+       if (mxl_fail(ret))
+               goto fail;
+
+       *strength = val1 | ((val2 & 0x07) << 8);
+fail:
+       ret = mxl111sf_tuner_write_reg(state, 0x00, 0x00);
+       mxl_fail(ret);
+
+       return ret;
+}
+
+/* ------------------------------------------------------------------------ */
+
+static int mxl111sf_tuner_get_frequency(struct dvb_frontend *fe, u32 *frequency)
+{
+       struct mxl111sf_tuner_state *state = fe->tuner_priv;
+       *frequency = state->frequency;
+       return 0;
+}
+
+static int mxl111sf_tuner_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
+{
+       struct mxl111sf_tuner_state *state = fe->tuner_priv;
+       *bandwidth = state->bandwidth;
+       return 0;
+}
+
+static int mxl111sf_tuner_release(struct dvb_frontend *fe)
+{
+       struct mxl111sf_tuner_state *state = fe->tuner_priv;
+       mxl_dbg("()");
+       kfree(state);
+       fe->tuner_priv = NULL;
+       return 0;
+}
+
+/* ------------------------------------------------------------------------- */
+
+static struct dvb_tuner_ops mxl111sf_tuner_tuner_ops = {
+       .info = {
+               .name = "MaxLinear MxL111SF",
+#if 0
+               .frequency_min  = ,
+               .frequency_max  = ,
+               .frequency_step = ,
+#endif
+       },
+#if 0
+       .init              = mxl111sf_tuner_init,
+       .sleep             = mxl111sf_tuner_sleep,
+#endif
+       .set_params        = mxl111sf_tuner_set_params,
+       .get_status        = mxl111sf_tuner_get_status,
+       .get_rf_strength   = mxl111sf_get_rf_strength,
+       .get_frequency     = mxl111sf_tuner_get_frequency,
+       .get_bandwidth     = mxl111sf_tuner_get_bandwidth,
+       .release           = mxl111sf_tuner_release,
+};
+
+struct dvb_frontend *mxl111sf_tuner_attach(struct dvb_frontend *fe,
+                                          struct mxl111sf_state *mxl_state,
+                                          struct mxl111sf_tuner_config *cfg)
+{
+       struct mxl111sf_tuner_state *state = NULL;
+
+       mxl_dbg("()");
+
+       state = kzalloc(sizeof(struct mxl111sf_tuner_state), GFP_KERNEL);
+       if (state == NULL)
+               return NULL;
+
+       state->mxl_state = mxl_state;
+       state->cfg = cfg;
+
+       memcpy(&fe->ops.tuner_ops, &mxl111sf_tuner_tuner_ops,
+              sizeof(struct dvb_tuner_ops));
+
+       fe->tuner_priv = state;
+       return fe;
+}
+EXPORT_SYMBOL_GPL(mxl111sf_tuner_attach);
+
+MODULE_DESCRIPTION("MaxLinear MxL111SF CMOS tuner driver");
+MODULE_AUTHOR("Michael Krufky <mkrufky@kernellabs.com>");
+MODULE_LICENSE("GPL");
+MODULE_VERSION("0.1");
+
+/*
+ * Overrides for Emacs so that we follow Linus's tabbing style.
+ * ---------------------------------------------------------------------------
+ * Local variables:
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/drivers/media/dvb/dvb-usb/mxl111sf-tuner.h b/drivers/media/dvb/dvb-usb/mxl111sf-tuner.h
new file mode 100644 (file)
index 0000000..ff33396
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ *  mxl111sf-tuner.h - driver for the MaxLinear MXL111SF CMOS tuner
+ *
+ *  Copyright (C) 2010 Michael Krufky <mkrufky@kernellabs.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef __MXL111SF_TUNER_H__
+#define __MXL111SF_TUNER_H__
+
+#include "dvb_frontend.h"
+
+#include "mxl111sf.h"
+
+enum mxl_if_freq {
+#if 0
+       MXL_IF_LO    = 0x00, /* other IF < 9MHz */
+#endif
+       MXL_IF_4_0   = 0x01, /* 4.0   MHz */
+       MXL_IF_4_5   = 0x02, /* 4.5   MHz */
+       MXL_IF_4_57  = 0x03, /* 4.57  MHz */
+       MXL_IF_5_0   = 0x04, /* 5.0   MHz */
+       MXL_IF_5_38  = 0x05, /* 5.38  MHz */
+       MXL_IF_6_0   = 0x06, /* 6.0   MHz */
+       MXL_IF_6_28  = 0x07, /* 6.28  MHz */
+       MXL_IF_7_2   = 0x08, /* 7.2   MHz */
+       MXL_IF_35_25 = 0x09, /* 35.25 MHz */
+       MXL_IF_36    = 0x0a, /* 36    MHz */
+       MXL_IF_36_15 = 0x0b, /* 36.15 MHz */
+       MXL_IF_44    = 0x0c, /* 44    MHz */
+#if 0
+       MXL_IF_HI    = 0x0f, /* other IF > 35 MHz and < 45 MHz */
+#endif
+};
+
+struct mxl111sf_tuner_config {
+       enum mxl_if_freq if_freq;
+       unsigned int invert_spectrum:1;
+
+       int (*read_reg)(struct mxl111sf_state *state, u8 addr, u8 *data);
+       int (*write_reg)(struct mxl111sf_state *state, u8 addr, u8 data);
+       int (*program_regs)(struct mxl111sf_state *state,
+                           struct mxl111sf_reg_ctrl_info *ctrl_reg_info);
+       int (*top_master_ctrl)(struct mxl111sf_state *state, int onoff);
+       int (*ant_hunt)(struct dvb_frontend *fe);
+};
+
+/* ------------------------------------------------------------------------ */
+
+#if defined(CONFIG_DVB_USB_MXL111SF) || \
+       (defined(CONFIG_DVB_USB_MXL111SF_MODULE) && defined(MODULE))
+extern
+struct dvb_frontend *mxl111sf_tuner_attach(struct dvb_frontend *fe,
+                                          struct mxl111sf_state *mxl_state,
+                                          struct mxl111sf_tuner_config *cfg);
+#else
+static inline
+struct dvb_frontend *mxl111sf_tuner_attach(struct dvb_frontend *fe,
+                                          struct mxl111sf_state *mxl_state
+                                          struct mxl111sf_tuner_config *cfg)
+{
+       printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
+       return NULL;
+}
+#endif
+
+#endif /* __MXL111SF_TUNER_H__ */
+
+/*
+ * Overrides for Emacs so that we follow Linus's tabbing style.
+ * ---------------------------------------------------------------------------
+ * Local variables:
+ * c-basic-offset: 8
+ * End:
+ */
+
diff --git a/drivers/media/dvb/dvb-usb/mxl111sf.c b/drivers/media/dvb/dvb-usb/mxl111sf.c
new file mode 100644 (file)
index 0000000..546ba59
--- /dev/null
@@ -0,0 +1,864 @@
+/*
+ * Copyright (C) 2010 Michael Krufky (mkrufky@kernellabs.com)
+ *
+ *   This program is free software; you can redistribute it and/or modify it
+ *   under the terms of the GNU General Public License as published by the Free
+ *   Software Foundation, version 2.
+ *
+ * see Documentation/dvb/README.dvb-usb for more information
+ */
+
+#include <linux/vmalloc.h>
+#include <linux/i2c.h>
+
+#include "mxl111sf.h"
+#include "mxl111sf-reg.h"
+#include "mxl111sf-phy.h"
+#include "mxl111sf-i2c.h"
+#include "mxl111sf-gpio.h"
+
+#include "mxl111sf-tuner.h"
+
+#include "lgdt3305.h"
+
+int dvb_usb_mxl111sf_debug;
+module_param_named(debug, dvb_usb_mxl111sf_debug, int, 0644);
+MODULE_PARM_DESC(debug, "set debugging level "
+                "(1=info, 2=xfer, 4=i2c, 8=reg, 16=adv (or-able)).");
+
+int dvb_usb_mxl111sf_isoc;
+module_param_named(isoc, dvb_usb_mxl111sf_isoc, int, 0644);
+MODULE_PARM_DESC(isoc, "enable usb isoc xfer (0=bulk, 1=isoc).");
+
+#define ANT_PATH_AUTO 0
+#define ANT_PATH_EXTERNAL 1
+#define ANT_PATH_INTERNAL 2
+
+int dvb_usb_mxl111sf_rfswitch =
+#if 0
+               ANT_PATH_AUTO;
+#else
+               ANT_PATH_EXTERNAL;
+#endif
+
+module_param_named(rfswitch, dvb_usb_mxl111sf_rfswitch, int, 0644);
+MODULE_PARM_DESC(rfswitch, "force rf switch position (0=auto, 1=ext, 2=int).");
+
+DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
+
+#define deb_info(args...)   dprintk(dvb_usb_mxl111sf_debug, 0x13, args)
+#define deb_reg(args...)    dprintk(dvb_usb_mxl111sf_debug, 0x08, args)
+#define deb_adv(args...)    dprintk(dvb_usb_mxl111sf_debug, MXL_ADV_DBG, args)
+
+int mxl111sf_ctrl_msg(struct dvb_usb_device *d,
+                     u8 cmd, u8 *wbuf, int wlen, u8 *rbuf, int rlen)
+{
+       int wo = (rbuf == NULL || rlen == 0); /* write-only */
+       int ret;
+       u8 sndbuf[1+wlen];
+
+       deb_adv("%s(wlen = %d, rlen = %d)\n", __func__, wlen, rlen);
+
+       memset(sndbuf, 0, 1+wlen);
+
+       sndbuf[0] = cmd;
+       memcpy(&sndbuf[1], wbuf, wlen);
+
+       ret = (wo) ? dvb_usb_generic_write(d, sndbuf, 1+wlen) :
+               dvb_usb_generic_rw(d, sndbuf, 1+wlen, rbuf, rlen, 0);
+       mxl_fail(ret);
+
+       return ret;
+}
+
+/* ------------------------------------------------------------------------ */
+
+#define MXL_CMD_REG_READ       0xaa
+#define MXL_CMD_REG_WRITE      0x55
+
+int mxl111sf_read_reg(struct mxl111sf_state *state, u8 addr, u8 *data)
+{
+       u8 buf[2];
+       int ret;
+
+       ret = mxl111sf_ctrl_msg(state->d, MXL_CMD_REG_READ, &addr, 1, buf, 2);
+       if (mxl_fail(ret)) {
+               mxl_debug("error reading reg: 0x%02x", addr);
+               goto fail;
+       }
+
+       if (buf[0] == addr)
+               *data = buf[1];
+       else {
+               err("invalid response reading reg: 0x%02x != 0x%02x, 0x%02x",
+                   addr, buf[0], buf[1]);
+               ret = -EINVAL;
+       }
+
+       deb_reg("R: (0x%02x, 0x%02x)\n", addr, *data);
+fail:
+       return ret;
+}
+
+int mxl111sf_write_reg(struct mxl111sf_state *state, u8 addr, u8 data)
+{
+       u8 buf[] = { addr, data };
+       int ret;
+
+       deb_reg("W: (0x%02x, 0x%02x)\n", addr, data);
+
+       ret = mxl111sf_ctrl_msg(state->d, MXL_CMD_REG_WRITE, buf, 2, NULL, 0);
+       if (mxl_fail(ret))
+               err("error writing reg: 0x%02x, val: 0x%02x", addr, data);
+       return ret;
+}
+
+/* ------------------------------------------------------------------------ */
+
+int mxl111sf_write_reg_mask(struct mxl111sf_state *state,
+                                  u8 addr, u8 mask, u8 data)
+{
+       int ret;
+       u8 val;
+
+       if (mask != 0xff) {
+               ret = mxl111sf_read_reg(state, addr, &val);
+#if 1
+               /* dont know why this usually errors out on the first try */
+               if (mxl_fail(ret))
+                       err("error writing addr: 0x%02x, mask: 0x%02x, "
+                           "data: 0x%02x, retrying...", addr, mask, data);
+
+               ret = mxl111sf_read_reg(state, addr, &val);
+#endif
+               if (mxl_fail(ret))
+                       goto fail;
+       }
+       val &= ~mask;
+       val |= data;
+
+       ret = mxl111sf_write_reg(state, addr, val);
+       mxl_fail(ret);
+fail:
+       return ret;
+}
+
+/* ------------------------------------------------------------------------ */
+
+int mxl111sf_ctrl_program_regs(struct mxl111sf_state *state,
+                              struct mxl111sf_reg_ctrl_info *ctrl_reg_info)
+{
+       int i, ret = 0;
+
+       for (i = 0;  ctrl_reg_info[i].addr |
+                    ctrl_reg_info[i].mask |
+                    ctrl_reg_info[i].data;  i++) {
+
+               ret = mxl111sf_write_reg_mask(state,
+                                             ctrl_reg_info[i].addr,
+                                             ctrl_reg_info[i].mask,
+                                             ctrl_reg_info[i].data);
+               if (mxl_fail(ret)) {
+                       err("failed on reg #%d (0x%02x)", i,
+                           ctrl_reg_info[i].addr);
+                       break;
+               }
+       }
+       return ret;
+}
+
+/* ------------------------------------------------------------------------ */
+
+static int mxl1x1sf_get_chip_info(struct mxl111sf_state *state)
+{
+       int ret;
+       u8 id, ver;
+       char *mxl_chip, *mxl_rev;
+
+       if ((state->chip_id) && (state->chip_ver))
+               return 0;
+
+       ret = mxl111sf_read_reg(state, CHIP_ID_REG, &id);
+       if (mxl_fail(ret))
+               goto fail;
+       state->chip_id = id;
+
+       ret = mxl111sf_read_reg(state, TOP_CHIP_REV_ID_REG, &ver);
+       if (mxl_fail(ret))
+               goto fail;
+       state->chip_ver = ver;
+
+       switch (id) {
+       case 0x61:
+               mxl_chip = "MxL101SF";
+               break;
+       case 0x63:
+               mxl_chip = "MxL111SF";
+               break;
+       default:
+               mxl_chip = "UNKNOWN MxL1X1";
+               break;
+       }
+       switch (ver) {
+       case 0x36:
+               state->chip_rev = MXL111SF_V6;
+               mxl_rev = "v6";
+               break;
+       case 0x08:
+               state->chip_rev = MXL111SF_V8_100;
+               mxl_rev = "v8_100";
+               break;
+       case 0x18:
+               state->chip_rev = MXL111SF_V8_200;
+               mxl_rev = "v8_200";
+               break;
+       default:
+               state->chip_rev = 0;
+               mxl_rev = "UNKNOWN REVISION";
+               break;
+       }
+       info("%s detected, %s (0x%x)", mxl_chip, mxl_rev, ver);
+fail:
+       return ret;
+}
+
+#define get_chip_info(state)                                           \
+({                                                                     \
+       int ___ret;                                                     \
+       ___ret = mxl1x1sf_get_chip_info(state);                         \
+       if (mxl_fail(___ret)) {                                         \
+               mxl_debug("failed to get chip info"                     \
+                         " on first probe attempt");                   \
+               ___ret = mxl1x1sf_get_chip_info(state);                 \
+               if (mxl_fail(___ret))                                   \
+                       err("failed to get chip info during probe");    \
+               else                                                    \
+                       mxl_debug("probe needed a retry "               \
+                                 "in order to succeed.");              \
+       }                                                               \
+       ___ret;                                                         \
+})
+
+/* ------------------------------------------------------------------------ */
+
+static int mxl111sf_power_ctrl(struct dvb_usb_device *d, int onoff)
+{
+       /* power control depends on which adapter is being woken:
+        * save this for init, instead, via mxl111sf_adap_fe_init */
+       return 0;
+}
+
+static int mxl111sf_adap_fe_init(struct dvb_frontend *fe)
+{
+       struct dvb_usb_adapter *adap = fe->dvb->priv;
+       struct dvb_usb_device *d = adap->dev;
+       struct mxl111sf_state *state = d->priv;
+       struct mxl111sf_adap_state *adap_state = adap->fe_adap[fe->id].priv;
+
+       int err;
+
+       /* exit if we didnt initialize the driver yet */
+       if (!state->chip_id) {
+               mxl_debug("driver not yet initialized, exit.");
+               goto fail;
+       }
+
+       deb_info("%s()\n", __func__);
+
+       mutex_lock(&state->fe_lock);
+
+       state->alt_mode = adap_state->alt_mode;
+
+       if (usb_set_interface(adap->dev->udev, 0, state->alt_mode) < 0)
+               err("set interface failed");
+
+       err = mxl1x1sf_soft_reset(state);
+       mxl_fail(err);
+       err = mxl111sf_init_tuner_demod(state);
+       mxl_fail(err);
+       err = mxl1x1sf_set_device_mode(state, adap_state->device_mode);
+
+       mxl_fail(err);
+       mxl111sf_enable_usb_output(state);
+       mxl_fail(err);
+       mxl1x1sf_top_master_ctrl(state, 1);
+       mxl_fail(err);
+
+       if ((MXL111SF_GPIO_MOD_DVBT != adap_state->gpio_mode) &&
+           (state->chip_rev > MXL111SF_V6)) {
+               mxl111sf_config_pin_mux_modes(state,
+                                             PIN_MUX_TS_SPI_IN_MODE_1);
+               mxl_fail(err);
+       }
+       err = mxl111sf_init_port_expander(state);
+       if (!mxl_fail(err)) {
+               state->gpio_mode = adap_state->gpio_mode;
+               err = mxl111sf_gpio_mode_switch(state, state->gpio_mode);
+               mxl_fail(err);
+#if 0
+               err = fe->ops.init(fe);
+#endif
+               msleep(100); /* add short delay after enabling
+                             * the demod before touching it */
+       }
+
+       return (adap_state->fe_init) ? adap_state->fe_init(fe) : 0;
+fail:
+       return -ENODEV;
+}
+
+static int mxl111sf_adap_fe_sleep(struct dvb_frontend *fe)
+{
+       struct dvb_usb_adapter *adap = fe->dvb->priv;
+       struct dvb_usb_device *d = adap->dev;
+       struct mxl111sf_state *state = d->priv;
+       struct mxl111sf_adap_state *adap_state = adap->fe_adap[fe->id].priv;
+       int err;
+
+       /* exit if we didnt initialize the driver yet */
+       if (!state->chip_id) {
+               mxl_debug("driver not yet initialized, exit.");
+               goto fail;
+       }
+
+       deb_info("%s()\n", __func__);
+
+       err = (adap_state->fe_sleep) ? adap_state->fe_sleep(fe) : 0;
+
+       mutex_unlock(&state->fe_lock);
+
+       return err;
+fail:
+       return -ENODEV;
+}
+
+
+static int mxl111sf_ep6_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
+{
+       struct dvb_usb_device *d = adap->dev;
+       struct mxl111sf_state *state = d->priv;
+       struct mxl111sf_adap_state *adap_state = adap->fe_adap[adap->active_fe].priv;
+       int ret = 0;
+       u8 tmp;
+
+       deb_info("%s(%d)\n", __func__, onoff);
+
+       if (onoff) {
+               ret = mxl111sf_enable_usb_output(state);
+               mxl_fail(ret);
+               ret = mxl111sf_config_mpeg_in(state, 1, 1,
+                                             adap_state->ep6_clockphase,
+                                             0, 0);
+               mxl_fail(ret);
+       } else {
+               ret = mxl111sf_disable_656_port(state);
+               mxl_fail(ret);
+       }
+
+       mxl111sf_read_reg(state, 0x12, &tmp);
+       tmp &= ~0x04;
+       mxl111sf_write_reg(state, 0x12, tmp);
+
+       return ret;
+}
+
+/* ------------------------------------------------------------------------ */
+
+static struct lgdt3305_config hauppauge_lgdt3305_config = {
+       .i2c_addr           = 0xb2 >> 1,
+       .mpeg_mode          = LGDT3305_MPEG_SERIAL,
+       .tpclk_edge         = LGDT3305_TPCLK_RISING_EDGE,
+       .tpvalid_polarity   = LGDT3305_TP_VALID_HIGH,
+       .deny_i2c_rptr      = 1,
+       .spectral_inversion = 0,
+       .qam_if_khz         = 6000,
+       .vsb_if_khz         = 6000,
+};
+
+static int mxl111sf_lgdt3305_frontend_attach(struct dvb_usb_adapter *adap)
+{
+       struct dvb_usb_device *d = adap->dev;
+       struct mxl111sf_state *state = d->priv;
+       int fe_id = adap->num_frontends_initialized;
+       struct mxl111sf_adap_state *adap_state = adap->fe_adap[fe_id].priv;
+       int ret;
+
+       deb_adv("%s()\n", __func__);
+
+       /* save a pointer to the dvb_usb_device in device state */
+       state->d = d;
+       adap_state->alt_mode = (dvb_usb_mxl111sf_isoc) ? 2 : 1;
+       state->alt_mode = adap_state->alt_mode;
+
+       if (usb_set_interface(adap->dev->udev, 0, state->alt_mode) < 0)
+               err("set interface failed");
+
+       state->gpio_mode = MXL111SF_GPIO_MOD_ATSC;
+       adap_state->gpio_mode = state->gpio_mode;
+       adap_state->device_mode = MXL_TUNER_MODE;
+       adap_state->ep6_clockphase = 1;
+
+       ret = mxl1x1sf_soft_reset(state);
+       if (mxl_fail(ret))
+               goto fail;
+       ret = mxl111sf_init_tuner_demod(state);
+       if (mxl_fail(ret))
+               goto fail;
+
+       ret = mxl1x1sf_set_device_mode(state, adap_state->device_mode);
+       if (mxl_fail(ret))
+               goto fail;
+
+       ret = mxl111sf_enable_usb_output(state);
+       if (mxl_fail(ret))
+               goto fail;
+       ret = mxl1x1sf_top_master_ctrl(state, 1);
+       if (mxl_fail(ret))
+               goto fail;
+
+       ret = mxl111sf_init_port_expander(state);
+       if (mxl_fail(ret))
+               goto fail;
+       ret = mxl111sf_gpio_mode_switch(state, state->gpio_mode);
+       if (mxl_fail(ret))
+               goto fail;
+
+       adap->fe_adap[fe_id].fe = dvb_attach(lgdt3305_attach,
+                                &hauppauge_lgdt3305_config,
+                                &adap->dev->i2c_adap);
+       if (adap->fe_adap[fe_id].fe) {
+               adap_state->fe_init = adap->fe_adap[fe_id].fe->ops.init;
+               adap->fe_adap[fe_id].fe->ops.init = mxl111sf_adap_fe_init;
+               adap_state->fe_sleep = adap->fe_adap[fe_id].fe->ops.sleep;
+               adap->fe_adap[fe_id].fe->ops.sleep = mxl111sf_adap_fe_sleep;
+               return 0;
+       }
+       ret = -EIO;
+fail:
+       return ret;
+}
+
+static inline int mxl111sf_set_ant_path(struct mxl111sf_state *state,
+                                       int antpath)
+{
+       return mxl111sf_idac_config(state, 1, 1,
+                                   (antpath == ANT_PATH_INTERNAL) ?
+                                   0x3f : 0x00, 0);
+}
+
+#define DbgAntHunt(x, pwr0, pwr1, pwr2, pwr3) \
+       err("%s(%d) FINAL input set to %s rxPwr:%d|%d|%d|%d\n", \
+           __func__, __LINE__, \
+           (ANT_PATH_EXTERNAL == x) ? "EXTERNAL" : "INTERNAL", \
+           pwr0, pwr1, pwr2, pwr3)
+
+#define ANT_HUNT_SLEEP 90
+#define ANT_EXT_TWEAK 0
+
+static int mxl111sf_ant_hunt(struct dvb_frontend *fe)
+{
+       struct dvb_usb_adapter *adap = fe->dvb->priv;
+       struct dvb_usb_device *d = adap->dev;
+       struct mxl111sf_state *state = d->priv;
+
+       int antctrl = dvb_usb_mxl111sf_rfswitch;
+
+       u16 rxPwrA, rxPwr0, rxPwr1, rxPwr2;
+
+       /* FIXME: must force EXTERNAL for QAM - done elsewhere */
+       mxl111sf_set_ant_path(state, antctrl == ANT_PATH_AUTO ?
+                             ANT_PATH_EXTERNAL : antctrl);
+
+       if (antctrl == ANT_PATH_AUTO) {
+#if 0
+               msleep(ANT_HUNT_SLEEP);
+#endif
+               fe->ops.tuner_ops.get_rf_strength(fe, &rxPwrA);
+
+               mxl111sf_set_ant_path(state, ANT_PATH_EXTERNAL);
+               msleep(ANT_HUNT_SLEEP);
+               fe->ops.tuner_ops.get_rf_strength(fe, &rxPwr0);
+
+               mxl111sf_set_ant_path(state, ANT_PATH_EXTERNAL);
+               msleep(ANT_HUNT_SLEEP);
+               fe->ops.tuner_ops.get_rf_strength(fe, &rxPwr1);
+
+               mxl111sf_set_ant_path(state, ANT_PATH_INTERNAL);
+               msleep(ANT_HUNT_SLEEP);
+               fe->ops.tuner_ops.get_rf_strength(fe, &rxPwr2);
+
+               if (rxPwr1+ANT_EXT_TWEAK >= rxPwr2) {
+                       /* return with EXTERNAL enabled */
+                       mxl111sf_set_ant_path(state, ANT_PATH_EXTERNAL);
+                       DbgAntHunt(ANT_PATH_EXTERNAL, rxPwrA,
+                                  rxPwr0, rxPwr1, rxPwr2);
+               } else {
+                       /* return with INTERNAL enabled */
+                       DbgAntHunt(ANT_PATH_INTERNAL, rxPwrA,
+                                  rxPwr0, rxPwr1, rxPwr2);
+               }
+       }
+       return 0;
+}
+
+static struct mxl111sf_tuner_config mxl_tuner_config = {
+       .if_freq         = MXL_IF_6_0, /* applies to external IF output, only */
+       .invert_spectrum = 0,
+       .read_reg        = mxl111sf_read_reg,
+       .write_reg       = mxl111sf_write_reg,
+       .program_regs    = mxl111sf_ctrl_program_regs,
+       .top_master_ctrl = mxl1x1sf_top_master_ctrl,
+       .ant_hunt        = mxl111sf_ant_hunt,
+};
+
+static int mxl111sf_attach_tuner(struct dvb_usb_adapter *adap)
+{
+       struct dvb_usb_device *d = adap->dev;
+       struct mxl111sf_state *state = d->priv;
+       int fe_id = adap->num_frontends_initialized;
+
+       deb_adv("%s()\n", __func__);
+
+       if (NULL != dvb_attach(mxl111sf_tuner_attach,
+                              adap->fe_adap[fe_id].fe, state,
+                              &mxl_tuner_config))
+               return 0;
+
+       return -EIO;
+}
+
+static int mxl111sf_fe_ioctl_override(struct dvb_frontend *fe,
+                                     unsigned int cmd, void *parg,
+                                     unsigned int stage)
+{
+       int err = 0;
+
+       switch (stage) {
+       case DVB_FE_IOCTL_PRE:
+
+               switch (cmd) {
+               case FE_READ_SIGNAL_STRENGTH:
+                       err = fe->ops.tuner_ops.get_rf_strength(fe, parg);
+                       /* If no error occurs, prevent dvb-core from handling
+                        * this IOCTL, otherwise return the error */
+                       if (0 == err)
+                               err = 1;
+                       break;
+               }
+               break;
+
+       case DVB_FE_IOCTL_POST:
+               /* no post-ioctl handling required */
+               break;
+       }
+       return err;
+};
+
+static u32 mxl111sf_i2c_func(struct i2c_adapter *adapter)
+{
+       return I2C_FUNC_I2C;
+}
+
+struct i2c_algorithm mxl111sf_i2c_algo = {
+       .master_xfer   = mxl111sf_i2c_xfer,
+       .functionality = mxl111sf_i2c_func,
+#ifdef NEED_ALGO_CONTROL
+       .algo_control = dummy_algo_control,
+#endif
+};
+
+/* DVB USB Driver stuff */
+static struct dvb_usb_device_properties mxl111sf_atsc_bulk_properties;
+static struct dvb_usb_device_properties mxl111sf_atsc_isoc_properties;
+
+static int mxl111sf_probe(struct usb_interface *intf,
+                         const struct usb_device_id *id)
+{
+       struct dvb_usb_device *d = NULL;
+
+       deb_adv("%s()\n", __func__);
+
+       if (((dvb_usb_mxl111sf_isoc) &&
+            (0 == dvb_usb_device_init(intf,
+                                      &mxl111sf_atsc_isoc_properties,
+                                      THIS_MODULE, &d, adapter_nr))) ||
+           0 == dvb_usb_device_init(intf,
+                                    &mxl111sf_atsc_bulk_properties,
+                                    THIS_MODULE, &d, adapter_nr) || 0) {
+
+               struct mxl111sf_state *state = d->priv;
+               static u8 eeprom[256];
+               struct i2c_client c;
+               int ret;
+
+               ret = get_chip_info(state);
+               if (mxl_fail(ret))
+                       err("failed to get chip info during probe");
+
+               mutex_init(&state->fe_lock);
+
+               if (state->chip_rev > MXL111SF_V6)
+                       mxl111sf_config_pin_mux_modes(state,
+                                                     PIN_MUX_TS_SPI_IN_MODE_1);
+
+               c.adapter = &d->i2c_adap;
+               c.addr = 0xa0 >> 1;
+
+               ret = tveeprom_read(&c, eeprom, sizeof(eeprom));
+               if (mxl_fail(ret))
+                       return 0;
+               tveeprom_hauppauge_analog(&c, &state->tv,
+                                         (0x84 == eeprom[0xa0]) ?
+                                         eeprom + 0xa0 : eeprom + 0x80);
+#if 0
+               switch (state->tv.model) {
+               case 117001:
+               case 126001:
+               case 138001:
+                       break;
+               default:
+                       printk(KERN_WARNING "%s: warning: "
+                              "unknown hauppauge model #%d\n",
+                              __func__, state->tv.model);
+               }
+#endif
+               return 0;
+       }
+       err("Your device is not yet supported by this driver. "
+           "See kernellabs.com for more info");
+       return -EINVAL;
+}
+
+static struct usb_device_id mxl111sf_table[] = {
+/* 0 */        { USB_DEVICE(USB_VID_HAUPPAUGE, 0xc600) }, /* ATSC+ IR     */
+       { USB_DEVICE(USB_VID_HAUPPAUGE, 0xc601) }, /* ATSC         */
+       { USB_DEVICE(USB_VID_HAUPPAUGE, 0xc602) }, /*     +        */
+       { USB_DEVICE(USB_VID_HAUPPAUGE, 0xc603) }, /* ATSC+        */
+       { USB_DEVICE(USB_VID_HAUPPAUGE, 0xc604) }, /* DVBT         */
+/* 5 */        { USB_DEVICE(USB_VID_HAUPPAUGE, 0xc609) }, /* ATSC  IR     */
+       { USB_DEVICE(USB_VID_HAUPPAUGE, 0xc60a) }, /*     + IR     */
+       { USB_DEVICE(USB_VID_HAUPPAUGE, 0xc60b) }, /* ATSC+ IR     */
+       { USB_DEVICE(USB_VID_HAUPPAUGE, 0xc60c) }, /* DVBT  IR     */
+       { USB_DEVICE(USB_VID_HAUPPAUGE, 0xc653) }, /* ATSC+        */
+/*10 */        { USB_DEVICE(USB_VID_HAUPPAUGE, 0xc65b) }, /* ATSC+ IR     */
+       { USB_DEVICE(USB_VID_HAUPPAUGE, 0xb700) }, /* ATSC+ sw     */
+       { USB_DEVICE(USB_VID_HAUPPAUGE, 0xb701) }, /* ATSC  sw     */
+       { USB_DEVICE(USB_VID_HAUPPAUGE, 0xb702) }, /*     + sw     */
+       { USB_DEVICE(USB_VID_HAUPPAUGE, 0xb703) }, /* ATSC+ sw     */
+/*15 */        { USB_DEVICE(USB_VID_HAUPPAUGE, 0xb704) }, /* DVBT  sw     */
+       { USB_DEVICE(USB_VID_HAUPPAUGE, 0xb753) }, /* ATSC+ sw     */
+       { USB_DEVICE(USB_VID_HAUPPAUGE, 0xb763) }, /* ATSC+ no     */
+       { USB_DEVICE(USB_VID_HAUPPAUGE, 0xb764) }, /* DVBT  no     */
+       { USB_DEVICE(USB_VID_HAUPPAUGE, 0xd853) }, /* ATSC+ sw     */
+/*20 */        { USB_DEVICE(USB_VID_HAUPPAUGE, 0xd854) }, /* DVBT  sw     */
+       { USB_DEVICE(USB_VID_HAUPPAUGE, 0xd863) }, /* ATSC+ no     */
+       { USB_DEVICE(USB_VID_HAUPPAUGE, 0xd864) }, /* DVBT  no     */
+       { USB_DEVICE(USB_VID_HAUPPAUGE, 0xd8d3) }, /* ATSC+ sw     */
+       { USB_DEVICE(USB_VID_HAUPPAUGE, 0xd8d4) }, /* DVBT  sw     */
+/*25 */        { USB_DEVICE(USB_VID_HAUPPAUGE, 0xd8e3) }, /* ATSC+ no     */
+       { USB_DEVICE(USB_VID_HAUPPAUGE, 0xd8e4) }, /* DVBT  no     */
+       { USB_DEVICE(USB_VID_HAUPPAUGE, 0xd8ff) }, /* ATSC+        */
+       { USB_DEVICE(USB_VID_HAUPPAUGE, 0xc612) }, /*     +        */
+       { USB_DEVICE(USB_VID_HAUPPAUGE, 0xc613) }, /* ATSC+        */
+/*30 */        { USB_DEVICE(USB_VID_HAUPPAUGE, 0xc61a) }, /*     + IR     */
+       { USB_DEVICE(USB_VID_HAUPPAUGE, 0xc61b) }, /* ATSC+ IR     */
+       { USB_DEVICE(USB_VID_HAUPPAUGE, 0xb757) }, /* ATSC+DVBT sw */
+       { USB_DEVICE(USB_VID_HAUPPAUGE, 0xb767) }, /* ATSC+DVBT no */
+       {}              /* Terminating entry */
+};
+MODULE_DEVICE_TABLE(usb, mxl111sf_table);
+
+
+#define MXL111SF_EP6_BULK_STREAMING_CONFIG             \
+       .streaming_ctrl = mxl111sf_ep6_streaming_ctrl,  \
+       .stream = {                                     \
+               .type = USB_BULK,                       \
+               .count = 5,                             \
+               .endpoint = 0x06,                       \
+               .u = {                                  \
+                       .bulk = {                       \
+                               .buffersize = 8192,     \
+                       }                               \
+               }                                       \
+       }
+
+/* FIXME */
+#define MXL111SF_EP6_ISOC_STREAMING_CONFIG             \
+       .streaming_ctrl = mxl111sf_ep6_streaming_ctrl,  \
+       .stream = {                                     \
+               .type = USB_ISOC,                       \
+               .count = 5,                             \
+               .endpoint = 0x06,                       \
+               .u = {                                  \
+                       .isoc = {                       \
+                               .framesperurb = 24,     \
+                               .framesize = 3072,      \
+                               .interval = 1,          \
+                       }                               \
+               }                                       \
+       }
+
+#define MXL111SF_DEFAULT_DEVICE_PROPERTIES                     \
+       .caps = DVB_USB_IS_AN_I2C_ADAPTER,                      \
+       .usb_ctrl = DEVICE_SPECIFIC,                            \
+       /* use usb alt setting 1 for EP4 ISOC transfer (dvb-t), \
+                                    EP6 BULK transfer (atsc/qam), \
+          use usb alt setting 2 for EP4 BULK transfer (dvb-t), \
+                                    EP6 ISOC transfer (atsc/qam), \
+       */                                                      \
+       .power_ctrl       = mxl111sf_power_ctrl,                \
+       .i2c_algo         = &mxl111sf_i2c_algo,                 \
+       .generic_bulk_ctrl_endpoint          = MXL_EP2_REG_WRITE, \
+       .generic_bulk_ctrl_endpoint_response = MXL_EP1_REG_READ, \
+       .size_of_priv     = sizeof(struct mxl111sf_state)
+
+static struct dvb_usb_device_properties mxl111sf_atsc_bulk_properties = {
+       MXL111SF_DEFAULT_DEVICE_PROPERTIES,
+
+       .num_adapters = 1,
+       .adapter = {
+               {
+               .fe_ioctl_override = mxl111sf_fe_ioctl_override,
+               .num_frontends = 1,
+               .fe = {{
+                       .size_of_priv     = sizeof(struct mxl111sf_adap_state),
+
+                       .frontend_attach  = mxl111sf_lgdt3305_frontend_attach,
+                       .tuner_attach     = mxl111sf_attach_tuner,
+
+                       MXL111SF_EP6_BULK_STREAMING_CONFIG,
+               }},
+               },
+       },
+       .num_device_descs = 6,
+       .devices = {
+               {   "Hauppauge 126xxx ATSC (bulk)",
+                       { NULL },
+                       { &mxl111sf_table[1], &mxl111sf_table[5],
+                         NULL },
+               },
+               {   "Hauppauge 117xxx ATSC (bulk)",
+                       { NULL },
+                       { &mxl111sf_table[12],
+                         NULL },
+               },
+               {   "Hauppauge 126xxx ATSC+ (bulk)",
+                       { NULL },
+                       { &mxl111sf_table[0], &mxl111sf_table[3],
+                         &mxl111sf_table[7], &mxl111sf_table[9],
+                         &mxl111sf_table[10], NULL },
+               },
+               {   "Hauppauge 117xxx ATSC+ (bulk)",
+                       { NULL },
+                       { &mxl111sf_table[11], &mxl111sf_table[14],
+                         &mxl111sf_table[16], &mxl111sf_table[17],
+                         &mxl111sf_table[32], &mxl111sf_table[33],
+                         NULL },
+               },
+               {   "Hauppauge Mercury (tp-bulk)",
+                       { NULL },
+                       { &mxl111sf_table[19], &mxl111sf_table[21],
+                         &mxl111sf_table[23], &mxl111sf_table[25],
+                         &mxl111sf_table[27], NULL },
+               },
+               {   "Hauppauge WinTV-Aero-M",
+                       { NULL },
+                       { &mxl111sf_table[29], &mxl111sf_table[31],
+                         NULL },
+               },
+       }
+};
+
+static struct dvb_usb_device_properties mxl111sf_atsc_isoc_properties = {
+       MXL111SF_DEFAULT_DEVICE_PROPERTIES,
+
+       .num_adapters = 1,
+       .adapter = {
+               {
+               .fe_ioctl_override = mxl111sf_fe_ioctl_override,
+               .num_frontends = 1,
+               .fe = {{
+                       .size_of_priv     = sizeof(struct mxl111sf_adap_state),
+
+                       .frontend_attach  = mxl111sf_lgdt3305_frontend_attach,
+                       .tuner_attach     = mxl111sf_attach_tuner,
+
+                       MXL111SF_EP6_ISOC_STREAMING_CONFIG,
+               }},
+               },
+       },
+       .num_device_descs = 6,
+       .devices = {
+               {   "Hauppauge 126xxx ATSC (isoc)",
+                       { NULL },
+                       { &mxl111sf_table[1], &mxl111sf_table[5],
+                         NULL },
+               },
+               {   "Hauppauge 117xxx ATSC (isoc)",
+                       { NULL },
+                       { &mxl111sf_table[12],
+                         NULL },
+               },
+               {   "Hauppauge 126xxx ATSC+ (isoc)",
+                       { NULL },
+                       { &mxl111sf_table[0], &mxl111sf_table[3],
+                         &mxl111sf_table[7], &mxl111sf_table[9],
+                         &mxl111sf_table[10], NULL },
+               },
+               {   "Hauppauge 117xxx ATSC+ (isoc)",
+                       { NULL },
+                       { &mxl111sf_table[11], &mxl111sf_table[14],
+                         &mxl111sf_table[16], &mxl111sf_table[17],
+                         &mxl111sf_table[32], &mxl111sf_table[33],
+                         NULL },
+               },
+               {   "Hauppauge Mercury (tp-isoc)",
+                       { NULL },
+                       { &mxl111sf_table[19], &mxl111sf_table[21],
+                         &mxl111sf_table[23], &mxl111sf_table[25],
+                         &mxl111sf_table[27], NULL },
+               },
+               {   "Hauppauge WinTV-Aero-M (tp-isoc)",
+                       { NULL },
+                       { &mxl111sf_table[29], &mxl111sf_table[31],
+                         NULL },
+               },
+       }
+};
+
+static struct usb_driver mxl111sf_driver = {
+       .name           = "dvb_usb_mxl111sf",
+       .probe          = mxl111sf_probe,
+       .disconnect     = dvb_usb_device_exit,
+       .id_table       = mxl111sf_table,
+};
+
+static int __init mxl111sf_module_init(void)
+{
+       int result = usb_register(&mxl111sf_driver);
+       if (result) {
+               err("usb_register failed. Error number %d", result);
+               return result;
+       }
+
+       return 0;
+}
+
+static void __exit mxl111sf_module_exit(void)
+{
+       usb_deregister(&mxl111sf_driver);
+}
+
+module_init(mxl111sf_module_init);
+module_exit(mxl111sf_module_exit);
+
+MODULE_AUTHOR("Michael Krufky <mkrufky@kernellabs.com>");
+MODULE_DESCRIPTION("Driver for MaxLinear MxL111SF");
+MODULE_VERSION("1.0");
+MODULE_LICENSE("GPL");
+
+/*
+ * Local variables:
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/drivers/media/dvb/dvb-usb/mxl111sf.h b/drivers/media/dvb/dvb-usb/mxl111sf.h
new file mode 100644 (file)
index 0000000..5a2c7bb
--- /dev/null
@@ -0,0 +1,158 @@
+/*
+ * Copyright (C) 2010 Michael Krufky (mkrufky@kernellabs.com)
+ *
+ *   This program is free software; you can redistribute it and/or modify it
+ *   under the terms of the GNU General Public License as published by the Free
+ *   Software Foundation, version 2.
+ *
+ * see Documentation/dvb/README.dvb-usb for more information
+ */
+
+#ifndef _DVB_USB_MXL111SF_H_
+#define _DVB_USB_MXL111SF_H_
+
+#ifdef DVB_USB_LOG_PREFIX
+#undef DVB_USB_LOG_PREFIX
+#endif
+#define DVB_USB_LOG_PREFIX "mxl111sf"
+#include "dvb-usb.h"
+#include <media/tveeprom.h>
+
+#define MXL_EP1_REG_READ     1
+#define MXL_EP2_REG_WRITE    2
+#define MXL_EP3_INTERRUPT    3
+#define MXL_EP4_MPEG2        4
+#define MXL_EP5_I2S          5
+#define MXL_EP6_656          6
+#define MXL_EP6_MPEG2        6
+
+#ifdef USING_ENUM_mxl111sf_current_mode
+enum mxl111sf_current_mode {
+       mxl_mode_dvbt = MXL_EP4_MPEG2,
+       mxl_mode_mh   = MXL_EP5_I2S,
+       mxl_mode_atsc = MXL_EP6_MPEG2,
+};
+#endif
+
+enum mxl111sf_gpio_port_expander {
+       mxl111sf_gpio_hw,
+       mxl111sf_PCA9534,
+};
+
+struct mxl111sf_state {
+       struct dvb_usb_device *d;
+
+       enum mxl111sf_gpio_port_expander gpio_port_expander;
+       u8 port_expander_addr;
+
+       u8 chip_id;
+       u8 chip_ver;
+#define MXL111SF_V6     1
+#define MXL111SF_V8_100 2
+#define MXL111SF_V8_200 3
+       u8 chip_rev;
+
+#ifdef USING_ENUM_mxl111sf_current_mode
+       enum mxl111sf_current_mode current_mode;
+#endif
+
+#define MXL_TUNER_MODE         0
+#define MXL_SOC_MODE           1
+#define MXL_DEV_MODE_MASK      0x01
+#if 1
+       int device_mode;
+#endif
+       /* use usb alt setting 1 for EP4 ISOC transfer (dvb-t),
+                                    EP5 BULK transfer (atsc-mh),
+                                    EP6 BULK transfer (atsc/qam),
+          use usb alt setting 2 for EP4 BULK transfer (dvb-t),
+                                    EP5 ISOC transfer (atsc-mh),
+                                    EP6 ISOC transfer (atsc/qam),
+        */
+       int alt_mode;
+       int gpio_mode;
+       struct tveeprom tv;
+
+       struct mutex fe_lock;
+};
+
+struct mxl111sf_adap_state {
+       int alt_mode;
+       int gpio_mode;
+       int device_mode;
+       int ep6_clockphase;
+       int (*fe_init)(struct dvb_frontend *);
+       int (*fe_sleep)(struct dvb_frontend *);
+};
+
+int mxl111sf_read_reg(struct mxl111sf_state *state, u8 addr, u8 *data);
+int mxl111sf_write_reg(struct mxl111sf_state *state, u8 addr, u8 data);
+
+struct mxl111sf_reg_ctrl_info {
+       u8 addr;
+       u8 mask;
+       u8 data;
+};
+
+int mxl111sf_write_reg_mask(struct mxl111sf_state *state,
+                           u8 addr, u8 mask, u8 data);
+int mxl111sf_ctrl_program_regs(struct mxl111sf_state *state,
+                              struct mxl111sf_reg_ctrl_info *ctrl_reg_info);
+
+/* needed for hardware i2c functions in mxl111sf-i2c.c:
+ * mxl111sf_i2c_send_data / mxl111sf_i2c_get_data */
+int mxl111sf_ctrl_msg(struct dvb_usb_device *d,
+                     u8 cmd, u8 *wbuf, int wlen, u8 *rbuf, int rlen);
+
+#define mxl_printk(kern, fmt, arg...) \
+       printk(kern "%s: " fmt "\n", __func__, ##arg)
+
+#define mxl_info(fmt, arg...) \
+       mxl_printk(KERN_INFO, fmt, ##arg)
+
+extern int dvb_usb_mxl111sf_debug;
+#define mxl_debug(fmt, arg...) \
+       if (dvb_usb_mxl111sf_debug) \
+               mxl_printk(KERN_DEBUG, fmt, ##arg)
+
+#define MXL_I2C_DBG 0x04
+#define MXL_ADV_DBG 0x10
+#define mxl_debug_adv(fmt, arg...) \
+       if (dvb_usb_mxl111sf_debug & MXL_ADV_DBG) \
+               mxl_printk(KERN_DEBUG, fmt, ##arg)
+
+#define mxl_i2c(fmt, arg...) \
+       if (dvb_usb_mxl111sf_debug & MXL_I2C_DBG) \
+               mxl_printk(KERN_DEBUG, fmt, ##arg)
+
+#define mxl_i2c_adv(fmt, arg...) \
+       if ((dvb_usb_mxl111sf_debug & (MXL_I2C_DBG | MXL_ADV_DBG)) == \
+               (MXL_I2C_DBG | MXL_ADV_DBG)) \
+                       mxl_printk(KERN_DEBUG, fmt, ##arg)
+
+/* The following allows the mxl_fail() macro defined below to work
+ * in externel modules, such as mxl111sf-tuner.ko, even though
+ * dvb_usb_mxl111sf_debug is not defined within those modules */
+#ifdef __MXL111SF_TUNER_H__
+#define MXL_ADV_DEBUG_ENABLED MXL_ADV_DBG
+#else
+#define MXL_ADV_DEBUG_ENABLED dvb_usb_mxl111sf_debug
+#endif
+
+#define mxl_fail(ret)                                                  \
+({                                                                     \
+       int __ret;                                                      \
+       __ret = (ret < 0);                                              \
+       if ((__ret) && (MXL_ADV_DEBUG_ENABLED & MXL_ADV_DBG))           \
+               mxl_printk(KERN_ERR, "error %d on line %d",             \
+                          ret, __LINE__);                              \
+       __ret;                                                          \
+})
+
+#endif /* _DVB_USB_MXL111SF_H_ */
+
+/*
+ * Local variables:
+ * c-basic-offset: 8
+ * End:
+ */
index bc350e982b72072a0e213af31d091c8da4cfb34d..21384da6570eedd36b3a5cc040c89ac1eea20e16 100644 (file)
@@ -166,6 +166,8 @@ static struct dvb_usb_device_properties nova_t_properties = {
        .num_adapters     = 1,
        .adapter          = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
                        .pid_filter_count = 32,
 
@@ -186,7 +188,7 @@ static struct dvb_usb_device_properties nova_t_properties = {
                                        }
                                }
                        },
-
+               }},
                        .size_of_priv     = sizeof(struct dibusb_state),
                }
        },
index 2e4fab7215f513d24993e54edc87ff785f6e31d3..98fd9a6092b7e68aa343b326a65141fa8d741717 100644 (file)
@@ -263,10 +263,10 @@ static struct stv0299_config opera1_stv0299_config = {
 
 static int opera1_frontend_attach(struct dvb_usb_adapter *d)
 {
-       if ((d->fe =
-            dvb_attach(stv0299_attach, &opera1_stv0299_config,
-                       &d->dev->i2c_adap)) != NULL) {
-               d->fe->ops.set_voltage = opera1_set_voltage;
+       d->fe_adap[0].fe = dvb_attach(stv0299_attach, &opera1_stv0299_config,
+                                     &d->dev->i2c_adap);
+       if ((d->fe_adap[0].fe) != NULL) {
+               d->fe_adap[0].fe->ops.set_voltage = opera1_set_voltage;
                return 0;
        }
        info("not attached stv0299");
@@ -276,7 +276,7 @@ static int opera1_frontend_attach(struct dvb_usb_adapter *d)
 static int opera1_tuner_attach(struct dvb_usb_adapter *adap)
 {
        dvb_attach(
-               dvb_pll_attach, adap->fe, 0xc0>>1,
+               dvb_pll_attach, adap->fe_adap[0].fe, 0xc0>>1,
                &adap->dev->i2c_adap, DVB_PLL_OPERA1
        );
        return 0;
@@ -516,6 +516,8 @@ static struct dvb_usb_device_properties opera1_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .frontend_attach = opera1_frontend_attach,
                        .streaming_ctrl = opera1_streaming_ctrl,
                        .tuner_attach = opera1_tuner_attach,
@@ -535,6 +537,7 @@ static struct dvb_usb_device_properties opera1_properties = {
                                        }
                                }
                        },
+               }},
                }
        },
        .num_device_descs = 1,
diff --git a/drivers/media/dvb/dvb-usb/pctv452e.c b/drivers/media/dvb/dvb-usb/pctv452e.c
new file mode 100644 (file)
index 0000000..f9aec5c
--- /dev/null
@@ -0,0 +1,1079 @@
+/*
+ * PCTV 452e DVB driver
+ *
+ * Copyright (c) 2006-2008 Dominik Kuhlen <dkuhlen@gmx.net>
+ *
+ * TT connect S2-3650-CI Common Interface support, MAC readout
+ * Copyright (C) 2008 Michael H. Schimek <mschimek@gmx.at>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ */
+
+/* dvb usb framework */
+#define DVB_USB_LOG_PREFIX "pctv452e"
+#include "dvb-usb.h"
+
+/* Demodulator */
+#include "stb0899_drv.h"
+#include "stb0899_reg.h"
+#include "stb0899_cfg.h"
+/* Tuner */
+#include "stb6100.h"
+#include "stb6100_cfg.h"
+/* FE Power */
+#include "lnbp22.h"
+
+#include "dvb_ca_en50221.h"
+#include "ttpci-eeprom.h"
+
+static int debug;
+module_param(debug, int, 0644);
+MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
+
+DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
+
+#define ISOC_INTERFACE_ALTERNATIVE 3
+
+#define SYNC_BYTE_OUT 0xaa
+#define SYNC_BYTE_IN  0x55
+
+/* guessed: (copied from ttusb-budget) */
+#define PCTV_CMD_RESET 0x15
+/* command to poll IR receiver */
+#define PCTV_CMD_IR    0x1b
+/* command to send I2C  */
+#define PCTV_CMD_I2C   0x31
+
+#define I2C_ADDR_STB0899 (0xd0 >> 1)
+#define I2C_ADDR_STB6100 (0xc0 >> 1)
+#define I2C_ADDR_LNBP22  (0x10 >> 1)
+#define I2C_ADDR_24C16   (0xa0 >> 1)
+#define I2C_ADDR_24C64   (0xa2 >> 1)
+
+
+/* pctv452e sends us this amount of data for each issued usb-command */
+#define PCTV_ANSWER_LEN 64
+/* Wait up to 1000ms for device  */
+#define PCTV_TIMEOUT 1000
+
+
+#define PCTV_LED_GPIO   STB0899_GPIO01
+#define PCTV_LED_GREEN  0x82
+#define PCTV_LED_ORANGE 0x02
+
+#define ci_dbg(format, arg...)                         \
+do {                                                   \
+       if (0)                                          \
+               printk(KERN_DEBUG DVB_USB_LOG_PREFIX    \
+                       ": " format "\n" , ## arg);     \
+} while (0)
+
+enum {
+       TT3650_CMD_CI_TEST = 0x40,
+       TT3650_CMD_CI_RD_CTRL,
+       TT3650_CMD_CI_WR_CTRL,
+       TT3650_CMD_CI_RD_ATTR,
+       TT3650_CMD_CI_WR_ATTR,
+       TT3650_CMD_CI_RESET,
+       TT3650_CMD_CI_SET_VIDEO_PORT
+};
+
+
+static struct stb0899_postproc pctv45e_postproc[] = {
+       { PCTV_LED_GPIO, STB0899_GPIOPULLUP },
+       { 0, 0 }
+};
+
+/*
+ * stores all private variables for communication with the PCTV452e DVB-S2
+ */
+struct pctv452e_state {
+       struct dvb_ca_en50221 ca;
+       struct mutex ca_mutex;
+
+       u8 c;      /* transaction counter, wraps around...  */
+       u8 initialized; /* set to 1 if 0x15 has been sent */
+       u16 last_rc_key;
+};
+
+static int tt3650_ci_msg(struct dvb_usb_device *d, u8 cmd, u8 *data,
+                        unsigned int write_len, unsigned int read_len)
+{
+       struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
+       u8 buf[64];
+       u8 id;
+       unsigned int rlen;
+       int ret;
+
+       BUG_ON(NULL == data && 0 != (write_len | read_len));
+       BUG_ON(write_len > 64 - 4);
+       BUG_ON(read_len > 64 - 4);
+
+       id = state->c++;
+
+       buf[0] = SYNC_BYTE_OUT;
+       buf[1] = id;
+       buf[2] = cmd;
+       buf[3] = write_len;
+
+       memcpy(buf + 4, data, write_len);
+
+       rlen = (read_len > 0) ? 64 : 0;
+       ret = dvb_usb_generic_rw(d, buf, 4 + write_len,
+                                 buf, rlen, /* delay_ms */ 0);
+       if (0 != ret)
+               goto failed;
+
+       ret = -EIO;
+       if (SYNC_BYTE_IN != buf[0] || id != buf[1])
+               goto failed;
+
+       memcpy(data, buf + 4, read_len);
+
+       return 0;
+
+failed:
+       err("CI error %d; %02X %02X %02X -> %02X %02X %02X.",
+            ret, SYNC_BYTE_OUT, id, cmd, buf[0], buf[1], buf[2]);
+
+       return ret;
+}
+
+static int tt3650_ci_msg_locked(struct dvb_ca_en50221 *ca,
+                               u8 cmd, u8 *data, unsigned int write_len,
+                               unsigned int read_len)
+{
+       struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
+       struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
+       int ret;
+
+       mutex_lock(&state->ca_mutex);
+       ret = tt3650_ci_msg(d, cmd, data, write_len, read_len);
+       mutex_unlock(&state->ca_mutex);
+
+       return ret;
+}
+
+static int tt3650_ci_read_attribute_mem(struct dvb_ca_en50221 *ca,
+                                int slot, int address)
+{
+       u8 buf[3];
+       int ret;
+
+       if (0 != slot)
+               return -EINVAL;
+
+       buf[0] = (address >> 8) & 0x0F;
+       buf[1] = address;
+
+       ret = tt3650_ci_msg_locked(ca, TT3650_CMD_CI_RD_ATTR, buf, 2, 3);
+
+       ci_dbg("%s %04x -> %d 0x%02x",
+               __func__, address, ret, buf[2]);
+
+       if (ret < 0)
+               return ret;
+
+       return buf[2];
+}
+
+static int tt3650_ci_write_attribute_mem(struct dvb_ca_en50221 *ca,
+                                int slot, int address, u8 value)
+{
+       u8 buf[3];
+
+       ci_dbg("%s %d 0x%04x 0x%02x",
+               __func__, slot, address, value);
+
+       if (0 != slot)
+               return -EINVAL;
+
+       buf[0] = (address >> 8) & 0x0F;
+       buf[1] = address;
+       buf[2] = value;
+
+       return tt3650_ci_msg_locked(ca, TT3650_CMD_CI_WR_ATTR, buf, 3, 3);
+}
+
+static int tt3650_ci_read_cam_control(struct dvb_ca_en50221 *ca,
+                                int                    slot,
+                                u8                     address)
+{
+       u8 buf[2];
+       int ret;
+
+       if (0 != slot)
+               return -EINVAL;
+
+       buf[0] = address & 3;
+
+       ret = tt3650_ci_msg_locked(ca, TT3650_CMD_CI_RD_CTRL, buf, 1, 2);
+
+       ci_dbg("%s 0x%02x -> %d 0x%02x",
+               __func__, address, ret, buf[1]);
+
+       if (ret < 0)
+               return ret;
+
+       return buf[1];
+}
+
+static int tt3650_ci_write_cam_control(struct dvb_ca_en50221 *ca,
+                                int                    slot,
+                                u8                     address,
+                                u8                     value)
+{
+       u8 buf[2];
+
+       ci_dbg("%s %d 0x%02x 0x%02x",
+               __func__, slot, address, value);
+
+       if (0 != slot)
+               return -EINVAL;
+
+       buf[0] = address;
+       buf[1] = value;
+
+       return tt3650_ci_msg_locked(ca, TT3650_CMD_CI_WR_CTRL, buf, 2, 2);
+}
+
+static int tt3650_ci_set_video_port(struct dvb_ca_en50221 *ca,
+                                int                    slot,
+                                int                    enable)
+{
+       u8 buf[1];
+       int ret;
+
+       ci_dbg("%s %d %d", __func__, slot, enable);
+
+       if (0 != slot)
+               return -EINVAL;
+
+       enable = !!enable;
+       buf[0] = enable;
+
+       ret = tt3650_ci_msg_locked(ca, TT3650_CMD_CI_SET_VIDEO_PORT, buf, 1, 1);
+       if (ret < 0)
+               return ret;
+
+       if (enable != buf[0]) {
+               err("CI not %sabled.", enable ? "en" : "dis");
+               return -EIO;
+       }
+
+       return 0;
+}
+
+static int tt3650_ci_slot_shutdown(struct dvb_ca_en50221 *ca, int slot)
+{
+       return tt3650_ci_set_video_port(ca, slot, /* enable */ 0);
+}
+
+static int tt3650_ci_slot_ts_enable(struct dvb_ca_en50221 *ca, int slot)
+{
+       return tt3650_ci_set_video_port(ca, slot, /* enable */ 1);
+}
+
+static int tt3650_ci_slot_reset(struct dvb_ca_en50221 *ca, int slot)
+{
+       struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
+       struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
+       u8 buf[1];
+       int ret;
+
+       ci_dbg("%s %d", __func__, slot);
+
+       if (0 != slot)
+               return -EINVAL;
+
+       buf[0] = 0;
+
+       mutex_lock(&state->ca_mutex);
+
+       ret = tt3650_ci_msg(d, TT3650_CMD_CI_RESET, buf, 1, 1);
+       if (0 != ret)
+               goto failed;
+
+       msleep(500);
+
+       buf[0] = 1;
+
+       ret = tt3650_ci_msg(d, TT3650_CMD_CI_RESET, buf, 1, 1);
+       if (0 != ret)
+               goto failed;
+
+       msleep(500);
+
+       buf[0] = 0; /* FTA */
+
+       ret = tt3650_ci_msg(d, TT3650_CMD_CI_SET_VIDEO_PORT, buf, 1, 1);
+
+ failed:
+       mutex_unlock(&state->ca_mutex);
+
+       return ret;
+}
+
+static int tt3650_ci_poll_slot_status(struct dvb_ca_en50221 *ca,
+                                int                    slot,
+                                int                    open)
+{
+       u8 buf[1];
+       int ret;
+
+       if (0 != slot)
+               return -EINVAL;
+
+       ret = tt3650_ci_msg_locked(ca, TT3650_CMD_CI_TEST, buf, 0, 1);
+       if (0 != ret)
+               return ret;
+
+       if (1 == buf[0])
+               return DVB_CA_EN50221_POLL_CAM_PRESENT |
+                       DVB_CA_EN50221_POLL_CAM_READY;
+
+       return 0;
+
+}
+
+static void tt3650_ci_uninit(struct dvb_usb_device *d)
+{
+       struct pctv452e_state *state;
+
+       ci_dbg("%s", __func__);
+
+       if (NULL == d)
+               return;
+
+       state = (struct pctv452e_state *)d->priv;
+       if (NULL == state)
+               return;
+
+       if (NULL == state->ca.data)
+               return;
+
+       /* Error ignored. */
+       tt3650_ci_set_video_port(&state->ca, /* slot */ 0, /* enable */ 0);
+
+       dvb_ca_en50221_release(&state->ca);
+
+       memset(&state->ca, 0, sizeof(state->ca));
+}
+
+static int tt3650_ci_init(struct dvb_usb_adapter *a)
+{
+       struct dvb_usb_device *d = a->dev;
+       struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
+       int ret;
+
+       ci_dbg("%s", __func__);
+
+       mutex_init(&state->ca_mutex);
+
+       state->ca.owner = THIS_MODULE;
+       state->ca.read_attribute_mem = tt3650_ci_read_attribute_mem;
+       state->ca.write_attribute_mem = tt3650_ci_write_attribute_mem;
+       state->ca.read_cam_control = tt3650_ci_read_cam_control;
+       state->ca.write_cam_control = tt3650_ci_write_cam_control;
+       state->ca.slot_reset = tt3650_ci_slot_reset;
+       state->ca.slot_shutdown = tt3650_ci_slot_shutdown;
+       state->ca.slot_ts_enable = tt3650_ci_slot_ts_enable;
+       state->ca.poll_slot_status = tt3650_ci_poll_slot_status;
+       state->ca.data = d;
+
+       ret = dvb_ca_en50221_init(&a->dvb_adap,
+                                  &state->ca,
+                                  /* flags */ 0,
+                                  /* n_slots */ 1);
+       if (0 != ret) {
+               err("Cannot initialize CI: Error %d.", ret);
+               memset(&state->ca, 0, sizeof(state->ca));
+               return ret;
+       }
+
+       info("CI initialized.");
+
+       return 0;
+}
+
+#define CMD_BUFFER_SIZE 0x28
+static int pctv452e_i2c_msg(struct dvb_usb_device *d, u8 addr,
+                               const u8 *snd_buf, u8 snd_len,
+                               u8 *rcv_buf, u8 rcv_len)
+{
+       struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
+       u8 buf[64];
+       u8 id;
+       int ret;
+
+       id = state->c++;
+
+       ret = -EINVAL;
+       if (snd_len > 64 - 7 || rcv_len > 64 - 7)
+               goto failed;
+
+       buf[0] = SYNC_BYTE_OUT;
+       buf[1] = id;
+       buf[2] = PCTV_CMD_I2C;
+       buf[3] = snd_len + 3;
+       buf[4] = addr << 1;
+       buf[5] = snd_len;
+       buf[6] = rcv_len;
+
+       memcpy(buf + 7, snd_buf, snd_len);
+
+       ret = dvb_usb_generic_rw(d, buf, 7 + snd_len,
+                                 buf, /* rcv_len */ 64,
+                                 /* delay_ms */ 0);
+       if (ret < 0)
+               goto failed;
+
+       /* TT USB protocol error. */
+       ret = -EIO;
+       if (SYNC_BYTE_IN != buf[0] || id != buf[1])
+               goto failed;
+
+       /* I2C device didn't respond as expected. */
+       ret = -EREMOTEIO;
+       if (buf[5] < snd_len || buf[6] < rcv_len)
+               goto failed;
+
+       memcpy(rcv_buf, buf + 7, rcv_len);
+
+       return rcv_len;
+
+failed:
+       err("I2C error %d; %02X %02X  %02X %02X %02X -> "
+            "%02X %02X  %02X %02X %02X.",
+            ret, SYNC_BYTE_OUT, id, addr << 1, snd_len, rcv_len,
+            buf[0], buf[1], buf[4], buf[5], buf[6]);
+
+       return ret;
+}
+
+static int pctv452e_i2c_xfer(struct i2c_adapter *adapter, struct i2c_msg *msg,
+                               int num)
+{
+       struct dvb_usb_device *d = i2c_get_adapdata(adapter);
+       int i;
+
+       if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
+               return -EAGAIN;
+
+       for (i = 0; i < num; i++) {
+               u8 addr, snd_len, rcv_len, *snd_buf, *rcv_buf;
+               int ret;
+
+               if (msg[i].flags & I2C_M_RD) {
+                       addr = msg[i].addr;
+                       snd_buf = NULL;
+                       snd_len = 0;
+                       rcv_buf = msg[i].buf;
+                       rcv_len = msg[i].len;
+               } else {
+                       addr = msg[i].addr;
+                       snd_buf = msg[i].buf;
+                       snd_len = msg[i].len;
+                       rcv_buf = NULL;
+                       rcv_len = 0;
+               }
+
+               ret = pctv452e_i2c_msg(d, addr, snd_buf, snd_len, rcv_buf,
+                                       rcv_len);
+               if (ret < rcv_len)
+                       break;
+       }
+
+       mutex_unlock(&d->i2c_mutex);
+       return i;
+}
+
+static u32 pctv452e_i2c_func(struct i2c_adapter *adapter)
+{
+       return I2C_FUNC_I2C;
+}
+
+static int pctv452e_power_ctrl(struct dvb_usb_device *d, int i)
+{
+       struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
+       u8 b0[] = { 0xaa, 0, PCTV_CMD_RESET, 1, 0 };
+       u8 rx[PCTV_ANSWER_LEN];
+       int ret;
+
+       info("%s: %d\n", __func__, i);
+
+       if (!i)
+               return 0;
+
+       if (state->initialized)
+               return 0;
+
+       /* hmm where shoud this should go? */
+       ret = usb_set_interface(d->udev, 0, ISOC_INTERFACE_ALTERNATIVE);
+       if (ret != 0)
+               info("%s: Warning set interface returned: %d\n",
+                       __func__, ret);
+
+       /* this is a one-time initialization, dont know where to put */
+       b0[1] = state->c++;
+       /* reset board */
+       ret = dvb_usb_generic_rw(d, b0, sizeof(b0), rx, PCTV_ANSWER_LEN, 0);
+       if (ret)
+               return ret;
+
+       b0[1] = state->c++;
+       b0[4] = 1;
+       /* reset board (again?) */
+       ret = dvb_usb_generic_rw(d, b0, sizeof(b0), rx, PCTV_ANSWER_LEN, 0);
+       if (ret)
+               return ret;
+
+       state->initialized = 1;
+
+       return 0;
+}
+
+static int pctv452e_rc_query(struct dvb_usb_device *d)
+{
+       struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
+       u8 b[CMD_BUFFER_SIZE];
+       u8 rx[PCTV_ANSWER_LEN];
+       int ret, i;
+       u8 id = state->c++;
+
+       /* prepare command header  */
+       b[0] = SYNC_BYTE_OUT;
+       b[1] = id;
+       b[2] = PCTV_CMD_IR;
+       b[3] = 0;
+
+       /* send ir request */
+       ret = dvb_usb_generic_rw(d, b, 4, rx, PCTV_ANSWER_LEN, 0);
+       if (ret != 0)
+               return ret;
+
+       if (debug > 3) {
+               info("%s: read: %2d: %02x %02x %02x: ", __func__,
+                               ret, rx[0], rx[1], rx[2]);
+               for (i = 0; (i < rx[3]) && ((i+3) < PCTV_ANSWER_LEN); i++)
+                       info(" %02x", rx[i+3]);
+
+               info("\n");
+       }
+
+       if ((rx[3] == 9) &&  (rx[12] & 0x01)) {
+               /* got a "press" event */
+               state->last_rc_key = (rx[7] << 8) | rx[6];
+               if (debug > 2)
+                       info("%s: cmd=0x%02x sys=0x%02x\n",
+                               __func__, rx[6], rx[7]);
+
+               rc_keydown(d->rc_dev, state->last_rc_key, 0);
+       } else if (state->last_rc_key) {
+               rc_keyup(d->rc_dev);
+               state->last_rc_key = 0;
+       }
+
+       return 0;
+}
+
+static int pctv452e_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
+{
+       const u8 mem_addr[] = { 0x1f, 0xcc };
+       u8 encoded_mac[20];
+       int ret;
+
+       ret = -EAGAIN;
+       if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
+               goto failed;
+
+       ret = pctv452e_i2c_msg(d, I2C_ADDR_24C16,
+                               mem_addr + 1, /* snd_len */ 1,
+                               encoded_mac, /* rcv_len */ 20);
+       if (-EREMOTEIO == ret)
+               /* Caution! A 24C16 interprets 0xA2 0x1F 0xCC as a
+                  byte write if /WC is low. */
+               ret = pctv452e_i2c_msg(d, I2C_ADDR_24C64,
+                                       mem_addr, 2,
+                                       encoded_mac, 20);
+
+       mutex_unlock(&d->i2c_mutex);
+
+       if (20 != ret)
+               goto failed;
+
+       ret = ttpci_eeprom_decode_mac(mac, encoded_mac);
+       if (0 != ret)
+               goto failed;
+
+       return 0;
+
+failed:
+       memset(mac, 0, 6);
+
+       return ret;
+}
+
+static const struct stb0899_s1_reg pctv452e_init_dev[] = {
+       { STB0899_DISCNTRL1,    0x26 },
+       { STB0899_DISCNTRL2,    0x80 },
+       { STB0899_DISRX_ST0,    0x04 },
+       { STB0899_DISRX_ST1,    0x20 },
+       { STB0899_DISPARITY,    0x00 },
+       { STB0899_DISFIFO,      0x00 },
+       { STB0899_DISF22,       0x99 },
+       { STB0899_DISF22RX,     0x85 }, /* 0xa8 */
+       { STB0899_ACRPRESC,     0x11 },
+       { STB0899_ACRDIV1,      0x0a },
+       { STB0899_ACRDIV2,      0x05 },
+       { STB0899_DACR1 ,       0x00 },
+       { STB0899_DACR2 ,       0x00 },
+       { STB0899_OUTCFG,       0x00 },
+       { STB0899_MODECFG,      0x00 }, /* Inversion */
+       { STB0899_IRQMSK_3,     0xf3 },
+       { STB0899_IRQMSK_2,     0xfc },
+       { STB0899_IRQMSK_1,     0xff },
+       { STB0899_IRQMSK_0,     0xff },
+       { STB0899_I2CCFG,       0x88 },
+       { STB0899_I2CRPT,       0x58 },
+       { STB0899_GPIO00CFG,    0x82 },
+       { STB0899_GPIO01CFG,    0x82 }, /* LED: 0x02 green, 0x82 orange */
+       { STB0899_GPIO02CFG,    0x82 },
+       { STB0899_GPIO03CFG,    0x82 },
+       { STB0899_GPIO04CFG,    0x82 },
+       { STB0899_GPIO05CFG,    0x82 },
+       { STB0899_GPIO06CFG,    0x82 },
+       { STB0899_GPIO07CFG,    0x82 },
+       { STB0899_GPIO08CFG,    0x82 },
+       { STB0899_GPIO09CFG,    0x82 },
+       { STB0899_GPIO10CFG,    0x82 },
+       { STB0899_GPIO11CFG,    0x82 },
+       { STB0899_GPIO12CFG,    0x82 },
+       { STB0899_GPIO13CFG,    0x82 },
+       { STB0899_GPIO14CFG,    0x82 },
+       { STB0899_GPIO15CFG,    0x82 },
+       { STB0899_GPIO16CFG,    0x82 },
+       { STB0899_GPIO17CFG,    0x82 },
+       { STB0899_GPIO18CFG,    0x82 },
+       { STB0899_GPIO19CFG,    0x82 },
+       { STB0899_GPIO20CFG,    0x82 },
+       { STB0899_SDATCFG,      0xb8 },
+       { STB0899_SCLTCFG,      0xba },
+       { STB0899_AGCRFCFG,     0x1c }, /* 0x11 DVB-S; 0x1c DVB-S2 (1c, rjkm) */
+       { STB0899_GPIO22,       0x82 },
+       { STB0899_GPIO21,       0x91 },
+       { STB0899_DIRCLKCFG,    0x82 },
+       { STB0899_CLKOUT27CFG,  0x7e },
+       { STB0899_STDBYCFG,     0x82 },
+       { STB0899_CS0CFG,       0x82 },
+       { STB0899_CS1CFG,       0x82 },
+       { STB0899_DISEQCOCFG,   0x20 },
+       { STB0899_NCOARSE,      0x15 }, /* 0x15 27Mhz, F/3 198MHz, F/6 108MHz */
+       { STB0899_SYNTCTRL,     0x00 }, /* 0x00 CLKI, 0x02 XTALI */
+       { STB0899_FILTCTRL,     0x00 },
+       { STB0899_SYSCTRL,      0x00 },
+       { STB0899_STOPCLK1,     0x20 }, /* orig: 0x00 budget-ci: 0x20 */
+       { STB0899_STOPCLK2,     0x00 },
+       { STB0899_INTBUFCTRL,   0x0a },
+       { STB0899_AGC2I1,       0x00 },
+       { STB0899_AGC2I2,       0x00 },
+       { STB0899_AGCIQIN,      0x00 },
+       { STB0899_TSTRES,       0x40 }, /* rjkm */
+       { 0xffff,               0xff },
+};
+
+static const struct stb0899_s1_reg pctv452e_init_s1_demod[] = {
+       { STB0899_DEMOD,        0x00 },
+       { STB0899_RCOMPC,       0xc9 },
+       { STB0899_AGC1CN,       0x01 },
+       { STB0899_AGC1REF,      0x10 },
+       { STB0899_RTC,          0x23 },
+       { STB0899_TMGCFG,       0x4e },
+       { STB0899_AGC2REF,      0x34 },
+       { STB0899_TLSR,         0x84 },
+       { STB0899_CFD,          0xf7 },
+       { STB0899_ACLC,         0x87 },
+       { STB0899_BCLC,         0x94 },
+       { STB0899_EQON,         0x41 },
+       { STB0899_LDT,          0xf1 },
+       { STB0899_LDT2,         0xe3 },
+       { STB0899_EQUALREF,     0xb4 },
+       { STB0899_TMGRAMP,      0x10 },
+       { STB0899_TMGTHD,       0x30 },
+       { STB0899_IDCCOMP,      0xfd },
+       { STB0899_QDCCOMP,      0xff },
+       { STB0899_POWERI,       0x0c },
+       { STB0899_POWERQ,       0x0f },
+       { STB0899_RCOMP,        0x6c },
+       { STB0899_AGCIQIN,      0x80 },
+       { STB0899_AGC2I1,       0x06 },
+       { STB0899_AGC2I2,       0x00 },
+       { STB0899_TLIR,         0x30 },
+       { STB0899_RTF,          0x7f },
+       { STB0899_DSTATUS,      0x00 },
+       { STB0899_LDI,          0xbc },
+       { STB0899_CFRM,         0xea },
+       { STB0899_CFRL,         0x31 },
+       { STB0899_NIRM,         0x2b },
+       { STB0899_NIRL,         0x80 },
+       { STB0899_ISYMB,        0x1d },
+       { STB0899_QSYMB,        0xa6 },
+       { STB0899_SFRH,         0x2f },
+       { STB0899_SFRM,         0x68 },
+       { STB0899_SFRL,         0x40 },
+       { STB0899_SFRUPH,       0x2f },
+       { STB0899_SFRUPM,       0x68 },
+       { STB0899_SFRUPL,       0x40 },
+       { STB0899_EQUAI1,       0x02 },
+       { STB0899_EQUAQ1,       0xff },
+       { STB0899_EQUAI2,       0x04 },
+       { STB0899_EQUAQ2,       0x05 },
+       { STB0899_EQUAI3,       0x02 },
+       { STB0899_EQUAQ3,       0xfd },
+       { STB0899_EQUAI4,       0x03 },
+       { STB0899_EQUAQ4,       0x07 },
+       { STB0899_EQUAI5,       0x08 },
+       { STB0899_EQUAQ5,       0xf5 },
+       { STB0899_DSTATUS2,     0x00 },
+       { STB0899_VSTATUS,      0x00 },
+       { STB0899_VERROR,       0x86 },
+       { STB0899_IQSWAP,       0x2a },
+       { STB0899_ECNT1M,       0x00 },
+       { STB0899_ECNT1L,       0x00 },
+       { STB0899_ECNT2M,       0x00 },
+       { STB0899_ECNT2L,       0x00 },
+       { STB0899_ECNT3M,       0x0a },
+       { STB0899_ECNT3L,       0xad },
+       { STB0899_FECAUTO1,     0x06 },
+       { STB0899_FECM,         0x01 },
+       { STB0899_VTH12,        0xb0 },
+       { STB0899_VTH23,        0x7a },
+       { STB0899_VTH34,        0x58 },
+       { STB0899_VTH56,        0x38 },
+       { STB0899_VTH67,        0x34 },
+       { STB0899_VTH78,        0x24 },
+       { STB0899_PRVIT,        0xff },
+       { STB0899_VITSYNC,      0x19 },
+       { STB0899_RSULC,        0xb1 }, /* DVB = 0xb1, DSS = 0xa1 */
+       { STB0899_TSULC,        0x42 },
+       { STB0899_RSLLC,        0x41 },
+       { STB0899_TSLPL,        0x12 },
+       { STB0899_TSCFGH,       0x0c },
+       { STB0899_TSCFGM,       0x00 },
+       { STB0899_TSCFGL,       0x00 },
+       { STB0899_TSOUT,        0x69 }, /* 0x0d for CAM */
+       { STB0899_RSSYNCDEL,    0x00 },
+       { STB0899_TSINHDELH,    0x02 },
+       { STB0899_TSINHDELM,    0x00 },
+       { STB0899_TSINHDELL,    0x00 },
+       { STB0899_TSLLSTKM,     0x1b },
+       { STB0899_TSLLSTKL,     0xb3 },
+       { STB0899_TSULSTKM,     0x00 },
+       { STB0899_TSULSTKL,     0x00 },
+       { STB0899_PCKLENUL,     0xbc },
+       { STB0899_PCKLENLL,     0xcc },
+       { STB0899_RSPCKLEN,     0xbd },
+       { STB0899_TSSTATUS,     0x90 },
+       { STB0899_ERRCTRL1,     0xb6 },
+       { STB0899_ERRCTRL2,     0x95 },
+       { STB0899_ERRCTRL3,     0x8d },
+       { STB0899_DMONMSK1,     0x27 },
+       { STB0899_DMONMSK0,     0x03 },
+       { STB0899_DEMAPVIT,     0x5c },
+       { STB0899_PLPARM,       0x19 },
+       { STB0899_PDELCTRL,     0x48 },
+       { STB0899_PDELCTRL2,    0x00 },
+       { STB0899_BBHCTRL1,     0x00 },
+       { STB0899_BBHCTRL2,     0x00 },
+       { STB0899_HYSTTHRESH,   0x77 },
+       { STB0899_MATCSTM,      0x00 },
+       { STB0899_MATCSTL,      0x00 },
+       { STB0899_UPLCSTM,      0x00 },
+       { STB0899_UPLCSTL,      0x00 },
+       { STB0899_DFLCSTM,      0x00 },
+       { STB0899_DFLCSTL,      0x00 },
+       { STB0899_SYNCCST,      0x00 },
+       { STB0899_SYNCDCSTM,    0x00 },
+       { STB0899_SYNCDCSTL,    0x00 },
+       { STB0899_ISI_ENTRY,    0x00 },
+       { STB0899_ISI_BIT_EN,   0x00 },
+       { STB0899_MATSTRM,      0xf0 },
+       { STB0899_MATSTRL,      0x02 },
+       { STB0899_UPLSTRM,      0x45 },
+       { STB0899_UPLSTRL,      0x60 },
+       { STB0899_DFLSTRM,      0xe3 },
+       { STB0899_DFLSTRL,      0x00 },
+       { STB0899_SYNCSTR,      0x47 },
+       { STB0899_SYNCDSTRM,    0x05 },
+       { STB0899_SYNCDSTRL,    0x18 },
+       { STB0899_CFGPDELSTATUS1, 0x19 },
+       { STB0899_CFGPDELSTATUS2, 0x2b },
+       { STB0899_BBFERRORM,    0x00 },
+       { STB0899_BBFERRORL,    0x01 },
+       { STB0899_UPKTERRORM,   0x00 },
+       { STB0899_UPKTERRORL,   0x00 },
+       { 0xffff,               0xff },
+};
+
+static struct stb0899_config stb0899_config = {
+       .init_dev       = pctv452e_init_dev,
+       .init_s2_demod  = stb0899_s2_init_2,
+       .init_s1_demod  = pctv452e_init_s1_demod,
+       .init_s2_fec    = stb0899_s2_init_4,
+       .init_tst       = stb0899_s1_init_5,
+
+       .demod_address   = I2C_ADDR_STB0899, /* I2C Address */
+       .block_sync_mode = STB0899_SYNC_FORCED, /* ? */
+
+       .xtal_freq       = 27000000,     /* Assume Hz ? */
+       .inversion       = IQ_SWAP_ON,       /* ? */
+
+       .lo_clk   = 76500000,
+       .hi_clk   = 99000000,
+
+       .ts_output_mode  = 0,   /* Use parallel mode */
+       .clock_polarity  = 0,
+       .data_clk_parity = 0,
+       .fec_mode       = 0,
+
+       .esno_ave           = STB0899_DVBS2_ESNO_AVE,
+       .esno_quant       = STB0899_DVBS2_ESNO_QUANT,
+       .avframes_coarse     = STB0899_DVBS2_AVFRAMES_COARSE,
+       .avframes_fine       = STB0899_DVBS2_AVFRAMES_FINE,
+       .miss_threshold      = STB0899_DVBS2_MISS_THRESHOLD,
+       .uwp_threshold_acq   = STB0899_DVBS2_UWP_THRESHOLD_ACQ,
+       .uwp_threshold_track = STB0899_DVBS2_UWP_THRESHOLD_TRACK,
+       .uwp_threshold_sof   = STB0899_DVBS2_UWP_THRESHOLD_SOF,
+       .sof_search_timeout  = STB0899_DVBS2_SOF_SEARCH_TIMEOUT,
+
+       .btr_nco_bits     = STB0899_DVBS2_BTR_NCO_BITS,
+       .btr_gain_shift_offset = STB0899_DVBS2_BTR_GAIN_SHIFT_OFFSET,
+       .crl_nco_bits     = STB0899_DVBS2_CRL_NCO_BITS,
+       .ldpc_max_iter   = STB0899_DVBS2_LDPC_MAX_ITER,
+
+       .tuner_get_frequency    = stb6100_get_frequency,
+       .tuner_set_frequency    = stb6100_set_frequency,
+       .tuner_set_bandwidth    = stb6100_set_bandwidth,
+       .tuner_get_bandwidth    = stb6100_get_bandwidth,
+       .tuner_set_rfsiggain    = NULL,
+
+       /* helper for switching LED green/orange */
+       .postproc = pctv45e_postproc
+};
+
+static struct stb6100_config stb6100_config = {
+       .tuner_address = I2C_ADDR_STB6100,
+       .refclock      = 27000000
+};
+
+
+static struct i2c_algorithm pctv452e_i2c_algo = {
+       .master_xfer   = pctv452e_i2c_xfer,
+       .functionality = pctv452e_i2c_func
+};
+
+static int pctv452e_frontend_attach(struct dvb_usb_adapter *a)
+{
+       struct usb_device_id *id;
+
+       a->fe_adap[0].fe = dvb_attach(stb0899_attach, &stb0899_config,
+                                               &a->dev->i2c_adap);
+       if (!a->fe_adap[0].fe)
+               return -ENODEV;
+       if ((dvb_attach(lnbp22_attach, a->fe_adap[0].fe,
+                                       &a->dev->i2c_adap)) == 0)
+               err("Cannot attach lnbp22\n");
+
+       id = a->dev->desc->warm_ids[0];
+       if (USB_VID_TECHNOTREND == id->idVendor
+           && USB_PID_TECHNOTREND_CONNECT_S2_3650_CI == id->idProduct)
+               /* Error ignored. */
+               tt3650_ci_init(a);
+
+       return 0;
+}
+
+static int pctv452e_tuner_attach(struct dvb_usb_adapter *a)
+{
+       if (!a->fe_adap[0].fe)
+               return -ENODEV;
+       if (dvb_attach(stb6100_attach, a->fe_adap[0].fe, &stb6100_config,
+                                       &a->dev->i2c_adap) == 0) {
+               err("%s failed\n", __func__);
+               return -ENODEV;
+       }
+
+       return 0;
+}
+
+static struct usb_device_id pctv452e_usb_table[] = {
+       {USB_DEVICE(USB_VID_PINNACLE, USB_PID_PCTV_452E)},
+       {USB_DEVICE(USB_VID_TECHNOTREND, USB_PID_TECHNOTREND_CONNECT_S2_3600)},
+       {USB_DEVICE(USB_VID_TECHNOTREND,
+                               USB_PID_TECHNOTREND_CONNECT_S2_3650_CI)},
+       {}
+};
+MODULE_DEVICE_TABLE(usb, pctv452e_usb_table);
+
+static struct dvb_usb_device_properties pctv452e_properties = {
+       .caps = DVB_USB_IS_AN_I2C_ADAPTER, /* more ? */
+       .usb_ctrl = DEVICE_SPECIFIC,
+
+       .size_of_priv     = sizeof(struct pctv452e_state),
+
+       .power_ctrl       = pctv452e_power_ctrl,
+
+       .rc.core = {
+               .rc_codes       = RC_MAP_DIB0700_RC5_TABLE,
+               .allowed_protos = RC_TYPE_UNKNOWN,
+               .rc_query       = pctv452e_rc_query,
+               .rc_interval    = 100,
+       },
+
+       .num_adapters     = 1,
+       .adapter = {{
+               .num_frontends = 1,
+               .fe = {{
+                       .frontend_attach  = pctv452e_frontend_attach,
+                       .tuner_attach     = pctv452e_tuner_attach,
+
+                       /* parameter for the MPEG2-data transfer */
+                       .stream = {
+                               .type     = USB_ISOC,
+                               .count    = 4,
+                               .endpoint = 0x02,
+                               .u = {
+                                       .isoc = {
+                                               .framesperurb = 4,
+                                               .framesize    = 940,
+                                               .interval     = 1
+                                       }
+                               }
+                       },
+               } },
+       } },
+
+       .i2c_algo = &pctv452e_i2c_algo,
+
+       .generic_bulk_ctrl_endpoint = 1, /* allow generice rw function */
+
+       .num_device_descs = 1,
+       .devices = {
+               { .name = "PCTV HDTV USB",
+                 .cold_ids = { NULL, NULL }, /* this is a warm only device */
+                 .warm_ids = { &pctv452e_usb_table[0], NULL }
+               },
+               { 0 },
+       }
+};
+
+static struct dvb_usb_device_properties tt_connect_s2_3600_properties = {
+       .caps = DVB_USB_IS_AN_I2C_ADAPTER, /* more ? */
+       .usb_ctrl = DEVICE_SPECIFIC,
+
+       .size_of_priv           = sizeof(struct pctv452e_state),
+
+       .power_ctrl             = pctv452e_power_ctrl,
+       .read_mac_address       = pctv452e_read_mac_address,
+
+       .rc.core = {
+               .rc_codes       = RC_MAP_TT_1500,
+               .allowed_protos = RC_TYPE_UNKNOWN,
+               .rc_query       = pctv452e_rc_query,
+               .rc_interval    = 100,
+       },
+
+       .num_adapters           = 1,
+       .adapter = {{
+               .num_frontends = 1,
+               .fe = {{
+                       .frontend_attach = pctv452e_frontend_attach,
+                       .tuner_attach = pctv452e_tuner_attach,
+
+                       /* parameter for the MPEG2-data transfer */
+                       .stream = {
+                               .type = USB_ISOC,
+                               .count = 7,
+                               .endpoint = 0x02,
+                               .u = {
+                                       .isoc = {
+                                               .framesperurb = 4,
+                                               .framesize = 940,
+                                               .interval = 1
+                                       }
+                               }
+                       },
+
+               } },
+       } },
+
+       .i2c_algo = &pctv452e_i2c_algo,
+
+       .generic_bulk_ctrl_endpoint = 1, /* allow generic rw function*/
+
+       .num_device_descs = 2,
+       .devices = {
+               { .name = "Technotrend TT Connect S2-3600",
+                 .cold_ids = { NULL, NULL }, /* this is a warm only device */
+                 .warm_ids = { &pctv452e_usb_table[1], NULL }
+               },
+               { .name = "Technotrend TT Connect S2-3650-CI",
+                 .cold_ids = { NULL, NULL },
+                 .warm_ids = { &pctv452e_usb_table[2], NULL }
+               },
+               { 0 },
+       }
+};
+
+static void pctv452e_usb_disconnect(struct usb_interface *intf)
+{
+       struct dvb_usb_device *d = usb_get_intfdata(intf);
+
+       tt3650_ci_uninit(d);
+       dvb_usb_device_exit(intf);
+}
+
+static int pctv452e_usb_probe(struct usb_interface *intf,
+                               const struct usb_device_id *id)
+{
+       if (0 == dvb_usb_device_init(intf, &pctv452e_properties,
+                                       THIS_MODULE, NULL, adapter_nr) ||
+           0 == dvb_usb_device_init(intf, &tt_connect_s2_3600_properties,
+                                       THIS_MODULE, NULL, adapter_nr))
+               return 0;
+
+       return -ENODEV;
+}
+
+static struct usb_driver pctv452e_usb_driver = {
+       .name       = "pctv452e",
+       .probe      = pctv452e_usb_probe,
+       .disconnect = pctv452e_usb_disconnect,
+       .id_table   = pctv452e_usb_table,
+};
+
+static int __init pctv452e_usb_init(void)
+{
+       int ret = usb_register(&pctv452e_usb_driver);
+       if (ret)
+               err("%s: usb_register failed! Error %d", __FILE__, ret);
+
+       return ret;
+}
+
+static void __exit pctv452e_usb_exit(void)
+{
+       usb_deregister(&pctv452e_usb_driver);
+}
+
+module_init(pctv452e_usb_init);
+module_exit(pctv452e_usb_exit);
+
+MODULE_AUTHOR("Dominik Kuhlen <dkuhlen@gmx.net>");
+MODULE_AUTHOR("Andre Weidemann <Andre.Weidemann@web.de>");
+MODULE_AUTHOR("Michael H. Schimek <mschimek@gmx.at>");
+MODULE_DESCRIPTION("Pinnacle PCTV HDTV USB DVB / TT connect S2-3600 Driver");
+MODULE_LICENSE("GPL");
index 473b95ed4d52759339b7b9f4b0c20541b76a569c..0998fe961950d3584a5897e83b11fc60e5fab5f2 100644 (file)
@@ -292,7 +292,7 @@ static void technisat_usb2_green_led_control(struct work_struct *work)
 {
        struct technisat_usb2_state *state =
                container_of(work, struct technisat_usb2_state, green_led_work.work);
-       struct dvb_frontend *fe = state->dev->adapter[0].fe;
+       struct dvb_frontend *fe = state->dev->adapter[0].fe_adap[0].fe;
 
        if (state->power_state == 0)
                goto schedule;
@@ -505,14 +505,14 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
        struct usb_device *udev = a->dev->udev;
        int ret;
 
-       a->fe = dvb_attach(stv090x_attach, &technisat_usb2_stv090x_config,
+       a->fe_adap[0].fe = dvb_attach(stv090x_attach, &technisat_usb2_stv090x_config,
                        &a->dev->i2c_adap, STV090x_DEMODULATOR_0);
 
-       if (a->fe) {
+       if (a->fe_adap[0].fe) {
                struct stv6110x_devctl *ctl;
 
                ctl = dvb_attach(stv6110x_attach,
-                               a->fe,
+                               a->fe_adap[0].fe,
                                &technisat_usb2_stv6110x_config,
                                &a->dev->i2c_adap);
 
@@ -532,8 +532,8 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
                        /* call the init function once to initialize
                           tuner's clock output divider and demod's
                           master clock */
-                       if (a->fe->ops.init)
-                               a->fe->ops.init(a->fe);
+                       if (a->fe_adap[0].fe->ops.init)
+                               a->fe_adap[0].fe->ops.init(a->fe_adap[0].fe);
 
                        if (mutex_lock_interruptible(&a->dev->i2c_mutex) < 0)
                                return -EAGAIN;
@@ -548,20 +548,20 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
                        if (ret != 0)
                                err("could not set IF_CLK to external");
 
-                       a->fe->ops.set_voltage = technisat_usb2_set_voltage;
+                       a->fe_adap[0].fe->ops.set_voltage = technisat_usb2_set_voltage;
 
                        /* if everything was successful assign a nice name to the frontend */
-                       strlcpy(a->fe->ops.info.name, a->dev->desc->name,
-                                       sizeof(a->fe->ops.info.name));
+                       strlcpy(a->fe_adap[0].fe->ops.info.name, a->dev->desc->name,
+                                       sizeof(a->fe_adap[0].fe->ops.info.name));
                } else {
-                       dvb_frontend_detach(a->fe);
-                       a->fe = NULL;
+                       dvb_frontend_detach(a->fe_adap[0].fe);
+                       a->fe_adap[0].fe = NULL;
                }
        }
 
        technisat_usb2_set_led_timer(a->dev, 1, 1);
 
-       return a->fe == NULL ? -ENODEV : 0;
+       return a->fe_adap[0].fe == NULL ? -ENODEV : 0;
 }
 
 /* Remote control */
@@ -697,6 +697,8 @@ static struct dvb_usb_device_properties technisat_usb2_devices = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .frontend_attach  = technisat_usb2_frontend_attach,
 
                        .stream = {
@@ -711,7 +713,7 @@ static struct dvb_usb_device_properties technisat_usb2_devices = {
                                        }
                                }
                        },
-
+               }},
                        .size_of_priv = 0,
                },
        },
index 0d4709ff9cbb2f4249d7b9c186991d6c57221521..ea4eab8b3965c00659aa8c26805e99fc4ed2bd0e 100644 (file)
 #include "tda826x.h"
 #include "tda10086.h"
 #include "tda1002x.h"
+#include "tda10048.h"
 #include "tda827x.h"
 #include "lnbp21.h"
+/* CA */
+#include "dvb_ca_en50221.h"
 
 /* debug */
 static int dvb_usb_ttusb2_debug;
 #define deb_info(args...)   dprintk(dvb_usb_ttusb2_debug,0x01,args)
 module_param_named(debug,dvb_usb_ttusb2_debug, int, 0644);
 MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able))." DVB_USB_DEBUG_STATUS);
+static int dvb_usb_ttusb2_debug_ci;
+module_param_named(debug_ci,dvb_usb_ttusb2_debug_ci, int, 0644);
+MODULE_PARM_DESC(debug_ci, "set debugging ci." DVB_USB_DEBUG_STATUS);
 
 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 
+#define ci_dbg(format, arg...)                \
+do {                                          \
+       if (dvb_usb_ttusb2_debug_ci)                                    \
+               printk(KERN_DEBUG DVB_USB_LOG_PREFIX \
+                       ": %s " format "\n" , __func__, ## arg);       \
+} while (0)
+
+enum {
+       TT3650_CMD_CI_TEST = 0x40,
+       TT3650_CMD_CI_RD_CTRL,
+       TT3650_CMD_CI_WR_CTRL,
+       TT3650_CMD_CI_RD_ATTR,
+       TT3650_CMD_CI_WR_ATTR,
+       TT3650_CMD_CI_RESET,
+       TT3650_CMD_CI_SET_VIDEO_PORT
+};
+
 struct ttusb2_state {
+       struct dvb_ca_en50221 ca;
+       struct mutex ca_mutex;
        u8 id;
        u16 last_rc_key;
 };
@@ -78,11 +103,260 @@ static int ttusb2_msg(struct dvb_usb_device *d, u8 cmd,
        return 0;
 }
 
+/* ci */
+static int tt3650_ci_msg(struct dvb_usb_device *d, u8 cmd, u8 *data, unsigned int write_len, unsigned int read_len)
+{
+       int ret;
+       u8 rx[60];/* (64 -4) */
+       ret = ttusb2_msg(d, cmd, data, write_len, rx, read_len);
+       if (!ret)
+               memcpy(data, rx, read_len);
+       return ret;
+}
+
+static int tt3650_ci_msg_locked(struct dvb_ca_en50221 *ca, u8 cmd, u8 *data, unsigned int write_len, unsigned int read_len)
+{
+       struct dvb_usb_device *d = ca->data;
+       struct ttusb2_state *state = d->priv;
+       int ret;
+
+       mutex_lock(&state->ca_mutex);
+       ret = tt3650_ci_msg(d, cmd, data, write_len, read_len);
+       mutex_unlock(&state->ca_mutex);
+
+       return ret;
+}
+
+static int tt3650_ci_read_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address)
+{
+       u8 buf[3];
+       int ret = 0;
+
+       if (slot)
+               return -EINVAL;
+
+       buf[0] = (address >> 8) & 0x0F;
+       buf[1] = address;
+
+
+       ret = tt3650_ci_msg_locked(ca, TT3650_CMD_CI_RD_ATTR, buf, 2, 3);
+
+       ci_dbg("%04x -> %d 0x%02x", address, ret, buf[2]);
+
+       if (ret < 0)
+               return ret;
+
+       return buf[2];
+}
+
+static int tt3650_ci_write_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address, u8 value)
+{
+       u8 buf[3];
+
+       ci_dbg("%d 0x%04x 0x%02x", slot, address, value);
+
+       if (slot)
+               return -EINVAL;
+
+       buf[0] = (address >> 8) & 0x0F;
+       buf[1] = address;
+       buf[2] = value;
+
+       return tt3650_ci_msg_locked(ca, TT3650_CMD_CI_WR_ATTR, buf, 3, 3);
+}
+
+static int tt3650_ci_read_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address)
+{
+       u8 buf[2];
+       int ret;
+
+       if (slot)
+               return -EINVAL;
+
+       buf[0] = address & 3;
+
+       ret = tt3650_ci_msg_locked(ca, TT3650_CMD_CI_RD_CTRL, buf, 1, 2);
+
+       ci_dbg("0x%02x -> %d 0x%02x", address, ret, buf[1]);
+
+       if (ret < 0)
+               return ret;
+
+       return buf[1];
+}
+
+static int tt3650_ci_write_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address, u8 value)
+{
+       u8 buf[2];
+
+       ci_dbg("%d 0x%02x 0x%02x", slot, address, value);
+
+       if (slot)
+               return -EINVAL;
+
+       buf[0] = address;
+       buf[1] = value;
+
+       return tt3650_ci_msg_locked(ca, TT3650_CMD_CI_WR_CTRL, buf, 2, 2);
+}
+
+static int tt3650_ci_set_video_port(struct dvb_ca_en50221 *ca, int slot, int enable)
+{
+       u8 buf[1];
+       int ret;
+
+       ci_dbg("%d %d", slot, enable);
+
+       if (slot)
+               return -EINVAL;
+
+       buf[0] = enable;
+
+       ret = tt3650_ci_msg_locked(ca, TT3650_CMD_CI_SET_VIDEO_PORT, buf, 1, 1);
+       if (ret < 0)
+               return ret;
+
+       if (enable != buf[0]) {
+               err("CI not %sabled.", enable ? "en" : "dis");
+               return -EIO;
+       }
+
+       return 0;
+}
+
+static int tt3650_ci_slot_shutdown(struct dvb_ca_en50221 *ca, int slot)
+{
+       return tt3650_ci_set_video_port(ca, slot, 0);
+}
+
+static int tt3650_ci_slot_ts_enable(struct dvb_ca_en50221 *ca, int slot)
+{
+       return tt3650_ci_set_video_port(ca, slot, 1);
+}
+
+static int tt3650_ci_slot_reset(struct dvb_ca_en50221 *ca, int slot)
+{
+       struct dvb_usb_device *d = ca->data;
+       struct ttusb2_state *state = d->priv;
+       u8 buf[1];
+       int ret;
+
+       ci_dbg("%d", slot);
+
+       if (slot)
+               return -EINVAL;
+
+       buf[0] = 0;
+
+       mutex_lock(&state->ca_mutex);
+
+       ret = tt3650_ci_msg(d, TT3650_CMD_CI_RESET, buf, 1, 1);
+       if (ret)
+               goto failed;
+
+       msleep(500);
+
+       buf[0] = 1;
+
+       ret = tt3650_ci_msg(d, TT3650_CMD_CI_RESET, buf, 1, 1);
+       if (ret)
+               goto failed;
+
+       msleep(500);
+
+       buf[0] = 0; /* FTA */
+
+       ret = tt3650_ci_msg(d, TT3650_CMD_CI_SET_VIDEO_PORT, buf, 1, 1);
+
+       msleep(1100);
+
+ failed:
+       mutex_unlock(&state->ca_mutex);
+
+       return ret;
+}
+
+static int tt3650_ci_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int open)
+{
+       u8 buf[1];
+       int ret;
+
+       if (slot)
+               return -EINVAL;
+
+       ret = tt3650_ci_msg_locked(ca, TT3650_CMD_CI_TEST, buf, 0, 1);
+       if (ret)
+               return ret;
+
+       if (1 == buf[0]) {
+               return DVB_CA_EN50221_POLL_CAM_PRESENT |
+                       DVB_CA_EN50221_POLL_CAM_READY;
+       }
+       return 0;
+}
+
+static void tt3650_ci_uninit(struct dvb_usb_device *d)
+{
+       struct ttusb2_state *state;
+
+       ci_dbg("");
+
+       if (NULL == d)
+               return;
+
+       state = d->priv;
+       if (NULL == state)
+               return;
+
+       if (NULL == state->ca.data)
+               return;
+
+       dvb_ca_en50221_release(&state->ca);
+
+       memset(&state->ca, 0, sizeof(state->ca));
+}
+
+static int tt3650_ci_init(struct dvb_usb_adapter *a)
+{
+       struct dvb_usb_device *d = a->dev;
+       struct ttusb2_state *state = d->priv;
+       int ret;
+
+       ci_dbg("");
+
+       mutex_init(&state->ca_mutex);
+
+       state->ca.owner = THIS_MODULE;
+       state->ca.read_attribute_mem = tt3650_ci_read_attribute_mem;
+       state->ca.write_attribute_mem = tt3650_ci_write_attribute_mem;
+       state->ca.read_cam_control = tt3650_ci_read_cam_control;
+       state->ca.write_cam_control = tt3650_ci_write_cam_control;
+       state->ca.slot_reset = tt3650_ci_slot_reset;
+       state->ca.slot_shutdown = tt3650_ci_slot_shutdown;
+       state->ca.slot_ts_enable = tt3650_ci_slot_ts_enable;
+       state->ca.poll_slot_status = tt3650_ci_poll_slot_status;
+       state->ca.data = d;
+
+       ret = dvb_ca_en50221_init(&a->dvb_adap,
+                                 &state->ca,
+                                 /* flags */ 0,
+                                 /* n_slots */ 1);
+       if (ret) {
+               err("Cannot initialize CI: Error %d.", ret);
+               memset(&state->ca, 0, sizeof(state->ca));
+               return ret;
+       }
+
+       info("CI initialized.");
+
+       return 0;
+}
+
 static int ttusb2_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num)
 {
        struct dvb_usb_device *d = i2c_get_adapdata(adap);
        static u8 obuf[60], ibuf[60];
-       int i,read;
+       int i, write_read, read;
 
        if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
                return -EAGAIN;
@@ -91,28 +365,35 @@ static int ttusb2_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num
                warn("more than 2 i2c messages at a time is not handled yet. TODO.");
 
        for (i = 0; i < num; i++) {
-               read = i+1 < num && (msg[i+1].flags & I2C_M_RD);
+               write_read = i+1 < num && (msg[i+1].flags & I2C_M_RD);
+               read = msg[i].flags & I2C_M_RD;
 
-               obuf[0] = (msg[i].addr << 1) | read;
-               obuf[1] = msg[i].len;
+               obuf[0] = (msg[i].addr << 1) | (write_read | read);
+               if (read)
+                       obuf[1] = 0;
+               else
+                       obuf[1] = msg[i].len;
 
                /* read request */
-               if (read)
+               if (write_read)
                        obuf[2] = msg[i+1].len;
+               else if (read)
+                       obuf[2] = msg[i].len;
                else
                        obuf[2] = 0;
 
-               memcpy(&obuf[3],msg[i].buf,msg[i].len);
+               memcpy(&obuf[3], msg[i].buf, msg[i].len);
 
                if (ttusb2_msg(d, CMD_I2C_XFER, obuf, msg[i].len+3, ibuf, obuf[2] + 3) < 0) {
                        err("i2c transfer failed.");
                        break;
                }
 
-               if (read) {
-                       memcpy(msg[i+1].buf,&ibuf[3],msg[i+1].len);
+               if (write_read) {
+                       memcpy(msg[i+1].buf, &ibuf[3], msg[i+1].len);
                        i++;
-               }
+               } else if (read)
+                       memcpy(msg[i].buf, &ibuf[3], msg[i].len);
        }
 
        mutex_unlock(&d->i2c_mutex);
@@ -190,12 +471,31 @@ static struct tda10023_config tda10023_config = {
        .deltaf = 0xa511,
 };
 
+static struct tda10048_config tda10048_config = {
+       .demod_address    = 0x10 >> 1,
+       .output_mode      = TDA10048_PARALLEL_OUTPUT,
+       .inversion        = TDA10048_INVERSION_ON,
+       .dtv6_if_freq_khz = TDA10048_IF_4000,
+       .dtv7_if_freq_khz = TDA10048_IF_4500,
+       .dtv8_if_freq_khz = TDA10048_IF_5000,
+       .clk_freq_khz     = TDA10048_CLK_16000,
+       .no_firmware      = 1,
+       .set_pll          = true ,
+       .pll_m            = 5,
+       .pll_n            = 3,
+       .pll_p            = 0,
+};
+
+static struct tda827x_config tda827x_config = {
+       .config = 0,
+};
+
 static int ttusb2_frontend_tda10086_attach(struct dvb_usb_adapter *adap)
 {
        if (usb_set_interface(adap->dev->udev,0,3) < 0)
                err("set interface to alts=3 failed");
 
-       if ((adap->fe = dvb_attach(tda10086_attach, &tda10086_config, &adap->dev->i2c_adap)) == NULL) {
+       if ((adap->fe_adap[0].fe = dvb_attach(tda10086_attach, &tda10086_config, &adap->dev->i2c_adap)) == NULL) {
                deb_info("TDA10086 attach failed\n");
                return -ENODEV;
        }
@@ -203,20 +503,57 @@ static int ttusb2_frontend_tda10086_attach(struct dvb_usb_adapter *adap)
        return 0;
 }
 
+static int ttusb2_ct3650_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
+{
+       struct dvb_usb_adapter *adap = fe->dvb->priv;
+
+       return adap->fe_adap[0].fe->ops.i2c_gate_ctrl(adap->fe_adap[0].fe, enable);
+}
+
 static int ttusb2_frontend_tda10023_attach(struct dvb_usb_adapter *adap)
 {
        if (usb_set_interface(adap->dev->udev, 0, 3) < 0)
                err("set interface to alts=3 failed");
-       if ((adap->fe = dvb_attach(tda10023_attach, &tda10023_config, &adap->dev->i2c_adap, 0x48)) == NULL) {
-               deb_info("TDA10023 attach failed\n");
-               return -ENODEV;
+
+       if (adap->fe_adap[0].fe == NULL) {
+               /* FE 0 DVB-C */
+               adap->fe_adap[0].fe = dvb_attach(tda10023_attach,
+                       &tda10023_config, &adap->dev->i2c_adap, 0x48);
+
+               if (adap->fe_adap[0].fe == NULL) {
+                       deb_info("TDA10023 attach failed\n");
+                       return -ENODEV;
+               }
+               tt3650_ci_init(adap);
+       } else {
+               adap->fe_adap[1].fe = dvb_attach(tda10048_attach,
+                       &tda10048_config, &adap->dev->i2c_adap);
+
+               if (adap->fe_adap[1].fe == NULL) {
+                       deb_info("TDA10048 attach failed\n");
+                       return -ENODEV;
+               }
+
+               /* tuner is behind TDA10023 I2C-gate */
+               adap->fe_adap[1].fe->ops.i2c_gate_ctrl = ttusb2_ct3650_i2c_gate_ctrl;
+
        }
+
        return 0;
 }
 
 static int ttusb2_tuner_tda827x_attach(struct dvb_usb_adapter *adap)
 {
-       if (dvb_attach(tda827x_attach, adap->fe, 0x61, &adap->dev->i2c_adap, NULL) == NULL) {
+       struct dvb_frontend *fe;
+
+       /* MFE: select correct FE to attach tuner since that's called twice */
+       if (adap->fe_adap[1].fe == NULL)
+               fe = adap->fe_adap[0].fe;
+       else
+               fe = adap->fe_adap[1].fe;
+
+       /* attach tuner */
+       if (dvb_attach(tda827x_attach, fe, 0x61, &adap->dev->i2c_adap, &tda827x_config) == NULL) {
                printk(KERN_ERR "%s: No tda827x found!\n", __func__);
                return -ENODEV;
        }
@@ -225,12 +562,12 @@ static int ttusb2_tuner_tda827x_attach(struct dvb_usb_adapter *adap)
 
 static int ttusb2_tuner_tda826x_attach(struct dvb_usb_adapter *adap)
 {
-       if (dvb_attach(tda826x_attach, adap->fe, 0x60, &adap->dev->i2c_adap, 0) == NULL) {
+       if (dvb_attach(tda826x_attach, adap->fe_adap[0].fe, 0x60, &adap->dev->i2c_adap, 0) == NULL) {
                deb_info("TDA8263 attach failed\n");
                return -ENODEV;
        }
 
-       if (dvb_attach(lnbp21_attach, adap->fe, &adap->dev->i2c_adap, 0, 0) == NULL) {
+       if (dvb_attach(lnbp21_attach, adap->fe_adap[0].fe, &adap->dev->i2c_adap, 0, 0) == NULL) {
                deb_info("LNBP21 attach failed\n");
                return -ENODEV;
        }
@@ -242,6 +579,14 @@ static struct dvb_usb_device_properties ttusb2_properties;
 static struct dvb_usb_device_properties ttusb2_properties_s2400;
 static struct dvb_usb_device_properties ttusb2_properties_ct3650;
 
+static void ttusb2_usb_disconnect(struct usb_interface *intf)
+{
+       struct dvb_usb_device *d = usb_get_intfdata(intf);
+
+       tt3650_ci_uninit(d);
+       dvb_usb_device_exit(intf);
+}
+
 static int ttusb2_probe(struct usb_interface *intf,
                const struct usb_device_id *id)
 {
@@ -277,6 +622,8 @@ static struct dvb_usb_device_properties ttusb2_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .streaming_ctrl   = NULL, // ttusb2_streaming_ctrl,
 
                        .frontend_attach  = ttusb2_frontend_tda10086_attach,
@@ -295,6 +642,7 @@ static struct dvb_usb_device_properties ttusb2_properties = {
                                        }
                                }
                        }
+               }},
                }
        },
 
@@ -329,6 +677,8 @@ static struct dvb_usb_device_properties ttusb2_properties_s2400 = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .streaming_ctrl   = NULL,
 
                        .frontend_attach  = ttusb2_frontend_tda10086_attach,
@@ -347,6 +697,7 @@ static struct dvb_usb_device_properties ttusb2_properties_s2400 = {
                                        }
                                }
                        }
+               }},
                }
        },
 
@@ -383,6 +734,27 @@ static struct dvb_usb_device_properties ttusb2_properties_ct3650 = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 2,
+               .fe = {{
+                       .streaming_ctrl   = NULL,
+
+                       .frontend_attach  = ttusb2_frontend_tda10023_attach,
+                       .tuner_attach = ttusb2_tuner_tda827x_attach,
+
+                       /* parameter for the MPEG2-data transfer */
+                       .stream = {
+                               .type = USB_ISOC,
+                               .count = 5,
+                               .endpoint = 0x02,
+                               .u = {
+                                       .isoc = {
+                                               .framesperurb = 4,
+                                               .framesize = 940,
+                                               .interval = 1,
+                                       }
+                               }
+                       }
+               }, {
                        .streaming_ctrl   = NULL,
 
                        .frontend_attach  = ttusb2_frontend_tda10023_attach,
@@ -401,6 +773,7 @@ static struct dvb_usb_device_properties ttusb2_properties_ct3650 = {
                                        }
                                }
                        }
+               }},
                },
        },
 
@@ -422,7 +795,7 @@ static struct dvb_usb_device_properties ttusb2_properties_ct3650 = {
 static struct usb_driver ttusb2_driver = {
        .name           = "dvb_usb_ttusb2",
        .probe          = ttusb2_probe,
-       .disconnect = dvb_usb_device_exit,
+       .disconnect     = ttusb2_usb_disconnect,
        .id_table       = ttusb2_table,
 };
 
index 118aab1a3e540943e7a325f5836999e4c4819d5f..463673a5c2b28cc4a8bb49a533fe127b86c0d929 100644 (file)
@@ -60,14 +60,14 @@ static int umt_mt352_frontend_attach(struct dvb_usb_adapter *adap)
        umt_config.demod_init = umt_mt352_demod_init;
        umt_config.demod_address = 0xf;
 
-       adap->fe = dvb_attach(mt352_attach, &umt_config, &adap->dev->i2c_adap);
+       adap->fe_adap[0].fe = dvb_attach(mt352_attach, &umt_config, &adap->dev->i2c_adap);
 
        return 0;
 }
 
 static int umt_tuner_attach (struct dvb_usb_adapter *adap)
 {
-       dvb_attach(dvb_pll_attach, adap->fe, 0x61, NULL, DVB_PLL_TUA6034);
+       dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x61, NULL, DVB_PLL_TUA6034);
        return 0;
 }
 
@@ -100,6 +100,8 @@ static struct dvb_usb_device_properties umt_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .streaming_ctrl   = dibusb2_0_streaming_ctrl,
                        .frontend_attach  = umt_mt352_frontend_attach,
                        .tuner_attach     = umt_tuner_attach,
@@ -115,7 +117,7 @@ static struct dvb_usb_device_properties umt_properties = {
                                        }
                                }
                        },
-
+               }},
                        .size_of_priv     = sizeof(struct dibusb_state),
                }
        },
index 86d68933b6b459a44cc557cba2e0aecd0a66ef47..d62ee0f5a1658d64cf165ba1a9fe6dde2a34774a 100644 (file)
@@ -148,7 +148,7 @@ static int usb_bulk_urb_init(struct usb_data_stream *stream)
                if (!stream->urb_list[i]) {
                        deb_mem("not enough memory for urb_alloc_urb!.\n");
                        for (j = 0; j < i; j++)
-                               usb_free_urb(stream->urb_list[i]);
+                               usb_free_urb(stream->urb_list[j]);
                        return -ENOMEM;
                }
                usb_fill_bulk_urb( stream->urb_list[i], stream->udev,
@@ -181,7 +181,7 @@ static int usb_isoc_urb_init(struct usb_data_stream *stream)
                if (!stream->urb_list[i]) {
                        deb_mem("not enough memory for urb_alloc_urb!\n");
                        for (j = 0; j < i; j++)
-                               usb_free_urb(stream->urb_list[i]);
+                               usb_free_urb(stream->urb_list[j]);
                        return -ENOMEM;
                }
 
index 54355f84a98fbee14bcadc89d7ad4fb61bae6a67..45e31f224814dfae6ed88491f53a8c4e1904e2a5 100644 (file)
@@ -320,7 +320,7 @@ static int vp702x_frontend_attach(struct dvb_usb_adapter *adap)
 
        vp702x_init_pid_filter(adap);
 
-       adap->fe = vp702x_fe_attach(adap->dev);
+       adap->fe_adap[0].fe = vp702x_fe_attach(adap->dev);
        vp702x_usb_out_op(adap->dev, SET_TUNER_POWER_REQ, 1, 7, NULL, 0);
 
        return 0;
@@ -383,6 +383,8 @@ static struct dvb_usb_device_properties vp702x_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .caps             = DVB_USB_ADAP_RECEIVES_204_BYTE_TS,
 
                        .streaming_ctrl   = vp702x_streaming_ctrl,
@@ -399,6 +401,7 @@ static struct dvb_usb_device_properties vp702x_properties = {
                                        }
                                }
                        },
+               }},
                        .size_of_priv     = sizeof(struct vp702x_adapter_state),
                }
        },
index 536c16c943bd7450874b6fc0ab67983f4015742b..90873af5682e93ff302f0e84ce4bc37102d5b236 100644 (file)
@@ -214,7 +214,7 @@ static int vp7045_frontend_attach(struct dvb_usb_adapter *adap)
 /*     Dump the EEPROM */
 /*     vp7045_read_eeprom(d,buf, 255, FX2_ID_ADDR); */
 
-       adap->fe = vp7045_fe_attach(adap->dev);
+       adap->fe_adap[0].fe = vp7045_fe_attach(adap->dev);
 
        return 0;
 }
@@ -245,6 +245,8 @@ static struct dvb_usb_device_properties vp7045_properties = {
        .num_adapters = 1,
        .adapter = {
                {
+               .num_frontends = 1,
+               .fe = {{
                        .frontend_attach  = vp7045_frontend_attach,
                        /* parameter for the MPEG2-data transfer */
                        .stream = {
@@ -257,6 +259,7 @@ static struct dvb_usb_device_properties vp7045_properties = {
                                        }
                                }
                        },
+               }},
                }
        },
        .power_ctrl       = vp7045_power_ctrl,
index 32e08e35152525386b2b8c48ac9422b23913c59f..4a2d2e6c91ab9f78f17715234cc4961a3397becd 100644 (file)
@@ -236,6 +236,13 @@ config DVB_MB86A16
          A DVB-S/DSS Direct Conversion reveiver.
          Say Y when you want to support this frontend.
 
+config DVB_TDA10071
+       tristate "NXP TDA10071"
+       depends on DVB_CORE && I2C
+       default m if DVB_FE_CUSTOMISE
+       help
+         Say Y when you want to support this frontend.
+
 comment "DVB-T (terrestrial) frontends"
        depends on DVB_CORE
 
@@ -600,6 +607,16 @@ config DVB_LNBP21
        help
          An SEC control chips.
 
+config DVB_LNBP22
+       tristate "LNBP22 SEC controllers"
+       depends on DVB_CORE && I2C
+       default m if DVB_FE_CUSTOMISE
+       help
+         LNB power supply and control voltage
+         regulator chip with step-up converter
+         and I2C interface.
+         Say Y when you want to support this chip.
+
 config DVB_ISL6405
        tristate "ISL6405 SEC controller"
        depends on DVB_CORE && I2C
@@ -621,6 +638,11 @@ config DVB_ISL6423
        help
          A SEC controller chip from Intersil
 
+config DVB_A8293
+       tristate "Allegro A8293"
+       depends on DVB_CORE && I2C
+       default m if DVB_FE_CUSTOMISE
+
 config DVB_LGS8GL5
        tristate "Silicon Legend LGS-8GL5 demodulator (OFDM)"
        depends on DVB_CORE && I2C
@@ -661,6 +683,14 @@ config DVB_IX2505V
        help
          A DVB-S tuner module. Say Y when you want to support this frontend.
 
+config DVB_IT913X_FE
+       tristate "it913x frontend and it9137 tuner"
+       depends on DVB_CORE && I2C
+       default m if DVB_FE_CUSTOMISE
+       help
+         A DVB-T tuner module.
+         Say Y when you want to support this frontend.
+
 comment "Tools to develop new frontends"
 
 config DVB_DUMMY_FE
index 6a6ba053ead4692eee52a9376e127f94c433ff7f..f639f67815515d40c8ff51b3a41a2ec52c456760 100644 (file)
@@ -2,8 +2,8 @@
 # Makefile for the kernel DVB frontend device drivers.
 #
 
-EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/
-EXTRA_CFLAGS += -Idrivers/media/common/tuners/
+ccflags-y += -Idrivers/media/dvb/dvb-core/
+ccflags-y += -Idrivers/media/common/tuners/
 
 stb0899-objs = stb0899_drv.o stb0899_algo.o
 stv0900-objs = stv0900_core.o stv0900_sw.o
@@ -52,6 +52,7 @@ obj-$(CONFIG_DVB_LGDT330X) += lgdt330x.o
 obj-$(CONFIG_DVB_LGDT3305) += lgdt3305.o
 obj-$(CONFIG_DVB_CX24123) += cx24123.o
 obj-$(CONFIG_DVB_LNBP21) += lnbp21.o
+obj-$(CONFIG_DVB_LNBP22) += lnbp22.o
 obj-$(CONFIG_DVB_ISL6405) += isl6405.o
 obj-$(CONFIG_DVB_ISL6421) += isl6421.o
 obj-$(CONFIG_DVB_TDA10086) += tda10086.o
@@ -91,4 +92,7 @@ obj-$(CONFIG_DVB_STV0367) += stv0367.o
 obj-$(CONFIG_DVB_CXD2820R) += cxd2820r.o
 obj-$(CONFIG_DVB_DRXK) += drxk.o
 obj-$(CONFIG_DVB_TDA18271C2DD) += tda18271c2dd.o
+obj-$(CONFIG_DVB_IT913X_FE) += it913x-fe.o
+obj-$(CONFIG_DVB_A8293) += a8293.o
+obj-$(CONFIG_DVB_TDA10071) += tda10071.o
 
diff --git a/drivers/media/dvb/frontends/a8293.c b/drivers/media/dvb/frontends/a8293.c
new file mode 100644 (file)
index 0000000..bb56497
--- /dev/null
@@ -0,0 +1,184 @@
+/*
+ * Allegro A8293 SEC driver
+ *
+ * Copyright (C) 2011 Antti Palosaari <crope@iki.fi>
+ *
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License along
+ *    with this program; if not, write to the Free Software Foundation, Inc.,
+ *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "dvb_frontend.h"
+#include "a8293.h"
+
+static int debug;
+module_param(debug, int, 0644);
+MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
+
+#define LOG_PREFIX "a8293"
+
+#undef dbg
+#define dbg(f, arg...) \
+       if (debug) \
+               printk(KERN_INFO   LOG_PREFIX": " f "\n" , ## arg)
+#undef err
+#define err(f, arg...)  printk(KERN_ERR     LOG_PREFIX": " f "\n" , ## arg)
+#undef info
+#define info(f, arg...) printk(KERN_INFO    LOG_PREFIX": " f "\n" , ## arg)
+#undef warn
+#define warn(f, arg...) printk(KERN_WARNING LOG_PREFIX": " f "\n" , ## arg)
+
+
+struct a8293_priv {
+       struct i2c_adapter *i2c;
+       const struct a8293_config *cfg;
+       u8 reg[2];
+};
+
+static int a8293_i2c(struct a8293_priv *priv, u8 *val, int len, bool rd)
+{
+       int ret;
+       struct i2c_msg msg[1] = {
+               {
+                       .addr = priv->cfg->i2c_addr,
+                       .len = len,
+                       .buf = val,
+               }
+       };
+
+       if (rd)
+               msg[0].flags = I2C_M_RD;
+       else
+               msg[0].flags = 0;
+
+       ret = i2c_transfer(priv->i2c, msg, 1);
+       if (ret == 1) {
+               ret = 0;
+       } else {
+               warn("i2c failed=%d rd=%d", ret, rd);
+               ret = -EREMOTEIO;
+       }
+
+       return ret;
+}
+
+static int a8293_wr(struct a8293_priv *priv, u8 *val, int len)
+{
+       return a8293_i2c(priv, val, len, 0);
+}
+
+static int a8293_rd(struct a8293_priv *priv, u8 *val, int len)
+{
+       return a8293_i2c(priv, val, len, 1);
+}
+
+static int a8293_set_voltage(struct dvb_frontend *fe,
+       fe_sec_voltage_t fe_sec_voltage)
+{
+       struct a8293_priv *priv = fe->sec_priv;
+       int ret;
+
+       dbg("%s: fe_sec_voltage=%d", __func__, fe_sec_voltage);
+
+       switch (fe_sec_voltage) {
+       case SEC_VOLTAGE_OFF:
+               /* ENB=0 */
+               priv->reg[0] = 0x10;
+               break;
+       case SEC_VOLTAGE_13:
+               /* VSEL0=1, VSEL1=0, VSEL2=0, VSEL3=0, ENB=1*/
+               priv->reg[0] = 0x31;
+               break;
+       case SEC_VOLTAGE_18:
+               /* VSEL0=0, VSEL1=0, VSEL2=0, VSEL3=1, ENB=1*/
+               priv->reg[0] = 0x38;
+               break;
+       default:
+               ret = -EINVAL;
+               goto err;
+       };
+
+       ret = a8293_wr(priv, &priv->reg[0], 1);
+       if (ret)
+               goto err;
+
+       return ret;
+err:
+       dbg("%s: failed=%d", __func__, ret);
+       return ret;
+}
+
+static void a8293_release_sec(struct dvb_frontend *fe)
+{
+       dbg("%s:", __func__);
+
+       a8293_set_voltage(fe, SEC_VOLTAGE_OFF);
+
+       kfree(fe->sec_priv);
+       fe->sec_priv = NULL;
+}
+
+struct dvb_frontend *a8293_attach(struct dvb_frontend *fe,
+       struct i2c_adapter *i2c, const struct a8293_config *cfg)
+{
+       int ret;
+       struct a8293_priv *priv = NULL;
+       u8 buf[2];
+
+       /* allocate memory for the internal priv */
+       priv = kzalloc(sizeof(struct a8293_priv), GFP_KERNEL);
+       if (priv == NULL) {
+               ret = -ENOMEM;
+               goto err;
+       }
+
+       /* setup the priv */
+       priv->i2c = i2c;
+       priv->cfg = cfg;
+       fe->sec_priv = priv;
+
+       /* check if the SEC is there */
+       ret = a8293_rd(priv, buf, 2);
+       if (ret)
+               goto err;
+
+       /* ENB=0 */
+       priv->reg[0] = 0x10;
+       ret = a8293_wr(priv, &priv->reg[1], 1);
+       if (ret)
+               goto err;
+
+       /* TMODE=0, TGATE=1 */
+       priv->reg[1] = 0x82;
+       ret = a8293_wr(priv, &priv->reg[1], 1);
+       if (ret)
+               goto err;
+
+       info("Allegro A8293 SEC attached.");
+
+       fe->ops.release_sec = a8293_release_sec;
+
+       /* override frontend ops */
+       fe->ops.set_voltage = a8293_set_voltage;
+
+       return fe;
+err:
+       dbg("%s: failed=%d", __func__, ret);
+       kfree(priv);
+       return NULL;
+}
+EXPORT_SYMBOL(a8293_attach);
+
+MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
+MODULE_DESCRIPTION("Allegro A8293 SEC driver");
+MODULE_LICENSE("GPL");
similarity index 58%
rename from drivers/media/common/tuners/tda18212_priv.h
rename to drivers/media/dvb/frontends/a8293.h
index 9adff9356b73d7c9bedd49a3dd86b4920ede0d8e..ed29e5504f765c8e349d7c7a8cde3295e4417a73 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * NXP TDA18212HN silicon tuner driver
+ * Allegro A8293 SEC driver
  *
  * Copyright (C) 2011 Antti Palosaari <crope@iki.fi>
  *
  *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#ifndef TDA18212_PRIV_H
-#define TDA18212_PRIV_H
+#ifndef A8293_H
+#define A8293_H
 
-#include "tda18212.h"
-
-#define LOG_PREFIX "tda18212"
-
-#undef dbg
-#define dbg(f, arg...) \
-       if (debug) \
-               printk(KERN_INFO   LOG_PREFIX": " f "\n" , ## arg)
-#undef err
-#define err(f, arg...)  printk(KERN_ERR     LOG_PREFIX": " f "\n" , ## arg)
-#undef info
-#define info(f, arg...) printk(KERN_INFO    LOG_PREFIX": " f "\n" , ## arg)
-#undef warn
-#define warn(f, arg...) printk(KERN_WARNING LOG_PREFIX": " f "\n" , ## arg)
-
-struct tda18212_priv {
-       struct tda18212_config *cfg;
-       struct i2c_adapter *i2c;
+struct a8293_config {
+       u8 i2c_addr;
 };
 
+#if defined(CONFIG_DVB_A8293) || \
+       (defined(CONFIG_DVB_A8293_MODULE) && defined(MODULE))
+extern struct dvb_frontend *a8293_attach(struct dvb_frontend *fe,
+       struct i2c_adapter *i2c, const struct a8293_config *cfg);
+#else
+static inline struct dvb_frontend *a8293_attach(struct dvb_frontend *fe,
+       struct i2c_adapter *i2c, const struct a8293_config *cfg)
+{
+       printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
+       return NULL;
+}
 #endif
+
+#endif /* A8293_H */
index 2906582dc94c20a5ed58460b4d4b3a59e0332e84..03cab7b547fbac253331206de193848acc8b93a0 100644 (file)
@@ -93,9 +93,6 @@ extern struct dvb_frontend *cxd2820r_attach(
        struct i2c_adapter *i2c,
        struct dvb_frontend *fe
 );
-extern struct i2c_adapter *cxd2820r_get_tuner_i2c_adapter(
-       struct dvb_frontend *fe
-);
 #else
 static inline struct dvb_frontend *cxd2820r_attach(
        const struct cxd2820r_config *config,
@@ -106,12 +103,6 @@ static inline struct dvb_frontend *cxd2820r_attach(
        printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
        return NULL;
 }
-static inline struct i2c_adapter *cxd2820r_get_tuner_i2c_adapter(
-       struct dvb_frontend *fe
-)
-{
-       return NULL;
-}
 
 #endif
 
index 3c07d400731d9f4337e06875d6d7136c43ab024d..b85f5011e344623fc3a03fbfb10d09d8df59a54f 100644 (file)
@@ -335,4 +335,3 @@ int cxd2820r_get_tune_settings_c(struct dvb_frontend *fe,
 
        return 0;
 }
-
index d416e85589e1150fe57c7b204a86b6c62ef8b6d2..036480f967b7b73c21a42004e17e1a8d2bc018ef 100644 (file)
@@ -727,72 +727,22 @@ static void cxd2820r_release(struct dvb_frontend *fe)
        struct cxd2820r_priv *priv = fe->demodulator_priv;
        dbg("%s", __func__);
 
-       if (fe->ops.info.type == FE_OFDM) {
-               i2c_del_adapter(&priv->tuner_i2c_adapter);
+       if (fe->ops.info.type == FE_OFDM)
                kfree(priv);
-       }
 
        return;
 }
 
-static u32 cxd2820r_tuner_i2c_func(struct i2c_adapter *adapter)
-{
-       return I2C_FUNC_I2C;
-}
-
-static int cxd2820r_tuner_i2c_xfer(struct i2c_adapter *i2c_adap,
-       struct i2c_msg msg[], int num)
-{
-       struct cxd2820r_priv *priv = i2c_get_adapdata(i2c_adap);
-       int ret;
-       u8 *obuf = kmalloc(msg[0].len + 2, GFP_KERNEL);
-       struct i2c_msg msg2[2] = {
-               {
-                       .addr = priv->cfg.i2c_address,
-                       .flags = 0,
-                       .len = msg[0].len + 2,
-                       .buf = obuf,
-               }, {
-                       .addr = priv->cfg.i2c_address,
-                       .flags = I2C_M_RD,
-                       .len = msg[1].len,
-                       .buf = msg[1].buf,
-               }
-       };
-
-       if (!obuf)
-               return -ENOMEM;
-
-       obuf[0] = 0x09;
-       obuf[1] = (msg[0].addr << 1);
-       if (num == 2) { /* I2C read */
-               obuf[1] = (msg[0].addr << 1) | I2C_M_RD; /* I2C RD flag */
-               msg2[0].len = msg[0].len + 2 - 1; /* '-1' maybe HW bug ? */
-       }
-       memcpy(&obuf[2], msg[0].buf, msg[0].len);
-
-       ret = i2c_transfer(priv->i2c, msg2, num);
-       if (ret < 0)
-               warn("tuner i2c failed ret:%d", ret);
-
-       kfree(obuf);
-
-       return ret;
-}
-
-static struct i2c_algorithm cxd2820r_tuner_i2c_algo = {
-       .master_xfer   = cxd2820r_tuner_i2c_xfer,
-       .functionality = cxd2820r_tuner_i2c_func,
-};
-
-struct i2c_adapter *cxd2820r_get_tuner_i2c_adapter(struct dvb_frontend *fe)
+static int cxd2820r_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
 {
        struct cxd2820r_priv *priv = fe->demodulator_priv;
-       return &priv->tuner_i2c_adapter;
+       dbg("%s: %d", __func__, enable);
+
+       /* Bit 0 of reg 0xdb in bank 0x00 controls I2C repeater */
+       return cxd2820r_wr_reg_mask(priv, 0xdb, enable ? 1 : 0, 0x1);
 }
-EXPORT_SYMBOL(cxd2820r_get_tuner_i2c_adapter);
 
-static struct dvb_frontend_ops cxd2820r_ops[2];
+static const struct dvb_frontend_ops cxd2820r_ops[2];
 
 struct dvb_frontend *cxd2820r_attach(const struct cxd2820r_config *cfg,
        struct i2c_adapter *i2c, struct dvb_frontend *fe)
@@ -831,18 +781,6 @@ struct dvb_frontend *cxd2820r_attach(const struct cxd2820r_config *cfg,
                priv->fe[0].demodulator_priv = priv;
                priv->fe[1].demodulator_priv = priv;
 
-               /* create tuner i2c adapter */
-               strlcpy(priv->tuner_i2c_adapter.name,
-                       "CXD2820R tuner I2C adapter",
-                       sizeof(priv->tuner_i2c_adapter.name));
-               priv->tuner_i2c_adapter.algo = &cxd2820r_tuner_i2c_algo;
-               priv->tuner_i2c_adapter.algo_data = NULL;
-               i2c_set_adapdata(&priv->tuner_i2c_adapter, priv);
-               if (i2c_add_adapter(&priv->tuner_i2c_adapter) < 0) {
-                       err("tuner I2C bus could not be initialized");
-                       goto error;
-               }
-
                return &priv->fe[0];
 
        } else {
@@ -858,7 +796,7 @@ error:
 }
 EXPORT_SYMBOL(cxd2820r_attach);
 
-static struct dvb_frontend_ops cxd2820r_ops[2] = {
+static const struct dvb_frontend_ops cxd2820r_ops[2] = {
        {
                /* DVB-T/T2 */
                .info = {
@@ -883,6 +821,7 @@ static struct dvb_frontend_ops cxd2820r_ops[2] = {
                .sleep = cxd2820r_sleep,
 
                .get_tune_settings = cxd2820r_get_tune_settings,
+               .i2c_gate_ctrl = cxd2820r_i2c_gate_ctrl,
 
                .get_frontend = cxd2820r_get_frontend,
 
@@ -911,6 +850,7 @@ static struct dvb_frontend_ops cxd2820r_ops[2] = {
                .sleep = cxd2820r_sleep,
 
                .get_tune_settings = cxd2820r_get_tune_settings,
+               .i2c_gate_ctrl = cxd2820r_i2c_gate_ctrl,
 
                .set_frontend = cxd2820r_set_frontend,
                .get_frontend = cxd2820r_get_frontend,
index 0c0ebc9d5c4ac0ca7a051fa0c64b55dc23d6aa70..95539134efdb796c911543b908a37390e6eb2121 100644 (file)
@@ -50,7 +50,6 @@ struct cxd2820r_priv {
        struct i2c_adapter *i2c;
        struct dvb_frontend fe[2];
        struct cxd2820r_config cfg;
-       struct i2c_adapter tuner_i2c_adapter;
 
        struct mutex fe_lock; /* FE lock */
        int active_fe:2; /* FE lock, -1=NONE, 0=DVB-T/T2, 1=DVB-C */
index 6582564c930cb30fb37b28ebc8b9da79e3cc56af..a04f9c810101652138b2685973c1969d3cdf9c31 100644 (file)
@@ -446,4 +446,3 @@ int cxd2820r_get_tune_settings_t(struct dvb_frontend *fe,
 
        return 0;
 }
-
index c47b35c8acf13caf0dfdcd6d7b4c77c88f9ae5de..6548588309f7986ffc347e7c2915cc30fef0ec9c 100644 (file)
@@ -420,4 +420,3 @@ int cxd2820r_get_tune_settings_t2(struct dvb_frontend *fe,
 
        return 0;
 }
-
index 1d47d4da7d4c4222373e8e89f55cd4fd1cd36e5e..dc1cb17a6ea716993fe5e31c187bcd1f41881838 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/i2c.h>
+#include <linux/mutex.h>
 
 #include "dvb_frontend.h"
 
@@ -78,10 +79,18 @@ struct dib0070_state {
        struct i2c_msg msg[2];
        u8 i2c_write_buffer[3];
        u8 i2c_read_buffer[2];
+       struct mutex i2c_buffer_lock;
 };
 
-static uint16_t dib0070_read_reg(struct dib0070_state *state, u8 reg)
+static u16 dib0070_read_reg(struct dib0070_state *state, u8 reg)
 {
+       u16 ret;
+
+       if (mutex_lock_interruptible(&state->i2c_buffer_lock) < 0) {
+               dprintk("could not acquire lock");
+               return 0;
+       }
+
        state->i2c_write_buffer[0] = reg;
 
        memset(state->msg, 0, 2 * sizeof(struct i2c_msg));
@@ -96,13 +105,23 @@ static uint16_t dib0070_read_reg(struct dib0070_state *state, u8 reg)
 
        if (i2c_transfer(state->i2c, state->msg, 2) != 2) {
                printk(KERN_WARNING "DiB0070 I2C read failed\n");
-               return 0;
-       }
-       return (state->i2c_read_buffer[0] << 8) | state->i2c_read_buffer[1];
+               ret = 0;
+       } else
+               ret = (state->i2c_read_buffer[0] << 8)
+                       | state->i2c_read_buffer[1];
+
+       mutex_unlock(&state->i2c_buffer_lock);
+       return ret;
 }
 
 static int dib0070_write_reg(struct dib0070_state *state, u8 reg, u16 val)
 {
+       int ret;
+
+       if (mutex_lock_interruptible(&state->i2c_buffer_lock) < 0) {
+               dprintk("could not acquire lock");
+               return -EINVAL;
+       }
        state->i2c_write_buffer[0] = reg;
        state->i2c_write_buffer[1] = val >> 8;
        state->i2c_write_buffer[2] = val & 0xff;
@@ -115,9 +134,12 @@ static int dib0070_write_reg(struct dib0070_state *state, u8 reg, u16 val)
 
        if (i2c_transfer(state->i2c, state->msg, 1) != 1) {
                printk(KERN_WARNING "DiB0070 I2C write failed\n");
-               return -EREMOTEIO;
-       }
-       return 0;
+               ret = -EREMOTEIO;
+       } else
+               ret = 0;
+
+       mutex_unlock(&state->i2c_buffer_lock);
+       return ret;
 }
 
 #define HARD_RESET(state) do { \
@@ -734,6 +756,7 @@ struct dvb_frontend *dib0070_attach(struct dvb_frontend *fe, struct i2c_adapter
        state->cfg = cfg;
        state->i2c = i2c;
        state->fe  = fe;
+       mutex_init(&state->i2c_buffer_lock);
        fe->tuner_priv = state;
 
        if (dib0070_reset(fe) != 0)
index c9c935ae41e47bf9eaccb4f6e9df0ef0701b6e18..b174d1c78583ee1001b8892626c80b00450f25fa 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/i2c.h>
+#include <linux/mutex.h>
 
 #include "dvb_frontend.h"
 
@@ -196,6 +197,7 @@ struct dib0090_state {
        struct i2c_msg msg[2];
        u8 i2c_write_buffer[3];
        u8 i2c_read_buffer[2];
+       struct mutex i2c_buffer_lock;
 };
 
 struct dib0090_fw_state {
@@ -208,10 +210,18 @@ struct dib0090_fw_state {
        struct i2c_msg msg;
        u8 i2c_write_buffer[2];
        u8 i2c_read_buffer[2];
+       struct mutex i2c_buffer_lock;
 };
 
 static u16 dib0090_read_reg(struct dib0090_state *state, u8 reg)
 {
+       u16 ret;
+
+       if (mutex_lock_interruptible(&state->i2c_buffer_lock) < 0) {
+               dprintk("could not acquire lock");
+               return 0;
+       }
+
        state->i2c_write_buffer[0] = reg;
 
        memset(state->msg, 0, 2 * sizeof(struct i2c_msg));
@@ -226,14 +236,24 @@ static u16 dib0090_read_reg(struct dib0090_state *state, u8 reg)
 
        if (i2c_transfer(state->i2c, state->msg, 2) != 2) {
                printk(KERN_WARNING "DiB0090 I2C read failed\n");
-               return 0;
-       }
+               ret = 0;
+       } else
+               ret = (state->i2c_read_buffer[0] << 8)
+                       | state->i2c_read_buffer[1];
 
-       return (state->i2c_read_buffer[0] << 8) | state->i2c_read_buffer[1];
+       mutex_unlock(&state->i2c_buffer_lock);
+       return ret;
 }
 
 static int dib0090_write_reg(struct dib0090_state *state, u32 reg, u16 val)
 {
+       int ret;
+
+       if (mutex_lock_interruptible(&state->i2c_buffer_lock) < 0) {
+               dprintk("could not acquire lock");
+               return -EINVAL;
+       }
+
        state->i2c_write_buffer[0] = reg & 0xff;
        state->i2c_write_buffer[1] = val >> 8;
        state->i2c_write_buffer[2] = val & 0xff;
@@ -246,13 +266,23 @@ static int dib0090_write_reg(struct dib0090_state *state, u32 reg, u16 val)
 
        if (i2c_transfer(state->i2c, state->msg, 1) != 1) {
                printk(KERN_WARNING "DiB0090 I2C write failed\n");
-               return -EREMOTEIO;
-       }
-       return 0;
+               ret = -EREMOTEIO;
+       } else
+               ret = 0;
+
+       mutex_unlock(&state->i2c_buffer_lock);
+       return ret;
 }
 
 static u16 dib0090_fw_read_reg(struct dib0090_fw_state *state, u8 reg)
 {
+       u16 ret;
+
+       if (mutex_lock_interruptible(&state->i2c_buffer_lock) < 0) {
+               dprintk("could not acquire lock");
+               return 0;
+       }
+
        state->i2c_write_buffer[0] = reg;
 
        memset(&state->msg, 0, sizeof(struct i2c_msg));
@@ -262,13 +292,24 @@ static u16 dib0090_fw_read_reg(struct dib0090_fw_state *state, u8 reg)
        state->msg.len = 2;
        if (i2c_transfer(state->i2c, &state->msg, 1) != 1) {
                printk(KERN_WARNING "DiB0090 I2C read failed\n");
-               return 0;
-       }
-       return (state->i2c_read_buffer[0] << 8) | state->i2c_read_buffer[1];
+               ret = 0;
+       } else
+               ret = (state->i2c_read_buffer[0] << 8)
+                       | state->i2c_read_buffer[1];
+
+       mutex_unlock(&state->i2c_buffer_lock);
+       return ret;
 }
 
 static int dib0090_fw_write_reg(struct dib0090_fw_state *state, u8 reg, u16 val)
 {
+       int ret;
+
+       if (mutex_lock_interruptible(&state->i2c_buffer_lock) < 0) {
+               dprintk("could not acquire lock");
+               return -EINVAL;
+       }
+
        state->i2c_write_buffer[0] = val >> 8;
        state->i2c_write_buffer[1] = val & 0xff;
 
@@ -279,9 +320,12 @@ static int dib0090_fw_write_reg(struct dib0090_fw_state *state, u8 reg, u16 val)
        state->msg.len = 2;
        if (i2c_transfer(state->i2c, &state->msg, 1) != 1) {
                printk(KERN_WARNING "DiB0090 I2C write failed\n");
-               return -EREMOTEIO;
-       }
-       return 0;
+               ret = -EREMOTEIO;
+       } else
+               ret = 0;
+
+       mutex_unlock(&state->i2c_buffer_lock);
+       return ret;
 }
 
 #define HARD_RESET(state) do {  if (cfg->reset) {  if (cfg->sleep) cfg->sleep(fe, 0); msleep(10);  cfg->reset(fe, 1); msleep(10);  cfg->reset(fe, 0); msleep(10);  }  } while (0)
@@ -2440,6 +2484,7 @@ struct dvb_frontend *dib0090_register(struct dvb_frontend *fe, struct i2c_adapte
        st->config = config;
        st->i2c = i2c;
        st->fe = fe;
+       mutex_init(&st->i2c_buffer_lock);
        fe->tuner_priv = st;
 
        if (config->wbd == NULL)
@@ -2471,6 +2516,7 @@ struct dvb_frontend *dib0090_fw_register(struct dvb_frontend *fe, struct i2c_ada
        st->config = config;
        st->i2c = i2c;
        st->fe = fe;
+       mutex_init(&st->i2c_buffer_lock);
        fe->tuner_priv = st;
 
        if (dib0090_fw_reset_digital(fe, st->config) != 0)
index 79cb1c20df24e7aece91b3f7e900efb7e13d1c57..dbb76d75c932fecb36784a62be7451a3d63fb4c8 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/i2c.h>
+#include <linux/mutex.h>
 
 #include "dvb_frontend.h"
 
@@ -55,6 +56,7 @@ struct dib7000m_state {
        struct i2c_msg msg[2];
        u8 i2c_write_buffer[4];
        u8 i2c_read_buffer[2];
+       struct mutex i2c_buffer_lock;
 };
 
 enum dib7000m_power_mode {
@@ -69,6 +71,13 @@ enum dib7000m_power_mode {
 
 static u16 dib7000m_read_word(struct dib7000m_state *state, u16 reg)
 {
+       u16 ret;
+
+       if (mutex_lock_interruptible(&state->i2c_buffer_lock) < 0) {
+               dprintk("could not acquire lock");
+               return 0;
+       }
+
        state->i2c_write_buffer[0] = (reg >> 8) | 0x80;
        state->i2c_write_buffer[1] = reg & 0xff;
 
@@ -85,11 +94,21 @@ static u16 dib7000m_read_word(struct dib7000m_state *state, u16 reg)
        if (i2c_transfer(state->i2c_adap, state->msg, 2) != 2)
                dprintk("i2c read error on %d",reg);
 
-       return (state->i2c_read_buffer[0] << 8) | state->i2c_read_buffer[1];
+       ret = (state->i2c_read_buffer[0] << 8) | state->i2c_read_buffer[1];
+       mutex_unlock(&state->i2c_buffer_lock);
+
+       return ret;
 }
 
 static int dib7000m_write_word(struct dib7000m_state *state, u16 reg, u16 val)
 {
+       int ret;
+
+       if (mutex_lock_interruptible(&state->i2c_buffer_lock) < 0) {
+               dprintk("could not acquire lock");
+               return -EINVAL;
+       }
+
        state->i2c_write_buffer[0] = (reg >> 8) & 0xff;
        state->i2c_write_buffer[1] = reg & 0xff;
        state->i2c_write_buffer[2] = (val >> 8) & 0xff;
@@ -101,7 +120,10 @@ static int dib7000m_write_word(struct dib7000m_state *state, u16 reg, u16 val)
        state->msg[0].buf = state->i2c_write_buffer;
        state->msg[0].len = 4;
 
-       return i2c_transfer(state->i2c_adap, state->msg, 1) != 1 ? -EREMOTEIO : 0;
+       ret = (i2c_transfer(state->i2c_adap, state->msg, 1) != 1 ?
+                       -EREMOTEIO : 0);
+       mutex_unlock(&state->i2c_buffer_lock);
+       return ret;
 }
 static void dib7000m_write_tab(struct dib7000m_state *state, u16 *buf)
 {
@@ -1385,6 +1407,7 @@ struct dvb_frontend * dib7000m_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr,
        demod                   = &st->demod;
        demod->demodulator_priv = st;
        memcpy(&st->demod.ops, &dib7000m_ops, sizeof(struct dvb_frontend_ops));
+       mutex_init(&st->i2c_buffer_lock);
 
        st->timf_default = cfg->bw->timf;
 
index a64a538ba36439b5723650905f434d8fba8ae58b..ce8534ff142efe448de4cf2b7f325edc74fadaab 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/i2c.h>
+#include <linux/mutex.h>
 
 #include "dvb_math.h"
 #include "dvb_frontend.h"
@@ -68,6 +69,7 @@ struct dib7000p_state {
        struct i2c_msg msg[2];
        u8 i2c_write_buffer[4];
        u8 i2c_read_buffer[2];
+       struct mutex i2c_buffer_lock;
 };
 
 enum dib7000p_power_mode {
@@ -81,6 +83,13 @@ static int dib7090_set_diversity_in(struct dvb_frontend *fe, int onoff);
 
 static u16 dib7000p_read_word(struct dib7000p_state *state, u16 reg)
 {
+       u16 ret;
+
+       if (mutex_lock_interruptible(&state->i2c_buffer_lock) < 0) {
+               dprintk("could not acquire lock");
+               return 0;
+       }
+
        state->i2c_write_buffer[0] = reg >> 8;
        state->i2c_write_buffer[1] = reg & 0xff;
 
@@ -97,11 +106,20 @@ static u16 dib7000p_read_word(struct dib7000p_state *state, u16 reg)
        if (i2c_transfer(state->i2c_adap, state->msg, 2) != 2)
                dprintk("i2c read error on %d", reg);
 
-       return (state->i2c_read_buffer[0] << 8) | state->i2c_read_buffer[1];
+       ret = (state->i2c_read_buffer[0] << 8) | state->i2c_read_buffer[1];
+       mutex_unlock(&state->i2c_buffer_lock);
+       return ret;
 }
 
 static int dib7000p_write_word(struct dib7000p_state *state, u16 reg, u16 val)
 {
+       int ret;
+
+       if (mutex_lock_interruptible(&state->i2c_buffer_lock) < 0) {
+               dprintk("could not acquire lock");
+               return -EINVAL;
+       }
+
        state->i2c_write_buffer[0] = (reg >> 8) & 0xff;
        state->i2c_write_buffer[1] = reg & 0xff;
        state->i2c_write_buffer[2] = (val >> 8) & 0xff;
@@ -113,7 +131,10 @@ static int dib7000p_write_word(struct dib7000p_state *state, u16 reg, u16 val)
        state->msg[0].buf = state->i2c_write_buffer;
        state->msg[0].len = 4;
 
-       return i2c_transfer(state->i2c_adap, state->msg, 1) != 1 ? -EREMOTEIO : 0;
+       ret = (i2c_transfer(state->i2c_adap, state->msg, 1) != 1 ?
+                       -EREMOTEIO : 0);
+       mutex_unlock(&state->i2c_buffer_lock);
+       return ret;
 }
 
 static void dib7000p_write_tab(struct dib7000p_state *state, u16 * buf)
@@ -1577,8 +1598,8 @@ int dib7000pc_detection(struct i2c_adapter *i2c_adap)
                return -ENOMEM;
        rx = kzalloc(2*sizeof(u8), GFP_KERNEL);
        if (!rx) {
-               goto rx_memory_error;
                ret = -ENOMEM;
+               goto rx_memory_error;
        }
 
        msg[0].buf = tx;
@@ -1646,6 +1667,7 @@ int dib7000p_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 defau
                return -ENOMEM;
 
        dpst->i2c_adap = i2c;
+       mutex_init(&dpst->i2c_buffer_lock);
 
        for (k = no_of_demods - 1; k >= 0; k--) {
                dpst->cfg = cfg[k];
@@ -2324,6 +2346,7 @@ struct dvb_frontend *dib7000p_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr,
        demod = &st->demod;
        demod->demodulator_priv = st;
        memcpy(&st->demod.ops, &dib7000p_ops, sizeof(struct dvb_frontend_ops));
+       mutex_init(&st->i2c_buffer_lock);
 
        dib7000p_write_word(st, 1287, 0x0003);  /* sram lead in, rdy */
 
@@ -2333,8 +2356,9 @@ struct dvb_frontend *dib7000p_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr,
        st->version = dib7000p_read_word(st, 897);
 
        /* FIXME: make sure the dev.parent field is initialized, or else
-               request_firmware() will hit an OOPS (this should be moved somewhere
-               more common) */
+          request_firmware() will hit an OOPS (this should be moved somewhere
+          more common) */
+       st->i2c_master.gated_tuner_i2c_adap.dev.parent = i2c_adap->dev.parent;
 
        /* FIXME: make sure the dev.parent field is initialized, or else
           request_firmware() will hit an OOPS (this should be moved somewhere
index 7d2ea112ae2bf9217363f3f0172a81d6340b3f0f..fe284d5292f5422f16a846e1077c7df34c576098 100644 (file)
@@ -10,6 +10,8 @@
 #include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/i2c.h>
+#include <linux/mutex.h>
+
 #include "dvb_math.h"
 
 #include "dvb_frontend.h"
@@ -37,6 +39,7 @@ struct i2c_device {
        u8 addr;
        u8 *i2c_write_buffer;
        u8 *i2c_read_buffer;
+       struct mutex *i2c_buffer_lock;
 };
 
 struct dib8000_state {
@@ -77,6 +80,7 @@ struct dib8000_state {
        struct i2c_msg msg[2];
        u8 i2c_write_buffer[4];
        u8 i2c_read_buffer[2];
+       struct mutex i2c_buffer_lock;
 };
 
 enum dib8000_power_mode {
@@ -86,24 +90,39 @@ enum dib8000_power_mode {
 
 static u16 dib8000_i2c_read16(struct i2c_device *i2c, u16 reg)
 {
+       u16 ret;
        struct i2c_msg msg[2] = {
-               {.addr = i2c->addr >> 1, .flags = 0,
-                       .buf = i2c->i2c_write_buffer, .len = 2},
-               {.addr = i2c->addr >> 1, .flags = I2C_M_RD,
-                       .buf = i2c->i2c_read_buffer, .len = 2},
+               {.addr = i2c->addr >> 1, .flags = 0, .len = 2},
+               {.addr = i2c->addr >> 1, .flags = I2C_M_RD, .len = 2},
        };
 
+       if (mutex_lock_interruptible(i2c->i2c_buffer_lock) < 0) {
+               dprintk("could not acquire lock");
+               return 0;
+       }
+
+       msg[0].buf    = i2c->i2c_write_buffer;
        msg[0].buf[0] = reg >> 8;
        msg[0].buf[1] = reg & 0xff;
+       msg[1].buf    = i2c->i2c_read_buffer;
 
        if (i2c_transfer(i2c->adap, msg, 2) != 2)
                dprintk("i2c read error on %d", reg);
 
-       return (msg[1].buf[0] << 8) | msg[1].buf[1];
+       ret = (msg[1].buf[0] << 8) | msg[1].buf[1];
+       mutex_unlock(i2c->i2c_buffer_lock);
+       return ret;
 }
 
 static u16 dib8000_read_word(struct dib8000_state *state, u16 reg)
 {
+       u16 ret;
+
+       if (mutex_lock_interruptible(&state->i2c_buffer_lock) < 0) {
+               dprintk("could not acquire lock");
+               return 0;
+       }
+
        state->i2c_write_buffer[0] = reg >> 8;
        state->i2c_write_buffer[1] = reg & 0xff;
 
@@ -120,7 +139,10 @@ static u16 dib8000_read_word(struct dib8000_state *state, u16 reg)
        if (i2c_transfer(state->i2c.adap, state->msg, 2) != 2)
                dprintk("i2c read error on %d", reg);
 
-       return (state->i2c_read_buffer[0] << 8) | state->i2c_read_buffer[1];
+       ret = (state->i2c_read_buffer[0] << 8) | state->i2c_read_buffer[1];
+       mutex_unlock(&state->i2c_buffer_lock);
+
+       return ret;
 }
 
 static u32 dib8000_read32(struct dib8000_state *state, u16 reg)
@@ -135,22 +157,35 @@ static u32 dib8000_read32(struct dib8000_state *state, u16 reg)
 
 static int dib8000_i2c_write16(struct i2c_device *i2c, u16 reg, u16 val)
 {
-       struct i2c_msg msg = {.addr = i2c->addr >> 1, .flags = 0,
-               .buf = i2c->i2c_write_buffer, .len = 4};
+       struct i2c_msg msg = {.addr = i2c->addr >> 1, .flags = 0, .len = 4};
        int ret = 0;
 
+       if (mutex_lock_interruptible(i2c->i2c_buffer_lock) < 0) {
+               dprintk("could not acquire lock");
+               return -EINVAL;
+       }
+
+       msg.buf    = i2c->i2c_write_buffer;
        msg.buf[0] = (reg >> 8) & 0xff;
        msg.buf[1] = reg & 0xff;
        msg.buf[2] = (val >> 8) & 0xff;
        msg.buf[3] = val & 0xff;
 
        ret = i2c_transfer(i2c->adap, &msg, 1) != 1 ? -EREMOTEIO : 0;
+       mutex_unlock(i2c->i2c_buffer_lock);
 
        return ret;
 }
 
 static int dib8000_write_word(struct dib8000_state *state, u16 reg, u16 val)
 {
+       int ret;
+
+       if (mutex_lock_interruptible(&state->i2c_buffer_lock) < 0) {
+               dprintk("could not acquire lock");
+               return -EINVAL;
+       }
+
        state->i2c_write_buffer[0] = (reg >> 8) & 0xff;
        state->i2c_write_buffer[1] = reg & 0xff;
        state->i2c_write_buffer[2] = (val >> 8) & 0xff;
@@ -162,7 +197,11 @@ static int dib8000_write_word(struct dib8000_state *state, u16 reg, u16 val)
        state->msg[0].buf = state->i2c_write_buffer;
        state->msg[0].len = 4;
 
-       return i2c_transfer(state->i2c.adap, state->msg, 1) != 1 ? -EREMOTEIO : 0;
+       ret = (i2c_transfer(state->i2c.adap, state->msg, 1) != 1 ?
+                       -EREMOTEIO : 0);
+       mutex_unlock(&state->i2c_buffer_lock);
+
+       return ret;
 }
 
 static const s16 coeff_2k_sb_1seg_dqpsk[8] = {
@@ -2434,8 +2473,15 @@ int dib8000_i2c_enumeration(struct i2c_adapter *host, int no_of_demods, u8 defau
        if (!client.i2c_read_buffer) {
                dprintk("%s: not enough memory", __func__);
                ret = -ENOMEM;
-               goto error_memory;
+               goto error_memory_read;
+       }
+       client.i2c_buffer_lock = kzalloc(sizeof(struct mutex), GFP_KERNEL);
+       if (!client.i2c_buffer_lock) {
+               dprintk("%s: not enough memory", __func__);
+               ret = -ENOMEM;
+               goto error_memory_lock;
        }
+       mutex_init(client.i2c_buffer_lock);
 
        for (k = no_of_demods - 1; k >= 0; k--) {
                /* designated i2c address */
@@ -2476,8 +2522,10 @@ int dib8000_i2c_enumeration(struct i2c_adapter *host, int no_of_demods, u8 defau
        }
 
 error:
+       kfree(client.i2c_buffer_lock);
+error_memory_lock:
        kfree(client.i2c_read_buffer);
-error_memory:
+error_memory_read:
        kfree(client.i2c_write_buffer);
 
        return ret;
@@ -2581,6 +2629,8 @@ struct dvb_frontend *dib8000_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, s
        state->i2c.addr = i2c_addr;
        state->i2c.i2c_write_buffer = state->i2c_write_buffer;
        state->i2c.i2c_read_buffer = state->i2c_read_buffer;
+       mutex_init(&state->i2c_buffer_lock);
+       state->i2c.i2c_buffer_lock = &state->i2c_buffer_lock;
        state->gpio_val = cfg->gpio_val;
        state->gpio_dir = cfg->gpio_dir;
 
index a0855883b5ce7afa6a97d4561b06ee5a55332b6f..660f80661ed48f5af1eb21c5e584e9d89f3a592f 100644 (file)
@@ -38,6 +38,15 @@ struct i2c_device {
 #define DibInitLock(lock) mutex_init(lock)
 #define DibFreeLock(lock)
 
+struct dib9000_pid_ctrl {
+#define DIB9000_PID_FILTER_CTRL 0
+#define DIB9000_PID_FILTER      1
+       u8 cmd;
+       u8 id;
+       u16 pid;
+       u8 onoff;
+};
+
 struct dib9000_state {
        struct i2c_device i2c;
 
@@ -99,6 +108,10 @@ struct dib9000_state {
        struct i2c_msg msg[2];
        u8 i2c_write_buffer[255];
        u8 i2c_read_buffer[255];
+       DIB_LOCK demod_lock;
+       u8 get_frontend_internal;
+       struct dib9000_pid_ctrl pid_ctrl[10];
+       s8 pid_ctrl_index; /* -1: empty list; -2: do not use the list */
 };
 
 static const u32 fe_info[44] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -1167,8 +1180,8 @@ static int dib9000_fw_get_channel(struct dvb_frontend *fe, struct dvb_frontend_p
 
        DibAcquireLock(&state->platform.risc.mem_mbx_lock);
        if (dib9000_fw_memmbx_sync(state, FE_SYNC_CHANNEL) < 0) {
-               goto error;
                ret = -EIO;
+               goto error;
        }
 
        dib9000_risc_mem_read(state, FE_MM_R_CHANNEL_UNION,
@@ -1743,19 +1756,56 @@ EXPORT_SYMBOL(dib9000_set_gpio);
 int dib9000_fw_pid_filter_ctrl(struct dvb_frontend *fe, u8 onoff)
 {
        struct dib9000_state *state = fe->demodulator_priv;
-       u16 val = dib9000_read_word(state, 294 + 1) & 0xffef;
+       u16 val;
+       int ret;
+
+       if ((state->pid_ctrl_index != -2) && (state->pid_ctrl_index < 9)) {
+               /* postpone the pid filtering cmd */
+               dprintk("pid filter cmd postpone");
+               state->pid_ctrl_index++;
+               state->pid_ctrl[state->pid_ctrl_index].cmd = DIB9000_PID_FILTER_CTRL;
+               state->pid_ctrl[state->pid_ctrl_index].onoff = onoff;
+               return 0;
+       }
+
+       DibAcquireLock(&state->demod_lock);
+
+       val = dib9000_read_word(state, 294 + 1) & 0xffef;
        val |= (onoff & 0x1) << 4;
 
        dprintk("PID filter enabled %d", onoff);
-       return dib9000_write_word(state, 294 + 1, val);
+       ret = dib9000_write_word(state, 294 + 1, val);
+       DibReleaseLock(&state->demod_lock);
+       return ret;
+
 }
 EXPORT_SYMBOL(dib9000_fw_pid_filter_ctrl);
 
 int dib9000_fw_pid_filter(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff)
 {
        struct dib9000_state *state = fe->demodulator_priv;
+       int ret;
+
+       if (state->pid_ctrl_index != -2) {
+               /* postpone the pid filtering cmd */
+               dprintk("pid filter postpone");
+               if (state->pid_ctrl_index < 9) {
+                       state->pid_ctrl_index++;
+                       state->pid_ctrl[state->pid_ctrl_index].cmd = DIB9000_PID_FILTER;
+                       state->pid_ctrl[state->pid_ctrl_index].id = id;
+                       state->pid_ctrl[state->pid_ctrl_index].pid = pid;
+                       state->pid_ctrl[state->pid_ctrl_index].onoff = onoff;
+               } else
+                       dprintk("can not add any more pid ctrl cmd");
+               return 0;
+       }
+
+       DibAcquireLock(&state->demod_lock);
        dprintk("Index %x, PID %d, OnOff %d", id, pid, onoff);
-       return dib9000_write_word(state, 300 + 1 + id, onoff ? (1 << 13) | pid : 0);
+       ret = dib9000_write_word(state, 300 + 1 + id,
+                       onoff ? (1 << 13) | pid : 0);
+       DibReleaseLock(&state->demod_lock);
+       return ret;
 }
 EXPORT_SYMBOL(dib9000_fw_pid_filter);
 
@@ -1778,6 +1828,7 @@ static void dib9000_release(struct dvb_frontend *demod)
        DibFreeLock(&state->platform.risc.mbx_lock);
        DibFreeLock(&state->platform.risc.mem_lock);
        DibFreeLock(&state->platform.risc.mem_mbx_lock);
+       DibFreeLock(&state->demod_lock);
        dibx000_exit_i2c_master(&st->i2c_master);
 
        i2c_del_adapter(&st->tuner_adap);
@@ -1795,14 +1846,19 @@ static int dib9000_sleep(struct dvb_frontend *fe)
 {
        struct dib9000_state *state = fe->demodulator_priv;
        u8 index_frontend;
-       int ret;
+       int ret = 0;
 
+       DibAcquireLock(&state->demod_lock);
        for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
                ret = state->fe[index_frontend]->ops.sleep(state->fe[index_frontend]);
                if (ret < 0)
-                       return ret;
+                       goto error;
        }
-       return dib9000_mbx_send(state, OUT_MSG_FE_SLEEP, NULL, 0);
+       ret = dib9000_mbx_send(state, OUT_MSG_FE_SLEEP, NULL, 0);
+
+error:
+       DibReleaseLock(&state->demod_lock);
+       return ret;
 }
 
 static int dib9000_fe_get_tune_settings(struct dvb_frontend *fe, struct dvb_frontend_tune_settings *tune)
@@ -1816,7 +1872,10 @@ static int dib9000_get_frontend(struct dvb_frontend *fe, struct dvb_frontend_par
        struct dib9000_state *state = fe->demodulator_priv;
        u8 index_frontend, sub_index_frontend;
        fe_status_t stat;
-       int ret;
+       int ret = 0;
+
+       if (state->get_frontend_internal == 0)
+               DibAcquireLock(&state->demod_lock);
 
        for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
                state->fe[index_frontend]->ops.read_status(state->fe[index_frontend], &stat);
@@ -1846,14 +1905,15 @@ static int dib9000_get_frontend(struct dvb_frontend *fe, struct dvb_frontend_par
                                            state->fe[index_frontend]->dtv_property_cache.rolloff;
                                }
                        }
-                       return 0;
+                       ret = 0;
+                       goto return_value;
                }
        }
 
        /* get the channel from master chip */
        ret = dib9000_fw_get_channel(fe, fep);
        if (ret != 0)
-               return ret;
+               goto return_value;
 
        /* synchronize the cache with the other frontends */
        for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
@@ -1866,8 +1926,12 @@ static int dib9000_get_frontend(struct dvb_frontend *fe, struct dvb_frontend_par
                state->fe[index_frontend]->dtv_property_cache.code_rate_LP = fe->dtv_property_cache.code_rate_LP;
                state->fe[index_frontend]->dtv_property_cache.rolloff = fe->dtv_property_cache.rolloff;
        }
+       ret = 0;
 
-       return 0;
+return_value:
+       if (state->get_frontend_internal == 0)
+               DibReleaseLock(&state->demod_lock);
+       return ret;
 }
 
 static int dib9000_set_tune_state(struct dvb_frontend *fe, enum frontend_tune_state tune_state)
@@ -1912,6 +1976,10 @@ static int dib9000_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_par
                dprintk("dib9000: must specify bandwidth ");
                return 0;
        }
+
+       state->pid_ctrl_index = -1; /* postpone the pid filtering cmd */
+       DibAcquireLock(&state->demod_lock);
+
        fe->dtv_property_cache.delivery_system = SYS_DVBT;
 
        /* set the master status */
@@ -1974,13 +2042,18 @@ static int dib9000_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_par
        /* check the tune result */
        if (exit_condition == 1) {      /* tune failed */
                dprintk("tune failed");
+               DibReleaseLock(&state->demod_lock);
+               /* tune failed; put all the pid filtering cmd to junk */
+               state->pid_ctrl_index = -1;
                return 0;
        }
 
        dprintk("tune success on frontend%i", index_frontend_success);
 
        /* synchronize all the channel cache */
+       state->get_frontend_internal = 1;
        dib9000_get_frontend(state->fe[0], fep);
+       state->get_frontend_internal = 0;
 
        /* retune the other frontends with the found channel */
        channel_status.status = CHANNEL_STATUS_PARAMETERS_SET;
@@ -2025,6 +2098,28 @@ static int dib9000_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_par
        /* turn off the diversity for the last frontend */
        dib9000_fw_set_diversity_in(state->fe[index_frontend - 1], 0);
 
+       DibReleaseLock(&state->demod_lock);
+       if (state->pid_ctrl_index >= 0) {
+               u8 index_pid_filter_cmd;
+               u8 pid_ctrl_index = state->pid_ctrl_index;
+
+               state->pid_ctrl_index = -2;
+               for (index_pid_filter_cmd = 0;
+                               index_pid_filter_cmd <= pid_ctrl_index;
+                               index_pid_filter_cmd++) {
+                       if (state->pid_ctrl[index_pid_filter_cmd].cmd == DIB9000_PID_FILTER_CTRL)
+                               dib9000_fw_pid_filter_ctrl(state->fe[0],
+                                               state->pid_ctrl[index_pid_filter_cmd].onoff);
+                       else if (state->pid_ctrl[index_pid_filter_cmd].cmd == DIB9000_PID_FILTER)
+                               dib9000_fw_pid_filter(state->fe[0],
+                                               state->pid_ctrl[index_pid_filter_cmd].id,
+                                               state->pid_ctrl[index_pid_filter_cmd].pid,
+                                               state->pid_ctrl[index_pid_filter_cmd].onoff);
+               }
+       }
+       /* do not postpone any more the pid filtering */
+       state->pid_ctrl_index = -2;
+
        return 0;
 }
 
@@ -2041,6 +2136,7 @@ static int dib9000_read_status(struct dvb_frontend *fe, fe_status_t * stat)
        u8 index_frontend;
        u16 lock = 0, lock_slave = 0;
 
+       DibAcquireLock(&state->demod_lock);
        for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++)
                lock_slave |= dib9000_read_lock(state->fe[index_frontend]);
 
@@ -2059,6 +2155,8 @@ static int dib9000_read_status(struct dvb_frontend *fe, fe_status_t * stat)
        if ((lock & 0x0008) || (lock_slave & 0x0008))
                *stat |= FE_HAS_LOCK;
 
+       DibReleaseLock(&state->demod_lock);
+
        return 0;
 }
 
@@ -2066,10 +2164,15 @@ static int dib9000_read_ber(struct dvb_frontend *fe, u32 * ber)
 {
        struct dib9000_state *state = fe->demodulator_priv;
        u16 *c;
+       int ret = 0;
 
+       DibAcquireLock(&state->demod_lock);
        DibAcquireLock(&state->platform.risc.mem_mbx_lock);
-       if (dib9000_fw_memmbx_sync(state, FE_SYNC_CHANNEL) < 0)
-               return -EIO;
+       if (dib9000_fw_memmbx_sync(state, FE_SYNC_CHANNEL) < 0) {
+               DibReleaseLock(&state->platform.risc.mem_mbx_lock);
+               ret = -EIO;
+               goto error;
+       }
        dib9000_risc_mem_read(state, FE_MM_R_FE_MONITOR,
                        state->i2c_read_buffer, 16 * 2);
        DibReleaseLock(&state->platform.risc.mem_mbx_lock);
@@ -2077,7 +2180,10 @@ static int dib9000_read_ber(struct dvb_frontend *fe, u32 * ber)
        c = (u16 *)state->i2c_read_buffer;
 
        *ber = c[10] << 16 | c[11];
-       return 0;
+
+error:
+       DibReleaseLock(&state->demod_lock);
+       return ret;
 }
 
 static int dib9000_read_signal_strength(struct dvb_frontend *fe, u16 * strength)
@@ -2086,7 +2192,9 @@ static int dib9000_read_signal_strength(struct dvb_frontend *fe, u16 * strength)
        u8 index_frontend;
        u16 *c = (u16 *)state->i2c_read_buffer;
        u16 val;
+       int ret = 0;
 
+       DibAcquireLock(&state->demod_lock);
        *strength = 0;
        for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
                state->fe[index_frontend]->ops.read_signal_strength(state->fe[index_frontend], &val);
@@ -2097,8 +2205,10 @@ static int dib9000_read_signal_strength(struct dvb_frontend *fe, u16 * strength)
        }
 
        DibAcquireLock(&state->platform.risc.mem_mbx_lock);
-       if (dib9000_fw_memmbx_sync(state, FE_SYNC_CHANNEL) < 0)
-               return -EIO;
+       if (dib9000_fw_memmbx_sync(state, FE_SYNC_CHANNEL) < 0) {
+               ret = -EIO;
+               goto error;
+       }
        dib9000_risc_mem_read(state, FE_MM_R_FE_MONITOR, (u8 *) c, 16 * 2);
        DibReleaseLock(&state->platform.risc.mem_mbx_lock);
 
@@ -2107,7 +2217,10 @@ static int dib9000_read_signal_strength(struct dvb_frontend *fe, u16 * strength)
                *strength = 65535;
        else
                *strength += val;
-       return 0;
+
+error:
+       DibReleaseLock(&state->demod_lock);
+       return ret;
 }
 
 static u32 dib9000_get_snr(struct dvb_frontend *fe)
@@ -2151,6 +2264,7 @@ static int dib9000_read_snr(struct dvb_frontend *fe, u16 * snr)
        u8 index_frontend;
        u32 snr_master;
 
+       DibAcquireLock(&state->demod_lock);
        snr_master = dib9000_get_snr(fe);
        for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++)
                snr_master += dib9000_get_snr(state->fe[index_frontend]);
@@ -2161,6 +2275,8 @@ static int dib9000_read_snr(struct dvb_frontend *fe, u16 * snr)
        } else
                *snr = 0;
 
+       DibReleaseLock(&state->demod_lock);
+
        return 0;
 }
 
@@ -2168,15 +2284,22 @@ static int dib9000_read_unc_blocks(struct dvb_frontend *fe, u32 * unc)
 {
        struct dib9000_state *state = fe->demodulator_priv;
        u16 *c = (u16 *)state->i2c_read_buffer;
+       int ret = 0;
 
+       DibAcquireLock(&state->demod_lock);
        DibAcquireLock(&state->platform.risc.mem_mbx_lock);
-       if (dib9000_fw_memmbx_sync(state, FE_SYNC_CHANNEL) < 0)
-               return -EIO;
+       if (dib9000_fw_memmbx_sync(state, FE_SYNC_CHANNEL) < 0) {
+               ret = -EIO;
+               goto error;
+       }
        dib9000_risc_mem_read(state, FE_MM_R_FE_MONITOR, (u8 *) c, 16 * 2);
        DibReleaseLock(&state->platform.risc.mem_mbx_lock);
 
        *unc = c[12];
-       return 0;
+
+error:
+       DibReleaseLock(&state->demod_lock);
+       return ret;
 }
 
 int dib9000_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 default_addr, u8 first_addr)
@@ -2322,6 +2445,10 @@ struct dvb_frontend *dib9000_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, c
        DibInitLock(&st->platform.risc.mbx_lock);
        DibInitLock(&st->platform.risc.mem_lock);
        DibInitLock(&st->platform.risc.mem_mbx_lock);
+       DibInitLock(&st->demod_lock);
+       st->get_frontend_internal = 0;
+
+       st->pid_ctrl_index = -2;
 
        st->fe[0] = fe;
        fe->demodulator_priv = st;
index dc5d17a6757944e97670358c5f1ea46428190cd8..774d507b66cc7e841b412efe4c06ea4a6c8c1be5 100644 (file)
@@ -1,4 +1,5 @@
 #include <linux/i2c.h>
+#include <linux/mutex.h>
 
 #include "dibx000_common.h"
 
@@ -10,6 +11,13 @@ MODULE_PARM_DESC(debug, "turn on debugging (default: 0)");
 
 static int dibx000_write_word(struct dibx000_i2c_master *mst, u16 reg, u16 val)
 {
+       int ret;
+
+       if (mutex_lock_interruptible(&mst->i2c_buffer_lock) < 0) {
+               dprintk("could not acquire lock");
+               return -EINVAL;
+       }
+
        mst->i2c_write_buffer[0] = (reg >> 8) & 0xff;
        mst->i2c_write_buffer[1] = reg & 0xff;
        mst->i2c_write_buffer[2] = (val >> 8) & 0xff;
@@ -21,11 +29,21 @@ static int dibx000_write_word(struct dibx000_i2c_master *mst, u16 reg, u16 val)
        mst->msg[0].buf = mst->i2c_write_buffer;
        mst->msg[0].len = 4;
 
-       return i2c_transfer(mst->i2c_adap, mst->msg, 1) != 1 ? -EREMOTEIO : 0;
+       ret = i2c_transfer(mst->i2c_adap, mst->msg, 1) != 1 ? -EREMOTEIO : 0;
+       mutex_unlock(&mst->i2c_buffer_lock);
+
+       return ret;
 }
 
 static u16 dibx000_read_word(struct dibx000_i2c_master *mst, u16 reg)
 {
+       u16 ret;
+
+       if (mutex_lock_interruptible(&mst->i2c_buffer_lock) < 0) {
+               dprintk("could not acquire lock");
+               return 0;
+       }
+
        mst->i2c_write_buffer[0] = reg >> 8;
        mst->i2c_write_buffer[1] = reg & 0xff;
 
@@ -42,7 +60,10 @@ static u16 dibx000_read_word(struct dibx000_i2c_master *mst, u16 reg)
        if (i2c_transfer(mst->i2c_adap, mst->msg, 2) != 2)
                dprintk("i2c read error on %d", reg);
 
-       return (mst->i2c_read_buffer[0] << 8) | mst->i2c_read_buffer[1];
+       ret = (mst->i2c_read_buffer[0] << 8) | mst->i2c_read_buffer[1];
+       mutex_unlock(&mst->i2c_buffer_lock);
+
+       return ret;
 }
 
 static int dibx000_is_i2c_done(struct dibx000_i2c_master *mst)
@@ -257,6 +278,7 @@ static int dibx000_i2c_gated_gpio67_xfer(struct i2c_adapter *i2c_adap,
                                        struct i2c_msg msg[], int num)
 {
        struct dibx000_i2c_master *mst = i2c_get_adapdata(i2c_adap);
+       int ret;
 
        if (num > 32) {
                dprintk("%s: too much I2C message to be transmitted (%i).\
@@ -264,10 +286,15 @@ static int dibx000_i2c_gated_gpio67_xfer(struct i2c_adapter *i2c_adap,
                return -ENOMEM;
        }
 
-       memset(mst->msg, 0, sizeof(struct i2c_msg) * (2 + num));
-
        dibx000_i2c_select_interface(mst, DIBX000_I2C_INTERFACE_GPIO_6_7);
 
+       if (mutex_lock_interruptible(&mst->i2c_buffer_lock) < 0) {
+               dprintk("could not acquire lock");
+               return -EINVAL;
+       }
+
+       memset(mst->msg, 0, sizeof(struct i2c_msg) * (2 + num));
+
        /* open the gate */
        dibx000_i2c_gate_ctrl(mst, &mst->i2c_write_buffer[0], msg[0].addr, 1);
        mst->msg[0].addr = mst->i2c_addr;
@@ -282,7 +309,11 @@ static int dibx000_i2c_gated_gpio67_xfer(struct i2c_adapter *i2c_adap,
        mst->msg[num + 1].buf = &mst->i2c_write_buffer[4];
        mst->msg[num + 1].len = 4;
 
-       return i2c_transfer(mst->i2c_adap, mst->msg, 2 + num) == 2 + num ? num : -EIO;
+       ret = (i2c_transfer(mst->i2c_adap, mst->msg, 2 + num) == 2 + num ?
+                       num : -EIO);
+
+       mutex_unlock(&mst->i2c_buffer_lock);
+       return ret;
 }
 
 static struct i2c_algorithm dibx000_i2c_gated_gpio67_algo = {
@@ -294,6 +325,7 @@ static int dibx000_i2c_gated_tuner_xfer(struct i2c_adapter *i2c_adap,
                                        struct i2c_msg msg[], int num)
 {
        struct dibx000_i2c_master *mst = i2c_get_adapdata(i2c_adap);
+       int ret;
 
        if (num > 32) {
                dprintk("%s: too much I2C message to be transmitted (%i).\
@@ -301,10 +333,14 @@ static int dibx000_i2c_gated_tuner_xfer(struct i2c_adapter *i2c_adap,
                return -ENOMEM;
        }
 
-       memset(mst->msg, 0, sizeof(struct i2c_msg) * (2 + num));
-
        dibx000_i2c_select_interface(mst, DIBX000_I2C_INTERFACE_TUNER);
 
+       if (mutex_lock_interruptible(&mst->i2c_buffer_lock) < 0) {
+               dprintk("could not acquire lock");
+               return -EINVAL;
+       }
+       memset(mst->msg, 0, sizeof(struct i2c_msg) * (2 + num));
+
        /* open the gate */
        dibx000_i2c_gate_ctrl(mst, &mst->i2c_write_buffer[0], msg[0].addr, 1);
        mst->msg[0].addr = mst->i2c_addr;
@@ -319,7 +355,10 @@ static int dibx000_i2c_gated_tuner_xfer(struct i2c_adapter *i2c_adap,
        mst->msg[num + 1].buf = &mst->i2c_write_buffer[4];
        mst->msg[num + 1].len = 4;
 
-       return i2c_transfer(mst->i2c_adap, mst->msg, 2 + num) == 2 + num ? num : -EIO;
+       ret = (i2c_transfer(mst->i2c_adap, mst->msg, 2 + num) == 2 + num ?
+                       num : -EIO);
+       mutex_unlock(&mst->i2c_buffer_lock);
+       return ret;
 }
 
 static struct i2c_algorithm dibx000_i2c_gated_tuner_algo = {
@@ -390,8 +429,18 @@ static int i2c_adapter_init(struct i2c_adapter *i2c_adap,
 int dibx000_init_i2c_master(struct dibx000_i2c_master *mst, u16 device_rev,
                                struct i2c_adapter *i2c_adap, u8 i2c_addr)
 {
-       u8 tx[4];
-       struct i2c_msg m = {.addr = i2c_addr >> 1,.buf = tx,.len = 4 };
+       int ret;
+
+       mutex_init(&mst->i2c_buffer_lock);
+       if (mutex_lock_interruptible(&mst->i2c_buffer_lock) < 0) {
+               dprintk("could not acquire lock");
+               return -EINVAL;
+       }
+       memset(mst->msg, 0, sizeof(struct i2c_msg));
+       mst->msg[0].addr = i2c_addr >> 1;
+       mst->msg[0].flags = 0;
+       mst->msg[0].buf = mst->i2c_write_buffer;
+       mst->msg[0].len = 4;
 
        mst->device_rev = device_rev;
        mst->i2c_adap = i2c_adap;
@@ -431,9 +480,12 @@ int dibx000_init_i2c_master(struct dibx000_i2c_master *mst, u16 device_rev,
                                "DiBX000: could not initialize the master i2c_adapter\n");
 
        /* initialize the i2c-master by closing the gate */
-       dibx000_i2c_gate_ctrl(mst, tx, 0, 0);
+       dibx000_i2c_gate_ctrl(mst, mst->i2c_write_buffer, 0, 0);
+
+       ret = (i2c_transfer(i2c_adap, mst->msg, 1) == 1);
+       mutex_unlock(&mst->i2c_buffer_lock);
 
-       return i2c_transfer(i2c_adap, &m, 1) == 1;
+       return ret;
 }
 
 EXPORT_SYMBOL(dibx000_init_i2c_master);
index f031165c04596df1e3774db6f039c28ba543c9df..5e011474be430658b1b13d283bd2f7e11d5c2ca6 100644 (file)
@@ -33,6 +33,7 @@ struct dibx000_i2c_master {
        struct i2c_msg msg[34];
        u8 i2c_write_buffer[8];
        u8 i2c_read_buffer[2];
+       struct mutex i2c_buffer_lock;
 };
 
 extern int dibx000_init_i2c_master(struct dibx000_i2c_master *mst,
index 2238bf0be95936320feccbfc65f30c1503167e08..88e46f4cdbb26c77a14fbeef942fb6df3682fa4f 100644 (file)
@@ -889,10 +889,15 @@ static int ReadIFAgc(struct drxd_state *state, u32 * pValue)
                        u32 R2 = state->if_agc_cfg.R2;
                        u32 R3 = state->if_agc_cfg.R3;
 
-                       u32 Vmax = (3300 * R2) / (R1 + R2);
-                       u32 Rpar = (R2 * R3) / (R3 + R2);
-                       u32 Vmin = (3300 * Rpar) / (R1 + Rpar);
-                       u32 Vout = Vmin + ((Vmax - Vmin) * Value) / 1024;
+                       u32 Vmax, Rpar, Vmin, Vout;
+
+                       if (R2 == 0 && (R1 == 0 || R3 == 0))
+                               return 0;
+
+                       Vmax = (3300 * R2) / (R1 + R2);
+                       Rpar = (R2 * R3) / (R3 + R2);
+                       Vmin = (3300 * Rpar) / (R1 + Rpar);
+                       Vout = Vmin + ((Vmax - Vmin) * Value) / 1024;
 
                        *pValue = Vout;
                }
@@ -926,16 +931,15 @@ static int DownloadMicrocode(struct drxd_state *state,
                             const u8 *pMCImage, u32 Length)
 {
        u8 *pSrc;
-       u16 Flags;
        u32 Address;
        u16 nBlocks;
        u16 BlockSize;
-       u16 BlockCRC;
        u32 offset = 0;
        int i, status = 0;
 
        pSrc = (u8 *) pMCImage;
-       Flags = (pSrc[0] << 8) | pSrc[1];
+       /* We're not using Flags */
+       /* Flags = (pSrc[0] << 8) | pSrc[1]; */
        pSrc += sizeof(u16);
        offset += sizeof(u16);
        nBlocks = (pSrc[0] << 8) | pSrc[1];
@@ -952,11 +956,13 @@ static int DownloadMicrocode(struct drxd_state *state,
                pSrc += sizeof(u16);
                offset += sizeof(u16);
 
-               Flags = (pSrc[0] << 8) | pSrc[1];
+               /* We're not using Flags */
+               /* u16 Flags = (pSrc[0] << 8) | pSrc[1]; */
                pSrc += sizeof(u16);
                offset += sizeof(u16);
 
-               BlockCRC = (pSrc[0] << 8) | pSrc[1];
+               /* We're not using BlockCRC */
+               /* u16 BlockCRC = (pSrc[0] << 8) | pSrc[1]; */
                pSrc += sizeof(u16);
                offset += sizeof(u16);
 
index 41b083820dae96ff726b1cca505ba7a8415bb85c..f6431ef827dc1f86e6b4748ae08c5edb141919ff 100644 (file)
@@ -6211,6 +6211,14 @@ static int drxk_set_parameters(struct dvb_frontend *fe,
        u32 IF;
 
        dprintk(1, "\n");
+
+       if (!fe->ops.tuner_ops.get_if_frequency) {
+               printk(KERN_ERR
+                      "drxk: Error: get_if_frequency() not defined at tuner. Can't work without it!\n");
+               return -EINVAL;
+       }
+
+
        if (fe->ops.i2c_gate_ctrl)
                fe->ops.i2c_gate_ctrl(fe, 1);
        if (fe->ops.tuner_ops.set_params)
@@ -6218,7 +6226,7 @@ static int drxk_set_parameters(struct dvb_frontend *fe,
        if (fe->ops.i2c_gate_ctrl)
                fe->ops.i2c_gate_ctrl(fe, 0);
        state->param = *p;
-       fe->ops.tuner_ops.get_frequency(fe, &IF);
+       fe->ops.tuner_ops.get_if_frequency(fe, &IF);
        Start(state, 0, IF);
 
        /* printk(KERN_DEBUG "drxk: %s IF=%d done\n", __func__, IF); */
diff --git a/drivers/media/dvb/frontends/it913x-fe-priv.h b/drivers/media/dvb/frontends/it913x-fe-priv.h
new file mode 100644 (file)
index 0000000..1c6fb4b
--- /dev/null
@@ -0,0 +1,336 @@
+
+struct it913xset {     u32 pro;
+                       u32 address;
+                       u8 reg[15];
+                       u8 count;
+};
+
+struct adctable {      u32 adcFrequency;
+                       u32 bandwidth;
+                       u32 coeff_1_2048;
+                       u32 coeff_1_4096;
+                       u32 coeff_1_8191;
+                       u32 coeff_1_8192;
+                       u32 coeff_1_8193;
+                       u32 coeff_2_2k;
+                       u32 coeff_2_4k;
+                       u32 coeff_2_8k;
+                       u16 bfsfcw_fftinx_ratio;
+                       u16 fftinx_bfsfcw_ratio;
+};
+
+/* clock and coeff tables only table 3 is used with IT9137*/
+/* TODO other tables relate AF9035 may be removed */
+static struct adctable tab1[] = {
+       {       20156250, BANDWIDTH_6_MHZ,
+               0x02b8ba6e, 0x015c5d37, 0x00ae340d, 0x00ae2e9b, 0x00ae292a,
+               0x015c5d37, 0x00ae2e9b, 0x0057174e, 0x02f1, 0x015c      },
+       {       20156250, BANDWIDTH_7_MHZ,
+               0x032cd980, 0x01966cc0, 0x00cb3cba, 0x00cb3660, 0x00cb3007,
+               0x01966cc0, 0x00cb3660, 0x00659b30, 0x0285, 0x0196      },
+       {       20156250, BANDWIDTH_8_MHZ,
+               0x03a0f893, 0x01d07c49, 0x00e84567, 0x00e83e25, 0x00e836e3,
+               0x01d07c49, 0x00e83e25, 0x00741f12, 0x0234, 0x01d0      },
+       {       20156250, BANDWIDTH_5_MHZ,
+               0x02449b5c, 0x01224dae, 0x00912b60, 0x009126d7, 0x0091224e,
+               0x01224dae, 0x009126d7, 0x0048936b, 0x0387, 0x0122      }
+};
+
+static struct adctable tab2[] = {
+       {       20187500, BANDWIDTH_6_MHZ,
+               0x02b7a654, 0x015bd32a, 0x00adef04, 0x00ade995, 0x00ade426,
+               0x015bd32a, 0x00ade995, 0x0056f4ca, 0x02f2, 0x015c      },
+       {       20187500, BANDWIDTH_7_MHZ,
+               0x032b9761, 0x0195cbb1, 0x00caec30, 0x00cae5d8, 0x00cadf81,
+               0x0195cbb1, 0x00cae5d8, 0x006572ec, 0x0286, 0x0196      },
+       {       20187500, BANDWIDTH_8_MHZ,
+               0x039f886f, 0x01cfc438, 0x00e7e95b, 0x00e7e21c, 0x00e7dadd,
+               0x01cfc438, 0x00e7e21c, 0x0073f10e, 0x0235, 0x01d0      },
+       {       20187500, BANDWIDTH_5_MHZ,
+               0x0243b546, 0x0121daa3, 0x0090f1d9, 0x0090ed51, 0x0090e8ca,
+               0x0121daa3, 0x0090ed51, 0x004876a9, 0x0388, 0x0122      }
+
+};
+
+static struct adctable tab3[] = {
+       {       20250000, BANDWIDTH_6_MHZ,
+               0x02b580ad, 0x015ac057, 0x00ad6597, 0x00ad602b, 0x00ad5ac1,
+               0x015ac057, 0x00ad602b, 0x0056b016, 0x02f4, 0x015b      },
+       {       20250000, BANDWIDTH_7_MHZ,
+               0x03291620, 0x01948b10, 0x00ca4bda, 0x00ca4588, 0x00ca3f36,
+               0x01948b10, 0x00ca4588, 0x006522c4, 0x0288, 0x0195      },
+       {       20250000, BANDWIDTH_8_MHZ,
+               0x039cab92, 0x01ce55c9, 0x00e7321e, 0x00e72ae4, 0x00e723ab,
+               0x01ce55c9, 0x00e72ae4, 0x00739572, 0x0237, 0x01ce      },
+       {       20250000, BANDWIDTH_5_MHZ,
+               0x0241eb3b, 0x0120f59e, 0x00907f53, 0x00907acf, 0x0090764b,
+               0x0120f59e, 0x00907acf, 0x00483d67, 0x038b, 0x0121      }
+
+};
+
+static struct adctable tab4[] = {
+       {       20583333, BANDWIDTH_6_MHZ,
+               0x02aa4598, 0x015522cc, 0x00aa96bb, 0x00aa9166, 0x00aa8c12,
+               0x015522cc, 0x00aa9166, 0x005548b3, 0x0300, 0x0155      },
+       {       20583333, BANDWIDTH_7_MHZ,
+               0x031bfbdc, 0x018dfdee, 0x00c7052f, 0x00c6fef7, 0x00c6f8bf,
+               0x018dfdee, 0x00c6fef7, 0x00637f7b, 0x0293, 0x018e      },
+       {       20583333, BANDWIDTH_8_MHZ,
+               0x038db21f, 0x01c6d910, 0x00e373a3, 0x00e36c88, 0x00e3656d,
+               0x01c6d910, 0x00e36c88, 0x0071b644, 0x0240, 0x01c7      },
+       {       20583333, BANDWIDTH_5_MHZ,
+               0x02388f54, 0x011c47aa, 0x008e2846, 0x008e23d5, 0x008e1f64,
+               0x011c47aa, 0x008e23d5, 0x004711ea, 0x039a, 0x011c      }
+
+};
+
+static struct adctable tab5[] = {
+       {       20416667, BANDWIDTH_6_MHZ,
+               0x02afd765, 0x0157ebb3, 0x00abfb39, 0x00abf5d9, 0x00abf07a,
+               0x0157ebb3, 0x00abf5d9, 0x0055faed, 0x02fa, 0x0158      },
+       {       20416667, BANDWIDTH_7_MHZ,
+               0x03227b4b, 0x01913da6, 0x00c8a518, 0x00c89ed3, 0x00c8988e,
+               0x01913da6, 0x00c89ed3, 0x00644f69, 0x028d, 0x0191      },
+       {       20416667, BANDWIDTH_8_MHZ,
+               0x03951f32, 0x01ca8f99, 0x00e54ef7, 0x00e547cc, 0x00e540a2,
+               0x01ca8f99, 0x00e547cc, 0x0072a3e6, 0x023c, 0x01cb      },
+       {       20416667, BANDWIDTH_5_MHZ,
+               0x023d337f, 0x011e99c0, 0x008f515a, 0x008f4ce0, 0x008f4865,
+               0x011e99c0, 0x008f4ce0, 0x0047a670, 0x0393, 0x011f      }
+
+};
+
+static struct adctable tab6[] = {
+       {       20480000, BANDWIDTH_6_MHZ,
+               0x02adb6db, 0x0156db6e, 0x00ab7312, 0x00ab6db7, 0x00ab685c,
+               0x0156db6e, 0x00ab6db7, 0x0055b6db, 0x02fd, 0x0157      },
+       {       20480000, BANDWIDTH_7_MHZ,
+               0x03200000, 0x01900000, 0x00c80640, 0x00c80000, 0x00c7f9c0,
+               0x01900000, 0x00c80000, 0x00640000, 0x028f, 0x0190      },
+       {       20480000, BANDWIDTH_8_MHZ,
+               0x03924925, 0x01c92492, 0x00e4996e, 0x00e49249, 0x00e48b25,
+               0x01c92492, 0x00e49249, 0x00724925, 0x023d, 0x01c9      },
+       {       20480000, BANDWIDTH_5_MHZ,
+               0x023b6db7, 0x011db6db, 0x008edfe5, 0x008edb6e, 0x008ed6f7,
+               0x011db6db, 0x008edb6e, 0x00476db7, 0x0396, 0x011e      }
+};
+
+static struct adctable tab7[] = {
+       {       20500000, BANDWIDTH_6_MHZ,
+               0x02ad0b99, 0x015685cc, 0x00ab4840, 0x00ab42e6, 0x00ab3d8c,
+               0x015685cc, 0x00ab42e6, 0x0055a173, 0x02fd, 0x0157      },
+       {       20500000, BANDWIDTH_7_MHZ,
+               0x031f3832, 0x018f9c19, 0x00c7d44b, 0x00c7ce0c, 0x00c7c7ce,
+               0x018f9c19, 0x00c7ce0c, 0x0063e706, 0x0290, 0x0190      },
+       {       20500000, BANDWIDTH_8_MHZ,
+               0x039164cb, 0x01c8b266, 0x00e46056, 0x00e45933, 0x00e45210,
+               0x01c8b266, 0x00e45933, 0x00722c99, 0x023e, 0x01c9      },
+       {       20500000, BANDWIDTH_5_MHZ,
+               0x023adeff, 0x011d6f80, 0x008ebc36, 0x008eb7c0, 0x008eb34a,
+               0x011d6f80, 0x008eb7c0, 0x00475be0, 0x0396, 0x011d      }
+
+};
+
+static struct adctable tab8[] = {
+       {       20625000, BANDWIDTH_6_MHZ,
+               0x02a8e4bd, 0x0154725e, 0x00aa3e81, 0x00aa392f, 0x00aa33de,
+               0x0154725e, 0x00aa392f, 0x00551c98, 0x0302, 0x0154      },
+       {       20625000, BANDWIDTH_7_MHZ,
+               0x031a6032, 0x018d3019, 0x00c69e41, 0x00c6980c, 0x00c691d8,
+               0x018d3019, 0x00c6980c, 0x00634c06, 0x0294, 0x018d      },
+       {       20625000, BANDWIDTH_8_MHZ,
+               0x038bdba6, 0x01c5edd3, 0x00e2fe02, 0x00e2f6ea, 0x00e2efd2,
+               0x01c5edd3, 0x00e2f6ea, 0x00717b75, 0x0242, 0x01c6      },
+       {       20625000, BANDWIDTH_5_MHZ,
+               0x02376948, 0x011bb4a4, 0x008ddec1, 0x008dda52, 0x008dd5e3,
+               0x011bb4a4, 0x008dda52, 0x0046ed29, 0x039c, 0x011c      }
+
+};
+
+struct table {
+               u32 xtal;
+               struct adctable *table;
+};
+
+static struct table fe_clockTable[] = {
+               {12000000, tab3},       /* FPGA     */
+               {16384000, tab6},       /* 16.38MHz */
+               {20480000, tab6},       /* 20.48MHz */
+               {36000000, tab3},       /* 36.00MHz */
+               {30000000, tab1},       /* 30.00MHz */
+               {26000000, tab4},       /* 26.00MHz */
+               {28000000, tab5},       /* 28.00MHz */
+               {32000000, tab7},       /* 32.00MHz */
+               {34000000, tab2},       /* 34.00MHz */
+               {24000000, tab1},       /* 24.00MHz */
+               {22000000, tab8},       /* 22.00MHz */
+               {12000000, tab3}        /* 12.00MHz */
+};
+
+/* fe get */
+fe_code_rate_t fe_code[] = {
+       FEC_1_2,
+       FEC_2_3,
+       FEC_3_4,
+       FEC_5_6,
+       FEC_7_8,
+       FEC_NONE,
+};
+
+fe_guard_interval_t fe_gi[] = {
+       GUARD_INTERVAL_1_32,
+       GUARD_INTERVAL_1_16,
+       GUARD_INTERVAL_1_8,
+       GUARD_INTERVAL_1_4,
+};
+
+fe_hierarchy_t fe_hi[] = {
+       HIERARCHY_NONE,
+       HIERARCHY_1,
+       HIERARCHY_2,
+       HIERARCHY_4,
+};
+
+fe_transmit_mode_t fe_mode[] = {
+       TRANSMISSION_MODE_2K,
+       TRANSMISSION_MODE_8K,
+       TRANSMISSION_MODE_4K,
+};
+
+fe_modulation_t fe_con[] = {
+       QPSK,
+       QAM_16,
+       QAM_64,
+};
+
+/* Standard demodulator functions */
+static struct it913xset set_solo_fe[] = {
+       {PRO_LINK, DVBT_INTEN, {0x04}, 0x01},
+       {PRO_LINK, DVBT_ENABLE, {0x05}, 0x01},
+       {PRO_DMOD, MP2IF_MPEG_PAR_MODE, {0x00}, 0x01},
+       {PRO_LINK, HOSTB_MPEG_SER_MODE, {0x00}, 0x01},
+       {PRO_LINK, HOSTB_MPEG_PAR_MODE, {0x00}, 0x01},
+       {PRO_DMOD, DCA_UPPER_CHIP, {0x00}, 0x01},
+       {PRO_LINK, HOSTB_DCA_UPPER, {0x00}, 0x01},
+       {PRO_DMOD, DCA_LOWER_CHIP, {0x00}, 0x01},
+       {PRO_LINK, HOSTB_DCA_LOWER, {0x00}, 0x01},
+       {PRO_DMOD, DCA_PLATCH, {0x00}, 0x01},
+       {PRO_DMOD, DCA_FPGA_LATCH, {0x00}, 0x01},
+       {PRO_DMOD, DCA_STAND_ALONE, {0x01}, 0x01},
+       {PRO_DMOD, DCA_ENABLE, {0x00}, 0x01},
+       {PRO_DMOD, MP2IF_MPEG_PAR_MODE, {0x00}, 0x01},
+       {PRO_DMOD, BFS_FCW, {0x00, 0x00, 0x00}, 0x03},
+       {0xff, 0x0000, {0x00}, 0x00}, /* Terminating Entry */
+};
+
+
+static struct it913xset init_1[] = {
+       {PRO_LINK, LOCK3_OUT, {0x01}, 0x01},
+       {PRO_LINK, PADMISCDRSR, {0x01}, 0x01},
+       {PRO_LINK, PADMISCDR2, {0x00}, 0x01},
+       {PRO_LINK, PADMISCDR4, {0x00}, 0x01}, /* Power up */
+       {PRO_LINK, PADMISCDR8, {0x00}, 0x01},
+       {0xff, 0x0000, {0x00}, 0x00} /* Terminating Entry */
+};
+
+/* ---------IT9137 0x38 tuner init---------- */
+static struct it913xset it9137_set[] = {
+       {PRO_DMOD, 0x0043, {0x00}, 0x01},
+       {PRO_DMOD, 0x0046, {0x38}, 0x01},
+       {PRO_DMOD, 0x0051, {0x01}, 0x01},
+       {PRO_DMOD, 0x005f, {0x00, 0x00}, 0x02},
+       {PRO_DMOD, 0x0068, {0x0a}, 0x01},
+       {PRO_DMOD, 0x0070, {0x0a, 0x05, 0x02}, 0x03},
+       {PRO_DMOD, 0x0075, {0x8c, 0x8c, 0x8c, 0xc8, 0x01}, 0x05},
+       {PRO_DMOD, 0x007e, {0x04, 0x00}, 0x02},
+       {PRO_DMOD, 0x0081, {    0x0a, 0x12, 0x02, 0x0a, 0x03, 0xc8, 0xb8,
+                               0xd0, 0xc3, 0x01        }, 0x0a},
+       {PRO_DMOD, 0x008e, {0x01}, 0x01},
+       {PRO_DMOD, 0x0092, {0x06, 0x00, 0x00, 0x00, 0x00}, 0x05},
+       {PRO_DMOD, 0x0099, {0x01}, 0x01},
+       {PRO_DMOD, 0x009b, {0x3c, 0x28}, 0x02},
+       {PRO_DMOD, 0x009f, {0xe1, 0xcf}, 0x02},
+       {PRO_DMOD, 0x00a3, {0x01, 0x5a, 0x01, 0x01}, 0x04},
+       {PRO_DMOD, 0x00a9, {0x00, 0x01}, 0x02},
+       {PRO_DMOD, 0x00b0, {0x01}, 0x01},
+       {PRO_DMOD, 0x00b3, {0x02, 0x32}, 0x02},
+       {PRO_DMOD, 0x00b6, {0x14}, 0x01},
+       {PRO_DMOD, 0x00c0, {0x11, 0x00, 0x05}, 0x03},
+       {PRO_DMOD, 0x00c4, {0x00}, 0x01},
+       {PRO_DMOD, 0x00c6, {0x19, 0x00}, 0x02},
+       {PRO_DMOD, 0x00cc, {0x2e, 0x51, 0x33}, 0x03},
+       {PRO_DMOD, 0x00f3, {0x05, 0x8c, 0x8c}, 0x03},
+       {PRO_DMOD, 0x00f8, {0x03, 0x06, 0x06}, 0x03},
+       {PRO_DMOD, 0x00fc, {    0x02, 0x02, 0x02, 0x09, 0x50, 0x7b, 0x77,
+                               0x00, 0x02, 0xc8, 0x05, 0x7b    }, 0x0c},
+       {PRO_DMOD, 0x0109, {0x02}, 0x01},
+       {PRO_DMOD, 0x0115, {0x0a, 0x03}, 0x02},
+       {PRO_DMOD, 0x011a, {0xc8, 0x7b, 0xbc, 0xa0}, 0x04},
+       {PRO_DMOD, 0x0122, {0x02, 0x18, 0xc3}, 0x03},
+       {PRO_DMOD, 0x0127, {0x00, 0x07}, 0x02},
+       {PRO_DMOD, 0x012a, {0x53, 0x51, 0x4e, 0x43}, 0x04},
+       {PRO_DMOD, 0x0137, {0x01, 0x00, 0x07, 0x00, 0x06}, 0x05},
+       {PRO_DMOD, 0x013d, {0x00, 0x01, 0x5b, 0xc8}, 0x04},
+       {PRO_DMOD, 0xf130, {0x04}, 0x01},
+       {PRO_DMOD, 0xf132, {0x04}, 0x01},
+       {PRO_DMOD, 0xf144, {0x1a}, 0x01},
+       {PRO_DMOD, 0xf146, {0x00}, 0x01},
+       {PRO_DMOD, 0xf14a, {0x01}, 0x01},
+       {PRO_DMOD, 0xf14c, {0x00, 0x00}, 0x02},
+       {PRO_DMOD, 0xf14f, {0x04}, 0x01},
+       {PRO_DMOD, 0xf158, {0x7f}, 0x01},
+       {PRO_DMOD, 0xf15a, {0x00, 0x08}, 0x02},
+       {PRO_DMOD, 0xf15d, {0x03, 0x05}, 0x02},
+       {PRO_DMOD, 0xf163, {0x05}, 0x01},
+       {PRO_DMOD, 0xf166, {0x01, 0x40, 0x0f}, 0x03},
+       {PRO_DMOD, 0xf17a, {0x00, 0x00}, 0x02},
+       {PRO_DMOD, 0xf183, {0x01}, 0x01},
+       {PRO_DMOD, 0xf19d, {0x40}, 0x01},
+       {PRO_DMOD, 0xf1bc, {0x36, 0x00}, 0x02},
+       {PRO_DMOD, 0xf1cb, {0xa0, 0x01}, 0x02},
+       {PRO_DMOD, 0xf204, {0x10}, 0x01},
+       {PRO_DMOD, 0xf214, {0x00}, 0x01},
+       {PRO_DMOD, 0xf24c, {0x88, 0x95, 0x9a, 0x90}, 0x04},
+       {PRO_DMOD, 0xf25a, {0x07, 0xe8, 0x03, 0xb0, 0x04}, 0x05},
+       {PRO_DMOD, 0xf270, {0x01, 0x02, 0x01, 0x02}, 0x04},
+       {PRO_DMOD, 0xf40e, {0x0a, 0x40, 0x08}, 0x03},
+       {PRO_DMOD, 0xf55f, {0x0a}, 0x01},
+       {PRO_DMOD, 0xf561, {0x15, 0x20}, 0x02},
+       {PRO_DMOD, 0xf5df, {0xfb, 0x00}, 0x02},
+       {PRO_DMOD, 0xf5e3, {0x09, 0x01, 0x01}, 0x03},
+       {PRO_DMOD, 0xf5f8, {0x01}, 0x01},
+       {PRO_DMOD, 0xf5fd, {0x01}, 0x01},
+       {PRO_DMOD, 0xf600, {    0x05, 0x08, 0x0b, 0x0e, 0x11, 0x14, 0x17,
+                               0x1f    }, 0x08},
+       {PRO_DMOD, 0xf60e, {0x00, 0x04, 0x32, 0x10}, 0x04},
+       {PRO_DMOD, 0xf707, {0xfc, 0x00, 0x37, 0x00}, 0x04},
+       {PRO_DMOD, 0xf78b, {0x01}, 0x01},
+       {PRO_DMOD, 0xf80f, {0x40, 0x54, 0x5a}, 0x03},
+       {PRO_DMOD, 0xf905, {0x01}, 0x01},
+       {PRO_DMOD, 0xfb06, {0x03}, 0x01},
+       {PRO_DMOD, 0xfd8b, {0x00}, 0x01},
+       {PRO_LINK, GPIOH5_EN, {0x01}, 0x01},
+       {PRO_LINK, GPIOH5_ON, {0x01}, 0x01},
+       {PRO_LINK, GPIOH5_O, {0x00}, 0x01},
+       {PRO_LINK, GPIOH5_O, {0x01}, 0x01},
+       {0xff, 0x0000, {0x00}, 0x00}, /* Terminating Entry */
+};
+
+static struct it913xset it9137_tuner_off[] = {
+       {PRO_DMOD, 0xfba8, {0x01}, 0x01}, /* Tuner Clock Off  */
+       {PRO_DMOD, 0xec40, {0x00}, 0x01}, /* Power Down Tuner */
+       {PRO_DMOD, 0xec02, {0x3f, 0x1f, 0x3f, 0x3f}, 0x04},
+       {PRO_DMOD, 0xec3f, {0x01}, 0x01},
+       {0xff, 0x0000, {0x00}, 0x00}, /* Terminating Entry */
+};
+
+static struct it913xset set_it9137_template[] = {
+       {PRO_DMOD, 0xee06, {0x00}, 0x01},
+       {PRO_DMOD, 0xec56, {0x00}, 0x01},
+       {PRO_DMOD, 0xec4c, {0x00}, 0x01},
+       {PRO_DMOD, 0xec4d, {0x00}, 0x01},
+       {PRO_DMOD, 0xec4e, {0x00}, 0x01},
+       {PRO_DMOD, 0xec4f, {0x00}, 0x01},
+       {PRO_DMOD, 0xec50, {0x00}, 0x01},
+       {0xff, 0x0000, {0x00}, 0x00}, /* Terminating Entry */
+};
diff --git a/drivers/media/dvb/frontends/it913x-fe.c b/drivers/media/dvb/frontends/it913x-fe.c
new file mode 100644 (file)
index 0000000..d4bd24e
--- /dev/null
@@ -0,0 +1,839 @@
+/*
+ *  Driver for it913x-fe Frontend
+ *
+ *  with support for on chip it9137 integral tuner
+ *
+ *  Copyright (C) 2011 Malcolm Priestley (tvboxspy@gmail.com)
+ *  IT9137 Copyright (C) ITE Tech Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.=
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/types.h>
+
+#include "dvb_frontend.h"
+#include "it913x-fe.h"
+#include "it913x-fe-priv.h"
+
+static int it913x_debug;
+
+module_param_named(debug, it913x_debug, int, 0644);
+MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able)).");
+
+#define dprintk(level, args...) do { \
+       if (level & it913x_debug) \
+               printk(KERN_DEBUG "it913x-fe: " args); \
+} while (0)
+
+#define deb_info(args...)  dprintk(0x01, args)
+#define debug_data_snipet(level, name, p) \
+         dprintk(level, name" (%02x%02x%02x%02x%02x%02x%02x%02x)", \
+               *p, *(p+1), *(p+2), *(p+3), *(p+4), \
+                       *(p+5), *(p+6), *(p+7));
+
+struct it913x_fe_state {
+       struct dvb_frontend frontend;
+       struct i2c_adapter *i2c_adap;
+       u8 i2c_addr;
+       u32 frequency;
+       u8 adf;
+       u32 crystalFrequency;
+       u32 adcFrequency;
+       u8 tuner_type;
+       struct adctable *table;
+       fe_status_t it913x_status;
+       u16 tun_xtal;
+       u8 tun_fdiv;
+       u8 tun_clk_mode;
+       u32 tun_fn_min;
+};
+
+static int it913x_read_reg(struct it913x_fe_state *state,
+               u32 reg, u8 *data, u8 count)
+{
+       int ret;
+       u8 pro = PRO_DMOD; /* All reads from demodulator */
+       u8 b[4];
+       struct i2c_msg msg[2] = {
+               { .addr = state->i2c_addr + (pro << 1), .flags = 0,
+                       .buf = b, .len = sizeof(b) },
+               { .addr = state->i2c_addr + (pro << 1), .flags = I2C_M_RD,
+                       .buf = data, .len = count }
+       };
+       b[0] = (u8) reg >> 24;
+       b[1] = (u8)(reg >> 16) & 0xff;
+       b[2] = (u8)(reg >> 8) & 0xff;
+       b[3] = (u8) reg & 0xff;
+
+       ret = i2c_transfer(state->i2c_adap, msg, 2);
+
+       return ret;
+}
+
+static int it913x_read_reg_u8(struct it913x_fe_state *state, u32 reg)
+{
+       int ret;
+       u8 b[1];
+       ret = it913x_read_reg(state, reg, &b[0], sizeof(b));
+       return (ret < 0) ? -ENODEV : b[0];
+}
+
+static int it913x_write(struct it913x_fe_state *state,
+               u8 pro, u32 reg, u8 buf[], u8 count)
+{
+       u8 b[256];
+       struct i2c_msg msg[1] = {
+               { .addr = state->i2c_addr + (pro << 1), .flags = 0,
+                 .buf = b, .len = count + 4 }
+       };
+       int ret;
+
+       b[0] = (u8) reg >> 24;
+       b[1] = (u8)(reg >> 16) & 0xff;
+       b[2] = (u8)(reg >> 8) & 0xff;
+       b[3] = (u8) reg & 0xff;
+       memcpy(&b[4], buf, count);
+
+       ret = i2c_transfer(state->i2c_adap, msg, 1);
+
+       if (ret < 0)
+               return -EIO;
+
+       return 0;
+}
+
+static int it913x_write_reg(struct it913x_fe_state *state,
+               u8 pro, u32 reg, u32 data)
+{
+       int ret;
+       u8 b[4];
+       u8 s;
+
+       b[0] = data >> 24;
+       b[1] = (data >> 16) & 0xff;
+       b[2] = (data >> 8) & 0xff;
+       b[3] = data & 0xff;
+       /* expand write as needed */
+       if (data < 0x100)
+               s = 3;
+       else if (data < 0x1000)
+               s = 2;
+       else if (data < 0x100000)
+               s = 1;
+       else
+               s = 0;
+
+       ret = it913x_write(state, pro, reg, &b[s], sizeof(b) - s);
+
+       return ret;
+}
+
+static int it913x_fe_script_loader(struct it913x_fe_state *state,
+               struct it913xset *loadscript)
+{
+       int ret, i;
+       if (loadscript == NULL)
+               return -EINVAL;
+
+       for (i = 0; i < 1000; ++i) {
+               if (loadscript[i].pro == 0xff)
+                       break;
+               ret = it913x_write(state, loadscript[i].pro,
+                       loadscript[i].address,
+                       loadscript[i].reg, loadscript[i].count);
+               if (ret < 0)
+                       return -ENODEV;
+       }
+       return 0;
+}
+
+static int it913x_init_tuner(struct it913x_fe_state *state)
+{
+       int ret, i, reg;
+       u8 val, nv_val;
+       u8 nv[] = {48, 32, 24, 16, 12, 8, 6, 4, 2};
+       u8 b[2];
+
+       reg = it913x_read_reg_u8(state, 0xec86);
+       switch (reg) {
+       case 0:
+               state->tun_clk_mode = reg;
+               state->tun_xtal = 2000;
+               state->tun_fdiv = 3;
+               val = 16;
+               break;
+       case -ENODEV:
+               return -ENODEV;
+       case 1:
+       default:
+               state->tun_clk_mode = reg;
+               state->tun_xtal = 640;
+               state->tun_fdiv = 1;
+               val = 6;
+               break;
+       }
+
+       reg = it913x_read_reg_u8(state, 0xed03);
+
+       if (reg < 0)
+               return -ENODEV;
+       else if (reg < sizeof(nv))
+               nv_val = nv[reg];
+       else
+               nv_val = 2;
+
+       for (i = 0; i < 50; i++) {
+               ret = it913x_read_reg(state, 0xed23, &b[0], sizeof(b));
+               reg = (b[1] << 8) + b[0];
+               if (reg > 0)
+                       break;
+               if (ret < 0)
+                       return -ENODEV;
+               udelay(2000);
+       }
+       state->tun_fn_min = state->tun_xtal * reg;
+       state->tun_fn_min /= (state->tun_fdiv * nv_val);
+       deb_info("Tuner fn_min %d", state->tun_fn_min);
+
+       for (i = 0; i < 50; i++) {
+               reg = it913x_read_reg_u8(state, 0xec82);
+               if (reg > 0)
+                       break;
+               if (reg < 0)
+                       return -ENODEV;
+               udelay(2000);
+       }
+
+       return it913x_write_reg(state, PRO_DMOD, 0xed81, val);
+}
+
+static int it9137_set_tuner(struct it913x_fe_state *state,
+               enum fe_bandwidth bandwidth, u32 frequency_m)
+{
+       struct it913xset *set_tuner = set_it9137_template;
+       int ret, reg;
+       u32 frequency = frequency_m / 1000;
+       u32 freq, temp_f, tmp;
+       u16 iqik_m_cal;
+       u16 n_div;
+       u8 n;
+       u8 l_band;
+       u8 lna_band;
+       u8 bw;
+
+       deb_info("Tuner Frequency %d Bandwidth %d", frequency, bandwidth);
+
+       if (frequency >= 51000 && frequency <= 440000) {
+               l_band = 0;
+               lna_band = 0;
+       } else if (frequency > 440000 && frequency <= 484000) {
+               l_band = 1;
+               lna_band = 1;
+       } else if (frequency > 484000 && frequency <= 533000) {
+               l_band = 1;
+               lna_band = 2;
+       } else if (frequency > 533000 && frequency <= 587000) {
+               l_band = 1;
+               lna_band = 3;
+       } else if (frequency > 587000 && frequency <= 645000) {
+               l_band = 1;
+               lna_band = 4;
+       } else if (frequency > 645000 && frequency <= 710000) {
+               l_band = 1;
+               lna_band = 5;
+       } else if (frequency > 710000 && frequency <= 782000) {
+               l_band = 1;
+               lna_band = 6;
+       } else if (frequency > 782000 && frequency <= 860000) {
+               l_band = 1;
+               lna_band = 7;
+       } else if (frequency > 1450000 && frequency <= 1492000) {
+               l_band = 1;
+               lna_band = 0;
+       } else if (frequency > 1660000 && frequency <= 1685000) {
+               l_band = 1;
+               lna_band = 1;
+       } else
+               return -EINVAL;
+       set_tuner[0].reg[0] = lna_band;
+
+       if (bandwidth == BANDWIDTH_5_MHZ)
+               bw = 0;
+       else if (bandwidth == BANDWIDTH_6_MHZ)
+               bw = 2;
+       else if (bandwidth == BANDWIDTH_7_MHZ)
+               bw = 4;
+       else if (bandwidth == BANDWIDTH_8_MHZ)
+               bw = 6;
+       else
+               bw = 6;
+
+       set_tuner[1].reg[0] = bw;
+       set_tuner[2].reg[0] = 0xa0 | (l_band << 3);
+
+       if (frequency > 53000 && frequency <= 74000) {
+               n_div = 48;
+               n = 0;
+       } else if (frequency > 74000 && frequency <= 111000) {
+               n_div = 32;
+               n = 1;
+       } else if (frequency > 111000 && frequency <= 148000) {
+               n_div = 24;
+               n = 2;
+       } else if (frequency > 148000 && frequency <= 222000) {
+               n_div = 16;
+               n = 3;
+       } else if (frequency > 222000 && frequency <= 296000) {
+               n_div = 12;
+               n = 4;
+       } else if (frequency > 296000 && frequency <= 445000) {
+               n_div = 8;
+               n = 5;
+       } else if (frequency > 445000 && frequency <= state->tun_fn_min) {
+               n_div = 6;
+               n = 6;
+       } else if (frequency > state->tun_fn_min && frequency <= 950000) {
+               n_div = 4;
+               n = 7;
+       } else if (frequency > 1450000 && frequency <= 1680000) {
+               n_div = 2;
+               n = 0;
+       } else
+               return -EINVAL;
+
+       reg = it913x_read_reg_u8(state, 0xed81);
+       iqik_m_cal = (u16)reg * n_div;
+
+       if (reg < 0x20) {
+               if (state->tun_clk_mode == 0)
+                       iqik_m_cal = (iqik_m_cal * 9) >> 5;
+               else
+                       iqik_m_cal >>= 1;
+       } else {
+               iqik_m_cal = 0x40 - iqik_m_cal;
+               if (state->tun_clk_mode == 0)
+                       iqik_m_cal = ~((iqik_m_cal * 9) >> 5);
+               else
+                       iqik_m_cal = ~(iqik_m_cal >> 1);
+       }
+
+       temp_f = frequency * (u32)n_div * (u32)state->tun_fdiv;
+       freq = temp_f / state->tun_xtal;
+       tmp = freq * state->tun_xtal;
+
+       if ((temp_f - tmp) >= (state->tun_xtal >> 1))
+               freq++;
+
+       freq += (u32) n << 13;
+       /* Frequency OMEGA_IQIK_M_CAL_MID*/
+       temp_f = freq + (u32)iqik_m_cal;
+
+       set_tuner[3].reg[0] =  temp_f & 0xff;
+       set_tuner[4].reg[0] =  (temp_f >> 8) & 0xff;
+
+       deb_info("High Frequency = %04x", temp_f);
+
+       /* Lower frequency */
+       set_tuner[5].reg[0] =  freq & 0xff;
+       set_tuner[6].reg[0] =  (freq >> 8) & 0xff;
+
+       deb_info("low Frequency = %04x", freq);
+
+       ret = it913x_fe_script_loader(state, set_tuner);
+
+       return (ret < 0) ? -ENODEV : 0;
+}
+
+static int it913x_fe_select_bw(struct it913x_fe_state *state,
+                       enum fe_bandwidth bandwidth, u32 adcFrequency)
+{
+       int ret, i;
+       u8 buffer[256];
+       u32 coeff[8];
+       u16 bfsfcw_fftinx_ratio;
+       u16 fftinx_bfsfcw_ratio;
+       u8 count;
+       u8 bw;
+       u8 adcmultiplier;
+
+       deb_info("Bandwidth %d Adc %d", bandwidth, adcFrequency);
+
+       if (bandwidth == BANDWIDTH_5_MHZ)
+               bw = 3;
+       else if (bandwidth == BANDWIDTH_6_MHZ)
+               bw = 0;
+       else if (bandwidth == BANDWIDTH_7_MHZ)
+               bw = 1;
+       else if (bandwidth == BANDWIDTH_8_MHZ)
+               bw = 2;
+       else
+               bw = 2;
+
+       ret = it913x_write_reg(state, PRO_DMOD, REG_BW, bw);
+
+       if (state->table == NULL)
+               return -EINVAL;
+
+       /* In write order */
+       coeff[0] = state->table[bw].coeff_1_2048;
+       coeff[1] = state->table[bw].coeff_2_2k;
+       coeff[2] = state->table[bw].coeff_1_8191;
+       coeff[3] = state->table[bw].coeff_1_8192;
+       coeff[4] = state->table[bw].coeff_1_8193;
+       coeff[5] = state->table[bw].coeff_2_8k;
+       coeff[6] = state->table[bw].coeff_1_4096;
+       coeff[7] = state->table[bw].coeff_2_4k;
+       bfsfcw_fftinx_ratio = state->table[bw].bfsfcw_fftinx_ratio;
+       fftinx_bfsfcw_ratio = state->table[bw].fftinx_bfsfcw_ratio;
+
+       /* ADC multiplier */
+       ret = it913x_read_reg_u8(state, ADC_X_2);
+       if (ret < 0)
+               return -EINVAL;
+
+       adcmultiplier = ret;
+
+       count = 0;
+
+       /*  Build Buffer for COEFF Registers */
+       for (i = 0; i < 8; i++) {
+               if (adcmultiplier == 1)
+                       coeff[i] /= 2;
+               buffer[count++] = (coeff[i] >> 24) & 0x3;
+               buffer[count++] = (coeff[i] >> 16) & 0xff;
+               buffer[count++] = (coeff[i] >> 8) & 0xff;
+               buffer[count++] = coeff[i] & 0xff;
+       }
+
+       /* bfsfcw_fftinx_ratio register 0x21-0x22 */
+       buffer[count++] = bfsfcw_fftinx_ratio & 0xff;
+       buffer[count++] = (bfsfcw_fftinx_ratio >> 8) & 0xff;
+       /* fftinx_bfsfcw_ratio register 0x23-0x24 */
+       buffer[count++] = fftinx_bfsfcw_ratio & 0xff;
+       buffer[count++] = (fftinx_bfsfcw_ratio >> 8) & 0xff;
+       /* start at COEFF_1_2048 and write through to fftinx_bfsfcw_ratio*/
+       ret = it913x_write(state, PRO_DMOD, COEFF_1_2048, buffer, count);
+
+       for (i = 0; i < 42; i += 8)
+               debug_data_snipet(0x1, "Buffer", &buffer[i]);
+
+       return ret;
+}
+
+
+
+static int it913x_fe_read_status(struct dvb_frontend *fe, fe_status_t *status)
+{
+       struct it913x_fe_state *state = fe->demodulator_priv;
+       int ret, i;
+       fe_status_t old_status = state->it913x_status;
+       *status = 0;
+
+       if (state->it913x_status == 0) {
+               ret = it913x_read_reg_u8(state, EMPTY_CHANNEL_STATUS);
+               if (ret == 0x1) {
+                       *status |= FE_HAS_SIGNAL;
+                       for (i = 0; i < 40; i++) {
+                               ret = it913x_read_reg_u8(state, MP2IF_SYNC_LK);
+                               if (ret == 0x1)
+                                       break;
+                               msleep(25);
+                       }
+                       if (ret == 0x1)
+                               *status |= FE_HAS_CARRIER
+                                       | FE_HAS_VITERBI
+                                       | FE_HAS_SYNC;
+                       state->it913x_status = *status;
+               }
+       }
+
+       if (state->it913x_status & FE_HAS_SYNC) {
+               ret = it913x_read_reg_u8(state, TPSD_LOCK);
+               if (ret == 0x1)
+                       *status |= FE_HAS_LOCK
+                               | state->it913x_status;
+               else
+                       state->it913x_status = 0;
+               if (old_status != state->it913x_status)
+                       ret = it913x_write_reg(state, PRO_LINK, GPIOH3_O, ret);
+       }
+
+       return 0;
+}
+
+static int it913x_fe_read_signal_strength(struct dvb_frontend *fe,
+               u16 *strength)
+{
+       struct it913x_fe_state *state = fe->demodulator_priv;
+       int ret = it913x_read_reg_u8(state, SIGNAL_LEVEL);
+       /*SIGNAL_LEVEL always returns 100%! so using FE_HAS_SIGNAL as switch*/
+       if (state->it913x_status & FE_HAS_SIGNAL)
+               ret = (ret * 0xff) / 0x64;
+       else
+               ret = 0x0;
+       ret |= ret << 0x8;
+       *strength = ret;
+       return 0;
+}
+
+static int it913x_fe_read_snr(struct dvb_frontend *fe, u16* snr)
+{
+       struct it913x_fe_state *state = fe->demodulator_priv;
+       int ret = it913x_read_reg_u8(state, SIGNAL_QUALITY);
+       ret = (ret * 0xff) / 0x64;
+       ret |= (ret << 0x8);
+       *snr = ~ret;
+       return 0;
+}
+
+static int it913x_fe_read_ber(struct dvb_frontend *fe, u32 *ber)
+{
+       *ber = 0;
+       return 0;
+}
+
+static int it913x_fe_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
+{
+       *ucblocks = 0;
+       return 0;
+}
+
+static int it913x_fe_get_frontend(struct dvb_frontend *fe,
+                       struct dvb_frontend_parameters *p)
+{
+       struct it913x_fe_state *state = fe->demodulator_priv;
+       int ret;
+       u8 reg[8];
+
+       ret = it913x_read_reg(state, REG_TPSD_TX_MODE, reg, sizeof(reg));
+
+       if (reg[3] < 3)
+               p->u.ofdm.constellation = fe_con[reg[3]];
+
+       if (reg[0] < 3)
+               p->u.ofdm.transmission_mode = fe_mode[reg[0]];
+
+       if (reg[1] < 4)
+               p->u.ofdm.guard_interval = fe_gi[reg[1]];
+
+       if (reg[2] < 4)
+               p->u.ofdm.hierarchy_information = fe_hi[reg[2]];
+
+       p->u.ofdm.code_rate_HP = (reg[6] < 6) ? fe_code[reg[6]] : FEC_NONE;
+       p->u.ofdm.code_rate_LP = (reg[7] < 6) ? fe_code[reg[7]] : FEC_NONE;
+
+       return 0;
+}
+
+static int it913x_fe_set_frontend(struct dvb_frontend *fe,
+                       struct dvb_frontend_parameters *p)
+{
+       struct it913x_fe_state *state = fe->demodulator_priv;
+       int ret, i;
+       u8 empty_ch, last_ch;
+
+       state->it913x_status = 0;
+
+       /* Set bw*/
+       ret = it913x_fe_select_bw(state, p->u.ofdm.bandwidth,
+               state->adcFrequency);
+
+       /* Training Mode Off */
+       ret = it913x_write_reg(state, PRO_LINK, TRAINING_MODE, 0x0);
+
+       /* Clear Empty Channel */
+       ret = it913x_write_reg(state, PRO_DMOD, EMPTY_CHANNEL_STATUS, 0x0);
+
+       /* Clear bits */
+       ret = it913x_write_reg(state, PRO_DMOD, MP2IF_SYNC_LK, 0x0);
+       /* LED on */
+       ret = it913x_write_reg(state, PRO_LINK, GPIOH3_O, 0x1);
+       /* Select Band*/
+       if ((p->frequency >= 51000000) && (p->frequency <= 230000000))
+               i = 0;
+       else if ((p->frequency >= 350000000) && (p->frequency <= 900000000))
+                       i = 1;
+       else if ((p->frequency >= 1450000000) && (p->frequency <= 1680000000))
+                       i = 2;
+               else
+                       return -EOPNOTSUPP;
+
+       ret = it913x_write_reg(state, PRO_DMOD, FREE_BAND, i);
+
+       deb_info("Frontend Set Tuner Type %02x", state->tuner_type);
+       switch (state->tuner_type) {
+       case IT9137: /* Tuner type 0x38 */
+               ret = it9137_set_tuner(state,
+                       p->u.ofdm.bandwidth, p->frequency);
+               break;
+       default:
+               if (fe->ops.tuner_ops.set_params) {
+                       fe->ops.tuner_ops.set_params(fe, p);
+                       if (fe->ops.i2c_gate_ctrl)
+                               fe->ops.i2c_gate_ctrl(fe, 0);
+               }
+               break;
+       }
+       /* LED off */
+       ret = it913x_write_reg(state, PRO_LINK, GPIOH3_O, 0x0);
+       /* Trigger ofsm */
+       ret = it913x_write_reg(state, PRO_DMOD, TRIGGER_OFSM, 0x0);
+       last_ch = 2;
+       for (i = 0; i < 40; ++i) {
+               empty_ch = it913x_read_reg_u8(state, EMPTY_CHANNEL_STATUS);
+               if (last_ch == 1 && empty_ch == 1)
+                       break;
+               if (last_ch == 2 && empty_ch == 2)
+                       return 0;
+               last_ch = empty_ch;
+               msleep(25);
+       }
+       for (i = 0; i < 40; ++i) {
+               if (it913x_read_reg_u8(state, D_TPSD_LOCK) == 1)
+                       break;
+               msleep(25);
+       }
+
+       state->frequency = p->frequency;
+       return 0;
+}
+
+static int it913x_fe_suspend(struct it913x_fe_state *state)
+{
+       int ret, i;
+       u8 b;
+
+       ret = it913x_write_reg(state, PRO_DMOD, SUSPEND_FLAG, 0x1);
+
+       ret |= it913x_write_reg(state, PRO_DMOD, TRIGGER_OFSM, 0x0);
+
+       for (i = 0; i < 128; i++) {
+               ret = it913x_read_reg(state, SUSPEND_FLAG, &b, 1);
+               if (ret < 0)
+                       return -ENODEV;
+               if (b == 0)
+                       break;
+
+       }
+
+       ret |= it913x_write_reg(state, PRO_DMOD, AFE_MEM0, 0x8);
+       /* Turn LED off */
+       ret |= it913x_write_reg(state, PRO_LINK, GPIOH3_O, 0x0);
+
+       ret |= it913x_fe_script_loader(state, it9137_tuner_off);
+
+       return (ret < 0) ? -ENODEV : 0;
+}
+
+/* Power sequence */
+/* Power Up    Tuner on -> Frontend suspend off -> Tuner clk on */
+/* Power Down  Frontend suspend on -> Tuner clk off -> Tuner off */
+
+static int it913x_fe_sleep(struct dvb_frontend *fe)
+{
+       struct it913x_fe_state *state = fe->demodulator_priv;
+       return it913x_fe_suspend(state);
+}
+
+static u32 compute_div(u32 a, u32 b, u32 x)
+{
+       u32 res = 0;
+       u32 c = 0;
+       u32 i = 0;
+
+       if (a > b) {
+               c = a / b;
+               a = a - c * b;
+       }
+
+       for (i = 0; i < x; i++) {
+               if (a >= b) {
+                       res += 1;
+                       a -= b;
+               }
+               a <<= 1;
+               res <<= 1;
+       }
+
+       res = (c << x) + res;
+
+       return res;
+}
+
+static int it913x_fe_start(struct it913x_fe_state *state)
+{
+       struct it913xset *set_fe;
+       struct it913xset *set_mode;
+       int ret;
+       u8 adf = (state->adf & 0xf);
+       u32 adc, xtal;
+       u8 b[4];
+
+       ret = it913x_init_tuner(state);
+
+       if (adf < 12) {
+               state->crystalFrequency = fe_clockTable[adf].xtal ;
+               state->table = fe_clockTable[adf].table;
+               state->adcFrequency = state->table->adcFrequency;
+
+               adc = compute_div(state->adcFrequency, 1000000ul, 19ul);
+               xtal = compute_div(state->crystalFrequency, 1000000ul, 19ul);
+
+       } else
+               return -EINVAL;
+
+       deb_info("Xtal Freq :%d Adc Freq :%d Adc %08x Xtal %08x",
+               state->crystalFrequency, state->adcFrequency, adc, xtal);
+
+       /* Set LED indicator on GPIOH3 */
+       ret = it913x_write_reg(state, PRO_LINK, GPIOH3_EN, 0x1);
+       ret |= it913x_write_reg(state, PRO_LINK, GPIOH3_ON, 0x1);
+       ret |= it913x_write_reg(state, PRO_LINK, GPIOH3_O, 0x1);
+
+       ret |= it913x_write_reg(state, PRO_LINK, 0xf641, state->tuner_type);
+       ret |= it913x_write_reg(state, PRO_DMOD, 0xf5ca, 0x01);
+       ret |= it913x_write_reg(state, PRO_DMOD, 0xf715, 0x01);
+
+       b[0] = xtal & 0xff;
+       b[1] = (xtal >> 8) & 0xff;
+       b[2] = (xtal >> 16) & 0xff;
+       b[3] = (xtal >> 24);
+       ret |= it913x_write(state, PRO_DMOD, XTAL_CLK, b , 4);
+
+       b[0] = adc & 0xff;
+       b[1] = (adc >> 8) & 0xff;
+       b[2] = (adc >> 16) & 0xff;
+       ret |= it913x_write(state, PRO_DMOD, ADC_FREQ, b, 3);
+
+       switch (state->tuner_type) {
+       case IT9137: /* Tuner type 0x38 */
+               set_fe = it9137_set;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       /* set the demod */
+       ret = it913x_fe_script_loader(state, set_fe);
+       /* Always solo frontend */
+       set_mode = set_solo_fe;
+       ret |= it913x_fe_script_loader(state, set_mode);
+
+       ret |= it913x_fe_suspend(state);
+       return 0;
+}
+
+static int it913x_fe_init(struct dvb_frontend *fe)
+{
+       struct it913x_fe_state *state = fe->demodulator_priv;
+       int ret = 0;
+       /* Power Up Tuner - common all versions */
+       ret = it913x_write_reg(state, PRO_DMOD, 0xec40, 0x1);
+
+       ret |= it913x_write_reg(state, PRO_DMOD, AFE_MEM0, 0x0);
+
+       ret |= it913x_fe_script_loader(state, init_1);
+
+       switch (state->tuner_type) {
+       case IT9137:
+               ret |= it913x_write_reg(state, PRO_DMOD, 0xfba8, 0x0);
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return (ret < 0) ? -ENODEV : 0;
+}
+
+static void it913x_fe_release(struct dvb_frontend *fe)
+{
+       struct it913x_fe_state *state = fe->demodulator_priv;
+       kfree(state);
+}
+
+static struct dvb_frontend_ops it913x_fe_ofdm_ops;
+
+struct dvb_frontend *it913x_fe_attach(struct i2c_adapter *i2c_adap,
+               u8 i2c_addr, u8 adf, u8 type)
+{
+       struct it913x_fe_state *state = NULL;
+       int ret;
+       /* allocate memory for the internal state */
+       state = kzalloc(sizeof(struct it913x_fe_state), GFP_KERNEL);
+       if (state == NULL)
+               goto error;
+
+       state->i2c_adap = i2c_adap;
+       state->i2c_addr = i2c_addr;
+       state->adf = adf;
+       state->tuner_type = type;
+
+       ret = it913x_fe_start(state);
+       if (ret < 0)
+               goto error;
+
+
+       /* create dvb_frontend */
+       memcpy(&state->frontend.ops, &it913x_fe_ofdm_ops,
+                       sizeof(struct dvb_frontend_ops));
+       state->frontend.demodulator_priv = state;
+
+       return &state->frontend;
+error:
+       kfree(state);
+       return NULL;
+}
+EXPORT_SYMBOL(it913x_fe_attach);
+
+static struct dvb_frontend_ops it913x_fe_ofdm_ops = {
+
+       .info = {
+               .name                   = "it913x-fe DVB-T",
+               .type                   = FE_OFDM,
+               .frequency_min          = 51000000,
+               .frequency_max          = 1680000000,
+               .frequency_stepsize     = 62500,
+               .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
+                       FE_CAN_FEC_4_5 | FE_CAN_FEC_5_6 | FE_CAN_FEC_6_7 |
+                       FE_CAN_FEC_7_8 | FE_CAN_FEC_8_9 | FE_CAN_FEC_AUTO |
+                       FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
+                       FE_CAN_TRANSMISSION_MODE_AUTO |
+                       FE_CAN_GUARD_INTERVAL_AUTO |
+                       FE_CAN_HIERARCHY_AUTO,
+       },
+
+       .release = it913x_fe_release,
+
+       .init = it913x_fe_init,
+       .sleep = it913x_fe_sleep,
+
+       .set_frontend = it913x_fe_set_frontend,
+       .get_frontend = it913x_fe_get_frontend,
+
+       .read_status = it913x_fe_read_status,
+       .read_signal_strength = it913x_fe_read_signal_strength,
+       .read_snr = it913x_fe_read_snr,
+       .read_ber = it913x_fe_read_ber,
+       .read_ucblocks = it913x_fe_read_ucblocks,
+};
+
+MODULE_DESCRIPTION("it913x Frontend and it9137 tuner");
+MODULE_AUTHOR("Malcolm Priestley tvboxspy@gmail.com");
+MODULE_VERSION("1.07");
+MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/it913x-fe.h b/drivers/media/dvb/frontends/it913x-fe.h
new file mode 100644 (file)
index 0000000..9d97f32
--- /dev/null
@@ -0,0 +1,196 @@
+/*
+ *  Driver for it913x Frontend
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.=
+ */
+
+#ifndef IT913X_FE_H
+#define IT913X_FE_H
+
+#include <linux/dvb/frontend.h>
+#include "dvb_frontend.h"
+#if defined(CONFIG_DVB_IT913X_FE) || (defined(CONFIG_DVB_IT913X_FE_MODULE) && \
+defined(MODULE))
+extern struct dvb_frontend *it913x_fe_attach(struct i2c_adapter *i2c_adap,
+                       u8 i2c_addr, u8 adf, u8 type);
+#else
+static inline struct dvb_frontend *it913x_fe_attach(
+               struct i2c_adapter *i2c_adap,   u8 i2c_addr, u8 adf, u8 type)
+{
+       printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
+       return NULL;
+}
+#endif /* CONFIG_IT913X_FE */
+#define I2C_BASE_ADDR          0x10
+#define DEV_0                  0x0
+#define DEV_1                  0x10
+#define PRO_LINK               0x0
+#define PRO_DMOD               0x1
+#define DEV_0_DMOD             (PRO_DMOD << 0x7)
+#define DEV_1_DMOD             (DEV_0_DMOD | DEV_1)
+#define CHIP2_I2C_ADDR         0x3a
+
+#define AFE_MEM0               0xfb24
+
+#define MP2_SW_RST             0xf99d
+#define MP2IF2_SW_RST          0xf9a4
+
+#define        PADODPU                 0xd827
+#define THIRDODPU              0xd828
+#define AGC_O_D                        0xd829
+
+#define EP0_TX_EN              0xdd11
+#define EP0_TX_NAK             0xdd13
+#define EP4_TX_LEN_LSB         0xdd88
+#define EP4_TX_LEN_MSB         0xdd89
+#define EP4_MAX_PKT            0xdd0c
+#define EP5_TX_LEN_LSB         0xdd8a
+#define EP5_TX_LEN_MSB         0xdd8b
+#define EP5_MAX_PKT            0xdd0d
+
+#define IO_MUX_POWER_CLK       0xd800
+#define CLK_O_EN               0xd81a
+#define I2C_CLK                        0xf103
+#define I2C_CLK_100            0x7
+#define I2C_CLK_400            0x1a
+
+#define D_TPSD_LOCK            0xf5a9
+#define MP2IF2_EN              0xf9a3
+#define MP2IF_SERIAL           0xf985
+#define TSIS_ENABLE            0xf9cd
+#define MP2IF2_HALF_PSB                0xf9a5
+#define MP2IF_STOP_EN          0xf9b5
+#define MPEG_FULL_SPEED                0xf990
+#define TOP_HOSTB_SER_MODE     0xd91c
+
+#define PID_RST                        0xf992
+#define PID_EN                 0xf993
+#define PID_INX_EN             0xf994
+#define PID_INX                        0xf995
+#define PID_LSB                        0xf996
+#define PID_MSB                        0xf997
+
+#define MP2IF_MPEG_PAR_MODE    0xf986
+#define DCA_UPPER_CHIP         0xf731
+#define DCA_LOWER_CHIP         0xf732
+#define DCA_PLATCH             0xf730
+#define DCA_FPGA_LATCH         0xf778
+#define DCA_STAND_ALONE                0xf73c
+#define DCA_ENABLE             0xf776
+
+#define DVBT_INTEN             0xf41f
+#define DVBT_ENABLE            0xf41a
+#define HOSTB_DCA_LOWER                0xd91f
+#define HOSTB_MPEG_PAR_MODE    0xd91b
+#define HOSTB_MPEG_SER_MODE    0xd91c
+#define HOSTB_MPEG_SER_DO7     0xd91d
+#define HOSTB_DCA_UPPER                0xd91e
+#define PADMISCDR2             0xd830
+#define PADMISCDR4             0xd831
+#define PADMISCDR8             0xd832
+#define PADMISCDRSR            0xd833
+#define LOCK3_OUT              0xd8fd
+
+#define GPIOH1_O               0xd8af
+#define GPIOH1_EN              0xd8b0
+#define GPIOH1_ON              0xd8b1
+#define GPIOH3_O               0xd8b3
+#define GPIOH3_EN              0xd8b4
+#define GPIOH3_ON              0xd8b5
+#define GPIOH5_O               0xd8bb
+#define GPIOH5_EN              0xd8bc
+#define GPIOH5_ON              0xd8bd
+
+#define AFE_MEM0               0xfb24
+
+#define REG_TPSD_TX_MODE       0xf900
+#define REG_TPSD_GI            0xf901
+#define REG_TPSD_HIER          0xf902
+#define REG_TPSD_CONST         0xf903
+#define REG_BW                 0xf904
+#define REG_PRIV               0xf905
+#define REG_TPSD_HP_CODE       0xf906
+#define REG_TPSD_LP_CODE       0xf907
+
+#define MP2IF_SYNC_LK          0xf999
+#define ADC_FREQ               0xf1cd
+
+#define TRIGGER_OFSM           0x0000
+/* COEFF Registers start at 0x0001 to 0x0020 */
+#define COEFF_1_2048           0x0001
+#define XTAL_CLK               0x0025
+#define BFS_FCW                        0x0029
+#define TPSD_LOCK              0x003c
+#define TRAINING_MODE          0x0040
+#define ADC_X_2                        0x0045
+#define TUNER_ID               0x0046
+#define EMPTY_CHANNEL_STATUS   0x0047
+#define SIGNAL_LEVEL           0x0048
+#define SIGNAL_QUALITY         0x0049
+#define EST_SIGNAL_LEVEL       0x004a
+#define FREE_BAND              0x004b
+#define SUSPEND_FLAG           0x004c
+/* Build in tuners */
+#define IT9137 0x38
+
+enum {
+       CMD_DEMOD_READ = 0,
+       CMD_DEMOD_WRITE,
+       CMD_TUNER_READ,
+       CMD_TUNER_WRITE,
+       CMD_REG_EEPROM_READ,
+       CMD_REG_EEPROM_WRITE,
+       CMD_DATA_READ,
+       CMD_VAR_READ = 8,
+       CMD_VAR_WRITE,
+       CMD_PLATFORM_GET,
+       CMD_PLATFORM_SET,
+       CMD_IP_CACHE,
+       CMD_IP_ADD,
+       CMD_IP_REMOVE,
+       CMD_PID_ADD,
+       CMD_PID_REMOVE,
+       CMD_SIPSI_GET,
+       CMD_SIPSI_MPE_RESET,
+       CMD_H_PID_ADD = 0x15,
+       CMD_H_PID_REMOVE,
+       CMD_ABORT,
+       CMD_IR_GET,
+       CMD_IR_SET,
+       CMD_FW_DOWNLOAD = 0x21,
+       CMD_QUERYINFO,
+       CMD_BOOT,
+       CMD_FW_DOWNLOAD_BEGIN,
+       CMD_FW_DOWNLOAD_END,
+       CMD_RUN_CODE,
+       CMD_SCATTER_READ = 0x28,
+       CMD_SCATTER_WRITE,
+       CMD_GENERIC_READ,
+       CMD_GENERIC_WRITE
+};
+
+enum {
+       READ_LONG,
+       WRITE_LONG,
+       READ_SHORT,
+       WRITE_SHORT,
+       READ_DATA,
+       WRITE_DATA,
+       WRITE_CMD,
+};
+
+#endif /* IT913X_FE_H */
diff --git a/drivers/media/dvb/frontends/lnbp22.c b/drivers/media/dvb/frontends/lnbp22.c
new file mode 100644 (file)
index 0000000..84ad039
--- /dev/null
@@ -0,0 +1,148 @@
+/*
+ * lnbp22.h - driver for lnb supply and control ic lnbp22
+ *
+ * Copyright (C) 2006 Dominik Kuhlen
+ * Based on lnbp21 driver
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
+ *
+ *
+ * the project's page is at http://www.linuxtv.org
+ */
+#include <linux/delay.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/string.h>
+#include <linux/slab.h>
+
+#include "dvb_frontend.h"
+#include "lnbp22.h"
+
+static int debug;
+module_param(debug, int, 0644);
+MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
+
+
+#define dprintk(lvl, arg...) if (debug >= (lvl)) printk(arg)
+
+struct lnbp22 {
+       u8                  config[4];
+       struct i2c_adapter *i2c;
+};
+
+static int lnbp22_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
+{
+       struct lnbp22 *lnbp22 = (struct lnbp22 *)fe->sec_priv;
+       struct i2c_msg msg = {
+               .addr = 0x08,
+               .flags = 0,
+               .buf = (char *)&lnbp22->config,
+               .len = sizeof(lnbp22->config),
+       };
+
+       dprintk(1, "%s: %d (18V=%d 13V=%d)\n", __func__, voltage,
+              SEC_VOLTAGE_18, SEC_VOLTAGE_13);
+
+       lnbp22->config[3] = 0x60; /* Power down */
+       switch (voltage) {
+       case SEC_VOLTAGE_OFF:
+               break;
+       case SEC_VOLTAGE_13:
+               lnbp22->config[3] |= LNBP22_EN;
+               break;
+       case SEC_VOLTAGE_18:
+               lnbp22->config[3] |= (LNBP22_EN | LNBP22_VSEL);
+               break;
+       default:
+               return -EINVAL;
+       };
+
+       dprintk(1, "%s: 0x%02x)\n", __func__, lnbp22->config[3]);
+       return (i2c_transfer(lnbp22->i2c, &msg, 1) == 1) ? 0 : -EIO;
+}
+
+static int lnbp22_enable_high_lnb_voltage(struct dvb_frontend *fe, long arg)
+{
+       struct lnbp22 *lnbp22 = (struct lnbp22 *) fe->sec_priv;
+       struct i2c_msg msg = {
+               .addr = 0x08,
+               .flags = 0,
+               .buf = (char *)&lnbp22->config,
+               .len = sizeof(lnbp22->config),
+       };
+
+       dprintk(1, "%s: %d\n", __func__, (int)arg);
+       if (arg)
+               lnbp22->config[3] |= LNBP22_LLC;
+       else
+               lnbp22->config[3] &= ~LNBP22_LLC;
+
+       return (i2c_transfer(lnbp22->i2c, &msg, 1) == 1) ? 0 : -EIO;
+}
+
+static void lnbp22_release(struct dvb_frontend *fe)
+{
+       dprintk(1, "%s\n", __func__);
+       /* LNBP power off */
+       lnbp22_set_voltage(fe, SEC_VOLTAGE_OFF);
+
+       /* free data */
+       kfree(fe->sec_priv);
+       fe->sec_priv = NULL;
+}
+
+struct dvb_frontend *lnbp22_attach(struct dvb_frontend *fe,
+                                       struct i2c_adapter *i2c)
+{
+       struct lnbp22 *lnbp22 = kmalloc(sizeof(struct lnbp22), GFP_KERNEL);
+       if (!lnbp22)
+               return NULL;
+
+       /* default configuration */
+       lnbp22->config[0] = 0x00; /* ? */
+       lnbp22->config[1] = 0x28; /* ? */
+       lnbp22->config[2] = 0x48; /* ? */
+       lnbp22->config[3] = 0x60; /* Power down */
+       lnbp22->i2c = i2c;
+       fe->sec_priv = lnbp22;
+
+       /* detect if it is present or not */
+       if (lnbp22_set_voltage(fe, SEC_VOLTAGE_OFF)) {
+               dprintk(0, "%s LNBP22 not found\n", __func__);
+               kfree(lnbp22);
+               fe->sec_priv = NULL;
+               return NULL;
+       }
+
+       /* install release callback */
+       fe->ops.release_sec = lnbp22_release;
+
+       /* override frontend ops */
+       fe->ops.set_voltage = lnbp22_set_voltage;
+       fe->ops.enable_high_lnb_voltage = lnbp22_enable_high_lnb_voltage;
+
+       return fe;
+}
+EXPORT_SYMBOL(lnbp22_attach);
+
+MODULE_DESCRIPTION("Driver for lnb supply and control ic lnbp22");
+MODULE_AUTHOR("Dominik Kuhlen");
+MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/lnbp22.h b/drivers/media/dvb/frontends/lnbp22.h
new file mode 100644 (file)
index 0000000..63e2dec
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * lnbp22.h - driver for lnb supply and control ic lnbp22
+ *
+ * Copyright (C) 2006 Dominik Kuhlen
+ * Based on lnbp21.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
+ *
+ *
+ * the project's page is at http://www.linuxtv.org
+ */
+
+#ifndef _LNBP22_H
+#define _LNBP22_H
+
+/* Enable */
+#define LNBP22_EN        0x10
+/* Voltage selection */
+#define LNBP22_VSEL    0x02
+/* Plus 1 Volt Bit */
+#define LNBP22_LLC     0x01
+
+#include <linux/dvb/frontend.h>
+
+#if defined(CONFIG_DVB_LNBP22) || \
+               (defined(CONFIG_DVB_LNBP22_MODULE) && defined(MODULE))
+/*
+ * override_set and override_clear control which system register bits (above)
+ * to always set & clear
+ */
+extern struct dvb_frontend *lnbp22_attach(struct dvb_frontend *fe,
+                                               struct i2c_adapter *i2c);
+#else
+static inline struct dvb_frontend *lnbp22_attach(struct dvb_frontend *fe,
+                                               struct i2c_adapter *i2c)
+{
+       printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
+       return NULL;
+}
+#endif /* CONFIG_DVB_LNBP22 */
+
+#endif /* _LNBP22_H */
index d70eee00f33a5d33fbefef13860f20ba15c020c4..117a56926dcad041316a53f4ea47ed3c7263505f 100644 (file)
@@ -358,6 +358,9 @@ static enum stb0899_status stb0899_check_data(struct stb0899_state *state)
        else
                dataTime = 500;
 
+       /* clear previous failed END_LOOPVIT */
+       stb0899_read_reg(state, STB0899_VSTATUS);
+
        stb0899_write_reg(state, STB0899_DSTATUS2, 0x00); /* force search loop  */
        while (1) {
                /* WARNING! VIT LOCKED has to be tested before VIT_END_LOOOP    */
index 37a222d9ddb366ebd201debedec915661589be94..8408ef877b4be55e0e2e88bfc6c6ae6945024c63 100644 (file)
@@ -706,7 +706,7 @@ static int stb0899_send_diseqc_msg(struct dvb_frontend *fe, struct dvb_diseqc_ma
        stb0899_write_reg(state, STB0899_DISCNTRL1, reg);
        for (i = 0; i < cmd->msg_len; i++) {
                /* wait for FIFO empty  */
-               if (stb0899_wait_diseqc_fifo_empty(state, 10) < 0)
+               if (stb0899_wait_diseqc_fifo_empty(state, 100) < 0)
                        return -ETIMEDOUT;
 
                stb0899_write_reg(state, STB0899_DISFIFO, cmd->msg[i]);
@@ -1426,9 +1426,9 @@ static void stb0899_set_iterations(struct stb0899_state *state)
        if (iter_scale > config->ldpc_max_iter)
                iter_scale = config->ldpc_max_iter;
 
-       reg = STB0899_READ_S2REG(STB0899_S2DEMOD, MAX_ITER);
+       reg = STB0899_READ_S2REG(STB0899_S2FEC, MAX_ITER);
        STB0899_SETFIELD_VAL(MAX_ITERATIONS, reg, iter_scale);
-       stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_MAX_ITER, STB0899_OFF0_MAX_ITER, reg);
+       stb0899_write_s2reg(state, STB0899_S2FEC, STB0899_BASE_MAX_ITER, STB0899_OFF0_MAX_ITER, reg);
 }
 
 static enum dvbfe_search stb0899_search(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
index 8e0cfadba6889d789d3c1e43d20a5e473187c28f..0aa3962ff18bc37bb07d5e838fe43596405d9c20 100644 (file)
@@ -127,6 +127,11 @@ static int stv0288_set_symbolrate(struct dvb_frontend *fe, u32 srate)
        if ((srate < 1000000) || (srate > 45000000))
                return -EINVAL;
 
+       stv0288_writeregI(state, 0x22, 0);
+       stv0288_writeregI(state, 0x23, 0);
+       stv0288_writeregI(state, 0x2b, 0xff);
+       stv0288_writeregI(state, 0x2c, 0xf7);
+
        temp = (unsigned int)srate / 1000;
 
                temp = temp * 32768;
@@ -461,6 +466,7 @@ static int stv0288_set_frontend(struct dvb_frontend *fe,
 
        char tm;
        unsigned char tda[3];
+       u8 reg, time_out = 0;
 
        dprintk("%s : FE_SET_FRONTEND\n", __func__);
 
@@ -488,22 +494,29 @@ static int stv0288_set_frontend(struct dvb_frontend *fe,
        /* Carrier lock control register */
        stv0288_writeregI(state, 0x15, 0xc5);
 
-       tda[0] = 0x2b; /* CFRM */
        tda[2] = 0x0; /* CFRL */
-       for (tm = -6; tm < 7;) {
+       for (tm = -9; tm < 7;) {
                /* Viterbi status */
-               if (stv0288_readreg(state, 0x24) & 0x8)
-                       break;
-
-               tda[2] += 40;
-               if (tda[2] < 40)
+               reg = stv0288_readreg(state, 0x24);
+               if (reg & 0x8)
+                               break;
+               if (reg & 0x80) {
+                       time_out++;
+                       if (time_out > 10)
+                               break;
+                       tda[2] += 40;
+                       if (tda[2] < 40)
+                               tm++;
+               } else {
                        tm++;
+                       tda[2] = 0;
+                       time_out = 0;
+               }
                tda[1] = (unsigned char)tm;
                stv0288_writeregI(state, 0x2b, tda[1]);
                stv0288_writeregI(state, 0x2c, tda[2]);
                udelay(30);
        }
-
        state->tuner_frequency = c->frequency;
        state->fec_inner = FEC_AUTO;
        state->symbol_rate = c->symbol_rate;
index 52d8712411e5ce1672a75202efc64d499821e8a1..ebda41936b9094b3cc3259231337c507dd474360 100644 (file)
@@ -3463,9 +3463,15 @@ static enum dvbfe_search stv090x_search(struct dvb_frontend *fe, struct dvb_fron
 static int stv090x_read_status(struct dvb_frontend *fe, enum fe_status *status)
 {
        struct stv090x_state *state = fe->demodulator_priv;
-       u32 reg;
+       u32 reg, dstatus;
        u8 search_state;
 
+       *status = 0;
+
+       dstatus = STV090x_READ_DEMOD(state, DSTATUS);
+       if (STV090x_GETFIELD_Px(dstatus, CAR_LOCK_FIELD))
+               *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER;
+
        reg = STV090x_READ_DEMOD(state, DMDSTATE);
        search_state = STV090x_GETFIELD_Px(reg, HEADER_MODE_FIELD);
 
@@ -3474,41 +3480,30 @@ static int stv090x_read_status(struct dvb_frontend *fe, enum fe_status *status)
        case 1: /* first PLH detected */
        default:
                dprintk(FE_DEBUG, 1, "Status: Unlocked (Searching ..)");
-               *status = 0;
                break;
 
        case 2: /* DVB-S2 mode */
                dprintk(FE_DEBUG, 1, "Delivery system: DVB-S2");
-               reg = STV090x_READ_DEMOD(state, DSTATUS);
-               if (STV090x_GETFIELD_Px(reg, LOCK_DEFINITIF_FIELD)) {
+               if (STV090x_GETFIELD_Px(dstatus, LOCK_DEFINITIF_FIELD)) {
                        reg = STV090x_READ_DEMOD(state, PDELSTATUS1);
                        if (STV090x_GETFIELD_Px(reg, PKTDELIN_LOCK_FIELD)) {
+                               *status |= FE_HAS_VITERBI;
                                reg = STV090x_READ_DEMOD(state, TSSTATUS);
-                               if (STV090x_GETFIELD_Px(reg, TSFIFO_LINEOK_FIELD)) {
-                                       *status = FE_HAS_SIGNAL |
-                                                 FE_HAS_CARRIER |
-                                                 FE_HAS_VITERBI |
-                                                 FE_HAS_SYNC |
-                                                 FE_HAS_LOCK;
-                               }
+                               if (STV090x_GETFIELD_Px(reg, TSFIFO_LINEOK_FIELD))
+                                       *status |= FE_HAS_SYNC | FE_HAS_LOCK;
                        }
                }
                break;
 
        case 3: /* DVB-S1/legacy mode */
                dprintk(FE_DEBUG, 1, "Delivery system: DVB-S");
-               reg = STV090x_READ_DEMOD(state, DSTATUS);
-               if (STV090x_GETFIELD_Px(reg, LOCK_DEFINITIF_FIELD)) {
+               if (STV090x_GETFIELD_Px(dstatus, LOCK_DEFINITIF_FIELD)) {
                        reg = STV090x_READ_DEMOD(state, VSTATUSVIT);
                        if (STV090x_GETFIELD_Px(reg, LOCKEDVIT_FIELD)) {
+                               *status |= FE_HAS_VITERBI;
                                reg = STV090x_READ_DEMOD(state, TSSTATUS);
-                               if (STV090x_GETFIELD_Px(reg, TSFIFO_LINEOK_FIELD)) {
-                                       *status = FE_HAS_SIGNAL |
-                                                 FE_HAS_CARRIER |
-                                                 FE_HAS_VITERBI |
-                                                 FE_HAS_SYNC |
-                                                 FE_HAS_LOCK;
-                               }
+                               if (STV090x_GETFIELD_Px(reg, TSFIFO_LINEOK_FIELD))
+                                       *status |= FE_HAS_SYNC | FE_HAS_LOCK;
                        }
                }
                break;
index 93f6a75c238eec25fbe2c8cfb905f08d113d5e2a..7f105946a4342171056e8b774c7032ec4970dedc 100644 (file)
@@ -206,15 +206,16 @@ static struct init_tab {
 static struct pll_tab {
        u32     clk_freq_khz;
        u32     if_freq_khz;
-       u8      m, n, p;
 } pll_tab[] = {
-       { TDA10048_CLK_4000,  TDA10048_IF_36130, 10, 0, 0 },
-       { TDA10048_CLK_16000, TDA10048_IF_3300,  10, 3, 0 },
-       { TDA10048_CLK_16000, TDA10048_IF_3500,  10, 3, 0 },
-       { TDA10048_CLK_16000, TDA10048_IF_3800,  10, 3, 0 },
-       { TDA10048_CLK_16000, TDA10048_IF_4000,  10, 3, 0 },
-       { TDA10048_CLK_16000, TDA10048_IF_4300,  10, 3, 0 },
-       { TDA10048_CLK_16000, TDA10048_IF_36130, 10, 3, 0 },
+       { TDA10048_CLK_4000,  TDA10048_IF_36130 },
+       { TDA10048_CLK_16000, TDA10048_IF_3300 },
+       { TDA10048_CLK_16000, TDA10048_IF_3500 },
+       { TDA10048_CLK_16000, TDA10048_IF_3800 },
+       { TDA10048_CLK_16000, TDA10048_IF_4000 },
+       { TDA10048_CLK_16000, TDA10048_IF_4300 },
+       { TDA10048_CLK_16000, TDA10048_IF_4500 },
+       { TDA10048_CLK_16000, TDA10048_IF_5000 },
+       { TDA10048_CLK_16000, TDA10048_IF_36130 },
 };
 
 static int tda10048_writereg(struct tda10048_state *state, u8 reg, u8 data)
@@ -460,9 +461,6 @@ static int tda10048_set_if(struct dvb_frontend *fe, enum fe_bandwidth bw)
 
                        state->freq_if_hz = pll_tab[i].if_freq_khz * 1000;
                        state->xtal_hz = pll_tab[i].clk_freq_khz * 1000;
-                       state->pll_mfactor = pll_tab[i].m;
-                       state->pll_nfactor = pll_tab[i].n;
-                       state->pll_pfactor = pll_tab[i].p;
                        break;
                }
        }
@@ -781,6 +779,10 @@ static int tda10048_init(struct dvb_frontend *fe)
 
        dprintk(1, "%s()\n", __func__);
 
+       /* PLL */
+       init_tab[4].data = (u8)(state->pll_mfactor);
+       init_tab[5].data = (u8)(state->pll_nfactor) | 0x40;
+
        /* Apply register defaults */
        for (i = 0; i < ARRAY_SIZE(init_tab); i++)
                tda10048_writereg(state, init_tab[i].reg, init_tab[i].data);
@@ -1123,7 +1125,7 @@ struct dvb_frontend *tda10048_attach(const struct tda10048_config *config,
        /* setup the state and clone the config */
        memcpy(&state->config, config, sizeof(*config));
        state->i2c = i2c;
-       state->fwloaded = 0;
+       state->fwloaded = config->no_firmware;
        state->bandwidth = BANDWIDTH_8_MHZ;
 
        /* check if the demod is present */
@@ -1135,6 +1137,17 @@ struct dvb_frontend *tda10048_attach(const struct tda10048_config *config,
                sizeof(struct dvb_frontend_ops));
        state->frontend.demodulator_priv = state;
 
+       /* set pll */
+       if (config->set_pll) {
+               state->pll_mfactor = config->pll_m;
+               state->pll_nfactor = config->pll_n;
+               state->pll_pfactor = config->pll_p;
+       } else {
+               state->pll_mfactor = 10;
+               state->pll_nfactor = 3;
+               state->pll_pfactor = 0;
+       }
+
        /* Establish any defaults the the user didn't pass */
        tda10048_establish_defaults(&state->frontend);
 
index 8828ceaf74bb491dad21c12759d0a1b316ec8a0c..fb2ef5ac948768c7b1fd35bfa8741731d66427b9 100644 (file)
@@ -51,6 +51,7 @@ struct tda10048_config {
 #define TDA10048_IF_4300  4300
 #define TDA10048_IF_4500  4500
 #define TDA10048_IF_4750  4750
+#define TDA10048_IF_5000  5000
 #define TDA10048_IF_36130 36130
        u16 dtv6_if_freq_khz;
        u16 dtv7_if_freq_khz;
@@ -62,6 +63,13 @@ struct tda10048_config {
 
        /* Disable I2C gate access */
        u8 disable_gate_access;
+
+       bool no_firmware;
+
+       bool set_pll;
+       u8 pll_m;
+       u8 pll_p;
+       u8 pll_n;
 };
 
 #if defined(CONFIG_DVB_TDA10048) || \
diff --git a/drivers/media/dvb/frontends/tda10071.c b/drivers/media/dvb/frontends/tda10071.c
new file mode 100644 (file)
index 0000000..0c37434
--- /dev/null
@@ -0,0 +1,1269 @@
+/*
+ * NXP TDA10071 + Conexant CX24118A DVB-S/S2 demodulator + tuner driver
+ *
+ * Copyright (C) 2011 Antti Palosaari <crope@iki.fi>
+ *
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License along
+ *    with this program; if not, write to the Free Software Foundation, Inc.,
+ *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "tda10071_priv.h"
+
+int tda10071_debug;
+module_param_named(debug, tda10071_debug, int, 0644);
+MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
+
+static struct dvb_frontend_ops tda10071_ops;
+
+/* write multiple registers */
+static int tda10071_wr_regs(struct tda10071_priv *priv, u8 reg, u8 *val,
+       int len)
+{
+       int ret;
+       u8 buf[len+1];
+       struct i2c_msg msg[1] = {
+               {
+                       .addr = priv->cfg.i2c_address,
+                       .flags = 0,
+                       .len = sizeof(buf),
+                       .buf = buf,
+               }
+       };
+
+       buf[0] = reg;
+       memcpy(&buf[1], val, len);
+
+       ret = i2c_transfer(priv->i2c, msg, 1);
+       if (ret == 1) {
+               ret = 0;
+       } else {
+               warn("i2c wr failed=%d reg=%02x len=%d", ret, reg, len);
+               ret = -EREMOTEIO;
+       }
+       return ret;
+}
+
+/* read multiple registers */
+static int tda10071_rd_regs(struct tda10071_priv *priv, u8 reg, u8 *val,
+       int len)
+{
+       int ret;
+       u8 buf[len];
+       struct i2c_msg msg[2] = {
+               {
+                       .addr = priv->cfg.i2c_address,
+                       .flags = 0,
+                       .len = 1,
+                       .buf = &reg,
+               }, {
+                       .addr = priv->cfg.i2c_address,
+                       .flags = I2C_M_RD,
+                       .len = sizeof(buf),
+                       .buf = buf,
+               }
+       };
+
+       ret = i2c_transfer(priv->i2c, msg, 2);
+       if (ret == 2) {
+               memcpy(val, buf, len);
+               ret = 0;
+       } else {
+               warn("i2c rd failed=%d reg=%02x len=%d", ret, reg, len);
+               ret = -EREMOTEIO;
+       }
+       return ret;
+}
+
+/* write single register */
+static int tda10071_wr_reg(struct tda10071_priv *priv, u8 reg, u8 val)
+{
+       return tda10071_wr_regs(priv, reg, &val, 1);
+}
+
+/* read single register */
+static int tda10071_rd_reg(struct tda10071_priv *priv, u8 reg, u8 *val)
+{
+       return tda10071_rd_regs(priv, reg, val, 1);
+}
+
+/* write single register with mask */
+int tda10071_wr_reg_mask(struct tda10071_priv *priv, u8 reg, u8 val, u8 mask)
+{
+       int ret;
+       u8 tmp;
+
+       /* no need for read if whole reg is written */
+       if (mask != 0xff) {
+               ret = tda10071_rd_regs(priv, reg, &tmp, 1);
+               if (ret)
+                       return ret;
+
+               val &= mask;
+               tmp &= ~mask;
+               val |= tmp;
+       }
+
+       return tda10071_wr_regs(priv, reg, &val, 1);
+}
+
+/* read single register with mask */
+int tda10071_rd_reg_mask(struct tda10071_priv *priv, u8 reg, u8 *val, u8 mask)
+{
+       int ret, i;
+       u8 tmp;
+
+       ret = tda10071_rd_regs(priv, reg, &tmp, 1);
+       if (ret)
+               return ret;
+
+       tmp &= mask;
+
+       /* find position of the first bit */
+       for (i = 0; i < 8; i++) {
+               if ((mask >> i) & 0x01)
+                       break;
+       }
+       *val = tmp >> i;
+
+       return 0;
+}
+
+/* execute firmware command */
+static int tda10071_cmd_execute(struct tda10071_priv *priv,
+       struct tda10071_cmd *cmd)
+{
+       int ret, i;
+       u8 tmp;
+
+       if (!priv->warm) {
+               ret = -EFAULT;
+               goto error;
+       }
+
+       /* write cmd and args for firmware */
+       ret = tda10071_wr_regs(priv, 0x00, cmd->args, cmd->len);
+       if (ret)
+               goto error;
+
+       /* start cmd execution */
+       ret = tda10071_wr_reg(priv, 0x1f, 1);
+       if (ret)
+               goto error;
+
+       /* wait cmd execution terminate */
+       for (i = 1000, tmp = 1; i && tmp; i--) {
+               ret = tda10071_rd_reg(priv, 0x1f, &tmp);
+               if (ret)
+                       goto error;
+
+               usleep_range(200, 5000);
+       }
+
+       dbg("%s: loop=%d", __func__, i);
+
+       if (i == 0) {
+               ret = -ETIMEDOUT;
+               goto error;
+       }
+
+       return ret;
+error:
+       dbg("%s: failed=%d", __func__, ret);
+       return ret;
+}
+
+static int tda10071_set_tone(struct dvb_frontend *fe,
+       fe_sec_tone_mode_t fe_sec_tone_mode)
+{
+       struct tda10071_priv *priv = fe->demodulator_priv;
+       struct tda10071_cmd cmd;
+       int ret;
+       u8 tone;
+
+       if (!priv->warm) {
+               ret = -EFAULT;
+               goto error;
+       }
+
+       dbg("%s: tone_mode=%d", __func__, fe_sec_tone_mode);
+
+       switch (fe_sec_tone_mode) {
+       case SEC_TONE_ON:
+               tone = 1;
+               break;
+       case SEC_TONE_OFF:
+               tone = 0;
+               break;
+       default:
+               dbg("%s: invalid fe_sec_tone_mode", __func__);
+               ret = -EINVAL;
+               goto error;
+       }
+
+       cmd.args[0x00] = CMD_LNB_PCB_CONFIG;
+       cmd.args[0x01] = 0;
+       cmd.args[0x02] = 0x00;
+       cmd.args[0x03] = 0x00;
+       cmd.args[0x04] = tone;
+       cmd.len = 0x05;
+       ret = tda10071_cmd_execute(priv, &cmd);
+       if (ret)
+               goto error;
+
+       return ret;
+error:
+       dbg("%s: failed=%d", __func__, ret);
+       return ret;
+}
+
+static int tda10071_set_voltage(struct dvb_frontend *fe,
+       fe_sec_voltage_t fe_sec_voltage)
+{
+       struct tda10071_priv *priv = fe->demodulator_priv;
+       struct tda10071_cmd cmd;
+       int ret;
+       u8 voltage;
+
+       if (!priv->warm) {
+               ret = -EFAULT;
+               goto error;
+       }
+
+       dbg("%s: voltage=%d", __func__, fe_sec_voltage);
+
+       switch (fe_sec_voltage) {
+       case SEC_VOLTAGE_13:
+               voltage = 0;
+               break;
+       case SEC_VOLTAGE_18:
+               voltage = 1;
+               break;
+       case SEC_VOLTAGE_OFF:
+               voltage = 0;
+               break;
+       default:
+               dbg("%s: invalid fe_sec_voltage", __func__);
+               ret = -EINVAL;
+               goto error;
+       };
+
+       cmd.args[0x00] = CMD_LNB_SET_DC_LEVEL;
+       cmd.args[0x01] = 0;
+       cmd.args[0x02] = voltage;
+       cmd.len = 0x03;
+       ret = tda10071_cmd_execute(priv, &cmd);
+       if (ret)
+               goto error;
+
+       return ret;
+error:
+       dbg("%s: failed=%d", __func__, ret);
+       return ret;
+}
+
+static int tda10071_diseqc_send_master_cmd(struct dvb_frontend *fe,
+       struct dvb_diseqc_master_cmd *diseqc_cmd)
+{
+       struct tda10071_priv *priv = fe->demodulator_priv;
+       struct tda10071_cmd cmd;
+       int ret, i;
+       u8 tmp;
+
+       if (!priv->warm) {
+               ret = -EFAULT;
+               goto error;
+       }
+
+       dbg("%s: msg_len=%d", __func__, diseqc_cmd->msg_len);
+
+       if (diseqc_cmd->msg_len < 3 || diseqc_cmd->msg_len > 16) {
+               ret = -EINVAL;
+               goto error;
+       }
+
+       /* wait LNB TX */
+       for (i = 500, tmp = 0; i && !tmp; i--) {
+               ret = tda10071_rd_reg_mask(priv, 0x47, &tmp, 0x01);
+               if (ret)
+                       goto error;
+
+               usleep_range(10000, 20000);
+       }
+
+       dbg("%s: loop=%d", __func__, i);
+
+       if (i == 0) {
+               ret = -ETIMEDOUT;
+               goto error;
+       }
+
+       ret = tda10071_wr_reg_mask(priv, 0x47, 0x00, 0x01);
+       if (ret)
+               goto error;
+
+       cmd.args[0x00] = CMD_LNB_SEND_DISEQC;
+       cmd.args[0x01] = 0;
+       cmd.args[0x02] = 0;
+       cmd.args[0x03] = 0;
+       cmd.args[0x04] = 2;
+       cmd.args[0x05] = 0;
+       cmd.args[0x06] = diseqc_cmd->msg_len;
+       memcpy(&cmd.args[0x07], diseqc_cmd->msg, diseqc_cmd->msg_len);
+       cmd.len = 0x07 + diseqc_cmd->msg_len;
+       ret = tda10071_cmd_execute(priv, &cmd);
+       if (ret)
+               goto error;
+
+       return ret;
+error:
+       dbg("%s: failed=%d", __func__, ret);
+       return ret;
+}
+
+static int tda10071_diseqc_recv_slave_reply(struct dvb_frontend *fe,
+       struct dvb_diseqc_slave_reply *reply)
+{
+       struct tda10071_priv *priv = fe->demodulator_priv;
+       struct tda10071_cmd cmd;
+       int ret, i;
+       u8 tmp;
+
+       if (!priv->warm) {
+               ret = -EFAULT;
+               goto error;
+       }
+
+       dbg("%s:", __func__);
+
+       /* wait LNB RX */
+       for (i = 500, tmp = 0; i && !tmp; i--) {
+               ret = tda10071_rd_reg_mask(priv, 0x47, &tmp, 0x02);
+               if (ret)
+                       goto error;
+
+               usleep_range(10000, 20000);
+       }
+
+       dbg("%s: loop=%d", __func__, i);
+
+       if (i == 0) {
+               ret = -ETIMEDOUT;
+               goto error;
+       }
+
+       /* reply len */
+       ret = tda10071_rd_reg(priv, 0x46, &tmp);
+       if (ret)
+               goto error;
+
+       reply->msg_len = tmp & 0x1f; /* [4:0] */;
+       if (reply->msg_len > sizeof(reply->msg))
+               reply->msg_len = sizeof(reply->msg); /* truncate API max */
+
+       /* read reply */
+       cmd.args[0x00] = CMD_LNB_UPDATE_REPLY;
+       cmd.args[0x01] = 0;
+       cmd.len = 0x02;
+       ret = tda10071_cmd_execute(priv, &cmd);
+       if (ret)
+               goto error;
+
+       ret = tda10071_rd_regs(priv, cmd.len, reply->msg, reply->msg_len);
+       if (ret)
+               goto error;
+
+       return ret;
+error:
+       dbg("%s: failed=%d", __func__, ret);
+       return ret;
+}
+
+static int tda10071_diseqc_send_burst(struct dvb_frontend *fe,
+       fe_sec_mini_cmd_t fe_sec_mini_cmd)
+{
+       struct tda10071_priv *priv = fe->demodulator_priv;
+       struct tda10071_cmd cmd;
+       int ret, i;
+       u8 tmp, burst;
+
+       if (!priv->warm) {
+               ret = -EFAULT;
+               goto error;
+       }
+
+       dbg("%s: fe_sec_mini_cmd=%d", __func__, fe_sec_mini_cmd);
+
+       switch (fe_sec_mini_cmd) {
+       case SEC_MINI_A:
+               burst = 0;
+               break;
+       case SEC_MINI_B:
+               burst = 1;
+               break;
+       default:
+               dbg("%s: invalid fe_sec_mini_cmd", __func__);
+               ret = -EINVAL;
+               goto error;
+       }
+
+       /* wait LNB TX */
+       for (i = 500, tmp = 0; i && !tmp; i--) {
+               ret = tda10071_rd_reg_mask(priv, 0x47, &tmp, 0x01);
+               if (ret)
+                       goto error;
+
+               usleep_range(10000, 20000);
+       }
+
+       dbg("%s: loop=%d", __func__, i);
+
+       if (i == 0) {
+               ret = -ETIMEDOUT;
+               goto error;
+       }
+
+       ret = tda10071_wr_reg_mask(priv, 0x47, 0x00, 0x01);
+       if (ret)
+               goto error;
+
+       cmd.args[0x00] = CMD_LNB_SEND_TONEBURST;
+       cmd.args[0x01] = 0;
+       cmd.args[0x02] = burst;
+       cmd.len = 0x03;
+       ret = tda10071_cmd_execute(priv, &cmd);
+       if (ret)
+               goto error;
+
+       return ret;
+error:
+       dbg("%s: failed=%d", __func__, ret);
+       return ret;
+}
+
+static int tda10071_read_status(struct dvb_frontend *fe, fe_status_t *status)
+{
+       struct tda10071_priv *priv = fe->demodulator_priv;
+       int ret;
+       u8 tmp;
+
+       *status = 0;
+
+       if (!priv->warm) {
+               ret = 0;
+               goto error;
+       }
+
+       ret = tda10071_rd_reg(priv, 0x39, &tmp);
+       if (ret)
+               goto error;
+
+       if (tmp & 0x01) /* tuner PLL */
+               *status |= FE_HAS_SIGNAL;
+       if (tmp & 0x02) /* demod PLL */
+               *status |= FE_HAS_CARRIER;
+       if (tmp & 0x04) /* viterbi or LDPC*/
+               *status |= FE_HAS_VITERBI;
+       if (tmp & 0x08) /* RS or BCH */
+               *status |= FE_HAS_SYNC | FE_HAS_LOCK;
+
+       priv->fe_status = *status;
+
+       return ret;
+error:
+       dbg("%s: failed=%d", __func__, ret);
+       return ret;
+}
+
+static int tda10071_read_snr(struct dvb_frontend *fe, u16 *snr)
+{
+       struct tda10071_priv *priv = fe->demodulator_priv;
+       int ret;
+       u8 buf[2];
+
+       if (!priv->warm || !(priv->fe_status & FE_HAS_LOCK)) {
+               *snr = 0;
+               ret = 0;
+               goto error;
+       }
+
+       ret = tda10071_rd_regs(priv, 0x3a, buf, 2);
+       if (ret)
+               goto error;
+
+       /* Es/No dBx10 */
+       *snr = buf[0] << 8 | buf[1];
+
+       return ret;
+error:
+       dbg("%s: failed=%d", __func__, ret);
+       return ret;
+}
+
+static int tda10071_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
+{
+       struct tda10071_priv *priv = fe->demodulator_priv;
+       struct tda10071_cmd cmd;
+       int ret;
+       u8 tmp;
+
+       if (!priv->warm || !(priv->fe_status & FE_HAS_LOCK)) {
+               *strength = 0;
+               ret = 0;
+               goto error;
+       }
+
+       cmd.args[0x00] = CMD_GET_AGCACC;
+       cmd.args[0x01] = 0;
+       cmd.len = 0x02;
+       ret = tda10071_cmd_execute(priv, &cmd);
+       if (ret)
+               goto error;
+
+       /* input power estimate dBm */
+       ret = tda10071_rd_reg(priv, 0x50, &tmp);
+       if (ret)
+               goto error;
+
+       if (tmp < 181)
+               tmp = 181; /* -75 dBm */
+       else if (tmp > 236)
+               tmp = 236; /* -20 dBm */
+
+       /* scale value to 0x0000-0xffff */
+       *strength = (tmp-181) * 0xffff / (236-181);
+
+       return ret;
+error:
+       dbg("%s: failed=%d", __func__, ret);
+       return ret;
+}
+
+static int tda10071_read_ber(struct dvb_frontend *fe, u32 *ber)
+{
+       struct tda10071_priv *priv = fe->demodulator_priv;
+       struct tda10071_cmd cmd;
+       int ret, i, len;
+       u8 tmp, reg, buf[8];
+
+       if (!priv->warm || !(priv->fe_status & FE_HAS_LOCK)) {
+               *ber = priv->ber = 0;
+               ret = 0;
+               goto error;
+       }
+
+       switch (priv->delivery_system) {
+       case SYS_DVBS:
+               reg = 0x4c;
+               len = 8;
+               i = 1;
+               break;
+       case SYS_DVBS2:
+               reg = 0x4d;
+               len = 4;
+               i = 0;
+               break;
+       default:
+               *ber = priv->ber = 0;
+               return 0;
+       }
+
+       ret = tda10071_rd_reg(priv, reg, &tmp);
+       if (ret)
+               goto error;
+
+       if (priv->meas_count[i] == tmp) {
+               dbg("%s: meas not ready=%02x", __func__, tmp);
+               *ber = priv->ber;
+               return 0;
+       } else {
+               priv->meas_count[i] = tmp;
+       }
+
+       cmd.args[0x00] = CMD_BER_UPDATE_COUNTERS;
+       cmd.args[0x01] = 0;
+       cmd.args[0x02] = i;
+       cmd.len = 0x03;
+       ret = tda10071_cmd_execute(priv, &cmd);
+       if (ret)
+               goto error;
+
+       ret = tda10071_rd_regs(priv, cmd.len, buf, len);
+       if (ret)
+               goto error;
+
+       if (priv->delivery_system == SYS_DVBS) {
+               *ber = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
+               priv->ucb += (buf[4] << 8) | buf[5];
+       } else {
+               *ber = (buf[0] << 8) | buf[1];
+       }
+       priv->ber = *ber;
+
+       return ret;
+error:
+       dbg("%s: failed=%d", __func__, ret);
+       return ret;
+}
+
+static int tda10071_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
+{
+       struct tda10071_priv *priv = fe->demodulator_priv;
+       int ret = 0;
+
+       if (!priv->warm || !(priv->fe_status & FE_HAS_LOCK)) {
+               *ucblocks = 0;
+               goto error;
+       }
+
+       /* UCB is updated when BER is read. Assume BER is read anyway. */
+
+       *ucblocks = priv->ucb;
+
+       return ret;
+error:
+       dbg("%s: failed=%d", __func__, ret);
+       return ret;
+}
+
+static int tda10071_set_frontend(struct dvb_frontend *fe,
+       struct dvb_frontend_parameters *params)
+{
+       struct tda10071_priv *priv = fe->demodulator_priv;
+       struct tda10071_cmd cmd;
+       struct dtv_frontend_properties *c = &fe->dtv_property_cache;
+       int ret, i;
+       u8 mode, rolloff, pilot, inversion, div;
+
+       dbg("%s: delivery_system=%d modulation=%d frequency=%d " \
+               "symbol_rate=%d inversion=%d pilot=%d rolloff=%d", __func__,
+               c->delivery_system, c->modulation, c->frequency,
+               c->symbol_rate, c->inversion, c->pilot, c->rolloff);
+
+       priv->delivery_system = SYS_UNDEFINED;
+
+       if (!priv->warm) {
+               ret = -EFAULT;
+               goto error;
+       }
+
+       switch (c->inversion) {
+       case INVERSION_OFF:
+               inversion = 1;
+               break;
+       case INVERSION_ON:
+               inversion = 0;
+               break;
+       case INVERSION_AUTO:
+               /* 2 = auto; try first on then off
+                * 3 = auto; try first off then on */
+               inversion = 3;
+               break;
+       default:
+               dbg("%s: invalid inversion", __func__);
+               ret = -EINVAL;
+               goto error;
+       }
+
+       switch (c->delivery_system) {
+       case SYS_DVBS:
+               rolloff = 0;
+               pilot = 2;
+               break;
+       case SYS_DVBS2:
+               switch (c->rolloff) {
+               case ROLLOFF_20:
+                       rolloff = 2;
+                       break;
+               case ROLLOFF_25:
+                       rolloff = 1;
+                       break;
+               case ROLLOFF_35:
+                       rolloff = 0;
+                       break;
+               case ROLLOFF_AUTO:
+               default:
+                       dbg("%s: invalid rolloff", __func__);
+                       ret = -EINVAL;
+                       goto error;
+               }
+
+               switch (c->pilot) {
+               case PILOT_OFF:
+                       pilot = 0;
+                       break;
+               case PILOT_ON:
+                       pilot = 1;
+                       break;
+               case PILOT_AUTO:
+                       pilot = 2;
+                       break;
+               default:
+                       dbg("%s: invalid pilot", __func__);
+                       ret = -EINVAL;
+                       goto error;
+               }
+               break;
+       default:
+               dbg("%s: invalid delivery_system", __func__);
+               ret = -EINVAL;
+               goto error;
+       }
+
+       for (i = 0, mode = 0xff; i < ARRAY_SIZE(TDA10071_MODCOD); i++) {
+               if (c->delivery_system == TDA10071_MODCOD[i].delivery_system &&
+                       c->modulation == TDA10071_MODCOD[i].modulation &&
+                       c->fec_inner == TDA10071_MODCOD[i].fec) {
+                       mode = TDA10071_MODCOD[i].val;
+                       dbg("%s: mode found=%02x", __func__, mode);
+                       break;
+               }
+       }
+
+       if (mode == 0xff) {
+               dbg("%s: invalid parameter combination", __func__);
+               ret = -EINVAL;
+               goto error;
+       }
+
+       if (c->symbol_rate <= 5000000)
+               div = 14;
+       else
+               div = 4;
+
+       ret = tda10071_wr_reg(priv, 0x81, div);
+       if (ret)
+               goto error;
+
+       ret = tda10071_wr_reg(priv, 0xe3, div);
+       if (ret)
+               goto error;
+
+       cmd.args[0x00] = CMD_CHANGE_CHANNEL;
+       cmd.args[0x01] = 0;
+       cmd.args[0x02] = mode;
+       cmd.args[0x03] = (c->frequency >> 16) & 0xff;
+       cmd.args[0x04] = (c->frequency >>  8) & 0xff;
+       cmd.args[0x05] = (c->frequency >>  0) & 0xff;
+       cmd.args[0x06] = ((c->symbol_rate / 1000) >> 8) & 0xff;
+       cmd.args[0x07] = ((c->symbol_rate / 1000) >> 0) & 0xff;
+       cmd.args[0x08] = (tda10071_ops.info.frequency_tolerance >> 8) & 0xff;
+       cmd.args[0x09] = (tda10071_ops.info.frequency_tolerance >> 0) & 0xff;
+       cmd.args[0x0a] = rolloff;
+       cmd.args[0x0b] = inversion;
+       cmd.args[0x0c] = pilot;
+       cmd.args[0x0d] = 0x00;
+       cmd.args[0x0e] = 0x00;
+       cmd.len = 0x0f;
+       ret = tda10071_cmd_execute(priv, &cmd);
+       if (ret)
+               goto error;
+
+       priv->delivery_system = c->delivery_system;
+
+       return ret;
+error:
+       dbg("%s: failed=%d", __func__, ret);
+       return ret;
+}
+
+static int tda10071_get_frontend(struct dvb_frontend *fe,
+       struct dvb_frontend_parameters *p)
+{
+       struct tda10071_priv *priv = fe->demodulator_priv;
+       struct dtv_frontend_properties *c = &fe->dtv_property_cache;
+       int ret, i;
+       u8 buf[5], tmp;
+
+       if (!priv->warm || !(priv->fe_status & FE_HAS_LOCK)) {
+               ret = -EFAULT;
+               goto error;
+       }
+
+       ret = tda10071_rd_regs(priv, 0x30, buf, 5);
+       if (ret)
+               goto error;
+
+       tmp = buf[0] & 0x3f;
+       for (i = 0; i < ARRAY_SIZE(TDA10071_MODCOD); i++) {
+               if (tmp == TDA10071_MODCOD[i].val) {
+                       c->modulation = TDA10071_MODCOD[i].modulation;
+                       c->fec_inner = TDA10071_MODCOD[i].fec;
+                       c->delivery_system = TDA10071_MODCOD[i].delivery_system;
+               }
+       }
+
+       switch ((buf[1] >> 0) & 0x01) {
+       case 0:
+               c->inversion = INVERSION_OFF;
+               break;
+       case 1:
+               c->inversion = INVERSION_ON;
+               break;
+       }
+
+       switch ((buf[1] >> 7) & 0x01) {
+       case 0:
+               c->pilot = PILOT_OFF;
+               break;
+       case 1:
+               c->pilot = PILOT_ON;
+               break;
+       }
+
+       c->frequency = (buf[2] << 16) | (buf[3] << 8) | (buf[4] << 0);
+
+       ret = tda10071_rd_regs(priv, 0x52, buf, 3);
+       if (ret)
+               goto error;
+
+       c->symbol_rate = (buf[0] << 16) | (buf[1] << 8) | (buf[2] << 0);
+
+       return ret;
+error:
+       dbg("%s: failed=%d", __func__, ret);
+       return ret;
+}
+
+static int tda10071_init(struct dvb_frontend *fe)
+{
+       struct tda10071_priv *priv = fe->demodulator_priv;
+       struct tda10071_cmd cmd;
+       int ret, i, len, remaining, fw_size;
+       const struct firmware *fw;
+       u8 *fw_file = TDA10071_DEFAULT_FIRMWARE;
+       u8 tmp, buf[4];
+       struct tda10071_reg_val_mask tab[] = {
+               { 0xcd, 0x00, 0x07 },
+               { 0x80, 0x00, 0x02 },
+               { 0xcd, 0x00, 0xc0 },
+               { 0xce, 0x00, 0x1b },
+               { 0x9d, 0x00, 0x01 },
+               { 0x9d, 0x00, 0x02 },
+               { 0x9e, 0x00, 0x01 },
+               { 0x87, 0x00, 0x80 },
+               { 0xce, 0x00, 0x08 },
+               { 0xce, 0x00, 0x10 },
+       };
+       struct tda10071_reg_val_mask tab2[] = {
+               { 0xf1, 0x70, 0xff },
+               { 0x88, priv->cfg.pll_multiplier, 0x3f },
+               { 0x89, 0x00, 0x10 },
+               { 0x89, 0x10, 0x10 },
+               { 0xc0, 0x01, 0x01 },
+               { 0xc0, 0x00, 0x01 },
+               { 0xe0, 0xff, 0xff },
+               { 0xe0, 0x00, 0xff },
+               { 0x96, 0x1e, 0x7e },
+               { 0x8b, 0x08, 0x08 },
+               { 0x8b, 0x00, 0x08 },
+               { 0x8f, 0x1a, 0x7e },
+               { 0x8c, 0x68, 0xff },
+               { 0x8d, 0x08, 0xff },
+               { 0x8e, 0x4c, 0xff },
+               { 0x8f, 0x01, 0x01 },
+               { 0x8b, 0x04, 0x04 },
+               { 0x8b, 0x00, 0x04 },
+               { 0x87, 0x05, 0x07 },
+               { 0x80, 0x00, 0x20 },
+               { 0xc8, 0x01, 0xff },
+               { 0xb4, 0x47, 0xff },
+               { 0xb5, 0x9c, 0xff },
+               { 0xb6, 0x7d, 0xff },
+               { 0xba, 0x00, 0x03 },
+               { 0xb7, 0x47, 0xff },
+               { 0xb8, 0x9c, 0xff },
+               { 0xb9, 0x7d, 0xff },
+               { 0xba, 0x00, 0x0c },
+               { 0xc8, 0x00, 0xff },
+               { 0xcd, 0x00, 0x04 },
+               { 0xcd, 0x00, 0x20 },
+               { 0xe8, 0x02, 0xff },
+               { 0xcf, 0x20, 0xff },
+               { 0x9b, 0xd7, 0xff },
+               { 0x9a, 0x01, 0x03 },
+               { 0xa8, 0x05, 0x0f },
+               { 0xa8, 0x65, 0xf0 },
+               { 0xa6, 0xa0, 0xf0 },
+               { 0x9d, 0x50, 0xfc },
+               { 0x9e, 0x20, 0xe0 },
+               { 0xa3, 0x1c, 0x7c },
+               { 0xd5, 0x03, 0x03 },
+       };
+
+       /* firmware status */
+       ret = tda10071_rd_reg(priv, 0x51, &tmp);
+       if (ret)
+               goto error;
+
+       if (!tmp) {
+               /* warm state - wake up device from sleep */
+               priv->warm = 1;
+
+               for (i = 0; i < ARRAY_SIZE(tab); i++) {
+                       ret = tda10071_wr_reg_mask(priv, tab[i].reg,
+                               tab[i].val, tab[i].mask);
+                       if (ret)
+                               goto error;
+               }
+
+               cmd.args[0x00] = CMD_SET_SLEEP_MODE;
+               cmd.args[0x01] = 0;
+               cmd.args[0x02] = 0;
+               cmd.len = 0x03;
+               ret = tda10071_cmd_execute(priv, &cmd);
+               if (ret)
+                       goto error;
+       } else {
+               /* cold state - try to download firmware */
+               priv->warm = 0;
+
+               /* request the firmware, this will block and timeout */
+               ret = request_firmware(&fw, fw_file, priv->i2c->dev.parent);
+               if (ret) {
+                       err("did not find the firmware file. (%s) "
+                               "Please see linux/Documentation/dvb/ for more" \
+                               " details on firmware-problems. (%d)",
+                               fw_file, ret);
+                       goto error;
+               }
+
+               /* init */
+               for (i = 0; i < ARRAY_SIZE(tab2); i++) {
+                       ret = tda10071_wr_reg_mask(priv, tab2[i].reg,
+                               tab2[i].val, tab2[i].mask);
+                       if (ret)
+                               goto error_release_firmware;
+               }
+
+               /*  download firmware */
+               ret = tda10071_wr_reg(priv, 0xe0, 0x7f);
+               if (ret)
+                       goto error_release_firmware;
+
+               ret = tda10071_wr_reg(priv, 0xf7, 0x81);
+               if (ret)
+                       goto error_release_firmware;
+
+               ret = tda10071_wr_reg(priv, 0xf8, 0x00);
+               if (ret)
+                       goto error_release_firmware;
+
+               ret = tda10071_wr_reg(priv, 0xf9, 0x00);
+               if (ret)
+                       goto error_release_firmware;
+
+               info("found a '%s' in cold state, will try to load a firmware",
+                       tda10071_ops.info.name);
+
+               info("downloading firmware from file '%s'", fw_file);
+
+               /* do not download last byte */
+               fw_size = fw->size - 1;
+
+               for (remaining = fw_size; remaining > 0;
+                       remaining -= (priv->cfg.i2c_wr_max - 1)) {
+                       len = remaining;
+                       if (len > (priv->cfg.i2c_wr_max - 1))
+                               len = (priv->cfg.i2c_wr_max - 1);
+
+                       ret = tda10071_wr_regs(priv, 0xfa,
+                               (u8 *) &fw->data[fw_size - remaining], len);
+                       if (ret) {
+                               err("firmware download failed=%d", ret);
+                               if (ret)
+                                       goto error_release_firmware;
+                       }
+               }
+               release_firmware(fw);
+
+               ret = tda10071_wr_reg(priv, 0xf7, 0x0c);
+               if (ret)
+                       goto error;
+
+               ret = tda10071_wr_reg(priv, 0xe0, 0x00);
+               if (ret)
+                       goto error;
+
+               /* wait firmware start */
+               msleep(250);
+
+               /* firmware status */
+               ret = tda10071_rd_reg(priv, 0x51, &tmp);
+               if (ret)
+                       goto error;
+
+               if (tmp) {
+                       info("firmware did not run");
+                       ret = -EFAULT;
+                       goto error;
+               } else {
+                       priv->warm = 1;
+               }
+
+               cmd.args[0x00] = CMD_GET_FW_VERSION;
+               cmd.len = 0x01;
+               ret = tda10071_cmd_execute(priv, &cmd);
+               if (ret)
+                       goto error;
+
+               ret = tda10071_rd_regs(priv, cmd.len, buf, 4);
+               if (ret)
+                       goto error;
+
+               info("firmware version %d.%d.%d.%d",
+                       buf[0], buf[1], buf[2], buf[3]);
+               info("found a '%s' in warm state.", tda10071_ops.info.name);
+
+               ret = tda10071_rd_regs(priv, 0x81, buf, 2);
+               if (ret)
+                       goto error;
+
+               cmd.args[0x00] = CMD_DEMOD_INIT;
+               cmd.args[0x01] = ((priv->cfg.xtal / 1000) >> 8) & 0xff;
+               cmd.args[0x02] = ((priv->cfg.xtal / 1000) >> 0) & 0xff;
+               cmd.args[0x03] = buf[0];
+               cmd.args[0x04] = buf[1];
+               cmd.args[0x05] = priv->cfg.pll_multiplier;
+               cmd.args[0x06] = priv->cfg.spec_inv;
+               cmd.args[0x07] = 0x00;
+               cmd.len = 0x08;
+               ret = tda10071_cmd_execute(priv, &cmd);
+               if (ret)
+                       goto error;
+
+               cmd.args[0x00] = CMD_TUNER_INIT;
+               cmd.args[0x01] = 0x00;
+               cmd.args[0x02] = 0x00;
+               cmd.args[0x03] = 0x00;
+               cmd.args[0x04] = 0x00;
+               cmd.args[0x05] = 0x14;
+               cmd.args[0x06] = 0x00;
+               cmd.args[0x07] = 0x03;
+               cmd.args[0x08] = 0x02;
+               cmd.args[0x09] = 0x02;
+               cmd.args[0x0a] = 0x00;
+               cmd.args[0x0b] = 0x00;
+               cmd.args[0x0c] = 0x00;
+               cmd.args[0x0d] = 0x00;
+               cmd.args[0x0e] = 0x00;
+               cmd.len = 0x0f;
+               ret = tda10071_cmd_execute(priv, &cmd);
+               if (ret)
+                       goto error;
+
+               cmd.args[0x00] = CMD_MPEG_CONFIG;
+               cmd.args[0x01] = 0;
+               cmd.args[0x02] = priv->cfg.ts_mode;
+               cmd.args[0x03] = 0x00;
+               cmd.args[0x04] = 0x04;
+               cmd.args[0x05] = 0x00;
+               cmd.len = 0x06;
+               ret = tda10071_cmd_execute(priv, &cmd);
+               if (ret)
+                       goto error;
+
+               ret = tda10071_wr_reg_mask(priv, 0xf0, 0x01, 0x01);
+               if (ret)
+                       goto error;
+
+               cmd.args[0x00] = CMD_LNB_CONFIG;
+               cmd.args[0x01] = 0;
+               cmd.args[0x02] = 150;
+               cmd.args[0x03] = 3;
+               cmd.args[0x04] = 22;
+               cmd.args[0x05] = 1;
+               cmd.args[0x06] = 1;
+               cmd.args[0x07] = 30;
+               cmd.args[0x08] = 30;
+               cmd.args[0x09] = 30;
+               cmd.args[0x0a] = 30;
+               cmd.len = 0x0b;
+               ret = tda10071_cmd_execute(priv, &cmd);
+               if (ret)
+                       goto error;
+
+               cmd.args[0x00] = CMD_BER_CONTROL;
+               cmd.args[0x01] = 0;
+               cmd.args[0x02] = 14;
+               cmd.args[0x03] = 14;
+               cmd.len = 0x04;
+               ret = tda10071_cmd_execute(priv, &cmd);
+               if (ret)
+                       goto error;
+       }
+
+       return ret;
+error_release_firmware:
+       release_firmware(fw);
+error:
+       dbg("%s: failed=%d", __func__, ret);
+       return ret;
+}
+
+static int tda10071_sleep(struct dvb_frontend *fe)
+{
+       struct tda10071_priv *priv = fe->demodulator_priv;
+       struct tda10071_cmd cmd;
+       int ret, i;
+       struct tda10071_reg_val_mask tab[] = {
+               { 0xcd, 0x07, 0x07 },
+               { 0x80, 0x02, 0x02 },
+               { 0xcd, 0xc0, 0xc0 },
+               { 0xce, 0x1b, 0x1b },
+               { 0x9d, 0x01, 0x01 },
+               { 0x9d, 0x02, 0x02 },
+               { 0x9e, 0x01, 0x01 },
+               { 0x87, 0x80, 0x80 },
+               { 0xce, 0x08, 0x08 },
+               { 0xce, 0x10, 0x10 },
+       };
+
+       if (!priv->warm) {
+               ret = -EFAULT;
+               goto error;
+       }
+
+       cmd.args[0x00] = CMD_SET_SLEEP_MODE;
+       cmd.args[0x01] = 0;
+       cmd.args[0x02] = 1;
+       cmd.len = 0x03;
+       ret = tda10071_cmd_execute(priv, &cmd);
+       if (ret)
+               goto error;
+
+       for (i = 0; i < ARRAY_SIZE(tab); i++) {
+               ret = tda10071_wr_reg_mask(priv, tab[i].reg, tab[i].val,
+                       tab[i].mask);
+               if (ret)
+                       goto error;
+       }
+
+       return ret;
+error:
+       dbg("%s: failed=%d", __func__, ret);
+       return ret;
+}
+
+static int tda10071_get_tune_settings(struct dvb_frontend *fe,
+       struct dvb_frontend_tune_settings *s)
+{
+       s->min_delay_ms = 8000;
+       s->step_size = 0;
+       s->max_drift = 0;
+
+       return 0;
+}
+
+static void tda10071_release(struct dvb_frontend *fe)
+{
+       struct tda10071_priv *priv = fe->demodulator_priv;
+       kfree(priv);
+}
+
+struct dvb_frontend *tda10071_attach(const struct tda10071_config *config,
+       struct i2c_adapter *i2c)
+{
+       int ret;
+       struct tda10071_priv *priv = NULL;
+       u8 tmp;
+
+       /* allocate memory for the internal priv */
+       priv = kzalloc(sizeof(struct tda10071_priv), GFP_KERNEL);
+       if (priv == NULL) {
+               ret = -ENOMEM;
+               goto error;
+       }
+
+       /* setup the priv */
+       priv->i2c = i2c;
+       memcpy(&priv->cfg, config, sizeof(struct tda10071_config));
+
+       /* chip ID */
+       ret = tda10071_rd_reg(priv, 0xff, &tmp);
+       if (ret || tmp != 0x0f)
+               goto error;
+
+       /* chip type */
+       ret = tda10071_rd_reg(priv, 0xdd, &tmp);
+       if (ret || tmp != 0x00)
+               goto error;
+
+       /* chip version */
+       ret = tda10071_rd_reg(priv, 0xfe, &tmp);
+       if (ret || tmp != 0x01)
+               goto error;
+
+       /* create dvb_frontend */
+       memcpy(&priv->fe.ops, &tda10071_ops, sizeof(struct dvb_frontend_ops));
+       priv->fe.demodulator_priv = priv;
+
+       return &priv->fe;
+error:
+       dbg("%s: failed=%d", __func__, ret);
+       kfree(priv);
+       return NULL;
+}
+EXPORT_SYMBOL(tda10071_attach);
+
+static struct dvb_frontend_ops tda10071_ops = {
+       .info = {
+               .name = "NXP TDA10071",
+               .type = FE_QPSK,
+               .frequency_min = 950000,
+               .frequency_max = 2150000,
+               .frequency_tolerance = 5000,
+               .symbol_rate_min = 1000000,
+               .symbol_rate_max = 45000000,
+               .caps = FE_CAN_INVERSION_AUTO |
+                       FE_CAN_FEC_1_2 |
+                       FE_CAN_FEC_2_3 |
+                       FE_CAN_FEC_3_4 |
+                       FE_CAN_FEC_4_5 |
+                       FE_CAN_FEC_5_6 |
+                       FE_CAN_FEC_6_7 |
+                       FE_CAN_FEC_7_8 |
+                       FE_CAN_FEC_8_9 |
+                       FE_CAN_FEC_AUTO |
+                       FE_CAN_QPSK |
+                       FE_CAN_RECOVER |
+                       FE_CAN_2G_MODULATION
+       },
+
+       .release = tda10071_release,
+
+       .get_tune_settings = tda10071_get_tune_settings,
+
+       .init = tda10071_init,
+       .sleep = tda10071_sleep,
+
+       .set_frontend = tda10071_set_frontend,
+       .get_frontend = tda10071_get_frontend,
+
+       .read_status = tda10071_read_status,
+       .read_snr = tda10071_read_snr,
+       .read_signal_strength = tda10071_read_signal_strength,
+       .read_ber = tda10071_read_ber,
+       .read_ucblocks = tda10071_read_ucblocks,
+
+       .diseqc_send_master_cmd = tda10071_diseqc_send_master_cmd,
+       .diseqc_recv_slave_reply = tda10071_diseqc_recv_slave_reply,
+       .diseqc_send_burst = tda10071_diseqc_send_burst,
+
+       .set_tone = tda10071_set_tone,
+       .set_voltage = tda10071_set_voltage,
+};
+
+MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
+MODULE_DESCRIPTION("NXP TDA10071 DVB-S/S2 demodulator driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/tda10071.h b/drivers/media/dvb/frontends/tda10071.h
new file mode 100644 (file)
index 0000000..21163c4
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * NXP TDA10071 + Conexant CX24118A DVB-S/S2 demodulator + tuner driver
+ *
+ * Copyright (C) 2011 Antti Palosaari <crope@iki.fi>
+ *
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License along
+ *    with this program; if not, write to the Free Software Foundation, Inc.,
+ *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef TDA10071_H
+#define TDA10071_H
+
+#include <linux/dvb/frontend.h>
+
+struct tda10071_config {
+       /* Demodulator I2C address.
+        * Default: none, must set
+        * Values: 0x55,
+        */
+       u8 i2c_address;
+
+       /* Max bytes I2C provider can write at once.
+        * Note: Buffer is taken from the stack currently!
+        * Default: none, must set
+        * Values:
+        */
+       u16 i2c_wr_max;
+
+       /* TS output mode.
+        * Default: TDA10071_TS_SERIAL
+        * Values:
+        */
+#define TDA10071_TS_SERIAL        0
+#define TDA10071_TS_PARALLEL      1
+       u8 ts_mode;
+
+       /* Input spectrum inversion.
+        * Default: 0
+        * Values: 0, 1
+        */
+       bool spec_inv;
+
+       /* Xtal frequency Hz
+        * Default: none, must set
+        * Values:
+        */
+       u32 xtal;
+
+       /* PLL multiplier.
+        * Default: none, must set
+        * Values:
+        */
+       u8 pll_multiplier;
+};
+
+
+#if defined(CONFIG_DVB_TDA10071) || \
+       (defined(CONFIG_DVB_TDA10071_MODULE) && defined(MODULE))
+extern struct dvb_frontend *tda10071_attach(
+       const struct tda10071_config *config, struct i2c_adapter *i2c);
+#else
+static inline struct dvb_frontend *tda10071_attach(
+       const struct tda10071_config *config, struct i2c_adapter *i2c)
+{
+       printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
+       return NULL;
+}
+#endif
+
+#endif /* TDA10071_H */
diff --git a/drivers/media/dvb/frontends/tda10071_priv.h b/drivers/media/dvb/frontends/tda10071_priv.h
new file mode 100644 (file)
index 0000000..93c5e63
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * NXP TDA10071 + Conexant CX24118A DVB-S/S2 demodulator + tuner driver
+ *
+ * Copyright (C) 2011 Antti Palosaari <crope@iki.fi>
+ *
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License along
+ *    with this program; if not, write to the Free Software Foundation, Inc.,
+ *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef TDA10071_PRIV
+#define TDA10071_PRIV
+
+#include "dvb_frontend.h"
+#include "tda10071.h"
+#include <linux/firmware.h>
+
+#define LOG_PREFIX "tda10071"
+
+#undef dbg
+#define dbg(f, arg...) \
+       if (tda10071_debug) \
+               printk(KERN_INFO   LOG_PREFIX": " f "\n" , ## arg)
+#undef err
+#define err(f, arg...)  printk(KERN_ERR     LOG_PREFIX": " f "\n" , ## arg)
+#undef info
+#define info(f, arg...) printk(KERN_INFO    LOG_PREFIX": " f "\n" , ## arg)
+#undef warn
+#define warn(f, arg...) printk(KERN_WARNING LOG_PREFIX": " f "\n" , ## arg)
+
+struct tda10071_priv {
+       struct i2c_adapter *i2c;
+       struct dvb_frontend fe;
+       struct tda10071_config cfg;
+
+       u8 meas_count[2];
+       u32 ber;
+       u32 ucb;
+       fe_status_t fe_status;
+       fe_delivery_system_t delivery_system;
+       bool warm; /* FW running */
+};
+
+static struct tda10071_modcod {
+       fe_delivery_system_t delivery_system;
+       fe_modulation_t modulation;
+       fe_code_rate_t fec;
+       u8 val;
+} TDA10071_MODCOD[] = {
+       /* NBC-QPSK */
+       { SYS_DVBS2, QPSK,  FEC_AUTO, 0x00 },
+       { SYS_DVBS2, QPSK,  FEC_1_2,  0x04 },
+       { SYS_DVBS2, QPSK,  FEC_3_5,  0x05 },
+       { SYS_DVBS2, QPSK,  FEC_2_3,  0x06 },
+       { SYS_DVBS2, QPSK,  FEC_3_4,  0x07 },
+       { SYS_DVBS2, QPSK,  FEC_4_5,  0x08 },
+       { SYS_DVBS2, QPSK,  FEC_5_6,  0x09 },
+       { SYS_DVBS2, QPSK,  FEC_8_9,  0x0a },
+       { SYS_DVBS2, QPSK,  FEC_9_10, 0x0b },
+       /* 8PSK */
+       { SYS_DVBS2, PSK_8, FEC_3_5,  0x0c },
+       { SYS_DVBS2, PSK_8, FEC_2_3,  0x0d },
+       { SYS_DVBS2, PSK_8, FEC_3_4,  0x0e },
+       { SYS_DVBS2, PSK_8, FEC_5_6,  0x0f },
+       { SYS_DVBS2, PSK_8, FEC_8_9,  0x10 },
+       { SYS_DVBS2, PSK_8, FEC_9_10, 0x11 },
+       /* QPSK */
+       { SYS_DVBS,  QPSK,  FEC_AUTO, 0x2d },
+       { SYS_DVBS,  QPSK,  FEC_1_2,  0x2e },
+       { SYS_DVBS,  QPSK,  FEC_2_3,  0x2f },
+       { SYS_DVBS,  QPSK,  FEC_3_4,  0x30 },
+       { SYS_DVBS,  QPSK,  FEC_5_6,  0x31 },
+       { SYS_DVBS,  QPSK,  FEC_7_8,  0x32 },
+};
+
+struct tda10071_reg_val_mask {
+       u8 reg;
+       u8 val;
+       u8 mask;
+};
+
+/* firmware filename */
+#define TDA10071_DEFAULT_FIRMWARE      "dvb-fe-tda10071.fw"
+
+/* firmware commands */
+#define CMD_DEMOD_INIT          0x10
+#define CMD_CHANGE_CHANNEL      0x11
+#define CMD_MPEG_CONFIG         0x13
+#define CMD_TUNER_INIT          0x15
+#define CMD_GET_AGCACC          0x1a
+
+#define CMD_LNB_CONFIG          0x20
+#define CMD_LNB_SEND_DISEQC     0x21
+#define CMD_LNB_SET_DC_LEVEL    0x22
+#define CMD_LNB_PCB_CONFIG      0x23
+#define CMD_LNB_SEND_TONEBURST  0x24
+#define CMD_LNB_UPDATE_REPLY    0x25
+
+#define CMD_GET_FW_VERSION      0x35
+#define CMD_SET_SLEEP_MODE      0x36
+#define CMD_BER_CONTROL         0x3e
+#define CMD_BER_UPDATE_COUNTERS 0x3f
+
+/* firmare command struct */
+#define TDA10071_ARGLEN      0x1e
+struct tda10071_cmd {
+       u8 args[TDA10071_ARGLEN];
+       u8 len;
+};
+
+
+#endif /* TDA10071_PRIV */
index 0384e8da4f5ea9ec66c83058031b1d1e52dffe8a..1b1bf200c55c4b1c65dea314d5abcffcf89e7027 100644 (file)
@@ -1195,7 +1195,7 @@ static int GetSignalStrength(s32 *pSignalStrength, u32 RFAgc, u32 IFAgc)
 }
 #endif
 
-static int get_frequency(struct dvb_frontend *fe, u32 *frequency)
+static int get_if_frequency(struct dvb_frontend *fe, u32 *frequency)
 {
        struct tda_state *state = fe->tuner_priv;
 
@@ -1222,7 +1222,7 @@ static struct dvb_tuner_ops tuner_ops = {
        .sleep             = sleep,
        .set_params        = set_params,
        .release           = release,
-       .get_frequency     = get_frequency,
+       .get_if_frequency  = get_if_frequency,
        .get_bandwidth     = get_bandwidth,
 };
 
index 98dc5cd258ac5364435dbeea9e2c2cb5770bdf6d..ec8116dcb368cea9f43bebe1bc1e28f8f64915c0 100644 (file)
@@ -25,4 +25,4 @@ obj-$(CONFIG_MANTIS_CORE)     += mantis_core.o
 obj-$(CONFIG_DVB_MANTIS)       += mantis.o
 obj-$(CONFIG_DVB_HOPPER)       += hopper.o
 
-EXTRA_CFLAGS = -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
+ccflags-y += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
index 1402062f2c89b570511bc9dfae2a986def9051f4..71622f65c037e0e7c297fefe5ac0b8e50b95e49b 100644 (file)
@@ -65,7 +65,7 @@ static int devs;
 
 static irqreturn_t hopper_irq_handler(int irq, void *dev_id)
 {
-       u32 stat = 0, mask = 0, lstat = 0, mstat = 0;
+       u32 stat = 0, mask = 0, lstat = 0;
        u32 rst_stat = 0, rst_mask = 0;
 
        struct mantis_pci *mantis;
@@ -80,7 +80,7 @@ static irqreturn_t hopper_irq_handler(int irq, void *dev_id)
 
        stat = mmread(MANTIS_INT_STAT);
        mask = mmread(MANTIS_INT_MASK);
-       mstat = lstat = stat & ~MANTIS_INT_RISCSTAT;
+       lstat = stat & ~MANTIS_INT_RISCSTAT;
        if (!(stat & mask))
                return IRQ_NONE;
 
@@ -126,7 +126,7 @@ static irqreturn_t hopper_irq_handler(int irq, void *dev_id)
        }
        if (stat & MANTIS_INT_RISCI) {
                dprintk(MANTIS_DEBUG, 0, "<%s>", label[8]);
-               mantis->finished_block = (stat & MANTIS_INT_RISCSTAT) >> 28;
+               mantis->busy_block = (stat & MANTIS_INT_RISCSTAT) >> 28;
                tasklet_schedule(&mantis->tasklet);
        }
        if (stat & MANTIS_INT_I2CDONE) {
index 05cbb9d95727f942194f392a6a76bba951726a84..c2bb90b3e52998f424a8dcb13fb4d3098bc6efdc 100644 (file)
@@ -73,7 +73,7 @@ static char *label[10] = {
 
 static irqreturn_t mantis_irq_handler(int irq, void *dev_id)
 {
-       u32 stat = 0, mask = 0, lstat = 0, mstat = 0;
+       u32 stat = 0, mask = 0, lstat = 0;
        u32 rst_stat = 0, rst_mask = 0;
 
        struct mantis_pci *mantis;
@@ -88,7 +88,7 @@ static irqreturn_t mantis_irq_handler(int irq, void *dev_id)
 
        stat = mmread(MANTIS_INT_STAT);
        mask = mmread(MANTIS_INT_MASK);
-       mstat = lstat = stat & ~MANTIS_INT_RISCSTAT;
+       lstat = stat & ~MANTIS_INT_RISCSTAT;
        if (!(stat & mask))
                return IRQ_NONE;
 
@@ -134,7 +134,7 @@ static irqreturn_t mantis_irq_handler(int irq, void *dev_id)
        }
        if (stat & MANTIS_INT_RISCI) {
                dprintk(MANTIS_DEBUG, 0, "<%s>", label[8]);
-               mantis->finished_block = (stat & MANTIS_INT_RISCSTAT) >> 28;
+               mantis->busy_block = (stat & MANTIS_INT_RISCSTAT) >> 28;
                tasklet_schedule(&mantis->tasklet);
        }
        if (stat & MANTIS_INT_I2CDONE) {
index 49dbca145bb8e3ae13aa47eb77fdfecf74c0462d..f2410cf0a6bf0ec980b475f8785d5afb7a58ec52 100644 (file)
@@ -123,11 +123,8 @@ struct mantis_pci {
        unsigned int            num;
 
        /*      RISC Core               */
-       u32                     finished_block;
+       u32                     busy_block;
        u32                     last_block;
-       u32                     line_bytes;
-       u32                     line_count;
-       u32                     risc_pos;
        u8                      *buf_cpu;
        dma_addr_t              buf_dma;
        u32                     *risc_cpu;
index 46202a4012aac8331d343769c449d50d73c1280e..c61ca7d3daea41c217ad2f29821bb468e509a452 100644 (file)
 #define RISC_IRQ               (0x01 << 24)
 
 #define RISC_STATUS(status)    ((((~status) & 0x0f) << 20) | ((status & 0x0f) << 16))
-#define RISC_FLUSH()           (mantis->risc_pos = 0)
-#define RISC_INSTR(opcode)     (mantis->risc_cpu[mantis->risc_pos++] = cpu_to_le32(opcode))
+#define RISC_FLUSH(risc_pos)           (risc_pos = 0)
+#define RISC_INSTR(risc_pos, opcode)   (mantis->risc_cpu[risc_pos++] = cpu_to_le32(opcode))
 
 #define MANTIS_BUF_SIZE                (64 * 1024)
-#define MANTIS_BLOCK_BYTES     (MANTIS_BUF_SIZE >> 4)
-#define MANTIS_BLOCK_COUNT     (1 << 4)
-#define MANTIS_RISC_SIZE       PAGE_SIZE
+#define MANTIS_BLOCK_BYTES      (MANTIS_BUF_SIZE / 4)
+#define MANTIS_DMA_TR_BYTES     (2 * 1024) /* upper limit: 4095 bytes. */
+#define MANTIS_BLOCK_COUNT     (MANTIS_BUF_SIZE / MANTIS_BLOCK_BYTES)
+
+#define MANTIS_DMA_TR_UNITS     (MANTIS_BLOCK_BYTES / MANTIS_DMA_TR_BYTES)
+/* MANTIS_BUF_SIZE / MANTIS_DMA_TR_UNITS must not exceed MANTIS_RISC_SIZE (4k RISC cmd buffer) */
+#define MANTIS_RISC_SIZE       PAGE_SIZE /* RISC program must fit here. */
 
 int mantis_dma_exit(struct mantis_pci *mantis)
 {
@@ -124,27 +128,6 @@ err:
        return -ENOMEM;
 }
 
-static inline int mantis_calc_lines(struct mantis_pci *mantis)
-{
-       mantis->line_bytes = MANTIS_BLOCK_BYTES;
-       mantis->line_count = MANTIS_BLOCK_COUNT;
-
-       while (mantis->line_bytes > 4095) {
-               mantis->line_bytes >>= 1;
-               mantis->line_count <<= 1;
-       }
-
-       dprintk(MANTIS_DEBUG, 1, "Mantis RISC block bytes=[%d], line bytes=[%d], line count=[%d]",
-               MANTIS_BLOCK_BYTES, mantis->line_bytes, mantis->line_count);
-
-       if (mantis->line_count > 255) {
-               dprintk(MANTIS_ERROR, 1, "Buffer size error");
-               return -EINVAL;
-       }
-
-       return 0;
-}
-
 int mantis_dma_init(struct mantis_pci *mantis)
 {
        int err = 0;
@@ -158,12 +141,6 @@ int mantis_dma_init(struct mantis_pci *mantis)
 
                goto err;
        }
-       err = mantis_calc_lines(mantis);
-       if (err < 0) {
-               dprintk(MANTIS_ERROR, 1, "Mantis calc lines failed");
-
-               goto err;
-       }
 
        return 0;
 err:
@@ -174,31 +151,32 @@ EXPORT_SYMBOL_GPL(mantis_dma_init);
 static inline void mantis_risc_program(struct mantis_pci *mantis)
 {
        u32 buf_pos = 0;
-       u32 line;
+       u32 line, step;
+       u32 risc_pos;
 
        dprintk(MANTIS_DEBUG, 1, "Mantis create RISC program");
-       RISC_FLUSH();
-
-       dprintk(MANTIS_DEBUG, 1, "risc len lines %u, bytes per line %u",
-               mantis->line_count, mantis->line_bytes);
-
-       for (line = 0; line < mantis->line_count; line++) {
-               dprintk(MANTIS_DEBUG, 1, "RISC PROG line=[%d]", line);
-               if (!(buf_pos % MANTIS_BLOCK_BYTES)) {
-                       RISC_INSTR(RISC_WRITE   |
-                                  RISC_IRQ     |
-                                  RISC_STATUS(((buf_pos / MANTIS_BLOCK_BYTES) +
-                                  (MANTIS_BLOCK_COUNT - 1)) %
-                                   MANTIS_BLOCK_COUNT) |
-                                   mantis->line_bytes);
-               } else {
-                       RISC_INSTR(RISC_WRITE   | mantis->line_bytes);
-               }
-               RISC_INSTR(mantis->buf_dma + buf_pos);
-               buf_pos += mantis->line_bytes;
+       RISC_FLUSH(risc_pos);
+
+       dprintk(MANTIS_DEBUG, 1, "risc len lines %u, bytes per line %u, bytes per DMA tr %u",
+               MANTIS_BLOCK_COUNT, MANTIS_BLOCK_BYTES, MANTIS_DMA_TR_BYTES);
+
+       for (line = 0; line < MANTIS_BLOCK_COUNT; line++) {
+               for (step = 0; step < MANTIS_DMA_TR_UNITS; step++) {
+                       dprintk(MANTIS_DEBUG, 1, "RISC PROG line=[%d], step=[%d]", line, step);
+                       if (step == 0) {
+                               RISC_INSTR(risc_pos, RISC_WRITE |
+                                          RISC_IRQ     |
+                                          RISC_STATUS(line) |
+                                          MANTIS_DMA_TR_BYTES);
+                       } else {
+                               RISC_INSTR(risc_pos, RISC_WRITE | MANTIS_DMA_TR_BYTES);
+                       }
+                       RISC_INSTR(risc_pos, mantis->buf_dma + buf_pos);
+                       buf_pos += MANTIS_DMA_TR_BYTES;
+                 }
        }
-       RISC_INSTR(RISC_JUMP);
-       RISC_INSTR(mantis->risc_dma);
+       RISC_INSTR(risc_pos, RISC_JUMP);
+       RISC_INSTR(risc_pos, mantis->risc_dma);
 }
 
 void mantis_dma_start(struct mantis_pci *mantis)
@@ -210,7 +188,7 @@ void mantis_dma_start(struct mantis_pci *mantis)
        mmwrite(mmread(MANTIS_GPIF_ADDR) | MANTIS_GPIF_HIFRDWRN, MANTIS_GPIF_ADDR);
 
        mmwrite(0, MANTIS_DMA_CTL);
-       mantis->last_block = mantis->finished_block = 0;
+       mantis->last_block = mantis->busy_block = 0;
 
        mmwrite(mmread(MANTIS_INT_MASK) | MANTIS_INT_RISCI, MANTIS_INT_MASK);
 
@@ -245,9 +223,9 @@ void mantis_dma_xfer(unsigned long data)
        struct mantis_pci *mantis = (struct mantis_pci *) data;
        struct mantis_hwconfig *config = mantis->hwconfig;
 
-       while (mantis->last_block != mantis->finished_block) {
+       while (mantis->last_block != mantis->busy_block) {
                dprintk(MANTIS_DEBUG, 1, "last block=[%d] finished block=[%d]",
-                       mantis->last_block, mantis->finished_block);
+                       mantis->last_block, mantis->busy_block);
 
                (config->ts_size ? dvb_dmx_swfilter_204 : dvb_dmx_swfilter)
                (&mantis->demux, &mantis->buf_cpu[mantis->last_block * MANTIS_BLOCK_BYTES], MANTIS_BLOCK_BYTES);
index 38a436ca2fdf352341c141b87fc5ec3ede2a4311..07aa887a4b4a9ed46b9daf136e37c36ee9bbff9c 100644 (file)
@@ -51,7 +51,6 @@ static const struct stb0899_s1_reg vp1041_stb0899_s1_init_1[] = {
        { STB0899_DISRX_ST0             , 0x04 },
        { STB0899_DISRX_ST1             , 0x00 },
        { STB0899_DISPARITY             , 0x00 },
-       { STB0899_DISFIFO               , 0x00 },
        { STB0899_DISSTATUS             , 0x20 },
        { STB0899_DISF22                , 0x99 },
        { STB0899_DISF22RX              , 0xa8 },
index 2bc96874d044ef02973eda58e2ab259111058f4a..89873615e6839f81ebb10729784994b9963a672f 100644 (file)
@@ -6,9 +6,9 @@ ngene-objs := ngene-core.o ngene-i2c.o ngene-cards.o ngene-dvb.o
 
 obj-$(CONFIG_DVB_NGENE) += ngene.o
 
-EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/
-EXTRA_CFLAGS += -Idrivers/media/dvb/frontends/
-EXTRA_CFLAGS += -Idrivers/media/common/tuners/
+ccflags-y += -Idrivers/media/dvb/dvb-core/
+ccflags-y += -Idrivers/media/dvb/frontends/
+ccflags-y += -Idrivers/media/common/tuners/
 
 # For the staging CI driver cxd2099
-EXTRA_CFLAGS += -Idrivers/staging/cxd2099/
+ccflags-y += -Idrivers/staging/cxd2099/
index 7ac128724df81100393c416af4cd872116e706bb..700822350ec5def033151293ea8e0ffc6585aa17 100644 (file)
@@ -1,3 +1,3 @@
 obj-$(CONFIG_DVB_PLUTO2) += pluto2.o
 
-EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
+ccflags-y += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
index a66da17bbe31c77d0cd6a344ed3cc0b04ec89301..d80d8e8e7c572b7218bd1103e669ab50ed352f97 100644 (file)
@@ -2,4 +2,4 @@ earth-pt1-objs := pt1.o va1j5jf8007s.o va1j5jf8007t.o
 
 obj-$(CONFIG_DVB_PT1) += earth-pt1.o
 
-EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core -Idrivers/media/dvb/frontends
+ccflags-y += -Idrivers/media/dvb/dvb-core -Idrivers/media/dvb/frontends
index c54140b5ab5a11e7defb883e3cda4e73d8b0406d..f233b57c86fb61144a6a32c11ed82e10c823d1c0 100644 (file)
@@ -5,7 +5,7 @@ obj-$(CONFIG_SMS_SIANO_MDTV) += smsmdtv.o smsdvb.o
 obj-$(CONFIG_SMS_USB_DRV) += smsusb.o
 obj-$(CONFIG_SMS_SDIO_DRV) += smssdio.o
 
-EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
+ccflags-y += -Idrivers/media/dvb/dvb-core
 
-EXTRA_CFLAGS += $(extra-cflags-y) $(extra-cflags-m)
+ccflags-y += $(extra-cflags-y) $(extra-cflags-m)
 
index 8a4d5bb20a5b18d36a5ebaf6697b79f463b62fd1..f6e869372e303f3f7dfac8b497e2c0e76a40be6c 100644 (file)
@@ -17,5 +17,5 @@ obj-$(CONFIG_DVB_BUDGET_CI) += budget-ci.o
 obj-$(CONFIG_DVB_BUDGET_PATCH) += budget-patch.o
 obj-$(CONFIG_DVB_AV7110) += dvb-ttpci.o
 
-EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
-EXTRA_CFLAGS += -Idrivers/media/common/tuners
+ccflags-y += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
+ccflags-y += -Idrivers/media/common/tuners
index cdd31cae46c437aab38f3f40024519236b2355c3..ee8ee1d481fa57003e1fdde762d362d15484a4e2 100644 (file)
@@ -25,6 +25,8 @@
  * the project's page is at http://www.linuxtv.org/ 
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/kernel.h>
 #include <linux/types.h>
 #include <linux/delay.h>
@@ -253,7 +255,7 @@ static int av7110_dvb_c_switch(struct saa7146_fh *fh)
 
                switch (av7110->current_input) {
                case 1:
-                       dprintk(1, "switching SAA7113 to Analog Tuner Input.\n");
+                       dprintk(1, "switching SAA7113 to Analog Tuner Input\n");
                        msp_writereg(av7110, MSP_WR_DSP, 0x0008, 0x0000); // loudspeaker source
                        msp_writereg(av7110, MSP_WR_DSP, 0x0009, 0x0000); // headphone source
                        msp_writereg(av7110, MSP_WR_DSP, 0x000a, 0x0000); // SCART 1 source
@@ -263,7 +265,7 @@ static int av7110_dvb_c_switch(struct saa7146_fh *fh)
 
                        if (av7110->analog_tuner_flags & ANALOG_TUNER_VES1820) {
                                if (ves1820_writereg(dev, 0x09, 0x0f, 0x60))
-                                       dprintk(1, "setting band in demodulator failed.\n");
+                                       dprintk(1, "setting band in demodulator failed\n");
                        } else if (av7110->analog_tuner_flags & ANALOG_TUNER_STV0297) {
                                saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTHI); // TDA9819 pin9(STD)
                                saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI); // TDA9819 pin30(VIF)
@@ -272,17 +274,17 @@ static int av7110_dvb_c_switch(struct saa7146_fh *fh)
                                dprintk(1, "saa7113 write failed @ card %d", av7110->dvb_adapter.num);
                        break;
                case 2:
-                       dprintk(1, "switching SAA7113 to Video AV CVBS Input.\n");
+                       dprintk(1, "switching SAA7113 to Video AV CVBS Input\n");
                        if (i2c_writereg(av7110, 0x48, 0x02, 0xd2) != 1)
                                dprintk(1, "saa7113 write failed @ card %d", av7110->dvb_adapter.num);
                        break;
                case 3:
-                       dprintk(1, "switching SAA7113 to Video AV Y/C Input.\n");
+                       dprintk(1, "switching SAA7113 to Video AV Y/C Input\n");
                        if (i2c_writereg(av7110, 0x48, 0x02, 0xd9) != 1)
                                dprintk(1, "saa7113 write failed @ card %d", av7110->dvb_adapter.num);
                        break;
                default:
-                       dprintk(1, "switching SAA7113 to Input: AV7110: SAA7113: invalid input.\n");
+                       dprintk(1, "switching SAA7113 to Input: AV7110: SAA7113: invalid input\n");
                }
        } else {
                adswitch = 0;
@@ -299,7 +301,7 @@ static int av7110_dvb_c_switch(struct saa7146_fh *fh)
 
                if (av7110->analog_tuner_flags & ANALOG_TUNER_VES1820) {
                        if (ves1820_writereg(dev, 0x09, 0x0f, 0x20))
-                               dprintk(1, "setting band in demodulator failed.\n");
+                               dprintk(1, "setting band in demodulator failed\n");
                } else if (av7110->analog_tuner_flags & ANALOG_TUNER_STV0297) {
                        saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTLO); // TDA9819 pin9(STD)
                        saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO); // TDA9819 pin30(VIF)
@@ -413,7 +415,7 @@ static int vidioc_g_frequency(struct file *file, void *fh, struct v4l2_frequency
        struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
        struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
 
-       dprintk(2, "VIDIOC_G_FREQ: freq:0x%08x.\n", f->frequency);
+       dprintk(2, "VIDIOC_G_FREQ: freq:0x%08x\n", f->frequency);
 
        if (!av7110->analog_tuner_flags || av7110->current_input != 1)
                return -EINVAL;
@@ -429,7 +431,7 @@ static int vidioc_s_frequency(struct file *file, void *fh, struct v4l2_frequency
        struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
        struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
 
-       dprintk(2, "VIDIOC_S_FREQUENCY: freq:0x%08x.\n", f->frequency);
+       dprintk(2, "VIDIOC_S_FREQUENCY: freq:0x%08x\n", f->frequency);
 
        if (!av7110->analog_tuner_flags || av7110->current_input != 1)
                return -EINVAL;
@@ -689,12 +691,12 @@ int av7110_init_analog_module(struct av7110 *av7110)
 
        if (i2c_writereg(av7110, 0x80, 0x0, 0x80) == 1 &&
            i2c_writereg(av7110, 0x80, 0x0, 0) == 1) {
-               printk("dvb-ttpci: DVB-C analog module @ card %d detected, initializing MSP3400\n",
+               pr_info("DVB-C analog module @ card %d detected, initializing MSP3400\n",
                        av7110->dvb_adapter.num);
                av7110->adac_type = DVB_ADAC_MSP34x0;
        } else if (i2c_writereg(av7110, 0x84, 0x0, 0x80) == 1 &&
                   i2c_writereg(av7110, 0x84, 0x0, 0) == 1) {
-               printk("dvb-ttpci: DVB-C analog module @ card %d detected, initializing MSP3415\n",
+               pr_info("DVB-C analog module @ card %d detected, initializing MSP3415\n",
                        av7110->dvb_adapter.num);
                av7110->adac_type = DVB_ADAC_MSP34x5;
        } else
@@ -715,7 +717,7 @@ int av7110_init_analog_module(struct av7110 *av7110)
        msp_writereg(av7110, MSP_WR_DSP, 0x000d, 0x1900); // prescale SCART
 
        if (i2c_writereg(av7110, 0x48, 0x01, 0x00)!=1) {
-               INFO(("saa7113 not accessible.\n"));
+               pr_info("saa7113 not accessible\n");
        } else {
                u8 *i = saa7113_init_regs;
 
@@ -733,7 +735,7 @@ int av7110_init_analog_module(struct av7110 *av7110)
                /* setup for DVB by default */
                if (av7110->analog_tuner_flags & ANALOG_TUNER_VES1820) {
                        if (ves1820_writereg(av7110->dev, 0x09, 0x0f, 0x20))
-                               dprintk(1, "setting band in demodulator failed.\n");
+                               dprintk(1, "setting band in demodulator failed\n");
                } else if (av7110->analog_tuner_flags & ANALOG_TUNER_STV0297) {
                        saa7146_setgpio(av7110->dev, 1, SAA7146_GPIO_OUTLO); // TDA9819 pin9(STD)
                        saa7146_setgpio(av7110->dev, 3, SAA7146_GPIO_OUTLO); // TDA9819 pin30(VIF)
@@ -797,7 +799,7 @@ int av7110_init_v4l(struct av7110 *av7110)
        ret = saa7146_vv_init(dev, vv_data);
 
        if (ret) {
-               ERR(("cannot init capture device. skipping.\n"));
+               ERR("cannot init capture device. skipping\n");
                return -ENODEV;
        }
        vv_data->ops.vidioc_enum_input = vidioc_enum_input;
@@ -814,12 +816,12 @@ int av7110_init_v4l(struct av7110 *av7110)
        vv_data->ops.vidioc_s_fmt_sliced_vbi_out = vidioc_s_fmt_sliced_vbi_out;
 
        if (saa7146_register_device(&av7110->v4l_dev, dev, "av7110", VFL_TYPE_GRABBER)) {
-               ERR(("cannot register capture device. skipping.\n"));
+               ERR("cannot register capture device. skipping\n");
                saa7146_vv_release(dev);
                return -ENODEV;
        }
        if (saa7146_register_device(&av7110->vbi_dev, dev, "av7110", VFL_TYPE_VBI))
-               ERR(("cannot register vbi v4l2 device. skipping.\n"));
+               ERR("cannot register vbi v4l2 device. skipping\n");
        return 0;
 }
 
index e957d7690bccf3cf2a13f7d555c0a270f6f42fb7..78d32f7e49fc569b84d16f68615f998c2c4dfeb4 100644 (file)
@@ -33,6 +33,8 @@
  * the project's page is at http://www.linuxtv.org/ 
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include "budget.h"
 #include "stv0299.h"
 #include "stb0899_drv.h"
@@ -149,7 +151,7 @@ static int ciintf_read_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int ad
        result = ttpci_budget_debiread(&budget_av->budget, DEBICICAM, address & 0xfff, 1, 0, 1);
        if (result == -ETIMEDOUT) {
                ciintf_slot_shutdown(ca, slot);
-               printk(KERN_INFO "budget-av: cam ejected 1\n");
+               pr_info("cam ejected 1\n");
        }
        return result;
 }
@@ -168,7 +170,7 @@ static int ciintf_write_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int a
        result = ttpci_budget_debiwrite(&budget_av->budget, DEBICICAM, address & 0xfff, 1, value, 0, 1);
        if (result == -ETIMEDOUT) {
                ciintf_slot_shutdown(ca, slot);
-               printk(KERN_INFO "budget-av: cam ejected 2\n");
+               pr_info("cam ejected 2\n");
        }
        return result;
 }
@@ -187,7 +189,7 @@ static int ciintf_read_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 addre
        result = ttpci_budget_debiread(&budget_av->budget, DEBICICAM, address & 3, 1, 0, 0);
        if (result == -ETIMEDOUT) {
                ciintf_slot_shutdown(ca, slot);
-               printk(KERN_INFO "budget-av: cam ejected 3\n");
+               pr_info("cam ejected 3\n");
                return -ETIMEDOUT;
        }
        return result;
@@ -207,7 +209,7 @@ static int ciintf_write_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 addr
        result = ttpci_budget_debiwrite(&budget_av->budget, DEBICICAM, address & 3, 1, value, 0, 0);
        if (result == -ETIMEDOUT) {
                ciintf_slot_shutdown(ca, slot);
-               printk(KERN_INFO "budget-av: cam ejected 5\n");
+               pr_info("cam ejected 5\n");
        }
        return result;
 }
@@ -289,7 +291,7 @@ static int ciintf_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int open
                if (saa7146_read(saa, PSR) & MASK_06) {
                        if (budget_av->slot_status == SLOTSTATUS_NONE) {
                                budget_av->slot_status = SLOTSTATUS_PRESENT;
-                               printk(KERN_INFO "budget-av: cam inserted A\n");
+                               pr_info("cam inserted A\n");
                        }
                }
                saa7146_setgpio(saa, 3, SAA7146_GPIO_OUTLO);
@@ -306,11 +308,11 @@ static int ciintf_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int open
                result = ttpci_budget_debiread(&budget_av->budget, DEBICICAM, 0, 1, 0, 1);
                if ((result >= 0) && (budget_av->slot_status == SLOTSTATUS_NONE)) {
                        budget_av->slot_status = SLOTSTATUS_PRESENT;
-                       printk(KERN_INFO "budget-av: cam inserted B\n");
+                       pr_info("cam inserted B\n");
                } else if (result < 0) {
                        if (budget_av->slot_status != SLOTSTATUS_NONE) {
                                ciintf_slot_shutdown(ca, slot);
-                               printk(KERN_INFO "budget-av: cam ejected 5\n");
+                               pr_info("cam ejected 5\n");
                                return 0;
                        }
                }
@@ -365,11 +367,11 @@ static int ciintf_init(struct budget_av *budget_av)
 
        if ((result = dvb_ca_en50221_init(&budget_av->budget.dvb_adapter,
                                          &budget_av->ca, 0, 1)) != 0) {
-               printk(KERN_ERR "budget-av: ci initialisation failed.\n");
+               pr_err("ci initialisation failed\n");
                goto error;
        }
 
-       printk(KERN_INFO "budget-av: ci interface initialised.\n");
+       pr_info("ci interface initialised\n");
        return 0;
 
 error:
@@ -896,7 +898,6 @@ static const struct stb0899_s1_reg knc1_stb0899_s1_init_1[] = {
        { STB0899_DISRX_ST0             , 0x04 },
        { STB0899_DISRX_ST1             , 0x00 },
        { STB0899_DISPARITY             , 0x00 },
-       { STB0899_DISFIFO               , 0x00 },
        { STB0899_DISSTATUS             , 0x20 },
        { STB0899_DISF22                , 0x8c },
        { STB0899_DISF22RX              , 0x9a },
@@ -1197,6 +1198,7 @@ static u8 read_pwm(struct budget_av *budget_av)
 #define SUBID_DVBC_KNC1                        0x0020
 #define SUBID_DVBC_KNC1_PLUS           0x0021
 #define SUBID_DVBC_KNC1_MK3            0x0022
+#define SUBID_DVBC_KNC1_TDA10024       0x0028
 #define SUBID_DVBC_KNC1_PLUS_MK3       0x0023
 #define SUBID_DVBC_CINERGY1200         0x1156
 #define SUBID_DVBC_CINERGY1200_MK3     0x1176
@@ -1316,6 +1318,7 @@ static void frontend_init(struct budget_av *budget_av)
        case SUBID_DVBC_EASYWATCH_MK3:
        case SUBID_DVBC_CINERGY1200_MK3:
        case SUBID_DVBC_KNC1_MK3:
+       case SUBID_DVBC_KNC1_TDA10024:
        case SUBID_DVBC_KNC1_PLUS_MK3:
                budget_av->reinitialise_demod = 1;
                budget_av->budget.dev->i2c_bitrate = SAA7146_I2C_BUS_BIT_RATE_240;
@@ -1343,8 +1346,7 @@ static void frontend_init(struct budget_av *budget_av)
        }
 
        if (fe == NULL) {
-               printk(KERN_ERR "budget-av: A frontend driver was not found "
-                               "for device [%04x:%04x] subsystem [%04x:%04x]\n",
+               pr_err("A frontend driver was not found for device [%04x:%04x] subsystem [%04x:%04x]\n",
                       saa->pci->vendor,
                       saa->pci->device,
                       saa->pci->subsystem_vendor,
@@ -1356,7 +1358,7 @@ static void frontend_init(struct budget_av *budget_av)
 
        if (dvb_register_frontend(&budget_av->budget.dvb_adapter,
                                  budget_av->budget.dvb_frontend)) {
-               printk(KERN_ERR "budget-av: Frontend registration failed!\n");
+               pr_err("Frontend registration failed!\n");
                dvb_frontend_detach(budget_av->budget.dvb_frontend);
                budget_av->budget.dvb_frontend = NULL;
        }
@@ -1414,7 +1416,7 @@ static struct v4l2_input knc1_inputs[KNC1_INPUTS] = {
 
 static int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *i)
 {
-       dprintk(1, "VIDIOC_ENUMINPUT %d.\n", i->index);
+       dprintk(1, "VIDIOC_ENUMINPUT %d\n", i->index);
        if (i->index >= KNC1_INPUTS)
                return -EINVAL;
        memcpy(i, &knc1_inputs[i->index], sizeof(struct v4l2_input));
@@ -1428,7 +1430,7 @@ static int vidioc_g_input(struct file *file, void *fh, unsigned int *i)
 
        *i = budget_av->cur_input;
 
-       dprintk(1, "VIDIOC_G_INPUT %d.\n", *i);
+       dprintk(1, "VIDIOC_G_INPUT %d\n", *i);
        return 0;
 }
 
@@ -1437,7 +1439,7 @@ static int vidioc_s_input(struct file *file, void *fh, unsigned int input)
        struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
        struct budget_av *budget_av = (struct budget_av *)dev->ext_priv;
 
-       dprintk(1, "VIDIOC_S_INPUT %d.\n", input);
+       dprintk(1, "VIDIOC_S_INPUT %d\n", input);
        return saa7113_setinput(budget_av, input);
 }
 
@@ -1476,7 +1478,7 @@ static int budget_av_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio
 
                if (0 != saa7146_vv_init(dev, &vv_data)) {
                        /* fixme: proper cleanup here */
-                       ERR(("cannot init vv subsystem.\n"));
+                       ERR("cannot init vv subsystem\n");
                        return err;
                }
                vv_data.ops.vidioc_enum_input = vidioc_enum_input;
@@ -1485,7 +1487,7 @@ static int budget_av_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio
 
                if ((err = saa7146_register_device(&budget_av->vd, dev, "knc1", VFL_TYPE_GRABBER))) {
                        /* fixme: proper cleanup here */
-                       ERR(("cannot register capture v4l2 device.\n"));
+                       ERR("cannot register capture v4l2 device\n");
                        saa7146_vv_release(dev);
                        return err;
                }
@@ -1502,13 +1504,12 @@ static int budget_av_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio
 
        mac = budget_av->budget.dvb_adapter.proposed_mac;
        if (i2c_readregs(&budget_av->budget.i2c_adap, 0xa0, 0x30, mac, 6)) {
-               printk(KERN_ERR "KNC1-%d: Could not read MAC from KNC1 card\n",
+               pr_err("KNC1-%d: Could not read MAC from KNC1 card\n",
                       budget_av->budget.dvb_adapter.num);
                memset(mac, 0, 6);
        } else {
-               printk(KERN_INFO "KNC1-%d: MAC addr = %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
-                      budget_av->budget.dvb_adapter.num,
-                      mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+               pr_info("KNC1-%d: MAC addr = %pM\n",
+                       budget_av->budget.dvb_adapter.num, mac);
        }
 
        budget_av->budget.dvb_adapter.priv = budget_av;
@@ -1558,6 +1559,7 @@ MAKE_BUDGET_INFO(knc1sp, "KNC1 DVB-S Plus", BUDGET_KNC1SP);
 MAKE_BUDGET_INFO(knc1spx4, "KNC1 DVB-S Plus X4", BUDGET_KNC1SP);
 MAKE_BUDGET_INFO(knc1cp, "KNC1 DVB-C Plus", BUDGET_KNC1CP);
 MAKE_BUDGET_INFO(knc1cmk3, "KNC1 DVB-C MK3", BUDGET_KNC1C_MK3);
+MAKE_BUDGET_INFO(knc1ctda10024, "KNC1 DVB-C TDA10024", BUDGET_KNC1C_TDA10024);
 MAKE_BUDGET_INFO(knc1cpmk3, "KNC1 DVB-C Plus MK3", BUDGET_KNC1CP_MK3);
 MAKE_BUDGET_INFO(knc1tp, "KNC1 DVB-T Plus", BUDGET_KNC1TP);
 MAKE_BUDGET_INFO(cin1200s, "TerraTec Cinergy 1200 DVB-S", BUDGET_CIN1200S);
@@ -1587,6 +1589,7 @@ static struct pci_device_id pci_tbl[] = {
        MAKE_EXTENSION_PCI(knc1c, 0x1894, 0x0020),
        MAKE_EXTENSION_PCI(knc1cp, 0x1894, 0x0021),
        MAKE_EXTENSION_PCI(knc1cmk3, 0x1894, 0x0022),
+       MAKE_EXTENSION_PCI(knc1ctda10024, 0x1894, 0x0028),
        MAKE_EXTENSION_PCI(knc1cpmk3, 0x1894, 0x0023),
        MAKE_EXTENSION_PCI(knc1t, 0x1894, 0x0030),
        MAKE_EXTENSION_PCI(knc1tp, 0x1894, 0x0031),
index 926f299b522553f719b67beba5a02f16f0450bf8..ca02e97221721e1f1927ed5b76a9ff29ed523665 100644 (file)
@@ -1053,7 +1053,6 @@ static const struct stb0899_s1_reg tt3200_stb0899_s1_init_1[] = {
        { STB0899_DISRX_ST0             , 0x04 },
        { STB0899_DISRX_ST1             , 0x00 },
        { STB0899_DISPARITY             , 0x00 },
-       { STB0899_DISFIFO               , 0x00 },
        { STB0899_DISSTATUS             , 0x20 },
        { STB0899_DISF22                , 0x8c },
        { STB0899_DISF22RX              , 0x9a },
index 37666d4edab679fb9e4d8a848293c985316d564a..37d02fe091376977840455a555038587dda0e9aa 100644 (file)
@@ -110,6 +110,7 @@ static int start_ts_capture(struct budget *budget)
                break;
        case BUDGET_CIN1200C_MK3:
        case BUDGET_KNC1C_MK3:
+       case BUDGET_KNC1C_TDA10024:
        case BUDGET_KNC1CP_MK3:
                if (budget->video_port == BUDGET_VIDEO_PORTA) {
                        saa7146_write(dev, DD1_INIT, 0x06000200);
@@ -434,6 +435,7 @@ int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev,
        case BUDGET_KNC1CP:
        case BUDGET_CIN1200C:
        case BUDGET_KNC1C_MK3:
+       case BUDGET_KNC1C_TDA10024:
        case BUDGET_KNC1CP_MK3:
        case BUDGET_CIN1200C_MK3:
                budget->buffer_width = TS_WIDTH_DVBC;
index 3ad0c6789ba736fd80e7a02b0810a6b8f4b50db4..3d8a806c20bb00b201ed577bb8c4360f1391b034 100644 (file)
@@ -104,6 +104,7 @@ static struct saa7146_pci_extension_data x_var = { \
 #define BUDGET_KNC1C_MK3          16
 #define BUDGET_KNC1CP_MK3         17
 #define BUDGET_KNC1S2              18
+#define BUDGET_KNC1C_TDA10024     19
 
 #define BUDGET_VIDEO_PORTA         0
 #define BUDGET_VIDEO_PORTB         1
index 7dd54b3026a251c9eb4ba7fbd69dc71fbdd8edb1..32d43156c54823e15e09e026b98cc50162c36b5b 100644 (file)
@@ -85,6 +85,35 @@ static int getmac_tt(u8 * decodedMAC, u8 * encodedMAC)
        return 0;
 }
 
+int ttpci_eeprom_decode_mac(u8 *decodedMAC, u8 *encodedMAC)
+{
+       u8 xor[20] = { 0x72, 0x23, 0x68, 0x19, 0x5c, 0xa8, 0x71, 0x2c,
+                      0x54, 0xd3, 0x7b, 0xf1, 0x9E, 0x23, 0x16, 0xf6,
+                      0x1d, 0x36, 0x64, 0x78};
+       u8 data[20];
+       int i;
+
+       memcpy(data, encodedMAC, 20);
+
+       for (i = 0; i < 20; i++)
+               data[i] ^= xor[i];
+       for (i = 0; i < 10; i++)
+               data[i] = ((data[2 * i + 1] << 8) | data[2 * i])
+                       >> ((data[2 * i + 1] >> 6) & 3);
+
+       if (check_mac_tt(data))
+               return -ENODEV;
+
+       decodedMAC[0] = data[2];
+       decodedMAC[1] = data[1];
+       decodedMAC[2] = data[0];
+       decodedMAC[3] = data[6];
+       decodedMAC[4] = data[5];
+       decodedMAC[5] = data[4];
+       return 0;
+}
+EXPORT_SYMBOL(ttpci_eeprom_decode_mac);
+
 static int ttpci_eeprom_read_encodedMAC(struct i2c_adapter *adapter, u8 * encodedMAC)
 {
        int ret;
index e2dc6cfe205c4052725c7be656d424f14d48a179..dcc33d5a5cb14848f99a61c0110fc38546011977 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/types.h>
 #include <linux/i2c.h>
 
+extern int ttpci_eeprom_decode_mac(u8 *decodedMAC, u8 *encodedMAC);
 extern int ttpci_eeprom_parse_mac(struct i2c_adapter *adapter, u8 *propsed_mac);
 
 #endif
index fbe2b9514c21bdc98fd69294adfcb25368781210..8d6c4acb7f1d49eada6f692b545d0940dff6fb03 100644 (file)
@@ -1,3 +1,3 @@
 obj-$(CONFIG_DVB_TTUSB_BUDGET) += dvb-ttusb-budget.o
 
-EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends
+ccflags-y += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends
index 2d70a8269391e20e6e8a49638ab69e9b626fb7b1..ed28b5384d20c190b78c3ab66d83119d1288e41b 100644 (file)
@@ -1,3 +1,3 @@
 obj-$(CONFIG_DVB_TTUSB_DEC) += ttusb_dec.o ttusbdecfe.o
 
-EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/
+ccflags-y += -Idrivers/media/dvb/dvb-core/
index f484a6e04eb248f80070632a39a2754c03dc435e..390daf94d84737aa25dde99341c58c89513f57fa 100644 (file)
@@ -27,4 +27,4 @@ obj-$(CONFIG_RADIO_TIMBERDALE) += radio-timb.o
 obj-$(CONFIG_RADIO_WL1273) += radio-wl1273.o
 obj-$(CONFIG_RADIO_WL128X) += wl128x/
 
-EXTRA_CFLAGS += -Isound
+ccflags-y += -Isound
index 444b4cf7e65c0ae14e8454954ea199567487c437..d1fab58850612a333fea3a5f26603bf04c52bc90 100644 (file)
@@ -92,10 +92,6 @@ static int radio_si4713_s_audout(struct file *file, void *priv,
 static int radio_si4713_querycap(struct file *file, void *priv,
                                        struct v4l2_capability *capability)
 {
-       struct radio_si4713_device *rsdev;
-
-       rsdev = video_get_drvdata(video_devdata(file));
-
        strlcpy(capability->driver, "radio-si4713", sizeof(capability->driver));
        strlcpy(capability->card, "Silicon Labs Si4713 Modulator",
                                sizeof(capability->card));
index 46cacf845049941c5ad0efc687e23fd2ad4236d7..6d1e4e750f63a08bd88dca3d305014583b01b925 100644 (file)
@@ -2109,7 +2109,7 @@ static int __devinit wl1273_fm_radio_probe(struct platform_device *pdev)
                                 V4L2_CID_TUNE_ANTENNA_CAPACITOR,
                                 0, 255, 1, 255);
        if (ctrl)
-               ctrl->is_volatile = 1;
+               ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
 
        if (radio->ctrl_handler.error) {
                r = radio->ctrl_handler.error;
index 4cf537043f99ec420ae8ebb6f960642a72bf9a5c..a6ad707fae963e507afe7fe785edef6114bf8475 100644 (file)
@@ -395,7 +395,6 @@ int si470x_disconnect_check(struct si470x_device *radio)
 static void si470x_int_in_callback(struct urb *urb)
 {
        struct si470x_device *radio = urb->context;
-       unsigned char buf[RDS_REPORT_SIZE];
        int retval;
        unsigned char regnr;
        unsigned char blocknum;
@@ -423,7 +422,6 @@ static void si470x_int_in_callback(struct urb *urb)
 
        if (urb->actual_length > 0) {
                /* Update RDS registers with URB data */
-               buf[0] = RDS_REPORT;
                for (regnr = 0; regnr < RDS_REGISTER_NUM; regnr++)
                        radio->registers[STATUSRSSI + regnr] =
                            get_unaligned_be16(&radio->int_in_buffer[
index ec1d52f38904e55805e65d4583099a5c7bcc210b..b93d8cf23b036578cc629d54a6460ce2592ff2f4 100644 (file)
@@ -84,12 +84,14 @@ static ssize_t fm_v4l2_fops_write(struct file *file, const char __user * buf,
        ret = copy_from_user(&rds, buf, sizeof(rds));
        fmdbg("(%d)type: %d, text %s, af %d\n",
                   ret, rds.text_type, rds.text, rds.af_freq);
+       if (ret)
+               return -EFAULT;
 
        fmdev = video_drvdata(file);
        fm_tx_set_radio_text(fmdev, rds.text, rds.text_type);
        fm_tx_set_af(fmdev, rds.af_freq);
 
-       return 0;
+       return sizeof(rds);
 }
 
 static u32 fm_v4l2_fops_poll(struct file *file, struct poll_table_struct *pts)
@@ -557,7 +559,7 @@ int fm_v4l2_init_video_device(struct fmdev *fmdev, int radio_nr)
                        255, 1, 255);
 
        if (ctrl)
-               ctrl->is_volatile = 1;
+               ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
 
        return 0;
 }
index 899f783d92fbb4e91d35fd1e8395a86a1732794c..aeb7f43dfb652790b053192bceeca1f9fdf31758 100644 (file)
@@ -4,8 +4,8 @@ menuconfig RC_CORE
        default INPUT
        ---help---
          Enable support for Remote Controllers on Linux. This is
-         needed in order to support several video capture adapters.
-         Currently, all supported devices use InfraRed.
+         needed in order to support several video capture adapters,
+         standalone IR receivers/transmitters, and RF receivers.
 
          Enable this option if you have a video capture board even
          if you don't need IR, as otherwise, you may not be able to
@@ -108,6 +108,25 @@ config IR_LIRC_CODEC
           Enable this option to pass raw IR to and from userspace via
           the LIRC interface.
 
+config RC_ATI_REMOTE
+       tristate "ATI / X10 based USB RF remote controls"
+       depends on USB_ARCH_HAS_HCD
+       depends on RC_CORE
+       select USB
+       help
+          Say Y here if you want to use an X10 based USB remote control.
+          These are RF remotes with USB receivers.
+
+          Such devices include the ATI remote that comes with many of ATI's
+          All-In-Wonder video cards, the X10 "Lola" remote, NVIDIA RF remote,
+          Medion RF remote, and SnapStream FireFly remote.
+
+          This driver provides mouse pointer, left and right mouse buttons,
+          and maps all the other remote buttons to keypress events.
+
+          To compile this driver as a module, choose M here: the module will be
+          called ati_remote.
+
 config IR_ENE
        tristate "ENE eHome Receiver/Transceiver (pnp id: ENE0100/ENE02xxx)"
        depends on PNP
index f224db027c411ecdaf8ddfa69f5bec43e2b1d05f..2156e786b5571194bbe36b69c4ac1e610cbfc75c 100644 (file)
@@ -14,6 +14,7 @@ obj-$(CONFIG_IR_MCE_KBD_DECODER) += ir-mce_kbd-decoder.o
 obj-$(CONFIG_IR_LIRC_CODEC) += ir-lirc-codec.o
 
 # stand-alone IR receivers/transmitters
+obj-$(CONFIG_RC_ATI_REMOTE) += ati_remote.o
 obj-$(CONFIG_IR_IMON) += imon.o
 obj-$(CONFIG_IR_ITE_CIR) += ite-cir.o
 obj-$(CONFIG_IR_MCEUSB) += mceusb.o
similarity index 77%
rename from drivers/input/misc/ati_remote.c
rename to drivers/media/rc/ati_remote.c
index bce57129afba150592573b137a8b8071614fa1d0..303f22ea04c075792cd2953628230c82d9e01160 100644 (file)
@@ -1,6 +1,7 @@
 /*
  *  USB ATI Remote support
  *
+ *                Copyright (c) 2011 Anssi Hannula <anssi.hannula@iki.fi>
  *  Version 2.2.0 Copyright (c) 2004 Torrey Hoffman <thoffman@arnor.net>
  *  Version 2.1.1 Copyright (c) 2002 Vladimir Dergachev
  *
 #include <linux/init.h>
 #include <linux/slab.h>
 #include <linux/module.h>
+#include <linux/mutex.h>
 #include <linux/usb/input.h>
 #include <linux/wait.h>
 #include <linux/jiffies.h>
+#include <media/rc-core.h>
 
 /*
  * Module and Version Information, Module Parameters
 #define ATI_REMOTE_PRODUCT_ID          0x0004
 #define NVIDIA_REMOTE_PRODUCT_ID       0x0005
 #define MEDION_REMOTE_PRODUCT_ID       0x0006
+#define FIREFLY_REMOTE_PRODUCT_ID      0x0008
 
-#define DRIVER_VERSION         "2.2.1"
+#define DRIVER_VERSION         "2.2.1"
 #define DRIVER_AUTHOR           "Torrey Hoffman <thoffman@arnor.net>"
 #define DRIVER_DESC             "ATI/X10 RF USB Remote Control"
 
@@ -139,16 +143,21 @@ static int repeat_delay = REPEAT_DELAY;
 module_param(repeat_delay, int, 0644);
 MODULE_PARM_DESC(repeat_delay, "Delay before sending repeats, default = 500 msec");
 
+static bool mouse = true;
+module_param(mouse, bool, 0444);
+MODULE_PARM_DESC(mouse, "Enable mouse device, default = yes");
+
 #define dbginfo(dev, format, arg...) do { if (debug) dev_info(dev , format , ## arg); } while (0)
 #undef err
 #define err(format, arg...) printk(KERN_ERR format , ## arg)
 
 static struct usb_device_id ati_remote_table[] = {
-       { USB_DEVICE(ATI_REMOTE_VENDOR_ID, LOLA_REMOTE_PRODUCT_ID) },
-       { USB_DEVICE(ATI_REMOTE_VENDOR_ID, LOLA2_REMOTE_PRODUCT_ID) },
-       { USB_DEVICE(ATI_REMOTE_VENDOR_ID, ATI_REMOTE_PRODUCT_ID) },
-       { USB_DEVICE(ATI_REMOTE_VENDOR_ID, NVIDIA_REMOTE_PRODUCT_ID) },
-       { USB_DEVICE(ATI_REMOTE_VENDOR_ID, MEDION_REMOTE_PRODUCT_ID) },
+       { USB_DEVICE(ATI_REMOTE_VENDOR_ID, LOLA_REMOTE_PRODUCT_ID),     .driver_info = (unsigned long)RC_MAP_ATI_X10 },
+       { USB_DEVICE(ATI_REMOTE_VENDOR_ID, LOLA2_REMOTE_PRODUCT_ID),    .driver_info = (unsigned long)RC_MAP_ATI_X10 },
+       { USB_DEVICE(ATI_REMOTE_VENDOR_ID, ATI_REMOTE_PRODUCT_ID),      .driver_info = (unsigned long)RC_MAP_ATI_X10 },
+       { USB_DEVICE(ATI_REMOTE_VENDOR_ID, NVIDIA_REMOTE_PRODUCT_ID),   .driver_info = (unsigned long)RC_MAP_ATI_X10 },
+       { USB_DEVICE(ATI_REMOTE_VENDOR_ID, MEDION_REMOTE_PRODUCT_ID),   .driver_info = (unsigned long)RC_MAP_MEDION_X10 },
+       { USB_DEVICE(ATI_REMOTE_VENDOR_ID, FIREFLY_REMOTE_PRODUCT_ID),  .driver_info = (unsigned long)RC_MAP_SNAPSTREAM_FIREFLY },
        {}      /* Terminating entry */
 };
 
@@ -167,6 +176,7 @@ static char init2[] = { 0x01, 0x00, 0x20, 0x14, 0x20, 0x20, 0x20 };
 
 struct ati_remote {
        struct input_dev *idev;
+       struct rc_dev *rdev;
        struct usb_device *udev;
        struct usb_interface *interface;
 
@@ -186,11 +196,16 @@ struct ati_remote {
 
        unsigned int repeat_count;
 
-       char name[NAME_BUFSIZE];
-       char phys[NAME_BUFSIZE];
+       char rc_name[NAME_BUFSIZE];
+       char rc_phys[NAME_BUFSIZE];
+       char mouse_name[NAME_BUFSIZE];
+       char mouse_phys[NAME_BUFSIZE];
 
        wait_queue_head_t wait;
        int send_flags;
+
+       int users; /* 0-2, users are rc and input */
+       struct mutex open_mutex;
 };
 
 /* "Kinds" of messages sent from the hardware to the driver. */
@@ -233,64 +248,11 @@ static const struct {
        {KIND_FILTERED, 0x3f, 0x7a, EV_KEY, BTN_SIDE, 1}, /* left dblclick */
        {KIND_FILTERED, 0x43, 0x7e, EV_KEY, BTN_EXTRA, 1},/* right dblclick */
 
-       /* keyboard. */
-       {KIND_FILTERED, 0xd2, 0x0d, EV_KEY, KEY_1, 1},
-       {KIND_FILTERED, 0xd3, 0x0e, EV_KEY, KEY_2, 1},
-       {KIND_FILTERED, 0xd4, 0x0f, EV_KEY, KEY_3, 1},
-       {KIND_FILTERED, 0xd5, 0x10, EV_KEY, KEY_4, 1},
-       {KIND_FILTERED, 0xd6, 0x11, EV_KEY, KEY_5, 1},
-       {KIND_FILTERED, 0xd7, 0x12, EV_KEY, KEY_6, 1},
-       {KIND_FILTERED, 0xd8, 0x13, EV_KEY, KEY_7, 1},
-       {KIND_FILTERED, 0xd9, 0x14, EV_KEY, KEY_8, 1},
-       {KIND_FILTERED, 0xda, 0x15, EV_KEY, KEY_9, 1},
-       {KIND_FILTERED, 0xdc, 0x17, EV_KEY, KEY_0, 1},
-       {KIND_FILTERED, 0xc5, 0x00, EV_KEY, KEY_A, 1},
-       {KIND_FILTERED, 0xc6, 0x01, EV_KEY, KEY_B, 1},
-       {KIND_FILTERED, 0xde, 0x19, EV_KEY, KEY_C, 1},
-       {KIND_FILTERED, 0xe0, 0x1b, EV_KEY, KEY_D, 1},
-       {KIND_FILTERED, 0xe6, 0x21, EV_KEY, KEY_E, 1},
-       {KIND_FILTERED, 0xe8, 0x23, EV_KEY, KEY_F, 1},
-
-       /* "special" keys */
-       {KIND_FILTERED, 0xdd, 0x18, EV_KEY, KEY_KPENTER, 1},    /* "check" */
-       {KIND_FILTERED, 0xdb, 0x16, EV_KEY, KEY_MENU, 1},       /* "menu" */
-       {KIND_FILTERED, 0xc7, 0x02, EV_KEY, KEY_POWER, 1},      /* Power */
-       {KIND_FILTERED, 0xc8, 0x03, EV_KEY, KEY_TV, 1},         /* TV */
-       {KIND_FILTERED, 0xc9, 0x04, EV_KEY, KEY_DVD, 1},        /* DVD */
-       {KIND_FILTERED, 0xca, 0x05, EV_KEY, KEY_WWW, 1},        /* WEB */
-       {KIND_FILTERED, 0xcb, 0x06, EV_KEY, KEY_BOOKMARKS, 1},  /* "book" */
-       {KIND_FILTERED, 0xcc, 0x07, EV_KEY, KEY_EDIT, 1},       /* "hand" */
-       {KIND_FILTERED, 0xe1, 0x1c, EV_KEY, KEY_COFFEE, 1},     /* "timer" */
-       {KIND_FILTERED, 0xe5, 0x20, EV_KEY, KEY_FRONT, 1},      /* "max" */
-       {KIND_FILTERED, 0xe2, 0x1d, EV_KEY, KEY_LEFT, 1},       /* left */
-       {KIND_FILTERED, 0xe4, 0x1f, EV_KEY, KEY_RIGHT, 1},      /* right */
-       {KIND_FILTERED, 0xe7, 0x22, EV_KEY, KEY_DOWN, 1},       /* down */
-       {KIND_FILTERED, 0xdf, 0x1a, EV_KEY, KEY_UP, 1},         /* up */
-       {KIND_FILTERED, 0xe3, 0x1e, EV_KEY, KEY_OK, 1},         /* "OK" */
-       {KIND_FILTERED, 0xce, 0x09, EV_KEY, KEY_VOLUMEDOWN, 1}, /* VOL + */
-       {KIND_FILTERED, 0xcd, 0x08, EV_KEY, KEY_VOLUMEUP, 1},   /* VOL - */
-       {KIND_FILTERED, 0xcf, 0x0a, EV_KEY, KEY_MUTE, 1},       /* MUTE  */
-       {KIND_FILTERED, 0xd0, 0x0b, EV_KEY, KEY_CHANNELUP, 1},  /* CH + */
-       {KIND_FILTERED, 0xd1, 0x0c, EV_KEY, KEY_CHANNELDOWN, 1},/* CH - */
-       {KIND_FILTERED, 0xec, 0x27, EV_KEY, KEY_RECORD, 1},     /* ( o) red */
-       {KIND_FILTERED, 0xea, 0x25, EV_KEY, KEY_PLAY, 1},       /* ( >) */
-       {KIND_FILTERED, 0xe9, 0x24, EV_KEY, KEY_REWIND, 1},     /* (<<) */
-       {KIND_FILTERED, 0xeb, 0x26, EV_KEY, KEY_FORWARD, 1},    /* (>>) */
-       {KIND_FILTERED, 0xed, 0x28, EV_KEY, KEY_STOP, 1},       /* ([]) */
-       {KIND_FILTERED, 0xee, 0x29, EV_KEY, KEY_PAUSE, 1},      /* ('') */
-       {KIND_FILTERED, 0xf0, 0x2b, EV_KEY, KEY_PREVIOUS, 1},   /* (<-) */
-       {KIND_FILTERED, 0xef, 0x2a, EV_KEY, KEY_NEXT, 1},       /* (>+) */
-       {KIND_FILTERED, 0xf2, 0x2D, EV_KEY, KEY_INFO, 1},       /* PLAYING */
-       {KIND_FILTERED, 0xf3, 0x2E, EV_KEY, KEY_HOME, 1},       /* TOP */
-       {KIND_FILTERED, 0xf4, 0x2F, EV_KEY, KEY_END, 1},        /* END */
-       {KIND_FILTERED, 0xf5, 0x30, EV_KEY, KEY_SELECT, 1},     /* SELECT */
-
+       /* Non-mouse events are handled by rc-core */
        {KIND_END, 0x00, 0x00, EV_MAX + 1, 0, 0}
 };
 
 /* Local function prototypes */
-static int ati_remote_open             (struct input_dev *inputdev);
-static void ati_remote_close           (struct input_dev *inputdev);
 static int ati_remote_sendpacket       (struct ati_remote *ati_remote, u16 cmd, unsigned char *data);
 static void ati_remote_irq_out         (struct urb *urb);
 static void ati_remote_irq_in          (struct urb *urb);
@@ -313,9 +275,10 @@ static struct usb_driver ati_remote_driver = {
 static void ati_remote_dump(struct device *dev, unsigned char *data,
                            unsigned int len)
 {
-       if ((len == 1) && (data[0] != (unsigned char)0xff) && (data[0] != 0x00))
-               dev_warn(dev, "Weird byte 0x%02x\n", data[0]);
-       else if (len == 4)
+       if (len == 1) {
+               if (data[0] != (unsigned char)0xff && data[0] != 0x00)
+                       dev_warn(dev, "Weird byte 0x%02x\n", data[0]);
+       } else if (len == 4)
                dev_warn(dev, "Weird key %02x %02x %02x %02x\n",
                     data[0], data[1], data[2], data[3]);
        else
@@ -326,29 +289,60 @@ static void ati_remote_dump(struct device *dev, unsigned char *data,
 /*
  *     ati_remote_open
  */
-static int ati_remote_open(struct input_dev *inputdev)
+static int ati_remote_open(struct ati_remote *ati_remote)
 {
-       struct ati_remote *ati_remote = input_get_drvdata(inputdev);
+       int err = 0;
+
+       mutex_lock(&ati_remote->open_mutex);
+
+       if (ati_remote->users++ != 0)
+               goto out; /* one was already active */
 
        /* On first open, submit the read urb which was set up previously. */
        ati_remote->irq_urb->dev = ati_remote->udev;
        if (usb_submit_urb(ati_remote->irq_urb, GFP_KERNEL)) {
                dev_err(&ati_remote->interface->dev,
                        "%s: usb_submit_urb failed!\n", __func__);
-               return -EIO;
+               err = -EIO;
        }
 
-       return 0;
+out:   mutex_unlock(&ati_remote->open_mutex);
+       return err;
 }
 
 /*
  *     ati_remote_close
  */
-static void ati_remote_close(struct input_dev *inputdev)
+static void ati_remote_close(struct ati_remote *ati_remote)
+{
+       mutex_lock(&ati_remote->open_mutex);
+       if (--ati_remote->users == 0)
+               usb_kill_urb(ati_remote->irq_urb);
+       mutex_unlock(&ati_remote->open_mutex);
+}
+
+static int ati_remote_input_open(struct input_dev *inputdev)
 {
        struct ati_remote *ati_remote = input_get_drvdata(inputdev);
+       return ati_remote_open(ati_remote);
+}
 
-       usb_kill_urb(ati_remote->irq_urb);
+static void ati_remote_input_close(struct input_dev *inputdev)
+{
+       struct ati_remote *ati_remote = input_get_drvdata(inputdev);
+       ati_remote_close(ati_remote);
+}
+
+static int ati_remote_rc_open(struct rc_dev *rdev)
+{
+       struct ati_remote *ati_remote = rdev->priv;
+       return ati_remote_open(ati_remote);
+}
+
+static void ati_remote_rc_close(struct rc_dev *rdev)
+{
+       struct ati_remote *ati_remote = rdev->priv;
+       ati_remote_close(ati_remote);
 }
 
 /*
@@ -413,10 +407,8 @@ static int ati_remote_event_lookup(int rem, unsigned char d1, unsigned char d2)
                /*
                 * Decide if the table entry matches the remote input.
                 */
-               if ((((ati_remote_tbl[i].data1 & 0x0f) == (d1 & 0x0f))) &&
-                   ((((ati_remote_tbl[i].data1 >> 4) -
-                      (d1 >> 4) + rem) & 0x0f) == 0x0f) &&
-                   (ati_remote_tbl[i].data2 == d2))
+               if (ati_remote_tbl[i].data1 == d1 &&
+                   ati_remote_tbl[i].data2 == d2)
                        return i;
 
        }
@@ -468,8 +460,10 @@ static void ati_remote_input_report(struct urb *urb)
        struct ati_remote *ati_remote = urb->context;
        unsigned char *data= ati_remote->inbuf;
        struct input_dev *dev = ati_remote->idev;
-       int index, acc;
+       int index = -1;
+       int acc;
        int remote_num;
+       unsigned char scancode[2];
 
        /* Deal with strange looking inputs */
        if ( (urb->actual_length != 4) || (data[0] != 0x14) ||
@@ -481,26 +475,41 @@ static void ati_remote_input_report(struct urb *urb)
        /* Mask unwanted remote channels.  */
        /* note: remote_num is 0-based, channel 1 on remote == 0 here */
        remote_num = (data[3] >> 4) & 0x0f;
-        if (channel_mask & (1 << (remote_num + 1))) {
+       if (channel_mask & (1 << (remote_num + 1))) {
                dbginfo(&ati_remote->interface->dev,
                        "Masked input from channel 0x%02x: data %02x,%02x, mask= 0x%02lx\n",
                        remote_num, data[1], data[2], channel_mask);
                return;
        }
 
-       /* Look up event code index in translation table */
-       index = ati_remote_event_lookup(remote_num, data[1], data[2]);
-       if (index < 0) {
-               dev_warn(&ati_remote->interface->dev,
-                        "Unknown input from channel 0x%02x: data %02x,%02x\n",
-                        remote_num, data[1], data[2]);
-               return;
-       }
-       dbginfo(&ati_remote->interface->dev,
-               "channel 0x%02x; data %02x,%02x; index %d; keycode %d\n",
-               remote_num, data[1], data[2], index, ati_remote_tbl[index].code);
+       scancode[0] = (((data[1] - ((remote_num + 1) << 4)) & 0xf0) | (data[1] & 0x0f));
 
-       if (ati_remote_tbl[index].kind == KIND_LITERAL) {
+       /*
+        * Some devices (e.g. SnapStream Firefly) use 8080 as toggle code,
+        * so we have to clear them. The first bit is a bit tricky as the
+        * "non-toggled" state depends on remote_num, so we xor it with the
+        * second bit which is only used for toggle.
+        */
+       scancode[0] ^= (data[2] & 0x80);
+
+       scancode[1] = data[2] & ~0x80;
+
+       /* Look up event code index in mouse translation table. */
+       index = ati_remote_event_lookup(remote_num, scancode[0], scancode[1]);
+
+       if (index >= 0) {
+               dbginfo(&ati_remote->interface->dev,
+                       "channel 0x%02x; mouse data %02x,%02x; index %d; keycode %d\n",
+                       remote_num, data[1], data[2], index, ati_remote_tbl[index].code);
+               if (!dev)
+                       return; /* no mouse device */
+       } else
+               dbginfo(&ati_remote->interface->dev,
+                       "channel 0x%02x; key data %02x,%02x, scancode %02x,%02x\n",
+                       remote_num, data[1], data[2], scancode[0], scancode[1]);
+
+
+       if (index >= 0 && ati_remote_tbl[index].kind == KIND_LITERAL) {
                input_event(dev, ati_remote_tbl[index].type,
                        ati_remote_tbl[index].code,
                        ati_remote_tbl[index].value);
@@ -510,7 +519,7 @@ static void ati_remote_input_report(struct urb *urb)
                return;
        }
 
-       if (ati_remote_tbl[index].kind == KIND_FILTERED) {
+       if (index < 0 || ati_remote_tbl[index].kind == KIND_FILTERED) {
                unsigned long now = jiffies;
 
                /* Filter duplicate events which happen "too close" together. */
@@ -538,6 +547,20 @@ static void ati_remote_input_report(struct urb *urb)
                                      msecs_to_jiffies(repeat_delay))))
                        return;
 
+               if (index < 0) {
+                       /* Not a mouse event, hand it to rc-core. */
+                       u32 rc_code = (scancode[0] << 8) | scancode[1];
+
+                       /*
+                        * We don't use the rc-core repeat handling yet as
+                        * it would cause ghost repeats which would be a
+                        * regression for this driver.
+                        */
+                       rc_keydown_notimeout(ati_remote->rdev, rc_code,
+                                            data[2]);
+                       rc_keyup(ati_remote->rdev);
+                       return;
+               }
 
                input_event(dev, ati_remote_tbl[index].type,
                        ati_remote_tbl[index].code, 1);
@@ -630,7 +653,7 @@ static int ati_remote_alloc_buffers(struct usb_device *udev,
                return -1;
 
        ati_remote->outbuf = usb_alloc_coherent(udev, DATA_BUFSIZE, GFP_ATOMIC,
-                                               &ati_remote->outbuf_dma);
+                                               &ati_remote->outbuf_dma);
        if (!ati_remote->outbuf)
                return -1;
 
@@ -675,14 +698,33 @@ static void ati_remote_input_init(struct ati_remote *ati_remote)
 
        input_set_drvdata(idev, ati_remote);
 
-       idev->open = ati_remote_open;
-       idev->close = ati_remote_close;
+       idev->open = ati_remote_input_open;
+       idev->close = ati_remote_input_close;
 
-       idev->name = ati_remote->name;
-       idev->phys = ati_remote->phys;
+       idev->name = ati_remote->mouse_name;
+       idev->phys = ati_remote->mouse_phys;
 
        usb_to_input_id(ati_remote->udev, &idev->id);
-       idev->dev.parent = &ati_remote->udev->dev;
+       idev->dev.parent = &ati_remote->interface->dev;
+}
+
+static void ati_remote_rc_init(struct ati_remote *ati_remote)
+{
+       struct rc_dev *rdev = ati_remote->rdev;
+
+       rdev->priv = ati_remote;
+       rdev->driver_type = RC_DRIVER_SCANCODE;
+       rdev->allowed_protos = RC_TYPE_OTHER;
+       rdev->driver_name = "ati_remote";
+
+       rdev->open = ati_remote_rc_open;
+       rdev->close = ati_remote_rc_close;
+
+       rdev->input_name = ati_remote->rc_name;
+       rdev->input_phys = ati_remote->rc_phys;
+
+       usb_to_input_id(ati_remote->udev, &rdev->input_id);
+       rdev->dev.parent = &ati_remote->interface->dev;
 }
 
 static int ati_remote_initialize(struct ati_remote *ati_remote)
@@ -735,6 +777,7 @@ static int ati_remote_probe(struct usb_interface *interface, const struct usb_de
        struct usb_endpoint_descriptor *endpoint_in, *endpoint_out;
        struct ati_remote *ati_remote;
        struct input_dev *input_dev;
+       struct rc_dev *rc_dev;
        int err = -ENOMEM;
 
        if (iface_host->desc.bNumEndpoints != 2) {
@@ -755,8 +798,8 @@ static int ati_remote_probe(struct usb_interface *interface, const struct usb_de
        }
 
        ati_remote = kzalloc(sizeof (struct ati_remote), GFP_KERNEL);
-       input_dev = input_allocate_device();
-       if (!ati_remote || !input_dev)
+       rc_dev = rc_allocate_device();
+       if (!ati_remote || !rc_dev)
                goto fail1;
 
        /* Allocate URB buffers, URBs */
@@ -766,44 +809,78 @@ static int ati_remote_probe(struct usb_interface *interface, const struct usb_de
        ati_remote->endpoint_in = endpoint_in;
        ati_remote->endpoint_out = endpoint_out;
        ati_remote->udev = udev;
-       ati_remote->idev = input_dev;
+       ati_remote->rdev = rc_dev;
        ati_remote->interface = interface;
 
-       usb_make_path(udev, ati_remote->phys, sizeof(ati_remote->phys));
-       strlcat(ati_remote->phys, "/input0", sizeof(ati_remote->phys));
+       usb_make_path(udev, ati_remote->rc_phys, sizeof(ati_remote->rc_phys));
+       strlcpy(ati_remote->mouse_phys, ati_remote->rc_phys,
+               sizeof(ati_remote->mouse_phys));
+
+       strlcat(ati_remote->rc_phys, "/input0", sizeof(ati_remote->rc_phys));
+       strlcat(ati_remote->mouse_phys, "/input1", sizeof(ati_remote->mouse_phys));
 
        if (udev->manufacturer)
-               strlcpy(ati_remote->name, udev->manufacturer, sizeof(ati_remote->name));
+               strlcpy(ati_remote->rc_name, udev->manufacturer,
+                       sizeof(ati_remote->rc_name));
 
        if (udev->product)
-               snprintf(ati_remote->name, sizeof(ati_remote->name),
-                        "%s %s", ati_remote->name, udev->product);
+               snprintf(ati_remote->rc_name, sizeof(ati_remote->rc_name),
+                        "%s %s", ati_remote->rc_name, udev->product);
 
-       if (!strlen(ati_remote->name))
-               snprintf(ati_remote->name, sizeof(ati_remote->name),
+       if (!strlen(ati_remote->rc_name))
+               snprintf(ati_remote->rc_name, sizeof(ati_remote->rc_name),
                        DRIVER_DESC "(%04x,%04x)",
                        le16_to_cpu(ati_remote->udev->descriptor.idVendor),
                        le16_to_cpu(ati_remote->udev->descriptor.idProduct));
 
-       ati_remote_input_init(ati_remote);
+       snprintf(ati_remote->mouse_name, sizeof(ati_remote->mouse_name),
+                "%s mouse", ati_remote->rc_name);
+
+       if (id->driver_info)
+               rc_dev->map_name = (const char *)id->driver_info;
+       else
+               rc_dev->map_name = RC_MAP_ATI_X10;
+
+       ati_remote_rc_init(ati_remote);
+       mutex_init(&ati_remote->open_mutex);
 
        /* Device Hardware Initialization - fills in ati_remote->idev from udev. */
        err = ati_remote_initialize(ati_remote);
        if (err)
                goto fail3;
 
-       /* Set up and register input device */
-       err = input_register_device(ati_remote->idev);
+       /* Set up and register rc device */
+       err = rc_register_device(ati_remote->rdev);
        if (err)
                goto fail3;
 
+       /* use our delay for rc_dev */
+       ati_remote->rdev->input_dev->rep[REP_DELAY] = repeat_delay;
+
+       /* Set up and register mouse input device */
+       if (mouse) {
+               input_dev = input_allocate_device();
+               if (!input_dev)
+                       goto fail4;
+
+               ati_remote->idev = input_dev;
+               ati_remote_input_init(ati_remote);
+               err = input_register_device(input_dev);
+
+               if (err)
+                       goto fail5;
+       }
+
        usb_set_intfdata(interface, ati_remote);
        return 0;
 
+ fail5:        input_free_device(input_dev);
+ fail4:        rc_unregister_device(rc_dev);
+       rc_dev = NULL;
  fail3:        usb_kill_urb(ati_remote->irq_urb);
        usb_kill_urb(ati_remote->out_urb);
  fail2:        ati_remote_free_buffers(ati_remote);
- fail1:        input_free_device(input_dev);
+ fail1:        rc_free_device(rc_dev);
        kfree(ati_remote);
        return err;
 }
@@ -824,7 +901,9 @@ static void ati_remote_disconnect(struct usb_interface *interface)
 
        usb_kill_urb(ati_remote->irq_urb);
        usb_kill_urb(ati_remote->out_urb);
-       input_unregister_device(ati_remote->idev);
+       if (ati_remote->idev)
+               input_unregister_device(ati_remote->idev);
+       rc_unregister_device(ati_remote->rdev);
        ati_remote_free_buffers(ati_remote);
        kfree(ati_remote);
 }
index 2b9c2569d74a2163888769e41045e97a7a5fc642..cf10ecf5acecab604a8b81de83748d64acd05104 100644 (file)
@@ -30,6 +30,8 @@
  *
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/pnp.h>
@@ -118,31 +120,31 @@ static int ene_hw_detect(struct ene_device *dev)
                        dev->pll_freq == ENE_DEFAULT_PLL_FREQ ? 2 : 4;
 
        if (hw_revision == 0xFF) {
-               ene_warn("device seems to be disabled");
-               ene_warn("send a mail to lirc-list@lists.sourceforge.net");
-               ene_warn("please attach output of acpidump and dmidecode");
+               pr_warn("device seems to be disabled\n");
+               pr_warn("send a mail to lirc-list@lists.sourceforge.net\n");
+               pr_warn("please attach output of acpidump and dmidecode\n");
                return -ENODEV;
        }
 
-       ene_notice("chip is 0x%02x%02x - kbver = 0x%02x, rev = 0x%02x",
-               chip_major, chip_minor, old_ver, hw_revision);
+       pr_notice("chip is 0x%02x%02x - kbver = 0x%02x, rev = 0x%02x\n",
+                 chip_major, chip_minor, old_ver, hw_revision);
 
-       ene_notice("PLL freq = %d", dev->pll_freq);
+       pr_notice("PLL freq = %d\n", dev->pll_freq);
 
        if (chip_major == 0x33) {
-               ene_warn("chips 0x33xx aren't supported");
+               pr_warn("chips 0x33xx aren't supported\n");
                return -ENODEV;
        }
 
        if (chip_major == 0x39 && chip_minor == 0x26 && hw_revision == 0xC0) {
                dev->hw_revision = ENE_HW_C;
-               ene_notice("KB3926C detected");
+               pr_notice("KB3926C detected\n");
        } else if (old_ver == 0x24 && hw_revision == 0xC0) {
                dev->hw_revision = ENE_HW_B;
-               ene_notice("KB3926B detected");
+               pr_notice("KB3926B detected\n");
        } else {
                dev->hw_revision = ENE_HW_D;
-               ene_notice("KB3926D or higher detected");
+               pr_notice("KB3926D or higher detected\n");
        }
 
        /* detect features hardware supports */
@@ -152,7 +154,7 @@ static int ene_hw_detect(struct ene_device *dev)
        fw_reg1 = ene_read_reg(dev, ENE_FW1);
        fw_reg2 = ene_read_reg(dev, ENE_FW2);
 
-       ene_notice("Firmware regs: %02x %02x", fw_reg1, fw_reg2);
+       pr_notice("Firmware regs: %02x %02x\n", fw_reg1, fw_reg2);
 
        dev->hw_use_gpio_0a = !!(fw_reg2 & ENE_FW2_GP0A);
        dev->hw_learning_and_tx_capable = !!(fw_reg2 & ENE_FW2_LEARNING);
@@ -161,30 +163,29 @@ static int ene_hw_detect(struct ene_device *dev)
        if (dev->hw_learning_and_tx_capable)
                dev->hw_fan_input = !!(fw_reg2 & ENE_FW2_FAN_INPUT);
 
-       ene_notice("Hardware features:");
+       pr_notice("Hardware features:\n");
 
        if (dev->hw_learning_and_tx_capable) {
-               ene_notice("* Supports transmitting & learning mode");
-               ene_notice("   This feature is rare and therefore,");
-               ene_notice("   you are welcome to test it,");
-               ene_notice("   and/or contact the author via:");
-               ene_notice("   lirc-list@lists.sourceforge.net");
-               ene_notice("   or maximlevitsky@gmail.com");
+               pr_notice("* Supports transmitting & learning mode\n");
+               pr_notice("   This feature is rare and therefore,\n");
+               pr_notice("   you are welcome to test it,\n");
+               pr_notice("   and/or contact the author via:\n");
+               pr_notice("   lirc-list@lists.sourceforge.net\n");
+               pr_notice("   or maximlevitsky@gmail.com\n");
 
-               ene_notice("* Uses GPIO %s for IR raw input",
-                       dev->hw_use_gpio_0a ? "40" : "0A");
+               pr_notice("* Uses GPIO %s for IR raw input\n",
+                         dev->hw_use_gpio_0a ? "40" : "0A");
 
                if (dev->hw_fan_input)
-                       ene_notice("* Uses unused fan feedback input as source"
-                                       " of demodulated IR data");
+                       pr_notice("* Uses unused fan feedback input as source of demodulated IR data\n");
        }
 
        if (!dev->hw_fan_input)
-               ene_notice("* Uses GPIO %s for IR demodulated input",
-                       dev->hw_use_gpio_0a ? "0A" : "40");
+               pr_notice("* Uses GPIO %s for IR demodulated input\n",
+                         dev->hw_use_gpio_0a ? "0A" : "40");
 
        if (dev->hw_extra_buffer)
-               ene_notice("* Uses new style input buffer");
+               pr_notice("* Uses new style input buffer\n");
        return 0;
 }
 
@@ -215,13 +216,13 @@ static void ene_rx_setup_hw_buffer(struct ene_device *dev)
 
        dev->buffer_len = dev->extra_buf1_len + dev->extra_buf2_len + 8;
 
-       ene_notice("Hardware uses 2 extended buffers:");
-       ene_notice("  0x%04x - len : %d", dev->extra_buf1_address,
-                                               dev->extra_buf1_len);
-       ene_notice("  0x%04x - len : %d", dev->extra_buf2_address,
-                                               dev->extra_buf2_len);
+       pr_notice("Hardware uses 2 extended buffers:\n");
+       pr_notice("  0x%04x - len : %d\n",
+                 dev->extra_buf1_address, dev->extra_buf1_len);
+       pr_notice("  0x%04x - len : %d\n",
+                 dev->extra_buf2_address, dev->extra_buf2_len);
 
-       ene_notice("Total buffer len = %d", dev->buffer_len);
+       pr_notice("Total buffer len = %d\n", dev->buffer_len);
 
        if (dev->buffer_len > 64 || dev->buffer_len < 16)
                goto error;
@@ -240,7 +241,7 @@ static void ene_rx_setup_hw_buffer(struct ene_device *dev)
        ene_set_reg_mask(dev, ENE_FW1, ENE_FW1_EXTRA_BUF_HND);
        return;
 error:
-       ene_warn("Error validating extra buffers, device probably won't work");
+       pr_warn("Error validating extra buffers, device probably won't work\n");
        dev->hw_extra_buffer = false;
        ene_clear_reg_mask(dev, ENE_FW1, ENE_FW1_EXTRA_BUF_HND);
 }
@@ -588,7 +589,7 @@ static void ene_tx_enable(struct ene_device *dev)
                dbg("TX: Transmitter #2 is connected");
 
        if (!(fwreg2 & (ENE_FW2_EMMITER1_CONN | ENE_FW2_EMMITER2_CONN)))
-               ene_warn("TX: transmitter cable isn't connected!");
+               pr_warn("TX: transmitter cable isn't connected!\n");
 
        /* disable receive on revc */
        if (dev->hw_revision == ENE_HW_C)
@@ -615,7 +616,7 @@ static void ene_tx_sample(struct ene_device *dev)
        bool pulse = dev->tx_sample_pulse;
 
        if (!dev->tx_buffer) {
-               ene_warn("TX: BUG: attempt to transmit NULL buffer");
+               pr_warn("TX: BUG: attempt to transmit NULL buffer\n");
                return;
        }
 
@@ -1049,7 +1050,7 @@ static int ene_probe(struct pnp_dev *pnp_dev, const struct pnp_device_id *id)
                dev->hw_learning_and_tx_capable = true;
                setup_timer(&dev->tx_sim_timer, ene_tx_irqsim,
                                                (long unsigned int)dev);
-               ene_warn("Simulation of TX activated");
+               pr_warn("Simulation of TX activated\n");
        }
 
        if (!dev->hw_learning_and_tx_capable)
@@ -1089,7 +1090,7 @@ static int ene_probe(struct pnp_dev *pnp_dev, const struct pnp_device_id *id)
        if (error < 0)
                goto error;
 
-       ene_notice("driver has been successfully loaded");
+       pr_notice("driver has been successfully loaded\n");
        return 0;
 error:
        if (dev && dev->irq >= 0)
index 017c209cdf8a2ac51ae7365908102e8dc4e8a10d..fd108d90f7500b726cee6edb6fd8bb0fdce310f6 100644 (file)
 #define  ENE_HW_C              2       /* 3926C */
 #define  ENE_HW_D              3       /* 3926D or later */
 
-#define ene_printk(level, text, ...) \
-       printk(level ENE_DRIVER_NAME ": " text "\n", ## __VA_ARGS__)
-
-#define ene_notice(text, ...) ene_printk(KERN_NOTICE, text, ## __VA_ARGS__)
-#define ene_warn(text, ...) ene_printk(KERN_WARNING, text, ## __VA_ARGS__)
-
-
-#define __dbg(level, format, ...) \
-       do { \
-               if (debug >= level) \
-                       printk(KERN_DEBUG ENE_DRIVER_NAME \
-                               ": " format "\n", ## __VA_ARGS__); \
-       } while (0)
-
+#define __dbg(level, format, ...)                              \
+do {                                                           \
+       if (debug >= level)                                     \
+               pr_debug(format "\n", ## __VA_ARGS__);          \
+} while (0)
 
 #define dbg(format, ...)               __dbg(1, format, ## __VA_ARGS__)
 #define dbg_verbose(format, ...)       __dbg(2, format, ## __VA_ARGS__)
index 6bc35eeb653bf0cbc3ff8a82766481e862d9b198..6ed96465137a024316f48e1b4c7fc7becc9c6ac4 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/uaccess.h>
+#include <linux/ratelimit.h>
 
 #include <linux/input.h>
 #include <linux/usb.h>
@@ -516,19 +517,19 @@ static int send_packet(struct imon_context *ictx)
        if (retval) {
                ictx->tx.busy = false;
                smp_rmb(); /* ensure later readers know we're not busy */
-               pr_err("error submitting urb(%d)\n", retval);
+               pr_err_ratelimited("error submitting urb(%d)\n", retval);
        } else {
                /* Wait for transmission to complete (or abort) */
                mutex_unlock(&ictx->lock);
                retval = wait_for_completion_interruptible(
                                &ictx->tx.finished);
                if (retval)
-                       pr_err("task interrupted\n");
+                       pr_err_ratelimited("task interrupted\n");
                mutex_lock(&ictx->lock);
 
                retval = ictx->tx.status;
                if (retval)
-                       pr_err("packet tx failed (%d)\n", retval);
+                       pr_err_ratelimited("packet tx failed (%d)\n", retval);
        }
 
        kfree(control_req);
@@ -830,20 +831,20 @@ static ssize_t vfd_write(struct file *file, const char *buf,
 
        ictx = file->private_data;
        if (!ictx) {
-               pr_err("no context for device\n");
+               pr_err_ratelimited("no context for device\n");
                return -ENODEV;
        }
 
        mutex_lock(&ictx->lock);
 
        if (!ictx->dev_present_intf0) {
-               pr_err("no iMON device present\n");
+               pr_err_ratelimited("no iMON device present\n");
                retval = -ENODEV;
                goto exit;
        }
 
        if (n_bytes <= 0 || n_bytes > 32) {
-               pr_err("invalid payload size\n");
+               pr_err_ratelimited("invalid payload size\n");
                retval = -EINVAL;
                goto exit;
        }
@@ -869,7 +870,7 @@ static ssize_t vfd_write(struct file *file, const char *buf,
 
                retval = send_packet(ictx);
                if (retval) {
-                       pr_err("send packet failed for packet #%d\n", seq / 2);
+                       pr_err_ratelimited("send packet #%d failed\n", seq / 2);
                        goto exit;
                } else {
                        seq += 2;
@@ -883,7 +884,7 @@ static ssize_t vfd_write(struct file *file, const char *buf,
        ictx->usb_tx_buf[7] = (unsigned char) seq;
        retval = send_packet(ictx);
        if (retval)
-               pr_err("send packet failed for packet #%d\n", seq / 2);
+               pr_err_ratelimited("send packet #%d failed\n", seq / 2);
 
 exit:
        mutex_unlock(&ictx->lock);
@@ -912,20 +913,21 @@ static ssize_t lcd_write(struct file *file, const char *buf,
 
        ictx = file->private_data;
        if (!ictx) {
-               pr_err("no context for device\n");
+               pr_err_ratelimited("no context for device\n");
                return -ENODEV;
        }
 
        mutex_lock(&ictx->lock);
 
        if (!ictx->display_supported) {
-               pr_err("no iMON display present\n");
+               pr_err_ratelimited("no iMON display present\n");
                retval = -ENODEV;
                goto exit;
        }
 
        if (n_bytes != 8) {
-               pr_err("invalid payload size: %d (expected 8)\n", (int)n_bytes);
+               pr_err_ratelimited("invalid payload size: %d (expected 8)\n",
+                                  (int)n_bytes);
                retval = -EINVAL;
                goto exit;
        }
@@ -937,7 +939,7 @@ static ssize_t lcd_write(struct file *file, const char *buf,
 
        retval = send_packet(ictx);
        if (retval) {
-               pr_err("send packet failed!\n");
+               pr_err_ratelimited("send packet failed!\n");
                goto exit;
        } else {
                dev_dbg(ictx->dev, "%s: write %d bytes to LCD\n",
@@ -1656,7 +1658,7 @@ static void usb_rx_callback_intf0(struct urb *urb)
                return;
 
        ictx = (struct imon_context *)urb->context;
-       if (!ictx)
+       if (!ictx || !ictx->dev_present_intf0)
                return;
 
        switch (urb->status) {
@@ -1688,7 +1690,7 @@ static void usb_rx_callback_intf1(struct urb *urb)
                return;
 
        ictx = (struct imon_context *)urb->context;
-       if (!ictx)
+       if (!ictx || !ictx->dev_present_intf1)
                return;
 
        switch (urb->status) {
@@ -2116,7 +2118,6 @@ static struct imon_context *imon_init_intf0(struct usb_interface *intf)
 
        ictx->dev = dev;
        ictx->usbdev_intf0 = usb_get_dev(interface_to_usbdev(intf));
-       ictx->dev_present_intf0 = true;
        ictx->rx_urb_intf0 = rx_urb;
        ictx->tx_urb = tx_urb;
        ictx->rf_device = false;
@@ -2155,6 +2156,8 @@ static struct imon_context *imon_init_intf0(struct usb_interface *intf)
                goto rdev_setup_failed;
        }
 
+       ictx->dev_present_intf0 = true;
+
        mutex_unlock(&ictx->lock);
        return ictx;
 
@@ -2198,7 +2201,6 @@ static struct imon_context *imon_init_intf1(struct usb_interface *intf,
        }
 
        ictx->usbdev_intf1 = usb_get_dev(interface_to_usbdev(intf));
-       ictx->dev_present_intf1 = true;
        ictx->rx_urb_intf1 = rx_urb;
 
        ret = -ENODEV;
@@ -2227,6 +2229,8 @@ static struct imon_context *imon_init_intf1(struct usb_interface *intf,
                goto urb_submit_failed;
        }
 
+       ictx->dev_present_intf1 = true;
+
        mutex_unlock(&ictx->lock);
        return ictx;
 
index e5eeec4da76ea776972cc202ac4367605dd999bb..ec2e67fd236b5f8f4e22be5db3061551b0e443a3 100644 (file)
@@ -98,7 +98,7 @@ static int ir_lirc_decode(struct rc_dev *dev, struct ir_raw_event ev)
        return 0;
 }
 
-static ssize_t ir_lirc_transmit_ir(struct file *file, const char *buf,
+static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf,
                                   size_t n, loff_t *ppos)
 {
        struct lirc_codec *lirc;
@@ -140,10 +140,11 @@ out:
 }
 
 static long ir_lirc_ioctl(struct file *filep, unsigned int cmd,
-                       unsigned long __user arg)
+                       unsigned long arg)
 {
        struct lirc_codec *lirc;
        struct rc_dev *dev;
+       u32 __user *argp = (u32 __user *)(arg);
        int ret = 0;
        __u32 val = 0, tmp;
 
@@ -156,7 +157,7 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd,
                return -EFAULT;
 
        if (_IOC_DIR(cmd) & _IOC_WRITE) {
-               ret = get_user(val, (__u32 *)arg);
+               ret = get_user(val, argp);
                if (ret)
                        return ret;
        }
@@ -265,7 +266,7 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd,
        }
 
        if (_IOC_DIR(cmd) & _IOC_READ)
-               ret = put_user(val, (__u32 *)arg);
+               ret = put_user(val, argp);
 
        return ret;
 }
index b57fc83fb4d288e1ea53d9a7556d1329b0d9ccba..36e4d5e8dd6aebde7ad9708ea808e67d5e49852c 100644 (file)
@@ -4,6 +4,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \
                        rc-apac-viewcomp.o \
                        rc-asus-pc39.o \
                        rc-ati-tv-wonder-hd-600.o \
+                       rc-ati-x10.o \
                        rc-avermedia-a16d.o \
                        rc-avermedia.o \
                        rc-avermedia-cardbus.o \
@@ -47,6 +48,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \
                        rc-lirc.o \
                        rc-lme2510.o \
                        rc-manli.o \
+                       rc-medion-x10.o \
                        rc-msi-digivox-ii.o \
                        rc-msi-digivox-iii.o \
                        rc-msi-tvanywhere.o \
@@ -70,6 +72,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \
                        rc-hauppauge.o \
                        rc-rc6-mce.o \
                        rc-real-audio-220-32-keys.o \
+                       rc-snapstream-firefly.o \
                        rc-streamzap.o \
                        rc-tbs-nec.o \
                        rc-technisat-usb2.o \
diff --git a/drivers/media/rc/keymaps/rc-ati-x10.c b/drivers/media/rc/keymaps/rc-ati-x10.c
new file mode 100644 (file)
index 0000000..e1b8b26
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * ATI X10 RF remote keytable
+ *
+ * Copyright (C) 2011 Anssi Hannula <anssi.hannula@?ki.fi>
+ *
+ * This file is based on the static generic keytable previously found in
+ * ati_remote.c, which is
+ * Copyright (c) 2004 Torrey Hoffman <thoffman@arnor.net>
+ * Copyright (c) 2002 Vladimir Dergachev
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <linux/module.h>
+#include <media/rc-map.h>
+
+static struct rc_map_table ati_x10[] = {
+       { 0xd20d, KEY_1 },
+       { 0xd30e, KEY_2 },
+       { 0xd40f, KEY_3 },
+       { 0xd510, KEY_4 },
+       { 0xd611, KEY_5 },
+       { 0xd712, KEY_6 },
+       { 0xd813, KEY_7 },
+       { 0xd914, KEY_8 },
+       { 0xda15, KEY_9 },
+       { 0xdc17, KEY_0 },
+       { 0xc500, KEY_A },
+       { 0xc601, KEY_B },
+       { 0xde19, KEY_C },
+       { 0xe01b, KEY_D },
+       { 0xe621, KEY_E },
+       { 0xe823, KEY_F },
+
+       { 0xdd18, KEY_KPENTER },    /* "check" */
+       { 0xdb16, KEY_MENU },       /* "menu" */
+       { 0xc702, KEY_POWER },      /* Power */
+       { 0xc803, KEY_TV },         /* TV */
+       { 0xc904, KEY_DVD },        /* DVD */
+       { 0xca05, KEY_WWW },        /* WEB */
+       { 0xcb06, KEY_BOOKMARKS },  /* "book" */
+       { 0xcc07, KEY_EDIT },       /* "hand" */
+       { 0xe11c, KEY_COFFEE },     /* "timer" */
+       { 0xe520, KEY_FRONT },      /* "max" */
+       { 0xe21d, KEY_LEFT },       /* left */
+       { 0xe41f, KEY_RIGHT },      /* right */
+       { 0xe722, KEY_DOWN },       /* down */
+       { 0xdf1a, KEY_UP },         /* up */
+       { 0xe31e, KEY_OK },         /* "OK" */
+       { 0xce09, KEY_VOLUMEDOWN }, /* VOL + */
+       { 0xcd08, KEY_VOLUMEUP },   /* VOL - */
+       { 0xcf0a, KEY_MUTE },       /* MUTE  */
+       { 0xd00b, KEY_CHANNELUP },  /* CH + */
+       { 0xd10c, KEY_CHANNELDOWN },/* CH - */
+       { 0xec27, KEY_RECORD },     /* ( o) red */
+       { 0xea25, KEY_PLAY },       /* ( >) */
+       { 0xe924, KEY_REWIND },     /* (<<) */
+       { 0xeb26, KEY_FORWARD },    /* (>>) */
+       { 0xed28, KEY_STOP },       /* ([]) */
+       { 0xee29, KEY_PAUSE },      /* ('') */
+       { 0xf02b, KEY_PREVIOUS },   /* (<-) */
+       { 0xef2a, KEY_NEXT },       /* (>+) */
+       { 0xf22d, KEY_INFO },       /* PLAYING */
+       { 0xf32e, KEY_HOME },       /* TOP */
+       { 0xf42f, KEY_END },        /* END */
+       { 0xf530, KEY_SELECT },     /* SELECT */
+};
+
+static struct rc_map_list ati_x10_map = {
+       .map = {
+               .scan    = ati_x10,
+               .size    = ARRAY_SIZE(ati_x10),
+               .rc_type = RC_TYPE_OTHER,
+               .name    = RC_MAP_ATI_X10,
+       }
+};
+
+static int __init init_rc_map_ati_x10(void)
+{
+       return rc_map_register(&ati_x10_map);
+}
+
+static void __exit exit_rc_map_ati_x10(void)
+{
+       rc_map_unregister(&ati_x10_map);
+}
+
+module_init(init_rc_map_ati_x10)
+module_exit(exit_rc_map_ati_x10)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Anssi Hannula <anssi.hannula@iki.fi>");
diff --git a/drivers/media/rc/keymaps/rc-medion-x10.c b/drivers/media/rc/keymaps/rc-medion-x10.c
new file mode 100644 (file)
index 0000000..09e2cc0
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+ * Medion X10 RF remote keytable
+ *
+ * Copyright (C) 2011 Anssi Hannula <anssi.hannula@?ki.fi>
+ *
+ * This file is based on a keytable provided by
+ * Jan Losinski <losinski@wh2.tu-dresden.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <linux/module.h>
+#include <media/rc-map.h>
+
+static struct rc_map_table medion_x10[] = {
+       { 0xf12c, KEY_TV },    /* TV */
+       { 0xf22d, KEY_VCR },   /* VCR */
+       { 0xc904, KEY_DVD },   /* DVD */
+       { 0xcb06, KEY_AUDIO }, /* MUSIC */
+
+       { 0xf32e, KEY_RADIO },     /* RADIO */
+       { 0xca05, KEY_DIRECTORY }, /* PHOTO */
+       { 0xf42f, KEY_INFO },      /* TV-PREVIEW */
+       { 0xf530, KEY_LIST },      /* CHANNEL-LST */
+
+       { 0xe01b, KEY_SETUP }, /* SETUP */
+       { 0xf631, KEY_VIDEO }, /* VIDEO DESKTOP */
+
+       { 0xcd08, KEY_VOLUMEDOWN },  /* VOL - */
+       { 0xce09, KEY_VOLUMEUP },    /* VOL + */
+       { 0xd00b, KEY_CHANNELUP },   /* CHAN + */
+       { 0xd10c, KEY_CHANNELDOWN }, /* CHAN - */
+       { 0xc500, KEY_MUTE },        /* MUTE */
+
+       { 0xf732, KEY_RED }, /* red */
+       { 0xf833, KEY_GREEN }, /* green */
+       { 0xf934, KEY_YELLOW }, /* yellow */
+       { 0xfa35, KEY_BLUE }, /* blue */
+       { 0xdb16, KEY_TEXT }, /* TXT */
+
+       { 0xd20d, KEY_1 },
+       { 0xd30e, KEY_2 },
+       { 0xd40f, KEY_3 },
+       { 0xd510, KEY_4 },
+       { 0xd611, KEY_5 },
+       { 0xd712, KEY_6 },
+       { 0xd813, KEY_7 },
+       { 0xd914, KEY_8 },
+       { 0xda15, KEY_9 },
+       { 0xdc17, KEY_0 },
+       { 0xe11c, KEY_SEARCH }, /* TV/RAD, CH SRC */
+       { 0xe520, KEY_DELETE }, /* DELETE */
+
+       { 0xfb36, KEY_KEYBOARD }, /* RENAME */
+       { 0xdd18, KEY_SCREEN },   /* SNAPSHOT */
+
+       { 0xdf1a, KEY_UP },    /* up */
+       { 0xe722, KEY_DOWN },  /* down */
+       { 0xe21d, KEY_LEFT },  /* left */
+       { 0xe41f, KEY_RIGHT }, /* right */
+       { 0xe31e, KEY_OK },    /* OK */
+
+       { 0xfc37, KEY_SELECT }, /* ACQUIRE IMAGE */
+       { 0xfd38, KEY_EDIT },   /* EDIT IMAGE */
+
+       { 0xe924, KEY_REWIND },   /* rewind  (<<) */
+       { 0xea25, KEY_PLAY },     /* play    ( >) */
+       { 0xeb26, KEY_FORWARD },  /* forward (>>) */
+       { 0xec27, KEY_RECORD },   /* record  ( o) */
+       { 0xed28, KEY_STOP },     /* stop    ([]) */
+       { 0xee29, KEY_PAUSE },    /* pause   ('') */
+
+       { 0xe621, KEY_PREVIOUS },        /* prev */
+       { 0xfe39, KEY_SWITCHVIDEOMODE }, /* F SCR */
+       { 0xe823, KEY_NEXT },            /* next */
+       { 0xde19, KEY_MENU },            /* MENU */
+       { 0xff3a, KEY_LANGUAGE },        /* AUDIO */
+
+       { 0xc702, KEY_POWER }, /* POWER */
+};
+
+static struct rc_map_list medion_x10_map = {
+       .map = {
+               .scan    = medion_x10,
+               .size    = ARRAY_SIZE(medion_x10),
+               .rc_type = RC_TYPE_OTHER,
+               .name    = RC_MAP_MEDION_X10,
+       }
+};
+
+static int __init init_rc_map_medion_x10(void)
+{
+       return rc_map_register(&medion_x10_map);
+}
+
+static void __exit exit_rc_map_medion_x10(void)
+{
+       rc_map_unregister(&medion_x10_map);
+}
+
+module_init(init_rc_map_medion_x10)
+module_exit(exit_rc_map_medion_x10)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Anssi Hannula <anssi.hannula@iki.fi>");
index 8d558ae63456488da72ba9982c7aae6739a3dd48..31fc64cd17ba94da435e16561ab8159525a9e4fe 100644 (file)
@@ -20,6 +20,7 @@ static struct rc_map_table pinnacle_pctv_hd[] = {
        { 0x0701, KEY_MENU }, /* Pinnacle logo */
        { 0x0739, KEY_POWER },
        { 0x0703, KEY_VOLUMEUP },
+       { 0x0705, KEY_OK },
        { 0x0709, KEY_VOLUMEDOWN },
        { 0x0706, KEY_CHANNELUP },
        { 0x070c, KEY_CHANNELDOWN },
diff --git a/drivers/media/rc/keymaps/rc-snapstream-firefly.c b/drivers/media/rc/keymaps/rc-snapstream-firefly.c
new file mode 100644 (file)
index 0000000..ef14652
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * SnapStream Firefly X10 RF remote keytable
+ *
+ * Copyright (C) 2011 Anssi Hannula <anssi.hannula@?ki.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <linux/module.h>
+#include <media/rc-map.h>
+
+static struct rc_map_table snapstream_firefly[] = {
+       { 0xf12c, KEY_ZOOM },       /* Maximize */
+       { 0xc702, KEY_CLOSE },
+
+       { 0xd20d, KEY_1 },
+       { 0xd30e, KEY_2 },
+       { 0xd40f, KEY_3 },
+       { 0xd510, KEY_4 },
+       { 0xd611, KEY_5 },
+       { 0xd712, KEY_6 },
+       { 0xd813, KEY_7 },
+       { 0xd914, KEY_8 },
+       { 0xda15, KEY_9 },
+       { 0xdc17, KEY_0 },
+       { 0xdb16, KEY_BACK },
+       { 0xdd18, KEY_KPENTER },    /* ent */
+
+       { 0xce09, KEY_VOLUMEUP },
+       { 0xcd08, KEY_VOLUMEDOWN },
+       { 0xcf0a, KEY_MUTE },
+       { 0xd00b, KEY_CHANNELUP },
+       { 0xd10c, KEY_CHANNELDOWN },
+       { 0xc500, KEY_VENDOR },     /* firefly */
+
+       { 0xf32e, KEY_INFO },
+       { 0xf42f, KEY_OPTION },
+
+       { 0xe21d, KEY_LEFT },
+       { 0xe41f, KEY_RIGHT },
+       { 0xe722, KEY_DOWN },
+       { 0xdf1a, KEY_UP },
+       { 0xe31e, KEY_OK },
+
+       { 0xe11c, KEY_MENU },
+       { 0xe520, KEY_EXIT },
+
+       { 0xec27, KEY_RECORD },
+       { 0xea25, KEY_PLAY },
+       { 0xed28, KEY_STOP },
+       { 0xe924, KEY_REWIND },
+       { 0xeb26, KEY_FORWARD },
+       { 0xee29, KEY_PAUSE },
+       { 0xf02b, KEY_PREVIOUS },
+       { 0xef2a, KEY_NEXT },
+
+       { 0xcb06, KEY_AUDIO },      /* Music */
+       { 0xca05, KEY_IMAGES },     /* Photos */
+       { 0xc904, KEY_DVD },
+       { 0xc803, KEY_TV },
+       { 0xcc07, KEY_VIDEO },
+
+       { 0xc601, KEY_HELP },
+       { 0xf22d, KEY_MODE },       /* Mouse */
+
+       { 0xde19, KEY_A },
+       { 0xe01b, KEY_B },
+       { 0xe621, KEY_C },
+       { 0xe823, KEY_D },
+};
+
+static struct rc_map_list snapstream_firefly_map = {
+       .map = {
+               .scan    = snapstream_firefly,
+               .size    = ARRAY_SIZE(snapstream_firefly),
+               .rc_type = RC_TYPE_OTHER,
+               .name    = RC_MAP_SNAPSTREAM_FIREFLY,
+       }
+};
+
+static int __init init_rc_map_snapstream_firefly(void)
+{
+       return rc_map_register(&snapstream_firefly_map);
+}
+
+static void __exit exit_rc_map_snapstream_firefly(void)
+{
+       rc_map_unregister(&snapstream_firefly_map);
+}
+
+module_init(init_rc_map_snapstream_firefly)
+module_exit(exit_rc_map_snapstream_firefly)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Anssi Hannula <anssi.hannula@iki.fi>");
index 85ff9a1ffb391b4ccfa291539e027ffa2c8d10da..60d3c1e0971205a83b63e81f34ce5193dbc587e2 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Driver for USB Windows Media Center Ed. eHome Infrared Transceivers
  *
- * Copyright (c) 2010 by Jarod Wilson <jarod@redhat.com>
+ * Copyright (c) 2010-2011, Jarod Wilson <jarod@redhat.com>
  *
  * Based on the original lirc_mceusb and lirc_mceusb2 drivers, by Dan
  * Conti, Martin Blatter and Daniel Melander, the latter of which was
  * Jon Smirl, which included enhancements and simplifications to the
  * incoming IR buffer parsing routines.
  *
+ * Updated in July of 2011 with the aid of Microsoft's official
+ * remote/transceiver requirements and specification document, found at
+ * download.microsoft.com, title
+ * Windows-Media-Center-RC-IR-Collection-Green-Button-Specification-03-08-2011-V2.pdf
+ *
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #include <linux/slab.h>
 #include <linux/usb.h>
 #include <linux/usb/input.h>
+#include <linux/pm_wakeup.h>
 #include <media/rc-core.h>
 
-#define DRIVER_VERSION "1.91"
-#define DRIVER_AUTHOR  "Jarod Wilson <jarod@wilsonet.com>"
+#define DRIVER_VERSION "1.92"
+#define DRIVER_AUTHOR  "Jarod Wilson <jarod@redhat.com>"
 #define DRIVER_DESC    "Windows Media Center Ed. eHome Infrared Transceiver " \
                        "device driver"
 #define DRIVER_NAME    "mceusb"
 #define MCE_PULSE_MASK         0x7f /* Pulse mask */
 #define MCE_MAX_PULSE_LENGTH   0x7f /* Longest transmittable pulse symbol */
 
-#define MCE_HW_CMD_HEADER      0xff    /* MCE hardware command header */
-#define MCE_COMMAND_HEADER     0x9f    /* MCE command header */
-#define MCE_COMMAND_MASK       0xe0    /* Mask out command bits */
-#define MCE_COMMAND_NULL       0x00    /* These show up various places... */
-/* if buf[i] & MCE_COMMAND_MASK == 0x80 and buf[i] != MCE_COMMAND_HEADER,
- * then we're looking at a raw IR data sample */
-#define MCE_COMMAND_IRDATA     0x80
-#define MCE_PACKET_LENGTH_MASK 0x1f /* Packet length mask */
-
-/* Sub-commands, which follow MCE_COMMAND_HEADER or MCE_HW_CMD_HEADER */
+/*
+ * The interface between the host and the IR hardware is command-response
+ * based. All commands and responses have a consistent format, where a lead
+ * byte always identifies the type of data following it. The lead byte has
+ * a port value in the 3 highest bits and a length value in the 5 lowest
+ * bits.
+ *
+ * The length field is overloaded, with a value of 11111 indicating that the
+ * following byte is a command or response code, and the length of the entire
+ * message is determined by the code. If the length field is not 11111, then
+ * it specifies the number of bytes of port data that follow.
+ */
+#define MCE_CMD                        0x1f
+#define MCE_PORT_IR            0x4     /* (0x4 << 5) | MCE_CMD = 0x9f */
+#define MCE_PORT_SYS           0x7     /* (0x7 << 5) | MCE_CMD = 0xff */
+#define MCE_PORT_SER           0x6     /* 0xc0 thru 0xdf flush & 0x1f bytes */
+#define MCE_PORT_MASK  0xe0    /* Mask out command bits */
+
+/* Command port headers */
+#define MCE_CMD_PORT_IR                0x9f    /* IR-related cmd/rsp */
+#define MCE_CMD_PORT_SYS       0xff    /* System (non-IR) device cmd/rsp */
+
+/* Commands that set device state  (2-4 bytes in length) */
+#define MCE_CMD_RESET          0xfe    /* Reset device, 2 bytes */
+#define MCE_CMD_RESUME         0xaa    /* Resume device after error, 2 bytes */
+#define MCE_CMD_SETIRCFS       0x06    /* Set tx carrier, 4 bytes */
+#define MCE_CMD_SETIRTIMEOUT   0x0c    /* Set timeout, 4 bytes */
+#define MCE_CMD_SETIRTXPORTS   0x08    /* Set tx ports, 3 bytes */
+#define MCE_CMD_SETIRRXPORTEN  0x14    /* Set rx ports, 3 bytes */
+#define MCE_CMD_FLASHLED       0x23    /* Flash receiver LED, 2 bytes */
+
+/* Commands that query device state (all 2 bytes, unless noted) */
+#define MCE_CMD_GETIRCFS       0x07    /* Get carrier */
+#define MCE_CMD_GETIRTIMEOUT   0x0d    /* Get timeout */
+#define MCE_CMD_GETIRTXPORTS   0x13    /* Get tx ports */
+#define MCE_CMD_GETIRRXPORTEN  0x15    /* Get rx ports */
+#define MCE_CMD_GETPORTSTATUS  0x11    /* Get tx port status, 3 bytes */
+#define MCE_CMD_GETIRNUMPORTS  0x16    /* Get number of ports */
+#define MCE_CMD_GETWAKESOURCE  0x17    /* Get wake source */
+#define MCE_CMD_GETEMVER       0x22    /* Get emulator interface version */
+#define MCE_CMD_GETDEVDETAILS  0x21    /* Get device details (em ver2 only) */
+#define MCE_CMD_GETWAKESUPPORT 0x20    /* Get wake details (em ver2 only) */
+#define MCE_CMD_GETWAKEVERSION 0x18    /* Get wake pattern (em ver2 only) */
+
+/* Misc commands */
+#define MCE_CMD_NOP            0xff    /* No operation */
+
+/* Responses to commands (non-error cases) */
+#define MCE_RSP_EQIRCFS                0x06    /* tx carrier, 4 bytes */
+#define MCE_RSP_EQIRTIMEOUT    0x0c    /* rx timeout, 4 bytes */
+#define MCE_RSP_GETWAKESOURCE  0x17    /* wake source, 3 bytes */
+#define MCE_RSP_EQIRTXPORTS    0x08    /* tx port mask, 3 bytes */
+#define MCE_RSP_EQIRRXPORTEN   0x14    /* rx port mask, 3 bytes */
+#define MCE_RSP_GETPORTSTATUS  0x11    /* tx port status, 7 bytes */
+#define MCE_RSP_EQIRRXCFCNT    0x15    /* rx carrier count, 4 bytes */
+#define MCE_RSP_EQIRNUMPORTS   0x16    /* number of ports, 4 bytes */
+#define MCE_RSP_EQWAKESUPPORT  0x20    /* wake capabilities, 3 bytes */
+#define MCE_RSP_EQWAKEVERSION  0x18    /* wake pattern details, 6 bytes */
+#define MCE_RSP_EQDEVDETAILS   0x21    /* device capabilities, 3 bytes */
+#define MCE_RSP_EQEMVER                0x22    /* emulator interface ver, 3 bytes */
+#define MCE_RSP_FLASHLED       0x23    /* success flashing LED, 2 bytes */
+
+/* Responses to error cases, must send MCE_CMD_RESUME to clear them */
+#define MCE_RSP_CMD_ILLEGAL    0xfe    /* illegal command for port, 2 bytes */
+#define MCE_RSP_TX_TIMEOUT     0x81    /* tx timed out, 2 bytes */
+
+/* Misc commands/responses not defined in the MCE remote/transceiver spec */
 #define MCE_CMD_SIG_END                0x01    /* End of signal */
 #define MCE_CMD_PING           0x03    /* Ping device */
 #define MCE_CMD_UNKNOWN                0x04    /* Unknown */
 #define MCE_CMD_UNKNOWN2       0x05    /* Unknown */
-#define MCE_CMD_S_CARRIER      0x06    /* Set TX carrier frequency */
-#define MCE_CMD_G_CARRIER      0x07    /* Get TX carrier frequency */
-#define MCE_CMD_S_TXMASK       0x08    /* Set TX port bitmask */
 #define MCE_CMD_UNKNOWN3       0x09    /* Unknown */
 #define MCE_CMD_UNKNOWN4       0x0a    /* Unknown */
 #define MCE_CMD_G_REVISION     0x0b    /* Get hw/sw revision */
-#define MCE_CMD_S_TIMEOUT      0x0c    /* Set RX timeout value */
-#define MCE_CMD_G_TIMEOUT      0x0d    /* Get RX timeout value */
 #define MCE_CMD_UNKNOWN5       0x0e    /* Unknown */
 #define MCE_CMD_UNKNOWN6       0x0f    /* Unknown */
-#define MCE_CMD_G_RXPORTSTS    0x11    /* Get RX port status */
-#define MCE_CMD_G_TXMASK       0x13    /* Set TX port bitmask */
-#define MCE_CMD_S_RXSENSOR     0x14    /* Set RX sensor (std/learning) */
-#define MCE_CMD_G_RXSENSOR     0x15    /* Get RX sensor (std/learning) */
-#define MCE_RSP_PULSE_COUNT    0x15    /* RX pulse count (only if learning) */
-#define MCE_CMD_TX_PORTS       0x16    /* Get number of TX ports */
-#define MCE_CMD_G_WAKESRC      0x17    /* Get wake source */
-#define MCE_CMD_UNKNOWN7       0x18    /* Unknown */
 #define MCE_CMD_UNKNOWN8       0x19    /* Unknown */
 #define MCE_CMD_UNKNOWN9       0x1b    /* Unknown */
-#define MCE_CMD_DEVICE_RESET   0xaa    /* Reset the hardware */
-#define MCE_RSP_CMD_INVALID    0xfe    /* Invalid command issued */
+#define MCE_CMD_NULL           0x00    /* These show up various places... */
 
+/* if buf[i] & MCE_PORT_MASK == 0x80 and buf[i] != MCE_CMD_PORT_IR,
+ * then we're looking at a raw IR data sample */
+#define MCE_COMMAND_IRDATA     0x80
+#define MCE_PACKET_LENGTH_MASK 0x1f /* Packet length mask */
 
 /* module parameters */
 #ifdef CONFIG_USB_DEBUG
@@ -388,48 +441,37 @@ struct mceusb_dev {
        char name[128];
        char phys[64];
        enum mceusb_model_type model;
+
+       bool need_reset;        /* flag to issue a device resume cmd */
+       u8 emver;               /* emulator interface version */
+       u8 num_txports;         /* number of transmit ports */
+       u8 num_rxports;         /* number of receive sensors */
+       u8 txports_cabled;      /* bitmask of transmitters with cable */
+       u8 rxports_active;      /* bitmask of active receive sensors */
 };
 
-/*
- * MCE Device Command Strings
- * Device command responses vary from device to device...
- * - DEVICE_RESET resets the hardware to its default state
- * - GET_REVISION fetches the hardware/software revision, common
- *   replies are ff 0b 45 ff 1b 08 and ff 0b 50 ff 1b 42
- * - GET_CARRIER_FREQ gets the carrier mode and frequency of the
- *   device, with replies in the form of 9f 06 MM FF, where MM is 0-3,
- *   meaning clk of 10000000, 2500000, 625000 or 156250, and FF is
- *   ((clk / frequency) - 1)
- * - GET_RX_TIMEOUT fetches the receiver timeout in units of 50us,
- *   response in the form of 9f 0c msb lsb
- * - GET_TX_BITMASK fetches the transmitter bitmask, replies in
- *   the form of 9f 08 bm, where bm is the bitmask
- * - GET_RX_SENSOR fetches the RX sensor setting -- long-range
- *   general use one or short-range learning one, in the form of
- *   9f 14 ss, where ss is either 01 for long-range or 02 for short
- * - SET_CARRIER_FREQ sets a new carrier mode and frequency
- * - SET_TX_BITMASK sets the transmitter bitmask
- * - SET_RX_TIMEOUT sets the receiver timeout
- * - SET_RX_SENSOR sets which receiver sensor to use
- */
-static char DEVICE_RESET[]     = {MCE_COMMAND_NULL, MCE_HW_CMD_HEADER,
-                                  MCE_CMD_DEVICE_RESET};
-static char GET_REVISION[]     = {MCE_HW_CMD_HEADER, MCE_CMD_G_REVISION};
-static char GET_UNKNOWN[]      = {MCE_HW_CMD_HEADER, MCE_CMD_UNKNOWN7};
-static char GET_UNKNOWN2[]     = {MCE_COMMAND_HEADER, MCE_CMD_UNKNOWN2};
-static char GET_CARRIER_FREQ[] = {MCE_COMMAND_HEADER, MCE_CMD_G_CARRIER};
-static char GET_RX_TIMEOUT[]   = {MCE_COMMAND_HEADER, MCE_CMD_G_TIMEOUT};
-static char GET_TX_BITMASK[]   = {MCE_COMMAND_HEADER, MCE_CMD_G_TXMASK};
-static char GET_RX_SENSOR[]    = {MCE_COMMAND_HEADER, MCE_CMD_G_RXSENSOR};
+/* MCE Device Command Strings, generally a port and command pair */
+static char DEVICE_RESUME[]    = {MCE_CMD_NULL, MCE_CMD_PORT_SYS,
+                                  MCE_CMD_RESUME};
+static char GET_REVISION[]     = {MCE_CMD_PORT_SYS, MCE_CMD_G_REVISION};
+static char GET_EMVER[]                = {MCE_CMD_PORT_SYS, MCE_CMD_GETEMVER};
+static char GET_WAKEVERSION[]  = {MCE_CMD_PORT_SYS, MCE_CMD_GETWAKEVERSION};
+static char FLASH_LED[]                = {MCE_CMD_PORT_SYS, MCE_CMD_FLASHLED};
+static char GET_UNKNOWN2[]     = {MCE_CMD_PORT_IR, MCE_CMD_UNKNOWN2};
+static char GET_CARRIER_FREQ[] = {MCE_CMD_PORT_IR, MCE_CMD_GETIRCFS};
+static char GET_RX_TIMEOUT[]   = {MCE_CMD_PORT_IR, MCE_CMD_GETIRTIMEOUT};
+static char GET_NUM_PORTS[]    = {MCE_CMD_PORT_IR, MCE_CMD_GETIRNUMPORTS};
+static char GET_TX_BITMASK[]   = {MCE_CMD_PORT_IR, MCE_CMD_GETIRTXPORTS};
+static char GET_RX_SENSOR[]    = {MCE_CMD_PORT_IR, MCE_CMD_GETIRRXPORTEN};
 /* sub in desired values in lower byte or bytes for full command */
 /* FIXME: make use of these for transmit.
-static char SET_CARRIER_FREQ[] = {MCE_COMMAND_HEADER,
-                                  MCE_CMD_S_CARRIER, 0x00, 0x00};
-static char SET_TX_BITMASK[]   = {MCE_COMMAND_HEADER, MCE_CMD_S_TXMASK, 0x00};
-static char SET_RX_TIMEOUT[]   = {MCE_COMMAND_HEADER,
-                                  MCE_CMD_S_TIMEOUT, 0x00, 0x00};
-static char SET_RX_SENSOR[]    = {MCE_COMMAND_HEADER,
-                                  MCE_CMD_S_RXSENSOR, 0x00};
+static char SET_CARRIER_FREQ[] = {MCE_CMD_PORT_IR,
+                                  MCE_CMD_SETIRCFS, 0x00, 0x00};
+static char SET_TX_BITMASK[]   = {MCE_CMD_PORT_IR, MCE_CMD_SETIRTXPORTS, 0x00};
+static char SET_RX_TIMEOUT[]   = {MCE_CMD_PORT_IR,
+                                  MCE_CMD_SETIRTIMEOUT, 0x00, 0x00};
+static char SET_RX_SENSOR[]    = {MCE_CMD_PORT_IR,
+                                  MCE_RSP_EQIRRXPORTEN, 0x00};
 */
 
 static int mceusb_cmdsize(u8 cmd, u8 subcmd)
@@ -437,27 +479,33 @@ static int mceusb_cmdsize(u8 cmd, u8 subcmd)
        int datasize = 0;
 
        switch (cmd) {
-       case MCE_COMMAND_NULL:
-               if (subcmd == MCE_HW_CMD_HEADER)
+       case MCE_CMD_NULL:
+               if (subcmd == MCE_CMD_PORT_SYS)
                        datasize = 1;
                break;
-       case MCE_HW_CMD_HEADER:
+       case MCE_CMD_PORT_SYS:
                switch (subcmd) {
+               case MCE_RSP_EQWAKEVERSION:
+                       datasize = 4;
+                       break;
                case MCE_CMD_G_REVISION:
                        datasize = 2;
                        break;
+               case MCE_RSP_EQWAKESUPPORT:
+                       datasize = 1;
+                       break;
                }
-       case MCE_COMMAND_HEADER:
+       case MCE_CMD_PORT_IR:
                switch (subcmd) {
                case MCE_CMD_UNKNOWN:
-               case MCE_CMD_S_CARRIER:
-               case MCE_CMD_S_TIMEOUT:
-               case MCE_RSP_PULSE_COUNT:
+               case MCE_RSP_EQIRCFS:
+               case MCE_RSP_EQIRTIMEOUT:
+               case MCE_RSP_EQIRRXCFCNT:
                        datasize = 2;
                        break;
                case MCE_CMD_SIG_END:
-               case MCE_CMD_S_TXMASK:
-               case MCE_CMD_S_RXSENSOR:
+               case MCE_RSP_EQIRTXPORTS:
+               case MCE_RSP_EQIRRXPORTEN:
                        datasize = 1;
                        break;
                }
@@ -470,9 +518,10 @@ static void mceusb_dev_printdata(struct mceusb_dev *ir, char *buf,
 {
        char codes[USB_BUFLEN * 3 + 1];
        char inout[9];
-       u8 cmd, subcmd, data1, data2;
+       u8 cmd, subcmd, data1, data2, data3, data4, data5;
        struct device *dev = ir->dev;
        int i, start, skip = 0;
+       u32 carrier, period;
 
        if (!debug)
                return;
@@ -500,18 +549,28 @@ static void mceusb_dev_printdata(struct mceusb_dev *ir, char *buf,
        subcmd = buf[start + 1] & 0xff;
        data1  = buf[start + 2] & 0xff;
        data2  = buf[start + 3] & 0xff;
+       data3  = buf[start + 4] & 0xff;
+       data4  = buf[start + 5] & 0xff;
+       data5  = buf[start + 6] & 0xff;
 
        switch (cmd) {
-       case MCE_COMMAND_NULL:
-               if ((subcmd == MCE_HW_CMD_HEADER) &&
-                   (data1 == MCE_CMD_DEVICE_RESET))
-                       dev_info(dev, "Device reset requested\n");
+       case MCE_CMD_NULL:
+               if (subcmd == MCE_CMD_NULL)
+                       break;
+               if ((subcmd == MCE_CMD_PORT_SYS) &&
+                   (data1 == MCE_CMD_RESUME))
+                       dev_info(dev, "Device resume requested\n");
                else
                        dev_info(dev, "Unknown command 0x%02x 0x%02x\n",
                                 cmd, subcmd);
                break;
-       case MCE_HW_CMD_HEADER:
+       case MCE_CMD_PORT_SYS:
                switch (subcmd) {
+               case MCE_RSP_EQEMVER:
+                       if (!out)
+                               dev_info(dev, "Emulator interface version %x\n",
+                                        data1);
+                       break;
                case MCE_CMD_G_REVISION:
                        if (len == 2)
                                dev_info(dev, "Get hw/sw rev?\n");
@@ -520,21 +579,35 @@ static void mceusb_dev_printdata(struct mceusb_dev *ir, char *buf,
                                         "0x%02x 0x%02x\n", data1, data2,
                                         buf[start + 4], buf[start + 5]);
                        break;
-               case MCE_CMD_DEVICE_RESET:
-                       dev_info(dev, "Device reset requested\n");
+               case MCE_CMD_RESUME:
+                       dev_info(dev, "Device resume requested\n");
+                       break;
+               case MCE_RSP_CMD_ILLEGAL:
+                       dev_info(dev, "Illegal PORT_SYS command\n");
                        break;
-               case MCE_RSP_CMD_INVALID:
-                       dev_info(dev, "Previous command not supported\n");
+               case MCE_RSP_EQWAKEVERSION:
+                       if (!out)
+                               dev_info(dev, "Wake version, proto: 0x%02x, "
+                                        "payload: 0x%02x, address: 0x%02x, "
+                                        "version: 0x%02x\n",
+                                        data1, data2, data3, data4);
+                       break;
+               case MCE_RSP_GETPORTSTATUS:
+                       if (!out)
+                               /* We use data1 + 1 here, to match hw labels */
+                               dev_info(dev, "TX port %d: blaster is%s connected\n",
+                                        data1 + 1, data4 ? " not" : "");
+                       break;
+               case MCE_CMD_FLASHLED:
+                       dev_info(dev, "Attempting to flash LED\n");
                        break;
-               case MCE_CMD_UNKNOWN7:
-               case MCE_CMD_UNKNOWN9:
                default:
                        dev_info(dev, "Unknown command 0x%02x 0x%02x\n",
                                 cmd, subcmd);
                        break;
                }
                break;
-       case MCE_COMMAND_HEADER:
+       case MCE_CMD_PORT_IR:
                switch (subcmd) {
                case MCE_CMD_SIG_END:
                        dev_info(dev, "End of signal\n");
@@ -546,47 +619,55 @@ static void mceusb_dev_printdata(struct mceusb_dev *ir, char *buf,
                        dev_info(dev, "Resp to 9f 05 of 0x%02x 0x%02x\n",
                                 data1, data2);
                        break;
-               case MCE_CMD_S_CARRIER:
-                       dev_info(dev, "%s carrier mode and freq of "
-                                "0x%02x 0x%02x\n", inout, data1, data2);
+               case MCE_RSP_EQIRCFS:
+                       period = DIV_ROUND_CLOSEST(
+                                       (1 << data1 * 2) * (data2 + 1), 10);
+                       if (!period)
+                               break;
+                       carrier = (1000 * 1000) / period;
+                       dev_info(dev, "%s carrier of %u Hz (period %uus)\n",
+                                inout, carrier, period);
                        break;
-               case MCE_CMD_G_CARRIER:
+               case MCE_CMD_GETIRCFS:
                        dev_info(dev, "Get carrier mode and freq\n");
                        break;
-               case MCE_CMD_S_TXMASK:
+               case MCE_RSP_EQIRTXPORTS:
                        dev_info(dev, "%s transmit blaster mask of 0x%02x\n",
                                 inout, data1);
                        break;
-               case MCE_CMD_S_TIMEOUT:
+               case MCE_RSP_EQIRTIMEOUT:
                        /* value is in units of 50us, so x*50/1000 ms */
+                       period = ((data1 << 8) | data2) * MCE_TIME_UNIT / 1000;
                        dev_info(dev, "%s receive timeout of %d ms\n",
-                                inout,
-                                ((data1 << 8) | data2) * MCE_TIME_UNIT / 1000);
+                                inout, period);
                        break;
-               case MCE_CMD_G_TIMEOUT:
+               case MCE_CMD_GETIRTIMEOUT:
                        dev_info(dev, "Get receive timeout\n");
                        break;
-               case MCE_CMD_G_TXMASK:
+               case MCE_CMD_GETIRTXPORTS:
                        dev_info(dev, "Get transmit blaster mask\n");
                        break;
-               case MCE_CMD_S_RXSENSOR:
+               case MCE_RSP_EQIRRXPORTEN:
                        dev_info(dev, "%s %s-range receive sensor in use\n",
                                 inout, data1 == 0x02 ? "short" : "long");
                        break;
-               case MCE_CMD_G_RXSENSOR:
-               /* aka MCE_RSP_PULSE_COUNT */
+               case MCE_CMD_GETIRRXPORTEN:
+               /* aka MCE_RSP_EQIRRXCFCNT */
                        if (out)
                                dev_info(dev, "Get receive sensor\n");
                        else if (ir->learning_enabled)
                                dev_info(dev, "RX pulse count: %d\n",
                                         ((data1 << 8) | data2));
                        break;
-               case MCE_RSP_CMD_INVALID:
-                       dev_info(dev, "Error! Hardware is likely wedged...\n");
+               case MCE_RSP_EQIRNUMPORTS:
+                       if (out)
+                               break;
+                       dev_info(dev, "Num TX ports: %x, num RX ports: %x\n",
+                                data1, data2);
+                       break;
+               case MCE_RSP_CMD_ILLEGAL:
+                       dev_info(dev, "Illegal PORT_IR command\n");
                        break;
-               case MCE_CMD_UNKNOWN2:
-               case MCE_CMD_UNKNOWN3:
-               case MCE_CMD_UNKNOWN5:
                default:
                        dev_info(dev, "Unknown command 0x%02x 0x%02x\n",
                                 cmd, subcmd);
@@ -599,8 +680,8 @@ static void mceusb_dev_printdata(struct mceusb_dev *ir, char *buf,
 
        if (cmd == MCE_IRDATA_TRAILER)
                dev_info(dev, "End of raw IR data\n");
-       else if ((cmd != MCE_COMMAND_HEADER) &&
-                ((cmd & MCE_COMMAND_MASK) == MCE_COMMAND_IRDATA))
+       else if ((cmd != MCE_CMD_PORT_IR) &&
+                ((cmd & MCE_PORT_MASK) == MCE_COMMAND_IRDATA))
                dev_info(dev, "Raw IR data, %d pulse/space samples\n", ir->rem);
 }
 
@@ -616,9 +697,6 @@ static void mce_async_callback(struct urb *urb, struct pt_regs *regs)
        if (ir) {
                len = urb->actual_length;
 
-               mce_dbg(ir->dev, "callback called (status=%d len=%d)\n",
-                       urb->status, len);
-
                mceusb_dev_printdata(ir, urb->transfer_buffer, 0, len, true);
        }
 
@@ -683,7 +761,16 @@ static void mce_request_packet(struct mceusb_dev *ir, unsigned char *data,
 
 static void mce_async_out(struct mceusb_dev *ir, unsigned char *data, int size)
 {
+       int rsize = sizeof(DEVICE_RESUME);
+
+       if (ir->need_reset) {
+               ir->need_reset = false;
+               mce_request_packet(ir, DEVICE_RESUME, rsize, MCEUSB_TX);
+               msleep(10);
+       }
+
        mce_request_packet(ir, data, size, MCEUSB_TX);
+       msleep(10);
 }
 
 static void mce_flush_rx_buffer(struct mceusb_dev *ir, int size)
@@ -708,8 +795,8 @@ static int mceusb_tx_ir(struct rc_dev *dev, unsigned *txbuf, unsigned count)
                return -ENOMEM;
 
        /* MCE tx init header */
-       cmdbuf[cmdcount++] = MCE_COMMAND_HEADER;
-       cmdbuf[cmdcount++] = MCE_CMD_S_TXMASK;
+       cmdbuf[cmdcount++] = MCE_CMD_PORT_IR;
+       cmdbuf[cmdcount++] = MCE_CMD_SETIRTXPORTS;
        cmdbuf[cmdcount++] = ir->tx_mask;
 
        /* Generate mce packet data */
@@ -795,8 +882,8 @@ static int mceusb_set_tx_carrier(struct rc_dev *dev, u32 carrier)
        struct mceusb_dev *ir = dev->priv;
        int clk = 10000000;
        int prescaler = 0, divisor = 0;
-       unsigned char cmdbuf[4] = { MCE_COMMAND_HEADER,
-                                   MCE_CMD_S_CARRIER, 0x00, 0x00 };
+       unsigned char cmdbuf[4] = { MCE_CMD_PORT_IR,
+                                   MCE_CMD_SETIRCFS, 0x00, 0x00 };
 
        /* Carrier has changed */
        if (ir->carrier != carrier) {
@@ -844,17 +931,34 @@ static void mceusb_handle_command(struct mceusb_dev *ir, int index)
        u8 lo = ir->buf_in[index + 2] & 0xff;
 
        switch (ir->buf_in[index]) {
+       /* the one and only 5-byte return value command */
+       case MCE_RSP_GETPORTSTATUS:
+               if ((ir->buf_in[index + 4] & 0xff) == 0x00)
+                       ir->txports_cabled |= 1 << hi;
+               break;
+
        /* 2-byte return value commands */
-       case MCE_CMD_S_TIMEOUT:
+       case MCE_RSP_EQIRTIMEOUT:
                ir->rc->timeout = US_TO_NS((hi << 8 | lo) * MCE_TIME_UNIT);
                break;
+       case MCE_RSP_EQIRNUMPORTS:
+               ir->num_txports = hi;
+               ir->num_rxports = lo;
+               break;
 
        /* 1-byte return value commands */
-       case MCE_CMD_S_TXMASK:
+       case MCE_RSP_EQEMVER:
+               ir->emver = hi;
+               break;
+       case MCE_RSP_EQIRTXPORTS:
                ir->tx_mask = hi;
                break;
-       case MCE_CMD_S_RXSENSOR:
-               ir->learning_enabled = (hi == 0x02);
+       case MCE_RSP_EQIRRXPORTEN:
+               ir->learning_enabled = ((hi & 0x02) == 0x02);
+               ir->rxports_active = hi;
+               break;
+       case MCE_RSP_CMD_ILLEGAL:
+               ir->need_reset = true;
                break;
        default:
                break;
@@ -903,8 +1007,8 @@ static void mceusb_process_ir_data(struct mceusb_dev *ir, int buf_len)
                        /* decode mce packets of the form (84),AA,BB,CC,DD */
                        /* IR data packets can span USB messages - rem */
                        ir->cmd = ir->buf_in[i];
-                       if ((ir->cmd == MCE_COMMAND_HEADER) ||
-                           ((ir->cmd & MCE_COMMAND_MASK) !=
+                       if ((ir->cmd == MCE_CMD_PORT_IR) ||
+                           ((ir->cmd & MCE_PORT_MASK) !=
                             MCE_COMMAND_IRDATA)) {
                                ir->parser_state = SUBCMD;
                                continue;
@@ -969,6 +1073,13 @@ static void mceusb_dev_recv(struct urb *urb, struct pt_regs *regs)
        usb_submit_urb(urb, GFP_ATOMIC);
 }
 
+static void mceusb_get_emulator_version(struct mceusb_dev *ir)
+{
+       /* If we get no reply or an illegal command reply, its ver 1, says MS */
+       ir->emver = 1;
+       mce_async_out(ir, GET_EMVER, sizeof(GET_EMVER));
+}
+
 static void mceusb_gen1_init(struct mceusb_dev *ir)
 {
        int ret;
@@ -1011,8 +1122,8 @@ static void mceusb_gen1_init(struct mceusb_dev *ir)
                              0x0000, 0x0100, NULL, 0, HZ * 3);
        mce_dbg(dev, "%s - retC = %d\n", __func__, ret);
 
-       /* device reset */
-       mce_async_out(ir, DEVICE_RESET, sizeof(DEVICE_RESET));
+       /* device resume */
+       mce_async_out(ir, DEVICE_RESUME, sizeof(DEVICE_RESUME));
 
        /* get hw/sw revision? */
        mce_async_out(ir, GET_REVISION, sizeof(GET_REVISION));
@@ -1022,23 +1133,36 @@ static void mceusb_gen1_init(struct mceusb_dev *ir)
 
 static void mceusb_gen2_init(struct mceusb_dev *ir)
 {
-       /* device reset */
-       mce_async_out(ir, DEVICE_RESET, sizeof(DEVICE_RESET));
+       /* device resume */
+       mce_async_out(ir, DEVICE_RESUME, sizeof(DEVICE_RESUME));
 
        /* get hw/sw revision? */
        mce_async_out(ir, GET_REVISION, sizeof(GET_REVISION));
 
-       /* unknown what the next two actually return... */
-       mce_async_out(ir, GET_UNKNOWN, sizeof(GET_UNKNOWN));
+       /* get wake version (protocol, key, address) */
+       mce_async_out(ir, GET_WAKEVERSION, sizeof(GET_WAKEVERSION));
+
+       /* unknown what this one actually returns... */
        mce_async_out(ir, GET_UNKNOWN2, sizeof(GET_UNKNOWN2));
 }
 
 static void mceusb_get_parameters(struct mceusb_dev *ir)
 {
+       int i;
+       unsigned char cmdbuf[3] = { MCE_CMD_PORT_SYS,
+                                   MCE_CMD_GETPORTSTATUS, 0x00 };
+
+       /* defaults, if the hardware doesn't support querying */
+       ir->num_txports = 2;
+       ir->num_rxports = 2;
+
+       /* get number of tx and rx ports */
+       mce_async_out(ir, GET_NUM_PORTS, sizeof(GET_NUM_PORTS));
+
        /* get the carrier and frequency */
        mce_async_out(ir, GET_CARRIER_FREQ, sizeof(GET_CARRIER_FREQ));
 
-       if (!ir->flags.no_tx)
+       if (ir->num_txports && !ir->flags.no_tx)
                /* get the transmitter bitmask */
                mce_async_out(ir, GET_TX_BITMASK, sizeof(GET_TX_BITMASK));
 
@@ -1047,6 +1171,19 @@ static void mceusb_get_parameters(struct mceusb_dev *ir)
 
        /* get receiver sensor setting */
        mce_async_out(ir, GET_RX_SENSOR, sizeof(GET_RX_SENSOR));
+
+       for (i = 0; i < ir->num_txports; i++) {
+               cmdbuf[2] = i;
+               mce_async_out(ir, cmdbuf, sizeof(cmdbuf));
+       }
+}
+
+static void mceusb_flash_led(struct mceusb_dev *ir)
+{
+       if (ir->emver < 2)
+               return;
+
+       mce_async_out(ir, FLASH_LED, sizeof(FLASH_LED));
 }
 
 static struct rc_dev *mceusb_init_rc_dev(struct mceusb_dev *ir)
@@ -1220,6 +1357,9 @@ static int __devinit mceusb_dev_probe(struct usb_interface *intf,
        mce_dbg(&intf->dev, "Flushing receive buffers\n");
        mce_flush_rx_buffer(ir, maxp);
 
+       /* figure out which firmware/emulator version this hardware has */
+       mceusb_get_emulator_version(ir);
+
        /* initialize device */
        if (ir->flags.microsoft_gen1)
                mceusb_gen1_init(ir);
@@ -1228,13 +1368,23 @@ static int __devinit mceusb_dev_probe(struct usb_interface *intf,
 
        mceusb_get_parameters(ir);
 
+       mceusb_flash_led(ir);
+
        if (!ir->flags.no_tx)
                mceusb_set_tx_mask(ir->rc, MCE_DEFAULT_TX_MASK);
 
        usb_set_intfdata(intf, ir);
 
-       dev_info(&intf->dev, "Registered %s on usb%d:%d\n", name,
-                dev->bus->busnum, dev->devnum);
+       /* enable wake via this device */
+       device_set_wakeup_capable(ir->dev, true);
+       device_set_wakeup_enable(ir->dev, true);
+
+       dev_info(&intf->dev, "Registered %s with mce emulator interface "
+                "version %x\n", name, ir->emver);
+       dev_info(&intf->dev, "%x tx ports (0x%x cabled) and "
+                "%x rx sensors (0x%x active)\n",
+                ir->num_txports, ir->txports_cabled,
+                ir->num_rxports, ir->rxports_active);
 
        return 0;
 
index 04c2c722b6ece48d9ead508e952b6e4ab4927328..c6ca870e8b7eb1e2a112b8da1670cd896ed12e1d 100644 (file)
@@ -162,49 +162,49 @@ void ir_raw_init(void);
 #ifdef CONFIG_IR_NEC_DECODER_MODULE
 #define load_nec_decode()      request_module("ir-nec-decoder")
 #else
-#define load_nec_decode()      0
+static inline void load_nec_decode(void) { }
 #endif
 
 /* from ir-rc5-decoder.c */
 #ifdef CONFIG_IR_RC5_DECODER_MODULE
 #define load_rc5_decode()      request_module("ir-rc5-decoder")
 #else
-#define load_rc5_decode()      0
+static inline void load_rc5_decode(void) { }
 #endif
 
 /* from ir-rc6-decoder.c */
 #ifdef CONFIG_IR_RC6_DECODER_MODULE
 #define load_rc6_decode()      request_module("ir-rc6-decoder")
 #else
-#define load_rc6_decode()      0
+static inline void load_rc6_decode(void) { }
 #endif
 
 /* from ir-jvc-decoder.c */
 #ifdef CONFIG_IR_JVC_DECODER_MODULE
 #define load_jvc_decode()      request_module("ir-jvc-decoder")
 #else
-#define load_jvc_decode()      0
+static inline void load_jvc_decode(void) { }
 #endif
 
 /* from ir-sony-decoder.c */
 #ifdef CONFIG_IR_SONY_DECODER_MODULE
 #define load_sony_decode()     request_module("ir-sony-decoder")
 #else
-#define load_sony_decode()     0
+static inline void load_sony_decode(void) { }
 #endif
 
 /* from ir-mce_kbd-decoder.c */
 #ifdef CONFIG_IR_MCE_KBD_DECODER_MODULE
 #define load_mce_kbd_decode()  request_module("ir-mce_kbd-decoder")
 #else
-#define load_mce_kbd_decode()  0
+static inline void load_mce_kbd_decode(void) { }
 #endif
 
 /* from ir-lirc-codec.c */
 #ifdef CONFIG_IR_LIRC_CODEC_MODULE
 #define load_lirc_codec()      request_module("ir-lirc-codec")
 #else
-#define load_lirc_codec()      0
+static inline void load_lirc_codec(void) { }
 #endif
 
 
index 51a23f48bc7d83f99eed629a32188083f22786c3..666d4bb5b1fb17b611c8fba37517494db746ead8 100644 (file)
@@ -928,10 +928,6 @@ out:
 
 static void rc_dev_release(struct device *device)
 {
-       struct rc_dev *dev = to_rc_dev(device);
-
-       kfree(dev);
-       module_put(THIS_MODULE);
 }
 
 #define ADD_HOTPLUG_VAR(fmt, val...)                                   \
@@ -945,6 +941,9 @@ static int rc_dev_uevent(struct device *device, struct kobj_uevent_env *env)
 {
        struct rc_dev *dev = to_rc_dev(device);
 
+       if (!dev || !dev->input_dev)
+               return -ENODEV;
+
        if (dev->rc_map.name)
                ADD_HOTPLUG_VAR("NAME=%s", dev->rc_map.name);
        if (dev->driver_name)
@@ -1013,10 +1012,16 @@ EXPORT_SYMBOL_GPL(rc_allocate_device);
 
 void rc_free_device(struct rc_dev *dev)
 {
-       if (dev) {
+       if (!dev)
+               return;
+
+       if (dev->input_dev)
                input_free_device(dev->input_dev);
-               put_device(&dev->dev);
-       }
+
+       put_device(&dev->dev);
+
+       kfree(dev);
+       module_put(THIS_MODULE);
 }
 EXPORT_SYMBOL_GPL(rc_free_device);
 
@@ -1143,14 +1148,18 @@ void rc_unregister_device(struct rc_dev *dev)
        if (dev->driver_type == RC_DRIVER_IR_RAW)
                ir_raw_event_unregister(dev);
 
+       /* Freeing the table should also call the stop callback */
+       ir_free_table(&dev->rc_map);
+       IR_dprintk(1, "Freed keycode table\n");
+
        input_unregister_device(dev->input_dev);
        dev->input_dev = NULL;
 
-       ir_free_table(&dev->rc_map);
-       IR_dprintk(1, "Freed keycode table\n");
+       device_del(&dev->dev);
 
-       device_unregister(&dev->dev);
+       rc_free_device(dev);
 }
+
 EXPORT_SYMBOL_GPL(rc_unregister_device);
 
 /*
index a166044779174bd4349572a052af3b16ff3b3c6d..61287fcca61aa323742e86ffa04899b1e662dd2e 100644 (file)
@@ -195,11 +195,6 @@ struct redrat3_dev {
        dma_addr_t dma_in;
        dma_addr_t dma_out;
 
-       /* true if write urb is busy */
-       bool write_busy;
-       /* wait for the write to finish */
-       struct completion write_finished;
-
        /* locks this structure */
        struct mutex lock;
 
@@ -207,8 +202,6 @@ struct redrat3_dev {
        struct timer_list rx_timeout;
        u32 hw_timeout;
 
-       /* Is the device currently receiving? */
-       bool recv_in_progress;
        /* is the detector enabled*/
        bool det_enabled;
        /* Is the device currently transmitting?*/
index bec8abc965f78061e7238bad7eda1adf58bd8b92..13f54b51194a02e360e09661fdfc5c50eeacf274 100644 (file)
@@ -41,6 +41,8 @@
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/module.h>
 #include <linux/pnp.h>
 #include <linux/interrupt.h>
@@ -1155,12 +1157,12 @@ wbcir_init(void)
        case IR_PROTOCOL_RC6:
                break;
        default:
-               printk(KERN_ERR DRVNAME ": Invalid power-on protocol\n");
+               pr_err("Invalid power-on protocol\n");
        }
 
        ret = pnp_register_driver(&wbcir_driver);
        if (ret)
-               printk(KERN_ERR DRVNAME ": Unable to register driver\n");
+               pr_err("Unable to register driver\n");
 
        return ret;
 }
index f574dc012cad047a817201b00676ff1497ac255c..d285c8c92819472d0ec0bc3a13afe9821f0680fd 100644 (file)
@@ -467,6 +467,20 @@ config VIDEO_OV7670
          OV7670 VGA camera.  It currently only works with the M88ALP01
          controller.
 
+config VIDEO_MT9P031
+       tristate "Aptina MT9P031 support"
+       depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+       ---help---
+         This is a Video4Linux2 sensor-level driver for the Aptina
+         (Micron) mt9p031 5 Mpixel camera.
+
+config VIDEO_MT9T001
+       tristate "Aptina MT9T001 support"
+       depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+       ---help---
+         This is a Video4Linux2 sensor-level driver for the Aptina
+         (Micron) mt0t001 3 Mpixel camera.
+
 config VIDEO_MT9V011
        tristate "Micron mt9v011 sensor support"
        depends on I2C && VIDEO_V4L2
@@ -489,6 +503,20 @@ config VIDEO_TCM825X
          This is a driver for the Toshiba TCM825x VGA camera sensor.
          It is used for example in Nokia N800.
 
+config VIDEO_SR030PC30
+       tristate "Siliconfile SR030PC30 sensor support"
+       depends on I2C && VIDEO_V4L2
+       ---help---
+         This driver supports SR030PC30 VGA camera from Siliconfile
+
+config VIDEO_NOON010PC30
+       tristate "Siliconfile NOON010PC30 sensor support"
+       depends on I2C && VIDEO_V4L2 && EXPERIMENTAL && VIDEO_V4L2_SUBDEV_API
+       ---help---
+         This driver supports NOON010PC30 CIF camera from Siliconfile
+
+source "drivers/media/video/m5mols/Kconfig"
+
 comment "Flash devices"
 
 config VIDEO_ADP1653
@@ -737,12 +765,6 @@ config VIDEO_M32R_AR_M64278
          To compile this driver as a module, choose M here: the
          module will be called arv.
 
-config VIDEO_SR030PC30
-       tristate "SR030PC30 VGA camera sensor support"
-       depends on I2C && VIDEO_V4L2
-       ---help---
-         This driver supports SR030PC30 VGA camera from Siliconfile
-
 config VIDEO_VIA_CAMERA
        tristate "VIAFB camera controller support"
        depends on FB_VIA
@@ -753,18 +775,9 @@ config VIDEO_VIA_CAMERA
           Chrome9 chipsets.  Currently only tested on OLPC xo-1.5 systems
           with ov7670 sensors.
 
-config VIDEO_NOON010PC30
-       tristate "NOON010PC30 CIF camera sensor support"
-       depends on I2C && VIDEO_V4L2
-       ---help---
-         This driver supports NOON010PC30 CIF camera from Siliconfile
-
-source "drivers/media/video/m5mols/Kconfig"
-
 config VIDEO_OMAP3
        tristate "OMAP 3 Camera support (EXPERIMENTAL)"
-       select OMAP_IOMMU
-       depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API && ARCH_OMAP3 && EXPERIMENTAL
+       depends on OMAP_IOVMM && VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API && ARCH_OMAP3 && EXPERIMENTAL
        ---help---
          Driver for an OMAP 3 camera controller.
 
@@ -949,8 +962,9 @@ config VIDEO_MX2
          Interface
 
 config  VIDEO_SAMSUNG_S5P_FIMC
-       tristate "Samsung S5P and EXYNOS4 camera host interface driver"
-       depends on VIDEO_DEV && VIDEO_V4L2 && PLAT_S5P
+       tristate "Samsung S5P and EXYNOS4 camera interface driver (EXPERIMENTAL)"
+       depends on VIDEO_V4L2 && I2C && PLAT_S5P && PM_RUNTIME && \
+               VIDEO_V4L2_SUBDEV_API && EXPERIMENTAL
        select VIDEOBUF2_DMA_CONTIG
        select V4L2_MEM2MEM_DEV
        ---help---
@@ -1004,6 +1018,8 @@ source "drivers/media/video/tlg2300/Kconfig"
 
 source "drivers/media/video/cx231xx/Kconfig"
 
+source "drivers/media/video/tm6000/Kconfig"
+
 source "drivers/media/video/usbvision/Kconfig"
 
 source "drivers/media/video/et61x251/Kconfig"
index 272390072aef7142b5e419e4443d7a5a3927533f..11fff97e7196c43cb2b2aa5cab7200d9042882ee 100644 (file)
@@ -65,6 +65,8 @@ obj-$(CONFIG_VIDEO_UPD64083) += upd64083.o
 obj-$(CONFIG_VIDEO_OV7670)     += ov7670.o
 obj-$(CONFIG_VIDEO_TCM825X) += tcm825x.o
 obj-$(CONFIG_VIDEO_TVEEPROM) += tveeprom.o
+obj-$(CONFIG_VIDEO_MT9P031) += mt9p031.o
+obj-$(CONFIG_VIDEO_MT9T001) += mt9t001.o
 obj-$(CONFIG_VIDEO_MT9V011) += mt9v011.o
 obj-$(CONFIG_VIDEO_MT9V032) += mt9v032.o
 obj-$(CONFIG_VIDEO_SR030PC30)  += sr030pc30.o
@@ -105,6 +107,7 @@ obj-$(CONFIG_VIDEO_CX231XX) += cx231xx/
 obj-$(CONFIG_VIDEO_USBVISION) += usbvision/
 obj-$(CONFIG_VIDEO_PVRUSB2) += pvrusb2/
 obj-$(CONFIG_VIDEO_CPIA2) += cpia2/
+obj-$(CONFIG_VIDEO_TM6000) += tm6000/
 obj-$(CONFIG_VIDEO_MXB) += mxb.o
 obj-$(CONFIG_VIDEO_HEXIUM_ORION) += hexium_orion.o
 obj-$(CONFIG_VIDEO_HEXIUM_GEMINI) += hexium_gemini.o
@@ -190,6 +193,6 @@ obj-y       += davinci/
 
 obj-$(CONFIG_ARCH_OMAP)        += omap/
 
-EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
-EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
-EXTRA_CFLAGS += -Idrivers/media/common/tuners
+ccflags-y += -Idrivers/media/dvb/dvb-core
+ccflags-y += -Idrivers/media/dvb/frontends
+ccflags-y += -Idrivers/media/common/tuners
index be7befd60947eff952698fc36f14923381ad69b7..5914390211ff2ac6f087ec5693c08234ec55bd7d 100644 (file)
@@ -32,6 +32,7 @@
 
 #include <linux/delay.h>
 #include <linux/i2c.h>
+#include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/version.h>
 #include <media/adp1653.h>
@@ -258,7 +259,7 @@ static int adp1653_init_controls(struct adp1653_flash *flash)
        if (flash->ctrls.error)
                return flash->ctrls.error;
 
-       fault->is_volatile = 1;
+       fault->flags |= V4L2_CTRL_FLAG_VOLATILE;
 
        flash->subdev.ctrl_handler = &flash->ctrls;
        return 0;
@@ -413,6 +414,10 @@ static int adp1653_probe(struct i2c_client *client,
        struct adp1653_flash *flash;
        int ret;
 
+       /* we couldn't work without platform data */
+       if (client->dev.platform_data == NULL)
+               return -ENODEV;
+
        flash = kzalloc(sizeof(*flash), GFP_KERNEL);
        if (flash == NULL)
                return -ENOMEM;
@@ -425,12 +430,21 @@ static int adp1653_probe(struct i2c_client *client,
        flash->subdev.internal_ops = &adp1653_internal_ops;
        flash->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
 
-       adp1653_init_controls(flash);
+       ret = adp1653_init_controls(flash);
+       if (ret)
+               goto free_and_quit;
 
        ret = media_entity_init(&flash->subdev.entity, 0, NULL, 0);
        if (ret < 0)
-               kfree(flash);
+               goto free_and_quit;
+
+       flash->subdev.entity.type = MEDIA_ENT_T_V4L2_SUBDEV_FLASH;
+
+       return 0;
 
+free_and_quit:
+       v4l2_ctrl_handler_free(&flash->ctrls);
+       kfree(flash);
        return ret;
 }
 
index d2327dbb473f6aae0b3be765a7dd71886adca38c..206078eca853d27ac63b5ca39f0312afbf27d055 100644 (file)
@@ -61,6 +61,11 @@ static inline struct adv7175 *to_adv7175(struct v4l2_subdev *sd)
 
 static char *inputs[] = { "pass_through", "play_back", "color_bar" };
 
+static enum v4l2_mbus_pixelcode adv7175_codes[] = {
+       V4L2_MBUS_FMT_UYVY8_2X8,
+       V4L2_MBUS_FMT_UYVY8_1X16,
+};
+
 /* ----------------------------------------------------------------------- */
 
 static inline int adv7175_write(struct v4l2_subdev *sd, u8 reg, u8 value)
@@ -296,6 +301,60 @@ static int adv7175_s_routing(struct v4l2_subdev *sd,
        return 0;
 }
 
+static int adv7175_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
+                               enum v4l2_mbus_pixelcode *code)
+{
+       if (index >= ARRAY_SIZE(adv7175_codes))
+               return -EINVAL;
+
+       *code = adv7175_codes[index];
+       return 0;
+}
+
+static int adv7175_g_fmt(struct v4l2_subdev *sd,
+                               struct v4l2_mbus_framefmt *mf)
+{
+       u8 val = adv7175_read(sd, 0x7);
+
+       if ((val & 0x40) == (1 << 6))
+               mf->code = V4L2_MBUS_FMT_UYVY8_1X16;
+       else
+               mf->code = V4L2_MBUS_FMT_UYVY8_2X8;
+
+       mf->colorspace  = V4L2_COLORSPACE_SMPTE170M;
+       mf->width       = 0;
+       mf->height      = 0;
+       mf->field       = V4L2_FIELD_ANY;
+
+       return 0;
+}
+
+static int adv7175_s_fmt(struct v4l2_subdev *sd,
+                               struct v4l2_mbus_framefmt *mf)
+{
+       u8 val = adv7175_read(sd, 0x7);
+       int ret;
+
+       switch (mf->code) {
+       case V4L2_MBUS_FMT_UYVY8_2X8:
+               val &= ~0x40;
+               break;
+
+       case V4L2_MBUS_FMT_UYVY8_1X16:
+               val |= 0x40;
+               break;
+
+       default:
+               v4l2_dbg(1, debug, sd,
+                       "illegal v4l2_mbus_framefmt code: %d\n", mf->code);
+               return -EINVAL;
+       }
+
+       ret = adv7175_write(sd, 0x7, val);
+
+       return ret;
+}
+
 static int adv7175_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
 {
        struct i2c_client *client = v4l2_get_subdevdata(sd);
@@ -324,6 +383,9 @@ static const struct v4l2_subdev_core_ops adv7175_core_ops = {
 static const struct v4l2_subdev_video_ops adv7175_video_ops = {
        .s_std_output = adv7175_s_std_output,
        .s_routing = adv7175_s_routing,
+       .s_mbus_fmt = adv7175_s_fmt,
+       .g_mbus_fmt = adv7175_g_fmt,
+       .enum_mbus_fmt  = adv7175_enum_fmt,
 };
 
 static const struct v4l2_subdev_ops adv7175_ops = {
index 7b89f00501b827efc52aee371eede35ef5d37b31..774715d2f84f33a52cc4b9fd98fbf667b2630abf 100644 (file)
@@ -249,7 +249,7 @@ static int atmel_isi_wait_status(struct atmel_isi *isi, int wait_reset)
        Videobuf operations
    ------------------------------------------------------------------*/
 static int queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
-                               unsigned int *nplanes, unsigned long sizes[],
+                               unsigned int *nplanes, unsigned int sizes[],
                                void *alloc_ctxs[])
 {
        struct soc_camera_device *icd = soc_camera_from_vb2q(vq);
@@ -341,7 +341,7 @@ static int buffer_prepare(struct vb2_buffer *vb)
 
                        /* Initialize the dma descriptor */
                        desc->p_fbd->fb_address =
-                                       vb2_dma_contig_plane_paddr(vb, 0);
+                                       vb2_dma_contig_plane_dma_addr(vb, 0);
                        desc->p_fbd->next_fbd_address = 0;
                        set_dma_ctrl(desc->p_fbd, ISI_DMA_CTRL_WB);
 
@@ -404,12 +404,13 @@ static void buffer_queue(struct vb2_buffer *vb)
 
        if (isi->active == NULL) {
                isi->active = buf;
-               start_dma(isi, buf);
+               if (vb2_is_streaming(vb->vb2_queue))
+                       start_dma(isi, buf);
        }
        spin_unlock_irqrestore(&isi->lock, flags);
 }
 
-static int start_streaming(struct vb2_queue *vq)
+static int start_streaming(struct vb2_queue *vq, unsigned int count)
 {
        struct soc_camera_device *icd = soc_camera_from_vb2q(vq);
        struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
@@ -431,17 +432,26 @@ static int start_streaming(struct vb2_queue *vq)
        ret = wait_event_interruptible(isi->vsync_wq,
                                       isi->state != ISI_STATE_IDLE);
        if (ret)
-               return ret;
+               goto err;
 
-       if (isi->state != ISI_STATE_READY)
-               return -EIO;
+       if (isi->state != ISI_STATE_READY) {
+               ret = -EIO;
+               goto err;
+       }
 
        spin_lock_irq(&isi->lock);
        isi->state = ISI_STATE_WAIT_SOF;
        isi_writel(isi, ISI_INTDIS, ISI_SR_VSYNC);
+       if (count)
+               start_dma(isi, isi->active);
        spin_unlock_irq(&isi->lock);
 
        return 0;
+err:
+       isi->active = NULL;
+       isi->sequence = 0;
+       INIT_LIST_HEAD(&isi->video_buffer_list);
+       return ret;
 }
 
 /* abort streaming and wait for last buffer */
index 5c7f2f7d980593795b999887b19522af42166845..bd22223f8d9f943a2a94fcf1aab1a4b625192f4d 100644 (file)
@@ -2,8 +2,8 @@ au0828-objs     := au0828-core.o au0828-i2c.o au0828-cards.o au0828-dvb.o au0828-vid
 
 obj-$(CONFIG_VIDEO_AU0828) += au0828.o
 
-EXTRA_CFLAGS += -Idrivers/media/common/tuners
-EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
-EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
+ccflags-y += -Idrivers/media/common/tuners
+ccflags-y += -Idrivers/media/dvb/dvb-core
+ccflags-y += -Idrivers/media/dvb/frontends
 
-EXTRA_CFLAGS += $(extra-cflags-y) $(extra-cflags-m)
+ccflags-y += $(extra-cflags-y) $(extra-cflags-m)
index f87204461cb41db609b97549250d80a468aeb4b9..859eabf57978ee44a7c3c38d91b12ebea6ae2b12 100644 (file)
@@ -229,7 +229,7 @@ static int bt819_status(struct v4l2_subdev *sd, u32 *pstatus, v4l2_std_id *pstd)
        if (pstd)
                *pstd = std;
        if (pstatus)
-               *pstatus = status;
+               *pstatus = res;
 
        v4l2_dbg(1, debug, sd, "get status %x\n", status);
        return 0;
index e415f6fc447c5905ffd87ac96e611a1c6bc9cf86..3f9a2b22d3d414533dfd73a640b22fe8dc6feaa3 100644 (file)
@@ -8,6 +8,6 @@ bttv-objs      :=      bttv-driver.o bttv-cards.o bttv-if.o \
 
 obj-$(CONFIG_VIDEO_BT848) += bttv.o
 
-EXTRA_CFLAGS += -Idrivers/media/video
-EXTRA_CFLAGS += -Idrivers/media/common/tuners
-EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
+ccflags-y += -Idrivers/media/video
+ccflags-y += -Idrivers/media/common/tuners
+ccflags-y += -Idrivers/media/dvb/dvb-core
index 5b15f63bf065cc8646753c5e1dc6f9c19d348da0..5939021d8eba4782cc983e99b658d0f370c93c0a 100644 (file)
@@ -25,6 +25,8 @@
 
 */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/delay.h>
 #include <linux/module.h>
 #include <linux/kmod.h>
@@ -2905,19 +2907,17 @@ void __devinit bttv_idcard(struct bttv *btv)
 
                if (type != -1) {
                        /* found it */
-                       printk(KERN_INFO "bttv%d: detected: %s [card=%d], "
-                              "PCI subsystem ID is %04x:%04x\n",
-                              btv->c.nr,cards[type].name,cards[type].cardnr,
-                              btv->cardid & 0xffff,
-                              (btv->cardid >> 16) & 0xffff);
+                       pr_info("%d: detected: %s [card=%d], PCI subsystem ID is %04x:%04x\n",
+                               btv->c.nr, cards[type].name, cards[type].cardnr,
+                               btv->cardid & 0xffff,
+                               (btv->cardid >> 16) & 0xffff);
                        btv->c.type = cards[type].cardnr;
                } else {
                        /* 404 */
-                       printk(KERN_INFO "bttv%d: subsystem: %04x:%04x (UNKNOWN)\n",
-                              btv->c.nr, btv->cardid & 0xffff,
-                              (btv->cardid >> 16) & 0xffff);
-                       printk(KERN_DEBUG "please mail id, board name and "
-                              "the correct card= insmod option to linux-media@vger.kernel.org\n");
+                       pr_info("%d: subsystem: %04x:%04x (UNKNOWN)\n",
+                               btv->c.nr, btv->cardid & 0xffff,
+                               (btv->cardid >> 16) & 0xffff);
+                       pr_debug("please mail id, board name and the correct card= insmod option to linux-media@vger.kernel.org\n");
                }
        }
 
@@ -2926,10 +2926,10 @@ void __devinit bttv_idcard(struct bttv *btv)
                btv->c.type=card[btv->c.nr];
 
        /* print which card config we are using */
-       printk(KERN_INFO "bttv%d: using: %s [card=%d,%s]\n",btv->c.nr,
-              bttv_tvcards[btv->c.type].name, btv->c.type,
-              card[btv->c.nr] < bttv_num_tvcards
-              ? "insmod option" : "autodetected");
+       pr_info("%d: using: %s [card=%d,%s]\n",
+               btv->c.nr, bttv_tvcards[btv->c.type].name, btv->c.type,
+               card[btv->c.nr] < bttv_num_tvcards
+               ? "insmod option" : "autodetected");
 
        /* overwrite gpio stuff ?? */
        if (UNSET == audioall && UNSET == audiomux[0])
@@ -2948,12 +2948,13 @@ void __devinit bttv_idcard(struct bttv *btv)
                }
        }
        bttv_tvcards[btv->c.type].gpiomask = (UNSET != gpiomask) ? gpiomask : gpiobits;
-       printk(KERN_INFO "bttv%d: gpio config override: mask=0x%x, mux=",
-              btv->c.nr,bttv_tvcards[btv->c.type].gpiomask);
+       pr_info("%d: gpio config override: mask=0x%x, mux=",
+               btv->c.nr, bttv_tvcards[btv->c.type].gpiomask);
        for (i = 0; i < ARRAY_SIZE(bttv_tvcards->gpiomux); i++) {
-               printk("%s0x%x", i ? "," : "", bttv_tvcards[btv->c.type].gpiomux[i]);
+               pr_cont("%s0x%x",
+                       i ? "," : "", bttv_tvcards[btv->c.type].gpiomux[i]);
        }
-       printk("\n");
+       pr_cont("\n");
 }
 
 /*
@@ -2974,8 +2975,8 @@ static void identify_by_eeprom(struct bttv *btv, unsigned char eeprom_data[256])
 
        if (-1 != type) {
                btv->c.type = type;
-               printk("bttv%d: detected by eeprom: %s [card=%d]\n",
-                      btv->c.nr, bttv_tvcards[btv->c.type].name, btv->c.type);
+               pr_info("%d: detected by eeprom: %s [card=%d]\n",
+                       btv->c.nr, bttv_tvcards[btv->c.type].name, btv->c.type);
        }
 }
 
@@ -3019,7 +3020,7 @@ static void flyvideo_gpio(struct bttv *btv)
                tuner_type = 3;  /* Philips SECAM(+PAL) FQ1216ME or FI1216MF */
                break;
        default:
-               printk(KERN_INFO "bttv%d: FlyVideo_gpio: unknown tuner type.\n", btv->c.nr);
+               pr_info("%d: FlyVideo_gpio: unknown tuner type\n", btv->c.nr);
                break;
        }
 
@@ -3036,13 +3037,13 @@ static void flyvideo_gpio(struct bttv *btv)
        if (is_capture_only)
                tuner_type = TUNER_ABSENT; /* No tuner present */
 
-       printk(KERN_INFO "bttv%d: FlyVideo Radio=%s RemoteControl=%s Tuner=%d gpio=0x%06x\n",
-               btv->c.nr, has_radio ? "yes" : "no ",
-               has_remote ? "yes" : "no ", tuner_type, gpio);
-       printk(KERN_INFO "bttv%d: FlyVideo  LR90=%s tda9821/tda9820=%s capture_only=%s\n",
-               btv->c.nr, is_lr90 ? "yes" : "no ",
-               has_tda9820_tda9821 ? "yes" : "no ",
-               is_capture_only ? "yes" : "no ");
+       pr_info("%d: FlyVideo Radio=%s RemoteControl=%s Tuner=%d gpio=0x%06x\n",
+               btv->c.nr, has_radio ? "yes" : "no",
+               has_remote ? "yes" : "no", tuner_type, gpio);
+       pr_info("%d: FlyVideo  LR90=%s tda9821/tda9820=%s capture_only=%s\n",
+               btv->c.nr, is_lr90 ? "yes" : "no",
+               has_tda9820_tda9821 ? "yes" : "no",
+               is_capture_only ? "yes" : "no");
 
        if (tuner_type != UNSET) /* only set if known tuner autodetected, else let insmod option through */
                btv->tuner_type = tuner_type;
@@ -3091,12 +3092,11 @@ static void miro_pinnacle_gpio(struct bttv *btv)
                        if (btv->c.type == BTTV_BOARD_PINNACLE)
                                btv->c.type = BTTV_BOARD_PINNACLEPRO;
                }
-               printk(KERN_INFO
-                      "bttv%d: miro: id=%d tuner=%d radio=%s stereo=%s\n",
-                      btv->c.nr, id+1, btv->tuner_type,
-                      !btv->has_radio ? "no" :
-                      (btv->has_matchbox ? "matchbox" : "fmtuner"),
-                      (-1 == msp) ? "no" : "yes");
+               pr_info("%d: miro: id=%d tuner=%d radio=%s stereo=%s\n",
+                       btv->c.nr, id+1, btv->tuner_type,
+                       !btv->has_radio ? "no" :
+                       (btv->has_matchbox ? "matchbox" : "fmtuner"),
+                       (-1 == msp) ? "no" : "yes");
        } else {
                /* new cards with microtune tuner */
                id = 63 - id;
@@ -3138,9 +3138,8 @@ static void miro_pinnacle_gpio(struct bttv *btv)
                }
                if (-1 != msp)
                        btv->c.type = BTTV_BOARD_PINNACLEPRO;
-               printk(KERN_INFO
-                      "bttv%d: pinnacle/mt: id=%d info=\"%s\" radio=%s\n",
-                      btv->c.nr, id, info, btv->has_radio ? "yes" : "no");
+               pr_info("%d: pinnacle/mt: id=%d info=\"%s\" radio=%s\n",
+                       btv->c.nr, id, info, btv->has_radio ? "yes" : "no");
                btv->tuner_type = TUNER_MT2032;
        }
 }
@@ -3202,7 +3201,7 @@ static void gvc1100_muxsel(struct bttv *btv, unsigned int input)
 
 static void init_lmlbt4x(struct bttv *btv)
 {
-       printk(KERN_DEBUG "LMLBT4x init\n");
+       pr_debug("LMLBT4x init\n");
        btwrite(0x000000, BT848_GPIO_REG_INP);
        gpio_inout(0xffffff, 0x0006C0);
        gpio_write(0x000000);
@@ -3246,7 +3245,7 @@ static void bttv_reset_audio(struct bttv *btv)
                return;
 
        if (bttv_debug)
-               printk("bttv%d: BT878A ARESET\n",btv->c.nr);
+               pr_debug("%d: BT878A ARESET\n", btv->c.nr);
        btwrite((1<<7), 0x058);
        udelay(10);
        btwrite(     0, 0x058);
@@ -3349,7 +3348,8 @@ void __devinit bttv_init_card2(struct bttv *btv)
        case BTTV_BOARD_MAGICTVIEW061:
                if (btv->cardid == 0x3002144f) {
                        btv->has_radio=1;
-                       printk("bttv%d: radio detected by subsystem id (CPH05x)\n",btv->c.nr);
+                       pr_info("%d: radio detected by subsystem id (CPH05x)\n",
+                               btv->c.nr);
                }
                break;
        case BTTV_BOARD_STB2:
@@ -3438,17 +3438,16 @@ void __devinit bttv_init_card2(struct bttv *btv)
                btv->tuner_type = tuner[btv->c.nr];
 
        if (btv->tuner_type == TUNER_ABSENT)
-               printk(KERN_INFO "bttv%d: tuner absent\n", btv->c.nr);
-       else if(btv->tuner_type == UNSET)
-               printk(KERN_WARNING "bttv%d: tuner type unset\n", btv->c.nr);
+               pr_info("%d: tuner absent\n", btv->c.nr);
+       else if (btv->tuner_type == UNSET)
+               pr_warn("%d: tuner type unset\n", btv->c.nr);
        else
-               printk(KERN_INFO "bttv%d: tuner type=%d\n", btv->c.nr,
-                      btv->tuner_type);
+               pr_info("%d: tuner type=%d\n", btv->c.nr, btv->tuner_type);
 
        if (autoload != UNSET) {
-               printk(KERN_WARNING "bttv%d: the autoload option is obsolete.\n", btv->c.nr);
-               printk(KERN_WARNING "bttv%d: use option msp3400, tda7432 or tvaudio to\n", btv->c.nr);
-               printk(KERN_WARNING "bttv%d: override which audio module should be used.\n", btv->c.nr);
+               pr_warn("%d: the autoload option is obsolete\n", btv->c.nr);
+               pr_warn("%d: use option msp3400, tda7432 or tvaudio to override which audio module should be used\n",
+                       btv->c.nr);
        }
 
        if (UNSET == btv->tuner_type)
@@ -3541,8 +3540,7 @@ void __devinit bttv_init_card2(struct bttv *btv)
        }
 
        default:
-               printk(KERN_WARNING "bttv%d: unknown audiodev value!\n",
-                       btv->c.nr);
+               pr_warn("%d: unknown audiodev value!\n", btv->c.nr);
                return;
        }
 
@@ -3585,8 +3583,7 @@ void __devinit bttv_init_card2(struct bttv *btv)
                return;
 
 no_audio:
-       printk(KERN_WARNING "bttv%d: audio absent, no audio device found!\n",
-                       btv->c.nr);
+       pr_warn("%d: audio absent, no audio device found!\n", btv->c.nr);
 }
 
 
@@ -3639,19 +3636,19 @@ static void modtec_eeprom(struct bttv *btv)
 {
        if( strncmp(&(eeprom_data[0x1e]),"Temic 4066 FY5",14) ==0) {
                btv->tuner_type=TUNER_TEMIC_4066FY5_PAL_I;
-               printk("bttv%d: Modtec: Tuner autodetected by eeprom: %s\n",
-                      btv->c.nr,&eeprom_data[0x1e]);
+               pr_info("%d: Modtec: Tuner autodetected by eeprom: %s\n",
+                       btv->c.nr, &eeprom_data[0x1e]);
        } else if (strncmp(&(eeprom_data[0x1e]),"Alps TSBB5",10) ==0) {
                btv->tuner_type=TUNER_ALPS_TSBB5_PAL_I;
-               printk("bttv%d: Modtec: Tuner autodetected by eeprom: %s\n",
-                      btv->c.nr,&eeprom_data[0x1e]);
+               pr_info("%d: Modtec: Tuner autodetected by eeprom: %s\n",
+                       btv->c.nr, &eeprom_data[0x1e]);
        } else if (strncmp(&(eeprom_data[0x1e]),"Philips FM1246",14) ==0) {
                btv->tuner_type=TUNER_PHILIPS_NTSC;
-               printk("bttv%d: Modtec: Tuner autodetected by eeprom: %s\n",
-                      btv->c.nr,&eeprom_data[0x1e]);
+               pr_info("%d: Modtec: Tuner autodetected by eeprom: %s\n",
+                       btv->c.nr, &eeprom_data[0x1e]);
        } else {
-               printk("bttv%d: Modtec: Unknown TunerString: %s\n",
-                      btv->c.nr,&eeprom_data[0x1e]);
+               pr_info("%d: Modtec: Unknown TunerString: %s\n",
+                       btv->c.nr, &eeprom_data[0x1e]);
        }
 }
 
@@ -3663,7 +3660,7 @@ static void __devinit hauppauge_eeprom(struct bttv *btv)
        btv->tuner_type = tv.tuner_type;
        btv->has_radio  = tv.has_radio;
 
-       printk("bttv%d: Hauppauge eeprom indicates model#%d\n",
+       pr_info("%d: Hauppauge eeprom indicates model#%d\n",
                btv->c.nr, tv.model);
 
        /*
@@ -3671,7 +3668,7 @@ static void __devinit hauppauge_eeprom(struct bttv *btv)
         * type based on model #.
         */
        if(tv.model == 64900) {
-               printk("bttv%d: Switching board type from %s to %s\n",
+               pr_info("%d: Switching board type from %s to %s\n",
                        btv->c.nr,
                        bttv_tvcards[btv->c.type].name,
                        bttv_tvcards[BTTV_BOARD_HAUPPAUGE_IMPACTVCB].name);
@@ -3698,8 +3695,7 @@ static int terratec_active_radio_upgrade(struct bttv *btv)
        freq=88000/62.5;
        tea5757_write(btv, 5 * freq + 0x358); /* write 0x1ed8 */
        if (0x1ed8 == tea5757_read(btv)) {
-               printk("bttv%d: Terratec Active Radio Upgrade found.\n",
-                      btv->c.nr);
+               pr_info("%d: Terratec Active Radio Upgrade found\n", btv->c.nr);
                btv->has_radio    = 1;
                btv->has_saa6588  = 1;
                btv->has_matchbox = 1;
@@ -3771,13 +3767,12 @@ static int __devinit pvr_boot(struct bttv *btv)
 
        rc = request_firmware(&fw_entry, "hcwamc.rbf", &btv->c.pci->dev);
        if (rc != 0) {
-               printk(KERN_WARNING "bttv%d: no altera firmware [via hotplug]\n",
-                      btv->c.nr);
+               pr_warn("%d: no altera firmware [via hotplug]\n", btv->c.nr);
                return rc;
        }
        rc = pvr_altera_load(btv, fw_entry->data, fw_entry->size);
-       printk(KERN_INFO "bttv%d: altera firmware upload %s\n",
-              btv->c.nr, (rc < 0) ? "failed" : "ok");
+       pr_info("%d: altera firmware upload %s\n",
+               btv->c.nr, (rc < 0) ? "failed" : "ok");
        release_firmware(fw_entry);
        return rc;
 }
@@ -3873,29 +3868,27 @@ static void __devinit osprey_eeprom(struct bttv *btv, const u8 ee[256])
                        break;
                default:
                        /* unknown...leave generic, but get serial # */
-                       printk(KERN_INFO "bttv%d: "
-                              "osprey eeprom: unknown card type 0x%04x\n",
-                              btv->c.nr, type);
+                       pr_info("%d: osprey eeprom: unknown card type 0x%04x\n",
+                               btv->c.nr, type);
                        break;
                }
                serial = get_unaligned_be32((__be32 *)(ee+6));
        }
 
-       printk(KERN_INFO "bttv%d: osprey eeprom: card=%d '%s' serial=%u\n",
-              btv->c.nr, cardid,
-              cardid>0 ? bttv_tvcards[cardid].name : "Unknown", serial);
+       pr_info("%d: osprey eeprom: card=%d '%s' serial=%u\n",
+               btv->c.nr, cardid,
+               cardid > 0 ? bttv_tvcards[cardid].name : "Unknown", serial);
 
        if (cardid<0 || btv->c.type == cardid)
                return;
 
        /* card type isn't set correctly */
        if (card[btv->c.nr] < bttv_num_tvcards) {
-               printk(KERN_WARNING "bttv%d: osprey eeprom: "
-                      "Not overriding user specified card type\n", btv->c.nr);
+               pr_warn("%d: osprey eeprom: Not overriding user specified card type\n",
+                       btv->c.nr);
        } else {
-               printk(KERN_INFO "bttv%d: osprey eeprom: "
-                      "Changing card type from %d to %d\n", btv->c.nr,
-                      btv->c.type, cardid);
+               pr_info("%d: osprey eeprom: Changing card type from %d to %d\n",
+                       btv->c.nr, btv->c.type, cardid);
                btv->c.type = cardid;
        }
 }
@@ -3938,14 +3931,14 @@ static void __devinit avermedia_eeprom(struct bttv *btv)
                if (tuner_format == 0x09)
                        tuner_type = TUNER_LG_NTSC_NEW_TAPC; /* TAPC-G702P */
 
-       printk(KERN_INFO "bttv%d: Avermedia eeprom[0x%02x%02x]: tuner=",
+       pr_info("%d: Avermedia eeprom[0x%02x%02x]: tuner=",
                btv->c.nr, eeprom_data[0x41], eeprom_data[0x42]);
        if (tuner_type) {
                btv->tuner_type = tuner_type;
-               printk(KERN_CONT "%d", tuner_type);
+               pr_cont("%d", tuner_type);
        } else
-               printk(KERN_CONT "Unknown type");
-       printk(KERN_CONT " radio:%s remote control:%s\n",
+               pr_cont("Unknown type");
+       pr_cont(" radio:%s remote control:%s\n",
               tuner_tv_fm     ? "yes" : "no",
               btv->has_remote ? "yes" : "no");
 }
@@ -3993,8 +3986,8 @@ static void __devinit boot_msp34xx(struct bttv *btv, int pin)
        if (bttv_gpio)
                bttv_gpio_tracking(btv,"msp34xx");
        if (bttv_verbose)
-               printk(KERN_INFO "bttv%d: Hauppauge/Voodoo msp34xx: reset line "
-                      "init [%d]\n", btv->c.nr, pin);
+               pr_info("%d: Hauppauge/Voodoo msp34xx: reset line init [%d]\n",
+                       btv->c.nr, pin);
 }
 
 /* ----------------------------------------------------------------------- */
@@ -4034,7 +4027,7 @@ static void __devinit init_PXC200(struct bttv *btv)
        btwrite(BT848_ADC_RESERVED|BT848_ADC_AGC_EN, BT848_ADC);
 
        /*      Initialise MAX517 DAC */
-       printk(KERN_INFO "Setting DAC reference voltage level ...\n");
+       pr_info("Setting DAC reference voltage level ...\n");
        bttv_I2CWrite(btv,0x5E,0,0x80,1);
 
        /*      Initialise 12C508 PIC */
@@ -4043,7 +4036,7 @@ static void __devinit init_PXC200(struct bttv *btv)
         *      argument so the numbers are different */
 
 
-       printk(KERN_INFO "Initialising 12C508 PIC chip ...\n");
+       pr_info("Initialising 12C508 PIC chip ...\n");
 
        /* First of all, enable the clock line. This is used in the PXC200-F */
        val = btread(BT848_GPIO_DMA_CTL);
@@ -4062,13 +4055,12 @@ static void __devinit init_PXC200(struct bttv *btv)
        for (i = 0; i < ARRAY_SIZE(vals); i++) {
                tmp=bttv_I2CWrite(btv,0x1E,0,vals[i],1);
                if (tmp != -1) {
-                       printk(KERN_INFO
-                              "I2C Write(%2.2x) = %i\nI2C Read () = %2.2x\n\n",
+                       pr_info("I2C Write(%2.2x) = %i\nI2C Read () = %2.2x\n\n",
                               vals[i],tmp,bttv_I2CRead(btv,0x1F,NULL));
                }
        }
 
-       printk(KERN_INFO "PXC200 Initialised.\n");
+       pr_info("PXC200 Initialised\n");
 }
 
 
@@ -4107,8 +4099,7 @@ init_RTV24 (struct bttv *btv)
        uint32_t dataRead = 0;
        long watchdog_value = 0x0E;
 
-       printk (KERN_INFO
-               "bttv%d: Adlink RTV-24 initialisation in progress ...\n",
+       pr_info("%d: Adlink RTV-24 initialisation in progress ...\n",
                btv->c.nr);
 
        btwrite (0x00c3feff, BT848_GPIO_OUT_EN);
@@ -4122,8 +4113,7 @@ init_RTV24 (struct bttv *btv)
        dataRead = btread (BT848_GPIO_DATA);
 
        if ((((dataRead >> 18) & 0x01) != 0) || (((dataRead >> 19) & 0x01) != 1)) {
-               printk (KERN_INFO
-                       "bttv%d: Adlink RTV-24 initialisation(1) ERROR_CPLD_Check_Failed (read %d)\n",
+               pr_info("%d: Adlink RTV-24 initialisation(1) ERROR_CPLD_Check_Failed (read %d)\n",
                        btv->c.nr, dataRead);
        }
 
@@ -4136,15 +4126,13 @@ init_RTV24 (struct bttv *btv)
        dataRead = btread (BT848_GPIO_DATA);
 
        if ((((dataRead >> 18) & 0x01) != 0) || (((dataRead >> 19) & 0x01) != 0)) {
-               printk (KERN_INFO
-                       "bttv%d: Adlink RTV-24 initialisation(2) ERROR_CPLD_Check_Failed (read %d)\n",
+               pr_info("%d: Adlink RTV-24 initialisation(2) ERROR_CPLD_Check_Failed (read %d)\n",
                        btv->c.nr, dataRead);
 
                return;
        }
 
-       printk (KERN_INFO
-               "bttv%d: Adlink RTV-24 initialisation complete.\n", btv->c.nr);
+       pr_info("%d: Adlink RTV-24 initialisation complete\n", btv->c.nr);
 }
 
 
@@ -4261,22 +4249,25 @@ static int tea5757_read(struct bttv *btv)
        while (bus_in(btv,btv->mbox_data) && time_before(jiffies, timeout))
                schedule();
        if (bus_in(btv,btv->mbox_data)) {
-               printk(KERN_WARNING "bttv%d: tea5757: read timeout\n",btv->c.nr);
+               pr_warn("%d: tea5757: read timeout\n", btv->c.nr);
                return -1;
        }
 
-       dprintk("bttv%d: tea5757:",btv->c.nr);
+       dprintk("%d: tea5757:", btv->c.nr);
        for (i = 0; i < 24; i++) {
                udelay(5);
                bus_high(btv,btv->mbox_clk);
                udelay(5);
-               dprintk("%c",(bus_in(btv,btv->mbox_most) == 0)?'T':'-');
+               dprintk_cont("%c",
+                            bus_in(btv, btv->mbox_most) == 0 ? 'T' : '-');
                bus_low(btv,btv->mbox_clk);
                value <<= 1;
                value |= (bus_in(btv,btv->mbox_data) == 0)?0:1;  /* MSB first */
-               dprintk("%c", (bus_in(btv,btv->mbox_most) == 0)?'S':'M');
+               dprintk_cont("%c",
+                            bus_in(btv, btv->mbox_most) == 0 ? 'S' : 'M');
        }
-       dprintk("\nbttv%d: tea5757: read 0x%X\n", btv->c.nr, value);
+       dprintk_cont("\n");
+       dprintk("%d: tea5757: read 0x%X\n", btv->c.nr, value);
        return value;
 }
 
@@ -4295,7 +4286,7 @@ static int tea5757_write(struct bttv *btv, int value)
        if (bttv_gpio)
                bttv_gpio_tracking(btv,"tea5757 write");
 
-       dprintk("bttv%d: tea5757: write 0x%X\n", btv->c.nr, value);
+       dprintk("%d: tea5757: write 0x%X\n", btv->c.nr, value);
        bus_low(btv,btv->mbox_clk);
        bus_high(btv,btv->mbox_we);
        for (i = 0; i < 25; i++) {
@@ -4547,7 +4538,7 @@ static void picolo_tetra_init(struct bttv *btv)
 static void picolo_tetra_muxsel (struct bttv* btv, unsigned int input)
 {
 
-       dprintk (KERN_DEBUG "bttv%d : picolo_tetra_muxsel =>  input = %d\n",btv->c.nr,input);
+       dprintk("%d : picolo_tetra_muxsel =>  input = %d\n", btv->c.nr, input);
        /*Just set the right path in the analog multiplexers : channel 1 -> 4 ==> Analog Mux ==> MUX0*/
        /*GPIO[20]&GPIO[21] used to choose the right input*/
        btwrite (input<<20,BT848_GPIO_DATA);
@@ -4592,7 +4583,7 @@ static void ivc120_muxsel(struct bttv *btv, unsigned int input)
        int key = input % 4;
        int matrix = input / 4;
 
-       dprintk("bttv%d: ivc120_muxsel: Input - %02d | TDA - %02d | In - %02d\n",
+       dprintk("%d: ivc120_muxsel: Input - %02d | TDA - %02d | In - %02d\n",
                btv->c.nr, input, matrix, key);
 
        /* Handles the input selection on the TDA8540's */
@@ -4649,15 +4640,17 @@ static void PXC200_muxsel(struct bttv *btv, unsigned int input)
        buf[1]=0;
        rc=bttv_I2CWrite(btv,(PX_I2C_PIC<<1),buf[0],buf[1],1);
        if (rc) {
-         printk(KERN_DEBUG "bttv%d: PXC200_muxsel: pic cfg write failed:%d\n", btv->c.nr,rc);
+               pr_debug("%d: PXC200_muxsel: pic cfg write failed:%d\n",
+                        btv->c.nr, rc);
          /* not PXC ? do nothing */
-         return;
+               return;
        }
 
        rc=bttv_I2CRead(btv,(PX_I2C_PIC<<1),NULL);
        if (!(rc & PX_CFG_PXC200F)) {
-         printk(KERN_DEBUG "bttv%d: PXC200_muxsel: not PXC200F rc:%d \n", btv->c.nr,rc);
-         return;
+               pr_debug("%d: PXC200_muxsel: not PXC200F rc:%d\n",
+                        btv->c.nr, rc);
+               return;
        }
 
 
@@ -4696,7 +4689,7 @@ static void PXC200_muxsel(struct bttv *btv, unsigned int input)
        else /* older device */
          btand(~BT848_IFORM_MUXSEL,BT848_IFORM);
 
-       printk(KERN_DEBUG "bttv%d: setting input channel to:%d\n", btv->c.nr,(int)mux);
+       pr_debug("%d: setting input channel to:%d\n", btv->c.nr, (int)mux);
 }
 
 static void phytec_muxsel(struct bttv *btv, unsigned int input)
@@ -4847,29 +4840,27 @@ void __init bttv_check_chipset(void)
 
        /* print warnings about any quirks found */
        if (triton1)
-               printk(KERN_INFO "bttv: Host bridge needs ETBF enabled.\n");
+               pr_info("Host bridge needs ETBF enabled\n");
        if (vsfx)
-               printk(KERN_INFO "bttv: Host bridge needs VSFX enabled.\n");
+               pr_info("Host bridge needs VSFX enabled\n");
        if (pcipci_fail) {
-               printk(KERN_INFO "bttv: bttv and your chipset may not work "
-                                                       "together.\n");
+               pr_info("bttv and your chipset may not work together\n");
                if (!no_overlay) {
-                       printk(KERN_INFO "bttv: overlay will be disabled.\n");
+                       pr_info("overlay will be disabled\n");
                        no_overlay = 1;
                } else {
-                       printk(KERN_INFO "bttv: overlay forced. Use this "
-                                               "option at your own risk.\n");
+                       pr_info("overlay forced. Use this option at your own risk.\n");
                }
        }
        if (UNSET != latency)
-               printk(KERN_INFO "bttv: pci latency fixup [%d]\n",latency);
+               pr_info("pci latency fixup [%d]\n", latency);
        while ((dev = pci_get_device(PCI_VENDOR_ID_INTEL,
                                      PCI_DEVICE_ID_INTEL_82441, dev))) {
                unsigned char b;
                pci_read_config_byte(dev, 0x53, &b);
                if (bttv_debug)
-                       printk(KERN_INFO "bttv: Host bridge: 82441FX Natoma, "
-                              "bufcon=0x%02x\n",b);
+                       pr_info("Host bridge: 82441FX Natoma, bufcon=0x%02x\n",
+                               b);
        }
 }
 
@@ -4882,12 +4873,13 @@ int __devinit bttv_handle_chipset(struct bttv *btv)
 
        if (bttv_verbose) {
                if (triton1)
-                       printk(KERN_INFO "bttv%d: enabling ETBF (430FX/VP3 compatibilty)\n",btv->c.nr);
+                       pr_info("%d: enabling ETBF (430FX/VP3 compatibility)\n",
+                               btv->c.nr);
                if (vsfx && btv->id >= 878)
-                       printk(KERN_INFO "bttv%d: enabling VSFX\n",btv->c.nr);
+                       pr_info("%d: enabling VSFX\n", btv->c.nr);
                if (UNSET != latency)
-                       printk(KERN_INFO "bttv%d: setting pci timer to %d\n",
-                              btv->c.nr,latency);
+                       pr_info("%d: setting pci timer to %d\n",
+                               btv->c.nr, latency);
        }
 
        if (btv->id < 878) {
index 14444de67d5e6d5ab8c618886529815eadf090cd..3dd06607aec2a0457ec4b75a36463162ab15b6e4 100644 (file)
@@ -34,6 +34,8 @@
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/delay.h>
@@ -942,8 +944,8 @@ static
 void free_btres_lock(struct bttv *btv, struct bttv_fh *fh, int bits)
 {
        if ((fh->resources & bits) != bits) {
-               /* trying to free ressources not allocated by us ... */
-               printk("bttv: BUG! (btres)\n");
+               /* trying to free resources not allocated by us ... */
+               pr_err("BUG! (btres)\n");
        }
        fh->resources  &= ~bits;
        btv->resources &= ~bits;
@@ -1000,7 +1002,7 @@ static void set_pll(struct bttv *btv)
                return;
 
        if (btv->pll.pll_ofreq == btv->pll.pll_current) {
-               dprintk("bttv%d: PLL: no change required\n",btv->c.nr);
+               dprintk("%d: PLL: no change required\n", btv->c.nr);
                return;
        }
 
@@ -1008,21 +1010,23 @@ static void set_pll(struct bttv *btv)
                /* no PLL needed */
                if (btv->pll.pll_current == 0)
                        return;
-               bttv_printk(KERN_INFO "bttv%d: PLL can sleep, using XTAL (%d).\n",
-                       btv->c.nr,btv->pll.pll_ifreq);
+               if (bttv_verbose)
+                       pr_info("%d: PLL can sleep, using XTAL (%d)\n",
+                               btv->c.nr, btv->pll.pll_ifreq);
                btwrite(0x00,BT848_TGCTRL);
                btwrite(0x00,BT848_PLL_XCI);
                btv->pll.pll_current = 0;
                return;
        }
 
-       bttv_printk(KERN_INFO "bttv%d: PLL: %d => %d ",btv->c.nr,
-               btv->pll.pll_ifreq, btv->pll.pll_ofreq);
+       if (bttv_verbose)
+               pr_info("%d: Setting PLL: %d => %d (needs up to 100ms)\n",
+                       btv->c.nr,
+                       btv->pll.pll_ifreq, btv->pll.pll_ofreq);
        set_pll_freq(btv, btv->pll.pll_ifreq, btv->pll.pll_ofreq);
 
        for (i=0; i<10; i++) {
                /*  Let other people run while the PLL stabilizes */
-               bttv_printk(".");
                msleep(10);
 
                if (btread(BT848_DSTATUS) & BT848_DSTATUS_PLOCK) {
@@ -1030,12 +1034,14 @@ static void set_pll(struct bttv *btv)
                } else {
                        btwrite(0x08,BT848_TGCTRL);
                        btv->pll.pll_current = btv->pll.pll_ofreq;
-                       bttv_printk(" ok\n");
+                       if (bttv_verbose)
+                               pr_info("PLL set ok\n");
                        return;
                }
        }
        btv->pll.pll_current = -1;
-       bttv_printk("failed\n");
+       if (bttv_verbose)
+               pr_info("Setting PLL failed\n");
        return;
 }
 
@@ -1047,7 +1053,7 @@ static void bt848A_set_timing(struct bttv *btv)
        int fsc       = bttv_tvnorms[btv->tvnorm].Fsc;
 
        if (btv->input == btv->dig) {
-               dprintk("bttv%d: load digital timing table (table_idx=%d)\n",
+               dprintk("%d: load digital timing table (table_idx=%d)\n",
                        btv->c.nr,table_idx);
 
                /* timing change...reset timing generator address */
@@ -1076,7 +1082,7 @@ static void bt848_bright(struct bttv *btv, int bright)
 {
        int value;
 
-       // printk("bttv: set bright: %d\n",bright); // DEBUG
+       // printk("set bright: %d\n", bright); // DEBUG
        btv->bright = bright;
 
        /* We want -128 to 127 we get 0-65535 */
@@ -1150,8 +1156,7 @@ video_mux(struct bttv *btv, unsigned int input)
        }
        mux = bttv_muxsel(btv, input);
        btaor(mux<<5, ~(3<<5), BT848_IFORM);
-       dprintk(KERN_DEBUG "bttv%d: video mux: input=%d mux=%d\n",
-               btv->c.nr,input,mux);
+       dprintk("%d: video mux: input=%d mux=%d\n", btv->c.nr, input, mux);
 
        /* card specific hook */
        if(bttv_tvcards[btv->c.type].muxsel_hook)
@@ -1440,7 +1445,7 @@ static void bttv_reinit_bt848(struct bttv *btv)
        unsigned long flags;
 
        if (bttv_verbose)
-               printk(KERN_INFO "bttv%d: reset, reinitialize\n",btv->c.nr);
+               pr_info("%d: reset, reinitialize\n", btv->c.nr);
        spin_lock_irqsave(&btv->s_lock,flags);
        btv->errors=0;
        bttv_set_dma(btv,0);
@@ -1622,8 +1627,8 @@ void bttv_gpio_tracking(struct bttv *btv, char *comment)
        unsigned int outbits, data;
        outbits = btread(BT848_GPIO_OUT_EN);
        data    = btread(BT848_GPIO_DATA);
-       printk(KERN_DEBUG "bttv%d: gpio: en=%08x, out=%08x in=%08x [%s]\n",
-              btv->c.nr,outbits,data & outbits, data & ~outbits, comment);
+       pr_debug("%d: gpio: en=%08x, out=%08x in=%08x [%s]\n",
+                btv->c.nr, outbits, data & outbits, data & ~outbits, comment);
 }
 
 static void bttv_field_count(struct bttv *btv)
@@ -1668,7 +1673,7 @@ bttv_switch_overlay(struct bttv *btv, struct bttv_fh *fh,
        unsigned long flags;
        int retval = 0;
 
-       dprintk("switch_overlay: enter [new=%p]\n",new);
+       dprintk("switch_overlay: enter [new=%p]\n", new);
        if (new)
                new->vb.state = VIDEOBUF_DONE;
        spin_lock_irqsave(&btv->s_lock,flags);
@@ -1678,7 +1683,8 @@ bttv_switch_overlay(struct bttv *btv, struct bttv_fh *fh,
        bttv_set_dma(btv, 0x03);
        spin_unlock_irqrestore(&btv->s_lock,flags);
        if (NULL != old) {
-               dprintk("switch_overlay: old=%p state is %d\n",old,old->vb.state);
+               dprintk("switch_overlay: old=%p state is %d\n",
+                       old, old->vb.state);
                bttv_dma_free(&fh->cap,btv, old);
                kfree(old);
        }
@@ -2029,11 +2035,11 @@ static int bttv_log_status(struct file *file, void *f)
        struct bttv_fh *fh  = f;
        struct bttv *btv = fh->btv;
 
-       printk(KERN_INFO "bttv%d: ========  START STATUS CARD #%d  ========\n",
-                       btv->c.nr, btv->c.nr);
+       pr_info("%d: ========  START STATUS CARD #%d  ========\n",
+               btv->c.nr, btv->c.nr);
        bttv_call_all(btv, core, log_status);
-       printk(KERN_INFO "bttv%d: ========  END STATUS CARD   #%d  ========\n",
-                       btv->c.nr, btv->c.nr);
+       pr_info("%d: ========  END STATUS CARD   #%d  ========\n",
+               btv->c.nr, btv->c.nr);
        return 0;
 }
 
@@ -2598,7 +2604,7 @@ static int bttv_s_fmt_vid_overlay(struct file *file, void *priv,
        struct bttv *btv = fh->btv;
 
        if (no_overlay > 0) {
-               printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
+               pr_err("V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
                return -EINVAL;
        }
 
@@ -2673,7 +2679,7 @@ static int bttv_enum_fmt_vid_overlay(struct file *file, void  *priv,
        int rc;
 
        if (no_overlay > 0) {
-               printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
+               pr_err("V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
                return -EINVAL;
        }
 
@@ -2714,7 +2720,7 @@ static int bttv_overlay(struct file *file, void *f, unsigned int on)
                        return -EINVAL;
                }
                if (unlikely(!fh->ov.setup_ok)) {
-                       dprintk("bttv%d: overlay: !setup_ok\n", btv->c.nr);
+                       dprintk("%d: overlay: !setup_ok\n", btv->c.nr);
                        retval = -EINVAL;
                }
                if (retval)
@@ -3091,8 +3097,8 @@ static ssize_t bttv_read(struct file *file, char __user *data,
 
        if (fh->btv->errors)
                bttv_reinit_bt848(fh->btv);
-       dprintk("bttv%d: read count=%d type=%s\n",
-               fh->btv->c.nr,(int)count,v4l2_type_names[fh->type]);
+       dprintk("%d: read count=%d type=%s\n",
+               fh->btv->c.nr, (int)count, v4l2_type_names[fh->type]);
 
        switch (fh->type) {
        case V4L2_BUF_TYPE_VIDEO_CAPTURE:
@@ -3174,7 +3180,7 @@ static int bttv_open(struct file *file)
        struct bttv_fh *fh;
        enum v4l2_buf_type type = 0;
 
-       dprintk(KERN_DEBUG "bttv: open dev=%s\n", video_device_node_name(vdev));
+       dprintk("open dev=%s\n", video_device_node_name(vdev));
 
        if (vdev->vfl_type == VFL_TYPE_GRABBER) {
                type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
@@ -3185,8 +3191,8 @@ static int bttv_open(struct file *file)
                return -ENODEV;
        }
 
-       dprintk(KERN_DEBUG "bttv%d: open called (type=%s)\n",
-               btv->c.nr,v4l2_type_names[type]);
+       dprintk("%d: open called (type=%s)\n",
+               btv->c.nr, v4l2_type_names[type]);
 
        /* allocate per filehandle data */
        fh = kmalloc(sizeof(*fh), GFP_KERNEL);
@@ -3288,7 +3294,7 @@ bttv_mmap(struct file *file, struct vm_area_struct *vma)
 {
        struct bttv_fh *fh = file->private_data;
 
-       dprintk("bttv%d: mmap type=%s 0x%lx+%ld\n",
+       dprintk("%d: mmap type=%s 0x%lx+%ld\n",
                fh->btv->c.nr, v4l2_type_names[fh->type],
                vma->vm_start, vma->vm_end - vma->vm_start);
        return videobuf_mmap_mapper(bttv_queue(fh),vma);
@@ -3370,9 +3376,9 @@ static int radio_open(struct file *file)
        struct bttv *btv = video_drvdata(file);
        struct bttv_fh *fh;
 
-       dprintk("bttv: open dev=%s\n", video_device_node_name(vdev));
+       dprintk("open dev=%s\n", video_device_node_name(vdev));
 
-       dprintk("bttv%d: open called (radio)\n",btv->c.nr);
+       dprintk("%d: open called (radio)\n", btv->c.nr);
 
        /* allocate per filehandle data */
        fh = kmalloc(sizeof(*fh), GFP_KERNEL);
@@ -3616,12 +3622,12 @@ static int bttv_risc_decode(u32 risc)
        };
        int i;
 
-       printk("0x%08x [ %s", risc,
+       pr_cont("0x%08x [ %s", risc,
               instr[risc >> 28] ? instr[risc >> 28] : "INVALID");
        for (i = ARRAY_SIZE(bits)-1; i >= 0; i--)
                if (risc & (1 << (i + 12)))
-                       printk(" %s",bits[i]);
-       printk(" count=%d ]\n", risc & 0xfff);
+                       pr_cont(" %s", bits[i]);
+       pr_cont(" count=%d ]\n", risc & 0xfff);
        return incr[risc >> 28] ? incr[risc >> 28] : 1;
 }
 
@@ -3630,16 +3636,18 @@ static void bttv_risc_disasm(struct bttv *btv,
 {
        unsigned int i,j,n;
 
-       printk("%s: risc disasm: %p [dma=0x%08lx]\n",
-              btv->c.v4l2_dev.name, risc->cpu, (unsigned long)risc->dma);
+       pr_info("%s: risc disasm: %p [dma=0x%08lx]\n",
+               btv->c.v4l2_dev.name, risc->cpu, (unsigned long)risc->dma);
        for (i = 0; i < (risc->size >> 2); i += n) {
-               printk("%s:   0x%lx: ", btv->c.v4l2_dev.name,
-                      (unsigned long)(risc->dma + (i<<2)));
+               pr_info("%s:   0x%lx: ",
+                       btv->c.v4l2_dev.name,
+                       (unsigned long)(risc->dma + (i<<2)));
                n = bttv_risc_decode(le32_to_cpu(risc->cpu[i]));
                for (j = 1; j < n; j++)
-                       printk("%s:   0x%lx: 0x%08x [ arg #%d ]\n",
-                              btv->c.v4l2_dev.name, (unsigned long)(risc->dma + ((i+j)<<2)),
-                              risc->cpu[i+j], j);
+                       pr_info("%s:   0x%lx: 0x%08x [ arg #%d ]\n",
+                               btv->c.v4l2_dev.name,
+                               (unsigned long)(risc->dma + ((i+j)<<2)),
+                               risc->cpu[i+j], j);
                if (0 == risc->cpu[i])
                        break;
        }
@@ -3647,17 +3655,18 @@ static void bttv_risc_disasm(struct bttv *btv,
 
 static void bttv_print_riscaddr(struct bttv *btv)
 {
-       printk("  main: %08Lx\n",
-              (unsigned long long)btv->main.dma);
-       printk("  vbi : o=%08Lx e=%08Lx\n",
-              btv->cvbi ? (unsigned long long)btv->cvbi->top.dma : 0,
-              btv->cvbi ? (unsigned long long)btv->cvbi->bottom.dma : 0);
-       printk("  cap : o=%08Lx e=%08Lx\n",
-              btv->curr.top    ? (unsigned long long)btv->curr.top->top.dma : 0,
-              btv->curr.bottom ? (unsigned long long)btv->curr.bottom->bottom.dma : 0);
-       printk("  scr : o=%08Lx e=%08Lx\n",
-              btv->screen ? (unsigned long long)btv->screen->top.dma : 0,
-              btv->screen ? (unsigned long long)btv->screen->bottom.dma : 0);
+       pr_info("  main: %08llx\n", (unsigned long long)btv->main.dma);
+       pr_info("  vbi : o=%08llx e=%08llx\n",
+               btv->cvbi ? (unsigned long long)btv->cvbi->top.dma : 0,
+               btv->cvbi ? (unsigned long long)btv->cvbi->bottom.dma : 0);
+       pr_info("  cap : o=%08llx e=%08llx\n",
+               btv->curr.top
+               ? (unsigned long long)btv->curr.top->top.dma : 0,
+               btv->curr.bottom
+               ? (unsigned long long)btv->curr.bottom->bottom.dma : 0);
+       pr_info("  scr : o=%08llx e=%08llx\n",
+               btv->screen ? (unsigned long long)btv->screen->top.dma : 0,
+               btv->screen ? (unsigned long long)btv->screen->bottom.dma : 0);
        bttv_risc_disasm(btv, &btv->main);
 }
 
@@ -3690,34 +3699,34 @@ static void bttv_print_irqbits(u32 print, u32 mark)
 {
        unsigned int i;
 
-       printk("bits:");
+       pr_cont("bits:");
        for (i = 0; i < ARRAY_SIZE(irq_name); i++) {
                if (print & (1 << i))
-                       printk(" %s",irq_name[i]);
+                       pr_cont(" %s", irq_name[i]);
                if (mark & (1 << i))
-                       printk("*");
+                       pr_cont("*");
        }
 }
 
 static void bttv_irq_debug_low_latency(struct bttv *btv, u32 rc)
 {
-       printk("bttv%d: irq: skipped frame [main=%lx,o_vbi=%lx,o_field=%lx,rc=%lx]\n",
-              btv->c.nr,
-              (unsigned long)btv->main.dma,
-              (unsigned long)le32_to_cpu(btv->main.cpu[RISC_SLOT_O_VBI+1]),
-              (unsigned long)le32_to_cpu(btv->main.cpu[RISC_SLOT_O_FIELD+1]),
-              (unsigned long)rc);
+       pr_warn("%d: irq: skipped frame [main=%lx,o_vbi=%lx,o_field=%lx,rc=%lx]\n",
+               btv->c.nr,
+               (unsigned long)btv->main.dma,
+               (unsigned long)le32_to_cpu(btv->main.cpu[RISC_SLOT_O_VBI+1]),
+               (unsigned long)le32_to_cpu(btv->main.cpu[RISC_SLOT_O_FIELD+1]),
+               (unsigned long)rc);
 
        if (0 == (btread(BT848_DSTATUS) & BT848_DSTATUS_HLOC)) {
-               printk("bttv%d: Oh, there (temporarely?) is no input signal. "
-                      "Ok, then this is harmless, don't worry ;)\n",
-                      btv->c.nr);
+               pr_notice("%d: Oh, there (temporarily?) is no input signal. "
+                         "Ok, then this is harmless, don't worry ;)\n",
+                         btv->c.nr);
                return;
        }
-       printk("bttv%d: Uhm. Looks like we have unusual high IRQ latencies.\n",
-              btv->c.nr);
-       printk("bttv%d: Lets try to catch the culpit red-handed ...\n",
-              btv->c.nr);
+       pr_notice("%d: Uhm. Looks like we have unusual high IRQ latencies\n",
+                 btv->c.nr);
+       pr_notice("%d: Lets try to catch the culpit red-handed ...\n",
+                 btv->c.nr);
        dump_stack();
 }
 
@@ -3798,9 +3807,9 @@ bttv_irq_next_video(struct bttv *btv, struct bttv_buffer_set *set)
                }
        }
 
-       dprintk("bttv%d: next set: top=%p bottom=%p [screen=%p,irq=%d,%d]\n",
-               btv->c.nr,set->top, set->bottom,
-               btv->screen,set->frame_irq,set->top_irq);
+       dprintk("%d: next set: top=%p bottom=%p [screen=%p,irq=%d,%d]\n",
+               btv->c.nr, set->top, set->bottom,
+               btv->screen, set->frame_irq, set->top_irq);
        return 0;
 }
 
@@ -3815,7 +3824,8 @@ bttv_irq_wakeup_video(struct bttv *btv, struct bttv_buffer_set *wakeup,
        if (wakeup->top == wakeup->bottom) {
                if (NULL != wakeup->top && curr->top != wakeup->top) {
                        if (irq_debug > 1)
-                               printk("bttv%d: wakeup: both=%p\n",btv->c.nr,wakeup->top);
+                               pr_debug("%d: wakeup: both=%p\n",
+                                        btv->c.nr, wakeup->top);
                        wakeup->top->vb.ts = ts;
                        wakeup->top->vb.field_count = btv->field_count;
                        wakeup->top->vb.state = state;
@@ -3824,7 +3834,8 @@ bttv_irq_wakeup_video(struct bttv *btv, struct bttv_buffer_set *wakeup,
        } else {
                if (NULL != wakeup->top && curr->top != wakeup->top) {
                        if (irq_debug > 1)
-                               printk("bttv%d: wakeup: top=%p\n",btv->c.nr,wakeup->top);
+                               pr_debug("%d: wakeup: top=%p\n",
+                                        btv->c.nr, wakeup->top);
                        wakeup->top->vb.ts = ts;
                        wakeup->top->vb.field_count = btv->field_count;
                        wakeup->top->vb.state = state;
@@ -3832,7 +3843,8 @@ bttv_irq_wakeup_video(struct bttv *btv, struct bttv_buffer_set *wakeup,
                }
                if (NULL != wakeup->bottom && curr->bottom != wakeup->bottom) {
                        if (irq_debug > 1)
-                               printk("bttv%d: wakeup: bottom=%p\n",btv->c.nr,wakeup->bottom);
+                               pr_debug("%d: wakeup: bottom=%p\n",
+                                        btv->c.nr, wakeup->bottom);
                        wakeup->bottom->vb.ts = ts;
                        wakeup->bottom->vb.field_count = btv->field_count;
                        wakeup->bottom->vb.state = state;
@@ -3866,11 +3878,11 @@ static void bttv_irq_timeout(unsigned long data)
        unsigned long flags;
 
        if (bttv_verbose) {
-               printk(KERN_INFO "bttv%d: timeout: drop=%d irq=%d/%d, risc=%08x, ",
-                      btv->c.nr, btv->framedrop, btv->irq_me, btv->irq_total,
-                      btread(BT848_RISC_COUNT));
+               pr_info("%d: timeout: drop=%d irq=%d/%d, risc=%08x, ",
+                       btv->c.nr, btv->framedrop, btv->irq_me, btv->irq_total,
+                       btread(BT848_RISC_COUNT));
                bttv_print_irqbits(btread(BT848_INT_STAT),0);
-               printk("\n");
+               pr_cont("\n");
        }
 
        spin_lock_irqsave(&btv->s_lock,flags);
@@ -4033,21 +4045,23 @@ static irqreturn_t bttv_irq(int irq, void *dev_id)
                dstat=btread(BT848_DSTATUS);
 
                if (irq_debug) {
-                       printk(KERN_DEBUG "bttv%d: irq loop=%d fc=%d "
-                              "riscs=%x, riscc=%08x, ",
-                              btv->c.nr, count, btv->field_count,
-                              stat>>28, btread(BT848_RISC_COUNT));
+                       pr_debug("%d: irq loop=%d fc=%d riscs=%x, riscc=%08x, ",
+                                btv->c.nr, count, btv->field_count,
+                                stat>>28, btread(BT848_RISC_COUNT));
                        bttv_print_irqbits(stat,astat);
                        if (stat & BT848_INT_HLOCK)
-                               printk("   HLOC => %s", (dstat & BT848_DSTATUS_HLOC)
-                                      ? "yes" : "no");
+                               pr_cont("   HLOC => %s",
+                                       dstat & BT848_DSTATUS_HLOC
+                                       ? "yes" : "no");
                        if (stat & BT848_INT_VPRES)
-                               printk("   PRES => %s", (dstat & BT848_DSTATUS_PRES)
-                                      ? "yes" : "no");
+                               pr_cont("   PRES => %s",
+                                       dstat & BT848_DSTATUS_PRES
+                                       ? "yes" : "no");
                        if (stat & BT848_INT_FMTCHG)
-                               printk("   NUML => %s", (dstat & BT848_DSTATUS_NUML)
-                                      ? "625" : "525");
-                       printk("\n");
+                               pr_cont("   NUML => %s",
+                                       dstat & BT848_DSTATUS_NUML
+                                       ? "625" : "525");
+                       pr_cont("\n");
                }
 
                if (astat&BT848_INT_VSYNC)
@@ -4075,18 +4089,19 @@ static irqreturn_t bttv_irq(int irq, void *dev_id)
                        audio_mute(btv, btv->mute);  /* trigger automute */
 
                if (astat & (BT848_INT_SCERR|BT848_INT_OCERR)) {
-                       printk(KERN_INFO "bttv%d: %s%s @ %08x,",btv->c.nr,
-                              (astat & BT848_INT_SCERR) ? "SCERR" : "",
-                              (astat & BT848_INT_OCERR) ? "OCERR" : "",
-                              btread(BT848_RISC_COUNT));
+                       pr_info("%d: %s%s @ %08x,",
+                               btv->c.nr,
+                               (astat & BT848_INT_SCERR) ? "SCERR" : "",
+                               (astat & BT848_INT_OCERR) ? "OCERR" : "",
+                               btread(BT848_RISC_COUNT));
                        bttv_print_irqbits(stat,astat);
-                       printk("\n");
+                       pr_cont("\n");
                        if (bttv_debug)
                                bttv_print_riscaddr(btv);
                }
                if (fdsr && astat & BT848_INT_FDSR) {
-                       printk(KERN_INFO "bttv%d: FDSR @ %08x\n",
-                              btv->c.nr,btread(BT848_RISC_COUNT));
+                       pr_info("%d: FDSR @ %08x\n",
+                               btv->c.nr, btread(BT848_RISC_COUNT));
                        if (bttv_debug)
                                bttv_print_riscaddr(btv);
                }
@@ -4097,11 +4112,11 @@ static irqreturn_t bttv_irq(int irq, void *dev_id)
                        if (count > 8 || !(astat & BT848_INT_GPINT)) {
                                btwrite(0, BT848_INT_MASK);
 
-                               printk(KERN_ERR
-                                          "bttv%d: IRQ lockup, cleared int mask [", btv->c.nr);
+                               pr_err("%d: IRQ lockup, cleared int mask [",
+                                      btv->c.nr);
                        } else {
-                               printk(KERN_ERR
-                                          "bttv%d: IRQ lockup, clearing GPINT from int mask [", btv->c.nr);
+                               pr_err("%d: IRQ lockup, clearing GPINT from int mask [",
+                                      btv->c.nr);
 
                                btwrite(btread(BT848_INT_MASK) & (-1 ^ BT848_INT_GPINT),
                                                BT848_INT_MASK);
@@ -4109,7 +4124,7 @@ static irqreturn_t bttv_irq(int irq, void *dev_id)
 
                        bttv_print_irqbits(stat,astat);
 
-                       printk("]\n");
+                       pr_cont("]\n");
                }
        }
        btv->irq_total++;
@@ -4171,7 +4186,7 @@ static void bttv_unregister_video(struct bttv *btv)
 static int __devinit bttv_register_video(struct bttv *btv)
 {
        if (no_overlay > 0)
-               printk("bttv: Overlay support disabled.\n");
+               pr_notice("Overlay support disabled\n");
 
        /* video */
        btv->video_dev = vdev_init(btv, &bttv_video_template, "video");
@@ -4181,12 +4196,11 @@ static int __devinit bttv_register_video(struct bttv *btv)
        if (video_register_device(btv->video_dev, VFL_TYPE_GRABBER,
                                  video_nr[btv->c.nr]) < 0)
                goto err;
-       printk(KERN_INFO "bttv%d: registered device %s\n",
-              btv->c.nr, video_device_node_name(btv->video_dev));
+       pr_info("%d: registered device %s\n",
+               btv->c.nr, video_device_node_name(btv->video_dev));
        if (device_create_file(&btv->video_dev->dev,
                                     &dev_attr_card)<0) {
-               printk(KERN_ERR "bttv%d: device_create_file 'card' "
-                      "failed\n", btv->c.nr);
+               pr_err("%d: device_create_file 'card' failed\n", btv->c.nr);
                goto err;
        }
 
@@ -4198,8 +4212,8 @@ static int __devinit bttv_register_video(struct bttv *btv)
        if (video_register_device(btv->vbi_dev, VFL_TYPE_VBI,
                                  vbi_nr[btv->c.nr]) < 0)
                goto err;
-       printk(KERN_INFO "bttv%d: registered device %s\n",
-              btv->c.nr, video_device_node_name(btv->vbi_dev));
+       pr_info("%d: registered device %s\n",
+               btv->c.nr, video_device_node_name(btv->vbi_dev));
 
        if (!btv->has_radio)
                return 0;
@@ -4210,8 +4224,8 @@ static int __devinit bttv_register_video(struct bttv *btv)
        if (video_register_device(btv->radio_dev, VFL_TYPE_RADIO,
                                  radio_nr[btv->c.nr]) < 0)
                goto err;
-       printk(KERN_INFO "bttv%d: registered device %s\n",
-              btv->c.nr, video_device_node_name(btv->radio_dev));
+       pr_info("%d: registered device %s\n",
+               btv->c.nr, video_device_node_name(btv->radio_dev));
 
        /* all done */
        return 0;
@@ -4244,10 +4258,10 @@ static int __devinit bttv_probe(struct pci_dev *dev,
 
        if (bttv_num == BTTV_MAX)
                return -ENOMEM;
-       printk(KERN_INFO "bttv: Bt8xx card found (%d).\n", bttv_num);
+       pr_info("Bt8xx card found (%d)\n", bttv_num);
        bttvs[bttv_num] = btv = kzalloc(sizeof(*btv), GFP_KERNEL);
        if (btv == NULL) {
-               printk(KERN_ERR "bttv: out of memory.\n");
+               pr_err("out of memory\n");
                return -ENOMEM;
        }
        btv->c.nr  = bttv_num;
@@ -4277,21 +4291,19 @@ static int __devinit bttv_probe(struct pci_dev *dev,
        btv->c.pci = dev;
        btv->id  = dev->device;
        if (pci_enable_device(dev)) {
-               printk(KERN_WARNING "bttv%d: Can't enable device.\n",
-                      btv->c.nr);
+               pr_warn("%d: Can't enable device\n", btv->c.nr);
                return -EIO;
        }
        if (pci_set_dma_mask(dev, DMA_BIT_MASK(32))) {
-               printk(KERN_WARNING "bttv%d: No suitable DMA available.\n",
-                      btv->c.nr);
+               pr_warn("%d: No suitable DMA available\n", btv->c.nr);
                return -EIO;
        }
        if (!request_mem_region(pci_resource_start(dev,0),
                                pci_resource_len(dev,0),
                                btv->c.v4l2_dev.name)) {
-               printk(KERN_WARNING "bttv%d: can't request iomem (0x%llx).\n",
-                      btv->c.nr,
-                      (unsigned long long)pci_resource_start(dev,0));
+               pr_warn("%d: can't request iomem (0x%llx)\n",
+                       btv->c.nr,
+                       (unsigned long long)pci_resource_start(dev, 0));
                return -EBUSY;
        }
        pci_set_master(dev);
@@ -4299,22 +4311,21 @@ static int __devinit bttv_probe(struct pci_dev *dev,
 
        result = v4l2_device_register(&dev->dev, &btv->c.v4l2_dev);
        if (result < 0) {
-               printk(KERN_WARNING "bttv%d: v4l2_device_register() failed\n", btv->c.nr);
+               pr_warn("%d: v4l2_device_register() failed\n", btv->c.nr);
                goto fail0;
        }
 
        btv->revision = dev->revision;
        pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lat);
-       printk(KERN_INFO "bttv%d: Bt%d (rev %d) at %s, ",
-              bttv_num,btv->id, btv->revision, pci_name(dev));
-       printk("irq: %d, latency: %d, mmio: 0x%llx\n",
-              btv->c.pci->irq, lat,
-              (unsigned long long)pci_resource_start(dev,0));
+       pr_info("%d: Bt%d (rev %d) at %s, irq: %d, latency: %d, mmio: 0x%llx\n",
+               bttv_num, btv->id, btv->revision, pci_name(dev),
+               btv->c.pci->irq, lat,
+               (unsigned long long)pci_resource_start(dev, 0));
        schedule();
 
        btv->bt848_mmio = ioremap(pci_resource_start(dev, 0), 0x1000);
        if (NULL == btv->bt848_mmio) {
-               printk("bttv%d: ioremap() failed\n", btv->c.nr);
+               pr_err("%d: ioremap() failed\n", btv->c.nr);
                result = -EIO;
                goto fail1;
        }
@@ -4327,8 +4338,8 @@ static int __devinit bttv_probe(struct pci_dev *dev,
        result = request_irq(btv->c.pci->irq, bttv_irq,
            IRQF_SHARED | IRQF_DISABLED, btv->c.v4l2_dev.name, (void *)btv);
        if (result < 0) {
-               printk(KERN_ERR "bttv%d: can't get IRQ %d\n",
-                      bttv_num,btv->c.pci->irq);
+               pr_err("%d: can't get IRQ %d\n",
+                      bttv_num, btv->c.pci->irq);
                goto fail1;
        }
 
@@ -4433,7 +4444,7 @@ static void __devexit bttv_remove(struct pci_dev *pci_dev)
        struct bttv *btv = to_bttv(v4l2_dev);
 
        if (bttv_verbose)
-               printk("bttv%d: unloading\n",btv->c.nr);
+               pr_info("%d: unloading\n", btv->c.nr);
 
        if (bttv_tvcards[btv->c.type].has_dvb)
                flush_request_modules(btv);
@@ -4481,7 +4492,7 @@ static int bttv_suspend(struct pci_dev *pci_dev, pm_message_t state)
        struct bttv_buffer_set idle;
        unsigned long flags;
 
-       dprintk("bttv%d: suspend %d\n", btv->c.nr, state.event);
+       dprintk("%d: suspend %d\n", btv->c.nr, state.event);
 
        /* stop dma + irqs */
        spin_lock_irqsave(&btv->s_lock,flags);
@@ -4517,14 +4528,13 @@ static int bttv_resume(struct pci_dev *pci_dev)
        unsigned long flags;
        int err;
 
-       dprintk("bttv%d: resume\n", btv->c.nr);
+       dprintk("%d: resume\n", btv->c.nr);
 
        /* restore pci state */
        if (btv->state.disabled) {
                err=pci_enable_device(pci_dev);
                if (err) {
-                       printk(KERN_WARNING "bttv%d: Can't enable device.\n",
-                                                               btv->c.nr);
+                       pr_warn("%d: Can't enable device\n", btv->c.nr);
                        return err;
                }
                btv->state.disabled = 0;
@@ -4532,8 +4542,7 @@ static int bttv_resume(struct pci_dev *pci_dev)
        err=pci_set_power_state(pci_dev, PCI_D0);
        if (err) {
                pci_disable_device(pci_dev);
-               printk(KERN_WARNING "bttv%d: Can't enable device.\n",
-                                                       btv->c.nr);
+               pr_warn("%d: Can't enable device\n", btv->c.nr);
                btv->state.disabled = 1;
                return err;
        }
@@ -4585,22 +4594,21 @@ static int __init bttv_init_module(void)
 
        bttv_num = 0;
 
-       printk(KERN_INFO "bttv: driver version %s loaded\n",
-              BTTV_VERSION);
+       pr_info("driver version %s loaded\n", BTTV_VERSION);
        if (gbuffers < 2 || gbuffers > VIDEO_MAX_FRAME)
                gbuffers = 2;
        if (gbufsize > BTTV_MAX_FBUF)
                gbufsize = BTTV_MAX_FBUF;
        gbufsize = (gbufsize + PAGE_SIZE - 1) & PAGE_MASK;
        if (bttv_verbose)
-               printk(KERN_INFO "bttv: using %d buffers with %dk (%d pages) each for capture\n",
-                      gbuffers, gbufsize >> 10, gbufsize >> PAGE_SHIFT);
+               pr_info("using %d buffers with %dk (%d pages) each for capture\n",
+                       gbuffers, gbufsize >> 10, gbufsize >> PAGE_SHIFT);
 
        bttv_check_chipset();
 
        ret = bus_register(&bttv_sub_bus_type);
        if (ret < 0) {
-               printk(KERN_WARNING "bttv: bus_register error: %d\n", ret);
+               pr_warn("bus_register error: %d\n", ret);
                return ret;
        }
        ret = pci_register_driver(&bttv_pci_driver);
index 13ce72c04b33879b9b59dbad08b5a992219a10be..922e8233fd0b88dbed55c284342edfa7c9b23cf0 100644 (file)
@@ -26,6 +26,8 @@
 
 */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/delay.h>
@@ -99,7 +101,7 @@ int bttv_sub_add_device(struct bttv_core *core, char *name)
                kfree(sub);
                return err;
        }
-       printk("bttv%d: add subdevice \"%s\"\n", core->nr, dev_name(&sub->dev));
+       pr_info("%d: add subdevice \"%s\"\n", core->nr, dev_name(&sub->dev));
        list_add_tail(&sub->list,&core->subs);
        return 0;
 }
index d49b675045fe55457145b453a89acb565d3bc496..e3952af7e56e2df0f28c6be896add69e2fa37b0f 100644 (file)
@@ -27,6 +27,8 @@
 
 */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/delay.h>
@@ -154,9 +156,7 @@ bttv_i2c_sendbytes(struct bttv *btv, const struct i2c_msg *msg, int last)
        if (retval == 0)
                goto eio;
        if (i2c_debug) {
-               printk(" <W %02x %02x", msg->addr << 1, msg->buf[0]);
-               if (!(xmit & BT878_I2C_NOSTOP))
-                       printk(" >\n");
+               pr_cont(" <W %02x %02x", msg->addr << 1, msg->buf[0]);
        }
 
        for (cnt = 1; cnt < msg->len; cnt++ ) {
@@ -170,19 +170,18 @@ bttv_i2c_sendbytes(struct bttv *btv, const struct i2c_msg *msg, int last)
                        goto err;
                if (retval == 0)
                        goto eio;
-               if (i2c_debug) {
-                       printk(" %02x", msg->buf[cnt]);
-                       if (!(xmit & BT878_I2C_NOSTOP))
-                               printk(" >\n");
-               }
+               if (i2c_debug)
+                       pr_cont(" %02x", msg->buf[cnt]);
        }
+       if (!(xmit & BT878_I2C_NOSTOP))
+               pr_cont(">\n");
        return msg->len;
 
  eio:
        retval = -EIO;
  err:
        if (i2c_debug)
-               printk(" ERR: %d\n",retval);
+               pr_cont(" ERR: %d\n",retval);
        return retval;
 }
 
@@ -193,7 +192,7 @@ bttv_i2c_readbytes(struct bttv *btv, const struct i2c_msg *msg, int last)
        u32 cnt;
        int retval;
 
-       for(cnt = 0; cnt < msg->len; cnt++) {
+       for (cnt = 0; cnt < msg->len; cnt++) {
                xmit = (msg->addr << 25) | (1 << 24) | I2C_HW;
                if (cnt < msg->len-1)
                        xmit |= BT848_I2C_W3B;
@@ -201,6 +200,12 @@ bttv_i2c_readbytes(struct bttv *btv, const struct i2c_msg *msg, int last)
                        xmit |= BT878_I2C_NOSTOP;
                if (cnt)
                        xmit |= BT878_I2C_NOSTART;
+
+               if (i2c_debug) {
+                       if (!(xmit & BT878_I2C_NOSTART))
+                               pr_cont(" <R %02x", (msg->addr << 1) +1);
+               }
+
                btwrite(xmit, BT848_I2C);
                retval = bttv_i2c_wait_done(btv);
                if (retval < 0)
@@ -209,20 +214,20 @@ bttv_i2c_readbytes(struct bttv *btv, const struct i2c_msg *msg, int last)
                        goto eio;
                msg->buf[cnt] = ((u32)btread(BT848_I2C) >> 8) & 0xff;
                if (i2c_debug) {
-                       if (!(xmit & BT878_I2C_NOSTART))
-                               printk(" <R %02x", (msg->addr << 1) +1);
-                       printk(" =%02x", msg->buf[cnt]);
-                       if (!(xmit & BT878_I2C_NOSTOP))
-                               printk(" >\n");
+                       pr_cont(" =%02x", msg->buf[cnt]);
                }
+               if (i2c_debug && !(xmit & BT878_I2C_NOSTOP))
+                       pr_cont(" >\n");
        }
+
+
        return msg->len;
 
  eio:
        retval = -EIO;
  err:
        if (i2c_debug)
-               printk(" ERR: %d\n",retval);
+               pr_cont(" ERR: %d\n",retval);
        return retval;
 }
 
@@ -234,7 +239,8 @@ static int bttv_i2c_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int
        int i;
 
        if (i2c_debug)
-               printk("bt-i2c:");
+               pr_debug("bt-i2c:");
+
        btwrite(BT848_INT_I2CDONE|BT848_INT_RACK, BT848_INT_STAT);
        for (i = 0 ; i < num; i++) {
                if (msgs[i].flags & I2C_M_RD) {
@@ -271,20 +277,20 @@ int bttv_I2CRead(struct bttv *btv, unsigned char addr, char *probe_for)
        if (0 != btv->i2c_rc)
                return -1;
        if (bttv_verbose && NULL != probe_for)
-               printk(KERN_INFO "bttv%d: i2c: checking for %s @ 0x%02x... ",
-                      btv->c.nr,probe_for,addr);
+               pr_info("%d: i2c: checking for %s @ 0x%02x... ",
+                       btv->c.nr, probe_for, addr);
        btv->i2c_client.addr = addr >> 1;
        if (1 != i2c_master_recv(&btv->i2c_client, &buffer, 1)) {
                if (NULL != probe_for) {
                        if (bttv_verbose)
-                               printk("not found\n");
+                               pr_cont("not found\n");
                } else
-                       printk(KERN_WARNING "bttv%d: i2c read 0x%x: error\n",
-                              btv->c.nr,addr);
+                       pr_warn("%d: i2c read 0x%x: error\n",
+                               btv->c.nr, addr);
                return -1;
        }
        if (bttv_verbose && NULL != probe_for)
-               printk("found\n");
+               pr_cont("found\n");
        return buffer;
 }
 
@@ -335,8 +341,8 @@ static void do_i2c_scan(char *name, struct i2c_client *c)
                rc = i2c_master_recv(c,&buf,0);
                if (rc < 0)
                        continue;
-               printk("%s: i2c scan: found device @ 0x%x  [%s]\n",
-                      name, i << 1, i2c_devs[i] ? i2c_devs[i] : "???");
+               pr_info("%s: i2c scan: found device @ 0x%x  [%s]\n",
+                       name, i << 1, i2c_devs[i] ? i2c_devs[i] : "???");
        }
 }
 
index 677d70c0e1cebf100649d52dec6587ab443a1b80..ef4c7cd419827f800f2073775923e042e73536a7 100644 (file)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/delay.h>
@@ -36,9 +38,10 @@ static int ir_rc5_remote_gap = 885;
 module_param(ir_rc5_remote_gap, int, 0644);
 
 #undef dprintk
-#define dprintk(arg...) do {   \
-       if (ir_debug >= 1)      \
-               printk(arg);    \
+#define dprintk(fmt, ...)                      \
+do {                                           \
+       if (ir_debug >= 1)                      \
+               pr_info(fmt, ##__VA_ARGS__);    \
 } while (0)
 
 #define DEVNAME "bttv-input"
@@ -62,7 +65,7 @@ static void ir_handle_key(struct bttv *btv)
 
        /* extract data */
        data = ir_extract_bits(gpio, ir->mask_keycode);
-       dprintk(KERN_INFO DEVNAME ": irq gpio=0x%x code=%d | %s%s%s\n",
+       dprintk("irq gpio=0x%x code=%d | %s%s%s\n",
                gpio, data,
                ir->polling               ? "poll"  : "irq",
                (gpio & ir->mask_keydown) ? " down" : "",
@@ -96,7 +99,7 @@ static void ir_enltv_handle_key(struct bttv *btv)
        keyup = (gpio & ir->mask_keyup) ? 1 << 31 : 0;
 
        if ((ir->last_gpio & 0x7f) != data) {
-               dprintk(KERN_INFO DEVNAME ": gpio=0x%x code=%d | %s\n",
+               dprintk("gpio=0x%x code=%d | %s\n",
                        gpio, data,
                        (gpio & ir->mask_keyup) ? " up" : "up/down");
 
@@ -107,7 +110,7 @@ static void ir_enltv_handle_key(struct bttv *btv)
                if ((ir->last_gpio & 1 << 31) == keyup)
                        return;
 
-               dprintk(KERN_INFO DEVNAME ":(cnt) gpio=0x%x code=%d | %s\n",
+               dprintk("(cnt) gpio=0x%x code=%d | %s\n",
                        gpio, data,
                        (gpio & ir->mask_keyup) ? " up" : "down");
 
@@ -177,13 +180,12 @@ static u32 bttv_rc5_decode(unsigned int code)
                        rc5 |= 1;
                break;
                case 3:
-                       dprintk(KERN_INFO DEVNAME ":rc5_decode(%x) bad code\n",
+                       dprintk("rc5_decode(%x) bad code\n",
                                org_code);
                        return 0;
                }
        }
-       dprintk(KERN_INFO DEVNAME ":"
-               "code=%x, rc5=%x, start=%x, toggle=%x, address=%x, "
+       dprintk("code=%x, rc5=%x, start=%x, toggle=%x, address=%x, "
                "instr=%x\n", rc5, org_code, RC5_START(rc5),
                RC5_TOGGLE(rc5), RC5_ADDR(rc5), RC5_INSTR(rc5));
        return rc5;
@@ -212,20 +214,20 @@ static void bttv_rc5_timer_end(unsigned long data)
 
        /* Allow some timer jitter (RC5 is ~24ms anyway so this is ok) */
        if (gap < 28000) {
-               dprintk(KERN_INFO DEVNAME ": spurious timer_end\n");
+               dprintk("spurious timer_end\n");
                return;
        }
 
        if (ir->last_bit < 20) {
                /* ignore spurious codes (caused by light/other remotes) */
-               dprintk(KERN_INFO DEVNAME ": short code: %x\n", ir->code);
+               dprintk("short code: %x\n", ir->code);
        } else {
                ir->code = (ir->code << ir->shift_by) | 1;
                rc5 = bttv_rc5_decode(ir->code);
 
                /* two start bits? */
                if (RC5_START(rc5) != ir->start) {
-                       printk(KERN_INFO DEVNAME ":"
+                       pr_info(DEVNAME ":"
                               " rc5 start bits invalid: %u\n", RC5_START(rc5));
 
                        /* right address? */
@@ -235,8 +237,7 @@ static void bttv_rc5_timer_end(unsigned long data)
 
                        /* Good code */
                        rc_keydown(ir->dev, instr, toggle);
-                       dprintk(KERN_INFO DEVNAME ":"
-                               " instruction %x, toggle %x\n",
+                       dprintk("instruction %x, toggle %x\n",
                                instr, toggle);
                }
        }
@@ -265,7 +266,7 @@ static int bttv_rc5_irq(struct bttv *btv)
                    tv.tv_usec - ir->base_time.tv_usec;
        }
 
-       dprintk(KERN_INFO DEVNAME ": RC5 IRQ: gap %d us for %s\n",
+       dprintk("RC5 IRQ: gap %d us for %s\n",
                gap, (gpio & 0x20) ? "mark" : "space");
 
        /* remote IRQ? */
@@ -340,14 +341,14 @@ static int get_key_pv951(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
 
        /* poll IR chip */
        if (1 != i2c_master_recv(ir->c, &b, 1)) {
-               dprintk(KERN_INFO DEVNAME ": read error\n");
+               dprintk("read error\n");
                return -EIO;
        }
 
        /* ignore 0xaa */
        if (b==0xaa)
                return 0;
-       dprintk(KERN_INFO DEVNAME ": key %02x\n", b);
+       dprintk("key %02x\n", b);
 
        /*
         * NOTE:
@@ -517,7 +518,7 @@ int bttv_input_init(struct bttv *btv)
                break;
        }
        if (NULL == ir_codes) {
-               dprintk(KERN_INFO "Ooops: IR config error [card=%d]\n", btv->c.type);
+               dprintk("Ooops: IR config error [card=%d]\n", btv->c.type);
                err = -ENODEV;
                goto err_out_free;
        }
index 9b57d091da48cede48cf7eca3e1976a96521a854..82cc47d2e3fa0e840f00d1741c17da7e7c019638 100644 (file)
@@ -24,6 +24,8 @@
 
 */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/slab.h>
@@ -473,8 +475,7 @@ bttv_set_dma(struct bttv *btv, int override)
        capctl |= (btv->cap_ctl & 0x0c) ? 0x0c : 0x00;  /* vbi data */
        capctl |= override;
 
-       d2printk(KERN_DEBUG
-                "bttv%d: capctl=%x lirq=%d top=%08Lx/%08Lx even=%08Lx/%08Lx\n",
+       d2printk("%d: capctl=%x lirq=%d top=%08llx/%08llx even=%08llx/%08llx\n",
                 btv->c.nr,capctl,btv->loop_irq,
                 btv->cvbi         ? (unsigned long long)btv->cvbi->top.dma            : 0,
                 btv->curr.top     ? (unsigned long long)btv->curr.top->top.dma        : 0,
@@ -517,8 +518,8 @@ bttv_risc_init_main(struct bttv *btv)
 
        if ((rc = btcx_riscmem_alloc(btv->c.pci,&btv->main,PAGE_SIZE)) < 0)
                return rc;
-       dprintk(KERN_DEBUG "bttv%d: risc main @ %08Lx\n",
-               btv->c.nr,(unsigned long long)btv->main.dma);
+       dprintk("%d: risc main @ %08llx\n",
+               btv->c.nr, (unsigned long long)btv->main.dma);
 
        btv->main.cpu[0] = cpu_to_le32(BT848_RISC_SYNC | BT848_RISC_RESYNC |
                                       BT848_FIFO_STATUS_VRE);
@@ -557,12 +558,12 @@ bttv_risc_hook(struct bttv *btv, int slot, struct btcx_riscmem *risc,
        unsigned long next = btv->main.dma + ((slot+2) << 2);
 
        if (NULL == risc) {
-               d2printk(KERN_DEBUG "bttv%d: risc=%p slot[%d]=NULL\n",
-                        btv->c.nr,risc,slot);
+               d2printk("%d: risc=%p slot[%d]=NULL\n", btv->c.nr, risc, slot);
                btv->main.cpu[slot+1] = cpu_to_le32(next);
        } else {
-               d2printk(KERN_DEBUG "bttv%d: risc=%p slot[%d]=%08Lx irq=%d\n",
-                        btv->c.nr,risc,slot,(unsigned long long)risc->dma,irqflags);
+               d2printk("%d: risc=%p slot[%d]=%08llx irq=%d\n",
+                        btv->c.nr, risc, slot,
+                        (unsigned long long)risc->dma, irqflags);
                cmd = BT848_RISC_JUMP;
                if (irqflags) {
                        cmd |= BT848_RISC_IRQ;
@@ -708,8 +709,7 @@ bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf)
        const struct bttv_tvnorm *tvnorm = bttv_tvnorms + buf->tvnorm;
        struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
 
-       dprintk(KERN_DEBUG
-               "bttv%d: buffer field: %s  format: %s  size: %dx%d\n",
+       dprintk("%d: buffer field: %s  format: %s  size: %dx%d\n",
                btv->c.nr, v4l2_field_names[buf->vb.field],
                buf->fmt->name, buf->vb.width, buf->vb.height);
 
@@ -870,10 +870,9 @@ bttv_overlay_risc(struct bttv *btv,
                  struct bttv_buffer *buf)
 {
        /* check interleave, bottom+top fields */
-       dprintk(KERN_DEBUG
-               "bttv%d: overlay fields: %s format: %s  size: %dx%d\n",
+       dprintk("%d: overlay fields: %s format: %s  size: %dx%d\n",
                btv->c.nr, v4l2_field_names[buf->vb.field],
-               fmt->name,ov->w.width,ov->w.height);
+               fmt->name, ov->w.width, ov->w.height);
 
        /* calculate geometry */
        bttv_calc_geo(btv,&buf->geo,ov->w.width,ov->w.height,
index e79a402fa6cd576897f042c44b75a5e0985fe386..b433267d9aa92d8cabb1da721646ef8bafc40e37 100644 (file)
@@ -23,6 +23,8 @@
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/module.h>
 #include <linux/errno.h>
 #include <linux/fs.h>
@@ -65,8 +67,11 @@ MODULE_PARM_DESC(vbi_debug,"vbi code debug messages, default is 0 (no)");
 #ifdef dprintk
 # undef dprintk
 #endif
-#define dprintk(fmt, arg...)   if (vbi_debug) \
-       printk(KERN_DEBUG "bttv%d/vbi: " fmt, btv->c.nr , ## arg)
+#define dprintk(fmt, ...)                                              \
+do {                                                                   \
+       if (vbi_debug)                                                  \
+               pr_debug("%d: " fmt, btv->c.nr, ##__VA_ARGS__);         \
+} while (0)
 
 #define IMAGE_SIZE(fmt) \
        (((fmt)->count[0] + (fmt)->count[1]) * (fmt)->samples_per_line)
index 318edf2830b4e7bfb0cde61582cadcd0b19ef3f6..db943a8d580db131a1bcd4daaece5b6bf0552093 100644 (file)
@@ -310,9 +310,21 @@ extern unsigned int bttv_gpio;
 extern void bttv_gpio_tracking(struct bttv *btv, char *comment);
 extern int init_bttv_i2c(struct bttv *btv);
 
-#define bttv_printk if (bttv_verbose) printk
-#define dprintk  if (bttv_debug >= 1) printk
-#define d2printk if (bttv_debug >= 2) printk
+#define dprintk(fmt, ...)                      \
+do {                                           \
+       if (bttv_debug >= 1)                    \
+               pr_debug(fmt, ##__VA_ARGS__);   \
+} while (0)
+#define dprintk_cont(fmt, ...)                 \
+do {                                           \
+       if (bttv_debug >= 1)                    \
+               pr_cont(fmt, ##__VA_ARGS__);    \
+} while (0)
+#define d2printk(fmt, ...)                     \
+do {                                           \
+       if (bttv_debug >= 2)                    \
+               printk(fmt, ##__VA_ARGS__);     \
+} while (0)
 
 #define BTTV_MAX_FBUF   0x208000
 #define BTTV_TIMEOUT    msecs_to_jiffies(500)    /* 0.5 seconds */
index 2fadd9ded34062097c777739da66d6c23610bdfa..a86bab5893ef0a3fd86d2357347d7ded1f841cde 100644 (file)
@@ -8,6 +8,6 @@ cx18-alsa-objs := cx18-alsa-main.o cx18-alsa-pcm.o
 obj-$(CONFIG_VIDEO_CX18) += cx18.o
 obj-$(CONFIG_VIDEO_CX18_ALSA) += cx18-alsa.o
 
-EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
-EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
-EXTRA_CFLAGS += -Idrivers/media/common/tuners
+ccflags-y += -Idrivers/media/dvb/dvb-core
+ccflags-y += -Idrivers/media/dvb/frontends
+ccflags-y += -Idrivers/media/common/tuners
index 1834207230607a5ce714ce1492b6855bb56bed44..b9a94fc5146db08e920cd98c4e7d28a14928bafa 100644 (file)
@@ -409,6 +409,7 @@ struct cx18_stream {
 
        /* Videobuf for YUV video */
        u32 pixelformat;
+       u32 vb_bytes_per_frame;
        struct list_head vb_capture;    /* video capture queue */
        spinlock_t vb_lock;
        struct timer_list vb_timeout;
@@ -430,10 +431,6 @@ struct cx18_open_id {
        u32 open_id;
        int type;
        struct cx18 *cx;
-
-       struct videobuf_queue vbuf_q;
-       spinlock_t s_lock; /* Protect vbuf_q */
-       enum v4l2_buf_type vb_type;
 };
 
 static inline struct cx18_open_id *fh2id(struct v4l2_fh *fh)
index 07411f34885a88797f39022ffc45ae10dd88b166..14cb961c22bdba5ef506ba56ad55e59d2dc1ade5 100644 (file)
@@ -784,8 +784,6 @@ int cx18_v4l2_close(struct file *filp)
                cx18_release_stream(s);
        } else {
                cx18_stop_capture(id, 0);
-               if (id->type == CX18_ENC_STREAM_TYPE_YUV)
-                       videobuf_mmap_free(&id->vbuf_q);
        }
        kfree(id);
        mutex_unlock(&cx->serialize_lock);
index afe0a29e7200b9cdbb21447f7f0d7a5256ed0c8f..66b1c15c35413b1f092068e6bfb2f4daf7cad7f7 100644 (file)
@@ -160,12 +160,7 @@ static int cx18_g_fmt_vid_cap(struct file *file, void *fh,
        pixfmt->priv = 0;
        if (id->type == CX18_ENC_STREAM_TYPE_YUV) {
                pixfmt->pixelformat = s->pixelformat;
-               /* HM12 YUV size is (Y=(h*720) + UV=(h*(720/2)))
-                  UYUV YUV size is (Y=(h*720) + UV=(h*(720))) */
-               if (s->pixelformat == V4L2_PIX_FMT_HM12)
-                       pixfmt->sizeimage = pixfmt->height * 720 * 3 / 2;
-               else
-                       pixfmt->sizeimage = pixfmt->height * 720 * 2;
+               pixfmt->sizeimage = s->vb_bytes_per_frame;
                pixfmt->bytesperline = 720;
        } else {
                pixfmt->pixelformat = V4L2_PIX_FMT_MPEG;
@@ -296,6 +291,12 @@ static int cx18_s_fmt_vid_cap(struct file *file, void *fh,
                return -EBUSY;
 
        s->pixelformat = fmt->fmt.pix.pixelformat;
+       /* HM12 YUV size is (Y=(h*720) + UV=(h*(720/2)))
+          UYUV YUV size is (Y=(h*720) + UV=(h*(720))) */
+       if (s->pixelformat == V4L2_PIX_FMT_HM12)
+               s->vb_bytes_per_frame = h * 720 * 3 / 2;
+       else
+               s->vb_bytes_per_frame = h * 720 * 2;
 
        mbus_fmt.width = cx->cxhdl.width = w;
        mbus_fmt.height = cx->cxhdl.height = h;
@@ -463,13 +464,16 @@ static int cx18_s_register(struct file *file, void *fh,
 static int cx18_querycap(struct file *file, void *fh,
                                struct v4l2_capability *vcap)
 {
-       struct cx18 *cx = fh2id(fh)->cx;
+       struct cx18_open_id *id = fh2id(fh);
+       struct cx18 *cx = id->cx;
 
        strlcpy(vcap->driver, CX18_DRIVER_NAME, sizeof(vcap->driver));
        strlcpy(vcap->card, cx->card_name, sizeof(vcap->card));
        snprintf(vcap->bus_info, sizeof(vcap->bus_info),
                 "PCI:%s", pci_name(cx->pci_dev));
        vcap->capabilities = cx->v4l2_cap;          /* capabilities */
+       if (id->type == CX18_ENC_STREAM_TYPE_YUV)
+               vcap->capabilities |= V4L2_CAP_STREAMING;
        return 0;
 }
 
index c07191e09fcbf63578ca85c353fefe63b44df682..0c7796e76ac0faceaf570df9fc2a495bea305808 100644 (file)
@@ -196,7 +196,7 @@ static void cx18_mdl_send_to_videobuf(struct cx18_stream *s,
        }
 
        /* If we've filled the buffer as per the callers res then dispatch it */
-       if (vb_buf->bytes_used >= (vb_buf->vb.width * vb_buf->vb.height * 2)) {
+       if (vb_buf->bytes_used >= s->vb_bytes_per_frame) {
                dispatch = 1;
                vb_buf->bytes_used = 0;
        }
index 852f420fd2715c6190cc97e25b7e8ddc280f9771..638cca156b5852753ed6e049b2f5647ba319081b 100644 (file)
@@ -138,6 +138,12 @@ static int cx18_prepare_buffer(struct videobuf_queue *q,
                buf->tvnorm    = cx->std;
                s->pixelformat = pixelformat;
 
+               /* HM12 YUV size is (Y=(h*720) + UV=(h*(720/2)))
+                  UYUV YUV size is (Y=(h*720) + UV=(h*(720))) */
+               if (s->pixelformat == V4L2_PIX_FMT_HM12)
+                       s->vb_bytes_per_frame = height * 720 * 3 / 2;
+               else
+                       s->vb_bytes_per_frame = height * 720 * 2;
                cx18_dma_free(q, s, buf);
        }
 
@@ -154,6 +160,12 @@ static int cx18_prepare_buffer(struct videobuf_queue *q,
                buf->tvnorm    = cx->std;
                s->pixelformat = pixelformat;
 
+               /* HM12 YUV size is (Y=(h*720) + UV=(h*(720/2)))
+                  UYUV YUV size is (Y=(h*720) + UV=(h*(720))) */
+               if (s->pixelformat == V4L2_PIX_FMT_HM12)
+                       s->vb_bytes_per_frame = height * 720 * 3 / 2;
+               else
+                       s->vb_bytes_per_frame = height * 720 * 2;
                rc = videobuf_iolock(q, &buf->vb, NULL);
                if (rc != 0)
                        goto fail;
@@ -287,6 +299,7 @@ static void cx18_stream_init(struct cx18 *cx, int type)
 
                /* Assume the previous pixel default */
                s->pixelformat = V4L2_PIX_FMT_HM12;
+               s->vb_bytes_per_frame = cx->cxhdl.height * 720 * 3 / 2;
        }
 }
 
index 2c2484355449e1846932021e3f9f66c25779fcf0..b3348975c7c2039df3b72fc184ec9a3a43555665 100644 (file)
@@ -8,9 +8,9 @@ obj-$(CONFIG_VIDEO_CX231XX) += cx231xx.o
 obj-$(CONFIG_VIDEO_CX231XX_ALSA) += cx231xx-alsa.o
 obj-$(CONFIG_VIDEO_CX231XX_DVB) += cx231xx-dvb.o
 
-EXTRA_CFLAGS += -Idrivers/media/video
-EXTRA_CFLAGS += -Idrivers/media/common/tuners
-EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
-EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
-EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-usb
+ccflags-y += -Idrivers/media/video
+ccflags-y += -Idrivers/media/common/tuners
+ccflags-y += -Idrivers/media/dvb/dvb-core
+ccflags-y += -Idrivers/media/dvb/frontends
+ccflags-y += -Idrivers/media/dvb/dvb-usb
 
index caab1bfb79e2b8d0cf943c83cf31c955fa191f06..b391e9bda877c65d01942212fce2275781be5815 100644 (file)
@@ -38,7 +38,7 @@ config VIDEO_CX23885
 config MEDIA_ALTERA_CI
        tristate "Altera FPGA based CI module"
        depends on VIDEO_CX23885 && DVB_CORE
-       select STAPL_ALTERA
+       select ALTERA_STAPL
        ---help---
          An Altera FPGA CI module for NetUP Dual DVB-T/C RF CI card.
 
index 23293c7b6ac7bd722d01ca394ce2196bf17b4e5b..f81f2796a0f9e45fc0bb717bed3d79e2525e48ba 100644 (file)
@@ -2,14 +2,14 @@ cx23885-objs  := cx23885-cards.o cx23885-video.o cx23885-vbi.o \
                    cx23885-core.o cx23885-i2c.o cx23885-dvb.o cx23885-417.o \
                    cx23885-ioctl.o cx23885-ir.o cx23885-av.o cx23885-input.o \
                    cx23888-ir.o netup-init.o cimax2.o netup-eeprom.o \
-                   cx23885-f300.o
+                   cx23885-f300.o cx23885-alsa.o
 
 obj-$(CONFIG_VIDEO_CX23885) += cx23885.o
 obj-$(CONFIG_MEDIA_ALTERA_CI) += altera-ci.o
 
-EXTRA_CFLAGS += -Idrivers/media/video
-EXTRA_CFLAGS += -Idrivers/media/common/tuners
-EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
-EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
+ccflags-y += -Idrivers/media/video
+ccflags-y += -Idrivers/media/common/tuners
+ccflags-y += -Idrivers/media/dvb/dvb-core
+ccflags-y += -Idrivers/media/dvb/frontends
 
-EXTRA_CFLAGS += $(extra-cflags-y) $(extra-cflags-m)
+ccflags-y += $(extra-cflags-y) $(extra-cflags-m)
diff --git a/drivers/media/video/cx23885/cx23885-alsa.c b/drivers/media/video/cx23885/cx23885-alsa.c
new file mode 100644 (file)
index 0000000..7951692
--- /dev/null
@@ -0,0 +1,535 @@
+/*
+ *
+ *  Support for CX23885 analog audio capture
+ *
+ *    (c) 2008 Mijhail Moreyra <mijhail.moreyra@gmail.com>
+ *    Adapted from cx88-alsa.c
+ *    (c) 2009 Steven Toth <stoth@kernellabs.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/device.h>
+#include <linux/interrupt.h>
+#include <linux/vmalloc.h>
+#include <linux/dma-mapping.h>
+#include <linux/pci.h>
+
+#include <asm/delay.h>
+
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/control.h>
+#include <sound/initval.h>
+
+#include <sound/tlv.h>
+
+
+#include "cx23885.h"
+#include "cx23885-reg.h"
+
+#define AUDIO_SRAM_CHANNEL     SRAM_CH07
+
+#define dprintk(level, fmt, arg...)    if (audio_debug >= level) \
+       printk(KERN_INFO "%s: " fmt, chip->dev->name , ## arg)
+
+#define dprintk_core(level, fmt, arg...)       if (audio_debug >= level) \
+       printk(KERN_DEBUG "%s: " fmt, chip->dev->name , ## arg)
+
+/****************************************************************************
+                       Module global static vars
+ ****************************************************************************/
+
+static unsigned int disable_analog_audio;
+module_param(disable_analog_audio, int, 0644);
+MODULE_PARM_DESC(disable_analog_audio, "disable analog audio ALSA driver");
+
+static unsigned int audio_debug;
+module_param(audio_debug, int, 0644);
+MODULE_PARM_DESC(audio_debug, "enable debug messages [analog audio]");
+
+/****************************************************************************
+                       Board specific funtions
+ ****************************************************************************/
+
+/* Constants taken from cx88-reg.h */
+#define AUD_INT_DN_RISCI1       (1 <<  0)
+#define AUD_INT_UP_RISCI1       (1 <<  1)
+#define AUD_INT_RDS_DN_RISCI1   (1 <<  2)
+#define AUD_INT_DN_RISCI2       (1 <<  4) /* yes, 3 is skipped */
+#define AUD_INT_UP_RISCI2       (1 <<  5)
+#define AUD_INT_RDS_DN_RISCI2   (1 <<  6)
+#define AUD_INT_DN_SYNC         (1 << 12)
+#define AUD_INT_UP_SYNC         (1 << 13)
+#define AUD_INT_RDS_DN_SYNC     (1 << 14)
+#define AUD_INT_OPC_ERR         (1 << 16)
+#define AUD_INT_BER_IRQ         (1 << 20)
+#define AUD_INT_MCHG_IRQ        (1 << 21)
+#define GP_COUNT_CONTROL_RESET 0x3
+
+/*
+ * BOARD Specific: Sets audio DMA
+ */
+
+static int cx23885_start_audio_dma(struct cx23885_audio_dev *chip)
+{
+       struct cx23885_audio_buffer *buf = chip->buf;
+       struct cx23885_dev *dev  = chip->dev;
+       struct sram_channel *audio_ch =
+               &dev->sram_channels[AUDIO_SRAM_CHANNEL];
+
+       dprintk(1, "%s()\n", __func__);
+
+       /* Make sure RISC/FIFO are off before changing FIFO/RISC settings */
+       cx_clear(AUD_INT_DMA_CTL, 0x11);
+
+       /* setup fifo + format - out channel */
+       cx23885_sram_channel_setup(chip->dev, audio_ch, buf->bpl,
+               buf->risc.dma);
+
+       /* sets bpl size */
+       cx_write(AUD_INT_A_LNGTH, buf->bpl);
+
+       /* This is required to get good audio (1 seems to be ok) */
+       cx_write(AUD_INT_A_MODE, 1);
+
+       /* reset counter */
+       cx_write(AUD_INT_A_GPCNT_CTL, GP_COUNT_CONTROL_RESET);
+       atomic_set(&chip->count, 0);
+
+       dprintk(1, "Start audio DMA, %d B/line, %d lines/FIFO, %d periods, %d "
+               "byte buffer\n", buf->bpl, cx_read(audio_ch->cmds_start+12)>>1,
+               chip->num_periods, buf->bpl * chip->num_periods);
+
+       /* Enables corresponding bits at AUD_INT_STAT */
+       cx_write(AUDIO_INT_INT_MSK, AUD_INT_OPC_ERR | AUD_INT_DN_SYNC |
+                                   AUD_INT_DN_RISCI1);
+
+       /* Clean any pending interrupt bits already set */
+       cx_write(AUDIO_INT_INT_STAT, ~0);
+
+       /* enable audio irqs */
+       cx_set(PCI_INT_MSK, chip->dev->pci_irqmask | PCI_MSK_AUD_INT);
+
+       /* start dma */
+       cx_set(DEV_CNTRL2, (1<<5)); /* Enables Risc Processor */
+       cx_set(AUD_INT_DMA_CTL, 0x11); /* audio downstream FIFO and
+                                         RISC enable */
+       if (audio_debug)
+               cx23885_sram_channel_dump(chip->dev, audio_ch);
+
+       return 0;
+}
+
+/*
+ * BOARD Specific: Resets audio DMA
+ */
+static int cx23885_stop_audio_dma(struct cx23885_audio_dev *chip)
+{
+       struct cx23885_dev *dev = chip->dev;
+       dprintk(1, "Stopping audio DMA\n");
+
+       /* stop dma */
+       cx_clear(AUD_INT_DMA_CTL, 0x11);
+
+       /* disable irqs */
+       cx_clear(PCI_INT_MSK, PCI_MSK_AUD_INT);
+       cx_clear(AUDIO_INT_INT_MSK, AUD_INT_OPC_ERR | AUD_INT_DN_SYNC |
+                                   AUD_INT_DN_RISCI1);
+
+       if (audio_debug)
+               cx23885_sram_channel_dump(chip->dev,
+                       &dev->sram_channels[AUDIO_SRAM_CHANNEL]);
+
+       return 0;
+}
+
+/*
+ * BOARD Specific: Handles audio IRQ
+ */
+int cx23885_audio_irq(struct cx23885_dev *dev, u32 status, u32 mask)
+{
+       struct cx23885_audio_dev *chip = dev->audio_dev;
+
+       if (0 == (status & mask))
+               return 0;
+
+       cx_write(AUDIO_INT_INT_STAT, status);
+
+       /* risc op code error */
+       if (status & AUD_INT_OPC_ERR) {
+               printk(KERN_WARNING "%s/1: Audio risc op code error\n",
+                       dev->name);
+               cx_clear(AUD_INT_DMA_CTL, 0x11);
+               cx23885_sram_channel_dump(dev,
+                       &dev->sram_channels[AUDIO_SRAM_CHANNEL]);
+       }
+       if (status & AUD_INT_DN_SYNC) {
+               dprintk(1, "Downstream sync error\n");
+               cx_write(AUD_INT_A_GPCNT_CTL, GP_COUNT_CONTROL_RESET);
+               return 1;
+       }
+       /* risc1 downstream */
+       if (status & AUD_INT_DN_RISCI1) {
+               atomic_set(&chip->count, cx_read(AUD_INT_A_GPCNT));
+               snd_pcm_period_elapsed(chip->substream);
+       }
+       /* FIXME: Any other status should deserve a special handling? */
+
+       return 1;
+}
+
+static int dsp_buffer_free(struct cx23885_audio_dev *chip)
+{
+       BUG_ON(!chip->dma_size);
+
+       dprintk(2, "Freeing buffer\n");
+       videobuf_dma_unmap(&chip->pci->dev, chip->dma_risc);
+       videobuf_dma_free(chip->dma_risc);
+       btcx_riscmem_free(chip->pci, &chip->buf->risc);
+       kfree(chip->buf);
+
+       chip->dma_risc = NULL;
+       chip->dma_size = 0;
+
+       return 0;
+}
+
+/****************************************************************************
+                               ALSA PCM Interface
+ ****************************************************************************/
+
+/*
+ * Digital hardware definition
+ */
+#define DEFAULT_FIFO_SIZE      4096
+
+static struct snd_pcm_hardware snd_cx23885_digital_hw = {
+       .info = SNDRV_PCM_INFO_MMAP |
+               SNDRV_PCM_INFO_INTERLEAVED |
+               SNDRV_PCM_INFO_BLOCK_TRANSFER |
+               SNDRV_PCM_INFO_MMAP_VALID,
+       .formats = SNDRV_PCM_FMTBIT_S16_LE,
+
+       .rates =                SNDRV_PCM_RATE_48000,
+       .rate_min =             48000,
+       .rate_max =             48000,
+       .channels_min = 2,
+       .channels_max = 2,
+       /* Analog audio output will be full of clicks and pops if there
+          are not exactly four lines in the SRAM FIFO buffer.  */
+       .period_bytes_min = DEFAULT_FIFO_SIZE/4,
+       .period_bytes_max = DEFAULT_FIFO_SIZE/4,
+       .periods_min = 1,
+       .periods_max = 1024,
+       .buffer_bytes_max = (1024*1024),
+};
+
+/*
+ * audio pcm capture open callback
+ */
+static int snd_cx23885_pcm_open(struct snd_pcm_substream *substream)
+{
+       struct cx23885_audio_dev *chip = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       int err;
+
+       if (!chip) {
+               printk(KERN_ERR "BUG: cx23885 can't find device struct."
+                               " Can't proceed with open\n");
+               return -ENODEV;
+       }
+
+       err = snd_pcm_hw_constraint_pow2(runtime, 0,
+               SNDRV_PCM_HW_PARAM_PERIODS);
+       if (err < 0)
+               goto _error;
+
+       chip->substream = substream;
+
+       runtime->hw = snd_cx23885_digital_hw;
+
+       if (chip->dev->sram_channels[AUDIO_SRAM_CHANNEL].fifo_size !=
+               DEFAULT_FIFO_SIZE) {
+               unsigned int bpl = chip->dev->
+                       sram_channels[AUDIO_SRAM_CHANNEL].fifo_size / 4;
+               bpl &= ~7; /* must be multiple of 8 */
+               runtime->hw.period_bytes_min = bpl;
+               runtime->hw.period_bytes_max = bpl;
+       }
+
+       return 0;
+_error:
+       dprintk(1, "Error opening PCM!\n");
+       return err;
+}
+
+/*
+ * audio close callback
+ */
+static int snd_cx23885_close(struct snd_pcm_substream *substream)
+{
+       return 0;
+}
+
+/*
+ * hw_params callback
+ */
+static int snd_cx23885_hw_params(struct snd_pcm_substream *substream,
+                             struct snd_pcm_hw_params *hw_params)
+{
+       struct cx23885_audio_dev *chip = snd_pcm_substream_chip(substream);
+       struct videobuf_dmabuf *dma;
+
+       struct cx23885_audio_buffer *buf;
+       int ret;
+
+       if (substream->runtime->dma_area) {
+               dsp_buffer_free(chip);
+               substream->runtime->dma_area = NULL;
+       }
+
+       chip->period_size = params_period_bytes(hw_params);
+       chip->num_periods = params_periods(hw_params);
+       chip->dma_size = chip->period_size * params_periods(hw_params);
+
+       BUG_ON(!chip->dma_size);
+       BUG_ON(chip->num_periods & (chip->num_periods-1));
+
+       buf = kzalloc(sizeof(*buf), GFP_KERNEL);
+       if (NULL == buf)
+               return -ENOMEM;
+
+       buf->bpl = chip->period_size;
+
+       dma = &buf->dma;
+       videobuf_dma_init(dma);
+       ret = videobuf_dma_init_kernel(dma, PCI_DMA_FROMDEVICE,
+                       (PAGE_ALIGN(chip->dma_size) >> PAGE_SHIFT));
+       if (ret < 0)
+               goto error;
+
+       ret = videobuf_dma_map(&chip->pci->dev, dma);
+       if (ret < 0)
+               goto error;
+
+       ret = cx23885_risc_databuffer(chip->pci, &buf->risc, dma->sglist,
+                                  chip->period_size, chip->num_periods, 1);
+       if (ret < 0)
+               goto error;
+
+       /* Loop back to start of program */
+       buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP|RISC_IRQ1|RISC_CNT_INC);
+       buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
+       buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
+
+       chip->buf = buf;
+       chip->dma_risc = dma;
+
+       substream->runtime->dma_area = chip->dma_risc->vaddr;
+       substream->runtime->dma_bytes = chip->dma_size;
+       substream->runtime->dma_addr = 0;
+
+       return 0;
+
+error:
+       kfree(buf);
+       return ret;
+}
+
+/*
+ * hw free callback
+ */
+static int snd_cx23885_hw_free(struct snd_pcm_substream *substream)
+{
+
+       struct cx23885_audio_dev *chip = snd_pcm_substream_chip(substream);
+
+       if (substream->runtime->dma_area) {
+               dsp_buffer_free(chip);
+               substream->runtime->dma_area = NULL;
+       }
+
+       return 0;
+}
+
+/*
+ * prepare callback
+ */
+static int snd_cx23885_prepare(struct snd_pcm_substream *substream)
+{
+       return 0;
+}
+
+/*
+ * trigger callback
+ */
+static int snd_cx23885_card_trigger(struct snd_pcm_substream *substream,
+       int cmd)
+{
+       struct cx23885_audio_dev *chip = snd_pcm_substream_chip(substream);
+       int err;
+
+       /* Local interrupts are already disabled by ALSA */
+       spin_lock(&chip->lock);
+
+       switch (cmd) {
+       case SNDRV_PCM_TRIGGER_START:
+               err = cx23885_start_audio_dma(chip);
+               break;
+       case SNDRV_PCM_TRIGGER_STOP:
+               err = cx23885_stop_audio_dma(chip);
+               break;
+       default:
+               err = -EINVAL;
+               break;
+       }
+
+       spin_unlock(&chip->lock);
+
+       return err;
+}
+
+/*
+ * pointer callback
+ */
+static snd_pcm_uframes_t snd_cx23885_pointer(
+       struct snd_pcm_substream *substream)
+{
+       struct cx23885_audio_dev *chip = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       u16 count;
+
+       count = atomic_read(&chip->count);
+
+       return runtime->period_size * (count & (runtime->periods-1));
+}
+
+/*
+ * page callback (needed for mmap)
+ */
+static struct page *snd_cx23885_page(struct snd_pcm_substream *substream,
+                               unsigned long offset)
+{
+       void *pageptr = substream->runtime->dma_area + offset;
+       return vmalloc_to_page(pageptr);
+}
+
+/*
+ * operators
+ */
+static struct snd_pcm_ops snd_cx23885_pcm_ops = {
+       .open = snd_cx23885_pcm_open,
+       .close = snd_cx23885_close,
+       .ioctl = snd_pcm_lib_ioctl,
+       .hw_params = snd_cx23885_hw_params,
+       .hw_free = snd_cx23885_hw_free,
+       .prepare = snd_cx23885_prepare,
+       .trigger = snd_cx23885_card_trigger,
+       .pointer = snd_cx23885_pointer,
+       .page = snd_cx23885_page,
+};
+
+/*
+ * create a PCM device
+ */
+static int snd_cx23885_pcm(struct cx23885_audio_dev *chip, int device,
+       char *name)
+{
+       int err;
+       struct snd_pcm *pcm;
+
+       err = snd_pcm_new(chip->card, name, device, 0, 1, &pcm);
+       if (err < 0)
+               return err;
+       pcm->private_data = chip;
+       strcpy(pcm->name, name);
+       snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_cx23885_pcm_ops);
+
+       return 0;
+}
+
+/****************************************************************************
+                       Basic Flow for Sound Devices
+ ****************************************************************************/
+
+/*
+ * Alsa Constructor - Component probe
+ */
+
+struct cx23885_audio_dev *cx23885_audio_register(struct cx23885_dev *dev)
+{
+       struct snd_card *card;
+       struct cx23885_audio_dev *chip;
+       int err;
+
+       if (disable_analog_audio)
+               return NULL;
+
+       if (dev->sram_channels[AUDIO_SRAM_CHANNEL].cmds_start == 0) {
+               printk(KERN_WARNING "%s(): Missing SRAM channel configuration "
+                       "for analog TV Audio\n", __func__);
+               return NULL;
+       }
+
+       err = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
+                       THIS_MODULE, sizeof(struct cx23885_audio_dev), &card);
+       if (err < 0)
+               goto error;
+
+       chip = (struct cx23885_audio_dev *) card->private_data;
+       chip->dev = dev;
+       chip->pci = dev->pci;
+       chip->card = card;
+       spin_lock_init(&chip->lock);
+
+       snd_card_set_dev(card, &dev->pci->dev);
+
+       err = snd_cx23885_pcm(chip, 0, "CX23885 Digital");
+       if (err < 0)
+               goto error;
+
+       strcpy(card->driver, "CX23885");
+       sprintf(card->shortname, "Conexant CX23885");
+       sprintf(card->longname, "%s at %s", card->shortname, dev->name);
+
+       err = snd_card_register(card);
+       if (err < 0)
+               goto error;
+
+       dprintk(0, "registered ALSA audio device\n");
+
+       return chip;
+
+error:
+       snd_card_free(card);
+       printk(KERN_ERR "%s(): Failed to register analog "
+                       "audio adapter\n", __func__);
+
+       return NULL;
+}
+
+/*
+ * ALSA destructor
+ */
+void cx23885_audio_unregister(struct cx23885_dev *dev)
+{
+       struct cx23885_audio_dev *chip = dev->audio_dev;
+
+       snd_card_free(chip->card);
+}
index 76b7563de39c9eadec8a492a7e01ad77138e776c..c3cf08945e4cf853f2acb959b64ab7eaac8291f7 100644 (file)
@@ -25,8 +25,8 @@
 #include <linux/delay.h>
 #include <media/cx25840.h>
 #include <linux/firmware.h>
+#include <misc/altera.h>
 
-#include "../../../staging/altera-stapl/altera.h"
 #include "cx23885.h"
 #include "tuner-xc2028.h"
 #include "netup-eeprom.h"
@@ -106,12 +106,14 @@ struct cx23885_board cx23885_boards[] = {
                        .vmux   =       CX25840_VIN7_CH3 |
                                        CX25840_VIN5_CH2 |
                                        CX25840_VIN2_CH1,
+                       .amux   = CX25840_AUDIO8,
                        .gpio0  = 0,
                }, {
                        .type   = CX23885_VMUX_COMPOSITE1,
                        .vmux   =       CX25840_VIN7_CH3 |
                                        CX25840_VIN4_CH2 |
                                        CX25840_VIN6_CH1,
+                       .amux   = CX25840_AUDIO7,
                        .gpio0  = 0,
                }, {
                        .type   = CX23885_VMUX_SVIDEO,
@@ -119,6 +121,7 @@ struct cx23885_board cx23885_boards[] = {
                                        CX25840_VIN4_CH2 |
                                        CX25840_VIN8_CH1 |
                                        CX25840_SVIDEO_ON,
+                       .amux   = CX25840_AUDIO7,
                        .gpio0  = 0,
                } },
        },
@@ -153,7 +156,30 @@ struct cx23885_board cx23885_boards[] = {
        },
        [CX23885_BOARD_HAUPPAUGE_HVR1500] = {
                .name           = "Hauppauge WinTV-HVR1500",
+               .porta          = CX23885_ANALOG_VIDEO,
                .portc          = CX23885_MPEG_DVB,
+               .tuner_type     = TUNER_XC2028,
+               .tuner_addr     = 0x61, /* 0xc2 >> 1 */
+               .input          = {{
+                       .type   = CX23885_VMUX_TELEVISION,
+                       .vmux   =       CX25840_VIN7_CH3 |
+                                       CX25840_VIN5_CH2 |
+                                       CX25840_VIN2_CH1,
+                       .gpio0  = 0,
+               }, {
+                       .type   = CX23885_VMUX_COMPOSITE1,
+                       .vmux   =       CX25840_VIN7_CH3 |
+                                       CX25840_VIN4_CH2 |
+                                       CX25840_VIN6_CH1,
+                       .gpio0  = 0,
+               }, {
+                       .type   = CX23885_VMUX_SVIDEO,
+                       .vmux   =       CX25840_VIN7_CH3 |
+                                       CX25840_VIN4_CH2 |
+                                       CX25840_VIN8_CH1 |
+                                       CX25840_SVIDEO_ON,
+                       .gpio0  = 0,
+               } },
        },
        [CX23885_BOARD_HAUPPAUGE_HVR1200] = {
                .name           = "Hauppauge WinTV-HVR1200",
@@ -387,6 +413,31 @@ struct cx23885_board cx23885_boards[] = {
                                .vmux   = CX25840_COMPOSITE1,
                } },
        },
+       [CX23885_BOARD_MPX885] = {
+               .name           = "MPX-885",
+               .porta          = CX23885_ANALOG_VIDEO,
+               .input          = {{
+                       .type   = CX23885_VMUX_COMPOSITE1,
+                       .vmux   = CX25840_COMPOSITE1,
+                       .amux   = CX25840_AUDIO6,
+                       .gpio0  = 0,
+               }, {
+                       .type   = CX23885_VMUX_COMPOSITE2,
+                       .vmux   = CX25840_COMPOSITE2,
+                       .amux   = CX25840_AUDIO6,
+                       .gpio0  = 0,
+               }, {
+                       .type   = CX23885_VMUX_COMPOSITE3,
+                       .vmux   = CX25840_COMPOSITE3,
+                       .amux   = CX25840_AUDIO7,
+                       .gpio0  = 0,
+               }, {
+                       .type   = CX23885_VMUX_COMPOSITE4,
+                       .vmux   = CX25840_COMPOSITE4,
+                       .amux   = CX25840_AUDIO7,
+                       .gpio0  = 0,
+               } },
+       },
 };
 const unsigned int cx23885_bcount = ARRAY_SIZE(cx23885_boards);
 
@@ -1415,6 +1466,8 @@ void cx23885_card_setup(struct cx23885_dev *dev)
        case CX23885_BOARD_HAUPPAUGE_HVR1290:
        case CX23885_BOARD_LEADTEK_WINFAST_PXTV1200:
        case CX23885_BOARD_GOTVIEW_X5_3D_HYBRID:
+       case CX23885_BOARD_HAUPPAUGE_HVR1500:
+       case CX23885_BOARD_MPX885:
                dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev,
                                &dev->i2c_bus[2].i2c_adap,
                                "cx25840", 0x88 >> 1, NULL);
index ee41a8882f58470db0f77057c318ca055bcb3802..40e68b22015eea4c54ce28babecd2701feb03d1c 100644 (file)
@@ -54,7 +54,7 @@ MODULE_PARM_DESC(card, "card type");
 
 #define dprintk(level, fmt, arg...)\
        do { if (debug >= level)\
-               printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\
+               printk(KERN_DEBUG "%s: " fmt, dev->name, ## arg);\
        } while (0)
 
 static unsigned int cx23885_devcount;
@@ -155,12 +155,12 @@ static struct sram_channel cx23885_sram_channels[] = {
                .cnt2_reg       = DMA5_CNT2,
        },
        [SRAM_CH07] = {
-               .name           = "ch7",
-               .cmds_start     = 0x0,
-               .ctrl_start     = 0x0,
-               .cdt            = 0x0,
-               .fifo_start     = 0x0,
-               .fifo_size      = 0x0,
+               .name           = "TV Audio",
+               .cmds_start     = 0x10190,
+               .ctrl_start     = 0x10480,
+               .cdt            = 0x10a00,
+               .fifo_start     = 0x7000,
+               .fifo_size      = 0x1000,
                .ptr1_reg       = DMA6_PTR1,
                .ptr2_reg       = DMA6_PTR2,
                .cnt1_reg       = DMA6_CNT1,
@@ -1082,10 +1082,10 @@ static void cx23885_dev_unregister(struct cx23885_dev *dev)
 static __le32 *cx23885_risc_field(__le32 *rp, struct scatterlist *sglist,
                               unsigned int offset, u32 sync_line,
                               unsigned int bpl, unsigned int padding,
-                              unsigned int lines)
+                              unsigned int lines,  unsigned int lpi)
 {
        struct scatterlist *sg;
-       unsigned int line, todo;
+       unsigned int line, todo, sol;
 
        /* sync instruction */
        if (sync_line != NO_SYNC_LINE)
@@ -1098,16 +1098,22 @@ static __le32 *cx23885_risc_field(__le32 *rp, struct scatterlist *sglist,
                        offset -= sg_dma_len(sg);
                        sg++;
                }
+
+               if (lpi && line > 0 && !(line % lpi))
+                       sol = RISC_SOL | RISC_IRQ1 | RISC_CNT_INC;
+               else
+                       sol = RISC_SOL;
+
                if (bpl <= sg_dma_len(sg)-offset) {
                        /* fits into current chunk */
-                       *(rp++) = cpu_to_le32(RISC_WRITE|RISC_SOL|RISC_EOL|bpl);
+                       *(rp++) = cpu_to_le32(RISC_WRITE|sol|RISC_EOL|bpl);
                        *(rp++) = cpu_to_le32(sg_dma_address(sg)+offset);
                        *(rp++) = cpu_to_le32(0); /* bits 63-32 */
                        offset += bpl;
                } else {
                        /* scanline needs to be split */
                        todo = bpl;
-                       *(rp++) = cpu_to_le32(RISC_WRITE|RISC_SOL|
+                       *(rp++) = cpu_to_le32(RISC_WRITE|sol|
                                            (sg_dma_len(sg)-offset));
                        *(rp++) = cpu_to_le32(sg_dma_address(sg)+offset);
                        *(rp++) = cpu_to_le32(0); /* bits 63-32 */
@@ -1164,10 +1170,10 @@ int cx23885_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,
        rp = risc->cpu;
        if (UNSET != top_offset)
                rp = cx23885_risc_field(rp, sglist, top_offset, 0,
-                                       bpl, padding, lines);
+                                       bpl, padding, lines, 0);
        if (UNSET != bottom_offset)
                rp = cx23885_risc_field(rp, sglist, bottom_offset, 0x200,
-                                       bpl, padding, lines);
+                                       bpl, padding, lines, 0);
 
        /* save pointer to jmp instruction address */
        risc->jmp = rp;
@@ -1175,11 +1181,11 @@ int cx23885_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,
        return 0;
 }
 
-static int cx23885_risc_databuffer(struct pci_dev *pci,
+int cx23885_risc_databuffer(struct pci_dev *pci,
                                   struct btcx_riscmem *risc,
                                   struct scatterlist *sglist,
                                   unsigned int bpl,
-                                  unsigned int lines)
+                                  unsigned int lines, unsigned int lpi)
 {
        u32 instructions;
        __le32 *rp;
@@ -1199,7 +1205,55 @@ static int cx23885_risc_databuffer(struct pci_dev *pci,
 
        /* write risc instructions */
        rp = risc->cpu;
-       rp = cx23885_risc_field(rp, sglist, 0, NO_SYNC_LINE, bpl, 0, lines);
+       rp = cx23885_risc_field(rp, sglist, 0, NO_SYNC_LINE,
+                               bpl, 0, lines, lpi);
+
+       /* save pointer to jmp instruction address */
+       risc->jmp = rp;
+       BUG_ON((risc->jmp - risc->cpu + 2) * sizeof(*risc->cpu) > risc->size);
+       return 0;
+}
+
+int cx23885_risc_vbibuffer(struct pci_dev *pci, struct btcx_riscmem *risc,
+                       struct scatterlist *sglist, unsigned int top_offset,
+                       unsigned int bottom_offset, unsigned int bpl,
+                       unsigned int padding, unsigned int lines)
+{
+       u32 instructions, fields;
+       __le32 *rp;
+       int rc;
+
+       fields = 0;
+       if (UNSET != top_offset)
+               fields++;
+       if (UNSET != bottom_offset)
+               fields++;
+
+       /* estimate risc mem: worst case is one write per page border +
+          one write per scan line + syncs + jump (all 2 dwords).  Padding
+          can cause next bpl to start close to a page border.  First DMA
+          region may be smaller than PAGE_SIZE */
+       /* write and jump need and extra dword */
+       instructions  = fields * (1 + ((bpl + padding) * lines)
+               / PAGE_SIZE + lines);
+       instructions += 2;
+       rc = btcx_riscmem_alloc(pci, risc, instructions*12);
+       if (rc < 0)
+               return rc;
+       /* write risc instructions */
+       rp = risc->cpu;
+
+       /* Sync to line 6, so US CC line 21 will appear in line '12'
+        * in the userland vbi payload */
+       if (UNSET != top_offset)
+               rp = cx23885_risc_field(rp, sglist, top_offset, 6,
+                                       bpl, padding, lines, 0);
+
+       if (UNSET != bottom_offset)
+               rp = cx23885_risc_field(rp, sglist, bottom_offset, 0x207,
+                                       bpl, padding, lines, 0);
+
+
 
        /* save pointer to jmp instruction address */
        risc->jmp = rp;
@@ -1207,6 +1261,7 @@ static int cx23885_risc_databuffer(struct pci_dev *pci,
        return 0;
 }
 
+
 int cx23885_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
                                u32 reg, u32 mask, u32 value)
 {
@@ -1517,7 +1572,7 @@ int cx23885_buf_prepare(struct videobuf_queue *q, struct cx23885_tsport *port,
                        goto fail;
                cx23885_risc_databuffer(dev->pci, &buf->risc,
                                        videobuf_to_dma(&buf->vb)->sglist,
-                                       buf->vb.width, buf->vb.height);
+                                       buf->vb.width, buf->vb.height, 0);
        }
        buf->vb.state = VIDEOBUF_PREPARED;
        return 0;
@@ -1741,15 +1796,19 @@ static irqreturn_t cx23885_irq(int irq, void *dev_id)
        struct cx23885_tsport *ts2 = &dev->ts2;
        u32 pci_status, pci_mask;
        u32 vida_status, vida_mask;
+       u32 audint_status, audint_mask;
        u32 ts1_status, ts1_mask;
        u32 ts2_status, ts2_mask;
        int vida_count = 0, ts1_count = 0, ts2_count = 0, handled = 0;
+       int audint_count = 0;
        bool subdev_handled;
 
        pci_status = cx_read(PCI_INT_STAT);
        pci_mask = cx23885_irq_get_mask(dev);
        vida_status = cx_read(VID_A_INT_STAT);
        vida_mask = cx_read(VID_A_INT_MSK);
+       audint_status = cx_read(AUDIO_INT_INT_STAT);
+       audint_mask = cx_read(AUDIO_INT_INT_MSK);
        ts1_status = cx_read(VID_B_INT_STAT);
        ts1_mask = cx_read(VID_B_INT_MSK);
        ts2_status = cx_read(VID_C_INT_STAT);
@@ -1759,12 +1818,15 @@ static irqreturn_t cx23885_irq(int irq, void *dev_id)
                goto out;
 
        vida_count = cx_read(VID_A_GPCNT);
+       audint_count = cx_read(AUD_INT_A_GPCNT);
        ts1_count = cx_read(ts1->reg_gpcnt);
        ts2_count = cx_read(ts2->reg_gpcnt);
        dprintk(7, "pci_status: 0x%08x  pci_mask: 0x%08x\n",
                pci_status, pci_mask);
        dprintk(7, "vida_status: 0x%08x vida_mask: 0x%08x count: 0x%x\n",
                vida_status, vida_mask, vida_count);
+       dprintk(7, "audint_status: 0x%08x audint_mask: 0x%08x count: 0x%x\n",
+               audint_status, audint_mask, audint_count);
        dprintk(7, "ts1_status: 0x%08x  ts1_mask: 0x%08x count: 0x%x\n",
                ts1_status, ts1_mask, ts1_count);
        dprintk(7, "ts2_status: 0x%08x  ts2_mask: 0x%08x count: 0x%x\n",
@@ -1861,6 +1923,9 @@ static irqreturn_t cx23885_irq(int irq, void *dev_id)
        if (vida_status)
                handled += cx23885_video_irq(dev, vida_status);
 
+       if (audint_status)
+               handled += cx23885_audio_irq(dev, audint_status, audint_mask);
+
        if (pci_status & PCI_MSK_IR) {
                subdev_handled = false;
                v4l2_subdev_call(dev->sd_ir, core, interrupt_service_routine,
index aa83f07b1b0f7bac44c7b72f1893c9346fabecb0..bcb45be44bb279a2085bd20f1491a58eee962d6e 100644 (file)
@@ -844,7 +844,7 @@ static int dvb_register(struct cx23885_tsport *port)
                        static struct xc2028_ctrl ctl = {
                                .fname   = XC3028L_DEFAULT_FIRMWARE,
                                .max_len = 64,
-                               .demod   = 5000,
+                               .demod   = XC3028_FE_DIBCOM52,
                                /* This is true for all demods with
                                        v36 firmware? */
                                .type    = XC2028_D2633,
index 307ff543c2543ba75251121411ca05f59e868d69..0ff7a9e98f3e637c6a9ef6d258c08e80de2e8c6c 100644 (file)
@@ -287,6 +287,7 @@ static char *i2c_devs[128] = {
        [0x32 >> 1] = "cx24227",
        [0x88 >> 1] = "cx25837",
        [0x84 >> 1] = "tda8295",
+       [0x98 >> 1] = "flatiron",
        [0xa0 >> 1] = "eeprom",
        [0xc0 >> 1] = "tuner/mt2131/tda8275",
        [0xc2 >> 1] = "tuner/mt2131/tda8275/xc5000/xc3028",
index c87ac682ebbef37d251c3b65967963b5371c4d31..a99936e0cbc270c5d9fe5ad29eeafd0101c4304d 100644 (file)
@@ -203,6 +203,7 @@ Channel manager Data Structure entry = 20 DWORD
 #define SD2_BIAS_CTRL  0x0000000A
 #define AMP_BIAS_CTRL  0x0000000C
 #define CH_PWR_CTRL1   0x0000000E
+#define FLD_CH_SEL      (1 << 3)
 #define CH_PWR_CTRL2   0x0000000F
 #define DSM_STATUS1    0x00000010
 #define DSM_STATUS2    0x00000011
@@ -271,7 +272,9 @@ Channel manager Data Structure entry = 20 DWORD
 #define VID_BC_MSK_OPC_ERR (1 << 16)
 #define VID_BC_MSK_SYNC    (1 << 12)
 #define VID_BC_MSK_OF      (1 <<  8)
+#define VID_BC_MSK_VBI_RISCI2 (1 <<  5)
 #define VID_BC_MSK_RISCI2  (1 <<  4)
+#define VID_BC_MSK_VBI_RISCI1 (1 <<  1)
 #define VID_BC_MSK_RISCI1   1
 
 #define VID_C_INT_MSK  0x00040040
index c0b60382ad13602ff9c2fc512cf92fe531568cc2..a1154f035bc185daa692f6ac5443a5067ff46169 100644 (file)
@@ -41,6 +41,12 @@ MODULE_PARM_DESC(vbi_debug, "enable debug messages [vbi]");
 
 /* ------------------------------------------------------------------ */
 
+#define VBI_LINE_LENGTH 1440
+#define NTSC_VBI_START_LINE 10        /* line 10 - 21 */
+#define NTSC_VBI_END_LINE   21
+#define NTSC_VBI_LINES      (NTSC_VBI_END_LINE - NTSC_VBI_START_LINE + 1)
+
+
 int cx23885_vbi_fmt(struct file *file, void *priv,
        struct v4l2_format *f)
 {
@@ -49,43 +55,86 @@ int cx23885_vbi_fmt(struct file *file, void *priv,
 
        if (dev->tvnorm & V4L2_STD_525_60) {
                /* ntsc */
-               f->fmt.vbi.sampling_rate = 28636363;
+               f->fmt.vbi.samples_per_line = VBI_LINE_LENGTH;
+               f->fmt.vbi.sampling_rate = 27000000;
+               f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
+               f->fmt.vbi.offset = 0;
+               f->fmt.vbi.flags = 0;
                f->fmt.vbi.start[0] = 10;
-               f->fmt.vbi.start[1] = 273;
-
+               f->fmt.vbi.count[0] = 17;
+               f->fmt.vbi.start[1] = 263 + 10 + 1;
+               f->fmt.vbi.count[1] = 17;
        } else if (dev->tvnorm & V4L2_STD_625_50) {
                /* pal */
                f->fmt.vbi.sampling_rate = 35468950;
                f->fmt.vbi.start[0] = 7 - 1;
                f->fmt.vbi.start[1] = 319 - 1;
        }
+
        return 0;
 }
 
+/* We're given the Video Interrupt status register.
+ * The cx23885_video_irq() func has already validated
+ * the potential error bits, we just need to
+ * deal with vbi payload and return indication if
+ * we actually processed any payload.
+ */
+int cx23885_vbi_irq(struct cx23885_dev *dev, u32 status)
+{
+       u32 count;
+       int handled = 0;
+
+       if (status & VID_BC_MSK_VBI_RISCI1) {
+               dprintk(1, "%s() VID_BC_MSK_VBI_RISCI1\n", __func__);
+               spin_lock(&dev->slock);
+               count = cx_read(VID_A_GPCNT);
+               cx23885_video_wakeup(dev, &dev->vbiq, count);
+               spin_unlock(&dev->slock);
+               handled++;
+       }
+
+       if (status & VID_BC_MSK_VBI_RISCI2) {
+               dprintk(1, "%s() VID_BC_MSK_VBI_RISCI2\n", __func__);
+               dprintk(2, "stopper vbi\n");
+               spin_lock(&dev->slock);
+               cx23885_restart_vbi_queue(dev, &dev->vbiq);
+               spin_unlock(&dev->slock);
+               handled++;
+       }
+
+       return handled;
+}
+
 static int cx23885_start_vbi_dma(struct cx23885_dev    *dev,
                         struct cx23885_dmaqueue *q,
                         struct cx23885_buffer   *buf)
 {
+       dprintk(1, "%s()\n", __func__);
+
        /* setup fifo + format */
        cx23885_sram_channel_setup(dev, &dev->sram_channels[SRAM_CH02],
                                buf->vb.width, buf->risc.dma);
 
        /* reset counter */
+       cx_write(VID_A_GPCNT_CTL, 3);
+       cx_write(VID_A_VBI_CTRL, 3);
+       cx_write(VBI_A_GPCNT_CTL, 3);
        q->count = 1;
 
-       /* enable irqs */
+       /* enable irq */
        cx23885_irq_add_enable(dev, 0x01);
        cx_set(VID_A_INT_MSK, 0x000022);
 
        /* start dma */
        cx_set(DEV_CNTRL2, (1<<5));
-       cx_set(VID_A_DMA_CTL, 0x00000022);
+       cx_set(VID_A_DMA_CTL, 0x22); /* FIFO and RISC enable */
 
        return 0;
 }
 
 
-static int cx23885_restart_vbi_queue(struct cx23885_dev    *dev,
+int cx23885_restart_vbi_queue(struct cx23885_dev    *dev,
                             struct cx23885_dmaqueue *q)
 {
        struct cx23885_buffer *buf;
@@ -102,7 +151,7 @@ static int cx23885_restart_vbi_queue(struct cx23885_dev    *dev,
                buf = list_entry(item, struct cx23885_buffer, vb.queue);
                buf->count = q->count++;
        }
-       mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
+       mod_timer(&q->timeout, jiffies + (BUFFER_TIMEOUT / 30));
        return 0;
 }
 
@@ -113,8 +162,7 @@ void cx23885_vbi_timeout(unsigned long data)
        struct cx23885_buffer *buf;
        unsigned long flags;
 
-       cx23885_sram_channel_dump(dev, &dev->sram_channels[SRAM_CH02]);
-
+       /* Stop the VBI engine */
        cx_clear(VID_A_DMA_CTL, 0x22);
 
        spin_lock_irqsave(&dev->slock, flags);
@@ -132,7 +180,7 @@ void cx23885_vbi_timeout(unsigned long data)
 }
 
 /* ------------------------------------------------------------------ */
-#define VBI_LINE_LENGTH 2048
+#define VBI_LINE_LENGTH 1440
 #define VBI_LINE_COUNT 17
 
 static int
@@ -173,7 +221,7 @@ vbi_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
                rc = videobuf_iolock(q, &buf->vb, NULL);
                if (0 != rc)
                        goto fail;
-               cx23885_risc_buffer(dev->pci, &buf->risc,
+               cx23885_risc_vbibuffer(dev->pci, &buf->risc,
                                 dma->sglist,
                                 0, buf->vb.width * buf->vb.height,
                                 buf->vb.width, 0,
@@ -207,7 +255,7 @@ vbi_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
                cx23885_start_vbi_dma(dev, q, buf);
                buf->vb.state = VIDEOBUF_ACTIVE;
                buf->count    = q->count++;
-               mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
+               mod_timer(&q->timeout, jiffies + (BUFFER_TIMEOUT / 30));
                dprintk(2, "[%p/%d] vbi_queue - first active\n",
                        buf, buf->vb.i);
 
index 896bb32dbf0301c53863dfae3ae7ae4d8a123fc1..e730b92630161b58b5d4c8278e48d394910b95b3 100644 (file)
@@ -37,6 +37,8 @@
 #include "cx23885-ioctl.h"
 #include "tuner-xc2028.h"
 
+#include <media/cx25840.h>
+
 MODULE_DESCRIPTION("v4l2 driver module for cx23885 based TV cards");
 MODULE_AUTHOR("Steven Toth <stoth@linuxtv.org>");
 MODULE_LICENSE("GPL");
@@ -69,14 +71,14 @@ MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes");
 
 #define dprintk(level, fmt, arg...)\
        do { if (video_debug >= level)\
-               printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\
+               printk(KERN_DEBUG "%s: " fmt, dev->name, ## arg);\
        } while (0)
 
 /* ------------------------------------------------------------------- */
 /* static data                                                         */
 
 #define FORMAT_FLAGS_PACKED       0x01
-
+#if 0
 static struct cx23885_fmt formats[] = {
        {
                .name     = "8 bpp, gray",
@@ -130,6 +132,23 @@ static struct cx23885_fmt formats[] = {
                .flags    = FORMAT_FLAGS_PACKED,
        },
 };
+#else
+static struct cx23885_fmt formats[] = {
+       {
+#if 0
+               .name     = "4:2:2, packed, UYVY",
+               .fourcc   = V4L2_PIX_FMT_UYVY,
+               .depth    = 16,
+               .flags    = FORMAT_FLAGS_PACKED,
+       }, {
+#endif
+               .name     = "4:2:2, packed, YUYV",
+               .fourcc   = V4L2_PIX_FMT_YUYV,
+               .depth    = 16,
+               .flags    = FORMAT_FLAGS_PACKED,
+       }
+};
+#endif
 
 static struct cx23885_fmt *format_by_fourcc(unsigned int fourcc)
 {
@@ -139,7 +158,12 @@ static struct cx23885_fmt *format_by_fourcc(unsigned int fourcc)
                if (formats[i].fourcc == fourcc)
                        return formats+i;
 
-       printk(KERN_ERR "%s(0x%08x) NOT FOUND\n", __func__, fourcc);
+       printk(KERN_ERR "%s(%c%c%c%c) NOT FOUND\n", __func__,
+               (fourcc & 0xff),
+               ((fourcc >> 8) & 0xff),
+               ((fourcc >> 16) & 0xff),
+               ((fourcc >> 24) & 0xff)
+               );
        return NULL;
 }
 
@@ -171,7 +195,7 @@ static struct cx23885_ctrl cx23885_ctls[] = {
                        .id            = V4L2_CID_CONTRAST,
                        .name          = "Contrast",
                        .minimum       = 0,
-                       .maximum       = 0xff,
+                       .maximum       = 0x7f,
                        .step          = 1,
                        .default_value = 0x3f,
                        .type          = V4L2_CTRL_TYPE_INTEGER,
@@ -184,10 +208,10 @@ static struct cx23885_ctrl cx23885_ctls[] = {
                .v = {
                        .id            = V4L2_CID_HUE,
                        .name          = "Hue",
-                       .minimum       = 0,
-                       .maximum       = 0xff,
+                       .minimum       = -127,
+                       .maximum       = 128,
                        .step          = 1,
-                       .default_value = 0x7f,
+                       .default_value = 0x0,
                        .type          = V4L2_CTRL_TYPE_INTEGER,
                },
                .off                   = 128,
@@ -202,9 +226,9 @@ static struct cx23885_ctrl cx23885_ctls[] = {
                        .id            = V4L2_CID_SATURATION,
                        .name          = "Saturation",
                        .minimum       = 0,
-                       .maximum       = 0xff,
+                       .maximum       = 0x7f,
                        .step          = 1,
-                       .default_value = 0x7f,
+                       .default_value = 0x3f,
                        .type          = V4L2_CTRL_TYPE_INTEGER,
                },
                .off                   = 0,
@@ -258,8 +282,8 @@ static const u32 *ctrl_classes[] = {
        NULL
 };
 
-static void cx23885_video_wakeup(struct cx23885_dev *dev,
-                struct cx23885_dmaqueue *q, u32 count)
+void cx23885_video_wakeup(struct cx23885_dev *dev,
+       struct cx23885_dmaqueue *q, u32 count)
 {
        struct cx23885_buffer *buf;
        int bc;
@@ -393,6 +417,71 @@ static void res_free(struct cx23885_dev *dev, struct cx23885_fh *fh,
        mutex_unlock(&dev->lock);
 }
 
+static int cx23885_flatiron_write(struct cx23885_dev *dev, u8 reg, u8 data)
+{
+       /* 8 bit registers, 8 bit values */
+       u8 buf[] = { reg, data };
+
+       struct i2c_msg msg = { .addr = 0x98 >> 1,
+               .flags = 0, .buf = buf, .len = 2 };
+
+       return i2c_transfer(&dev->i2c_bus[2].i2c_adap, &msg, 1);
+}
+
+static u8 cx23885_flatiron_read(struct cx23885_dev *dev, u8 reg)
+{
+       /* 8 bit registers, 8 bit values */
+       int ret;
+       u8 b0[] = { reg };
+       u8 b1[] = { 0 };
+
+       struct i2c_msg msg[] = {
+               { .addr = 0x98 >> 1, .flags = 0, .buf = b0, .len = 1 },
+               { .addr = 0x98 >> 1, .flags = I2C_M_RD, .buf = b1, .len = 1 }
+       };
+
+       ret = i2c_transfer(&dev->i2c_bus[2].i2c_adap, &msg[0], 2);
+       if (ret != 2)
+               printk(KERN_ERR "%s() error\n", __func__);
+
+       return b1[0];
+}
+
+static void cx23885_flatiron_dump(struct cx23885_dev *dev)
+{
+       int i;
+       dprintk(1, "Flatiron dump\n");
+       for (i = 0; i < 0x24; i++) {
+               dprintk(1, "FI[%02x] = %02x\n", i,
+                       cx23885_flatiron_read(dev, i));
+       }
+}
+
+static int cx23885_flatiron_mux(struct cx23885_dev *dev, int input)
+{
+       u8 val;
+       dprintk(1, "%s(input = %d)\n", __func__, input);
+
+       if (input == 1)
+               val = cx23885_flatiron_read(dev, CH_PWR_CTRL1) & ~FLD_CH_SEL;
+       else if (input == 2)
+               val = cx23885_flatiron_read(dev, CH_PWR_CTRL1) | FLD_CH_SEL;
+       else
+               return -EINVAL;
+
+       val |= 0x20; /* Enable clock to delta-sigma and dec filter */
+
+       cx23885_flatiron_write(dev, CH_PWR_CTRL1, val);
+
+       /* Wake up */
+       cx23885_flatiron_write(dev, CH_PWR_CTRL2, 0);
+
+       if (video_debug)
+               cx23885_flatiron_dump(dev);
+
+       return 0;
+}
+
 static int cx23885_video_mux(struct cx23885_dev *dev, unsigned int input)
 {
        dprintk(1, "%s() video_mux: %d [vmux=%d, gpio=0x%x,0x%x,0x%x,0x%x]\n",
@@ -413,27 +502,59 @@ static int cx23885_video_mux(struct cx23885_dev *dev, unsigned int input)
        v4l2_subdev_call(dev->sd_cx25840, video, s_routing,
                        INPUT(input)->vmux, 0, 0);
 
+       if ((dev->board == CX23885_BOARD_HAUPPAUGE_HVR1800) ||
+               (dev->board == CX23885_BOARD_MPX885)) {
+               /* Configure audio routing */
+               v4l2_subdev_call(dev->sd_cx25840, audio, s_routing,
+                       INPUT(input)->amux, 0, 0);
+
+               if (INPUT(input)->amux == CX25840_AUDIO7)
+                       cx23885_flatiron_mux(dev, 1);
+               else if (INPUT(input)->amux == CX25840_AUDIO6)
+                       cx23885_flatiron_mux(dev, 2);
+       }
+
        return 0;
 }
 
-/* ------------------------------------------------------------------ */
-static int cx23885_set_scale(struct cx23885_dev *dev, unsigned int width,
-       unsigned int height, enum v4l2_field field)
+static int cx23885_audio_mux(struct cx23885_dev *dev, unsigned int input)
 {
-       dprintk(1, "%s()\n", __func__);
+       dprintk(1, "%s(input=%d)\n", __func__, input);
+
+       /* The baseband video core of the cx23885 has two audio inputs.
+        * LR1 and LR2. In almost every single case so far only HVR1xxx
+        * cards we've only ever supported LR1. Time to support LR2,
+        * which is available via the optional white breakout header on
+        * the board.
+        * We'll use a could of existing enums in the card struct to allow
+        * devs to specify which baseband input they need, or just default
+        * to what we've always used.
+        */
+       if (INPUT(input)->amux == CX25840_AUDIO7)
+               cx23885_flatiron_mux(dev, 1);
+       else if (INPUT(input)->amux == CX25840_AUDIO6)
+               cx23885_flatiron_mux(dev, 2);
+       else {
+               /* Not specifically defined, assume the default. */
+               cx23885_flatiron_mux(dev, 1);
+       }
+
        return 0;
 }
 
+/* ------------------------------------------------------------------ */
 static int cx23885_start_video_dma(struct cx23885_dev *dev,
                           struct cx23885_dmaqueue *q,
                           struct cx23885_buffer *buf)
 {
        dprintk(1, "%s()\n", __func__);
 
+       /* Stop the dma/fifo before we tamper with it's risc programs */
+       cx_clear(VID_A_DMA_CTL, 0x11);
+
        /* setup fifo + format */
        cx23885_sram_channel_setup(dev, &dev->sram_channels[SRAM_CH01],
                                buf->bpl, buf->risc.dma);
-       cx23885_set_scale(dev, buf->vb.width, buf->vb.height, buf->vb.field);
 
        /* reset counter */
        cx_write(VID_A_GPCNT_CTL, 3);
@@ -748,7 +869,7 @@ static int video_open(struct file *file)
        fh->type     = type;
        fh->width    = 320;
        fh->height   = 240;
-       fh->fmt      = format_by_fourcc(V4L2_PIX_FMT_BGR24);
+       fh->fmt      = format_by_fourcc(V4L2_PIX_FMT_YUYV);
 
        videobuf_queue_sg_init(&fh->vidq, &cx23885_video_qops,
                            &dev->pci->dev, &dev->slock,
@@ -757,6 +878,14 @@ static int video_open(struct file *file)
                            sizeof(struct cx23885_buffer),
                            fh, NULL);
 
+       videobuf_queue_sg_init(&fh->vbiq, &cx23885_vbi_qops,
+               &dev->pci->dev, &dev->slock,
+               V4L2_BUF_TYPE_VBI_CAPTURE,
+               V4L2_FIELD_SEQ_TB,
+               sizeof(struct cx23885_buffer),
+               fh, NULL);
+
+
        dprintk(1, "post videobuf_queue_init()\n");
 
        return 0;
@@ -884,8 +1013,9 @@ static int cx23885_get_control(struct cx23885_dev *dev,
 static int cx23885_set_control(struct cx23885_dev *dev,
        struct v4l2_control *ctl)
 {
-       dprintk(1, "%s() calling cx25840(VIDIOC_S_CTRL)"
-               " (disabled - no action)\n", __func__);
+       dprintk(1, "%s() calling cx25840(VIDIOC_S_CTRL)\n", __func__);
+       call_all(dev, core, s_ctrl, ctl);
+
        return 0;
 }
 
@@ -1059,13 +1189,22 @@ static int vidioc_streamon(struct file *file, void *priv,
        struct cx23885_dev *dev = fh->dev;
        dprintk(1, "%s()\n", __func__);
 
-       if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE))
+       if ((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
+               (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE))
                return -EINVAL;
        if (unlikely(i != fh->type))
                return -EINVAL;
 
        if (unlikely(!res_get(dev, fh, get_resource(fh))))
                return -EBUSY;
+
+       /* Don't start VBI streaming unless vida streaming
+        * has already started.
+        */
+       if ((fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) &&
+               ((cx_read(VID_A_DMA_CTL) & 0x11) == 0))
+               return -EINVAL;
+
        return videobuf_streamon(get_queue(fh));
 }
 
@@ -1076,7 +1215,8 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
        int err, res;
        dprintk(1, "%s()\n", __func__);
 
-       if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+       if ((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
+               (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE))
                return -EINVAL;
        if (i != fh->type)
                return -EINVAL;
@@ -1119,7 +1259,7 @@ static int cx23885_enum_input(struct cx23885_dev *dev, struct v4l2_input *i)
        dprintk(1, "%s()\n", __func__);
 
        n = i->index;
-       if (n >= 4)
+       if (n >= MAX_CX23885_INPUT)
                return -EINVAL;
 
        if (0 == INPUT(n)->type)
@@ -1133,6 +1273,11 @@ static int cx23885_enum_input(struct cx23885_dev *dev, struct v4l2_input *i)
                i->type = V4L2_INPUT_TYPE_TUNER;
                i->std = CX23885_NORMS;
        }
+
+       /* Two selectable audio inputs for non-tv inputs */
+       if (INPUT(n)->type != CX23885_VMUX_TELEVISION)
+               i->audioset = 0x3;
+
        return 0;
 }
 
@@ -1159,13 +1304,20 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
 
        dprintk(1, "%s(%d)\n", __func__, i);
 
-       if (i >= 4) {
+       if (i >= MAX_CX23885_INPUT) {
                dprintk(1, "%s() -EINVAL\n", __func__);
                return -EINVAL;
        }
 
+       if (INPUT(i)->type == 0)
+               return -EINVAL;
+
        mutex_lock(&dev->lock);
        cx23885_video_mux(dev, i);
+
+       /* By default establish the default audio input for the card also */
+       /* Caller is free to use VIDIOC_S_AUDIO to override afterwards */
+       cx23885_audio_mux(dev, i);
        mutex_unlock(&dev->lock);
        return 0;
 }
@@ -1185,6 +1337,64 @@ static int vidioc_log_status(struct file *file, void *priv)
        return 0;
 }
 
+static int cx23885_query_audinput(struct file *file, void *priv,
+       struct v4l2_audio *i)
+{
+       struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
+       static const char *iname[] = {
+               [0] = "Baseband L/R 1",
+               [1] = "Baseband L/R 2",
+       };
+       unsigned int n;
+       dprintk(1, "%s()\n", __func__);
+
+       n = i->index;
+       if (n >= 2)
+               return -EINVAL;
+
+       memset(i, 0, sizeof(*i));
+       i->index = n;
+       strcpy(i->name, iname[n]);
+       i->capability  = V4L2_AUDCAP_STEREO;
+       i->mode  = V4L2_AUDMODE_AVL;
+       return 0;
+
+}
+
+static int vidioc_enum_audinput(struct file *file, void *priv,
+                               struct v4l2_audio *i)
+{
+       return cx23885_query_audinput(file, priv, i);
+}
+
+static int vidioc_g_audinput(struct file *file, void *priv,
+       struct v4l2_audio *i)
+{
+       struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
+
+       i->index = dev->audinput;
+       dprintk(1, "%s(input=%d)\n", __func__, i->index);
+
+       return cx23885_query_audinput(file, priv, i);
+}
+
+static int vidioc_s_audinput(struct file *file, void *priv,
+       struct v4l2_audio *i)
+{
+       struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
+       if (i->index >= 2)
+               return -EINVAL;
+
+       dprintk(1, "%s(%d)\n", __func__, i->index);
+
+       dev->audinput = i->index;
+
+       /* Skip the audio defaults from the cards struct, caller wants
+        * directly touch the audio mux hardware. */
+       cx23885_flatiron_mux(dev, dev->audinput + 1);
+       return 0;
+}
+
 static int vidioc_queryctrl(struct file *file, void *priv,
                                struct v4l2_queryctrl *qctrl)
 {
@@ -1221,10 +1431,8 @@ static int vidioc_g_tuner(struct file *file, void *priv,
                return -EINVAL;
 
        strcpy(t->name, "Television");
-       t->type       = V4L2_TUNER_ANALOG_TV;
-       t->capability = V4L2_TUNER_CAP_NORM;
-       t->rangehigh  = 0xffffffffUL;
-       t->signal = 0xffff ; /* LOCKED */
+
+       call_all(dev, tuner, g_tuner, t);
        return 0;
 }
 
@@ -1237,6 +1445,9 @@ static int vidioc_s_tuner(struct file *file, void *priv,
                return -EINVAL;
        if (0 != t->index)
                return -EINVAL;
+       /* Update the A/V core */
+       call_all(dev, tuner, s_tuner, t);
+
        return 0;
 }
 
@@ -1302,10 +1513,6 @@ static void cx23885_vid_timeout(unsigned long data)
        struct cx23885_buffer *buf;
        unsigned long flags;
 
-       cx23885_sram_channel_dump(dev, &dev->sram_channels[SRAM_CH01]);
-
-       cx_clear(VID_A_DMA_CTL, 0x11);
-
        spin_lock_irqsave(&dev->slock, flags);
        while (!list_empty(&q->active)) {
                buf = list_entry(q->active.next,
@@ -1313,7 +1520,7 @@ static void cx23885_vid_timeout(unsigned long data)
                list_del(&buf->vb.queue);
                buf->vb.state = VIDEOBUF_ERROR;
                wake_up(&buf->vb.done);
-               printk(KERN_ERR "%s/0: [%p/%d] timeout - dma=0x%08lx\n",
+               printk(KERN_ERR "%s: [%p/%d] timeout - dma=0x%08lx\n",
                        dev->name, buf, buf->vb.i,
                        (unsigned long)buf->risc.dma);
        }
@@ -1329,27 +1536,43 @@ int cx23885_video_irq(struct cx23885_dev *dev, u32 status)
        mask   = cx_read(VID_A_INT_MSK);
        if (0 == (status & mask))
                return handled;
+
        cx_write(VID_A_INT_STAT, status);
 
-       dprintk(2, "%s() status = 0x%08x\n", __func__, status);
-       /* risc op code error */
-       if (status & (1 << 16)) {
-               printk(KERN_WARNING "%s/0: video risc op code error\n",
-                       dev->name);
-               cx_clear(VID_A_DMA_CTL, 0x11);
-               cx23885_sram_channel_dump(dev, &dev->sram_channels[SRAM_CH01]);
+       /* risc op code error, fifo overflow or line sync detection error */
+       if ((status & VID_BC_MSK_OPC_ERR) ||
+               (status & VID_BC_MSK_SYNC) ||
+               (status & VID_BC_MSK_OF)) {
+
+               if (status & VID_BC_MSK_OPC_ERR) {
+                       dprintk(7, " (VID_BC_MSK_OPC_ERR 0x%08x)\n",
+                               VID_BC_MSK_OPC_ERR);
+                       printk(KERN_WARNING "%s: video risc op code error\n",
+                               dev->name);
+                       cx23885_sram_channel_dump(dev,
+                               &dev->sram_channels[SRAM_CH01]);
+               }
+
+               if (status & VID_BC_MSK_SYNC)
+                       dprintk(7, " (VID_BC_MSK_SYNC 0x%08x) "
+                               "video lines miss-match\n",
+                               VID_BC_MSK_SYNC);
+
+               if (status & VID_BC_MSK_OF)
+                       dprintk(7, " (VID_BC_MSK_OF 0x%08x) fifo overflow\n",
+                               VID_BC_MSK_OF);
+
        }
 
-       /* risc1 y */
-       if (status & 0x01) {
+       /* Video */
+       if (status & VID_BC_MSK_RISCI1) {
                spin_lock(&dev->slock);
                count = cx_read(VID_A_GPCNT);
                cx23885_video_wakeup(dev, &dev->vidq, count);
                spin_unlock(&dev->slock);
                handled++;
        }
-       /* risc2 y */
-       if (status & 0x10) {
+       if (status & VID_BC_MSK_RISCI2) {
                dprintk(2, "stopper video\n");
                spin_lock(&dev->slock);
                cx23885_restart_video_queue(dev, &dev->vidq);
@@ -1357,6 +1580,9 @@ int cx23885_video_irq(struct cx23885_dev *dev, u32 status)
                handled++;
        }
 
+       /* Allow the VBI framework to process it's payload */
+       handled += cx23885_vbi_irq(dev, status);
+
        return handled;
 }
 
@@ -1405,6 +1631,9 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
        .vidioc_g_register    = cx23885_g_register,
        .vidioc_s_register    = cx23885_s_register,
 #endif
+       .vidioc_enumaudio     = vidioc_enum_audinput,
+       .vidioc_g_audio       = vidioc_g_audinput,
+       .vidioc_s_audio       = vidioc_s_audinput,
 };
 
 static struct video_device cx23885_vbi_template;
@@ -1429,6 +1658,14 @@ void cx23885_video_unregister(struct cx23885_dev *dev)
        dprintk(1, "%s()\n", __func__);
        cx23885_irq_remove(dev, 0x01);
 
+       if (dev->vbi_dev) {
+               if (video_is_registered(dev->vbi_dev))
+                       video_unregister_device(dev->vbi_dev);
+               else
+                       video_device_release(dev->vbi_dev);
+               dev->vbi_dev = NULL;
+               btcx_riscmem_free(dev->pci, &dev->vbiq.stopper);
+       }
        if (dev->video_dev) {
                if (video_is_registered(dev->video_dev))
                        video_unregister_device(dev->video_dev);
@@ -1438,6 +1675,9 @@ void cx23885_video_unregister(struct cx23885_dev *dev)
 
                btcx_riscmem_free(dev->pci, &dev->vidq.stopper);
        }
+
+       if (dev->audio_dev)
+               cx23885_audio_unregister(dev);
 }
 
 int cx23885_video_register(struct cx23885_dev *dev)
@@ -1463,7 +1703,14 @@ int cx23885_video_register(struct cx23885_dev *dev)
        cx23885_risc_stopper(dev->pci, &dev->vidq.stopper,
                VID_A_DMA_CTL, 0x11, 0x00);
 
-       /* Don't enable VBI yet */
+       /* init vbi dma queues */
+       INIT_LIST_HEAD(&dev->vbiq.active);
+       INIT_LIST_HEAD(&dev->vbiq.queued);
+       dev->vbiq.timeout.function = cx23885_vbi_timeout;
+       dev->vbiq.timeout.data = (unsigned long)dev;
+       init_timer(&dev->vbiq.timeout);
+       cx23885_risc_stopper(dev->pci, &dev->vbiq.stopper,
+               VID_A_DMA_CTL, 0x22, 0x00);
 
        cx23885_irq_add_enable(dev, 0x01);
 
@@ -1504,8 +1751,7 @@ int cx23885_video_register(struct cx23885_dev *dev)
                }
        }
 
-
-       /* register v4l devices */
+       /* register Video device */
        dev->video_dev = cx23885_vdev_init(dev, dev->pci,
                &cx23885_video_template, "video");
        err = video_register_device(dev->video_dev, VFL_TYPE_GRABBER,
@@ -1515,13 +1761,31 @@ int cx23885_video_register(struct cx23885_dev *dev)
                        dev->name);
                goto fail_unreg;
        }
-       printk(KERN_INFO "%s/0: registered device %s [v4l2]\n",
+       printk(KERN_INFO "%s: registered device %s [v4l2]\n",
               dev->name, video_device_node_name(dev->video_dev));
+
+       /* register VBI device */
+       dev->vbi_dev = cx23885_vdev_init(dev, dev->pci,
+               &cx23885_vbi_template, "vbi");
+       err = video_register_device(dev->vbi_dev, VFL_TYPE_VBI,
+                                   vbi_nr[dev->nr]);
+       if (err < 0) {
+               printk(KERN_INFO "%s: can't register vbi device\n",
+                       dev->name);
+               goto fail_unreg;
+       }
+       printk(KERN_INFO "%s: registered device %s\n",
+              dev->name, video_device_node_name(dev->vbi_dev));
+
+       /* Register ALSA audio device */
+       dev->audio_dev = cx23885_audio_register(dev);
+
        /* initial device configuration */
        mutex_lock(&dev->lock);
        cx23885_set_tvnorm(dev, dev->tvnorm);
        init_controls(dev);
        cx23885_video_mux(dev, 0);
+       cx23885_audio_mux(dev, 0);
        mutex_unlock(&dev->lock);
 
        return 0;
index d86bc0b1317baca5fdd32b23fb6a1401396c1000..b49036fe3ffdc52fcea1bf946a423594e4a5f242 100644 (file)
@@ -86,6 +86,7 @@
 #define CX23885_BOARD_GOTVIEW_X5_3D_HYBRID     29
 #define CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF 30
 #define CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H_XC4000 31
+#define CX23885_BOARD_MPX885                   32
 
 #define GPIO_0 0x00000001
 #define GPIO_1 0x00000002
@@ -192,6 +193,7 @@ struct cx23885_buffer {
 struct cx23885_input {
        enum cx23885_itype type;
        unsigned int    vmux;
+       unsigned int    amux;
        u32             gpio0, gpio1, gpio2, gpio3;
 };
 
@@ -318,6 +320,34 @@ struct cx23885_kernel_ir {
        struct rc_dev           *rc;
 };
 
+struct cx23885_audio_buffer {
+       unsigned int            bpl;
+       struct btcx_riscmem     risc;
+       struct videobuf_dmabuf  dma;
+};
+
+struct cx23885_audio_dev {
+       struct cx23885_dev      *dev;
+
+       struct pci_dev          *pci;
+
+       struct snd_card         *card;
+
+       spinlock_t              lock;
+
+       atomic_t                count;
+
+       unsigned int            dma_size;
+       unsigned int            period_size;
+       unsigned int            num_periods;
+
+       struct videobuf_dmabuf  *dma_risc;
+
+       struct cx23885_audio_buffer   *buf;
+
+       struct snd_pcm_substream *substream;
+};
+
 struct cx23885_dev {
        atomic_t                   refcount;
        struct v4l2_device         v4l2_dev;
@@ -362,6 +392,7 @@ struct cx23885_dev {
        /* Analog video */
        u32                        resources;
        unsigned int               input;
+       unsigned int               audinput; /* Selectable audio input */
        u32                        tvaudio;
        v4l2_std_id                tvnorm;
        unsigned int               tuner_type;
@@ -400,6 +431,9 @@ struct cx23885_dev {
        atomic_t                   v4l_reader_count;
        struct cx23885_tvnorm      encodernorm;
 
+       /* Analog raw audio */
+       struct cx23885_audio_dev   *audio_dev;
+
 };
 
 static inline struct cx23885_dev *to_cx23885(struct v4l2_device *v4l2_dev)
@@ -478,6 +512,11 @@ extern int cx23885_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,
        unsigned int top_offset, unsigned int bottom_offset,
        unsigned int bpl, unsigned int padding, unsigned int lines);
 
+extern int cx23885_risc_vbibuffer(struct pci_dev *pci,
+       struct btcx_riscmem *risc, struct scatterlist *sglist,
+       unsigned int top_offset, unsigned int bottom_offset,
+       unsigned int bpl, unsigned int padding, unsigned int lines);
+
 void cx23885_cancel_buffers(struct cx23885_tsport *port);
 
 extern int cx23885_restart_queue(struct cx23885_tsport *port,
@@ -533,6 +572,8 @@ extern void cx23885_free_buffer(struct videobuf_queue *q,
 extern int cx23885_video_register(struct cx23885_dev *dev);
 extern void cx23885_video_unregister(struct cx23885_dev *dev);
 extern int cx23885_video_irq(struct cx23885_dev *dev, u32 status);
+extern void cx23885_video_wakeup(struct cx23885_dev *dev,
+       struct cx23885_dmaqueue *q, u32 count);
 
 /* ----------------------------------------------------------- */
 /* cx23885-vbi.c                                               */
@@ -540,6 +581,9 @@ extern int cx23885_vbi_fmt(struct file *file, void *priv,
        struct v4l2_format *f);
 extern void cx23885_vbi_timeout(unsigned long data);
 extern struct videobuf_queue_ops cx23885_vbi_qops;
+extern int cx23885_restart_vbi_queue(struct cx23885_dev *dev,
+       struct cx23885_dmaqueue *q);
+extern int cx23885_vbi_irq(struct cx23885_dev *dev, u32 status);
 
 /* cx23885-i2c.c                                                */
 extern int cx23885_i2c_register(struct cx23885_i2c *bus);
@@ -563,6 +607,18 @@ extern void mc417_gpio_set(struct cx23885_dev *dev, u32 mask);
 extern void mc417_gpio_clear(struct cx23885_dev *dev, u32 mask);
 extern void mc417_gpio_enable(struct cx23885_dev *dev, u32 mask, int asoutput);
 
+/* ----------------------------------------------------------- */
+/* cx23885-alsa.c                                             */
+extern struct cx23885_audio_dev *cx23885_audio_register(
+                                       struct cx23885_dev *dev);
+extern void cx23885_audio_unregister(struct cx23885_dev *dev);
+extern int cx23885_audio_irq(struct cx23885_dev *dev, u32 status, u32 mask);
+extern int cx23885_risc_databuffer(struct pci_dev *pci,
+                                  struct btcx_riscmem *risc,
+                                  struct scatterlist *sglist,
+                                  unsigned int bpl,
+                                  unsigned int lines,
+                                  unsigned int lpi);
 
 /* ----------------------------------------------------------- */
 /* tv norms                                                    */
index e37be6fcf67dba7d43b32006d749e79e5db73954..bb1ce346425d309fe1a618ec23ffcc214fb5987c 100644 (file)
@@ -673,7 +673,7 @@ static int cx23888_ir_rx_read(struct v4l2_subdev *sd, u8 *buf, size_t count,
 
        unsigned int i, n;
        union cx23888_ir_fifo_rec *p;
-       unsigned u, v;
+       unsigned u, v, w;
 
        n = count / sizeof(union cx23888_ir_fifo_rec)
                * sizeof(union cx23888_ir_fifo_rec);
@@ -692,11 +692,12 @@ static int cx23888_ir_rx_read(struct v4l2_subdev *sd, u8 *buf, size_t count,
                if ((p->hw_fifo_data & FIFO_RXTX_RTO) == FIFO_RXTX_RTO) {
                        /* Assume RTO was because of no IR light input */
                        u = 0;
-                       v4l2_dbg(2, ir_888_debug, sd, "rx read: end of rx\n");
+                       w = 1;
                } else {
                        u = (p->hw_fifo_data & FIFO_RXTX_LVL) ? 1 : 0;
                        if (invert)
                                u = u ? 0 : 1;
+                       w = 0;
                }
 
                v = (unsigned) pulse_width_count_to_ns(
@@ -707,9 +708,12 @@ static int cx23888_ir_rx_read(struct v4l2_subdev *sd, u8 *buf, size_t count,
                init_ir_raw_event(&p->ir_core_data);
                p->ir_core_data.pulse = u;
                p->ir_core_data.duration = v;
+               p->ir_core_data.timeout = w;
 
-               v4l2_dbg(2, ir_888_debug, sd, "rx read: %10u ns  %s\n",
-                        v, u ? "mark" : "space");
+               v4l2_dbg(2, ir_888_debug, sd, "rx read: %10u ns  %s  %s\n",
+                        v, u ? "mark" : "space", w ? "(timed out)" : "");
+               if (w)
+                       v4l2_dbg(2, ir_888_debug, sd, "rx read: end of rx\n");
        }
        return 0;
 }
index 2ee96d3973b865277766ca95e78af54f10f98ff3..dc40dde2e0c8449a85bb81119b319168b99532e3 100644 (file)
@@ -3,4 +3,4 @@ cx25840-objs    := cx25840-core.o cx25840-audio.o cx25840-firmware.o \
 
 obj-$(CONFIG_VIDEO_CX25840) += cx25840.o
 
-EXTRA_CFLAGS += -Idrivers/media/video
+ccflags-y += -Idrivers/media/video
index 34b96c7cfd620007b88a7082166413c284ac7a0e..005f11093642711cc854dce2decb70760ee08fdd 100644 (file)
@@ -480,6 +480,7 @@ void cx25840_audio_set_path(struct i2c_client *client)
 
 static void set_volume(struct i2c_client *client, int volume)
 {
+       struct cx25840_state *state = to_state(i2c_get_clientdata(client));
        int vol;
 
        /* Convert the volume to msp3400 values (0-127) */
@@ -495,7 +496,14 @@ static void set_volume(struct i2c_client *client, int volume)
        }
 
        /* PATH1_VOLUME */
-       cx25840_write(client, 0x8d4, 228 - (vol * 2));
+       if (is_cx2388x(state)) {
+               /* for cx23885 volume doesn't work,
+                * the calculation always results in
+                * e4 regardless.
+                */
+               cx25840_write(client, 0x8d4, volume);
+       } else
+               cx25840_write(client, 0x8d4, 228 - (vol * 2));
 }
 
 static void set_balance(struct i2c_client *client, int balance)
index b7ee2ae70583decb1c2afabbfdca62949532e699..cd9976408ab33050498633ee5c8c3e87a8d2f24c 100644 (file)
@@ -702,6 +702,13 @@ static void cx231xx_initialize(struct i2c_client *client)
 
        /* start microcontroller */
        cx25840_and_or(client, 0x803, ~0x10, 0x10);
+
+       /* CC raw enable */
+       cx25840_write(client, 0x404, 0x0b);
+
+       /* CC on */
+       cx25840_write(client, 0x42f, 0x66);
+       cx25840_write4(client, 0x474, 0x1e1e601a);
 }
 
 /* ----------------------------------------------------------------------- */
@@ -1067,6 +1074,18 @@ static int set_input(struct i2c_client *client, enum cx25840_video_input vid_inp
                cx25840_write(client, 0x919, 0x01);
        }
 
+       if (is_cx2388x(state) && ((aud_input == CX25840_AUDIO7) ||
+               (aud_input == CX25840_AUDIO6))) {
+               /* Configure audio from LR1 or LR2 input */
+               cx25840_write4(client, 0x910, 0);
+               cx25840_write4(client, 0x8d0, 0x63073);
+       } else
+       if (is_cx2388x(state) && (aud_input == CX25840_AUDIO8)) {
+               /* Configure audio from tuner/sif input */
+               cx25840_write4(client, 0x910, 0x12b000c9);
+               cx25840_write4(client, 0x8d0, 0x1f063870);
+       }
+
        return 0;
 }
 
index 7eb79af28aa3737780ca3cf7ea101b5530094874..b718a3a4bed359ecfa3b7b178ce56508c79a920c 100644 (file)
@@ -668,7 +668,7 @@ static int cx25840_ir_rx_read(struct v4l2_subdev *sd, u8 *buf, size_t count,
        u16 divider;
        unsigned int i, n;
        union cx25840_ir_fifo_rec *p;
-       unsigned u, v;
+       unsigned u, v, w;
 
        if (ir_state == NULL)
                return -ENODEV;
@@ -694,11 +694,12 @@ static int cx25840_ir_rx_read(struct v4l2_subdev *sd, u8 *buf, size_t count,
                if ((p->hw_fifo_data & FIFO_RXTX_RTO) == FIFO_RXTX_RTO) {
                        /* Assume RTO was because of no IR light input */
                        u = 0;
-                       v4l2_dbg(2, ir_debug, sd, "rx read: end of rx\n");
+                       w = 1;
                } else {
                        u = (p->hw_fifo_data & FIFO_RXTX_LVL) ? 1 : 0;
                        if (invert)
                                u = u ? 0 : 1;
+                       w = 0;
                }
 
                v = (unsigned) pulse_width_count_to_ns(
@@ -709,9 +710,12 @@ static int cx25840_ir_rx_read(struct v4l2_subdev *sd, u8 *buf, size_t count,
                init_ir_raw_event(&p->ir_core_data);
                p->ir_core_data.pulse = u;
                p->ir_core_data.duration = v;
+               p->ir_core_data.timeout = w;
 
-               v4l2_dbg(2, ir_debug, sd, "rx read: %10u ns  %s\n",
-                        v, u ? "mark" : "space");
+               v4l2_dbg(2, ir_debug, sd, "rx read: %10u ns  %s  %s\n",
+                        v, u ? "mark" : "space", w ? "(timed out)" : "");
+               if (w)
+                       v4l2_dbg(2, ir_debug, sd, "rx read: end of rx\n");
        }
        return 0;
 }
index 5b7e26761f0a78006ebfd064dbc667db4edcc8b7..c1a2785ba2431a607e9791edeeae6fa4f05adb5c 100644 (file)
@@ -10,7 +10,7 @@ obj-$(CONFIG_VIDEO_CX88_BLACKBIRD) += cx88-blackbird.o
 obj-$(CONFIG_VIDEO_CX88_DVB) += cx88-dvb.o
 obj-$(CONFIG_VIDEO_CX88_VP3054) += cx88-vp3054-i2c.o
 
-EXTRA_CFLAGS += -Idrivers/media/video
-EXTRA_CFLAGS += -Idrivers/media/common/tuners
-EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
-EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
+ccflags-y += -Idrivers/media/video
+ccflags-y += -Idrivers/media/common/tuners
+ccflags-y += -Idrivers/media/dvb/dvb-core
+ccflags-y += -Idrivers/media/dvb/frontends
index fbcaa1c5b09da7b43b7f54024a56c4ba7297e55f..fbfdd8067937604ab31482727a3204de970a6167 100644 (file)
@@ -636,9 +636,6 @@ int cx88_reset(struct cx88_core *core)
        cx_write(MO_PCI_INTSTAT,   0xFFFFFFFF); // Clear PCI int
        cx_write(MO_INT1_STAT,     0xFFFFFFFF); // Clear RISC int
 
-       /* set default notch filter */
-       cx_andor(MO_HTOTAL, 0x1800, (HLNotchFilter4xFsc << 11));
-
        /* Reset on-board parts */
        cx_write(MO_SRST_IO, 0);
        msleep(10);
index 60d28fdd77911c286a1d9ec365aa37e976f5cdee..921c56d115d6e06ec228f4edd7d301f4b5fe338c 100644 (file)
@@ -266,7 +266,7 @@ static const struct cx88_ctrl cx8800_ctls[] = {
                        .id            = V4L2_CID_BAND_STOP_FILTER,
                        .name          = "Notch filter",
                        .minimum       = 0,
-                       .maximum       = 3,
+                       .maximum       = 1,
                        .step          = 1,
                        .default_value = 0x0,
                        .type          = V4L2_CTRL_TYPE_INTEGER,
index 7f1d83a6d5759e1ec0132bdfa7bd61bcfa7f222c..8588a86d9b45ecb31335924b5259499fd310d69c 100644 (file)
@@ -43,7 +43,6 @@
 
 static int debug;
 
-#define VPBE_DISPLAY_SD_BUF_SIZE (720*576*2)
 #define VPBE_DEFAULT_NUM_BUFS 3
 
 module_param(debug, int, 0644);
index 5352884998f5bb7542157ee0d938ae262815617e..ceccf43025189743960ac711bae3cf8c01b4cda6 100644 (file)
@@ -1162,7 +1162,7 @@ static int osd_probe(struct platform_device *pdev)
                goto free_mem;
        }
        osd->osd_base_phys = res->start;
-       osd->osd_size = res->end - res->start + 1;
+       osd->osd_size = resource_size(res);
        if (!request_mem_region(osd->osd_base_phys, osd->osd_size,
                                MODULE_NAME)) {
                dev_err(osd->dev, "Unable to reserve OSD MMIO region\n");
index 281ee427c2ab6a20734b6af8082b3340cfbee144..f6f622e123bdbf4c7ad301b41f845eb2faaf7837 100644 (file)
@@ -41,6 +41,8 @@ config VIDEO_EM28XX_DVB
        select DVB_CXD2820R if !DVB_FE_CUSTOMISE
        select DVB_DRXK if !DVB_FE_CUSTOMISE
        select DVB_TDA18271C2DD if !DVB_FE_CUSTOMISE
+       select DVB_TDA10071 if !DVB_FE_CUSTOMISE
+       select DVB_A8293 if !DVB_FE_CUSTOMISE
        select VIDEOBUF_DVB
        ---help---
          This adds support for DVB cards based on the
index 38aaa004f57d6b64e6f6dd57ca3c85ddc2f31221..2abdf76c5203f32fb64bce891e3641f6fbb84623 100644 (file)
@@ -9,8 +9,8 @@ obj-$(CONFIG_VIDEO_EM28XX) += em28xx.o
 obj-$(CONFIG_VIDEO_EM28XX_ALSA) += em28xx-alsa.o
 obj-$(CONFIG_VIDEO_EM28XX_DVB) += em28xx-dvb.o
 
-EXTRA_CFLAGS += -Idrivers/media/video
-EXTRA_CFLAGS += -Idrivers/media/common/tuners
-EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
-EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
+ccflags-y += -Idrivers/media/video
+ccflags-y += -Idrivers/media/common/tuners
+ccflags-y += -Idrivers/media/dvb/dvb-core
+ccflags-y += -Idrivers/media/dvb/frontends
 
index 3e3959fee4195cad5bfc6070d42250f57e2c96a2..4240f0b720fa293556ccfd8f76a843d47144b064 100644 (file)
@@ -60,7 +60,7 @@ static unsigned int card[]     = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET };
 module_param_array(card,  int, NULL, 0444);
 MODULE_PARM_DESC(card,     "card type");
 
-/* Bitmask marking allocated devices from 0 to EM28XX_MAXBOARDS */
+/* Bitmask marking allocated devices from 0 to EM28XX_MAXBOARDS - 1 */
 static unsigned long em28xx_devused;
 
 struct em28xx_hash_table {
@@ -317,6 +317,25 @@ static struct em28xx_reg_seq terratec_h5_digital[] = {
 };
 #endif
 
+/* 2013:024f PCTV DVB-S2 Stick 460e
+ * GPIO_0 - POWER_ON
+ * GPIO_1 - BOOST
+ * GPIO_2 - VUV_LNB (red LED)
+ * GPIO_3 - EXT_12V
+ * GPIO_4 - INT_DEM (DEMOD GPIO_0)
+ * GPIO_5 - INT_LNB
+ * GPIO_6 - RESET_DEM
+ * GPIO_7 - LED (green LED)
+ */
+static struct em28xx_reg_seq pctv_460e[] = {
+       {EM2874_R80_GPIO, 0x01, 0xff,  50},
+       {0x0d,            0xff, 0xff,  50},
+       {EM2874_R80_GPIO, 0x41, 0xff,  50}, /* GPIO_6=1 */
+       {0x0d,            0x42, 0xff,  50},
+       {EM2874_R80_GPIO, 0x61, 0xff,  50}, /* GPIO_5=1 */
+       {             -1,   -1,   -1,  -1},
+};
+
 /*
  *  Board definitions
  */
@@ -1810,6 +1829,17 @@ struct em28xx_board em28xx_boards[] = {
                .has_dvb       = 1,
                .ir_codes      = RC_MAP_PINNACLE_PCTV_HD,
        },
+       /* 2013:024f PCTV DVB-S2 Stick 460e
+        * Empia EM28174, NXP TDA10071, Conexant CX24118A and Allegro A8293 */
+       [EM28174_BOARD_PCTV_460E] = {
+               .i2c_speed     = EM2874_I2C_SECONDARY_BUS_SELECT |
+                       EM28XX_I2C_CLK_WAIT_ENABLE | EM28XX_I2C_FREQ_400_KHZ,
+               .name          = "PCTV DVB-S2 Stick (460e)",
+               .tuner_type    = TUNER_ABSENT,
+               .tuner_gpio    = pctv_460e,
+               .has_dvb       = 1,
+               .ir_codes      = RC_MAP_PINNACLE_PCTV_HD,
+       },
 };
 const unsigned int em28xx_bcount = ARRAY_SIZE(em28xx_boards);
 
@@ -1941,6 +1971,8 @@ struct usb_device_id em28xx_id_table[] = {
                        .driver_info = EM2870_BOARD_KWORLD_A340 },
        { USB_DEVICE(0x2013, 0x024f),
                        .driver_info = EM28174_BOARD_PCTV_290E },
+       { USB_DEVICE(0x2013, 0x024c),
+                       .driver_info = EM28174_BOARD_PCTV_460E },
        { },
 };
 MODULE_DEVICE_TABLE(usb, em28xx_id_table);
@@ -2768,9 +2800,9 @@ static void flush_request_modules(struct em28xx *dev)
 #endif /* CONFIG_MODULES */
 
 /*
- * em28xx_realease_resources()
+ * em28xx_release_resources()
  * unregisters the v4l2,i2c and usb devices
- * called when the device gets disconected or at module unload
+ * called when the device gets disconnected or at module unload
 */
 void em28xx_release_resources(struct em28xx *dev)
 {
@@ -2784,8 +2816,6 @@ void em28xx_release_resources(struct em28xx *dev)
 
        em28xx_release_analog_resources(dev);
 
-       em28xx_remove_from_devlist(dev);
-
        em28xx_i2c_unregister(dev);
 
        v4l2_device_unregister(&dev->v4l2_dev);
@@ -2793,7 +2823,7 @@ void em28xx_release_resources(struct em28xx *dev)
        usb_put_dev(dev->udev);
 
        /* Mark device as unused */
-       em28xx_devused &= ~(1 << dev->devno);
+       clear_bit(dev->devno, &em28xx_devused);
 };
 
 /*
@@ -2806,7 +2836,6 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
 {
        struct em28xx *dev = *devhandle;
        int retval;
-       int errCode;
 
        dev->udev = udev;
        mutex_init(&dev->ctrl_urb_lock);
@@ -2883,10 +2912,9 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
        }
 
        if (dev->is_audio_only) {
-               errCode = em28xx_audio_setup(dev);
-               if (errCode)
+               retval = em28xx_audio_setup(dev);
+               if (retval)
                        return -ENODEV;
-               em28xx_add_into_devlist(dev);
                em28xx_init_extension(dev);
 
                return 0;
@@ -2903,7 +2931,7 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
                /* Resets I2C speed */
                em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, dev->board.i2c_speed);
                if (retval < 0) {
-                       em28xx_errdev("%s: em28xx_write_regs_req failed!"
+                       em28xx_errdev("%s: em28xx_write_reg failed!"
                                      " retval [%d]\n",
                                      __func__, retval);
                        return retval;
@@ -2917,12 +2945,11 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
        }
 
        /* register i2c bus */
-       errCode = em28xx_i2c_register(dev);
-       if (errCode < 0) {
-               v4l2_device_unregister(&dev->v4l2_dev);
-               em28xx_errdev("%s: em28xx_i2c_register - errCode [%d]!\n",
-                       __func__, errCode);
-               return errCode;
+       retval = em28xx_i2c_register(dev);
+       if (retval < 0) {
+               em28xx_errdev("%s: em28xx_i2c_register - error [%d]!\n",
+                       __func__, retval);
+               goto unregister_dev;
        }
 
        /*
@@ -2936,11 +2963,11 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
        em28xx_card_setup(dev);
 
        /* Configure audio */
-       errCode = em28xx_audio_setup(dev);
-       if (errCode < 0) {
-               v4l2_device_unregister(&dev->v4l2_dev);
-               em28xx_errdev("%s: Error while setting audio - errCode [%d]!\n",
-                       __func__, errCode);
+       retval = em28xx_audio_setup(dev);
+       if (retval < 0) {
+               em28xx_errdev("%s: Error while setting audio - error [%d]!\n",
+                       __func__, retval);
+               goto fail;
        }
 
        /* wake i2c devices */
@@ -2954,41 +2981,41 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
 
        if (dev->board.has_msp34xx) {
                /* Send a reset to other chips via gpio */
-               errCode = em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xf7);
-               if (errCode < 0) {
-                       em28xx_errdev("%s: em28xx_write_regs_req - "
-                                     "msp34xx(1) failed! errCode [%d]\n",
-                                     __func__, errCode);
-                       return errCode;
+               retval = em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xf7);
+               if (retval < 0) {
+                       em28xx_errdev("%s: em28xx_write_reg - "
+                                     "msp34xx(1) failed! error [%d]\n",
+                                     __func__, retval);
+                       goto fail;
                }
                msleep(3);
 
-               errCode = em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xff);
-               if (errCode < 0) {
-                       em28xx_errdev("%s: em28xx_write_regs_req - "
-                                     "msp34xx(2) failed! errCode [%d]\n",
-                                     __func__, errCode);
-                       return errCode;
+               retval = em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xff);
+               if (retval < 0) {
+                       em28xx_errdev("%s: em28xx_write_reg - "
+                                     "msp34xx(2) failed! error [%d]\n",
+                                     __func__, retval);
+                       goto fail;
                }
                msleep(3);
        }
 
-       em28xx_add_into_devlist(dev);
-
        retval = em28xx_register_analog_devices(dev);
        if (retval < 0) {
-               em28xx_release_resources(dev);
-               goto fail_reg_devices;
+               goto fail;
        }
 
-       em28xx_init_extension(dev);
-
        /* Save some power by putting tuner to sleep */
        v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_power, 0);
 
        return 0;
 
-fail_reg_devices:
+fail:
+       em28xx_i2c_unregister(dev);
+
+unregister_dev:
+       v4l2_device_unregister(&dev->v4l2_dev);
+
        return retval;
 }
 
@@ -3015,8 +3042,16 @@ static int em28xx_usb_probe(struct usb_interface *interface,
        udev = usb_get_dev(interface_to_usbdev(interface));
 
        /* Check to see next free device and mark as used */
-       nr = find_first_zero_bit(&em28xx_devused, EM28XX_MAXBOARDS);
-       em28xx_devused |= 1<<nr;
+       do {
+               nr = find_first_zero_bit(&em28xx_devused, EM28XX_MAXBOARDS);
+               if (nr >= EM28XX_MAXBOARDS) {
+                       /* No free device slots */
+                       printk(DRIVER_NAME ": Supports only %i em28xx boards.\n",
+                                       EM28XX_MAXBOARDS);
+                       retval = -ENOMEM;
+                       goto err_no_slot;
+               }
+       } while (test_and_set_bit(nr, &em28xx_devused));
 
        /* Don't register audio interfaces */
        if (interface->altsetting[0].desc.bInterfaceClass == USB_CLASS_AUDIO) {
@@ -3027,7 +3062,6 @@ static int em28xx_usb_probe(struct usb_interface *interface,
                        ifnum,
                        interface->altsetting[0].desc.bInterfaceClass);
 
-               em28xx_devused &= ~(1<<nr);
                retval = -ENODEV;
                goto err;
        }
@@ -3076,7 +3110,6 @@ static int em28xx_usb_probe(struct usb_interface *interface,
                                em28xx_err(DRIVER_NAME " This is an anciliary "
                                        "interface not used by the driver\n");
 
-                               em28xx_devused &= ~(1<<nr);
                                retval = -ENODEV;
                                goto err;
                        }
@@ -3132,29 +3165,19 @@ static int em28xx_usb_probe(struct usb_interface *interface,
                printk(DRIVER_NAME ": Device initialization failed.\n");
                printk(DRIVER_NAME ": Device must be connected to a high-speed"
                       " USB 2.0 port.\n");
-               em28xx_devused &= ~(1<<nr);
                retval = -ENODEV;
                goto err;
        }
 
-       if (nr >= EM28XX_MAXBOARDS) {
-               printk(DRIVER_NAME ": Supports only %i em28xx boards.\n",
-                               EM28XX_MAXBOARDS);
-               em28xx_devused &= ~(1<<nr);
-               retval = -ENOMEM;
-               goto err;
-       }
-
        /* allocate memory for our device state and initialize it */
        dev = kzalloc(sizeof(*dev), GFP_KERNEL);
        if (dev == NULL) {
                em28xx_err(DRIVER_NAME ": out of memory!\n");
-               em28xx_devused &= ~(1<<nr);
                retval = -ENOMEM;
                goto err;
        }
 
-       snprintf(dev->name, 29, "em28xx #%d", nr);
+       snprintf(dev->name, sizeof(dev->name), "em28xx #%d", nr);
        dev->devno = nr;
        dev->model = id->driver_info;
        dev->alt   = -1;
@@ -3177,7 +3200,6 @@ static int em28xx_usb_probe(struct usb_interface *interface,
 
        if (dev->alt_max_pkt_size == NULL) {
                em28xx_errdev("out of memory!\n");
-               em28xx_devused &= ~(1<<nr);
                kfree(dev);
                retval = -ENOMEM;
                goto err;
@@ -3204,8 +3226,8 @@ static int em28xx_usb_probe(struct usb_interface *interface,
        mutex_lock(&dev->lock);
        retval = em28xx_init_dev(&dev, udev, interface, nr);
        if (retval) {
-               em28xx_devused &= ~(1<<dev->devno);
                mutex_unlock(&dev->lock);
+               kfree(dev->alt_max_pkt_size);
                kfree(dev);
                goto err;
        }
@@ -3217,15 +3239,26 @@ static int em28xx_usb_probe(struct usb_interface *interface,
         */
        mutex_unlock(&dev->lock);
 
+       /*
+        * These extensions can be modules. If the modules are already
+        * loaded then we can initialise the device now, otherwise we
+        * will initialise it when the modules load instead.
+        */
+       em28xx_init_extension(dev);
+
        return 0;
 
 err:
+       clear_bit(nr, &em28xx_devused);
+
+err_no_slot:
+       usb_put_dev(udev);
        return retval;
 }
 
 /*
  * em28xx_usb_disconnect()
- * called when the device gets diconencted
+ * called when the device gets disconnected
  * video device will be unregistered on v4l2_close in case it is still open
  */
 static void em28xx_usb_disconnect(struct usb_interface *interface)
@@ -3273,10 +3306,10 @@ static void em28xx_usb_disconnect(struct usb_interface *interface)
                em28xx_release_resources(dev);
        }
 
-       em28xx_close_extension(dev);
-
        mutex_unlock(&dev->lock);
 
+       em28xx_close_extension(dev);
+
        if (!dev->users) {
                kfree(dev->alt_max_pkt_size);
                kfree(dev);
index 57b1b5c6d88585521b06dcf647424669e7a2de60..804a4ab47ac636405579d4d6a8003dcffafa04f0 100644 (file)
@@ -1183,25 +1183,6 @@ void em28xx_wake_i2c(struct em28xx *dev)
 static LIST_HEAD(em28xx_devlist);
 static DEFINE_MUTEX(em28xx_devlist_mutex);
 
-/*
- * em28xx_realease_resources()
- * unregisters the v4l2,i2c and usb devices
- * called when the device gets disconected or at module unload
-*/
-void em28xx_remove_from_devlist(struct em28xx *dev)
-{
-       mutex_lock(&em28xx_devlist_mutex);
-       list_del(&dev->devlist);
-       mutex_unlock(&em28xx_devlist_mutex);
-};
-
-void em28xx_add_into_devlist(struct em28xx *dev)
-{
-       mutex_lock(&em28xx_devlist_mutex);
-       list_add_tail(&dev->devlist, &em28xx_devlist);
-       mutex_unlock(&em28xx_devlist_mutex);
-};
-
 /*
  * Extension interface
  */
@@ -1217,8 +1198,8 @@ int em28xx_register_extension(struct em28xx_ops *ops)
        list_for_each_entry(dev, &em28xx_devlist, devlist) {
                ops->init(dev);
        }
-       printk(KERN_INFO "Em28xx: Initialized (%s) extension\n", ops->name);
        mutex_unlock(&em28xx_devlist_mutex);
+       printk(KERN_INFO "Em28xx: Initialized (%s) extension\n", ops->name);
        return 0;
 }
 EXPORT_SYMBOL(em28xx_register_extension);
@@ -1231,36 +1212,34 @@ void em28xx_unregister_extension(struct em28xx_ops *ops)
        list_for_each_entry(dev, &em28xx_devlist, devlist) {
                ops->fini(dev);
        }
-       printk(KERN_INFO "Em28xx: Removed (%s) extension\n", ops->name);
        list_del(&ops->next);
        mutex_unlock(&em28xx_devlist_mutex);
+       printk(KERN_INFO "Em28xx: Removed (%s) extension\n", ops->name);
 }
 EXPORT_SYMBOL(em28xx_unregister_extension);
 
 void em28xx_init_extension(struct em28xx *dev)
 {
-       struct em28xx_ops *ops = NULL;
+       const struct em28xx_ops *ops = NULL;
 
        mutex_lock(&em28xx_devlist_mutex);
-       if (!list_empty(&em28xx_extension_devlist)) {
-               list_for_each_entry(ops, &em28xx_extension_devlist, next) {
-                       if (ops->init)
-                               ops->init(dev);
-               }
+       list_add_tail(&dev->devlist, &em28xx_devlist);
+       list_for_each_entry(ops, &em28xx_extension_devlist, next) {
+               if (ops->init)
+                       ops->init(dev);
        }
        mutex_unlock(&em28xx_devlist_mutex);
 }
 
 void em28xx_close_extension(struct em28xx *dev)
 {
-       struct em28xx_ops *ops = NULL;
+       const struct em28xx_ops *ops = NULL;
 
        mutex_lock(&em28xx_devlist_mutex);
-       if (!list_empty(&em28xx_extension_devlist)) {
-               list_for_each_entry(ops, &em28xx_extension_devlist, next) {
-                       if (ops->fini)
-                               ops->fini(dev);
-               }
+       list_for_each_entry(ops, &em28xx_extension_devlist, next) {
+               if (ops->fini)
+                       ops->fini(dev);
        }
+       list_del(&dev->devlist);
        mutex_unlock(&em28xx_devlist_mutex);
 }
index e5916dee40945b8fd250582615904f5c8b381e98..cef7a2d409cbc27c53c2aabe805528d62f40b894 100644 (file)
@@ -42,6 +42,8 @@
 #include "cxd2820r.h"
 #include "tda18271c2dd.h"
 #include "drxk.h"
+#include "tda10071.h"
+#include "a8293.h"
 
 MODULE_DESCRIPTION("driver for em28xx based DVB cards");
 MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
@@ -122,7 +124,7 @@ static inline void print_err_status(struct em28xx *dev,
        }
 }
 
-static inline int dvb_isoc_copy(struct em28xx *dev, struct urb *urb)
+static inline int em28xx_dvb_isoc_copy(struct em28xx *dev, struct urb *urb)
 {
        int i;
 
@@ -155,7 +157,7 @@ static inline int dvb_isoc_copy(struct em28xx *dev, struct urb *urb)
        return 0;
 }
 
-static int start_streaming(struct em28xx_dvb *dvb)
+static int em28xx_start_streaming(struct em28xx_dvb *dvb)
 {
        int rc;
        struct em28xx *dev = dvb->adapter.priv;
@@ -175,10 +177,10 @@ static int start_streaming(struct em28xx_dvb *dvb)
 
        return em28xx_init_isoc(dev, EM28XX_DVB_MAX_PACKETS,
                                EM28XX_DVB_NUM_BUFS, max_dvb_packet_size,
-                               dvb_isoc_copy);
+                               em28xx_dvb_isoc_copy);
 }
 
-static int stop_streaming(struct em28xx_dvb *dvb)
+static int em28xx_stop_streaming(struct em28xx_dvb *dvb)
 {
        struct em28xx *dev = dvb->adapter.priv;
 
@@ -189,7 +191,7 @@ static int stop_streaming(struct em28xx_dvb *dvb)
        return 0;
 }
 
-static int start_feed(struct dvb_demux_feed *feed)
+static int em28xx_start_feed(struct dvb_demux_feed *feed)
 {
        struct dvb_demux *demux  = feed->demux;
        struct em28xx_dvb *dvb = demux->priv;
@@ -203,7 +205,7 @@ static int start_feed(struct dvb_demux_feed *feed)
        rc = dvb->nfeeds;
 
        if (dvb->nfeeds == 1) {
-               ret = start_streaming(dvb);
+               ret = em28xx_start_streaming(dvb);
                if (ret < 0)
                        rc = ret;
        }
@@ -212,7 +214,7 @@ static int start_feed(struct dvb_demux_feed *feed)
        return rc;
 }
 
-static int stop_feed(struct dvb_demux_feed *feed)
+static int em28xx_stop_feed(struct dvb_demux_feed *feed)
 {
        struct dvb_demux *demux  = feed->demux;
        struct em28xx_dvb *dvb = demux->priv;
@@ -222,7 +224,7 @@ static int stop_feed(struct dvb_demux_feed *feed)
        dvb->nfeeds--;
 
        if (0 == dvb->nfeeds)
-               err = stop_streaming(dvb);
+               err = em28xx_stop_streaming(dvb);
 
        mutex_unlock(&dvb->lock);
        return err;
@@ -380,7 +382,7 @@ static void terratec_h5_init(struct em28xx *dev)
        em28xx_gpio_set(dev, terratec_h5_end);
 };
 
-static int mt352_terratec_xs_init(struct dvb_frontend *fe)
+static int em28xx_mt352_terratec_xs_init(struct dvb_frontend *fe)
 {
        /* Values extracted from a USB trace of the Terratec Windows driver */
        static u8 clock_config[]   = { CLOCK_CTL,  0x38, 0x2c };
@@ -412,7 +414,7 @@ static struct mt352_config terratec_xs_mt352_cfg = {
        .demod_address = (0x1e >> 1),
        .no_tuner = 1,
        .if2 = 45600,
-       .demod_init = mt352_terratec_xs_init,
+       .demod_init = em28xx_mt352_terratec_xs_init,
 };
 
 static struct tda10023_config em28xx_tda10023_config = {
@@ -438,11 +440,25 @@ static struct cxd2820r_config em28xx_cxd2820r_config = {
 
 static struct tda18271_config em28xx_cxd2820r_tda18271_config = {
        .output_opt = TDA18271_OUTPUT_LT_OFF,
+       .gate = TDA18271_GATE_DIGITAL,
+};
+
+static const struct tda10071_config em28xx_tda10071_config = {
+       .i2c_address = 0x55, /* (0xaa >> 1) */
+       .i2c_wr_max = 64,
+       .ts_mode = TDA10071_TS_SERIAL,
+       .spec_inv = 0,
+       .xtal = 40444000, /* 40.444 MHz */
+       .pll_multiplier = 20,
+};
+
+static const struct a8293_config em28xx_a8293_config = {
+       .i2c_addr = 0x08, /* (0x10 >> 1) */
 };
 
 /* ------------------------------------------------------------------ */
 
-static int attach_xc3028(u8 addr, struct em28xx *dev)
+static int em28xx_attach_xc3028(u8 addr, struct em28xx *dev)
 {
        struct dvb_frontend *fe;
        struct xc2028_config cfg;
@@ -472,10 +488,8 @@ static int attach_xc3028(u8 addr, struct em28xx *dev)
 
 /* ------------------------------------------------------------------ */
 
-static int register_dvb(struct em28xx_dvb *dvb,
-                struct module *module,
-                struct em28xx *dev,
-                struct device *device)
+static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module,
+                              struct em28xx *dev, struct device *device)
 {
        int result;
 
@@ -522,8 +536,8 @@ static int register_dvb(struct em28xx_dvb *dvb,
        dvb->demux.priv       = dvb;
        dvb->demux.filternum  = 256;
        dvb->demux.feednum    = 256;
-       dvb->demux.start_feed = start_feed;
-       dvb->demux.stop_feed  = stop_feed;
+       dvb->demux.start_feed = em28xx_start_feed;
+       dvb->demux.stop_feed  = em28xx_stop_feed;
 
        result = dvb_dmx_init(&dvb->demux);
        if (result < 0) {
@@ -591,7 +605,7 @@ fail_adapter:
        return result;
 }
 
-static void unregister_dvb(struct em28xx_dvb *dvb)
+static void em28xx_unregister_dvb(struct em28xx_dvb *dvb)
 {
        dvb_net_release(&dvb->net);
        dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
@@ -607,9 +621,9 @@ static void unregister_dvb(struct em28xx_dvb *dvb)
        dvb_unregister_adapter(&dvb->adapter);
 }
 
-static int dvb_init(struct em28xx *dev)
+static int em28xx_dvb_init(struct em28xx *dev)
 {
-       int result = 0;
+       int result = 0, mfe_shared = 0;
        struct em28xx_dvb *dvb;
 
        if (!dev->board.has_dvb) {
@@ -648,7 +662,7 @@ static int dvb_init(struct em28xx *dev)
                dvb->fe[0] = dvb_attach(lgdt330x_attach,
                                           &em2880_lgdt3303_dev,
                                           &dev->i2c_adap);
-               if (attach_xc3028(0x61, dev) < 0) {
+               if (em28xx_attach_xc3028(0x61, dev) < 0) {
                        result = -EINVAL;
                        goto out_free;
                }
@@ -657,7 +671,7 @@ static int dvb_init(struct em28xx *dev)
                dvb->fe[0] = dvb_attach(zl10353_attach,
                                           &em28xx_zl10353_with_xc3028,
                                           &dev->i2c_adap);
-               if (attach_xc3028(0x61, dev) < 0) {
+               if (em28xx_attach_xc3028(0x61, dev) < 0) {
                        result = -EINVAL;
                        goto out_free;
                }
@@ -668,7 +682,7 @@ static int dvb_init(struct em28xx *dev)
                dvb->fe[0] = dvb_attach(zl10353_attach,
                                           &em28xx_zl10353_xc3028_no_i2c_gate,
                                           &dev->i2c_adap);
-               if (attach_xc3028(0x61, dev) < 0) {
+               if (em28xx_attach_xc3028(0x61, dev) < 0) {
                        result = -EINVAL;
                        goto out_free;
                }
@@ -689,7 +703,7 @@ static int dvb_init(struct em28xx *dev)
                                                   &dev->i2c_adap);
                }
 
-               if (attach_xc3028(0x61, dev) < 0) {
+               if (em28xx_attach_xc3028(0x61, dev) < 0) {
                        result = -EINVAL;
                        goto out_free;
                }
@@ -699,7 +713,7 @@ static int dvb_init(struct em28xx *dev)
                dvb->fe[0] = dvb_attach(s5h1409_attach,
                                           &em28xx_s5h1409_with_xc3028,
                                           &dev->i2c_adap);
-               if (attach_xc3028(0x61, dev) < 0) {
+               if (em28xx_attach_xc3028(0x61, dev) < 0) {
                        result = -EINVAL;
                        goto out_free;
                }
@@ -720,7 +734,7 @@ static int dvb_init(struct em28xx *dev)
        case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
                dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL,
                                           &dev->i2c_adap, &dev->udev->dev);
-               if (attach_xc3028(0x61, dev) < 0) {
+               if (em28xx_attach_xc3028(0x61, dev) < 0) {
                        result = -EINVAL;
                        goto out_free;
                }
@@ -753,11 +767,9 @@ static int dvb_init(struct em28xx *dev)
                dvb->fe[0] = dvb_attach(cxd2820r_attach,
                        &em28xx_cxd2820r_config, &dev->i2c_adap, NULL);
                if (dvb->fe[0]) {
-                       struct i2c_adapter *i2c_tuner;
-                       i2c_tuner = cxd2820r_get_tuner_i2c_adapter(dvb->fe[0]);
                        /* FE 0 attach tuner */
                        if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
-                               i2c_tuner, &em28xx_cxd2820r_tda18271_config)) {
+                               &dev->i2c_adap, &em28xx_cxd2820r_tda18271_config)) {
                                dvb_frontend_detach(dvb->fe[0]);
                                result = -EINVAL;
                                goto out_free;
@@ -768,10 +780,12 @@ static int dvb_init(struct em28xx *dev)
                        dvb->fe[1]->id = 1;
                        /* FE 1 attach tuner */
                        if (!dvb_attach(tda18271_attach, dvb->fe[1], 0x60,
-                               i2c_tuner, &em28xx_cxd2820r_tda18271_config)) {
+                               &dev->i2c_adap, &em28xx_cxd2820r_tda18271_config)) {
                                dvb_frontend_detach(dvb->fe[1]);
                                /* leave FE 0 still active */
                        }
+
+                       mfe_shared = 1;
                }
                break;
        case EM2884_BOARD_TERRATEC_H5:
@@ -809,6 +823,16 @@ static int dvb_init(struct em28xx *dev)
                       sizeof(dvb->fe[0]->ops.tuner_ops));
 
                break;
+       case EM28174_BOARD_PCTV_460E:
+               /* attach demod */
+               dvb->fe[0] = dvb_attach(tda10071_attach,
+                       &em28xx_tda10071_config, &dev->i2c_adap);
+
+               /* attach SEC */
+               if (dvb->fe[0])
+                       dvb_attach(a8293_attach, dvb->fe[0], &dev->i2c_adap,
+                               &em28xx_a8293_config);
+               break;
        default:
                em28xx_errdev("/2: The frontend of your DVB/ATSC card"
                                " isn't supported yet\n");
@@ -823,11 +847,14 @@ static int dvb_init(struct em28xx *dev)
        dvb->fe[0]->callback = em28xx_tuner_callback;
 
        /* register everything */
-       result = register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev);
+       result = em28xx_register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev);
 
        if (result < 0)
                goto out_free;
 
+       /* MFE lock */
+       dvb->adapter.mfe_shared = mfe_shared;
+
        em28xx_info("Successfully loaded em28xx-dvb\n");
 ret:
        em28xx_set_mode(dev, EM28XX_SUSPEND);
@@ -840,7 +867,14 @@ out_free:
        goto ret;
 }
 
-static int dvb_fini(struct em28xx *dev)
+static inline void prevent_sleep(struct dvb_frontend_ops *ops)
+{
+       ops->set_voltage = NULL;
+       ops->sleep = NULL;
+       ops->tuner_ops.sleep = NULL;
+}
+
+static int em28xx_dvb_fini(struct em28xx *dev)
 {
        if (!dev->board.has_dvb) {
                /* This device does not support the extension */
@@ -848,8 +882,19 @@ static int dvb_fini(struct em28xx *dev)
        }
 
        if (dev->dvb) {
-               unregister_dvb(dev->dvb);
-               kfree(dev->dvb);
+               struct em28xx_dvb *dvb = dev->dvb;
+
+               if (dev->state & DEV_DISCONNECTED) {
+                       /* We cannot tell the device to sleep
+                        * once it has been unplugged. */
+                       if (dvb->fe[0])
+                               prevent_sleep(&dvb->fe[0]->ops);
+                       if (dvb->fe[1])
+                               prevent_sleep(&dvb->fe[1]->ops);
+               }
+
+               em28xx_unregister_dvb(dvb);
+               kfree(dvb);
                dev->dvb = NULL;
        }
 
@@ -859,8 +904,8 @@ static int dvb_fini(struct em28xx *dev)
 static struct em28xx_ops dvb_ops = {
        .id   = EM28XX_DVB,
        .name = "Em28xx dvb Extension",
-       .init = dvb_init,
-       .fini = dvb_fini,
+       .init = em28xx_dvb_init,
+       .fini = em28xx_dvb_fini,
 };
 
 static int __init em28xx_dvb_register(void)
index 5d12b14282e3dc19353f62831b3d5df1d7757f6f..679da480428113ec8d7da347e722bf36bde6e590 100644 (file)
@@ -463,11 +463,11 @@ int em28xx_ir_fini(struct em28xx *dev)
        if (!ir)
                return 0;
 
-       em28xx_ir_stop(ir->rc);
-       rc_unregister_device(ir->rc);
-       kfree(ir);
+       if (ir->rc)
+               rc_unregister_device(ir->rc);
 
        /* done */
+       kfree(ir);
        dev->ir = NULL;
        return 0;
 }
index d176dc0394e2f9c276c4e333f695c7c91f39a563..9b4557a2f6d02858cb0c6a29a4295fac966cd317 100644 (file)
@@ -1156,6 +1156,21 @@ static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *norm)
        return 0;
 }
 
+static int vidioc_querystd(struct file *file, void *priv, v4l2_std_id *norm)
+{
+       struct em28xx_fh   *fh  = priv;
+       struct em28xx      *dev = fh->dev;
+       int                rc;
+
+       rc = check_dev(dev);
+       if (rc < 0)
+               return rc;
+
+       v4l2_device_call_all(&dev->v4l2_dev, 0, video, querystd, norm);
+
+       return 0;
+}
+
 static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *norm)
 {
        struct em28xx_fh   *fh  = priv;
@@ -1787,6 +1802,45 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void  *priv,
        return 0;
 }
 
+static int vidioc_enum_framesizes(struct file *file, void *priv,
+                                 struct v4l2_frmsizeenum *fsize)
+{
+       struct em28xx_fh      *fh  = priv;
+       struct em28xx         *dev = fh->dev;
+       struct em28xx_fmt     *fmt;
+       unsigned int          maxw = norm_maxw(dev);
+       unsigned int          maxh = norm_maxh(dev);
+
+       fmt = format_by_fourcc(fsize->pixel_format);
+       if (!fmt) {
+               em28xx_videodbg("Fourcc format (%08x) invalid.\n",
+                               fsize->pixel_format);
+               return -EINVAL;
+       }
+
+       if (dev->board.is_em2800) {
+               if (fsize->index > 1)
+                       return -EINVAL;
+               fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
+               fsize->discrete.width = maxw / (1 + fsize->index);
+               fsize->discrete.height = maxh / (1 + fsize->index);
+               return 0;
+       }
+
+       if (fsize->index != 0)
+               return -EINVAL;
+
+       /* Report a continuous range */
+       fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
+       fsize->stepwise.min_width = 48;
+       fsize->stepwise.min_height = 32;
+       fsize->stepwise.max_width = maxw;
+       fsize->stepwise.max_height = maxh;
+       fsize->stepwise.step_width = 1;
+       fsize->stepwise.step_height = 1;
+       return 0;
+}
+
 /* Sliced VBI ioctls */
 static int vidioc_g_fmt_sliced_vbi_cap(struct file *file, void *priv,
                                        struct v4l2_format *f)
@@ -2200,6 +2254,7 @@ static int em28xx_v4l2_close(struct file *filp)
                   free the remaining resources */
                if (dev->state & DEV_DISCONNECTED) {
                        em28xx_release_resources(dev);
+                       kfree(dev->alt_max_pkt_size);
                        kfree(dev);
                        return 0;
                }
@@ -2340,10 +2395,10 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
        .vidioc_s_fmt_vid_cap       = vidioc_s_fmt_vid_cap,
        .vidioc_g_fmt_vbi_cap       = vidioc_g_fmt_vbi_cap,
        .vidioc_s_fmt_vbi_cap       = vidioc_s_fmt_vbi_cap,
+       .vidioc_enum_framesizes     = vidioc_enum_framesizes,
        .vidioc_g_audio             = vidioc_g_audio,
        .vidioc_s_audio             = vidioc_s_audio,
        .vidioc_cropcap             = vidioc_cropcap,
-
        .vidioc_g_fmt_sliced_vbi_cap   = vidioc_g_fmt_sliced_vbi_cap,
        .vidioc_try_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap,
        .vidioc_s_fmt_sliced_vbi_cap   = vidioc_try_set_sliced_vbi_cap,
@@ -2353,6 +2408,7 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
        .vidioc_qbuf                = vidioc_qbuf,
        .vidioc_dqbuf               = vidioc_dqbuf,
        .vidioc_g_std               = vidioc_g_std,
+       .vidioc_querystd            = vidioc_querystd,
        .vidioc_s_std               = vidioc_s_std,
        .vidioc_g_parm              = vidioc_g_parm,
        .vidioc_s_parm              = vidioc_s_parm,
index d80658bf3da9f70df94b60c4cdd2ed042b470f7b..2a2cb7ed0014fcda319a31c60066c3ebbfa12f9f 100644 (file)
 #define EM2874_BOARD_LEADERSHIP_ISDBT            77
 #define EM28174_BOARD_PCTV_290E                   78
 #define EM2884_BOARD_TERRATEC_H5                 79
+#define EM28174_BOARD_PCTV_460E                   80
 
 /* Limits minimum and default number of buffers */
 #define EM28XX_MIN_BUF 4
@@ -677,8 +678,6 @@ int em28xx_isoc_dvb_max_packetsize(struct em28xx *dev);
 int em28xx_set_mode(struct em28xx *dev, enum em28xx_mode set_mode);
 int em28xx_gpio_set(struct em28xx *dev, struct em28xx_reg_seq *gpio);
 void em28xx_wake_i2c(struct em28xx *dev);
-void em28xx_remove_from_devlist(struct em28xx *dev);
-void em28xx_add_into_devlist(struct em28xx *dev);
 int em28xx_register_extension(struct em28xx_ops *dev);
 void em28xx_unregister_extension(struct em28xx_ops *dev);
 void em28xx_init_extension(struct em28xx *dev);
index 14bb907d650e123b4fe2be6a2366c5618f596f82..337ded4a6388d68d58c6f7afb78dc18fe0e7ba29 100644 (file)
@@ -165,45 +165,49 @@ et61x251_attach_sensor(struct et61x251_device* cam,
 #undef DBG
 #undef KDBG
 #ifdef ET61X251_DEBUG
-#      define DBG(level, fmt, args...)                                       \
-do {                                                                          \
-       if (debug >= (level)) {                                               \
-               if ((level) == 1)                                             \
-                       dev_err(&cam->usbdev->dev, fmt "\n", ## args);        \
-               else if ((level) == 2)                                        \
-                       dev_info(&cam->usbdev->dev, fmt "\n", ## args);       \
-               else if ((level) >= 3)                                        \
-                       dev_info(&cam->usbdev->dev, "[%s:%s:%d] " fmt "\n",   \
-                                __FILE__, __func__, __LINE__ , ## args); \
-       }                                                                     \
+#define DBG(level, fmt, ...)                                           \
+do {                                                                   \
+       if (debug >= (level)) {                                         \
+               if ((level) == 1)                                       \
+                       dev_err(&cam->usbdev->dev, fmt "\n",            \
+                               ##__VA_ARGS__);                         \
+               else if ((level) == 2)                                  \
+                       dev_info(&cam->usbdev->dev, fmt "\n",           \
+                                ##__VA_ARGS__);                        \
+               else if ((level) >= 3)                                  \
+                       dev_info(&cam->usbdev->dev, "[%s:%s:%d] " fmt "\n", \
+                                __FILE__, __func__, __LINE__,          \
+                                ##__VA_ARGS__);                        \
+       }                                                               \
 } while (0)
-#      define KDBG(level, fmt, args...)                                      \
-do {                                                                          \
-       if (debug >= (level)) {                                               \
-               if ((level) == 1 || (level) == 2)                             \
-                       pr_info("et61x251: " fmt "\n", ## args);              \
-               else if ((level) == 3)                                        \
-                       pr_debug("sn9c102: [%s:%s:%d] " fmt "\n", __FILE__,   \
-                                __func__, __LINE__ , ## args);           \
-       }                                                                     \
+#define KDBG(level, fmt, ...)                                          \
+do {                                                                   \
+       if (debug >= (level)) {                                         \
+               if ((level) == 1 || (level) == 2)                       \
+                       pr_info(fmt "\n", ##__VA_ARGS__);               \
+               else if ((level) == 3)                                  \
+                       pr_debug("[%s:%s:%d] " fmt "\n",                \
+                                __FILE__,  __func__, __LINE__,         \
+                                ##__VA_ARGS__);                        \
+       }                                                               \
 } while (0)
-#      define V4LDBG(level, name, cmd)                                       \
-do {                                                                          \
-       if (debug >= (level))                                                 \
-               v4l_print_ioctl(name, cmd);                                   \
+#define V4LDBG(level, name, cmd)                                       \
+do {                                                                   \
+       if (debug >= (level))                                           \
+               v4l_print_ioctl(name, cmd);                             \
 } while (0)
 #else
-#      define DBG(level, fmt, args...) do {;} while(0)
-#      define KDBG(level, fmt, args...) do {;} while(0)
-#      define V4LDBG(level, name, cmd) do {;} while(0)
+#define DBG(level, fmt, ...) do {;} while(0)
+#define KDBG(level, fmt, ...) do {;} while(0)
+#define V4LDBG(level, name, cmd) do {;} while(0)
 #endif
 
 #undef PDBG
-#define PDBG(fmt, args...)                                                    \
-dev_info(&cam->usbdev->dev, "[%s:%s:%d] " fmt "\n", __FILE__, __func__,   \
-        __LINE__ , ## args)
+#define PDBG(fmt, ...)                                                 \
+       dev_info(&cam->usbdev->dev, "[%s:%s:%d] " fmt "\n",             \
+                __FILE__, __func__, __LINE__, ##__VA_ARGS__)
 
 #undef PDBGG
-#define PDBGG(fmt, args...) do {;} while(0) /* placeholder */
+#define PDBGG(fmt, args...) do {;} while (0) /* placeholder */
 
 #endif /* _ET61X251_H_ */
index 9a1e80a1e1459824b95da0abe23dc00f8e8393e7..d3777c86e1de7a3043fb40c7d355fca4872e1bd7 100644 (file)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.               *
  ***************************************************************************/
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/version.h>
 #include <linux/module.h>
 #include <linux/init.h>
index 04b7fbb310a82d6d7737c57846d325f651f4f367..ced2e167935d83a3a8410bd371b963320548ca5e 100644 (file)
@@ -19,6 +19,8 @@
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.               *
  ***************************************************************************/
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include "et61x251_sensor.h"
 
 
index 43d9a20caebc3f6439693e0833530e247c4b94ee..103af3fe5aa07b8aabd5cbd1acb3c8fa08ca6c82 100644 (file)
@@ -356,6 +356,16 @@ config USB_GSPCA_T613
          To compile this driver as a module, choose M here: the
          module will be called gspca_t613.
 
+config USB_GSPCA_TOPRO
+       tristate "TOPRO USB Camera Driver"
+       depends on VIDEO_V4L2 && USB_GSPCA
+       help
+         Say Y here if you want support for cameras based on the
+         TP6800 and TP6810 Topro chips.
+
+         To compile this driver as a module, choose M here: the
+         module will be called gspca_topro.
+
 config USB_GSPCA_TV8532
        tristate "TV8532 USB Camera Driver"
        depends on VIDEO_V4L2 && USB_GSPCA
index d6364a86333ab8382d5ab11f0f360087a927ad39..f345f494d0f3121e16302ee20d61daea8d813deb 100644 (file)
@@ -35,6 +35,7 @@ obj-$(CONFIG_USB_GSPCA_SUNPLUS)  += gspca_sunplus.o
 obj-$(CONFIG_USB_GSPCA_STK014)   += gspca_stk014.o
 obj-$(CONFIG_USB_GSPCA_STV0680)  += gspca_stv0680.o
 obj-$(CONFIG_USB_GSPCA_T613)     += gspca_t613.o
+obj-$(CONFIG_USB_GSPCA_TOPRO)    += gspca_topro.o
 obj-$(CONFIG_USB_GSPCA_TV8532)   += gspca_tv8532.o
 obj-$(CONFIG_USB_GSPCA_VC032X)   += gspca_vc032x.o
 obj-$(CONFIG_USB_GSPCA_VICAM)    += gspca_vicam.o
@@ -78,6 +79,7 @@ gspca_stk014-objs   := stk014.o
 gspca_stv0680-objs  := stv0680.o
 gspca_sunplus-objs  := sunplus.o
 gspca_t613-objs     := t613.o
+gspca_topro-objs    := topro.o
 gspca_tv8532-objs   := tv8532.o
 gspca_vc032x-objs   := vc032x.o
 gspca_vicam-objs    := vicam.o
index a09c4709d6139b9616e79804b39f0d1aa982ac1e..6ae26160b81f9c16e2bdf8f30934f141a5ea0b02 100644 (file)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "benq"
 
 #include "gspca.h"
@@ -62,7 +64,7 @@ static void reg_w(struct gspca_dev *gspca_dev,
                        0,
                        500);
        if (ret < 0) {
-               err("reg_w err %d", ret);
+               pr_err("reg_w err %d\n", ret);
                gspca_dev->usb_err = ret;
        }
 }
@@ -84,20 +86,6 @@ static int sd_init(struct gspca_dev *gspca_dev)
        return 0;
 }
 
-static int sd_isoc_init(struct gspca_dev *gspca_dev)
-{
-       int ret;
-
-       ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface,
-               gspca_dev->nbalt - 1);
-       if (ret < 0) {
-               err("usb_set_interface failed");
-               return ret;
-       }
-/*     reg_w(gspca_dev, 0x0003, 0x0002); */
-       return 0;
-}
-
 /* -- start the camera -- */
 static int sd_start(struct gspca_dev *gspca_dev)
 {
@@ -113,7 +101,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
        for (n = 0; n < 4; n++) {
                urb = usb_alloc_urb(SD_NPKT, GFP_KERNEL);
                if (!urb) {
-                       err("usb_alloc_urb failed");
+                       pr_err("usb_alloc_urb failed\n");
                        return -ENOMEM;
                }
                gspca_dev->urb[n] = urb;
@@ -123,7 +111,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
                                                &urb->transfer_dma);
 
                if (urb->transfer_buffer == NULL) {
-                       err("usb_alloc_coherent failed");
+                       pr_err("usb_alloc_coherent failed\n");
                        return -ENOMEM;
                }
                urb->dev = gspca_dev->dev;
@@ -181,7 +169,7 @@ static void sd_isoc_irq(struct urb *urb)
                if (gspca_dev->frozen)
                        return;
 #endif
-               err("urb status: %d", urb->status);
+               pr_err("urb status: %d\n", urb->status);
                return;
        }
 
@@ -209,7 +197,7 @@ static void sd_isoc_irq(struct urb *urb)
                if (st == 0)
                        st = urb->iso_frame_desc[i].status;
                if (st) {
-                       err("ISOC data error: [%d] status=%d",
+                       pr_err("ISOC data error: [%d] status=%d\n",
                                i, st);
                        gspca_dev->last_packet_type = DISCARD_PACKET;
                        continue;
@@ -256,10 +244,10 @@ static void sd_isoc_irq(struct urb *urb)
        /* resubmit the URBs */
        st = usb_submit_urb(urb0, GFP_ATOMIC);
        if (st < 0)
-               err("usb_submit_urb(0) ret %d", st);
+               pr_err("usb_submit_urb(0) ret %d\n", st);
        st = usb_submit_urb(urb, GFP_ATOMIC);
        if (st < 0)
-               err("usb_submit_urb() ret %d", st);
+               pr_err("usb_submit_urb() ret %d\n", st);
 }
 
 /* sub-driver description */
@@ -269,7 +257,6 @@ static const struct sd_desc sd_desc = {
        .nctrls = ARRAY_SIZE(sd_ctrls),
        .config = sd_config,
        .init = sd_init,
-       .isoc_init = sd_isoc_init,
        .start = sd_start,
        .stopN = sd_stopN,
        .pkt_scan = sd_pkt_scan,
index 8b398493f96bc65e63dd018bfd684109e16c9b6e..4c56dbef6d92fb778bb625a99e941de597beeed1 100644 (file)
@@ -19,6 +19,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "conex"
 
 #include "gspca.h"
@@ -129,7 +131,7 @@ static void reg_r(struct gspca_dev *gspca_dev,
 
 #ifdef GSPCA_DEBUG
        if (len > USB_BUF_SZ) {
-               err("reg_r: buffer overflow");
+               pr_err("reg_r: buffer overflow\n");
                return;
        }
 #endif
@@ -169,7 +171,7 @@ static void reg_w(struct gspca_dev *gspca_dev,
 
 #ifdef GSPCA_DEBUG
        if (len > USB_BUF_SZ) {
-               err("reg_w: buffer overflow");
+               pr_err("reg_w: buffer overflow\n");
                return;
        }
        PDEBUG(D_USBO, "reg write [%02x] = %02x..", index, *buffer);
index f2a9451eea19ba87042be32c7dd184c9d4b45016..f9b86b2484b0d22fbf0c604a0a9a50d39ce930b8 100644 (file)
@@ -26,6 +26,8 @@
  *
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "cpia1"
 
 #include <linux/input.h>
@@ -550,8 +552,7 @@ retry:
                              gspca_dev->usb_buf, databytes, 1000);
 
        if (ret < 0)
-               err("usb_control_msg %02x, error %d", command[1],
-                      ret);
+               pr_err("usb_control_msg %02x, error %d\n", command[1], ret);
 
        if (ret == -EPIPE && retries > 0) {
                retries--;
@@ -1279,7 +1280,7 @@ static void monitor_exposure(struct gspca_dev *gspca_dev)
        cmd[7] = 0;
        ret = cpia_usb_transferCmd(gspca_dev, cmd);
        if (ret) {
-               err("ReadVPRegs(30,4,9,8) - failed: %d", ret);
+               pr_err("ReadVPRegs(30,4,9,8) - failed: %d\n", ret);
                return;
        }
        exp_acc = gspca_dev->usb_buf[0];
index 4b2c483fce6f9d48fce457ad764d3f4e0fdc5466..0357d6d461d1dc9a06e00d4d9a130c6f15ea5680 100644 (file)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "etoms"
 
 #include "gspca.h"
@@ -236,7 +238,7 @@ static void reg_r(struct gspca_dev *gspca_dev,
 
 #ifdef GSPCA_DEBUG
        if (len > USB_BUF_SZ) {
-               err("reg_r: buffer overflow");
+               pr_err("reg_r: buffer overflow\n");
                return;
        }
 #endif
@@ -274,7 +276,7 @@ static void reg_w(struct gspca_dev *gspca_dev,
 
 #ifdef GSPCA_DEBUG
        if (len > USB_BUF_SZ) {
-               err("reg_w: buffer overflow");
+               pr_err("reg_w: buffer overflow\n");
                return;
        }
        PDEBUG(D_USBO, "reg write [%02x] = %02x..", index, *buffer);
index 987b4b69d7ab2a71a06d7dc0c39b235646ef47a2..ea48200fd3a0927a7c646ae61453003e085b6b68 100644 (file)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "finepix"
 
 #include "gspca.h"
@@ -182,7 +184,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
        /* Init the device */
        ret = command(gspca_dev, 0);
        if (ret < 0) {
-               err("init failed %d", ret);
+               pr_err("init failed %d\n", ret);
                return ret;
        }
 
@@ -194,14 +196,14 @@ static int sd_start(struct gspca_dev *gspca_dev)
                        FPIX_MAX_TRANSFER, &len,
                        FPIX_TIMEOUT);
        if (ret < 0) {
-               err("usb_bulk_msg failed %d", ret);
+               pr_err("usb_bulk_msg failed %d\n", ret);
                return ret;
        }
 
        /* Request a frame, but don't read it */
        ret = command(gspca_dev, 1);
        if (ret < 0) {
-               err("frame request failed %d", ret);
+               pr_err("frame request failed %d\n", ret);
                return ret;
        }
 
index 13c9403cc87dd988df44f43365391a49f1ac667f..f511eccdfd9ce8a7abd626a3af1efea69c8a9aca 100644 (file)
@@ -6,5 +6,5 @@ gspca_gl860-objs := gl860.o \
                    gl860-ov9655.o \
                    gl860-mi2020.o
 
-EXTRA_CFLAGS += -Idrivers/media/video/gspca
+ccflags-y += -Idrivers/media/video/gspca
 
index e8e071aa212f4ac23514ac32c83327c4a2e0519e..2ced3b73994fed758bd126e9a55efc6d1ce2bdde 100644 (file)
@@ -18,6 +18,9 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include "gspca.h"
 #include "gl860.h"
 
@@ -572,9 +575,8 @@ int gl860_RTx(struct gspca_dev *gspca_dev,
        }
 
        if (r < 0)
-               err("ctrl transfer failed %4d "
-                       "[p%02x r%d v%04x i%04x len%d]",
-                       r, pref, req, val, index, len);
+               pr_err("ctrl transfer failed %4d [p%02x r%d v%04x i%04x len%d]\n",
+                      r, pref, req, val, index, len);
        else if (len > 1 && r < len)
                PDEBUG(D_ERR, "short ctrl transfer %d/%d", r, len);
 
index 5da4879f47f2c3e01342479add75a04332e48fa8..881e04c7ffe6dd91f5a96f12aaebe236a7bfba5c 100644 (file)
@@ -21,7 +21,9 @@
  * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-#define MODULE_NAME "gspca"
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#define GSPCA_VERSION  "2.14.0"
 
 #include <linux/init.h>
 #include <linux/fs.h>
 #error "DEF_NURBS too big"
 #endif
 
-#define DRIVER_VERSION_NUMBER  "2.13.0"
-
 MODULE_AUTHOR("Jean-François Moine <http://moinejf.free.fr>");
 MODULE_DESCRIPTION("GSPCA USB Camera Driver");
 MODULE_LICENSE("GPL");
-MODULE_VERSION(DRIVER_VERSION_NUMBER);
+MODULE_VERSION(GSPCA_VERSION);
 
 #ifdef GSPCA_DEBUG
 int gspca_debug = D_ERR | D_PROBE;
@@ -148,7 +148,7 @@ static void int_irq(struct urb *urb)
        if (ret == 0) {
                ret = usb_submit_urb(urb, GFP_ATOMIC);
                if (ret < 0)
-                       err("Resubmit URB failed with error %i", ret);
+                       pr_err("Resubmit URB failed with error %i\n", ret);
        }
 }
 
@@ -177,8 +177,8 @@ static int gspca_input_connect(struct gspca_dev *dev)
 
                err = input_register_device(input_dev);
                if (err) {
-                       err("Input device registration failed with error %i",
-                               err);
+                       pr_err("Input device registration failed with error %i\n",
+                              err);
                        input_dev->dev.parent = NULL;
                        input_free_device(input_dev);
                } else {
@@ -323,8 +323,8 @@ static void fill_frame(struct gspca_dev *gspca_dev,
                /* check the packet status and length */
                st = urb->iso_frame_desc[i].status;
                if (st) {
-                       err("ISOC data error: [%d] len=%d, status=%d",
-                               i, len, st);
+                       pr_err("ISOC data error: [%d] len=%d, status=%d\n",
+                              i, len, st);
                        gspca_dev->last_packet_type = DISCARD_PACKET;
                        continue;
                }
@@ -346,7 +346,7 @@ resubmit:
        /* resubmit the URB */
        st = usb_submit_urb(urb, GFP_ATOMIC);
        if (st < 0)
-               err("usb_submit_urb() ret %d", st);
+               pr_err("usb_submit_urb() ret %d\n", st);
 }
 
 /*
@@ -400,7 +400,7 @@ resubmit:
        if (gspca_dev->cam.bulk_nurbs != 0) {
                st = usb_submit_urb(urb, GFP_ATOMIC);
                if (st < 0)
-                       err("usb_submit_urb() ret %d", st);
+                       pr_err("usb_submit_urb() ret %d\n", st);
        }
 }
 
@@ -464,7 +464,7 @@ void gspca_frame_add(struct gspca_dev *gspca_dev,
                } else {
 /* !! image is NULL only when last pkt is LAST or DISCARD
                        if (gspca_dev->image == NULL) {
-                               err("gspca_frame_add() image == NULL");
+                               pr_err("gspca_frame_add() image == NULL\n");
                                return;
                        }
  */
@@ -497,19 +497,6 @@ void gspca_frame_add(struct gspca_dev *gspca_dev,
 }
 EXPORT_SYMBOL(gspca_frame_add);
 
-static int gspca_is_compressed(__u32 format)
-{
-       switch (format) {
-       case V4L2_PIX_FMT_MJPEG:
-       case V4L2_PIX_FMT_JPEG:
-       case V4L2_PIX_FMT_SPCA561:
-       case V4L2_PIX_FMT_PAC207:
-       case V4L2_PIX_FMT_MR97310A:
-               return 1;
-       }
-       return 0;
-}
-
 static int frame_alloc(struct gspca_dev *gspca_dev, struct file *file,
                        enum v4l2_memory memory, unsigned int count)
 {
@@ -525,7 +512,7 @@ static int frame_alloc(struct gspca_dev *gspca_dev, struct file *file,
                count = GSPCA_MAX_FRAMES - 1;
        gspca_dev->frbuf = vmalloc_32(frsz * count);
        if (!gspca_dev->frbuf) {
-               err("frame alloc failed");
+               pr_err("frame alloc failed\n");
                return -ENOMEM;
        }
        gspca_dev->capt_file = file;
@@ -597,7 +584,7 @@ static int gspca_set_alt0(struct gspca_dev *gspca_dev)
                return 0;
        ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, 0);
        if (ret < 0)
-               err("set alt 0 err %d", ret);
+               pr_err("set alt 0 err %d\n", ret);
        return ret;
 }
 
@@ -640,53 +627,104 @@ static struct usb_host_endpoint *alt_xfer(struct usb_host_interface *alt,
        return NULL;
 }
 
+/* compute the minimum bandwidth for the current transfer */
+static u32 which_bandwidth(struct gspca_dev *gspca_dev)
+{
+       u32 bandwidth;
+       int i;
+
+       i = gspca_dev->curr_mode;
+       bandwidth = gspca_dev->cam.cam_mode[i].sizeimage;
+
+       /* if the image is compressed, estimate the mean image size */
+       if (bandwidth < gspca_dev->cam.cam_mode[i].width *
+                               gspca_dev->cam.cam_mode[i].height)
+               bandwidth /= 3;
+
+       /* estimate the frame rate */
+       if (gspca_dev->sd_desc->get_streamparm) {
+               struct v4l2_streamparm parm;
+
+               parm.parm.capture.timeperframe.denominator = 15;
+               gspca_dev->sd_desc->get_streamparm(gspca_dev, &parm);
+               bandwidth *= parm.parm.capture.timeperframe.denominator;
+       } else {
+               bandwidth *= 15;                /* 15 fps */
+       }
+
+       PDEBUG(D_STREAM, "min bandwidth: %d", bandwidth);
+       return bandwidth;
+}
+
+/* endpoint table */
+#define MAX_ALT 16
+struct ep_tb_s {
+       u32 alt;
+       u32 bandwidth;
+};
+
 /*
- * look for an input (isoc or bulk) endpoint
- *
- * The endpoint is defined by the subdriver.
- * Use only the first isoc (some Zoran - 0x0572:0x0001 - have two such ep).
- * This routine may be called many times when the bandwidth is too small
- * (the bandwidth is checked on urb submit).
+ * build the table of the endpoints
+ * and compute the minimum bandwidth for the image transfer
  */
-static struct usb_host_endpoint *get_ep(struct gspca_dev *gspca_dev)
+static int build_ep_tb(struct gspca_dev *gspca_dev,
+                       struct usb_interface *intf,
+                       int xfer,
+                       struct ep_tb_s *ep_tb)
 {
-       struct usb_interface *intf;
        struct usb_host_endpoint *ep;
-       int xfer, i, ret;
+       int i, j, nbalt, psize, found;
+       u32 bandwidth, last_bw;
 
-       intf = usb_ifnum_to_if(gspca_dev->dev, gspca_dev->iface);
-       ep = NULL;
-       xfer = gspca_dev->cam.bulk ? USB_ENDPOINT_XFER_BULK
-                                  : USB_ENDPOINT_XFER_ISOC;
-       i = gspca_dev->alt;                     /* previous alt setting */
-       if (gspca_dev->cam.reverse_alts) {
-               while (++i < gspca_dev->nbalt) {
-                       ep = alt_xfer(&intf->altsetting[i], xfer);
-                       if (ep)
-                               break;
-               }
-       } else {
-               while (--i >= 0) {
-                       ep = alt_xfer(&intf->altsetting[i], xfer);
-                       if (ep)
-                               break;
-               }
-       }
-       if (ep == NULL) {
-               err("no transfer endpoint found");
-               return NULL;
-       }
-       PDEBUG(D_STREAM, "use alt %d ep 0x%02x",
-                       i, ep->desc.bEndpointAddress);
-       gspca_dev->alt = i;             /* memorize the current alt setting */
-       if (gspca_dev->nbalt > 1) {
-               ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, i);
-               if (ret < 0) {
-                       err("set alt %d err %d", i, ret);
-                       ep = NULL;
+       nbalt = intf->num_altsetting;
+       if (nbalt > MAX_ALT)
+               nbalt = MAX_ALT;        /* fixme: should warn */
+
+       /* build the endpoint table */
+       i = 0;
+       last_bw = 0;
+       for (;;) {
+               ep_tb->bandwidth = 2000 * 2000 * 120;
+               found = 0;
+               for (j = 0; j < nbalt; j++) {
+                       ep = alt_xfer(&intf->altsetting[j], xfer);
+                       if (ep == NULL)
+                               continue;
+                       psize = le16_to_cpu(ep->desc.wMaxPacketSize);
+                       if (!gspca_dev->cam.bulk)               /* isoc */
+                               psize = (psize & 0x07ff) *
+                                               (1 + ((psize >> 11) & 3));
+                       bandwidth = psize * ep->desc.bInterval * 1000;
+                       if (gspca_dev->dev->speed == USB_SPEED_HIGH
+                        || gspca_dev->dev->speed == USB_SPEED_SUPER)
+                               bandwidth *= 8;
+                       if (bandwidth <= last_bw)
+                               continue;
+                       if (bandwidth < ep_tb->bandwidth) {
+                               ep_tb->bandwidth = bandwidth;
+                               ep_tb->alt = j;
+                               found = 1;
+                       }
                }
+               if (!found)
+                       break;
+               PDEBUG(D_STREAM, "alt %d bandwidth %d",
+                               ep_tb->alt, ep_tb->bandwidth);
+               last_bw = ep_tb->bandwidth;
+               i++;
+               ep_tb++;
+       }
+
+       /* get the requested bandwidth and start at the highest atlsetting */
+       bandwidth = which_bandwidth(gspca_dev);
+       ep_tb--;
+       while (i > 1) {
+               ep_tb--;
+               if (ep_tb->bandwidth < bandwidth)
+                       break;
+               i--;
        }
-       return ep;
+       return i;
 }
 
 /*
@@ -731,7 +769,7 @@ static int create_urbs(struct gspca_dev *gspca_dev,
        for (n = 0; n < nurbs; n++) {
                urb = usb_alloc_urb(npkt, GFP_KERNEL);
                if (!urb) {
-                       err("usb_alloc_urb failed");
+                       pr_err("usb_alloc_urb failed\n");
                        return -ENOMEM;
                }
                gspca_dev->urb[n] = urb;
@@ -741,7 +779,7 @@ static int create_urbs(struct gspca_dev *gspca_dev,
                                                &urb->transfer_dma);
 
                if (urb->transfer_buffer == NULL) {
-                       err("usb_alloc_coherent failed");
+                       pr_err("usb_alloc_coherent failed\n");
                        return -ENOMEM;
                }
                urb->dev = gspca_dev->dev;
@@ -752,7 +790,10 @@ static int create_urbs(struct gspca_dev *gspca_dev,
                                                    ep->desc.bEndpointAddress);
                        urb->transfer_flags = URB_ISO_ASAP
                                        | URB_NO_TRANSFER_DMA_MAP;
-                       urb->interval = ep->desc.bInterval;
+                       if (gspca_dev->dev->speed == USB_SPEED_LOW)
+                               urb->interval = ep->desc.bInterval;
+                       else
+                               urb->interval = 1 << (ep->desc.bInterval - 1);
                        urb->complete = isoc_irq;
                        urb->number_of_packets = npkt;
                        for (i = 0; i < npkt; i++) {
@@ -774,9 +815,11 @@ static int create_urbs(struct gspca_dev *gspca_dev,
  */
 static int gspca_init_transfer(struct gspca_dev *gspca_dev)
 {
+       struct usb_interface *intf;
        struct usb_host_endpoint *ep;
        struct urb *urb;
-       int n, ret;
+       struct ep_tb_s ep_tb[MAX_ALT];
+       int n, ret, xfer, alt, alt_idx;
 
        if (mutex_lock_interruptible(&gspca_dev->usb_lock))
                return -ERESTARTSYS;
@@ -794,30 +837,65 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev)
 
        gspca_dev->usb_err = 0;
 
-       /* set the higher alternate setting and
-        * loop until urb submit succeeds */
-       if (gspca_dev->cam.reverse_alts)
-               gspca_dev->alt = 0;
-       else
-               gspca_dev->alt = gspca_dev->nbalt;
-
+       /* do the specific subdriver stuff before endpoint selection */
+       gspca_dev->alt = 0;
        if (gspca_dev->sd_desc->isoc_init) {
                ret = gspca_dev->sd_desc->isoc_init(gspca_dev);
                if (ret < 0)
                        goto unlock;
        }
+       intf = usb_ifnum_to_if(gspca_dev->dev, gspca_dev->iface);
+       xfer = gspca_dev->cam.bulk ? USB_ENDPOINT_XFER_BULK
+                                  : USB_ENDPOINT_XFER_ISOC;
 
-       gspca_input_destroy_urb(gspca_dev);
-       ep = get_ep(gspca_dev);
-       if (ep == NULL) {
-               ret = -EIO;
-               goto out;
+       /* if the subdriver forced an altsetting, get the endpoint */
+       if (gspca_dev->alt != 0) {
+               gspca_dev->alt--;       /* (previous version compatibility) */
+               ep = alt_xfer(&intf->altsetting[gspca_dev->alt], xfer);
+               if (ep == NULL) {
+                       pr_err("bad altsetting %d\n", gspca_dev->alt);
+                       ret = -EIO;
+                       goto out;
+               }
+               ep_tb[0].alt = gspca_dev->alt;
+               alt_idx = 1;
+       } else {
+
+       /* else, compute the minimum bandwidth
+        * and build the endpoint table */
+               alt_idx = build_ep_tb(gspca_dev, intf, xfer, ep_tb);
+               if (alt_idx <= 0) {
+                       pr_err("no transfer endpoint found\n");
+                       ret = -EIO;
+                       goto unlock;
+               }
        }
+
+       /* set the highest alternate setting and
+        * loop until urb submit succeeds */
+       gspca_input_destroy_urb(gspca_dev);
+
+       gspca_dev->alt = ep_tb[--alt_idx].alt;
+       alt = -1;
        for (;;) {
+               if (alt != gspca_dev->alt) {
+                       alt = gspca_dev->alt;
+                       if (gspca_dev->nbalt > 1) {
+                               ret = usb_set_interface(gspca_dev->dev,
+                                                       gspca_dev->iface,
+                                                       alt);
+                               if (ret < 0) {
+                                       if (ret == -ENOSPC)
+                                               goto retry; /*fixme: ugly*/
+                                       pr_err("set alt %d err %d\n", alt, ret);
+                                       goto out;
+                               }
+                       }
+               }
                if (!gspca_dev->cam.no_urb_create) {
-                       PDEBUG(D_STREAM, "init transfer alt %d",
-                               gspca_dev->alt);
-                       ret = create_urbs(gspca_dev, ep);
+                       PDEBUG(D_STREAM, "init transfer alt %d", alt);
+                       ret = create_urbs(gspca_dev,
+                               alt_xfer(&intf->altsetting[alt], xfer));
                        if (ret < 0) {
                                destroy_urbs(gspca_dev);
                                goto out;
@@ -851,29 +929,35 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev)
                                break;
                }
                if (ret >= 0)
-                       break;
+                       break;                  /* transfer is started */
+
+               /* something when wrong
+                * stop the webcam and free the transfer resources */
                gspca_stream_off(gspca_dev);
                if (ret != -ENOSPC) {
-                       err("usb_submit_urb alt %d err %d",
-                               gspca_dev->alt, ret);
+                       pr_err("usb_submit_urb alt %d err %d\n",
+                              gspca_dev->alt, ret);
                        goto out;
                }
 
                /* the bandwidth is not wide enough
                 * negotiate or try a lower alternate setting */
+retry:
                PDEBUG(D_ERR|D_STREAM,
-                       "bandwidth not wide enough - trying again");
+                       "alt %d - bandwidth not wide enough - trying again",
+                       alt);
                msleep(20);     /* wait for kill complete */
                if (gspca_dev->sd_desc->isoc_nego) {
                        ret = gspca_dev->sd_desc->isoc_nego(gspca_dev);
                        if (ret < 0)
                                goto out;
                } else {
-                       ep = get_ep(gspca_dev);
-                       if (ep == NULL) {
+                       if (alt_idx <= 0) {
+                               pr_err("no transfer endpoint found\n");
                                ret = -EIO;
                                goto out;
                        }
+                       alt = ep_tb[--alt_idx].alt;
                }
        }
 out:
@@ -1044,7 +1128,9 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void  *priv,
                return -EINVAL;         /* no more format */
 
        fmtdesc->pixelformat = fmt_tb[index];
-       if (gspca_is_compressed(fmt_tb[index]))
+       if (gspca_dev->cam.cam_mode[i].sizeimage <
+                       gspca_dev->cam.cam_mode[i].width *
+                               gspca_dev->cam.cam_mode[i].height)
                fmtdesc->flags = V4L2_FMT_FLAG_COMPRESSED;
        fmtdesc->description[0] = fmtdesc->pixelformat & 0xff;
        fmtdesc->description[1] = (fmtdesc->pixelformat >> 8) & 0xff;
@@ -2195,19 +2281,20 @@ int gspca_dev_probe2(struct usb_interface *intf,
        struct usb_device *dev = interface_to_usbdev(intf);
        int ret;
 
-       PDEBUG(D_PROBE, "probing %04x:%04x", id->idVendor, id->idProduct);
+       pr_info("%s-" GSPCA_VERSION " probing %04x:%04x\n",
+               sd_desc->name, id->idVendor, id->idProduct);
 
        /* create the device */
        if (dev_size < sizeof *gspca_dev)
                dev_size = sizeof *gspca_dev;
        gspca_dev = kzalloc(dev_size, GFP_KERNEL);
        if (!gspca_dev) {
-               err("couldn't kzalloc gspca struct");
+               pr_err("couldn't kzalloc gspca struct\n");
                return -ENOMEM;
        }
        gspca_dev->usb_buf = kmalloc(USB_BUF_SZ, GFP_KERNEL);
        if (!gspca_dev->usb_buf) {
-               err("out of memory");
+               pr_err("out of memory\n");
                ret = -ENOMEM;
                goto out;
        }
@@ -2264,7 +2351,7 @@ int gspca_dev_probe2(struct usb_interface *intf,
                                  VFL_TYPE_GRABBER,
                                  -1);
        if (ret < 0) {
-               err("video_register_device err %d", ret);
+               pr_err("video_register_device err %d\n", ret);
                goto out;
        }
 
@@ -2296,8 +2383,8 @@ int gspca_dev_probe(struct usb_interface *intf,
 
        /* we don't handle multi-config cameras */
        if (dev->descriptor.bNumConfigurations != 1) {
-               err("%04x:%04x too many config",
-                               id->idVendor, id->idProduct);
+               pr_err("%04x:%04x too many config\n",
+                      id->idVendor, id->idProduct);
                return -ENODEV;
        }
 
@@ -2480,7 +2567,7 @@ EXPORT_SYMBOL(gspca_auto_gain_n_exposure);
 /* -- module insert / remove -- */
 static int __init gspca_init(void)
 {
-       info("v" DRIVER_VERSION_NUMBER " registered");
+       pr_info("v" GSPCA_VERSION " registered\n");
        return 0;
 }
 static void __exit gspca_exit(void)
index 49e2fcbe81fbbfedcd08c04a63e09deaf48d524e..e444f16e14971c97d02d63e13d74fe57c4fc32ee 100644 (file)
 #ifdef GSPCA_DEBUG
 /* GSPCA our debug messages */
 extern int gspca_debug;
-#define PDEBUG(level, fmt, args...) \
-       do {\
-               if (gspca_debug & (level)) \
-                       printk(KERN_INFO MODULE_NAME ": " fmt "\n", ## args); \
-       } while (0)
+#define PDEBUG(level, fmt, ...)                                        \
+do {                                                           \
+       if (gspca_debug & (level))                              \
+               pr_info(fmt, ##__VA_ARGS__);                    \
+} while (0)
+
 #define D_ERR  0x01
 #define D_PROBE 0x02
 #define D_CONF 0x04
@@ -29,17 +30,8 @@ extern int gspca_debug;
 #define D_USBO 0x00
 #define D_V4L2 0x0100
 #else
-#define PDEBUG(level, fmt, args...)
+#define PDEBUG(level, fmt, ...)
 #endif
-#undef err
-#define err(fmt, args...) \
-       printk(KERN_ERR MODULE_NAME ": " fmt "\n", ## args)
-#undef info
-#define info(fmt, args...) \
-       printk(KERN_INFO MODULE_NAME ": " fmt "\n", ## args)
-#undef warn
-#define warn(fmt, args...) \
-       printk(KERN_WARNING MODULE_NAME ": " fmt "\n", ## args)
 
 #define GSPCA_MAX_FRAMES 16    /* maximum number of video frame buffers */
 /* image transfers */
index 1bd9c4b542dd8fbb221bc5c0f843d79a3764f3e7..8e3dabe30077d85837c35ffdb3fd4a5ba0094000 100644 (file)
@@ -24,6 +24,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "jeilinj"
 
 #include <linux/slab.h>
@@ -113,8 +115,8 @@ static void jlj_write2(struct gspca_dev *gspca_dev, unsigned char *command)
                        usb_sndbulkpipe(gspca_dev->dev, 3),
                        gspca_dev->usb_buf, 2, NULL, 500);
        if (retval < 0) {
-               err("command write [%02x] error %d",
-                               gspca_dev->usb_buf[0], retval);
+               pr_err("command write [%02x] error %d\n",
+                      gspca_dev->usb_buf[0], retval);
                gspca_dev->usb_err = retval;
        }
 }
@@ -131,8 +133,8 @@ static void jlj_read1(struct gspca_dev *gspca_dev, unsigned char response)
                                gspca_dev->usb_buf, 1, NULL, 500);
        response = gspca_dev->usb_buf[0];
        if (retval < 0) {
-               err("read command [%02x] error %d",
-                               gspca_dev->usb_buf[0], retval);
+               pr_err("read command [%02x] error %d\n",
+                      gspca_dev->usb_buf[0], retval);
                gspca_dev->usb_err = retval;
        }
 }
@@ -403,13 +405,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
        dev->type = id->driver_info;
        gspca_dev->cam.ctrls = dev->ctrls;
        dev->quality = QUALITY_DEF;
-       dev->ctrls[LIGHTFREQ].def = V4L2_CID_POWER_LINE_FREQUENCY_60HZ;
-       dev->ctrls[RED].def = RED_BALANCE_DEF;
-       dev->ctrls[GREEN].def = GREEN_BALANCE_DEF;
-       dev->ctrls[BLUE].def = BLUE_BALANCE_DEF;
-       PDEBUG(D_PROBE,
-               "JEILINJ camera detected"
-               " (vid/pid 0x%04X:0x%04X)", id->idVendor, id->idProduct);
+
        cam->cam_mode = jlj_mode;
        cam->nmodes = ARRAY_SIZE(jlj_mode);
        cam->bulk = 1;
@@ -422,7 +418,7 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
 {
        int i;
        u8 *buf;
-       u8 stop_commands[][2] = {
+       static u8 stop_commands[][2] = {
                {0x71, 0x00},
                {0x70, 0x09},
                {0x71, 0x80},
index 26fc206f095e13f9e202c13e7754236af0daa551..4fe51fda80f30f5369ff3ab2c4bf064133cdf314 100644 (file)
@@ -24,6 +24,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "kinect"
 
 #include "gspca.h"
@@ -34,11 +36,6 @@ MODULE_AUTHOR("Antonio Ospite <ospite@studenti.unina.it>");
 MODULE_DESCRIPTION("GSPCA/Kinect Sensor Device USB Camera Driver");
 MODULE_LICENSE("GPL");
 
-#ifdef GSPCA_DEBUG
-int gspca_debug = D_ERR | D_PROBE | D_CONF | D_STREAM | D_FRAM | D_PACK |
-       D_USBI | D_USBO | D_V4L2;
-#endif
-
 struct pkt_hdr {
        uint8_t magic[2];
        uint8_t pad;
@@ -141,7 +138,7 @@ static int send_cmd(struct gspca_dev *gspca_dev, uint16_t cmd, void *cmdbuf,
        struct cam_hdr *rhdr = (void *)ibuf;
 
        if (cmd_len & 1 || cmd_len > (0x400 - sizeof(*chdr))) {
-               err("send_cmd: Invalid command length (0x%x)", cmd_len);
+               pr_err("send_cmd: Invalid command length (0x%x)\n", cmd_len);
                return -1;
        }
 
@@ -157,7 +154,7 @@ static int send_cmd(struct gspca_dev *gspca_dev, uint16_t cmd, void *cmdbuf,
        PDEBUG(D_USBO, "Control cmd=%04x tag=%04x len=%04x: %d", cmd,
                sd->cam_tag, cmd_len, res);
        if (res < 0) {
-               err("send_cmd: Output control transfer failed (%d)", res);
+               pr_err("send_cmd: Output control transfer failed (%d)\n", res);
                return res;
        }
 
@@ -166,33 +163,35 @@ static int send_cmd(struct gspca_dev *gspca_dev, uint16_t cmd, void *cmdbuf,
        } while (actual_len == 0);
        PDEBUG(D_USBO, "Control reply: %d", res);
        if (actual_len < sizeof(*rhdr)) {
-               err("send_cmd: Input control transfer failed (%d)", res);
+               pr_err("send_cmd: Input control transfer failed (%d)\n", res);
                return res;
        }
        actual_len -= sizeof(*rhdr);
 
        if (rhdr->magic[0] != 0x52 || rhdr->magic[1] != 0x42) {
-               err("send_cmd: Bad magic %02x %02x", rhdr->magic[0],
-                       rhdr->magic[1]);
+               pr_err("send_cmd: Bad magic %02x %02x\n",
+                      rhdr->magic[0], rhdr->magic[1]);
                return -1;
        }
        if (rhdr->cmd != chdr->cmd) {
-               err("send_cmd: Bad cmd %02x != %02x", rhdr->cmd, chdr->cmd);
+               pr_err("send_cmd: Bad cmd %02x != %02x\n",
+                      rhdr->cmd, chdr->cmd);
                return -1;
        }
        if (rhdr->tag != chdr->tag) {
-               err("send_cmd: Bad tag %04x != %04x", rhdr->tag, chdr->tag);
+               pr_err("send_cmd: Bad tag %04x != %04x\n",
+                      rhdr->tag, chdr->tag);
                return -1;
        }
        if (cpu_to_le16(rhdr->len) != (actual_len/2)) {
-               err("send_cmd: Bad len %04x != %04x",
-                               cpu_to_le16(rhdr->len), (int)(actual_len/2));
+               pr_err("send_cmd: Bad len %04x != %04x\n",
+                      cpu_to_le16(rhdr->len), (int)(actual_len/2));
                return -1;
        }
 
        if (actual_len > reply_len) {
-               warn("send_cmd: Data buffer is %d bytes long, but got %d bytes",
-                               reply_len, actual_len);
+               pr_warn("send_cmd: Data buffer is %d bytes long, but got %d bytes\n",
+                       reply_len, actual_len);
                memcpy(replybuf, ibuf+sizeof(*rhdr), reply_len);
        } else {
                memcpy(replybuf, ibuf+sizeof(*rhdr), actual_len);
@@ -218,8 +217,8 @@ static int write_register(struct gspca_dev *gspca_dev, uint16_t reg,
        if (res < 0)
                return res;
        if (res != 2) {
-               warn("send_cmd returned %d [%04x %04x], 0000 expected",
-                               res, reply[0], reply[1]);
+               pr_warn("send_cmd returned %d [%04x %04x], 0000 expected\n",
+                       res, reply[0], reply[1]);
        }
        return 0;
 }
@@ -353,8 +352,8 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, u8 *__data, int len)
                return;
 
        if (hdr->magic[0] != 'R' || hdr->magic[1] != 'B') {
-               warn("[Stream %02x] Invalid magic %02x%02x", sd->stream_flag,
-                               hdr->magic[0], hdr->magic[1]);
+               pr_warn("[Stream %02x] Invalid magic %02x%02x\n",
+                       sd->stream_flag, hdr->magic[0], hdr->magic[1]);
                return;
        }
 
@@ -368,7 +367,7 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, u8 *__data, int len)
                gspca_frame_add(gspca_dev, LAST_PACKET, data, datalen);
 
        else
-               warn("Packet type not recognized...");
+               pr_warn("Packet type not recognized...\n");
 }
 
 /* sub-driver description */
index 5964691c0e95e66f8b6c56905181ba0281822b6f..f3f7fe0ec4b721bb679b5a6b2299f3b079b7cb9b 100644 (file)
@@ -28,6 +28,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "konica"
 
 #include <linux/input.h>
@@ -200,7 +202,7 @@ static void reg_w(struct gspca_dev *gspca_dev, u16 value, u16 index)
                        0,
                        1000);
        if (ret < 0) {
-               err("reg_w err %d", ret);
+               pr_err("reg_w err %d\n", ret);
                gspca_dev->usb_err = ret;
        }
 }
@@ -221,7 +223,7 @@ static void reg_r(struct gspca_dev *gspca_dev, u16 value, u16 index)
                        2,
                        1000);
        if (ret < 0) {
-               err("reg_w err %d", ret);
+               pr_err("reg_w err %d\n", ret);
                gspca_dev->usb_err = ret;
        }
 }
@@ -284,7 +286,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
        intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
        alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
        if (!alt) {
-               err("Couldn't get altsetting");
+               pr_err("Couldn't get altsetting\n");
                return -EIO;
        }
 
@@ -315,7 +317,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
                        le16_to_cpu(alt->endpoint[i].desc.wMaxPacketSize);
                urb = usb_alloc_urb(SD_NPKT, GFP_KERNEL);
                if (!urb) {
-                       err("usb_alloc_urb failed");
+                       pr_err("usb_alloc_urb failed\n");
                        return -ENOMEM;
                }
                gspca_dev->urb[n] = urb;
@@ -324,7 +326,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
                                                GFP_KERNEL,
                                                &urb->transfer_dma);
                if (urb->transfer_buffer == NULL) {
-                       err("usb_buffer_alloc failed");
+                       pr_err("usb_buffer_alloc failed\n");
                        return -ENOMEM;
                }
 
@@ -386,7 +388,7 @@ static void sd_isoc_irq(struct urb *urb)
                PDEBUG(D_ERR, "urb status: %d", urb->status);
                st = usb_submit_urb(urb, GFP_ATOMIC);
                if (st < 0)
-                       err("resubmit urb error %d", st);
+                       pr_err("resubmit urb error %d\n", st);
                return;
        }
 
@@ -477,7 +479,7 @@ resubmit:
        }
        st = usb_submit_urb(status_urb, GFP_ATOMIC);
        if (st < 0)
-               err("usb_submit_urb(status_urb) ret %d", st);
+               pr_err("usb_submit_urb(status_urb) ret %d\n", st);
 }
 
 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
index bf7a19a1e6d1470c3b5dbc611187a499ea53add8..7f52961f439c3b1b2a465110ddb48bf2b18a3b84 100644 (file)
@@ -8,4 +8,4 @@ gspca_m5602-objs := m5602_core.o \
                    m5602_s5k83a.o \
                    m5602_s5k4aa.o
 
-EXTRA_CFLAGS += -Idrivers/media/video/gspca
+ccflags-y += -Idrivers/media/video/gspca
index a7722b1aef9b5963d1dba5cd511a6860393e7dbf..67533e5582a64b8e1071a1a584b239dd8c465383 100644 (file)
@@ -16,6 +16,8 @@
  *
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include "m5602_ov9650.h"
 #include "m5602_ov7660.h"
 #include "m5602_mt9m111.h"
@@ -192,10 +194,9 @@ static void m5602_dump_bridge(struct sd *sd)
        for (i = 0; i < 0x80; i++) {
                unsigned char val = 0;
                m5602_read_bridge(sd, i, &val);
-               info("ALi m5602 address 0x%x contains 0x%x", i, val);
+               pr_info("ALi m5602 address 0x%x contains 0x%x\n", i, val);
        }
-       info("Warning: The ALi m5602 webcam probably won't work "
-               "until it's power cycled");
+       pr_info("Warning: The ALi m5602 webcam probably won't work until it's power cycled\n");
 }
 
 static int m5602_probe_sensor(struct sd *sd)
@@ -231,7 +232,7 @@ static int m5602_probe_sensor(struct sd *sd)
                return 0;
 
        /* More sensor probe function goes here */
-       info("Failed to find a sensor");
+       pr_info("Failed to find a sensor\n");
        sd->sensor = NULL;
        return -ENODEV;
 }
index 0d605a52b924e802b438858b0e9b4d2bbb4cdbf4..6268aa24ec5d9989ec4003f598fde028950fec3b 100644 (file)
@@ -16,6 +16,8 @@
  *
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include "m5602_mt9m111.h"
 
 static int mt9m111_set_vflip(struct gspca_dev *gspca_dev, __s32 val);
@@ -163,7 +165,7 @@ int mt9m111_probe(struct sd *sd)
 
        if (force_sensor) {
                if (force_sensor == MT9M111_SENSOR) {
-                       info("Forcing a %s sensor", mt9m111.name);
+                       pr_info("Forcing a %s sensor\n", mt9m111.name);
                        goto sensor_found;
                }
                /* If we want to force another sensor, don't try to probe this
@@ -191,7 +193,7 @@ int mt9m111_probe(struct sd *sd)
                return -ENODEV;
 
        if ((data[0] == 0x14) && (data[1] == 0x3a)) {
-               info("Detected a mt9m111 sensor");
+               pr_info("Detected a mt9m111 sensor\n");
                goto sensor_found;
        }
 
@@ -612,34 +614,34 @@ static void mt9m111_dump_registers(struct sd *sd)
 {
        u8 address, value[2] = {0x00, 0x00};
 
-       info("Dumping the mt9m111 register state");
+       pr_info("Dumping the mt9m111 register state\n");
 
-       info("Dumping the mt9m111 sensor core registers");
+       pr_info("Dumping the mt9m111 sensor core registers\n");
        value[1] = MT9M111_SENSOR_CORE;
        m5602_write_sensor(sd, MT9M111_PAGE_MAP, value, 2);
        for (address = 0; address < 0xff; address++) {
                m5602_read_sensor(sd, address, value, 2);
-               info("register 0x%x contains 0x%x%x",
-                    address, value[0], value[1]);
+               pr_info("register 0x%x contains 0x%x%x\n",
+                       address, value[0], value[1]);
        }
 
-       info("Dumping the mt9m111 color pipeline registers");
+       pr_info("Dumping the mt9m111 color pipeline registers\n");
        value[1] = MT9M111_COLORPIPE;
        m5602_write_sensor(sd, MT9M111_PAGE_MAP, value, 2);
        for (address = 0; address < 0xff; address++) {
                m5602_read_sensor(sd, address, value, 2);
-               info("register 0x%x contains 0x%x%x",
-                    address, value[0], value[1]);
+               pr_info("register 0x%x contains 0x%x%x\n",
+                       address, value[0], value[1]);
        }
 
-       info("Dumping the mt9m111 camera control registers");
+       pr_info("Dumping the mt9m111 camera control registers\n");
        value[1] = MT9M111_CAMERA_CONTROL;
        m5602_write_sensor(sd, MT9M111_PAGE_MAP, value, 2);
        for (address = 0; address < 0xff; address++) {
                m5602_read_sensor(sd, address, value, 2);
-               info("register 0x%x contains 0x%x%x",
-                    address, value[0], value[1]);
+               pr_info("register 0x%x contains 0x%x%x\n",
+                       address, value[0], value[1]);
        }
 
-       info("mt9m111 register state dump complete");
+       pr_info("mt9m111 register state dump complete\n");
 }
index b12f60464b3b99097a8b55c9f0ec464fa61f872d..9a14835c128fb9b8047d91b05ef0927aeeee65ec 100644 (file)
@@ -16,6 +16,8 @@
  *
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include "m5602_ov7660.h"
 
 static int ov7660_get_gain(struct gspca_dev *gspca_dev, __s32 *val);
@@ -149,7 +151,7 @@ int ov7660_probe(struct sd *sd)
 
        if (force_sensor) {
                if (force_sensor == OV7660_SENSOR) {
-                       info("Forcing an %s sensor", ov7660.name);
+                       pr_info("Forcing an %s sensor\n", ov7660.name);
                        goto sensor_found;
                }
                /* If we want to force another sensor,
@@ -180,10 +182,10 @@ int ov7660_probe(struct sd *sd)
        if (m5602_read_sensor(sd, OV7660_VER, &ver_id, 1))
                return -ENODEV;
 
-       info("Sensor reported 0x%x%x", prod_id, ver_id);
+       pr_info("Sensor reported 0x%x%x\n", prod_id, ver_id);
 
        if ((prod_id == 0x76) && (ver_id == 0x60)) {
-               info("Detected a ov7660 sensor");
+               pr_info("Detected a ov7660 sensor\n");
                goto sensor_found;
        }
        return -ENODEV;
@@ -457,17 +459,16 @@ static int ov7660_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
 static void ov7660_dump_registers(struct sd *sd)
 {
        int address;
-       info("Dumping the ov7660 register state");
+       pr_info("Dumping the ov7660 register state\n");
        for (address = 0; address < 0xa9; address++) {
                u8 value;
                m5602_read_sensor(sd, address, &value, 1);
-               info("register 0x%x contains 0x%x",
-                    address, value);
+               pr_info("register 0x%x contains 0x%x\n", address, value);
        }
 
-       info("ov7660 register state dump complete");
+       pr_info("ov7660 register state dump complete\n");
 
-       info("Probing for which registers that are read/write");
+       pr_info("Probing for which registers that are read/write\n");
        for (address = 0; address < 0xff; address++) {
                u8 old_value, ctrl_value;
                u8 test_value[2] = {0xff, 0xff};
@@ -477,9 +478,9 @@ static void ov7660_dump_registers(struct sd *sd)
                m5602_read_sensor(sd, address, &ctrl_value, 1);
 
                if (ctrl_value == test_value[0])
-                       info("register 0x%x is writeable", address);
+                       pr_info("register 0x%x is writeable\n", address);
                else
-                       info("register 0x%x is read only", address);
+                       pr_info("register 0x%x is read only\n", address);
 
                /* Restore original value */
                m5602_write_sensor(sd, address, &old_value, 1);
index 703d48670a240c893045411e8a6c98cb9ff4be03..2114a8b90ec98d53b16be0ef8a05367c09e5ea99 100644 (file)
@@ -16,6 +16,8 @@
  *
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include "m5602_ov9650.h"
 
 static int ov9650_set_exposure(struct gspca_dev *gspca_dev, __s32 val);
@@ -299,7 +301,7 @@ int ov9650_probe(struct sd *sd)
 
        if (force_sensor) {
                if (force_sensor == OV9650_SENSOR) {
-                       info("Forcing an %s sensor", ov9650.name);
+                       pr_info("Forcing an %s sensor\n", ov9650.name);
                        goto sensor_found;
                }
                /* If we want to force another sensor,
@@ -330,7 +332,7 @@ int ov9650_probe(struct sd *sd)
                return -ENODEV;
 
        if ((prod_id == 0x96) && (ver_id == 0x52)) {
-               info("Detected an ov9650 sensor");
+               pr_info("Detected an ov9650 sensor\n");
                goto sensor_found;
        }
        return -ENODEV;
@@ -850,17 +852,16 @@ static int ov9650_set_auto_gain(struct gspca_dev *gspca_dev, __s32 val)
 static void ov9650_dump_registers(struct sd *sd)
 {
        int address;
-       info("Dumping the ov9650 register state");
+       pr_info("Dumping the ov9650 register state\n");
        for (address = 0; address < 0xa9; address++) {
                u8 value;
                m5602_read_sensor(sd, address, &value, 1);
-               info("register 0x%x contains 0x%x",
-                    address, value);
+               pr_info("register 0x%x contains 0x%x\n", address, value);
        }
 
-       info("ov9650 register state dump complete");
+       pr_info("ov9650 register state dump complete\n");
 
-       info("Probing for which registers that are read/write");
+       pr_info("Probing for which registers that are read/write\n");
        for (address = 0; address < 0xff; address++) {
                u8 old_value, ctrl_value;
                u8 test_value[2] = {0xff, 0xff};
@@ -870,9 +871,9 @@ static void ov9650_dump_registers(struct sd *sd)
                m5602_read_sensor(sd, address, &ctrl_value, 1);
 
                if (ctrl_value == test_value[0])
-                       info("register 0x%x is writeable", address);
+                       pr_info("register 0x%x is writeable\n", address);
                else
-                       info("register 0x%x is read only", address);
+                       pr_info("register 0x%x is read only\n", address);
 
                /* Restore original value */
                m5602_write_sensor(sd, address, &old_value, 1);
index 1febd34c2f0591a5bc3ebce9068af26e8332e832..b8771698cbcb1b8260654adc8d9cba84504139e5 100644 (file)
@@ -16,6 +16,8 @@
  *
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include "m5602_po1030.h"
 
 static int po1030_get_exposure(struct gspca_dev *gspca_dev, __s32 *val);
@@ -197,7 +199,7 @@ int po1030_probe(struct sd *sd)
 
        if (force_sensor) {
                if (force_sensor == PO1030_SENSOR) {
-                       info("Forcing a %s sensor", po1030.name);
+                       pr_info("Forcing a %s sensor\n", po1030.name);
                        goto sensor_found;
                }
                /* If we want to force another sensor, don't try to probe this
@@ -221,7 +223,7 @@ int po1030_probe(struct sd *sd)
                return -ENODEV;
 
        if (dev_id_h == 0x30) {
-               info("Detected a po1030 sensor");
+               pr_info("Detected a po1030 sensor\n");
                goto sensor_found;
        }
        return -ENODEV;
@@ -267,7 +269,7 @@ int po1030_init(struct sd *sd)
                        break;
 
                default:
-                       info("Invalid stream command, exiting init");
+                       pr_info("Invalid stream command, exiting init\n");
                        return -EINVAL;
                }
        }
@@ -733,16 +735,15 @@ static void po1030_dump_registers(struct sd *sd)
        int address;
        u8 value = 0;
 
-       info("Dumping the po1030 sensor core registers");
+       pr_info("Dumping the po1030 sensor core registers\n");
        for (address = 0; address < 0x7f; address++) {
                m5602_read_sensor(sd, address, &value, 1);
-               info("register 0x%x contains 0x%x",
-                    address, value);
+               pr_info("register 0x%x contains 0x%x\n", address, value);
        }
 
-       info("po1030 register state dump complete");
+       pr_info("po1030 register state dump complete\n");
 
-       info("Probing for which registers that are read/write");
+       pr_info("Probing for which registers that are read/write\n");
        for (address = 0; address < 0xff; address++) {
                u8 old_value, ctrl_value;
                u8 test_value[2] = {0xff, 0xff};
@@ -752,9 +753,9 @@ static void po1030_dump_registers(struct sd *sd)
                m5602_read_sensor(sd, address, &ctrl_value, 1);
 
                if (ctrl_value == test_value[0])
-                       info("register 0x%x is writeable", address);
+                       pr_info("register 0x%x is writeable\n", address);
                else
-                       info("register 0x%x is read only", address);
+                       pr_info("register 0x%x is read only\n", address);
 
                /* Restore original value */
                m5602_write_sensor(sd, address, &old_value, 1);
index d27280be9852ddc864f37787bdb38c28173018f6..cc8ec3f7e8dc59df40952cc0dfdaf810c86e4ffd 100644 (file)
@@ -16,6 +16,8 @@
  *
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include "m5602_s5k4aa.h"
 
 static int s5k4aa_get_exposure(struct gspca_dev *gspca_dev, __s32 *val);
@@ -240,7 +242,7 @@ int s5k4aa_probe(struct sd *sd)
 
        if (force_sensor) {
                if (force_sensor == S5K4AA_SENSOR) {
-                       info("Forcing a %s sensor", s5k4aa.name);
+                       pr_info("Forcing a %s sensor\n", s5k4aa.name);
                        goto sensor_found;
                }
                /* If we want to force another sensor, don't try to probe this
@@ -276,7 +278,7 @@ int s5k4aa_probe(struct sd *sd)
                                                  data, 2);
                        break;
                default:
-                       info("Invalid stream command, exiting init");
+                       pr_info("Invalid stream command, exiting init\n");
                        return -EINVAL;
                }
        }
@@ -292,7 +294,7 @@ int s5k4aa_probe(struct sd *sd)
        if (memcmp(prod_id, expected_prod_id, sizeof(prod_id)))
                return -ENODEV;
        else
-               info("Detected a s5k4aa sensor");
+               pr_info("Detected a s5k4aa sensor\n");
 
 sensor_found:
        sensor_settings = kmalloc(
@@ -347,7 +349,7 @@ int s5k4aa_start(struct sd *sd)
                        break;
 
                        default:
-                               err("Invalid stream command, exiting init");
+                               pr_err("Invalid stream command, exiting init\n");
                                return -EINVAL;
                        }
                }
@@ -383,7 +385,7 @@ int s5k4aa_start(struct sd *sd)
                        break;
 
                        default:
-                               err("Invalid stream command, exiting init");
+                               pr_err("Invalid stream command, exiting init\n");
                                return -EINVAL;
                        }
                }
@@ -447,7 +449,7 @@ int s5k4aa_init(struct sd *sd)
                                init_s5k4aa[i][1], data, 2);
                        break;
                default:
-                       info("Invalid stream command, exiting init");
+                       pr_info("Invalid stream command, exiting init\n");
                        return -EINVAL;
                }
        }
@@ -686,20 +688,21 @@ static void s5k4aa_dump_registers(struct sd *sd)
        m5602_read_sensor(sd, S5K4AA_PAGE_MAP, &old_page, 1);
        for (page = 0; page < 16; page++) {
                m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &page, 1);
-               info("Dumping the s5k4aa register state for page 0x%x", page);
+               pr_info("Dumping the s5k4aa register state for page 0x%x\n",
+                       page);
                for (address = 0; address <= 0xff; address++) {
                        u8 value = 0;
                        m5602_read_sensor(sd, address, &value, 1);
-                       info("register 0x%x contains 0x%x",
-                            address, value);
+                       pr_info("register 0x%x contains 0x%x\n",
+                               address, value);
                }
        }
-       info("s5k4aa register state dump complete");
+       pr_info("s5k4aa register state dump complete\n");
 
        for (page = 0; page < 16; page++) {
                m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &page, 1);
-               info("Probing for which registers that are "
-                    "read/write for page 0x%x", page);
+               pr_info("Probing for which registers that are read/write for page 0x%x\n",
+                       page);
                for (address = 0; address <= 0xff; address++) {
                        u8 old_value, ctrl_value, test_value = 0xff;
 
@@ -708,14 +711,16 @@ static void s5k4aa_dump_registers(struct sd *sd)
                        m5602_read_sensor(sd, address, &ctrl_value, 1);
 
                        if (ctrl_value == test_value)
-                               info("register 0x%x is writeable", address);
+                               pr_info("register 0x%x is writeable\n",
+                                       address);
                        else
-                               info("register 0x%x is read only", address);
+                               pr_info("register 0x%x is read only\n",
+                                       address);
 
                        /* Restore original value */
                        m5602_write_sensor(sd, address, &old_value, 1);
                }
        }
-       info("Read/write register probing complete");
+       pr_info("Read/write register probing complete\n");
        m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &old_page, 1);
 }
index fbd91545497a8e6b36d36ecae38898664c8e4d34..1de743a02b02521e8effe86129c287046a4f1566 100644 (file)
@@ -16,6 +16,8 @@
  *
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/kthread.h>
 #include "m5602_s5k83a.h"
 
@@ -135,7 +137,7 @@ int s5k83a_probe(struct sd *sd)
 
        if (force_sensor) {
                if (force_sensor == S5K83A_SENSOR) {
-                       info("Forcing a %s sensor", s5k83a.name);
+                       pr_info("Forcing a %s sensor\n", s5k83a.name);
                        goto sensor_found;
                }
                /* If we want to force another sensor, don't try to probe this
@@ -168,7 +170,7 @@ int s5k83a_probe(struct sd *sd)
        if ((prod_id == 0xff) || (ver_id == 0xff))
                return -ENODEV;
        else
-               info("Detected a s5k83a sensor");
+               pr_info("Detected a s5k83a sensor\n");
 
 sensor_found:
        sens_priv = kmalloc(
@@ -227,7 +229,7 @@ int s5k83a_init(struct sd *sd)
                                init_s5k83a[i][1], data, 2);
                        break;
                default:
-                       info("Invalid stream command, exiting init");
+                       pr_info("Invalid stream command, exiting init\n");
                        return -EINVAL;
                }
        }
@@ -273,7 +275,7 @@ static int rotation_thread_function(void *data)
                s5k83a_get_rotation(sd, &reg);
                if (previous_rotation != reg) {
                        previous_rotation = reg;
-                       info("Camera was flipped");
+                       pr_info("Camera was flipped\n");
 
                        s5k83a_get_vflip((struct gspca_dev *) sd, &vflip);
                        s5k83a_get_hflip((struct gspca_dev *) sd, &hflip);
@@ -566,20 +568,20 @@ static void s5k83a_dump_registers(struct sd *sd)
 
        for (page = 0; page < 16; page++) {
                m5602_write_sensor(sd, S5K83A_PAGE_MAP, &page, 1);
-               info("Dumping the s5k83a register state for page 0x%x", page);
+               pr_info("Dumping the s5k83a register state for page 0x%x\n",
+                       page);
                for (address = 0; address <= 0xff; address++) {
                        u8 val = 0;
                        m5602_read_sensor(sd, address, &val, 1);
-                       info("register 0x%x contains 0x%x",
-                            address, val);
+                       pr_info("register 0x%x contains 0x%x\n", address, val);
                }
        }
-       info("s5k83a register state dump complete");
+       pr_info("s5k83a register state dump complete\n");
 
        for (page = 0; page < 16; page++) {
                m5602_write_sensor(sd, S5K83A_PAGE_MAP, &page, 1);
-               info("Probing for which registers that are read/write "
-                               "for page 0x%x", page);
+               pr_info("Probing for which registers that are read/write for page 0x%x\n",
+                       page);
                for (address = 0; address <= 0xff; address++) {
                        u8 old_val, ctrl_val, test_val = 0xff;
 
@@ -588,14 +590,16 @@ static void s5k83a_dump_registers(struct sd *sd)
                        m5602_read_sensor(sd, address, &ctrl_val, 1);
 
                        if (ctrl_val == test_val)
-                               info("register 0x%x is writeable", address);
+                               pr_info("register 0x%x is writeable\n",
+                                       address);
                        else
-                               info("register 0x%x is read only", address);
+                               pr_info("register 0x%x is read only\n",
+                                       address);
 
                        /* Restore original val */
                        m5602_write_sensor(sd, address, &old_val, 1);
                }
        }
-       info("Read/write register probing complete");
+       pr_info("Read/write register probing complete\n");
        m5602_write_sensor(sd, S5K83A_PAGE_MAP, &old_page, 1);
 }
index 0196209a948a879846fcbb660b11a0fe91feddc0..ef45fa575752607823267946c38d17289e6c6d16 100644 (file)
@@ -19,6 +19,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "mars"
 
 #include "gspca.h"
@@ -178,8 +180,8 @@ static void reg_w(struct gspca_dev *gspca_dev,
                        &alen,
                        500);   /* timeout in milliseconds */
        if (ret < 0) {
-               err("reg write [%02x] error %d",
-                       gspca_dev->usb_buf[0], ret);
+               pr_err("reg write [%02x] error %d\n",
+                      gspca_dev->usb_buf[0], ret);
                gspca_dev->usb_err = ret;
        }
 }
index 97e50796743425c78cb99e762428322ebc1a4179..473e813b680e4dd0c1440bfdcdbc765485d98a7b 100644 (file)
@@ -40,6 +40,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "mr97310a"
 
 #include "gspca.h"
@@ -267,7 +269,7 @@ static int mr_write(struct gspca_dev *gspca_dev, int len)
                          usb_sndbulkpipe(gspca_dev->dev, 4),
                          gspca_dev->usb_buf, len, NULL, 500);
        if (rc < 0)
-               err("reg write [%02x] error %d",
+               pr_err("reg write [%02x] error %d\n",
                       gspca_dev->usb_buf[0], rc);
        return rc;
 }
@@ -281,7 +283,7 @@ static int mr_read(struct gspca_dev *gspca_dev, int len)
                          usb_rcvbulkpipe(gspca_dev->dev, 3),
                          gspca_dev->usb_buf, len, NULL, 500);
        if (rc < 0)
-               err("reg read [%02x] error %d",
+               pr_err("reg read [%02x] error %d\n",
                       gspca_dev->usb_buf[0], rc);
        return rc;
 }
@@ -540,7 +542,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
                        sd->sensor_type = 1;
                        break;
                default:
-                       err("Unknown CIF Sensor id : %02x",
+                       pr_err("Unknown CIF Sensor id : %02x\n",
                               gspca_dev->usb_buf[1]);
                        return -ENODEV;
                }
@@ -575,10 +577,10 @@ static int sd_config(struct gspca_dev *gspca_dev,
                        sd->sensor_type = 2;
                } else if ((gspca_dev->usb_buf[0] != 0x03) &&
                                        (gspca_dev->usb_buf[0] != 0x04)) {
-                       err("Unknown VGA Sensor id Byte 0: %02x",
-                                       gspca_dev->usb_buf[0]);
-                       err("Defaults assumed, may not work");
-                       err("Please report this");
+                       pr_err("Unknown VGA Sensor id Byte 0: %02x\n",
+                              gspca_dev->usb_buf[0]);
+                       pr_err("Defaults assumed, may not work\n");
+                       pr_err("Please report this\n");
                }
                /* Sakar Digital color needs to be adjusted. */
                if ((gspca_dev->usb_buf[0] == 0x03) &&
@@ -595,10 +597,10 @@ static int sd_config(struct gspca_dev *gspca_dev,
                                /* Nothing to do here. */
                                break;
                        default:
-                               err("Unknown VGA Sensor id Byte 1: %02x",
-                                       gspca_dev->usb_buf[1]);
-                               err("Defaults assumed, may not work");
-                               err("Please report this");
+                               pr_err("Unknown VGA Sensor id Byte 1: %02x\n",
+                                      gspca_dev->usb_buf[1]);
+                               pr_err("Defaults assumed, may not work\n");
+                               pr_err("Please report this\n");
                        }
                }
                PDEBUG(D_PROBE, "MR97310A VGA camera detected, sensor: %d",
index 8e754fd4dc5e4ba27b35e171ac9b961558272ba5..7681814e594f0c92fce9e18c5892345edab5e0b7 100644 (file)
@@ -20,6 +20,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "nw80x"
 
 #include "gspca.h"
@@ -1571,7 +1573,7 @@ static void reg_w(struct gspca_dev *gspca_dev,
                        len,
                        500);
        if (ret < 0) {
-               err("reg_w err %d", ret);
+               pr_err("reg_w err %d\n", ret);
                gspca_dev->usb_err = ret;
        }
 }
@@ -1592,7 +1594,7 @@ static void reg_r(struct gspca_dev *gspca_dev,
                        0x00, index,
                        gspca_dev->usb_buf, len, 500);
        if (ret < 0) {
-               err("reg_r err %d", ret);
+               pr_err("reg_r err %d\n", ret);
                gspca_dev->usb_err = ret;
                return;
        }
@@ -1802,7 +1804,8 @@ static int sd_config(struct gspca_dev *gspca_dev,
                }
        }
        if (webcam_chip[sd->webcam] != sd->bridge) {
-               err("Bad webcam type %d for NW80%d", sd->webcam, sd->bridge);
+               pr_err("Bad webcam type %d for NW80%d\n",
+                      sd->webcam, sd->bridge);
                gspca_dev->usb_err = -ENODEV;
                return gspca_dev->usb_err;
        }
index 18305c89083c567944890ec3ee451aa52b5182df..6a01b35a947814f0a84b025ef0ccb237389d748b 100644 (file)
@@ -36,6 +36,9 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  *
  */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "ov519"
 
 #include <linux/input.h>
@@ -2171,7 +2174,7 @@ static void reg_w(struct sd *sd, u16 index, u16 value)
                        sd->gspca_dev.usb_buf, 1, 500);
 leave:
        if (ret < 0) {
-               err("reg_w %02x failed %d", index, ret);
+               pr_err("reg_w %02x failed %d\n", index, ret);
                sd->gspca_dev.usb_err = ret;
                return;
        }
@@ -2210,7 +2213,7 @@ static int reg_r(struct sd *sd, u16 index)
                PDEBUG(D_USBI, "GET %02x 0000 %04x %02x",
                        req, index, ret);
        } else {
-               err("reg_r %02x failed %d", index, ret);
+               pr_err("reg_r %02x failed %d\n", index, ret);
                sd->gspca_dev.usb_err = ret;
        }
 
@@ -2235,7 +2238,7 @@ static int reg_r8(struct sd *sd,
        if (ret >= 0) {
                ret = sd->gspca_dev.usb_buf[0];
        } else {
-               err("reg_r8 %02x failed %d", index, ret);
+               pr_err("reg_r8 %02x failed %d\n", index, ret);
                sd->gspca_dev.usb_err = ret;
        }
 
@@ -2288,7 +2291,7 @@ static void ov518_reg_w32(struct sd *sd, u16 index, u32 value, int n)
                        0, index,
                        sd->gspca_dev.usb_buf, n, 500);
        if (ret < 0) {
-               err("reg_w32 %02x failed %d", index, ret);
+               pr_err("reg_w32 %02x failed %d\n", index, ret);
                sd->gspca_dev.usb_err = ret;
        }
 }
@@ -2457,7 +2460,7 @@ static void ovfx2_i2c_w(struct sd *sd, u8 reg, u8 value)
                        (u16) value, (u16) reg, NULL, 0, 500);
 
        if (ret < 0) {
-               err("ovfx2_i2c_w %02x failed %d", reg, ret);
+               pr_err("ovfx2_i2c_w %02x failed %d\n", reg, ret);
                sd->gspca_dev.usb_err = ret;
        }
 
@@ -2481,7 +2484,7 @@ static int ovfx2_i2c_r(struct sd *sd, u8 reg)
                ret = sd->gspca_dev.usb_buf[0];
                PDEBUG(D_USBI, "ovfx2_i2c_r %02x %02x", reg, ret);
        } else {
-               err("ovfx2_i2c_r %02x failed %d", reg, ret);
+               pr_err("ovfx2_i2c_r %02x failed %d\n", reg, ret);
                sd->gspca_dev.usb_err = ret;
        }
 
@@ -2727,7 +2730,7 @@ static void ov_hires_configure(struct sd *sd)
        int high, low;
 
        if (sd->bridge != BRIDGE_OVFX2) {
-               err("error hires sensors only supported with ovfx2");
+               pr_err("error hires sensors only supported with ovfx2\n");
                return;
        }
 
@@ -2762,7 +2765,7 @@ static void ov_hires_configure(struct sd *sd)
                }
                break;
        }
-       err("Error unknown sensor type: %02x%02x", high, low);
+       pr_err("Error unknown sensor type: %02x%02x\n", high, low);
 }
 
 /* This initializes the OV8110, OV8610 sensor. The OV8110 uses
@@ -2783,7 +2786,7 @@ static void ov8xx0_configure(struct sd *sd)
        if ((rc & 3) == 1)
                sd->sensor = SEN_OV8610;
        else
-               err("Unknown image sensor version: %d", rc & 3);
+               pr_err("Unknown image sensor version: %d\n", rc & 3);
 }
 
 /* This initializes the OV7610, OV7620, or OV76BE sensor. The OV76BE uses
@@ -2840,8 +2843,8 @@ static void ov7xx0_configure(struct sd *sd)
                if (high == 0x76) {
                        switch (low) {
                        case 0x30:
-                               err("Sensor is an OV7630/OV7635");
-                               err("7630 is not supported by this driver");
+                               pr_err("Sensor is an OV7630/OV7635\n");
+                               pr_err("7630 is not supported by this driver\n");
                                return;
                        case 0x40:
                                PDEBUG(D_PROBE, "Sensor is an OV7645");
@@ -2868,7 +2871,7 @@ static void ov7xx0_configure(struct sd *sd)
                        sd->sensor = SEN_OV7620;
                }
        } else {
-               err("Unknown image sensor version: %d", rc & 3);
+               pr_err("Unknown image sensor version: %d\n", rc & 3);
        }
 }
 
@@ -2891,8 +2894,7 @@ static void ov6xx0_configure(struct sd *sd)
        switch (rc) {
        case 0x00:
                sd->sensor = SEN_OV6630;
-               warn("WARNING: Sensor is an OV66308. Your camera may have");
-               warn("been misdetected in previous driver versions.");
+               pr_warn("WARNING: Sensor is an OV66308. Your camera may have been misdetected in previous driver versions.\n");
                break;
        case 0x01:
                sd->sensor = SEN_OV6620;
@@ -2908,11 +2910,10 @@ static void ov6xx0_configure(struct sd *sd)
                break;
        case 0x90:
                sd->sensor = SEN_OV6630;
-               warn("WARNING: Sensor is an OV66307. Your camera may have");
-               warn("been misdetected in previous driver versions.");
+               pr_warn("WARNING: Sensor is an OV66307. Your camera may have been misdetected in previous driver versions.\n");
                break;
        default:
-               err("FATAL: Unknown sensor version: 0x%02x", rc);
+               pr_err("FATAL: Unknown sensor version: 0x%02x\n", rc);
                return;
        }
 
@@ -3405,7 +3406,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
        } else if (init_ov_sensor(sd, OV_HIRES_SID) >= 0) {
                ov_hires_configure(sd);
        } else {
-               err("Can't determine sensor slave IDs");
+               pr_err("Can't determine sensor slave IDs\n");
                goto error;
        }
 
@@ -3590,7 +3591,7 @@ static void ov511_mode_init_regs(struct sd *sd)
        intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
        alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
        if (!alt) {
-               err("Couldn't get altsetting");
+               pr_err("Couldn't get altsetting\n");
                sd->gspca_dev.usb_err = -EIO;
                return;
        }
@@ -3713,7 +3714,7 @@ static void ov518_mode_init_regs(struct sd *sd)
        intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
        alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
        if (!alt) {
-               err("Couldn't get altsetting");
+               pr_err("Couldn't get altsetting\n");
                sd->gspca_dev.usb_err = -EIO;
                return;
        }
index 0c6369b7fe1892e0fcae05608587e8cd4999f333..76907eced4a18cc0d4e7848361609d0b12598506 100644 (file)
@@ -28,6 +28,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "ov534"
 
 #include "gspca.h"
@@ -775,7 +777,7 @@ static void ov534_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val)
                              USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
                              0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
        if (ret < 0) {
-               err("write failed %d", ret);
+               pr_err("write failed %d\n", ret);
                gspca_dev->usb_err = ret;
        }
 }
@@ -794,7 +796,7 @@ static u8 ov534_reg_read(struct gspca_dev *gspca_dev, u16 reg)
                              0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
        PDEBUG(D_USBI, "GET 01 0000 %04x %02x", reg, gspca_dev->usb_buf[0]);
        if (ret < 0) {
-               err("read failed %d", ret);
+               pr_err("read failed %d\n", ret);
                gspca_dev->usb_err = ret;
        }
        return gspca_dev->usb_buf[0];
@@ -858,7 +860,7 @@ static void sccb_reg_write(struct gspca_dev *gspca_dev, u8 reg, u8 val)
        ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3);
 
        if (!sccb_check_status(gspca_dev)) {
-               err("sccb_reg_write failed");
+               pr_err("sccb_reg_write failed\n");
                gspca_dev->usb_err = -EIO;
        }
 }
@@ -868,11 +870,11 @@ static u8 sccb_reg_read(struct gspca_dev *gspca_dev, u16 reg)
        ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
        ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2);
        if (!sccb_check_status(gspca_dev))
-               err("sccb_reg_read failed 1");
+               pr_err("sccb_reg_read failed 1\n");
 
        ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2);
        if (!sccb_check_status(gspca_dev))
-               err("sccb_reg_read failed 2");
+               pr_err("sccb_reg_read failed 2\n");
 
        return ov534_reg_read(gspca_dev, OV534_REG_READ);
 }
index aaf5428c57f57ac4fc3e37223074ec456973ebee..b3b1ea60a8411dea0cd2a979b5ec1c9d089806f9 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * ov534-ov965x gspca driver
+ * ov534-ov9xxx gspca driver
  *
- * Copyright (C) 2009-2010 Jean-Francois Moine http://moinejf.free.fr
+ * Copyright (C) 2009-2011 Jean-Francois Moine http://moinejf.free.fr
  * Copyright (C) 2008 Antonio Ospite <ospite@studenti.unina.it>
  * Copyright (C) 2008 Jim Paris <jim@jtan.com>
  *
@@ -24,6 +24,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "ov534_9"
 
 #include "gspca.h"
@@ -45,39 +47,44 @@ MODULE_AUTHOR("Jean-Francois Moine <moinejf@free.fr>");
 MODULE_DESCRIPTION("GSPCA/OV534_9 USB Camera Driver");
 MODULE_LICENSE("GPL");
 
+/* controls */
+enum e_ctrl {
+       BRIGHTNESS,
+       CONTRAST,
+       AUTOGAIN,
+       EXPOSURE,
+       SHARPNESS,
+       SATUR,
+       LIGHTFREQ,
+       NCTRLS          /* number of controls */
+};
+
 /* specific webcam descriptor */
 struct sd {
        struct gspca_dev gspca_dev;     /* !! must be the first item */
+       struct gspca_ctrl ctrls[NCTRLS];
        __u32 last_pts;
        u8 last_fid;
 
-       u8 brightness;
-       u8 contrast;
-       u8 autogain;
-       u8 exposure;
-       s8 sharpness;
-       u8 satur;
-       u8 freq;
+       u8 sensor;
+};
+enum sensors {
+       SENSOR_OV965x,          /* ov9657 */
+       SENSOR_OV971x,          /* ov9712 */
+       NSENSORS
 };
 
 /* V4L2 controls supported by the driver */
-static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
-static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
-static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
-static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
-static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
-static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
-static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
-static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
-static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
-static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
-static int sd_setsatur(struct gspca_dev *gspca_dev, __s32 val);
-static int sd_getsatur(struct gspca_dev *gspca_dev, __s32 *val);
-static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
-static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
-
-static const struct ctrl sd_ctrls[] = {
-    {                                                  /* 0 */
+static void setbrightness(struct gspca_dev *gspca_dev);
+static void setcontrast(struct gspca_dev *gspca_dev);
+static void setautogain(struct gspca_dev *gspca_dev);
+static void setexposure(struct gspca_dev *gspca_dev);
+static void setsharpness(struct gspca_dev *gspca_dev);
+static void setsatur(struct gspca_dev *gspca_dev);
+static void setlightfreq(struct gspca_dev *gspca_dev);
+
+static const struct ctrl sd_ctrls[NCTRLS] = {
+[BRIGHTNESS] = {
        {
                .id      = V4L2_CID_BRIGHTNESS,
                .type    = V4L2_CTRL_TYPE_INTEGER,
@@ -85,13 +92,11 @@ static const struct ctrl sd_ctrls[] = {
                .minimum = 0,
                .maximum = 15,
                .step    = 1,
-#define BRIGHTNESS_DEF 7
-               .default_value = BRIGHTNESS_DEF,
+               .default_value = 7
        },
-       .set = sd_setbrightness,
-       .get = sd_getbrightness,
+       .set_control = setbrightness
     },
-    {                                                  /* 1 */
+[CONTRAST] = {
        {
                .id      = V4L2_CID_CONTRAST,
                .type    = V4L2_CTRL_TYPE_INTEGER,
@@ -99,13 +104,11 @@ static const struct ctrl sd_ctrls[] = {
                .minimum = 0,
                .maximum = 15,
                .step    = 1,
-#define CONTRAST_DEF 3
-               .default_value = CONTRAST_DEF,
+               .default_value = 3
        },
-       .set = sd_setcontrast,
-       .get = sd_getcontrast,
+       .set_control = setcontrast
     },
-    {                                                  /* 2 */
+[AUTOGAIN] = {
        {
                .id      = V4L2_CID_AUTOGAIN,
                .type    = V4L2_CTRL_TYPE_BOOLEAN,
@@ -116,11 +119,9 @@ static const struct ctrl sd_ctrls[] = {
 #define AUTOGAIN_DEF 1
                .default_value = AUTOGAIN_DEF,
        },
-       .set = sd_setautogain,
-       .get = sd_getautogain,
+       .set_control = setautogain
     },
-#define EXPO_IDX 3
-    {                                                  /* 3 */
+[EXPOSURE] = {
        {
                .id      = V4L2_CID_EXPOSURE,
                .type    = V4L2_CTRL_TYPE_INTEGER,
@@ -128,13 +129,11 @@ static const struct ctrl sd_ctrls[] = {
                .minimum = 0,
                .maximum = 3,
                .step    = 1,
-#define EXPO_DEF 0
-               .default_value = EXPO_DEF,
+               .default_value = 0
        },
-       .set = sd_setexposure,
-       .get = sd_getexposure,
+       .set_control = setexposure
     },
-    {                                                  /* 4 */
+[SHARPNESS] = {
        {
                .id      = V4L2_CID_SHARPNESS,
                .type    = V4L2_CTRL_TYPE_INTEGER,
@@ -142,13 +141,11 @@ static const struct ctrl sd_ctrls[] = {
                .minimum = -1,          /* -1 = auto */
                .maximum = 4,
                .step    = 1,
-#define SHARPNESS_DEF -1
-               .default_value = SHARPNESS_DEF,
+               .default_value = -1
        },
-       .set = sd_setsharpness,
-       .get = sd_getsharpness,
+       .set_control = setsharpness
     },
-    {                                                  /* 5 */
+[SATUR] = {
        {
                .id      = V4L2_CID_SATURATION,
                .type    = V4L2_CTRL_TYPE_INTEGER,
@@ -156,13 +153,11 @@ static const struct ctrl sd_ctrls[] = {
                .minimum = 0,
                .maximum = 4,
                .step    = 1,
-#define SATUR_DEF 2
-               .default_value = SATUR_DEF,
+               .default_value = 2
        },
-       .set = sd_setsatur,
-       .get = sd_getsatur,
+       .set_control = setsatur
     },
-    {
+[LIGHTFREQ] = {
        {
                .id      = V4L2_CID_POWER_LINE_FREQUENCY,
                .type    = V4L2_CTRL_TYPE_MENU,
@@ -170,11 +165,9 @@ static const struct ctrl sd_ctrls[] = {
                .minimum = 0,
                .maximum = 2,   /* 0: 0, 1: 50Hz, 2:60Hz */
                .step    = 1,
-#define FREQ_DEF 0
-               .default_value = FREQ_DEF,
+               .default_value = 0
        },
-       .set = sd_setfreq,
-       .get = sd_getfreq,
+       .set_control = setlightfreq
     },
 };
 
@@ -206,6 +199,14 @@ static const struct v4l2_pix_format ov965x_mode[] = {
                .colorspace = V4L2_COLORSPACE_JPEG},
 };
 
+static const struct v4l2_pix_format ov971x_mode[] = {
+       {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
+               .bytesperline = 640,
+               .sizeimage = 640 * 480,
+               .colorspace = V4L2_COLORSPACE_SRGB
+       }
+};
+
 static const u8 bridge_init[][2] = {
        {0x88, 0xf8},
        {0x89, 0xff},
@@ -240,7 +241,7 @@ static const u8 bridge_init[][2] = {
        {0x94, 0x11},
 };
 
-static const u8 sensor_init[][2] = {
+static const u8 ov965x_init[][2] = {
        {0x12, 0x80},   /* com7 - SSCB reset */
        {0x00, 0x00},   /* gain */
        {0x01, 0x80},   /* blue */
@@ -450,7 +451,7 @@ static const u8 bridge_init_2[][2] = {
        {0x94, 0x11},
 };
 
-static const u8 sensor_init_2[][2] = {
+static const u8 ov965x_init_2[][2] = {
        {0x3b, 0xc4},
        {0x1e, 0x04},   /* mvfp */
        {0x13, 0xe0},   /* com8 */
@@ -492,7 +493,65 @@ static const u8 sensor_init_2[][2] = {
        {0x13, 0xe7},   /* com8 - everything (AGC, AWB and AEC) */
 };
 
-static const u8 sensor_start_1_vga[][2] = {    /* same for qvga */
+static const u8 ov971x_init[][2] = {
+       {0x12, 0x80},
+       {0x09, 0x10},
+       {0x1e, 0x07},
+       {0x5f, 0x18},
+       {0x69, 0x04},
+       {0x65, 0x2a},
+       {0x68, 0x0a},
+       {0x39, 0x28},
+       {0x4d, 0x90},
+       {0xc1, 0x80},
+       {0x0c, 0x30},
+       {0x6d, 0x02},
+       {0x96, 0xf1},
+       {0xbc, 0x68},
+       {0x12, 0x00},
+       {0x3b, 0x00},
+       {0x97, 0x80},
+       {0x17, 0x25},
+       {0x18, 0xa2},
+       {0x19, 0x01},
+       {0x1a, 0xca},
+       {0x03, 0x0a},
+       {0x32, 0x07},
+       {0x98, 0x40},   /*{0x98, 0x00},*/
+       {0x99, 0xA0},   /*{0x99, 0x00},*/
+       {0x9a, 0x01},   /*{0x9a, 0x00},*/
+       {0x57, 0x00},
+       {0x58, 0x78},   /*{0x58, 0xc8},*/
+       {0x59, 0x50},   /*{0x59, 0xa0},*/
+       {0x4c, 0x13},
+       {0x4b, 0x36},
+       {0x3d, 0x3c},
+       {0x3e, 0x03},
+       {0xbd, 0x50},   /*{0xbd, 0xa0},*/
+       {0xbe, 0x78},   /*{0xbe, 0xc8},*/
+       {0x4e, 0x55},
+       {0x4f, 0x55},
+       {0x50, 0x55},
+       {0x51, 0x55},
+       {0x24, 0x55},
+       {0x25, 0x40},
+       {0x26, 0xa1},
+       {0x5c, 0x59},
+       {0x5d, 0x00},
+       {0x11, 0x00},
+       {0x2a, 0x98},
+       {0x2b, 0x06},
+       {0x2d, 0x00},
+       {0x2e, 0x00},
+       {0x13, 0xa5},
+       {0x14, 0x40},
+       {0x4a, 0x00},
+       {0x49, 0xce},
+       {0x22, 0x03},
+       {0x09, 0x00}
+};
+
+static const u8 ov965x_start_1_vga[][2] = {    /* same for qvga */
        {0x12, 0x62},   /* com7 - 30fps VGA YUV */
        {0x36, 0xfa},   /* aref3 */
        {0x69, 0x0a},   /* hv */
@@ -515,7 +574,7 @@ static const u8 sensor_start_1_vga[][2] = { /* same for qvga */
        {0xc0, 0xaa},
 };
 
-static const u8 sensor_start_1_svga[][2] = {
+static const u8 ov965x_start_1_svga[][2] = {
        {0x12, 0x02},   /* com7 - YUYV - VGA 15 full resolution */
        {0x36, 0xf8},   /* aref3 */
        {0x69, 0x02},   /* hv */
@@ -537,7 +596,7 @@ static const u8 sensor_start_1_svga[][2] = {
        {0xc0, 0xe2},
 };
 
-static const u8 sensor_start_1_xga[][2] = {
+static const u8 ov965x_start_1_xga[][2] = {
        {0x12, 0x02},   /* com7 */
        {0x36, 0xf8},   /* aref3 */
        {0x69, 0x02},   /* hv */
@@ -560,7 +619,7 @@ static const u8 sensor_start_1_xga[][2] = {
        {0xc0, 0xe2},
 };
 
-static const u8 sensor_start_1_sxga[][2] = {
+static const u8 ov965x_start_1_sxga[][2] = {
        {0x12, 0x02},   /* com7 */
        {0x36, 0xf8},   /* aref3 */
        {0x69, 0x02},   /* hv */
@@ -709,7 +768,7 @@ static const u8 bridge_start_sxga[][2] = {
        {0x94, 0x11},
 };
 
-static const u8 sensor_start_2_qvga[][2] = {
+static const u8 ov965x_start_2_qvga[][2] = {
        {0x3b, 0xe4},   /* com11 - night mode 1/4 frame rate */
        {0x1e, 0x04},   /* mvfp */
        {0x13, 0xe0},   /* com8 */
@@ -727,7 +786,7 @@ static const u8 sensor_start_2_qvga[][2] = {
        {0x3a, 0x80},   /* tslb - yuyv */
 };
 
-static const u8 sensor_start_2_vga[][2] = {
+static const u8 ov965x_start_2_vga[][2] = {
        {0x3b, 0xc4},   /* com11 - night mode 1/4 frame rate */
        {0x1e, 0x04},   /* mvfp */
        {0x13, 0xe0},   /* com8 */
@@ -743,7 +802,7 @@ static const u8 sensor_start_2_vga[][2] = {
        {0x2d, 0x00},   /* advfl */
 };
 
-static const u8 sensor_start_2_svga[][2] = {   /* same for xga */
+static const u8 ov965x_start_2_svga[][2] = {   /* same for xga */
        {0x3b, 0xc4},   /* com11 - night mode 1/4 frame rate */
        {0x1e, 0x04},   /* mvfp */
        {0x13, 0xe0},   /* com8 */
@@ -757,7 +816,7 @@ static const u8 sensor_start_2_svga[][2] = {        /* same for xga */
        {0xa3, 0x41},   /* bd60 */
 };
 
-static const u8 sensor_start_2_sxga[][2] = {
+static const u8 ov965x_start_2_sxga[][2] = {
        {0x13, 0xe0},   /* com8 */
        {0x00, 0x00},
        {0x13, 0xe7},   /* com8 - everything (AGC, AWB and AEC) */
@@ -785,7 +844,7 @@ static void reg_w_i(struct gspca_dev *gspca_dev, u16 reg, u8 val)
                              USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
                              0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
        if (ret < 0) {
-               err("reg_w failed %d", ret);
+               pr_err("reg_w failed %d\n", ret);
                gspca_dev->usb_err = ret;
        }
 }
@@ -810,7 +869,7 @@ static u8 reg_r(struct gspca_dev *gspca_dev, u16 reg)
                              0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
        PDEBUG(D_USBI, "reg_r [%04x] -> %02x", reg, gspca_dev->usb_buf[0]);
        if (ret < 0) {
-               err("reg_r err %d", ret);
+               pr_err("reg_r err %d\n", ret);
                gspca_dev->usb_err = ret;
        }
        return gspca_dev->usb_buf[0];
@@ -848,7 +907,7 @@ static void sccb_write(struct gspca_dev *gspca_dev, u8 reg, u8 val)
        reg_w_i(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3);
 
        if (!sccb_check_status(gspca_dev))
-               err("sccb_write failed");
+               pr_err("sccb_write failed\n");
 }
 
 static u8 sccb_read(struct gspca_dev *gspca_dev, u16 reg)
@@ -856,11 +915,11 @@ static u8 sccb_read(struct gspca_dev *gspca_dev, u16 reg)
        reg_w(gspca_dev, OV534_REG_SUBADDR, reg);
        reg_w(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2);
        if (!sccb_check_status(gspca_dev))
-               err("sccb_read failed 1");
+               pr_err("sccb_read failed 1\n");
 
        reg_w(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2);
        if (!sccb_check_status(gspca_dev))
-               err("sccb_read failed 2");
+               pr_err("sccb_read failed 2\n");
 
        return reg_r(gspca_dev, OV534_REG_READ);
 }
@@ -922,7 +981,9 @@ static void setbrightness(struct gspca_dev *gspca_dev)
        struct sd *sd = (struct sd *) gspca_dev;
        u8 val;
 
-       val = sd->brightness;
+       if (gspca_dev->ctrl_dis & (1 << BRIGHTNESS))
+               return;
+       val = sd->ctrls[BRIGHTNESS].val;
        if (val < 8)
                val = 15 - val;         /* f .. 8 */
        else
@@ -935,8 +996,10 @@ static void setcontrast(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
 
+       if (gspca_dev->ctrl_dis & (1 << CONTRAST))
+               return;
        sccb_write(gspca_dev, 0x56,     /* cnst1 - contrast 1 ctrl coeff */
-                       sd->contrast << 4);
+                       sd->ctrls[CONTRAST].val << 4);
 }
 
 static void setautogain(struct gspca_dev *gspca_dev)
@@ -944,10 +1007,12 @@ static void setautogain(struct gspca_dev *gspca_dev)
        struct sd *sd = (struct sd *) gspca_dev;
        u8 val;
 
+       if (gspca_dev->ctrl_dis & (1 << AUTOGAIN))
+               return;
 /*fixme: should adjust agc/awb/aec by different controls */
        val = sccb_read(gspca_dev, 0x13);               /* com8 */
        sccb_write(gspca_dev, 0xff, 0x00);
-       if (sd->autogain)
+       if (sd->ctrls[AUTOGAIN].val)
                val |= 0x05;            /* agc & aec */
        else
                val &= 0xfa;
@@ -960,8 +1025,10 @@ static void setexposure(struct gspca_dev *gspca_dev)
        u8 val;
        static const u8 expo[4] = {0x00, 0x25, 0x38, 0x5e};
 
+       if (gspca_dev->ctrl_dis & (1 << EXPOSURE))
+               return;
        sccb_write(gspca_dev, 0x10,                     /* aec[9:2] */
-                       expo[sd->exposure]);
+                       expo[sd->ctrls[EXPOSURE].val]);
 
        val = sccb_read(gspca_dev, 0x13);               /* com8 */
        sccb_write(gspca_dev, 0xff, 0x00);
@@ -977,7 +1044,9 @@ static void setsharpness(struct gspca_dev *gspca_dev)
        struct sd *sd = (struct sd *) gspca_dev;
        s8 val;
 
-       val = sd->sharpness;
+       if (gspca_dev->ctrl_dis & (1 << SHARPNESS))
+               return;
+       val = sd->ctrls[SHARPNESS].val;
        if (val < 0) {                          /* auto */
                val = sccb_read(gspca_dev, 0x42);       /* com17 */
                sccb_write(gspca_dev, 0xff, 0x00);
@@ -1006,8 +1075,10 @@ static void setsatur(struct gspca_dev *gspca_dev)
                {0x48, 0x90}
        };
 
-       val1 = matrix[sd->satur][0];
-       val2 = matrix[sd->satur][1];
+       if (gspca_dev->ctrl_dis & (1 << SATUR))
+               return;
+       val1 = matrix[sd->ctrls[SATUR].val][0];
+       val2 = matrix[sd->ctrls[SATUR].val][1];
        val3 = val1 + val2;
        sccb_write(gspca_dev, 0x4f, val3);      /* matrix coeff */
        sccb_write(gspca_dev, 0x50, val3);
@@ -1022,14 +1093,16 @@ static void setsatur(struct gspca_dev *gspca_dev)
        sccb_write(gspca_dev, 0x41, val1);
 }
 
-static void setfreq(struct gspca_dev *gspca_dev)
+static void setlightfreq(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
        u8 val;
 
+       if (gspca_dev->ctrl_dis & (1 << LIGHTFREQ))
+               return;
        val = sccb_read(gspca_dev, 0x13);               /* com8 */
        sccb_write(gspca_dev, 0xff, 0x00);
-       if (sd->freq == 0) {
+       if (sd->ctrls[LIGHTFREQ].val == 0) {
                sccb_write(gspca_dev, 0x13, val & 0xdf);
                return;
        }
@@ -1037,7 +1110,7 @@ static void setfreq(struct gspca_dev *gspca_dev)
 
        val = sccb_read(gspca_dev, 0x42);               /* com17 */
        sccb_write(gspca_dev, 0xff, 0x00);
-       if (sd->freq == 1)
+       if (sd->ctrls[LIGHTFREQ].val == 1)
                val |= 0x01;
        else
                val &= 0xfe;
@@ -1049,34 +1122,19 @@ static int sd_config(struct gspca_dev *gspca_dev,
                     const struct usb_device_id *id)
 {
        struct sd *sd = (struct sd *) gspca_dev;
-       struct cam *cam;
-
-       cam = &gspca_dev->cam;
 
-       cam->cam_mode = ov965x_mode;
-       cam->nmodes = ARRAY_SIZE(ov965x_mode);
+       gspca_dev->cam.ctrls = sd->ctrls;
 
-       sd->brightness = BRIGHTNESS_DEF;
-       sd->contrast = CONTRAST_DEF;
 #if AUTOGAIN_DEF != 0
-       sd->autogain = AUTOGAIN_DEF;
-       gspca_dev->ctrl_inac |= (1 << EXPO_IDX);
-#endif
-#if EXPO_DEF != 0
-       sd->exposure = EXPO_DEF;
-#endif
-#if SHARPNESS_DEF != 0
-       sd->sharpness = SHARPNESS_DEF;
+       gspca_dev->ctrl_inac |= (1 << EXPOSURE);
 #endif
-       sd->satur = SATUR_DEF;
-       sd->freq = FREQ_DEF;
-
        return 0;
 }
 
 /* this function is called at probe and resume time */
 static int sd_init(struct gspca_dev *gspca_dev)
 {
+       struct sd *sd = (struct sd *) gspca_dev;
        u16 sensor_id;
 
        /* reset bridge */
@@ -1099,68 +1157,117 @@ static int sd_init(struct gspca_dev *gspca_dev)
        PDEBUG(D_PROBE, "Sensor ID: %04x", sensor_id);
 
        /* initialize */
-       reg_w_array(gspca_dev, bridge_init,
-                       ARRAY_SIZE(bridge_init));
-       sccb_w_array(gspca_dev, sensor_init,
-                       ARRAY_SIZE(sensor_init));
-       reg_w_array(gspca_dev, bridge_init_2,
-                       ARRAY_SIZE(bridge_init_2));
-       sccb_w_array(gspca_dev, sensor_init_2,
-                       ARRAY_SIZE(sensor_init_2));
-       reg_w(gspca_dev, 0xe0, 0x00);
-       reg_w(gspca_dev, 0xe0, 0x01);
-       set_led(gspca_dev, 0);
-       reg_w(gspca_dev, 0xe0, 0x00);
+       if ((sensor_id & 0xfff0) == 0x9650) {
+               sd->sensor = SENSOR_OV965x;
+
+               gspca_dev->cam.cam_mode = ov965x_mode;
+               gspca_dev->cam.nmodes = ARRAY_SIZE(ov965x_mode);
+
+               reg_w_array(gspca_dev, bridge_init,
+                               ARRAY_SIZE(bridge_init));
+               sccb_w_array(gspca_dev, ov965x_init,
+                               ARRAY_SIZE(ov965x_init));
+               reg_w_array(gspca_dev, bridge_init_2,
+                               ARRAY_SIZE(bridge_init_2));
+               sccb_w_array(gspca_dev, ov965x_init_2,
+                               ARRAY_SIZE(ov965x_init_2));
+               reg_w(gspca_dev, 0xe0, 0x00);
+               reg_w(gspca_dev, 0xe0, 0x01);
+               set_led(gspca_dev, 0);
+               reg_w(gspca_dev, 0xe0, 0x00);
+       } else if ((sensor_id & 0xfff0) == 0x9710) {
+               const char *p;
+               int l;
+
+               sd->sensor = SENSOR_OV971x;
+
+               gspca_dev->cam.cam_mode = ov971x_mode;
+               gspca_dev->cam.nmodes = ARRAY_SIZE(ov971x_mode);
+
+               /* no control yet */
+               gspca_dev->ctrl_dis = (1 << NCTRLS) - 1;
+
+               gspca_dev->cam.bulk = 1;
+               gspca_dev->cam.bulk_size = 16384;
+               gspca_dev->cam.bulk_nurbs = 2;
+
+               sccb_w_array(gspca_dev, ov971x_init,
+                               ARRAY_SIZE(ov971x_init));
+
+               /* set video format on bridge processor */
+               /* access bridge processor's video format registers at: 0x00 */
+               reg_w(gspca_dev, 0x1c, 0x00);
+               /*set register: 0x00 is 'RAW8', 0x40 is 'YUV422' (YUYV?)*/
+               reg_w(gspca_dev, 0x1d, 0x00);
+
+               /* Will W. specific stuff
+                * set VSYNC to
+                *      output (0x1f) if first webcam
+                *      input (0x17) if 2nd or 3rd webcam */
+               p = video_device_node_name(&gspca_dev->vdev);
+               l = strlen(p) - 1;
+               if (p[l] == '0')
+                       reg_w(gspca_dev, 0x56, 0x1f);
+               else
+                       reg_w(gspca_dev, 0x56, 0x17);
+       } else {
+               err("Unknown sensor %04x", sensor_id);
+               return -EINVAL;
+       }
 
        return gspca_dev->usb_err;
 }
 
 static int sd_start(struct gspca_dev *gspca_dev)
 {
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       if (sd->sensor == SENSOR_OV971x)
+               return gspca_dev->usb_err;
        switch (gspca_dev->curr_mode) {
        case QVGA_MODE:                 /* 320x240 */
-               sccb_w_array(gspca_dev, sensor_start_1_vga,
-                               ARRAY_SIZE(sensor_start_1_vga));
+               sccb_w_array(gspca_dev, ov965x_start_1_vga,
+                               ARRAY_SIZE(ov965x_start_1_vga));
                reg_w_array(gspca_dev, bridge_start_qvga,
                                ARRAY_SIZE(bridge_start_qvga));
-               sccb_w_array(gspca_dev, sensor_start_2_qvga,
-                               ARRAY_SIZE(sensor_start_2_qvga));
+               sccb_w_array(gspca_dev, ov965x_start_2_qvga,
+                               ARRAY_SIZE(ov965x_start_2_qvga));
                break;
        case VGA_MODE:                  /* 640x480 */
-               sccb_w_array(gspca_dev, sensor_start_1_vga,
-                               ARRAY_SIZE(sensor_start_1_vga));
+               sccb_w_array(gspca_dev, ov965x_start_1_vga,
+                               ARRAY_SIZE(ov965x_start_1_vga));
                reg_w_array(gspca_dev, bridge_start_vga,
                                ARRAY_SIZE(bridge_start_vga));
-               sccb_w_array(gspca_dev, sensor_start_2_vga,
-                               ARRAY_SIZE(sensor_start_2_vga));
+               sccb_w_array(gspca_dev, ov965x_start_2_vga,
+                               ARRAY_SIZE(ov965x_start_2_vga));
                break;
        case SVGA_MODE:                 /* 800x600 */
-               sccb_w_array(gspca_dev, sensor_start_1_svga,
-                               ARRAY_SIZE(sensor_start_1_svga));
+               sccb_w_array(gspca_dev, ov965x_start_1_svga,
+                               ARRAY_SIZE(ov965x_start_1_svga));
                reg_w_array(gspca_dev, bridge_start_svga,
                                ARRAY_SIZE(bridge_start_svga));
-               sccb_w_array(gspca_dev, sensor_start_2_svga,
-                               ARRAY_SIZE(sensor_start_2_svga));
+               sccb_w_array(gspca_dev, ov965x_start_2_svga,
+                               ARRAY_SIZE(ov965x_start_2_svga));
                break;
        case XGA_MODE:                  /* 1024x768 */
-               sccb_w_array(gspca_dev, sensor_start_1_xga,
-                               ARRAY_SIZE(sensor_start_1_xga));
+               sccb_w_array(gspca_dev, ov965x_start_1_xga,
+                               ARRAY_SIZE(ov965x_start_1_xga));
                reg_w_array(gspca_dev, bridge_start_xga,
                                ARRAY_SIZE(bridge_start_xga));
-               sccb_w_array(gspca_dev, sensor_start_2_svga,
-                               ARRAY_SIZE(sensor_start_2_svga));
+               sccb_w_array(gspca_dev, ov965x_start_2_svga,
+                               ARRAY_SIZE(ov965x_start_2_svga));
                break;
        default:
 /*     case SXGA_MODE:                  * 1280x1024 */
-               sccb_w_array(gspca_dev, sensor_start_1_sxga,
-                               ARRAY_SIZE(sensor_start_1_sxga));
+               sccb_w_array(gspca_dev, ov965x_start_1_sxga,
+                               ARRAY_SIZE(ov965x_start_1_sxga));
                reg_w_array(gspca_dev, bridge_start_sxga,
                                ARRAY_SIZE(bridge_start_sxga));
-               sccb_w_array(gspca_dev, sensor_start_2_sxga,
-                               ARRAY_SIZE(sensor_start_2_sxga));
+               sccb_w_array(gspca_dev, ov965x_start_2_sxga,
+                               ARRAY_SIZE(ov965x_start_2_sxga));
                break;
        }
-       setfreq(gspca_dev);
+       setlightfreq(gspca_dev);
        setautogain(gspca_dev);
        setbrightness(gspca_dev);
        setcontrast(gspca_dev);
@@ -1198,9 +1305,11 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
        __u32 this_pts;
        u8 this_fid;
        int remaining_len = len;
+       int payload_len;
 
+       payload_len = gspca_dev->cam.bulk ? 2048 : 2040;
        do {
-               len = min(remaining_len, 2040);
+               len = min(remaining_len, payload_len);
 
                /* Payloads are prefixed with a UVC-style header.  We
                   consider a frame to start when the FID toggles, or the PTS
@@ -1262,138 +1371,6 @@ scan_next:
        } while (remaining_len > 0);
 }
 
-/* controls */
-static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
-{
-       struct sd *sd = (struct sd *) gspca_dev;
-
-       sd->brightness = val;
-       if (gspca_dev->streaming)
-               setbrightness(gspca_dev);
-       return gspca_dev->usb_err;
-}
-
-static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
-{
-       struct sd *sd = (struct sd *) gspca_dev;
-
-       *val = sd->brightness;
-       return 0;
-}
-
-static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
-{
-       struct sd *sd = (struct sd *) gspca_dev;
-
-       sd->contrast = val;
-       if (gspca_dev->streaming)
-               setcontrast(gspca_dev);
-       return gspca_dev->usb_err;
-}
-
-static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
-{
-       struct sd *sd = (struct sd *) gspca_dev;
-
-       *val = sd->contrast;
-       return 0;
-}
-
-static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
-{
-       struct sd *sd = (struct sd *) gspca_dev;
-
-       sd->autogain = val;
-
-       if (gspca_dev->streaming) {
-               if (val)
-                       gspca_dev->ctrl_inac |= (1 << EXPO_IDX);
-               else
-                       gspca_dev->ctrl_inac &= ~(1 << EXPO_IDX);
-               setautogain(gspca_dev);
-       }
-       return gspca_dev->usb_err;
-}
-
-static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
-{
-       struct sd *sd = (struct sd *) gspca_dev;
-
-       *val = sd->autogain;
-       return 0;
-}
-
-static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
-{
-       struct sd *sd = (struct sd *) gspca_dev;
-
-       sd->exposure = val;
-       if (gspca_dev->streaming)
-               setexposure(gspca_dev);
-       return gspca_dev->usb_err;
-}
-
-static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
-{
-       struct sd *sd = (struct sd *) gspca_dev;
-
-       *val = sd->exposure;
-       return 0;
-}
-
-static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
-{
-       struct sd *sd = (struct sd *) gspca_dev;
-
-       sd->sharpness = val;
-       if (gspca_dev->streaming)
-               setsharpness(gspca_dev);
-       return gspca_dev->usb_err;
-}
-
-static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
-{
-       struct sd *sd = (struct sd *) gspca_dev;
-
-       *val = sd->sharpness;
-       return 0;
-}
-
-static int sd_setsatur(struct gspca_dev *gspca_dev, __s32 val)
-{
-       struct sd *sd = (struct sd *) gspca_dev;
-
-       sd->satur = val;
-       if (gspca_dev->streaming)
-               setsatur(gspca_dev);
-       return gspca_dev->usb_err;
-}
-
-static int sd_getsatur(struct gspca_dev *gspca_dev, __s32 *val)
-{
-       struct sd *sd = (struct sd *) gspca_dev;
-
-       *val = sd->satur;
-       return 0;
-}
-static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
-{
-       struct sd *sd = (struct sd *) gspca_dev;
-
-       sd->freq = val;
-       if (gspca_dev->streaming)
-               setfreq(gspca_dev);
-       return gspca_dev->usb_err;
-}
-
-static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
-{
-       struct sd *sd = (struct sd *) gspca_dev;
-
-       *val = sd->freq;
-       return 0;
-}
-
 static int sd_querymenu(struct gspca_dev *gspca_dev,
                        struct v4l2_querymenu *menu)
 {
@@ -1419,7 +1396,7 @@ static int sd_querymenu(struct gspca_dev *gspca_dev,
 static const struct sd_desc sd_desc = {
        .name     = MODULE_NAME,
        .ctrls    = sd_ctrls,
-       .nctrls   = ARRAY_SIZE(sd_ctrls),
+       .nctrls   = NCTRLS,
        .config   = sd_config,
        .init     = sd_init,
        .start    = sd_start,
@@ -1430,6 +1407,7 @@ static const struct sd_desc sd_desc = {
 
 /* -- module initialisation -- */
 static const struct usb_device_id device_table[] = {
+       {USB_DEVICE(0x05a9, 0x8065)},
        {USB_DEVICE(0x06f8, 0x3003)},
        {}
 };
index 81739a2f205e8e020ac789c984d60a143603e3ce..1600df152fd6130976e83788f8ed2cee04f8c6f0 100644 (file)
@@ -23,6 +23,8 @@
  *
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "pac207"
 
 #include <linux/input.h>
@@ -178,8 +180,8 @@ static int pac207_write_regs(struct gspca_dev *gspca_dev, u16 index,
                        0x00, index,
                        gspca_dev->usb_buf, length, PAC207_CTRL_TIMEOUT);
        if (err < 0)
-               err("Failed to write registers to index 0x%04X, error %d)",
-                       index, err);
+               pr_err("Failed to write registers to index 0x%04X, error %d\n",
+                      index, err);
 
        return err;
 }
@@ -194,8 +196,8 @@ static int pac207_write_reg(struct gspca_dev *gspca_dev, u16 index, u16 value)
                        USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
                        value, index, NULL, 0, PAC207_CTRL_TIMEOUT);
        if (err)
-               err("Failed to write a register (index 0x%04X,"
-                       " value 0x%02X, error %d)", index, value, err);
+               pr_err("Failed to write a register (index 0x%04X, value 0x%02X, error %d)\n",
+                      index, value, err);
 
        return err;
 }
@@ -210,8 +212,8 @@ static int pac207_read_reg(struct gspca_dev *gspca_dev, u16 index)
                        0x00, index,
                        gspca_dev->usb_buf, 1, PAC207_CTRL_TIMEOUT);
        if (res < 0) {
-               err("Failed to read a register (index 0x%04X, error %d)",
-                       index, res);
+               pr_err("Failed to read a register (index 0x%04X, error %d)\n",
+                      index, res);
                return res;
        }
 
index 5615d7bd830455e8e1e269c94311601e6b4b8c16..1c44f78ff9e2cdcd55559b69da73d668904236cf 100644 (file)
@@ -61,6 +61,8 @@
     3   | 0x21       | sethvflip()
 */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "pac7302"
 
 #include <linux/input.h>
@@ -408,8 +410,8 @@ static void reg_w_buf(struct gspca_dev *gspca_dev,
                        index, gspca_dev->usb_buf, len,
                        500);
        if (ret < 0) {
-               err("reg_w_buf failed index 0x%02x, error %d",
-                       index, ret);
+               pr_err("reg_w_buf failed index 0x%02x, error %d\n",
+                      index, ret);
                gspca_dev->usb_err = ret;
        }
 }
@@ -431,8 +433,8 @@ static void reg_w(struct gspca_dev *gspca_dev,
                        0, index, gspca_dev->usb_buf, 1,
                        500);
        if (ret < 0) {
-               err("reg_w() failed index 0x%02x, value 0x%02x, error %d",
-                       index, value, ret);
+               pr_err("reg_w() failed index 0x%02x, value 0x%02x, error %d\n",
+                      index, value, ret);
                gspca_dev->usb_err = ret;
        }
 }
@@ -466,9 +468,8 @@ static void reg_w_page(struct gspca_dev *gspca_dev,
                                0, index, gspca_dev->usb_buf, 1,
                                500);
                if (ret < 0) {
-                       err("reg_w_page() failed index 0x%02x, "
-                       "value 0x%02x, error %d",
-                               index, page[index], ret);
+                       pr_err("reg_w_page() failed index 0x%02x, value 0x%02x, error %d\n",
+                              index, page[index], ret);
                        gspca_dev->usb_err = ret;
                        break;
                }
index f8801b50e64f2f20b5c5030bb76faaeafef073c8..7509d05dc065a1c4fdc959e699c6892bf460ee64 100644 (file)
@@ -49,6 +49,8 @@
                for max gain, 0x14 for minimal gain.
 */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "pac7311"
 
 #include <linux/input.h>
@@ -276,8 +278,8 @@ static void reg_w_buf(struct gspca_dev *gspca_dev,
                        index, gspca_dev->usb_buf, len,
                        500);
        if (ret < 0) {
-               err("reg_w_buf() failed index 0x%02x, error %d",
-                       index, ret);
+               pr_err("reg_w_buf() failed index 0x%02x, error %d\n",
+                      index, ret);
                gspca_dev->usb_err = ret;
        }
 }
@@ -299,8 +301,8 @@ static void reg_w(struct gspca_dev *gspca_dev,
                        0, index, gspca_dev->usb_buf, 1,
                        500);
        if (ret < 0) {
-               err("reg_w() failed index 0x%02x, value 0x%02x, error %d",
-                       index, value, ret);
+               pr_err("reg_w() failed index 0x%02x, value 0x%02x, error %d\n",
+                      index, value, ret);
                gspca_dev->usb_err = ret;
        }
 }
@@ -334,9 +336,8 @@ static void reg_w_page(struct gspca_dev *gspca_dev,
                                0, index, gspca_dev->usb_buf, 1,
                                500);
                if (ret < 0) {
-                       err("reg_w_page() failed index 0x%02x, "
-                       "value 0x%02x, error %d",
-                               index, page[index], ret);
+                       pr_err("reg_w_page() failed index 0x%02x, value 0x%02x, error %d\n",
+                              index, page[index], ret);
                        gspca_dev->usb_err = ret;
                        break;
                }
index 4c283c24c752bd7dffa26d2a67db71b6c32ba251..3b71bbcd977add2e91847ec6799bdefae4cedf80 100644 (file)
@@ -23,6 +23,8 @@
  *
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "se401"
 
 #define BULK_SIZE 4096
@@ -144,8 +146,8 @@ static void se401_write_req(struct gspca_dev *gspca_dev, u16 req, u16 value,
                              value, 0, NULL, 0, 1000);
        if (err < 0) {
                if (!silent)
-                       err("write req failed req %#04x val %#04x error %d",
-                           req, value, err);
+                       pr_err("write req failed req %#04x val %#04x error %d\n",
+                              req, value, err);
                gspca_dev->usb_err = err;
        }
 }
@@ -158,7 +160,7 @@ static void se401_read_req(struct gspca_dev *gspca_dev, u16 req, int silent)
                return;
 
        if (USB_BUF_SZ < READ_REQ_SIZE) {
-               err("USB_BUF_SZ too small!!");
+               pr_err("USB_BUF_SZ too small!!\n");
                gspca_dev->usb_err = -ENOBUFS;
                return;
        }
@@ -169,7 +171,8 @@ static void se401_read_req(struct gspca_dev *gspca_dev, u16 req, int silent)
                              0, 0, gspca_dev->usb_buf, READ_REQ_SIZE, 1000);
        if (err < 0) {
                if (!silent)
-                       err("read req failed req %#04x error %d", req, err);
+                       pr_err("read req failed req %#04x error %d\n",
+                              req, err);
                gspca_dev->usb_err = err;
        }
 }
@@ -188,8 +191,8 @@ static void se401_set_feature(struct gspca_dev *gspca_dev,
                              USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
                              param, selector, NULL, 0, 1000);
        if (err < 0) {
-               err("set feature failed sel %#04x param %#04x error %d",
-                   selector, param, err);
+               pr_err("set feature failed sel %#04x param %#04x error %d\n",
+                      selector, param, err);
                gspca_dev->usb_err = err;
        }
 }
@@ -202,7 +205,7 @@ static int se401_get_feature(struct gspca_dev *gspca_dev, u16 selector)
                return gspca_dev->usb_err;
 
        if (USB_BUF_SZ < 2) {
-               err("USB_BUF_SZ too small!!");
+               pr_err("USB_BUF_SZ too small!!\n");
                gspca_dev->usb_err = -ENOBUFS;
                return gspca_dev->usb_err;
        }
@@ -213,7 +216,8 @@ static int se401_get_feature(struct gspca_dev *gspca_dev, u16 selector)
                              USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
                              0, selector, gspca_dev->usb_buf, 2, 1000);
        if (err < 0) {
-               err("get feature failed sel %#04x error %d", selector, err);
+               pr_err("get feature failed sel %#04x error %d\n",
+                      selector, err);
                gspca_dev->usb_err = err;
                return err;
        }
@@ -300,21 +304,21 @@ static int sd_config(struct gspca_dev *gspca_dev,
                return gspca_dev->usb_err;
 
        if (cd[1] != 0x41) {
-               err("Wrong descriptor type");
+               pr_err("Wrong descriptor type\n");
                return -ENODEV;
        }
 
        if (!(cd[2] & SE401_FORMAT_BAYER)) {
-               err("Bayer format not supported!");
+               pr_err("Bayer format not supported!\n");
                return -ENODEV;
        }
 
        if (cd[3])
-               info("ExtraFeatures: %d", cd[3]);
+               pr_info("ExtraFeatures: %d\n", cd[3]);
 
        n = cd[4] | (cd[5] << 8);
        if (n > MAX_MODES) {
-               err("Too many frame sizes");
+               pr_err("Too many frame sizes\n");
                return -ENODEV;
        }
 
@@ -353,15 +357,16 @@ static int sd_config(struct gspca_dev *gspca_dev,
                        sd->fmts[i].pixelformat = V4L2_PIX_FMT_SBGGR8;
                        sd->fmts[i].bytesperline = widths[i];
                        sd->fmts[i].sizeimage = widths[i] * heights[i];
-                       info("Frame size: %dx%d bayer", widths[i], heights[i]);
+                       pr_info("Frame size: %dx%d bayer\n",
+                               widths[i], heights[i]);
                } else {
                        /* Found a match use janggu compression */
                        sd->fmts[i].pixelformat = V4L2_PIX_FMT_SE401;
                        sd->fmts[i].bytesperline = 0;
                        sd->fmts[i].sizeimage = widths[i] * heights[i] * 3;
-                       info("Frame size: %dx%d 1/%dth janggu",
-                            widths[i], heights[i],
-                            sd->fmts[i].priv * sd->fmts[i].priv);
+                       pr_info("Frame size: %dx%d 1/%dth janggu\n",
+                               widths[i], heights[i],
+                               sd->fmts[i].priv * sd->fmts[i].priv);
                }
        }
 
@@ -571,11 +576,12 @@ static void sd_pkt_scan_janggu(struct gspca_dev *gspca_dev, u8 *data, int len)
                plen   = ((bits + 47) >> 4) << 1;
                /* Sanity checks */
                if (plen > 1024) {
-                       err("invalid packet len %d restarting stream", plen);
+                       pr_err("invalid packet len %d restarting stream\n",
+                              plen);
                        goto error;
                }
                if (info == 3) {
-                       err("unknown frame info value restarting stream");
+                       pr_err("unknown frame info value restarting stream\n");
                        goto error;
                }
 
@@ -599,8 +605,8 @@ static void sd_pkt_scan_janggu(struct gspca_dev *gspca_dev, u8 *data, int len)
                        break;
                case 1: /* EOF */
                        if (sd->pixels_read != imagesize) {
-                               err("frame size %d expected %d",
-                                   sd->pixels_read, imagesize);
+                               pr_err("frame size %d expected %d\n",
+                                      sd->pixels_read, imagesize);
                                goto error;
                        }
                        sd_complete_frame(gspca_dev, sd->packet, plen);
index 4271f86dfe015eab27bc91bec6d4149b25e175bd..48aae3926a33e8e65aaf6547d893d74df6affe20 100644 (file)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "sn9c2028"
 
 #include "gspca.h"
@@ -75,8 +77,8 @@ static int sn9c2028_command(struct gspca_dev *gspca_dev, u8 *command)
                        USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
                        2, 0, gspca_dev->usb_buf, 6, 500);
        if (rc < 0) {
-               err("command write [%02x] error %d",
-                               gspca_dev->usb_buf[0], rc);
+               pr_err("command write [%02x] error %d\n",
+                      gspca_dev->usb_buf[0], rc);
                return rc;
        }
 
@@ -93,7 +95,7 @@ static int sn9c2028_read1(struct gspca_dev *gspca_dev)
                        USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
                        1, 0, gspca_dev->usb_buf, 1, 500);
        if (rc != 1) {
-               err("read1 error %d", rc);
+               pr_err("read1 error %d\n", rc);
                return (rc < 0) ? rc : -EIO;
        }
        PDEBUG(D_USBI, "read1 response %02x", gspca_dev->usb_buf[0]);
@@ -109,7 +111,7 @@ static int sn9c2028_read4(struct gspca_dev *gspca_dev, u8 *reading)
                        USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
                        4, 0, gspca_dev->usb_buf, 4, 500);
        if (rc != 4) {
-               err("read4 error %d", rc);
+               pr_err("read4 error %d\n", rc);
                return (rc < 0) ? rc : -EIO;
        }
        memcpy(reading, gspca_dev->usb_buf, 4);
@@ -131,7 +133,7 @@ static int sn9c2028_long_command(struct gspca_dev *gspca_dev, u8 *command)
        for (i = 0; i < 256 && status < 2; i++)
                status = sn9c2028_read1(gspca_dev);
        if (status != 2) {
-               err("long command status read error %d", status);
+               pr_err("long command status read error %d\n", status);
                return (status < 0) ? status : -EIO;
        }
 
@@ -638,7 +640,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
                err_code = start_vivitar_cam(gspca_dev);
                break;
        default:
-               err("Starting unknown camera, please report this");
+               pr_err("Starting unknown camera, please report this\n");
                return -ENXIO;
        }
 
index c431900cd292a11f690808e2718c953dff6324e2..86e07a139a16e2867970baca2d217e42f89e99eb 100644 (file)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/input.h>
 
 #include "gspca.h"
@@ -1123,7 +1125,7 @@ static int reg_r(struct gspca_dev *gspca_dev, u16 reg, u16 length)
                        length,
                        500);
        if (unlikely(result < 0 || result != length)) {
-               err("Read register failed 0x%02X", reg);
+               pr_err("Read register failed 0x%02X\n", reg);
                return -EIO;
        }
        return 0;
@@ -1144,7 +1146,7 @@ static int reg_w(struct gspca_dev *gspca_dev, u16 reg,
                        length,
                        500);
        if (unlikely(result < 0 || result != length)) {
-               err("Write register failed index 0x%02X", reg);
+               pr_err("Write register failed index 0x%02X\n", reg);
                return -EIO;
        }
        return 0;
@@ -1275,14 +1277,14 @@ static int ov9650_init_sensor(struct gspca_dev *gspca_dev)
                return -EINVAL;
 
        if (id != 0x7fa2) {
-               err("sensor id for ov9650 doesn't match (0x%04x)", id);
+               pr_err("sensor id for ov9650 doesn't match (0x%04x)\n", id);
                return -ENODEV;
        }
 
        for (i = 0; i < ARRAY_SIZE(ov9650_init); i++) {
                if (i2c_w1(gspca_dev, ov9650_init[i].reg,
                                ov9650_init[i].val) < 0) {
-                       err("OV9650 sensor initialization failed");
+                       pr_err("OV9650 sensor initialization failed\n");
                        return -ENODEV;
                }
        }
@@ -1299,7 +1301,7 @@ static int ov9655_init_sensor(struct gspca_dev *gspca_dev)
        for (i = 0; i < ARRAY_SIZE(ov9655_init); i++) {
                if (i2c_w1(gspca_dev, ov9655_init[i].reg,
                                ov9655_init[i].val) < 0) {
-                       err("OV9655 sensor initialization failed");
+                       pr_err("OV9655 sensor initialization failed\n");
                        return -ENODEV;
                }
        }
@@ -1318,7 +1320,7 @@ static int soi968_init_sensor(struct gspca_dev *gspca_dev)
        for (i = 0; i < ARRAY_SIZE(soi968_init); i++) {
                if (i2c_w1(gspca_dev, soi968_init[i].reg,
                                soi968_init[i].val) < 0) {
-                       err("SOI968 sensor initialization failed");
+                       pr_err("SOI968 sensor initialization failed\n");
                        return -ENODEV;
                }
        }
@@ -1338,7 +1340,7 @@ static int ov7660_init_sensor(struct gspca_dev *gspca_dev)
        for (i = 0; i < ARRAY_SIZE(ov7660_init); i++) {
                if (i2c_w1(gspca_dev, ov7660_init[i].reg,
                                ov7660_init[i].val) < 0) {
-                       err("OV7660 sensor initialization failed");
+                       pr_err("OV7660 sensor initialization failed\n");
                        return -ENODEV;
                }
        }
@@ -1355,7 +1357,7 @@ static int ov7670_init_sensor(struct gspca_dev *gspca_dev)
        for (i = 0; i < ARRAY_SIZE(ov7670_init); i++) {
                if (i2c_w1(gspca_dev, ov7670_init[i].reg,
                                ov7670_init[i].val) < 0) {
-                       err("OV7670 sensor initialization failed");
+                       pr_err("OV7670 sensor initialization failed\n");
                        return -ENODEV;
                }
        }
@@ -1379,14 +1381,14 @@ static int mt9v_init_sensor(struct gspca_dev *gspca_dev)
                for (i = 0; i < ARRAY_SIZE(mt9v011_init); i++) {
                        if (i2c_w2(gspca_dev, mt9v011_init[i].reg,
                                        mt9v011_init[i].val) < 0) {
-                               err("MT9V011 sensor initialization failed");
+                               pr_err("MT9V011 sensor initialization failed\n");
                                return -ENODEV;
                        }
                }
                sd->hstart = 2;
                sd->vstart = 2;
                sd->sensor = SENSOR_MT9V011;
-               info("MT9V011 sensor detected");
+               pr_info("MT9V011 sensor detected\n");
                return 0;
        }
 
@@ -1397,7 +1399,7 @@ static int mt9v_init_sensor(struct gspca_dev *gspca_dev)
                for (i = 0; i < ARRAY_SIZE(mt9v111_init); i++) {
                        if (i2c_w2(gspca_dev, mt9v111_init[i].reg,
                                        mt9v111_init[i].val) < 0) {
-                               err("MT9V111 sensor initialization failed");
+                               pr_err("MT9V111 sensor initialization failed\n");
                                return -ENODEV;
                        }
                }
@@ -1407,7 +1409,7 @@ static int mt9v_init_sensor(struct gspca_dev *gspca_dev)
                sd->hstart = 2;
                sd->vstart = 2;
                sd->sensor = SENSOR_MT9V111;
-               info("MT9V111 sensor detected");
+               pr_info("MT9V111 sensor detected\n");
                return 0;
        }
 
@@ -1422,14 +1424,14 @@ static int mt9v_init_sensor(struct gspca_dev *gspca_dev)
                for (i = 0; i < ARRAY_SIZE(mt9v112_init); i++) {
                        if (i2c_w2(gspca_dev, mt9v112_init[i].reg,
                                        mt9v112_init[i].val) < 0) {
-                               err("MT9V112 sensor initialization failed");
+                               pr_err("MT9V112 sensor initialization failed\n");
                                return -ENODEV;
                        }
                }
                sd->hstart = 6;
                sd->vstart = 2;
                sd->sensor = SENSOR_MT9V112;
-               info("MT9V112 sensor detected");
+               pr_info("MT9V112 sensor detected\n");
                return 0;
        }
 
@@ -1443,7 +1445,7 @@ static int mt9m112_init_sensor(struct gspca_dev *gspca_dev)
        for (i = 0; i < ARRAY_SIZE(mt9m112_init); i++) {
                if (i2c_w2(gspca_dev, mt9m112_init[i].reg,
                                mt9m112_init[i].val) < 0) {
-                       err("MT9M112 sensor initialization failed");
+                       pr_err("MT9M112 sensor initialization failed\n");
                        return -ENODEV;
                }
        }
@@ -1461,7 +1463,7 @@ static int mt9m111_init_sensor(struct gspca_dev *gspca_dev)
        for (i = 0; i < ARRAY_SIZE(mt9m111_init); i++) {
                if (i2c_w2(gspca_dev, mt9m111_init[i].reg,
                                mt9m111_init[i].val) < 0) {
-                       err("MT9M111 sensor initialization failed");
+                       pr_err("MT9M111 sensor initialization failed\n");
                        return -ENODEV;
                }
        }
@@ -1485,20 +1487,20 @@ static int mt9m001_init_sensor(struct gspca_dev *gspca_dev)
        switch (id) {
        case 0x8411:
        case 0x8421:
-               info("MT9M001 color sensor detected");
+               pr_info("MT9M001 color sensor detected\n");
                break;
        case 0x8431:
-               info("MT9M001 mono sensor detected");
+               pr_info("MT9M001 mono sensor detected\n");
                break;
        default:
-               err("No MT9M001 chip detected, ID = %x\n", id);
+               pr_err("No MT9M001 chip detected, ID = %x\n\n", id);
                return -ENODEV;
        }
 
        for (i = 0; i < ARRAY_SIZE(mt9m001_init); i++) {
                if (i2c_w2(gspca_dev, mt9m001_init[i].reg,
                                mt9m001_init[i].val) < 0) {
-                       err("MT9M001 sensor initialization failed");
+                       pr_err("MT9M001 sensor initialization failed\n");
                        return -ENODEV;
                }
        }
@@ -1517,7 +1519,7 @@ static int hv7131r_init_sensor(struct gspca_dev *gspca_dev)
        for (i = 0; i < ARRAY_SIZE(hv7131r_init); i++) {
                if (i2c_w1(gspca_dev, hv7131r_init[i].reg,
                                hv7131r_init[i].val) < 0) {
-                       err("HV7131R Sensor initialization failed");
+                       pr_err("HV7131R Sensor initialization failed\n");
                        return -ENODEV;
                }
        }
@@ -2103,7 +2105,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
        for (i = 0; i < ARRAY_SIZE(bridge_init); i++) {
                value = bridge_init[i][1];
                if (reg_w(gspca_dev, bridge_init[i][0], &value, 1) < 0) {
-                       err("Device initialization failed");
+                       pr_err("Device initialization failed\n");
                        return -ENODEV;
                }
        }
@@ -2114,7 +2116,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
                reg_w1(gspca_dev, 0x1006, 0x20);
 
        if (reg_w(gspca_dev, 0x10c0, i2c_init, 9) < 0) {
-               err("Device initialization failed");
+               pr_err("Device initialization failed\n");
                return -ENODEV;
        }
 
@@ -2122,27 +2124,27 @@ static int sd_init(struct gspca_dev *gspca_dev)
        case SENSOR_OV9650:
                if (ov9650_init_sensor(gspca_dev) < 0)
                        return -ENODEV;
-               info("OV9650 sensor detected");
+               pr_info("OV9650 sensor detected\n");
                break;
        case SENSOR_OV9655:
                if (ov9655_init_sensor(gspca_dev) < 0)
                        return -ENODEV;
-               info("OV9655 sensor detected");
+               pr_info("OV9655 sensor detected\n");
                break;
        case SENSOR_SOI968:
                if (soi968_init_sensor(gspca_dev) < 0)
                        return -ENODEV;
-               info("SOI968 sensor detected");
+               pr_info("SOI968 sensor detected\n");
                break;
        case SENSOR_OV7660:
                if (ov7660_init_sensor(gspca_dev) < 0)
                        return -ENODEV;
-               info("OV7660 sensor detected");
+               pr_info("OV7660 sensor detected\n");
                break;
        case SENSOR_OV7670:
                if (ov7670_init_sensor(gspca_dev) < 0)
                        return -ENODEV;
-               info("OV7670 sensor detected");
+               pr_info("OV7670 sensor detected\n");
                break;
        case SENSOR_MT9VPRB:
                if (mt9v_init_sensor(gspca_dev) < 0)
@@ -2151,12 +2153,12 @@ static int sd_init(struct gspca_dev *gspca_dev)
        case SENSOR_MT9M111:
                if (mt9m111_init_sensor(gspca_dev) < 0)
                        return -ENODEV;
-               info("MT9M111 sensor detected");
+               pr_info("MT9M111 sensor detected\n");
                break;
        case SENSOR_MT9M112:
                if (mt9m112_init_sensor(gspca_dev) < 0)
                        return -ENODEV;
-               info("MT9M112 sensor detected");
+               pr_info("MT9M112 sensor detected\n");
                break;
        case SENSOR_MT9M001:
                if (mt9m001_init_sensor(gspca_dev) < 0)
@@ -2165,10 +2167,10 @@ static int sd_init(struct gspca_dev *gspca_dev)
        case SENSOR_HV7131R:
                if (hv7131r_init_sensor(gspca_dev) < 0)
                        return -ENODEV;
-               info("HV7131R sensor detected");
+               pr_info("HV7131R sensor detected\n");
                break;
        default:
-               info("Unsupported Sensor");
+               pr_info("Unsupported Sensor\n");
                return -ENODEV;
        }
 
@@ -2263,19 +2265,19 @@ static int sd_start(struct gspca_dev *gspca_dev)
        switch (mode & SCALE_MASK) {
        case SCALE_1280x1024:
                scale = 0xc0;
-               info("Set 1280x1024");
+               pr_info("Set 1280x1024\n");
                break;
        case SCALE_640x480:
                scale = 0x80;
-               info("Set 640x480");
+               pr_info("Set 640x480\n");
                break;
        case SCALE_320x240:
                scale = 0x90;
-               info("Set 320x240");
+               pr_info("Set 320x240\n");
                break;
        case SCALE_160x120:
                scale = 0xa0;
-               info("Set 160x120");
+               pr_info("Set 160x120\n");
                break;
        }
 
@@ -2513,7 +2515,7 @@ static const struct usb_device_id device_table[] = {
        {USB_DEVICE(0x0c45, 0x628f), SN9C20X(OV9650, 0x30, 0)},
        {USB_DEVICE(0x0c45, 0x62a0), SN9C20X(OV7670, 0x21, 0)},
        {USB_DEVICE(0x0c45, 0x62b0), SN9C20X(MT9VPRB, 0x00, 0)},
-       {USB_DEVICE(0x0c45, 0x62b3), SN9C20X(OV9655, 0x30, 0)},
+       {USB_DEVICE(0x0c45, 0x62b3), SN9C20X(OV9655, 0x30, LED_REVERSE)},
        {USB_DEVICE(0x0c45, 0x62bb), SN9C20X(OV7660, 0x21, LED_REVERSE)},
        {USB_DEVICE(0x0c45, 0x62bc), SN9C20X(HV7131R, 0x11, 0)},
        {USB_DEVICE(0x045e, 0x00f4), SN9C20X(OV9650, 0x30, 0)},
index c477ad11f103486128c0ce13b69b7949908dc900..c746bf19ca14be56aa7172f180721b54ea71d993 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Sonix sn9c102p sn9c105 sn9c120 (jpeg) subdriver
  *
- * Copyright (C) 2009-2010 Jean-François Moine <http://moinejf.free.fr>
+ * Copyright (C) 2009-2011 Jean-François Moine <http://moinejf.free.fr>
  * Copyright (C) 2005 Michel Xhaard mxhaard@magic.fr
  *
  * This program is free software; you can redistribute it and/or modify
@@ -19,6 +19,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "sonixj"
 
 #include <linux/input.h>
@@ -136,7 +138,7 @@ static void setillum(struct gspca_dev *gspca_dev);
 static void setfreq(struct gspca_dev *gspca_dev);
 
 static const struct ctrl sd_ctrls[NCTRLS] = {
-[BRIGHTNESS] =  {
+[BRIGHTNESS] = {
            {
                .id      = V4L2_CID_BRIGHTNESS,
                .type    = V4L2_CTRL_TYPE_INTEGER,
@@ -157,7 +159,7 @@ static const struct ctrl sd_ctrls[NCTRLS] = {
 #define CONTRAST_MAX 127
                .maximum = CONTRAST_MAX,
                .step    = 1,
-               .default_value = 63,
+               .default_value = 20,
            },
            .set_control = setcontrast
        },
@@ -737,7 +739,7 @@ static const u8 mi0360_sensor_init[][8] = {
        {0xd1, 0x5d, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
        {0xd1, 0x5d, 0x24, 0x00, 0x00, 0x00, 0x00, 0x10},
        {0xd1, 0x5d, 0x26, 0x00, 0x00, 0x00, 0x24, 0x10},
-       {0xd1, 0x5d, 0x2f, 0xf7, 0xB0, 0x00, 0x04, 0x10},
+       {0xd1, 0x5d, 0x2f, 0xf7, 0xb0, 0x00, 0x04, 0x10},
        {0xd1, 0x5d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
        {0xd1, 0x5d, 0x33, 0x00, 0x00, 0x01, 0x00, 0x10},
        {0xb1, 0x5d, 0x3d, 0x06, 0x8f, 0x00, 0x00, 0x10},
@@ -1277,7 +1279,7 @@ static const u8 soi768_sensor_param1[][8] = {
                        /* global gain ? : 07 - change with 0x15 at the end */
        {0xa1, 0x21, 0x10, 0x3f, 0x00, 0x00, 0x00, 0x10}, /* ???? : 063f */
        {0xa1, 0x21, 0x04, 0x06, 0x00, 0x00, 0x00, 0x10},
-       {0xb1, 0x21, 0x2d, 0x00, 0x02, 0x00, 0x00, 0x10},
+       {0xb1, 0x21, 0x2d, 0x63, 0x03, 0x00, 0x00, 0x10},
                        /* exposure ? : 0200 - change with 0x1e at the end */
        {}
 };
@@ -1395,7 +1397,7 @@ static void reg_r(struct gspca_dev *gspca_dev,
                return;
 #ifdef GSPCA_DEBUG
        if (len > USB_BUF_SZ) {
-               err("reg_r: buffer overflow");
+               pr_err("reg_r: buffer overflow\n");
                return;
        }
 #endif
@@ -1408,7 +1410,7 @@ static void reg_r(struct gspca_dev *gspca_dev,
                        500);
        PDEBUG(D_USBI, "reg_r [%02x] -> %02x", value, gspca_dev->usb_buf[0]);
        if (ret < 0) {
-               err("reg_r err %d", ret);
+               pr_err("reg_r err %d\n", ret);
                gspca_dev->usb_err = ret;
        }
 }
@@ -1432,7 +1434,7 @@ static void reg_w1(struct gspca_dev *gspca_dev,
                        gspca_dev->usb_buf, 1,
                        500);
        if (ret < 0) {
-               err("reg_w1 err %d", ret);
+               pr_err("reg_w1 err %d\n", ret);
                gspca_dev->usb_err = ret;
        }
 }
@@ -1449,7 +1451,7 @@ static void reg_w(struct gspca_dev *gspca_dev,
                value, buffer[0], buffer[1]);
 #ifdef GSPCA_DEBUG
        if (len > USB_BUF_SZ) {
-               err("reg_w: buffer overflow");
+               pr_err("reg_w: buffer overflow\n");
                return;
        }
 #endif
@@ -1462,7 +1464,7 @@ static void reg_w(struct gspca_dev *gspca_dev,
                        gspca_dev->usb_buf, len,
                        500);
        if (ret < 0) {
-               err("reg_w err %d", ret);
+               pr_err("reg_w err %d\n", ret);
                gspca_dev->usb_err = ret;
        }
 }
@@ -1502,7 +1504,7 @@ static void i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val)
                        gspca_dev->usb_buf, 8,
                        500);
        if (ret < 0) {
-               err("i2c_w1 err %d", ret);
+               pr_err("i2c_w1 err %d\n", ret);
                gspca_dev->usb_err = ret;
        }
 }
@@ -1527,7 +1529,7 @@ static void i2c_w8(struct gspca_dev *gspca_dev,
                        500);
        msleep(2);
        if (ret < 0) {
-               err("i2c_w8 err %d", ret);
+               pr_err("i2c_w8 err %d\n", ret);
                gspca_dev->usb_err = ret;
        }
 }
@@ -1591,7 +1593,7 @@ static void hv7131r_probe(struct gspca_dev *gspca_dev)
                PDEBUG(D_PROBE, "Sensor HV7131R found");
                return;
        }
-       warn("Erroneous HV7131R ID 0x%02x 0x%02x 0x%02x",
+       pr_warn("Erroneous HV7131R ID 0x%02x 0x%02x 0x%02x\n",
                gspca_dev->usb_buf[0], gspca_dev->usb_buf[1],
                gspca_dev->usb_buf[2]);
 }
@@ -1710,7 +1712,7 @@ static void ov7648_probe(struct gspca_dev *gspca_dev)
                sd->sensor = SENSOR_PO1030;
                return;
        }
-       err("Unknown sensor %04x", val);
+       pr_err("Unknown sensor %04x\n", val);
 }
 
 /* 0c45:6142 sensor may be po2030n, gc0305 or gc0307 */
@@ -1748,7 +1750,7 @@ static void po2030n_probe(struct gspca_dev *gspca_dev)
                PDEBUG(D_PROBE, "Sensor po2030n");
 /*             sd->sensor = SENSOR_PO2030N; */
        } else {
-               err("Unknown sensor ID %04x", val);
+               pr_err("Unknown sensor ID %04x\n", val);
        }
 }
 
@@ -2006,8 +2008,7 @@ static void setbrightness(struct gspca_dev *gspca_dev)
        case SENSOR_OM6802:
                expo = brightness << 2;
                sd->exposure = setexposure(gspca_dev, expo);
-               k2 = brightness >> 3;
-               break;
+               return;                 /* Y offset already set */
        }
 
        reg_w1(gspca_dev, 0x96, k2);    /* color matrix Y offset */
@@ -2019,13 +2020,13 @@ static void setcontrast(struct gspca_dev *gspca_dev)
        u8 k2;
        u8 contrast[6];
 
-       k2 = sd->ctrls[CONTRAST].val * 0x30 / (CONTRAST_MAX + 1)
-                               + 0x10;         /* 10..40 */
+       k2 = sd->ctrls[CONTRAST].val * 37 / (CONTRAST_MAX + 1)
+                               + 37;           /* 37..73 */
        contrast[0] = (k2 + 1) / 2;             /* red */
        contrast[1] = 0;
        contrast[2] = k2;                       /* green */
        contrast[3] = 0;
-       contrast[4] = (k2 + 1) / 5;             /* blue */
+       contrast[4] = k2 / 5;                   /* blue */
        contrast[5] = 0;
        reg_w(gspca_dev, 0x84, contrast, sizeof contrast);
 }
@@ -2507,9 +2508,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
                break;
        case SENSOR_HV7131R:
        case SENSOR_MI0360:
-               if (mode)
-                       reg01 |= SYS_SEL_48M;   /* 320x240: clk 48Mhz */
-               else
+               if (!mode)
                        reg01 &= ~SYS_SEL_48M;  /* 640x480: clk 24Mhz */
                reg17 &= ~MCK_SIZE_MASK;
                reg17 |= 0x01;                  /* clock / 1 */
index 76c006b2bc83035edbadd8da3d907b2943069ed1..695673106e7616408af2d3c2cacb88c46e36f699 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * spca1528 subdriver
  *
- * Copyright (C) 2010 Jean-Francois Moine (http://moinejf.free.fr)
+ * Copyright (C) 2010-2011 Jean-Francois Moine (http://moinejf.free.fr)
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "spca1528"
 
 #include "gspca.h"
@@ -171,7 +173,7 @@ static void reg_r(struct gspca_dev *gspca_dev,
        PDEBUG(D_USBI, "GET %02x 0000 %04x %02x", req, index,
                         gspca_dev->usb_buf[0]);
        if (ret < 0) {
-               err("reg_r err %d", ret);
+               pr_err("reg_r err %d\n", ret);
                gspca_dev->usb_err = ret;
        }
 }
@@ -193,7 +195,7 @@ static void reg_w(struct gspca_dev *gspca_dev,
                        value, index,
                        NULL, 0, 500);
        if (ret < 0) {
-               err("reg_w err %d", ret);
+               pr_err("reg_w err %d\n", ret);
                gspca_dev->usb_err = ret;
        }
 }
@@ -217,21 +219,23 @@ static void reg_wb(struct gspca_dev *gspca_dev,
                        value, index,
                        gspca_dev->usb_buf, 1, 500);
        if (ret < 0) {
-               err("reg_w err %d", ret);
+               pr_err("reg_w err %d\n", ret);
                gspca_dev->usb_err = ret;
        }
 }
 
 static void wait_status_0(struct gspca_dev *gspca_dev)
 {
-       int i;
+       int i, w;
 
-       i = 20;
+       i = 16;
+       w = 0;
        do {
                reg_r(gspca_dev, 0x21, 0x0000, 1);
                if (gspca_dev->usb_buf[0] == 0)
                        return;
-               msleep(30);
+               w += 15;
+               msleep(w);
        } while (--i > 0);
        PDEBUG(D_ERR, "wait_status_0 timeout");
        gspca_dev->usb_err = -ETIME;
@@ -307,8 +311,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
        sd->color = COLOR_DEF;
        sd->sharpness = SHARPNESS_DEF;
 
-       gspca_dev->nbalt = 4;           /* use alternate setting 3 */
-
        return 0;
 }
 
@@ -347,8 +349,12 @@ static int sd_isoc_init(struct gspca_dev *gspca_dev)
        mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
        reg_wb(gspca_dev, 0x25, 0x0000, 0x0004, mode);
        reg_r(gspca_dev, 0x25, 0x0004, 1);
-       reg_wb(gspca_dev, 0x27, 0x0000, 0x0000, 0x06);
+       reg_wb(gspca_dev, 0x27, 0x0000, 0x0000, 0x06);  /* 420 */
        reg_r(gspca_dev, 0x27, 0x0000, 1);
+
+/* not useful..
+       gspca_dev->alt = 4;             * use alternate setting 3 */
+
        return gspca_dev->usb_err;
 }
 
@@ -361,8 +367,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
        jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
                        0x22);          /* JPEG 411 */
 
-       /* the JPEG quality seems to be 82% */
-       jpeg_set_qual(sd->jpeg_hdr, 82);
+       /* the JPEG quality shall be 85% */
+       jpeg_set_qual(sd->jpeg_hdr, 85);
 
        /* set the controls */
        setbrightness(gspca_dev);
@@ -377,7 +383,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
 
        /* start the capture */
        wait_status_0(gspca_dev);
-       reg_w(gspca_dev, 0x31, 0x0000, 0x0004);
+       reg_w(gspca_dev, 0x31, 0x0000, 0x0004); /* start request */
        wait_status_1(gspca_dev);
        wait_status_0(gspca_dev);
        msleep(200);
@@ -390,7 +396,7 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
 {
        /* stop the capture */
        wait_status_0(gspca_dev);
-       reg_w(gspca_dev, 0x31, 0x0000, 0x0000);
+       reg_w(gspca_dev, 0x31, 0x0000, 0x0000); /* stop request */
        wait_status_1(gspca_dev);
        wait_status_0(gspca_dev);
 }
index 3e76951e3c1926066ee09451608898074538b7ac..bb82c94ece14712285278236f7d7a01fe3a40ef9 100644 (file)
@@ -19,6 +19,8 @@
  *
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "spca500"
 
 #include "gspca.h"
@@ -396,7 +398,7 @@ static int reg_w(struct gspca_dev *gspca_dev,
                        USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
                        value, index, NULL, 0, 500);
        if (ret < 0)
-               err("reg write: error %d", ret);
+               pr_err("reg write: error %d\n", ret);
        return ret;
 }
 
@@ -418,7 +420,7 @@ static int reg_r_12(struct gspca_dev *gspca_dev,
                        gspca_dev->usb_buf, length,
                        500);           /* timeout */
        if (ret < 0) {
-               err("reg_r_12 err %d", ret);
+               pr_err("reg_r_12 err %d\n", ret);
                return ret;
        }
        return (gspca_dev->usb_buf[1] << 8) + gspca_dev->usb_buf[0];
index f7ef282cc600ccb75a39fa025b06774e6dcd5f26..7aaac72aee913d019b4485bbcd9e4b1ae58678f5 100644 (file)
@@ -19,6 +19,8 @@
  *
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "spca501"
 
 #include "gspca.h"
@@ -1852,7 +1854,7 @@ static int reg_write(struct usb_device *dev,
        PDEBUG(D_USBO, "reg write: 0x%02x 0x%02x 0x%02x",
                req, index, value);
        if (ret < 0)
-               err("reg write: error %d", ret);
+               pr_err("reg write: error %d\n", ret);
        return ret;
 }
 
index e5bf865147d7a5ec4ffb0f43e2acff3bb1909816..16722dc603948705cf24878e003b16c8af76b569 100644 (file)
@@ -19,6 +19,8 @@
  *
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "spca505"
 
 #include "gspca.h"
@@ -578,7 +580,7 @@ static int reg_write(struct usb_device *dev,
        PDEBUG(D_USBO, "reg write: 0x%02x,0x%02x:0x%02x, %d",
                req, index, value, ret);
        if (ret < 0)
-               err("reg write: error %d", ret);
+               pr_err("reg write: error %d\n", ret);
        return ret;
 }
 
@@ -685,8 +687,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
                return ret;
        }
        if (ret != 0x0101) {
-               err("After vector read returns 0x%04x should be 0x0101",
-                       ret);
+               pr_err("After vector read returns 0x%04x should be 0x0101\n",
+                      ret);
        }
 
        ret = reg_write(gspca_dev->dev, 0x06, 0x16, 0x0a);
index 9d0b46027b9344e67dd1f82c788b77cbf3f5357d..a44fe3d259659a362ac39e0e190044b17ce0e32a 100644 (file)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "spca508"
 
 #include "gspca.h"
@@ -1275,7 +1277,7 @@ static int reg_write(struct usb_device *dev,
        PDEBUG(D_USBO, "reg write i:0x%04x = 0x%02x",
                index, value);
        if (ret < 0)
-               err("reg write: error %d", ret);
+               pr_err("reg write: error %d\n", ret);
        return ret;
 }
 
@@ -1297,7 +1299,7 @@ static int reg_read(struct gspca_dev *gspca_dev,
        PDEBUG(D_USBI, "reg read i:%04x --> %02x",
                index, gspca_dev->usb_buf[0]);
        if (ret < 0) {
-               err("reg_read err %d", ret);
+               pr_err("reg_read err %d\n", ret);
                return ret;
        }
        return gspca_dev->usb_buf[0];
index e836e778dfb6ae08f3890b2f6d69759926fddf83..c82fd53cef95bb3ee06975760fb02d6f100378d1 100644 (file)
@@ -20,6 +20,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "spca561"
 
 #include <linux/input.h>
@@ -315,7 +317,7 @@ static void reg_w_val(struct usb_device *dev, __u16 index, __u8 value)
                              value, index, NULL, 0, 500);
        PDEBUG(D_USBO, "reg write: 0x%02x:0x%02x", index, value);
        if (ret < 0)
-               err("reg write: error %d", ret);
+               pr_err("reg write: error %d\n", ret);
 }
 
 static void write_vector(struct gspca_dev *gspca_dev,
index 5ba96aff2252994e3265c873a04dbf530362e733..df805f7982827510568714ba8322123bc8b915d3 100644 (file)
@@ -33,6 +33,8 @@
  * drivers.
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "sq905"
 
 #include <linux/workqueue.h>
@@ -123,8 +125,7 @@ static int sq905_command(struct gspca_dev *gspca_dev, u16 index)
                              SQ905_COMMAND, index, gspca_dev->usb_buf, 1,
                              SQ905_CMD_TIMEOUT);
        if (ret < 0) {
-               err("%s: usb_control_msg failed (%d)",
-                       __func__, ret);
+               pr_err("%s: usb_control_msg failed (%d)\n", __func__, ret);
                return ret;
        }
 
@@ -135,8 +136,7 @@ static int sq905_command(struct gspca_dev *gspca_dev, u16 index)
                              SQ905_PING, 0, gspca_dev->usb_buf, 1,
                              SQ905_CMD_TIMEOUT);
        if (ret < 0) {
-               err("%s: usb_control_msg failed 2 (%d)",
-                       __func__, ret);
+               pr_err("%s: usb_control_msg failed 2 (%d)\n", __func__, ret);
                return ret;
        }
 
@@ -158,7 +158,7 @@ static int sq905_ack_frame(struct gspca_dev *gspca_dev)
                              SQ905_READ_DONE, 0, gspca_dev->usb_buf, 1,
                              SQ905_CMD_TIMEOUT);
        if (ret < 0) {
-               err("%s: usb_control_msg failed (%d)", __func__, ret);
+               pr_err("%s: usb_control_msg failed (%d)\n", __func__, ret);
                return ret;
        }
 
@@ -186,7 +186,7 @@ sq905_read_data(struct gspca_dev *gspca_dev, u8 *data, int size, int need_lock)
        if (need_lock)
                mutex_unlock(&gspca_dev->usb_lock);
        if (ret < 0) {
-               err("%s: usb_control_msg failed (%d)", __func__, ret);
+               pr_err("%s: usb_control_msg failed (%d)\n", __func__, ret);
                return ret;
        }
        ret = usb_bulk_msg(gspca_dev->dev,
@@ -195,8 +195,7 @@ sq905_read_data(struct gspca_dev *gspca_dev, u8 *data, int size, int need_lock)
 
        /* successful, it returns 0, otherwise  negative */
        if (ret < 0 || act_len != size) {
-               err("bulk read fail (%d) len %d/%d",
-                       ret, act_len, size);
+               pr_err("bulk read fail (%d) len %d/%d\n", ret, act_len, size);
                return -EIO;
        }
        return 0;
@@ -226,7 +225,7 @@ static void sq905_dostream(struct work_struct *work)
 
        buffer = kmalloc(SQ905_MAX_TRANSFER, GFP_KERNEL | GFP_DMA);
        if (!buffer) {
-               err("Couldn't allocate USB buffer");
+               pr_err("Couldn't allocate USB buffer\n");
                goto quit_stream;
        }
 
index 457563b7a71bd98e246225eb2d4eb8026c1ebfde..c2c056056e082a781b680833a72f2ede2a155b6b 100644 (file)
@@ -27,6 +27,8 @@
  * and may contain code fragments from it.
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "sq905c"
 
 #include <linux/workqueue.h>
@@ -95,8 +97,7 @@ static int sq905c_command(struct gspca_dev *gspca_dev, u16 command, u16 index)
                              command, index, NULL, 0,
                              SQ905C_CMD_TIMEOUT);
        if (ret < 0) {
-               err("%s: usb_control_msg failed (%d)",
-                       __func__, ret);
+               pr_err("%s: usb_control_msg failed (%d)\n", __func__, ret);
                return ret;
        }
 
@@ -115,8 +116,7 @@ static int sq905c_read(struct gspca_dev *gspca_dev, u16 command, u16 index,
                              command, index, gspca_dev->usb_buf, size,
                              SQ905C_CMD_TIMEOUT);
        if (ret < 0) {
-               err("%s: usb_control_msg failed (%d)",
-                      __func__, ret);
+               pr_err("%s: usb_control_msg failed (%d)\n", __func__, ret);
                return ret;
        }
 
@@ -146,7 +146,7 @@ static void sq905c_dostream(struct work_struct *work)
 
        buffer = kmalloc(SQ905C_MAX_TRANSFER, GFP_KERNEL | GFP_DMA);
        if (!buffer) {
-               err("Couldn't allocate USB buffer");
+               pr_err("Couldn't allocate USB buffer\n");
                goto quit_stream;
        }
 
index 8215d5dcd4560fa8383215971709b1e92dc36b31..e4255b4905e705bb2a0bb3c48c2382033f292b13 100644 (file)
@@ -20,6 +20,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "sq930x"
 
 #include "gspca.h"
@@ -468,7 +470,7 @@ static void reg_r(struct gspca_dev *gspca_dev,
                        value, 0, gspca_dev->usb_buf, len,
                        500);
        if (ret < 0) {
-               err("reg_r %04x failed %d", value, ret);
+               pr_err("reg_r %04x failed %d\n", value, ret);
                gspca_dev->usb_err = ret;
        }
 }
@@ -488,7 +490,7 @@ static void reg_w(struct gspca_dev *gspca_dev, u16 value, u16 index)
                        500);
        msleep(30);
        if (ret < 0) {
-               err("reg_w %04x %04x failed %d", value, index, ret);
+               pr_err("reg_w %04x %04x failed %d\n", value, index, ret);
                gspca_dev->usb_err = ret;
        }
 }
@@ -511,7 +513,7 @@ static void reg_wb(struct gspca_dev *gspca_dev, u16 value, u16 index,
                        1000);
        msleep(30);
        if (ret < 0) {
-               err("reg_wb %04x %04x failed %d", value, index, ret);
+               pr_err("reg_wb %04x %04x failed %d\n", value, index, ret);
                gspca_dev->usb_err = ret;
        }
 }
@@ -556,7 +558,7 @@ static void i2c_write(struct sd *sd,
                        gspca_dev->usb_buf, buf - gspca_dev->usb_buf,
                        500);
        if (ret < 0) {
-               err("i2c_write failed %d", ret);
+               pr_err("i2c_write failed %d\n", ret);
                gspca_dev->usb_err = ret;
        }
 }
@@ -575,7 +577,7 @@ static void ucbus_write(struct gspca_dev *gspca_dev,
 
 #ifdef GSPCA_DEBUG
        if ((batchsize - 1) * 3 > USB_BUF_SZ) {
-               err("Bug: usb_buf overflow");
+               pr_err("Bug: usb_buf overflow\n");
                gspca_dev->usb_err = -ENOMEM;
                return;
        }
@@ -612,7 +614,7 @@ static void ucbus_write(struct gspca_dev *gspca_dev,
                                gspca_dev->usb_buf, buf - gspca_dev->usb_buf,
                                500);
                if (ret < 0) {
-                       err("ucbus_write failed %d", ret);
+                       pr_err("ucbus_write failed %d\n", ret);
                        gspca_dev->usb_err = ret;
                        return;
                }
@@ -688,7 +690,7 @@ static void cmos_probe(struct gspca_dev *gspca_dev)
                        break;
        }
        if (i >= ARRAY_SIZE(probe_order)) {
-               err("Unknown sensor");
+               pr_err("Unknown sensor\n");
                gspca_dev->usb_err = -EINVAL;
                return;
        }
@@ -696,7 +698,8 @@ static void cmos_probe(struct gspca_dev *gspca_dev)
        switch (sd->sensor) {
        case SENSOR_OV7660:
        case SENSOR_OV9630:
-               err("Sensor %s not yet treated", sensor_tb[sd->sensor].name);
+               pr_err("Sensor %s not yet treated\n",
+                      sensor_tb[sd->sensor].name);
                gspca_dev->usb_err = -EINVAL;
                break;
        }
@@ -1091,7 +1094,7 @@ static void sd_dq_callback(struct gspca_dev *gspca_dev)
        gspca_dev->cam.bulk_nurbs = 1;
        ret = usb_submit_urb(gspca_dev->urb[0], GFP_ATOMIC);
        if (ret < 0)
-               err("sd_dq_callback() err %d", ret);
+               pr_err("sd_dq_callback() err %d\n", ret);
 
        /* wait a little time, otherwise the webcam crashes */
        msleep(100);
index 763747700f10be0ed6e7731c26de841b0f22bcbb..42a7a28a6c8bf934c4312281373ad9dc4b112bc3 100644 (file)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "stk014"
 
 #include "gspca.h"
@@ -137,7 +139,7 @@ static u8 reg_r(struct gspca_dev *gspca_dev,
                        gspca_dev->usb_buf, 1,
                        500);
        if (ret < 0) {
-               err("reg_r err %d", ret);
+               pr_err("reg_r err %d\n", ret);
                gspca_dev->usb_err = ret;
                return 0;
        }
@@ -162,7 +164,7 @@ static void reg_w(struct gspca_dev *gspca_dev,
                        0,
                        500);
        if (ret < 0) {
-               err("reg_w err %d", ret);
+               pr_err("reg_w err %d\n", ret);
                gspca_dev->usb_err = ret;
        }
 }
@@ -192,7 +194,7 @@ static void rcv_val(struct gspca_dev *gspca_dev,
                        &alen,
                        500);           /* timeout in milliseconds */
        if (ret < 0) {
-               err("rcv_val err %d", ret);
+               pr_err("rcv_val err %d\n", ret);
                gspca_dev->usb_err = ret;
        }
 }
@@ -235,7 +237,7 @@ static void snd_val(struct gspca_dev *gspca_dev,
                        &alen,
                        500);   /* timeout in milliseconds */
        if (ret < 0) {
-               err("snd_val err %d", ret);
+               pr_err("snd_val err %d\n", ret);
                gspca_dev->usb_err = ret;
        } else {
                if (ads == 0x003f08) {
@@ -315,7 +317,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
        ret = reg_r(gspca_dev, 0x0740);
        if (gspca_dev->usb_err >= 0) {
                if (ret != 0xff) {
-                       err("init reg: 0x%02x", ret);
+                       pr_err("init reg: 0x%02x\n", ret);
                        gspca_dev->usb_err = -EIO;
                }
        }
@@ -349,8 +351,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
                                        gspca_dev->iface,
                                        gspca_dev->alt);
        if (ret < 0) {
-               err("set intf %d %d failed",
-                       gspca_dev->iface, gspca_dev->alt);
+               pr_err("set intf %d %d failed\n",
+                      gspca_dev->iface, gspca_dev->alt);
                gspca_dev->usb_err = ret;
                goto out;
        }
index e2ef41cf72d74bdaca8425d34048a3a159895cb6..4dcc7e37f9fde492c228d315314459c069cc26d2 100644 (file)
@@ -27,6 +27,8 @@
  *
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "stv0680"
 
 #include "gspca.h"
@@ -79,7 +81,7 @@ static int stv_sndctrl(struct gspca_dev *gspca_dev, int set, u8 req, u16 val,
                              val, 0, gspca_dev->usb_buf, size, 500);
 
        if ((ret < 0) && (req != 0x0a))
-               err("usb_control_msg error %i, request = 0x%x, error = %i",
+               pr_err("usb_control_msg error %i, request = 0x%x, error = %i\n",
                       set, req, ret);
 
        return ret;
@@ -236,7 +238,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
 
        if (stv_sndctrl(gspca_dev, 2, 0x06, 0x0100, 0x12) != 0x12 ||
            gspca_dev->usb_buf[8] != 0x53 || gspca_dev->usb_buf[9] != 0x05) {
-               err("Could not get descriptor 0100.");
+               pr_err("Could not get descriptor 0100\n");
                return stv0680_handle_error(gspca_dev, -EIO);
        }
 
index 2f3c3a606ce463b58ba4b15d7f50dc178f70dfd0..5b318faf9aa8da3a6648103a3b6297aaa48d2e33 100644 (file)
@@ -6,5 +6,5 @@ gspca_stv06xx-objs := stv06xx.o \
                      stv06xx_pb0100.o \
                      stv06xx_st6422.o
 
-EXTRA_CFLAGS += -Idrivers/media/video/gspca
+ccflags-y += -Idrivers/media/video/gspca
 
index abf1658fa33e9e4ca175e2f69a56ed9651d3e1ec..b1fca7db1015acd75a68d61bd68d54c43201ea97 100644 (file)
@@ -27,6 +27,8 @@
  * P/N 861040-0000: Sensor ST VV6410       ASIC STV0610   - QuickCam Web
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/input.h>
 #include "stv06xx_sensor.h"
 
@@ -189,7 +191,7 @@ int stv06xx_read_sensor(struct sd *sd, const u8 address, u16 *value)
                              0x04, 0x40, 0x1400, 0, buf, I2C_BUFFER_LENGTH,
                              STV06XX_URB_MSG_TIMEOUT);
        if (err < 0) {
-               err("I2C: Read error writing address: %d", err);
+               pr_err("I2C: Read error writing address: %d\n", err);
                return err;
        }
 
@@ -213,14 +215,14 @@ static void stv06xx_dump_bridge(struct sd *sd)
        int i;
        u8 data, buf;
 
-       info("Dumping all stv06xx bridge registers");
+       pr_info("Dumping all stv06xx bridge registers\n");
        for (i = 0x1400; i < 0x160f; i++) {
                stv06xx_read_bridge(sd, i, &data);
 
-               info("Read 0x%x from address 0x%x", data, i);
+               pr_info("Read 0x%x from address 0x%x\n", data, i);
        }
 
-       info("Testing stv06xx bridge registers for writability");
+       pr_info("Testing stv06xx bridge registers for writability\n");
        for (i = 0x1400; i < 0x160f; i++) {
                stv06xx_read_bridge(sd, i, &data);
                buf = data;
@@ -228,12 +230,12 @@ static void stv06xx_dump_bridge(struct sd *sd)
                stv06xx_write_bridge(sd, i, 0xff);
                stv06xx_read_bridge(sd, i, &data);
                if (data == 0xff)
-                       info("Register 0x%x is read/write", i);
+                       pr_info("Register 0x%x is read/write\n", i);
                else if (data != buf)
-                       info("Register 0x%x is read/write,"
-                            " but only partially", i);
+                       pr_info("Register 0x%x is read/write, but only partially\n",
+                               i);
                else
-                       info("Register 0x%x is read-only", i);
+                       pr_info("Register 0x%x is read-only\n", i);
 
                stv06xx_write_bridge(sd, i, buf);
        }
index e0f63c51f40d0dc7e103a3a6a7ff1f25d4aabfb0..d270a5981afe21564e7fb751a3a051f91f486552 100644 (file)
@@ -37,6 +37,8 @@
 
 #define STV_ISOC_ENDPOINT_ADDR         0x81
 
+#define STV_R                           0x0509
+
 #define STV_REG23                      0x0423
 
 /* Control registers of the STV0600 ASIC */
@@ -61,7 +63,9 @@
 
 /* Refers to the CIF 352x288 and QCIF 176x144 */
 /* 1: 288 lines, 2: 144 lines */
-#define STV_Y_CTRL                     0x15c3
+#define STV_Y_CTRL                     0x15c3
+
+#define STV_RESET                       0x1620
 
 /* 0xa: 352 columns, 0x6: 176 columns */
 #define STV_X_CTRL                     0x1680
index b8156855f2b759e7df9f934e5540c5d87a68308e..a8698b7a75669a096beb134836863e7258a3f973 100644 (file)
@@ -28,6 +28,8 @@
  * P/N 861040-0000: Sensor ST VV6410       ASIC STV0610   - QuickCam Web
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include "stv06xx_hdcs.h"
 
 static const struct ctrl hdcs1x00_ctrl[] = {
@@ -428,7 +430,7 @@ static int hdcs_probe_1x00(struct sd *sd)
        if (ret < 0 || sensor != 0x08)
                return -ENODEV;
 
-       info("HDCS-1000/1100 sensor detected");
+       pr_info("HDCS-1000/1100 sensor detected\n");
 
        sd->gspca_dev.cam.cam_mode = hdcs1x00_mode;
        sd->gspca_dev.cam.nmodes = ARRAY_SIZE(hdcs1x00_mode);
@@ -487,7 +489,7 @@ static int hdcs_probe_1020(struct sd *sd)
        if (ret < 0 || sensor != 0x10)
                return -ENODEV;
 
-       info("HDCS-1020 sensor detected");
+       pr_info("HDCS-1020 sensor detected\n");
 
        sd->gspca_dev.cam.cam_mode = hdcs1020_mode;
        sd->gspca_dev.cam.nmodes = ARRAY_SIZE(hdcs1020_mode);
@@ -601,11 +603,11 @@ static int hdcs_dump(struct sd *sd)
 {
        u16 reg, val;
 
-       info("Dumping sensor registers:");
+       pr_info("Dumping sensor registers:\n");
 
        for (reg = HDCS_IDENT; reg <= HDCS_ROWEXPH; reg++) {
                stv06xx_read_sensor(sd, reg, &val);
-               info("reg 0x%02x = 0x%02x", reg, val);
+               pr_info("reg 0x%02x = 0x%02x\n", reg, val);
        }
        return 0;
 }
index 75a5b9c2f15ff35810637c4f4b04ff6398eda736..26f14fc4a135eec6991deb85f2d72e8d6acd682e 100644 (file)
@@ -44,6 +44,8 @@
  * PB_CFILLIN       = R5  = 0x0E (14 dec)     : Sets the frame rate
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include "stv06xx_pb0100.h"
 
 static const struct ctrl pb0100_ctrl[] = {
@@ -190,7 +192,7 @@ static int pb0100_probe(struct sd *sd)
                if (!sensor_settings)
                        return -ENOMEM;
 
-               info("Photobit pb0100 sensor detected");
+               pr_info("Photobit pb0100 sensor detected\n");
 
                sd->gspca_dev.cam.cam_mode = pb0100_mode;
                sd->gspca_dev.cam.nmodes = ARRAY_SIZE(pb0100_mode);
index 8a456de4970ab2a82cb7c5ecd920cc71c35205ce..9940e035b3ab4b0ef0dd318eb31f36b90d70c640 100644 (file)
@@ -26,6 +26,8 @@
  *
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include "stv06xx_st6422.h"
 
 /* controls */
@@ -136,7 +138,7 @@ static int st6422_probe(struct sd *sd)
        if (sd->bridge != BRIDGE_ST6422)
                return -ENODEV;
 
-       info("st6422 sensor detected");
+       pr_info("st6422 sensor detected\n");
 
        sensor_settings = kmalloc(sizeof *sensor_settings, GFP_KERNEL);
        if (!sensor_settings)
index f8398434c328c3659a30b73c1ae1bb80a0620435..a5c69d9ebdd4b3d63271a51de10294c7ca2571d2 100644 (file)
@@ -27,6 +27,8 @@
  * P/N 861040-0000: Sensor ST VV6410       ASIC STV0610   - QuickCam Web
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include "stv06xx_vv6410.h"
 
 static struct v4l2_pix_format vv6410_mode[] = {
@@ -112,7 +114,7 @@ static int vv6410_probe(struct sd *sd)
                return -ENODEV;
 
        if (data == 0x19) {
-               info("vv6410 sensor detected");
+               pr_info("vv6410 sensor detected\n");
 
                sensor_settings = kmalloc(ARRAY_SIZE(vv6410_ctrl) * sizeof(s32),
                                          GFP_KERNEL);
@@ -138,18 +140,7 @@ static int vv6410_init(struct sd *sd)
        s32 *sensor_settings = sd->sensor_priv;
 
        for (i = 0; i < ARRAY_SIZE(stv_bridge_init); i++) {
-               /* if NULL then len contains single value */
-               if (stv_bridge_init[i].data == NULL) {
-                       err = stv06xx_write_bridge(sd,
-                               stv_bridge_init[i].start,
-                               stv_bridge_init[i].len);
-               } else {
-                       int j;
-                       for (j = 0; j < stv_bridge_init[i].len; j++)
-                               err = stv06xx_write_bridge(sd,
-                                       stv_bridge_init[i].start + j,
-                                       stv_bridge_init[i].data[j]);
-               }
+               stv06xx_write_bridge(sd, stv_bridge_init[i].addr, stv_bridge_init[i].data);
        }
 
        if (err < 0)
@@ -183,15 +174,6 @@ static int vv6410_start(struct sd *sd)
        struct cam *cam = &sd->gspca_dev.cam;
        u32 priv = cam->cam_mode[sd->gspca_dev.curr_mode].priv;
 
-       if (priv & VV6410_CROP_TO_QVGA) {
-               PDEBUG(D_CONF, "Cropping to QVGA");
-               stv06xx_write_sensor(sd, VV6410_XENDH, 320 - 1);
-               stv06xx_write_sensor(sd, VV6410_YENDH, 240 - 1);
-       } else {
-               stv06xx_write_sensor(sd, VV6410_XENDH, 360 - 1);
-               stv06xx_write_sensor(sd, VV6410_YENDH, 294 - 1);
-       }
-
        if (priv & VV6410_SUBSAMPLE) {
                PDEBUG(D_CONF, "Enabling subsampling");
                stv06xx_write_bridge(sd, STV_Y_CTRL, 0x02);
@@ -201,8 +183,8 @@ static int vv6410_start(struct sd *sd)
        } else {
                stv06xx_write_bridge(sd, STV_Y_CTRL, 0x01);
                stv06xx_write_bridge(sd, STV_X_CTRL, 0x0a);
+               stv06xx_write_bridge(sd, STV_SCAN_RATE, 0x00);
 
-               stv06xx_write_bridge(sd, STV_SCAN_RATE, 0x20);
        }
 
        /* Turn on LED */
@@ -242,11 +224,11 @@ static int vv6410_dump(struct sd *sd)
        u8 i;
        int err = 0;
 
-       info("Dumping all vv6410 sensor registers");
+       pr_info("Dumping all vv6410 sensor registers\n");
        for (i = 0; i < 0xff && !err; i++) {
                u16 data;
                err = stv06xx_read_sensor(sd, i, &data);
-               info("Register 0x%x contained 0x%x", i, data);
+               pr_info("Register 0x%x contained 0x%x\n", i, data);
        }
        return (err < 0) ? err : 0;
 }
index 7fe3587f5f71fac1bc0aef41e8478261f7e278cc..a25b8873f2e65a1ae765b1af2def15e8e9ddc4a8 100644 (file)
@@ -211,49 +211,49 @@ const struct stv06xx_sensor stv06xx_sensor_vv6410 = {
 
 /* If NULL, only single value to write, stored in len */
 struct stv_init {
-       const u8 *data;
-       u16 start;
-       u8 len;
-};
-
-static const u8 x1500[] = {    /* 0x1500 - 0x150f */
-       0x0b, 0xa7, 0xb7, 0x00, 0x00
-};
-
-static const u8 x1536[] = {    /* 0x1536 - 0x153b */
-       0x02, 0x00, 0x60, 0x01, 0x20, 0x01
+       u16 addr;
+       u8 data;
 };
 
 static const struct stv_init stv_bridge_init[] = {
        /* This reg is written twice. Some kind of reset? */
-       {NULL,  0x1620, 0x80},
-       {NULL,  0x1620, 0x00},
-       {NULL,  0x1443, 0x00},
-       {NULL,  0x1423, 0x04},
-       {x1500, 0x1500, ARRAY_SIZE(x1500)},
-       {x1536, 0x1536, ARRAY_SIZE(x1536)},
+       {STV_RESET, 0x80},
+       {STV_RESET, 0x00},
+       {STV_SCAN_RATE, 0x00},
+       {STV_I2C_FLUSH, 0x04},
+       {STV_REG00, 0x0b},
+       {STV_REG01, 0xa7},
+       {STV_REG02, 0xb7},
+       {STV_REG03, 0x00},
+       {STV_REG04, 0x00},
+       {0x1536, 0x02},
+       {0x1537, 0x00},
+       {0x1538, 0x60},
+       {0x1539, 0x01},
+       {0x153a, 0x20},
+       {0x153b, 0x01},
 };
 
 static const u8 vv6410_sensor_init[][2] = {
        /* Setup registers */
-       {VV6410_SETUP0,         VV6410_SOFT_RESET},
-       {VV6410_SETUP0,         VV6410_LOW_POWER_MODE},
+       {VV6410_SETUP0, VV6410_SOFT_RESET},
+       {VV6410_SETUP0, VV6410_LOW_POWER_MODE},
        /* Use shuffled read-out mode */
-       {VV6410_SETUP1,         BIT(6)},
-       /* All modes to 1 */
-       {VV6410_FGMODES,        BIT(6) | BIT(4) | BIT(2) | BIT(0)},
-       {VV6410_PINMAPPING,     0x00},
+       {VV6410_SETUP1, BIT(6)},
+       /* All modes to 1, FST, Fast QCK, Free running QCK, Free running LST, FST will qualify visible pixels */
+       {VV6410_FGMODES, BIT(6) | BIT(4) | BIT(2) | BIT(0)},
+       {VV6410_PINMAPPING, 0x00},
        /* Pre-clock generator divide off */
-       {VV6410_DATAFORMAT,     BIT(7) | BIT(0)},
+       {VV6410_DATAFORMAT, BIT(7) | BIT(0)},
 
-       {VV6410_CLKDIV,         VV6410_CLK_DIV_2},
+       {VV6410_CLKDIV, VV6410_CLK_DIV_2},
 
        /* System registers */
        /* Enable voltage doubler */
-       {VV6410_AS0,            BIT(6) | BIT(4) | BIT(3) | BIT(2) | BIT(1)},
-       {VV6410_AT0,            0x00},
+       {VV6410_AS0, BIT(6) | BIT(4) | BIT(3) | BIT(2) | BIT(1)},
+       {VV6410_AT0, 0x00},
        /* Power up audio, differential */
-       {VV6410_AT1,            BIT(4)|BIT(0)},
+       {VV6410_AT1, BIT(4) | BIT(0)},
 };
 
 #endif
index 6ec232902183ebb7b2dc4c7afe93010b9c1cd791..c8909772435ac8252bd5e6633c888259c53133b7 100644 (file)
@@ -19,6 +19,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "sunplus"
 
 #include "gspca.h"
@@ -325,7 +327,7 @@ static void reg_r(struct gspca_dev *gspca_dev,
 
 #ifdef GSPCA_DEBUG
        if (len > USB_BUF_SZ) {
-               err("reg_r: buffer overflow");
+               pr_err("reg_r: buffer overflow\n");
                return;
        }
 #endif
@@ -340,7 +342,7 @@ static void reg_r(struct gspca_dev *gspca_dev,
                        len ? gspca_dev->usb_buf : NULL, len,
                        500);
        if (ret < 0) {
-               err("reg_r err %d", ret);
+               pr_err("reg_r err %d\n", ret);
                gspca_dev->usb_err = ret;
        }
 }
@@ -365,7 +367,7 @@ static void reg_w_1(struct gspca_dev *gspca_dev,
                        gspca_dev->usb_buf, 1,
                        500);
        if (ret < 0) {
-               err("reg_w_1 err %d", ret);
+               pr_err("reg_w_1 err %d\n", ret);
                gspca_dev->usb_err = ret;
        }
 }
@@ -385,7 +387,7 @@ static void reg_w_riv(struct gspca_dev *gspca_dev,
                        USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
                        value, index, NULL, 0, 500);
        if (ret < 0) {
-               err("reg_w_riv err %d", ret);
+               pr_err("reg_w_riv err %d\n", ret);
                gspca_dev->usb_err = ret;
                return;
        }
index d1d733b9359b41e9f012a6d6b651d2f4b2597a3b..90f0877eb5991467c0631b6b4d96b4bf4ba6d139 100644 (file)
@@ -26,6 +26,8 @@
  *                     Costantino Leandro
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "t613"
 
 #include <linux/slab.h>
@@ -572,7 +574,7 @@ static void reg_w_buf(struct gspca_dev *gspca_dev,
 
                tmpbuf = kmemdup(buffer, len, GFP_KERNEL);
                if (!tmpbuf) {
-                       err("Out of memory");
+                       pr_err("Out of memory\n");
                        return;
                }
                usb_control_msg(gspca_dev->dev,
@@ -598,7 +600,7 @@ static void reg_w_ixbuf(struct gspca_dev *gspca_dev,
        } else {
                p = tmpbuf = kmalloc(len * 2, GFP_KERNEL);
                if (!tmpbuf) {
-                       err("Out of memory");
+                       pr_err("Out of memory\n");
                        return;
                }
        }
@@ -652,7 +654,7 @@ static void om6802_sensor_init(struct gspca_dev *gspca_dev)
        }
        byte = reg_r(gspca_dev, 0x0063);
        if (byte != 0x17) {
-               err("Bad sensor reset %02x", byte);
+               pr_err("Bad sensor reset %02x\n", byte);
                /* continue? */
        }
 
@@ -890,7 +892,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
                sd->sensor = SENSOR_OM6802;
                break;
        default:
-               err("unknown sensor %04x", sensor_id);
+               pr_err("unknown sensor %04x\n", sensor_id);
                return -EINVAL;
        }
 
@@ -905,7 +907,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
                                break;          /* OK */
                }
                if (i < 0) {
-                       err("Bad sensor reset %02x", test_byte);
+                       pr_err("Bad sensor reset %02x\n", test_byte);
                        return -EIO;
                }
                reg_w_buf(gspca_dev, n2, sizeof n2);
diff --git a/drivers/media/video/gspca/topro.c b/drivers/media/video/gspca/topro.c
new file mode 100644 (file)
index 0000000..29596c5
--- /dev/null
@@ -0,0 +1,4989 @@
+/*
+ * Topro TP6800/6810 webcam driver.
+ *
+ * Copyright (C) 2011 Jean-François Moine (http://moinejf.free.fr)
+ * Copyright (C) 2009 Anders Blomdell (anders.blomdell@control.lth.se)
+ * Copyright (C) 2008 Thomas Champagne (lafeuil@gmail.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include "gspca.h"
+
+MODULE_DESCRIPTION("Topro TP6800/6810 gspca webcam driver");
+MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>, "
+               "Anders Blomdell <anders.blomdell@control.lth.se>");
+MODULE_LICENSE("GPL");
+
+static int force_sensor = -1;
+
+/* JPEG header */
+static const u8 jpeg_head[] = {
+       0xff, 0xd8,                     /* jpeg */
+
+/* quantization table quality 50% */
+       0xff, 0xdb, 0x00, 0x84,         /* DQT */
+0,
+#define JPEG_QT0_OFFSET 7
+       0x10, 0x0b, 0x0c, 0x0e, 0x0c, 0x0a, 0x10, 0x0e,
+       0x0d, 0x0e, 0x12, 0x11, 0x10, 0x13, 0x18, 0x28,
+       0x1a, 0x18, 0x16, 0x16, 0x18, 0x31, 0x23, 0x25,
+       0x1d, 0x28, 0x3a, 0x33, 0x3d, 0x3c, 0x39, 0x33,
+       0x38, 0x37, 0x40, 0x48, 0x5c, 0x4e, 0x40, 0x44,
+       0x57, 0x45, 0x37, 0x38, 0x50, 0x6d, 0x51, 0x57,
+       0x5f, 0x62, 0x67, 0x68, 0x67, 0x3e, 0x4d, 0x71,
+       0x79, 0x70, 0x64, 0x78, 0x5c, 0x65, 0x67, 0x63,
+1,
+#define JPEG_QT1_OFFSET 72
+       0x11, 0x12, 0x12, 0x18, 0x15, 0x18, 0x2f, 0x1a,
+       0x1a, 0x2f, 0x63, 0x42, 0x38, 0x42, 0x63, 0x63,
+       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+
+       /* Define Huffman table (thanks to Thomas Kaiser) */
+       0xff, 0xc4, 0x01, 0x5e,
+       0x00, 0x00, 0x02, 0x03,
+       0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02,
+       0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10,
+       0x00, 0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04,
+       0x07, 0x05, 0x04, 0x06, 0x01, 0x00, 0x00, 0x57,
+       0x01, 0x02, 0x03, 0x00, 0x11, 0x04, 0x12, 0x21,
+       0x31, 0x13, 0x41, 0x51, 0x61, 0x05, 0x22, 0x32,
+       0x14, 0x71, 0x81, 0x91, 0x15, 0x23, 0x42, 0x52,
+       0x62, 0xa1, 0xb1, 0x06, 0x33, 0x72, 0xc1, 0xd1,
+       0x24, 0x43, 0x53, 0x82, 0x16, 0x34, 0x92, 0xa2,
+       0xe1, 0xf1, 0xf0, 0x07, 0x08, 0x17, 0x18, 0x25,
+       0x26, 0x27, 0x28, 0x35, 0x36, 0x37, 0x38, 0x44,
+       0x45, 0x46, 0x47, 0x48, 0x54, 0x55, 0x56, 0x57,
+       0x58, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x73,
+       0x74, 0x75, 0x76, 0x77, 0x78, 0x83, 0x84, 0x85,
+       0x86, 0x87, 0x88, 0x93, 0x94, 0x95, 0x96, 0x97,
+       0x98, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xb2,
+       0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xc2, 0xc3,
+       0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xd2, 0xd3, 0xd4,
+       0xd5, 0xd6, 0xd7, 0xd8, 0xe2, 0xe3, 0xe4, 0xe5,
+       0xe6, 0xe7, 0xe8, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6,
+       0xf7, 0xf8, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+       0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04,
+       0x05, 0x06, 0x07, 0x08, 0x09, 0x11, 0x00, 0x02,
+       0x01, 0x02, 0x04, 0x04, 0x03, 0x04, 0x07, 0x05,
+       0x04, 0x06, 0x01, 0x00, 0x00, 0x57, 0x00, 0x01,
+       0x11, 0x02, 0x21, 0x03, 0x12, 0x31, 0x41, 0x13,
+       0x22, 0x51, 0x61, 0x04, 0x32, 0x71, 0x05, 0x14,
+       0x23, 0x42, 0x33, 0x52, 0x81, 0x91, 0xa1, 0xb1,
+       0xf0, 0x06, 0x15, 0xc1, 0xd1, 0xe1, 0x24, 0x43,
+       0x62, 0xf1, 0x16, 0x25, 0x34, 0x53, 0x72, 0x82,
+       0x92, 0x07, 0x08, 0x17, 0x18, 0x26, 0x27, 0x28,
+       0x35, 0x36, 0x37, 0x38, 0x44, 0x45, 0x46, 0x47,
+       0x48, 0x54, 0x55, 0x56, 0x57, 0x58, 0x63, 0x64,
+       0x65, 0x66, 0x67, 0x68, 0x73, 0x74, 0x75, 0x76,
+       0x77, 0x78, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88,
+       0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0xa2, 0xa3,
+       0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xb2, 0xb3, 0xb4,
+       0xb5, 0xb6, 0xb7, 0xb8, 0xc2, 0xc3, 0xc4, 0xc5,
+       0xc6, 0xc7, 0xc8, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6,
+       0xd7, 0xd8, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
+       0xe8, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
+       0xff, 0xc0, 0x00, 0x11,         /* SOF0 (start of frame 0 */
+       0x08,                           /* data precision */
+#define JPEG_HEIGHT_OFFSET 493
+       0x01, 0xe0,                     /* height */
+       0x02, 0x80,                     /* width */
+       0x03,                           /* component number */
+               0x01,
+                       0x21,           /* samples Y = jpeg 422 */
+                       0x00,           /* quant Y */
+               0x02, 0x11, 0x01,       /* samples CbCr - quant CbCr */
+               0x03, 0x11, 0x01,
+
+       0xff, 0xda, 0x00, 0x0c,         /* SOS (start of scan) */
+       0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f, 0x00
+#define JPEG_HDR_SZ 521
+};
+
+enum e_ctrl {
+       EXPOSURE,
+       QUALITY,
+       SHARPNESS,
+       RGAIN,
+       GAIN,
+       BGAIN,
+       GAMMA,
+       AUTOGAIN,
+       NCTRLS          /* number of controls */
+};
+
+#define AUTOGAIN_DEF 1
+
+struct sd {
+       struct gspca_dev gspca_dev;     /* !! must be the first item */
+
+       struct gspca_ctrl ctrls[NCTRLS];
+
+       u8 framerate;
+       u8 quality;             /* webcam current JPEG quality (0..16) */
+       s8 ag_cnt;              /* autogain / start counter for tp6810 */
+#define AG_CNT_START 13                /* check gain every N frames */
+
+       u8 bridge;
+       u8 sensor;
+
+       u8 jpeg_hdr[JPEG_HDR_SZ];
+};
+
+enum bridges {
+       BRIDGE_TP6800,
+       BRIDGE_TP6810,
+};
+
+enum sensors {
+       SENSOR_CX0342,
+       SENSOR_SOI763A,         /* ~= ov7630 / ov7648 */
+       NSENSORS
+};
+
+static const struct v4l2_pix_format vga_mode[] = {
+       {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
+               .bytesperline = 320,
+               .sizeimage = 320 * 240 * 4 / 8 + 590,
+               .colorspace = V4L2_COLORSPACE_JPEG},
+       {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
+               .bytesperline = 640,
+               .sizeimage = 640 * 480 * 3 / 8 + 590,
+               .colorspace = V4L2_COLORSPACE_JPEG}
+};
+
+/*
+ * JPEG quality
+ * index: webcam compression
+ * value: JPEG quality in %
+ */
+static const u8 jpeg_q[17] = {
+       88, 77, 67, 57, 55, 55, 45, 45, 36, 36, 30, 30, 26, 26, 22, 22, 94
+};
+
+#define BULK_OUT_SIZE          0x20
+#if BULK_OUT_SIZE > USB_BUF_SZ
+#error "USB buffer too small"
+#endif
+
+static const u8 rates[] = {30, 20, 15, 10, 7, 5};
+static const struct framerates framerates[] = {
+       {
+               .rates = rates,
+               .nrates = ARRAY_SIZE(rates)
+       },
+       {
+               .rates = rates,
+               .nrates = ARRAY_SIZE(rates)
+       }
+};
+static const u8 rates_6810[] = {30, 15, 10, 7, 5};
+static const struct framerates framerates_6810[] = {
+       {
+               .rates = rates_6810,
+               .nrates = ARRAY_SIZE(rates_6810)
+       },
+       {
+               .rates = rates_6810,
+               .nrates = ARRAY_SIZE(rates_6810)
+       }
+};
+
+/*
+ * webcam quality in %
+ * the last value is the ultra fine quality
+ */
+
+/* TP6800 register offsets */
+#define TP6800_R10_SIF_TYPE            0x10
+#define TP6800_R11_SIF_CONTROL         0x11
+#define TP6800_R12_SIF_ADDR_S          0x12
+#define TP6800_R13_SIF_TX_DATA         0x13
+#define TP6800_R14_SIF_RX_DATA         0x14
+#define TP6800_R15_GPIO_PU             0x15
+#define TP6800_R16_GPIO_PD             0x16
+#define TP6800_R17_GPIO_IO             0x17
+#define TP6800_R18_GPIO_DATA           0x18
+#define TP6800_R19_SIF_ADDR_S2         0x19
+#define TP6800_R1A_SIF_TX_DATA2                0x1a
+#define TP6800_R1B_SIF_RX_DATA2                0x1b
+#define TP6800_R21_ENDP_1_CTL          0x21
+#define TP6800_R2F_TIMING_CFG          0x2f
+#define TP6800_R30_SENSOR_CFG          0x30
+#define TP6800_R31_PIXEL_START         0x31
+#define TP6800_R32_PIXEL_END_L         0x32
+#define TP6800_R33_PIXEL_END_H         0x33
+#define TP6800_R34_LINE_START          0x34
+#define TP6800_R35_LINE_END_L          0x35
+#define TP6800_R36_LINE_END_H          0x36
+#define TP6800_R37_FRONT_DARK_ST       0x37
+#define TP6800_R38_FRONT_DARK_END      0x38
+#define TP6800_R39_REAR_DARK_ST_L      0x39
+#define TP6800_R3A_REAR_DARK_ST_H      0x3a
+#define TP6800_R3B_REAR_DARK_END_L     0x3b
+#define TP6800_R3C_REAR_DARK_END_H     0x3c
+#define TP6800_R3D_HORIZ_DARK_LINE_L   0x3d
+#define TP6800_R3E_HORIZ_DARK_LINE_H   0x3e
+#define TP6800_R3F_FRAME_RATE          0x3f
+#define TP6800_R50                     0x50
+#define TP6800_R51                     0x51
+#define TP6800_R52                     0x52
+#define TP6800_R53                     0x53
+#define TP6800_R54_DARK_CFG            0x54
+#define TP6800_R55_GAMMA_R             0x55
+#define TP6800_R56_GAMMA_G             0x56
+#define TP6800_R57_GAMMA_B             0x57
+#define TP6800_R5C_EDGE_THRLD          0x5c
+#define TP6800_R5D_DEMOSAIC_CFG                0x5d
+#define TP6800_R78_FORMAT              0x78
+#define TP6800_R79_QUALITY             0x79
+#define TP6800_R7A_BLK_THRLD           0x7a
+
+/* CX0342 register offsets */
+
+#define CX0342_SENSOR_ID               0x00
+#define CX0342_VERSION_NO              0x01
+#define CX0342_ORG_X_L                 0x02
+#define CX0342_ORG_X_H                 0x03
+#define CX0342_ORG_Y_L                 0x04
+#define CX0342_ORG_Y_H                 0x05
+#define CX0342_STOP_X_L                        0x06
+#define CX0342_STOP_X_H                        0x07
+#define CX0342_STOP_Y_L                        0x08
+#define CX0342_STOP_Y_H                        0x09
+#define CX0342_FRAME_WIDTH_L           0x0a
+#define CX0342_FRAME_WIDTH_H           0x0b
+#define CX0342_FRAME_HEIGH_L           0x0c
+#define CX0342_FRAME_HEIGH_H           0x0d
+#define CX0342_EXPO_LINE_L             0x10
+#define CX0342_EXPO_LINE_H             0x11
+#define CX0342_EXPO_CLK_L              0x12
+#define CX0342_EXPO_CLK_H              0x13
+#define CX0342_RAW_GRGAIN_L            0x14
+#define CX0342_RAW_GRGAIN_H            0x15
+#define CX0342_RAW_GBGAIN_L            0x16
+#define CX0342_RAW_GBGAIN_H            0x17
+#define CX0342_RAW_RGAIN_L             0x18
+#define CX0342_RAW_RGAIN_H             0x19
+#define CX0342_RAW_BGAIN_L             0x1a
+#define CX0342_RAW_BGAIN_H             0x1b
+#define CX0342_GLOBAL_GAIN             0x1c
+#define CX0342_SYS_CTRL_0              0x20
+#define CX0342_SYS_CTRL_1              0x21
+#define CX0342_SYS_CTRL_2              0x22
+#define CX0342_BYPASS_MODE             0x23
+#define CX0342_SYS_CTRL_3              0x24
+#define CX0342_TIMING_EN               0x25
+#define CX0342_OUTPUT_CTRL             0x26
+#define CX0342_AUTO_ADC_CALIB          0x27
+#define CX0342_SYS_CTRL_4              0x28
+#define CX0342_ADCGN                   0x30
+#define CX0342_SLPCR                   0x31
+#define CX0342_SLPFN_LO                        0x32
+#define CX0342_ADC_CTL                 0x33
+#define CX0342_LVRST_BLBIAS            0x34
+#define CX0342_VTHSEL                  0x35
+#define CX0342_RAMP_RIV                        0x36
+#define CX0342_LDOSEL                  0x37
+#define CX0342_CLOCK_GEN               0x40
+#define CX0342_SOFT_RESET              0x41
+#define CX0342_PLL                     0x42
+#define CX0342_DR_ENH_PULSE_OFFSET_L   0x43
+#define CX0342_DR_ENH_PULSE_OFFSET_H   0x44
+#define CX0342_DR_ENH_PULSE_POS_L      0x45
+#define CX0342_DR_ENH_PULSE_POS_H      0x46
+#define CX0342_DR_ENH_PULSE_WIDTH      0x47
+#define CX0342_AS_CURRENT_CNT_L                0x48
+#define CX0342_AS_CURRENT_CNT_H                0x49
+#define CX0342_AS_PREVIOUS_CNT_L       0x4a
+#define CX0342_AS_PREVIOUS_CNT_H       0x4b
+#define CX0342_SPV_VALUE_L             0x4c
+#define CX0342_SPV_VALUE_H             0x4d
+#define CX0342_GPXLTHD_L               0x50
+#define CX0342_GPXLTHD_H               0x51
+#define CX0342_RBPXLTHD_L              0x52
+#define CX0342_RBPXLTHD_H              0x53
+#define CX0342_PLANETHD_L              0x54
+#define CX0342_PLANETHD_H              0x55
+#define CX0342_ROWDARK_TH              0x56
+#define CX0342_ROWDARK_TOL             0x57
+#define CX0342_RB_GAP_L                        0x58
+#define CX0342_RB_GAP_H                        0x59
+#define CX0342_G_GAP_L                 0x5a
+#define CX0342_G_GAP_H                 0x5b
+#define CX0342_AUTO_ROW_DARK           0x60
+#define CX0342_MANUAL_DARK_VALUE       0x61
+#define CX0342_GB_DARK_OFFSET          0x62
+#define CX0342_GR_DARK_OFFSET          0x63
+#define CX0342_RED_DARK_OFFSET         0x64
+#define CX0342_BLUE_DARK_OFFSET                0x65
+#define CX0342_DATA_SCALING_MULTI      0x66
+#define CX0342_AUTOD_Q_FRAME           0x67
+#define CX0342_AUTOD_ALLOW_VARI                0x68
+#define CX0342_AUTO_DARK_VALUE_L       0x69
+#define CX0342_AUTO_DARK_VALUE_H       0x6a
+#define CX0342_IO_CTRL_0               0x70
+#define CX0342_IO_CTRL_1               0x71
+#define CX0342_IO_CTRL_2               0x72
+#define CX0342_IDLE_CTRL               0x73
+#define CX0342_TEST_MODE               0x74
+#define CX0342_FRAME_FIX_DATA_TEST     0x75
+#define CX0342_FRAME_CNT_TEST          0x76
+#define CX0342_RST_OVERFLOW_L          0x80
+#define CX0342_RST_OVERFLOW_H          0x81
+#define CX0342_RST_UNDERFLOW_L         0x82
+#define CX0342_RST_UNDERFLOW_H         0x83
+#define CX0342_DATA_OVERFLOW_L         0x84
+#define CX0342_DATA_OVERFLOW_H         0x85
+#define CX0342_DATA_UNDERFLOW_L                0x86
+#define CX0342_DATA_UNDERFLOW_H                0x87
+#define CX0342_CHANNEL_0_0_L_irst      0x90
+#define CX0342_CHANNEL_0_0_H_irst      0x91
+#define CX0342_CHANNEL_0_1_L_irst      0x92
+#define CX0342_CHANNEL_0_1_H_irst      0x93
+#define CX0342_CHANNEL_0_2_L_irst      0x94
+#define CX0342_CHANNEL_0_2_H_irst      0x95
+#define CX0342_CHANNEL_0_3_L_irst      0x96
+#define CX0342_CHANNEL_0_3_H_irst      0x97
+#define CX0342_CHANNEL_0_4_L_irst      0x98
+#define CX0342_CHANNEL_0_4_H_irst      0x99
+#define CX0342_CHANNEL_0_5_L_irst      0x9a
+#define CX0342_CHANNEL_0_5_H_irst      0x9b
+#define CX0342_CHANNEL_0_6_L_irst      0x9c
+#define CX0342_CHANNEL_0_6_H_irst      0x9d
+#define CX0342_CHANNEL_0_7_L_irst      0x9e
+#define CX0342_CHANNEL_0_7_H_irst      0x9f
+#define CX0342_CHANNEL_1_0_L_itx       0xa0
+#define CX0342_CHANNEL_1_0_H_itx       0xa1
+#define CX0342_CHANNEL_1_1_L_itx       0xa2
+#define CX0342_CHANNEL_1_1_H_itx       0xa3
+#define CX0342_CHANNEL_1_2_L_itx       0xa4
+#define CX0342_CHANNEL_1_2_H_itx       0xa5
+#define CX0342_CHANNEL_1_3_L_itx       0xa6
+#define CX0342_CHANNEL_1_3_H_itx       0xa7
+#define CX0342_CHANNEL_1_4_L_itx       0xa8
+#define CX0342_CHANNEL_1_4_H_itx       0xa9
+#define CX0342_CHANNEL_1_5_L_itx       0xaa
+#define CX0342_CHANNEL_1_5_H_itx       0xab
+#define CX0342_CHANNEL_1_6_L_itx       0xac
+#define CX0342_CHANNEL_1_6_H_itx       0xad
+#define CX0342_CHANNEL_1_7_L_itx       0xae
+#define CX0342_CHANNEL_1_7_H_itx       0xaf
+#define CX0342_CHANNEL_2_0_L_iwl       0xb0
+#define CX0342_CHANNEL_2_0_H_iwl       0xb1
+#define CX0342_CHANNEL_2_1_L_iwl       0xb2
+#define CX0342_CHANNEL_2_1_H_iwl       0xb3
+#define CX0342_CHANNEL_2_2_L_iwl       0xb4
+#define CX0342_CHANNEL_2_2_H_iwl       0xb5
+#define CX0342_CHANNEL_2_3_L_iwl       0xb6
+#define CX0342_CHANNEL_2_3_H_iwl       0xb7
+#define CX0342_CHANNEL_2_4_L_iwl       0xb8
+#define CX0342_CHANNEL_2_4_H_iwl       0xb9
+#define CX0342_CHANNEL_2_5_L_iwl       0xba
+#define CX0342_CHANNEL_2_5_H_iwl       0xbb
+#define CX0342_CHANNEL_2_6_L_iwl       0xbc
+#define CX0342_CHANNEL_2_6_H_iwl       0xbd
+#define CX0342_CHANNEL_2_7_L_iwl       0xbe
+#define CX0342_CHANNEL_2_7_H_iwl       0xbf
+#define CX0342_CHANNEL_3_0_L_ensp      0xc0
+#define CX0342_CHANNEL_3_0_H_ensp      0xc1
+#define CX0342_CHANNEL_3_1_L_ensp      0xc2
+#define CX0342_CHANNEL_3_1_H_ensp      0xc3
+#define CX0342_CHANNEL_3_2_L_ensp      0xc4
+#define CX0342_CHANNEL_3_2_H_ensp      0xc5
+#define CX0342_CHANNEL_3_3_L_ensp      0xc6
+#define CX0342_CHANNEL_3_3_H_ensp      0xc7
+#define CX0342_CHANNEL_3_4_L_ensp      0xc8
+#define CX0342_CHANNEL_3_4_H_ensp      0xc9
+#define CX0342_CHANNEL_3_5_L_ensp      0xca
+#define CX0342_CHANNEL_3_5_H_ensp      0xcb
+#define CX0342_CHANNEL_3_6_L_ensp      0xcc
+#define CX0342_CHANNEL_3_6_H_ensp      0xcd
+#define CX0342_CHANNEL_3_7_L_ensp      0xce
+#define CX0342_CHANNEL_3_7_H_ensp      0xcf
+#define CX0342_CHANNEL_4_0_L_sela      0xd0
+#define CX0342_CHANNEL_4_0_H_sela      0xd1
+#define CX0342_CHANNEL_4_1_L_sela      0xd2
+#define CX0342_CHANNEL_4_1_H_sela      0xd3
+#define CX0342_CHANNEL_5_0_L_intla     0xe0
+#define CX0342_CHANNEL_5_0_H_intla     0xe1
+#define CX0342_CHANNEL_5_1_L_intla     0xe2
+#define CX0342_CHANNEL_5_1_H_intla     0xe3
+#define CX0342_CHANNEL_5_2_L_intla     0xe4
+#define CX0342_CHANNEL_5_2_H_intla     0xe5
+#define CX0342_CHANNEL_5_3_L_intla     0xe6
+#define CX0342_CHANNEL_5_3_H_intla     0xe7
+#define CX0342_CHANNEL_6_0_L_xa_sel_pos 0xf0
+#define CX0342_CHANNEL_6_0_H_xa_sel_pos 0xf1
+#define CX0342_CHANNEL_7_1_L_cds_pos   0xf2
+#define CX0342_CHANNEL_7_1_H_cds_pos   0xf3
+#define CX0342_SENSOR_HEIGHT_L         0xfb
+#define CX0342_SENSOR_HEIGHT_H         0xfc
+#define CX0342_SENSOR_WIDTH_L          0xfd
+#define CX0342_SENSOR_WIDTH_H          0xfe
+#define CX0342_VSYNC_HSYNC_READ                0xff
+
+struct cmd {
+       u8 reg;
+       u8 val;
+};
+
+static const u8 DQT[17][130] = {
+       /* Define quantization table (thanks to Thomas Kaiser) */
+       {                       /* Quality 0 */
+        0x00,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x01,
+        0x04, 0x04, 0x04, 0x06, 0x05, 0x06, 0x0b, 0x06,
+        0x06, 0x0b, 0x18, 0x10, 0x0e, 0x10, 0x18, 0x18,
+        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+        },
+       {                       /* Quality 1 */
+        0x00,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x04, 0x04, 0x04, 0x09, 0x09, 0x09, 0x09, 0x09,
+        0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,
+        0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,
+        0x01,
+        0x08, 0x09, 0x09, 0x0c, 0x0a, 0x0c, 0x17, 0x0d,
+        0x0d, 0x17, 0x31, 0x21, 0x1c, 0x21, 0x31, 0x31,
+        0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31,
+        0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31,
+        0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31,
+        0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31,
+        0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31,
+        0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31,
+        },
+       {                       /* Quality 2 */
+        0x00,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x04, 0x04, 0x06, 0x06, 0x06, 0x04, 0x04, 0x04,
+        0x04, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
+        0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
+        0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
+        0x06, 0x06, 0x06, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e,
+        0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e,
+        0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e,
+        0x01,
+        0x0c, 0x0d, 0x0d, 0x12, 0x0f, 0x12, 0x23, 0x13,
+        0x13, 0x23, 0x4a, 0x31, 0x2a, 0x31, 0x4a, 0x4a,
+        0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a,
+        0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a,
+        0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a,
+        0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a,
+        0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a,
+        0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a,
+        },
+       {                       /* Quality 3 */
+        0x00,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x04, 0x04, 0x08, 0x08, 0x08, 0x04, 0x04, 0x04,
+        0x04, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
+        0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
+        0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
+        0x08, 0x08, 0x08, 0x13, 0x13, 0x13, 0x13, 0x13,
+        0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
+        0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
+        0x01,
+        0x11, 0x12, 0x12, 0x18, 0x15, 0x18, 0x2f, 0x1a,
+        0x1a, 0x2f, 0x63, 0x42, 0x38, 0x42, 0x63, 0x63,
+        0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+        0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+        0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+        0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+        0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+        0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+        },
+       {                       /* Quality 4 */
+        0x00,
+        0x04, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
+        0x05, 0x05, 0x0a, 0x0a, 0x0a, 0x05, 0x05, 0x05,
+        0x05, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
+        0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
+        0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
+        0x0a, 0x0a, 0x0a, 0x17, 0x17, 0x17, 0x17, 0x17,
+        0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17,
+        0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17,
+        0x01,
+        0x11, 0x16, 0x16, 0x1e, 0x1a, 0x1e, 0x3a, 0x20,
+        0x20, 0x3a, 0x7b, 0x52, 0x46, 0x52, 0x7b, 0x7b,
+        0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b,
+        0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b,
+        0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b,
+        0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b,
+        0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b,
+        0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b,
+        },
+       {                       /* Quality 5 */
+        0x00,
+        0x04, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
+        0x06, 0x06, 0x0c, 0x0c, 0x0c, 0x06, 0x06, 0x06,
+        0x06, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
+        0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
+        0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
+        0x0c, 0x0c, 0x0c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c,
+        0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c,
+        0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c,
+        0x01,
+        0x11, 0x1b, 0x1b, 0x24, 0x1f, 0x24, 0x46, 0x27,
+        0x27, 0x46, 0x94, 0x63, 0x54, 0x63, 0x94, 0x94,
+        0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94,
+        0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94,
+        0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94,
+        0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94,
+        0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94,
+        0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94,
+        },
+       {                       /* Quality 6 */
+        0x00,
+        0x05, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
+        0x07, 0x07, 0x0e, 0x0e, 0x0e, 0x07, 0x07, 0x07,
+        0x07, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e,
+        0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e,
+        0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e,
+        0x0e, 0x0e, 0x0e, 0x21, 0x21, 0x21, 0x21, 0x21,
+        0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21,
+        0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21,
+        0x01,
+        0x15, 0x1f, 0x1f, 0x2a, 0x24, 0x2a, 0x52, 0x2d,
+        0x2d, 0x52, 0xad, 0x73, 0x62, 0x73, 0xad, 0xad,
+        0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad,
+        0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad,
+        0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad,
+        0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad,
+        0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad,
+        0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad,
+        },
+       {                       /* Quality 7 */
+        0x00,
+        0x05, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
+        0x08, 0x08, 0x10, 0x10, 0x10, 0x08, 0x08, 0x08,
+        0x08, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
+        0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
+        0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
+        0x10, 0x10, 0x10, 0x26, 0x26, 0x26, 0x26, 0x26,
+        0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26,
+        0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26,
+        0x01,
+        0x15, 0x24, 0x24, 0x30, 0x2a, 0x30, 0x5e, 0x34,
+        0x34, 0x5e, 0xc6, 0x84, 0x70, 0x84, 0xc6, 0xc6,
+        0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
+        0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
+        0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
+        0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
+        0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
+        0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
+        },
+       {                       /* Quality 8 */
+        0x00,
+        0x06, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
+        0x0a, 0x0a, 0x14, 0x14, 0x14, 0x0a, 0x0a, 0x0a,
+        0x0a, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
+        0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
+        0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
+        0x14, 0x14, 0x14, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f,
+        0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f,
+        0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f,
+        0x01,
+        0x19, 0x2d, 0x2d, 0x3c, 0x34, 0x3c, 0x75, 0x41,
+        0x41, 0x75, 0xf7, 0xa5, 0x8c, 0xa5, 0xf7, 0xf7,
+        0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7,
+        0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7,
+        0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7,
+        0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7,
+        0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7,
+        0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7,
+        },
+       {                       /* Quality 9 */
+        0x00,
+        0x06, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
+        0x0c, 0x0c, 0x18, 0x18, 0x18, 0x0c, 0x0c, 0x0c,
+        0x0c, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+        0x18, 0x18, 0x18, 0x39, 0x39, 0x39, 0x39, 0x39,
+        0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39,
+        0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39,
+        0x01,
+        0x19, 0x36, 0x36, 0x48, 0x3f, 0x48, 0x8d, 0x4e,
+        0x4e, 0x8d, 0xff, 0xc6, 0xa8, 0xc6, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        },
+       {                       /* Quality 10 */
+        0x00,
+        0x07, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e,
+        0x0e, 0x0e, 0x1c, 0x1c, 0x1c, 0x0e, 0x0e, 0x0e,
+        0x0e, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c,
+        0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c,
+        0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c,
+        0x1c, 0x1c, 0x1c, 0x42, 0x42, 0x42, 0x42, 0x42,
+        0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
+        0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
+        0x01,
+        0x1d, 0x3f, 0x3f, 0x54, 0x49, 0x54, 0xa4, 0x5b,
+        0x5b, 0xa4, 0xff, 0xe7, 0xc4, 0xe7, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        },
+       {                       /* Quality 11 */
+        0x00,
+        0x07, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
+        0x10, 0x10, 0x20, 0x20, 0x20, 0x10, 0x10, 0x10,
+        0x10, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+        0x20, 0x20, 0x20, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,
+        0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,
+        0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,
+        0x01,
+        0x1d, 0x48, 0x48, 0x60, 0x54, 0x60, 0xbc, 0x68,
+        0x68, 0xbc, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        },
+       {                       /* Quality 12 */
+        0x00,
+        0x08, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
+        0x14, 0x14, 0x28, 0x28, 0x28, 0x14, 0x14, 0x14,
+        0x14, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
+        0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
+        0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
+        0x28, 0x28, 0x28, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f,
+        0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f,
+        0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f,
+        0x01,
+        0x22, 0x5a, 0x5a, 0x78, 0x69, 0x78, 0xeb, 0x82,
+        0x82, 0xeb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        },
+       {                       /* Quality 13 */
+        0x00,
+        0x08, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+        0x18, 0x18, 0x30, 0x30, 0x30, 0x18, 0x18, 0x18,
+        0x18, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
+        0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
+        0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
+        0x30, 0x30, 0x30, 0x72, 0x72, 0x72, 0x72, 0x72,
+        0x72, 0x72, 0x72, 0x72, 0x72, 0x72, 0x72, 0x72,
+        0x72, 0x72, 0x72, 0x72, 0x72, 0x72, 0x72, 0x72,
+        0x01,
+        0x22, 0x6c, 0x6c, 0x90, 0x7e, 0x90, 0xff, 0x9c,
+        0x9c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        },
+       {                       /* Quality 14 */
+        0x00,
+        0x0a, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c,
+        0x1c, 0x1c, 0x38, 0x38, 0x38, 0x1c, 0x1c, 0x1c,
+        0x1c, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38,
+        0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38,
+        0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38,
+        0x38, 0x38, 0x38, 0x85, 0x85, 0x85, 0x85, 0x85,
+        0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85,
+        0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85,
+        0x01,
+        0x2a, 0x7e, 0x7e, 0xa8, 0x93, 0xa8, 0xff, 0xb6,
+        0xb6, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        },
+       {                       /* Quality 15 */
+        0x00,
+        0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+        0x20, 0x20, 0x40, 0x40, 0x40, 0x20, 0x20, 0x20,
+        0x20, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+        0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+        0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+        0x40, 0x40, 0x40, 0x98, 0x98, 0x98, 0x98, 0x98,
+        0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98,
+        0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98,
+        0x01,
+        0x2a, 0x90, 0x90, 0xc0, 0xa8, 0xc0, 0xff, 0xd0,
+        0xd0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        },
+       {                       /* Quality 16-31 */
+        0x00,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x01,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+        }
+};
+
+static const struct cmd tp6810_cx_init_common[] = {
+       {0x1c, 0x00},
+       {TP6800_R10_SIF_TYPE, 0x00},
+       {0x4e, 0x00},
+       {0x4f, 0x00},
+       {TP6800_R50, 0xff},
+       {TP6800_R51, 0x03},
+       {0x00, 0x07},
+       {TP6800_R79_QUALITY, 0x03},
+       {TP6800_R2F_TIMING_CFG, 0x37},
+       {TP6800_R30_SENSOR_CFG, 0x10},
+       {TP6800_R21_ENDP_1_CTL, 0x00},
+       {TP6800_R52, 0x40},
+       {TP6800_R53, 0x40},
+       {TP6800_R54_DARK_CFG, 0x40},
+       {TP6800_R30_SENSOR_CFG, 0x18},
+       {0x4b, 0x00},
+       {TP6800_R3F_FRAME_RATE, 0x83},
+       {TP6800_R79_QUALITY, 0x05},
+       {TP6800_R21_ENDP_1_CTL, 0x00},
+       {0x7c, 0x04},
+       {0x25, 0x14},
+       {0x26, 0x0f},
+       {0x7b, 0x10},
+};
+
+static const struct cmd tp6810_ov_init_common[] = {
+       {0x1c, 0x00},
+       {TP6800_R10_SIF_TYPE, 0x00},
+       {0x4e, 0x00},
+       {0x4f, 0x00},
+       {TP6800_R50, 0xff},
+       {TP6800_R51, 0x03},
+       {0x00, 0x07},
+       {TP6800_R52, 0x40},
+       {TP6800_R53, 0x40},
+       {TP6800_R54_DARK_CFG, 0x40},
+       {TP6800_R79_QUALITY, 0x03},
+       {TP6800_R2F_TIMING_CFG, 0x17},
+       {TP6800_R30_SENSOR_CFG, 0x18},
+       {TP6800_R21_ENDP_1_CTL, 0x00},
+       {TP6800_R3F_FRAME_RATE, 0x86},
+       {0x25, 0x18},
+       {0x26, 0x0f},
+       {0x7b, 0x90},
+};
+
+static const struct cmd tp6810_bridge_start[] = {
+       {0x59, 0x88},
+       {0x5a, 0x0f},
+       {0x5b, 0x4e},
+       {TP6800_R5C_EDGE_THRLD, 0x63},
+       {TP6800_R5D_DEMOSAIC_CFG, 0x00},
+       {0x03, 0x7f},
+       {0x04, 0x80},
+       {0x06, 0x00},
+       {0x00, 0x00},
+};
+
+static const struct cmd tp6810_late_start[] = {
+       {0x7d, 0x01},
+       {0xb0, 0x04},
+       {0xb1, 0x04},
+       {0xb2, 0x04},
+       {0xb3, 0x04},
+       {0xb4, 0x04},
+       {0xb5, 0x04},
+       {0xb6, 0x08},
+       {0xb7, 0x08},
+       {0xb8, 0x04},
+       {0xb9, 0x04},
+       {0xba, 0x04},
+       {0xbb, 0x04},
+       {0xbc, 0x04},
+       {0xbd, 0x08},
+       {0xbe, 0x08},
+       {0xbf, 0x08},
+       {0xc0, 0x04},
+       {0xc1, 0x04},
+       {0xc2, 0x08},
+       {0xc3, 0x08},
+       {0xc4, 0x08},
+       {0xc5, 0x08},
+       {0xc6, 0x08},
+       {0xc7, 0x13},
+       {0xc8, 0x04},
+       {0xc9, 0x08},
+       {0xca, 0x08},
+       {0xcb, 0x08},
+       {0xcc, 0x08},
+       {0xcd, 0x08},
+       {0xce, 0x13},
+       {0xcf, 0x13},
+       {0xd0, 0x08},
+       {0xd1, 0x08},
+       {0xd2, 0x08},
+       {0xd3, 0x08},
+       {0xd4, 0x08},
+       {0xd5, 0x13},
+       {0xd6, 0x13},
+       {0xd7, 0x13},
+       {0xd8, 0x08},
+       {0xd9, 0x08},
+       {0xda, 0x08},
+       {0xdb, 0x08},
+       {0xdc, 0x13},
+       {0xdd, 0x13},
+       {0xde, 0x13},
+       {0xdf, 0x13},
+       {0xe0, 0x08},
+       {0xe1, 0x08},
+       {0xe2, 0x08},
+       {0xe3, 0x13},
+       {0xe4, 0x13},
+       {0xe5, 0x13},
+       {0xe6, 0x13},
+       {0xe7, 0x13},
+       {0xe8, 0x08},
+       {0xe9, 0x08},
+       {0xea, 0x13},
+       {0xeb, 0x13},
+       {0xec, 0x13},
+       {0xed, 0x13},
+       {0xee, 0x13},
+       {0xef, 0x13},
+       {0x7d, 0x02},
+
+       /* later after isoc start */
+       {0x7d, 0x08},
+       {0x7d, 0x00},
+};
+
+static const struct cmd cx0342_timing_seq[] = {
+       {CX0342_CHANNEL_0_1_L_irst, 0x20},
+       {CX0342_CHANNEL_0_2_L_irst, 0x24},
+       {CX0342_CHANNEL_0_2_H_irst, 0x00},
+       {CX0342_CHANNEL_0_3_L_irst, 0x2f},
+       {CX0342_CHANNEL_0_3_H_irst, 0x00},
+       {CX0342_CHANNEL_1_0_L_itx, 0x02},
+       {CX0342_CHANNEL_1_0_H_itx, 0x00},
+       {CX0342_CHANNEL_1_1_L_itx, 0x20},
+       {CX0342_CHANNEL_1_1_H_itx, 0x00},
+       {CX0342_CHANNEL_1_2_L_itx, 0xe4},
+       {CX0342_CHANNEL_1_2_H_itx, 0x00},
+       {CX0342_CHANNEL_1_3_L_itx, 0xee},
+       {CX0342_CHANNEL_1_3_H_itx, 0x00},
+       {CX0342_CHANNEL_2_0_L_iwl, 0x30},
+       {CX0342_CHANNEL_2_0_H_iwl, 0x00},
+       {CX0342_CHANNEL_3_0_L_ensp, 0x34},
+       {CX0342_CHANNEL_3_1_L_ensp, 0xe2},
+       {CX0342_CHANNEL_3_1_H_ensp, 0x00},
+       {CX0342_CHANNEL_3_2_L_ensp, 0xf6},
+       {CX0342_CHANNEL_3_2_H_ensp, 0x00},
+       {CX0342_CHANNEL_3_3_L_ensp, 0xf4},
+       {CX0342_CHANNEL_3_3_H_ensp, 0x02},
+       {CX0342_CHANNEL_4_0_L_sela, 0x26},
+       {CX0342_CHANNEL_4_0_H_sela, 0x00},
+       {CX0342_CHANNEL_4_1_L_sela, 0xe2},
+       {CX0342_CHANNEL_4_1_H_sela, 0x00},
+       {CX0342_CHANNEL_5_0_L_intla, 0x26},
+       {CX0342_CHANNEL_5_1_L_intla, 0x29},
+       {CX0342_CHANNEL_5_2_L_intla, 0xf0},
+       {CX0342_CHANNEL_5_2_H_intla, 0x00},
+       {CX0342_CHANNEL_5_3_L_intla, 0xf3},
+       {CX0342_CHANNEL_5_3_H_intla, 0x00},
+       {CX0342_CHANNEL_6_0_L_xa_sel_pos, 0x24},
+       {CX0342_CHANNEL_7_1_L_cds_pos, 0x02},
+       {CX0342_TIMING_EN, 0x01},
+};
+
+/* define the JPEG header */
+static void jpeg_define(u8 *jpeg_hdr,
+                       int height,
+                       int width)
+{
+       memcpy(jpeg_hdr, jpeg_head, sizeof jpeg_head);
+       jpeg_hdr[JPEG_HEIGHT_OFFSET + 0] = height >> 8;
+       jpeg_hdr[JPEG_HEIGHT_OFFSET + 1] = height;
+       jpeg_hdr[JPEG_HEIGHT_OFFSET + 2] = width >> 8;
+       jpeg_hdr[JPEG_HEIGHT_OFFSET + 3] = width;
+}
+
+/* set the JPEG quality for sensor soi763a */
+static void jpeg_set_qual(u8 *jpeg_hdr,
+                         int quality)
+{
+       int i, sc;
+
+       if (quality < 50)
+               sc = 5000 / quality;
+       else
+               sc = 200 - quality * 2;
+       for (i = 0; i < 64; i++) {
+               jpeg_hdr[JPEG_QT0_OFFSET + i] =
+                       (jpeg_head[JPEG_QT0_OFFSET + i] * sc + 50) / 100;
+               jpeg_hdr[JPEG_QT1_OFFSET + i] =
+                       (jpeg_head[JPEG_QT1_OFFSET + i] * sc + 50) / 100;
+       }
+}
+
+static void reg_w(struct gspca_dev *gspca_dev, u8 index, u8 value)
+{
+       struct usb_device *dev = gspca_dev->dev;
+       int ret;
+
+       if (gspca_dev->usb_err < 0)
+               return;
+       ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
+                       0x0e,
+                       USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+                       value, index, NULL, 0, 500);
+       if (ret < 0) {
+               pr_err("reg_w err %d\n", ret);
+               gspca_dev->usb_err = ret;
+       }
+}
+
+/* the returned value is in gspca_dev->usb_buf */
+static void reg_r(struct gspca_dev *gspca_dev, u8 index)
+{
+       struct usb_device *dev = gspca_dev->dev;
+       int ret;
+
+       if (gspca_dev->usb_err < 0)
+               return;
+       ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
+                       0x0d,
+                       USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+                       0, index, gspca_dev->usb_buf, 1, 500);
+       if (ret < 0) {
+               pr_err("reg_r err %d\n", ret);
+               gspca_dev->usb_err = ret;
+       }
+}
+
+static void reg_w_buf(struct gspca_dev *gspca_dev,
+                       const struct cmd *p, int l)
+{
+       do {
+               reg_w(gspca_dev, p->reg, p->val);
+               p++;
+       } while (--l > 0);
+}
+
+static int i2c_w(struct gspca_dev *gspca_dev, u8 index, u8 value)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       reg_w(gspca_dev, TP6800_R11_SIF_CONTROL, 0x00);
+       reg_w(gspca_dev, TP6800_R19_SIF_ADDR_S2, index);
+       reg_w(gspca_dev, TP6800_R13_SIF_TX_DATA, value);
+       reg_w(gspca_dev, TP6800_R11_SIF_CONTROL, 0x01);
+       if (sd->bridge == BRIDGE_TP6800)
+               return 0;
+       msleep(5);
+       reg_r(gspca_dev, TP6800_R11_SIF_CONTROL);
+       if (gspca_dev->usb_buf[0] == 0)
+               return 0;
+       reg_w(gspca_dev, TP6800_R11_SIF_CONTROL, 0x00);
+       return -1;                              /* error */
+}
+
+static void i2c_w_buf(struct gspca_dev *gspca_dev,
+                       const struct cmd *p, int l)
+{
+       do {
+               i2c_w(gspca_dev, p->reg, p->val);
+               p++;
+       } while (--l > 0);
+}
+
+static int i2c_r(struct gspca_dev *gspca_dev, u8 index, int len)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       int v;
+
+       reg_w(gspca_dev, TP6800_R19_SIF_ADDR_S2, index);
+       reg_w(gspca_dev, TP6800_R11_SIF_CONTROL, 0x02);
+       msleep(5);
+       reg_r(gspca_dev, TP6800_R14_SIF_RX_DATA);
+       v = gspca_dev->usb_buf[0];
+       if (sd->bridge == BRIDGE_TP6800)
+               return v;
+       if (len > 1) {
+               reg_r(gspca_dev, TP6800_R1B_SIF_RX_DATA2);
+               v |= (gspca_dev->usb_buf[0] << 8);
+       }
+       reg_r(gspca_dev, TP6800_R11_SIF_CONTROL);
+       if (gspca_dev->usb_buf[0] == 0)
+               return v;
+       reg_w(gspca_dev, TP6800_R11_SIF_CONTROL, 0x00);
+       return -1;
+}
+
+static void bulk_w(struct gspca_dev *gspca_dev,
+                 u8 tag,
+                 const u8 *data,
+                 int length)
+{
+       struct usb_device *dev = gspca_dev->dev;
+       int count, actual_count, ret;
+
+       if (gspca_dev->usb_err < 0)
+               return;
+       for (;;) {
+               count = length > BULK_OUT_SIZE - 1
+                               ? BULK_OUT_SIZE - 1 : length;
+               gspca_dev->usb_buf[0] = tag;
+               memcpy(&gspca_dev->usb_buf[1], data, count);
+               ret = usb_bulk_msg(dev,
+                                  usb_sndbulkpipe(dev, 3),
+                                  gspca_dev->usb_buf, count + 1,
+                                  &actual_count, 500);
+               if (ret < 0) {
+                       pr_err("bulk write error %d tag=%02x\n",
+                               ret, tag);
+                       gspca_dev->usb_err = ret;
+                       return;
+               }
+               length -= count;
+               if (length <= 0)
+                       break;
+               data += count;
+       }
+}
+
+static int probe_6810(struct gspca_dev *gspca_dev)
+{
+       u8 gpio;
+       int ret;
+
+       reg_r(gspca_dev, TP6800_R18_GPIO_DATA);
+       gpio = gspca_dev->usb_buf[0];
+       reg_w(gspca_dev, TP6800_R18_GPIO_DATA, gpio);
+       reg_w(gspca_dev, TP6800_R18_GPIO_DATA, gpio | 0x20);
+       reg_w(gspca_dev, TP6800_R18_GPIO_DATA, gpio);
+       reg_w(gspca_dev, TP6800_R10_SIF_TYPE, 0x04);    /* i2c 16 bits */
+       reg_w(gspca_dev, TP6800_R12_SIF_ADDR_S, 0x21);  /* ov??? */
+       reg_w(gspca_dev, TP6800_R1A_SIF_TX_DATA2, 0x00);
+       if (i2c_w(gspca_dev, 0x00, 0x00) >= 0)
+               return SENSOR_SOI763A;
+
+       reg_w(gspca_dev, TP6800_R18_GPIO_DATA, gpio | 0x20);
+       reg_w(gspca_dev, TP6800_R10_SIF_TYPE, 0x00);    /* i2c 8 bits */
+       reg_w(gspca_dev, TP6800_R12_SIF_ADDR_S, 0x7f);  /* (unknown i2c) */
+       if (i2c_w(gspca_dev, 0x00, 0x00) >= 0)
+               return -2;
+
+       reg_w(gspca_dev, TP6800_R18_GPIO_DATA, gpio | 0x20);
+       reg_w(gspca_dev, TP6800_R18_GPIO_DATA, gpio);
+       reg_w(gspca_dev, TP6800_R18_GPIO_DATA, gpio | 0x20);
+       reg_w(gspca_dev, TP6800_R10_SIF_TYPE, 0x00);    /* i2c 8 bits */
+       reg_w(gspca_dev, TP6800_R12_SIF_ADDR_S, 0x11);  /* tas??? / hv??? */
+       ret = i2c_r(gspca_dev, 0x00, 1);
+       if (ret > 0)
+               return -3;
+
+       reg_w(gspca_dev, TP6800_R18_GPIO_DATA, gpio | 0x20);
+       reg_w(gspca_dev, TP6800_R18_GPIO_DATA, gpio);
+       reg_w(gspca_dev, TP6800_R18_GPIO_DATA, gpio | 0x20);
+       reg_w(gspca_dev, TP6800_R12_SIF_ADDR_S, 0x6e);  /* po??? */
+       ret = i2c_r(gspca_dev, 0x00, 1);
+       if (ret > 0)
+               return -4;
+
+       ret = i2c_r(gspca_dev, 0x01, 1);
+       if (ret > 0)
+               return -5;
+
+       reg_w(gspca_dev, TP6800_R18_GPIO_DATA, gpio | 0x20);
+       reg_w(gspca_dev, TP6800_R18_GPIO_DATA, gpio);
+       reg_w(gspca_dev, TP6800_R18_GPIO_DATA, gpio | 0x20);
+       reg_w(gspca_dev, TP6800_R10_SIF_TYPE, 0x04);    /* i2c 16 bits */
+       reg_w(gspca_dev, TP6800_R12_SIF_ADDR_S, 0x5d);  /* mi/mt??? */
+       ret = i2c_r(gspca_dev, 0x00, 2);
+       if (ret > 0)
+               return -6;
+
+       reg_w(gspca_dev, TP6800_R18_GPIO_DATA, gpio | 0x20);
+       reg_w(gspca_dev, TP6800_R18_GPIO_DATA, gpio);
+       reg_w(gspca_dev, TP6800_R18_GPIO_DATA, gpio | 0x20);
+       reg_w(gspca_dev, TP6800_R12_SIF_ADDR_S, 0x5c);  /* mi/mt??? */
+       ret = i2c_r(gspca_dev, 0x36, 2);
+       if (ret > 0)
+               return -7;
+
+       reg_w(gspca_dev, TP6800_R18_GPIO_DATA, gpio);
+       reg_w(gspca_dev, TP6800_R18_GPIO_DATA, gpio | 0x20);
+       reg_w(gspca_dev, TP6800_R18_GPIO_DATA, gpio);
+       reg_w(gspca_dev, TP6800_R12_SIF_ADDR_S, 0x61);  /* (unknown i2c) */
+       reg_w(gspca_dev, TP6800_R1A_SIF_TX_DATA2, 0x10);
+       if (i2c_w(gspca_dev, 0xff, 0x00) >= 0)
+               return -8;
+
+       reg_w(gspca_dev, TP6800_R18_GPIO_DATA, gpio | 0x20);
+       reg_w(gspca_dev, TP6800_R18_GPIO_DATA, gpio);
+       reg_w(gspca_dev, TP6800_R18_GPIO_DATA, gpio | 0x20);
+       reg_w(gspca_dev, TP6800_R10_SIF_TYPE, 0x00);    /* i2c 8 bits */
+       reg_w(gspca_dev, TP6800_R12_SIF_ADDR_S, 0x20);  /* cx0342 */
+       ret = i2c_r(gspca_dev, 0x00, 1);
+       if (ret > 0)
+               return SENSOR_CX0342;
+       return -9;
+}
+
+static void cx0342_6810_init(struct gspca_dev *gspca_dev)
+{
+       static const struct cmd reg_init_1[] = {
+               {TP6800_R2F_TIMING_CFG, 0x2f},
+               {0x25, 0x02},
+               {TP6800_R21_ENDP_1_CTL, 0x00},
+               {TP6800_R3F_FRAME_RATE, 0x80},
+               {TP6800_R2F_TIMING_CFG, 0x2f},
+               {TP6800_R18_GPIO_DATA, 0xe1},
+               {TP6800_R18_GPIO_DATA, 0xc1},
+               {TP6800_R18_GPIO_DATA, 0xe1},
+               {TP6800_R11_SIF_CONTROL, 0x00},
+       };
+       static const struct cmd reg_init_2[] = {
+               {TP6800_R78_FORMAT, 0x48},
+               {TP6800_R11_SIF_CONTROL, 0x00},
+       };
+       static const struct cmd sensor_init[] = {
+               {CX0342_OUTPUT_CTRL, 0x07},
+               {CX0342_BYPASS_MODE, 0x58},
+               {CX0342_GPXLTHD_L, 0x28},
+               {CX0342_RBPXLTHD_L, 0x28},
+               {CX0342_PLANETHD_L, 0x50},
+               {CX0342_PLANETHD_H, 0x03},
+               {CX0342_RB_GAP_L, 0xff},
+               {CX0342_RB_GAP_H, 0x07},
+               {CX0342_G_GAP_L, 0xff},
+               {CX0342_G_GAP_H, 0x07},
+               {CX0342_RST_OVERFLOW_L, 0x5c},
+               {CX0342_RST_OVERFLOW_H, 0x01},
+               {CX0342_DATA_OVERFLOW_L, 0xfc},
+               {CX0342_DATA_OVERFLOW_H, 0x03},
+               {CX0342_DATA_UNDERFLOW_L, 0x00},
+               {CX0342_DATA_UNDERFLOW_H, 0x00},
+               {CX0342_SYS_CTRL_0, 0x40},
+               {CX0342_GLOBAL_GAIN, 0x01},
+               {CX0342_CLOCK_GEN, 0x00},
+               {CX0342_SYS_CTRL_0, 0x02},
+               {CX0342_IDLE_CTRL, 0x05},
+               {CX0342_ADCGN, 0x00},
+               {CX0342_ADC_CTL, 0x00},
+               {CX0342_LVRST_BLBIAS, 0x01},
+               {CX0342_VTHSEL, 0x0b},
+               {CX0342_RAMP_RIV, 0x0b},
+               {CX0342_LDOSEL, 0x07},
+               {CX0342_SPV_VALUE_L, 0x40},
+               {CX0342_SPV_VALUE_H, 0x02},
+
+               {CX0342_AUTO_ADC_CALIB, 0x81},
+               {CX0342_TIMING_EN, 0x01},
+       };
+
+       reg_w_buf(gspca_dev, reg_init_1, ARRAY_SIZE(reg_init_1));
+       reg_w_buf(gspca_dev, tp6810_cx_init_common,
+                       ARRAY_SIZE(tp6810_cx_init_common));
+       reg_w_buf(gspca_dev, reg_init_2, ARRAY_SIZE(reg_init_2));
+
+       reg_w(gspca_dev, TP6800_R12_SIF_ADDR_S, 0x20);  /* cx0342 I2C addr */
+       i2c_w_buf(gspca_dev, sensor_init, ARRAY_SIZE(sensor_init));
+       i2c_w_buf(gspca_dev, cx0342_timing_seq, ARRAY_SIZE(cx0342_timing_seq));
+}
+
+static void soi763a_6810_init(struct gspca_dev *gspca_dev)
+{
+       static const struct cmd reg_init_1[] = {
+               {TP6800_R2F_TIMING_CFG, 0x2f},
+               {TP6800_R18_GPIO_DATA, 0xe1},
+               {0x25, 0x02},
+               {TP6800_R21_ENDP_1_CTL, 0x00},
+               {TP6800_R3F_FRAME_RATE, 0x80},
+               {TP6800_R2F_TIMING_CFG, 0x2f},
+               {TP6800_R18_GPIO_DATA, 0xc1},
+       };
+       static const struct cmd reg_init_2[] = {
+               {TP6800_R78_FORMAT, 0x54},
+       };
+       static const struct cmd sensor_init[] = {
+               {0x00, 0x00},
+               {0x01, 0x80},
+               {0x02, 0x80},
+               {0x03, 0x90},
+               {0x04, 0x20},
+               {0x05, 0x20},
+               {0x06, 0x80},
+               {0x07, 0x00},
+               {0x08, 0xff},
+               {0x09, 0xff},
+               {0x0a, 0x76},           /* 7630 = soi673a */
+               {0x0b, 0x30},
+               {0x0c, 0x20},
+               {0x0d, 0x20},
+               {0x0e, 0xff},
+               {0x0f, 0xff},
+               {0x10, 0x41},
+               {0x15, 0x14},
+               {0x11, 0x40},
+               {0x12, 0x48},
+               {0x13, 0x80},
+               {0x14, 0x80},
+               {0x16, 0x03},
+               {0x28, 0xb0},
+               {0x71, 0x20},
+               {0x75, 0x8e},
+               {0x17, 0x1b},
+               {0x18, 0xbd},
+               {0x19, 0x05},
+               {0x1a, 0xf6},
+               {0x1b, 0x04},
+               {0x1c, 0x7f},           /* omnivision */
+               {0x1d, 0xa2},
+               {0x1e, 0x00},
+               {0x1f, 0x00},
+               {0x20, 0x45},
+               {0x21, 0x80},
+               {0x22, 0x80},
+               {0x23, 0xee},
+               {0x24, 0x50},
+               {0x25, 0x7a},
+               {0x26, 0xa0},
+               {0x27, 0x9a},
+               {0x29, 0x30},
+               {0x2a, 0x80},
+               {0x2b, 0x00},
+               {0x2c, 0xac},
+               {0x2d, 0x05},
+               {0x2e, 0x80},
+               {0x2f, 0x3c},
+               {0x30, 0x22},
+               {0x31, 0x00},
+               {0x32, 0x86},
+               {0x33, 0x08},
+               {0x34, 0xff},
+               {0x35, 0xff},
+               {0x36, 0xff},
+               {0x37, 0xff},
+               {0x38, 0xff},
+               {0x39, 0xff},
+               {0x3a, 0xfe},
+               {0x3b, 0xfe},
+               {0x3c, 0xfe},
+               {0x3d, 0xfe},
+               {0x3e, 0xfe},
+               {0x3f, 0x71},
+               {0x40, 0xff},
+               {0x41, 0xff},
+               {0x42, 0xff},
+               {0x43, 0xff},
+               {0x44, 0xff},
+               {0x45, 0xff},
+               {0x46, 0xff},
+               {0x47, 0xff},
+               {0x48, 0xff},
+               {0x49, 0xff},
+               {0x4a, 0xfe},
+               {0x4b, 0xff},
+               {0x4c, 0x00},
+               {0x4d, 0x00},
+               {0x4e, 0xff},
+               {0x4f, 0xff},
+               {0x50, 0xff},
+               {0x51, 0xff},
+               {0x52, 0xff},
+               {0x53, 0xff},
+               {0x54, 0xff},
+               {0x55, 0xff},
+               {0x56, 0xff},
+               {0x57, 0xff},
+               {0x58, 0xff},
+               {0x59, 0xff},
+               {0x5a, 0xff},
+               {0x5b, 0xfe},
+               {0x5c, 0xff},
+               {0x5d, 0x8f},
+               {0x5e, 0xff},
+               {0x5f, 0x8f},
+               {0x60, 0xa2},
+               {0x61, 0x4a},
+               {0x62, 0xf3},
+               {0x63, 0x75},
+               {0x64, 0xf0},
+               {0x65, 0x00},
+               {0x66, 0x55},
+               {0x67, 0x92},
+               {0x68, 0xa0},
+               {0x69, 0x4a},
+               {0x6a, 0x22},
+               {0x6b, 0x00},
+               {0x6c, 0x33},
+               {0x6d, 0x44},
+               {0x6e, 0x22},
+               {0x6f, 0x84},
+               {0x70, 0x0b},
+               {0x72, 0x10},
+               {0x73, 0x50},
+               {0x74, 0x21},
+               {0x76, 0x00},
+               {0x77, 0xa5},
+               {0x78, 0x80},
+               {0x79, 0x80},
+               {0x7a, 0x80},
+               {0x7b, 0xe2},
+               {0x7c, 0x00},
+               {0x7d, 0xf7},
+               {0x7e, 0x00},
+               {0x7f, 0x00},
+       };
+
+       reg_w_buf(gspca_dev, reg_init_1, ARRAY_SIZE(reg_init_1));
+       reg_w_buf(gspca_dev, tp6810_ov_init_common,
+                       ARRAY_SIZE(tp6810_ov_init_common));
+       reg_w_buf(gspca_dev, reg_init_2, ARRAY_SIZE(reg_init_2));
+
+       i2c_w(gspca_dev, 0x12, 0x80);           /* sensor reset */
+       msleep(10);
+       i2c_w_buf(gspca_dev, sensor_init, ARRAY_SIZE(sensor_init));
+}
+
+/* set the gain and exposure */
+static void setexposure(struct gspca_dev *gspca_dev)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       if (sd->sensor == SENSOR_CX0342) {
+               int expo;
+
+               expo = (sd->ctrls[EXPOSURE].val << 2) - 1;
+               i2c_w(gspca_dev, CX0342_EXPO_LINE_L, expo);
+               i2c_w(gspca_dev, CX0342_EXPO_LINE_H, expo >> 8);
+               if (sd->bridge == BRIDGE_TP6800)
+                       i2c_w(gspca_dev, CX0342_RAW_GBGAIN_H,
+                                               sd->ctrls[GAIN].val >> 8);
+               i2c_w(gspca_dev, CX0342_RAW_GBGAIN_L, sd->ctrls[GAIN].val);
+               if (sd->bridge == BRIDGE_TP6800)
+                       i2c_w(gspca_dev, CX0342_RAW_GRGAIN_H,
+                                               sd->ctrls[GAIN].val >> 8);
+               i2c_w(gspca_dev, CX0342_RAW_GRGAIN_L, sd->ctrls[GAIN].val);
+               if (sd->bridge == BRIDGE_TP6800)
+                       i2c_w(gspca_dev, CX0342_RAW_BGAIN_H,
+                                               sd->ctrls[BGAIN].val >> 8);
+               i2c_w(gspca_dev, CX0342_RAW_BGAIN_L, sd->ctrls[BGAIN].val);
+               if (sd->bridge == BRIDGE_TP6800)
+                       i2c_w(gspca_dev, CX0342_RAW_RGAIN_H,
+                                               sd->ctrls[RGAIN].val >> 8);
+               i2c_w(gspca_dev, CX0342_RAW_RGAIN_L, sd->ctrls[RGAIN].val);
+               i2c_w(gspca_dev, CX0342_SYS_CTRL_0,
+                               sd->bridge == BRIDGE_TP6800 ? 0x80 : 0x81);
+               return;
+       }
+
+       /* soi763a */
+       i2c_w(gspca_dev, 0x10,          /* AEC_H (exposure time) */
+                        sd->ctrls[EXPOSURE].val);
+/*     i2c_w(gspca_dev, 0x76, 0x02);    * AEC_L ([1:0] */
+       i2c_w(gspca_dev, 0x00,          /* gain */
+                        sd->ctrls[GAIN].val);
+}
+
+/* set the JPEG quantization tables */
+static void set_dqt(struct gspca_dev *gspca_dev, u8 q)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       /* update the jpeg quantization tables */
+       PDEBUG(D_STREAM, "q %d -> %d", sd->quality, q);
+       sd->quality = q;
+       if (q > 16)
+               q = 16;
+       if (sd->sensor == SENSOR_SOI763A)
+               jpeg_set_qual(sd->jpeg_hdr, jpeg_q[q]);
+       else
+               memcpy(&sd->jpeg_hdr[JPEG_QT0_OFFSET - 1],
+                       DQT[q], sizeof DQT[0]);
+}
+
+/* set the JPEG compression quality factor */
+static void setquality(struct gspca_dev *gspca_dev)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       u16 q;
+
+       q = sd->ctrls[QUALITY].val;
+       if (q != 16)
+               q = 15 - q;
+
+       reg_w(gspca_dev, TP6800_R7A_BLK_THRLD, 0x00);
+       reg_w(gspca_dev, TP6800_R79_QUALITY, 0x04);
+       reg_w(gspca_dev, TP6800_R79_QUALITY, q);
+
+       /* auto quality */
+       if (q == 15 && sd->bridge == BRIDGE_TP6810) {
+               msleep(4);
+               reg_w(gspca_dev, TP6800_R7A_BLK_THRLD, 0x19);
+       }
+}
+
+static const u8 color_null[18] = {
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+};
+static const u8 color_gain[NSENSORS][18] = {
+[SENSOR_CX0342] =
+       {0x4c, 0x00, 0xa9, 0x00, 0x31, 0x00,    /* Y R/G/B (LE values) */
+        0xb6, 0x03, 0x6c, 0x03, 0xe0, 0x00,    /* U R/G/B */
+        0xdf, 0x00, 0x46, 0x03, 0xdc, 0x03},   /* V R/G/B */
+[SENSOR_SOI763A] =
+       {0x4c, 0x00, 0x95, 0x00, 0x1d, 0x00,    /* Y R/G/B (LE values) */
+        0xb6, 0x03, 0x6c, 0x03, 0xd7, 0x00,    /* U R/G/B */
+        0xd5, 0x00, 0x46, 0x03, 0xdc, 0x03},   /* V R/G/B */
+};
+
+static void setgamma(struct gspca_dev *gspca_dev)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       int gamma;
+#define NGAMMA 6
+       static const u8 gamma_tb[NGAMMA][3][1024] = {
+           {                           /* gamma 0 - from tp6800 + soi763a */
+               {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02,
+                0x02, 0x03, 0x05, 0x07, 0x07, 0x08, 0x09, 0x09,
+                0x0a, 0x0c, 0x0c, 0x0d, 0x0e, 0x0e, 0x10, 0x11,
+                0x11, 0x12, 0x14, 0x14, 0x15, 0x16, 0x16, 0x17,
+                0x17, 0x18, 0x1a, 0x1a, 0x1b, 0x1b, 0x1c, 0x1e,
+                0x1e, 0x1f, 0x1f, 0x20, 0x20, 0x22, 0x23, 0x23,
+                0x25, 0x25, 0x26, 0x26, 0x27, 0x27, 0x28, 0x28,
+                0x29, 0x29, 0x2b, 0x2c, 0x2c, 0x2d, 0x2d, 0x2f,
+                0x2f, 0x30, 0x30, 0x31, 0x31, 0x33, 0x33, 0x34,
+                0x34, 0x34, 0x35, 0x35, 0x37, 0x37, 0x38, 0x38,
+                0x39, 0x39, 0x3a, 0x3a, 0x3b, 0x3b, 0x3b, 0x3c,
+                0x3c, 0x3d, 0x3d, 0x3f, 0x3f, 0x40, 0x40, 0x40,
+                0x42, 0x42, 0x43, 0x43, 0x44, 0x44, 0x44, 0x45,
+                0x45, 0x47, 0x47, 0x47, 0x48, 0x48, 0x49, 0x49,
+                0x4a, 0x4a, 0x4a, 0x4b, 0x4b, 0x4b, 0x4c, 0x4c,
+                0x4d, 0x4d, 0x4d, 0x4f, 0x4f, 0x50, 0x50, 0x50,
+                0x52, 0x52, 0x52, 0x53, 0x53, 0x54, 0x54, 0x54,
+                0x55, 0x55, 0x55, 0x56, 0x56, 0x58, 0x58, 0x58,
+                0x59, 0x59, 0x59, 0x5a, 0x5a, 0x5a, 0x5b, 0x5b,
+                0x5b, 0x5c, 0x5c, 0x5c, 0x5e, 0x5e, 0x5e, 0x5f,
+                0x5f, 0x5f, 0x60, 0x60, 0x60, 0x61, 0x61, 0x61,
+                0x62, 0x62, 0x62, 0x63, 0x63, 0x63, 0x65, 0x65,
+                0x65, 0x66, 0x66, 0x66, 0x67, 0x67, 0x67, 0x68,
+                0x68, 0x68, 0x69, 0x69, 0x69, 0x69, 0x6a, 0x6a,
+                0x6a, 0x6c, 0x6c, 0x6c, 0x6d, 0x6d, 0x6d, 0x6e,
+                0x6e, 0x6e, 0x6e, 0x6f, 0x6f, 0x6f, 0x70, 0x70,
+                0x70, 0x71, 0x71, 0x71, 0x71, 0x73, 0x73, 0x73,
+                0x74, 0x74, 0x74, 0x74, 0x75, 0x75, 0x75, 0x77,
+                0x77, 0x77, 0x77, 0x78, 0x78, 0x78, 0x79, 0x79,
+                0x79, 0x79, 0x7a, 0x7a, 0x7a, 0x7a, 0x7b, 0x7b,
+                0x7b, 0x7c, 0x7c, 0x7c, 0x7c, 0x7d, 0x7d, 0x7d,
+                0x7d, 0x7f, 0x7f, 0x7f, 0x80, 0x80, 0x80, 0x80,
+                0x81, 0x81, 0x81, 0x81, 0x82, 0x82, 0x82, 0x82,
+                0x84, 0x84, 0x84, 0x85, 0x85, 0x85, 0x85, 0x86,
+                0x86, 0x86, 0x86, 0x88, 0x88, 0x88, 0x88, 0x89,
+                0x89, 0x89, 0x89, 0x8a, 0x8a, 0x8a, 0x8a, 0x8b,
+                0x8b, 0x8b, 0x8b, 0x8d, 0x8d, 0x8d, 0x8d, 0x8e,
+                0x8e, 0x8e, 0x8e, 0x8f, 0x8f, 0x8f, 0x8f, 0x90,
+                0x90, 0x90, 0x90, 0x90, 0x91, 0x91, 0x91, 0x91,
+                0x92, 0x92, 0x92, 0x92, 0x93, 0x93, 0x93, 0x93,
+                0x94, 0x94, 0x94, 0x94, 0x96, 0x96, 0x96, 0x96,
+                0x96, 0x97, 0x97, 0x97, 0x97, 0x98, 0x98, 0x98,
+                0x98, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9a, 0x9a,
+                0x9a, 0x9a, 0x9b, 0x9b, 0x9b, 0x9b, 0x9c, 0x9c,
+                0x9c, 0x9c, 0x9c, 0x9d, 0x9d, 0x9d, 0x9d, 0x9e,
+                0x9e, 0x9e, 0x9e, 0x9e, 0xa0, 0xa0, 0xa0, 0xa0,
+                0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa2, 0xa2, 0xa2,
+                0xa2, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa4, 0xa4,
+                0xa4, 0xa4, 0xa4, 0xa5, 0xa5, 0xa5, 0xa5, 0xa6,
+                0xa6, 0xa6, 0xa6, 0xa6, 0xa8, 0xa8, 0xa8, 0xa8,
+                0xa8, 0xa9, 0xa9, 0xa9, 0xa9, 0xab, 0xab, 0xab,
+                0xab, 0xab, 0xac, 0xac, 0xac, 0xac, 0xac, 0xad,
+                0xad, 0xad, 0xad, 0xae, 0xae, 0xae, 0xae, 0xae,
+                0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xb0, 0xb0, 0xb0,
+                0xb0, 0xb0, 0xb1, 0xb1, 0xb1, 0xb1, 0xb1, 0xb2,
+                0xb2, 0xb2, 0xb2, 0xb2, 0xb3, 0xb3, 0xb3, 0xb3,
+                0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0xb6, 0xb6, 0xb6,
+                0xb6, 0xb6, 0xb7, 0xb7, 0xb7, 0xb7, 0xb7, 0xb8,
+                0xb8, 0xb8, 0xb8, 0xb8, 0xb9, 0xb9, 0xb9, 0xb9,
+                0xb9, 0xba, 0xba, 0xba, 0xba, 0xba, 0xbc, 0xbc,
+                0xbc, 0xbc, 0xbc, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd,
+                0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbf, 0xbf, 0xbf,
+                0xbf, 0xbf, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc2,
+                0xc2, 0xc2, 0xc2, 0xc2, 0xc3, 0xc3, 0xc3, 0xc3,
+                0xc3, 0xc4, 0xc4, 0xc4, 0xc4, 0xc4, 0xc5, 0xc5,
+                0xc5, 0xc5, 0xc5, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
+                0xc7, 0xc7, 0xc7, 0xc7, 0xc7, 0xc9, 0xc9, 0xc9,
+                0xc9, 0xc9, 0xc9, 0xca, 0xca, 0xca, 0xca, 0xca,
+                0xcb, 0xcb, 0xcb, 0xcb, 0xcb, 0xcc, 0xcc, 0xcc,
+                0xcc, 0xcc, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xce,
+                0xce, 0xce, 0xce, 0xce, 0xcf, 0xcf, 0xcf, 0xcf,
+                0xcf, 0xd0, 0xd0, 0xd0, 0xd0, 0xd0, 0xd1, 0xd1,
+                0xd1, 0xd1, 0xd1, 0xd1, 0xd3, 0xd3, 0xd3, 0xd3,
+                0xd3, 0xd4, 0xd4, 0xd4, 0xd4, 0xd4, 0xd6, 0xd6,
+                0xd6, 0xd6, 0xd6, 0xd7, 0xd7, 0xd7, 0xd7, 0xd7,
+                0xd8, 0xd8, 0xd8, 0xd8, 0xd8, 0xd9, 0xd9, 0xd9,
+                0xd9, 0xd9, 0xda, 0xda, 0xda, 0xda, 0xda, 0xdb,
+                0xdb, 0xdb, 0xdb, 0xdb, 0xdd, 0xdd, 0xdd, 0xdd,
+                0xdd, 0xde, 0xde, 0xde, 0xde, 0xde, 0xde, 0xdf,
+                0xdf, 0xdf, 0xdf, 0xdf, 0xe0, 0xe0, 0xe0, 0xe0,
+                0xe0, 0xe1, 0xe1, 0xe1, 0xe1, 0xe1, 0xe2, 0xe2,
+                0xe2, 0xe2, 0xe2, 0xe3, 0xe3, 0xe3, 0xe3, 0xe3,
+                0xe4, 0xe4, 0xe4, 0xe4, 0xe4, 0xe5, 0xe5, 0xe5,
+                0xe5, 0xe5, 0xe6, 0xe6, 0xe6, 0xe6, 0xe6, 0xe7,
+                0xe7, 0xe7, 0xe7, 0xe7, 0xe8, 0xe8, 0xe8, 0xe8,
+                0xe8, 0xe9, 0xe9, 0xe9, 0xe9, 0xeb, 0xeb, 0xeb,
+                0xeb, 0xeb, 0xec, 0xec, 0xec, 0xec, 0xec, 0xed,
+                0xed, 0xed, 0xed, 0xed, 0xee, 0xee, 0xee, 0xee,
+                0xee, 0xef, 0xef, 0xef, 0xef, 0xef, 0xf0, 0xf0,
+                0xf0, 0xf0, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf3,
+                0xf3, 0xf3, 0xf3, 0xf3, 0xf4, 0xf4, 0xf4, 0xf4,
+                0xf4, 0xf5, 0xf5, 0xf5, 0xf5, 0xf6, 0xf6, 0xf6,
+                0xf6, 0xf6, 0xf7, 0xf7, 0xf7, 0xf7, 0xf8, 0xf8,
+                0xf8, 0xf8, 0xf8, 0xf9, 0xf9, 0xf9, 0xf9, 0xfa,
+                0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb},
+               {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02,
+                0x02, 0x03, 0x05, 0x07, 0x07, 0x08, 0x09, 0x09,
+                0x0a, 0x0c, 0x0c, 0x0d, 0x0e, 0x0e, 0x10, 0x11,
+                0x11, 0x12, 0x14, 0x14, 0x15, 0x16, 0x16, 0x17,
+                0x17, 0x18, 0x1a, 0x1a, 0x1b, 0x1b, 0x1c, 0x1e,
+                0x1e, 0x1f, 0x1f, 0x20, 0x20, 0x22, 0x23, 0x23,
+                0x25, 0x25, 0x26, 0x26, 0x27, 0x27, 0x28, 0x28,
+                0x29, 0x29, 0x2b, 0x2c, 0x2c, 0x2d, 0x2d, 0x2f,
+                0x2f, 0x30, 0x30, 0x31, 0x31, 0x33, 0x33, 0x34,
+                0x34, 0x34, 0x35, 0x35, 0x37, 0x37, 0x38, 0x38,
+                0x39, 0x39, 0x3a, 0x3a, 0x3b, 0x3b, 0x3b, 0x3c,
+                0x3c, 0x3d, 0x3d, 0x3f, 0x3f, 0x40, 0x40, 0x40,
+                0x42, 0x42, 0x43, 0x43, 0x44, 0x44, 0x44, 0x45,
+                0x45, 0x47, 0x47, 0x47, 0x48, 0x48, 0x49, 0x49,
+                0x4a, 0x4a, 0x4a, 0x4b, 0x4b, 0x4b, 0x4c, 0x4c,
+                0x4d, 0x4d, 0x4d, 0x4f, 0x4f, 0x50, 0x50, 0x50,
+                0x52, 0x52, 0x52, 0x53, 0x53, 0x54, 0x54, 0x54,
+                0x55, 0x55, 0x55, 0x56, 0x56, 0x58, 0x58, 0x58,
+                0x59, 0x59, 0x59, 0x5a, 0x5a, 0x5a, 0x5b, 0x5b,
+                0x5b, 0x5c, 0x5c, 0x5c, 0x5e, 0x5e, 0x5e, 0x5f,
+                0x5f, 0x5f, 0x60, 0x60, 0x60, 0x61, 0x61, 0x61,
+                0x62, 0x62, 0x62, 0x63, 0x63, 0x63, 0x65, 0x65,
+                0x65, 0x66, 0x66, 0x66, 0x67, 0x67, 0x67, 0x68,
+                0x68, 0x68, 0x69, 0x69, 0x69, 0x69, 0x6a, 0x6a,
+                0x6a, 0x6c, 0x6c, 0x6c, 0x6d, 0x6d, 0x6d, 0x6e,
+                0x6e, 0x6e, 0x6e, 0x6f, 0x6f, 0x6f, 0x70, 0x70,
+                0x70, 0x71, 0x71, 0x71, 0x71, 0x73, 0x73, 0x73,
+                0x74, 0x74, 0x74, 0x74, 0x75, 0x75, 0x75, 0x77,
+                0x77, 0x77, 0x77, 0x78, 0x78, 0x78, 0x79, 0x79,
+                0x79, 0x79, 0x7a, 0x7a, 0x7a, 0x7a, 0x7b, 0x7b,
+                0x7b, 0x7c, 0x7c, 0x7c, 0x7c, 0x7d, 0x7d, 0x7d,
+                0x7d, 0x7f, 0x7f, 0x7f, 0x80, 0x80, 0x80, 0x80,
+                0x81, 0x81, 0x81, 0x81, 0x82, 0x82, 0x82, 0x82,
+                0x84, 0x84, 0x84, 0x85, 0x85, 0x85, 0x85, 0x86,
+                0x86, 0x86, 0x86, 0x88, 0x88, 0x88, 0x88, 0x89,
+                0x89, 0x89, 0x89, 0x8a, 0x8a, 0x8a, 0x8a, 0x8b,
+                0x8b, 0x8b, 0x8b, 0x8d, 0x8d, 0x8d, 0x8d, 0x8e,
+                0x8e, 0x8e, 0x8e, 0x8f, 0x8f, 0x8f, 0x8f, 0x90,
+                0x90, 0x90, 0x90, 0x90, 0x91, 0x91, 0x91, 0x91,
+                0x92, 0x92, 0x92, 0x92, 0x93, 0x93, 0x93, 0x93,
+                0x94, 0x94, 0x94, 0x94, 0x96, 0x96, 0x96, 0x96,
+                0x96, 0x97, 0x97, 0x97, 0x97, 0x98, 0x98, 0x98,
+                0x98, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9a, 0x9a,
+                0x9a, 0x9a, 0x9b, 0x9b, 0x9b, 0x9b, 0x9c, 0x9c,
+                0x9c, 0x9c, 0x9c, 0x9d, 0x9d, 0x9d, 0x9d, 0x9e,
+                0x9e, 0x9e, 0x9e, 0x9e, 0xa0, 0xa0, 0xa0, 0xa0,
+                0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa2, 0xa2, 0xa2,
+                0xa2, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa4, 0xa4,
+                0xa4, 0xa4, 0xa4, 0xa5, 0xa5, 0xa5, 0xa5, 0xa6,
+                0xa6, 0xa6, 0xa6, 0xa6, 0xa8, 0xa8, 0xa8, 0xa8,
+                0xa8, 0xa9, 0xa9, 0xa9, 0xa9, 0xab, 0xab, 0xab,
+                0xab, 0xab, 0xac, 0xac, 0xac, 0xac, 0xac, 0xad,
+                0xad, 0xad, 0xad, 0xae, 0xae, 0xae, 0xae, 0xae,
+                0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xb0, 0xb0, 0xb0,
+                0xb0, 0xb0, 0xb1, 0xb1, 0xb1, 0xb1, 0xb1, 0xb2,
+                0xb2, 0xb2, 0xb2, 0xb2, 0xb3, 0xb3, 0xb3, 0xb3,
+                0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0xb6, 0xb6, 0xb6,
+                0xb6, 0xb6, 0xb7, 0xb7, 0xb7, 0xb7, 0xb7, 0xb8,
+                0xb8, 0xb8, 0xb8, 0xb8, 0xb9, 0xb9, 0xb9, 0xb9,
+                0xb9, 0xba, 0xba, 0xba, 0xba, 0xba, 0xbc, 0xbc,
+                0xbc, 0xbc, 0xbc, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd,
+                0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbf, 0xbf, 0xbf,
+                0xbf, 0xbf, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc2,
+                0xc2, 0xc2, 0xc2, 0xc2, 0xc3, 0xc3, 0xc3, 0xc3,
+                0xc3, 0xc4, 0xc4, 0xc4, 0xc4, 0xc4, 0xc5, 0xc5,
+                0xc5, 0xc5, 0xc5, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
+                0xc7, 0xc7, 0xc7, 0xc7, 0xc7, 0xc9, 0xc9, 0xc9,
+                0xc9, 0xc9, 0xc9, 0xca, 0xca, 0xca, 0xca, 0xca,
+                0xcb, 0xcb, 0xcb, 0xcb, 0xcb, 0xcc, 0xcc, 0xcc,
+                0xcc, 0xcc, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xce,
+                0xce, 0xce, 0xce, 0xce, 0xcf, 0xcf, 0xcf, 0xcf,
+                0xcf, 0xd0, 0xd0, 0xd0, 0xd0, 0xd0, 0xd1, 0xd1,
+                0xd1, 0xd1, 0xd1, 0xd1, 0xd3, 0xd3, 0xd3, 0xd3,
+                0xd3, 0xd4, 0xd4, 0xd4, 0xd4, 0xd4, 0xd6, 0xd6,
+                0xd6, 0xd6, 0xd6, 0xd7, 0xd7, 0xd7, 0xd7, 0xd7,
+                0xd8, 0xd8, 0xd8, 0xd8, 0xd8, 0xd9, 0xd9, 0xd9,
+                0xd9, 0xd9, 0xda, 0xda, 0xda, 0xda, 0xda, 0xdb,
+                0xdb, 0xdb, 0xdb, 0xdb, 0xdd, 0xdd, 0xdd, 0xdd,
+                0xdd, 0xde, 0xde, 0xde, 0xde, 0xde, 0xde, 0xdf,
+                0xdf, 0xdf, 0xdf, 0xdf, 0xe0, 0xe0, 0xe0, 0xe0,
+                0xe0, 0xe1, 0xe1, 0xe1, 0xe1, 0xe1, 0xe2, 0xe2,
+                0xe2, 0xe2, 0xe2, 0xe3, 0xe3, 0xe3, 0xe3, 0xe3,
+                0xe4, 0xe4, 0xe4, 0xe4, 0xe4, 0xe5, 0xe5, 0xe5,
+                0xe5, 0xe5, 0xe6, 0xe6, 0xe6, 0xe6, 0xe6, 0xe7,
+                0xe7, 0xe7, 0xe7, 0xe7, 0xe8, 0xe8, 0xe8, 0xe8,
+                0xe8, 0xe9, 0xe9, 0xe9, 0xe9, 0xeb, 0xeb, 0xeb,
+                0xeb, 0xeb, 0xec, 0xec, 0xec, 0xec, 0xec, 0xed,
+                0xed, 0xed, 0xed, 0xed, 0xee, 0xee, 0xee, 0xee,
+                0xee, 0xef, 0xef, 0xef, 0xef, 0xef, 0xf0, 0xf0,
+                0xf0, 0xf0, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf3,
+                0xf3, 0xf3, 0xf3, 0xf3, 0xf4, 0xf4, 0xf4, 0xf4,
+                0xf4, 0xf5, 0xf5, 0xf5, 0xf5, 0xf6, 0xf6, 0xf6,
+                0xf6, 0xf6, 0xf7, 0xf7, 0xf7, 0xf7, 0xf8, 0xf8,
+                0xf8, 0xf8, 0xf8, 0xf9, 0xf9, 0xf9, 0xf9, 0xfa,
+                0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb},
+               {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02,
+                0x02, 0x03, 0x05, 0x07, 0x07, 0x08, 0x09, 0x09,
+                0x0a, 0x0c, 0x0c, 0x0d, 0x0e, 0x0e, 0x10, 0x11,
+                0x11, 0x12, 0x14, 0x14, 0x15, 0x16, 0x16, 0x17,
+                0x17, 0x18, 0x1a, 0x1a, 0x1b, 0x1b, 0x1c, 0x1e,
+                0x1e, 0x1f, 0x1f, 0x20, 0x20, 0x22, 0x23, 0x23,
+                0x25, 0x25, 0x26, 0x26, 0x27, 0x27, 0x28, 0x28,
+                0x29, 0x29, 0x2b, 0x2c, 0x2c, 0x2d, 0x2d, 0x2f,
+                0x2f, 0x30, 0x30, 0x31, 0x31, 0x33, 0x33, 0x34,
+                0x34, 0x34, 0x35, 0x35, 0x37, 0x37, 0x38, 0x38,
+                0x39, 0x39, 0x3a, 0x3a, 0x3b, 0x3b, 0x3b, 0x3c,
+                0x3c, 0x3d, 0x3d, 0x3f, 0x3f, 0x40, 0x40, 0x40,
+                0x42, 0x42, 0x43, 0x43, 0x44, 0x44, 0x44, 0x45,
+                0x45, 0x47, 0x47, 0x47, 0x48, 0x48, 0x49, 0x49,
+                0x4a, 0x4a, 0x4a, 0x4b, 0x4b, 0x4b, 0x4c, 0x4c,
+                0x4d, 0x4d, 0x4d, 0x4f, 0x4f, 0x50, 0x50, 0x50,
+                0x52, 0x52, 0x52, 0x53, 0x53, 0x54, 0x54, 0x54,
+                0x55, 0x55, 0x55, 0x56, 0x56, 0x58, 0x58, 0x58,
+                0x59, 0x59, 0x59, 0x5a, 0x5a, 0x5a, 0x5b, 0x5b,
+                0x5b, 0x5c, 0x5c, 0x5c, 0x5e, 0x5e, 0x5e, 0x5f,
+                0x5f, 0x5f, 0x60, 0x60, 0x60, 0x61, 0x61, 0x61,
+                0x62, 0x62, 0x62, 0x63, 0x63, 0x63, 0x65, 0x65,
+                0x65, 0x66, 0x66, 0x66, 0x67, 0x67, 0x67, 0x68,
+                0x68, 0x68, 0x69, 0x69, 0x69, 0x69, 0x6a, 0x6a,
+                0x6a, 0x6c, 0x6c, 0x6c, 0x6d, 0x6d, 0x6d, 0x6e,
+                0x6e, 0x6e, 0x6e, 0x6f, 0x6f, 0x6f, 0x70, 0x70,
+                0x70, 0x71, 0x71, 0x71, 0x71, 0x73, 0x73, 0x73,
+                0x74, 0x74, 0x74, 0x74, 0x75, 0x75, 0x75, 0x76,
+                0x77, 0x77, 0x77, 0x78, 0x78, 0x78, 0x79, 0x79,
+                0x79, 0x79, 0x7a, 0x7a, 0x7a, 0x7a, 0x7b, 0x7b,
+                0x7b, 0x7c, 0x7c, 0x7c, 0x7c, 0x7d, 0x7d, 0x7d,
+                0x7d, 0x7f, 0x7f, 0x7f, 0x80, 0x80, 0x80, 0x80,
+                0x81, 0x81, 0x81, 0x81, 0x82, 0x82, 0x82, 0x82,
+                0x84, 0x84, 0x84, 0x85, 0x85, 0x85, 0x85, 0x86,
+                0x86, 0x86, 0x86, 0x88, 0x88, 0x88, 0x88, 0x89,
+                0x89, 0x89, 0x89, 0x8a, 0x8a, 0x8a, 0x8a, 0x8b,
+                0x8b, 0x8b, 0x8b, 0x8d, 0x8d, 0x8d, 0x8d, 0x8e,
+                0x8e, 0x8e, 0x8e, 0x8f, 0x8f, 0x8f, 0x8f, 0x90,
+                0x90, 0x90, 0x90, 0x90, 0x91, 0x91, 0x91, 0x91,
+                0x92, 0x92, 0x92, 0x92, 0x93, 0x93, 0x93, 0x93,
+                0x94, 0x94, 0x94, 0x94, 0x96, 0x96, 0x96, 0x96,
+                0x96, 0x97, 0x97, 0x97, 0x97, 0x98, 0x98, 0x98,
+                0x98, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9a, 0x9a,
+                0x9a, 0x9a, 0x9b, 0x9b, 0x9b, 0x9b, 0x9c, 0x9c,
+                0x9c, 0x9c, 0x9c, 0x9d, 0x9d, 0x9d, 0x9d, 0x9e,
+                0x9e, 0x9e, 0x9e, 0x9e, 0xa0, 0xa0, 0xa0, 0xa0,
+                0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa2, 0xa2, 0xa2,
+                0xa2, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa4, 0xa4,
+                0xa4, 0xa4, 0xa4, 0xa5, 0xa5, 0xa5, 0xa5, 0xa6,
+                0xa6, 0xa6, 0xa6, 0xa6, 0xa8, 0xa8, 0xa8, 0xa8,
+                0xa8, 0xa9, 0xa9, 0xa9, 0xa9, 0xab, 0xab, 0xab,
+                0xab, 0xab, 0xac, 0xac, 0xac, 0xac, 0xac, 0xad,
+                0xad, 0xad, 0xad, 0xae, 0xae, 0xae, 0xae, 0xae,
+                0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xb0, 0xb0, 0xb0,
+                0xb0, 0xb0, 0xb1, 0xb1, 0xb1, 0xb1, 0xb1, 0xb2,
+                0xb2, 0xb2, 0xb2, 0xb2, 0xb3, 0xb3, 0xb3, 0xb3,
+                0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0xb6, 0xb6, 0xb6,
+                0xb6, 0xb6, 0xb7, 0xb7, 0xb7, 0xb7, 0xb7, 0xb8,
+                0xb8, 0xb8, 0xb8, 0xb8, 0xb9, 0xb9, 0xb9, 0xb9,
+                0xb9, 0xba, 0xba, 0xba, 0xba, 0xba, 0xbc, 0xbc,
+                0xbc, 0xbc, 0xbc, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd,
+                0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbf, 0xbf, 0xbf,
+                0xbf, 0xbf, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc2,
+                0xc2, 0xc2, 0xc2, 0xc2, 0xc3, 0xc3, 0xc3, 0xc3,
+                0xc3, 0xc4, 0xc4, 0xc4, 0xc4, 0xc4, 0xc5, 0xc5,
+                0xc5, 0xc5, 0xc5, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
+                0xc7, 0xc7, 0xc7, 0xc7, 0xc7, 0xc9, 0xc9, 0xc9,
+                0xc9, 0xc9, 0xc9, 0xca, 0xca, 0xca, 0xca, 0xca,
+                0xcb, 0xcb, 0xcb, 0xcb, 0xcb, 0xcc, 0xcc, 0xcc,
+                0xcc, 0xcc, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xce,
+                0xce, 0xce, 0xce, 0xce, 0xcf, 0xcf, 0xcf, 0xcf,
+                0xcf, 0xd0, 0xd0, 0xd0, 0xd0, 0xd0, 0xd1, 0xd1,
+                0xd1, 0xd1, 0xd1, 0xd1, 0xd3, 0xd3, 0xd3, 0xd3,
+                0xd3, 0xd4, 0xd4, 0xd4, 0xd4, 0xd4, 0xd6, 0xd6,
+                0xd6, 0xd6, 0xd6, 0xd7, 0xd7, 0xd7, 0xd7, 0xd7,
+                0xd8, 0xd8, 0xd8, 0xd8, 0xd8, 0xd9, 0xd9, 0xd9,
+                0xd9, 0xd9, 0xda, 0xda, 0xda, 0xda, 0xda, 0xdb,
+                0xdb, 0xdb, 0xdb, 0xdb, 0xdd, 0xdd, 0xdd, 0xdd,
+                0xdd, 0xde, 0xde, 0xde, 0xde, 0xde, 0xde, 0xdf,
+                0xdf, 0xdf, 0xdf, 0xdf, 0xe0, 0xe0, 0xe0, 0xe0,
+                0xe0, 0xe1, 0xe1, 0xe1, 0xe1, 0xe1, 0xe2, 0xe2,
+                0xe2, 0xe2, 0xe2, 0xe3, 0xe3, 0xe3, 0xe3, 0xe3,
+                0xe4, 0xe4, 0xe4, 0xe4, 0xe4, 0xe5, 0xe5, 0xe5,
+                0xe5, 0xe5, 0xe6, 0xe6, 0xe6, 0xe6, 0xe6, 0xe7,
+                0xe7, 0xe7, 0xe7, 0xe7, 0xe8, 0xe8, 0xe8, 0xe8,
+                0xe8, 0xe9, 0xe9, 0xe9, 0xe9, 0xeb, 0xeb, 0xeb,
+                0xeb, 0xeb, 0xec, 0xec, 0xec, 0xec, 0xec, 0xed,
+                0xed, 0xed, 0xed, 0xed, 0xee, 0xee, 0xee, 0xee,
+                0xee, 0xef, 0xef, 0xef, 0xef, 0xef, 0xf0, 0xf0,
+                0xf0, 0xf0, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf3,
+                0xf3, 0xf3, 0xf3, 0xf3, 0xf4, 0xf4, 0xf4, 0xf4,
+                0xf4, 0xf5, 0xf5, 0xf5, 0xf5, 0xf6, 0xf6, 0xf6,
+                0xf6, 0xf6, 0xf7, 0xf7, 0xf7, 0xf7, 0xf8, 0xf8,
+                0xf8, 0xf8, 0xf8, 0xf9, 0xf9, 0xf9, 0xf9, 0xfa,
+                0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb}
+           },
+           {                           /* gamma 1 - from tp6810 + soi763a */
+               {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x01, 0x02, 0x03, 0x05, 0x07, 0x08, 0x09, 0x0a,
+                0x0c, 0x0d, 0x0e, 0x10, 0x11, 0x12, 0x14, 0x15,
+                0x16, 0x17, 0x18, 0x1a, 0x1a, 0x1b, 0x1c, 0x1e,
+                0x1f, 0x20, 0x22, 0x22, 0x23, 0x25, 0x26, 0x27,
+                0x27, 0x28, 0x29, 0x2b, 0x2b, 0x2c, 0x2d, 0x2f,
+                0x2f, 0x30, 0x31, 0x33, 0x33, 0x34, 0x35, 0x35,
+                0x37, 0x38, 0x38, 0x39, 0x3a, 0x3a, 0x3b, 0x3c,
+                0x3c, 0x3d, 0x3f, 0x3f, 0x40, 0x42, 0x42, 0x43,
+                0x43, 0x44, 0x45, 0x45, 0x47, 0x47, 0x48, 0x49,
+                0x49, 0x4a, 0x4a, 0x4b, 0x4b, 0x4c, 0x4d, 0x4d,
+                0x4f, 0x4f, 0x50, 0x50, 0x52, 0x52, 0x53, 0x53,
+                0x54, 0x54, 0x55, 0x56, 0x56, 0x58, 0x58, 0x59,
+                0x59, 0x5a, 0x5a, 0x5b, 0x5b, 0x5c, 0x5c, 0x5e,
+                0x5e, 0x5e, 0x5f, 0x5f, 0x60, 0x60, 0x61, 0x61,
+                0x62, 0x62, 0x63, 0x63, 0x65, 0x65, 0x65, 0x66,
+                0x66, 0x67, 0x67, 0x68, 0x68, 0x69, 0x69, 0x69,
+                0x6a, 0x6a, 0x6c, 0x6c, 0x6d, 0x6d, 0x6d, 0x6e,
+                0x6e, 0x6f, 0x6f, 0x6f, 0x70, 0x70, 0x71, 0x71,
+                0x73, 0x73, 0x73, 0x74, 0x74, 0x74, 0x75, 0x75,
+                0x77, 0x77, 0x77, 0x78, 0x78, 0x79, 0x79, 0x79,
+                0x7a, 0x7a, 0x7a, 0x7b, 0x7b, 0x7c, 0x7c, 0x7c,
+                0x7d, 0x7d, 0x7d, 0x7f, 0x7f, 0x80, 0x80, 0x80,
+                0x81, 0x81, 0x81, 0x82, 0x82, 0x82, 0x84, 0x84,
+                0x84, 0x85, 0x85, 0x85, 0x86, 0x86, 0x86, 0x88,
+                0x88, 0x88, 0x89, 0x89, 0x89, 0x8a, 0x8a, 0x8a,
+                0x8b, 0x8b, 0x8b, 0x8d, 0x8d, 0x8d, 0x8e, 0x8e,
+                0x8e, 0x8f, 0x8f, 0x8f, 0x90, 0x90, 0x90, 0x91,
+                0x91, 0x91, 0x92, 0x92, 0x92, 0x92, 0x93, 0x93,
+                0x93, 0x94, 0x94, 0x94, 0x96, 0x96, 0x96, 0x97,
+                0x97, 0x97, 0x97, 0x98, 0x98, 0x98, 0x99, 0x99,
+                0x99, 0x9a, 0x9a, 0x9a, 0x9a, 0x9b, 0x9b, 0x9b,
+                0x9c, 0x9c, 0x9c, 0x9c, 0x9d, 0x9d, 0x9d, 0x9e,
+                0x9e, 0x9e, 0x9e, 0xa0, 0xa0, 0xa0, 0xa1, 0xa1,
+                0xa1, 0xa1, 0xa2, 0xa2, 0xa2, 0xa2, 0xa3, 0xa3,
+                0xa3, 0xa4, 0xa4, 0xa4, 0xa4, 0xa5, 0xa5, 0xa5,
+                0xa5, 0xa6, 0xa6, 0xa6, 0xa8, 0xa8, 0xa8, 0xa8,
+                0xa9, 0xa9, 0xa9, 0xa9, 0xab, 0xab, 0xab, 0xab,
+                0xac, 0xac, 0xac, 0xad, 0xad, 0xad, 0xad, 0xae,
+                0xae, 0xae, 0xae, 0xaf, 0xaf, 0xaf, 0xaf, 0xb0,
+                0xb0, 0xb0, 0xb0, 0xb1, 0xb1, 0xb1, 0xb1, 0xb2,
+                0xb2, 0xb2, 0xb2, 0xb3, 0xb3, 0xb3, 0xb3, 0xb4,
+                0xb4, 0xb4, 0xb4, 0xb6, 0xb6, 0xb6, 0xb6, 0xb7,
+                0xb7, 0xb7, 0xb7, 0xb7, 0xb8, 0xb8, 0xb8, 0xb8,
+                0xb9, 0xb9, 0xb9, 0xb9, 0xba, 0xba, 0xba, 0xba,
+                0xbc, 0xbc, 0xbc, 0xbc, 0xbd, 0xbd, 0xbd, 0xbd,
+                0xbd, 0xbe, 0xbe, 0xbe, 0xbe, 0xbf, 0xbf, 0xbf,
+                0xbf, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc2, 0xc2,
+                0xc2, 0xc2, 0xc3, 0xc3, 0xc3, 0xc3, 0xc4, 0xc4,
+                0xc4, 0xc4, 0xc4, 0xc5, 0xc5, 0xc5, 0xc5, 0xc6,
+                0xc6, 0xc6, 0xc6, 0xc6, 0xc7, 0xc7, 0xc7, 0xc7,
+                0xc9, 0xc9, 0xc9, 0xc9, 0xc9, 0xca, 0xca, 0xca,
+                0xca, 0xcb, 0xcb, 0xcb, 0xcb, 0xcb, 0xcc, 0xcc,
+                0xcc, 0xcc, 0xcc, 0xcd, 0xcd, 0xcd, 0xcd, 0xce,
+                0xce, 0xce, 0xce, 0xce, 0xcf, 0xcf, 0xcf, 0xcf,
+                0xcf, 0xd0, 0xd0, 0xd0, 0xd0, 0xd1, 0xd1, 0xd1,
+                0xd1, 0xd1, 0xd3, 0xd3, 0xd3, 0xd3, 0xd3, 0xd4,
+                0xd4, 0xd4, 0xd4, 0xd6, 0xd6, 0xd6, 0xd6, 0xd6,
+                0xd7, 0xd7, 0xd7, 0xd7, 0xd7, 0xd8, 0xd8, 0xd8,
+                0xd8, 0xd8, 0xd9, 0xd9, 0xd9, 0xd9, 0xd9, 0xda,
+                0xda, 0xda, 0xda, 0xda, 0xdb, 0xdb, 0xdb, 0xdb,
+                0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xde, 0xde, 0xde,
+                0xde, 0xde, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xe0,
+                0xe0, 0xe0, 0xe0, 0xe0, 0xe1, 0xe1, 0xe1, 0xe1,
+                0xe1, 0xe2, 0xe2, 0xe2, 0xe2, 0xe2, 0xe3, 0xe3,
+                0xe3, 0xe3, 0xe3, 0xe4, 0xe4, 0xe4, 0xe4, 0xe4,
+                0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 0xe6, 0xe6, 0xe6,
+                0xe6, 0xe6, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe8,
+                0xe8, 0xe8, 0xe8, 0xe8, 0xe9, 0xe9, 0xe9, 0xe9,
+                0xe9, 0xeb, 0xeb, 0xeb, 0xeb, 0xeb, 0xec, 0xec,
+                0xec, 0xec, 0xec, 0xed, 0xed, 0xed, 0xed, 0xed,
+                0xee, 0xee, 0xee, 0xee, 0xee, 0xef, 0xef, 0xef,
+                0xef, 0xef, 0xef, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
+                0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf3, 0xf3, 0xf3,
+                0xf3, 0xf3, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf5,
+                0xf5, 0xf5, 0xf5, 0xf5, 0xf6, 0xf6, 0xf6, 0xf6,
+                0xf6, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf8, 0xf8,
+                0xf8, 0xf8, 0xf8, 0xf8, 0xf9, 0xf9, 0xf9, 0xf9,
+                0xf9, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa,
+                0xfa, 0xfa, 0xfa, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc,
+                0xfc, 0xfc, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfe,
+                0xfe, 0xfe, 0xfe, 0xfe, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
+               {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03,
+                0x05, 0x07, 0x07, 0x08, 0x09, 0x0a, 0x0c, 0x0d,
+                0x0e, 0x10, 0x10, 0x11, 0x12, 0x14, 0x15, 0x15,
+                0x16, 0x17, 0x18, 0x1a, 0x1a, 0x1b, 0x1c, 0x1e,
+                0x1e, 0x1f, 0x20, 0x20, 0x22, 0x23, 0x25, 0x25,
+                0x26, 0x27, 0x27, 0x28, 0x29, 0x29, 0x2b, 0x2c,
+                0x2c, 0x2d, 0x2d, 0x2f, 0x30, 0x30, 0x31, 0x31,
+                0x33, 0x34, 0x34, 0x35, 0x35, 0x37, 0x38, 0x38,
+                0x39, 0x39, 0x3a, 0x3a, 0x3b, 0x3b, 0x3c, 0x3d,
+                0x3d, 0x3f, 0x3f, 0x40, 0x40, 0x42, 0x42, 0x43,
+                0x43, 0x44, 0x44, 0x45, 0x45, 0x47, 0x47, 0x48,
+                0x48, 0x49, 0x49, 0x4a, 0x4a, 0x4b, 0x4b, 0x4c,
+                0x4c, 0x4d, 0x4d, 0x4d, 0x4f, 0x4f, 0x50, 0x50,
+                0x52, 0x52, 0x53, 0x53, 0x53, 0x54, 0x54, 0x55,
+                0x55, 0x56, 0x56, 0x56, 0x58, 0x58, 0x59, 0x59,
+                0x5a, 0x5a, 0x5a, 0x5b, 0x5b, 0x5c, 0x5c, 0x5c,
+                0x5e, 0x5e, 0x5f, 0x5f, 0x5f, 0x60, 0x60, 0x60,
+                0x61, 0x61, 0x62, 0x62, 0x62, 0x63, 0x63, 0x65,
+                0x65, 0x65, 0x66, 0x66, 0x66, 0x67, 0x67, 0x67,
+                0x68, 0x68, 0x69, 0x69, 0x69, 0x6a, 0x6a, 0x6a,
+                0x6c, 0x6c, 0x6c, 0x6d, 0x6d, 0x6d, 0x6e, 0x6e,
+                0x6e, 0x6f, 0x6f, 0x6f, 0x70, 0x70, 0x70, 0x71,
+                0x71, 0x71, 0x73, 0x73, 0x73, 0x74, 0x74, 0x74,
+                0x75, 0x75, 0x75, 0x77, 0x77, 0x77, 0x78, 0x78,
+                0x78, 0x79, 0x79, 0x79, 0x79, 0x7a, 0x7a, 0x7a,
+                0x7b, 0x7b, 0x7b, 0x7c, 0x7c, 0x7c, 0x7c, 0x7d,
+                0x7d, 0x7d, 0x7f, 0x7f, 0x7f, 0x80, 0x80, 0x80,
+                0x80, 0x81, 0x81, 0x81, 0x82, 0x82, 0x82, 0x82,
+                0x84, 0x84, 0x84, 0x85, 0x85, 0x85, 0x85, 0x86,
+                0x86, 0x86, 0x88, 0x88, 0x88, 0x88, 0x89, 0x89,
+                0x89, 0x89, 0x8a, 0x8a, 0x8a, 0x8b, 0x8b, 0x8b,
+                0x8b, 0x8d, 0x8d, 0x8d, 0x8d, 0x8e, 0x8e, 0x8e,
+                0x8e, 0x8f, 0x8f, 0x8f, 0x90, 0x90, 0x90, 0x90,
+                0x91, 0x91, 0x91, 0x91, 0x92, 0x92, 0x92, 0x92,
+                0x93, 0x93, 0x93, 0x93, 0x94, 0x94, 0x94, 0x94,
+                0x96, 0x96, 0x96, 0x96, 0x97, 0x97, 0x97, 0x97,
+                0x98, 0x98, 0x98, 0x98, 0x99, 0x99, 0x99, 0x99,
+                0x9a, 0x9a, 0x9a, 0x9a, 0x9a, 0x9b, 0x9b, 0x9b,
+                0x9b, 0x9c, 0x9c, 0x9c, 0x9c, 0x9d, 0x9d, 0x9d,
+                0x9d, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0xa0, 0xa0,
+                0xa0, 0xa0, 0xa1, 0xa1, 0xa1, 0xa1, 0xa2, 0xa2,
+                0xa2, 0xa2, 0xa2, 0xa3, 0xa3, 0xa3, 0xa3, 0xa4,
+                0xa4, 0xa4, 0xa4, 0xa4, 0xa5, 0xa5, 0xa5, 0xa5,
+                0xa6, 0xa6, 0xa6, 0xa6, 0xa6, 0xa8, 0xa8, 0xa8,
+                0xa8, 0xa9, 0xa9, 0xa9, 0xa9, 0xa9, 0xab, 0xab,
+                0xab, 0xab, 0xac, 0xac, 0xac, 0xac, 0xac, 0xad,
+                0xad, 0xad, 0xad, 0xad, 0xae, 0xae, 0xae, 0xae,
+                0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xb0, 0xb0, 0xb0,
+                0xb0, 0xb0, 0xb1, 0xb1, 0xb1, 0xb1, 0xb1, 0xb2,
+                0xb2, 0xb2, 0xb2, 0xb2, 0xb3, 0xb3, 0xb3, 0xb3,
+                0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0xb6, 0xb6, 0xb6,
+                0xb6, 0xb6, 0xb7, 0xb7, 0xb7, 0xb7, 0xb7, 0xb8,
+                0xb8, 0xb8, 0xb8, 0xb8, 0xb9, 0xb9, 0xb9, 0xb9,
+                0xb9, 0xba, 0xba, 0xba, 0xba, 0xba, 0xbc, 0xbc,
+                0xbc, 0xbc, 0xbc, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd,
+                0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbf, 0xbf,
+                0xbf, 0xbf, 0xbf, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0,
+                0xc2, 0xc2, 0xc2, 0xc2, 0xc2, 0xc3, 0xc3, 0xc3,
+                0xc3, 0xc3, 0xc4, 0xc4, 0xc4, 0xc4, 0xc4, 0xc5,
+                0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 0xc6, 0xc6, 0xc6,
+                0xc6, 0xc6, 0xc7, 0xc7, 0xc7, 0xc7, 0xc7, 0xc9,
+                0xc9, 0xc9, 0xc9, 0xc9, 0xc9, 0xca, 0xca, 0xca,
+                0xca, 0xca, 0xcb, 0xcb, 0xcb, 0xcb, 0xcb, 0xcc,
+                0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcd, 0xcd, 0xcd,
+                0xcd, 0xcd, 0xce, 0xce, 0xce, 0xce, 0xce, 0xcf,
+                0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xd0, 0xd0, 0xd0,
+                0xd0, 0xd0, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1,
+                0xd3, 0xd3, 0xd3, 0xd3, 0xd3, 0xd4, 0xd4, 0xd4,
+                0xd4, 0xd4, 0xd4, 0xd6, 0xd6, 0xd6, 0xd6, 0xd6,
+                0xd7, 0xd7, 0xd7, 0xd7, 0xd7, 0xd7, 0xd8, 0xd8,
+                0xd8, 0xd8, 0xd8, 0xd9, 0xd9, 0xd9, 0xd9, 0xd9,
+                0xd9, 0xda, 0xda, 0xda, 0xda, 0xda, 0xdb, 0xdb,
+                0xdb, 0xdb, 0xdb, 0xdb, 0xdd, 0xdd, 0xdd, 0xdd,
+                0xdd, 0xde, 0xde, 0xde, 0xde, 0xde, 0xde, 0xdf,
+                0xdf, 0xdf, 0xdf, 0xdf, 0xe0, 0xe0, 0xe0, 0xe0,
+                0xe0, 0xe0, 0xe1, 0xe1, 0xe1, 0xe1, 0xe1, 0xe2,
+                0xe2, 0xe2, 0xe2, 0xe2, 0xe2, 0xe3, 0xe3, 0xe3,
+                0xe3, 0xe3, 0xe4, 0xe4, 0xe4, 0xe4, 0xe4, 0xe4,
+                0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 0xe6, 0xe6, 0xe6,
+                0xe6, 0xe6, 0xe6, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7,
+                0xe8, 0xe8, 0xe8, 0xe8, 0xe8, 0xe8, 0xe9, 0xe9,
+                0xe9, 0xe9, 0xe9, 0xeb, 0xeb, 0xeb, 0xeb, 0xeb,
+                0xeb, 0xec, 0xec, 0xec, 0xec, 0xec, 0xed, 0xed,
+                0xed, 0xed, 0xed, 0xed, 0xee, 0xee, 0xee, 0xee,
+                0xee, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xf0,
+                0xf0, 0xf0, 0xf0, 0xf0, 0xf1, 0xf1, 0xf1, 0xf1,
+                0xf1, 0xf1, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf4,
+                0xf4, 0xf4, 0xf4, 0xf4, 0xf5, 0xf5, 0xf5, 0xf5,
+                0xf5, 0xf5, 0xf6, 0xf6, 0xf6, 0xf6, 0xf6, 0xf7,
+                0xf7, 0xf7, 0xf7, 0xf7, 0xf8, 0xf8, 0xf8, 0xf8,
+                0xf8, 0xf8, 0xf9, 0xf9, 0xf9, 0xf9, 0xf9, 0xfa,
+                0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa,
+                0xfa, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfc, 0xfc,
+                0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc,
+                0xfc, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfe, 0xfe,
+                0xfe, 0xfe, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
+               {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x01, 0x02, 0x03, 0x05, 0x05, 0x07,
+                0x08, 0x09, 0x0a, 0x0a, 0x0c, 0x0d, 0x0e, 0x0e,
+                0x10, 0x11, 0x12, 0x12, 0x14, 0x15, 0x16, 0x16,
+                0x17, 0x18, 0x18, 0x1a, 0x1b, 0x1b, 0x1c, 0x1e,
+                0x1e, 0x1f, 0x1f, 0x20, 0x22, 0x22, 0x23, 0x23,
+                0x25, 0x26, 0x26, 0x27, 0x27, 0x28, 0x29, 0x29,
+                0x2b, 0x2b, 0x2c, 0x2c, 0x2d, 0x2d, 0x2f, 0x30,
+                0x30, 0x31, 0x31, 0x33, 0x33, 0x34, 0x34, 0x35,
+                0x35, 0x37, 0x37, 0x38, 0x38, 0x39, 0x39, 0x3a,
+                0x3a, 0x3b, 0x3b, 0x3b, 0x3c, 0x3c, 0x3d, 0x3d,
+                0x3f, 0x3f, 0x40, 0x40, 0x42, 0x42, 0x42, 0x43,
+                0x43, 0x44, 0x44, 0x45, 0x45, 0x47, 0x47, 0x47,
+                0x48, 0x48, 0x49, 0x49, 0x49, 0x4a, 0x4a, 0x4b,
+                0x4b, 0x4b, 0x4c, 0x4c, 0x4d, 0x4d, 0x4d, 0x4f,
+                0x4f, 0x50, 0x50, 0x50, 0x52, 0x52, 0x52, 0x53,
+                0x53, 0x54, 0x54, 0x54, 0x55, 0x55, 0x55, 0x56,
+                0x56, 0x58, 0x58, 0x58, 0x59, 0x59, 0x59, 0x5a,
+                0x5a, 0x5a, 0x5b, 0x5b, 0x5b, 0x5c, 0x5c, 0x5c,
+                0x5e, 0x5e, 0x5e, 0x5f, 0x5f, 0x5f, 0x60, 0x60,
+                0x60, 0x61, 0x61, 0x61, 0x62, 0x62, 0x62, 0x63,
+                0x63, 0x63, 0x65, 0x65, 0x65, 0x66, 0x66, 0x66,
+                0x66, 0x67, 0x67, 0x67, 0x68, 0x68, 0x68, 0x69,
+                0x69, 0x69, 0x6a, 0x6a, 0x6a, 0x6a, 0x6c, 0x6c,
+                0x6c, 0x6d, 0x6d, 0x6d, 0x6d, 0x6e, 0x6e, 0x6e,
+                0x6f, 0x6f, 0x6f, 0x6f, 0x70, 0x70, 0x70, 0x71,
+                0x71, 0x71, 0x71, 0x73, 0x73, 0x73, 0x74, 0x74,
+                0x74, 0x74, 0x75, 0x75, 0x75, 0x75, 0x77, 0x77,
+                0x77, 0x78, 0x78, 0x78, 0x78, 0x79, 0x79, 0x79,
+                0x79, 0x7a, 0x7a, 0x7a, 0x7a, 0x7b, 0x7b, 0x7b,
+                0x7b, 0x7c, 0x7c, 0x7c, 0x7c, 0x7d, 0x7d, 0x7d,
+                0x7d, 0x7f, 0x7f, 0x7f, 0x7f, 0x80, 0x80, 0x80,
+                0x80, 0x81, 0x81, 0x81, 0x81, 0x82, 0x82, 0x82,
+                0x82, 0x84, 0x84, 0x84, 0x84, 0x85, 0x85, 0x85,
+                0x85, 0x86, 0x86, 0x86, 0x86, 0x88, 0x88, 0x88,
+                0x88, 0x88, 0x89, 0x89, 0x89, 0x89, 0x8a, 0x8a,
+                0x8a, 0x8a, 0x8b, 0x8b, 0x8b, 0x8b, 0x8b, 0x8d,
+                0x8d, 0x8d, 0x8d, 0x8e, 0x8e, 0x8e, 0x8e, 0x8e,
+                0x8f, 0x8f, 0x8f, 0x8f, 0x90, 0x90, 0x90, 0x90,
+                0x90, 0x91, 0x91, 0x91, 0x91, 0x92, 0x92, 0x92,
+                0x92, 0x92, 0x93, 0x93, 0x93, 0x93, 0x94, 0x94,
+                0x94, 0x94, 0x94, 0x96, 0x96, 0x96, 0x96, 0x96,
+                0x97, 0x97, 0x97, 0x97, 0x97, 0x98, 0x98, 0x98,
+                0x98, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9a, 0x9a,
+                0x9a, 0x9a, 0x9a, 0x9b, 0x9b, 0x9b, 0x9b, 0x9b,
+                0x9c, 0x9c, 0x9c, 0x9c, 0x9c, 0x9d, 0x9d, 0x9d,
+                0x9d, 0x9d, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0xa0,
+                0xa0, 0xa0, 0xa0, 0xa0, 0xa1, 0xa1, 0xa1, 0xa1,
+                0xa1, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa3, 0xa3,
+                0xa3, 0xa3, 0xa3, 0xa4, 0xa4, 0xa4, 0xa4, 0xa4,
+                0xa4, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa6, 0xa6,
+                0xa6, 0xa6, 0xa6, 0xa8, 0xa8, 0xa8, 0xa8, 0xa8,
+                0xa9, 0xa9, 0xa9, 0xa9, 0xa9, 0xa9, 0xab, 0xab,
+                0xab, 0xab, 0xab, 0xac, 0xac, 0xac, 0xac, 0xac,
+                0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xae, 0xae,
+                0xae, 0xae, 0xae, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf,
+                0xaf, 0xb0, 0xb0, 0xb0, 0xb0, 0xb0, 0xb1, 0xb1,
+                0xb1, 0xb1, 0xb1, 0xb1, 0xb2, 0xb2, 0xb2, 0xb2,
+                0xb2, 0xb3, 0xb3, 0xb3, 0xb3, 0xb3, 0xb3, 0xb4,
+                0xb4, 0xb4, 0xb4, 0xb4, 0xb6, 0xb6, 0xb6, 0xb6,
+                0xb6, 0xb6, 0xb7, 0xb7, 0xb7, 0xb7, 0xb7, 0xb7,
+                0xb8, 0xb8, 0xb8, 0xb8, 0xb8, 0xb9, 0xb9, 0xb9,
+                0xb9, 0xb9, 0xb9, 0xba, 0xba, 0xba, 0xba, 0xba,
+                0xba, 0xbc, 0xbc, 0xbc, 0xbc, 0xbc, 0xbd, 0xbd,
+                0xbd, 0xbd, 0xbd, 0xbd, 0xbe, 0xbe, 0xbe, 0xbe,
+                0xbe, 0xbe, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf,
+                0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc2, 0xc2,
+                0xc2, 0xc2, 0xc2, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3,
+                0xc3, 0xc4, 0xc4, 0xc4, 0xc4, 0xc4, 0xc4, 0xc5,
+                0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 0xc6, 0xc6, 0xc6,
+                0xc6, 0xc6, 0xc6, 0xc7, 0xc7, 0xc7, 0xc7, 0xc7,
+                0xc7, 0xc9, 0xc9, 0xc9, 0xc9, 0xc9, 0xca, 0xca,
+                0xca, 0xca, 0xca, 0xca, 0xcb, 0xcb, 0xcb, 0xcb,
+                0xcb, 0xcb, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
+                0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xce, 0xce,
+                0xce, 0xce, 0xce, 0xce, 0xcf, 0xcf, 0xcf, 0xcf,
+                0xcf, 0xcf, 0xd0, 0xd0, 0xd0, 0xd0, 0xd0, 0xd0,
+                0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd3, 0xd3,
+                0xd3, 0xd3, 0xd3, 0xd4, 0xd4, 0xd4, 0xd4, 0xd4,
+                0xd4, 0xd6, 0xd6, 0xd6, 0xd6, 0xd6, 0xd6, 0xd7,
+                0xd7, 0xd7, 0xd7, 0xd7, 0xd7, 0xd8, 0xd8, 0xd8,
+                0xd8, 0xd8, 0xd8, 0xd9, 0xd9, 0xd9, 0xd9, 0xd9,
+                0xd9, 0xda, 0xda, 0xda, 0xda, 0xda, 0xda, 0xdb,
+                0xdb, 0xdb, 0xdb, 0xdb, 0xdd, 0xdd, 0xdd, 0xdd,
+                0xdd, 0xdd, 0xde, 0xde, 0xde, 0xde, 0xde, 0xde,
+                0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xe0, 0xe0,
+                0xe0, 0xe0, 0xe0, 0xe0, 0xe1, 0xe1, 0xe1, 0xe1,
+                0xe1, 0xe2, 0xe2, 0xe2, 0xe2, 0xe2, 0xe2, 0xe3,
+                0xe3, 0xe3, 0xe3, 0xe3, 0xe3, 0xe4, 0xe4, 0xe4,
+                0xe4, 0xe4, 0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 0xe5,
+                0xe6, 0xe6, 0xe6, 0xe6, 0xe6, 0xe6, 0xe7, 0xe7,
+                0xe7, 0xe7, 0xe7, 0xe8, 0xe8, 0xe8, 0xe8, 0xe8,
+                0xe8, 0xe9, 0xe9, 0xe9, 0xe9, 0xe9, 0xeb, 0xeb,
+                0xeb, 0xeb, 0xeb, 0xeb, 0xec, 0xec, 0xec, 0xec,
+                0xec, 0xed, 0xed, 0xed, 0xed, 0xed, 0xed, 0xee,
+                0xee, 0xee, 0xee, 0xee, 0xef, 0xef, 0xef, 0xef,
+                0xef, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf1,
+                0xf1, 0xf1, 0xf1, 0xf1, 0xf3, 0xf3, 0xf3, 0xf3,
+                0xf3, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf5, 0xf5,
+                0xf5, 0xf5, 0xf5, 0xf6, 0xf6, 0xf6, 0xf6, 0xf6,
+                0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf8, 0xf8, 0xf8,
+                0xf8, 0xf8, 0xf9, 0xf9, 0xf9, 0xf9, 0xf9, 0xfa,
+                0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa,
+                0xfa, 0xfb, 0xfb, 0xfb, 0xfb, 0xfc, 0xfc, 0xfc,
+                0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfd,
+                0xfd, 0xfd, 0xfd, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
+           },
+           {                                                   /* gamma 2 */
+               {0x00, 0x01, 0x02, 0x05, 0x07, 0x08, 0x0a, 0x0c,
+                0x0d, 0x0e, 0x10, 0x12, 0x14, 0x15, 0x16, 0x17,
+                0x18, 0x1a, 0x1b, 0x1c, 0x1e, 0x1f, 0x20, 0x22,
+                0x23, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2b, 0x2c,
+                0x2d, 0x2d, 0x2f, 0x30, 0x31, 0x33, 0x34, 0x34,
+                0x35, 0x37, 0x38, 0x38, 0x39, 0x3a, 0x3b, 0x3b,
+                0x3c, 0x3d, 0x3f, 0x3f, 0x40, 0x42, 0x42, 0x43,
+                0x44, 0x44, 0x45, 0x47, 0x47, 0x48, 0x49, 0x49,
+                0x4a, 0x4b, 0x4b, 0x4c, 0x4c, 0x4d, 0x4f, 0x4f,
+                0x50, 0x50, 0x52, 0x53, 0x53, 0x54, 0x54, 0x55,
+                0x55, 0x56, 0x56, 0x58, 0x58, 0x59, 0x5a, 0x5a,
+                0x5b, 0x5b, 0x5c, 0x5c, 0x5e, 0x5e, 0x5f, 0x5f,
+                0x60, 0x60, 0x61, 0x61, 0x62, 0x62, 0x63, 0x63,
+                0x65, 0x65, 0x65, 0x66, 0x66, 0x67, 0x67, 0x68,
+                0x68, 0x69, 0x69, 0x6a, 0x6a, 0x6a, 0x6c, 0x6c,
+                0x6d, 0x6d, 0x6e, 0x6e, 0x6e, 0x6f, 0x6f, 0x70,
+                0x70, 0x70, 0x71, 0x71, 0x73, 0x73, 0x73, 0x74,
+                0x74, 0x75, 0x75, 0x75, 0x77, 0x77, 0x78, 0x78,
+                0x78, 0x79, 0x79, 0x79, 0x7a, 0x7a, 0x7b, 0x7b,
+                0x7b, 0x7c, 0x7c, 0x7c, 0x7d, 0x7d, 0x7f, 0x7f,
+                0x7f, 0x80, 0x80, 0x80, 0x81, 0x81, 0x81, 0x82,
+                0x82, 0x82, 0x84, 0x84, 0x84, 0x85, 0x85, 0x85,
+                0x86, 0x86, 0x86, 0x88, 0x88, 0x88, 0x89, 0x89,
+                0x89, 0x8a, 0x8a, 0x8a, 0x8b, 0x8b, 0x8b, 0x8d,
+                0x8d, 0x8d, 0x8d, 0x8e, 0x8e, 0x8e, 0x8f, 0x8f,
+                0x8f, 0x90, 0x90, 0x90, 0x91, 0x91, 0x91, 0x91,
+                0x92, 0x92, 0x92, 0x93, 0x93, 0x93, 0x93, 0x94,
+                0x94, 0x94, 0x96, 0x96, 0x96, 0x97, 0x97, 0x97,
+                0x97, 0x98, 0x98, 0x98, 0x98, 0x99, 0x99, 0x99,
+                0x9a, 0x9a, 0x9a, 0x9a, 0x9b, 0x9b, 0x9b, 0x9b,
+                0x9c, 0x9c, 0x9c, 0x9d, 0x9d, 0x9d, 0x9d, 0x9e,
+                0x9e, 0x9e, 0x9e, 0xa0, 0xa0, 0xa0, 0xa0, 0xa1,
+                0xa1, 0xa1, 0xa1, 0xa2, 0xa2, 0xa2, 0xa2, 0xa3,
+                0xa3, 0xa3, 0xa4, 0xa4, 0xa4, 0xa4, 0xa5, 0xa5,
+                0xa5, 0xa5, 0xa5, 0xa6, 0xa6, 0xa6, 0xa6, 0xa8,
+                0xa8, 0xa8, 0xa8, 0xa9, 0xa9, 0xa9, 0xa9, 0xab,
+                0xab, 0xab, 0xab, 0xac, 0xac, 0xac, 0xac, 0xad,
+                0xad, 0xad, 0xad, 0xad, 0xae, 0xae, 0xae, 0xae,
+                0xaf, 0xaf, 0xaf, 0xaf, 0xb0, 0xb0, 0xb0, 0xb0,
+                0xb0, 0xb1, 0xb1, 0xb1, 0xb1, 0xb2, 0xb2, 0xb2,
+                0xb2, 0xb2, 0xb3, 0xb3, 0xb3, 0xb3, 0xb4, 0xb4,
+                0xb4, 0xb4, 0xb4, 0xb6, 0xb6, 0xb6, 0xb6, 0xb7,
+                0xb7, 0xb7, 0xb7, 0xb7, 0xb8, 0xb8, 0xb8, 0xb8,
+                0xb8, 0xb9, 0xb9, 0xb9, 0xb9, 0xba, 0xba, 0xba,
+                0xba, 0xba, 0xbc, 0xbc, 0xbc, 0xbc, 0xbc, 0xbd,
+                0xbd, 0xbd, 0xbd, 0xbd, 0xbe, 0xbe, 0xbe, 0xbe,
+                0xbe, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xc0, 0xc0,
+                0xc0, 0xc0, 0xc0, 0xc2, 0xc2, 0xc2, 0xc2, 0xc3,
+                0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc4, 0xc4, 0xc4,
+                0xc4, 0xc4, 0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 0xc6,
+                0xc6, 0xc6, 0xc6, 0xc6, 0xc7, 0xc7, 0xc7, 0xc7,
+                0xc7, 0xc9, 0xc9, 0xc9, 0xc9, 0xc9, 0xca, 0xca,
+                0xca, 0xca, 0xca, 0xcb, 0xcb, 0xcb, 0xcb, 0xcb,
+                0xcb, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcd, 0xcd,
+                0xcd, 0xcd, 0xcd, 0xce, 0xce, 0xce, 0xce, 0xce,
+                0xce, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xd0, 0xd0,
+                0xd0, 0xd0, 0xd0, 0xd0, 0xd1, 0xd1, 0xd1, 0xd1,
+                0xd1, 0xd3, 0xd3, 0xd3, 0xd3, 0xd3, 0xd4, 0xd4,
+                0xd4, 0xd4, 0xd4, 0xd4, 0xd6, 0xd6, 0xd6, 0xd6,
+                0xd6, 0xd6, 0xd7, 0xd7, 0xd7, 0xd7, 0xd7, 0xd8,
+                0xd8, 0xd8, 0xd8, 0xd8, 0xd8, 0xd9, 0xd9, 0xd9,
+                0xd9, 0xd9, 0xda, 0xda, 0xda, 0xda, 0xda, 0xda,
+                0xdb, 0xdb, 0xdb, 0xdb, 0xdb, 0xdb, 0xdd, 0xdd,
+                0xdd, 0xdd, 0xdd, 0xde, 0xde, 0xde, 0xde, 0xde,
+                0xde, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xe0,
+                0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe1, 0xe1, 0xe1,
+                0xe1, 0xe1, 0xe1, 0xe2, 0xe2, 0xe2, 0xe2, 0xe2,
+                0xe3, 0xe3, 0xe3, 0xe3, 0xe3, 0xe3, 0xe4, 0xe4,
+                0xe4, 0xe4, 0xe4, 0xe4, 0xe5, 0xe5, 0xe5, 0xe5,
+                0xe5, 0xe5, 0xe6, 0xe6, 0xe6, 0xe6, 0xe6, 0xe6,
+                0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe8, 0xe8,
+                0xe8, 0xe8, 0xe8, 0xe8, 0xe9, 0xe9, 0xe9, 0xe9,
+                0xe9, 0xe9, 0xeb, 0xeb, 0xeb, 0xeb, 0xeb, 0xeb,
+                0xec, 0xec, 0xec, 0xec, 0xec, 0xed, 0xed, 0xed,
+                0xed, 0xed, 0xed, 0xee, 0xee, 0xee, 0xee, 0xee,
+                0xee, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xf0,
+                0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf1, 0xf1, 0xf1,
+                0xf1, 0xf1, 0xf1, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3,
+                0xf3, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf5,
+                0xf5, 0xf5, 0xf5, 0xf5, 0xf5, 0xf6, 0xf6, 0xf6,
+                0xf6, 0xf6, 0xf6, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7,
+                0xf7, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf9,
+                0xf9, 0xf9, 0xf9, 0xf9, 0xf9, 0xfa, 0xfa, 0xfa,
+                0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa,
+                0xfa, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb},
+               {0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x05,
+                0x07, 0x08, 0x09, 0x0a, 0x0d, 0x0e, 0x10, 0x11,
+                0x12, 0x14, 0x15, 0x16, 0x16, 0x17, 0x18, 0x1a,
+                0x1b, 0x1c, 0x1e, 0x1f, 0x20, 0x20, 0x22, 0x23,
+                0x25, 0x26, 0x26, 0x27, 0x28, 0x29, 0x29, 0x2b,
+                0x2c, 0x2d, 0x2d, 0x2f, 0x30, 0x30, 0x31, 0x33,
+                0x33, 0x34, 0x35, 0x35, 0x37, 0x38, 0x38, 0x39,
+                0x3a, 0x3a, 0x3b, 0x3b, 0x3c, 0x3d, 0x3d, 0x3f,
+                0x3f, 0x40, 0x42, 0x42, 0x43, 0x43, 0x44, 0x44,
+                0x45, 0x45, 0x47, 0x47, 0x48, 0x48, 0x49, 0x4a,
+                0x4a, 0x4b, 0x4b, 0x4c, 0x4c, 0x4d, 0x4d, 0x4d,
+                0x4f, 0x4f, 0x50, 0x50, 0x52, 0x52, 0x53, 0x53,
+                0x54, 0x54, 0x55, 0x55, 0x56, 0x56, 0x56, 0x58,
+                0x58, 0x59, 0x59, 0x5a, 0x5a, 0x5a, 0x5b, 0x5b,
+                0x5c, 0x5c, 0x5c, 0x5e, 0x5e, 0x5f, 0x5f, 0x5f,
+                0x60, 0x60, 0x61, 0x61, 0x61, 0x62, 0x62, 0x63,
+                0x63, 0x63, 0x65, 0x65, 0x65, 0x66, 0x66, 0x67,
+                0x67, 0x67, 0x68, 0x68, 0x68, 0x69, 0x69, 0x69,
+                0x6a, 0x6a, 0x6c, 0x6c, 0x6c, 0x6d, 0x6d, 0x6d,
+                0x6e, 0x6e, 0x6e, 0x6f, 0x6f, 0x6f, 0x70, 0x70,
+                0x70, 0x71, 0x71, 0x71, 0x73, 0x73, 0x73, 0x73,
+                0x74, 0x74, 0x74, 0x75, 0x75, 0x75, 0x77, 0x77,
+                0x77, 0x78, 0x78, 0x78, 0x79, 0x79, 0x79, 0x79,
+                0x7a, 0x7a, 0x7a, 0x7b, 0x7b, 0x7b, 0x7b, 0x7c,
+                0x7c, 0x7c, 0x7d, 0x7d, 0x7d, 0x7d, 0x7f, 0x7f,
+                0x7f, 0x80, 0x80, 0x80, 0x80, 0x81, 0x81, 0x81,
+                0x82, 0x82, 0x82, 0x82, 0x84, 0x84, 0x84, 0x84,
+                0x85, 0x85, 0x85, 0x85, 0x86, 0x86, 0x86, 0x88,
+                0x88, 0x88, 0x88, 0x89, 0x89, 0x89, 0x89, 0x8a,
+                0x8a, 0x8a, 0x8a, 0x8b, 0x8b, 0x8b, 0x8b, 0x8d,
+                0x8d, 0x8d, 0x8d, 0x8e, 0x8e, 0x8e, 0x8e, 0x8f,
+                0x8f, 0x8f, 0x8f, 0x90, 0x90, 0x90, 0x90, 0x91,
+                0x91, 0x91, 0x91, 0x91, 0x92, 0x92, 0x92, 0x92,
+                0x93, 0x93, 0x93, 0x93, 0x94, 0x94, 0x94, 0x94,
+                0x94, 0x96, 0x96, 0x96, 0x96, 0x97, 0x97, 0x97,
+                0x97, 0x98, 0x98, 0x98, 0x98, 0x98, 0x99, 0x99,
+                0x99, 0x99, 0x99, 0x9a, 0x9a, 0x9a, 0x9a, 0x9b,
+                0x9b, 0x9b, 0x9b, 0x9b, 0x9c, 0x9c, 0x9c, 0x9c,
+                0x9d, 0x9d, 0x9d, 0x9d, 0x9d, 0x9e, 0x9e, 0x9e,
+                0x9e, 0x9e, 0xa0, 0xa0, 0xa0, 0xa0, 0xa0, 0xa1,
+                0xa1, 0xa1, 0xa1, 0xa1, 0xa2, 0xa2, 0xa2, 0xa2,
+                0xa2, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa4, 0xa4,
+                0xa4, 0xa4, 0xa4, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5,
+                0xa6, 0xa6, 0xa6, 0xa6, 0xa6, 0xa8, 0xa8, 0xa8,
+                0xa8, 0xa8, 0xa9, 0xa9, 0xa9, 0xa9, 0xa9, 0xab,
+                0xab, 0xab, 0xab, 0xab, 0xac, 0xac, 0xac, 0xac,
+                0xac, 0xac, 0xad, 0xad, 0xad, 0xad, 0xad, 0xae,
+                0xae, 0xae, 0xae, 0xae, 0xaf, 0xaf, 0xaf, 0xaf,
+                0xaf, 0xaf, 0xb0, 0xb0, 0xb0, 0xb0, 0xb0, 0xb1,
+                0xb1, 0xb1, 0xb1, 0xb1, 0xb1, 0xb2, 0xb2, 0xb2,
+                0xb2, 0xb2, 0xb3, 0xb3, 0xb3, 0xb3, 0xb3, 0xb3,
+                0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0xb6, 0xb6,
+                0xb6, 0xb6, 0xb6, 0xb7, 0xb7, 0xb7, 0xb7, 0xb7,
+                0xb7, 0xb8, 0xb8, 0xb8, 0xb8, 0xb8, 0xb8, 0xb9,
+                0xb9, 0xb9, 0xb9, 0xb9, 0xba, 0xba, 0xba, 0xba,
+                0xba, 0xba, 0xbc, 0xbc, 0xbc, 0xbc, 0xbc, 0xbc,
+                0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbe, 0xbe,
+                0xbe, 0xbe, 0xbe, 0xbe, 0xbf, 0xbf, 0xbf, 0xbf,
+                0xbf, 0xbf, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0,
+                0xc2, 0xc2, 0xc2, 0xc2, 0xc2, 0xc2, 0xc3, 0xc3,
+                0xc3, 0xc3, 0xc3, 0xc3, 0xc4, 0xc4, 0xc4, 0xc4,
+                0xc4, 0xc4, 0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 0xc5,
+                0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc7, 0xc7,
+                0xc7, 0xc7, 0xc7, 0xc7, 0xc7, 0xc9, 0xc9, 0xc9,
+                0xc9, 0xc9, 0xc9, 0xca, 0xca, 0xca, 0xca, 0xca,
+                0xca, 0xcb, 0xcb, 0xcb, 0xcb, 0xcb, 0xcb, 0xcc,
+                0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcd, 0xcd,
+                0xcd, 0xcd, 0xcd, 0xcd, 0xce, 0xce, 0xce, 0xce,
+                0xce, 0xce, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf,
+                0xcf, 0xd0, 0xd0, 0xd0, 0xd0, 0xd0, 0xd0, 0xd1,
+                0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd3, 0xd3,
+                0xd3, 0xd3, 0xd3, 0xd3, 0xd4, 0xd4, 0xd4, 0xd4,
+                0xd4, 0xd4, 0xd6, 0xd6, 0xd6, 0xd6, 0xd6, 0xd6,
+                0xd6, 0xd7, 0xd7, 0xd7, 0xd7, 0xd7, 0xd7, 0xd8,
+                0xd8, 0xd8, 0xd8, 0xd8, 0xd8, 0xd8, 0xd9, 0xd9,
+                0xd9, 0xd9, 0xd9, 0xd9, 0xda, 0xda, 0xda, 0xda,
+                0xda, 0xda, 0xda, 0xdb, 0xdb, 0xdb, 0xdb, 0xdb,
+                0xdb, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
+                0xde, 0xde, 0xde, 0xde, 0xde, 0xde, 0xdf, 0xdf,
+                0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xe0, 0xe0, 0xe0,
+                0xe0, 0xe0, 0xe0, 0xe1, 0xe1, 0xe1, 0xe1, 0xe1,
+                0xe1, 0xe1, 0xe2, 0xe2, 0xe2, 0xe2, 0xe2, 0xe2,
+                0xe3, 0xe3, 0xe3, 0xe3, 0xe3, 0xe3, 0xe3, 0xe4,
+                0xe4, 0xe4, 0xe4, 0xe4, 0xe4, 0xe5, 0xe5, 0xe5,
+                0xe5, 0xe5, 0xe5, 0xe5, 0xe6, 0xe6, 0xe6, 0xe6,
+                0xe6, 0xe6, 0xe6, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7,
+                0xe8, 0xe8, 0xe8, 0xe8, 0xe8, 0xe8, 0xe8, 0xe9,
+                0xe9, 0xe9, 0xe9, 0xe9, 0xe9, 0xeb, 0xeb, 0xeb,
+                0xeb, 0xeb, 0xeb, 0xeb, 0xec, 0xec, 0xec, 0xec,
+                0xec, 0xec, 0xed, 0xed, 0xed, 0xed, 0xed, 0xed,
+                0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xef,
+                0xef, 0xef, 0xef, 0xef, 0xef, 0xf0, 0xf0, 0xf0,
+                0xf0, 0xf0, 0xf0, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1,
+                0xf1, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf4,
+                0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf5, 0xf5,
+                0xf5, 0xf5, 0xf5, 0xf5, 0xf6, 0xf6, 0xf6, 0xf6,
+                0xf6, 0xf6, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7,
+                0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf9, 0xf9,
+                0xf9, 0xf9, 0xf9, 0xf9, 0xfa, 0xfa, 0xfa, 0xfa,
+                0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb},
+               {0x00, 0x00, 0x00, 0x01, 0x02, 0x05, 0x07, 0x08,
+                0x09, 0x0a, 0x0c, 0x0e, 0x10, 0x11, 0x12, 0x14,
+                0x15, 0x16, 0x17, 0x18, 0x1a, 0x1b, 0x1c, 0x1e,
+                0x1f, 0x20, 0x20, 0x22, 0x23, 0x25, 0x26, 0x27,
+                0x28, 0x28, 0x29, 0x2b, 0x2c, 0x2d, 0x2d, 0x2f,
+                0x30, 0x31, 0x31, 0x33, 0x34, 0x35, 0x35, 0x37,
+                0x38, 0x38, 0x39, 0x3a, 0x3a, 0x3b, 0x3c, 0x3c,
+                0x3d, 0x3f, 0x3f, 0x40, 0x40, 0x42, 0x43, 0x43,
+                0x44, 0x44, 0x45, 0x47, 0x47, 0x48, 0x48, 0x49,
+                0x4a, 0x4a, 0x4b, 0x4b, 0x4c, 0x4c, 0x4d, 0x4d,
+                0x4f, 0x4f, 0x50, 0x50, 0x52, 0x52, 0x53, 0x53,
+                0x54, 0x54, 0x55, 0x55, 0x56, 0x56, 0x58, 0x58,
+                0x59, 0x59, 0x5a, 0x5a, 0x5b, 0x5b, 0x5c, 0x5c,
+                0x5c, 0x5e, 0x5e, 0x5f, 0x5f, 0x60, 0x60, 0x61,
+                0x61, 0x61, 0x62, 0x62, 0x63, 0x63, 0x65, 0x65,
+                0x65, 0x66, 0x66, 0x67, 0x67, 0x67, 0x68, 0x68,
+                0x69, 0x69, 0x69, 0x6a, 0x6a, 0x6a, 0x6c, 0x6c,
+                0x6d, 0x6d, 0x6d, 0x6e, 0x6e, 0x6e, 0x6f, 0x6f,
+                0x70, 0x70, 0x70, 0x71, 0x71, 0x71, 0x73, 0x73,
+                0x73, 0x74, 0x74, 0x74, 0x75, 0x75, 0x75, 0x77,
+                0x77, 0x78, 0x78, 0x78, 0x79, 0x79, 0x79, 0x7a,
+                0x7a, 0x7a, 0x7a, 0x7b, 0x7b, 0x7b, 0x7c, 0x7c,
+                0x7c, 0x7d, 0x7d, 0x7d, 0x7f, 0x7f, 0x7f, 0x80,
+                0x80, 0x80, 0x81, 0x81, 0x81, 0x81, 0x82, 0x82,
+                0x82, 0x84, 0x84, 0x84, 0x85, 0x85, 0x85, 0x85,
+                0x86, 0x86, 0x86, 0x88, 0x88, 0x88, 0x88, 0x89,
+                0x89, 0x89, 0x8a, 0x8a, 0x8a, 0x8a, 0x8b, 0x8b,
+                0x8b, 0x8b, 0x8d, 0x8d, 0x8d, 0x8e, 0x8e, 0x8e,
+                0x8e, 0x8f, 0x8f, 0x8f, 0x8f, 0x90, 0x90, 0x90,
+                0x91, 0x91, 0x91, 0x91, 0x92, 0x92, 0x92, 0x92,
+                0x93, 0x93, 0x93, 0x93, 0x94, 0x94, 0x94, 0x94,
+                0x96, 0x96, 0x96, 0x96, 0x97, 0x97, 0x97, 0x97,
+                0x98, 0x98, 0x98, 0x98, 0x99, 0x99, 0x99, 0x99,
+                0x9a, 0x9a, 0x9a, 0x9a, 0x9b, 0x9b, 0x9b, 0x9b,
+                0x9b, 0x9c, 0x9c, 0x9c, 0x9c, 0x9d, 0x9d, 0x9d,
+                0x9d, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0xa0, 0xa0,
+                0xa0, 0xa0, 0xa1, 0xa1, 0xa1, 0xa1, 0xa2, 0xa2,
+                0xa2, 0xa2, 0xa2, 0xa3, 0xa3, 0xa3, 0xa3, 0xa4,
+                0xa4, 0xa4, 0xa4, 0xa4, 0xa5, 0xa5, 0xa5, 0xa5,
+                0xa5, 0xa6, 0xa6, 0xa6, 0xa6, 0xa8, 0xa8, 0xa8,
+                0xa8, 0xa8, 0xa9, 0xa9, 0xa9, 0xa9, 0xa9, 0xab,
+                0xab, 0xab, 0xab, 0xab, 0xac, 0xac, 0xac, 0xac,
+                0xad, 0xad, 0xad, 0xad, 0xad, 0xae, 0xae, 0xae,
+                0xae, 0xae, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xb0,
+                0xb0, 0xb0, 0xb0, 0xb0, 0xb1, 0xb1, 0xb1, 0xb1,
+                0xb1, 0xb2, 0xb2, 0xb2, 0xb2, 0xb2, 0xb3, 0xb3,
+                0xb3, 0xb3, 0xb3, 0xb4, 0xb3, 0xb4, 0xb4, 0xb4,
+                0xb6, 0xb6, 0xb6, 0xb6, 0xb6, 0xb6, 0xb7, 0xb7,
+                0xb7, 0xb7, 0xb7, 0xb8, 0xb8, 0xb8, 0xb8, 0xb8,
+                0xb9, 0xb9, 0xb9, 0xb9, 0xb9, 0xb9, 0xba, 0xba,
+                0xba, 0xba, 0xba, 0xbc, 0xbc, 0xbc, 0xbc, 0xbc,
+                0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbe, 0xbe,
+                0xbe, 0xbe, 0xbe, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf,
+                0xbf, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc2, 0xc2,
+                0xc2, 0xc2, 0xc2, 0xc2, 0xc3, 0xc3, 0xc3, 0xc3,
+                0xc3, 0xc3, 0xc4, 0xc4, 0xc4, 0xc4, 0xc4, 0xc5,
+                0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 0xc6, 0xc6, 0xc6,
+                0xc6, 0xc6, 0xc6, 0xc7, 0xc7, 0xc7, 0xc7, 0xc7,
+                0xc9, 0xc9, 0xc9, 0xc9, 0xc9, 0xc9, 0xca, 0xca,
+                0xca, 0xca, 0xca, 0xca, 0xcb, 0xcb, 0xcb, 0xcb,
+                0xcb, 0xcb, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
+                0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xce, 0xce,
+                0xce, 0xce, 0xce, 0xce, 0xcf, 0xcf, 0xcf, 0xcf,
+                0xcf, 0xcf, 0xd0, 0xd0, 0xd0, 0xd0, 0xd0, 0xd0,
+                0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd3, 0xd3,
+                0xd3, 0xd3, 0xd3, 0xd3, 0xd4, 0xd4, 0xd4, 0xd4,
+                0xd4, 0xd4, 0xd6, 0xd6, 0xd6, 0xd6, 0xd6, 0xd6,
+                0xd7, 0xd7, 0xd7, 0xd7, 0xd7, 0xd7, 0xd8, 0xd8,
+                0xd8, 0xd8, 0xd8, 0xd8, 0xd9, 0xd9, 0xd9, 0xd9,
+                0xd9, 0xd9, 0xda, 0xda, 0xda, 0xda, 0xda, 0xda,
+                0xda, 0xdb, 0xdb, 0xdb, 0xdb, 0xdb, 0xdb, 0xdd,
+                0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xde, 0xde, 0xde,
+                0xde, 0xde, 0xde, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf,
+                0xdf, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0,
+                0xe1, 0xe1, 0xe1, 0xe1, 0xe1, 0xe1, 0xe2, 0xe2,
+                0xe2, 0xe2, 0xe2, 0xe2, 0xe3, 0xe3, 0xe3, 0xe3,
+                0xe3, 0xe3, 0xe4, 0xe4, 0xe4, 0xe4, 0xe4, 0xe4,
+                0xe4, 0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 0xe6,
+                0xe6, 0xe6, 0xe6, 0xe6, 0xe6, 0xe7, 0xe7, 0xe7,
+                0xe7, 0xe7, 0xe7, 0xe8, 0xe8, 0xe8, 0xe8, 0xe8,
+                0xe8, 0xe8, 0xe9, 0xe9, 0xe9, 0xe9, 0xe9, 0xe9,
+                0xeb, 0xeb, 0xeb, 0xeb, 0xeb, 0xeb, 0xec, 0xec,
+                0xec, 0xec, 0xec, 0xec, 0xec, 0xed, 0xed, 0xed,
+                0xed, 0xed, 0xed, 0xee, 0xee, 0xee, 0xee, 0xee,
+                0xee, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xf0,
+                0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf1, 0xf1,
+                0xf1, 0xf1, 0xf1, 0xf1, 0xf3, 0xf3, 0xf3, 0xf3,
+                0xf3, 0xf3, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4,
+                0xf5, 0xf5, 0xf5, 0xf5, 0xf5, 0xf5, 0xf6, 0xf6,
+                0xf6, 0xf6, 0xf6, 0xf6, 0xf7, 0xf7, 0xf7, 0xf7,
+                0xf7, 0xf7, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8,
+                0xf8, 0xf9, 0xf9, 0xf9, 0xf9, 0xf9, 0xf9, 0xfa,
+                0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa,
+                0xfa, 0xfa, 0xfa, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb}
+           },
+           {                           /* gamma 3 - from tp6810 + cx0342 */
+               {0x08, 0x09, 0x0c, 0x0d, 0x10, 0x11, 0x14, 0x15,
+                0x17, 0x18, 0x1a, 0x1c, 0x1e, 0x1f, 0x20, 0x23,
+                0x25, 0x26, 0x27, 0x28, 0x2b, 0x2c, 0x2d, 0x2f,
+                0x30, 0x31, 0x33, 0x34, 0x35, 0x37, 0x38, 0x39,
+                0x3a, 0x3b, 0x3c, 0x3d, 0x3f, 0x40, 0x42, 0x43,
+                0x44, 0x45, 0x47, 0x48, 0x48, 0x49, 0x4a, 0x4b,
+                0x4c, 0x4d, 0x4d, 0x4f, 0x50, 0x52, 0x53, 0x53,
+                0x54, 0x55, 0x56, 0x56, 0x58, 0x59, 0x5a, 0x5a,
+                0x5b, 0x5c, 0x5c, 0x5e, 0x5f, 0x5f, 0x60, 0x61,
+                0x61, 0x62, 0x63, 0x63, 0x65, 0x66, 0x66, 0x67,
+                0x68, 0x68, 0x69, 0x69, 0x6a, 0x6c, 0x6c, 0x6d,
+                0x6d, 0x6e, 0x6f, 0x6f, 0x70, 0x70, 0x71, 0x73,
+                0x73, 0x74, 0x74, 0x75, 0x75, 0x77, 0x77, 0x78,
+                0x78, 0x79, 0x7a, 0x7a, 0x7b, 0x7b, 0x7c, 0x7c,
+                0x7d, 0x7d, 0x7f, 0x7f, 0x80, 0x80, 0x81, 0x81,
+                0x82, 0x82, 0x84, 0x84, 0x85, 0x85, 0x86, 0x86,
+                0x86, 0x88, 0x88, 0x89, 0x89, 0x8a, 0x8a, 0x8b,
+                0x8b, 0x8d, 0x8d, 0x8d, 0x8e, 0x8e, 0x8f, 0x8f,
+                0x90, 0x90, 0x91, 0x91, 0x91, 0x92, 0x92, 0x93,
+                0x93, 0x93, 0x94, 0x94, 0x96, 0x96, 0x97, 0x97,
+                0x97, 0x98, 0x98, 0x99, 0x99, 0x99, 0x9a, 0x9a,
+                0x9a, 0x9b, 0x9b, 0x9c, 0x9c, 0x9c, 0x9d, 0x9d,
+                0x9e, 0x9e, 0x9e, 0xa0, 0xa0, 0xa0, 0xa1, 0xa1,
+                0xa2, 0xa2, 0xa2, 0xa3, 0xa3, 0xa3, 0xa4, 0xa4,
+                0xa4, 0xa5, 0xa5, 0xa5, 0xa6, 0xa6, 0xa8, 0xa8,
+                0xa8, 0xa9, 0xa9, 0xa9, 0xab, 0xab, 0xab, 0xac,
+                0xac, 0xac, 0xad, 0xad, 0xad, 0xae, 0xae, 0xae,
+                0xaf, 0xaf, 0xaf, 0xb0, 0xb0, 0xb0, 0xb1, 0xb1,
+                0xb1, 0xb2, 0xb2, 0xb2, 0xb2, 0xb3, 0xb3, 0xb3,
+                0xb4, 0xb4, 0xb4, 0xb6, 0xb6, 0xb6, 0xb7, 0xb7,
+                0xb7, 0xb8, 0xb8, 0xb8, 0xb8, 0xb9, 0xb9, 0xb9,
+                0xba, 0xba, 0xba, 0xbc, 0xbc, 0xbc, 0xbc, 0xbd,
+                0xbd, 0xbd, 0xbe, 0xbe, 0xbe, 0xbe, 0xbf, 0xbf,
+                0xbf, 0xc0, 0xc0, 0xc0, 0xc0, 0xc2, 0xc2, 0xc2,
+                0xc3, 0xc3, 0xc3, 0xc3, 0xc4, 0xc4, 0xc4, 0xc5,
+                0xc5, 0xc5, 0xc5, 0xc6, 0xc6, 0xc6, 0xc6, 0xc7,
+                0xc7, 0xc7, 0xc9, 0xc9, 0xc9, 0xc9, 0xca, 0xca,
+                0xca, 0xca, 0xcb, 0xcb, 0xcb, 0xcb, 0xcc, 0xcc,
+                0xcc, 0xcd, 0xcd, 0xcd, 0xcd, 0xce, 0xce, 0xce,
+                0xce, 0xcf, 0xcf, 0xcf, 0xcf, 0xd0, 0xd0, 0xd0,
+                0xd0, 0xd1, 0xd1, 0xd1, 0xd1, 0xd3, 0xd3, 0xd3,
+                0xd3, 0xd4, 0xd4, 0xd4, 0xd4, 0xd6, 0xd6, 0xd6,
+                0xd6, 0xd7, 0xd7, 0xd7, 0xd7, 0xd8, 0xd8, 0xd8,
+                0xd8, 0xd9, 0xd9, 0xd9, 0xd9, 0xda, 0xda, 0xda,
+                0xda, 0xda, 0xdb, 0xdb, 0xdb, 0xdb, 0xdd, 0xdd,
+                0xdd, 0xdd, 0xde, 0xde, 0xde, 0xde, 0xdf, 0xdf,
+                0xdf, 0xdf, 0xdf, 0xe0, 0xe0, 0xe0, 0xe0, 0xe1,
+                0xe1, 0xe1, 0xe1, 0xe2, 0xe2, 0xe2, 0xe2, 0xe2,
+                0xe3, 0xe3, 0xe3, 0xe3, 0xe4, 0xe4, 0xe4, 0xe4,
+                0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 0xe6, 0xe6, 0xe6,
+                0xe6, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe8, 0xe8,
+                0xe8, 0xe8, 0xe8, 0xe9, 0xe9, 0xe9, 0xe9, 0xeb,
+                0xeb, 0xeb, 0xeb, 0xeb, 0xec, 0xec, 0xec, 0xec,
+                0xed, 0xed, 0xed, 0xed, 0xed, 0xee, 0xee, 0xee,
+                0xee, 0xee, 0xef, 0xef, 0xef, 0xef, 0xf0, 0xf0,
+                0xf0, 0xf0, 0xf0, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1,
+                0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf4, 0xf4, 0xf4,
+                0xf4, 0xf4, 0xf5, 0xf5, 0xf5, 0xf5, 0xf6, 0xf6,
+                0xf6, 0xf6, 0xf6, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7,
+                0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf9, 0xf9, 0xf9,
+                0xf9, 0xf9, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa,
+                0xfa, 0xfa, 0xfa, 0xfa, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc,
+                0xfc, 0xfc, 0xfc, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd,
+                0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
+               {0x03, 0x05, 0x07, 0x09, 0x0a, 0x0c, 0x0d, 0x10,
+                0x11, 0x12, 0x14, 0x15, 0x17, 0x18, 0x1a, 0x1b,
+                0x1c, 0x1e, 0x1f, 0x20, 0x22, 0x23, 0x25, 0x26,
+                0x27, 0x28, 0x29, 0x2b, 0x2c, 0x2c, 0x2d, 0x2f,
+                0x30, 0x31, 0x33, 0x33, 0x34, 0x35, 0x37, 0x38,
+                0x38, 0x39, 0x3a, 0x3b, 0x3b, 0x3c, 0x3d, 0x3f,
+                0x3f, 0x40, 0x42, 0x42, 0x43, 0x44, 0x45, 0x45,
+                0x47, 0x47, 0x48, 0x49, 0x49, 0x4a, 0x4b, 0x4b,
+                0x4c, 0x4d, 0x4d, 0x4f, 0x4f, 0x50, 0x52, 0x52,
+                0x53, 0x53, 0x54, 0x54, 0x55, 0x55, 0x56, 0x58,
+                0x58, 0x59, 0x59, 0x5a, 0x5a, 0x5b, 0x5b, 0x5c,
+                0x5c, 0x5e, 0x5e, 0x5f, 0x5f, 0x60, 0x60, 0x61,
+                0x61, 0x62, 0x62, 0x63, 0x63, 0x65, 0x65, 0x66,
+                0x66, 0x67, 0x67, 0x67, 0x68, 0x68, 0x69, 0x69,
+                0x6a, 0x6a, 0x6c, 0x6c, 0x6c, 0x6d, 0x6d, 0x6e,
+                0x6e, 0x6f, 0x6f, 0x6f, 0x70, 0x70, 0x71, 0x71,
+                0x71, 0x73, 0x73, 0x74, 0x74, 0x74, 0x75, 0x75,
+                0x77, 0x77, 0x77, 0x78, 0x78, 0x79, 0x79, 0x79,
+                0x7a, 0x7a, 0x7a, 0x7b, 0x7b, 0x7b, 0x7c, 0x7c,
+                0x7d, 0x7d, 0x7d, 0x7f, 0x7f, 0x7f, 0x80, 0x80,
+                0x80, 0x81, 0x81, 0x81, 0x82, 0x82, 0x82, 0x84,
+                0x84, 0x84, 0x85, 0x85, 0x85, 0x86, 0x86, 0x86,
+                0x88, 0x88, 0x88, 0x89, 0x89, 0x89, 0x8a, 0x8a,
+                0x8a, 0x8b, 0x8b, 0x8b, 0x8d, 0x8d, 0x8d, 0x8e,
+                0x8e, 0x8e, 0x8e, 0x8f, 0x8f, 0x8f, 0x90, 0x90,
+                0x90, 0x91, 0x91, 0x91, 0x91, 0x92, 0x92, 0x92,
+                0x93, 0x93, 0x93, 0x93, 0x94, 0x94, 0x94, 0x96,
+                0x96, 0x96, 0x96, 0x97, 0x97, 0x97, 0x98, 0x98,
+                0x98, 0x98, 0x99, 0x99, 0x99, 0x9a, 0x9a, 0x9a,
+                0x9a, 0x9b, 0x9b, 0x9b, 0x9b, 0x9c, 0x9c, 0x9c,
+                0x9c, 0x9d, 0x9d, 0x9d, 0x9e, 0x9e, 0x9e, 0x9e,
+                0xa0, 0xa0, 0xa0, 0xa0, 0xa1, 0xa1, 0xa1, 0xa1,
+                0xa2, 0xa2, 0xa2, 0xa2, 0xa3, 0xa3, 0xa3, 0xa3,
+                0xa4, 0xa4, 0xa4, 0xa4, 0xa5, 0xa5, 0xa5, 0xa5,
+                0xa6, 0xa6, 0xa6, 0xa6, 0xa8, 0xa8, 0xa8, 0xa8,
+                0xa9, 0xa9, 0xa9, 0xa9, 0xa9, 0xab, 0xab, 0xab,
+                0xab, 0xac, 0xac, 0xac, 0xac, 0xad, 0xad, 0xad,
+                0xad, 0xad, 0xae, 0xae, 0xae, 0xae, 0xaf, 0xaf,
+                0xaf, 0xaf, 0xb0, 0xb0, 0xb0, 0xb0, 0xb0, 0xb1,
+                0xb1, 0xb1, 0xb1, 0xb2, 0xb2, 0xb2, 0xb2, 0xb2,
+                0xb3, 0xb3, 0xb3, 0xb3, 0xb3, 0xb4, 0xb4, 0xb4,
+                0xb4, 0xb6, 0xb6, 0xb6, 0xb6, 0xb6, 0xb7, 0xb7,
+                0xb7, 0xb7, 0xb7, 0xb8, 0xb8, 0xb8, 0xb8, 0xb9,
+                0xb9, 0xb9, 0xb9, 0xb9, 0xba, 0xba, 0xba, 0xba,
+                0xba, 0xbc, 0xbc, 0xbc, 0xbc, 0xbc, 0xbd, 0xbd,
+                0xbd, 0xbd, 0xbd, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe,
+                0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xc0, 0xc0, 0xc0,
+                0xc0, 0xc0, 0xc2, 0xc2, 0xc2, 0xc2, 0xc2, 0xc3,
+                0xc3, 0xc3, 0xc3, 0xc3, 0xc4, 0xc4, 0xc4, 0xc4,
+                0xc4, 0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 0xc6, 0xc6,
+                0xc6, 0xc6, 0xc6, 0xc7, 0xc7, 0xc7, 0xc7, 0xc7,
+                0xc7, 0xc9, 0xc9, 0xc9, 0xc9, 0xc9, 0xca, 0xca,
+                0xca, 0xca, 0xca, 0xcb, 0xcb, 0xcb, 0xcb, 0xcb,
+                0xcb, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcd, 0xcd,
+                0xcd, 0xcd, 0xcd, 0xcd, 0xce, 0xce, 0xce, 0xce,
+                0xce, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xd0,
+                0xd0, 0xd0, 0xd0, 0xd0, 0xd1, 0xd1, 0xd1, 0xd1,
+                0xd1, 0xd1, 0xd3, 0xd3, 0xd3, 0xd3, 0xd3, 0xd4,
+                0xd4, 0xd4, 0xd4, 0xd4, 0xd4, 0xd6, 0xd6, 0xd6,
+                0xd6, 0xd6, 0xd6, 0xd7, 0xd7, 0xd7, 0xd7, 0xd7,
+                0xd8, 0xd8, 0xd8, 0xd8, 0xd8, 0xd8, 0xd9, 0xd9,
+                0xd9, 0xd9, 0xd9, 0xd9, 0xda, 0xda, 0xda, 0xda,
+                0xda, 0xdb, 0xdb, 0xdb, 0xdb, 0xdb, 0xdb, 0xdd,
+                0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xde, 0xde, 0xde,
+                0xde, 0xde, 0xde, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf,
+                0xdf, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe1,
+                0xe1, 0xe1, 0xe1, 0xe1, 0xe1, 0xe2, 0xe2, 0xe2,
+                0xe2, 0xe2, 0xe2, 0xe3, 0xe3, 0xe3, 0xe3, 0xe3,
+                0xe3, 0xe4, 0xe4, 0xe4, 0xe4, 0xe4, 0xe4, 0xe5,
+                0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 0xe6, 0xe6, 0xe6,
+                0xe6, 0xe6, 0xe6, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7,
+                0xe7, 0xe8, 0xe8, 0xe8, 0xe8, 0xe8, 0xe8, 0xe9,
+                0xe9, 0xe9, 0xe9, 0xe9, 0xe9, 0xeb, 0xeb, 0xeb,
+                0xeb, 0xeb, 0xeb, 0xec, 0xec, 0xec, 0xec, 0xec,
+                0xec, 0xed, 0xed, 0xed, 0xed, 0xed, 0xed, 0xee,
+                0xee, 0xee, 0xee, 0xee, 0xee, 0xef, 0xef, 0xef,
+                0xef, 0xef, 0xef, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
+                0xf0, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf3,
+                0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf4, 0xf4, 0xf4,
+                0xf4, 0xf4, 0xf4, 0xf5, 0xf5, 0xf5, 0xf5, 0xf5,
+                0xf5, 0xf5, 0xf6, 0xf6, 0xf6, 0xf6, 0xf6, 0xf6,
+                0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf8, 0xf8,
+                0xf8, 0xf8, 0xf8, 0xf8, 0xf9, 0xf9, 0xf9, 0xf9,
+                0xf9, 0xf9, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa,
+                0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfc, 0xfc, 0xfc, 0xfc,
+                0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc,
+                0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfe, 0xfe,
+                0xfe, 0xfe, 0xfe, 0xfe, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
+               {0x07, 0x08, 0x0a, 0x0c, 0x0e, 0x10, 0x12, 0x14,
+                0x16, 0x17, 0x18, 0x1b, 0x1c, 0x1e, 0x1f, 0x20,
+                0x23, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2b, 0x2d,
+                0x2f, 0x30, 0x31, 0x33, 0x34, 0x35, 0x37, 0x38,
+                0x39, 0x3a, 0x3b, 0x3b, 0x3c, 0x3d, 0x3f, 0x40,
+                0x42, 0x43, 0x44, 0x44, 0x45, 0x47, 0x48, 0x49,
+                0x4a, 0x4a, 0x4b, 0x4c, 0x4d, 0x4d, 0x4f, 0x50,
+                0x52, 0x52, 0x53, 0x54, 0x55, 0x55, 0x56, 0x58,
+                0x58, 0x59, 0x5a, 0x5b, 0x5b, 0x5c, 0x5e, 0x5e,
+                0x5f, 0x5f, 0x60, 0x61, 0x61, 0x62, 0x63, 0x63,
+                0x65, 0x65, 0x66, 0x67, 0x67, 0x68, 0x68, 0x69,
+                0x6a, 0x6a, 0x6c, 0x6c, 0x6d, 0x6d, 0x6e, 0x6e,
+                0x6f, 0x70, 0x70, 0x71, 0x71, 0x73, 0x73, 0x74,
+                0x74, 0x75, 0x75, 0x77, 0x77, 0x78, 0x78, 0x79,
+                0x79, 0x7a, 0x7a, 0x7b, 0x7b, 0x7c, 0x7c, 0x7d,
+                0x7d, 0x7f, 0x7f, 0x80, 0x80, 0x81, 0x81, 0x81,
+                0x82, 0x82, 0x84, 0x84, 0x85, 0x85, 0x86, 0x86,
+                0x88, 0x88, 0x88, 0x89, 0x89, 0x8a, 0x8a, 0x8b,
+                0x8b, 0x8b, 0x8d, 0x8d, 0x8e, 0x8e, 0x8e, 0x8f,
+                0x8f, 0x90, 0x90, 0x90, 0x91, 0x91, 0x92, 0x92,
+                0x92, 0x93, 0x93, 0x94, 0x94, 0x94, 0x96, 0x96,
+                0x96, 0x97, 0x97, 0x98, 0x98, 0x98, 0x99, 0x99,
+                0x99, 0x9a, 0x9a, 0x9b, 0x9b, 0x9b, 0x9c, 0x9c,
+                0x9c, 0x9d, 0x9d, 0x9d, 0x9e, 0x9e, 0x9e, 0xa0,
+                0xa0, 0xa1, 0xa1, 0xa1, 0xa2, 0xa2, 0xa2, 0xa3,
+                0xa3, 0xa3, 0xa4, 0xa4, 0xa4, 0xa5, 0xa5, 0xa5,
+                0xa6, 0xa6, 0xa6, 0xa8, 0xa8, 0xa8, 0xa8, 0xa9,
+                0xa9, 0xa9, 0xab, 0xab, 0xab, 0xac, 0xac, 0xac,
+                0xad, 0xad, 0xad, 0xae, 0xae, 0xae, 0xaf, 0xaf,
+                0xaf, 0xaf, 0xb0, 0xb0, 0xb0, 0xb1, 0xb1, 0xb1,
+                0xb2, 0xb2, 0xb2, 0xb2, 0xb3, 0xb3, 0xb3, 0xb4,
+                0xb4, 0xb4, 0xb4, 0xb6, 0xb6, 0xb6, 0xb7, 0xb7,
+                0xb7, 0xb7, 0xb8, 0xb8, 0xb8, 0xb9, 0xb9, 0xb9,
+                0xb9, 0xba, 0xba, 0xba, 0xbc, 0xbc, 0xbc, 0xbc,
+                0xbd, 0xbd, 0xbd, 0xbd, 0xbe, 0xbe, 0xbe, 0xbf,
+                0xbf, 0xbf, 0xbf, 0xc0, 0xc0, 0xc0, 0xc0, 0xc2,
+                0xc2, 0xc2, 0xc2, 0xc3, 0xc3, 0xc3, 0xc3, 0xc4,
+                0xc4, 0xc4, 0xc5, 0xc5, 0xc5, 0xc5, 0xc6, 0xc6,
+                0xc6, 0xc6, 0xc7, 0xc7, 0xc7, 0xc7, 0xc9, 0xc9,
+                0xc9, 0xc9, 0xca, 0xca, 0xca, 0xca, 0xcb, 0xcb,
+                0xcb, 0xcb, 0xcc, 0xcc, 0xcc, 0xcc, 0xcd, 0xcd,
+                0xcd, 0xcd, 0xcd, 0xce, 0xce, 0xce, 0xce, 0xcf,
+                0xcf, 0xcf, 0xcf, 0xd0, 0xd0, 0xd0, 0xd0, 0xd1,
+                0xd1, 0xd1, 0xd1, 0xd3, 0xd3, 0xd3, 0xd3, 0xd3,
+                0xd4, 0xd4, 0xd4, 0xd4, 0xd6, 0xd6, 0xd6, 0xd6,
+                0xd7, 0xd7, 0xd7, 0xd7, 0xd7, 0xd8, 0xd8, 0xd8,
+                0xd8, 0xd9, 0xd9, 0xd9, 0xd9, 0xd9, 0xda, 0xda,
+                0xda, 0xda, 0xdb, 0xdb, 0xdb, 0xdb, 0xdb, 0xdd,
+                0xdd, 0xdd, 0xdd, 0xde, 0xde, 0xde, 0xde, 0xde,
+                0xdf, 0xdf, 0xdf, 0xdf, 0xe0, 0xe0, 0xe0, 0xe0,
+                0xe0, 0xe1, 0xe1, 0xe1, 0xe1, 0xe1, 0xe2, 0xe2,
+                0xe2, 0xe2, 0xe3, 0xe3, 0xe3, 0xe3, 0xe3, 0xe4,
+                0xe4, 0xe4, 0xe4, 0xe4, 0xe5, 0xe5, 0xe5, 0xe5,
+                0xe6, 0xe6, 0xe6, 0xe6, 0xe6, 0xe7, 0xe7, 0xe7,
+                0xe7, 0xe7, 0xe8, 0xe8, 0xe8, 0xe8, 0xe8, 0xe9,
+                0xe9, 0xe9, 0xe9, 0xe9, 0xeb, 0xeb, 0xeb, 0xeb,
+                0xeb, 0xec, 0xec, 0xec, 0xec, 0xec, 0xed, 0xed,
+                0xed, 0xed, 0xed, 0xee, 0xee, 0xee, 0xee, 0xee,
+                0xef, 0xef, 0xef, 0xef, 0xef, 0xf0, 0xf0, 0xf0,
+                0xf0, 0xf0, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf3,
+                0xf3, 0xf3, 0xf3, 0xf3, 0xf4, 0xf4, 0xf4, 0xf4,
+                0xf4, 0xf5, 0xf5, 0xf5, 0xf5, 0xf5, 0xf6, 0xf6,
+                0xf6, 0xf6, 0xf6, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7,
+                0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf9, 0xf9, 0xf9,
+                0xf9, 0xf9, 0xf9, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa,
+                0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc,
+                0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfd, 0xfd, 0xfd,
+                0xfd, 0xfd, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
+           },
+           {                           /* gamma 4 - from tp6800 + soi763a */
+               {0x11, 0x14, 0x15, 0x17, 0x1a, 0x1b, 0x1e, 0x1f,
+                0x22, 0x23, 0x25, 0x27, 0x28, 0x2b, 0x2c, 0x2d,
+                0x2f, 0x31, 0x33, 0x34, 0x35, 0x38, 0x39, 0x3a,
+                0x3b, 0x3c, 0x3d, 0x40, 0x42, 0x43, 0x44, 0x45,
+                0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4f,
+                0x50, 0x52, 0x53, 0x53, 0x54, 0x55, 0x56, 0x58,
+                0x59, 0x5a, 0x5b, 0x5b, 0x5c, 0x5e, 0x5f, 0x60,
+                0x61, 0x61, 0x62, 0x63, 0x65, 0x65, 0x66, 0x67,
+                0x68, 0x68, 0x69, 0x6a, 0x6c, 0x6c, 0x6d, 0x6e,
+                0x6f, 0x6f, 0x70, 0x71, 0x71, 0x73, 0x74, 0x74,
+                0x75, 0x77, 0x77, 0x78, 0x79, 0x79, 0x7a, 0x7a,
+                0x7b, 0x7c, 0x7c, 0x7d, 0x7f, 0x7f, 0x80, 0x80,
+                0x81, 0x81, 0x82, 0x84, 0x84, 0x85, 0x85, 0x86,
+                0x86, 0x88, 0x89, 0x89, 0x8a, 0x8a, 0x8b, 0x8b,
+                0x8d, 0x8d, 0x8e, 0x8e, 0x8f, 0x90, 0x90, 0x91,
+                0x91, 0x92, 0x92, 0x93, 0x93, 0x94, 0x94, 0x96,
+                0x96, 0x97, 0x97, 0x98, 0x98, 0x98, 0x99, 0x99,
+                0x9a, 0x9a, 0x9b, 0x9b, 0x9c, 0x9c, 0x9d, 0x9d,
+                0x9e, 0x9e, 0xa0, 0xa0, 0xa0, 0xa1, 0xa1, 0xa2,
+                0xa2, 0xa3, 0xa3, 0xa3, 0xa4, 0xa4, 0xa5, 0xa5,
+                0xa6, 0xa6, 0xa6, 0xa8, 0xa8, 0xa9, 0xa9, 0xab,
+                0xab, 0xab, 0xac, 0xac, 0xad, 0xad, 0xad, 0xae,
+                0xae, 0xaf, 0xaf, 0xaf, 0xb0, 0xb0, 0xb1, 0xb1,
+                0xb1, 0xb2, 0xb2, 0xb2, 0xb3, 0xb3, 0xb4, 0xb4,
+                0xb4, 0xb6, 0xb6, 0xb6, 0xb7, 0xb7, 0xb8, 0xb8,
+                0xb8, 0xb9, 0xb9, 0xb9, 0xba, 0xba, 0xba, 0xbc,
+                0xbc, 0xbd, 0xbd, 0xbd, 0xbe, 0xbe, 0xbe, 0xbf,
+                0xbf, 0xbf, 0xc0, 0xc0, 0xc0, 0xc2, 0xc2, 0xc2,
+                0xc3, 0xc3, 0xc3, 0xc4, 0xc4, 0xc4, 0xc5, 0xc5,
+                0xc5, 0xc6, 0xc6, 0xc6, 0xc7, 0xc7, 0xc7, 0xc9,
+                0xc9, 0xc9, 0xca, 0xca, 0xca, 0xcb, 0xcb, 0xcb,
+                0xcb, 0xcc, 0xcc, 0xcc, 0xcd, 0xcd, 0xcd, 0xce,
+                0xce, 0xce, 0xcf, 0xcf, 0xcf, 0xcf, 0xd0, 0xd0,
+                0xd0, 0xd1, 0xd1, 0xd1, 0xd3, 0xd3, 0xd3, 0xd3,
+                0xd4, 0xd4, 0xd4, 0xd6, 0xd6, 0xd6, 0xd7, 0xd7,
+                0xd7, 0xd7, 0xd8, 0xd8, 0xd8, 0xd9, 0xd9, 0xd9,
+                0xd9, 0xda, 0xda, 0xda, 0xdb, 0xdb, 0xdb, 0xdb,
+                0xdd, 0xdd, 0xdd, 0xde, 0xde, 0xde, 0xde, 0xdf,
+                0xdf, 0xdf, 0xdf, 0xe0, 0xe0, 0xe0, 0xe1, 0xe1,
+                0xe1, 0xe1, 0xe2, 0xe2, 0xe2, 0xe2, 0xe3, 0xe3,
+                0xe3, 0xe3, 0xe4, 0xe4, 0xe4, 0xe5, 0xe5, 0xe5,
+                0xe5, 0xe6, 0xe6, 0xe6, 0xe6, 0xe7, 0xe7, 0xe7,
+                0xe7, 0xe8, 0xe8, 0xe8, 0xe8, 0xe9, 0xe9, 0xe9,
+                0xe9, 0xeb, 0xeb, 0xeb, 0xeb, 0xec, 0xec, 0xec,
+                0xec, 0xed, 0xed, 0xed, 0xed, 0xee, 0xee, 0xee,
+                0xee, 0xef, 0xef, 0xef, 0xef, 0xf0, 0xf0, 0xf0,
+                0xf0, 0xf1, 0xf1, 0xf1, 0xf1, 0xf3, 0xf3, 0xf3,
+                0xf3, 0xf4, 0xf4, 0xf4, 0xf4, 0xf5, 0xf5, 0xf5,
+                0xf5, 0xf6, 0xf6, 0xf6, 0xf6, 0xf6, 0xf7, 0xf7,
+                0xf7, 0xf7, 0xf8, 0xf8, 0xf8, 0xf8, 0xf9, 0xf9,
+                0xf9, 0xf9, 0xfa, 0xf9, 0xfa, 0xfa, 0xfa, 0xfa,
+                0xfa, 0xfa, 0xfa, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb},
+               {0x08, 0x0a, 0x0c, 0x0e, 0x10, 0x11, 0x14, 0x15,
+                0x16, 0x17, 0x1a, 0x1b, 0x1c, 0x1e, 0x1f, 0x20,
+                0x23, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2b, 0x2c,
+                0x2d, 0x2f, 0x30, 0x31, 0x33, 0x34, 0x34, 0x35,
+                0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3c, 0x3d,
+                0x3f, 0x40, 0x42, 0x42, 0x43, 0x44, 0x45, 0x45,
+                0x47, 0x48, 0x49, 0x49, 0x4a, 0x4b, 0x4b, 0x4c,
+                0x4d, 0x4f, 0x4f, 0x50, 0x52, 0x52, 0x53, 0x54,
+                0x54, 0x55, 0x55, 0x56, 0x58, 0x58, 0x59, 0x5a,
+                0x5a, 0x5b, 0x5b, 0x5c, 0x5e, 0x5e, 0x5f, 0x5f,
+                0x60, 0x60, 0x61, 0x61, 0x62, 0x63, 0x63, 0x65,
+                0x65, 0x66, 0x66, 0x67, 0x67, 0x68, 0x68, 0x69,
+                0x69, 0x6a, 0x6a, 0x6c, 0x6c, 0x6d, 0x6d, 0x6e,
+                0x6e, 0x6f, 0x6f, 0x70, 0x70, 0x71, 0x71, 0x73,
+                0x73, 0x74, 0x74, 0x74, 0x75, 0x75, 0x77, 0x77,
+                0x78, 0x78, 0x79, 0x79, 0x79, 0x7a, 0x7a, 0x7b,
+                0x7b, 0x7c, 0x7c, 0x7c, 0x7d, 0x7d, 0x7f, 0x7f,
+                0x7f, 0x80, 0x80, 0x81, 0x81, 0x81, 0x82, 0x82,
+                0x84, 0x84, 0x84, 0x85, 0x85, 0x86, 0x86, 0x86,
+                0x88, 0x88, 0x88, 0x89, 0x89, 0x8a, 0x8a, 0x8a,
+                0x8b, 0x8b, 0x8b, 0x8d, 0x8d, 0x8d, 0x8e, 0x8e,
+                0x8e, 0x8f, 0x8f, 0x90, 0x90, 0x90, 0x91, 0x91,
+                0x91, 0x92, 0x92, 0x92, 0x93, 0x93, 0x93, 0x94,
+                0x94, 0x94, 0x96, 0x96, 0x96, 0x97, 0x97, 0x97,
+                0x98, 0x98, 0x98, 0x98, 0x99, 0x99, 0x99, 0x9a,
+                0x9a, 0x9a, 0x9b, 0x9b, 0x9b, 0x9c, 0x9c, 0x9c,
+                0x9c, 0x9d, 0x9d, 0x9d, 0x9e, 0x9e, 0x9e, 0xa0,
+                0xa0, 0xa0, 0xa0, 0xa1, 0xa1, 0xa1, 0xa2, 0xa2,
+                0xa2, 0xa3, 0xa3, 0xa3, 0xa3, 0xa4, 0xa4, 0xa4,
+                0xa5, 0xa5, 0xa5, 0xa5, 0xa6, 0xa6, 0xa6, 0xa6,
+                0xa8, 0xa8, 0xa8, 0xa9, 0xa9, 0xa9, 0xa9, 0xab,
+                0xaa, 0xab, 0xab, 0xac, 0xac, 0xac, 0xad, 0xad,
+                0xad, 0xad, 0xae, 0xae, 0xae, 0xae, 0xaf, 0xaf,
+                0xaf, 0xaf, 0xb0, 0xb0, 0xb0, 0xb0, 0xb1, 0xb1,
+                0xb1, 0xb1, 0xb2, 0xb2, 0xb2, 0xb2, 0xb3, 0xb3,
+                0xb3, 0xb3, 0xb4, 0xb4, 0xb4, 0xb4, 0xb6, 0xb6,
+                0xb6, 0xb6, 0xb7, 0xb7, 0xb7, 0xb7, 0xb8, 0xb8,
+                0xb8, 0xb8, 0xb9, 0xb9, 0xb9, 0xb9, 0xba, 0xba,
+                0xba, 0xba, 0xba, 0xbc, 0xbc, 0xbc, 0xbc, 0xbd,
+                0xbd, 0xbd, 0xbd, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe,
+                0xbf, 0xbf, 0xbf, 0xbf, 0xc0, 0xc0, 0xc0, 0xc0,
+                0xc2, 0xc2, 0xc2, 0xc2, 0xc2, 0xc3, 0xc3, 0xc3,
+                0xc3, 0xc4, 0xc4, 0xc4, 0xc4, 0xc4, 0xc5, 0xc5,
+                0xc5, 0xc5, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc7,
+                0xc7, 0xc7, 0xc7, 0xc7, 0xc9, 0xc9, 0xc9, 0xc9,
+                0xca, 0xca, 0xca, 0xca, 0xca, 0xcb, 0xcb, 0xcb,
+                0xcb, 0xcb, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcd,
+                0xcd, 0xcd, 0xcd, 0xcd, 0xce, 0xce, 0xce, 0xce,
+                0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xd0, 0xd0, 0xd0,
+                0xd0, 0xd0, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd3,
+                0xd3, 0xd3, 0xd3, 0xd3, 0xd4, 0xd4, 0xd4, 0xd4,
+                0xd4, 0xd6, 0xd6, 0xd6, 0xd6, 0xd6, 0xd7, 0xd7,
+                0xd7, 0xd7, 0xd7, 0xd8, 0xd8, 0xd8, 0xd8, 0xd8,
+                0xd8, 0xd9, 0xd9, 0xd9, 0xd9, 0xd9, 0xda, 0xda,
+                0xda, 0xda, 0xda, 0xdb, 0xdb, 0xdb, 0xdb, 0xdb,
+                0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xde, 0xde, 0xde,
+                0xde, 0xde, 0xde, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf,
+                0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe1, 0xe1, 0xe1,
+                0xe1, 0xe1, 0xe1, 0xe2, 0xe2, 0xe2, 0xe2, 0xe2,
+                0xe3, 0xe3, 0xe3, 0xe3, 0xe3, 0xe3, 0xe4, 0xe4,
+                0xe4, 0xe4, 0xe4, 0xe5, 0xe5, 0xe5, 0xe5, 0xe5,
+                0xe5, 0xe6, 0xe6, 0xe6, 0xe6, 0xe6, 0xe7, 0xe7,
+                0xe7, 0xe7, 0xe7, 0xe7, 0xe8, 0xe8, 0xe8, 0xe8,
+                0xe8, 0xe9, 0xe9, 0xe9, 0xe9, 0xe9, 0xe9, 0xeb,
+                0xeb, 0xeb, 0xeb, 0xeb, 0xec, 0xec, 0xec, 0xec,
+                0xec, 0xec, 0xed, 0xed, 0xed, 0xed, 0xed, 0xed,
+                0xee, 0xee, 0xee, 0xee, 0xee, 0xef, 0xef, 0xef,
+                0xef, 0xef, 0xef, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
+                0xf0, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf3,
+                0xf3, 0xf3, 0xf3, 0xf3, 0xf4, 0xf4, 0xf4, 0xf4,
+                0xf4, 0xf4, 0xf5, 0xf5, 0xf5, 0xf5, 0xf5, 0xf5,
+                0xf6, 0xf6, 0xf6, 0xf6, 0xf6, 0xf6, 0xf7, 0xf7,
+                0xf7, 0xf7, 0xf7, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8,
+                0xf8, 0xf9, 0xf9, 0xf9, 0xf9, 0xf9, 0xf9, 0xfa,
+                0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa,
+                0xfa, 0xfa, 0xfa, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb},
+               {0x0d, 0x10, 0x11, 0x14, 0x15, 0x17, 0x18, 0x1b,
+                0x1c, 0x1e, 0x20, 0x22, 0x23, 0x26, 0x27, 0x28,
+                0x29, 0x2b, 0x2d, 0x2f, 0x30, 0x31, 0x33, 0x34,
+                0x35, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d,
+                0x3f, 0x40, 0x42, 0x43, 0x44, 0x45, 0x47, 0x48,
+                0x49, 0x4a, 0x4b, 0x4b, 0x4c, 0x4d, 0x4f, 0x50,
+                0x52, 0x52, 0x53, 0x54, 0x55, 0x56, 0x56, 0x58,
+                0x59, 0x5a, 0x5a, 0x5b, 0x5c, 0x5e, 0x5e, 0x5f,
+                0x60, 0x60, 0x61, 0x62, 0x62, 0x63, 0x65, 0x65,
+                0x66, 0x67, 0x67, 0x68, 0x69, 0x69, 0x6a, 0x6c,
+                0x6c, 0x6d, 0x6d, 0x6e, 0x6f, 0x6f, 0x70, 0x70,
+                0x71, 0x73, 0x73, 0x74, 0x74, 0x75, 0x75, 0x77,
+                0x78, 0x78, 0x79, 0x79, 0x7a, 0x7a, 0x7b, 0x7b,
+                0x7c, 0x7c, 0x7d, 0x7d, 0x7f, 0x7f, 0x80, 0x80,
+                0x81, 0x81, 0x82, 0x82, 0x84, 0x84, 0x85, 0x85,
+                0x86, 0x86, 0x88, 0x88, 0x89, 0x89, 0x8a, 0x8a,
+                0x8b, 0x8b, 0x8d, 0x8d, 0x8d, 0x8e, 0x8e, 0x8f,
+                0x8f, 0x90, 0x90, 0x91, 0x91, 0x91, 0x92, 0x92,
+                0x93, 0x93, 0x94, 0x94, 0x94, 0x96, 0x96, 0x97,
+                0x97, 0x98, 0x98, 0x98, 0x99, 0x99, 0x9a, 0x9a,
+                0x9a, 0x9b, 0x9b, 0x9c, 0x9c, 0x9c, 0x9d, 0x9d,
+                0x9d, 0x9e, 0x9e, 0xa0, 0xa0, 0xa0, 0xa1, 0xa1,
+                0xa1, 0xa2, 0xa2, 0xa3, 0xa3, 0xa3, 0xa4, 0xa4,
+                0xa4, 0xa5, 0xa5, 0xa5, 0xa6, 0xa6, 0xa8, 0xa8,
+                0xa8, 0xa9, 0xa9, 0xa9, 0xab, 0xab, 0xab, 0xac,
+                0xac, 0xac, 0xad, 0xad, 0xad, 0xae, 0xae, 0xae,
+                0xaf, 0xaf, 0xaf, 0xb0, 0xb0, 0xb0, 0xb1, 0xb1,
+                0xb1, 0xb2, 0xb2, 0xb2, 0xb3, 0xb3, 0xb3, 0xb4,
+                0xb4, 0xb4, 0xb6, 0xb6, 0xb6, 0xb6, 0xb7, 0xb7,
+                0xb7, 0xb8, 0xb8, 0xb8, 0xb9, 0xb9, 0xb9, 0xba,
+                0xba, 0xba, 0xba, 0xbc, 0xbc, 0xbc, 0xbd, 0xbd,
+                0xbd, 0xbe, 0xbe, 0xbe, 0xbe, 0xbf, 0xbf, 0xbf,
+                0xc0, 0xc0, 0xc0, 0xc0, 0xc2, 0xc2, 0xc2, 0xc3,
+                0xc3, 0xc3, 0xc3, 0xc4, 0xc4, 0xc4, 0xc5, 0xc5,
+                0xc5, 0xc5, 0xc6, 0xc6, 0xc6, 0xc6, 0xc7, 0xc7,
+                0xc7, 0xc9, 0xc9, 0xc9, 0xc9, 0xca, 0xca, 0xca,
+                0xca, 0xcb, 0xcb, 0xcb, 0xcc, 0xcc, 0xcc, 0xcc,
+                0xcd, 0xcd, 0xcd, 0xcd, 0xce, 0xce, 0xce, 0xce,
+                0xcf, 0xcf, 0xcf, 0xcf, 0xd0, 0xd0, 0xd0, 0xd0,
+                0xd1, 0xd1, 0xd1, 0xd1, 0xd3, 0xd3, 0xd3, 0xd3,
+                0xd4, 0xd4, 0xd4, 0xd4, 0xd6, 0xd6, 0xd6, 0xd6,
+                0xd7, 0xd7, 0xd7, 0xd7, 0xd8, 0xd8, 0xd8, 0xd8,
+                0xd9, 0xd9, 0xd9, 0xd9, 0xda, 0xda, 0xda, 0xda,
+                0xdb, 0xdb, 0xdb, 0xdb, 0xdd, 0xdd, 0xdd, 0xdd,
+                0xdd, 0xde, 0xde, 0xde, 0xde, 0xdf, 0xdf, 0xdf,
+                0xdf, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe1, 0xe1,
+                0xe1, 0xe1, 0xe2, 0xe2, 0xe2, 0xe2, 0xe3, 0xe3,
+                0xe3, 0xe3, 0xe3, 0xe4, 0xe4, 0xe4, 0xe4, 0xe5,
+                0xe5, 0xe5, 0xe5, 0xe5, 0xe6, 0xe6, 0xe6, 0xe6,
+                0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe8, 0xe8, 0xe8,
+                0xe8, 0xe9, 0xe9, 0xe9, 0xe9, 0xe9, 0xeb, 0xeb,
+                0xeb, 0xeb, 0xec, 0xec, 0xec, 0xec, 0xec, 0xed,
+                0xed, 0xed, 0xed, 0xed, 0xee, 0xee, 0xee, 0xee,
+                0xef, 0xef, 0xef, 0xef, 0xef, 0xf0, 0xf0, 0xf0,
+                0xf0, 0xf0, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf3,
+                0xf3, 0xf3, 0xf3, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4,
+                0xf5, 0xf5, 0xf5, 0xf5, 0xf5, 0xf6, 0xf6, 0xf6,
+                0xf6, 0xf6, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf8,
+                0xf8, 0xf8, 0xf8, 0xf8, 0xf9, 0xf9, 0xf9, 0xf9,
+                0xf9, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa,
+                0xfa, 0xfa, 0xfa, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb}
+           },
+           {                                                   /* gamma 5 */
+               {0x16, 0x18, 0x19, 0x1b, 0x1d, 0x1e, 0x20, 0x21,
+                0x23, 0x24, 0x25, 0x27, 0x28, 0x2a, 0x2b, 0x2c,
+                0x2d, 0x2f, 0x30, 0x31, 0x32, 0x34, 0x35, 0x36,
+                0x37, 0x38, 0x39, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
+                0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
+                0x48, 0x49, 0x4a, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e,
+                0x4f, 0x50, 0x51, 0x51, 0x52, 0x53, 0x54, 0x55,
+                0x56, 0x56, 0x57, 0x58, 0x59, 0x59, 0x5a, 0x5b,
+                0x5c, 0x5c, 0x5d, 0x5e, 0x5f, 0x5f, 0x60, 0x61,
+                0x62, 0x62, 0x63, 0x64, 0x64, 0x65, 0x66, 0x66,
+                0x67, 0x68, 0x68, 0x69, 0x6a, 0x6a, 0x6b, 0x6b,
+                0x6c, 0x6d, 0x6d, 0x6e, 0x6f, 0x6f, 0x70, 0x70,
+                0x71, 0x71, 0x72, 0x73, 0x73, 0x74, 0x74, 0x75,
+                0x75, 0x76, 0x77, 0x77, 0x78, 0x78, 0x79, 0x79,
+                0x7a, 0x7a, 0x7b, 0x7b, 0x7c, 0x7d, 0x7d, 0x7e,
+                0x7e, 0x7f, 0x7f, 0x80, 0x80, 0x81, 0x81, 0x82,
+                0x82, 0x83, 0x83, 0x84, 0x84, 0x84, 0x85, 0x85,
+                0x86, 0x86, 0x87, 0x87, 0x88, 0x88, 0x89, 0x89,
+                0x8a, 0x8a, 0x8b, 0x8b, 0x8b, 0x8c, 0x8c, 0x8d,
+                0x8d, 0x8e, 0x8e, 0x8e, 0x8f, 0x8f, 0x90, 0x90,
+                0x91, 0x91, 0x91, 0x92, 0x92, 0x93, 0x93, 0x94,
+                0x94, 0x94, 0x95, 0x95, 0x96, 0x96, 0x96, 0x97,
+                0x97, 0x98, 0x98, 0x98, 0x99, 0x99, 0x9a, 0x9a,
+                0x9a, 0x9b, 0x9b, 0x9b, 0x9c, 0x9c, 0x9d, 0x9d,
+                0x9d, 0x9e, 0x9e, 0x9e, 0x9f, 0x9f, 0xa0, 0xa0,
+                0xa0, 0xa1, 0xa1, 0xa1, 0xa2, 0xa2, 0xa2, 0xa3,
+                0xa3, 0xa4, 0xa4, 0xa4, 0xa5, 0xa5, 0xa5, 0xa6,
+                0xa6, 0xa6, 0xa7, 0xa7, 0xa7, 0xa8, 0xa8, 0xa8,
+                0xa9, 0xa9, 0xa9, 0xaa, 0xaa, 0xaa, 0xab, 0xab,
+                0xab, 0xac, 0xac, 0xac, 0xad, 0xad, 0xad, 0xae,
+                0xae, 0xae, 0xaf, 0xaf, 0xaf, 0xb0, 0xb0, 0xb0,
+                0xb0, 0xb1, 0xb1, 0xb1, 0xb2, 0xb2, 0xb2, 0xb3,
+                0xb3, 0xb3, 0xb4, 0xb4, 0xb4, 0xb4, 0xb5, 0xb5,
+                0xb5, 0xb6, 0xb6, 0xb6, 0xb7, 0xb7, 0xb7, 0xb7,
+                0xb8, 0xb8, 0xb8, 0xb9, 0xb9, 0xb9, 0xba, 0xba,
+                0xba, 0xba, 0xbb, 0xbb, 0xbb, 0xbc, 0xbc, 0xbc,
+                0xbc, 0xbd, 0xbd, 0xbd, 0xbe, 0xbe, 0xbe, 0xbe,
+                0xbf, 0xbf, 0xbf, 0xc0, 0xc0, 0xc0, 0xc0, 0xc1,
+                0xc1, 0xc1, 0xc1, 0xc2, 0xc2, 0xc2, 0xc3, 0xc3,
+                0xc3, 0xc3, 0xc4, 0xc4, 0xc4, 0xc4, 0xc5, 0xc5,
+                0xc5, 0xc5, 0xc6, 0xc6, 0xc6, 0xc7, 0xc7, 0xc7,
+                0xc7, 0xc8, 0xc8, 0xc8, 0xc8, 0xc9, 0xc9, 0xc9,
+                0xc9, 0xca, 0xca, 0xca, 0xca, 0xcb, 0xcb, 0xcb,
+                0xcb, 0xcc, 0xcc, 0xcc, 0xcc, 0xcd, 0xcd, 0xcd,
+                0xcd, 0xce, 0xce, 0xce, 0xce, 0xcf, 0xcf, 0xcf,
+                0xcf, 0xd0, 0xd0, 0xd0, 0xd0, 0xd1, 0xd1, 0xd1,
+                0xd1, 0xd2, 0xd2, 0xd2, 0xd2, 0xd3, 0xd3, 0xd3,
+                0xd3, 0xd4, 0xd4, 0xd4, 0xd4, 0xd5, 0xd5, 0xd5,
+                0xd5, 0xd6, 0xd6, 0xd6, 0xd6, 0xd6, 0xd7, 0xd7,
+                0xd7, 0xd7, 0xd8, 0xd8, 0xd8, 0xd8, 0xd9, 0xd9,
+                0xd9, 0xd9, 0xda, 0xda, 0xda, 0xda, 0xda, 0xdb,
+                0xdb, 0xdb, 0xdb, 0xdc, 0xdc, 0xdc, 0xdc, 0xdd,
+                0xdd, 0xdd, 0xdd, 0xdd, 0xde, 0xde, 0xde, 0xde,
+                0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xe0, 0xe0, 0xe0,
+                0xe0, 0xe1, 0xe1, 0xe1, 0xe1, 0xe1, 0xe2, 0xe2,
+                0xe2, 0xe2, 0xe3, 0xe3, 0xe3, 0xe3, 0xe3, 0xe4,
+                0xe4, 0xe4, 0xe4, 0xe5, 0xe5, 0xe5, 0xe5, 0xe5,
+                0xe6, 0xe6, 0xe6, 0xe6, 0xe7, 0xe7, 0xe7, 0xe7,
+                0xe7, 0xe8, 0xe8, 0xe8, 0xe8, 0xe8, 0xe9, 0xe9,
+                0xe9, 0xe9, 0xea, 0xea, 0xea, 0xea, 0xea, 0xeb,
+                0xeb, 0xeb, 0xeb, 0xeb, 0xec, 0xec, 0xec, 0xec,
+                0xed, 0xed, 0xed, 0xed, 0xed, 0xee, 0xee, 0xee,
+                0xee, 0xee, 0xef, 0xef, 0xef, 0xef, 0xef, 0xf0,
+                0xf0, 0xf0, 0xf0, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1,
+                0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf3, 0xf3, 0xf3,
+                0xf3, 0xf3, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf5,
+                0xf5, 0xf5, 0xf5, 0xf5, 0xf6, 0xf6, 0xf6, 0xf6,
+                0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf8, 0xf8, 0xf8,
+                0xf8, 0xf8, 0xf9, 0xf9, 0xf9, 0xf9, 0xf9, 0xfa,
+                0xfa, 0xfa, 0xfa, 0xfa, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfd, 0xfd,
+                0xfd, 0xfd, 0xfd, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
+               {0x0f, 0x11, 0x12, 0x14, 0x15, 0x16, 0x18, 0x19,
+                0x1a, 0x1b, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22,
+                0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
+                0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x31, 0x32,
+                0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x38, 0x39,
+                0x3a, 0x3b, 0x3c, 0x3c, 0x3d, 0x3e, 0x3f, 0x3f,
+                0x40, 0x41, 0x42, 0x42, 0x43, 0x44, 0x44, 0x45,
+                0x46, 0x47, 0x47, 0x48, 0x49, 0x49, 0x4a, 0x4b,
+                0x4b, 0x4c, 0x4c, 0x4d, 0x4e, 0x4e, 0x4f, 0x50,
+                0x50, 0x51, 0x51, 0x52, 0x53, 0x53, 0x54, 0x54,
+                0x55, 0x55, 0x56, 0x56, 0x57, 0x58, 0x58, 0x59,
+                0x59, 0x5a, 0x5a, 0x5b, 0x5b, 0x5c, 0x5c, 0x5d,
+                0x5d, 0x5e, 0x5e, 0x5f, 0x5f, 0x60, 0x60, 0x61,
+                0x61, 0x62, 0x62, 0x63, 0x63, 0x64, 0x64, 0x65,
+                0x65, 0x66, 0x66, 0x66, 0x67, 0x67, 0x68, 0x68,
+                0x69, 0x69, 0x6a, 0x6a, 0x6a, 0x6b, 0x6b, 0x6c,
+                0x6c, 0x6d, 0x6d, 0x6d, 0x6e, 0x6e, 0x6f, 0x6f,
+                0x6f, 0x70, 0x70, 0x71, 0x71, 0x71, 0x72, 0x72,
+                0x73, 0x73, 0x73, 0x74, 0x74, 0x75, 0x75, 0x75,
+                0x76, 0x76, 0x76, 0x77, 0x77, 0x78, 0x78, 0x78,
+                0x79, 0x79, 0x79, 0x7a, 0x7a, 0x7a, 0x7b, 0x7b,
+                0x7b, 0x7c, 0x7c, 0x7d, 0x7d, 0x7d, 0x7e, 0x7e,
+                0x7e, 0x7f, 0x7f, 0x7f, 0x80, 0x80, 0x80, 0x81,
+                0x81, 0x81, 0x82, 0x82, 0x82, 0x83, 0x83, 0x83,
+                0x84, 0x84, 0x84, 0x84, 0x85, 0x85, 0x85, 0x86,
+                0x86, 0x86, 0x87, 0x87, 0x87, 0x88, 0x88, 0x88,
+                0x88, 0x89, 0x89, 0x89, 0x8a, 0x8a, 0x8a, 0x8b,
+                0x8b, 0x8b, 0x8b, 0x8c, 0x8c, 0x8c, 0x8d, 0x8d,
+                0x8d, 0x8e, 0x8e, 0x8e, 0x8e, 0x8f, 0x8f, 0x8f,
+                0x90, 0x90, 0x90, 0x90, 0x91, 0x91, 0x91, 0x91,
+                0x92, 0x92, 0x92, 0x93, 0x93, 0x93, 0x93, 0x94,
+                0x94, 0x94, 0x94, 0x95, 0x95, 0x95, 0x96, 0x96,
+                0x96, 0x96, 0x97, 0x97, 0x97, 0x97, 0x98, 0x98,
+                0x98, 0x98, 0x99, 0x99, 0x99, 0x99, 0x9a, 0x9a,
+                0x9a, 0x9a, 0x9b, 0x9b, 0x9b, 0x9b, 0x9c, 0x9c,
+                0x9c, 0x9c, 0x9d, 0x9d, 0x9d, 0x9d, 0x9e, 0x9e,
+                0x9e, 0x9e, 0x9f, 0x9f, 0x9f, 0x9f, 0xa0, 0xa0,
+                0xa0, 0xa0, 0xa1, 0xa1, 0xa1, 0xa1, 0xa2, 0xa2,
+                0xa2, 0xa2, 0xa2, 0xa3, 0xa3, 0xa3, 0xa3, 0xa4,
+                0xa4, 0xa4, 0xa4, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5,
+                0xa6, 0xa6, 0xa6, 0xa6, 0xa7, 0xa7, 0xa7, 0xa7,
+                0xa8, 0xa8, 0xa8, 0xa8, 0xa8, 0xa9, 0xa9, 0xa9,
+                0xa9, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xab, 0xab,
+                0xab, 0xab, 0xac, 0xac, 0xac, 0xac, 0xac, 0xad,
+                0xad, 0xad, 0xad, 0xad, 0xae, 0xae, 0xae, 0xae,
+                0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xb0, 0xb0, 0xb0,
+                0xb0, 0xb0, 0xb1, 0xb1, 0xb1, 0xb1, 0xb1, 0xb2,
+                0xb2, 0xb2, 0xb2, 0xb2, 0xb3, 0xb3, 0xb3, 0xb3,
+                0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0xb5, 0xb5, 0xb5,
+                0xb5, 0xb5, 0xb6, 0xb6, 0xb6, 0xb6, 0xb6, 0xb7,
+                0xb7, 0xb7, 0xb7, 0xb7, 0xb8, 0xb8, 0xb8, 0xb8,
+                0xb8, 0xb9, 0xb9, 0xb9, 0xb9, 0xb9, 0xba, 0xba,
+                0xba, 0xba, 0xba, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb,
+                0xbb, 0xbc, 0xbc, 0xbc, 0xbc, 0xbc, 0xbd, 0xbd,
+                0xbd, 0xbd, 0xbd, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe,
+                0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xc0, 0xc0, 0xc0,
+                0xc0, 0xc0, 0xc0, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1,
+                0xc2, 0xc2, 0xc2, 0xc2, 0xc2, 0xc3, 0xc3, 0xc3,
+                0xc3, 0xc3, 0xc3, 0xc4, 0xc4, 0xc4, 0xc4, 0xc4,
+                0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 0xc5, 0xc6, 0xc6,
+                0xc6, 0xc6, 0xc6, 0xc7, 0xc7, 0xc7, 0xc7, 0xc7,
+                0xc7, 0xc8, 0xc8, 0xc8, 0xc8, 0xc8, 0xc9, 0xc9,
+                0xc9, 0xc9, 0xc9, 0xc9, 0xca, 0xca, 0xca, 0xca,
+                0xca, 0xcb, 0xcb, 0xcb, 0xcb, 0xcb, 0xcb, 0xcc,
+                0xcc, 0xcc, 0xcc, 0xcc, 0xcd, 0xcd, 0xcd, 0xcd,
+                0xcd, 0xcd, 0xce, 0xce, 0xce, 0xce, 0xce, 0xce,
+                0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xd0, 0xd0, 0xd0,
+                0xd0, 0xd0, 0xd0, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1,
+                0xd1, 0xd2, 0xd2, 0xd2, 0xd2, 0xd2, 0xd2, 0xd3,
+                0xd3, 0xd3, 0xd3, 0xd3, 0xd4, 0xd4, 0xd4, 0xd4,
+                0xd4, 0xd4, 0xd5, 0xd5, 0xd5, 0xd5, 0xd5, 0xd5,
+                0xd6, 0xd6, 0xd6, 0xd6, 0xd6, 0xd6, 0xd7, 0xd7,
+                0xd7, 0xd7, 0xd7, 0xd8, 0xd8, 0xd8, 0xd8, 0xd8,
+                0xd8, 0xd9, 0xd9, 0xd9, 0xd9, 0xd9, 0xd9, 0xda,
+                0xda, 0xda, 0xda, 0xda, 0xda, 0xdb, 0xdb, 0xdb,
+                0xdb, 0xdb, 0xdb, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc,
+                0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xde, 0xde,
+                0xde, 0xde, 0xde, 0xde, 0xdf, 0xdf, 0xdf, 0xdf,
+                0xdf, 0xdf, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0,
+                0xe1, 0xe1, 0xe1, 0xe1, 0xe1, 0xe1, 0xe2, 0xe2,
+                0xe2, 0xe2, 0xe2, 0xe2, 0xe3, 0xe3, 0xe3, 0xe3,
+                0xe3, 0xe4, 0xe4, 0xe4, 0xe4, 0xe4, 0xe4, 0xe5,
+                0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 0xe6, 0xe6, 0xe6,
+                0xe6, 0xe6, 0xe6, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7,
+                0xe7, 0xe8, 0xe8, 0xe8, 0xe8, 0xe8, 0xe9, 0xe9,
+                0xe9, 0xe9, 0xe9, 0xe9, 0xea, 0xea, 0xea, 0xea,
+                0xea, 0xea, 0xeb, 0xeb, 0xeb, 0xeb, 0xeb, 0xeb,
+                0xec, 0xec, 0xec, 0xec, 0xec, 0xec, 0xed, 0xed,
+                0xed, 0xed, 0xed, 0xee, 0xee, 0xee, 0xee, 0xee,
+                0xee, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xf0,
+                0xf0, 0xf0, 0xf0, 0xf0, 0xf1, 0xf1, 0xf1, 0xf1,
+                0xf1, 0xf1, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2,
+                0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf4, 0xf4, 0xf4,
+                0xf4, 0xf4, 0xf4, 0xf5, 0xf5, 0xf5, 0xf5, 0xf5,
+                0xf6, 0xf6, 0xf6, 0xf6, 0xf6, 0xf6, 0xf7, 0xf7,
+                0xf7, 0xf7, 0xf7, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8,
+                0xf8, 0xf9, 0xf9, 0xf9, 0xf9, 0xf9, 0xfa, 0xfa,
+                0xfa, 0xfa, 0xfa, 0xfa, 0xfb, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfd, 0xfd,
+                0xfd, 0xfd, 0xfd, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
+                0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
+               {0x13, 0x15, 0x16, 0x18, 0x19, 0x1b, 0x1c, 0x1e,
+                0x1f, 0x20, 0x22, 0x23, 0x24, 0x26, 0x27, 0x28,
+                0x29, 0x2a, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31,
+                0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
+                0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41,
+                0x42, 0x43, 0x44, 0x44, 0x45, 0x46, 0x47, 0x48,
+                0x49, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4d, 0x4e,
+                0x4f, 0x50, 0x50, 0x51, 0x52, 0x53, 0x53, 0x54,
+                0x55, 0x55, 0x56, 0x57, 0x57, 0x58, 0x59, 0x59,
+                0x5a, 0x5b, 0x5b, 0x5c, 0x5d, 0x5d, 0x5e, 0x5f,
+                0x5f, 0x60, 0x60, 0x61, 0x62, 0x62, 0x63, 0x63,
+                0x64, 0x65, 0x65, 0x66, 0x66, 0x67, 0x67, 0x68,
+                0x69, 0x69, 0x6a, 0x6a, 0x6b, 0x6b, 0x6c, 0x6c,
+                0x6d, 0x6d, 0x6e, 0x6e, 0x6f, 0x6f, 0x70, 0x70,
+                0x71, 0x71, 0x72, 0x72, 0x73, 0x73, 0x74, 0x74,
+                0x75, 0x75, 0x76, 0x76, 0x77, 0x77, 0x78, 0x78,
+                0x79, 0x79, 0x7a, 0x7a, 0x7a, 0x7b, 0x7b, 0x7c,
+                0x7c, 0x7d, 0x7d, 0x7e, 0x7e, 0x7e, 0x7f, 0x7f,
+                0x80, 0x80, 0x81, 0x81, 0x81, 0x82, 0x82, 0x83,
+                0x83, 0x84, 0x84, 0x84, 0x85, 0x85, 0x86, 0x86,
+                0x86, 0x87, 0x87, 0x88, 0x88, 0x88, 0x89, 0x89,
+                0x89, 0x8a, 0x8a, 0x8b, 0x8b, 0x8b, 0x8c, 0x8c,
+                0x8c, 0x8d, 0x8d, 0x8e, 0x8e, 0x8e, 0x8f, 0x8f,
+                0x8f, 0x90, 0x90, 0x90, 0x91, 0x91, 0x92, 0x92,
+                0x92, 0x93, 0x93, 0x93, 0x94, 0x94, 0x94, 0x95,
+                0x95, 0x95, 0x96, 0x96, 0x96, 0x97, 0x97, 0x97,
+                0x98, 0x98, 0x98, 0x99, 0x99, 0x99, 0x9a, 0x9a,
+                0x9a, 0x9b, 0x9b, 0x9b, 0x9c, 0x9c, 0x9c, 0x9d,
+                0x9d, 0x9d, 0x9e, 0x9e, 0x9e, 0x9e, 0x9f, 0x9f,
+                0x9f, 0xa0, 0xa0, 0xa0, 0xa1, 0xa1, 0xa1, 0xa2,
+                0xa2, 0xa2, 0xa2, 0xa3, 0xa3, 0xa3, 0xa4, 0xa4,
+                0xa4, 0xa5, 0xa5, 0xa5, 0xa5, 0xa6, 0xa6, 0xa6,
+                0xa7, 0xa7, 0xa7, 0xa7, 0xa8, 0xa8, 0xa8, 0xa9,
+                0xa9, 0xa9, 0xa9, 0xaa, 0xaa, 0xaa, 0xab, 0xab,
+                0xab, 0xab, 0xac, 0xac, 0xac, 0xac, 0xad, 0xad,
+                0xad, 0xae, 0xae, 0xae, 0xae, 0xaf, 0xaf, 0xaf,
+                0xaf, 0xb0, 0xb0, 0xb0, 0xb1, 0xb1, 0xb1, 0xb1,
+                0xb2, 0xb2, 0xb2, 0xb2, 0xb3, 0xb3, 0xb3, 0xb3,
+                0xb4, 0xb4, 0xb4, 0xb4, 0xb5, 0xb5, 0xb5, 0xb5,
+                0xb6, 0xb6, 0xb6, 0xb6, 0xb7, 0xb7, 0xb7, 0xb7,
+                0xb8, 0xb8, 0xb8, 0xb8, 0xb9, 0xb9, 0xb9, 0xb9,
+                0xba, 0xba, 0xba, 0xba, 0xbb, 0xbb, 0xbb, 0xbb,
+                0xbc, 0xbc, 0xbc, 0xbc, 0xbd, 0xbd, 0xbd, 0xbd,
+                0xbe, 0xbe, 0xbe, 0xbe, 0xbf, 0xbf, 0xbf, 0xbf,
+                0xbf, 0xc0, 0xc0, 0xc0, 0xc0, 0xc1, 0xc1, 0xc1,
+                0xc1, 0xc2, 0xc2, 0xc2, 0xc2, 0xc2, 0xc3, 0xc3,
+                0xc3, 0xc3, 0xc4, 0xc4, 0xc4, 0xc4, 0xc5, 0xc5,
+                0xc5, 0xc5, 0xc5, 0xc6, 0xc6, 0xc6, 0xc6, 0xc7,
+                0xc7, 0xc7, 0xc7, 0xc7, 0xc8, 0xc8, 0xc8, 0xc8,
+                0xc9, 0xc9, 0xc9, 0xc9, 0xc9, 0xca, 0xca, 0xca,
+                0xca, 0xcb, 0xcb, 0xcb, 0xcb, 0xcb, 0xcc, 0xcc,
+                0xcc, 0xcc, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xce,
+                0xce, 0xce, 0xce, 0xce, 0xcf, 0xcf, 0xcf, 0xcf,
+                0xd0, 0xd0, 0xd0, 0xd0, 0xd0, 0xd1, 0xd1, 0xd1,
+                0xd1, 0xd1, 0xd2, 0xd2, 0xd2, 0xd2, 0xd2, 0xd3,
+                0xd3, 0xd3, 0xd3, 0xd4, 0xd4, 0xd4, 0xd4, 0xd4,
+                0xd5, 0xd5, 0xd5, 0xd5, 0xd5, 0xd6, 0xd6, 0xd6,
+                0xd6, 0xd6, 0xd7, 0xd7, 0xd7, 0xd7, 0xd7, 0xd8,
+                0xd8, 0xd8, 0xd8, 0xd8, 0xd9, 0xd9, 0xd9, 0xd9,
+                0xd9, 0xda, 0xda, 0xda, 0xda, 0xda, 0xdb, 0xdb,
+                0xdb, 0xdb, 0xdb, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc,
+                0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xde, 0xde, 0xde,
+                0xde, 0xde, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xe0,
+                0xe0, 0xe0, 0xe0, 0xe0, 0xe1, 0xe1, 0xe1, 0xe1,
+                0xe1, 0xe2, 0xe2, 0xe2, 0xe2, 0xe2, 0xe3, 0xe3,
+                0xe3, 0xe3, 0xe3, 0xe4, 0xe4, 0xe4, 0xe4, 0xe4,
+                0xe4, 0xe5, 0xe5, 0xe5, 0xe5, 0xe5, 0xe6, 0xe6,
+                0xe6, 0xe6, 0xe6, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7,
+                0xe8, 0xe8, 0xe8, 0xe8, 0xe8, 0xe9, 0xe9, 0xe9,
+                0xe9, 0xe9, 0xe9, 0xea, 0xea, 0xea, 0xea, 0xea,
+                0xeb, 0xeb, 0xeb, 0xeb, 0xeb, 0xec, 0xec, 0xec,
+                0xec, 0xec, 0xed, 0xed, 0xed, 0xed, 0xed, 0xed,
+                0xee, 0xee, 0xee, 0xee, 0xee, 0xef, 0xef, 0xef,
+                0xef, 0xef, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
+                0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf2, 0xf2, 0xf2,
+                0xf2, 0xf2, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3,
+                0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf5, 0xf5, 0xf5,
+                0xf5, 0xf5, 0xf6, 0xf6, 0xf6, 0xf6, 0xf6, 0xf6,
+                0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf8, 0xf8, 0xf8,
+                0xf8, 0xf8, 0xf9, 0xf9, 0xf9, 0xf9, 0xf9, 0xf9,
+                0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfb, 0xfb, 0xfb,
+                0xfb, 0xfb, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc,
+                0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfe, 0xfe, 0xfe,
+                0xfe, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
+           },
+       };
+
+       reg_w(gspca_dev, TP6800_R21_ENDP_1_CTL, 0x00);
+       if (sd->bridge == BRIDGE_TP6810)
+               reg_w(gspca_dev, 0x02, 0x28);
+/*     msleep(50); */
+       gamma = sd->ctrls[GAMMA].val;
+       bulk_w(gspca_dev, 0x00, gamma_tb[gamma][0], 1024);
+       bulk_w(gspca_dev, 0x01, gamma_tb[gamma][1], 1024);
+       bulk_w(gspca_dev, 0x02, gamma_tb[gamma][2], 1024);
+       if (sd->bridge == BRIDGE_TP6810) {
+               int i;
+
+               reg_w(gspca_dev, 0x02, 0x2b);
+               reg_w(gspca_dev, 0x02, 0x28);
+               for (i = 0; i < 6; i++)
+                       reg_w(gspca_dev, TP6800_R55_GAMMA_R,
+                               gamma_tb[gamma][0][i]);
+               reg_w(gspca_dev, 0x02, 0x2b);
+               reg_w(gspca_dev, 0x02, 0x28);
+               for (i = 0; i < 6; i++)
+                       reg_w(gspca_dev, TP6800_R56_GAMMA_G,
+                               gamma_tb[gamma][1][i]);
+               reg_w(gspca_dev, 0x02, 0x2b);
+               reg_w(gspca_dev, 0x02, 0x28);
+               for (i = 0; i < 6; i++)
+                       reg_w(gspca_dev, TP6800_R57_GAMMA_B,
+                               gamma_tb[gamma][2][i]);
+               reg_w(gspca_dev, 0x02, 0x28);
+       }
+       reg_w(gspca_dev, TP6800_R21_ENDP_1_CTL, 0x03);
+/*     msleep(50); */
+}
+
+static void setsharpness(struct gspca_dev *gspca_dev)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       u8 val;
+
+       if (sd->bridge == BRIDGE_TP6800) {
+               val = sd->ctrls[SHARPNESS].val
+                               | 0x08;         /* grid compensation enable */
+               if (gspca_dev->width == 640)
+                       reg_w(gspca_dev, TP6800_R78_FORMAT, 0x00); /* vga */
+               else
+                       val |= 0x04;            /* scaling down enable */
+               reg_w(gspca_dev, TP6800_R5D_DEMOSAIC_CFG, val);
+       } else {
+               val = (sd->ctrls[SHARPNESS].val << 5) | 0x08;
+               reg_w(gspca_dev, 0x59, val);
+       }
+}
+
+static void setautogain(struct gspca_dev *gspca_dev)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       if (gspca_dev->ctrl_dis & (1 << AUTOGAIN))
+               return;
+       if (sd->ctrls[AUTOGAIN].val) {
+               sd->ag_cnt = AG_CNT_START;
+               gspca_dev->ctrl_inac |= (1 << EXPOSURE) | (1 << GAIN);
+       } else {
+               sd->ag_cnt = -1;
+               gspca_dev->ctrl_inac &= ~((1 << EXPOSURE) | (1 << GAIN));
+       }
+}
+
+/* set the resolution for sensor cx0342 */
+static void set_resolution(struct gspca_dev *gspca_dev)
+{
+       reg_w(gspca_dev, TP6800_R21_ENDP_1_CTL, 0x00);
+       if (gspca_dev->width == 320) {
+               reg_w(gspca_dev, TP6800_R3F_FRAME_RATE, 0x06);
+               msleep(100);
+               i2c_w(gspca_dev, CX0342_AUTO_ADC_CALIB, 0x01);
+               msleep(100);
+               reg_w(gspca_dev, TP6800_R21_ENDP_1_CTL, 0x03);
+               reg_w(gspca_dev, TP6800_R78_FORMAT, 0x01);      /* qvga */
+               reg_w(gspca_dev, TP6800_R5D_DEMOSAIC_CFG, 0x0d);
+               i2c_w(gspca_dev, CX0342_EXPO_LINE_L, 0x37);
+               i2c_w(gspca_dev, CX0342_EXPO_LINE_H, 0x01);
+       } else {
+               reg_w(gspca_dev, TP6800_R3F_FRAME_RATE, 0x05);
+               msleep(100);
+               i2c_w(gspca_dev, CX0342_AUTO_ADC_CALIB, 0x01);
+               msleep(100);
+               reg_w(gspca_dev, TP6800_R21_ENDP_1_CTL, 0x03);
+               reg_w(gspca_dev, TP6800_R78_FORMAT, 0x00);      /* vga */
+               reg_w(gspca_dev, TP6800_R5D_DEMOSAIC_CFG, 0x09);
+               i2c_w(gspca_dev, CX0342_EXPO_LINE_L, 0xcf);
+               i2c_w(gspca_dev, CX0342_EXPO_LINE_H, 0x00);
+       }
+       i2c_w(gspca_dev, CX0342_SYS_CTRL_0, 0x01);
+       bulk_w(gspca_dev, 0x03, color_gain[SENSOR_CX0342],
+                               ARRAY_SIZE(color_gain[0]));
+       setgamma(gspca_dev);
+       setquality(gspca_dev);
+}
+
+/* convert the frame rate to a tp68x0 value */
+static int get_fr_idx(struct gspca_dev *gspca_dev)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       int i;
+
+       if (sd->bridge == BRIDGE_TP6800) {
+               for (i = 0; i < ARRAY_SIZE(rates) - 1; i++) {
+                       if (sd->framerate >= rates[i])
+                               break;
+               }
+               i = 6 - i;              /* 1 = 5fps .. 6 = 30fps */
+
+               /* 640x480 * 30 fps does not work */
+               if (i == 6                      /* if 30 fps */
+                && gspca_dev->width == 640)
+                       i = 0x86;               /* 15 fps */
+       } else {
+               for (i = 0; i < ARRAY_SIZE(rates_6810) - 1; i++) {
+                       if (sd->framerate >= rates_6810[i])
+                               break;
+               }
+               i = 7 - i;              /* 3 = 5fps .. 7 = 30fps */
+
+               /* 640x480 * 30 fps does not work */
+               if (i == 7                      /* if 30 fps */
+                && gspca_dev->width == 640)
+                       i = 6;                  /* 15 fps */
+               i |= 0x80;                      /* clock * 1 */
+       }
+       return i;
+}
+
+static void setframerate(struct gspca_dev *gspca_dev)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       u8 fr_idx;
+
+       fr_idx = get_fr_idx(gspca_dev);
+
+       if (sd->bridge == BRIDGE_TP6810) {
+               reg_r(gspca_dev, 0x7b);
+               reg_w(gspca_dev, 0x7b,
+                       sd->sensor == SENSOR_CX0342 ? 0x10 : 0x90);
+               if (sd->ctrls[EXPOSURE].val >= 128)
+                       fr_idx = 0xf0;          /* lower frame rate */
+       }
+
+       reg_w(gspca_dev, TP6800_R3F_FRAME_RATE, fr_idx);
+
+       if (sd->sensor == SENSOR_CX0342)
+               i2c_w(gspca_dev, CX0342_AUTO_ADC_CALIB, 0x01);
+}
+
+static void setrgain(struct gspca_dev *gspca_dev)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       int rgain;
+
+       rgain = sd->ctrls[RGAIN].val;
+       i2c_w(gspca_dev, CX0342_RAW_RGAIN_H, rgain >> 8);
+       i2c_w(gspca_dev, CX0342_RAW_RGAIN_L, rgain);
+       i2c_w(gspca_dev, CX0342_SYS_CTRL_0, 0x80);
+}
+
+static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       if (sd->sensor == SENSOR_CX0342) {
+               sd->ctrls[BGAIN].val = sd->ctrls[BGAIN].val
+                                       * val / sd->ctrls[GAIN].val;
+               if (sd->ctrls[BGAIN].val > 4095)
+                       sd->ctrls[BGAIN].val = 4095;
+               sd->ctrls[RGAIN].val = sd->ctrls[RGAIN].val
+                                       * val / sd->ctrls[GAIN].val;
+               if (sd->ctrls[RGAIN].val > 4095)
+                       sd->ctrls[RGAIN].val = 4095;
+       }
+       sd->ctrls[GAIN].val = val;
+       if (gspca_dev->streaming)
+               setexposure(gspca_dev);
+       return gspca_dev->usb_err;
+}
+
+static void setbgain(struct gspca_dev *gspca_dev)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       int bgain;
+
+       bgain = sd->ctrls[BGAIN].val;
+       i2c_w(gspca_dev, CX0342_RAW_BGAIN_H, bgain >> 8);
+       i2c_w(gspca_dev, CX0342_RAW_BGAIN_L, bgain);
+       i2c_w(gspca_dev, CX0342_SYS_CTRL_0, 0x80);
+}
+
+/* this function is called at probe time */
+static int sd_config(struct gspca_dev *gspca_dev,
+                    const struct usb_device_id *id)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       sd->bridge = id->driver_info;
+
+       gspca_dev->cam.cam_mode = vga_mode;
+       gspca_dev->cam.nmodes = ARRAY_SIZE(vga_mode);
+       gspca_dev->cam.mode_framerates = sd->bridge == BRIDGE_TP6800 ?
+                       framerates : framerates_6810;
+
+       sd->framerate = 30;             /* default: 30 fps */
+       gspca_dev->cam.ctrls = sd->ctrls;
+       return 0;
+}
+
+/* this function is called at probe and resume time */
+static int sd_init(struct gspca_dev *gspca_dev)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       static const struct cmd tp6800_preinit[] = {
+               {TP6800_R10_SIF_TYPE, 0x01},    /* sif */
+               {TP6800_R11_SIF_CONTROL, 0x01},
+               {TP6800_R15_GPIO_PU, 0x9f},
+               {TP6800_R16_GPIO_PD, 0x9f},
+               {TP6800_R17_GPIO_IO, 0x80},
+               {TP6800_R18_GPIO_DATA, 0x40},   /* LED off */
+       };
+       static const struct cmd tp6810_preinit[] = {
+               {TP6800_R2F_TIMING_CFG, 0x2f},
+               {TP6800_R15_GPIO_PU, 0x6f},
+               {TP6800_R16_GPIO_PD, 0x40},
+               {TP6800_R17_GPIO_IO, 0x9f},
+               {TP6800_R18_GPIO_DATA, 0xc1},   /* LED off */
+       };
+
+       if (sd->bridge == BRIDGE_TP6800)
+               reg_w_buf(gspca_dev, tp6800_preinit,
+                               ARRAY_SIZE(tp6800_preinit));
+       else
+               reg_w_buf(gspca_dev, tp6810_preinit,
+                               ARRAY_SIZE(tp6810_preinit));
+       msleep(15);
+       reg_r(gspca_dev, TP6800_R18_GPIO_DATA);
+       PDEBUG(D_PROBE, "gpio: %02x", gspca_dev->usb_buf[0]);
+/* values:
+ *     0x80: snapshot button
+ *     0x40: LED
+ *     0x20: (bridge / sensor) reset for tp6810 ?
+ *     0x07: sensor type ?
+ */
+
+       /* guess the sensor type */
+       if (force_sensor >= 0) {
+               sd->sensor = force_sensor;
+       } else {
+               if (sd->bridge == BRIDGE_TP6800) {
+/*fixme: not sure this is working*/
+                       switch (gspca_dev->usb_buf[0] & 0x07) {
+                       case 0:
+                               sd->sensor = SENSOR_SOI763A;
+                               break;
+                       case 1:
+                               sd->sensor = SENSOR_CX0342;
+                               break;
+                       }
+               } else {
+                       int sensor;
+
+                       sensor = probe_6810(gspca_dev);
+                       if (sensor < 0) {
+                               pr_warn("Unknown sensor %d - forced to soi763a\n",
+                                       -sensor);
+                               sensor = SENSOR_SOI763A;
+                       }
+                       sd->sensor = sensor;
+               }
+       }
+       if (sd->sensor == SENSOR_SOI763A) {
+               pr_info("Sensor soi763a\n");
+               sd->ctrls[GAMMA].def = sd->bridge == BRIDGE_TP6800 ? 0 : 1;
+               sd->ctrls[GAIN].max = 15;
+               sd->ctrls[GAIN].def = 3;
+               gspca_dev->ctrl_dis = (1 << RGAIN) | (1 << BGAIN);
+               if (sd->bridge == BRIDGE_TP6810) {
+                       soi763a_6810_init(gspca_dev);
+#if AUTOGAIN_DEF
+                       gspca_dev->ctrl_inac |= (1 << EXPOSURE) | (1 << GAIN);
+#endif
+               } else {
+                       gspca_dev->ctrl_dis |= (1 << AUTOGAIN);
+               }
+       } else {
+               pr_info("Sensor cx0342\n");
+               if (sd->bridge == BRIDGE_TP6810) {
+                       cx0342_6810_init(gspca_dev);
+#if AUTOGAIN_DEF
+                       gspca_dev->ctrl_inac |= (1 << EXPOSURE) | (1 << GAIN);
+#endif
+               } else {
+                       gspca_dev->ctrl_dis |= (1 << AUTOGAIN);
+               }
+       }
+
+       if (sd->bridge == BRIDGE_TP6810)
+               sd->ctrls[QUALITY].def = 0;     /* auto quality */
+       set_dqt(gspca_dev, 0);
+       return 0;
+}
+
+/* This function is called before choosing the alt setting */
+static int sd_isoc_init(struct gspca_dev *gspca_dev)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       static const struct cmd cx_sensor_init[] = {
+               {CX0342_AUTO_ADC_CALIB, 0x81},
+               {CX0342_EXPO_LINE_L, 0x37},
+               {CX0342_EXPO_LINE_H, 0x01},
+               {CX0342_RAW_GRGAIN_L, 0x00},
+               {CX0342_RAW_GBGAIN_L, 0x00},
+               {CX0342_RAW_RGAIN_L, 0x00},
+               {CX0342_RAW_BGAIN_L, 0x00},
+               {CX0342_SYS_CTRL_0, 0x81},
+       };
+       static const struct cmd cx_bridge_init[] = {
+               {0x4d, 0x00},
+               {0x4c, 0xff},
+               {0x4e, 0xff},
+               {0x4f, 0x00},
+       };
+       static const struct cmd ov_sensor_init[] = {
+               {0x10, 0x75},           /* exposure */
+               {0x76, 0x03},
+               {0x00, 0x00},           /* gain */
+       };
+       static const struct cmd ov_bridge_init[] = {
+               {0x7b, 0x90},
+               {TP6800_R3F_FRAME_RATE, 0x87},
+       };
+
+       if (sd->bridge == BRIDGE_TP6800)
+               return 0;
+       if (sd->sensor == SENSOR_CX0342) {
+               reg_w(gspca_dev, TP6800_R12_SIF_ADDR_S, 0x20);
+               reg_w(gspca_dev, TP6800_R3F_FRAME_RATE, 0x87);
+               i2c_w_buf(gspca_dev, cx_sensor_init,
+                               ARRAY_SIZE(cx_sensor_init));
+               reg_w_buf(gspca_dev, cx_bridge_init,
+                               ARRAY_SIZE(cx_bridge_init));
+               bulk_w(gspca_dev, 0x03, color_null, sizeof color_null);
+               reg_w(gspca_dev, 0x59, 0x40);
+       } else {
+               reg_w(gspca_dev, TP6800_R12_SIF_ADDR_S, 0x21);
+               i2c_w_buf(gspca_dev, ov_sensor_init,
+                               ARRAY_SIZE(ov_sensor_init));
+               reg_r(gspca_dev, 0x7b);
+               reg_w_buf(gspca_dev, ov_bridge_init,
+                               ARRAY_SIZE(ov_bridge_init));
+       }
+       reg_w(gspca_dev, TP6800_R78_FORMAT,
+                       gspca_dev->curr_mode ? 0x00 : 0x01);
+       return gspca_dev->usb_err;
+}
+
+static void set_led(struct gspca_dev *gspca_dev, int on)
+{
+       u8 data;
+
+       reg_r(gspca_dev, TP6800_R18_GPIO_DATA);
+       data = gspca_dev->usb_buf[0];
+       if (on)
+               data &= ~0x40;
+       else
+               data |= 0x40;
+       reg_w(gspca_dev, TP6800_R18_GPIO_DATA, data);
+}
+
+static void cx0342_6800_start(struct gspca_dev *gspca_dev)
+{
+       static const struct cmd reg_init[] = {
+/*fixme: is this usefull?*/
+               {TP6800_R17_GPIO_IO, 0x9f},
+               {TP6800_R16_GPIO_PD, 0x40},
+               {TP6800_R10_SIF_TYPE, 0x00},    /* i2c 8 bits */
+               {TP6800_R50, 0x00},
+               {TP6800_R51, 0x00},
+               {TP6800_R52, 0xff},
+               {TP6800_R53, 0x03},
+               {TP6800_R54_DARK_CFG, 0x07},
+               {TP6800_R5C_EDGE_THRLD, 0x40},
+               {TP6800_R7A_BLK_THRLD, 0x40},
+               {TP6800_R2F_TIMING_CFG, 0x17},
+               {TP6800_R30_SENSOR_CFG, 0x18},  /* G1B..RG0 */
+               {TP6800_R37_FRONT_DARK_ST, 0x00},
+               {TP6800_R38_FRONT_DARK_END, 0x00},
+               {TP6800_R39_REAR_DARK_ST_L, 0x00},
+               {TP6800_R3A_REAR_DARK_ST_H, 0x00},
+               {TP6800_R3B_REAR_DARK_END_L, 0x00},
+               {TP6800_R3C_REAR_DARK_END_H, 0x00},
+               {TP6800_R3D_HORIZ_DARK_LINE_L, 0x00},
+               {TP6800_R3E_HORIZ_DARK_LINE_H, 0x00},
+               {TP6800_R21_ENDP_1_CTL, 0x03},
+
+               {TP6800_R31_PIXEL_START, 0x0b},
+               {TP6800_R32_PIXEL_END_L, 0x8a},
+               {TP6800_R33_PIXEL_END_H, 0x02},
+               {TP6800_R34_LINE_START, 0x0e},
+               {TP6800_R35_LINE_END_L, 0xf4},
+               {TP6800_R36_LINE_END_H, 0x01},
+               {TP6800_R78_FORMAT, 0x00},
+               {TP6800_R12_SIF_ADDR_S, 0x20},  /* cx0342 i2c addr */
+       };
+       static const struct cmd sensor_init[] = {
+               {CX0342_OUTPUT_CTRL, 0x07},
+               {CX0342_BYPASS_MODE, 0x58},
+               {CX0342_GPXLTHD_L, 0x16},
+               {CX0342_RBPXLTHD_L, 0x16},
+               {CX0342_PLANETHD_L, 0xc0},
+               {CX0342_PLANETHD_H, 0x03},
+               {CX0342_RB_GAP_L, 0xff},
+               {CX0342_RB_GAP_H, 0x07},
+               {CX0342_G_GAP_L, 0xff},
+               {CX0342_G_GAP_H, 0x07},
+               {CX0342_RST_OVERFLOW_L, 0x5c},
+               {CX0342_RST_OVERFLOW_H, 0x01},
+               {CX0342_DATA_OVERFLOW_L, 0xfc},
+               {CX0342_DATA_OVERFLOW_H, 0x03},
+               {CX0342_DATA_UNDERFLOW_L, 0x00},
+               {CX0342_DATA_UNDERFLOW_H, 0x00},
+               {CX0342_SYS_CTRL_0, 0x40},
+               {CX0342_GLOBAL_GAIN, 0x01},
+               {CX0342_CLOCK_GEN, 0x00},
+               {CX0342_SYS_CTRL_0, 0x02},
+               {CX0342_IDLE_CTRL, 0x05},
+               {CX0342_ADCGN, 0x00},
+               {CX0342_ADC_CTL, 0x00},
+               {CX0342_LVRST_BLBIAS, 0x01},
+               {CX0342_VTHSEL, 0x0b},
+               {CX0342_RAMP_RIV, 0x0b},
+               {CX0342_LDOSEL, 0x07},
+               {CX0342_SPV_VALUE_L, 0x40},
+               {CX0342_SPV_VALUE_H, 0x02},
+       };
+
+       reg_w_buf(gspca_dev, reg_init, ARRAY_SIZE(reg_init));
+       i2c_w_buf(gspca_dev, sensor_init, ARRAY_SIZE(sensor_init));
+       i2c_w_buf(gspca_dev, cx0342_timing_seq, ARRAY_SIZE(cx0342_timing_seq));
+       reg_w(gspca_dev, TP6800_R5C_EDGE_THRLD, 0x10);
+       reg_w(gspca_dev, TP6800_R54_DARK_CFG, 0x00);
+       i2c_w(gspca_dev, CX0342_EXPO_LINE_H, 0x00);
+       i2c_w(gspca_dev, CX0342_SYS_CTRL_0, 0x01);
+       setexposure(gspca_dev);
+       set_led(gspca_dev, 1);
+       set_resolution(gspca_dev);
+}
+
+static void cx0342_6810_start(struct gspca_dev *gspca_dev)
+{
+       static const struct cmd sensor_init_2[] = {
+               {CX0342_EXPO_LINE_L, 0x6f},
+               {CX0342_EXPO_LINE_H, 0x02},
+               {CX0342_RAW_GRGAIN_L, 0x00},
+               {CX0342_RAW_GBGAIN_L, 0x00},
+               {CX0342_RAW_RGAIN_L, 0x00},
+               {CX0342_RAW_BGAIN_L, 0x00},
+               {CX0342_SYS_CTRL_0, 0x81},
+       };
+       static const struct cmd bridge_init_2[] = {
+               {0x4d, 0x00},
+               {0x4c, 0xff},
+               {0x4e, 0xff},
+               {0x4f, 0x00},
+               {TP6800_R7A_BLK_THRLD, 0x00},
+               {TP6800_R79_QUALITY, 0x04},
+               {TP6800_R79_QUALITY, 0x01},
+       };
+       static const struct cmd bridge_init_3[] = {
+               {TP6800_R31_PIXEL_START, 0x08},
+               {TP6800_R32_PIXEL_END_L, 0x87},
+               {TP6800_R33_PIXEL_END_H, 0x02},
+               {TP6800_R34_LINE_START, 0x0e},
+               {TP6800_R35_LINE_END_L, 0xf4},
+               {TP6800_R36_LINE_END_H, 0x01},
+       };
+       static const struct cmd sensor_init_3[] = {
+               {CX0342_AUTO_ADC_CALIB, 0x81},
+               {CX0342_EXPO_LINE_L, 0x6f},
+               {CX0342_EXPO_LINE_H, 0x02},
+               {CX0342_RAW_GRGAIN_L, 0x00},
+               {CX0342_RAW_GBGAIN_L, 0x00},
+               {CX0342_RAW_RGAIN_L, 0x00},
+               {CX0342_RAW_BGAIN_L, 0x00},
+               {CX0342_SYS_CTRL_0, 0x81},
+       };
+       static const struct cmd bridge_init_5[] = {
+               {0x4d, 0x00},
+               {0x4c, 0xff},
+               {0x4e, 0xff},
+               {0x4f, 0x00},
+       };
+       static const struct cmd sensor_init_4[] = {
+               {CX0342_EXPO_LINE_L, 0xd3},
+               {CX0342_EXPO_LINE_H, 0x01},
+/*fixme: gains, but 00..80 only*/
+               {CX0342_RAW_GRGAIN_L, 0x40},
+               {CX0342_RAW_GBGAIN_L, 0x40},
+               {CX0342_RAW_RGAIN_L, 0x40},
+               {CX0342_RAW_BGAIN_L, 0x40},
+               {CX0342_SYS_CTRL_0, 0x81},
+       };
+       static const struct cmd sensor_init_5[] = {
+               {CX0342_IDLE_CTRL, 0x05},
+               {CX0342_ADCGN, 0x00},
+               {CX0342_ADC_CTL, 0x00},
+               {CX0342_LVRST_BLBIAS, 0x01},
+               {CX0342_VTHSEL, 0x0b},
+               {CX0342_RAMP_RIV, 0x0b},
+               {CX0342_LDOSEL, 0x07},
+               {CX0342_SPV_VALUE_L, 0x40},
+               {CX0342_SPV_VALUE_H, 0x02},
+               {CX0342_AUTO_ADC_CALIB, 0x81},
+       };
+
+       reg_w(gspca_dev, 0x22, gspca_dev->alt);
+       i2c_w_buf(gspca_dev, sensor_init_2, ARRAY_SIZE(sensor_init_2));
+       reg_w_buf(gspca_dev, bridge_init_2, ARRAY_SIZE(bridge_init_2));
+       reg_w_buf(gspca_dev, tp6810_cx_init_common,
+                       ARRAY_SIZE(tp6810_cx_init_common));
+       reg_w_buf(gspca_dev, bridge_init_3, ARRAY_SIZE(bridge_init_3));
+       if (gspca_dev->curr_mode) {
+               reg_w(gspca_dev, 0x4a, 0x7f);
+               reg_w(gspca_dev, 0x07, 0x05);
+               reg_w(gspca_dev, TP6800_R78_FORMAT, 0x00);      /* vga */
+       } else {
+               reg_w(gspca_dev, 0x4a, 0xff);
+               reg_w(gspca_dev, 0x07, 0x85);
+               reg_w(gspca_dev, TP6800_R78_FORMAT, 0x01);      /* qvga */
+       }
+       setgamma(gspca_dev);
+       reg_w_buf(gspca_dev, tp6810_bridge_start,
+                       ARRAY_SIZE(tp6810_bridge_start));
+       setsharpness(gspca_dev);
+       bulk_w(gspca_dev, 0x03, color_gain[SENSOR_CX0342],
+                               ARRAY_SIZE(color_gain[0]));
+       reg_w(gspca_dev, TP6800_R3F_FRAME_RATE, 0x87);
+       i2c_w_buf(gspca_dev, sensor_init_3, ARRAY_SIZE(sensor_init_3));
+       reg_w_buf(gspca_dev, bridge_init_5, ARRAY_SIZE(bridge_init_5));
+       i2c_w_buf(gspca_dev, sensor_init_4, ARRAY_SIZE(sensor_init_4));
+       reg_w_buf(gspca_dev, bridge_init_5, ARRAY_SIZE(bridge_init_5));
+       i2c_w_buf(gspca_dev, sensor_init_5, ARRAY_SIZE(sensor_init_5));
+
+       set_led(gspca_dev, 1);
+/*     setquality(gspca_dev); */
+}
+
+static void soi763a_6800_start(struct gspca_dev *gspca_dev)
+{
+       static const struct cmd reg_init[] = {
+               {TP6800_R79_QUALITY, 0x04},
+               {TP6800_R79_QUALITY, 0x01},
+               {TP6800_R10_SIF_TYPE, 0x00},    /* i2c 8 bits */
+
+               {TP6800_R50, 0x00},
+               {TP6800_R51, 0x00},
+               {TP6800_R52, 0xff},
+               {TP6800_R53, 0x03},
+               {TP6800_R54_DARK_CFG, 0x07},
+               {TP6800_R5C_EDGE_THRLD, 0x40},
+
+               {TP6800_R79_QUALITY, 0x03},
+               {TP6800_R7A_BLK_THRLD, 0x40},
+
+               {TP6800_R2F_TIMING_CFG, 0x46},
+               {TP6800_R30_SENSOR_CFG, 0x10},  /* BG1..G0R */
+               {TP6800_R37_FRONT_DARK_ST, 0x00},
+               {TP6800_R38_FRONT_DARK_END, 0x00},
+               {TP6800_R39_REAR_DARK_ST_L, 0x00},
+               {TP6800_R3A_REAR_DARK_ST_H, 0x00},
+               {TP6800_R3B_REAR_DARK_END_L, 0x00},
+               {TP6800_R3C_REAR_DARK_END_H, 0x00},
+               {TP6800_R3D_HORIZ_DARK_LINE_L, 0x00},
+               {TP6800_R3E_HORIZ_DARK_LINE_H, 0x00},
+               {TP6800_R21_ENDP_1_CTL, 0x03},
+
+               {TP6800_R3F_FRAME_RATE, 0x04},  /* 15 fps */
+               {TP6800_R5D_DEMOSAIC_CFG, 0x0e}, /* scale down - medium edge */
+
+               {TP6800_R31_PIXEL_START, 0x1b},
+               {TP6800_R32_PIXEL_END_L, 0x9a},
+               {TP6800_R33_PIXEL_END_H, 0x02},
+               {TP6800_R34_LINE_START, 0x0f},
+               {TP6800_R35_LINE_END_L, 0xf4},
+               {TP6800_R36_LINE_END_H, 0x01},
+               {TP6800_R78_FORMAT, 0x01},      /* qvga */
+               {TP6800_R12_SIF_ADDR_S, 0x21},  /* soi763a i2c addr */
+               {TP6800_R1A_SIF_TX_DATA2, 0x00},
+       };
+       static const struct cmd sensor_init[] = {
+               {0x12, 0x48},           /* mirror - RGB */
+               {0x13, 0xa0},           /* clock - no AGC nor AEC */
+               {0x03, 0xa4},           /* saturation */
+               {0x04, 0x30},           /* hue */
+               {0x05, 0x88},           /* contrast */
+               {0x06, 0x60},           /* brightness */
+               {0x10, 0x41},           /* AEC */
+               {0x11, 0x40},           /* clock rate */
+               {0x13, 0xa0},
+               {0x14, 0x00},           /* 640x480 */
+               {0x15, 0x14},
+               {0x1f, 0x41},
+               {0x20, 0x80},
+               {0x23, 0xee},
+               {0x24, 0x50},
+               {0x25, 0x7a},
+               {0x26, 0x00},
+               {0x27, 0xe2},
+               {0x28, 0xb0},
+               {0x2a, 0x00},
+               {0x2b, 0x00},
+               {0x2d, 0x81},
+               {0x2f, 0x9d},
+               {0x60, 0x80},
+               {0x61, 0x00},
+               {0x62, 0x88},
+               {0x63, 0x11},
+               {0x64, 0x89},
+               {0x65, 0x00},
+               {0x67, 0x94},
+               {0x68, 0x7a},
+               {0x69, 0x0f},
+               {0x6c, 0x80},
+               {0x6d, 0x80},
+               {0x6e, 0x80},
+               {0x6f, 0xff},
+               {0x71, 0x20},
+               {0x74, 0x20},
+               {0x75, 0x86},
+               {0x77, 0xb5},
+               {0x17, 0x18},           /* H href start */
+               {0x18, 0xbf},           /* H href end */
+               {0x19, 0x03},           /* V start */
+               {0x1a, 0xf8},           /* V end */
+               {0x01, 0x80},           /* blue gain */
+               {0x02, 0x80},           /* red gain */
+       };
+
+       reg_w_buf(gspca_dev, reg_init, ARRAY_SIZE(reg_init));
+
+       i2c_w(gspca_dev, 0x12, 0x80);           /* sensor reset */
+       msleep(10);
+
+       i2c_w_buf(gspca_dev, sensor_init, ARRAY_SIZE(sensor_init));
+
+       reg_w(gspca_dev, TP6800_R5C_EDGE_THRLD, 0x10);
+       reg_w(gspca_dev, TP6800_R54_DARK_CFG, 0x00);
+
+       setsharpness(gspca_dev);
+
+       bulk_w(gspca_dev, 0x03, color_gain[SENSOR_SOI763A],
+                               ARRAY_SIZE(color_gain[0]));
+
+       set_led(gspca_dev, 1);
+       setexposure(gspca_dev);
+       setquality(gspca_dev);
+       setgamma(gspca_dev);
+}
+
+static void soi763a_6810_start(struct gspca_dev *gspca_dev)
+{
+       static const struct cmd bridge_init_2[] = {
+               {TP6800_R7A_BLK_THRLD, 0x00},
+               {TP6800_R79_QUALITY, 0x04},
+               {TP6800_R79_QUALITY, 0x01},
+       };
+       static const struct cmd bridge_init_3[] = {
+               {TP6800_R31_PIXEL_START, 0x20},
+               {TP6800_R32_PIXEL_END_L, 0x9f},
+               {TP6800_R33_PIXEL_END_H, 0x02},
+               {TP6800_R34_LINE_START, 0x13},
+               {TP6800_R35_LINE_END_L, 0xf8},
+               {TP6800_R36_LINE_END_H, 0x01},
+       };
+       static const struct cmd bridge_init_6[] = {
+               {0x08, 0xff},
+               {0x09, 0xff},
+               {0x0a, 0x5f},
+               {0x0b, 0x80},
+       };
+
+       reg_w(gspca_dev, 0x22, gspca_dev->alt);
+       bulk_w(gspca_dev, 0x03, color_null, sizeof color_null);
+       reg_w(gspca_dev, 0x59, 0x40);
+       setexposure(gspca_dev);
+       reg_w_buf(gspca_dev, bridge_init_2, ARRAY_SIZE(bridge_init_2));
+       reg_w_buf(gspca_dev, tp6810_ov_init_common,
+                       ARRAY_SIZE(tp6810_ov_init_common));
+       reg_w_buf(gspca_dev, bridge_init_3, ARRAY_SIZE(bridge_init_3));
+       if (gspca_dev->curr_mode) {
+               reg_w(gspca_dev, 0x4a, 0x7f);
+               reg_w(gspca_dev, 0x07, 0x05);
+               reg_w(gspca_dev, TP6800_R78_FORMAT, 0x00);      /* vga */
+       } else {
+               reg_w(gspca_dev, 0x4a, 0xff);
+               reg_w(gspca_dev, 0x07, 0x85);
+               reg_w(gspca_dev, TP6800_R78_FORMAT, 0x01);      /* qvga */
+       }
+       setgamma(gspca_dev);
+       reg_w_buf(gspca_dev, tp6810_bridge_start,
+                       ARRAY_SIZE(tp6810_bridge_start));
+
+       if (gspca_dev->curr_mode) {
+               reg_w(gspca_dev, 0x4f, 0x00);
+               reg_w(gspca_dev, 0x4e, 0x7c);
+       }
+
+       reg_w(gspca_dev, 0x00, 0x00);
+
+       setsharpness(gspca_dev);
+       bulk_w(gspca_dev, 0x03, color_gain[SENSOR_SOI763A],
+                               ARRAY_SIZE(color_gain[0]));
+       set_led(gspca_dev, 1);
+       reg_w(gspca_dev, TP6800_R3F_FRAME_RATE, 0xf0);
+       setexposure(gspca_dev);
+       reg_w_buf(gspca_dev, bridge_init_6, ARRAY_SIZE(bridge_init_6));
+}
+
+/* -- start the camera -- */
+static int sd_start(struct gspca_dev *gspca_dev)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width);
+       set_dqt(gspca_dev, sd->quality);
+       if (sd->bridge == BRIDGE_TP6800) {
+               if (sd->sensor == SENSOR_CX0342)
+                       cx0342_6800_start(gspca_dev);
+               else
+                       soi763a_6800_start(gspca_dev);
+       } else {
+               if (sd->sensor == SENSOR_CX0342)
+                       cx0342_6810_start(gspca_dev);
+               else
+                       soi763a_6810_start(gspca_dev);
+               reg_w_buf(gspca_dev, tp6810_late_start,
+                               ARRAY_SIZE(tp6810_late_start));
+               reg_w(gspca_dev, 0x80, 0x03);
+               reg_w(gspca_dev, 0x82, gspca_dev->curr_mode ? 0x0a : 0x0e);
+
+               setexposure(gspca_dev);
+               setquality(gspca_dev);
+               setautogain(gspca_dev);
+       }
+
+       setframerate(gspca_dev);
+
+       return gspca_dev->usb_err;
+}
+
+static void sd_stopN(struct gspca_dev *gspca_dev)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       if (sd->bridge == BRIDGE_TP6800)
+               reg_w(gspca_dev, TP6800_R2F_TIMING_CFG, 0x03);
+       set_led(gspca_dev, 0);
+       reg_w(gspca_dev, TP6800_R21_ENDP_1_CTL, 0x00);
+}
+
+static void sd_pkt_scan(struct gspca_dev *gspca_dev,
+                       u8 *data,
+                       int len)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       /* the start of frame contains:
+        *      ff d8
+        *      ff fe
+        *      width / 16
+        *      height / 8
+        *      quality
+        */
+       if (sd->bridge == BRIDGE_TP6810) {
+               if (*data != 0x5a) {
+/*fixme: don't discard the whole frame..*/
+                       if (*data == 0xaa || *data == 0x00)
+                               return;
+                       if (*data > 0xc0) {
+                               PDEBUG(D_FRAM, "bad frame");
+                               gspca_dev->last_packet_type = DISCARD_PACKET;
+                               return;
+                       }
+               }
+               data++;
+               len--;
+               if (*data == 0xff && data[1] == 0xd8) {
+/*fixme: there may be information in the 4 high bits*/
+                       if ((data[6] & 0x0f) != sd->quality)
+                               set_dqt(gspca_dev, data[6] & 0x0f);
+                       gspca_frame_add(gspca_dev, FIRST_PACKET,
+                                       sd->jpeg_hdr, JPEG_HDR_SZ);
+                       gspca_frame_add(gspca_dev, INTER_PACKET,
+                                       data + 7, len - 7);
+               } else if (data[len - 2] == 0xff && data[len - 1] == 0xd9) {
+                       gspca_frame_add(gspca_dev, LAST_PACKET,
+                                       data, len);
+               } else {
+                       gspca_frame_add(gspca_dev, INTER_PACKET,
+                                       data, len);
+               }
+               return;
+       }
+
+       switch (*data) {
+       case 0x55:
+               gspca_frame_add(gspca_dev, LAST_PACKET, data, 0);
+
+               if (len < 8
+                || data[1] != 0xff || data[2] != 0xd8
+                || data[3] != 0xff || data[4] != 0xfe) {
+
+                       /* Have only seen this with corrupt frames */
+                       gspca_dev->last_packet_type = DISCARD_PACKET;
+                       return;
+               }
+               if (data[7] != sd->quality)
+                       set_dqt(gspca_dev, data[7]);
+               gspca_frame_add(gspca_dev, FIRST_PACKET,
+                               sd->jpeg_hdr, JPEG_HDR_SZ);
+               gspca_frame_add(gspca_dev, INTER_PACKET,
+                               data + 8, len - 8);
+               break;
+       case 0xaa:
+               gspca_dev->last_packet_type = DISCARD_PACKET;
+               break;
+       case 0xcc:
+               if (data[1] != 0xff || data[2] != 0xd8)
+                       gspca_frame_add(gspca_dev, INTER_PACKET,
+                                       data + 1, len - 1);
+               else
+                       gspca_dev->last_packet_type = DISCARD_PACKET;
+               break;
+       }
+}
+
+/* -- do autogain -- */
+/* gain setting is done in setexposure() for tp6810 */
+static void setgain(struct gspca_dev *gspca_dev) {}
+/* !! coarse_grained_expo_autogain is not used !! */
+#define exp_too_low_cnt bridge
+#define exp_too_high_cnt sensor
+
+#include "autogain_functions.h"
+static void sd_dq_callback(struct gspca_dev *gspca_dev)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       int ret, alen;
+       int luma, expo;
+
+       if (sd->ag_cnt < 0)
+               return;
+       if (--sd->ag_cnt > 5)
+               return;
+       switch (sd->ag_cnt) {
+/*     case 5: */
+       default:
+               reg_w(gspca_dev, 0x7d, 0x00);
+               break;
+       case 4:
+               reg_w(gspca_dev, 0x27, 0xb0);
+               break;
+       case 3:
+               reg_w(gspca_dev, 0x0c, 0x01);
+               break;
+       case 2:
+               ret = usb_bulk_msg(gspca_dev->dev,
+                               usb_rcvbulkpipe(gspca_dev->dev, 0x02),
+                               gspca_dev->usb_buf,
+                               32,
+                               &alen,
+                               500);
+               if (ret < 0) {
+                       pr_err("bulk err %d\n", ret);
+                       break;
+               }
+               /* values not used (unknown) */
+               break;
+       case 1:
+               reg_w(gspca_dev, 0x27, 0xd0);
+               break;
+       case 0:
+               ret = usb_bulk_msg(gspca_dev->dev,
+                               usb_rcvbulkpipe(gspca_dev->dev, 0x02),
+                               gspca_dev->usb_buf,
+                               32,
+                               &alen,
+                               500);
+               if (ret < 0) {
+                       pr_err("bulk err %d\n", ret);
+                       break;
+               }
+               luma = ((gspca_dev->usb_buf[8] << 8) + gspca_dev->usb_buf[7] +
+                       (gspca_dev->usb_buf[11] << 8) + gspca_dev->usb_buf[10] +
+                       (gspca_dev->usb_buf[14] << 8) + gspca_dev->usb_buf[13] +
+                       (gspca_dev->usb_buf[17] << 8) + gspca_dev->usb_buf[16] +
+                       (gspca_dev->usb_buf[20] << 8) + gspca_dev->usb_buf[19] +
+                       (gspca_dev->usb_buf[23] << 8) + gspca_dev->usb_buf[22] +
+                       (gspca_dev->usb_buf[26] << 8) + gspca_dev->usb_buf[25] +
+                       (gspca_dev->usb_buf[29] << 8) + gspca_dev->usb_buf[28])
+                               / 8;
+               if (gspca_dev->width == 640)
+                       luma /= 4;
+               reg_w(gspca_dev, 0x7d, 0x00);
+
+               expo = sd->ctrls[EXPOSURE].val;
+               ret = auto_gain_n_exposure(gspca_dev, luma,
+                               60,     /* desired luma */
+                               6,      /* dead zone */
+                               2,      /* gain knee */
+                               70);    /* expo knee */
+               sd->ag_cnt = AG_CNT_START;
+               if (sd->bridge == BRIDGE_TP6810) {
+                       if ((expo >= 128 && sd->ctrls[EXPOSURE].val < 128)
+                        || (expo < 128 && sd->ctrls[EXPOSURE].val >= 128))
+                               setframerate(gspca_dev);
+               }
+               break;
+       }
+}
+
+/* get stream parameters (framerate) */
+static void sd_get_streamparm(struct gspca_dev *gspca_dev,
+                            struct v4l2_streamparm *parm)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       struct v4l2_captureparm *cp = &parm->parm.capture;
+       struct v4l2_fract *tpf = &cp->timeperframe;
+       int fr, i;
+
+       cp->capability |= V4L2_CAP_TIMEPERFRAME;
+       tpf->numerator = 1;
+       i = get_fr_idx(gspca_dev);
+       if (i & 0x80) {
+               if (sd->bridge == BRIDGE_TP6800)
+                       fr = rates[6 - (i & 0x07)];
+               else
+                       fr = rates_6810[7 - (i & 0x07)];
+       } else {
+               fr = rates[6 - i];
+       }
+       tpf->denominator = fr;
+}
+
+/* set stream parameters (framerate) */
+static void sd_set_streamparm(struct gspca_dev *gspca_dev,
+                            struct v4l2_streamparm *parm)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       struct v4l2_captureparm *cp = &parm->parm.capture;
+       struct v4l2_fract *tpf = &cp->timeperframe;
+       int fr, i;
+
+       sd->framerate = tpf->denominator / tpf->numerator;
+       if (gspca_dev->streaming)
+               setframerate(gspca_dev);
+
+       /* Return the actual framerate */
+       i = get_fr_idx(gspca_dev);
+       if (i & 0x80)
+               fr = rates_6810[7 - (i & 0x07)];
+       else
+               fr = rates[6 - i];
+       tpf->numerator = 1;
+       tpf->denominator = fr;
+}
+
+static int sd_set_jcomp(struct gspca_dev *gspca_dev,
+                       struct v4l2_jpegcompression *jcomp)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       if (sd->sensor == SENSOR_SOI763A)
+               jpeg_set_qual(sd->jpeg_hdr, jcomp->quality);
+/*     else
+               fixme: TODO
+*/
+       return gspca_dev->usb_err;
+}
+
+static int sd_get_jcomp(struct gspca_dev *gspca_dev,
+                       struct v4l2_jpegcompression *jcomp)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       memset(jcomp, 0, sizeof *jcomp);
+       jcomp->quality = jpeg_q[sd->quality];
+       jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
+                       | V4L2_JPEG_MARKER_DQT;
+       return 0;
+}
+
+static struct ctrl sd_ctrls[NCTRLS] = {
+[EXPOSURE] = {
+           {
+               .id = V4L2_CID_EXPOSURE,
+               .type = V4L2_CTRL_TYPE_INTEGER,
+               .name = "Exposure",
+               .minimum = 0x01,
+               .maximum = 0xdc,
+               .step = 1,
+               .default_value = 0x4e,
+           },
+           .set_control = setexposure
+       },
+[QUALITY] = {
+           {
+               .id = V4L2_CID_PRIVATE_BASE,
+               .type = V4L2_CTRL_TYPE_INTEGER,
+               .name = "Compression quality",
+               .minimum = 0,
+               .maximum = 15,
+               .step = 1,
+               .default_value = 13,
+           },
+           .set_control = setquality
+       },
+[RGAIN] = {
+           {
+               .id = V4L2_CID_RED_BALANCE,
+               .type = V4L2_CTRL_TYPE_INTEGER,
+               .name = "Red balance",
+               .minimum = 0,
+               .maximum = 4095,
+               .step = 1,
+               .default_value = 256,
+           },
+           .set_control = setrgain
+       },
+[GAIN] = {
+           {
+               .id = V4L2_CID_GAIN,
+               .type = V4L2_CTRL_TYPE_INTEGER,
+               .name = "Gain",
+               .minimum = 0,
+               .maximum = 4095,
+               .step = 1,
+               .default_value = 256,
+           },
+           .set = sd_setgain
+       },
+[BGAIN] = {
+           {
+               .id = V4L2_CID_BLUE_BALANCE,
+               .type = V4L2_CTRL_TYPE_INTEGER,
+               .name = "Blue balance",
+               .minimum = 0,
+               .maximum = 4095,
+               .step = 1,
+               .default_value = 256,
+           },
+           .set_control = setbgain
+       },
+[SHARPNESS] = {
+           {
+               .id      = V4L2_CID_SHARPNESS,
+               .type    = V4L2_CTRL_TYPE_INTEGER,
+               .name    = "Sharpness",
+               .minimum = 0,
+               .maximum = 3,
+               .step    = 1,
+               .default_value = 2,
+           },
+           .set_control = setsharpness
+       },
+[GAMMA] = {
+           {
+               .id      = V4L2_CID_GAMMA,
+               .type    = V4L2_CTRL_TYPE_INTEGER,
+               .name    = "Gamma",
+               .minimum = 0,
+               .maximum = NGAMMA - 1,
+               .step    = 1,
+               .default_value = 1,
+           },
+           .set_control = setgamma
+       },
+[AUTOGAIN] = {
+           {
+               .id      = V4L2_CID_AUTOGAIN,
+               .type    = V4L2_CTRL_TYPE_BOOLEAN,
+               .name    = "Auto Gain",
+               .minimum = 0,
+               .maximum = 1,
+               .step    = 1,
+               .default_value = AUTOGAIN_DEF
+           },
+           .set_control = setautogain
+       },
+};
+
+static const struct sd_desc sd_desc = {
+       .name = KBUILD_MODNAME,
+       .ctrls = sd_ctrls,
+       .nctrls = NCTRLS,
+       .config = sd_config,
+       .init = sd_init,
+       .isoc_init = sd_isoc_init,
+       .start = sd_start,
+       .stopN = sd_stopN,
+       .pkt_scan = sd_pkt_scan,
+       .dq_callback = sd_dq_callback,
+       .get_streamparm = sd_get_streamparm,
+       .set_streamparm = sd_set_streamparm,
+       .get_jcomp = sd_get_jcomp,
+       .set_jcomp = sd_set_jcomp,
+};
+
+static const struct usb_device_id device_table[] = {
+       {USB_DEVICE(0x06a2, 0x0003), .driver_info = BRIDGE_TP6800},
+       {USB_DEVICE(0x06a2, 0x6810), .driver_info = BRIDGE_TP6810},
+       {}                      /* Terminating entry */
+};
+
+MODULE_DEVICE_TABLE(usb, device_table);
+
+static int sd_probe(struct usb_interface *interface,
+                   const struct usb_device_id *id)
+{
+       return gspca_dev_probe(interface, id, &sd_desc, sizeof(struct sd),
+                              THIS_MODULE);
+}
+
+static struct usb_driver sd_driver = {
+       .name = KBUILD_MODNAME,
+       .id_table = device_table,
+       .probe = sd_probe,
+       .disconnect = gspca_disconnect,
+#ifdef CONFIG_PM
+       .suspend = gspca_suspend,
+       .resume = gspca_resume,
+       .reset_resume = gspca_resume,
+#endif
+};
+
+/* -- module insert / remove -- */
+static int __init sd_mod_init(void)
+{
+       return usb_register(&sd_driver);
+}
+static void __exit sd_mod_exit(void)
+{
+       usb_deregister(&sd_driver);
+}
+
+module_init(sd_mod_init);
+module_exit(sd_mod_exit);
+
+module_param(force_sensor, int, 0644);
+MODULE_PARM_DESC(force_sensor,
+       "Force sensor. 0: cx0342, 1: soi763a");
index 6caed734a06ab0559892a869f330f0d0840f8865..7ee2c8271dcc04cfd6adc21c3b14662615aa8a9d 100644 (file)
@@ -20,6 +20,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "vc032x"
 
 #include "gspca.h"
@@ -3169,7 +3171,7 @@ static void reg_r_i(struct gspca_dev *gspca_dev,
                        index, gspca_dev->usb_buf, len,
                        500);
        if (ret < 0) {
-               err("reg_r err %d", ret);
+               pr_err("reg_r err %d\n", ret);
                gspca_dev->usb_err = ret;
        }
 }
@@ -3210,7 +3212,7 @@ static void reg_w_i(struct gspca_dev *gspca_dev,
                        value, index, NULL, 0,
                        500);
        if (ret < 0) {
-               err("reg_w err %d", ret);
+               pr_err("reg_w err %d\n", ret);
                gspca_dev->usb_err = ret;
        }
 }
@@ -3235,8 +3237,7 @@ static u16 read_sensor_register(struct gspca_dev *gspca_dev,
 
        reg_r(gspca_dev, 0xa1, 0xb33f, 1);
        if (!(gspca_dev->usb_buf[0] & 0x02)) {
-               err("I2c Bus Busy Wait %02x",
-                       gspca_dev->usb_buf[0]);
+               pr_err("I2c Bus Busy Wait %02x\n", gspca_dev->usb_buf[0]);
                return 0;
        }
        reg_w(gspca_dev, 0xa0, address, 0xb33a);
@@ -3349,7 +3350,7 @@ static void i2c_write(struct gspca_dev *gspca_dev,
                msleep(20);
        } while (--retry > 0);
        if (retry <= 0)
-               err("i2c_write timeout");
+               pr_err("i2c_write timeout\n");
 }
 
 static void put_tab_to_reg(struct gspca_dev *gspca_dev,
@@ -3446,7 +3447,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
 
        switch (sensor) {
        case -1:
-               err("Unknown sensor...");
+               pr_err("Unknown sensor...\n");
                return -EINVAL;
        case SENSOR_HV7131R:
                PDEBUG(D_PROBE, "Find Sensor HV7131R");
index 84dfbab923b59b3a063767ff7b0cb08de78f9f90..81dd4c99d025aedb51c8e344c083541f92fc8ac9 100644 (file)
@@ -26,6 +26,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "vicam"
 #define HEADER_SIZE 64
 
@@ -117,7 +119,7 @@ static int vicam_control_msg(struct gspca_dev *gspca_dev, u8 request,
                              USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
                              value, index, data, len, 1000);
        if (ret < 0)
-               err("control msg req %02X error %d", request, ret);
+               pr_err("control msg req %02X error %d\n", request, ret);
 
        return ret;
 }
@@ -189,8 +191,8 @@ static int vicam_read_frame(struct gspca_dev *gspca_dev, u8 *data, int size)
                           data, size, &act_len, 10000);
        /* successful, it returns 0, otherwise  negative */
        if (ret < 0 || act_len != size) {
-               err("bulk read fail (%d) len %d/%d",
-                       ret, act_len, size);
+               pr_err("bulk read fail (%d) len %d/%d\n",
+                      ret, act_len, size);
                return -EIO;
        }
        return 0;
@@ -216,7 +218,7 @@ static void vicam_dostream(struct work_struct *work)
                   HEADER_SIZE;
        buffer = kmalloc(frame_sz, GFP_KERNEL | GFP_DMA);
        if (!buffer) {
-               err("Couldn't allocate USB buffer");
+               pr_err("Couldn't allocate USB buffer\n");
                goto exit;
        }
 
@@ -269,7 +271,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
        ret = request_ihex_firmware(&fw, "vicam/firmware.fw",
                                    &gspca_dev->dev->dev);
        if (ret) {
-               err("Failed to load \"vicam/firmware.fw\": %d\n", ret);
+               pr_err("Failed to load \"vicam/firmware.fw\": %d\n", ret);
                return ret;
        }
 
index 4a9e622e5e1bf677d9c8d19c61238beddbc7a17c..27d2cef0692a8dafa834bb5ba408614a0cd785e3 100644 (file)
@@ -31,6 +31,8 @@
    the sensor drivers to v4l2 sub drivers, and properly split of this
    driver from ov519.c */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define W9968CF_I2C_BUS_DELAY    4 /* delay in us for I2C bit r/w operations */
 
 #define Y_QUANTABLE (&sd->jpeg_hdr[JPEG_QT0_OFFSET])
@@ -81,7 +83,7 @@ static void w9968cf_write_fsb(struct sd *sd, u16* data)
                              USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
                              value, 0x06, sd->gspca_dev.usb_buf, 6, 500);
        if (ret < 0) {
-               err("Write FSB registers failed (%d)", ret);
+               pr_err("Write FSB registers failed (%d)\n", ret);
                sd->gspca_dev.usb_err = ret;
        }
 }
@@ -108,7 +110,7 @@ static void w9968cf_write_sb(struct sd *sd, u16 value)
        udelay(W9968CF_I2C_BUS_DELAY);
 
        if (ret < 0) {
-               err("Write SB reg [01] %04x failed", value);
+               pr_err("Write SB reg [01] %04x failed\n", value);
                sd->gspca_dev.usb_err = ret;
        }
 }
@@ -135,7 +137,7 @@ static int w9968cf_read_sb(struct sd *sd)
                ret = sd->gspca_dev.usb_buf[0] |
                      (sd->gspca_dev.usb_buf[1] << 8);
        } else {
-               err("Read SB reg [01] failed");
+               pr_err("Read SB reg [01] failed\n");
                sd->gspca_dev.usb_err = ret;
        }
 
index c089a0f6f1d034924553357e6645584bb82504ea..3aed42acdb5ae82bc9eb21d9113c14593dd4cf8c 100644 (file)
@@ -27,6 +27,8 @@
  *
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "xirlink-cit"
 
 #include <linux/input.h>
@@ -800,8 +802,8 @@ static int cit_write_reg(struct gspca_dev *gspca_dev, u16 value, u16 index)
                        USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT,
                        value, index, NULL, 0, 1000);
        if (err < 0)
-               err("Failed to write a register (index 0x%04X,"
-                       " value 0x%02X, error %d)", index, value, err);
+               pr_err("Failed to write a register (index 0x%04X, value 0x%02X, error %d)\n",
+                      index, value, err);
 
        return 0;
 }
@@ -816,8 +818,8 @@ static int cit_read_reg(struct gspca_dev *gspca_dev, u16 index, int verbose)
                        USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT,
                        0x00, index, buf, 8, 1000);
        if (res < 0) {
-               err("Failed to read a register (index 0x%04X, error %d)",
-                       index, res);
+               pr_err("Failed to read a register (index 0x%04X, error %d)\n",
+                      index, res);
                return res;
        }
 
@@ -1587,7 +1589,7 @@ static int cit_get_packet_size(struct gspca_dev *gspca_dev)
        intf = usb_ifnum_to_if(gspca_dev->dev, gspca_dev->iface);
        alt = usb_altnum_to_altsetting(intf, gspca_dev->alt);
        if (!alt) {
-               err("Couldn't get altsetting");
+               pr_err("Couldn't get altsetting\n");
                return -EIO;
        }
 
@@ -2824,7 +2826,7 @@ static int sd_isoc_nego(struct gspca_dev *gspca_dev)
 
        ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, 1);
        if (ret < 0)
-               err("set alt 1 err %d", ret);
+               pr_err("set alt 1 err %d\n", ret);
 
        return ret;
 }
index 61cdd56a74a9761783dd3ee00b16850e5b0053c9..30ea1e479492ecd814c973394e97938886ee7888 100644 (file)
@@ -19,6 +19,8 @@
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define MODULE_NAME "zc3xx"
 
 #include <linux/input.h>
@@ -5666,7 +5668,7 @@ static u8 reg_r_i(struct gspca_dev *gspca_dev,
                        index, gspca_dev->usb_buf, 1,
                        500);
        if (ret < 0) {
-               err("reg_r_i err %d", ret);
+               pr_err("reg_r_i err %d\n", ret);
                gspca_dev->usb_err = ret;
                return 0;
        }
@@ -5698,7 +5700,7 @@ static void reg_w_i(struct gspca_dev *gspca_dev,
                        value, index, NULL, 0,
                        500);
        if (ret < 0) {
-               err("reg_w_i err %d", ret);
+               pr_err("reg_w_i err %d\n", ret);
                gspca_dev->usb_err = ret;
        }
 }
@@ -5724,7 +5726,7 @@ static u16 i2c_read(struct gspca_dev *gspca_dev,
        msleep(20);
        retbyte = reg_r_i(gspca_dev, 0x0091);           /* read status */
        if (retbyte != 0x00)
-               err("i2c_r status error %02x", retbyte);
+               pr_err("i2c_r status error %02x\n", retbyte);
        retval = reg_r_i(gspca_dev, 0x0095);            /* read Lowbyte */
        retval |= reg_r_i(gspca_dev, 0x0096) << 8;      /* read Hightbyte */
        PDEBUG(D_USBI, "i2c r [%02x] -> %04x (%02x)",
@@ -5748,7 +5750,7 @@ static u8 i2c_write(struct gspca_dev *gspca_dev,
        msleep(1);
        retbyte = reg_r_i(gspca_dev, 0x0091);           /* read status */
        if (retbyte != 0x00)
-               err("i2c_w status error %02x", retbyte);
+               pr_err("i2c_w status error %02x\n", retbyte);
        PDEBUG(D_USBO, "i2c w [%02x] = %02x%02x (%02x)",
                        reg, valH, valL, retbyte);
        return retbyte;
@@ -6497,7 +6499,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
                                PDEBUG(D_PROBE, "Sensor GC0303");
                                break;
                        default:
-                               warn("Unknown sensor - set to TAS5130C");
+                               pr_warn("Unknown sensor - set to TAS5130C\n");
                                sd->sensor = SENSOR_TAS5130C;
                        }
                        break;
@@ -6603,7 +6605,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
                        sd->sensor = SENSOR_OV7620;     /* same sensor (?) */
                        break;
                default:
-                       err("Unknown sensor %04x", sensor);
+                       pr_err("Unknown sensor %04x\n", sensor);
                        return -EINVAL;
                }
        }
@@ -6970,6 +6972,7 @@ static const struct sd_desc sd_desc = {
 };
 
 static const struct usb_device_id device_table[] = {
+       {USB_DEVICE(0x03f0, 0x1b07)},
        {USB_DEVICE(0x041e, 0x041e)},
        {USB_DEVICE(0x041e, 0x4017)},
        {USB_DEVICE(0x041e, 0x401c), .driver_info = SENSOR_PAS106},
index 3baa9f613ca36aa82efaff5742cbb463c698c13a..52f057f24e3944a174b134bc65921abb55b78070 100644 (file)
@@ -2,6 +2,6 @@ hdpvr-objs      := hdpvr-control.o hdpvr-core.o hdpvr-video.o hdpvr-i2c.o
 
 obj-$(CONFIG_VIDEO_HDPVR) += hdpvr.o
 
-EXTRA_CFLAGS += -Idrivers/media/video
+ccflags-y += -Idrivers/media/video
 
-EXTRA_CFLAGS += $(extra-cflags-y) $(extra-cflags-m)
+ccflags-y += $(extra-cflags-y) $(extra-cflags-m)
index cbc505a2fc29cecf838ed92592db2e576fb021ec..9cb039e593dbc78140d7f801e31dfbd9a30ddc9f 100644 (file)
@@ -21,6 +21,8 @@
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define DEBUG_VARIABLE debug
 
 #include <media/saa7146_vv.h>
@@ -175,13 +177,14 @@ static int hexium_init_done(struct saa7146_dev *dev)
        union i2c_smbus_data data;
        int i = 0;
 
-       DEB_D(("hexium_init_done called.\n"));
+       DEB_D("hexium_init_done called\n");
 
        /* initialize the helper ics to useful values */
        for (i = 0; i < sizeof(hexium_ks0127b); i++) {
                data.byte = hexium_ks0127b[i];
                if (0 != i2c_smbus_xfer(&hexium->i2c_adapter, 0x6c, 0, I2C_SMBUS_WRITE, i, I2C_SMBUS_BYTE_DATA, &data)) {
-                       printk("hexium_gemini: hexium_init_done() failed for address 0x%02x\n", i);
+                       pr_err("hexium_init_done() failed for address 0x%02x\n",
+                              i);
                }
        }
 
@@ -192,7 +195,7 @@ static int hexium_set_input(struct hexium *hexium, int input)
 {
        union i2c_smbus_data data;
 
-       DEB_D((".\n"));
+       DEB_D("\n");
 
        data.byte = hexium_input_select[input].byte;
        if (0 != i2c_smbus_xfer(&hexium->i2c_adapter, 0x6c, 0, I2C_SMBUS_WRITE, hexium_input_select[input].adr, I2C_SMBUS_BYTE_DATA, &data)) {
@@ -207,12 +210,13 @@ static int hexium_set_standard(struct hexium *hexium, struct hexium_data *vdec)
        union i2c_smbus_data data;
        int i = 0;
 
-       DEB_D((".\n"));
+       DEB_D("\n");
 
        while (vdec[i].adr != -1) {
                data.byte = vdec[i].byte;
                if (0 != i2c_smbus_xfer(&hexium->i2c_adapter, 0x6c, 0, I2C_SMBUS_WRITE, vdec[i].adr, I2C_SMBUS_BYTE_DATA, &data)) {
-                       printk("hexium_init_done: hexium_set_standard() failed for address 0x%02x\n", i);
+                       pr_err("hexium_init_done: hexium_set_standard() failed for address 0x%02x\n",
+                              i);
                        return -1;
                }
                i++;
@@ -222,14 +226,14 @@ static int hexium_set_standard(struct hexium *hexium, struct hexium_data *vdec)
 
 static int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *i)
 {
-       DEB_EE(("VIDIOC_ENUMINPUT %d.\n", i->index));
+       DEB_EE("VIDIOC_ENUMINPUT %d\n", i->index);
 
        if (i->index >= HEXIUM_INPUTS)
                return -EINVAL;
 
        memcpy(i, &hexium_inputs[i->index], sizeof(struct v4l2_input));
 
-       DEB_D(("v4l2_ioctl: VIDIOC_ENUMINPUT %d.\n", i->index));
+       DEB_D("v4l2_ioctl: VIDIOC_ENUMINPUT %d\n", i->index);
        return 0;
 }
 
@@ -240,7 +244,7 @@ static int vidioc_g_input(struct file *file, void *fh, unsigned int *input)
 
        *input = hexium->cur_input;
 
-       DEB_D(("VIDIOC_G_INPUT: %d\n", *input));
+       DEB_D("VIDIOC_G_INPUT: %d\n", *input);
        return 0;
 }
 
@@ -249,7 +253,7 @@ static int vidioc_s_input(struct file *file, void *fh, unsigned int input)
        struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
        struct hexium *hexium = (struct hexium *) dev->ext_priv;
 
-       DEB_EE(("VIDIOC_S_INPUT %d.\n", input));
+       DEB_EE("VIDIOC_S_INPUT %d\n", input);
 
        if (input >= HEXIUM_INPUTS)
                return -EINVAL;
@@ -270,7 +274,7 @@ static int vidioc_queryctrl(struct file *file, void *fh, struct v4l2_queryctrl *
        for (i = HEXIUM_CONTROLS - 1; i >= 0; i--) {
                if (hexium_controls[i].id == qc->id) {
                        *qc = hexium_controls[i];
-                       DEB_D(("VIDIOC_QUERYCTRL %d.\n", qc->id));
+                       DEB_D("VIDIOC_QUERYCTRL %d\n", qc->id);
                        return 0;
                }
        }
@@ -293,7 +297,7 @@ static int vidioc_g_ctrl(struct file *file, void *fh, struct v4l2_control *vc)
 
        if (vc->id == V4L2_CID_PRIVATE_BASE) {
                vc->value = hexium->cur_bw;
-               DEB_D(("VIDIOC_G_CTRL BW:%d.\n", vc->value));
+               DEB_D("VIDIOC_G_CTRL BW:%d\n", vc->value);
                return 0;
        }
        return -EINVAL;
@@ -316,7 +320,7 @@ static int vidioc_s_ctrl(struct file *file, void *fh, struct v4l2_control *vc)
        if (vc->id == V4L2_CID_PRIVATE_BASE)
                hexium->cur_bw = vc->value;
 
-       DEB_D(("VIDIOC_S_CTRL BW:%d.\n", hexium->cur_bw));
+       DEB_D("VIDIOC_S_CTRL BW:%d\n", hexium->cur_bw);
 
        if (0 == hexium->cur_bw && V4L2_STD_PAL == hexium->cur_std) {
                hexium_set_standard(hexium, hexium_pal);
@@ -351,14 +355,14 @@ static struct saa7146_ext_vv vv_data;
 /* this function only gets called when the probing was successful */
 static int hexium_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data *info)
 {
-       struct hexium *hexium = (struct hexium *) dev->ext_priv;
+       struct hexium *hexium;
        int ret;
 
-       DEB_EE((".\n"));
+       DEB_EE("\n");
 
        hexium = kzalloc(sizeof(struct hexium), GFP_KERNEL);
        if (NULL == hexium) {
-               printk("hexium_gemini: not enough kernel memory in hexium_attach().\n");
+               pr_err("not enough kernel memory in hexium_attach()\n");
                return -ENOMEM;
        }
        dev->ext_priv = hexium;
@@ -371,7 +375,7 @@ static int hexium_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_d
        };
        saa7146_i2c_adapter_prepare(dev, &hexium->i2c_adapter, SAA7146_I2C_BUS_BIT_RATE_480);
        if (i2c_add_adapter(&hexium->i2c_adapter) < 0) {
-               DEB_S(("cannot register i2c-device. skipping.\n"));
+               DEB_S("cannot register i2c-device. skipping.\n");
                kfree(hexium);
                return -EFAULT;
        }
@@ -402,11 +406,11 @@ static int hexium_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_d
        vv_data.ops.vidioc_s_input = vidioc_s_input;
        ret = saa7146_register_device(&hexium->video_dev, dev, "hexium gemini", VFL_TYPE_GRABBER);
        if (ret < 0) {
-               printk("hexium_gemini: cannot register capture v4l2 device. skipping.\n");
+               pr_err("cannot register capture v4l2 device. skipping.\n");
                return ret;
        }
 
-       printk("hexium_gemini: found 'hexium gemini' frame grabber-%d.\n", hexium_num);
+       pr_info("found 'hexium gemini' frame grabber-%d\n", hexium_num);
        hexium_num++;
 
        return 0;
@@ -416,7 +420,7 @@ static int hexium_detach(struct saa7146_dev *dev)
 {
        struct hexium *hexium = (struct hexium *) dev->ext_priv;
 
-       DEB_EE(("dev:%p\n", dev));
+       DEB_EE("dev:%p\n", dev);
 
        saa7146_unregister_device(&hexium->video_dev, dev);
        saa7146_vv_release(dev);
@@ -508,7 +512,7 @@ static struct saa7146_extension hexium_extension = {
 static int __init hexium_init_module(void)
 {
        if (0 != saa7146_register_extension(&hexium_extension)) {
-               DEB_S(("failed to register extension.\n"));
+               DEB_S("failed to register extension\n");
                return -ENODEV;
        }
 
index 6ad7e1c8b92266500019be37b841830c676d6b4e..74861a4b601aff51589e96fabb61167b51fa993f 100644 (file)
@@ -21,6 +21,8 @@
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define DEBUG_VARIABLE debug
 
 #include <media/saa7146_vv.h>
@@ -209,7 +211,7 @@ static int hexium_probe(struct saa7146_dev *dev)
        union i2c_smbus_data data;
        int err = 0;
 
-       DEB_EE((".\n"));
+       DEB_EE("\n");
 
        /* there are no hexium orion cards with revision 0 saa7146s */
        if (0 == dev->revision) {
@@ -218,7 +220,7 @@ static int hexium_probe(struct saa7146_dev *dev)
 
        hexium = kzalloc(sizeof(struct hexium), GFP_KERNEL);
        if (NULL == hexium) {
-               printk("hexium_orion: hexium_probe: not enough kernel memory.\n");
+               pr_err("hexium_probe: not enough kernel memory\n");
                return -ENOMEM;
        }
 
@@ -234,7 +236,7 @@ static int hexium_probe(struct saa7146_dev *dev)
        };
        saa7146_i2c_adapter_prepare(dev, &hexium->i2c_adapter, SAA7146_I2C_BUS_BIT_RATE_480);
        if (i2c_add_adapter(&hexium->i2c_adapter) < 0) {
-               DEB_S(("cannot register i2c-device. skipping.\n"));
+               DEB_S("cannot register i2c-device. skipping.\n");
                kfree(hexium);
                return -EFAULT;
        }
@@ -248,7 +250,7 @@ static int hexium_probe(struct saa7146_dev *dev)
 
        /* detect newer Hexium Orion cards by subsystem ids */
        if (0x17c8 == dev->pci->subsystem_vendor && 0x0101 == dev->pci->subsystem_device) {
-               printk("hexium_orion: device is a Hexium Orion w/ 1 SVHS + 3 BNC inputs.\n");
+               pr_info("device is a Hexium Orion w/ 1 SVHS + 3 BNC inputs\n");
                /* we store the pointer in our private data field */
                dev->ext_priv = hexium;
                hexium->type = HEXIUM_ORION_1SVHS_3BNC;
@@ -256,7 +258,7 @@ static int hexium_probe(struct saa7146_dev *dev)
        }
 
        if (0x17c8 == dev->pci->subsystem_vendor && 0x2101 == dev->pci->subsystem_device) {
-               printk("hexium_orion: device is a Hexium Orion w/ 4 BNC inputs.\n");
+               pr_info("device is a Hexium Orion w/ 4 BNC inputs\n");
                /* we store the pointer in our private data field */
                dev->ext_priv = hexium;
                hexium->type = HEXIUM_ORION_4BNC;
@@ -266,7 +268,7 @@ static int hexium_probe(struct saa7146_dev *dev)
        /* check if this is an old hexium Orion card by looking at
           a saa7110 at address 0x4e */
        if (0 == (err = i2c_smbus_xfer(&hexium->i2c_adapter, 0x4e, 0, I2C_SMBUS_READ, 0x00, I2C_SMBUS_BYTE_DATA, &data))) {
-               printk("hexium_orion: device is a Hexium HV-PCI6/Orion (old).\n");
+               pr_info("device is a Hexium HV-PCI6/Orion (old)\n");
                /* we store the pointer in our private data field */
                dev->ext_priv = hexium;
                hexium->type = HEXIUM_HV_PCI6_ORION;
@@ -288,13 +290,13 @@ static int hexium_init_done(struct saa7146_dev *dev)
        union i2c_smbus_data data;
        int i = 0;
 
-       DEB_D(("hexium_init_done called.\n"));
+       DEB_D("hexium_init_done called\n");
 
        /* initialize the helper ics to useful values */
        for (i = 0; i < sizeof(hexium_saa7110); i++) {
                data.byte = hexium_saa7110[i];
                if (0 != i2c_smbus_xfer(&hexium->i2c_adapter, 0x4e, 0, I2C_SMBUS_WRITE, i, I2C_SMBUS_BYTE_DATA, &data)) {
-                       printk("hexium_orion: failed for address 0x%02x\n", i);
+                       pr_err("failed for address 0x%02x\n", i);
                }
        }
 
@@ -306,7 +308,7 @@ static int hexium_set_input(struct hexium *hexium, int input)
        union i2c_smbus_data data;
        int i = 0;
 
-       DEB_D((".\n"));
+       DEB_D("\n");
 
        for (i = 0; i < 8; i++) {
                int adr = hexium_input_select[input].data[i].adr;
@@ -314,7 +316,7 @@ static int hexium_set_input(struct hexium *hexium, int input)
                if (0 != i2c_smbus_xfer(&hexium->i2c_adapter, 0x4e, 0, I2C_SMBUS_WRITE, adr, I2C_SMBUS_BYTE_DATA, &data)) {
                        return -1;
                }
-               printk("%d: 0x%02x => 0x%02x\n",input, adr,data.byte);
+               pr_debug("%d: 0x%02x => 0x%02x\n", input, adr, data.byte);
        }
 
        return 0;
@@ -322,14 +324,14 @@ static int hexium_set_input(struct hexium *hexium, int input)
 
 static int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *i)
 {
-       DEB_EE(("VIDIOC_ENUMINPUT %d.\n", i->index));
+       DEB_EE("VIDIOC_ENUMINPUT %d\n", i->index);
 
        if (i->index >= HEXIUM_INPUTS)
                return -EINVAL;
 
        memcpy(i, &hexium_inputs[i->index], sizeof(struct v4l2_input));
 
-       DEB_D(("v4l2_ioctl: VIDIOC_ENUMINPUT %d.\n", i->index));
+       DEB_D("v4l2_ioctl: VIDIOC_ENUMINPUT %d\n", i->index);
        return 0;
 }
 
@@ -340,7 +342,7 @@ static int vidioc_g_input(struct file *file, void *fh, unsigned int *input)
 
        *input = hexium->cur_input;
 
-       DEB_D(("VIDIOC_G_INPUT: %d\n", *input));
+       DEB_D("VIDIOC_G_INPUT: %d\n", *input);
        return 0;
 }
 
@@ -365,18 +367,18 @@ static int hexium_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_d
 {
        struct hexium *hexium = (struct hexium *) dev->ext_priv;
 
-       DEB_EE((".\n"));
+       DEB_EE("\n");
 
        saa7146_vv_init(dev, &vv_data);
        vv_data.ops.vidioc_enum_input = vidioc_enum_input;
        vv_data.ops.vidioc_g_input = vidioc_g_input;
        vv_data.ops.vidioc_s_input = vidioc_s_input;
        if (0 != saa7146_register_device(&hexium->video_dev, dev, "hexium orion", VFL_TYPE_GRABBER)) {
-               printk("hexium_orion: cannot register capture v4l2 device. skipping.\n");
+               pr_err("cannot register capture v4l2 device. skipping.\n");
                return -1;
        }
 
-       printk("hexium_orion: found 'hexium orion' frame grabber-%d.\n", hexium_num);
+       pr_err("found 'hexium orion' frame grabber-%d\n", hexium_num);
        hexium_num++;
 
        /* the rest */
@@ -390,7 +392,7 @@ static int hexium_detach(struct saa7146_dev *dev)
 {
        struct hexium *hexium = (struct hexium *) dev->ext_priv;
 
-       DEB_EE(("dev:%p\n", dev));
+       DEB_EE("dev:%p\n", dev);
 
        saa7146_unregister_device(&hexium->video_dev, dev);
        saa7146_vv_release(dev);
@@ -479,7 +481,7 @@ static struct saa7146_extension extension = {
 static int __init hexium_init_module(void)
 {
        if (0 != saa7146_register_extension(&extension)) {
-               DEB_S(("failed to register extension.\n"));
+               DEB_S("failed to register extension\n");
                return -ENODEV;
        }
 
index 26ce0d6eaee1a3c15a918783130b26eb713827da..71ab76a5ab265b002bb9ad3a6b31f42611ecbe8a 100644 (file)
@@ -7,8 +7,8 @@ ivtv-objs       := ivtv-routing.o ivtv-cards.o ivtv-controls.o \
 obj-$(CONFIG_VIDEO_IVTV) += ivtv.o
 obj-$(CONFIG_VIDEO_FB_IVTV) += ivtvfb.o
 
-EXTRA_CFLAGS += -Idrivers/media/video
-EXTRA_CFLAGS += -Idrivers/media/common/tuners
-EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
-EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
+ccflags-y += -Idrivers/media/video
+ccflags-y += -Idrivers/media/common/tuners
+ccflags-y += -Idrivers/media/dvb/dvb-core
+ccflags-y += -Idrivers/media/dvb/frontends
 
index 3e5c090af112bf12fb229bda27166e08db935d3d..ecafa697326e302803ab85604c0a7ab8aec697f6 100644 (file)
@@ -1203,9 +1203,7 @@ static int ivtv_g_sliced_vbi_cap(struct file *file, void *fh, struct v4l2_sliced
                                        cap->service_lines[f][l] = set;
                        }
                }
-               return 0;
-       }
-       if (cap->type == V4L2_BUF_TYPE_SLICED_VBI_OUTPUT) {
+       } else if (cap->type == V4L2_BUF_TYPE_SLICED_VBI_OUTPUT) {
                if (!(itv->v4l2_cap & V4L2_CAP_SLICED_VBI_OUTPUT))
                        return -EINVAL;
                if (itv->is_60hz) {
@@ -1215,9 +1213,16 @@ static int ivtv_g_sliced_vbi_cap(struct file *file, void *fh, struct v4l2_sliced
                        cap->service_lines[0][23] = V4L2_SLICED_WSS_625;
                        cap->service_lines[0][16] = V4L2_SLICED_VPS;
                }
-               return 0;
+       } else {
+               return -EINVAL;
        }
-       return -EINVAL;
+
+       set = 0;
+       for (f = 0; f < 2; f++)
+               for (l = 0; l < 24; l++)
+                       set |= cap->service_lines[f][l];
+       cap->service_set = set;
+       return 0;
 }
 
 static int ivtv_g_enc_index(struct file *file, void *fh, struct v4l2_enc_idx *idx)
index fb8e4a7a9dd29f27fdf96a5191a4e1581f5ddf56..5d21d056d6a3523dbd440bc77ea78a8f8df2eee6 100644 (file)
@@ -936,7 +936,7 @@ static int __devinit m5mols_probe(struct i2c_client *client,
                return -EINVAL;
        }
 
-       if (!pdata->irq) {
+       if (!client->irq) {
                dev_err(&client->dev, "Interrupt not assigned\n");
                return -EINVAL;
        }
@@ -973,7 +973,7 @@ static int __devinit m5mols_probe(struct i2c_client *client,
 
        init_waitqueue_head(&info->irq_waitq);
        INIT_WORK(&info->work_irq, m5mols_irq_work);
-       ret = request_irq(pdata->irq, m5mols_irq_handler,
+       ret = request_irq(client->irq, m5mols_irq_handler,
                          IRQF_TRIGGER_RISING, MODULE_NAME, sd);
        if (ret) {
                dev_err(&client->dev, "Interrupt request failed: %d\n", ret);
@@ -998,7 +998,7 @@ static int __devexit m5mols_remove(struct i2c_client *client)
        struct m5mols_info *info = to_m5mols(sd);
 
        v4l2_device_unregister_subdev(sd);
-       free_irq(info->pdata->irq, sd);
+       free_irq(client->irq, sd);
 
        regulator_bulk_free(ARRAY_SIZE(supplies), supplies);
        gpio_free(info->pdata->gpio_reset);
index 83c14514cd52c5db2fce764c420506ed02c687a2..1141b976dff47bf3bd56fe1445d652cf601a81a9 100644 (file)
@@ -450,7 +450,7 @@ static void mcam_set_contig_buffer(struct mcam_camera *cam, int frame)
                buf = cam->vb_bufs[frame ^ 0x1];
                cam->vb_bufs[frame] = buf;
                mcam_reg_write(cam, frame == 0 ? REG_Y0BAR : REG_Y1BAR,
-                               vb2_dma_contig_plane_paddr(&buf->vb_buf, 0));
+                               vb2_dma_contig_plane_dma_addr(&buf->vb_buf, 0));
                set_bit(CF_SINGLE_BUFFER, &cam->flags);
                singles++;
                return;
@@ -461,7 +461,7 @@ static void mcam_set_contig_buffer(struct mcam_camera *cam, int frame)
        buf = list_first_entry(&cam->buffers, struct mcam_vb_buffer, queue);
        list_del_init(&buf->queue);
        mcam_reg_write(cam, frame == 0 ? REG_Y0BAR : REG_Y1BAR,
-                       vb2_dma_contig_plane_paddr(&buf->vb_buf, 0));
+                       vb2_dma_contig_plane_dma_addr(&buf->vb_buf, 0));
        cam->vb_bufs[frame] = buf;
        clear_bit(CF_SINGLE_BUFFER, &cam->flags);
 }
@@ -884,7 +884,7 @@ static int mcam_read_setup(struct mcam_camera *cam)
  */
 
 static int mcam_vb_queue_setup(struct vb2_queue *vq, unsigned int *nbufs,
-               unsigned int *num_planes, unsigned long sizes[],
+               unsigned int *num_planes, unsigned int sizes[],
                void *alloc_ctxs[])
 {
        struct mcam_camera *cam = vb2_get_drv_priv(vq);
@@ -940,12 +940,14 @@ static void mcam_vb_wait_finish(struct vb2_queue *vq)
 /*
  * These need to be called with the mutex held from vb2
  */
-static int mcam_vb_start_streaming(struct vb2_queue *vq)
+static int mcam_vb_start_streaming(struct vb2_queue *vq, unsigned int count)
 {
        struct mcam_camera *cam = vb2_get_drv_priv(vq);
 
-       if (cam->state != S_IDLE)
+       if (cam->state != S_IDLE) {
+               INIT_LIST_HEAD(&cam->buffers);
                return -EINVAL;
+       }
        cam->sequence = 0;
        /*
         * Videobuf2 sneakily hoards all the buffers and won't
index d6b764541375ef0f0076988e6809375af2f2686f..fb0b124b35f302529eadcc9f3eef85db3820a10a 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "mcam-core.h"
 
+MODULE_ALIAS("platform:mmp-camera");
 MODULE_AUTHOR("Jonathan Corbet <corbet@lwn.net>");
 MODULE_LICENSE("GPL");
 
index 166bf9349c10c03dacce418f452e7bdc64df168a..9594b52f86059d533f179d350c55d322294c4a68 100644 (file)
@@ -739,7 +739,7 @@ static const struct v4l2_ioctl_ops m2mtest_ioctl_ops = {
  */
 
 static int m2mtest_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
-                               unsigned int *nplanes, unsigned long sizes[],
+                               unsigned int *nplanes, unsigned int sizes[],
                                void *alloc_ctxs[])
 {
        struct m2mtest_ctx *ctx = vb2_get_drv_priv(vq);
@@ -793,10 +793,24 @@ static void m2mtest_buf_queue(struct vb2_buffer *vb)
        v4l2_m2m_buf_queue(ctx->m2m_ctx, vb);
 }
 
+static void m2mtest_wait_prepare(struct vb2_queue *q)
+{
+       struct m2mtest_ctx *ctx = vb2_get_drv_priv(q);
+       m2mtest_unlock(ctx);
+}
+
+static void m2mtest_wait_finish(struct vb2_queue *q)
+{
+       struct m2mtest_ctx *ctx = vb2_get_drv_priv(q);
+       m2mtest_lock(ctx);
+}
+
 static struct vb2_ops m2mtest_qops = {
        .queue_setup     = m2mtest_queue_setup,
        .buf_prepare     = m2mtest_buf_prepare,
        .buf_queue       = m2mtest_buf_queue,
+       .wait_prepare    = m2mtest_wait_prepare,
+       .wait_finish     = m2mtest_wait_finish,
 };
 
 static int queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq)
index c43c81f5f9784ea6b9ac0691753aa7b05fdd39a7..d0f5388572855d8fed885a1ed54d1a37db3d7ec1 100644 (file)
@@ -426,6 +426,20 @@ static int msp_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *freq)
        return 0;
 }
 
+static int msp_querystd(struct v4l2_subdev *sd, v4l2_std_id *id)
+{
+       struct msp_state *state = to_state(sd);
+       struct i2c_client *client = v4l2_get_subdevdata(sd);
+
+       *id &= state->detected_std;
+
+       v4l_dbg(2, msp_debug, client,
+               "detected standard: %s(0x%08Lx)\n",
+               msp_standard_std_name(state->std), state->detected_std);
+
+       return 0;
+}
+
 static int msp_s_std(struct v4l2_subdev *sd, v4l2_std_id id)
 {
        struct msp_state *state = to_state(sd);
@@ -616,6 +630,10 @@ static const struct v4l2_subdev_core_ops msp_core_ops = {
        .s_std = msp_s_std,
 };
 
+static const struct v4l2_subdev_video_ops msp_video_ops = {
+       .querystd = msp_querystd,
+};
+
 static const struct v4l2_subdev_tuner_ops msp_tuner_ops = {
        .s_frequency = msp_s_frequency,
        .g_tuner = msp_g_tuner,
@@ -630,6 +648,7 @@ static const struct v4l2_subdev_audio_ops msp_audio_ops = {
 
 static const struct v4l2_subdev_ops msp_ops = {
        .core = &msp_core_ops,
+       .video = &msp_video_ops,
        .tuner = &msp_tuner_ops,
        .audio = &msp_audio_ops,
 };
@@ -664,6 +683,7 @@ static int msp_probe(struct i2c_client *client, const struct i2c_device_id *id)
        v4l2_i2c_subdev_init(sd, client, &msp_ops);
 
        state->v4l2_std = V4L2_STD_NTSC;
+       state->detected_std = V4L2_STD_ALL;
        state->audmode = V4L2_TUNER_MODE_STEREO;
        state->input = -1;
        state->i2s_mode = 0;
index 32a478e532f352ef6d74bc3725a3608e054a1357..831e8db4368c06e23915518b82abb56dde84fcd1 100644 (file)
@@ -75,7 +75,7 @@ struct msp_state {
        int opmode;
        int std;
        int mode;
-       v4l2_std_id v4l2_std;
+       v4l2_std_id v4l2_std, detected_std;
        int nicam_on;
        int acb;
        int in_scart;
index 80387e2c3eca1e5f43945f0d472bdbb524cf79d0..f8b51714f2f9ba7838a8cba3d039bf26a77b037e 100644 (file)
@@ -37,29 +37,49 @@ static struct {
        int retval;
        int main, second;
        char *name;
+       v4l2_std_id std;
 } msp_stdlist[] = {
-       { 0x0000, 0, 0, "could not detect sound standard" },
-       { 0x0001, 0, 0, "autodetect start" },
-       { 0x0002, MSP_CARRIER(4.5), MSP_CARRIER(4.72), "4.5/4.72  M Dual FM-Stereo" },
-       { 0x0003, MSP_CARRIER(5.5), MSP_CARRIER(5.7421875), "5.5/5.74  B/G Dual FM-Stereo" },
-       { 0x0004, MSP_CARRIER(6.5), MSP_CARRIER(6.2578125), "6.5/6.25  D/K1 Dual FM-Stereo" },
-       { 0x0005, MSP_CARRIER(6.5), MSP_CARRIER(6.7421875), "6.5/6.74  D/K2 Dual FM-Stereo" },
-       { 0x0006, MSP_CARRIER(6.5), MSP_CARRIER(6.5), "6.5  D/K FM-Mono (HDEV3)" },
-       { 0x0007, MSP_CARRIER(6.5), MSP_CARRIER(5.7421875), "6.5/5.74  D/K3 Dual FM-Stereo" },
-       { 0x0008, MSP_CARRIER(5.5), MSP_CARRIER(5.85), "5.5/5.85  B/G NICAM FM" },
-       { 0x0009, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85  L NICAM AM" },
-       { 0x000a, MSP_CARRIER(6.0), MSP_CARRIER(6.55), "6.0/6.55  I NICAM FM" },
-       { 0x000b, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85  D/K NICAM FM" },
-       { 0x000c, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85  D/K NICAM FM (HDEV2)" },
-       { 0x000d, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85  D/K NICAM FM (HDEV3)" },
-       { 0x0020, MSP_CARRIER(4.5), MSP_CARRIER(4.5), "4.5  M BTSC-Stereo" },
-       { 0x0021, MSP_CARRIER(4.5), MSP_CARRIER(4.5), "4.5  M BTSC-Mono + SAP" },
-       { 0x0030, MSP_CARRIER(4.5), MSP_CARRIER(4.5), "4.5  M EIA-J Japan Stereo" },
-       { 0x0040, MSP_CARRIER(10.7), MSP_CARRIER(10.7), "10.7  FM-Stereo Radio" },
-       { 0x0050, MSP_CARRIER(6.5), MSP_CARRIER(6.5), "6.5  SAT-Mono" },
-       { 0x0051, MSP_CARRIER(7.02), MSP_CARRIER(7.20), "7.02/7.20  SAT-Stereo" },
-       { 0x0060, MSP_CARRIER(7.2), MSP_CARRIER(7.2), "7.2  SAT ADR" },
-       {     -1, 0, 0, NULL }, /* EOF */
+       { 0x0000, 0, 0, "could not detect sound standard", V4L2_STD_ALL },
+       { 0x0001, 0, 0, "autodetect start", V4L2_STD_ALL },
+       { 0x0002, MSP_CARRIER(4.5), MSP_CARRIER(4.72),
+         "4.5/4.72  M Dual FM-Stereo", V4L2_STD_MN },
+       { 0x0003, MSP_CARRIER(5.5), MSP_CARRIER(5.7421875),
+         "5.5/5.74  B/G Dual FM-Stereo", V4L2_STD_BG },
+       { 0x0004, MSP_CARRIER(6.5), MSP_CARRIER(6.2578125),
+         "6.5/6.25  D/K1 Dual FM-Stereo", V4L2_STD_DK },
+       { 0x0005, MSP_CARRIER(6.5), MSP_CARRIER(6.7421875),
+         "6.5/6.74  D/K2 Dual FM-Stereo", V4L2_STD_DK },
+       { 0x0006, MSP_CARRIER(6.5), MSP_CARRIER(6.5),
+         "6.5  D/K FM-Mono (HDEV3)", V4L2_STD_DK },
+       { 0x0007, MSP_CARRIER(6.5), MSP_CARRIER(5.7421875),
+         "6.5/5.74  D/K3 Dual FM-Stereo", V4L2_STD_DK },
+       { 0x0008, MSP_CARRIER(5.5), MSP_CARRIER(5.85),
+         "5.5/5.85  B/G NICAM FM", V4L2_STD_BG },
+       { 0x0009, MSP_CARRIER(6.5), MSP_CARRIER(5.85),
+         "6.5/5.85  L NICAM AM", V4L2_STD_L },
+       { 0x000a, MSP_CARRIER(6.0), MSP_CARRIER(6.55),
+         "6.0/6.55  I NICAM FM", V4L2_STD_PAL_I },
+       { 0x000b, MSP_CARRIER(6.5), MSP_CARRIER(5.85),
+         "6.5/5.85  D/K NICAM FM", V4L2_STD_DK },
+       { 0x000c, MSP_CARRIER(6.5), MSP_CARRIER(5.85),
+         "6.5/5.85  D/K NICAM FM (HDEV2)", V4L2_STD_DK },
+       { 0x000d, MSP_CARRIER(6.5), MSP_CARRIER(5.85),
+         "6.5/5.85  D/K NICAM FM (HDEV3)", V4L2_STD_DK },
+       { 0x0020, MSP_CARRIER(4.5), MSP_CARRIER(4.5),
+         "4.5  M BTSC-Stereo", V4L2_STD_MTS },
+       { 0x0021, MSP_CARRIER(4.5), MSP_CARRIER(4.5),
+         "4.5  M BTSC-Mono + SAP", V4L2_STD_MTS },
+       { 0x0030, MSP_CARRIER(4.5), MSP_CARRIER(4.5),
+         "4.5  M EIA-J Japan Stereo", V4L2_STD_NTSC_M_JP },
+       { 0x0040, MSP_CARRIER(10.7), MSP_CARRIER(10.7),
+         "10.7  FM-Stereo Radio", V4L2_STD_ALL },
+       { 0x0050, MSP_CARRIER(6.5), MSP_CARRIER(6.5),
+         "6.5  SAT-Mono", V4L2_STD_ALL },
+       { 0x0051, MSP_CARRIER(7.02), MSP_CARRIER(7.20),
+         "7.02/7.20  SAT-Stereo", V4L2_STD_ALL },
+       { 0x0060, MSP_CARRIER(7.2), MSP_CARRIER(7.2),
+         "7.2  SAT ADR", V4L2_STD_ALL },
+       {     -1, 0, 0, NULL, 0 }, /* EOF */
 };
 
 static struct msp3400c_init_data_dem {
@@ -156,6 +176,16 @@ const char *msp_standard_std_name(int std)
        return "unknown";
 }
 
+static v4l2_std_id msp_standard_std(int std)
+{
+       int i;
+
+       for (i = 0; msp_stdlist[i].name != NULL; i++)
+               if (msp_stdlist[i].retval == std)
+                       return msp_stdlist[i].std;
+       return V4L2_STD_ALL;
+}
+
 static void msp_set_source(struct i2c_client *client, u16 src)
 {
        struct msp_state *state = to_state(i2c_get_clientdata(client));
@@ -479,6 +509,7 @@ int msp3400c_thread(void *data)
        int count, max1, max2, val1, val2, val, i;
 
        v4l_dbg(1, msp_debug, client, "msp3400 daemon started\n");
+       state->detected_std = V4L2_STD_ALL;
        set_freezable();
        for (;;) {
                v4l_dbg(2, msp_debug, client, "msp3400 thread: sleep\n");
@@ -579,6 +610,7 @@ restart:
                state->main = msp3400c_carrier_detect_main[max1].cdo;
                switch (max1) {
                case 1: /* 5.5 */
+                       state->detected_std = V4L2_STD_BG | V4L2_STD_PAL_H;
                        if (max2 == 0) {
                                /* B/G FM-stereo */
                                state->second = msp3400c_carrier_detect_55[max2].cdo;
@@ -596,6 +628,7 @@ restart:
                        break;
                case 2: /* 6.0 */
                        /* PAL I NICAM */
+                       state->detected_std = V4L2_STD_PAL_I;
                        state->second = MSP_CARRIER(6.552);
                        msp3400c_set_mode(client, MSP_MODE_FM_NICAM2);
                        state->nicam_on = 1;
@@ -607,22 +640,26 @@ restart:
                                state->second = msp3400c_carrier_detect_65[max2].cdo;
                                msp3400c_set_mode(client, MSP_MODE_FM_TERRA);
                                state->watch_stereo = 1;
+                               state->detected_std = V4L2_STD_DK;
                        } else if (max2 == 0 && (state->v4l2_std & V4L2_STD_SECAM)) {
                                /* L NICAM or AM-mono */
                                state->second = msp3400c_carrier_detect_65[max2].cdo;
                                msp3400c_set_mode(client, MSP_MODE_AM_NICAM);
                                state->watch_stereo = 1;
+                               state->detected_std = V4L2_STD_L;
                        } else if (max2 == 0 && state->has_nicam) {
                                /* D/K NICAM */
                                state->second = msp3400c_carrier_detect_65[max2].cdo;
                                msp3400c_set_mode(client, MSP_MODE_FM_NICAM1);
                                state->nicam_on = 1;
                                state->watch_stereo = 1;
+                               state->detected_std = V4L2_STD_DK;
                        } else {
                                goto no_second;
                        }
                        break;
                case 0: /* 4.5 */
+                       state->detected_std = V4L2_STD_MN;
                default:
 no_second:
                        state->second = msp3400c_carrier_detect_main[max1].cdo;
@@ -662,6 +699,7 @@ int msp3410d_thread(void *data)
        int val, i, std, count;
 
        v4l_dbg(1, msp_debug, client, "msp3410 daemon started\n");
+       state->detected_std = V4L2_STD_ALL;
        set_freezable();
        for (;;) {
                v4l_dbg(2, msp_debug, client, "msp3410 thread: sleep\n");
@@ -743,6 +781,8 @@ restart:
                                        msp_stdlist[8].name : "unknown", val);
                        state->std = val = 0x0009;
                        msp_write_dem(client, 0x20, val);
+               } else {
+                       state->detected_std = msp_standard_std(state->std);
                }
 
                /* set stereo */
@@ -957,6 +997,7 @@ int msp34xxg_thread(void *data)
        int val, i;
 
        v4l_dbg(1, msp_debug, client, "msp34xxg daemon started\n");
+       state->detected_std = V4L2_STD_ALL;
        set_freezable();
        for (;;) {
                v4l_dbg(2, msp_debug, client, "msp34xxg thread: sleep\n");
@@ -1013,6 +1054,7 @@ unmute:
                v4l_dbg(1, msp_debug, client,
                        "detected standard: %s (0x%04x)\n",
                        msp_standard_std_name(state->std), state->std);
+               state->detected_std = msp_standard_std(state->std);
 
                if (state->std == 9) {
                        /* AM NICAM mode */
index a357aa889fc6c07357b91c86877f8094db7d8539..07af26e6bebdacf9a2ea8ce70debfddaabb0c12a 100644 (file)
@@ -184,6 +184,7 @@ struct mt9m111 {
        struct mutex power_lock; /* lock to protect power_count */
        int power_count;
        const struct mt9m111_datafmt *fmt;
+       int lastpage;   /* PageMap cache value */
        unsigned int gain;
        unsigned char autoexposure;
        unsigned char datawidth;
@@ -202,17 +203,17 @@ static int reg_page_map_set(struct i2c_client *client, const u16 reg)
 {
        int ret;
        u16 page;
-       static int lastpage = -1;       /* PageMap cache value */
+       struct mt9m111 *mt9m111 = to_mt9m111(client);
 
        page = (reg >> 8);
-       if (page == lastpage)
+       if (page == mt9m111->lastpage)
                return 0;
        if (page > 2)
                return -EINVAL;
 
        ret = i2c_smbus_write_word_data(client, MT9M111_PAGE_MAP, swab16(page));
        if (!ret)
-               lastpage = page;
+               mt9m111->lastpage = page;
        return ret;
 }
 
@@ -932,6 +933,8 @@ static int mt9m111_video_probe(struct soc_camera_device *icd,
        BUG_ON(!icd->parent ||
               to_soc_camera_host(icd->parent)->nr != icd->iface);
 
+       mt9m111->lastpage = -1;
+
        mt9m111->autoexposure = 1;
        mt9m111->autowhitebalance = 1;
 
diff --git a/drivers/media/video/mt9p031.c b/drivers/media/video/mt9p031.c
new file mode 100644 (file)
index 0000000..73c0689
--- /dev/null
@@ -0,0 +1,964 @@
+/*
+ * Driver for MT9P031 CMOS Image Sensor from Aptina
+ *
+ * Copyright (C) 2011, Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ * Copyright (C) 2011, Javier Martin <javier.martin@vista-silicon.com>
+ * Copyright (C) 2011, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
+ *
+ * Based on the MT9V032 driver and Bastian Hecht's code.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/i2c.h>
+#include <linux/log2.h>
+#include <linux/pm.h>
+#include <linux/slab.h>
+#include <media/v4l2-subdev.h>
+#include <linux/videodev2.h>
+
+#include <media/mt9p031.h>
+#include <media/v4l2-chip-ident.h>
+#include <media/v4l2-ctrls.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-subdev.h>
+
+#define MT9P031_PIXEL_ARRAY_WIDTH                      2752
+#define MT9P031_PIXEL_ARRAY_HEIGHT                     2004
+
+#define MT9P031_CHIP_VERSION                           0x00
+#define                MT9P031_CHIP_VERSION_VALUE              0x1801
+#define MT9P031_ROW_START                              0x01
+#define                MT9P031_ROW_START_MIN                   0
+#define                MT9P031_ROW_START_MAX                   2004
+#define                MT9P031_ROW_START_DEF                   54
+#define MT9P031_COLUMN_START                           0x02
+#define                MT9P031_COLUMN_START_MIN                0
+#define                MT9P031_COLUMN_START_MAX                2750
+#define                MT9P031_COLUMN_START_DEF                16
+#define MT9P031_WINDOW_HEIGHT                          0x03
+#define                MT9P031_WINDOW_HEIGHT_MIN               2
+#define                MT9P031_WINDOW_HEIGHT_MAX               2006
+#define                MT9P031_WINDOW_HEIGHT_DEF               1944
+#define MT9P031_WINDOW_WIDTH                           0x04
+#define                MT9P031_WINDOW_WIDTH_MIN                2
+#define                MT9P031_WINDOW_WIDTH_MAX                2752
+#define                MT9P031_WINDOW_WIDTH_DEF                2592
+#define MT9P031_HORIZONTAL_BLANK                       0x05
+#define                MT9P031_HORIZONTAL_BLANK_MIN            0
+#define                MT9P031_HORIZONTAL_BLANK_MAX            4095
+#define MT9P031_VERTICAL_BLANK                         0x06
+#define                MT9P031_VERTICAL_BLANK_MIN              0
+#define                MT9P031_VERTICAL_BLANK_MAX              4095
+#define                MT9P031_VERTICAL_BLANK_DEF              25
+#define MT9P031_OUTPUT_CONTROL                         0x07
+#define                MT9P031_OUTPUT_CONTROL_CEN              2
+#define                MT9P031_OUTPUT_CONTROL_SYN              1
+#define                MT9P031_OUTPUT_CONTROL_DEF              0x1f82
+#define MT9P031_SHUTTER_WIDTH_UPPER                    0x08
+#define MT9P031_SHUTTER_WIDTH_LOWER                    0x09
+#define                MT9P031_SHUTTER_WIDTH_MIN               1
+#define                MT9P031_SHUTTER_WIDTH_MAX               1048575
+#define                MT9P031_SHUTTER_WIDTH_DEF               1943
+#define        MT9P031_PLL_CONTROL                             0x10
+#define                MT9P031_PLL_CONTROL_PWROFF              0x0050
+#define                MT9P031_PLL_CONTROL_PWRON               0x0051
+#define                MT9P031_PLL_CONTROL_USEPLL              0x0052
+#define        MT9P031_PLL_CONFIG_1                            0x11
+#define        MT9P031_PLL_CONFIG_2                            0x12
+#define MT9P031_PIXEL_CLOCK_CONTROL                    0x0a
+#define MT9P031_FRAME_RESTART                          0x0b
+#define MT9P031_SHUTTER_DELAY                          0x0c
+#define MT9P031_RST                                    0x0d
+#define                MT9P031_RST_ENABLE                      1
+#define                MT9P031_RST_DISABLE                     0
+#define MT9P031_READ_MODE_1                            0x1e
+#define MT9P031_READ_MODE_2                            0x20
+#define                MT9P031_READ_MODE_2_ROW_MIR             (1 << 15)
+#define                MT9P031_READ_MODE_2_COL_MIR             (1 << 14)
+#define                MT9P031_READ_MODE_2_ROW_BLC             (1 << 6)
+#define MT9P031_ROW_ADDRESS_MODE                       0x22
+#define MT9P031_COLUMN_ADDRESS_MODE                    0x23
+#define MT9P031_GLOBAL_GAIN                            0x35
+#define                MT9P031_GLOBAL_GAIN_MIN                 8
+#define                MT9P031_GLOBAL_GAIN_MAX                 1024
+#define                MT9P031_GLOBAL_GAIN_DEF                 8
+#define                MT9P031_GLOBAL_GAIN_MULT                (1 << 6)
+#define MT9P031_ROW_BLACK_DEF_OFFSET                   0x4b
+#define MT9P031_TEST_PATTERN                           0xa0
+#define                MT9P031_TEST_PATTERN_SHIFT              3
+#define                MT9P031_TEST_PATTERN_ENABLE             (1 << 0)
+#define                MT9P031_TEST_PATTERN_DISABLE            (0 << 0)
+#define MT9P031_TEST_PATTERN_GREEN                     0xa1
+#define MT9P031_TEST_PATTERN_RED                       0xa2
+#define MT9P031_TEST_PATTERN_BLUE                      0xa3
+
+struct mt9p031_pll_divs {
+       u32 ext_freq;
+       u32 target_freq;
+       u8 m;
+       u8 n;
+       u8 p1;
+};
+
+struct mt9p031 {
+       struct v4l2_subdev subdev;
+       struct media_pad pad;
+       struct v4l2_rect crop;  /* Sensor window */
+       struct v4l2_mbus_framefmt format;
+       struct v4l2_ctrl_handler ctrls;
+       struct mt9p031_platform_data *pdata;
+       struct mutex power_lock; /* lock to protect power_count */
+       int power_count;
+       u16 xskip;
+       u16 yskip;
+
+       const struct mt9p031_pll_divs *pll;
+
+       /* Registers cache */
+       u16 output_control;
+       u16 mode2;
+};
+
+static struct mt9p031 *to_mt9p031(struct v4l2_subdev *sd)
+{
+       return container_of(sd, struct mt9p031, subdev);
+}
+
+static int mt9p031_read(struct i2c_client *client, u8 reg)
+{
+       s32 data = i2c_smbus_read_word_data(client, reg);
+       return data < 0 ? data : be16_to_cpu(data);
+}
+
+static int mt9p031_write(struct i2c_client *client, u8 reg, u16 data)
+{
+       return i2c_smbus_write_word_data(client, reg, cpu_to_be16(data));
+}
+
+static int mt9p031_set_output_control(struct mt9p031 *mt9p031, u16 clear,
+                                     u16 set)
+{
+       struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev);
+       u16 value = (mt9p031->output_control & ~clear) | set;
+       int ret;
+
+       ret = mt9p031_write(client, MT9P031_OUTPUT_CONTROL, value);
+       if (ret < 0)
+               return ret;
+
+       mt9p031->output_control = value;
+       return 0;
+}
+
+static int mt9p031_set_mode2(struct mt9p031 *mt9p031, u16 clear, u16 set)
+{
+       struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev);
+       u16 value = (mt9p031->mode2 & ~clear) | set;
+       int ret;
+
+       ret = mt9p031_write(client, MT9P031_READ_MODE_2, value);
+       if (ret < 0)
+               return ret;
+
+       mt9p031->mode2 = value;
+       return 0;
+}
+
+static int mt9p031_reset(struct mt9p031 *mt9p031)
+{
+       struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev);
+       int ret;
+
+       /* Disable chip output, synchronous option update */
+       ret = mt9p031_write(client, MT9P031_RST, MT9P031_RST_ENABLE);
+       if (ret < 0)
+               return ret;
+       ret = mt9p031_write(client, MT9P031_RST, MT9P031_RST_DISABLE);
+       if (ret < 0)
+               return ret;
+
+       return mt9p031_set_output_control(mt9p031, MT9P031_OUTPUT_CONTROL_CEN,
+                                         0);
+}
+
+/*
+ * This static table uses ext_freq and vdd_io values to select suitable
+ * PLL dividers m, n and p1 which have been calculated as specifiec in p36
+ * of Aptina's mt9p031 datasheet. New values should be added here.
+ */
+static const struct mt9p031_pll_divs mt9p031_divs[] = {
+       /* ext_freq     target_freq     m       n       p1 */
+       {21000000,      48000000,       26,     2,      6}
+};
+
+static int mt9p031_pll_get_divs(struct mt9p031 *mt9p031)
+{
+       struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev);
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(mt9p031_divs); i++) {
+               if (mt9p031_divs[i].ext_freq == mt9p031->pdata->ext_freq &&
+                 mt9p031_divs[i].target_freq == mt9p031->pdata->target_freq) {
+                       mt9p031->pll = &mt9p031_divs[i];
+                       return 0;
+               }
+       }
+
+       dev_err(&client->dev, "Couldn't find PLL dividers for ext_freq = %d, "
+               "target_freq = %d\n", mt9p031->pdata->ext_freq,
+               mt9p031->pdata->target_freq);
+       return -EINVAL;
+}
+
+static int mt9p031_pll_enable(struct mt9p031 *mt9p031)
+{
+       struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev);
+       int ret;
+
+       ret = mt9p031_write(client, MT9P031_PLL_CONTROL,
+                           MT9P031_PLL_CONTROL_PWRON);
+       if (ret < 0)
+               return ret;
+
+       ret = mt9p031_write(client, MT9P031_PLL_CONFIG_1,
+                           (mt9p031->pll->m << 8) | (mt9p031->pll->n - 1));
+       if (ret < 0)
+               return ret;
+
+       ret = mt9p031_write(client, MT9P031_PLL_CONFIG_2, mt9p031->pll->p1 - 1);
+       if (ret < 0)
+               return ret;
+
+       usleep_range(1000, 2000);
+       ret = mt9p031_write(client, MT9P031_PLL_CONTROL,
+                           MT9P031_PLL_CONTROL_PWRON |
+                           MT9P031_PLL_CONTROL_USEPLL);
+       return ret;
+}
+
+static inline int mt9p031_pll_disable(struct mt9p031 *mt9p031)
+{
+       struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev);
+
+       return mt9p031_write(client, MT9P031_PLL_CONTROL,
+                            MT9P031_PLL_CONTROL_PWROFF);
+}
+
+static int mt9p031_power_on(struct mt9p031 *mt9p031)
+{
+       /* Ensure RESET_BAR is low */
+       if (mt9p031->pdata->reset) {
+               mt9p031->pdata->reset(&mt9p031->subdev, 1);
+               usleep_range(1000, 2000);
+       }
+
+       /* Emable clock */
+       if (mt9p031->pdata->set_xclk)
+               mt9p031->pdata->set_xclk(&mt9p031->subdev,
+                                        mt9p031->pdata->ext_freq);
+
+       /* Now RESET_BAR must be high */
+       if (mt9p031->pdata->reset) {
+               mt9p031->pdata->reset(&mt9p031->subdev, 0);
+               usleep_range(1000, 2000);
+       }
+
+       return 0;
+}
+
+static void mt9p031_power_off(struct mt9p031 *mt9p031)
+{
+       if (mt9p031->pdata->reset) {
+               mt9p031->pdata->reset(&mt9p031->subdev, 1);
+               usleep_range(1000, 2000);
+       }
+
+       if (mt9p031->pdata->set_xclk)
+               mt9p031->pdata->set_xclk(&mt9p031->subdev, 0);
+}
+
+static int __mt9p031_set_power(struct mt9p031 *mt9p031, bool on)
+{
+       struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev);
+       int ret;
+
+       if (!on) {
+               mt9p031_power_off(mt9p031);
+               return 0;
+       }
+
+       ret = mt9p031_power_on(mt9p031);
+       if (ret < 0)
+               return ret;
+
+       ret = mt9p031_reset(mt9p031);
+       if (ret < 0) {
+               dev_err(&client->dev, "Failed to reset the camera\n");
+               return ret;
+       }
+
+       return v4l2_ctrl_handler_setup(&mt9p031->ctrls);
+}
+
+/* -----------------------------------------------------------------------------
+ * V4L2 subdev video operations
+ */
+
+static int mt9p031_set_params(struct mt9p031 *mt9p031)
+{
+       struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev);
+       struct v4l2_mbus_framefmt *format = &mt9p031->format;
+       const struct v4l2_rect *crop = &mt9p031->crop;
+       unsigned int hblank;
+       unsigned int vblank;
+       unsigned int xskip;
+       unsigned int yskip;
+       unsigned int xbin;
+       unsigned int ybin;
+       int ret;
+
+       /* Windows position and size.
+        *
+        * TODO: Make sure the start coordinates and window size match the
+        * skipping, binning and mirroring (see description of registers 2 and 4
+        * in table 13, and Binning section on page 41).
+        */
+       ret = mt9p031_write(client, MT9P031_COLUMN_START, crop->left);
+       if (ret < 0)
+               return ret;
+       ret = mt9p031_write(client, MT9P031_ROW_START, crop->top);
+       if (ret < 0)
+               return ret;
+       ret = mt9p031_write(client, MT9P031_WINDOW_WIDTH, crop->width - 1);
+       if (ret < 0)
+               return ret;
+       ret = mt9p031_write(client, MT9P031_WINDOW_HEIGHT, crop->height - 1);
+       if (ret < 0)
+               return ret;
+
+       /* Row and column binning and skipping. Use the maximum binning value
+        * compatible with the skipping settings.
+        */
+       xskip = DIV_ROUND_CLOSEST(crop->width, format->width);
+       yskip = DIV_ROUND_CLOSEST(crop->height, format->height);
+       xbin = 1 << (ffs(xskip) - 1);
+       ybin = 1 << (ffs(yskip) - 1);
+
+       ret = mt9p031_write(client, MT9P031_COLUMN_ADDRESS_MODE,
+                           ((xbin - 1) << 4) | (xskip - 1));
+       if (ret < 0)
+               return ret;
+       ret = mt9p031_write(client, MT9P031_ROW_ADDRESS_MODE,
+                           ((ybin - 1) << 4) | (yskip - 1));
+       if (ret < 0)
+               return ret;
+
+       /* Blanking - use minimum value for horizontal blanking and default
+        * value for vertical blanking.
+        */
+       hblank = 346 * ybin + 64 + (80 >> max_t(unsigned int, xbin, 3));
+       vblank = MT9P031_VERTICAL_BLANK_DEF;
+
+       ret = mt9p031_write(client, MT9P031_HORIZONTAL_BLANK, hblank);
+       if (ret < 0)
+               return ret;
+       ret = mt9p031_write(client, MT9P031_VERTICAL_BLANK, vblank);
+       if (ret < 0)
+               return ret;
+
+       return ret;
+}
+
+static int mt9p031_s_stream(struct v4l2_subdev *subdev, int enable)
+{
+       struct mt9p031 *mt9p031 = to_mt9p031(subdev);
+       int ret;
+
+       if (!enable) {
+               /* Stop sensor readout */
+               ret = mt9p031_set_output_control(mt9p031,
+                                                MT9P031_OUTPUT_CONTROL_CEN, 0);
+               if (ret < 0)
+                       return ret;
+
+               return mt9p031_pll_disable(mt9p031);
+       }
+
+       ret = mt9p031_set_params(mt9p031);
+       if (ret < 0)
+               return ret;
+
+       /* Switch to master "normal" mode */
+       ret = mt9p031_set_output_control(mt9p031, 0,
+                                        MT9P031_OUTPUT_CONTROL_CEN);
+       if (ret < 0)
+               return ret;
+
+       return mt9p031_pll_enable(mt9p031);
+}
+
+static int mt9p031_enum_mbus_code(struct v4l2_subdev *subdev,
+                                 struct v4l2_subdev_fh *fh,
+                                 struct v4l2_subdev_mbus_code_enum *code)
+{
+       struct mt9p031 *mt9p031 = to_mt9p031(subdev);
+
+       if (code->pad || code->index)
+               return -EINVAL;
+
+       code->code = mt9p031->format.code;
+       return 0;
+}
+
+static int mt9p031_enum_frame_size(struct v4l2_subdev *subdev,
+                                  struct v4l2_subdev_fh *fh,
+                                  struct v4l2_subdev_frame_size_enum *fse)
+{
+       struct mt9p031 *mt9p031 = to_mt9p031(subdev);
+
+       if (fse->index >= 8 || fse->code != mt9p031->format.code)
+               return -EINVAL;
+
+       fse->min_width = MT9P031_WINDOW_WIDTH_DEF
+                      / min_t(unsigned int, 7, fse->index + 1);
+       fse->max_width = fse->min_width;
+       fse->min_height = MT9P031_WINDOW_HEIGHT_DEF / (fse->index + 1);
+       fse->max_height = fse->min_height;
+
+       return 0;
+}
+
+static struct v4l2_mbus_framefmt *
+__mt9p031_get_pad_format(struct mt9p031 *mt9p031, struct v4l2_subdev_fh *fh,
+                        unsigned int pad, u32 which)
+{
+       switch (which) {
+       case V4L2_SUBDEV_FORMAT_TRY:
+               return v4l2_subdev_get_try_format(fh, pad);
+       case V4L2_SUBDEV_FORMAT_ACTIVE:
+               return &mt9p031->format;
+       default:
+               return NULL;
+       }
+}
+
+static struct v4l2_rect *
+__mt9p031_get_pad_crop(struct mt9p031 *mt9p031, struct v4l2_subdev_fh *fh,
+                    unsigned int pad, u32 which)
+{
+       switch (which) {
+       case V4L2_SUBDEV_FORMAT_TRY:
+               return v4l2_subdev_get_try_crop(fh, pad);
+       case V4L2_SUBDEV_FORMAT_ACTIVE:
+               return &mt9p031->crop;
+       default:
+               return NULL;
+       }
+}
+
+static int mt9p031_get_format(struct v4l2_subdev *subdev,
+                             struct v4l2_subdev_fh *fh,
+                             struct v4l2_subdev_format *fmt)
+{
+       struct mt9p031 *mt9p031 = to_mt9p031(subdev);
+
+       fmt->format = *__mt9p031_get_pad_format(mt9p031, fh, fmt->pad,
+                                               fmt->which);
+       return 0;
+}
+
+static int mt9p031_set_format(struct v4l2_subdev *subdev,
+                             struct v4l2_subdev_fh *fh,
+                             struct v4l2_subdev_format *format)
+{
+       struct mt9p031 *mt9p031 = to_mt9p031(subdev);
+       struct v4l2_mbus_framefmt *__format;
+       struct v4l2_rect *__crop;
+       unsigned int width;
+       unsigned int height;
+       unsigned int hratio;
+       unsigned int vratio;
+
+       __crop = __mt9p031_get_pad_crop(mt9p031, fh, format->pad,
+                                       format->which);
+
+       /* Clamp the width and height to avoid dividing by zero. */
+       width = clamp_t(unsigned int, ALIGN(format->format.width, 2),
+                       max(__crop->width / 7, MT9P031_WINDOW_WIDTH_MIN),
+                       __crop->width);
+       height = clamp_t(unsigned int, ALIGN(format->format.height, 2),
+                       max(__crop->height / 8, MT9P031_WINDOW_HEIGHT_MIN),
+                       __crop->height);
+
+       hratio = DIV_ROUND_CLOSEST(__crop->width, width);
+       vratio = DIV_ROUND_CLOSEST(__crop->height, height);
+
+       __format = __mt9p031_get_pad_format(mt9p031, fh, format->pad,
+                                           format->which);
+       __format->width = __crop->width / hratio;
+       __format->height = __crop->height / vratio;
+
+       format->format = *__format;
+
+       return 0;
+}
+
+static int mt9p031_get_crop(struct v4l2_subdev *subdev,
+                           struct v4l2_subdev_fh *fh,
+                           struct v4l2_subdev_crop *crop)
+{
+       struct mt9p031 *mt9p031 = to_mt9p031(subdev);
+
+       crop->rect = *__mt9p031_get_pad_crop(mt9p031, fh, crop->pad,
+                                            crop->which);
+       return 0;
+}
+
+static int mt9p031_set_crop(struct v4l2_subdev *subdev,
+                           struct v4l2_subdev_fh *fh,
+                           struct v4l2_subdev_crop *crop)
+{
+       struct mt9p031 *mt9p031 = to_mt9p031(subdev);
+       struct v4l2_mbus_framefmt *__format;
+       struct v4l2_rect *__crop;
+       struct v4l2_rect rect;
+
+       /* Clamp the crop rectangle boundaries and align them to a multiple of 2
+        * pixels to ensure a GRBG Bayer pattern.
+        */
+       rect.left = clamp(ALIGN(crop->rect.left, 2), MT9P031_COLUMN_START_MIN,
+                         MT9P031_COLUMN_START_MAX);
+       rect.top = clamp(ALIGN(crop->rect.top, 2), MT9P031_ROW_START_MIN,
+                        MT9P031_ROW_START_MAX);
+       rect.width = clamp(ALIGN(crop->rect.width, 2),
+                          MT9P031_WINDOW_WIDTH_MIN,
+                          MT9P031_WINDOW_WIDTH_MAX);
+       rect.height = clamp(ALIGN(crop->rect.height, 2),
+                           MT9P031_WINDOW_HEIGHT_MIN,
+                           MT9P031_WINDOW_HEIGHT_MAX);
+
+       rect.width = min(rect.width, MT9P031_PIXEL_ARRAY_WIDTH - rect.left);
+       rect.height = min(rect.height, MT9P031_PIXEL_ARRAY_HEIGHT - rect.top);
+
+       __crop = __mt9p031_get_pad_crop(mt9p031, fh, crop->pad, crop->which);
+
+       if (rect.width != __crop->width || rect.height != __crop->height) {
+               /* Reset the output image size if the crop rectangle size has
+                * been modified.
+                */
+               __format = __mt9p031_get_pad_format(mt9p031, fh, crop->pad,
+                                                   crop->which);
+               __format->width = rect.width;
+               __format->height = rect.height;
+       }
+
+       *__crop = rect;
+       crop->rect = rect;
+
+       return 0;
+}
+
+/* -----------------------------------------------------------------------------
+ * V4L2 subdev control operations
+ */
+
+#define V4L2_CID_TEST_PATTERN          (V4L2_CID_USER_BASE | 0x1001)
+
+static int mt9p031_s_ctrl(struct v4l2_ctrl *ctrl)
+{
+       struct mt9p031 *mt9p031 =
+                       container_of(ctrl->handler, struct mt9p031, ctrls);
+       struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev);
+       u16 data;
+       int ret;
+
+       switch (ctrl->id) {
+       case V4L2_CID_EXPOSURE:
+               ret = mt9p031_write(client, MT9P031_SHUTTER_WIDTH_UPPER,
+                                   (ctrl->val >> 16) & 0xffff);
+               if (ret < 0)
+                       return ret;
+
+               return mt9p031_write(client, MT9P031_SHUTTER_WIDTH_LOWER,
+                                    ctrl->val & 0xffff);
+
+       case V4L2_CID_GAIN:
+               /* Gain is controlled by 2 analog stages and a digital stage.
+                * Valid values for the 3 stages are
+                *
+                * Stage                Min     Max     Step
+                * ------------------------------------------
+                * First analog stage   x1      x2      1
+                * Second analog stage  x1      x4      0.125
+                * Digital stage        x1      x16     0.125
+                *
+                * To minimize noise, the gain stages should be used in the
+                * second analog stage, first analog stage, digital stage order.
+                * Gain from a previous stage should be pushed to its maximum
+                * value before the next stage is used.
+                */
+               if (ctrl->val <= 32) {
+                       data = ctrl->val;
+               } else if (ctrl->val <= 64) {
+                       ctrl->val &= ~1;
+                       data = (1 << 6) | (ctrl->val >> 1);
+               } else {
+                       ctrl->val &= ~7;
+                       data = ((ctrl->val - 64) << 5) | (1 << 6) | 32;
+               }
+
+               return mt9p031_write(client, MT9P031_GLOBAL_GAIN, data);
+
+       case V4L2_CID_HFLIP:
+               if (ctrl->val)
+                       return mt9p031_set_mode2(mt9p031,
+                                       0, MT9P031_READ_MODE_2_COL_MIR);
+               else
+                       return mt9p031_set_mode2(mt9p031,
+                                       MT9P031_READ_MODE_2_COL_MIR, 0);
+
+       case V4L2_CID_VFLIP:
+               if (ctrl->val)
+                       return mt9p031_set_mode2(mt9p031,
+                                       0, MT9P031_READ_MODE_2_ROW_MIR);
+               else
+                       return mt9p031_set_mode2(mt9p031,
+                                       MT9P031_READ_MODE_2_ROW_MIR, 0);
+
+       case V4L2_CID_TEST_PATTERN:
+               if (!ctrl->val) {
+                       ret = mt9p031_set_mode2(mt9p031,
+                                       0, MT9P031_READ_MODE_2_ROW_BLC);
+                       if (ret < 0)
+                               return ret;
+
+                       return mt9p031_write(client, MT9P031_TEST_PATTERN,
+                                            MT9P031_TEST_PATTERN_DISABLE);
+               }
+
+               ret = mt9p031_write(client, MT9P031_TEST_PATTERN_GREEN, 0x05a0);
+               if (ret < 0)
+                       return ret;
+               ret = mt9p031_write(client, MT9P031_TEST_PATTERN_RED, 0x0a50);
+               if (ret < 0)
+                       return ret;
+               ret = mt9p031_write(client, MT9P031_TEST_PATTERN_BLUE, 0x0aa0);
+               if (ret < 0)
+                       return ret;
+
+               ret = mt9p031_set_mode2(mt9p031, MT9P031_READ_MODE_2_ROW_BLC,
+                                       0);
+               if (ret < 0)
+                       return ret;
+               ret = mt9p031_write(client, MT9P031_ROW_BLACK_DEF_OFFSET, 0);
+               if (ret < 0)
+                       return ret;
+
+               return mt9p031_write(client, MT9P031_TEST_PATTERN,
+                               ((ctrl->val - 1) << MT9P031_TEST_PATTERN_SHIFT)
+                               | MT9P031_TEST_PATTERN_ENABLE);
+       }
+       return 0;
+}
+
+static struct v4l2_ctrl_ops mt9p031_ctrl_ops = {
+       .s_ctrl = mt9p031_s_ctrl,
+};
+
+static const char * const mt9p031_test_pattern_menu[] = {
+       "Disabled",
+       "Color Field",
+       "Horizontal Gradient",
+       "Vertical Gradient",
+       "Diagonal Gradient",
+       "Classic Test Pattern",
+       "Walking 1s",
+       "Monochrome Horizontal Bars",
+       "Monochrome Vertical Bars",
+       "Vertical Color Bars",
+};
+
+static const struct v4l2_ctrl_config mt9p031_ctrls[] = {
+       {
+               .ops            = &mt9p031_ctrl_ops,
+               .id             = V4L2_CID_TEST_PATTERN,
+               .type           = V4L2_CTRL_TYPE_MENU,
+               .name           = "Test Pattern",
+               .min            = 0,
+               .max            = ARRAY_SIZE(mt9p031_test_pattern_menu) - 1,
+               .step           = 0,
+               .def            = 0,
+               .flags          = 0,
+               .menu_skip_mask = 0,
+               .qmenu          = mt9p031_test_pattern_menu,
+       }
+};
+
+/* -----------------------------------------------------------------------------
+ * V4L2 subdev core operations
+ */
+
+static int mt9p031_set_power(struct v4l2_subdev *subdev, int on)
+{
+       struct mt9p031 *mt9p031 = to_mt9p031(subdev);
+       int ret = 0;
+
+       mutex_lock(&mt9p031->power_lock);
+
+       /* If the power count is modified from 0 to != 0 or from != 0 to 0,
+        * update the power state.
+        */
+       if (mt9p031->power_count == !on) {
+               ret = __mt9p031_set_power(mt9p031, !!on);
+               if (ret < 0)
+                       goto out;
+       }
+
+       /* Update the power count. */
+       mt9p031->power_count += on ? 1 : -1;
+       WARN_ON(mt9p031->power_count < 0);
+
+out:
+       mutex_unlock(&mt9p031->power_lock);
+       return ret;
+}
+
+/* -----------------------------------------------------------------------------
+ * V4L2 subdev internal operations
+ */
+
+static int mt9p031_registered(struct v4l2_subdev *subdev)
+{
+       struct i2c_client *client = v4l2_get_subdevdata(subdev);
+       struct mt9p031 *mt9p031 = to_mt9p031(subdev);
+       s32 data;
+       int ret;
+
+       ret = mt9p031_power_on(mt9p031);
+       if (ret < 0) {
+               dev_err(&client->dev, "MT9P031 power up failed\n");
+               return ret;
+       }
+
+       /* Read out the chip version register */
+       data = mt9p031_read(client, MT9P031_CHIP_VERSION);
+       if (data != MT9P031_CHIP_VERSION_VALUE) {
+               dev_err(&client->dev, "MT9P031 not detected, wrong version "
+                       "0x%04x\n", data);
+               return -ENODEV;
+       }
+
+       mt9p031_power_off(mt9p031);
+
+       dev_info(&client->dev, "MT9P031 detected at address 0x%02x\n",
+                client->addr);
+
+       return ret;
+}
+
+static int mt9p031_open(struct v4l2_subdev *subdev, struct v4l2_subdev_fh *fh)
+{
+       struct mt9p031 *mt9p031 = to_mt9p031(subdev);
+       struct v4l2_mbus_framefmt *format;
+       struct v4l2_rect *crop;
+
+       crop = v4l2_subdev_get_try_crop(fh, 0);
+       crop->left = MT9P031_COLUMN_START_DEF;
+       crop->top = MT9P031_ROW_START_DEF;
+       crop->width = MT9P031_WINDOW_WIDTH_DEF;
+       crop->height = MT9P031_WINDOW_HEIGHT_DEF;
+
+       format = v4l2_subdev_get_try_format(fh, 0);
+
+       if (mt9p031->pdata->version == MT9P031_MONOCHROME_VERSION)
+               format->code = V4L2_MBUS_FMT_Y12_1X12;
+       else
+               format->code = V4L2_MBUS_FMT_SGRBG12_1X12;
+
+       format->width = MT9P031_WINDOW_WIDTH_DEF;
+       format->height = MT9P031_WINDOW_HEIGHT_DEF;
+       format->field = V4L2_FIELD_NONE;
+       format->colorspace = V4L2_COLORSPACE_SRGB;
+
+       mt9p031->xskip = 1;
+       mt9p031->yskip = 1;
+       return mt9p031_set_power(subdev, 1);
+}
+
+static int mt9p031_close(struct v4l2_subdev *subdev, struct v4l2_subdev_fh *fh)
+{
+       return mt9p031_set_power(subdev, 0);
+}
+
+static struct v4l2_subdev_core_ops mt9p031_subdev_core_ops = {
+       .s_power        = mt9p031_set_power,
+};
+
+static struct v4l2_subdev_video_ops mt9p031_subdev_video_ops = {
+       .s_stream       = mt9p031_s_stream,
+};
+
+static struct v4l2_subdev_pad_ops mt9p031_subdev_pad_ops = {
+       .enum_mbus_code = mt9p031_enum_mbus_code,
+       .enum_frame_size = mt9p031_enum_frame_size,
+       .get_fmt = mt9p031_get_format,
+       .set_fmt = mt9p031_set_format,
+       .get_crop = mt9p031_get_crop,
+       .set_crop = mt9p031_set_crop,
+};
+
+static struct v4l2_subdev_ops mt9p031_subdev_ops = {
+       .core   = &mt9p031_subdev_core_ops,
+       .video  = &mt9p031_subdev_video_ops,
+       .pad    = &mt9p031_subdev_pad_ops,
+};
+
+static const struct v4l2_subdev_internal_ops mt9p031_subdev_internal_ops = {
+       .registered = mt9p031_registered,
+       .open = mt9p031_open,
+       .close = mt9p031_close,
+};
+
+/* -----------------------------------------------------------------------------
+ * Driver initialization and probing
+ */
+
+static int mt9p031_probe(struct i2c_client *client,
+                        const struct i2c_device_id *did)
+{
+       struct mt9p031_platform_data *pdata = client->dev.platform_data;
+       struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
+       struct mt9p031 *mt9p031;
+       unsigned int i;
+       int ret;
+
+       if (pdata == NULL) {
+               dev_err(&client->dev, "No platform data\n");
+               return -EINVAL;
+       }
+
+       if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) {
+               dev_warn(&client->dev,
+                       "I2C-Adapter doesn't support I2C_FUNC_SMBUS_WORD\n");
+               return -EIO;
+       }
+
+       mt9p031 = kzalloc(sizeof(*mt9p031), GFP_KERNEL);
+       if (mt9p031 == NULL)
+               return -ENOMEM;
+
+       mt9p031->pdata = pdata;
+       mt9p031->output_control = MT9P031_OUTPUT_CONTROL_DEF;
+       mt9p031->mode2 = MT9P031_READ_MODE_2_ROW_BLC;
+
+       v4l2_ctrl_handler_init(&mt9p031->ctrls, ARRAY_SIZE(mt9p031_ctrls) + 4);
+
+       v4l2_ctrl_new_std(&mt9p031->ctrls, &mt9p031_ctrl_ops,
+                         V4L2_CID_EXPOSURE, MT9P031_SHUTTER_WIDTH_MIN,
+                         MT9P031_SHUTTER_WIDTH_MAX, 1,
+                         MT9P031_SHUTTER_WIDTH_DEF);
+       v4l2_ctrl_new_std(&mt9p031->ctrls, &mt9p031_ctrl_ops,
+                         V4L2_CID_GAIN, MT9P031_GLOBAL_GAIN_MIN,
+                         MT9P031_GLOBAL_GAIN_MAX, 1, MT9P031_GLOBAL_GAIN_DEF);
+       v4l2_ctrl_new_std(&mt9p031->ctrls, &mt9p031_ctrl_ops,
+                         V4L2_CID_HFLIP, 0, 1, 1, 0);
+       v4l2_ctrl_new_std(&mt9p031->ctrls, &mt9p031_ctrl_ops,
+                         V4L2_CID_VFLIP, 0, 1, 1, 0);
+
+       for (i = 0; i < ARRAY_SIZE(mt9p031_ctrls); ++i)
+               v4l2_ctrl_new_custom(&mt9p031->ctrls, &mt9p031_ctrls[i], NULL);
+
+       mt9p031->subdev.ctrl_handler = &mt9p031->ctrls;
+
+       if (mt9p031->ctrls.error)
+               printk(KERN_INFO "%s: control initialization error %d\n",
+                      __func__, mt9p031->ctrls.error);
+
+       mutex_init(&mt9p031->power_lock);
+       v4l2_i2c_subdev_init(&mt9p031->subdev, client, &mt9p031_subdev_ops);
+       mt9p031->subdev.internal_ops = &mt9p031_subdev_internal_ops;
+
+       mt9p031->pad.flags = MEDIA_PAD_FL_SOURCE;
+       ret = media_entity_init(&mt9p031->subdev.entity, 1, &mt9p031->pad, 0);
+       if (ret < 0)
+               goto done;
+
+       mt9p031->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+
+       mt9p031->crop.width = MT9P031_WINDOW_WIDTH_DEF;
+       mt9p031->crop.height = MT9P031_WINDOW_HEIGHT_DEF;
+       mt9p031->crop.left = MT9P031_COLUMN_START_DEF;
+       mt9p031->crop.top = MT9P031_ROW_START_DEF;
+
+       if (mt9p031->pdata->version == MT9P031_MONOCHROME_VERSION)
+               mt9p031->format.code = V4L2_MBUS_FMT_Y12_1X12;
+       else
+               mt9p031->format.code = V4L2_MBUS_FMT_SGRBG12_1X12;
+
+       mt9p031->format.width = MT9P031_WINDOW_WIDTH_DEF;
+       mt9p031->format.height = MT9P031_WINDOW_HEIGHT_DEF;
+       mt9p031->format.field = V4L2_FIELD_NONE;
+       mt9p031->format.colorspace = V4L2_COLORSPACE_SRGB;
+
+       ret = mt9p031_pll_get_divs(mt9p031);
+
+done:
+       if (ret < 0) {
+               v4l2_ctrl_handler_free(&mt9p031->ctrls);
+               media_entity_cleanup(&mt9p031->subdev.entity);
+               kfree(mt9p031);
+       }
+
+       return ret;
+}
+
+static int mt9p031_remove(struct i2c_client *client)
+{
+       struct v4l2_subdev *subdev = i2c_get_clientdata(client);
+       struct mt9p031 *mt9p031 = to_mt9p031(subdev);
+
+       v4l2_ctrl_handler_free(&mt9p031->ctrls);
+       v4l2_device_unregister_subdev(subdev);
+       media_entity_cleanup(&subdev->entity);
+       kfree(mt9p031);
+
+       return 0;
+}
+
+static const struct i2c_device_id mt9p031_id[] = {
+       { "mt9p031", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, mt9p031_id);
+
+static struct i2c_driver mt9p031_i2c_driver = {
+       .driver = {
+               .name = "mt9p031",
+       },
+       .probe          = mt9p031_probe,
+       .remove         = mt9p031_remove,
+       .id_table       = mt9p031_id,
+};
+
+static int __init mt9p031_mod_init(void)
+{
+       return i2c_add_driver(&mt9p031_i2c_driver);
+}
+
+static void __exit mt9p031_mod_exit(void)
+{
+       i2c_del_driver(&mt9p031_i2c_driver);
+}
+
+module_init(mt9p031_mod_init);
+module_exit(mt9p031_mod_exit);
+
+MODULE_DESCRIPTION("Aptina MT9P031 Camera driver");
+MODULE_AUTHOR("Bastian Hecht <hechtb@gmail.com>");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/media/video/mt9t001.c b/drivers/media/video/mt9t001.c
new file mode 100644 (file)
index 0000000..08074b8
--- /dev/null
@@ -0,0 +1,836 @@
+/*
+ * Driver for MT9T001 CMOS Image Sensor from Aptina (Micron)
+ *
+ * Copyright (C) 2010-2011, Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ *
+ * Based on the MT9M001 driver,
+ *
+ * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/log2.h>
+#include <linux/slab.h>
+#include <linux/videodev2.h>
+#include <linux/v4l2-mediabus.h>
+
+#include <media/mt9t001.h>
+#include <media/v4l2-ctrls.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-subdev.h>
+
+#define MT9T001_PIXEL_ARRAY_HEIGHT                     1568
+#define MT9T001_PIXEL_ARRAY_WIDTH                      2112
+
+#define MT9T001_CHIP_VERSION                           0x00
+#define                MT9T001_CHIP_ID                         0x1621
+#define MT9T001_ROW_START                              0x01
+#define                MT9T001_ROW_START_MIN                   0
+#define                MT9T001_ROW_START_DEF                   20
+#define                MT9T001_ROW_START_MAX                   1534
+#define MT9T001_COLUMN_START                           0x02
+#define                MT9T001_COLUMN_START_MIN                0
+#define                MT9T001_COLUMN_START_DEF                32
+#define                MT9T001_COLUMN_START_MAX                2046
+#define MT9T001_WINDOW_HEIGHT                          0x03
+#define                MT9T001_WINDOW_HEIGHT_MIN               1
+#define                MT9T001_WINDOW_HEIGHT_DEF               1535
+#define                MT9T001_WINDOW_HEIGHT_MAX               1567
+#define MT9T001_WINDOW_WIDTH                           0x04
+#define                MT9T001_WINDOW_WIDTH_MIN                1
+#define                MT9T001_WINDOW_WIDTH_DEF                2047
+#define                MT9T001_WINDOW_WIDTH_MAX                2111
+#define MT9T001_HORIZONTAL_BLANKING                    0x05
+#define                MT9T001_HORIZONTAL_BLANKING_MIN         21
+#define                MT9T001_HORIZONTAL_BLANKING_MAX         1023
+#define MT9T001_VERTICAL_BLANKING                      0x06
+#define                MT9T001_VERTICAL_BLANKING_MIN           3
+#define                MT9T001_VERTICAL_BLANKING_MAX           1023
+#define MT9T001_OUTPUT_CONTROL                         0x07
+#define                MT9T001_OUTPUT_CONTROL_SYNC             (1 << 0)
+#define                MT9T001_OUTPUT_CONTROL_CHIP_ENABLE      (1 << 1)
+#define                MT9T001_OUTPUT_CONTROL_TEST_DATA        (1 << 6)
+#define MT9T001_SHUTTER_WIDTH_HIGH                     0x08
+#define MT9T001_SHUTTER_WIDTH_LOW                      0x09
+#define                MT9T001_SHUTTER_WIDTH_MIN               1
+#define                MT9T001_SHUTTER_WIDTH_DEF               1561
+#define                MT9T001_SHUTTER_WIDTH_MAX               (1024 * 1024)
+#define MT9T001_PIXEL_CLOCK                            0x0a
+#define                MT9T001_PIXEL_CLOCK_INVERT              (1 << 15)
+#define                MT9T001_PIXEL_CLOCK_SHIFT_MASK          (7 << 8)
+#define                MT9T001_PIXEL_CLOCK_SHIFT_SHIFT         8
+#define                MT9T001_PIXEL_CLOCK_DIVIDE_MASK         (0x7f << 0)
+#define MT9T001_FRAME_RESTART                          0x0b
+#define MT9T001_SHUTTER_DELAY                          0x0c
+#define                MT9T001_SHUTTER_DELAY_MAX               2047
+#define MT9T001_RESET                                  0x0d
+#define MT9T001_READ_MODE1                             0x1e
+#define                MT9T001_READ_MODE_SNAPSHOT              (1 << 8)
+#define                MT9T001_READ_MODE_STROBE_ENABLE         (1 << 9)
+#define                MT9T001_READ_MODE_STROBE_WIDTH          (1 << 10)
+#define                MT9T001_READ_MODE_STROBE_OVERRIDE       (1 << 11)
+#define MT9T001_READ_MODE2                             0x20
+#define                MT9T001_READ_MODE_BAD_FRAMES            (1 << 0)
+#define                MT9T001_READ_MODE_LINE_VALID_CONTINUOUS (1 << 9)
+#define                MT9T001_READ_MODE_LINE_VALID_FRAME      (1 << 10)
+#define MT9T001_READ_MODE3                             0x21
+#define                MT9T001_READ_MODE_GLOBAL_RESET          (1 << 0)
+#define                MT9T001_READ_MODE_GHST_CTL              (1 << 1)
+#define MT9T001_ROW_ADDRESS_MODE                       0x22
+#define                MT9T001_ROW_SKIP_MASK                   (7 << 0)
+#define                MT9T001_ROW_BIN_MASK                    (3 << 3)
+#define                MT9T001_ROW_BIN_SHIFT                   3
+#define MT9T001_COLUMN_ADDRESS_MODE                    0x23
+#define                MT9T001_COLUMN_SKIP_MASK                (7 << 0)
+#define                MT9T001_COLUMN_BIN_MASK                 (3 << 3)
+#define                MT9T001_COLUMN_BIN_SHIFT                3
+#define MT9T001_GREEN1_GAIN                            0x2b
+#define MT9T001_BLUE_GAIN                              0x2c
+#define MT9T001_RED_GAIN                               0x2d
+#define MT9T001_GREEN2_GAIN                            0x2e
+#define MT9T001_TEST_DATA                              0x32
+#define MT9T001_GLOBAL_GAIN                            0x35
+#define                MT9T001_GLOBAL_GAIN_MIN                 8
+#define                MT9T001_GLOBAL_GAIN_MAX                 1024
+#define MT9T001_BLACK_LEVEL                            0x49
+#define MT9T001_ROW_BLACK_DEFAULT_OFFSET               0x4b
+#define MT9T001_BLC_DELTA_THRESHOLDS                   0x5d
+#define MT9T001_CAL_THRESHOLDS                         0x5f
+#define MT9T001_GREEN1_OFFSET                          0x60
+#define MT9T001_GREEN2_OFFSET                          0x61
+#define MT9T001_BLACK_LEVEL_CALIBRATION                        0x62
+#define                MT9T001_BLACK_LEVEL_OVERRIDE            (1 << 0)
+#define                MT9T001_BLACK_LEVEL_DISABLE_OFFSET      (1 << 1)
+#define                MT9T001_BLACK_LEVEL_RECALCULATE         (1 << 12)
+#define                MT9T001_BLACK_LEVEL_LOCK_RED_BLUE       (1 << 13)
+#define                MT9T001_BLACK_LEVEL_LOCK_GREEN          (1 << 14)
+#define MT9T001_RED_OFFSET                             0x63
+#define MT9T001_BLUE_OFFSET                            0x64
+
+struct mt9t001 {
+       struct v4l2_subdev subdev;
+       struct media_pad pad;
+
+       struct v4l2_mbus_framefmt format;
+       struct v4l2_rect crop;
+
+       struct v4l2_ctrl_handler ctrls;
+       struct v4l2_ctrl *gains[4];
+
+       u16 output_control;
+       u16 black_level;
+};
+
+static inline struct mt9t001 *to_mt9t001(struct v4l2_subdev *sd)
+{
+       return container_of(sd, struct mt9t001, subdev);
+}
+
+static int mt9t001_read(struct i2c_client *client, u8 reg)
+{
+       s32 data = i2c_smbus_read_word_data(client, reg);
+       return data < 0 ? data : be16_to_cpu(data);
+}
+
+static int mt9t001_write(struct i2c_client *client, u8 reg, u16 data)
+{
+       return i2c_smbus_write_word_data(client, reg, cpu_to_be16(data));
+}
+
+static int mt9t001_set_output_control(struct mt9t001 *mt9t001, u16 clear,
+                                     u16 set)
+{
+       struct i2c_client *client = v4l2_get_subdevdata(&mt9t001->subdev);
+       u16 value = (mt9t001->output_control & ~clear) | set;
+       int ret;
+
+       if (value == mt9t001->output_control)
+               return 0;
+
+       ret = mt9t001_write(client, MT9T001_OUTPUT_CONTROL, value);
+       if (ret < 0)
+               return ret;
+
+       mt9t001->output_control = value;
+       return 0;
+}
+
+/* -----------------------------------------------------------------------------
+ * V4L2 subdev video operations
+ */
+
+static struct v4l2_mbus_framefmt *
+__mt9t001_get_pad_format(struct mt9t001 *mt9t001, struct v4l2_subdev_fh *fh,
+                        unsigned int pad, enum v4l2_subdev_format_whence which)
+{
+       switch (which) {
+       case V4L2_SUBDEV_FORMAT_TRY:
+               return v4l2_subdev_get_try_format(fh, pad);
+       case V4L2_SUBDEV_FORMAT_ACTIVE:
+               return &mt9t001->format;
+       default:
+               return NULL;
+       }
+}
+
+static struct v4l2_rect *
+__mt9t001_get_pad_crop(struct mt9t001 *mt9t001, struct v4l2_subdev_fh *fh,
+                      unsigned int pad, enum v4l2_subdev_format_whence which)
+{
+       switch (which) {
+       case V4L2_SUBDEV_FORMAT_TRY:
+               return v4l2_subdev_get_try_crop(fh, pad);
+       case V4L2_SUBDEV_FORMAT_ACTIVE:
+               return &mt9t001->crop;
+       default:
+               return NULL;
+       }
+}
+
+static int mt9t001_s_stream(struct v4l2_subdev *subdev, int enable)
+{
+       const u16 mode = MT9T001_OUTPUT_CONTROL_CHIP_ENABLE;
+       struct i2c_client *client = v4l2_get_subdevdata(subdev);
+       struct mt9t001 *mt9t001 = to_mt9t001(subdev);
+       struct v4l2_mbus_framefmt *format = &mt9t001->format;
+       struct v4l2_rect *crop = &mt9t001->crop;
+       unsigned int hratio;
+       unsigned int vratio;
+       int ret;
+
+       if (!enable)
+               return mt9t001_set_output_control(mt9t001, mode, 0);
+
+       /* Configure the window size and row/column bin */
+       hratio = DIV_ROUND_CLOSEST(crop->width, format->width);
+       vratio = DIV_ROUND_CLOSEST(crop->height, format->height);
+
+       ret = mt9t001_write(client, MT9T001_ROW_ADDRESS_MODE, hratio - 1);
+       if (ret < 0)
+               return ret;
+
+       ret = mt9t001_write(client, MT9T001_COLUMN_ADDRESS_MODE, vratio - 1);
+       if (ret < 0)
+               return ret;
+
+       ret = mt9t001_write(client, MT9T001_COLUMN_START, crop->left);
+       if (ret < 0)
+               return ret;
+
+       ret = mt9t001_write(client, MT9T001_ROW_START, crop->top);
+       if (ret < 0)
+               return ret;
+
+       ret = mt9t001_write(client, MT9T001_WINDOW_WIDTH, crop->width - 1);
+       if (ret < 0)
+               return ret;
+
+       ret = mt9t001_write(client, MT9T001_WINDOW_HEIGHT, crop->height - 1);
+       if (ret < 0)
+               return ret;
+
+       /* Switch to master "normal" mode */
+       return mt9t001_set_output_control(mt9t001, 0, mode);
+}
+
+static int mt9t001_enum_mbus_code(struct v4l2_subdev *subdev,
+                                 struct v4l2_subdev_fh *fh,
+                                 struct v4l2_subdev_mbus_code_enum *code)
+{
+       if (code->index > 0)
+               return -EINVAL;
+
+       code->code = V4L2_MBUS_FMT_SGRBG10_1X10;
+       return 0;
+}
+
+static int mt9t001_enum_frame_size(struct v4l2_subdev *subdev,
+                                  struct v4l2_subdev_fh *fh,
+                                  struct v4l2_subdev_frame_size_enum *fse)
+{
+       if (fse->index >= 8 || fse->code != V4L2_MBUS_FMT_SGRBG10_1X10)
+               return -EINVAL;
+
+       fse->min_width = (MT9T001_WINDOW_WIDTH_DEF + 1) / fse->index;
+       fse->max_width = fse->min_width;
+       fse->min_height = (MT9T001_WINDOW_HEIGHT_DEF + 1) / fse->index;
+       fse->max_height = fse->min_height;
+
+       return 0;
+}
+
+static int mt9t001_get_format(struct v4l2_subdev *subdev,
+                             struct v4l2_subdev_fh *fh,
+                             struct v4l2_subdev_format *format)
+{
+       struct mt9t001 *mt9t001 = to_mt9t001(subdev);
+
+       format->format = *__mt9t001_get_pad_format(mt9t001, fh, format->pad,
+                                                  format->which);
+       return 0;
+}
+
+static int mt9t001_set_format(struct v4l2_subdev *subdev,
+                             struct v4l2_subdev_fh *fh,
+                             struct v4l2_subdev_format *format)
+{
+       struct mt9t001 *mt9t001 = to_mt9t001(subdev);
+       struct v4l2_mbus_framefmt *__format;
+       struct v4l2_rect *__crop;
+       unsigned int width;
+       unsigned int height;
+       unsigned int hratio;
+       unsigned int vratio;
+
+       __crop = __mt9t001_get_pad_crop(mt9t001, fh, format->pad,
+                                       format->which);
+
+       /* Clamp the width and height to avoid dividing by zero. */
+       width = clamp_t(unsigned int, ALIGN(format->format.width, 2),
+                       max(__crop->width / 8, MT9T001_WINDOW_HEIGHT_MIN + 1),
+                       __crop->width);
+       height = clamp_t(unsigned int, ALIGN(format->format.height, 2),
+                        max(__crop->height / 8, MT9T001_WINDOW_HEIGHT_MIN + 1),
+                        __crop->height);
+
+       hratio = DIV_ROUND_CLOSEST(__crop->width, width);
+       vratio = DIV_ROUND_CLOSEST(__crop->height, height);
+
+       __format = __mt9t001_get_pad_format(mt9t001, fh, format->pad,
+                                           format->which);
+       __format->width = __crop->width / hratio;
+       __format->height = __crop->height / vratio;
+
+       format->format = *__format;
+
+       return 0;
+}
+
+static int mt9t001_get_crop(struct v4l2_subdev *subdev,
+                           struct v4l2_subdev_fh *fh,
+                           struct v4l2_subdev_crop *crop)
+{
+       struct mt9t001 *mt9t001 = to_mt9t001(subdev);
+
+       crop->rect = *__mt9t001_get_pad_crop(mt9t001, fh, crop->pad,
+                                            crop->which);
+       return 0;
+}
+
+static int mt9t001_set_crop(struct v4l2_subdev *subdev,
+                           struct v4l2_subdev_fh *fh,
+                           struct v4l2_subdev_crop *crop)
+{
+       struct mt9t001 *mt9t001 = to_mt9t001(subdev);
+       struct v4l2_mbus_framefmt *__format;
+       struct v4l2_rect *__crop;
+       struct v4l2_rect rect;
+
+       /* Clamp the crop rectangle boundaries and align them to a multiple of 2
+        * pixels.
+        */
+       rect.left = clamp(ALIGN(crop->rect.left, 2),
+                         MT9T001_COLUMN_START_MIN,
+                         MT9T001_COLUMN_START_MAX);
+       rect.top = clamp(ALIGN(crop->rect.top, 2),
+                        MT9T001_ROW_START_MIN,
+                        MT9T001_ROW_START_MAX);
+       rect.width = clamp(ALIGN(crop->rect.width, 2),
+                          MT9T001_WINDOW_WIDTH_MIN + 1,
+                          MT9T001_WINDOW_WIDTH_MAX + 1);
+       rect.height = clamp(ALIGN(crop->rect.height, 2),
+                           MT9T001_WINDOW_HEIGHT_MIN + 1,
+                           MT9T001_WINDOW_HEIGHT_MAX + 1);
+
+       rect.width = min(rect.width, MT9T001_PIXEL_ARRAY_WIDTH - rect.left);
+       rect.height = min(rect.height, MT9T001_PIXEL_ARRAY_HEIGHT - rect.top);
+
+       __crop = __mt9t001_get_pad_crop(mt9t001, fh, crop->pad, crop->which);
+
+       if (rect.width != __crop->width || rect.height != __crop->height) {
+               /* Reset the output image size if the crop rectangle size has
+                * been modified.
+                */
+               __format = __mt9t001_get_pad_format(mt9t001, fh, crop->pad,
+                                                   crop->which);
+               __format->width = rect.width;
+               __format->height = rect.height;
+       }
+
+       *__crop = rect;
+       crop->rect = rect;
+
+       return 0;
+}
+
+/* -----------------------------------------------------------------------------
+ * V4L2 subdev control operations
+ */
+
+#define V4L2_CID_TEST_PATTERN          (V4L2_CID_USER_BASE | 0x1001)
+#define V4L2_CID_BLACK_LEVEL_AUTO      (V4L2_CID_USER_BASE | 0x1002)
+#define V4L2_CID_BLACK_LEVEL_OFFSET    (V4L2_CID_USER_BASE | 0x1003)
+#define V4L2_CID_BLACK_LEVEL_CALIBRATE (V4L2_CID_USER_BASE | 0x1004)
+
+#define V4L2_CID_GAIN_RED              (V4L2_CTRL_CLASS_CAMERA | 0x1001)
+#define V4L2_CID_GAIN_GREEN_RED                (V4L2_CTRL_CLASS_CAMERA | 0x1002)
+#define V4L2_CID_GAIN_GREEN_BLUE       (V4L2_CTRL_CLASS_CAMERA | 0x1003)
+#define V4L2_CID_GAIN_BLUE             (V4L2_CTRL_CLASS_CAMERA | 0x1004)
+
+static u16 mt9t001_gain_value(s32 *gain)
+{
+       /* Gain is controlled by 2 analog stages and a digital stage. Valid
+        * values for the 3 stages are
+        *
+        * Stage                Min     Max     Step
+        * ------------------------------------------
+        * First analog stage   x1      x2      1
+        * Second analog stage  x1      x4      0.125
+        * Digital stage        x1      x16     0.125
+        *
+        * To minimize noise, the gain stages should be used in the second
+        * analog stage, first analog stage, digital stage order. Gain from a
+        * previous stage should be pushed to its maximum value before the next
+        * stage is used.
+        */
+       if (*gain <= 32)
+               return *gain;
+
+       if (*gain <= 64) {
+               *gain &= ~1;
+               return (1 << 6) | (*gain >> 1);
+       }
+
+       *gain &= ~7;
+       return ((*gain - 64) << 5) | (1 << 6) | 32;
+}
+
+static int mt9t001_ctrl_freeze(struct mt9t001 *mt9t001, bool freeze)
+{
+       return mt9t001_set_output_control(mt9t001,
+               freeze ? 0 : MT9T001_OUTPUT_CONTROL_SYNC,
+               freeze ? MT9T001_OUTPUT_CONTROL_SYNC : 0);
+}
+
+static int mt9t001_s_ctrl(struct v4l2_ctrl *ctrl)
+{
+       static const u8 gains[4] = {
+               MT9T001_RED_GAIN, MT9T001_GREEN1_GAIN,
+               MT9T001_GREEN2_GAIN, MT9T001_BLUE_GAIN
+       };
+
+       struct mt9t001 *mt9t001 =
+                       container_of(ctrl->handler, struct mt9t001, ctrls);
+       struct i2c_client *client = v4l2_get_subdevdata(&mt9t001->subdev);
+       unsigned int count;
+       unsigned int i;
+       u16 value;
+       int ret;
+
+       switch (ctrl->id) {
+       case V4L2_CID_GAIN_RED:
+       case V4L2_CID_GAIN_GREEN_RED:
+       case V4L2_CID_GAIN_GREEN_BLUE:
+       case V4L2_CID_GAIN_BLUE:
+
+               /* Disable control updates if more than one control has changed
+                * in the cluster.
+                */
+               for (i = 0, count = 0; i < 4; ++i) {
+                       struct v4l2_ctrl *gain = mt9t001->gains[i];
+
+                       if (gain->val != gain->cur.val)
+                               count++;
+               }
+
+               if (count > 1) {
+                       ret = mt9t001_ctrl_freeze(mt9t001, true);
+                       if (ret < 0)
+                               return ret;
+               }
+
+               /* Update the gain controls. */
+               for (i = 0; i < 4; ++i) {
+                       struct v4l2_ctrl *gain = mt9t001->gains[i];
+
+                       if (gain->val == gain->cur.val)
+                               continue;
+
+                       value = mt9t001_gain_value(&gain->val);
+                       ret = mt9t001_write(client, gains[i], value);
+                       if (ret < 0) {
+                               mt9t001_ctrl_freeze(mt9t001, false);
+                               return ret;
+                       }
+               }
+
+               /* Enable control updates. */
+               if (count > 1) {
+                       ret = mt9t001_ctrl_freeze(mt9t001, false);
+                       if (ret < 0)
+                               return ret;
+               }
+
+               break;
+
+       case V4L2_CID_EXPOSURE:
+               ret = mt9t001_write(client, MT9T001_SHUTTER_WIDTH_LOW,
+                                   ctrl->val & 0xffff);
+               if (ret < 0)
+                       return ret;
+
+               return mt9t001_write(client, MT9T001_SHUTTER_WIDTH_HIGH,
+                                    ctrl->val >> 16);
+
+       case V4L2_CID_TEST_PATTERN:
+               ret = mt9t001_set_output_control(mt9t001,
+                       ctrl->val ? 0 : MT9T001_OUTPUT_CONTROL_TEST_DATA,
+                       ctrl->val ? MT9T001_OUTPUT_CONTROL_TEST_DATA : 0);
+               if (ret < 0)
+                       return ret;
+
+               return mt9t001_write(client, MT9T001_TEST_DATA, ctrl->val << 2);
+
+       case V4L2_CID_BLACK_LEVEL_AUTO:
+               value = ctrl->val ? 0 : MT9T001_BLACK_LEVEL_OVERRIDE;
+               ret = mt9t001_write(client, MT9T001_BLACK_LEVEL_CALIBRATION,
+                                   value);
+               if (ret < 0)
+                       return ret;
+
+               mt9t001->black_level = value;
+               break;
+
+       case V4L2_CID_BLACK_LEVEL_OFFSET:
+               ret = mt9t001_write(client, MT9T001_GREEN1_OFFSET, ctrl->val);
+               if (ret < 0)
+                       return ret;
+
+               ret = mt9t001_write(client, MT9T001_GREEN2_OFFSET, ctrl->val);
+               if (ret < 0)
+                       return ret;
+
+               ret = mt9t001_write(client, MT9T001_RED_OFFSET, ctrl->val);
+               if (ret < 0)
+                       return ret;
+
+               return mt9t001_write(client, MT9T001_BLUE_OFFSET, ctrl->val);
+
+       case V4L2_CID_BLACK_LEVEL_CALIBRATE:
+               return mt9t001_write(client, MT9T001_BLACK_LEVEL_CALIBRATION,
+                                    MT9T001_BLACK_LEVEL_RECALCULATE |
+                                    mt9t001->black_level);
+       }
+
+       return 0;
+}
+
+static struct v4l2_ctrl_ops mt9t001_ctrl_ops = {
+       .s_ctrl = mt9t001_s_ctrl,
+};
+
+static const struct v4l2_ctrl_config mt9t001_ctrls[] = {
+       {
+               .ops            = &mt9t001_ctrl_ops,
+               .id             = V4L2_CID_TEST_PATTERN,
+               .type           = V4L2_CTRL_TYPE_INTEGER,
+               .name           = "Test pattern",
+               .min            = 0,
+               .max            = 1023,
+               .step           = 1,
+               .def            = 0,
+               .flags          = 0,
+       }, {
+               .ops            = &mt9t001_ctrl_ops,
+               .id             = V4L2_CID_BLACK_LEVEL_AUTO,
+               .type           = V4L2_CTRL_TYPE_BOOLEAN,
+               .name           = "Black Level, Auto",
+               .min            = 0,
+               .max            = 1,
+               .step           = 1,
+               .def            = 1,
+               .flags          = 0,
+       }, {
+               .ops            = &mt9t001_ctrl_ops,
+               .id             = V4L2_CID_BLACK_LEVEL_OFFSET,
+               .type           = V4L2_CTRL_TYPE_INTEGER,
+               .name           = "Black Level, Offset",
+               .min            = -256,
+               .max            = 255,
+               .step           = 1,
+               .def            = 32,
+               .flags          = 0,
+       }, {
+               .ops            = &mt9t001_ctrl_ops,
+               .id             = V4L2_CID_BLACK_LEVEL_CALIBRATE,
+               .type           = V4L2_CTRL_TYPE_BUTTON,
+               .name           = "Black Level, Calibrate",
+               .min            = 0,
+               .max            = 0,
+               .step           = 0,
+               .def            = 0,
+               .flags          = V4L2_CTRL_FLAG_WRITE_ONLY,
+       },
+};
+
+static const struct v4l2_ctrl_config mt9t001_gains[] = {
+       {
+               .ops            = &mt9t001_ctrl_ops,
+               .id             = V4L2_CID_GAIN_RED,
+               .type           = V4L2_CTRL_TYPE_INTEGER,
+               .name           = "Gain, Red",
+               .min            = MT9T001_GLOBAL_GAIN_MIN,
+               .max            = MT9T001_GLOBAL_GAIN_MAX,
+               .step           = 1,
+               .def            = MT9T001_GLOBAL_GAIN_MIN,
+               .flags          = 0,
+       }, {
+               .ops            = &mt9t001_ctrl_ops,
+               .id             = V4L2_CID_GAIN_GREEN_RED,
+               .type           = V4L2_CTRL_TYPE_INTEGER,
+               .name           = "Gain, Green (R)",
+               .min            = MT9T001_GLOBAL_GAIN_MIN,
+               .max            = MT9T001_GLOBAL_GAIN_MAX,
+               .step           = 1,
+               .def            = MT9T001_GLOBAL_GAIN_MIN,
+               .flags          = 0,
+       }, {
+               .ops            = &mt9t001_ctrl_ops,
+               .id             = V4L2_CID_GAIN_GREEN_BLUE,
+               .type           = V4L2_CTRL_TYPE_INTEGER,
+               .name           = "Gain, Green (B)",
+               .min            = MT9T001_GLOBAL_GAIN_MIN,
+               .max            = MT9T001_GLOBAL_GAIN_MAX,
+               .step           = 1,
+               .def            = MT9T001_GLOBAL_GAIN_MIN,
+               .flags          = 0,
+       }, {
+               .ops            = &mt9t001_ctrl_ops,
+               .id             = V4L2_CID_GAIN_BLUE,
+               .type           = V4L2_CTRL_TYPE_INTEGER,
+               .name           = "Gain, Blue",
+               .min            = MT9T001_GLOBAL_GAIN_MIN,
+               .max            = MT9T001_GLOBAL_GAIN_MAX,
+               .step           = 1,
+               .def            = MT9T001_GLOBAL_GAIN_MIN,
+               .flags          = 0,
+       },
+};
+
+/* -----------------------------------------------------------------------------
+ * V4L2 subdev internal operations
+ */
+
+static int mt9t001_open(struct v4l2_subdev *subdev, struct v4l2_subdev_fh *fh)
+{
+       struct v4l2_mbus_framefmt *format;
+       struct v4l2_rect *crop;
+
+       crop = v4l2_subdev_get_try_crop(fh, 0);
+       crop->left = MT9T001_COLUMN_START_DEF;
+       crop->top = MT9T001_ROW_START_DEF;
+       crop->width = MT9T001_WINDOW_WIDTH_DEF + 1;
+       crop->height = MT9T001_WINDOW_HEIGHT_DEF + 1;
+
+       format = v4l2_subdev_get_try_format(fh, 0);
+       format->code = V4L2_MBUS_FMT_SGRBG10_1X10;
+       format->width = MT9T001_WINDOW_WIDTH_DEF + 1;
+       format->height = MT9T001_WINDOW_HEIGHT_DEF + 1;
+       format->field = V4L2_FIELD_NONE;
+       format->colorspace = V4L2_COLORSPACE_SRGB;
+
+       return 0;
+}
+
+static struct v4l2_subdev_video_ops mt9t001_subdev_video_ops = {
+       .s_stream = mt9t001_s_stream,
+};
+
+static struct v4l2_subdev_pad_ops mt9t001_subdev_pad_ops = {
+       .enum_mbus_code = mt9t001_enum_mbus_code,
+       .enum_frame_size = mt9t001_enum_frame_size,
+       .get_fmt = mt9t001_get_format,
+       .set_fmt = mt9t001_set_format,
+       .get_crop = mt9t001_get_crop,
+       .set_crop = mt9t001_set_crop,
+};
+
+static struct v4l2_subdev_ops mt9t001_subdev_ops = {
+       .video = &mt9t001_subdev_video_ops,
+       .pad = &mt9t001_subdev_pad_ops,
+};
+
+static struct v4l2_subdev_internal_ops mt9t001_subdev_internal_ops = {
+       .open = mt9t001_open,
+};
+
+static int mt9t001_video_probe(struct i2c_client *client)
+{
+       struct mt9t001_platform_data *pdata = client->dev.platform_data;
+       s32 data;
+       int ret;
+
+       dev_info(&client->dev, "Probing MT9T001 at address 0x%02x\n",
+                client->addr);
+
+       /* Reset the chip and stop data read out */
+       ret = mt9t001_write(client, MT9T001_RESET, 1);
+       if (ret < 0)
+               return ret;
+
+       ret = mt9t001_write(client, MT9T001_RESET, 0);
+       if (ret < 0)
+               return ret;
+
+       ret  = mt9t001_write(client, MT9T001_OUTPUT_CONTROL, 0);
+       if (ret < 0)
+               return ret;
+
+       /* Configure the pixel clock polarity */
+       if (pdata && pdata->clk_pol) {
+               ret  = mt9t001_write(client, MT9T001_PIXEL_CLOCK,
+                                    MT9T001_PIXEL_CLOCK_INVERT);
+               if (ret < 0)
+                       return ret;
+       }
+
+       /* Read and check the sensor version */
+       data = mt9t001_read(client, MT9T001_CHIP_VERSION);
+       if (data != MT9T001_CHIP_ID) {
+               dev_err(&client->dev, "MT9T001 not detected, wrong version "
+                       "0x%04x\n", data);
+               return -ENODEV;
+       }
+
+       dev_info(&client->dev, "MT9T001 detected at address 0x%02x\n",
+                client->addr);
+
+       return ret;
+}
+
+static int mt9t001_probe(struct i2c_client *client,
+                        const struct i2c_device_id *did)
+{
+       struct mt9t001 *mt9t001;
+       unsigned int i;
+       int ret;
+
+       if (!i2c_check_functionality(client->adapter,
+                                    I2C_FUNC_SMBUS_WORD_DATA)) {
+               dev_warn(&client->adapter->dev,
+                        "I2C-Adapter doesn't support I2C_FUNC_SMBUS_WORD\n");
+               return -EIO;
+       }
+
+       ret = mt9t001_video_probe(client);
+       if (ret < 0)
+               return ret;
+
+       mt9t001 = kzalloc(sizeof(*mt9t001), GFP_KERNEL);
+       if (!mt9t001)
+               return -ENOMEM;
+
+       v4l2_ctrl_handler_init(&mt9t001->ctrls, ARRAY_SIZE(mt9t001_ctrls) +
+                                               ARRAY_SIZE(mt9t001_gains) + 2);
+
+       v4l2_ctrl_new_std(&mt9t001->ctrls, &mt9t001_ctrl_ops,
+                         V4L2_CID_EXPOSURE, MT9T001_SHUTTER_WIDTH_MIN,
+                         MT9T001_SHUTTER_WIDTH_MAX, 1,
+                         MT9T001_SHUTTER_WIDTH_DEF);
+       v4l2_ctrl_new_std(&mt9t001->ctrls, &mt9t001_ctrl_ops,
+                         V4L2_CID_BLACK_LEVEL, 1, 1, 1, 1);
+
+       for (i = 0; i < ARRAY_SIZE(mt9t001_ctrls); ++i)
+               v4l2_ctrl_new_custom(&mt9t001->ctrls, &mt9t001_ctrls[i], NULL);
+
+       for (i = 0; i < ARRAY_SIZE(mt9t001_gains); ++i)
+               mt9t001->gains[i] = v4l2_ctrl_new_custom(&mt9t001->ctrls,
+                       &mt9t001_gains[i], NULL);
+
+       v4l2_ctrl_cluster(ARRAY_SIZE(mt9t001_gains), mt9t001->gains);
+
+       mt9t001->subdev.ctrl_handler = &mt9t001->ctrls;
+
+       if (mt9t001->ctrls.error) {
+               printk(KERN_INFO "%s: control initialization error %d\n",
+                      __func__, mt9t001->ctrls.error);
+               ret = -EINVAL;
+               goto done;
+       }
+
+       mt9t001->crop.left = MT9T001_COLUMN_START_DEF;
+       mt9t001->crop.top = MT9T001_ROW_START_DEF;
+       mt9t001->crop.width = MT9T001_WINDOW_WIDTH_DEF + 1;
+       mt9t001->crop.height = MT9T001_WINDOW_HEIGHT_DEF + 1;
+
+       mt9t001->format.code = V4L2_MBUS_FMT_SGRBG10_1X10;
+       mt9t001->format.width = MT9T001_WINDOW_WIDTH_DEF + 1;
+       mt9t001->format.height = MT9T001_WINDOW_HEIGHT_DEF + 1;
+       mt9t001->format.field = V4L2_FIELD_NONE;
+       mt9t001->format.colorspace = V4L2_COLORSPACE_SRGB;
+
+       v4l2_i2c_subdev_init(&mt9t001->subdev, client, &mt9t001_subdev_ops);
+       mt9t001->subdev.internal_ops = &mt9t001_subdev_internal_ops;
+       mt9t001->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+
+       mt9t001->pad.flags = MEDIA_PAD_FL_SOURCE;
+       ret = media_entity_init(&mt9t001->subdev.entity, 1, &mt9t001->pad, 0);
+
+done:
+       if (ret < 0) {
+               v4l2_ctrl_handler_free(&mt9t001->ctrls);
+               media_entity_cleanup(&mt9t001->subdev.entity);
+               kfree(mt9t001);
+       }
+
+       return ret;
+}
+
+static int mt9t001_remove(struct i2c_client *client)
+{
+       struct v4l2_subdev *subdev = i2c_get_clientdata(client);
+       struct mt9t001 *mt9t001 = to_mt9t001(subdev);
+
+       v4l2_ctrl_handler_free(&mt9t001->ctrls);
+       v4l2_device_unregister_subdev(subdev);
+       media_entity_cleanup(&subdev->entity);
+       kfree(mt9t001);
+       return 0;
+}
+
+static const struct i2c_device_id mt9t001_id[] = {
+       { "mt9t001", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, mt9t001_id);
+
+static struct i2c_driver mt9t001_driver = {
+       .driver = {
+               .name = "mt9t001",
+       },
+       .probe          = mt9t001_probe,
+       .remove         = mt9t001_remove,
+       .id_table       = mt9t001_id,
+};
+
+static int __init mt9t001_init(void)
+{
+       return i2c_add_driver(&mt9t001_driver);
+}
+
+static void __exit mt9t001_exit(void)
+{
+       i2c_del_driver(&mt9t001_driver);
+}
+
+module_init(mt9t001_init);
+module_exit(mt9t001_exit);
+
+MODULE_DESCRIPTION("Aptina (Micron) MT9T001 Camera driver");
+MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>");
+MODULE_LICENSE("GPL");
index c045b47803adfdca07328815b08c34ab009ea9e3..c8e958a07e91f6e4a4d22d10c8c29c86cfe05177 100644 (file)
@@ -191,7 +191,7 @@ static void mx3_cam_dma_done(void *arg)
  */
 static int mx3_videobuf_setup(struct vb2_queue *vq,
                        unsigned int *count, unsigned int *num_planes,
-                       unsigned long sizes[], void *alloc_ctxs[])
+                       unsigned int sizes[], void *alloc_ctxs[])
 {
        struct soc_camera_device *icd = soc_camera_from_vb2q(vq);
        struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
@@ -247,7 +247,7 @@ static int mx3_videobuf_prepare(struct vb2_buffer *vb)
        }
 
        if (buf->state == CSI_BUF_NEEDS_INIT) {
-               sg_dma_address(sg)      = vb2_dma_contig_plane_paddr(vb, 0);
+               sg_dma_address(sg)      = vb2_dma_contig_plane_dma_addr(vb, 0);
                sg_dma_len(sg)          = new_size;
 
                buf->txd = ichan->dma_chan.device->device_prep_slave_sg(
index 0b38500235055bc176ebbc444f277a276c3b00d5..f0c3968ac7ebf68098f510d5604a82cfd7c01745 100644 (file)
@@ -21,6 +21,8 @@
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #define DEBUG_VARIABLE debug
 
 #include <media/saa7146_vv.h>
@@ -171,7 +173,7 @@ static int mxb_probe(struct saa7146_dev *dev)
 
        mxb = kzalloc(sizeof(struct mxb), GFP_KERNEL);
        if (mxb == NULL) {
-               DEB_D(("not enough kernel memory.\n"));
+               DEB_D("not enough kernel memory\n");
                return -ENOMEM;
        }
 
@@ -179,7 +181,7 @@ static int mxb_probe(struct saa7146_dev *dev)
 
        saa7146_i2c_adapter_prepare(dev, &mxb->i2c_adapter, SAA7146_I2C_BUS_BIT_RATE_480);
        if (i2c_add_adapter(&mxb->i2c_adapter) < 0) {
-               DEB_S(("cannot register i2c-device. skipping.\n"));
+               DEB_S("cannot register i2c-device. skipping.\n");
                kfree(mxb);
                return -EFAULT;
        }
@@ -200,7 +202,7 @@ static int mxb_probe(struct saa7146_dev *dev)
        /* check if all devices are present */
        if (!mxb->tea6420_1 || !mxb->tea6420_2 || !mxb->tea6415c ||
            !mxb->tda9840 || !mxb->saa7111a || !mxb->tuner) {
-               printk("mxb: did not find all i2c devices. aborting\n");
+               pr_err("did not find all i2c devices. aborting\n");
                i2c_del_adapter(&mxb->i2c_adapter);
                kfree(mxb);
                return -ENODEV;
@@ -346,11 +348,11 @@ static int mxb_init_done(struct saa7146_dev* dev)
                        msg.buf = &mxb_saa7740_init[i].data[0];
                        err = i2c_transfer(&mxb->i2c_adapter, &msg, 1);
                        if (err != 1) {
-                               DEB_D(("failed to initialize 'sound arena module'.\n"));
+                               DEB_D("failed to initialize 'sound arena module'\n");
                                goto err;
                        }
                }
-               INFO(("'sound arena module' detected.\n"));
+               pr_info("'sound arena module' detected\n");
        }
 err:
        /* the rest for saa7146: you should definitely set some basic values
@@ -390,7 +392,7 @@ static int vidioc_queryctrl(struct file *file, void *fh, struct v4l2_queryctrl *
        for (i = MAXCONTROLS - 1; i >= 0; i--) {
                if (mxb_controls[i].id == qc->id) {
                        *qc = mxb_controls[i];
-                       DEB_D(("VIDIOC_QUERYCTRL %d.\n", qc->id));
+                       DEB_D("VIDIOC_QUERYCTRL %d\n", qc->id);
                        return 0;
                }
        }
@@ -413,11 +415,11 @@ static int vidioc_g_ctrl(struct file *file, void *fh, struct v4l2_control *vc)
 
        if (vc->id == V4L2_CID_AUDIO_MUTE) {
                vc->value = mxb->cur_mute;
-               DEB_D(("VIDIOC_G_CTRL V4L2_CID_AUDIO_MUTE:%d.\n", vc->value));
+               DEB_D("VIDIOC_G_CTRL V4L2_CID_AUDIO_MUTE:%d\n", vc->value);
                return 0;
        }
 
-       DEB_EE(("VIDIOC_G_CTRL V4L2_CID_AUDIO_MUTE:%d.\n", vc->value));
+       DEB_EE("VIDIOC_G_CTRL V4L2_CID_AUDIO_MUTE:%d\n", vc->value);
        return 0;
 }
 
@@ -440,14 +442,14 @@ static int vidioc_s_ctrl(struct file *file, void *fh, struct v4l2_control *vc)
                /* switch the audio-source */
                tea6420_route_line(mxb, vc->value ? 6 :
                                video_audio_connect[mxb->cur_input]);
-               DEB_EE(("VIDIOC_S_CTRL, V4L2_CID_AUDIO_MUTE: %d.\n", vc->value));
+               DEB_EE("VIDIOC_S_CTRL, V4L2_CID_AUDIO_MUTE: %d\n", vc->value);
        }
        return 0;
 }
 
 static int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *i)
 {
-       DEB_EE(("VIDIOC_ENUMINPUT %d.\n", i->index));
+       DEB_EE("VIDIOC_ENUMINPUT %d\n", i->index);
        if (i->index >= MXB_INPUTS)
                return -EINVAL;
        memcpy(i, &mxb_inputs[i->index], sizeof(struct v4l2_input));
@@ -460,7 +462,7 @@ static int vidioc_g_input(struct file *file, void *fh, unsigned int *i)
        struct mxb *mxb = (struct mxb *)dev->ext_priv;
        *i = mxb->cur_input;
 
-       DEB_EE(("VIDIOC_G_INPUT %d.\n", *i));
+       DEB_EE("VIDIOC_G_INPUT %d\n", *i);
        return 0;
 }
 
@@ -471,7 +473,7 @@ static int vidioc_s_input(struct file *file, void *fh, unsigned int input)
        int err = 0;
        int i = 0;
 
-       DEB_EE(("VIDIOC_S_INPUT %d.\n", input));
+       DEB_EE("VIDIOC_S_INPUT %d\n", input);
 
        if (input >= MXB_INPUTS)
                return -EINVAL;
@@ -514,7 +516,7 @@ static int vidioc_s_input(struct file *file, void *fh, unsigned int input)
 
        /* switch video in saa7111a */
        if (saa7111a_call(mxb, video, s_routing, i, SAA7111_FMT_CCIR, 0))
-               printk(KERN_ERR "VIDIOC_S_INPUT: could not address saa7111a.\n");
+               pr_err("VIDIOC_S_INPUT: could not address saa7111a\n");
 
        /* switch the audio-source only if necessary */
        if (0 == mxb->cur_mute)
@@ -529,11 +531,12 @@ static int vidioc_g_tuner(struct file *file, void *fh, struct v4l2_tuner *t)
        struct mxb *mxb = (struct mxb *)dev->ext_priv;
 
        if (t->index) {
-               DEB_D(("VIDIOC_G_TUNER: channel %d does not have a tuner attached.\n", t->index));
+               DEB_D("VIDIOC_G_TUNER: channel %d does not have a tuner attached\n",
+                     t->index);
                return -EINVAL;
        }
 
-       DEB_EE(("VIDIOC_G_TUNER: %d\n", t->index));
+       DEB_EE("VIDIOC_G_TUNER: %d\n", t->index);
 
        memset(t, 0, sizeof(*t));
        strlcpy(t->name, "TV Tuner", sizeof(t->name));
@@ -550,7 +553,8 @@ static int vidioc_s_tuner(struct file *file, void *fh, struct v4l2_tuner *t)
        struct mxb *mxb = (struct mxb *)dev->ext_priv;
 
        if (t->index) {
-               DEB_D(("VIDIOC_S_TUNER: channel %d does not have a tuner attached.\n", t->index));
+               DEB_D("VIDIOC_S_TUNER: channel %d does not have a tuner attached\n",
+                     t->index);
                return -EINVAL;
        }
 
@@ -564,14 +568,14 @@ static int vidioc_g_frequency(struct file *file, void *fh, struct v4l2_frequency
        struct mxb *mxb = (struct mxb *)dev->ext_priv;
 
        if (mxb->cur_input) {
-               DEB_D(("VIDIOC_G_FREQ: channel %d does not have a tuner!\n",
-                                       mxb->cur_input));
+               DEB_D("VIDIOC_G_FREQ: channel %d does not have a tuner!\n",
+                     mxb->cur_input);
                return -EINVAL;
        }
 
        *f = mxb->cur_freq;
 
-       DEB_EE(("VIDIOC_G_FREQ: freq:0x%08x.\n", mxb->cur_freq.frequency));
+       DEB_EE("VIDIOC_G_FREQ: freq:0x%08x\n", mxb->cur_freq.frequency);
        return 0;
 }
 
@@ -588,12 +592,13 @@ static int vidioc_s_frequency(struct file *file, void *fh, struct v4l2_frequency
                return -EINVAL;
 
        if (mxb->cur_input) {
-               DEB_D(("VIDIOC_S_FREQ: channel %d does not have a tuner!\n", mxb->cur_input));
+               DEB_D("VIDIOC_S_FREQ: channel %d does not have a tuner!\n",
+                     mxb->cur_input);
                return -EINVAL;
        }
 
        mxb->cur_freq = *f;
-       DEB_EE(("VIDIOC_S_FREQUENCY: freq:0x%08x.\n", mxb->cur_freq.frequency));
+       DEB_EE("VIDIOC_S_FREQUENCY: freq:0x%08x\n", mxb->cur_freq.frequency);
 
        /* tune in desired frequency */
        tuner_call(mxb, tuner, s_frequency, &mxb->cur_freq);
@@ -612,18 +617,18 @@ static int vidioc_g_audio(struct file *file, void *fh, struct v4l2_audio *a)
        struct mxb *mxb = (struct mxb *)dev->ext_priv;
 
        if (a->index > MXB_INPUTS) {
-               DEB_D(("VIDIOC_G_AUDIO %d out of range.\n", a->index));
+               DEB_D("VIDIOC_G_AUDIO %d out of range\n", a->index);
                return -EINVAL;
        }
 
-       DEB_EE(("VIDIOC_G_AUDIO %d.\n", a->index));
+       DEB_EE("VIDIOC_G_AUDIO %d\n", a->index);
        memcpy(a, &mxb_audios[video_audio_connect[mxb->cur_input]], sizeof(struct v4l2_audio));
        return 0;
 }
 
 static int vidioc_s_audio(struct file *file, void *fh, struct v4l2_audio *a)
 {
-       DEB_D(("VIDIOC_S_AUDIO %d.\n", a->index));
+       DEB_D("VIDIOC_S_AUDIO %d\n", a->index);
        return 0;
 }
 
@@ -655,11 +660,11 @@ static long vidioc_default(struct file *file, void *fh, bool valid_prio,
                int i = *(int *)arg;
 
                if (i < 0 || i >= MXB_AUDIOS) {
-                       DEB_D(("illegal argument to MXB_S_AUDIO_CD: i:%d.\n", i));
+                       DEB_D("invalid argument to MXB_S_AUDIO_CD: i:%d\n", i);
                        return -EINVAL;
                }
 
-               DEB_EE(("MXB_S_AUDIO_CD: i:%d.\n", i));
+               DEB_EE("MXB_S_AUDIO_CD: i:%d\n", i);
 
                tea6420_route_cd(mxb, i);
                return 0;
@@ -669,17 +674,18 @@ static long vidioc_default(struct file *file, void *fh, bool valid_prio,
                int i = *(int *)arg;
 
                if (i < 0 || i >= MXB_AUDIOS) {
-                       DEB_D(("illegal argument to MXB_S_AUDIO_LINE: i:%d.\n", i));
+                       DEB_D("invalid argument to MXB_S_AUDIO_LINE: i:%d\n",
+                             i);
                        return -EINVAL;
                }
 
-               DEB_EE(("MXB_S_AUDIO_LINE: i:%d.\n", i));
+               DEB_EE("MXB_S_AUDIO_LINE: i:%d\n", i);
                tea6420_route_line(mxb, i);
                return 0;
        }
        default:
 /*
-               DEB2(printk("does not handle this ioctl.\n"));
+               DEB2(pr_err("does not handle this ioctl\n"));
 */
                return -ENOIOCTLCMD;
        }
@@ -693,7 +699,7 @@ static int mxb_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data
 {
        struct mxb *mxb;
 
-       DEB_EE(("dev:%p\n", dev));
+       DEB_EE("dev:%p\n", dev);
 
        saa7146_vv_init(dev, &vv_data);
        if (mxb_probe(dev)) {
@@ -720,7 +726,7 @@ static int mxb_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data
 #endif
        vv_data.ops.vidioc_default = vidioc_default;
        if (saa7146_register_device(&mxb->video_dev, dev, "mxb", VFL_TYPE_GRABBER)) {
-               ERR(("cannot register capture v4l2 device. skipping.\n"));
+               ERR("cannot register capture v4l2 device. skipping.\n");
                saa7146_vv_release(dev);
                return -1;
        }
@@ -728,11 +734,11 @@ static int mxb_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data
        /* initialization stuff (vbi) (only for revision > 0 and for extensions which want it)*/
        if (MXB_BOARD_CAN_DO_VBI(dev)) {
                if (saa7146_register_device(&mxb->vbi_dev, dev, "mxb", VFL_TYPE_VBI)) {
-                       ERR(("cannot register vbi v4l2 device. skipping.\n"));
+                       ERR("cannot register vbi v4l2 device. skipping.\n");
                }
        }
 
-       printk("mxb: found Multimedia eXtension Board #%d.\n", mxb_num);
+       pr_info("found Multimedia eXtension Board #%d\n", mxb_num);
 
        mxb_num++;
        mxb_init_done(dev);
@@ -743,7 +749,7 @@ static int mxb_detach(struct saa7146_dev *dev)
 {
        struct mxb *mxb = (struct mxb *)dev->ext_priv;
 
-       DEB_EE(("dev:%p\n", dev));
+       DEB_EE("dev:%p\n", dev);
 
        saa7146_unregister_device(&mxb->video_dev,dev);
        if (MXB_BOARD_CAN_DO_VBI(dev))
@@ -765,7 +771,7 @@ static int std_callback(struct saa7146_dev *dev, struct saa7146_standard *standa
        if (V4L2_STD_PAL_I == standard->id) {
                v4l2_std_id std = V4L2_STD_PAL_I;
 
-               DEB_D(("VIDIOC_S_STD: setting mxb for PAL_I.\n"));
+               DEB_D("VIDIOC_S_STD: setting mxb for PAL_I\n");
                /* set the 7146 gpio register -- I don't know what this does exactly */
                saa7146_write(dev, GPIO_CTRL, 0x00404050);
                /* unset the 7111 gpio register -- I don't know what this does exactly */
@@ -774,7 +780,7 @@ static int std_callback(struct saa7146_dev *dev, struct saa7146_standard *standa
        } else {
                v4l2_std_id std = V4L2_STD_PAL_BG;
 
-               DEB_D(("VIDIOC_S_STD: setting mxb for PAL/NTSC/SECAM.\n"));
+               DEB_D("VIDIOC_S_STD: setting mxb for PAL/NTSC/SECAM\n");
                /* set the 7146 gpio register -- I don't know what this does exactly */
                saa7146_write(dev, GPIO_CTRL, 0x00404050);
                /* set the 7111 gpio register -- I don't know what this does exactly */
@@ -852,7 +858,7 @@ static struct saa7146_extension extension = {
 static int __init mxb_init_module(void)
 {
        if (saa7146_register_extension(&extension)) {
-               DEB_S(("failed to register extension.\n"));
+               DEB_S("failed to register extension\n");
                return -ENODEV;
        }
 
index 35f722a88f76c51e826101d0786d65fce7f7803e..6cd21cf91b44b8667015034dc5734882c91c5b4e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Driver for SiliconFile NOON010PC30 CIF (1/11") Image Sensor with ISP
  *
- * Copyright (C) 2010 Samsung Electronics
+ * Copyright (C) 2010 - 2011 Samsung Electronics Co., Ltd.
  * Contact: Sylwester Nawrocki, <s.nawrocki@samsung.com>
  *
  * Initial register configuration based on a driver authored by
@@ -10,7 +10,7 @@
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later vergsion.
+ * (at your option) any later version.
  */
 
 #include <linux/delay.h>
@@ -131,17 +131,23 @@ static const char * const noon010_supply_name[] = {
 
 struct noon010_info {
        struct v4l2_subdev sd;
+       struct media_pad pad;
        struct v4l2_ctrl_handler hdl;
-       const struct noon010pc30_platform_data *pdata;
+       struct regulator_bulk_data supply[NOON010_NUM_SUPPLIES];
+       u32 gpio_nreset;
+       u32 gpio_nstby;
+
+       /* Protects the struct members below */
+       struct mutex lock;
+
        const struct noon010_format *curr_fmt;
        const struct noon010_frmsize *curr_win;
+       unsigned int apply_new_cfg:1;
+       unsigned int streaming:1;
        unsigned int hflip:1;
        unsigned int vflip:1;
        unsigned int power:1;
        u8 i2c_reg_page;
-       struct regulator_bulk_data supply[NOON010_NUM_SUPPLIES];
-       u32 gpio_nreset;
-       u32 gpio_nstby;
 };
 
 struct i2c_regval {
@@ -292,8 +298,10 @@ static int noon010_power_ctrl(struct v4l2_subdev *sd, bool reset, bool sleep)
        u8 reg = sleep ? 0xF1 : 0xF0;
        int ret = 0;
 
-       if (reset)
+       if (reset) {
                ret = cam_i2c_write(sd, POWER_CTRL_REG, reg | 0x02);
+               udelay(20);
+       }
        if (!ret) {
                ret = cam_i2c_write(sd, POWER_CTRL_REG, reg);
                if (reset && !ret)
@@ -313,6 +321,7 @@ static int noon010_enable_autowhitebalance(struct v4l2_subdev *sd, int on)
        return ret;
 }
 
+/* Called with struct noon010_info.lock mutex held */
 static int noon010_set_flip(struct v4l2_subdev *sd, int hflip, int vflip)
 {
        struct noon010_info *info = to_noon010(sd);
@@ -340,21 +349,18 @@ static int noon010_set_flip(struct v4l2_subdev *sd, int hflip, int vflip)
 static int noon010_set_params(struct v4l2_subdev *sd)
 {
        struct noon010_info *info = to_noon010(sd);
-       int ret;
 
-       if (!info->curr_win)
-               return -EINVAL;
-
-       ret = cam_i2c_write(sd, VDO_CTL_REG(0), info->curr_win->vid_ctl1);
-
-       if (!ret && info->curr_fmt)
-               ret = cam_i2c_write(sd, ISP_CTL_REG(0),
-                               info->curr_fmt->ispctl1_reg);
-       return ret;
+       int ret = cam_i2c_write(sd, VDO_CTL_REG(0),
+                               info->curr_win->vid_ctl1);
+       if (ret)
+               return ret;
+       return cam_i2c_write(sd, ISP_CTL_REG(0),
+                            info->curr_fmt->ispctl1_reg);
 }
 
 /* Find nearest matching image pixel size. */
-static int noon010_try_frame_size(struct v4l2_mbus_framefmt *mf)
+static int noon010_try_frame_size(struct v4l2_mbus_framefmt *mf,
+                                 const struct noon010_frmsize **size)
 {
        unsigned int min_err = ~0;
        int i = ARRAY_SIZE(noon010_sizes);
@@ -374,11 +380,14 @@ static int noon010_try_frame_size(struct v4l2_mbus_framefmt *mf)
        if (match) {
                mf->width  = match->width;
                mf->height = match->height;
+               if (size)
+                       *size = match;
                return 0;
        }
        return -EINVAL;
 }
 
+/* Called with info.lock mutex held */
 static int power_enable(struct noon010_info *info)
 {
        int ret;
@@ -419,6 +428,7 @@ static int power_enable(struct noon010_info *info)
        return 0;
 }
 
+/* Called with info.lock mutex held */
 static int power_disable(struct noon010_info *info)
 {
        int ret;
@@ -448,147 +458,175 @@ static int power_disable(struct noon010_info *info)
 static int noon010_s_ctrl(struct v4l2_ctrl *ctrl)
 {
        struct v4l2_subdev *sd = to_sd(ctrl);
+       struct noon010_info *info = to_noon010(sd);
+       int ret = 0;
 
        v4l2_dbg(1, debug, sd, "%s: ctrl_id: %d, value: %d\n",
                 __func__, ctrl->id, ctrl->val);
 
+       mutex_lock(&info->lock);
+       /*
+        * If the device is not powered up by the host driver do
+        * not apply any controls to H/W at this time. Instead
+        * the controls will be restored right after power-up.
+        */
+       if (!info->power)
+               goto unlock;
+
        switch (ctrl->id) {
        case V4L2_CID_AUTO_WHITE_BALANCE:
-               return noon010_enable_autowhitebalance(sd, ctrl->val);
+               ret = noon010_enable_autowhitebalance(sd, ctrl->val);
+               break;
        case V4L2_CID_BLUE_BALANCE:
-               return cam_i2c_write(sd, MWB_BGAIN_REG, ctrl->val);
+               ret = cam_i2c_write(sd, MWB_BGAIN_REG, ctrl->val);
+               break;
        case V4L2_CID_RED_BALANCE:
-               return cam_i2c_write(sd, MWB_RGAIN_REG, ctrl->val);
+               ret =  cam_i2c_write(sd, MWB_RGAIN_REG, ctrl->val);
+               break;
        default:
-               return -EINVAL;
+               ret = -EINVAL;
        }
+unlock:
+       mutex_unlock(&info->lock);
+       return ret;
 }
 
-static int noon010_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
-                           enum v4l2_mbus_pixelcode *code)
+static int noon010_enum_mbus_code(struct v4l2_subdev *sd,
+                                 struct v4l2_subdev_fh *fh,
+                                 struct v4l2_subdev_mbus_code_enum *code)
 {
-       if (!code || index >= ARRAY_SIZE(noon010_formats))
+       if (code->index >= ARRAY_SIZE(noon010_formats))
                return -EINVAL;
 
-       *code = noon010_formats[index].code;
+       code->code = noon010_formats[code->index].code;
        return 0;
 }
 
-static int noon010_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
+static int noon010_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
+                          struct v4l2_subdev_format *fmt)
 {
        struct noon010_info *info = to_noon010(sd);
-       int ret;
-
-       if (!mf)
-               return -EINVAL;
+       struct v4l2_mbus_framefmt *mf;
 
-       if (!info->curr_win || !info->curr_fmt) {
-               ret = noon010_set_params(sd);
-               if (ret)
-                       return ret;
+       if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
+               if (fh) {
+                       mf = v4l2_subdev_get_try_format(fh, 0);
+                       fmt->format = *mf;
+               }
+               return 0;
        }
+       mf = &fmt->format;
 
-       mf->width       = info->curr_win->width;
-       mf->height      = info->curr_win->height;
-       mf->code        = info->curr_fmt->code;
-       mf->colorspace  = info->curr_fmt->colorspace;
-       mf->field       = V4L2_FIELD_NONE;
+       mutex_lock(&info->lock);
+       mf->width = info->curr_win->width;
+       mf->height = info->curr_win->height;
+       mf->code = info->curr_fmt->code;
+       mf->colorspace = info->curr_fmt->colorspace;
+       mf->field = V4L2_FIELD_NONE;
 
+       mutex_unlock(&info->lock);
        return 0;
 }
 
 /* Return nearest media bus frame format. */
-static const struct noon010_format *try_fmt(struct v4l2_subdev *sd,
+static const struct noon010_format *noon010_try_fmt(struct v4l2_subdev *sd,
                                            struct v4l2_mbus_framefmt *mf)
 {
        int i = ARRAY_SIZE(noon010_formats);
 
-       noon010_try_frame_size(mf);
-
-       while (i--)
+       while (--i)
                if (mf->code == noon010_formats[i].code)
                        break;
-
        mf->code = noon010_formats[i].code;
 
        return &noon010_formats[i];
 }
 
-static int noon010_try_fmt(struct v4l2_subdev *sd,
-                          struct v4l2_mbus_framefmt *mf)
-{
-       if (!sd || !mf)
-               return -EINVAL;
-
-       try_fmt(sd, mf);
-       return 0;
-}
-
-static int noon010_s_fmt(struct v4l2_subdev *sd,
-                        struct v4l2_mbus_framefmt *mf)
+static int noon010_set_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
+                          struct v4l2_subdev_format *fmt)
 {
        struct noon010_info *info = to_noon010(sd);
+       const struct noon010_frmsize *size = NULL;
+       const struct noon010_format *nf;
+       struct v4l2_mbus_framefmt *mf;
+       int ret = 0;
 
-       if (!sd || !mf)
-               return -EINVAL;
-
-       info->curr_fmt = try_fmt(sd, mf);
+       nf = noon010_try_fmt(sd, &fmt->format);
+       noon010_try_frame_size(&fmt->format, &size);
+       fmt->format.colorspace = V4L2_COLORSPACE_JPEG;
 
-       return noon010_set_params(sd);
+       if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
+               if (fh) {
+                       mf = v4l2_subdev_get_try_format(fh, 0);
+                       *mf = fmt->format;
+               }
+               return 0;
+       }
+       mutex_lock(&info->lock);
+       if (!info->streaming) {
+               info->apply_new_cfg = 1;
+               info->curr_fmt = nf;
+               info->curr_win = size;
+       } else {
+               ret = -EBUSY;
+       }
+       mutex_unlock(&info->lock);
+       return ret;
 }
 
+/* Called with struct noon010_info.lock mutex held */
 static int noon010_base_config(struct v4l2_subdev *sd)
 {
-       struct noon010_info *info = to_noon010(sd);
-       int ret;
-
-       ret = noon010_bulk_write_reg(sd, noon010_base_regs);
-       if (!ret) {
-               info->curr_fmt = &noon010_formats[0];
-               info->curr_win = &noon010_sizes[0];
+       int ret = noon010_bulk_write_reg(sd, noon010_base_regs);
+       if (!ret)
                ret = noon010_set_params(sd);
-       }
        if (!ret)
                ret = noon010_set_flip(sd, 1, 0);
-       if (!ret)
-               ret = noon010_power_ctrl(sd, false, false);
 
-       /* sync the handler and the registers state */
-       v4l2_ctrl_handler_setup(&to_noon010(sd)->hdl);
        return ret;
 }
 
 static int noon010_s_power(struct v4l2_subdev *sd, int on)
 {
        struct noon010_info *info = to_noon010(sd);
-       const struct noon010pc30_platform_data *pdata = info->pdata;
-       int ret = 0;
-
-       if (WARN(pdata == NULL, "No platform data!\n"))
-               return -ENOMEM;
+       int ret;
 
+       mutex_lock(&info->lock);
        if (on) {
                ret = power_enable(info);
-               if (ret)
-                       return ret;
-               ret = noon010_base_config(sd);
+               if (!ret)
+                       ret = noon010_base_config(sd);
        } else {
                noon010_power_ctrl(sd, false, true);
                ret = power_disable(info);
-               info->curr_win = NULL;
-               info->curr_fmt = NULL;
        }
+       mutex_unlock(&info->lock);
+
+       /* Restore the controls state */
+       if (!ret && on)
+               ret = v4l2_ctrl_handler_setup(&info->hdl);
 
        return ret;
 }
 
-static int noon010_g_chip_ident(struct v4l2_subdev *sd,
-                               struct v4l2_dbg_chip_ident *chip)
+static int noon010_s_stream(struct v4l2_subdev *sd, int on)
 {
-       struct i2c_client *client = v4l2_get_subdevdata(sd);
+       struct noon010_info *info = to_noon010(sd);
+       int ret = 0;
 
-       return v4l2_chip_ident_i2c_client(client, chip,
-                                         V4L2_IDENT_NOON010PC30, 0);
+       mutex_lock(&info->lock);
+       if (!info->streaming != !on) {
+               ret = noon010_power_ctrl(sd, false, !on);
+               if (!ret)
+                       info->streaming = on;
+       }
+       if (!ret && on && info->apply_new_cfg) {
+               ret = noon010_set_params(sd);
+               if (!ret)
+                       info->apply_new_cfg = 0;
+       }
+       mutex_unlock(&info->lock);
+       return ret;
 }
 
 static int noon010_log_status(struct v4l2_subdev *sd)
@@ -599,12 +637,27 @@ static int noon010_log_status(struct v4l2_subdev *sd)
        return 0;
 }
 
+static int noon010_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
+{
+       struct v4l2_mbus_framefmt *mf = v4l2_subdev_get_try_format(fh, 0);
+
+       mf->width = noon010_sizes[0].width;
+       mf->height = noon010_sizes[0].height;
+       mf->code = noon010_formats[0].code;
+       mf->colorspace = V4L2_COLORSPACE_JPEG;
+       mf->field = V4L2_FIELD_NONE;
+       return 0;
+}
+
+static const struct v4l2_subdev_internal_ops noon010_subdev_internal_ops = {
+       .open = noon010_open,
+};
+
 static const struct v4l2_ctrl_ops noon010_ctrl_ops = {
        .s_ctrl = noon010_s_ctrl,
 };
 
 static const struct v4l2_subdev_core_ops noon010_core_ops = {
-       .g_chip_ident   = noon010_g_chip_ident,
        .s_power        = noon010_s_power,
        .g_ctrl         = v4l2_subdev_g_ctrl,
        .s_ctrl         = v4l2_subdev_s_ctrl,
@@ -616,15 +669,19 @@ static const struct v4l2_subdev_core_ops noon010_core_ops = {
        .log_status     = noon010_log_status,
 };
 
-static const struct v4l2_subdev_video_ops noon010_video_ops = {
-       .g_mbus_fmt     = noon010_g_fmt,
-       .s_mbus_fmt     = noon010_s_fmt,
-       .try_mbus_fmt   = noon010_try_fmt,
-       .enum_mbus_fmt  = noon010_enum_fmt,
+static struct v4l2_subdev_pad_ops noon010_pad_ops = {
+       .enum_mbus_code = noon010_enum_mbus_code,
+       .get_fmt        = noon010_get_fmt,
+       .set_fmt        = noon010_set_fmt,
+};
+
+static struct v4l2_subdev_video_ops noon010_video_ops = {
+       .s_stream       = noon010_s_stream,
 };
 
 static const struct v4l2_subdev_ops noon010_ops = {
        .core   = &noon010_core_ops,
+       .pad    = &noon010_pad_ops,
        .video  = &noon010_video_ops,
 };
 
@@ -665,10 +722,14 @@ static int noon010_probe(struct i2c_client *client,
        if (!info)
                return -ENOMEM;
 
+       mutex_init(&info->lock);
        sd = &info->sd;
        strlcpy(sd->name, MODULE_NAME, sizeof(sd->name));
        v4l2_i2c_subdev_init(sd, client, &noon010_ops);
 
+       sd->internal_ops = &noon010_subdev_internal_ops;
+       sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+
        v4l2_ctrl_handler_init(&info->hdl, 3);
 
        v4l2_ctrl_new_std(&info->hdl, &noon010_ctrl_ops,
@@ -684,10 +745,11 @@ static int noon010_probe(struct i2c_client *client,
        if (ret)
                goto np_err;
 
-       info->pdata             = client->dev.platform_data;
        info->i2c_reg_page      = -1;
        info->gpio_nreset       = -EINVAL;
        info->gpio_nstby        = -EINVAL;
+       info->curr_fmt          = &noon010_formats[0];
+       info->curr_win          = &noon010_sizes[0];
 
        if (gpio_is_valid(pdata->gpio_nreset)) {
                ret = gpio_request(pdata->gpio_nreset, "NOON010PC30 NRST");
@@ -719,11 +781,17 @@ static int noon010_probe(struct i2c_client *client,
        if (ret)
                goto np_reg_err;
 
+       info->pad.flags = MEDIA_PAD_FL_SOURCE;
+       sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_SENSOR;
+       ret = media_entity_init(&sd->entity, 1, &info->pad, 0);
+       if (ret < 0)
+               goto np_me_err;
+
        ret = noon010_detect(client, info);
        if (!ret)
                return 0;
 
-       /* the sensor detection failed */
+np_me_err:
        regulator_bulk_free(NOON010_NUM_SUPPLIES, info->supply);
 np_reg_err:
        if (gpio_is_valid(info->gpio_nstby))
@@ -754,6 +822,7 @@ static int noon010_remove(struct i2c_client *client)
        if (gpio_is_valid(info->gpio_nstby))
                gpio_free(info->gpio_nstby);
 
+       media_entity_cleanup(&sd->entity);
        kfree(info);
        return 0;
 }
index b3a5ecdb33ac00cac5dc3e94ed5cceaabe225655..30d8896bb710db6f4979f11ef6d70476a2896f93 100644 (file)
@@ -400,7 +400,6 @@ static int omapvid_setup_overlay(struct omap_vout_device *vout,
 
        ovl->get_overlay_info(ovl, &info);
        info.paddr = addr;
-       info.vaddr = NULL;
        info.width = cropwidth;
        info.height = cropheight;
        info.color_mode = vout->dss_mode;
@@ -1165,12 +1164,17 @@ static int vidioc_try_fmt_vid_overlay(struct file *file, void *fh,
 {
        int ret = 0;
        struct omap_vout_device *vout = fh;
+       struct omap_overlay *ovl;
+       struct omapvideo_info *ovid;
        struct v4l2_window *win = &f->fmt.win;
 
+       ovid = &vout->vid_info;
+       ovl = ovid->overlays[0];
+
        ret = omap_vout_try_window(&vout->fbuf, win);
 
        if (!ret) {
-               if (vout->vid == OMAP_VIDEO1)
+               if ((ovl->caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
                        win->global_alpha = 255;
                else
                        win->global_alpha = f->fmt.win.global_alpha;
@@ -1194,8 +1198,8 @@ static int vidioc_s_fmt_vid_overlay(struct file *file, void *fh,
 
        ret = omap_vout_new_window(&vout->crop, &vout->win, &vout->fbuf, win);
        if (!ret) {
-               /* Video1 plane does not support global alpha */
-               if (ovl->id == OMAP_DSS_VIDEO1)
+               /* Video1 plane does not support global alpha on OMAP3 */
+               if ((ovl->caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
                        vout->win.global_alpha = 255;
                else
                        vout->win.global_alpha = f->fmt.win.global_alpha;
@@ -1788,7 +1792,9 @@ static int vidioc_s_fbuf(struct file *file, void *fh,
        if (ovl->manager && ovl->manager->get_manager_info &&
                        ovl->manager->set_manager_info) {
                ovl->manager->get_manager_info(ovl->manager, &info);
-               info.alpha_enabled = enable;
+               /* enable this only if there is no zorder cap */
+               if ((ovl->caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
+                       info.partial_alpha_enabled = enable;
                if (ovl->manager->set_manager_info(ovl->manager, &info))
                        return -EINVAL;
        }
@@ -1820,7 +1826,7 @@ static int vidioc_g_fbuf(struct file *file, void *fh,
        }
        if (ovl->manager && ovl->manager->get_manager_info) {
                ovl->manager->get_manager_info(ovl->manager, &info);
-               if (info.alpha_enabled)
+               if (info.partial_alpha_enabled)
                        a->flags |= V4L2_FBUF_FLAG_LOCAL_ALPHA;
        }
 
index b1b344774ae78f72971b2d14a4200f9cd49f0fc0..e8847e79e31aefc236a279d0b93c2b1953131567 100644 (file)
@@ -1,8 +1,6 @@
 # Makefile for OMAP3 ISP driver
 
-ifdef CONFIG_VIDEO_OMAP3_DEBUG
-EXTRA_CFLAGS += -DDEBUG
-endif
+ccflags-$(CONFIG_VIDEO_OMAP3_DEBUG) += -DDEBUG
 
 omap3-isp-objs += \
        isp.o ispqueue.o ispvideo.o \
index 5cea2bbd7014d463aa2e3959af2a0491b0e82136..678e1252047a7092b9471636d76e4a41270cdd6b 100644 (file)
 #include "isph3a.h"
 #include "isphist.h"
 
+/*
+ * this is provided as an interim solution until omap3isp doesn't need
+ * any omap-specific iommu API
+ */
+#define to_iommu(dev)                                                  \
+       (struct omap_iommu *)platform_get_drvdata(to_platform_device(dev))
+
 static unsigned int autoidle;
 module_param(autoidle, int, 0444);
 MODULE_PARM_DESC(autoidle, "Enable OMAP3ISP AUTOIDLE support");
@@ -732,7 +739,7 @@ static int isp_pipeline_enable(struct isp_pipeline *pipe,
        struct media_pad *pad;
        struct v4l2_subdev *subdev;
        unsigned long flags;
-       int ret = 0;
+       int ret;
 
        spin_lock_irqsave(&pipe->lock, flags);
        pipe->state &= ~(ISP_PIPELINE_IDLE_INPUT | ISP_PIPELINE_IDLE_OUTPUT);
@@ -756,7 +763,7 @@ static int isp_pipeline_enable(struct isp_pipeline *pipe,
 
                ret = v4l2_subdev_call(subdev, video, s_stream, mode);
                if (ret < 0 && ret != -ENOIOCTLCMD)
-                       break;
+                       return ret;
 
                if (subdev == &isp->isp_ccdc.subdev) {
                        v4l2_subdev_call(&isp->isp_aewb.subdev, video,
@@ -777,7 +784,7 @@ static int isp_pipeline_enable(struct isp_pipeline *pipe,
        if (pipe->do_propagation && mode == ISP_PIPELINE_STREAM_SINGLESHOT)
                atomic_inc(&pipe->frame_number);
 
-       return ret;
+       return 0;
 }
 
 static int isp_pipeline_wait_resizer(struct isp_device *isp)
@@ -1108,7 +1115,7 @@ static void isp_save_ctx(struct isp_device *isp)
 {
        isp_save_context(isp, isp_reg_list);
        if (isp->iommu)
-               iommu_save_ctx(isp->iommu);
+               omap_iommu_save_ctx(isp->iommu);
 }
 
 /*
@@ -1122,7 +1129,7 @@ static void isp_restore_ctx(struct isp_device *isp)
 {
        isp_restore_context(isp, isp_reg_list);
        if (isp->iommu)
-               iommu_restore_ctx(isp->iommu);
+               omap_iommu_restore_ctx(isp->iommu);
        omap3isp_ccdc_restore_context(isp);
        omap3isp_preview_restore_context(isp);
 }
@@ -1975,7 +1982,8 @@ static int isp_remove(struct platform_device *pdev)
        isp_cleanup_modules(isp);
 
        omap3isp_get(isp);
-       iommu_put(isp->iommu);
+       iommu_detach_device(isp->domain, isp->iommu_dev);
+       iommu_domain_free(isp->domain);
        omap3isp_put(isp);
 
        free_irq(isp->irq_num, isp);
@@ -2123,25 +2131,41 @@ static int isp_probe(struct platform_device *pdev)
        }
 
        /* IOMMU */
-       isp->iommu = iommu_get("isp");
-       if (IS_ERR_OR_NULL(isp->iommu)) {
-               isp->iommu = NULL;
+       isp->iommu_dev = omap_find_iommu_device("isp");
+       if (!isp->iommu_dev) {
+               dev_err(isp->dev, "omap_find_iommu_device failed\n");
                ret = -ENODEV;
                goto error_isp;
        }
 
+       /* to be removed once iommu migration is complete */
+       isp->iommu = to_iommu(isp->iommu_dev);
+
+       isp->domain = iommu_domain_alloc(pdev->dev.bus);
+       if (!isp->domain) {
+               dev_err(isp->dev, "can't alloc iommu domain\n");
+               ret = -ENOMEM;
+               goto error_isp;
+       }
+
+       ret = iommu_attach_device(isp->domain, isp->iommu_dev);
+       if (ret) {
+               dev_err(&pdev->dev, "can't attach iommu device: %d\n", ret);
+               goto free_domain;
+       }
+
        /* Interrupt */
        isp->irq_num = platform_get_irq(pdev, 0);
        if (isp->irq_num <= 0) {
                dev_err(isp->dev, "No IRQ resource\n");
                ret = -ENODEV;
-               goto error_isp;
+               goto detach_dev;
        }
 
        if (request_irq(isp->irq_num, isp_isr, IRQF_SHARED, "OMAP3 ISP", isp)) {
                dev_err(isp->dev, "Unable to request IRQ\n");
                ret = -EINVAL;
-               goto error_isp;
+               goto detach_dev;
        }
 
        /* Entities */
@@ -2162,8 +2186,11 @@ error_modules:
        isp_cleanup_modules(isp);
 error_irq:
        free_irq(isp->irq_num, isp);
+detach_dev:
+       iommu_detach_device(isp->domain, isp->iommu_dev);
+free_domain:
+       iommu_domain_free(isp->domain);
 error_isp:
-       iommu_put(isp->iommu);
        omap3isp_put(isp);
 error:
        isp_put_clocks(isp);
index 529e582ef94875488a8b8ff239183a2f9054ca42..705946ef4d6027ca6f2e966149868e7a80b64d0e 100644 (file)
 #ifndef OMAP3_ISP_CORE_H
 #define OMAP3_ISP_CORE_H
 
+#include <media/omap3isp.h>
 #include <media/v4l2-device.h>
 #include <linux/device.h>
 #include <linux/io.h>
 #include <linux/platform_device.h>
 #include <linux/wait.h>
+#include <linux/iommu.h>
 #include <plat/iommu.h>
 #include <plat/iovmm.h>
 
@@ -94,14 +96,6 @@ enum isp_subclk_resource {
        OMAP3_ISP_SUBCLK_RESIZER        = (1 << 4),
 };
 
-enum isp_interface_type {
-       ISP_INTERFACE_PARALLEL,
-       ISP_INTERFACE_CSI2A_PHY2,
-       ISP_INTERFACE_CCP2B_PHY1,
-       ISP_INTERFACE_CCP2B_PHY2,
-       ISP_INTERFACE_CSI2C_PHY1,
-};
-
 /* ISP: OMAP 34xx ES 1.0 */
 #define ISP_REVISION_1_0               0x10
 /* ISP2: OMAP 34xx ES 2.0, 2.1 and 3.0 */
@@ -130,82 +124,6 @@ struct isp_reg {
        u32 val;
 };
 
-/**
- * struct isp_parallel_platform_data - Parallel interface platform data
- * @data_lane_shift: Data lane shifter
- *             0 - CAMEXT[13:0] -> CAM[13:0]
- *             1 - CAMEXT[13:2] -> CAM[11:0]
- *             2 - CAMEXT[13:4] -> CAM[9:0]
- *             3 - CAMEXT[13:6] -> CAM[7:0]
- * @clk_pol: Pixel clock polarity
- *             0 - Non Inverted, 1 - Inverted
- * @hs_pol: Horizontal synchronization polarity
- *             0 - Active high, 1 - Active low
- * @vs_pol: Vertical synchronization polarity
- *             0 - Active high, 1 - Active low
- * @bridge: CCDC Bridge input control
- *             ISPCTRL_PAR_BRIDGE_DISABLE - Disable
- *             ISPCTRL_PAR_BRIDGE_LENDIAN - Little endian
- *             ISPCTRL_PAR_BRIDGE_BENDIAN - Big endian
- */
-struct isp_parallel_platform_data {
-       unsigned int data_lane_shift:2;
-       unsigned int clk_pol:1;
-       unsigned int hs_pol:1;
-       unsigned int vs_pol:1;
-       unsigned int bridge:4;
-};
-
-/**
- * struct isp_ccp2_platform_data - CCP2 interface platform data
- * @strobe_clk_pol: Strobe/clock polarity
- *             0 - Non Inverted, 1 - Inverted
- * @crc: Enable the cyclic redundancy check
- * @ccp2_mode: Enable CCP2 compatibility mode
- *             0 - MIPI-CSI1 mode, 1 - CCP2 mode
- * @phy_layer: Physical layer selection
- *             ISPCCP2_CTRL_PHY_SEL_CLOCK - Data/clock physical layer
- *             ISPCCP2_CTRL_PHY_SEL_STROBE - Data/strobe physical layer
- * @vpclk_div: Video port output clock control
- */
-struct isp_ccp2_platform_data {
-       unsigned int strobe_clk_pol:1;
-       unsigned int crc:1;
-       unsigned int ccp2_mode:1;
-       unsigned int phy_layer:1;
-       unsigned int vpclk_div:2;
-};
-
-/**
- * struct isp_csi2_platform_data - CSI2 interface platform data
- * @crc: Enable the cyclic redundancy check
- * @vpclk_div: Video port output clock control
- */
-struct isp_csi2_platform_data {
-       unsigned crc:1;
-       unsigned vpclk_div:2;
-};
-
-struct isp_subdev_i2c_board_info {
-       struct i2c_board_info *board_info;
-       int i2c_adapter_id;
-};
-
-struct isp_v4l2_subdevs_group {
-       struct isp_subdev_i2c_board_info *subdevs;
-       enum isp_interface_type interface;
-       union {
-               struct isp_parallel_platform_data parallel;
-               struct isp_ccp2_platform_data ccp2;
-               struct isp_csi2_platform_data csi2;
-       } bus; /* gcc < 4.6.0 chokes on anonymous union initializers */
-};
-
-struct isp_platform_data {
-       struct isp_v4l2_subdevs_group *subdevs;
-       void (*set_constraints)(struct isp_device *isp, bool enable);
-};
-
 struct isp_platform_callback {
        u32 (*set_xclk)(struct isp_device *isp, u32 xclk, u8 xclksel);
        int (*csiphy_config)(struct isp_csiphy *phy,
@@ -294,7 +212,9 @@ struct isp_device {
        unsigned int sbl_resources;
        unsigned int subclk_resources;
 
-       struct iommu *iommu;
+       struct omap_iommu *iommu;
+       struct iommu_domain *domain;
+       struct device *iommu_dev;
 
        struct isp_platform_callback platform_cb;
 };
index 80796eb0c53ec020f50afe5acb7d75d7debbe234..253fdcce2df29c33ececf6ea76abd280a104d33b 100644 (file)
@@ -366,7 +366,7 @@ static void ccdc_lsc_free_request(struct isp_ccdc_device *ccdc,
                dma_unmap_sg(isp->dev, req->iovm->sgt->sgl,
                             req->iovm->sgt->nents, DMA_TO_DEVICE);
        if (req->table)
-               iommu_vfree(isp->iommu, req->table);
+               omap_iommu_vfree(isp->domain, isp->iommu, req->table);
        kfree(req);
 }
 
@@ -438,15 +438,15 @@ static int ccdc_lsc_config(struct isp_ccdc_device *ccdc,
 
                req->enable = 1;
 
-               req->table = iommu_vmalloc(isp->iommu, 0, req->config.size,
-                                          IOMMU_FLAG);
+               req->table = omap_iommu_vmalloc(isp->domain, isp->iommu, 0,
+                                       req->config.size, IOMMU_FLAG);
                if (IS_ERR_VALUE(req->table)) {
                        req->table = 0;
                        ret = -ENOMEM;
                        goto done;
                }
 
-               req->iovm = find_iovm_area(isp->iommu, req->table);
+               req->iovm = omap_find_iovm_area(isp->iommu, req->table);
                if (req->iovm == NULL) {
                        ret = -ENOMEM;
                        goto done;
@@ -462,7 +462,7 @@ static int ccdc_lsc_config(struct isp_ccdc_device *ccdc,
                dma_sync_sg_for_cpu(isp->dev, req->iovm->sgt->sgl,
                                    req->iovm->sgt->nents, DMA_TO_DEVICE);
 
-               table = da_to_va(isp->iommu, req->table);
+               table = omap_da_to_va(isp->iommu, req->table);
                if (copy_from_user(table, config->lsc, req->config.size)) {
                        ret = -EFAULT;
                        goto done;
@@ -731,18 +731,19 @@ static int ccdc_config(struct isp_ccdc_device *ccdc,
 
                        /*
                         * table_new must be 64-bytes aligned, but it's
-                        * already done by iommu_vmalloc().
+                        * already done by omap_iommu_vmalloc().
                         */
                        size = ccdc->fpc.fpnum * 4;
-                       table_new = iommu_vmalloc(isp->iommu, 0, size,
-                                                 IOMMU_FLAG);
+                       table_new = omap_iommu_vmalloc(isp->domain, isp->iommu,
+                                                       0, size, IOMMU_FLAG);
                        if (IS_ERR_VALUE(table_new))
                                return -ENOMEM;
 
-                       if (copy_from_user(da_to_va(isp->iommu, table_new),
+                       if (copy_from_user(omap_da_to_va(isp->iommu, table_new),
                                           (__force void __user *)
                                           ccdc->fpc.fpcaddr, size)) {
-                               iommu_vfree(isp->iommu, table_new);
+                               omap_iommu_vfree(isp->domain, isp->iommu,
+                                                               table_new);
                                return -EFAULT;
                        }
 
@@ -752,7 +753,7 @@ static int ccdc_config(struct isp_ccdc_device *ccdc,
 
                ccdc_configure_fpc(ccdc);
                if (table_old != 0)
-                       iommu_vfree(isp->iommu, table_old);
+                       omap_iommu_vfree(isp->domain, isp->iommu, table_old);
        }
 
        return ccdc_lsc_config(ccdc, ccdc_struct);
@@ -1405,11 +1406,14 @@ static int __ccdc_handle_stopping(struct isp_ccdc_device *ccdc, u32 event)
 
 static void ccdc_hs_vs_isr(struct isp_ccdc_device *ccdc)
 {
+       struct isp_pipeline *pipe =
+               to_isp_pipeline(&ccdc->video_out.video.entity);
        struct video_device *vdev = &ccdc->subdev.devnode;
        struct v4l2_event event;
 
        memset(&event, 0, sizeof(event));
-       event.type = V4L2_EVENT_OMAP3ISP_HS_VS;
+       event.type = V4L2_EVENT_FRAME_SYNC;
+       event.u.frame_sync.frame_sequence = atomic_read(&pipe->frame_number);
 
        v4l2_event_queue(vdev, &event);
 }
@@ -1691,7 +1695,11 @@ static long ccdc_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
 static int ccdc_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
                                struct v4l2_event_subscription *sub)
 {
-       if (sub->type != V4L2_EVENT_OMAP3ISP_HS_VS)
+       if (sub->type != V4L2_EVENT_FRAME_SYNC)
+               return -EINVAL;
+
+       /* line number is zero at frame start */
+       if (sub->id != 0)
                return -EINVAL;
 
        return v4l2_event_subscribe(fh, sub, OMAP3ISP_CCDC_NEVENTS);
@@ -2287,5 +2295,5 @@ void omap3isp_ccdc_cleanup(struct isp_device *isp)
        ccdc_lsc_free_queue(ccdc, &ccdc->lsc.free_queue);
 
        if (ccdc->fpc.fpcaddr != 0)
-               iommu_vfree(isp->iommu, ccdc->fpc.fpcaddr);
+               omap_iommu_vfree(isp->domain, isp->iommu, ccdc->fpc.fpcaddr);
 }
index ec9e395f3339dd0ae3f567620574a37149df4eff..fa1d09b0ad9891eba70467969e6327c190a7dd7a 100644 (file)
@@ -243,9 +243,9 @@ static int ccp2_phyif_config(struct isp_ccp2_device *ccp2,
 
        val = isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCP2, ISPCCP2_CTRL);
        if (!(val & ISPCCP2_CTRL_MODE)) {
-               if (pdata->ccp2_mode)
+               if (pdata->ccp2_mode == ISP_CCP2_MODE_CCP2)
                        dev_warn(isp->dev, "OMAP3 CCP2 bus not available\n");
-               if (pdata->phy_layer == ISPCCP2_CTRL_PHY_SEL_STROBE)
+               if (pdata->phy_layer == ISP_CCP2_PHY_DATA_STROBE)
                        /* Strobe mode requires CCP2 */
                        return -EIO;
        }
index 9c317148205f82a73cb774607ca0a2ea412d2ea6..9bebb1e57aab0dac17e8bccbb6e55cf1566661df 100644 (file)
@@ -867,6 +867,10 @@ int omap3isp_video_queue_qbuf(struct isp_video_queue *queue,
        if (buf->state != ISP_BUF_STATE_IDLE)
                goto done;
 
+       if (vbuf->memory == V4L2_MEMORY_USERPTR &&
+           vbuf->length < buf->vbuf.length)
+               goto done;
+
        if (vbuf->memory == V4L2_MEMORY_USERPTR &&
            vbuf->m.userptr != buf->vbuf.m.userptr) {
                isp_video_buffer_cleanup(buf);
index 808065948ac15c56bd07d05389933937c98ed4d8..732905552261af9d27a020fe2e61cf015ddbb301 100644 (file)
@@ -366,7 +366,8 @@ static void isp_stat_bufs_free(struct ispstat *stat)
                                dma_unmap_sg(isp->dev, buf->iovm->sgt->sgl,
                                             buf->iovm->sgt->nents,
                                             DMA_FROM_DEVICE);
-                       iommu_vfree(isp->iommu, buf->iommu_addr);
+                       omap_iommu_vfree(isp->domain, isp->iommu,
+                                                       buf->iommu_addr);
                } else {
                        if (!buf->virt_addr)
                                continue;
@@ -399,8 +400,8 @@ static int isp_stat_bufs_alloc_iommu(struct ispstat *stat, unsigned int size)
                struct iovm_struct *iovm;
 
                WARN_ON(buf->dma_addr);
-               buf->iommu_addr = iommu_vmalloc(isp->iommu, 0, size,
-                                               IOMMU_FLAG);
+               buf->iommu_addr = omap_iommu_vmalloc(isp->domain, isp->iommu, 0,
+                                                       size, IOMMU_FLAG);
                if (IS_ERR((void *)buf->iommu_addr)) {
                        dev_err(stat->isp->dev,
                                 "%s: Can't acquire memory for "
@@ -409,7 +410,7 @@ static int isp_stat_bufs_alloc_iommu(struct ispstat *stat, unsigned int size)
                        return -ENOMEM;
                }
 
-               iovm = find_iovm_area(isp->iommu, buf->iommu_addr);
+               iovm = omap_find_iovm_area(isp->iommu, buf->iommu_addr);
                if (!iovm ||
                    !dma_map_sg(isp->dev, iovm->sgt->sgl, iovm->sgt->nents,
                                DMA_FROM_DEVICE)) {
@@ -418,7 +419,7 @@ static int isp_stat_bufs_alloc_iommu(struct ispstat *stat, unsigned int size)
                }
                buf->iovm = iovm;
 
-               buf->virt_addr = da_to_va(stat->isp->iommu,
+               buf->virt_addr = omap_da_to_va(stat->isp->iommu,
                                          (u32)buf->iommu_addr);
                buf->empty = 1;
                dev_dbg(stat->isp->dev, "%s: buffer[%d] allocated."
index fd965adfd5970316d4d763af4e4e311d5401d54d..0cb8a9f9d675ddbd9e460b2a8143ea81fb47a105 100644 (file)
@@ -278,7 +278,8 @@ isp_video_far_end(struct isp_video *video)
  * limits reported by every block in the pipeline.
  *
  * Return 0 if all formats match, or -EPIPE if at least one link is found with
- * different formats on its two ends.
+ * different formats on its two ends or if the pipeline doesn't start with a
+ * video source (either a subdev with no input pad, or a non-subdev entity).
  */
 static int isp_video_validate_pipeline(struct isp_pipeline *pipe)
 {
@@ -329,10 +330,15 @@ static int isp_video_validate_pipeline(struct isp_pipeline *pipe)
                 * in the middle of it. */
                shifter_link = subdev == &isp->isp_ccdc.subdev;
 
-               /* Retrieve the source format */
+               /* Retrieve the source format. Return an error if no source
+                * entity can be found, and stop checking the pipeline if the
+                * source entity isn't a subdev.
+                */
                pad = media_entity_remote_source(pad);
-               if (pad == NULL ||
-                   media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+               if (pad == NULL)
+                       return -EPIPE;
+
+               if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
                        break;
 
                subdev = media_entity_to_v4l2_subdev(pad->entity);
@@ -446,7 +452,7 @@ ispmmu_vmap(struct isp_device *isp, const struct scatterlist *sglist, int sglen)
        sgt->nents = sglen;
        sgt->orig_nents = sglen;
 
-       da = iommu_vmap(isp->iommu, 0, sgt, IOMMU_FLAG);
+       da = omap_iommu_vmap(isp->domain, isp->iommu, 0, sgt, IOMMU_FLAG);
        if (IS_ERR_VALUE(da))
                kfree(sgt);
 
@@ -462,7 +468,7 @@ static void ispmmu_vunmap(struct isp_device *isp, dma_addr_t da)
 {
        struct sg_table *sgt;
 
-       sgt = iommu_vunmap(isp->iommu, (u32)da);
+       sgt = omap_iommu_vunmap(isp->domain, isp->iommu, (u32)da);
        kfree(sgt);
 }
 
@@ -1050,6 +1056,14 @@ error:
                if (video->isp->pdata->set_constraints)
                        video->isp->pdata->set_constraints(video->isp, false);
                media_entity_pipeline_stop(&video->video.entity);
+               /* The DMA queue must be emptied here, otherwise CCDC interrupts
+                * that will get triggered the next time the CCDC is powered up
+                * will try to access buffers that might have been freed but
+                * still present in the DMA queue. This can easily get triggered
+                * if the above omap3isp_pipeline_set_stream() call fails on a
+                * system with a free-running sensor.
+                */
+               INIT_LIST_HEAD(&video->dmaqueue);
                video->queue = NULL;
        }
 
index de2fc14f043b8b4a9ab79bf35b0a5eee189177e2..c17f37d964ad00460700abcc3a4105e3f84605d9 100644 (file)
@@ -16,7 +16,7 @@ pvrusb2-objs  := pvrusb2-i2c-core.o \
 
 obj-$(CONFIG_VIDEO_PVRUSB2) += pvrusb2.o
 
-EXTRA_CFLAGS += -Idrivers/media/video
-EXTRA_CFLAGS += -Idrivers/media/common/tuners
-EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
-EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
+ccflags-y += -Idrivers/media/video
+ccflags-y += -Idrivers/media/common/tuners
+ccflags-y += -Idrivers/media/dvb/dvb-core
+ccflags-y += -Idrivers/media/dvb/frontends
index e98d38212791034cdac61d11a24dec00ca636297..5a6f24d1246d459edbd69cefde0a690048ff8e16 100644 (file)
@@ -2993,6 +2993,13 @@ static void pvr2_subdev_set_control(struct pvr2_hdw *hdw, int id,
                pvr2_subdev_set_control(hdw, id, #lab, (hdw)->lab##_val); \
        }
 
+int pvr2_hdw_get_detected_std(struct pvr2_hdw *hdw, v4l2_std_id *std)
+{
+       v4l2_device_call_all(&hdw->v4l2_dev, 0,
+                            video, querystd, std);
+       return 0;
+}
+
 /* Execute whatever commands are required to update the state of all the
    sub-devices so that they match our current control values. */
 static void pvr2_subdev_update(struct pvr2_hdw *hdw)
index d7753ae9ff46bed8b0c91bf438a9e9d3ff39120f..66546580b17d8d06f3521fb9096ce584207535d5 100644 (file)
@@ -214,6 +214,9 @@ struct pvr2_stream *pvr2_hdw_get_video_stream(struct pvr2_hdw *);
 int pvr2_hdw_get_stdenum_value(struct pvr2_hdw *hdw,struct v4l2_standard *std,
                               unsigned int idx);
 
+/* Get the detected video standard */
+int pvr2_hdw_get_detected_std(struct pvr2_hdw *hdw, v4l2_std_id *std);
+
 /* Enable / disable retrieval of CPU firmware or prom contents.  This must
    be enabled before pvr2_hdw_cpufw_get() will function.  Note that doing
    this may prevent the device from running (and leaving this mode may
index e27f8ab76966ccdebd9f1a11338b0006ea759a84..ce7ac4595276b8a86da9e8a4641f5b1207e31bc6 100644 (file)
@@ -227,6 +227,14 @@ static long pvr2_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
                break;
        }
 
+       case VIDIOC_QUERYSTD:
+       {
+               v4l2_std_id *std = arg;
+               *std = V4L2_STD_ALL;
+               ret = pvr2_hdw_get_detected_std(hdw, std);
+               break;
+       }
+
        case VIDIOC_G_STD:
        {
                int val = 0;
index 51ca3589b1b5987b7a19284613d8bc894376e982..360be226718de37f39bcb02d4c66d1a1b1532169 100644 (file)
@@ -745,7 +745,7 @@ static int pwc_video_mmap(struct file *file, struct vm_area_struct *vma)
 /* Videobuf2 operations */
 
 static int queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
-                               unsigned int *nplanes, unsigned long sizes[],
+                               unsigned int *nplanes, unsigned int sizes[],
                                void *alloc_ctxs[])
 {
        struct pwc_device *pdev = vb2_get_drv_priv(vq);
@@ -816,7 +816,7 @@ static void buffer_queue(struct vb2_buffer *vb)
        spin_unlock_irqrestore(&pdev->queued_bufs_lock, flags);
 }
 
-static int start_streaming(struct vb2_queue *vq)
+static int start_streaming(struct vb2_queue *vq, unsigned int count)
 {
        struct pwc_device *pdev = vb2_get_drv_priv(vq);
 
index 8c70e64444e7b38bc03b00fdafb36d7bd43d21e7..a10ff6b64acf21a552ae4bd58a686d7cfb27de93 100644 (file)
@@ -83,6 +83,7 @@ static const struct v4l2_ctrl_config pwc_contour_cfg = {
        .id     = PWC_CID_CUSTOM(contour),
        .type   = V4L2_CTRL_TYPE_INTEGER,
        .name   = "Contour",
+       .flags  = V4L2_CTRL_FLAG_SLIDER,
        .min    = 0,
        .max    = 63,
        .step   = 1,
@@ -206,8 +207,7 @@ int pwc_init_controls(struct pwc_device *pdev)
        pdev->blue_balance = v4l2_ctrl_new_std(hdl, &pwc_ctrl_ops,
                                V4L2_CID_BLUE_BALANCE, 0, 255, 1, def);
 
-       v4l2_ctrl_auto_cluster(3, &pdev->auto_white_balance, awb_manual,
-                              pdev->auto_white_balance->cur.val == awb_auto);
+       v4l2_ctrl_auto_cluster(3, &pdev->auto_white_balance, awb_manual, true);
 
        /* autogain, gain */
        r = pwc_get_u8_ctrl(pdev, GET_LUM_CTL, AGC_MODE_FORMATTER, &def);
@@ -331,12 +331,12 @@ int pwc_init_controls(struct pwc_device *pdev)
        pdev->restore_user = v4l2_ctrl_new_custom(hdl, &pwc_restore_user_cfg,
                                                  NULL);
        if (pdev->restore_user)
-               pdev->restore_user->flags = V4L2_CTRL_FLAG_UPDATE;
+               pdev->restore_user->flags |= V4L2_CTRL_FLAG_UPDATE;
        pdev->restore_factory = v4l2_ctrl_new_custom(hdl,
                                                     &pwc_restore_factory_cfg,
                                                     NULL);
        if (pdev->restore_factory)
-               pdev->restore_factory->flags = V4L2_CTRL_FLAG_UPDATE;
+               pdev->restore_factory->flags |= V4L2_CTRL_FLAG_UPDATE;
 
        if (!(pdev->features & FEATURE_MOTOR_PANTILT))
                return hdl->error;
@@ -563,8 +563,10 @@ static int pwc_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
 
        switch (ctrl->id) {
        case V4L2_CID_AUTO_WHITE_BALANCE:
-               if (pdev->color_bal_valid && time_before(jiffies,
-                               pdev->last_color_bal_update + HZ / 4)) {
+               if (pdev->color_bal_valid &&
+                       (pdev->auto_white_balance->val != awb_auto ||
+                        time_before(jiffies,
+                               pdev->last_color_bal_update + HZ / 4))) {
                        pdev->red_balance->val  = pdev->last_red_balance;
                        pdev->blue_balance->val = pdev->last_blue_balance;
                        break;
@@ -630,7 +632,7 @@ leave:
 
 static int pwc_set_awb(struct pwc_device *pdev)
 {
-       int ret = 0;
+       int ret;
 
        if (pdev->auto_white_balance->is_new) {
                ret = pwc_set_u8_ctrl(pdev, SET_CHROM_CTL,
@@ -639,52 +641,34 @@ static int pwc_set_awb(struct pwc_device *pdev)
                if (ret)
                        return ret;
 
-               /* Update val when coming from auto or going to a preset */
-               if (pdev->red_balance->is_volatile ||
-                   pdev->auto_white_balance->val == awb_indoor ||
-                   pdev->auto_white_balance->val == awb_outdoor ||
-                   pdev->auto_white_balance->val == awb_fl) {
-                       if (!pdev->red_balance->is_new)
-                               pwc_get_u8_ctrl(pdev, GET_STATUS_CTL,
-                                       READ_RED_GAIN_FORMATTER,
-                                       &pdev->red_balance->val);
-                       if (!pdev->blue_balance->is_new)
-                               pwc_get_u8_ctrl(pdev, GET_STATUS_CTL,
-                                       READ_BLUE_GAIN_FORMATTER,
-                                       &pdev->blue_balance->val);
-               }
-               if (pdev->auto_white_balance->val == awb_auto) {
-                       pdev->red_balance->is_volatile = true;
-                       pdev->blue_balance->is_volatile = true;
+               if (pdev->auto_white_balance->val != awb_manual)
                        pdev->color_bal_valid = false; /* Force cache update */
-               } else {
-                       pdev->red_balance->is_volatile = false;
-                       pdev->blue_balance->is_volatile = false;
-               }
        }
+       if (pdev->auto_white_balance->val != awb_manual)
+               return 0;
 
-       if (ret == 0 && pdev->red_balance->is_new) {
-               if (pdev->auto_white_balance->val != awb_manual)
-                       return -EBUSY;
+       if (pdev->red_balance->is_new) {
                ret = pwc_set_u8_ctrl(pdev, SET_CHROM_CTL,
                                      PRESET_MANUAL_RED_GAIN_FORMATTER,
                                      pdev->red_balance->val);
+               if (ret)
+                       return ret;
        }
 
-       if (ret == 0 && pdev->blue_balance->is_new) {
-               if (pdev->auto_white_balance->val != awb_manual)
-                       return -EBUSY;
+       if (pdev->blue_balance->is_new) {
                ret = pwc_set_u8_ctrl(pdev, SET_CHROM_CTL,
                                      PRESET_MANUAL_BLUE_GAIN_FORMATTER,
                                      pdev->blue_balance->val);
+               if (ret)
+                       return ret;
        }
-       return ret;
+       return 0;
 }
 
 /* For CODEC2 models which have separate autogain and auto exposure */
 static int pwc_set_autogain(struct pwc_device *pdev)
 {
-       int ret = 0;
+       int ret;
 
        if (pdev->autogain->is_new) {
                ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL,
@@ -692,27 +676,28 @@ static int pwc_set_autogain(struct pwc_device *pdev)
                                      pdev->autogain->val ? 0 : 0xff);
                if (ret)
                        return ret;
+
                if (pdev->autogain->val)
                        pdev->gain_valid = false; /* Force cache update */
-               else if (!pdev->gain->is_new)
-                       pwc_get_u8_ctrl(pdev, GET_STATUS_CTL,
-                                       READ_AGC_FORMATTER,
-                                       &pdev->gain->val);
        }
-       if (ret == 0 && pdev->gain->is_new) {
-               if (pdev->autogain->val)
-                       return -EBUSY;
+
+       if (pdev->autogain->val)
+               return 0;
+
+       if (pdev->gain->is_new) {
                ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL,
                                      PRESET_AGC_FORMATTER,
                                      pdev->gain->val);
+               if (ret)
+                       return ret;
        }
-       return ret;
+       return 0;
 }
 
 /* For CODEC2 models which have separate autogain and auto exposure */
 static int pwc_set_exposure_auto(struct pwc_device *pdev)
 {
-       int ret = 0;
+       int ret;
        int is_auto = pdev->exposure_auto->val == V4L2_EXPOSURE_AUTO;
 
        if (pdev->exposure_auto->is_new) {
@@ -721,27 +706,28 @@ static int pwc_set_exposure_auto(struct pwc_device *pdev)
                                      is_auto ? 0 : 0xff);
                if (ret)
                        return ret;
+
                if (is_auto)
                        pdev->exposure_valid = false; /* Force cache update */
-               else if (!pdev->exposure->is_new)
-                       pwc_get_u16_ctrl(pdev, GET_STATUS_CTL,
-                                        READ_SHUTTER_FORMATTER,
-                                        &pdev->exposure->val);
        }
-       if (ret == 0 && pdev->exposure->is_new) {
-               if (is_auto)
-                       return -EBUSY;
+
+       if (is_auto)
+               return 0;
+
+       if (pdev->exposure->is_new) {
                ret = pwc_set_u16_ctrl(pdev, SET_LUM_CTL,
                                       PRESET_SHUTTER_FORMATTER,
                                       pdev->exposure->val);
+               if (ret)
+                       return ret;
        }
-       return ret;
+       return 0;
 }
 
 /* For CODEC3 models which have autogain controlling both gain and exposure */
 static int pwc_set_autogain_expo(struct pwc_device *pdev)
 {
-       int ret = 0;
+       int ret;
 
        if (pdev->autogain->is_new) {
                ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL,
@@ -749,35 +735,32 @@ static int pwc_set_autogain_expo(struct pwc_device *pdev)
                                      pdev->autogain->val ? 0 : 0xff);
                if (ret)
                        return ret;
+
                if (pdev->autogain->val) {
                        pdev->gain_valid     = false; /* Force cache update */
                        pdev->exposure_valid = false; /* Force cache update */
-               } else {
-                       if (!pdev->gain->is_new)
-                               pwc_get_u8_ctrl(pdev, GET_STATUS_CTL,
-                                               READ_AGC_FORMATTER,
-                                               &pdev->gain->val);
-                       if (!pdev->exposure->is_new)
-                               pwc_get_u16_ctrl(pdev, GET_STATUS_CTL,
-                                                READ_SHUTTER_FORMATTER,
-                                                &pdev->exposure->val);
                }
        }
-       if (ret == 0 && pdev->gain->is_new) {
-               if (pdev->autogain->val)
-                       return -EBUSY;
+
+       if (pdev->autogain->val)
+               return 0;
+
+       if (pdev->gain->is_new) {
                ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL,
                                      PRESET_AGC_FORMATTER,
                                      pdev->gain->val);
+               if (ret)
+                       return ret;
        }
-       if (ret == 0 && pdev->exposure->is_new) {
-               if (pdev->autogain->val)
-                       return -EBUSY;
+
+       if (pdev->exposure->is_new) {
                ret = pwc_set_u16_ctrl(pdev, SET_LUM_CTL,
                                       PRESET_SHUTTER_FORMATTER,
                                       pdev->exposure->val);
+               if (ret)
+                       return ret;
        }
-       return ret;
+       return 0;
 }
 
 static int pwc_set_motor(struct pwc_device *pdev)
@@ -878,10 +861,6 @@ static int pwc_s_ctrl(struct v4l2_ctrl *ctrl)
                                        pdev->autocontour->val ? 0 : 0xff);
                }
                if (ret == 0 && pdev->contour->is_new) {
-                       if (pdev->autocontour->val) {
-                               ret = -EBUSY;
-                               break;
-                       }
                        ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL,
                                              PRESET_CONTOUR_FORMATTER,
                                              pdev->contour->val);
@@ -1099,6 +1078,14 @@ static int pwc_enum_frameintervals(struct file *file, void *fh,
        return 0;
 }
 
+static int pwc_log_status(struct file *file, void *priv)
+{
+       struct pwc_device *pdev = video_drvdata(file);
+
+       v4l2_ctrl_handler_log_status(&pdev->ctrl_handler, PWC_NAME);
+       return 0;
+}
+
 static long pwc_default(struct file *file, void *fh, bool valid_prio,
                        int cmd, void *arg)
 {
@@ -1122,6 +1109,7 @@ const struct v4l2_ioctl_ops pwc_ioctl_ops = {
        .vidioc_dqbuf                       = pwc_dqbuf,
        .vidioc_streamon                    = pwc_streamon,
        .vidioc_streamoff                   = pwc_streamoff,
+       .vidioc_log_status                  = pwc_log_status,
        .vidioc_enum_framesizes             = pwc_enum_framesizes,
        .vidioc_enum_frameintervals         = pwc_enum_frameintervals,
        .vidioc_default             = pwc_default,
index df6954ab1d991853d0d453daab7b9c8a8c610a08..33dec7f890e773ce586e857debfd461c06851314 100644 (file)
@@ -1,4 +1,4 @@
-s5p-fimc-objs := fimc-core.o fimc-reg.o fimc-capture.o
+s5p-fimc-objs := fimc-core.o fimc-reg.o fimc-capture.o fimc-mdevice.o
 s5p-csis-objs := mipi-csis.o
 
 obj-$(CONFIG_VIDEO_S5P_MIPI_CSIS)      += s5p-csis.o
index 0d730e55605d02423a5f34aea359f1e5202416d0..931f469604b06d32e4b500a048f91528b8ed63b8 100644 (file)
 #include <linux/bug.h>
 #include <linux/interrupt.h>
 #include <linux/device.h>
-#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
 #include <linux/list.h>
 #include <linux/slab.h>
-#include <linux/clk.h>
-#include <linux/i2c.h>
 
 #include <linux/videodev2.h>
 #include <media/v4l2-device.h>
 #include <media/videobuf2-core.h>
 #include <media/videobuf2-dma-contig.h>
 
+#include "fimc-mdevice.h"
 #include "fimc-core.h"
 
-static struct v4l2_subdev *fimc_subdev_register(struct fimc_dev *fimc,
-                                           struct s5p_fimc_isp_info *isp_info)
+static int fimc_init_capture(struct fimc_dev *fimc)
 {
-       struct i2c_adapter *i2c_adap;
-       struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
-       struct v4l2_subdev *sd = NULL;
-
-       i2c_adap = i2c_get_adapter(isp_info->i2c_bus_num);
-       if (!i2c_adap)
-               return ERR_PTR(-ENOMEM);
-
-       sd = v4l2_i2c_new_subdev_board(&vid_cap->v4l2_dev, i2c_adap,
-                                      isp_info->board_info, NULL);
-       if (!sd) {
-               v4l2_err(&vid_cap->v4l2_dev, "failed to acquire subdev\n");
-               return NULL;
-       }
+       struct fimc_ctx *ctx = fimc->vid_cap.ctx;
+       struct fimc_sensor_info *sensor;
+       unsigned long flags;
+       int ret = 0;
 
-       v4l2_info(&vid_cap->v4l2_dev, "subdevice %s registered successfuly\n",
-               isp_info->board_info->type);
+       if (fimc->pipeline.sensor == NULL || ctx == NULL)
+               return -ENXIO;
+       if (ctx->s_frame.fmt == NULL)
+               return -EINVAL;
 
-       return sd;
-}
+       sensor = v4l2_get_subdev_hostdata(fimc->pipeline.sensor);
 
-static void fimc_subdev_unregister(struct fimc_dev *fimc)
-{
-       struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
-       struct i2c_client *client;
+       spin_lock_irqsave(&fimc->slock, flags);
+       fimc_prepare_dma_offset(ctx, &ctx->d_frame);
+       fimc_set_yuv_order(ctx);
 
-       if (vid_cap->input_index < 0)
-               return; /* Subdevice already released or not registered. */
+       fimc_hw_set_camera_polarity(fimc, sensor->pdata);
+       fimc_hw_set_camera_type(fimc, sensor->pdata);
+       fimc_hw_set_camera_source(fimc, sensor->pdata);
+       fimc_hw_set_camera_offset(fimc, &ctx->s_frame);
 
-       if (vid_cap->sd) {
-               v4l2_device_unregister_subdev(vid_cap->sd);
-               client = v4l2_get_subdevdata(vid_cap->sd);
-               i2c_unregister_device(client);
-               i2c_put_adapter(client->adapter);
-               vid_cap->sd = NULL;
+       ret = fimc_set_scaler_info(ctx);
+       if (!ret) {
+               fimc_hw_set_input_path(ctx);
+               fimc_hw_set_prescaler(ctx);
+               fimc_hw_set_mainscaler(ctx);
+               fimc_hw_set_target_format(ctx);
+               fimc_hw_set_rotation(ctx);
+               fimc_hw_set_effect(ctx, false);
+               fimc_hw_set_output_path(ctx);
+               fimc_hw_set_out_dma(ctx);
+               clear_bit(ST_CAPT_APPLY_CFG, &fimc->state);
        }
-
-       vid_cap->input_index = -1;
+       spin_unlock_irqrestore(&fimc->slock, flags);
+       return ret;
 }
 
-/**
- * fimc_subdev_attach - attach v4l2_subdev to camera host interface
- *
- * @fimc: FIMC device information
- * @index: index to the array of available subdevices,
- *        -1 for full array search or non negative value
- *        to select specific subdevice
- */
-static int fimc_subdev_attach(struct fimc_dev *fimc, int index)
+static int fimc_capture_state_cleanup(struct fimc_dev *fimc, bool suspend)
 {
-       struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
-       struct s5p_platform_fimc *pdata = fimc->pdata;
-       struct s5p_fimc_isp_info *isp_info;
-       struct v4l2_subdev *sd;
-       int i;
-
-       for (i = 0; i < pdata->num_clients; ++i) {
-               isp_info = &pdata->isp_info[i];
+       struct fimc_vid_cap *cap = &fimc->vid_cap;
+       struct fimc_vid_buffer *buf;
+       unsigned long flags;
+       bool streaming;
 
-               if (index >= 0 && i != index)
-                       continue;
+       spin_lock_irqsave(&fimc->slock, flags);
+       streaming = fimc->state & (1 << ST_CAPT_ISP_STREAM);
 
-               sd = fimc_subdev_register(fimc, isp_info);
-               if (!IS_ERR_OR_NULL(sd)) {
-                       vid_cap->sd = sd;
-                       vid_cap->input_index = i;
+       fimc->state &= ~(1 << ST_CAPT_RUN | 1 << ST_CAPT_SHUT |
+                        1 << ST_CAPT_STREAM | 1 << ST_CAPT_ISP_STREAM);
+       if (!suspend)
+               fimc->state &= ~(1 << ST_CAPT_PEND | 1 << ST_CAPT_SUSPENDED);
 
-                       return 0;
-               }
+       /* Release unused buffers */
+       while (!suspend && !list_empty(&cap->pending_buf_q)) {
+               buf = fimc_pending_queue_pop(cap);
+               vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
        }
+       /* If suspending put unused buffers onto pending queue */
+       while (!list_empty(&cap->active_buf_q)) {
+               buf = fimc_active_queue_pop(cap);
+               if (suspend)
+                       fimc_pending_queue_add(cap, buf);
+               else
+                       vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+       }
+       set_bit(ST_CAPT_SUSPENDED, &fimc->state);
+       spin_unlock_irqrestore(&fimc->slock, flags);
 
-       vid_cap->input_index = -1;
-       vid_cap->sd = NULL;
-       v4l2_err(&vid_cap->v4l2_dev, "fimc%d: sensor attach failed\n",
-                fimc->id);
-       return -ENODEV;
-}
-
-static int fimc_isp_subdev_init(struct fimc_dev *fimc, unsigned int index)
-{
-       struct s5p_fimc_isp_info *isp_info;
-       struct s5p_platform_fimc *pdata = fimc->pdata;
-       int ret;
-
-       if (index >= pdata->num_clients)
-               return -EINVAL;
-
-       isp_info = &pdata->isp_info[index];
-
-       if (isp_info->clk_frequency)
-               clk_set_rate(fimc->clock[CLK_CAM], isp_info->clk_frequency);
-
-       ret = clk_enable(fimc->clock[CLK_CAM]);
-       if (ret)
-               return ret;
-
-       ret = fimc_subdev_attach(fimc, index);
-       if (ret)
-               return ret;
-
-       ret = fimc_hw_set_camera_polarity(fimc, isp_info);
-       if (ret)
-               return ret;
-
-       ret = v4l2_subdev_call(fimc->vid_cap.sd, core, s_power, 1);
-       if (!ret)
-               return ret;
-
-       /* enabling power failed so unregister subdev */
-       fimc_subdev_unregister(fimc);
-
-       v4l2_err(&fimc->vid_cap.v4l2_dev, "ISP initialization failed: %d\n",
-                ret);
-
-       return ret;
+       if (streaming)
+               return fimc_pipeline_s_stream(fimc, 0);
+       else
+               return 0;
 }
 
-static int fimc_stop_capture(struct fimc_dev *fimc)
+static int fimc_stop_capture(struct fimc_dev *fimc, bool suspend)
 {
        unsigned long flags;
-       struct fimc_vid_cap *cap;
-       struct fimc_vid_buffer *buf;
-
-       cap = &fimc->vid_cap;
 
        if (!fimc_capture_active(fimc))
                return 0;
@@ -169,81 +120,73 @@ static int fimc_stop_capture(struct fimc_dev *fimc)
 
        wait_event_timeout(fimc->irq_queue,
                           !test_bit(ST_CAPT_SHUT, &fimc->state),
-                          FIMC_SHUTDOWN_TIMEOUT);
-
-       v4l2_subdev_call(cap->sd, video, s_stream, 0);
+                          (2*HZ/10)); /* 200 ms */
 
-       spin_lock_irqsave(&fimc->slock, flags);
-       fimc->state &= ~(1 << ST_CAPT_RUN | 1 << ST_CAPT_PEND |
-                        1 << ST_CAPT_SHUT | 1 << ST_CAPT_STREAM);
+       return fimc_capture_state_cleanup(fimc, suspend);
+}
 
-       fimc->vid_cap.active_buf_cnt = 0;
+/**
+ * fimc_capture_config_update - apply the camera interface configuration
+ *
+ * To be called from within the interrupt handler with fimc.slock
+ * spinlock held. It updates the camera pixel crop, rotation and
+ * image flip in H/W.
+ */
+int fimc_capture_config_update(struct fimc_ctx *ctx)
+{
+       struct fimc_dev *fimc = ctx->fimc_dev;
+       int ret;
 
-       /* Release buffers that were enqueued in the driver by videobuf2. */
-       while (!list_empty(&cap->pending_buf_q)) {
-               buf = pending_queue_pop(cap);
-               vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
-       }
+       if (test_bit(ST_CAPT_APPLY_CFG, &fimc->state))
+               return 0;
 
-       while (!list_empty(&cap->active_buf_q)) {
-               buf = active_queue_pop(cap);
-               vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+       spin_lock(&ctx->slock);
+       fimc_hw_set_camera_offset(fimc, &ctx->s_frame);
+       ret = fimc_set_scaler_info(ctx);
+       if (ret == 0) {
+               fimc_hw_set_prescaler(ctx);
+               fimc_hw_set_mainscaler(ctx);
+               fimc_hw_set_target_format(ctx);
+               fimc_hw_set_rotation(ctx);
+               fimc_prepare_dma_offset(ctx, &ctx->d_frame);
+               fimc_hw_set_out_dma(ctx);
+               set_bit(ST_CAPT_APPLY_CFG, &fimc->state);
        }
-
-       spin_unlock_irqrestore(&fimc->slock, flags);
-
-       dbg("state: 0x%lx", fimc->state);
-       return 0;
+       spin_unlock(&ctx->slock);
+       return ret;
 }
 
-static int start_streaming(struct vb2_queue *q)
+static int start_streaming(struct vb2_queue *q, unsigned int count)
 {
        struct fimc_ctx *ctx = q->drv_priv;
        struct fimc_dev *fimc = ctx->fimc_dev;
-       struct s5p_fimc_isp_info *isp_info;
+       struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
+       int min_bufs;
        int ret;
 
        fimc_hw_reset(fimc);
+       vid_cap->frame_count = 0;
 
-       ret = v4l2_subdev_call(fimc->vid_cap.sd, video, s_stream, 1);
-       if (ret && ret != -ENOIOCTLCMD)
-               return ret;
-
-       ret = fimc_prepare_config(ctx, ctx->state);
+       ret = fimc_init_capture(fimc);
        if (ret)
-               return ret;
-
-       isp_info = &fimc->pdata->isp_info[fimc->vid_cap.input_index];
-       fimc_hw_set_camera_type(fimc, isp_info);
-       fimc_hw_set_camera_source(fimc, isp_info);
-       fimc_hw_set_camera_offset(fimc, &ctx->s_frame);
+               goto error;
 
-       if (ctx->state & FIMC_PARAMS) {
-               ret = fimc_set_scaler_info(ctx);
-               if (ret) {
-                       err("Scaler setup error");
-                       return ret;
-               }
-               fimc_hw_set_input_path(ctx);
-               fimc_hw_set_prescaler(ctx);
-               fimc_hw_set_mainscaler(ctx);
-               fimc_hw_set_target_format(ctx);
-               fimc_hw_set_rotation(ctx);
-               fimc_hw_set_effect(ctx);
-       }
+       set_bit(ST_CAPT_PEND, &fimc->state);
 
-       fimc_hw_set_output_path(ctx);
-       fimc_hw_set_out_dma(ctx);
+       min_bufs = fimc->vid_cap.reqbufs_count > 1 ? 2 : 1;
 
-       INIT_LIST_HEAD(&fimc->vid_cap.pending_buf_q);
-       INIT_LIST_HEAD(&fimc->vid_cap.active_buf_q);
-       fimc->vid_cap.active_buf_cnt = 0;
-       fimc->vid_cap.frame_count = 0;
-       fimc->vid_cap.buf_index = 0;
+       if (vid_cap->active_buf_cnt >= min_bufs &&
+           !test_and_set_bit(ST_CAPT_STREAM, &fimc->state)) {
+               fimc_activate_capture(ctx);
 
-       set_bit(ST_CAPT_PEND, &fimc->state);
+               if (!test_and_set_bit(ST_CAPT_ISP_STREAM, &fimc->state))
+                       fimc_pipeline_s_stream(fimc, 1);
+       }
 
        return 0;
+error:
+       fimc_capture_state_cleanup(fimc, false);
+       return ret;
 }
 
 static int stop_streaming(struct vb2_queue *q)
@@ -254,7 +197,46 @@ static int stop_streaming(struct vb2_queue *q)
        if (!fimc_capture_active(fimc))
                return -EINVAL;
 
-       return fimc_stop_capture(fimc);
+       return fimc_stop_capture(fimc, false);
+}
+
+int fimc_capture_suspend(struct fimc_dev *fimc)
+{
+       bool suspend = fimc_capture_busy(fimc);
+
+       int ret = fimc_stop_capture(fimc, suspend);
+       if (ret)
+               return ret;
+       return fimc_pipeline_shutdown(fimc);
+}
+
+static void buffer_queue(struct vb2_buffer *vb);
+
+int fimc_capture_resume(struct fimc_dev *fimc)
+{
+       struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
+       struct fimc_vid_buffer *buf;
+       int i;
+
+       if (!test_and_clear_bit(ST_CAPT_SUSPENDED, &fimc->state))
+               return 0;
+
+       INIT_LIST_HEAD(&fimc->vid_cap.active_buf_q);
+       vid_cap->buf_index = 0;
+       fimc_pipeline_initialize(fimc, &fimc->vid_cap.vfd->entity,
+                                false);
+       fimc_init_capture(fimc);
+
+       clear_bit(ST_CAPT_SUSPENDED, &fimc->state);
+
+       for (i = 0; i < vid_cap->reqbufs_count; i++) {
+               if (list_empty(&vid_cap->pending_buf_q))
+                       break;
+               buf = fimc_pending_queue_pop(vid_cap);
+               buffer_queue(&buf->vb);
+       }
+       return 0;
+
 }
 
 static unsigned int get_plane_size(struct fimc_frame *fr, unsigned int plane)
@@ -265,7 +247,7 @@ static unsigned int get_plane_size(struct fimc_frame *fr, unsigned int plane)
 }
 
 static int queue_setup(struct vb2_queue *vq, unsigned int *num_buffers,
-                      unsigned int *num_planes, unsigned long sizes[],
+                      unsigned int *num_planes, unsigned int sizes[],
                       void *allocators[])
 {
        struct fimc_ctx *ctx = vq->drv_priv;
@@ -289,21 +271,20 @@ static int buffer_prepare(struct vb2_buffer *vb)
 {
        struct vb2_queue *vq = vb->vb2_queue;
        struct fimc_ctx *ctx = vq->drv_priv;
-       struct v4l2_device *v4l2_dev = &ctx->fimc_dev->m2m.v4l2_dev;
        int i;
 
-       if (!ctx->d_frame.fmt || vq->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
+       if (ctx->d_frame.fmt == NULL)
                return -EINVAL;
 
        for (i = 0; i < ctx->d_frame.fmt->memplanes; i++) {
-               unsigned long size = get_plane_size(&ctx->d_frame, i);
+               unsigned long size = ctx->d_frame.payload[i];
 
                if (vb2_plane_size(vb, i) < size) {
-                       v4l2_err(v4l2_dev, "User buffer too small (%ld < %ld)\n",
+                       v4l2_err(ctx->fimc_dev->vid_cap.vfd,
+                                "User buffer too small (%ld < %ld)\n",
                                 vb2_plane_size(vb, i), size);
                        return -EINVAL;
                }
-
                vb2_set_plane_payload(vb, i, size);
        }
 
@@ -312,10 +293,10 @@ static int buffer_prepare(struct vb2_buffer *vb)
 
 static void buffer_queue(struct vb2_buffer *vb)
 {
-       struct fimc_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
-       struct fimc_dev *fimc = ctx->fimc_dev;
        struct fimc_vid_buffer *buf
                = container_of(vb, struct fimc_vid_buffer, vb);
+       struct fimc_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+       struct fimc_dev *fimc = ctx->fimc_dev;
        struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
        unsigned long flags;
        int min_bufs;
@@ -323,15 +304,16 @@ static void buffer_queue(struct vb2_buffer *vb)
        spin_lock_irqsave(&fimc->slock, flags);
        fimc_prepare_addr(ctx, &buf->vb, &ctx->d_frame, &buf->paddr);
 
-       if (!test_bit(ST_CAPT_STREAM, &fimc->state)
-            && vid_cap->active_buf_cnt < FIMC_MAX_OUT_BUFS) {
+       if (!test_bit(ST_CAPT_SUSPENDED, &fimc->state) &&
+           !test_bit(ST_CAPT_STREAM, &fimc->state) &&
+           vid_cap->active_buf_cnt < FIMC_MAX_OUT_BUFS) {
                /* Setup the buffer directly for processing. */
                int buf_id = (vid_cap->reqbufs_count == 1) ? -1 :
                                vid_cap->buf_index;
 
                fimc_hw_set_output_addr(fimc, &buf->paddr, buf_id);
                buf->index = vid_cap->buf_index;
-               active_queue_add(vid_cap, buf);
+               fimc_active_queue_add(vid_cap, buf);
 
                if (++vid_cap->buf_index >= FIMC_MAX_OUT_BUFS)
                        vid_cap->buf_index = 0;
@@ -341,10 +323,17 @@ static void buffer_queue(struct vb2_buffer *vb)
 
        min_bufs = vid_cap->reqbufs_count > 1 ? 2 : 1;
 
-       if (vid_cap->active_buf_cnt >= min_bufs &&
-           !test_and_set_bit(ST_CAPT_STREAM, &fimc->state))
+
+       if (vb2_is_streaming(&vid_cap->vbq) &&
+           vid_cap->active_buf_cnt >= min_bufs &&
+           !test_and_set_bit(ST_CAPT_STREAM, &fimc->state)) {
                fimc_activate_capture(ctx);
+               spin_unlock_irqrestore(&fimc->slock, flags);
 
+               if (!test_and_set_bit(ST_CAPT_ISP_STREAM, &fimc->state))
+                       fimc_pipeline_s_stream(fimc, 1);
+               return;
+       }
        spin_unlock_irqrestore(&fimc->slock, flags);
 }
 
@@ -370,10 +359,40 @@ static struct vb2_ops fimc_capture_qops = {
        .stop_streaming         = stop_streaming,
 };
 
+/**
+ * fimc_capture_ctrls_create - initialize the control handler
+ * Initialize the capture video node control handler and fill it
+ * with the FIMC controls. Inherit any sensor's controls if the
+ * 'user_subdev_api' flag is false (default behaviour).
+ * This function need to be called with the graph mutex held.
+ */
+int fimc_capture_ctrls_create(struct fimc_dev *fimc)
+{
+       struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
+       int ret;
+
+       if (WARN_ON(vid_cap->ctx == NULL))
+               return -ENXIO;
+       if (vid_cap->ctx->ctrls_rdy)
+               return 0;
+
+       ret = fimc_ctrls_create(vid_cap->ctx);
+       if (ret || vid_cap->user_subdev_api)
+               return ret;
+
+       return v4l2_ctrl_add_handler(&vid_cap->ctx->ctrl_handler,
+                                   fimc->pipeline.sensor->ctrl_handler);
+}
+
+static int fimc_capture_set_default_format(struct fimc_dev *fimc);
+
 static int fimc_capture_open(struct file *file)
 {
        struct fimc_dev *fimc = video_drvdata(file);
-       int ret = 0;
+       int ret = v4l2_fh_open(file);
+
+       if (ret)
+               return ret;
 
        dbg("pid: %d, state: 0x%lx", task_pid_nr(current), fimc->state);
 
@@ -381,17 +400,27 @@ static int fimc_capture_open(struct file *file)
        if (fimc_m2m_active(fimc))
                return -EBUSY;
 
+       set_bit(ST_CAPT_BUSY, &fimc->state);
+       pm_runtime_get_sync(&fimc->pdev->dev);
+
        if (++fimc->vid_cap.refcnt == 1) {
-               ret = fimc_isp_subdev_init(fimc, 0);
-               if (ret) {
+               ret = fimc_pipeline_initialize(fimc,
+                              &fimc->vid_cap.vfd->entity, true);
+               if (ret < 0) {
+                       dev_err(&fimc->pdev->dev,
+                               "Video pipeline initialization failed\n");
+                       pm_runtime_put_sync(&fimc->pdev->dev);
                        fimc->vid_cap.refcnt--;
-                       return -EIO;
+                       v4l2_fh_release(file);
+                       clear_bit(ST_CAPT_BUSY, &fimc->state);
+                       return ret;
                }
-       }
-
-       file->private_data = fimc->vid_cap.ctx;
+               ret = fimc_capture_ctrls_create(fimc);
 
-       return 0;
+               if (!ret && !fimc->vid_cap.user_subdev_api)
+                       ret = fimc_capture_set_default_format(fimc);
+       }
+       return ret;
 }
 
 static int fimc_capture_close(struct file *file)
@@ -401,37 +430,36 @@ static int fimc_capture_close(struct file *file)
        dbg("pid: %d, state: 0x%lx", task_pid_nr(current), fimc->state);
 
        if (--fimc->vid_cap.refcnt == 0) {
-               fimc_stop_capture(fimc);
-               vb2_queue_release(&fimc->vid_cap.vbq);
+               clear_bit(ST_CAPT_BUSY, &fimc->state);
+               fimc_stop_capture(fimc, false);
+               fimc_pipeline_shutdown(fimc);
+               clear_bit(ST_CAPT_SUSPENDED, &fimc->state);
+       }
 
-               v4l2_err(&fimc->vid_cap.v4l2_dev, "releasing ISP\n");
+       pm_runtime_put(&fimc->pdev->dev);
 
-               v4l2_subdev_call(fimc->vid_cap.sd, core, s_power, 0);
-               clk_disable(fimc->clock[CLK_CAM]);
-               fimc_subdev_unregister(fimc);
+       if (fimc->vid_cap.refcnt == 0) {
+               vb2_queue_release(&fimc->vid_cap.vbq);
+               fimc_ctrls_delete(fimc->vid_cap.ctx);
        }
-
-       return 0;
+       return v4l2_fh_release(file);
 }
 
 static unsigned int fimc_capture_poll(struct file *file,
                                      struct poll_table_struct *wait)
 {
-       struct fimc_ctx *ctx = file->private_data;
-       struct fimc_dev *fimc = ctx->fimc_dev;
+       struct fimc_dev *fimc = video_drvdata(file);
 
        return vb2_poll(&fimc->vid_cap.vbq, file, wait);
 }
 
 static int fimc_capture_mmap(struct file *file, struct vm_area_struct *vma)
 {
-       struct fimc_ctx *ctx = file->private_data;
-       struct fimc_dev *fimc = ctx->fimc_dev;
+       struct fimc_dev *fimc = video_drvdata(file);
 
        return vb2_mmap(&fimc->vid_cap.vbq, vma);
 }
 
-/* video device file operations */
 static const struct v4l2_file_operations fimc_capture_fops = {
        .owner          = THIS_MODULE,
        .open           = fimc_capture_open,
@@ -441,263 +469,553 @@ static const struct v4l2_file_operations fimc_capture_fops = {
        .mmap           = fimc_capture_mmap,
 };
 
+/*
+ * Format and crop negotiation helpers
+ */
+
+static struct fimc_fmt *fimc_capture_try_format(struct fimc_ctx *ctx,
+                                               u32 *width, u32 *height,
+                                               u32 *code, u32 *fourcc, int pad)
+{
+       bool rotation = ctx->rotation == 90 || ctx->rotation == 270;
+       struct fimc_dev *fimc = ctx->fimc_dev;
+       struct samsung_fimc_variant *var = fimc->variant;
+       struct fimc_pix_limit *pl = var->pix_limit;
+       struct fimc_frame *dst = &ctx->d_frame;
+       u32 depth, min_w, max_w, min_h, align_h = 3;
+       u32 mask = FMT_FLAGS_CAM;
+       struct fimc_fmt *ffmt;
+
+       /* Color conversion from/to JPEG is not supported */
+       if (code && ctx->s_frame.fmt && pad == FIMC_SD_PAD_SOURCE &&
+           fimc_fmt_is_jpeg(ctx->s_frame.fmt->color))
+               *code = V4L2_MBUS_FMT_JPEG_1X8;
+
+       if (fourcc && *fourcc != V4L2_PIX_FMT_JPEG && pad != FIMC_SD_PAD_SINK)
+               mask |= FMT_FLAGS_M2M;
+
+       ffmt = fimc_find_format(fourcc, code, mask, 0);
+       if (WARN_ON(!ffmt))
+               return NULL;
+       if (code)
+               *code = ffmt->mbus_code;
+       if (fourcc)
+               *fourcc = ffmt->fourcc;
+
+       if (pad == FIMC_SD_PAD_SINK) {
+               max_w = fimc_fmt_is_jpeg(ffmt->color) ?
+                       pl->scaler_dis_w : pl->scaler_en_w;
+               /* Apply the camera input interface pixel constraints */
+               v4l_bound_align_image(width, max_t(u32, *width, 32), max_w, 4,
+                                     height, max_t(u32, *height, 32),
+                                     FIMC_CAMIF_MAX_HEIGHT,
+                                     fimc_fmt_is_jpeg(ffmt->color) ? 3 : 1,
+                                     0);
+               return ffmt;
+       }
+       /* Can't scale or crop in transparent (JPEG) transfer mode */
+       if (fimc_fmt_is_jpeg(ffmt->color)) {
+               *width  = ctx->s_frame.f_width;
+               *height = ctx->s_frame.f_height;
+               return ffmt;
+       }
+       /* Apply the scaler and the output DMA constraints */
+       max_w = rotation ? pl->out_rot_en_w : pl->out_rot_dis_w;
+       min_w = ctx->state & FIMC_DST_CROP ? dst->width : var->min_out_pixsize;
+       min_h = ctx->state & FIMC_DST_CROP ? dst->height : var->min_out_pixsize;
+       if (fimc->id == 1 && var->pix_hoff)
+               align_h = fimc_fmt_is_rgb(ffmt->color) ? 0 : 1;
+
+       depth = fimc_get_format_depth(ffmt);
+       v4l_bound_align_image(width, min_w, max_w,
+                             ffs(var->min_out_pixsize) - 1,
+                             height, min_h, FIMC_CAMIF_MAX_HEIGHT,
+                             align_h,
+                             64/(ALIGN(depth, 8)));
+
+       dbg("pad%d: code: 0x%x, %dx%d. dst fmt: %dx%d",
+           pad, code ? *code : 0, *width, *height,
+           dst->f_width, dst->f_height);
+
+       return ffmt;
+}
+
+static void fimc_capture_try_crop(struct fimc_ctx *ctx, struct v4l2_rect *r,
+                                 int pad)
+{
+       bool rotate = ctx->rotation == 90 || ctx->rotation == 270;
+       struct fimc_dev *fimc = ctx->fimc_dev;
+       struct samsung_fimc_variant *var = fimc->variant;
+       struct fimc_pix_limit *pl = var->pix_limit;
+       struct fimc_frame *sink = &ctx->s_frame;
+       u32 max_w, max_h, min_w = 0, min_h = 0, min_sz;
+       u32 align_sz = 0, align_h = 4;
+       u32 max_sc_h, max_sc_v;
+
+       /* In JPEG transparent transfer mode cropping is not supported */
+       if (fimc_fmt_is_jpeg(ctx->d_frame.fmt->color)) {
+               r->width  = sink->f_width;
+               r->height = sink->f_height;
+               r->left   = r->top = 0;
+               return;
+       }
+       if (pad == FIMC_SD_PAD_SOURCE) {
+               if (ctx->rotation != 90 && ctx->rotation != 270)
+                       align_h = 1;
+               max_sc_h = min(SCALER_MAX_HRATIO, 1 << (ffs(sink->width) - 3));
+               max_sc_v = min(SCALER_MAX_VRATIO, 1 << (ffs(sink->height) - 1));
+               min_sz = var->min_out_pixsize;
+       } else {
+               u32 depth = fimc_get_format_depth(sink->fmt);
+               align_sz = 64/ALIGN(depth, 8);
+               min_sz = var->min_inp_pixsize;
+               min_w = min_h = min_sz;
+               max_sc_h = max_sc_v = 1;
+       }
+       /*
+        * For the crop rectangle at source pad the following constraints
+        * must be met:
+        * - it must fit in the sink pad format rectangle (f_width/f_height);
+        * - maximum downscaling ratio is 64;
+        * - maximum crop size depends if the rotator is used or not;
+        * - the sink pad format width/height must be 4 multiple of the
+        *   prescaler ratios determined by sink pad size and source pad crop,
+        *   the prescaler ratio is returned by fimc_get_scaler_factor().
+        */
+       max_w = min_t(u32,
+                     rotate ? pl->out_rot_en_w : pl->out_rot_dis_w,
+                     rotate ? sink->f_height : sink->f_width);
+       max_h = min_t(u32, FIMC_CAMIF_MAX_HEIGHT, sink->f_height);
+       if (pad == FIMC_SD_PAD_SOURCE) {
+               min_w = min_t(u32, max_w, sink->f_width / max_sc_h);
+               min_h = min_t(u32, max_h, sink->f_height / max_sc_v);
+               if (rotate) {
+                       swap(max_sc_h, max_sc_v);
+                       swap(min_w, min_h);
+               }
+       }
+       v4l_bound_align_image(&r->width, min_w, max_w, ffs(min_sz) - 1,
+                             &r->height, min_h, max_h, align_h,
+                             align_sz);
+       /* Adjust left/top if cropping rectangle is out of bounds */
+       r->left = clamp_t(u32, r->left, 0, sink->f_width - r->width);
+       r->top  = clamp_t(u32, r->top, 0, sink->f_height - r->height);
+       r->left = round_down(r->left, var->hor_offs_align);
+
+       dbg("pad%d: (%d,%d)/%dx%d, sink fmt: %dx%d",
+           pad, r->left, r->top, r->width, r->height,
+           sink->f_width, sink->f_height);
+}
+
+/*
+ * The video node ioctl operations
+ */
 static int fimc_vidioc_querycap_capture(struct file *file, void *priv,
                                        struct v4l2_capability *cap)
 {
-       struct fimc_ctx *ctx = file->private_data;
-       struct fimc_dev *fimc = ctx->fimc_dev;
+       struct fimc_dev *fimc = video_drvdata(file);
 
        strncpy(cap->driver, fimc->pdev->name, sizeof(cap->driver) - 1);
        strncpy(cap->card, fimc->pdev->name, sizeof(cap->card) - 1);
        cap->bus_info[0] = 0;
-       cap->capabilities = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_CAPTURE |
-                           V4L2_CAP_VIDEO_CAPTURE_MPLANE;
+       cap->capabilities = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_CAPTURE_MPLANE;
 
        return 0;
 }
 
-/* Synchronize formats of the camera interface input and attached  sensor. */
-static int sync_capture_fmt(struct fimc_ctx *ctx)
+static int fimc_cap_enum_fmt_mplane(struct file *file, void *priv,
+                                   struct v4l2_fmtdesc *f)
+{
+       struct fimc_fmt *fmt;
+
+       fmt = fimc_find_format(NULL, NULL, FMT_FLAGS_CAM | FMT_FLAGS_M2M,
+                              f->index);
+       if (!fmt)
+               return -EINVAL;
+       strncpy(f->description, fmt->name, sizeof(f->description) - 1);
+       f->pixelformat = fmt->fourcc;
+       if (fmt->fourcc == V4L2_MBUS_FMT_JPEG_1X8)
+               f->flags |= V4L2_FMT_FLAG_COMPRESSED;
+       return 0;
+}
+
+/**
+ * fimc_pipeline_try_format - negotiate and/or set formats at pipeline
+ *                            elements
+ * @ctx: FIMC capture context
+ * @tfmt: media bus format to try/set on subdevs
+ * @fmt_id: fimc pixel format id corresponding to returned @tfmt (output)
+ * @set: true to set format on subdevs, false to try only
+ */
+static int fimc_pipeline_try_format(struct fimc_ctx *ctx,
+                                   struct v4l2_mbus_framefmt *tfmt,
+                                   struct fimc_fmt **fmt_id,
+                                   bool set)
 {
-       struct fimc_frame *frame = &ctx->s_frame;
        struct fimc_dev *fimc = ctx->fimc_dev;
-       struct v4l2_mbus_framefmt *fmt = &fimc->vid_cap.fmt;
-       int ret;
+       struct v4l2_subdev *sd = fimc->pipeline.sensor;
+       struct v4l2_subdev *csis = fimc->pipeline.csis;
+       struct v4l2_subdev_format sfmt;
+       struct v4l2_mbus_framefmt *mf = &sfmt.format;
+       struct fimc_fmt *ffmt = NULL;
+       int ret, i = 0;
+
+       if (WARN_ON(!sd || !tfmt))
+               return -EINVAL;
 
-       fmt->width  = ctx->d_frame.o_width;
-       fmt->height = ctx->d_frame.o_height;
+       memset(&sfmt, 0, sizeof(sfmt));
+       sfmt.format = *tfmt;
+
+       sfmt.which = set ? V4L2_SUBDEV_FORMAT_ACTIVE : V4L2_SUBDEV_FORMAT_TRY;
+       while (1) {
+               ffmt = fimc_find_format(NULL, mf->code != 0 ? &mf->code : NULL,
+                                       FMT_FLAGS_CAM, i++);
+               if (ffmt == NULL) {
+                       /*
+                        * Notify user-space if common pixel code for
+                        * host and sensor does not exist.
+                        */
+                       return -EINVAL;
+               }
+               mf->code = tfmt->code = ffmt->mbus_code;
 
-       ret = v4l2_subdev_call(fimc->vid_cap.sd, video, s_mbus_fmt, fmt);
-       if (ret == -ENOIOCTLCMD) {
-               err("s_mbus_fmt failed");
-               return ret;
-       }
-       dbg("w: %d, h: %d, code= %d", fmt->width, fmt->height, fmt->code);
+               ret = v4l2_subdev_call(sd, pad, set_fmt, NULL, &sfmt);
+               if (ret)
+                       return ret;
+               if (mf->code != tfmt->code) {
+                       mf->code = 0;
+                       continue;
+               }
+               if (mf->width != tfmt->width || mf->width != tfmt->width) {
+                       u32 fcc = ffmt->fourcc;
+                       tfmt->width  = mf->width;
+                       tfmt->height = mf->height;
+                       ffmt = fimc_capture_try_format(ctx,
+                                              &tfmt->width, &tfmt->height,
+                                              NULL, &fcc, FIMC_SD_PAD_SOURCE);
+                       if (ffmt && ffmt->mbus_code)
+                               mf->code = ffmt->mbus_code;
+                       if (mf->width != tfmt->width || mf->width != tfmt->width)
+                               continue;
+                       tfmt->code = mf->code;
+               }
+               if (csis)
+                       ret = v4l2_subdev_call(csis, pad, set_fmt, NULL, &sfmt);
 
-       frame->fmt = find_mbus_format(fmt, FMT_FLAGS_CAM);
-       if (!frame->fmt) {
-               err("fimc source format not found\n");
-               return -EINVAL;
+               if (mf->code == tfmt->code &&
+                   mf->width == tfmt->width && mf->width == tfmt->width)
+                       break;
        }
 
-       frame->f_width  = fmt->width;
-       frame->f_height = fmt->height;
-       frame->width    = fmt->width;
-       frame->height   = fmt->height;
-       frame->o_width  = fmt->width;
-       frame->o_height = fmt->height;
-       frame->offs_h   = 0;
-       frame->offs_v   = 0;
+       if (fmt_id && ffmt)
+               *fmt_id = ffmt;
+       *tfmt = *mf;
 
+       dbg("code: 0x%x, %dx%d, %p", mf->code, mf->width, mf->height, ffmt);
        return 0;
 }
 
-static int fimc_cap_s_fmt_mplane(struct file *file, void *priv,
+static int fimc_cap_g_fmt_mplane(struct file *file, void *fh,
                                 struct v4l2_format *f)
 {
-       struct fimc_ctx *ctx = priv;
-       struct fimc_dev *fimc = ctx->fimc_dev;
-       struct fimc_frame *frame;
-       struct v4l2_pix_format_mplane *pix;
-       int ret;
-       int i;
+       struct fimc_dev *fimc = video_drvdata(file);
+       struct fimc_ctx *ctx = fimc->vid_cap.ctx;
 
        if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
                return -EINVAL;
 
-       ret = fimc_vidioc_try_fmt_mplane(file, priv, f);
-       if (ret)
-               return ret;
-
-       if (vb2_is_busy(&fimc->vid_cap.vbq) || fimc_capture_active(fimc))
-               return -EBUSY;
+       return fimc_fill_format(&ctx->d_frame, f);
+}
 
-       frame = &ctx->d_frame;
+static int fimc_cap_try_fmt_mplane(struct file *file, void *fh,
+                                  struct v4l2_format *f)
+{
+       struct v4l2_pix_format_mplane *pix = &f->fmt.pix_mp;
+       struct fimc_dev *fimc = video_drvdata(file);
+       struct fimc_ctx *ctx = fimc->vid_cap.ctx;
+       struct v4l2_mbus_framefmt mf;
+       struct fimc_fmt *ffmt = NULL;
 
-       pix = &f->fmt.pix_mp;
-       frame->fmt = find_format(f, FMT_FLAGS_M2M | FMT_FLAGS_CAM);
-       if (!frame->fmt) {
-               err("fimc target format not found\n");
+       if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
                return -EINVAL;
+
+       if (pix->pixelformat == V4L2_PIX_FMT_JPEG) {
+               fimc_capture_try_format(ctx, &pix->width, &pix->height,
+                                       NULL, &pix->pixelformat,
+                                       FIMC_SD_PAD_SINK);
+               ctx->s_frame.f_width  = pix->width;
+               ctx->s_frame.f_height = pix->height;
        }
+       ffmt = fimc_capture_try_format(ctx, &pix->width, &pix->height,
+                                      NULL, &pix->pixelformat,
+                                      FIMC_SD_PAD_SOURCE);
+       if (!ffmt)
+               return -EINVAL;
 
-       for (i = 0; i < frame->fmt->colplanes; i++) {
-               frame->payload[i] =
-                       (pix->width * pix->height * frame->fmt->depth[i]) >> 3;
+       if (!fimc->vid_cap.user_subdev_api) {
+               mf.width  = pix->width;
+               mf.height = pix->height;
+               mf.code   = ffmt->mbus_code;
+               fimc_md_graph_lock(fimc);
+               fimc_pipeline_try_format(ctx, &mf, &ffmt, false);
+               fimc_md_graph_unlock(fimc);
+
+               pix->width       = mf.width;
+               pix->height      = mf.height;
+               if (ffmt)
+                       pix->pixelformat = ffmt->fourcc;
        }
 
-       /* Output DMA frame pixel size and offsets. */
-       frame->f_width = pix->plane_fmt[0].bytesperline * 8
-                       / frame->fmt->depth[0];
-       frame->f_height = pix->height;
-       frame->width    = pix->width;
-       frame->height   = pix->height;
-       frame->o_width  = pix->width;
-       frame->o_height = pix->height;
-       frame->offs_h   = 0;
-       frame->offs_v   = 0;
+       fimc_adjust_mplane_format(ffmt, pix->width, pix->height, pix);
+       return 0;
+}
 
-       ctx->state |= (FIMC_PARAMS | FIMC_DST_FMT);
+static void fimc_capture_mark_jpeg_xfer(struct fimc_ctx *ctx, bool jpeg)
+{
+       ctx->scaler.enabled = !jpeg;
+       fimc_ctrls_activate(ctx, !jpeg);
 
-       ret = sync_capture_fmt(ctx);
-       return ret;
+       if (jpeg)
+               set_bit(ST_CAPT_JPEG, &ctx->fimc_dev->state);
+       else
+               clear_bit(ST_CAPT_JPEG, &ctx->fimc_dev->state);
 }
 
-static int fimc_cap_enum_input(struct file *file, void *priv,
-                                    struct v4l2_input *i)
+static int fimc_capture_set_format(struct fimc_dev *fimc, struct v4l2_format *f)
 {
-       struct fimc_ctx *ctx = priv;
-       struct s5p_platform_fimc *pldata = ctx->fimc_dev->pdata;
-       struct s5p_fimc_isp_info *isp_info;
+       struct fimc_ctx *ctx = fimc->vid_cap.ctx;
+       struct v4l2_pix_format_mplane *pix = &f->fmt.pix_mp;
+       struct v4l2_mbus_framefmt *mf = &fimc->vid_cap.mf;
+       struct fimc_frame *ff = &ctx->d_frame;
+       struct fimc_fmt *s_fmt = NULL;
+       int ret, i;
 
-       if (i->index >= pldata->num_clients)
+       if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
                return -EINVAL;
+       if (vb2_is_busy(&fimc->vid_cap.vbq))
+               return -EBUSY;
 
-       isp_info = &pldata->isp_info[i->index];
+       /* Pre-configure format at camera interface input, for JPEG only */
+       if (pix->pixelformat == V4L2_PIX_FMT_JPEG) {
+               fimc_capture_try_format(ctx, &pix->width, &pix->height,
+                                       NULL, &pix->pixelformat,
+                                       FIMC_SD_PAD_SINK);
+               ctx->s_frame.f_width  = pix->width;
+               ctx->s_frame.f_height = pix->height;
+       }
+       /* Try the format at the scaler and the DMA output */
+       ff->fmt = fimc_capture_try_format(ctx, &pix->width, &pix->height,
+                                         NULL, &pix->pixelformat,
+                                         FIMC_SD_PAD_SOURCE);
+       if (!ff->fmt)
+               return -EINVAL;
+       /* Try to match format at the host and the sensor */
+       if (!fimc->vid_cap.user_subdev_api) {
+               mf->code   = ff->fmt->mbus_code;
+               mf->width  = pix->width;
+               mf->height = pix->height;
+
+               fimc_md_graph_lock(fimc);
+               ret = fimc_pipeline_try_format(ctx, mf, &s_fmt, true);
+               fimc_md_graph_unlock(fimc);
+               if (ret)
+                       return ret;
+               pix->width  = mf->width;
+               pix->height = mf->height;
+       }
+       fimc_adjust_mplane_format(ff->fmt, pix->width, pix->height, pix);
+       for (i = 0; i < ff->fmt->colplanes; i++)
+               ff->payload[i] =
+                       (pix->width * pix->height * ff->fmt->depth[i]) / 8;
+
+       set_frame_bounds(ff, pix->width, pix->height);
+       /* Reset the composition rectangle if not yet configured */
+       if (!(ctx->state & FIMC_DST_CROP))
+               set_frame_crop(ff, 0, 0, pix->width, pix->height);
+
+       fimc_capture_mark_jpeg_xfer(ctx, fimc_fmt_is_jpeg(ff->fmt->color));
+
+       /* Reset cropping and set format at the camera interface input */
+       if (!fimc->vid_cap.user_subdev_api) {
+               ctx->s_frame.fmt = s_fmt;
+               set_frame_bounds(&ctx->s_frame, pix->width, pix->height);
+               set_frame_crop(&ctx->s_frame, 0, 0, pix->width, pix->height);
+       }
 
-       i->type = V4L2_INPUT_TYPE_CAMERA;
-       strncpy(i->name, isp_info->board_info->type, 32);
-       return 0;
+       return ret;
 }
 
-static int fimc_cap_s_input(struct file *file, void *priv,
-                                 unsigned int i)
+static int fimc_cap_s_fmt_mplane(struct file *file, void *priv,
+                                struct v4l2_format *f)
 {
-       struct fimc_ctx *ctx = priv;
-       struct fimc_dev *fimc = ctx->fimc_dev;
-       struct s5p_platform_fimc *pdata = fimc->pdata;
-
-       if (fimc_capture_active(ctx->fimc_dev))
-               return -EBUSY;
+       struct fimc_dev *fimc = video_drvdata(file);
 
-       if (i >= pdata->num_clients)
-               return -EINVAL;
+       return fimc_capture_set_format(fimc, f);
+}
 
+static int fimc_cap_enum_input(struct file *file, void *priv,
+                              struct v4l2_input *i)
+{
+       struct fimc_dev *fimc = video_drvdata(file);
+       struct v4l2_subdev *sd = fimc->pipeline.sensor;
 
-       if (fimc->vid_cap.sd) {
-               int ret = v4l2_subdev_call(fimc->vid_cap.sd, core, s_power, 0);
-               if (ret)
-                       err("s_power failed: %d", ret);
+       if (i->index != 0)
+               return -EINVAL;
 
-               clk_disable(fimc->clock[CLK_CAM]);
-       }
+       i->type = V4L2_INPUT_TYPE_CAMERA;
+       if (sd)
+               strlcpy(i->name, sd->name, sizeof(i->name));
+       return 0;
+}
 
-       /* Release the attached sensor subdevice. */
-       fimc_subdev_unregister(fimc);
+static int fimc_cap_s_input(struct file *file, void *priv, unsigned int i)
+{
+       return i == 0 ? i : -EINVAL;
+}
 
-       return fimc_isp_subdev_init(fimc, i);
+static int fimc_cap_g_input(struct file *file, void *priv, unsigned int *i)
+{
+       *i = 0;
+       return 0;
 }
 
-static int fimc_cap_g_input(struct file *file, void *priv,
-                                      unsigned int *i)
+/**
+ * fimc_pipeline_validate - check for formats inconsistencies
+ *                          between source and sink pad of each link
+ *
+ * Return 0 if all formats match or -EPIPE otherwise.
+ */
+static int fimc_pipeline_validate(struct fimc_dev *fimc)
 {
-       struct fimc_ctx *ctx = priv;
-       struct fimc_vid_cap *cap = &ctx->fimc_dev->vid_cap;
+       struct v4l2_subdev_format sink_fmt, src_fmt;
+       struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
+       struct v4l2_subdev *sd;
+       struct media_pad *pad;
+       int ret;
 
-       *i = cap->input_index;
+       /* Start with the video capture node pad */
+       pad = media_entity_remote_source(&vid_cap->vd_pad);
+       if (pad == NULL)
+               return -EPIPE;
+       /* FIMC.{N} subdevice */
+       sd = media_entity_to_v4l2_subdev(pad->entity);
+
+       while (1) {
+               /* Retrieve format at the sink pad */
+               pad = &sd->entity.pads[0];
+               if (!(pad->flags & MEDIA_PAD_FL_SINK))
+                       break;
+               /* Don't call FIMC subdev operation to avoid nested locking */
+               if (sd == fimc->vid_cap.subdev) {
+                       struct fimc_frame *ff = &vid_cap->ctx->s_frame;
+                       sink_fmt.format.width = ff->f_width;
+                       sink_fmt.format.height = ff->f_height;
+                       sink_fmt.format.code = ff->fmt ? ff->fmt->mbus_code : 0;
+               } else {
+                       sink_fmt.pad = pad->index;
+                       sink_fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
+                       ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &sink_fmt);
+                       if (ret < 0 && ret != -ENOIOCTLCMD)
+                               return -EPIPE;
+               }
+               /* Retrieve format at the source pad */
+               pad = media_entity_remote_source(pad);
+               if (pad == NULL ||
+                   media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+                       break;
+
+               sd = media_entity_to_v4l2_subdev(pad->entity);
+               src_fmt.pad = pad->index;
+               src_fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
+               ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &src_fmt);
+               if (ret < 0 && ret != -ENOIOCTLCMD)
+                       return -EPIPE;
+
+               if (src_fmt.format.width != sink_fmt.format.width ||
+                   src_fmt.format.height != sink_fmt.format.height ||
+                   src_fmt.format.code != sink_fmt.format.code)
+                       return -EPIPE;
+       }
        return 0;
 }
 
 static int fimc_cap_streamon(struct file *file, void *priv,
                             enum v4l2_buf_type type)
 {
-       struct fimc_ctx *ctx = priv;
-       struct fimc_dev *fimc = ctx->fimc_dev;
+       struct fimc_dev *fimc = video_drvdata(file);
+       struct fimc_pipeline *p = &fimc->pipeline;
+       int ret;
 
-       if (fimc_capture_active(fimc) || !fimc->vid_cap.sd)
+       if (fimc_capture_active(fimc))
                return -EBUSY;
 
-       if (!(ctx->state & FIMC_DST_FMT)) {
-               v4l2_err(&fimc->vid_cap.v4l2_dev, "Format is not set\n");
-               return -EINVAL;
-       }
+       media_entity_pipeline_start(&p->sensor->entity, p->pipe);
 
+       if (fimc->vid_cap.user_subdev_api) {
+               ret = fimc_pipeline_validate(fimc);
+               if (ret)
+                       return ret;
+       }
        return vb2_streamon(&fimc->vid_cap.vbq, type);
 }
 
 static int fimc_cap_streamoff(struct file *file, void *priv,
                            enum v4l2_buf_type type)
 {
-       struct fimc_ctx *ctx = priv;
-       struct fimc_dev *fimc = ctx->fimc_dev;
+       struct fimc_dev *fimc = video_drvdata(file);
+       struct v4l2_subdev *sd = fimc->pipeline.sensor;
+       int ret;
 
-       return vb2_streamoff(&fimc->vid_cap.vbq, type);
+       ret = vb2_streamoff(&fimc->vid_cap.vbq, type);
+       if (ret == 0)
+               media_entity_pipeline_stop(&sd->entity);
+       return ret;
 }
 
 static int fimc_cap_reqbufs(struct file *file, void *priv,
                            struct v4l2_requestbuffers *reqbufs)
 {
-       struct fimc_ctx *ctx = priv;
-       struct fimc_vid_cap *cap = &ctx->fimc_dev->vid_cap;
-       int ret;
-
+       struct fimc_dev *fimc = video_drvdata(file);
+       int ret = vb2_reqbufs(&fimc->vid_cap.vbq, reqbufs);
 
-       ret = vb2_reqbufs(&cap->vbq, reqbufs);
        if (!ret)
-               cap->reqbufs_count = reqbufs->count;
-
+               fimc->vid_cap.reqbufs_count = reqbufs->count;
        return ret;
 }
 
 static int fimc_cap_querybuf(struct file *file, void *priv,
                           struct v4l2_buffer *buf)
 {
-       struct fimc_ctx *ctx = priv;
-       struct fimc_vid_cap *cap = &ctx->fimc_dev->vid_cap;
+       struct fimc_dev *fimc = video_drvdata(file);
 
-       return vb2_querybuf(&cap->vbq, buf);
+       return vb2_querybuf(&fimc->vid_cap.vbq, buf);
 }
 
 static int fimc_cap_qbuf(struct file *file, void *priv,
                          struct v4l2_buffer *buf)
 {
-       struct fimc_ctx *ctx = priv;
-       struct fimc_vid_cap *cap = &ctx->fimc_dev->vid_cap;
-       return vb2_qbuf(&cap->vbq, buf);
+       struct fimc_dev *fimc = video_drvdata(file);
+
+       return vb2_qbuf(&fimc->vid_cap.vbq, buf);
 }
 
 static int fimc_cap_dqbuf(struct file *file, void *priv,
                           struct v4l2_buffer *buf)
 {
-       struct fimc_ctx *ctx = priv;
-       return vb2_dqbuf(&ctx->fimc_dev->vid_cap.vbq, buf,
-               file->f_flags & O_NONBLOCK);
-}
-
-static int fimc_cap_s_ctrl(struct file *file, void *priv,
-                        struct v4l2_control *ctrl)
-{
-       struct fimc_ctx *ctx = priv;
-       int ret = -EINVAL;
+       struct fimc_dev *fimc = video_drvdata(file);
 
-       /* Allow any controls but 90/270 rotation while streaming */
-       if (!fimc_capture_active(ctx->fimc_dev) ||
-           ctrl->id != V4L2_CID_ROTATE ||
-           (ctrl->value != 90 && ctrl->value != 270)) {
-               ret = check_ctrl_val(ctx, ctrl);
-               if (!ret) {
-                       ret = fimc_s_ctrl(ctx, ctrl);
-                       if (!ret)
-                               ctx->state |= FIMC_PARAMS;
-               }
-       }
-       if (ret == -EINVAL)
-               ret = v4l2_subdev_call(ctx->fimc_dev->vid_cap.sd,
-                                      core, s_ctrl, ctrl);
-       return ret;
+       return vb2_dqbuf(&fimc->vid_cap.vbq, buf, file->f_flags & O_NONBLOCK);
 }
 
 static int fimc_cap_cropcap(struct file *file, void *fh,
                            struct v4l2_cropcap *cr)
 {
-       struct fimc_frame *f;
-       struct fimc_ctx *ctx = fh;
+       struct fimc_dev *fimc = video_drvdata(file);
+       struct fimc_frame *f = &fimc->vid_cap.ctx->s_frame;
 
        if (cr->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
                return -EINVAL;
 
-       f = &ctx->s_frame;
-
        cr->bounds.left         = 0;
        cr->bounds.top          = 0;
        cr->bounds.width        = f->o_width;
@@ -709,10 +1027,8 @@ static int fimc_cap_cropcap(struct file *file, void *fh,
 
 static int fimc_cap_g_crop(struct file *file, void *fh, struct v4l2_crop *cr)
 {
-       struct fimc_frame *f;
-       struct fimc_ctx *ctx = file->private_data;
-
-       f = &ctx->s_frame;
+       struct fimc_dev *fimc = video_drvdata(file);
+       struct fimc_frame *f = &fimc->vid_cap.ctx->s_frame;
 
        cr->c.left      = f->offs_h;
        cr->c.top       = f->offs_v;
@@ -722,53 +1038,31 @@ static int fimc_cap_g_crop(struct file *file, void *fh, struct v4l2_crop *cr)
        return 0;
 }
 
-static int fimc_cap_s_crop(struct file *file, void *fh,
-                              struct v4l2_crop *cr)
+static int fimc_cap_s_crop(struct file *file, void *fh, struct v4l2_crop *cr)
 {
-       struct fimc_frame *f;
-       struct fimc_ctx *ctx = file->private_data;
-       struct fimc_dev *fimc = ctx->fimc_dev;
-       int ret = -EINVAL;
-
-       if (fimc_capture_active(fimc))
-               return -EBUSY;
-
-       ret = fimc_try_crop(ctx, cr);
-       if (ret)
-               return ret;
-
-       if (!(ctx->state & FIMC_DST_FMT)) {
-               v4l2_err(&fimc->vid_cap.v4l2_dev,
-                        "Capture color format not set\n");
-               return -EINVAL; /* TODO: make sure this is the right value */
-       }
+       struct fimc_dev *fimc = video_drvdata(file);
+       struct fimc_ctx *ctx = fimc->vid_cap.ctx;
+       struct fimc_frame *ff;
+       unsigned long flags;
 
-       f = &ctx->s_frame;
-       /* Check for the pixel scaling ratio when cropping input image. */
-       ret = fimc_check_scaler_ratio(cr->c.width, cr->c.height,
-                                     ctx->d_frame.width, ctx->d_frame.height,
-                                     ctx->rotation);
-       if (ret) {
-               v4l2_err(&fimc->vid_cap.v4l2_dev, "Out of the scaler range\n");
-               return ret;
-       }
+       fimc_capture_try_crop(ctx, &cr->c, FIMC_SD_PAD_SINK);
+       ff = &ctx->s_frame;
 
-       f->offs_h = cr->c.left;
-       f->offs_v = cr->c.top;
-       f->width  = cr->c.width;
-       f->height = cr->c.height;
+       spin_lock_irqsave(&fimc->slock, flags);
+       set_frame_crop(ff, cr->c.left, cr->c.top, cr->c.width, cr->c.height);
+       set_bit(ST_CAPT_APPLY_CFG, &fimc->state);
+       spin_unlock_irqrestore(&fimc->slock, flags);
 
        return 0;
 }
 
-
 static const struct v4l2_ioctl_ops fimc_capture_ioctl_ops = {
        .vidioc_querycap                = fimc_vidioc_querycap_capture,
 
-       .vidioc_enum_fmt_vid_cap_mplane = fimc_vidioc_enum_fmt_mplane,
-       .vidioc_try_fmt_vid_cap_mplane  = fimc_vidioc_try_fmt_mplane,
+       .vidioc_enum_fmt_vid_cap_mplane = fimc_cap_enum_fmt_mplane,
+       .vidioc_try_fmt_vid_cap_mplane  = fimc_cap_try_fmt_mplane,
        .vidioc_s_fmt_vid_cap_mplane    = fimc_cap_s_fmt_mplane,
-       .vidioc_g_fmt_vid_cap_mplane    = fimc_vidioc_g_fmt_mplane,
+       .vidioc_g_fmt_vid_cap_mplane    = fimc_cap_g_fmt_mplane,
 
        .vidioc_reqbufs                 = fimc_cap_reqbufs,
        .vidioc_querybuf                = fimc_cap_querybuf,
@@ -779,10 +1073,6 @@ static const struct v4l2_ioctl_ops fimc_capture_ioctl_ops = {
        .vidioc_streamon                = fimc_cap_streamon,
        .vidioc_streamoff               = fimc_cap_streamoff,
 
-       .vidioc_queryctrl               = fimc_vidioc_queryctrl,
-       .vidioc_g_ctrl                  = fimc_vidioc_g_ctrl,
-       .vidioc_s_ctrl                  = fimc_cap_s_ctrl,
-
        .vidioc_g_crop                  = fimc_cap_g_crop,
        .vidioc_s_crop                  = fimc_cap_s_crop,
        .vidioc_cropcap                 = fimc_cap_cropcap,
@@ -792,17 +1082,328 @@ static const struct v4l2_ioctl_ops fimc_capture_ioctl_ops = {
        .vidioc_g_input                 = fimc_cap_g_input,
 };
 
+/* Capture subdev media entity operations */
+static int fimc_link_setup(struct media_entity *entity,
+                          const struct media_pad *local,
+                          const struct media_pad *remote, u32 flags)
+{
+       struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
+       struct fimc_dev *fimc = v4l2_get_subdevdata(sd);
+
+       if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+               return -EINVAL;
+
+       if (WARN_ON(fimc == NULL))
+               return 0;
+
+       dbg("%s --> %s, flags: 0x%x. input: 0x%x",
+           local->entity->name, remote->entity->name, flags,
+           fimc->vid_cap.input);
+
+       if (flags & MEDIA_LNK_FL_ENABLED) {
+               if (fimc->vid_cap.input != 0)
+                       return -EBUSY;
+               fimc->vid_cap.input = sd->grp_id;
+               return 0;
+       }
+
+       fimc->vid_cap.input = 0;
+       return 0;
+}
+
+static const struct media_entity_operations fimc_sd_media_ops = {
+       .link_setup = fimc_link_setup,
+};
+
+/**
+ * fimc_sensor_notify - v4l2_device notification from a sensor subdev
+ * @sd: pointer to a subdev generating the notification
+ * @notification: the notification type, must be S5P_FIMC_TX_END_NOTIFY
+ * @arg: pointer to an u32 type integer that stores the frame payload value
+ *
+ * The End Of Frame notification sent by sensor subdev in its still capture
+ * mode. If there is only a single VSYNC generated by the sensor at the
+ * beginning of a frame transmission, FIMC does not issue the LastIrq
+ * (end of frame) interrupt. And this notification is used to complete the
+ * frame capture and returning a buffer to user-space. Subdev drivers should
+ * call this notification from their last 'End of frame capture' interrupt.
+ */
+void fimc_sensor_notify(struct v4l2_subdev *sd, unsigned int notification,
+                       void *arg)
+{
+       struct fimc_sensor_info *sensor;
+       struct fimc_vid_buffer *buf;
+       struct fimc_md *fmd;
+       struct fimc_dev *fimc;
+       unsigned long flags;
+
+       if (sd == NULL)
+               return;
+
+       sensor = v4l2_get_subdev_hostdata(sd);
+       fmd = entity_to_fimc_mdev(&sd->entity);
+
+       spin_lock_irqsave(&fmd->slock, flags);
+       fimc = sensor ? sensor->host : NULL;
+
+       if (fimc && arg && notification == S5P_FIMC_TX_END_NOTIFY &&
+           test_bit(ST_CAPT_PEND, &fimc->state)) {
+               unsigned long irq_flags;
+               spin_lock_irqsave(&fimc->slock, irq_flags);
+               if (!list_empty(&fimc->vid_cap.active_buf_q)) {
+                       buf = list_entry(fimc->vid_cap.active_buf_q.next,
+                                        struct fimc_vid_buffer, list);
+                       vb2_set_plane_payload(&buf->vb, 0, *((u32 *)arg));
+               }
+               fimc_capture_irq_handler(fimc, true);
+               fimc_deactivate_capture(fimc);
+               spin_unlock_irqrestore(&fimc->slock, irq_flags);
+       }
+       spin_unlock_irqrestore(&fmd->slock, flags);
+}
+
+static int fimc_subdev_enum_mbus_code(struct v4l2_subdev *sd,
+                                     struct v4l2_subdev_fh *fh,
+                                     struct v4l2_subdev_mbus_code_enum *code)
+{
+       struct fimc_fmt *fmt;
+
+       fmt = fimc_find_format(NULL, NULL, FMT_FLAGS_CAM, code->index);
+       if (!fmt)
+               return -EINVAL;
+       code->code = fmt->mbus_code;
+       return 0;
+}
+
+static int fimc_subdev_get_fmt(struct v4l2_subdev *sd,
+                              struct v4l2_subdev_fh *fh,
+                              struct v4l2_subdev_format *fmt)
+{
+       struct fimc_dev *fimc = v4l2_get_subdevdata(sd);
+       struct fimc_ctx *ctx = fimc->vid_cap.ctx;
+       struct v4l2_mbus_framefmt *mf;
+       struct fimc_frame *ff;
+
+       if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
+               mf = v4l2_subdev_get_try_format(fh, fmt->pad);
+               fmt->format = *mf;
+               return 0;
+       }
+       mf = &fmt->format;
+       mf->colorspace = V4L2_COLORSPACE_JPEG;
+       ff = fmt->pad == FIMC_SD_PAD_SINK ? &ctx->s_frame : &ctx->d_frame;
+
+       mutex_lock(&fimc->lock);
+       /* The pixel code is same on both input and output pad */
+       if (!WARN_ON(ctx->s_frame.fmt == NULL))
+               mf->code = ctx->s_frame.fmt->mbus_code;
+       mf->width  = ff->f_width;
+       mf->height = ff->f_height;
+       mutex_unlock(&fimc->lock);
+
+       return 0;
+}
+
+static int fimc_subdev_set_fmt(struct v4l2_subdev *sd,
+                              struct v4l2_subdev_fh *fh,
+                              struct v4l2_subdev_format *fmt)
+{
+       struct fimc_dev *fimc = v4l2_get_subdevdata(sd);
+       struct v4l2_mbus_framefmt *mf = &fmt->format;
+       struct fimc_ctx *ctx = fimc->vid_cap.ctx;
+       struct fimc_frame *ff;
+       struct fimc_fmt *ffmt;
+
+       dbg("pad%d: code: 0x%x, %dx%d",
+           fmt->pad, mf->code, mf->width, mf->height);
+
+       if (fmt->pad == FIMC_SD_PAD_SOURCE &&
+           vb2_is_busy(&fimc->vid_cap.vbq))
+               return -EBUSY;
+
+       mutex_lock(&fimc->lock);
+       ffmt = fimc_capture_try_format(ctx, &mf->width, &mf->height,
+                                      &mf->code, NULL, fmt->pad);
+       mutex_unlock(&fimc->lock);
+       mf->colorspace = V4L2_COLORSPACE_JPEG;
+
+       if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
+               mf = v4l2_subdev_get_try_format(fh, fmt->pad);
+               *mf = fmt->format;
+               return 0;
+       }
+       fimc_capture_mark_jpeg_xfer(ctx, fimc_fmt_is_jpeg(ffmt->color));
+
+       ff = fmt->pad == FIMC_SD_PAD_SINK ?
+               &ctx->s_frame : &ctx->d_frame;
+
+       mutex_lock(&fimc->lock);
+       set_frame_bounds(ff, mf->width, mf->height);
+       ff->fmt = ffmt;
+
+       /* Reset the crop rectangle if required. */
+       if (!(fmt->pad == FIMC_SD_PAD_SOURCE && (ctx->state & FIMC_DST_CROP)))
+               set_frame_crop(ff, 0, 0, mf->width, mf->height);
+
+       if (fmt->pad == FIMC_SD_PAD_SINK)
+               ctx->state &= ~FIMC_DST_CROP;
+       mutex_unlock(&fimc->lock);
+       return 0;
+}
+
+static int fimc_subdev_get_crop(struct v4l2_subdev *sd,
+                               struct v4l2_subdev_fh *fh,
+                               struct v4l2_subdev_crop *crop)
+{
+       struct fimc_dev *fimc = v4l2_get_subdevdata(sd);
+       struct fimc_ctx *ctx = fimc->vid_cap.ctx;
+       struct v4l2_rect *r = &crop->rect;
+       struct fimc_frame *ff;
+
+       if (crop->which == V4L2_SUBDEV_FORMAT_TRY) {
+               crop->rect = *v4l2_subdev_get_try_crop(fh, crop->pad);
+               return 0;
+       }
+       ff = crop->pad == FIMC_SD_PAD_SINK ?
+               &ctx->s_frame : &ctx->d_frame;
+
+       mutex_lock(&fimc->lock);
+       r->left   = ff->offs_h;
+       r->top    = ff->offs_v;
+       r->width  = ff->width;
+       r->height = ff->height;
+       mutex_unlock(&fimc->lock);
+
+       dbg("ff:%p, pad%d: l:%d, t:%d, %dx%d, f_w: %d, f_h: %d",
+           ff, crop->pad, r->left, r->top, r->width, r->height,
+           ff->f_width, ff->f_height);
+
+       return 0;
+}
+
+static int fimc_subdev_set_crop(struct v4l2_subdev *sd,
+                               struct v4l2_subdev_fh *fh,
+                               struct v4l2_subdev_crop *crop)
+{
+       struct fimc_dev *fimc = v4l2_get_subdevdata(sd);
+       struct fimc_ctx *ctx = fimc->vid_cap.ctx;
+       struct v4l2_rect *r = &crop->rect;
+       struct fimc_frame *ff;
+       unsigned long flags;
+
+       dbg("(%d,%d)/%dx%d", r->left, r->top, r->width, r->height);
+
+       ff = crop->pad == FIMC_SD_PAD_SOURCE ?
+               &ctx->d_frame : &ctx->s_frame;
+
+       mutex_lock(&fimc->lock);
+       fimc_capture_try_crop(ctx, r, crop->pad);
+
+       if (crop->which == V4L2_SUBDEV_FORMAT_TRY) {
+               mutex_lock(&fimc->lock);
+               *v4l2_subdev_get_try_crop(fh, crop->pad) = *r;
+               return 0;
+       }
+       spin_lock_irqsave(&fimc->slock, flags);
+       set_frame_crop(ff, r->left, r->top, r->width, r->height);
+       if (crop->pad == FIMC_SD_PAD_SOURCE)
+               ctx->state |= FIMC_DST_CROP;
+
+       set_bit(ST_CAPT_APPLY_CFG, &fimc->state);
+       spin_unlock_irqrestore(&fimc->slock, flags);
+
+       dbg("pad%d: (%d,%d)/%dx%d", crop->pad, r->left, r->top,
+           r->width, r->height);
+
+       mutex_unlock(&fimc->lock);
+       return 0;
+}
+
+static struct v4l2_subdev_pad_ops fimc_subdev_pad_ops = {
+       .enum_mbus_code = fimc_subdev_enum_mbus_code,
+       .get_fmt = fimc_subdev_get_fmt,
+       .set_fmt = fimc_subdev_set_fmt,
+       .get_crop = fimc_subdev_get_crop,
+       .set_crop = fimc_subdev_set_crop,
+};
+
+static struct v4l2_subdev_ops fimc_subdev_ops = {
+       .pad = &fimc_subdev_pad_ops,
+};
+
+static int fimc_create_capture_subdev(struct fimc_dev *fimc,
+                                     struct v4l2_device *v4l2_dev)
+{
+       struct v4l2_subdev *sd;
+       int ret;
+
+       sd = kzalloc(sizeof(*sd), GFP_KERNEL);
+       if (!sd)
+               return -ENOMEM;
+
+       v4l2_subdev_init(sd, &fimc_subdev_ops);
+       sd->flags = V4L2_SUBDEV_FL_HAS_DEVNODE;
+       snprintf(sd->name, sizeof(sd->name), "FIMC.%d", fimc->pdev->id);
+
+       fimc->vid_cap.sd_pads[FIMC_SD_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
+       fimc->vid_cap.sd_pads[FIMC_SD_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;
+       ret = media_entity_init(&sd->entity, FIMC_SD_PADS_NUM,
+                               fimc->vid_cap.sd_pads, 0);
+       if (ret)
+               goto me_err;
+       ret = v4l2_device_register_subdev(v4l2_dev, sd);
+       if (ret)
+               goto sd_err;
+
+       fimc->vid_cap.subdev = sd;
+       v4l2_set_subdevdata(sd, fimc);
+       sd->entity.ops = &fimc_sd_media_ops;
+       return 0;
+sd_err:
+       media_entity_cleanup(&sd->entity);
+me_err:
+       kfree(sd);
+       return ret;
+}
+
+static void fimc_destroy_capture_subdev(struct fimc_dev *fimc)
+{
+       struct v4l2_subdev *sd = fimc->vid_cap.subdev;
+
+       if (!sd)
+               return;
+       media_entity_cleanup(&sd->entity);
+       v4l2_device_unregister_subdev(sd);
+       kfree(sd);
+       sd = NULL;
+}
+
+/* Set default format at the sensor and host interface */
+static int fimc_capture_set_default_format(struct fimc_dev *fimc)
+{
+       struct v4l2_format fmt = {
+               .type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
+               .fmt.pix_mp = {
+                       .width          = 640,
+                       .height         = 480,
+                       .pixelformat    = V4L2_PIX_FMT_YUYV,
+                       .field          = V4L2_FIELD_NONE,
+                       .colorspace     = V4L2_COLORSPACE_JPEG,
+               },
+       };
+
+       return fimc_capture_set_format(fimc, &fmt);
+}
+
 /* fimc->lock must be already initialized */
-int fimc_register_capture_device(struct fimc_dev *fimc)
+int fimc_register_capture_device(struct fimc_dev *fimc,
+                                struct v4l2_device *v4l2_dev)
 {
-       struct v4l2_device *v4l2_dev = &fimc->vid_cap.v4l2_dev;
        struct video_device *vfd;
        struct fimc_vid_cap *vid_cap;
        struct fimc_ctx *ctx;
-       struct v4l2_format f;
-       struct fimc_frame *fr;
        struct vb2_queue *q;
-       int ret;
+       int ret = -ENOMEM;
 
        ctx = kzalloc(sizeof *ctx, GFP_KERNEL);
        if (!ctx)
@@ -812,33 +1413,21 @@ int fimc_register_capture_device(struct fimc_dev *fimc)
        ctx->in_path     = FIMC_CAMERA;
        ctx->out_path    = FIMC_DMA;
        ctx->state       = FIMC_CTX_CAP;
-
-       /* Default format of the output frames */
-       f.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB32;
-       fr = &ctx->d_frame;
-       fr->fmt = find_format(&f, FMT_FLAGS_M2M);
-       fr->width = fr->f_width = fr->o_width = 640;
-       fr->height = fr->f_height = fr->o_height = 480;
-
-       if (!v4l2_dev->name[0])
-               snprintf(v4l2_dev->name, sizeof(v4l2_dev->name),
-                        "%s.capture", dev_name(&fimc->pdev->dev));
-
-       ret = v4l2_device_register(NULL, v4l2_dev);
-       if (ret)
-               goto err_info;
+       ctx->s_frame.fmt = fimc_find_format(NULL, NULL, FMT_FLAGS_CAM, 0);
+       ctx->d_frame.fmt = fimc_find_format(NULL, NULL, FMT_FLAGS_CAM, 0);
 
        vfd = video_device_alloc();
        if (!vfd) {
                v4l2_err(v4l2_dev, "Failed to allocate video device\n");
-               goto err_v4l2_reg;
+               goto err_vd_alloc;
        }
 
-       snprintf(vfd->name, sizeof(vfd->name), "%s:cap",
+       snprintf(vfd->name, sizeof(vfd->name), "%s.capture",
                 dev_name(&fimc->pdev->dev));
 
        vfd->fops       = &fimc_capture_fops;
        vfd->ioctl_ops  = &fimc_capture_ioctl_ops;
+       vfd->v4l2_dev   = v4l2_dev;
        vfd->minor      = -1;
        vfd->release    = video_device_release;
        vfd->lock       = &fimc->lock;
@@ -849,8 +1438,6 @@ int fimc_register_capture_device(struct fimc_dev *fimc)
        vid_cap->active_buf_cnt = 0;
        vid_cap->reqbufs_count  = 0;
        vid_cap->refcnt = 0;
-       /* Default color format for image sensor */
-       vid_cap->fmt.code = V4L2_MBUS_FMT_YUYV8_2X8;
 
        INIT_LIST_HEAD(&vid_cap->pending_buf_q);
        INIT_LIST_HEAD(&vid_cap->active_buf_q);
@@ -868,34 +1455,37 @@ int fimc_register_capture_device(struct fimc_dev *fimc)
 
        vb2_queue_init(q);
 
-       ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1);
-       if (ret) {
-               v4l2_err(v4l2_dev, "Failed to register video device\n");
-               goto err_vd_reg;
-       }
-
-       v4l2_info(v4l2_dev,
-                 "FIMC capture driver registered as /dev/video%d\n",
-                 vfd->num);
+       fimc->vid_cap.vd_pad.flags = MEDIA_PAD_FL_SINK;
+       ret = media_entity_init(&vfd->entity, 1, &fimc->vid_cap.vd_pad, 0);
+       if (ret)
+               goto err_ent;
+       ret = fimc_create_capture_subdev(fimc, v4l2_dev);
+       if (ret)
+               goto err_sd_reg;
 
+       vfd->ctrl_handler = &ctx->ctrl_handler;
        return 0;
 
-err_vd_reg:
+err_sd_reg:
+       media_entity_cleanup(&vfd->entity);
+err_ent:
        video_device_release(vfd);
-err_v4l2_reg:
-       v4l2_device_unregister(v4l2_dev);
-err_info:
+err_vd_alloc:
        kfree(ctx);
-       dev_err(&fimc->pdev->dev, "failed to install\n");
        return ret;
 }
 
 void fimc_unregister_capture_device(struct fimc_dev *fimc)
 {
-       struct fimc_vid_cap *capture = &fimc->vid_cap;
-
-       if (capture->vfd)
-               video_unregister_device(capture->vfd);
+       struct video_device *vfd = fimc->vid_cap.vfd;
 
-       kfree(capture->ctx);
+       if (vfd) {
+               media_entity_cleanup(&vfd->entity);
+               /* Can also be called if video device was
+                  not registered */
+               video_unregister_device(vfd);
+       }
+       fimc_destroy_capture_subdev(fimc);
+       kfree(fimc->vid_cap.ctx);
+       fimc->vid_cap.ctx = NULL;
 }
index aa550666cc0bca77fe372cb93067fd0312c6d327..6c1c9cb5537840bc1fb25ad057e100c093e870be 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/interrupt.h>
 #include <linux/device.h>
 #include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
 #include <linux/list.h>
 #include <linux/io.h>
 #include <linux/slab.h>
 #include <media/videobuf2-dma-contig.h>
 
 #include "fimc-core.h"
+#include "fimc-mdevice.h"
 
 static char *fimc_clocks[MAX_FIMC_CLOCKS] = {
-       "sclk_fimc", "fimc", "sclk_cam"
+       "sclk_fimc", "fimc"
 };
 
 static struct fimc_fmt fimc_formats[] = {
@@ -157,59 +159,28 @@ static struct fimc_fmt fimc_formats[] = {
                .memplanes      = 2,
                .colplanes      = 2,
                .flags          = FMT_FLAGS_M2M,
-       },
-};
-
-static struct v4l2_queryctrl fimc_ctrls[] = {
-       {
-               .id             = V4L2_CID_HFLIP,
-               .type           = V4L2_CTRL_TYPE_BOOLEAN,
-               .name           = "Horizontal flip",
-               .minimum        = 0,
-               .maximum        = 1,
-               .default_value  = 0,
        }, {
-               .id             = V4L2_CID_VFLIP,
-               .type           = V4L2_CTRL_TYPE_BOOLEAN,
-               .name           = "Vertical flip",
-               .minimum        = 0,
-               .maximum        = 1,
-               .default_value  = 0,
-       }, {
-               .id             = V4L2_CID_ROTATE,
-               .type           = V4L2_CTRL_TYPE_INTEGER,
-               .name           = "Rotation (CCW)",
-               .minimum        = 0,
-               .maximum        = 270,
-               .step           = 90,
-               .default_value  = 0,
+               .name           = "JPEG encoded data",
+               .fourcc         = V4L2_PIX_FMT_JPEG,
+               .color          = S5P_FIMC_JPEG,
+               .depth          = { 8 },
+               .memplanes      = 1,
+               .colplanes      = 1,
+               .mbus_code      = V4L2_MBUS_FMT_JPEG_1X8,
+               .flags          = FMT_FLAGS_CAM,
        },
 };
 
-
-static struct v4l2_queryctrl *get_ctrl(int id)
+int fimc_check_scaler_ratio(struct fimc_ctx *ctx, int sw, int sh,
+                           int dw, int dh, int rotation)
 {
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(fimc_ctrls); ++i)
-               if (id == fimc_ctrls[i].id)
-                       return &fimc_ctrls[i];
-       return NULL;
-}
+       if (rotation == 90 || rotation == 270)
+               swap(dw, dh);
 
-int fimc_check_scaler_ratio(int sw, int sh, int dw, int dh, int rot)
-{
-       int tx, ty;
-
-       if (rot == 90 || rot == 270) {
-               ty = dw;
-               tx = dh;
-       } else {
-               tx = dw;
-               ty = dh;
-       }
+       if (!ctx->scaler.enabled)
+               return (sw == dw && sh == dh) ? 0 : -EINVAL;
 
-       if ((sw >= SCALER_MAX_HRATIO * tx) || (sh >= SCALER_MAX_VRATIO * ty))
+       if ((sw >= SCALER_MAX_HRATIO * dw) || (sh >= SCALER_MAX_VRATIO * dh))
                return -EINVAL;
 
        return 0;
@@ -235,10 +206,11 @@ static int fimc_get_scaler_factor(u32 src, u32 tar, u32 *ratio, u32 *shift)
 
 int fimc_set_scaler_info(struct fimc_ctx *ctx)
 {
+       struct samsung_fimc_variant *variant = ctx->fimc_dev->variant;
+       struct device *dev = &ctx->fimc_dev->pdev->dev;
        struct fimc_scaler *sc = &ctx->scaler;
        struct fimc_frame *s_frame = &ctx->s_frame;
        struct fimc_frame *d_frame = &ctx->d_frame;
-       struct samsung_fimc_variant *variant = ctx->fimc_dev->variant;
        int tx, ty, sx, sy;
        int ret;
 
@@ -250,15 +222,14 @@ int fimc_set_scaler_info(struct fimc_ctx *ctx)
                ty = d_frame->height;
        }
        if (tx <= 0 || ty <= 0) {
-               v4l2_err(&ctx->fimc_dev->m2m.v4l2_dev,
-                       "invalid target size: %d x %d", tx, ty);
+               dev_err(dev, "Invalid target size: %dx%d", tx, ty);
                return -EINVAL;
        }
 
        sx = s_frame->width;
        sy = s_frame->height;
        if (sx <= 0 || sy <= 0) {
-               err("invalid source size: %d x %d", sx, sy);
+               dev_err(dev, "Invalid source size: %dx%d", sx, sy);
                return -EINVAL;
        }
        sc->real_width = sx;
@@ -301,7 +272,6 @@ int fimc_set_scaler_info(struct fimc_ctx *ctx)
 static void fimc_m2m_job_finish(struct fimc_ctx *ctx, int vb_state)
 {
        struct vb2_buffer *src_vb, *dst_vb;
-       struct fimc_dev *fimc = ctx->fimc_dev;
 
        if (!ctx || !ctx->m2m_ctx)
                return;
@@ -312,54 +282,68 @@ static void fimc_m2m_job_finish(struct fimc_ctx *ctx, int vb_state)
        if (src_vb && dst_vb) {
                v4l2_m2m_buf_done(src_vb, vb_state);
                v4l2_m2m_buf_done(dst_vb, vb_state);
-               v4l2_m2m_job_finish(fimc->m2m.m2m_dev, ctx->m2m_ctx);
+               v4l2_m2m_job_finish(ctx->fimc_dev->m2m.m2m_dev,
+                                   ctx->m2m_ctx);
        }
 }
 
 /* Complete the transaction which has been scheduled for execution. */
-static void fimc_m2m_shutdown(struct fimc_ctx *ctx)
+static int fimc_m2m_shutdown(struct fimc_ctx *ctx)
 {
        struct fimc_dev *fimc = ctx->fimc_dev;
        int ret;
 
        if (!fimc_m2m_pending(fimc))
-               return;
+               return 0;
 
        fimc_ctx_state_lock_set(FIMC_CTX_SHUT, ctx);
 
        ret = wait_event_timeout(fimc->irq_queue,
                           !fimc_ctx_state_is_set(FIMC_CTX_SHUT, ctx),
                           FIMC_SHUTDOWN_TIMEOUT);
-       /*
-        * In case of a timeout the buffers are not released in the interrupt
-        * handler so return them here with the error flag set, if there are
-        * any on the queue.
-        */
-       if (ret == 0)
-               fimc_m2m_job_finish(ctx, VB2_BUF_STATE_ERROR);
+
+       return ret == 0 ? -ETIMEDOUT : ret;
+}
+
+static int start_streaming(struct vb2_queue *q, unsigned int count)
+{
+       struct fimc_ctx *ctx = q->drv_priv;
+       int ret;
+
+       ret = pm_runtime_get_sync(&ctx->fimc_dev->pdev->dev);
+       return ret > 0 ? 0 : ret;
 }
 
 static int stop_streaming(struct vb2_queue *q)
 {
        struct fimc_ctx *ctx = q->drv_priv;
+       int ret;
 
-       fimc_m2m_shutdown(ctx);
+       ret = fimc_m2m_shutdown(ctx);
+       if (ret == -ETIMEDOUT)
+               fimc_m2m_job_finish(ctx, VB2_BUF_STATE_ERROR);
 
+       pm_runtime_put(&ctx->fimc_dev->pdev->dev);
        return 0;
 }
 
-static void fimc_capture_irq_handler(struct fimc_dev *fimc)
+void fimc_capture_irq_handler(struct fimc_dev *fimc, bool final)
 {
        struct fimc_vid_cap *cap = &fimc->vid_cap;
        struct fimc_vid_buffer *v_buf;
        struct timeval *tv;
        struct timespec ts;
 
+       if (test_and_clear_bit(ST_CAPT_SHUT, &fimc->state)) {
+               wake_up(&fimc->irq_queue);
+               return;
+       }
+
        if (!list_empty(&cap->active_buf_q) &&
-           test_bit(ST_CAPT_RUN, &fimc->state)) {
+           test_bit(ST_CAPT_RUN, &fimc->state) && final) {
                ktime_get_real_ts(&ts);
 
-               v_buf = active_queue_pop(cap);
+               v_buf = fimc_active_queue_pop(cap);
 
                tv = &v_buf->vb.v4l2_buf.timestamp;
                tv->tv_sec = ts.tv_sec;
@@ -369,19 +353,14 @@ static void fimc_capture_irq_handler(struct fimc_dev *fimc)
                vb2_buffer_done(&v_buf->vb, VB2_BUF_STATE_DONE);
        }
 
-       if (test_and_clear_bit(ST_CAPT_SHUT, &fimc->state)) {
-               wake_up(&fimc->irq_queue);
-               return;
-       }
-
        if (!list_empty(&cap->pending_buf_q)) {
 
-               v_buf = pending_queue_pop(cap);
+               v_buf = fimc_pending_queue_pop(cap);
                fimc_hw_set_output_addr(fimc, &v_buf->paddr, cap->buf_index);
                v_buf->index = cap->buf_index;
 
                /* Move the buffer to the capture active queue */
-               active_queue_add(cap, v_buf);
+               fimc_active_queue_add(cap, v_buf);
 
                dbg("next frame: %d, done frame: %d",
                    fimc_hw_get_frame_index(fimc), v_buf->index);
@@ -391,7 +370,8 @@ static void fimc_capture_irq_handler(struct fimc_dev *fimc)
        }
 
        if (cap->active_buf_cnt == 0) {
-               clear_bit(ST_CAPT_RUN, &fimc->state);
+               if (final)
+                       clear_bit(ST_CAPT_RUN, &fimc->state);
 
                if (++cap->buf_index >= FIMC_MAX_OUT_BUFS)
                        cap->buf_index = 0;
@@ -399,11 +379,13 @@ static void fimc_capture_irq_handler(struct fimc_dev *fimc)
                set_bit(ST_CAPT_RUN, &fimc->state);
        }
 
+       fimc_capture_config_update(cap->ctx);
+
        dbg("frame: %d, active_buf_cnt: %d",
            fimc_hw_get_frame_index(fimc), cap->active_buf_cnt);
 }
 
-static irqreturn_t fimc_isr(int irq, void *priv)
+static irqreturn_t fimc_irq_handler(int irq, void *priv)
 {
        struct fimc_dev *fimc = priv;
        struct fimc_vid_cap *cap = &fimc->vid_cap;
@@ -411,9 +393,17 @@ static irqreturn_t fimc_isr(int irq, void *priv)
 
        fimc_hw_clear_irq(fimc);
 
+       spin_lock(&fimc->slock);
+
        if (test_and_clear_bit(ST_M2M_PEND, &fimc->state)) {
+               if (test_and_clear_bit(ST_M2M_SUSPENDING, &fimc->state)) {
+                       set_bit(ST_M2M_SUSPENDED, &fimc->state);
+                       wake_up(&fimc->irq_queue);
+                       goto out;
+               }
                ctx = v4l2_m2m_get_curr_priv(fimc->m2m.m2m_dev);
                if (ctx != NULL) {
+                       spin_unlock(&fimc->slock);
                        fimc_m2m_job_finish(ctx, VB2_BUF_STATE_DONE);
 
                        spin_lock(&ctx->slock);
@@ -423,21 +413,16 @@ static irqreturn_t fimc_isr(int irq, void *priv)
                        }
                        spin_unlock(&ctx->slock);
                }
-
                return IRQ_HANDLED;
-       }
-
-       spin_lock(&fimc->slock);
-
-       if (test_bit(ST_CAPT_PEND, &fimc->state)) {
-               fimc_capture_irq_handler(fimc);
-
+       } else if (test_bit(ST_CAPT_PEND, &fimc->state)) {
+               fimc_capture_irq_handler(fimc,
+                                !test_bit(ST_CAPT_JPEG, &fimc->state));
                if (cap->active_buf_cnt == 1) {
                        fimc_deactivate_capture(fimc);
                        clear_bit(ST_CAPT_STREAM, &fimc->state);
                }
        }
-
+out:
        spin_unlock(&fimc->slock);
        return IRQ_HANDLED;
 }
@@ -457,7 +442,7 @@ int fimc_prepare_addr(struct fimc_ctx *ctx, struct vb2_buffer *vb,
        dbg("memplanes= %d, colplanes= %d, pix_size= %d",
                frame->fmt->memplanes, frame->fmt->colplanes, pix_size);
 
-       paddr->y = vb2_dma_contig_plane_paddr(vb, 0);
+       paddr->y = vb2_dma_contig_plane_dma_addr(vb, 0);
 
        if (frame->fmt->memplanes == 1) {
                switch (frame->fmt->colplanes) {
@@ -485,10 +470,10 @@ int fimc_prepare_addr(struct fimc_ctx *ctx, struct vb2_buffer *vb,
                }
        } else {
                if (frame->fmt->memplanes >= 2)
-                       paddr->cb = vb2_dma_contig_plane_paddr(vb, 1);
+                       paddr->cb = vb2_dma_contig_plane_dma_addr(vb, 1);
 
                if (frame->fmt->memplanes == 3)
-                       paddr->cr = vb2_dma_contig_plane_paddr(vb, 2);
+                       paddr->cr = vb2_dma_contig_plane_dma_addr(vb, 2);
        }
 
        dbg("PHYS_ADDR: y= 0x%X  cb= 0x%X cr= 0x%X ret= %d",
@@ -498,7 +483,7 @@ int fimc_prepare_addr(struct fimc_ctx *ctx, struct vb2_buffer *vb,
 }
 
 /* Set order for 1 and 2 plane YCBCR 4:2:2 formats. */
-static void fimc_set_yuv_order(struct fimc_ctx *ctx)
+void fimc_set_yuv_order(struct fimc_ctx *ctx)
 {
        /* The one only mode supported in SoC. */
        ctx->in_order_2p = S5P_FIMC_LSB_CRCB;
@@ -540,7 +525,7 @@ static void fimc_set_yuv_order(struct fimc_ctx *ctx)
        dbg("ctx->out_order_1p= %d", ctx->out_order_1p);
 }
 
-static void fimc_prepare_dma_offset(struct fimc_ctx *ctx, struct fimc_frame *f)
+void fimc_prepare_dma_offset(struct fimc_ctx *ctx, struct fimc_frame *f)
 {
        struct samsung_fimc_variant *variant = ctx->fimc_dev->variant;
        u32 i, depth = 0;
@@ -606,9 +591,6 @@ int fimc_prepare_config(struct fimc_ctx *ctx, u32 flags)
                fimc_set_yuv_order(ctx);
        }
 
-       /* Input DMA mode is not allowed when the scaler is disabled. */
-       ctx->scaler.enabled = 1;
-
        if (flags & FIMC_SRC_ADDR) {
                vb = v4l2_m2m_next_src_buf(ctx->m2m_ctx);
                ret = fimc_prepare_addr(ctx, vb, s_frame, &s_frame->paddr);
@@ -635,10 +617,10 @@ static void fimc_dma_run(void *priv)
                return;
 
        fimc = ctx->fimc_dev;
-
-       spin_lock_irqsave(&ctx->slock, flags);
+       spin_lock_irqsave(&fimc->slock, flags);
        set_bit(ST_M2M_PEND, &fimc->state);
 
+       spin_lock(&ctx->slock);
        ctx->state |= (FIMC_SRC_ADDR | FIMC_DST_ADDR);
        ret = fimc_prepare_config(ctx, ctx->state);
        if (ret)
@@ -649,8 +631,6 @@ static void fimc_dma_run(void *priv)
                ctx->state |= FIMC_PARAMS;
                fimc->m2m.ctx = ctx;
        }
-
-       spin_lock(&fimc->slock);
        fimc_hw_set_input_addr(fimc, &ctx->s_frame.paddr);
 
        if (ctx->state & FIMC_PARAMS) {
@@ -665,7 +645,7 @@ static void fimc_dma_run(void *priv)
                fimc_hw_set_mainscaler(ctx);
                fimc_hw_set_target_format(ctx);
                fimc_hw_set_rotation(ctx);
-               fimc_hw_set_effect(ctx);
+               fimc_hw_set_effect(ctx, false);
        }
 
        fimc_hw_set_output_path(ctx);
@@ -680,10 +660,9 @@ static void fimc_dma_run(void *priv)
        ctx->state &= (FIMC_CTX_M2M | FIMC_CTX_CAP |
                       FIMC_SRC_FMT | FIMC_DST_FMT);
        fimc_hw_activate_input_dma(fimc, true);
-       spin_unlock(&fimc->slock);
-
 dma_unlock:
-       spin_unlock_irqrestore(&ctx->slock, flags);
+       spin_unlock(&ctx->slock);
+       spin_unlock_irqrestore(&fimc->slock, flags);
 }
 
 static void fimc_job_abort(void *priv)
@@ -692,7 +671,7 @@ static void fimc_job_abort(void *priv)
 }
 
 static int fimc_queue_setup(struct vb2_queue *vq, unsigned int *num_buffers,
-                           unsigned int *num_planes, unsigned long sizes[],
+                           unsigned int *num_planes, unsigned int sizes[],
                            void *allocators[])
 {
        struct fimc_ctx *ctx = vb2_get_drv_priv(vq);
@@ -762,146 +741,296 @@ static struct vb2_ops fimc_qops = {
        .wait_prepare    = fimc_unlock,
        .wait_finish     = fimc_lock,
        .stop_streaming  = stop_streaming,
+       .start_streaming = start_streaming,
 };
 
-static int fimc_m2m_querycap(struct file *file, void *priv,
-                          struct v4l2_capability *cap)
+/*
+ * V4L2 controls handling
+ */
+#define ctrl_to_ctx(__ctrl) \
+       container_of((__ctrl)->handler, struct fimc_ctx, ctrl_handler)
+
+static int fimc_s_ctrl(struct v4l2_ctrl *ctrl)
 {
-       struct fimc_ctx *ctx = file->private_data;
+       struct fimc_ctx *ctx = ctrl_to_ctx(ctrl);
+       struct fimc_dev *fimc = ctx->fimc_dev;
+       struct samsung_fimc_variant *variant = fimc->variant;
+       unsigned long flags;
+       int ret = 0;
+
+       if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE)
+               return 0;
+
+       switch (ctrl->id) {
+       case V4L2_CID_HFLIP:
+               spin_lock_irqsave(&ctx->slock, flags);
+               ctx->hflip = ctrl->val;
+               break;
+
+       case V4L2_CID_VFLIP:
+               spin_lock_irqsave(&ctx->slock, flags);
+               ctx->vflip = ctrl->val;
+               break;
+
+       case V4L2_CID_ROTATE:
+               if (fimc_capture_pending(fimc) ||
+                   fimc_ctx_state_is_set(FIMC_DST_FMT | FIMC_SRC_FMT, ctx)) {
+                       ret = fimc_check_scaler_ratio(ctx, ctx->s_frame.width,
+                                       ctx->s_frame.height, ctx->d_frame.width,
+                                       ctx->d_frame.height, ctrl->val);
+               }
+               if (ret) {
+                       v4l2_err(fimc->m2m.vfd, "Out of scaler range\n");
+                       return -EINVAL;
+               }
+               if ((ctrl->val == 90 || ctrl->val == 270) &&
+                   !variant->has_out_rot)
+                       return -EINVAL;
+               spin_lock_irqsave(&ctx->slock, flags);
+               ctx->rotation = ctrl->val;
+               break;
+
+       default:
+               v4l2_err(fimc->v4l2_dev, "Invalid control: 0x%X\n", ctrl->id);
+               return -EINVAL;
+       }
+       ctx->state |= FIMC_PARAMS;
+       set_bit(ST_CAPT_APPLY_CFG, &fimc->state);
+       spin_unlock_irqrestore(&ctx->slock, flags);
+       return 0;
+}
+
+static const struct v4l2_ctrl_ops fimc_ctrl_ops = {
+       .s_ctrl = fimc_s_ctrl,
+};
+
+int fimc_ctrls_create(struct fimc_ctx *ctx)
+{
+       if (ctx->ctrls_rdy)
+               return 0;
+       v4l2_ctrl_handler_init(&ctx->ctrl_handler, 3);
+
+       ctx->ctrl_rotate = v4l2_ctrl_new_std(&ctx->ctrl_handler, &fimc_ctrl_ops,
+                                    V4L2_CID_HFLIP, 0, 1, 1, 0);
+       ctx->ctrl_hflip = v4l2_ctrl_new_std(&ctx->ctrl_handler, &fimc_ctrl_ops,
+                                   V4L2_CID_VFLIP, 0, 1, 1, 0);
+       ctx->ctrl_vflip = v4l2_ctrl_new_std(&ctx->ctrl_handler, &fimc_ctrl_ops,
+                                   V4L2_CID_ROTATE, 0, 270, 90, 0);
+       ctx->ctrls_rdy = ctx->ctrl_handler.error == 0;
+
+       return ctx->ctrl_handler.error;
+}
+
+void fimc_ctrls_delete(struct fimc_ctx *ctx)
+{
+       if (ctx->ctrls_rdy) {
+               v4l2_ctrl_handler_free(&ctx->ctrl_handler);
+               ctx->ctrls_rdy = false;
+       }
+}
+
+void fimc_ctrls_activate(struct fimc_ctx *ctx, bool active)
+{
+       if (!ctx->ctrls_rdy)
+               return;
+
+       mutex_lock(&ctx->ctrl_handler.lock);
+       v4l2_ctrl_activate(ctx->ctrl_rotate, active);
+       v4l2_ctrl_activate(ctx->ctrl_hflip, active);
+       v4l2_ctrl_activate(ctx->ctrl_vflip, active);
+
+       if (active) {
+               ctx->rotation = ctx->ctrl_rotate->val;
+               ctx->hflip    = ctx->ctrl_hflip->val;
+               ctx->vflip    = ctx->ctrl_vflip->val;
+       } else {
+               ctx->rotation = 0;
+               ctx->hflip    = 0;
+               ctx->vflip    = 0;
+       }
+       mutex_unlock(&ctx->ctrl_handler.lock);
+}
+
+/*
+ * V4L2 ioctl handlers
+ */
+static int fimc_m2m_querycap(struct file *file, void *fh,
+                            struct v4l2_capability *cap)
+{
+       struct fimc_ctx *ctx = fh_to_ctx(fh);
        struct fimc_dev *fimc = ctx->fimc_dev;
 
        strncpy(cap->driver, fimc->pdev->name, sizeof(cap->driver) - 1);
        strncpy(cap->card, fimc->pdev->name, sizeof(cap->card) - 1);
        cap->bus_info[0] = 0;
        cap->capabilities = V4L2_CAP_STREAMING |
-               V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OUTPUT |
                V4L2_CAP_VIDEO_CAPTURE_MPLANE | V4L2_CAP_VIDEO_OUTPUT_MPLANE;
 
        return 0;
 }
 
-int fimc_vidioc_enum_fmt_mplane(struct file *file, void *priv,
-                               struct v4l2_fmtdesc *f)
+static int fimc_m2m_enum_fmt_mplane(struct file *file, void *priv,
+                                   struct v4l2_fmtdesc *f)
 {
        struct fimc_fmt *fmt;
 
-       if (f->index >= ARRAY_SIZE(fimc_formats))
+       fmt = fimc_find_format(NULL, NULL, FMT_FLAGS_M2M, f->index);
+       if (!fmt)
                return -EINVAL;
 
-       fmt = &fimc_formats[f->index];
        strncpy(f->description, fmt->name, sizeof(f->description) - 1);
        f->pixelformat = fmt->fourcc;
-
        return 0;
 }
 
-int fimc_vidioc_g_fmt_mplane(struct file *file, void *priv,
-                            struct v4l2_format *f)
+int fimc_fill_format(struct fimc_frame *frame, struct v4l2_format *f)
 {
-       struct fimc_ctx *ctx = priv;
-       struct fimc_frame *frame;
-       struct v4l2_pix_format_mplane *pixm;
+       struct v4l2_pix_format_mplane *pixm = &f->fmt.pix_mp;
        int i;
 
-       frame = ctx_get_frame(ctx, f->type);
-       if (IS_ERR(frame))
-               return PTR_ERR(frame);
-
-       pixm = &f->fmt.pix_mp;
-
-       pixm->width             = frame->width;
-       pixm->height            = frame->height;
-       pixm->field             = V4L2_FIELD_NONE;
-       pixm->pixelformat       = frame->fmt->fourcc;
-       pixm->colorspace        = V4L2_COLORSPACE_JPEG;
-       pixm->num_planes        = frame->fmt->memplanes;
+       pixm->width = frame->o_width;
+       pixm->height = frame->o_height;
+       pixm->field = V4L2_FIELD_NONE;
+       pixm->pixelformat = frame->fmt->fourcc;
+       pixm->colorspace = V4L2_COLORSPACE_JPEG;
+       pixm->num_planes = frame->fmt->memplanes;
 
        for (i = 0; i < pixm->num_planes; ++i) {
-               int bpl = frame->o_width;
-
+               int bpl = frame->f_width;
                if (frame->fmt->colplanes == 1) /* packed formats */
                        bpl = (bpl * frame->fmt->depth[0]) / 8;
-
                pixm->plane_fmt[i].bytesperline = bpl;
-
                pixm->plane_fmt[i].sizeimage = (frame->o_width *
                        frame->o_height * frame->fmt->depth[i]) / 8;
        }
-
        return 0;
 }
 
-struct fimc_fmt *find_format(struct v4l2_format *f, unsigned int mask)
+void fimc_fill_frame(struct fimc_frame *frame, struct v4l2_format *f)
 {
-       struct fimc_fmt *fmt;
-       unsigned int i;
+       struct v4l2_pix_format_mplane *pixm = &f->fmt.pix_mp;
+
+       frame->f_width  = pixm->plane_fmt[0].bytesperline;
+       if (frame->fmt->colplanes == 1)
+               frame->f_width = (frame->f_width * 8) / frame->fmt->depth[0];
+       frame->f_height = pixm->height;
+       frame->width    = pixm->width;
+       frame->height   = pixm->height;
+       frame->o_width  = pixm->width;
+       frame->o_height = pixm->height;
+       frame->offs_h   = 0;
+       frame->offs_v   = 0;
+}
 
-       for (i = 0; i < ARRAY_SIZE(fimc_formats); ++i) {
-               fmt = &fimc_formats[i];
-               if (fmt->fourcc == f->fmt.pix_mp.pixelformat &&
-                  (fmt->flags & mask))
-                       break;
+/**
+ * fimc_adjust_mplane_format - adjust bytesperline/sizeimage for each plane
+ * @fmt: fimc pixel format description (input)
+ * @width: requested pixel width
+ * @height: requested pixel height
+ * @pix: multi-plane format to adjust
+ */
+void fimc_adjust_mplane_format(struct fimc_fmt *fmt, u32 width, u32 height,
+                              struct v4l2_pix_format_mplane *pix)
+{
+       u32 bytesperline = 0;
+       int i;
+
+       pix->colorspace = V4L2_COLORSPACE_JPEG;
+       pix->field = V4L2_FIELD_NONE;
+       pix->num_planes = fmt->memplanes;
+       pix->height = height;
+       pix->width = width;
+
+       for (i = 0; i < pix->num_planes; ++i) {
+               u32 bpl = pix->plane_fmt[i].bytesperline;
+               u32 *sizeimage = &pix->plane_fmt[i].sizeimage;
+
+               if (fmt->colplanes > 1 && (bpl == 0 || bpl < pix->width))
+                       bpl = pix->width; /* Planar */
+
+               if (fmt->colplanes == 1 && /* Packed */
+                   (bpl == 0 || ((bpl * 8) / fmt->depth[i]) < pix->width))
+                       bpl = (pix->width * fmt->depth[0]) / 8;
+
+               if (i == 0) /* Same bytesperline for each plane. */
+                       bytesperline = bpl;
+
+               pix->plane_fmt[i].bytesperline = bytesperline;
+               *sizeimage = (pix->width * pix->height * fmt->depth[i]) / 8;
        }
+}
 
-       return (i == ARRAY_SIZE(fimc_formats)) ? NULL : fmt;
+static int fimc_m2m_g_fmt_mplane(struct file *file, void *fh,
+                                struct v4l2_format *f)
+{
+       struct fimc_ctx *ctx = fh_to_ctx(fh);
+       struct fimc_frame *frame = ctx_get_frame(ctx, f->type);
+
+       if (IS_ERR(frame))
+               return PTR_ERR(frame);
+
+       return fimc_fill_format(frame, f);
 }
 
-struct fimc_fmt *find_mbus_format(struct v4l2_mbus_framefmt *f,
-                                 unsigned int mask)
+/**
+ * fimc_find_format - lookup fimc color format by fourcc or media bus format
+ * @pixelformat: fourcc to match, ignored if null
+ * @mbus_code: media bus code to match, ignored if null
+ * @mask: the color flags to match
+ * @index: offset in the fimc_formats array, ignored if negative
+ */
+struct fimc_fmt *fimc_find_format(u32 *pixelformat, u32 *mbus_code,
+                                 unsigned int mask, int index)
 {
-       struct fimc_fmt *fmt;
+       struct fimc_fmt *fmt, *def_fmt = NULL;
        unsigned int i;
+       int id = 0;
+
+       if (index >= ARRAY_SIZE(fimc_formats))
+               return NULL;
 
        for (i = 0; i < ARRAY_SIZE(fimc_formats); ++i) {
                fmt = &fimc_formats[i];
-               if (fmt->mbus_code == f->code && (fmt->flags & mask))
-                       break;
+               if (!(fmt->flags & mask))
+                       continue;
+               if (pixelformat && fmt->fourcc == *pixelformat)
+                       return fmt;
+               if (mbus_code && fmt->mbus_code == *mbus_code)
+                       return fmt;
+               if (index == id)
+                       def_fmt = fmt;
+               id++;
        }
-
-       return (i == ARRAY_SIZE(fimc_formats)) ? NULL : fmt;
+       return def_fmt;
 }
 
-
-int fimc_vidioc_try_fmt_mplane(struct file *file, void *priv,
-                              struct v4l2_format *f)
+static int fimc_try_fmt_mplane(struct fimc_ctx *ctx, struct v4l2_format *f)
 {
-       struct fimc_ctx *ctx = priv;
        struct fimc_dev *fimc = ctx->fimc_dev;
        struct samsung_fimc_variant *variant = fimc->variant;
        struct v4l2_pix_format_mplane *pix = &f->fmt.pix_mp;
        struct fimc_fmt *fmt;
-       u32 max_width, mod_x, mod_y, mask;
-       int i, is_output = 0;
-
+       u32 max_w, mod_x, mod_y;
 
-       if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
-               if (fimc_ctx_state_is_set(FIMC_CTX_CAP, ctx))
-                       return -EINVAL;
-               is_output = 1;
-       } else if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
+       if (!IS_M2M(f->type))
                return -EINVAL;
-       }
 
        dbg("w: %d, h: %d", pix->width, pix->height);
 
-       mask = is_output ? FMT_FLAGS_M2M : FMT_FLAGS_M2M | FMT_FLAGS_CAM;
-       fmt = find_format(f, mask);
-       if (!fmt) {
-               v4l2_err(&fimc->m2m.v4l2_dev, "Fourcc format (0x%X) invalid.\n",
-                        pix->pixelformat);
+       fmt = fimc_find_format(&pix->pixelformat, NULL, FMT_FLAGS_M2M, 0);
+       if (WARN(fmt == NULL, "Pixel format lookup failed"))
                return -EINVAL;
-       }
 
        if (pix->field == V4L2_FIELD_ANY)
                pix->field = V4L2_FIELD_NONE;
-       else if (V4L2_FIELD_NONE != pix->field)
+       else if (pix->field != V4L2_FIELD_NONE)
                return -EINVAL;
 
-       if (is_output) {
-               max_width = variant->pix_limit->scaler_dis_w;
+       if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
+               max_w = variant->pix_limit->scaler_dis_w;
                mod_x = ffs(variant->min_inp_pixsize) - 1;
        } else {
-               max_width = variant->pix_limit->out_rot_dis_w;
+               max_w = variant->pix_limit->out_rot_dis_w;
                mod_x = ffs(variant->min_out_pixsize) - 1;
        }
 
@@ -914,70 +1043,52 @@ int fimc_vidioc_try_fmt_mplane(struct file *file, void *priv,
                else
                        mod_y = mod_x;
        }
+       dbg("mod_x: %d, mod_y: %d, max_w: %d", mod_x, mod_y, max_w);
 
-       dbg("mod_x: %d, mod_y: %d, max_w: %d", mod_x, mod_y, max_width);
-
-       v4l_bound_align_image(&pix->width, 16, max_width, mod_x,
+       v4l_bound_align_image(&pix->width, 16, max_w, mod_x,
                &pix->height, 8, variant->pix_limit->scaler_dis_w, mod_y, 0);
 
-       pix->num_planes = fmt->memplanes;
-       pix->colorspace = V4L2_COLORSPACE_JPEG;
-
-
-       for (i = 0; i < pix->num_planes; ++i) {
-               u32 bpl = pix->plane_fmt[i].bytesperline;
-               u32 *sizeimage = &pix->plane_fmt[i].sizeimage;
-
-               if (fmt->colplanes > 1 && (bpl == 0 || bpl < pix->width))
-                       bpl = pix->width; /* Planar */
-
-               if (fmt->colplanes == 1 && /* Packed */
-                   (bpl == 0 || ((bpl * 8) / fmt->depth[i]) < pix->width))
-                       bpl = (pix->width * fmt->depth[0]) / 8;
-
-               if (i == 0) /* Same bytesperline for each plane. */
-                       mod_x = bpl;
+       fimc_adjust_mplane_format(fmt, pix->width, pix->height, &f->fmt.pix_mp);
+       return 0;
+}
 
-               pix->plane_fmt[i].bytesperline = mod_x;
-               *sizeimage = (pix->width * pix->height * fmt->depth[i]) / 8;
-       }
+static int fimc_m2m_try_fmt_mplane(struct file *file, void *fh,
+                                  struct v4l2_format *f)
+{
+       struct fimc_ctx *ctx = fh_to_ctx(fh);
 
-       return 0;
+       return fimc_try_fmt_mplane(ctx, f);
 }
 
-static int fimc_m2m_s_fmt_mplane(struct file *file, void *priv,
+static int fimc_m2m_s_fmt_mplane(struct file *file, void *fh,
                                 struct v4l2_format *f)
 {
-       struct fimc_ctx *ctx = priv;
+       struct fimc_ctx *ctx = fh_to_ctx(fh);
        struct fimc_dev *fimc = ctx->fimc_dev;
        struct vb2_queue *vq;
        struct fimc_frame *frame;
        struct v4l2_pix_format_mplane *pix;
        int i, ret = 0;
 
-       ret = fimc_vidioc_try_fmt_mplane(file, priv, f);
+       ret = fimc_try_fmt_mplane(ctx, f);
        if (ret)
                return ret;
 
        vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type);
 
        if (vb2_is_busy(vq)) {
-               v4l2_err(&fimc->m2m.v4l2_dev, "queue (%d) busy\n", f->type);
+               v4l2_err(fimc->m2m.vfd, "queue (%d) busy\n", f->type);
                return -EBUSY;
        }
 
-       if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
+       if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
                frame = &ctx->s_frame;
-       } else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
+       else
                frame = &ctx->d_frame;
-       } else {
-               v4l2_err(&fimc->m2m.v4l2_dev,
-                        "Wrong buffer/video queue type (%d)\n", f->type);
-               return -EINVAL;
-       }
 
        pix = &f->fmt.pix_mp;
-       frame->fmt = find_format(f, FMT_FLAGS_M2M);
+       frame->fmt = fimc_find_format(&pix->pixelformat, NULL,
+                                     FMT_FLAGS_M2M, 0);
        if (!frame->fmt)
                return -EINVAL;
 
@@ -986,15 +1097,9 @@ static int fimc_m2m_s_fmt_mplane(struct file *file, void *priv,
                        (pix->width * pix->height * frame->fmt->depth[i]) / 8;
        }
 
-       frame->f_width  = pix->plane_fmt[0].bytesperline * 8 /
-               frame->fmt->depth[0];
-       frame->f_height = pix->height;
-       frame->width    = pix->width;
-       frame->height   = pix->height;
-       frame->o_width  = pix->width;
-       frame->o_height = pix->height;
-       frame->offs_h   = 0;
-       frame->offs_v   = 0;
+       fimc_fill_frame(frame, f);
+
+       ctx->scaler.enabled = 1;
 
        if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
                fimc_ctx_state_lock_set(FIMC_PARAMS | FIMC_DST_FMT, ctx);
@@ -1006,39 +1111,42 @@ static int fimc_m2m_s_fmt_mplane(struct file *file, void *priv,
        return 0;
 }
 
-static int fimc_m2m_reqbufs(struct file *file, void *priv,
-                         struct v4l2_requestbuffers *reqbufs)
+static int fimc_m2m_reqbufs(struct file *file, void *fh,
+                           struct v4l2_requestbuffers *reqbufs)
 {
-       struct fimc_ctx *ctx = priv;
+       struct fimc_ctx *ctx = fh_to_ctx(fh);
+
        return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, reqbufs);
 }
 
-static int fimc_m2m_querybuf(struct file *file, void *priv,
-                          struct v4l2_buffer *buf)
+static int fimc_m2m_querybuf(struct file *file, void *fh,
+                            struct v4l2_buffer *buf)
 {
-       struct fimc_ctx *ctx = priv;
+       struct fimc_ctx *ctx = fh_to_ctx(fh);
+
        return v4l2_m2m_querybuf(file, ctx->m2m_ctx, buf);
 }
 
-static int fimc_m2m_qbuf(struct file *file, void *priv,
-                         struct v4l2_buffer *buf)
+static int fimc_m2m_qbuf(struct file *file, void *fh,
+                        struct v4l2_buffer *buf)
 {
-       struct fimc_ctx *ctx = priv;
+       struct fimc_ctx *ctx = fh_to_ctx(fh);
 
        return v4l2_m2m_qbuf(file, ctx->m2m_ctx, buf);
 }
 
-static int fimc_m2m_dqbuf(struct file *file, void *priv,
-                          struct v4l2_buffer *buf)
+static int fimc_m2m_dqbuf(struct file *file, void *fh,
+                         struct v4l2_buffer *buf)
 {
-       struct fimc_ctx *ctx = priv;
+       struct fimc_ctx *ctx = fh_to_ctx(fh);
+
        return v4l2_m2m_dqbuf(file, ctx->m2m_ctx, buf);
 }
 
-static int fimc_m2m_streamon(struct file *file, void *priv,
-                          enum v4l2_buf_type type)
+static int fimc_m2m_streamon(struct file *file, void *fh,
+                            enum v4l2_buf_type type)
 {
-       struct fimc_ctx *ctx = priv;
+       struct fimc_ctx *ctx = fh_to_ctx(fh);
 
        /* The source and target color format need to be set */
        if (V4L2_TYPE_IS_OUTPUT(type)) {
@@ -1051,149 +1159,19 @@ static int fimc_m2m_streamon(struct file *file, void *priv,
        return v4l2_m2m_streamon(file, ctx->m2m_ctx, type);
 }
 
-static int fimc_m2m_streamoff(struct file *file, void *priv,
+static int fimc_m2m_streamoff(struct file *file, void *fh,
                            enum v4l2_buf_type type)
 {
-       struct fimc_ctx *ctx = priv;
-       return v4l2_m2m_streamoff(file, ctx->m2m_ctx, type);
-}
-
-int fimc_vidioc_queryctrl(struct file *file, void *priv,
-                           struct v4l2_queryctrl *qc)
-{
-       struct fimc_ctx *ctx = priv;
-       struct v4l2_queryctrl *c;
-       int ret = -EINVAL;
-
-       c = get_ctrl(qc->id);
-       if (c) {
-               *qc = *c;
-               return 0;
-       }
-
-       if (fimc_ctx_state_is_set(FIMC_CTX_CAP, ctx)) {
-               return v4l2_subdev_call(ctx->fimc_dev->vid_cap.sd,
-                                       core, queryctrl, qc);
-       }
-       return ret;
-}
-
-int fimc_vidioc_g_ctrl(struct file *file, void *priv,
-                        struct v4l2_control *ctrl)
-{
-       struct fimc_ctx *ctx = priv;
-       struct fimc_dev *fimc = ctx->fimc_dev;
+       struct fimc_ctx *ctx = fh_to_ctx(fh);
 
-       switch (ctrl->id) {
-       case V4L2_CID_HFLIP:
-               ctrl->value = (FLIP_X_AXIS & ctx->flip) ? 1 : 0;
-               break;
-       case V4L2_CID_VFLIP:
-               ctrl->value = (FLIP_Y_AXIS & ctx->flip) ? 1 : 0;
-               break;
-       case V4L2_CID_ROTATE:
-               ctrl->value = ctx->rotation;
-               break;
-       default:
-               if (fimc_ctx_state_is_set(FIMC_CTX_CAP, ctx)) {
-                       return v4l2_subdev_call(fimc->vid_cap.sd, core,
-                                               g_ctrl, ctrl);
-               } else {
-                       v4l2_err(&fimc->m2m.v4l2_dev, "Invalid control\n");
-                       return -EINVAL;
-               }
-       }
-       dbg("ctrl->value= %d", ctrl->value);
-
-       return 0;
-}
-
-int check_ctrl_val(struct fimc_ctx *ctx,  struct v4l2_control *ctrl)
-{
-       struct v4l2_queryctrl *c;
-       c = get_ctrl(ctrl->id);
-       if (!c)
-               return -EINVAL;
-
-       if (ctrl->value < c->minimum || ctrl->value > c->maximum
-               || (c->step != 0 && ctrl->value % c->step != 0)) {
-               v4l2_err(&ctx->fimc_dev->m2m.v4l2_dev,
-               "Invalid control value\n");
-               return -ERANGE;
-       }
-
-       return 0;
-}
-
-int fimc_s_ctrl(struct fimc_ctx *ctx, struct v4l2_control *ctrl)
-{
-       struct samsung_fimc_variant *variant = ctx->fimc_dev->variant;
-       struct fimc_dev *fimc = ctx->fimc_dev;
-       int ret = 0;
-
-       switch (ctrl->id) {
-       case V4L2_CID_HFLIP:
-               if (ctrl->value)
-                       ctx->flip |= FLIP_X_AXIS;
-               else
-                       ctx->flip &= ~FLIP_X_AXIS;
-               break;
-
-       case V4L2_CID_VFLIP:
-               if (ctrl->value)
-                       ctx->flip |= FLIP_Y_AXIS;
-               else
-                       ctx->flip &= ~FLIP_Y_AXIS;
-               break;
-
-       case V4L2_CID_ROTATE:
-               if (fimc_ctx_state_is_set(FIMC_DST_FMT | FIMC_SRC_FMT, ctx)) {
-                       ret = fimc_check_scaler_ratio(ctx->s_frame.width,
-                                       ctx->s_frame.height, ctx->d_frame.width,
-                                       ctx->d_frame.height, ctrl->value);
-               }
-
-               if (ret) {
-                       v4l2_err(&fimc->m2m.v4l2_dev, "Out of scaler range\n");
-                       return -EINVAL;
-               }
-
-               /* Check for the output rotator availability */
-               if ((ctrl->value == 90 || ctrl->value == 270) &&
-                   (ctx->in_path == FIMC_DMA && !variant->has_out_rot))
-                       return -EINVAL;
-               ctx->rotation = ctrl->value;
-               break;
-
-       default:
-               v4l2_err(&fimc->m2m.v4l2_dev, "Invalid control\n");
-               return -EINVAL;
-       }
-
-       fimc_ctx_state_lock_set(FIMC_PARAMS, ctx);
-
-       return 0;
-}
-
-static int fimc_m2m_s_ctrl(struct file *file, void *priv,
-                          struct v4l2_control *ctrl)
-{
-       struct fimc_ctx *ctx = priv;
-       int ret = 0;
-
-       ret = check_ctrl_val(ctx, ctrl);
-       if (ret)
-               return ret;
-
-       ret = fimc_s_ctrl(ctx, ctrl);
-       return 0;
+       return v4l2_m2m_streamoff(file, ctx->m2m_ctx, type);
 }
 
 static int fimc_m2m_cropcap(struct file *file, void *fh,
-                       struct v4l2_cropcap *cr)
+                           struct v4l2_cropcap *cr)
 {
+       struct fimc_ctx *ctx = fh_to_ctx(fh);
        struct fimc_frame *frame;
-       struct fimc_ctx *ctx = fh;
 
        frame = ctx_get_frame(ctx, cr->type);
        if (IS_ERR(frame))
@@ -1201,8 +1179,8 @@ static int fimc_m2m_cropcap(struct file *file, void *fh,
 
        cr->bounds.left         = 0;
        cr->bounds.top          = 0;
-       cr->bounds.width        = frame->f_width;
-       cr->bounds.height       = frame->f_height;
+       cr->bounds.width        = frame->o_width;
+       cr->bounds.height       = frame->o_height;
        cr->defrect             = cr->bounds;
 
        return 0;
@@ -1210,8 +1188,8 @@ static int fimc_m2m_cropcap(struct file *file, void *fh,
 
 static int fimc_m2m_g_crop(struct file *file, void *fh, struct v4l2_crop *cr)
 {
+       struct fimc_ctx *ctx = fh_to_ctx(fh);
        struct fimc_frame *frame;
-       struct fimc_ctx *ctx = file->private_data;
 
        frame = ctx_get_frame(ctx, cr->type);
        if (IS_ERR(frame))
@@ -1225,26 +1203,21 @@ static int fimc_m2m_g_crop(struct file *file, void *fh, struct v4l2_crop *cr)
        return 0;
 }
 
-int fimc_try_crop(struct fimc_ctx *ctx, struct v4l2_crop *cr)
+static int fimc_m2m_try_crop(struct fimc_ctx *ctx, struct v4l2_crop *cr)
 {
        struct fimc_dev *fimc = ctx->fimc_dev;
        struct fimc_frame *f;
        u32 min_size, halign, depth = 0;
-       bool is_capture_ctx;
        int i;
 
        if (cr->c.top < 0 || cr->c.left < 0) {
-               v4l2_err(&fimc->m2m.v4l2_dev,
+               v4l2_err(fimc->m2m.vfd,
                        "doesn't support negative values for top & left\n");
                return -EINVAL;
        }
-
-       is_capture_ctx = fimc_ctx_state_is_set(FIMC_CTX_CAP, ctx);
-
        if (cr->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
-               f = is_capture_ctx ? &ctx->s_frame : &ctx->d_frame;
-       else if (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE &&
-                !is_capture_ctx)
+               f = &ctx->d_frame;
+       else if (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
                f = &ctx->s_frame;
        else
                return -EINVAL;
@@ -1253,15 +1226,10 @@ int fimc_try_crop(struct fimc_ctx *ctx, struct v4l2_crop *cr)
                fimc->variant->min_inp_pixsize : fimc->variant->min_out_pixsize;
 
        /* Get pixel alignment constraints. */
-       if (is_capture_ctx) {
-               min_size = 16;
-               halign = 4;
-       } else {
-               if (fimc->id == 1 && fimc->variant->pix_hoff)
-                       halign = fimc_fmt_is_rgb(f->fmt->color) ? 0 : 1;
-               else
-                       halign = ffs(min_size) - 1;
-       }
+       if (fimc->id == 1 && fimc->variant->pix_hoff)
+               halign = fimc_fmt_is_rgb(f->fmt->color) ? 0 : 1;
+       else
+               halign = ffs(min_size) - 1;
 
        for (i = 0; i < f->fmt->colplanes; i++)
                depth += f->fmt->depth[i];
@@ -1278,7 +1246,7 @@ int fimc_try_crop(struct fimc_ctx *ctx, struct v4l2_crop *cr)
                cr->c.top = f->o_height - cr->c.height;
 
        cr->c.left = round_down(cr->c.left, min_size);
-       cr->c.top  = round_down(cr->c.top, is_capture_ctx ? 16 : 8);
+       cr->c.top  = round_down(cr->c.top, fimc->variant->hor_offs_align);
 
        dbg("l:%d, t:%d, w:%d, h:%d, f_w: %d, f_h: %d",
            cr->c.left, cr->c.top, cr->c.width, cr->c.height,
@@ -1289,12 +1257,12 @@ int fimc_try_crop(struct fimc_ctx *ctx, struct v4l2_crop *cr)
 
 static int fimc_m2m_s_crop(struct file *file, void *fh, struct v4l2_crop *cr)
 {
-       struct fimc_ctx *ctx = file->private_data;
+       struct fimc_ctx *ctx = fh_to_ctx(fh);
        struct fimc_dev *fimc = ctx->fimc_dev;
        struct fimc_frame *f;
        int ret;
 
-       ret = fimc_try_crop(ctx, cr);
+       ret = fimc_m2m_try_crop(ctx, cr);
        if (ret)
                return ret;
 
@@ -1304,18 +1272,16 @@ static int fimc_m2m_s_crop(struct file *file, void *fh, struct v4l2_crop *cr)
        /* Check to see if scaling ratio is within supported range */
        if (fimc_ctx_state_is_set(FIMC_DST_FMT | FIMC_SRC_FMT, ctx)) {
                if (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
-                       ret = fimc_check_scaler_ratio(cr->c.width, cr->c.height,
-                                                     ctx->d_frame.width,
-                                                     ctx->d_frame.height,
-                                                     ctx->rotation);
+                       ret = fimc_check_scaler_ratio(ctx, cr->c.width,
+                                       cr->c.height, ctx->d_frame.width,
+                                       ctx->d_frame.height, ctx->rotation);
                } else {
-                       ret = fimc_check_scaler_ratio(ctx->s_frame.width,
-                                                     ctx->s_frame.height,
-                                                     cr->c.width, cr->c.height,
-                                                     ctx->rotation);
+                       ret = fimc_check_scaler_ratio(ctx, ctx->s_frame.width,
+                                       ctx->s_frame.height, cr->c.width,
+                                       cr->c.height, ctx->rotation);
                }
                if (ret) {
-                       v4l2_err(&fimc->m2m.v4l2_dev, "Out of scaler range\n");
+                       v4l2_err(fimc->m2m.vfd, "Out of scaler range\n");
                        return -EINVAL;
                }
        }
@@ -1333,14 +1299,14 @@ static int fimc_m2m_s_crop(struct file *file, void *fh, struct v4l2_crop *cr)
 static const struct v4l2_ioctl_ops fimc_m2m_ioctl_ops = {
        .vidioc_querycap                = fimc_m2m_querycap,
 
-       .vidioc_enum_fmt_vid_cap_mplane = fimc_vidioc_enum_fmt_mplane,
-       .vidioc_enum_fmt_vid_out_mplane = fimc_vidioc_enum_fmt_mplane,
+       .vidioc_enum_fmt_vid_cap_mplane = fimc_m2m_enum_fmt_mplane,
+       .vidioc_enum_fmt_vid_out_mplane = fimc_m2m_enum_fmt_mplane,
 
-       .vidioc_g_fmt_vid_cap_mplane    = fimc_vidioc_g_fmt_mplane,
-       .vidioc_g_fmt_vid_out_mplane    = fimc_vidioc_g_fmt_mplane,
+       .vidioc_g_fmt_vid_cap_mplane    = fimc_m2m_g_fmt_mplane,
+       .vidioc_g_fmt_vid_out_mplane    = fimc_m2m_g_fmt_mplane,
 
-       .vidioc_try_fmt_vid_cap_mplane  = fimc_vidioc_try_fmt_mplane,
-       .vidioc_try_fmt_vid_out_mplane  = fimc_vidioc_try_fmt_mplane,
+       .vidioc_try_fmt_vid_cap_mplane  = fimc_m2m_try_fmt_mplane,
+       .vidioc_try_fmt_vid_out_mplane  = fimc_m2m_try_fmt_mplane,
 
        .vidioc_s_fmt_vid_cap_mplane    = fimc_m2m_s_fmt_mplane,
        .vidioc_s_fmt_vid_out_mplane    = fimc_m2m_s_fmt_mplane,
@@ -1354,10 +1320,6 @@ static const struct v4l2_ioctl_ops fimc_m2m_ioctl_ops = {
        .vidioc_streamon                = fimc_m2m_streamon,
        .vidioc_streamoff               = fimc_m2m_streamoff,
 
-       .vidioc_queryctrl               = fimc_vidioc_queryctrl,
-       .vidioc_g_ctrl                  = fimc_vidioc_g_ctrl,
-       .vidioc_s_ctrl                  = fimc_m2m_s_ctrl,
-
        .vidioc_g_crop                  = fimc_m2m_g_crop,
        .vidioc_s_crop                  = fimc_m2m_s_crop,
        .vidioc_cropcap                 = fimc_m2m_cropcap
@@ -1396,7 +1358,8 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
 static int fimc_m2m_open(struct file *file)
 {
        struct fimc_dev *fimc = video_drvdata(file);
-       struct fimc_ctx *ctx = NULL;
+       struct fimc_ctx *ctx;
+       int ret;
 
        dbg("pid: %d, state: 0x%lx, refcnt: %d",
                task_pid_nr(current), fimc->state, fimc->vid_cap.refcnt);
@@ -1408,19 +1371,24 @@ static int fimc_m2m_open(struct file *file)
        if (fimc->vid_cap.refcnt > 0)
                return -EBUSY;
 
-       fimc->m2m.refcnt++;
-       set_bit(ST_OUTDMA_RUN, &fimc->state);
-
        ctx = kzalloc(sizeof *ctx, GFP_KERNEL);
        if (!ctx)
                return -ENOMEM;
+       v4l2_fh_init(&ctx->fh, fimc->m2m.vfd);
+       ret = fimc_ctrls_create(ctx);
+       if (ret)
+               goto error_fh;
+
+       /* Use separate control handler per file handle */
+       ctx->fh.ctrl_handler = &ctx->ctrl_handler;
+       file->private_data = &ctx->fh;
+       v4l2_fh_add(&ctx->fh);
 
-       file->private_data = ctx;
        ctx->fimc_dev = fimc;
        /* Default color format */
        ctx->s_frame.fmt = &fimc_formats[0];
        ctx->d_frame.fmt = &fimc_formats[0];
-       /* Setup the device context for mem2mem mode. */
+       /* Setup the device context for memory-to-memory mode */
        ctx->state = FIMC_CTX_M2M;
        ctx->flags = 0;
        ctx->in_path = FIMC_DMA;
@@ -1429,34 +1397,46 @@ static int fimc_m2m_open(struct file *file)
 
        ctx->m2m_ctx = v4l2_m2m_ctx_init(fimc->m2m.m2m_dev, ctx, queue_init);
        if (IS_ERR(ctx->m2m_ctx)) {
-               int err = PTR_ERR(ctx->m2m_ctx);
-               kfree(ctx);
-               return err;
+               ret = PTR_ERR(ctx->m2m_ctx);
+               goto error_c;
        }
 
+       if (fimc->m2m.refcnt++ == 0)
+               set_bit(ST_M2M_RUN, &fimc->state);
        return 0;
+
+error_c:
+       fimc_ctrls_delete(ctx);
+error_fh:
+       v4l2_fh_del(&ctx->fh);
+       v4l2_fh_exit(&ctx->fh);
+       kfree(ctx);
+       return ret;
 }
 
 static int fimc_m2m_release(struct file *file)
 {
-       struct fimc_ctx *ctx = file->private_data;
+       struct fimc_ctx *ctx = fh_to_ctx(file->private_data);
        struct fimc_dev *fimc = ctx->fimc_dev;
 
        dbg("pid: %d, state: 0x%lx, refcnt= %d",
                task_pid_nr(current), fimc->state, fimc->m2m.refcnt);
 
        v4l2_m2m_ctx_release(ctx->m2m_ctx);
-       kfree(ctx);
-       if (--fimc->m2m.refcnt <= 0)
-               clear_bit(ST_OUTDMA_RUN, &fimc->state);
+       fimc_ctrls_delete(ctx);
+       v4l2_fh_del(&ctx->fh);
+       v4l2_fh_exit(&ctx->fh);
 
+       if (--fimc->m2m.refcnt <= 0)
+               clear_bit(ST_M2M_RUN, &fimc->state);
+       kfree(ctx);
        return 0;
 }
 
 static unsigned int fimc_m2m_poll(struct file *file,
-                                    struct poll_table_struct *wait)
+                                 struct poll_table_struct *wait)
 {
-       struct fimc_ctx *ctx = file->private_data;
+       struct fimc_ctx *ctx = fh_to_ctx(file->private_data);
 
        return v4l2_m2m_poll(file, ctx->m2m_ctx, wait);
 }
@@ -1464,7 +1444,7 @@ static unsigned int fimc_m2m_poll(struct file *file,
 
 static int fimc_m2m_mmap(struct file *file, struct vm_area_struct *vma)
 {
-       struct fimc_ctx *ctx = file->private_data;
+       struct fimc_ctx *ctx = fh_to_ctx(file->private_data);
 
        return v4l2_m2m_mmap(file, ctx->m2m_ctx, vma);
 }
@@ -1483,92 +1463,73 @@ static struct v4l2_m2m_ops m2m_ops = {
        .job_abort      = fimc_job_abort,
 };
 
-static int fimc_register_m2m_device(struct fimc_dev *fimc)
+int fimc_register_m2m_device(struct fimc_dev *fimc,
+                            struct v4l2_device *v4l2_dev)
 {
        struct video_device *vfd;
        struct platform_device *pdev;
-       struct v4l2_device *v4l2_dev;
        int ret = 0;
 
        if (!fimc)
                return -ENODEV;
 
        pdev = fimc->pdev;
-       v4l2_dev = &fimc->m2m.v4l2_dev;
-
-       /* set name if it is empty */
-       if (!v4l2_dev->name[0])
-               snprintf(v4l2_dev->name, sizeof(v4l2_dev->name),
-                        "%s.m2m", dev_name(&pdev->dev));
-
-       ret = v4l2_device_register(&pdev->dev, v4l2_dev);
-       if (ret)
-               goto err_m2m_r1;
+       fimc->v4l2_dev = v4l2_dev;
 
        vfd = video_device_alloc();
        if (!vfd) {
                v4l2_err(v4l2_dev, "Failed to allocate video device\n");
-               goto err_m2m_r1;
+               return -ENOMEM;
        }
 
        vfd->fops       = &fimc_m2m_fops;
        vfd->ioctl_ops  = &fimc_m2m_ioctl_ops;
+       vfd->v4l2_dev   = v4l2_dev;
        vfd->minor      = -1;
        vfd->release    = video_device_release;
        vfd->lock       = &fimc->lock;
 
-       snprintf(vfd->name, sizeof(vfd->name), "%s:m2m", dev_name(&pdev->dev));
-
+       snprintf(vfd->name, sizeof(vfd->name), "%s.m2m", dev_name(&pdev->dev));
        video_set_drvdata(vfd, fimc);
-       platform_set_drvdata(pdev, fimc);
 
        fimc->m2m.vfd = vfd;
        fimc->m2m.m2m_dev = v4l2_m2m_init(&m2m_ops);
        if (IS_ERR(fimc->m2m.m2m_dev)) {
                v4l2_err(v4l2_dev, "failed to initialize v4l2-m2m device\n");
                ret = PTR_ERR(fimc->m2m.m2m_dev);
-               goto err_m2m_r2;
-       }
-
-       ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1);
-       if (ret) {
-               v4l2_err(v4l2_dev,
-                        "%s(): failed to register video device\n", __func__);
-               goto err_m2m_r3;
+               goto err_init;
        }
-       v4l2_info(v4l2_dev,
-                 "FIMC m2m driver registered as /dev/video%d\n", vfd->num);
 
-       return 0;
+       ret = media_entity_init(&vfd->entity, 0, NULL, 0);
+       if (!ret)
+               return 0;
 
-err_m2m_r3:
        v4l2_m2m_release(fimc->m2m.m2m_dev);
-err_m2m_r2:
+err_init:
        video_device_release(fimc->m2m.vfd);
-err_m2m_r1:
-       v4l2_device_unregister(v4l2_dev);
-
        return ret;
 }
 
-static void fimc_unregister_m2m_device(struct fimc_dev *fimc)
+void fimc_unregister_m2m_device(struct fimc_dev *fimc)
 {
-       if (fimc) {
+       if (!fimc)
+               return;
+
+       if (fimc->m2m.m2m_dev)
                v4l2_m2m_release(fimc->m2m.m2m_dev);
+       if (fimc->m2m.vfd) {
+               media_entity_cleanup(&fimc->m2m.vfd->entity);
+               /* Can also be called if video device wasn't registered */
                video_unregister_device(fimc->m2m.vfd);
-
-               v4l2_device_unregister(&fimc->m2m.v4l2_dev);
        }
 }
 
-static void fimc_clk_release(struct fimc_dev *fimc)
+static void fimc_clk_put(struct fimc_dev *fimc)
 {
        int i;
        for (i = 0; i < fimc->num_clocks; i++) {
-               if (fimc->clock[i]) {
-                       clk_disable(fimc->clock[i]);
+               if (fimc->clock[i])
                        clk_put(fimc->clock[i]);
-               }
        }
 }
 
@@ -1577,15 +1538,50 @@ static int fimc_clk_get(struct fimc_dev *fimc)
        int i;
        for (i = 0; i < fimc->num_clocks; i++) {
                fimc->clock[i] = clk_get(&fimc->pdev->dev, fimc_clocks[i]);
-
-               if (!IS_ERR_OR_NULL(fimc->clock[i])) {
-                       clk_enable(fimc->clock[i]);
+               if (!IS_ERR_OR_NULL(fimc->clock[i]))
                        continue;
-               }
                dev_err(&fimc->pdev->dev, "failed to get fimc clock: %s\n",
                        fimc_clocks[i]);
                return -ENXIO;
        }
+
+       return 0;
+}
+
+static int fimc_m2m_suspend(struct fimc_dev *fimc)
+{
+       unsigned long flags;
+       int timeout;
+
+       spin_lock_irqsave(&fimc->slock, flags);
+       if (!fimc_m2m_pending(fimc)) {
+               spin_unlock_irqrestore(&fimc->slock, flags);
+               return 0;
+       }
+       clear_bit(ST_M2M_SUSPENDED, &fimc->state);
+       set_bit(ST_M2M_SUSPENDING, &fimc->state);
+       spin_unlock_irqrestore(&fimc->slock, flags);
+
+       timeout = wait_event_timeout(fimc->irq_queue,
+                            test_bit(ST_M2M_SUSPENDED, &fimc->state),
+                            FIMC_SHUTDOWN_TIMEOUT);
+
+       clear_bit(ST_M2M_SUSPENDING, &fimc->state);
+       return timeout == 0 ? -EAGAIN : 0;
+}
+
+static int fimc_m2m_resume(struct fimc_dev *fimc)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&fimc->slock, flags);
+       /* Clear for full H/W setup in first run after resume */
+       fimc->m2m.ctx = NULL;
+       spin_unlock_irqrestore(&fimc->slock, flags);
+
+       if (test_and_clear_bit(ST_M2M_SUSPENDED, &fimc->state))
+               fimc_m2m_job_finish(fimc->m2m.ctx,
+                                   VB2_BUF_STATE_ERROR);
        return 0;
 }
 
@@ -1596,7 +1592,6 @@ static int fimc_probe(struct platform_device *pdev)
        struct samsung_fimc_driverdata *drv_data;
        struct s5p_platform_fimc *pdata;
        int ret = 0;
-       int cap_input_index = -1;
 
        dev_dbg(&pdev->dev, "%s():\n", __func__);
 
@@ -1614,15 +1609,16 @@ static int fimc_probe(struct platform_device *pdev)
                return -ENOMEM;
 
        fimc->id = pdev->id;
+
        fimc->variant = drv_data->variant[fimc->id];
        fimc->pdev = pdev;
        pdata = pdev->dev.platform_data;
        fimc->pdata = pdata;
-       fimc->state = ST_IDLE;
+
+       set_bit(ST_LPM, &fimc->state);
 
        init_waitqueue_head(&fimc->irq_queue);
        spin_lock_init(&fimc->slock);
-
        mutex_init(&fimc->lock);
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -1647,71 +1643,51 @@ static int fimc_probe(struct platform_device *pdev)
                goto err_req_region;
        }
 
-       fimc->num_clocks = MAX_FIMC_CLOCKS - 1;
-
-       /* Check if a video capture node needs to be registered. */
-       if (pdata && pdata->num_clients > 0) {
-               cap_input_index = 0;
-               fimc->num_clocks++;
-       }
-
-       ret = fimc_clk_get(fimc);
-       if (ret)
-               goto err_regs_unmap;
-       clk_set_rate(fimc->clock[CLK_BUS], drv_data->lclk_frequency);
-
        res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
        if (!res) {
                dev_err(&pdev->dev, "failed to get IRQ resource\n");
                ret = -ENXIO;
-               goto err_clk;
+               goto err_regs_unmap;
        }
        fimc->irq = res->start;
 
-       fimc_hw_reset(fimc);
+       fimc->num_clocks = MAX_FIMC_CLOCKS;
+       ret = fimc_clk_get(fimc);
+       if (ret)
+               goto err_regs_unmap;
+       clk_set_rate(fimc->clock[CLK_BUS], drv_data->lclk_frequency);
+       clk_enable(fimc->clock[CLK_BUS]);
 
-       ret = request_irq(fimc->irq, fimc_isr, 0, pdev->name, fimc);
+       platform_set_drvdata(pdev, fimc);
+
+       ret = request_irq(fimc->irq, fimc_irq_handler, 0, pdev->name, fimc);
        if (ret) {
                dev_err(&pdev->dev, "failed to install irq (%d)\n", ret);
                goto err_clk;
        }
 
+       pm_runtime_enable(&pdev->dev);
+       ret = pm_runtime_get_sync(&pdev->dev);
+       if (ret < 0)
+               goto err_irq;
        /* Initialize contiguous memory allocator */
-       fimc->alloc_ctx = vb2_dma_contig_init_ctx(&fimc->pdev->dev);
+       fimc->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
        if (IS_ERR(fimc->alloc_ctx)) {
                ret = PTR_ERR(fimc->alloc_ctx);
-               goto err_irq;
+               goto err_pm;
        }
 
-       ret = fimc_register_m2m_device(fimc);
-       if (ret)
-               goto err_irq;
-
-       /* At least one camera sensor is required to register capture node */
-       if (cap_input_index >= 0) {
-               ret = fimc_register_capture_device(fimc);
-               if (ret)
-                       goto err_m2m;
-               clk_disable(fimc->clock[CLK_CAM]);
-       }
-       /*
-        * Exclude the additional output DMA address registers by masking
-        * them out on HW revisions that provide extended capabilites.
-        */
-       if (fimc->variant->out_buf_count > 4)
-               fimc_hw_set_dma_seq(fimc, 0xF);
-
-       dev_dbg(&pdev->dev, "%s(): fimc-%d registered successfully\n",
-               __func__, fimc->id);
+       dev_dbg(&pdev->dev, "FIMC.%d registered successfully\n", fimc->id);
 
+       pm_runtime_put(&pdev->dev);
        return 0;
 
-err_m2m:
-       fimc_unregister_m2m_device(fimc);
+err_pm:
+       pm_runtime_put(&pdev->dev);
 err_irq:
        free_irq(fimc->irq, fimc);
 err_clk:
-       fimc_clk_release(fimc);
+       fimc_clk_put(fimc);
 err_regs_unmap:
        iounmap(fimc->regs);
 err_req_region:
@@ -1719,31 +1695,105 @@ err_req_region:
        kfree(fimc->regs_res);
 err_info:
        kfree(fimc);
+       return ret;
+}
 
+static int fimc_runtime_resume(struct device *dev)
+{
+       struct fimc_dev *fimc = dev_get_drvdata(dev);
+
+       dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state);
+
+       /* Enable clocks and perform basic initalization */
+       clk_enable(fimc->clock[CLK_GATE]);
+       fimc_hw_reset(fimc);
+       if (fimc->variant->out_buf_count > 4)
+               fimc_hw_set_dma_seq(fimc, 0xF);
+
+       /* Resume the capture or mem-to-mem device */
+       if (fimc_capture_busy(fimc))
+               return fimc_capture_resume(fimc);
+       else if (fimc_m2m_pending(fimc))
+               return fimc_m2m_resume(fimc);
+       return 0;
+}
+
+static int fimc_runtime_suspend(struct device *dev)
+{
+       struct fimc_dev *fimc = dev_get_drvdata(dev);
+       int ret = 0;
+
+       if (fimc_capture_busy(fimc))
+               ret = fimc_capture_suspend(fimc);
+       else
+               ret = fimc_m2m_suspend(fimc);
+       if (!ret)
+               clk_disable(fimc->clock[CLK_GATE]);
+
+       dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state);
        return ret;
 }
 
-static int __devexit fimc_remove(struct platform_device *pdev)
+#ifdef CONFIG_PM_SLEEP
+static int fimc_resume(struct device *dev)
 {
-       struct fimc_dev *fimc =
-               (struct fimc_dev *)platform_get_drvdata(pdev);
+       struct fimc_dev *fimc = dev_get_drvdata(dev);
+       unsigned long flags;
 
-       free_irq(fimc->irq, fimc);
+       dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state);
+
+       /* Do not resume if the device was idle before system suspend */
+       spin_lock_irqsave(&fimc->slock, flags);
+       if (!test_and_clear_bit(ST_LPM, &fimc->state) ||
+           (!fimc_m2m_active(fimc) && !fimc_capture_busy(fimc))) {
+               spin_unlock_irqrestore(&fimc->slock, flags);
+               return 0;
+       }
        fimc_hw_reset(fimc);
+       if (fimc->variant->out_buf_count > 4)
+               fimc_hw_set_dma_seq(fimc, 0xF);
+       spin_unlock_irqrestore(&fimc->slock, flags);
+
+       if (fimc_capture_busy(fimc))
+               return fimc_capture_resume(fimc);
 
-       fimc_unregister_m2m_device(fimc);
-       fimc_unregister_capture_device(fimc);
+       return fimc_m2m_resume(fimc);
+}
+
+static int fimc_suspend(struct device *dev)
+{
+       struct fimc_dev *fimc = dev_get_drvdata(dev);
+
+       dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state);
 
-       fimc_clk_release(fimc);
+       if (test_and_set_bit(ST_LPM, &fimc->state))
+               return 0;
+       if (fimc_capture_busy(fimc))
+               return fimc_capture_suspend(fimc);
+
+       return fimc_m2m_suspend(fimc);
+}
+#endif /* CONFIG_PM_SLEEP */
+
+static int __devexit fimc_remove(struct platform_device *pdev)
+{
+       struct fimc_dev *fimc = platform_get_drvdata(pdev);
+
+       pm_runtime_disable(&pdev->dev);
+       fimc_runtime_suspend(&pdev->dev);
+       pm_runtime_set_suspended(&pdev->dev);
 
        vb2_dma_contig_cleanup_ctx(fimc->alloc_ctx);
 
+       clk_disable(fimc->clock[CLK_BUS]);
+       fimc_clk_put(fimc);
+       free_irq(fimc->irq, fimc);
        iounmap(fimc->regs);
        release_resource(fimc->regs_res);
        kfree(fimc->regs_res);
        kfree(fimc);
 
-       dev_info(&pdev->dev, "%s driver unloaded\n", pdev->name);
+       dev_info(&pdev->dev, "driver unloaded\n");
        return 0;
 }
 
@@ -1786,6 +1836,7 @@ static struct fimc_pix_limit s5p_pix_limit[4] = {
 static struct samsung_fimc_variant fimc0_variant_s5p = {
        .has_inp_rot     = 1,
        .has_out_rot     = 1,
+       .has_cam_if      = 1,
        .min_inp_pixsize = 16,
        .min_out_pixsize = 16,
        .hor_offs_align  = 8,
@@ -1794,6 +1845,7 @@ static struct samsung_fimc_variant fimc0_variant_s5p = {
 };
 
 static struct samsung_fimc_variant fimc2_variant_s5p = {
+       .has_cam_if      = 1,
        .min_inp_pixsize = 16,
        .min_out_pixsize = 16,
        .hor_offs_align  = 8,
@@ -1805,6 +1857,7 @@ static struct samsung_fimc_variant fimc0_variant_s5pv210 = {
        .pix_hoff        = 1,
        .has_inp_rot     = 1,
        .has_out_rot     = 1,
+       .has_cam_if      = 1,
        .min_inp_pixsize = 16,
        .min_out_pixsize = 16,
        .hor_offs_align  = 8,
@@ -1816,6 +1869,7 @@ static struct samsung_fimc_variant fimc1_variant_s5pv210 = {
        .pix_hoff        = 1,
        .has_inp_rot     = 1,
        .has_out_rot     = 1,
+       .has_cam_if      = 1,
        .has_mainscaler_ext = 1,
        .min_inp_pixsize = 16,
        .min_out_pixsize = 16,
@@ -1825,6 +1879,7 @@ static struct samsung_fimc_variant fimc1_variant_s5pv210 = {
 };
 
 static struct samsung_fimc_variant fimc2_variant_s5pv210 = {
+       .has_cam_if      = 1,
        .pix_hoff        = 1,
        .min_inp_pixsize = 16,
        .min_out_pixsize = 16,
@@ -1837,22 +1892,24 @@ static struct samsung_fimc_variant fimc0_variant_exynos4 = {
        .pix_hoff        = 1,
        .has_inp_rot     = 1,
        .has_out_rot     = 1,
+       .has_cam_if      = 1,
        .has_cistatus2   = 1,
        .has_mainscaler_ext = 1,
        .min_inp_pixsize = 16,
        .min_out_pixsize = 16,
-       .hor_offs_align  = 1,
+       .hor_offs_align  = 2,
        .out_buf_count   = 32,
        .pix_limit       = &s5p_pix_limit[1],
 };
 
-static struct samsung_fimc_variant fimc2_variant_exynos4 = {
+static struct samsung_fimc_variant fimc3_variant_exynos4 = {
        .pix_hoff        = 1,
+       .has_cam_if      = 1,
        .has_cistatus2   = 1,
        .has_mainscaler_ext = 1,
        .min_inp_pixsize = 16,
        .min_out_pixsize = 16,
-       .hor_offs_align  = 1,
+       .hor_offs_align  = 2,
        .out_buf_count   = 32,
        .pix_limit       = &s5p_pix_limit[3],
 };
@@ -1885,7 +1942,7 @@ static struct samsung_fimc_driverdata fimc_drvdata_exynos4 = {
                [0] = &fimc0_variant_exynos4,
                [1] = &fimc0_variant_exynos4,
                [2] = &fimc0_variant_exynos4,
-               [3] = &fimc2_variant_exynos4,
+               [3] = &fimc3_variant_exynos4,
        },
        .num_entities = 4,
        .lclk_frequency = 166000000UL,
@@ -1906,33 +1963,28 @@ static struct platform_device_id fimc_driver_ids[] = {
 };
 MODULE_DEVICE_TABLE(platform, fimc_driver_ids);
 
+static const struct dev_pm_ops fimc_pm_ops = {
+       SET_SYSTEM_SLEEP_PM_OPS(fimc_suspend, fimc_resume)
+       SET_RUNTIME_PM_OPS(fimc_runtime_suspend, fimc_runtime_resume, NULL)
+};
+
 static struct platform_driver fimc_driver = {
        .probe          = fimc_probe,
-       .remove = __devexit_p(fimc_remove),
+       .remove         = __devexit_p(fimc_remove),
        .id_table       = fimc_driver_ids,
        .driver = {
-               .name   = MODULE_NAME,
+               .name   = FIMC_MODULE_NAME,
                .owner  = THIS_MODULE,
+               .pm     = &fimc_pm_ops,
        }
 };
 
-static int __init fimc_init(void)
+int __init fimc_register_driver(void)
 {
-       int ret = platform_driver_register(&fimc_driver);
-       if (ret)
-               err("platform_driver_register failed: %d\n", ret);
-       return ret;
+       return platform_driver_probe(&fimc_driver, fimc_probe);
 }
 
-static void __exit fimc_exit(void)
+void __exit fimc_unregister_driver(void)
 {
        platform_driver_unregister(&fimc_driver);
 }
-
-module_init(fimc_init);
-module_exit(fimc_exit);
-
-MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>");
-MODULE_DESCRIPTION("S5P FIMC camera host interface/video postprocessor driver");
-MODULE_LICENSE("GPL");
-MODULE_VERSION("1.0.1");
index 1f70772daaf0056fad709c7f26845595191f6ab0..a6936dad5b1025b196ef6c1acd5e40131a44d7c3 100644 (file)
 
 /*#define DEBUG*/
 
+#include <linux/platform_device.h>
 #include <linux/sched.h>
 #include <linux/spinlock.h>
 #include <linux/types.h>
 #include <linux/videodev2.h>
 #include <linux/io.h>
+
+#include <media/media-entity.h>
 #include <media/videobuf2-core.h>
+#include <media/v4l2-ctrls.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-mem2mem.h>
 #include <media/v4l2-mediabus.h>
 
 /* Time to wait for next frame VSYNC interrupt while stopping operation. */
 #define FIMC_SHUTDOWN_TIMEOUT  ((100*HZ)/1000)
-#define MAX_FIMC_CLOCKS                3
-#define MODULE_NAME            "s5p-fimc"
+#define MAX_FIMC_CLOCKS                2
+#define FIMC_MODULE_NAME       "s5p-fimc"
 #define FIMC_MAX_DEVS          4
 #define FIMC_MAX_OUT_BUFS      4
 #define SCALER_MAX_HRATIO      64
 #define SCALER_MAX_VRATIO      64
 #define DMA_MIN_SIZE           8
+#define FIMC_CAMIF_MAX_HEIGHT  0x2000
 
 /* indices to the clocks array */
 enum {
        CLK_BUS,
        CLK_GATE,
-       CLK_CAM,
 };
 
 enum fimc_dev_flags {
-       /* for m2m node */
-       ST_IDLE,
-       ST_OUTDMA_RUN,
+       ST_LPM,
+       /* m2m node */
+       ST_M2M_RUN,
        ST_M2M_PEND,
-       /* for capture node */
+       ST_M2M_SUSPENDING,
+       ST_M2M_SUSPENDED,
+       /* capture node */
        ST_CAPT_PEND,
        ST_CAPT_RUN,
        ST_CAPT_STREAM,
+       ST_CAPT_ISP_STREAM,
+       ST_CAPT_SUSPENDED,
        ST_CAPT_SHUT,
+       ST_CAPT_BUSY,
+       ST_CAPT_APPLY_CFG,
+       ST_CAPT_JPEG,
 };
 
-#define fimc_m2m_active(dev) test_bit(ST_OUTDMA_RUN, &(dev)->state)
+#define fimc_m2m_active(dev) test_bit(ST_M2M_RUN, &(dev)->state)
 #define fimc_m2m_pending(dev) test_bit(ST_M2M_PEND, &(dev)->state)
 
 #define fimc_capture_running(dev) test_bit(ST_CAPT_RUN, &(dev)->state)
 #define fimc_capture_pending(dev) test_bit(ST_CAPT_PEND, &(dev)->state)
+#define fimc_capture_busy(dev) test_bit(ST_CAPT_BUSY, &(dev)->state)
 
 enum fimc_datapath {
        FIMC_CAMERA,
@@ -83,9 +95,14 @@ enum fimc_color_fmt {
        S5P_FIMC_CBYCRY422,
        S5P_FIMC_CRYCBY422,
        S5P_FIMC_YCBCR444_LOCAL,
+       S5P_FIMC_JPEG = 0x40,
 };
 
-#define fimc_fmt_is_rgb(x) ((x) & 0x10)
+#define fimc_fmt_is_rgb(x) (!!((x) & 0x10))
+#define fimc_fmt_is_jpeg(x) (!!((x) & 0x40))
+
+#define IS_M2M(__strt) ((__strt) == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE || \
+                       __strt == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
 
 /* Cb/Cr chrominance components order for 2 plane Y/CbCr 4:2:2 formats. */
 #define        S5P_FIMC_LSB_CRCB       S5P_CIOCTRL_ORDER422_2P_LSB_CRCB
@@ -104,9 +121,10 @@ enum fimc_color_fmt {
 #define        FIMC_DST_ADDR           (1 << 2)
 #define        FIMC_SRC_FMT            (1 << 3)
 #define        FIMC_DST_FMT            (1 << 4)
-#define        FIMC_CTX_M2M            (1 << 5)
-#define        FIMC_CTX_CAP            (1 << 6)
-#define        FIMC_CTX_SHUT           (1 << 7)
+#define        FIMC_DST_CROP           (1 << 5)
+#define        FIMC_CTX_M2M            (1 << 16)
+#define        FIMC_CTX_CAP            (1 << 17)
+#define        FIMC_CTX_SHUT           (1 << 18)
 
 /* Image conversion flags */
 #define        FIMC_IN_DMA_ACCESS_TILED        (1 << 0)
@@ -122,11 +140,6 @@ enum fimc_color_fmt {
 /* Y (16 ~ 235), Cb/Cr (16 ~ 240) */
 #define        FIMC_COLOR_RANGE_NARROW         (1 << 3)
 
-#define        FLIP_NONE                       0
-#define        FLIP_X_AXIS                     1
-#define        FLIP_Y_AXIS                     2
-#define        FLIP_XY_AXIS                    (FLIP_X_AXIS | FLIP_Y_AXIS)
-
 /**
  * struct fimc_fmt - the driver's internal color format data
  * @mbus_code: Media Bus pixel code, -1 if not applicable
@@ -275,26 +288,29 @@ struct fimc_frame {
 /**
  * struct fimc_m2m_device - v4l2 memory-to-memory device data
  * @vfd: the video device node for v4l2 m2m mode
- * @v4l2_dev: v4l2 device for m2m mode
  * @m2m_dev: v4l2 memory-to-memory device data
  * @ctx: hardware context data
  * @refcnt: the reference counter
  */
 struct fimc_m2m_device {
        struct video_device     *vfd;
-       struct v4l2_device      v4l2_dev;
        struct v4l2_m2m_dev     *m2m_dev;
        struct fimc_ctx         *ctx;
        int                     refcnt;
 };
 
+#define FIMC_SD_PAD_SINK       0
+#define FIMC_SD_PAD_SOURCE     1
+#define FIMC_SD_PADS_NUM       2
+
 /**
  * struct fimc_vid_cap - camera capture device information
  * @ctx: hardware context data
  * @vfd: video device node for camera capture mode
- * @v4l2_dev: v4l2_device struct to manage subdevs
- * @sd: pointer to camera sensor subdevice currently in use
- * @fmt: Media Bus format configured at selected image sensor
+ * @subdev: subdev exposing the FIMC processing block
+ * @vd_pad: fimc video capture node pad
+ * @sd_pads: fimc video processing block pads
+ * @mf: media bus format at the FIMC camera input (and the scaler output) pad
  * @pending_buf_q: the pending buffer queue head
  * @active_buf_q: the queue head of buffers scheduled in hardware
  * @vbq: the capture am video buffer queue
@@ -304,14 +320,17 @@ struct fimc_m2m_device {
  * @reqbufs_count: the number of buffers requested in REQBUFS ioctl
  * @input_index: input (camera sensor) index
  * @refcnt: driver's private reference counter
+ * @input: capture input type, grp_id of the attached subdev
+ * @user_subdev_api: true if subdevs are not configured by the host driver
  */
 struct fimc_vid_cap {
        struct fimc_ctx                 *ctx;
        struct vb2_alloc_ctx            *alloc_ctx;
        struct video_device             *vfd;
-       struct v4l2_device              v4l2_dev;
-       struct v4l2_subdev              *sd;;
-       struct v4l2_mbus_framefmt       fmt;
+       struct v4l2_subdev              *subdev;
+       struct media_pad                vd_pad;
+       struct v4l2_mbus_framefmt       mf;
+       struct media_pad                sd_pads[FIMC_SD_PADS_NUM];
        struct list_head                pending_buf_q;
        struct list_head                active_buf_q;
        struct vb2_queue                vbq;
@@ -321,6 +340,8 @@ struct fimc_vid_cap {
        unsigned int                    reqbufs_count;
        int                             input_index;
        int                             refcnt;
+       u32                             input;
+       bool                            user_subdev_api;
 };
 
 /**
@@ -351,6 +372,7 @@ struct fimc_pix_limit {
  * @has_cistatus2: 1 if CISTATUS2 register is present in this IP revision
  * @has_mainscaler_ext: 1 if extended mainscaler ratios in CIEXTEN register
  *                      are present in this IP revision
+ * @has_cam_if: set if this instance has a camera input interface
  * @pix_limit: pixel size constraints for the scaler
  * @min_inp_pixsize: minimum input pixel size
  * @min_out_pixsize: minimum output pixel size
@@ -363,6 +385,7 @@ struct samsung_fimc_variant {
        unsigned int    has_out_rot:1;
        unsigned int    has_cistatus2:1;
        unsigned int    has_mainscaler_ext:1;
+       unsigned int    has_cam_if:1;
        struct fimc_pix_limit *pix_limit;
        u16             min_inp_pixsize;
        u16             min_out_pixsize;
@@ -383,6 +406,12 @@ struct samsung_fimc_driverdata {
        int             num_entities;
 };
 
+struct fimc_pipeline {
+       struct media_pipeline *pipe;
+       struct v4l2_subdev *sensor;
+       struct v4l2_subdev *csis;
+};
+
 struct fimc_ctx;
 
 /**
@@ -399,10 +428,12 @@ struct fimc_ctx;
  * @regs_res:  the resource claimed for IO registers
  * @irq:       FIMC interrupt number
  * @irq_queue: interrupt handler waitqueue
+ * @v4l2_dev:  root v4l2_device
  * @m2m:       memory-to-memory V4L2 device information
  * @vid_cap:   camera capture device information
  * @state:     flags used to synchronize m2m and capture mode operation
  * @alloc_ctx: videobuf2 memory allocator context
+ * @pipeline:  fimc video capture pipeline data structure
  */
 struct fimc_dev {
        spinlock_t                      slock;
@@ -417,10 +448,12 @@ struct fimc_dev {
        struct resource                 *regs_res;
        int                             irq;
        wait_queue_head_t               irq_queue;
+       struct v4l2_device              *v4l2_dev;
        struct fimc_m2m_device          m2m;
        struct fimc_vid_cap             vid_cap;
        unsigned long                   state;
        struct vb2_alloc_ctx            *alloc_ctx;
+       struct fimc_pipeline            pipeline;
 };
 
 /**
@@ -437,11 +470,18 @@ struct fimc_dev {
  * @scaler:            image scaler properties
  * @effect:            image effect
  * @rotation:          image clockwise rotation in degrees
- * @flip:              image flip mode
+ * @hflip:             indicates image horizontal flip if set
+ * @vflip:             indicates image vertical flip if set
  * @flags:             additional flags for image conversion
  * @state:             flags to keep track of user configuration
  * @fimc_dev:          the FIMC device this context applies to
  * @m2m_ctx:           memory-to-memory device context
+ * @fh:                        v4l2 file handle
+ * @ctrl_handler:      v4l2 controls handler
+ * @ctrl_rotate                image rotation control
+ * @ctrl_hflip         horizontal flip control
+ * @ctrl_vflip         vartical flip control
+ * @ctrls_rdy:         true if the control handler is initialized
  */
 struct fimc_ctx {
        spinlock_t              slock;
@@ -456,13 +496,49 @@ struct fimc_ctx {
        struct fimc_scaler      scaler;
        struct fimc_effect      effect;
        int                     rotation;
-       u32                     flip;
+       unsigned int            hflip:1;
+       unsigned int            vflip:1;
        u32                     flags;
        u32                     state;
        struct fimc_dev         *fimc_dev;
        struct v4l2_m2m_ctx     *m2m_ctx;
+       struct v4l2_fh          fh;
+       struct v4l2_ctrl_handler ctrl_handler;
+       struct v4l2_ctrl        *ctrl_rotate;
+       struct v4l2_ctrl        *ctrl_hflip;
+       struct v4l2_ctrl        *ctrl_vflip;
+       bool                    ctrls_rdy;
 };
 
+#define fh_to_ctx(__fh) container_of(__fh, struct fimc_ctx, fh)
+
+static inline void set_frame_bounds(struct fimc_frame *f, u32 width, u32 height)
+{
+       f->o_width  = width;
+       f->o_height = height;
+       f->f_width  = width;
+       f->f_height = height;
+}
+
+static inline void set_frame_crop(struct fimc_frame *f,
+                                 u32 left, u32 top, u32 width, u32 height)
+{
+       f->offs_h = left;
+       f->offs_v = top;
+       f->width  = width;
+       f->height = height;
+}
+
+static inline u32 fimc_get_format_depth(struct fimc_fmt *ff)
+{
+       u32 i, depth = 0;
+
+       if (ff != NULL)
+               for (i = 0; i < ff->colplanes; i++)
+                       depth += ff->depth[i];
+       return depth;
+}
+
 static inline bool fimc_capture_active(struct fimc_dev *fimc)
 {
        unsigned long flags;
@@ -561,7 +637,7 @@ static inline struct fimc_frame *ctx_get_frame(struct fimc_ctx *ctx,
        } else if (V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE == type) {
                frame = &ctx->d_frame;
        } else {
-               v4l2_err(&ctx->fimc_dev->m2m.v4l2_dev,
+               v4l2_err(ctx->fimc_dev->v4l2_dev,
                        "Wrong buffer/video queue type (%d)\n", type);
                return ERR_PTR(-EINVAL);
        }
@@ -595,7 +671,7 @@ void fimc_hw_en_irq(struct fimc_dev *fimc, int enable);
 void fimc_hw_set_prescaler(struct fimc_ctx *ctx);
 void fimc_hw_set_mainscaler(struct fimc_ctx *ctx);
 void fimc_hw_en_capture(struct fimc_ctx *ctx);
-void fimc_hw_set_effect(struct fimc_ctx *ctx);
+void fimc_hw_set_effect(struct fimc_ctx *ctx, bool active);
 void fimc_hw_set_in_dma(struct fimc_ctx *ctx);
 void fimc_hw_set_input_path(struct fimc_ctx *ctx);
 void fimc_hw_set_output_path(struct fimc_ctx *ctx);
@@ -614,36 +690,45 @@ int fimc_hw_set_camera_type(struct fimc_dev *fimc,
 /* fimc-core.c */
 int fimc_vidioc_enum_fmt_mplane(struct file *file, void *priv,
                                struct v4l2_fmtdesc *f);
-int fimc_vidioc_g_fmt_mplane(struct file *file, void *priv,
-                            struct v4l2_format *f);
-int fimc_vidioc_try_fmt_mplane(struct file *file, void *priv,
-                              struct v4l2_format *f);
-int fimc_vidioc_queryctrl(struct file *file, void *priv,
-                         struct v4l2_queryctrl *qc);
-int fimc_vidioc_g_ctrl(struct file *file, void *priv,
-                      struct v4l2_control *ctrl);
-
-int fimc_try_crop(struct fimc_ctx *ctx, struct v4l2_crop *cr);
-int check_ctrl_val(struct fimc_ctx *ctx,  struct v4l2_control *ctrl);
-int fimc_s_ctrl(struct fimc_ctx *ctx, struct v4l2_control *ctrl);
-
-struct fimc_fmt *find_format(struct v4l2_format *f, unsigned int mask);
-struct fimc_fmt *find_mbus_format(struct v4l2_mbus_framefmt *f,
-                                 unsigned int mask);
-
-int fimc_check_scaler_ratio(int sw, int sh, int dw, int dh, int rot);
+int fimc_ctrls_create(struct fimc_ctx *ctx);
+void fimc_ctrls_delete(struct fimc_ctx *ctx);
+void fimc_ctrls_activate(struct fimc_ctx *ctx, bool active);
+int fimc_fill_format(struct fimc_frame *frame, struct v4l2_format *f);
+void fimc_adjust_mplane_format(struct fimc_fmt *fmt, u32 width, u32 height,
+                              struct v4l2_pix_format_mplane *pix);
+struct fimc_fmt *fimc_find_format(u32 *pixelformat, u32 *mbus_code,
+                                 unsigned int mask, int index);
+
+int fimc_check_scaler_ratio(struct fimc_ctx *ctx, int sw, int sh,
+                           int dw, int dh, int rotation);
 int fimc_set_scaler_info(struct fimc_ctx *ctx);
 int fimc_prepare_config(struct fimc_ctx *ctx, u32 flags);
 int fimc_prepare_addr(struct fimc_ctx *ctx, struct vb2_buffer *vb,
                      struct fimc_frame *frame, struct fimc_addr *paddr);
+void fimc_prepare_dma_offset(struct fimc_ctx *ctx, struct fimc_frame *f);
+void fimc_set_yuv_order(struct fimc_ctx *ctx);
+void fimc_fill_frame(struct fimc_frame *frame, struct v4l2_format *f);
+void fimc_capture_irq_handler(struct fimc_dev *fimc, bool done);
+
+int fimc_register_m2m_device(struct fimc_dev *fimc,
+                            struct v4l2_device *v4l2_dev);
+void fimc_unregister_m2m_device(struct fimc_dev *fimc);
+int fimc_register_driver(void);
+void fimc_unregister_driver(void);
 
 /* -----------------------------------------------------*/
 /* fimc-capture.c                                      */
-int fimc_register_capture_device(struct fimc_dev *fimc);
+int fimc_register_capture_device(struct fimc_dev *fimc,
+                                struct v4l2_device *v4l2_dev);
 void fimc_unregister_capture_device(struct fimc_dev *fimc);
-int fimc_sensor_sd_init(struct fimc_dev *fimc, int index);
+int fimc_capture_ctrls_create(struct fimc_dev *fimc);
 int fimc_vid_cap_buf_queue(struct fimc_dev *fimc,
                             struct fimc_vid_buffer *fimc_vb);
+void fimc_sensor_notify(struct v4l2_subdev *sd, unsigned int notification,
+                       void *arg);
+int fimc_capture_suspend(struct fimc_dev *fimc);
+int fimc_capture_resume(struct fimc_dev *fimc);
+int fimc_capture_config_update(struct fimc_ctx *ctx);
 
 /* Locking: the caller holds fimc->slock */
 static inline void fimc_activate_capture(struct fimc_ctx *ctx)
@@ -661,22 +746,27 @@ static inline void fimc_deactivate_capture(struct fimc_dev *fimc)
 }
 
 /*
- * Add buf to the capture active buffers queue.
- * Locking: Need to be called with fimc_dev::slock held.
+ * Buffer list manipulation functions. Must be called with fimc.slock held.
  */
-static inline void active_queue_add(struct fimc_vid_cap *vid_cap,
-                                   struct fimc_vid_buffer *buf)
+
+/**
+ * fimc_active_queue_add - add buffer to the capture active buffers queue
+ * @buf: buffer to add to the active buffers list
+ */
+static inline void fimc_active_queue_add(struct fimc_vid_cap *vid_cap,
+                                        struct fimc_vid_buffer *buf)
 {
        list_add_tail(&buf->list, &vid_cap->active_buf_q);
        vid_cap->active_buf_cnt++;
 }
 
-/*
- * Pop a video buffer from the capture active buffers queue
- * Locking: Need to be called with fimc_dev::slock held.
+/**
+ * fimc_active_queue_pop - pop buffer from the capture active buffers queue
+ *
+ * The caller must assure the active_buf_q list is not empty.
  */
-static inline struct fimc_vid_buffer *
-active_queue_pop(struct fimc_vid_cap *vid_cap)
+static inline struct fimc_vid_buffer *fimc_active_queue_pop(
+                                   struct fimc_vid_cap *vid_cap)
 {
        struct fimc_vid_buffer *buf;
        buf = list_entry(vid_cap->active_buf_q.next,
@@ -686,16 +776,23 @@ active_queue_pop(struct fimc_vid_cap *vid_cap)
        return buf;
 }
 
-/* Add video buffer to the capture pending buffers queue */
+/**
+ * fimc_pending_queue_add - add buffer to the capture pending buffers queue
+ * @buf: buffer to add to the pending buffers list
+ */
 static inline void fimc_pending_queue_add(struct fimc_vid_cap *vid_cap,
                                          struct fimc_vid_buffer *buf)
 {
        list_add_tail(&buf->list, &vid_cap->pending_buf_q);
 }
 
-/* Add video buffer to the capture pending buffers queue */
-static inline struct fimc_vid_buffer *
-pending_queue_pop(struct fimc_vid_cap *vid_cap)
+/**
+ * fimc_pending_queue_pop - pop buffer from the capture pending buffers queue
+ *
+ * The caller must assure the pending_buf_q list is not empty.
+ */
+static inline struct fimc_vid_buffer *fimc_pending_queue_pop(
+                                    struct fimc_vid_cap *vid_cap)
 {
        struct fimc_vid_buffer *buf;
        buf = list_entry(vid_cap->pending_buf_q.next,
diff --git a/drivers/media/video/s5p-fimc/fimc-mdevice.c b/drivers/media/video/s5p-fimc/fimc-mdevice.c
new file mode 100644 (file)
index 0000000..cc337b1
--- /dev/null
@@ -0,0 +1,858 @@
+/*
+ * S5P/EXYNOS4 SoC series camera host interface media device driver
+ *
+ * Copyright (C) 2011 Samsung Electronics Co., Ltd.
+ * Contact: Sylwester Nawrocki, <s.nawrocki@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 2 of the License,
+ * or (at your option) any later version.
+ */
+
+#include <linux/bug.h>
+#include <linux/device.h>
+#include <linux/errno.h>
+#include <linux/i2c.h>
+#include <linux/kernel.h>
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/types.h>
+#include <linux/slab.h>
+#include <linux/version.h>
+#include <media/v4l2-ctrls.h>
+#include <media/media-device.h>
+
+#include "fimc-core.h"
+#include "fimc-mdevice.h"
+#include "mipi-csis.h"
+
+static int __fimc_md_set_camclk(struct fimc_md *fmd,
+                               struct fimc_sensor_info *s_info,
+                               bool on);
+/**
+ * fimc_pipeline_prepare - update pipeline information with subdevice pointers
+ * @fimc: fimc device terminating the pipeline
+ *
+ * Caller holds the graph mutex.
+ */
+void fimc_pipeline_prepare(struct fimc_dev *fimc, struct media_entity *me)
+{
+       struct media_entity_graph graph;
+       struct v4l2_subdev *sd;
+
+       media_entity_graph_walk_start(&graph, me);
+
+       while ((me = media_entity_graph_walk_next(&graph))) {
+               if (media_entity_type(me) != MEDIA_ENT_T_V4L2_SUBDEV)
+                       continue;
+               sd = media_entity_to_v4l2_subdev(me);
+
+               if (sd->grp_id == SENSOR_GROUP_ID)
+                       fimc->pipeline.sensor = sd;
+               else if (sd->grp_id == CSIS_GROUP_ID)
+                       fimc->pipeline.csis = sd;
+       }
+}
+
+/**
+ * __subdev_set_power - change power state of a single subdev
+ * @sd: subdevice to change power state for
+ * @on: 1 to enable power or 0 to disable
+ *
+ * Return result of s_power subdev operation or -ENXIO if sd argument
+ * is NULL. Return 0 if the subdevice does not implement s_power.
+ */
+static int __subdev_set_power(struct v4l2_subdev *sd, int on)
+{
+       int *use_count;
+       int ret;
+
+       if (sd == NULL)
+               return -ENXIO;
+
+       use_count = &sd->entity.use_count;
+       if (on && (*use_count)++ > 0)
+               return 0;
+       else if (!on && (*use_count == 0 || --(*use_count) > 0))
+               return 0;
+       ret = v4l2_subdev_call(sd, core, s_power, on);
+
+       return ret != -ENOIOCTLCMD ? ret : 0;
+}
+
+/**
+ * fimc_pipeline_s_power - change power state of all pipeline subdevs
+ * @fimc: fimc device terminating the pipeline
+ * @state: 1 to enable power or 0 for power down
+ *
+ * Need to be called with the graph mutex held.
+ */
+int fimc_pipeline_s_power(struct fimc_dev *fimc, int state)
+{
+       int ret = 0;
+
+       if (fimc->pipeline.sensor == NULL)
+               return -ENXIO;
+
+       if (state) {
+               ret = __subdev_set_power(fimc->pipeline.csis, 1);
+               if (ret && ret != -ENXIO)
+                       return ret;
+               return __subdev_set_power(fimc->pipeline.sensor, 1);
+       }
+
+       ret = __subdev_set_power(fimc->pipeline.sensor, 0);
+       if (ret)
+               return ret;
+       ret = __subdev_set_power(fimc->pipeline.csis, 0);
+
+       return ret == -ENXIO ? 0 : ret;
+}
+
+/**
+ * __fimc_pipeline_initialize - update the pipeline information, enable power
+ *                              of all pipeline subdevs and the sensor clock
+ * @me: media entity to start graph walk with
+ * @prep: true to acquire sensor (and csis) subdevs
+ *
+ * This function must be called with the graph mutex held.
+ */
+static int __fimc_pipeline_initialize(struct fimc_dev *fimc,
+                                     struct media_entity *me, bool prep)
+{
+       int ret;
+
+       if (prep)
+               fimc_pipeline_prepare(fimc, me);
+       if (fimc->pipeline.sensor == NULL)
+               return -EINVAL;
+       ret = fimc_md_set_camclk(fimc->pipeline.sensor, true);
+       if (ret)
+               return ret;
+       return fimc_pipeline_s_power(fimc, 1);
+}
+
+int fimc_pipeline_initialize(struct fimc_dev *fimc, struct media_entity *me,
+                            bool prep)
+{
+       int ret;
+
+       mutex_lock(&me->parent->graph_mutex);
+       ret =  __fimc_pipeline_initialize(fimc, me, prep);
+       mutex_unlock(&me->parent->graph_mutex);
+
+       return ret;
+}
+
+/**
+ * __fimc_pipeline_shutdown - disable the sensor clock and pipeline power
+ * @fimc: fimc device terminating the pipeline
+ *
+ * Disable power of all subdevs in the pipeline and turn off the external
+ * sensor clock.
+ * Called with the graph mutex held.
+ */
+int __fimc_pipeline_shutdown(struct fimc_dev *fimc)
+{
+       int ret = 0;
+
+       if (fimc->pipeline.sensor) {
+               ret = fimc_pipeline_s_power(fimc, 0);
+               fimc_md_set_camclk(fimc->pipeline.sensor, false);
+       }
+       return ret == -ENXIO ? 0 : ret;
+}
+
+int fimc_pipeline_shutdown(struct fimc_dev *fimc)
+{
+       struct media_entity *me = &fimc->vid_cap.vfd->entity;
+       int ret;
+
+       mutex_lock(&me->parent->graph_mutex);
+       ret = __fimc_pipeline_shutdown(fimc);
+       mutex_unlock(&me->parent->graph_mutex);
+
+       return ret;
+}
+
+/**
+ * fimc_pipeline_s_stream - invoke s_stream on pipeline subdevs
+ * @fimc: fimc device terminating the pipeline
+ * @on: passed as the s_stream call argument
+ */
+int fimc_pipeline_s_stream(struct fimc_dev *fimc, int on)
+{
+       struct fimc_pipeline *p = &fimc->pipeline;
+       int ret = 0;
+
+       if (p->sensor == NULL)
+               return -ENODEV;
+
+       if ((on && p->csis) || !on)
+               ret = v4l2_subdev_call(on ? p->csis : p->sensor,
+                                      video, s_stream, on);
+       if (ret < 0 && ret != -ENOIOCTLCMD)
+               return ret;
+       if ((!on && p->csis) || on)
+               ret = v4l2_subdev_call(on ? p->sensor : p->csis,
+                                      video, s_stream, on);
+       return ret == -ENOIOCTLCMD ? 0 : ret;
+}
+
+/*
+ * Sensor subdevice helper functions
+ */
+static struct v4l2_subdev *fimc_md_register_sensor(struct fimc_md *fmd,
+                                  struct fimc_sensor_info *s_info)
+{
+       struct i2c_adapter *adapter;
+       struct v4l2_subdev *sd = NULL;
+
+       if (!s_info || !fmd)
+               return NULL;
+
+       adapter = i2c_get_adapter(s_info->pdata->i2c_bus_num);
+       if (!adapter)
+               return NULL;
+       sd = v4l2_i2c_new_subdev_board(&fmd->v4l2_dev, adapter,
+                                      s_info->pdata->board_info, NULL);
+       if (IS_ERR_OR_NULL(sd)) {
+               v4l2_err(&fmd->v4l2_dev, "Failed to acquire subdev\n");
+               return NULL;
+       }
+       v4l2_set_subdev_hostdata(sd, s_info);
+       sd->grp_id = SENSOR_GROUP_ID;
+
+       v4l2_info(&fmd->v4l2_dev, "Registered sensor subdevice %s\n",
+                 s_info->pdata->board_info->type);
+       return sd;
+}
+
+static void fimc_md_unregister_sensor(struct v4l2_subdev *sd)
+{
+       struct i2c_client *client = v4l2_get_subdevdata(sd);
+
+       if (!client)
+               return;
+       v4l2_device_unregister_subdev(sd);
+       i2c_unregister_device(client);
+       i2c_put_adapter(client->adapter);
+}
+
+static int fimc_md_register_sensor_entities(struct fimc_md *fmd)
+{
+       struct s5p_platform_fimc *pdata = fmd->pdev->dev.platform_data;
+       struct fimc_dev *fd = NULL;
+       int num_clients, ret, i;
+
+       /*
+        * Runtime resume one of the FIMC entities to make sure
+        * the sclk_cam clocks are not globally disabled.
+        */
+       for (i = 0; !fd && i < ARRAY_SIZE(fmd->fimc); i++)
+               if (fmd->fimc[i])
+                       fd = fmd->fimc[i];
+       if (!fd)
+               return -ENXIO;
+       ret = pm_runtime_get_sync(&fd->pdev->dev);
+       if (ret < 0)
+               return ret;
+
+       WARN_ON(pdata->num_clients > ARRAY_SIZE(fmd->sensor));
+       num_clients = min_t(u32, pdata->num_clients, ARRAY_SIZE(fmd->sensor));
+
+       fmd->num_sensors = num_clients;
+       for (i = 0; i < num_clients; i++) {
+               fmd->sensor[i].pdata = &pdata->isp_info[i];
+               ret = __fimc_md_set_camclk(fmd, &fmd->sensor[i], true);
+               if (ret)
+                       break;
+               fmd->sensor[i].subdev =
+                       fimc_md_register_sensor(fmd, &fmd->sensor[i]);
+               ret = __fimc_md_set_camclk(fmd, &fmd->sensor[i], false);
+               if (ret)
+                       break;
+       }
+       pm_runtime_put(&fd->pdev->dev);
+       return ret;
+}
+
+/*
+ * MIPI CSIS and FIMC platform devices registration.
+ */
+static int fimc_register_callback(struct device *dev, void *p)
+{
+       struct fimc_dev *fimc = dev_get_drvdata(dev);
+       struct fimc_md *fmd = p;
+       int ret;
+
+       if (!fimc || !fimc->pdev)
+               return 0;
+       if (fimc->pdev->id < 0 || fimc->pdev->id >= FIMC_MAX_DEVS)
+               return 0;
+
+       fmd->fimc[fimc->pdev->id] = fimc;
+       ret = fimc_register_m2m_device(fimc, &fmd->v4l2_dev);
+       if (ret)
+               return ret;
+       ret = fimc_register_capture_device(fimc, &fmd->v4l2_dev);
+       if (!ret)
+               fimc->vid_cap.user_subdev_api = fmd->user_subdev_api;
+       return ret;
+}
+
+static int csis_register_callback(struct device *dev, void *p)
+{
+       struct v4l2_subdev *sd = dev_get_drvdata(dev);
+       struct platform_device *pdev;
+       struct fimc_md *fmd = p;
+       int id, ret;
+
+       if (!sd)
+               return 0;
+       pdev = v4l2_get_subdevdata(sd);
+       if (!pdev || pdev->id < 0 || pdev->id >= CSIS_MAX_ENTITIES)
+               return 0;
+       v4l2_info(sd, "csis%d sd: %s\n", pdev->id, sd->name);
+
+       id = pdev->id < 0 ? 0 : pdev->id;
+       fmd->csis[id].sd = sd;
+       sd->grp_id = CSIS_GROUP_ID;
+       ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd);
+       if (ret)
+               v4l2_err(&fmd->v4l2_dev,
+                        "Failed to register CSIS subdevice: %d\n", ret);
+       return ret;
+}
+
+/**
+ * fimc_md_register_platform_entities - register FIMC and CSIS media entities
+ */
+static int fimc_md_register_platform_entities(struct fimc_md *fmd)
+{
+       struct device_driver *driver;
+       int ret;
+
+       driver = driver_find(FIMC_MODULE_NAME, &platform_bus_type);
+       if (!driver)
+               return -ENODEV;
+       ret = driver_for_each_device(driver, NULL, fmd,
+                                    fimc_register_callback);
+       put_driver(driver);
+       if (ret)
+               return ret;
+
+       driver = driver_find(CSIS_DRIVER_NAME, &platform_bus_type);
+       if (driver) {
+               ret = driver_for_each_device(driver, NULL, fmd,
+                                            csis_register_callback);
+               put_driver(driver);
+       }
+       return ret;
+}
+
+static void fimc_md_unregister_entities(struct fimc_md *fmd)
+{
+       int i;
+
+       for (i = 0; i < FIMC_MAX_DEVS; i++) {
+               if (fmd->fimc[i] == NULL)
+                       continue;
+               fimc_unregister_m2m_device(fmd->fimc[i]);
+               fimc_unregister_capture_device(fmd->fimc[i]);
+               fmd->fimc[i] = NULL;
+       }
+       for (i = 0; i < CSIS_MAX_ENTITIES; i++) {
+               if (fmd->csis[i].sd == NULL)
+                       continue;
+               v4l2_device_unregister_subdev(fmd->csis[i].sd);
+               fmd->csis[i].sd = NULL;
+       }
+       for (i = 0; i < fmd->num_sensors; i++) {
+               if (fmd->sensor[i].subdev == NULL)
+                       continue;
+               fimc_md_unregister_sensor(fmd->sensor[i].subdev);
+               fmd->sensor[i].subdev = NULL;
+       }
+}
+
+static int fimc_md_register_video_nodes(struct fimc_md *fmd)
+{
+       int i, ret = 0;
+
+       for (i = 0; i < FIMC_MAX_DEVS && !ret; i++) {
+               if (!fmd->fimc[i])
+                       continue;
+
+               if (fmd->fimc[i]->m2m.vfd)
+                       ret = video_register_device(fmd->fimc[i]->m2m.vfd,
+                                                   VFL_TYPE_GRABBER, -1);
+               if (ret)
+                       break;
+               if (fmd->fimc[i]->vid_cap.vfd)
+                       ret = video_register_device(fmd->fimc[i]->vid_cap.vfd,
+                                                   VFL_TYPE_GRABBER, -1);
+       }
+
+       return ret;
+}
+
+/**
+ * __fimc_md_create_fimc_links - create links to all FIMC entities
+ * @fmd: fimc media device
+ * @source: the source entity to create links to all fimc entities from
+ * @sensor: sensor subdev linked to FIMC[fimc_id] entity, may be null
+ * @pad: the source entity pad index
+ * @fimc_id: index of the fimc device for which link should be enabled
+ */
+static int __fimc_md_create_fimc_links(struct fimc_md *fmd,
+                                      struct media_entity *source,
+                                      struct v4l2_subdev *sensor,
+                                      int pad, int fimc_id)
+{
+       struct fimc_sensor_info *s_info;
+       struct media_entity *sink;
+       unsigned int flags;
+       int ret, i;
+
+       for (i = 0; i < FIMC_MAX_DEVS; i++) {
+               if (!fmd->fimc[i])
+                       break;
+               /*
+                * Some FIMC variants are not fitted with camera capture
+                * interface. Skip creating a link from sensor for those.
+                */
+               if (sensor->grp_id == SENSOR_GROUP_ID &&
+                   !fmd->fimc[i]->variant->has_cam_if)
+                       continue;
+
+               flags = (i == fimc_id) ? MEDIA_LNK_FL_ENABLED : 0;
+               sink = &fmd->fimc[i]->vid_cap.subdev->entity;
+               ret = media_entity_create_link(source, pad, sink,
+                                             FIMC_SD_PAD_SINK, flags);
+               if (ret)
+                       return ret;
+
+               /* Notify FIMC capture subdev entity */
+               ret = media_entity_call(sink, link_setup, &sink->pads[0],
+                                       &source->pads[pad], flags);
+               if (ret)
+                       break;
+
+               v4l2_info(&fmd->v4l2_dev, "created link [%s] %c> [%s]",
+                         source->name, flags ? '=' : '-', sink->name);
+
+               if (flags == 0)
+                       continue;
+               s_info = v4l2_get_subdev_hostdata(sensor);
+               if (!WARN_ON(s_info == NULL)) {
+                       unsigned long irq_flags;
+                       spin_lock_irqsave(&fmd->slock, irq_flags);
+                       s_info->host = fmd->fimc[i];
+                       spin_unlock_irqrestore(&fmd->slock, irq_flags);
+               }
+       }
+       return 0;
+}
+
+/**
+ * fimc_md_create_links - create default links between registered entities
+ *
+ * Parallel interface sensor entities are connected directly to FIMC capture
+ * entities. The sensors using MIPI CSIS bus are connected through immutable
+ * link with CSI receiver entity specified by mux_id. Any registered CSIS
+ * entity has a link to each registered FIMC capture entity. Enabled links
+ * are created by default between each subsequent registered sensor and
+ * subsequent FIMC capture entity. The number of default active links is
+ * determined by the number of available sensors or FIMC entities,
+ * whichever is less.
+ */
+static int fimc_md_create_links(struct fimc_md *fmd)
+{
+       struct v4l2_subdev *sensor, *csis;
+       struct s5p_fimc_isp_info *pdata;
+       struct fimc_sensor_info *s_info;
+       struct media_entity *source, *sink;
+       int i, pad, fimc_id = 0;
+       int ret = 0;
+       u32 flags;
+
+       for (i = 0; i < fmd->num_sensors; i++) {
+               if (fmd->sensor[i].subdev == NULL)
+                       continue;
+
+               sensor = fmd->sensor[i].subdev;
+               s_info = v4l2_get_subdev_hostdata(sensor);
+               if (!s_info || !s_info->pdata)
+                       continue;
+
+               source = NULL;
+               pdata = s_info->pdata;
+
+               switch (pdata->bus_type) {
+               case FIMC_MIPI_CSI2:
+                       if (WARN(pdata->mux_id >= CSIS_MAX_ENTITIES,
+                               "Wrong CSI channel id: %d\n", pdata->mux_id))
+                               return -EINVAL;
+
+                       csis = fmd->csis[pdata->mux_id].sd;
+                       if (WARN(csis == NULL,
+                                "MIPI-CSI interface specified "
+                                "but s5p-csis module is not loaded!\n"))
+                               continue;
+
+                       ret = media_entity_create_link(&sensor->entity, 0,
+                                             &csis->entity, CSIS_PAD_SINK,
+                                             MEDIA_LNK_FL_IMMUTABLE |
+                                             MEDIA_LNK_FL_ENABLED);
+                       if (ret)
+                               return ret;
+
+                       v4l2_info(&fmd->v4l2_dev, "created link [%s] => [%s]",
+                                 sensor->entity.name, csis->entity.name);
+
+                       source = &csis->entity;
+                       pad = CSIS_PAD_SOURCE;
+                       break;
+
+               case FIMC_ITU_601...FIMC_ITU_656:
+                       source = &sensor->entity;
+                       pad = 0;
+                       break;
+
+               default:
+                       v4l2_err(&fmd->v4l2_dev, "Wrong bus_type: %x\n",
+                                pdata->bus_type);
+                       return -EINVAL;
+               }
+               if (source == NULL)
+                       continue;
+
+               ret = __fimc_md_create_fimc_links(fmd, source, sensor, pad,
+                                                 fimc_id++);
+       }
+       /* Create immutable links between each FIMC's subdev and video node */
+       flags = MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED;
+       for (i = 0; i < FIMC_MAX_DEVS; i++) {
+               if (!fmd->fimc[i])
+                       continue;
+               source = &fmd->fimc[i]->vid_cap.subdev->entity;
+               sink = &fmd->fimc[i]->vid_cap.vfd->entity;
+               ret = media_entity_create_link(source, FIMC_SD_PAD_SOURCE,
+                                             sink, 0, flags);
+               if (ret)
+                       break;
+       }
+
+       return ret;
+}
+
+/*
+ * The peripheral sensor clock management.
+ */
+static int fimc_md_get_clocks(struct fimc_md *fmd)
+{
+       char clk_name[32];
+       struct clk *clock;
+       int i;
+
+       for (i = 0; i < FIMC_MAX_CAMCLKS; i++) {
+               snprintf(clk_name, sizeof(clk_name), "sclk_cam%u", i);
+               clock = clk_get(NULL, clk_name);
+               if (IS_ERR_OR_NULL(clock)) {
+                       v4l2_err(&fmd->v4l2_dev, "Failed to get clock: %s",
+                                 clk_name);
+                       return -ENXIO;
+               }
+               fmd->camclk[i].clock = clock;
+       }
+       return 0;
+}
+
+static void fimc_md_put_clocks(struct fimc_md *fmd)
+{
+       int i = FIMC_MAX_CAMCLKS;
+
+       while (--i >= 0) {
+               if (IS_ERR_OR_NULL(fmd->camclk[i].clock))
+                       continue;
+               clk_put(fmd->camclk[i].clock);
+               fmd->camclk[i].clock = NULL;
+       }
+}
+
+static int __fimc_md_set_camclk(struct fimc_md *fmd,
+                                        struct fimc_sensor_info *s_info,
+                                        bool on)
+{
+       struct s5p_fimc_isp_info *pdata = s_info->pdata;
+       struct fimc_camclk_info *camclk;
+       int ret = 0;
+
+       if (WARN_ON(pdata->clk_id >= FIMC_MAX_CAMCLKS) || fmd == NULL)
+               return -EINVAL;
+
+       if (s_info->clk_on == on)
+               return 0;
+       camclk = &fmd->camclk[pdata->clk_id];
+
+       dbg("camclk %d, f: %lu, clk: %p, on: %d",
+           pdata->clk_id, pdata->clk_frequency, camclk, on);
+
+       if (on) {
+               if (camclk->use_count > 0 &&
+                   camclk->frequency != pdata->clk_frequency)
+                       return -EINVAL;
+
+               if (camclk->use_count++ == 0) {
+                       clk_set_rate(camclk->clock, pdata->clk_frequency);
+                       camclk->frequency = pdata->clk_frequency;
+                       ret = clk_enable(camclk->clock);
+               }
+               s_info->clk_on = 1;
+               dbg("Enabled camclk %d: f: %lu", pdata->clk_id,
+                   clk_get_rate(camclk->clock));
+
+               return ret;
+       }
+
+       if (WARN_ON(camclk->use_count == 0))
+               return 0;
+
+       if (--camclk->use_count == 0) {
+               clk_disable(camclk->clock);
+               s_info->clk_on = 0;
+               dbg("Disabled camclk %d", pdata->clk_id);
+       }
+       return ret;
+}
+
+/**
+ * fimc_md_set_camclk - peripheral sensor clock setup
+ * @sd: sensor subdev to configure sclk_cam clock for
+ * @on: 1 to enable or 0 to disable the clock
+ *
+ * There are 2 separate clock outputs available in the SoC for external
+ * image processors. These clocks are shared between all registered FIMC
+ * devices to which sensors can be attached, either directly or through
+ * the MIPI CSI receiver. The clock is allowed here to be used by
+ * multiple sensors concurrently if they use same frequency.
+ * The per sensor subdev clk_on attribute helps to synchronize accesses
+ * to the sclk_cam clocks from the video and media device nodes.
+ * This function should only be called when the graph mutex is held.
+ */
+int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on)
+{
+       struct fimc_sensor_info *s_info = v4l2_get_subdev_hostdata(sd);
+       struct fimc_md *fmd = entity_to_fimc_mdev(&sd->entity);
+
+       return __fimc_md_set_camclk(fmd, s_info, on);
+}
+
+static int fimc_md_link_notify(struct media_pad *source,
+                              struct media_pad *sink, u32 flags)
+{
+       struct v4l2_subdev *sd;
+       struct fimc_dev *fimc;
+       int ret = 0;
+
+       if (media_entity_type(sink->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+               return 0;
+
+       sd = media_entity_to_v4l2_subdev(sink->entity);
+       fimc = v4l2_get_subdevdata(sd);
+
+       if (!(flags & MEDIA_LNK_FL_ENABLED)) {
+               ret = __fimc_pipeline_shutdown(fimc);
+               fimc->pipeline.sensor = NULL;
+               fimc->pipeline.csis = NULL;
+
+               mutex_lock(&fimc->lock);
+               fimc_ctrls_delete(fimc->vid_cap.ctx);
+               mutex_unlock(&fimc->lock);
+               return ret;
+       }
+       /*
+        * Link activation. Enable power of pipeline elements only if the
+        * pipeline is already in use, i.e. its video node is opened.
+        * Recreate the controls destroyed during the link deactivation.
+        */
+       mutex_lock(&fimc->lock);
+       if (fimc->vid_cap.refcnt > 0) {
+               ret = __fimc_pipeline_initialize(fimc, source->entity, true);
+               if (!ret)
+                       ret = fimc_capture_ctrls_create(fimc);
+       }
+       mutex_unlock(&fimc->lock);
+
+       return ret ? -EPIPE : ret;
+}
+
+static ssize_t fimc_md_sysfs_show(struct device *dev,
+                                 struct device_attribute *attr, char *buf)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       struct fimc_md *fmd = platform_get_drvdata(pdev);
+
+       if (fmd->user_subdev_api)
+               return strlcpy(buf, "Sub-device API (sub-dev)\n", PAGE_SIZE);
+
+       return strlcpy(buf, "V4L2 video node only API (vid-dev)\n", PAGE_SIZE);
+}
+
+static ssize_t fimc_md_sysfs_store(struct device *dev,
+                                  struct device_attribute *attr,
+                                  const char *buf, size_t count)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       struct fimc_md *fmd = platform_get_drvdata(pdev);
+       bool subdev_api;
+       int i;
+
+       if (!strcmp(buf, "vid-dev\n"))
+               subdev_api = false;
+       else if (!strcmp(buf, "sub-dev\n"))
+               subdev_api = true;
+       else
+               return count;
+
+       fmd->user_subdev_api = subdev_api;
+       for (i = 0; i < FIMC_MAX_DEVS; i++)
+               if (fmd->fimc[i])
+                       fmd->fimc[i]->vid_cap.user_subdev_api = subdev_api;
+       return count;
+}
+/*
+ * This device attribute is to select video pipeline configuration method.
+ * There are following valid values:
+ *  vid-dev - for V4L2 video node API only, subdevice will be configured
+ *  by the host driver.
+ *  sub-dev - for media controller API, subdevs must be configured in user
+ *  space before starting streaming.
+ */
+static DEVICE_ATTR(subdev_conf_mode, S_IWUSR | S_IRUGO,
+                  fimc_md_sysfs_show, fimc_md_sysfs_store);
+
+static int __devinit fimc_md_probe(struct platform_device *pdev)
+{
+       struct v4l2_device *v4l2_dev;
+       struct fimc_md *fmd;
+       int ret;
+
+       if (WARN(!pdev->dev.platform_data, "Platform data not specified!\n"))
+               return -EINVAL;
+
+       fmd = kzalloc(sizeof(struct fimc_md), GFP_KERNEL);
+       if (!fmd)
+               return -ENOMEM;
+
+       spin_lock_init(&fmd->slock);
+       fmd->pdev = pdev;
+
+       strlcpy(fmd->media_dev.model, "SAMSUNG S5P FIMC",
+               sizeof(fmd->media_dev.model));
+       fmd->media_dev.link_notify = fimc_md_link_notify;
+       fmd->media_dev.dev = &pdev->dev;
+
+       v4l2_dev = &fmd->v4l2_dev;
+       v4l2_dev->mdev = &fmd->media_dev;
+       v4l2_dev->notify = fimc_sensor_notify;
+       snprintf(v4l2_dev->name, sizeof(v4l2_dev->name), "%s",
+                dev_name(&pdev->dev));
+
+       ret = v4l2_device_register(&pdev->dev, &fmd->v4l2_dev);
+       if (ret < 0) {
+               v4l2_err(v4l2_dev, "Failed to register v4l2_device: %d\n", ret);
+               goto err1;
+       }
+       ret = media_device_register(&fmd->media_dev);
+       if (ret < 0) {
+               v4l2_err(v4l2_dev, "Failed to register media device: %d\n", ret);
+               goto err2;
+       }
+       ret = fimc_md_get_clocks(fmd);
+       if (ret)
+               goto err3;
+
+       fmd->user_subdev_api = false;
+       ret = fimc_md_register_platform_entities(fmd);
+       if (ret)
+               goto err3;
+
+       ret = fimc_md_register_sensor_entities(fmd);
+       if (ret)
+               goto err3;
+       ret = fimc_md_create_links(fmd);
+       if (ret)
+               goto err3;
+       ret = v4l2_device_register_subdev_nodes(&fmd->v4l2_dev);
+       if (ret)
+               goto err3;
+       ret = fimc_md_register_video_nodes(fmd);
+       if (ret)
+               goto err3;
+
+       ret = device_create_file(&pdev->dev, &dev_attr_subdev_conf_mode);
+       if (!ret) {
+               platform_set_drvdata(pdev, fmd);
+               return 0;
+       }
+err3:
+       media_device_unregister(&fmd->media_dev);
+       fimc_md_put_clocks(fmd);
+       fimc_md_unregister_entities(fmd);
+err2:
+       v4l2_device_unregister(&fmd->v4l2_dev);
+err1:
+       kfree(fmd);
+       return ret;
+}
+
+static int __devexit fimc_md_remove(struct platform_device *pdev)
+{
+       struct fimc_md *fmd = platform_get_drvdata(pdev);
+
+       if (!fmd)
+               return 0;
+       device_remove_file(&pdev->dev, &dev_attr_subdev_conf_mode);
+       fimc_md_unregister_entities(fmd);
+       media_device_unregister(&fmd->media_dev);
+       fimc_md_put_clocks(fmd);
+       kfree(fmd);
+       return 0;
+}
+
+static struct platform_driver fimc_md_driver = {
+       .probe          = fimc_md_probe,
+       .remove         = __devexit_p(fimc_md_remove),
+       .driver = {
+               .name   = "s5p-fimc-md",
+               .owner  = THIS_MODULE,
+       }
+};
+
+int __init fimc_md_init(void)
+{
+       int ret;
+       request_module("s5p-csis");
+       ret = fimc_register_driver();
+       if (ret)
+               return ret;
+       return platform_driver_register(&fimc_md_driver);
+}
+void __exit fimc_md_exit(void)
+{
+       platform_driver_unregister(&fimc_md_driver);
+       fimc_unregister_driver();
+}
+
+module_init(fimc_md_init);
+module_exit(fimc_md_exit);
+
+MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>");
+MODULE_DESCRIPTION("S5P FIMC camera host interface/video postprocessor driver");
+MODULE_LICENSE("GPL");
+MODULE_VERSION("2.0.1");
diff --git a/drivers/media/video/s5p-fimc/fimc-mdevice.h b/drivers/media/video/s5p-fimc/fimc-mdevice.h
new file mode 100644 (file)
index 0000000..da37808
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2011 Samsung Electronics Co., Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef FIMC_MDEVICE_H_
+#define FIMC_MDEVICE_H_
+
+#include <linux/clk.h>
+#include <linux/platform_device.h>
+#include <linux/mutex.h>
+#include <media/media-device.h>
+#include <media/media-entity.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-subdev.h>
+
+#include "fimc-core.h"
+#include "mipi-csis.h"
+
+/* Group IDs of sensor, MIPI CSIS and the writeback subdevs. */
+#define SENSOR_GROUP_ID                (1 << 8)
+#define CSIS_GROUP_ID          (1 << 9)
+#define WRITEBACK_GROUP_ID     (1 << 10)
+
+#define FIMC_MAX_SENSORS       8
+#define FIMC_MAX_CAMCLKS       2
+
+struct fimc_csis_info {
+       struct v4l2_subdev *sd;
+       int id;
+};
+
+struct fimc_camclk_info {
+       struct clk *clock;
+       int use_count;
+       unsigned long frequency;
+};
+
+/**
+ * struct fimc_sensor_info - image data source subdev information
+ * @pdata: sensor's atrributes passed as media device's platform data
+ * @subdev: image sensor v4l2 subdev
+ * @host: fimc device the sensor is currently linked to
+ * @clk_on: sclk_cam clock's state associated with this subdev
+ *
+ * This data structure applies to image sensor and the writeback subdevs.
+ */
+struct fimc_sensor_info {
+       struct s5p_fimc_isp_info *pdata;
+       struct v4l2_subdev *subdev;
+       struct fimc_dev *host;
+       bool clk_on;
+};
+
+/**
+ * struct fimc_md - fimc media device information
+ * @csis: MIPI CSIS subdevs data
+ * @sensor: array of registered sensor subdevs
+ * @num_sensors: actual number of registered sensors
+ * @camclk: external sensor clock information
+ * @fimc: array of registered fimc devices
+ * @media_dev: top level media device
+ * @v4l2_dev: top level v4l2_device holding up the subdevs
+ * @pdev: platform device this media device is hooked up into
+ * @user_subdev_api: true if subdevs are not configured by the host driver
+ * @slock: spinlock protecting @sensor array
+ */
+struct fimc_md {
+       struct fimc_csis_info csis[CSIS_MAX_ENTITIES];
+       struct fimc_sensor_info sensor[FIMC_MAX_SENSORS];
+       int num_sensors;
+       struct fimc_camclk_info camclk[FIMC_MAX_CAMCLKS];
+       struct fimc_dev *fimc[FIMC_MAX_DEVS];
+       struct media_device media_dev;
+       struct v4l2_device v4l2_dev;
+       struct platform_device *pdev;
+       bool user_subdev_api;
+       spinlock_t slock;
+};
+
+#define is_subdev_pad(pad) (pad == NULL || \
+       media_entity_type(pad->entity) == MEDIA_ENT_T_V4L2_SUBDEV)
+
+#define me_subtype(me) \
+       ((me->type) & (MEDIA_ENT_TYPE_MASK | MEDIA_ENT_SUBTYPE_MASK))
+
+#define subdev_has_devnode(__sd) (__sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE)
+
+static inline struct fimc_md *entity_to_fimc_mdev(struct media_entity *me)
+{
+       return me->parent == NULL ? NULL :
+               container_of(me->parent, struct fimc_md, media_dev);
+}
+
+static inline void fimc_md_graph_lock(struct fimc_dev *fimc)
+{
+       BUG_ON(fimc->vid_cap.vfd == NULL);
+       mutex_lock(&fimc->vid_cap.vfd->entity.parent->graph_mutex);
+}
+
+static inline void fimc_md_graph_unlock(struct fimc_dev *fimc)
+{
+       BUG_ON(fimc->vid_cap.vfd == NULL);
+       mutex_unlock(&fimc->vid_cap.vfd->entity.parent->graph_mutex);
+}
+
+int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on);
+void fimc_pipeline_prepare(struct fimc_dev *fimc, struct media_entity *me);
+int fimc_pipeline_initialize(struct fimc_dev *fimc, struct media_entity *me,
+                            bool resume);
+int fimc_pipeline_shutdown(struct fimc_dev *fimc);
+int fimc_pipeline_s_power(struct fimc_dev *fimc, int state);
+int fimc_pipeline_s_stream(struct fimc_dev *fimc, int state);
+
+#endif
index 4893b2d91d84606520f4901eebb1db5167254f0a..20e664e341632df52877c78ef10ce96f6bc57301 100644 (file)
@@ -30,7 +30,7 @@ void fimc_hw_reset(struct fimc_dev *dev)
        cfg = readl(dev->regs + S5P_CIGCTRL);
        cfg |= (S5P_CIGCTRL_SWRST | S5P_CIGCTRL_IRQ_LEVEL);
        writel(cfg, dev->regs + S5P_CIGCTRL);
-       udelay(1000);
+       udelay(10);
 
        cfg = readl(dev->regs + S5P_CIGCTRL);
        cfg &= ~S5P_CIGCTRL_SWRST;
@@ -41,19 +41,11 @@ static u32 fimc_hw_get_in_flip(struct fimc_ctx *ctx)
 {
        u32 flip = S5P_MSCTRL_FLIP_NORMAL;
 
-       switch (ctx->flip) {
-       case FLIP_X_AXIS:
+       if (ctx->hflip)
                flip = S5P_MSCTRL_FLIP_X_MIRROR;
-               break;
-       case FLIP_Y_AXIS:
+       if (ctx->vflip)
                flip = S5P_MSCTRL_FLIP_Y_MIRROR;
-               break;
-       case FLIP_XY_AXIS:
-               flip = S5P_MSCTRL_FLIP_180;
-               break;
-       default:
-               break;
-       }
+
        if (ctx->rotation <= 90)
                return flip;
 
@@ -64,19 +56,11 @@ static u32 fimc_hw_get_target_flip(struct fimc_ctx *ctx)
 {
        u32 flip = S5P_CITRGFMT_FLIP_NORMAL;
 
-       switch (ctx->flip) {
-       case FLIP_X_AXIS:
-               flip = S5P_CITRGFMT_FLIP_X_MIRROR;
-               break;
-       case FLIP_Y_AXIS:
-               flip = S5P_CITRGFMT_FLIP_Y_MIRROR;
-               break;
-       case FLIP_XY_AXIS:
-               flip = S5P_CITRGFMT_FLIP_180;
-               break;
-       default:
-               break;
-       }
+       if (ctx->hflip)
+               flip |= S5P_CITRGFMT_FLIP_X_MIRROR;
+       if (ctx->vflip)
+               flip |= S5P_CITRGFMT_FLIP_Y_MIRROR;
+
        if (ctx->rotation <= 90)
                return flip;
 
@@ -368,17 +352,19 @@ void fimc_hw_en_capture(struct fimc_ctx *ctx)
        writel(cfg | S5P_CIIMGCPT_IMGCPTEN, dev->regs + S5P_CIIMGCPT);
 }
 
-void fimc_hw_set_effect(struct fimc_ctx *ctx)
+void fimc_hw_set_effect(struct fimc_ctx *ctx, bool active)
 {
        struct fimc_dev *dev = ctx->fimc_dev;
        struct fimc_effect *effect = &ctx->effect;
-       u32 cfg = (S5P_CIIMGEFF_IE_ENABLE | S5P_CIIMGEFF_IE_SC_AFTER);
-
-       cfg |= effect->type;
+       u32 cfg = 0;
 
-       if (effect->type == S5P_FIMC_EFFECT_ARBITRARY) {
-               cfg |= S5P_CIIMGEFF_PAT_CB(effect->pat_cb);
-               cfg |= S5P_CIIMGEFF_PAT_CR(effect->pat_cr);
+       if (active) {
+               cfg |= S5P_CIIMGEFF_IE_SC_AFTER | S5P_CIIMGEFF_IE_ENABLE;
+               cfg |= effect->type;
+               if (effect->type == S5P_FIMC_EFFECT_ARBITRARY) {
+                       cfg |= S5P_CIIMGEFF_PAT_CB(effect->pat_cb);
+                       cfg |= S5P_CIIMGEFF_PAT_CR(effect->pat_cr);
+               }
        }
 
        writel(cfg, dev->regs + S5P_CIIMGEFF);
@@ -547,20 +533,24 @@ int fimc_hw_set_camera_polarity(struct fimc_dev *fimc,
        u32 cfg = readl(fimc->regs + S5P_CIGCTRL);
 
        cfg &= ~(S5P_CIGCTRL_INVPOLPCLK | S5P_CIGCTRL_INVPOLVSYNC |
-                S5P_CIGCTRL_INVPOLHREF | S5P_CIGCTRL_INVPOLHSYNC);
+                S5P_CIGCTRL_INVPOLHREF | S5P_CIGCTRL_INVPOLHSYNC |
+                S5P_CIGCTRL_INVPOLFIELD);
 
-       if (cam->flags & FIMC_CLK_INV_PCLK)
+       if (cam->flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)
                cfg |= S5P_CIGCTRL_INVPOLPCLK;
 
-       if (cam->flags & FIMC_CLK_INV_VSYNC)
+       if (cam->flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)
                cfg |= S5P_CIGCTRL_INVPOLVSYNC;
 
-       if (cam->flags & FIMC_CLK_INV_HREF)
+       if (cam->flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)
                cfg |= S5P_CIGCTRL_INVPOLHREF;
 
-       if (cam->flags & FIMC_CLK_INV_HSYNC)
+       if (cam->flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)
                cfg |= S5P_CIGCTRL_INVPOLHSYNC;
 
+       if (cam->flags & V4L2_MBUS_FIELD_EVEN_LOW)
+               cfg |= S5P_CIGCTRL_INVPOLFIELD;
+
        writel(cfg, fimc->regs + S5P_CIGCTRL);
 
        return 0;
@@ -588,7 +578,7 @@ int fimc_hw_set_camera_source(struct fimc_dev *fimc,
 
        if (cam->bus_type == FIMC_ITU_601 || cam->bus_type == FIMC_ITU_656) {
                for (i = 0; i < ARRAY_SIZE(pix_desc); i++) {
-                       if (fimc->vid_cap.fmt.code == pix_desc[i].pixelcode) {
+                       if (fimc->vid_cap.mf.code == pix_desc[i].pixelcode) {
                                cfg = pix_desc[i].cisrcfmt;
                                bus_width = pix_desc[i].bus_width;
                                break;
@@ -596,9 +586,9 @@ int fimc_hw_set_camera_source(struct fimc_dev *fimc,
                }
 
                if (i == ARRAY_SIZE(pix_desc)) {
-                       v4l2_err(&fimc->vid_cap.v4l2_dev,
+                       v4l2_err(fimc->vid_cap.vfd,
                                 "Camera color format not supported: %d\n",
-                                fimc->vid_cap.fmt.code);
+                                fimc->vid_cap.mf.code);
                        return -EINVAL;
                }
 
@@ -608,6 +598,9 @@ int fimc_hw_set_camera_source(struct fimc_dev *fimc,
                        else if (bus_width == 16)
                                cfg |= S5P_CISRCFMT_ITU601_16BIT;
                } /* else defaults to ITU-R BT.656 8-bit */
+       } else if (cam->bus_type == FIMC_MIPI_CSI2) {
+               if (fimc_fmt_is_jpeg(f->fmt->color))
+                       cfg |= S5P_CISRCFMT_ITU601_8BIT;
        }
 
        cfg |= S5P_CISRCFMT_HSIZE(f->o_width) | S5P_CISRCFMT_VSIZE(f->o_height);
@@ -649,7 +642,7 @@ int fimc_hw_set_camera_type(struct fimc_dev *fimc,
        /* Select ITU B interface, disable Writeback path and test pattern. */
        cfg &= ~(S5P_CIGCTRL_TESTPAT_MASK | S5P_CIGCTRL_SELCAM_ITU_A |
                S5P_CIGCTRL_SELCAM_MIPI | S5P_CIGCTRL_CAMIF_SELWB |
-               S5P_CIGCTRL_SELCAM_MIPI_A);
+               S5P_CIGCTRL_SELCAM_MIPI_A | S5P_CIGCTRL_CAM_JPEG);
 
        if (cam->bus_type == FIMC_MIPI_CSI2) {
                cfg |= S5P_CIGCTRL_SELCAM_MIPI;
@@ -658,11 +651,18 @@ int fimc_hw_set_camera_type(struct fimc_dev *fimc,
                        cfg |= S5P_CIGCTRL_SELCAM_MIPI_A;
 
                /* TODO: add remaining supported formats. */
-               if (vid_cap->fmt.code == V4L2_MBUS_FMT_VYUY8_2X8) {
+               switch (vid_cap->mf.code) {
+               case V4L2_MBUS_FMT_VYUY8_2X8:
                        tmp = S5P_CSIIMGFMT_YCBCR422_8BIT;
-               } else {
-                       err("camera image format not supported: %d",
-                           vid_cap->fmt.code);
+                       break;
+               case V4L2_MBUS_FMT_JPEG_1X8:
+                       tmp = S5P_CSIIMGFMT_USER(1);
+                       cfg |= S5P_CIGCTRL_CAM_JPEG;
+                       break;
+               default:
+                       v4l2_err(fimc->vid_cap.vfd,
+                                "Not supported camera pixel format: %d",
+                                vid_cap->mf.code);
                        return -EINVAL;
                }
                tmp |= (cam->csi_data_align == 32) << 8;
index ef056d6605ca8d106dec32a9d29a8cd31bf573ed..59d79bc2f58a243c1de3cfa15b3af40b10c4cbaa 100644 (file)
@@ -81,6 +81,12 @@ static char *csi_clock_name[] = {
 };
 #define NUM_CSIS_CLOCKS        ARRAY_SIZE(csi_clock_name)
 
+static const char * const csis_supply_name[] = {
+       "vdd11", /* 1.1V or 1.2V (s5pc100) MIPI CSI suppply */
+       "vdd18", /* VDD 1.8V and MIPI CSI PLL supply */
+};
+#define CSIS_NUM_SUPPLIES ARRAY_SIZE(csis_supply_name)
+
 enum {
        ST_POWERED      = 1,
        ST_STREAMING    = 2,
@@ -109,9 +115,9 @@ struct csis_state {
        struct platform_device *pdev;
        struct resource *regs_res;
        void __iomem *regs;
+       struct regulator_bulk_data supplies[CSIS_NUM_SUPPLIES];
        struct clk *clock[NUM_CSIS_CLOCKS];
        int irq;
-       struct regulator *supply;
        u32 flags;
        const struct csis_pix_format *csis_fmt;
        struct v4l2_mbus_framefmt format;
@@ -460,6 +466,7 @@ static int __devinit s5pcsis_probe(struct platform_device *pdev)
        struct resource *regs_res;
        struct csis_state *state;
        int ret = -ENOMEM;
+       int i;
 
        state = kzalloc(sizeof(*state), GFP_KERNEL);
        if (!state)
@@ -519,14 +526,13 @@ static int __devinit s5pcsis_probe(struct platform_device *pdev)
                goto e_clkput;
        }
 
-       if (!pdata->fixed_phy_vdd) {
-               state->supply = regulator_get(&pdev->dev, "vdd");
-               if (IS_ERR(state->supply)) {
-                       ret = PTR_ERR(state->supply);
-                       state->supply = NULL;
-                       goto e_clkput;
-               }
-       }
+       for (i = 0; i < CSIS_NUM_SUPPLIES; i++)
+               state->supplies[i].supply = csis_supply_name[i];
+
+       ret = regulator_bulk_get(&pdev->dev, CSIS_NUM_SUPPLIES,
+                                state->supplies);
+       if (ret)
+               goto e_clkput;
 
        ret = request_irq(state->irq, s5pcsis_irq_handler, 0,
                          dev_name(&pdev->dev), state);
@@ -553,7 +559,6 @@ static int __devinit s5pcsis_probe(struct platform_device *pdev)
        /* .. and a pointer to the subdev. */
        platform_set_drvdata(pdev, &state->sd);
 
-       state->flags = ST_SUSPENDED;
        pm_runtime_enable(&pdev->dev);
 
        return 0;
@@ -561,8 +566,7 @@ static int __devinit s5pcsis_probe(struct platform_device *pdev)
 e_irqfree:
        free_irq(state->irq, state);
 e_regput:
-       if (state->supply)
-               regulator_put(state->supply);
+       regulator_bulk_free(CSIS_NUM_SUPPLIES, state->supplies);
 e_clkput:
        clk_disable(state->clock[CSIS_CLK_MUX]);
        s5pcsis_clk_put(state);
@@ -575,7 +579,7 @@ e_free:
        return ret;
 }
 
-static int s5pcsis_suspend(struct device *dev)
+static int s5pcsis_pm_suspend(struct device *dev, bool runtime)
 {
        struct s5p_platform_mipi_csis *pdata = dev->platform_data;
        struct platform_device *pdev = to_platform_device(dev);
@@ -592,21 +596,21 @@ static int s5pcsis_suspend(struct device *dev)
                ret = pdata->phy_enable(state->pdev, false);
                if (ret)
                        goto unlock;
-               if (state->supply) {
-                       ret = regulator_disable(state->supply);
-                       if (ret)
-                               goto unlock;
-               }
+               ret = regulator_bulk_disable(CSIS_NUM_SUPPLIES,
+                                            state->supplies);
+               if (ret)
+                       goto unlock;
                clk_disable(state->clock[CSIS_CLK_GATE]);
                state->flags &= ~ST_POWERED;
+               if (!runtime)
+                       state->flags |= ST_SUSPENDED;
        }
-       state->flags |= ST_SUSPENDED;
  unlock:
        mutex_unlock(&state->lock);
        return ret ? -EAGAIN : 0;
 }
 
-static int s5pcsis_resume(struct device *dev)
+static int s5pcsis_pm_resume(struct device *dev, bool runtime)
 {
        struct s5p_platform_mipi_csis *pdata = dev->platform_data;
        struct platform_device *pdev = to_platform_device(dev);
@@ -618,20 +622,20 @@ static int s5pcsis_resume(struct device *dev)
                 __func__, state->flags);
 
        mutex_lock(&state->lock);
-       if (!(state->flags & ST_SUSPENDED))
+       if (!runtime && !(state->flags & ST_SUSPENDED))
                goto unlock;
 
        if (!(state->flags & ST_POWERED)) {
-               if (state->supply)
-                       ret = regulator_enable(state->supply);
+               ret = regulator_bulk_enable(CSIS_NUM_SUPPLIES,
+                                           state->supplies);
                if (ret)
                        goto unlock;
-
                ret = pdata->phy_enable(state->pdev, true);
                if (!ret) {
                        state->flags |= ST_POWERED;
-               } else if (state->supply) {
-                       regulator_disable(state->supply);
+               } else {
+                       regulator_bulk_disable(CSIS_NUM_SUPPLIES,
+                                              state->supplies);
                        goto unlock;
                }
                clk_enable(state->clock[CSIS_CLK_GATE]);
@@ -646,24 +650,26 @@ static int s5pcsis_resume(struct device *dev)
 }
 
 #ifdef CONFIG_PM_SLEEP
-static int s5pcsis_pm_suspend(struct device *dev)
+static int s5pcsis_suspend(struct device *dev)
 {
-       return s5pcsis_suspend(dev);
+       return s5pcsis_pm_suspend(dev, false);
 }
 
-static int s5pcsis_pm_resume(struct device *dev)
+static int s5pcsis_resume(struct device *dev)
 {
-       int ret;
-
-       ret = s5pcsis_resume(dev);
+       return s5pcsis_pm_resume(dev, false);
+}
+#endif
 
-       if (!ret) {
-               pm_runtime_disable(dev);
-               ret = pm_runtime_set_active(dev);
-               pm_runtime_enable(dev);
-       }
+#ifdef CONFIG_PM_RUNTIME
+static int s5pcsis_runtime_suspend(struct device *dev)
+{
+       return s5pcsis_pm_suspend(dev, true);
+}
 
-       return ret;
+static int s5pcsis_runtime_resume(struct device *dev)
+{
+       return s5pcsis_pm_resume(dev, true);
 }
 #endif
 
@@ -679,8 +685,7 @@ static int __devexit s5pcsis_remove(struct platform_device *pdev)
        pm_runtime_set_suspended(&pdev->dev);
 
        s5pcsis_clk_put(state);
-       if (state->supply)
-               regulator_put(state->supply);
+       regulator_bulk_free(CSIS_NUM_SUPPLIES, state->supplies);
 
        media_entity_cleanup(&state->sd.entity);
        free_irq(state->irq, state);
@@ -692,8 +697,9 @@ static int __devexit s5pcsis_remove(struct platform_device *pdev)
 }
 
 static const struct dev_pm_ops s5pcsis_pm_ops = {
-       SET_RUNTIME_PM_OPS(s5pcsis_suspend, s5pcsis_resume, NULL)
-       SET_SYSTEM_SLEEP_PM_OPS(s5pcsis_pm_suspend, s5pcsis_pm_resume)
+       SET_RUNTIME_PM_OPS(s5pcsis_runtime_suspend, s5pcsis_runtime_resume,
+                          NULL)
+       SET_SYSTEM_SLEEP_PM_OPS(s5pcsis_suspend, s5pcsis_resume)
 };
 
 static struct platform_driver s5pcsis_driver = {
index 0fea3e635d76bd19c487dc81bb89307bd4684011..c8e3b94bd91d2ca7cf16c66886a33c9afbe1c290 100644 (file)
 #define S5P_CIGCTRL_IRQ_CLR            (1 << 19)
 #define S5P_CIGCTRL_IRQ_ENABLE         (1 << 16)
 #define S5P_CIGCTRL_SHDW_DISABLE       (1 << 12)
+#define S5P_CIGCTRL_CAM_JPEG           (1 << 8)
 #define S5P_CIGCTRL_SELCAM_MIPI_A      (1 << 7)
 #define S5P_CIGCTRL_CAMIF_SELWB                (1 << 6)
 /* 0 - ITU601; 1 - ITU709 */
 #define S5P_CIGCTRL_CSC_ITU601_709     (1 << 5)
 #define S5P_CIGCTRL_INVPOLHSYNC                (1 << 4)
 #define S5P_CIGCTRL_SELCAM_MIPI                (1 << 3)
+#define S5P_CIGCTRL_INVPOLFIELD                (1 << 1)
 #define S5P_CIGCTRL_INTERLACE          (1 << 0)
 
 /* Window offset 2 */
 
 /* Image effect */
 #define S5P_CIIMGEFF                   0xd0
-#define S5P_CIIMGEFF_IE_DISABLE                (0 << 30)
 #define S5P_CIIMGEFF_IE_ENABLE         (1 << 30)
 #define S5P_CIIMGEFF_IE_SC_BEFORE      (0 << 29)
 #define S5P_CIIMGEFF_IE_SC_AFTER       (1 << 29)
 #define S5P_CSIIMGFMT_RAW8             0x2a
 #define S5P_CSIIMGFMT_RAW10            0x2b
 #define S5P_CSIIMGFMT_RAW12            0x2c
-#define S5P_CSIIMGFMT_USER1            0x30
-#define S5P_CSIIMGFMT_USER2            0x31
-#define S5P_CSIIMGFMT_USER3            0x32
-#define S5P_CSIIMGFMT_USER4            0x33
+/* User defined formats. x = 0...16. */
+#define S5P_CSIIMGFMT_USER(x)          (0x30 + x - 1)
 
 /* Output frame buffer sequence mask */
 #define S5P_CIFCNTSEQ                  0x1FC
index 7dc7eab58b387e1bd4c2711ed32f9d1259913bfc..8be8b54eb749769449a49f68fcf23f57b3628bd9 100644 (file)
@@ -202,7 +202,7 @@ static void s5p_mfc_handle_frame_copy_time(struct s5p_mfc_ctx *ctx)
           appropraite flags */
        src_buf = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
        list_for_each_entry(dst_buf, &ctx->dst_queue, list) {
-               if (vb2_dma_contig_plane_paddr(dst_buf->b, 0) == dec_y_addr) {
+               if (vb2_dma_contig_plane_dma_addr(dst_buf->b, 0) == dec_y_addr) {
                        memcpy(&dst_buf->b->v4l2_buf.timecode,
                                &src_buf->b->v4l2_buf.timecode,
                                sizeof(struct v4l2_timecode));
@@ -248,7 +248,7 @@ static void s5p_mfc_handle_frame_new(struct s5p_mfc_ctx *ctx, unsigned int err)
         * check which videobuf does it correspond to */
        list_for_each_entry(dst_buf, &ctx->dst_queue, list) {
                /* Check if this is the buffer we're looking for */
-               if (vb2_dma_contig_plane_paddr(dst_buf->b, 0) == dspl_y_addr) {
+               if (vb2_dma_contig_plane_dma_addr(dst_buf->b, 0) == dspl_y_addr) {
                        list_del(&dst_buf->list);
                        ctx->dst_queue_cnt--;
                        dst_buf->b->v4l2_buf.sequence = ctx->sequence;
@@ -940,9 +940,8 @@ static int match_child(struct device *dev, void *data)
        return !strcmp(dev_name(dev), (char *)data);
 }
 
-
 /* MFC probe function */
-static int __devinit s5p_mfc_probe(struct platform_device *pdev)
+static int s5p_mfc_probe(struct platform_device *pdev)
 {
        struct s5p_mfc_dev *dev;
        struct video_device *vfd;
@@ -1236,7 +1235,7 @@ static const struct dev_pm_ops s5p_mfc_pm_ops = {
                           NULL)
 };
 
-static struct platform_driver s5p_mfc_pdrv = {
+static struct platform_driver s5p_mfc_driver = {
        .probe  = s5p_mfc_probe,
        .remove = __devexit_p(s5p_mfc_remove),
        .driver = {
@@ -1254,15 +1253,15 @@ static int __init s5p_mfc_init(void)
        int ret;
 
        pr_info("%s", banner);
-       ret = platform_driver_register(&s5p_mfc_pdrv);
+       ret = platform_driver_register(&s5p_mfc_driver);
        if (ret)
                pr_err("Platform device registration failed.\n");
        return ret;
 }
 
-static void __devexit s5p_mfc_exit(void)
+static void __exit s5p_mfc_exit(void)
 {
-       platform_driver_unregister(&s5p_mfc_pdrv);
+       platform_driver_unregister(&s5p_mfc_driver);
 }
 
 module_init(s5p_mfc_init);
index b2c5052a9c41f6533723c2e6da160bd095e3cc94..bfbe08432050af205ca19d46e7abcfd073ee2df8 100644 (file)
@@ -165,7 +165,7 @@ static struct mfc_control controls[] = {
                .maximum = 32,
                .step = 1,
                .default_value = 1,
-               .is_volatile = 1,
+               .flags = V4L2_CTRL_FLAG_VOLATILE,
        },
 };
 
@@ -745,7 +745,7 @@ static const struct v4l2_ioctl_ops s5p_mfc_dec_ioctl_ops = {
 };
 
 static int s5p_mfc_queue_setup(struct vb2_queue *vq, unsigned int *buf_count,
-                              unsigned int *plane_count, unsigned long psize[],
+                              unsigned int *plane_count, unsigned int psize[],
                               void *allocators[])
 {
        struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
@@ -824,7 +824,7 @@ static int s5p_mfc_buf_init(struct vb2_buffer *vb)
                        return 0;
                for (i = 0; i <= ctx->src_fmt->num_planes ; i++) {
                        if (IS_ERR_OR_NULL(ERR_PTR(
-                                       vb2_dma_contig_plane_paddr(vb, i)))) {
+                                       vb2_dma_contig_plane_dma_addr(vb, i)))) {
                                mfc_err("Plane mem not allocated\n");
                                return -EINVAL;
                        }
@@ -837,13 +837,13 @@ static int s5p_mfc_buf_init(struct vb2_buffer *vb)
                i = vb->v4l2_buf.index;
                ctx->dst_bufs[i].b = vb;
                ctx->dst_bufs[i].cookie.raw.luma =
-                                       vb2_dma_contig_plane_paddr(vb, 0);
+                                       vb2_dma_contig_plane_dma_addr(vb, 0);
                ctx->dst_bufs[i].cookie.raw.chroma =
-                                       vb2_dma_contig_plane_paddr(vb, 1);
+                                       vb2_dma_contig_plane_dma_addr(vb, 1);
                ctx->dst_bufs_cnt++;
        } else if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
                if (IS_ERR_OR_NULL(ERR_PTR(
-                                       vb2_dma_contig_plane_paddr(vb, 0)))) {
+                                       vb2_dma_contig_plane_dma_addr(vb, 0)))) {
                        mfc_err("Plane memory not allocated\n");
                        return -EINVAL;
                }
@@ -855,7 +855,7 @@ static int s5p_mfc_buf_init(struct vb2_buffer *vb)
                i = vb->v4l2_buf.index;
                ctx->src_bufs[i].b = vb;
                ctx->src_bufs[i].cookie.stream =
-                                       vb2_dma_contig_plane_paddr(vb, 0);
+                                       vb2_dma_contig_plane_dma_addr(vb, 0);
                ctx->src_bufs_cnt++;
        } else {
                mfc_err("s5p_mfc_buf_init: unknown queue type\n");
@@ -864,7 +864,7 @@ static int s5p_mfc_buf_init(struct vb2_buffer *vb)
        return 0;
 }
 
-static int s5p_mfc_start_streaming(struct vb2_queue *q)
+static int s5p_mfc_start_streaming(struct vb2_queue *q, unsigned int count)
 {
        struct s5p_mfc_ctx *ctx = fh_to_ctx(q->drv_priv);
        struct s5p_mfc_dev *dev = ctx->dev;
@@ -1020,7 +1020,7 @@ int s5p_mfc_dec_ctrls_setup(struct s5p_mfc_ctx *ctx)
                        return ctx->ctrl_handler.error;
                }
                if (controls[i].is_volatile && ctx->ctrls[i])
-                       ctx->ctrls[i]->is_volatile = 1;
+                       ctx->ctrls[i]->flags |= V4L2_CTRL_FLAG_VOLATILE;
        }
        return 0;
 }
index fee094a14f4c3c6ec5ccadbbc55211cf71b37a9d..4c90e53bd96467675c7ab7155773ec7bf590d6c2 100644 (file)
@@ -599,8 +599,8 @@ static void cleanup_ref_queue(struct s5p_mfc_ctx *ctx)
        while (!list_empty(&ctx->ref_queue)) {
                mb_entry = list_entry((&ctx->ref_queue)->next,
                                                struct s5p_mfc_buf, list);
-               mb_y_addr = vb2_dma_contig_plane_paddr(mb_entry->b, 0);
-               mb_c_addr = vb2_dma_contig_plane_paddr(mb_entry->b, 1);
+               mb_y_addr = vb2_dma_contig_plane_dma_addr(mb_entry->b, 0);
+               mb_c_addr = vb2_dma_contig_plane_dma_addr(mb_entry->b, 1);
                list_del(&mb_entry->list);
                ctx->ref_queue_cnt--;
                list_add_tail(&mb_entry->list, &ctx->src_queue);
@@ -622,7 +622,7 @@ static int enc_pre_seq_start(struct s5p_mfc_ctx *ctx)
 
        spin_lock_irqsave(&dev->irqlock, flags);
        dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
-       dst_addr = vb2_dma_contig_plane_paddr(dst_mb->b, 0);
+       dst_addr = vb2_dma_contig_plane_dma_addr(dst_mb->b, 0);
        dst_size = vb2_plane_size(dst_mb->b, 0);
        s5p_mfc_set_enc_stream_buffer(ctx, dst_addr, dst_size);
        spin_unlock_irqrestore(&dev->irqlock, flags);
@@ -668,14 +668,14 @@ static int enc_pre_frame_start(struct s5p_mfc_ctx *ctx)
 
        spin_lock_irqsave(&dev->irqlock, flags);
        src_mb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
-       src_y_addr = vb2_dma_contig_plane_paddr(src_mb->b, 0);
-       src_c_addr = vb2_dma_contig_plane_paddr(src_mb->b, 1);
+       src_y_addr = vb2_dma_contig_plane_dma_addr(src_mb->b, 0);
+       src_c_addr = vb2_dma_contig_plane_dma_addr(src_mb->b, 1);
        s5p_mfc_set_enc_frame_buffer(ctx, src_y_addr, src_c_addr);
        spin_unlock_irqrestore(&dev->irqlock, flags);
 
        spin_lock_irqsave(&dev->irqlock, flags);
        dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
-       dst_addr = vb2_dma_contig_plane_paddr(dst_mb->b, 0);
+       dst_addr = vb2_dma_contig_plane_dma_addr(dst_mb->b, 0);
        dst_size = vb2_plane_size(dst_mb->b, 0);
        s5p_mfc_set_enc_stream_buffer(ctx, dst_addr, dst_size);
        spin_unlock_irqrestore(&dev->irqlock, flags);
@@ -703,8 +703,8 @@ static int enc_post_frame_start(struct s5p_mfc_ctx *ctx)
        if (slice_type >= 0) {
                s5p_mfc_get_enc_frame_buffer(ctx, &enc_y_addr, &enc_c_addr);
                list_for_each_entry(mb_entry, &ctx->src_queue, list) {
-                       mb_y_addr = vb2_dma_contig_plane_paddr(mb_entry->b, 0);
-                       mb_c_addr = vb2_dma_contig_plane_paddr(mb_entry->b, 1);
+                       mb_y_addr = vb2_dma_contig_plane_dma_addr(mb_entry->b, 0);
+                       mb_c_addr = vb2_dma_contig_plane_dma_addr(mb_entry->b, 1);
                        if ((enc_y_addr == mb_y_addr) &&
                                                (enc_c_addr == mb_c_addr)) {
                                list_del(&mb_entry->list);
@@ -715,8 +715,8 @@ static int enc_post_frame_start(struct s5p_mfc_ctx *ctx)
                        }
                }
                list_for_each_entry(mb_entry, &ctx->ref_queue, list) {
-                       mb_y_addr = vb2_dma_contig_plane_paddr(mb_entry->b, 0);
-                       mb_c_addr = vb2_dma_contig_plane_paddr(mb_entry->b, 1);
+                       mb_y_addr = vb2_dma_contig_plane_dma_addr(mb_entry->b, 0);
+                       mb_c_addr = vb2_dma_contig_plane_dma_addr(mb_entry->b, 1);
                        if ((enc_y_addr == mb_y_addr) &&
                                                (enc_c_addr == mb_c_addr)) {
                                list_del(&mb_entry->list);
@@ -1501,20 +1501,20 @@ static int check_vb_with_fmt(struct s5p_mfc_fmt *fmt, struct vb2_buffer *vb)
                return -EINVAL;
        }
        for (i = 0; i < fmt->num_planes; i++) {
-               if (!vb2_dma_contig_plane_paddr(vb, i)) {
+               if (!vb2_dma_contig_plane_dma_addr(vb, i)) {
                        mfc_err("failed to get plane cookie\n");
                        return -EINVAL;
                }
                mfc_debug(2, "index: %d, plane[%d] cookie: 0x%08zx",
                                vb->v4l2_buf.index, i,
-                               vb2_dma_contig_plane_paddr(vb, i));
+                               vb2_dma_contig_plane_dma_addr(vb, i));
        }
        return 0;
 }
 
 static int s5p_mfc_queue_setup(struct vb2_queue *vq,
                       unsigned int *buf_count, unsigned int *plane_count,
-                      unsigned long psize[], void *allocators[])
+                      unsigned int psize[], void *allocators[])
 {
        struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
 
@@ -1584,7 +1584,7 @@ static int s5p_mfc_buf_init(struct vb2_buffer *vb)
                i = vb->v4l2_buf.index;
                ctx->dst_bufs[i].b = vb;
                ctx->dst_bufs[i].cookie.stream =
-                                       vb2_dma_contig_plane_paddr(vb, 0);
+                                       vb2_dma_contig_plane_dma_addr(vb, 0);
                ctx->dst_bufs_cnt++;
        } else if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
                ret = check_vb_with_fmt(ctx->src_fmt, vb);
@@ -1593,9 +1593,9 @@ static int s5p_mfc_buf_init(struct vb2_buffer *vb)
                i = vb->v4l2_buf.index;
                ctx->src_bufs[i].b = vb;
                ctx->src_bufs[i].cookie.raw.luma =
-                                       vb2_dma_contig_plane_paddr(vb, 0);
+                                       vb2_dma_contig_plane_dma_addr(vb, 0);
                ctx->src_bufs[i].cookie.raw.chroma =
-                                       vb2_dma_contig_plane_paddr(vb, 1);
+                                       vb2_dma_contig_plane_dma_addr(vb, 1);
                ctx->src_bufs_cnt++;
        } else {
                mfc_err("inavlid queue type: %d\n", vq->type);
@@ -1640,7 +1640,7 @@ static int s5p_mfc_buf_prepare(struct vb2_buffer *vb)
        return 0;
 }
 
-static int s5p_mfc_start_streaming(struct vb2_queue *q)
+static int s5p_mfc_start_streaming(struct vb2_queue *q, unsigned int count)
 {
        struct s5p_mfc_ctx *ctx = fh_to_ctx(q->drv_priv);
        struct s5p_mfc_dev *dev = ctx->dev;
@@ -1814,7 +1814,7 @@ int s5p_mfc_enc_ctrls_setup(struct s5p_mfc_ctx *ctx)
                        return ctx->ctrl_handler.error;
                }
                if (controls[i].is_volatile && ctx->ctrls[i])
-                       ctx->ctrls[i]->is_volatile = 1;
+                       ctx->ctrls[i]->flags |= V4L2_CTRL_FLAG_VOLATILE;
        }
        return 0;
 }
index 7b239168c1995b68403f24b22a43e73632f4ac10..e08b21c50ebfc0c415993cdf845e9a6f0c5cf53e 100644 (file)
@@ -1135,7 +1135,7 @@ static int s5p_mfc_run_dec_frame(struct s5p_mfc_ctx *ctx, int last_frame)
        temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
        temp_vb->used = 1;
        s5p_mfc_set_dec_stream_buffer(ctx,
-               vb2_dma_contig_plane_paddr(temp_vb->b, 0), ctx->consumed_stream,
+               vb2_dma_contig_plane_dma_addr(temp_vb->b, 0), ctx->consumed_stream,
                                        temp_vb->b->v4l2_planes[0].bytesused);
        spin_unlock_irqrestore(&dev->irqlock, flags);
        index = temp_vb->b->v4l2_buf.index;
@@ -1172,12 +1172,12 @@ static int s5p_mfc_run_enc_frame(struct s5p_mfc_ctx *ctx)
        }
        src_mb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
        src_mb->used = 1;
-       src_y_addr = vb2_dma_contig_plane_paddr(src_mb->b, 0);
-       src_c_addr = vb2_dma_contig_plane_paddr(src_mb->b, 1);
+       src_y_addr = vb2_dma_contig_plane_dma_addr(src_mb->b, 0);
+       src_c_addr = vb2_dma_contig_plane_dma_addr(src_mb->b, 1);
        s5p_mfc_set_enc_frame_buffer(ctx, src_y_addr, src_c_addr);
        dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
        dst_mb->used = 1;
-       dst_addr = vb2_dma_contig_plane_paddr(dst_mb->b, 0);
+       dst_addr = vb2_dma_contig_plane_dma_addr(dst_mb->b, 0);
        dst_size = vb2_plane_size(dst_mb->b, 0);
        s5p_mfc_set_enc_stream_buffer(ctx, dst_addr, dst_size);
        spin_unlock_irqrestore(&dev->irqlock, flags);
@@ -1200,7 +1200,7 @@ static void s5p_mfc_run_init_dec(struct s5p_mfc_ctx *ctx)
        s5p_mfc_set_dec_desc_buffer(ctx);
        mfc_debug(2, "Header size: %d\n", temp_vb->b->v4l2_planes[0].bytesused);
        s5p_mfc_set_dec_stream_buffer(ctx,
-                               vb2_dma_contig_plane_paddr(temp_vb->b, 0),
+                               vb2_dma_contig_plane_dma_addr(temp_vb->b, 0),
                                0, temp_vb->b->v4l2_planes[0].bytesused);
        spin_unlock_irqrestore(&dev->irqlock, flags);
        dev->curr_ctx = ctx->num;
@@ -1219,7 +1219,7 @@ static void s5p_mfc_run_init_enc(struct s5p_mfc_ctx *ctx)
        s5p_mfc_set_enc_ref_buffer(ctx);
        spin_lock_irqsave(&dev->irqlock, flags);
        dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
-       dst_addr = vb2_dma_contig_plane_paddr(dst_mb->b, 0);
+       dst_addr = vb2_dma_contig_plane_dma_addr(dst_mb->b, 0);
        dst_size = vb2_plane_size(dst_mb->b, 0);
        s5p_mfc_set_enc_stream_buffer(ctx, dst_addr, dst_size);
        spin_unlock_irqrestore(&dev->irqlock, flags);
@@ -1255,7 +1255,7 @@ static int s5p_mfc_run_init_dec_buffers(struct s5p_mfc_ctx *ctx)
        temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
        mfc_debug(2, "Header size: %d\n", temp_vb->b->v4l2_planes[0].bytesused);
        s5p_mfc_set_dec_stream_buffer(ctx,
-                               vb2_dma_contig_plane_paddr(temp_vb->b, 0),
+                               vb2_dma_contig_plane_dma_addr(temp_vb->b, 0),
                                0, temp_vb->b->v4l2_planes[0].bytesused);
        spin_unlock_irqrestore(&dev->irqlock, flags);
        dev->curr_ctx = ctx->num;
index 9c37dee7bc594ac66aa152e5c87e70b988dc7ce2..f2a09779ec8f71c89e7647cc74988f9d4e3bf8da 100644 (file)
@@ -8,7 +8,7 @@
 
 config VIDEO_SAMSUNG_S5P_TV
        bool "Samsung TV driver for S5P platform (experimental)"
-       depends on PLAT_S5P
+       depends on PLAT_S5P && PM_RUNTIME
        depends on EXPERIMENTAL
        default n
        ---help---
index 06d6663f45945d0b8f855a1d60107ea02fdd477d..0279e6e89febaf74db82d92c5ea783ab557ce187 100644 (file)
@@ -210,20 +210,17 @@ static void hdmi_reg_init(struct hdmi_device *hdev)
        /* enable HPD interrupts */
        hdmi_write_mask(hdev, HDMI_INTC_CON, ~0, HDMI_INTC_EN_GLOBAL |
                HDMI_INTC_EN_HPD_PLUG | HDMI_INTC_EN_HPD_UNPLUG);
-       /* choose HDMI mode */
+       /* choose DVI mode */
        hdmi_write_mask(hdev, HDMI_MODE_SEL,
-               HDMI_MODE_HDMI_EN, HDMI_MODE_MASK);
+               HDMI_MODE_DVI_EN, HDMI_MODE_MASK);
+       hdmi_write_mask(hdev, HDMI_CON_2, ~0,
+               HDMI_DVI_PERAMBLE_EN | HDMI_DVI_BAND_EN);
        /* disable bluescreen */
        hdmi_write_mask(hdev, HDMI_CON_0, 0, HDMI_BLUE_SCR_EN);
        /* choose bluescreen (fecal) color */
        hdmi_writeb(hdev, HDMI_BLUE_SCREEN_0, 0x12);
        hdmi_writeb(hdev, HDMI_BLUE_SCREEN_1, 0x34);
        hdmi_writeb(hdev, HDMI_BLUE_SCREEN_2, 0x56);
-       /* enable AVI packet every vsync, fixes purple line problem */
-       hdmi_writeb(hdev, HDMI_AVI_CON, 0x02);
-       /* force YUV444, look to CEA-861-D, table 7 for more detail */
-       hdmi_writeb(hdev, HDMI_AVI_BYTE(0), 2 << 5);
-       hdmi_write_mask(hdev, HDMI_CON_1, 2, 3 << 5);
 }
 
 static void hdmi_timing_apply(struct hdmi_device *hdev,
@@ -443,6 +440,7 @@ static const struct hdmi_preset_conf hdmi_conf_480p = {
                .height = 480,
                .code = V4L2_MBUS_FMT_FIXED, /* means RGB888 */
                .field = V4L2_FIELD_NONE,
+               .colorspace = V4L2_COLORSPACE_SRGB,
        },
 };
 
@@ -475,6 +473,7 @@ static const struct hdmi_preset_conf hdmi_conf_720p60 = {
                .height = 720,
                .code = V4L2_MBUS_FMT_FIXED, /* means RGB888 */
                .field = V4L2_FIELD_NONE,
+               .colorspace = V4L2_COLORSPACE_SRGB,
        },
 };
 
@@ -507,6 +506,7 @@ static const struct hdmi_preset_conf hdmi_conf_1080p50 = {
                .height = 1080,
                .code = V4L2_MBUS_FMT_FIXED, /* means RGB888 */
                .field = V4L2_FIELD_NONE,
+               .colorspace = V4L2_COLORSPACE_SRGB,
        },
 };
 
@@ -539,6 +539,7 @@ static const struct hdmi_preset_conf hdmi_conf_1080p60 = {
                .height = 1080,
                .code = V4L2_MBUS_FMT_FIXED, /* means RGB888 */
                .field = V4L2_FIELD_NONE,
+               .colorspace = V4L2_COLORSPACE_SRGB,
        },
 };
 
index e2242243f63dbf33742cb2fcfc3082c3b54d19fb..51ad59b30358aa7e869a94d6d68df581e2d7b539 100644 (file)
@@ -111,8 +111,6 @@ struct mxr_buffer {
 enum mxr_layer_state {
        /** layers is not shown */
        MXR_LAYER_IDLE = 0,
-       /** state between STREAMON and hardware start */
-       MXR_LAYER_STREAMING_START,
        /** layer is shown */
        MXR_LAYER_STREAMING,
        /** state before STREAMOFF is finished */
index 58f0ba49580f7916f0733ff82a9623c9870a052a..de8270c2b6e7d408569d1c731f9549579153b548 100644 (file)
@@ -86,7 +86,7 @@ static void mxr_graph_buffer_set(struct mxr_layer *layer,
        dma_addr_t addr = 0;
 
        if (buf)
-               addr = vb2_dma_contig_plane_paddr(&buf->vb, 0);
+               addr = vb2_dma_contig_plane_dma_addr(&buf->vb, 0);
        mxr_reg_graph_buffer(layer->mdev, layer->idx, addr);
 }
 
index 38dac672aa1c2471a15efedd2a6ad0b9a84eacb0..4800a3cbb297726a235e4d7cdc1e7fc055b1efce 100644 (file)
@@ -90,7 +90,7 @@ void mxr_reg_reset(struct mxr_device *mdev)
        mxr_vsync_set_update(mdev, MXR_DISABLE);
 
        /* set output in RGB888 mode */
-       mxr_write(mdev, MXR_CFG, MXR_CFG_OUT_YUV444);
+       mxr_write(mdev, MXR_CFG, MXR_CFG_OUT_RGB888);
 
        /* 16 beat burst in DMA */
        mxr_write_mask(mdev, MXR_STATUS, MXR_STATUS_16_BURST,
@@ -376,6 +376,12 @@ void mxr_reg_set_mbus_fmt(struct mxr_device *mdev,
        spin_lock_irqsave(&mdev->reg_slock, flags);
        mxr_vsync_set_update(mdev, MXR_DISABLE);
 
+       /* selecting colorspace accepted by output */
+       if (fmt->colorspace == V4L2_COLORSPACE_JPEG)
+               val |= MXR_CFG_OUT_YUV444;
+       else
+               val |= MXR_CFG_OUT_RGB888;
+
        /* choosing between interlace and progressive mode */
        if (fmt->field == V4L2_FIELD_INTERLACED)
                val |= MXR_CFG_SCAN_INTERLACE;
@@ -394,7 +400,8 @@ void mxr_reg_set_mbus_fmt(struct mxr_device *mdev,
        else
                WARN(1, "unrecognized mbus height %u!\n", fmt->height);
 
-       mxr_write_mask(mdev, MXR_CFG, val, MXR_CFG_SCAN_MASK);
+       mxr_write_mask(mdev, MXR_CFG, val, MXR_CFG_SCAN_MASK |
+               MXR_CFG_OUT_MASK);
 
        val = (fmt->field == V4L2_FIELD_INTERLACED) ? ~0 : 0;
        vp_write_mask(mdev, VP_MODE, val,
index 43ac22f35bc715566dbd2960d35915b046026426..4917e2c2b321ee8a74b7528b732e2807e4ff04cb 100644 (file)
@@ -728,7 +728,7 @@ static const struct v4l2_file_operations mxr_fops = {
 };
 
 static int queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
-       unsigned int *nplanes, unsigned long sizes[],
+       unsigned int *nplanes, unsigned int sizes[],
        void *alloc_ctxs[])
 {
        struct mxr_layer *layer = vb2_get_drv_priv(vq);
@@ -764,19 +764,10 @@ static void buf_queue(struct vb2_buffer *vb)
        struct mxr_layer *layer = vb2_get_drv_priv(vb->vb2_queue);
        struct mxr_device *mdev = layer->mdev;
        unsigned long flags;
-       int must_start = 0;
 
        spin_lock_irqsave(&layer->enq_slock, flags);
-       if (layer->state == MXR_LAYER_STREAMING_START) {
-               layer->state = MXR_LAYER_STREAMING;
-               must_start = 1;
-       }
        list_add_tail(&buffer->list, &layer->enq_list);
        spin_unlock_irqrestore(&layer->enq_slock, flags);
-       if (must_start) {
-               layer->ops.stream_set(layer, MXR_ENABLE);
-               mxr_streamer_get(mdev);
-       }
 
        mxr_dbg(mdev, "queuing buffer\n");
 }
@@ -797,13 +788,19 @@ static void wait_unlock(struct vb2_queue *vq)
        mutex_unlock(&layer->mutex);
 }
 
-static int start_streaming(struct vb2_queue *vq)
+static int start_streaming(struct vb2_queue *vq, unsigned int count)
 {
        struct mxr_layer *layer = vb2_get_drv_priv(vq);
        struct mxr_device *mdev = layer->mdev;
        unsigned long flags;
 
        mxr_dbg(mdev, "%s\n", __func__);
+
+       if (count == 0) {
+               mxr_dbg(mdev, "no output buffers queued\n");
+               return -EINVAL;
+       }
+
        /* block any changes in output configuration */
        mxr_output_get(mdev);
 
@@ -814,9 +811,12 @@ static int start_streaming(struct vb2_queue *vq)
        layer->ops.format_set(layer);
        /* enabling layer in hardware */
        spin_lock_irqsave(&layer->enq_slock, flags);
-       layer->state = MXR_LAYER_STREAMING_START;
+       layer->state = MXR_LAYER_STREAMING;
        spin_unlock_irqrestore(&layer->enq_slock, flags);
 
+       layer->ops.stream_set(layer, MXR_ENABLE);
+       mxr_streamer_get(mdev);
+
        return 0;
 }
 
index 6950ed8ac1a0d209569a27c5e3b291ea6ace48ce..f3bb2e34cb517d11bdb1dd11d716cb18255f0e4b 100644 (file)
@@ -97,9 +97,9 @@ static void mxr_vp_buffer_set(struct mxr_layer *layer,
                mxr_reg_vp_buffer(layer->mdev, luma_addr, chroma_addr);
                return;
        }
-       luma_addr[0] = vb2_dma_contig_plane_paddr(&buf->vb, 0);
+       luma_addr[0] = vb2_dma_contig_plane_dma_addr(&buf->vb, 0);
        if (layer->fmt->num_subframes == 2) {
-               chroma_addr[0] = vb2_dma_contig_plane_paddr(&buf->vb, 1);
+               chroma_addr[0] = vb2_dma_contig_plane_dma_addr(&buf->vb, 1);
        } else {
                /* FIXME: mxr_get_plane_size compute integer division,
                 * which is slow and should not be performed in interrupt */
index ac93ad6f2bc35998640cfb6f67c4dc5b498f97e2..33247d13e4c0c08d93709d73e4664b20c6a2ac26 100644 (file)
 #define HDMI_BLUE_SCR_EN               (1 << 5)
 #define HDMI_EN                                (1 << 0)
 
+/* HDMI_CON_2 */
+#define HDMI_DVI_PERAMBLE_EN           (1 << 5)
+#define HDMI_DVI_BAND_EN               (1 << 1)
+
 /* HDMI_PHY_STATUS */
 #define HDMI_PHY_STATUS_READY          (1 << 0)
 
index 3c8442609c1ad068a4f60fb4854a960f1ec56d27..158abb43d0a40f1e63d4a637a00681800e16f064 100644 (file)
@@ -67,6 +67,7 @@
 /* bits for MXR_CFG */
 #define MXR_CFG_OUT_YUV444             (0 << 8)
 #define MXR_CFG_OUT_RGB888             (1 << 8)
+#define MXR_CFG_OUT_MASK               (1 << 8)
 #define MXR_CFG_DST_SDO                        (0 << 7)
 #define MXR_CFG_DST_HDMI               (1 << 7)
 #define MXR_CFG_DST_MASK               (1 << 7)
index 4dddd6bd635be25a2a4412c4bfa35215267f9b68..8cec67ef48c9214b0f529039e905de235bca219c 100644 (file)
@@ -170,6 +170,7 @@ static int sdo_g_mbus_fmt(struct v4l2_subdev *sd,
        fmt->height = sdev->fmt->height;
        fmt->code = V4L2_MBUS_FMT_FIXED;
        fmt->field = V4L2_FIELD_INTERLACED;
+       fmt->colorspace = V4L2_COLORSPACE_JPEG;
        return 0;
 }
 
index f2ae405c74ac4186b84bda12a7e8f0b5c48b6ec2..5cfdbc78b91848df1305feef404c5677d587e260 100644 (file)
@@ -793,7 +793,6 @@ static int saa711x_s_ctrl(struct v4l2_ctrl *ctrl)
                        saa711x_write(sd, R_0F_CHROMA_GAIN_CNTL, state->gain->val);
                else
                        saa711x_write(sd, R_0F_CHROMA_GAIN_CNTL, state->gain->val | 0x80);
-               v4l2_ctrl_activate(state->gain, !state->agc->val);
                break;
 
        default:
@@ -1345,35 +1344,57 @@ static int saa711x_g_vbi_data(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_dat
 static int saa711x_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
 {
        struct saa711x_state *state = to_state(sd);
-       int reg1e;
+       int reg1f, reg1e;
 
-       *std = V4L2_STD_ALL;
-       if (state->ident != V4L2_IDENT_SAA7115) {
-               int reg1f = saa711x_read(sd, R_1F_STATUS_BYTE_2_VD_DEC);
+       /*
+        * The V4L2 core already initializes std with all supported
+        * Standards. All driver needs to do is to mask it, to remove
+        * standards that don't apply from the mask
+        */
 
-               if (reg1f & 0x20)
-                       *std = V4L2_STD_525_60;
-               else
-                       *std = V4L2_STD_625_50;
+       reg1f = saa711x_read(sd, R_1F_STATUS_BYTE_2_VD_DEC);
+       v4l2_dbg(1, debug, sd, "Status byte 2 (0x1f)=0x%02x\n", reg1f);
 
-               return 0;
-       }
+       /* horizontal/vertical not locked */
+       if (reg1f & 0x40)
+               goto ret;
+
+       if (reg1f & 0x20)
+               *std &= V4L2_STD_525_60;
+       else
+               *std &= V4L2_STD_625_50;
+
+       if (state->ident != V4L2_IDENT_SAA7115)
+               goto ret;
 
        reg1e = saa711x_read(sd, R_1E_STATUS_BYTE_1_VD_DEC);
 
        switch (reg1e & 0x03) {
        case 1:
-               *std = V4L2_STD_NTSC;
+               *std &= V4L2_STD_NTSC;
                break;
        case 2:
-               *std = V4L2_STD_PAL;
+               /*
+                * V4L2_STD_PAL just cover the european PAL standards.
+                * This is wrong, as the device could also be using an
+                * other PAL standard.
+                */
+               *std &= V4L2_STD_PAL   | V4L2_STD_PAL_N  | V4L2_STD_PAL_Nc |
+                       V4L2_STD_PAL_M | V4L2_STD_PAL_60;
                break;
        case 3:
-               *std = V4L2_STD_SECAM;
+               *std &= V4L2_STD_SECAM;
                break;
        default:
+               /* Can't detect anything */
                break;
        }
+
+       v4l2_dbg(1, debug, sd, "Status byte 1 (0x1e)=0x%02x\n", reg1e);
+
+ret:
+       v4l2_dbg(1, debug, sd, "detected std mask = %08Lx\n", *std);
+
        return 0;
 }
 
@@ -1601,7 +1622,6 @@ static int saa711x_probe(struct i2c_client *client,
                        V4L2_CID_CHROMA_AGC, 0, 1, 1, 1);
        state->gain = v4l2_ctrl_new_std(hdl, &saa711x_ctrl_ops,
                        V4L2_CID_CHROMA_GAIN, 0, 127, 1, 40);
-       state->gain->is_volatile = 1;
        sd->ctrl_handler = hdl;
        if (hdl->error) {
                int err = hdl->error;
@@ -1610,8 +1630,7 @@ static int saa711x_probe(struct i2c_client *client,
                kfree(state);
                return err;
        }
-       state->agc->flags |= V4L2_CTRL_FLAG_UPDATE;
-       v4l2_ctrl_cluster(2, &state->agc);
+       v4l2_ctrl_auto_cluster(2, &state->agc, 0, true);
 
        state->input = -1;
        state->output = SAA7115_IPORT_ON;
index 8a5ff4d3cf15c6c5563d2792ccd23e3aff778515..a646ccf51696eddf8073cc4c1082062cfaf29c5d 100644 (file)
@@ -10,7 +10,7 @@ obj-$(CONFIG_VIDEO_SAA7134_ALSA) += saa7134-alsa.o
 
 obj-$(CONFIG_VIDEO_SAA7134_DVB) += saa7134-dvb.o
 
-EXTRA_CFLAGS += -Idrivers/media/video
-EXTRA_CFLAGS += -Idrivers/media/common/tuners
-EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
-EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
+ccflags-y += -Idrivers/media/video
+ccflags-y += -Idrivers/media/common/tuners
+ccflags-y += -Idrivers/media/dvb/dvb-core
+ccflags-y += -Idrivers/media/dvb/frontends
index 6303a8e60eac7fd7d6fad92b2a36f300f246b3f6..ecd5811dc486571a77e907d561d7f264d3e5a2fd 100644 (file)
@@ -4,9 +4,9 @@ saa7164-objs    := saa7164-cards.o saa7164-core.o saa7164-i2c.o saa7164-dvb.o \
 
 obj-$(CONFIG_VIDEO_SAA7164) += saa7164.o
 
-EXTRA_CFLAGS += -Idrivers/media/video
-EXTRA_CFLAGS += -Idrivers/media/common/tuners
-EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
-EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
+ccflags-y += -Idrivers/media/video
+ccflags-y += -Idrivers/media/common/tuners
+ccflags-y += -Idrivers/media/dvb/dvb-core
+ccflags-y += -Idrivers/media/dvb/frontends
 
-EXTRA_CFLAGS += $(extra-cflags-y) $(extra-cflags-m)
+ccflags-y += $(extra-cflags-y) $(extra-cflags-m)
index 69822a4e727502b72f5ccaaa9ced649a27bdda44..971591d6450fccc5a7164adb94cb40e3404fb635 100644 (file)
@@ -203,6 +203,66 @@ struct saa7164_board saa7164_boards[] = {
                        .i2c_reg_len    = REGLEN_8bit,
                } },
        },
+       [SAA7164_BOARD_HAUPPAUGE_HVR2200_4] = {
+               .name           = "Hauppauge WinTV-HVR2200",
+               .porta          = SAA7164_MPEG_DVB,
+               .portb          = SAA7164_MPEG_DVB,
+               .portc          = SAA7164_MPEG_ENCODER,
+               .portd          = SAA7164_MPEG_ENCODER,
+               .porte          = SAA7164_MPEG_VBI,
+               .portf          = SAA7164_MPEG_VBI,
+               .chiprev        = SAA7164_CHIP_REV3,
+               .unit           = {{
+                       .id             = 0x1d,
+                       .type           = SAA7164_UNIT_EEPROM,
+                       .name           = "4K EEPROM",
+                       .i2c_bus_nr     = SAA7164_I2C_BUS_0,
+                       .i2c_bus_addr   = 0xa0 >> 1,
+                       .i2c_reg_len    = REGLEN_8bit,
+               }, {
+                       .id             = 0x04,
+                       .type           = SAA7164_UNIT_TUNER,
+                       .name           = "TDA18271-1",
+                       .i2c_bus_nr     = SAA7164_I2C_BUS_1,
+                       .i2c_bus_addr   = 0xc0 >> 1,
+                       .i2c_reg_len    = REGLEN_8bit,
+               }, {
+                       .id             = 0x05,
+                       .type           = SAA7164_UNIT_ANALOG_DEMODULATOR,
+                       .name           = "TDA8290-1",
+                       .i2c_bus_nr     = SAA7164_I2C_BUS_1,
+                       .i2c_bus_addr   = 0x84 >> 1,
+                       .i2c_reg_len    = REGLEN_8bit,
+               }, {
+                       .id             = 0x1b,
+                       .type           = SAA7164_UNIT_TUNER,
+                       .name           = "TDA18271-2",
+                       .i2c_bus_nr     = SAA7164_I2C_BUS_2,
+                       .i2c_bus_addr   = 0xc0 >> 1,
+                       .i2c_reg_len    = REGLEN_8bit,
+               }, {
+                       .id             = 0x1c,
+                       .type           = SAA7164_UNIT_ANALOG_DEMODULATOR,
+                       .name           = "TDA8290-2",
+                       .i2c_bus_nr     = SAA7164_I2C_BUS_2,
+                       .i2c_bus_addr   = 0x84 >> 1,
+                       .i2c_reg_len    = REGLEN_8bit,
+               }, {
+                       .id             = 0x1e,
+                       .type           = SAA7164_UNIT_DIGITAL_DEMODULATOR,
+                       .name           = "TDA10048-1",
+                       .i2c_bus_nr     = SAA7164_I2C_BUS_1,
+                       .i2c_bus_addr   = 0x10 >> 1,
+                       .i2c_reg_len    = REGLEN_8bit,
+               }, {
+                       .id             = 0x1f,
+                       .type           = SAA7164_UNIT_DIGITAL_DEMODULATOR,
+                       .name           = "TDA10048-2",
+                       .i2c_bus_nr     = SAA7164_I2C_BUS_2,
+                       .i2c_bus_addr   = 0x12 >> 1,
+                       .i2c_reg_len    = REGLEN_8bit,
+               } },
+       },
        [SAA7164_BOARD_HAUPPAUGE_HVR2250] = {
                .name           = "Hauppauge WinTV-HVR2250",
                .porta          = SAA7164_MPEG_DVB,
@@ -387,6 +447,62 @@ struct saa7164_board saa7164_boards[] = {
                        .i2c_reg_len    = REGLEN_8bit,
                } },
        },
+       [SAA7164_BOARD_HAUPPAUGE_HVR2200_5] = {
+               .name           = "Hauppauge WinTV-HVR2200",
+               .porta          = SAA7164_MPEG_DVB,
+               .portb          = SAA7164_MPEG_DVB,
+               .chiprev        = SAA7164_CHIP_REV3,
+               .unit           = {{
+                       .id             = 0x23,
+                       .type           = SAA7164_UNIT_EEPROM,
+                       .name           = "4K EEPROM",
+                       .i2c_bus_nr     = SAA7164_I2C_BUS_0,
+                       .i2c_bus_addr   = 0xa0 >> 1,
+                       .i2c_reg_len    = REGLEN_8bit,
+               }, {
+                       .id             = 0x04,
+                       .type           = SAA7164_UNIT_TUNER,
+                       .name           = "TDA18271-1",
+                       .i2c_bus_nr     = SAA7164_I2C_BUS_1,
+                       .i2c_bus_addr   = 0xc0 >> 1,
+                       .i2c_reg_len    = REGLEN_8bit,
+               }, {
+                       .id             = 0x05,
+                       .type           = SAA7164_UNIT_ANALOG_DEMODULATOR,
+                       .name           = "TDA8290-1",
+                       .i2c_bus_nr     = SAA7164_I2C_BUS_1,
+                       .i2c_bus_addr   = 0x84 >> 1,
+                       .i2c_reg_len    = REGLEN_8bit,
+               }, {
+                       .id             = 0x21,
+                       .type           = SAA7164_UNIT_TUNER,
+                       .name           = "TDA18271-2",
+                       .i2c_bus_nr     = SAA7164_I2C_BUS_2,
+                       .i2c_bus_addr   = 0xc0 >> 1,
+                       .i2c_reg_len    = REGLEN_8bit,
+               }, {
+                       .id             = 0x22,
+                       .type           = SAA7164_UNIT_ANALOG_DEMODULATOR,
+                       .name           = "TDA8290-2",
+                       .i2c_bus_nr     = SAA7164_I2C_BUS_2,
+                       .i2c_bus_addr   = 0x84 >> 1,
+                       .i2c_reg_len    = REGLEN_8bit,
+               }, {
+                       .id             = 0x24,
+                       .type           = SAA7164_UNIT_DIGITAL_DEMODULATOR,
+                       .name           = "TDA10048-1",
+                       .i2c_bus_nr     = SAA7164_I2C_BUS_1,
+                       .i2c_bus_addr   = 0x10 >> 1,
+                       .i2c_reg_len    = REGLEN_8bit,
+               }, {
+                       .id             = 0x25,
+                       .type           = SAA7164_UNIT_DIGITAL_DEMODULATOR,
+                       .name           = "TDA10048-2",
+                       .i2c_bus_nr     = SAA7164_I2C_BUS_2,
+                       .i2c_bus_addr   = 0x12 >> 1,
+                       .i2c_reg_len    = REGLEN_8bit,
+               } },
+       },
 };
 const unsigned int saa7164_bcount = ARRAY_SIZE(saa7164_boards);
 
@@ -426,6 +542,14 @@ struct saa7164_subid saa7164_subids[] = {
                .subvendor = 0x0070,
                .subdevice = 0x8851,
                .card      = SAA7164_BOARD_HAUPPAUGE_HVR2250_2,
+       }, {
+               .subvendor = 0x0070,
+               .subdevice = 0x8940,
+               .card      = SAA7164_BOARD_HAUPPAUGE_HVR2200_4,
+       }, {
+               .subvendor = 0x0070,
+               .subdevice = 0x8953,
+               .card      = SAA7164_BOARD_HAUPPAUGE_HVR2200_5,
        },
 };
 const unsigned int saa7164_idcount = ARRAY_SIZE(saa7164_subids);
@@ -469,6 +593,8 @@ void saa7164_gpio_setup(struct saa7164_dev *dev)
        case SAA7164_BOARD_HAUPPAUGE_HVR2200:
        case SAA7164_BOARD_HAUPPAUGE_HVR2200_2:
        case SAA7164_BOARD_HAUPPAUGE_HVR2200_3:
+       case SAA7164_BOARD_HAUPPAUGE_HVR2200_4:
+       case SAA7164_BOARD_HAUPPAUGE_HVR2200_5:
        case SAA7164_BOARD_HAUPPAUGE_HVR2250:
        case SAA7164_BOARD_HAUPPAUGE_HVR2250_2:
        case SAA7164_BOARD_HAUPPAUGE_HVR2250_3:
@@ -549,6 +675,8 @@ void saa7164_card_setup(struct saa7164_dev *dev)
        case SAA7164_BOARD_HAUPPAUGE_HVR2200:
        case SAA7164_BOARD_HAUPPAUGE_HVR2200_2:
        case SAA7164_BOARD_HAUPPAUGE_HVR2200_3:
+       case SAA7164_BOARD_HAUPPAUGE_HVR2200_4:
+       case SAA7164_BOARD_HAUPPAUGE_HVR2200_5:
        case SAA7164_BOARD_HAUPPAUGE_HVR2250:
        case SAA7164_BOARD_HAUPPAUGE_HVR2250_2:
        case SAA7164_BOARD_HAUPPAUGE_HVR2250_3:
index f65eab63ca871fb634be16d0f17a0457ee1d933c..5c5cc3ebf9bd42386868a155f7254cb151d002a3 100644 (file)
@@ -475,6 +475,8 @@ int saa7164_dvb_register(struct saa7164_port *port)
        case SAA7164_BOARD_HAUPPAUGE_HVR2200:
        case SAA7164_BOARD_HAUPPAUGE_HVR2200_2:
        case SAA7164_BOARD_HAUPPAUGE_HVR2200_3:
+       case SAA7164_BOARD_HAUPPAUGE_HVR2200_4:
+       case SAA7164_BOARD_HAUPPAUGE_HVR2200_5:
                i2c_bus = &dev->i2c_bus[port->nr + 1];
                switch (port->nr) {
                case 0:
index 6678bf1e78168bc0401453de3599e4c5ebc2ad7d..742b34103b5d8fb244fd779949c7b56deda52ec2 100644 (file)
@@ -82,6 +82,8 @@
 #define SAA7164_BOARD_HAUPPAUGE_HVR2200_3      6
 #define SAA7164_BOARD_HAUPPAUGE_HVR2250_2      7
 #define SAA7164_BOARD_HAUPPAUGE_HVR2250_3      8
+#define SAA7164_BOARD_HAUPPAUGE_HVR2200_4      9
+#define SAA7164_BOARD_HAUPPAUGE_HVR2200_5      10
 
 #define SAA7164_MAX_UNITS              8
 #define SAA7164_TS_NUMBER_OF_LINES     312
index e54089802b6b906027b36369984f126d9d8e8830..8615fb81775f6d303f2f14a67a03418e6a34fd50 100644 (file)
@@ -218,7 +218,7 @@ static int sh_mobile_ceu_soft_reset(struct sh_mobile_ceu_dev *pcdev)
  */
 static int sh_mobile_ceu_videobuf_setup(struct vb2_queue *vq,
                        unsigned int *count, unsigned int *num_planes,
-                       unsigned long sizes[], void *alloc_ctxs[])
+                       unsigned int sizes[], void *alloc_ctxs[])
 {
        struct soc_camera_device *icd = container_of(vq, struct soc_camera_device, vb2_vidq);
        struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
@@ -243,7 +243,7 @@ static int sh_mobile_ceu_videobuf_setup(struct vb2_queue *vq,
                        *count = pcdev->video_limit / PAGE_ALIGN(sizes[0]);
        }
 
-       dev_dbg(icd->parent, "count=%d, size=%lu\n", *count, sizes[0]);
+       dev_dbg(icd->parent, "count=%d, size=%u\n", *count, sizes[0]);
 
        return 0;
 }
@@ -312,7 +312,7 @@ static int sh_mobile_ceu_capture(struct sh_mobile_ceu_dev *pcdev)
                bottom2 = CDBCR;
        }
 
-       phys_addr_top = vb2_dma_contig_plane_paddr(pcdev->active, 0);
+       phys_addr_top = vb2_dma_contig_plane_dma_addr(pcdev->active, 0);
 
        ceu_write(pcdev, top1, phys_addr_top);
        if (V4L2_FIELD_NONE != pcdev->field) {
index 8afb0e8a2e0033dea97f466d929fea3a8d53a09c..10aff3f943a88a23c4fd88ceb67837b92684da32 100644 (file)
@@ -714,11 +714,6 @@ static int sr030pc30_base_config(struct v4l2_subdev *sd)
        return ret;
 }
 
-static int sr030pc30_s_stream(struct v4l2_subdev *sd, int enable)
-{
-       return 0;
-}
-
 static int sr030pc30_s_power(struct v4l2_subdev *sd, int on)
 {
        struct i2c_client *client = v4l2_get_subdevdata(sd);
@@ -764,7 +759,6 @@ static const struct v4l2_subdev_core_ops sr030pc30_core_ops = {
 };
 
 static const struct v4l2_subdev_video_ops sr030pc30_video_ops = {
-       .s_stream       = sr030pc30_s_stream,
        .g_mbus_fmt     = sr030pc30_g_fmt,
        .s_mbus_fmt     = sr030pc30_s_fmt,
        .try_mbus_fmt   = sr030pc30_try_fmt,
index d1a2cefbf55bfffc14b4ba3dd33e4c87cccc6823..cbc105f975de24c71d90e2863222bcd9802d8906 100644 (file)
@@ -55,6 +55,8 @@ MODULE_AUTHOR("Jaime Velasco Juan <jsagarribay@gmail.com> and Nicolas VIVIEN");
 MODULE_DESCRIPTION("Syntek DC1125 webcam driver");
 
 
+/* bool for webcam LED management */
+int first_init = 1;
 
 /* Some cameras have audio interfaces, we aren't interested in those */
 static struct usb_device_id stkwebcam_table[] = {
@@ -518,7 +520,7 @@ static int stk_prepare_sio_buffers(struct stk_camera *dev, unsigned n_sbufs)
                        return -ENOMEM;
                for (i = 0; i < n_sbufs; i++) {
                        if (stk_setup_siobuf(dev, i))
-                               return (dev->n_sbufs > 1)? 0 : -ENOMEM;
+                               return (dev->n_sbufs > 1 ? 0 : -ENOMEM);
                        dev->n_sbufs = i+1;
                }
        }
@@ -558,9 +560,14 @@ static int v4l_stk_open(struct file *fp)
        vdev = video_devdata(fp);
        dev = vdev_to_camera(vdev);
 
-       if (dev == NULL || !is_present(dev)) {
+       if (dev == NULL || !is_present(dev))
                return -ENXIO;
-       }
+
+       if (!first_init)
+               stk_camera_write_reg(dev, 0x0, 0x24);
+       else
+               first_init = 0;
+
        fp->private_data = dev;
        usb_autopm_get_interface(dev->interface);
 
@@ -574,10 +581,12 @@ static int v4l_stk_release(struct file *fp)
        if (dev->owner == fp) {
                stk_stop_stream(dev);
                stk_free_buffers(dev);
+               stk_camera_write_reg(dev, 0x0, 0x49); /* turn off the LED */
+               unset_initialised(dev);
                dev->owner = NULL;
        }
 
-       if(is_present(dev))
+       if (is_present(dev))
                usb_autopm_put_interface(dev->interface);
 
        return 0;
@@ -654,7 +663,7 @@ static unsigned int v4l_stk_poll(struct file *fp, poll_table *wait)
                return POLLERR;
 
        if (!list_empty(&dev->sio_full))
-               return (POLLIN | POLLRDNORM);
+               return POLLIN | POLLRDNORM;
 
        return 0;
 }
@@ -891,9 +900,9 @@ static int stk_vidioc_g_fmt_vid_cap(struct file *filp,
        struct stk_camera *dev = priv;
        int i;
 
-       for (i = 0; i < ARRAY_SIZE(stk_sizes)
-                       && stk_sizes[i].m != dev->vsettings.mode;
-               i++);
+       for (i = 0; i < ARRAY_SIZE(stk_sizes) &&
+                       stk_sizes[i].m != dev->vsettings.mode; i++)
+               ;
        if (i == ARRAY_SIZE(stk_sizes)) {
                STK_ERROR("ERROR: mode invalid\n");
                return -EINVAL;
@@ -1305,9 +1314,8 @@ static int stk_camera_probe(struct usb_interface *interface,
        usb_set_intfdata(interface, dev);
 
        err = stk_register_video_device(dev);
-       if (err) {
+       if (err)
                goto error;
-       }
 
        return 0;
 
@@ -1350,6 +1358,7 @@ static int stk_camera_resume(struct usb_interface *intf)
                return 0;
        unset_initialised(dev);
        stk_initialise(dev);
+       stk_camera_write_reg(dev, 0x0, 0x49);
        stk_setup_format(dev);
        if (is_streaming(dev))
                stk_start_stream(dev);
index 81bb7fdd1e3ddc044d65ac93236c44e0a225e6c8..ea09b9af2d30b102a32fbb7b7b425dc2e079de8f 100644 (file)
@@ -2,8 +2,8 @@ poseidon-objs := pd-video.o pd-alsa.o pd-dvb.o pd-radio.o pd-main.o
 
 obj-$(CONFIG_VIDEO_TLG2300) += poseidon.o
 
-EXTRA_CFLAGS += -Idrivers/media/video
-EXTRA_CFLAGS += -Idrivers/media/common/tuners
-EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
-EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
+ccflags-y += -Idrivers/media/video
+ccflags-y += -Idrivers/media/common/tuners
+ccflags-y += -Idrivers/media/dvb/dvb-core
+ccflags-y += -Idrivers/media/dvb/frontends
 
similarity index 97%
rename from drivers/staging/tm6000/tm6000-alsa.c
rename to drivers/media/video/tm6000/tm6000-alsa.c
index bd5fa89af07c32814ea55f28c0075dad7747cdad..7d675c72fd479cffac862f00c6afb9bd85342688 100644 (file)
@@ -80,7 +80,7 @@ static int _tm6000_start_audio_dma(struct snd_tm6000_card *chip)
        dprintk(1, "Starting audio DMA\n");
 
        /* Enables audio */
-       tm6000_set_reg_mask(core, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, 0x40, 0x40);
+       tm6000_set_reg_mask(core, TM6010_REQ07_RCC_ACTIVE_IF, 0x40, 0x40);
 
        tm6000_set_audio_bitrate(core, 48000);
 
@@ -97,7 +97,7 @@ static int _tm6000_stop_audio_dma(struct snd_tm6000_card *chip)
        dprintk(1, "Stopping audio DMA\n");
 
        /* Disables audio */
-       tm6000_set_reg_mask(core, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, 0x00, 0x40);
+       tm6000_set_reg_mask(core, TM6010_REQ07_RCC_ACTIVE_IF, 0x00, 0x40);
 
        return 0;
 }
@@ -304,6 +304,7 @@ static int snd_tm6000_hw_free(struct snd_pcm_substream *substream)
                schedule_work(&core->wq_trigger);
        }
 
+       dsp_buffer_free(substream);
        return 0;
 }
 
@@ -397,7 +398,7 @@ static struct snd_pcm_ops snd_tm6000_pcm_ops = {
 /*
  * Alsa Constructor - Component probe
  */
-int tm6000_audio_init(struct tm6000_core *dev)
+static int tm6000_audio_init(struct tm6000_core *dev)
 {
        struct snd_card         *card;
        struct snd_tm6000_card  *chip;
@@ -490,7 +491,7 @@ static int tm6000_audio_fini(struct tm6000_core *dev)
        return 0;
 }
 
-struct tm6000_ops audio_ops = {
+static struct tm6000_ops audio_ops = {
        .type   = TM6000_AUDIO,
        .name   = "TM6000 Audio Extension",
        .init   = tm6000_audio_init,
similarity index 97%
rename from drivers/staging/tm6000/tm6000-cards.c
rename to drivers/media/video/tm6000/tm6000-cards.c
index 9227db5d8955444f9049bf49dd634e243a9f50f7..ec2578a0fdf7378858ab1995c4c06ad85fa9b188 100644 (file)
@@ -87,7 +87,7 @@ struct tm6000_board {
        char            *ir_codes;
 };
 
-struct tm6000_board tm6000_boards[] = {
+static struct tm6000_board tm6000_boards[] = {
        [TM6000_BOARD_UNKNOWN] = {
                .name         = "Unknown tm6000 video grabber",
                .caps = {
@@ -394,7 +394,7 @@ struct tm6000_board tm6000_boards[] = {
                        .has_zl10353    = 1,
                        .has_eeprom     = 1,
                        .has_remote     = 1,
-                       .has_radio      = 1.
+                       .has_radio      = 1,
                },
                .gpio = {
                        .tuner_reset    = TM6010_GPIO_0,
@@ -468,6 +468,7 @@ struct tm6000_board tm6000_boards[] = {
                        .has_zl10353  = 1,
                        .has_eeprom   = 1,
                        .has_remote   = 1,
+                       .has_radio    = 1,
                },
                .gpio = {
                        .tuner_reset    = TM6010_GPIO_2,
@@ -493,6 +494,10 @@ struct tm6000_board tm6000_boards[] = {
                        .amux   = TM6000_AMUX_ADC2,
                        },
                },
+               .rinput = {
+                       .type = TM6000_INPUT_RADIO,
+                       .amux = TM6000_AMUX_SIF1,
+               },
        },
        [TM5600_BOARD_TERRATEC_GRABSTER] = {
                .name         = "Terratec Grabster AV 150/250 MX",
@@ -611,7 +616,7 @@ struct tm6000_board tm6000_boards[] = {
 };
 
 /* table of devices that work with this driver */
-struct usb_device_id tm6000_id_table[] = {
+static struct usb_device_id tm6000_id_table[] = {
        { USB_DEVICE(0x6000, 0x0001), .driver_info = TM5600_BOARD_GENERIC },
        { USB_DEVICE(0x6000, 0x0002), .driver_info = TM6010_BOARD_GENERIC },
        { USB_DEVICE(0x06e1, 0xf332), .driver_info = TM6000_BOARD_ADSTECH_DUAL_TV },
@@ -632,7 +637,7 @@ struct usb_device_id tm6000_id_table[] = {
        { USB_DEVICE(0x13d3, 0x3264), .driver_info = TM6010_BOARD_TWINHAN_TU501 },
        { USB_DEVICE(0x6000, 0xdec2), .driver_info = TM6010_BOARD_BEHOLD_WANDER_LITE },
        { USB_DEVICE(0x6000, 0xdec3), .driver_info = TM6010_BOARD_BEHOLD_VOYAGER_LITE },
-       { },
+       { }
 };
 
 /* Control power led for show some activity */
@@ -780,6 +785,11 @@ int tm6000_tuner_callback(void *ptr, int component, int command, int arg)
                        rc = tm6000_i2c_reset(dev, 100);
                        break;
                }
+               break;
+       case XC2028_I2C_FLUSH:
+               tm6000_set_reg(dev, REQ_50_SET_START, 0, 0);
+               tm6000_set_reg(dev, REQ_51_SET_STOP, 0, 0);
+               break;
        }
        return rc;
 }
@@ -787,8 +797,6 @@ EXPORT_SYMBOL_GPL(tm6000_tuner_callback);
 
 int tm6000_cards_setup(struct tm6000_core *dev)
 {
-       int i, rc;
-
        /*
         * Board-specific initialization sequence. Handles all GPIO
         * initialization sequences that are board-specific.
@@ -860,6 +868,9 @@ int tm6000_cards_setup(struct tm6000_core *dev)
         */
 
        if (dev->gpio.tuner_reset) {
+               int rc;
+               int i;
+
                for (i = 0; i < 2; i++) {
                        rc = tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
                                                dev->gpio.tuner_reset, 0x00);
@@ -988,6 +999,16 @@ static int fill_board_specific_data(struct tm6000_core *dev)
        dev->vinput[2] = tm6000_boards[dev->model].vinput[2];
        dev->rinput = tm6000_boards[dev->model].rinput;
 
+       /* setup per-model quirks */
+       switch (dev->model) {
+       case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
+               dev->quirks |= TM6000_QUIRK_NO_USB_DELAY;
+               break;
+
+       default:
+               break;
+       }
+
        /* initialize hardware */
        rc = tm6000_init(dev);
        if (rc < 0)
@@ -1162,13 +1183,14 @@ static int tm6000_usb_probe(struct usb_interface *interface,
                return -ENOMEM;
        }
        spin_lock_init(&dev->slock);
+       mutex_init(&dev->usb_lock);
 
        /* Increment usage count */
-       tm6000_devused |= 1<<nr;
+       set_bit(nr, &tm6000_devused);
        snprintf(dev->name, 29, "tm6000 #%d", nr);
 
        dev->model = id->driver_info;
-       if ((card[nr] >= 0) && (card[nr] < ARRAY_SIZE(tm6000_boards)))
+       if (card[nr] < ARRAY_SIZE(tm6000_boards))
                dev->model = card[nr];
 
        dev->udev = usbdev;
@@ -1189,8 +1211,6 @@ static int tm6000_usb_probe(struct usb_interface *interface,
                speed = "unknown";
        }
 
-
-
        /* Get endpoints */
        for (i = 0; i < interface->num_altsetting; i++) {
                int ep;
@@ -1274,7 +1294,6 @@ static int tm6000_usb_probe(struct usb_interface *interface,
        printk(KERN_INFO "tm6000: Found %s\n", tm6000_boards[dev->model].name);
 
        rc = tm6000_init_dev(dev);
-
        if (rc < 0)
                goto err;
 
@@ -1283,7 +1302,7 @@ static int tm6000_usb_probe(struct usb_interface *interface,
 err:
        printk(KERN_ERR "tm6000: Error %d while registering\n", rc);
 
-       tm6000_devused &= ~(1<<nr);
+       clear_bit(nr, &tm6000_devused);
        usb_put_dev(usbdev);
 
        kfree(dev);
@@ -1341,6 +1360,7 @@ static void tm6000_usb_disconnect(struct usb_interface *interface)
        tm6000_close_extension(dev);
        tm6000_remove_from_devlist(dev);
 
+       clear_bit(dev->devno, &tm6000_devused);
        kfree(dev);
 }
 
similarity index 91%
rename from drivers/staging/tm6000/tm6000-core.c
rename to drivers/media/video/tm6000/tm6000-core.c
index d7eb2e23cdbdc38014f81f9200636ff1bd609343..9783616a0da2791b83680132168d1522baf8b9af 100644 (file)
@@ -39,10 +39,11 @@ int tm6000_read_write_usb(struct tm6000_core *dev, u8 req_type, u8 req,
        unsigned int pipe;
        u8           *data = NULL;
 
+       mutex_lock(&dev->usb_lock);
+
        if (len)
                data = kzalloc(len, GFP_KERNEL);
 
-
        if (req_type & USB_DIR_IN)
                pipe = usb_rcvctrlpipe(dev->udev, 0);
        else {
@@ -51,18 +52,18 @@ int tm6000_read_write_usb(struct tm6000_core *dev, u8 req_type, u8 req,
        }
 
        if (tm6000_debug & V4L2_DEBUG_I2C) {
-               printk("(dev %p, pipe %08x): ", dev->udev, pipe);
+               printk(KERN_DEBUG "(dev %p, pipe %08x): ", dev->udev, pipe);
 
-               printk("%s: %02x %02x %02x %02x %02x %02x %02x %02x ",
+               printk(KERN_CONT "%s: %02x %02x %02x %02x %02x %02x %02x %02x ",
                        (req_type & USB_DIR_IN) ? " IN" : "OUT",
                        req_type, req, value&0xff, value>>8, index&0xff,
                        index>>8, len&0xff, len>>8);
 
                if (!(req_type & USB_DIR_IN)) {
-                       printk(">>> ");
+                       printk(KERN_CONT ">>> ");
                        for (i = 0; i < len; i++)
-                               printk(" %02x", buf[i]);
-               printk("\n");
+                               printk(KERN_CONT " %02x", buf[i]);
+                       printk(KERN_CONT "\n");
                }
        }
 
@@ -75,21 +76,21 @@ int tm6000_read_write_usb(struct tm6000_core *dev, u8 req_type, u8 req,
        if (tm6000_debug & V4L2_DEBUG_I2C) {
                if (ret < 0) {
                        if (req_type &  USB_DIR_IN)
-                               printk("<<< (len=%d)\n", len);
+                               printk(KERN_DEBUG "<<< (len=%d)\n", len);
 
-                       printk("%s: Error #%d\n", __FUNCTION__, ret);
+                       printk(KERN_CONT "%s: Error #%d\n", __func__, ret);
                } else if (req_type &  USB_DIR_IN) {
-                       printk("<<< ");
+                       printk(KERN_CONT "<<< ");
                        for (i = 0; i < len; i++)
-                               printk(" %02x", buf[i]);
-                       printk("\n");
+                               printk(KERN_CONT " %02x", buf[i]);
+                       printk(KERN_CONT "\n");
                }
        }
 
        kfree(data);
-
        msleep(5);
 
+       mutex_unlock(&dev->usb_lock);
        return ret;
 }
 
@@ -188,11 +189,11 @@ void tm6000_set_fourcc_format(struct tm6000_core *dev)
        if (dev->dev_type == TM6010) {
                int val;
 
-               val = tm6000_get_reg(dev, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, 0) & 0xfc;
+               val = tm6000_get_reg(dev, TM6010_REQ07_RCC_ACTIVE_IF, 0) & 0xfc;
                if (dev->fourcc == V4L2_PIX_FMT_UYVY)
-                       tm6000_set_reg(dev, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, val);
+                       tm6000_set_reg(dev, TM6010_REQ07_RCC_ACTIVE_IF, val);
                else
-                       tm6000_set_reg(dev, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, val | 1);
+                       tm6000_set_reg(dev, TM6010_REQ07_RCC_ACTIVE_IF, val | 1);
        } else {
                if (dev->fourcc == V4L2_PIX_FMT_UYVY)
                        tm6000_set_reg(dev, TM6010_REQ07_RC1_TRESHOLD, 0xd0);
@@ -268,9 +269,14 @@ int tm6000_init_analog_mode(struct tm6000_core *dev)
        struct v4l2_frequency f;
 
        if (dev->dev_type == TM6010) {
+               u8 active = TM6010_REQ07_RCC_ACTIVE_IF_AUDIO_ENABLE;
+
+               if (!dev->radio)
+                       active |= TM6010_REQ07_RCC_ACTIVE_IF_VIDEO_ENABLE;
+
                /* Enable video and audio */
-               tm6000_set_reg_mask(dev, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF,
-                                                       0x60, 0x60);
+               tm6000_set_reg_mask(dev, TM6010_REQ07_RCC_ACTIVE_IF,
+                                                       active, 0x60);
                /* Disable TS input */
                tm6000_set_reg_mask(dev, TM6010_REQ07_RC0_ACTIVE_VIDEO_SOURCE,
                                                        0x00, 0x40);
@@ -308,7 +314,7 @@ int tm6000_init_analog_mode(struct tm6000_core *dev)
         * FIXME: This is a hack! xc3028 "sleeps" when no channel is detected
         * for more than a few seconds. Not sure why, as this behavior does
         * not happen on other devices with xc3028. So, I suspect that it
-        * is yet another bug at tm6000. After start sleeping, decoding 
+        * is yet another bug at tm6000. After start sleeping, decoding
         * doesn't start automatically. Instead, it requires some
         * I2C commands to wake it up. As we want to have image at the
         * beginning, we needed to add this hack. The better would be to
@@ -335,7 +341,7 @@ int tm6000_init_digital_mode(struct tm6000_core *dev)
 {
        if (dev->dev_type == TM6010) {
                /* Disable video and audio */
-               tm6000_set_reg_mask(dev, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF,
+               tm6000_set_reg_mask(dev, TM6010_REQ07_RCC_ACTIVE_IF,
                                0x00, 0x60);
                /* Enable TS input */
                tm6000_set_reg_mask(dev, TM6010_REQ07_RC0_ACTIVE_VIDEO_SOURCE,
@@ -390,7 +396,7 @@ struct reg_init {
 };
 
 /* The meaning of those initializations are unknown */
-struct reg_init tm6000_init_tab[] = {
+static struct reg_init tm6000_init_tab[] = {
        /* REG  VALUE */
        { TM6000_REQ07_RDF_PWDOWN_ACLK, 0x1f },
        { TM6010_REQ07_RFF_SOFT_RESET, 0x08 },
@@ -458,12 +464,12 @@ struct reg_init tm6000_init_tab[] = {
        { TM6010_REQ05_R18_IMASK7, 0x00 },
 };
 
-struct reg_init tm6010_init_tab[] = {
+static struct reg_init tm6010_init_tab[] = {
        { TM6010_REQ07_RC0_ACTIVE_VIDEO_SOURCE, 0x00 },
        { TM6010_REQ07_RC4_HSTART0, 0xa0 },
        { TM6010_REQ07_RC6_HEND0, 0x40 },
        { TM6010_REQ07_RCA_VEND0, 0x31 },
-       { TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, 0xe1 },
+       { TM6010_REQ07_RCC_ACTIVE_IF, 0xe1 },
        { TM6010_REQ07_RE0_DVIDEO_SOURCE, 0x03 },
        { TM6010_REQ07_RFE_POWER_DOWN, 0x7f },
 
@@ -593,6 +599,56 @@ int tm6000_init(struct tm6000_core *dev)
        return rc;
 }
 
+int tm6000_reset(struct tm6000_core *dev)
+{
+       int pipe;
+       int err;
+
+       msleep(500);
+
+       err = usb_set_interface(dev->udev, dev->isoc_in.bInterfaceNumber, 0);
+       if (err < 0) {
+               tm6000_err("failed to select interface %d, alt. setting 0\n",
+                               dev->isoc_in.bInterfaceNumber);
+               return err;
+       }
+
+       err = usb_reset_configuration(dev->udev);
+       if (err < 0) {
+               tm6000_err("failed to reset configuration\n");
+               return err;
+       }
+
+       if ((dev->quirks & TM6000_QUIRK_NO_USB_DELAY) == 0)
+               msleep(5);
+
+       /*
+        * Not all devices have int_in defined
+        */
+       if (!dev->int_in.endp)
+               return 0;
+
+       err = usb_set_interface(dev->udev, dev->isoc_in.bInterfaceNumber, 2);
+       if (err < 0) {
+               tm6000_err("failed to select interface %d, alt. setting 2\n",
+                               dev->isoc_in.bInterfaceNumber);
+               return err;
+       }
+
+       msleep(5);
+
+       pipe = usb_rcvintpipe(dev->udev,
+                       dev->int_in.endp->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
+
+       err = usb_clear_halt(dev->udev, pipe);
+       if (err < 0) {
+               tm6000_err("usb_clear_halt failed: %d\n", err);
+               return err;
+       }
+
+       return 0;
+}
+
 int tm6000_set_audio_bitrate(struct tm6000_core *dev, int bitrate)
 {
        int val = 0;
@@ -687,7 +743,7 @@ int tm6000_set_audio_rinput(struct tm6000_core *dev)
        return 0;
 }
 
-void tm6010_set_mute_sif(struct tm6000_core *dev, u8 mute)
+static void tm6010_set_mute_sif(struct tm6000_core *dev, u8 mute)
 {
        u8 mute_reg = 0;
 
@@ -697,7 +753,7 @@ void tm6010_set_mute_sif(struct tm6000_core *dev, u8 mute)
        tm6000_set_reg_mask(dev, TM6010_REQ08_R0A_A_I2S_MOD, mute_reg, 0x08);
 }
 
-void tm6010_set_mute_adc(struct tm6000_core *dev, u8 mute)
+static void tm6010_set_mute_adc(struct tm6000_core *dev, u8 mute)
 {
        u8 mute_reg = 0;
 
@@ -749,7 +805,7 @@ int tm6000_tvaudio_set_mute(struct tm6000_core *dev, u8 mute)
        return 0;
 }
 
-void tm6010_set_volume_sif(struct tm6000_core *dev, int vol)
+static void tm6010_set_volume_sif(struct tm6000_core *dev, int vol)
 {
        u8 vol_reg;
 
@@ -762,7 +818,7 @@ void tm6010_set_volume_sif(struct tm6000_core *dev, int vol)
        tm6000_set_reg(dev, TM6010_REQ08_R08_A_RIGHT_VOL, vol_reg);
 }
 
-void tm6010_set_volume_adc(struct tm6000_core *dev, int vol)
+static void tm6010_set_volume_adc(struct tm6000_core *dev, int vol)
 {
        u8 vol_reg;
 
similarity index 95%
rename from drivers/staging/tm6000/tm6000-dvb.c
rename to drivers/media/video/tm6000/tm6000-dvb.c
index 0e0dfce05821c1e5f07a3b66269ce6d39047d77a..5e6c129a4bebd2564f18779be0051573fa9b9242 100644 (file)
@@ -105,7 +105,7 @@ static void tm6000_urb_received(struct urb *urb)
        }
 }
 
-int tm6000_start_stream(struct tm6000_core *dev)
+static int tm6000_start_stream(struct tm6000_core *dev)
 {
        int ret;
        unsigned int pipe, size;
@@ -166,7 +166,7 @@ int tm6000_start_stream(struct tm6000_core *dev)
        return 0;
 }
 
-void tm6000_stop_stream(struct tm6000_core *dev)
+static void tm6000_stop_stream(struct tm6000_core *dev)
 {
        struct tm6000_dvb *dvb = dev->dvb;
 
@@ -180,7 +180,7 @@ void tm6000_stop_stream(struct tm6000_core *dev)
        }
 }
 
-int tm6000_start_feed(struct dvb_demux_feed *feed)
+static int tm6000_start_feed(struct dvb_demux_feed *feed)
 {
        struct dvb_demux *demux = feed->demux;
        struct tm6000_core *dev = demux->priv;
@@ -199,7 +199,7 @@ int tm6000_start_feed(struct dvb_demux_feed *feed)
        return 0;
 }
 
-int tm6000_stop_feed(struct dvb_demux_feed *feed)
+static int tm6000_stop_feed(struct dvb_demux_feed *feed)
 {
        struct dvb_demux *demux = feed->demux;
        struct tm6000_core *dev = demux->priv;
@@ -222,7 +222,7 @@ int tm6000_stop_feed(struct dvb_demux_feed *feed)
        return 0;
 }
 
-int tm6000_dvb_attach_frontend(struct tm6000_core *dev)
+static int tm6000_dvb_attach_frontend(struct tm6000_core *dev)
 {
        struct tm6000_dvb *dvb = dev->dvb;
 
@@ -247,7 +247,7 @@ int tm6000_dvb_attach_frontend(struct tm6000_core *dev)
 
 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 
-int register_dvb(struct tm6000_core *dev)
+static int register_dvb(struct tm6000_core *dev)
 {
        int ret = -1;
        struct tm6000_dvb *dvb = dev->dvb;
@@ -330,7 +330,7 @@ int register_dvb(struct tm6000_core *dev)
        dvb->demux.write_to_decoder = NULL;
        ret = dvb_dmx_init(&dvb->demux);
        if (ret < 0) {
-               printk("tm6000: dvb_dmx_init failed (errno = %d)\n", ret);
+               printk(KERN_ERR "tm6000: dvb_dmx_init failed (errno = %d)\n", ret);
                goto frontend_err;
        }
 
@@ -340,7 +340,7 @@ int register_dvb(struct tm6000_core *dev)
 
        ret =  dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
        if (ret < 0) {
-               printk("tm6000: dvb_dmxdev_init failed (errno = %d)\n", ret);
+               printk(KERN_ERR "tm6000: dvb_dmxdev_init failed (errno = %d)\n", ret);
                goto dvb_dmx_err;
        }
 
@@ -359,7 +359,7 @@ err:
        return ret;
 }
 
-void unregister_dvb(struct tm6000_core *dev)
+static void unregister_dvb(struct tm6000_core *dev)
 {
        struct tm6000_dvb *dvb = dev->dvb;
 
similarity index 95%
rename from drivers/staging/tm6000/tm6000-i2c.c
rename to drivers/media/video/tm6000/tm6000-i2c.c
index 5a651ea5f60afbabe5df852d720e0b9750332eec..0290bbf00c3e68c0541e87803d98963b721e8a41 100644 (file)
@@ -189,7 +189,7 @@ static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap,
                        /* 1 or 2 byte write followed by a read */
                        if (i2c_debug >= 2)
                                for (byte = 0; byte < msgs[i].len; byte++)
-                                       printk(" %02x", msgs[i].buf[byte]);
+                                       printk(KERN_CONT " %02x", msgs[i].buf[byte]);
                        i2c_dprintk(2, "; joined to read %s len=%d:",
                                    i == num - 2 ? "stop" : "nonstop",
                                    msgs[i + 1].len);
@@ -211,22 +211,17 @@ static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap,
                        }
                        if (i2c_debug >= 2)
                                for (byte = 0; byte < msgs[i].len; byte++)
-                                       printk(" %02x", msgs[i].buf[byte]);
+                                       printk(KERN_CONT " %02x", msgs[i].buf[byte]);
                } else {
                        /* write bytes */
                        if (i2c_debug >= 2)
                                for (byte = 0; byte < msgs[i].len; byte++)
-                                       printk(" %02x", msgs[i].buf[byte]);
+                                       printk(KERN_CONT " %02x", msgs[i].buf[byte]);
                        rc = tm6000_i2c_send_regs(dev, addr, msgs[i].buf[0],
                                msgs[i].buf + 1, msgs[i].len - 1);
-
-                       if (addr == dev->tuner_addr  << 1) {
-                               tm6000_set_reg(dev, REQ_50_SET_START, 0, 0);
-                               tm6000_set_reg(dev, REQ_51_SET_STOP, 0, 0);
-                       }
                }
                if (i2c_debug >= 2)
-                       printk("\n");
+                       printk(KERN_CONT "\n");
                if (rc < 0)
                        goto err;
        }
@@ -264,7 +259,7 @@ static int tm6000_i2c_eeprom(struct tm6000_core *dev)
                p++;
                if (0 == (i % 16))
                        printk(KERN_INFO "%s: i2c eeprom %02x:", dev->name, i);
-               printk(" %02x", dev->eedata[i]);
+               printk(KERN_CONT " %02x", dev->eedata[i]);
                if ((dev->eedata[i] >= ' ') && (dev->eedata[i] <= 'z'))
                        bytes[i%16] = dev->eedata[i];
                else
@@ -274,14 +269,14 @@ static int tm6000_i2c_eeprom(struct tm6000_core *dev)
 
                if (0 == (i % 16)) {
                        bytes[16] = '\0';
-                       printk("  %s\n", bytes);
+                       printk(KERN_CONT "  %s\n", bytes);
                }
        }
        if (0 != (i%16)) {
                bytes[i%16] = '\0';
                for (i %= 16; i < 16; i++)
-                       printk("   ");
-               printk("  %s\n", bytes);
+                       printk(KERN_CONT "   ");
+               printk(KERN_CONT "  %s\n", bytes);
        }
 
        return 0;
similarity index 99%
rename from drivers/staging/tm6000/tm6000-input.c
rename to drivers/media/video/tm6000/tm6000-input.c
index 70a2c5f557c12e98c5c3af9d25edf0ad6c1adc2a..405d12729d057c0d6eebce12d5614f266c3211a8 100644 (file)
@@ -284,7 +284,7 @@ static void tm6000_ir_stop(struct rc_dev *rc)
        cancel_delayed_work_sync(&ir->work);
 }
 
-int tm6000_ir_change_protocol(struct rc_dev *rc, u64 rc_type)
+static int tm6000_ir_change_protocol(struct rc_dev *rc, u64 rc_type)
 {
        struct tm6000_IR *ir = rc->priv;
 
similarity index 99%
rename from drivers/staging/tm6000/tm6000-regs.h
rename to drivers/media/video/tm6000/tm6000-regs.h
index 5375a834737401a4abd61e20f426a0ff6d9d6007..7f491b6de9337a22d7bfda621203218712176ac3 100644 (file)
@@ -90,7 +90,7 @@
  */
 
 enum {
-       TM6000_URB_MSG_VIDEO=1,
+       TM6000_URB_MSG_VIDEO = 1,
        TM6000_URB_MSG_AUDIO,
        TM6000_URB_MSG_VBI,
        TM6000_URB_MSG_PTS,
@@ -270,7 +270,9 @@ enum {
 #define TM6010_REQ07_RCA_VEND0                         0x07, 0xca
 #define TM6010_REQ07_RCB_DELAY                         0x07, 0xcb
 /* ONLY for TM6010 */
-#define TM6010_REQ07_RCC_ACTIVE_VIDEO_IF               0x07, 0xcc
+#define TM6010_REQ07_RCC_ACTIVE_IF                     0x07, 0xcc
+#define TM6010_REQ07_RCC_ACTIVE_IF_VIDEO_ENABLE (1 << 5)
+#define TM6010_REQ07_RCC_ACTIVE_IF_AUDIO_ENABLE (1 << 6)
 #define TM6010_REQ07_RD0_USB_PERIPHERY_CONTROL         0x07, 0xd0
 #define TM6010_REQ07_RD1_ADDR_FOR_REQ1                 0x07, 0xd1
 #define TM6010_REQ07_RD2_ADDR_FOR_REQ2                 0x07, 0xd2
diff --git a/drivers/media/video/tm6000/tm6000-stds.c b/drivers/media/video/tm6000/tm6000-stds.c
new file mode 100644 (file)
index 0000000..9a4145d
--- /dev/null
@@ -0,0 +1,659 @@
+/*
+ *  tm6000-stds.c - driver for TM5600/TM6000/TM6010 USB video capture devices
+ *
+ *  Copyright (C) 2007 Mauro Carvalho Chehab <mchehab@redhat.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation version 2
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include "tm6000.h"
+#include "tm6000-regs.h"
+
+static unsigned int tm6010_a_mode;
+module_param(tm6010_a_mode, int, 0644);
+MODULE_PARM_DESC(tm6010_a_mode, "set tm6010 sif audio mode");
+
+struct tm6000_reg_settings {
+       unsigned char req;
+       unsigned char reg;
+       unsigned char value;
+};
+
+
+struct tm6000_std_settings {
+       v4l2_std_id id;
+       struct tm6000_reg_settings *common;
+};
+
+static struct tm6000_reg_settings composite_pal_m[] = {
+       { TM6010_REQ07_R3F_RESET, 0x01 },
+       { TM6010_REQ07_R00_VIDEO_CONTROL0, 0x04 },
+       { TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e },
+       { TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f },
+       { TM6010_REQ07_R03_YC_SEP_CONTROL, 0x00 },
+       { TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31 },
+       { TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e },
+       { TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x83 },
+       { TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x0a },
+       { TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0xe0 },
+       { TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c },
+       { TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc },
+       { TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc },
+       { TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd },
+       { TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x88 },
+       { TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x20 },
+       { TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0x61 },
+       { TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x0c },
+       { TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c },
+       { TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x52 },
+       { TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6f },
+       { TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdc },
+       { TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07 },
+       { TM6010_REQ07_R3F_RESET, 0x00 },
+       { 0, 0, 0 }
+};
+
+static struct tm6000_reg_settings composite_pal_nc[] = {
+       { TM6010_REQ07_R3F_RESET, 0x01 },
+       { TM6010_REQ07_R00_VIDEO_CONTROL0, 0x36 },
+       { TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e },
+       { TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f },
+       { TM6010_REQ07_R03_YC_SEP_CONTROL, 0x02 },
+       { TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31 },
+       { TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e },
+       { TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x91 },
+       { TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x1f },
+       { TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0x0c },
+       { TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c },
+       { TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc },
+       { TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc },
+       { TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd },
+       { TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x8c },
+       { TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x2c },
+       { TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0xc1 },
+       { TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x0c },
+       { TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c },
+       { TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x52 },
+       { TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6f },
+       { TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdc },
+       { TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07 },
+       { TM6010_REQ07_R3F_RESET, 0x00 },
+       { 0, 0, 0 }
+};
+
+static struct tm6000_reg_settings composite_pal[] = {
+       { TM6010_REQ07_R3F_RESET, 0x01 },
+       { TM6010_REQ07_R00_VIDEO_CONTROL0, 0x32 },
+       { TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e },
+       { TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f },
+       { TM6010_REQ07_R03_YC_SEP_CONTROL, 0x02 },
+       { TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31 },
+       { TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x25 },
+       { TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0xd5 },
+       { TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x63 },
+       { TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0x50 },
+       { TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c },
+       { TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc },
+       { TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc },
+       { TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd },
+       { TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x8c },
+       { TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x2c },
+       { TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0xc1 },
+       { TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x0c },
+       { TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c },
+       { TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x52 },
+       { TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6f },
+       { TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdc },
+       { TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07 },
+       { TM6010_REQ07_R3F_RESET, 0x00 },
+       { 0, 0, 0 }
+};
+
+static struct tm6000_reg_settings composite_secam[] = {
+       { TM6010_REQ07_R3F_RESET, 0x01 },
+       { TM6010_REQ07_R00_VIDEO_CONTROL0, 0x38 },
+       { TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e },
+       { TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f },
+       { TM6010_REQ07_R03_YC_SEP_CONTROL, 0x02 },
+       { TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31 },
+       { TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x24 },
+       { TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x92 },
+       { TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xe8 },
+       { TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0xed },
+       { TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c },
+       { TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc },
+       { TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc },
+       { TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd },
+       { TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x8c },
+       { TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x2c },
+       { TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0xc1 },
+       { TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x2c },
+       { TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x18 },
+       { TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x42 },
+       { TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0xff },
+       { TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07 },
+       { TM6010_REQ07_R3F_RESET, 0x00 },
+       { 0, 0, 0 }
+};
+
+static struct tm6000_reg_settings composite_ntsc[] = {
+       { TM6010_REQ07_R3F_RESET, 0x01 },
+       { TM6010_REQ07_R00_VIDEO_CONTROL0, 0x00 },
+       { TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0f },
+       { TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f },
+       { TM6010_REQ07_R03_YC_SEP_CONTROL, 0x00 },
+       { TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31 },
+       { TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e },
+       { TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x8b },
+       { TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xa2 },
+       { TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0xe9 },
+       { TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c },
+       { TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc },
+       { TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc },
+       { TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd },
+       { TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x88 },
+       { TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x22 },
+       { TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0x61 },
+       { TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x1c },
+       { TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c },
+       { TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x42 },
+       { TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6f },
+       { TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdd },
+       { TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07 },
+       { TM6010_REQ07_R3F_RESET, 0x00 },
+       { 0, 0, 0 }
+};
+
+static struct tm6000_std_settings composite_stds[] = {
+       { .id = V4L2_STD_PAL_M, .common = composite_pal_m, },
+       { .id = V4L2_STD_PAL_Nc, .common = composite_pal_nc, },
+       { .id = V4L2_STD_PAL, .common = composite_pal, },
+       { .id = V4L2_STD_SECAM, .common = composite_secam, },
+       { .id = V4L2_STD_NTSC, .common = composite_ntsc, },
+};
+
+static struct tm6000_reg_settings svideo_pal_m[] = {
+       { TM6010_REQ07_R3F_RESET, 0x01 },
+       { TM6010_REQ07_R00_VIDEO_CONTROL0, 0x05 },
+       { TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e },
+       { TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f },
+       { TM6010_REQ07_R03_YC_SEP_CONTROL, 0x04 },
+       { TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31 },
+       { TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e },
+       { TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x83 },
+       { TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x0a },
+       { TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0xe0 },
+       { TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c },
+       { TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc },
+       { TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc },
+       { TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd },
+       { TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x88 },
+       { TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x22 },
+       { TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0x61 },
+       { TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x0c },
+       { TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c },
+       { TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x52 },
+       { TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6f },
+       { TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdc },
+       { TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07 },
+       { TM6010_REQ07_R3F_RESET, 0x00 },
+       { 0, 0, 0 }
+};
+
+static struct tm6000_reg_settings svideo_pal_nc[] = {
+       { TM6010_REQ07_R3F_RESET, 0x01 },
+       { TM6010_REQ07_R00_VIDEO_CONTROL0, 0x37 },
+       { TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e },
+       { TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f },
+       { TM6010_REQ07_R03_YC_SEP_CONTROL, 0x04 },
+       { TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31 },
+       { TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e },
+       { TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x91 },
+       { TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x1f },
+       { TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0x0c },
+       { TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c },
+       { TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc },
+       { TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc },
+       { TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd },
+       { TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x88 },
+       { TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x22 },
+       { TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0xc1 },
+       { TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x0c },
+       { TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c },
+       { TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x52 },
+       { TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6f },
+       { TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdc },
+       { TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07 },
+       { TM6010_REQ07_R3F_RESET, 0x00 },
+       { 0, 0, 0 }
+};
+
+static struct tm6000_reg_settings svideo_pal[] = {
+       { TM6010_REQ07_R3F_RESET, 0x01 },
+       { TM6010_REQ07_R00_VIDEO_CONTROL0, 0x33 },
+       { TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e },
+       { TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f },
+       { TM6010_REQ07_R03_YC_SEP_CONTROL, 0x04 },
+       { TM6010_REQ07_R07_OUTPUT_CONTROL, 0x30 },
+       { TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x25 },
+       { TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0xd5 },
+       { TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x63 },
+       { TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0x50 },
+       { TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c },
+       { TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc },
+       { TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc },
+       { TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd },
+       { TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x8c },
+       { TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x2a },
+       { TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0xc1 },
+       { TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x0c },
+       { TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c },
+       { TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x52 },
+       { TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6f },
+       { TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdc },
+       { TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07 },
+       { TM6010_REQ07_R3F_RESET, 0x00 },
+       { 0, 0, 0 }
+};
+
+static struct tm6000_reg_settings svideo_secam[] = {
+       { TM6010_REQ07_R3F_RESET, 0x01 },
+       { TM6010_REQ07_R00_VIDEO_CONTROL0, 0x39 },
+       { TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e },
+       { TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f },
+       { TM6010_REQ07_R03_YC_SEP_CONTROL, 0x03 },
+       { TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31 },
+       { TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x24 },
+       { TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x92 },
+       { TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xe8 },
+       { TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0xed },
+       { TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c },
+       { TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc },
+       { TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc },
+       { TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd },
+       { TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x8c },
+       { TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x2a },
+       { TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0xc1 },
+       { TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x2c },
+       { TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x18 },
+       { TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x42 },
+       { TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0xff },
+       { TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07 },
+       { TM6010_REQ07_R3F_RESET, 0x00 },
+       { 0, 0, 0 }
+};
+
+static struct tm6000_reg_settings svideo_ntsc[] = {
+       { TM6010_REQ07_R3F_RESET, 0x01 },
+       { TM6010_REQ07_R00_VIDEO_CONTROL0, 0x01 },
+       { TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0f },
+       { TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f },
+       { TM6010_REQ07_R03_YC_SEP_CONTROL, 0x03 },
+       { TM6010_REQ07_R07_OUTPUT_CONTROL, 0x30 },
+       { TM6010_REQ07_R17_HLOOP_MAXSTATE, 0x8b },
+       { TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e },
+       { TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x8b },
+       { TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xa2 },
+       { TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0xe9 },
+       { TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c },
+       { TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc },
+       { TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc },
+       { TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd },
+       { TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x88 },
+       { TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x22 },
+       { TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0x61 },
+       { TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x1c },
+       { TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c },
+       { TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x42 },
+       { TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6f },
+       { TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdd },
+       { TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07 },
+       { TM6010_REQ07_R3F_RESET, 0x00 },
+       { 0, 0, 0 }
+};
+
+static struct tm6000_std_settings svideo_stds[] = {
+       { .id = V4L2_STD_PAL_M, .common = svideo_pal_m, },
+       { .id = V4L2_STD_PAL_Nc, .common = svideo_pal_nc, },
+       { .id = V4L2_STD_PAL, .common = svideo_pal, },
+       { .id = V4L2_STD_SECAM, .common = svideo_secam, },
+       { .id = V4L2_STD_NTSC, .common = svideo_ntsc, },
+};
+
+static int tm6000_set_audio_std(struct tm6000_core *dev)
+{
+       uint8_t areg_02 = 0x04; /* GC1 Fixed gain 0dB */
+       uint8_t areg_05 = 0x01; /* Auto 4.5 = M Japan, Auto 6.5 = DK */
+       uint8_t areg_06 = 0x02; /* Auto de-emphasis, mannual channel mode */
+       uint8_t nicam_flag = 0; /* No NICAM */
+
+       if (dev->radio) {
+               tm6000_set_reg(dev, TM6010_REQ08_R01_A_INIT, 0x00);
+               tm6000_set_reg(dev, TM6010_REQ08_R02_A_FIX_GAIN_CTRL, 0x04);
+               tm6000_set_reg(dev, TM6010_REQ08_R03_A_AUTO_GAIN_CTRL, 0x00);
+               tm6000_set_reg(dev, TM6010_REQ08_R04_A_SIF_AMP_CTRL, 0x80);
+               tm6000_set_reg(dev, TM6010_REQ08_R05_A_STANDARD_MOD, 0x0c);
+               /* set mono or stereo */
+               if (dev->amode == V4L2_TUNER_MODE_MONO)
+                       tm6000_set_reg(dev, TM6010_REQ08_R06_A_SOUND_MOD, 0x00);
+               else if (dev->amode == V4L2_TUNER_MODE_STEREO)
+                       tm6000_set_reg(dev, TM6010_REQ08_R06_A_SOUND_MOD, 0x02);
+               tm6000_set_reg(dev, TM6010_REQ08_R09_A_MAIN_VOL, 0x18);
+               tm6000_set_reg(dev, TM6010_REQ08_R0C_A_ASD_THRES2, 0x0a);
+               tm6000_set_reg(dev, TM6010_REQ08_R0D_A_AMD_THRES, 0x40);
+               tm6000_set_reg(dev, TM6010_REQ08_RF1_AADC_POWER_DOWN, 0xfe);
+               tm6000_set_reg(dev, TM6010_REQ08_R1E_A_GAIN_DEEMPH_OUT, 0x13);
+               tm6000_set_reg(dev, TM6010_REQ08_R01_A_INIT, 0x80);
+               tm6000_set_reg(dev, TM6010_REQ07_RFE_POWER_DOWN, 0xff);
+               return 0;
+       }
+
+       switch (tm6010_a_mode) {
+       /* auto */
+       case 0:
+               switch (dev->norm) {
+               case V4L2_STD_NTSC_M_KR:
+                       areg_05 |= 0x00;
+                       break;
+               case V4L2_STD_NTSC_M_JP:
+                       areg_05 |= 0x40;
+                       break;
+               case V4L2_STD_NTSC_M:
+               case V4L2_STD_PAL_M:
+               case V4L2_STD_PAL_N:
+                       areg_05 |= 0x20;
+                       break;
+               case V4L2_STD_PAL_Nc:
+                       areg_05 |= 0x60;
+                       break;
+               case V4L2_STD_SECAM_L:
+                       areg_05 |= 0x00;
+                       break;
+               case V4L2_STD_DK:
+                       areg_05 |= 0x10;
+                       break;
+               }
+               break;
+       /* A2 */
+       case 1:
+               switch (dev->norm) {
+               case V4L2_STD_B:
+               case V4L2_STD_GH:
+                       areg_05 = 0x05;
+                       break;
+               case V4L2_STD_DK:
+                       areg_05 = 0x09;
+                       break;
+               }
+               break;
+       /* NICAM */
+       case 2:
+               switch (dev->norm) {
+               case V4L2_STD_B:
+               case V4L2_STD_GH:
+                       areg_05 = 0x07;
+                       break;
+               case V4L2_STD_DK:
+                       areg_05 = 0x06;
+                       break;
+               case V4L2_STD_PAL_I:
+                       areg_05 = 0x08;
+                       break;
+               case V4L2_STD_SECAM_L:
+                       areg_05 = 0x0a;
+                       areg_02 = 0x02;
+                       break;
+               }
+               nicam_flag = 1;
+               break;
+       /* other */
+       case 3:
+               switch (dev->norm) {
+               /* DK3_A2 */
+               case V4L2_STD_DK:
+                       areg_05 = 0x0b;
+                       break;
+               /* Korea */
+               case V4L2_STD_NTSC_M_KR:
+                       areg_05 = 0x04;
+                       break;
+               /* EIAJ */
+               case V4L2_STD_NTSC_M_JP:
+                       areg_05 = 0x03;
+                       break;
+               default:
+                       areg_05 = 0x02;
+                       break;
+               }
+               break;
+       }
+
+       tm6000_set_reg(dev, TM6010_REQ08_R01_A_INIT, 0x00);
+       tm6000_set_reg(dev, TM6010_REQ08_R02_A_FIX_GAIN_CTRL, areg_02);
+       tm6000_set_reg(dev, TM6010_REQ08_R03_A_AUTO_GAIN_CTRL, 0x00);
+       tm6000_set_reg(dev, TM6010_REQ08_R04_A_SIF_AMP_CTRL, 0xa0);
+       tm6000_set_reg(dev, TM6010_REQ08_R05_A_STANDARD_MOD, areg_05);
+       tm6000_set_reg(dev, TM6010_REQ08_R06_A_SOUND_MOD, areg_06);
+       tm6000_set_reg(dev, TM6010_REQ08_R07_A_LEFT_VOL, 0x00);
+       tm6000_set_reg(dev, TM6010_REQ08_R08_A_RIGHT_VOL, 0x00);
+       tm6000_set_reg(dev, TM6010_REQ08_R09_A_MAIN_VOL, 0x08);
+       tm6000_set_reg(dev, TM6010_REQ08_R0A_A_I2S_MOD, 0x91);
+       tm6000_set_reg(dev, TM6010_REQ08_R0B_A_ASD_THRES1, 0x20);
+       tm6000_set_reg(dev, TM6010_REQ08_R0C_A_ASD_THRES2, 0x12);
+       tm6000_set_reg(dev, TM6010_REQ08_R0D_A_AMD_THRES, 0x20);
+       tm6000_set_reg(dev, TM6010_REQ08_R0E_A_MONO_THRES1, 0xf0);
+       tm6000_set_reg(dev, TM6010_REQ08_R0F_A_MONO_THRES2, 0x80);
+       tm6000_set_reg(dev, TM6010_REQ08_R10_A_MUTE_THRES1, 0xc0);
+       tm6000_set_reg(dev, TM6010_REQ08_R11_A_MUTE_THRES2, 0x80);
+       tm6000_set_reg(dev, TM6010_REQ08_R12_A_AGC_U, 0x12);
+       tm6000_set_reg(dev, TM6010_REQ08_R13_A_AGC_ERR_T, 0xfe);
+       tm6000_set_reg(dev, TM6010_REQ08_R14_A_AGC_GAIN_INIT, 0x20);
+       tm6000_set_reg(dev, TM6010_REQ08_R15_A_AGC_STEP_THR, 0x14);
+       tm6000_set_reg(dev, TM6010_REQ08_R16_A_AGC_GAIN_MAX, 0xfe);
+       tm6000_set_reg(dev, TM6010_REQ08_R17_A_AGC_GAIN_MIN, 0x01);
+       tm6000_set_reg(dev, TM6010_REQ08_R18_A_TR_CTRL, 0xa0);
+       tm6000_set_reg(dev, TM6010_REQ08_R19_A_FH_2FH_GAIN, 0x32);
+       tm6000_set_reg(dev, TM6010_REQ08_R1A_A_NICAM_SER_MAX, 0x64);
+       tm6000_set_reg(dev, TM6010_REQ08_R1B_A_NICAM_SER_MIN, 0x20);
+       tm6000_set_reg(dev, REQ_08_SET_GET_AVREG_BIT, 0x1c, 0x00);
+       tm6000_set_reg(dev, REQ_08_SET_GET_AVREG_BIT, 0x1d, 0x00);
+       tm6000_set_reg(dev, TM6010_REQ08_R1E_A_GAIN_DEEMPH_OUT, 0x13);
+       tm6000_set_reg(dev, TM6010_REQ08_R1F_A_TEST_INTF_SEL, 0x00);
+       tm6000_set_reg(dev, TM6010_REQ08_R20_A_TEST_PIN_SEL, 0x00);
+       tm6000_set_reg(dev, TM6010_REQ08_R01_A_INIT, 0x80);
+
+       return 0;
+}
+
+void tm6000_get_std_res(struct tm6000_core *dev)
+{
+       /* Currently, those are the only supported resoltions */
+       if (dev->norm & V4L2_STD_525_60)
+               dev->height = 480;
+       else
+               dev->height = 576;
+
+       dev->width = 720;
+}
+
+static int tm6000_load_std(struct tm6000_core *dev, struct tm6000_reg_settings *set)
+{
+       int i, rc;
+
+       /* Load board's initialization table */
+       for (i = 0; set[i].req; i++) {
+               rc = tm6000_set_reg(dev, set[i].req, set[i].reg, set[i].value);
+               if (rc < 0) {
+                       printk(KERN_ERR "Error %i while setting "
+                              "req %d, reg %d to value %d\n",
+                              rc, set[i].req, set[i].reg, set[i].value);
+                       return rc;
+               }
+       }
+
+       return 0;
+}
+
+int tm6000_set_standard(struct tm6000_core *dev)
+{
+       struct tm6000_input *input;
+       int i, rc = 0;
+       u8 reg_07_fe = 0x8a;
+       u8 reg_08_f1 = 0xfc;
+       u8 reg_08_e2 = 0xf0;
+       u8 reg_08_e6 = 0x0f;
+
+       tm6000_get_std_res(dev);
+
+       if (!dev->radio)
+               input = &dev->vinput[dev->input];
+       else
+               input = &dev->rinput;
+
+       if (dev->dev_type == TM6010) {
+               switch (input->vmux) {
+               case TM6000_VMUX_VIDEO_A:
+                       tm6000_set_reg(dev, TM6010_REQ08_RE3_ADC_IN1_SEL, 0xf4);
+                       tm6000_set_reg(dev, TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf1);
+                       tm6000_set_reg(dev, TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xe0);
+                       tm6000_set_reg(dev, TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2);
+                       tm6000_set_reg(dev, TM6010_REQ08_RED_GAIN_SEL, 0xe8);
+                       reg_07_fe |= 0x01;
+                       break;
+               case TM6000_VMUX_VIDEO_B:
+                       tm6000_set_reg(dev, TM6010_REQ08_RE3_ADC_IN1_SEL, 0xf8);
+                       tm6000_set_reg(dev, TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf1);
+                       tm6000_set_reg(dev, TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xe0);
+                       tm6000_set_reg(dev, TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2);
+                       tm6000_set_reg(dev, TM6010_REQ08_RED_GAIN_SEL, 0xe8);
+                       reg_07_fe |= 0x01;
+                       break;
+               case TM6000_VMUX_VIDEO_AB:
+                       tm6000_set_reg(dev, TM6010_REQ08_RE3_ADC_IN1_SEL, 0xfc);
+                       tm6000_set_reg(dev, TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf8);
+                       reg_08_e6 = 0x00;
+                       tm6000_set_reg(dev, TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf2);
+                       tm6000_set_reg(dev, TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xf0);
+                       tm6000_set_reg(dev, TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2);
+                       tm6000_set_reg(dev, TM6010_REQ08_RED_GAIN_SEL, 0xe0);
+                       break;
+               default:
+                       break;
+               }
+               switch (input->amux) {
+               case TM6000_AMUX_ADC1:
+                       tm6000_set_reg_mask(dev, TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG,
+                               0x00, 0x0f);
+                       break;
+               case TM6000_AMUX_ADC2:
+                       tm6000_set_reg_mask(dev, TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG,
+                               0x08, 0x0f);
+                       break;
+               case TM6000_AMUX_SIF1:
+                       reg_08_e2 |= 0x02;
+                       reg_08_e6 = 0x08;
+                       reg_07_fe |= 0x40;
+                       reg_08_f1 |= 0x02;
+                       tm6000_set_reg(dev, TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf3);
+                       tm6000_set_reg_mask(dev, TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG,
+                               0x02, 0x0f);
+                       break;
+               case TM6000_AMUX_SIF2:
+                       reg_08_e2 |= 0x02;
+                       reg_08_e6 = 0x08;
+                       reg_07_fe |= 0x40;
+                       reg_08_f1 |= 0x02;
+                       tm6000_set_reg(dev, TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf7);
+                       tm6000_set_reg_mask(dev, TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG,
+                               0x02, 0x0f);
+                       break;
+               default:
+                       break;
+               }
+               tm6000_set_reg(dev, TM6010_REQ08_RE2_POWER_DOWN_CTRL1, reg_08_e2);
+               tm6000_set_reg(dev, TM6010_REQ08_RE6_POWER_DOWN_CTRL2, reg_08_e6);
+               tm6000_set_reg(dev, TM6010_REQ08_RF1_AADC_POWER_DOWN, reg_08_f1);
+               tm6000_set_reg(dev, TM6010_REQ07_RFE_POWER_DOWN, reg_07_fe);
+       } else {
+               switch (input->vmux) {
+               case TM6000_VMUX_VIDEO_A:
+                       tm6000_set_reg(dev, TM6000_REQ07_RE3_VADC_INP_LPF_SEL1, 0x10);
+                       tm6000_set_reg(dev, TM6000_REQ07_RE5_VADC_INP_LPF_SEL2, 0x00);
+                       tm6000_set_reg(dev, TM6000_REQ07_RE8_VADC_PWDOWN_CTL, 0x0f);
+                       tm6000_set_reg(dev,
+                           REQ_03_SET_GET_MCU_PIN, input->v_gpio, 0);
+                       break;
+               case TM6000_VMUX_VIDEO_B:
+                       tm6000_set_reg(dev, TM6000_REQ07_RE3_VADC_INP_LPF_SEL1, 0x00);
+                       tm6000_set_reg(dev, TM6000_REQ07_RE5_VADC_INP_LPF_SEL2, 0x00);
+                       tm6000_set_reg(dev, TM6000_REQ07_RE8_VADC_PWDOWN_CTL, 0x0f);
+                       tm6000_set_reg(dev,
+                           REQ_03_SET_GET_MCU_PIN, input->v_gpio, 0);
+                       break;
+               case TM6000_VMUX_VIDEO_AB:
+                       tm6000_set_reg(dev, TM6000_REQ07_RE3_VADC_INP_LPF_SEL1, 0x10);
+                       tm6000_set_reg(dev, TM6000_REQ07_RE5_VADC_INP_LPF_SEL2, 0x10);
+                       tm6000_set_reg(dev, TM6000_REQ07_RE8_VADC_PWDOWN_CTL, 0x00);
+                       tm6000_set_reg(dev,
+                           REQ_03_SET_GET_MCU_PIN, input->v_gpio, 1);
+                       break;
+               default:
+                       break;
+               }
+               switch (input->amux) {
+               case TM6000_AMUX_ADC1:
+                       tm6000_set_reg_mask(dev,
+                               TM6000_REQ07_REB_VADC_AADC_MODE, 0x00, 0x0f);
+                       break;
+               case TM6000_AMUX_ADC2:
+                       tm6000_set_reg_mask(dev,
+                               TM6000_REQ07_REB_VADC_AADC_MODE, 0x04, 0x0f);
+                       break;
+               default:
+                       break;
+               }
+       }
+       if (input->type == TM6000_INPUT_SVIDEO) {
+               for (i = 0; i < ARRAY_SIZE(svideo_stds); i++) {
+                       if (dev->norm & svideo_stds[i].id) {
+                               rc = tm6000_load_std(dev, svideo_stds[i].common);
+                               goto ret;
+                       }
+               }
+               return -EINVAL;
+       } else {
+               for (i = 0; i < ARRAY_SIZE(composite_stds); i++) {
+                       if (dev->norm & composite_stds[i].id) {
+                               rc = tm6000_load_std(dev, composite_stds[i].common);
+                               goto ret;
+                       }
+               }
+               return -EINVAL;
+       }
+
+ret:
+       if (rc < 0)
+               return rc;
+
+       if ((dev->dev_type == TM6010) &&
+           ((input->amux == TM6000_AMUX_SIF1) ||
+           (input->amux == TM6000_AMUX_SIF2)))
+               tm6000_set_audio_std(dev);
+
+       msleep(40);
+
+       return 0;
+}
similarity index 97%
rename from drivers/staging/tm6000/tm6000-usb-isoc.h
rename to drivers/media/video/tm6000/tm6000-usb-isoc.h
index 084c2a8904a3da6a3bcadb7ac67d07f0cf5e4fc3..99d15a55aa03ae3049320d2b468b14b7dd0a874d 100644 (file)
@@ -46,5 +46,5 @@ struct usb_isoc_ctl {
        int                             tmp_buf_len;
 
                /* Stores already requested buffers */
-       struct tm6000_buffer            *buf;
+       struct tm6000_buffer            *buf;
 };
similarity index 96%
rename from drivers/staging/tm6000/tm6000-video.c
rename to drivers/media/video/tm6000/tm6000-video.c
index 8d8b939915d8117116977f4372695e916d81198e..1e5ace0b5d10517f4e36baf81698d2851b459f45 100644 (file)
@@ -19,6 +19,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
+
 #include <linux/module.h>
 #include <linux/delay.h>
 #include <linux/errno.h>
@@ -202,17 +203,6 @@ static inline void buffer_filled(struct tm6000_core *dev,
        wake_up(&buf->vb.done);
 }
 
-const char *tm6000_msg_type[] = {
-       "unknown(0)",   /* 0 */
-       "video",        /* 1 */
-       "audio",        /* 2 */
-       "vbi",          /* 3 */
-       "pts",          /* 4 */
-       "err",          /* 5 */
-       "unknown(6)",   /* 6 */
-       "unknown(7)",   /* 7 */
-};
-
 /*
  * Identify the tm5600/6000 buffer header type and properly handles
  */
@@ -286,17 +276,18 @@ static int copy_streams(u8 *data, unsigned long len,
                        if (size > TM6000_URB_MSG_LEN)
                                size = TM6000_URB_MSG_LEN;
                        pktsize = TM6000_URB_MSG_LEN;
-                       /* calculate position in buffer
-                        * and change the buffer
+                       /*
+                        * calculate position in buffer and change the buffer
                         */
                        switch (cmd) {
                        case TM6000_URB_MSG_VIDEO:
                                if (!dev->radio) {
                                        if ((dev->isoc_ctl.vfield != field) &&
                                                (field == 1)) {
-                                       /* Announces that a new buffer
-                                        * were filled
-                                        */
+                                               /*
+                                                * Announces that a new buffer
+                                                * were filled
+                                                */
                                                buffer_filled(dev, dma_q, vbuf);
                                                dprintk(dev, V4L2_DEBUG_ISOC,
                                                        "new buffer filled\n");
@@ -321,7 +312,7 @@ static int copy_streams(u8 *data, unsigned long len,
                                break;
                        case TM6000_URB_MSG_AUDIO:
                        case TM6000_URB_MSG_PTS:
-                               size = pktsize;         /* Size is always 180 bytes */
+                               size = pktsize; /* Size is always 180 bytes */
                                break;
                        }
                } else {
@@ -363,7 +354,8 @@ static int copy_streams(u8 *data, unsigned long len,
                        }
                }
                if (ptr + pktsize > endp) {
-                       /* End of URB packet, but cmd processing is not
+                       /*
+                        * End of URB packet, but cmd processing is not
                         * complete. Preserve the state for a next packet
                         */
                        dev->isoc_ctl.pos = pos + cpysize;
@@ -521,9 +513,21 @@ static void tm6000_irq_callback(struct urb *urb)
        struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
        int i;
 
-       if (!dev)
+       switch (urb->status) {
+       case 0:
+       case -ETIMEDOUT:
+               break;
+
+       case -ECONNRESET:
+       case -ENOENT:
+       case -ESHUTDOWN:
                return;
 
+       default:
+               tm6000_err("urb completion error %d.\n", urb->status);
+               break;
+       }
+
        spin_lock(&dev->slock);
        tm6000_isoc_copy(urb);
        spin_unlock(&dev->slock);
@@ -750,7 +754,7 @@ buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
        struct tm6000_fh     *fh  = vq->priv_data;
        struct tm6000_buffer *buf = container_of(vb, struct tm6000_buffer, vb);
        struct tm6000_core   *dev = fh->dev;
-       int rc = 0, urb_init = 0;
+       int rc = 0;
 
        BUG_ON(NULL == fh->fmt);
 
@@ -776,13 +780,9 @@ buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
                rc = videobuf_iolock(vq, &buf->vb, NULL);
                if (rc != 0)
                        goto fail;
-               urb_init = 1;
        }
 
-       if (!dev->isoc_ctl.num_bufs)
-               urb_init = 1;
-
-       if (urb_init) {
+       if (!dev->isoc_ctl.num_bufs) {
                rc = tm6000_prepare_isoc(dev);
                if (rc < 0)
                        goto fail;
@@ -1035,8 +1035,8 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
 
 static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
 {
-       struct tm6000_fh  *fh = priv;
-       struct tm6000_core *dev    = fh->dev;
+       struct tm6000_fh *fh = priv;
+       struct tm6000_core *dev = fh->dev;
 
        if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
                return -EINVAL;
@@ -1050,11 +1050,12 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
 
 static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
 {
-       struct tm6000_fh  *fh = priv;
-       struct tm6000_core *dev    = fh->dev;
+       struct tm6000_fh *fh = priv;
+       struct tm6000_core *dev = fh->dev;
 
        if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
                return -EINVAL;
+
        if (i != fh->type)
                return -EINVAL;
 
@@ -1067,7 +1068,7 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
 static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *norm)
 {
        int rc = 0;
-       struct tm6000_fh   *fh = priv;
+       struct tm6000_fh *fh = priv;
        struct tm6000_core *dev = fh->dev;
 
        dev->norm = *norm;
@@ -1464,9 +1465,6 @@ static int tm6000_open(struct file *file)
        int i, rc;
        int radio = 0;
 
-       printk(KERN_INFO "tm6000: open called (dev=%s)\n",
-               video_device_node_name(vdev));
-
        dprintk(dev, V4L2_DEBUG_OPEN, "tm6000: open called (dev=%s)\n",
                video_device_node_name(vdev));
 
@@ -1507,12 +1505,13 @@ static int tm6000_open(struct file *file)
 
        tm6000_get_std_res(dev);
 
-       fh->width    = dev->width;
-       fh->height   = dev->height;
+       fh->width = dev->width;
+       fh->height = dev->height;
 
        dprintk(dev, V4L2_DEBUG_OPEN, "Open: fh=0x%08lx, dev=0x%08lx, "
                                                "dev->vidq=0x%08lx\n",
-               (unsigned long)fh, (unsigned long)dev, (unsigned long)&dev->vidq);
+                       (unsigned long)fh, (unsigned long)dev,
+                       (unsigned long)&dev->vidq);
        dprintk(dev, V4L2_DEBUG_OPEN, "Open: list_empty "
                                "queued=%d\n", list_empty(&dev->vidq.queued));
        dprintk(dev, V4L2_DEBUG_OPEN, "Open: list_empty "
@@ -1531,13 +1530,13 @@ static int tm6000_open(struct file *file)
                dev->mode = TM6000_MODE_ANALOG;
        }
 
-       videobuf_queue_vmalloc_init(&fh->vb_vidq, &tm6000_video_qops,
-                       NULL, &dev->slock,
-                       fh->type,
-                       V4L2_FIELD_INTERLACED,
-                       sizeof(struct tm6000_buffer), fh, &dev->lock);
-
-       if (fh->radio) {
+       if (!fh->radio) {
+               videobuf_queue_vmalloc_init(&fh->vb_vidq, &tm6000_video_qops,
+                               NULL, &dev->slock,
+                               fh->type,
+                               V4L2_FIELD_INTERLACED,
+                               sizeof(struct tm6000_buffer), fh, &dev->lock);
+       } else {
                dprintk(dev, V4L2_DEBUG_OPEN, "video_open: setting radio device\n");
                dev->input = 5;
                tm6000_set_audio_rinput(dev);
@@ -1583,8 +1582,7 @@ tm6000_poll(struct file *file, struct poll_table_struct *wait)
                buf = list_entry(fh->vb_vidq.stream.next, struct tm6000_buffer, vb.stream);
        } else {
                /* read() capture */
-               return videobuf_poll_stream(file, &fh->vb_vidq,
-                                           wait);
+               return videobuf_poll_stream(file, &fh->vb_vidq, wait);
        }
        poll_wait(file, &buf->vb.done, wait);
        if (buf->vb.state == VIDEOBUF_DONE ||
@@ -1605,9 +1603,18 @@ static int tm6000_release(struct file *file)
        dev->users--;
 
        res_free(dev, fh);
+
        if (!dev->users) {
+               int err;
+
                tm6000_uninit_isoc(dev);
-               videobuf_mmap_free(&fh->vb_vidq);
+
+               if (!fh->radio)
+                       videobuf_mmap_free(&fh->vb_vidq);
+
+               err = tm6000_reset(dev);
+               if (err < 0)
+                       dev_err(&vdev->dev, "reset failed: %d\n", err);
        }
 
        kfree(fh);
@@ -1617,22 +1624,19 @@ static int tm6000_release(struct file *file)
 
 static int tm6000_mmap(struct file *file, struct vm_area_struct * vma)
 {
-       struct tm6000_fh        *fh = file->private_data;
-       int ret;
-
-       ret = videobuf_mmap_mapper(&fh->vb_vidq, vma);
+       struct tm6000_fh *fh = file->private_data;
 
-       return ret;
+       return videobuf_mmap_mapper(&fh->vb_vidq, vma);
 }
 
 static struct v4l2_file_operations tm6000_fops = {
-       .owner          = THIS_MODULE,
-       .open           = tm6000_open,
-       .release        = tm6000_release,
-       .unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */
-       .read           = tm6000_read,
-       .poll           = tm6000_poll,
-       .mmap           = tm6000_mmap,
+       .owner = THIS_MODULE,
+       .open = tm6000_open,
+       .release = tm6000_release,
+       .unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */
+       .read = tm6000_read,
+       .poll = tm6000_poll,
+       .mmap = tm6000_mmap,
 };
 
 static const struct v4l2_ioctl_ops video_ioctl_ops = {
@@ -1693,7 +1697,7 @@ static const struct v4l2_ioctl_ops radio_ioctl_ops = {
        .vidioc_s_frequency     = vidioc_s_frequency,
 };
 
-struct video_device tm6000_radio_template = {
+static struct video_device tm6000_radio_template = {
        .name                   = "tm6000",
        .fops                   = &radio_fops,
        .ioctl_ops              = &radio_ioctl_ops,
similarity index 98%
rename from drivers/staging/tm6000/tm6000.h
rename to drivers/media/video/tm6000/tm6000.h
index c56da628dbefa5d57c14d001a9566c39cbeb2ad6..2777e514eff27a8a95fa0d315f7b040c1ff2c8b3 100644 (file)
@@ -20,9 +20,6 @@
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-/* Use the tm6000-hack, instead of the proper initialization code i*/
-/* #define HACK 1 */
-
 #include <linux/videodev2.h>
 #include <media/v4l2-common.h>
 #include <media/videobuf-vmalloc.h>
@@ -30,7 +27,7 @@
 #include <linux/i2c.h>
 #include <linux/mutex.h>
 #include <media/v4l2-device.h>
-#include <linux/version.h>
+
 #include <linux/dvb/frontend.h>
 #include "dvb_demux.h"
 #include "dvb_frontend.h"
@@ -172,6 +169,8 @@ struct tm6000_endpoint {
        unsigned                        maxsize;
 };
 
+#define TM6000_QUIRK_NO_USB_DELAY (1 << 0)
+
 struct tm6000_core {
        /* generic device properties */
        char                            name[30];       /* name (including minor) of the device */
@@ -248,6 +247,7 @@ struct tm6000_core {
 
        /* locks */
        struct mutex                    lock;
+       struct mutex                    usb_lock;
 
        /* usb transfer */
        struct usb_device               *udev;          /* the usb device */
@@ -262,6 +262,8 @@ struct tm6000_core {
        struct usb_isoc_ctl          isoc_ctl;
 
        spinlock_t                   slock;
+
+       unsigned long quirks;
 };
 
 enum tm6000_ops_type {
@@ -313,6 +315,7 @@ int tm6000_set_reg_mask(struct tm6000_core *dev, u8 req, u16 value,
                                                u16 index, u16 mask);
 int tm6000_i2c_reset(struct tm6000_core *dev, u16 tsleep);
 int tm6000_init(struct tm6000_core *dev);
+int tm6000_reset(struct tm6000_core *dev);
 
 int tm6000_init_analog_mode(struct tm6000_core *dev);
 int tm6000_init_digital_mode(struct tm6000_core *dev);
@@ -381,7 +384,7 @@ extern int tm6000_debug;
 #define dprintk(dev, level, fmt, arg...) do {\
        if (tm6000_debug & level) \
                printk(KERN_INFO "(%lu) %s %s :"fmt, jiffies, \
-                        dev->name, __FUNCTION__ , ##arg); } while (0)
+                        dev->name, __func__ , ##arg); } while (0)
 
 #define V4L2_DEBUG_REG         0x0004
 #define V4L2_DEBUG_I2C         0x0008
@@ -392,4 +395,4 @@ extern int tm6000_debug;
 
 #define tm6000_err(fmt, arg...) do {\
        printk(KERN_ERR "tm6000 %s :"fmt, \
-               __FUNCTION__ , ##arg); } while (0)
+               __func__ , ##arg); } while (0)
index c46a3bb95852a7da7ad866387ec1b602c29bc5a6..f22dbef9b95b72bfe4bf06f2a6d9aa185573bcf2 100644 (file)
@@ -1695,14 +1695,17 @@ static int tvaudio_s_ctrl(struct v4l2_subdev *sd,
        case V4L2_CID_AUDIO_BALANCE:
        {
                int volume, balance;
+
                if (!(desc->flags & CHIP_HAS_VOLUME))
                        break;
 
-               volume = max(chip->left,chip->right);
+               volume = max(chip->left, chip->right);
                balance = ctrl->value;
+               chip->left = (min(65536 - balance, 32768) * volume) / 32768;
+               chip->right = (min(balance, volume * (__u16)32768)) / 32768;
 
-               chip_write(chip,desc->leftreg,desc->volfunc(chip->left));
-               chip_write(chip,desc->rightreg,desc->volfunc(chip->right));
+               chip_write(chip, desc->leftreg, desc->volfunc(chip->left));
+               chip_write(chip, desc->rightreg, desc->volfunc(chip->right));
 
                return 0;
        }
index 4240043c0b2a5ea445c2bd2247a3037722cc9e43..25a994944918703f064eee85a6017ca7010dca4b 100644 (file)
 
 /* Reserved 1Fh-27h */
 
-#define TVP5150_VIDEO_STD           0x28 /* Video standard */
+#define VIDEO_STD_MASK                  (0x07 >> 1)
+#define TVP5150_VIDEO_STD                0x28 /* Video standard */
+#define VIDEO_STD_AUTO_SWITCH_BIT       0x00
+#define VIDEO_STD_NTSC_MJ_BIT           0x02
+#define VIDEO_STD_PAL_BDGHIN_BIT        0x04
+#define VIDEO_STD_PAL_M_BIT             0x06
+#define VIDEO_STD_PAL_COMBINATION_N_BIT         0x08
+#define VIDEO_STD_NTSC_4_43_BIT                 0x0a
+#define VIDEO_STD_SECAM_BIT             0x0c
+
+#define VIDEO_STD_NTSC_MJ_BIT_AS                 0x01
+#define VIDEO_STD_PAL_BDGHIN_BIT_AS              0x03
+#define VIDEO_STD_PAL_M_BIT_AS                  0x05
+#define VIDEO_STD_PAL_COMBINATION_N_BIT_AS      0x07
+#define VIDEO_STD_NTSC_4_43_BIT_AS              0x09
+#define VIDEO_STD_SECAM_BIT_AS                  0x0b
 
 /* Reserved 29h-2bh */
 
index b799851bf3d0be20abfd593a6cf98d8b131e49ab..2e6059a52e9f4e5cdb38f1999f346d5921ff8254 100644 (file)
@@ -128,7 +128,7 @@ static const struct i2c_reg_value tvp7002_init_default[] = {
        { TVP7002_ADC_SETUP, 0x50, TVP7002_WRITE },
        { TVP7002_COARSE_CLAMP_CTL, 0x00, TVP7002_WRITE },
        { TVP7002_SOG_CLAMP, 0x80, TVP7002_WRITE },
-       { TVP7002_RGB_COARSE_CLAMP_CTL, 0x00, TVP7002_WRITE },
+       { TVP7002_RGB_COARSE_CLAMP_CTL, 0x8c, TVP7002_WRITE },
        { TVP7002_SOG_COARSE_CLAMP_CTL, 0x04, TVP7002_WRITE },
        { TVP7002_ALC_PLACEMENT, 0x5a, TVP7002_WRITE },
        { 0x32, 0x18, TVP7002_RESERVED },
@@ -182,7 +182,6 @@ static const struct i2c_reg_value tvp7002_parms_480P[] = {
        { TVP7002_HPLL_FDBK_DIV_MSBS, 0x35, TVP7002_WRITE },
        { TVP7002_HPLL_FDBK_DIV_LSBS, 0xa0, TVP7002_WRITE },
        { TVP7002_HPLL_CRTL, 0x02, TVP7002_WRITE },
-       { TVP7002_HPLL_PHASE_SEL, 0x14, TVP7002_WRITE },
        { TVP7002_AVID_START_PIXEL_LSBS, 0x91, TVP7002_WRITE },
        { TVP7002_AVID_START_PIXEL_MSBS, 0x00, TVP7002_WRITE },
        { TVP7002_AVID_STOP_PIXEL_LSBS, 0x0B, TVP7002_WRITE },
@@ -204,7 +203,6 @@ static const struct i2c_reg_value tvp7002_parms_576P[] = {
        { TVP7002_HPLL_FDBK_DIV_MSBS, 0x36, TVP7002_WRITE },
        { TVP7002_HPLL_FDBK_DIV_LSBS, 0x00, TVP7002_WRITE },
        { TVP7002_HPLL_CRTL, 0x18, TVP7002_WRITE },
-       { TVP7002_HPLL_PHASE_SEL, 0x14, TVP7002_WRITE },
        { TVP7002_AVID_START_PIXEL_LSBS, 0x9B, TVP7002_WRITE },
        { TVP7002_AVID_START_PIXEL_MSBS, 0x00, TVP7002_WRITE },
        { TVP7002_AVID_STOP_PIXEL_LSBS, 0x0F, TVP7002_WRITE },
@@ -226,7 +224,6 @@ static const struct i2c_reg_value tvp7002_parms_1080I60[] = {
        { TVP7002_HPLL_FDBK_DIV_MSBS, 0x89, TVP7002_WRITE },
        { TVP7002_HPLL_FDBK_DIV_LSBS, 0x80, TVP7002_WRITE },
        { TVP7002_HPLL_CRTL, 0x98, TVP7002_WRITE },
-       { TVP7002_HPLL_PHASE_SEL, 0x14, TVP7002_WRITE },
        { TVP7002_AVID_START_PIXEL_LSBS, 0x06, TVP7002_WRITE },
        { TVP7002_AVID_START_PIXEL_MSBS, 0x01, TVP7002_WRITE },
        { TVP7002_AVID_STOP_PIXEL_LSBS, 0x8a, TVP7002_WRITE },
@@ -248,7 +245,6 @@ static const struct i2c_reg_value tvp7002_parms_1080P60[] = {
        { TVP7002_HPLL_FDBK_DIV_MSBS, 0x89, TVP7002_WRITE },
        { TVP7002_HPLL_FDBK_DIV_LSBS, 0x80, TVP7002_WRITE },
        { TVP7002_HPLL_CRTL, 0xE0, TVP7002_WRITE },
-       { TVP7002_HPLL_PHASE_SEL, 0x14, TVP7002_WRITE },
        { TVP7002_AVID_START_PIXEL_LSBS, 0x06, TVP7002_WRITE },
        { TVP7002_AVID_START_PIXEL_MSBS, 0x01, TVP7002_WRITE },
        { TVP7002_AVID_STOP_PIXEL_LSBS, 0x8a, TVP7002_WRITE },
@@ -270,7 +266,6 @@ static const struct i2c_reg_value tvp7002_parms_1080I50[] = {
        { TVP7002_HPLL_FDBK_DIV_MSBS, 0xa5, TVP7002_WRITE },
        { TVP7002_HPLL_FDBK_DIV_LSBS, 0x00, TVP7002_WRITE },
        { TVP7002_HPLL_CRTL, 0x98, TVP7002_WRITE },
-       { TVP7002_HPLL_PHASE_SEL, 0x14, TVP7002_WRITE },
        { TVP7002_AVID_START_PIXEL_LSBS, 0x06, TVP7002_WRITE },
        { TVP7002_AVID_START_PIXEL_MSBS, 0x01, TVP7002_WRITE },
        { TVP7002_AVID_STOP_PIXEL_LSBS, 0x8a, TVP7002_WRITE },
@@ -292,7 +287,6 @@ static const struct i2c_reg_value tvp7002_parms_720P60[] = {
        { TVP7002_HPLL_FDBK_DIV_MSBS, 0x67, TVP7002_WRITE },
        { TVP7002_HPLL_FDBK_DIV_LSBS, 0x20, TVP7002_WRITE },
        { TVP7002_HPLL_CRTL, 0xa0, TVP7002_WRITE },
-       { TVP7002_HPLL_PHASE_SEL, 0x16, TVP7002_WRITE },
        { TVP7002_AVID_START_PIXEL_LSBS, 0x47, TVP7002_WRITE },
        { TVP7002_AVID_START_PIXEL_MSBS, 0x01, TVP7002_WRITE },
        { TVP7002_AVID_STOP_PIXEL_LSBS, 0x4B, TVP7002_WRITE },
@@ -314,7 +308,6 @@ static const struct i2c_reg_value tvp7002_parms_720P50[] = {
        { TVP7002_HPLL_FDBK_DIV_MSBS, 0x7b, TVP7002_WRITE },
        { TVP7002_HPLL_FDBK_DIV_LSBS, 0xc0, TVP7002_WRITE },
        { TVP7002_HPLL_CRTL, 0x98, TVP7002_WRITE },
-       { TVP7002_HPLL_PHASE_SEL, 0x16, TVP7002_WRITE },
        { TVP7002_AVID_START_PIXEL_LSBS, 0x47, TVP7002_WRITE },
        { TVP7002_AVID_START_PIXEL_MSBS, 0x01, TVP7002_WRITE },
        { TVP7002_AVID_STOP_PIXEL_LSBS, 0x4B, TVP7002_WRITE },
@@ -687,6 +680,9 @@ static int tvp7002_query_dv_preset(struct v4l2_subdev *sd,
        u8 cpl_msb;
        int index;
 
+       /* Return invalid preset if no active input is detected */
+       qpreset->preset = V4L2_DV_INVALID;
+
        device = to_tvp7002(sd);
 
        /* Read standards from device registers */
@@ -720,8 +716,6 @@ static int tvp7002_query_dv_preset(struct v4l2_subdev *sd,
        if (index == NUM_PRESETS) {
                v4l2_dbg(1, debug, sd, "detection failed: lpf = %x, cpl = %x\n",
                                                                lpfr, cpln);
-               /* Could not detect a signal, so return the 'invalid' preset */
-               qpreset->preset = V4L2_DV_INVALID;
                return 0;
        }
 
index 338718750945bf8feb63e3d00a8e254b6781a3cc..aea1e3b5f06b7c1b1b9c7687a3f0a52f02a29bf0 100644 (file)
@@ -2,5 +2,5 @@ usbvision-objs  := usbvision-core.o usbvision-video.o usbvision-i2c.o usbvision-
 
 obj-$(CONFIG_VIDEO_USBVISION) += usbvision.o
 
-EXTRA_CFLAGS += -Idrivers/media/video
-EXTRA_CFLAGS += -Idrivers/media/common/tuners
+ccflags-y += -Idrivers/media/video
+ccflags-y += -Idrivers/media/common/tuners
index e4100b1f68df993eb622f0940c6feff2decd6d52..656d4c9e3b9f85a07d96a57b5401b13e9526aa4d 100644 (file)
@@ -114,6 +114,11 @@ static struct uvc_format_desc uvc_fmts[] = {
                .guid           = UVC_GUID_FORMAT_RGBP,
                .fcc            = V4L2_PIX_FMT_RGB565,
        },
+       {
+               .name           = "H.264",
+               .guid           = UVC_GUID_FORMAT_H264,
+               .fcc            = V4L2_PIX_FMT_H264,
+       },
 };
 
 /* ------------------------------------------------------------------------
@@ -2331,6 +2336,14 @@ static struct usb_device_id uvc_ids[] = {
          .bInterfaceSubClass   = 1,
          .bInterfaceProtocol   = 0,
          .driver_info          = UVC_QUIRK_PROBE_DEF },
+       /* The Imaging Source USB CCD cameras */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x199e,
+         .idProduct            = 0x8102,
+         .bInterfaceClass      = USB_CLASS_VENDOR_SPEC,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0 },
        /* Bodelin ProScopeHR */
        { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
                                | USB_DEVICE_ID_MATCH_DEV_HI
index ea71d5f1f6db93d285eada76f87f68b2692cfd36..dadf11f704dc742e8fe21d8df0880f35e3b9128e 100644 (file)
@@ -32,7 +32,7 @@
  * UVC ioctls
  */
 static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain,
-       struct uvc_xu_control_mapping *xmap, int old)
+       struct uvc_xu_control_mapping *xmap)
 {
        struct uvc_control_mapping *map;
        unsigned int size;
@@ -58,13 +58,6 @@ static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain,
                break;
 
        case V4L2_CTRL_TYPE_MENU:
-               if (old) {
-                       uvc_trace(UVC_TRACE_CONTROL, "V4L2_CTRL_TYPE_MENU not "
-                                 "supported for UVCIOC_CTRL_MAP_OLD.\n");
-                       ret = -EINVAL;
-                       goto done;
-               }
-
                size = xmap->menu_count * sizeof(*map->menu_info);
                map->menu_info = kmalloc(size, GFP_KERNEL);
                if (map->menu_info == NULL) {
@@ -538,20 +531,6 @@ static int uvc_v4l2_release(struct file *file)
        return 0;
 }
 
-static void uvc_v4l2_ioctl_warn(void)
-{
-       static int warned;
-
-       if (warned)
-               return;
-
-       uvc_printk(KERN_INFO, "Deprecated UVCIOC_CTRL_{ADD,MAP_OLD,GET,SET} "
-                  "ioctls will be removed in 2.6.42.\n");
-       uvc_printk(KERN_INFO, "See http://www.ideasonboard.org/uvc/upgrade/ "
-                  "for upgrade instructions.\n");
-       warned = 1;
-}
-
 static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
 {
        struct video_device *vdev = video_devdata(file);
@@ -1032,37 +1011,8 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
                uvc_trace(UVC_TRACE_IOCTL, "Unsupported ioctl 0x%08x\n", cmd);
                return -EINVAL;
 
-       /* Dynamic controls. UVCIOC_CTRL_ADD, UVCIOC_CTRL_MAP_OLD,
-        * UVCIOC_CTRL_GET and UVCIOC_CTRL_SET are deprecated and scheduled for
-        * removal in 2.6.42.
-        */
-       case __UVCIOC_CTRL_ADD:
-               uvc_v4l2_ioctl_warn();
-               return -EEXIST;
-
-       case __UVCIOC_CTRL_MAP_OLD:
-               uvc_v4l2_ioctl_warn();
-       case __UVCIOC_CTRL_MAP:
        case UVCIOC_CTRL_MAP:
-               return uvc_ioctl_ctrl_map(chain, arg,
-                                         cmd == __UVCIOC_CTRL_MAP_OLD);
-
-       case __UVCIOC_CTRL_GET:
-       case __UVCIOC_CTRL_SET:
-       {
-               struct uvc_xu_control *xctrl = arg;
-               struct uvc_xu_control_query xqry = {
-                       .unit           = xctrl->unit,
-                       .selector       = xctrl->selector,
-                       .query          = cmd == __UVCIOC_CTRL_GET
-                                       ? UVC_GET_CUR : UVC_SET_CUR,
-                       .size           = xctrl->size,
-                       .data           = xctrl->data,
-               };
-
-               uvc_v4l2_ioctl_warn();
-               return uvc_xu_ctrl_query(chain, &xqry);
-       }
+               return uvc_ioctl_ctrl_map(chain, arg);
 
        case UVCIOC_CTRL_QUERY:
                return uvc_xu_ctrl_query(chain, arg);
index ffd1158628b63ae0fa5a5db99e9a7a7f90a228a7..b015e8e5e8b08ad6ade229a02e63f2ea2396edaf 100644 (file)
@@ -790,8 +790,12 @@ static void uvc_free_urb_buffers(struct uvc_streaming *stream)
 
        for (i = 0; i < UVC_URBS; ++i) {
                if (stream->urb_buffer[i]) {
+#ifndef CONFIG_DMA_NONCOHERENT
                        usb_free_coherent(stream->dev->udev, stream->urb_size,
                                stream->urb_buffer[i], stream->urb_dma[i]);
+#else
+                       kfree(stream->urb_buffer[i]);
+#endif
                        stream->urb_buffer[i] = NULL;
                }
        }
@@ -831,9 +835,14 @@ static int uvc_alloc_urb_buffers(struct uvc_streaming *stream,
        for (; npackets > 1; npackets /= 2) {
                for (i = 0; i < UVC_URBS; ++i) {
                        stream->urb_size = psize * npackets;
+#ifndef CONFIG_DMA_NONCOHERENT
                        stream->urb_buffer[i] = usb_alloc_coherent(
                                stream->dev->udev, stream->urb_size,
                                gfp_flags | __GFP_NOWARN, &stream->urb_dma[i]);
+#else
+                       stream->urb_buffer[i] =
+                           kmalloc(stream->urb_size, gfp_flags | __GFP_NOWARN);
+#endif
                        if (!stream->urb_buffer[i]) {
                                uvc_free_urb_buffers(stream);
                                break;
@@ -908,10 +917,14 @@ static int uvc_init_video_isoc(struct uvc_streaming *stream,
                urb->context = stream;
                urb->pipe = usb_rcvisocpipe(stream->dev->udev,
                                ep->desc.bEndpointAddress);
+#ifndef CONFIG_DMA_NONCOHERENT
                urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
+               urb->transfer_dma = stream->urb_dma[i];
+#else
+               urb->transfer_flags = URB_ISO_ASAP;
+#endif
                urb->interval = ep->desc.bInterval;
                urb->transfer_buffer = stream->urb_buffer[i];
-               urb->transfer_dma = stream->urb_dma[i];
                urb->complete = uvc_video_complete;
                urb->number_of_packets = npackets;
                urb->transfer_buffer_length = size;
@@ -969,8 +982,10 @@ static int uvc_init_video_bulk(struct uvc_streaming *stream,
                usb_fill_bulk_urb(urb, stream->dev->udev, pipe,
                        stream->urb_buffer[i], size, uvc_video_complete,
                        stream);
+#ifndef CONFIG_DMA_NONCOHERENT
                urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
                urb->transfer_dma = stream->urb_dma[i];
+#endif
 
                stream->urb[i] = urb;
        }
index cbdd49bf8b67572eb35256d0cef6ba282586718d..4c1392ebcd4bd2634b245a23209f37c129e7be1f 100644 (file)
 #ifndef _USB_VIDEO_H_
 #define _USB_VIDEO_H_
 
-#include <linux/kernel.h>
-#include <linux/videodev2.h>
-
-#ifndef __KERNEL__
-/*
- * This header provides binary compatibility with applications using the private
- * uvcvideo API. This API is deprecated and will be removed in 2.6.42.
- * Applications should be recompiled against the public linux/uvcvideo.h header.
- */
-#warn "The uvcvideo.h header is deprecated, use linux/uvcvideo.h instead."
-
-/*
- * Dynamic controls
- */
-
-/* Data types for UVC control data */
-#define UVC_CTRL_DATA_TYPE_RAW         0
-#define UVC_CTRL_DATA_TYPE_SIGNED      1
-#define UVC_CTRL_DATA_TYPE_UNSIGNED    2
-#define UVC_CTRL_DATA_TYPE_BOOLEAN     3
-#define UVC_CTRL_DATA_TYPE_ENUM                4
-#define UVC_CTRL_DATA_TYPE_BITMASK     5
-
-/* Control flags */
-#define UVC_CONTROL_SET_CUR    (1 << 0)
-#define UVC_CONTROL_GET_CUR    (1 << 1)
-#define UVC_CONTROL_GET_MIN    (1 << 2)
-#define UVC_CONTROL_GET_MAX    (1 << 3)
-#define UVC_CONTROL_GET_RES    (1 << 4)
-#define UVC_CONTROL_GET_DEF    (1 << 5)
-#define UVC_CONTROL_RESTORE    (1 << 6)
-#define UVC_CONTROL_AUTO_UPDATE        (1 << 7)
-
-#define UVC_CONTROL_GET_RANGE  (UVC_CONTROL_GET_CUR | UVC_CONTROL_GET_MIN | \
-                                UVC_CONTROL_GET_MAX | UVC_CONTROL_GET_RES | \
-                                UVC_CONTROL_GET_DEF)
-
-struct uvc_menu_info {
-       __u32 value;
-       __u8 name[32];
-};
-
-struct uvc_xu_control_mapping {
-       __u32 id;
-       __u8 name[32];
-       __u8 entity[16];
-       __u8 selector;
-
-       __u8 size;
-       __u8 offset;
-       __u32 v4l2_type;
-       __u32 data_type;
-
-       struct uvc_menu_info __user *menu_info;
-       __u32 menu_count;
-
-       __u32 reserved[4];
-};
-
-#endif
-
-struct uvc_xu_control_info {
-       __u8 entity[16];
-       __u8 index;
-       __u8 selector;
-       __u16 size;
-       __u32 flags;
-};
-
-struct uvc_xu_control_mapping_old {
-       __u8 reserved[64];
-};
-
-struct uvc_xu_control {
-       __u8 unit;
-       __u8 selector;
-       __u16 size;
-       __u8 __user *data;
-};
-
 #ifndef __KERNEL__
-#define UVCIOC_CTRL_ADD                _IOW('U', 1, struct uvc_xu_control_info)
-#define UVCIOC_CTRL_MAP_OLD    _IOWR('U', 2, struct uvc_xu_control_mapping_old)
-#define UVCIOC_CTRL_MAP                _IOWR('U', 2, struct uvc_xu_control_mapping)
-#define UVCIOC_CTRL_GET                _IOWR('U', 3, struct uvc_xu_control)
-#define UVCIOC_CTRL_SET                _IOW('U', 4, struct uvc_xu_control)
-#else
-#define __UVCIOC_CTRL_ADD      _IOW('U', 1, struct uvc_xu_control_info)
-#define __UVCIOC_CTRL_MAP_OLD  _IOWR('U', 2, struct uvc_xu_control_mapping_old)
-#define __UVCIOC_CTRL_MAP      _IOWR('U', 2, struct uvc_xu_control_mapping)
-#define __UVCIOC_CTRL_GET      _IOWR('U', 3, struct uvc_xu_control)
-#define __UVCIOC_CTRL_SET      _IOW('U', 4, struct uvc_xu_control)
-#endif
-
-#ifdef __KERNEL__
+#error "The uvcvideo.h header is deprecated, use linux/uvcvideo.h instead."
+#endif /* __KERNEL__ */
 
+#include <linux/kernel.h>
 #include <linux/poll.h>
 #include <linux/usb.h>
 #include <linux/usb/video.h>
 #include <linux/uvcvideo.h>
+#include <linux/videodev2.h>
 #include <media/media-device.h>
 #include <media/v4l2-device.h>
 
@@ -179,6 +89,10 @@ struct uvc_xu_control {
        { 'M',  '4',  '2',  '0', 0x00, 0x00, 0x10, 0x00, \
         0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
 
+#define UVC_GUID_FORMAT_H264 \
+       { 'H',  '2',  '6',  '4', 0x00, 0x00, 0x10, 0x00, \
+        0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
+
 /* ------------------------------------------------------------------------
  * Driver specific constants.
  */
@@ -698,6 +612,4 @@ extern struct usb_host_endpoint *uvc_find_endpoint(
 void uvc_video_decode_isight(struct urb *urb, struct uvc_streaming *stream,
                struct uvc_buffer *buf);
 
-#endif /* __KERNEL__ */
-
 #endif
index 06b6014d4fb4cda5adb94c54a425c0b08b94019e..fc8666ae408fd5c0b79f98c6f004e921a065f130 100644 (file)
@@ -43,7 +43,7 @@ struct v4l2_ctrl_helper {
 };
 
 /* Small helper function to determine if the autocluster is set to manual
-   mode. In that case the is_volatile flag should be ignored. */
+   mode. */
 static bool is_cur_manual(const struct v4l2_ctrl *master)
 {
        return master->is_auto && master->cur.val == master->manual_mode_value;
@@ -937,9 +937,14 @@ static void new_to_cur(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl,
                break;
        }
        if (update_inactive) {
-               ctrl->flags &= ~V4L2_CTRL_FLAG_INACTIVE;
-               if (!is_cur_manual(ctrl->cluster[0]))
+               /* Note: update_inactive can only be true for auto clusters. */
+               ctrl->flags &=
+                       ~(V4L2_CTRL_FLAG_INACTIVE | V4L2_CTRL_FLAG_VOLATILE);
+               if (!is_cur_manual(ctrl->cluster[0])) {
                        ctrl->flags |= V4L2_CTRL_FLAG_INACTIVE;
+                       if (ctrl->cluster[0]->has_volatiles)
+                               ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
+               }
        }
        if (changed || update_inactive) {
                /* If a control was changed that was not one of the controls
@@ -1394,10 +1399,8 @@ struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
                        type, min, max,
                        is_menu ? cfg->menu_skip_mask : step,
                        def, flags, qmenu, priv);
-       if (ctrl) {
+       if (ctrl)
                ctrl->is_private = cfg->is_private;
-               ctrl->is_volatile = cfg->is_volatile;
-       }
        return ctrl;
 }
 EXPORT_SYMBOL(v4l2_ctrl_new_custom);
@@ -1491,6 +1494,7 @@ EXPORT_SYMBOL(v4l2_ctrl_add_handler);
 /* Cluster controls */
 void v4l2_ctrl_cluster(unsigned ncontrols, struct v4l2_ctrl **controls)
 {
+       bool has_volatiles = false;
        int i;
 
        /* The first control is the master control and it must not be NULL */
@@ -1500,8 +1504,11 @@ void v4l2_ctrl_cluster(unsigned ncontrols, struct v4l2_ctrl **controls)
                if (controls[i]) {
                        controls[i]->cluster = controls;
                        controls[i]->ncontrols = ncontrols;
+                       if (controls[i]->flags & V4L2_CTRL_FLAG_VOLATILE)
+                               has_volatiles = true;
                }
        }
+       controls[0]->has_volatiles = has_volatiles;
 }
 EXPORT_SYMBOL(v4l2_ctrl_cluster);
 
@@ -1509,22 +1516,25 @@ void v4l2_ctrl_auto_cluster(unsigned ncontrols, struct v4l2_ctrl **controls,
                            u8 manual_val, bool set_volatile)
 {
        struct v4l2_ctrl *master = controls[0];
-       u32 flag;
+       u32 flag = 0;
        int i;
 
        v4l2_ctrl_cluster(ncontrols, controls);
        WARN_ON(ncontrols <= 1);
        WARN_ON(manual_val < master->minimum || manual_val > master->maximum);
+       WARN_ON(set_volatile && !has_op(master, g_volatile_ctrl));
        master->is_auto = true;
+       master->has_volatiles = set_volatile;
        master->manual_mode_value = manual_val;
        master->flags |= V4L2_CTRL_FLAG_UPDATE;
-       flag = is_cur_manual(master) ? 0 : V4L2_CTRL_FLAG_INACTIVE;
+
+       if (!is_cur_manual(master))
+               flag = V4L2_CTRL_FLAG_INACTIVE |
+                       (set_volatile ? V4L2_CTRL_FLAG_VOLATILE : 0);
 
        for (i = 1; i < ncontrols; i++)
-               if (controls[i]) {
-                       controls[i]->is_volatile = set_volatile;
+               if (controls[i])
                        controls[i]->flags |= flag;
-               }
 }
 EXPORT_SYMBOL(v4l2_ctrl_auto_cluster);
 
@@ -1579,9 +1589,6 @@ EXPORT_SYMBOL(v4l2_ctrl_grab);
 static void log_ctrl(const struct v4l2_ctrl *ctrl,
                     const char *prefix, const char *colon)
 {
-       int fl_inact = ctrl->flags & V4L2_CTRL_FLAG_INACTIVE;
-       int fl_grabbed = ctrl->flags & V4L2_CTRL_FLAG_GRABBED;
-
        if (ctrl->flags & (V4L2_CTRL_FLAG_DISABLED | V4L2_CTRL_FLAG_WRITE_ONLY))
                return;
        if (ctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS)
@@ -1612,14 +1619,17 @@ static void log_ctrl(const struct v4l2_ctrl *ctrl,
                printk(KERN_CONT "unknown type %d", ctrl->type);
                break;
        }
-       if (fl_inact && fl_grabbed)
-               printk(KERN_CONT " (inactive, grabbed)\n");
-       else if (fl_inact)
-               printk(KERN_CONT " (inactive)\n");
-       else if (fl_grabbed)
-               printk(KERN_CONT " (grabbed)\n");
-       else
-               printk(KERN_CONT "\n");
+       if (ctrl->flags & (V4L2_CTRL_FLAG_INACTIVE |
+                          V4L2_CTRL_FLAG_GRABBED |
+                          V4L2_CTRL_FLAG_VOLATILE)) {
+               if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE)
+                       printk(KERN_CONT " inactive");
+               if (ctrl->flags & V4L2_CTRL_FLAG_GRABBED)
+                       printk(KERN_CONT " grabbed");
+               if (ctrl->flags & V4L2_CTRL_FLAG_VOLATILE)
+                       printk(KERN_CONT " volatile");
+       }
+       printk(KERN_CONT "\n");
 }
 
 /* Log all controls owned by the handler */
@@ -1959,7 +1969,8 @@ int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs
                v4l2_ctrl_lock(master);
 
                /* g_volatile_ctrl will update the new control values */
-               if (has_op(master, g_volatile_ctrl) && !is_cur_manual(master)) {
+               if ((master->flags & V4L2_CTRL_FLAG_VOLATILE) ||
+                       (master->has_volatiles && !is_cur_manual(master))) {
                        for (j = 0; j < master->ncontrols; j++)
                                cur_to_new(master->cluster[j]);
                        ret = call_op(master, g_volatile_ctrl);
@@ -2004,7 +2015,7 @@ static int get_ctrl(struct v4l2_ctrl *ctrl, s32 *val)
 
        v4l2_ctrl_lock(master);
        /* g_volatile_ctrl will update the current control values */
-       if (ctrl->is_volatile && !is_cur_manual(master)) {
+       if (ctrl->flags & V4L2_CTRL_FLAG_VOLATILE) {
                for (i = 0; i < master->ncontrols; i++)
                        cur_to_new(master->cluster[i]);
                ret = call_op(master, g_volatile_ctrl);
@@ -2120,6 +2131,20 @@ static int validate_ctrls(struct v4l2_ext_controls *cs,
        return 0;
 }
 
+/* Obtain the current volatile values of an autocluster and mark them
+   as new. */
+static void update_from_auto_cluster(struct v4l2_ctrl *master)
+{
+       int i;
+
+       for (i = 0; i < master->ncontrols; i++)
+               cur_to_new(master->cluster[i]);
+       if (!call_op(master, g_volatile_ctrl))
+               for (i = 1; i < master->ncontrols; i++)
+                       if (master->cluster[i])
+                               master->cluster[i]->is_new = 1;
+}
+
 /* Try or try-and-set controls */
 static int try_set_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
                             struct v4l2_ext_controls *cs,
@@ -2165,6 +2190,31 @@ static int try_set_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
                        if (master->cluster[j])
                                master->cluster[j]->is_new = 0;
 
+               /* For volatile autoclusters that are currently in auto mode
+                  we need to discover if it will be set to manual mode.
+                  If so, then we have to copy the current volatile values
+                  first since those will become the new manual values (which
+                  may be overwritten by explicit new values from this set
+                  of controls). */
+               if (master->is_auto && master->has_volatiles &&
+                                               !is_cur_manual(master)) {
+                       /* Pick an initial non-manual value */
+                       s32 new_auto_val = master->manual_mode_value + 1;
+                       u32 tmp_idx = idx;
+
+                       do {
+                               /* Check if the auto control is part of the
+                                  list, and remember the new value. */
+                               if (helpers[tmp_idx].ctrl == master)
+                                       new_auto_val = cs->controls[tmp_idx].value;
+                               tmp_idx = helpers[tmp_idx].next;
+                       } while (tmp_idx);
+                       /* If the new value == the manual value, then copy
+                          the current volatile values. */
+                       if (new_auto_val == master->manual_mode_value)
+                               update_from_auto_cluster(master);
+               }
+
                /* Copy the new caller-supplied control values.
                   user_to_new() sets 'is_new' to 1. */
                do {
@@ -2235,6 +2285,12 @@ static int set_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, s32 *val)
                if (master->cluster[i])
                        master->cluster[i]->is_new = 0;
 
+       /* For autoclusters with volatiles that are switched from auto to
+          manual mode we have to update the current volatile values since
+          those will become the initial manual values after such a switch. */
+       if (master->is_auto && master->has_volatiles && ctrl == master &&
+           !is_cur_manual(master) && *val == master->manual_mode_value)
+               update_from_auto_cluster(master);
        ctrl->val = *val;
        ctrl->is_new = 1;
        ret = try_or_set_cluster(fh, master, true);
index 002ce1363443338a714fca863f254968a224f6ee..24fd43322150e07d7fe1d24a07a2e1320d64a167 100644 (file)
        memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
        0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
 
+#define have_fmt_ops(foo) (                                            \
+       ops->vidioc_##foo##_fmt_vid_cap ||                              \
+       ops->vidioc_##foo##_fmt_vid_out ||                              \
+       ops->vidioc_##foo##_fmt_vid_cap_mplane ||                       \
+       ops->vidioc_##foo##_fmt_vid_out_mplane ||                       \
+       ops->vidioc_##foo##_fmt_vid_overlay ||                          \
+       ops->vidioc_##foo##_fmt_vbi_cap ||                              \
+       ops->vidioc_##foo##_fmt_vid_out_overlay ||                      \
+       ops->vidioc_##foo##_fmt_vbi_out ||                              \
+       ops->vidioc_##foo##_fmt_sliced_vbi_cap ||                       \
+       ops->vidioc_##foo##_fmt_sliced_vbi_out ||                       \
+       ops->vidioc_##foo##_fmt_type_private)
+
 struct std_descr {
        v4l2_std_id std;
        const char *descr;
@@ -477,63 +490,6 @@ static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
        return -EINVAL;
 }
 
-/**
- * fmt_sp_to_mp() - Convert a single-plane format to its multi-planar 1-plane
- * equivalent
- */
-static int fmt_sp_to_mp(const struct v4l2_format *f_sp,
-                       struct v4l2_format *f_mp)
-{
-       struct v4l2_pix_format_mplane *pix_mp = &f_mp->fmt.pix_mp;
-       const struct v4l2_pix_format *pix = &f_sp->fmt.pix;
-
-       if (f_sp->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
-               f_mp->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
-       else if (f_sp->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
-               f_mp->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
-       else
-               return -EINVAL;
-
-       pix_mp->width = pix->width;
-       pix_mp->height = pix->height;
-       pix_mp->pixelformat = pix->pixelformat;
-       pix_mp->field = pix->field;
-       pix_mp->colorspace = pix->colorspace;
-       pix_mp->num_planes = 1;
-       pix_mp->plane_fmt[0].sizeimage = pix->sizeimage;
-       pix_mp->plane_fmt[0].bytesperline = pix->bytesperline;
-
-       return 0;
-}
-
-/**
- * fmt_mp_to_sp() - Convert a multi-planar 1-plane format to its single-planar
- * equivalent
- */
-static int fmt_mp_to_sp(const struct v4l2_format *f_mp,
-                       struct v4l2_format *f_sp)
-{
-       const struct v4l2_pix_format_mplane *pix_mp = &f_mp->fmt.pix_mp;
-       struct v4l2_pix_format *pix = &f_sp->fmt.pix;
-
-       if (f_mp->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
-               f_sp->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-       else if (f_mp->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
-               f_sp->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
-       else
-               return -EINVAL;
-
-       pix->width = pix_mp->width;
-       pix->height = pix_mp->height;
-       pix->pixelformat = pix_mp->pixelformat;
-       pix->field = pix_mp->field;
-       pix->colorspace = pix_mp->colorspace;
-       pix->sizeimage = pix_mp->plane_fmt[0].sizeimage;
-       pix->bytesperline = pix_mp->plane_fmt[0].bytesperline;
-
-       return 0;
-}
-
 static long __video_do_ioctl(struct file *file,
                unsigned int cmd, void *arg)
 {
@@ -541,8 +497,8 @@ static long __video_do_ioctl(struct file *file,
        const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
        void *fh = file->private_data;
        struct v4l2_fh *vfh = NULL;
-       struct v4l2_format f_copy;
        int use_fh_prio = 0;
+       long ret_prio = 0;
        long ret = -ENOTTY;
 
        if (ops == NULL) {
@@ -562,39 +518,8 @@ static long __video_do_ioctl(struct file *file,
                use_fh_prio = test_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
        }
 
-       if (use_fh_prio) {
-               switch (cmd) {
-               case VIDIOC_S_CTRL:
-               case VIDIOC_S_STD:
-               case VIDIOC_S_INPUT:
-               case VIDIOC_S_OUTPUT:
-               case VIDIOC_S_TUNER:
-               case VIDIOC_S_FREQUENCY:
-               case VIDIOC_S_FMT:
-               case VIDIOC_S_CROP:
-               case VIDIOC_S_AUDIO:
-               case VIDIOC_S_AUDOUT:
-               case VIDIOC_S_EXT_CTRLS:
-               case VIDIOC_S_FBUF:
-               case VIDIOC_S_PRIORITY:
-               case VIDIOC_S_DV_PRESET:
-               case VIDIOC_S_DV_TIMINGS:
-               case VIDIOC_S_JPEGCOMP:
-               case VIDIOC_S_MODULATOR:
-               case VIDIOC_S_PARM:
-               case VIDIOC_S_HW_FREQ_SEEK:
-               case VIDIOC_ENCODER_CMD:
-               case VIDIOC_OVERLAY:
-               case VIDIOC_REQBUFS:
-               case VIDIOC_STREAMON:
-               case VIDIOC_STREAMOFF:
-                       ret = v4l2_prio_check(vfd->prio, vfh->prio);
-                       if (ret)
-                               goto exit_prio;
-                       ret = -EINVAL;
-                       break;
-               }
-       }
+       if (use_fh_prio)
+               ret_prio = v4l2_prio_check(vfd->prio, vfh->prio);
 
        switch (cmd) {
 
@@ -638,12 +563,14 @@ static long __video_do_ioctl(struct file *file,
                enum v4l2_priority *p = arg;
 
                if (!ops->vidioc_s_priority && !use_fh_prio)
-                               break;
+                       break;
                dbgarg(cmd, "setting priority to %d\n", *p);
                if (ops->vidioc_s_priority)
                        ret = ops->vidioc_s_priority(file, fh, *p);
                else
-                       ret = v4l2_prio_change(&vfd->v4l2_dev->prio, &vfh->prio, *p);
+                       ret = ret_prio ? ret_prio :
+                               v4l2_prio_change(&vfd->v4l2_dev->prio,
+                                                       &vfh->prio, *p);
                break;
        }
 
@@ -654,37 +581,37 @@ static long __video_do_ioctl(struct file *file,
 
                switch (f->type) {
                case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-                       if (ops->vidioc_enum_fmt_vid_cap)
+                       if (likely(ops->vidioc_enum_fmt_vid_cap))
                                ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f);
                        break;
                case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
-                       if (ops->vidioc_enum_fmt_vid_cap_mplane)
+                       if (likely(ops->vidioc_enum_fmt_vid_cap_mplane))
                                ret = ops->vidioc_enum_fmt_vid_cap_mplane(file,
                                                                        fh, f);
                        break;
                case V4L2_BUF_TYPE_VIDEO_OVERLAY:
-                       if (ops->vidioc_enum_fmt_vid_overlay)
+                       if (likely(ops->vidioc_enum_fmt_vid_overlay))
                                ret = ops->vidioc_enum_fmt_vid_overlay(file,
                                        fh, f);
                        break;
                case V4L2_BUF_TYPE_VIDEO_OUTPUT:
-                       if (ops->vidioc_enum_fmt_vid_out)
+                       if (likely(ops->vidioc_enum_fmt_vid_out))
                                ret = ops->vidioc_enum_fmt_vid_out(file, fh, f);
                        break;
                case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
-                       if (ops->vidioc_enum_fmt_vid_out_mplane)
+                       if (likely(ops->vidioc_enum_fmt_vid_out_mplane))
                                ret = ops->vidioc_enum_fmt_vid_out_mplane(file,
                                                                        fh, f);
                        break;
                case V4L2_BUF_TYPE_PRIVATE:
-                       if (ops->vidioc_enum_fmt_type_private)
+                       if (likely(ops->vidioc_enum_fmt_type_private))
                                ret = ops->vidioc_enum_fmt_type_private(file,
                                                                fh, f);
                        break;
                default:
                        break;
                }
-               if (!ret)
+               if (likely (!ret))
                        dbgarg(cmd, "index=%d, type=%d, flags=%d, "
                                "pixelformat=%c%c%c%c, description='%s'\n",
                                f->index, f->type, f->flags,
@@ -693,6 +620,14 @@ static long __video_do_ioctl(struct file *file,
                                (f->pixelformat >> 16) & 0xff,
                                (f->pixelformat >> 24) & 0xff,
                                f->description);
+               else if (ret == -ENOTTY &&
+                        (ops->vidioc_enum_fmt_vid_cap ||
+                         ops->vidioc_enum_fmt_vid_out ||
+                         ops->vidioc_enum_fmt_vid_cap_mplane ||
+                         ops->vidioc_enum_fmt_vid_out_mplane ||
+                         ops->vidioc_enum_fmt_vid_overlay ||
+                         ops->vidioc_enum_fmt_type_private))
+                       ret = -EINVAL;
                break;
        }
        case VIDIOC_G_FMT:
@@ -704,119 +639,67 @@ static long __video_do_ioctl(struct file *file,
 
                switch (f->type) {
                case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-                       if (ops->vidioc_g_fmt_vid_cap) {
+                       if (ops->vidioc_g_fmt_vid_cap)
                                ret = ops->vidioc_g_fmt_vid_cap(file, fh, f);
-                       } else if (ops->vidioc_g_fmt_vid_cap_mplane) {
-                               if (fmt_sp_to_mp(f, &f_copy))
-                                       break;
-                               ret = ops->vidioc_g_fmt_vid_cap_mplane(file, fh,
-                                                                      &f_copy);
-                               if (ret)
-                                       break;
-
-                               /* Driver is currently in multi-planar format,
-                                * we can't return it in single-planar API*/
-                               if (f_copy.fmt.pix_mp.num_planes > 1) {
-                                       ret = -EBUSY;
-                                       break;
-                               }
-
-                               ret = fmt_mp_to_sp(&f_copy, f);
-                       }
                        if (!ret)
                                v4l_print_pix_fmt(vfd, &f->fmt.pix);
                        break;
                case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
-                       if (ops->vidioc_g_fmt_vid_cap_mplane) {
+                       if (ops->vidioc_g_fmt_vid_cap_mplane)
                                ret = ops->vidioc_g_fmt_vid_cap_mplane(file,
                                                                        fh, f);
-                       } else if (ops->vidioc_g_fmt_vid_cap) {
-                               if (fmt_mp_to_sp(f, &f_copy))
-                                       break;
-                               ret = ops->vidioc_g_fmt_vid_cap(file,
-                                                               fh, &f_copy);
-                               if (ret)
-                                       break;
-
-                               ret = fmt_sp_to_mp(&f_copy, f);
-                       }
                        if (!ret)
                                v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
                        break;
                case V4L2_BUF_TYPE_VIDEO_OVERLAY:
-                       if (ops->vidioc_g_fmt_vid_overlay)
+                       if (likely(ops->vidioc_g_fmt_vid_overlay))
                                ret = ops->vidioc_g_fmt_vid_overlay(file,
                                                                    fh, f);
                        break;
                case V4L2_BUF_TYPE_VIDEO_OUTPUT:
-                       if (ops->vidioc_g_fmt_vid_out) {
+                       if (ops->vidioc_g_fmt_vid_out)
                                ret = ops->vidioc_g_fmt_vid_out(file, fh, f);
-                       } else if (ops->vidioc_g_fmt_vid_out_mplane) {
-                               if (fmt_sp_to_mp(f, &f_copy))
-                                       break;
-                               ret = ops->vidioc_g_fmt_vid_out_mplane(file, fh,
-                                                                       &f_copy);
-                               if (ret)
-                                       break;
-
-                               /* Driver is currently in multi-planar format,
-                                * we can't return it in single-planar API*/
-                               if (f_copy.fmt.pix_mp.num_planes > 1) {
-                                       ret = -EBUSY;
-                                       break;
-                               }
-
-                               ret = fmt_mp_to_sp(&f_copy, f);
-                       }
                        if (!ret)
                                v4l_print_pix_fmt(vfd, &f->fmt.pix);
                        break;
                case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
-                       if (ops->vidioc_g_fmt_vid_out_mplane) {
+                       if (ops->vidioc_g_fmt_vid_out_mplane)
                                ret = ops->vidioc_g_fmt_vid_out_mplane(file,
                                                                        fh, f);
-                       } else if (ops->vidioc_g_fmt_vid_out) {
-                               if (fmt_mp_to_sp(f, &f_copy))
-                                       break;
-                               ret = ops->vidioc_g_fmt_vid_out(file,
-                                                               fh, &f_copy);
-                               if (ret)
-                                       break;
-
-                               ret = fmt_sp_to_mp(&f_copy, f);
-                       }
                        if (!ret)
                                v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
                        break;
                case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
-                       if (ops->vidioc_g_fmt_vid_out_overlay)
+                       if (likely(ops->vidioc_g_fmt_vid_out_overlay))
                                ret = ops->vidioc_g_fmt_vid_out_overlay(file,
                                       fh, f);
                        break;
                case V4L2_BUF_TYPE_VBI_CAPTURE:
-                       if (ops->vidioc_g_fmt_vbi_cap)
+                       if (likely(ops->vidioc_g_fmt_vbi_cap))
                                ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f);
                        break;
                case V4L2_BUF_TYPE_VBI_OUTPUT:
-                       if (ops->vidioc_g_fmt_vbi_out)
+                       if (likely(ops->vidioc_g_fmt_vbi_out))
                                ret = ops->vidioc_g_fmt_vbi_out(file, fh, f);
                        break;
                case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
-                       if (ops->vidioc_g_fmt_sliced_vbi_cap)
+                       if (likely(ops->vidioc_g_fmt_sliced_vbi_cap))
                                ret = ops->vidioc_g_fmt_sliced_vbi_cap(file,
                                                                        fh, f);
                        break;
                case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
-                       if (ops->vidioc_g_fmt_sliced_vbi_out)
+                       if (likely(ops->vidioc_g_fmt_sliced_vbi_out))
                                ret = ops->vidioc_g_fmt_sliced_vbi_out(file,
                                                                        fh, f);
                        break;
                case V4L2_BUF_TYPE_PRIVATE:
-                       if (ops->vidioc_g_fmt_type_private)
+                       if (likely(ops->vidioc_g_fmt_type_private))
                                ret = ops->vidioc_g_fmt_type_private(file,
                                                                fh, f);
                        break;
                }
+               if (unlikely(ret == -ENOTTY && have_fmt_ops(g)))
+                       ret = -EINVAL;
 
                break;
        }
@@ -824,6 +707,14 @@ static long __video_do_ioctl(struct file *file,
        {
                struct v4l2_format *f = (struct v4l2_format *)arg;
 
+               if (!have_fmt_ops(s))
+                       break;
+               if (ret_prio) {
+                       ret = ret_prio;
+                       break;
+               }
+               ret = -EINVAL;
+
                /* FIXME: Should be one dump per type */
                dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
 
@@ -831,44 +722,15 @@ static long __video_do_ioctl(struct file *file,
                case V4L2_BUF_TYPE_VIDEO_CAPTURE:
                        CLEAR_AFTER_FIELD(f, fmt.pix);
                        v4l_print_pix_fmt(vfd, &f->fmt.pix);
-                       if (ops->vidioc_s_fmt_vid_cap) {
+                       if (ops->vidioc_s_fmt_vid_cap)
                                ret = ops->vidioc_s_fmt_vid_cap(file, fh, f);
-                       } else if (ops->vidioc_s_fmt_vid_cap_mplane) {
-                               if (fmt_sp_to_mp(f, &f_copy))
-                                       break;
-                               ret = ops->vidioc_s_fmt_vid_cap_mplane(file, fh,
-                                                                       &f_copy);
-                               if (ret)
-                                       break;
-
-                               if (f_copy.fmt.pix_mp.num_planes > 1) {
-                                       /* Drivers shouldn't adjust from 1-plane
-                                        * to more than 1-plane formats */
-                                       ret = -EBUSY;
-                                       WARN_ON(1);
-                                       break;
-                               }
-
-                               ret = fmt_mp_to_sp(&f_copy, f);
-                       }
                        break;
                case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
                        CLEAR_AFTER_FIELD(f, fmt.pix_mp);
                        v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
-                       if (ops->vidioc_s_fmt_vid_cap_mplane) {
+                       if (ops->vidioc_s_fmt_vid_cap_mplane)
                                ret = ops->vidioc_s_fmt_vid_cap_mplane(file,
                                                                        fh, f);
-                       } else if (ops->vidioc_s_fmt_vid_cap &&
-                                       f->fmt.pix_mp.num_planes == 1) {
-                               if (fmt_mp_to_sp(f, &f_copy))
-                                       break;
-                               ret = ops->vidioc_s_fmt_vid_cap(file,
-                                                               fh, &f_copy);
-                               if (ret)
-                                       break;
-
-                               ret = fmt_sp_to_mp(&f_copy, f);
-                       }
                        break;
                case V4L2_BUF_TYPE_VIDEO_OVERLAY:
                        CLEAR_AFTER_FIELD(f, fmt.win);
@@ -879,44 +741,15 @@ static long __video_do_ioctl(struct file *file,
                case V4L2_BUF_TYPE_VIDEO_OUTPUT:
                        CLEAR_AFTER_FIELD(f, fmt.pix);
                        v4l_print_pix_fmt(vfd, &f->fmt.pix);
-                       if (ops->vidioc_s_fmt_vid_out) {
+                       if (ops->vidioc_s_fmt_vid_out)
                                ret = ops->vidioc_s_fmt_vid_out(file, fh, f);
-                       } else if (ops->vidioc_s_fmt_vid_out_mplane) {
-                               if (fmt_sp_to_mp(f, &f_copy))
-                                       break;
-                               ret = ops->vidioc_s_fmt_vid_out_mplane(file, fh,
-                                                                       &f_copy);
-                               if (ret)
-                                       break;
-
-                               if (f_copy.fmt.pix_mp.num_planes > 1) {
-                                       /* Drivers shouldn't adjust from 1-plane
-                                        * to more than 1-plane formats */
-                                       ret = -EBUSY;
-                                       WARN_ON(1);
-                                       break;
-                               }
-
-                               ret = fmt_mp_to_sp(&f_copy, f);
-                       }
                        break;
                case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
                        CLEAR_AFTER_FIELD(f, fmt.pix_mp);
                        v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
-                       if (ops->vidioc_s_fmt_vid_out_mplane) {
+                       if (ops->vidioc_s_fmt_vid_out_mplane)
                                ret = ops->vidioc_s_fmt_vid_out_mplane(file,
                                                                        fh, f);
-                       } else if (ops->vidioc_s_fmt_vid_out &&
-                                       f->fmt.pix_mp.num_planes == 1) {
-                               if (fmt_mp_to_sp(f, &f_copy))
-                                       break;
-                               ret = ops->vidioc_s_fmt_vid_out(file,
-                                                               fh, &f_copy);
-                               if (ret)
-                                       break;
-
-                               ret = fmt_mp_to_sp(&f_copy, f);
-                       }
                        break;
                case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
                        CLEAR_AFTER_FIELD(f, fmt.win);
@@ -926,29 +759,30 @@ static long __video_do_ioctl(struct file *file,
                        break;
                case V4L2_BUF_TYPE_VBI_CAPTURE:
                        CLEAR_AFTER_FIELD(f, fmt.vbi);
-                       if (ops->vidioc_s_fmt_vbi_cap)
+                       if (likely(ops->vidioc_s_fmt_vbi_cap))
                                ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f);
                        break;
                case V4L2_BUF_TYPE_VBI_OUTPUT:
                        CLEAR_AFTER_FIELD(f, fmt.vbi);
-                       if (ops->vidioc_s_fmt_vbi_out)
+                       if (likely(ops->vidioc_s_fmt_vbi_out))
                                ret = ops->vidioc_s_fmt_vbi_out(file, fh, f);
                        break;
                case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
                        CLEAR_AFTER_FIELD(f, fmt.sliced);
-                       if (ops->vidioc_s_fmt_sliced_vbi_cap)
+                       if (likely(ops->vidioc_s_fmt_sliced_vbi_cap))
                                ret = ops->vidioc_s_fmt_sliced_vbi_cap(file,
                                                                        fh, f);
                        break;
                case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
                        CLEAR_AFTER_FIELD(f, fmt.sliced);
-                       if (ops->vidioc_s_fmt_sliced_vbi_out)
+                       if (likely(ops->vidioc_s_fmt_sliced_vbi_out))
                                ret = ops->vidioc_s_fmt_sliced_vbi_out(file,
                                                                        fh, f);
+
                        break;
                case V4L2_BUF_TYPE_PRIVATE:
                        /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
-                       if (ops->vidioc_s_fmt_type_private)
+                       if (likely(ops->vidioc_s_fmt_type_private))
                                ret = ops->vidioc_s_fmt_type_private(file,
                                                                fh, f);
                        break;
@@ -965,132 +799,77 @@ static long __video_do_ioctl(struct file *file,
                switch (f->type) {
                case V4L2_BUF_TYPE_VIDEO_CAPTURE:
                        CLEAR_AFTER_FIELD(f, fmt.pix);
-                       if (ops->vidioc_try_fmt_vid_cap) {
+                       if (ops->vidioc_try_fmt_vid_cap)
                                ret = ops->vidioc_try_fmt_vid_cap(file, fh, f);
-                       } else if (ops->vidioc_try_fmt_vid_cap_mplane) {
-                               if (fmt_sp_to_mp(f, &f_copy))
-                                       break;
-                               ret = ops->vidioc_try_fmt_vid_cap_mplane(file,
-                                                               fh, &f_copy);
-                               if (ret)
-                                       break;
-
-                               if (f_copy.fmt.pix_mp.num_planes > 1) {
-                                       /* Drivers shouldn't adjust from 1-plane
-                                        * to more than 1-plane formats */
-                                       ret = -EBUSY;
-                                       WARN_ON(1);
-                                       break;
-                               }
-                               ret = fmt_mp_to_sp(&f_copy, f);
-                       }
                        if (!ret)
                                v4l_print_pix_fmt(vfd, &f->fmt.pix);
                        break;
                case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
                        CLEAR_AFTER_FIELD(f, fmt.pix_mp);
-                       if (ops->vidioc_try_fmt_vid_cap_mplane) {
+                       if (ops->vidioc_try_fmt_vid_cap_mplane)
                                ret = ops->vidioc_try_fmt_vid_cap_mplane(file,
                                                                         fh, f);
-                       } else if (ops->vidioc_try_fmt_vid_cap &&
-                                       f->fmt.pix_mp.num_planes == 1) {
-                               if (fmt_mp_to_sp(f, &f_copy))
-                                       break;
-                               ret = ops->vidioc_try_fmt_vid_cap(file,
-                                                                 fh, &f_copy);
-                               if (ret)
-                                       break;
-
-                               ret = fmt_sp_to_mp(&f_copy, f);
-                       }
                        if (!ret)
                                v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
                        break;
                case V4L2_BUF_TYPE_VIDEO_OVERLAY:
                        CLEAR_AFTER_FIELD(f, fmt.win);
-                       if (ops->vidioc_try_fmt_vid_overlay)
+                       if (likely(ops->vidioc_try_fmt_vid_overlay))
                                ret = ops->vidioc_try_fmt_vid_overlay(file,
                                        fh, f);
                        break;
                case V4L2_BUF_TYPE_VIDEO_OUTPUT:
                        CLEAR_AFTER_FIELD(f, fmt.pix);
-                       if (ops->vidioc_try_fmt_vid_out) {
+                       if (ops->vidioc_try_fmt_vid_out)
                                ret = ops->vidioc_try_fmt_vid_out(file, fh, f);
-                       } else if (ops->vidioc_try_fmt_vid_out_mplane) {
-                               if (fmt_sp_to_mp(f, &f_copy))
-                                       break;
-                               ret = ops->vidioc_try_fmt_vid_out_mplane(file,
-                                                               fh, &f_copy);
-                               if (ret)
-                                       break;
-
-                               if (f_copy.fmt.pix_mp.num_planes > 1) {
-                                       /* Drivers shouldn't adjust from 1-plane
-                                        * to more than 1-plane formats */
-                                       ret = -EBUSY;
-                                       WARN_ON(1);
-                                       break;
-                               }
-                               ret = fmt_mp_to_sp(&f_copy, f);
-                       }
                        if (!ret)
                                v4l_print_pix_fmt(vfd, &f->fmt.pix);
                        break;
                case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
                        CLEAR_AFTER_FIELD(f, fmt.pix_mp);
-                       if (ops->vidioc_try_fmt_vid_out_mplane) {
+                       if (ops->vidioc_try_fmt_vid_out_mplane)
                                ret = ops->vidioc_try_fmt_vid_out_mplane(file,
                                                                         fh, f);
-                       } else if (ops->vidioc_try_fmt_vid_out &&
-                                       f->fmt.pix_mp.num_planes == 1) {
-                               if (fmt_mp_to_sp(f, &f_copy))
-                                       break;
-                               ret = ops->vidioc_try_fmt_vid_out(file,
-                                                                 fh, &f_copy);
-                               if (ret)
-                                       break;
-
-                               ret = fmt_sp_to_mp(&f_copy, f);
-                       }
                        if (!ret)
                                v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
                        break;
                case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
                        CLEAR_AFTER_FIELD(f, fmt.win);
-                       if (ops->vidioc_try_fmt_vid_out_overlay)
+                       if (likely(ops->vidioc_try_fmt_vid_out_overlay))
                                ret = ops->vidioc_try_fmt_vid_out_overlay(file,
                                       fh, f);
                        break;
                case V4L2_BUF_TYPE_VBI_CAPTURE:
                        CLEAR_AFTER_FIELD(f, fmt.vbi);
-                       if (ops->vidioc_try_fmt_vbi_cap)
+                       if (likely(ops->vidioc_try_fmt_vbi_cap))
                                ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f);
                        break;
                case V4L2_BUF_TYPE_VBI_OUTPUT:
                        CLEAR_AFTER_FIELD(f, fmt.vbi);
-                       if (ops->vidioc_try_fmt_vbi_out)
+                       if (likely(ops->vidioc_try_fmt_vbi_out))
                                ret = ops->vidioc_try_fmt_vbi_out(file, fh, f);
                        break;
                case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
                        CLEAR_AFTER_FIELD(f, fmt.sliced);
-                       if (ops->vidioc_try_fmt_sliced_vbi_cap)
+                       if (likely(ops->vidioc_try_fmt_sliced_vbi_cap))
                                ret = ops->vidioc_try_fmt_sliced_vbi_cap(file,
                                                                fh, f);
                        break;
                case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
                        CLEAR_AFTER_FIELD(f, fmt.sliced);
-                       if (ops->vidioc_try_fmt_sliced_vbi_out)
+                       if (likely(ops->vidioc_try_fmt_sliced_vbi_out))
                                ret = ops->vidioc_try_fmt_sliced_vbi_out(file,
                                                                fh, f);
                        break;
                case V4L2_BUF_TYPE_PRIVATE:
                        /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
-                       if (ops->vidioc_try_fmt_type_private)
+                       if (likely(ops->vidioc_try_fmt_type_private))
                                ret = ops->vidioc_try_fmt_type_private(file,
                                                                fh, f);
                        break;
                }
-
+               if (unlikely(ret == -ENOTTY && have_fmt_ops(try)))
+                       ret = -EINVAL;
                break;
        }
        /* FIXME: Those buf reqs could be handled here,
@@ -1103,6 +882,10 @@ static long __video_do_ioctl(struct file *file,
 
                if (!ops->vidioc_reqbufs)
                        break;
+               if (ret_prio) {
+                       ret = ret_prio;
+                       break;
+               }
                ret = check_fmt(ops, p->type);
                if (ret)
                        break;
@@ -1168,6 +951,10 @@ static long __video_do_ioctl(struct file *file,
 
                if (!ops->vidioc_overlay)
                        break;
+               if (ret_prio) {
+                       ret = ret_prio;
+                       break;
+               }
                dbgarg(cmd, "value=%d\n", *i);
                ret = ops->vidioc_overlay(file, fh, *i);
                break;
@@ -1193,6 +980,10 @@ static long __video_do_ioctl(struct file *file,
 
                if (!ops->vidioc_s_fbuf)
                        break;
+               if (ret_prio) {
+                       ret = ret_prio;
+                       break;
+               }
                dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
                        p->capability, p->flags, (unsigned long)p->base);
                v4l_print_pix_fmt(vfd, &p->fmt);
@@ -1205,6 +996,10 @@ static long __video_do_ioctl(struct file *file,
 
                if (!ops->vidioc_streamon)
                        break;
+               if (ret_prio) {
+                       ret = ret_prio;
+                       break;
+               }
                dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
                ret = ops->vidioc_streamon(file, fh, i);
                break;
@@ -1215,6 +1010,10 @@ static long __video_do_ioctl(struct file *file,
 
                if (!ops->vidioc_streamoff)
                        break;
+               if (ret_prio) {
+                       ret = ret_prio;
+                       break;
+               }
                dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
                ret = ops->vidioc_streamoff(file, fh, i);
                break;
@@ -1227,6 +1026,10 @@ static long __video_do_ioctl(struct file *file,
                unsigned int index = p->index, i, j = 0;
                const char *descr = "";
 
+               if (id == 0)
+                       break;
+               ret = -EINVAL;
+
                /* Return norm array in a canonical way */
                for (i = 0; i <= index && id; i++) {
                        /* last std value in the standards array is 0, so this
@@ -1262,16 +1065,15 @@ static long __video_do_ioctl(struct file *file,
        {
                v4l2_std_id *id = arg;
 
-               ret = 0;
                /* Calls the specific handler */
                if (ops->vidioc_g_std)
                        ret = ops->vidioc_g_std(file, fh, id);
-               else if (vfd->current_norm)
+               else if (vfd->current_norm) {
+                       ret = 0;
                        *id = vfd->current_norm;
-               else
-                       ret = -EINVAL;
+               }
 
-               if (!ret)
+               if (likely(!ret))
                        dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
                break;
        }
@@ -1281,15 +1083,20 @@ static long __video_do_ioctl(struct file *file,
 
                dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
 
+               if (!ops->vidioc_s_std)
+                       break;
+
+               if (ret_prio) {
+                       ret = ret_prio;
+                       break;
+               }
+               ret = -EINVAL;
                norm = (*id) & vfd->tvnorms;
                if (vfd->tvnorms && !norm)      /* Check if std is supported */
                        break;
 
                /* Calls the specific handler */
-               if (ops->vidioc_s_std)
-                       ret = ops->vidioc_s_std(file, fh, &norm);
-               else
-                       ret = -EINVAL;
+               ret = ops->vidioc_s_std(file, fh, &norm);
 
                /* Updates standard information */
                if (ret >= 0)
@@ -1302,6 +1109,14 @@ static long __video_do_ioctl(struct file *file,
 
                if (!ops->vidioc_querystd)
                        break;
+               /*
+                * If nothing detected, it should return all supported
+                * Drivers just need to mask the std argument, in order
+                * to remove the standards that don't apply from the mask.
+                * This means that tuners, audio and video decoders can join
+                * their efforts to improve the standards detection
+                */
+               *p = vfd->tvnorms;
                ret = ops->vidioc_querystd(file, fh, arg);
                if (!ret)
                        dbgarg(cmd, "detected std=%08Lx\n",
@@ -1358,6 +1173,10 @@ static long __video_do_ioctl(struct file *file,
 
                if (!ops->vidioc_s_input)
                        break;
+               if (ret_prio) {
+                       ret = ret_prio;
+                       break;
+               }
                dbgarg(cmd, "value=%d\n", *i);
                ret = ops->vidioc_s_input(file, fh, *i);
                break;
@@ -1410,6 +1229,10 @@ static long __video_do_ioctl(struct file *file,
 
                if (!ops->vidioc_s_output)
                        break;
+               if (ret_prio) {
+                       ret = ret_prio;
+                       break;
+               }
                dbgarg(cmd, "value=%d\n", *i);
                ret = ops->vidioc_s_output(file, fh, *i);
                break;
@@ -1479,6 +1302,10 @@ static long __video_do_ioctl(struct file *file,
                if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
                        !ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
                        break;
+               if (ret_prio) {
+                       ret = ret_prio;
+                       break;
+               }
 
                dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
 
@@ -1504,6 +1331,8 @@ static long __video_do_ioctl(struct file *file,
                ctrl.value = p->value;
                if (check_ext_ctrls(&ctrls, 1))
                        ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
+               else
+                       ret = -EINVAL;
                break;
        }
        case VIDIOC_G_EXT_CTRLS:
@@ -1515,8 +1344,10 @@ static long __video_do_ioctl(struct file *file,
                        ret = v4l2_g_ext_ctrls(vfh->ctrl_handler, p);
                else if (vfd->ctrl_handler)
                        ret = v4l2_g_ext_ctrls(vfd->ctrl_handler, p);
-               else if (ops->vidioc_g_ext_ctrls && check_ext_ctrls(p, 0))
-                       ret = ops->vidioc_g_ext_ctrls(file, fh, p);
+               else if (ops->vidioc_g_ext_ctrls)
+                       ret = check_ext_ctrls(p, 0) ?
+                               ops->vidioc_g_ext_ctrls(file, fh, p) :
+                               -EINVAL;
                else
                        break;
                v4l_print_ext_ctrls(cmd, vfd, p, !ret);
@@ -1530,6 +1361,10 @@ static long __video_do_ioctl(struct file *file,
                if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
                                !ops->vidioc_s_ext_ctrls)
                        break;
+               if (ret_prio) {
+                       ret = ret_prio;
+                       break;
+               }
                v4l_print_ext_ctrls(cmd, vfd, p, 1);
                if (vfh && vfh->ctrl_handler)
                        ret = v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, p);
@@ -1537,6 +1372,8 @@ static long __video_do_ioctl(struct file *file,
                        ret = v4l2_s_ext_ctrls(NULL, vfd->ctrl_handler, p);
                else if (check_ext_ctrls(p, 0))
                        ret = ops->vidioc_s_ext_ctrls(file, fh, p);
+               else
+                       ret = -EINVAL;
                break;
        }
        case VIDIOC_TRY_EXT_CTRLS:
@@ -1554,6 +1391,8 @@ static long __video_do_ioctl(struct file *file,
                        ret = v4l2_try_ext_ctrls(vfd->ctrl_handler, p);
                else if (check_ext_ctrls(p, 0))
                        ret = ops->vidioc_try_ext_ctrls(file, fh, p);
+               else
+                       ret = -EINVAL;
                break;
        }
        case VIDIOC_QUERYMENU:
@@ -1614,6 +1453,10 @@ static long __video_do_ioctl(struct file *file,
 
                if (!ops->vidioc_s_audio)
                        break;
+               if (ret_prio) {
+                       ret = ret_prio;
+                       break;
+               }
                dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
                                        "mode=0x%x\n", p->index, p->name,
                                        p->capability, p->mode);
@@ -1654,6 +1497,10 @@ static long __video_do_ioctl(struct file *file,
 
                if (!ops->vidioc_s_audout)
                        break;
+               if (ret_prio) {
+                       ret = ret_prio;
+                       break;
+               }
                dbgarg(cmd, "index=%d, name=%s, capability=%d, "
                                        "mode=%d\n", p->index, p->name,
                                        p->capability, p->mode);
@@ -1683,6 +1530,10 @@ static long __video_do_ioctl(struct file *file,
 
                if (!ops->vidioc_s_modulator)
                        break;
+               if (ret_prio) {
+                       ret = ret_prio;
+                       break;
+               }
                dbgarg(cmd, "index=%d, name=%s, capability=%d, "
                                "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
                                p->index, p->name, p->capability, p->rangelow,
@@ -1709,6 +1560,10 @@ static long __video_do_ioctl(struct file *file,
 
                if (!ops->vidioc_s_crop)
                        break;
+               if (ret_prio) {
+                       ret = ret_prio;
+                       break;
+               }
                dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
                dbgrect(vfd, "", &p->c);
                ret = ops->vidioc_s_crop(file, fh, p);
@@ -1752,11 +1607,15 @@ static long __video_do_ioctl(struct file *file,
 
                if (!ops->vidioc_g_jpegcomp)
                        break;
+               if (ret_prio) {
+                       ret = ret_prio;
+                       break;
+               }
                dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
                                        "COM_len=%d, jpeg_markers=%d\n",
                                        p->quality, p->APPn, p->APP_len,
                                        p->COM_len, p->jpeg_markers);
-                       ret = ops->vidioc_s_jpegcomp(file, fh, p);
+               ret = ops->vidioc_s_jpegcomp(file, fh, p);
                break;
        }
        case VIDIOC_G_ENC_INDEX:
@@ -1777,6 +1636,10 @@ static long __video_do_ioctl(struct file *file,
 
                if (!ops->vidioc_encoder_cmd)
                        break;
+               if (ret_prio) {
+                       ret = ret_prio;
+                       break;
+               }
                ret = ops->vidioc_encoder_cmd(file, fh, p);
                if (!ret)
                        dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
@@ -1797,6 +1660,8 @@ static long __video_do_ioctl(struct file *file,
        {
                struct v4l2_streamparm *p = arg;
 
+               if (!ops->vidioc_g_parm && !vfd->current_norm)
+                       break;
                if (ops->vidioc_g_parm) {
                        ret = check_fmt(ops, p->type);
                        if (ret)
@@ -1805,14 +1670,13 @@ static long __video_do_ioctl(struct file *file,
                } else {
                        v4l2_std_id std = vfd->current_norm;
 
+                       ret = -EINVAL;
                        if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
                                break;
 
                        ret = 0;
                        if (ops->vidioc_g_std)
                                ret = ops->vidioc_g_std(file, fh, &std);
-                       else if (std == 0)
-                               ret = -EINVAL;
                        if (ret == 0)
                                v4l2_video_std_frame_period(std,
                                                    &p->parm.capture.timeperframe);
@@ -1827,6 +1691,10 @@ static long __video_do_ioctl(struct file *file,
 
                if (!ops->vidioc_s_parm)
                        break;
+               if (ret_prio) {
+                       ret = ret_prio;
+                       break;
+               }
                ret = check_fmt(ops, p->type);
                if (ret)
                        break;
@@ -1862,6 +1730,10 @@ static long __video_do_ioctl(struct file *file,
 
                if (!ops->vidioc_s_tuner)
                        break;
+               if (ret_prio) {
+                       ret = ret_prio;
+                       break;
+               }
                p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
                        V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
                dbgarg(cmd, "index=%d, name=%s, type=%d, "
@@ -1896,6 +1768,10 @@ static long __video_do_ioctl(struct file *file,
 
                if (!ops->vidioc_s_frequency)
                        break;
+               if (ret_prio) {
+                       ret = ret_prio;
+                       break;
+               }
                dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
                                p->tuner, p->type, p->frequency);
                ret = ops->vidioc_s_frequency(file, fh, p);
@@ -1970,6 +1846,10 @@ static long __video_do_ioctl(struct file *file,
 
                if (!ops->vidioc_s_hw_freq_seek)
                        break;
+               if (ret_prio) {
+                       ret = ret_prio;
+                       break;
+               }
                type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
                        V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
                dbgarg(cmd,
@@ -2074,6 +1954,10 @@ static long __video_do_ioctl(struct file *file,
 
                if (!ops->vidioc_s_dv_preset)
                        break;
+               if (ret_prio) {
+                       ret = ret_prio;
+                       break;
+               }
 
                dbgarg(cmd, "preset=%d\n", p->preset);
                ret = ops->vidioc_s_dv_preset(file, fh, p);
@@ -2109,6 +1993,10 @@ static long __video_do_ioctl(struct file *file,
 
                if (!ops->vidioc_s_dv_timings)
                        break;
+               if (ret_prio) {
+                       ret = ret_prio;
+                       break;
+               }
 
                switch (p->type) {
                case V4L2_DV_BT_656_1120:
@@ -2217,19 +2105,12 @@ static long __video_do_ioctl(struct file *file,
                break;
        }
        default:
-       {
-               bool valid_prio = true;
-
                if (!ops->vidioc_default)
                        break;
-               if (use_fh_prio)
-                       valid_prio = v4l2_prio_check(vfd->prio, vfh->prio) >= 0;
-               ret = ops->vidioc_default(file, fh, valid_prio, cmd, arg);
+               ret = ops->vidioc_default(file, fh, ret_prio >= 0, cmd, arg);
                break;
-       }
        } /* switch */
 
-exit_prio:
        if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
                if (ret < 0) {
                        v4l_print_ioctl(vfd->name, cmd);
index 3b15bf5892a803b4da4e7eb8af7e6a20d83a7455..975d0fa938c6fa81fd9a6bcacafecb69386c31a5 100644 (file)
@@ -97,11 +97,12 @@ void *v4l2_m2m_next_buf(struct v4l2_m2m_queue_ctx *q_ctx)
 
        spin_lock_irqsave(&q_ctx->rdy_spinlock, flags);
 
-       if (list_empty(&q_ctx->rdy_queue))
-               goto end;
+       if (list_empty(&q_ctx->rdy_queue)) {
+               spin_unlock_irqrestore(&q_ctx->rdy_spinlock, flags);
+               return NULL;
+       }
 
        b = list_entry(q_ctx->rdy_queue.next, struct v4l2_m2m_buffer, list);
-end:
        spin_unlock_irqrestore(&q_ctx->rdy_spinlock, flags);
        return &b->vb;
 }
@@ -117,12 +118,13 @@ void *v4l2_m2m_buf_remove(struct v4l2_m2m_queue_ctx *q_ctx)
        unsigned long flags;
 
        spin_lock_irqsave(&q_ctx->rdy_spinlock, flags);
-       if (!list_empty(&q_ctx->rdy_queue)) {
-               b = list_entry(q_ctx->rdy_queue.next, struct v4l2_m2m_buffer,
-                               list);
-               list_del(&b->list);
-               q_ctx->num_rdy--;
+       if (list_empty(&q_ctx->rdy_queue)) {
+               spin_unlock_irqrestore(&q_ctx->rdy_spinlock, flags);
+               return NULL;
        }
+       b = list_entry(q_ctx->rdy_queue.next, struct v4l2_m2m_buffer, list);
+       list_del(&b->list);
+       q_ctx->num_rdy--;
        spin_unlock_irqrestore(&q_ctx->rdy_spinlock, flags);
 
        return &b->vb;
index b7967c9dc4ae917c16cec58da1ac16b947bedd50..179e20e23fc4b58673f23c7fb37688a506589d83 100644 (file)
@@ -173,6 +173,25 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
 
        case VIDIOC_UNSUBSCRIBE_EVENT:
                return v4l2_subdev_call(sd, core, unsubscribe_event, vfh, arg);
+
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+       case VIDIOC_DBG_G_REGISTER:
+       {
+               struct v4l2_dbg_register *p = arg;
+
+               if (!capable(CAP_SYS_ADMIN))
+                       return -EPERM;
+               return v4l2_subdev_call(sd, core, g_register, p);
+       }
+       case VIDIOC_DBG_S_REGISTER:
+       {
+               struct v4l2_dbg_register *p = arg;
+
+               if (!capable(CAP_SYS_ADMIN))
+                       return -EPERM;
+               return v4l2_subdev_call(sd, core, s_register, p);
+       }
+#endif
 #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
        case VIDIOC_SUBDEV_G_FMT: {
                struct v4l2_subdev_format *format = arg;
index 3015e6000946b735a89d9b0a5e90f70540ab10c2..3f5c7a38e6e885d28e3ae5c5f982377aa4285aae 100644 (file)
@@ -43,8 +43,7 @@ module_param(debug, int, 0644);
 /**
  * __vb2_buf_mem_alloc() - allocate video memory for the given buffer
  */
-static int __vb2_buf_mem_alloc(struct vb2_buffer *vb,
-                               unsigned long *plane_sizes)
+static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
 {
        struct vb2_queue *q = vb->vb2_queue;
        void *mem_priv;
@@ -53,13 +52,13 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb,
        /* Allocate memory for all planes in this buffer */
        for (plane = 0; plane < vb->num_planes; ++plane) {
                mem_priv = call_memop(q, plane, alloc, q->alloc_ctx[plane],
-                                       plane_sizes[plane]);
+                                     q->plane_sizes[plane]);
                if (IS_ERR_OR_NULL(mem_priv))
                        goto free;
 
                /* Associate allocator private data with this plane */
                vb->planes[plane].mem_priv = mem_priv;
-               vb->v4l2_planes[plane].length = plane_sizes[plane];
+               vb->v4l2_planes[plane].length = q->plane_sizes[plane];
        }
 
        return 0;
@@ -141,8 +140,7 @@ static void __setup_offsets(struct vb2_queue *q)
  * Returns the number of buffers successfully allocated.
  */
 static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
-                            unsigned int num_buffers, unsigned int num_planes,
-                            unsigned long plane_sizes[])
+                            unsigned int num_buffers, unsigned int num_planes)
 {
        unsigned int buffer;
        struct vb2_buffer *vb;
@@ -169,7 +167,7 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
 
                /* Allocate video buffer memory for the MMAP type */
                if (memory == V4L2_MEMORY_MMAP) {
-                       ret = __vb2_buf_mem_alloc(vb, plane_sizes);
+                       ret = __vb2_buf_mem_alloc(vb);
                        if (ret) {
                                dprintk(1, "Failed allocating memory for "
                                                "buffer %d\n", buffer);
@@ -278,6 +276,41 @@ static int __verify_planes_array(struct vb2_buffer *vb, struct v4l2_buffer *b)
        return 0;
 }
 
+/**
+ * __buffer_in_use() - return true if the buffer is in use and
+ * the queue cannot be freed (by the means of REQBUFS(0)) call
+ */
+static bool __buffer_in_use(struct vb2_queue *q, struct vb2_buffer *vb)
+{
+       unsigned int plane;
+       for (plane = 0; plane < vb->num_planes; ++plane) {
+               /*
+                * If num_users() has not been provided, call_memop
+                * will return 0, apparently nobody cares about this
+                * case anyway. If num_users() returns more than 1,
+                * we are not the only user of the plane's memory.
+                */
+               if (call_memop(q, plane, num_users,
+                               vb->planes[plane].mem_priv) > 1)
+                       return true;
+       }
+       return false;
+}
+
+/**
+ * __buffers_in_use() - return true if any buffers on the queue are in use and
+ * the queue cannot be freed (by the means of REQBUFS(0)) call
+ */
+static bool __buffers_in_use(struct vb2_queue *q)
+{
+       unsigned int buffer;
+       for (buffer = 0; buffer < q->num_buffers; ++buffer) {
+               if (__buffer_in_use(q, q->bufs[buffer]))
+                       return true;
+       }
+       return false;
+}
+
 /**
  * __fill_v4l2_buffer() - fill in a struct v4l2_buffer with information to be
  * returned to userspace
@@ -337,7 +370,7 @@ static int __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b)
                break;
        }
 
-       if (vb->num_planes_mapped == vb->num_planes)
+       if (__buffer_in_use(q, vb))
                b->flags |= V4L2_BUF_FLAG_MAPPED;
 
        return ret;
@@ -401,33 +434,6 @@ static int __verify_mmap_ops(struct vb2_queue *q)
        return 0;
 }
 
-/**
- * __buffers_in_use() - return true if any buffers on the queue are in use and
- * the queue cannot be freed (by the means of REQBUFS(0)) call
- */
-static bool __buffers_in_use(struct vb2_queue *q)
-{
-       unsigned int buffer, plane;
-       struct vb2_buffer *vb;
-
-       for (buffer = 0; buffer < q->num_buffers; ++buffer) {
-               vb = q->bufs[buffer];
-               for (plane = 0; plane < vb->num_planes; ++plane) {
-                       /*
-                        * If num_users() has not been provided, call_memop
-                        * will return 0, apparently nobody cares about this
-                        * case anyway. If num_users() returns more than 1,
-                        * we are not the only user of the plane's memory.
-                        */
-                       if (call_memop(q, plane, num_users,
-                                       vb->planes[plane].mem_priv) > 1)
-                               return true;
-               }
-       }
-
-       return false;
-}
-
 /**
  * vb2_reqbufs() - Initiate streaming
  * @q:         videobuf2 queue
@@ -454,7 +460,6 @@ static bool __buffers_in_use(struct vb2_queue *q)
 int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
 {
        unsigned int num_buffers, num_planes;
-       unsigned long plane_sizes[VIDEO_MAX_PLANES];
        int ret = 0;
 
        if (q->fileio) {
@@ -516,7 +521,7 @@ int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
         * Make sure the requested values and current defaults are sane.
         */
        num_buffers = min_t(unsigned int, req->count, VIDEO_MAX_FRAME);
-       memset(plane_sizes, 0, sizeof(plane_sizes));
+       memset(q->plane_sizes, 0, sizeof(q->plane_sizes));
        memset(q->alloc_ctx, 0, sizeof(q->alloc_ctx));
        q->memory = req->memory;
 
@@ -525,13 +530,12 @@ int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
         * Driver also sets the size and allocator context for each plane.
         */
        ret = call_qop(q, queue_setup, q, &num_buffers, &num_planes,
-                      plane_sizes, q->alloc_ctx);
+                      q->plane_sizes, q->alloc_ctx);
        if (ret)
                return ret;
 
        /* Finally, allocate buffers and video memory */
-       ret = __vb2_queue_alloc(q, req->memory, num_buffers, num_planes,
-                               plane_sizes);
+       ret = __vb2_queue_alloc(q, req->memory, num_buffers, num_planes);
        if (ret == 0) {
                dprintk(1, "Memory allocation failed\n");
                return -ENOMEM;
@@ -545,7 +549,7 @@ int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
 
                orig_num_buffers = num_buffers = ret;
                ret = call_qop(q, queue_setup, q, &num_buffers, &num_planes,
-                              plane_sizes, q->alloc_ctx);
+                              q->plane_sizes, q->alloc_ctx);
                if (ret)
                        goto free_mem;
 
@@ -745,12 +749,20 @@ static int __qbuf_userptr(struct vb2_buffer *vb, struct v4l2_buffer *b)
                dprintk(3, "qbuf: userspace address for plane %d changed, "
                                "reacquiring memory\n", plane);
 
+               /* Check if the provided plane buffer is large enough */
+               if (planes[plane].length < q->plane_sizes[plane]) {
+                       ret = -EINVAL;
+                       goto err;
+               }
+
                /* Release previously acquired memory if present */
                if (vb->planes[plane].mem_priv)
                        call_memop(q, plane, put_userptr,
                                        vb->planes[plane].mem_priv);
 
                vb->planes[plane].mem_priv = NULL;
+               vb->v4l2_planes[plane].m.userptr = 0;
+               vb->v4l2_planes[plane].length = 0;
 
                /* Acquire each plane's memory */
                if (q->mem_ops->get_userptr) {
@@ -788,10 +800,13 @@ static int __qbuf_userptr(struct vb2_buffer *vb, struct v4l2_buffer *b)
        return 0;
 err:
        /* In case of errors, release planes that were already acquired */
-       for (; plane > 0; --plane) {
-               call_memop(q, plane, put_userptr,
-                               vb->planes[plane - 1].mem_priv);
-               vb->planes[plane - 1].mem_priv = NULL;
+       for (plane = 0; plane < vb->num_planes; ++plane) {
+               if (vb->planes[plane].mem_priv)
+                       call_memop(q, plane, put_userptr,
+                                  vb->planes[plane].mem_priv);
+               vb->planes[plane].mem_priv = NULL;
+               vb->v4l2_planes[plane].m.userptr = 0;
+               vb->v4l2_planes[plane].length = 0;
        }
 
        return ret;
@@ -1095,6 +1110,43 @@ int vb2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking)
 }
 EXPORT_SYMBOL_GPL(vb2_dqbuf);
 
+/**
+ * __vb2_queue_cancel() - cancel and stop (pause) streaming
+ *
+ * Removes all queued buffers from driver's queue and all buffers queued by
+ * userspace from videobuf's queue. Returns to state after reqbufs.
+ */
+static void __vb2_queue_cancel(struct vb2_queue *q)
+{
+       unsigned int i;
+
+       /*
+        * Tell driver to stop all transactions and release all queued
+        * buffers.
+        */
+       if (q->streaming)
+               call_qop(q, stop_streaming, q);
+       q->streaming = 0;
+
+       /*
+        * Remove all buffers from videobuf's list...
+        */
+       INIT_LIST_HEAD(&q->queued_list);
+       /*
+        * ...and done list; userspace will not receive any buffers it
+        * has not already dequeued before initiating cancel.
+        */
+       INIT_LIST_HEAD(&q->done_list);
+       atomic_set(&q->queued_count, 0);
+       wake_up_all(&q->done_wq);
+
+       /*
+        * Reinitialize all buffers for next use.
+        */
+       for (i = 0; i < q->num_buffers; ++i)
+               q->bufs[i]->state = VB2_BUF_STATE_DEQUEUED;
+}
+
 /**
  * vb2_streamon - start streaming
  * @q:         videobuf2 queue
@@ -1103,7 +1155,7 @@ EXPORT_SYMBOL_GPL(vb2_dqbuf);
  * Should be called from vidioc_streamon handler of a driver.
  * This function:
  * 1) verifies current state
- * 2) starts streaming and passes any previously queued buffers to the driver
+ * 2) passes any previously queued buffers to the driver and starts streaming
  *
  * The return values from this function are intended to be directly returned
  * from vidioc_streamon handler in the driver.
@@ -1129,75 +1181,29 @@ int vb2_streamon(struct vb2_queue *q, enum v4l2_buf_type type)
        }
 
        /*
-        * Cannot start streaming on an OUTPUT device if no buffers have
-        * been queued yet.
+        * If any buffers were queued before streamon,
+        * we can now pass them to driver for processing.
         */
-       if (V4L2_TYPE_IS_OUTPUT(q->type)) {
-               if (list_empty(&q->queued_list)) {
-                       dprintk(1, "streamon: no output buffers queued\n");
-                       return -EINVAL;
-               }
-       }
+       list_for_each_entry(vb, &q->queued_list, queued_entry)
+               __enqueue_in_driver(vb);
 
        /*
         * Let driver notice that streaming state has been enabled.
         */
-       ret = call_qop(q, start_streaming, q);
+       ret = call_qop(q, start_streaming, q, atomic_read(&q->queued_count));
        if (ret) {
                dprintk(1, "streamon: driver refused to start streaming\n");
+               __vb2_queue_cancel(q);
                return ret;
        }
 
        q->streaming = 1;
 
-       /*
-        * If any buffers were queued before streamon,
-        * we can now pass them to driver for processing.
-        */
-       list_for_each_entry(vb, &q->queued_list, queued_entry)
-               __enqueue_in_driver(vb);
-
        dprintk(3, "Streamon successful\n");
        return 0;
 }
 EXPORT_SYMBOL_GPL(vb2_streamon);
 
-/**
- * __vb2_queue_cancel() - cancel and stop (pause) streaming
- *
- * Removes all queued buffers from driver's queue and all buffers queued by
- * userspace from videobuf's queue. Returns to state after reqbufs.
- */
-static void __vb2_queue_cancel(struct vb2_queue *q)
-{
-       unsigned int i;
-
-       /*
-        * Tell driver to stop all transactions and release all queued
-        * buffers.
-        */
-       if (q->streaming)
-               call_qop(q, stop_streaming, q);
-       q->streaming = 0;
-
-       /*
-        * Remove all buffers from videobuf's list...
-        */
-       INIT_LIST_HEAD(&q->queued_list);
-       /*
-        * ...and done list; userspace will not receive any buffers it
-        * has not already dequeued before initiating cancel.
-        */
-       INIT_LIST_HEAD(&q->done_list);
-       atomic_set(&q->queued_count, 0);
-       wake_up_all(&q->done_wq);
-
-       /*
-        * Reinitialize all buffers for next use.
-        */
-       for (i = 0; i < q->num_buffers; ++i)
-               q->bufs[i]->state = VB2_BUF_STATE_DEQUEUED;
-}
 
 /**
  * vb2_streamoff - stop streaming
@@ -1336,9 +1342,6 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
        if (ret)
                return ret;
 
-       vb_plane->mapped = 1;
-       vb->num_planes_mapped++;
-
        dprintk(3, "Buffer %d, plane %d successfully mapped\n", buffer, plane);
        return 0;
 }
index a790a5f8c06ff5e48566bfeb41a512975fc26d4f..f17ad98fcc5fa61e09d87af99a57b6934443e656 100644 (file)
@@ -24,7 +24,7 @@ struct vb2_dc_conf {
 struct vb2_dc_buf {
        struct vb2_dc_conf              *conf;
        void                            *vaddr;
-       dma_addr_t                      paddr;
+       dma_addr_t                      dma_addr;
        unsigned long                   size;
        struct vm_area_struct           *vma;
        atomic_t                        refcount;
@@ -42,7 +42,7 @@ static void *vb2_dma_contig_alloc(void *alloc_ctx, unsigned long size)
        if (!buf)
                return ERR_PTR(-ENOMEM);
 
-       buf->vaddr = dma_alloc_coherent(conf->dev, size, &buf->paddr,
+       buf->vaddr = dma_alloc_coherent(conf->dev, size, &buf->dma_addr,
                                        GFP_KERNEL);
        if (!buf->vaddr) {
                dev_err(conf->dev, "dma_alloc_coherent of size %ld failed\n",
@@ -69,7 +69,7 @@ static void vb2_dma_contig_put(void *buf_priv)
 
        if (atomic_dec_and_test(&buf->refcount)) {
                dma_free_coherent(buf->conf->dev, buf->size, buf->vaddr,
-                                 buf->paddr);
+                                 buf->dma_addr);
                kfree(buf);
        }
 }
@@ -78,7 +78,7 @@ static void *vb2_dma_contig_cookie(void *buf_priv)
 {
        struct vb2_dc_buf *buf = buf_priv;
 
-       return &buf->paddr;
+       return &buf->dma_addr;
 }
 
 static void *vb2_dma_contig_vaddr(void *buf_priv)
@@ -106,7 +106,7 @@ static int vb2_dma_contig_mmap(void *buf_priv, struct vm_area_struct *vma)
                return -EINVAL;
        }
 
-       return vb2_mmap_pfn_range(vma, buf->paddr, buf->size,
+       return vb2_mmap_pfn_range(vma, buf->dma_addr, buf->size,
                                  &vb2_common_vm_ops, &buf->handler);
 }
 
@@ -115,14 +115,14 @@ static void *vb2_dma_contig_get_userptr(void *alloc_ctx, unsigned long vaddr,
 {
        struct vb2_dc_buf *buf;
        struct vm_area_struct *vma;
-       dma_addr_t paddr = 0;
+       dma_addr_t dma_addr = 0;
        int ret;
 
        buf = kzalloc(sizeof *buf, GFP_KERNEL);
        if (!buf)
                return ERR_PTR(-ENOMEM);
 
-       ret = vb2_get_contig_userptr(vaddr, size, &vma, &paddr);
+       ret = vb2_get_contig_userptr(vaddr, size, &vma, &dma_addr);
        if (ret) {
                printk(KERN_ERR "Failed acquiring VMA for vaddr 0x%08lx\n",
                                vaddr);
@@ -131,7 +131,7 @@ static void *vb2_dma_contig_get_userptr(void *alloc_ctx, unsigned long vaddr,
        }
 
        buf->size = size;
-       buf->paddr = paddr;
+       buf->dma_addr = dma_addr;
        buf->vma = vma;
 
        return buf;
index 065f468faf8fd021d7b12b59407db380a3cd478e..3bad8b105fea3260ffcb5fff745009b943885eec 100644 (file)
@@ -75,12 +75,6 @@ static void *vb2_dma_sg_alloc(void *alloc_ctx, unsigned long size)
 
        printk(KERN_DEBUG "%s: Allocated buffer of %d pages\n",
                __func__, buf->sg_desc.num_pages);
-
-       if (!buf->vaddr)
-               buf->vaddr = vm_map_ram(buf->pages,
-                                       buf->sg_desc.num_pages,
-                                       -1,
-                                       PAGE_KERNEL);
        return buf;
 
 fail_pages_alloc:
index 569eeb3dfd506d4647ca9dae2e54db7213e816ec..71a7a78c3fc05ce039b87661644f880ea15b4a79 100644 (file)
@@ -68,12 +68,12 @@ void vb2_put_vma(struct vm_area_struct *vma)
        if (!vma)
                return;
 
-       if (vma->vm_file)
-               fput(vma->vm_file);
-
        if (vma->vm_ops && vma->vm_ops->close)
                vma->vm_ops->close(vma);
 
+       if (vma->vm_file)
+               fput(vma->vm_file);
+
        kfree(vma);
 }
 EXPORT_SYMBOL_GPL(vb2_put_vma);
index a848bd2af97f0b704fbdf49216da85109ee874c2..7cf94c09d99ab54d75b7ccf2668b0dbf200ac567 100644 (file)
@@ -651,7 +651,7 @@ static void vivi_stop_generating(struct vivi_dev *dev)
        Videobuf operations
    ------------------------------------------------------------------*/
 static int queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
-                               unsigned int *nplanes, unsigned long sizes[],
+                               unsigned int *nplanes, unsigned int sizes[],
                                void *alloc_ctxs[])
 {
        struct vivi_dev *dev = vb2_get_drv_priv(vq);
@@ -766,7 +766,7 @@ static void buffer_queue(struct vb2_buffer *vb)
        spin_unlock_irqrestore(&dev->slock, flags);
 }
 
-static int start_streaming(struct vb2_queue *vq)
+static int start_streaming(struct vb2_queue *vq, unsigned int count)
 {
        struct vivi_dev *dev = vb2_get_drv_priv(vq);
        dprintk(dev, 1, "%s\n", __func__);
@@ -852,6 +852,11 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
                (f->fmt.pix.width * dev->fmt->depth) >> 3;
        f->fmt.pix.sizeimage =
                f->fmt.pix.height * f->fmt.pix.bytesperline;
+       if (dev->fmt->fourcc == V4L2_PIX_FMT_YUYV ||
+           dev->fmt->fourcc == V4L2_PIX_FMT_UYVY)
+               f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
+       else
+               f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
        return 0;
 }
 
@@ -885,6 +890,11 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
                (f->fmt.pix.width * fmt->depth) >> 3;
        f->fmt.pix.sizeimage =
                f->fmt.pix.height * f->fmt.pix.bytesperline;
+       if (fmt->fourcc == V4L2_PIX_FMT_YUYV ||
+           fmt->fourcc == V4L2_PIX_FMT_UYVY)
+               f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
+       else
+               f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
        return 0;
 }
 
@@ -948,6 +958,14 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
        return vb2_streamoff(&dev->vb_vidq, i);
 }
 
+static int vidioc_log_status(struct file *file, void *priv)
+{
+       struct vivi_dev *dev = video_drvdata(file);
+
+       v4l2_ctrl_handler_log_status(&dev->ctrl_handler, dev->v4l2_dev.name);
+       return 0;
+}
+
 static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *i)
 {
        return 0;
@@ -1191,6 +1209,7 @@ static const struct v4l2_ioctl_ops vivi_ioctl_ops = {
        .vidioc_s_input       = vidioc_s_input,
        .vidioc_streamon      = vidioc_streamon,
        .vidioc_streamoff     = vidioc_streamoff,
+       .vidioc_log_status    = vidioc_log_status,
        .vidioc_subscribe_event = vidioc_subscribe_event,
        .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
 };
index ca372eb911d0d5905ffcfc76481fe9e99f52272b..e5cad6ff64a1d24e89665b4b1168c6dc55e0fd98 100644 (file)
@@ -331,7 +331,7 @@ static int vpx3220_status(struct v4l2_subdev *sd, u32 *pstatus, v4l2_std_id *pst
        if (pstd)
                *pstd = std;
        if (pstatus)
-               *pstatus = status;
+               *pstatus = res;
        return 0;
 }
 
index c492846c1c5a33770c6488cbfd8095f7c91757db..e78cf94f491e76ff8eca011c9d92cc6a313141ad 100644 (file)
@@ -1638,6 +1638,9 @@ static int zr364xx_probe(struct usb_interface *intf,
 
        if (!cam->read_endpoint) {
                dev_err(&intf->dev, "Could not find bulk-in endpoint\n");
+               video_device_release(cam->vdev);
+               kfree(cam);
+               cam = NULL;
                return -ENOMEM;
        }
 
index 7956a10f94885f19cc91dc981c5934fcb494a414..e9c6a6047a00cfcf5c28306226e62ef148a35531 100644 (file)
@@ -63,6 +63,8 @@
 #ifdef CONFIG_MTRR
 #include <asm/mtrr.h>
 #endif
+#include <linux/kthread.h>
+#include <scsi/scsi_host.h>
 
 #include "mptbase.h"
 #include "lsi/mpi_log_fc.h"
@@ -323,6 +325,32 @@ mpt_is_discovery_complete(MPT_ADAPTER *ioc)
        return rc;
 }
 
+
+/**
+ *  mpt_remove_dead_ioc_func - kthread context to remove dead ioc
+ * @arg: input argument, used to derive ioc
+ *
+ * Return 0 if controller is removed from pci subsystem.
+ * Return -1 for other case.
+ */
+static int mpt_remove_dead_ioc_func(void *arg)
+{
+       MPT_ADAPTER *ioc = (MPT_ADAPTER *)arg;
+       struct pci_dev *pdev;
+
+       if ((ioc == NULL))
+               return -1;
+
+       pdev = ioc->pcidev;
+       if ((pdev == NULL))
+               return -1;
+
+       pci_remove_bus_device(pdev);
+       return 0;
+}
+
+
+
 /**
  *     mpt_fault_reset_work - work performed on workq after ioc fault
  *     @work: input argument, used to derive ioc
@@ -336,12 +364,45 @@ mpt_fault_reset_work(struct work_struct *work)
        u32              ioc_raw_state;
        int              rc;
        unsigned long    flags;
+       MPT_SCSI_HOST   *hd;
+       struct task_struct *p;
 
        if (ioc->ioc_reset_in_progress || !ioc->active)
                goto out;
 
+
        ioc_raw_state = mpt_GetIocState(ioc, 0);
-       if ((ioc_raw_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT) {
+       if ((ioc_raw_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_MASK) {
+               printk(MYIOC_s_INFO_FMT "%s: IOC is non-operational !!!!\n",
+                   ioc->name, __func__);
+
+               /*
+                * Call mptscsih_flush_pending_cmds callback so that we
+                * flush all pending commands back to OS.
+                * This call is required to aovid deadlock at block layer.
+                * Dead IOC will fail to do diag reset,and this call is safe
+                * since dead ioc will never return any command back from HW.
+                */
+               hd = shost_priv(ioc->sh);
+               ioc->schedule_dead_ioc_flush_running_cmds(hd);
+
+               /*Remove the Dead Host */
+               p = kthread_run(mpt_remove_dead_ioc_func, ioc,
+                               "mpt_dead_ioc_%d", ioc->id);
+               if (IS_ERR(p))  {
+                       printk(MYIOC_s_ERR_FMT
+                               "%s: Running mpt_dead_ioc thread failed !\n",
+                               ioc->name, __func__);
+               } else {
+                       printk(MYIOC_s_WARN_FMT
+                               "%s: Running mpt_dead_ioc thread success !\n",
+                               ioc->name, __func__);
+               }
+               return; /* don't rearm timer */
+       }
+
+       if ((ioc_raw_state & MPI_IOC_STATE_MASK)
+                       == MPI_IOC_STATE_FAULT) {
                printk(MYIOC_s_WARN_FMT "IOC is in FAULT state (%04xh)!!!\n",
                       ioc->name, ioc_raw_state & MPI_DOORBELL_DATA_MASK);
                printk(MYIOC_s_WARN_FMT "Issuing HardReset from %s!!\n",
@@ -6413,8 +6474,19 @@ mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg)
                        pReq->Action, ioc->mptbase_cmds.status, timeleft));
                if (ioc->mptbase_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
                        goto out;
-               if (!timeleft)
+               if (!timeleft) {
+                       spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
+                       if (ioc->ioc_reset_in_progress) {
+                               spin_unlock_irqrestore(&ioc->taskmgmt_lock,
+                                       flags);
+                               printk(MYIOC_s_INFO_FMT "%s: host reset in"
+                                       " progress mpt_config timed out.!!\n",
+                                       __func__, ioc->name);
+                               return -EFAULT;
+                       }
+                       spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
                        issue_hard_reset = 1;
+               }
                goto out;
        }
 
@@ -7128,7 +7200,18 @@ mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag)
        spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
        if (ioc->ioc_reset_in_progress) {
                spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
-               return 0;
+               ioc->wait_on_reset_completion = 1;
+               do {
+                       ssleep(1);
+               } while (ioc->ioc_reset_in_progress == 1);
+               ioc->wait_on_reset_completion = 0;
+               return ioc->reset_status;
+       }
+       if (ioc->wait_on_reset_completion) {
+               spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
+               rc = 0;
+               time_count = jiffies;
+               goto exit;
        }
        ioc->ioc_reset_in_progress = 1;
        if (ioc->alt_ioc)
@@ -7165,6 +7248,7 @@ mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag)
        ioc->ioc_reset_in_progress = 0;
        ioc->taskmgmt_quiesce_io = 0;
        ioc->taskmgmt_in_progress = 0;
+       ioc->reset_status = rc;
        if (ioc->alt_ioc) {
                ioc->alt_ioc->ioc_reset_in_progress = 0;
                ioc->alt_ioc->taskmgmt_quiesce_io = 0;
@@ -7180,7 +7264,7 @@ mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag)
                                        ioc->alt_ioc, MPT_IOC_POST_RESET);
                }
        }
-
+exit:
        dtmprintk(ioc,
            printk(MYIOC_s_DEBUG_FMT
                "HardResetHandler: completed (%d seconds): %s\n", ioc->name,
index fe902338539b7bca6d22e9d2b1a563760d5fc849..b4d24dc081ae5de35c3d4d0c3765ddf63235b517 100644 (file)
@@ -76,8 +76,8 @@
 #define COPYRIGHT      "Copyright (c) 1999-2008 " MODULEAUTHOR
 #endif
 
-#define MPT_LINUX_VERSION_COMMON       "3.04.19"
-#define MPT_LINUX_PACKAGE_NAME         "@(#)mptlinux-3.04.19"
+#define MPT_LINUX_VERSION_COMMON       "3.04.20"
+#define MPT_LINUX_PACKAGE_NAME         "@(#)mptlinux-3.04.20"
 #define WHAT_MAGIC_STRING              "@" "(" "#" ")"
 
 #define show_mptmod_ver(s,ver)  \
@@ -554,10 +554,47 @@ struct mptfc_rport_info
        u8              flags;
 };
 
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+
+/*
+ * MPT_SCSI_HOST defines - Used by the IOCTL and the SCSI drivers
+ * Private to the driver.
+ */
+
+#define MPT_HOST_BUS_UNKNOWN           (0xFF)
+#define MPT_HOST_TOO_MANY_TM           (0x05)
+#define MPT_HOST_NVRAM_INVALID         (0xFFFFFFFF)
+#define MPT_HOST_NO_CHAIN              (0xFFFFFFFF)
+#define MPT_NVRAM_MASK_TIMEOUT         (0x000000FF)
+#define MPT_NVRAM_SYNC_MASK            (0x0000FF00)
+#define MPT_NVRAM_SYNC_SHIFT           (8)
+#define MPT_NVRAM_DISCONNECT_ENABLE    (0x00010000)
+#define MPT_NVRAM_ID_SCAN_ENABLE       (0x00020000)
+#define MPT_NVRAM_LUN_SCAN_ENABLE      (0x00040000)
+#define MPT_NVRAM_TAG_QUEUE_ENABLE     (0x00080000)
+#define MPT_NVRAM_WIDE_DISABLE         (0x00100000)
+#define MPT_NVRAM_BOOT_CHOICE          (0x00200000)
+
+typedef enum {
+       FC,
+       SPI,
+       SAS
+} BUS_TYPE;
+
+typedef struct _MPT_SCSI_HOST {
+       struct _MPT_ADAPTER              *ioc;
+       ushort                    sel_timeout[MPT_MAX_FC_DEVICES];
+       char                      *info_kbuf;
+       long                      last_queue_full;
+       u16                       spi_pending;
+       struct list_head          target_reset_list;
+} MPT_SCSI_HOST;
+
 typedef void (*MPT_ADD_SGE)(void *pAddr, u32 flagslength, dma_addr_t dma_addr);
 typedef void (*MPT_ADD_CHAIN)(void *pAddr, u8 next, u16 length,
                dma_addr_t dma_addr);
 typedef void (*MPT_SCHEDULE_TARGET_RESET)(void *ioc);
+typedef void (*MPT_FLUSH_RUNNING_CMDS)(MPT_SCSI_HOST *hd);
 
 /*
  *  Adapter Structure - pci_dev specific. Maximum: MPT_MAX_ADAPTERS
@@ -716,7 +753,10 @@ typedef struct _MPT_ADAPTER
        int                      taskmgmt_in_progress;
        u8                       taskmgmt_quiesce_io;
        u8                       ioc_reset_in_progress;
+       u8                       reset_status;
+       u8                       wait_on_reset_completion;
        MPT_SCHEDULE_TARGET_RESET schedule_target_reset;
+       MPT_FLUSH_RUNNING_CMDS schedule_dead_ioc_flush_running_cmds;
        struct work_struct       sas_persist_task;
 
        struct work_struct       fc_setup_reset_work;
@@ -830,19 +870,6 @@ typedef struct _MPT_LOCAL_REPLY {
        u32     pad;
 } MPT_LOCAL_REPLY;
 
-#define MPT_HOST_BUS_UNKNOWN           (0xFF)
-#define MPT_HOST_TOO_MANY_TM           (0x05)
-#define MPT_HOST_NVRAM_INVALID         (0xFFFFFFFF)
-#define MPT_HOST_NO_CHAIN              (0xFFFFFFFF)
-#define MPT_NVRAM_MASK_TIMEOUT         (0x000000FF)
-#define MPT_NVRAM_SYNC_MASK            (0x0000FF00)
-#define MPT_NVRAM_SYNC_SHIFT           (8)
-#define MPT_NVRAM_DISCONNECT_ENABLE    (0x00010000)
-#define MPT_NVRAM_ID_SCAN_ENABLE       (0x00020000)
-#define MPT_NVRAM_LUN_SCAN_ENABLE      (0x00040000)
-#define MPT_NVRAM_TAG_QUEUE_ENABLE     (0x00080000)
-#define MPT_NVRAM_WIDE_DISABLE         (0x00100000)
-#define MPT_NVRAM_BOOT_CHOICE          (0x00200000)
 
 /* The TM_STATE variable is used to provide strict single threading of TM
  * requests as well as communicate TM error conditions.
@@ -851,21 +878,6 @@ typedef struct _MPT_LOCAL_REPLY {
 #define        TM_STATE_IN_PROGRESS   (1)
 #define        TM_STATE_ERROR         (2)
 
-typedef enum {
-       FC,
-       SPI,
-       SAS
-} BUS_TYPE;
-
-typedef struct _MPT_SCSI_HOST {
-       MPT_ADAPTER              *ioc;
-       ushort                    sel_timeout[MPT_MAX_FC_DEVICES];
-       char                      *info_kbuf;
-       long                      last_queue_full;
-       u16                       spi_pending;
-       struct list_head          target_reset_list;
-} MPT_SCSI_HOST;
-
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
 /*
  *     More Dynamic Multi-Pathing stuff...
index 7596aecd5072a0ea96da0b871573b4e3ca424cd1..9d9504298549d147133e107a1d66c1a74440c3eb 100644 (file)
@@ -92,6 +92,11 @@ static int max_lun = MPTSAS_MAX_LUN;
 module_param(max_lun, int, 0);
 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
 
+static int mpt_loadtime_max_sectors = 8192;
+module_param(mpt_loadtime_max_sectors, int, 0);
+MODULE_PARM_DESC(mpt_loadtime_max_sectors,
+               " Maximum sector define for Host Bus Adaptor.Range 64 to 8192 default=8192");
+
 static u8      mptsasDoneCtx = MPT_MAX_PROTOCOL_DRIVERS;
 static u8      mptsasTaskCtx = MPT_MAX_PROTOCOL_DRIVERS;
 static u8      mptsasInternalCtx = MPT_MAX_PROTOCOL_DRIVERS; /* Used only for internal commands */
@@ -285,10 +290,11 @@ mptsas_add_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event,
        spin_lock_irqsave(&ioc->fw_event_lock, flags);
        list_add_tail(&fw_event->list, &ioc->fw_event_list);
        INIT_DELAYED_WORK(&fw_event->work, mptsas_firmware_event_work);
-       devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: add (fw_event=0x%p)\n",
-           ioc->name, __func__, fw_event));
-       queue_delayed_work(ioc->fw_event_q, &fw_event->work,
-           delay);
+       devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: add (fw_event=0x%p)"
+               "on cpuid %d\n", ioc->name, __func__,
+               fw_event, smp_processor_id()));
+       queue_delayed_work_on(smp_processor_id(), ioc->fw_event_q,
+           &fw_event->work, delay);
        spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
 }
 
@@ -300,10 +306,11 @@ mptsas_requeue_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event,
        unsigned long flags;
        spin_lock_irqsave(&ioc->fw_event_lock, flags);
        devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: reschedule task "
-           "(fw_event=0x%p)\n", ioc->name, __func__, fw_event));
+           "(fw_event=0x%p)on cpuid %d\n", ioc->name, __func__,
+               fw_event, smp_processor_id()));
        fw_event->retries++;
-       queue_delayed_work(ioc->fw_event_q, &fw_event->work,
-           msecs_to_jiffies(delay));
+       queue_delayed_work_on(smp_processor_id(), ioc->fw_event_q,
+           &fw_event->work, msecs_to_jiffies(delay));
        spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
 }
 
@@ -1943,6 +1950,15 @@ static enum blk_eh_timer_return mptsas_eh_timed_out(struct scsi_cmnd *sc)
                goto done;
        }
 
+       /* In case if IOC is in reset from internal context.
+       *  Do not execute EEH for the same IOC. SML should to reset timer.
+       */
+       if (ioc->ioc_reset_in_progress) {
+               dtmprintk(ioc, printk(MYIOC_s_WARN_FMT ": %s: ioc is in reset,"
+                   "SML need to reset the timer (sc=%p)\n",
+                   ioc->name, __func__, sc));
+               rc = BLK_EH_RESET_TIMER;
+       }
        vdevice = sc->device->hostdata;
        if (vdevice && vdevice->vtarget && (vdevice->vtarget->inDMD
                || vdevice->vtarget->deleted)) {
@@ -5142,6 +5158,8 @@ mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id)
        ioc->TaskCtx = mptsasTaskCtx;
        ioc->InternalCtx = mptsasInternalCtx;
        ioc->schedule_target_reset = &mptsas_schedule_target_reset;
+       ioc->schedule_dead_ioc_flush_running_cmds =
+                               &mptscsih_flush_running_cmds;
        /*  Added sanity check on readiness of the MPT adapter.
         */
        if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
@@ -5239,6 +5257,21 @@ mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id)
                sh->sg_tablesize = numSGE;
        }
 
+       if (mpt_loadtime_max_sectors) {
+               if (mpt_loadtime_max_sectors < 64 ||
+                       mpt_loadtime_max_sectors > 8192) {
+                       printk(MYIOC_s_INFO_FMT "Invalid value passed for"
+                               "mpt_loadtime_max_sectors %d."
+                               "Range from 64 to 8192\n", ioc->name,
+                               mpt_loadtime_max_sectors);
+               }
+               mpt_loadtime_max_sectors &=  0xFFFFFFFE;
+               dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                       "Resetting max sector to %d from %d\n",
+                 ioc->name, mpt_loadtime_max_sectors, sh->max_sectors));
+               sh->max_sectors = mpt_loadtime_max_sectors;
+       }
+
        hd = shost_priv(sh);
        hd->ioc = ioc;
 
index ce61a5769765a4fda0fd4b5acfc2883a937480c6..0c3ced70707b9b62be49c41f56e3bc482f80e2bb 100644 (file)
@@ -830,7 +830,8 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
                                        if ((pScsiReq->CDB[0] == READ_6  && ((pScsiReq->CDB[1] & 0x02) == 0)) ||
                                            pScsiReq->CDB[0] == READ_10 ||
                                            pScsiReq->CDB[0] == READ_12 ||
-                                           pScsiReq->CDB[0] == READ_16 ||
+                                               (pScsiReq->CDB[0] == READ_16 &&
+                                               ((pScsiReq->CDB[1] & 0x02) == 0)) ||
                                            pScsiReq->CDB[0] == VERIFY  ||
                                            pScsiReq->CDB[0] == VERIFY_16) {
                                                if (scsi_bufflen(sc) !=
@@ -1024,7 +1025,7 @@ out:
  *
  *     Must be called while new I/Os are being queued.
  */
-static void
+void
 mptscsih_flush_running_cmds(MPT_SCSI_HOST *hd)
 {
        MPT_ADAPTER *ioc = hd->ioc;
@@ -1055,6 +1056,7 @@ mptscsih_flush_running_cmds(MPT_SCSI_HOST *hd)
                sc->scsi_done(sc);
        }
 }
+EXPORT_SYMBOL(mptscsih_flush_running_cmds);
 
 /*
  *     mptscsih_search_running_cmds - Delete any commands associated
@@ -1629,7 +1631,13 @@ mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun,
                return 0;
        }
 
-       if (ioc_raw_state & MPI_DOORBELL_ACTIVE) {
+       /* DOORBELL ACTIVE check is not required if
+       *  MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q is supported.
+       */
+
+       if (!((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q)
+                && (ioc->facts.MsgVersion >= MPI_VERSION_01_05)) &&
+               (ioc_raw_state & MPI_DOORBELL_ACTIVE)) {
                printk(MYIOC_s_WARN_FMT
                        "TaskMgmt type=%x: ioc_state: "
                        "DOORBELL_ACTIVE (0x%x)!\n",
@@ -1728,7 +1736,9 @@ mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun,
                printk(MYIOC_s_WARN_FMT
                       "Issuing Reset from %s!! doorbell=0x%08x\n",
                       ioc->name, __func__, mpt_GetIocState(ioc, 0));
-               retval = mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);
+               retval = (ioc->bus_type == SAS) ?
+                       mpt_HardResetHandler(ioc, CAN_SLEEP) :
+                       mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);
                mpt_free_msg_frame(ioc, mf);
        }
 
index 45a5ff3eff6191cd91e3d2dfcb5936567ff5e46f..43e75ff39921b6556e8e2acb36685dc227d4961e 100644 (file)
@@ -135,3 +135,4 @@ extern int mptscsih_is_phys_disk(MPT_ADAPTER *ioc, u8 channel, u8 id);
 extern struct device_attribute *mptscsih_host_attrs[];
 extern struct scsi_cmnd        *mptscsih_get_scsi_lookup(MPT_ADAPTER *ioc, int i);
 extern void mptscsih_taskmgmt_response_code(MPT_ADAPTER *ioc, u8 response_code);
+extern void mptscsih_flush_running_cmds(MPT_SCSI_HOST *hd);
index 24d436c2fe4ac85998f097480231ef0dc89ca22f..268f80fd04394e2e7abca10d065d0be20625d37e 100644 (file)
@@ -34,7 +34,7 @@
 #include <linux/mfd/core.h>
 #include <linux/mfd/twl6040.h>
 
-static struct platform_device *twl6040_dev;
+#define VIBRACTRL_MEMBER(reg) ((reg == TWL6040_REG_VIBCTLL) ? 0 : 1)
 
 int twl6040_reg_read(struct twl6040 *twl6040, unsigned int reg)
 {
@@ -42,10 +42,16 @@ int twl6040_reg_read(struct twl6040 *twl6040, unsigned int reg)
        u8 val = 0;
 
        mutex_lock(&twl6040->io_mutex);
-       ret = twl_i2c_read_u8(TWL_MODULE_AUDIO_VOICE, &val, reg);
-       if (ret < 0) {
-               mutex_unlock(&twl6040->io_mutex);
-               return ret;
+       /* Vibra control registers from cache */
+       if (unlikely(reg == TWL6040_REG_VIBCTLL ||
+                    reg == TWL6040_REG_VIBCTLR)) {
+               val = twl6040->vibra_ctrl_cache[VIBRACTRL_MEMBER(reg)];
+       } else {
+               ret = twl_i2c_read_u8(TWL_MODULE_AUDIO_VOICE, &val, reg);
+               if (ret < 0) {
+                       mutex_unlock(&twl6040->io_mutex);
+                       return ret;
+               }
        }
        mutex_unlock(&twl6040->io_mutex);
 
@@ -59,6 +65,9 @@ int twl6040_reg_write(struct twl6040 *twl6040, unsigned int reg, u8 val)
 
        mutex_lock(&twl6040->io_mutex);
        ret = twl_i2c_write_u8(TWL_MODULE_AUDIO_VOICE, val, reg);
+       /* Cache the vibra control registers */
+       if (reg == TWL6040_REG_VIBCTLL || reg == TWL6040_REG_VIBCTLR)
+               twl6040->vibra_ctrl_cache[VIBRACTRL_MEMBER(reg)] = val;
        mutex_unlock(&twl6040->io_mutex);
 
        return ret;
@@ -203,11 +212,11 @@ static irqreturn_t twl6040_naudint_handler(int irq, void *data)
        if (intid & TWL6040_THINT) {
                status = twl6040_reg_read(twl6040, TWL6040_REG_STATUS);
                if (status & TWL6040_TSHUTDET) {
-                       dev_warn(&twl6040_dev->dev,
+                       dev_warn(twl6040->dev,
                                 "Thermal shutdown, powering-off");
                        twl6040_power(twl6040, 0);
                } else {
-                       dev_warn(&twl6040_dev->dev,
+                       dev_warn(twl6040->dev,
                                 "Leaving thermal shutdown, powering-on");
                        twl6040_power(twl6040, 1);
                }
@@ -227,7 +236,7 @@ static int twl6040_power_up_completion(struct twl6040 *twl6040,
        if (!time_left) {
                intid = twl6040_reg_read(twl6040, TWL6040_REG_INTID);
                if (!(intid & TWL6040_READYINT)) {
-                       dev_err(&twl6040_dev->dev,
+                       dev_err(twl6040->dev,
                                "timeout waiting for READYINT\n");
                        return -ETIMEDOUT;
                }
@@ -255,7 +264,7 @@ int twl6040_power(struct twl6040 *twl6040, int on)
                        /* wait for power-up completion */
                        ret = twl6040_power_up_completion(twl6040, naudint);
                        if (ret) {
-                               dev_err(&twl6040_dev->dev,
+                               dev_err(twl6040->dev,
                                        "automatic power-down failed\n");
                                twl6040->power_count = 0;
                                goto out;
@@ -264,7 +273,7 @@ int twl6040_power(struct twl6040 *twl6040, int on)
                        /* use manual power-up sequence */
                        ret = twl6040_power_up(twl6040);
                        if (ret) {
-                               dev_err(&twl6040_dev->dev,
+                               dev_err(twl6040->dev,
                                        "manual power-up failed\n");
                                twl6040->power_count = 0;
                                goto out;
@@ -276,7 +285,7 @@ int twl6040_power(struct twl6040 *twl6040, int on)
        } else {
                /* already powered-down */
                if (!twl6040->power_count) {
-                       dev_err(&twl6040_dev->dev,
+                       dev_err(twl6040->dev,
                                "device is already powered-off\n");
                        ret = -EPERM;
                        goto out;
@@ -326,7 +335,7 @@ int twl6040_set_pll(struct twl6040 *twl6040, int pll_id,
                        lppllctl &= ~TWL6040_LPLLFIN;
                        break;
                default:
-                       dev_err(&twl6040_dev->dev,
+                       dev_err(twl6040->dev,
                                "freq_out %d not supported\n", freq_out);
                        ret = -EINVAL;
                        goto pll_out;
@@ -347,7 +356,7 @@ int twl6040_set_pll(struct twl6040 *twl6040, int pll_id,
                                          hppllctl);
                        break;
                default:
-                       dev_err(&twl6040_dev->dev,
+                       dev_err(twl6040->dev,
                                "freq_in %d not supported\n", freq_in);
                        ret = -EINVAL;
                        goto pll_out;
@@ -356,7 +365,7 @@ int twl6040_set_pll(struct twl6040 *twl6040, int pll_id,
        case TWL6040_SYSCLK_SEL_HPPLL:
                /* high-performance PLL can provide only 19.2 MHz */
                if (freq_out != 19200000) {
-                       dev_err(&twl6040_dev->dev,
+                       dev_err(twl6040->dev,
                                "freq_out %d not supported\n", freq_out);
                        ret = -EINVAL;
                        goto pll_out;
@@ -389,7 +398,7 @@ int twl6040_set_pll(struct twl6040 *twl6040, int pll_id,
                                    TWL6040_HPLLENA;
                        break;
                default:
-                       dev_err(&twl6040_dev->dev,
+                       dev_err(twl6040->dev,
                                "freq_in %d not supported\n", freq_in);
                        ret = -EINVAL;
                        goto pll_out;
@@ -406,7 +415,7 @@ int twl6040_set_pll(struct twl6040 *twl6040, int pll_id,
                twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, lppllctl);
                break;
        default:
-               dev_err(&twl6040_dev->dev, "unknown pll id %d\n", pll_id);
+               dev_err(twl6040->dev, "unknown pll id %d\n", pll_id);
                ret = -EINVAL;
                goto pll_out;
        }
@@ -435,6 +444,18 @@ unsigned int twl6040_get_sysclk(struct twl6040 *twl6040)
 }
 EXPORT_SYMBOL(twl6040_get_sysclk);
 
+/* Get the combined status of the vibra control register */
+int twl6040_get_vibralr_status(struct twl6040 *twl6040)
+{
+       u8 status;
+
+       status = twl6040->vibra_ctrl_cache[0] | twl6040->vibra_ctrl_cache[1];
+       status &= (TWL6040_VIBENA | TWL6040_VIBSEL);
+
+       return status;
+}
+EXPORT_SYMBOL(twl6040_get_vibralr_status);
+
 static struct resource twl6040_vibra_rsrc[] = {
        {
                .flags = IORESOURCE_IRQ,
@@ -471,9 +492,7 @@ static int __devinit twl6040_probe(struct platform_device *pdev)
 
        platform_set_drvdata(pdev, twl6040);
 
-       twl6040_dev = pdev;
        twl6040->dev = &pdev->dev;
-       twl6040->audpwron = pdata->audpwron_gpio;
        twl6040->irq = pdata->naudint_irq;
        twl6040->irq_base = pdata->irq_base;
 
@@ -483,6 +502,12 @@ static int __devinit twl6040_probe(struct platform_device *pdev)
 
        twl6040->rev = twl6040_reg_read(twl6040, TWL6040_REG_ASICREV);
 
+       /* ERRATA: Automatic power-up is not possible in ES1.0 */
+       if (twl6040_get_revid(twl6040) > TWL6040_REV_ES1_0)
+               twl6040->audpwron = pdata->audpwron_gpio;
+       else
+               twl6040->audpwron = -EINVAL;
+
        if (gpio_is_valid(twl6040->audpwron)) {
                ret = gpio_request(twl6040->audpwron, "audpwron");
                if (ret)
@@ -493,10 +518,6 @@ static int __devinit twl6040_probe(struct platform_device *pdev)
                        goto gpio2_err;
        }
 
-       /* ERRATA: Automatic power-up is not possible in ES1.0 */
-       if (twl6040->rev == TWL6040_REV_ES1_0)
-               twl6040->audpwron = -EINVAL;
-
        /* codec interrupt */
        ret = twl6040_irq_init(twl6040);
        if (ret)
@@ -566,7 +587,6 @@ gpio2_err:
 gpio1_err:
        platform_set_drvdata(pdev, NULL);
        kfree(twl6040);
-       twl6040_dev = NULL;
        return ret;
 }
 
@@ -586,7 +606,6 @@ static int __devexit twl6040_remove(struct platform_device *pdev)
        mfd_remove_devices(&pdev->dev);
        platform_set_drvdata(pdev, NULL);
        kfree(twl6040);
-       twl6040_dev = NULL;
 
        return 0;
 }
index bfde4e8ec6381a5cb0b230009fe834c02703429f..b03be1d4e0caf62741beaa1c2e65dec3e9718b6e 100644 (file)
@@ -167,6 +167,18 @@ static struct mfd_cell wm8994_devs[] = {
  * and should be handled via the standard regulator API supply
  * management.
  */
+static const char *wm1811_main_supplies[] = {
+       "DBVDD1",
+       "DBVDD2",
+       "DBVDD3",
+       "DCVDD",
+       "AVDD1",
+       "AVDD2",
+       "CPVDD",
+       "SPKVDD1",
+       "SPKVDD2",
+};
+
 static const char *wm8994_main_supplies[] = {
        "DBVDD",
        "DCVDD",
@@ -329,6 +341,9 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq)
        }
 
        switch (wm8994->type) {
+       case WM1811:
+               wm8994->num_supplies = ARRAY_SIZE(wm1811_main_supplies);
+               break;
        case WM8994:
                wm8994->num_supplies = ARRAY_SIZE(wm8994_main_supplies);
                break;
@@ -349,6 +364,10 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq)
        }
 
        switch (wm8994->type) {
+       case WM1811:
+               for (i = 0; i < ARRAY_SIZE(wm1811_main_supplies); i++)
+                       wm8994->supplies[i].supply = wm1811_main_supplies[i];
+               break;
        case WM8994:
                for (i = 0; i < ARRAY_SIZE(wm8994_main_supplies); i++)
                        wm8994->supplies[i].supply = wm8994_main_supplies[i];
@@ -382,6 +401,13 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq)
                goto err_enable;
        }
        switch (ret) {
+       case 0x1811:
+               devname = "WM1811";
+               if (wm8994->type != WM1811)
+                       dev_warn(wm8994->dev, "Device registered as type %d\n",
+                                wm8994->type);
+               wm8994->type = WM1811;
+               break;
        case 0x8994:
                devname = "WM8994";
                if (wm8994->type != WM8994)
@@ -539,6 +565,7 @@ static int wm8994_i2c_remove(struct i2c_client *i2c)
 }
 
 static const struct i2c_device_id wm8994_i2c_id[] = {
+       { "wm1811", WM1811 },
        { "wm8994", WM8994 },
        { "wm8958", WM8958 },
        { }
index 2d6423c2d19340015c9f4be263342387db661d9a..50d5f27f09d0bb85c110fce0468bb01af9022eba 100644 (file)
@@ -506,5 +506,6 @@ source "drivers/misc/iwmc3200top/Kconfig"
 source "drivers/misc/ti-st/Kconfig"
 source "drivers/misc/lis3lv02d/Kconfig"
 source "drivers/misc/carma/Kconfig"
+source "drivers/misc/altera-stapl/Kconfig"
 
 endif # MISC_DEVICES
index 8f3efb68a141889e591b08925da27b3d63d8be7c..b26495a0255494d7c1ee03f987d4a12ac39b8196 100644 (file)
@@ -47,3 +47,4 @@ obj-$(CONFIG_AB8500_PWM)      += ab8500-pwm.o
 obj-y                          += lis3lv02d/
 obj-y                          += carma/
 obj-$(CONFIG_USB_SWITCH_FSA9480) += fsa9480.o
+obj-$(CONFIG_ALTERA_STAPL)     +=altera-stapl/
index 4ff73c215746688357ca5406e332b3ed320a5985..a39e0555df63e6443b816b933c069bb70c4477fd 100644 (file)
@@ -98,6 +98,7 @@ static const struct i2c_device_id ad_dpot_id[] = {
        {"ad5282", AD5282_ID},
        {"adn2860", ADN2860_ID},
        {"ad5273", AD5273_ID},
+       {"ad5161", AD5161_ID},
        {"ad5171", AD5171_ID},
        {"ad5170", AD5170_ID},
        {"ad5172", AD5172_ID},
similarity index 77%
rename from drivers/staging/altera-stapl/Kconfig
rename to drivers/misc/altera-stapl/Kconfig
index b6537321ed72ff14105257bec6cd2ead02cebb71..7f01d8e93992268df6ed51dd475afda5d7c84818 100644 (file)
@@ -1,3 +1,5 @@
+comment "Altera FPGA firmware download module"
+
 config ALTERA_STAPL
        tristate "Altera FPGA firmware download module"
        depends on I2C
diff --git a/drivers/misc/altera-stapl/Makefile b/drivers/misc/altera-stapl/Makefile
new file mode 100644 (file)
index 0000000..055f61e
--- /dev/null
@@ -0,0 +1,3 @@
+altera-stapl-objs = altera-lpt.o altera-jtag.o altera-comp.o altera.o
+
+obj-$(CONFIG_ALTERA_STAPL) += altera-stapl.o
similarity index 99%
rename from drivers/staging/altera-stapl/altera-jtag.c
rename to drivers/misc/altera-stapl/altera-jtag.c
index 8b1620b1b2d0b0f614004726a3814155d039c543..f4bf20096972f4b5804f6c643448c3ca609c79ff 100644 (file)
@@ -26,7 +26,7 @@
 #include <linux/delay.h>
 #include <linux/firmware.h>
 #include <linux/slab.h>
-#include "altera.h"
+#include <misc/altera.h>
 #include "altera-exprt.h"
 #include "altera-jtag.h"
 
similarity index 99%
rename from drivers/staging/altera-stapl/altera.c
rename to drivers/misc/altera-stapl/altera.c
index c2eff6a82db1fb3699f9a50f33085607f15ff44e..24272e022bec926f729d6cf26fd5953e63316ad7 100644 (file)
@@ -29,7 +29,7 @@
 #include <linux/firmware.h>
 #include <linux/slab.h>
 #include <linux/module.h>
-#include "altera.h"
+#include <misc/altera.h>
 #include "altera-exprt.h"
 #include "altera-jtag.h"
 
index 27dc0d21aafa36b73955105aa6097eb5c7836352..f6586d53e1a3a6d7314fb5c3bdcf34a61e956f7c 100644 (file)
@@ -400,7 +400,8 @@ static int fsa9480_irq_init(struct fsa9480_usbsw *usbsw)
                        return ret;
                }
 
-               device_init_wakeup(&client->dev, pdata->wakeup);
+               if (pdata)
+                       device_init_wakeup(&client->dev, pdata->wakeup);
        }
 
        return 0;
index 8b51cd62d067d3e5f614c65e7437d31bd6df90f8..29d12a70eb1bcbb2ccb08ab76f907057ee368021 100644 (file)
@@ -163,7 +163,7 @@ static void lis3lv02d_get_xyz(struct lis3lv02d *lis3, int *x, int *y, int *z)
        int i;
 
        if (lis3->blkread) {
-               if (lis3_dev.whoami == WAI_12B) {
+               if (lis3->whoami == WAI_12B) {
                        u16 data[3];
                        lis3->blkread(lis3, OUTX_L, 6, (u8 *)data);
                        for (i = 0; i < 3; i++)
@@ -195,18 +195,30 @@ static int lis3_8_rates[2] = {100, 400};
 static int lis3_3dc_rates[16] = {0, 1, 10, 25, 50, 100, 200, 400, 1600, 5000};
 
 /* ODR is Output Data Rate */
-static int lis3lv02d_get_odr(void)
+static int lis3lv02d_get_odr(struct lis3lv02d *lis3)
 {
        u8 ctrl;
        int shift;
 
-       lis3_dev.read(&lis3_dev, CTRL_REG1, &ctrl);
-       ctrl &= lis3_dev.odr_mask;
-       shift = ffs(lis3_dev.odr_mask) - 1;
-       return lis3_dev.odrs[(ctrl >> shift)];
+       lis3->read(lis3, CTRL_REG1, &ctrl);
+       ctrl &= lis3->odr_mask;
+       shift = ffs(lis3->odr_mask) - 1;
+       return lis3->odrs[(ctrl >> shift)];
 }
 
-static int lis3lv02d_set_odr(int rate)
+static int lis3lv02d_get_pwron_wait(struct lis3lv02d *lis3)
+{
+       int div = lis3lv02d_get_odr(lis3);
+
+       if (WARN_ONCE(div == 0, "device returned spurious data"))
+               return -ENXIO;
+
+       /* LIS3 power on delay is quite long */
+       msleep(lis3->pwron_delay / div);
+       return 0;
+}
+
+static int lis3lv02d_set_odr(struct lis3lv02d *lis3, int rate)
 {
        u8 ctrl;
        int i, len, shift;
@@ -214,14 +226,14 @@ static int lis3lv02d_set_odr(int rate)
        if (!rate)
                return -EINVAL;
 
-       lis3_dev.read(&lis3_dev, CTRL_REG1, &ctrl);
-       ctrl &= ~lis3_dev.odr_mask;
-       len = 1 << hweight_long(lis3_dev.odr_mask); /* # of possible values */
-       shift = ffs(lis3_dev.odr_mask) - 1;
+       lis3->read(lis3, CTRL_REG1, &ctrl);
+       ctrl &= ~lis3->odr_mask;
+       len = 1 << hweight_long(lis3->odr_mask); /* # of possible values */
+       shift = ffs(lis3->odr_mask) - 1;
 
        for (i = 0; i < len; i++)
-               if (lis3_dev.odrs[i] == rate) {
-                       lis3_dev.write(&lis3_dev, CTRL_REG1,
+               if (lis3->odrs[i] == rate) {
+                       lis3->write(lis3, CTRL_REG1,
                                        ctrl | (i << shift));
                        return 0;
                }
@@ -240,12 +252,12 @@ static int lis3lv02d_selftest(struct lis3lv02d *lis3, s16 results[3])
        mutex_lock(&lis3->mutex);
 
        irq_cfg = lis3->irq_cfg;
-       if (lis3_dev.whoami == WAI_8B) {
+       if (lis3->whoami == WAI_8B) {
                lis3->data_ready_count[IRQ_LINE0] = 0;
                lis3->data_ready_count[IRQ_LINE1] = 0;
 
                /* Change interrupt cfg to data ready for selftest */
-               atomic_inc(&lis3_dev.wake_thread);
+               atomic_inc(&lis3->wake_thread);
                lis3->irq_cfg = LIS3_IRQ1_DATA_READY | LIS3_IRQ2_DATA_READY;
                lis3->read(lis3, CTRL_REG3, &ctrl_reg_data);
                lis3->write(lis3, CTRL_REG3, (ctrl_reg_data &
@@ -253,12 +265,12 @@ static int lis3lv02d_selftest(struct lis3lv02d *lis3, s16 results[3])
                                (LIS3_IRQ1_DATA_READY | LIS3_IRQ2_DATA_READY));
        }
 
-       if (lis3_dev.whoami == WAI_3DC) {
+       if (lis3->whoami == WAI_3DC) {
                ctlreg = CTRL_REG4;
                selftest = CTRL4_ST0;
        } else {
                ctlreg = CTRL_REG1;
-               if (lis3_dev.whoami == WAI_12B)
+               if (lis3->whoami == WAI_12B)
                        selftest = CTRL1_ST;
                else
                        selftest = CTRL1_STP;
@@ -266,7 +278,9 @@ static int lis3lv02d_selftest(struct lis3lv02d *lis3, s16 results[3])
 
        lis3->read(lis3, ctlreg, &reg);
        lis3->write(lis3, ctlreg, (reg | selftest));
-       msleep(lis3->pwron_delay / lis3lv02d_get_odr());
+       ret = lis3lv02d_get_pwron_wait(lis3);
+       if (ret)
+               goto fail;
 
        /* Read directly to avoid axis remap */
        x = lis3->read_data(lis3, OUTX);
@@ -275,7 +289,9 @@ static int lis3lv02d_selftest(struct lis3lv02d *lis3, s16 results[3])
 
        /* back to normal settings */
        lis3->write(lis3, ctlreg, reg);
-       msleep(lis3->pwron_delay / lis3lv02d_get_odr());
+       ret = lis3lv02d_get_pwron_wait(lis3);
+       if (ret)
+               goto fail;
 
        results[0] = x - lis3->read_data(lis3, OUTX);
        results[1] = y - lis3->read_data(lis3, OUTY);
@@ -283,9 +299,9 @@ static int lis3lv02d_selftest(struct lis3lv02d *lis3, s16 results[3])
 
        ret = 0;
 
-       if (lis3_dev.whoami == WAI_8B) {
+       if (lis3->whoami == WAI_8B) {
                /* Restore original interrupt configuration */
-               atomic_dec(&lis3_dev.wake_thread);
+               atomic_dec(&lis3->wake_thread);
                lis3->write(lis3, CTRL_REG3, ctrl_reg_data);
                lis3->irq_cfg = irq_cfg;
 
@@ -363,8 +379,9 @@ void lis3lv02d_poweroff(struct lis3lv02d *lis3)
 }
 EXPORT_SYMBOL_GPL(lis3lv02d_poweroff);
 
-void lis3lv02d_poweron(struct lis3lv02d *lis3)
+int lis3lv02d_poweron(struct lis3lv02d *lis3)
 {
+       int err;
        u8 reg;
 
        lis3->init(lis3);
@@ -384,35 +401,41 @@ void lis3lv02d_poweron(struct lis3lv02d *lis3)
                lis3->write(lis3, CTRL_REG2, reg);
        }
 
-       /* LIS3 power on delay is quite long */
-       msleep(lis3->pwron_delay / lis3lv02d_get_odr());
+       err = lis3lv02d_get_pwron_wait(lis3);
+       if (err)
+               return err;
 
        if (lis3->reg_ctrl)
                lis3_context_restore(lis3);
+
+       return 0;
 }
 EXPORT_SYMBOL_GPL(lis3lv02d_poweron);
 
 
 static void lis3lv02d_joystick_poll(struct input_polled_dev *pidev)
 {
+       struct lis3lv02d *lis3 = pidev->private;
        int x, y, z;
 
-       mutex_lock(&lis3_dev.mutex);
-       lis3lv02d_get_xyz(&lis3_dev, &x, &y, &z);
+       mutex_lock(&lis3->mutex);
+       lis3lv02d_get_xyz(lis3, &x, &y, &z);
        input_report_abs(pidev->input, ABS_X, x);
        input_report_abs(pidev->input, ABS_Y, y);
        input_report_abs(pidev->input, ABS_Z, z);
        input_sync(pidev->input);
-       mutex_unlock(&lis3_dev.mutex);
+       mutex_unlock(&lis3->mutex);
 }
 
 static void lis3lv02d_joystick_open(struct input_polled_dev *pidev)
 {
-       if (lis3_dev.pm_dev)
-               pm_runtime_get_sync(lis3_dev.pm_dev);
+       struct lis3lv02d *lis3 = pidev->private;
 
-       if (lis3_dev.pdata && lis3_dev.whoami == WAI_8B && lis3_dev.idev)
-               atomic_set(&lis3_dev.wake_thread, 1);
+       if (lis3->pm_dev)
+               pm_runtime_get_sync(lis3->pm_dev);
+
+       if (lis3->pdata && lis3->whoami == WAI_8B && lis3->idev)
+               atomic_set(&lis3->wake_thread, 1);
        /*
         * Update coordinates for the case where poll interval is 0 and
         * the chip in running purely under interrupt control
@@ -422,14 +445,18 @@ static void lis3lv02d_joystick_open(struct input_polled_dev *pidev)
 
 static void lis3lv02d_joystick_close(struct input_polled_dev *pidev)
 {
-       atomic_set(&lis3_dev.wake_thread, 0);
-       if (lis3_dev.pm_dev)
-               pm_runtime_put(lis3_dev.pm_dev);
+       struct lis3lv02d *lis3 = pidev->private;
+
+       atomic_set(&lis3->wake_thread, 0);
+       if (lis3->pm_dev)
+               pm_runtime_put(lis3->pm_dev);
 }
 
-static irqreturn_t lis302dl_interrupt(int irq, void *dummy)
+static irqreturn_t lis302dl_interrupt(int irq, void *data)
 {
-       if (!test_bit(0, &lis3_dev.misc_opened))
+       struct lis3lv02d *lis3 = data;
+
+       if (!test_bit(0, &lis3->misc_opened))
                goto out;
 
        /*
@@ -437,12 +464,12 @@ static irqreturn_t lis302dl_interrupt(int irq, void *dummy)
         * the lid is closed. This leads to interrupts as soon as a little move
         * is done.
         */
-       atomic_inc(&lis3_dev.count);
+       atomic_inc(&lis3->count);
 
-       wake_up_interruptible(&lis3_dev.misc_wait);
-       kill_fasync(&lis3_dev.async_queue, SIGIO, POLL_IN);
+       wake_up_interruptible(&lis3->misc_wait);
+       kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
 out:
-       if (atomic_read(&lis3_dev.wake_thread))
+       if (atomic_read(&lis3->wake_thread))
                return IRQ_WAKE_THREAD;
        return IRQ_HANDLED;
 }
@@ -514,28 +541,37 @@ static irqreturn_t lis302dl_interrupt_thread2_8b(int irq, void *data)
 
 static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
 {
-       if (test_and_set_bit(0, &lis3_dev.misc_opened))
+       struct lis3lv02d *lis3 = container_of(file->private_data,
+                                             struct lis3lv02d, miscdev);
+
+       if (test_and_set_bit(0, &lis3->misc_opened))
                return -EBUSY; /* already open */
 
-       if (lis3_dev.pm_dev)
-               pm_runtime_get_sync(lis3_dev.pm_dev);
+       if (lis3->pm_dev)
+               pm_runtime_get_sync(lis3->pm_dev);
 
-       atomic_set(&lis3_dev.count, 0);
+       atomic_set(&lis3->count, 0);
        return 0;
 }
 
 static int lis3lv02d_misc_release(struct inode *inode, struct file *file)
 {
-       fasync_helper(-1, file, 0, &lis3_dev.async_queue);
-       clear_bit(0, &lis3_dev.misc_opened); /* release the device */
-       if (lis3_dev.pm_dev)
-               pm_runtime_put(lis3_dev.pm_dev);
+       struct lis3lv02d *lis3 = container_of(file->private_data,
+                                             struct lis3lv02d, miscdev);
+
+       fasync_helper(-1, file, 0, &lis3->async_queue);
+       clear_bit(0, &lis3->misc_opened); /* release the device */
+       if (lis3->pm_dev)
+               pm_runtime_put(lis3->pm_dev);
        return 0;
 }
 
 static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
                                size_t count, loff_t *pos)
 {
+       struct lis3lv02d *lis3 = container_of(file->private_data,
+                                             struct lis3lv02d, miscdev);
+
        DECLARE_WAITQUEUE(wait, current);
        u32 data;
        unsigned char byte_data;
@@ -544,10 +580,10 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
        if (count < 1)
                return -EINVAL;
 
-       add_wait_queue(&lis3_dev.misc_wait, &wait);
+       add_wait_queue(&lis3->misc_wait, &wait);
        while (true) {
                set_current_state(TASK_INTERRUPTIBLE);
-               data = atomic_xchg(&lis3_dev.count, 0);
+               data = atomic_xchg(&lis3->count, 0);
                if (data)
                        break;
 
@@ -577,22 +613,28 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
 
 out:
        __set_current_state(TASK_RUNNING);
-       remove_wait_queue(&lis3_dev.misc_wait, &wait);
+       remove_wait_queue(&lis3->misc_wait, &wait);
 
        return retval;
 }
 
 static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
 {
-       poll_wait(file, &lis3_dev.misc_wait, wait);
-       if (atomic_read(&lis3_dev.count))
+       struct lis3lv02d *lis3 = container_of(file->private_data,
+                                             struct lis3lv02d, miscdev);
+
+       poll_wait(file, &lis3->misc_wait, wait);
+       if (atomic_read(&lis3->count))
                return POLLIN | POLLRDNORM;
        return 0;
 }
 
 static int lis3lv02d_misc_fasync(int fd, struct file *file, int on)
 {
-       return fasync_helper(fd, file, on, &lis3_dev.async_queue);
+       struct lis3lv02d *lis3 = container_of(file->private_data,
+                                             struct lis3lv02d, miscdev);
+
+       return fasync_helper(fd, file, on, &lis3->async_queue);
 }
 
 static const struct file_operations lis3lv02d_misc_fops = {
@@ -605,85 +647,80 @@ static const struct file_operations lis3lv02d_misc_fops = {
        .fasync  = lis3lv02d_misc_fasync,
 };
 
-static struct miscdevice lis3lv02d_misc_device = {
-       .minor   = MISC_DYNAMIC_MINOR,
-       .name    = "freefall",
-       .fops    = &lis3lv02d_misc_fops,
-};
-
-int lis3lv02d_joystick_enable(void)
+int lis3lv02d_joystick_enable(struct lis3lv02d *lis3)
 {
        struct input_dev *input_dev;
        int err;
        int max_val, fuzz, flat;
        int btns[] = {BTN_X, BTN_Y, BTN_Z};
 
-       if (lis3_dev.idev)
+       if (lis3->idev)
                return -EINVAL;
 
-       lis3_dev.idev = input_allocate_polled_device();
-       if (!lis3_dev.idev)
+       lis3->idev = input_allocate_polled_device();
+       if (!lis3->idev)
                return -ENOMEM;
 
-       lis3_dev.idev->poll = lis3lv02d_joystick_poll;
-       lis3_dev.idev->open = lis3lv02d_joystick_open;
-       lis3_dev.idev->close = lis3lv02d_joystick_close;
-       lis3_dev.idev->poll_interval = MDPS_POLL_INTERVAL;
-       lis3_dev.idev->poll_interval_min = MDPS_POLL_MIN;
-       lis3_dev.idev->poll_interval_max = MDPS_POLL_MAX;
-       input_dev = lis3_dev.idev->input;
+       lis3->idev->poll = lis3lv02d_joystick_poll;
+       lis3->idev->open = lis3lv02d_joystick_open;
+       lis3->idev->close = lis3lv02d_joystick_close;
+       lis3->idev->poll_interval = MDPS_POLL_INTERVAL;
+       lis3->idev->poll_interval_min = MDPS_POLL_MIN;
+       lis3->idev->poll_interval_max = MDPS_POLL_MAX;
+       lis3->idev->private = lis3;
+       input_dev = lis3->idev->input;
 
        input_dev->name       = "ST LIS3LV02DL Accelerometer";
        input_dev->phys       = DRIVER_NAME "/input0";
        input_dev->id.bustype = BUS_HOST;
        input_dev->id.vendor  = 0;
-       input_dev->dev.parent = &lis3_dev.pdev->dev;
+       input_dev->dev.parent = &lis3->pdev->dev;
 
        set_bit(EV_ABS, input_dev->evbit);
-       max_val = (lis3_dev.mdps_max_val * lis3_dev.scale) / LIS3_ACCURACY;
-       if (lis3_dev.whoami == WAI_12B) {
+       max_val = (lis3->mdps_max_val * lis3->scale) / LIS3_ACCURACY;
+       if (lis3->whoami == WAI_12B) {
                fuzz = LIS3_DEFAULT_FUZZ_12B;
                flat = LIS3_DEFAULT_FLAT_12B;
        } else {
                fuzz = LIS3_DEFAULT_FUZZ_8B;
                flat = LIS3_DEFAULT_FLAT_8B;
        }
-       fuzz = (fuzz * lis3_dev.scale) / LIS3_ACCURACY;
-       flat = (flat * lis3_dev.scale) / LIS3_ACCURACY;
+       fuzz = (fuzz * lis3->scale) / LIS3_ACCURACY;
+       flat = (flat * lis3->scale) / LIS3_ACCURACY;
 
        input_set_abs_params(input_dev, ABS_X, -max_val, max_val, fuzz, flat);
        input_set_abs_params(input_dev, ABS_Y, -max_val, max_val, fuzz, flat);
        input_set_abs_params(input_dev, ABS_Z, -max_val, max_val, fuzz, flat);
 
-       lis3_dev.mapped_btns[0] = lis3lv02d_get_axis(abs(lis3_dev.ac.x), btns);
-       lis3_dev.mapped_btns[1] = lis3lv02d_get_axis(abs(lis3_dev.ac.y), btns);
-       lis3_dev.mapped_btns[2] = lis3lv02d_get_axis(abs(lis3_dev.ac.z), btns);
+       lis3->mapped_btns[0] = lis3lv02d_get_axis(abs(lis3->ac.x), btns);
+       lis3->mapped_btns[1] = lis3lv02d_get_axis(abs(lis3->ac.y), btns);
+       lis3->mapped_btns[2] = lis3lv02d_get_axis(abs(lis3->ac.z), btns);
 
-       err = input_register_polled_device(lis3_dev.idev);
+       err = input_register_polled_device(lis3->idev);
        if (err) {
-               input_free_polled_device(lis3_dev.idev);
-               lis3_dev.idev = NULL;
+               input_free_polled_device(lis3->idev);
+               lis3->idev = NULL;
        }
 
        return err;
 }
 EXPORT_SYMBOL_GPL(lis3lv02d_joystick_enable);
 
-void lis3lv02d_joystick_disable(void)
+void lis3lv02d_joystick_disable(struct lis3lv02d *lis3)
 {
-       if (lis3_dev.irq)
-               free_irq(lis3_dev.irq, &lis3_dev);
-       if (lis3_dev.pdata && lis3_dev.pdata->irq2)
-               free_irq(lis3_dev.pdata->irq2, &lis3_dev);
+       if (lis3->irq)
+               free_irq(lis3->irq, lis3);
+       if (lis3->pdata && lis3->pdata->irq2)
+               free_irq(lis3->pdata->irq2, lis3);
 
-       if (!lis3_dev.idev)
+       if (!lis3->idev)
                return;
 
-       if (lis3_dev.irq)
-               misc_deregister(&lis3lv02d_misc_device);
-       input_unregister_polled_device(lis3_dev.idev);
-       input_free_polled_device(lis3_dev.idev);
-       lis3_dev.idev = NULL;
+       if (lis3->irq)
+               misc_deregister(&lis3->miscdev);
+       input_unregister_polled_device(lis3->idev);
+       input_free_polled_device(lis3->idev);
+       lis3->idev = NULL;
 }
 EXPORT_SYMBOL_GPL(lis3lv02d_joystick_disable);
 
@@ -708,6 +745,7 @@ static void lis3lv02d_sysfs_poweron(struct lis3lv02d *lis3)
 static ssize_t lis3lv02d_selftest_show(struct device *dev,
                                struct device_attribute *attr, char *buf)
 {
+       struct lis3lv02d *lis3 = dev_get_drvdata(dev);
        s16 values[3];
 
        static const char ok[] = "OK";
@@ -715,8 +753,8 @@ static ssize_t lis3lv02d_selftest_show(struct device *dev,
        static const char irq[] = "FAIL_IRQ";
        const char *res;
 
-       lis3lv02d_sysfs_poweron(&lis3_dev);
-       switch (lis3lv02d_selftest(&lis3_dev, values)) {
+       lis3lv02d_sysfs_poweron(lis3);
+       switch (lis3lv02d_selftest(lis3, values)) {
        case SELFTEST_FAIL:
                res = fail;
                break;
@@ -735,33 +773,37 @@ static ssize_t lis3lv02d_selftest_show(struct device *dev,
 static ssize_t lis3lv02d_position_show(struct device *dev,
                                struct device_attribute *attr, char *buf)
 {
+       struct lis3lv02d *lis3 = dev_get_drvdata(dev);
        int x, y, z;
 
-       lis3lv02d_sysfs_poweron(&lis3_dev);
-       mutex_lock(&lis3_dev.mutex);
-       lis3lv02d_get_xyz(&lis3_dev, &x, &y, &z);
-       mutex_unlock(&lis3_dev.mutex);
+       lis3lv02d_sysfs_poweron(lis3);
+       mutex_lock(&lis3->mutex);
+       lis3lv02d_get_xyz(lis3, &x, &y, &z);
+       mutex_unlock(&lis3->mutex);
        return sprintf(buf, "(%d,%d,%d)\n", x, y, z);
 }
 
 static ssize_t lis3lv02d_rate_show(struct device *dev,
                        struct device_attribute *attr, char *buf)
 {
-       lis3lv02d_sysfs_poweron(&lis3_dev);
-       return sprintf(buf, "%d\n", lis3lv02d_get_odr());
+       struct lis3lv02d *lis3 = dev_get_drvdata(dev);
+
+       lis3lv02d_sysfs_poweron(lis3);
+       return sprintf(buf, "%d\n", lis3lv02d_get_odr(lis3));
 }
 
 static ssize_t lis3lv02d_rate_set(struct device *dev,
                                struct device_attribute *attr, const char *buf,
                                size_t count)
 {
+       struct lis3lv02d *lis3 = dev_get_drvdata(dev);
        unsigned long rate;
 
        if (strict_strtoul(buf, 0, &rate))
                return -EINVAL;
 
-       lis3lv02d_sysfs_poweron(&lis3_dev);
-       if (lis3lv02d_set_odr(rate))
+       lis3lv02d_sysfs_poweron(lis3);
+       if (lis3lv02d_set_odr(lis3, rate))
                return -EINVAL;
 
        return count;
@@ -790,6 +832,7 @@ static int lis3lv02d_add_fs(struct lis3lv02d *lis3)
        if (IS_ERR(lis3->pdev))
                return PTR_ERR(lis3->pdev);
 
+       platform_set_drvdata(lis3->pdev, lis3);
        return sysfs_create_group(&lis3->pdev->dev.kobj, &lis3lv02d_attribute_group);
 }
 
@@ -803,7 +846,7 @@ int lis3lv02d_remove_fs(struct lis3lv02d *lis3)
 
                /* SYSFS may have left chip running. Turn off if necessary */
                if (!pm_runtime_suspended(lis3->pm_dev))
-                       lis3lv02d_poweroff(&lis3_dev);
+                       lis3lv02d_poweroff(lis3);
 
                pm_runtime_disable(lis3->pm_dev);
                pm_runtime_set_suspended(lis3->pm_dev);
@@ -813,24 +856,24 @@ int lis3lv02d_remove_fs(struct lis3lv02d *lis3)
 }
 EXPORT_SYMBOL_GPL(lis3lv02d_remove_fs);
 
-static void lis3lv02d_8b_configure(struct lis3lv02d *dev,
+static void lis3lv02d_8b_configure(struct lis3lv02d *lis3,
                                struct lis3lv02d_platform_data *p)
 {
        int err;
        int ctrl2 = p->hipass_ctrl;
 
        if (p->click_flags) {
-               dev->write(dev, CLICK_CFG, p->click_flags);
-               dev->write(dev, CLICK_TIMELIMIT, p->click_time_limit);
-               dev->write(dev, CLICK_LATENCY, p->click_latency);
-               dev->write(dev, CLICK_WINDOW, p->click_window);
-               dev->write(dev, CLICK_THSZ, p->click_thresh_z & 0xf);
-               dev->write(dev, CLICK_THSY_X,
+               lis3->write(lis3, CLICK_CFG, p->click_flags);
+               lis3->write(lis3, CLICK_TIMELIMIT, p->click_time_limit);
+               lis3->write(lis3, CLICK_LATENCY, p->click_latency);
+               lis3->write(lis3, CLICK_WINDOW, p->click_window);
+               lis3->write(lis3, CLICK_THSZ, p->click_thresh_z & 0xf);
+               lis3->write(lis3, CLICK_THSY_X,
                        (p->click_thresh_x & 0xf) |
                        (p->click_thresh_y << 4));
 
-               if (dev->idev) {
-                       struct input_dev *input_dev = lis3_dev.idev->input;
+               if (lis3->idev) {
+                       struct input_dev *input_dev = lis3->idev->input;
                        input_set_capability(input_dev, EV_KEY, BTN_X);
                        input_set_capability(input_dev, EV_KEY, BTN_Y);
                        input_set_capability(input_dev, EV_KEY, BTN_Z);
@@ -838,22 +881,22 @@ static void lis3lv02d_8b_configure(struct lis3lv02d *dev,
        }
 
        if (p->wakeup_flags) {
-               dev->write(dev, FF_WU_CFG_1, p->wakeup_flags);
-               dev->write(dev, FF_WU_THS_1, p->wakeup_thresh & 0x7f);
+               lis3->write(lis3, FF_WU_CFG_1, p->wakeup_flags);
+               lis3->write(lis3, FF_WU_THS_1, p->wakeup_thresh & 0x7f);
                /* pdata value + 1 to keep this backward compatible*/
-               dev->write(dev, FF_WU_DURATION_1, p->duration1 + 1);
+               lis3->write(lis3, FF_WU_DURATION_1, p->duration1 + 1);
                ctrl2 ^= HP_FF_WU1; /* Xor to keep compatible with old pdata*/
        }
 
        if (p->wakeup_flags2) {
-               dev->write(dev, FF_WU_CFG_2, p->wakeup_flags2);
-               dev->write(dev, FF_WU_THS_2, p->wakeup_thresh2 & 0x7f);
+               lis3->write(lis3, FF_WU_CFG_2, p->wakeup_flags2);
+               lis3->write(lis3, FF_WU_THS_2, p->wakeup_thresh2 & 0x7f);
                /* pdata value + 1 to keep this backward compatible*/
-               dev->write(dev, FF_WU_DURATION_2, p->duration2 + 1);
+               lis3->write(lis3, FF_WU_DURATION_2, p->duration2 + 1);
                ctrl2 ^= HP_FF_WU2; /* Xor to keep compatible with old pdata*/
        }
        /* Configure hipass filters */
-       dev->write(dev, CTRL_REG2, ctrl2);
+       lis3->write(lis3, CTRL_REG2, ctrl2);
 
        if (p->irq2) {
                err = request_threaded_irq(p->irq2,
@@ -861,7 +904,7 @@ static void lis3lv02d_8b_configure(struct lis3lv02d *dev,
                                        lis302dl_interrupt_thread2_8b,
                                        IRQF_TRIGGER_RISING | IRQF_ONESHOT |
                                        (p->irq_flags2 & IRQF_TRIGGER_MASK),
-                                       DRIVER_NAME, &lis3_dev);
+                                       DRIVER_NAME, lis3);
                if (err < 0)
                        pr_err("No second IRQ. Limited functionality\n");
        }
@@ -871,93 +914,97 @@ static void lis3lv02d_8b_configure(struct lis3lv02d *dev,
  * Initialise the accelerometer and the various subsystems.
  * Should be rather independent of the bus system.
  */
-int lis3lv02d_init_device(struct lis3lv02d *dev)
+int lis3lv02d_init_device(struct lis3lv02d *lis3)
 {
        int err;
        irq_handler_t thread_fn;
        int irq_flags = 0;
 
-       dev->whoami = lis3lv02d_read_8(dev, WHO_AM_I);
+       lis3->whoami = lis3lv02d_read_8(lis3, WHO_AM_I);
 
-       switch (dev->whoami) {
+       switch (lis3->whoami) {
        case WAI_12B:
                pr_info("12 bits sensor found\n");
-               dev->read_data = lis3lv02d_read_12;
-               dev->mdps_max_val = 2048;
-               dev->pwron_delay = LIS3_PWRON_DELAY_WAI_12B;
-               dev->odrs = lis3_12_rates;
-               dev->odr_mask = CTRL1_DF0 | CTRL1_DF1;
-               dev->scale = LIS3_SENSITIVITY_12B;
-               dev->regs = lis3_wai12_regs;
-               dev->regs_size = ARRAY_SIZE(lis3_wai12_regs);
+               lis3->read_data = lis3lv02d_read_12;
+               lis3->mdps_max_val = 2048;
+               lis3->pwron_delay = LIS3_PWRON_DELAY_WAI_12B;
+               lis3->odrs = lis3_12_rates;
+               lis3->odr_mask = CTRL1_DF0 | CTRL1_DF1;
+               lis3->scale = LIS3_SENSITIVITY_12B;
+               lis3->regs = lis3_wai12_regs;
+               lis3->regs_size = ARRAY_SIZE(lis3_wai12_regs);
                break;
        case WAI_8B:
                pr_info("8 bits sensor found\n");
-               dev->read_data = lis3lv02d_read_8;
-               dev->mdps_max_val = 128;
-               dev->pwron_delay = LIS3_PWRON_DELAY_WAI_8B;
-               dev->odrs = lis3_8_rates;
-               dev->odr_mask = CTRL1_DR;
-               dev->scale = LIS3_SENSITIVITY_8B;
-               dev->regs = lis3_wai8_regs;
-               dev->regs_size = ARRAY_SIZE(lis3_wai8_regs);
+               lis3->read_data = lis3lv02d_read_8;
+               lis3->mdps_max_val = 128;
+               lis3->pwron_delay = LIS3_PWRON_DELAY_WAI_8B;
+               lis3->odrs = lis3_8_rates;
+               lis3->odr_mask = CTRL1_DR;
+               lis3->scale = LIS3_SENSITIVITY_8B;
+               lis3->regs = lis3_wai8_regs;
+               lis3->regs_size = ARRAY_SIZE(lis3_wai8_regs);
                break;
        case WAI_3DC:
                pr_info("8 bits 3DC sensor found\n");
-               dev->read_data = lis3lv02d_read_8;
-               dev->mdps_max_val = 128;
-               dev->pwron_delay = LIS3_PWRON_DELAY_WAI_8B;
-               dev->odrs = lis3_3dc_rates;
-               dev->odr_mask = CTRL1_ODR0|CTRL1_ODR1|CTRL1_ODR2|CTRL1_ODR3;
-               dev->scale = LIS3_SENSITIVITY_8B;
+               lis3->read_data = lis3lv02d_read_8;
+               lis3->mdps_max_val = 128;
+               lis3->pwron_delay = LIS3_PWRON_DELAY_WAI_8B;
+               lis3->odrs = lis3_3dc_rates;
+               lis3->odr_mask = CTRL1_ODR0|CTRL1_ODR1|CTRL1_ODR2|CTRL1_ODR3;
+               lis3->scale = LIS3_SENSITIVITY_8B;
                break;
        default:
-               pr_err("unknown sensor type 0x%X\n", dev->whoami);
+               pr_err("unknown sensor type 0x%X\n", lis3->whoami);
                return -EINVAL;
        }
 
-       dev->reg_cache = kzalloc(max(sizeof(lis3_wai8_regs),
+       lis3->reg_cache = kzalloc(max(sizeof(lis3_wai8_regs),
                                     sizeof(lis3_wai12_regs)), GFP_KERNEL);
 
-       if (dev->reg_cache == NULL) {
+       if (lis3->reg_cache == NULL) {
                printk(KERN_ERR DRIVER_NAME "out of memory\n");
                return -ENOMEM;
        }
 
-       mutex_init(&dev->mutex);
-       atomic_set(&dev->wake_thread, 0);
+       mutex_init(&lis3->mutex);
+       atomic_set(&lis3->wake_thread, 0);
 
-       lis3lv02d_add_fs(dev);
-       lis3lv02d_poweron(dev);
+       lis3lv02d_add_fs(lis3);
+       err = lis3lv02d_poweron(lis3);
+       if (err) {
+               lis3lv02d_remove_fs(lis3);
+               return err;
+       }
 
-       if (dev->pm_dev) {
-               pm_runtime_set_active(dev->pm_dev);
-               pm_runtime_enable(dev->pm_dev);
+       if (lis3->pm_dev) {
+               pm_runtime_set_active(lis3->pm_dev);
+               pm_runtime_enable(lis3->pm_dev);
        }
 
-       if (lis3lv02d_joystick_enable())
+       if (lis3lv02d_joystick_enable(lis3))
                pr_err("joystick initialization failed\n");
 
        /* passing in platform specific data is purely optional and only
         * used by the SPI transport layer at the moment */
-       if (dev->pdata) {
-               struct lis3lv02d_platform_data *p = dev->pdata;
+       if (lis3->pdata) {
+               struct lis3lv02d_platform_data *p = lis3->pdata;
 
-               if (dev->whoami == WAI_8B)
-                       lis3lv02d_8b_configure(dev, p);
+               if (lis3->whoami == WAI_8B)
+                       lis3lv02d_8b_configure(lis3, p);
 
                irq_flags = p->irq_flags1 & IRQF_TRIGGER_MASK;
 
-               dev->irq_cfg = p->irq_cfg;
+               lis3->irq_cfg = p->irq_cfg;
                if (p->irq_cfg)
-                       dev->write(dev, CTRL_REG3, p->irq_cfg);
+                       lis3->write(lis3, CTRL_REG3, p->irq_cfg);
 
                if (p->default_rate)
-                       lis3lv02d_set_odr(p->default_rate);
+                       lis3lv02d_set_odr(lis3, p->default_rate);
        }
 
        /* bail if we did not get an IRQ from the bus layer */
-       if (!dev->irq) {
+       if (!lis3->irq) {
                pr_debug("No IRQ. Disabling /dev/freefall\n");
                goto out;
        }
@@ -973,23 +1020,27 @@ int lis3lv02d_init_device(struct lis3lv02d *dev)
         * io-apic is not configurable (and generates a warning) but I keep it
         * in case of support for other hardware.
         */
-       if (dev->pdata && dev->whoami == WAI_8B)
+       if (lis3->pdata && lis3->whoami == WAI_8B)
                thread_fn = lis302dl_interrupt_thread1_8b;
        else
                thread_fn = NULL;
 
-       err = request_threaded_irq(dev->irq, lis302dl_interrupt,
+       err = request_threaded_irq(lis3->irq, lis302dl_interrupt,
                                thread_fn,
                                IRQF_TRIGGER_RISING | IRQF_ONESHOT |
                                irq_flags,
-                               DRIVER_NAME, &lis3_dev);
+                               DRIVER_NAME, lis3);
 
        if (err < 0) {
                pr_err("Cannot get IRQ\n");
                goto out;
        }
 
-       if (misc_register(&lis3lv02d_misc_device))
+       lis3->miscdev.minor     = MISC_DYNAMIC_MINOR;
+       lis3->miscdev.name      = "freefall";
+       lis3->miscdev.fops      = &lis3lv02d_misc_fops;
+
+       if (misc_register(&lis3->miscdev))
                pr_err("misc_register failed\n");
 out:
        return 0;
index a1939589eb2c47e9067ecc85911a19cede974503..2b1482ad3f16aedc776ef4429e6c9da7741c7d5a 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/platform_device.h>
 #include <linux/input-polldev.h>
 #include <linux/regulator/consumer.h>
+#include <linux/miscdevice.h>
 
 /*
  * This driver tries to support the "digital" accelerometer chips from
@@ -273,6 +274,8 @@ struct lis3lv02d {
        struct fasync_struct    *async_queue; /* queue for the misc device */
        wait_queue_head_t       misc_wait; /* Wait queue for the misc device */
        unsigned long           misc_opened; /* bit0: whether the device is open */
+       struct miscdevice       miscdev;
+
        int                     data_ready_count[2];
        atomic_t                wake_thread;
        unsigned char           irq_cfg;
@@ -282,10 +285,10 @@ struct lis3lv02d {
 };
 
 int lis3lv02d_init_device(struct lis3lv02d *lis3);
-int lis3lv02d_joystick_enable(void);
-void lis3lv02d_joystick_disable(void);
+int lis3lv02d_joystick_enable(struct lis3lv02d *lis3);
+void lis3lv02d_joystick_disable(struct lis3lv02d *lis3);
 void lis3lv02d_poweroff(struct lis3lv02d *lis3);
-void lis3lv02d_poweron(struct lis3lv02d *lis3);
+int lis3lv02d_poweron(struct lis3lv02d *lis3);
 int lis3lv02d_remove_fs(struct lis3lv02d *lis3);
 
 extern struct lis3lv02d lis3_dev;
index b20dfb4522d278eebefa6eb8f2242e78c32f3f8d..c02fea029dcf1bcd971199eea32c9c79cb9fa0fc 100644 (file)
@@ -79,8 +79,7 @@ static int lis3_i2c_init(struct lis3lv02d *lis3)
        u8 reg;
        int ret;
 
-       if (lis3->reg_ctrl)
-               lis3_reg_ctrl(lis3, LIS3_REG_ON);
+       lis3_reg_ctrl(lis3, LIS3_REG_ON);
 
        lis3->read(lis3, WHO_AM_I, &reg);
        if (reg != lis3->whoami)
@@ -106,10 +105,6 @@ static int __devinit lis3lv02d_i2c_probe(struct i2c_client *client,
        struct lis3lv02d_platform_data *pdata = client->dev.platform_data;
 
        if (pdata) {
-               /* Regulator control is optional */
-               if (pdata->driver_features & LIS3_USE_REGULATOR_CTRL)
-                       lis3_dev.reg_ctrl = lis3_reg_ctrl;
-
                if ((pdata->driver_features & LIS3_USE_BLOCK_READ) &&
                        (i2c_check_functionality(client->adapter,
                                                I2C_FUNC_SMBUS_I2C_BLOCK)))
@@ -131,15 +126,13 @@ static int __devinit lis3lv02d_i2c_probe(struct i2c_client *client,
                        goto fail;
        }
 
-       if (lis3_dev.reg_ctrl) {
-               lis3_dev.regulators[0].supply = reg_vdd;
-               lis3_dev.regulators[1].supply = reg_vdd_io;
-               ret = regulator_bulk_get(&client->dev,
-                                       ARRAY_SIZE(lis3_dev.regulators),
-                                       lis3_dev.regulators);
-               if (ret < 0)
-                       goto fail;
-       }
+       lis3_dev.regulators[0].supply = reg_vdd;
+       lis3_dev.regulators[1].supply = reg_vdd_io;
+       ret = regulator_bulk_get(&client->dev,
+                                ARRAY_SIZE(lis3_dev.regulators),
+                                lis3_dev.regulators);
+       if (ret < 0)
+               goto fail;
 
        lis3_dev.pdata    = pdata;
        lis3_dev.bus_priv = client;
@@ -153,16 +146,19 @@ static int __devinit lis3lv02d_i2c_probe(struct i2c_client *client,
        i2c_set_clientdata(client, &lis3_dev);
 
        /* Provide power over the init call */
-       if (lis3_dev.reg_ctrl)
-               lis3_reg_ctrl(&lis3_dev, LIS3_REG_ON);
+       lis3_reg_ctrl(&lis3_dev, LIS3_REG_ON);
 
        ret = lis3lv02d_init_device(&lis3_dev);
 
-       if (lis3_dev.reg_ctrl)
-               lis3_reg_ctrl(&lis3_dev, LIS3_REG_OFF);
+       lis3_reg_ctrl(&lis3_dev, LIS3_REG_OFF);
 
-       if (ret == 0)
-               return 0;
+       if (ret)
+               goto fail2;
+       return 0;
+
+fail2:
+       regulator_bulk_free(ARRAY_SIZE(lis3_dev.regulators),
+                               lis3_dev.regulators);
 fail:
        if (pdata && pdata->release_resources)
                pdata->release_resources();
@@ -177,12 +173,11 @@ static int __devexit lis3lv02d_i2c_remove(struct i2c_client *client)
        if (pdata && pdata->release_resources)
                pdata->release_resources();
 
-       lis3lv02d_joystick_disable();
+       lis3lv02d_joystick_disable(lis3);
        lis3lv02d_remove_fs(&lis3_dev);
 
-       if (lis3_dev.reg_ctrl)
-               regulator_bulk_free(ARRAY_SIZE(lis3->regulators),
-                               lis3_dev.regulators);
+       regulator_bulk_free(ARRAY_SIZE(lis3->regulators),
+                           lis3_dev.regulators);
        return 0;
 }
 
index c1f8a8fbf6943983a8e8a34b47e049cfc5111ef0..b2c1be12d16fb5625190b21e3bed774cc924d3a2 100644 (file)
@@ -83,7 +83,7 @@ static int __devinit lis302dl_spi_probe(struct spi_device *spi)
 static int __devexit lis302dl_spi_remove(struct spi_device *spi)
 {
        struct lis3lv02d *lis3 = spi_get_drvdata(spi);
-       lis3lv02d_joystick_disable();
+       lis3lv02d_joystick_disable(lis3);
        lis3lv02d_poweroff(lis3);
 
        return lis3lv02d_remove_fs(&lis3_dev);
index 4c1a648d00fcfbc156f62c4a551daaf368db88f8..a1cb21f95302c497157dc97ed85f9acd68a3c10d 100644 (file)
@@ -94,6 +94,11 @@ struct mmc_blk_data {
        unsigned int    read_only;
        unsigned int    part_type;
        unsigned int    name_idx;
+       unsigned int    reset_done;
+#define MMC_BLK_READ           BIT(0)
+#define MMC_BLK_WRITE          BIT(1)
+#define MMC_BLK_DISCARD                BIT(2)
+#define MMC_BLK_SECDISCARD     BIT(3)
 
        /*
         * Only set in main mmc_blk_data associated
@@ -109,11 +114,11 @@ static DEFINE_MUTEX(open_lock);
 enum mmc_blk_status {
        MMC_BLK_SUCCESS = 0,
        MMC_BLK_PARTIAL,
-       MMC_BLK_RETRY,
-       MMC_BLK_RETRY_SINGLE,
-       MMC_BLK_DATA_ERR,
        MMC_BLK_CMD_ERR,
+       MMC_BLK_RETRY,
        MMC_BLK_ABORT,
+       MMC_BLK_DATA_ERR,
+       MMC_BLK_ECC_ERR,
 };
 
 module_param(perdev_minors, int, 0444);
@@ -291,7 +296,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
        struct mmc_card *card;
        struct mmc_command cmd = {0};
        struct mmc_data data = {0};
-       struct mmc_request mrq = {0};
+       struct mmc_request mrq = {NULL};
        struct scatterlist sg;
        int err;
 
@@ -442,19 +447,24 @@ static inline int mmc_blk_part_switch(struct mmc_card *card,
 {
        int ret;
        struct mmc_blk_data *main_md = mmc_get_drvdata(card);
+
        if (main_md->part_curr == md->part_type)
                return 0;
 
        if (mmc_card_mmc(card)) {
-               card->ext_csd.part_config &= ~EXT_CSD_PART_CONFIG_ACC_MASK;
-               card->ext_csd.part_config |= md->part_type;
+               u8 part_config = card->ext_csd.part_config;
+
+               part_config &= ~EXT_CSD_PART_CONFIG_ACC_MASK;
+               part_config |= md->part_type;
 
                ret = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
-                                EXT_CSD_PART_CONFIG, card->ext_csd.part_config,
+                                EXT_CSD_PART_CONFIG, part_config,
                                 card->ext_csd.part_time);
                if (ret)
                        return ret;
-}
+
+               card->ext_csd.part_config = part_config;
+       }
 
        main_md->part_curr = md->part_type;
        return 0;
@@ -466,7 +476,7 @@ static u32 mmc_sd_num_wr_blocks(struct mmc_card *card)
        u32 result;
        __be32 *blocks;
 
-       struct mmc_request mrq = {0};
+       struct mmc_request mrq = {NULL};
        struct mmc_command cmd = {0};
        struct mmc_data data = {0};
        unsigned int timeout_us;
@@ -616,7 +626,7 @@ static int mmc_blk_cmd_error(struct request *req, const char *name, int error,
  * Otherwise we don't understand what happened, so abort.
  */
 static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
-       struct mmc_blk_request *brq)
+       struct mmc_blk_request *brq, int *ecc_err)
 {
        bool prev_cmd_status_valid = true;
        u32 status, stop_status = 0;
@@ -641,6 +651,12 @@ static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
        if (err)
                return ERR_ABORT;
 
+       /* Flag ECC errors */
+       if ((status & R1_CARD_ECC_FAILED) ||
+           (brq->stop.resp[0] & R1_CARD_ECC_FAILED) ||
+           (brq->cmd.resp[0] & R1_CARD_ECC_FAILED))
+               *ecc_err = 1;
+
        /*
         * Check the current card state.  If it is in some data transfer
         * mode, tell it to stop (and hopefully transition back to TRAN.)
@@ -658,6 +674,8 @@ static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
                 */
                if (err)
                        return ERR_ABORT;
+               if (stop_status & R1_CARD_ECC_FAILED)
+                       *ecc_err = 1;
        }
 
        /* Check for set block count errors */
@@ -670,6 +688,10 @@ static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
                return mmc_blk_cmd_error(req, "r/w cmd", brq->cmd.error,
                                prev_cmd_status_valid, status);
 
+       /* Data errors */
+       if (!brq->stop.error)
+               return ERR_CONTINUE;
+
        /* Now for stop errors.  These aren't fatal to the transfer. */
        pr_err("%s: error %d sending stop command, original cmd response %#x, card status %#x\n",
               req->rq_disk->disk_name, brq->stop.error,
@@ -686,12 +708,45 @@ static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
        return ERR_CONTINUE;
 }
 
+static int mmc_blk_reset(struct mmc_blk_data *md, struct mmc_host *host,
+                        int type)
+{
+       int err;
+
+       if (md->reset_done & type)
+               return -EEXIST;
+
+       md->reset_done |= type;
+       err = mmc_hw_reset(host);
+       /* Ensure we switch back to the correct partition */
+       if (err != -EOPNOTSUPP) {
+               struct mmc_blk_data *main_md = mmc_get_drvdata(host->card);
+               int part_err;
+
+               main_md->part_curr = main_md->part_type;
+               part_err = mmc_blk_part_switch(host->card, md);
+               if (part_err) {
+                       /*
+                        * We have failed to get back into the correct
+                        * partition, so we need to abort the whole request.
+                        */
+                       return -ENODEV;
+               }
+       }
+       return err;
+}
+
+static inline void mmc_blk_reset_success(struct mmc_blk_data *md, int type)
+{
+       md->reset_done &= ~type;
+}
+
 static int mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req)
 {
        struct mmc_blk_data *md = mq->data;
        struct mmc_card *card = md->queue.card;
        unsigned int from, nr, arg;
-       int err = 0;
+       int err = 0, type = MMC_BLK_DISCARD;
 
        if (!mmc_can_erase(card)) {
                err = -EOPNOTSUPP;
@@ -701,11 +756,13 @@ static int mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req)
        from = blk_rq_pos(req);
        nr = blk_rq_sectors(req);
 
-       if (mmc_can_trim(card))
+       if (mmc_can_discard(card))
+               arg = MMC_DISCARD_ARG;
+       else if (mmc_can_trim(card))
                arg = MMC_TRIM_ARG;
        else
                arg = MMC_ERASE_ARG;
-
+retry:
        if (card->quirks & MMC_QUIRK_INAND_CMD38) {
                err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
                                 INAND_CMD38_ARG_EXT_CSD,
@@ -718,6 +775,10 @@ static int mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req)
        }
        err = mmc_erase(card, from, nr, arg);
 out:
+       if (err == -EIO && !mmc_blk_reset(md, card->host, type))
+               goto retry;
+       if (!err)
+               mmc_blk_reset_success(md, type);
        spin_lock_irq(&md->lock);
        __blk_end_request(req, err, blk_rq_bytes(req));
        spin_unlock_irq(&md->lock);
@@ -731,13 +792,20 @@ static int mmc_blk_issue_secdiscard_rq(struct mmc_queue *mq,
        struct mmc_blk_data *md = mq->data;
        struct mmc_card *card = md->queue.card;
        unsigned int from, nr, arg;
-       int err = 0;
+       int err = 0, type = MMC_BLK_SECDISCARD;
 
-       if (!mmc_can_secure_erase_trim(card)) {
+       if (!(mmc_can_secure_erase_trim(card) || mmc_can_sanitize(card))) {
                err = -EOPNOTSUPP;
                goto out;
        }
 
+       /* The sanitize operation is supported at v4.5 only */
+       if (mmc_can_sanitize(card)) {
+               err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
+                               EXT_CSD_SANITIZE_START, 1, 0);
+               goto out;
+       }
+
        from = blk_rq_pos(req);
        nr = blk_rq_sectors(req);
 
@@ -745,7 +813,7 @@ static int mmc_blk_issue_secdiscard_rq(struct mmc_queue *mq,
                arg = MMC_SECURE_TRIM1_ARG;
        else
                arg = MMC_SECURE_ERASE_ARG;
-
+retry:
        if (card->quirks & MMC_QUIRK_INAND_CMD38) {
                err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
                                 INAND_CMD38_ARG_EXT_CSD,
@@ -769,6 +837,10 @@ static int mmc_blk_issue_secdiscard_rq(struct mmc_queue *mq,
                err = mmc_erase(card, from, nr, MMC_SECURE_TRIM2_ARG);
        }
 out:
+       if (err == -EIO && !mmc_blk_reset(md, card->host, type))
+               goto retry;
+       if (!err)
+               mmc_blk_reset_success(md, type);
        spin_lock_irq(&md->lock);
        __blk_end_request(req, err, blk_rq_bytes(req));
        spin_unlock_irq(&md->lock);
@@ -779,16 +851,18 @@ out:
 static int mmc_blk_issue_flush(struct mmc_queue *mq, struct request *req)
 {
        struct mmc_blk_data *md = mq->data;
+       struct mmc_card *card = md->queue.card;
+       int ret = 0;
+
+       ret = mmc_flush_cache(card);
+       if (ret)
+               ret = -EIO;
 
-       /*
-        * No-op, only service this because we need REQ_FUA for reliable
-        * writes.
-        */
        spin_lock_irq(&md->lock);
-       __blk_end_request_all(req, 0);
+       __blk_end_request_all(req, ret);
        spin_unlock_irq(&md->lock);
 
-       return 1;
+       return ret ? 0 : 1;
 }
 
 /*
@@ -825,11 +899,11 @@ static inline void mmc_apply_rel_rw(struct mmc_blk_request *brq,
 static int mmc_blk_err_check(struct mmc_card *card,
                             struct mmc_async_req *areq)
 {
-       enum mmc_blk_status ret = MMC_BLK_SUCCESS;
        struct mmc_queue_req *mq_mrq = container_of(areq, struct mmc_queue_req,
                                                    mmc_active);
        struct mmc_blk_request *brq = &mq_mrq->brq;
        struct request *req = mq_mrq->req;
+       int ecc_err = 0;
 
        /*
         * sbc.error indicates a problem with the set block count
@@ -841,8 +915,9 @@ static int mmc_blk_err_check(struct mmc_card *card,
         * stop.error indicates a problem with the stop command.  Data
         * may have been transferred, or may still be transferring.
         */
-       if (brq->sbc.error || brq->cmd.error || brq->stop.error) {
-               switch (mmc_blk_cmd_recovery(card, req, brq)) {
+       if (brq->sbc.error || brq->cmd.error || brq->stop.error ||
+           brq->data.error) {
+               switch (mmc_blk_cmd_recovery(card, req, brq, &ecc_err)) {
                case ERR_RETRY:
                        return MMC_BLK_RETRY;
                case ERR_ABORT:
@@ -873,7 +948,7 @@ static int mmc_blk_err_check(struct mmc_card *card,
                do {
                        int err = get_card_status(card, &status, 5);
                        if (err) {
-                               printk(KERN_ERR "%s: error %d requesting status\n",
+                               pr_err("%s: error %d requesting status\n",
                                       req->rq_disk->disk_name, err);
                                return MMC_BLK_CMD_ERR;
                        }
@@ -894,23 +969,21 @@ static int mmc_blk_err_check(struct mmc_card *card,
                       brq->cmd.resp[0], brq->stop.resp[0]);
 
                if (rq_data_dir(req) == READ) {
-                       if (brq->data.blocks > 1) {
-                               /* Redo read one sector at a time */
-                               pr_warning("%s: retrying using single block read\n",
-                                          req->rq_disk->disk_name);
-                               return MMC_BLK_RETRY_SINGLE;
-                       }
+                       if (ecc_err)
+                               return MMC_BLK_ECC_ERR;
                        return MMC_BLK_DATA_ERR;
                } else {
                        return MMC_BLK_CMD_ERR;
                }
        }
 
-       if (ret == MMC_BLK_SUCCESS &&
-           blk_rq_bytes(req) != brq->data.bytes_xfered)
-               ret = MMC_BLK_PARTIAL;
+       if (!brq->data.bytes_xfered)
+               return MMC_BLK_RETRY;
 
-       return ret;
+       if (blk_rq_bytes(req) != brq->data.bytes_xfered)
+               return MMC_BLK_PARTIAL;
+
+       return MMC_BLK_SUCCESS;
 }
 
 static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,
@@ -957,13 +1030,20 @@ static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,
        if (brq->data.blocks > card->host->max_blk_count)
                brq->data.blocks = card->host->max_blk_count;
 
-       /*
-        * After a read error, we redo the request one sector at a time
-        * in order to accurately determine which sectors can be read
-        * successfully.
-        */
-       if (disable_multi && brq->data.blocks > 1)
-               brq->data.blocks = 1;
+       if (brq->data.blocks > 1) {
+               /*
+                * After a read error, we redo the request one sector
+                * at a time in order to accurately determine which
+                * sectors can be read successfully.
+                */
+               if (disable_multi)
+                       brq->data.blocks = 1;
+
+               /* Some controllers can't do multiblock reads due to hw bugs */
+               if (card->host->caps2 & MMC_CAP2_NO_MULTI_READ &&
+                   rq_data_dir(req) == READ)
+                       brq->data.blocks = 1;
+       }
 
        if (brq->data.blocks > 1 || do_rel_wr) {
                /* SPI multiblock writes terminate using a special
@@ -1049,12 +1129,41 @@ static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,
        mmc_queue_bounce_pre(mqrq);
 }
 
+static int mmc_blk_cmd_err(struct mmc_blk_data *md, struct mmc_card *card,
+                          struct mmc_blk_request *brq, struct request *req,
+                          int ret)
+{
+       /*
+        * If this is an SD card and we're writing, we can first
+        * mark the known good sectors as ok.
+        *
+        * If the card is not SD, we can still ok written sectors
+        * as reported by the controller (which might be less than
+        * the real number of written sectors, but never more).
+        */
+       if (mmc_card_sd(card)) {
+               u32 blocks;
+
+               blocks = mmc_sd_num_wr_blocks(card);
+               if (blocks != (u32)-1) {
+                       spin_lock_irq(&md->lock);
+                       ret = __blk_end_request(req, 0, blocks << 9);
+                       spin_unlock_irq(&md->lock);
+               }
+       } else {
+               spin_lock_irq(&md->lock);
+               ret = __blk_end_request(req, 0, brq->data.bytes_xfered);
+               spin_unlock_irq(&md->lock);
+       }
+       return ret;
+}
+
 static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
 {
        struct mmc_blk_data *md = mq->data;
        struct mmc_card *card = md->queue.card;
        struct mmc_blk_request *brq = &mq->mqrq_cur->brq;
-       int ret = 1, disable_multi = 0, retry = 0;
+       int ret = 1, disable_multi = 0, retry = 0, type;
        enum mmc_blk_status status;
        struct mmc_queue_req *mq_rq;
        struct request *req;
@@ -1076,6 +1185,7 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
                mq_rq = container_of(areq, struct mmc_queue_req, mmc_active);
                brq = &mq_rq->brq;
                req = mq_rq->req;
+               type = rq_data_dir(req) == READ ? MMC_BLK_READ : MMC_BLK_WRITE;
                mmc_queue_bounce_post(mq_rq);
 
                switch (status) {
@@ -1084,18 +1194,18 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
                        /*
                         * A block was successfully transferred.
                         */
+                       mmc_blk_reset_success(md, type);
                        spin_lock_irq(&md->lock);
                        ret = __blk_end_request(req, 0,
                                                brq->data.bytes_xfered);
                        spin_unlock_irq(&md->lock);
+                       /*
+                        * If the blk_end_request function returns non-zero even
+                        * though all data has been transferred and no errors
+                        * were returned by the host controller, it's a bug.
+                        */
                        if (status == MMC_BLK_SUCCESS && ret) {
-                               /*
-                                * The blk_end_request has returned non zero
-                                * even though all data is transfered and no
-                                * erros returned by host.
-                                * If this happen it's a bug.
-                                */
-                               printk(KERN_ERR "%s BUG rq_tot %d d_xfer %d\n",
+                               pr_err("%s BUG rq_tot %d d_xfer %d\n",
                                       __func__, blk_rq_bytes(req),
                                       brq->data.bytes_xfered);
                                rqc = NULL;
@@ -1103,16 +1213,36 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
                        }
                        break;
                case MMC_BLK_CMD_ERR:
-                       goto cmd_err;
-               case MMC_BLK_RETRY_SINGLE:
-                       disable_multi = 1;
-                       break;
+                       ret = mmc_blk_cmd_err(md, card, brq, req, ret);
+                       if (!mmc_blk_reset(md, card->host, type))
+                               break;
+                       goto cmd_abort;
                case MMC_BLK_RETRY:
                        if (retry++ < 5)
                                break;
+                       /* Fall through */
                case MMC_BLK_ABORT:
+                       if (!mmc_blk_reset(md, card->host, type))
+                               break;
                        goto cmd_abort;
-               case MMC_BLK_DATA_ERR:
+               case MMC_BLK_DATA_ERR: {
+                       int err;
+
+                       err = mmc_blk_reset(md, card->host, type);
+                       if (!err)
+                               break;
+                       if (err == -ENODEV)
+                               goto cmd_abort;
+                       /* Fall through */
+               }
+               case MMC_BLK_ECC_ERR:
+                       if (brq->data.blocks > 1) {
+                               /* Redo read one sector at a time */
+                               pr_warning("%s: retrying using single block read\n",
+                                          req->rq_disk->disk_name);
+                               disable_multi = 1;
+                               break;
+                       }
                        /*
                         * After an error, we redo I/O one sector at a
                         * time, so we only reach here after trying to
@@ -1129,7 +1259,7 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
 
                if (ret) {
                        /*
-                        * In case of a none complete request
+                        * In case of a incomplete request
                         * prepare it again and resend.
                         */
                        mmc_blk_rw_rq_prep(mq_rq, card, disable_multi, mq);
@@ -1139,30 +1269,6 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
 
        return 1;
 
- cmd_err:
-       /*
-        * If this is an SD card and we're writing, we can first
-        * mark the known good sectors as ok.
-        *
-        * If the card is not SD, we can still ok written sectors
-        * as reported by the controller (which might be less than
-        * the real number of written sectors, but never more).
-        */
-       if (mmc_card_sd(card)) {
-               u32 blocks;
-
-               blocks = mmc_sd_num_wr_blocks(card);
-               if (blocks != (u32)-1) {
-                       spin_lock_irq(&md->lock);
-                       ret = __blk_end_request(req, 0, blocks << 9);
-                       spin_unlock_irq(&md->lock);
-               }
-       } else {
-               spin_lock_irq(&md->lock);
-               ret = __blk_end_request(req, 0, brq->data.bytes_xfered);
-               spin_unlock_irq(&md->lock);
-       }
-
  cmd_abort:
        spin_lock_irq(&md->lock);
        while (ret)
@@ -1190,6 +1296,11 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
 
        ret = mmc_blk_part_switch(card, md);
        if (ret) {
+               if (req) {
+                       spin_lock_irq(&md->lock);
+                       __blk_end_request_all(req, -EIO);
+                       spin_unlock_irq(&md->lock);
+               }
                ret = 0;
                goto out;
        }
@@ -1374,32 +1485,35 @@ static int mmc_blk_alloc_part(struct mmc_card *card,
 
        string_get_size((u64)get_capacity(part_md->disk) << 9, STRING_UNITS_2,
                        cap_str, sizeof(cap_str));
-       printk(KERN_INFO "%s: %s %s partition %u %s\n",
+       pr_info("%s: %s %s partition %u %s\n",
               part_md->disk->disk_name, mmc_card_id(card),
               mmc_card_name(card), part_md->part_type, cap_str);
        return 0;
 }
 
+/* MMC Physical partitions consist of two boot partitions and
+ * up to four general purpose partitions.
+ * For each partition enabled in EXT_CSD a block device will be allocatedi
+ * to provide access to the partition.
+ */
+
 static int mmc_blk_alloc_parts(struct mmc_card *card, struct mmc_blk_data *md)
 {
-       int ret = 0;
+       int idx, ret = 0;
 
        if (!mmc_card_mmc(card))
                return 0;
 
-       if (card->ext_csd.boot_size) {
-               ret = mmc_blk_alloc_part(card, md, EXT_CSD_PART_CONFIG_ACC_BOOT0,
-                                        card->ext_csd.boot_size >> 9,
-                                        true,
-                                        "boot0");
-               if (ret)
-                       return ret;
-               ret = mmc_blk_alloc_part(card, md, EXT_CSD_PART_CONFIG_ACC_BOOT1,
-                                        card->ext_csd.boot_size >> 9,
-                                        true,
-                                        "boot1");
-               if (ret)
-                       return ret;
+       for (idx = 0; idx < card->nr_parts; idx++) {
+               if (card->part[idx].size) {
+                       ret = mmc_blk_alloc_part(card, md,
+                               card->part[idx].part_cfg,
+                               card->part[idx].size >> 9,
+                               card->part[idx].force_ro,
+                               card->part[idx].name);
+                       if (ret)
+                               return ret;
+               }
        }
 
        return ret;
@@ -1415,7 +1529,7 @@ mmc_blk_set_blksize(struct mmc_blk_data *md, struct mmc_card *card)
        mmc_release_host(card->host);
 
        if (err) {
-               printk(KERN_ERR "%s: unable to set block size to 512: %d\n",
+               pr_err("%s: unable to set block size to 512: %d\n",
                        md->disk->disk_name, err);
                return -EINVAL;
        }
@@ -1517,7 +1631,7 @@ static int mmc_blk_probe(struct mmc_card *card)
 
        string_get_size((u64)get_capacity(md->disk) << 9, STRING_UNITS_2,
                        cap_str, sizeof(cap_str));
-       printk(KERN_INFO "%s: %s %s %s %s\n",
+       pr_info("%s: %s %s %s %s\n",
                md->disk->disk_name, mmc_card_id(card), mmc_card_name(card),
                cap_str, md->read_only ? "(ro)" : "");
 
index 2bf229acd3b8110c3a03bc3dbb9783e2451ef099..b038c4a9468b0a9d06d9ae72ac7d4ee3325ac8a4 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/debugfs.h>
 #include <linux/uaccess.h>
 #include <linux/seq_file.h>
+#include <linux/module.h>
 
 #define RESULT_OK              0
 #define RESULT_FAIL            1
@@ -250,7 +251,7 @@ static int mmc_test_wait_busy(struct mmc_test_card *test)
                if (!busy && mmc_test_busy(&cmd)) {
                        busy = 1;
                        if (test->card->host->caps & MMC_CAP_WAIT_WHILE_BUSY)
-                               printk(KERN_INFO "%s: Warning: Host did not "
+                               pr_info("%s: Warning: Host did not "
                                        "wait for busy state to end.\n",
                                        mmc_hostname(test->card->host));
                }
@@ -552,7 +553,7 @@ static void mmc_test_print_rate(struct mmc_test_card *test, uint64_t bytes,
        rate = mmc_test_rate(bytes, &ts);
        iops = mmc_test_rate(100, &ts); /* I/O ops per sec x 100 */
 
-       printk(KERN_INFO "%s: Transfer of %u sectors (%u%s KiB) took %lu.%09lu "
+       pr_info("%s: Transfer of %u sectors (%u%s KiB) took %lu.%09lu "
                         "seconds (%u kB/s, %u KiB/s, %u.%02u IOPS)\n",
                         mmc_hostname(test->card->host), sectors, sectors >> 1,
                         (sectors & 1 ? ".5" : ""), (unsigned long)ts.tv_sec,
@@ -578,7 +579,7 @@ static void mmc_test_print_avg_rate(struct mmc_test_card *test, uint64_t bytes,
        rate = mmc_test_rate(tot, &ts);
        iops = mmc_test_rate(count * 100, &ts); /* I/O ops per sec x 100 */
 
-       printk(KERN_INFO "%s: Transfer of %u x %u sectors (%u x %u%s KiB) took "
+       pr_info("%s: Transfer of %u x %u sectors (%u x %u%s KiB) took "
                         "%lu.%09lu seconds (%u kB/s, %u KiB/s, "
                         "%u.%02u IOPS, sg_len %d)\n",
                         mmc_hostname(test->card->host), count, sectors, count,
@@ -1408,7 +1409,7 @@ static int mmc_test_multi_read_high(struct mmc_test_card *test)
 
 static int mmc_test_no_highmem(struct mmc_test_card *test)
 {
-       printk(KERN_INFO "%s: Highmem not configured - test skipped\n",
+       pr_info("%s: Highmem not configured - test skipped\n",
               mmc_hostname(test->card->host));
        return 0;
 }
@@ -1435,7 +1436,7 @@ static int mmc_test_area_map(struct mmc_test_card *test, unsigned long sz,
                                      t->max_seg_sz, &t->sg_len, min_sg_len);
        }
        if (err)
-               printk(KERN_INFO "%s: Failed to map sg list\n",
+               pr_info("%s: Failed to map sg list\n",
                       mmc_hostname(test->card->host));
        return err;
 }
@@ -2135,7 +2136,7 @@ static int mmc_test_rw_multiple(struct mmc_test_card *test,
 
        return ret;
  err:
-       printk(KERN_INFO "[%s] error\n", __func__);
+       pr_info("[%s] error\n", __func__);
        return ret;
 }
 
@@ -2149,7 +2150,7 @@ static int mmc_test_rw_multiple_size(struct mmc_test_card *test,
 
        if (rw->do_nonblock_req &&
            ((!pre_req && post_req) || (pre_req && !post_req))) {
-               printk(KERN_INFO "error: only one of pre/post is defined\n");
+               pr_info("error: only one of pre/post is defined\n");
                return -EINVAL;
        }
 
@@ -2328,6 +2329,31 @@ static int mmc_test_profile_sglen_r_nonblock_perf(struct mmc_test_card *test)
        return mmc_test_rw_multiple_sg_len(test, &test_data);
 }
 
+/*
+ * eMMC hardware reset.
+ */
+static int mmc_test_hw_reset(struct mmc_test_card *test)
+{
+       struct mmc_card *card = test->card;
+       struct mmc_host *host = card->host;
+       int err;
+
+       err = mmc_hw_reset_check(host);
+       if (!err)
+               return RESULT_OK;
+
+       if (err == -ENOSYS)
+               return RESULT_FAIL;
+
+       if (err != -EOPNOTSUPP)
+               return err;
+
+       if (!mmc_can_reset(card))
+               return RESULT_UNSUP_CARD;
+
+       return RESULT_UNSUP_HOST;
+}
+
 static const struct mmc_test_case mmc_test_cases[] = {
        {
                .name = "Basic write (no data verification)",
@@ -2650,6 +2676,11 @@ static const struct mmc_test_case mmc_test_cases[] = {
                .run = mmc_test_profile_sglen_r_nonblock_perf,
                .cleanup = mmc_test_area_cleanup,
        },
+
+       {
+               .name = "eMMC hardware reset",
+               .run = mmc_test_hw_reset,
+       },
 };
 
 static DEFINE_MUTEX(mmc_test_lock);
@@ -2660,7 +2691,7 @@ static void mmc_test_run(struct mmc_test_card *test, int testcase)
 {
        int i, ret;
 
-       printk(KERN_INFO "%s: Starting tests of card %s...\n",
+       pr_info("%s: Starting tests of card %s...\n",
                mmc_hostname(test->card->host), mmc_card_id(test->card));
 
        mmc_claim_host(test->card->host);
@@ -2671,14 +2702,14 @@ static void mmc_test_run(struct mmc_test_card *test, int testcase)
                if (testcase && ((i + 1) != testcase))
                        continue;
 
-               printk(KERN_INFO "%s: Test case %d. %s...\n",
+               pr_info("%s: Test case %d. %s...\n",
                        mmc_hostname(test->card->host), i + 1,
                        mmc_test_cases[i].name);
 
                if (mmc_test_cases[i].prepare) {
                        ret = mmc_test_cases[i].prepare(test);
                        if (ret) {
-                               printk(KERN_INFO "%s: Result: Prepare "
+                               pr_info("%s: Result: Prepare "
                                        "stage failed! (%d)\n",
                                        mmc_hostname(test->card->host),
                                        ret);
@@ -2708,25 +2739,25 @@ static void mmc_test_run(struct mmc_test_card *test, int testcase)
                ret = mmc_test_cases[i].run(test);
                switch (ret) {
                case RESULT_OK:
-                       printk(KERN_INFO "%s: Result: OK\n",
+                       pr_info("%s: Result: OK\n",
                                mmc_hostname(test->card->host));
                        break;
                case RESULT_FAIL:
-                       printk(KERN_INFO "%s: Result: FAILED\n",
+                       pr_info("%s: Result: FAILED\n",
                                mmc_hostname(test->card->host));
                        break;
                case RESULT_UNSUP_HOST:
-                       printk(KERN_INFO "%s: Result: UNSUPPORTED "
+                       pr_info("%s: Result: UNSUPPORTED "
                                "(by host)\n",
                                mmc_hostname(test->card->host));
                        break;
                case RESULT_UNSUP_CARD:
-                       printk(KERN_INFO "%s: Result: UNSUPPORTED "
+                       pr_info("%s: Result: UNSUPPORTED "
                                "(by card)\n",
                                mmc_hostname(test->card->host));
                        break;
                default:
-                       printk(KERN_INFO "%s: Result: ERROR (%d)\n",
+                       pr_info("%s: Result: ERROR (%d)\n",
                                mmc_hostname(test->card->host), ret);
                }
 
@@ -2737,7 +2768,7 @@ static void mmc_test_run(struct mmc_test_card *test, int testcase)
                if (mmc_test_cases[i].cleanup) {
                        ret = mmc_test_cases[i].cleanup(test);
                        if (ret) {
-                               printk(KERN_INFO "%s: Warning: Cleanup "
+                               pr_info("%s: Warning: Cleanup "
                                        "stage failed! (%d)\n",
                                        mmc_hostname(test->card->host),
                                        ret);
@@ -2747,7 +2778,7 @@ static void mmc_test_run(struct mmc_test_card *test, int testcase)
 
        mmc_release_host(test->card->host);
 
-       printk(KERN_INFO "%s: Tests completed.\n",
+       pr_info("%s: Tests completed.\n",
                mmc_hostname(test->card->host));
 }
 
index 45fb362e3f013460fc951909dc72d13847530a1e..dcad59cbfef11a873b0dfa49ef9dcd4e8fcf1d83 100644 (file)
@@ -108,7 +108,7 @@ static void mmc_request(struct request_queue *q)
                wake_up_process(mq->thread);
 }
 
-struct scatterlist *mmc_alloc_sg(int sg_len, int *err)
+static struct scatterlist *mmc_alloc_sg(int sg_len, int *err)
 {
        struct scatterlist *sg;
 
@@ -140,7 +140,7 @@ static void mmc_queue_setup_discard(struct request_queue *q,
        /* granularity must not be greater than max. discard */
        if (card->pref_erase > max_discard)
                q->limits.discard_granularity = 0;
-       if (mmc_can_secure_erase_trim(card))
+       if (mmc_can_secure_erase_trim(card) || mmc_can_sanitize(card))
                queue_flag_set_unlocked(QUEUE_FLAG_SECDISCARD, q);
 }
 
@@ -197,13 +197,13 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card,
                if (bouncesz > 512) {
                        mqrq_cur->bounce_buf = kmalloc(bouncesz, GFP_KERNEL);
                        if (!mqrq_cur->bounce_buf) {
-                               printk(KERN_WARNING "%s: unable to "
+                               pr_warning("%s: unable to "
                                        "allocate bounce cur buffer\n",
                                        mmc_card_name(card));
                        }
                        mqrq_prev->bounce_buf = kmalloc(bouncesz, GFP_KERNEL);
                        if (!mqrq_prev->bounce_buf) {
-                               printk(KERN_WARNING "%s: unable to "
+                               pr_warning("%s: unable to "
                                        "allocate bounce prev buffer\n",
                                        mmc_card_name(card));
                                kfree(mqrq_cur->bounce_buf);
index c8c9edb3d7cb2bf84651f8350fde97f7faa79d66..2c151e18c9e847b147798386fd2effdb03b4465e 100644 (file)
@@ -1082,7 +1082,7 @@ static int sdio_uart_probe(struct sdio_func *func,
                return -ENOMEM;
 
        if (func->class == SDIO_CLASS_UART) {
-               printk(KERN_WARNING "%s: need info on UART class basic setup\n",
+               pr_warning("%s: need info on UART class basic setup\n",
                       sdio_func_id(func));
                kfree(port);
                return -ENOSYS;
@@ -1101,23 +1101,23 @@ static int sdio_uart_probe(struct sdio_func *func,
                                break;
                }
                if (!tpl) {
-                       printk(KERN_WARNING
+                       pr_warning(
        "%s: can't find tuple 0x91 subtuple 0 (SUBTPL_SIOREG) for GPS class\n",
                               sdio_func_id(func));
                        kfree(port);
                        return -EINVAL;
                }
-               printk(KERN_DEBUG "%s: Register ID = 0x%02x, Exp ID = 0x%02x\n",
+               pr_debug("%s: Register ID = 0x%02x, Exp ID = 0x%02x\n",
                       sdio_func_id(func), tpl->data[2], tpl->data[3]);
                port->regs_offset = (tpl->data[4] << 0) |
                                    (tpl->data[5] << 8) |
                                    (tpl->data[6] << 16);
-               printk(KERN_DEBUG "%s: regs offset = 0x%x\n",
+               pr_debug("%s: regs offset = 0x%x\n",
                       sdio_func_id(func), port->regs_offset);
                port->uartclk = tpl->data[7] * 115200;
                if (port->uartclk == 0)
                        port->uartclk = 115200;
-               printk(KERN_DEBUG "%s: clk %d baudcode %u 4800-div %u\n",
+               pr_debug("%s: clk %d baudcode %u 4800-div %u\n",
                       sdio_func_id(func), port->uartclk,
                       tpl->data[7], tpl->data[8] | (tpl->data[9] << 8));
        } else {
index 393d817ed04076dca934511f4522b698776073ae..46b6e84d953e3f29697fbdb4d275edc778783988 100644 (file)
@@ -295,7 +295,7 @@ int mmc_add_card(struct mmc_card *card)
        }
 
        if (mmc_host_is_spi(card->host)) {
-               printk(KERN_INFO "%s: new %s%s%s card on SPI\n",
+               pr_info("%s: new %s%s%s card on SPI\n",
                        mmc_hostname(card->host),
                        mmc_card_highspeed(card) ? "high speed " : "",
                        mmc_card_ddr_mode(card) ? "DDR " : "",
@@ -334,10 +334,10 @@ void mmc_remove_card(struct mmc_card *card)
 
        if (mmc_card_present(card)) {
                if (mmc_host_is_spi(card->host)) {
-                       printk(KERN_INFO "%s: SPI card removed\n",
+                       pr_info("%s: SPI card removed\n",
                                mmc_hostname(card->host));
                } else {
-                       printk(KERN_INFO "%s: card %04x removed\n",
+                       pr_info("%s: card %04x removed\n",
                                mmc_hostname(card->host), card->rca);
                }
                device_del(&card->dev);
index b27b94078c21888bd472346e92e04fcb8a87464e..5278ffb20e74bbba9b5508e008171165ad296f16 100644 (file)
@@ -24,6 +24,8 @@
 #include <linux/regulator/consumer.h>
 #include <linux/pm_runtime.h>
 #include <linux/suspend.h>
+#include <linux/fault-inject.h>
+#include <linux/random.h>
 
 #include <linux/mmc/card.h>
 #include <linux/mmc/host.h>
@@ -83,6 +85,43 @@ static void mmc_flush_scheduled_work(void)
        flush_workqueue(workqueue);
 }
 
+#ifdef CONFIG_FAIL_MMC_REQUEST
+
+/*
+ * Internal function. Inject random data errors.
+ * If mmc_data is NULL no errors are injected.
+ */
+static void mmc_should_fail_request(struct mmc_host *host,
+                                   struct mmc_request *mrq)
+{
+       struct mmc_command *cmd = mrq->cmd;
+       struct mmc_data *data = mrq->data;
+       static const int data_errors[] = {
+               -ETIMEDOUT,
+               -EILSEQ,
+               -EIO,
+       };
+
+       if (!data)
+               return;
+
+       if (cmd->error || data->error ||
+           !should_fail(&host->fail_mmc_request, data->blksz * data->blocks))
+               return;
+
+       data->error = data_errors[random32() % ARRAY_SIZE(data_errors)];
+       data->bytes_xfered = (random32() % (data->bytes_xfered >> 9)) << 9;
+}
+
+#else /* CONFIG_FAIL_MMC_REQUEST */
+
+static inline void mmc_should_fail_request(struct mmc_host *host,
+                                          struct mmc_request *mrq)
+{
+}
+
+#endif /* CONFIG_FAIL_MMC_REQUEST */
+
 /**
  *     mmc_request_done - finish processing an MMC request
  *     @host: MMC host which completed request
@@ -102,13 +141,15 @@ void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq)
        }
 
        if (err && cmd->retries) {
-               pr_debug("%s: req failed (CMD%u): %d, retrying...\n",
-                       mmc_hostname(host), cmd->opcode, err);
-
-               cmd->retries--;
-               cmd->error = 0;
-               host->ops->request(host, mrq);
+               /*
+                * Request starter must handle retries - see
+                * mmc_wait_for_req_done().
+                */
+               if (mrq->done)
+                       mrq->done(mrq);
        } else {
+               mmc_should_fail_request(host, mrq);
+
                led_trigger_event(host->led, LED_OFF);
 
                pr_debug("%s: req done (CMD%u): %d: %08x %08x %08x %08x\n",
@@ -212,7 +253,21 @@ static void __mmc_start_req(struct mmc_host *host, struct mmc_request *mrq)
 static void mmc_wait_for_req_done(struct mmc_host *host,
                                  struct mmc_request *mrq)
 {
-       wait_for_completion(&mrq->completion);
+       struct mmc_command *cmd;
+
+       while (1) {
+               wait_for_completion(&mrq->completion);
+
+               cmd = mrq->cmd;
+               if (!cmd->error || !cmd->retries)
+                       break;
+
+               pr_debug("%s: req failed (CMD%u): %d, retrying...\n",
+                        mmc_hostname(host), cmd->opcode, cmd->error);
+               cmd->retries--;
+               cmd->error = 0;
+               host->ops->request(host, mrq);
+       }
 }
 
 /**
@@ -279,8 +334,14 @@ struct mmc_async_req *mmc_start_req(struct mmc_host *host,
                mmc_wait_for_req_done(host, host->areq->mrq);
                err = host->areq->err_check(host->card, host->areq);
                if (err) {
+                       /* post process the completed failed request */
                        mmc_post_req(host, host->areq->mrq, 0);
                        if (areq)
+                               /*
+                                * Cancel the new prepared request, because
+                                * it can't run until the failed
+                                * request has been properly handled.
+                                */
                                mmc_post_req(host, areq->mrq, -EINVAL);
 
                        host->areq = NULL;
@@ -318,6 +379,63 @@ void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq)
 }
 EXPORT_SYMBOL(mmc_wait_for_req);
 
+/**
+ *     mmc_interrupt_hpi - Issue for High priority Interrupt
+ *     @card: the MMC card associated with the HPI transfer
+ *
+ *     Issued High Priority Interrupt, and check for card status
+ *     util out-of prg-state.
+ */
+int mmc_interrupt_hpi(struct mmc_card *card)
+{
+       int err;
+       u32 status;
+
+       BUG_ON(!card);
+
+       if (!card->ext_csd.hpi_en) {
+               pr_info("%s: HPI enable bit unset\n", mmc_hostname(card->host));
+               return 1;
+       }
+
+       mmc_claim_host(card->host);
+       err = mmc_send_status(card, &status);
+       if (err) {
+               pr_err("%s: Get card status fail\n", mmc_hostname(card->host));
+               goto out;
+       }
+
+       /*
+        * If the card status is in PRG-state, we can send the HPI command.
+        */
+       if (R1_CURRENT_STATE(status) == R1_STATE_PRG) {
+               do {
+                       /*
+                        * We don't know when the HPI command will finish
+                        * processing, so we need to resend HPI until out
+                        * of prg-state, and keep checking the card status
+                        * with SEND_STATUS.  If a timeout error occurs when
+                        * sending the HPI command, we are already out of
+                        * prg-state.
+                        */
+                       err = mmc_send_hpi_cmd(card, &status);
+                       if (err)
+                               pr_debug("%s: abort HPI (%d error)\n",
+                                        mmc_hostname(card->host), err);
+
+                       err = mmc_send_status(card, &status);
+                       if (err)
+                               break;
+               } while (R1_CURRENT_STATE(status) == R1_STATE_PRG);
+       } else
+               pr_debug("%s: Left prg-state\n", mmc_hostname(card->host));
+
+out:
+       mmc_release_host(card->host);
+       return err;
+}
+EXPORT_SYMBOL(mmc_interrupt_hpi);
+
 /**
  *     mmc_wait_for_cmd - start a command and wait for completion
  *     @host: MMC host to start command
@@ -330,7 +448,7 @@ EXPORT_SYMBOL(mmc_wait_for_req);
  */
 int mmc_wait_for_cmd(struct mmc_host *host, struct mmc_command *cmd, int retries)
 {
-       struct mmc_request mrq = {0};
+       struct mmc_request mrq = {NULL};
 
        WARN_ON(!host->claimed);
 
@@ -1119,13 +1237,11 @@ static void mmc_power_up(struct mmc_host *host)
                bit = fls(host->ocr_avail) - 1;
 
        host->ios.vdd = bit;
-       if (mmc_host_is_spi(host)) {
+       if (mmc_host_is_spi(host))
                host->ios.chip_select = MMC_CS_HIGH;
-               host->ios.bus_mode = MMC_BUSMODE_PUSHPULL;
-       } else {
+       else
                host->ios.chip_select = MMC_CS_DONTCARE;
-               host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
-       }
+       host->ios.bus_mode = MMC_BUSMODE_PUSHPULL;
        host->ios.power_mode = MMC_POWER_UP;
        host->ios.bus_width = MMC_BUS_WIDTH_1;
        host->ios.timing = MMC_TIMING_LEGACY;
@@ -1151,13 +1267,45 @@ static void mmc_power_up(struct mmc_host *host)
        mmc_host_clk_release(host);
 }
 
-static void mmc_power_off(struct mmc_host *host)
+void mmc_power_off(struct mmc_host *host)
 {
+       struct mmc_card *card;
+       unsigned int notify_type;
+       unsigned int timeout;
+       int err;
+
        mmc_host_clk_hold(host);
 
+       card = host->card;
        host->ios.clock = 0;
        host->ios.vdd = 0;
 
+       if (card && mmc_card_mmc(card) &&
+           (card->poweroff_notify_state == MMC_POWERED_ON)) {
+
+               if (host->power_notify_type == MMC_HOST_PW_NOTIFY_SHORT) {
+                       notify_type = EXT_CSD_POWER_OFF_SHORT;
+                       timeout = card->ext_csd.generic_cmd6_time;
+                       card->poweroff_notify_state = MMC_POWEROFF_SHORT;
+               } else {
+                       notify_type = EXT_CSD_POWER_OFF_LONG;
+                       timeout = card->ext_csd.power_off_longtime;
+                       card->poweroff_notify_state = MMC_POWEROFF_LONG;
+               }
+
+               err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
+                                EXT_CSD_POWER_OFF_NOTIFICATION,
+                                notify_type, timeout);
+
+               if (err && err != -EBADMSG)
+                       pr_err("Device failed to respond within %d poweroff "
+                              "time. Forcefully powering down the device\n",
+                              timeout);
+
+               /* Set the card state to no notification after the poweroff */
+               card->poweroff_notify_state = MMC_NO_POWER_NOTIFICATION;
+       }
+
        /*
         * Reset ocr mask to be the highest possible voltage supported for
         * this mmc host. This value will be used at next power up.
@@ -1173,6 +1321,13 @@ static void mmc_power_off(struct mmc_host *host)
        host->ios.timing = MMC_TIMING_LEGACY;
        mmc_set_ios(host);
 
+       /*
+        * Some configurations, such as the 802.11 SDIO card in the OLPC
+        * XO-1.5, require a short delay after poweroff before the card
+        * can be successfully turned on again.
+        */
+       mmc_delay(1);
+
        mmc_host_clk_release(host);
 }
 
@@ -1241,8 +1396,7 @@ void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops)
 }
 
 /*
- * Remove the current bus handler from a host. Assumes that there are
- * no interesting cards left, so the bus is powered down.
+ * Remove the current bus handler from a host.
  */
 void mmc_detach_bus(struct mmc_host *host)
 {
@@ -1259,8 +1413,6 @@ void mmc_detach_bus(struct mmc_host *host)
 
        spin_unlock_irqrestore(&host->lock, flags);
 
-       mmc_power_off(host);
-
        mmc_bus_put(host);
 }
 
@@ -1478,9 +1630,9 @@ static int mmc_do_erase(struct mmc_card *card, unsigned int from,
        cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
        err = mmc_wait_for_cmd(card->host, &cmd, 0);
        if (err) {
-               printk(KERN_ERR "mmc_erase: group start error %d, "
+               pr_err("mmc_erase: group start error %d, "
                       "status %#x\n", err, cmd.resp[0]);
-               err = -EINVAL;
+               err = -EIO;
                goto out;
        }
 
@@ -1493,9 +1645,9 @@ static int mmc_do_erase(struct mmc_card *card, unsigned int from,
        cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
        err = mmc_wait_for_cmd(card->host, &cmd, 0);
        if (err) {
-               printk(KERN_ERR "mmc_erase: group end error %d, status %#x\n",
+               pr_err("mmc_erase: group end error %d, status %#x\n",
                       err, cmd.resp[0]);
-               err = -EINVAL;
+               err = -EIO;
                goto out;
        }
 
@@ -1506,7 +1658,7 @@ static int mmc_do_erase(struct mmc_card *card, unsigned int from,
        cmd.cmd_timeout_ms = mmc_erase_timeout(card, arg, qty);
        err = mmc_wait_for_cmd(card->host, &cmd, 0);
        if (err) {
-               printk(KERN_ERR "mmc_erase: erase error %d, status %#x\n",
+               pr_err("mmc_erase: erase error %d, status %#x\n",
                       err, cmd.resp[0]);
                err = -EIO;
                goto out;
@@ -1523,7 +1675,7 @@ static int mmc_do_erase(struct mmc_card *card, unsigned int from,
                /* Do not retry else we can't see errors */
                err = mmc_wait_for_cmd(card->host, &cmd, 0);
                if (err || (cmd.resp[0] & 0xFDF92000)) {
-                       printk(KERN_ERR "error %d requesting status %#x\n",
+                       pr_err("error %d requesting status %#x\n",
                                err, cmd.resp[0]);
                        err = -EIO;
                        goto out;
@@ -1614,10 +1766,32 @@ int mmc_can_trim(struct mmc_card *card)
 {
        if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_GB_CL_EN)
                return 1;
+       if (mmc_can_discard(card))
+               return 1;
        return 0;
 }
 EXPORT_SYMBOL(mmc_can_trim);
 
+int mmc_can_discard(struct mmc_card *card)
+{
+       /*
+        * As there's no way to detect the discard support bit at v4.5
+        * use the s/w feature support filed.
+        */
+       if (card->ext_csd.feature_support & MMC_DISCARD_FEATURE)
+               return 1;
+       return 0;
+}
+EXPORT_SYMBOL(mmc_can_discard);
+
+int mmc_can_sanitize(struct mmc_card *card)
+{
+       if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_SANITIZE)
+               return 1;
+       return 0;
+}
+EXPORT_SYMBOL(mmc_can_sanitize);
+
 int mmc_can_secure_erase_trim(struct mmc_card *card)
 {
        if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_ER_EN)
@@ -1727,6 +1901,94 @@ int mmc_set_blocklen(struct mmc_card *card, unsigned int blocklen)
 }
 EXPORT_SYMBOL(mmc_set_blocklen);
 
+static void mmc_hw_reset_for_init(struct mmc_host *host)
+{
+       if (!(host->caps & MMC_CAP_HW_RESET) || !host->ops->hw_reset)
+               return;
+       mmc_host_clk_hold(host);
+       host->ops->hw_reset(host);
+       mmc_host_clk_release(host);
+}
+
+int mmc_can_reset(struct mmc_card *card)
+{
+       u8 rst_n_function;
+
+       if (!mmc_card_mmc(card))
+               return 0;
+       rst_n_function = card->ext_csd.rst_n_function;
+       if ((rst_n_function & EXT_CSD_RST_N_EN_MASK) != EXT_CSD_RST_N_ENABLED)
+               return 0;
+       return 1;
+}
+EXPORT_SYMBOL(mmc_can_reset);
+
+static int mmc_do_hw_reset(struct mmc_host *host, int check)
+{
+       struct mmc_card *card = host->card;
+
+       if (!host->bus_ops->power_restore)
+               return -EOPNOTSUPP;
+
+       if (!(host->caps & MMC_CAP_HW_RESET) || !host->ops->hw_reset)
+               return -EOPNOTSUPP;
+
+       if (!card)
+               return -EINVAL;
+
+       if (!mmc_can_reset(card))
+               return -EOPNOTSUPP;
+
+       mmc_host_clk_hold(host);
+       mmc_set_clock(host, host->f_init);
+
+       host->ops->hw_reset(host);
+
+       /* If the reset has happened, then a status command will fail */
+       if (check) {
+               struct mmc_command cmd = {0};
+               int err;
+
+               cmd.opcode = MMC_SEND_STATUS;
+               if (!mmc_host_is_spi(card->host))
+                       cmd.arg = card->rca << 16;
+               cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC;
+               err = mmc_wait_for_cmd(card->host, &cmd, 0);
+               if (!err) {
+                       mmc_host_clk_release(host);
+                       return -ENOSYS;
+               }
+       }
+
+       host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_DDR);
+       if (mmc_host_is_spi(host)) {
+               host->ios.chip_select = MMC_CS_HIGH;
+               host->ios.bus_mode = MMC_BUSMODE_PUSHPULL;
+       } else {
+               host->ios.chip_select = MMC_CS_DONTCARE;
+               host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
+       }
+       host->ios.bus_width = MMC_BUS_WIDTH_1;
+       host->ios.timing = MMC_TIMING_LEGACY;
+       mmc_set_ios(host);
+
+       mmc_host_clk_release(host);
+
+       return host->bus_ops->power_restore(host);
+}
+
+int mmc_hw_reset(struct mmc_host *host)
+{
+       return mmc_do_hw_reset(host, 0);
+}
+EXPORT_SYMBOL(mmc_hw_reset);
+
+int mmc_hw_reset_check(struct mmc_host *host)
+{
+       return mmc_do_hw_reset(host, 1);
+}
+EXPORT_SYMBOL(mmc_hw_reset_check);
+
 static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq)
 {
        host->f_init = freq;
@@ -1737,6 +1999,12 @@ static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq)
 #endif
        mmc_power_up(host);
 
+       /*
+        * Some eMMCs (with VCCQ always on) may not be reset after power up, so
+        * do a hardware reset if possible.
+        */
+       mmc_hw_reset_for_init(host);
+
        /*
         * sdio_reset sends CMD52 to reset card.  Since we do not know
         * if the card is being re-initialized, just send it.  CMD52
@@ -1845,6 +2113,7 @@ void mmc_stop_host(struct mmc_host *host)
 
                mmc_claim_host(host);
                mmc_detach_bus(host);
+               mmc_power_off(host);
                mmc_release_host(host);
                mmc_bus_put(host);
                return;
@@ -1946,6 +2215,65 @@ int mmc_card_can_sleep(struct mmc_host *host)
 }
 EXPORT_SYMBOL(mmc_card_can_sleep);
 
+/*
+ * Flush the cache to the non-volatile storage.
+ */
+int mmc_flush_cache(struct mmc_card *card)
+{
+       struct mmc_host *host = card->host;
+       int err = 0;
+
+       if (!(host->caps2 & MMC_CAP2_CACHE_CTRL))
+               return err;
+
+       if (mmc_card_mmc(card) &&
+                       (card->ext_csd.cache_size > 0) &&
+                       (card->ext_csd.cache_ctrl & 1)) {
+               err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
+                               EXT_CSD_FLUSH_CACHE, 1, 0);
+               if (err)
+                       pr_err("%s: cache flush error %d\n",
+                                       mmc_hostname(card->host), err);
+       }
+
+       return err;
+}
+EXPORT_SYMBOL(mmc_flush_cache);
+
+/*
+ * Turn the cache ON/OFF.
+ * Turning the cache OFF shall trigger flushing of the data
+ * to the non-volatile storage.
+ */
+int mmc_cache_ctrl(struct mmc_host *host, u8 enable)
+{
+       struct mmc_card *card = host->card;
+       int err = 0;
+
+       if (!(host->caps2 & MMC_CAP2_CACHE_CTRL) ||
+                       mmc_card_is_removable(host))
+               return err;
+
+       if (card && mmc_card_mmc(card) &&
+                       (card->ext_csd.cache_size > 0)) {
+               enable = !!enable;
+
+               if (card->ext_csd.cache_ctrl ^ enable)
+                       err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
+                                       EXT_CSD_CACHE_CTRL, enable, 0);
+               if (err)
+                       pr_err("%s: cache %s error %d\n",
+                                       mmc_hostname(card->host),
+                                       enable ? "on" : "off",
+                                       err);
+               else
+                       card->ext_csd.cache_ctrl = enable;
+       }
+
+       return err;
+}
+EXPORT_SYMBOL(mmc_cache_ctrl);
+
 #ifdef CONFIG_PM
 
 /**
@@ -1960,23 +2288,39 @@ int mmc_suspend_host(struct mmc_host *host)
                cancel_delayed_work(&host->disable);
        cancel_delayed_work(&host->detect);
        mmc_flush_scheduled_work();
+       err = mmc_cache_ctrl(host, 0);
+       if (err)
+               goto out;
 
        mmc_bus_get(host);
        if (host->bus_ops && !host->bus_dead) {
-               if (host->bus_ops->suspend)
-                       err = host->bus_ops->suspend(host);
-               if (err == -ENOSYS || !host->bus_ops->resume) {
-                       /*
-                        * We simply "remove" the card in this case.
-                        * It will be redetected on resume.
-                        */
-                       if (host->bus_ops->remove)
-                               host->bus_ops->remove(host);
-                       mmc_claim_host(host);
-                       mmc_detach_bus(host);
-                       mmc_release_host(host);
-                       host->pm_flags = 0;
-                       err = 0;
+
+               /*
+                * A long response time is not acceptable for device drivers
+                * when doing suspend. Prevent mmc_claim_host in the suspend
+                * sequence, to potentially wait "forever" by trying to
+                * pre-claim the host.
+                */
+               if (mmc_try_claim_host(host)) {
+                       if (host->bus_ops->suspend)
+                               err = host->bus_ops->suspend(host);
+                       if (err == -ENOSYS || !host->bus_ops->resume) {
+                               /*
+                                * We simply "remove" the card in this case.
+                                * It will be redetected on resume.
+                                */
+                               if (host->bus_ops->remove)
+                                       host->bus_ops->remove(host);
+                               mmc_claim_host(host);
+                               mmc_detach_bus(host);
+                               mmc_power_off(host);
+                               mmc_release_host(host);
+                               host->pm_flags = 0;
+                               err = 0;
+                       }
+                       mmc_do_release_host(host);
+               } else {
+                       err = -EBUSY;
                }
        }
        mmc_bus_put(host);
@@ -1984,6 +2328,7 @@ int mmc_suspend_host(struct mmc_host *host)
        if (!err && !mmc_card_keep_power(host))
                mmc_power_off(host);
 
+out:
        return err;
 }
 
@@ -2018,7 +2363,7 @@ int mmc_resume_host(struct mmc_host *host)
                BUG_ON(!host->bus_ops->resume);
                err = host->bus_ops->resume(host);
                if (err) {
-                       printk(KERN_WARNING "%s: error %d during resume "
+                       pr_warning("%s: error %d during resume "
                                            "(card was removed?)\n",
                                            mmc_hostname(host), err);
                        err = 0;
@@ -2049,6 +2394,7 @@ int mmc_pm_notify(struct notifier_block *notify_block,
 
                spin_lock_irqsave(&host->lock, flags);
                host->rescan_disable = 1;
+               host->power_notify_type = MMC_HOST_PW_NOTIFY_SHORT;
                spin_unlock_irqrestore(&host->lock, flags);
                cancel_delayed_work_sync(&host->detect);
 
@@ -2061,6 +2407,7 @@ int mmc_pm_notify(struct notifier_block *notify_block,
                        host->bus_ops->remove(host);
 
                mmc_detach_bus(host);
+               mmc_power_off(host);
                mmc_release_host(host);
                host->pm_flags = 0;
                break;
@@ -2071,6 +2418,7 @@ int mmc_pm_notify(struct notifier_block *notify_block,
 
                spin_lock_irqsave(&host->lock, flags);
                host->rescan_disable = 0;
+               host->power_notify_type = MMC_HOST_PW_NOTIFY_LONG;
                spin_unlock_irqrestore(&host->lock, flags);
                mmc_detect_change(host, 0);
 
index d9411ed2a39bf6490a5a788629d45a628e14e6fe..14664f1fb16fb560c526dd30817cc10ae6db1adf 100644 (file)
@@ -43,6 +43,7 @@ int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage,
                           bool cmd11);
 void mmc_set_timing(struct mmc_host *host, unsigned int timing);
 void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type);
+void mmc_power_off(struct mmc_host *host);
 
 static inline void mmc_delay(unsigned int ms)
 {
index 998797ed67a6d0f49802985c31d70b8f4cef0be8..6045ea469362ebf3875f57af34c13451d9c665ad 100644 (file)
@@ -7,11 +7,13 @@
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  */
+#include <linux/moduleparam.h>
 #include <linux/debugfs.h>
 #include <linux/fs.h>
 #include <linux/seq_file.h>
 #include <linux/slab.h>
 #include <linux/stat.h>
+#include <linux/fault-inject.h>
 
 #include <linux/mmc/card.h>
 #include <linux/mmc/host.h>
 #include "core.h"
 #include "mmc_ops.h"
 
+#ifdef CONFIG_FAIL_MMC_REQUEST
+
+static DECLARE_FAULT_ATTR(fail_default_attr);
+static char *fail_request;
+module_param(fail_request, charp, 0);
+
+#endif /* CONFIG_FAIL_MMC_REQUEST */
+
 /* The debugfs functions are optimized away when CONFIG_DEBUG_FS isn't set. */
 static int mmc_ios_show(struct seq_file *s, void *data)
 {
@@ -113,6 +123,15 @@ static int mmc_ios_show(struct seq_file *s, void *data)
        case MMC_TIMING_SD_HS:
                str = "sd high-speed";
                break;
+       case MMC_TIMING_UHS_SDR50:
+               str = "sd uhs SDR50";
+               break;
+       case MMC_TIMING_UHS_SDR104:
+               str = "sd uhs SDR104";
+               break;
+       case MMC_TIMING_UHS_DDR50:
+               str = "sd uhs DDR50";
+               break;
        default:
                str = "invalid";
                break;
@@ -187,6 +206,15 @@ void mmc_add_host_debugfs(struct mmc_host *host)
        if (!debugfs_create_u32("clk_delay", (S_IRUSR | S_IWUSR),
                                root, &host->clk_delay))
                goto err_node;
+#endif
+#ifdef CONFIG_FAIL_MMC_REQUEST
+       if (fail_request)
+               setup_fault_attr(&fail_default_attr, fail_request);
+       host->fail_mmc_request = fail_default_attr;
+       if (IS_ERR(fault_create_debugfs_attr("fail_mmc_request",
+                                            root,
+                                            &host->fail_mmc_request)))
+               goto err_node;
 #endif
        return;
 
index 793d0a0dad8d74d85d239da2c3b107e47a5d1b4e..ca2e4f50f61580f65b213159af86647272fbea2d 100644 (file)
@@ -301,6 +301,17 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
        host->max_blk_size = 512;
        host->max_blk_count = PAGE_CACHE_SIZE / 512;
 
+       /*
+        * Enable runtime power management by default. This flag was added due
+        * to runtime power management causing disruption for some users, but
+        * the power on/off code has been improved since then.
+        *
+        * We'll enable this flag by default as an experiment, and if no
+        * problems are reported, we will follow up later and remove the flag
+        * altogether.
+        */
+       host->caps = MMC_CAP_POWER_OFF_CARD;
+
        return host;
 
 free:
index 5700b1cbdfec05ffc606879d4da293d24f63484d..36270449dd9d24c20167484bfbeb70b7b9f4e6d4 100644 (file)
@@ -101,7 +101,7 @@ static int mmc_decode_cid(struct mmc_card *card)
                break;
 
        default:
-               printk(KERN_ERR "%s: card has unknown MMCA version %d\n",
+               pr_err("%s: card has unknown MMCA version %d\n",
                        mmc_hostname(card->host), card->csd.mmca_vsn);
                return -EINVAL;
        }
@@ -135,7 +135,7 @@ static int mmc_decode_csd(struct mmc_card *card)
         */
        csd->structure = UNSTUFF_BITS(resp, 126, 2);
        if (csd->structure == 0) {
-               printk(KERN_ERR "%s: unrecognised CSD structure version %d\n",
+               pr_err("%s: unrecognised CSD structure version %d\n",
                        mmc_hostname(card->host), csd->structure);
                return -EINVAL;
        }
@@ -195,7 +195,7 @@ static int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd)
         */
        ext_csd = kmalloc(512, GFP_KERNEL);
        if (!ext_csd) {
-               printk(KERN_ERR "%s: could not allocate a buffer to "
+               pr_err("%s: could not allocate a buffer to "
                        "receive the ext_csd.\n", mmc_hostname(card->host));
                return -ENOMEM;
        }
@@ -217,12 +217,12 @@ static int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd)
                 * stored in their CSD.
                 */
                if (card->csd.capacity == (4096 * 512)) {
-                       printk(KERN_ERR "%s: unable to read EXT_CSD "
+                       pr_err("%s: unable to read EXT_CSD "
                                "on a possible high capacity card. "
                                "Card will be ignored.\n",
                                mmc_hostname(card->host));
                } else {
-                       printk(KERN_WARNING "%s: unable to read "
+                       pr_warning("%s: unable to read "
                                "EXT_CSD, performance might "
                                "suffer.\n",
                                mmc_hostname(card->host));
@@ -239,7 +239,9 @@ static int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd)
  */
 static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
 {
-       int err = 0;
+       int err = 0, idx;
+       unsigned int part_size;
+       u8 hc_erase_grp_sz = 0, hc_wp_grp_sz = 0;
 
        BUG_ON(!card);
 
@@ -250,7 +252,7 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
        card->ext_csd.raw_ext_csd_structure = ext_csd[EXT_CSD_STRUCTURE];
        if (card->csd.structure == 3) {
                if (card->ext_csd.raw_ext_csd_structure > 2) {
-                       printk(KERN_ERR "%s: unrecognised EXT_CSD structure "
+                       pr_err("%s: unrecognised EXT_CSD structure "
                                "version %d\n", mmc_hostname(card->host),
                                        card->ext_csd.raw_ext_csd_structure);
                        err = -EINVAL;
@@ -260,7 +262,7 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
 
        card->ext_csd.rev = ext_csd[EXT_CSD_REV];
        if (card->ext_csd.rev > 6) {
-               printk(KERN_ERR "%s: unrecognised EXT_CSD revision %d\n",
+               pr_err("%s: unrecognised EXT_CSD revision %d\n",
                        mmc_hostname(card->host), card->ext_csd.rev);
                err = -EINVAL;
                goto out;
@@ -306,7 +308,7 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
                break;
        default:
                /* MMC v4 spec says this cannot happen */
-               printk(KERN_WARNING "%s: card is mmc v4 but doesn't "
+               pr_warning("%s: card is mmc v4 but doesn't "
                        "support any high-speed modes.\n",
                        mmc_hostname(card->host));
        }
@@ -340,7 +342,14 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
                 * There are two boot regions of equal size, defined in
                 * multiples of 128K.
                 */
-               card->ext_csd.boot_size = ext_csd[EXT_CSD_BOOT_MULT] << 17;
+               if (ext_csd[EXT_CSD_BOOT_MULT] && mmc_boot_partition_access(card->host)) {
+                       for (idx = 0; idx < MMC_NUM_BOOT_PARTITION; idx++) {
+                               part_size = ext_csd[EXT_CSD_BOOT_MULT] << 17;
+                               mmc_part_add(card, part_size,
+                                       EXT_CSD_PART_CONFIG_ACC_BOOT0 + idx,
+                                       "boot%d", idx, true);
+                       }
+               }
        }
 
        card->ext_csd.raw_hc_erase_gap_size =
@@ -359,11 +368,12 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
                 * card has the Enhanced area enabled.  If so, export enhanced
                 * area offset and size to user by adding sysfs interface.
                 */
+               card->ext_csd.raw_partition_support = ext_csd[EXT_CSD_PARTITION_SUPPORT];
                if ((ext_csd[EXT_CSD_PARTITION_SUPPORT] & 0x2) &&
                    (ext_csd[EXT_CSD_PARTITION_ATTRIBUTE] & 0x1)) {
-                       u8 hc_erase_grp_sz =
+                       hc_erase_grp_sz =
                                ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
-                       u8 hc_wp_grp_sz =
+                       hc_wp_grp_sz =
                                ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
 
                        card->ext_csd.enhanced_area_en = 1;
@@ -392,6 +402,41 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
                        card->ext_csd.enhanced_area_offset = -EINVAL;
                        card->ext_csd.enhanced_area_size = -EINVAL;
                }
+
+               /*
+                * General purpose partition feature support --
+                * If ext_csd has the size of general purpose partitions,
+                * set size, part_cfg, partition name in mmc_part.
+                */
+               if (ext_csd[EXT_CSD_PARTITION_SUPPORT] &
+                       EXT_CSD_PART_SUPPORT_PART_EN) {
+                       if (card->ext_csd.enhanced_area_en != 1) {
+                               hc_erase_grp_sz =
+                                       ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
+                               hc_wp_grp_sz =
+                                       ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
+
+                               card->ext_csd.enhanced_area_en = 1;
+                       }
+
+                       for (idx = 0; idx < MMC_NUM_GP_PARTITION; idx++) {
+                               if (!ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3] &&
+                               !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 1] &&
+                               !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 2])
+                                       continue;
+                               part_size =
+                               (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 2]
+                                       << 16) +
+                               (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 1]
+                                       << 8) +
+                               ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3];
+                               part_size *= (size_t)(hc_erase_grp_sz *
+                                       hc_wp_grp_sz);
+                               mmc_part_add(card, part_size << 19,
+                                       EXT_CSD_PART_CONFIG_ACC_GP0 + idx,
+                                       "gp%d", idx, false);
+                       }
+               }
                card->ext_csd.sec_trim_mult =
                        ext_csd[EXT_CSD_SEC_TRIM_MULT];
                card->ext_csd.sec_erase_mult =
@@ -402,14 +447,48 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
                        ext_csd[EXT_CSD_TRIM_MULT];
        }
 
-       if (card->ext_csd.rev >= 5)
+       if (card->ext_csd.rev >= 5) {
+               /* check whether the eMMC card supports HPI */
+               if (ext_csd[EXT_CSD_HPI_FEATURES] & 0x1) {
+                       card->ext_csd.hpi = 1;
+                       if (ext_csd[EXT_CSD_HPI_FEATURES] & 0x2)
+                               card->ext_csd.hpi_cmd = MMC_STOP_TRANSMISSION;
+                       else
+                               card->ext_csd.hpi_cmd = MMC_SEND_STATUS;
+                       /*
+                        * Indicate the maximum timeout to close
+                        * a command interrupted by HPI
+                        */
+                       card->ext_csd.out_of_int_time =
+                               ext_csd[EXT_CSD_OUT_OF_INTERRUPT_TIME] * 10;
+               }
+
                card->ext_csd.rel_param = ext_csd[EXT_CSD_WR_REL_PARAM];
+               card->ext_csd.rst_n_function = ext_csd[EXT_CSD_RST_N_FUNCTION];
+       }
 
+       card->ext_csd.raw_erased_mem_count = ext_csd[EXT_CSD_ERASED_MEM_CONT];
        if (ext_csd[EXT_CSD_ERASED_MEM_CONT])
                card->erased_byte = 0xFF;
        else
                card->erased_byte = 0x0;
 
+       /* eMMC v4.5 or later */
+       if (card->ext_csd.rev >= 6) {
+               card->ext_csd.feature_support |= MMC_DISCARD_FEATURE;
+
+               card->ext_csd.generic_cmd6_time = 10 *
+                       ext_csd[EXT_CSD_GENERIC_CMD6_TIME];
+               card->ext_csd.power_off_longtime = 10 *
+                       ext_csd[EXT_CSD_POWER_OFF_LONG_TIME];
+
+               card->ext_csd.cache_size =
+                       ext_csd[EXT_CSD_CACHE_SIZE + 0] << 0 |
+                       ext_csd[EXT_CSD_CACHE_SIZE + 1] << 8 |
+                       ext_csd[EXT_CSD_CACHE_SIZE + 2] << 16 |
+                       ext_csd[EXT_CSD_CACHE_SIZE + 3] << 24;
+       }
+
 out:
        return err;
 }
@@ -529,6 +608,86 @@ static struct device_type mmc_type = {
        .groups = mmc_attr_groups,
 };
 
+/*
+ * Select the PowerClass for the current bus width
+ * If power class is defined for 4/8 bit bus in the
+ * extended CSD register, select it by executing the
+ * mmc_switch command.
+ */
+static int mmc_select_powerclass(struct mmc_card *card,
+               unsigned int bus_width, u8 *ext_csd)
+{
+       int err = 0;
+       unsigned int pwrclass_val;
+       unsigned int index = 0;
+       struct mmc_host *host;
+
+       BUG_ON(!card);
+
+       host = card->host;
+       BUG_ON(!host);
+
+       if (ext_csd == NULL)
+               return 0;
+
+       /* Power class selection is supported for versions >= 4.0 */
+       if (card->csd.mmca_vsn < CSD_SPEC_VER_4)
+               return 0;
+
+       /* Power class values are defined only for 4/8 bit bus */
+       if (bus_width == EXT_CSD_BUS_WIDTH_1)
+               return 0;
+
+       switch (1 << host->ios.vdd) {
+       case MMC_VDD_165_195:
+               if (host->ios.clock <= 26000000)
+                       index = EXT_CSD_PWR_CL_26_195;
+               else if (host->ios.clock <= 52000000)
+                       index = (bus_width <= EXT_CSD_BUS_WIDTH_8) ?
+                               EXT_CSD_PWR_CL_52_195 :
+                               EXT_CSD_PWR_CL_DDR_52_195;
+               else if (host->ios.clock <= 200000000)
+                       index = EXT_CSD_PWR_CL_200_195;
+               break;
+       case MMC_VDD_32_33:
+       case MMC_VDD_33_34:
+       case MMC_VDD_34_35:
+       case MMC_VDD_35_36:
+               if (host->ios.clock <= 26000000)
+                       index = EXT_CSD_PWR_CL_26_360;
+               else if (host->ios.clock <= 52000000)
+                       index = (bus_width <= EXT_CSD_BUS_WIDTH_8) ?
+                               EXT_CSD_PWR_CL_52_360 :
+                               EXT_CSD_PWR_CL_DDR_52_360;
+               else if (host->ios.clock <= 200000000)
+                       index = EXT_CSD_PWR_CL_200_360;
+               break;
+       default:
+               pr_warning("%s: Voltage range not supported "
+                          "for power class.\n", mmc_hostname(host));
+               return -EINVAL;
+       }
+
+       pwrclass_val = ext_csd[index];
+
+       if (bus_width & (EXT_CSD_BUS_WIDTH_8 | EXT_CSD_DDR_BUS_WIDTH_8))
+               pwrclass_val = (pwrclass_val & EXT_CSD_PWR_CL_8BIT_MASK) >>
+                               EXT_CSD_PWR_CL_8BIT_SHIFT;
+       else
+               pwrclass_val = (pwrclass_val & EXT_CSD_PWR_CL_4BIT_MASK) >>
+                               EXT_CSD_PWR_CL_4BIT_SHIFT;
+
+       /* If the power class is different from the default value */
+       if (pwrclass_val > 0) {
+               err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
+                                EXT_CSD_POWER_CLASS,
+                                pwrclass_val,
+                                card->ext_csd.generic_cmd6_time);
+       }
+
+       return err;
+}
+
 /*
  * Handle the detection and initialisation of a card.
  *
@@ -548,11 +707,16 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
        BUG_ON(!host);
        WARN_ON(!host->claimed);
 
+       /* Set correct bus mode for MMC before attempting init */
+       if (!mmc_host_is_spi(host))
+               mmc_set_bus_mode(host, MMC_BUSMODE_OPENDRAIN);
+
        /*
         * Since we're changing the OCR value, we seem to
         * need to tell some cards to go back to the idle
         * state.  We wait 1ms to give cards time to
         * respond.
+        * mmc_go_idle is needed for eMMC that are asleep
         */
        mmc_go_idle(host);
 
@@ -668,7 +832,8 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
         */
        if (card->ext_csd.enhanced_area_en) {
                err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
-                                EXT_CSD_ERASE_GROUP_DEF, 1, 0);
+                                EXT_CSD_ERASE_GROUP_DEF, 1,
+                                card->ext_csd.generic_cmd6_time);
 
                if (err && err != -EBADMSG)
                        goto free_card;
@@ -705,18 +870,36 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
                        goto free_card;
        }
 
+       /*
+        * If the host supports the power_off_notify capability then
+        * set the notification byte in the ext_csd register of device
+        */
+       if ((host->caps2 & MMC_CAP2_POWEROFF_NOTIFY) &&
+           (card->poweroff_notify_state == MMC_NO_POWER_NOTIFICATION)) {
+               err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
+                                EXT_CSD_POWER_OFF_NOTIFICATION,
+                                EXT_CSD_POWER_ON,
+                                card->ext_csd.generic_cmd6_time);
+               if (err && err != -EBADMSG)
+                       goto free_card;
+       }
+
+       if (!err)
+               card->poweroff_notify_state = MMC_POWERED_ON;
+
        /*
         * Activate high speed (if supported)
         */
        if ((card->ext_csd.hs_max_dtr != 0) &&
                (host->caps & MMC_CAP_MMC_HIGHSPEED)) {
                err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
-                                EXT_CSD_HS_TIMING, 1, 0);
+                                EXT_CSD_HS_TIMING, 1,
+                                card->ext_csd.generic_cmd6_time);
                if (err && err != -EBADMSG)
                        goto free_card;
 
                if (err) {
-                       printk(KERN_WARNING "%s: switch to highspeed failed\n",
+                       pr_warning("%s: switch to highspeed failed\n",
                               mmc_hostname(card->host));
                        err = 0;
                } else {
@@ -725,6 +908,22 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
                }
        }
 
+       /*
+        * Enable HPI feature (if supported)
+        */
+       if (card->ext_csd.hpi) {
+               err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
+                       EXT_CSD_HPI_MGMT, 1, 0);
+               if (err && err != -EBADMSG)
+                       goto free_card;
+               if (err) {
+                       pr_warning("%s: Enabling HPI failed\n",
+                                  mmc_hostname(card->host));
+                       err = 0;
+               } else
+                       card->ext_csd.hpi_en = 1;
+       }
+
        /*
         * Compute bus speed.
         */
@@ -780,10 +979,18 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
                        bus_width = bus_widths[idx];
                        if (bus_width == MMC_BUS_WIDTH_1)
                                ddr = 0; /* no DDR for 1-bit width */
+                       err = mmc_select_powerclass(card, ext_csd_bits[idx][0],
+                                                   ext_csd);
+                       if (err)
+                               pr_err("%s: power class selection to "
+                                      "bus width %d failed\n",
+                                      mmc_hostname(card->host),
+                                      1 << bus_width);
+
                        err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
                                         EXT_CSD_BUS_WIDTH,
                                         ext_csd_bits[idx][0],
-                                        0);
+                                        card->ext_csd.generic_cmd6_time);
                        if (!err) {
                                mmc_set_bus_width(card->host, bus_width);
 
@@ -803,13 +1010,21 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
                }
 
                if (!err && ddr) {
+                       err = mmc_select_powerclass(card, ext_csd_bits[idx][1],
+                                                   ext_csd);
+                       if (err)
+                               pr_err("%s: power class selection to "
+                                      "bus width %d ddr %d failed\n",
+                                      mmc_hostname(card->host),
+                                      1 << bus_width, ddr);
+
                        err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
                                         EXT_CSD_BUS_WIDTH,
                                         ext_csd_bits[idx][1],
-                                        0);
+                                        card->ext_csd.generic_cmd6_time);
                }
                if (err) {
-                       printk(KERN_WARNING "%s: switch to bus width %d ddr %d "
+                       pr_warning("%s: switch to bus width %d ddr %d "
                                "failed\n", mmc_hostname(card->host),
                                1 << bus_width, ddr);
                        goto free_card;
@@ -840,6 +1055,23 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
                }
        }
 
+       /*
+        * If cache size is higher than 0, this indicates
+        * the existence of cache and it can be turned on.
+        */
+       if ((host->caps2 & MMC_CAP2_CACHE_CTRL) &&
+                       card->ext_csd.cache_size > 0) {
+               err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
+                               EXT_CSD_CACHE_CTRL, 1, 0);
+               if (err && err != -EBADMSG)
+                       goto free_card;
+
+               /*
+                * Only if no error, cache is turned on successfully.
+                */
+               card->ext_csd.cache_ctrl = err ? 0 : 1;
+       }
+
        if (!oldcard)
                host->card = card;
 
@@ -891,6 +1123,7 @@ static void mmc_detect(struct mmc_host *host)
 
                mmc_claim_host(host);
                mmc_detach_bus(host);
+               mmc_power_off(host);
                mmc_release_host(host);
        }
 }
@@ -900,16 +1133,20 @@ static void mmc_detect(struct mmc_host *host)
  */
 static int mmc_suspend(struct mmc_host *host)
 {
+       int err = 0;
+
        BUG_ON(!host);
        BUG_ON(!host->card);
 
        mmc_claim_host(host);
-       if (!mmc_host_is_spi(host))
+       if (mmc_card_can_sleep(host))
+               err = mmc_card_sleep(host);
+       else if (!mmc_host_is_spi(host))
                mmc_deselect_cards(host);
        host->card->state &= ~MMC_STATE_HIGHSPEED;
        mmc_release_host(host);
 
-       return 0;
+       return err;
 }
 
 /*
@@ -1016,6 +1253,10 @@ int mmc_attach_mmc(struct mmc_host *host)
        BUG_ON(!host);
        WARN_ON(!host->claimed);
 
+       /* Set correct bus mode for MMC before attempting attach */
+       if (!mmc_host_is_spi(host))
+               mmc_set_bus_mode(host, MMC_BUSMODE_OPENDRAIN);
+
        err = mmc_send_op_cond(host, 0, &ocr);
        if (err)
                return err;
@@ -1038,7 +1279,7 @@ int mmc_attach_mmc(struct mmc_host *host)
         * support.
         */
        if (ocr & 0x7F) {
-               printk(KERN_WARNING "%s: card claims to support voltages "
+               pr_warning("%s: card claims to support voltages "
                       "below the defined range. These will be ignored.\n",
                       mmc_hostname(host));
                ocr &= ~0x7F;
@@ -1077,7 +1318,7 @@ remove_card:
 err:
        mmc_detach_bus(host);
 
-       printk(KERN_ERR "%s: error %d whilst initialising MMC card\n",
+       pr_err("%s: error %d whilst initialising MMC card\n",
                mmc_hostname(host), err);
 
        return err;
index 770c3d06f5dcd1a01814065464d7c20a6f7d051f..007863eea4fb73ba72ad3bc052b0cc139c137456 100644 (file)
@@ -233,7 +233,7 @@ static int
 mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
                u32 opcode, void *buf, unsigned len)
 {
-       struct mmc_request mrq = {0};
+       struct mmc_request mrq = {NULL};
        struct mmc_command cmd = {0};
        struct mmc_data data = {0};
        struct scatterlist sg;
@@ -414,7 +414,7 @@ int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
                        return -EBADMSG;
        } else {
                if (status & 0xFDFFA000)
-                       printk(KERN_WARNING "%s: unexpected status %#x after "
+                       pr_warning("%s: unexpected status %#x after "
                               "switch", mmc_hostname(card->host), status);
                if (status & R1_SWITCH_ERROR)
                        return -EBADMSG;
@@ -454,7 +454,7 @@ static int
 mmc_send_bus_test(struct mmc_card *card, struct mmc_host *host, u8 opcode,
                  u8 len)
 {
-       struct mmc_request mrq = {0};
+       struct mmc_request mrq = {NULL};
        struct mmc_command cmd = {0};
        struct mmc_data data = {0};
        struct scatterlist sg;
@@ -476,7 +476,7 @@ mmc_send_bus_test(struct mmc_card *card, struct mmc_host *host, u8 opcode,
        else if (len == 4)
                test_buf = testdata_4bit;
        else {
-               printk(KERN_ERR "%s: Invalid bus_width %d\n",
+               pr_err("%s: Invalid bus_width %d\n",
                       mmc_hostname(host), len);
                kfree(data_buf);
                return -EINVAL;
@@ -547,3 +547,34 @@ int mmc_bus_test(struct mmc_card *card, u8 bus_width)
        err = mmc_send_bus_test(card, card->host, MMC_BUS_TEST_R, width);
        return err;
 }
+
+int mmc_send_hpi_cmd(struct mmc_card *card, u32 *status)
+{
+       struct mmc_command cmd = {0};
+       unsigned int opcode;
+       unsigned int flags;
+       int err;
+
+       opcode = card->ext_csd.hpi_cmd;
+       if (opcode == MMC_STOP_TRANSMISSION)
+               flags = MMC_RSP_R1 | MMC_CMD_AC;
+       else if (opcode == MMC_SEND_STATUS)
+               flags = MMC_RSP_R1 | MMC_CMD_AC;
+
+       cmd.opcode = opcode;
+       cmd.arg = card->rca << 16 | 1;
+       cmd.flags = flags;
+       cmd.cmd_timeout_ms = card->ext_csd.out_of_int_time;
+
+       err = mmc_wait_for_cmd(card->host, &cmd, 0);
+       if (err) {
+               pr_warn("%s: error %d interrupting operation. "
+                       "HPI command response %#x\n", mmc_hostname(card->host),
+                       err, cmd.resp[0]);
+               return err;
+       }
+       if (status)
+               *status = cmd.resp[0];
+
+       return 0;
+}
index 9276946fa5b719b8d1128c2ed94dedc73406ab12..3dd8941c29801a6ce5c482e5400a067b54950f51 100644 (file)
@@ -26,6 +26,7 @@ int mmc_spi_read_ocr(struct mmc_host *host, int highcap, u32 *ocrp);
 int mmc_spi_set_crc(struct mmc_host *host, int use_crc);
 int mmc_card_sleepawake(struct mmc_host *host, int sleep);
 int mmc_bus_test(struct mmc_card *card, u8 bus_width);
+int mmc_send_hpi_cmd(struct mmc_card *card, u32 *status);
 
 #endif
 
index 3a596217029e1e94fbd9797f2d324fa5dde03472..6c3cf98a62eb6d04825afb1b792e5d4e1c3ade55 100644 (file)
 #define SDIO_DEVICE_ID_TI_WL1271       0x4076
 #endif
 
+#ifndef SDIO_VENDOR_ID_STE
+#define SDIO_VENDOR_ID_STE             0x0020
+#endif
+
+#ifndef SDIO_DEVICE_ID_STE_CW1200
+#define SDIO_DEVICE_ID_STE_CW1200      0x2280
+#endif
+
 /*
  * This hook just adds a quirk for all sdio devices
  */
@@ -46,6 +54,9 @@ static const struct mmc_fixup mmc_fixup_methods[] = {
        SDIO_FIXUP(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271,
                   add_quirk, MMC_QUIRK_DISABLE_CD),
 
+       SDIO_FIXUP(SDIO_VENDOR_ID_STE, SDIO_DEVICE_ID_STE_CW1200,
+                  add_quirk, MMC_QUIRK_BROKEN_BYTE_MODE_512),
+
        END_FIXUP
 };
 
index 0370e03e314253f027a36aa994591ea2817f0826..a230e7f9d77a5c79c2f1b9f52606f5d9b53dce8c 100644 (file)
@@ -163,7 +163,7 @@ static int mmc_decode_csd(struct mmc_card *card)
                csd->erase_size = 1;
                break;
        default:
-               printk(KERN_ERR "%s: unrecognised CSD structure version %d\n",
+               pr_err("%s: unrecognised CSD structure version %d\n",
                        mmc_hostname(card->host), csd_struct);
                return -EINVAL;
        }
@@ -187,7 +187,7 @@ static int mmc_decode_scr(struct mmc_card *card)
 
        scr_struct = UNSTUFF_BITS(resp, 60, 4);
        if (scr_struct != 0) {
-               printk(KERN_ERR "%s: unrecognised SCR structure version %d\n",
+               pr_err("%s: unrecognised SCR structure version %d\n",
                        mmc_hostname(card->host), scr_struct);
                return -EINVAL;
        }
@@ -218,7 +218,7 @@ static int mmc_read_ssr(struct mmc_card *card)
        u32 *ssr;
 
        if (!(card->csd.cmdclass & CCC_APP_SPEC)) {
-               printk(KERN_WARNING "%s: card lacks mandatory SD Status "
+               pr_warning("%s: card lacks mandatory SD Status "
                        "function.\n", mmc_hostname(card->host));
                return 0;
        }
@@ -229,7 +229,7 @@ static int mmc_read_ssr(struct mmc_card *card)
 
        err = mmc_app_sd_status(card, ssr);
        if (err) {
-               printk(KERN_WARNING "%s: problem reading SD Status "
+               pr_warning("%s: problem reading SD Status "
                        "register.\n", mmc_hostname(card->host));
                err = 0;
                goto out;
@@ -253,7 +253,7 @@ static int mmc_read_ssr(struct mmc_card *card)
                        card->ssr.erase_offset = eo * 1000;
                }
        } else {
-               printk(KERN_WARNING "%s: SD Status: Invalid Allocation Unit "
+               pr_warning("%s: SD Status: Invalid Allocation Unit "
                        "size.\n", mmc_hostname(card->host));
        }
 out:
@@ -273,7 +273,7 @@ static int mmc_read_switch(struct mmc_card *card)
                return 0;
 
        if (!(card->csd.cmdclass & CCC_SWITCH)) {
-               printk(KERN_WARNING "%s: card lacks mandatory switch "
+               pr_warning("%s: card lacks mandatory switch "
                        "function, performance might suffer.\n",
                        mmc_hostname(card->host));
                return 0;
@@ -283,7 +283,7 @@ static int mmc_read_switch(struct mmc_card *card)
 
        status = kmalloc(64, GFP_KERNEL);
        if (!status) {
-               printk(KERN_ERR "%s: could not allocate a buffer for "
+               pr_err("%s: could not allocate a buffer for "
                        "switch capabilities.\n",
                        mmc_hostname(card->host));
                return -ENOMEM;
@@ -299,13 +299,16 @@ static int mmc_read_switch(struct mmc_card *card)
                if (err != -EINVAL && err != -ENOSYS && err != -EFAULT)
                        goto out;
 
-               printk(KERN_WARNING "%s: problem reading Bus Speed modes.\n",
+               pr_warning("%s: problem reading Bus Speed modes.\n",
                        mmc_hostname(card->host));
                err = 0;
 
                goto out;
        }
 
+       if (status[13] & UHS_SDR50_BUS_SPEED)
+               card->sw_caps.hs_max_dtr = 50000000;
+
        if (card->scr.sda_spec3) {
                card->sw_caps.sd3_bus_mode = status[13];
 
@@ -319,7 +322,7 @@ static int mmc_read_switch(struct mmc_card *card)
                        if (err != -EINVAL && err != -ENOSYS && err != -EFAULT)
                                goto out;
 
-                       printk(KERN_WARNING "%s: problem reading "
+                       pr_warning("%s: problem reading "
                                "Driver Strength.\n",
                                mmc_hostname(card->host));
                        err = 0;
@@ -339,7 +342,7 @@ static int mmc_read_switch(struct mmc_card *card)
                        if (err != -EINVAL && err != -ENOSYS && err != -EFAULT)
                                goto out;
 
-                       printk(KERN_WARNING "%s: problem reading "
+                       pr_warning("%s: problem reading "
                                "Current Limit.\n",
                                mmc_hostname(card->host));
                        err = 0;
@@ -348,9 +351,6 @@ static int mmc_read_switch(struct mmc_card *card)
                }
 
                card->sw_caps.sd3_curr_limit = status[7];
-       } else {
-               if (status[13] & 0x02)
-                       card->sw_caps.hs_max_dtr = 50000000;
        }
 
 out:
@@ -383,7 +383,7 @@ int mmc_sd_switch_hs(struct mmc_card *card)
 
        status = kmalloc(64, GFP_KERNEL);
        if (!status) {
-               printk(KERN_ERR "%s: could not allocate a buffer for "
+               pr_err("%s: could not allocate a buffer for "
                        "switch capabilities.\n", mmc_hostname(card->host));
                return -ENOMEM;
        }
@@ -393,7 +393,7 @@ int mmc_sd_switch_hs(struct mmc_card *card)
                goto out;
 
        if ((status[16] & 0xF) != 1) {
-               printk(KERN_WARNING "%s: Problem switching card "
+               pr_warning("%s: Problem switching card "
                        "into high-speed mode!\n",
                        mmc_hostname(card->host));
                err = 0;
@@ -459,7 +459,7 @@ static int sd_select_driver_type(struct mmc_card *card, u8 *status)
                return err;
 
        if ((status[15] & 0xF) != drive_strength) {
-               printk(KERN_WARNING "%s: Problem setting drive strength!\n",
+               pr_warning("%s: Problem setting drive strength!\n",
                        mmc_hostname(card->host));
                return 0;
        }
@@ -538,7 +538,7 @@ static int sd_set_bus_speed_mode(struct mmc_card *card, u8 *status)
                return err;
 
        if ((status[16] & 0xF) != card->sd_bus_speed)
-               printk(KERN_WARNING "%s: Problem setting bus speed mode!\n",
+               pr_warning("%s: Problem setting bus speed mode!\n",
                        mmc_hostname(card->host));
        else {
                mmc_set_timing(card->host, timing);
@@ -600,7 +600,7 @@ static int sd_set_current_limit(struct mmc_card *card, u8 *status)
                return err;
 
        if (((status[15] >> 4) & 0x0F) != current_limit)
-               printk(KERN_WARNING "%s: Problem setting current limit!\n",
+               pr_warning("%s: Problem setting current limit!\n",
                        mmc_hostname(card->host));
 
        return 0;
@@ -622,7 +622,7 @@ static int mmc_sd_init_uhs_card(struct mmc_card *card)
 
        status = kmalloc(64, GFP_KERNEL);
        if (!status) {
-               printk(KERN_ERR "%s: could not allocate a buffer for "
+               pr_err("%s: could not allocate a buffer for "
                        "switch capabilities.\n", mmc_hostname(card->host));
                return -ENOMEM;
        }
@@ -852,7 +852,7 @@ int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card,
                        ro = host->ops->get_ro(host);
 
                if (ro < 0) {
-                       printk(KERN_WARNING "%s: host does not "
+                       pr_warning("%s: host does not "
                                "support reading read-only "
                                "switch. assuming write-enable.\n",
                                mmc_hostname(host));
@@ -929,8 +929,6 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
                err = mmc_send_relative_addr(host, &card->rca);
                if (err)
                        return err;
-
-               mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
        }
 
        if (!oldcard) {
@@ -1043,6 +1041,7 @@ static void mmc_sd_detect(struct mmc_host *host)
 
                mmc_claim_host(host);
                mmc_detach_bus(host);
+               mmc_power_off(host);
                mmc_release_host(host);
        }
 }
@@ -1167,7 +1166,7 @@ int mmc_attach_sd(struct mmc_host *host)
         * support.
         */
        if (ocr & 0x7F) {
-               printk(KERN_WARNING "%s: card claims to support voltages "
+               pr_warning("%s: card claims to support voltages "
                       "below the defined range. These will be ignored.\n",
                       mmc_hostname(host));
                ocr &= ~0x7F;
@@ -1175,7 +1174,7 @@ int mmc_attach_sd(struct mmc_host *host)
 
        if ((ocr & MMC_VDD_165_195) &&
            !(host->ocr_avail_sd & MMC_VDD_165_195)) {
-               printk(KERN_WARNING "%s: SD card claims to support the "
+               pr_warning("%s: SD card claims to support the "
                       "incompletely defined 'low voltage range'. This "
                       "will be ignored.\n", mmc_hostname(host));
                ocr &= ~MMC_VDD_165_195;
@@ -1214,7 +1213,7 @@ remove_card:
 err:
        mmc_detach_bus(host);
 
-       printk(KERN_ERR "%s: error %d whilst initialising SD card\n",
+       pr_err("%s: error %d whilst initialising SD card\n",
                mmc_hostname(host), err);
 
        return err;
index 021fed153804cf0c9d3ad20598895ae093b36e5d..46a785419fab59c6cdfced8e082e60f2af4371f6 100644 (file)
@@ -67,7 +67,7 @@ EXPORT_SYMBOL_GPL(mmc_app_cmd);
 int mmc_wait_for_app_cmd(struct mmc_host *host, struct mmc_card *card,
        struct mmc_command *cmd, int retries)
 {
-       struct mmc_request mrq = {0};
+       struct mmc_request mrq = {NULL};
 
        int i, err;
 
@@ -244,7 +244,7 @@ int mmc_send_relative_addr(struct mmc_host *host, unsigned int *rca)
 int mmc_app_send_scr(struct mmc_card *card, u32 *scr)
 {
        int err;
-       struct mmc_request mrq = {0};
+       struct mmc_request mrq = {NULL};
        struct mmc_command cmd = {0};
        struct mmc_data data = {0};
        struct scatterlist sg;
@@ -303,7 +303,7 @@ int mmc_app_send_scr(struct mmc_card *card, u32 *scr)
 int mmc_sd_switch(struct mmc_card *card, int mode, int group,
        u8 value, u8 *resp)
 {
-       struct mmc_request mrq = {0};
+       struct mmc_request mrq = {NULL};
        struct mmc_command cmd = {0};
        struct mmc_data data = {0};
        struct scatterlist sg;
@@ -348,7 +348,7 @@ int mmc_sd_switch(struct mmc_card *card, int mode, int group,
 int mmc_app_sd_status(struct mmc_card *card, void *ssr)
 {
        int err;
-       struct mmc_request mrq = {0};
+       struct mmc_request mrq = {NULL};
        struct mmc_command cmd = {0};
        struct mmc_data data = {0};
        struct scatterlist sg;
index 262fff0191779301232fefba02bc8c916e026b33..3ab565e32a6aca624d6f462879a0c19b7cae7697 100644 (file)
@@ -111,8 +111,8 @@ static int sdio_read_cccr(struct mmc_card *card)
 
        cccr_vsn = data & 0x0f;
 
-       if (cccr_vsn > SDIO_CCCR_REV_1_20) {
-               printk(KERN_ERR "%s: unrecognised CCCR structure version %d\n",
+       if (cccr_vsn > SDIO_CCCR_REV_3_00) {
+               pr_err("%s: unrecognised CCCR structure version %d\n",
                        mmc_hostname(card->host), cccr_vsn);
                return -EINVAL;
        }
@@ -408,8 +408,6 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
                 */
                if (oldcard)
                        oldcard->rca = card->rca;
-
-               mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
        }
 
        /*
@@ -597,6 +595,7 @@ out:
 
                mmc_claim_host(host);
                mmc_detach_bus(host);
+               mmc_power_off(host);
                mmc_release_host(host);
        }
 }
@@ -778,7 +777,7 @@ int mmc_attach_sdio(struct mmc_host *host)
         * support.
         */
        if (ocr & 0x7F) {
-               printk(KERN_WARNING "%s: card claims to support voltages "
+               pr_warning("%s: card claims to support voltages "
                       "below the defined range. These will be ignored.\n",
                       mmc_hostname(host));
                ocr &= ~0x7F;
@@ -875,7 +874,7 @@ remove:
 err:
        mmc_detach_bus(host);
 
-       printk(KERN_ERR "%s: error %d whilst initialising SDIO card\n",
+       pr_err("%s: error %d whilst initialising SDIO card\n",
                mmc_hostname(host), err);
 
        return err;
index e4e6822d09e3d4501ac433bebdb4d33613ba2187..c643b2f78bf1f95a66ad822d4cc559c41b1fdcfd 100644 (file)
@@ -173,7 +173,7 @@ static int sdio_bus_remove(struct device *dev)
        drv->remove(func);
 
        if (func->irq_handler) {
-               printk(KERN_WARNING "WARNING: driver %s did not remove "
+               pr_warning("WARNING: driver %s did not remove "
                        "its interrupt handler!\n", drv->name);
                sdio_claim_host(func);
                sdio_release_irq(func);
index 541bdb89e0c5e03cadcbad743bea8814542446d4..f1c7ed8f4d85a2a58b41c7b44d7899f115edaa02 100644 (file)
@@ -132,7 +132,7 @@ static int cis_tpl_parse(struct mmc_card *card, struct sdio_func *func,
                        ret = -EINVAL;
                }
                if (ret && ret != -EILSEQ && ret != -ENOENT) {
-                       printk(KERN_ERR "%s: bad %s tuple 0x%02x (%u bytes)\n",
+                       pr_err("%s: bad %s tuple 0x%02x (%u bytes)\n",
                               mmc_hostname(card->host), tpl_descr, code, size);
                }
        } else {
@@ -313,7 +313,7 @@ static int sdio_read_cis(struct mmc_card *card, struct sdio_func *func)
 
                        if (ret == -ENOENT) {
                                /* warn about unknown tuples */
-                               printk(KERN_WARNING "%s: queuing unknown"
+                               pr_warning("%s: queuing unknown"
                                       " CIS tuple 0x%02x (%u bytes)\n",
                                       mmc_hostname(card->host),
                                       tpl_code, tpl_link);
index 03ead028d2ce147ac9a33387814b040ec1e91e53..b644dd59c16eee8337e45e59c8b4d61f76d3e2ee 100644 (file)
@@ -45,7 +45,7 @@ static int process_sdio_pending_irqs(struct mmc_card *card)
 
        ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_INTx, 0, &pending);
        if (ret) {
-               printk(KERN_DEBUG "%s: error %d reading SDIO_CCCR_INTx\n",
+               pr_debug("%s: error %d reading SDIO_CCCR_INTx\n",
                       mmc_card_id(card), ret);
                return ret;
        }
@@ -55,7 +55,7 @@ static int process_sdio_pending_irqs(struct mmc_card *card)
                if (pending & (1 << i)) {
                        func = card->sdio_func[i - 1];
                        if (!func) {
-                               printk(KERN_WARNING "%s: pending IRQ for "
+                               pr_warning("%s: pending IRQ for "
                                        "non-existent function\n",
                                        mmc_card_id(card));
                                ret = -EINVAL;
@@ -63,7 +63,7 @@ static int process_sdio_pending_irqs(struct mmc_card *card)
                                func->irq_handler(func);
                                count++;
                        } else {
-                               printk(KERN_WARNING "%s: pending IRQ with no handler\n",
+                               pr_warning("%s: pending IRQ with no handler\n",
                                       sdio_func_id(func));
                                ret = -EINVAL;
                        }
index f087d876c5731ebb0feefe14244811936ddefa70..b0517cc06200177d16766c84f237214a6f813d2f 100644 (file)
@@ -121,7 +121,7 @@ int mmc_io_rw_direct(struct mmc_card *card, int write, unsigned fn,
 int mmc_io_rw_extended(struct mmc_card *card, int write, unsigned fn,
        unsigned addr, int incr_addr, u8 *buf, unsigned blocks, unsigned blksz)
 {
-       struct mmc_request mrq = {0};
+       struct mmc_request mrq = {NULL};
        struct mmc_command cmd = {0};
        struct mmc_data data = {0};
        struct scatterlist sg;
@@ -144,8 +144,11 @@ int mmc_io_rw_extended(struct mmc_card *card, int write, unsigned fn,
        cmd.arg |= fn << 28;
        cmd.arg |= incr_addr ? 0x04000000 : 0x00000000;
        cmd.arg |= addr << 9;
-       if (blocks == 1 && blksz <= 512)
-               cmd.arg |= (blksz == 512) ? 0 : blksz;  /* byte mode */
+       if (blocks == 1 && blksz < 512)
+               cmd.arg |= blksz;                       /* byte mode */
+       else if (blocks == 1 && blksz == 512 &&
+                !(mmc_card_broken_byte_mode_512(card)))
+               cmd.arg |= 0;                           /* byte mode, 0==512 */
        else
                cmd.arg |= 0x08000000 | blocks;         /* block mode */
        cmd.flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_ADTC;
index 8c87096531e98fb0bb7846f46a2daaa4828a280c..87d5067ba629a13b8ce96e602ac88f5734a45973 100644 (file)
@@ -130,13 +130,13 @@ config MMC_SDHCI_CNS3XXX
          If unsure, say N.
 
 config MMC_SDHCI_ESDHC_IMX
-       tristate "SDHCI platform support for the Freescale eSDHC i.MX controller"
-       depends on ARCH_MX25 || ARCH_MX35 || ARCH_MX5
+       tristate "SDHCI support for the Freescale eSDHC/uSDHC i.MX controller"
+       depends on ARCH_MXC
        depends on MMC_SDHCI_PLTFM
        select MMC_SDHCI_IO_ACCESSORS
        help
-         This selects the Freescale eSDHC controller support on the platform
-         bus, found on platforms like mx35/51.
+         This selects the Freescale eSDHC/uSDHC controller support
+         found on i.MX25, i.MX35 i.MX5x and i.MX6x.
 
          If you have a controller with this interface, say Y or M here.
 
@@ -326,11 +326,11 @@ config MMC_MSM
          support for SDIO devices.
 
 config MMC_MXC
-       tristate "Freescale i.MX2/3 Multimedia Card Interface support"
-       depends on MACH_MX21 || MACH_MX27 || ARCH_MX31
+       tristate "Freescale i.MX21/27/31 Multimedia Card Interface support"
+       depends on ARCH_MXC
        help
-         This selects the Freescale i.MX2/3 Multimedia card Interface.
-         If you have a i.MX platform with a Multimedia Card slot,
+         This selects the Freescale i.MX21, i.MX27 and i.MX31 Multimedia card
+         Interface. If you have a i.MX platform with a Multimedia Card slot,
          say Y or M here.
 
          If unsure, say N.
index a4aa3af86fedb68ad07eef68e37bff8f65b61e30..a8b4d2aa18e510817a6e83409558078639dd862d 100644 (file)
@@ -869,7 +869,11 @@ static irqreturn_t at91_mci_irq(int irq, void *devid)
 static irqreturn_t at91_mmc_det_irq(int irq, void *_host)
 {
        struct at91mci_host *host = _host;
-       int present = !gpio_get_value(irq_to_gpio(irq));
+       int present;
+
+       /* entering this ISR means that we have configured det_pin:
+        * we can use its value in board structure */
+       present = !gpio_get_value(host->board->det_pin);
 
        /*
         * we expect this irq on both insert and remove,
index fc8a0fe7c5c57b1fbf3282733b285c7da40aaf8f..000b3ad0f5ca5d7e1bb1c5a0d81b2130c2279d73 100644 (file)
 #define __DRIVERS_MMC_ATMEL_MCI_H__
 
 /* MCI Register Definitions */
-#define MCI_CR                 0x0000  /* Control */
-# define MCI_CR_MCIEN          (  1 <<  0)     /* MCI Enable */
-# define MCI_CR_MCIDIS         (  1 <<  1)     /* MCI Disable */
-# define MCI_CR_PWSEN          (  1 <<  2)     /* Power Save Enable */
-# define MCI_CR_PWSDIS         (  1 <<  3)     /* Power Save Disable */
-# define MCI_CR_SWRST          (  1 <<  7)     /* Software Reset */
-#define MCI_MR                 0x0004  /* Mode */
-# define MCI_MR_CLKDIV(x)      ((x) <<  0)     /* Clock Divider */
-# define MCI_MR_PWSDIV(x)      ((x) <<  8)     /* Power Saving Divider */
-# define MCI_MR_RDPROOF                (  1 << 11)     /* Read Proof */
-# define MCI_MR_WRPROOF                (  1 << 12)     /* Write Proof */
-# define MCI_MR_PDCFBYTE       (  1 << 13)     /* Force Byte Transfer */
-# define MCI_MR_PDCPADV                (  1 << 14)     /* Padding Value */
-# define MCI_MR_PDCMODE                (  1 << 15)     /* PDC-oriented Mode */
-#define MCI_DTOR               0x0008  /* Data Timeout */
-# define MCI_DTOCYC(x)         ((x) <<  0)     /* Data Timeout Cycles */
-# define MCI_DTOMUL(x)         ((x) <<  4)     /* Data Timeout Multiplier */
-#define MCI_SDCR               0x000c  /* SD Card / SDIO */
-# define MCI_SDCSEL_SLOT_A     (  0 <<  0)     /* Select SD slot A */
-# define MCI_SDCSEL_SLOT_B     (  1 <<  0)     /* Select SD slot A */
-# define MCI_SDCSEL_MASK       (  3 <<  0)
-# define MCI_SDCBUS_1BIT       (  0 <<  6)     /* 1-bit data bus */
-# define MCI_SDCBUS_4BIT       (  2 <<  6)     /* 4-bit data bus */
-# define MCI_SDCBUS_8BIT       (  3 <<  6)     /* 8-bit data bus[2] */
-# define MCI_SDCBUS_MASK       (  3 <<  6)
-#define MCI_ARGR               0x0010  /* Command Argument */
-#define MCI_CMDR               0x0014  /* Command */
-# define MCI_CMDR_CMDNB(x)     ((x) <<  0)     /* Command Opcode */
-# define MCI_CMDR_RSPTYP_NONE  (  0 <<  6)     /* No response */
-# define MCI_CMDR_RSPTYP_48BIT (  1 <<  6)     /* 48-bit response */
-# define MCI_CMDR_RSPTYP_136BIT        (  2 <<  6)     /* 136-bit response */
-# define MCI_CMDR_SPCMD_INIT   (  1 <<  8)     /* Initialization command */
-# define MCI_CMDR_SPCMD_SYNC   (  2 <<  8)     /* Synchronized command */
-# define MCI_CMDR_SPCMD_INT    (  4 <<  8)     /* Interrupt command */
-# define MCI_CMDR_SPCMD_INTRESP        (  5 <<  8)     /* Interrupt response */
-# define MCI_CMDR_OPDCMD       (  1 << 11)     /* Open Drain */
-# define MCI_CMDR_MAXLAT_5CYC  (  0 << 12)     /* Max latency 5 cycles */
-# define MCI_CMDR_MAXLAT_64CYC (  1 << 12)     /* Max latency 64 cycles */
-# define MCI_CMDR_START_XFER   (  1 << 16)     /* Start data transfer */
-# define MCI_CMDR_STOP_XFER    (  2 << 16)     /* Stop data transfer */
-# define MCI_CMDR_TRDIR_WRITE  (  0 << 18)     /* Write data */
-# define MCI_CMDR_TRDIR_READ   (  1 << 18)     /* Read data */
-# define MCI_CMDR_BLOCK                (  0 << 19)     /* Single-block transfer */
-# define MCI_CMDR_MULTI_BLOCK  (  1 << 19)     /* Multi-block transfer */
-# define MCI_CMDR_STREAM       (  2 << 19)     /* MMC Stream transfer */
-# define MCI_CMDR_SDIO_BYTE    (  4 << 19)     /* SDIO Byte transfer */
-# define MCI_CMDR_SDIO_BLOCK   (  5 << 19)     /* SDIO Block transfer */
-# define MCI_CMDR_SDIO_SUSPEND (  1 << 24)     /* SDIO Suspend Command */
-# define MCI_CMDR_SDIO_RESUME  (  2 << 24)     /* SDIO Resume Command */
-#define MCI_BLKR               0x0018  /* Block */
-# define MCI_BCNT(x)           ((x) <<  0)     /* Data Block Count */
-# define MCI_BLKLEN(x)         ((x) << 16)     /* Data Block Length */
-#define MCI_CSTOR              0x001c  /* Completion Signal Timeout[2] */
-# define MCI_CSTOCYC(x)                ((x) <<  0)     /* CST cycles */
-# define MCI_CSTOMUL(x)                ((x) <<  4)     /* CST multiplier */
-#define MCI_RSPR               0x0020  /* Response 0 */
-#define MCI_RSPR1              0x0024  /* Response 1 */
-#define MCI_RSPR2              0x0028  /* Response 2 */
-#define MCI_RSPR3              0x002c  /* Response 3 */
-#define MCI_RDR                        0x0030  /* Receive Data */
-#define MCI_TDR                        0x0034  /* Transmit Data */
-#define MCI_SR                 0x0040  /* Status */
-#define MCI_IER                        0x0044  /* Interrupt Enable */
-#define MCI_IDR                        0x0048  /* Interrupt Disable */
-#define MCI_IMR                        0x004c  /* Interrupt Mask */
-# define MCI_CMDRDY            (  1 <<   0)    /* Command Ready */
-# define MCI_RXRDY             (  1 <<   1)    /* Receiver Ready */
-# define MCI_TXRDY             (  1 <<   2)    /* Transmitter Ready */
-# define MCI_BLKE              (  1 <<   3)    /* Data Block Ended */
-# define MCI_DTIP              (  1 <<   4)    /* Data Transfer In Progress */
-# define MCI_NOTBUSY           (  1 <<   5)    /* Data Not Busy */
-# define MCI_SDIOIRQA          (  1 <<   8)    /* SDIO IRQ in slot A */
-# define MCI_SDIOIRQB          (  1 <<   9)    /* SDIO IRQ in slot B */
-# define MCI_RINDE             (  1 <<  16)    /* Response Index Error */
-# define MCI_RDIRE             (  1 <<  17)    /* Response Direction Error */
-# define MCI_RCRCE             (  1 <<  18)    /* Response CRC Error */
-# define MCI_RENDE             (  1 <<  19)    /* Response End Bit Error */
-# define MCI_RTOE              (  1 <<  20)    /* Response Time-Out Error */
-# define MCI_DCRCE             (  1 <<  21)    /* Data CRC Error */
-# define MCI_DTOE              (  1 <<  22)    /* Data Time-Out Error */
-# define MCI_OVRE              (  1 <<  30)    /* RX Overrun Error */
-# define MCI_UNRE              (  1 <<  31)    /* TX Underrun Error */
-#define MCI_DMA                        0x0050  /* DMA Configuration[2] */
-# define MCI_DMA_OFFSET(x)     ((x) <<  0)     /* DMA Write Buffer Offset */
-# define MCI_DMA_CHKSIZE(x)    ((x) <<  4)     /* DMA Channel Read and Write Chunk Size */
-# define MCI_DMAEN             (  1 <<  8)     /* DMA Hardware Handshaking Enable */
-#define MCI_CFG                        0x0054  /* Configuration[2] */
-# define MCI_CFG_FIFOMODE_1DATA        (  1 <<  0)     /* MCI Internal FIFO control mode */
-# define MCI_CFG_FERRCTRL_COR  (  1 <<  4)     /* Flow Error flag reset control mode */
-# define MCI_CFG_HSMODE                (  1 <<  8)     /* High Speed Mode */
-# define MCI_CFG_LSYNC         (  1 << 12)     /* Synchronize on the last block */
-#define MCI_WPMR               0x00e4  /* Write Protection Mode[2] */
-# define MCI_WP_EN             (  1 <<  0)     /* WP Enable */
-# define MCI_WP_KEY            (0x4d4349 << 8) /* WP Key */
-#define MCI_WPSR               0x00e8  /* Write Protection Status[2] */
-# define MCI_GET_WP_VS(x)      ((x) & 0x0f)
-# define MCI_GET_WP_VSRC(x)    (((x) >> 8) & 0xffff)
-#define MCI_FIFO_APERTURE      0x0200  /* FIFO Aperture[2] */
+#define ATMCI_CR                       0x0000  /* Control */
+# define ATMCI_CR_MCIEN                        (  1 <<  0)     /* MCI Enable */
+# define ATMCI_CR_MCIDIS               (  1 <<  1)     /* MCI Disable */
+# define ATMCI_CR_PWSEN                        (  1 <<  2)     /* Power Save Enable */
+# define ATMCI_CR_PWSDIS               (  1 <<  3)     /* Power Save Disable */
+# define ATMCI_CR_SWRST                        (  1 <<  7)     /* Software Reset */
+#define ATMCI_MR                       0x0004  /* Mode */
+# define ATMCI_MR_CLKDIV(x)            ((x) <<  0)     /* Clock Divider */
+# define ATMCI_MR_PWSDIV(x)            ((x) <<  8)     /* Power Saving Divider */
+# define ATMCI_MR_RDPROOF              (  1 << 11)     /* Read Proof */
+# define ATMCI_MR_WRPROOF              (  1 << 12)     /* Write Proof */
+# define ATMCI_MR_PDCFBYTE             (  1 << 13)     /* Force Byte Transfer */
+# define ATMCI_MR_PDCPADV              (  1 << 14)     /* Padding Value */
+# define ATMCI_MR_PDCMODE              (  1 << 15)     /* PDC-oriented Mode */
+#define ATMCI_DTOR                     0x0008  /* Data Timeout */
+# define ATMCI_DTOCYC(x)               ((x) <<  0)     /* Data Timeout Cycles */
+# define ATMCI_DTOMUL(x)               ((x) <<  4)     /* Data Timeout Multiplier */
+#define ATMCI_SDCR                     0x000c  /* SD Card / SDIO */
+# define ATMCI_SDCSEL_SLOT_A           (  0 <<  0)     /* Select SD slot A */
+# define ATMCI_SDCSEL_SLOT_B           (  1 <<  0)     /* Select SD slot A */
+# define ATMCI_SDCSEL_MASK             (  3 <<  0)
+# define ATMCI_SDCBUS_1BIT             (  0 <<  6)     /* 1-bit data bus */
+# define ATMCI_SDCBUS_4BIT             (  2 <<  6)     /* 4-bit data bus */
+# define ATMCI_SDCBUS_8BIT             (  3 <<  6)     /* 8-bit data bus[2] */
+# define ATMCI_SDCBUS_MASK             (  3 <<  6)
+#define ATMCI_ARGR                     0x0010  /* Command Argument */
+#define ATMCI_CMDR                     0x0014  /* Command */
+# define ATMCI_CMDR_CMDNB(x)           ((x) <<  0)     /* Command Opcode */
+# define ATMCI_CMDR_RSPTYP_NONE                (  0 <<  6)     /* No response */
+# define ATMCI_CMDR_RSPTYP_48BIT       (  1 <<  6)     /* 48-bit response */
+# define ATMCI_CMDR_RSPTYP_136BIT      (  2 <<  6)     /* 136-bit response */
+# define ATMCI_CMDR_SPCMD_INIT         (  1 <<  8)     /* Initialization command */
+# define ATMCI_CMDR_SPCMD_SYNC         (  2 <<  8)     /* Synchronized command */
+# define ATMCI_CMDR_SPCMD_INT          (  4 <<  8)     /* Interrupt command */
+# define ATMCI_CMDR_SPCMD_INTRESP      (  5 <<  8)     /* Interrupt response */
+# define ATMCI_CMDR_OPDCMD             (  1 << 11)     /* Open Drain */
+# define ATMCI_CMDR_MAXLAT_5CYC                (  0 << 12)     /* Max latency 5 cycles */
+# define ATMCI_CMDR_MAXLAT_64CYC       (  1 << 12)     /* Max latency 64 cycles */
+# define ATMCI_CMDR_START_XFER         (  1 << 16)     /* Start data transfer */
+# define ATMCI_CMDR_STOP_XFER          (  2 << 16)     /* Stop data transfer */
+# define ATMCI_CMDR_TRDIR_WRITE                (  0 << 18)     /* Write data */
+# define ATMCI_CMDR_TRDIR_READ         (  1 << 18)     /* Read data */
+# define ATMCI_CMDR_BLOCK              (  0 << 19)     /* Single-block transfer */
+# define ATMCI_CMDR_MULTI_BLOCK                (  1 << 19)     /* Multi-block transfer */
+# define ATMCI_CMDR_STREAM             (  2 << 19)     /* MMC Stream transfer */
+# define ATMCI_CMDR_SDIO_BYTE          (  4 << 19)     /* SDIO Byte transfer */
+# define ATMCI_CMDR_SDIO_BLOCK         (  5 << 19)     /* SDIO Block transfer */
+# define ATMCI_CMDR_SDIO_SUSPEND       (  1 << 24)     /* SDIO Suspend Command */
+# define ATMCI_CMDR_SDIO_RESUME                (  2 << 24)     /* SDIO Resume Command */
+#define ATMCI_BLKR                     0x0018  /* Block */
+# define ATMCI_BCNT(x)                 ((x) <<  0)     /* Data Block Count */
+# define ATMCI_BLKLEN(x)               ((x) << 16)     /* Data Block Length */
+#define ATMCI_CSTOR                    0x001c  /* Completion Signal Timeout[2] */
+# define ATMCI_CSTOCYC(x)              ((x) <<  0)     /* CST cycles */
+# define ATMCI_CSTOMUL(x)              ((x) <<  4)     /* CST multiplier */
+#define ATMCI_RSPR                     0x0020  /* Response 0 */
+#define ATMCI_RSPR1                    0x0024  /* Response 1 */
+#define ATMCI_RSPR2                    0x0028  /* Response 2 */
+#define ATMCI_RSPR3                    0x002c  /* Response 3 */
+#define ATMCI_RDR                      0x0030  /* Receive Data */
+#define ATMCI_TDR                      0x0034  /* Transmit Data */
+#define ATMCI_SR                       0x0040  /* Status */
+#define ATMCI_IER                      0x0044  /* Interrupt Enable */
+#define ATMCI_IDR                      0x0048  /* Interrupt Disable */
+#define ATMCI_IMR                      0x004c  /* Interrupt Mask */
+# define ATMCI_CMDRDY                  (  1 <<   0)    /* Command Ready */
+# define ATMCI_RXRDY                   (  1 <<   1)    /* Receiver Ready */
+# define ATMCI_TXRDY                   (  1 <<   2)    /* Transmitter Ready */
+# define ATMCI_BLKE                    (  1 <<   3)    /* Data Block Ended */
+# define ATMCI_DTIP                    (  1 <<   4)    /* Data Transfer In Progress */
+# define ATMCI_NOTBUSY                 (  1 <<   5)    /* Data Not Busy */
+# define ATMCI_ENDRX                   (  1 <<   6)    /* End of RX Buffer */
+# define ATMCI_ENDTX                   (  1 <<   7)    /* End of TX Buffer */
+# define ATMCI_SDIOIRQA                        (  1 <<   8)    /* SDIO IRQ in slot A */
+# define ATMCI_SDIOIRQB                        (  1 <<   9)    /* SDIO IRQ in slot B */
+# define ATMCI_SDIOWAIT                        (  1 <<  12)    /* SDIO Read Wait Operation Status */
+# define ATMCI_CSRCV                   (  1 <<  13)    /* CE-ATA Completion Signal Received */
+# define ATMCI_RXBUFF                  (  1 <<  14)    /* RX Buffer Full */
+# define ATMCI_TXBUFE                  (  1 <<  15)    /* TX Buffer Empty */
+# define ATMCI_RINDE                   (  1 <<  16)    /* Response Index Error */
+# define ATMCI_RDIRE                   (  1 <<  17)    /* Response Direction Error */
+# define ATMCI_RCRCE                   (  1 <<  18)    /* Response CRC Error */
+# define ATMCI_RENDE                   (  1 <<  19)    /* Response End Bit Error */
+# define ATMCI_RTOE                    (  1 <<  20)    /* Response Time-Out Error */
+# define ATMCI_DCRCE                   (  1 <<  21)    /* Data CRC Error */
+# define ATMCI_DTOE                    (  1 <<  22)    /* Data Time-Out Error */
+# define ATMCI_CSTOE                   (  1 <<  23)    /* Completion Signal Time-out Error */
+# define ATMCI_BLKOVRE                 (  1 <<  24)    /* DMA Block Overrun Error */
+# define ATMCI_DMADONE                 (  1 <<  25)    /* DMA Transfer Done */
+# define ATMCI_FIFOEMPTY               (  1 <<  26)    /* FIFO Empty Flag */
+# define ATMCI_XFRDONE                 (  1 <<  27)    /* Transfer Done Flag */
+# define ATMCI_ACKRCV                  (  1 <<  28)    /* Boot Operation Acknowledge Received */
+# define ATMCI_ACKRCVE                 (  1 <<  29)    /* Boot Operation Acknowledge Error */
+# define ATMCI_OVRE                    (  1 <<  30)    /* RX Overrun Error */
+# define ATMCI_UNRE                    (  1 <<  31)    /* TX Underrun Error */
+#define ATMCI_DMA                      0x0050  /* DMA Configuration[2] */
+# define ATMCI_DMA_OFFSET(x)           ((x) <<  0)     /* DMA Write Buffer Offset */
+# define ATMCI_DMA_CHKSIZE(x)          ((x) <<  4)     /* DMA Channel Read and Write Chunk Size */
+# define ATMCI_DMAEN                   (  1 <<  8)     /* DMA Hardware Handshaking Enable */
+#define ATMCI_CFG                      0x0054  /* Configuration[2] */
+# define ATMCI_CFG_FIFOMODE_1DATA      (  1 <<  0)     /* MCI Internal FIFO control mode */
+# define ATMCI_CFG_FERRCTRL_COR                (  1 <<  4)     /* Flow Error flag reset control mode */
+# define ATMCI_CFG_HSMODE              (  1 <<  8)     /* High Speed Mode */
+# define ATMCI_CFG_LSYNC               (  1 << 12)     /* Synchronize on the last block */
+#define ATMCI_WPMR                     0x00e4  /* Write Protection Mode[2] */
+# define ATMCI_WP_EN                   (  1 <<  0)     /* WP Enable */
+# define ATMCI_WP_KEY                  (0x4d4349 << 8) /* WP Key */
+#define ATMCI_WPSR                     0x00e8  /* Write Protection Status[2] */
+# define ATMCI_GET_WP_VS(x)            ((x) & 0x0f)
+# define ATMCI_GET_WP_VSRC(x)          (((x) >> 8) & 0xffff)
+#define ATMCI_VERSION                  0x00FC  /* Version */
+#define ATMCI_FIFO_APERTURE            0x0200  /* FIFO Aperture[2] */
 
 /* This is not including the FIFO Aperture on MCI2 */
-#define MCI_REGS_SIZE          0x100
+#define ATMCI_REGS_SIZE                0x100
 
 /* Register access macros */
-#define mci_readl(port,reg)                            \
-       __raw_readl((port)->regs + MCI_##reg)
-#define mci_writel(port,reg,value)                     \
-       __raw_writel((value), (port)->regs + MCI_##reg)
+#define atmci_readl(port,reg)                          \
+       __raw_readl((port)->regs + reg)
+#define atmci_writel(port,reg,value)                   \
+       __raw_writel((value), (port)->regs + reg)
 
 #endif /* __DRIVERS_MMC_ATMEL_MCI_H__ */
index fa8cae1d7005c03524681564a38c1a7d5bb6a12b..a7ee5027146528aafc6b18fa8c2e55f32e32a174 100644 (file)
@@ -30,6 +30,7 @@
 
 #include <mach/atmel-mci.h>
 #include <linux/atmel-mci.h>
+#include <linux/atmel_pdc.h>
 
 #include <asm/io.h>
 #include <asm/unaligned.h>
@@ -39,7 +40,7 @@
 
 #include "atmel-mci-regs.h"
 
-#define ATMCI_DATA_ERROR_FLAGS (MCI_DCRCE | MCI_DTOE | MCI_OVRE | MCI_UNRE)
+#define ATMCI_DATA_ERROR_FLAGS (ATMCI_DCRCE | ATMCI_DTOE | ATMCI_OVRE | ATMCI_UNRE)
 #define ATMCI_DMA_THRESHOLD    16
 
 enum {
@@ -58,18 +59,35 @@ enum atmel_mci_state {
        STATE_DATA_ERROR,
 };
 
+enum atmci_xfer_dir {
+       XFER_RECEIVE = 0,
+       XFER_TRANSMIT,
+};
+
+enum atmci_pdc_buf {
+       PDC_FIRST_BUF = 0,
+       PDC_SECOND_BUF,
+};
+
+struct atmel_mci_caps {
+       bool    has_dma;
+       bool    has_pdc;
+       bool    has_cfg_reg;
+       bool    has_cstor_reg;
+       bool    has_highspeed;
+       bool    has_rwproof;
+};
+
 struct atmel_mci_dma {
-#ifdef CONFIG_MMC_ATMELMCI_DMA
        struct dma_chan                 *chan;
        struct dma_async_tx_descriptor  *data_desc;
-#endif
 };
 
 /**
  * struct atmel_mci - MMC controller state shared between all slots
  * @lock: Spinlock protecting the queue and associated data.
  * @regs: Pointer to MMIO registers.
- * @sg: Scatterlist entry currently being processed by PIO code, if any.
+ * @sg: Scatterlist entry currently being processed by PIO or PDC code.
  * @pio_offset: Offset into the current scatterlist entry.
  * @cur_slot: The slot which is currently using the controller.
  * @mrq: The request currently being processed on @cur_slot,
@@ -77,6 +95,7 @@ struct atmel_mci_dma {
  * @cmd: The command currently being sent to the card, or NULL.
  * @data: The data currently being transferred, or NULL if no data
  *     transfer is in progress.
+ * @data_size: just data->blocks * data->blksz.
  * @dma: DMA client state.
  * @data_chan: DMA channel being used for the current data transfer.
  * @cmd_status: Snapshot of SR taken upon completion of the current
@@ -103,6 +122,13 @@ struct atmel_mci_dma {
  * @mck: The peripheral bus clock hooked up to the MMC controller.
  * @pdev: Platform device associated with the MMC controller.
  * @slot: Slots sharing this MMC controller.
+ * @caps: MCI capabilities depending on MCI version.
+ * @prepare_data: function to setup MCI before data transfer which
+ * depends on MCI capabilities.
+ * @submit_data: function to start data transfer which depends on MCI
+ * capabilities.
+ * @stop_transfer: function to stop data transfer which depends on MCI
+ * capabilities.
  *
  * Locking
  * =======
@@ -143,6 +169,7 @@ struct atmel_mci {
        struct mmc_request      *mrq;
        struct mmc_command      *cmd;
        struct mmc_data         *data;
+       unsigned int            data_size;
 
        struct atmel_mci_dma    dma;
        struct dma_chan         *data_chan;
@@ -166,7 +193,13 @@ struct atmel_mci {
        struct clk              *mck;
        struct platform_device  *pdev;
 
-       struct atmel_mci_slot   *slot[ATMEL_MCI_MAX_NR_SLOTS];
+       struct atmel_mci_slot   *slot[ATMCI_MAX_NR_SLOTS];
+
+       struct atmel_mci_caps   caps;
+
+       u32 (*prepare_data)(struct atmel_mci *host, struct mmc_data *data);
+       void (*submit_data)(struct atmel_mci *host, struct mmc_data *data);
+       void (*stop_transfer)(struct atmel_mci *host);
 };
 
 /**
@@ -219,31 +252,6 @@ struct atmel_mci_slot {
 #define atmci_set_pending(host, event)                         \
        set_bit(event, &host->pending_events)
 
-/*
- * Enable or disable features/registers based on
- * whether the processor supports them
- */
-static bool mci_has_rwproof(void)
-{
-       if (cpu_is_at91sam9261() || cpu_is_at91rm9200())
-               return false;
-       else
-               return true;
-}
-
-/*
- * The new MCI2 module isn't 100% compatible with the old MCI module,
- * and it has a few nice features which we want to use...
- */
-static inline bool atmci_is_mci2(void)
-{
-       if (cpu_is_at91sam9g45())
-               return true;
-
-       return false;
-}
-
-
 /*
  * The debugfs stuff below is mostly optimized away when
  * CONFIG_DEBUG_FS is not set.
@@ -352,7 +360,7 @@ static int atmci_regs_show(struct seq_file *s, void *v)
        struct atmel_mci        *host = s->private;
        u32                     *buf;
 
-       buf = kmalloc(MCI_REGS_SIZE, GFP_KERNEL);
+       buf = kmalloc(ATMCI_REGS_SIZE, GFP_KERNEL);
        if (!buf)
                return -ENOMEM;
 
@@ -363,47 +371,50 @@ static int atmci_regs_show(struct seq_file *s, void *v)
         */
        spin_lock_bh(&host->lock);
        clk_enable(host->mck);
-       memcpy_fromio(buf, host->regs, MCI_REGS_SIZE);
+       memcpy_fromio(buf, host->regs, ATMCI_REGS_SIZE);
        clk_disable(host->mck);
        spin_unlock_bh(&host->lock);
 
        seq_printf(s, "MR:\t0x%08x%s%s CLKDIV=%u\n",
-                       buf[MCI_MR / 4],
-                       buf[MCI_MR / 4] & MCI_MR_RDPROOF ? " RDPROOF" : "",
-                       buf[MCI_MR / 4] & MCI_MR_WRPROOF ? " WRPROOF" : "",
-                       buf[MCI_MR / 4] & 0xff);
-       seq_printf(s, "DTOR:\t0x%08x\n", buf[MCI_DTOR / 4]);
-       seq_printf(s, "SDCR:\t0x%08x\n", buf[MCI_SDCR / 4]);
-       seq_printf(s, "ARGR:\t0x%08x\n", buf[MCI_ARGR / 4]);
+                       buf[ATMCI_MR / 4],
+                       buf[ATMCI_MR / 4] & ATMCI_MR_RDPROOF ? " RDPROOF" : "",
+                       buf[ATMCI_MR / 4] & ATMCI_MR_WRPROOF ? " WRPROOF" : "",
+                       buf[ATMCI_MR / 4] & 0xff);
+       seq_printf(s, "DTOR:\t0x%08x\n", buf[ATMCI_DTOR / 4]);
+       seq_printf(s, "SDCR:\t0x%08x\n", buf[ATMCI_SDCR / 4]);
+       seq_printf(s, "ARGR:\t0x%08x\n", buf[ATMCI_ARGR / 4]);
        seq_printf(s, "BLKR:\t0x%08x BCNT=%u BLKLEN=%u\n",
-                       buf[MCI_BLKR / 4],
-                       buf[MCI_BLKR / 4] & 0xffff,
-                       (buf[MCI_BLKR / 4] >> 16) & 0xffff);
-       if (atmci_is_mci2())
-               seq_printf(s, "CSTOR:\t0x%08x\n", buf[MCI_CSTOR / 4]);
+                       buf[ATMCI_BLKR / 4],
+                       buf[ATMCI_BLKR / 4] & 0xffff,
+                       (buf[ATMCI_BLKR / 4] >> 16) & 0xffff);
+       if (host->caps.has_cstor_reg)
+               seq_printf(s, "CSTOR:\t0x%08x\n", buf[ATMCI_CSTOR / 4]);
 
        /* Don't read RSPR and RDR; it will consume the data there */
 
-       atmci_show_status_reg(s, "SR", buf[MCI_SR / 4]);
-       atmci_show_status_reg(s, "IMR", buf[MCI_IMR / 4]);
+       atmci_show_status_reg(s, "SR", buf[ATMCI_SR / 4]);
+       atmci_show_status_reg(s, "IMR", buf[ATMCI_IMR / 4]);
 
-       if (atmci_is_mci2()) {
+       if (host->caps.has_dma) {
                u32 val;
 
-               val = buf[MCI_DMA / 4];
+               val = buf[ATMCI_DMA / 4];
                seq_printf(s, "DMA:\t0x%08x OFFSET=%u CHKSIZE=%u%s\n",
                                val, val & 3,
                                ((val >> 4) & 3) ?
                                        1 << (((val >> 4) & 3) + 1) : 1,
-                               val & MCI_DMAEN ? " DMAEN" : "");
+                               val & ATMCI_DMAEN ? " DMAEN" : "");
+       }
+       if (host->caps.has_cfg_reg) {
+               u32 val;
 
-               val = buf[MCI_CFG / 4];
+               val = buf[ATMCI_CFG / 4];
                seq_printf(s, "CFG:\t0x%08x%s%s%s%s\n",
                                val,
-                               val & MCI_CFG_FIFOMODE_1DATA ? " FIFOMODE_ONE_DATA" : "",
-                               val & MCI_CFG_FERRCTRL_COR ? " FERRCTRL_CLEAR_ON_READ" : "",
-                               val & MCI_CFG_HSMODE ? " HSMODE" : "",
-                               val & MCI_CFG_LSYNC ? " LSYNC" : "");
+                               val & ATMCI_CFG_FIFOMODE_1DATA ? " FIFOMODE_ONE_DATA" : "",
+                               val & ATMCI_CFG_FERRCTRL_COR ? " FERRCTRL_CLEAR_ON_READ" : "",
+                               val & ATMCI_CFG_HSMODE ? " HSMODE" : "",
+                               val & ATMCI_CFG_LSYNC ? " LSYNC" : "");
        }
 
        kfree(buf);
@@ -466,7 +477,7 @@ err:
        dev_err(&mmc->class_dev, "failed to initialize debugfs for slot\n");
 }
 
-static inline unsigned int ns_to_clocks(struct atmel_mci *host,
+static inline unsigned int atmci_ns_to_clocks(struct atmel_mci *host,
                                        unsigned int ns)
 {
        return (ns * (host->bus_hz / 1000000) + 999) / 1000;
@@ -482,7 +493,8 @@ static void atmci_set_timeout(struct atmel_mci *host,
        unsigned        dtocyc;
        unsigned        dtomul;
 
-       timeout = ns_to_clocks(host, data->timeout_ns) + data->timeout_clks;
+       timeout = atmci_ns_to_clocks(host, data->timeout_ns)
+               + data->timeout_clks;
 
        for (dtomul = 0; dtomul < 8; dtomul++) {
                unsigned shift = dtomul_to_shift[dtomul];
@@ -498,7 +510,7 @@ static void atmci_set_timeout(struct atmel_mci *host,
 
        dev_vdbg(&slot->mmc->class_dev, "setting timeout to %u cycles\n",
                        dtocyc << dtomul_to_shift[dtomul]);
-       mci_writel(host, DTOR, (MCI_DTOMUL(dtomul) | MCI_DTOCYC(dtocyc)));
+       atmci_writel(host, ATMCI_DTOR, (ATMCI_DTOMUL(dtomul) | ATMCI_DTOCYC(dtocyc)));
 }
 
 /*
@@ -512,13 +524,13 @@ static u32 atmci_prepare_command(struct mmc_host *mmc,
 
        cmd->error = -EINPROGRESS;
 
-       cmdr = MCI_CMDR_CMDNB(cmd->opcode);
+       cmdr = ATMCI_CMDR_CMDNB(cmd->opcode);
 
        if (cmd->flags & MMC_RSP_PRESENT) {
                if (cmd->flags & MMC_RSP_136)
-                       cmdr |= MCI_CMDR_RSPTYP_136BIT;
+                       cmdr |= ATMCI_CMDR_RSPTYP_136BIT;
                else
-                       cmdr |= MCI_CMDR_RSPTYP_48BIT;
+                       cmdr |= ATMCI_CMDR_RSPTYP_48BIT;
        }
 
        /*
@@ -526,34 +538,34 @@ static u32 atmci_prepare_command(struct mmc_host *mmc,
         * it's too difficult to determine whether this is an ACMD or
         * not. Better make it 64.
         */
-       cmdr |= MCI_CMDR_MAXLAT_64CYC;
+       cmdr |= ATMCI_CMDR_MAXLAT_64CYC;
 
        if (mmc->ios.bus_mode == MMC_BUSMODE_OPENDRAIN)
-               cmdr |= MCI_CMDR_OPDCMD;
+               cmdr |= ATMCI_CMDR_OPDCMD;
 
        data = cmd->data;
        if (data) {
-               cmdr |= MCI_CMDR_START_XFER;
+               cmdr |= ATMCI_CMDR_START_XFER;
 
                if (cmd->opcode == SD_IO_RW_EXTENDED) {
-                       cmdr |= MCI_CMDR_SDIO_BLOCK;
+                       cmdr |= ATMCI_CMDR_SDIO_BLOCK;
                } else {
                        if (data->flags & MMC_DATA_STREAM)
-                               cmdr |= MCI_CMDR_STREAM;
+                               cmdr |= ATMCI_CMDR_STREAM;
                        else if (data->blocks > 1)
-                               cmdr |= MCI_CMDR_MULTI_BLOCK;
+                               cmdr |= ATMCI_CMDR_MULTI_BLOCK;
                        else
-                               cmdr |= MCI_CMDR_BLOCK;
+                               cmdr |= ATMCI_CMDR_BLOCK;
                }
 
                if (data->flags & MMC_DATA_READ)
-                       cmdr |= MCI_CMDR_TRDIR_READ;
+                       cmdr |= ATMCI_CMDR_TRDIR_READ;
        }
 
        return cmdr;
 }
 
-static void atmci_start_command(struct atmel_mci *host,
+static void atmci_send_command(struct atmel_mci *host,
                struct mmc_command *cmd, u32 cmd_flags)
 {
        WARN_ON(host->cmd);
@@ -563,43 +575,119 @@ static void atmci_start_command(struct atmel_mci *host,
                        "start command: ARGR=0x%08x CMDR=0x%08x\n",
                        cmd->arg, cmd_flags);
 
-       mci_writel(host, ARGR, cmd->arg);
-       mci_writel(host, CMDR, cmd_flags);
+       atmci_writel(host, ATMCI_ARGR, cmd->arg);
+       atmci_writel(host, ATMCI_CMDR, cmd_flags);
 }
 
-static void send_stop_cmd(struct atmel_mci *host, struct mmc_data *data)
+static void atmci_send_stop_cmd(struct atmel_mci *host, struct mmc_data *data)
 {
-       atmci_start_command(host, data->stop, host->stop_cmdr);
-       mci_writel(host, IER, MCI_CMDRDY);
+       atmci_send_command(host, data->stop, host->stop_cmdr);
+       atmci_writel(host, ATMCI_IER, ATMCI_CMDRDY);
 }
 
-#ifdef CONFIG_MMC_ATMELMCI_DMA
-static void atmci_dma_cleanup(struct atmel_mci *host)
+/*
+ * Configure given PDC buffer taking care of alignement issues.
+ * Update host->data_size and host->sg.
+ */
+static void atmci_pdc_set_single_buf(struct atmel_mci *host,
+       enum atmci_xfer_dir dir, enum atmci_pdc_buf buf_nb)
+{
+       u32 pointer_reg, counter_reg;
+
+       if (dir == XFER_RECEIVE) {
+               pointer_reg = ATMEL_PDC_RPR;
+               counter_reg = ATMEL_PDC_RCR;
+       } else {
+               pointer_reg = ATMEL_PDC_TPR;
+               counter_reg = ATMEL_PDC_TCR;
+       }
+
+       if (buf_nb == PDC_SECOND_BUF) {
+               pointer_reg += ATMEL_PDC_SCND_BUF_OFF;
+               counter_reg += ATMEL_PDC_SCND_BUF_OFF;
+       }
+
+       atmci_writel(host, pointer_reg, sg_dma_address(host->sg));
+       if (host->data_size <= sg_dma_len(host->sg)) {
+               if (host->data_size & 0x3) {
+                       /* If size is different from modulo 4, transfer bytes */
+                       atmci_writel(host, counter_reg, host->data_size);
+                       atmci_writel(host, ATMCI_MR, host->mode_reg | ATMCI_MR_PDCFBYTE);
+               } else {
+                       /* Else transfer 32-bits words */
+                       atmci_writel(host, counter_reg, host->data_size / 4);
+               }
+               host->data_size = 0;
+       } else {
+               /* We assume the size of a page is 32-bits aligned */
+               atmci_writel(host, counter_reg, sg_dma_len(host->sg) / 4);
+               host->data_size -= sg_dma_len(host->sg);
+               if (host->data_size)
+                       host->sg = sg_next(host->sg);
+       }
+}
+
+/*
+ * Configure PDC buffer according to the data size ie configuring one or two
+ * buffers. Don't use this function if you want to configure only the second
+ * buffer. In this case, use atmci_pdc_set_single_buf.
+ */
+static void atmci_pdc_set_both_buf(struct atmel_mci *host, int dir)
 {
-       struct mmc_data                 *data = host->data;
+       atmci_pdc_set_single_buf(host, dir, PDC_FIRST_BUF);
+       if (host->data_size)
+               atmci_pdc_set_single_buf(host, dir, PDC_SECOND_BUF);
+}
+
+/*
+ * Unmap sg lists, called when transfer is finished.
+ */
+static void atmci_pdc_cleanup(struct atmel_mci *host)
+{
+       struct mmc_data         *data = host->data;
 
        if (data)
-               dma_unmap_sg(host->dma.chan->device->dev,
-                            data->sg, data->sg_len,
-                            ((data->flags & MMC_DATA_WRITE)
-                             ? DMA_TO_DEVICE : DMA_FROM_DEVICE));
+               dma_unmap_sg(&host->pdev->dev,
+                               data->sg, data->sg_len,
+                               ((data->flags & MMC_DATA_WRITE)
+                                ? DMA_TO_DEVICE : DMA_FROM_DEVICE));
 }
 
-static void atmci_stop_dma(struct atmel_mci *host)
+/*
+ * Disable PDC transfers. Update pending flags to EVENT_XFER_COMPLETE after
+ * having received ATMCI_TXBUFE or ATMCI_RXBUFF interrupt. Enable ATMCI_NOTBUSY
+ * interrupt needed for both transfer directions.
+ */
+static void atmci_pdc_complete(struct atmel_mci *host)
 {
-       struct dma_chan *chan = host->data_chan;
+       atmci_writel(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS);
+       atmci_pdc_cleanup(host);
 
-       if (chan) {
-               dmaengine_terminate_all(chan);
-               atmci_dma_cleanup(host);
-       } else {
-               /* Data transfer was stopped by the interrupt handler */
+       /*
+        * If the card was removed, data will be NULL. No point trying
+        * to send the stop command or waiting for NBUSY in this case.
+        */
+       if (host->data) {
                atmci_set_pending(host, EVENT_XFER_COMPLETE);
-               mci_writel(host, IER, MCI_NOTBUSY);
+               tasklet_schedule(&host->tasklet);
+               atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY);
        }
 }
 
-/* This function is called by the DMA driver from tasklet context. */
+static void atmci_dma_cleanup(struct atmel_mci *host)
+{
+       struct mmc_data                 *data = host->data;
+
+       if (data)
+               dma_unmap_sg(host->dma.chan->device->dev,
+                               data->sg, data->sg_len,
+                               ((data->flags & MMC_DATA_WRITE)
+                                ? DMA_TO_DEVICE : DMA_FROM_DEVICE));
+}
+
+/*
+ * This function is called by the DMA driver from tasklet context.
+ */
 static void atmci_dma_complete(void *arg)
 {
        struct atmel_mci        *host = arg;
@@ -607,9 +695,9 @@ static void atmci_dma_complete(void *arg)
 
        dev_vdbg(&host->pdev->dev, "DMA complete\n");
 
-       if (atmci_is_mci2())
+       if (host->caps.has_dma)
                /* Disable DMA hardware handshaking on MCI */
-               mci_writel(host, DMA, mci_readl(host, DMA) & ~MCI_DMAEN);
+               atmci_writel(host, ATMCI_DMA, atmci_readl(host, ATMCI_DMA) & ~ATMCI_DMAEN);
 
        atmci_dma_cleanup(host);
 
@@ -641,11 +729,93 @@ static void atmci_dma_complete(void *arg)
                 * completion callback" rule of the dma engine
                 * framework.
                 */
-               mci_writel(host, IER, MCI_NOTBUSY);
+               atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY);
        }
 }
 
-static int
+/*
+ * Returns a mask of interrupt flags to be enabled after the whole
+ * request has been prepared.
+ */
+static u32 atmci_prepare_data(struct atmel_mci *host, struct mmc_data *data)
+{
+       u32 iflags;
+
+       data->error = -EINPROGRESS;
+
+       host->sg = data->sg;
+       host->data = data;
+       host->data_chan = NULL;
+
+       iflags = ATMCI_DATA_ERROR_FLAGS;
+
+       /*
+        * Errata: MMC data write operation with less than 12
+        * bytes is impossible.
+        *
+        * Errata: MCI Transmit Data Register (TDR) FIFO
+        * corruption when length is not multiple of 4.
+        */
+       if (data->blocks * data->blksz < 12
+                       || (data->blocks * data->blksz) & 3)
+               host->need_reset = true;
+
+       host->pio_offset = 0;
+       if (data->flags & MMC_DATA_READ)
+               iflags |= ATMCI_RXRDY;
+       else
+               iflags |= ATMCI_TXRDY;
+
+       return iflags;
+}
+
+/*
+ * Set interrupt flags and set block length into the MCI mode register even
+ * if this value is also accessible in the MCI block register. It seems to be
+ * necessary before the High Speed MCI version. It also map sg and configure
+ * PDC registers.
+ */
+static u32
+atmci_prepare_data_pdc(struct atmel_mci *host, struct mmc_data *data)
+{
+       u32 iflags, tmp;
+       unsigned int sg_len;
+       enum dma_data_direction dir;
+
+       data->error = -EINPROGRESS;
+
+       host->data = data;
+       host->sg = data->sg;
+       iflags = ATMCI_DATA_ERROR_FLAGS;
+
+       /* Enable pdc mode */
+       atmci_writel(host, ATMCI_MR, host->mode_reg | ATMCI_MR_PDCMODE);
+
+       if (data->flags & MMC_DATA_READ) {
+               dir = DMA_FROM_DEVICE;
+               iflags |= ATMCI_ENDRX | ATMCI_RXBUFF;
+       } else {
+               dir = DMA_TO_DEVICE;
+               iflags |= ATMCI_ENDTX | ATMCI_TXBUFE;
+       }
+
+       /* Set BLKLEN */
+       tmp = atmci_readl(host, ATMCI_MR);
+       tmp &= 0x0000ffff;
+       tmp |= ATMCI_BLKLEN(data->blksz);
+       atmci_writel(host, ATMCI_MR, tmp);
+
+       /* Configure PDC */
+       host->data_size = data->blocks * data->blksz;
+       sg_len = dma_map_sg(&host->pdev->dev, data->sg, data->sg_len, dir);
+       if (host->data_size)
+               atmci_pdc_set_both_buf(host,
+                       ((dir == DMA_FROM_DEVICE) ? XFER_RECEIVE : XFER_TRANSMIT));
+
+       return iflags;
+}
+
+static u32
 atmci_prepare_data_dma(struct atmel_mci *host, struct mmc_data *data)
 {
        struct dma_chan                 *chan;
@@ -654,6 +824,15 @@ atmci_prepare_data_dma(struct atmel_mci *host, struct mmc_data *data)
        unsigned int                    i;
        enum dma_data_direction         direction;
        unsigned int                    sglen;
+       u32 iflags;
+
+       data->error = -EINPROGRESS;
+
+       WARN_ON(host->data);
+       host->sg = NULL;
+       host->data = data;
+
+       iflags = ATMCI_DATA_ERROR_FLAGS;
 
        /*
         * We don't do DMA on "complex" transfers, i.e. with
@@ -661,13 +840,13 @@ atmci_prepare_data_dma(struct atmel_mci *host, struct mmc_data *data)
         * with all the DMA setup overhead for short transfers.
         */
        if (data->blocks * data->blksz < ATMCI_DMA_THRESHOLD)
-               return -EINVAL;
+               return atmci_prepare_data(host, data);
        if (data->blksz & 3)
-               return -EINVAL;
+               return atmci_prepare_data(host, data);
 
        for_each_sg(data->sg, sg, data->sg_len, i) {
                if (sg->offset & 3 || sg->length & 3)
-                       return -EINVAL;
+                       return atmci_prepare_data(host, data);
        }
 
        /* If we don't have a channel, we can't do DMA */
@@ -678,8 +857,8 @@ atmci_prepare_data_dma(struct atmel_mci *host, struct mmc_data *data)
        if (!chan)
                return -ENODEV;
 
-       if (atmci_is_mci2())
-               mci_writel(host, DMA, MCI_DMA_CHKSIZE(3) | MCI_DMAEN);
+       if (host->caps.has_dma)
+               atmci_writel(host, ATMCI_DMA, ATMCI_DMA_CHKSIZE(3) | ATMCI_DMAEN);
 
        if (data->flags & MMC_DATA_READ)
                direction = DMA_FROM_DEVICE;
@@ -687,7 +866,7 @@ atmci_prepare_data_dma(struct atmel_mci *host, struct mmc_data *data)
                direction = DMA_TO_DEVICE;
 
        sglen = dma_map_sg(chan->device->dev, data->sg,
-                          data->sg_len, direction);
+                       data->sg_len, direction);
 
        desc = chan->device->device_prep_slave_sg(chan,
                        data->sg, sglen, direction,
@@ -699,13 +878,32 @@ atmci_prepare_data_dma(struct atmel_mci *host, struct mmc_data *data)
        desc->callback = atmci_dma_complete;
        desc->callback_param = host;
 
-       return 0;
+       return iflags;
 unmap_exit:
        dma_unmap_sg(chan->device->dev, data->sg, data->sg_len, direction);
        return -ENOMEM;
 }
 
-static void atmci_submit_data(struct atmel_mci *host)
+static void
+atmci_submit_data(struct atmel_mci *host, struct mmc_data *data)
+{
+       return;
+}
+
+/*
+ * Start PDC according to transfer direction.
+ */
+static void
+atmci_submit_data_pdc(struct atmel_mci *host, struct mmc_data *data)
+{
+       if (data->flags & MMC_DATA_READ)
+               atmci_writel(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTEN);
+       else
+               atmci_writel(host, ATMEL_PDC_PTCR, ATMEL_PDC_TXTEN);
+}
+
+static void
+atmci_submit_data_dma(struct atmel_mci *host, struct mmc_data *data)
 {
        struct dma_chan                 *chan = host->data_chan;
        struct dma_async_tx_descriptor  *desc = host->dma.data_desc;
@@ -716,64 +914,39 @@ static void atmci_submit_data(struct atmel_mci *host)
        }
 }
 
-#else /* CONFIG_MMC_ATMELMCI_DMA */
-
-static int atmci_prepare_data_dma(struct atmel_mci *host, struct mmc_data *data)
-{
-       return -ENOSYS;
-}
-
-static void atmci_submit_data(struct atmel_mci *host) {}
-
-static void atmci_stop_dma(struct atmel_mci *host)
+static void atmci_stop_transfer(struct atmel_mci *host)
 {
-       /* Data transfer was stopped by the interrupt handler */
        atmci_set_pending(host, EVENT_XFER_COMPLETE);
-       mci_writel(host, IER, MCI_NOTBUSY);
+       atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY);
 }
 
-#endif /* CONFIG_MMC_ATMELMCI_DMA */
-
 /*
- * Returns a mask of interrupt flags to be enabled after the whole
- * request has been prepared.
+ * Stop data transfer because error(s) occured.
  */
-static u32 atmci_prepare_data(struct atmel_mci *host, struct mmc_data *data)
+static void atmci_stop_transfer_pdc(struct atmel_mci *host)
 {
-       u32 iflags;
-
-       data->error = -EINPROGRESS;
-
-       WARN_ON(host->data);
-       host->sg = NULL;
-       host->data = data;
-
-       iflags = ATMCI_DATA_ERROR_FLAGS;
-       if (atmci_prepare_data_dma(host, data)) {
-               host->data_chan = NULL;
+       atmci_set_pending(host, EVENT_XFER_COMPLETE);
+       atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY);
+}
 
-               /*
-                * Errata: MMC data write operation with less than 12
-                * bytes is impossible.
-                *
-                * Errata: MCI Transmit Data Register (TDR) FIFO
-                * corruption when length is not multiple of 4.
-                */
-               if (data->blocks * data->blksz < 12
-                               || (data->blocks * data->blksz) & 3)
-                       host->need_reset = true;
+static void atmci_stop_transfer_dma(struct atmel_mci *host)
+{
+       struct dma_chan *chan = host->data_chan;
 
-               host->sg = data->sg;
-               host->pio_offset = 0;
-               if (data->flags & MMC_DATA_READ)
-                       iflags |= MCI_RXRDY;
-               else
-                       iflags |= MCI_TXRDY;
+       if (chan) {
+               dmaengine_terminate_all(chan);
+               atmci_dma_cleanup(host);
+       } else {
+               /* Data transfer was stopped by the interrupt handler */
+               atmci_set_pending(host, EVENT_XFER_COMPLETE);
+               atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY);
        }
-
-       return iflags;
 }
 
+/*
+ * Start a request: prepare data if needed, prepare the command and activate
+ * interrupts.
+ */
 static void atmci_start_request(struct atmel_mci *host,
                struct atmel_mci_slot *slot)
 {
@@ -792,24 +965,24 @@ static void atmci_start_request(struct atmel_mci *host,
        host->data_status = 0;
 
        if (host->need_reset) {
-               mci_writel(host, CR, MCI_CR_SWRST);
-               mci_writel(host, CR, MCI_CR_MCIEN);
-               mci_writel(host, MR, host->mode_reg);
-               if (atmci_is_mci2())
-                       mci_writel(host, CFG, host->cfg_reg);
+               atmci_writel(host, ATMCI_CR, ATMCI_CR_SWRST);
+               atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIEN);
+               atmci_writel(host, ATMCI_MR, host->mode_reg);
+               if (host->caps.has_cfg_reg)
+                       atmci_writel(host, ATMCI_CFG, host->cfg_reg);
                host->need_reset = false;
        }
-       mci_writel(host, SDCR, slot->sdc_reg);
+       atmci_writel(host, ATMCI_SDCR, slot->sdc_reg);
 
-       iflags = mci_readl(host, IMR);
-       if (iflags & ~(MCI_SDIOIRQA | MCI_SDIOIRQB))
+       iflags = atmci_readl(host, ATMCI_IMR);
+       if (iflags & ~(ATMCI_SDIOIRQA | ATMCI_SDIOIRQB))
                dev_warn(&slot->mmc->class_dev, "WARNING: IMR=0x%08x\n",
                                iflags);
 
        if (unlikely(test_and_clear_bit(ATMCI_CARD_NEED_INIT, &slot->flags))) {
                /* Send init sequence (74 clock cycles) */
-               mci_writel(host, CMDR, MCI_CMDR_SPCMD_INIT);
-               while (!(mci_readl(host, SR) & MCI_CMDRDY))
+               atmci_writel(host, ATMCI_CMDR, ATMCI_CMDR_SPCMD_INIT);
+               while (!(atmci_readl(host, ATMCI_SR) & ATMCI_CMDRDY))
                        cpu_relax();
        }
        iflags = 0;
@@ -818,31 +991,31 @@ static void atmci_start_request(struct atmel_mci *host,
                atmci_set_timeout(host, slot, data);
 
                /* Must set block count/size before sending command */
-               mci_writel(host, BLKR, MCI_BCNT(data->blocks)
-                               | MCI_BLKLEN(data->blksz));
+               atmci_writel(host, ATMCI_BLKR, ATMCI_BCNT(data->blocks)
+                               | ATMCI_BLKLEN(data->blksz));
                dev_vdbg(&slot->mmc->class_dev, "BLKR=0x%08x\n",
-                       MCI_BCNT(data->blocks) | MCI_BLKLEN(data->blksz));
+                       ATMCI_BCNT(data->blocks) | ATMCI_BLKLEN(data->blksz));
 
-               iflags |= atmci_prepare_data(host, data);
+               iflags |= host->prepare_data(host, data);
        }
 
-       iflags |= MCI_CMDRDY;
+       iflags |= ATMCI_CMDRDY;
        cmd = mrq->cmd;
        cmdflags = atmci_prepare_command(slot->mmc, cmd);
-       atmci_start_command(host, cmd, cmdflags);
+       atmci_send_command(host, cmd, cmdflags);
 
        if (data)
-               atmci_submit_data(host);
+               host->submit_data(host, data);
 
        if (mrq->stop) {
                host->stop_cmdr = atmci_prepare_command(slot->mmc, mrq->stop);
-               host->stop_cmdr |= MCI_CMDR_STOP_XFER;
+               host->stop_cmdr |= ATMCI_CMDR_STOP_XFER;
                if (!(data->flags & MMC_DATA_WRITE))
-                       host->stop_cmdr |= MCI_CMDR_TRDIR_READ;
+                       host->stop_cmdr |= ATMCI_CMDR_TRDIR_READ;
                if (data->flags & MMC_DATA_STREAM)
-                       host->stop_cmdr |= MCI_CMDR_STREAM;
+                       host->stop_cmdr |= ATMCI_CMDR_STREAM;
                else
-                       host->stop_cmdr |= MCI_CMDR_MULTI_BLOCK;
+                       host->stop_cmdr |= ATMCI_CMDR_MULTI_BLOCK;
        }
 
        /*
@@ -851,7 +1024,7 @@ static void atmci_start_request(struct atmel_mci *host,
         * conditions (e.g. command and data complete, but stop not
         * prepared yet.)
         */
-       mci_writel(host, IER, iflags);
+       atmci_writel(host, ATMCI_IER, iflags);
 }
 
 static void atmci_queue_request(struct atmel_mci *host,
@@ -909,13 +1082,13 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
        struct atmel_mci        *host = slot->host;
        unsigned int            i;
 
-       slot->sdc_reg &= ~MCI_SDCBUS_MASK;
+       slot->sdc_reg &= ~ATMCI_SDCBUS_MASK;
        switch (ios->bus_width) {
        case MMC_BUS_WIDTH_1:
-               slot->sdc_reg |= MCI_SDCBUS_1BIT;
+               slot->sdc_reg |= ATMCI_SDCBUS_1BIT;
                break;
        case MMC_BUS_WIDTH_4:
-               slot->sdc_reg |= MCI_SDCBUS_4BIT;
+               slot->sdc_reg |= ATMCI_SDCBUS_4BIT;
                break;
        }
 
@@ -926,10 +1099,10 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
                spin_lock_bh(&host->lock);
                if (!host->mode_reg) {
                        clk_enable(host->mck);
-                       mci_writel(host, CR, MCI_CR_SWRST);
-                       mci_writel(host, CR, MCI_CR_MCIEN);
-                       if (atmci_is_mci2())
-                               mci_writel(host, CFG, host->cfg_reg);
+                       atmci_writel(host, ATMCI_CR, ATMCI_CR_SWRST);
+                       atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIEN);
+                       if (host->caps.has_cfg_reg)
+                               atmci_writel(host, ATMCI_CFG, host->cfg_reg);
                }
 
                /*
@@ -937,7 +1110,7 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
                 * core ios update when finding the minimum.
                 */
                slot->clock = ios->clock;
-               for (i = 0; i < ATMEL_MCI_MAX_NR_SLOTS; i++) {
+               for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
                        if (host->slot[i] && host->slot[i]->clock
                                        && host->slot[i]->clock < clock_min)
                                clock_min = host->slot[i]->clock;
@@ -952,28 +1125,28 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
                        clkdiv = 255;
                }
 
-               host->mode_reg = MCI_MR_CLKDIV(clkdiv);
+               host->mode_reg = ATMCI_MR_CLKDIV(clkdiv);
 
                /*
                 * WRPROOF and RDPROOF prevent overruns/underruns by
                 * stopping the clock when the FIFO is full/empty.
                 * This state is not expected to last for long.
                 */
-               if (mci_has_rwproof())
-                       host->mode_reg |= (MCI_MR_WRPROOF | MCI_MR_RDPROOF);
+               if (host->caps.has_rwproof)
+                       host->mode_reg |= (ATMCI_MR_WRPROOF | ATMCI_MR_RDPROOF);
 
-               if (atmci_is_mci2()) {
+               if (host->caps.has_cfg_reg) {
                        /* setup High Speed mode in relation with card capacity */
                        if (ios->timing == MMC_TIMING_SD_HS)
-                               host->cfg_reg |= MCI_CFG_HSMODE;
+                               host->cfg_reg |= ATMCI_CFG_HSMODE;
                        else
-                               host->cfg_reg &= ~MCI_CFG_HSMODE;
+                               host->cfg_reg &= ~ATMCI_CFG_HSMODE;
                }
 
                if (list_empty(&host->queue)) {
-                       mci_writel(host, MR, host->mode_reg);
-                       if (atmci_is_mci2())
-                               mci_writel(host, CFG, host->cfg_reg);
+                       atmci_writel(host, ATMCI_MR, host->mode_reg);
+                       if (host->caps.has_cfg_reg)
+                               atmci_writel(host, ATMCI_CFG, host->cfg_reg);
                } else {
                        host->need_clock_update = true;
                }
@@ -984,16 +1157,16 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
 
                spin_lock_bh(&host->lock);
                slot->clock = 0;
-               for (i = 0; i < ATMEL_MCI_MAX_NR_SLOTS; i++) {
+               for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
                        if (host->slot[i] && host->slot[i]->clock) {
                                any_slot_active = true;
                                break;
                        }
                }
                if (!any_slot_active) {
-                       mci_writel(host, CR, MCI_CR_MCIDIS);
+                       atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIDIS);
                        if (host->mode_reg) {
-                               mci_readl(host, MR);
+                               atmci_readl(host, ATMCI_MR);
                                clk_disable(host->mck);
                        }
                        host->mode_reg = 0;
@@ -1057,9 +1230,9 @@ static void atmci_enable_sdio_irq(struct mmc_host *mmc, int enable)
        struct atmel_mci        *host = slot->host;
 
        if (enable)
-               mci_writel(host, IER, slot->sdio_irq);
+               atmci_writel(host, ATMCI_IER, slot->sdio_irq);
        else
-               mci_writel(host, IDR, slot->sdio_irq);
+               atmci_writel(host, ATMCI_IDR, slot->sdio_irq);
 }
 
 static const struct mmc_host_ops atmci_ops = {
@@ -1086,9 +1259,9 @@ static void atmci_request_end(struct atmel_mci *host, struct mmc_request *mrq)
         * busy transferring data.
         */
        if (host->need_clock_update) {
-               mci_writel(host, MR, host->mode_reg);
-               if (atmci_is_mci2())
-                       mci_writel(host, CFG, host->cfg_reg);
+               atmci_writel(host, ATMCI_MR, host->mode_reg);
+               if (host->caps.has_cfg_reg)
+                       atmci_writel(host, ATMCI_CFG, host->cfg_reg);
        }
 
        host->cur_slot->mrq = NULL;
@@ -1117,16 +1290,16 @@ static void atmci_command_complete(struct atmel_mci *host,
        u32             status = host->cmd_status;
 
        /* Read the response from the card (up to 16 bytes) */
-       cmd->resp[0] = mci_readl(host, RSPR);
-       cmd->resp[1] = mci_readl(host, RSPR);
-       cmd->resp[2] = mci_readl(host, RSPR);
-       cmd->resp[3] = mci_readl(host, RSPR);
+       cmd->resp[0] = atmci_readl(host, ATMCI_RSPR);
+       cmd->resp[1] = atmci_readl(host, ATMCI_RSPR);
+       cmd->resp[2] = atmci_readl(host, ATMCI_RSPR);
+       cmd->resp[3] = atmci_readl(host, ATMCI_RSPR);
 
-       if (status & MCI_RTOE)
+       if (status & ATMCI_RTOE)
                cmd->error = -ETIMEDOUT;
-       else if ((cmd->flags & MMC_RSP_CRC) && (status & MCI_RCRCE))
+       else if ((cmd->flags & MMC_RSP_CRC) && (status & ATMCI_RCRCE))
                cmd->error = -EILSEQ;
-       else if (status & (MCI_RINDE | MCI_RDIRE | MCI_RENDE))
+       else if (status & (ATMCI_RINDE | ATMCI_RDIRE | ATMCI_RENDE))
                cmd->error = -EIO;
        else
                cmd->error = 0;
@@ -1136,10 +1309,10 @@ static void atmci_command_complete(struct atmel_mci *host,
                        "command error: status=0x%08x\n", status);
 
                if (cmd->data) {
-                       atmci_stop_dma(host);
+                       host->stop_transfer(host);
                        host->data = NULL;
-                       mci_writel(host, IDR, MCI_NOTBUSY
-                                       | MCI_TXRDY | MCI_RXRDY
+                       atmci_writel(host, ATMCI_IDR, ATMCI_NOTBUSY
+                                       | ATMCI_TXRDY | ATMCI_RXRDY
                                        | ATMCI_DATA_ERROR_FLAGS);
                }
        }
@@ -1191,11 +1364,11 @@ static void atmci_detect_change(unsigned long data)
                                 * Reset controller to terminate any ongoing
                                 * commands or data transfers.
                                 */
-                               mci_writel(host, CR, MCI_CR_SWRST);
-                               mci_writel(host, CR, MCI_CR_MCIEN);
-                               mci_writel(host, MR, host->mode_reg);
-                               if (atmci_is_mci2())
-                                       mci_writel(host, CFG, host->cfg_reg);
+                               atmci_writel(host, ATMCI_CR, ATMCI_CR_SWRST);
+                               atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIEN);
+                               atmci_writel(host, ATMCI_MR, host->mode_reg);
+                               if (host->caps.has_cfg_reg)
+                                       atmci_writel(host, ATMCI_CFG, host->cfg_reg);
 
                                host->data = NULL;
                                host->cmd = NULL;
@@ -1210,7 +1383,7 @@ static void atmci_detect_change(unsigned long data)
                                        /* fall through */
                                case STATE_SENDING_DATA:
                                        mrq->data->error = -ENOMEDIUM;
-                                       atmci_stop_dma(host);
+                                       host->stop_transfer(host);
                                        break;
                                case STATE_DATA_BUSY:
                                case STATE_DATA_ERROR:
@@ -1261,7 +1434,7 @@ static void atmci_tasklet_func(unsigned long priv)
        dev_vdbg(&host->pdev->dev,
                "tasklet: state %u pending/completed/mask %lx/%lx/%x\n",
                state, host->pending_events, host->completed_events,
-               mci_readl(host, IMR));
+               atmci_readl(host, ATMCI_IMR));
 
        do {
                prev_state = state;
@@ -1289,9 +1462,9 @@ static void atmci_tasklet_func(unsigned long priv)
                case STATE_SENDING_DATA:
                        if (atmci_test_and_clear_pending(host,
                                                EVENT_DATA_ERROR)) {
-                               atmci_stop_dma(host);
+                               host->stop_transfer(host);
                                if (data->stop)
-                                       send_stop_cmd(host, data);
+                                       atmci_send_stop_cmd(host, data);
                                state = STATE_DATA_ERROR;
                                break;
                        }
@@ -1313,11 +1486,11 @@ static void atmci_tasklet_func(unsigned long priv)
                        atmci_set_completed(host, EVENT_DATA_COMPLETE);
                        status = host->data_status;
                        if (unlikely(status & ATMCI_DATA_ERROR_FLAGS)) {
-                               if (status & MCI_DTOE) {
+                               if (status & ATMCI_DTOE) {
                                        dev_dbg(&host->pdev->dev,
                                                        "data timeout error\n");
                                        data->error = -ETIMEDOUT;
-                               } else if (status & MCI_DCRCE) {
+                               } else if (status & ATMCI_DCRCE) {
                                        dev_dbg(&host->pdev->dev,
                                                        "data CRC error\n");
                                        data->error = -EILSEQ;
@@ -1330,7 +1503,7 @@ static void atmci_tasklet_func(unsigned long priv)
                        } else {
                                data->bytes_xfered = data->blocks * data->blksz;
                                data->error = 0;
-                               mci_writel(host, IDR, ATMCI_DATA_ERROR_FLAGS);
+                               atmci_writel(host, ATMCI_IDR, ATMCI_DATA_ERROR_FLAGS);
                        }
 
                        if (!data->stop) {
@@ -1340,7 +1513,7 @@ static void atmci_tasklet_func(unsigned long priv)
 
                        prev_state = state = STATE_SENDING_STOP;
                        if (!data->error)
-                               send_stop_cmd(host, data);
+                               atmci_send_stop_cmd(host, data);
                        /* fall through */
 
                case STATE_SENDING_STOP:
@@ -1380,7 +1553,7 @@ static void atmci_read_data_pio(struct atmel_mci *host)
        unsigned int            nbytes = 0;
 
        do {
-               value = mci_readl(host, RDR);
+               value = atmci_readl(host, ATMCI_RDR);
                if (likely(offset + 4 <= sg->length)) {
                        put_unaligned(value, (u32 *)(buf + offset));
 
@@ -1412,9 +1585,9 @@ static void atmci_read_data_pio(struct atmel_mci *host)
                        nbytes += offset;
                }
 
-               status = mci_readl(host, SR);
+               status = atmci_readl(host, ATMCI_SR);
                if (status & ATMCI_DATA_ERROR_FLAGS) {
-                       mci_writel(host, IDR, (MCI_NOTBUSY | MCI_RXRDY
+                       atmci_writel(host, ATMCI_IDR, (ATMCI_NOTBUSY | ATMCI_RXRDY
                                                | ATMCI_DATA_ERROR_FLAGS));
                        host->data_status = status;
                        data->bytes_xfered += nbytes;
@@ -1423,7 +1596,7 @@ static void atmci_read_data_pio(struct atmel_mci *host)
                        tasklet_schedule(&host->tasklet);
                        return;
                }
-       } while (status & MCI_RXRDY);
+       } while (status & ATMCI_RXRDY);
 
        host->pio_offset = offset;
        data->bytes_xfered += nbytes;
@@ -1431,8 +1604,8 @@ static void atmci_read_data_pio(struct atmel_mci *host)
        return;
 
 done:
-       mci_writel(host, IDR, MCI_RXRDY);
-       mci_writel(host, IER, MCI_NOTBUSY);
+       atmci_writel(host, ATMCI_IDR, ATMCI_RXRDY);
+       atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY);
        data->bytes_xfered += nbytes;
        smp_wmb();
        atmci_set_pending(host, EVENT_XFER_COMPLETE);
@@ -1451,7 +1624,7 @@ static void atmci_write_data_pio(struct atmel_mci *host)
        do {
                if (likely(offset + 4 <= sg->length)) {
                        value = get_unaligned((u32 *)(buf + offset));
-                       mci_writel(host, TDR, value);
+                       atmci_writel(host, ATMCI_TDR, value);
 
                        offset += 4;
                        nbytes += 4;
@@ -1472,20 +1645,20 @@ static void atmci_write_data_pio(struct atmel_mci *host)
 
                        host->sg = sg = sg_next(sg);
                        if (!sg) {
-                               mci_writel(host, TDR, value);
+                               atmci_writel(host, ATMCI_TDR, value);
                                goto done;
                        }
 
                        offset = 4 - remaining;
                        buf = sg_virt(sg);
                        memcpy((u8 *)&value + remaining, buf, offset);
-                       mci_writel(host, TDR, value);
+                       atmci_writel(host, ATMCI_TDR, value);
                        nbytes += offset;
                }
 
-               status = mci_readl(host, SR);
+               status = atmci_readl(host, ATMCI_SR);
                if (status & ATMCI_DATA_ERROR_FLAGS) {
-                       mci_writel(host, IDR, (MCI_NOTBUSY | MCI_TXRDY
+                       atmci_writel(host, ATMCI_IDR, (ATMCI_NOTBUSY | ATMCI_TXRDY
                                                | ATMCI_DATA_ERROR_FLAGS));
                        host->data_status = status;
                        data->bytes_xfered += nbytes;
@@ -1494,7 +1667,7 @@ static void atmci_write_data_pio(struct atmel_mci *host)
                        tasklet_schedule(&host->tasklet);
                        return;
                }
-       } while (status & MCI_TXRDY);
+       } while (status & ATMCI_TXRDY);
 
        host->pio_offset = offset;
        data->bytes_xfered += nbytes;
@@ -1502,8 +1675,8 @@ static void atmci_write_data_pio(struct atmel_mci *host)
        return;
 
 done:
-       mci_writel(host, IDR, MCI_TXRDY);
-       mci_writel(host, IER, MCI_NOTBUSY);
+       atmci_writel(host, ATMCI_IDR, ATMCI_TXRDY);
+       atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY);
        data->bytes_xfered += nbytes;
        smp_wmb();
        atmci_set_pending(host, EVENT_XFER_COMPLETE);
@@ -1511,7 +1684,7 @@ done:
 
 static void atmci_cmd_interrupt(struct atmel_mci *host, u32 status)
 {
-       mci_writel(host, IDR, MCI_CMDRDY);
+       atmci_writel(host, ATMCI_IDR, ATMCI_CMDRDY);
 
        host->cmd_status = status;
        smp_wmb();
@@ -1523,7 +1696,7 @@ static void atmci_sdio_interrupt(struct atmel_mci *host, u32 status)
 {
        int     i;
 
-       for (i = 0; i < ATMEL_MCI_MAX_NR_SLOTS; i++) {
+       for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
                struct atmel_mci_slot *slot = host->slot[i];
                if (slot && (status & slot->sdio_irq)) {
                        mmc_signal_sdio_irq(slot->mmc);
@@ -1539,40 +1712,92 @@ static irqreturn_t atmci_interrupt(int irq, void *dev_id)
        unsigned int            pass_count = 0;
 
        do {
-               status = mci_readl(host, SR);
-               mask = mci_readl(host, IMR);
+               status = atmci_readl(host, ATMCI_SR);
+               mask = atmci_readl(host, ATMCI_IMR);
                pending = status & mask;
                if (!pending)
                        break;
 
                if (pending & ATMCI_DATA_ERROR_FLAGS) {
-                       mci_writel(host, IDR, ATMCI_DATA_ERROR_FLAGS
-                                       | MCI_RXRDY | MCI_TXRDY);
-                       pending &= mci_readl(host, IMR);
+                       atmci_writel(host, ATMCI_IDR, ATMCI_DATA_ERROR_FLAGS
+                                       | ATMCI_RXRDY | ATMCI_TXRDY);
+                       pending &= atmci_readl(host, ATMCI_IMR);
 
                        host->data_status = status;
                        smp_wmb();
                        atmci_set_pending(host, EVENT_DATA_ERROR);
                        tasklet_schedule(&host->tasklet);
                }
-               if (pending & MCI_NOTBUSY) {
-                       mci_writel(host, IDR,
-                                       ATMCI_DATA_ERROR_FLAGS | MCI_NOTBUSY);
+
+               if (pending & ATMCI_TXBUFE) {
+                       atmci_writel(host, ATMCI_IDR, ATMCI_TXBUFE);
+                       atmci_writel(host, ATMCI_IDR, ATMCI_ENDTX);
+                       /*
+                        * We can receive this interruption before having configured
+                        * the second pdc buffer, so we need to reconfigure first and
+                        * second buffers again
+                        */
+                       if (host->data_size) {
+                               atmci_pdc_set_both_buf(host, XFER_TRANSMIT);
+                               atmci_writel(host, ATMCI_IER, ATMCI_ENDTX);
+                               atmci_writel(host, ATMCI_IER, ATMCI_TXBUFE);
+                       } else {
+                               atmci_pdc_complete(host);
+                       }
+               } else if (pending & ATMCI_ENDTX) {
+                       atmci_writel(host, ATMCI_IDR, ATMCI_ENDTX);
+
+                       if (host->data_size) {
+                               atmci_pdc_set_single_buf(host,
+                                               XFER_TRANSMIT, PDC_SECOND_BUF);
+                               atmci_writel(host, ATMCI_IER, ATMCI_ENDTX);
+                       }
+               }
+
+               if (pending & ATMCI_RXBUFF) {
+                       atmci_writel(host, ATMCI_IDR, ATMCI_RXBUFF);
+                       atmci_writel(host, ATMCI_IDR, ATMCI_ENDRX);
+                       /*
+                        * We can receive this interruption before having configured
+                        * the second pdc buffer, so we need to reconfigure first and
+                        * second buffers again
+                        */
+                       if (host->data_size) {
+                               atmci_pdc_set_both_buf(host, XFER_RECEIVE);
+                               atmci_writel(host, ATMCI_IER, ATMCI_ENDRX);
+                               atmci_writel(host, ATMCI_IER, ATMCI_RXBUFF);
+                       } else {
+                               atmci_pdc_complete(host);
+                       }
+               } else if (pending & ATMCI_ENDRX) {
+                       atmci_writel(host, ATMCI_IDR, ATMCI_ENDRX);
+
+                       if (host->data_size) {
+                               atmci_pdc_set_single_buf(host,
+                                               XFER_RECEIVE, PDC_SECOND_BUF);
+                               atmci_writel(host, ATMCI_IER, ATMCI_ENDRX);
+                       }
+               }
+
+
+               if (pending & ATMCI_NOTBUSY) {
+                       atmci_writel(host, ATMCI_IDR,
+                                       ATMCI_DATA_ERROR_FLAGS | ATMCI_NOTBUSY);
                        if (!host->data_status)
                                host->data_status = status;
                        smp_wmb();
                        atmci_set_pending(host, EVENT_DATA_COMPLETE);
                        tasklet_schedule(&host->tasklet);
                }
-               if (pending & MCI_RXRDY)
+               if (pending & ATMCI_RXRDY)
                        atmci_read_data_pio(host);
-               if (pending & MCI_TXRDY)
+               if (pending & ATMCI_TXRDY)
                        atmci_write_data_pio(host);
 
-               if (pending & MCI_CMDRDY)
+               if (pending & ATMCI_CMDRDY)
                        atmci_cmd_interrupt(host, status);
 
-               if (pending & (MCI_SDIOIRQA | MCI_SDIOIRQB))
+               if (pending & (ATMCI_SDIOIRQA | ATMCI_SDIOIRQB))
                        atmci_sdio_interrupt(host, status);
 
        } while (pass_count++ < 5);
@@ -1621,7 +1846,7 @@ static int __init atmci_init_slot(struct atmel_mci *host,
        mmc->ocr_avail  = MMC_VDD_32_33 | MMC_VDD_33_34;
        if (sdio_irq)
                mmc->caps |= MMC_CAP_SDIO_IRQ;
-       if (atmci_is_mci2())
+       if (host->caps.has_highspeed)
                mmc->caps |= MMC_CAP_SD_HIGHSPEED;
        if (slot_data->bus_width >= 4)
                mmc->caps |= MMC_CAP_4_BIT_DATA;
@@ -1704,8 +1929,7 @@ static void __exit atmci_cleanup_slot(struct atmel_mci_slot *slot,
        mmc_free_host(slot->mmc);
 }
 
-#ifdef CONFIG_MMC_ATMELMCI_DMA
-static bool filter(struct dma_chan *chan, void *slave)
+static bool atmci_filter(struct dma_chan *chan, void *slave)
 {
        struct mci_dma_data     *sl = slave;
 
@@ -1730,14 +1954,14 @@ static void atmci_configure_dma(struct atmel_mci *host)
                dma_cap_mask_t mask;
 
                setup_dma_addr(pdata->dma_slave,
-                              host->mapbase + MCI_TDR,
-                              host->mapbase + MCI_RDR);
+                              host->mapbase + ATMCI_TDR,
+                              host->mapbase + ATMCI_RDR);
 
                /* Try to grab a DMA channel */
                dma_cap_zero(mask);
                dma_cap_set(DMA_SLAVE, mask);
                host->dma.chan =
-                       dma_request_channel(mask, filter, pdata->dma_slave);
+                       dma_request_channel(mask, atmci_filter, pdata->dma_slave);
        }
        if (!host->dma.chan)
                dev_notice(&host->pdev->dev, "DMA not available, using PIO\n");
@@ -1746,9 +1970,60 @@ static void atmci_configure_dma(struct atmel_mci *host)
                                        "Using %s for DMA transfers\n",
                                        dma_chan_name(host->dma.chan));
 }
+
+static inline unsigned int atmci_get_version(struct atmel_mci *host)
+{
+       return atmci_readl(host, ATMCI_VERSION) & 0x00000fff;
+}
+
+/*
+ * HSMCI (High Speed MCI) module is not fully compatible with MCI module.
+ * HSMCI provides DMA support and a new config register but no more supports
+ * PDC.
+ */
+static void __init atmci_get_cap(struct atmel_mci *host)
+{
+       unsigned int version;
+
+       version = atmci_get_version(host);
+       dev_info(&host->pdev->dev,
+                       "version: 0x%x\n", version);
+
+       host->caps.has_dma = 0;
+       host->caps.has_pdc = 0;
+       host->caps.has_cfg_reg = 0;
+       host->caps.has_cstor_reg = 0;
+       host->caps.has_highspeed = 0;
+       host->caps.has_rwproof = 0;
+
+       /* keep only major version number */
+       switch (version & 0xf00) {
+       case 0x100:
+       case 0x200:
+               host->caps.has_pdc = 1;
+               host->caps.has_rwproof = 1;
+               break;
+       case 0x300:
+       case 0x400:
+       case 0x500:
+#ifdef CONFIG_AT_HDMAC
+               host->caps.has_dma = 1;
 #else
-static void atmci_configure_dma(struct atmel_mci *host) {}
+               host->caps.has_dma = 0;
+               dev_info(&host->pdev->dev,
+                       "has dma capability but dma engine is not selected, then use pio\n");
 #endif
+               host->caps.has_cfg_reg = 1;
+               host->caps.has_cstor_reg = 1;
+               host->caps.has_highspeed = 1;
+               host->caps.has_rwproof = 1;
+               break;
+       default:
+               dev_warn(&host->pdev->dev,
+                               "Unmanaged mci version, set minimum capabilities\n");
+               break;
+       }
+}
 
 static int __init atmci_probe(struct platform_device *pdev)
 {
@@ -1789,7 +2064,7 @@ static int __init atmci_probe(struct platform_device *pdev)
                goto err_ioremap;
 
        clk_enable(host->mck);
-       mci_writel(host, CR, MCI_CR_SWRST);
+       atmci_writel(host, ATMCI_CR, ATMCI_CR_SWRST);
        host->bus_hz = clk_get_rate(host->mck);
        clk_disable(host->mck);
 
@@ -1801,7 +2076,27 @@ static int __init atmci_probe(struct platform_device *pdev)
        if (ret)
                goto err_request_irq;
 
-       atmci_configure_dma(host);
+       /* Get MCI capabilities and set operations according to it */
+       atmci_get_cap(host);
+       if (host->caps.has_dma) {
+               dev_info(&pdev->dev, "using DMA\n");
+               host->prepare_data = &atmci_prepare_data_dma;
+               host->submit_data = &atmci_submit_data_dma;
+               host->stop_transfer = &atmci_stop_transfer_dma;
+       } else if (host->caps.has_pdc) {
+               dev_info(&pdev->dev, "using PDC\n");
+               host->prepare_data = &atmci_prepare_data_pdc;
+               host->submit_data = &atmci_submit_data_pdc;
+               host->stop_transfer = &atmci_stop_transfer_pdc;
+       } else {
+               dev_info(&pdev->dev, "no DMA, no PDC\n");
+               host->prepare_data = &atmci_prepare_data;
+               host->submit_data = &atmci_submit_data;
+               host->stop_transfer = &atmci_stop_transfer;
+       }
+
+       if (host->caps.has_dma)
+               atmci_configure_dma(host);
 
        platform_set_drvdata(pdev, host);
 
@@ -1810,13 +2105,13 @@ static int __init atmci_probe(struct platform_device *pdev)
        ret = -ENODEV;
        if (pdata->slot[0].bus_width) {
                ret = atmci_init_slot(host, &pdata->slot[0],
-                               0, MCI_SDCSEL_SLOT_A, MCI_SDIOIRQA);
+                               0, ATMCI_SDCSEL_SLOT_A, ATMCI_SDIOIRQA);
                if (!ret)
                        nr_slots++;
        }
        if (pdata->slot[1].bus_width) {
                ret = atmci_init_slot(host, &pdata->slot[1],
-                               1, MCI_SDCSEL_SLOT_B, MCI_SDIOIRQB);
+                               1, ATMCI_SDCSEL_SLOT_B, ATMCI_SDIOIRQB);
                if (!ret)
                        nr_slots++;
        }
@@ -1833,10 +2128,8 @@ static int __init atmci_probe(struct platform_device *pdev)
        return 0;
 
 err_init_slot:
-#ifdef CONFIG_MMC_ATMELMCI_DMA
        if (host->dma.chan)
                dma_release_channel(host->dma.chan);
-#endif
        free_irq(irq, host);
 err_request_irq:
        iounmap(host->regs);
@@ -1854,15 +2147,15 @@ static int __exit atmci_remove(struct platform_device *pdev)
 
        platform_set_drvdata(pdev, NULL);
 
-       for (i = 0; i < ATMEL_MCI_MAX_NR_SLOTS; i++) {
+       for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
                if (host->slot[i])
                        atmci_cleanup_slot(host->slot[i], i);
        }
 
        clk_enable(host->mck);
-       mci_writel(host, IDR, ~0UL);
-       mci_writel(host, CR, MCI_CR_MCIDIS);
-       mci_readl(host, SR);
+       atmci_writel(host, ATMCI_IDR, ~0UL);
+       atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIDIS);
+       atmci_readl(host, ATMCI_SR);
        clk_disable(host->mck);
 
 #ifdef CONFIG_MMC_ATMELMCI_DMA
@@ -1885,7 +2178,7 @@ static int atmci_suspend(struct device *dev)
        struct atmel_mci *host = dev_get_drvdata(dev);
        int i;
 
-        for (i = 0; i < ATMEL_MCI_MAX_NR_SLOTS; i++) {
+        for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
                struct atmel_mci_slot *slot = host->slot[i];
                int ret;
 
@@ -1916,7 +2209,7 @@ static int atmci_resume(struct device *dev)
        int i;
        int ret = 0;
 
-       for (i = 0; i < ATMEL_MCI_MAX_NR_SLOTS; i++) {
+       for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
                struct atmel_mci_slot *slot = host->slot[i];
                int err;
 
index ef72e874ca36b9ddb0ad943232ffa5a4f08eae2e..707bc7dddd226a1d29405efefa2bc2e853f13d1a 100644 (file)
@@ -55,7 +55,7 @@
 
 #ifdef DEBUG
 #define DBG(fmt, idx, args...) \
-       printk(KERN_DEBUG "au1xmmc(%d): DEBUG: " fmt, idx, ##args)
+       pr_debug("au1xmmc(%d): DEBUG: " fmt, idx, ##args)
 #else
 #define DBG(fmt, idx, args...) do {} while (0)
 #endif
@@ -268,7 +268,7 @@ static int au1xmmc_send_command(struct au1xmmc_host *host, int wait,
                mmccmd |= SD_CMD_RT_3;
                break;
        default:
-               printk(KERN_INFO "au1xmmc: unhandled response type %02x\n",
+               pr_info("au1xmmc: unhandled response type %02x\n",
                        mmc_resp_type(cmd));
                return -EINVAL;
        }
@@ -1031,7 +1031,7 @@ static int __devinit au1xmmc_probe(struct platform_device *pdev)
 #ifdef CONFIG_SOC_AU1200
        ret = au1xmmc_dbdma_init(host);
        if (ret)
-               printk(KERN_INFO DRIVER_NAME ": DBDMA init failed; using PIO\n");
+               pr_info(DRIVER_NAME ": DBDMA init failed; using PIO\n");
 #endif
 
 #ifdef CONFIG_LEDS_CLASS
@@ -1056,7 +1056,7 @@ static int __devinit au1xmmc_probe(struct platform_device *pdev)
 
        platform_set_drvdata(pdev, host);
 
-       printk(KERN_INFO DRIVER_NAME ": MMC Controller %d set up at %8.8X"
+       pr_info(DRIVER_NAME ": MMC Controller %d set up at %8.8X"
                " (mode=%s)\n", pdev->id, host->iobase,
                host->flags & HOST_F_DMA ? "dma" : "pio");
 
@@ -1188,7 +1188,7 @@ static int __init au1xmmc_init(void)
         */
        memid = au1xxx_ddma_add_device(&au1xmmc_mem_dbdev);
        if (!memid)
-               printk(KERN_ERR "au1xmmc: cannot add memory dbdma dev\n");
+               pr_err("au1xmmc: cannot add memory dbdma dev\n");
 #endif
        return platform_driver_register(&au1xmmc_driver);
 }
index ff0f714b012c0babf2b9faddcc36fe4647c87892..3aaeb0841914f6a1fdc790de71e6dbaaf15e735b 100644 (file)
@@ -764,11 +764,29 @@ static int dw_mci_get_cd(struct mmc_host *mmc)
        return present;
 }
 
+static void dw_mci_enable_sdio_irq(struct mmc_host *mmc, int enb)
+{
+       struct dw_mci_slot *slot = mmc_priv(mmc);
+       struct dw_mci *host = slot->host;
+       u32 int_mask;
+
+       /* Enable/disable Slot Specific SDIO interrupt */
+       int_mask = mci_readl(host, INTMASK);
+       if (enb) {
+               mci_writel(host, INTMASK,
+                          (int_mask | (1 << SDMMC_INT_SDIO(slot->id))));
+       } else {
+               mci_writel(host, INTMASK,
+                          (int_mask & ~(1 << SDMMC_INT_SDIO(slot->id))));
+       }
+}
+
 static const struct mmc_host_ops dw_mci_ops = {
-       .request        = dw_mci_request,
-       .set_ios        = dw_mci_set_ios,
-       .get_ro         = dw_mci_get_ro,
-       .get_cd         = dw_mci_get_cd,
+       .request                = dw_mci_request,
+       .set_ios                = dw_mci_set_ios,
+       .get_ro                 = dw_mci_get_ro,
+       .get_cd                 = dw_mci_get_cd,
+       .enable_sdio_irq        = dw_mci_enable_sdio_irq,
 };
 
 static void dw_mci_request_end(struct dw_mci *host, struct mmc_request *mrq)
@@ -1025,7 +1043,8 @@ static void dw_mci_push_data16(struct dw_mci *host, void *buf, int cnt)
                buf += len;
                cnt -= len;
                if (!sg_next(host->sg) || host->part_buf_count == 2) {
-                       mci_writew(host, DATA, host->part_buf16);
+                       mci_writew(host, DATA(host->data_offset),
+                                       host->part_buf16);
                        host->part_buf_count = 0;
                }
        }
@@ -1042,21 +1061,23 @@ static void dw_mci_push_data16(struct dw_mci *host, void *buf, int cnt)
                        cnt -= len;
                        /* push data from aligned buffer into fifo */
                        for (i = 0; i < items; ++i)
-                               mci_writew(host, DATA, aligned_buf[i]);
+                               mci_writew(host, DATA(host->data_offset),
+                                               aligned_buf[i]);
                }
        } else
 #endif
        {
                u16 *pdata = buf;
                for (; cnt >= 2; cnt -= 2)
-                       mci_writew(host, DATA, *pdata++);
+                       mci_writew(host, DATA(host->data_offset), *pdata++);
                buf = pdata;
        }
        /* put anything remaining in the part_buf */
        if (cnt) {
                dw_mci_set_part_bytes(host, buf, cnt);
                if (!sg_next(host->sg))
-                       mci_writew(host, DATA, host->part_buf16);
+                       mci_writew(host, DATA(host->data_offset),
+                                       host->part_buf16);
        }
 }
 
@@ -1071,7 +1092,8 @@ static void dw_mci_pull_data16(struct dw_mci *host, void *buf, int cnt)
                        int items = len >> 1;
                        int i;
                        for (i = 0; i < items; ++i)
-                               aligned_buf[i] = mci_readw(host, DATA);
+                               aligned_buf[i] = mci_readw(host,
+                                               DATA(host->data_offset));
                        /* memcpy from aligned buffer into output buffer */
                        memcpy(buf, aligned_buf, len);
                        buf += len;
@@ -1082,11 +1104,11 @@ static void dw_mci_pull_data16(struct dw_mci *host, void *buf, int cnt)
        {
                u16 *pdata = buf;
                for (; cnt >= 2; cnt -= 2)
-                       *pdata++ = mci_readw(host, DATA);
+                       *pdata++ = mci_readw(host, DATA(host->data_offset));
                buf = pdata;
        }
        if (cnt) {
-               host->part_buf16 = mci_readw(host, DATA);
+               host->part_buf16 = mci_readw(host, DATA(host->data_offset));
                dw_mci_pull_final_bytes(host, buf, cnt);
        }
 }
@@ -1099,7 +1121,8 @@ static void dw_mci_push_data32(struct dw_mci *host, void *buf, int cnt)
                buf += len;
                cnt -= len;
                if (!sg_next(host->sg) || host->part_buf_count == 4) {
-                       mci_writel(host, DATA, host->part_buf32);
+                       mci_writel(host, DATA(host->data_offset),
+                                       host->part_buf32);
                        host->part_buf_count = 0;
                }
        }
@@ -1116,21 +1139,23 @@ static void dw_mci_push_data32(struct dw_mci *host, void *buf, int cnt)
                        cnt -= len;
                        /* push data from aligned buffer into fifo */
                        for (i = 0; i < items; ++i)
-                               mci_writel(host, DATA, aligned_buf[i]);
+                               mci_writel(host, DATA(host->data_offset),
+                                               aligned_buf[i]);
                }
        } else
 #endif
        {
                u32 *pdata = buf;
                for (; cnt >= 4; cnt -= 4)
-                       mci_writel(host, DATA, *pdata++);
+                       mci_writel(host, DATA(host->data_offset), *pdata++);
                buf = pdata;
        }
        /* put anything remaining in the part_buf */
        if (cnt) {
                dw_mci_set_part_bytes(host, buf, cnt);
                if (!sg_next(host->sg))
-                       mci_writel(host, DATA, host->part_buf32);
+                       mci_writel(host, DATA(host->data_offset),
+                                               host->part_buf32);
        }
 }
 
@@ -1145,7 +1170,8 @@ static void dw_mci_pull_data32(struct dw_mci *host, void *buf, int cnt)
                        int items = len >> 2;
                        int i;
                        for (i = 0; i < items; ++i)
-                               aligned_buf[i] = mci_readl(host, DATA);
+                               aligned_buf[i] = mci_readl(host,
+                                               DATA(host->data_offset));
                        /* memcpy from aligned buffer into output buffer */
                        memcpy(buf, aligned_buf, len);
                        buf += len;
@@ -1156,11 +1182,11 @@ static void dw_mci_pull_data32(struct dw_mci *host, void *buf, int cnt)
        {
                u32 *pdata = buf;
                for (; cnt >= 4; cnt -= 4)
-                       *pdata++ = mci_readl(host, DATA);
+                       *pdata++ = mci_readl(host, DATA(host->data_offset));
                buf = pdata;
        }
        if (cnt) {
-               host->part_buf32 = mci_readl(host, DATA);
+               host->part_buf32 = mci_readl(host, DATA(host->data_offset));
                dw_mci_pull_final_bytes(host, buf, cnt);
        }
 }
@@ -1173,7 +1199,8 @@ static void dw_mci_push_data64(struct dw_mci *host, void *buf, int cnt)
                buf += len;
                cnt -= len;
                if (!sg_next(host->sg) || host->part_buf_count == 8) {
-                       mci_writew(host, DATA, host->part_buf);
+                       mci_writew(host, DATA(host->data_offset),
+                                       host->part_buf);
                        host->part_buf_count = 0;
                }
        }
@@ -1190,21 +1217,23 @@ static void dw_mci_push_data64(struct dw_mci *host, void *buf, int cnt)
                        cnt -= len;
                        /* push data from aligned buffer into fifo */
                        for (i = 0; i < items; ++i)
-                               mci_writeq(host, DATA, aligned_buf[i]);
+                               mci_writeq(host, DATA(host->data_offset),
+                                               aligned_buf[i]);
                }
        } else
 #endif
        {
                u64 *pdata = buf;
                for (; cnt >= 8; cnt -= 8)
-                       mci_writeq(host, DATA, *pdata++);
+                       mci_writeq(host, DATA(host->data_offset), *pdata++);
                buf = pdata;
        }
        /* put anything remaining in the part_buf */
        if (cnt) {
                dw_mci_set_part_bytes(host, buf, cnt);
                if (!sg_next(host->sg))
-                       mci_writeq(host, DATA, host->part_buf);
+                       mci_writeq(host, DATA(host->data_offset),
+                                       host->part_buf);
        }
 }
 
@@ -1219,7 +1248,8 @@ static void dw_mci_pull_data64(struct dw_mci *host, void *buf, int cnt)
                        int items = len >> 3;
                        int i;
                        for (i = 0; i < items; ++i)
-                               aligned_buf[i] = mci_readq(host, DATA);
+                               aligned_buf[i] = mci_readq(host,
+                                               DATA(host->data_offset));
                        /* memcpy from aligned buffer into output buffer */
                        memcpy(buf, aligned_buf, len);
                        buf += len;
@@ -1230,11 +1260,11 @@ static void dw_mci_pull_data64(struct dw_mci *host, void *buf, int cnt)
        {
                u64 *pdata = buf;
                for (; cnt >= 8; cnt -= 8)
-                       *pdata++ = mci_readq(host, DATA);
+                       *pdata++ = mci_readq(host, DATA(host->data_offset));
                buf = pdata;
        }
        if (cnt) {
-               host->part_buf = mci_readq(host, DATA);
+               host->part_buf = mci_readq(host, DATA(host->data_offset));
                dw_mci_pull_final_bytes(host, buf, cnt);
        }
 }
@@ -1406,6 +1436,7 @@ static irqreturn_t dw_mci_interrupt(int irq, void *dev_id)
        struct dw_mci *host = dev_id;
        u32 status, pending;
        unsigned int pass_count = 0;
+       int i;
 
        do {
                status = mci_readl(host, RINTSTS);
@@ -1477,6 +1508,15 @@ static irqreturn_t dw_mci_interrupt(int irq, void *dev_id)
                        queue_work(dw_mci_card_workqueue, &host->card_work);
                }
 
+               /* Handle SDIO Interrupts */
+               for (i = 0; i < host->num_slots; i++) {
+                       struct dw_mci_slot *slot = host->slot[i];
+                       if (pending & SDMMC_INT_SDIO(i)) {
+                               mci_writel(host, RINTSTS, SDMMC_INT_SDIO(i));
+                               mmc_signal_sdio_irq(slot->mmc);
+                       }
+               }
+
        } while (pass_count++ < 5);
 
 #ifdef CONFIG_MMC_DW_IDMAC
@@ -1673,7 +1713,7 @@ static int __init dw_mci_init_slot(struct dw_mci *host, unsigned int id)
 
        host->vmmc = regulator_get(mmc_dev(mmc), "vmmc");
        if (IS_ERR(host->vmmc)) {
-               printk(KERN_INFO "%s: no vmmc regulator found\n", mmc_hostname(mmc));
+               pr_info("%s: no vmmc regulator found\n", mmc_hostname(mmc));
                host->vmmc = NULL;
        } else
                regulator_enable(host->vmmc);
@@ -1923,6 +1963,18 @@ static int dw_mci_probe(struct platform_device *pdev)
                }
        }
 
+       /*
+        * In 2.40a spec, Data offset is changed.
+        * Need to check the version-id and set data-offset for DATA register.
+        */
+       host->verid = SDMMC_GET_VERID(mci_readl(host, VERID));
+       dev_info(&pdev->dev, "Version ID is %04x\n", host->verid);
+
+       if (host->verid < DW_MMC_240A)
+               host->data_offset = DATA_OFFSET;
+       else
+               host->data_offset = DATA_240A_OFFSET;
+
        /*
         * Enable interrupts for command done, data over, data empty, card det,
         * receive ready and error such as transmit, receive timeout, crc error
index 027d3773539429eea6ca081ab8dccfd2fbba8bcd..72c071f6e0015c7c0d254560fc3d3c344569de39 100644 (file)
@@ -14,6 +14,8 @@
 #ifndef _DW_MMC_H_
 #define _DW_MMC_H_
 
+#define DW_MMC_240A            0x240a
+
 #define SDMMC_CTRL             0x000
 #define SDMMC_PWREN            0x004
 #define SDMMC_CLKDIV           0x008
 #define SDMMC_IDINTEN          0x090
 #define SDMMC_DSCADDR          0x094
 #define SDMMC_BUFADDR          0x098
-#define SDMMC_DATA             0x100
+#define SDMMC_DATA(x)          (x)
+
+/*
+ * Data offset is difference according to Version
+ * Lower than 2.40a : data register offest is 0x100
+ */
+#define DATA_OFFSET            0x100
+#define DATA_240A_OFFSET       0x200
 
 /* shift bit field */
 #define _SBF(f, v)             ((v) << (f))
@@ -82,7 +91,7 @@
 #define SDMMC_CTYPE_4BIT               BIT(0)
 #define SDMMC_CTYPE_1BIT               0
 /* Interrupt status & mask register defines */
-#define SDMMC_INT_SDIO                 BIT(16)
+#define SDMMC_INT_SDIO(n)              BIT(16 + (n))
 #define SDMMC_INT_EBE                  BIT(15)
 #define SDMMC_INT_ACD                  BIT(14)
 #define SDMMC_INT_SBE                  BIT(13)
 #define SDMMC_IDMAC_ENABLE             BIT(7)
 #define SDMMC_IDMAC_FB                 BIT(1)
 #define SDMMC_IDMAC_SWRESET            BIT(0)
+/* Version ID register define */
+#define SDMMC_GET_VERID(x)             ((x) & 0xFFFF)
 
 /* Register access macros */
 #define mci_readl(dev, reg)                    \
index 881f7ba545aefa05dd0e8c5389b06f2092723b7d..ea0f3cedef21de71a1d5472e91631504f6ad3371 100644 (file)
@@ -942,7 +942,7 @@ static int __init imxmci_probe(struct platform_device *pdev)
        int ret = 0, irq;
        u16 rev_no;
 
-       printk(KERN_INFO "i.MX mmc driver\n");
+       pr_info("i.MX mmc driver\n");
 
        r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        irq = platform_get_irq(pdev, 0);
index 7c1e16aaf17ff9449909dd77b72573f6bd156526..92946b84e9faa58e9958a1cbf7e371332748afd3 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/sched.h>
 #include <linux/delay.h>
 #include <linux/slab.h>
+#include <linux/module.h>
 #include <linux/bio.h>
 #include <linux/dma-mapping.h>
 #include <linux/crc7.h>
index 7be8db0f9f7dc9fbc7b82b311944649b83a6f099..50b5f9926f6462d7836434c89a71213f418faa9c 100644 (file)
@@ -466,7 +466,7 @@ static void mmci_get_next_data(struct mmci_host *host, struct mmc_data *data)
        struct mmci_host_next *next = &host->next_data;
 
        if (data->host_cookie && data->host_cookie != next->cookie) {
-               printk(KERN_WARNING "[%s] invalid cookie: data->host_cookie %d"
+               pr_warning("[%s] invalid cookie: data->host_cookie %d"
                       " host->next_data.cookie %d\n",
                       __func__, data->host_cookie, host->next_data.cookie);
                data->host_cookie = 0;
@@ -531,7 +531,7 @@ static void mmci_post_request(struct mmc_host *mmc, struct mmc_request *mrq,
        if (chan) {
                if (err)
                        dmaengine_terminate_all(chan);
-               if (err || data->host_cookie)
+               if (data->host_cookie)
                        dma_unmap_sg(mmc_dev(host->mmc), data->sg,
                                     data->sg_len, dir);
                mrq->data->host_cookie = 0;
index a4c865a5286b2cde603898fd7e4a669e429855f1..80d8eb143b486c92ee143f6e70992570625e33e3 100644 (file)
@@ -213,7 +213,8 @@ msmsdcc_dma_exec_func(struct msm_dmov_cmd *cmd)
        msmsdcc_writel(host, host->cmd_timeout, MMCIDATATIMER);
        msmsdcc_writel(host, (unsigned int)host->curr.xfer_size,
                       MMCIDATALENGTH);
-       msmsdcc_writel(host, host->cmd_pio_irqmask, MMCIMASK1);
+       msmsdcc_writel(host, (msmsdcc_readl(host, MMCIMASK0) &
+                       (~MCI_IRQ_PIO)) | host->cmd_pio_irqmask, MMCIMASK0);
        msmsdcc_writel(host, host->cmd_datactrl, MMCIDATACTRL);
 
        if (host->cmd_cmd) {
@@ -388,7 +389,7 @@ static int msmsdcc_config_dma(struct msmsdcc_host *host, struct mmc_data *data)
        n = dma_map_sg(mmc_dev(host->mmc), host->dma.sg,
                        host->dma.num_ents, host->dma.dir);
        if (n == 0) {
-               printk(KERN_ERR "%s: Unable to map in all sg elements\n",
+               pr_err("%s: Unable to map in all sg elements\n",
                        mmc_hostname(host->mmc));
                host->dma.sg = NULL;
                host->dma.num_ents = 0;
@@ -474,7 +475,7 @@ msmsdcc_start_command_deferred(struct msmsdcc_host *host,
                *c |= MCI_CSPM_MCIABORT;
 
        if (host->curr.cmd != NULL) {
-               printk(KERN_ERR "%s: Overlapping command requests\n",
+               pr_err("%s: Overlapping command requests\n",
                        mmc_hostname(host->mmc));
        }
        host->curr.cmd = cmd;
@@ -543,7 +544,9 @@ msmsdcc_start_data(struct msmsdcc_host *host, struct mmc_data *data,
 
                msmsdcc_writel(host, host->curr.xfer_size, MMCIDATALENGTH);
 
-               msmsdcc_writel(host, pio_irqmask, MMCIMASK1);
+               msmsdcc_writel(host, (msmsdcc_readl(host, MMCIMASK0) &
+                               (~MCI_IRQ_PIO)) | pio_irqmask, MMCIMASK0);
+
                msmsdcc_writel(host, datactrl, MMCIDATACTRL);
 
                if (cmd) {
@@ -659,8 +662,13 @@ msmsdcc_pio_irq(int irq, void *dev_id)
 {
        struct msmsdcc_host     *host = dev_id;
        uint32_t                status;
+       u32 mci_mask0;
 
        status = msmsdcc_readl(host, MMCISTATUS);
+       mci_mask0 = msmsdcc_readl(host, MMCIMASK0);
+
+       if (((mci_mask0 & status) & MCI_IRQ_PIO) == 0)
+               return IRQ_NONE;
 
        do {
                unsigned long flags;
@@ -719,10 +727,12 @@ msmsdcc_pio_irq(int irq, void *dev_id)
        } while (1);
 
        if (status & MCI_RXACTIVE && host->curr.xfer_remain < MCI_FIFOSIZE)
-               msmsdcc_writel(host, MCI_RXDATAAVLBLMASK, MMCIMASK1);
+               msmsdcc_writel(host, (mci_mask0 & (~MCI_IRQ_PIO)) |
+                                       MCI_RXDATAAVLBLMASK, MMCIMASK0);
 
        if (!host->curr.xfer_remain)
-               msmsdcc_writel(host, 0, MMCIMASK1);
+               msmsdcc_writel(host, (mci_mask0 & (~MCI_IRQ_PIO)) | 0,
+                                       MMCIMASK0);
 
        return IRQ_HANDLED;
 }
@@ -854,6 +864,8 @@ msmsdcc_irq(int irq, void *dev_id)
        do {
                status = msmsdcc_readl(host, MMCISTATUS);
                status &= msmsdcc_readl(host, MMCIMASK0);
+               if ((status & (~MCI_IRQ_PIO)) == 0)
+                       break;
                msmsdcc_writel(host, status, MMCICLEAR);
 
                if (status & MCI_SDIOINTR)
@@ -939,7 +951,7 @@ static void msmsdcc_setup_gpio(struct msmsdcc_host *host, bool enable)
        struct msm_mmc_gpio_data *curr;
        int i, rc = 0;
 
-       if (!host->plat->gpio_data && host->gpio_config_status == enable)
+       if (!host->plat->gpio_data || host->gpio_config_status == enable)
                return;
 
        curr = host->plat->gpio_data;
@@ -1052,10 +1064,19 @@ static void msmsdcc_enable_sdio_irq(struct mmc_host *mmc, int enable)
        spin_unlock_irqrestore(&host->lock, flags);
 }
 
+static void msmsdcc_init_card(struct mmc_host *mmc, struct mmc_card *card)
+{
+       struct msmsdcc_host *host = mmc_priv(mmc);
+
+       if (host->plat->init_card)
+               host->plat->init_card(card);
+}
+
 static const struct mmc_host_ops msmsdcc_ops = {
        .request        = msmsdcc_request,
        .set_ios        = msmsdcc_set_ios,
        .enable_sdio_irq = msmsdcc_enable_sdio_irq,
+       .init_card      = msmsdcc_init_card,
 };
 
 static void
@@ -1092,7 +1113,7 @@ msmsdcc_platform_status_irq(int irq, void *dev_id)
 {
        struct msmsdcc_host *host = dev_id;
 
-       printk(KERN_DEBUG "%s: %d\n", __func__, irq);
+       pr_debug("%s: %d\n", __func__, irq);
        msmsdcc_check_status((unsigned long) host);
        return IRQ_HANDLED;
 }
@@ -1102,7 +1123,7 @@ msmsdcc_status_notify_cb(int card_present, void *dev_id)
 {
        struct msmsdcc_host *host = dev_id;
 
-       printk(KERN_DEBUG "%s: card_present %d\n", mmc_hostname(host->mmc),
+       pr_debug("%s: card_present %d\n", mmc_hostname(host->mmc),
               card_present);
        msmsdcc_check_status((unsigned long) host);
 }
@@ -1150,7 +1171,6 @@ msmsdcc_probe(struct platform_device *pdev)
        struct msmsdcc_host *host;
        struct mmc_host *mmc;
        struct resource *cmd_irqres = NULL;
-       struct resource *pio_irqres = NULL;
        struct resource *stat_irqres = NULL;
        struct resource *memres = NULL;
        struct resource *dmares = NULL;
@@ -1175,12 +1195,10 @@ msmsdcc_probe(struct platform_device *pdev)
        dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0);
        cmd_irqres = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
                                                  "cmd_irq");
-       pio_irqres = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
-                                                 "pio_irq");
        stat_irqres = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
                                                   "status_irq");
 
-       if (!cmd_irqres || !pio_irqres || !memres) {
+       if (!cmd_irqres || !memres) {
                pr_err("%s: Invalid resource\n", __func__);
                return -ENXIO;
        }
@@ -1200,17 +1218,20 @@ msmsdcc_probe(struct platform_device *pdev)
        host->plat = plat;
        host->mmc = mmc;
        host->curr.cmd = NULL;
+       init_timer(&host->busclk_timer);
+       host->busclk_timer.data = (unsigned long) host;
+       host->busclk_timer.function = msmsdcc_busclk_expired;
+
 
        host->cmdpoll = 1;
 
        host->base = ioremap(memres->start, PAGE_SIZE);
        if (!host->base) {
                ret = -ENOMEM;
-               goto out;
+               goto host_free;
        }
 
        host->cmd_irqres = cmd_irqres;
-       host->pio_irqres = pio_irqres;
        host->memres = memres;
        host->dmares = dmares;
        spin_lock_init(&host->lock);
@@ -1221,13 +1242,19 @@ msmsdcc_probe(struct platform_device *pdev)
        /*
         * Setup DMA
         */
-       msmsdcc_init_dma(host);
+       if (host->dmares) {
+               ret = msmsdcc_init_dma(host);
+               if (ret)
+                       goto ioremap_free;
+       } else {
+               host->dma.channel = -1;
+       }
 
        /* Get our clocks */
        host->pclk = clk_get(&pdev->dev, "sdc_pclk");
        if (IS_ERR(host->pclk)) {
                ret = PTR_ERR(host->pclk);
-               goto host_free;
+               goto dma_free;
        }
 
        host->clk = clk_get(&pdev->dev, "sdc_clk");
@@ -1236,17 +1263,17 @@ msmsdcc_probe(struct platform_device *pdev)
                goto pclk_put;
        }
 
-       /* Enable clocks */
-       ret = msmsdcc_enable_clocks(host);
-       if (ret)
-               goto clk_put;
-
        ret = clk_set_rate(host->clk, msmsdcc_fmin);
        if (ret) {
                pr_err("%s: Clock rate set failed (%d)\n", __func__, ret);
-               goto clk_disable;
+               goto clk_put;
        }
 
+       /* Enable clocks */
+       ret = msmsdcc_enable_clocks(host);
+       if (ret)
+               goto clk_put;
+
        host->pclk_rate = clk_get_rate(host->pclk);
        host->clk_rate = clk_get_rate(host->clk);
 
@@ -1316,16 +1343,12 @@ msmsdcc_probe(struct platform_device *pdev)
                host->eject = !host->oldstat;
        }
 
-       init_timer(&host->busclk_timer);
-       host->busclk_timer.data = (unsigned long) host;
-       host->busclk_timer.function = msmsdcc_busclk_expired;
-
        ret = request_irq(cmd_irqres->start, msmsdcc_irq, IRQF_SHARED,
                          DRIVER_NAME " (cmd)", host);
        if (ret)
                goto stat_irq_free;
 
-       ret = request_irq(pio_irqres->start, msmsdcc_pio_irq, IRQF_SHARED,
+       ret = request_irq(cmd_irqres->start, msmsdcc_pio_irq, IRQF_SHARED,
                          DRIVER_NAME " (pio)", host);
        if (ret)
                goto cmd_irq_free;
@@ -1368,6 +1391,13 @@ msmsdcc_probe(struct platform_device *pdev)
        clk_put(host->clk);
  pclk_put:
        clk_put(host->pclk);
+dma_free:
+       if (host->dmares)
+               dma_free_coherent(NULL, sizeof(struct msmsdcc_nc_dmadata),
+                                       host->dma.nc, host->dma.nc_busaddr);
+ioremap_free:
+       tasklet_kill(&host->dma_tlet);
+       iounmap(host->base);
  host_free:
        mmc_free_host(mmc);
  out:
index 42d7bbc977c5846a38e5c06449a22a0998374e41..402028d16b86836171a5c4a1c43ff7eea2ab8bb4 100644 (file)
        MCI_DATATIMEOUTMASK|MCI_TXUNDERRUNMASK|MCI_RXOVERRUNMASK|       \
        MCI_CMDRESPENDMASK|MCI_CMDSENTMASK|MCI_DATAENDMASK|MCI_PROGDONEMASK)
 
+#define MCI_IRQ_PIO \
+       (MCI_RXDATAAVLBLMASK | MCI_TXDATAAVLBLMASK | MCI_RXFIFOEMPTYMASK | \
+        MCI_TXFIFOEMPTYMASK | MCI_RXFIFOFULLMASK | MCI_TXFIFOFULLMASK | \
+        MCI_RXFIFOHALFFULLMASK | MCI_TXFIFOHALFEMPTYMASK | \
+        MCI_RXACTIVEMASK | MCI_TXACTIVEMASK)
 /*
  * The size of the FIFO in bytes.
  */
@@ -202,7 +207,6 @@ struct msmsdcc_stats {
 
 struct msmsdcc_host {
        struct resource         *cmd_irqres;
-       struct resource         *pio_irqres;
        struct resource         *memres;
        struct resource         *dmares;
        void __iomem            *base;
index a5bf60e01af44b96059e0c145afe4bb3ea2ebdc4..211a4959c29372e6e93f38e96554274f050f0499 100644 (file)
@@ -117,7 +117,7 @@ static int mvsd_setup_data(struct mvsd_host *host, struct mmc_data *data)
                host->pio_size = data->blocks * data->blksz;
                host->pio_ptr = sg_virt(data->sg);
                if (!nodma)
-                       printk(KERN_DEBUG "%s: fallback to PIO for data "
+                       pr_debug("%s: fallback to PIO for data "
                                          "at 0x%p size %d\n",
                                          mmc_hostname(host->mmc),
                                          host->pio_ptr, host->pio_size);
@@ -471,7 +471,7 @@ static irqreturn_t mvsd_irq(int irq, void *dev)
                if (mrq->data)
                        err_status = mvsd_finish_data(host, mrq->data, err_status);
                if (err_status) {
-                       printk(KERN_ERR "%s: unhandled error status %#04x\n",
+                       pr_err("%s: unhandled error status %#04x\n",
                                        mmc_hostname(host->mmc), err_status);
                        cmd->error = -ENOMSG;
                }
@@ -489,7 +489,7 @@ static irqreturn_t mvsd_irq(int irq, void *dev)
        if (irq_handled)
                return IRQ_HANDLED;
 
-       printk(KERN_ERR "%s: unhandled interrupt status=0x%04x en=0x%04x "
+       pr_err("%s: unhandled interrupt status=0x%04x en=0x%04x "
                        "pio=%d\n", mmc_hostname(host->mmc), intr_status,
                        host->intr_en, host->pio_size);
        return IRQ_NONE;
@@ -505,9 +505,9 @@ static void mvsd_timeout_timer(unsigned long data)
        spin_lock_irqsave(&host->lock, flags);
        mrq = host->mrq;
        if (mrq) {
-               printk(KERN_ERR "%s: Timeout waiting for hardware interrupt.\n",
+               pr_err("%s: Timeout waiting for hardware interrupt.\n",
                                mmc_hostname(host->mmc));
-               printk(KERN_ERR "%s: hw_state=0x%04x, intr_status=0x%04x "
+               pr_err("%s: hw_state=0x%04x, intr_status=0x%04x "
                                "intr_en=0x%04x\n", mmc_hostname(host->mmc),
                                mvsd_read(MVSD_HW_STATE),
                                mvsd_read(MVSD_NOR_INTR_STATUS),
@@ -762,7 +762,7 @@ static int __init mvsd_probe(struct platform_device *pdev)
 
        ret = request_irq(irq, mvsd_irq, 0, DRIVER_NAME, host);
        if (ret) {
-               printk(KERN_ERR "%s: cannot assign irq %d\n", DRIVER_NAME, irq);
+               pr_err("%s: cannot assign irq %d\n", DRIVER_NAME, irq);
                goto out;
        } else
                host->irq = irq;
@@ -802,7 +802,7 @@ static int __init mvsd_probe(struct platform_device *pdev)
        if (ret)
                goto out;
 
-       printk(KERN_NOTICE "%s: %s driver initialized, ",
+       pr_notice("%s: %s driver initialized, ",
                           mmc_hostname(mmc), DRIVER_NAME);
        if (host->gpio_card_detect)
                printk("using GPIO %d for card detection\n",
index 14aa213b00da3a3b2a8d5e332528bb2d952e44a9..f48743de467301cffd1dd423a413b419014f25d9 100644 (file)
@@ -842,7 +842,7 @@ static int mxcmci_probe(struct platform_device *pdev)
        int ret = 0, irq;
        dma_cap_mask_t mask;
 
-       printk(KERN_INFO "i.MX SDHC driver\n");
+       pr_info("i.MX SDHC driver\n");
 
        iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        irq = platform_get_irq(pdev, 0);
index d513d47364d0ad07c3bf4f6eac0e722655d8ff5a..99b449d26a4d39579c787871ca448e50bed8a37a 100644 (file)
@@ -37,6 +37,7 @@
 #include <linux/mmc/sdio.h>
 #include <linux/gpio.h>
 #include <linux/regulator/consumer.h>
+#include <linux/module.h>
 
 #include <mach/mxs.h>
 #include <mach/common.h>
index 21e4a799df48b49bdbea53cefbc671375e944bf4..e8ff12396680cab635cb1ee370bd5c656cae9640 100644 (file)
@@ -450,15 +450,14 @@ static int omap_hsmmc_reg_get(struct omap_hsmmc_host *host)
                * framework is fixed, we need a workaround like this
                * (which is safe for MMC, but not in general).
                */
-               if (regulator_is_enabled(host->vcc) > 0) {
-                       regulator_enable(host->vcc);
-                       regulator_disable(host->vcc);
-               }
-               if (host->vcc_aux) {
-                       if (regulator_is_enabled(reg) > 0) {
-                               regulator_enable(reg);
-                               regulator_disable(reg);
-                       }
+               if (regulator_is_enabled(host->vcc) > 0 ||
+                   (host->vcc_aux && regulator_is_enabled(host->vcc_aux))) {
+                       int vdd = ffs(mmc_slot(host).ocr_mask) - 1;
+
+                       mmc_slot(host).set_power(host->dev, host->slot_id,
+                                                1, vdd);
+                       mmc_slot(host).set_power(host->dev, host->slot_id,
+                                                0, 0);
                }
        }
 
@@ -1264,14 +1263,14 @@ static void omap_hsmmc_protect_card(struct omap_hsmmc_host *host)
        host->reqs_blocked = 0;
        if (mmc_slot(host).get_cover_state(host->dev, host->slot_id)) {
                if (host->protect_card) {
-                       printk(KERN_INFO "%s: cover is closed, "
+                       pr_info("%s: cover is closed, "
                                         "card is now accessible\n",
                                         mmc_hostname(host->mmc));
                        host->protect_card = 0;
                }
        } else {
                if (!host->protect_card) {
-                       printk(KERN_INFO "%s: cover is open, "
+                       pr_info"%s: cover is open, "
                                         "card is now inaccessible\n",
                                         mmc_hostname(host->mmc));
                        host->protect_card = 1;
@@ -1422,7 +1421,7 @@ static int omap_hsmmc_pre_dma_transfer(struct omap_hsmmc_host *host,
 
        if (!next && data->host_cookie &&
            data->host_cookie != host->next_data.cookie) {
-               printk(KERN_WARNING "[%s] invalid cookie: data->host_cookie %d"
+               pr_warning("[%s] invalid cookie: data->host_cookie %d"
                       " host->next_data.cookie %d\n",
                       __func__, data->host_cookie, host->next_data.cookie);
                data->host_cookie = 0;
@@ -1943,6 +1942,10 @@ static int __init omap_hsmmc_probe(struct platform_device *pdev)
        omap_hsmmc_context_save(host);
 
        mmc->caps |= MMC_CAP_DISABLE;
+       if (host->pdata->controller_flags & OMAP_HSMMC_BROKEN_MULTIBLOCK_READ) {
+               dev_info(&pdev->dev, "multiblock reads disabled due to 35xx erratum 2.1.1.128; MMC read performance may suffer\n");
+               mmc->caps2 |= MMC_CAP2_NO_MULTI_READ;
+       }
 
        pm_runtime_enable(host->dev);
        pm_runtime_get_sync(host->dev);
@@ -2015,7 +2018,7 @@ static int __init omap_hsmmc_probe(struct platform_device *pdev)
        }
 
        /* Request IRQ for MMC operations */
-       ret = request_irq(host->irq, omap_hsmmc_irq, IRQF_DISABLED,
+       ret = request_irq(host->irq, omap_hsmmc_irq, 0,
                        mmc_hostname(mmc), host);
        if (ret) {
                dev_dbg(mmc_dev(host->mmc), "Unable to grab HSMMC IRQ\n");
@@ -2043,8 +2046,7 @@ static int __init omap_hsmmc_probe(struct platform_device *pdev)
        if ((mmc_slot(host).card_detect_irq)) {
                ret = request_irq(mmc_slot(host).card_detect_irq,
                                  omap_hsmmc_cd_handler,
-                                 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING
-                                         | IRQF_DISABLED,
+                                 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
                                  mmc_hostname(mmc), host);
                if (ret) {
                        dev_dbg(mmc_dev(host->mmc),
index 7257738fd7daf125b043ea9984bebf5f83ac1bbc..fc4356e00d46ff7366ed38a6f76ab2f3e2c9cbce 100644 (file)
@@ -558,7 +558,7 @@ static void pxamci_dma_irq(int dma, void *devid)
        if (dcsr & DCSR_ENDINTR) {
                writel(BUF_PART_FULL, host->base + MMC_PRTBUF);
        } else {
-               printk(KERN_ERR "%s: DMA error on channel %d (DCSR=%#x)\n",
+               pr_err("%s: DMA error on channel %d (DCSR=%#x)\n",
                       mmc_hostname(host->mmc), dma, dcsr);
                host->data->error = -EIO;
                pxamci_data_done(host, 0);
index a04f87d7ee3d13a79be90146b2cfa004014d01be..d2856b6b2a627470cc458e77a03152a774c708b2 100644 (file)
@@ -247,7 +247,7 @@ static void s3cmci_check_sdio_irq(struct s3cmci_host *host)
 {
        if (host->sdio_irqen) {
                if (gpio_get_value(S3C2410_GPE(8)) == 0) {
-                       printk(KERN_DEBUG "%s: signalling irq\n", __func__);
+                       pr_debug("%s: signalling irq\n", __func__);
                        mmc_signal_sdio_irq(host->mmc);
                }
        }
@@ -344,7 +344,7 @@ static void s3cmci_disable_irq(struct s3cmci_host *host, bool transfer)
 
        local_irq_save(flags);
 
-       //printk(KERN_DEBUG "%s: transfer %d\n", __func__, transfer);
+       /* pr_debug("%s: transfer %d\n", __func__, transfer); */
 
        host->irq_disabled = transfer;
 
index 4dc0028086a34357ef5b5578678ce7ca4a1ccdd6..ae57769ba50d53c129bc1b6399b92db37c9bc010 100644 (file)
 /* VENDOR SPEC register */
 #define SDHCI_VENDOR_SPEC              0xC0
 #define  SDHCI_VENDOR_SPEC_SDIO_QUIRK  0x00000002
+#define SDHCI_MIX_CTRL                 0x48
+
+/*
+ * There is an INT DMA ERR mis-match between eSDHC and STD SDHC SPEC:
+ * Bit25 is used in STD SPEC, and is reserved in fsl eSDHC design,
+ * but bit28 is used as the INT DMA ERR in fsl eSDHC design.
+ * Define this macro DMA error INT for fsl eSDHC
+ */
+#define SDHCI_INT_VENDOR_SPEC_DMA_ERR  0x10000000
 
 /*
  * The CMDTYPE of the CMD register (offset 0xE) should be set to
@@ -51,6 +60,7 @@ enum imx_esdhc_type {
        IMX35_ESDHC,
        IMX51_ESDHC,
        IMX53_ESDHC,
+       IMX6Q_USDHC,
 };
 
 struct pltfm_imx_data {
@@ -73,6 +83,9 @@ static struct platform_device_id imx_esdhc_devtype[] = {
        }, {
                .name = "sdhci-esdhc-imx53",
                .driver_data = IMX53_ESDHC,
+       }, {
+               .name = "sdhci-usdhc-imx6q",
+               .driver_data = IMX6Q_USDHC,
        }, {
                /* sentinel */
        }
@@ -84,6 +97,7 @@ static const struct of_device_id imx_esdhc_dt_ids[] = {
        { .compatible = "fsl,imx35-esdhc", .data = &imx_esdhc_devtype[IMX35_ESDHC], },
        { .compatible = "fsl,imx51-esdhc", .data = &imx_esdhc_devtype[IMX51_ESDHC], },
        { .compatible = "fsl,imx53-esdhc", .data = &imx_esdhc_devtype[IMX53_ESDHC], },
+       { .compatible = "fsl,imx6q-usdhc", .data = &imx_esdhc_devtype[IMX6Q_USDHC], },
        { /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, imx_esdhc_dt_ids);
@@ -108,6 +122,11 @@ static inline int is_imx53_esdhc(struct pltfm_imx_data *data)
        return data->devtype == IMX53_ESDHC;
 }
 
+static inline int is_imx6q_usdhc(struct pltfm_imx_data *data)
+{
+       return data->devtype == IMX6Q_USDHC;
+}
+
 static inline void esdhc_clrset_le(struct sdhci_host *host, u32 mask, u32 val, int reg)
 {
        void __iomem *base = host->ioaddr + (reg & ~0x3);
@@ -135,6 +154,27 @@ static u32 esdhc_readl_le(struct sdhci_host *host, int reg)
                        val |= SDHCI_CARD_PRESENT;
        }
 
+       if (unlikely(reg == SDHCI_CAPABILITIES)) {
+               /* In FSL esdhc IC module, only bit20 is used to indicate the
+                * ADMA2 capability of esdhc, but this bit is messed up on
+                * some SOCs (e.g. on MX25, MX35 this bit is set, but they
+                * don't actually support ADMA2). So set the BROKEN_ADMA
+                * uirk on MX25/35 platforms.
+                */
+
+               if (val & SDHCI_CAN_DO_ADMA1) {
+                       val &= ~SDHCI_CAN_DO_ADMA1;
+                       val |= SDHCI_CAN_DO_ADMA2;
+               }
+       }
+
+       if (unlikely(reg == SDHCI_INT_STATUS)) {
+               if (val & SDHCI_INT_VENDOR_SPEC_DMA_ERR) {
+                       val &= ~SDHCI_INT_VENDOR_SPEC_DMA_ERR;
+                       val |= SDHCI_INT_ADMA_ERROR;
+               }
+       }
+
        return val;
 }
 
@@ -179,13 +219,28 @@ static void esdhc_writel_le(struct sdhci_host *host, u32 val, int reg)
                        writel(v, host->ioaddr + SDHCI_VENDOR_SPEC);
        }
 
+       if (unlikely(reg == SDHCI_INT_ENABLE || reg == SDHCI_SIGNAL_ENABLE)) {
+               if (val & SDHCI_INT_ADMA_ERROR) {
+                       val &= ~SDHCI_INT_ADMA_ERROR;
+                       val |= SDHCI_INT_VENDOR_SPEC_DMA_ERR;
+               }
+       }
+
        writel(val, host->ioaddr + reg);
 }
 
 static u16 esdhc_readw_le(struct sdhci_host *host, int reg)
 {
-       if (unlikely(reg == SDHCI_HOST_VERSION))
-               reg ^= 2;
+       if (unlikely(reg == SDHCI_HOST_VERSION)) {
+               u16 val = readw(host->ioaddr + (reg ^ 2));
+               /*
+                * uSDHC supports SDHCI v3.0, but it's encoded as value
+                * 0x3 in host controller version register, which violates
+                * SDHCI_SPEC_300 definition.  Work it around here.
+                */
+               if ((val & SDHCI_SPEC_VER_MASK) == 3)
+                       return --val;
+       }
 
        return readw(host->ioaddr + reg);
 }
@@ -216,8 +271,17 @@ static void esdhc_writew_le(struct sdhci_host *host, u16 val, int reg)
                if ((host->cmd->opcode == MMC_STOP_TRANSMISSION)
                        && (imx_data->flags & ESDHC_FLAG_MULTIBLK_NO_INT))
                        val |= SDHCI_CMD_ABORTCMD;
-               writel(val << 16 | imx_data->scratchpad,
-                       host->ioaddr + SDHCI_TRANSFER_MODE);
+
+               if (is_imx6q_usdhc(imx_data)) {
+                       u32 m = readl(host->ioaddr + SDHCI_MIX_CTRL);
+                       m = imx_data->scratchpad | (m & 0xffff0000);
+                       writel(m, host->ioaddr + SDHCI_MIX_CTRL);
+                       writel(val << 16,
+                              host->ioaddr + SDHCI_TRANSFER_MODE);
+               } else {
+                       writel(val << 16 | imx_data->scratchpad,
+                              host->ioaddr + SDHCI_TRANSFER_MODE);
+               }
                return;
        case SDHCI_BLOCK_SIZE:
                val &= ~SDHCI_MAKE_BLKSZ(0x7, 0);
@@ -311,9 +375,10 @@ static struct sdhci_ops sdhci_esdhc_ops = {
 };
 
 static struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = {
-       .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_BROKEN_ADMA
+       .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_NO_HISPD_BIT
+                       | SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
+                       | SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC
                        | SDHCI_QUIRK_BROKEN_CARD_DETECTION,
-       /* ADMA has issues. Might be fixable */
        .ops = &sdhci_esdhc_ops,
 };
 
@@ -405,7 +470,8 @@ static int __devinit sdhci_esdhc_imx_probe(struct platform_device *pdev)
 
        if (is_imx25_esdhc(imx_data) || is_imx35_esdhc(imx_data))
                /* Fix errata ENGcm07207 present on i.MX25 and i.MX35 */
-               host->quirks |= SDHCI_QUIRK_NO_MULTIBLOCK;
+               host->quirks |= SDHCI_QUIRK_NO_MULTIBLOCK
+                       | SDHCI_QUIRK_BROKEN_ADMA;
 
        if (is_imx53_esdhc(imx_data))
                imx_data->flags |= ESDHC_FLAG_MULTIBLK_NO_INT;
index fe604df650112d7303433a98477afed7b4ba9a3e..59e9d003e5891c0f9d76b8788055399bb1c3c070 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Freescale eSDHC controller driver.
  *
- * Copyright (c) 2007 Freescale Semiconductor, Inc.
+ * Copyright (c) 2007, 2010 Freescale Semiconductor, Inc.
  * Copyright (c) 2009 MontaVista Software, Inc.
  *
  * Authors: Xiaobo Xie <X.Xie@freescale.com>
@@ -15,6 +15,7 @@
 
 #include <linux/io.h>
 #include <linux/delay.h>
+#include <linux/module.h>
 #include <linux/mmc/host.h>
 #include "sdhci-pltfm.h"
 #include "sdhci-esdhc.h"
 static u16 esdhc_readw(struct sdhci_host *host, int reg)
 {
        u16 ret;
+       int base = reg & ~0x3;
+       int shift = (reg & 0x2) * 8;
 
        if (unlikely(reg == SDHCI_HOST_VERSION))
-               ret = in_be16(host->ioaddr + reg);
+               ret = in_be32(host->ioaddr + base) & 0xffff;
        else
-               ret = sdhci_be32bs_readw(host, reg);
+               ret = (in_be32(host->ioaddr + base) >> shift) & 0xffff;
+       return ret;
+}
+
+static u8 esdhc_readb(struct sdhci_host *host, int reg)
+{
+       int base = reg & ~0x3;
+       int shift = (reg & 0x3) * 8;
+       u8 ret = (in_be32(host->ioaddr + base) >> shift) & 0xff;
        return ret;
 }
 
@@ -74,7 +85,7 @@ static unsigned int esdhc_of_get_min_clock(struct sdhci_host *host)
 static struct sdhci_ops sdhci_esdhc_ops = {
        .read_l = sdhci_be32bs_readl,
        .read_w = esdhc_readw,
-       .read_b = sdhci_be32bs_readb,
+       .read_b = esdhc_readb,
        .write_l = sdhci_be32bs_writel,
        .write_w = esdhc_writew,
        .write_b = esdhc_writeb,
index 735be131dca9613cc58cb3670ff7cc137323f6de..9b0d794a4f692911d05347fe917722635b96594b 100644 (file)
@@ -20,6 +20,7 @@
  */
 
 #include <linux/delay.h>
+#include <linux/module.h>
 #include <linux/mmc/host.h>
 #include "sdhci-pltfm.h"
 
index 26c528648f3cb53a32fefcd4cb92d5f5d3ff7b75..d833d9c2f7e338425262402af53d6e2f2b63e848 100644 (file)
@@ -14,6 +14,7 @@
 
 #include <linux/delay.h>
 #include <linux/highmem.h>
+#include <linux/module.h>
 #include <linux/pci.h>
 #include <linux/dma-mapping.h>
 #include <linux/slab.h>
@@ -21,6 +22,9 @@
 #include <linux/mmc/host.h>
 #include <linux/scatterlist.h>
 #include <linux/io.h>
+#include <linux/gpio.h>
+#include <linux/sfi.h>
+#include <linux/pm_runtime.h>
 
 #include "sdhci.h"
 
@@ -43,6 +47,7 @@ struct sdhci_pci_slot;
 
 struct sdhci_pci_fixes {
        unsigned int            quirks;
+       bool                    allow_runtime_pm;
 
        int                     (*probe) (struct sdhci_pci_chip *);
 
@@ -59,12 +64,16 @@ struct sdhci_pci_slot {
        struct sdhci_host       *host;
 
        int                     pci_bar;
+       int                     rst_n_gpio;
+       int                     cd_gpio;
+       int                     cd_irq;
 };
 
 struct sdhci_pci_chip {
        struct pci_dev          *pdev;
 
        unsigned int            quirks;
+       bool                    allow_runtime_pm;
        const struct sdhci_pci_fixes *fixes;
 
        int                     num_slots;      /* Slots on controller */
@@ -163,12 +172,129 @@ static int mrst_hc_probe(struct sdhci_pci_chip *chip)
        return 0;
 }
 
+/* Medfield eMMC hardware reset GPIOs */
+static int mfd_emmc0_rst_gpio = -EINVAL;
+static int mfd_emmc1_rst_gpio = -EINVAL;
+
+static int mfd_emmc_gpio_parse(struct sfi_table_header *table)
+{
+       struct sfi_table_simple *sb = (struct sfi_table_simple *)table;
+       struct sfi_gpio_table_entry *entry;
+       int i, num;
+
+       num = SFI_GET_NUM_ENTRIES(sb, struct sfi_gpio_table_entry);
+       entry = (struct sfi_gpio_table_entry *)sb->pentry;
+
+       for (i = 0; i < num; i++, entry++) {
+               if (!strncmp(entry->pin_name, "emmc0_rst", SFI_NAME_LEN))
+                       mfd_emmc0_rst_gpio = entry->pin_no;
+               else if (!strncmp(entry->pin_name, "emmc1_rst", SFI_NAME_LEN))
+                       mfd_emmc1_rst_gpio = entry->pin_no;
+       }
+
+       return 0;
+}
+
+#ifdef CONFIG_PM_RUNTIME
+
+static irqreturn_t mfd_sd_cd(int irq, void *dev_id)
+{
+       struct sdhci_pci_slot *slot = dev_id;
+       struct sdhci_host *host = slot->host;
+
+       mmc_detect_change(host->mmc, msecs_to_jiffies(200));
+       return IRQ_HANDLED;
+}
+
+#define MFLD_SD_CD_PIN 69
+
+static int mfd_sd_probe_slot(struct sdhci_pci_slot *slot)
+{
+       int err, irq, gpio = MFLD_SD_CD_PIN;
+
+       slot->cd_gpio = -EINVAL;
+       slot->cd_irq = -EINVAL;
+
+       err = gpio_request(gpio, "sd_cd");
+       if (err < 0)
+               goto out;
+
+       err = gpio_direction_input(gpio);
+       if (err < 0)
+               goto out_free;
+
+       irq = gpio_to_irq(gpio);
+       if (irq < 0)
+               goto out_free;
+
+       err = request_irq(irq, mfd_sd_cd, IRQF_TRIGGER_RISING |
+                         IRQF_TRIGGER_FALLING, "sd_cd", slot);
+       if (err)
+               goto out_free;
+
+       slot->cd_gpio = gpio;
+       slot->cd_irq = irq;
+       slot->host->quirks2 |= SDHCI_QUIRK2_OWN_CARD_DETECTION;
+
+       return 0;
+
+out_free:
+       gpio_free(gpio);
+out:
+       dev_warn(&slot->chip->pdev->dev, "failed to setup card detect wake up\n");
+       return 0;
+}
+
+static void mfd_sd_remove_slot(struct sdhci_pci_slot *slot, int dead)
+{
+       if (slot->cd_irq >= 0)
+               free_irq(slot->cd_irq, slot);
+       gpio_free(slot->cd_gpio);
+}
+
+#else
+
+#define mfd_sd_probe_slot      NULL
+#define mfd_sd_remove_slot     NULL
+
+#endif
+
 static int mfd_emmc_probe_slot(struct sdhci_pci_slot *slot)
 {
-       slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA;
+       const char *name = NULL;
+       int gpio = -EINVAL;
+
+       sfi_table_parse(SFI_SIG_GPIO, NULL, NULL, mfd_emmc_gpio_parse);
+
+       switch (slot->chip->pdev->device) {
+       case PCI_DEVICE_ID_INTEL_MFD_EMMC0:
+               gpio = mfd_emmc0_rst_gpio;
+               name = "eMMC0_reset";
+               break;
+       case PCI_DEVICE_ID_INTEL_MFD_EMMC1:
+               gpio = mfd_emmc1_rst_gpio;
+               name = "eMMC1_reset";
+               break;
+       }
+
+       if (!gpio_request(gpio, name)) {
+               gpio_direction_output(gpio, 1);
+               slot->rst_n_gpio = gpio;
+               slot->host->mmc->caps |= MMC_CAP_HW_RESET;
+       }
+
+       slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE;
+
+       slot->host->mmc->caps2 = MMC_CAP2_BOOTPART_NOACC;
+
        return 0;
 }
 
+static void mfd_emmc_remove_slot(struct sdhci_pci_slot *slot, int dead)
+{
+       gpio_free(slot->rst_n_gpio);
+}
+
 static const struct sdhci_pci_fixes sdhci_intel_mrst_hc0 = {
        .quirks         = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT,
        .probe_slot     = mrst_hc_probe_slot,
@@ -181,15 +307,21 @@ static const struct sdhci_pci_fixes sdhci_intel_mrst_hc1_hc2 = {
 
 static const struct sdhci_pci_fixes sdhci_intel_mfd_sd = {
        .quirks         = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
+       .allow_runtime_pm = true,
+       .probe_slot     = mfd_sd_probe_slot,
+       .remove_slot    = mfd_sd_remove_slot,
 };
 
 static const struct sdhci_pci_fixes sdhci_intel_mfd_sdio = {
        .quirks         = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
+       .allow_runtime_pm = true,
 };
 
 static const struct sdhci_pci_fixes sdhci_intel_mfd_emmc = {
        .quirks         = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
+       .allow_runtime_pm = true,
        .probe_slot     = mfd_emmc_probe_slot,
+       .remove_slot    = mfd_emmc_remove_slot,
 };
 
 /* O2Micro extra registers */
@@ -832,9 +964,25 @@ static int sdhci_pci_8bit_width(struct sdhci_host *host, int width)
        return 0;
 }
 
+static void sdhci_pci_hw_reset(struct sdhci_host *host)
+{
+       struct sdhci_pci_slot *slot = sdhci_priv(host);
+       int rst_n_gpio = slot->rst_n_gpio;
+
+       if (!gpio_is_valid(rst_n_gpio))
+               return;
+       gpio_set_value_cansleep(rst_n_gpio, 0);
+       /* For eMMC, minimum is 1us but give it 10us for good measure */
+       udelay(10);
+       gpio_set_value_cansleep(rst_n_gpio, 1);
+       /* For eMMC, minimum is 200us but give it 300us for good measure */
+       usleep_range(300, 1000);
+}
+
 static struct sdhci_ops sdhci_pci_ops = {
        .enable_dma     = sdhci_pci_enable_dma,
        .platform_8bit_width    = sdhci_pci_8bit_width,
+       .hw_reset               = sdhci_pci_hw_reset,
 };
 
 /*****************************************************************************\
@@ -944,6 +1092,95 @@ static int sdhci_pci_resume(struct pci_dev *pdev)
 
 #endif /* CONFIG_PM */
 
+#ifdef CONFIG_PM_RUNTIME
+
+static int sdhci_pci_runtime_suspend(struct device *dev)
+{
+       struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
+       struct sdhci_pci_chip *chip;
+       struct sdhci_pci_slot *slot;
+       pm_message_t state = { .event = PM_EVENT_SUSPEND };
+       int i, ret;
+
+       chip = pci_get_drvdata(pdev);
+       if (!chip)
+               return 0;
+
+       for (i = 0; i < chip->num_slots; i++) {
+               slot = chip->slots[i];
+               if (!slot)
+                       continue;
+
+               ret = sdhci_runtime_suspend_host(slot->host);
+
+               if (ret) {
+                       for (i--; i >= 0; i--)
+                               sdhci_runtime_resume_host(chip->slots[i]->host);
+                       return ret;
+               }
+       }
+
+       if (chip->fixes && chip->fixes->suspend) {
+               ret = chip->fixes->suspend(chip, state);
+               if (ret) {
+                       for (i = chip->num_slots - 1; i >= 0; i--)
+                               sdhci_runtime_resume_host(chip->slots[i]->host);
+                       return ret;
+               }
+       }
+
+       return 0;
+}
+
+static int sdhci_pci_runtime_resume(struct device *dev)
+{
+       struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
+       struct sdhci_pci_chip *chip;
+       struct sdhci_pci_slot *slot;
+       int i, ret;
+
+       chip = pci_get_drvdata(pdev);
+       if (!chip)
+               return 0;
+
+       if (chip->fixes && chip->fixes->resume) {
+               ret = chip->fixes->resume(chip);
+               if (ret)
+                       return ret;
+       }
+
+       for (i = 0; i < chip->num_slots; i++) {
+               slot = chip->slots[i];
+               if (!slot)
+                       continue;
+
+               ret = sdhci_runtime_resume_host(slot->host);
+               if (ret)
+                       return ret;
+       }
+
+       return 0;
+}
+
+static int sdhci_pci_runtime_idle(struct device *dev)
+{
+       return 0;
+}
+
+#else
+
+#define sdhci_pci_runtime_suspend      NULL
+#define sdhci_pci_runtime_resume       NULL
+#define sdhci_pci_runtime_idle         NULL
+
+#endif
+
+static const struct dev_pm_ops sdhci_pci_pm_ops = {
+       .runtime_suspend = sdhci_pci_runtime_suspend,
+       .runtime_resume = sdhci_pci_runtime_resume,
+       .runtime_idle = sdhci_pci_runtime_idle,
+};
+
 /*****************************************************************************\
  *                                                                           *
  * Device probing/removal                                                    *
@@ -988,6 +1225,7 @@ static struct sdhci_pci_slot * __devinit sdhci_pci_probe_slot(
        slot->chip = chip;
        slot->host = host;
        slot->pci_bar = bar;
+       slot->rst_n_gpio = -EINVAL;
 
        host->hw_name = "PCI";
        host->ops = &sdhci_pci_ops;
@@ -1058,6 +1296,21 @@ static void sdhci_pci_remove_slot(struct sdhci_pci_slot *slot)
        sdhci_free_host(slot->host);
 }
 
+static void __devinit sdhci_pci_runtime_pm_allow(struct device *dev)
+{
+       pm_runtime_put_noidle(dev);
+       pm_runtime_allow(dev);
+       pm_runtime_set_autosuspend_delay(dev, 50);
+       pm_runtime_use_autosuspend(dev);
+       pm_suspend_ignore_children(dev, 1);
+}
+
+static void __devexit sdhci_pci_runtime_pm_forbid(struct device *dev)
+{
+       pm_runtime_forbid(dev);
+       pm_runtime_get_noresume(dev);
+}
+
 static int __devinit sdhci_pci_probe(struct pci_dev *pdev,
                                     const struct pci_device_id *ent)
 {
@@ -1107,8 +1360,10 @@ static int __devinit sdhci_pci_probe(struct pci_dev *pdev,
 
        chip->pdev = pdev;
        chip->fixes = (const struct sdhci_pci_fixes *)ent->driver_data;
-       if (chip->fixes)
+       if (chip->fixes) {
                chip->quirks = chip->fixes->quirks;
+               chip->allow_runtime_pm = chip->fixes->allow_runtime_pm;
+       }
        chip->num_slots = slots;
 
        pci_set_drvdata(pdev, chip);
@@ -1133,6 +1388,9 @@ static int __devinit sdhci_pci_probe(struct pci_dev *pdev,
                chip->slots[i] = slot;
        }
 
+       if (chip->allow_runtime_pm)
+               sdhci_pci_runtime_pm_allow(&pdev->dev);
+
        return 0;
 
 free:
@@ -1152,6 +1410,9 @@ static void __devexit sdhci_pci_remove(struct pci_dev *pdev)
        chip = pci_get_drvdata(pdev);
 
        if (chip) {
+               if (chip->allow_runtime_pm)
+                       sdhci_pci_runtime_pm_forbid(&pdev->dev);
+
                for (i = 0; i < chip->num_slots; i++)
                        sdhci_pci_remove_slot(chip->slots[i]);
 
@@ -1169,6 +1430,9 @@ static struct pci_driver sdhci_driver = {
        .remove =       __devexit_p(sdhci_pci_remove),
        .suspend =      sdhci_pci_suspend,
        .resume =       sdhci_pci_resume,
+       .driver =       {
+               .pm =   &sdhci_pci_pm_ops
+       },
 };
 
 /*****************************************************************************\
index 6414efeddca0bb4475cd2fafa4d201dd2af77747..a9e12ea05583bfe3da78ef48f5442c3294367ff5 100644 (file)
@@ -29,6 +29,7 @@
  */
 
 #include <linux/err.h>
+#include <linux/module.h>
 #include <linux/of.h>
 #ifdef CONFIG_PPC
 #include <asm/machdep.h>
index 38f58994f79a816e353717c8b69bdb3b409fbe0e..d4bf6d30c7baa3ea5a6c6bb1abc01d58e41ad853 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/init.h>
 #include <linux/platform_device.h>
 #include <linux/clk.h>
+#include <linux/module.h>
 #include <linux/io.h>
 #include <linux/gpio.h>
 #include <linux/mmc/card.h>
@@ -59,7 +60,7 @@ static void pxav2_set_private_registers(struct sdhci_host *host, u8 mask)
                 * tune timing of read data/command when crc error happen
                 * no performance impact
                 */
-               if (pdata->clk_delay_sel == 1) {
+               if (pdata && pdata->clk_delay_sel == 1) {
                        tmp = readw(host->ioaddr + SD_CLOCK_BURST_SIZE_SETUP);
 
                        tmp &= ~(SDCLK_DELAY_MASK << SDCLK_DELAY_SHIFT);
@@ -71,7 +72,7 @@ static void pxav2_set_private_registers(struct sdhci_host *host, u8 mask)
                        writew(tmp, host->ioaddr + SD_CLOCK_BURST_SIZE_SETUP);
                }
 
-               if (pdata->flags & PXA_FLAG_ENABLE_CLOCK_GATING) {
+               if (pdata && (pdata->flags & PXA_FLAG_ENABLE_CLOCK_GATING)) {
                        tmp = readw(host->ioaddr + SD_FIFO_PARAM);
                        tmp &= ~CLK_GATE_SETTING_BITS;
                        writew(tmp, host->ioaddr + SD_FIFO_PARAM);
index fc7e4a51562934064bf4345bbe0851461d011362..cff4ad3e7a59c94c599716bfcf3bf63b0f28d3d7 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/platform_data/pxa_sdhci.h>
 #include <linux/slab.h>
 #include <linux/delay.h>
+#include <linux/module.h>
 #include "sdhci.h"
 #include "sdhci-pltfm.h"
 
index fe886d6c474a41718fb4b388c90c14ad26bf823e..3d00e722efc9cec34e9cbdd1807863326f58e828 100644 (file)
@@ -203,17 +203,23 @@ static void sdhci_s3c_set_clock(struct sdhci_host *host, unsigned int clock)
                writel(ctrl, host->ioaddr + S3C_SDHCI_CONTROL2);
        }
 
-       /* reconfigure the hardware for new clock rate */
-
-       {
-               struct mmc_ios ios;
-
-               ios.clock = clock;
-
-               if (ourhost->pdata->cfg_card)
-                       (ourhost->pdata->cfg_card)(ourhost->pdev, host->ioaddr,
-                                                  &ios, NULL);
-       }
+       /* reprogram default hardware configuration */
+       writel(S3C64XX_SDHCI_CONTROL4_DRIVE_9mA,
+               host->ioaddr + S3C64XX_SDHCI_CONTROL4);
+
+       ctrl = readl(host->ioaddr + S3C_SDHCI_CONTROL2);
+       ctrl |= (S3C64XX_SDHCI_CTRL2_ENSTAASYNCCLR |
+                 S3C64XX_SDHCI_CTRL2_ENCMDCNFMSK |
+                 S3C_SDHCI_CTRL2_ENFBCLKRX |
+                 S3C_SDHCI_CTRL2_DFCNT_NONE |
+                 S3C_SDHCI_CTRL2_ENCLKOUTHOLD);
+       writel(ctrl, host->ioaddr + S3C_SDHCI_CONTROL2);
+
+       /* reconfigure the controller for new clock rate */
+       ctrl = (S3C_SDHCI_CTRL3_FCSEL1 | S3C_SDHCI_CTRL3_FCSEL0);
+       if (clock < 25 * 1000000)
+               ctrl |= (S3C_SDHCI_CTRL3_FCSEL3 | S3C_SDHCI_CTRL3_FCSEL2);
+       writel(ctrl, host->ioaddr + S3C_SDHCI_CONTROL3);
 }
 
 /**
@@ -561,8 +567,10 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
 
  err_req_regs:
        for (ptr = 0; ptr < MAX_BUS_CLK; ptr++) {
-               clk_disable(sc->clk_bus[ptr]);
-               clk_put(sc->clk_bus[ptr]);
+               if (sc->clk_bus[ptr]) {
+                       clk_disable(sc->clk_bus[ptr]);
+                       clk_put(sc->clk_bus[ptr]);
+               }
        }
 
  err_no_busclks:
index 60a4c97d3d18f9deba2d46abde3cb26e4ffffef4..63cc8b6a1c9e6335113f67b5dd84766819b7cb80 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/delay.h>
 #include <linux/gpio.h>
 #include <linux/highmem.h>
+#include <linux/module.h>
 #include <linux/interrupt.h>
 #include <linux/irq.h>
 #include <linux/platform_device.h>
@@ -177,8 +178,6 @@ static int __devinit sdhci_probe(struct platform_device *pdev)
                                        sdhci->data->card_power_gpio);
                        goto err_pgpio_direction;
                }
-
-               gpio_set_value(sdhci->data->card_power_gpio, 1);
        }
 
        if (sdhci->data->card_int_gpio >= 0) {
index 21b00cefae63f2372dd14ee96453bc9c6f68bd6e..067a4cded9cf7b592938aa24b306679c5038141a 100644 (file)
 #include <linux/platform_device.h>
 #include <linux/clk.h>
 #include <linux/io.h>
+#include <linux/of.h>
+#include <linux/of_gpio.h>
 #include <linux/gpio.h>
 #include <linux/mmc/card.h>
 #include <linux/mmc/host.h>
+#include <linux/module.h>
 
 #include <asm/gpio.h>
 
@@ -75,10 +78,8 @@ static void tegra_sdhci_writel(struct sdhci_host *host, u32 val, int reg)
 
 static unsigned int tegra_sdhci_get_ro(struct sdhci_host *sdhci)
 {
-       struct platform_device *pdev = to_platform_device(mmc_dev(sdhci->mmc));
-       struct tegra_sdhci_platform_data *plat;
-
-       plat = pdev->dev.platform_data;
+       struct sdhci_pltfm_host *pltfm_host = sdhci_priv(sdhci);
+       struct tegra_sdhci_platform_data *plat = pltfm_host->priv;
 
        if (!gpio_is_valid(plat->wp_gpio))
                return -1;
@@ -96,12 +97,10 @@ static irqreturn_t carddetect_irq(int irq, void *data)
 
 static int tegra_sdhci_8bit(struct sdhci_host *host, int bus_width)
 {
-       struct platform_device *pdev = to_platform_device(mmc_dev(host->mmc));
-       struct tegra_sdhci_platform_data *plat;
+       struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
+       struct tegra_sdhci_platform_data *plat = pltfm_host->priv;
        u32 ctrl;
 
-       plat = pdev->dev.platform_data;
-
        ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
        if (plat->is_8bit && bus_width == MMC_BUS_WIDTH_8) {
                ctrl &= ~SDHCI_CTRL_4BITBUS;
@@ -133,6 +132,36 @@ static struct sdhci_pltfm_data sdhci_tegra_pdata = {
        .ops  = &tegra_sdhci_ops,
 };
 
+static const struct of_device_id sdhci_tegra_dt_match[] __devinitdata = {
+       { .compatible = "nvidia,tegra20-sdhci", },
+       {}
+};
+MODULE_DEVICE_TABLE(of, sdhci_dt_ids);
+
+static struct tegra_sdhci_platform_data * __devinit sdhci_tegra_dt_parse_pdata(
+                                               struct platform_device *pdev)
+{
+       struct tegra_sdhci_platform_data *plat;
+       struct device_node *np = pdev->dev.of_node;
+
+       if (!np)
+               return NULL;
+
+       plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
+       if (!plat) {
+               dev_err(&pdev->dev, "Can't allocate platform data\n");
+               return NULL;
+       }
+
+       plat->cd_gpio = of_get_named_gpio(np, "cd-gpios", 0);
+       plat->wp_gpio = of_get_named_gpio(np, "wp-gpios", 0);
+       plat->power_gpio = of_get_named_gpio(np, "power-gpios", 0);
+       if (of_find_property(np, "support-8bit", NULL))
+               plat->is_8bit = 1;
+
+       return plat;
+}
+
 static int __devinit sdhci_tegra_probe(struct platform_device *pdev)
 {
        struct sdhci_pltfm_host *pltfm_host;
@@ -149,12 +178,17 @@ static int __devinit sdhci_tegra_probe(struct platform_device *pdev)
 
        plat = pdev->dev.platform_data;
 
+       if (plat == NULL)
+               plat = sdhci_tegra_dt_parse_pdata(pdev);
+
        if (plat == NULL) {
                dev_err(mmc_dev(host->mmc), "missing platform data\n");
                rc = -ENXIO;
                goto err_no_plat;
        }
 
+       pltfm_host->priv = plat;
+
        if (gpio_is_valid(plat->power_gpio)) {
                rc = gpio_request(plat->power_gpio, "sdhci_power");
                if (rc) {
@@ -249,13 +283,11 @@ static int __devexit sdhci_tegra_remove(struct platform_device *pdev)
 {
        struct sdhci_host *host = platform_get_drvdata(pdev);
        struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
-       struct tegra_sdhci_platform_data *plat;
+       struct tegra_sdhci_platform_data *plat = pltfm_host->priv;
        int dead = (readl(host->ioaddr + SDHCI_INT_STATUS) == 0xffffffff);
 
        sdhci_remove_host(host, dead);
 
-       plat = pdev->dev.platform_data;
-
        if (gpio_is_valid(plat->wp_gpio)) {
                tegra_gpio_disable(plat->wp_gpio);
                gpio_free(plat->wp_gpio);
@@ -284,6 +316,7 @@ static struct platform_driver sdhci_tegra_driver = {
        .driver         = {
                .name   = "sdhci-tegra",
                .owner  = THIS_MODULE,
+               .of_match_table = sdhci_tegra_dt_match,
        },
        .probe          = sdhci_tegra_probe,
        .remove         = __devexit_p(sdhci_tegra_remove),
index 0e02cc1df12e40b66b4302ee9af6d69a5f9947fe..6d8eea3235411e875250b3a8b7f588c2290304ec 100644 (file)
 #include <linux/delay.h>
 #include <linux/highmem.h>
 #include <linux/io.h>
+#include <linux/module.h>
 #include <linux/dma-mapping.h>
 #include <linux/slab.h>
 #include <linux/scatterlist.h>
 #include <linux/regulator/consumer.h>
+#include <linux/pm_runtime.h>
 
 #include <linux/leds.h>
 
@@ -41,6 +43,7 @@
 #define MAX_TUNING_LOOP 40
 
 static unsigned int debug_quirks = 0;
+static unsigned int debug_quirks2;
 
 static void sdhci_finish_data(struct sdhci_host *);
 
@@ -49,53 +52,67 @@ static void sdhci_finish_command(struct sdhci_host *);
 static int sdhci_execute_tuning(struct mmc_host *mmc);
 static void sdhci_tuning_timer(unsigned long data);
 
+#ifdef CONFIG_PM_RUNTIME
+static int sdhci_runtime_pm_get(struct sdhci_host *host);
+static int sdhci_runtime_pm_put(struct sdhci_host *host);
+#else
+static inline int sdhci_runtime_pm_get(struct sdhci_host *host)
+{
+       return 0;
+}
+static inline int sdhci_runtime_pm_put(struct sdhci_host *host)
+{
+       return 0;
+}
+#endif
+
 static void sdhci_dumpregs(struct sdhci_host *host)
 {
-       printk(KERN_DEBUG DRIVER_NAME ": =========== REGISTER DUMP (%s)===========\n",
+       pr_debug(DRIVER_NAME ": =========== REGISTER DUMP (%s)===========\n",
                mmc_hostname(host->mmc));
 
-       printk(KERN_DEBUG DRIVER_NAME ": Sys addr: 0x%08x | Version:  0x%08x\n",
+       pr_debug(DRIVER_NAME ": Sys addr: 0x%08x | Version:  0x%08x\n",
                sdhci_readl(host, SDHCI_DMA_ADDRESS),
                sdhci_readw(host, SDHCI_HOST_VERSION));
-       printk(KERN_DEBUG DRIVER_NAME ": Blk size: 0x%08x | Blk cnt:  0x%08x\n",
+       pr_debug(DRIVER_NAME ": Blk size: 0x%08x | Blk cnt:  0x%08x\n",
                sdhci_readw(host, SDHCI_BLOCK_SIZE),
                sdhci_readw(host, SDHCI_BLOCK_COUNT));
-       printk(KERN_DEBUG DRIVER_NAME ": Argument: 0x%08x | Trn mode: 0x%08x\n",
+       pr_debug(DRIVER_NAME ": Argument: 0x%08x | Trn mode: 0x%08x\n",
                sdhci_readl(host, SDHCI_ARGUMENT),
                sdhci_readw(host, SDHCI_TRANSFER_MODE));
-       printk(KERN_DEBUG DRIVER_NAME ": Present:  0x%08x | Host ctl: 0x%08x\n",
+       pr_debug(DRIVER_NAME ": Present:  0x%08x | Host ctl: 0x%08x\n",
                sdhci_readl(host, SDHCI_PRESENT_STATE),
                sdhci_readb(host, SDHCI_HOST_CONTROL));
-       printk(KERN_DEBUG DRIVER_NAME ": Power:    0x%08x | Blk gap:  0x%08x\n",
+       pr_debug(DRIVER_NAME ": Power:    0x%08x | Blk gap:  0x%08x\n",
                sdhci_readb(host, SDHCI_POWER_CONTROL),
                sdhci_readb(host, SDHCI_BLOCK_GAP_CONTROL));
-       printk(KERN_DEBUG DRIVER_NAME ": Wake-up:  0x%08x | Clock:    0x%08x\n",
+       pr_debug(DRIVER_NAME ": Wake-up:  0x%08x | Clock:    0x%08x\n",
                sdhci_readb(host, SDHCI_WAKE_UP_CONTROL),
                sdhci_readw(host, SDHCI_CLOCK_CONTROL));
-       printk(KERN_DEBUG DRIVER_NAME ": Timeout:  0x%08x | Int stat: 0x%08x\n",
+       pr_debug(DRIVER_NAME ": Timeout:  0x%08x | Int stat: 0x%08x\n",
                sdhci_readb(host, SDHCI_TIMEOUT_CONTROL),
                sdhci_readl(host, SDHCI_INT_STATUS));
-       printk(KERN_DEBUG DRIVER_NAME ": Int enab: 0x%08x | Sig enab: 0x%08x\n",
+       pr_debug(DRIVER_NAME ": Int enab: 0x%08x | Sig enab: 0x%08x\n",
                sdhci_readl(host, SDHCI_INT_ENABLE),
                sdhci_readl(host, SDHCI_SIGNAL_ENABLE));
-       printk(KERN_DEBUG DRIVER_NAME ": AC12 err: 0x%08x | Slot int: 0x%08x\n",
+       pr_debug(DRIVER_NAME ": AC12 err: 0x%08x | Slot int: 0x%08x\n",
                sdhci_readw(host, SDHCI_ACMD12_ERR),
                sdhci_readw(host, SDHCI_SLOT_INT_STATUS));
-       printk(KERN_DEBUG DRIVER_NAME ": Caps:     0x%08x | Caps_1:   0x%08x\n",
+       pr_debug(DRIVER_NAME ": Caps:     0x%08x | Caps_1:   0x%08x\n",
                sdhci_readl(host, SDHCI_CAPABILITIES),
                sdhci_readl(host, SDHCI_CAPABILITIES_1));
-       printk(KERN_DEBUG DRIVER_NAME ": Cmd:      0x%08x | Max curr: 0x%08x\n",
+       pr_debug(DRIVER_NAME ": Cmd:      0x%08x | Max curr: 0x%08x\n",
                sdhci_readw(host, SDHCI_COMMAND),
                sdhci_readl(host, SDHCI_MAX_CURRENT));
-       printk(KERN_DEBUG DRIVER_NAME ": Host ctl2: 0x%08x\n",
+       pr_debug(DRIVER_NAME ": Host ctl2: 0x%08x\n",
                sdhci_readw(host, SDHCI_HOST_CONTROL2));
 
        if (host->flags & SDHCI_USE_ADMA)
-               printk(KERN_DEBUG DRIVER_NAME ": ADMA Err: 0x%08x | ADMA Ptr: 0x%08x\n",
+               pr_debug(DRIVER_NAME ": ADMA Err: 0x%08x | ADMA Ptr: 0x%08x\n",
                       readl(host->ioaddr + SDHCI_ADMA_ERROR),
                       readl(host->ioaddr + SDHCI_ADMA_ADDRESS));
 
-       printk(KERN_DEBUG DRIVER_NAME ": ===========================================\n");
+       pr_debug(DRIVER_NAME ": ===========================================\n");
 }
 
 /*****************************************************************************\
@@ -132,6 +149,9 @@ static void sdhci_set_card_detection(struct sdhci_host *host, bool enable)
        if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)
                return;
 
+       if (host->quirks2 & SDHCI_QUIRK2_OWN_CARD_DETECTION)
+               return;
+
        present = sdhci_readl(host, SDHCI_PRESENT_STATE) &
                              SDHCI_CARD_PRESENT;
        irqs = present ? SDHCI_INT_CARD_REMOVE : SDHCI_INT_CARD_INSERT;
@@ -180,7 +200,7 @@ static void sdhci_reset(struct sdhci_host *host, u8 mask)
        /* hw clears the bit when it's done */
        while (sdhci_readb(host, SDHCI_SOFTWARE_RESET) & mask) {
                if (timeout == 0) {
-                       printk(KERN_ERR "%s: Reset 0x%x never completed.\n",
+                       pr_err("%s: Reset 0x%x never completed.\n",
                                mmc_hostname(host->mmc), (int)mask);
                        sdhci_dumpregs(host);
                        return;
@@ -251,11 +271,14 @@ static void sdhci_led_control(struct led_classdev *led,
 
        spin_lock_irqsave(&host->lock, flags);
 
+       if (host->runtime_suspended)
+               goto out;
+
        if (brightness == LED_OFF)
                sdhci_deactivate_led(host);
        else
                sdhci_activate_led(host);
-
+out:
        spin_unlock_irqrestore(&host->lock, flags);
 }
 #endif
@@ -654,7 +677,7 @@ static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_command *cmd)
        }
 
        if (count >= 0xF) {
-               printk(KERN_WARNING "%s: Too large timeout requested for CMD%d!\n",
+               pr_warning("%s: Too large timeout requested for CMD%d!\n",
                       mmc_hostname(host->mmc), cmd->opcode);
                count = 0xE;
        }
@@ -949,7 +972,7 @@ static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
 
        while (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) {
                if (timeout == 0) {
-                       printk(KERN_ERR "%s: Controller never released "
+                       pr_err("%s: Controller never released "
                                "inhibit bit(s).\n", mmc_hostname(host->mmc));
                        sdhci_dumpregs(host);
                        cmd->error = -EIO;
@@ -971,7 +994,7 @@ static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
        sdhci_set_transfer_mode(host, cmd);
 
        if ((cmd->flags & MMC_RSP_136) && (cmd->flags & MMC_RSP_BUSY)) {
-               printk(KERN_ERR "%s: Unsupported response type!\n",
+               pr_err("%s: Unsupported response type!\n",
                        mmc_hostname(host->mmc));
                cmd->error = -EINVAL;
                tasklet_schedule(&host->finish_tasklet);
@@ -1121,7 +1144,7 @@ static void sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
        while (!((clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL))
                & SDHCI_CLOCK_INT_STABLE)) {
                if (timeout == 0) {
-                       printk(KERN_ERR "%s: Internal clock never "
+                       pr_err("%s: Internal clock never "
                                "stabilised.\n", mmc_hostname(host->mmc));
                        sdhci_dumpregs(host);
                        return;
@@ -1209,6 +1232,8 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
 
        host = mmc_priv(mmc);
 
+       sdhci_runtime_pm_get(host);
+
        spin_lock_irqsave(&host->lock, flags);
 
        WARN_ON(host->mrq != NULL);
@@ -1269,14 +1294,11 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
        spin_unlock_irqrestore(&host->lock, flags);
 }
 
-static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
+static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios)
 {
-       struct sdhci_host *host;
        unsigned long flags;
        u8 ctrl;
 
-       host = mmc_priv(mmc);
-
        spin_lock_irqsave(&host->lock, flags);
 
        if (host->flags & SDHCI_DEVICE_DEAD)
@@ -1426,7 +1448,16 @@ out:
        spin_unlock_irqrestore(&host->lock, flags);
 }
 
-static int check_ro(struct sdhci_host *host)
+static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
+{
+       struct sdhci_host *host = mmc_priv(mmc);
+
+       sdhci_runtime_pm_get(host);
+       sdhci_do_set_ios(host, ios);
+       sdhci_runtime_pm_put(host);
+}
+
+static int sdhci_check_ro(struct sdhci_host *host)
 {
        unsigned long flags;
        int is_readonly;
@@ -1450,19 +1481,16 @@ static int check_ro(struct sdhci_host *host)
 
 #define SAMPLE_COUNT   5
 
-static int sdhci_get_ro(struct mmc_host *mmc)
+static int sdhci_do_get_ro(struct sdhci_host *host)
 {
-       struct sdhci_host *host;
        int i, ro_count;
 
-       host = mmc_priv(mmc);
-
        if (!(host->quirks & SDHCI_QUIRK_UNSTABLE_RO_DETECT))
-               return check_ro(host);
+               return sdhci_check_ro(host);
 
        ro_count = 0;
        for (i = 0; i < SAMPLE_COUNT; i++) {
-               if (check_ro(host)) {
+               if (sdhci_check_ro(host)) {
                        if (++ro_count > SAMPLE_COUNT / 2)
                                return 1;
                }
@@ -1471,38 +1499,64 @@ static int sdhci_get_ro(struct mmc_host *mmc)
        return 0;
 }
 
-static void sdhci_enable_sdio_irq(struct mmc_host *mmc, int enable)
+static void sdhci_hw_reset(struct mmc_host *mmc)
 {
-       struct sdhci_host *host;
-       unsigned long flags;
+       struct sdhci_host *host = mmc_priv(mmc);
 
-       host = mmc_priv(mmc);
+       if (host->ops && host->ops->hw_reset)
+               host->ops->hw_reset(host);
+}
 
-       spin_lock_irqsave(&host->lock, flags);
+static int sdhci_get_ro(struct mmc_host *mmc)
+{
+       struct sdhci_host *host = mmc_priv(mmc);
+       int ret;
 
+       sdhci_runtime_pm_get(host);
+       ret = sdhci_do_get_ro(host);
+       sdhci_runtime_pm_put(host);
+       return ret;
+}
+
+static void sdhci_enable_sdio_irq_nolock(struct sdhci_host *host, int enable)
+{
        if (host->flags & SDHCI_DEVICE_DEAD)
                goto out;
 
+       if (enable)
+               host->flags |= SDHCI_SDIO_IRQ_ENABLED;
+       else
+               host->flags &= ~SDHCI_SDIO_IRQ_ENABLED;
+
+       /* SDIO IRQ will be enabled as appropriate in runtime resume */
+       if (host->runtime_suspended)
+               goto out;
+
        if (enable)
                sdhci_unmask_irqs(host, SDHCI_INT_CARD_INT);
        else
                sdhci_mask_irqs(host, SDHCI_INT_CARD_INT);
 out:
        mmiowb();
+}
+
+static void sdhci_enable_sdio_irq(struct mmc_host *mmc, int enable)
+{
+       struct sdhci_host *host = mmc_priv(mmc);
+       unsigned long flags;
 
+       spin_lock_irqsave(&host->lock, flags);
+       sdhci_enable_sdio_irq_nolock(host, enable);
        spin_unlock_irqrestore(&host->lock, flags);
 }
 
-static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc,
-       struct mmc_ios *ios)
+static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host,
+                                               struct mmc_ios *ios)
 {
-       struct sdhci_host *host;
        u8 pwr;
        u16 clk, ctrl;
        u32 present_state;
 
-       host = mmc_priv(mmc);
-
        /*
         * Signal Voltage Switching is only applicable for Host Controllers
         * v3.00 and above.
@@ -1528,7 +1582,7 @@ static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc,
                if (!(ctrl & SDHCI_CTRL_VDD_180))
                        return 0;
                else {
-                       printk(KERN_INFO DRIVER_NAME ": Switching to 3.3V "
+                       pr_info(DRIVER_NAME ": Switching to 3.3V "
                                "signalling voltage failed\n");
                        return -EIO;
                }
@@ -1587,7 +1641,7 @@ static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc,
                pwr |= SDHCI_POWER_ON;
                sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);
 
-               printk(KERN_INFO DRIVER_NAME ": Switching to 1.8V signalling "
+               pr_info(DRIVER_NAME ": Switching to 1.8V signalling "
                        "voltage failed, retrying with S18R set to 0\n");
                return -EAGAIN;
        } else
@@ -1595,6 +1649,20 @@ static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc,
                return 0;
 }
 
+static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc,
+       struct mmc_ios *ios)
+{
+       struct sdhci_host *host = mmc_priv(mmc);
+       int err;
+
+       if (host->version < SDHCI_SPEC_300)
+               return 0;
+       sdhci_runtime_pm_get(host);
+       err = sdhci_do_start_signal_voltage_switch(host, ios);
+       sdhci_runtime_pm_put(host);
+       return err;
+}
+
 static int sdhci_execute_tuning(struct mmc_host *mmc)
 {
        struct sdhci_host *host;
@@ -1606,6 +1674,7 @@ static int sdhci_execute_tuning(struct mmc_host *mmc)
 
        host = mmc_priv(mmc);
 
+       sdhci_runtime_pm_get(host);
        disable_irq(host->irq);
        spin_lock(&host->lock);
 
@@ -1623,6 +1692,7 @@ static int sdhci_execute_tuning(struct mmc_host *mmc)
        else {
                spin_unlock(&host->lock);
                enable_irq(host->irq);
+               sdhci_runtime_pm_put(host);
                return 0;
        }
 
@@ -1648,7 +1718,7 @@ static int sdhci_execute_tuning(struct mmc_host *mmc)
        timeout = 150;
        do {
                struct mmc_command cmd = {0};
-               struct mmc_request mrq = {0};
+               struct mmc_request mrq = {NULL};
 
                if (!tuning_loop_counter && !timeout)
                        break;
@@ -1694,7 +1764,7 @@ static int sdhci_execute_tuning(struct mmc_host *mmc)
                spin_lock(&host->lock);
 
                if (!host->tuning_done) {
-                       printk(KERN_INFO DRIVER_NAME ": Timeout waiting for "
+                       pr_info(DRIVER_NAME ": Timeout waiting for "
                                "Buffer Read Ready interrupt during tuning "
                                "procedure, falling back to fixed sampling "
                                "clock\n");
@@ -1724,7 +1794,7 @@ static int sdhci_execute_tuning(struct mmc_host *mmc)
                sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
        } else {
                if (!(ctrl & SDHCI_CTRL_TUNED_CLK)) {
-                       printk(KERN_INFO DRIVER_NAME ": Tuning procedure"
+                       pr_info(DRIVER_NAME ": Tuning procedure"
                                " failed, falling back to fixed sampling"
                                " clock\n");
                        err = -EIO;
@@ -1766,18 +1836,16 @@ out:
        sdhci_clear_set_irqs(host, SDHCI_INT_DATA_AVAIL, ier);
        spin_unlock(&host->lock);
        enable_irq(host->irq);
+       sdhci_runtime_pm_put(host);
 
        return err;
 }
 
-static void sdhci_enable_preset_value(struct mmc_host *mmc, bool enable)
+static void sdhci_do_enable_preset_value(struct sdhci_host *host, bool enable)
 {
-       struct sdhci_host *host;
        u16 ctrl;
        unsigned long flags;
 
-       host = mmc_priv(mmc);
-
        /* Host Controller v3.00 defines preset value registers */
        if (host->version < SDHCI_SPEC_300)
                return;
@@ -1793,18 +1861,30 @@ static void sdhci_enable_preset_value(struct mmc_host *mmc, bool enable)
        if (enable && !(ctrl & SDHCI_CTRL_PRESET_VAL_ENABLE)) {
                ctrl |= SDHCI_CTRL_PRESET_VAL_ENABLE;
                sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
+               host->flags |= SDHCI_PV_ENABLED;
        } else if (!enable && (ctrl & SDHCI_CTRL_PRESET_VAL_ENABLE)) {
                ctrl &= ~SDHCI_CTRL_PRESET_VAL_ENABLE;
                sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
+               host->flags &= ~SDHCI_PV_ENABLED;
        }
 
        spin_unlock_irqrestore(&host->lock, flags);
 }
 
+static void sdhci_enable_preset_value(struct mmc_host *mmc, bool enable)
+{
+       struct sdhci_host *host = mmc_priv(mmc);
+
+       sdhci_runtime_pm_get(host);
+       sdhci_do_enable_preset_value(host, enable);
+       sdhci_runtime_pm_put(host);
+}
+
 static const struct mmc_host_ops sdhci_ops = {
        .request        = sdhci_request,
        .set_ios        = sdhci_set_ios,
        .get_ro         = sdhci_get_ro,
+       .hw_reset       = sdhci_hw_reset,
        .enable_sdio_irq = sdhci_enable_sdio_irq,
        .start_signal_voltage_switch    = sdhci_start_signal_voltage_switch,
        .execute_tuning                 = sdhci_execute_tuning,
@@ -1826,19 +1906,19 @@ static void sdhci_tasklet_card(unsigned long param)
 
        spin_lock_irqsave(&host->lock, flags);
 
-       if (!(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT)) {
-               if (host->mrq) {
-                       printk(KERN_ERR "%s: Card removed during transfer!\n",
-                               mmc_hostname(host->mmc));
-                       printk(KERN_ERR "%s: Resetting controller.\n",
-                               mmc_hostname(host->mmc));
+       /* Check host->mrq first in case we are runtime suspended */
+       if (host->mrq &&
+           !(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT)) {
+               pr_err("%s: Card removed during transfer!\n",
+                       mmc_hostname(host->mmc));
+               pr_err("%s: Resetting controller.\n",
+                       mmc_hostname(host->mmc));
 
-                       sdhci_reset(host, SDHCI_RESET_CMD);
-                       sdhci_reset(host, SDHCI_RESET_DATA);
+               sdhci_reset(host, SDHCI_RESET_CMD);
+               sdhci_reset(host, SDHCI_RESET_DATA);
 
-                       host->mrq->cmd->error = -ENOMEDIUM;
-                       tasklet_schedule(&host->finish_tasklet);
-               }
+               host->mrq->cmd->error = -ENOMEDIUM;
+               tasklet_schedule(&host->finish_tasklet);
        }
 
        spin_unlock_irqrestore(&host->lock, flags);
@@ -1854,14 +1934,16 @@ static void sdhci_tasklet_finish(unsigned long param)
 
        host = (struct sdhci_host*)param;
 
+       spin_lock_irqsave(&host->lock, flags);
+
         /*
          * If this tasklet gets rescheduled while running, it will
          * be run again afterwards but without any active request.
          */
-       if (!host->mrq)
+       if (!host->mrq) {
+               spin_unlock_irqrestore(&host->lock, flags);
                return;
-
-       spin_lock_irqsave(&host->lock, flags);
+       }
 
        del_timer(&host->timer);
 
@@ -1905,6 +1987,7 @@ static void sdhci_tasklet_finish(unsigned long param)
        spin_unlock_irqrestore(&host->lock, flags);
 
        mmc_request_done(host->mmc, mrq);
+       sdhci_runtime_pm_put(host);
 }
 
 static void sdhci_timeout_timer(unsigned long data)
@@ -1917,7 +2000,7 @@ static void sdhci_timeout_timer(unsigned long data)
        spin_lock_irqsave(&host->lock, flags);
 
        if (host->mrq) {
-               printk(KERN_ERR "%s: Timeout waiting for hardware "
+               pr_err("%s: Timeout waiting for hardware "
                        "interrupt.\n", mmc_hostname(host->mmc));
                sdhci_dumpregs(host);
 
@@ -1963,7 +2046,7 @@ static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask)
        BUG_ON(intmask == 0);
 
        if (!host->cmd) {
-               printk(KERN_ERR "%s: Got command interrupt 0x%08x even "
+               pr_err("%s: Got command interrupt 0x%08x even "
                        "though no command operation was in progress.\n",
                        mmc_hostname(host->mmc), (unsigned)intmask);
                sdhci_dumpregs(host);
@@ -2063,7 +2146,7 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
                        }
                }
 
-               printk(KERN_ERR "%s: Got data interrupt 0x%08x even "
+               pr_err("%s: Got data interrupt 0x%08x even "
                        "though no data operation was in progress.\n",
                        mmc_hostname(host->mmc), (unsigned)intmask);
                sdhci_dumpregs(host);
@@ -2080,7 +2163,7 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
                        != MMC_BUS_TEST_R)
                host->data->error = -EILSEQ;
        else if (intmask & SDHCI_INT_ADMA_ERROR) {
-               printk(KERN_ERR "%s: ADMA error\n", mmc_hostname(host->mmc));
+               pr_err("%s: ADMA error\n", mmc_hostname(host->mmc));
                sdhci_show_adma_error(host);
                host->data->error = -EIO;
        }
@@ -2136,12 +2219,19 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
 static irqreturn_t sdhci_irq(int irq, void *dev_id)
 {
        irqreturn_t result;
-       struct sdhci_hosthost = dev_id;
+       struct sdhci_host *host = dev_id;
        u32 intmask;
        int cardint = 0;
 
        spin_lock(&host->lock);
 
+       if (host->runtime_suspended) {
+               spin_unlock(&host->lock);
+               pr_warning("%s: got irq while runtime suspended\n",
+                      mmc_hostname(host->mmc));
+               return IRQ_HANDLED;
+       }
+
        intmask = sdhci_readl(host, SDHCI_INT_STATUS);
 
        if (!intmask || intmask == 0xffffffff) {
@@ -2194,7 +2284,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
        intmask &= ~SDHCI_INT_ERROR;
 
        if (intmask & SDHCI_INT_BUS_POWER) {
-               printk(KERN_ERR "%s: Card is consuming too much power!\n",
+               pr_err("%s: Card is consuming too much power!\n",
                        mmc_hostname(host->mmc));
                sdhci_writel(host, SDHCI_INT_BUS_POWER, SDHCI_INT_STATUS);
        }
@@ -2207,7 +2297,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
        intmask &= ~SDHCI_INT_CARD_INT;
 
        if (intmask) {
-               printk(KERN_ERR "%s: Unexpected interrupt 0x%08x.\n",
+               pr_err("%s: Unexpected interrupt 0x%08x.\n",
                        mmc_hostname(host->mmc), intmask);
                sdhci_dumpregs(host);
 
@@ -2275,7 +2365,6 @@ int sdhci_resume_host(struct sdhci_host *host)
                        return ret;
        }
 
-
        if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
                if (host->ops->enable_dma)
                        host->ops->enable_dma(host);
@@ -2314,6 +2403,90 @@ EXPORT_SYMBOL_GPL(sdhci_enable_irq_wakeups);
 
 #endif /* CONFIG_PM */
 
+#ifdef CONFIG_PM_RUNTIME
+
+static int sdhci_runtime_pm_get(struct sdhci_host *host)
+{
+       return pm_runtime_get_sync(host->mmc->parent);
+}
+
+static int sdhci_runtime_pm_put(struct sdhci_host *host)
+{
+       pm_runtime_mark_last_busy(host->mmc->parent);
+       return pm_runtime_put_autosuspend(host->mmc->parent);
+}
+
+int sdhci_runtime_suspend_host(struct sdhci_host *host)
+{
+       unsigned long flags;
+       int ret = 0;
+
+       /* Disable tuning since we are suspending */
+       if (host->version >= SDHCI_SPEC_300 &&
+           host->tuning_mode == SDHCI_TUNING_MODE_1) {
+               del_timer_sync(&host->tuning_timer);
+               host->flags &= ~SDHCI_NEEDS_RETUNING;
+       }
+
+       spin_lock_irqsave(&host->lock, flags);
+       sdhci_mask_irqs(host, SDHCI_INT_ALL_MASK);
+       spin_unlock_irqrestore(&host->lock, flags);
+
+       synchronize_irq(host->irq);
+
+       spin_lock_irqsave(&host->lock, flags);
+       host->runtime_suspended = true;
+       spin_unlock_irqrestore(&host->lock, flags);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(sdhci_runtime_suspend_host);
+
+int sdhci_runtime_resume_host(struct sdhci_host *host)
+{
+       unsigned long flags;
+       int ret = 0, host_flags = host->flags;
+
+       if (host_flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
+               if (host->ops->enable_dma)
+                       host->ops->enable_dma(host);
+       }
+
+       sdhci_init(host, 0);
+
+       /* Force clock and power re-program */
+       host->pwr = 0;
+       host->clock = 0;
+       sdhci_do_set_ios(host, &host->mmc->ios);
+
+       sdhci_do_start_signal_voltage_switch(host, &host->mmc->ios);
+       if (host_flags & SDHCI_PV_ENABLED)
+               sdhci_do_enable_preset_value(host, true);
+
+       /* Set the re-tuning expiration flag */
+       if ((host->version >= SDHCI_SPEC_300) && host->tuning_count &&
+           (host->tuning_mode == SDHCI_TUNING_MODE_1))
+               host->flags |= SDHCI_NEEDS_RETUNING;
+
+       spin_lock_irqsave(&host->lock, flags);
+
+       host->runtime_suspended = false;
+
+       /* Enable SDIO IRQ */
+       if ((host->flags & SDHCI_SDIO_IRQ_ENABLED))
+               sdhci_enable_sdio_irq_nolock(host, true);
+
+       /* Enable Card Detection */
+       sdhci_enable_card_detection(host);
+
+       spin_unlock_irqrestore(&host->lock, flags);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(sdhci_runtime_resume_host);
+
+#endif
+
 /*****************************************************************************\
  *                                                                           *
  * Device allocation/registration                                            *
@@ -2356,6 +2529,8 @@ int sdhci_add_host(struct sdhci_host *host)
 
        if (debug_quirks)
                host->quirks = debug_quirks;
+       if (debug_quirks2)
+               host->quirks2 = debug_quirks2;
 
        sdhci_reset(host, SDHCI_RESET_ALL);
 
@@ -2363,7 +2538,7 @@ int sdhci_add_host(struct sdhci_host *host)
        host->version = (host->version & SDHCI_SPEC_VER_MASK)
                                >> SDHCI_SPEC_VER_SHIFT;
        if (host->version > SDHCI_SPEC_300) {
-               printk(KERN_ERR "%s: Unknown controller version (%d). "
+               pr_err("%s: Unknown controller version (%d). "
                        "You may experience problems.\n", mmc_hostname(mmc),
                        host->version);
        }
@@ -2400,7 +2575,7 @@ int sdhci_add_host(struct sdhci_host *host)
        if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
                if (host->ops->enable_dma) {
                        if (host->ops->enable_dma(host)) {
-                               printk(KERN_WARNING "%s: No suitable DMA "
+                               pr_warning("%s: No suitable DMA "
                                        "available. Falling back to PIO.\n",
                                        mmc_hostname(mmc));
                                host->flags &=
@@ -2420,7 +2595,7 @@ int sdhci_add_host(struct sdhci_host *host)
                if (!host->adma_desc || !host->align_buffer) {
                        kfree(host->adma_desc);
                        kfree(host->align_buffer);
-                       printk(KERN_WARNING "%s: Unable to allocate ADMA "
+                       pr_warning("%s: Unable to allocate ADMA "
                                "buffers. Falling back to standard DMA.\n",
                                mmc_hostname(mmc));
                        host->flags &= ~SDHCI_USE_ADMA;
@@ -2448,8 +2623,7 @@ int sdhci_add_host(struct sdhci_host *host)
        if (host->max_clk == 0 || host->quirks &
                        SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN) {
                if (!host->ops->get_max_clock) {
-                       printk(KERN_ERR
-                              "%s: Hardware doesn't specify base clock "
+                       pr_err("%s: Hardware doesn't specify base clock "
                               "frequency.\n", mmc_hostname(mmc));
                        return -ENODEV;
                }
@@ -2495,8 +2669,7 @@ int sdhci_add_host(struct sdhci_host *host)
                        host->timeout_clk = host->ops->get_timeout_clock(host);
                } else if (!(host->quirks &
                                SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK)) {
-                       printk(KERN_ERR
-                              "%s: Hardware doesn't specify timeout clock "
+                       pr_err("%s: Hardware doesn't specify timeout clock "
                               "frequency.\n", mmc_hostname(mmc));
                        return -ENODEV;
                }
@@ -2566,6 +2739,15 @@ int sdhci_add_host(struct sdhci_host *host)
        if (caps[1] & SDHCI_DRIVER_TYPE_D)
                mmc->caps |= MMC_CAP_DRIVER_TYPE_D;
 
+       /*
+        * If Power Off Notify capability is enabled by the host,
+        * set notify to short power off notify timeout value.
+        */
+       if (mmc->caps2 & MMC_CAP2_POWEROFF_NOTIFY)
+               mmc->power_notify_type = MMC_HOST_PW_NOTIFY_SHORT;
+       else
+               mmc->power_notify_type = MMC_HOST_PW_NOTIFY_NONE;
+
        /* Initial value for re-tuning timer count */
        host->tuning_count = (caps[1] & SDHCI_RETUNING_TIMER_COUNT_MASK) >>
                              SDHCI_RETUNING_TIMER_COUNT_SHIFT;
@@ -2655,7 +2837,7 @@ int sdhci_add_host(struct sdhci_host *host)
                mmc->ocr_avail_mmc &= host->ocr_avail_mmc;
 
        if (mmc->ocr_avail == 0) {
-               printk(KERN_ERR "%s: Hardware doesn't report any "
+               pr_err("%s: Hardware doesn't report any "
                        "support voltages.\n", mmc_hostname(mmc));
                return -ENODEV;
        }
@@ -2703,7 +2885,7 @@ int sdhci_add_host(struct sdhci_host *host)
                mmc->max_blk_size = (caps[0] & SDHCI_MAX_BLOCK_MASK) >>
                                SDHCI_MAX_BLOCK_SHIFT;
                if (mmc->max_blk_size >= 3) {
-                       printk(KERN_WARNING "%s: Invalid maximum block size, "
+                       pr_warning("%s: Invalid maximum block size, "
                                "assuming 512 bytes\n", mmc_hostname(mmc));
                        mmc->max_blk_size = 0;
                }
@@ -2742,7 +2924,7 @@ int sdhci_add_host(struct sdhci_host *host)
 
        host->vmmc = regulator_get(mmc_dev(mmc), "vmmc");
        if (IS_ERR(host->vmmc)) {
-               printk(KERN_INFO "%s: no vmmc regulator found\n", mmc_hostname(mmc));
+               pr_info("%s: no vmmc regulator found\n", mmc_hostname(mmc));
                host->vmmc = NULL;
        } else {
                regulator_enable(host->vmmc);
@@ -2771,7 +2953,7 @@ int sdhci_add_host(struct sdhci_host *host)
 
        mmc_add_host(mmc);
 
-       printk(KERN_INFO "%s: SDHCI controller on %s [%s] using %s\n",
+       pr_info("%s: SDHCI controller on %s [%s] using %s\n",
                mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)),
                (host->flags & SDHCI_USE_ADMA) ? "ADMA" :
                (host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO");
@@ -2804,7 +2986,7 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)
                host->flags |= SDHCI_DEVICE_DEAD;
 
                if (host->mrq) {
-                       printk(KERN_ERR "%s: Controller removed during "
+                       pr_err("%s: Controller removed during "
                                " transfer!\n", mmc_hostname(host->mmc));
 
                        host->mrq->cmd->error = -ENOMEDIUM;
@@ -2863,9 +3045,9 @@ EXPORT_SYMBOL_GPL(sdhci_free_host);
 
 static int __init sdhci_drv_init(void)
 {
-       printk(KERN_INFO DRIVER_NAME
+       pr_info(DRIVER_NAME
                ": Secure Digital Host Controller Interface driver\n");
-       printk(KERN_INFO DRIVER_NAME ": Copyright(c) Pierre Ossman\n");
+       pr_info(DRIVER_NAME ": Copyright(c) Pierre Ossman\n");
 
        return 0;
 }
@@ -2878,9 +3060,11 @@ module_init(sdhci_drv_init);
 module_exit(sdhci_drv_exit);
 
 module_param(debug_quirks, uint, 0444);
+module_param(debug_quirks2, uint, 0444);
 
 MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>");
 MODULE_DESCRIPTION("Secure Digital Host Controller Interface core driver");
 MODULE_LICENSE("GPL");
 
 MODULE_PARM_DESC(debug_quirks, "Force certain quirks.");
+MODULE_PARM_DESC(debug_quirks2, "Force certain other quirks.");
index 745c42fa41ed5fb85cfc45ff9238e37b222ae2b1..0a5b65460d8a760de4c37cbdb2d9a89dd7cf430d 100644 (file)
@@ -273,7 +273,7 @@ struct sdhci_ops {
        void    (*platform_reset_enter)(struct sdhci_host *host, u8 mask);
        void    (*platform_reset_exit)(struct sdhci_host *host, u8 mask);
        int     (*set_uhs_signaling)(struct sdhci_host *host, unsigned int uhs);
-
+       void    (*hw_reset)(struct sdhci_host *host);
 };
 
 #ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS
@@ -379,4 +379,9 @@ extern int sdhci_resume_host(struct sdhci_host *host);
 extern void sdhci_enable_irq_wakeups(struct sdhci_host *host);
 #endif
 
+#ifdef CONFIG_PM_RUNTIME
+extern int sdhci_runtime_suspend_host(struct sdhci_host *host);
+extern int sdhci_runtime_resume_host(struct sdhci_host *host);
+#endif
+
 #endif /* __SDHCI_HW_H */
index 496b7efbc6b079976646a7e9c593d652003cad0f..7009f17ad6cd02acbc21718d7bdd9ab7d8b2a3bf 100644 (file)
@@ -26,6 +26,7 @@
 */
 #include <linux/delay.h>
 #include <linux/highmem.h>
+#include <linux/module.h>
 #include <linux/pci.h>
 #include <linux/ioport.h>
 #include <linux/scatterlist.h>
index 557886bee9ce7501f574e1cbe493c7d2be740ff5..369366c8e205e4ed8aa27746e3a8940b89e54287 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
 #include <linux/spinlock.h>
+#include <linux/module.h>
 
 #define DRIVER_NAME    "sh_mmcif"
 #define DRIVER_VERSION "2010-04-28"
@@ -165,6 +166,8 @@ struct sh_mmcif_host {
        struct mmc_host *mmc;
        struct mmc_data *data;
        struct platform_device *pd;
+       struct sh_dmae_slave dma_slave_tx;
+       struct sh_dmae_slave dma_slave_rx;
        struct clk *hclk;
        unsigned int clk;
        int bus_width;
@@ -323,25 +326,35 @@ static bool sh_mmcif_filter(struct dma_chan *chan, void *arg)
 static void sh_mmcif_request_dma(struct sh_mmcif_host *host,
                                 struct sh_mmcif_plat_data *pdata)
 {
+       struct sh_dmae_slave *tx, *rx;
        host->dma_active = false;
 
        /* We can only either use DMA for both Tx and Rx or not use it at all */
        if (pdata->dma) {
+               dev_warn(&host->pd->dev,
+                        "Update your platform to use embedded DMA slave IDs\n");
+               tx = &pdata->dma->chan_priv_tx;
+               rx = &pdata->dma->chan_priv_rx;
+       } else {
+               tx = &host->dma_slave_tx;
+               tx->slave_id = pdata->slave_id_tx;
+               rx = &host->dma_slave_rx;
+               rx->slave_id = pdata->slave_id_rx;
+       }
+       if (tx->slave_id > 0 && rx->slave_id > 0) {
                dma_cap_mask_t mask;
 
                dma_cap_zero(mask);
                dma_cap_set(DMA_SLAVE, mask);
 
-               host->chan_tx = dma_request_channel(mask, sh_mmcif_filter,
-                                                   &pdata->dma->chan_priv_tx);
+               host->chan_tx = dma_request_channel(mask, sh_mmcif_filter, tx);
                dev_dbg(&host->pd->dev, "%s: TX: got channel %p\n", __func__,
                        host->chan_tx);
 
                if (!host->chan_tx)
                        return;
 
-               host->chan_rx = dma_request_channel(mask, sh_mmcif_filter,
-                                                   &pdata->dma->chan_priv_rx);
+               host->chan_rx = dma_request_channel(mask, sh_mmcif_filter, rx);
                dev_dbg(&host->pd->dev, "%s: RX: got channel %p\n", __func__,
                        host->chan_rx);
 
index 0c4a672f5db618bd68c96b4bb7a6239bdf7f12aa..41ae6466bd83e8b65b87d0da122afe54bdc93fb3 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/kernel.h>
 #include <linux/clk.h>
 #include <linux/slab.h>
+#include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/mmc/host.h>
 #include <linux/mmc/sh_mobile_sdhi.h>
@@ -96,7 +97,8 @@ static int __devinit sh_mobile_sdhi_probe(struct platform_device *pdev)
        struct sh_mobile_sdhi_info *p = pdev->dev.platform_data;
        struct tmio_mmc_host *host;
        char clk_name[8];
-       int i, irq, ret;
+       int irq, ret, i = 0;
+       bool multiplexed_isr = true;
 
        priv = kzalloc(sizeof(struct sh_mobile_sdhi), GFP_KERNEL);
        if (priv == NULL) {
@@ -153,27 +155,60 @@ static int __devinit sh_mobile_sdhi_probe(struct platform_device *pdev)
        if (ret < 0)
                goto eprobe;
 
-       for (i = 0; i < 3; i++) {
-               irq = platform_get_irq(pdev, i);
-               if (irq < 0) {
-                       if (i) {
-                               continue;
-                       } else {
-                               ret = irq;
-                               goto eirq;
-                       }
-               }
-               ret = request_irq(irq, tmio_mmc_irq, 0,
+       /*
+        * Allow one or more specific (named) ISRs or
+        * one or more multiplexed (un-named) ISRs.
+        */
+
+       irq = platform_get_irq_byname(pdev, SH_MOBILE_SDHI_IRQ_CARD_DETECT);
+       if (irq >= 0) {
+               multiplexed_isr = false;
+               ret = request_irq(irq, tmio_mmc_card_detect_irq, 0,
+                                 dev_name(&pdev->dev), host);
+               if (ret)
+                       goto eirq_card_detect;
+       }
+
+       irq = platform_get_irq_byname(pdev, SH_MOBILE_SDHI_IRQ_SDIO);
+       if (irq >= 0) {
+               multiplexed_isr = false;
+               ret = request_irq(irq, tmio_mmc_sdio_irq, 0,
+                                 dev_name(&pdev->dev), host);
+               if (ret)
+                       goto eirq_sdio;
+       }
+
+       irq = platform_get_irq_byname(pdev, SH_MOBILE_SDHI_IRQ_SDCARD);
+       if (irq >= 0) {
+               multiplexed_isr = false;
+               ret = request_irq(irq, tmio_mmc_sdcard_irq, 0,
                                  dev_name(&pdev->dev), host);
-               if (ret) {
-                       while (i--) {
-                               irq = platform_get_irq(pdev, i);
-                               if (irq >= 0)
-                                       free_irq(irq, host);
-                       }
-                       goto eirq;
+               if (ret)
+                       goto eirq_sdcard;
+       } else if (!multiplexed_isr) {
+               dev_err(&pdev->dev,
+                       "Principal SD-card IRQ is missing among named interrupts\n");
+               ret = irq;
+               goto eirq_sdcard;
+       }
+
+       if (multiplexed_isr) {
+               while (1) {
+                       irq = platform_get_irq(pdev, i);
+                       if (irq < 0)
+                               break;
+                       i++;
+                       ret = request_irq(irq, tmio_mmc_irq, 0,
+                                         dev_name(&pdev->dev), host);
+                       if (ret)
+                               goto eirq_multiplexed;
                }
+
+               /* There must be at least one IRQ source */
+               if (!i)
+                       goto eirq_multiplexed;
        }
+
        dev_info(&pdev->dev, "%s base at 0x%08lx clock rate %u MHz\n",
                 mmc_hostname(host->mmc), (unsigned long)
                 (platform_get_resource(pdev,IORESOURCE_MEM, 0)->start),
@@ -181,7 +216,20 @@ static int __devinit sh_mobile_sdhi_probe(struct platform_device *pdev)
 
        return ret;
 
-eirq:
+eirq_multiplexed:
+       while (i--) {
+               irq = platform_get_irq(pdev, i);
+               free_irq(irq, host);
+       }
+eirq_sdcard:
+       irq = platform_get_irq_byname(pdev, SH_MOBILE_SDHI_IRQ_SDIO);
+       if (irq >= 0)
+               free_irq(irq, host);
+eirq_sdio:
+       irq = platform_get_irq_byname(pdev, SH_MOBILE_SDHI_IRQ_CARD_DETECT);
+       if (irq >= 0)
+               free_irq(irq, host);
+eirq_card_detect:
        tmio_mmc_host_remove(host);
 eprobe:
        clk_disable(priv->clk);
@@ -197,16 +245,17 @@ static int sh_mobile_sdhi_remove(struct platform_device *pdev)
        struct tmio_mmc_host *host = mmc_priv(mmc);
        struct sh_mobile_sdhi *priv = container_of(host->pdata, struct sh_mobile_sdhi, mmc_data);
        struct sh_mobile_sdhi_info *p = pdev->dev.platform_data;
-       int i, irq;
+       int i = 0, irq;
 
        p->pdata = NULL;
 
        tmio_mmc_host_remove(host);
 
-       for (i = 0; i < 3; i++) {
-               irq = platform_get_irq(pdev, i);
-               if (irq >= 0)
-                       free_irq(irq, host);
+       while (1) {
+               irq = platform_get_irq(pdev, i++);
+               if (irq < 0)
+                       break;
+               free_irq(irq, host);
        }
 
        clk_disable(priv->clk);
index 457c26ea09de4923abe6725b4c2ae7d75d01f3ed..f70d04664cac8aff6223df5d2965e630db826044 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/mmc/host.h>
 #include <linux/highmem.h>
 #include <linux/scatterlist.h>
+#include <linux/module.h>
 #include <asm/io.h>
 
 #define DRIVER_NAME "tifm_sd"
@@ -631,7 +632,7 @@ static void tifm_sd_request(struct mmc_host *mmc, struct mmc_request *mrq)
        }
 
        if (host->req) {
-               printk(KERN_ERR "%s : unfinished request detected\n",
+               pr_err("%s : unfinished request detected\n",
                       dev_name(&sock->dev));
                mrq->cmd->error = -ETIMEDOUT;
                goto err_out;
@@ -671,7 +672,7 @@ static void tifm_sd_request(struct mmc_host *mmc, struct mmc_request *mrq)
                                            r_data->flags & MMC_DATA_WRITE
                                            ? PCI_DMA_TODEVICE
                                            : PCI_DMA_FROMDEVICE)) {
-                               printk(KERN_ERR "%s : scatterlist map failed\n",
+                               pr_err("%s : scatterlist map failed\n",
                                       dev_name(&sock->dev));
                                mrq->cmd->error = -ENOMEM;
                                goto err_out;
@@ -683,7 +684,7 @@ static void tifm_sd_request(struct mmc_host *mmc, struct mmc_request *mrq)
                                                   ? PCI_DMA_TODEVICE
                                                   : PCI_DMA_FROMDEVICE);
                        if (host->sg_len < 1) {
-                               printk(KERN_ERR "%s : scatterlist map failed\n",
+                               pr_err("%s : scatterlist map failed\n",
                                       dev_name(&sock->dev));
                                tifm_unmap_sg(sock, &host->bounce_buf, 1,
                                              r_data->flags & MMC_DATA_WRITE
@@ -747,7 +748,7 @@ static void tifm_sd_end_cmd(unsigned long data)
        host->req = NULL;
 
        if (!mrq) {
-               printk(KERN_ERR " %s : no request to complete?\n",
+               pr_err(" %s : no request to complete?\n",
                       dev_name(&sock->dev));
                spin_unlock_irqrestore(&sock->lock, flags);
                return;
@@ -786,8 +787,7 @@ static void tifm_sd_abort(unsigned long data)
 {
        struct tifm_sd *host = (struct tifm_sd*)data;
 
-       printk(KERN_ERR
-              "%s : card failed to respond for a long period of time "
+       pr_err("%s : card failed to respond for a long period of time "
               "(%x, %x)\n",
               dev_name(&host->dev->dev), host->req->cmd->opcode, host->cmd_flags);
 
@@ -905,7 +905,7 @@ static int tifm_sd_initialize_host(struct tifm_sd *host)
        }
 
        if (rc) {
-               printk(KERN_ERR "%s : controller failed to reset\n",
+               pr_err("%s : controller failed to reset\n",
                       dev_name(&sock->dev));
                return -ENODEV;
        }
@@ -931,8 +931,7 @@ static int tifm_sd_initialize_host(struct tifm_sd *host)
        }
 
        if (rc) {
-               printk(KERN_ERR
-                      "%s : card not ready - probe failed on initialization\n",
+               pr_err("%s : card not ready - probe failed on initialization\n",
                       dev_name(&sock->dev));
                return -ENODEV;
        }
@@ -953,7 +952,7 @@ static int tifm_sd_probe(struct tifm_dev *sock)
 
        if (!(TIFM_SOCK_STATE_OCCUPIED
              & readl(sock->addr + SOCK_PRESENT_STATE))) {
-               printk(KERN_WARNING "%s : card gone, unexpectedly\n",
+               pr_warning("%s : card gone, unexpectedly\n",
                       dev_name(&sock->dev));
                return rc;
        }
index 44a9668c4b7ad759483b286569470a105d7ecc53..a4ea10242787465d21f99e93e11516d8090cdef1 100644 (file)
@@ -88,8 +88,8 @@ static int __devinit tmio_mmc_probe(struct platform_device *pdev)
        if (ret)
                goto cell_disable;
 
-       ret = request_irq(irq, tmio_mmc_irq, IRQF_DISABLED |
-                         IRQF_TRIGGER_FALLING, dev_name(&pdev->dev), host);
+       ret = request_irq(irq, tmio_mmc_irq, IRQF_TRIGGER_FALLING,
+                               dev_name(&pdev->dev), host);
        if (ret)
                goto host_remove;
 
index eeaf64391fbe3d8620dc675853716f704cb0e3e9..3020f98218f0104d5082dd4d94a84a3c9a5160eb 100644 (file)
@@ -79,6 +79,10 @@ struct tmio_mmc_host {
        struct delayed_work     delayed_reset_work;
        struct work_struct      done;
 
+       /* Cache IRQ mask */
+       u32                     sdcard_irq_mask;
+       u32                     sdio_irq_mask;
+
        spinlock_t              lock;           /* protect host private data */
        unsigned long           last_req_ts;
        struct mutex            ios_lock;       /* protect set_ios() context */
@@ -93,6 +97,9 @@ void tmio_mmc_do_data_irq(struct tmio_mmc_host *host);
 void tmio_mmc_enable_mmc_irqs(struct tmio_mmc_host *host, u32 i);
 void tmio_mmc_disable_mmc_irqs(struct tmio_mmc_host *host, u32 i);
 irqreturn_t tmio_mmc_irq(int irq, void *devid);
+irqreturn_t tmio_mmc_sdcard_irq(int irq, void *devid);
+irqreturn_t tmio_mmc_card_detect_irq(int irq, void *devid);
+irqreturn_t tmio_mmc_sdio_irq(int irq, void *devid);
 
 static inline char *tmio_mmc_kmap_atomic(struct scatterlist *sg,
                                         unsigned long *flags)
index 1f16357e7301d1f4ea9a61f994f094bc71e0785b..d85a60cda16781ae25509a28705122597b87dd2a 100644 (file)
 
 void tmio_mmc_enable_mmc_irqs(struct tmio_mmc_host *host, u32 i)
 {
-       u32 mask = sd_ctrl_read32(host, CTL_IRQ_MASK) & ~(i & TMIO_MASK_IRQ);
-       sd_ctrl_write32(host, CTL_IRQ_MASK, mask);
+       host->sdcard_irq_mask &= ~(i & TMIO_MASK_IRQ);
+       sd_ctrl_write32(host, CTL_IRQ_MASK, host->sdcard_irq_mask);
 }
 
 void tmio_mmc_disable_mmc_irqs(struct tmio_mmc_host *host, u32 i)
 {
-       u32 mask = sd_ctrl_read32(host, CTL_IRQ_MASK) | (i & TMIO_MASK_IRQ);
-       sd_ctrl_write32(host, CTL_IRQ_MASK, mask);
+       host->sdcard_irq_mask |= (i & TMIO_MASK_IRQ);
+       sd_ctrl_write32(host, CTL_IRQ_MASK, host->sdcard_irq_mask);
 }
 
 static void tmio_mmc_ack_mmc_irqs(struct tmio_mmc_host *host, u32 i)
@@ -92,7 +92,7 @@ static int tmio_mmc_next_sg(struct tmio_mmc_host *host)
 static void pr_debug_status(u32 status)
 {
        int i = 0;
-       printk(KERN_DEBUG "status: %08x = ", status);
+       pr_debug("status: %08x = ", status);
        STATUS_TO_TEXT(CARD_REMOVE, status, i);
        STATUS_TO_TEXT(CARD_INSERT, status, i);
        STATUS_TO_TEXT(SIGSTATE, status, i);
@@ -127,11 +127,13 @@ static void tmio_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable)
 
        if (enable) {
                host->sdio_irq_enabled = 1;
+               host->sdio_irq_mask = TMIO_SDIO_MASK_ALL &
+                                       ~TMIO_SDIO_STAT_IOIRQ;
                sd_ctrl_write16(host, CTL_TRANSACTION_CTL, 0x0001);
-               sd_ctrl_write16(host, CTL_SDIO_IRQ_MASK,
-                       (TMIO_SDIO_MASK_ALL & ~TMIO_SDIO_STAT_IOIRQ));
+               sd_ctrl_write16(host, CTL_SDIO_IRQ_MASK, host->sdio_irq_mask);
        } else {
-               sd_ctrl_write16(host, CTL_SDIO_IRQ_MASK, TMIO_SDIO_MASK_ALL);
+               host->sdio_irq_mask = TMIO_SDIO_MASK_ALL;
+               sd_ctrl_write16(host, CTL_SDIO_IRQ_MASK, host->sdio_irq_mask);
                sd_ctrl_write16(host, CTL_TRANSACTION_CTL, 0x0000);
                host->sdio_irq_enabled = 0;
        }
@@ -543,45 +545,20 @@ out:
        spin_unlock(&host->lock);
 }
 
-irqreturn_t tmio_mmc_irq(int irq, void *devid)
+static void tmio_mmc_card_irq_status(struct tmio_mmc_host *host,
+                                      int *ireg, int *status)
 {
-       struct tmio_mmc_host *host = devid;
-       struct mmc_host *mmc = host->mmc;
-       struct tmio_mmc_data *pdata = host->pdata;
-       unsigned int ireg, irq_mask, status;
-       unsigned int sdio_ireg, sdio_irq_mask, sdio_status;
-
-       pr_debug("MMC IRQ begin\n");
-
-       status = sd_ctrl_read32(host, CTL_STATUS);
-       irq_mask = sd_ctrl_read32(host, CTL_IRQ_MASK);
-       ireg = status & TMIO_MASK_IRQ & ~irq_mask;
-
-       sdio_ireg = 0;
-       if (!ireg && pdata->flags & TMIO_MMC_SDIO_IRQ) {
-               sdio_status = sd_ctrl_read16(host, CTL_SDIO_STATUS);
-               sdio_irq_mask = sd_ctrl_read16(host, CTL_SDIO_IRQ_MASK);
-               sdio_ireg = sdio_status & TMIO_SDIO_MASK_ALL & ~sdio_irq_mask;
+       *status = sd_ctrl_read32(host, CTL_STATUS);
+       *ireg = *status & TMIO_MASK_IRQ & ~host->sdcard_irq_mask;
 
-               sd_ctrl_write16(host, CTL_SDIO_STATUS, sdio_status & ~TMIO_SDIO_MASK_ALL);
-
-               if (sdio_ireg && !host->sdio_irq_enabled) {
-                       pr_warning("tmio_mmc: Spurious SDIO IRQ, disabling! 0x%04x 0x%04x 0x%04x\n",
-                                  sdio_status, sdio_irq_mask, sdio_ireg);
-                       tmio_mmc_enable_sdio_irq(mmc, 0);
-                       goto out;
-               }
-
-               if (mmc->caps & MMC_CAP_SDIO_IRQ &&
-                       sdio_ireg & TMIO_SDIO_STAT_IOIRQ)
-                       mmc_signal_sdio_irq(mmc);
-
-               if (sdio_ireg)
-                       goto out;
-       }
+       pr_debug_status(*status);
+       pr_debug_status(*ireg);
+}
 
-       pr_debug_status(status);
-       pr_debug_status(ireg);
+static bool __tmio_mmc_card_detect_irq(struct tmio_mmc_host *host,
+                                     int ireg, int status)
+{
+       struct mmc_host *mmc = host->mmc;
 
        /* Card insert / remove attempts */
        if (ireg & (TMIO_STAT_CARD_INSERT | TMIO_STAT_CARD_REMOVE)) {
@@ -591,43 +568,102 @@ irqreturn_t tmio_mmc_irq(int irq, void *devid)
                     ((ireg & TMIO_STAT_CARD_INSERT) && !mmc->card)) &&
                    !work_pending(&mmc->detect.work))
                        mmc_detect_change(host->mmc, msecs_to_jiffies(100));
-               goto out;
+               return true;
        }
 
-       /* CRC and other errors */
-/*     if (ireg & TMIO_STAT_ERR_IRQ)
- *             handled |= tmio_error_irq(host, irq, stat);
- */
+       return false;
+}
+
+irqreturn_t tmio_mmc_card_detect_irq(int irq, void *devid)
+{
+       unsigned int ireg, status;
+       struct tmio_mmc_host *host = devid;
+
+       tmio_mmc_card_irq_status(host, &ireg, &status);
+       __tmio_mmc_card_detect_irq(host, ireg, status);
 
+       return IRQ_HANDLED;
+}
+EXPORT_SYMBOL(tmio_mmc_card_detect_irq);
+
+static bool __tmio_mmc_sdcard_irq(struct tmio_mmc_host *host,
+                                int ireg, int status)
+{
        /* Command completion */
        if (ireg & (TMIO_STAT_CMDRESPEND | TMIO_STAT_CMDTIMEOUT)) {
                tmio_mmc_ack_mmc_irqs(host,
                             TMIO_STAT_CMDRESPEND |
                             TMIO_STAT_CMDTIMEOUT);
                tmio_mmc_cmd_irq(host, status);
-               goto out;
+               return true;
        }
 
        /* Data transfer */
        if (ireg & (TMIO_STAT_RXRDY | TMIO_STAT_TXRQ)) {
                tmio_mmc_ack_mmc_irqs(host, TMIO_STAT_RXRDY | TMIO_STAT_TXRQ);
                tmio_mmc_pio_irq(host);
-               goto out;
+               return true;
        }
 
        /* Data transfer completion */
        if (ireg & TMIO_STAT_DATAEND) {
                tmio_mmc_ack_mmc_irqs(host, TMIO_STAT_DATAEND);
                tmio_mmc_data_irq(host);
-               goto out;
+               return true;
        }
 
-       pr_warning("tmio_mmc: Spurious irq, disabling! "
-               "0x%08x 0x%08x 0x%08x\n", status, irq_mask, ireg);
-       pr_debug_status(status);
-       tmio_mmc_disable_mmc_irqs(host, status & ~irq_mask);
+       return false;
+}
+
+irqreturn_t tmio_mmc_sdcard_irq(int irq, void *devid)
+{
+       unsigned int ireg, status;
+       struct tmio_mmc_host *host = devid;
+
+       tmio_mmc_card_irq_status(host, &ireg, &status);
+       __tmio_mmc_sdcard_irq(host, ireg, status);
+
+       return IRQ_HANDLED;
+}
+EXPORT_SYMBOL(tmio_mmc_sdcard_irq);
+
+irqreturn_t tmio_mmc_sdio_irq(int irq, void *devid)
+{
+       struct tmio_mmc_host *host = devid;
+       struct mmc_host *mmc = host->mmc;
+       struct tmio_mmc_data *pdata = host->pdata;
+       unsigned int ireg, status;
+
+       if (!(pdata->flags & TMIO_MMC_SDIO_IRQ))
+               return IRQ_HANDLED;
+
+       status = sd_ctrl_read16(host, CTL_SDIO_STATUS);
+       ireg = status & TMIO_SDIO_MASK_ALL & ~host->sdcard_irq_mask;
+
+       sd_ctrl_write16(host, CTL_SDIO_STATUS, status & ~TMIO_SDIO_MASK_ALL);
+
+       if (mmc->caps & MMC_CAP_SDIO_IRQ && ireg & TMIO_SDIO_STAT_IOIRQ)
+               mmc_signal_sdio_irq(mmc);
+
+       return IRQ_HANDLED;
+}
+EXPORT_SYMBOL(tmio_mmc_sdio_irq);
+
+irqreturn_t tmio_mmc_irq(int irq, void *devid)
+{
+       struct tmio_mmc_host *host = devid;
+       unsigned int ireg, status;
+
+       pr_debug("MMC IRQ begin\n");
+
+       tmio_mmc_card_irq_status(host, &ireg, &status);
+       if (__tmio_mmc_card_detect_irq(host, ireg, status))
+               return IRQ_HANDLED;
+       if (__tmio_mmc_sdcard_irq(host, ireg, status))
+               return IRQ_HANDLED;
+
+       tmio_mmc_sdio_irq(irq, devid);
 
-out:
        return IRQ_HANDLED;
 }
 EXPORT_SYMBOL(tmio_mmc_irq);
@@ -882,6 +918,7 @@ int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host,
        tmio_mmc_clk_stop(_host);
        tmio_mmc_reset(_host);
 
+       _host->sdcard_irq_mask = sd_ctrl_read32(_host, CTL_IRQ_MASK);
        tmio_mmc_disable_mmc_irqs(_host, TMIO_MASK_ALL);
        if (pdata->flags & TMIO_MMC_SDIO_IRQ)
                tmio_mmc_enable_sdio_irq(mmc, 0);
index 4dfe2c02ea91f340fd3de23db2b371da9020fc91..4b83c43f950d4634498ae809cbd40e827eec0339 100644 (file)
@@ -9,6 +9,7 @@
  */
 
 #include <linux/pci.h>
+#include <linux/module.h>
 #include <linux/dma-mapping.h>
 #include <linux/highmem.h>
 #include <linux/delay.h>
@@ -1191,7 +1192,7 @@ static void __devexit via_sd_remove(struct pci_dev *pcidev)
        mmiowb();
 
        if (sdhost->mrq) {
-               printk(KERN_ERR "%s: Controller removed during "
+               pr_err("%s: Controller removed during "
                        "transfer\n", mmc_hostname(sdhost->mmc));
 
                /* make sure all DMA is stopped */
index 62e5a4d171e1c881c8ba8780d06aadacaaaef90d..64acd9ce141cb9a9e14690d3e0b05f8150737a3d 100644 (file)
@@ -194,7 +194,7 @@ static void wbsd_reset(struct wbsd_host *host)
 {
        u8 setup;
 
-       printk(KERN_ERR "%s: Resetting chip\n", mmc_hostname(host->mmc));
+       pr_err("%s: Resetting chip\n", mmc_hostname(host->mmc));
 
        /*
         * Soft reset of chip (SD/MMC part).
@@ -721,7 +721,7 @@ static void wbsd_finish_data(struct wbsd_host *host, struct mmc_data *data)
                 * Any leftover data?
                 */
                if (count) {
-                       printk(KERN_ERR "%s: Incomplete DMA transfer. "
+                       pr_err("%s: Incomplete DMA transfer. "
                                "%d bytes left.\n",
                                mmc_hostname(host->mmc), count);
 
@@ -803,7 +803,7 @@ static void wbsd_request(struct mmc_host *mmc, struct mmc_request *mrq)
 
                default:
 #ifdef CONFIG_MMC_DEBUG
-                       printk(KERN_WARNING "%s: Data command %d is not "
+                       pr_warning("%s: Data command %d is not "
                                "supported by this controller.\n",
                                mmc_hostname(host->mmc), cmd->opcode);
 #endif
@@ -1029,7 +1029,7 @@ static void wbsd_tasklet_card(unsigned long param)
                host->flags &= ~WBSD_FCARD_PRESENT;
 
                if (host->mrq) {
-                       printk(KERN_ERR "%s: Card removed during transfer!\n",
+                       pr_err("%s: Card removed during transfer!\n",
                                mmc_hostname(host->mmc));
                        wbsd_reset(host);
 
@@ -1429,7 +1429,7 @@ free:
        free_dma(dma);
 
 err:
-       printk(KERN_WARNING DRIVER_NAME ": Unable to allocate DMA %d. "
+       pr_warning(DRIVER_NAME ": Unable to allocate DMA %d. "
                "Falling back on FIFO.\n", dma);
 }
 
@@ -1664,7 +1664,7 @@ static int __devinit wbsd_init(struct device *dev, int base, int irq, int dma,
        ret = wbsd_scan(host);
        if (ret) {
                if (pnp && (ret == -ENODEV)) {
-                       printk(KERN_WARNING DRIVER_NAME
+                       pr_warning(DRIVER_NAME
                                ": Unable to confirm device presence. You may "
                                "experience lock-ups.\n");
                } else {
@@ -1688,7 +1688,7 @@ static int __devinit wbsd_init(struct device *dev, int base, int irq, int dma,
         */
        if (pnp) {
                if ((host->config != 0) && !wbsd_chip_validate(host)) {
-                       printk(KERN_WARNING DRIVER_NAME
+                       pr_warning(DRIVER_NAME
                                ": PnP active but chip not configured! "
                                "You probably have a buggy BIOS. "
                                "Configuring chip manually.\n");
@@ -1720,7 +1720,7 @@ static int __devinit wbsd_init(struct device *dev, int base, int irq, int dma,
 
        mmc_add_host(mmc);
 
-       printk(KERN_INFO "%s: W83L51xD", mmc_hostname(mmc));
+       pr_info("%s: W83L51xD", mmc_hostname(mmc));
        if (host->chip_id != 0)
                printk(" id %x", (int)host->chip_id);
        printk(" at 0x%x irq %d", (int)host->base, (int)host->irq);
@@ -1909,7 +1909,7 @@ static int wbsd_pnp_resume(struct pnp_dev *pnp_dev)
         */
        if (host->config != 0) {
                if (!wbsd_chip_validate(host)) {
-                       printk(KERN_WARNING DRIVER_NAME
+                       pr_warning(DRIVER_NAME
                                ": PnP active but chip not configured! "
                                "You probably have a buggy BIOS. "
                                "Configuring chip manually.\n");
@@ -1973,9 +1973,9 @@ static int __init wbsd_drv_init(void)
 {
        int result;
 
-       printk(KERN_INFO DRIVER_NAME
+       pr_info(DRIVER_NAME
                ": Winbond W83L51xD SD/MMC card interface driver\n");
-       printk(KERN_INFO DRIVER_NAME ": Copyright(c) Pierre Ossman\n");
+       pr_info(DRIVER_NAME ": Copyright(c) Pierre Ossman\n");
 
 #ifdef CONFIG_PNP
 
index b33c099d65a43b518e1c0d6547d680d5bb6fe565..0ae0d7c54ccf647e91792edfa14dc32d900ec877 100644 (file)
@@ -2110,9 +2110,6 @@ void bond_3ad_state_machine_handler(struct work_struct *work)
 
        read_lock(&bond->lock);
 
-       if (bond->kill_timers)
-               goto out;
-
        //check if there are any slaves
        if (bond->slave_cnt == 0)
                goto re_arm;
@@ -2161,9 +2158,8 @@ void bond_3ad_state_machine_handler(struct work_struct *work)
        }
 
 re_arm:
-       if (!bond->kill_timers)
-               queue_delayed_work(bond->wq, &bond->ad_work, ad_delta_in_ticks);
-out:
+       queue_delayed_work(bond->wq, &bond->ad_work, ad_delta_in_ticks);
+
        read_unlock(&bond->lock);
 }
 
index d4fbd2e62616cfc780a993c8ba4dc51a639f79bb..106b88a04738fb25fa5bd850537653beaa5b4aa5 100644 (file)
@@ -1343,10 +1343,6 @@ void bond_alb_monitor(struct work_struct *work)
 
        read_lock(&bond->lock);
 
-       if (bond->kill_timers) {
-               goto out;
-       }
-
        if (bond->slave_cnt == 0) {
                bond_info->tx_rebalance_counter = 0;
                bond_info->lp_counter = 0;
@@ -1401,10 +1397,13 @@ void bond_alb_monitor(struct work_struct *work)
 
                        /*
                         * dev_set_promiscuity requires rtnl and
-                        * nothing else.
+                        * nothing else.  Avoid race with bond_close.
                         */
                        read_unlock(&bond->lock);
-                       rtnl_lock();
+                       if (!rtnl_trylock()) {
+                               read_lock(&bond->lock);
+                               goto re_arm;
+                       }
 
                        bond_info->rlb_promisc_timeout_counter = 0;
 
@@ -1440,9 +1439,8 @@ void bond_alb_monitor(struct work_struct *work)
        }
 
 re_arm:
-       if (!bond->kill_timers)
-               queue_delayed_work(bond->wq, &bond->alb_work, alb_delta_in_ticks);
-out:
+       queue_delayed_work(bond->wq, &bond->alb_work, alb_delta_in_ticks);
+
        read_unlock(&bond->lock);
 }
 
index c5944f1a4f9d52da7820337d8fb2324727724048..c34cc1e7c6f6d9b413b899cc66a6356066155d32 100644 (file)
@@ -773,9 +773,6 @@ static void bond_resend_igmp_join_requests(struct bonding *bond)
 
        read_lock(&bond->lock);
 
-       if (bond->kill_timers)
-               goto out;
-
        /* rejoin all groups on bond device */
        __bond_resend_igmp_join_requests(bond->dev);
 
@@ -789,9 +786,9 @@ static void bond_resend_igmp_join_requests(struct bonding *bond)
                        __bond_resend_igmp_join_requests(vlan_dev);
        }
 
-       if ((--bond->igmp_retrans > 0) && !bond->kill_timers)
+       if (--bond->igmp_retrans > 0)
                queue_delayed_work(bond->wq, &bond->mcast_work, HZ/5);
-out:
+
        read_unlock(&bond->lock);
 }
 
@@ -2517,10 +2514,11 @@ void bond_mii_monitor(struct work_struct *work)
        struct bonding *bond = container_of(work, struct bonding,
                                            mii_work.work);
        bool should_notify_peers = false;
+       unsigned long delay;
 
        read_lock(&bond->lock);
-       if (bond->kill_timers)
-               goto out;
+
+       delay = msecs_to_jiffies(bond->params.miimon);
 
        if (bond->slave_cnt == 0)
                goto re_arm;
@@ -2529,7 +2527,15 @@ void bond_mii_monitor(struct work_struct *work)
 
        if (bond_miimon_inspect(bond)) {
                read_unlock(&bond->lock);
-               rtnl_lock();
+
+               /* Race avoidance with bond_close cancel of workqueue */
+               if (!rtnl_trylock()) {
+                       read_lock(&bond->lock);
+                       delay = 1;
+                       should_notify_peers = false;
+                       goto re_arm;
+               }
+
                read_lock(&bond->lock);
 
                bond_miimon_commit(bond);
@@ -2540,14 +2546,18 @@ void bond_mii_monitor(struct work_struct *work)
        }
 
 re_arm:
-       if (bond->params.miimon && !bond->kill_timers)
-               queue_delayed_work(bond->wq, &bond->mii_work,
-                                  msecs_to_jiffies(bond->params.miimon));
-out:
+       if (bond->params.miimon)
+               queue_delayed_work(bond->wq, &bond->mii_work, delay);
+
        read_unlock(&bond->lock);
 
        if (should_notify_peers) {
-               rtnl_lock();
+               if (!rtnl_trylock()) {
+                       read_lock(&bond->lock);
+                       bond->send_peer_notif++;
+                       read_unlock(&bond->lock);
+                       return;
+               }
                netdev_bonding_change(bond->dev, NETDEV_NOTIFY_PEERS);
                rtnl_unlock();
        }
@@ -2789,9 +2799,6 @@ void bond_loadbalance_arp_mon(struct work_struct *work)
 
        delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval);
 
-       if (bond->kill_timers)
-               goto out;
-
        if (bond->slave_cnt == 0)
                goto re_arm;
 
@@ -2888,9 +2895,9 @@ void bond_loadbalance_arp_mon(struct work_struct *work)
        }
 
 re_arm:
-       if (bond->params.arp_interval && !bond->kill_timers)
+       if (bond->params.arp_interval)
                queue_delayed_work(bond->wq, &bond->arp_work, delta_in_ticks);
-out:
+
        read_unlock(&bond->lock);
 }
 
@@ -3131,9 +3138,6 @@ void bond_activebackup_arp_mon(struct work_struct *work)
 
        read_lock(&bond->lock);
 
-       if (bond->kill_timers)
-               goto out;
-
        delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval);
 
        if (bond->slave_cnt == 0)
@@ -3143,7 +3147,15 @@ void bond_activebackup_arp_mon(struct work_struct *work)
 
        if (bond_ab_arp_inspect(bond, delta_in_ticks)) {
                read_unlock(&bond->lock);
-               rtnl_lock();
+
+               /* Race avoidance with bond_close flush of workqueue */
+               if (!rtnl_trylock()) {
+                       read_lock(&bond->lock);
+                       delta_in_ticks = 1;
+                       should_notify_peers = false;
+                       goto re_arm;
+               }
+
                read_lock(&bond->lock);
 
                bond_ab_arp_commit(bond, delta_in_ticks);
@@ -3156,13 +3168,18 @@ void bond_activebackup_arp_mon(struct work_struct *work)
        bond_ab_arp_probe(bond);
 
 re_arm:
-       if (bond->params.arp_interval && !bond->kill_timers)
+       if (bond->params.arp_interval)
                queue_delayed_work(bond->wq, &bond->arp_work, delta_in_ticks);
-out:
+
        read_unlock(&bond->lock);
 
        if (should_notify_peers) {
-               rtnl_lock();
+               if (!rtnl_trylock()) {
+                       read_lock(&bond->lock);
+                       bond->send_peer_notif++;
+                       read_unlock(&bond->lock);
+                       return;
+               }
                netdev_bonding_change(bond->dev, NETDEV_NOTIFY_PEERS);
                rtnl_unlock();
        }
@@ -3424,8 +3441,6 @@ static int bond_open(struct net_device *bond_dev)
        struct slave *slave;
        int i;
 
-       bond->kill_timers = 0;
-
        /* reset slave->backup and slave->inactive */
        read_lock(&bond->lock);
        if (bond->slave_cnt > 0) {
@@ -3494,33 +3509,30 @@ static int bond_close(struct net_device *bond_dev)
 
        bond->send_peer_notif = 0;
 
-       /* signal timers not to re-arm */
-       bond->kill_timers = 1;
-
        write_unlock_bh(&bond->lock);
 
        if (bond->params.miimon) {  /* link check interval, in milliseconds. */
-               cancel_delayed_work(&bond->mii_work);
+               cancel_delayed_work_sync(&bond->mii_work);
        }
 
        if (bond->params.arp_interval) {  /* arp interval, in milliseconds. */
-               cancel_delayed_work(&bond->arp_work);
+               cancel_delayed_work_sync(&bond->arp_work);
        }
 
        switch (bond->params.mode) {
        case BOND_MODE_8023AD:
-               cancel_delayed_work(&bond->ad_work);
+               cancel_delayed_work_sync(&bond->ad_work);
                break;
        case BOND_MODE_TLB:
        case BOND_MODE_ALB:
-               cancel_delayed_work(&bond->alb_work);
+               cancel_delayed_work_sync(&bond->alb_work);
                break;
        default:
                break;
        }
 
        if (delayed_work_pending(&bond->mcast_work))
-               cancel_delayed_work(&bond->mcast_work);
+               cancel_delayed_work_sync(&bond->mcast_work);
 
        if (bond_is_lb(bond)) {
                /* Must be called only after all
@@ -4367,26 +4379,22 @@ static void bond_setup(struct net_device *bond_dev)
 
 static void bond_work_cancel_all(struct bonding *bond)
 {
-       write_lock_bh(&bond->lock);
-       bond->kill_timers = 1;
-       write_unlock_bh(&bond->lock);
-
        if (bond->params.miimon && delayed_work_pending(&bond->mii_work))
-               cancel_delayed_work(&bond->mii_work);
+               cancel_delayed_work_sync(&bond->mii_work);
 
        if (bond->params.arp_interval && delayed_work_pending(&bond->arp_work))
-               cancel_delayed_work(&bond->arp_work);
+               cancel_delayed_work_sync(&bond->arp_work);
 
        if (bond->params.mode == BOND_MODE_ALB &&
            delayed_work_pending(&bond->alb_work))
-               cancel_delayed_work(&bond->alb_work);
+               cancel_delayed_work_sync(&bond->alb_work);
 
        if (bond->params.mode == BOND_MODE_8023AD &&
            delayed_work_pending(&bond->ad_work))
-               cancel_delayed_work(&bond->ad_work);
+               cancel_delayed_work_sync(&bond->ad_work);
 
        if (delayed_work_pending(&bond->mcast_work))
-               cancel_delayed_work(&bond->mcast_work);
+               cancel_delayed_work_sync(&bond->mcast_work);
 }
 
 /*
index 82fec5fc75d7fd84fc861516cd356ae793feb41c..1aecc37e5b4dcd041cefecc1fb3e7813ab39d8b0 100644 (file)
@@ -222,7 +222,6 @@ struct bonding {
                               struct slave *);
        rwlock_t lock;
        rwlock_t curr_slave_lock;
-       s8       kill_timers;
        u8       send_peer_notif;
        s8       setup_by_slave;
        s8       igmp_retrans;
index 627a5807836d6aff162a5c387965a8502747d00b..aec7212ac9835a4aba89b24641238a0e2d08448e 100644 (file)
@@ -23,8 +23,8 @@
  * (you will need to reboot afterwards) */
 /* #define BNX2X_STOP_ON_ERROR */
 
-#define DRV_MODULE_VERSION      "1.70.00-0"
-#define DRV_MODULE_RELDATE      "2011/06/13"
+#define DRV_MODULE_VERSION      "1.70.30-0"
+#define DRV_MODULE_RELDATE      "2011/10/25"
 #define BNX2X_BC_VER            0x040200
 
 #if defined(CONFIG_DCB)
index 1a6e37ce730c4deeecd119b0740da0bbed6a599b..f0ca8b27a55eea7b96f3984b03aaead457ba3db8 100644 (file)
@@ -329,6 +329,7 @@ static int bnx2x_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
                        PORT_HW_CFG_PHY_SELECTION_FIRST_PHY;
                break;
        case PORT_FIBRE:
+       case PORT_DA:
                if (bp->port.supported[cfg_idx] & SUPPORTED_FIBRE)
                        break; /* no port change */
 
index e44b858ff12f09fdbd20326293da2f75be3b1ed3..fc754cb6cc0fbf95967f40ba37ae4aca0b50b049 100644 (file)
@@ -2550,7 +2550,7 @@ struct host_func_stats {
 
 #define BCM_5710_FW_MAJOR_VERSION                      7
 #define BCM_5710_FW_MINOR_VERSION                      0
-#define BCM_5710_FW_REVISION_VERSION           23
+#define BCM_5710_FW_REVISION_VERSION           29
 #define BCM_5710_FW_ENGINEERING_VERSION                0
 #define BCM_5710_FW_COMPILE_FLAGS                      1
 
index 818723c9e6783aa97b6e2340cd84c7ab44578cfa..bce203fa4b9e274c24e06e52b133a0936328c4e5 100644 (file)
@@ -45,6 +45,9 @@
 #define MCPR_IMC_COMMAND_READ_OP       1
 #define MCPR_IMC_COMMAND_WRITE_OP      2
 
+/* LED Blink rate that will achieve ~15.9Hz */
+#define LED_BLINK_RATE_VAL_E3          354
+#define LED_BLINK_RATE_VAL_E1X_E2      480
 /***********************************************************/
 /*                     Shortcut definitions               */
 /***********************************************************/
 
 #define MAX_PACKET_SIZE                                        (9700)
 #define WC_UC_TIMEOUT                                  100
+#define MAX_KR_LINK_RETRY                              4
 
 /**********************************************************/
 /*                     INTERFACE                          */
@@ -1490,6 +1494,18 @@ static void bnx2x_set_xumac_nig(struct link_params *params,
               NIG_REG_P0_MAC_PAUSE_OUT_EN, tx_pause_en);
 }
 
+static void bnx2x_umac_disable(struct link_params *params)
+{
+       u32 umac_base = params->port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
+       struct bnx2x *bp = params->bp;
+       if (!(REG_RD(bp, MISC_REG_RESET_REG_2) &
+                  (MISC_REGISTERS_RESET_REG_2_UMAC0 << params->port)))
+               return;
+
+       /* Disable RX and TX */
+       REG_WR(bp, umac_base + UMAC_REG_COMMAND_CONFIG, 0);
+}
+
 static void bnx2x_umac_enable(struct link_params *params,
                            struct link_vars *vars, u8 lb)
 {
@@ -1599,8 +1615,9 @@ static u8 bnx2x_is_4_port_mode(struct bnx2x *bp)
 }
 
 /* Define the XMAC mode */
-static void bnx2x_xmac_init(struct bnx2x *bp, u32 max_speed)
+static void bnx2x_xmac_init(struct link_params *params, u32 max_speed)
 {
+       struct bnx2x *bp = params->bp;
        u32 is_port4mode = bnx2x_is_4_port_mode(bp);
 
        /**
@@ -1610,7 +1627,8 @@ static void bnx2x_xmac_init(struct bnx2x *bp, u32 max_speed)
        * ports of the path
        **/
 
-       if (is_port4mode && (REG_RD(bp, MISC_REG_RESET_REG_2) &
+       if ((CHIP_NUM(bp) == CHIP_NUM_57840) &&
+           (REG_RD(bp, MISC_REG_RESET_REG_2) &
             MISC_REGISTERS_RESET_REG_2_XMAC)) {
                DP(NETIF_MSG_LINK,
                   "XMAC already out of reset in 4-port mode\n");
@@ -1677,10 +1695,6 @@ static void bnx2x_xmac_disable(struct link_params *params)
                       (pfc_ctrl | (1<<1)));
                DP(NETIF_MSG_LINK, "Disable XMAC on port %x\n", port);
                REG_WR(bp, xmac_base + XMAC_REG_CTRL, 0);
-               usleep_range(1000, 1000);
-               bnx2x_set_xumac_nig(params, 0, 0);
-               REG_WR(bp, xmac_base + XMAC_REG_CTRL,
-                      XMAC_CTRL_REG_SOFT_RESET);
        }
 }
 
@@ -1693,7 +1707,7 @@ static int bnx2x_xmac_enable(struct link_params *params,
 
        xmac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
 
-       bnx2x_xmac_init(bp, vars->line_speed);
+       bnx2x_xmac_init(params, vars->line_speed);
 
        /*
         * This register determines on which events the MAC will assert
@@ -3575,6 +3589,11 @@ static void bnx2x_warpcore_enable_AN_KR(struct bnx2x_phy *phy,
        u16 val16 = 0, lane, bam37 = 0;
        struct bnx2x *bp = params->bp;
        DP(NETIF_MSG_LINK, "Enable Auto Negotiation for KR\n");
+
+       /* Disable Autoneg: re-enable it after adv is done. */
+       bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
+                        MDIO_WC_REG_IEEE0BLK_MIICNTL, 0);
+
        /* Check adding advertisement for 1G KX */
        if (((vars->line_speed == SPEED_AUTO_NEG) &&
             (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
@@ -3616,9 +3635,6 @@ static void bnx2x_warpcore_enable_AN_KR(struct bnx2x_phy *phy,
        bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
                         MDIO_WC_REG_CL72_USERB0_CL72_2P5_DEF_CTRL,
                         0x03f0);
-       bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
-                        MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL,
-                        0x383f);
 
        /* Advertised speeds */
        bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
@@ -3645,19 +3661,22 @@ static void bnx2x_warpcore_enable_AN_KR(struct bnx2x_phy *phy,
        /* Advertise pause */
        bnx2x_ext_phy_set_pause(params, phy, vars);
 
-       /* Enable Autoneg */
-       bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
-                        MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x1000);
-
-       /* Over 1G - AN local device user page 1 */
-       bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
-                       MDIO_WC_REG_DIGITAL3_UP1, 0x1f);
+       vars->rx_tx_asic_rst = MAX_KR_LINK_RETRY;
 
        bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
                        MDIO_WC_REG_DIGITAL5_MISC7, &val16);
 
        bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
                         MDIO_WC_REG_DIGITAL5_MISC7, val16 | 0x100);
+
+       /* Over 1G - AN local device user page 1 */
+       bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
+                       MDIO_WC_REG_DIGITAL3_UP1, 0x1f);
+
+       /* Enable Autoneg */
+       bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
+                        MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x1000);
+
 }
 
 static void bnx2x_warpcore_set_10G_KR(struct bnx2x_phy *phy,
@@ -4126,6 +4145,85 @@ static int bnx2x_is_sfp_module_plugged(struct bnx2x_phy *phy,
        else
                return 0;
 }
+static int bnx2x_warpcore_get_sigdet(struct bnx2x_phy *phy,
+                                       struct link_params *params)
+{
+       u16 gp2_status_reg0, lane;
+       struct bnx2x *bp = params->bp;
+
+       lane = bnx2x_get_warpcore_lane(phy, params);
+
+       bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD, MDIO_WC_REG_GP2_STATUS_GP_2_0,
+                                &gp2_status_reg0);
+
+       return (gp2_status_reg0 >> (8+lane)) & 0x1;
+}
+
+static void bnx2x_warpcore_config_runtime(struct bnx2x_phy *phy,
+                                      struct link_params *params,
+                                      struct link_vars *vars)
+{
+       struct bnx2x *bp = params->bp;
+       u32 serdes_net_if;
+       u16 gp_status1 = 0, lnkup = 0, lnkup_kr = 0;
+       u16 lane = bnx2x_get_warpcore_lane(phy, params);
+
+       vars->turn_to_run_wc_rt = vars->turn_to_run_wc_rt ? 0 : 1;
+
+       if (!vars->turn_to_run_wc_rt)
+               return;
+
+       /* return if there is no link partner */
+       if (!(bnx2x_warpcore_get_sigdet(phy, params))) {
+               DP(NETIF_MSG_LINK, "bnx2x_warpcore_get_sigdet false\n");
+               return;
+       }
+
+       if (vars->rx_tx_asic_rst) {
+               serdes_net_if = (REG_RD(bp, params->shmem_base +
+                               offsetof(struct shmem_region, dev_info.
+                               port_hw_config[params->port].default_cfg)) &
+                               PORT_HW_CFG_NET_SERDES_IF_MASK);
+
+               switch (serdes_net_if) {
+               case PORT_HW_CFG_NET_SERDES_IF_KR:
+                       /* Do we get link yet? */
+                       bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD, 0x81d1,
+                                                               &gp_status1);
+                       lnkup = (gp_status1 >> (8+lane)) & 0x1;/* 1G */
+                               /*10G KR*/
+                       lnkup_kr = (gp_status1 >> (12+lane)) & 0x1;
+
+                       DP(NETIF_MSG_LINK,
+                               "gp_status1 0x%x\n", gp_status1);
+
+                       if (lnkup_kr || lnkup) {
+                                       vars->rx_tx_asic_rst = 0;
+                                       DP(NETIF_MSG_LINK,
+                                       "link up, rx_tx_asic_rst 0x%x\n",
+                                       vars->rx_tx_asic_rst);
+                       } else {
+                               /*reset the lane to see if link comes up.*/
+                               bnx2x_warpcore_reset_lane(bp, phy, 1);
+                               bnx2x_warpcore_reset_lane(bp, phy, 0);
+
+                               /* restart Autoneg */
+                               bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
+                                       MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x1200);
+
+                               vars->rx_tx_asic_rst--;
+                               DP(NETIF_MSG_LINK, "0x%x retry left\n",
+                               vars->rx_tx_asic_rst);
+                       }
+                       break;
+
+               default:
+                       break;
+               }
+
+       } /*params->rx_tx_asic_rst*/
+
+}
 
 static void bnx2x_warpcore_config_init(struct bnx2x_phy *phy,
                                       struct link_params *params,
@@ -5896,7 +5994,13 @@ int bnx2x_set_led(struct link_params *params,
                       SHARED_HW_CFG_LED_MAC1);
 
                tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
-               EMAC_WR(bp, EMAC_REG_EMAC_LED, (tmp | EMAC_LED_OVERRIDE));
+               if (params->phy[EXT_PHY1].type ==
+                         PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE)
+                       EMAC_WR(bp, EMAC_REG_EMAC_LED, tmp & 0xfff1);
+               else {
+                       EMAC_WR(bp, EMAC_REG_EMAC_LED,
+                               (tmp | EMAC_LED_OVERRIDE));
+               }
                break;
 
        case LED_MODE_OPER:
@@ -5949,17 +6053,33 @@ int bnx2x_set_led(struct link_params *params,
                        else
                                REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4,
                                       hw_led_mode);
+               } else if ((params->phy[EXT_PHY1].type ==
+                           PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE) &&
+                          (mode != LED_MODE_OPER)) {
+                       REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
+                       tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
+                       EMAC_WR(bp, EMAC_REG_EMAC_LED, tmp | 0x3);
                } else
-                       REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, hw_led_mode);
+                       REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4,
+                              hw_led_mode);
 
                REG_WR(bp, NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0 + port*4, 0);
                /* Set blinking rate to ~15.9Hz */
-               REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_P0 + port*4,
-                      LED_BLINK_RATE_VAL);
+               if (CHIP_IS_E3(bp))
+                       REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_P0 + port*4,
+                              LED_BLINK_RATE_VAL_E3);
+               else
+                       REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_P0 + port*4,
+                              LED_BLINK_RATE_VAL_E1X_E2);
                REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_ENA_P0 +
                       port*4, 1);
-               tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
-               EMAC_WR(bp, EMAC_REG_EMAC_LED, (tmp & (~EMAC_LED_OVERRIDE)));
+               if ((params->phy[EXT_PHY1].type !=
+                    PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE) &&
+                   (mode != LED_MODE_OPER)) {
+                       tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
+                       EMAC_WR(bp, EMAC_REG_EMAC_LED,
+                               (tmp & (~EMAC_LED_OVERRIDE)));
+               }
 
                if (CHIP_IS_E1(bp) &&
                    ((speed == SPEED_2500) ||
@@ -6218,8 +6338,10 @@ static int bnx2x_update_link_down(struct link_params *params,
                       MISC_REGISTERS_RESET_REG_2_CLEAR,
               (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
        }
-       if (CHIP_IS_E3(bp))
+       if (CHIP_IS_E3(bp)) {
                bnx2x_xmac_disable(params);
+               bnx2x_umac_disable(params);
+       }
 
        return 0;
 }
@@ -10205,22 +10327,6 @@ static int bnx2x_54618se_config_init(struct bnx2x_phy *phy,
        return 0;
 }
 
-static void bnx2x_54618se_set_link_led(struct bnx2x_phy *phy,
-                                      struct link_params *params, u8 mode)
-{
-       struct bnx2x *bp = params->bp;
-       DP(NETIF_MSG_LINK, "54618SE set link led (mode=%x)\n", mode);
-       switch (mode) {
-       case LED_MODE_FRONT_PANEL_OFF:
-       case LED_MODE_OFF:
-       case LED_MODE_OPER:
-       case LED_MODE_ON:
-       default:
-               break;
-       }
-       return;
-}
-
 static void bnx2x_54618se_link_reset(struct bnx2x_phy *phy,
                                     struct link_params *params)
 {
@@ -10997,7 +11103,7 @@ static struct bnx2x_phy phy_54618se = {
        .config_loopback = (config_loopback_t)bnx2x_54618se_config_loopback,
        .format_fw_ver  = (format_fw_ver_t)NULL,
        .hw_reset       = (hw_reset_t)NULL,
-       .set_link_led   = (set_link_led_t)bnx2x_54618se_set_link_led,
+       .set_link_led   = (set_link_led_t)NULL,
        .phy_specific_func = (phy_specific_func_t)NULL
 };
 /*****************************************************************/
@@ -11718,8 +11824,10 @@ int bnx2x_link_reset(struct link_params *params, struct link_vars *vars,
        /* Stop BigMac rx */
        if (!CHIP_IS_E3(bp))
                bnx2x_bmac_rx_disable(bp, port);
-       else
+       else {
                bnx2x_xmac_disable(params);
+               bnx2x_umac_disable(params);
+       }
        /* disable emac */
        if (!CHIP_IS_E3(bp))
                REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
@@ -11757,14 +11865,21 @@ int bnx2x_link_reset(struct link_params *params, struct link_vars *vars,
        if (params->phy[INT_PHY].link_reset)
                params->phy[INT_PHY].link_reset(
                        &params->phy[INT_PHY], params);
-       /* reset BigMac */
-       REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
-              (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
 
        /* disable nig ingress interface */
        if (!CHIP_IS_E3(bp)) {
+               /* reset BigMac */
+               REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
+                      (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
                REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0);
                REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0);
+       } else {
+               u32 xmac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
+               bnx2x_set_xumac_nig(params, 0, 0);
+               if (REG_RD(bp, MISC_REG_RESET_REG_2) &
+                   MISC_REGISTERS_RESET_REG_2_XMAC)
+                       REG_WR(bp, xmac_base + XMAC_REG_CTRL,
+                              XMAC_CTRL_REG_SOFT_RESET);
        }
        vars->link_up = 0;
        vars->phy_flags = 0;
@@ -12332,11 +12447,6 @@ void bnx2x_period_func(struct link_params *params, struct link_vars *vars)
 {
        struct bnx2x *bp = params->bp;
        u16 phy_idx;
-       if (!params) {
-               DP(NETIF_MSG_LINK, "Uninitialized params !\n");
-               return;
-       }
-
        for (phy_idx = INT_PHY; phy_idx < MAX_PHYS; phy_idx++) {
                if (params->phy[phy_idx].flags & FLAGS_TX_ERROR_CHECK) {
                        bnx2x_set_aer_mmd(params, &params->phy[phy_idx]);
@@ -12345,8 +12455,13 @@ void bnx2x_period_func(struct link_params *params, struct link_vars *vars)
                }
        }
 
-       if (CHIP_IS_E3(bp))
+       if (CHIP_IS_E3(bp)) {
+               struct bnx2x_phy *phy = &params->phy[INT_PHY];
+               bnx2x_set_aer_mmd(params, phy);
                bnx2x_check_over_curr(params, vars);
+               bnx2x_warpcore_config_runtime(phy, params, vars);
+       }
+
 }
 
 u8 bnx2x_hw_lock_required(struct bnx2x *bp, u32 shmem_base, u32 shmem2_base)
index c12db6da213efe7f25da6000774de35b78939642..2a46e633abe9c7992566c2e0fe0b89fa32816d8c 100644 (file)
@@ -303,6 +303,9 @@ struct link_vars {
 #define PERIODIC_FLAGS_LINK_EVENT      0x0001
 
        u32 aeu_int_mask;
+       u8 rx_tx_asic_rst;
+       u8 turn_to_run_wc_rt;
+       u16 rsrv2;
 };
 
 /***********************************************************/
index e0ff96193c49d81f896677a8adaf717ce8b51e44..824b8e6021f6eff17299350a1e6e9af05380b448 100644 (file)
@@ -428,28 +428,33 @@ static inline struct be_sge *nonembedded_sgl(struct be_mcc_wrb *wrb)
        return &wrb->payload.sgl[0];
 }
 
-/* Don't touch the hdr after it's prepared */
-static void be_wrb_hdr_prepare(struct be_mcc_wrb *wrb, int payload_len,
-                               bool embedded, u8 sge_cnt, u32 opcode)
-{
-       if (embedded)
-               wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
-       else
-               wrb->embedded |= (sge_cnt & MCC_WRB_SGE_CNT_MASK) <<
-                               MCC_WRB_SGE_CNT_SHIFT;
-       wrb->payload_length = payload_len;
-       wrb->tag0 = opcode;
-       be_dws_cpu_to_le(wrb, 8);
-}
 
 /* Don't touch the hdr after it's prepared */
-static void be_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
-                               u8 subsystem, u8 opcode, int cmd_len)
+/* mem will be NULL for embedded commands */
+static void be_wrb_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
+                               u8 subsystem, u8 opcode, int cmd_len,
+                               struct be_mcc_wrb *wrb, struct be_dma_mem *mem)
 {
+       struct be_sge *sge;
+
        req_hdr->opcode = opcode;
        req_hdr->subsystem = subsystem;
        req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
        req_hdr->version = 0;
+
+       wrb->tag0 = opcode;
+       wrb->tag1 = subsystem;
+       wrb->payload_length = cmd_len;
+       if (mem) {
+               wrb->embedded |= (1 & MCC_WRB_SGE_CNT_MASK) <<
+                       MCC_WRB_SGE_CNT_SHIFT;
+               sge = nonembedded_sgl(wrb);
+               sge->pa_hi = cpu_to_le32(upper_32_bits(mem->dma));
+               sge->pa_lo = cpu_to_le32(mem->dma & 0xFFFFFFFF);
+               sge->len = cpu_to_le32(mem->size);
+       } else
+               wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
+       be_dws_cpu_to_le(wrb, 8);
 }
 
 static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
@@ -586,10 +591,8 @@ int be_cmd_eq_create(struct be_adapter *adapter,
        wrb = wrb_from_mbox(adapter);
        req = embedded_payload(wrb);
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, OPCODE_COMMON_EQ_CREATE);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
-               OPCODE_COMMON_EQ_CREATE, sizeof(*req));
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+               OPCODE_COMMON_EQ_CREATE, sizeof(*req), wrb, NULL);
 
        req->num_pages =  cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
 
@@ -632,12 +635,8 @@ int be_cmd_mac_addr_query(struct be_adapter *adapter, u8 *mac_addr,
        }
        req = embedded_payload(wrb);
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
-                       OPCODE_COMMON_NTWK_MAC_QUERY);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
-               OPCODE_COMMON_NTWK_MAC_QUERY, sizeof(*req));
-
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+               OPCODE_COMMON_NTWK_MAC_QUERY, sizeof(*req), wrb, NULL);
        req->type = type;
        if (permanent) {
                req->permanent = 1;
@@ -674,11 +673,8 @@ int be_cmd_pmac_add(struct be_adapter *adapter, u8 *mac_addr,
        }
        req = embedded_payload(wrb);
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
-                       OPCODE_COMMON_NTWK_PMAC_ADD);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
-               OPCODE_COMMON_NTWK_PMAC_ADD, sizeof(*req));
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+               OPCODE_COMMON_NTWK_PMAC_ADD, sizeof(*req), wrb, NULL);
 
        req->hdr.domain = domain;
        req->if_id = cpu_to_le32(if_id);
@@ -692,6 +688,10 @@ int be_cmd_pmac_add(struct be_adapter *adapter, u8 *mac_addr,
 
 err:
        spin_unlock_bh(&adapter->mcc_lock);
+
+        if (status == MCC_STATUS_UNAUTHORIZED_REQUEST)
+               status = -EPERM;
+
        return status;
 }
 
@@ -711,11 +711,8 @@ int be_cmd_pmac_del(struct be_adapter *adapter, u32 if_id, u32 pmac_id, u32 dom)
        }
        req = embedded_payload(wrb);
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
-                       OPCODE_COMMON_NTWK_PMAC_DEL);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
-               OPCODE_COMMON_NTWK_PMAC_DEL, sizeof(*req));
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+               OPCODE_COMMON_NTWK_PMAC_DEL, sizeof(*req), wrb, NULL);
 
        req->hdr.domain = dom;
        req->if_id = cpu_to_le32(if_id);
@@ -746,11 +743,8 @@ int be_cmd_cq_create(struct be_adapter *adapter,
        req = embedded_payload(wrb);
        ctxt = &req->context;
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
-                       OPCODE_COMMON_CQ_CREATE);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
-               OPCODE_COMMON_CQ_CREATE, sizeof(*req));
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+               OPCODE_COMMON_CQ_CREATE, sizeof(*req), wrb, NULL);
 
        req->num_pages =  cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
        if (lancer_chip(adapter)) {
@@ -822,11 +816,8 @@ int be_cmd_mccq_ext_create(struct be_adapter *adapter,
        req = embedded_payload(wrb);
        ctxt = &req->context;
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
-                       OPCODE_COMMON_MCC_CREATE_EXT);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
-                       OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req));
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+                       OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req), wrb, NULL);
 
        req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
        if (lancer_chip(adapter)) {
@@ -882,11 +873,8 @@ int be_cmd_mccq_org_create(struct be_adapter *adapter,
        req = embedded_payload(wrb);
        ctxt = &req->context;
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
-                       OPCODE_COMMON_MCC_CREATE);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
-                       OPCODE_COMMON_MCC_CREATE, sizeof(*req));
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+                       OPCODE_COMMON_MCC_CREATE, sizeof(*req), wrb, NULL);
 
        req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
 
@@ -943,11 +931,8 @@ int be_cmd_txq_create(struct be_adapter *adapter,
        req = embedded_payload(wrb);
        ctxt = &req->context;
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
-                       OPCODE_ETH_TX_CREATE);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, OPCODE_ETH_TX_CREATE,
-               sizeof(*req));
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
+               OPCODE_ETH_TX_CREATE, sizeof(*req), wrb, NULL);
 
        if (lancer_chip(adapter)) {
                req->hdr.version = 1;
@@ -999,11 +984,8 @@ int be_cmd_rxq_create(struct be_adapter *adapter,
        }
        req = embedded_payload(wrb);
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
-                       OPCODE_ETH_RX_CREATE);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, OPCODE_ETH_RX_CREATE,
-               sizeof(*req));
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
+                               OPCODE_ETH_RX_CREATE, sizeof(*req), wrb, NULL);
 
        req->cq_id = cpu_to_le16(cq_id);
        req->frag_size = fls(frag_size) - 1;
@@ -1071,9 +1053,8 @@ int be_cmd_q_destroy(struct be_adapter *adapter, struct be_queue_info *q,
                BUG();
        }
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, opcode);
-
-       be_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req));
+       be_wrb_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req), wrb,
+                               NULL);
        req->id = cpu_to_le16(q->id);
 
        status = be_mbox_notify_wait(adapter);
@@ -1100,9 +1081,8 @@ int be_cmd_rxq_destroy(struct be_adapter *adapter, struct be_queue_info *q)
        }
        req = embedded_payload(wrb);
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, OPCODE_ETH_RX_DESTROY);
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, OPCODE_ETH_RX_DESTROY,
-               sizeof(*req));
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
+                       OPCODE_ETH_RX_DESTROY, sizeof(*req), wrb, NULL);
        req->id = cpu_to_le16(q->id);
 
        status = be_mcc_notify_wait(adapter);
@@ -1133,12 +1113,8 @@ int be_cmd_if_create(struct be_adapter *adapter, u32 cap_flags, u32 en_flags,
        }
        req = embedded_payload(wrb);
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
-                       OPCODE_COMMON_NTWK_INTERFACE_CREATE);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
-               OPCODE_COMMON_NTWK_INTERFACE_CREATE, sizeof(*req));
-
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+               OPCODE_COMMON_NTWK_INTERFACE_CREATE, sizeof(*req), wrb, NULL);
        req->hdr.domain = domain;
        req->capability_flags = cpu_to_le32(cap_flags);
        req->enable_flags = cpu_to_le32(en_flags);
@@ -1182,12 +1158,8 @@ int be_cmd_if_destroy(struct be_adapter *adapter, u32 interface_id, u32 domain)
        }
        req = embedded_payload(wrb);
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
-                       OPCODE_COMMON_NTWK_INTERFACE_DESTROY);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
-               OPCODE_COMMON_NTWK_INTERFACE_DESTROY, sizeof(*req));
-
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+               OPCODE_COMMON_NTWK_INTERFACE_DESTROY, sizeof(*req), wrb, NULL);
        req->hdr.domain = domain;
        req->interface_id = cpu_to_le32(interface_id);
 
@@ -1205,7 +1177,6 @@ int be_cmd_get_stats(struct be_adapter *adapter, struct be_dma_mem *nonemb_cmd)
 {
        struct be_mcc_wrb *wrb;
        struct be_cmd_req_hdr *hdr;
-       struct be_sge *sge;
        int status = 0;
 
        if (MODULO(adapter->work_counter, be_get_temp_freq) == 0)
@@ -1219,22 +1190,13 @@ int be_cmd_get_stats(struct be_adapter *adapter, struct be_dma_mem *nonemb_cmd)
                goto err;
        }
        hdr = nonemb_cmd->va;
-       sge = nonembedded_sgl(wrb);
-
-       be_wrb_hdr_prepare(wrb, nonemb_cmd->size, false, 1,
-                       OPCODE_ETH_GET_STATISTICS);
 
-       be_cmd_hdr_prepare(hdr, CMD_SUBSYSTEM_ETH,
-               OPCODE_ETH_GET_STATISTICS, nonemb_cmd->size);
+       be_wrb_cmd_hdr_prepare(hdr, CMD_SUBSYSTEM_ETH,
+               OPCODE_ETH_GET_STATISTICS, nonemb_cmd->size, wrb, nonemb_cmd);
 
        if (adapter->generation == BE_GEN3)
                hdr->version = 1;
 
-       wrb->tag1 = CMD_SUBSYSTEM_ETH;
-       sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
-       sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
-       sge->len = cpu_to_le32(nonemb_cmd->size);
-
        be_mcc_notify(adapter);
        adapter->stats_cmd_sent = true;
 
@@ -1250,7 +1212,6 @@ int lancer_cmd_get_pport_stats(struct be_adapter *adapter,
 
        struct be_mcc_wrb *wrb;
        struct lancer_cmd_req_pport_stats *req;
-       struct be_sge *sge;
        int status = 0;
 
        spin_lock_bh(&adapter->mcc_lock);
@@ -1261,23 +1222,14 @@ int lancer_cmd_get_pport_stats(struct be_adapter *adapter,
                goto err;
        }
        req = nonemb_cmd->va;
-       sge = nonembedded_sgl(wrb);
-
-       be_wrb_hdr_prepare(wrb, nonemb_cmd->size, false, 1,
-                       OPCODE_ETH_GET_PPORT_STATS);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
-                       OPCODE_ETH_GET_PPORT_STATS, nonemb_cmd->size);
 
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
+                       OPCODE_ETH_GET_PPORT_STATS, nonemb_cmd->size, wrb,
+                       nonemb_cmd);
 
        req->cmd_params.params.pport_num = cpu_to_le16(adapter->port_num);
        req->cmd_params.params.reset_stats = 0;
 
-       wrb->tag1 = CMD_SUBSYSTEM_ETH;
-       sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
-       sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
-       sge->len = cpu_to_le32(nonemb_cmd->size);
-
        be_mcc_notify(adapter);
        adapter->stats_cmd_sent = true;
 
@@ -1303,11 +1255,8 @@ int be_cmd_link_status_query(struct be_adapter *adapter, u8 *mac_speed,
        }
        req = embedded_payload(wrb);
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
-                       OPCODE_COMMON_NTWK_LINK_STATUS_QUERY);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
-               OPCODE_COMMON_NTWK_LINK_STATUS_QUERY, sizeof(*req));
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+               OPCODE_COMMON_NTWK_LINK_STATUS_QUERY, sizeof(*req), wrb, NULL);
 
        status = be_mcc_notify_wait(adapter);
        if (!status) {
@@ -1343,11 +1292,9 @@ int be_cmd_get_die_temperature(struct be_adapter *adapter)
        }
        req = embedded_payload(wrb);
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
-                       OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
-               OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES, sizeof(*req));
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+               OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES, sizeof(*req),
+               wrb, NULL);
 
        wrb->tag1 = mccq_index;
 
@@ -1374,11 +1321,8 @@ int be_cmd_get_reg_len(struct be_adapter *adapter, u32 *log_size)
        }
        req = embedded_payload(wrb);
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
-                       OPCODE_COMMON_MANAGE_FAT);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
-               OPCODE_COMMON_MANAGE_FAT, sizeof(*req));
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+               OPCODE_COMMON_MANAGE_FAT, sizeof(*req), wrb, NULL);
        req->fat_operation = cpu_to_le32(QUERY_FAT);
        status = be_mcc_notify_wait(adapter);
        if (!status) {
@@ -1397,7 +1341,6 @@ void be_cmd_get_regs(struct be_adapter *adapter, u32 buf_len, void *buf)
        struct be_dma_mem get_fat_cmd;
        struct be_mcc_wrb *wrb;
        struct be_cmd_req_get_fat *req;
-       struct be_sge *sge;
        u32 offset = 0, total_size, buf_size,
                                log_offset = sizeof(u32), payload_len;
        int status;
@@ -1430,18 +1373,11 @@ void be_cmd_get_regs(struct be_adapter *adapter, u32 buf_len, void *buf)
                        goto err;
                }
                req = get_fat_cmd.va;
-               sge = nonembedded_sgl(wrb);
 
                payload_len = sizeof(struct be_cmd_req_get_fat) + buf_size;
-               be_wrb_hdr_prepare(wrb, payload_len, false, 1,
-                               OPCODE_COMMON_MANAGE_FAT);
-
-               be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
-                               OPCODE_COMMON_MANAGE_FAT, payload_len);
-
-               sge->pa_hi = cpu_to_le32(upper_32_bits(get_fat_cmd.dma));
-               sge->pa_lo = cpu_to_le32(get_fat_cmd.dma & 0xFFFFFFFF);
-               sge->len = cpu_to_le32(get_fat_cmd.size);
+               be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+                               OPCODE_COMMON_MANAGE_FAT, payload_len, wrb,
+                               &get_fat_cmd);
 
                req->fat_operation = cpu_to_le32(RETRIEVE_FAT);
                req->read_log_offset = cpu_to_le32(log_offset);
@@ -1485,11 +1421,9 @@ int be_cmd_get_fw_ver(struct be_adapter *adapter, char *fw_ver,
        }
 
        req = embedded_payload(wrb);
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
-                               OPCODE_COMMON_GET_FW_VERSION);
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
-                               OPCODE_COMMON_GET_FW_VERSION, sizeof(*req));
 
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+               OPCODE_COMMON_GET_FW_VERSION, sizeof(*req), wrb, NULL);
        status = be_mcc_notify_wait(adapter);
        if (!status) {
                struct be_cmd_resp_get_fw_version *resp = embedded_payload(wrb);
@@ -1520,11 +1454,8 @@ int be_cmd_modify_eqd(struct be_adapter *adapter, u32 eq_id, u32 eqd)
        }
        req = embedded_payload(wrb);
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
-                       OPCODE_COMMON_MODIFY_EQ_DELAY);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
-               OPCODE_COMMON_MODIFY_EQ_DELAY, sizeof(*req));
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+               OPCODE_COMMON_MODIFY_EQ_DELAY, sizeof(*req), wrb, NULL);
 
        req->num_eq = cpu_to_le32(1);
        req->delay[0].eq_id = cpu_to_le32(eq_id);
@@ -1555,11 +1486,8 @@ int be_cmd_vlan_config(struct be_adapter *adapter, u32 if_id, u16 *vtag_array,
        }
        req = embedded_payload(wrb);
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
-                       OPCODE_COMMON_NTWK_VLAN_CONFIG);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
-               OPCODE_COMMON_NTWK_VLAN_CONFIG, sizeof(*req));
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+               OPCODE_COMMON_NTWK_VLAN_CONFIG, sizeof(*req), wrb, NULL);
 
        req->interface_id = if_id;
        req->promiscuous = promiscuous;
@@ -1582,7 +1510,6 @@ int be_cmd_rx_filter(struct be_adapter *adapter, u32 flags, u32 value)
        struct be_mcc_wrb *wrb;
        struct be_dma_mem *mem = &adapter->rx_filter;
        struct be_cmd_req_rx_filter *req = mem->va;
-       struct be_sge *sge;
        int status;
 
        spin_lock_bh(&adapter->mcc_lock);
@@ -1592,16 +1519,10 @@ int be_cmd_rx_filter(struct be_adapter *adapter, u32 flags, u32 value)
                status = -EBUSY;
                goto err;
        }
-       sge = nonembedded_sgl(wrb);
-       sge->pa_hi = cpu_to_le32(upper_32_bits(mem->dma));
-       sge->pa_lo = cpu_to_le32(mem->dma & 0xFFFFFFFF);
-       sge->len = cpu_to_le32(mem->size);
-       be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
-                               OPCODE_COMMON_NTWK_RX_FILTER);
-
        memset(req, 0, sizeof(*req));
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
-                               OPCODE_COMMON_NTWK_RX_FILTER, sizeof(*req));
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+                               OPCODE_COMMON_NTWK_RX_FILTER, sizeof(*req),
+                               wrb, mem);
 
        req->if_id = cpu_to_le32(adapter->if_handle);
        if (flags & IFF_PROMISC) {
@@ -1646,11 +1567,8 @@ int be_cmd_set_flow_control(struct be_adapter *adapter, u32 tx_fc, u32 rx_fc)
        }
        req = embedded_payload(wrb);
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
-                       OPCODE_COMMON_SET_FLOW_CONTROL);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
-               OPCODE_COMMON_SET_FLOW_CONTROL, sizeof(*req));
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+               OPCODE_COMMON_SET_FLOW_CONTROL, sizeof(*req), wrb, NULL);
 
        req->tx_flow_control = cpu_to_le16((u16)tx_fc);
        req->rx_flow_control = cpu_to_le16((u16)rx_fc);
@@ -1678,11 +1596,8 @@ int be_cmd_get_flow_control(struct be_adapter *adapter, u32 *tx_fc, u32 *rx_fc)
        }
        req = embedded_payload(wrb);
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
-                       OPCODE_COMMON_GET_FLOW_CONTROL);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
-               OPCODE_COMMON_GET_FLOW_CONTROL, sizeof(*req));
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+               OPCODE_COMMON_GET_FLOW_CONTROL, sizeof(*req), wrb, NULL);
 
        status = be_mcc_notify_wait(adapter);
        if (!status) {
@@ -1711,11 +1626,8 @@ int be_cmd_query_fw_cfg(struct be_adapter *adapter, u32 *port_num,
        wrb = wrb_from_mbox(adapter);
        req = embedded_payload(wrb);
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
-                       OPCODE_COMMON_QUERY_FIRMWARE_CONFIG);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
-               OPCODE_COMMON_QUERY_FIRMWARE_CONFIG, sizeof(*req));
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+               OPCODE_COMMON_QUERY_FIRMWARE_CONFIG, sizeof(*req), wrb, NULL);
 
        status = be_mbox_notify_wait(adapter);
        if (!status) {
@@ -1742,11 +1654,8 @@ int be_cmd_reset_function(struct be_adapter *adapter)
        wrb = wrb_from_mbox(adapter);
        req = embedded_payload(wrb);
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
-                       OPCODE_COMMON_FUNCTION_RESET);
-
-       be_cmd_hdr_prepare(req, CMD_SUBSYSTEM_COMMON,
-               OPCODE_COMMON_FUNCTION_RESET, sizeof(*req));
+       be_wrb_cmd_hdr_prepare(req, CMD_SUBSYSTEM_COMMON,
+               OPCODE_COMMON_FUNCTION_RESET, sizeof(*req), wrb, NULL);
 
        status = be_mbox_notify_wait(adapter);
 
@@ -1768,11 +1677,8 @@ int be_cmd_rss_config(struct be_adapter *adapter, u8 *rsstable, u16 table_size)
        wrb = wrb_from_mbox(adapter);
        req = embedded_payload(wrb);
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
-               OPCODE_ETH_RSS_CONFIG);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
-               OPCODE_ETH_RSS_CONFIG, sizeof(*req));
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
+               OPCODE_ETH_RSS_CONFIG, sizeof(*req), wrb, NULL);
 
        req->if_id = cpu_to_le32(adapter->if_handle);
        req->enable_rss = cpu_to_le16(RSS_ENABLE_TCP_IPV4 | RSS_ENABLE_IPV4);
@@ -1804,11 +1710,8 @@ int be_cmd_set_beacon_state(struct be_adapter *adapter, u8 port_num,
        }
        req = embedded_payload(wrb);
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
-                       OPCODE_COMMON_ENABLE_DISABLE_BEACON);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
-               OPCODE_COMMON_ENABLE_DISABLE_BEACON, sizeof(*req));
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+               OPCODE_COMMON_ENABLE_DISABLE_BEACON, sizeof(*req), wrb, NULL);
 
        req->port_num = port_num;
        req->beacon_state = state;
@@ -1838,11 +1741,8 @@ int be_cmd_get_beacon_state(struct be_adapter *adapter, u8 port_num, u32 *state)
        }
        req = embedded_payload(wrb);
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
-                       OPCODE_COMMON_GET_BEACON_STATE);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
-               OPCODE_COMMON_GET_BEACON_STATE, sizeof(*req));
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+               OPCODE_COMMON_GET_BEACON_STATE, sizeof(*req), wrb, NULL);
 
        req->port_num = port_num;
 
@@ -1879,13 +1779,10 @@ int lancer_cmd_write_object(struct be_adapter *adapter, struct be_dma_mem *cmd,
 
        req = embedded_payload(wrb);
 
-       be_wrb_hdr_prepare(wrb, sizeof(struct lancer_cmd_req_write_object),
-                       true, 1, OPCODE_COMMON_WRITE_OBJECT);
-       wrb->tag1 = CMD_SUBSYSTEM_COMMON;
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
                                OPCODE_COMMON_WRITE_OBJECT,
-                               sizeof(struct lancer_cmd_req_write_object));
+                               sizeof(struct lancer_cmd_req_write_object), wrb,
+                               NULL);
 
        ctxt = &req->context;
        AMAP_SET_BITS(struct amap_lancer_write_obj_context,
@@ -1938,7 +1835,6 @@ int be_cmd_write_flashrom(struct be_adapter *adapter, struct be_dma_mem *cmd,
 {
        struct be_mcc_wrb *wrb;
        struct be_cmd_write_flashrom *req;
-       struct be_sge *sge;
        int status;
 
        spin_lock_bh(&adapter->mcc_lock);
@@ -1950,17 +1846,9 @@ int be_cmd_write_flashrom(struct be_adapter *adapter, struct be_dma_mem *cmd,
                goto err_unlock;
        }
        req = cmd->va;
-       sge = nonembedded_sgl(wrb);
-
-       be_wrb_hdr_prepare(wrb, cmd->size, false, 1,
-                       OPCODE_COMMON_WRITE_FLASHROM);
-       wrb->tag1 = CMD_SUBSYSTEM_COMMON;
 
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
-               OPCODE_COMMON_WRITE_FLASHROM, cmd->size);
-       sge->pa_hi = cpu_to_le32(upper_32_bits(cmd->dma));
-       sge->pa_lo = cpu_to_le32(cmd->dma & 0xFFFFFFFF);
-       sge->len = cpu_to_le32(cmd->size);
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+               OPCODE_COMMON_WRITE_FLASHROM, cmd->size, wrb, cmd);
 
        req->params.op_type = cpu_to_le32(flash_type);
        req->params.op_code = cpu_to_le32(flash_opcode);
@@ -1998,11 +1886,8 @@ int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc,
        }
        req = embedded_payload(wrb);
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req)+4, true, 0,
-                       OPCODE_COMMON_READ_FLASHROM);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
-               OPCODE_COMMON_READ_FLASHROM, sizeof(*req)+4);
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+               OPCODE_COMMON_READ_FLASHROM, sizeof(*req)+4, wrb, NULL);
 
        req->params.op_type = cpu_to_le32(IMG_TYPE_REDBOOT);
        req->params.op_code = cpu_to_le32(FLASHROM_OPER_REPORT);
@@ -2023,7 +1908,6 @@ int be_cmd_enable_magic_wol(struct be_adapter *adapter, u8 *mac,
 {
        struct be_mcc_wrb *wrb;
        struct be_cmd_req_acpi_wol_magic_config *req;
-       struct be_sge *sge;
        int status;
 
        spin_lock_bh(&adapter->mcc_lock);
@@ -2034,19 +1918,12 @@ int be_cmd_enable_magic_wol(struct be_adapter *adapter, u8 *mac,
                goto err;
        }
        req = nonemb_cmd->va;
-       sge = nonembedded_sgl(wrb);
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
-                       OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
-               OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG, sizeof(*req));
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
+               OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG, sizeof(*req), wrb,
+               nonemb_cmd);
        memcpy(req->magic_mac, mac, ETH_ALEN);
 
-       sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
-       sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
-       sge->len = cpu_to_le32(nonemb_cmd->size);
-
        status = be_mcc_notify_wait(adapter);
 
 err:
@@ -2071,12 +1948,9 @@ int be_cmd_set_loopback(struct be_adapter *adapter, u8 port_num,
 
        req = embedded_payload(wrb);
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
-                               OPCODE_LOWLEVEL_SET_LOOPBACK_MODE);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
-                       OPCODE_LOWLEVEL_SET_LOOPBACK_MODE,
-                       sizeof(*req));
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
+                       OPCODE_LOWLEVEL_SET_LOOPBACK_MODE, sizeof(*req), wrb,
+                       NULL);
 
        req->src_port = port_num;
        req->dest_port = port_num;
@@ -2106,11 +1980,8 @@ int be_cmd_loopback_test(struct be_adapter *adapter, u32 port_num,
 
        req = embedded_payload(wrb);
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
-                               OPCODE_LOWLEVEL_LOOPBACK_TEST);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
-                       OPCODE_LOWLEVEL_LOOPBACK_TEST, sizeof(*req));
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
+                       OPCODE_LOWLEVEL_LOOPBACK_TEST, sizeof(*req), wrb, NULL);
        req->hdr.timeout = cpu_to_le32(4);
 
        req->pattern = cpu_to_le64(pattern);
@@ -2136,7 +2007,6 @@ int be_cmd_ddr_dma_test(struct be_adapter *adapter, u64 pattern,
 {
        struct be_mcc_wrb *wrb;
        struct be_cmd_req_ddrdma_test *req;
-       struct be_sge *sge;
        int status;
        int i, j = 0;
 
@@ -2148,15 +2018,8 @@ int be_cmd_ddr_dma_test(struct be_adapter *adapter, u64 pattern,
                goto err;
        }
        req = cmd->va;
-       sge = nonembedded_sgl(wrb);
-       be_wrb_hdr_prepare(wrb, cmd->size, false, 1,
-                               OPCODE_LOWLEVEL_HOST_DDR_DMA);
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
-                       OPCODE_LOWLEVEL_HOST_DDR_DMA, cmd->size);
-
-       sge->pa_hi = cpu_to_le32(upper_32_bits(cmd->dma));
-       sge->pa_lo = cpu_to_le32(cmd->dma & 0xFFFFFFFF);
-       sge->len = cpu_to_le32(cmd->size);
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
+                       OPCODE_LOWLEVEL_HOST_DDR_DMA, cmd->size, wrb, cmd);
 
        req->pattern = cpu_to_le64(pattern);
        req->byte_count = cpu_to_le32(byte_cnt);
@@ -2201,15 +2064,9 @@ int be_cmd_get_seeprom_data(struct be_adapter *adapter,
        req = nonemb_cmd->va;
        sge = nonembedded_sgl(wrb);
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
-                       OPCODE_COMMON_SEEPROM_READ);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
-                       OPCODE_COMMON_SEEPROM_READ, sizeof(*req));
-
-       sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
-       sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
-       sge->len = cpu_to_le32(nonemb_cmd->size);
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+                       OPCODE_COMMON_SEEPROM_READ, sizeof(*req), wrb,
+                       nonemb_cmd);
 
        status = be_mcc_notify_wait(adapter);
 
@@ -2223,7 +2080,6 @@ int be_cmd_get_phy_info(struct be_adapter *adapter,
 {
        struct be_mcc_wrb *wrb;
        struct be_cmd_req_get_phy_info *req;
-       struct be_sge *sge;
        struct be_dma_mem cmd;
        int status;
 
@@ -2244,18 +2100,10 @@ int be_cmd_get_phy_info(struct be_adapter *adapter,
        }
 
        req = cmd.va;
-       sge = nonembedded_sgl(wrb);
-
-       be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
-                               OPCODE_COMMON_GET_PHY_DETAILS);
 
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
-                       OPCODE_COMMON_GET_PHY_DETAILS,
-                       sizeof(*req));
-
-       sge->pa_hi = cpu_to_le32(upper_32_bits(cmd.dma));
-       sge->pa_lo = cpu_to_le32(cmd.dma & 0xFFFFFFFF);
-       sge->len = cpu_to_le32(cmd.size);
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+                       OPCODE_COMMON_GET_PHY_DETAILS, sizeof(*req),
+                       wrb, &cmd);
 
        status = be_mcc_notify_wait(adapter);
        if (!status) {
@@ -2288,11 +2136,8 @@ int be_cmd_set_qos(struct be_adapter *adapter, u32 bps, u32 domain)
 
        req = embedded_payload(wrb);
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
-                               OPCODE_COMMON_SET_QOS);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
-                       OPCODE_COMMON_SET_QOS, sizeof(*req));
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+                       OPCODE_COMMON_SET_QOS, sizeof(*req), wrb, NULL);
 
        req->hdr.domain = domain;
        req->valid_bits = cpu_to_le32(BE_QOS_BITS_NIC);
@@ -2310,7 +2155,6 @@ int be_cmd_get_cntl_attributes(struct be_adapter *adapter)
        struct be_mcc_wrb *wrb;
        struct be_cmd_req_cntl_attribs *req;
        struct be_cmd_resp_cntl_attribs *resp;
-       struct be_sge *sge;
        int status;
        int payload_len = max(sizeof(*req), sizeof(*resp));
        struct mgmt_controller_attrib *attribs;
@@ -2335,15 +2179,10 @@ int be_cmd_get_cntl_attributes(struct be_adapter *adapter)
                goto err;
        }
        req = attribs_cmd.va;
-       sge = nonembedded_sgl(wrb);
 
-       be_wrb_hdr_prepare(wrb, payload_len, false, 1,
-                       OPCODE_COMMON_GET_CNTL_ATTRIBUTES);
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
-                        OPCODE_COMMON_GET_CNTL_ATTRIBUTES, payload_len);
-       sge->pa_hi = cpu_to_le32(upper_32_bits(attribs_cmd.dma));
-       sge->pa_lo = cpu_to_le32(attribs_cmd.dma & 0xFFFFFFFF);
-       sge->len = cpu_to_le32(attribs_cmd.size);
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+                        OPCODE_COMMON_GET_CNTL_ATTRIBUTES, payload_len, wrb,
+                       &attribs_cmd);
 
        status = be_mbox_notify_wait(adapter);
        if (!status) {
@@ -2376,11 +2215,8 @@ int be_cmd_req_native_mode(struct be_adapter *adapter)
 
        req = embedded_payload(wrb);
 
-       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
-               OPCODE_COMMON_SET_DRIVER_FUNCTION_CAP);
-
-       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
-               OPCODE_COMMON_SET_DRIVER_FUNCTION_CAP, sizeof(*req));
+       be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+               OPCODE_COMMON_SET_DRIVER_FUNCTION_CAP, sizeof(*req), wrb, NULL);
 
        req->valid_cap_flags = cpu_to_le32(CAPABILITY_SW_TIMESTAMPS |
                                CAPABILITY_BE3_NATIVE_ERX_API);
index d6a232a300ad802ad76d2ab9c91a9a1a3784cbd0..21804972fa2f91cc2278823c096f379403a51218 100644 (file)
@@ -229,27 +229,29 @@ static int be_mac_addr_set(struct net_device *netdev, void *p)
        struct be_adapter *adapter = netdev_priv(netdev);
        struct sockaddr *addr = p;
        int status = 0;
+       u8 current_mac[ETH_ALEN];
+       u32 pmac_id = adapter->pmac_id;
 
        if (!is_valid_ether_addr(addr->sa_data))
                return -EADDRNOTAVAIL;
 
-       /* MAC addr configuration will be done in hardware for VFs
-        * by their corresponding PFs. Just copy to netdev addr here
-        */
-       if (!be_physfn(adapter))
-               goto netdev_addr;
-
-       status = be_cmd_pmac_del(adapter, adapter->if_handle,
-                               adapter->pmac_id, 0);
+       status = be_cmd_mac_addr_query(adapter, current_mac,
+                       MAC_ADDRESS_TYPE_NETWORK, false, adapter->if_handle);
        if (status)
-               return status;
+               goto err;
 
-       status = be_cmd_pmac_add(adapter, (u8 *)addr->sa_data,
+       if (memcmp(addr->sa_data, current_mac, ETH_ALEN)) {
+               status = be_cmd_pmac_add(adapter, (u8 *)addr->sa_data,
                                adapter->if_handle, &adapter->pmac_id, 0);
-netdev_addr:
-       if (!status)
-               memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
+               if (status)
+                       goto err;
 
+               be_cmd_pmac_del(adapter, adapter->if_handle, pmac_id, 0);
+       }
+       memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
+       return 0;
+err:
+       dev_err(&adapter->pdev->dev, "MAC %pM set Failed\n", addr->sa_data);
        return status;
 }
 
index 2be46986cbe21399398e8130854e868f02f7f55f..ca1ae985c6df1f4d5b6e69ff059eab8995c15345 100644 (file)
@@ -85,7 +85,7 @@ config APRICOT
 
 config BVME6000_NET
        tristate "BVME6000 Ethernet support"
-       depends on BVME6000MVME16x
+       depends on BVME6000
        ---help---
          This is the driver for the Ethernet interface on BVME4000 and
          BVME6000 VME boards.  Say Y here to include the driver for this chip
index 1ad1f6029af80a3fd84dd0071fbdefb57de2892a..869a2c220a7b4b7c6b727a1696ea94070edab334 100644 (file)
@@ -484,7 +484,7 @@ static void mlx4_free_eq(struct mlx4_dev *dev,
 
        mlx4_mtt_cleanup(dev, &eq->mtt);
        for (i = 0; i < npages; ++i)
-               pci_free_consistent(dev->pdev, PAGE_SIZE,
+               dma_free_coherent(&dev->pdev->dev, PAGE_SIZE,
                                    eq->page_list[i].buf,
                                    eq->page_list[i].map);
 
index ed452ddfe3426606ac651cf22d6136f77e364857..abdfbacab4a68eba2a32b1cf104f448cb09247af 100644 (file)
@@ -205,6 +205,8 @@ int mlx4_QUERY_DEV_CAP(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap)
 #define QUERY_DEV_CAP_MAX_MCG_OFFSET           0x63
 #define QUERY_DEV_CAP_RSVD_PD_OFFSET           0x64
 #define QUERY_DEV_CAP_MAX_PD_OFFSET            0x65
+#define QUERY_DEV_CAP_RSVD_XRC_OFFSET          0x66
+#define QUERY_DEV_CAP_MAX_XRC_OFFSET           0x67
 #define QUERY_DEV_CAP_MAX_COUNTERS_OFFSET      0x68
 #define QUERY_DEV_CAP_RDMARC_ENTRY_SZ_OFFSET   0x80
 #define QUERY_DEV_CAP_QPC_ENTRY_SZ_OFFSET      0x82
@@ -319,6 +321,10 @@ int mlx4_QUERY_DEV_CAP(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap)
        dev_cap->reserved_pds = field >> 4;
        MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_PD_OFFSET);
        dev_cap->max_pds = 1 << (field & 0x3f);
+       MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_XRC_OFFSET);
+       dev_cap->reserved_xrcds = field >> 4;
+       MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_PD_OFFSET);
+       dev_cap->max_xrcds = 1 << (field & 0x1f);
 
        MLX4_GET(size, outbox, QUERY_DEV_CAP_RDMARC_ENTRY_SZ_OFFSET);
        dev_cap->rdmarc_entry_sz = size;
index 1e8ecc3708e22eff9f33d5326af850d9a4c4c7da..bf5ec2286528ca9bbf239c126dd3f706c5b2a55b 100644 (file)
@@ -93,6 +93,8 @@ struct mlx4_dev_cap {
        int max_mcgs;
        int reserved_pds;
        int max_pds;
+       int reserved_xrcds;
+       int max_xrcds;
        int qpc_entry_sz;
        int rdmarc_entry_sz;
        int altc_entry_sz;
index f0ee35df4dd7779aa971fec3d7fa7555d9bc058a..94bbc85a532d18d2fd67caf5406bcd2a6baac26d 100644 (file)
@@ -96,6 +96,8 @@ MODULE_PARM_DESC(log_num_mac, "Log2 max number of MACs per ETH port (1-7)");
 static int log_num_vlan;
 module_param_named(log_num_vlan, log_num_vlan, int, 0444);
 MODULE_PARM_DESC(log_num_vlan, "Log2 max number of VLANs per ETH port (0-7)");
+/* Log2 max number of VLANs per ETH port (0-7) */
+#define MLX4_LOG_NUM_VLANS 7
 
 static int use_prio;
 module_param_named(use_prio, use_prio, bool, 0444);
@@ -220,6 +222,10 @@ static int mlx4_dev_cap(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap)
        dev->caps.reserved_mrws      = dev_cap->reserved_mrws;
        dev->caps.reserved_uars      = dev_cap->reserved_uars;
        dev->caps.reserved_pds       = dev_cap->reserved_pds;
+       dev->caps.reserved_xrcds     = (dev->caps.flags & MLX4_DEV_CAP_FLAG_XRC) ?
+                                       dev_cap->reserved_xrcds : 0;
+       dev->caps.max_xrcds          = (dev->caps.flags & MLX4_DEV_CAP_FLAG_XRC) ?
+                                       dev_cap->max_xrcds : 0;
        dev->caps.mtt_entry_sz       = dev->caps.mtts_per_seg * dev_cap->mtt_entry_sz;
        dev->caps.max_msg_sz         = dev_cap->max_msg_sz;
        dev->caps.page_size_cap      = ~(u32) (dev_cap->min_page_sz - 1);
@@ -230,7 +236,7 @@ static int mlx4_dev_cap(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap)
        dev->caps.max_gso_sz         = dev_cap->max_gso_sz;
 
        dev->caps.log_num_macs  = log_num_mac;
-       dev->caps.log_num_vlans = log_num_vlan;
+       dev->caps.log_num_vlans = MLX4_LOG_NUM_VLANS;
        dev->caps.log_num_prios = use_prio ? 3 : 0;
 
        for (i = 1; i <= dev->caps.num_ports; ++i) {
@@ -912,11 +918,18 @@ static int mlx4_setup_hca(struct mlx4_dev *dev)
                goto err_kar_unmap;
        }
 
+       err = mlx4_init_xrcd_table(dev);
+       if (err) {
+               mlx4_err(dev, "Failed to initialize "
+                        "reliable connection domain table, aborting.\n");
+               goto err_pd_table_free;
+       }
+
        err = mlx4_init_mr_table(dev);
        if (err) {
                mlx4_err(dev, "Failed to initialize "
                         "memory region table, aborting.\n");
-               goto err_pd_table_free;
+               goto err_xrcd_table_free;
        }
 
        err = mlx4_init_eq_table(dev);
@@ -998,6 +1011,13 @@ static int mlx4_setup_hca(struct mlx4_dev *dev)
                                  "ib capabilities (%d). Continuing with "
                                  "caps = 0\n", port, err);
                dev->caps.ib_port_def_cap[port] = ib_port_default_caps;
+
+               err = mlx4_check_ext_port_caps(dev, port);
+               if (err)
+                       mlx4_warn(dev, "failed to get port %d extended "
+                                 "port capabilities support info (%d)."
+                                 " Assuming not supported\n", port, err);
+
                err = mlx4_SET_PORT(dev, port);
                if (err) {
                        mlx4_err(dev, "Failed to set port %d, aborting\n",
@@ -1033,6 +1053,9 @@ err_eq_table_free:
 err_mr_table_free:
        mlx4_cleanup_mr_table(dev);
 
+err_xrcd_table_free:
+       mlx4_cleanup_xrcd_table(dev);
+
 err_pd_table_free:
        mlx4_cleanup_pd_table(dev);
 
@@ -1355,6 +1378,7 @@ err_port:
        mlx4_cmd_use_polling(dev);
        mlx4_cleanup_eq_table(dev);
        mlx4_cleanup_mr_table(dev);
+       mlx4_cleanup_xrcd_table(dev);
        mlx4_cleanup_pd_table(dev);
        mlx4_cleanup_uar_table(dev);
 
@@ -1416,6 +1440,7 @@ static void mlx4_remove_one(struct pci_dev *pdev)
                mlx4_cmd_use_polling(dev);
                mlx4_cleanup_eq_table(dev);
                mlx4_cleanup_mr_table(dev);
+               mlx4_cleanup_xrcd_table(dev);
                mlx4_cleanup_pd_table(dev);
 
                iounmap(priv->kar);
@@ -1489,10 +1514,9 @@ static int __init mlx4_verify_params(void)
                return -1;
        }
 
-       if ((log_num_vlan < 0) || (log_num_vlan > 7)) {
-               pr_warning("mlx4_core: bad num_vlan: %d\n", log_num_vlan);
-               return -1;
-       }
+       if (log_num_vlan != 0)
+               pr_warning("mlx4_core: log_num_vlan - obsolete module param, using %d\n",
+                          MLX4_LOG_NUM_VLANS);
 
        if ((log_mtts_per_seg < 1) || (log_mtts_per_seg > 7)) {
                pr_warning("mlx4_core: bad log_mtts_per_seg: %d\n", log_mtts_per_seg);
index a2fcd8402d37295a04474e502a8594dfb8a4a188..5dfa68ffc11c4ea9bacb8b8bdfff94299fd630c1 100644 (file)
@@ -335,6 +335,7 @@ struct mlx4_priv {
        struct mlx4_cmd         cmd;
 
        struct mlx4_bitmap      pd_bitmap;
+       struct mlx4_bitmap      xrcd_bitmap;
        struct mlx4_uar_table   uar_table;
        struct mlx4_mr_table    mr_table;
        struct mlx4_cq_table    cq_table;
@@ -384,6 +385,7 @@ int mlx4_alloc_eq_table(struct mlx4_dev *dev);
 void mlx4_free_eq_table(struct mlx4_dev *dev);
 
 int mlx4_init_pd_table(struct mlx4_dev *dev);
+int mlx4_init_xrcd_table(struct mlx4_dev *dev);
 int mlx4_init_uar_table(struct mlx4_dev *dev);
 int mlx4_init_mr_table(struct mlx4_dev *dev);
 int mlx4_init_eq_table(struct mlx4_dev *dev);
@@ -393,6 +395,7 @@ int mlx4_init_srq_table(struct mlx4_dev *dev);
 int mlx4_init_mcg_table(struct mlx4_dev *dev);
 
 void mlx4_cleanup_pd_table(struct mlx4_dev *dev);
+void mlx4_cleanup_xrcd_table(struct mlx4_dev *dev);
 void mlx4_cleanup_uar_table(struct mlx4_dev *dev);
 void mlx4_cleanup_mr_table(struct mlx4_dev *dev);
 void mlx4_cleanup_eq_table(struct mlx4_dev *dev);
@@ -450,6 +453,7 @@ void mlx4_init_vlan_table(struct mlx4_dev *dev, struct mlx4_vlan_table *table);
 
 int mlx4_SET_PORT(struct mlx4_dev *dev, u8 port);
 int mlx4_get_port_ib_caps(struct mlx4_dev *dev, u8 port, __be32 *caps);
+int mlx4_check_ext_port_caps(struct mlx4_dev *dev, u8 port);
 
 int mlx4_qp_detach_common(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16],
                          enum mlx4_protocol prot, enum mlx4_steer_type steer);
index fca66165110ef95e8d4e57ac2be1157893696480..8fda331c65dfddd19a69da927444ec41be546da4 100644 (file)
@@ -581,8 +581,9 @@ extern const struct ethtool_ops mlx4_en_ethtool_ops;
  * printk / logging functions
  */
 
+__printf(3, 4)
 int en_print(const char *level, const struct mlx4_en_priv *priv,
-            const char *format, ...) __attribute__ ((format (printf, 3, 4)));
+            const char *format, ...);
 
 #define en_dbg(mlevel, priv, format, arg...)                   \
 do {                                                           \
index 9c188bdd7f4f2c5a6a3a124749d513c4d6b77958..ab639cfef78ea8005f39beccd6a8f71a92ed96c9 100644 (file)
@@ -139,7 +139,7 @@ static int mlx4_buddy_init(struct mlx4_buddy *buddy, int max_order)
 
        buddy->bits = kzalloc((buddy->max_order + 1) * sizeof (long *),
                              GFP_KERNEL);
-       buddy->num_free = kzalloc((buddy->max_order + 1) * sizeof (int *),
+       buddy->num_free = kcalloc((buddy->max_order + 1), sizeof *buddy->num_free,
                                  GFP_KERNEL);
        if (!buddy->bits || !buddy->num_free)
                goto err_out;
index 1286b886dcea5d6f54f32f7e22374ee600fd36ca..3736163e30e9a6d9296e541d4756b3925c51a5df 100644 (file)
@@ -61,6 +61,24 @@ void mlx4_pd_free(struct mlx4_dev *dev, u32 pdn)
 }
 EXPORT_SYMBOL_GPL(mlx4_pd_free);
 
+int mlx4_xrcd_alloc(struct mlx4_dev *dev, u32 *xrcdn)
+{
+       struct mlx4_priv *priv = mlx4_priv(dev);
+
+       *xrcdn = mlx4_bitmap_alloc(&priv->xrcd_bitmap);
+       if (*xrcdn == -1)
+               return -ENOMEM;
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(mlx4_xrcd_alloc);
+
+void mlx4_xrcd_free(struct mlx4_dev *dev, u32 xrcdn)
+{
+       mlx4_bitmap_free(&mlx4_priv(dev)->xrcd_bitmap, xrcdn);
+}
+EXPORT_SYMBOL_GPL(mlx4_xrcd_free);
+
 int mlx4_init_pd_table(struct mlx4_dev *dev)
 {
        struct mlx4_priv *priv = mlx4_priv(dev);
@@ -74,6 +92,18 @@ void mlx4_cleanup_pd_table(struct mlx4_dev *dev)
        mlx4_bitmap_cleanup(&mlx4_priv(dev)->pd_bitmap);
 }
 
+int mlx4_init_xrcd_table(struct mlx4_dev *dev)
+{
+       struct mlx4_priv *priv = mlx4_priv(dev);
+
+       return mlx4_bitmap_init(&priv->xrcd_bitmap, (1 << 16),
+                               (1 << 16) - 1, dev->caps.reserved_xrcds + 1, 0);
+}
+
+void mlx4_cleanup_xrcd_table(struct mlx4_dev *dev)
+{
+       mlx4_bitmap_cleanup(&mlx4_priv(dev)->xrcd_bitmap);
+}
 
 int mlx4_uar_alloc(struct mlx4_dev *dev, struct mlx4_uar *uar)
 {
index 163a314c148f1ada4286003838830d08c688bdeb..a44f080fdfe59899c6d06639a63dfe43bfea8ba4 100644 (file)
@@ -148,22 +148,26 @@ int mlx4_register_mac(struct mlx4_dev *dev, u8 port, u64 mac, int *qpn, u8 wrap)
 
        if (dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_UC_STEER) {
                err = mlx4_uc_steer_add(dev, port, mac, qpn, 1);
-               if (!err) {
-                       entry = kmalloc(sizeof *entry, GFP_KERNEL);
-                       if (!entry) {
-                               mlx4_uc_steer_release(dev, port, mac, *qpn, 1);
-                               return -ENOMEM;
-                       }
-                       entry->mac = mac;
-                       err = radix_tree_insert(&info->mac_tree, *qpn, entry);
-                       if (err) {
-                               mlx4_uc_steer_release(dev, port, mac, *qpn, 1);
-                               return err;
-                       }
-               } else
+               if (err)
                        return err;
+
+               entry = kmalloc(sizeof *entry, GFP_KERNEL);
+               if (!entry) {
+                       mlx4_uc_steer_release(dev, port, mac, *qpn, 1);
+                       return -ENOMEM;
+               }
+
+               entry->mac = mac;
+               err = radix_tree_insert(&info->mac_tree, *qpn, entry);
+               if (err) {
+                       kfree(entry);
+                       mlx4_uc_steer_release(dev, port, mac, *qpn, 1);
+                       return err;
+               }
        }
+
        mlx4_dbg(dev, "Registering MAC: 0x%llx\n", (unsigned long long) mac);
+
        mutex_lock(&table->mutex);
        for (i = 0; i < MLX4_MAX_MAC_NUM - 1; i++) {
                if (free < 0 && !table->refs[i]) {
@@ -465,6 +469,48 @@ int mlx4_get_port_ib_caps(struct mlx4_dev *dev, u8 port, __be32 *caps)
        return err;
 }
 
+int mlx4_check_ext_port_caps(struct mlx4_dev *dev, u8 port)
+{
+       struct mlx4_cmd_mailbox *inmailbox, *outmailbox;
+       u8 *inbuf, *outbuf;
+       int err, packet_error;
+
+       inmailbox = mlx4_alloc_cmd_mailbox(dev);
+       if (IS_ERR(inmailbox))
+               return PTR_ERR(inmailbox);
+
+       outmailbox = mlx4_alloc_cmd_mailbox(dev);
+       if (IS_ERR(outmailbox)) {
+               mlx4_free_cmd_mailbox(dev, inmailbox);
+               return PTR_ERR(outmailbox);
+       }
+
+       inbuf = inmailbox->buf;
+       outbuf = outmailbox->buf;
+       memset(inbuf, 0, 256);
+       memset(outbuf, 0, 256);
+       inbuf[0] = 1;
+       inbuf[1] = 1;
+       inbuf[2] = 1;
+       inbuf[3] = 1;
+
+       *(__be16 *) (&inbuf[16]) = MLX4_ATTR_EXTENDED_PORT_INFO;
+       *(__be32 *) (&inbuf[20]) = cpu_to_be32(port);
+
+       err = mlx4_cmd_box(dev, inmailbox->dma, outmailbox->dma, port, 3,
+                          MLX4_CMD_MAD_IFC, MLX4_CMD_TIME_CLASS_C);
+
+       packet_error = be16_to_cpu(*(__be16 *) (outbuf + 4));
+
+       dev->caps.ext_port_cap[port] = (!err && !packet_error) ?
+                                      MLX_EXT_PORT_CAP_FLAG_EXTENDED_PORT_INFO
+                                      : 0;
+
+       mlx4_free_cmd_mailbox(dev, inmailbox);
+       mlx4_free_cmd_mailbox(dev, outmailbox);
+       return err;
+}
+
 int mlx4_SET_PORT(struct mlx4_dev *dev, u8 port)
 {
        struct mlx4_cmd_mailbox *mailbox;
index ec9350e5f21ab7072dc00a062b28cb9781af2d7b..51c53898c35f89f3529e866fea994e001a828a85 100644 (file)
@@ -280,6 +280,9 @@ int mlx4_init_qp_table(struct mlx4_dev *dev)
         * We reserve 2 extra QPs per port for the special QPs.  The
         * block of special QPs must be aligned to a multiple of 8, so
         * round up.
+        *
+        * We also reserve the MSB of the 24-bit QP number to indicate
+        * that a QP is an XRC QP.
         */
        dev->caps.sqp_start =
                ALIGN(dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW], 8);
index 3b07b80a0456baec10d02146c1a71aa1feed872e..a20b141dbb5cf3a1ee3b8910624b9c0b58740a08 100644 (file)
 struct mlx4_srq_context {
        __be32                  state_logsize_srqn;
        u8                      logstride;
-       u8                      reserved1[3];
-       u8                      pg_offset;
-       u8                      reserved2[3];
-       u32                     reserved3;
+       u8                      reserved1;
+       __be16                  xrcd;
+       __be32                  pg_offset_cqn;
+       u32                     reserved2;
        u8                      log_page_size;
-       u8                      reserved4[2];
+       u8                      reserved3[2];
        u8                      mtt_base_addr_h;
        __be32                  mtt_base_addr_l;
        __be32                  pd;
        __be16                  limit_watermark;
        __be16                  wqe_cnt;
-       u16                     reserved5;
+       u16                     reserved4;
        __be16                  wqe_counter;
-       u32                     reserved6;
+       u32                     reserved5;
        __be64                  db_rec_addr;
 };
 
@@ -109,8 +109,8 @@ static int mlx4_QUERY_SRQ(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbox
                            MLX4_CMD_TIME_CLASS_A);
 }
 
-int mlx4_srq_alloc(struct mlx4_dev *dev, u32 pdn, struct mlx4_mtt *mtt,
-                  u64 db_rec, struct mlx4_srq *srq)
+int mlx4_srq_alloc(struct mlx4_dev *dev, u32 pdn, u32 cqn, u16 xrcd,
+                  struct mlx4_mtt *mtt, u64 db_rec, struct mlx4_srq *srq)
 {
        struct mlx4_srq_table *srq_table = &mlx4_priv(dev)->srq_table;
        struct mlx4_cmd_mailbox *mailbox;
@@ -148,6 +148,8 @@ int mlx4_srq_alloc(struct mlx4_dev *dev, u32 pdn, struct mlx4_mtt *mtt,
        srq_context->state_logsize_srqn = cpu_to_be32((ilog2(srq->max) << 24) |
                                                      srq->srqn);
        srq_context->logstride          = srq->wqe_shift - 4;
+       srq_context->xrcd               = cpu_to_be16(xrcd);
+       srq_context->pg_offset_cqn      = cpu_to_be32(cqn & 0xffffff);
        srq_context->log_page_size      = mtt->page_shift - MLX4_ICM_PAGE_SHIFT;
 
        mtt_addr = mlx4_mtt_addr(dev, mtt);
index 2fd1ba8fee4ab17a89700b5863d7d862b9ac1a58..7ed53dbb8646fa886e0411c3f6cfba2a372e6bcf 100644 (file)
@@ -36,8 +36,8 @@
 
 #define _QLCNIC_LINUX_MAJOR 5
 #define _QLCNIC_LINUX_MINOR 0
-#define _QLCNIC_LINUX_SUBVERSION 24
-#define QLCNIC_LINUX_VERSIONID  "5.0.24"
+#define _QLCNIC_LINUX_SUBVERSION 25
+#define QLCNIC_LINUX_VERSIONID  "5.0.25"
 #define QLCNIC_DRV_IDC_VER  0x01
 #define QLCNIC_DRIVER_VERSION  ((_QLCNIC_LINUX_MAJOR << 16) |\
                 (_QLCNIC_LINUX_MINOR << 8) | (_QLCNIC_LINUX_SUBVERSION))
index 5d8bec2832677ed328f4d85d0814237f8dffeacb..8aa1c6e8667be48710bd9d1384db92266a6ecd55 100644 (file)
@@ -935,31 +935,49 @@ static int qlcnic_set_led(struct net_device *dev,
 {
        struct qlcnic_adapter *adapter = netdev_priv(dev);
        int max_sds_rings = adapter->max_sds_rings;
+       int err = -EIO, active = 1;
+
+       if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) {
+               netdev_warn(dev, "LED test not supported for non "
+                               "privilege function\n");
+               return -EOPNOTSUPP;
+       }
 
        switch (state) {
        case ETHTOOL_ID_ACTIVE:
                if (test_and_set_bit(__QLCNIC_LED_ENABLE, &adapter->state))
                        return -EBUSY;
 
-               if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
-                       if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
-                               return -EIO;
+               if (test_bit(__QLCNIC_RESETTING, &adapter->state))
+                       break;
 
-                       if (qlcnic_diag_alloc_res(dev, QLCNIC_LED_TEST)) {
-                               clear_bit(__QLCNIC_RESETTING, &adapter->state);
-                               return -EIO;
-                       }
+               if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
+                       if (qlcnic_diag_alloc_res(dev, QLCNIC_LED_TEST))
+                               break;
                        set_bit(__QLCNIC_DIAG_RES_ALLOC, &adapter->state);
                }
 
-               if (adapter->nic_ops->config_led(adapter, 1, 0xf) == 0)
-                       return 0;
+               if (adapter->nic_ops->config_led(adapter, 1, 0xf) == 0) {
+                       err = 0;
+                       break;
+               }
 
                dev_err(&adapter->pdev->dev,
                        "Failed to set LED blink state.\n");
                break;
 
        case ETHTOOL_ID_INACTIVE:
+               active = 0;
+
+               if (test_bit(__QLCNIC_RESETTING, &adapter->state))
+                       break;
+
+               if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
+                       if (qlcnic_diag_alloc_res(dev, QLCNIC_LED_TEST))
+                               break;
+                       set_bit(__QLCNIC_DIAG_RES_ALLOC, &adapter->state);
+               }
+
                if (adapter->nic_ops->config_led(adapter, 0, 0xf))
                        dev_err(&adapter->pdev->dev,
                                "Failed to reset LED blink state.\n");
@@ -970,14 +988,13 @@ static int qlcnic_set_led(struct net_device *dev,
                return -EINVAL;
        }
 
-       if (test_and_clear_bit(__QLCNIC_DIAG_RES_ALLOC, &adapter->state)) {
+       if (test_and_clear_bit(__QLCNIC_DIAG_RES_ALLOC, &adapter->state))
                qlcnic_diag_free_res(dev, max_sds_rings);
-               clear_bit(__QLCNIC_RESETTING, &adapter->state);
-       }
 
-       clear_bit(__QLCNIC_LED_ENABLE, &adapter->state);
+       if (!active || err)
+               clear_bit(__QLCNIC_LED_ENABLE, &adapter->state);
 
-       return -EIO;
+       return err;
 }
 
 static void
index 92bc8ce9b2879750baca679af987f83475ced89c..a52819303d1b286138604ec8031ac0b658443723 100644 (file)
@@ -407,7 +407,9 @@ enum {
 #define QLCNIC_CRB_SRE         QLCNIC_PCI_CRB_WINDOW(QLCNIC_HW_PX_MAP_CRB_SRE)
 #define QLCNIC_CRB_ROMUSB      \
        QLCNIC_PCI_CRB_WINDOW(QLCNIC_HW_PX_MAP_CRB_ROMUSB)
+#define QLCNIC_CRB_EPG         QLCNIC_PCI_CRB_WINDOW(QLCNIC_HW_PX_MAP_CRB_EG)
 #define QLCNIC_CRB_I2Q         QLCNIC_PCI_CRB_WINDOW(QLCNIC_HW_PX_MAP_CRB_I2Q)
+#define QLCNIC_CRB_TIMER       QLCNIC_PCI_CRB_WINDOW(QLCNIC_HW_PX_MAP_CRB_TIMR)
 #define QLCNIC_CRB_I2C0        QLCNIC_PCI_CRB_WINDOW(QLCNIC_HW_PX_MAP_CRB_I2C0)
 #define QLCNIC_CRB_SMB         QLCNIC_PCI_CRB_WINDOW(QLCNIC_HW_PX_MAP_CRB_SMB)
 #define QLCNIC_CRB_MAX         QLCNIC_PCI_CRB_WINDOW(64)
index 74e9d7b94965bafb8ac4199b77915438159c58c9..bcb81e47543a3f47f2e9fd59d61c3a7d2f9d2886 100644 (file)
@@ -566,7 +566,7 @@ int qlcnic_set_lb_mode(struct qlcnic_adapter *adapter, u8 mode)
                return -EIO;
 
        if (qlcnic_nic_set_promisc(adapter, VPORT_MISS_MODE_ACCEPT_ALL)) {
-               qlcnic_set_fw_loopback(adapter, mode);
+               qlcnic_set_fw_loopback(adapter, 0);
                return -EIO;
        }
 
index 312c1c37889d719585d9e1eb9c2ab211f65a81d7..38669583840ce0a9e9f3ad31cd0d0d02a7b95bd6 100644 (file)
@@ -422,9 +422,53 @@ int qlcnic_pinit_from_rom(struct qlcnic_adapter *adapter)
        QLCWR32(adapter, CRB_CMDPEG_STATE, 0);
        QLCWR32(adapter, CRB_RCVPEG_STATE, 0);
 
-       qlcnic_rom_lock(adapter);
-       QLCWR32(adapter, QLCNIC_ROMUSB_GLB_SW_RESET, 0xfeffffff);
+       /* Halt all the indiviual PEGs and other blocks */
+       /* disable all I2Q */
+       QLCWR32(adapter, QLCNIC_CRB_I2Q + 0x10, 0x0);
+       QLCWR32(adapter, QLCNIC_CRB_I2Q + 0x14, 0x0);
+       QLCWR32(adapter, QLCNIC_CRB_I2Q + 0x18, 0x0);
+       QLCWR32(adapter, QLCNIC_CRB_I2Q + 0x1c, 0x0);
+       QLCWR32(adapter, QLCNIC_CRB_I2Q + 0x20, 0x0);
+       QLCWR32(adapter, QLCNIC_CRB_I2Q + 0x24, 0x0);
+
+       /* disable all niu interrupts */
+       QLCWR32(adapter, QLCNIC_CRB_NIU + 0x40, 0xff);
+       /* disable xge rx/tx */
+       QLCWR32(adapter, QLCNIC_CRB_NIU + 0x70000, 0x00);
+       /* disable xg1 rx/tx */
+       QLCWR32(adapter, QLCNIC_CRB_NIU + 0x80000, 0x00);
+       /* disable sideband mac */
+       QLCWR32(adapter, QLCNIC_CRB_NIU + 0x90000, 0x00);
+       /* disable ap0 mac */
+       QLCWR32(adapter, QLCNIC_CRB_NIU + 0xa0000, 0x00);
+       /* disable ap1 mac */
+       QLCWR32(adapter, QLCNIC_CRB_NIU + 0xb0000, 0x00);
+
+       /* halt sre */
+       val = QLCRD32(adapter, QLCNIC_CRB_SRE + 0x1000);
+       QLCWR32(adapter, QLCNIC_CRB_SRE + 0x1000, val & (~(0x1)));
+
+       /* halt epg */
+       QLCWR32(adapter, QLCNIC_CRB_EPG + 0x1300, 0x1);
+
+       /* halt timers */
+       QLCWR32(adapter, QLCNIC_CRB_TIMER + 0x0, 0x0);
+       QLCWR32(adapter, QLCNIC_CRB_TIMER + 0x8, 0x0);
+       QLCWR32(adapter, QLCNIC_CRB_TIMER + 0x10, 0x0);
+       QLCWR32(adapter, QLCNIC_CRB_TIMER + 0x18, 0x0);
+       QLCWR32(adapter, QLCNIC_CRB_TIMER + 0x100, 0x0);
+       QLCWR32(adapter, QLCNIC_CRB_TIMER + 0x200, 0x0);
+       /* halt pegs */
+       QLCWR32(adapter, QLCNIC_CRB_PEG_NET_0 + 0x3c, 1);
+       QLCWR32(adapter, QLCNIC_CRB_PEG_NET_1 + 0x3c, 1);
+       QLCWR32(adapter, QLCNIC_CRB_PEG_NET_2 + 0x3c, 1);
+       QLCWR32(adapter, QLCNIC_CRB_PEG_NET_3 + 0x3c, 1);
+       QLCWR32(adapter, QLCNIC_CRB_PEG_NET_4 + 0x3c, 1);
+       msleep(20);
+
        qlcnic_rom_unlock(adapter);
+       /* big hammer don't reset CAM block on reset */
+       QLCWR32(adapter, QLCNIC_ROMUSB_GLB_SW_RESET, 0xfeffffff);
 
        /* Init HW CRB block */
        if (qlcnic_rom_fast_read(adapter, 0, &n) != 0 || (n != 0xcafecafe) ||
@@ -522,8 +566,10 @@ int qlcnic_pinit_from_rom(struct qlcnic_adapter *adapter)
        QLCWR32(adapter, QLCNIC_CRB_PEG_NET_4 + 0x8, 0);
        QLCWR32(adapter, QLCNIC_CRB_PEG_NET_4 + 0xc, 0);
        msleep(1);
+
        QLCWR32(adapter, QLCNIC_PEG_HALT_STATUS1, 0);
        QLCWR32(adapter, QLCNIC_PEG_HALT_STATUS2, 0);
+
        return 0;
 }
 
index 106503f118f6295002bab4b13382a2b58f771396..0bd163828e339fbb0c6f290167c74561a55b4471 100644 (file)
@@ -2840,8 +2840,15 @@ qlcnic_fwinit_work(struct work_struct *work)
                goto wait_npar;
        }
 
+       if (dev_state == QLCNIC_DEV_INITIALIZING ||
+           dev_state == QLCNIC_DEV_READY) {
+               dev_info(&adapter->pdev->dev, "Detected state change from "
+                               "DEV_NEED_RESET, skipping ack check\n");
+               goto skip_ack_check;
+       }
+
        if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) {
-               dev_err(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n",
+               dev_info(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n",
                                        adapter->reset_ack_timeo);
                goto skip_ack_check;
        }
@@ -3497,11 +3504,16 @@ qlcnic_store_beacon(struct device *dev,
 {
        struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
        int max_sds_rings = adapter->max_sds_rings;
-       int dev_down = 0;
        u16 beacon;
        u8 b_state, b_rate;
        int err;
 
+       if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) {
+               dev_warn(dev, "LED test not supported for non "
+                               "privilege function\n");
+               return -EOPNOTSUPP;
+       }
+
        if (len != sizeof(u16))
                return QL_STATUS_INVALID_PARAM;
 
@@ -3513,36 +3525,40 @@ qlcnic_store_beacon(struct device *dev,
        if (adapter->ahw->beacon_state == b_state)
                return len;
 
+       rtnl_lock();
+
        if (!adapter->ahw->beacon_state)
-               if (test_and_set_bit(__QLCNIC_LED_ENABLE, &adapter->state))
+               if (test_and_set_bit(__QLCNIC_LED_ENABLE, &adapter->state)) {
+                       rtnl_unlock();
                        return -EBUSY;
+               }
+
+       if (test_bit(__QLCNIC_RESETTING, &adapter->state)) {
+               err = -EIO;
+               goto out;
+       }
 
        if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
-               if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
-                       return -EIO;
                err = qlcnic_diag_alloc_res(adapter->netdev, QLCNIC_LED_TEST);
-               if (err) {
-                       clear_bit(__QLCNIC_RESETTING, &adapter->state);
-                       clear_bit(__QLCNIC_LED_ENABLE, &adapter->state);
-                       return err;
-               }
-               dev_down = 1;
+               if (err)
+                       goto out;
+               set_bit(__QLCNIC_DIAG_RES_ALLOC, &adapter->state);
        }
 
        err = qlcnic_config_led(adapter, b_state, b_rate);
 
        if (!err) {
-               adapter->ahw->beacon_state = b_state;
                err = len;
+               adapter->ahw->beacon_state = b_state;
        }
 
-       if (dev_down) {
+       if (test_and_clear_bit(__QLCNIC_DIAG_RES_ALLOC, &adapter->state))
                qlcnic_diag_free_res(adapter->netdev, max_sds_rings);
-               clear_bit(__QLCNIC_RESETTING, &adapter->state);
-       }
 
-       if (!b_state)
+ out:
+       if (!adapter->ahw->beacon_state)
                clear_bit(__QLCNIC_LED_ENABLE, &adapter->state);
+       rtnl_unlock();
 
        return err;
 }
index de9afebe18301c261361f8021d1d2b999f6553e3..d5731f1fe6d67dc3713070ec4e7733f4788cc35a 100644 (file)
@@ -2229,13 +2229,15 @@ void efx_schedule_reset(struct efx_nic *efx, enum reset_type type)
 
 /* PCI device ID table */
 static DEFINE_PCI_DEVICE_TABLE(efx_pci_table) = {
-       {PCI_DEVICE(EFX_VENDID_SFC, FALCON_A_P_DEVID),
+       {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE,
+                   PCI_DEVICE_ID_SOLARFLARE_SFC4000A_0),
         .driver_data = (unsigned long) &falcon_a1_nic_type},
-       {PCI_DEVICE(EFX_VENDID_SFC, FALCON_B_P_DEVID),
+       {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE,
+                   PCI_DEVICE_ID_SOLARFLARE_SFC4000B),
         .driver_data = (unsigned long) &falcon_b0_nic_type},
-       {PCI_DEVICE(EFX_VENDID_SFC, BETHPAGE_A_P_DEVID),
+       {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, BETHPAGE_A_P_DEVID),
         .driver_data = (unsigned long) &siena_a0_nic_type},
-       {PCI_DEVICE(EFX_VENDID_SFC, SIENA_A_P_DEVID),
+       {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, SIENA_A_P_DEVID),
         .driver_data = (unsigned long) &siena_a0_nic_type},
        {0}                     /* end of list */
 };
index 442f4d0c247d8e043a640f838d88604b0d5e23a3..4764793ed234ce43d222e5d895f15ae69384d9ee 100644 (file)
 #include "filter.h"
 
 /* PCI IDs */
-#define EFX_VENDID_SFC         0x1924
-#define FALCON_A_P_DEVID       0x0703
-#define FALCON_A_S_DEVID        0x6703
-#define FALCON_B_P_DEVID        0x0710
 #define BETHPAGE_A_P_DEVID      0x0803
 #define SIENA_A_P_DEVID         0x0813
 
index 4dd1748a19c6098f88893bd28ed4cbdbd8afce7e..97b606b92e881eb6aeda796ec7286834f3422041 100644 (file)
@@ -1426,7 +1426,8 @@ static int falcon_probe_nic(struct efx_nic *efx)
                }
 
                dev = pci_dev_get(efx->pci_dev);
-               while ((dev = pci_get_device(EFX_VENDID_SFC, FALCON_A_S_DEVID,
+               while ((dev = pci_get_device(PCI_VENDOR_ID_SOLARFLARE,
+                                            PCI_DEVICE_ID_SOLARFLARE_SFC4000A_1,
                                             dev))) {
                        if (dev->bus == efx->pci_dev->bus &&
                            dev->devfn == efx->pci_dev->devfn + 1) {
index b9cc846811d642b7ac87ff832eb90c7c1ec5b4cf..6cc16b8cc6f48b7eda0bd4b431a15f45e5b6dcd2 100644 (file)
@@ -764,7 +764,8 @@ int falcon_probe_board(struct efx_nic *efx, u16 revision_info)
 
        if (board->type) {
                netif_info(efx, probe, efx->net_dev, "board is %s rev %c%d\n",
-                        (efx->pci_dev->subsystem_vendor == EFX_VENDID_SFC)
+                        (efx->pci_dev->subsystem_vendor ==
+                         PCI_VENDOR_ID_SOLARFLARE)
                         ? board->type->ref_model : board->type->gen_type,
                         'A' + board->major, board->minor);
                return 0;
index 9100c100d29563167d6d66bef82ac5e84d4263f3..2cc119295821500b465ddc633516155a69ad0982 100644 (file)
@@ -49,7 +49,7 @@ struct stmmac_extra_stats {
        unsigned long tx_underflow ____cacheline_aligned;
        unsigned long tx_carrier;
        unsigned long tx_losscarrier;
-       unsigned long tx_heartbeat;
+       unsigned long vlan_tag;
        unsigned long tx_deferred;
        unsigned long tx_vlan;
        unsigned long tx_jabber;
@@ -58,9 +58,9 @@ struct stmmac_extra_stats {
        unsigned long tx_ip_header_error;
        /* Receive errors */
        unsigned long rx_desc;
-       unsigned long rx_partial;
-       unsigned long rx_runt;
-       unsigned long rx_toolong;
+       unsigned long sa_filter_fail;
+       unsigned long overflow_error;
+       unsigned long ipc_csum_error;
        unsigned long rx_collision;
        unsigned long rx_crc;
        unsigned long rx_length;
index 63a03e26469442b77e528027932c9e570a51392b..9820ec842cc01f8a7fb0897d993d0b873902dee8 100644 (file)
@@ -25,33 +25,34 @@ struct dma_desc {
        union {
                struct {
                        /* RDES0 */
-                       u32 reserved1:1;
+                       u32 payload_csum_error:1;
                        u32 crc_error:1;
                        u32 dribbling:1;
                        u32 mii_error:1;
                        u32 receive_watchdog:1;
                        u32 frame_type:1;
                        u32 collision:1;
-                       u32 frame_too_long:1;
+                       u32 ipc_csum_error:1;
                        u32 last_descriptor:1;
                        u32 first_descriptor:1;
-                       u32 multicast_frame:1;
-                       u32 run_frame:1;
+                       u32 vlan_tag:1;
+                       u32 overflow_error:1;
                        u32 length_error:1;
-                       u32 partial_frame_error:1;
+                       u32 sa_filter_fail:1;
                        u32 descriptor_error:1;
                        u32 error_summary:1;
                        u32 frame_length:14;
-                       u32 filtering_fail:1;
+                       u32 da_filter_fail:1;
                        u32 own:1;
                        /* RDES1 */
                        u32 buffer1_size:11;
                        u32 buffer2_size:11;
-                       u32 reserved2:2;
+                       u32 reserved1:2;
                        u32 second_address_chained:1;
                        u32 end_ring:1;
-                       u32 reserved3:5;
+                       u32 reserved2:5;
                        u32 disable_ic:1;
+
                } rx;
                struct {
                        /* RDES0 */
@@ -91,24 +92,28 @@ struct dma_desc {
                        u32 underflow_error:1;
                        u32 excessive_deferral:1;
                        u32 collision_count:4;
-                       u32 heartbeat_fail:1;
+                       u32 vlan_frame:1;
                        u32 excessive_collisions:1;
                        u32 late_collision:1;
                        u32 no_carrier:1;
                        u32 loss_carrier:1;
-                       u32 reserved1:3;
+                       u32 payload_error:1;
+                       u32 frame_flushed:1;
+                       u32 jabber_timeout:1;
                        u32 error_summary:1;
-                       u32 reserved2:15;
+                       u32 ip_header_error:1;
+                       u32 time_stamp_status:1;
+                       u32 reserved1:13;
                        u32 own:1;
                        /* TDES1 */
                        u32 buffer1_size:11;
                        u32 buffer2_size:11;
-                       u32 reserved3:1;
+                       u32 time_stamp_enable:1;
                        u32 disable_padding:1;
                        u32 second_address_chained:1;
                        u32 end_ring:1;
                        u32 crc_disable:1;
-                       u32 reserved4:2;
+                       u32 checksum_insertion:2;
                        u32 first_segment:1;
                        u32 last_segment:1;
                        u32 interrupt:1;
index f7e8ba7f501aaa49fa163a02bb504676c9279784..fda5d2b31d3ac5b139e9f5f2caf3b0c7d09123bb 100644 (file)
@@ -50,11 +50,12 @@ static int ndesc_get_tx_status(void *data, struct stmmac_extra_stats *x,
                        stats->collisions += p->des01.tx.collision_count;
                ret = -1;
        }
-       if (unlikely(p->des01.tx.heartbeat_fail)) {
-               x->tx_heartbeat++;
-               stats->tx_heartbeat_errors++;
-               ret = -1;
+
+       if (p->des01.etx.vlan_frame) {
+               CHIP_DBG(KERN_INFO "GMAC TX status: VLAN frame\n");
+               x->tx_vlan++;
        }
+
        if (unlikely(p->des01.tx.deferred))
                x->tx_deferred++;
 
@@ -68,12 +69,12 @@ static int ndesc_get_tx_len(struct dma_desc *p)
 
 /* This function verifies if each incoming frame has some errors
  * and, if required, updates the multicast statistics.
- * In case of success, it returns csum_none because the device
- * is not able to compute the csum in HW. */
+ * In case of success, it returns good_frame because the GMAC device
+ * is supposed to be able to compute the csum in HW. */
 static int ndesc_get_rx_status(void *data, struct stmmac_extra_stats *x,
                               struct dma_desc *p)
 {
-       int ret = csum_none;
+       int ret = good_frame;
        struct net_device_stats *stats = (struct net_device_stats *)data;
 
        if (unlikely(p->des01.rx.last_descriptor == 0)) {
@@ -86,12 +87,12 @@ static int ndesc_get_rx_status(void *data, struct stmmac_extra_stats *x,
        if (unlikely(p->des01.rx.error_summary)) {
                if (unlikely(p->des01.rx.descriptor_error))
                        x->rx_desc++;
-               if (unlikely(p->des01.rx.partial_frame_error))
-                       x->rx_partial++;
-               if (unlikely(p->des01.rx.run_frame))
-                       x->rx_runt++;
-               if (unlikely(p->des01.rx.frame_too_long))
-                       x->rx_toolong++;
+               if (unlikely(p->des01.rx.sa_filter_fail))
+                       x->sa_filter_fail++;
+               if (unlikely(p->des01.rx.overflow_error))
+                       x->overflow_error++;
+               if (unlikely(p->des01.rx.ipc_csum_error))
+                       x->ipc_csum_error++;
                if (unlikely(p->des01.rx.collision)) {
                        x->rx_collision++;
                        stats->collisions++;
@@ -113,10 +114,10 @@ static int ndesc_get_rx_status(void *data, struct stmmac_extra_stats *x,
                x->rx_mii++;
                ret = discard_frame;
        }
-       if (p->des01.rx.multicast_frame) {
-               x->rx_multicast++;
-               stats->multicast++;
-       }
+#ifdef STMMAC_VLAN_TAG_USED
+       if (p->des01.rx.vlan_tag)
+               x->vlan_tag++;
+#endif
        return ret;
 }
 
@@ -184,6 +185,9 @@ static void ndesc_prepare_tx_desc(struct dma_desc *p, int is_fs, int len,
 {
        p->des01.tx.first_segment = is_fs;
        norm_set_tx_desc_len(p, len);
+
+       if (likely(csum_flag))
+               p->des01.tx.checksum_insertion = cic_full;
 }
 
 static void ndesc_clear_tx_ic(struct dma_desc *p)
index 406404f6e32193d5d7d1f5b06433a9bcb4d38ea0..e8eff09bbbd73c7b036f5cd9520d030c949fddc1 100644 (file)
@@ -50,7 +50,7 @@ static const struct stmmac_stats stmmac_gstrings_stats[] = {
        STMMAC_STAT(tx_underflow),
        STMMAC_STAT(tx_carrier),
        STMMAC_STAT(tx_losscarrier),
-       STMMAC_STAT(tx_heartbeat),
+       STMMAC_STAT(vlan_tag),
        STMMAC_STAT(tx_deferred),
        STMMAC_STAT(tx_vlan),
        STMMAC_STAT(rx_vlan),
@@ -59,9 +59,9 @@ static const struct stmmac_stats stmmac_gstrings_stats[] = {
        STMMAC_STAT(tx_payload_error),
        STMMAC_STAT(tx_ip_header_error),
        STMMAC_STAT(rx_desc),
-       STMMAC_STAT(rx_partial),
-       STMMAC_STAT(rx_runt),
-       STMMAC_STAT(rx_toolong),
+       STMMAC_STAT(sa_filter_fail),
+       STMMAC_STAT(overflow_error),
+       STMMAC_STAT(ipc_csum_error),
        STMMAC_STAT(rx_collision),
        STMMAC_STAT(rx_crc),
        STMMAC_STAT(rx_length),
index aeaa15b451de158b6daa778db235f1625cc0cda0..20546bbbb8db04744d39b2e4a4e5710f04fa6538 100644 (file)
@@ -325,7 +325,7 @@ static int stmmac_init_phy(struct net_device *dev)
            (interface == PHY_INTERFACE_MODE_RMII))) {
                phydev->supported &= (PHY_BASIC_FEATURES | SUPPORTED_Pause |
                                      SUPPORTED_Asym_Pause);
-               priv->phydev->advertising = priv->phydev->supported;
+               phydev->advertising = phydev->supported;
        }
 
        /*
@@ -812,9 +812,11 @@ static u32 stmmac_get_synopsys_id(struct stmmac_priv *priv)
  */
 static int stmmac_get_hw_features(struct stmmac_priv *priv)
 {
-       u32 hw_cap = priv->hw->dma->get_hw_feature(priv->ioaddr);
+       u32 hw_cap = 0;
+
+       if (priv->hw->dma->get_hw_feature) {
+               hw_cap = priv->hw->dma->get_hw_feature(priv->ioaddr);
 
-       if (likely(hw_cap)) {
                priv->dma_cap.mbps_10_100 = (hw_cap & DMA_HW_FEAT_MIISEL);
                priv->dma_cap.mbps_1000 = (hw_cap & DMA_HW_FEAT_GMIISEL) >> 1;
                priv->dma_cap.half_duplex = (hw_cap & DMA_HW_FEAT_HDSEL) >> 2;
@@ -937,6 +939,7 @@ static int stmmac_open(struct net_device *dev)
 
        stmmac_get_hw_features(priv);
 
+       priv->rx_coe = priv->hw->mac->rx_coe(priv->ioaddr);
        if (priv->rx_coe)
                pr_info("stmmac: Rx Checksum Offload Engine supported\n");
        if (priv->plat->tx_coe)
@@ -1274,8 +1277,8 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit)
 #endif
                        skb->protocol = eth_type_trans(skb, priv->dev);
 
-                       if (unlikely(status == csum_none)) {
-                               /* always for the old mac 10/100 */
+                       if (unlikely(!priv->rx_coe)) {
+                               /* No RX COE for old mac10/100 devices */
                                skb_checksum_none_assert(skb);
                                netif_receive_skb(skb);
                        } else {
index 39322d4121b79f17e90ecd39491b666c28c7217a..4045e5ab0555a3cbd2f55b1aa0e413a137f6f7f0 100644 (file)
@@ -517,7 +517,7 @@ static char *hex2str(void *buf, size_t len)
                goto exit;
 
        while (len--) {
-               obuf = pack_hex_byte(obuf, *ibuf++);
+               obuf = hex_byte_pack(obuf, *ibuf++);
                *obuf++ = '-';
        }
        obuf--;
index 908fdbc3e0eeaaef62523ee5828d50e760f8e627..0f9ee46cfc970eb8b898bf215bb48099165758de 100644 (file)
@@ -173,8 +173,7 @@ bool ath_hw_keyreset(struct ath_common *common, u16 entry);
 void ath_hw_cycle_counters_update(struct ath_common *common);
 int32_t ath_hw_get_listen_time(struct ath_common *common);
 
-extern __attribute__((format (printf, 2, 3)))
-void ath_printk(const char *level, const char *fmt, ...);
+extern __printf(2, 3) void ath_printk(const char *level, const char *fmt, ...);
 
 #define _ath_printk(level, common, fmt, ...)                   \
 do {                                                           \
@@ -258,7 +257,7 @@ do {                                                                        \
 
 #else
 
-static inline  __attribute__((format (printf, 3, 4)))
+static inline  __attribute__ ((format (printf, 3, 4)))
 void ath_dbg(struct ath_common *common, enum ATH_DEBUG dbg_mask,
             const char *fmt, ...)
 {
index 7f37df3125fd3852a8d76dd498dd188a39b7347e..0a3f916a1ef32fa3260534e8658e65bbb0a77106 100644 (file)
@@ -141,10 +141,10 @@ ath5k_debug_printtxbuf(struct ath5k_hw *ah, struct ath5k_buf *bf);
 
 #include <linux/compiler.h>
 
-static inline void __attribute__ ((format (printf, 3, 4)))
+static inline __printf(3, 4) void
 ATH5K_DBG(struct ath5k_hw *ah, unsigned int m, const char *fmt, ...) {}
 
-static inline void __attribute__ ((format (printf, 3, 4)))
+static inline __printf(3, 4) void
 ATH5K_DBG_UNLIMIT(struct ath5k_hw *ah, unsigned int m, const char *fmt, ...)
 {}
 
index 9288a3ce1e399446fada3406c5659e0dbe5d8a40..7b7675f70a102a585a6fc1be257242b1c63d496b 100644 (file)
@@ -44,8 +44,8 @@ enum ATH6K_DEBUG_MASK {
 };
 
 extern unsigned int debug_mask;
-extern int ath6kl_printk(const char *level, const char *fmt, ...)
-       __attribute__ ((format (printf, 2, 3)));
+extern __printf(2, 3)
+int ath6kl_printk(const char *level, const char *fmt, ...);
 
 #define ath6kl_info(fmt, ...)                          \
        ath6kl_printk(KERN_INFO, fmt, ##__VA_ARGS__)
index 447a2307c9d9ae2bdb7657c2f0160f978c8e55e9..37110dfd2c9627ff436379c8305151c0d6ff2e24 100644 (file)
@@ -1011,14 +1011,10 @@ static inline bool b43_using_pio_transfers(struct b43_wldev *dev)
 }
 
 /* Message printing */
-void b43info(struct b43_wl *wl, const char *fmt, ...)
-    __attribute__ ((format(printf, 2, 3)));
-void b43err(struct b43_wl *wl, const char *fmt, ...)
-    __attribute__ ((format(printf, 2, 3)));
-void b43warn(struct b43_wl *wl, const char *fmt, ...)
-    __attribute__ ((format(printf, 2, 3)));
-void b43dbg(struct b43_wl *wl, const char *fmt, ...)
-    __attribute__ ((format(printf, 2, 3)));
+__printf(2, 3) void b43info(struct b43_wl *wl, const char *fmt, ...);
+__printf(2, 3) void b43err(struct b43_wl *wl, const char *fmt, ...);
+__printf(2, 3) void b43warn(struct b43_wl *wl, const char *fmt, ...);
+__printf(2, 3) void b43dbg(struct b43_wl *wl, const char *fmt, ...);
 
 
 /* A WARN_ON variant that vanishes when b43 debugging is disabled.
index 12b5182515816e76d60fc08dd6ed2d54e43ac91b..1d4fc9db7f5e31863f1467696305076be882506b 100644 (file)
@@ -810,15 +810,15 @@ struct b43legacy_lopair *b43legacy_get_lopair(struct b43legacy_phy *phy,
 
 
 /* Message printing */
-void b43legacyinfo(struct b43legacy_wl *wl, const char *fmt, ...)
-               __attribute__((format(printf, 2, 3)));
-void b43legacyerr(struct b43legacy_wl *wl, const char *fmt, ...)
-               __attribute__((format(printf, 2, 3)));
-void b43legacywarn(struct b43legacy_wl *wl, const char *fmt, ...)
-               __attribute__((format(printf, 2, 3)));
+__printf(2, 3)
+void b43legacyinfo(struct b43legacy_wl *wl, const char *fmt, ...);
+__printf(2, 3)
+void b43legacyerr(struct b43legacy_wl *wl, const char *fmt, ...);
+__printf(2, 3)
+void b43legacywarn(struct b43legacy_wl *wl, const char *fmt, ...);
 #if B43legacy_DEBUG
-void b43legacydbg(struct b43legacy_wl *wl, const char *fmt, ...)
-               __attribute__((format(printf, 2, 3)));
+__printf(2, 3)
+void b43legacydbg(struct b43legacy_wl *wl, const char *fmt, ...);
 #else /* DEBUG */
 # define b43legacydbg(wl, fmt...) do { /* nothing */ } while (0)
 #endif /* DEBUG */
index 0fa466a91bf413995169f1751823e25784d70891..cec66064ee4b51a65be8d940b719c2d67760e4bf 100644 (file)
@@ -71,9 +71,13 @@ config HT_IRQ
 
           If unsure say Y.
 
+config PCI_ATS
+       bool
+
 config PCI_IOV
        bool "PCI IOV support"
        depends on PCI
+       select PCI_ATS
        help
          I/O Virtualization is a PCI feature supported by some devices
          which allows them to create virtual devices which share their
@@ -81,6 +85,28 @@ config PCI_IOV
 
          If unsure, say N.
 
+config PCI_PRI
+       bool "PCI PRI support"
+       select PCI_ATS
+       help
+         PRI is the PCI Page Request Interface. It allows PCI devices that are
+         behind an IOMMU to recover from page faults.
+
+         If unsure, say N.
+
+config PCI_PASID
+       bool "PCI PASID support"
+       depends on PCI
+       select PCI_ATS
+       help
+         Process Address Space Identifiers (PASIDs) can be used by PCI devices
+         to access more than one IO address space at the same time. To make
+         use of this feature an IOMMU is required which also supports PASIDs.
+         Select this option if you have such an IOMMU and want to compile the
+         driver for it into your kernel.
+
+         If unsure, say N.
+
 config PCI_IOAPIC
        bool
        depends on PCI
index 6fadae3ad1343bba7977ad14da2d063a36c81ee3..083a49fee56a8bbaa0d3834d92fd459225a69d0e 100644 (file)
@@ -29,6 +29,7 @@ obj-$(CONFIG_PCI_MSI) += msi.o
 # Build the Hypertransport interrupt support
 obj-$(CONFIG_HT_IRQ) += htirq.o
 
+obj-$(CONFIG_PCI_ATS) += ats.o
 obj-$(CONFIG_PCI_IOV) += iov.o
 
 #
diff --git a/drivers/pci/ats.c b/drivers/pci/ats.c
new file mode 100644 (file)
index 0000000..f727a09
--- /dev/null
@@ -0,0 +1,438 @@
+/*
+ * drivers/pci/ats.c
+ *
+ * Copyright (C) 2009 Intel Corporation, Yu Zhao <yu.zhao@intel.com>
+ * Copyright (C) 2011 Advanced Micro Devices,
+ *
+ * PCI Express I/O Virtualization (IOV) support.
+ *   Address Translation Service 1.0
+ *   Page Request Interface added by Joerg Roedel <joerg.roedel@amd.com>
+ *   PASID support added by Joerg Roedel <joerg.roedel@amd.com>
+ */
+
+#include <linux/pci-ats.h>
+#include <linux/pci.h>
+
+#include "pci.h"
+
+static int ats_alloc_one(struct pci_dev *dev, int ps)
+{
+       int pos;
+       u16 cap;
+       struct pci_ats *ats;
+
+       pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ATS);
+       if (!pos)
+               return -ENODEV;
+
+       ats = kzalloc(sizeof(*ats), GFP_KERNEL);
+       if (!ats)
+               return -ENOMEM;
+
+       ats->pos = pos;
+       ats->stu = ps;
+       pci_read_config_word(dev, pos + PCI_ATS_CAP, &cap);
+       ats->qdep = PCI_ATS_CAP_QDEP(cap) ? PCI_ATS_CAP_QDEP(cap) :
+                                           PCI_ATS_MAX_QDEP;
+       dev->ats = ats;
+
+       return 0;
+}
+
+static void ats_free_one(struct pci_dev *dev)
+{
+       kfree(dev->ats);
+       dev->ats = NULL;
+}
+
+/**
+ * pci_enable_ats - enable the ATS capability
+ * @dev: the PCI device
+ * @ps: the IOMMU page shift
+ *
+ * Returns 0 on success, or negative on failure.
+ */
+int pci_enable_ats(struct pci_dev *dev, int ps)
+{
+       int rc;
+       u16 ctrl;
+
+       BUG_ON(dev->ats && dev->ats->is_enabled);
+
+       if (ps < PCI_ATS_MIN_STU)
+               return -EINVAL;
+
+       if (dev->is_physfn || dev->is_virtfn) {
+               struct pci_dev *pdev = dev->is_physfn ? dev : dev->physfn;
+
+               mutex_lock(&pdev->sriov->lock);
+               if (pdev->ats)
+                       rc = pdev->ats->stu == ps ? 0 : -EINVAL;
+               else
+                       rc = ats_alloc_one(pdev, ps);
+
+               if (!rc)
+                       pdev->ats->ref_cnt++;
+               mutex_unlock(&pdev->sriov->lock);
+               if (rc)
+                       return rc;
+       }
+
+       if (!dev->is_physfn) {
+               rc = ats_alloc_one(dev, ps);
+               if (rc)
+                       return rc;
+       }
+
+       ctrl = PCI_ATS_CTRL_ENABLE;
+       if (!dev->is_virtfn)
+               ctrl |= PCI_ATS_CTRL_STU(ps - PCI_ATS_MIN_STU);
+       pci_write_config_word(dev, dev->ats->pos + PCI_ATS_CTRL, ctrl);
+
+       dev->ats->is_enabled = 1;
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(pci_enable_ats);
+
+/**
+ * pci_disable_ats - disable the ATS capability
+ * @dev: the PCI device
+ */
+void pci_disable_ats(struct pci_dev *dev)
+{
+       u16 ctrl;
+
+       BUG_ON(!dev->ats || !dev->ats->is_enabled);
+
+       pci_read_config_word(dev, dev->ats->pos + PCI_ATS_CTRL, &ctrl);
+       ctrl &= ~PCI_ATS_CTRL_ENABLE;
+       pci_write_config_word(dev, dev->ats->pos + PCI_ATS_CTRL, ctrl);
+
+       dev->ats->is_enabled = 0;
+
+       if (dev->is_physfn || dev->is_virtfn) {
+               struct pci_dev *pdev = dev->is_physfn ? dev : dev->physfn;
+
+               mutex_lock(&pdev->sriov->lock);
+               pdev->ats->ref_cnt--;
+               if (!pdev->ats->ref_cnt)
+                       ats_free_one(pdev);
+               mutex_unlock(&pdev->sriov->lock);
+       }
+
+       if (!dev->is_physfn)
+               ats_free_one(dev);
+}
+EXPORT_SYMBOL_GPL(pci_disable_ats);
+
+/**
+ * pci_ats_queue_depth - query the ATS Invalidate Queue Depth
+ * @dev: the PCI device
+ *
+ * Returns the queue depth on success, or negative on failure.
+ *
+ * The ATS spec uses 0 in the Invalidate Queue Depth field to
+ * indicate that the function can accept 32 Invalidate Request.
+ * But here we use the `real' values (i.e. 1~32) for the Queue
+ * Depth; and 0 indicates the function shares the Queue with
+ * other functions (doesn't exclusively own a Queue).
+ */
+int pci_ats_queue_depth(struct pci_dev *dev)
+{
+       int pos;
+       u16 cap;
+
+       if (dev->is_virtfn)
+               return 0;
+
+       if (dev->ats)
+               return dev->ats->qdep;
+
+       pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ATS);
+       if (!pos)
+               return -ENODEV;
+
+       pci_read_config_word(dev, pos + PCI_ATS_CAP, &cap);
+
+       return PCI_ATS_CAP_QDEP(cap) ? PCI_ATS_CAP_QDEP(cap) :
+                                      PCI_ATS_MAX_QDEP;
+}
+EXPORT_SYMBOL_GPL(pci_ats_queue_depth);
+
+#ifdef CONFIG_PCI_PRI
+/**
+ * pci_enable_pri - Enable PRI capability
+ * @ pdev: PCI device structure
+ *
+ * Returns 0 on success, negative value on error
+ */
+int pci_enable_pri(struct pci_dev *pdev, u32 reqs)
+{
+       u16 control, status;
+       u32 max_requests;
+       int pos;
+
+       pos = pci_find_ext_capability(pdev, PCI_PRI_CAP);
+       if (!pos)
+               return -EINVAL;
+
+       pci_read_config_word(pdev, pos + PCI_PRI_CONTROL_OFF, &control);
+       pci_read_config_word(pdev, pos + PCI_PRI_STATUS_OFF,  &status);
+       if ((control & PCI_PRI_ENABLE) || !(status & PCI_PRI_STATUS_STOPPED))
+               return -EBUSY;
+
+       pci_read_config_dword(pdev, pos + PCI_PRI_MAX_REQ_OFF, &max_requests);
+       reqs = min(max_requests, reqs);
+       pci_write_config_dword(pdev, pos + PCI_PRI_ALLOC_REQ_OFF, reqs);
+
+       control |= PCI_PRI_ENABLE;
+       pci_write_config_word(pdev, pos + PCI_PRI_CONTROL_OFF, control);
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(pci_enable_pri);
+
+/**
+ * pci_disable_pri - Disable PRI capability
+ * @pdev: PCI device structure
+ *
+ * Only clears the enabled-bit, regardless of its former value
+ */
+void pci_disable_pri(struct pci_dev *pdev)
+{
+       u16 control;
+       int pos;
+
+       pos = pci_find_ext_capability(pdev, PCI_PRI_CAP);
+       if (!pos)
+               return;
+
+       pci_read_config_word(pdev, pos + PCI_PRI_CONTROL_OFF, &control);
+       control &= ~PCI_PRI_ENABLE;
+       pci_write_config_word(pdev, pos + PCI_PRI_CONTROL_OFF, control);
+}
+EXPORT_SYMBOL_GPL(pci_disable_pri);
+
+/**
+ * pci_pri_enabled - Checks if PRI capability is enabled
+ * @pdev: PCI device structure
+ *
+ * Returns true if PRI is enabled on the device, false otherwise
+ */
+bool pci_pri_enabled(struct pci_dev *pdev)
+{
+       u16 control;
+       int pos;
+
+       pos = pci_find_ext_capability(pdev, PCI_PRI_CAP);
+       if (!pos)
+               return false;
+
+       pci_read_config_word(pdev, pos + PCI_PRI_CONTROL_OFF, &control);
+
+       return (control & PCI_PRI_ENABLE) ? true : false;
+}
+EXPORT_SYMBOL_GPL(pci_pri_enabled);
+
+/**
+ * pci_reset_pri - Resets device's PRI state
+ * @pdev: PCI device structure
+ *
+ * The PRI capability must be disabled before this function is called.
+ * Returns 0 on success, negative value on error.
+ */
+int pci_reset_pri(struct pci_dev *pdev)
+{
+       u16 control;
+       int pos;
+
+       pos = pci_find_ext_capability(pdev, PCI_PRI_CAP);
+       if (!pos)
+               return -EINVAL;
+
+       pci_read_config_word(pdev, pos + PCI_PRI_CONTROL_OFF, &control);
+       if (control & PCI_PRI_ENABLE)
+               return -EBUSY;
+
+       control |= PCI_PRI_RESET;
+
+       pci_write_config_word(pdev, pos + PCI_PRI_CONTROL_OFF, control);
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(pci_reset_pri);
+
+/**
+ * pci_pri_stopped - Checks whether the PRI capability is stopped
+ * @pdev: PCI device structure
+ *
+ * Returns true if the PRI capability on the device is disabled and the
+ * device has no outstanding PRI requests, false otherwise. The device
+ * indicates this via the STOPPED bit in the status register of the
+ * capability.
+ * The device internal state can be cleared by resetting the PRI state
+ * with pci_reset_pri(). This can force the capability into the STOPPED
+ * state.
+ */
+bool pci_pri_stopped(struct pci_dev *pdev)
+{
+       u16 control, status;
+       int pos;
+
+       pos = pci_find_ext_capability(pdev, PCI_PRI_CAP);
+       if (!pos)
+               return true;
+
+       pci_read_config_word(pdev, pos + PCI_PRI_CONTROL_OFF, &control);
+       pci_read_config_word(pdev, pos + PCI_PRI_STATUS_OFF,  &status);
+
+       if (control & PCI_PRI_ENABLE)
+               return false;
+
+       return (status & PCI_PRI_STATUS_STOPPED) ? true : false;
+}
+EXPORT_SYMBOL_GPL(pci_pri_stopped);
+
+/**
+ * pci_pri_status - Request PRI status of a device
+ * @pdev: PCI device structure
+ *
+ * Returns negative value on failure, status on success. The status can
+ * be checked against status-bits. Supported bits are currently:
+ * PCI_PRI_STATUS_RF:      Response failure
+ * PCI_PRI_STATUS_UPRGI:   Unexpected Page Request Group Index
+ * PCI_PRI_STATUS_STOPPED: PRI has stopped
+ */
+int pci_pri_status(struct pci_dev *pdev)
+{
+       u16 status, control;
+       int pos;
+
+       pos = pci_find_ext_capability(pdev, PCI_PRI_CAP);
+       if (!pos)
+               return -EINVAL;
+
+       pci_read_config_word(pdev, pos + PCI_PRI_CONTROL_OFF, &control);
+       pci_read_config_word(pdev, pos + PCI_PRI_STATUS_OFF,  &status);
+
+       /* Stopped bit is undefined when enable == 1, so clear it */
+       if (control & PCI_PRI_ENABLE)
+               status &= ~PCI_PRI_STATUS_STOPPED;
+
+       return status;
+}
+EXPORT_SYMBOL_GPL(pci_pri_status);
+#endif /* CONFIG_PCI_PRI */
+
+#ifdef CONFIG_PCI_PASID
+/**
+ * pci_enable_pasid - Enable the PASID capability
+ * @pdev: PCI device structure
+ * @features: Features to enable
+ *
+ * Returns 0 on success, negative value on error. This function checks
+ * whether the features are actually supported by the device and returns
+ * an error if not.
+ */
+int pci_enable_pasid(struct pci_dev *pdev, int features)
+{
+       u16 control, supported;
+       int pos;
+
+       pos = pci_find_ext_capability(pdev, PCI_PASID_CAP);
+       if (!pos)
+               return -EINVAL;
+
+       pci_read_config_word(pdev, pos + PCI_PASID_CONTROL_OFF, &control);
+       pci_read_config_word(pdev, pos + PCI_PASID_CAP_OFF,     &supported);
+
+       if (!(supported & PCI_PASID_ENABLE))
+               return -EINVAL;
+
+       supported &= PCI_PASID_EXEC | PCI_PASID_PRIV;
+
+       /* User wants to enable anything unsupported? */
+       if ((supported & features) != features)
+               return -EINVAL;
+
+       control = PCI_PASID_ENABLE | features;
+
+       pci_write_config_word(pdev, pos + PCI_PASID_CONTROL_OFF, control);
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(pci_enable_pasid);
+
+/**
+ * pci_disable_pasid - Disable the PASID capability
+ * @pdev: PCI device structure
+ *
+ */
+void pci_disable_pasid(struct pci_dev *pdev)
+{
+       u16 control = 0;
+       int pos;
+
+       pos = pci_find_ext_capability(pdev, PCI_PASID_CAP);
+       if (!pos)
+               return;
+
+       pci_write_config_word(pdev, pos + PCI_PASID_CONTROL_OFF, control);
+}
+EXPORT_SYMBOL_GPL(pci_disable_pasid);
+
+/**
+ * pci_pasid_features - Check which PASID features are supported
+ * @pdev: PCI device structure
+ *
+ * Returns a negative value when no PASI capability is present.
+ * Otherwise is returns a bitmask with supported features. Current
+ * features reported are:
+ * PCI_PASID_ENABLE - PASID capability can be enabled
+ * PCI_PASID_EXEC - Execute permission supported
+ * PCI_PASID_PRIV - Priviledged mode supported
+ */
+int pci_pasid_features(struct pci_dev *pdev)
+{
+       u16 supported;
+       int pos;
+
+       pos = pci_find_ext_capability(pdev, PCI_PASID_CAP);
+       if (!pos)
+               return -EINVAL;
+
+       pci_read_config_word(pdev, pos + PCI_PASID_CAP_OFF, &supported);
+
+       supported &= PCI_PASID_ENABLE | PCI_PASID_EXEC | PCI_PASID_PRIV;
+
+       return supported;
+}
+EXPORT_SYMBOL_GPL(pci_pasid_features);
+
+#define PASID_NUMBER_SHIFT     8
+#define PASID_NUMBER_MASK      (0x1f << PASID_NUMBER_SHIFT)
+/**
+ * pci_max_pasid - Get maximum number of PASIDs supported by device
+ * @pdev: PCI device structure
+ *
+ * Returns negative value when PASID capability is not present.
+ * Otherwise it returns the numer of supported PASIDs.
+ */
+int pci_max_pasids(struct pci_dev *pdev)
+{
+       u16 supported;
+       int pos;
+
+       pos = pci_find_ext_capability(pdev, PCI_PASID_CAP);
+       if (!pos)
+               return -EINVAL;
+
+       pci_read_config_word(pdev, pos + PCI_PASID_CAP_OFF, &supported);
+
+       supported = (supported & PASID_NUMBER_MASK) >> PASID_NUMBER_SHIFT;
+
+       return (1 << supported);
+}
+EXPORT_SYMBOL_GPL(pci_max_pasids);
+#endif /* CONFIG_PCI_PASID */
index 220285760b68691f2d3d16ec79822de2383a50be..596172b4ae955802a5778dd0c375b870b9a11909 100644 (file)
@@ -48,6 +48,7 @@
 #include <linux/pci-acpi.h>
 #include <linux/mutex.h>
 #include <linux/slab.h>
+#include <linux/acpi.h>
 
 #include "../pci.h"
 #include "acpiphp.h"
@@ -1149,15 +1150,35 @@ check_sub_bridges(acpi_handle handle, u32 lvl, void *context, void **rv)
        return AE_OK ;
 }
 
-/**
- * handle_hotplug_event_bridge - handle ACPI event on bridges
- * @handle: Notify()'ed acpi_handle
- * @type: Notify code
- * @context: pointer to acpiphp_bridge structure
- *
- * Handles ACPI event notification on {host,p2p} bridges.
- */
-static void handle_hotplug_event_bridge(acpi_handle handle, u32 type, void *context)
+struct acpiphp_hp_work {
+       struct work_struct work;
+       acpi_handle handle;
+       u32 type;
+       void *context;
+};
+
+static void alloc_acpiphp_hp_work(acpi_handle handle, u32 type,
+                                 void *context,
+                                 void (*func)(struct work_struct *work))
+{
+       struct acpiphp_hp_work *hp_work;
+       int ret;
+
+       hp_work = kmalloc(sizeof(*hp_work), GFP_KERNEL);
+       if (!hp_work)
+               return;
+
+       hp_work->handle = handle;
+       hp_work->type = type;
+       hp_work->context = context;
+
+       INIT_WORK(&hp_work->work, func);
+       ret = queue_work(kacpi_hotplug_wq, &hp_work->work);
+       if (!ret)
+               kfree(hp_work);
+}
+
+static void _handle_hotplug_event_bridge(struct work_struct *work)
 {
        struct acpiphp_bridge *bridge;
        char objname[64];
@@ -1165,11 +1186,18 @@ static void handle_hotplug_event_bridge(acpi_handle handle, u32 type, void *cont
                                      .pointer = objname };
        struct acpi_device *device;
        int num_sub_bridges = 0;
+       struct acpiphp_hp_work *hp_work;
+       acpi_handle handle;
+       u32 type;
+
+       hp_work = container_of(work, struct acpiphp_hp_work, work);
+       handle = hp_work->handle;
+       type = hp_work->type;
 
        if (acpi_bus_get_device(handle, &device)) {
                /* This bridge must have just been physically inserted */
                handle_bridge_insertion(handle, type);
-               return;
+               goto out;
        }
 
        bridge = acpiphp_handle_to_bridge(handle);
@@ -1180,7 +1208,7 @@ static void handle_hotplug_event_bridge(acpi_handle handle, u32 type, void *cont
 
        if (!bridge && !num_sub_bridges) {
                err("cannot get bridge info\n");
-               return;
+               goto out;
        }
 
        acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
@@ -1241,22 +1269,49 @@ static void handle_hotplug_event_bridge(acpi_handle handle, u32 type, void *cont
                warn("notify_handler: unknown event type 0x%x for %s\n", type, objname);
                break;
        }
+
+out:
+       kfree(hp_work); /* allocated in handle_hotplug_event_bridge */
 }
 
 /**
- * handle_hotplug_event_func - handle ACPI event on functions (i.e. slots)
+ * handle_hotplug_event_bridge - handle ACPI event on bridges
  * @handle: Notify()'ed acpi_handle
  * @type: Notify code
- * @context: pointer to acpiphp_func structure
+ * @context: pointer to acpiphp_bridge structure
  *
- * Handles ACPI event notification on slots.
+ * Handles ACPI event notification on {host,p2p} bridges.
  */
-static void handle_hotplug_event_func(acpi_handle handle, u32 type, void *context)
+static void handle_hotplug_event_bridge(acpi_handle handle, u32 type,
+                                       void *context)
+{
+       /*
+        * Currently the code adds all hotplug events to the kacpid_wq
+        * queue when it should add hotplug events to the kacpi_hotplug_wq.
+        * The proper way to fix this is to reorganize the code so that
+        * drivers (dock, etc.) do not call acpi_os_execute(), etc.
+        * For now just re-add this work to the kacpi_hotplug_wq so we
+        * don't deadlock on hotplug actions.
+        */
+       alloc_acpiphp_hp_work(handle, type, context,
+                             _handle_hotplug_event_bridge);
+}
+
+static void _handle_hotplug_event_func(struct work_struct *work)
 {
        struct acpiphp_func *func;
        char objname[64];
        struct acpi_buffer buffer = { .length = sizeof(objname),
                                      .pointer = objname };
+       struct acpiphp_hp_work *hp_work;
+       acpi_handle handle;
+       u32 type;
+       void *context;
+
+       hp_work = container_of(work, struct acpiphp_hp_work, work);
+       handle = hp_work->handle;
+       type = hp_work->type;
+       context = hp_work->context;
 
        acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
 
@@ -1291,8 +1346,32 @@ static void handle_hotplug_event_func(acpi_handle handle, u32 type, void *contex
                warn("notify_handler: unknown event type 0x%x for %s\n", type, objname);
                break;
        }
+
+       kfree(hp_work); /* allocated in handle_hotplug_event_func */
 }
 
+/**
+ * handle_hotplug_event_func - handle ACPI event on functions (i.e. slots)
+ * @handle: Notify()'ed acpi_handle
+ * @type: Notify code
+ * @context: pointer to acpiphp_func structure
+ *
+ * Handles ACPI event notification on slots.
+ */
+static void handle_hotplug_event_func(acpi_handle handle, u32 type,
+                                     void *context)
+{
+       /*
+        * Currently the code adds all hotplug events to the kacpid_wq
+        * queue when it should add hotplug events to the kacpi_hotplug_wq.
+        * The proper way to fix this is to reorganize the code so that
+        * drivers (dock, etc.) do not call acpi_os_execute(), etc.
+        * For now just re-add this work to the kacpi_hotplug_wq so we
+        * don't deadlock on hotplug actions.
+        */
+       alloc_acpiphp_hp_work(handle, type, context,
+                             _handle_hotplug_event_func);
+}
 
 static acpi_status
 find_root_bridges(acpi_handle handle, u32 lvl, void *context, void **rv)
index 42fae477651517ef8dd447427c39ea00d8955951..9b4e88c636f8573049c43cacd54d6c017fa21cc7 100644 (file)
@@ -722,145 +722,3 @@ int pci_num_vf(struct pci_dev *dev)
                return dev->sriov->nr_virtfn;
 }
 EXPORT_SYMBOL_GPL(pci_num_vf);
-
-static int ats_alloc_one(struct pci_dev *dev, int ps)
-{
-       int pos;
-       u16 cap;
-       struct pci_ats *ats;
-
-       pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ATS);
-       if (!pos)
-               return -ENODEV;
-
-       ats = kzalloc(sizeof(*ats), GFP_KERNEL);
-       if (!ats)
-               return -ENOMEM;
-
-       ats->pos = pos;
-       ats->stu = ps;
-       pci_read_config_word(dev, pos + PCI_ATS_CAP, &cap);
-       ats->qdep = PCI_ATS_CAP_QDEP(cap) ? PCI_ATS_CAP_QDEP(cap) :
-                                           PCI_ATS_MAX_QDEP;
-       dev->ats = ats;
-
-       return 0;
-}
-
-static void ats_free_one(struct pci_dev *dev)
-{
-       kfree(dev->ats);
-       dev->ats = NULL;
-}
-
-/**
- * pci_enable_ats - enable the ATS capability
- * @dev: the PCI device
- * @ps: the IOMMU page shift
- *
- * Returns 0 on success, or negative on failure.
- */
-int pci_enable_ats(struct pci_dev *dev, int ps)
-{
-       int rc;
-       u16 ctrl;
-
-       BUG_ON(dev->ats && dev->ats->is_enabled);
-
-       if (ps < PCI_ATS_MIN_STU)
-               return -EINVAL;
-
-       if (dev->is_physfn || dev->is_virtfn) {
-               struct pci_dev *pdev = dev->is_physfn ? dev : dev->physfn;
-
-               mutex_lock(&pdev->sriov->lock);
-               if (pdev->ats)
-                       rc = pdev->ats->stu == ps ? 0 : -EINVAL;
-               else
-                       rc = ats_alloc_one(pdev, ps);
-
-               if (!rc)
-                       pdev->ats->ref_cnt++;
-               mutex_unlock(&pdev->sriov->lock);
-               if (rc)
-                       return rc;
-       }
-
-       if (!dev->is_physfn) {
-               rc = ats_alloc_one(dev, ps);
-               if (rc)
-                       return rc;
-       }
-
-       ctrl = PCI_ATS_CTRL_ENABLE;
-       if (!dev->is_virtfn)
-               ctrl |= PCI_ATS_CTRL_STU(ps - PCI_ATS_MIN_STU);
-       pci_write_config_word(dev, dev->ats->pos + PCI_ATS_CTRL, ctrl);
-
-       dev->ats->is_enabled = 1;
-
-       return 0;
-}
-
-/**
- * pci_disable_ats - disable the ATS capability
- * @dev: the PCI device
- */
-void pci_disable_ats(struct pci_dev *dev)
-{
-       u16 ctrl;
-
-       BUG_ON(!dev->ats || !dev->ats->is_enabled);
-
-       pci_read_config_word(dev, dev->ats->pos + PCI_ATS_CTRL, &ctrl);
-       ctrl &= ~PCI_ATS_CTRL_ENABLE;
-       pci_write_config_word(dev, dev->ats->pos + PCI_ATS_CTRL, ctrl);
-
-       dev->ats->is_enabled = 0;
-
-       if (dev->is_physfn || dev->is_virtfn) {
-               struct pci_dev *pdev = dev->is_physfn ? dev : dev->physfn;
-
-               mutex_lock(&pdev->sriov->lock);
-               pdev->ats->ref_cnt--;
-               if (!pdev->ats->ref_cnt)
-                       ats_free_one(pdev);
-               mutex_unlock(&pdev->sriov->lock);
-       }
-
-       if (!dev->is_physfn)
-               ats_free_one(dev);
-}
-
-/**
- * pci_ats_queue_depth - query the ATS Invalidate Queue Depth
- * @dev: the PCI device
- *
- * Returns the queue depth on success, or negative on failure.
- *
- * The ATS spec uses 0 in the Invalidate Queue Depth field to
- * indicate that the function can accept 32 Invalidate Request.
- * But here we use the `real' values (i.e. 1~32) for the Queue
- * Depth; and 0 indicates the function shares the Queue with
- * other functions (doesn't exclusively own a Queue).
- */
-int pci_ats_queue_depth(struct pci_dev *dev)
-{
-       int pos;
-       u16 cap;
-
-       if (dev->is_virtfn)
-               return 0;
-
-       if (dev->ats)
-               return dev->ats->qdep;
-
-       pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ATS);
-       if (!pos)
-               return -ENODEV;
-
-       pci_read_config_word(dev, pos + PCI_ATS_CAP, &cap);
-
-       return PCI_ATS_CAP_QDEP(cap) ? PCI_ATS_CAP_QDEP(cap) :
-                                      PCI_ATS_MAX_QDEP;
-}
index d36f41ea8cbfb9ccd61ebfc9c68700b98cb31136..4ecb6408b0d61e2128c26100bba3d6690402de5d 100644 (file)
@@ -46,6 +46,9 @@ static void pci_acpi_wake_dev(acpi_handle handle, u32 event, void *context)
        struct pci_dev *pci_dev = context;
 
        if (event == ACPI_NOTIFY_DEVICE_WAKE && pci_dev) {
+               if (pci_dev->pme_poll)
+                       pci_dev->pme_poll = false;
+
                pci_wakeup_event(pci_dev);
                pci_check_pme_status(pci_dev);
                pm_runtime_resume(&pci_dev->dev);
@@ -282,7 +285,6 @@ static int acpi_dev_run_wake(struct device *phys_dev, bool enable)
 {
        struct acpi_device *dev;
        acpi_handle handle;
-       int error = -ENODEV;
 
        if (!device_run_wake(phys_dev))
                return -EINVAL;
@@ -302,7 +304,7 @@ static int acpi_dev_run_wake(struct device *phys_dev, bool enable)
                acpi_disable_wakeup_device_power(dev);
        }
 
-       return error;
+       return 0;
 }
 
 static void acpi_pci_propagate_run_wake(struct pci_bus *bus, bool enable)
index e9651f0a88177097b0f3db03153554a6e54a6137..6f45a73c6e9fa38c9e09fbf3d5a4853d8cc3396c 100644 (file)
@@ -1407,13 +1407,16 @@ bool pci_check_pme_status(struct pci_dev *dev)
 /**
  * pci_pme_wakeup - Wake up a PCI device if its PME Status bit is set.
  * @dev: Device to handle.
- * @ign: Ignored.
+ * @pme_poll_reset: Whether or not to reset the device's pme_poll flag.
  *
  * Check if @dev has generated PME and queue a resume request for it in that
  * case.
  */
-static int pci_pme_wakeup(struct pci_dev *dev, void *ign)
+static int pci_pme_wakeup(struct pci_dev *dev, void *pme_poll_reset)
 {
+       if (pme_poll_reset && dev->pme_poll)
+               dev->pme_poll = false;
+
        if (pci_check_pme_status(dev)) {
                pci_wakeup_event(dev);
                pm_request_resume(&dev->dev);
@@ -1428,7 +1431,7 @@ static int pci_pme_wakeup(struct pci_dev *dev, void *ign)
 void pci_pme_wakeup_bus(struct pci_bus *bus)
 {
        if (bus)
-               pci_walk_bus(bus, pci_pme_wakeup, NULL);
+               pci_walk_bus(bus, pci_pme_wakeup, (void *)true);
 }
 
 /**
@@ -1446,30 +1449,25 @@ bool pci_pme_capable(struct pci_dev *dev, pci_power_t state)
 
 static void pci_pme_list_scan(struct work_struct *work)
 {
-       struct pci_pme_device *pme_dev;
+       struct pci_pme_device *pme_dev, *n;
 
        mutex_lock(&pci_pme_list_mutex);
        if (!list_empty(&pci_pme_list)) {
-               list_for_each_entry(pme_dev, &pci_pme_list, list)
-                       pci_pme_wakeup(pme_dev->dev, NULL);
-               schedule_delayed_work(&pci_pme_work, msecs_to_jiffies(PME_TIMEOUT));
+               list_for_each_entry_safe(pme_dev, n, &pci_pme_list, list) {
+                       if (pme_dev->dev->pme_poll) {
+                               pci_pme_wakeup(pme_dev->dev, NULL);
+                       } else {
+                               list_del(&pme_dev->list);
+                               kfree(pme_dev);
+                       }
+               }
+               if (!list_empty(&pci_pme_list))
+                       schedule_delayed_work(&pci_pme_work,
+                                             msecs_to_jiffies(PME_TIMEOUT));
        }
        mutex_unlock(&pci_pme_list_mutex);
 }
 
-/**
- * pci_external_pme - is a device an external PCI PME source?
- * @dev: PCI device to check
- *
- */
-
-static bool pci_external_pme(struct pci_dev *dev)
-{
-       if (pci_is_pcie(dev) || dev->bus->number == 0)
-               return false;
-       return true;
-}
-
 /**
  * pci_pme_active - enable or disable PCI device's PME# function
  * @dev: PCI device to handle.
@@ -1503,7 +1501,7 @@ void pci_pme_active(struct pci_dev *dev, bool enable)
           hit, and the power savings from the devices will still be a
           win. */
 
-       if (pci_external_pme(dev)) {
+       if (dev->pme_poll) {
                struct pci_pme_device *pme_dev;
                if (enable) {
                        pme_dev = kmalloc(sizeof(struct pci_pme_device),
@@ -1821,6 +1819,7 @@ void pci_pm_init(struct pci_dev *dev)
                         (pmc & PCI_PM_CAP_PME_D3) ? " D3hot" : "",
                         (pmc & PCI_PM_CAP_PME_D3cold) ? " D3cold" : "");
                dev->pme_support = pmc >> PCI_PM_CAP_PME_SHIFT;
+               dev->pme_poll = true;
                /*
                 * Make device's PM flags reflect the wake-up capability, but
                 * let the user space enable it to wake up the system as needed.
@@ -3203,8 +3202,6 @@ int pcie_set_readrq(struct pci_dev *dev, int rq)
        if (rq < 128 || rq > 4096 || !is_power_of_2(rq))
                goto out;
 
-       v = (ffs(rq) - 8) << 12;
-
        cap = pci_pcie_cap(dev);
        if (!cap)
                goto out;
@@ -3212,6 +3209,22 @@ int pcie_set_readrq(struct pci_dev *dev, int rq)
        err = pci_read_config_word(dev, cap + PCI_EXP_DEVCTL, &ctl);
        if (err)
                goto out;
+       /*
+        * If using the "performance" PCIe config, we clamp the
+        * read rq size to the max packet size to prevent the
+        * host bridge generating requests larger than we can
+        * cope with
+        */
+       if (pcie_bus_config == PCIE_BUS_PERFORMANCE) {
+               int mps = pcie_get_mps(dev);
+
+               if (mps < 0)
+                       return mps;
+               if (mps < rq)
+                       rq = mps;
+       }
+
+       v = (ffs(rq) - 8) << 12;
 
        if ((ctl & PCI_EXP_DEVCTL_READRQ) != v) {
                ctl &= ~PCI_EXP_DEVCTL_READRQ;
index 0057344a3fcb231507a115d4d97ac84125da2161..001f1b78f39ca22e0309e5b9a958fcdfa3c055f5 100644 (file)
@@ -84,6 +84,9 @@ static bool pcie_pme_walk_bus(struct pci_bus *bus)
        list_for_each_entry(dev, &bus->devices, bus_list) {
                /* Skip PCIe devices in case we started from a root port. */
                if (!pci_is_pcie(dev) && pci_check_pme_status(dev)) {
+                       if (dev->pme_poll)
+                               dev->pme_poll = false;
+
                        pci_wakeup_event(dev);
                        pm_request_resume(&dev->dev);
                        ret = true;
@@ -142,6 +145,9 @@ static void pcie_pme_handle_request(struct pci_dev *port, u16 req_id)
 
        /* First, check if the PME is from the root port itself. */
        if (port->devfn == devfn && port->bus->number == busnr) {
+               if (port->pme_poll)
+                       port->pme_poll = false;
+
                if (pci_check_pme_status(port)) {
                        pm_request_resume(&port->dev);
                        found = true;
@@ -187,6 +193,9 @@ static void pcie_pme_handle_request(struct pci_dev *port, u16 req_id)
                /* The device is there, but we have to check its PME status. */
                found = pci_check_pme_status(dev);
                if (found) {
+                       if (dev->pme_poll)
+                               dev->pme_poll = false;
+
                        pci_wakeup_event(dev);
                        pm_request_resume(&dev->dev);
                }
index 6ab6bd3df4b25582f8fec61fbda9779333273a95..04e74f4857146e4700669504de55a6ad632823a0 100644 (file)
@@ -1363,31 +1363,25 @@ static int pcie_find_smpss(struct pci_dev *dev, void *data)
 
 static void pcie_write_mps(struct pci_dev *dev, int mps)
 {
-       int rc, dev_mpss;
-
-       dev_mpss = 128 << dev->pcie_mpss;
+       int rc;
 
        if (pcie_bus_config == PCIE_BUS_PERFORMANCE) {
-               if (dev->bus->self) {
-                       dev_dbg(&dev->bus->dev, "Bus MPSS %d\n",
-                               128 << dev->bus->self->pcie_mpss);
+               mps = 128 << dev->pcie_mpss;
 
-                       /* For "MPS Force Max", the assumption is made that
+               if (dev->pcie_type != PCI_EXP_TYPE_ROOT_PORT && dev->bus->self)
+                       /* For "Performance", the assumption is made that
                         * downstream communication will never be larger than
                         * the MRRS.  So, the MPS only needs to be configured
                         * for the upstream communication.  This being the case,
                         * walk from the top down and set the MPS of the child
                         * to that of the parent bus.
+                        *
+                        * Configure the device MPS with the smaller of the
+                        * device MPSS or the bridge MPS (which is assumed to be
+                        * properly configured at this point to the largest
+                        * allowable MPS based on its parent bus).
                         */
-                       mps = 128 << dev->bus->self->pcie_mpss;
-                       if (mps > dev_mpss)
-                               dev_warn(&dev->dev, "MPS configured higher than"
-                                        " maximum supported by the device.  If"
-                                        " a bus issue occurs, try running with"
-                                        " pci=pcie_bus_safe.\n");
-               }
-
-               dev->pcie_mpss = ffs(mps) - 8;
+                       mps = min(mps, pcie_get_mps(dev->bus->self));
        }
 
        rc = pcie_set_mps(dev, mps);
@@ -1395,25 +1389,22 @@ static void pcie_write_mps(struct pci_dev *dev, int mps)
                dev_err(&dev->dev, "Failed attempting to set the MPS\n");
 }
 
-static void pcie_write_mrrs(struct pci_dev *dev, int mps)
+static void pcie_write_mrrs(struct pci_dev *dev)
 {
-       int rc, mrrs, dev_mpss;
+       int rc, mrrs;
 
        /* In the "safe" case, do not configure the MRRS.  There appear to be
         * issues with setting MRRS to 0 on a number of devices.
         */
-
        if (pcie_bus_config != PCIE_BUS_PERFORMANCE)
                return;
 
-       dev_mpss = 128 << dev->pcie_mpss;
-
        /* For Max performance, the MRRS must be set to the largest supported
         * value.  However, it cannot be configured larger than the MPS the
-        * device or the bus can support.  This assumes that the largest MRRS
-        * available on the device cannot be smaller than the device MPSS.
+        * device or the bus can support.  This should already be properly
+        * configured by a prior call to pcie_write_mps.
         */
-       mrrs = min(mps, dev_mpss);
+       mrrs = pcie_get_mps(dev);
 
        /* MRRS is a R/W register.  Invalid values can be written, but a
         * subsequent read will verify if the value is acceptable or not.
@@ -1421,38 +1412,41 @@ static void pcie_write_mrrs(struct pci_dev *dev, int mps)
         * shrink the value until it is acceptable to the HW.
         */
        while (mrrs != pcie_get_readrq(dev) && mrrs >= 128) {
-               dev_warn(&dev->dev, "Attempting to modify the PCI-E MRRS value"
-                        " to %d.  If any issues are encountered, please try "
-                        "running with pci=pcie_bus_safe\n", mrrs);
                rc = pcie_set_readrq(dev, mrrs);
-               if (rc)
-                       dev_err(&dev->dev,
-                               "Failed attempting to set the MRRS\n");
+               if (!rc)
+                       break;
 
+               dev_warn(&dev->dev, "Failed attempting to set the MRRS\n");
                mrrs /= 2;
        }
+
+       if (mrrs < 128)
+               dev_err(&dev->dev, "MRRS was unable to be configured with a "
+                       "safe value.  If problems are experienced, try running "
+                       "with pci=pcie_bus_safe.\n");
 }
 
 static int pcie_bus_configure_set(struct pci_dev *dev, void *data)
 {
-       int mps = 128 << *(u8 *)data;
+       int mps, orig_mps;
 
        if (!pci_is_pcie(dev))
                return 0;
 
-       dev_dbg(&dev->dev, "Dev MPS %d MPSS %d MRRS %d\n",
-                pcie_get_mps(dev), 128<<dev->pcie_mpss, pcie_get_readrq(dev));
+       mps = 128 << *(u8 *)data;
+       orig_mps = pcie_get_mps(dev);
 
        pcie_write_mps(dev, mps);
-       pcie_write_mrrs(dev, mps);
+       pcie_write_mrrs(dev);
 
-       dev_dbg(&dev->dev, "Dev MPS %d MPSS %d MRRS %d\n",
-                pcie_get_mps(dev), 128<<dev->pcie_mpss, pcie_get_readrq(dev));
+       dev_info(&dev->dev, "PCI-E Max Payload Size set to %4d/%4d (was %4d), "
+                "Max Read Rq %4d\n", pcie_get_mps(dev), 128 << dev->pcie_mpss,
+                orig_mps, pcie_get_readrq(dev));
 
        return 0;
 }
 
-/* pcie_bus_configure_mps requires that pci_walk_bus work in a top-down,
+/* pcie_bus_configure_settings requires that pci_walk_bus work in a top-down,
  * parents then children fashion.  If this changes, then this code will not
  * work as designed.
  */
index b23856aaf6eb490bbfd9e83f1d6fe40056cc0a36..7285145ac1c917a5513376aba72321374f7e9eab 100644 (file)
@@ -2745,20 +2745,6 @@ static void ricoh_mmc_fixup_r5c832(struct pci_dev *dev)
        /* disable must be done via function #0 */
        if (PCI_FUNC(dev->devfn))
                return;
-
-       pci_read_config_byte(dev, 0xCB, &disable);
-
-       if (disable & 0x02)
-               return;
-
-       pci_read_config_byte(dev, 0xCA, &write_enable);
-       pci_write_config_byte(dev, 0xCA, 0x57);
-       pci_write_config_byte(dev, 0xCB, disable | 0x02);
-       pci_write_config_byte(dev, 0xCA, write_enable);
-
-       dev_notice(&dev->dev, "proprietary Ricoh MMC controller disabled (via firewire function)\n");
-       dev_notice(&dev->dev, "MMC cards are now supported by standard SDHCI controller\n");
-
        /*
         * RICOH 0xe823 SD/MMC card reader fails to recognize
         * certain types of SD/MMC cards. Lowering the SD base
@@ -2781,6 +2767,20 @@ static void ricoh_mmc_fixup_r5c832(struct pci_dev *dev)
 
                dev_notice(&dev->dev, "MMC controller base frequency changed to 50Mhz.\n");
        }
+
+       pci_read_config_byte(dev, 0xCB, &disable);
+
+       if (disable & 0x02)
+               return;
+
+       pci_read_config_byte(dev, 0xCA, &write_enable);
+       pci_write_config_byte(dev, 0xCA, 0x57);
+       pci_write_config_byte(dev, 0xCB, disable | 0x02);
+       pci_write_config_byte(dev, 0xCA, write_enable);
+
+       dev_notice(&dev->dev, "proprietary Ricoh MMC controller disabled (via firewire function)\n");
+       dev_notice(&dev->dev, "MMC cards are now supported by standard SDHCI controller\n");
+
 }
 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5C832, ricoh_mmc_fixup_r5c832);
 DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5C832, ricoh_mmc_fixup_r5c832);
@@ -2822,6 +2822,89 @@ static void __devinit fixup_ti816x_class(struct pci_dev* dev)
 }
 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_TI, 0xb800, fixup_ti816x_class);
 
+/* Some PCIe devices do not work reliably with the claimed maximum
+ * payload size supported.
+ */
+static void __devinit fixup_mpss_256(struct pci_dev *dev)
+{
+       dev->pcie_mpss = 1; /* 256 bytes */
+}
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SOLARFLARE,
+                        PCI_DEVICE_ID_SOLARFLARE_SFC4000A_0, fixup_mpss_256);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SOLARFLARE,
+                        PCI_DEVICE_ID_SOLARFLARE_SFC4000A_1, fixup_mpss_256);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SOLARFLARE,
+                        PCI_DEVICE_ID_SOLARFLARE_SFC4000B, fixup_mpss_256);
+
+/* Intel 5000 and 5100 Memory controllers have an errata with read completion
+ * coalescing (which is enabled by default on some BIOSes) and MPS of 256B.
+ * Since there is no way of knowing what the PCIE MPS on each fabric will be
+ * until all of the devices are discovered and buses walked, read completion
+ * coalescing must be disabled.  Unfortunately, it cannot be re-enabled because
+ * it is possible to hotplug a device with MPS of 256B.
+ */
+static void __devinit quirk_intel_mc_errata(struct pci_dev *dev)
+{
+       int err;
+       u16 rcc;
+
+       if (pcie_bus_config == PCIE_BUS_TUNE_OFF)
+               return;
+
+       /* Intel errata specifies bits to change but does not say what they are.
+        * Keeping them magical until such time as the registers and values can
+        * be explained.
+        */
+       err = pci_read_config_word(dev, 0x48, &rcc);
+       if (err) {
+               dev_err(&dev->dev, "Error attempting to read the read "
+                       "completion coalescing register.\n");
+               return;
+       }
+
+       if (!(rcc & (1 << 10)))
+               return;
+
+       rcc &= ~(1 << 10);
+
+       err = pci_write_config_word(dev, 0x48, rcc);
+       if (err) {
+               dev_err(&dev->dev, "Error attempting to write the read "
+                       "completion coalescing register.\n");
+               return;
+       }
+
+       pr_info_once("Read completion coalescing disabled due to hardware "
+                    "errata relating to 256B MPS.\n");
+}
+/* Intel 5000 series memory controllers and ports 2-7 */
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25c0, quirk_intel_mc_errata);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25d0, quirk_intel_mc_errata);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25d4, quirk_intel_mc_errata);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25d8, quirk_intel_mc_errata);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25e2, quirk_intel_mc_errata);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25e3, quirk_intel_mc_errata);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25e4, quirk_intel_mc_errata);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25e5, quirk_intel_mc_errata);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25e6, quirk_intel_mc_errata);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25e7, quirk_intel_mc_errata);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25f7, quirk_intel_mc_errata);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25f8, quirk_intel_mc_errata);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25f9, quirk_intel_mc_errata);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25fa, quirk_intel_mc_errata);
+/* Intel 5100 series memory controllers and ports 2-7 */
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65c0, quirk_intel_mc_errata);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65e2, quirk_intel_mc_errata);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65e3, quirk_intel_mc_errata);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65e4, quirk_intel_mc_errata);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65e5, quirk_intel_mc_errata);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65e6, quirk_intel_mc_errata);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65e7, quirk_intel_mc_errata);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65f7, quirk_intel_mc_errata);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65f8, quirk_intel_mc_errata);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65f9, quirk_intel_mc_errata);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65fa, quirk_intel_mc_errata);
+
 static void pci_do_fixups(struct pci_dev *dev, struct pci_fixup *f,
                          struct pci_fixup *end)
 {
index 784da9d3602985606d850d9d07f51b65f21e3f05..86b69f85f9005f778634d81ab52f548f091978e4 100644 (file)
@@ -426,7 +426,7 @@ static void __pci_setup_bridge(struct pci_bus *bus, unsigned long type)
        pci_write_config_word(bridge, PCI_BRIDGE_CONTROL, bus->bridge_ctl);
 }
 
-static void pci_setup_bridge(struct pci_bus *bus)
+void pci_setup_bridge(struct pci_bus *bus)
 {
        unsigned long type = IORESOURCE_IO | IORESOURCE_MEM |
                                  IORESOURCE_PREFETCH;
index 10cf2500522b3463c06a6a2f901911a193361163..f4e3d82379d7869f39f479b74484e3b28dda5140 100644 (file)
@@ -61,15 +61,18 @@ config ASUS_LAPTOP
        depends on INPUT
        depends on RFKILL || RFKILL = n
        select INPUT_SPARSEKMAP
+       select INPUT_POLLDEV
        ---help---
-         This is the new Linux driver for Asus laptops. It may also support some
-         MEDION, JVC or VICTOR laptops. It makes all the extra buttons generate
-         standard ACPI events and input events. It also adds
-         support for video output switching, LCD backlight control, Bluetooth and
-         Wlan control, and most importantly, allows you to blink those fancy LEDs.
+         This is a driver for Asus laptops, Lenovo SL and the Pegatron
+         Lucid tablet. It may also support some MEDION, JVC or VICTOR
+         laptops. It makes all the extra buttons generate standard
+         ACPI events and input events, and on the Lucid the built-in
+         accelerometer appears as an input device.  It also adds
+         support for video output switching, LCD backlight control,
+         Bluetooth and Wlan control, and most importantly, allows you
+         to blink those fancy LEDs.
 
-         For more information and a userspace daemon for handling the extra
-         buttons see <http://acpi4asus.sf.net>.
+         For more information see <http://acpi4asus.sf.net>.
 
          If you have an ACPI-compatible ASUS laptop, say Y or M here.
 
index af2bb20cb2fbd39bcc3be8d77e42565cb35b1877..b848277171a4e74cbd373338fe1a3425381e3cf7 100644 (file)
@@ -190,6 +190,7 @@ enum interface_flags {
        ACER_AMW0,
        ACER_AMW0_V2,
        ACER_WMID,
+       ACER_WMID_v2,
 };
 
 #define ACER_DEFAULT_WIRELESS  0
@@ -205,6 +206,7 @@ static int threeg = -1;
 static int force_series;
 static bool ec_raw_mode;
 static bool has_type_aa;
+static u16 commun_func_bitmap;
 
 module_param(mailled, int, 0444);
 module_param(brightness, int, 0444);
@@ -464,6 +466,15 @@ static struct dmi_system_id acer_quirks[] = {
                },
                .driver_data = &quirk_lenovo_ideapad_s205,
        },
+       {
+               .callback = dmi_matched,
+               .ident = "Lenovo 3000 N200",
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "0687A31"),
+               },
+               .driver_data = &quirk_fujitsu_amilo_li_1718,
+       },
        {}
 };
 
@@ -868,6 +879,174 @@ static acpi_status WMID_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
        return WMI_execute_u32(method_id, (u32)value, NULL);
 }
 
+static acpi_status wmid3_get_device_status(u32 *value, u16 device)
+{
+       struct wmid3_gds_return_value return_value;
+       acpi_status status;
+       union acpi_object *obj;
+       struct wmid3_gds_input_param params = {
+               .function_num = 0x1,
+               .hotkey_number = 0x01,
+               .devices = device,
+       };
+       struct acpi_buffer input = {
+               sizeof(struct wmid3_gds_input_param),
+               &params
+       };
+       struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
+
+       status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
+       if (ACPI_FAILURE(status))
+               return status;
+
+       obj = output.pointer;
+
+       if (!obj)
+               return AE_ERROR;
+       else if (obj->type != ACPI_TYPE_BUFFER) {
+               kfree(obj);
+               return AE_ERROR;
+       }
+       if (obj->buffer.length != 8) {
+               pr_warn("Unknown buffer length %d\n", obj->buffer.length);
+               kfree(obj);
+               return AE_ERROR;
+       }
+
+       return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
+       kfree(obj);
+
+       if (return_value.error_code || return_value.ec_return_value)
+               pr_warn("Get 0x%x Device Status failed: 0x%x - 0x%x\n",
+                       device,
+                       return_value.error_code,
+                       return_value.ec_return_value);
+       else
+               *value = !!(return_value.devices & device);
+
+       return status;
+}
+
+static acpi_status wmid_v2_get_u32(u32 *value, u32 cap)
+{
+       u16 device;
+
+       switch (cap) {
+       case ACER_CAP_WIRELESS:
+               device = ACER_WMID3_GDS_WIRELESS;
+               break;
+       case ACER_CAP_BLUETOOTH:
+               device = ACER_WMID3_GDS_BLUETOOTH;
+               break;
+       case ACER_CAP_THREEG:
+               device = ACER_WMID3_GDS_THREEG;
+               break;
+       default:
+               return AE_ERROR;
+       }
+       return wmid3_get_device_status(value, device);
+}
+
+static acpi_status wmid3_set_device_status(u32 value, u16 device)
+{
+       struct wmid3_gds_return_value return_value;
+       acpi_status status;
+       union acpi_object *obj;
+       u16 devices;
+       struct wmid3_gds_input_param params = {
+               .function_num = 0x1,
+               .hotkey_number = 0x01,
+               .devices = commun_func_bitmap,
+       };
+       struct acpi_buffer input = {
+               sizeof(struct wmid3_gds_input_param),
+               &params
+       };
+       struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
+       struct acpi_buffer output2 = { ACPI_ALLOCATE_BUFFER, NULL };
+
+       status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
+       if (ACPI_FAILURE(status))
+               return status;
+
+       obj = output.pointer;
+
+       if (!obj)
+               return AE_ERROR;
+       else if (obj->type != ACPI_TYPE_BUFFER) {
+               kfree(obj);
+               return AE_ERROR;
+       }
+       if (obj->buffer.length != 8) {
+               pr_warning("Unknown buffer length %d\n", obj->buffer.length);
+               kfree(obj);
+               return AE_ERROR;
+       }
+
+       return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
+       kfree(obj);
+
+       if (return_value.error_code || return_value.ec_return_value) {
+               pr_warning("Get Current Device Status failed: "
+                       "0x%x - 0x%x\n", return_value.error_code,
+                       return_value.ec_return_value);
+               return status;
+       }
+
+       devices = return_value.devices;
+       params.function_num = 0x2;
+       params.hotkey_number = 0x01;
+       params.devices = (value) ? (devices | device) : (devices & ~device);
+
+       status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output2);
+       if (ACPI_FAILURE(status))
+               return status;
+
+       obj = output2.pointer;
+
+       if (!obj)
+               return AE_ERROR;
+       else if (obj->type != ACPI_TYPE_BUFFER) {
+               kfree(obj);
+               return AE_ERROR;
+       }
+       if (obj->buffer.length != 4) {
+               pr_warning("Unknown buffer length %d\n", obj->buffer.length);
+               kfree(obj);
+               return AE_ERROR;
+       }
+
+       return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
+       kfree(obj);
+
+       if (return_value.error_code || return_value.ec_return_value)
+               pr_warning("Set Device Status failed: "
+                       "0x%x - 0x%x\n", return_value.error_code,
+                       return_value.ec_return_value);
+
+       return status;
+}
+
+static acpi_status wmid_v2_set_u32(u32 value, u32 cap)
+{
+       u16 device;
+
+       switch (cap) {
+       case ACER_CAP_WIRELESS:
+               device = ACER_WMID3_GDS_WIRELESS;
+               break;
+       case ACER_CAP_BLUETOOTH:
+               device = ACER_WMID3_GDS_BLUETOOTH;
+               break;
+       case ACER_CAP_THREEG:
+               device = ACER_WMID3_GDS_THREEG;
+               break;
+       default:
+               return AE_ERROR;
+       }
+       return wmid3_set_device_status(value, device);
+}
+
 static void type_aa_dmi_decode(const struct dmi_header *header, void *dummy)
 {
        struct hotkey_function_type_aa *type_aa;
@@ -881,6 +1060,7 @@ static void type_aa_dmi_decode(const struct dmi_header *header, void *dummy)
 
        pr_info("Function bitmap for Communication Button: 0x%x\n",
                type_aa->commun_func_bitmap);
+       commun_func_bitmap = type_aa->commun_func_bitmap;
 
        if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_WIRELESS)
                interface->capability |= ACER_CAP_WIRELESS;
@@ -913,17 +1093,13 @@ static acpi_status WMID_set_capabilities(void)
                return AE_ERROR;
        }
 
-       dmi_walk(type_aa_dmi_decode, NULL);
-       if (!has_type_aa) {
+       pr_info("Function bitmap for Communication Device: 0x%x\n", devices);
+       if (devices & 0x07)
                interface->capability |= ACER_CAP_WIRELESS;
-               if (devices & 0x40)
-                       interface->capability |= ACER_CAP_THREEG;
-               if (devices & 0x10)
-                       interface->capability |= ACER_CAP_BLUETOOTH;
-       }
-
-       /* WMID always provides brightness methods */
-       interface->capability |= ACER_CAP_BRIGHTNESS;
+       if (devices & 0x40)
+               interface->capability |= ACER_CAP_THREEG;
+       if (devices & 0x10)
+               interface->capability |= ACER_CAP_BLUETOOTH;
 
        if (!(devices & 0x20))
                max_brightness = 0x9;
@@ -936,6 +1112,10 @@ static struct wmi_interface wmid_interface = {
        .type = ACER_WMID,
 };
 
+static struct wmi_interface wmid_v2_interface = {
+       .type = ACER_WMID_v2,
+};
+
 /*
  * Generic Device (interface-independent)
  */
@@ -956,6 +1136,14 @@ static acpi_status get_u32(u32 *value, u32 cap)
        case ACER_WMID:
                status = WMID_get_u32(value, cap, interface);
                break;
+       case ACER_WMID_v2:
+               if (cap & (ACER_CAP_WIRELESS |
+                          ACER_CAP_BLUETOOTH |
+                          ACER_CAP_THREEG))
+                       status = wmid_v2_get_u32(value, cap);
+               else if (wmi_has_guid(WMID_GUID2))
+                       status = WMID_get_u32(value, cap, interface);
+               break;
        }
 
        return status;
@@ -989,6 +1177,13 @@ static acpi_status set_u32(u32 value, u32 cap)
                        }
                case ACER_WMID:
                        return WMID_set_u32(value, cap, interface);
+               case ACER_WMID_v2:
+                       if (cap & (ACER_CAP_WIRELESS |
+                                  ACER_CAP_BLUETOOTH |
+                                  ACER_CAP_THREEG))
+                               return wmid_v2_set_u32(value, cap);
+                       else if (wmi_has_guid(WMID_GUID2))
+                               return WMID_set_u32(value, cap, interface);
                default:
                        return AE_BAD_PARAMETER;
                }
@@ -1095,186 +1290,6 @@ static void acer_backlight_exit(void)
        backlight_device_unregister(acer_backlight_device);
 }
 
-static acpi_status wmid3_get_device_status(u32 *value, u16 device)
-{
-       struct wmid3_gds_return_value return_value;
-       acpi_status status;
-       union acpi_object *obj;
-       struct wmid3_gds_input_param params = {
-               .function_num = 0x1,
-               .hotkey_number = 0x01,
-               .devices = device,
-       };
-       struct acpi_buffer input = {
-               sizeof(struct wmid3_gds_input_param),
-               &params
-       };
-       struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
-
-       status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
-       if (ACPI_FAILURE(status))
-               return status;
-
-       obj = output.pointer;
-
-       if (!obj)
-               return AE_ERROR;
-       else if (obj->type != ACPI_TYPE_BUFFER) {
-               kfree(obj);
-               return AE_ERROR;
-       }
-       if (obj->buffer.length != 8) {
-               pr_warn("Unknown buffer length %d\n", obj->buffer.length);
-               kfree(obj);
-               return AE_ERROR;
-       }
-
-       return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
-       kfree(obj);
-
-       if (return_value.error_code || return_value.ec_return_value)
-               pr_warn("Get Device Status failed: 0x%x - 0x%x\n",
-                       return_value.error_code,
-                       return_value.ec_return_value);
-       else
-               *value = !!(return_value.devices & device);
-
-       return status;
-}
-
-static acpi_status get_device_status(u32 *value, u32 cap)
-{
-       if (wmi_has_guid(WMID_GUID3)) {
-               u16 device;
-
-               switch (cap) {
-               case ACER_CAP_WIRELESS:
-                       device = ACER_WMID3_GDS_WIRELESS;
-                       break;
-               case ACER_CAP_BLUETOOTH:
-                       device = ACER_WMID3_GDS_BLUETOOTH;
-                       break;
-               case ACER_CAP_THREEG:
-                       device = ACER_WMID3_GDS_THREEG;
-                       break;
-               default:
-                       return AE_ERROR;
-               }
-               return wmid3_get_device_status(value, device);
-
-       } else {
-               return get_u32(value, cap);
-       }
-}
-
-static acpi_status wmid3_set_device_status(u32 value, u16 device)
-{
-       struct wmid3_gds_return_value return_value;
-       acpi_status status;
-       union acpi_object *obj;
-       u16 devices;
-       struct wmid3_gds_input_param params = {
-               .function_num = 0x1,
-               .hotkey_number = 0x01,
-               .devices = ACER_WMID3_GDS_WIRELESS |
-                               ACER_WMID3_GDS_THREEG |
-                               ACER_WMID3_GDS_WIMAX |
-                               ACER_WMID3_GDS_BLUETOOTH,
-       };
-       struct acpi_buffer input = {
-               sizeof(struct wmid3_gds_input_param),
-               &params
-       };
-       struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
-       struct acpi_buffer output2 = { ACPI_ALLOCATE_BUFFER, NULL };
-
-       status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
-       if (ACPI_FAILURE(status))
-               return status;
-
-       obj = output.pointer;
-
-       if (!obj)
-               return AE_ERROR;
-       else if (obj->type != ACPI_TYPE_BUFFER) {
-               kfree(obj);
-               return AE_ERROR;
-       }
-       if (obj->buffer.length != 8) {
-               pr_warning("Unknown buffer length %d\n", obj->buffer.length);
-               kfree(obj);
-               return AE_ERROR;
-       }
-
-       return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
-       kfree(obj);
-
-       if (return_value.error_code || return_value.ec_return_value) {
-               pr_warning("Get Current Device Status failed: "
-                       "0x%x - 0x%x\n", return_value.error_code,
-                       return_value.ec_return_value);
-               return status;
-       }
-
-       devices = return_value.devices;
-       params.function_num = 0x2;
-       params.hotkey_number = 0x01;
-       params.devices = (value) ? (devices | device) : (devices & ~device);
-
-       status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output2);
-       if (ACPI_FAILURE(status))
-               return status;
-
-       obj = output2.pointer;
-
-       if (!obj)
-               return AE_ERROR;
-       else if (obj->type != ACPI_TYPE_BUFFER) {
-               kfree(obj);
-               return AE_ERROR;
-       }
-       if (obj->buffer.length != 4) {
-               pr_warning("Unknown buffer length %d\n", obj->buffer.length);
-               kfree(obj);
-               return AE_ERROR;
-       }
-
-       return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
-       kfree(obj);
-
-       if (return_value.error_code || return_value.ec_return_value)
-               pr_warning("Set Device Status failed: "
-                       "0x%x - 0x%x\n", return_value.error_code,
-                       return_value.ec_return_value);
-
-       return status;
-}
-
-static acpi_status set_device_status(u32 value, u32 cap)
-{
-       if (wmi_has_guid(WMID_GUID3)) {
-               u16 device;
-
-               switch (cap) {
-               case ACER_CAP_WIRELESS:
-                       device = ACER_WMID3_GDS_WIRELESS;
-                       break;
-               case ACER_CAP_BLUETOOTH:
-                       device = ACER_WMID3_GDS_BLUETOOTH;
-                       break;
-               case ACER_CAP_THREEG:
-                       device = ACER_WMID3_GDS_THREEG;
-                       break;
-               default:
-                       return AE_ERROR;
-               }
-               return wmid3_set_device_status(value, device);
-
-       } else {
-               return set_u32(value, cap);
-       }
-}
-
 /*
  * Rfkill devices
  */
@@ -1285,12 +1300,13 @@ static void acer_rfkill_update(struct work_struct *ignored)
        u32 state;
        acpi_status status;
 
-       status = get_u32(&state, ACER_CAP_WIRELESS);
-       if (ACPI_SUCCESS(status)) {
-               if (quirks->wireless == 3) {
-                       rfkill_set_hw_state(wireless_rfkill, !state);
-               } else {
-                       rfkill_set_sw_state(wireless_rfkill, !state);
+       if (has_cap(ACER_CAP_WIRELESS)) {
+               status = get_u32(&state, ACER_CAP_WIRELESS);
+               if (ACPI_SUCCESS(status)) {
+                       if (quirks->wireless == 3)
+                               rfkill_set_hw_state(wireless_rfkill, !state);
+                       else
+                               rfkill_set_sw_state(wireless_rfkill, !state);
                }
        }
 
@@ -1301,8 +1317,7 @@ static void acer_rfkill_update(struct work_struct *ignored)
        }
 
        if (has_cap(ACER_CAP_THREEG) && wmi_has_guid(WMID_GUID3)) {
-               status = wmid3_get_device_status(&state,
-                               ACER_WMID3_GDS_THREEG);
+               status = get_u32(&state, ACER_WMID3_GDS_THREEG);
                if (ACPI_SUCCESS(status))
                        rfkill_set_sw_state(threeg_rfkill, !state);
        }
@@ -1316,7 +1331,7 @@ static int acer_rfkill_set(void *data, bool blocked)
        u32 cap = (unsigned long)data;
 
        if (rfkill_inited) {
-               status = set_device_status(!blocked, cap);
+               status = set_u32(!blocked, cap);
                if (ACPI_FAILURE(status))
                        return -ENODEV;
        }
@@ -1343,7 +1358,7 @@ static struct rfkill *acer_rfkill_register(struct device *dev,
        if (!rfkill_dev)
                return ERR_PTR(-ENOMEM);
 
-       status = get_device_status(&state, cap);
+       status = get_u32(&state, cap);
 
        err = rfkill_register(rfkill_dev);
        if (err) {
@@ -1359,19 +1374,24 @@ static struct rfkill *acer_rfkill_register(struct device *dev,
 
 static int acer_rfkill_init(struct device *dev)
 {
-       wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN,
-               "acer-wireless", ACER_CAP_WIRELESS);
-       if (IS_ERR(wireless_rfkill))
-               return PTR_ERR(wireless_rfkill);
+       int err;
+
+       if (has_cap(ACER_CAP_WIRELESS)) {
+               wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN,
+                       "acer-wireless", ACER_CAP_WIRELESS);
+               if (IS_ERR(wireless_rfkill)) {
+                       err = PTR_ERR(wireless_rfkill);
+                       goto error_wireless;
+               }
+       }
 
        if (has_cap(ACER_CAP_BLUETOOTH)) {
                bluetooth_rfkill = acer_rfkill_register(dev,
                        RFKILL_TYPE_BLUETOOTH, "acer-bluetooth",
                        ACER_CAP_BLUETOOTH);
                if (IS_ERR(bluetooth_rfkill)) {
-                       rfkill_unregister(wireless_rfkill);
-                       rfkill_destroy(wireless_rfkill);
-                       return PTR_ERR(bluetooth_rfkill);
+                       err = PTR_ERR(bluetooth_rfkill);
+                       goto error_bluetooth;
                }
        }
 
@@ -1380,30 +1400,44 @@ static int acer_rfkill_init(struct device *dev)
                        RFKILL_TYPE_WWAN, "acer-threeg",
                        ACER_CAP_THREEG);
                if (IS_ERR(threeg_rfkill)) {
-                       rfkill_unregister(wireless_rfkill);
-                       rfkill_destroy(wireless_rfkill);
-                       rfkill_unregister(bluetooth_rfkill);
-                       rfkill_destroy(bluetooth_rfkill);
-                       return PTR_ERR(threeg_rfkill);
+                       err = PTR_ERR(threeg_rfkill);
+                       goto error_threeg;
                }
        }
 
        rfkill_inited = true;
 
-       if (ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID))
+       if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
+           has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
                schedule_delayed_work(&acer_rfkill_work,
                        round_jiffies_relative(HZ));
 
        return 0;
+
+error_threeg:
+       if (has_cap(ACER_CAP_BLUETOOTH)) {
+               rfkill_unregister(bluetooth_rfkill);
+               rfkill_destroy(bluetooth_rfkill);
+       }
+error_bluetooth:
+       if (has_cap(ACER_CAP_WIRELESS)) {
+               rfkill_unregister(wireless_rfkill);
+               rfkill_destroy(wireless_rfkill);
+       }
+error_wireless:
+       return err;
 }
 
 static void acer_rfkill_exit(void)
 {
-       if (ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID))
+       if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
+           has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
                cancel_delayed_work_sync(&acer_rfkill_work);
 
-       rfkill_unregister(wireless_rfkill);
-       rfkill_destroy(wireless_rfkill);
+       if (has_cap(ACER_CAP_WIRELESS)) {
+               rfkill_unregister(wireless_rfkill);
+               rfkill_destroy(wireless_rfkill);
+       }
 
        if (has_cap(ACER_CAP_BLUETOOTH)) {
                rfkill_unregister(bluetooth_rfkill);
@@ -1428,11 +1462,7 @@ static ssize_t show_bool_threeg(struct device *dev,
 
        pr_info("This threeg sysfs will be removed in 2012"
                " - used by: %s\n", current->comm);
-       if (wmi_has_guid(WMID_GUID3))
-               status = wmid3_get_device_status(&result,
-                               ACER_WMID3_GDS_THREEG);
-       else
-               status = get_u32(&result, ACER_CAP_THREEG);
+       status = get_u32(&result, ACER_CAP_THREEG);
        if (ACPI_SUCCESS(status))
                return sprintf(buf, "%u\n", result);
        return sprintf(buf, "Read error\n");
@@ -1464,6 +1494,8 @@ static ssize_t show_interface(struct device *dev, struct device_attribute *attr,
                return sprintf(buf, "AMW0 v2\n");
        case ACER_WMID:
                return sprintf(buf, "WMID\n");
+       case ACER_WMID_v2:
+               return sprintf(buf, "WMID v2\n");
        default:
                return sprintf(buf, "Error!\n");
        }
@@ -1883,12 +1915,20 @@ static int __init acer_wmi_init(void)
        if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
                interface = &wmid_interface;
 
+       if (wmi_has_guid(WMID_GUID3))
+               interface = &wmid_v2_interface;
+
+       if (interface)
+               dmi_walk(type_aa_dmi_decode, NULL);
+
        if (wmi_has_guid(WMID_GUID2) && interface) {
-               if (ACPI_FAILURE(WMID_set_capabilities())) {
+               if (!has_type_aa && ACPI_FAILURE(WMID_set_capabilities())) {
                        pr_err("Unable to detect available WMID devices\n");
                        return -ENODEV;
                }
-       } else if (!wmi_has_guid(WMID_GUID2) && interface) {
+               /* WMID always provides brightness methods */
+               interface->capability |= ACER_CAP_BRIGHTNESS;
+       } else if (!wmi_has_guid(WMID_GUID2) && interface && !has_type_aa) {
                pr_err("No WMID device detection method found\n");
                return -ENODEV;
        }
@@ -1912,7 +1952,7 @@ static int __init acer_wmi_init(void)
 
        set_quirks();
 
-       if (acpi_video_backlight_support() && has_cap(ACER_CAP_BRIGHTNESS)) {
+       if (acpi_video_backlight_support()) {
                interface->capability &= ~ACER_CAP_BRIGHTNESS;
                pr_info("Brightness must be controlled by "
                       "generic video driver\n");
index fa6d7ec68b269670b4de8ca24cb97b3d55160acc..edaccad9b5bf9671949febd19e31bfef3308b31e 100644 (file)
@@ -4,6 +4,7 @@
  *
  *  Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 Karol Kozimor
  *  Copyright (C) 2006-2007 Corentin Chary
+ *  Copyright (C) 2011 Wind River Systems
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -48,6 +49,7 @@
 #include <linux/uaccess.h>
 #include <linux/input.h>
 #include <linux/input/sparse-keymap.h>
+#include <linux/input-polldev.h>
 #include <linux/rfkill.h>
 #include <linux/slab.h>
 #include <linux/dmi.h>
@@ -83,26 +85,32 @@ static int wlan_status = 1;
 static int bluetooth_status = 1;
 static int wimax_status = -1;
 static int wwan_status = -1;
+static int als_status;
 
 module_param(wlan_status, int, 0444);
 MODULE_PARM_DESC(wlan_status, "Set the wireless status on boot "
                 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
-                "default is 1");
+                "default is -1");
 
 module_param(bluetooth_status, int, 0444);
 MODULE_PARM_DESC(bluetooth_status, "Set the wireless status on boot "
                 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
-                "default is 1");
+                "default is -1");
 
 module_param(wimax_status, int, 0444);
 MODULE_PARM_DESC(wimax_status, "Set the wireless status on boot "
                 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
-                "default is 1");
+                "default is -1");
 
 module_param(wwan_status, int, 0444);
 MODULE_PARM_DESC(wwan_status, "Set the wireless status on boot "
                 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
-                "default is 1");
+                "default is -1");
+
+module_param(als_status, int, 0444);
+MODULE_PARM_DESC(als_status, "Set the ALS status on boot "
+                "(0 = disabled, 1 = enabled). "
+                "default is 0");
 
 /*
  * Some events we use, same for all Asus
@@ -173,6 +181,29 @@ MODULE_PARM_DESC(wwan_status, "Set the wireless status on boot "
 #define METHOD_KBD_LIGHT_SET   "SLKB"
 #define METHOD_KBD_LIGHT_GET   "GLKB"
 
+/* For Pegatron Lucid tablet */
+#define DEVICE_NAME_PEGA       "Lucid"
+
+#define METHOD_PEGA_ENABLE     "ENPR"
+#define METHOD_PEGA_DISABLE    "DAPR"
+#define PEGA_WLAN      0x00
+#define PEGA_BLUETOOTH 0x01
+#define PEGA_WWAN      0x02
+#define PEGA_ALS       0x04
+#define PEGA_ALS_POWER 0x05
+
+#define METHOD_PEGA_READ       "RDLN"
+#define PEGA_READ_ALS_H        0x02
+#define PEGA_READ_ALS_L        0x03
+
+#define PEGA_ACCEL_NAME "pega_accel"
+#define PEGA_ACCEL_DESC "Pegatron Lucid Tablet Accelerometer"
+#define METHOD_XLRX "XLRX"
+#define METHOD_XLRY "XLRY"
+#define METHOD_XLRZ "XLRZ"
+#define PEGA_ACC_CLAMP 512 /* 1G accel is reported as ~256, so clamp to 2G */
+#define PEGA_ACC_RETRIES 3
+
 /*
  * Define a specific led structure to keep the main structure clean
  */
@@ -184,6 +215,15 @@ struct asus_led {
        const char *method;
 };
 
+/*
+ * Same thing for rfkill
+ */
+struct asus_pega_rfkill {
+       int control_id;         /* type of control. Maps to PEGA_* values */
+       struct rfkill *rfkill;
+       struct asus_laptop *asus;
+};
+
 /*
  * This is the main structure, we can use it to store anything interesting
  * about the hotk device
@@ -198,6 +238,7 @@ struct asus_laptop {
 
        struct input_dev *inputdev;
        struct key_entry *keymap;
+       struct input_polled_dev *pega_accel_poll;
 
        struct asus_led mled;
        struct asus_led tled;
@@ -209,9 +250,18 @@ struct asus_laptop {
 
        int wireless_status;
        bool have_rsts;
+       bool is_pega_lucid;
+       bool pega_acc_live;
+       int pega_acc_x;
+       int pega_acc_y;
+       int pega_acc_z;
 
        struct rfkill *gps_rfkill;
 
+       struct asus_pega_rfkill wlanrfk;
+       struct asus_pega_rfkill btrfk;
+       struct asus_pega_rfkill wwanrfk;
+
        acpi_handle handle;     /* the handle of the hotk device */
        u32 ledd_status;        /* status of the LED display */
        u8 light_level;         /* light sensor level */
@@ -323,6 +373,127 @@ static int acpi_check_handle(acpi_handle handle, const char *method,
        return 0;
 }
 
+static bool asus_check_pega_lucid(struct asus_laptop *asus)
+{
+       return !strcmp(asus->name, DEVICE_NAME_PEGA) &&
+          !acpi_check_handle(asus->handle, METHOD_PEGA_ENABLE, NULL) &&
+          !acpi_check_handle(asus->handle, METHOD_PEGA_DISABLE, NULL) &&
+          !acpi_check_handle(asus->handle, METHOD_PEGA_READ, NULL);
+}
+
+static int asus_pega_lucid_set(struct asus_laptop *asus, int unit, bool enable)
+{
+       char *method = enable ? METHOD_PEGA_ENABLE : METHOD_PEGA_DISABLE;
+       return write_acpi_int(asus->handle, method, unit);
+}
+
+static int pega_acc_axis(struct asus_laptop *asus, int curr, char *method)
+{
+       int i, delta;
+       unsigned long long val;
+       for (i = 0; i < PEGA_ACC_RETRIES; i++) {
+               acpi_evaluate_integer(asus->handle, method, NULL, &val);
+
+               /* The output is noisy.  From reading the ASL
+                * dissassembly, timeout errors are returned with 1's
+                * in the high word, and the lack of locking around
+                * thei hi/lo byte reads means that a transition
+                * between (for example) -1 and 0 could be read as
+                * 0xff00 or 0x00ff. */
+               delta = abs(curr - (short)val);
+               if (delta < 128 && !(val & ~0xffff))
+                       break;
+       }
+       return clamp_val((short)val, -PEGA_ACC_CLAMP, PEGA_ACC_CLAMP);
+}
+
+static void pega_accel_poll(struct input_polled_dev *ipd)
+{
+       struct device *parent = ipd->input->dev.parent;
+       struct asus_laptop *asus = dev_get_drvdata(parent);
+
+       /* In some cases, the very first call to poll causes a
+        * recursive fault under the polldev worker.  This is
+        * apparently related to very early userspace access to the
+        * device, and perhaps a firmware bug. Fake the first report. */
+       if (!asus->pega_acc_live) {
+               asus->pega_acc_live = true;
+               input_report_abs(ipd->input, ABS_X, 0);
+               input_report_abs(ipd->input, ABS_Y, 0);
+               input_report_abs(ipd->input, ABS_Z, 0);
+               input_sync(ipd->input);
+               return;
+       }
+
+       asus->pega_acc_x = pega_acc_axis(asus, asus->pega_acc_x, METHOD_XLRX);
+       asus->pega_acc_y = pega_acc_axis(asus, asus->pega_acc_y, METHOD_XLRY);
+       asus->pega_acc_z = pega_acc_axis(asus, asus->pega_acc_z, METHOD_XLRZ);
+
+       /* Note transform, convert to "right/up/out" in the native
+        * landscape orientation (i.e. the vector is the direction of
+        * "real up" in the device's cartiesian coordinates). */
+       input_report_abs(ipd->input, ABS_X, -asus->pega_acc_x);
+       input_report_abs(ipd->input, ABS_Y, -asus->pega_acc_y);
+       input_report_abs(ipd->input, ABS_Z,  asus->pega_acc_z);
+       input_sync(ipd->input);
+}
+
+static void pega_accel_exit(struct asus_laptop *asus)
+{
+       if (asus->pega_accel_poll) {
+               input_unregister_polled_device(asus->pega_accel_poll);
+               input_free_polled_device(asus->pega_accel_poll);
+       }
+       asus->pega_accel_poll = NULL;
+}
+
+static int pega_accel_init(struct asus_laptop *asus)
+{
+       int err;
+       struct input_polled_dev *ipd;
+
+       if (!asus->is_pega_lucid)
+               return -ENODEV;
+
+       if (acpi_check_handle(asus->handle, METHOD_XLRX, NULL) ||
+           acpi_check_handle(asus->handle, METHOD_XLRY, NULL) ||
+           acpi_check_handle(asus->handle, METHOD_XLRZ, NULL))
+               return -ENODEV;
+
+       ipd = input_allocate_polled_device();
+       if (!ipd)
+               return -ENOMEM;
+
+       ipd->poll = pega_accel_poll;
+       ipd->poll_interval = 125;
+       ipd->poll_interval_min = 50;
+       ipd->poll_interval_max = 2000;
+
+       ipd->input->name = PEGA_ACCEL_DESC;
+       ipd->input->phys = PEGA_ACCEL_NAME "/input0";
+       ipd->input->dev.parent = &asus->platform_device->dev;
+       ipd->input->id.bustype = BUS_HOST;
+
+       set_bit(EV_ABS, ipd->input->evbit);
+       input_set_abs_params(ipd->input, ABS_X,
+                            -PEGA_ACC_CLAMP, PEGA_ACC_CLAMP, 0, 0);
+       input_set_abs_params(ipd->input, ABS_Y,
+                            -PEGA_ACC_CLAMP, PEGA_ACC_CLAMP, 0, 0);
+       input_set_abs_params(ipd->input, ABS_Z,
+                            -PEGA_ACC_CLAMP, PEGA_ACC_CLAMP, 0, 0);
+
+       err = input_register_polled_device(ipd);
+       if (err)
+               goto exit;
+
+       asus->pega_accel_poll = ipd;
+       return 0;
+
+exit:
+       input_free_polled_device(ipd);
+       return err;
+}
+
 /* Generic LED function */
 static int asus_led_set(struct asus_laptop *asus, const char *method,
                         int value)
@@ -430,17 +601,17 @@ static enum led_brightness asus_kled_cdev_get(struct led_classdev *led_cdev)
 
 static void asus_led_exit(struct asus_laptop *asus)
 {
-       if (asus->mled.led.dev)
+       if (!IS_ERR_OR_NULL(asus->mled.led.dev))
                led_classdev_unregister(&asus->mled.led);
-       if (asus->tled.led.dev)
+       if (!IS_ERR_OR_NULL(asus->tled.led.dev))
                led_classdev_unregister(&asus->tled.led);
-       if (asus->pled.led.dev)
+       if (!IS_ERR_OR_NULL(asus->pled.led.dev))
                led_classdev_unregister(&asus->pled.led);
-       if (asus->rled.led.dev)
+       if (!IS_ERR_OR_NULL(asus->rled.led.dev))
                led_classdev_unregister(&asus->rled.led);
-       if (asus->gled.led.dev)
+       if (!IS_ERR_OR_NULL(asus->gled.led.dev))
                led_classdev_unregister(&asus->gled.led);
-       if (asus->kled.led.dev)
+       if (!IS_ERR_OR_NULL(asus->kled.led.dev))
                led_classdev_unregister(&asus->kled.led);
        if (asus->led_workqueue) {
                destroy_workqueue(asus->led_workqueue);
@@ -473,6 +644,13 @@ static int asus_led_init(struct asus_laptop *asus)
 {
        int r;
 
+       /*
+        * The Pegatron Lucid has no physical leds, but all methods are
+        * available in the DSDT...
+        */
+       if (asus->is_pega_lucid)
+               return 0;
+
        /*
         * Functions that actually update the LED's are called from a
         * workqueue. By doing this as separate work rather than when the LED
@@ -907,8 +1085,18 @@ static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
  */
 static void asus_als_switch(struct asus_laptop *asus, int value)
 {
-       if (write_acpi_int(asus->handle, METHOD_ALS_CONTROL, value))
-               pr_warn("Error setting light sensor switch\n");
+       int ret;
+
+       if (asus->is_pega_lucid) {
+               ret = asus_pega_lucid_set(asus, PEGA_ALS, value);
+               if (!ret)
+                       ret = asus_pega_lucid_set(asus, PEGA_ALS_POWER, value);
+       } else {
+               ret = write_acpi_int(asus->handle, METHOD_ALS_CONTROL, value);
+       }
+       if (ret)
+               pr_warning("Error setting light sensor switch\n");
+
        asus->light_switch = value;
 }
 
@@ -964,6 +1152,35 @@ static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
        return rv;
 }
 
+static int pega_int_read(struct asus_laptop *asus, int arg, int *result)
+{
+       struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
+       int err = write_acpi_int_ret(asus->handle, METHOD_PEGA_READ, arg,
+                                    &buffer);
+       if (!err) {
+               union acpi_object *obj = buffer.pointer;
+               if (obj && obj->type == ACPI_TYPE_INTEGER)
+                       *result = obj->integer.value;
+               else
+                       err = -EIO;
+       }
+       return err;
+}
+
+static ssize_t show_lsvalue(struct device *dev,
+                           struct device_attribute *attr, char *buf)
+{
+       struct asus_laptop *asus = dev_get_drvdata(dev);
+       int err, hi, lo;
+
+       err = pega_int_read(asus, PEGA_READ_ALS_H, &hi);
+       if (!err)
+               err = pega_int_read(asus, PEGA_READ_ALS_L, &lo);
+       if (!err)
+               return sprintf(buf, "%d\n", 10 * hi + lo);
+       return err;
+}
+
 /*
  * GPS
  */
@@ -1062,6 +1279,86 @@ static int asus_rfkill_init(struct asus_laptop *asus)
        return result;
 }
 
+static int pega_rfkill_set(void *data, bool blocked)
+{
+       struct asus_pega_rfkill *pega_rfk = data;
+
+       int ret = asus_pega_lucid_set(pega_rfk->asus, pega_rfk->control_id, !blocked);
+       pr_warn("Setting rfkill %d, to %d; returned %d\n", pega_rfk->control_id, !blocked, ret);
+
+       return ret;
+}
+
+static const struct rfkill_ops pega_rfkill_ops = {
+       .set_block = pega_rfkill_set,
+};
+
+static void pega_rfkill_terminate(struct asus_pega_rfkill *pega_rfk)
+{
+       pr_warn("Terminating %d\n", pega_rfk->control_id);
+       if (pega_rfk->rfkill) {
+               rfkill_unregister(pega_rfk->rfkill);
+               rfkill_destroy(pega_rfk->rfkill);
+               pega_rfk->rfkill = NULL;
+       }
+}
+
+static void pega_rfkill_exit(struct asus_laptop *asus)
+{
+       pega_rfkill_terminate(&asus->wwanrfk);
+       pega_rfkill_terminate(&asus->btrfk);
+       pega_rfkill_terminate(&asus->wlanrfk);
+}
+
+static int pega_rfkill_setup(struct asus_laptop *asus, struct asus_pega_rfkill *pega_rfk,
+               const char *name, int controlid, int rfkill_type)
+{
+       int result;
+
+       pr_warn("Setting up rfk %s, control %d, type %d\n", name, controlid, rfkill_type);
+       pega_rfk->control_id = controlid;
+       pega_rfk->asus = asus;
+       pega_rfk->rfkill = rfkill_alloc(name, &asus->platform_device->dev,
+                                       rfkill_type, &pega_rfkill_ops, pega_rfk);
+       if (!pega_rfk->rfkill)
+               return -EINVAL;
+
+       result = rfkill_register(pega_rfk->rfkill);
+       if (result) {
+               rfkill_destroy(pega_rfk->rfkill);
+               pega_rfk->rfkill = NULL;
+       }
+
+       return result;
+}
+
+static int pega_rfkill_init(struct asus_laptop *asus)
+{
+       int ret = 0;
+
+       if(!asus->is_pega_lucid)
+               return -ENODEV;
+
+       ret = pega_rfkill_setup(asus, &asus->wlanrfk, "pega-wlan", PEGA_WLAN, RFKILL_TYPE_WLAN);
+       if(ret)
+               return ret;
+       ret = pega_rfkill_setup(asus, &asus->btrfk, "pega-bt", PEGA_BLUETOOTH, RFKILL_TYPE_BLUETOOTH);
+       if(ret)
+               goto err_btrfk;
+       ret = pega_rfkill_setup(asus, &asus->wwanrfk, "pega-wwan", PEGA_WWAN, RFKILL_TYPE_WWAN);
+       if(ret)
+               goto err_wwanrfk;
+
+       pr_warn("Pega rfkill init succeeded\n");
+       return 0;
+err_wwanrfk:
+       pega_rfkill_terminate(&asus->btrfk);
+err_btrfk:
+       pega_rfkill_terminate(&asus->wlanrfk);
+
+       return ret;
+}
+
 /*
  * Input device (i.e. hotkeys)
  */
@@ -1141,6 +1438,14 @@ static void asus_acpi_notify(struct acpi_device *device, u32 event)
                }
                return ;
        }
+
+       /* Accelerometer "coarse orientation change" event */
+       if (asus->pega_accel_poll && event == 0xEA) {
+               kobject_uevent(&asus->pega_accel_poll->input->dev.kobj,
+                              KOBJ_CHANGE);
+               return ;
+       }
+
        asus_input_notify(asus, event);
 }
 
@@ -1152,6 +1457,7 @@ static DEVICE_ATTR(wimax, S_IRUGO | S_IWUSR, show_wimax, store_wimax);
 static DEVICE_ATTR(wwan, S_IRUGO | S_IWUSR, show_wwan, store_wwan);
 static DEVICE_ATTR(display, S_IWUSR, NULL, store_disp);
 static DEVICE_ATTR(ledd, S_IRUGO | S_IWUSR, show_ledd, store_ledd);
+static DEVICE_ATTR(ls_value, S_IRUGO, show_lsvalue, NULL);
 static DEVICE_ATTR(ls_level, S_IRUGO | S_IWUSR, show_lslvl, store_lslvl);
 static DEVICE_ATTR(ls_switch, S_IRUGO | S_IWUSR, show_lssw, store_lssw);
 static DEVICE_ATTR(gps, S_IRUGO | S_IWUSR, show_gps, store_gps);
@@ -1164,6 +1470,7 @@ static struct attribute *asus_attributes[] = {
        &dev_attr_wwan.attr,
        &dev_attr_display.attr,
        &dev_attr_ledd.attr,
+       &dev_attr_ls_value.attr,
        &dev_attr_ls_level.attr,
        &dev_attr_ls_switch.attr,
        &dev_attr_gps.attr,
@@ -1180,6 +1487,19 @@ static mode_t asus_sysfs_is_visible(struct kobject *kobj,
        acpi_handle handle = asus->handle;
        bool supported;
 
+       if (asus->is_pega_lucid) {
+               /* no ls_level interface on the Lucid */
+               if (attr == &dev_attr_ls_switch.attr)
+                       supported = true;
+               else if (attr == &dev_attr_ls_level.attr)
+                       supported = false;
+               else
+                       goto normal;
+
+               return supported;
+       }
+
+normal:
        if (attr == &dev_attr_wlan.attr) {
                supported = !acpi_check_handle(handle, METHOD_WLAN, NULL);
 
@@ -1202,8 +1522,9 @@ static mode_t asus_sysfs_is_visible(struct kobject *kobj,
        } else if (attr == &dev_attr_ls_switch.attr ||
                   attr == &dev_attr_ls_level.attr) {
                supported = !acpi_check_handle(handle, METHOD_ALS_CONTROL, NULL) &&
-                           !acpi_check_handle(handle, METHOD_ALS_LEVEL, NULL);
-
+                       !acpi_check_handle(handle, METHOD_ALS_LEVEL, NULL);
+       } else if (attr == &dev_attr_ls_value.attr) {
+               supported = asus->is_pega_lucid;
        } else if (attr == &dev_attr_gps.attr) {
                supported = !acpi_check_handle(handle, METHOD_GPS_ON, NULL) &&
                            !acpi_check_handle(handle, METHOD_GPS_OFF, NULL) &&
@@ -1258,7 +1579,7 @@ static struct platform_driver platform_driver = {
        .driver = {
                .name = ASUS_LAPTOP_FILE,
                .owner = THIS_MODULE,
-       }
+       },
 };
 
 /*
@@ -1388,11 +1709,13 @@ static int __devinit asus_acpi_init(struct asus_laptop *asus)
        asus->ledd_status = 0xFFF;
 
        /* Set initial values of light sensor and level */
-       asus->light_switch = 0; /* Default to light sensor disabled */
+       asus->light_switch = !!als_status;
        asus->light_level = 5;  /* level 5 for sensor sensitivity */
 
-       if (!acpi_check_handle(asus->handle, METHOD_ALS_CONTROL, NULL) &&
-           !acpi_check_handle(asus->handle, METHOD_ALS_LEVEL, NULL)) {
+       if (asus->is_pega_lucid) {
+               asus_als_switch(asus, asus->light_switch);
+       } else if (!acpi_check_handle(asus->handle, METHOD_ALS_CONTROL, NULL) &&
+                  !acpi_check_handle(asus->handle, METHOD_ALS_LEVEL, NULL)) {
                asus_als_switch(asus, asus->light_switch);
                asus_als_level(asus, asus->light_level);
        }
@@ -1439,9 +1762,10 @@ static int __devinit asus_acpi_add(struct acpi_device *device)
                goto fail_platform;
 
        /*
-        * Register the platform device first.  It is used as a parent for the
-        * sub-devices below.
+        * Need platform type detection first, then the platform
+        * device.  It is used as a parent for the sub-devices below.
         */
+       asus->is_pega_lucid = asus_check_pega_lucid(asus);
        result = asus_platform_init(asus);
        if (result)
                goto fail_platform;
@@ -1465,9 +1789,21 @@ static int __devinit asus_acpi_add(struct acpi_device *device)
        if (result)
                goto fail_rfkill;
 
+       result = pega_accel_init(asus);
+       if (result && result != -ENODEV)
+               goto fail_pega_accel;
+
+       result = pega_rfkill_init(asus);
+       if (result && result != -ENODEV)
+               goto fail_pega_rfkill;
+
        asus_device_present = true;
        return 0;
 
+fail_pega_rfkill:
+       pega_accel_exit(asus);
+fail_pega_accel:
+       asus_rfkill_exit(asus);
 fail_rfkill:
        asus_led_exit(asus);
 fail_led:
@@ -1491,6 +1827,8 @@ static int asus_acpi_remove(struct acpi_device *device, int type)
        asus_rfkill_exit(asus);
        asus_led_exit(asus);
        asus_input_exit(asus);
+       pega_accel_exit(asus);
+       pega_rfkill_exit(asus);
        asus_platform_exit(asus);
 
        kfree(asus->name);
index 95cba9ebf6c08ddab129840447367fb0e83aea9e..d1049ee3c9e866590a72d52094378b4cc95ab0fc 100644 (file)
@@ -453,7 +453,9 @@ static enum led_brightness kbd_led_get(struct led_classdev *led_cdev)
 
 static void asus_wmi_led_exit(struct asus_wmi *asus)
 {
-       if (asus->tpd_led.dev)
+       if (!IS_ERR_OR_NULL(asus->kbd_led.dev))
+               led_classdev_unregister(&asus->kbd_led);
+       if (!IS_ERR_OR_NULL(asus->tpd_led.dev))
                led_classdev_unregister(&asus->tpd_led);
        if (asus->led_workqueue)
                destroy_workqueue(asus->led_workqueue);
index f31fa4efa725504bc4a9e6b251686453d0cb7e6d..a43cfd906c6d678759d241a3fae9363889e1c15d 100644 (file)
@@ -60,6 +60,22 @@ struct calling_interface_structure {
        struct calling_interface_token tokens[];
 } __packed;
 
+struct quirk_entry {
+       u8 touchpad_led;
+};
+
+static struct quirk_entry *quirks;
+
+static struct quirk_entry quirk_dell_vostro_v130 = {
+       .touchpad_led = 1,
+};
+
+static int dmi_matched(const struct dmi_system_id *dmi)
+{
+       quirks = dmi->driver_data;
+       return 1;
+}
+
 static int da_command_address;
 static int da_command_code;
 static int da_num_tokens;
@@ -149,6 +165,27 @@ static struct dmi_system_id __devinitdata dell_blacklist[] = {
        {}
 };
 
+static struct dmi_system_id __devinitdata dell_quirks[] = {
+       {
+               .callback = dmi_matched,
+               .ident = "Dell Vostro V130",
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V130"),
+               },
+               .driver_data = &quirk_dell_vostro_v130,
+       },
+       {
+               .callback = dmi_matched,
+               .ident = "Dell Vostro V131",
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V131"),
+               },
+               .driver_data = &quirk_dell_vostro_v130,
+       },
+};
+
 static struct calling_interface_buffer *buffer;
 static struct page *bufferpage;
 static DEFINE_MUTEX(buffer_mutex);
@@ -552,6 +589,44 @@ static const struct backlight_ops dell_ops = {
        .update_status  = dell_send_intensity,
 };
 
+static void touchpad_led_on()
+{
+       int command = 0x97;
+       char data = 1;
+       i8042_command(&data, command | 1 << 12);
+}
+
+static void touchpad_led_off()
+{
+       int command = 0x97;
+       char data = 2;
+       i8042_command(&data, command | 1 << 12);
+}
+
+static void touchpad_led_set(struct led_classdev *led_cdev,
+       enum led_brightness value)
+{
+       if (value > 0)
+               touchpad_led_on();
+       else
+               touchpad_led_off();
+}
+
+static struct led_classdev touchpad_led = {
+       .name = "dell-laptop::touchpad",
+       .brightness_set = touchpad_led_set,
+};
+
+static int __devinit touchpad_led_init(struct device *dev)
+{
+       return led_classdev_register(dev, &touchpad_led);
+}
+
+static void touchpad_led_exit(void)
+{
+       led_classdev_unregister(&touchpad_led);
+}
+
 static bool dell_laptop_i8042_filter(unsigned char data, unsigned char str,
                              struct serio *port)
 {
@@ -584,6 +659,10 @@ static int __init dell_init(void)
        if (!dmi_check_system(dell_device_table))
                return -ENODEV;
 
+       quirks = NULL;
+       /* find if this machine support other functions */
+       dmi_check_system(dell_quirks);
+
        dmi_walk(find_tokens, NULL);
 
        if (!da_tokens)  {
@@ -626,6 +705,9 @@ static int __init dell_init(void)
                goto fail_filter;
        }
 
+       if (quirks && quirks->touchpad_led)
+               touchpad_led_init(&platform_device->dev);
+
        dell_laptop_dir = debugfs_create_dir("dell_laptop", NULL);
        if (dell_laptop_dir != NULL)
                debugfs_create_file("rfkill", 0444, dell_laptop_dir, NULL,
@@ -692,6 +774,8 @@ fail_platform_driver:
 static void __exit dell_exit(void)
 {
        debugfs_remove_recursive(dell_laptop_dir);
+       if (quirks && quirks->touchpad_led)
+               touchpad_led_exit();
        i8042_remove_filter(dell_laptop_i8042_filter);
        cancel_delayed_work_sync(&dell_rfkill_work);
        backlight_device_unregister(dell_backlight_device);
index 1c45d92e21638230728a1f2919b1cc776360c937..ea44abd8df48d7db82c3b8e8a7d7c671cd00b028 100644 (file)
@@ -568,7 +568,7 @@ static int eeepc_led_init(struct eeepc_laptop *eeepc)
 
 static void eeepc_led_exit(struct eeepc_laptop *eeepc)
 {
-       if (eeepc->tpd_led.dev)
+       if (!IS_ERR_OR_NULL(eeepc->tpd_led.dev))
                led_classdev_unregister(&eeepc->tpd_led);
        if (eeepc->led_workqueue)
                destroy_workqueue(eeepc->led_workqueue);
index 1b52d00e2f9069b045e8cfad7f399821d753f935..22b2dfa731480769ffbf18f6e447ee8ac54c5741 100644 (file)
@@ -76,6 +76,7 @@ static inline void delayed_sysfs_set(struct led_classdev *led_cdev,
 /* For automatic insertion of the module */
 static struct acpi_device_id lis3lv02d_device_ids[] = {
        {"HPQ0004", 0}, /* HP Mobile Data Protection System PNP */
+       {"HPQ6000", 0}, /* HP Mobile Data Protection System PNP */
        {"", 0},
 };
 MODULE_DEVICE_TABLE(acpi, lis3lv02d_device_ids);
@@ -209,6 +210,8 @@ static struct dmi_system_id lis3lv02d_dmi_ids[] = {
        AXIS_DMI_MATCH("NC6715x", "HP Compaq 6715", y_inverted),
        AXIS_DMI_MATCH("NC693xx", "HP EliteBook 693", xy_rotated_right),
        AXIS_DMI_MATCH("NC693xx", "HP EliteBook 853", xy_swap),
+       AXIS_DMI_MATCH("NC854xx", "HP EliteBook 854", y_inverted),
+       AXIS_DMI_MATCH("NC273xx", "HP EliteBook 273", y_inverted),
        /* Intel-based HP Pavilion dv5 */
        AXIS_DMI_MATCH2("HPDV5_I",
                        PRODUCT_NAME, "HP Pavilion dv5",
@@ -227,7 +230,12 @@ static struct dmi_system_id lis3lv02d_dmi_ids[] = {
        AXIS_DMI_MATCH("HPB452x", "HP ProBook 452", y_inverted),
        AXIS_DMI_MATCH("HPB522x", "HP ProBook 522", xy_swap),
        AXIS_DMI_MATCH("HPB532x", "HP ProBook 532", y_inverted),
+       AXIS_DMI_MATCH("HPB655x", "HP ProBook 655", xy_swap_inverted),
        AXIS_DMI_MATCH("Mini510x", "HP Mini 510", xy_rotated_left_usd),
+       AXIS_DMI_MATCH("HPB63xx", "HP ProBook 63", xy_swap),
+       AXIS_DMI_MATCH("HPB64xx", "HP ProBook 64", xy_swap),
+       AXIS_DMI_MATCH("HPB64xx", "HP EliteBook 84", xy_swap),
+       AXIS_DMI_MATCH("HPB65xx", "HP ProBook 65", x_inverted),
        { NULL, }
 /* Laptop models without axis info (yet):
  * "NC6910" "HP Compaq 6910"
@@ -320,7 +328,7 @@ static int lis3lv02d_add(struct acpi_device *device)
        INIT_WORK(&hpled_led.work, delayed_set_status_worker);
        ret = led_classdev_register(NULL, &hpled_led.led_classdev);
        if (ret) {
-               lis3lv02d_joystick_disable();
+               lis3lv02d_joystick_disable(&lis3_dev);
                lis3lv02d_poweroff(&lis3_dev);
                flush_work(&hpled_led.work);
                return ret;
@@ -334,7 +342,7 @@ static int lis3lv02d_remove(struct acpi_device *device, int type)
        if (!device)
                return -EINVAL;
 
-       lis3lv02d_joystick_disable();
+       lis3lv02d_joystick_disable(&lis3_dev);
        lis3lv02d_poweroff(&lis3_dev);
 
        led_classdev_unregister(&hpled_led.led_classdev);
@@ -354,8 +362,7 @@ static int lis3lv02d_suspend(struct acpi_device *device, pm_message_t state)
 
 static int lis3lv02d_resume(struct acpi_device *device)
 {
-       lis3lv02d_poweron(&lis3_dev);
-       return 0;
+       return lis3lv02d_poweron(&lis3_dev);
 }
 #else
 #define lis3lv02d_suspend NULL
index 0c595410e78897e8b6b3f4b9e9c84e765ac0ba57..a36addf106a0706b2bcaee89477d05e5e25991a8 100644 (file)
@@ -34,6 +34,8 @@
 #include <linux/input/sparse-keymap.h>
 #include <linux/backlight.h>
 #include <linux/fb.h>
+#include <linux/debugfs.h>
+#include <linux/seq_file.h>
 
 #define IDEAPAD_RFKILL_DEV_NUM (3)
 
 #define CFG_WIFI_BIT   (18)
 #define CFG_CAMERA_BIT (19)
 
+enum {
+       VPCCMD_R_VPC1 = 0x10,
+       VPCCMD_R_BL_MAX,
+       VPCCMD_R_BL,
+       VPCCMD_W_BL,
+       VPCCMD_R_WIFI,
+       VPCCMD_W_WIFI,
+       VPCCMD_R_BT,
+       VPCCMD_W_BT,
+       VPCCMD_R_BL_POWER,
+       VPCCMD_R_NOVO,
+       VPCCMD_R_VPC2,
+       VPCCMD_R_TOUCHPAD,
+       VPCCMD_W_TOUCHPAD,
+       VPCCMD_R_CAMERA,
+       VPCCMD_W_CAMERA,
+       VPCCMD_R_3G,
+       VPCCMD_W_3G,
+       VPCCMD_R_ODD, /* 0x21 */
+       VPCCMD_R_RF = 0x23,
+       VPCCMD_W_RF,
+       VPCCMD_W_BL_POWER = 0x33,
+};
+
 struct ideapad_private {
        struct rfkill *rfk[IDEAPAD_RFKILL_DEV_NUM];
        struct platform_device *platform_device;
        struct input_dev *inputdev;
        struct backlight_device *blightdev;
+       struct dentry *debug;
        unsigned long cfg;
 };
 
 static acpi_handle ideapad_handle;
+static struct ideapad_private *ideapad_priv;
 static bool no_bt_rfkill;
 module_param(no_bt_rfkill, bool, 0444);
 MODULE_PARM_DESC(no_bt_rfkill, "No rfkill for bluetooth.");
@@ -163,6 +191,146 @@ static int write_ec_cmd(acpi_handle handle, int cmd, unsigned long data)
        return -1;
 }
 
+/*
+ * debugfs
+ */
+#define DEBUGFS_EVENT_LEN (4096)
+static int debugfs_status_show(struct seq_file *s, void *data)
+{
+       unsigned long value;
+
+       if (!read_ec_data(ideapad_handle, VPCCMD_R_BL_MAX, &value))
+               seq_printf(s, "Backlight max:\t%lu\n", value);
+       if (!read_ec_data(ideapad_handle, VPCCMD_R_BL, &value))
+               seq_printf(s, "Backlight now:\t%lu\n", value);
+       if (!read_ec_data(ideapad_handle, VPCCMD_R_BL_POWER, &value))
+               seq_printf(s, "BL power value:\t%s\n", value ? "On" : "Off");
+       seq_printf(s, "=====================\n");
+
+       if (!read_ec_data(ideapad_handle, VPCCMD_R_RF, &value))
+               seq_printf(s, "Radio status:\t%s(%lu)\n",
+                          value ? "On" : "Off", value);
+       if (!read_ec_data(ideapad_handle, VPCCMD_R_WIFI, &value))
+               seq_printf(s, "Wifi status:\t%s(%lu)\n",
+                          value ? "On" : "Off", value);
+       if (!read_ec_data(ideapad_handle, VPCCMD_R_BT, &value))
+               seq_printf(s, "BT status:\t%s(%lu)\n",
+                          value ? "On" : "Off", value);
+       if (!read_ec_data(ideapad_handle, VPCCMD_R_3G, &value))
+               seq_printf(s, "3G status:\t%s(%lu)\n",
+                          value ? "On" : "Off", value);
+       seq_printf(s, "=====================\n");
+
+       if (!read_ec_data(ideapad_handle, VPCCMD_R_TOUCHPAD, &value))
+               seq_printf(s, "Touchpad status:%s(%lu)\n",
+                          value ? "On" : "Off", value);
+       if (!read_ec_data(ideapad_handle, VPCCMD_R_CAMERA, &value))
+               seq_printf(s, "Camera status:\t%s(%lu)\n",
+                          value ? "On" : "Off", value);
+
+       return 0;
+}
+
+static int debugfs_status_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, debugfs_status_show, NULL);
+}
+
+static const struct file_operations debugfs_status_fops = {
+       .owner = THIS_MODULE,
+       .open = debugfs_status_open,
+       .read = seq_read,
+       .llseek = seq_lseek,
+       .release = single_release,
+};
+
+static int debugfs_cfg_show(struct seq_file *s, void *data)
+{
+       if (!ideapad_priv) {
+               seq_printf(s, "cfg: N/A\n");
+       } else {
+               seq_printf(s, "cfg: 0x%.8lX\n\nCapability: ",
+                          ideapad_priv->cfg);
+               if (test_bit(CFG_BT_BIT, &ideapad_priv->cfg))
+                       seq_printf(s, "Bluetooth ");
+               if (test_bit(CFG_3G_BIT, &ideapad_priv->cfg))
+                       seq_printf(s, "3G ");
+               if (test_bit(CFG_WIFI_BIT, &ideapad_priv->cfg))
+                       seq_printf(s, "Wireless ");
+               if (test_bit(CFG_CAMERA_BIT, &ideapad_priv->cfg))
+                       seq_printf(s, "Camera ");
+               seq_printf(s, "\nGraphic: ");
+               switch ((ideapad_priv->cfg)&0x700) {
+               case 0x100:
+                       seq_printf(s, "Intel");
+                       break;
+               case 0x200:
+                       seq_printf(s, "ATI");
+                       break;
+               case 0x300:
+                       seq_printf(s, "Nvidia");
+                       break;
+               case 0x400:
+                       seq_printf(s, "Intel and ATI");
+                       break;
+               case 0x500:
+                       seq_printf(s, "Intel and Nvidia");
+                       break;
+               }
+               seq_printf(s, "\n");
+       }
+       return 0;
+}
+
+static int debugfs_cfg_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, debugfs_cfg_show, NULL);
+}
+
+static const struct file_operations debugfs_cfg_fops = {
+       .owner = THIS_MODULE,
+       .open = debugfs_cfg_open,
+       .read = seq_read,
+       .llseek = seq_lseek,
+       .release = single_release,
+};
+
+static int __devinit ideapad_debugfs_init(struct ideapad_private *priv)
+{
+       struct dentry *node;
+
+       priv->debug = debugfs_create_dir("ideapad", NULL);
+       if (priv->debug == NULL) {
+               pr_err("failed to create debugfs directory");
+               goto errout;
+       }
+
+       node = debugfs_create_file("cfg", S_IRUGO, priv->debug, NULL,
+                                  &debugfs_cfg_fops);
+       if (!node) {
+               pr_err("failed to create cfg in debugfs");
+               goto errout;
+       }
+
+       node = debugfs_create_file("status", S_IRUGO, priv->debug, NULL,
+                                  &debugfs_status_fops);
+       if (!node) {
+               pr_err("failed to create event in debugfs");
+               goto errout;
+       }
+
+       return 0;
+
+errout:
+       return -ENOMEM;
+}
+
+static void ideapad_debugfs_exit(struct ideapad_private *priv)
+{
+       debugfs_remove_recursive(priv->debug);
+       priv->debug = NULL;
+}
+
 /*
  * sysfs
  */
@@ -172,7 +340,7 @@ static ssize_t show_ideapad_cam(struct device *dev,
 {
        unsigned long result;
 
-       if (read_ec_data(ideapad_handle, 0x1D, &result))
+       if (read_ec_data(ideapad_handle, VPCCMD_R_CAMERA, &result))
                return sprintf(buf, "-1\n");
        return sprintf(buf, "%lu\n", result);
 }
@@ -187,7 +355,7 @@ static ssize_t store_ideapad_cam(struct device *dev,
                return 0;
        if (sscanf(buf, "%i", &state) != 1)
                return -EINVAL;
-       ret = write_ec_cmd(ideapad_handle, 0x1E, state);
+       ret = write_ec_cmd(ideapad_handle, VPCCMD_W_CAMERA, state);
        if (ret < 0)
                return ret;
        return count;
@@ -195,20 +363,8 @@ static ssize_t store_ideapad_cam(struct device *dev,
 
 static DEVICE_ATTR(camera_power, 0644, show_ideapad_cam, store_ideapad_cam);
 
-static ssize_t show_ideapad_cfg(struct device *dev,
-                               struct device_attribute *attr,
-                               char *buf)
-{
-       struct ideapad_private *priv = dev_get_drvdata(dev);
-
-       return sprintf(buf, "0x%.8lX\n", priv->cfg);
-}
-
-static DEVICE_ATTR(cfg, 0444, show_ideapad_cfg, NULL);
-
 static struct attribute *ideapad_attributes[] = {
        &dev_attr_camera_power.attr,
-       &dev_attr_cfg.attr,
        NULL
 };
 
@@ -244,9 +400,9 @@ struct ideapad_rfk_data {
 };
 
 const struct ideapad_rfk_data ideapad_rfk_data[] = {
-       { "ideapad_wlan",      CFG_WIFI_BIT, 0x15, RFKILL_TYPE_WLAN },
-       { "ideapad_bluetooth", CFG_BT_BIT,   0x17, RFKILL_TYPE_BLUETOOTH },
-       { "ideapad_3g",        CFG_3G_BIT,   0x20, RFKILL_TYPE_WWAN },
+       { "ideapad_wlan",    CFG_WIFI_BIT, VPCCMD_W_WIFI, RFKILL_TYPE_WLAN },
+       { "ideapad_bluetooth", CFG_BT_BIT, VPCCMD_W_BT, RFKILL_TYPE_BLUETOOTH },
+       { "ideapad_3g",        CFG_3G_BIT, VPCCMD_W_3G, RFKILL_TYPE_WWAN },
 };
 
 static int ideapad_rfk_set(void *data, bool blocked)
@@ -260,13 +416,12 @@ static struct rfkill_ops ideapad_rfk_ops = {
        .set_block = ideapad_rfk_set,
 };
 
-static void ideapad_sync_rfk_state(struct acpi_device *adevice)
+static void ideapad_sync_rfk_state(struct ideapad_private *priv)
 {
-       struct ideapad_private *priv = dev_get_drvdata(&adevice->dev);
        unsigned long hw_blocked;
        int i;
 
-       if (read_ec_data(ideapad_handle, 0x23, &hw_blocked))
+       if (read_ec_data(ideapad_handle, VPCCMD_R_RF, &hw_blocked))
                return;
        hw_blocked = !hw_blocked;
 
@@ -363,8 +518,10 @@ static void ideapad_platform_exit(struct ideapad_private *priv)
  * input device
  */
 static const struct key_entry ideapad_keymap[] = {
-       { KE_KEY, 0x06, { KEY_SWITCHVIDEOMODE } },
-       { KE_KEY, 0x0D, { KEY_WLAN } },
+       { KE_KEY, 6,  { KEY_SWITCHVIDEOMODE } },
+       { KE_KEY, 13, { KEY_WLAN } },
+       { KE_KEY, 16, { KEY_PROG1 } },
+       { KE_KEY, 17, { KEY_PROG2 } },
        { KE_END, 0 },
 };
 
@@ -419,6 +576,18 @@ static void ideapad_input_report(struct ideapad_private *priv,
        sparse_keymap_report_event(priv->inputdev, scancode, 1, true);
 }
 
+static void ideapad_input_novokey(struct ideapad_private *priv)
+{
+       unsigned long long_pressed;
+
+       if (read_ec_data(ideapad_handle, VPCCMD_R_NOVO, &long_pressed))
+               return;
+       if (long_pressed)
+               ideapad_input_report(priv, 17);
+       else
+               ideapad_input_report(priv, 16);
+}
+
 /*
  * backlight
  */
@@ -426,16 +595,17 @@ static int ideapad_backlight_get_brightness(struct backlight_device *blightdev)
 {
        unsigned long now;
 
-       if (read_ec_data(ideapad_handle, 0x12, &now))
+       if (read_ec_data(ideapad_handle, VPCCMD_R_BL, &now))
                return -EIO;
        return now;
 }
 
 static int ideapad_backlight_update_status(struct backlight_device *blightdev)
 {
-       if (write_ec_cmd(ideapad_handle, 0x13, blightdev->props.brightness))
+       if (write_ec_cmd(ideapad_handle, VPCCMD_W_BL,
+                        blightdev->props.brightness))
                return -EIO;
-       if (write_ec_cmd(ideapad_handle, 0x33,
+       if (write_ec_cmd(ideapad_handle, VPCCMD_W_BL_POWER,
                         blightdev->props.power == FB_BLANK_POWERDOWN ? 0 : 1))
                return -EIO;
 
@@ -453,11 +623,11 @@ static int ideapad_backlight_init(struct ideapad_private *priv)
        struct backlight_properties props;
        unsigned long max, now, power;
 
-       if (read_ec_data(ideapad_handle, 0x11, &max))
+       if (read_ec_data(ideapad_handle, VPCCMD_R_BL_MAX, &max))
                return -EIO;
-       if (read_ec_data(ideapad_handle, 0x12, &now))
+       if (read_ec_data(ideapad_handle, VPCCMD_R_BL, &now))
                return -EIO;
-       if (read_ec_data(ideapad_handle, 0x18, &power))
+       if (read_ec_data(ideapad_handle, VPCCMD_R_BL_POWER, &power))
                return -EIO;
 
        memset(&props, 0, sizeof(struct backlight_properties));
@@ -493,7 +663,9 @@ static void ideapad_backlight_notify_power(struct ideapad_private *priv)
        unsigned long power;
        struct backlight_device *blightdev = priv->blightdev;
 
-       if (read_ec_data(ideapad_handle, 0x18, &power))
+       if (!blightdev)
+               return;
+       if (read_ec_data(ideapad_handle, VPCCMD_R_BL_POWER, &power))
                return;
        blightdev->props.power = power ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
 }
@@ -504,7 +676,7 @@ static void ideapad_backlight_notify_brightness(struct ideapad_private *priv)
 
        /* if we control brightness via acpi video driver */
        if (priv->blightdev == NULL) {
-               read_ec_data(ideapad_handle, 0x12, &now);
+               read_ec_data(ideapad_handle, VPCCMD_R_BL, &now);
                return;
        }
 
@@ -533,6 +705,7 @@ static int __devinit ideapad_acpi_add(struct acpi_device *adevice)
        if (!priv)
                return -ENOMEM;
        dev_set_drvdata(&adevice->dev, priv);
+       ideapad_priv = priv;
        ideapad_handle = adevice->handle;
        priv->cfg = cfg;
 
@@ -540,6 +713,10 @@ static int __devinit ideapad_acpi_add(struct acpi_device *adevice)
        if (ret)
                goto platform_failed;
 
+       ret = ideapad_debugfs_init(priv);
+       if (ret)
+               goto debugfs_failed;
+
        ret = ideapad_input_init(priv);
        if (ret)
                goto input_failed;
@@ -550,7 +727,7 @@ static int __devinit ideapad_acpi_add(struct acpi_device *adevice)
                else
                        priv->rfk[i] = NULL;
        }
-       ideapad_sync_rfk_state(adevice);
+       ideapad_sync_rfk_state(priv);
 
        if (!acpi_video_backlight_support()) {
                ret = ideapad_backlight_init(priv);
@@ -565,6 +742,8 @@ backlight_failed:
                ideapad_unregister_rfkill(adevice, i);
        ideapad_input_exit(priv);
 input_failed:
+       ideapad_debugfs_exit(priv);
+debugfs_failed:
        ideapad_platform_exit(priv);
 platform_failed:
        kfree(priv);
@@ -580,6 +759,7 @@ static int __devexit ideapad_acpi_remove(struct acpi_device *adevice, int type)
        for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
                ideapad_unregister_rfkill(adevice, i);
        ideapad_input_exit(priv);
+       ideapad_debugfs_exit(priv);
        ideapad_platform_exit(priv);
        dev_set_drvdata(&adevice->dev, NULL);
        kfree(priv);
@@ -593,9 +773,9 @@ static void ideapad_acpi_notify(struct acpi_device *adevice, u32 event)
        acpi_handle handle = adevice->handle;
        unsigned long vpc1, vpc2, vpc_bit;
 
-       if (read_ec_data(handle, 0x10, &vpc1))
+       if (read_ec_data(handle, VPCCMD_R_VPC1, &vpc1))
                return;
-       if (read_ec_data(handle, 0x1A, &vpc2))
+       if (read_ec_data(handle, VPCCMD_R_VPC2, &vpc2))
                return;
 
        vpc1 = (vpc2 << 8) | vpc1;
@@ -603,11 +783,14 @@ static void ideapad_acpi_notify(struct acpi_device *adevice, u32 event)
                if (test_bit(vpc_bit, &vpc1)) {
                        switch (vpc_bit) {
                        case 9:
-                               ideapad_sync_rfk_state(adevice);
+                               ideapad_sync_rfk_state(priv);
                                break;
                        case 4:
                                ideapad_backlight_notify_brightness(priv);
                                break;
+                       case 3:
+                               ideapad_input_novokey(priv);
+                               break;
                        case 2:
                                ideapad_backlight_notify_power(priv);
                                break;
index b93a03259c16909b2e7a811a0aea1a4278239aa8..2d0f9136ea9a8bd8ba0160cddacd60a3e0f5d7a2 100644 (file)
@@ -24,7 +24,7 @@
 #include <linux/init.h>
 #include <asm/intel_scu_ipc.h>
 
-static u32 major;
+static int major;
 
 #define MAX_FW_SIZE 264192
 
@@ -117,7 +117,11 @@ static const struct file_operations scu_ipc_fops = {
 
 static int __init ipc_module_init(void)
 {
-       return register_chrdev(0, "intel_mid_scu", &scu_ipc_fops);
+       major = register_chrdev(0, "intel_mid_scu", &scu_ipc_fops);
+       if (major < 0)
+               return major;
+
+       return 0;
 }
 
 static void __exit ipc_module_exit(void)
index 359163011044d4fced62b95164a7d8baee399cc1..09e26bfd464343766a3bfcff39d4b6e0a306f179 100644 (file)
@@ -226,6 +226,7 @@ static struct backlight_device *backlight_device;
 static struct mutex sabi_mutex;
 static struct platform_device *sdev;
 static struct rfkill *rfk;
+static bool has_stepping_quirk;
 
 static int force;
 module_param(force, bool, 0);
@@ -370,15 +371,28 @@ static u8 read_brightness(void)
                                  &sretval);
        if (!retval) {
                user_brightness = sretval.retval[0];
-               if (user_brightness != 0)
+               if (user_brightness > sabi_config->min_brightness)
                        user_brightness -= sabi_config->min_brightness;
+               else
+                       user_brightness = 0;
        }
        return user_brightness;
 }
 
 static void set_brightness(u8 user_brightness)
 {
-       u8 user_level = user_brightness - sabi_config->min_brightness;
+       u8 user_level = user_brightness + sabi_config->min_brightness;
+
+       if (has_stepping_quirk && user_level != 0) {
+               /*
+                * short circuit if the specified level is what's already set
+                * to prevent the screen from flickering needlessly
+                */
+               if (user_brightness == read_brightness())
+                       return;
+
+               sabi_set_command(sabi_config->commands.set_brightness, 0);
+       }
 
        sabi_set_command(sabi_config->commands.set_brightness, user_level);
 }
@@ -388,6 +402,40 @@ static int get_brightness(struct backlight_device *bd)
        return (int)read_brightness();
 }
 
+static void check_for_stepping_quirk(void)
+{
+       u8 initial_level;
+       u8 check_level;
+       u8 orig_level = read_brightness();
+
+       /*
+        * Some laptops exhibit the strange behaviour of stepping toward
+        * (rather than setting) the brightness except when changing to/from
+        * brightness level 0. This behaviour is checked for here and worked
+        * around in set_brightness.
+        */
+
+       if (orig_level == 0)
+               set_brightness(1);
+
+       initial_level = read_brightness();
+
+       if (initial_level <= 2)
+               check_level = initial_level + 2;
+       else
+               check_level = initial_level - 2;
+
+       has_stepping_quirk = false;
+       set_brightness(check_level);
+
+       if (read_brightness() != check_level) {
+               has_stepping_quirk = true;
+               pr_info("enabled workaround for brightness stepping quirk\n");
+       }
+
+       set_brightness(orig_level);
+}
+
 static int update_status(struct backlight_device *bd)
 {
        set_brightness(bd->props.brightness);
@@ -620,6 +668,16 @@ static struct dmi_system_id __initdata samsung_dmi_table[] = {
                },
                .callback = dmi_check_cb,
        },
+       {
+               .ident = "N220",
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR,
+                                       "SAMSUNG ELECTRONICS CO., LTD."),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "N220"),
+                       DMI_MATCH(DMI_BOARD_NAME, "N220"),
+               },
+               .callback = dmi_check_cb,
+       },
        {
                .ident = "N150/N210/N220/N230",
                .matches = {
@@ -640,6 +698,15 @@ static struct dmi_system_id __initdata samsung_dmi_table[] = {
                },
                .callback = dmi_check_cb,
        },
+       {
+               .ident = "R700",
+               .matches = {
+                     DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
+                     DMI_MATCH(DMI_PRODUCT_NAME, "SR700"),
+                     DMI_MATCH(DMI_BOARD_NAME, "SR700"),
+               },
+               .callback = dmi_check_cb,
+       },
        {
                .ident = "R530/R730",
                .matches = {
@@ -686,6 +753,33 @@ static struct dmi_system_id __initdata samsung_dmi_table[] = {
                },
                .callback = dmi_check_cb,
        },
+       {
+               .ident = "R528/R728",
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "R528/R728"),
+                       DMI_MATCH(DMI_BOARD_NAME, "R528/R728"),
+               },
+               .callback = dmi_check_cb,
+       },
+       {
+               .ident = "NC210/NC110",
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "NC210/NC110"),
+                       DMI_MATCH(DMI_BOARD_NAME, "NC210/NC110"),
+               },
+               .callback = dmi_check_cb,
+       },
+               {
+               .ident = "X520",
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "X520"),
+                       DMI_MATCH(DMI_BOARD_NAME, "X520"),
+               },
+               .callback = dmi_check_cb,
+       },
        { },
 };
 MODULE_DEVICE_TABLE(dmi, samsung_dmi_table);
@@ -770,7 +864,7 @@ static int __init samsung_init(void)
        sabi_iface = ioremap_nocache(ifaceP, 16);
        if (!sabi_iface) {
                pr_err("Can't remap %x\n", ifaceP);
-               goto exit;
+               goto error_no_signature;
        }
        if (debug) {
                printk(KERN_DEBUG "ifaceP = 0x%08x\n", ifaceP);
@@ -794,6 +888,9 @@ static int __init samsung_init(void)
                }
        }
 
+       /* Check for stepping quirk */
+       check_for_stepping_quirk();
+
        /* knock up a platform device to hang stuff off of */
        sdev = platform_device_register_simple("samsung", -1, NULL, 0);
        if (IS_ERR(sdev))
@@ -802,7 +899,8 @@ static int __init samsung_init(void)
        /* create a backlight device to talk to this one */
        memset(&props, 0, sizeof(struct backlight_properties));
        props.type = BACKLIGHT_PLATFORM;
-       props.max_brightness = sabi_config->max_brightness;
+       props.max_brightness = sabi_config->max_brightness -
+                               sabi_config->min_brightness;
        backlight_device = backlight_device_register("samsung", &sdev->dev,
                                                     NULL, &backlight_ops,
                                                     &props);
@@ -821,7 +919,6 @@ static int __init samsung_init(void)
        if (retval)
                goto error_file_create;
 
-exit:
        return 0;
 
 error_file_create:
index bbd182e178cb65682b7ed47684467184da4c9a03..c006dee5ebfe84bb33a962dbdddf4ff9440c74be 100644 (file)
@@ -3281,7 +3281,7 @@ static int sony_pic_add(struct acpi_device *device)
        /* request IRQ */
        list_for_each_entry_reverse(irq, &spic_dev.interrupts, list) {
                if (!request_irq(irq->irq.interrupts[0], sony_pic_irq,
-                                       IRQF_DISABLED, "sony-laptop", &spic_dev)) {
+                                       0, "sony-laptop", &spic_dev)) {
                        dprintk("IRQ: %d - triggering: %d - "
                                        "polarity: %d - shr: %d\n",
                                        irq->irq.interrupts[0],
index 4c20447ddbb73cfc572e7668f2fd6da431f34275..d528daa0e81c0eec51b23c962c2e7eb5ce0047d2 100644 (file)
@@ -41,6 +41,7 @@ static const struct key_entry topstar_keymap[] = {
        { KE_KEY, 0x8c, { KEY_MEDIA } },
 
        /* Known non hotkey events don't handled or that we don't care yet */
+       { KE_IGNORE, 0x82, }, /* backlight event */
        { KE_IGNORE, 0x8e, },
        { KE_IGNORE, 0x8f, },
        { KE_IGNORE, 0x90, },
index cb009b2629eef532c444bf71ce1372106cfd9327..13ef8c37471d0a6575fed59d6cf92dece74c34ba 100644 (file)
@@ -47,7 +47,6 @@
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
 #include <linux/backlight.h>
-#include <linux/platform_device.h>
 #include <linux/rfkill.h>
 #include <linux/input.h>
 #include <linux/input/sparse-keymap.h>
@@ -63,11 +62,7 @@ MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
 MODULE_LICENSE("GPL");
 
 /* Toshiba ACPI method paths */
-#define METHOD_LCD_BRIGHTNESS  "\\_SB_.PCI0.VGA_.LCD_._BCM"
-#define TOSH_INTERFACE_1       "\\_SB_.VALD"
-#define TOSH_INTERFACE_2       "\\_SB_.VALZ"
 #define METHOD_VIDEO_OUT       "\\_SB_.VALX.DSSX"
-#define GHCI_METHOD            ".GHCI"
 
 /* Toshiba HCI interface definitions
  *
@@ -111,6 +106,25 @@ MODULE_LICENSE("GPL");
 #define HCI_WIRELESS_BT_ATTACH         0x40
 #define HCI_WIRELESS_BT_POWER          0x80
 
+struct toshiba_acpi_dev {
+       struct acpi_device *acpi_dev;
+       const char *method_hci;
+       struct rfkill *bt_rfk;
+       struct input_dev *hotkey_dev;
+       struct backlight_device *backlight_dev;
+       struct led_classdev led_dev;
+
+       int force_fan;
+       int last_key_event;
+       int key_event_valid;
+
+       int illumination_supported:1;
+       int video_supported:1;
+       int fan_supported:1;
+
+       struct mutex mutex;
+};
+
 static const struct acpi_device_id toshiba_device_ids[] = {
        {"TOS6200", 0},
        {"TOS6208", 0},
@@ -119,7 +133,7 @@ static const struct acpi_device_id toshiba_device_ids[] = {
 };
 MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
 
-static const struct key_entry toshiba_acpi_keymap[] __initconst = {
+static const struct key_entry toshiba_acpi_keymap[] __devinitconst = {
        { KE_KEY, 0x101, { KEY_MUTE } },
        { KE_KEY, 0x102, { KEY_ZOOMOUT } },
        { KE_KEY, 0x103, { KEY_ZOOMIN } },
@@ -155,15 +169,6 @@ static __inline__ void _set_bit(u32 * word, u32 mask, int value)
 /* acpi interface wrappers
  */
 
-static int is_valid_acpi_path(const char *methodName)
-{
-       acpi_handle handle;
-       acpi_status status;
-
-       status = acpi_get_handle(NULL, (char *)methodName, &handle);
-       return !ACPI_FAILURE(status);
-}
-
 static int write_acpi_int(const char *methodName, int val)
 {
        struct acpi_object_list params;
@@ -176,32 +181,14 @@ static int write_acpi_int(const char *methodName, int val)
        in_objs[0].integer.value = val;
 
        status = acpi_evaluate_object(NULL, (char *)methodName, &params, NULL);
-       return (status == AE_OK);
-}
-
-#if 0
-static int read_acpi_int(const char *methodName, int *pVal)
-{
-       struct acpi_buffer results;
-       union acpi_object out_objs[1];
-       acpi_status status;
-
-       results.length = sizeof(out_objs);
-       results.pointer = out_objs;
-
-       status = acpi_evaluate_object(0, (char *)methodName, 0, &results);
-       *pVal = out_objs[0].integer.value;
-
-       return (status == AE_OK) && (out_objs[0].type == ACPI_TYPE_INTEGER);
+       return (status == AE_OK) ? 0 : -EIO;
 }
-#endif
-
-static const char *method_hci /*= 0*/ ;
 
 /* Perform a raw HCI call.  Here we don't care about input or output buffer
  * format.
  */
-static acpi_status hci_raw(const u32 in[HCI_WORDS], u32 out[HCI_WORDS])
+static acpi_status hci_raw(struct toshiba_acpi_dev *dev,
+                          const u32 in[HCI_WORDS], u32 out[HCI_WORDS])
 {
        struct acpi_object_list params;
        union acpi_object in_objs[HCI_WORDS];
@@ -220,7 +207,8 @@ static acpi_status hci_raw(const u32 in[HCI_WORDS], u32 out[HCI_WORDS])
        results.length = sizeof(out_objs);
        results.pointer = out_objs;
 
-       status = acpi_evaluate_object(NULL, (char *)method_hci, &params,
+       status = acpi_evaluate_object(dev->acpi_dev->handle,
+                                     (char *)dev->method_hci, &params,
                                      &results);
        if ((status == AE_OK) && (out_objs->package.count <= HCI_WORDS)) {
                for (i = 0; i < out_objs->package.count; ++i) {
@@ -237,85 +225,79 @@ static acpi_status hci_raw(const u32 in[HCI_WORDS], u32 out[HCI_WORDS])
  * may be useful (such as "not supported").
  */
 
-static acpi_status hci_write1(u32 reg, u32 in1, u32 * result)
+static acpi_status hci_write1(struct toshiba_acpi_dev *dev, u32 reg,
+                             u32 in1, u32 *result)
 {
        u32 in[HCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
        u32 out[HCI_WORDS];
-       acpi_status status = hci_raw(in, out);
+       acpi_status status = hci_raw(dev, in, out);
        *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
        return status;
 }
 
-static acpi_status hci_read1(u32 reg, u32 * out1, u32 * result)
+static acpi_status hci_read1(struct toshiba_acpi_dev *dev, u32 reg,
+                            u32 *out1, u32 *result)
 {
        u32 in[HCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
        u32 out[HCI_WORDS];
-       acpi_status status = hci_raw(in, out);
+       acpi_status status = hci_raw(dev, in, out);
        *out1 = out[2];
        *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
        return status;
 }
 
-static acpi_status hci_write2(u32 reg, u32 in1, u32 in2, u32 *result)
+static acpi_status hci_write2(struct toshiba_acpi_dev *dev, u32 reg,
+                             u32 in1, u32 in2, u32 *result)
 {
        u32 in[HCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 };
        u32 out[HCI_WORDS];
-       acpi_status status = hci_raw(in, out);
+       acpi_status status = hci_raw(dev, in, out);
        *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
        return status;
 }
 
-static acpi_status hci_read2(u32 reg, u32 *out1, u32 *out2, u32 *result)
+static acpi_status hci_read2(struct toshiba_acpi_dev *dev, u32 reg,
+                            u32 *out1, u32 *out2, u32 *result)
 {
        u32 in[HCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 };
        u32 out[HCI_WORDS];
-       acpi_status status = hci_raw(in, out);
+       acpi_status status = hci_raw(dev, in, out);
        *out1 = out[2];
        *out2 = out[3];
        *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
        return status;
 }
 
-struct toshiba_acpi_dev {
-       struct platform_device *p_dev;
-       struct rfkill *bt_rfk;
-       struct input_dev *hotkey_dev;
-       int illumination_installed;
-       acpi_handle handle;
-
-       const char *bt_name;
-
-       struct mutex mutex;
-};
-
 /* Illumination support */
-static int toshiba_illumination_available(void)
+static int toshiba_illumination_available(struct toshiba_acpi_dev *dev)
 {
        u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 };
        u32 out[HCI_WORDS];
        acpi_status status;
 
        in[0] = 0xf100;
-       status = hci_raw(in, out);
+       status = hci_raw(dev, in, out);
        if (ACPI_FAILURE(status)) {
                pr_info("Illumination device not available\n");
                return 0;
        }
        in[0] = 0xf400;
-       status = hci_raw(in, out);
+       status = hci_raw(dev, in, out);
        return 1;
 }
 
 static void toshiba_illumination_set(struct led_classdev *cdev,
                                     enum led_brightness brightness)
 {
+       struct toshiba_acpi_dev *dev = container_of(cdev,
+                       struct toshiba_acpi_dev, led_dev);
        u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 };
        u32 out[HCI_WORDS];
        acpi_status status;
 
        /* First request : initialize communication. */
        in[0] = 0xf100;
-       status = hci_raw(in, out);
+       status = hci_raw(dev, in, out);
        if (ACPI_FAILURE(status)) {
                pr_info("Illumination device not available\n");
                return;
@@ -326,7 +308,7 @@ static void toshiba_illumination_set(struct led_classdev *cdev,
                in[0] = 0xf400;
                in[1] = 0x14e;
                in[2] = 1;
-               status = hci_raw(in, out);
+               status = hci_raw(dev, in, out);
                if (ACPI_FAILURE(status)) {
                        pr_info("ACPI call for illumination failed\n");
                        return;
@@ -336,7 +318,7 @@ static void toshiba_illumination_set(struct led_classdev *cdev,
                in[0] = 0xf400;
                in[1] = 0x14e;
                in[2] = 0;
-               status = hci_raw(in, out);
+               status = hci_raw(dev, in, out);
                if (ACPI_FAILURE(status)) {
                        pr_info("ACPI call for illumination failed.\n");
                        return;
@@ -347,11 +329,13 @@ static void toshiba_illumination_set(struct led_classdev *cdev,
        in[0] = 0xf200;
        in[1] = 0;
        in[2] = 0;
-       hci_raw(in, out);
+       hci_raw(dev, in, out);
 }
 
 static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
 {
+       struct toshiba_acpi_dev *dev = container_of(cdev,
+                       struct toshiba_acpi_dev, led_dev);
        u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 };
        u32 out[HCI_WORDS];
        acpi_status status;
@@ -359,7 +343,7 @@ static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
 
        /* First request : initialize communication. */
        in[0] = 0xf100;
-       status = hci_raw(in, out);
+       status = hci_raw(dev, in, out);
        if (ACPI_FAILURE(status)) {
                pr_info("Illumination device not available\n");
                return LED_OFF;
@@ -368,7 +352,7 @@ static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
        /* Check the illumination */
        in[0] = 0xf300;
        in[1] = 0x14e;
-       status = hci_raw(in, out);
+       status = hci_raw(dev, in, out);
        if (ACPI_FAILURE(status)) {
                pr_info("ACPI call for illumination failed.\n");
                return LED_OFF;
@@ -380,46 +364,35 @@ static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
        in[0] = 0xf200;
        in[1] = 0;
        in[2] = 0;
-       hci_raw(in, out);
+       hci_raw(dev, in, out);
 
        return result;
 }
 
-static struct led_classdev toshiba_led = {
-       .name           = "toshiba::illumination",
-       .max_brightness = 1,
-       .brightness_set = toshiba_illumination_set,
-       .brightness_get = toshiba_illumination_get,
-};
-
-static struct toshiba_acpi_dev toshiba_acpi = {
-       .bt_name = "Toshiba Bluetooth",
-};
-
 /* Bluetooth rfkill handlers */
 
-static u32 hci_get_bt_present(bool *present)
+static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present)
 {
        u32 hci_result;
        u32 value, value2;
 
        value = 0;
        value2 = 0;
-       hci_read2(HCI_WIRELESS, &value, &value2, &hci_result);
+       hci_read2(dev, HCI_WIRELESS, &value, &value2, &hci_result);
        if (hci_result == HCI_SUCCESS)
                *present = (value & HCI_WIRELESS_BT_PRESENT) ? true : false;
 
        return hci_result;
 }
 
-static u32 hci_get_radio_state(bool *radio_state)
+static u32 hci_get_radio_state(struct toshiba_acpi_dev *dev, bool *radio_state)
 {
        u32 hci_result;
        u32 value, value2;
 
        value = 0;
        value2 = 0x0001;
-       hci_read2(HCI_WIRELESS, &value, &value2, &hci_result);
+       hci_read2(dev, HCI_WIRELESS, &value, &value2, &hci_result);
 
        *radio_state = value & HCI_WIRELESS_KILL_SWITCH;
        return hci_result;
@@ -436,8 +409,8 @@ static int bt_rfkill_set_block(void *data, bool blocked)
        value = (blocked == false);
 
        mutex_lock(&dev->mutex);
-       if (hci_get_radio_state(&radio_state) != HCI_SUCCESS) {
-               err = -EBUSY;
+       if (hci_get_radio_state(dev, &radio_state) != HCI_SUCCESS) {
+               err = -EIO;
                goto out;
        }
 
@@ -446,11 +419,11 @@ static int bt_rfkill_set_block(void *data, bool blocked)
                goto out;
        }
 
-       hci_write2(HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER, &result1);
-       hci_write2(HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH, &result2);
+       hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER, &result1);
+       hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH, &result2);
 
        if (result1 != HCI_SUCCESS || result2 != HCI_SUCCESS)
-               err = -EBUSY;
+               err = -EIO;
        else
                err = 0;
  out:
@@ -467,7 +440,7 @@ static void bt_rfkill_poll(struct rfkill *rfkill, void *data)
 
        mutex_lock(&dev->mutex);
 
-       hci_result = hci_get_radio_state(&value);
+       hci_result = hci_get_radio_state(dev, &value);
        if (hci_result != HCI_SUCCESS) {
                /* Can't do anything useful */
                mutex_unlock(&dev->mutex);
@@ -488,63 +461,64 @@ static const struct rfkill_ops toshiba_rfk_ops = {
 };
 
 static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ;
-static struct backlight_device *toshiba_backlight_device;
-static int force_fan;
-static int last_key_event;
-static int key_event_valid;
 
 static int get_lcd(struct backlight_device *bd)
 {
+       struct toshiba_acpi_dev *dev = bl_get_data(bd);
        u32 hci_result;
        u32 value;
 
-       hci_read1(HCI_LCD_BRIGHTNESS, &value, &hci_result);
-       if (hci_result == HCI_SUCCESS) {
+       hci_read1(dev, HCI_LCD_BRIGHTNESS, &value, &hci_result);
+       if (hci_result == HCI_SUCCESS)
                return (value >> HCI_LCD_BRIGHTNESS_SHIFT);
-       } else
-               return -EFAULT;
+
+       return -EIO;
 }
 
 static int lcd_proc_show(struct seq_file *m, void *v)
 {
-       int value = get_lcd(NULL);
+       struct toshiba_acpi_dev *dev = m->private;
+       int value;
+
+       if (!dev->backlight_dev)
+               return -ENODEV;
 
+       value = get_lcd(dev->backlight_dev);
        if (value >= 0) {
                seq_printf(m, "brightness:              %d\n", value);
                seq_printf(m, "brightness_levels:       %d\n",
                             HCI_LCD_BRIGHTNESS_LEVELS);
-       } else {
-               pr_err("Error reading LCD brightness\n");
+               return 0;
        }
 
-       return 0;
+       pr_err("Error reading LCD brightness\n");
+       return -EIO;
 }
 
 static int lcd_proc_open(struct inode *inode, struct file *file)
 {
-       return single_open(file, lcd_proc_show, NULL);
+       return single_open(file, lcd_proc_show, PDE(inode)->data);
 }
 
-static int set_lcd(int value)
+static int set_lcd(struct toshiba_acpi_dev *dev, int value)
 {
        u32 hci_result;
 
        value = value << HCI_LCD_BRIGHTNESS_SHIFT;
-       hci_write1(HCI_LCD_BRIGHTNESS, value, &hci_result);
-       if (hci_result != HCI_SUCCESS)
-               return -EFAULT;
-
-       return 0;
+       hci_write1(dev, HCI_LCD_BRIGHTNESS, value, &hci_result);
+       return hci_result == HCI_SUCCESS ? 0 : -EIO;
 }
 
 static int set_lcd_status(struct backlight_device *bd)
 {
-       return set_lcd(bd->props.brightness);
+       struct toshiba_acpi_dev *dev = bl_get_data(bd);
+       return set_lcd(dev, bd->props.brightness);
 }
 
 static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
                              size_t count, loff_t *pos)
 {
+       struct toshiba_acpi_dev *dev = PDE(file->f_path.dentry->d_inode)->data;
        char cmd[42];
        size_t len;
        int value;
@@ -557,7 +531,7 @@ static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
 
        if (sscanf(cmd, " brightness : %i", &value) == 1 &&
            value >= 0 && value < HCI_LCD_BRIGHTNESS_LEVELS) {
-               ret = set_lcd(value);
+               ret = set_lcd(dev, value);
                if (ret == 0)
                        ret = count;
        } else {
@@ -575,41 +549,49 @@ static const struct file_operations lcd_proc_fops = {
        .write          = lcd_proc_write,
 };
 
-static int video_proc_show(struct seq_file *m, void *v)
+static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status)
 {
        u32 hci_result;
+
+       hci_read1(dev, HCI_VIDEO_OUT, status, &hci_result);
+       return hci_result == HCI_SUCCESS ? 0 : -EIO;
+}
+
+static int video_proc_show(struct seq_file *m, void *v)
+{
+       struct toshiba_acpi_dev *dev = m->private;
        u32 value;
+       int ret;
 
-       hci_read1(HCI_VIDEO_OUT, &value, &hci_result);
-       if (hci_result == HCI_SUCCESS) {
+       ret = get_video_status(dev, &value);
+       if (!ret) {
                int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
                int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
                int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
                seq_printf(m, "lcd_out:                 %d\n", is_lcd);
                seq_printf(m, "crt_out:                 %d\n", is_crt);
                seq_printf(m, "tv_out:                  %d\n", is_tv);
-       } else {
-               pr_err("Error reading video out status\n");
        }
 
-       return 0;
+       return ret;
 }
 
 static int video_proc_open(struct inode *inode, struct file *file)
 {
-       return single_open(file, video_proc_show, NULL);
+       return single_open(file, video_proc_show, PDE(inode)->data);
 }
 
 static ssize_t video_proc_write(struct file *file, const char __user *buf,
                                size_t count, loff_t *pos)
 {
+       struct toshiba_acpi_dev *dev = PDE(file->f_path.dentry->d_inode)->data;
        char *cmd, *buffer;
+       int ret;
        int value;
        int remain = count;
        int lcd_out = -1;
        int crt_out = -1;
        int tv_out = -1;
-       u32 hci_result;
        u32 video_out;
 
        cmd = kmalloc(count + 1, GFP_KERNEL);
@@ -644,8 +626,8 @@ static ssize_t video_proc_write(struct file *file, const char __user *buf,
 
        kfree(cmd);
 
-       hci_read1(HCI_VIDEO_OUT, &video_out, &hci_result);
-       if (hci_result == HCI_SUCCESS) {
+       ret = get_video_status(dev, &video_out);
+       if (!ret) {
                unsigned int new_video_out = video_out;
                if (lcd_out != -1)
                        _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
@@ -656,12 +638,10 @@ static ssize_t video_proc_write(struct file *file, const char __user *buf,
                /* To avoid unnecessary video disruption, only write the new
                 * video setting if something changed. */
                if (new_video_out != video_out)
-                       write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
-       } else {
-               return -EFAULT;
+                       ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
        }
 
-       return count;
+       return ret ? ret : count;
 }
 
 static const struct file_operations video_proc_fops = {
@@ -673,30 +653,38 @@ static const struct file_operations video_proc_fops = {
        .write          = video_proc_write,
 };
 
-static int fan_proc_show(struct seq_file *m, void *v)
+static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
 {
        u32 hci_result;
+
+       hci_read1(dev, HCI_FAN, status, &hci_result);
+       return hci_result == HCI_SUCCESS ? 0 : -EIO;
+}
+
+static int fan_proc_show(struct seq_file *m, void *v)
+{
+       struct toshiba_acpi_dev *dev = m->private;
+       int ret;
        u32 value;
 
-       hci_read1(HCI_FAN, &value, &hci_result);
-       if (hci_result == HCI_SUCCESS) {
+       ret = get_fan_status(dev, &value);
+       if (!ret) {
                seq_printf(m, "running:                 %d\n", (value > 0));
-               seq_printf(m, "force_on:                %d\n", force_fan);
-       } else {
-               pr_err("Error reading fan status\n");
+               seq_printf(m, "force_on:                %d\n", dev->force_fan);
        }
 
-       return 0;
+       return ret;
 }
 
 static int fan_proc_open(struct inode *inode, struct file *file)
 {
-       return single_open(file, fan_proc_show, NULL);
+       return single_open(file, fan_proc_show, PDE(inode)->data);
 }
 
 static ssize_t fan_proc_write(struct file *file, const char __user *buf,
                              size_t count, loff_t *pos)
 {
+       struct toshiba_acpi_dev *dev = PDE(file->f_path.dentry->d_inode)->data;
        char cmd[42];
        size_t len;
        int value;
@@ -709,11 +697,11 @@ static ssize_t fan_proc_write(struct file *file, const char __user *buf,
 
        if (sscanf(cmd, " force_on : %i", &value) == 1 &&
            value >= 0 && value <= 1) {
-               hci_write1(HCI_FAN, value, &hci_result);
+               hci_write1(dev, HCI_FAN, value, &hci_result);
                if (hci_result != HCI_SUCCESS)
-                       return -EFAULT;
+                       return -EIO;
                else
-                       force_fan = value;
+                       dev->force_fan = value;
        } else {
                return -EINVAL;
        }
@@ -732,42 +720,43 @@ static const struct file_operations fan_proc_fops = {
 
 static int keys_proc_show(struct seq_file *m, void *v)
 {
+       struct toshiba_acpi_dev *dev = m->private;
        u32 hci_result;
        u32 value;
 
-       if (!key_event_valid) {
-               hci_read1(HCI_SYSTEM_EVENT, &value, &hci_result);
+       if (!dev->key_event_valid) {
+               hci_read1(dev, HCI_SYSTEM_EVENT, &value, &hci_result);
                if (hci_result == HCI_SUCCESS) {
-                       key_event_valid = 1;
-                       last_key_event = value;
+                       dev->key_event_valid = 1;
+                       dev->last_key_event = value;
                } else if (hci_result == HCI_EMPTY) {
                        /* better luck next time */
                } else if (hci_result == HCI_NOT_SUPPORTED) {
                        /* This is a workaround for an unresolved issue on
                         * some machines where system events sporadically
                         * become disabled. */
-                       hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result);
+                       hci_write1(dev, HCI_SYSTEM_EVENT, 1, &hci_result);
                        pr_notice("Re-enabled hotkeys\n");
                } else {
                        pr_err("Error reading hotkey status\n");
-                       goto end;
+                       return -EIO;
                }
        }
 
-       seq_printf(m, "hotkey_ready:            %d\n", key_event_valid);
-       seq_printf(m, "hotkey:                  0x%04x\n", last_key_event);
-end:
+       seq_printf(m, "hotkey_ready:            %d\n", dev->key_event_valid);
+       seq_printf(m, "hotkey:                  0x%04x\n", dev->last_key_event);
        return 0;
 }
 
 static int keys_proc_open(struct inode *inode, struct file *file)
 {
-       return single_open(file, keys_proc_show, NULL);
+       return single_open(file, keys_proc_show, PDE(inode)->data);
 }
 
 static ssize_t keys_proc_write(struct file *file, const char __user *buf,
                               size_t count, loff_t *pos)
 {
+       struct toshiba_acpi_dev *dev = PDE(file->f_path.dentry->d_inode)->data;
        char cmd[42];
        size_t len;
        int value;
@@ -778,7 +767,7 @@ static ssize_t keys_proc_write(struct file *file, const char __user *buf,
        cmd[len] = '\0';
 
        if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0) {
-               key_event_valid = 0;
+               dev->key_event_valid = 0;
        } else {
                return -EINVAL;
        }
@@ -820,21 +809,35 @@ static const struct file_operations version_proc_fops = {
 
 #define PROC_TOSHIBA           "toshiba"
 
-static void __init create_toshiba_proc_entries(void)
+static void __devinit
+create_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
 {
-       proc_create("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir, &lcd_proc_fops);
-       proc_create("video", S_IRUGO | S_IWUSR, toshiba_proc_dir, &video_proc_fops);
-       proc_create("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir, &fan_proc_fops);
-       proc_create("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir, &keys_proc_fops);
-       proc_create("version", S_IRUGO, toshiba_proc_dir, &version_proc_fops);
+       if (dev->backlight_dev)
+               proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir,
+                                &lcd_proc_fops, dev);
+       if (dev->video_supported)
+               proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir,
+                                &video_proc_fops, dev);
+       if (dev->fan_supported)
+               proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir,
+                                &fan_proc_fops, dev);
+       if (dev->hotkey_dev)
+               proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir,
+                                &keys_proc_fops, dev);
+       proc_create_data("version", S_IRUGO, toshiba_proc_dir,
+                        &version_proc_fops, dev);
 }
 
-static void remove_toshiba_proc_entries(void)
+static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
 {
-       remove_proc_entry("lcd", toshiba_proc_dir);
-       remove_proc_entry("video", toshiba_proc_dir);
-       remove_proc_entry("fan", toshiba_proc_dir);
-       remove_proc_entry("keys", toshiba_proc_dir);
+       if (dev->backlight_dev)
+               remove_proc_entry("lcd", toshiba_proc_dir);
+       if (dev->video_supported)
+               remove_proc_entry("video", toshiba_proc_dir);
+       if (dev->fan_supported)
+               remove_proc_entry("fan", toshiba_proc_dir);
+       if (dev->hotkey_dev)
+               remove_proc_entry("keys", toshiba_proc_dir);
        remove_proc_entry("version", toshiba_proc_dir);
 }
 
@@ -843,224 +846,256 @@ static const struct backlight_ops toshiba_backlight_data = {
         .update_status  = set_lcd_status,
 };
 
-static void toshiba_acpi_notify(acpi_handle handle, u32 event, void *context)
-{
-       u32 hci_result, value;
-
-       if (event != 0x80)
-               return;
-       do {
-               hci_read1(HCI_SYSTEM_EVENT, &value, &hci_result);
-               if (hci_result == HCI_SUCCESS) {
-                       if (value == 0x100)
-                               continue;
-                       /* act on key press; ignore key release */
-                       if (value & 0x80)
-                               continue;
-
-                       if (!sparse_keymap_report_event(toshiba_acpi.hotkey_dev,
-                                                       value, 1, true)) {
-                               pr_info("Unknown key %x\n",
-                                      value);
-                       }
-               } else if (hci_result == HCI_NOT_SUPPORTED) {
-                       /* This is a workaround for an unresolved issue on
-                        * some machines where system events sporadically
-                        * become disabled. */
-                       hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result);
-                       pr_notice("Re-enabled hotkeys\n");
-               }
-       } while (hci_result != HCI_EMPTY);
-}
-
-static int __init toshiba_acpi_setup_keyboard(char *device)
+static int __devinit toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
 {
        acpi_status status;
        int error;
 
-       status = acpi_get_handle(NULL, device, &toshiba_acpi.handle);
-       if (ACPI_FAILURE(status)) {
-               pr_info("Unable to get notification device\n");
-               return -ENODEV;
-       }
-
-       toshiba_acpi.hotkey_dev = input_allocate_device();
-       if (!toshiba_acpi.hotkey_dev) {
+       dev->hotkey_dev = input_allocate_device();
+       if (!dev->hotkey_dev) {
                pr_info("Unable to register input device\n");
                return -ENOMEM;
        }
 
-       toshiba_acpi.hotkey_dev->name = "Toshiba input device";
-       toshiba_acpi.hotkey_dev->phys = device;
-       toshiba_acpi.hotkey_dev->id.bustype = BUS_HOST;
+       dev->hotkey_dev->name = "Toshiba input device";
+       dev->hotkey_dev->phys = "toshiba_acpi/input0";
+       dev->hotkey_dev->id.bustype = BUS_HOST;
 
-       error = sparse_keymap_setup(toshiba_acpi.hotkey_dev,
-                                   toshiba_acpi_keymap, NULL);
+       error = sparse_keymap_setup(dev->hotkey_dev, toshiba_acpi_keymap, NULL);
        if (error)
                goto err_free_dev;
 
-       status = acpi_install_notify_handler(toshiba_acpi.handle,
-                               ACPI_DEVICE_NOTIFY, toshiba_acpi_notify, NULL);
-       if (ACPI_FAILURE(status)) {
-               pr_info("Unable to install hotkey notification\n");
-               error = -ENODEV;
-               goto err_free_keymap;
-       }
-
-       status = acpi_evaluate_object(toshiba_acpi.handle, "ENAB", NULL, NULL);
+       status = acpi_evaluate_object(dev->acpi_dev->handle, "ENAB", NULL, NULL);
        if (ACPI_FAILURE(status)) {
                pr_info("Unable to enable hotkeys\n");
                error = -ENODEV;
-               goto err_remove_notify;
+               goto err_free_keymap;
        }
 
-       error = input_register_device(toshiba_acpi.hotkey_dev);
+       error = input_register_device(dev->hotkey_dev);
        if (error) {
                pr_info("Unable to register input device\n");
-               goto err_remove_notify;
+               goto err_free_keymap;
        }
 
        return 0;
 
- err_remove_notify:
-       acpi_remove_notify_handler(toshiba_acpi.handle,
-                                  ACPI_DEVICE_NOTIFY, toshiba_acpi_notify);
  err_free_keymap:
-       sparse_keymap_free(toshiba_acpi.hotkey_dev);
+       sparse_keymap_free(dev->hotkey_dev);
  err_free_dev:
-       input_free_device(toshiba_acpi.hotkey_dev);
-       toshiba_acpi.hotkey_dev = NULL;
+       input_free_device(dev->hotkey_dev);
+       dev->hotkey_dev = NULL;
        return error;
 }
 
-static void toshiba_acpi_exit(void)
+static int toshiba_acpi_remove(struct acpi_device *acpi_dev, int type)
 {
-       if (toshiba_acpi.hotkey_dev) {
-               acpi_remove_notify_handler(toshiba_acpi.handle,
-                               ACPI_DEVICE_NOTIFY, toshiba_acpi_notify);
-               sparse_keymap_free(toshiba_acpi.hotkey_dev);
-               input_unregister_device(toshiba_acpi.hotkey_dev);
+       struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
+
+       remove_toshiba_proc_entries(dev);
+
+       if (dev->hotkey_dev) {
+               input_unregister_device(dev->hotkey_dev);
+               sparse_keymap_free(dev->hotkey_dev);
        }
 
-       if (toshiba_acpi.bt_rfk) {
-               rfkill_unregister(toshiba_acpi.bt_rfk);
-               rfkill_destroy(toshiba_acpi.bt_rfk);
+       if (dev->bt_rfk) {
+               rfkill_unregister(dev->bt_rfk);
+               rfkill_destroy(dev->bt_rfk);
        }
 
-       if (toshiba_backlight_device)
-               backlight_device_unregister(toshiba_backlight_device);
+       if (dev->backlight_dev)
+               backlight_device_unregister(dev->backlight_dev);
 
-       remove_toshiba_proc_entries();
+       if (dev->illumination_supported)
+               led_classdev_unregister(&dev->led_dev);
 
-       if (toshiba_proc_dir)
-               remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
+       kfree(dev);
+
+       return 0;
+}
+
+static const char * __devinit find_hci_method(acpi_handle handle)
+{
+       acpi_status status;
+       acpi_handle hci_handle;
 
-       if (toshiba_acpi.illumination_installed)
-               led_classdev_unregister(&toshiba_led);
+       status = acpi_get_handle(handle, "GHCI", &hci_handle);
+       if (ACPI_SUCCESS(status))
+               return "GHCI";
 
-       platform_device_unregister(toshiba_acpi.p_dev);
+       status = acpi_get_handle(handle, "SPFC", &hci_handle);
+       if (ACPI_SUCCESS(status))
+               return "SPFC";
 
-       return;
+       return NULL;
 }
 
-static int __init toshiba_acpi_init(void)
+static int __devinit toshiba_acpi_add(struct acpi_device *acpi_dev)
 {
+       struct toshiba_acpi_dev *dev;
+       const char *hci_method;
        u32 hci_result;
+       u32 dummy;
        bool bt_present;
        int ret = 0;
        struct backlight_properties props;
 
-       if (acpi_disabled)
-               return -ENODEV;
-
-       /* simple device detection: look for HCI method */
-       if (is_valid_acpi_path(TOSH_INTERFACE_1 GHCI_METHOD)) {
-               method_hci = TOSH_INTERFACE_1 GHCI_METHOD;
-               if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_1))
-                       pr_info("Unable to activate hotkeys\n");
-       } else if (is_valid_acpi_path(TOSH_INTERFACE_2 GHCI_METHOD)) {
-               method_hci = TOSH_INTERFACE_2 GHCI_METHOD;
-               if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_2))
-                       pr_info("Unable to activate hotkeys\n");
-       } else
-               return -ENODEV;
-
        pr_info("Toshiba Laptop ACPI Extras version %s\n",
               TOSHIBA_ACPI_VERSION);
-       pr_info("    HCI method: %s\n", method_hci);
-
-       mutex_init(&toshiba_acpi.mutex);
-
-       toshiba_acpi.p_dev = platform_device_register_simple("toshiba_acpi",
-                                                             -1, NULL, 0);
-       if (IS_ERR(toshiba_acpi.p_dev)) {
-               ret = PTR_ERR(toshiba_acpi.p_dev);
-               pr_err("unable to register platform device\n");
-               toshiba_acpi.p_dev = NULL;
-               toshiba_acpi_exit();
-               return ret;
+
+       hci_method = find_hci_method(acpi_dev->handle);
+       if (!hci_method) {
+               pr_err("HCI interface not found\n");
+               return -ENODEV;
        }
 
-       force_fan = 0;
-       key_event_valid = 0;
+       dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+       if (!dev)
+               return -ENOMEM;
+       dev->acpi_dev = acpi_dev;
+       dev->method_hci = hci_method;
+       acpi_dev->driver_data = dev;
 
-       /* enable event fifo */
-       hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result);
+       if (toshiba_acpi_setup_keyboard(dev))
+               pr_info("Unable to activate hotkeys\n");
 
-       toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
-       if (!toshiba_proc_dir) {
-               toshiba_acpi_exit();
-               return -ENODEV;
-       } else {
-               create_toshiba_proc_entries();
-       }
+       mutex_init(&dev->mutex);
+
+       /* enable event fifo */
+       hci_write1(dev, HCI_SYSTEM_EVENT, 1, &hci_result);
 
        props.type = BACKLIGHT_PLATFORM;
        props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
-       toshiba_backlight_device = backlight_device_register("toshiba",
-                                                            &toshiba_acpi.p_dev->dev,
-                                                            NULL,
-                                                            &toshiba_backlight_data,
-                                                            &props);
-        if (IS_ERR(toshiba_backlight_device)) {
-               ret = PTR_ERR(toshiba_backlight_device);
+       dev->backlight_dev = backlight_device_register("toshiba",
+                                                      &acpi_dev->dev,
+                                                      dev,
+                                                      &toshiba_backlight_data,
+                                                      &props);
+       if (IS_ERR(dev->backlight_dev)) {
+               ret = PTR_ERR(dev->backlight_dev);
 
                pr_err("Could not register toshiba backlight device\n");
-               toshiba_backlight_device = NULL;
-               toshiba_acpi_exit();
-               return ret;
+               dev->backlight_dev = NULL;
+               goto error;
        }
+       dev->backlight_dev->props.brightness = get_lcd(dev->backlight_dev);
 
        /* Register rfkill switch for Bluetooth */
-       if (hci_get_bt_present(&bt_present) == HCI_SUCCESS && bt_present) {
-               toshiba_acpi.bt_rfk = rfkill_alloc(toshiba_acpi.bt_name,
-                                                  &toshiba_acpi.p_dev->dev,
-                                                  RFKILL_TYPE_BLUETOOTH,
-                                                  &toshiba_rfk_ops,
-                                                  &toshiba_acpi);
-               if (!toshiba_acpi.bt_rfk) {
+       if (hci_get_bt_present(dev, &bt_present) == HCI_SUCCESS && bt_present) {
+               dev->bt_rfk = rfkill_alloc("Toshiba Bluetooth",
+                                          &acpi_dev->dev,
+                                          RFKILL_TYPE_BLUETOOTH,
+                                          &toshiba_rfk_ops,
+                                          dev);
+               if (!dev->bt_rfk) {
                        pr_err("unable to allocate rfkill device\n");
-                       toshiba_acpi_exit();
-                       return -ENOMEM;
+                       ret = -ENOMEM;
+                       goto error;
                }
 
-               ret = rfkill_register(toshiba_acpi.bt_rfk);
+               ret = rfkill_register(dev->bt_rfk);
                if (ret) {
                        pr_err("unable to register rfkill device\n");
-                       rfkill_destroy(toshiba_acpi.bt_rfk);
-                       toshiba_acpi_exit();
-                       return ret;
+                       rfkill_destroy(dev->bt_rfk);
+                       goto error;
                }
        }
 
-       toshiba_acpi.illumination_installed = 0;
-       if (toshiba_illumination_available()) {
-               if (!led_classdev_register(&(toshiba_acpi.p_dev->dev),
-                                          &toshiba_led))
-                       toshiba_acpi.illumination_installed = 1;
+       if (toshiba_illumination_available(dev)) {
+               dev->led_dev.name = "toshiba::illumination";
+               dev->led_dev.max_brightness = 1;
+               dev->led_dev.brightness_set = toshiba_illumination_set;
+               dev->led_dev.brightness_get = toshiba_illumination_get;
+               if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev))
+                       dev->illumination_supported = 1;
        }
 
+       /* Determine whether or not BIOS supports fan and video interfaces */
+
+       ret = get_video_status(dev, &dummy);
+       dev->video_supported = !ret;
+
+       ret = get_fan_status(dev, &dummy);
+       dev->fan_supported = !ret;
+
+       create_toshiba_proc_entries(dev);
+
        return 0;
+
+error:
+       toshiba_acpi_remove(acpi_dev, 0);
+       return ret;
+}
+
+static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
+{
+       struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
+       u32 hci_result, value;
+
+       if (event != 0x80)
+               return;
+       do {
+               hci_read1(dev, HCI_SYSTEM_EVENT, &value, &hci_result);
+               if (hci_result == HCI_SUCCESS) {
+                       if (value == 0x100)
+                               continue;
+                       /* act on key press; ignore key release */
+                       if (value & 0x80)
+                               continue;
+
+                       if (!sparse_keymap_report_event(dev->hotkey_dev,
+                                                       value, 1, true)) {
+                               pr_info("Unknown key %x\n",
+                                      value);
+                       }
+               } else if (hci_result == HCI_NOT_SUPPORTED) {
+                       /* This is a workaround for an unresolved issue on
+                        * some machines where system events sporadically
+                        * become disabled. */
+                       hci_write1(dev, HCI_SYSTEM_EVENT, 1, &hci_result);
+                       pr_notice("Re-enabled hotkeys\n");
+               }
+       } while (hci_result != HCI_EMPTY);
+}
+
+
+static struct acpi_driver toshiba_acpi_driver = {
+       .name   = "Toshiba ACPI driver",
+       .owner  = THIS_MODULE,
+       .ids    = toshiba_device_ids,
+       .flags  = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
+       .ops    = {
+               .add            = toshiba_acpi_add,
+               .remove         = toshiba_acpi_remove,
+               .notify         = toshiba_acpi_notify,
+       },
+};
+
+static int __init toshiba_acpi_init(void)
+{
+       int ret;
+
+       toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
+       if (!toshiba_proc_dir) {
+               pr_err("Unable to create proc dir " PROC_TOSHIBA "\n");
+               return -ENODEV;
+       }
+
+       ret = acpi_bus_register_driver(&toshiba_acpi_driver);
+       if (ret) {
+               pr_err("Failed to register ACPI driver: %d\n", ret);
+               remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
+       }
+
+       return ret;
+}
+
+static void __exit toshiba_acpi_exit(void)
+{
+       acpi_bus_unregister_driver(&toshiba_acpi_driver);
+       if (toshiba_proc_dir)
+               remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
 }
 
 module_init(toshiba_acpi_init);
index f23d5a84e7b1b61108bdb651b5a240bed3ee4ed0..9b88be42b6cd3a43ba9b2c1d1563446c7df43f16 100644 (file)
@@ -754,9 +754,13 @@ static void wmi_free_devices(void)
        struct wmi_block *wblock, *next;
 
        /* Delete devices for all the GUIDs */
-       list_for_each_entry_safe(wblock, next, &wmi_block_list, list)
+       list_for_each_entry_safe(wblock, next, &wmi_block_list, list) {
+               list_del(&wblock->list);
                if (wblock->dev.class)
                        device_unregister(&wblock->dev);
+               else
+                       kfree(wblock);
+       }
 }
 
 static bool guid_already_parsed(const char *guid_string)
index d63fddb0fbb0d5ead8cadb323bfbff49b2a3e00f..e821b2159b4b72a93ef0225d0db2a35b86bc4efa 100644 (file)
@@ -412,7 +412,7 @@ static int __devinit pm8607_regulator_probe(struct platform_device *pdev)
                if (info->desc.id == res->start)
                        break;
        }
-       if ((i < 0) || (i > PM8607_ID_RG_MAX)) {
+       if (i == ARRAY_SIZE(pm8607_regulator_info)) {
                dev_err(&pdev->dev, "Failed to find regulator %llu\n",
                        (unsigned long long)res->start);
                return -EINVAL;
index c7fd2c0e3f2bd212ebe607224fb9dd4943fa8546..9713b1b860cb70a88f9fc51805f087a2919f0ef2 100644 (file)
@@ -64,6 +64,16 @@ config REGULATOR_USERSPACE_CONSUMER
 
           If unsure, say no.
 
+config REGULATOR_GPIO
+       tristate "GPIO regulator support"
+       depends on GENERIC_GPIO
+       help
+         This driver provides support for regulators that can be
+         controlled via gpios.
+         It is capable of supporting current and voltage regulators
+         and the platform has to provide a mapping of GPIO-states
+         to target volts/amps.
+
 config REGULATOR_BQ24022
        tristate "TI bq24022 Dual Input 1-Cell Li-Ion Charger IC"
        help
index 040d5aa63535bb33d2c0e946d7878bfc7418fad8..93a6318f5328eabaa73af83c877aee2a3edac876 100644 (file)
@@ -8,6 +8,7 @@ obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o
 obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o
 obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o
 
+obj-$(CONFIG_REGULATOR_GPIO) += gpio-regulator.o
 obj-$(CONFIG_REGULATOR_AD5398) += ad5398.o
 obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o
 obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o
index cd4104542f0dc26ee0f7573556ad73c04dedc707..5abeb3ac3e8da43df3d58bf677c3ac0e3d17116e 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/err.h>
+#include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/delay.h>
 #include <linux/platform_device.h>
index d8e6a429e8ba046027e9fa8550be6444f47ae971..67fa2a3297adc14afa059709d899defbb7aed9ba 100644 (file)
@@ -1425,7 +1425,7 @@ int regulator_enable(struct regulator *regulator)
        ret = _regulator_enable(rdev);
        mutex_unlock(&rdev->mutex);
 
-       if (ret != 0)
+       if (ret != 0 && rdev->supply)
                regulator_disable(rdev->supply);
 
        return ret;
@@ -1552,6 +1552,68 @@ int regulator_force_disable(struct regulator *regulator)
 }
 EXPORT_SYMBOL_GPL(regulator_force_disable);
 
+static void regulator_disable_work(struct work_struct *work)
+{
+       struct regulator_dev *rdev = container_of(work, struct regulator_dev,
+                                                 disable_work.work);
+       int count, i, ret;
+
+       mutex_lock(&rdev->mutex);
+
+       BUG_ON(!rdev->deferred_disables);
+
+       count = rdev->deferred_disables;
+       rdev->deferred_disables = 0;
+
+       for (i = 0; i < count; i++) {
+               ret = _regulator_disable(rdev);
+               if (ret != 0)
+                       rdev_err(rdev, "Deferred disable failed: %d\n", ret);
+       }
+
+       mutex_unlock(&rdev->mutex);
+
+       if (rdev->supply) {
+               for (i = 0; i < count; i++) {
+                       ret = regulator_disable(rdev->supply);
+                       if (ret != 0) {
+                               rdev_err(rdev,
+                                        "Supply disable failed: %d\n", ret);
+                       }
+               }
+       }
+}
+
+/**
+ * regulator_disable_deferred - disable regulator output with delay
+ * @regulator: regulator source
+ * @ms: miliseconds until the regulator is disabled
+ *
+ * Execute regulator_disable() on the regulator after a delay.  This
+ * is intended for use with devices that require some time to quiesce.
+ *
+ * NOTE: this will only disable the regulator output if no other consumer
+ * devices have it enabled, the regulator device supports disabling and
+ * machine constraints permit this operation.
+ */
+int regulator_disable_deferred(struct regulator *regulator, int ms)
+{
+       struct regulator_dev *rdev = regulator->rdev;
+       int ret;
+
+       mutex_lock(&rdev->mutex);
+       rdev->deferred_disables++;
+       mutex_unlock(&rdev->mutex);
+
+       ret = schedule_delayed_work(&rdev->disable_work,
+                                   msecs_to_jiffies(ms));
+       if (ret < 0)
+               return ret;
+       else
+               return 0;
+}
+EXPORT_SYMBOL_GPL(regulator_disable_deferred);
+
 static int _regulator_is_enabled(struct regulator_dev *rdev)
 {
        /* If we don't know then assume that the regulator is always on */
@@ -2622,6 +2684,7 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
        INIT_LIST_HEAD(&rdev->consumer_list);
        INIT_LIST_HEAD(&rdev->list);
        BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier);
+       INIT_DELAYED_WORK(&rdev->disable_work, regulator_disable_work);
 
        /* preform any regulator specific init */
        if (init_data->regulator_init) {
@@ -2729,6 +2792,7 @@ void regulator_unregister(struct regulator_dev *rdev)
 #ifdef CONFIG_DEBUG_FS
        debugfs_remove_recursive(rdev->debugfs);
 #endif
+       flush_work_sync(&rdev->disable_work.work);
        WARN_ON(rdev->open_count);
        unset_regulator_supplies(rdev);
        list_del(&rdev->list);
@@ -2907,6 +2971,43 @@ void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data)
 }
 EXPORT_SYMBOL_GPL(regulator_get_init_drvdata);
 
+#ifdef CONFIG_DEBUG_FS
+static ssize_t supply_map_read_file(struct file *file, char __user *user_buf,
+                                   size_t count, loff_t *ppos)
+{
+       char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
+       ssize_t len, ret = 0;
+       struct regulator_map *map;
+
+       if (!buf)
+               return -ENOMEM;
+
+       list_for_each_entry(map, &regulator_map_list, list) {
+               len = snprintf(buf + ret, PAGE_SIZE - ret,
+                              "%s -> %s.%s\n",
+                              rdev_get_name(map->regulator), map->dev_name,
+                              map->supply);
+               if (len >= 0)
+                       ret += len;
+               if (ret > PAGE_SIZE) {
+                       ret = PAGE_SIZE;
+                       break;
+               }
+       }
+
+       ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
+
+       kfree(buf);
+
+       return ret;
+}
+
+static const struct file_operations supply_map_fops = {
+       .read = supply_map_read_file,
+       .llseek = default_llseek,
+};
+#endif
+
 static int __init regulator_init(void)
 {
        int ret;
@@ -2919,6 +3020,10 @@ static int __init regulator_init(void)
                pr_warn("regulator: Failed to create debugfs directory\n");
                debugfs_root = NULL;
        }
+
+       if (IS_ERR(debugfs_create_file("supply_map", 0444, debugfs_root,
+                                      NULL, &supply_map_fops)))
+               pr_warn("regulator: Failed to create supplies debugfs\n");
 #endif
 
        regulator_dummy_init();
diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c
new file mode 100644 (file)
index 0000000..f0acf52
--- /dev/null
@@ -0,0 +1,358 @@
+/*
+ * gpio-regulator.c
+ *
+ * Copyright 2011 Heiko Stuebner <heiko@sntech.de>
+ *
+ * based on fixed.c
+ *
+ * Copyright 2008 Wolfson Microelectronics PLC.
+ *
+ * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
+ *
+ * Copyright (c) 2009 Nokia Corporation
+ * Roger Quadros <ext-roger.quadros@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This is useful for systems with mixed controllable and
+ * non-controllable regulators, as well as for allowing testing on
+ * systems with no controllable regulators.
+ */
+
+#include <linux/err.h>
+#include <linux/mutex.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/regulator/driver.h>
+#include <linux/regulator/machine.h>
+#include <linux/regulator/gpio-regulator.h>
+#include <linux/gpio.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+
+struct gpio_regulator_data {
+       struct regulator_desc desc;
+       struct regulator_dev *dev;
+
+       int enable_gpio;
+       bool enable_high;
+       bool is_enabled;
+       unsigned startup_delay;
+
+       struct gpio *gpios;
+       int nr_gpios;
+
+       struct gpio_regulator_state *states;
+       int nr_states;
+
+       int state;
+};
+
+static int gpio_regulator_is_enabled(struct regulator_dev *dev)
+{
+       struct gpio_regulator_data *data = rdev_get_drvdata(dev);
+
+       return data->is_enabled;
+}
+
+static int gpio_regulator_enable(struct regulator_dev *dev)
+{
+       struct gpio_regulator_data *data = rdev_get_drvdata(dev);
+
+       if (gpio_is_valid(data->enable_gpio)) {
+               gpio_set_value_cansleep(data->enable_gpio, data->enable_high);
+               data->is_enabled = true;
+       }
+
+       return 0;
+}
+
+static int gpio_regulator_disable(struct regulator_dev *dev)
+{
+       struct gpio_regulator_data *data = rdev_get_drvdata(dev);
+
+       if (gpio_is_valid(data->enable_gpio)) {
+               gpio_set_value_cansleep(data->enable_gpio, !data->enable_high);
+               data->is_enabled = false;
+       }
+
+       return 0;
+}
+
+static int gpio_regulator_enable_time(struct regulator_dev *dev)
+{
+       struct gpio_regulator_data *data = rdev_get_drvdata(dev);
+
+       return data->startup_delay;
+}
+
+static int gpio_regulator_get_value(struct regulator_dev *dev)
+{
+       struct gpio_regulator_data *data = rdev_get_drvdata(dev);
+       int ptr;
+
+       for (ptr = 0; ptr < data->nr_states; ptr++)
+               if (data->states[ptr].gpios == data->state)
+                       return data->states[ptr].value;
+
+       return -EINVAL;
+}
+
+static int gpio_regulator_set_value(struct regulator_dev *dev,
+                                       int min, int max)
+{
+       struct gpio_regulator_data *data = rdev_get_drvdata(dev);
+       int ptr, target, state;
+
+       target = -1;
+       for (ptr = 0; ptr < data->nr_states; ptr++)
+               if (data->states[ptr].value >= min &&
+                   data->states[ptr].value <= max)
+                       target = data->states[ptr].gpios;
+
+       if (target < 0)
+               return -EINVAL;
+
+       for (ptr = 0; ptr < data->nr_gpios; ptr++) {
+               state = (target & (1 << ptr)) >> ptr;
+               gpio_set_value(data->gpios[ptr].gpio, state);
+       }
+       data->state = target;
+
+       return 0;
+}
+
+static int gpio_regulator_set_voltage(struct regulator_dev *dev,
+                                       int min_uV, int max_uV,
+                                       unsigned *selector)
+{
+       return gpio_regulator_set_value(dev, min_uV, max_uV);
+}
+
+static int gpio_regulator_list_voltage(struct regulator_dev *dev,
+                                     unsigned selector)
+{
+       struct gpio_regulator_data *data = rdev_get_drvdata(dev);
+
+       if (selector >= data->nr_states)
+               return -EINVAL;
+
+       return data->states[selector].value;
+}
+
+static int gpio_regulator_set_current_limit(struct regulator_dev *dev,
+                                       int min_uA, int max_uA)
+{
+       return gpio_regulator_set_value(dev, min_uA, max_uA);
+}
+
+static struct regulator_ops gpio_regulator_voltage_ops = {
+       .is_enabled = gpio_regulator_is_enabled,
+       .enable = gpio_regulator_enable,
+       .disable = gpio_regulator_disable,
+       .enable_time = gpio_regulator_enable_time,
+       .get_voltage = gpio_regulator_get_value,
+       .set_voltage = gpio_regulator_set_voltage,
+       .list_voltage = gpio_regulator_list_voltage,
+};
+
+static struct regulator_ops gpio_regulator_current_ops = {
+       .is_enabled = gpio_regulator_is_enabled,
+       .enable = gpio_regulator_enable,
+       .disable = gpio_regulator_disable,
+       .enable_time = gpio_regulator_enable_time,
+       .get_current_limit = gpio_regulator_get_value,
+       .set_current_limit = gpio_regulator_set_current_limit,
+};
+
+static int __devinit gpio_regulator_probe(struct platform_device *pdev)
+{
+       struct gpio_regulator_config *config = pdev->dev.platform_data;
+       struct gpio_regulator_data *drvdata;
+       int ptr, ret, state;
+
+       drvdata = kzalloc(sizeof(struct gpio_regulator_data), GFP_KERNEL);
+       if (drvdata == NULL) {
+               dev_err(&pdev->dev, "Failed to allocate device data\n");
+               return -ENOMEM;
+       }
+
+       drvdata->desc.name = kstrdup(config->supply_name, GFP_KERNEL);
+       if (drvdata->desc.name == NULL) {
+               dev_err(&pdev->dev, "Failed to allocate supply name\n");
+               ret = -ENOMEM;
+               goto err;
+       }
+
+       drvdata->gpios = kmemdup(config->gpios,
+                                config->nr_gpios * sizeof(struct gpio),
+                                GFP_KERNEL);
+       if (drvdata->gpios == NULL) {
+               dev_err(&pdev->dev, "Failed to allocate gpio data\n");
+               ret = -ENOMEM;
+               goto err_name;
+       }
+
+       drvdata->states = kmemdup(config->states,
+                                 config->nr_states *
+                                        sizeof(struct gpio_regulator_state),
+                                 GFP_KERNEL);
+       if (drvdata->states == NULL) {
+               dev_err(&pdev->dev, "Failed to allocate state data\n");
+               ret = -ENOMEM;
+               goto err_memgpio;
+       }
+       drvdata->nr_states = config->nr_states;
+
+       drvdata->desc.owner = THIS_MODULE;
+
+       /* handle regulator type*/
+       switch (config->type) {
+       case REGULATOR_VOLTAGE:
+               drvdata->desc.type = REGULATOR_VOLTAGE;
+               drvdata->desc.ops = &gpio_regulator_voltage_ops;
+               drvdata->desc.n_voltages = config->nr_states;
+               break;
+       case REGULATOR_CURRENT:
+               drvdata->desc.type = REGULATOR_CURRENT;
+               drvdata->desc.ops = &gpio_regulator_current_ops;
+               break;
+       default:
+               dev_err(&pdev->dev, "No regulator type set\n");
+               ret = -EINVAL;
+               goto err_memgpio;
+               break;
+       }
+
+       drvdata->enable_gpio = config->enable_gpio;
+       drvdata->startup_delay = config->startup_delay;
+
+       if (gpio_is_valid(config->enable_gpio)) {
+               drvdata->enable_high = config->enable_high;
+
+               ret = gpio_request(config->enable_gpio, config->supply_name);
+               if (ret) {
+                       dev_err(&pdev->dev,
+                          "Could not obtain regulator enable GPIO %d: %d\n",
+                                               config->enable_gpio, ret);
+                       goto err_memstate;
+               }
+
+               /* set output direction without changing state
+                * to prevent glitch
+                */
+               if (config->enabled_at_boot) {
+                       drvdata->is_enabled = true;
+                       ret = gpio_direction_output(config->enable_gpio,
+                                                   config->enable_high);
+               } else {
+                       drvdata->is_enabled = false;
+                       ret = gpio_direction_output(config->enable_gpio,
+                                                   !config->enable_high);
+               }
+
+               if (ret) {
+                       dev_err(&pdev->dev,
+                          "Could not configure regulator enable GPIO %d direction: %d\n",
+                                               config->enable_gpio, ret);
+                       goto err_enablegpio;
+               }
+       } else {
+               /* Regulator without GPIO control is considered
+                * always enabled
+                */
+               drvdata->is_enabled = true;
+       }
+
+       drvdata->nr_gpios = config->nr_gpios;
+       ret = gpio_request_array(drvdata->gpios, drvdata->nr_gpios);
+       if (ret) {
+               dev_err(&pdev->dev,
+                  "Could not obtain regulator setting GPIOs: %d\n", ret);
+               goto err_enablegpio;
+       }
+
+       /* build initial state from gpio init data. */
+       state = 0;
+       for (ptr = 0; ptr < drvdata->nr_gpios; ptr++) {
+               if (config->gpios[ptr].flags & GPIOF_OUT_INIT_HIGH)
+                       state |= (1 << ptr);
+       }
+       drvdata->state = state;
+
+       drvdata->dev = regulator_register(&drvdata->desc, &pdev->dev,
+                                         config->init_data, drvdata);
+       if (IS_ERR(drvdata->dev)) {
+               ret = PTR_ERR(drvdata->dev);
+               dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret);
+               goto err_stategpio;
+       }
+
+       platform_set_drvdata(pdev, drvdata);
+
+       return 0;
+
+err_stategpio:
+       gpio_free_array(drvdata->gpios, drvdata->nr_gpios);
+err_enablegpio:
+       if (gpio_is_valid(config->enable_gpio))
+               gpio_free(config->enable_gpio);
+err_memstate:
+       kfree(drvdata->states);
+err_memgpio:
+       kfree(drvdata->gpios);
+err_name:
+       kfree(drvdata->desc.name);
+err:
+       kfree(drvdata);
+       return ret;
+}
+
+static int __devexit gpio_regulator_remove(struct platform_device *pdev)
+{
+       struct gpio_regulator_data *drvdata = platform_get_drvdata(pdev);
+
+       regulator_unregister(drvdata->dev);
+
+       gpio_free_array(drvdata->gpios, drvdata->nr_gpios);
+
+       kfree(drvdata->states);
+       kfree(drvdata->gpios);
+
+       if (gpio_is_valid(drvdata->enable_gpio))
+               gpio_free(drvdata->enable_gpio);
+
+       kfree(drvdata->desc.name);
+       kfree(drvdata);
+
+       return 0;
+}
+
+static struct platform_driver gpio_regulator_driver = {
+       .probe          = gpio_regulator_probe,
+       .remove         = __devexit_p(gpio_regulator_remove),
+       .driver         = {
+               .name           = "gpio-regulator",
+               .owner          = THIS_MODULE,
+       },
+};
+
+static int __init gpio_regulator_init(void)
+{
+       return platform_driver_register(&gpio_regulator_driver);
+}
+subsys_initcall(gpio_regulator_init);
+
+static void __exit gpio_regulator_exit(void)
+{
+       platform_driver_unregister(&gpio_regulator_driver);
+}
+module_exit(gpio_regulator_exit);
+
+MODULE_AUTHOR("Heiko Stuebner <heiko@sntech.de>");
+MODULE_DESCRIPTION("gpio voltage regulator");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:gpio-regulator");
index 30eb9e54f7ec033a8ae7d889a5e42599c47a0a7c..1062cf9f02dc3303a7fae53a23203dd21a7707a8 100644 (file)
@@ -221,7 +221,7 @@ static int max8649_enable_time(struct regulator_dev *rdev)
        ret = (ret & MAX8649_RAMP_MASK) >> 5;
        rate = (32 * 1000) >> ret;      /* uV/uS */
 
-       return (voltage / rate);
+       return DIV_ROUND_UP(voltage, rate);
 }
 
 static int max8649_set_mode(struct regulator_dev *rdev, unsigned int mode)
index 486ed8141fcddc93dc13b7c5f91a58e8fd8baf10..3883d85c5b8864835c41b2b5b74b919696bd02d8 100644 (file)
@@ -26,7 +26,6 @@
 #include <linux/platform_device.h>
 #include <linux/regulator/driver.h>
 #include <linux/regulator/max8952.h>
-#include <linux/mutex.h>
 #include <linux/gpio.h>
 #include <linux/io.h>
 #include <linux/slab.h>
@@ -47,7 +46,6 @@ enum {
 struct max8952_data {
        struct i2c_client       *client;
        struct device           *dev;
-       struct mutex            mutex;
        struct max8952_platform_data *pdata;
        struct regulator_dev    *rdev;
 
@@ -208,7 +206,6 @@ static int __devinit max8952_pmic_probe(struct i2c_client *client,
        max8952->client = client;
        max8952->dev = &client->dev;
        max8952->pdata = pdata;
-       mutex_init(&max8952->mutex);
 
        max8952->rdev = regulator_register(&regulator, max8952->dev,
                        &pdata->reg_data, max8952);
index 701a5900f83f64b6a645bf8d98ae16b0597ead08..9fb4c7b81753d99ff8effaa781f2d8b5930261d8 100644 (file)
 #define TPS65023_REG_CTRL_LDO2_EN      BIT(2)
 #define TPS65023_REG_CTRL_LDO1_EN      BIT(1)
 
+/* REG_CTRL2 bitfields */
+#define TPS65023_REG_CTRL2_GO          BIT(7)
+#define TPS65023_REG_CTRL2_CORE_ADJ    BIT(6)
+#define TPS65023_REG_CTRL2_DCDC2       BIT(2)
+#define TPS65023_REG_CTRL2_DCDC1       BIT(1)
+#define TPS65023_REG_CTRL2_DCDC3       BIT(0)
+
 /* LDO_CTRL bitfields */
 #define TPS65023_LDO_CTRL_LDOx_SHIFT(ldo_id)   ((ldo_id)*4)
 #define TPS65023_LDO_CTRL_LDOx_MASK(ldo_id)    (0xF0 >> ((ldo_id)*4))
@@ -85,7 +92,7 @@
 #define TPS65023_MAX_REG_ID            TPS65023_LDO_2
 
 /* Supported voltage values for regulators */
-static const u16 VDCDC1_VSEL_table[] = {
+static const u16 VCORE_VSEL_table[] = {
        800, 825, 850, 875,
        900, 925, 950, 975,
        1000, 1025, 1050, 1075,
@@ -96,20 +103,29 @@ static const u16 VDCDC1_VSEL_table[] = {
        1500, 1525, 1550, 1600,
 };
 
-static const u16 LDO1_VSEL_table[] = {
+/* Supported voltage values for LDO regulators for tps65020 */
+static const u16 TPS65020_LDO1_VSEL_table[] = {
+       1000, 1050, 1100, 1300,
+       1800, 2500, 3000, 3300,
+};
+
+static const u16 TPS65020_LDO2_VSEL_table[] = {
+       1000, 1050, 1100, 1300,
+       1800, 2500, 3000, 3300,
+};
+
+/* Supported voltage values for LDO regulators
+ * for tps65021 and tps65023 */
+static const u16 TPS65023_LDO1_VSEL_table[] = {
        1000, 1100, 1300, 1800,
        2200, 2600, 2800, 3150,
 };
 
-static const u16 LDO2_VSEL_table[] = {
+static const u16 TPS65023_LDO2_VSEL_table[] = {
        1050, 1200, 1300, 1800,
        2500, 2800, 3000, 3300,
 };
 
-static unsigned int num_voltages[] = {ARRAY_SIZE(VDCDC1_VSEL_table),
-                               0, 0, ARRAY_SIZE(LDO1_VSEL_table),
-                               ARRAY_SIZE(LDO2_VSEL_table)};
-
 /* Regulator specific details */
 struct tps_info {
        const char *name;
@@ -127,6 +143,13 @@ struct tps_pmic {
        struct regulator_dev *rdev[TPS65023_NUM_REGULATOR];
        const struct tps_info *info[TPS65023_NUM_REGULATOR];
        struct regmap *regmap;
+       u8 core_regulator;
+};
+
+/* Struct passed as driver data */
+struct tps_driver_data {
+       const struct tps_info *info;
+       u8 core_regulator;
 };
 
 static int tps_65023_set_bits(struct tps_pmic *tps, u8 reg, u8 mask)
@@ -253,7 +276,7 @@ static int tps65023_dcdc_get_voltage(struct regulator_dev *dev)
        if (dcdc < TPS65023_DCDC_1 || dcdc > TPS65023_DCDC_3)
                return -EINVAL;
 
-       if (dcdc == TPS65023_DCDC_1) {
+       if (dcdc == tps->core_regulator) {
                data = tps_65023_reg_read(tps, TPS65023_REG_DEF_CORE);
                if (data < 0)
                        return data;
@@ -270,10 +293,10 @@ static int tps65023_dcdc_set_voltage(struct regulator_dev *dev,
        struct tps_pmic *tps = rdev_get_drvdata(dev);
        int dcdc = rdev_get_id(dev);
        int vsel;
+       int ret;
 
-       if (dcdc != TPS65023_DCDC_1)
+       if (dcdc != tps->core_regulator)
                return -EINVAL;
-
        if (min_uV < tps->info[dcdc]->min_uV
                        || min_uV > tps->info[dcdc]->max_uV)
                return -EINVAL;
@@ -292,11 +315,21 @@ static int tps65023_dcdc_set_voltage(struct regulator_dev *dev,
 
        *selector = vsel;
 
-       /* write to the register in case we found a match */
        if (vsel == tps->info[dcdc]->table_len)
-               return -EINVAL;
-       else
-               return tps_65023_reg_write(tps, TPS65023_REG_DEF_CORE, vsel);
+               goto failed;
+
+       ret = tps_65023_reg_write(tps, TPS65023_REG_DEF_CORE, vsel);
+
+       /* Tell the chip that we have changed the value in DEFCORE
+        * and its time to update the core voltage
+        */
+       tps_65023_set_bits(tps, TPS65023_REG_CON_CTRL2,
+                                               TPS65023_REG_CTRL2_GO);
+
+       return ret;
+
+failed:
+       return -EINVAL;
 }
 
 static int tps65023_ldo_get_voltage(struct regulator_dev *dev)
@@ -362,7 +395,7 @@ static int tps65023_dcdc_list_voltage(struct regulator_dev *dev,
        if (dcdc < TPS65023_DCDC_1 || dcdc > TPS65023_DCDC_3)
                return -EINVAL;
 
-       if (dcdc == TPS65023_DCDC_1) {
+       if (dcdc == tps->core_regulator) {
                if (selector >= tps->info[dcdc]->table_len)
                        return -EINVAL;
                else
@@ -414,7 +447,8 @@ static struct regmap_config tps65023_regmap_config = {
 static int __devinit tps_65023_probe(struct i2c_client *client,
                                     const struct i2c_device_id *id)
 {
-       const struct tps_info *info = (void *)id->driver_data;
+       const struct tps_driver_data *drv_data = (void *)id->driver_data;
+       const struct tps_info *info = drv_data->info;
        struct regulator_init_data *init_data;
        struct regulator_dev *rdev;
        struct tps_pmic *tps;
@@ -446,6 +480,7 @@ static int __devinit tps_65023_probe(struct i2c_client *client,
 
        /* common for all regulators */
        tps->client = client;
+       tps->core_regulator = drv_data->core_regulator;
 
        for (i = 0; i < TPS65023_NUM_REGULATOR; i++, info++, init_data++) {
                /* Store regulator specific information */
@@ -453,7 +488,7 @@ static int __devinit tps_65023_probe(struct i2c_client *client,
 
                tps->desc[i].name = info->name;
                tps->desc[i].id = i;
-               tps->desc[i].n_voltages = num_voltages[i];
+               tps->desc[i].n_voltages = info->table_len;
                tps->desc[i].ops = (i > TPS65023_DCDC_3 ?
                                        &tps65023_ldo_ops : &tps65023_dcdc_ops);
                tps->desc[i].type = REGULATOR_VOLTAGE;
@@ -475,6 +510,14 @@ static int __devinit tps_65023_probe(struct i2c_client *client,
 
        i2c_set_clientdata(client, tps);
 
+       /* Enable setting output voltage by I2C */
+       tps_65023_clear_bits(tps, TPS65023_REG_CON_CTRL2,
+                                               TPS65023_REG_CTRL2_CORE_ADJ);
+
+       /* Enable setting output voltage by I2C */
+       tps_65023_clear_bits(tps, TPS65023_REG_CON_CTRL2,
+                                               TPS65023_REG_CTRL2_CORE_ADJ);
+
        return 0;
 
  fail:
@@ -507,13 +550,86 @@ static int __devexit tps_65023_remove(struct i2c_client *client)
        return 0;
 }
 
+static const struct tps_info tps65020_regs[] = {
+       {
+               .name = "VDCDC1",
+               .min_uV = 3300000,
+               .max_uV = 3300000,
+               .fixed  = 1,
+       },
+       {
+               .name = "VDCDC2",
+               .min_uV =  1800000,
+               .max_uV = 1800000,
+               .fixed = 1,
+       },
+       {
+               .name = "VDCDC3",
+               .min_uV =  800000,
+               .max_uV = 1600000,
+               .table_len = ARRAY_SIZE(VCORE_VSEL_table),
+               .table = VCORE_VSEL_table,
+       },
+
+       {
+               .name = "LDO1",
+               .min_uV = 1000000,
+               .max_uV = 3150000,
+               .table_len = ARRAY_SIZE(TPS65020_LDO1_VSEL_table),
+               .table = TPS65020_LDO1_VSEL_table,
+       },
+       {
+               .name = "LDO2",
+               .min_uV = 1050000,
+               .max_uV = 3300000,
+               .table_len = ARRAY_SIZE(TPS65020_LDO2_VSEL_table),
+               .table = TPS65020_LDO2_VSEL_table,
+       },
+};
+
+static const struct tps_info tps65021_regs[] = {
+       {
+               .name = "VDCDC1",
+               .min_uV =  3300000,
+               .max_uV = 3300000,
+               .fixed = 1,
+       },
+       {
+               .name = "VDCDC2",
+               .min_uV =  1800000,
+               .max_uV = 1800000,
+               .fixed = 1,
+       },
+       {
+               .name = "VDCDC3",
+               .min_uV =  800000,
+               .max_uV = 1600000,
+               .table_len = ARRAY_SIZE(VCORE_VSEL_table),
+               .table = VCORE_VSEL_table,
+       },
+       {
+               .name = "LDO1",
+               .min_uV = 1000000,
+               .max_uV = 3150000,
+               .table_len = ARRAY_SIZE(TPS65023_LDO1_VSEL_table),
+               .table = TPS65023_LDO1_VSEL_table,
+       },
+       {
+               .name = "LDO2",
+               .min_uV = 1050000,
+               .max_uV = 3300000,
+               .table_len = ARRAY_SIZE(TPS65023_LDO2_VSEL_table),
+               .table = TPS65023_LDO2_VSEL_table,
+       },
+};
+
 static const struct tps_info tps65023_regs[] = {
        {
                .name = "VDCDC1",
                .min_uV =  800000,
                .max_uV = 1600000,
-               .table_len = ARRAY_SIZE(VDCDC1_VSEL_table),
-               .table = VDCDC1_VSEL_table,
+               .table_len = ARRAY_SIZE(VCORE_VSEL_table),
+               .table = VCORE_VSEL_table,
        },
        {
                .name = "VDCDC2",
@@ -531,23 +647,40 @@ static const struct tps_info tps65023_regs[] = {
                .name = "LDO1",
                .min_uV = 1000000,
                .max_uV = 3150000,
-               .table_len = ARRAY_SIZE(LDO1_VSEL_table),
-               .table = LDO1_VSEL_table,
+               .table_len = ARRAY_SIZE(TPS65023_LDO1_VSEL_table),
+               .table = TPS65023_LDO1_VSEL_table,
        },
        {
                .name = "LDO2",
                .min_uV = 1050000,
                .max_uV = 3300000,
-               .table_len = ARRAY_SIZE(LDO2_VSEL_table),
-               .table = LDO2_VSEL_table,
+               .table_len = ARRAY_SIZE(TPS65023_LDO2_VSEL_table),
+               .table = TPS65023_LDO2_VSEL_table,
        },
 };
 
+static struct tps_driver_data tps65020_drv_data = {
+       .info = tps65020_regs,
+       .core_regulator = TPS65023_DCDC_3,
+};
+
+static struct tps_driver_data tps65021_drv_data = {
+               .info = tps65021_regs,
+               .core_regulator = TPS65023_DCDC_3,
+};
+
+static struct tps_driver_data tps65023_drv_data = {
+               .info = tps65023_regs,
+               .core_regulator = TPS65023_DCDC_1,
+};
+
 static const struct i2c_device_id tps_65023_id[] = {
        {.name = "tps65023",
-       .driver_data = (unsigned long) tps65023_regs,},
+       .driver_data = (unsigned long) &tps65023_drv_data},
        {.name = "tps65021",
-       .driver_data = (unsigned long) tps65023_regs,},
+       .driver_data = (unsigned long) &tps65021_drv_data,},
+       {.name = "tps65020",
+       .driver_data = (unsigned long) &tps65020_drv_data},
        { },
 };
 
index bfffabc21edabdffe051466b9d11b9fd60890400..bdef70365f52b5c1c01ae30cd66d194d31c820ac 100644 (file)
@@ -90,12 +90,6 @@ static const u16 LDO2_VSEL_table[] = {
        3000, 3100, 3200, 3300,
 };
 
-static unsigned int num_voltages[] = {ARRAY_SIZE(VDCDCx_VSEL_table),
-                               ARRAY_SIZE(VDCDCx_VSEL_table),
-                               ARRAY_SIZE(VDCDCx_VSEL_table),
-                               ARRAY_SIZE(LDO1_VSEL_table),
-                               ARRAY_SIZE(LDO2_VSEL_table)};
-
 struct tps_info {
        const char *name;
        unsigned min_uV;
@@ -598,7 +592,7 @@ int tps6507x_pmic_probe(struct platform_device *pdev)
 
                tps->desc[i].name = info->name;
                tps->desc[i].id = i;
-               tps->desc[i].n_voltages = num_voltages[i];
+               tps->desc[i].n_voltages = info->table_len;
                tps->desc[i].ops = (i > TPS6507X_DCDC_3 ?
                &tps6507x_pmic_ldo_ops : &tps6507x_pmic_dcdc_ops);
                tps->desc[i].type = REGULATOR_VOLTAGE;
index bb04a75a4c98818665a9e44e077d229b27147d79..dbcf09d5080c654bef77c7b725f12bc88729d45a 100644 (file)
@@ -332,6 +332,36 @@ static inline int tps6586x_regulator_preinit(struct device *parent,
                                 1 << ri->enable_bit[1]);
 }
 
+static int tps6586x_regulator_set_slew_rate(struct platform_device *pdev)
+{
+       struct device *parent = pdev->dev.parent;
+       struct regulator_init_data *p = pdev->dev.platform_data;
+       struct tps6586x_settings *setting = p->driver_data;
+       uint8_t reg;
+
+       if (setting == NULL)
+               return 0;
+
+       if (!(setting->slew_rate & TPS6586X_SLEW_RATE_SET))
+               return 0;
+
+       /* only SM0 and SM1 can have the slew rate settings */
+       switch (pdev->id) {
+       case TPS6586X_ID_SM_0:
+               reg = TPS6586X_SM0SL;
+               break;
+       case TPS6586X_ID_SM_1:
+               reg = TPS6586X_SM1SL;
+               break;
+       default:
+               dev_warn(&pdev->dev, "Only SM0/SM1 can set slew rate\n");
+               return -EINVAL;
+       }
+
+       return tps6586x_write(parent, reg,
+                       setting->slew_rate & TPS6586X_SLEW_RATE_MASK);
+}
+
 static inline struct tps6586x_regulator *find_regulator_info(int id)
 {
        struct tps6586x_regulator *ri;
@@ -374,7 +404,7 @@ static int __devinit tps6586x_regulator_probe(struct platform_device *pdev)
 
        platform_set_drvdata(pdev, rdev);
 
-       return 0;
+       return tps6586x_regulator_set_slew_rate(pdev);
 }
 
 static int __devexit tps6586x_regulator_remove(struct platform_device *pdev)
index 3a9313e00fac796b3d8799c90004a13fd2587142..39d4a1749e71a78b3ad73907e407bb8d02435df3 100644 (file)
@@ -43,8 +43,6 @@
 #define TPS65912_REG_LDO9      12
 #define TPS65912_REG_LDO10     13
 
-#define TPS65912_MAX_REG_ID    TPS65912_REG_LDO_10
-
 /* Number of step-down converters available */
 #define TPS65912_NUM_DCDC      4
 
index 1a6a690f24dbecc415c7c7f9c5006573a767ef0b..b87bf5c841f8216a8867db35b23bab5acd0acce2 100644 (file)
@@ -140,6 +140,14 @@ static int wm8994_ldo2_list_voltage(struct regulator_dev *rdev,
                return (selector * 100000) + 900000;
        case WM8958:
                return (selector * 100000) + 1000000;
+       case WM1811:
+               switch (selector) {
+               case 0:
+                       return -EINVAL;
+               default:
+                       return (selector * 100000) + 950000;
+               }
+               break;
        default:
                return -EINVAL;
        }
@@ -170,6 +178,11 @@ static int wm8994_ldo2_set_voltage(struct regulator_dev *rdev,
        case WM8958:
                selector = (min_uV - 1000000) / 100000;
                break;
+       case WM1811:
+               selector = (min_uV - 950000) / 100000;
+               if (selector == 0)
+                       selector = 1;
+               break;
        default:
                return -EINVAL;
        }
index a1d3ddba99ccad4b90d4a9a06af1fd371b2d0033..65894f05a801d073974ae11a6599b59c45e5daee 100644 (file)
@@ -11,7 +11,6 @@
 #define KMSG_COMPONENT "dasd"
 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
 
-#include <linux/kernel_stat.h>
 #include <linux/kmod.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
@@ -1594,7 +1593,6 @@ void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
        unsigned long long now;
        int expires;
 
-       kstat_cpu(smp_processor_id()).irqs[IOINT_DAS]++;
        if (IS_ERR(irb)) {
                switch (PTR_ERR(irb)) {
                case -EIO:
@@ -2061,13 +2059,14 @@ void dasd_add_request_tail(struct dasd_ccw_req *cqr)
 /*
  * Wakeup helper for the 'sleep_on' functions.
  */
-static void dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
+void dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
 {
        spin_lock_irq(get_ccwdev_lock(cqr->startdev->cdev));
        cqr->callback_data = DASD_SLEEPON_END_TAG;
        spin_unlock_irq(get_ccwdev_lock(cqr->startdev->cdev));
        wake_up(&generic_waitq);
 }
+EXPORT_SYMBOL_GPL(dasd_wakeup_cb);
 
 static inline int _wait_for_wakeup(struct dasd_ccw_req *cqr)
 {
@@ -2167,7 +2166,9 @@ static int _dasd_sleep_on(struct dasd_ccw_req *maincqr, int interruptible)
                } else
                        wait_event(generic_waitq, !(device->stopped));
 
-               cqr->callback = dasd_wakeup_cb;
+               if (!cqr->callback)
+                       cqr->callback = dasd_wakeup_cb;
+
                cqr->callback_data = DASD_SLEEPON_START_TAG;
                dasd_add_request_tail(cqr);
                if (interruptible) {
@@ -2263,7 +2264,11 @@ int dasd_sleep_on_immediatly(struct dasd_ccw_req *cqr)
        cqr->callback = dasd_wakeup_cb;
        cqr->callback_data = DASD_SLEEPON_START_TAG;
        cqr->status = DASD_CQR_QUEUED;
-       list_add(&cqr->devlist, &device->ccw_queue);
+       /*
+        * add new request as second
+        * first the terminated cqr needs to be finished
+        */
+       list_add(&cqr->devlist, device->ccw_queue.next);
 
        /* let the bh start the request to keep them in order */
        dasd_schedule_device_bh(device);
@@ -3284,6 +3289,9 @@ int dasd_generic_pm_freeze(struct ccw_device *cdev)
        if (IS_ERR(device))
                return PTR_ERR(device);
 
+       /* mark device as suspended */
+       set_bit(DASD_FLAG_SUSPENDED, &device->flags);
+
        if (device->discipline->freeze)
                rc = device->discipline->freeze(device);
 
@@ -3358,6 +3366,7 @@ int dasd_generic_restore_device(struct ccw_device *cdev)
        if (device->block)
                dasd_schedule_block_bh(device->block);
 
+       clear_bit(DASD_FLAG_SUSPENDED, &device->flags);
        dasd_put_device(device);
        return 0;
 }
index 6e835c9fdfcba9b5c6e9e501d6921aefa266c012..6ab29680586a150b0f2f25db5176489141dcdfda 100644 (file)
@@ -844,6 +844,30 @@ static void dasd_eckd_fill_rcd_cqr(struct dasd_device *device,
        set_bit(DASD_CQR_VERIFY_PATH, &cqr->flags);
 }
 
+/*
+ * Wakeup helper for read_conf
+ * if the cqr is not done and needs some error recovery
+ * the buffer has to be re-initialized with the EBCDIC "V1.0"
+ * to show support for virtual device SNEQ
+ */
+static void read_conf_cb(struct dasd_ccw_req *cqr, void *data)
+{
+       struct ccw1 *ccw;
+       __u8 *rcd_buffer;
+
+       if (cqr->status !=  DASD_CQR_DONE) {
+               ccw = cqr->cpaddr;
+               rcd_buffer = (__u8 *)((addr_t) ccw->cda);
+               memset(rcd_buffer, 0, sizeof(*rcd_buffer));
+
+               rcd_buffer[0] = 0xE5;
+               rcd_buffer[1] = 0xF1;
+               rcd_buffer[2] = 0x4B;
+               rcd_buffer[3] = 0xF0;
+       }
+       dasd_wakeup_cb(cqr, data);
+}
+
 static int dasd_eckd_read_conf_immediately(struct dasd_device *device,
                                           struct dasd_ccw_req *cqr,
                                           __u8 *rcd_buffer,
@@ -863,6 +887,7 @@ static int dasd_eckd_read_conf_immediately(struct dasd_device *device,
        clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
        set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags);
        cqr->retries = 5;
+       cqr->callback = read_conf_cb;
        rc = dasd_sleep_on_immediatly(cqr);
        return rc;
 }
@@ -900,6 +925,7 @@ static int dasd_eckd_read_conf_lpm(struct dasd_device *device,
                goto out_error;
        }
        dasd_eckd_fill_rcd_cqr(device, cqr, rcd_buf, lpm);
+       cqr->callback = read_conf_cb;
        ret = dasd_sleep_on(cqr);
        /*
         * on success we update the user input parms
@@ -1075,6 +1101,12 @@ static void do_path_verification_work(struct work_struct *work)
        data = container_of(work, struct path_verification_work_data, worker);
        device = data->device;
 
+       /* delay path verification until device was resumed */
+       if (test_bit(DASD_FLAG_SUSPENDED, &device->flags)) {
+               schedule_work(work);
+               return;
+       }
+
        opm = 0;
        npm = 0;
        ppm = 0;
@@ -2021,9 +2053,13 @@ static void dasd_eckd_check_for_device_change(struct dasd_device *device,
        /* first of all check for state change pending interrupt */
        mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
        if ((scsw_dstat(&irb->scsw) & mask) == mask) {
-               /* for alias only and not in offline processing*/
+               /*
+                * for alias only, not in offline processing
+                * and only if not suspended
+                */
                if (!device->block && private->lcu &&
-                   !test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
+                   !test_bit(DASD_FLAG_OFFLINE, &device->flags) &&
+                   !test_bit(DASD_FLAG_SUSPENDED, &device->flags)) {
                        /*
                         * the state change could be caused by an alias
                         * reassignment remove device from alias handling
@@ -2350,7 +2386,7 @@ static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_track(
        new_track = 1;
        end_idaw = 0;
        len_to_track_end = 0;
-       idaw_dst = 0;
+       idaw_dst = NULL;
        idaw_len = 0;
        rq_for_each_segment(bv, req, iter) {
                dst = page_address(bv->bv_page) + bv->bv_offset;
@@ -2412,7 +2448,7 @@ static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_track(
                        if (end_idaw) {
                                idaws = idal_create_words(idaws, idaw_dst,
                                                          idaw_len);
-                               idaw_dst = 0;
+                               idaw_dst = NULL;
                                idaw_len = 0;
                                end_idaw = 0;
                        }
@@ -3998,6 +4034,7 @@ static struct ccw_driver dasd_eckd_driver = {
        .thaw        = dasd_generic_restore_device,
        .restore     = dasd_generic_restore_device,
        .uc_handler  = dasd_generic_uc_handler,
+       .int_class   = IOINT_DAS,
 };
 
 /*
index 4b71b116486838daea8132a832fcaa200f720016..a62a75358eb94ab7686373e7e166628e1eaf2773 100644 (file)
@@ -79,6 +79,7 @@ static struct ccw_driver dasd_fba_driver = {
        .freeze      = dasd_generic_pm_freeze,
        .thaw        = dasd_generic_restore_device,
        .restore     = dasd_generic_restore_device,
+       .int_class   = IOINT_DAS,
 };
 
 static void
index 1dd12bd85a697f673af92726f5ec1ba2347e0416..afe8c33422edae5f6e90ae8afa597f54f0346959 100644 (file)
@@ -516,6 +516,7 @@ struct dasd_block {
                                         */
 #define DASD_FLAG_IS_RESERVED  7       /* The device is reserved */
 #define DASD_FLAG_LOCK_STOLEN  8       /* The device lock was stolen */
+#define DASD_FLAG_SUSPENDED    9       /* The device was suspended */
 
 
 void dasd_put_device_wake(struct dasd_device *);
@@ -643,6 +644,7 @@ struct dasd_ccw_req *
 dasd_smalloc_request(int , int, int, struct dasd_device *);
 void dasd_kfree_request(struct dasd_ccw_req *, struct dasd_device *);
 void dasd_sfree_request(struct dasd_ccw_req *, struct dasd_device *);
+void dasd_wakeup_cb(struct dasd_ccw_req *, void *);
 
 static inline int
 dasd_kmalloc_set_cda(struct ccw1 *ccw, void *cda, struct dasd_device *device)
index 694464c65fcdaaddd5c7c2b09514ca822e1606af..934458ad55e51782c7b595b48c5f3088393b8495 100644 (file)
@@ -9,7 +9,6 @@
  *           Dan Morrison, IBM Corporation <dmorriso@cse.buffalo.edu>
  */
 
-#include <linux/kernel_stat.h>
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/kdev_t.h>
@@ -362,7 +361,6 @@ static void raw3215_irq(struct ccw_device *cdev, unsigned long intparm,
        int cstat, dstat;
        int count;
 
-       kstat_cpu(smp_processor_id()).irqs[IOINT_C15]++;
        raw = dev_get_drvdata(&cdev->dev);
        req = (struct raw3215_req *) intparm;
        cstat = irb->scsw.cmd.cstat;
@@ -776,6 +774,7 @@ static struct ccw_driver raw3215_ccw_driver = {
        .freeze         = &raw3215_pm_stop,
        .thaw           = &raw3215_pm_start,
        .restore        = &raw3215_pm_start,
+       .int_class      = IOINT_C15,
 };
 
 #ifdef CONFIG_TN3215_CONSOLE
index 810ac38631c35ac919ba7fb110c80d38d75b260f..e5cb9248a442a5d67f574302aa76aa8904d1812a 100644 (file)
@@ -7,7 +7,6 @@
  *     Copyright IBM Corp. 2003, 2009
  */
 
-#include <linux/kernel_stat.h>
 #include <linux/module.h>
 #include <linux/err.h>
 #include <linux/init.h>
@@ -330,7 +329,6 @@ raw3270_irq (struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
        struct raw3270_request *rq;
        int rc;
 
-       kstat_cpu(smp_processor_id()).irqs[IOINT_C70]++;
        rp = dev_get_drvdata(&cdev->dev);
        if (!rp)
                return;
@@ -1398,6 +1396,7 @@ static struct ccw_driver raw3270_ccw_driver = {
        .freeze         = &raw3270_pm_stop,
        .thaw           = &raw3270_pm_start,
        .restore        = &raw3270_pm_start,
+       .int_class      = IOINT_C70,
 };
 
 static int
index 837e010299a894f4f249fc6c0707a95634146598..0b54a91f8dcd2aa23d23634910fb92a683cea949 100644 (file)
@@ -61,8 +61,8 @@ static int __init sclp_cmd_sync_early(sclp_cmdw_t cmd, void *sccb)
        rc = sclp_service_call(cmd, sccb);
        if (rc)
                goto out;
-       __load_psw_mask(PSW_BASE_BITS | PSW_MASK_EXT |
-                       PSW_MASK_WAIT | PSW_DEFAULT_KEY);
+       __load_psw_mask(PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_MASK_EA |
+                       PSW_MASK_BA | PSW_MASK_EXT | PSW_MASK_WAIT);
        local_irq_disable();
 out:
        /* Contents of the sccb might have changed. */
index a90a02c28d6a1d2c75ecbb6d287e82950fe1785d..87fc0ac11e6766b16e3c4386010afe4cdabe67d2 100644 (file)
@@ -30,7 +30,8 @@ static void do_machine_quiesce(void)
        psw_t quiesce_psw;
 
        smp_send_stop();
-       quiesce_psw.mask = PSW_BASE_BITS | PSW_MASK_WAIT;
+       quiesce_psw.mask =
+               PSW_MASK_BASE | PSW_MASK_EA | PSW_MASK_BA | PSW_MASK_WAIT;
        quiesce_psw.addr = 0xfff;
        __load_psw(quiesce_psw);
 }
index 9eff2df70ddb2e579c0e2ff3472278df080178d2..934ef33eb9a478bf357341100468e89183e88429 100644 (file)
@@ -1330,6 +1330,7 @@ static struct ccw_driver tape_34xx_driver = {
        .set_online = tape_34xx_online,
        .set_offline = tape_generic_offline,
        .freeze = tape_generic_pm_suspend,
+       .int_class = IOINT_TAP,
 };
 
 static int
index a7d570728882cae1ce2443baa44044e1f824f00e..49c6aab7ad788d6bd9c3090af9d0931922f2c2e2 100644 (file)
@@ -1762,6 +1762,7 @@ static struct ccw_driver tape_3590_driver = {
        .set_offline = tape_generic_offline,
        .set_online = tape_3590_online,
        .freeze = tape_generic_pm_suspend,
+       .int_class = IOINT_TAP,
 };
 
 /*
index 7978a0adeaf3cd2781216d5c2d0fb13724282506..b3a3e8e8656e6db1be5e3a50b63056c43f0897f6 100644 (file)
@@ -14,7 +14,6 @@
 #define KMSG_COMPONENT "tape"
 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
 
-#include <linux/kernel_stat.h>
 #include <linux/module.h>
 #include <linux/init.h>             // for kernel parameters
 #include <linux/kmod.h>             // for requesting modules
@@ -1115,7 +1114,6 @@ __tape_do_irq (struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
        struct tape_request *request;
        int rc;
 
-       kstat_cpu(smp_processor_id()).irqs[IOINT_TAP]++;
        device = dev_get_drvdata(&cdev->dev);
        if (device == NULL) {
                return;
index f6b00c3df425d192da15790e75f16f6a6af09fb2..d291a54acfad5f94ec127cfdbff6e37d5b8cf85d 100644 (file)
@@ -11,7 +11,6 @@
 #define KMSG_COMPONENT "vmur"
 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
 
-#include <linux/kernel_stat.h>
 #include <linux/cdev.h>
 #include <linux/slab.h>
 
@@ -74,6 +73,7 @@ static struct ccw_driver ur_driver = {
        .set_online     = ur_set_online,
        .set_offline    = ur_set_offline,
        .freeze         = ur_pm_suspend,
+       .int_class      = IOINT_VMR,
 };
 
 static DEFINE_MUTEX(vmur_mutex);
@@ -305,7 +305,6 @@ static void ur_int_handler(struct ccw_device *cdev, unsigned long intparm,
 {
        struct urdev *urd;
 
-       kstat_cpu(smp_processor_id()).irqs[IOINT_VMR]++;
        TRACE("ur_int_handler: intparm=0x%lx cstat=%02x dstat=%02x res=%u\n",
              intparm, irb->scsw.cmd.cstat, irb->scsw.cmd.dstat,
              irb->scsw.cmd.count);
index 3b94044027c2c0229df51a7c6e05f4519eb00df6..43068fbd0baacfe8beb7d353cda35a8c06c371e2 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/slab.h>
 #include <linux/miscdevice.h>
 #include <linux/debugfs.h>
+#include <linux/module.h>
 #include <asm/asm-offsets.h>
 #include <asm/ipl.h>
 #include <asm/sclp.h>
@@ -142,22 +143,6 @@ static int memcpy_hsa_kernel(void *dest, unsigned long src, size_t count)
        return memcpy_hsa(dest, src, count, TO_KERNEL);
 }
 
-static int memcpy_real_user(void __user *dest, unsigned long src, size_t count)
-{
-       static char buf[4096];
-       int offs = 0, size;
-
-       while (offs < count) {
-               size = min(sizeof(buf), count - offs);
-               if (memcpy_real(buf, (void *) src + offs, size))
-                       return -EFAULT;
-               if (copy_to_user(dest + offs, buf, size))
-                       return -EFAULT;
-               offs += size;
-       }
-       return 0;
-}
-
 static int __init init_cpu_info(enum arch_id arch)
 {
        struct save_area *sa;
@@ -346,8 +331,8 @@ static ssize_t zcore_read(struct file *file, char __user *buf, size_t count,
 
        /* Copy from real mem */
        size = count - mem_offs - hdr_count;
-       rc = memcpy_real_user(buf + hdr_count + mem_offs, mem_start + mem_offs,
-                             size);
+       rc = copy_to_user_real(buf + hdr_count + mem_offs,
+                              (void *) mem_start + mem_offs, size);
        if (rc)
                goto fail;
 
index 5c567414c4bb81ee74250b01a4755d8c30da3dbc..4f1989d27b1f4b4163b4c03f5ffa8ae895d88eb7 100644 (file)
 
 /* a device matches a driver if all its slave devices match the same
  * entry of the driver */
-static int
-ccwgroup_bus_match (struct device * dev, struct device_driver * drv)
+static int ccwgroup_bus_match(struct device *dev, struct device_driver * drv)
 {
-       struct ccwgroup_device *gdev;
-       struct ccwgroup_driver *gdrv;
-
-       gdev = to_ccwgroupdev(dev);
-       gdrv = to_ccwgroupdrv(drv);
+       struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
+       struct ccwgroup_driver *gdrv = to_ccwgroupdrv(drv);
 
        if (gdev->creator_id == gdrv->driver_id)
                return 1;
 
        return 0;
 }
-static int
-ccwgroup_uevent (struct device *dev, struct kobj_uevent_env *env)
-{
-       /* TODO */
-       return 0;
-}
 
 static struct bus_type ccwgroup_bus_type;
 
-static void
-__ccwgroup_remove_symlinks(struct ccwgroup_device *gdev)
+static void __ccwgroup_remove_symlinks(struct ccwgroup_device *gdev)
 {
        int i;
        char str[8];
@@ -63,7 +52,6 @@ __ccwgroup_remove_symlinks(struct ccwgroup_device *gdev)
                sysfs_remove_link(&gdev->dev.kobj, str);
                sysfs_remove_link(&gdev->cdev[i]->dev.kobj, "group_device");
        }
-       
 }
 
 /*
@@ -87,6 +75,87 @@ static void __ccwgroup_remove_cdev_refs(struct ccwgroup_device *gdev)
        }
 }
 
+static int ccwgroup_set_online(struct ccwgroup_device *gdev)
+{
+       struct ccwgroup_driver *gdrv = to_ccwgroupdrv(gdev->dev.driver);
+       int ret = 0;
+
+       if (atomic_cmpxchg(&gdev->onoff, 0, 1) != 0)
+               return -EAGAIN;
+       if (gdev->state == CCWGROUP_ONLINE)
+               goto out;
+       if (gdrv->set_online)
+               ret = gdrv->set_online(gdev);
+       if (ret)
+               goto out;
+
+       gdev->state = CCWGROUP_ONLINE;
+out:
+       atomic_set(&gdev->onoff, 0);
+       return ret;
+}
+
+static int ccwgroup_set_offline(struct ccwgroup_device *gdev)
+{
+       struct ccwgroup_driver *gdrv = to_ccwgroupdrv(gdev->dev.driver);
+       int ret = 0;
+
+       if (atomic_cmpxchg(&gdev->onoff, 0, 1) != 0)
+               return -EAGAIN;
+       if (gdev->state == CCWGROUP_OFFLINE)
+               goto out;
+       if (gdrv->set_offline)
+               ret = gdrv->set_offline(gdev);
+       if (ret)
+               goto out;
+
+       gdev->state = CCWGROUP_OFFLINE;
+out:
+       atomic_set(&gdev->onoff, 0);
+       return ret;
+}
+
+static ssize_t ccwgroup_online_store(struct device *dev,
+                                    struct device_attribute *attr,
+                                    const char *buf, size_t count)
+{
+       struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
+       struct ccwgroup_driver *gdrv = to_ccwgroupdrv(dev->driver);
+       unsigned long value;
+       int ret;
+
+       if (!dev->driver)
+               return -EINVAL;
+       if (!try_module_get(gdrv->driver.owner))
+               return -EINVAL;
+
+       ret = strict_strtoul(buf, 0, &value);
+       if (ret)
+               goto out;
+
+       if (value == 1)
+               ret = ccwgroup_set_online(gdev);
+       else if (value == 0)
+               ret = ccwgroup_set_offline(gdev);
+       else
+               ret = -EINVAL;
+out:
+       module_put(gdrv->driver.owner);
+       return (ret == 0) ? count : ret;
+}
+
+static ssize_t ccwgroup_online_show(struct device *dev,
+                                   struct device_attribute *attr,
+                                   char *buf)
+{
+       struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
+       int online;
+
+       online = (gdev->state == CCWGROUP_ONLINE) ? 1 : 0;
+
+       return scnprintf(buf, PAGE_SIZE, "%d\n", online);
+}
+
 /*
  * Provide an 'ungroup' attribute so the user can remove group devices no
  * longer needed or accidentially created. Saves memory :)
@@ -104,14 +173,13 @@ static void ccwgroup_ungroup_callback(struct device *dev)
        mutex_unlock(&gdev->reg_mutex);
 }
 
-static ssize_t
-ccwgroup_ungroup_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
+static ssize_t ccwgroup_ungroup_store(struct device *dev,
+                                     struct device_attribute *attr,
+                                     const char *buf, size_t count)
 {
-       struct ccwgroup_device *gdev;
+       struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
        int rc;
 
-       gdev = to_ccwgroupdev(dev);
-
        /* Prevent concurrent online/offline processing and ungrouping. */
        if (atomic_cmpxchg(&gdev->onoff, 0, 1) != 0)
                return -EAGAIN;
@@ -132,24 +200,35 @@ out:
        }
        return count;
 }
-
 static DEVICE_ATTR(ungroup, 0200, NULL, ccwgroup_ungroup_store);
+static DEVICE_ATTR(online, 0644, ccwgroup_online_show, ccwgroup_online_store);
 
-static void
-ccwgroup_release (struct device *dev)
+static struct attribute *ccwgroup_attrs[] = {
+       &dev_attr_online.attr,
+       &dev_attr_ungroup.attr,
+       NULL,
+};
+static struct attribute_group ccwgroup_attr_group = {
+       .attrs = ccwgroup_attrs,
+};
+static const struct attribute_group *ccwgroup_attr_groups[] = {
+       &ccwgroup_attr_group,
+       NULL,
+};
+
+static void ccwgroup_release(struct device *dev)
 {
        kfree(to_ccwgroupdev(dev));
 }
 
-static int
-__ccwgroup_create_symlinks(struct ccwgroup_device *gdev)
+static int __ccwgroup_create_symlinks(struct ccwgroup_device *gdev)
 {
        char str[8];
        int i, rc;
 
        for (i = 0; i < gdev->count; i++) {
-               rc = sysfs_create_link(&gdev->cdev[i]->dev.kobj, &gdev->dev.kobj,
-                                      "group_device");
+               rc = sysfs_create_link(&gdev->cdev[i]->dev.kobj,
+                                      &gdev->dev.kobj, "group_device");
                if (rc) {
                        for (--i; i >= 0; i--)
                                sysfs_remove_link(&gdev->cdev[i]->dev.kobj,
@@ -159,8 +238,8 @@ __ccwgroup_create_symlinks(struct ccwgroup_device *gdev)
        }
        for (i = 0; i < gdev->count; i++) {
                sprintf(str, "cdev%d", i);
-               rc = sysfs_create_link(&gdev->dev.kobj, &gdev->cdev[i]->dev.kobj,
-                                      str);
+               rc = sysfs_create_link(&gdev->dev.kobj,
+                                      &gdev->cdev[i]->dev.kobj, str);
                if (rc) {
                        for (--i; i >= 0; i--) {
                                sprintf(str, "cdev%d", i);
@@ -293,26 +372,17 @@ int ccwgroup_create_from_string(struct device *root, unsigned int creator_id,
        }
 
        dev_set_name(&gdev->dev, "%s", dev_name(&gdev->cdev[0]->dev));
-
+       gdev->dev.groups = ccwgroup_attr_groups;
        rc = device_add(&gdev->dev);
        if (rc)
                goto error;
-       get_device(&gdev->dev);
-       rc = device_create_file(&gdev->dev, &dev_attr_ungroup);
-
+       rc = __ccwgroup_create_symlinks(gdev);
        if (rc) {
-               device_unregister(&gdev->dev);
+               device_del(&gdev->dev);
                goto error;
        }
-
-       rc = __ccwgroup_create_symlinks(gdev);
-       if (!rc) {
-               mutex_unlock(&gdev->reg_mutex);
-               put_device(&gdev->dev);
-               return 0;
-       }
-       device_remove_file(&gdev->dev, &dev_attr_ungroup);
-       device_unregister(&gdev->dev);
+       mutex_unlock(&gdev->reg_mutex);
+       return 0;
 error:
        for (i = 0; i < num_devices; i++)
                if (gdev->cdev[i]) {
@@ -330,7 +400,15 @@ error:
 EXPORT_SYMBOL(ccwgroup_create_from_string);
 
 static int ccwgroup_notifier(struct notifier_block *nb, unsigned long action,
-                            void *data);
+                            void *data)
+{
+       struct device *dev = data;
+
+       if (action == BUS_NOTIFY_UNBIND_DRIVER)
+               device_schedule_callback(dev, ccwgroup_ungroup_callback);
+
+       return NOTIFY_OK;
+}
 
 static struct notifier_block ccwgroup_nb = {
        .notifier_call = ccwgroup_notifier
@@ -362,138 +440,21 @@ module_exit(cleanup_ccwgroup);
 
 /************************** driver stuff ******************************/
 
-static int
-ccwgroup_set_online(struct ccwgroup_device *gdev)
+static int ccwgroup_probe(struct device *dev)
 {
-       struct ccwgroup_driver *gdrv;
-       int ret;
-
-       if (atomic_cmpxchg(&gdev->onoff, 0, 1) != 0)
-               return -EAGAIN;
-       if (gdev->state == CCWGROUP_ONLINE) {
-               ret = 0;
-               goto out;
-       }
-       if (!gdev->dev.driver) {
-               ret = -EINVAL;
-               goto out;
-       }
-       gdrv = to_ccwgroupdrv (gdev->dev.driver);
-       if ((ret = gdrv->set_online ? gdrv->set_online(gdev) : 0))
-               goto out;
-
-       gdev->state = CCWGROUP_ONLINE;
- out:
-       atomic_set(&gdev->onoff, 0);
-       return ret;
-}
-
-static int
-ccwgroup_set_offline(struct ccwgroup_device *gdev)
-{
-       struct ccwgroup_driver *gdrv;
-       int ret;
-
-       if (atomic_cmpxchg(&gdev->onoff, 0, 1) != 0)
-               return -EAGAIN;
-       if (gdev->state == CCWGROUP_OFFLINE) {
-               ret = 0;
-               goto out;
-       }
-       if (!gdev->dev.driver) {
-               ret = -EINVAL;
-               goto out;
-       }
-       gdrv = to_ccwgroupdrv (gdev->dev.driver);
-       if ((ret = gdrv->set_offline ? gdrv->set_offline(gdev) : 0))
-               goto out;
-
-       gdev->state = CCWGROUP_OFFLINE;
- out:
-       atomic_set(&gdev->onoff, 0);
-       return ret;
-}
-
-static ssize_t
-ccwgroup_online_store (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
-{
-       struct ccwgroup_device *gdev;
-       struct ccwgroup_driver *gdrv;
-       unsigned long value;
-       int ret;
-
-       if (!dev->driver)
-               return -ENODEV;
-
-       gdev = to_ccwgroupdev(dev);
-       gdrv = to_ccwgroupdrv(dev->driver);
-
-       if (!try_module_get(gdrv->driver.owner))
-               return -EINVAL;
-
-       ret = strict_strtoul(buf, 0, &value);
-       if (ret)
-               goto out;
-
-       if (value == 1)
-               ret = ccwgroup_set_online(gdev);
-       else if (value == 0)
-               ret = ccwgroup_set_offline(gdev);
-       else
-               ret = -EINVAL;
-out:
-       module_put(gdrv->driver.owner);
-       return (ret == 0) ? count : ret;
-}
-
-static ssize_t
-ccwgroup_online_show (struct device *dev, struct device_attribute *attr, char *buf)
-{
-       int online;
-
-       online = (to_ccwgroupdev(dev)->state == CCWGROUP_ONLINE);
-
-       return sprintf(buf, online ? "1\n" : "0\n");
-}
-
-static DEVICE_ATTR(online, 0644, ccwgroup_online_show, ccwgroup_online_store);
-
-static int
-ccwgroup_probe (struct device *dev)
-{
-       struct ccwgroup_device *gdev;
-       struct ccwgroup_driver *gdrv;
-
-       int ret;
-
-       gdev = to_ccwgroupdev(dev);
-       gdrv = to_ccwgroupdrv(dev->driver);
-
-       if ((ret = device_create_file(dev, &dev_attr_online)))
-               return ret;
-
-       ret = gdrv->probe ? gdrv->probe(gdev) : -ENODEV;
-       if (ret)
-               device_remove_file(dev, &dev_attr_online);
+       struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
+       struct ccwgroup_driver *gdrv = to_ccwgroupdrv(dev->driver);
 
-       return ret;
+       return gdrv->probe ? gdrv->probe(gdev) : -ENODEV;
 }
 
-static int
-ccwgroup_remove (struct device *dev)
+static int ccwgroup_remove(struct device *dev)
 {
-       struct ccwgroup_device *gdev;
-       struct ccwgroup_driver *gdrv;
-
-       device_remove_file(dev, &dev_attr_online);
-       device_remove_file(dev, &dev_attr_ungroup);
+       struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
+       struct ccwgroup_driver *gdrv = to_ccwgroupdrv(dev->driver);
 
        if (!dev->driver)
                return 0;
-
-       gdev = to_ccwgroupdev(dev);
-       gdrv = to_ccwgroupdrv(dev->driver);
-
        if (gdrv->remove)
                gdrv->remove(gdev);
 
@@ -502,15 +463,11 @@ ccwgroup_remove (struct device *dev)
 
 static void ccwgroup_shutdown(struct device *dev)
 {
-       struct ccwgroup_device *gdev;
-       struct ccwgroup_driver *gdrv;
+       struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
+       struct ccwgroup_driver *gdrv = to_ccwgroupdrv(dev->driver);
 
        if (!dev->driver)
                return;
-
-       gdev = to_ccwgroupdev(dev);
-       gdrv = to_ccwgroupdrv(dev->driver);
-
        if (gdrv->shutdown)
                gdrv->shutdown(gdev);
 }
@@ -586,26 +543,12 @@ static const struct dev_pm_ops ccwgroup_pm_ops = {
 static struct bus_type ccwgroup_bus_type = {
        .name   = "ccwgroup",
        .match  = ccwgroup_bus_match,
-       .uevent = ccwgroup_uevent,
        .probe  = ccwgroup_probe,
        .remove = ccwgroup_remove,
        .shutdown = ccwgroup_shutdown,
        .pm = &ccwgroup_pm_ops,
 };
 
-
-static int ccwgroup_notifier(struct notifier_block *nb, unsigned long action,
-                            void *data)
-{
-       struct device *dev = data;
-
-       if (action == BUS_NOTIFY_UNBIND_DRIVER)
-               device_schedule_callback(dev, ccwgroup_ungroup_callback);
-
-       return NOTIFY_OK;
-}
-
-
 /**
  * ccwgroup_driver_register() - register a ccw group driver
  * @cdriver: driver to be registered
@@ -619,9 +562,9 @@ int ccwgroup_driver_register(struct ccwgroup_driver *cdriver)
 
        return driver_register(&cdriver->driver);
 }
+EXPORT_SYMBOL(ccwgroup_driver_register);
 
-static int
-__ccwgroup_match_all(struct device *dev, void *data)
+static int __ccwgroup_match_all(struct device *dev, void *data)
 {
        return 1;
 }
@@ -652,6 +595,7 @@ void ccwgroup_driver_unregister(struct ccwgroup_driver *cdriver)
        put_driver(&cdriver->driver);
        driver_unregister(&cdriver->driver);
 }
+EXPORT_SYMBOL(ccwgroup_driver_unregister);
 
 /**
  * ccwgroup_probe_ccwdev() - probe function for slave devices
@@ -666,6 +610,7 @@ int ccwgroup_probe_ccwdev(struct ccw_device *cdev)
 {
        return 0;
 }
+EXPORT_SYMBOL(ccwgroup_probe_ccwdev);
 
 /**
  * ccwgroup_remove_ccwdev() - remove function for slave devices
@@ -702,9 +647,5 @@ void ccwgroup_remove_ccwdev(struct ccw_device *cdev)
        /* Release ccwgroup device reference for local processing. */
        put_device(&gdev->dev);
 }
-
-MODULE_LICENSE("GPL");
-EXPORT_SYMBOL(ccwgroup_driver_register);
-EXPORT_SYMBOL(ccwgroup_driver_unregister);
-EXPORT_SYMBOL(ccwgroup_probe_ccwdev);
 EXPORT_SYMBOL(ccwgroup_remove_ccwdev);
+MODULE_LICENSE("GPL");
index d15f8b4d78bd5f67476dafd0d6e320093a75d59c..5156264d0c745f6321ba00616bbb7ea1a8f853f3 100644 (file)
@@ -1,10 +1,13 @@
 /*
  *  Handling of internal CCW device requests.
  *
- *    Copyright IBM Corp. 2009
+ *    Copyright IBM Corp. 2009, 2011
  *    Author(s): Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
  */
 
+#define KMSG_COMPONENT "cio"
+#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
+
 #include <linux/types.h>
 #include <linux/err.h>
 #include <asm/ccwdev.h>
@@ -323,7 +326,21 @@ void ccw_request_timeout(struct ccw_device *cdev)
 {
        struct subchannel *sch = to_subchannel(cdev->dev.parent);
        struct ccw_request *req = &cdev->private->req;
-       int rc;
+       int rc = -ENODEV, chp;
+
+       if (cio_update_schib(sch))
+               goto err;
+
+       for (chp = 0; chp < 8; chp++) {
+               if ((0x80 >> chp) & sch->schib.pmcw.lpum)
+                       pr_warning("%s: No interrupt was received within %lus "
+                                  "(CS=%02x, DS=%02x, CHPID=%x.%02x)\n",
+                                  dev_name(&cdev->dev), req->timeout / HZ,
+                                  scsw_cstat(&sch->schib.scsw),
+                                  scsw_dstat(&sch->schib.scsw),
+                                  sch->schid.cssid,
+                                  sch->schib.pmcw.chpid[chp]);
+       }
 
        if (!ccwreq_next_path(cdev)) {
                /* set the final return code for this request */
@@ -342,7 +359,7 @@ err:
  * ccw_request_notoper - notoper handler for I/O request procedure
  * @cdev: ccw device
  *
- * Handle timeout during I/O request procedure.
+ * Handle notoper during I/O request procedure.
  */
 void ccw_request_notoper(struct ccw_device *cdev)
 {
index e950f1ad4dd121934551c02673801aa3fa82daa5..0c87b0fc7714b42f3dedec1e1adc1035c2f96877 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Driver for s390 chsc subchannels
  *
- * Copyright IBM Corp. 2008, 2009
+ * Copyright IBM Corp. 2008, 2011
  *
  * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
  *
@@ -12,6 +12,7 @@
 #include <linux/module.h>
 #include <linux/uaccess.h>
 #include <linux/miscdevice.h>
+#include <linux/kernel_stat.h>
 
 #include <asm/compat.h>
 #include <asm/cio.h>
@@ -56,6 +57,8 @@ static void chsc_subchannel_irq(struct subchannel *sch)
 
        CHSC_LOG(4, "irb");
        CHSC_LOG_HEX(4, irb, sizeof(*irb));
+       kstat_cpu(smp_processor_id()).irqs[IOINT_CSC]++;
+
        /* Copy irb to provided request and set done. */
        if (!request) {
                CHSC_MSG(0, "Interrupt on sch 0.%x.%04x with no request\n",
index eb3140ee821eaab07fe43a2eb079909c11f3e362..dc67c397449e529f7cb377f776df6784d72944c1 100644 (file)
@@ -622,6 +622,7 @@ void __irq_entry do_IRQ(struct pt_regs *regs)
                sch = (struct subchannel *)(unsigned long)tpi_info->intparm;
                if (!sch) {
                        /* Clear pending interrupt condition. */
+                       kstat_cpu(smp_processor_id()).irqs[IOINT_CIO]++;
                        tsch(tpi_info->schid, irb);
                        continue;
                }
@@ -634,7 +635,10 @@ void __irq_entry do_IRQ(struct pt_regs *regs)
                        /* Call interrupt handler if there is one. */
                        if (sch->driver && sch->driver->irq)
                                sch->driver->irq(sch);
-               }
+                       else
+                               kstat_cpu(smp_processor_id()).irqs[IOINT_CIO]++;
+               } else
+                       kstat_cpu(smp_processor_id()).irqs[IOINT_CIO]++;
                spin_unlock(sch->lock);
                /*
                 * Are more interrupts pending?
@@ -667,18 +671,23 @@ static int cio_tpi(void)
        tpi_info = (struct tpi_info *)&S390_lowcore.subchannel_id;
        if (tpi(NULL) != 1)
                return 0;
+       kstat_cpu(smp_processor_id()).irqs[IO_INTERRUPT]++;
        if (tpi_info->adapter_IO) {
                do_adapter_IO(tpi_info->isc);
                return 1;
        }
        irb = (struct irb *)&S390_lowcore.irb;
        /* Store interrupt response block to lowcore. */
-       if (tsch(tpi_info->schid, irb) != 0)
+       if (tsch(tpi_info->schid, irb) != 0) {
                /* Not status pending or not operational. */
+               kstat_cpu(smp_processor_id()).irqs[IOINT_CIO]++;
                return 1;
+       }
        sch = (struct subchannel *)(unsigned long)tpi_info->intparm;
-       if (!sch)
+       if (!sch) {
+               kstat_cpu(smp_processor_id()).irqs[IOINT_CIO]++;
                return 1;
+       }
        irq_context = in_interrupt();
        if (!irq_context)
                local_bh_disable();
@@ -687,6 +696,8 @@ static int cio_tpi(void)
        memcpy(&sch->schib.scsw, &irb->scsw, sizeof(union scsw));
        if (sch->driver && sch->driver->irq)
                sch->driver->irq(sch);
+       else
+               kstat_cpu(smp_processor_id()).irqs[IOINT_CIO]++;
        spin_unlock(sch->lock);
        irq_exit();
        if (!irq_context)
@@ -1058,7 +1069,7 @@ void reipl_ccw_dev(struct ccw_dev_id *devid)
 {
        struct subchannel_id schid;
 
-       s390_reset_system();
+       s390_reset_system(NULL, NULL);
        if (reipl_find_schid(devid, &schid) != 0)
                panic("IPL Device not found\n");
        do_reipl_asm(*((__u32*)&schid));
index 80ebdddf7747a4b24c7ab4d07b1f952a3a257e39..33bb4d891e161174d01b8f6e0d6433883d5fb495 100644 (file)
@@ -133,6 +133,8 @@ struct channel_subsystem {
 
 extern struct channel_subsystem *channel_subsystems[];
 
+void channel_subsystem_reinit(void);
+
 /* Helper functions to build lists for the slow path. */
 void css_schedule_eval(struct subchannel_id schid);
 void css_schedule_eval_all(void);
index 8e04c00cf0ad10d522128b97e33cefcf3b870adf..d734f4a0ecac23cea1d821b316a563b71087ccc6 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/device.h>
 #include <linux/workqueue.h>
 #include <linux/timer.h>
+#include <linux/kernel_stat.h>
 
 #include <asm/ccwdev.h>
 #include <asm/cio.h>
@@ -747,6 +748,7 @@ static int io_subchannel_initialize_dev(struct subchannel *sch,
                                        struct ccw_device *cdev)
 {
        cdev->private->cdev = cdev;
+       cdev->private->int_class = IOINT_CIO;
        atomic_set(&cdev->private->onoff, 0);
        cdev->dev.parent = &sch->dev;
        cdev->dev.release = ccw_device_release;
@@ -1010,6 +1012,8 @@ static void io_subchannel_irq(struct subchannel *sch)
        CIO_TRACE_EVENT(6, dev_name(&sch->dev));
        if (cdev)
                dev_fsm_event(cdev, DEV_EVENT_INTERRUPT);
+       else
+               kstat_cpu(smp_processor_id()).irqs[IOINT_CIO]++;
 }
 
 void io_subchannel_init_config(struct subchannel *sch)
@@ -1621,6 +1625,7 @@ ccw_device_probe_console(void)
        memset(&console_private, 0, sizeof(struct ccw_device_private));
        console_cdev.private = &console_private;
        console_private.cdev = &console_cdev;
+       console_private.int_class = IOINT_CIO;
        ret = ccw_device_console_enable(&console_cdev, sch);
        if (ret) {
                cio_release_console();
@@ -1702,11 +1707,18 @@ ccw_device_probe (struct device *dev)
        int ret;
 
        cdev->drv = cdrv; /* to let the driver call _set_online */
+       /* Note: we interpret class 0 in this context as an uninitialized
+        * field since it translates to a non-I/O interrupt class. */
+       if (cdrv->int_class != 0)
+               cdev->private->int_class = cdrv->int_class;
+       else
+               cdev->private->int_class = IOINT_CIO;
 
        ret = cdrv->probe ? cdrv->probe(cdev) : -ENODEV;
 
        if (ret) {
                cdev->drv = NULL;
+               cdev->private->int_class = IOINT_CIO;
                return ret;
        }
 
@@ -1740,6 +1752,7 @@ ccw_device_remove (struct device *dev)
        }
        ccw_device_set_timeout(cdev, 0);
        cdev->drv = NULL;
+       cdev->private->int_class = IOINT_CIO;
        return 0;
 }
 
index 0b7245c72d5e290aeda9cd16ab1fabb681f784b2..179824b3082f731412b428e46fb71a8d1a912788 100644 (file)
@@ -5,6 +5,7 @@
 #include <linux/atomic.h>
 #include <linux/wait.h>
 #include <linux/notifier.h>
+#include <linux/kernel_stat.h>
 #include "io_sch.h"
 
 /*
@@ -56,7 +57,17 @@ extern fsm_func_t *dev_jumptable[NR_DEV_STATES][NR_DEV_EVENTS];
 static inline void
 dev_fsm_event(struct ccw_device *cdev, enum dev_event dev_event)
 {
-       dev_jumptable[cdev->private->state][dev_event](cdev, dev_event);
+       int state = cdev->private->state;
+
+       if (dev_event == DEV_EVENT_INTERRUPT) {
+               if (state == DEV_STATE_ONLINE)
+                       kstat_cpu(smp_processor_id()).
+                               irqs[cdev->private->int_class]++;
+               else if (state != DEV_STATE_CMFCHANGE &&
+                        state != DEV_STATE_CMFUPDATE)
+                       kstat_cpu(smp_processor_id()).irqs[IOINT_CIO]++;
+       }
+       dev_jumptable[state][dev_event](cdev, dev_event);
 }
 
 /*
index ba31ad88f4f7e3edf4d255e49ee8b457767beb0d..2ebb492a5c17dcb8a9e05fb23209162edb43d849 100644 (file)
@@ -4,6 +4,7 @@
 #include <linux/types.h>
 #include <asm/schid.h>
 #include <asm/ccwdev.h>
+#include <asm/irq.h>
 #include "css.h"
 #include "orb.h"
 
@@ -157,6 +158,7 @@ struct ccw_device_private {
        struct list_head cmb_list;      /* list of measured devices */
        u64 cmb_start_time;             /* clock value of cmb reset */
        void *cmb_wait;                 /* deferred cmb enable/disable */
+       enum interruption_class int_class;
 };
 
 static inline int rsch(struct subchannel_id schid)
index 3dd86441da3d33ef7077a11e677d6ed600d34e73..b962ffbc0803dead8c7efb3e49bd4f5d903bc6a4 100644 (file)
 #define QDIO_BUSY_BIT_RETRIES          1000            /* = 10s retry time */
 #define QDIO_INPUT_THRESHOLD           (500 << 12)     /* 500 microseconds */
 
-/*
- * if an asynchronous HiperSockets queue runs full, the 10 seconds timer wait
- * till next initiative to give transmitted skbs back to the stack is too long.
- * Therefore polling is started in case of multicast queue is filled more
- * than 50 percent.
- */
-#define QDIO_IQDIO_POLL_LVL            65      /* HS multicast queue */
-
 enum qdio_irq_states {
        QDIO_IRQ_STATE_INACTIVE,
        QDIO_IRQ_STATE_ESTABLISHED,
@@ -290,6 +282,9 @@ struct qdio_q {
        /* error condition during a data transfer */
        unsigned int qdio_error;
 
+       /* last scan of the queue */
+       u64 timestamp;
+
        struct tasklet_struct tasklet;
        struct qdio_queue_perf_stat q_stats;
 
@@ -423,31 +418,7 @@ static inline int multicast_outbound(struct qdio_q *q)
 #define queue_irqs_disabled(q)                 \
        (test_bit(QDIO_QUEUE_IRQS_DISABLED, &q->u.in.queue_irq_state) != 0)
 
-#define TIQDIO_SHARED_IND              63
-
-/* device state change indicators */
-struct indicator_t {
-       u32 ind;        /* u32 because of compare-and-swap performance */
-       atomic_t count; /* use count, 0 or 1 for non-shared indicators */
-};
-
-extern struct indicator_t *q_indicators;
-
-static inline int has_multiple_inq_on_dsci(struct qdio_irq *irq)
-{
-       return irq->nr_input_qs > 1;
-}
-
-static inline int references_shared_dsci(struct qdio_irq *irq)
-{
-       return irq->dsci == &q_indicators[TIQDIO_SHARED_IND].ind;
-}
-
-static inline int shared_ind(struct qdio_q *q)
-{
-       struct qdio_irq *i = q->irq_ptr;
-       return references_shared_dsci(i) || has_multiple_inq_on_dsci(i);
-}
+extern u64 last_ai_time;
 
 /* prototypes for thin interrupt */
 void qdio_setup_thinint(struct qdio_irq *irq_ptr);
@@ -460,7 +431,8 @@ int tiqdio_allocate_memory(void);
 void tiqdio_free_memory(void);
 int tiqdio_register_thinints(void);
 void tiqdio_unregister_thinints(void);
-
+void clear_nonshared_ind(struct qdio_irq *);
+int test_nonshared_ind(struct qdio_irq *);
 
 /* prototypes for setup */
 void qdio_inbound_processing(unsigned long data);
index aaf7f935bfd37e16c44e6ff70e84b38bde1c71c4..ed68245f9741612f5826a5a244907758f9f36901 100644 (file)
@@ -54,15 +54,17 @@ static int qstat_show(struct seq_file *m, void *v)
        if (!q)
                return 0;
 
-       seq_printf(m, "DSCI: %d   nr_used: %d\n",
-                  *(u32 *)q->irq_ptr->dsci, atomic_read(&q->nr_buf_used));
-       seq_printf(m, "ftc: %d  last_move: %d\n",
+       seq_printf(m, "Timestamp: %Lx  Last AI: %Lx\n",
+                  q->timestamp, last_ai_time);
+       seq_printf(m, "nr_used: %d  ftc: %d  last_move: %d\n",
+                  atomic_read(&q->nr_buf_used),
                   q->first_to_check, q->last_move);
        if (q->is_input_q) {
                seq_printf(m, "polling: %d  ack start: %d  ack count: %d\n",
                           q->u.in.polling, q->u.in.ack_start,
                           q->u.in.ack_count);
-               seq_printf(m, "IRQs disabled: %u\n",
+               seq_printf(m, "DSCI: %d   IRQs disabled: %u\n",
+                          *(u32 *)q->irq_ptr->dsci,
                           test_bit(QDIO_QUEUE_IRQS_DISABLED,
                           &q->u.in.queue_irq_state));
        }
index 9a122280246c1783485af4140d9785cefadca976..3ef8d071c64a683316a01b6e12ecd68f3d6f1d9d 100644 (file)
@@ -15,7 +15,6 @@
 #include <linux/delay.h>
 #include <linux/gfp.h>
 #include <linux/io.h>
-#include <linux/kernel_stat.h>
 #include <linux/atomic.h>
 #include <asm/debug.h>
 #include <asm/qdio.h>
@@ -105,9 +104,12 @@ static inline int qdio_check_ccq(struct qdio_q *q, unsigned int ccq)
        /* all done or next buffer state different */
        if (ccq == 0 || ccq == 32)
                return 0;
-       /* not all buffers processed */
-       if (ccq == 96 || ccq == 97)
+       /* no buffer processed */
+       if (ccq == 97)
                return 1;
+       /* not all buffers processed */
+       if (ccq == 96)
+               return 2;
        /* notify devices immediately */
        DBF_ERROR("%4x ccq:%3d", SCH_NO(q), ccq);
        return -EIO;
@@ -127,10 +129,8 @@ static inline int qdio_check_ccq(struct qdio_q *q, unsigned int ccq)
 static int qdio_do_eqbs(struct qdio_q *q, unsigned char *state,
                        int start, int count, int auto_ack)
 {
+       int rc, tmp_count = count, tmp_start = start, nr = q->nr, retried = 0;
        unsigned int ccq = 0;
-       int tmp_count = count, tmp_start = start;
-       int nr = q->nr;
-       int rc;
 
        BUG_ON(!q->irq_ptr->sch_token);
        qperf_inc(q, eqbs);
@@ -141,29 +141,34 @@ again:
        ccq = do_eqbs(q->irq_ptr->sch_token, state, nr, &tmp_start, &tmp_count,
                      auto_ack);
        rc = qdio_check_ccq(q, ccq);
-
-       /* At least one buffer was processed, return and extract the remaining
-        * buffers later.
-        */
-       if ((ccq == 96) && (count != tmp_count)) {
-               qperf_inc(q, eqbs_partial);
-               return (count - tmp_count);
-       }
+       if (!rc)
+               return count - tmp_count;
 
        if (rc == 1) {
                DBF_DEV_EVENT(DBF_WARN, q->irq_ptr, "EQBS again:%2d", ccq);
                goto again;
        }
 
-       if (rc < 0) {
-               DBF_ERROR("%4x EQBS ERROR", SCH_NO(q));
-               DBF_ERROR("%3d%3d%2d", count, tmp_count, nr);
-               q->handler(q->irq_ptr->cdev,
-                          QDIO_ERROR_ACTIVATE_CHECK_CONDITION,
-                          0, -1, -1, q->irq_ptr->int_parm);
-               return 0;
+       if (rc == 2) {
+               BUG_ON(tmp_count == count);
+               qperf_inc(q, eqbs_partial);
+               DBF_DEV_EVENT(DBF_WARN, q->irq_ptr, "EQBS part:%02x",
+                       tmp_count);
+               /*
+                * Retry once, if that fails bail out and process the
+                * extracted buffers before trying again.
+                */
+               if (!retried++)
+                       goto again;
+               else
+                       return count - tmp_count;
        }
-       return count - tmp_count;
+
+       DBF_ERROR("%4x EQBS ERROR", SCH_NO(q));
+       DBF_ERROR("%3d%3d%2d", count, tmp_count, nr);
+       q->handler(q->irq_ptr->cdev, QDIO_ERROR_ACTIVATE_CHECK_CONDITION,
+                  0, -1, -1, q->irq_ptr->int_parm);
+       return 0;
 }
 
 /**
@@ -196,21 +201,22 @@ static int qdio_do_sqbs(struct qdio_q *q, unsigned char state, int start,
 again:
        ccq = do_sqbs(q->irq_ptr->sch_token, state, nr, &tmp_start, &tmp_count);
        rc = qdio_check_ccq(q, ccq);
-       if (rc == 1) {
+       if (!rc) {
+               WARN_ON(tmp_count);
+               return count - tmp_count;
+       }
+
+       if (rc == 1 || rc == 2) {
                DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "SQBS again:%2d", ccq);
                qperf_inc(q, sqbs_partial);
                goto again;
        }
-       if (rc < 0) {
-               DBF_ERROR("%4x SQBS ERROR", SCH_NO(q));
-               DBF_ERROR("%3d%3d%2d", count, tmp_count, nr);
-               q->handler(q->irq_ptr->cdev,
-                          QDIO_ERROR_ACTIVATE_CHECK_CONDITION,
-                          0, -1, -1, q->irq_ptr->int_parm);
-               return 0;
-       }
-       WARN_ON(tmp_count);
-       return count - tmp_count;
+
+       DBF_ERROR("%4x SQBS ERROR", SCH_NO(q));
+       DBF_ERROR("%3d%3d%2d", count, tmp_count, nr);
+       q->handler(q->irq_ptr->cdev, QDIO_ERROR_ACTIVATE_CHECK_CONDITION,
+                  0, -1, -1, q->irq_ptr->int_parm);
+       return 0;
 }
 
 /* returns number of examined buffers and their common state in *state */
@@ -275,7 +281,7 @@ static inline int set_buf_state(struct qdio_q *q, int bufnr,
 }
 
 /* set slsb states to initial state */
-void qdio_init_buf_states(struct qdio_irq *irq_ptr)
+static void qdio_init_buf_states(struct qdio_irq *irq_ptr)
 {
        struct qdio_q *q;
        int i;
@@ -444,7 +450,7 @@ static void process_buffer_error(struct qdio_q *q, int count)
                qperf_inc(q, target_full);
                DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "OUTFULL FTC:%02x",
                              q->first_to_check);
-               return;
+               goto set;
        }
 
        DBF_ERROR("%4x BUF ERROR", SCH_NO(q));
@@ -454,6 +460,7 @@ static void process_buffer_error(struct qdio_q *q, int count)
                  q->sbal[q->first_to_check]->element[14].sflags,
                  q->sbal[q->first_to_check]->element[15].sflags);
 
+set:
        /*
         * Interrupts may be avoided as long as the error is present
         * so change the buffer state immediately to avoid starvation.
@@ -511,6 +518,8 @@ static int get_inbound_buffer_frontier(struct qdio_q *q)
        int count, stop;
        unsigned char state = 0;
 
+       q->timestamp = get_clock_fast();
+
        /*
         * Don't check 128 buffers, as otherwise qdio_inbound_q_moved
         * would return 0.
@@ -780,6 +789,8 @@ static int get_outbound_buffer_frontier(struct qdio_q *q)
        int count, stop;
        unsigned char state = 0;
 
+       q->timestamp = get_clock_fast();
+
        if (need_siga_sync(q))
                if (((queue_type(q) != QDIO_IQDIO_QFMT) &&
                    !pci_out_supported(q)) ||
@@ -910,21 +921,13 @@ static void __qdio_outbound_processing(struct qdio_q *q)
                if (!pci_out_supported(q) && !qdio_outbound_q_done(q))
                        goto sched;
 
-       /* bail out for HiperSockets unicast queues */
-       if (queue_type(q) == QDIO_IQDIO_QFMT && !multicast_outbound(q))
-               return;
-
-       if ((queue_type(q) == QDIO_IQDIO_QFMT) &&
-           (atomic_read(&q->nr_buf_used)) > QDIO_IQDIO_POLL_LVL)
-               goto sched;
-
        if (q->u.out.pci_out_enabled)
                return;
 
        /*
         * Now we know that queue type is either qeth without pci enabled
-        * or HiperSockets multicast. Make sure buffer switch from PRIMED to
-        * EMPTY is noticed and outbound_handler is called after some time.
+        * or HiperSockets. Make sure buffer switch from PRIMED to EMPTY
+        * is noticed and outbound_handler is called after some time.
         */
        if (qdio_outbound_q_done(q))
                del_timer(&q->u.out.timer);
@@ -1070,6 +1073,7 @@ static void qdio_handle_activate_check(struct ccw_device *cdev,
 {
        struct qdio_irq *irq_ptr = cdev->private->qdio_data;
        struct qdio_q *q;
+       int count;
 
        DBF_ERROR("%4x ACT CHECK", irq_ptr->schid.sch_no);
        DBF_ERROR("intp :%lx", intparm);
@@ -1083,8 +1087,10 @@ static void qdio_handle_activate_check(struct ccw_device *cdev,
                dump_stack();
                goto no_handler;
        }
+
+       count = sub_buf(q->first_to_check, q->first_to_kick);
        q->handler(q->irq_ptr->cdev, QDIO_ERROR_ACTIVATE_CHECK_CONDITION,
-                  0, -1, -1, irq_ptr->int_parm);
+                  q->nr, q->first_to_kick, count, irq_ptr->int_parm);
 no_handler:
        qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED);
 }
@@ -1123,7 +1129,6 @@ void qdio_int_handler(struct ccw_device *cdev, unsigned long intparm,
                return;
        }
 
-       kstat_cpu(smp_processor_id()).irqs[IOINT_QDI]++;
        if (irq_ptr->perf_stat_enabled)
                irq_ptr->perf_stat.qdio_int++;
 
@@ -1714,9 +1719,7 @@ int qdio_start_irq(struct ccw_device *cdev, int nr)
 
        WARN_ON(queue_irqs_enabled(q));
 
-       if (!shared_ind(q))
-               xchg(q->irq_ptr->dsci, 0);
-
+       clear_nonshared_ind(irq_ptr);
        qdio_stop_polling(q);
        clear_bit(QDIO_QUEUE_IRQS_DISABLED, &q->u.in.queue_irq_state);
 
@@ -1724,7 +1727,7 @@ int qdio_start_irq(struct ccw_device *cdev, int nr)
         * We need to check again to not lose initiative after
         * resetting the ACK state.
         */
-       if (!shared_ind(q) && *q->irq_ptr->dsci)
+       if (test_nonshared_ind(irq_ptr))
                goto rescan;
        if (!qdio_inbound_q_done(q))
                goto rescan;
index dd8bd670a6b8fd290296060b50fbb305dbf2e508..d9a46a429bccf8213f4dd6c6fea8032c1d127070 100644 (file)
@@ -381,6 +381,7 @@ static void setup_qdr(struct qdio_irq *irq_ptr,
        int i;
 
        irq_ptr->qdr->qfmt = qdio_init->q_format;
+       irq_ptr->qdr->ac = qdio_init->qdr_ac;
        irq_ptr->qdr->iqdcnt = qdio_init->no_input_qs;
        irq_ptr->qdr->oqdcnt = qdio_init->no_output_qs;
        irq_ptr->qdr->iqdsz = sizeof(struct qdesfmt0) / 4; /* size in words */
index a3e3949d7b692d36c4aec1260b1aab74fd6b6e74..011eadea3ee422fabb85ef24caa784401682ff89 100644 (file)
  */
 #define TIQDIO_NR_NONSHARED_IND                63
 #define TIQDIO_NR_INDICATORS           (TIQDIO_NR_NONSHARED_IND + 1)
+#define TIQDIO_SHARED_IND              63
+
+/* device state change indicators */
+struct indicator_t {
+       u32 ind;        /* u32 because of compare-and-swap performance */
+       atomic_t count; /* use count, 0 or 1 for non-shared indicators */
+};
 
 /* list of thin interrupt input queues */
 static LIST_HEAD(tiq_list);
-DEFINE_MUTEX(tiq_list_lock);
+static DEFINE_MUTEX(tiq_list_lock);
 
 /* adapter local summary indicator */
 static u8 *tiqdio_alsi;
 
-struct indicator_t *q_indicators;
+static struct indicator_t *q_indicators;
 
-static u64 last_ai_time;
+u64 last_ai_time;
 
 /* returns addr for the device state change indicator */
 static u32 *get_indicator(void)
@@ -90,6 +97,43 @@ void tiqdio_remove_input_queues(struct qdio_irq *irq_ptr)
        synchronize_rcu();
 }
 
+static inline int has_multiple_inq_on_dsci(struct qdio_irq *irq_ptr)
+{
+       return irq_ptr->nr_input_qs > 1;
+}
+
+static inline int references_shared_dsci(struct qdio_irq *irq_ptr)
+{
+       return irq_ptr->dsci == &q_indicators[TIQDIO_SHARED_IND].ind;
+}
+
+static inline int shared_ind(struct qdio_irq *irq_ptr)
+{
+       return references_shared_dsci(irq_ptr) ||
+               has_multiple_inq_on_dsci(irq_ptr);
+}
+
+void clear_nonshared_ind(struct qdio_irq *irq_ptr)
+{
+       if (!is_thinint_irq(irq_ptr))
+               return;
+       if (shared_ind(irq_ptr))
+               return;
+       xchg(irq_ptr->dsci, 0);
+}
+
+int test_nonshared_ind(struct qdio_irq *irq_ptr)
+{
+       if (!is_thinint_irq(irq_ptr))
+               return 0;
+       if (shared_ind(irq_ptr))
+               return 0;
+       if (*irq_ptr->dsci)
+               return 1;
+       else
+               return 0;
+}
+
 static inline u32 clear_shared_ind(void)
 {
        if (!atomic_read(&q_indicators[TIQDIO_SHARED_IND].count))
@@ -119,7 +163,7 @@ static inline void tiqdio_call_inq_handlers(struct qdio_irq *irq)
                        q->u.in.queue_start_poll(q->irq_ptr->cdev, q->nr,
                                                 q->irq_ptr->int_parm);
                } else {
-                       if (!shared_ind(q))
+                       if (!shared_ind(q->irq_ptr))
                                xchg(q->irq_ptr->dsci, 0);
 
                        /*
index aec60d55b10dc238e5b3529507fe9afc43db173e..3c2c923d5c0ae6d77a61ec7cac392b4aee4a8f71 100644 (file)
@@ -33,7 +33,7 @@
  * The pointer to our (page) of device descriptions.
  */
 static void *kvm_devices;
-struct work_struct hotplug_work;
+static struct work_struct hotplug_work;
 
 struct kvm_device {
        struct virtio_device vdev;
@@ -334,10 +334,10 @@ static void scan_devices(void)
  */
 static int match_desc(struct device *dev, void *data)
 {
-       if ((ulong)to_kvmdev(dev_to_virtio(dev))->desc == (ulong)data)
-               return 1;
+       struct virtio_device *vdev = dev_to_virtio(dev);
+       struct kvm_device *kdev = to_kvmdev(vdev);
 
-       return 0;
+       return kdev->desc == data;
 }
 
 /*
index f1fa2483ae6b9f02d065fb652732d6e081639eea..b41fae37d3afde703e225ec6f42ea59c94edf848 100644 (file)
@@ -63,7 +63,6 @@
 
 #define KMSG_COMPONENT "claw"
 
-#include <linux/kernel_stat.h>
 #include <asm/ccwdev.h>
 #include <asm/ccwgroup.h>
 #include <asm/debug.h>
@@ -291,6 +290,7 @@ static struct ccw_driver claw_ccw_driver = {
        .ids    = claw_ids,
        .probe  = ccwgroup_probe_ccwdev,
        .remove = ccwgroup_remove_ccwdev,
+       .int_class = IOINT_CLW,
 };
 
 static ssize_t
@@ -645,7 +645,6 @@ claw_irq_handler(struct ccw_device *cdev,
         struct claw_env  *p_env;
         struct chbk *p_ch_r=NULL;
 
-       kstat_cpu(smp_processor_id()).irqs[IOINT_CLW]++;
        CLAW_DBF_TEXT(4, trace, "clawirq");
         /* Bypass all 'unsolicited interrupts' */
        privptr = dev_get_drvdata(&cdev->dev);
index 426787efc49204c8a11036f0236a446c5e866dde..5cb93a8e340326b5a23a4d6e3c3e64a75b09749b 100644 (file)
@@ -24,7 +24,6 @@
 #define KMSG_COMPONENT "ctcm"
 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
 
-#include <linux/kernel_stat.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
@@ -1203,7 +1202,6 @@ static void ctcm_irq_handler(struct ccw_device *cdev,
        int cstat;
        int dstat;
 
-       kstat_cpu(smp_processor_id()).irqs[IOINT_CTC]++;
        CTCM_DBF_TEXT_(TRACE, CTC_DBF_DEBUG,
                "Enter %s(%s)", CTCM_FUNTAIL, dev_name(&cdev->dev));
 
@@ -1769,6 +1767,7 @@ static struct ccw_driver ctcm_ccw_driver = {
        .ids    = ctcm_ids,
        .probe  = ccwgroup_probe_ccwdev,
        .remove = ccwgroup_remove_ccwdev,
+       .int_class = IOINT_CTC,
 };
 
 static struct ccwgroup_driver ctcm_group_driver = {
index 8305319b2a846c31328f5b773e8e0177cf6d41d0..650aec1839e9e381b7eef4f05fd3edac557e8478 100644 (file)
@@ -159,7 +159,7 @@ static ssize_t ctcm_proto_store(struct device *dev,
        return count;
 }
 
-const char *ctcm_type[] = {
+static const char *ctcm_type[] = {
        "not a channel",
        "CTC/A",
        "FICON channel",
index fb246b944b16e7219957f41ca200dc4459484da8..c28713da1ec5d380f9e904bab6f2946016cb76ec 100644 (file)
@@ -26,7 +26,6 @@
 #define KMSG_COMPONENT         "lcs"
 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
 
-#include <linux/kernel_stat.h>
 #include <linux/module.h>
 #include <linux/if.h>
 #include <linux/netdevice.h>
@@ -1399,7 +1398,6 @@ lcs_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
        int rc, index;
        int cstat, dstat;
 
-       kstat_cpu(smp_processor_id()).irqs[IOINT_LCS]++;
        if (lcs_check_irb_error(cdev, irb))
                return;
 
@@ -1972,7 +1970,7 @@ lcs_portno_store (struct device *dev, struct device_attribute *attr, const char
 
 static DEVICE_ATTR(portno, 0644, lcs_portno_show, lcs_portno_store);
 
-const char *lcs_type[] = {
+static const char *lcs_type[] = {
        "not a channel",
        "2216 parallel",
        "2216 channel",
@@ -2399,6 +2397,7 @@ static struct ccw_driver lcs_ccw_driver = {
        .ids    = lcs_ids,
        .probe  = ccwgroup_probe_ccwdev,
        .remove = ccwgroup_remove_ccwdev,
+       .int_class = IOINT_LCS,
 };
 
 /**
index ce735204d317c75470b0920b48406a93007fa781..e4c1176ee25b2fd9942cfad447826611bbc7037f 100644 (file)
@@ -1415,7 +1415,7 @@ static int qeth_l3_send_checksum_command(struct qeth_card *card)
        return 0;
 }
 
-int qeth_l3_set_rx_csum(struct qeth_card *card, int on)
+static int qeth_l3_set_rx_csum(struct qeth_card *card, int on)
 {
        int rc = 0;
 
index 96d1462e0bf5bddc8719e603702afb491981df3c..967e7b70e9779d7c26c58cbe65dd2329c358e0a1 100644 (file)
@@ -163,6 +163,42 @@ void zfcp_dbf_hba_bit_err(char *tag, struct zfcp_fsf_req *req)
        spin_unlock_irqrestore(&dbf->hba_lock, flags);
 }
 
+/**
+ * zfcp_dbf_hba_def_err - trace event for deferred error messages
+ * @adapter: pointer to struct zfcp_adapter
+ * @req_id: request id which caused the deferred error message
+ * @scount: number of sbals incl. the signaling sbal
+ * @pl: array of all involved sbals
+ */
+void zfcp_dbf_hba_def_err(struct zfcp_adapter *adapter, u64 req_id, u16 scount,
+                         void **pl)
+{
+       struct zfcp_dbf *dbf = adapter->dbf;
+       struct zfcp_dbf_pay *payload = &dbf->pay_buf;
+       unsigned long flags;
+       u16 length;
+
+       if (!pl)
+               return;
+
+       spin_lock_irqsave(&dbf->pay_lock, flags);
+       memset(payload, 0, sizeof(*payload));
+
+       memcpy(payload->area, "def_err", 7);
+       payload->fsf_req_id = req_id;
+       payload->counter = 0;
+       length = min((u16)sizeof(struct qdio_buffer),
+                    (u16)ZFCP_DBF_PAY_MAX_REC);
+
+       while ((char *)pl[payload->counter] && payload->counter < scount) {
+               memcpy(payload->data, (char *)pl[payload->counter], length);
+               debug_event(dbf->pay, 1, payload, zfcp_dbf_plen(length));
+               payload->counter++;
+       }
+
+       spin_unlock_irqrestore(&dbf->pay_lock, flags);
+}
+
 static void zfcp_dbf_set_common(struct zfcp_dbf_rec *rec,
                                struct zfcp_adapter *adapter,
                                struct zfcp_port *port,
index 527ba48eea5762563c981e6a725b7c91e191f33f..ed5d921e82cd18448a09a16a502724eae4f6ac76 100644 (file)
@@ -72,6 +72,7 @@ struct zfcp_reqlist;
 #define ZFCP_STATUS_COMMON_NOESC               0x00200000
 
 /* adapter status */
+#define ZFCP_STATUS_ADAPTER_MB_ACT             0x00000001
 #define ZFCP_STATUS_ADAPTER_QDIOUP             0x00000002
 #define ZFCP_STATUS_ADAPTER_SIOSL_ISSUED       0x00000004
 #define ZFCP_STATUS_ADAPTER_XCONFIG_OK         0x00000008
@@ -314,4 +315,10 @@ struct zfcp_fsf_req {
        void                    (*handler)(struct zfcp_fsf_req *);
 };
 
+static inline
+int zfcp_adapter_multi_buffer_active(struct zfcp_adapter *adapter)
+{
+       return atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_MB_ACT;
+}
+
 #endif /* ZFCP_DEF_H */
index 03627cfd81cddff765c0d4a64468ad9f44535d63..2302e1cfb76cb5bec677b849f139494d6028011b 100644 (file)
@@ -53,6 +53,7 @@ extern void zfcp_dbf_hba_fsf_uss(char *, struct zfcp_fsf_req *);
 extern void zfcp_dbf_hba_fsf_res(char *, struct zfcp_fsf_req *);
 extern void zfcp_dbf_hba_bit_err(char *, struct zfcp_fsf_req *);
 extern void zfcp_dbf_hba_berr(struct zfcp_dbf *, struct zfcp_fsf_req *);
+extern void zfcp_dbf_hba_def_err(struct zfcp_adapter *, u64, u16, void **);
 extern void zfcp_dbf_san_req(char *, struct zfcp_fsf_req *, u32);
 extern void zfcp_dbf_san_res(char *, struct zfcp_fsf_req *);
 extern void zfcp_dbf_san_in_els(char *, struct zfcp_fsf_req *);
index 022fb6a8cb8339a6a8854b69ffc7021a3bdce1cf..e9a787e2e6a59ba46fe7fa70f7b8f719cc95ef04 100644 (file)
@@ -936,39 +936,47 @@ static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
                                       struct scatterlist *sg_resp)
 {
        struct zfcp_adapter *adapter = req->adapter;
+       struct zfcp_qdio *qdio = adapter->qdio;
+       struct fsf_qtcb *qtcb = req->qtcb;
        u32 feat = adapter->adapter_features;
-       int bytes;
 
-       if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
-               if (!zfcp_qdio_sg_one_sbale(sg_req) ||
-                   !zfcp_qdio_sg_one_sbale(sg_resp))
-                       return -EOPNOTSUPP;
+       if (zfcp_adapter_multi_buffer_active(adapter)) {
+               if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
+                       return -EIO;
+               if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
+                       return -EIO;
 
-               zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
-                                               sg_req, sg_resp);
+               zfcp_qdio_set_data_div(qdio, &req->qdio_req,
+                                       zfcp_qdio_sbale_count(sg_req));
+               zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
+               zfcp_qdio_set_scount(qdio, &req->qdio_req);
                return 0;
        }
 
        /* use single, unchained SBAL if it can hold the request */
        if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
-               zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
+               zfcp_fsf_setup_ct_els_unchained(qdio, &req->qdio_req,
                                                sg_req, sg_resp);
                return 0;
        }
 
-       bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req, sg_req);
-       if (bytes <= 0)
+       if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS))
+               return -EOPNOTSUPP;
+
+       if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
                return -EIO;
-       zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
-       req->qtcb->bottom.support.req_buf_length = bytes;
-       zfcp_qdio_skip_to_last_sbale(&req->qdio_req);
 
-       bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
-                                       sg_resp);
-       req->qtcb->bottom.support.resp_buf_length = bytes;
-       if (bytes <= 0)
+       qtcb->bottom.support.req_buf_length = zfcp_qdio_real_bytes(sg_req);
+
+       zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
+       zfcp_qdio_skip_to_last_sbale(qdio, &req->qdio_req);
+
+       if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
                return -EIO;
-       zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
+
+       qtcb->bottom.support.resp_buf_length = zfcp_qdio_real_bytes(sg_resp);
+
+       zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
 
        return 0;
 }
@@ -1119,7 +1127,8 @@ int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
 
        req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
 
-       zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2);
+       if (!zfcp_adapter_multi_buffer_active(adapter))
+               zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2);
 
        ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, timeout);
 
@@ -2162,7 +2171,7 @@ int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd)
        struct zfcp_fsf_req *req;
        struct fcp_cmnd *fcp_cmnd;
        u8 sbtype = SBAL_SFLAGS0_TYPE_READ;
-       int real_bytes, retval = -EIO, dix_bytes = 0;
+       int retval = -EIO;
        struct scsi_device *sdev = scsi_cmnd->device;
        struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
        struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
@@ -2207,7 +2216,8 @@ int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd)
                io->ref_tag_value = scsi_get_lba(scsi_cmnd) & 0xFFFFFFFF;
        }
 
-       zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction);
+       if (zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction))
+               goto failed_scsi_cmnd;
 
        fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
        zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd, 0);
@@ -2215,18 +2225,22 @@ int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd)
        if (scsi_prot_sg_count(scsi_cmnd)) {
                zfcp_qdio_set_data_div(qdio, &req->qdio_req,
                                       scsi_prot_sg_count(scsi_cmnd));
-               dix_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
+               retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
+                                                scsi_prot_sglist(scsi_cmnd));
+               if (retval)
+                       goto failed_scsi_cmnd;
+               io->prot_data_length = zfcp_qdio_real_bytes(
                                                scsi_prot_sglist(scsi_cmnd));
-               io->prot_data_length = dix_bytes;
        }
 
-       real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
-                                            scsi_sglist(scsi_cmnd));
-
-       if (unlikely(real_bytes < 0) || unlikely(dix_bytes < 0))
+       retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
+                                        scsi_sglist(scsi_cmnd));
+       if (unlikely(retval))
                goto failed_scsi_cmnd;
 
        zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
+       if (zfcp_adapter_multi_buffer_active(adapter))
+               zfcp_qdio_set_scount(qdio, &req->qdio_req);
 
        retval = zfcp_fsf_req_send(req);
        if (unlikely(retval))
@@ -2328,7 +2342,7 @@ struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
        struct zfcp_qdio *qdio = adapter->qdio;
        struct zfcp_fsf_req *req = NULL;
        struct fsf_qtcb_bottom_support *bottom;
-       int retval = -EIO, bytes;
+       int retval = -EIO;
        u8 direction;
 
        if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
@@ -2361,13 +2375,17 @@ struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
        bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
        bottom->option = fsf_cfdc->option;
 
-       bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, fsf_cfdc->sg);
+       retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, fsf_cfdc->sg);
 
-       if (bytes != ZFCP_CFDC_MAX_SIZE) {
+       if (retval ||
+               (zfcp_qdio_real_bytes(fsf_cfdc->sg) != ZFCP_CFDC_MAX_SIZE)) {
                zfcp_fsf_req_free(req);
+               retval = -EIO;
                goto out;
        }
-       zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
+       zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
+       if (zfcp_adapter_multi_buffer_active(adapter))
+               zfcp_qdio_set_scount(qdio, &req->qdio_req);
 
        zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
        retval = zfcp_fsf_req_send(req);
index d9c40ea73eef4864e6a477d2803b61309e037a1a..df9e69f5474204220d54f7498c724e56ae41f383 100644 (file)
 
 #define QBUFF_PER_PAGE         (PAGE_SIZE / sizeof(struct qdio_buffer))
 
+static bool enable_multibuffer;
+module_param_named(datarouter, enable_multibuffer, bool, 0400);
+MODULE_PARM_DESC(datarouter, "Enable hardware data router support");
+
 static int zfcp_qdio_buffers_enqueue(struct qdio_buffer **sbal)
 {
        int pos;
@@ -37,8 +41,11 @@ static void zfcp_qdio_handler_error(struct zfcp_qdio *qdio, char *id,
 
        dev_warn(&adapter->ccw_device->dev, "A QDIO problem occurred\n");
 
-       if (qdio_err & QDIO_ERROR_SLSB_STATE)
+       if (qdio_err & QDIO_ERROR_SLSB_STATE) {
                zfcp_qdio_siosl(adapter);
+               zfcp_erp_adapter_shutdown(adapter, 0, id);
+               return;
+       }
        zfcp_erp_adapter_reopen(adapter,
                                ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
                                ZFCP_STATUS_COMMON_ERP_FAILED, id);
@@ -93,9 +100,27 @@ static void zfcp_qdio_int_resp(struct ccw_device *cdev, unsigned int qdio_err,
                               unsigned long parm)
 {
        struct zfcp_qdio *qdio = (struct zfcp_qdio *) parm;
-       int sbal_idx, sbal_no;
+       struct zfcp_adapter *adapter = qdio->adapter;
+       struct qdio_buffer_element *sbale;
+       int sbal_no, sbal_idx;
+       void *pl[ZFCP_QDIO_MAX_SBALS_PER_REQ + 1];
+       u64 req_id;
+       u8 scount;
 
        if (unlikely(qdio_err)) {
+               memset(pl, 0, ZFCP_QDIO_MAX_SBALS_PER_REQ * sizeof(void *));
+               if (zfcp_adapter_multi_buffer_active(adapter)) {
+                       sbale = qdio->res_q[idx]->element;
+                       req_id = (u64) sbale->addr;
+                       scount = sbale->scount + 1; /* incl. signaling SBAL */
+
+                       for (sbal_no = 0; sbal_no < scount; sbal_no++) {
+                               sbal_idx = (idx + sbal_no) %
+                                       QDIO_MAX_BUFFERS_PER_Q;
+                               pl[sbal_no] = qdio->res_q[sbal_idx];
+                       }
+                       zfcp_dbf_hba_def_err(adapter, req_id, scount, pl);
+               }
                zfcp_qdio_handler_error(qdio, "qdires1", qdio_err);
                return;
        }
@@ -155,7 +180,7 @@ zfcp_qdio_sbal_chain(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req)
 static struct qdio_buffer_element *
 zfcp_qdio_sbale_next(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req)
 {
-       if (q_req->sbale_curr == ZFCP_QDIO_LAST_SBALE_PER_SBAL)
+       if (q_req->sbale_curr == qdio->max_sbale_per_sbal - 1)
                return zfcp_qdio_sbal_chain(qdio, q_req);
        q_req->sbale_curr++;
        return zfcp_qdio_sbale_curr(qdio, q_req);
@@ -167,13 +192,12 @@ zfcp_qdio_sbale_next(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req)
  * @q_req: pointer to struct zfcp_qdio_req
  * @sg: scatter-gather list
  * @max_sbals: upper bound for number of SBALs to be used
- * Returns: number of bytes, or error (negativ)
+ * Returns: zero or -EINVAL on error
  */
 int zfcp_qdio_sbals_from_sg(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req,
                            struct scatterlist *sg)
 {
        struct qdio_buffer_element *sbale;
-       int bytes = 0;
 
        /* set storage-block type for this request */
        sbale = zfcp_qdio_sbale_req(qdio, q_req);
@@ -187,14 +211,10 @@ int zfcp_qdio_sbals_from_sg(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req,
                                             q_req->sbal_number);
                        return -EINVAL;
                }
-
                sbale->addr = sg_virt(sg);
                sbale->length = sg->length;
-
-               bytes += sg->length;
        }
-
-       return bytes;
+       return 0;
 }
 
 static int zfcp_qdio_sbal_check(struct zfcp_qdio *qdio)
@@ -283,6 +303,8 @@ static void zfcp_qdio_setup_init_data(struct qdio_initialize *id,
        memcpy(id->adapter_name, dev_name(&id->cdev->dev), 8);
        ASCEBC(id->adapter_name, 8);
        id->qib_rflags = QIB_RFLAGS_ENABLE_DATA_DIV;
+       if (enable_multibuffer)
+               id->qdr_ac |= QDR_AC_MULTI_BUFFER_ENABLE;
        id->no_input_qs = 1;
        id->no_output_qs = 1;
        id->input_handler = zfcp_qdio_int_resp;
@@ -378,6 +400,17 @@ int zfcp_qdio_open(struct zfcp_qdio *qdio)
                atomic_set_mask(ZFCP_STATUS_ADAPTER_DATA_DIV_ENABLED,
                                &qdio->adapter->status);
 
+       if (ssqd.qdioac2 & CHSC_AC2_MULTI_BUFFER_ENABLED) {
+               atomic_set_mask(ZFCP_STATUS_ADAPTER_MB_ACT, &adapter->status);
+               qdio->max_sbale_per_sbal = QDIO_MAX_ELEMENTS_PER_BUFFER;
+       } else {
+               atomic_clear_mask(ZFCP_STATUS_ADAPTER_MB_ACT, &adapter->status);
+               qdio->max_sbale_per_sbal = QDIO_MAX_ELEMENTS_PER_BUFFER - 1;
+       }
+
+       qdio->max_sbale_per_req =
+               ZFCP_QDIO_MAX_SBALS_PER_REQ * qdio->max_sbale_per_sbal
+               - 2;
        if (qdio_activate(cdev))
                goto failed_qdio;
 
@@ -397,6 +430,11 @@ int zfcp_qdio_open(struct zfcp_qdio *qdio)
        atomic_set(&qdio->req_q_free, QDIO_MAX_BUFFERS_PER_Q);
        atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &qdio->adapter->status);
 
+       if (adapter->scsi_host) {
+               adapter->scsi_host->sg_tablesize = qdio->max_sbale_per_req;
+               adapter->scsi_host->max_sectors = qdio->max_sbale_per_req * 8;
+       }
+
        return 0;
 
 failed_qdio:
index 54e22ace012b601f5a3cc8dd3cc33505458b8cfd..8ac7f5342d29d807e815e939b54f68f3c8f38fca 100644 (file)
 
 #define ZFCP_QDIO_SBALE_LEN    PAGE_SIZE
 
-/* DMQ bug workaround: don't use last SBALE */
-#define ZFCP_QDIO_MAX_SBALES_PER_SBAL  (QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
-
-/* index of last SBALE (with respect to DMQ bug workaround) */
-#define ZFCP_QDIO_LAST_SBALE_PER_SBAL  (ZFCP_QDIO_MAX_SBALES_PER_SBAL - 1)
-
 /* Max SBALS for chaining */
 #define ZFCP_QDIO_MAX_SBALS_PER_REQ    36
 
-/* max. number of (data buffer) SBALEs in largest SBAL chain
- * request ID + QTCB in SBALE 0 + 1 of first SBAL in chain   */
-#define ZFCP_QDIO_MAX_SBALES_PER_REQ     \
-       (ZFCP_QDIO_MAX_SBALS_PER_REQ * ZFCP_QDIO_MAX_SBALES_PER_SBAL - 2)
-
 /**
  * struct zfcp_qdio - basic qdio data structure
  * @res_q: response queue
@@ -53,6 +42,8 @@ struct zfcp_qdio {
        atomic_t                req_q_full;
        wait_queue_head_t       req_q_wq;
        struct zfcp_adapter     *adapter;
+       u16                     max_sbale_per_sbal;
+       u16                     max_sbale_per_req;
 };
 
 /**
@@ -155,7 +146,7 @@ void zfcp_qdio_fill_next(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req,
 {
        struct qdio_buffer_element *sbale;
 
-       BUG_ON(q_req->sbale_curr == ZFCP_QDIO_LAST_SBALE_PER_SBAL);
+       BUG_ON(q_req->sbale_curr == qdio->max_sbale_per_sbal - 1);
        q_req->sbale_curr++;
        sbale = zfcp_qdio_sbale_curr(qdio, q_req);
        sbale->addr = data;
@@ -195,9 +186,10 @@ int zfcp_qdio_sg_one_sbale(struct scatterlist *sg)
  * @q_req: The current zfcp_qdio_req
  */
 static inline
-void zfcp_qdio_skip_to_last_sbale(struct zfcp_qdio_req *q_req)
+void zfcp_qdio_skip_to_last_sbale(struct zfcp_qdio *qdio,
+                                 struct zfcp_qdio_req *q_req)
 {
-       q_req->sbale_curr = ZFCP_QDIO_LAST_SBALE_PER_SBAL;
+       q_req->sbale_curr = qdio->max_sbale_per_sbal - 1;
 }
 
 /**
@@ -228,8 +220,52 @@ void zfcp_qdio_set_data_div(struct zfcp_qdio *qdio,
 {
        struct qdio_buffer_element *sbale;
 
-       sbale = &qdio->req_q[q_req->sbal_first]->element[0];
+       sbale = qdio->req_q[q_req->sbal_first]->element;
        sbale->length = count;
 }
 
+/**
+ * zfcp_qdio_sbale_count - count sbale used
+ * @sg: pointer to struct scatterlist
+ */
+static inline
+unsigned int zfcp_qdio_sbale_count(struct scatterlist *sg)
+{
+       unsigned int count = 0;
+
+       for (; sg; sg = sg_next(sg))
+               count++;
+
+       return count;
+}
+
+/**
+ * zfcp_qdio_real_bytes - count bytes used
+ * @sg: pointer to struct scatterlist
+ */
+static inline
+unsigned int zfcp_qdio_real_bytes(struct scatterlist *sg)
+{
+       unsigned int real_bytes = 0;
+
+       for (; sg; sg = sg_next(sg))
+               real_bytes += sg->length;
+
+       return real_bytes;
+}
+
+/**
+ * zfcp_qdio_set_scount - set SBAL count value
+ * @qdio: pointer to struct zfcp_qdio
+ * @q_req: The current zfcp_qdio_req
+ */
+static inline
+void zfcp_qdio_set_scount(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req)
+{
+       struct qdio_buffer_element *sbale;
+
+       sbale = qdio->req_q[q_req->sbal_first]->element;
+       sbale->scount = q_req->sbal_number - 1;
+}
+
 #endif /* ZFCP_QDIO_H */
index 7cac873c73837ac668c4f4985c2c4a06061ad547..09126a9d62ff8942fe3246cc2d8b5a3c9074c768 100644 (file)
@@ -24,11 +24,8 @@ module_param_named(queue_depth, default_depth, uint, 0600);
 MODULE_PARM_DESC(queue_depth, "Default queue depth for new SCSI devices");
 
 static bool enable_dif;
-
-#ifdef CONFIG_ZFCP_DIF
-module_param_named(dif, enable_dif, bool, 0600);
+module_param_named(dif, enable_dif, bool, 0400);
 MODULE_PARM_DESC(dif, "Enable DIF/DIX data integrity support");
-#endif
 
 static bool allow_lun_scan = 1;
 module_param(allow_lun_scan, bool, 0600);
@@ -309,8 +306,8 @@ static struct scsi_host_template zfcp_scsi_host_template = {
        .proc_name               = "zfcp",
        .can_queue               = 4096,
        .this_id                 = -1,
-       .sg_tablesize            = ZFCP_QDIO_MAX_SBALES_PER_REQ,
-       .max_sectors             = (ZFCP_QDIO_MAX_SBALES_PER_REQ * 8),
+       .sg_tablesize            = 1, /* adjusted later */
+       .max_sectors             = 8, /* adjusted later */
        .dma_boundary            = ZFCP_QDIO_SBALE_LEN - 1,
        .cmd_per_lun             = 1,
        .use_clustering          = 1,
@@ -668,9 +665,9 @@ void zfcp_scsi_set_prot(struct zfcp_adapter *adapter)
            adapter->adapter_features & FSF_FEATURE_DIX_PROT_TCPIP) {
                mask |= SHOST_DIX_TYPE1_PROTECTION;
                scsi_host_set_guard(shost, SHOST_DIX_GUARD_IP);
-               shost->sg_prot_tablesize = ZFCP_QDIO_MAX_SBALES_PER_REQ / 2;
-               shost->sg_tablesize = ZFCP_QDIO_MAX_SBALES_PER_REQ / 2;
-               shost->max_sectors = ZFCP_QDIO_MAX_SBALES_PER_REQ * 8 / 2;
+               shost->sg_prot_tablesize = adapter->qdio->max_sbale_per_req / 2;
+               shost->sg_tablesize = adapter->qdio->max_sbale_per_req / 2;
+               shost->max_sectors = shost->sg_tablesize * 8;
        }
 
        scsi_host_set_prot(shost, mask);
index 3878b739508134a2a527098638342c106adbd51c..aa573c39f59626da03692aea19bb34ad3ac80123 100644 (file)
@@ -309,6 +309,7 @@ config SCSI_FC_TGT_ATTRS
 config SCSI_ISCSI_ATTRS
        tristate "iSCSI Transport Attributes"
        depends on SCSI && NET
+       select BLK_DEV_BSGLIB
        help
          If you wish to export transport-specific information about
          each attached iSCSI device to sysfs, say Y.
@@ -559,6 +560,15 @@ source "drivers/scsi/aic7xxx/Kconfig.aic79xx"
 source "drivers/scsi/aic94xx/Kconfig"
 source "drivers/scsi/mvsas/Kconfig"
 
+config SCSI_MVUMI
+       tristate "Marvell UMI driver"
+       depends on SCSI && PCI
+       help
+         Module for Marvell Universal Message Interface(UMI) driver
+
+         To compile this driver as a module, choose M here: the
+         module will be called mvumi.
+
 config SCSI_DPT_I2O
        tristate "Adaptec I2O RAID support "
        depends on SCSI && PCI && VIRT_TO_BUS
@@ -1872,10 +1882,6 @@ config ZFCP
           called zfcp. If you want to compile it as a module, say M here
           and read <file:Documentation/kbuild/modules.txt>.
 
-config ZFCP_DIF
-       tristate "T10 DIF/DIX support for the zfcp driver (EXPERIMENTAL)"
-       depends on ZFCP && EXPERIMENTAL
-
 config SCSI_PMCRAID
        tristate "PMC SIERRA Linux MaxRAID adapter support"
        depends on PCI && SCSI && NET
index 6153a66a8a3184631481dfd8733d9b31e4792ff5..2b887498be50135bcd68a5e8b0a736f64482cd55 100644 (file)
@@ -134,6 +134,7 @@ obj-$(CONFIG_SCSI_IBMVFC)   += ibmvscsi/
 obj-$(CONFIG_SCSI_HPTIOP)      += hptiop.o
 obj-$(CONFIG_SCSI_STEX)                += stex.o
 obj-$(CONFIG_SCSI_MVSAS)       += mvsas/
+obj-$(CONFIG_SCSI_MVUMI)       += mvumi.o
 obj-$(CONFIG_PS3_ROM)          += ps3rom.o
 obj-$(CONFIG_SCSI_CXGB3_ISCSI) += libiscsi.o libiscsi_tcp.o cxgbi/
 obj-$(CONFIG_SCSI_CXGB4_ISCSI) += libiscsi.o libiscsi_tcp.o cxgbi/
index 3382475dc22dcf1ac4167aed67da6056539b2131..4aa76d6f11dfed870db05bb098f13cf4aa3d361a 100644 (file)
@@ -894,16 +894,17 @@ static ssize_t aac_show_serial_number(struct device *device,
        int len = 0;
 
        if (le32_to_cpu(dev->adapter_info.serial[0]) != 0xBAD0)
-               len = snprintf(buf, PAGE_SIZE, "%06X\n",
+               len = snprintf(buf, 16, "%06X\n",
                  le32_to_cpu(dev->adapter_info.serial[0]));
        if (len &&
          !memcmp(&dev->supplement_adapter_info.MfgPcbaSerialNo[
            sizeof(dev->supplement_adapter_info.MfgPcbaSerialNo)-len],
          buf, len-1))
-               len = snprintf(buf, PAGE_SIZE, "%.*s\n",
+               len = snprintf(buf, 16, "%.*s\n",
                  (int)sizeof(dev->supplement_adapter_info.MfgPcbaSerialNo),
                  dev->supplement_adapter_info.MfgPcbaSerialNo);
-       return len;
+
+       return min(len, 16);
 }
 
 static ssize_t aac_show_max_channel(struct device *device,
index 29593275201a563835511c2957384cf06bca7484..fdac7c2fef379bdddd6570d1229bada750c6643b 100644 (file)
@@ -906,6 +906,7 @@ int asd_control_phy(struct asd_sas_phy *phy, enum phy_func func, void *arg)
 
        switch (func) {
        case PHY_FUNC_CLEAR_ERROR_LOG:
+       case PHY_FUNC_GET_EVENTS:
                return -ENOSYS;
        case PHY_FUNC_SET_LINK_RATE:
                rates = arg;
index b8a82f2c62c82306e67ec47e45154077f7324978..cdb15364bc6905316816c78c0aac9fde161839dc 100644 (file)
@@ -660,6 +660,7 @@ int beiscsi_cmd_mccq_create(struct beiscsi_hba *phba,
        spin_lock(&phba->ctrl.mbox_lock);
        ctrl = &phba->ctrl;
        wrb = wrb_from_mbox(&ctrl->mbox_mem);
+       memset(wrb, 0, sizeof(*wrb));
        req = embedded_payload(wrb);
        ctxt = &req->context;
 
@@ -868,3 +869,22 @@ error:
                beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
        return status;
 }
+
+int beiscsi_cmd_reset_function(struct beiscsi_hba  *phba)
+{
+       struct be_ctrl_info *ctrl = &phba->ctrl;
+       struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
+       struct be_post_sgl_pages_req *req = embedded_payload(wrb);
+       int status;
+
+       spin_lock(&ctrl->mbox_lock);
+
+       req = embedded_payload(wrb);
+       be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
+       be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+                          OPCODE_COMMON_FUNCTION_RESET, sizeof(*req));
+       status = be_mbox_notify_wait(phba);
+
+       spin_unlock(&ctrl->mbox_lock);
+       return status;
+}
index 497eb29e5c9e1634a388c6be4902fbdc4c177471..8b40a5b4366c21cd2afd271e541f90bc81dea218 100644 (file)
@@ -561,6 +561,8 @@ int be_cmd_iscsi_post_sgl_pages(struct be_ctrl_info *ctrl,
                                struct be_dma_mem *q_mem, u32 page_offset,
                                u32 num_pages);
 
+int beiscsi_cmd_reset_function(struct beiscsi_hba *phba);
+
 int be_cmd_wrbq_create(struct be_ctrl_info *ctrl, struct be_dma_mem *q_mem,
                       struct be_queue_info *wrbq);
 
index 3cad1060502302a92dd78a2566482ceb2986c376..8b002f6db6ca98b796d23e9cd77832a476627133 100644 (file)
@@ -177,9 +177,8 @@ int beiscsi_conn_bind(struct iscsi_cls_session *cls_session,
 {
        struct iscsi_conn *conn = cls_conn->dd_data;
        struct beiscsi_conn *beiscsi_conn = conn->dd_data;
-       struct Scsi_Host *shost =
-               (struct Scsi_Host *)iscsi_session_to_shost(cls_session);
-       struct beiscsi_hba *phba = (struct beiscsi_hba *)iscsi_host_priv(shost);
+       struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
+       struct beiscsi_hba *phba = iscsi_host_priv(shost);
        struct beiscsi_endpoint *beiscsi_ep;
        struct iscsi_endpoint *ep;
 
@@ -290,7 +289,7 @@ int beiscsi_set_param(struct iscsi_cls_conn *cls_conn,
 int beiscsi_get_host_param(struct Scsi_Host *shost,
                           enum iscsi_host_param param, char *buf)
 {
-       struct beiscsi_hba *phba = (struct beiscsi_hba *)iscsi_host_priv(shost);
+       struct beiscsi_hba *phba = iscsi_host_priv(shost);
        int status = 0;
 
        SE_DEBUG(DBG_LVL_8, "In beiscsi_get_host_param, param= %d\n", param);
@@ -733,3 +732,56 @@ void beiscsi_ep_disconnect(struct iscsi_endpoint *ep)
        beiscsi_unbind_conn_to_cid(phba, beiscsi_ep->ep_cid);
        iscsi_destroy_endpoint(beiscsi_ep->openiscsi_ep);
 }
+
+mode_t be2iscsi_attr_is_visible(int param_type, int param)
+{
+       switch (param_type) {
+       case ISCSI_HOST_PARAM:
+               switch (param) {
+               case ISCSI_HOST_PARAM_HWADDRESS:
+               case ISCSI_HOST_PARAM_IPADDRESS:
+               case ISCSI_HOST_PARAM_INITIATOR_NAME:
+                       return S_IRUGO;
+               default:
+                       return 0;
+               }
+       case ISCSI_PARAM:
+               switch (param) {
+               case ISCSI_PARAM_MAX_RECV_DLENGTH:
+               case ISCSI_PARAM_MAX_XMIT_DLENGTH:
+               case ISCSI_PARAM_HDRDGST_EN:
+               case ISCSI_PARAM_DATADGST_EN:
+               case ISCSI_PARAM_CONN_ADDRESS:
+               case ISCSI_PARAM_CONN_PORT:
+               case ISCSI_PARAM_EXP_STATSN:
+               case ISCSI_PARAM_PERSISTENT_ADDRESS:
+               case ISCSI_PARAM_PERSISTENT_PORT:
+               case ISCSI_PARAM_PING_TMO:
+               case ISCSI_PARAM_RECV_TMO:
+               case ISCSI_PARAM_INITIAL_R2T_EN:
+               case ISCSI_PARAM_MAX_R2T:
+               case ISCSI_PARAM_IMM_DATA_EN:
+               case ISCSI_PARAM_FIRST_BURST:
+               case ISCSI_PARAM_MAX_BURST:
+               case ISCSI_PARAM_PDU_INORDER_EN:
+               case ISCSI_PARAM_DATASEQ_INORDER_EN:
+               case ISCSI_PARAM_ERL:
+               case ISCSI_PARAM_TARGET_NAME:
+               case ISCSI_PARAM_TPGT:
+               case ISCSI_PARAM_USERNAME:
+               case ISCSI_PARAM_PASSWORD:
+               case ISCSI_PARAM_USERNAME_IN:
+               case ISCSI_PARAM_PASSWORD_IN:
+               case ISCSI_PARAM_FAST_ABORT:
+               case ISCSI_PARAM_ABORT_TMO:
+               case ISCSI_PARAM_LU_RESET_TMO:
+               case ISCSI_PARAM_IFACE_NAME:
+               case ISCSI_PARAM_INITIATOR_NAME:
+                       return S_IRUGO;
+               default:
+                       return 0;
+               }
+       }
+
+       return 0;
+}
index ff60b7fd92d6e15db2360a1fb494580cbcac0458..4a1f2e393f31e00cc37a77dcc9f1eca8a623cd65 100644 (file)
@@ -26,6 +26,8 @@
 #define BE2_IPV4  0x1
 #define BE2_IPV6  0x10
 
+mode_t be2iscsi_attr_is_visible(int param_type, int param);
+
 void beiscsi_offload_connection(struct beiscsi_conn *beiscsi_conn,
                                struct beiscsi_offload_params *params);
 
index 0a9bdfa3d939866560c296efb40d8aab71973149..7b0a8ab710494c120d0d7b2338ebe218e6883cbf 100644 (file)
@@ -822,33 +822,47 @@ static int beiscsi_init_irqs(struct beiscsi_hba *phba)
        struct hwi_controller *phwi_ctrlr;
        struct hwi_context_memory *phwi_context;
        int ret, msix_vec, i, j;
-       char desc[32];
 
        phwi_ctrlr = phba->phwi_ctrlr;
        phwi_context = phwi_ctrlr->phwi_ctxt;
 
        if (phba->msix_enabled) {
                for (i = 0; i < phba->num_cpus; i++) {
-                       sprintf(desc, "beiscsi_msix_%04x", i);
+                       phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME,
+                                                   GFP_KERNEL);
+                       if (!phba->msi_name[i]) {
+                               ret = -ENOMEM;
+                               goto free_msix_irqs;
+                       }
+
+                       sprintf(phba->msi_name[i], "beiscsi_%02x_%02x",
+                               phba->shost->host_no, i);
                        msix_vec = phba->msix_entries[i].vector;
-                       ret = request_irq(msix_vec, be_isr_msix, 0, desc,
+                       ret = request_irq(msix_vec, be_isr_msix, 0,
+                                         phba->msi_name[i],
                                          &phwi_context->be_eq[i]);
                        if (ret) {
                                shost_printk(KERN_ERR, phba->shost,
                                             "beiscsi_init_irqs-Failed to"
                                             "register msix for i = %d\n", i);
-                               if (!i)
-                                       return ret;
+                               kfree(phba->msi_name[i]);
                                goto free_msix_irqs;
                        }
                }
+               phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME, GFP_KERNEL);
+               if (!phba->msi_name[i]) {
+                       ret = -ENOMEM;
+                       goto free_msix_irqs;
+               }
+               sprintf(phba->msi_name[i], "beiscsi_mcc_%02x",
+                       phba->shost->host_no);
                msix_vec = phba->msix_entries[i].vector;
-               ret = request_irq(msix_vec, be_isr_mcc, 0, "beiscsi_msix_mcc",
+               ret = request_irq(msix_vec, be_isr_mcc, 0, phba->msi_name[i],
                                  &phwi_context->be_eq[i]);
                if (ret) {
                        shost_printk(KERN_ERR, phba->shost, "beiscsi_init_irqs-"
                                     "Failed to register beiscsi_msix_mcc\n");
-                       i++;
+                       kfree(phba->msi_name[i]);
                        goto free_msix_irqs;
                }
 
@@ -863,8 +877,11 @@ static int beiscsi_init_irqs(struct beiscsi_hba *phba)
        }
        return 0;
 free_msix_irqs:
-       for (j = i - 1; j == 0; j++)
+       for (j = i - 1; j >= 0; j--) {
+               kfree(phba->msi_name[j]);
+               msix_vec = phba->msix_entries[j].vector;
                free_irq(msix_vec, &phwi_context->be_eq[j]);
+       }
        return ret;
 }
 
@@ -1106,7 +1123,12 @@ be_complete_io(struct beiscsi_conn *beiscsi_conn,
                                                & SOL_STS_MASK) >> 8);
        flags = ((psol->dw[offsetof(struct amap_sol_cqe, i_flags) / 32]
                                        & SOL_FLAGS_MASK) >> 24) | 0x80;
+       if (!task->sc) {
+               if (io_task->scsi_cmnd)
+                       scsi_dma_unmap(io_task->scsi_cmnd);
 
+               return;
+       }
        task->sc->result = (DID_OK << 16) | status;
        if (rsp != ISCSI_STATUS_CMD_COMPLETED) {
                task->sc->result = DID_ERROR << 16;
@@ -4027,11 +4049,11 @@ static int beiscsi_mtask(struct iscsi_task *task)
                                      TGT_DM_CMD);
                        AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt,
                                      pwrb, 0);
-                       AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
+                       AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 1);
                } else {
                        AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
                                      INI_RD_CMD);
-                       AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 1);
+                       AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
                }
                hwi_write_buffer(pwrb, task);
                break;
@@ -4102,9 +4124,8 @@ static int beiscsi_task_xmit(struct iscsi_task *task)
        return beiscsi_iotask(task, sg, num_sg, xferlen, writedir);
 }
 
-static void beiscsi_remove(struct pci_dev *pcidev)
+static void beiscsi_quiesce(struct beiscsi_hba *phba)
 {
-       struct beiscsi_hba *phba = NULL;
        struct hwi_controller *phwi_ctrlr;
        struct hwi_context_memory *phwi_context;
        struct be_eq_obj *pbe_eq;
@@ -4112,12 +4133,6 @@ static void beiscsi_remove(struct pci_dev *pcidev)
        u8 *real_offset = 0;
        u32 value = 0;
 
-       phba = (struct beiscsi_hba *)pci_get_drvdata(pcidev);
-       if (!phba) {
-               dev_err(&pcidev->dev, "beiscsi_remove called with no phba\n");
-               return;
-       }
-
        phwi_ctrlr = phba->phwi_ctrlr;
        phwi_context = phwi_ctrlr->phwi_ctxt;
        hwi_disable_intr(phba);
@@ -4125,6 +4140,7 @@ static void beiscsi_remove(struct pci_dev *pcidev)
                for (i = 0; i <= phba->num_cpus; i++) {
                        msix_vec = phba->msix_entries[i].vector;
                        free_irq(msix_vec, &phwi_context->be_eq[i]);
+                       kfree(phba->msi_name[i]);
                }
        } else
                if (phba->pcidev->irq)
@@ -4152,10 +4168,40 @@ static void beiscsi_remove(struct pci_dev *pcidev)
                            phba->ctrl.mbox_mem_alloced.size,
                            phba->ctrl.mbox_mem_alloced.va,
                            phba->ctrl.mbox_mem_alloced.dma);
+}
+
+static void beiscsi_remove(struct pci_dev *pcidev)
+{
+
+       struct beiscsi_hba *phba = NULL;
+
+       phba = pci_get_drvdata(pcidev);
+       if (!phba) {
+               dev_err(&pcidev->dev, "beiscsi_remove called with no phba\n");
+               return;
+       }
+
+       beiscsi_quiesce(phba);
        iscsi_boot_destroy_kset(phba->boot_kset);
        iscsi_host_remove(phba->shost);
        pci_dev_put(phba->pcidev);
        iscsi_host_free(phba->shost);
+       pci_disable_device(pcidev);
+}
+
+static void beiscsi_shutdown(struct pci_dev *pcidev)
+{
+
+       struct beiscsi_hba *phba = NULL;
+
+       phba = (struct beiscsi_hba *)pci_get_drvdata(pcidev);
+       if (!phba) {
+               dev_err(&pcidev->dev, "beiscsi_shutdown called with no phba\n");
+               return;
+       }
+
+       beiscsi_quiesce(phba);
+       pci_disable_device(pcidev);
 }
 
 static void beiscsi_msix_enable(struct beiscsi_hba *phba)
@@ -4235,7 +4281,7 @@ static int __devinit beiscsi_dev_probe(struct pci_dev *pcidev,
                        gcrashmode++;
                        shost_printk(KERN_ERR, phba->shost,
                                "Loading Driver in crashdump mode\n");
-                       ret = beiscsi_pci_soft_reset(phba);
+                       ret = beiscsi_cmd_reset_function(phba);
                        if (ret) {
                                shost_printk(KERN_ERR, phba->shost,
                                        "Reset Failed. Aborting Crashdump\n");
@@ -4364,37 +4410,12 @@ struct iscsi_transport beiscsi_iscsi_transport = {
        .name = DRV_NAME,
        .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_TEXT_NEGO |
                CAP_MULTI_R2T | CAP_DATADGST | CAP_DATA_PATH_OFFLOAD,
-       .param_mask = ISCSI_MAX_RECV_DLENGTH |
-               ISCSI_MAX_XMIT_DLENGTH |
-               ISCSI_HDRDGST_EN |
-               ISCSI_DATADGST_EN |
-               ISCSI_INITIAL_R2T_EN |
-               ISCSI_MAX_R2T |
-               ISCSI_IMM_DATA_EN |
-               ISCSI_FIRST_BURST |
-               ISCSI_MAX_BURST |
-               ISCSI_PDU_INORDER_EN |
-               ISCSI_DATASEQ_INORDER_EN |
-               ISCSI_ERL |
-               ISCSI_CONN_PORT |
-               ISCSI_CONN_ADDRESS |
-               ISCSI_EXP_STATSN |
-               ISCSI_PERSISTENT_PORT |
-               ISCSI_PERSISTENT_ADDRESS |
-               ISCSI_TARGET_NAME | ISCSI_TPGT |
-               ISCSI_USERNAME | ISCSI_PASSWORD |
-               ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN |
-               ISCSI_FAST_ABORT | ISCSI_ABORT_TMO |
-               ISCSI_LU_RESET_TMO |
-               ISCSI_PING_TMO | ISCSI_RECV_TMO |
-               ISCSI_IFACE_NAME | ISCSI_INITIATOR_NAME,
-       .host_param_mask = ISCSI_HOST_HWADDRESS | ISCSI_HOST_IPADDRESS |
-                               ISCSI_HOST_INITIATOR_NAME,
        .create_session = beiscsi_session_create,
        .destroy_session = beiscsi_session_destroy,
        .create_conn = beiscsi_conn_create,
        .bind_conn = beiscsi_conn_bind,
        .destroy_conn = iscsi_conn_teardown,
+       .attr_is_visible = be2iscsi_attr_is_visible,
        .set_param = beiscsi_set_param,
        .get_conn_param = iscsi_conn_get_param,
        .get_session_param = iscsi_session_get_param,
@@ -4418,6 +4439,7 @@ static struct pci_driver beiscsi_pci_driver = {
        .name = DRV_NAME,
        .probe = beiscsi_dev_probe,
        .remove = beiscsi_remove,
+       .shutdown = beiscsi_shutdown,
        .id_table = beiscsi_pci_id_table
 };
 
index 5ce5170254caaabd2ce81d0438e5523c001ffaca..b4a06d5e5f9eeac939215365df3efb9323c4e5fc 100644 (file)
@@ -34,7 +34,7 @@
 
 #include "be.h"
 #define DRV_NAME               "be2iscsi"
-#define BUILD_STR              "2.103.298.0"
+#define BUILD_STR              "4.1.239.0"
 #define BE_NAME                        "ServerEngines BladeEngine2" \
                                "Linux iSCSI Driver version" BUILD_STR
 #define DRV_DESC               BE_NAME " " "Driver"
@@ -162,6 +162,8 @@ do {                                                        \
 #define PAGES_REQUIRED(x) \
        ((x < PAGE_SIZE) ? 1 :  ((x + PAGE_SIZE - 1) / PAGE_SIZE))
 
+#define BEISCSI_MSI_NAME 20 /* size of msi_name string */
+
 enum be_mem_enum {
        HWI_MEM_ADDN_CONTEXT,
        HWI_MEM_WRB,
@@ -287,6 +289,7 @@ struct beiscsi_hba {
        unsigned int num_cpus;
        unsigned int nxt_cqid;
        struct msix_entry msix_entries[MAX_CPUS + 1];
+       char *msi_name[MAX_CPUS + 1];
        bool msix_enabled;
        struct be_mem_descriptor *init_mem;
 
index dd335a2a797b59e603e657beaabba438c8ad3e52..63de1c7cd0cb7b8b847809a661d5f378abc97bce 100644 (file)
@@ -62,7 +62,7 @@
 #include "bnx2fc_constants.h"
 
 #define BNX2FC_NAME            "bnx2fc"
-#define BNX2FC_VERSION         "1.0.4"
+#define BNX2FC_VERSION         "1.0.8"
 
 #define PFX                    "bnx2fc: "
 
@@ -224,6 +224,7 @@ struct bnx2fc_interface {
        struct fcoe_ctlr ctlr;
        u8 vlan_enabled;
        int vlan_id;
+       bool enabled;
 };
 
 #define bnx2fc_from_ctlr(fip) container_of(fip, struct bnx2fc_interface, ctlr)
index d66dcbd0df106d1a9912f90b6e50bbbcb9621e46..fd382fe33f6ef108362debbf0d8a5f872947c560 100644 (file)
@@ -391,18 +391,6 @@ void bnx2fc_rec_compl(struct bnx2fc_els_cb_arg *cb_arg)
        BNX2FC_IO_DBG(rec_req, "rec_compl: orig xid = 0x%x", orig_io_req->xid);
        tgt = orig_io_req->tgt;
 
-       if (test_bit(BNX2FC_FLAG_IO_COMPL, &orig_io_req->req_flags)) {
-               BNX2FC_IO_DBG(rec_req, "completed"
-                      "orig_io - 0x%x\n",
-                       orig_io_req->xid);
-               goto rec_compl_done;
-       }
-       if (test_bit(BNX2FC_FLAG_ISSUE_ABTS, &orig_io_req->req_flags)) {
-               BNX2FC_IO_DBG(rec_req, "abts in prog "
-                      "orig_io - 0x%x\n",
-                       orig_io_req->xid);
-               goto rec_compl_done;
-       }
        /* Handle REC timeout case */
        if (test_and_clear_bit(BNX2FC_FLAG_ELS_TIMEOUT, &rec_req->req_flags)) {
                BNX2FC_IO_DBG(rec_req, "timed out, abort "
@@ -433,6 +421,20 @@ void bnx2fc_rec_compl(struct bnx2fc_els_cb_arg *cb_arg)
                }
                goto rec_compl_done;
        }
+
+       if (test_bit(BNX2FC_FLAG_IO_COMPL, &orig_io_req->req_flags)) {
+               BNX2FC_IO_DBG(rec_req, "completed"
+                      "orig_io - 0x%x\n",
+                       orig_io_req->xid);
+               goto rec_compl_done;
+       }
+       if (test_bit(BNX2FC_FLAG_ISSUE_ABTS, &orig_io_req->req_flags)) {
+               BNX2FC_IO_DBG(rec_req, "abts in prog "
+                      "orig_io - 0x%x\n",
+                       orig_io_req->xid);
+               goto rec_compl_done;
+       }
+
        mp_req = &(rec_req->mp_req);
        fc_hdr = &(mp_req->resp_fc_hdr);
        resp_len = mp_req->resp_len;
index 820a1840c3f755b5c90fd66922e2da5f8d729dab..85bcc4b5596593c1732d4cd04c738f89fe999221 100644 (file)
@@ -22,7 +22,7 @@ DEFINE_PER_CPU(struct bnx2fc_percpu_s, bnx2fc_percpu);
 
 #define DRV_MODULE_NAME                "bnx2fc"
 #define DRV_MODULE_VERSION     BNX2FC_VERSION
-#define DRV_MODULE_RELDATE     "Jun 23, 2011"
+#define DRV_MODULE_RELDATE     "Oct 02, 2011"
 
 
 static char version[] __devinitdata =
@@ -56,6 +56,7 @@ static struct scsi_host_template bnx2fc_shost_template;
 static struct fc_function_template bnx2fc_transport_function;
 static struct fc_function_template bnx2fc_vport_xport_function;
 static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode);
+static void __bnx2fc_destroy(struct bnx2fc_interface *interface);
 static int bnx2fc_destroy(struct net_device *net_device);
 static int bnx2fc_enable(struct net_device *netdev);
 static int bnx2fc_disable(struct net_device *netdev);
@@ -64,7 +65,6 @@ static void bnx2fc_recv_frame(struct sk_buff *skb);
 
 static void bnx2fc_start_disc(struct bnx2fc_interface *interface);
 static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev);
-static int bnx2fc_net_config(struct fc_lport *lp);
 static int bnx2fc_lport_config(struct fc_lport *lport);
 static int bnx2fc_em_config(struct fc_lport *lport);
 static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba);
@@ -78,6 +78,7 @@ static void bnx2fc_destroy_work(struct work_struct *work);
 static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev);
 static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
                                                        *phys_dev);
+static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface);
 static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic);
 
 static int bnx2fc_fw_init(struct bnx2fc_hba *hba);
@@ -98,6 +99,25 @@ static struct notifier_block bnx2fc_cpu_notifier = {
        .notifier_call = bnx2fc_cpu_callback,
 };
 
+static inline struct net_device *bnx2fc_netdev(const struct fc_lport *lport)
+{
+       return ((struct bnx2fc_interface *)
+               ((struct fcoe_port *)lport_priv(lport))->priv)->netdev;
+}
+
+/**
+ * bnx2fc_get_lesb() - Fill the FCoE Link Error Status Block
+ * @lport: the local port
+ * @fc_lesb: the link error status block
+ */
+static void bnx2fc_get_lesb(struct fc_lport *lport,
+                           struct fc_els_lesb *fc_lesb)
+{
+       struct net_device *netdev = bnx2fc_netdev(lport);
+
+       __fcoe_get_lesb(lport, fc_lesb, netdev);
+}
+
 static void bnx2fc_clean_rx_queue(struct fc_lport *lp)
 {
        struct fcoe_percpu_s *bg;
@@ -545,6 +565,14 @@ static void bnx2fc_recv_frame(struct sk_buff *skb)
                        break;
                }
        }
+
+       if (fh->fh_r_ctl == FC_RCTL_BA_ABTS) {
+               /* Drop incoming ABTS */
+               put_cpu();
+               kfree_skb(skb);
+               return;
+       }
+
        if (le32_to_cpu(fr_crc(fp)) !=
                        ~crc32(~0, skb->data, fr_len)) {
                if (stats->InvalidCRCCount < 5)
@@ -727,7 +755,7 @@ void bnx2fc_get_link_state(struct bnx2fc_hba *hba)
                clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
 }
 
-static int bnx2fc_net_config(struct fc_lport *lport)
+static int bnx2fc_net_config(struct fc_lport *lport, struct net_device *netdev)
 {
        struct bnx2fc_hba *hba;
        struct bnx2fc_interface *interface;
@@ -753,11 +781,16 @@ static int bnx2fc_net_config(struct fc_lport *lport)
        bnx2fc_link_speed_update(lport);
 
        if (!lport->vport) {
-               wwnn = fcoe_wwn_from_mac(interface->ctlr.ctl_src_addr, 1, 0);
+               if (fcoe_get_wwn(netdev, &wwnn, NETDEV_FCOE_WWNN))
+                       wwnn = fcoe_wwn_from_mac(interface->ctlr.ctl_src_addr,
+                                                1, 0);
                BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn);
                fc_set_wwnn(lport, wwnn);
 
-               wwpn = fcoe_wwn_from_mac(interface->ctlr.ctl_src_addr, 2, 0);
+               if (fcoe_get_wwn(netdev, &wwpn, NETDEV_FCOE_WWPN))
+                       wwpn = fcoe_wwn_from_mac(interface->ctlr.ctl_src_addr,
+                                                2, 0);
+
                BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn);
                fc_set_wwpn(lport, wwpn);
        }
@@ -769,8 +802,8 @@ static void bnx2fc_destroy_timer(unsigned long data)
 {
        struct bnx2fc_hba *hba = (struct bnx2fc_hba *)data;
 
-       BNX2FC_MISC_DBG("ERROR:bnx2fc_destroy_timer - "
-                  "Destroy compl not received!!\n");
+       printk(KERN_ERR PFX "ERROR:bnx2fc_destroy_timer - "
+              "Destroy compl not received!!\n");
        set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
        wake_up_interruptible(&hba->destroy_wait);
 }
@@ -783,7 +816,7 @@ static void bnx2fc_destroy_timer(unsigned long data)
  * @vlan_id:   vlan id - associated vlan id with this event
  *
  * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
- * NETDEV_CHANGE_MTU events
+ * NETDEV_CHANGE_MTU events. Handle NETDEV_UNREGISTER only for vlans.
  */
 static void bnx2fc_indicate_netevent(void *context, unsigned long event,
                                     u16 vlan_id)
@@ -791,12 +824,11 @@ static void bnx2fc_indicate_netevent(void *context, unsigned long event,
        struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
        struct fc_lport *lport;
        struct fc_lport *vport;
-       struct bnx2fc_interface *interface;
+       struct bnx2fc_interface *interface, *tmp;
        int wait_for_upload = 0;
        u32 link_possible = 1;
 
-       /* Ignore vlans for now */
-       if (vlan_id != 0)
+       if (vlan_id != 0 && event != NETDEV_UNREGISTER)
                return;
 
        switch (event) {
@@ -820,6 +852,18 @@ static void bnx2fc_indicate_netevent(void *context, unsigned long event,
        case NETDEV_CHANGE:
                break;
 
+       case NETDEV_UNREGISTER:
+               if (!vlan_id)
+                       return;
+               mutex_lock(&bnx2fc_dev_lock);
+               list_for_each_entry_safe(interface, tmp, &if_list, list) {
+                       if (interface->hba == hba &&
+                           interface->vlan_id == (vlan_id & VLAN_VID_MASK))
+                               __bnx2fc_destroy(interface);
+               }
+               mutex_unlock(&bnx2fc_dev_lock);
+               return;
+
        default:
                printk(KERN_ERR PFX "Unkonwn netevent %ld", event);
                return;
@@ -838,8 +882,15 @@ static void bnx2fc_indicate_netevent(void *context, unsigned long event,
                bnx2fc_link_speed_update(lport);
 
                if (link_possible && !bnx2fc_link_ok(lport)) {
-                       printk(KERN_ERR "indicate_netevent: ctlr_link_up\n");
-                       fcoe_ctlr_link_up(&interface->ctlr);
+                       /* Reset max recv frame size to default */
+                       fc_set_mfs(lport, BNX2FC_MFS);
+                       /*
+                        * ctlr link up will only be handled during
+                        * enable to avoid sending discovery solicitation
+                        * on a stale vlan
+                        */
+                       if (interface->enabled)
+                               fcoe_ctlr_link_up(&interface->ctlr);
                } else if (fcoe_ctlr_link_down(&interface->ctlr)) {
                        mutex_lock(&lport->lp_mutex);
                        list_for_each_entry(vport, &lport->vports, list)
@@ -995,6 +1046,17 @@ static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled)
        struct bnx2fc_interface *interface = port->priv;
        struct net_device *netdev = interface->netdev;
        struct fc_lport *vn_port;
+       int rc;
+       char buf[32];
+
+       rc = fcoe_validate_vport_create(vport);
+       if (rc) {
+               fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf));
+               printk(KERN_ERR PFX "Failed to create vport, "
+                      "WWPN (0x%s) already exists\n",
+                      buf);
+               return rc;
+       }
 
        if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
                printk(KERN_ERR PFX "vn ports cannot be created on"
@@ -1024,16 +1086,46 @@ static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled)
        return 0;
 }
 
+static void bnx2fc_free_vport(struct bnx2fc_hba *hba, struct fc_lport *lport)
+{
+       struct bnx2fc_lport *blport, *tmp;
+
+       spin_lock_bh(&hba->hba_lock);
+       list_for_each_entry_safe(blport, tmp, &hba->vports, list) {
+               if (blport->lport == lport) {
+                       list_del(&blport->list);
+                       kfree(blport);
+               }
+       }
+       spin_unlock_bh(&hba->hba_lock);
+}
+
 static int bnx2fc_vport_destroy(struct fc_vport *vport)
 {
        struct Scsi_Host *shost = vport_to_shost(vport);
        struct fc_lport *n_port = shost_priv(shost);
        struct fc_lport *vn_port = vport->dd_data;
        struct fcoe_port *port = lport_priv(vn_port);
+       struct bnx2fc_interface *interface = port->priv;
+       struct fc_lport *v_port;
+       bool found = false;
 
        mutex_lock(&n_port->lp_mutex);
+       list_for_each_entry(v_port, &n_port->vports, list)
+               if (v_port->vport == vport) {
+                       found = true;
+                       break;
+               }
+
+       if (!found) {
+               mutex_unlock(&n_port->lp_mutex);
+               return -ENOENT;
+       }
        list_del(&vn_port->list);
        mutex_unlock(&n_port->lp_mutex);
+       bnx2fc_free_vport(interface->hba, port->lport);
+       bnx2fc_port_shutdown(port->lport);
+       bnx2fc_interface_put(interface);
        queue_work(bnx2fc_wq, &port->destroy_work);
        return 0;
 }
@@ -1054,7 +1146,7 @@ static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable)
 }
 
 
-static int bnx2fc_netdev_setup(struct bnx2fc_interface *interface)
+static int bnx2fc_interface_setup(struct bnx2fc_interface *interface)
 {
        struct net_device *netdev = interface->netdev;
        struct net_device *physdev = interface->hba->phys_dev;
@@ -1252,7 +1344,7 @@ struct bnx2fc_interface *bnx2fc_interface_create(struct bnx2fc_hba *hba,
        interface->ctlr.get_src_addr = bnx2fc_get_src_mac;
        set_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags);
 
-       rc = bnx2fc_netdev_setup(interface);
+       rc = bnx2fc_interface_setup(interface);
        if (!rc)
                return interface;
 
@@ -1318,7 +1410,7 @@ static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
                fc_set_wwpn(lport, vport->port_name);
        }
        /* Configure netdev and networking properties of the lport */
-       rc = bnx2fc_net_config(lport);
+       rc = bnx2fc_net_config(lport, interface->netdev);
        if (rc) {
                printk(KERN_ERR PFX "Error on bnx2fc_net_config\n");
                goto lp_config_err;
@@ -1372,7 +1464,7 @@ free_blport:
        return NULL;
 }
 
-static void bnx2fc_netdev_cleanup(struct bnx2fc_interface *interface)
+static void bnx2fc_net_cleanup(struct bnx2fc_interface *interface)
 {
        /* Dont listen for Ethernet packets anymore */
        __dev_remove_pack(&interface->fcoe_packet_type);
@@ -1380,10 +1472,11 @@ static void bnx2fc_netdev_cleanup(struct bnx2fc_interface *interface)
        synchronize_net();
 }
 
-static void bnx2fc_if_destroy(struct fc_lport *lport, struct bnx2fc_hba *hba)
+static void bnx2fc_interface_cleanup(struct bnx2fc_interface *interface)
 {
+       struct fc_lport *lport = interface->ctlr.lp;
        struct fcoe_port *port = lport_priv(lport);
-       struct bnx2fc_lport *blport, *tmp;
+       struct bnx2fc_hba *hba = interface->hba;
 
        /* Stop the transmit retry timer */
        del_timer_sync(&port->timer);
@@ -1391,6 +1484,14 @@ static void bnx2fc_if_destroy(struct fc_lport *lport, struct bnx2fc_hba *hba)
        /* Free existing transmit skbs */
        fcoe_clean_pending_queue(lport);
 
+       bnx2fc_net_cleanup(interface);
+
+       bnx2fc_free_vport(hba, lport);
+}
+
+static void bnx2fc_if_destroy(struct fc_lport *lport)
+{
+
        /* Free queued packets for the receive thread */
        bnx2fc_clean_rx_queue(lport);
 
@@ -1407,19 +1508,22 @@ static void bnx2fc_if_destroy(struct fc_lport *lport, struct bnx2fc_hba *hba)
        /* Free memory used by statistical counters */
        fc_lport_free_stats(lport);
 
-       spin_lock_bh(&hba->hba_lock);
-       list_for_each_entry_safe(blport, tmp, &hba->vports, list) {
-               if (blport->lport == lport) {
-                       list_del(&blport->list);
-                       kfree(blport);
-               }
-       }
-       spin_unlock_bh(&hba->hba_lock);
-
        /* Release Scsi_Host */
        scsi_host_put(lport->host);
 }
 
+static void __bnx2fc_destroy(struct bnx2fc_interface *interface)
+{
+       struct fc_lport *lport = interface->ctlr.lp;
+       struct fcoe_port *port = lport_priv(lport);
+
+       bnx2fc_interface_cleanup(interface);
+       bnx2fc_stop(interface);
+       list_del(&interface->list);
+       bnx2fc_interface_put(interface);
+       queue_work(bnx2fc_wq, &port->destroy_work);
+}
+
 /**
  * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
  *
@@ -1433,8 +1537,6 @@ static void bnx2fc_if_destroy(struct fc_lport *lport, struct bnx2fc_hba *hba)
 static int bnx2fc_destroy(struct net_device *netdev)
 {
        struct bnx2fc_interface *interface = NULL;
-       struct bnx2fc_hba *hba;
-       struct fc_lport *lport;
        int rc = 0;
 
        rtnl_lock();
@@ -1447,15 +1549,9 @@ static int bnx2fc_destroy(struct net_device *netdev)
                goto netdev_err;
        }
 
-       hba = interface->hba;
 
-       bnx2fc_netdev_cleanup(interface);
-       lport = interface->ctlr.lp;
-       bnx2fc_stop(interface);
-       list_del(&interface->list);
        destroy_workqueue(interface->timer_work_queue);
-       bnx2fc_interface_put(interface);
-       bnx2fc_if_destroy(lport, hba);
+       __bnx2fc_destroy(interface);
 
 netdev_err:
        mutex_unlock(&bnx2fc_dev_lock);
@@ -1467,22 +1563,13 @@ static void bnx2fc_destroy_work(struct work_struct *work)
 {
        struct fcoe_port *port;
        struct fc_lport *lport;
-       struct bnx2fc_interface *interface;
-       struct bnx2fc_hba *hba;
 
        port = container_of(work, struct fcoe_port, destroy_work);
        lport = port->lport;
-       interface = port->priv;
-       hba = interface->hba;
 
        BNX2FC_HBA_DBG(lport, "Entered bnx2fc_destroy_work\n");
 
-       bnx2fc_port_shutdown(lport);
-       rtnl_lock();
-       mutex_lock(&bnx2fc_dev_lock);
-       bnx2fc_if_destroy(lport, hba);
-       mutex_unlock(&bnx2fc_dev_lock);
-       rtnl_unlock();
+       bnx2fc_if_destroy(lport);
 }
 
 static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba)
@@ -1661,6 +1748,7 @@ static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
                        wait_event_interruptible(hba->destroy_wait,
                                        test_bit(BNX2FC_FLAG_DESTROY_CMPL,
                                                 &hba->flags));
+                       clear_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
                        /* This should never happen */
                        if (signal_pending(current))
                                flush_signals(current);
@@ -1723,7 +1811,7 @@ static void bnx2fc_start_disc(struct bnx2fc_interface *interface)
        lport = interface->ctlr.lp;
        BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n");
 
-       if (!bnx2fc_link_ok(lport)) {
+       if (!bnx2fc_link_ok(lport) && interface->enabled) {
                BNX2FC_HBA_DBG(lport, "ctlr_link_up\n");
                fcoe_ctlr_link_up(&interface->ctlr);
                fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
@@ -1737,6 +1825,11 @@ static void bnx2fc_start_disc(struct bnx2fc_interface *interface)
                if (++wait_cnt > 12)
                        break;
        }
+
+       /* Reset max receive frame size to default */
+       if (fc_set_mfs(lport, BNX2FC_MFS))
+               return;
+
        fc_lport_init(lport);
        fc_fabric_login(lport);
 }
@@ -1800,6 +1893,7 @@ static int bnx2fc_disable(struct net_device *netdev)
                rc = -ENODEV;
                printk(KERN_ERR PFX "bnx2fc_disable: interface or lport not found\n");
        } else {
+               interface->enabled = false;
                fcoe_ctlr_link_down(&interface->ctlr);
                fcoe_clean_pending_queue(interface->ctlr.lp);
        }
@@ -1822,8 +1916,10 @@ static int bnx2fc_enable(struct net_device *netdev)
        if (!interface || !interface->ctlr.lp) {
                rc = -ENODEV;
                printk(KERN_ERR PFX "bnx2fc_enable: interface or lport not found\n");
-       } else if (!bnx2fc_link_ok(interface->ctlr.lp))
+       } else if (!bnx2fc_link_ok(interface->ctlr.lp)) {
                fcoe_ctlr_link_up(&interface->ctlr);
+               interface->enabled = true;
+       }
 
        mutex_unlock(&bnx2fc_dev_lock);
        rtnl_unlock();
@@ -1923,7 +2019,6 @@ static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode)
        if (!lport) {
                printk(KERN_ERR PFX "Failed to create interface (%s)\n",
                        netdev->name);
-               bnx2fc_netdev_cleanup(interface);
                rc = -EINVAL;
                goto if_create_err;
        }
@@ -1936,8 +2031,15 @@ static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode)
        /* Make this master N_port */
        interface->ctlr.lp = lport;
 
+       if (!bnx2fc_link_ok(lport)) {
+               fcoe_ctlr_link_up(&interface->ctlr);
+               fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
+               set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
+       }
+
        BNX2FC_HBA_DBG(lport, "create: START DISC\n");
        bnx2fc_start_disc(interface);
+       interface->enabled = true;
        /*
         * Release from kref_init in bnx2fc_interface_setup, on success
         * lport should be holding a reference taken in bnx2fc_if_create
@@ -1951,6 +2053,7 @@ static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode)
 if_create_err:
        destroy_workqueue(interface->timer_work_queue);
 ifput_err:
+       bnx2fc_net_cleanup(interface);
        bnx2fc_interface_put(interface);
 netdev_err:
        module_put(THIS_MODULE);
@@ -2017,7 +2120,6 @@ static void bnx2fc_ulp_exit(struct cnic_dev *dev)
 {
        struct bnx2fc_hba *hba;
        struct bnx2fc_interface *interface, *tmp;
-       struct fc_lport *lport;
 
        BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
 
@@ -2039,18 +2141,10 @@ static void bnx2fc_ulp_exit(struct cnic_dev *dev)
        list_del_init(&hba->list);
        adapter_count--;
 
-       list_for_each_entry_safe(interface, tmp, &if_list, list) {
+       list_for_each_entry_safe(interface, tmp, &if_list, list)
                /* destroy not called yet, move to quiesced list */
-               if (interface->hba == hba) {
-                       bnx2fc_netdev_cleanup(interface);
-                       bnx2fc_stop(interface);
-
-                       list_del(&interface->list);
-                       lport = interface->ctlr.lp;
-                       bnx2fc_interface_put(interface);
-                       bnx2fc_if_destroy(lport, hba);
-               }
-       }
+               if (interface->hba == hba)
+                       __bnx2fc_destroy(interface);
        mutex_unlock(&bnx2fc_dev_lock);
 
        bnx2fc_ulp_stop(hba);
@@ -2119,7 +2213,7 @@ static void bnx2fc_percpu_thread_create(unsigned int cpu)
                                (void *)p,
                                "bnx2fc_thread/%d", cpu);
        /* bind thread to the cpu */
-       if (likely(!IS_ERR(p->iothread))) {
+       if (likely(!IS_ERR(thread))) {
                kthread_bind(thread, cpu);
                p->iothread = thread;
                wake_up_process(thread);
@@ -2131,7 +2225,6 @@ static void bnx2fc_percpu_thread_destroy(unsigned int cpu)
        struct bnx2fc_percpu_s *p;
        struct task_struct *thread;
        struct bnx2fc_work *work, *tmp;
-       LIST_HEAD(work_list);
 
        BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu);
 
@@ -2143,7 +2236,7 @@ static void bnx2fc_percpu_thread_destroy(unsigned int cpu)
 
 
        /* Free all work in the list */
-       list_for_each_entry_safe(work, tmp, &work_list, list) {
+       list_for_each_entry_safe(work, tmp, &p->work_list, list) {
                list_del_init(&work->list);
                bnx2fc_process_cq_compl(work->tgt, work->wqe);
                kfree(work);
@@ -2376,6 +2469,7 @@ static struct fc_function_template bnx2fc_transport_function = {
        .vport_create = bnx2fc_vport_create,
        .vport_delete = bnx2fc_vport_destroy,
        .vport_disable = bnx2fc_vport_disable,
+       .bsg_request = fc_lport_bsg_request,
 };
 
 static struct fc_function_template bnx2fc_vport_xport_function = {
@@ -2409,6 +2503,7 @@ static struct fc_function_template bnx2fc_vport_xport_function = {
        .get_fc_host_stats = fc_get_host_stats,
        .issue_fc_host_lip = bnx2fc_fcoe_reset,
        .terminate_rport_io = fc_rport_terminate_io,
+       .bsg_request = fc_lport_bsg_request,
 };
 
 /**
@@ -2438,6 +2533,7 @@ static struct libfc_function_template bnx2fc_libfc_fcn_templ = {
        .elsct_send             = bnx2fc_elsct_send,
        .fcp_abort_io           = bnx2fc_abort_io,
        .fcp_cleanup            = bnx2fc_cleanup,
+       .get_lesb               = bnx2fc_get_lesb,
        .rport_event_callback   = bnx2fc_rport_event_handler,
 };
 
index 72cfb14acd3aacf0ea6ca43f88f0846ddca08004..1923a25cb6a22201bc45456cb06f2da9c7715f90 100644 (file)
@@ -1009,6 +1009,7 @@ int bnx2fc_process_new_cqes(struct bnx2fc_rport *tgt)
        u32 cq_cons;
        struct fcoe_cqe *cqe;
        u32 num_free_sqes = 0;
+       u32 num_cqes = 0;
        u16 wqe;
 
        /*
@@ -1058,10 +1059,11 @@ unlock:
                                wake_up_process(fps->iothread);
                        else
                                bnx2fc_process_cq_compl(tgt, wqe);
+                       num_free_sqes++;
                }
                cqe++;
                tgt->cq_cons_idx++;
-               num_free_sqes++;
+               num_cqes++;
 
                if (tgt->cq_cons_idx == BNX2FC_CQ_WQES_MAX) {
                        tgt->cq_cons_idx = 0;
@@ -1070,8 +1072,10 @@ unlock:
                                1 - tgt->cq_curr_toggle_bit;
                }
        }
-       if (num_free_sqes) {
-               bnx2fc_arm_cq(tgt);
+       if (num_cqes) {
+               /* Arm CQ only if doorbell is mapped */
+               if (tgt->ctx_base)
+                       bnx2fc_arm_cq(tgt);
                atomic_add(num_free_sqes, &tgt->free_sqes);
        }
        spin_unlock_bh(&tgt->cq_lock);
@@ -1739,11 +1743,13 @@ void bnx2fc_init_task(struct bnx2fc_cmd *io_req,
        /* Init state to NORMAL */
        task->txwr_rxrd.const_ctx.init_flags |= task_type <<
                                FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT;
-       if (dev_type == TYPE_TAPE)
+       if (dev_type == TYPE_TAPE) {
                task->txwr_rxrd.const_ctx.init_flags |=
                                FCOE_TASK_DEV_TYPE_TAPE <<
                                FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
-       else
+               io_req->rec_retry = 0;
+               io_req->rec_retry = 0;
+       } else
                task->txwr_rxrd.const_ctx.init_flags |=
                                FCOE_TASK_DEV_TYPE_DISK <<
                                FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
index 6cc3789075bc16fc9a4104b5277b94c40f6faca9..0c64d184d7313ba01c1688b3da8e9a7ebb50b597 100644 (file)
@@ -17,7 +17,7 @@
 static int bnx2fc_split_bd(struct bnx2fc_cmd *io_req, u64 addr, int sg_len,
                           int bd_index);
 static int bnx2fc_map_sg(struct bnx2fc_cmd *io_req);
-static void bnx2fc_build_bd_list_from_sg(struct bnx2fc_cmd *io_req);
+static int bnx2fc_build_bd_list_from_sg(struct bnx2fc_cmd *io_req);
 static void bnx2fc_unmap_sg_list(struct bnx2fc_cmd *io_req);
 static void bnx2fc_free_mp_resc(struct bnx2fc_cmd *io_req);
 static void bnx2fc_parse_fcp_rsp(struct bnx2fc_cmd *io_req,
@@ -1251,7 +1251,6 @@ void bnx2fc_process_seq_cleanup_compl(struct bnx2fc_cmd *seq_clnp_req,
                        seq_clnp_req->xid);
                goto free_cb_arg;
        }
-       kref_get(&orig_io_req->refcount);
 
        spin_unlock_bh(&tgt->tgt_lock);
        rc = bnx2fc_send_srr(orig_io_req, offset, r_ctl);
@@ -1569,6 +1568,8 @@ static int bnx2fc_split_bd(struct bnx2fc_cmd *io_req, u64 addr, int sg_len,
 
 static int bnx2fc_map_sg(struct bnx2fc_cmd *io_req)
 {
+       struct bnx2fc_interface *interface = io_req->port->priv;
+       struct bnx2fc_hba *hba = interface->hba;
        struct scsi_cmnd *sc = io_req->sc_cmd;
        struct fcoe_bd_ctx *bd = io_req->bd_tbl->bd_tbl;
        struct scatterlist *sg;
@@ -1580,7 +1581,8 @@ static int bnx2fc_map_sg(struct bnx2fc_cmd *io_req)
        u64 addr;
        int i;
 
-       sg_count = scsi_dma_map(sc);
+       sg_count = dma_map_sg(&hba->pcidev->dev, scsi_sglist(sc),
+                             scsi_sg_count(sc), sc->sc_data_direction);
        scsi_for_each_sg(sc, sg, sg_count, i) {
                sg_len = sg_dma_len(sg);
                addr = sg_dma_address(sg);
@@ -1605,20 +1607,24 @@ static int bnx2fc_map_sg(struct bnx2fc_cmd *io_req)
        return bd_count;
 }
 
-static void bnx2fc_build_bd_list_from_sg(struct bnx2fc_cmd *io_req)
+static int bnx2fc_build_bd_list_from_sg(struct bnx2fc_cmd *io_req)
 {
        struct scsi_cmnd *sc = io_req->sc_cmd;
        struct fcoe_bd_ctx *bd = io_req->bd_tbl->bd_tbl;
        int bd_count;
 
-       if (scsi_sg_count(sc))
+       if (scsi_sg_count(sc)) {
                bd_count = bnx2fc_map_sg(io_req);
-       else {
+               if (bd_count == 0)
+                       return -ENOMEM;
+       } else {
                bd_count = 0;
                bd[0].buf_addr_lo = bd[0].buf_addr_hi = 0;
                bd[0].buf_len = bd[0].flags = 0;
        }
        io_req->bd_tbl->bd_valid = bd_count;
+
+       return 0;
 }
 
 static void bnx2fc_unmap_sg_list(struct bnx2fc_cmd *io_req)
@@ -1790,12 +1796,6 @@ int bnx2fc_queuecommand(struct Scsi_Host *host,
        tgt = (struct bnx2fc_rport *)&rp[1];
 
        if (!test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags)) {
-               if (test_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags))  {
-                       sc_cmd->result = DID_NO_CONNECT << 16;
-                       sc_cmd->scsi_done(sc_cmd);
-                       return 0;
-
-               }
                /*
                 * Session is not offloaded yet. Let SCSI-ml retry
                 * the command.
@@ -1946,7 +1946,13 @@ int bnx2fc_post_io_req(struct bnx2fc_rport *tgt,
        xid = io_req->xid;
 
        /* Build buffer descriptor list for firmware from sg list */
-       bnx2fc_build_bd_list_from_sg(io_req);
+       if (bnx2fc_build_bd_list_from_sg(io_req)) {
+               printk(KERN_ERR PFX "BD list creation failed\n");
+               spin_lock_bh(&tgt->tgt_lock);
+               kref_put(&io_req->refcount, bnx2fc_cmd_release);
+               spin_unlock_bh(&tgt->tgt_lock);
+               return -EAGAIN;
+       }
 
        task_idx = xid / BNX2FC_TASKS_PER_PAGE;
        index = xid % BNX2FC_TASKS_PER_PAGE;
index d5311b577ccadcf322cf271410552ba31cfb50e3..c1800b5312708a914cf424319dd7376fbb008186 100644 (file)
@@ -76,7 +76,7 @@ static void bnx2fc_offload_session(struct fcoe_port *port,
        if (rval) {
                printk(KERN_ERR PFX "Failed to allocate conn id for "
                        "port_id (%6x)\n", rport->port_id);
-               goto ofld_err;
+               goto tgt_init_err;
        }
 
        /* Allocate session resources */
@@ -134,18 +134,17 @@ retry_ofld:
                /* upload will take care of cleaning up sess resc */
                lport->tt.rport_logoff(rdata);
        }
-       /* Arm CQ */
-       bnx2fc_arm_cq(tgt);
        return;
 
 ofld_err:
        /* couldn't offload the session. log off from this rport */
        BNX2FC_TGT_DBG(tgt, "bnx2fc_offload_session - offload error\n");
-       lport->tt.rport_logoff(rdata);
        /* Free session resources */
        bnx2fc_free_session_resc(hba, tgt);
+tgt_init_err:
        if (tgt->fcoe_conn_id != -1)
                bnx2fc_free_conn_id(hba, tgt->fcoe_conn_id);
+       lport->tt.rport_logoff(rdata);
 }
 
 void bnx2fc_flush_active_ios(struct bnx2fc_rport *tgt)
@@ -624,7 +623,6 @@ static void bnx2fc_free_conn_id(struct bnx2fc_hba *hba, u32 conn_id)
        /* called with hba mutex held */
        spin_lock_bh(&hba->hba_lock);
        hba->tgt_ofld_list[conn_id] = NULL;
-       hba->next_conn_id = conn_id;
        spin_unlock_bh(&hba->hba_lock);
 }
 
@@ -791,8 +789,6 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
        return 0;
 
 mem_alloc_failure:
-       bnx2fc_free_session_resc(hba, tgt);
-       bnx2fc_free_conn_id(hba, tgt->fcoe_conn_id);
        return -ENOMEM;
 }
 
@@ -807,14 +803,14 @@ mem_alloc_failure:
 static void bnx2fc_free_session_resc(struct bnx2fc_hba *hba,
                                                struct bnx2fc_rport *tgt)
 {
-       BNX2FC_TGT_DBG(tgt, "Freeing up session resources\n");
+       void __iomem *ctx_base_ptr;
 
-       if (tgt->ctx_base) {
-               iounmap(tgt->ctx_base);
-               tgt->ctx_base = NULL;
-       }
+       BNX2FC_TGT_DBG(tgt, "Freeing up session resources\n");
 
        spin_lock_bh(&tgt->cq_lock);
+       ctx_base_ptr = tgt->ctx_base;
+       tgt->ctx_base = NULL;
+
        /* Free LCQ */
        if (tgt->lcq) {
                dma_free_coherent(&hba->pcidev->dev, tgt->lcq_mem_size,
@@ -868,4 +864,7 @@ static void bnx2fc_free_session_resc(struct bnx2fc_hba *hba,
                tgt->sq = NULL;
        }
        spin_unlock_bh(&tgt->cq_lock);
+
+       if (ctx_base_ptr)
+               iounmap(ctx_base_ptr);
 }
index cffd4d75df568a0d994e9b4e2187f4ed4ac3c30e..d1e69719097024b58f699cb1f676d784c2c93e13 100644 (file)
@@ -2177,6 +2177,59 @@ static int bnx2i_nl_set_path(struct Scsi_Host *shost, struct iscsi_path *params)
        return 0;
 }
 
+static mode_t bnx2i_attr_is_visible(int param_type, int param)
+{
+       switch (param_type) {
+       case ISCSI_HOST_PARAM:
+               switch (param) {
+               case ISCSI_HOST_PARAM_NETDEV_NAME:
+               case ISCSI_HOST_PARAM_HWADDRESS:
+               case ISCSI_HOST_PARAM_IPADDRESS:
+                       return S_IRUGO;
+               default:
+                       return 0;
+               }
+       case ISCSI_PARAM:
+               switch (param) {
+               case ISCSI_PARAM_MAX_RECV_DLENGTH:
+               case ISCSI_PARAM_MAX_XMIT_DLENGTH:
+               case ISCSI_PARAM_HDRDGST_EN:
+               case ISCSI_PARAM_DATADGST_EN:
+               case ISCSI_PARAM_CONN_ADDRESS:
+               case ISCSI_PARAM_CONN_PORT:
+               case ISCSI_PARAM_EXP_STATSN:
+               case ISCSI_PARAM_PERSISTENT_ADDRESS:
+               case ISCSI_PARAM_PERSISTENT_PORT:
+               case ISCSI_PARAM_PING_TMO:
+               case ISCSI_PARAM_RECV_TMO:
+               case ISCSI_PARAM_INITIAL_R2T_EN:
+               case ISCSI_PARAM_MAX_R2T:
+               case ISCSI_PARAM_IMM_DATA_EN:
+               case ISCSI_PARAM_FIRST_BURST:
+               case ISCSI_PARAM_MAX_BURST:
+               case ISCSI_PARAM_PDU_INORDER_EN:
+               case ISCSI_PARAM_DATASEQ_INORDER_EN:
+               case ISCSI_PARAM_ERL:
+               case ISCSI_PARAM_TARGET_NAME:
+               case ISCSI_PARAM_TPGT:
+               case ISCSI_PARAM_USERNAME:
+               case ISCSI_PARAM_PASSWORD:
+               case ISCSI_PARAM_USERNAME_IN:
+               case ISCSI_PARAM_PASSWORD_IN:
+               case ISCSI_PARAM_FAST_ABORT:
+               case ISCSI_PARAM_ABORT_TMO:
+               case ISCSI_PARAM_LU_RESET_TMO:
+               case ISCSI_PARAM_TGT_RESET_TMO:
+               case ISCSI_PARAM_IFACE_NAME:
+               case ISCSI_PARAM_INITIATOR_NAME:
+                       return S_IRUGO;
+               default:
+                       return 0;
+               }
+       }
+
+       return 0;
+}
 
 /*
  * 'Scsi_Host_Template' structure and 'iscsi_tranport' structure template
@@ -2207,37 +2260,12 @@ struct iscsi_transport bnx2i_iscsi_transport = {
                                  CAP_MULTI_R2T | CAP_DATADGST |
                                  CAP_DATA_PATH_OFFLOAD |
                                  CAP_TEXT_NEGO,
-       .param_mask             = ISCSI_MAX_RECV_DLENGTH |
-                                 ISCSI_MAX_XMIT_DLENGTH |
-                                 ISCSI_HDRDGST_EN |
-                                 ISCSI_DATADGST_EN |
-                                 ISCSI_INITIAL_R2T_EN |
-                                 ISCSI_MAX_R2T |
-                                 ISCSI_IMM_DATA_EN |
-                                 ISCSI_FIRST_BURST |
-                                 ISCSI_MAX_BURST |
-                                 ISCSI_PDU_INORDER_EN |
-                                 ISCSI_DATASEQ_INORDER_EN |
-                                 ISCSI_ERL |
-                                 ISCSI_CONN_PORT |
-                                 ISCSI_CONN_ADDRESS |
-                                 ISCSI_EXP_STATSN |
-                                 ISCSI_PERSISTENT_PORT |
-                                 ISCSI_PERSISTENT_ADDRESS |
-                                 ISCSI_TARGET_NAME | ISCSI_TPGT |
-                                 ISCSI_USERNAME | ISCSI_PASSWORD |
-                                 ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN |
-                                 ISCSI_FAST_ABORT | ISCSI_ABORT_TMO |
-                                 ISCSI_LU_RESET_TMO | ISCSI_TGT_RESET_TMO |
-                                 ISCSI_PING_TMO | ISCSI_RECV_TMO |
-                                 ISCSI_IFACE_NAME | ISCSI_INITIATOR_NAME,
-       .host_param_mask        = ISCSI_HOST_HWADDRESS | ISCSI_HOST_IPADDRESS |
-                                 ISCSI_HOST_NETDEV_NAME,
        .create_session         = bnx2i_session_create,
        .destroy_session        = bnx2i_session_destroy,
        .create_conn            = bnx2i_conn_create,
        .bind_conn              = bnx2i_conn_bind,
        .destroy_conn           = bnx2i_conn_destroy,
+       .attr_is_visible        = bnx2i_attr_is_visible,
        .set_param              = iscsi_set_param,
        .get_conn_param         = iscsi_conn_get_param,
        .get_session_param      = iscsi_session_get_param,
index 1242c7c04a01a712859de3bb2ff20d2a82525608..000294a9df8024e58a16b02e75e22b2d02d7fa0a 100644 (file)
@@ -105,25 +105,7 @@ static struct iscsi_transport cxgb3i_iscsi_transport = {
        .caps           = CAP_RECOVERY_L0 | CAP_MULTI_R2T | CAP_HDRDGST
                                | CAP_DATADGST | CAP_DIGEST_OFFLOAD |
                                CAP_PADDING_OFFLOAD | CAP_TEXT_NEGO,
-       .param_mask     = ISCSI_MAX_RECV_DLENGTH | ISCSI_MAX_XMIT_DLENGTH |
-                               ISCSI_HDRDGST_EN | ISCSI_DATADGST_EN |
-                               ISCSI_INITIAL_R2T_EN | ISCSI_MAX_R2T |
-                               ISCSI_IMM_DATA_EN | ISCSI_FIRST_BURST |
-                               ISCSI_MAX_BURST | ISCSI_PDU_INORDER_EN |
-                               ISCSI_DATASEQ_INORDER_EN | ISCSI_ERL |
-                               ISCSI_CONN_PORT | ISCSI_CONN_ADDRESS |
-                               ISCSI_EXP_STATSN | ISCSI_PERSISTENT_PORT |
-                               ISCSI_PERSISTENT_ADDRESS |
-                               ISCSI_TARGET_NAME | ISCSI_TPGT |
-                               ISCSI_USERNAME | ISCSI_PASSWORD |
-                               ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN |
-                               ISCSI_FAST_ABORT | ISCSI_ABORT_TMO |
-                               ISCSI_LU_RESET_TMO | ISCSI_TGT_RESET_TMO |
-                               ISCSI_PING_TMO | ISCSI_RECV_TMO |
-                               ISCSI_IFACE_NAME | ISCSI_INITIATOR_NAME,
-       .host_param_mask        = ISCSI_HOST_HWADDRESS | ISCSI_HOST_IPADDRESS |
-                               ISCSI_HOST_INITIATOR_NAME |
-                               ISCSI_HOST_NETDEV_NAME,
+       .attr_is_visible        = cxgbi_attr_is_visible,
        .get_host_param = cxgbi_get_host_param,
        .set_host_param = cxgbi_set_host_param,
        /* session management */
index 31c79bde6976af4a347fdfe0a8775cc3cd3e6b0a..ac7a9b1e3e237ade16f38436fecffa2e6ded69bb 100644 (file)
@@ -106,25 +106,7 @@ static struct iscsi_transport cxgb4i_iscsi_transport = {
        .caps           = CAP_RECOVERY_L0 | CAP_MULTI_R2T | CAP_HDRDGST |
                                CAP_DATADGST | CAP_DIGEST_OFFLOAD |
                                CAP_PADDING_OFFLOAD | CAP_TEXT_NEGO,
-       .param_mask     = ISCSI_MAX_RECV_DLENGTH | ISCSI_MAX_XMIT_DLENGTH |
-                               ISCSI_HDRDGST_EN | ISCSI_DATADGST_EN |
-                               ISCSI_INITIAL_R2T_EN | ISCSI_MAX_R2T |
-                               ISCSI_IMM_DATA_EN | ISCSI_FIRST_BURST |
-                               ISCSI_MAX_BURST | ISCSI_PDU_INORDER_EN |
-                               ISCSI_DATASEQ_INORDER_EN | ISCSI_ERL |
-                               ISCSI_CONN_PORT | ISCSI_CONN_ADDRESS |
-                               ISCSI_EXP_STATSN | ISCSI_PERSISTENT_PORT |
-                               ISCSI_PERSISTENT_ADDRESS |
-                               ISCSI_TARGET_NAME | ISCSI_TPGT |
-                               ISCSI_USERNAME | ISCSI_PASSWORD |
-                               ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN |
-                               ISCSI_FAST_ABORT | ISCSI_ABORT_TMO |
-                               ISCSI_LU_RESET_TMO | ISCSI_TGT_RESET_TMO |
-                               ISCSI_PING_TMO | ISCSI_RECV_TMO |
-                               ISCSI_IFACE_NAME | ISCSI_INITIATOR_NAME,
-       .host_param_mask        = ISCSI_HOST_HWADDRESS | ISCSI_HOST_IPADDRESS |
-                               ISCSI_HOST_INITIATOR_NAME |
-                               ISCSI_HOST_NETDEV_NAME,
+       .attr_is_visible        = cxgbi_attr_is_visible,
        .get_host_param = cxgbi_get_host_param,
        .set_host_param = cxgbi_set_host_param,
        /* session management */
index 1c1329bc77c7b3bc8095d6040952151fad4a4696..c363a4b260fd7292279c938a5d1a0489eabda007 100644 (file)
@@ -2568,6 +2568,62 @@ void cxgbi_iscsi_cleanup(struct iscsi_transport *itp,
 }
 EXPORT_SYMBOL_GPL(cxgbi_iscsi_cleanup);
 
+mode_t cxgbi_attr_is_visible(int param_type, int param)
+{
+       switch (param_type) {
+       case ISCSI_HOST_PARAM:
+               switch (param) {
+               case ISCSI_HOST_PARAM_NETDEV_NAME:
+               case ISCSI_HOST_PARAM_HWADDRESS:
+               case ISCSI_HOST_PARAM_IPADDRESS:
+               case ISCSI_HOST_PARAM_INITIATOR_NAME:
+                       return S_IRUGO;
+               default:
+                       return 0;
+               }
+       case ISCSI_PARAM:
+               switch (param) {
+               case ISCSI_PARAM_MAX_RECV_DLENGTH:
+               case ISCSI_PARAM_MAX_XMIT_DLENGTH:
+               case ISCSI_PARAM_HDRDGST_EN:
+               case ISCSI_PARAM_DATADGST_EN:
+               case ISCSI_PARAM_CONN_ADDRESS:
+               case ISCSI_PARAM_CONN_PORT:
+               case ISCSI_PARAM_EXP_STATSN:
+               case ISCSI_PARAM_PERSISTENT_ADDRESS:
+               case ISCSI_PARAM_PERSISTENT_PORT:
+               case ISCSI_PARAM_PING_TMO:
+               case ISCSI_PARAM_RECV_TMO:
+               case ISCSI_PARAM_INITIAL_R2T_EN:
+               case ISCSI_PARAM_MAX_R2T:
+               case ISCSI_PARAM_IMM_DATA_EN:
+               case ISCSI_PARAM_FIRST_BURST:
+               case ISCSI_PARAM_MAX_BURST:
+               case ISCSI_PARAM_PDU_INORDER_EN:
+               case ISCSI_PARAM_DATASEQ_INORDER_EN:
+               case ISCSI_PARAM_ERL:
+               case ISCSI_PARAM_TARGET_NAME:
+               case ISCSI_PARAM_TPGT:
+               case ISCSI_PARAM_USERNAME:
+               case ISCSI_PARAM_PASSWORD:
+               case ISCSI_PARAM_USERNAME_IN:
+               case ISCSI_PARAM_PASSWORD_IN:
+               case ISCSI_PARAM_FAST_ABORT:
+               case ISCSI_PARAM_ABORT_TMO:
+               case ISCSI_PARAM_LU_RESET_TMO:
+               case ISCSI_PARAM_TGT_RESET_TMO:
+               case ISCSI_PARAM_IFACE_NAME:
+               case ISCSI_PARAM_INITIATOR_NAME:
+                       return S_IRUGO;
+               default:
+                       return 0;
+               }
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(cxgbi_attr_is_visible);
+
 static int __init libcxgbi_init_module(void)
 {
        sw_tag_idx_bits = (__ilog2_u32(ISCSI_ITT_MASK)) + 1;
index 3a25b1187c1024ab7a0ac882a41ee9a2c60e33c1..20c88279c7a63f98b421b220feb4350598c002bb 100644 (file)
@@ -709,6 +709,7 @@ int cxgbi_conn_xmit_pdu(struct iscsi_task *);
 
 void cxgbi_cleanup_task(struct iscsi_task *task);
 
+mode_t cxgbi_attr_is_visible(int param_type, int param);
 void cxgbi_get_conn_stats(struct iscsi_cls_conn *, struct iscsi_stats *);
 int cxgbi_set_conn_param(struct iscsi_cls_conn *,
                        enum iscsi_param, char *, int);
index 0119b814779744ccfc448bceddcaac3a7e195fcc..7c05fd9dccfd1259133adaa1691df648cff56521 100644 (file)
@@ -59,6 +59,46 @@ static struct scsi_device_handler *get_device_handler_by_idx(int idx)
        return found;
 }
 
+/*
+ * device_handler_match_function - Match a device handler to a device
+ * @sdev - SCSI device to be tested
+ *
+ * Tests @sdev against the match function of all registered device_handler.
+ * Returns the found device handler or NULL if not found.
+ */
+static struct scsi_device_handler *
+device_handler_match_function(struct scsi_device *sdev)
+{
+       struct scsi_device_handler *tmp_dh, *found_dh = NULL;
+
+       spin_lock(&list_lock);
+       list_for_each_entry(tmp_dh, &scsi_dh_list, list) {
+               if (tmp_dh->match && tmp_dh->match(sdev)) {
+                       found_dh = tmp_dh;
+                       break;
+               }
+       }
+       spin_unlock(&list_lock);
+       return found_dh;
+}
+
+/*
+ * device_handler_match_devlist - Match a device handler to a device
+ * @sdev - SCSI device to be tested
+ *
+ * Tests @sdev against all device_handler registered in the devlist.
+ * Returns the found device handler or NULL if not found.
+ */
+static struct scsi_device_handler *
+device_handler_match_devlist(struct scsi_device *sdev)
+{
+       int idx;
+
+       idx = scsi_get_device_flags_keyed(sdev, sdev->vendor, sdev->model,
+                                         SCSI_DEVINFO_DH);
+       return get_device_handler_by_idx(idx);
+}
+
 /*
  * device_handler_match - Attach a device handler to a device
  * @scsi_dh - The device handler to match against or NULL
@@ -72,12 +112,11 @@ static struct scsi_device_handler *
 device_handler_match(struct scsi_device_handler *scsi_dh,
                     struct scsi_device *sdev)
 {
-       struct scsi_device_handler *found_dh = NULL;
-       int idx;
+       struct scsi_device_handler *found_dh;
 
-       idx = scsi_get_device_flags_keyed(sdev, sdev->vendor, sdev->model,
-                                         SCSI_DEVINFO_DH);
-       found_dh = get_device_handler_by_idx(idx);
+       found_dh = device_handler_match_function(sdev);
+       if (!found_dh)
+               found_dh = device_handler_match_devlist(sdev);
 
        if (scsi_dh && found_dh != scsi_dh)
                found_dh = NULL;
@@ -151,6 +190,10 @@ store_dh_state(struct device *dev, struct device_attribute *attr,
        struct scsi_device_handler *scsi_dh;
        int err = -EINVAL;
 
+       if (sdev->sdev_state == SDEV_CANCEL ||
+           sdev->sdev_state == SDEV_DEL)
+               return -ENODEV;
+
        if (!sdev->scsi_dh_data) {
                /*
                 * Attach to a device handler
@@ -327,7 +370,7 @@ int scsi_register_device_handler(struct scsi_device_handler *scsi_dh)
        list_add(&scsi_dh->list, &scsi_dh_list);
        spin_unlock(&list_lock);
 
-       for (i = 0; scsi_dh->devlist[i].vendor; i++) {
+       for (i = 0; scsi_dh->devlist && scsi_dh->devlist[i].vendor; i++) {
                scsi_dev_info_list_add_keyed(0,
                                        scsi_dh->devlist[i].vendor,
                                        scsi_dh->devlist[i].model,
@@ -360,7 +403,7 @@ int scsi_unregister_device_handler(struct scsi_device_handler *scsi_dh)
        bus_for_each_dev(&scsi_bus_type, NULL, scsi_dh,
                         scsi_dh_notifier_remove);
 
-       for (i = 0; scsi_dh->devlist[i].vendor; i++) {
+       for (i = 0; scsi_dh->devlist && scsi_dh->devlist[i].vendor; i++) {
                scsi_dev_info_list_del_keyed(scsi_dh->devlist[i].vendor,
                                             scsi_dh->devlist[i].model,
                                             SCSI_DEVINFO_DH);
@@ -468,7 +511,7 @@ int scsi_dh_handler_exist(const char *name)
 EXPORT_SYMBOL_GPL(scsi_dh_handler_exist);
 
 /*
- * scsi_dh_handler_attach - Attach device handler
+ * scsi_dh_attach - Attach device handler
  * @sdev - sdev the handler should be attached to
  * @name - name of the handler to attach
  */
@@ -498,7 +541,7 @@ int scsi_dh_attach(struct request_queue *q, const char *name)
 EXPORT_SYMBOL_GPL(scsi_dh_attach);
 
 /*
- * scsi_dh_handler_detach - Detach device handler
+ * scsi_dh_detach - Detach device handler
  * @sdev - sdev the handler should be detached from
  *
  * This function will detach the device handler only
index 6fec9fe5dc39f7908df4bdc79f02cdafe92b415d..627f4b5e5176b16e9cc969c0b98ac80a85c4afb1 100644 (file)
@@ -127,43 +127,6 @@ static struct request *get_alua_req(struct scsi_device *sdev,
        return rq;
 }
 
-/*
- * submit_std_inquiry - Issue a standard INQUIRY command
- * @sdev: sdev the command should be send to
- */
-static int submit_std_inquiry(struct scsi_device *sdev, struct alua_dh_data *h)
-{
-       struct request *rq;
-       int err = SCSI_DH_RES_TEMP_UNAVAIL;
-
-       rq = get_alua_req(sdev, h->inq, ALUA_INQUIRY_SIZE, READ);
-       if (!rq)
-               goto done;
-
-       /* Prepare the command. */
-       rq->cmd[0] = INQUIRY;
-       rq->cmd[1] = 0;
-       rq->cmd[2] = 0;
-       rq->cmd[4] = ALUA_INQUIRY_SIZE;
-       rq->cmd_len = COMMAND_SIZE(INQUIRY);
-
-       rq->sense = h->sense;
-       memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE);
-       rq->sense_len = h->senselen = 0;
-
-       err = blk_execute_rq(rq->q, NULL, rq, 1);
-       if (err == -EIO) {
-               sdev_printk(KERN_INFO, sdev,
-                           "%s: std inquiry failed with %x\n",
-                           ALUA_DH_NAME, rq->errors);
-               h->senselen = rq->sense_len;
-               err = SCSI_DH_IO;
-       }
-       blk_put_request(rq);
-done:
-       return err;
-}
-
 /*
  * submit_vpd_inquiry - Issue an INQUIRY VPD page 0x83 command
  * @sdev: sdev the command should be sent to
@@ -338,23 +301,17 @@ static unsigned submit_stpg(struct alua_dh_data *h)
 }
 
 /*
- * alua_std_inquiry - Evaluate standard INQUIRY command
+ * alua_check_tpgs - Evaluate TPGS setting
  * @sdev: device to be checked
  *
- * Just extract the TPGS setting to find out if ALUA
+ * Examine the TPGS setting of the sdev to find out if ALUA
  * is supported.
  */
-static int alua_std_inquiry(struct scsi_device *sdev, struct alua_dh_data *h)
+static int alua_check_tpgs(struct scsi_device *sdev, struct alua_dh_data *h)
 {
-       int err;
-
-       err = submit_std_inquiry(sdev, h);
-
-       if (err != SCSI_DH_OK)
-               return err;
+       int err = SCSI_DH_OK;
 
-       /* Check TPGS setting */
-       h->tpgs = (h->inq[5] >> 4) & 0x3;
+       h->tpgs = scsi_device_tpgs(sdev);
        switch (h->tpgs) {
        case TPGS_MODE_EXPLICIT|TPGS_MODE_IMPLICIT:
                sdev_printk(KERN_INFO, sdev,
@@ -508,27 +465,28 @@ static int alua_check_sense(struct scsi_device *sdev,
                         * Power On, Reset, or Bus Device Reset, just retry.
                         */
                        return ADD_TO_MLQUEUE;
-               if (sense_hdr->asc == 0x2a && sense_hdr->ascq == 0x06) {
+               if (sense_hdr->asc == 0x2a && sense_hdr->ascq == 0x06)
                        /*
                         * ALUA state changed
                         */
                        return ADD_TO_MLQUEUE;
-               }
-               if (sense_hdr->asc == 0x2a && sense_hdr->ascq == 0x07) {
+               if (sense_hdr->asc == 0x2a && sense_hdr->ascq == 0x07)
                        /*
                         * Implicit ALUA state transition failed
                         */
                        return ADD_TO_MLQUEUE;
-               }
-               if (sense_hdr->asc == 0x3f && sense_hdr->ascq == 0x0e) {
+               if (sense_hdr->asc == 0x3f && sense_hdr->ascq == 0x03)
+                       /*
+                        * Inquiry data has changed
+                        */
+                       return ADD_TO_MLQUEUE;
+               if (sense_hdr->asc == 0x3f && sense_hdr->ascq == 0x0e)
                        /*
                         * REPORTED_LUNS_DATA_HAS_CHANGED is reported
                         * when switching controllers on targets like
                         * Intel Multi-Flex. We can just retry.
                         */
                        return ADD_TO_MLQUEUE;
-               }
-
                break;
        }
 
@@ -547,9 +505,9 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_dh_data *h)
 {
        struct scsi_sense_hdr sense_hdr;
        int len, k, off, valid_states = 0;
-       char *ucp;
+       unsigned char *ucp;
        unsigned err;
-       unsigned long expiry, interval = 10;
+       unsigned long expiry, interval = 1;
 
        expiry = round_jiffies_up(jiffies + ALUA_FAILOVER_TIMEOUT);
  retry:
@@ -610,7 +568,7 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_dh_data *h)
        case TPGS_STATE_TRANSITIONING:
                if (time_before(jiffies, expiry)) {
                        /* State transition, retry */
-                       interval *= 10;
+                       interval *= 2;
                        msleep(interval);
                        goto retry;
                }
@@ -642,7 +600,7 @@ static int alua_initialize(struct scsi_device *sdev, struct alua_dh_data *h)
 {
        int err;
 
-       err = alua_std_inquiry(sdev, h);
+       err = alua_check_tpgs(sdev, h);
        if (err != SCSI_DH_OK)
                goto out;
 
@@ -674,11 +632,9 @@ static int alua_activate(struct scsi_device *sdev,
        struct alua_dh_data *h = get_alua_data(sdev);
        int err = SCSI_DH_OK;
 
-       if (h->group_id != -1) {
-               err = alua_rtpg(sdev, h);
-               if (err != SCSI_DH_OK)
-                       goto out;
-       }
+       err = alua_rtpg(sdev, h);
+       if (err != SCSI_DH_OK)
+               goto out;
 
        if (h->tpgs & TPGS_MODE_EXPLICIT &&
            h->state != TPGS_STATE_OPTIMIZED &&
@@ -720,23 +676,10 @@ static int alua_prep_fn(struct scsi_device *sdev, struct request *req)
 
 }
 
-static const struct scsi_dh_devlist alua_dev_list[] = {
-       {"HP", "MSA VOLUME" },
-       {"HP", "HSV101" },
-       {"HP", "HSV111" },
-       {"HP", "HSV200" },
-       {"HP", "HSV210" },
-       {"HP", "HSV300" },
-       {"IBM", "2107900" },
-       {"IBM", "2145" },
-       {"Pillar", "Axiom" },
-       {"Intel", "Multi-Flex"},
-       {"NETAPP", "LUN"},
-       {"NETAPP", "LUN C-Mode"},
-       {"AIX", "NVDISK"},
-       {"Promise", "VTrak"},
-       {NULL, NULL}
-};
+static bool alua_match(struct scsi_device *sdev)
+{
+       return (scsi_device_tpgs(sdev) != 0);
+}
 
 static int alua_bus_attach(struct scsi_device *sdev);
 static void alua_bus_detach(struct scsi_device *sdev);
@@ -744,12 +687,12 @@ static void alua_bus_detach(struct scsi_device *sdev);
 static struct scsi_device_handler alua_dh = {
        .name = ALUA_DH_NAME,
        .module = THIS_MODULE,
-       .devlist = alua_dev_list,
        .attach = alua_bus_attach,
        .detach = alua_bus_detach,
        .prep_fn = alua_prep_fn,
        .check_sense = alua_check_sense,
        .activate = alua_activate,
+       .match = alua_match,
 };
 
 /*
index 27c9d65d54a902443ff5b32fd4772666951c15dd..82d612f0c49dc1d422e0f3efc817bab2c947ffff 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Engenio/LSI RDAC SCSI Device Handler
+ * LSI/Engenio/NetApp E-Series RDAC SCSI Device Handler
  *
  * Copyright (C) 2005 Mike Christie. All rights reserved.
  * Copyright (C) Chandra Seetharaman, IBM Corp. 2007
@@ -795,6 +795,7 @@ static const struct scsi_dh_devlist rdac_dev_list[] = {
        {"IBM", "3526"},
        {"SGI", "TP9400"},
        {"SGI", "TP9500"},
+       {"SGI", "TP9700"},
        {"SGI", "IS"},
        {"STK", "OPENstorage D280"},
        {"SUN", "CSM200_R"},
@@ -814,6 +815,7 @@ static const struct scsi_dh_devlist rdac_dev_list[] = {
        {"SUN", "CSM100_R_FC"},
        {"SUN", "STK6580_6780"},
        {"SUN", "SUN_6180"},
+       {"SUN", "ArrayStorage"},
        {NULL, NULL},
 };
 
@@ -945,7 +947,7 @@ static void __exit rdac_exit(void)
 module_init(rdac_init);
 module_exit(rdac_exit);
 
-MODULE_DESCRIPTION("Multipath LSI/Engenio RDAC driver");
+MODULE_DESCRIPTION("Multipath LSI/Engenio/NetApp E-Series RDAC driver");
 MODULE_AUTHOR("Mike Christie, Chandra Seetharaman");
 MODULE_VERSION("01.00.0000.0000");
 MODULE_LICENSE("GPL");
index a1c0ddd53aa9a30132580f531d4d1a79942fd04f..61384ee4049b39364ec9481fffaaf3155efb77d7 100644 (file)
@@ -51,7 +51,7 @@ MODULE_DESCRIPTION("FCoE");
 MODULE_LICENSE("GPL v2");
 
 /* Performance tuning parameters for fcoe */
-static unsigned int fcoe_ddp_min;
+static unsigned int fcoe_ddp_min = 4096;
 module_param_named(ddp_min, fcoe_ddp_min, uint, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(ddp_min, "Minimum I/O size in bytes for "     \
                 "Direct Data Placement (DDP).");
@@ -137,7 +137,6 @@ static int fcoe_vport_create(struct fc_vport *, bool disabled);
 static int fcoe_vport_disable(struct fc_vport *, bool disable);
 static void fcoe_set_vport_symbolic_name(struct fc_vport *);
 static void fcoe_set_port_id(struct fc_lport *, u32, struct fc_frame *);
-static int fcoe_validate_vport_create(struct fc_vport *);
 
 static struct libfc_function_template fcoe_libfc_fcn_templ = {
        .frame_send = fcoe_xmit,
@@ -280,6 +279,7 @@ static int fcoe_interface_setup(struct fcoe_interface *fcoe,
         * use the first one for SPMA */
        real_dev = (netdev->priv_flags & IFF_802_1Q_VLAN) ?
                vlan_dev_real_dev(netdev) : netdev;
+       fcoe->realdev = real_dev;
        rcu_read_lock();
        for_each_dev_addr(real_dev, ha) {
                if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
@@ -579,23 +579,6 @@ static int fcoe_lport_config(struct fc_lport *lport)
        return 0;
 }
 
-/**
- * fcoe_get_wwn() - Get the world wide name from LLD if it supports it
- * @netdev: the associated net device
- * @wwn: the output WWN
- * @type: the type of WWN (WWPN or WWNN)
- *
- * Returns: 0 for success
- */
-static int fcoe_get_wwn(struct net_device *netdev, u64 *wwn, int type)
-{
-       const struct net_device_ops *ops = netdev->netdev_ops;
-
-       if (ops->ndo_fcoe_get_wwn)
-               return ops->ndo_fcoe_get_wwn(netdev, wwn, type);
-       return -EINVAL;
-}
-
 /**
  * fcoe_netdev_features_change - Updates the lport's offload flags based
  * on the LLD netdev's FCoE feature flags
@@ -1134,8 +1117,9 @@ static void fcoe_percpu_thread_create(unsigned int cpu)
 
        p = &per_cpu(fcoe_percpu, cpu);
 
-       thread = kthread_create(fcoe_percpu_receive_thread,
-                               (void *)p, "fcoethread/%d", cpu);
+       thread = kthread_create_on_node(fcoe_percpu_receive_thread,
+                                       (void *)p, cpu_to_node(cpu),
+                                       "fcoethread/%d", cpu);
 
        if (likely(!IS_ERR(thread))) {
                kthread_bind(thread, cpu);
@@ -1538,7 +1522,13 @@ int fcoe_xmit(struct fc_lport *lport, struct fc_frame *fp)
        skb_reset_network_header(skb);
        skb->mac_len = elen;
        skb->protocol = htons(ETH_P_FCOE);
-       skb->dev = fcoe->netdev;
+       if (fcoe->netdev->priv_flags & IFF_802_1Q_VLAN &&
+           fcoe->realdev->features & NETIF_F_HW_VLAN_TX) {
+               skb->vlan_tci = VLAN_TAG_PRESENT |
+                               vlan_dev_vlan_id(fcoe->netdev);
+               skb->dev = fcoe->realdev;
+       } else
+               skb->dev = fcoe->netdev;
 
        /* fill up mac and fcoe headers */
        eh = eth_hdr(skb);
@@ -2446,7 +2436,7 @@ static int fcoe_vport_create(struct fc_vport *vport, bool disabled)
 
        rc = fcoe_validate_vport_create(vport);
        if (rc) {
-               wwn_to_str(vport->port_name, buf, sizeof(buf));
+               fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf));
                printk(KERN_ERR "fcoe: Failed to create vport, "
                        "WWPN (0x%s) already exists\n",
                        buf);
@@ -2555,28 +2545,9 @@ static void fcoe_set_vport_symbolic_name(struct fc_vport *vport)
 static void fcoe_get_lesb(struct fc_lport *lport,
                         struct fc_els_lesb *fc_lesb)
 {
-       unsigned int cpu;
-       u32 lfc, vlfc, mdac;
-       struct fcoe_dev_stats *devst;
-       struct fcoe_fc_els_lesb *lesb;
-       struct rtnl_link_stats64 temp;
        struct net_device *netdev = fcoe_netdev(lport);
 
-       lfc = 0;
-       vlfc = 0;
-       mdac = 0;
-       lesb = (struct fcoe_fc_els_lesb *)fc_lesb;
-       memset(lesb, 0, sizeof(*lesb));
-       for_each_possible_cpu(cpu) {
-               devst = per_cpu_ptr(lport->dev_stats, cpu);
-               lfc += devst->LinkFailureCount;
-               vlfc += devst->VLinkFailureCount;
-               mdac += devst->MissDiscAdvCount;
-       }
-       lesb->lesb_link_fail = htonl(lfc);
-       lesb->lesb_vlink_fail = htonl(vlfc);
-       lesb->lesb_miss_fka = htonl(mdac);
-       lesb->lesb_fcs_error = htonl(dev_get_stats(netdev, &temp)->rx_crc_errors);
+       __fcoe_get_lesb(lport, fc_lesb, netdev);
 }
 
 /**
@@ -2600,49 +2571,3 @@ static void fcoe_set_port_id(struct fc_lport *lport,
        if (fp && fc_frame_payload_op(fp) == ELS_FLOGI)
                fcoe_ctlr_recv_flogi(&fcoe->ctlr, lport, fp);
 }
-
-/**
- * fcoe_validate_vport_create() - Validate a vport before creating it
- * @vport: NPIV port to be created
- *
- * This routine is meant to add validation for a vport before creating it
- * via fcoe_vport_create().
- * Current validations are:
- *      - WWPN supplied is unique for given lport
- *
- *
-*/
-static int fcoe_validate_vport_create(struct fc_vport *vport)
-{
-       struct Scsi_Host *shost = vport_to_shost(vport);
-       struct fc_lport *n_port = shost_priv(shost);
-       struct fc_lport *vn_port;
-       int rc = 0;
-       char buf[32];
-
-       mutex_lock(&n_port->lp_mutex);
-
-       wwn_to_str(vport->port_name, buf, sizeof(buf));
-       /* Check if the wwpn is not same as that of the lport */
-       if (!memcmp(&n_port->wwpn, &vport->port_name, sizeof(u64))) {
-               FCOE_DBG("vport WWPN 0x%s is same as that of the "
-                       "base port WWPN\n", buf);
-               rc = -EINVAL;
-               goto out;
-       }
-
-       /* Check if there is any existing vport with same wwpn */
-       list_for_each_entry(vn_port, &n_port->vports, list) {
-               if (!memcmp(&vn_port->wwpn, &vport->port_name, sizeof(u64))) {
-                       FCOE_DBG("vport with given WWPN 0x%s already "
-                       "exists\n", buf);
-                       rc = -EINVAL;
-                       break;
-               }
-       }
-
-out:
-       mutex_unlock(&n_port->lp_mutex);
-
-       return rc;
-}
index c4a93993c0cfd5f943be8fb36fad466941523356..6c6884bcf84004e7f792ccccc71bf9728cc24095 100644 (file)
@@ -80,6 +80,7 @@ do {                                                                  \
 struct fcoe_interface {
        struct list_head   list;
        struct net_device  *netdev;
+       struct net_device  *realdev;
        struct packet_type fcoe_packet_type;
        struct packet_type fip_packet_type;
        struct fcoe_ctlr   ctlr;
@@ -99,14 +100,4 @@ static inline struct net_device *fcoe_netdev(const struct fc_lport *lport)
                        ((struct fcoe_port *)lport_priv(lport))->priv)->netdev;
 }
 
-static inline void wwn_to_str(u64 wwn, char *buf, int len)
-{
-       u8 wwpn[8];
-
-       u64_to_wwn(wwn, wwpn);
-       snprintf(buf, len, "%02x%02x%02x%02x%02x%02x%02x%02x",
-               wwpn[0], wwpn[1], wwpn[2], wwpn[3],
-               wwpn[4], wwpn[5], wwpn[6], wwpn[7]);
-}
-
 #endif /* _FCOE_H_ */
index dac8e39a518897aeef1bbd7c094c51c650da2e9f..bd97b2273f20bc545c4d97aa742294777bb6fc49 100644 (file)
@@ -83,6 +83,107 @@ static struct notifier_block libfcoe_notifier = {
        .notifier_call = libfcoe_device_notification,
 };
 
+void __fcoe_get_lesb(struct fc_lport *lport,
+                    struct fc_els_lesb *fc_lesb,
+                    struct net_device *netdev)
+{
+       unsigned int cpu;
+       u32 lfc, vlfc, mdac;
+       struct fcoe_dev_stats *devst;
+       struct fcoe_fc_els_lesb *lesb;
+       struct rtnl_link_stats64 temp;
+
+       lfc = 0;
+       vlfc = 0;
+       mdac = 0;
+       lesb = (struct fcoe_fc_els_lesb *)fc_lesb;
+       memset(lesb, 0, sizeof(*lesb));
+       for_each_possible_cpu(cpu) {
+               devst = per_cpu_ptr(lport->dev_stats, cpu);
+               lfc += devst->LinkFailureCount;
+               vlfc += devst->VLinkFailureCount;
+               mdac += devst->MissDiscAdvCount;
+       }
+       lesb->lesb_link_fail = htonl(lfc);
+       lesb->lesb_vlink_fail = htonl(vlfc);
+       lesb->lesb_miss_fka = htonl(mdac);
+       lesb->lesb_fcs_error =
+                       htonl(dev_get_stats(netdev, &temp)->rx_crc_errors);
+}
+EXPORT_SYMBOL_GPL(__fcoe_get_lesb);
+
+void fcoe_wwn_to_str(u64 wwn, char *buf, int len)
+{
+       u8 wwpn[8];
+
+       u64_to_wwn(wwn, wwpn);
+       snprintf(buf, len, "%02x%02x%02x%02x%02x%02x%02x%02x",
+                wwpn[0], wwpn[1], wwpn[2], wwpn[3],
+                wwpn[4], wwpn[5], wwpn[6], wwpn[7]);
+}
+EXPORT_SYMBOL_GPL(fcoe_wwn_to_str);
+
+/**
+ * fcoe_validate_vport_create() - Validate a vport before creating it
+ * @vport: NPIV port to be created
+ *
+ * This routine is meant to add validation for a vport before creating it
+ * via fcoe_vport_create().
+ * Current validations are:
+ *      - WWPN supplied is unique for given lport
+ */
+int fcoe_validate_vport_create(struct fc_vport *vport)
+{
+       struct Scsi_Host *shost = vport_to_shost(vport);
+       struct fc_lport *n_port = shost_priv(shost);
+       struct fc_lport *vn_port;
+       int rc = 0;
+       char buf[32];
+
+       mutex_lock(&n_port->lp_mutex);
+
+       fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf));
+       /* Check if the wwpn is not same as that of the lport */
+       if (!memcmp(&n_port->wwpn, &vport->port_name, sizeof(u64))) {
+               LIBFCOE_TRANSPORT_DBG("vport WWPN 0x%s is same as that of the "
+                                     "base port WWPN\n", buf);
+               rc = -EINVAL;
+               goto out;
+       }
+
+       /* Check if there is any existing vport with same wwpn */
+       list_for_each_entry(vn_port, &n_port->vports, list) {
+               if (!memcmp(&vn_port->wwpn, &vport->port_name, sizeof(u64))) {
+                       LIBFCOE_TRANSPORT_DBG("vport with given WWPN 0x%s "
+                                             "already exists\n", buf);
+                       rc = -EINVAL;
+                       break;
+               }
+       }
+out:
+       mutex_unlock(&n_port->lp_mutex);
+       return rc;
+}
+EXPORT_SYMBOL_GPL(fcoe_validate_vport_create);
+
+/**
+ * fcoe_get_wwn() - Get the world wide name from LLD if it supports it
+ * @netdev: the associated net device
+ * @wwn: the output WWN
+ * @type: the type of WWN (WWPN or WWNN)
+ *
+ * Returns: 0 for success
+ */
+int fcoe_get_wwn(struct net_device *netdev, u64 *wwn, int type)
+{
+       const struct net_device_ops *ops = netdev->netdev_ops;
+
+       if (ops->ndo_fcoe_get_wwn)
+               return ops->ndo_fcoe_get_wwn(netdev, wwn, type);
+       return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(fcoe_get_wwn);
+
 /**
  * fcoe_fc_crc() - Calculates the CRC for a given frame
  * @fp: The frame to be checksumed
index b200b736b000dc357ba2e416fb899b394c12fd3a..9825ecf3495793cc5a6c1b166337d9ab85a0cf58 100644 (file)
@@ -3438,10 +3438,8 @@ static __devinit int hpsa_kdump_hard_reset_controller(struct pci_dev *pdev)
        } else {
                use_doorbell = misc_fw_support & MISC_FW_DOORBELL_RESET;
                if (use_doorbell) {
-                       dev_warn(&pdev->dev, "Controller claims that "
-                               "'Bit 2 doorbell reset' is "
-                               "supported, but not 'bit 5 doorbell reset'.  "
-                               "Firmware update is recommended.\n");
+                       dev_warn(&pdev->dev, "Soft reset not supported. "
+                               "Firmware update is required.\n");
                        rc = -ENOTSUPP; /* try soft reset */
                        goto unmap_cfgtable;
                }
index 8d636301e32c4ba289bffe22300739b396ccd566..73e24b48dced4d10a6f1139f75ebfab1fcebba5e 100644 (file)
@@ -2901,7 +2901,7 @@ static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
 
        spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
 
-       if (ioa_cfg->sdt_state != GET_DUMP) {
+       if (ioa_cfg->sdt_state != READ_DUMP) {
                spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
                return;
        }
@@ -3097,7 +3097,7 @@ static void ipr_worker_thread(struct work_struct *work)
        ENTER;
        spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
 
-       if (ioa_cfg->sdt_state == GET_DUMP) {
+       if (ioa_cfg->sdt_state == READ_DUMP) {
                dump = ioa_cfg->dump;
                if (!dump) {
                        spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
@@ -3109,7 +3109,7 @@ static void ipr_worker_thread(struct work_struct *work)
                kref_put(&dump->kref, ipr_release_dump);
 
                spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
-               if (ioa_cfg->sdt_state == DUMP_OBTAINED)
+               if (ioa_cfg->sdt_state == DUMP_OBTAINED && !ioa_cfg->dump_timeout)
                        ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
                spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
                return;
@@ -3751,14 +3751,6 @@ static ssize_t ipr_store_update_fw(struct device *dev,
 
        image_hdr = (struct ipr_ucode_image_header *)fw_entry->data;
 
-       if (be32_to_cpu(image_hdr->header_length) > fw_entry->size ||
-           (ioa_cfg->vpd_cbs->page3_data.card_type &&
-            ioa_cfg->vpd_cbs->page3_data.card_type != image_hdr->card_type)) {
-               dev_err(&ioa_cfg->pdev->dev, "Invalid microcode buffer\n");
-               release_firmware(fw_entry);
-               return -EINVAL;
-       }
-
        src = (u8 *)image_hdr + be32_to_cpu(image_hdr->header_length);
        dnld_size = fw_entry->size - be32_to_cpu(image_hdr->header_length);
        sglist = ipr_alloc_ucode_buffer(dnld_size);
@@ -3777,6 +3769,8 @@ static ssize_t ipr_store_update_fw(struct device *dev,
                goto out;
        }
 
+       ipr_info("Updating microcode, please be patient.  This may take up to 30 minutes.\n");
+
        result = ipr_update_ioa_ucode(ioa_cfg, sglist);
 
        if (!result)
@@ -7449,8 +7443,11 @@ static int ipr_reset_wait_for_dump(struct ipr_cmnd *ipr_cmd)
        struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
 
        if (ioa_cfg->sdt_state == GET_DUMP)
+               ioa_cfg->sdt_state = WAIT_FOR_DUMP;
+       else if (ioa_cfg->sdt_state == READ_DUMP)
                ioa_cfg->sdt_state = ABORT_DUMP;
 
+       ioa_cfg->dump_timeout = 1;
        ipr_cmd->job_step = ipr_reset_alert;
 
        return IPR_RC_JOB_CONTINUE;
@@ -7614,6 +7611,8 @@ static int ipr_reset_restore_cfg_space(struct ipr_cmnd *ipr_cmd)
                ipr_cmd->job_step = ipr_reset_enable_ioa;
 
                if (GET_DUMP == ioa_cfg->sdt_state) {
+                       ioa_cfg->sdt_state = READ_DUMP;
+                       ioa_cfg->dump_timeout = 0;
                        if (ioa_cfg->sis64)
                                ipr_reset_start_timer(ipr_cmd, IPR_SIS64_DUMP_TIMEOUT);
                        else
@@ -8003,8 +8002,12 @@ static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
        if (ioa_cfg->ioa_is_dead)
                return;
 
-       if (ioa_cfg->in_reset_reload && ioa_cfg->sdt_state == GET_DUMP)
-               ioa_cfg->sdt_state = ABORT_DUMP;
+       if (ioa_cfg->in_reset_reload) {
+               if (ioa_cfg->sdt_state == GET_DUMP)
+                       ioa_cfg->sdt_state = WAIT_FOR_DUMP;
+               else if (ioa_cfg->sdt_state == READ_DUMP)
+                       ioa_cfg->sdt_state = ABORT_DUMP;
+       }
 
        if (ioa_cfg->reset_retries++ >= IPR_NUM_RESET_RELOAD_RETRIES) {
                dev_err(&ioa_cfg->pdev->dev,
@@ -8812,7 +8815,7 @@ static int __devinit ipr_probe_ioa(struct pci_dev *pdev,
        uproc = readl(ioa_cfg->regs.sense_uproc_interrupt_reg32);
        if ((mask & IPR_PCII_HRRQ_UPDATED) == 0 || (uproc & IPR_UPROCI_RESET_ALERT))
                ioa_cfg->needs_hard_reset = 1;
-       if (interrupts & IPR_PCII_ERROR_INTERRUPTS)
+       if ((interrupts & IPR_PCII_ERROR_INTERRUPTS) || reset_devices)
                ioa_cfg->needs_hard_reset = 1;
        if (interrupts & IPR_PCII_IOA_UNIT_CHECKED)
                ioa_cfg->ioa_unit_checked = 1;
index f93f8637c5a18380d0145c2650e963fddeb2ce7d..6d257e0dd6a57e8b7b7c6448e5430ba3bb483568 100644 (file)
 #define IPR_CANCEL_ALL_TIMEOUT         (ipr_fastfail ? 10 * HZ : 30 * HZ)
 #define IPR_ABORT_TASK_TIMEOUT         (ipr_fastfail ? 10 * HZ : 30 * HZ)
 #define IPR_INTERNAL_TIMEOUT                   (ipr_fastfail ? 10 * HZ : 30 * HZ)
-#define IPR_WRITE_BUFFER_TIMEOUT               (10 * 60 * HZ)
+#define IPR_WRITE_BUFFER_TIMEOUT               (30 * 60 * HZ)
 #define IPR_SET_SUP_DEVICE_TIMEOUT             (2 * 60 * HZ)
 #define IPR_REQUEST_SENSE_TIMEOUT              (10 * HZ)
 #define IPR_OPERATIONAL_TIMEOUT                (5 * 60)
@@ -1360,6 +1360,7 @@ enum ipr_sdt_state {
        INACTIVE,
        WAIT_FOR_DUMP,
        GET_DUMP,
+       READ_DUMP,
        ABORT_DUMP,
        DUMP_OBTAINED
 };
@@ -1384,6 +1385,7 @@ struct ipr_ioa_cfg {
        u8 needs_warm_reset:1;
        u8 msi_received:1;
        u8 sis64:1;
+       u8 dump_timeout:1;
 
        u8 revid;
 
index 6981b773a88d42bdf9e7213e31844d2c22711317..f07f30fada1bc1d66bd274cdb54d8582569c1ef5 100644 (file)
@@ -1263,6 +1263,10 @@ void isci_host_deinit(struct isci_host *ihost)
 {
        int i;
 
+       /* disable output data selects */
+       for (i = 0; i < isci_gpio_count(ihost); i++)
+               writel(SGPIO_HW_CONTROL, &ihost->scu_registers->peg0.sgpio.output_data_select[i]);
+
        isci_host_change_state(ihost, isci_stopping);
        for (i = 0; i < SCI_MAX_PORTS; i++) {
                struct isci_port *iport = &ihost->ports[i];
@@ -1281,6 +1285,12 @@ void isci_host_deinit(struct isci_host *ihost)
        spin_unlock_irq(&ihost->scic_lock);
 
        wait_for_stop(ihost);
+
+       /* disable sgpio: where the above wait should give time for the
+        * enclosure to sample the gpios going inactive
+        */
+       writel(0, &ihost->scu_registers->peg0.sgpio.interface_control);
+
        sci_controller_reset(ihost);
 
        /* Cancel any/all outstanding port timers */
@@ -2365,6 +2375,12 @@ int isci_host_init(struct isci_host *ihost)
        for (i = 0; i < SCI_MAX_PHYS; i++)
                isci_phy_init(&ihost->phys[i], ihost, i);
 
+       /* enable sgpio */
+       writel(1, &ihost->scu_registers->peg0.sgpio.interface_control);
+       for (i = 0; i < isci_gpio_count(ihost); i++)
+               writel(SGPIO_HW_CONTROL, &ihost->scu_registers->peg0.sgpio.output_data_select[i]);
+       writel(0, &ihost->scu_registers->peg0.sgpio.vendor_specific_code);
+
        for (i = 0; i < SCI_MAX_REMOTE_DEVICES; i++) {
                struct isci_remote_device *idev = &ihost->devices[i];
 
@@ -2760,3 +2776,56 @@ enum sci_task_status sci_controller_start_task(struct isci_host *ihost,
 
        return status;
 }
+
+static int sci_write_gpio_tx_gp(struct isci_host *ihost, u8 reg_index, u8 reg_count, u8 *write_data)
+{
+       int d;
+
+       /* no support for TX_GP_CFG */
+       if (reg_index == 0)
+               return -EINVAL;
+
+       for (d = 0; d < isci_gpio_count(ihost); d++) {
+               u32 val = 0x444; /* all ODx.n clear */
+               int i;
+
+               for (i = 0; i < 3; i++) {
+                       int bit = (i << 2) + 2;
+
+                       bit = try_test_sas_gpio_gp_bit(to_sas_gpio_od(d, i),
+                                                      write_data, reg_index,
+                                                      reg_count);
+                       if (bit < 0)
+                               break;
+
+                       /* if od is set, clear the 'invert' bit */
+                       val &= ~(bit << ((i << 2) + 2));
+               }
+
+               if (i < 3)
+                       break;
+               writel(val, &ihost->scu_registers->peg0.sgpio.output_data_select[d]);
+       }
+
+       /* unless reg_index is > 1, we should always be able to write at
+        * least one register
+        */
+       return d > 0;
+}
+
+int isci_gpio_write(struct sas_ha_struct *sas_ha, u8 reg_type, u8 reg_index,
+                   u8 reg_count, u8 *write_data)
+{
+       struct isci_host *ihost = sas_ha->lldd_ha;
+       int written;
+
+       switch (reg_type) {
+       case SAS_GPIO_REG_TX_GP:
+               written = sci_write_gpio_tx_gp(ihost, reg_index, reg_count, write_data);
+               break;
+       default:
+               written = -EINVAL;
+       }
+
+       return written;
+}
index 9f33831a2f04ae211e43000d2b3fb4d773708fa6..646051afd3cbd07e2ab6761a18edef7355cf39f6 100644 (file)
@@ -440,6 +440,18 @@ static inline bool is_c0(struct pci_dev *pdev)
        return false;
 }
 
+/* set hw control for 'activity', even though active enclosures seem to drive
+ * the activity led on their own.  Skip setting FSENG control on 'status' due
+ * to unexpected operation and 'error' due to not being a supported automatic
+ * FSENG output
+ */
+#define SGPIO_HW_CONTROL 0x00000443
+
+static inline int isci_gpio_count(struct isci_host *ihost)
+{
+       return ARRAY_SIZE(ihost->scu_registers->peg0.sgpio.output_data_select);
+}
+
 void sci_controller_post_request(struct isci_host *ihost,
                                      u32 request);
 void sci_controller_release_frame(struct isci_host *ihost,
@@ -542,4 +554,7 @@ void sci_port_configuration_agent_construct(
 enum sci_status sci_port_configuration_agent_initialize(
        struct isci_host *ihost,
        struct sci_port_configuration_agent *port_agent);
+
+int isci_gpio_write(struct sas_ha_struct *, u8 reg_type, u8 reg_index,
+                   u8 reg_count, u8 *write_data);
 #endif
index 29aa34efb0f5bd03e3165e0918f9fed9c72b4cd3..43fe840fbe9c3427127ad0eac99a0f3b4b45aacb 100644 (file)
@@ -192,6 +192,9 @@ static struct sas_domain_function_template isci_transport_ops  = {
 
        /* Phy management */
        .lldd_control_phy       = isci_phy_control,
+
+       /* GPIO support */
+       .lldd_write_gpio        = isci_gpio_write,
 };
 
 
index d1de63312e7f3cc544b7487ad87a297449dc2c01..8efeb6b083213bb20d15ca3a9ca0a954515ec23f 100644 (file)
@@ -97,7 +97,7 @@
 #define SCU_MAX_COMPLETION_QUEUE_SHIFT   (ilog2(SCU_MAX_COMPLETION_QUEUE_ENTRIES))
 
 #define SCU_ABSOLUTE_MAX_UNSOLICITED_FRAMES (4096)
-#define SCU_UNSOLICITED_FRAME_BUFFER_SIZE   (1024)
+#define SCU_UNSOLICITED_FRAME_BUFFER_SIZE   (1024U)
 #define SCU_INVALID_FRAME_INDEX             (0xFFFF)
 
 #define SCU_IO_REQUEST_MAX_SGE_SIZE         (0x00FFFFFF)
index 09e61134037fe877f20937721f5f1c6e13f6e5c2..35f50c2183e18a4c6460b07db081bb7d82ff6beb 100644 (file)
@@ -1313,6 +1313,17 @@ int isci_phy_control(struct asd_sas_phy *sas_phy,
                ret = isci_port_perform_hard_reset(ihost, iport, iphy);
 
                break;
+       case PHY_FUNC_GET_EVENTS: {
+               struct scu_link_layer_registers __iomem *r;
+               struct sas_phy *phy = sas_phy->phy;
+
+               r = iphy->link_layer_registers;
+               phy->running_disparity_error_count = readl(&r->running_disparity_error_count);
+               phy->loss_of_dword_sync_count = readl(&r->loss_of_sync_error_count);
+               phy->phy_reset_problem_count = readl(&r->phy_reset_problem_count);
+               phy->invalid_dword_count = readl(&r->invalid_dword_counter);
+               break;
+       }
 
        default:
                dev_dbg(&ihost->pdev->dev,
index 8f6f9b77e41a45f46cfbe358af0e732307d8b26f..8e59c8865dcdc06911bdda139088825230e95692 100644 (file)
@@ -294,8 +294,8 @@ static void isci_port_link_down(struct isci_host *isci_host,
                                        __func__, isci_device);
                                set_bit(IDEV_GONE, &isci_device->flags);
                        }
+                       isci_port_change_state(isci_port, isci_stopping);
                }
-               isci_port_change_state(isci_port, isci_stopping);
        }
 
        /* Notify libsas of the borken link, this will trigger calls to our
index 486b113c634a4810652f11a4aa197c551a07c390..38a99d2811411d102220a96bdf918579fb47546b 100644 (file)
@@ -678,7 +678,7 @@ static void apc_agent_timeout(unsigned long data)
        configure_phy_mask = ~port_agent->phy_configured_mask & port_agent->phy_ready_mask;
 
        if (!configure_phy_mask)
-               return;
+               goto done;
 
        for (index = 0; index < SCI_MAX_PHYS; index++) {
                if ((configure_phy_mask & (1 << index)) == 0)
index 00afc738bbed368baacef402058a1639ebabf248..eaa541afc7550a0b2c9d06a6ccae8fc61f1e3c30 100644 (file)
@@ -875,122 +875,6 @@ struct scu_iit_entry {
 #define SCU_PTSxSR_GEN_BIT(name) \
        SCU_GEN_BIT(SCU_PTSG_PORT_TASK_SCHEDULER_STATUS_ ## name)
 
-
-/*
- * *****************************************************************************
- * * SGPIO Register shift and mask values
- * ***************************************************************************** */
-#define SCU_SGPIO_CONTROL_SGPIO_ENABLE_SHIFT                    (0)
-#define SCU_SGPIO_CONTROL_SGPIO_ENABLE_MASK                     (0x00000001)
-#define SCU_SGPIO_CONTROL_SGPIO_SERIAL_CLOCK_SELECT_SHIFT       (1)
-#define SCU_SGPIO_CONTROL_SGPIO_SERIAL_CLOCK_SELECT_MASK        (0x00000002)
-#define SCU_SGPIO_CONTROL_SGPIO_SERIAL_SHIFT_WIDTH_SELECT_SHIFT (2)
-#define SCU_SGPIO_CONTROL_SGPIO_SERIAL_SHIFT_WIDTH_SELECT_MASK  (0x00000004)
-#define SCU_SGPIO_CONTROL_SGPIO_TEST_BIT_SHIFT                  (15)
-#define SCU_SGPIO_CONTROL_SGPIO_TEST_BIT_MASK                   (0x00008000)
-#define SCU_SGPIO_CONTROL_SGPIO_RESERVED_MASK                   (0xFFFF7FF8)
-
-#define SCU_SGICRx_GEN_BIT(name) \
-       SCU_GEN_BIT(SCU_SGPIO_CONTROL_SGPIO_ ## name)
-
-#define SCU_SGPIO_PROGRAMMABLE_BLINK_REGISTER_R0_SHIFT      (0)
-#define SCU_SGPIO_PROGRAMMABLE_BLINK_REGISTER_R0_MASK       (0x0000000F)
-#define SCU_SGPIO_PROGRAMMABLE_BLINK_REGISTER_R1_SHIFT      (4)
-#define SCU_SGPIO_PROGRAMMABLE_BLINK_REGISTER_R1_MASK       (0x000000F0)
-#define SCU_SGPIO_PROGRAMMABLE_BLINK_REGISTER_R2_SHIFT      (8)
-#define SCU_SGPIO_PROGRAMMABLE_BLINK_REGISTER_R2_MASK       (0x00000F00)
-#define SCU_SGPIO_PROGRAMMABLE_BLINK_REGISTER_R3_SHIFT      (12)
-#define SCU_SGPIO_PROGRAMMABLE_BLINK_REGISTER_R3_MASK       (0x0000F000)
-#define SCU_SGPIO_PROGRAMMABLE_BLINK_REGISTER_RESERVED_MASK (0xFFFF0000)
-
-#define SCU_SGPBRx_GEN_VAL(name, value)        \
-       SCU_GEN_VALUE(SCU_SGPIO_PROGRAMMABLE_BLINK_REGISTER_ ## name, value)
-
-#define SCU_SGPIO_START_DRIVE_LOWER_R0_SHIFT        (0)
-#define SCU_SGPIO_START_DRIVE_LOWER_R0_MASK         (0x00000003)
-#define SCU_SGPIO_START_DRIVE_LOWER_R1_SHIFT        (4)
-#define SCU_SGPIO_START_DRIVE_LOWER_R1_MASK         (0x00000030)
-#define SCU_SGPIO_START_DRIVE_LOWER_R2_SHIFT        (8)
-#define SCU_SGPIO_START_DRIVE_LOWER_R2_MASK         (0x00000300)
-#define SCU_SGPIO_START_DRIVE_LOWER_R3_SHIFT        (12)
-#define SCU_SGPIO_START_DRIVE_LOWER_R3_MASK         (0x00003000)
-#define SCU_SGPIO_START_DRIVE_LOWER_RESERVED_MASK   (0xFFFF8888)
-
-#define SCU_SGSDLRx_GEN_VAL(name, value) \
-       SCU_GEN_VALUE(SCU_SGPIO_START_DRIVE_LOWER_ ## name, value)
-
-#define SCU_SGPIO_START_DRIVE_UPPER_R0_SHIFT        (0)
-#define SCU_SGPIO_START_DRIVE_UPPER_R0_MASK         (0x00000003)
-#define SCU_SGPIO_START_DRIVE_UPPER_R1_SHIFT        (4)
-#define SCU_SGPIO_START_DRIVE_UPPER_R1_MASK         (0x00000030)
-#define SCU_SGPIO_START_DRIVE_UPPER_R2_SHIFT        (8)
-#define SCU_SGPIO_START_DRIVE_UPPER_R2_MASK         (0x00000300)
-#define SCU_SGPIO_START_DRIVE_UPPER_R3_SHIFT        (12)
-#define SCU_SGPIO_START_DRIVE_UPPER_R3_MASK         (0x00003000)
-#define SCU_SGPIO_START_DRIVE_UPPER_RESERVED_MASK   (0xFFFF8888)
-
-#define SCU_SGSDURx_GEN_VAL(name, value) \
-       SCU_GEN_VALUE(SCU_SGPIO_START_DRIVE_LOWER_ ## name, value)
-
-#define SCU_SGPIO_SERIAL_INPUT_DATA_LOWER_D0_SHIFT      (0)
-#define SCU_SGPIO_SERIAL_INPUT_DATA_LOWER_D0_MASK       (0x00000003)
-#define SCU_SGPIO_SERIAL_INPUT_DATA_LOWER_D1_SHIFT      (4)
-#define SCU_SGPIO_SERIAL_INPUT_DATA_LOWER_D1_MASK       (0x00000030)
-#define SCU_SGPIO_SERIAL_INPUT_DATA_LOWER_D2_SHIFT      (8)
-#define SCU_SGPIO_SERIAL_INPUT_DATA_LOWER_D2_MASK       (0x00000300)
-#define SCU_SGPIO_SERIAL_INPUT_DATA_LOWER_D3_SHIFT      (12)
-#define SCU_SGPIO_SERIAL_INPUT_DATA_LOWER_D3_MASK       (0x00003000)
-#define SCU_SGPIO_SERIAL_INPUT_DATA_LOWER_RESERVED_MASK (0xFFFF8888)
-
-#define SCU_SGSIDLRx_GEN_VAL(name, value) \
-       SCU_GEN_VALUE(SCU_SGPIO_SERIAL_INPUT_DATA_LOWER_ ## name, value)
-
-#define SCU_SGPIO_SERIAL_INPUT_DATA_UPPER_D0_SHIFT      (0)
-#define SCU_SGPIO_SERIAL_INPUT_DATA_UPPER_D0_MASK       (0x00000003)
-#define SCU_SGPIO_SERIAL_INPUT_DATA_UPPER_D1_SHIFT      (4)
-#define SCU_SGPIO_SERIAL_INPUT_DATA_UPPER_D1_MASK       (0x00000030)
-#define SCU_SGPIO_SERIAL_INPUT_DATA_UPPER_D2_SHIFT      (8)
-#define SCU_SGPIO_SERIAL_INPUT_DATA_UPPER_D2_MASK       (0x00000300)
-#define SCU_SGPIO_SERIAL_INPUT_DATA_UPPER_D3_SHIFT      (12)
-#define SCU_SGPIO_SERIAL_INPUT_DATA_UPPER_D3_MASK       (0x00003000)
-#define SCU_SGPIO_SERIAL_INPUT_DATA_UPPER_RESERVED_MASK (0xFFFF8888)
-
-#define SCU_SGSIDURx_GEN_VAL(name, value) \
-       SCU_GEN_VALUE(SCU_SGPIO_SERIAL_INPUT_DATA_LOWER_ ## name, value)
-
-#define SCU_SGPIO_VENDOR_SPECIFIC_CODE_SHIFT            (0)
-#define SCU_SGPIO_VENDOR_SPECIFIC_CODE_MASK             (0x0000000F)
-#define SCU_SGPIO_VENDOR_SPECIFIC_CODE_RESERVED_MASK    (0xFFFFFFF0)
-
-#define SCU_SGVSCR_GEN_VAL(value) \
-       SCU_GEN_VALUE(SCU_SGPIO_VENDOR_SPECIFIC_CODE ## name, value)
-
-#define SCU_SGPIO_OUPUT_DATA_SELECT_INPUT_DATA0_SHIFT           (0)
-#define SCU_SGPIO_OUPUT_DATA_SELECT_INPUT_DATA0_MASK            (0x00000003)
-#define SCU_SGPIO_OUPUT_DATA_SELECT_INVERT_INPUT_DATA0_SHIFT    (2)
-#define SCU_SGPIO_OUPUT_DATA_SELECT_INVERT_INPUT_DATA0_MASK     (0x00000004)
-#define SCU_SGPIO_OUPUT_DATA_SELECT_JOG_ENABLE_DATA0_SHIFT      (3)
-#define SCU_SGPIO_OUPUT_DATA_SELECT_JOG_ENABLE_DATA0_MASK       (0x00000008)
-#define SCU_SGPIO_OUPUT_DATA_SELECT_INPUT_DATA1_SHIFT           (4)
-#define SCU_SGPIO_OUPUT_DATA_SELECT_INPUT_DATA1_MASK            (0x00000030)
-#define SCU_SGPIO_OUPUT_DATA_SELECT_INVERT_INPUT_DATA1_SHIFT    (6)
-#define SCU_SGPIO_OUPUT_DATA_SELECT_INVERT_INPUT_DATA1_MASK     (0x00000040)
-#define SCU_SGPIO_OUPUT_DATA_SELECT_JOG_ENABLE_DATA1_SHIFT      (7)
-#define SCU_SGPIO_OUPUT_DATA_SELECT_JOG_ENABLE_DATA1_MASK       (0x00000080)
-#define SCU_SGPIO_OUPUT_DATA_SELECT_INPUT_DATA2_SHIFT           (8)
-#define SCU_SGPIO_OUPUT_DATA_SELECT_INPUT_DATA2_MASK            (0x00000300)
-#define SCU_SGPIO_OUPUT_DATA_SELECT_INVERT_INPUT_DATA2_SHIFT    (10)
-#define SCU_SGPIO_OUPUT_DATA_SELECT_INVERT_INPUT_DATA2_MASK     (0x00000400)
-#define SCU_SGPIO_OUPUT_DATA_SELECT_JOG_ENABLE_DATA2_SHIFT      (11)
-#define SCU_SGPIO_OUPUT_DATA_SELECT_JOG_ENABLE_DATA2_MASK       (0x00000800)
-#define SCU_SGPIO_OUPUT_DATA_SELECT_RESERVED_MASK               (0xFFFFF000)
-
-#define SCU_SGODSR_GEN_VAL(name, value)        \
-       SCU_GEN_VALUE(SCU_SGPIO_OUPUT_DATA_SELECT_ ## name, value)
-
-#define SCU_SGODSR_GEN_BIT(name) \
-       SCU_GEN_BIT(SCU_SGPIO_OUPUT_DATA_SELECT_ ## name)
-
 /*
  * *****************************************************************************
  * * SMU Registers
@@ -1529,10 +1413,12 @@ struct scu_sgpio_registers {
        u32 serial_input_upper;
 /* 0x0018 SGPIO_SGVSCR */
        u32 vendor_specific_code;
+/* 0x001C Reserved */
+       u32 reserved_001c;
 /* 0x0020 SGPIO_SGODSR */
-       u32 ouput_data_select[8];
+       u32 output_data_select[8];
 /* Remainder of memory space 256 bytes */
-       u32 reserved_1444_14ff[0x31];
+       u32 reserved_1444_14ff[0x30];
 
 };
 
index b6e6368c2665e610bd8efdd7abf5b299bedf7e7e..fbf9ce28c3f5f92774e0ec1465ad4688e4c8b7d8 100644 (file)
@@ -386,6 +386,18 @@ static bool is_remote_device_ready(struct isci_remote_device *idev)
        }
 }
 
+/*
+ * called once the remote node context has transisitioned to a ready
+ * state (after suspending RX and/or TX due to early D2H fis)
+ */
+static void atapi_remote_device_resume_done(void *_dev)
+{
+       struct isci_remote_device *idev = _dev;
+       struct isci_request *ireq = idev->working_request;
+
+       sci_change_state(&ireq->sm, SCI_REQ_COMPLETED);
+}
+
 enum sci_status sci_remote_device_event_handler(struct isci_remote_device *idev,
                                                     u32 event_code)
 {
@@ -432,6 +444,16 @@ enum sci_status sci_remote_device_event_handler(struct isci_remote_device *idev,
        if (status != SCI_SUCCESS)
                return status;
 
+       if (state == SCI_STP_DEV_ATAPI_ERROR) {
+               /* For ATAPI error state resume the RNC right away. */
+               if (scu_get_event_type(event_code) == SCU_EVENT_TYPE_RNC_SUSPEND_TX ||
+                   scu_get_event_type(event_code) == SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX) {
+                       return sci_remote_node_context_resume(&idev->rnc,
+                                                             atapi_remote_device_resume_done,
+                                                             idev);
+               }
+       }
+
        if (state == SCI_STP_DEV_IDLE) {
 
                /* We pick up suspension events to handle specifically to this
@@ -625,6 +647,7 @@ enum sci_status sci_remote_device_complete_io(struct isci_host *ihost,
        case SCI_STP_DEV_CMD:
        case SCI_STP_DEV_NCQ:
        case SCI_STP_DEV_NCQ_ERROR:
+       case SCI_STP_DEV_ATAPI_ERROR:
                status = common_complete_io(iport, idev, ireq);
                if (status != SCI_SUCCESS)
                        break;
@@ -1020,6 +1043,7 @@ static const struct sci_base_state sci_remote_device_state_table[] = {
        [SCI_STP_DEV_NCQ_ERROR] = {
                .enter_state = sci_stp_remote_device_ready_ncq_error_substate_enter,
        },
+       [SCI_STP_DEV_ATAPI_ERROR] = { },
        [SCI_STP_DEV_AWAIT_RESET] = { },
        [SCI_SMP_DEV_IDLE] = {
                .enter_state = sci_smp_remote_device_ready_idle_substate_enter,
index 57ccfc3d6ad304ae79b806f6d46694040bb1b72f..e1747ea0d0ea13ae42713a2d18ed0c1ea07574f3 100644 (file)
@@ -243,6 +243,15 @@ enum sci_remote_device_states {
         */
        SCI_STP_DEV_NCQ_ERROR,
 
+       /**
+        * This is the ATAPI error state for the STP ATAPI remote device.
+        * This state is entered when ATAPI device sends error status FIS
+        * without data while the device object is in CMD state.
+        * A suspension event is expected in this state.
+        * The device object will resume right away.
+        */
+       SCI_STP_DEV_ATAPI_ERROR,
+
        /**
         * This is the READY substate indicates the device is waiting for the RESET task
         * coming to be recovered from certain hardware specific error.
index b5d3a8c4d3297ebf87e72a8087d5277500abc17d..565a9f0a9bc2d176ea669f68a9cedcef703fd911 100644 (file)
@@ -481,7 +481,29 @@ static void sci_stp_optimized_request_construct(struct isci_request *ireq,
        }
 }
 
+static void sci_atapi_construct(struct isci_request *ireq)
+{
+       struct host_to_dev_fis *h2d_fis = &ireq->stp.cmd;
+       struct sas_task *task;
+
+       /* To simplify the implementation we take advantage of the
+        * silicon's partial acceleration of atapi protocol (dma data
+        * transfers), so we promote all commands to dma protocol.  This
+        * breaks compatibility with ATA_HORKAGE_ATAPI_MOD16_DMA drives.
+        */
+       h2d_fis->features |= ATAPI_PKT_DMA;
 
+       scu_stp_raw_request_construct_task_context(ireq);
+
+       task = isci_request_access_task(ireq);
+       if (task->data_dir == DMA_NONE)
+               task->total_xfer_len = 0;
+
+       /* clear the response so we can detect arrivial of an
+        * unsolicited h2d fis
+        */
+       ireq->stp.rsp.fis_type = 0;
+}
 
 static enum sci_status
 sci_io_request_construct_sata(struct isci_request *ireq,
@@ -491,6 +513,7 @@ sci_io_request_construct_sata(struct isci_request *ireq,
 {
        enum sci_status status = SCI_SUCCESS;
        struct sas_task *task = isci_request_access_task(ireq);
+       struct domain_device *dev = ireq->target_device->domain_dev;
 
        /* check for management protocols */
        if (ireq->ttype == tmf_task) {
@@ -519,6 +542,13 @@ sci_io_request_construct_sata(struct isci_request *ireq,
 
        }
 
+       /* ATAPI */
+       if (dev->sata_dev.command_set == ATAPI_COMMAND_SET &&
+           task->ata_task.fis.command == ATA_CMD_PACKET) {
+               sci_atapi_construct(ireq);
+               return SCI_SUCCESS;
+       }
+
        /* non data */
        if (task->data_dir == DMA_NONE) {
                scu_stp_raw_request_construct_task_context(ireq);
@@ -627,7 +657,7 @@ enum sci_status sci_task_request_construct_sata(struct isci_request *ireq)
 
 /**
  * sci_req_tx_bytes - bytes transferred when reply underruns request
- * @sci_req: request that was terminated early
+ * @ireq: request that was terminated early
  */
 #define SCU_TASK_CONTEXT_SRAM 0x200000
 static u32 sci_req_tx_bytes(struct isci_request *ireq)
@@ -729,6 +759,10 @@ sci_io_request_terminate(struct isci_request *ireq)
        case SCI_REQ_STP_SOFT_RESET_WAIT_H2D_ASSERTED:
        case SCI_REQ_STP_SOFT_RESET_WAIT_H2D_DIAG:
        case SCI_REQ_STP_SOFT_RESET_WAIT_D2H:
+       case SCI_REQ_ATAPI_WAIT_H2D:
+       case SCI_REQ_ATAPI_WAIT_PIO_SETUP:
+       case SCI_REQ_ATAPI_WAIT_D2H:
+       case SCI_REQ_ATAPI_WAIT_TC_COMP:
                sci_change_state(&ireq->sm, SCI_REQ_ABORTING);
                return SCI_SUCCESS;
        case SCI_REQ_TASK_WAIT_TC_RESP:
@@ -1194,8 +1228,8 @@ static enum sci_status sci_stp_request_pio_data_out_transmit_data(struct isci_re
 {
        struct isci_stp_request *stp_req = &ireq->stp.req;
        struct scu_sgl_element_pair *sgl_pair;
+       enum sci_status status = SCI_SUCCESS;
        struct scu_sgl_element *sgl;
-       enum sci_status status;
        u32 offset;
        u32 len = 0;
 
@@ -1249,7 +1283,7 @@ static enum sci_status sci_stp_request_pio_data_out_transmit_data(struct isci_re
  */
 static enum sci_status
 sci_stp_request_pio_data_in_copy_data_buffer(struct isci_stp_request *stp_req,
-                                                 u8 *data_buf, u32 len)
+                                            u8 *data_buf, u32 len)
 {
        struct isci_request *ireq;
        u8 *src_addr;
@@ -1423,6 +1457,128 @@ static enum sci_status sci_stp_request_udma_general_frame_handler(struct isci_re
        return status;
 }
 
+static enum sci_status process_unsolicited_fis(struct isci_request *ireq,
+                                              u32 frame_index)
+{
+       struct isci_host *ihost = ireq->owning_controller;
+       enum sci_status status;
+       struct dev_to_host_fis *frame_header;
+       u32 *frame_buffer;
+
+       status = sci_unsolicited_frame_control_get_header(&ihost->uf_control,
+                                                         frame_index,
+                                                         (void **)&frame_header);
+
+       if (status != SCI_SUCCESS)
+               return status;
+
+       if (frame_header->fis_type != FIS_REGD2H) {
+               dev_err(&ireq->isci_host->pdev->dev,
+                       "%s ERROR: invalid fis type 0x%X\n",
+                       __func__, frame_header->fis_type);
+               return SCI_FAILURE;
+       }
+
+       sci_unsolicited_frame_control_get_buffer(&ihost->uf_control,
+                                                frame_index,
+                                                (void **)&frame_buffer);
+
+       sci_controller_copy_sata_response(&ireq->stp.rsp,
+                                         (u32 *)frame_header,
+                                         frame_buffer);
+
+       /* Frame has been decoded return it to the controller */
+       sci_controller_release_frame(ihost, frame_index);
+
+       return status;
+}
+
+static enum sci_status atapi_d2h_reg_frame_handler(struct isci_request *ireq,
+                                                  u32 frame_index)
+{
+       struct sas_task *task = isci_request_access_task(ireq);
+       enum sci_status status;
+
+       status = process_unsolicited_fis(ireq, frame_index);
+
+       if (status == SCI_SUCCESS) {
+               if (ireq->stp.rsp.status & ATA_ERR)
+                       status = SCI_IO_FAILURE_RESPONSE_VALID;
+       } else {
+               status = SCI_IO_FAILURE_RESPONSE_VALID;
+       }
+
+       if (status != SCI_SUCCESS) {
+               ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE;
+               ireq->sci_status = status;
+       } else {
+               ireq->scu_status = SCU_TASK_DONE_GOOD;
+               ireq->sci_status = SCI_SUCCESS;
+       }
+
+       /* the d2h ufi is the end of non-data commands */
+       if (task->data_dir == DMA_NONE)
+               sci_change_state(&ireq->sm, SCI_REQ_COMPLETED);
+
+       return status;
+}
+
+static void scu_atapi_reconstruct_raw_frame_task_context(struct isci_request *ireq)
+{
+       struct ata_device *dev = sas_to_ata_dev(ireq->target_device->domain_dev);
+       void *atapi_cdb = ireq->ttype_ptr.io_task_ptr->ata_task.atapi_packet;
+       struct scu_task_context *task_context = ireq->tc;
+
+       /* fill in the SCU Task Context for a DATA fis containing CDB in Raw Frame
+        * type. The TC for previous Packet fis was already there, we only need to
+        * change the H2D fis content.
+        */
+       memset(&ireq->stp.cmd, 0, sizeof(struct host_to_dev_fis));
+       memcpy(((u8 *)&ireq->stp.cmd + sizeof(u32)), atapi_cdb, ATAPI_CDB_LEN);
+       memset(&(task_context->type.stp), 0, sizeof(struct stp_task_context));
+       task_context->type.stp.fis_type = FIS_DATA;
+       task_context->transfer_length_bytes = dev->cdb_len;
+}
+
+static void scu_atapi_construct_task_context(struct isci_request *ireq)
+{
+       struct ata_device *dev = sas_to_ata_dev(ireq->target_device->domain_dev);
+       struct sas_task *task = isci_request_access_task(ireq);
+       struct scu_task_context *task_context = ireq->tc;
+       int cdb_len = dev->cdb_len;
+
+       /* reference: SSTL 1.13.4.2
+        * task_type, sata_direction
+        */
+       if (task->data_dir == DMA_TO_DEVICE) {
+               task_context->task_type = SCU_TASK_TYPE_PACKET_DMA_OUT;
+               task_context->sata_direction = 0;
+       } else {
+               /* todo: for NO_DATA command, we need to send out raw frame. */
+               task_context->task_type = SCU_TASK_TYPE_PACKET_DMA_IN;
+               task_context->sata_direction = 1;
+       }
+
+       memset(&task_context->type.stp, 0, sizeof(task_context->type.stp));
+       task_context->type.stp.fis_type = FIS_DATA;
+
+       memset(&ireq->stp.cmd, 0, sizeof(ireq->stp.cmd));
+       memcpy(&ireq->stp.cmd.lbal, task->ata_task.atapi_packet, cdb_len);
+       task_context->ssp_command_iu_length = cdb_len / sizeof(u32);
+
+       /* task phase is set to TX_CMD */
+       task_context->task_phase = 0x1;
+
+       /* retry counter */
+       task_context->stp_retry_count = 0;
+
+       /* data transfer size. */
+       task_context->transfer_length_bytes = task->total_xfer_len;
+
+       /* setup sgl */
+       sci_request_build_sgl(ireq);
+}
+
 enum sci_status
 sci_io_request_frame_handler(struct isci_request *ireq,
                                  u32 frame_index)
@@ -1490,29 +1646,30 @@ sci_io_request_frame_handler(struct isci_request *ireq,
                return SCI_SUCCESS;
 
        case SCI_REQ_SMP_WAIT_RESP: {
-               struct smp_resp *rsp_hdr = &ireq->smp.rsp;
-               void *frame_header;
+               struct sas_task *task = isci_request_access_task(ireq);
+               struct scatterlist *sg = &task->smp_task.smp_resp;
+               void *frame_header, *kaddr;
+               u8 *rsp;
 
                sci_unsolicited_frame_control_get_header(&ihost->uf_control,
-                                                             frame_index,
-                                                             &frame_header);
-
-               /* byte swap the header. */
-               word_cnt = SMP_RESP_HDR_SZ / sizeof(u32);
-               sci_swab32_cpy(rsp_hdr, frame_header, word_cnt);
+                                                        frame_index,
+                                                        &frame_header);
+               kaddr = kmap_atomic(sg_page(sg), KM_IRQ0);
+               rsp = kaddr + sg->offset;
+               sci_swab32_cpy(rsp, frame_header, 1);
 
-               if (rsp_hdr->frame_type == SMP_RESPONSE) {
+               if (rsp[0] == SMP_RESPONSE) {
                        void *smp_resp;
 
                        sci_unsolicited_frame_control_get_buffer(&ihost->uf_control,
-                                                                     frame_index,
-                                                                     &smp_resp);
-
-                       word_cnt = (sizeof(struct smp_resp) - SMP_RESP_HDR_SZ) /
-                               sizeof(u32);
+                                                                frame_index,
+                                                                &smp_resp);
 
-                       sci_swab32_cpy(((u8 *) rsp_hdr) + SMP_RESP_HDR_SZ,
-                                      smp_resp, word_cnt);
+                       word_cnt = (sg->length/4)-1;
+                       if (word_cnt > 0)
+                               word_cnt = min_t(unsigned int, word_cnt,
+                                                SCU_UNSOLICITED_FRAME_BUFFER_SIZE/4);
+                       sci_swab32_cpy(rsp + 4, smp_resp, word_cnt);
 
                        ireq->scu_status = SCU_TASK_DONE_GOOD;
                        ireq->sci_status = SCI_SUCCESS;
@@ -1528,12 +1685,13 @@ sci_io_request_frame_handler(struct isci_request *ireq,
                                __func__,
                                ireq,
                                frame_index,
-                               rsp_hdr->frame_type);
+                               rsp[0]);
 
                        ireq->scu_status = SCU_TASK_DONE_SMP_FRM_TYPE_ERR;
                        ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR;
                        sci_change_state(&ireq->sm, SCI_REQ_COMPLETED);
                }
+               kunmap_atomic(kaddr, KM_IRQ0);
 
                sci_controller_release_frame(ihost, frame_index);
 
@@ -1833,6 +1991,24 @@ sci_io_request_frame_handler(struct isci_request *ireq,
 
                return status;
        }
+       case SCI_REQ_ATAPI_WAIT_PIO_SETUP: {
+               struct sas_task *task = isci_request_access_task(ireq);
+
+               sci_controller_release_frame(ihost, frame_index);
+               ireq->target_device->working_request = ireq;
+               if (task->data_dir == DMA_NONE) {
+                       sci_change_state(&ireq->sm, SCI_REQ_ATAPI_WAIT_TC_COMP);
+                       scu_atapi_reconstruct_raw_frame_task_context(ireq);
+               } else {
+                       sci_change_state(&ireq->sm, SCI_REQ_ATAPI_WAIT_D2H);
+                       scu_atapi_construct_task_context(ireq);
+               }
+
+               sci_controller_continue_io(ireq);
+               return SCI_SUCCESS;
+       }
+       case SCI_REQ_ATAPI_WAIT_D2H:
+               return atapi_d2h_reg_frame_handler(ireq, frame_index);
        case SCI_REQ_ABORTING:
                /*
                 * TODO: Is it even possible to get an unsolicited frame in the
@@ -1898,10 +2074,9 @@ static enum sci_status stp_request_udma_await_tc_event(struct isci_request *ireq
        case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_MAX_PLD_ERR):
        case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_R_ERR):
        case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CMD_LL_R_ERR):
-       case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CRC_ERR):
                sci_remote_device_suspend(ireq->target_device,
                        SCU_EVENT_SPECIFIC(SCU_NORMALIZE_COMPLETION_STATUS(completion_code)));
-       /* Fall through to the default case */
+               /* Fall through to the default case */
        default:
                /* All other completion status cause the IO to be complete. */
                ireq->scu_status = SCU_NORMALIZE_COMPLETION_STATUS(completion_code);
@@ -1964,6 +2139,112 @@ stp_request_soft_reset_await_h2d_diagnostic_tc_event(struct isci_request *ireq,
        return SCI_SUCCESS;
 }
 
+static enum sci_status atapi_raw_completion(struct isci_request *ireq, u32 completion_code,
+                                                 enum sci_base_request_states next)
+{
+       enum sci_status status = SCI_SUCCESS;
+
+       switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
+       case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
+               ireq->scu_status = SCU_TASK_DONE_GOOD;
+               ireq->sci_status = SCI_SUCCESS;
+               sci_change_state(&ireq->sm, next);
+               break;
+       default:
+               /* All other completion status cause the IO to be complete.
+                * If a NAK was received, then it is up to the user to retry
+                * the request.
+                */
+               ireq->scu_status = SCU_NORMALIZE_COMPLETION_STATUS(completion_code);
+               ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR;
+
+               sci_change_state(&ireq->sm, SCI_REQ_COMPLETED);
+               break;
+       }
+
+       return status;
+}
+
+static enum sci_status atapi_data_tc_completion_handler(struct isci_request *ireq,
+                                                       u32 completion_code)
+{
+       struct isci_remote_device *idev = ireq->target_device;
+       struct dev_to_host_fis *d2h = &ireq->stp.rsp;
+       enum sci_status status = SCI_SUCCESS;
+
+       switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
+       case (SCU_TASK_DONE_GOOD << SCU_COMPLETION_TL_STATUS_SHIFT):
+               sci_change_state(&ireq->sm, SCI_REQ_COMPLETED);
+               break;
+
+       case (SCU_TASK_DONE_UNEXP_FIS << SCU_COMPLETION_TL_STATUS_SHIFT): {
+               u16 len = sci_req_tx_bytes(ireq);
+
+               /* likely non-error data underrrun, workaround missing
+                * d2h frame from the controller
+                */
+               if (d2h->fis_type != FIS_REGD2H) {
+                       d2h->fis_type = FIS_REGD2H;
+                       d2h->flags = (1 << 6);
+                       d2h->status = 0x50;
+                       d2h->error = 0;
+                       d2h->lbal = 0;
+                       d2h->byte_count_low = len & 0xff;
+                       d2h->byte_count_high = len >> 8;
+                       d2h->device = 0xa0;
+                       d2h->lbal_exp = 0;
+                       d2h->lbam_exp = 0;
+                       d2h->lbah_exp = 0;
+                       d2h->_r_a = 0;
+                       d2h->sector_count = 0x3;
+                       d2h->sector_count_exp = 0;
+                       d2h->_r_b = 0;
+                       d2h->_r_c = 0;
+                       d2h->_r_d = 0;
+               }
+
+               ireq->scu_status = SCU_TASK_DONE_GOOD;
+               ireq->sci_status = SCI_SUCCESS_IO_DONE_EARLY;
+               status = ireq->sci_status;
+
+               /* the hw will have suspended the rnc, so complete the
+                * request upon pending resume
+                */
+               sci_change_state(&idev->sm, SCI_STP_DEV_ATAPI_ERROR);
+               break;
+       }
+       case (SCU_TASK_DONE_EXCESS_DATA << SCU_COMPLETION_TL_STATUS_SHIFT):
+               /* In this case, there is no UF coming after.
+                * compelte the IO now.
+                */
+               ireq->scu_status = SCU_TASK_DONE_GOOD;
+               ireq->sci_status = SCI_SUCCESS;
+               sci_change_state(&ireq->sm, SCI_REQ_COMPLETED);
+               break;
+
+       default:
+               if (d2h->fis_type == FIS_REGD2H) {
+                       /* UF received change the device state to ATAPI_ERROR */
+                       status = ireq->sci_status;
+                       sci_change_state(&idev->sm, SCI_STP_DEV_ATAPI_ERROR);
+               } else {
+                       /* If receiving any non-sucess TC status, no UF
+                        * received yet, then an UF for the status fis
+                        * is coming after (XXX: suspect this is
+                        * actually a protocol error or a bug like the
+                        * DONE_UNEXP_FIS case)
+                        */
+                       ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE;
+                       ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID;
+
+                       sci_change_state(&ireq->sm, SCI_REQ_ATAPI_WAIT_D2H);
+               }
+               break;
+       }
+
+       return status;
+}
+
 enum sci_status
 sci_io_request_tc_completion(struct isci_request *ireq,
                                  u32 completion_code)
@@ -2015,6 +2296,17 @@ sci_io_request_tc_completion(struct isci_request *ireq,
                return request_aborting_state_tc_event(ireq,
                                                       completion_code);
 
+       case SCI_REQ_ATAPI_WAIT_H2D:
+               return atapi_raw_completion(ireq, completion_code,
+                                           SCI_REQ_ATAPI_WAIT_PIO_SETUP);
+
+       case SCI_REQ_ATAPI_WAIT_TC_COMP:
+               return atapi_raw_completion(ireq, completion_code,
+                                           SCI_REQ_ATAPI_WAIT_D2H);
+
+       case SCI_REQ_ATAPI_WAIT_D2H:
+               return atapi_data_tc_completion_handler(ireq, completion_code);
+
        default:
                dev_warn(&ihost->pdev->dev,
                         "%s: SCIC IO Request given task completion "
@@ -2421,6 +2713,8 @@ static void isci_process_stp_response(struct sas_task *task, struct dev_to_host_
         */
        if (fis->status & ATA_DF)
                ts->stat = SAS_PROTO_RESPONSE;
+       else if (fis->status & ATA_ERR)
+               ts->stat = SAM_STAT_CHECK_CONDITION;
        else
                ts->stat = SAM_STAT_GOOD;
 
@@ -2603,18 +2897,7 @@ static void isci_request_io_request_complete(struct isci_host *ihost,
                        status   = SAM_STAT_GOOD;
                        set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags);
 
-                       if (task->task_proto == SAS_PROTOCOL_SMP) {
-                               void *rsp = &request->smp.rsp;
-
-                               dev_dbg(&ihost->pdev->dev,
-                                       "%s: SMP protocol completion\n",
-                                       __func__);
-
-                               sg_copy_from_buffer(
-                                       &task->smp_task.smp_resp, 1,
-                                       rsp, sizeof(struct smp_resp));
-                       } else if (completion_status
-                                  == SCI_IO_SUCCESS_IO_DONE_EARLY) {
+                       if (completion_status == SCI_IO_SUCCESS_IO_DONE_EARLY) {
 
                                /* This was an SSP / STP / SATA transfer.
                                 * There is a possibility that less data than
@@ -2791,6 +3074,7 @@ static void sci_request_started_state_enter(struct sci_base_state_machine *sm)
 {
        struct isci_request *ireq = container_of(sm, typeof(*ireq), sm);
        struct domain_device *dev = ireq->target_device->domain_dev;
+       enum sci_base_request_states state;
        struct sas_task *task;
 
        /* XXX as hch said always creating an internal sas_task for tmf
@@ -2802,26 +3086,30 @@ static void sci_request_started_state_enter(struct sci_base_state_machine *sm)
         * substates
         */
        if (!task && dev->dev_type == SAS_END_DEV) {
-               sci_change_state(sm, SCI_REQ_TASK_WAIT_TC_COMP);
+               state = SCI_REQ_TASK_WAIT_TC_COMP;
        } else if (!task &&
                   (isci_request_access_tmf(ireq)->tmf_code == isci_tmf_sata_srst_high ||
                    isci_request_access_tmf(ireq)->tmf_code == isci_tmf_sata_srst_low)) {
-               sci_change_state(sm, SCI_REQ_STP_SOFT_RESET_WAIT_H2D_ASSERTED);
+               state = SCI_REQ_STP_SOFT_RESET_WAIT_H2D_ASSERTED;
        } else if (task && task->task_proto == SAS_PROTOCOL_SMP) {
-               sci_change_state(sm, SCI_REQ_SMP_WAIT_RESP);
+               state = SCI_REQ_SMP_WAIT_RESP;
        } else if (task && sas_protocol_ata(task->task_proto) &&
                   !task->ata_task.use_ncq) {
-               u32 state;
-
-               if (task->data_dir == DMA_NONE)
+               if (dev->sata_dev.command_set == ATAPI_COMMAND_SET &&
+                       task->ata_task.fis.command == ATA_CMD_PACKET) {
+                       state = SCI_REQ_ATAPI_WAIT_H2D;
+               } else if (task->data_dir == DMA_NONE) {
                        state = SCI_REQ_STP_NON_DATA_WAIT_H2D;
-               else if (task->ata_task.dma_xfer)
+               } else if (task->ata_task.dma_xfer) {
                        state = SCI_REQ_STP_UDMA_WAIT_TC_COMP;
-               else /* PIO */
+               } else /* PIO */ {
                        state = SCI_REQ_STP_PIO_WAIT_H2D;
-
-               sci_change_state(sm, state);
+               }
+       } else {
+               /* SSP or NCQ are fully accelerated, no substates */
+               return;
        }
+       sci_change_state(sm, state);
 }
 
 static void sci_request_completed_state_enter(struct sci_base_state_machine *sm)
@@ -2913,6 +3201,10 @@ static const struct sci_base_state sci_request_state_table[] = {
        [SCI_REQ_TASK_WAIT_TC_RESP] = { },
        [SCI_REQ_SMP_WAIT_RESP] = { },
        [SCI_REQ_SMP_WAIT_TC_COMP] = { },
+       [SCI_REQ_ATAPI_WAIT_H2D] = { },
+       [SCI_REQ_ATAPI_WAIT_PIO_SETUP] = { },
+       [SCI_REQ_ATAPI_WAIT_D2H] = { },
+       [SCI_REQ_ATAPI_WAIT_TC_COMP] = { },
        [SCI_REQ_COMPLETED] = {
                .enter_state = sci_request_completed_state_enter,
        },
index 7a1d5a9778eba04c557ae68fe7a20147d4debd6a..f720b97b7bb5c9982afda972af51aab1f9be4b25 100644 (file)
@@ -96,7 +96,6 @@ enum sci_request_protocol {
  *          to wait for another fis or if the transfer is complete.  Upon
  *           receipt of a d2h fis this will be the status field of that fis.
  * @sgl - track pio transfer progress as we iterate through the sgl
- * @device_cdb_len - atapi device advertises it's transfer constraints at setup
  */
 struct isci_stp_request {
        u32 pio_len;
@@ -107,7 +106,6 @@ struct isci_stp_request {
                u8 set;
                u32 offset;
        } sgl;
-       u32 device_cdb_len;
 };
 
 struct isci_request {
@@ -173,9 +171,6 @@ struct isci_request {
                                u8 rsp_buf[SSP_RESP_IU_MAX_SIZE];
                        };
                } ssp;
-               struct {
-                       struct smp_resp rsp;
-               } smp;
                struct {
                        struct isci_stp_request req;
                        struct host_to_dev_fis cmd;
@@ -251,6 +246,32 @@ enum sci_base_request_states {
         */
        SCI_REQ_STP_PIO_DATA_OUT,
 
+       /*
+        * While in this state the IO request object is waiting for the TC
+        * completion notification for the H2D Register FIS
+        */
+       SCI_REQ_ATAPI_WAIT_H2D,
+
+       /*
+        * While in this state the IO request object is waiting for either a
+        * PIO Setup.
+        */
+       SCI_REQ_ATAPI_WAIT_PIO_SETUP,
+
+       /*
+        * The non-data IO transit to this state in this state after receiving
+        * TC completion. While in this state IO request object is waiting for
+        * D2H status frame as UF.
+        */
+       SCI_REQ_ATAPI_WAIT_D2H,
+
+       /*
+        * When transmitting raw frames hardware reports task context completion
+        * after every frame submission, so in the non-accelerated case we need
+        * to expect the completion for the "cdb" frame.
+        */
+       SCI_REQ_ATAPI_WAIT_TC_COMP,
+
        /*
         * The AWAIT_TC_COMPLETION sub-state indicates that the started raw
         * task management request is waiting for the transmission of the
index 462b15174d3f012c19de4d87c7fe98e7f4f2363b..dc26b4aea99e6fb636d3868071768cbf897ccc5b 100644 (file)
@@ -204,8 +204,6 @@ struct smp_req {
        u8 req_data[0];
 }  __packed;
 
-#define SMP_RESP_HDR_SZ        4
-
 /*
  * struct sci_sas_address - This structure depicts how a SAS address is
  *    represented by SCI.
index d6bcdd013dc9f4231f3f7fa0034e0f2a343282d7..e2d9418683ce66ce45f2522eff72556287064464 100644 (file)
@@ -1345,29 +1345,6 @@ static void isci_smp_task_done(struct sas_task *task)
        complete(&task->completion);
 }
 
-static struct sas_task *isci_alloc_task(void)
-{
-       struct sas_task *task = kzalloc(sizeof(*task), GFP_KERNEL);
-
-       if (task) {
-               INIT_LIST_HEAD(&task->list);
-               spin_lock_init(&task->task_state_lock);
-               task->task_state_flags = SAS_TASK_STATE_PENDING;
-               init_timer(&task->timer);
-               init_completion(&task->completion);
-       }
-
-       return task;
-}
-
-static void isci_free_task(struct isci_host *ihost, struct sas_task  *task)
-{
-       if (task) {
-               BUG_ON(!list_empty(&task->list));
-               kfree(task);
-       }
-}
-
 static int isci_smp_execute_task(struct isci_host *ihost,
                                 struct domain_device *dev, void *req,
                                 int req_size, void *resp, int resp_size)
@@ -1376,7 +1353,7 @@ static int isci_smp_execute_task(struct isci_host *ihost,
        struct sas_task *task = NULL;
 
        for (retry = 0; retry < 3; retry++) {
-               task = isci_alloc_task();
+               task = sas_alloc_task(GFP_KERNEL);
                if (!task)
                        return -ENOMEM;
 
@@ -1439,13 +1416,13 @@ static int isci_smp_execute_task(struct isci_host *ihost,
                                SAS_ADDR(dev->sas_addr),
                                task->task_status.resp,
                                task->task_status.stat);
-                       isci_free_task(ihost, task);
+                       sas_free_task(task);
                        task = NULL;
                }
        }
 ex_err:
        BUG_ON(retry == 3 && task != NULL);
-       isci_free_task(ihost, task);
+       sas_free_task(task);
        return res;
 }
 
index 4a7fa90287ef3553dc6ade693d2a1e6a2f25b19c..15b18d1589936dcdeef39a8a336f055aa549dd16 100644 (file)
@@ -286,6 +286,25 @@ isci_task_set_completion_status(
        task->task_status.resp = response;
        task->task_status.stat = status;
 
+       switch (task->task_proto) {
+
+       case SAS_PROTOCOL_SATA:
+       case SAS_PROTOCOL_STP:
+       case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
+
+               if (task_notification_selection
+                   == isci_perform_error_io_completion) {
+                       /* SATA/STP I/O has it's own means of scheduling device
+                       * error handling on the normal path.
+                       */
+                       task_notification_selection
+                               = isci_perform_normal_io_completion;
+               }
+               break;
+       default:
+               break;
+       }
+
        switch (task_notification_selection) {
 
        case isci_perform_error_io_completion:
index 7724414588fa9b2c076530298b0b6c0d280ae685..23e706673d066117cbcf673d8f495987a69754b5 100644 (file)
@@ -872,6 +872,61 @@ static void iscsi_sw_tcp_session_destroy(struct iscsi_cls_session *cls_session)
        iscsi_host_free(shost);
 }
 
+static mode_t iscsi_sw_tcp_attr_is_visible(int param_type, int param)
+{
+       switch (param_type) {
+       case ISCSI_HOST_PARAM:
+               switch (param) {
+               case ISCSI_HOST_PARAM_NETDEV_NAME:
+               case ISCSI_HOST_PARAM_HWADDRESS:
+               case ISCSI_HOST_PARAM_IPADDRESS:
+               case ISCSI_HOST_PARAM_INITIATOR_NAME:
+                       return S_IRUGO;
+               default:
+                       return 0;
+               }
+       case ISCSI_PARAM:
+               switch (param) {
+               case ISCSI_PARAM_MAX_RECV_DLENGTH:
+               case ISCSI_PARAM_MAX_XMIT_DLENGTH:
+               case ISCSI_PARAM_HDRDGST_EN:
+               case ISCSI_PARAM_DATADGST_EN:
+               case ISCSI_PARAM_CONN_ADDRESS:
+               case ISCSI_PARAM_CONN_PORT:
+               case ISCSI_PARAM_EXP_STATSN:
+               case ISCSI_PARAM_PERSISTENT_ADDRESS:
+               case ISCSI_PARAM_PERSISTENT_PORT:
+               case ISCSI_PARAM_PING_TMO:
+               case ISCSI_PARAM_RECV_TMO:
+               case ISCSI_PARAM_INITIAL_R2T_EN:
+               case ISCSI_PARAM_MAX_R2T:
+               case ISCSI_PARAM_IMM_DATA_EN:
+               case ISCSI_PARAM_FIRST_BURST:
+               case ISCSI_PARAM_MAX_BURST:
+               case ISCSI_PARAM_PDU_INORDER_EN:
+               case ISCSI_PARAM_DATASEQ_INORDER_EN:
+               case ISCSI_PARAM_ERL:
+               case ISCSI_PARAM_TARGET_NAME:
+               case ISCSI_PARAM_TPGT:
+               case ISCSI_PARAM_USERNAME:
+               case ISCSI_PARAM_PASSWORD:
+               case ISCSI_PARAM_USERNAME_IN:
+               case ISCSI_PARAM_PASSWORD_IN:
+               case ISCSI_PARAM_FAST_ABORT:
+               case ISCSI_PARAM_ABORT_TMO:
+               case ISCSI_PARAM_LU_RESET_TMO:
+               case ISCSI_PARAM_TGT_RESET_TMO:
+               case ISCSI_PARAM_IFACE_NAME:
+               case ISCSI_PARAM_INITIATOR_NAME:
+                       return S_IRUGO;
+               default:
+                       return 0;
+               }
+       }
+
+       return 0;
+}
+
 static int iscsi_sw_tcp_slave_alloc(struct scsi_device *sdev)
 {
        set_bit(QUEUE_FLAG_BIDI, &sdev->request_queue->queue_flags);
@@ -910,33 +965,6 @@ static struct iscsi_transport iscsi_sw_tcp_transport = {
        .name                   = "tcp",
        .caps                   = CAP_RECOVERY_L0 | CAP_MULTI_R2T | CAP_HDRDGST
                                  | CAP_DATADGST,
-       .param_mask             = ISCSI_MAX_RECV_DLENGTH |
-                                 ISCSI_MAX_XMIT_DLENGTH |
-                                 ISCSI_HDRDGST_EN |
-                                 ISCSI_DATADGST_EN |
-                                 ISCSI_INITIAL_R2T_EN |
-                                 ISCSI_MAX_R2T |
-                                 ISCSI_IMM_DATA_EN |
-                                 ISCSI_FIRST_BURST |
-                                 ISCSI_MAX_BURST |
-                                 ISCSI_PDU_INORDER_EN |
-                                 ISCSI_DATASEQ_INORDER_EN |
-                                 ISCSI_ERL |
-                                 ISCSI_CONN_PORT |
-                                 ISCSI_CONN_ADDRESS |
-                                 ISCSI_EXP_STATSN |
-                                 ISCSI_PERSISTENT_PORT |
-                                 ISCSI_PERSISTENT_ADDRESS |
-                                 ISCSI_TARGET_NAME | ISCSI_TPGT |
-                                 ISCSI_USERNAME | ISCSI_PASSWORD |
-                                 ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN |
-                                 ISCSI_FAST_ABORT | ISCSI_ABORT_TMO |
-                                 ISCSI_LU_RESET_TMO | ISCSI_TGT_RESET_TMO |
-                                 ISCSI_PING_TMO | ISCSI_RECV_TMO |
-                                 ISCSI_IFACE_NAME | ISCSI_INITIATOR_NAME,
-       .host_param_mask        = ISCSI_HOST_HWADDRESS | ISCSI_HOST_IPADDRESS |
-                                 ISCSI_HOST_INITIATOR_NAME |
-                                 ISCSI_HOST_NETDEV_NAME,
        /* session management */
        .create_session         = iscsi_sw_tcp_session_create,
        .destroy_session        = iscsi_sw_tcp_session_destroy,
@@ -944,6 +972,7 @@ static struct iscsi_transport iscsi_sw_tcp_transport = {
        .create_conn            = iscsi_sw_tcp_conn_create,
        .bind_conn              = iscsi_sw_tcp_conn_bind,
        .destroy_conn           = iscsi_sw_tcp_conn_destroy,
+       .attr_is_visible        = iscsi_sw_tcp_attr_is_visible,
        .set_param              = iscsi_sw_tcp_conn_set_param,
        .get_conn_param         = iscsi_sw_tcp_conn_get_param,
        .get_session_param      = iscsi_session_get_param,
index d261e982a2fae5a0c8b13ef098cc3265ebb2ebc5..7c055fdca45de91ae3c2682ab217e34ee32f4f54 100644 (file)
@@ -65,16 +65,15 @@ static struct workqueue_struct *fc_exch_workqueue;
  * assigned range of exchanges to per cpu pool.
  */
 struct fc_exch_pool {
+       spinlock_t       lock;
+       struct list_head ex_list;
        u16              next_index;
        u16              total_exches;
 
        /* two cache of free slot in exch array */
        u16              left;
        u16              right;
-
-       spinlock_t       lock;
-       struct list_head ex_list;
-};
+} ____cacheline_aligned_in_smp;
 
 /**
  * struct fc_exch_mgr - The Exchange Manager (EM).
@@ -91,13 +90,13 @@ struct fc_exch_pool {
  * It manages the allocation of exchange IDs.
  */
 struct fc_exch_mgr {
+       struct fc_exch_pool *pool;
+       mempool_t       *ep_pool;
        enum fc_class   class;
        struct kref     kref;
        u16             min_xid;
        u16             max_xid;
-       mempool_t       *ep_pool;
        u16             pool_max_index;
-       struct fc_exch_pool *pool;
 
        /*
         * currently exchange mgr stats are updated but not used.
index 4c41ee816f0bbbedf5b88f4b72981c9991fbc843..221875ec3d7c64de19c4f6404961be441fb16f34 100644 (file)
@@ -759,7 +759,6 @@ static void fc_fcp_recv(struct fc_seq *seq, struct fc_frame *fp, void *arg)
                goto out;
        if (fc_fcp_lock_pkt(fsp))
                goto out;
-       fsp->last_pkt_time = jiffies;
 
        if (fh->fh_type == FC_TYPE_BLS) {
                fc_fcp_abts_resp(fsp, fp);
@@ -1148,7 +1147,6 @@ static int fc_fcp_cmd_send(struct fc_lport *lport, struct fc_fcp_pkt *fsp,
                rc = -1;
                goto unlock;
        }
-       fsp->last_pkt_time = jiffies;
        fsp->seq_ptr = seq;
        fc_fcp_pkt_hold(fsp);   /* hold for fc_fcp_pkt_destroy */
 
index 256a999d010bc6414f3f6702189decddd3813ac4..d7c76f2eb6368eac8f6b1d0e50f51fe6f087e53c 100644 (file)
@@ -3163,7 +3163,6 @@ int iscsi_set_param(struct iscsi_cls_conn *cls_conn,
 {
        struct iscsi_conn *conn = cls_conn->dd_data;
        struct iscsi_session *session = conn->session;
-       uint32_t value;
 
        switch(param) {
        case ISCSI_PARAM_FAST_ABORT:
@@ -3220,14 +3219,6 @@ int iscsi_set_param(struct iscsi_cls_conn *cls_conn,
        case ISCSI_PARAM_ERL:
                sscanf(buf, "%d", &session->erl);
                break;
-       case ISCSI_PARAM_IFMARKER_EN:
-               sscanf(buf, "%d", &value);
-               BUG_ON(value);
-               break;
-       case ISCSI_PARAM_OFMARKER_EN:
-               sscanf(buf, "%d", &value);
-               BUG_ON(value);
-               break;
        case ISCSI_PARAM_EXP_STATSN:
                sscanf(buf, "%u", &conn->exp_statsn);
                break;
index f5831930df9bd31e540516b792673f8fd7ce5ab5..54a5199ceb56d9176ee51a46eba097e3120398d4 100644 (file)
@@ -219,17 +219,20 @@ out_err2:
 
 /* ---------- Device registration and unregistration ---------- */
 
-static inline void sas_unregister_common_dev(struct domain_device *dev)
+static void sas_unregister_common_dev(struct asd_sas_port *port, struct domain_device *dev)
 {
        sas_notify_lldd_dev_gone(dev);
        if (!dev->parent)
                dev->port->port_dev = NULL;
        else
                list_del_init(&dev->siblings);
+
+       spin_lock_irq(&port->dev_list_lock);
        list_del_init(&dev->dev_list_node);
+       spin_unlock_irq(&port->dev_list_lock);
 }
 
-void sas_unregister_dev(struct domain_device *dev)
+void sas_unregister_dev(struct asd_sas_port *port, struct domain_device *dev)
 {
        if (dev->rphy) {
                sas_remove_children(&dev->rphy->dev);
@@ -241,15 +244,15 @@ void sas_unregister_dev(struct domain_device *dev)
                kfree(dev->ex_dev.ex_phy);
                dev->ex_dev.ex_phy = NULL;
        }
-       sas_unregister_common_dev(dev);
+       sas_unregister_common_dev(port, dev);
 }
 
 void sas_unregister_domain_devices(struct asd_sas_port *port)
 {
        struct domain_device *dev, *n;
 
-       list_for_each_entry_safe_reverse(dev,n,&port->dev_list,dev_list_node)
-               sas_unregister_dev(dev);
+       list_for_each_entry_safe_reverse(dev, n, &port->dev_list, dev_list_node)
+               sas_unregister_dev(port, dev);
 
        port->port->rphy = NULL;
 
index 16ad97df5ba6790b11eb40b1a4eef4fd90325cd1..1b831c55ec6e364f4f7001d4bd7a741e6a1d3bc2 100644 (file)
@@ -199,6 +199,8 @@ static void sas_set_ex_phy(struct domain_device *dev, int phy_id,
        phy->virtual = dr->virtual;
        phy->last_da_index = -1;
 
+       phy->phy->identify.sas_address = SAS_ADDR(phy->attached_sas_addr);
+       phy->phy->identify.device_type = phy->attached_dev_type;
        phy->phy->identify.initiator_port_protocols = phy->attached_iproto;
        phy->phy->identify.target_port_protocols = phy->attached_tproto;
        phy->phy->identify.phy_identifier = phy_id;
@@ -329,6 +331,7 @@ static void ex_assign_report_general(struct domain_device *dev,
        dev->ex_dev.ex_change_count = be16_to_cpu(rg->change_count);
        dev->ex_dev.max_route_indexes = be16_to_cpu(rg->route_indexes);
        dev->ex_dev.num_phys = min(rg->num_phys, (u8)MAX_EXPANDER_PHYS);
+       dev->ex_dev.t2t_supp = rg->t2t_supp;
        dev->ex_dev.conf_route_table = rg->conf_route_table;
        dev->ex_dev.configuring = rg->configuring;
        memcpy(dev->ex_dev.enclosure_logical_id, rg->enclosure_logical_id, 8);
@@ -751,7 +754,10 @@ static struct domain_device *sas_ex_discover_end_dev(
  out_list_del:
        sas_rphy_free(child->rphy);
        child->rphy = NULL;
+
+       spin_lock_irq(&parent->port->dev_list_lock);
        list_del(&child->dev_list_node);
+       spin_unlock_irq(&parent->port->dev_list_lock);
  out_free:
        sas_port_delete(phy->port);
  out_err:
@@ -1133,15 +1139,17 @@ static void sas_print_parent_topology_bug(struct domain_device *child,
        };
        struct domain_device *parent = child->parent;
 
-       sas_printk("%s ex %016llx phy 0x%x <--> %s ex %016llx phy 0x%x "
-                  "has %c:%c routing link!\n",
+       sas_printk("%s ex %016llx (T2T supp:%d) phy 0x%x <--> %s ex %016llx "
+                  "(T2T supp:%d) phy 0x%x has %c:%c routing link!\n",
 
                   ex_type[parent->dev_type],
                   SAS_ADDR(parent->sas_addr),
+                  parent->ex_dev.t2t_supp,
                   parent_phy->phy_id,
 
                   ex_type[child->dev_type],
                   SAS_ADDR(child->sas_addr),
+                  child->ex_dev.t2t_supp,
                   child_phy->phy_id,
 
                   ra_char[parent_phy->routing_attr],
@@ -1238,10 +1246,15 @@ static int sas_check_parent_topology(struct domain_device *child)
                                        sas_print_parent_topology_bug(child, parent_phy, child_phy);
                                        res = -ENODEV;
                                }
-                       } else if (parent_phy->routing_attr == TABLE_ROUTING &&
-                                  child_phy->routing_attr != SUBTRACTIVE_ROUTING) {
-                               sas_print_parent_topology_bug(child, parent_phy, child_phy);
-                               res = -ENODEV;
+                       } else if (parent_phy->routing_attr == TABLE_ROUTING) {
+                               if (child_phy->routing_attr == SUBTRACTIVE_ROUTING ||
+                                   (child_phy->routing_attr == TABLE_ROUTING &&
+                                    child_ex->t2t_supp && parent_ex->t2t_supp)) {
+                                       /* All good */;
+                               } else {
+                                       sas_print_parent_topology_bug(child, parent_phy, child_phy);
+                                       res = -ENODEV;
+                               }
                        }
                        break;
                case FANOUT_DEV:
@@ -1729,7 +1742,7 @@ out:
        return res;
 }
 
-static void sas_unregister_ex_tree(struct domain_device *dev)
+static void sas_unregister_ex_tree(struct asd_sas_port *port, struct domain_device *dev)
 {
        struct expander_device *ex = &dev->ex_dev;
        struct domain_device *child, *n;
@@ -1738,11 +1751,11 @@ static void sas_unregister_ex_tree(struct domain_device *dev)
                child->gone = 1;
                if (child->dev_type == EDGE_DEV ||
                    child->dev_type == FANOUT_DEV)
-                       sas_unregister_ex_tree(child);
+                       sas_unregister_ex_tree(port, child);
                else
-                       sas_unregister_dev(child);
+                       sas_unregister_dev(port, child);
        }
-       sas_unregister_dev(dev);
+       sas_unregister_dev(port, dev);
 }
 
 static void sas_unregister_devs_sas_addr(struct domain_device *parent,
@@ -1759,9 +1772,9 @@ static void sas_unregister_devs_sas_addr(struct domain_device *parent,
                                child->gone = 1;
                                if (child->dev_type == EDGE_DEV ||
                                    child->dev_type == FANOUT_DEV)
-                                       sas_unregister_ex_tree(child);
+                                       sas_unregister_ex_tree(parent->port, child);
                                else
-                                       sas_unregister_dev(child);
+                                       sas_unregister_dev(parent->port, child);
                                break;
                        }
                }
index 04ad8dd1a74cf8267982e29a551efd1503a5ef1c..e1aa17840c5bf2e0a2d41784114c3f41cdd5aeb1 100644 (file)
@@ -51,6 +51,91 @@ static void sas_host_smp_discover(struct sas_ha_struct *sas_ha, u8 *resp_data,
        resp_data[15] = rphy->identify.target_port_protocols;
 }
 
+/**
+ * to_sas_gpio_gp_bit - given the gpio frame data find the byte/bit position of 'od'
+ * @od: od bit to find
+ * @data: incoming bitstream (from frame)
+ * @index: requested data register index (from frame)
+ * @count: total number of registers in the bitstream (from frame)
+ * @bit: bit position of 'od' in the returned byte
+ *
+ * returns NULL if 'od' is not in 'data'
+ *
+ * From SFF-8485 v0.7:
+ * "In GPIO_TX[1], bit 0 of byte 3 contains the first bit (i.e., OD0.0)
+ *  and bit 7 of byte 0 contains the 32nd bit (i.e., OD10.1).
+ *
+ *  In GPIO_TX[2], bit 0 of byte 3 contains the 33rd bit (i.e., OD10.2)
+ *  and bit 7 of byte 0 contains the 64th bit (i.e., OD21.0)."
+ *
+ * The general-purpose (raw-bitstream) RX registers have the same layout
+ * although 'od' is renamed 'id' for 'input data'.
+ *
+ * SFF-8489 defines the behavior of the LEDs in response to the 'od' values.
+ */
+static u8 *to_sas_gpio_gp_bit(unsigned int od, u8 *data, u8 index, u8 count, u8 *bit)
+{
+       unsigned int reg;
+       u8 byte;
+
+       /* gp registers start at index 1 */
+       if (index == 0)
+               return NULL;
+
+       index--; /* make index 0-based */
+       if (od < index * 32)
+               return NULL;
+
+       od -= index * 32;
+       reg = od >> 5;
+
+       if (reg >= count)
+               return NULL;
+
+       od &= (1 << 5) - 1;
+       byte = 3 - (od >> 3);
+       *bit = od & ((1 << 3) - 1);
+
+       return &data[reg * 4 + byte];
+}
+
+int try_test_sas_gpio_gp_bit(unsigned int od, u8 *data, u8 index, u8 count)
+{
+       u8 *byte;
+       u8 bit;
+
+       byte = to_sas_gpio_gp_bit(od, data, index, count, &bit);
+       if (!byte)
+               return -1;
+
+       return (*byte >> bit) & 1;
+}
+EXPORT_SYMBOL(try_test_sas_gpio_gp_bit);
+
+static int sas_host_smp_write_gpio(struct sas_ha_struct *sas_ha, u8 *resp_data,
+                                  u8 reg_type, u8 reg_index, u8 reg_count,
+                                  u8 *req_data)
+{
+       struct sas_internal *i = to_sas_internal(sas_ha->core.shost->transportt);
+       int written;
+
+       if (i->dft->lldd_write_gpio == NULL) {
+               resp_data[2] = SMP_RESP_FUNC_UNK;
+               return 0;
+       }
+
+       written = i->dft->lldd_write_gpio(sas_ha, reg_type, reg_index,
+                                         reg_count, req_data);
+
+       if (written < 0) {
+               resp_data[2] = SMP_RESP_FUNC_FAILED;
+               written = 0;
+       } else
+               resp_data[2] = SMP_RESP_FUNC_ACC;
+
+       return written;
+}
+
 static void sas_report_phy_sata(struct sas_ha_struct *sas_ha, u8 *resp_data,
                                u8 phy_id)
 {
@@ -230,9 +315,23 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
                /* Can't implement; hosts have no routes */
                break;
 
-       case SMP_WRITE_GPIO_REG:
-               /* FIXME: need GPIO support in the transport class */
+       case SMP_WRITE_GPIO_REG: {
+               /* SFF-8485 v0.7 */
+               const int base_frame_size = 11;
+               int to_write = req_data[4];
+
+               if (blk_rq_bytes(req) < base_frame_size + to_write * 4 ||
+                   req->resid_len < base_frame_size + to_write * 4) {
+                       resp_data[2] = SMP_RESP_INV_FRM_LEN;
+                       break;
+               }
+
+               to_write = sas_host_smp_write_gpio(sas_ha, resp_data, req_data[2],
+                                                  req_data[3], to_write, &req_data[8]);
+               req->resid_len -= base_frame_size + to_write * 4;
+               rsp->resid_len -= 8;
                break;
+       }
 
        case SMP_CONF_ROUTE_INFO:
                /* Can't implement; hosts have no routes */
index 2dc55343f671f6c7b4fa681278233c85c3db314e..d81c3b1989f7d343a6a550a064b7623e44a893ed 100644 (file)
 
 #include "../scsi_sas_internal.h"
 
-struct kmem_cache *sas_task_cache;
+static struct kmem_cache *sas_task_cache;
+
+struct sas_task *sas_alloc_task(gfp_t flags)
+{
+       struct sas_task *task = kmem_cache_zalloc(sas_task_cache, flags);
+
+       if (task) {
+               INIT_LIST_HEAD(&task->list);
+               spin_lock_init(&task->task_state_lock);
+               task->task_state_flags = SAS_TASK_STATE_PENDING;
+               init_timer(&task->timer);
+               init_completion(&task->completion);
+       }
+
+       return task;
+}
+EXPORT_SYMBOL_GPL(sas_alloc_task);
+
+void sas_free_task(struct sas_task *task)
+{
+       if (task) {
+               BUG_ON(!list_empty(&task->list));
+               kmem_cache_free(sas_task_cache, task);
+       }
+}
+EXPORT_SYMBOL_GPL(sas_free_task);
 
 /*------------ SAS addr hash -----------*/
 void sas_hash_addr(u8 *hashed, const u8 *sas_addr)
@@ -152,10 +177,15 @@ int sas_unregister_ha(struct sas_ha_struct *sas_ha)
 
 static int sas_get_linkerrors(struct sas_phy *phy)
 {
-       if (scsi_is_sas_phy_local(phy))
-               /* FIXME: we have no local phy stats
-                * gathering at this time */
-               return -EINVAL;
+       if (scsi_is_sas_phy_local(phy)) {
+               struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
+               struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(shost);
+               struct asd_sas_phy *asd_phy = sas_ha->sas_phy[phy->number];
+               struct sas_internal *i =
+                       to_sas_internal(sas_ha->core.shost->transportt);
+
+               return i->dft->lldd_control_phy(asd_phy, PHY_FUNC_GET_EVENTS, NULL);
+       }
 
        return sas_smp_get_phy_events(phy);
 }
@@ -293,8 +323,7 @@ EXPORT_SYMBOL_GPL(sas_domain_release_transport);
 
 static int __init sas_class_init(void)
 {
-       sas_task_cache = kmem_cache_create("sas_task", sizeof(struct sas_task),
-                                          0, SLAB_HWCACHE_ALIGN, NULL);
+       sas_task_cache = KMEM_CACHE(sas_task, SLAB_HWCACHE_ALIGN);
        if (!sas_task_cache)
                return -ENOMEM;
 
index eeba76cdf7746c518c49f680d3d2ab9f3a9b863a..b2c4a773165699e8a46544c1aeb522a1d8e318e1 100644 (file)
@@ -182,79 +182,56 @@ int sas_queue_up(struct sas_task *task)
        return 0;
 }
 
-/**
- * sas_queuecommand -- Enqueue a command for processing
- * @parameters: See SCSI Core documentation
- *
- * Note: XXX: Remove the host unlock/lock pair when SCSI Core can
- * call us without holding an IRQ spinlock...
- */
-static int sas_queuecommand_lck(struct scsi_cmnd *cmd,
-                    void (*scsi_done)(struct scsi_cmnd *))
-       __releases(host->host_lock)
-       __acquires(dev->sata_dev.ap->lock)
-       __releases(dev->sata_dev.ap->lock)
-       __acquires(host->host_lock)
+int sas_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
 {
-       int res = 0;
-       struct domain_device *dev = cmd_to_domain_dev(cmd);
-       struct Scsi_Host *host = cmd->device->host;
        struct sas_internal *i = to_sas_internal(host->transportt);
+       struct domain_device *dev = cmd_to_domain_dev(cmd);
+       struct sas_ha_struct *sas_ha = dev->port->ha;
+       struct sas_task *task;
+       int res = 0;
 
-       spin_unlock_irq(host->host_lock);
+       /* If the device fell off, no sense in issuing commands */
+       if (dev->gone) {
+               cmd->result = DID_BAD_TARGET << 16;
+               goto out_done;
+       }
 
-       {
-               struct sas_ha_struct *sas_ha = dev->port->ha;
-               struct sas_task *task;
-
-               /* If the device fell off, no sense in issuing commands */
-               if (dev->gone) {
-                       cmd->result = DID_BAD_TARGET << 16;
-                       scsi_done(cmd);
-                       goto out;
-               }
+       if (dev_is_sata(dev)) {
+               unsigned long flags;
 
-               if (dev_is_sata(dev)) {
-                       unsigned long flags;
+               spin_lock_irqsave(dev->sata_dev.ap->lock, flags);
+               res = ata_sas_queuecmd(cmd, dev->sata_dev.ap);
+               spin_unlock_irqrestore(dev->sata_dev.ap->lock, flags);
+               return res;
+       }
 
-                       spin_lock_irqsave(dev->sata_dev.ap->lock, flags);
-                       res = ata_sas_queuecmd(cmd, dev->sata_dev.ap);
-                       spin_unlock_irqrestore(dev->sata_dev.ap->lock, flags);
-                       goto out;
-               }
+       task = sas_create_task(cmd, dev, GFP_ATOMIC);
+       if (!task)
+               return SCSI_MLQUEUE_HOST_BUSY;
 
-               res = -ENOMEM;
-               task = sas_create_task(cmd, dev, GFP_ATOMIC);
-               if (!task)
-                       goto out;
+       /* Queue up, Direct Mode or Task Collector Mode. */
+       if (sas_ha->lldd_max_execute_num < 2)
+               res = i->dft->lldd_execute_task(task, 1, GFP_ATOMIC);
+       else
+               res = sas_queue_up(task);
 
-               cmd->scsi_done = scsi_done;
-               /* Queue up, Direct Mode or Task Collector Mode. */
-               if (sas_ha->lldd_max_execute_num < 2)
-                       res = i->dft->lldd_execute_task(task, 1, GFP_ATOMIC);
-               else
-                       res = sas_queue_up(task);
+       if (res)
+               goto out_free_task;
+       return 0;
 
-               /* Examine */
-               if (res) {
-                       SAS_DPRINTK("lldd_execute_task returned: %d\n", res);
-                       ASSIGN_SAS_TASK(cmd, NULL);
-                       sas_free_task(task);
-                       if (res == -SAS_QUEUE_FULL) {
-                               cmd->result = DID_SOFT_ERROR << 16; /* retry */
-                               res = 0;
-                               scsi_done(cmd);
-                       }
-                       goto out;
-               }
-       }
-out:
-       spin_lock_irq(host->host_lock);
-       return res;
+out_free_task:
+       SAS_DPRINTK("lldd_execute_task returned: %d\n", res);
+       ASSIGN_SAS_TASK(cmd, NULL);
+       sas_free_task(task);
+       if (res == -SAS_QUEUE_FULL)
+               cmd->result = DID_SOFT_ERROR << 16; /* retry */
+       else
+               cmd->result = DID_ERROR << 16;
+out_done:
+       cmd->scsi_done(cmd);
+       return 0;
 }
 
-DEF_SCSI_QCMD(sas_queuecommand)
-
 static void sas_eh_finish_cmd(struct scsi_cmnd *cmd)
 {
        struct sas_task *task = TO_SAS_TASK(cmd);
@@ -784,8 +761,7 @@ int sas_target_alloc(struct scsi_target *starget)
        return 0;
 }
 
-#define SAS_DEF_QD 32
-#define SAS_MAX_QD 64
+#define SAS_DEF_QD 256
 
 int sas_slave_configure(struct scsi_device *scsi_dev)
 {
@@ -825,34 +801,41 @@ void sas_slave_destroy(struct scsi_device *scsi_dev)
        struct domain_device *dev = sdev_to_domain_dev(scsi_dev);
 
        if (dev_is_sata(dev))
-               dev->sata_dev.ap->link.device[0].class = ATA_DEV_NONE;
+               sas_to_ata_dev(dev)->class = ATA_DEV_NONE;
 }
 
-int sas_change_queue_depth(struct scsi_device *scsi_dev, int new_depth,
-                          int reason)
+int sas_change_queue_depth(struct scsi_device *sdev, int depth, int reason)
 {
-       int res = min(new_depth, SAS_MAX_QD);
+       struct domain_device *dev = sdev_to_domain_dev(sdev);
 
-       if (reason != SCSI_QDEPTH_DEFAULT)
+       if (dev_is_sata(dev))
+               return __ata_change_queue_depth(dev->sata_dev.ap, sdev, depth,
+                                               reason);
+
+       switch (reason) {
+       case SCSI_QDEPTH_DEFAULT:
+       case SCSI_QDEPTH_RAMP_UP:
+               if (!sdev->tagged_supported)
+                       depth = 1;
+               scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
+               break;
+       case SCSI_QDEPTH_QFULL:
+               scsi_track_queue_full(sdev, depth);
+               break;
+       default:
                return -EOPNOTSUPP;
-
-       if (scsi_dev->tagged_supported)
-               scsi_adjust_queue_depth(scsi_dev, scsi_get_tag_type(scsi_dev),
-                                       res);
-       else {
-               struct domain_device *dev = sdev_to_domain_dev(scsi_dev);
-               sas_printk("device %llx LUN %x queue depth changed to 1\n",
-                          SAS_ADDR(dev->sas_addr),
-                          scsi_dev->lun);
-               scsi_adjust_queue_depth(scsi_dev, 0, 1);
-               res = 1;
        }
 
-       return res;
+       return depth;
 }
 
 int sas_change_queue_type(struct scsi_device *scsi_dev, int qt)
 {
+       struct domain_device *dev = sdev_to_domain_dev(scsi_dev);
+
+       if (dev_is_sata(dev))
+               return -EINVAL;
+
        if (!scsi_dev->tagged_supported)
                return 0;
 
index c088a36d1f33c679730fa8ce0082a0fab4a45888..bb4c8e0584e23b343392a2c9a692273daadf8d45 100644 (file)
@@ -846,8 +846,24 @@ struct lpfc_hba {
        struct dentry *debug_hbqinfo;
        struct dentry *debug_dumpHostSlim;
        struct dentry *debug_dumpHBASlim;
-       struct dentry *debug_dumpData;   /* BlockGuard BPL*/
-       struct dentry *debug_dumpDif;    /* BlockGuard BPL*/
+       struct dentry *debug_dumpData;   /* BlockGuard BPL */
+       struct dentry *debug_dumpDif;    /* BlockGuard BPL */
+       struct dentry *debug_InjErrLBA;  /* LBA to inject errors at */
+       struct dentry *debug_writeGuard; /* inject write guard_tag errors */
+       struct dentry *debug_writeApp;   /* inject write app_tag errors */
+       struct dentry *debug_writeRef;   /* inject write ref_tag errors */
+       struct dentry *debug_readApp;    /* inject read app_tag errors */
+       struct dentry *debug_readRef;    /* inject read ref_tag errors */
+
+       /* T10 DIF error injection */
+       uint32_t lpfc_injerr_wgrd_cnt;
+       uint32_t lpfc_injerr_wapp_cnt;
+       uint32_t lpfc_injerr_wref_cnt;
+       uint32_t lpfc_injerr_rapp_cnt;
+       uint32_t lpfc_injerr_rref_cnt;
+       sector_t lpfc_injerr_lba;
+#define LPFC_INJERR_LBA_OFF    (sector_t)0xffffffffffffffff
+
        struct dentry *debug_slow_ring_trc;
        struct lpfc_debugfs_trc *slow_ring_trc;
        atomic_t slow_ring_trc_cnt;
index 2542f1f8bf86583df36fba43ddbfb2c26e0d5120..4b0333ee2d948be0eaabcb225cd9c4ed0115e51c 100644 (file)
 #define LPFC_MIN_DEVLOSS_TMO 1
 #define LPFC_MAX_DEVLOSS_TMO 255
 
+/*
+ * Write key size should be multiple of 4. If write key is changed
+ * make sure that library write key is also changed.
+ */
+#define LPFC_REG_WRITE_KEY_SIZE        4
+#define LPFC_REG_WRITE_KEY     "EMLX"
+
 /**
  * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
  * @incr: integer to convert.
@@ -693,7 +700,7 @@ lpfc_selective_reset(struct lpfc_hba *phba)
        int rc;
 
        if (!phba->cfg_enable_hba_reset)
-               return -EIO;
+               return -EACCES;
 
        status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
 
@@ -742,9 +749,11 @@ lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
        struct Scsi_Host  *shost = class_to_shost(dev);
        struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
        struct lpfc_hba   *phba = vport->phba;
-
        int status = -EINVAL;
 
+       if (!phba->cfg_enable_hba_reset)
+               return -EACCES;
+
        if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
                status = phba->lpfc_selective_reset(phba);
 
@@ -765,16 +774,21 @@ lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
  * Returns:
  * zero for success
  **/
-static int
+int
 lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
 {
-       struct lpfc_register portstat_reg;
+       struct lpfc_register portstat_reg = {0};
        int i;
 
-
+       msleep(100);
        lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
                   &portstat_reg.word0);
 
+       /* verify if privilaged for the request operation */
+       if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
+           !bf_get(lpfc_sliport_status_err, &portstat_reg))
+               return -EPERM;
+
        /* wait for the SLI port firmware ready after firmware reset */
        for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
                msleep(10);
@@ -816,16 +830,13 @@ lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
        int rc;
 
        if (!phba->cfg_enable_hba_reset)
-               return -EIO;
+               return -EACCES;
 
        if ((phba->sli_rev < LPFC_SLI_REV4) ||
            (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
             LPFC_SLI_INTF_IF_TYPE_2))
                return -EPERM;
 
-       if (!pdev->is_physfn)
-               return -EPERM;
-
        /* Disable SR-IOV virtual functions if enabled */
        if (phba->cfg_sriov_nr_virtfn) {
                pci_disable_sriov(pdev);
@@ -858,7 +869,7 @@ lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
        rc = lpfc_sli4_pdev_status_reg_wait(phba);
 
        if (rc)
-               return -EIO;
+               return rc;
 
        init_completion(&online_compl);
        rc = lpfc_workq_post_event(phba, &status, &online_compl,
@@ -984,7 +995,7 @@ lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
        if (!status)
                return strlen(buf);
        else
-               return -EIO;
+               return status;
 }
 
 /**
@@ -3885,18 +3896,23 @@ sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
        if ((off + count) > FF_REG_AREA_SIZE)
                return -ERANGE;
 
-       if (count == 0) return 0;
+       if (count <= LPFC_REG_WRITE_KEY_SIZE)
+               return 0;
 
        if (off % 4 || count % 4 || (unsigned long)buf % 4)
                return -EINVAL;
 
-       if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
+       /* This is to protect HBA registers from accidental writes. */
+       if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
+               return -EINVAL;
+
+       if (!(vport->fc_flag & FC_OFFLINE_MODE))
                return -EPERM;
-       }
 
        spin_lock_irq(&phba->hbalock);
-       for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
-               writel(*((uint32_t *)(buf + buf_off)),
+       for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
+                       buf_off += sizeof(uint32_t))
+               writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
                       phba->ctrl_regs_memmap_p + off + buf_off);
 
        spin_unlock_irq(&phba->hbalock);
@@ -4097,8 +4113,10 @@ sysfs_mbox_read(struct file *filp, struct kobject *kobj,
        struct Scsi_Host  *shost = class_to_shost(dev);
        struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
        struct lpfc_hba   *phba = vport->phba;
-       int rc;
+       LPFC_MBOXQ_t *mboxq;
        MAILBOX_t *pmb;
+       uint32_t mbox_tmo;
+       int rc;
 
        if (off > MAILBOX_CMD_SIZE)
                return -ERANGE;
@@ -4123,7 +4141,8 @@ sysfs_mbox_read(struct file *filp, struct kobject *kobj,
        if (off == 0 &&
            phba->sysfs_mbox.state  == SMBOX_WRITING &&
            phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
-               pmb = &phba->sysfs_mbox.mbox->u.mb;
+               mboxq = (LPFC_MBOXQ_t *)&phba->sysfs_mbox.mbox;
+               pmb = &mboxq->u.mb;
                switch (pmb->mbxCommand) {
                        /* Offline only */
                case MBX_INIT_LINK:
@@ -4233,9 +4252,8 @@ sysfs_mbox_read(struct file *filp, struct kobject *kobj,
 
                } else {
                        spin_unlock_irq(&phba->hbalock);
-                       rc = lpfc_sli_issue_mbox_wait (phba,
-                                                      phba->sysfs_mbox.mbox,
-                               lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
+                       mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
+                       rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
                        spin_lock_irq(&phba->hbalock);
                }
 
@@ -4480,9 +4498,10 @@ lpfc_get_host_fabric_name (struct Scsi_Host *shost)
 
        spin_lock_irq(shost->host_lock);
 
-       if ((vport->fc_flag & FC_FABRIC) ||
-           ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
-            (vport->fc_flag & FC_PUBLIC_LOOP)))
+       if ((vport->port_state > LPFC_FLOGI) &&
+           ((vport->fc_flag & FC_FABRIC) ||
+            ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
+             (vport->fc_flag & FC_PUBLIC_LOOP))))
                node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
        else
                /* fabric is local port if there is no F/FL_Port */
@@ -4555,9 +4574,17 @@ lpfc_get_stats(struct Scsi_Host *shost)
        memset(hs, 0, sizeof (struct fc_host_statistics));
 
        hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
-       hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
+       /*
+        * The MBX_READ_STATUS returns tx_k_bytes which has to
+        * converted to words
+        */
+       hs->tx_words = (uint64_t)
+                       ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
+                       * (uint64_t)256);
        hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
-       hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
+       hs->rx_words = (uint64_t)
+                       ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
+                        * (uint64_t)256);
 
        memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
        pmb->mbxCommand = MBX_READ_LNK_STAT;
index a6db6aef133193a22f810f6ddd0e0800bdbc7918..60f95347babff7ae907753259a067f0909607b5c 100644 (file)
@@ -209,7 +209,7 @@ void __lpfc_mbox_cmpl_put(struct lpfc_hba *, LPFC_MBOXQ_t *);
 void lpfc_mbox_cmpl_put(struct lpfc_hba *, LPFC_MBOXQ_t *);
 int lpfc_mbox_cmd_check(struct lpfc_hba *, LPFC_MBOXQ_t *);
 int lpfc_mbox_dev_check(struct lpfc_hba *);
-int lpfc_mbox_tmo_val(struct lpfc_hba *, int);
+int lpfc_mbox_tmo_val(struct lpfc_hba *, LPFC_MBOXQ_t *);
 void lpfc_init_vfi(struct lpfcMboxq *, struct lpfc_vport *);
 void lpfc_reg_vfi(struct lpfcMboxq *, struct lpfc_vport *, dma_addr_t);
 void lpfc_init_vpi(struct lpfc_hba *, struct lpfcMboxq *, uint16_t);
@@ -451,3 +451,5 @@ int lpfc_wr_object(struct lpfc_hba *, struct list_head *, uint32_t, uint32_t *);
 /* functions to support SR-IOV */
 int lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *, int);
 uint16_t lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *);
+int lpfc_sli4_queue_create(struct lpfc_hba *);
+void lpfc_sli4_queue_destroy(struct lpfc_hba *);
index 779b88e1469d01a8d2bcf8dbe28d2faeb7070161..707081d0a2265ad88e7d4b18c25ca0d51d2a9998 100644 (file)
@@ -1856,6 +1856,9 @@ lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
                case 2:
                        c = 'B';
                        break;
+               case 3:
+                       c = 'X';
+                       break;
                default:
                        c = 0;
                        break;
index a0424dd90e4039863c272550e1263ce71c52c716..2cd844f7058f0ec20745485fc14f71afd33ee670 100644 (file)
@@ -996,6 +996,85 @@ lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
        return nbytes;
 }
 
+static int
+lpfc_debugfs_dif_err_open(struct inode *inode, struct file *file)
+{
+       file->private_data = inode->i_private;
+       return 0;
+}
+
+static ssize_t
+lpfc_debugfs_dif_err_read(struct file *file, char __user *buf,
+       size_t nbytes, loff_t *ppos)
+{
+       struct dentry *dent = file->f_dentry;
+       struct lpfc_hba *phba = file->private_data;
+       char cbuf[16];
+       int cnt = 0;
+
+       if (dent == phba->debug_writeGuard)
+               cnt = snprintf(cbuf, 16, "%u\n", phba->lpfc_injerr_wgrd_cnt);
+       else if (dent == phba->debug_writeApp)
+               cnt = snprintf(cbuf, 16, "%u\n", phba->lpfc_injerr_wapp_cnt);
+       else if (dent == phba->debug_writeRef)
+               cnt = snprintf(cbuf, 16, "%u\n", phba->lpfc_injerr_wref_cnt);
+       else if (dent == phba->debug_readApp)
+               cnt = snprintf(cbuf, 16, "%u\n", phba->lpfc_injerr_rapp_cnt);
+       else if (dent == phba->debug_readRef)
+               cnt = snprintf(cbuf, 16, "%u\n", phba->lpfc_injerr_rref_cnt);
+       else if (dent == phba->debug_InjErrLBA)
+               cnt = snprintf(cbuf, 16, "0x%lx\n",
+                                (unsigned long) phba->lpfc_injerr_lba);
+       else
+               lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
+                        "0547 Unknown debugfs error injection entry\n");
+
+       return simple_read_from_buffer(buf, nbytes, ppos, &cbuf, cnt);
+}
+
+static ssize_t
+lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
+       size_t nbytes, loff_t *ppos)
+{
+       struct dentry *dent = file->f_dentry;
+       struct lpfc_hba *phba = file->private_data;
+       char dstbuf[32];
+       unsigned long tmp;
+       int size;
+
+       memset(dstbuf, 0, 32);
+       size = (nbytes < 32) ? nbytes : 32;
+       if (copy_from_user(dstbuf, buf, size))
+               return 0;
+
+       if (strict_strtoul(dstbuf, 0, &tmp))
+               return 0;
+
+       if (dent == phba->debug_writeGuard)
+               phba->lpfc_injerr_wgrd_cnt = (uint32_t)tmp;
+       else if (dent == phba->debug_writeApp)
+               phba->lpfc_injerr_wapp_cnt = (uint32_t)tmp;
+       else if (dent == phba->debug_writeRef)
+               phba->lpfc_injerr_wref_cnt = (uint32_t)tmp;
+       else if (dent == phba->debug_readApp)
+               phba->lpfc_injerr_rapp_cnt = (uint32_t)tmp;
+       else if (dent == phba->debug_readRef)
+               phba->lpfc_injerr_rref_cnt = (uint32_t)tmp;
+       else if (dent == phba->debug_InjErrLBA)
+               phba->lpfc_injerr_lba = (sector_t)tmp;
+       else
+               lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
+                        "0548 Unknown debugfs error injection entry\n");
+
+       return nbytes;
+}
+
+static int
+lpfc_debugfs_dif_err_release(struct inode *inode, struct file *file)
+{
+       return 0;
+}
+
 /**
  * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
  * @inode: The inode pointer that contains a vport pointer.
@@ -3380,6 +3459,16 @@ static const struct file_operations lpfc_debugfs_op_dumpDif = {
        .release =      lpfc_debugfs_dumpDataDif_release,
 };
 
+#undef lpfc_debugfs_op_dif_err
+static const struct file_operations lpfc_debugfs_op_dif_err = {
+       .owner =        THIS_MODULE,
+       .open =         lpfc_debugfs_dif_err_open,
+       .llseek =       lpfc_debugfs_lseek,
+       .read =         lpfc_debugfs_dif_err_read,
+       .write =        lpfc_debugfs_dif_err_write,
+       .release =      lpfc_debugfs_dif_err_release,
+};
+
 #undef lpfc_debugfs_op_slow_ring_trc
 static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
        .owner =        THIS_MODULE,
@@ -3788,6 +3877,74 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
                        goto debug_failed;
                }
 
+               /* Setup DIF Error Injections */
+               snprintf(name, sizeof(name), "InjErrLBA");
+               phba->debug_InjErrLBA =
+                       debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+                       phba->hba_debugfs_root,
+                       phba, &lpfc_debugfs_op_dif_err);
+               if (!phba->debug_InjErrLBA) {
+                       lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
+                               "0807 Cannot create debugfs InjErrLBA\n");
+                       goto debug_failed;
+               }
+               phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
+
+               snprintf(name, sizeof(name), "writeGuardInjErr");
+               phba->debug_writeGuard =
+                       debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+                       phba->hba_debugfs_root,
+                       phba, &lpfc_debugfs_op_dif_err);
+               if (!phba->debug_writeGuard) {
+                       lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
+                               "0802 Cannot create debugfs writeGuard\n");
+                       goto debug_failed;
+               }
+
+               snprintf(name, sizeof(name), "writeAppInjErr");
+               phba->debug_writeApp =
+                       debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+                       phba->hba_debugfs_root,
+                       phba, &lpfc_debugfs_op_dif_err);
+               if (!phba->debug_writeApp) {
+                       lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
+                               "0803 Cannot create debugfs writeApp\n");
+                       goto debug_failed;
+               }
+
+               snprintf(name, sizeof(name), "writeRefInjErr");
+               phba->debug_writeRef =
+                       debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+                       phba->hba_debugfs_root,
+                       phba, &lpfc_debugfs_op_dif_err);
+               if (!phba->debug_writeRef) {
+                       lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
+                               "0804 Cannot create debugfs writeRef\n");
+                       goto debug_failed;
+               }
+
+               snprintf(name, sizeof(name), "readAppInjErr");
+               phba->debug_readApp =
+                       debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+                       phba->hba_debugfs_root,
+                       phba, &lpfc_debugfs_op_dif_err);
+               if (!phba->debug_readApp) {
+                       lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
+                               "0805 Cannot create debugfs readApp\n");
+                       goto debug_failed;
+               }
+
+               snprintf(name, sizeof(name), "readRefInjErr");
+               phba->debug_readRef =
+                       debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+                       phba->hba_debugfs_root,
+                       phba, &lpfc_debugfs_op_dif_err);
+               if (!phba->debug_readRef) {
+                       lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
+                               "0806 Cannot create debugfs readApp\n");
+                       goto debug_failed;
+               }
+
                /* Setup slow ring trace */
                if (lpfc_debugfs_max_slow_ring_trc) {
                        num = lpfc_debugfs_max_slow_ring_trc - 1;
@@ -4090,6 +4247,30 @@ lpfc_debugfs_terminate(struct lpfc_vport *vport)
                        debugfs_remove(phba->debug_dumpDif); /* dumpDif */
                        phba->debug_dumpDif = NULL;
                }
+               if (phba->debug_InjErrLBA) {
+                       debugfs_remove(phba->debug_InjErrLBA); /* InjErrLBA */
+                       phba->debug_InjErrLBA = NULL;
+               }
+               if (phba->debug_writeGuard) {
+                       debugfs_remove(phba->debug_writeGuard); /* writeGuard */
+                       phba->debug_writeGuard = NULL;
+               }
+               if (phba->debug_writeApp) {
+                       debugfs_remove(phba->debug_writeApp); /* writeApp */
+                       phba->debug_writeApp = NULL;
+               }
+               if (phba->debug_writeRef) {
+                       debugfs_remove(phba->debug_writeRef); /* writeRef */
+                       phba->debug_writeRef = NULL;
+               }
+               if (phba->debug_readApp) {
+                       debugfs_remove(phba->debug_readApp); /* readApp */
+                       phba->debug_readApp = NULL;
+               }
+               if (phba->debug_readRef) {
+                       debugfs_remove(phba->debug_readRef); /* readRef */
+                       phba->debug_readRef = NULL;
+               }
 
                if (phba->slow_ring_trc) {
                        kfree(phba->slow_ring_trc);
index 023da0e00d38609fe407e0acf8f08a80eab5f419..445826a4c9814a1e77188c356538b14b4d1ade62 100644 (file)
@@ -3386,7 +3386,14 @@ lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
                        cmdiocb->context1 = NULL;
                }
        }
+
+       /*
+        * The driver received a LOGO from the rport and has ACK'd it.
+        * At this point, the driver is done so release the IOCB and
+        * remove the ndlp reference.
+        */
        lpfc_els_free_iocb(phba, cmdiocb);
+       lpfc_nlp_put(ndlp);
        return;
 }
 
@@ -4082,9 +4089,6 @@ lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
 
        phba->fc_stat.elsXmitACC++;
        elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
-       lpfc_nlp_put(ndlp);
-       elsiocb->context1 = NULL;  /* Don't need ndlp for cmpl,
-                                   * it could be freed */
 
        rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
        if (rc == IOCB_ERROR) {
@@ -4166,6 +4170,11 @@ lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
        psli = &phba->sli;
        cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
 
+       /* The accumulated length can exceed the BPL_SIZE.  For
+        * now, use this as the limit
+        */
+       if (cmdsize > LPFC_BPL_SIZE)
+               cmdsize = LPFC_BPL_SIZE;
        elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
                                     ndlp->nlp_DID, ELS_CMD_ACC);
        if (!elsiocb)
@@ -4189,9 +4198,6 @@ lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
 
        phba->fc_stat.elsXmitACC++;
        elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
-       lpfc_nlp_put(ndlp);
-       elsiocb->context1 = NULL;  /* Don't need ndlp for cmpl,
-                                   * it could be freed */
 
        rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
        if (rc == IOCB_ERROR) {
@@ -7258,16 +7264,11 @@ lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
        icmd->un.elsreq64.myID = 0;
        icmd->un.elsreq64.fl = 1;
 
-       if  ((phba->sli_rev == LPFC_SLI_REV4) &&
-            (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
-             LPFC_SLI_INTF_IF_TYPE_0)) {
-               /* FDISC needs to be 1 for WQE VPI */
-               elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
-               elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
-               /* Set the ulpContext to the vpi */
-               elsiocb->iocb.ulpContext = phba->vpi_ids[vport->vpi];
-       } else {
-               /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
+       /*
+        * SLI3 ports require a different context type value than SLI4.
+        * Catch SLI3 ports here and override the prep.
+        */
+       if (phba->sli_rev == LPFC_SLI_REV3) {
                icmd->ulpCt_h = 1;
                icmd->ulpCt_l = 0;
        }
index 0b47adf9fee8e18ae0e9becbb8232b9a98baba86..091f68e5cb70a0e4a327073943d66de63de43446 100644 (file)
@@ -1412,7 +1412,7 @@ lpfc_register_fcf(struct lpfc_hba *phba)
                if (phba->pport->port_state != LPFC_FLOGI) {
                        phba->hba_flag |= FCF_RR_INPROG;
                        spin_unlock_irq(&phba->hbalock);
-                       lpfc_issue_init_vfi(phba->pport);
+                       lpfc_initial_flogi(phba->pport);
                        return;
                }
                spin_unlock_irq(&phba->hbalock);
@@ -2646,7 +2646,9 @@ lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
 {
        struct lpfc_vport *vport = mboxq->vport;
 
-       if (mboxq->u.mb.mbxStatus && (mboxq->u.mb.mbxStatus != 0x4002)) {
+       /* VFI not supported on interface type 0, just do the flogi */
+       if (mboxq->u.mb.mbxStatus && (bf_get(lpfc_sli_intf_if_type,
+           &phba->sli4_hba.sli_intf) != LPFC_SLI_INTF_IF_TYPE_0)) {
                lpfc_printf_vlog(vport, KERN_ERR,
                                LOG_MBOX,
                                "2891 Init VFI mailbox failed 0x%x\n",
@@ -2655,6 +2657,7 @@ lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
                lpfc_vport_set_state(vport, FC_VPORT_FAILED);
                return;
        }
+
        lpfc_initial_flogi(vport);
        mempool_free(mboxq, phba->mbox_mem_pool);
        return;
index 7f8003b5181eb47504b86930550af227853ca2b1..98d21521f5391b149d41d709c28bcb4b0db79e93 100644 (file)
@@ -41,6 +41,8 @@
  * Or clear that bit field:
  *     bf_set(example_bit_field, &t1, 0);
  */
+#define bf_get_be32(name, ptr) \
+       ((be32_to_cpu((ptr)->name##_WORD) >> name##_SHIFT) & name##_MASK)
 #define bf_get_le32(name, ptr) \
        ((le32_to_cpu((ptr)->name##_WORD) >> name##_SHIFT) & name##_MASK)
 #define bf_get(name, ptr) \
@@ -678,7 +680,6 @@ struct lpfc_register {
 #define lpfc_rq_doorbell_num_posted_SHIFT      16
 #define lpfc_rq_doorbell_num_posted_MASK       0x3FFF
 #define lpfc_rq_doorbell_num_posted_WORD       word0
-#define LPFC_RQ_POST_BATCH             8       /* RQEs to post at one time */
 #define lpfc_rq_doorbell_id_SHIFT              0
 #define lpfc_rq_doorbell_id_MASK               0xFFFF
 #define lpfc_rq_doorbell_id_WORD               word0
@@ -784,6 +785,8 @@ union lpfc_sli4_cfg_shdr {
 #define LPFC_Q_CREATE_VERSION_2        2
 #define LPFC_Q_CREATE_VERSION_1        1
 #define LPFC_Q_CREATE_VERSION_0        0
+#define LPFC_OPCODE_VERSION_0  0
+#define LPFC_OPCODE_VERSION_1  1
        } request;
        struct {
                uint32_t word6;
@@ -825,6 +828,7 @@ struct mbox_header {
 #define LPFC_EXTENT_VERSION_DEFAULT    0
 
 /* Subsystem Definitions */
+#define LPFC_MBOX_SUBSYSTEM_NA         0x0
 #define LPFC_MBOX_SUBSYSTEM_COMMON     0x1
 #define LPFC_MBOX_SUBSYSTEM_FCOE       0xC
 
@@ -835,25 +839,34 @@ struct mbox_header {
 #define HOST_ENDIAN_HIGH_WORD1 0xFF7856FF
 
 /* Common Opcodes */
-#define LPFC_MBOX_OPCODE_CQ_CREATE             0x0C
-#define LPFC_MBOX_OPCODE_EQ_CREATE             0x0D
-#define LPFC_MBOX_OPCODE_MQ_CREATE             0x15
-#define LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES   0x20
-#define LPFC_MBOX_OPCODE_NOP                   0x21
-#define LPFC_MBOX_OPCODE_MQ_DESTROY            0x35
-#define LPFC_MBOX_OPCODE_CQ_DESTROY            0x36
-#define LPFC_MBOX_OPCODE_EQ_DESTROY            0x37
-#define LPFC_MBOX_OPCODE_QUERY_FW_CFG          0x3A
-#define LPFC_MBOX_OPCODE_FUNCTION_RESET                0x3D
-#define LPFC_MBOX_OPCODE_MQ_CREATE_EXT         0x5A
-#define LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO  0x9A
-#define LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT 0x9B
-#define LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT     0x9C
-#define LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT   0x9D
-#define LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG    0xA0
-#define LPFC_MBOX_OPCODE_GET_PROFILE_CONFIG    0xA4
-#define LPFC_MBOX_OPCODE_WRITE_OBJECT          0xAC
-#define LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS   0xB5
+#define LPFC_MBOX_OPCODE_NA                            0x00
+#define LPFC_MBOX_OPCODE_CQ_CREATE                     0x0C
+#define LPFC_MBOX_OPCODE_EQ_CREATE                     0x0D
+#define LPFC_MBOX_OPCODE_MQ_CREATE                     0x15
+#define LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES           0x20
+#define LPFC_MBOX_OPCODE_NOP                           0x21
+#define LPFC_MBOX_OPCODE_MQ_DESTROY                    0x35
+#define LPFC_MBOX_OPCODE_CQ_DESTROY                    0x36
+#define LPFC_MBOX_OPCODE_EQ_DESTROY                    0x37
+#define LPFC_MBOX_OPCODE_QUERY_FW_CFG                  0x3A
+#define LPFC_MBOX_OPCODE_FUNCTION_RESET                        0x3D
+#define LPFC_MBOX_OPCODE_GET_PORT_NAME                 0x4D
+#define LPFC_MBOX_OPCODE_MQ_CREATE_EXT                 0x5A
+#define LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO          0x9A
+#define LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT         0x9B
+#define LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT             0x9C
+#define LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT           0x9D
+#define LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG           0xA0
+#define LPFC_MBOX_OPCODE_GET_PROFILE_CONFIG            0xA4
+#define LPFC_MBOX_OPCODE_SET_PROFILE_CONFIG            0xA5
+#define LPFC_MBOX_OPCODE_GET_PROFILE_LIST              0xA6
+#define LPFC_MBOX_OPCODE_SET_ACT_PROFILE               0xA8
+#define LPFC_MBOX_OPCODE_GET_FACTORY_PROFILE_CONFIG    0xA9
+#define LPFC_MBOX_OPCODE_READ_OBJECT                   0xAB
+#define LPFC_MBOX_OPCODE_WRITE_OBJECT                  0xAC
+#define LPFC_MBOX_OPCODE_READ_OBJECT_LIST              0xAD
+#define LPFC_MBOX_OPCODE_DELETE_OBJECT                 0xAE
+#define LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS           0xB5
 
 /* FCoE Opcodes */
 #define LPFC_MBOX_OPCODE_FCOE_WQ_CREATE                        0x01
@@ -867,6 +880,7 @@ struct mbox_header {
 #define LPFC_MBOX_OPCODE_FCOE_DELETE_FCF               0x0A
 #define LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE                0x0B
 #define LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF           0x10
+#define LPFC_MBOX_OPCODE_FCOE_SET_FCLINK_SETTINGS      0x21
 #define LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_STATE          0x22
 #define LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_LOOPBACK       0x23
 
@@ -1470,16 +1484,81 @@ struct sli4_sge {       /* SLI-4 */
        uint32_t addr_lo;
 
        uint32_t word2;
-#define lpfc_sli4_sge_offset_SHIFT     0 /* Offset of buffer - Not used*/
-#define lpfc_sli4_sge_offset_MASK      0x1FFFFFFF
+#define lpfc_sli4_sge_offset_SHIFT     0
+#define lpfc_sli4_sge_offset_MASK      0x07FFFFFF
 #define lpfc_sli4_sge_offset_WORD      word2
-#define lpfc_sli4_sge_last_SHIFT       31 /* Last SEG in the SGL sets
-                                               this  flag !! */
+#define lpfc_sli4_sge_type_SHIFT       27
+#define lpfc_sli4_sge_type_MASK                0x0000000F
+#define lpfc_sli4_sge_type_WORD                word2
+#define LPFC_SGE_TYPE_DATA             0x0
+#define LPFC_SGE_TYPE_DIF              0x4
+#define LPFC_SGE_TYPE_LSP              0x5
+#define LPFC_SGE_TYPE_PEDIF            0x6
+#define LPFC_SGE_TYPE_PESEED           0x7
+#define LPFC_SGE_TYPE_DISEED           0x8
+#define LPFC_SGE_TYPE_ENC              0x9
+#define LPFC_SGE_TYPE_ATM              0xA
+#define LPFC_SGE_TYPE_SKIP             0xC
+#define lpfc_sli4_sge_last_SHIFT       31 /* Last SEG in the SGL sets it */
 #define lpfc_sli4_sge_last_MASK                0x00000001
 #define lpfc_sli4_sge_last_WORD                word2
        uint32_t sge_len;
 };
 
+struct sli4_sge_diseed {       /* SLI-4 */
+       uint32_t ref_tag;
+       uint32_t ref_tag_tran;
+
+       uint32_t word2;
+#define lpfc_sli4_sge_dif_apptran_SHIFT        0
+#define lpfc_sli4_sge_dif_apptran_MASK 0x0000FFFF
+#define lpfc_sli4_sge_dif_apptran_WORD word2
+#define lpfc_sli4_sge_dif_af_SHIFT     24
+#define lpfc_sli4_sge_dif_af_MASK      0x00000001
+#define lpfc_sli4_sge_dif_af_WORD      word2
+#define lpfc_sli4_sge_dif_na_SHIFT     25
+#define lpfc_sli4_sge_dif_na_MASK      0x00000001
+#define lpfc_sli4_sge_dif_na_WORD      word2
+#define lpfc_sli4_sge_dif_hi_SHIFT     26
+#define lpfc_sli4_sge_dif_hi_MASK      0x00000001
+#define lpfc_sli4_sge_dif_hi_WORD      word2
+#define lpfc_sli4_sge_dif_type_SHIFT   27
+#define lpfc_sli4_sge_dif_type_MASK    0x0000000F
+#define lpfc_sli4_sge_dif_type_WORD    word2
+#define lpfc_sli4_sge_dif_last_SHIFT   31 /* Last SEG in the SGL sets it */
+#define lpfc_sli4_sge_dif_last_MASK    0x00000001
+#define lpfc_sli4_sge_dif_last_WORD    word2
+       uint32_t word3;
+#define lpfc_sli4_sge_dif_apptag_SHIFT 0
+#define lpfc_sli4_sge_dif_apptag_MASK  0x0000FFFF
+#define lpfc_sli4_sge_dif_apptag_WORD  word3
+#define lpfc_sli4_sge_dif_bs_SHIFT     16
+#define lpfc_sli4_sge_dif_bs_MASK      0x00000007
+#define lpfc_sli4_sge_dif_bs_WORD      word3
+#define lpfc_sli4_sge_dif_ai_SHIFT     19
+#define lpfc_sli4_sge_dif_ai_MASK      0x00000001
+#define lpfc_sli4_sge_dif_ai_WORD      word3
+#define lpfc_sli4_sge_dif_me_SHIFT     20
+#define lpfc_sli4_sge_dif_me_MASK      0x00000001
+#define lpfc_sli4_sge_dif_me_WORD      word3
+#define lpfc_sli4_sge_dif_re_SHIFT     21
+#define lpfc_sli4_sge_dif_re_MASK      0x00000001
+#define lpfc_sli4_sge_dif_re_WORD      word3
+#define lpfc_sli4_sge_dif_ce_SHIFT     22
+#define lpfc_sli4_sge_dif_ce_MASK      0x00000001
+#define lpfc_sli4_sge_dif_ce_WORD      word3
+#define lpfc_sli4_sge_dif_nr_SHIFT     23
+#define lpfc_sli4_sge_dif_nr_MASK      0x00000001
+#define lpfc_sli4_sge_dif_nr_WORD      word3
+#define lpfc_sli4_sge_dif_oprx_SHIFT   24
+#define lpfc_sli4_sge_dif_oprx_MASK    0x0000000F
+#define lpfc_sli4_sge_dif_oprx_WORD    word3
+#define lpfc_sli4_sge_dif_optx_SHIFT   28
+#define lpfc_sli4_sge_dif_optx_MASK    0x0000000F
+#define lpfc_sli4_sge_dif_optx_WORD    word3
+/* optx and oprx use BG_OP_IN defines in lpfc_hw.h */
+};
+
 struct fcf_record {
        uint32_t max_rcv_size;
        uint32_t fka_adv_period;
@@ -2019,6 +2098,15 @@ struct lpfc_mbx_read_config {
 #define lpfc_mbx_rd_conf_extnts_inuse_MASK     0x00000001
 #define lpfc_mbx_rd_conf_extnts_inuse_WORD     word1
        uint32_t word2;
+#define lpfc_mbx_rd_conf_lnk_numb_SHIFT                0
+#define lpfc_mbx_rd_conf_lnk_numb_MASK         0x0000003F
+#define lpfc_mbx_rd_conf_lnk_numb_WORD         word2
+#define lpfc_mbx_rd_conf_lnk_type_SHIFT                6
+#define lpfc_mbx_rd_conf_lnk_type_MASK         0x00000003
+#define lpfc_mbx_rd_conf_lnk_type_WORD         word2
+#define lpfc_mbx_rd_conf_lnk_ldv_SHIFT         8
+#define lpfc_mbx_rd_conf_lnk_ldv_MASK          0x00000001
+#define lpfc_mbx_rd_conf_lnk_ldv_WORD          word2
 #define lpfc_mbx_rd_conf_topology_SHIFT                24
 #define lpfc_mbx_rd_conf_topology_MASK         0x000000FF
 #define lpfc_mbx_rd_conf_topology_WORD         word2
@@ -2552,8 +2640,152 @@ struct lpfc_mbx_get_prof_cfg {
        } u;
 };
 
+struct lpfc_controller_attribute {
+       uint32_t version_string[8];
+       uint32_t manufacturer_name[8];
+       uint32_t supported_modes;
+       uint32_t word17;
+#define lpfc_cntl_attr_eprom_ver_lo_SHIFT      0
+#define lpfc_cntl_attr_eprom_ver_lo_MASK       0x000000ff
+#define lpfc_cntl_attr_eprom_ver_lo_WORD       word17
+#define lpfc_cntl_attr_eprom_ver_hi_SHIFT      8
+#define lpfc_cntl_attr_eprom_ver_hi_MASK       0x000000ff
+#define lpfc_cntl_attr_eprom_ver_hi_WORD       word17
+       uint32_t mbx_da_struct_ver;
+       uint32_t ep_fw_da_struct_ver;
+       uint32_t ncsi_ver_str[3];
+       uint32_t dflt_ext_timeout;
+       uint32_t model_number[8];
+       uint32_t description[16];
+       uint32_t serial_number[8];
+       uint32_t ip_ver_str[8];
+       uint32_t fw_ver_str[8];
+       uint32_t bios_ver_str[8];
+       uint32_t redboot_ver_str[8];
+       uint32_t driver_ver_str[8];
+       uint32_t flash_fw_ver_str[8];
+       uint32_t functionality;
+       uint32_t word105;
+#define lpfc_cntl_attr_max_cbd_len_SHIFT       0
+#define lpfc_cntl_attr_max_cbd_len_MASK                0x0000ffff
+#define lpfc_cntl_attr_max_cbd_len_WORD                word105
+#define lpfc_cntl_attr_asic_rev_SHIFT          16
+#define lpfc_cntl_attr_asic_rev_MASK           0x000000ff
+#define lpfc_cntl_attr_asic_rev_WORD           word105
+#define lpfc_cntl_attr_gen_guid0_SHIFT         24
+#define lpfc_cntl_attr_gen_guid0_MASK          0x000000ff
+#define lpfc_cntl_attr_gen_guid0_WORD          word105
+       uint32_t gen_guid1_12[3];
+       uint32_t word109;
+#define lpfc_cntl_attr_gen_guid13_14_SHIFT     0
+#define lpfc_cntl_attr_gen_guid13_14_MASK      0x0000ffff
+#define lpfc_cntl_attr_gen_guid13_14_WORD      word109
+#define lpfc_cntl_attr_gen_guid15_SHIFT                16
+#define lpfc_cntl_attr_gen_guid15_MASK         0x000000ff
+#define lpfc_cntl_attr_gen_guid15_WORD         word109
+#define lpfc_cntl_attr_hba_port_cnt_SHIFT      24
+#define lpfc_cntl_attr_hba_port_cnt_MASK       0x000000ff
+#define lpfc_cntl_attr_hba_port_cnt_WORD       word109
+       uint32_t word110;
+#define lpfc_cntl_attr_dflt_lnk_tmo_SHIFT      0
+#define lpfc_cntl_attr_dflt_lnk_tmo_MASK       0x0000ffff
+#define lpfc_cntl_attr_dflt_lnk_tmo_WORD       word110
+#define lpfc_cntl_attr_multi_func_dev_SHIFT    24
+#define lpfc_cntl_attr_multi_func_dev_MASK     0x000000ff
+#define lpfc_cntl_attr_multi_func_dev_WORD     word110
+       uint32_t word111;
+#define lpfc_cntl_attr_cache_valid_SHIFT       0
+#define lpfc_cntl_attr_cache_valid_MASK                0x000000ff
+#define lpfc_cntl_attr_cache_valid_WORD                word111
+#define lpfc_cntl_attr_hba_status_SHIFT                8
+#define lpfc_cntl_attr_hba_status_MASK         0x000000ff
+#define lpfc_cntl_attr_hba_status_WORD         word111
+#define lpfc_cntl_attr_max_domain_SHIFT                16
+#define lpfc_cntl_attr_max_domain_MASK         0x000000ff
+#define lpfc_cntl_attr_max_domain_WORD         word111
+#define lpfc_cntl_attr_lnk_numb_SHIFT          24
+#define lpfc_cntl_attr_lnk_numb_MASK           0x0000003f
+#define lpfc_cntl_attr_lnk_numb_WORD           word111
+#define lpfc_cntl_attr_lnk_type_SHIFT          30
+#define lpfc_cntl_attr_lnk_type_MASK           0x00000003
+#define lpfc_cntl_attr_lnk_type_WORD           word111
+       uint32_t fw_post_status;
+       uint32_t hba_mtu[8];
+       uint32_t word121;
+       uint32_t reserved1[3];
+       uint32_t word125;
+#define lpfc_cntl_attr_pci_vendor_id_SHIFT     0
+#define lpfc_cntl_attr_pci_vendor_id_MASK      0x0000ffff
+#define lpfc_cntl_attr_pci_vendor_id_WORD      word125
+#define lpfc_cntl_attr_pci_device_id_SHIFT     16
+#define lpfc_cntl_attr_pci_device_id_MASK      0x0000ffff
+#define lpfc_cntl_attr_pci_device_id_WORD      word125
+       uint32_t word126;
+#define lpfc_cntl_attr_pci_subvdr_id_SHIFT     0
+#define lpfc_cntl_attr_pci_subvdr_id_MASK      0x0000ffff
+#define lpfc_cntl_attr_pci_subvdr_id_WORD      word126
+#define lpfc_cntl_attr_pci_subsys_id_SHIFT     16
+#define lpfc_cntl_attr_pci_subsys_id_MASK      0x0000ffff
+#define lpfc_cntl_attr_pci_subsys_id_WORD      word126
+       uint32_t word127;
+#define lpfc_cntl_attr_pci_bus_num_SHIFT       0
+#define lpfc_cntl_attr_pci_bus_num_MASK                0x000000ff
+#define lpfc_cntl_attr_pci_bus_num_WORD                word127
+#define lpfc_cntl_attr_pci_dev_num_SHIFT       8
+#define lpfc_cntl_attr_pci_dev_num_MASK                0x000000ff
+#define lpfc_cntl_attr_pci_dev_num_WORD                word127
+#define lpfc_cntl_attr_pci_fnc_num_SHIFT       16
+#define lpfc_cntl_attr_pci_fnc_num_MASK                0x000000ff
+#define lpfc_cntl_attr_pci_fnc_num_WORD                word127
+#define lpfc_cntl_attr_inf_type_SHIFT          24
+#define lpfc_cntl_attr_inf_type_MASK           0x000000ff
+#define lpfc_cntl_attr_inf_type_WORD           word127
+       uint32_t unique_id[2];
+       uint32_t word130;
+#define lpfc_cntl_attr_num_netfil_SHIFT                0
+#define lpfc_cntl_attr_num_netfil_MASK         0x000000ff
+#define lpfc_cntl_attr_num_netfil_WORD         word130
+       uint32_t reserved2[4];
+};
+
+struct lpfc_mbx_get_cntl_attributes {
+       union  lpfc_sli4_cfg_shdr cfg_shdr;
+       struct lpfc_controller_attribute cntl_attr;
+};
+
+struct lpfc_mbx_get_port_name {
+       struct mbox_header header;
+       union {
+               struct {
+                       uint32_t word4;
+#define lpfc_mbx_get_port_name_lnk_type_SHIFT  0
+#define lpfc_mbx_get_port_name_lnk_type_MASK   0x00000003
+#define lpfc_mbx_get_port_name_lnk_type_WORD   word4
+               } request;
+               struct {
+                       uint32_t word4;
+#define lpfc_mbx_get_port_name_name0_SHIFT     0
+#define lpfc_mbx_get_port_name_name0_MASK      0x000000FF
+#define lpfc_mbx_get_port_name_name0_WORD      word4
+#define lpfc_mbx_get_port_name_name1_SHIFT     8
+#define lpfc_mbx_get_port_name_name1_MASK      0x000000FF
+#define lpfc_mbx_get_port_name_name1_WORD      word4
+#define lpfc_mbx_get_port_name_name2_SHIFT     16
+#define lpfc_mbx_get_port_name_name2_MASK      0x000000FF
+#define lpfc_mbx_get_port_name_name2_WORD      word4
+#define lpfc_mbx_get_port_name_name3_SHIFT     24
+#define lpfc_mbx_get_port_name_name3_MASK      0x000000FF
+#define lpfc_mbx_get_port_name_name3_WORD      word4
+#define LPFC_LINK_NUMBER_0                     0
+#define LPFC_LINK_NUMBER_1                     1
+#define LPFC_LINK_NUMBER_2                     2
+#define LPFC_LINK_NUMBER_3                     3
+               } response;
+       } u;
+};
+
 /* Mailbox Completion Queue Error Messages */
-#define MB_CQE_STATUS_SUCCESS                  0x0
+#define MB_CQE_STATUS_SUCCESS                  0x0
 #define MB_CQE_STATUS_INSUFFICIENT_PRIVILEGES  0x1
 #define MB_CQE_STATUS_INVALID_PARAMETER                0x2
 #define MB_CQE_STATUS_INSUFFICIENT_RESOURCES   0x3
@@ -2637,8 +2869,9 @@ struct lpfc_mqe {
                struct lpfc_mbx_run_link_diag_test link_diag_test;
                struct lpfc_mbx_get_func_cfg get_func_cfg;
                struct lpfc_mbx_get_prof_cfg get_prof_cfg;
-               struct lpfc_mbx_nop nop;
                struct lpfc_mbx_wr_object wr_object;
+               struct lpfc_mbx_get_port_name get_port_name;
+               struct lpfc_mbx_nop nop;
        } un;
 };
 
@@ -2855,6 +3088,9 @@ struct wqe_common {
 #define wqe_ctxt_tag_MASK     0x0000FFFF
 #define wqe_ctxt_tag_WORD     word6
        uint32_t word7;
+#define wqe_dif_SHIFT         0
+#define wqe_dif_MASK          0x00000003
+#define wqe_dif_WORD          word7
 #define wqe_ct_SHIFT          2
 #define wqe_ct_MASK           0x00000003
 #define wqe_ct_WORD           word7
@@ -2867,12 +3103,21 @@ struct wqe_common {
 #define wqe_class_SHIFT       16
 #define wqe_class_MASK        0x00000007
 #define wqe_class_WORD        word7
+#define wqe_ar_SHIFT          19
+#define wqe_ar_MASK           0x00000001
+#define wqe_ar_WORD           word7
+#define wqe_ag_SHIFT          wqe_ar_SHIFT
+#define wqe_ag_MASK           wqe_ar_MASK
+#define wqe_ag_WORD           wqe_ar_WORD
 #define wqe_pu_SHIFT          20
 #define wqe_pu_MASK           0x00000003
 #define wqe_pu_WORD           word7
 #define wqe_erp_SHIFT         22
 #define wqe_erp_MASK          0x00000001
 #define wqe_erp_WORD          word7
+#define wqe_conf_SHIFT        wqe_erp_SHIFT
+#define wqe_conf_MASK         wqe_erp_MASK
+#define wqe_conf_WORD         wqe_erp_WORD
 #define wqe_lnk_SHIFT         23
 #define wqe_lnk_MASK          0x00000001
 #define wqe_lnk_WORD          word7
@@ -2931,6 +3176,9 @@ struct wqe_common {
 #define wqe_xc_SHIFT          21
 #define wqe_xc_MASK           0x00000001
 #define wqe_xc_WORD           word10
+#define wqe_sr_SHIFT          22
+#define wqe_sr_MASK           0x00000001
+#define wqe_sr_WORD           word10
 #define wqe_ccpe_SHIFT        23
 #define wqe_ccpe_MASK         0x00000001
 #define wqe_ccpe_WORD         word10
index a3c820083c368527c37ac2ea451a0634b281b1e4..907c94b9245dc0989ae6184506a449543e4ccef0 100644 (file)
@@ -58,8 +58,7 @@ spinlock_t _dump_buf_lock;
 
 static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
 static int lpfc_post_rcv_buf(struct lpfc_hba *);
-static int lpfc_sli4_queue_create(struct lpfc_hba *);
-static void lpfc_sli4_queue_destroy(struct lpfc_hba *);
+static int lpfc_sli4_queue_verify(struct lpfc_hba *);
 static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
 static int lpfc_setup_endian_order(struct lpfc_hba *);
 static int lpfc_sli4_read_config(struct lpfc_hba *);
@@ -1438,6 +1437,7 @@ lpfc_handle_eratt_s4(struct lpfc_hba *phba)
        struct Scsi_Host *shost;
        uint32_t if_type;
        struct lpfc_register portstat_reg;
+       int rc;
 
        /* If the pci channel is offline, ignore possible errors, since
         * we cannot communicate with the pci card anyway.
@@ -1480,16 +1480,24 @@ lpfc_handle_eratt_s4(struct lpfc_hba *phba)
                        lpfc_sli4_offline_eratt(phba);
                        return;
                }
-               if (bf_get(lpfc_sliport_status_rn, &portstat_reg)) {
-                       /*
-                        * TODO: Attempt port recovery via a port reset.
-                        * When fully implemented, the driver should
-                        * attempt to recover the port here and return.
-                        * For now, log an error and take the port offline.
-                        */
+               /*
+                * On error status condition, driver need to wait for port
+                * ready before performing reset.
+                */
+               rc = lpfc_sli4_pdev_status_reg_wait(phba);
+               if (!rc) {
+                       /* need reset: attempt for port recovery */
                        lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
                                        "2887 Port Error: Attempting "
                                        "Port Recovery\n");
+                       lpfc_offline_prep(phba);
+                       lpfc_offline(phba);
+                       lpfc_sli_brdrestart(phba);
+                       if (lpfc_online(phba) == 0) {
+                               lpfc_unblock_mgmt_io(phba);
+                               return;
+                       }
+                       /* fall through for not able to recover */
                }
                lpfc_sli4_offline_eratt(phba);
                break;
@@ -1724,11 +1732,20 @@ lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
                                j = 0;
                                Length -= (3+i);
                                while(i--) {
-                               phba->Port[j++] = vpd[index++];
-                               if (j == 19)
-                                       break;
+                                       if ((phba->sli_rev == LPFC_SLI_REV4) &&
+                                           (phba->sli4_hba.pport_name_sta ==
+                                            LPFC_SLI4_PPNAME_GET)) {
+                                               j++;
+                                               index++;
+                                       } else
+                                               phba->Port[j++] = vpd[index++];
+                                       if (j == 19)
+                                               break;
                                }
-                               phba->Port[j] = 0;
+                               if ((phba->sli_rev != LPFC_SLI_REV4) ||
+                                   (phba->sli4_hba.pport_name_sta ==
+                                    LPFC_SLI4_PPNAME_NON))
+                                       phba->Port[j] = 0;
                                continue;
                        }
                        else {
@@ -1958,7 +1975,7 @@ lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
        case PCI_DEVICE_ID_LANCER_FCOE:
        case PCI_DEVICE_ID_LANCER_FCOE_VF:
                oneConnect = 1;
-               m = (typeof(m)){"OCe50100", "PCIe", "FCoE"};
+               m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
                break;
        default:
                m = (typeof(m)){"Unknown", "", ""};
@@ -2432,17 +2449,19 @@ lpfc_block_mgmt_io(struct lpfc_hba * phba)
        uint8_t actcmd = MBX_HEARTBEAT;
        unsigned long timeout;
 
-
+       timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
        spin_lock_irqsave(&phba->hbalock, iflag);
        phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
-       if (phba->sli.mbox_active)
+       if (phba->sli.mbox_active) {
                actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
+               /* Determine how long we might wait for the active mailbox
+                * command to be gracefully completed by firmware.
+                */
+               timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
+                               phba->sli.mbox_active) * 1000) + jiffies;
+       }
        spin_unlock_irqrestore(&phba->hbalock, iflag);
-       /* Determine how long we might wait for the active mailbox
-        * command to be gracefully completed by firmware.
-        */
-       timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
-                       jiffies;
+
        /* Wait for the outstnading mailbox command to complete */
        while (phba->sli.mbox_active) {
                /* Check active mailbox complete status every 2ms */
@@ -3949,7 +3968,7 @@ static int
 lpfc_enable_pci_dev(struct lpfc_hba *phba)
 {
        struct pci_dev *pdev;
-       int bars;
+       int bars = 0;
 
        /* Obtain PCI device reference */
        if (!phba->pcidev)
@@ -3978,6 +3997,8 @@ lpfc_enable_pci_dev(struct lpfc_hba *phba)
 out_disable_device:
        pci_disable_device(pdev);
 out_error:
+       lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
+                       "1401 Failed to enable pci device, bars:x%x\n", bars);
        return -ENODEV;
 }
 
@@ -4051,9 +4072,6 @@ lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
        uint16_t nr_virtfn;
        int pos;
 
-       if (!pdev->is_physfn)
-               return 0;
-
        pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
        if (pos == 0)
                return 0;
@@ -4474,15 +4492,15 @@ lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
                }
        }
        mempool_free(mboxq, phba->mbox_mem_pool);
-       /* Create all the SLI4 queues */
-       rc = lpfc_sli4_queue_create(phba);
+       /* Verify all the SLI4 queues */
+       rc = lpfc_sli4_queue_verify(phba);
        if (rc)
                goto out_free_bsmbx;
 
        /* Create driver internal CQE event pool */
        rc = lpfc_sli4_cq_event_pool_create(phba);
        if (rc)
-               goto out_destroy_queue;
+               goto out_free_bsmbx;
 
        /* Initialize and populate the iocb list per host */
        rc = lpfc_init_sgl_list(phba);
@@ -4516,14 +4534,21 @@ lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
                goto out_remove_rpi_hdrs;
        }
 
-       phba->sli4_hba.fcp_eq_hdl = kzalloc((sizeof(struct lpfc_fcp_eq_hdl) *
+       /*
+        * The cfg_fcp_eq_count can be zero whenever there is exactly one
+        * interrupt vector.  This is not an error
+        */
+       if (phba->cfg_fcp_eq_count) {
+               phba->sli4_hba.fcp_eq_hdl =
+                               kzalloc((sizeof(struct lpfc_fcp_eq_hdl) *
                                    phba->cfg_fcp_eq_count), GFP_KERNEL);
-       if (!phba->sli4_hba.fcp_eq_hdl) {
-               lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
-                               "2572 Failed allocate memory for fast-path "
-                               "per-EQ handle array\n");
-               rc = -ENOMEM;
-               goto out_free_fcf_rr_bmask;
+               if (!phba->sli4_hba.fcp_eq_hdl) {
+                       lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
+                                       "2572 Failed allocate memory for "
+                                       "fast-path per-EQ handle array\n");
+                       rc = -ENOMEM;
+                       goto out_free_fcf_rr_bmask;
+               }
        }
 
        phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) *
@@ -4567,8 +4592,6 @@ out_free_sgl_list:
        lpfc_free_sgl_list(phba);
 out_destroy_cq_event_pool:
        lpfc_sli4_cq_event_pool_destroy(phba);
-out_destroy_queue:
-       lpfc_sli4_queue_destroy(phba);
 out_free_bsmbx:
        lpfc_destroy_bootstrap_mbox(phba);
 out_free_mem:
@@ -4608,9 +4631,6 @@ lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
        /* Free the SCSI sgl management array */
        kfree(phba->sli4_hba.lpfc_scsi_psb_array);
 
-       /* Free the SLI4 queues */
-       lpfc_sli4_queue_destroy(phba);
-
        /* Free the completion queue EQ event pool */
        lpfc_sli4_cq_event_release_all(phba);
        lpfc_sli4_cq_event_pool_destroy(phba);
@@ -6139,24 +6159,21 @@ lpfc_setup_endian_order(struct lpfc_hba *phba)
 }
 
 /**
- * lpfc_sli4_queue_create - Create all the SLI4 queues
+ * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts
  * @phba: pointer to lpfc hba data structure.
  *
- * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
- * operation. For each SLI4 queue type, the parameters such as queue entry
- * count (queue depth) shall be taken from the module parameter. For now,
- * we just use some constant number as place holder.
+ * This routine is invoked to check the user settable queue counts for EQs and
+ * CQs. after this routine is called the counts will be set to valid values that
+ * adhere to the constraints of the system's interrupt vectors and the port's
+ * queue resources.
  *
  * Return codes
  *      0 - successful
  *      -ENOMEM - No available memory
- *      -EIO - The mailbox failed to complete successfully.
  **/
 static int
-lpfc_sli4_queue_create(struct lpfc_hba *phba)
+lpfc_sli4_queue_verify(struct lpfc_hba *phba)
 {
-       struct lpfc_queue *qdesc;
-       int fcp_eqidx, fcp_cqidx, fcp_wqidx;
        int cfg_fcp_wq_count;
        int cfg_fcp_eq_count;
 
@@ -6229,14 +6246,43 @@ lpfc_sli4_queue_create(struct lpfc_hba *phba)
        /* The overall number of event queues used */
        phba->sli4_hba.cfg_eqn = phba->cfg_fcp_eq_count + LPFC_SP_EQN_DEF;
 
-       /*
-        * Create Event Queues (EQs)
-        */
-
        /* Get EQ depth from module parameter, fake the default for now */
        phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
        phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
 
+       /* Get CQ depth from module parameter, fake the default for now */
+       phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
+       phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
+
+       return 0;
+out_error:
+       return -ENOMEM;
+}
+
+/**
+ * lpfc_sli4_queue_create - Create all the SLI4 queues
+ * @phba: pointer to lpfc hba data structure.
+ *
+ * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
+ * operation. For each SLI4 queue type, the parameters such as queue entry
+ * count (queue depth) shall be taken from the module parameter. For now,
+ * we just use some constant number as place holder.
+ *
+ * Return codes
+ *      0 - sucessful
+ *      -ENOMEM - No availble memory
+ *      -EIO - The mailbox failed to complete successfully.
+ **/
+int
+lpfc_sli4_queue_create(struct lpfc_hba *phba)
+{
+       struct lpfc_queue *qdesc;
+       int fcp_eqidx, fcp_cqidx, fcp_wqidx;
+
+       /*
+        * Create Event Queues (EQs)
+        */
+
        /* Create slow path event queue */
        qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
                                      phba->sli4_hba.eq_ecount);
@@ -6247,14 +6293,20 @@ lpfc_sli4_queue_create(struct lpfc_hba *phba)
        }
        phba->sli4_hba.sp_eq = qdesc;
 
-       /* Create fast-path FCP Event Queue(s) */
-       phba->sli4_hba.fp_eq = kzalloc((sizeof(struct lpfc_queue *) *
-                              phba->cfg_fcp_eq_count), GFP_KERNEL);
-       if (!phba->sli4_hba.fp_eq) {
-               lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
-                               "2576 Failed allocate memory for fast-path "
-                               "EQ record array\n");
-               goto out_free_sp_eq;
+       /*
+        * Create fast-path FCP Event Queue(s).  The cfg_fcp_eq_count can be
+        * zero whenever there is exactly one interrupt vector.  This is not
+        * an error.
+        */
+       if (phba->cfg_fcp_eq_count) {
+               phba->sli4_hba.fp_eq = kzalloc((sizeof(struct lpfc_queue *) *
+                                      phba->cfg_fcp_eq_count), GFP_KERNEL);
+               if (!phba->sli4_hba.fp_eq) {
+                       lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
+                                       "2576 Failed allocate memory for "
+                                       "fast-path EQ record array\n");
+                       goto out_free_sp_eq;
+               }
        }
        for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
                qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
@@ -6271,10 +6323,6 @@ lpfc_sli4_queue_create(struct lpfc_hba *phba)
         * Create Complete Queues (CQs)
         */
 
-       /* Get CQ depth from module parameter, fake the default for now */
-       phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
-       phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
-
        /* Create slow-path Mailbox Command Complete Queue */
        qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
                                      phba->sli4_hba.cq_ecount);
@@ -6296,16 +6344,25 @@ lpfc_sli4_queue_create(struct lpfc_hba *phba)
        phba->sli4_hba.els_cq = qdesc;
 
 
-       /* Create fast-path FCP Completion Queue(s), one-to-one with EQs */
-       phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) *
-                               phba->cfg_fcp_eq_count), GFP_KERNEL);
+       /*
+        * Create fast-path FCP Completion Queue(s), one-to-one with FCP EQs.
+        * If there are no FCP EQs then create exactly one FCP CQ.
+        */
+       if (phba->cfg_fcp_eq_count)
+               phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) *
+                                                phba->cfg_fcp_eq_count),
+                                               GFP_KERNEL);
+       else
+               phba->sli4_hba.fcp_cq = kzalloc(sizeof(struct lpfc_queue *),
+                                               GFP_KERNEL);
        if (!phba->sli4_hba.fcp_cq) {
                lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
                                "2577 Failed allocate memory for fast-path "
                                "CQ record array\n");
                goto out_free_els_cq;
        }
-       for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_eq_count; fcp_cqidx++) {
+       fcp_cqidx = 0;
+       do {
                qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
                                              phba->sli4_hba.cq_ecount);
                if (!qdesc) {
@@ -6315,7 +6372,7 @@ lpfc_sli4_queue_create(struct lpfc_hba *phba)
                        goto out_free_fcp_cq;
                }
                phba->sli4_hba.fcp_cq[fcp_cqidx] = qdesc;
-       }
+       } while (++fcp_cqidx < phba->cfg_fcp_eq_count);
 
        /* Create Mailbox Command Queue */
        phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
@@ -6447,7 +6504,7 @@ out_error:
  *      -ENOMEM - No available memory
  *      -EIO - The mailbox failed to complete successfully.
  **/
-static void
+void
 lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
 {
        int fcp_qidx;
@@ -6723,6 +6780,10 @@ lpfc_sli4_queue_setup(struct lpfc_hba *phba)
                                "0540 Receive Queue not allocated\n");
                goto out_destroy_fcp_wq;
        }
+
+       lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ);
+       lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ);
+
        rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
                            phba->sli4_hba.els_cq, LPFC_USOL);
        if (rc) {
@@ -6731,6 +6792,7 @@ lpfc_sli4_queue_setup(struct lpfc_hba *phba)
                                "rc = 0x%x\n", rc);
                goto out_destroy_fcp_wq;
        }
+
        lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
                        "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
                        "parent cq-id=%d\n",
@@ -6790,8 +6852,10 @@ lpfc_sli4_queue_unset(struct lpfc_hba *phba)
        /* Unset ELS complete queue */
        lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
        /* Unset FCP response complete queue */
-       for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
+       fcp_qidx = 0;
+       do {
                lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]);
+       } while (++fcp_qidx < phba->cfg_fcp_eq_count);
        /* Unset fast-path event queue */
        for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
                lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_qidx]);
@@ -7040,10 +7104,11 @@ lpfc_pci_function_reset(struct lpfc_hba *phba)
                         * the loop again.
                         */
                        for (rdy_chk = 0; rdy_chk < 1000; rdy_chk++) {
+                               msleep(10);
                                if (lpfc_readl(phba->sli4_hba.u.if_type2.
                                              STATUSregaddr, &reg_data.word0)) {
                                        rc = -ENODEV;
-                                       break;
+                                       goto out;
                                }
                                if (bf_get(lpfc_sliport_status_rdy, &reg_data))
                                        break;
@@ -7051,7 +7116,6 @@ lpfc_pci_function_reset(struct lpfc_hba *phba)
                                        reset_again++;
                                        break;
                                }
-                               msleep(10);
                        }
 
                        /*
@@ -7065,11 +7129,6 @@ lpfc_pci_function_reset(struct lpfc_hba *phba)
                        }
 
                        /* Detect any port errors. */
-                       if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
-                                &reg_data.word0)) {
-                               rc = -ENODEV;
-                               break;
-                       }
                        if ((bf_get(lpfc_sliport_status_err, &reg_data)) ||
                            (rdy_chk >= 1000)) {
                                phba->work_status[0] = readl(
@@ -7102,6 +7161,7 @@ lpfc_pci_function_reset(struct lpfc_hba *phba)
                break;
        }
 
+out:
        /* Catch the not-ready port failure after a port reset. */
        if (num_resets >= MAX_IF_TYPE_2_RESETS)
                rc = -ENODEV;
@@ -7149,12 +7209,13 @@ lpfc_sli4_send_nop_mbox_cmds(struct lpfc_hba *phba, uint32_t cnt)
        lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
                         LPFC_MBOX_OPCODE_NOP, length, LPFC_SLI4_MBX_EMBED);
 
-       mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
        for (cmdsent = 0; cmdsent < cnt; cmdsent++) {
                if (!phba->sli4_hba.intr_enable)
                        rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
-               else
+               else {
+                       mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
                        rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
+               }
                if (rc == MBX_TIMEOUT)
                        break;
                /* Check return status */
@@ -7974,6 +8035,7 @@ lpfc_sli4_unset_hba(struct lpfc_hba *phba)
 
        /* Reset SLI4 HBA FCoE function */
        lpfc_pci_function_reset(phba);
+       lpfc_sli4_queue_destroy(phba);
 
        return;
 }
@@ -8087,6 +8149,7 @@ lpfc_sli4_hba_unset(struct lpfc_hba *phba)
 
        /* Reset SLI4 HBA FCoE function */
        lpfc_pci_function_reset(phba);
+       lpfc_sli4_queue_destroy(phba);
 
        /* Stop the SLI4 device port */
        phba->pport->work_port_events = 0;
@@ -8120,7 +8183,7 @@ lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
        if (!phba->sli4_hba.intr_enable)
                rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
        else {
-               mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_PORT_CAPABILITIES);
+               mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
                rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
        }
 
@@ -8182,6 +8245,7 @@ lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
        int rc;
        struct lpfc_mqe *mqe = &mboxq->u.mqe;
        struct lpfc_pc_sli4_params *sli4_params;
+       uint32_t mbox_tmo;
        int length;
        struct lpfc_sli4_parameters *mbx_sli4_parameters;
 
@@ -8200,9 +8264,10 @@ lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
                         length, LPFC_SLI4_MBX_EMBED);
        if (!phba->sli4_hba.intr_enable)
                rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
-       else
-               rc = lpfc_sli_issue_mbox_wait(phba, mboxq,
-                       lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG));
+       else {
+               mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
+               rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
+       }
        if (unlikely(rc))
                return rc;
        sli4_params = &phba->sli4_hba.pc_sli4_params;
@@ -8271,11 +8336,8 @@ lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
 
        /* Perform generic PCI device enabling operation */
        error = lpfc_enable_pci_dev(phba);
-       if (error) {
-               lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
-                               "1401 Failed to enable pci device.\n");
+       if (error)
                goto out_free_phba;
-       }
 
        /* Set up SLI API function jump table for PCI-device group-0 HBAs */
        error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
@@ -8322,6 +8384,9 @@ lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
                goto out_free_iocb_list;
        }
 
+       /* Get the default values for Model Name and Description */
+       lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
+
        /* Create SCSI host to the physical port */
        error = lpfc_create_shost(phba);
        if (error) {
@@ -8885,16 +8950,17 @@ lpfc_write_firmware(struct lpfc_hba *phba, const struct firmware *fw)
        uint32_t offset = 0, temp_offset = 0;
 
        INIT_LIST_HEAD(&dma_buffer_list);
-       if ((image->magic_number != LPFC_GROUP_OJECT_MAGIC_NUM) ||
-           (bf_get(lpfc_grp_hdr_file_type, image) != LPFC_FILE_TYPE_GROUP) ||
-           (bf_get(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) ||
-           (image->size != fw->size)) {
+       if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) ||
+           (bf_get_be32(lpfc_grp_hdr_file_type, image) !=
+            LPFC_FILE_TYPE_GROUP) ||
+           (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) ||
+           (be32_to_cpu(image->size) != fw->size)) {
                lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
                                "3022 Invalid FW image found. "
-                               "Magic:%d Type:%x ID:%x\n",
-                               image->magic_number,
-                               bf_get(lpfc_grp_hdr_file_type, image),
-                               bf_get(lpfc_grp_hdr_id, image));
+                               "Magic:%x Type:%x ID:%x\n",
+                               be32_to_cpu(image->magic_number),
+                               bf_get_be32(lpfc_grp_hdr_file_type, image),
+                               bf_get_be32(lpfc_grp_hdr_id, image));
                return -EINVAL;
        }
        lpfc_decode_firmware_rev(phba, fwrev, 1);
@@ -8924,11 +8990,11 @@ lpfc_write_firmware(struct lpfc_hba *phba, const struct firmware *fw)
                while (offset < fw->size) {
                        temp_offset = offset;
                        list_for_each_entry(dmabuf, &dma_buffer_list, list) {
-                               if (offset + SLI4_PAGE_SIZE > fw->size) {
-                                       temp_offset += fw->size - offset;
+                               if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
                                        memcpy(dmabuf->virt,
                                               fw->data + temp_offset,
-                                              fw->size - offset);
+                                              fw->size - temp_offset);
+                                       temp_offset = fw->size;
                                        break;
                                }
                                memcpy(dmabuf->virt, fw->data + temp_offset,
@@ -8984,7 +9050,6 @@ lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
        uint32_t cfg_mode, intr_mode;
        int mcnt;
        int adjusted_fcp_eq_count;
-       int fcp_qidx;
        const struct firmware *fw;
        uint8_t file_name[16];
 
@@ -8995,11 +9060,8 @@ lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
 
        /* Perform generic PCI device enabling operation */
        error = lpfc_enable_pci_dev(phba);
-       if (error) {
-               lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
-                               "1409 Failed to enable pci device.\n");
+       if (error)
                goto out_free_phba;
-       }
 
        /* Set up SLI API function jump table for PCI-device group-1 HBAs */
        error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
@@ -9054,6 +9116,9 @@ lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
                goto out_free_iocb_list;
        }
 
+       /* Get the default values for Model Name and Description */
+       lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
+
        /* Create SCSI host to the physical port */
        error = lpfc_create_shost(phba);
        if (error) {
@@ -9093,16 +9158,6 @@ lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
                        adjusted_fcp_eq_count = phba->sli4_hba.msix_vec_nr - 1;
                else
                        adjusted_fcp_eq_count = phba->cfg_fcp_eq_count;
-               /* Free unused EQs */
-               for (fcp_qidx = adjusted_fcp_eq_count;
-                    fcp_qidx < phba->cfg_fcp_eq_count;
-                    fcp_qidx++) {
-                       lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_qidx]);
-                       /* do not delete the first fcp_cq */
-                       if (fcp_qidx)
-                               lpfc_sli4_queue_free(
-                                       phba->sli4_hba.fcp_cq[fcp_qidx]);
-               }
                phba->cfg_fcp_eq_count = adjusted_fcp_eq_count;
                /* Set up SLI-4 HBA */
                if (lpfc_sli4_hba_setup(phba)) {
@@ -9285,6 +9340,7 @@ lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
 
        /* Disable interrupt from device */
        lpfc_sli4_disable_intr(phba);
+       lpfc_sli4_queue_destroy(phba);
 
        /* Save device state to PCI config space */
        pci_save_state(pdev);
@@ -9414,6 +9470,7 @@ lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
 
        /* Disable interrupt and pci device */
        lpfc_sli4_disable_intr(phba);
+       lpfc_sli4_queue_destroy(phba);
        pci_disable_device(phba->pcidev);
 
        /* Flush all driver's outstanding SCSI I/Os as we are to reset */
index e3b790e5915624794284b5c2e420caee58fe6114..baf53e6c2bd15bfbbf8c25af5face63f1c9fe006 100644 (file)
@@ -36,6 +36,7 @@
 #define LOG_SECURITY   0x00008000      /* Security events */
 #define LOG_EVENT      0x00010000      /* CT,TEMP,DUMP, logging */
 #define LOG_FIP                0x00020000      /* FIP events */
+#define LOG_FCP_UNDER  0x00040000      /* FCP underruns errors */
 #define LOG_ALL_MSG    0xffffffff      /* LOG all messages */
 
 #define lpfc_printf_vlog(vport, level, mask, fmt, arg...) \
index 83450cc5c4d3d0f722e214e4d09398501d491207..2ebc7d2540c0ea0183c5cb4be8e49725e23f4439 100644 (file)
@@ -1598,9 +1598,12 @@ lpfc_mbox_dev_check(struct lpfc_hba *phba)
  *    Timeout value to be used for the given mailbox command
  **/
 int
-lpfc_mbox_tmo_val(struct lpfc_hba *phba, int cmd)
+lpfc_mbox_tmo_val(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
 {
-       switch (cmd) {
+       MAILBOX_t *mbox = &mboxq->u.mb;
+       uint8_t subsys, opcode;
+
+       switch (mbox->mbxCommand) {
        case MBX_WRITE_NV:      /* 0x03 */
        case MBX_UPDATE_CFG:    /* 0x1B */
        case MBX_DOWN_LOAD:     /* 0x1C */
@@ -1610,6 +1613,28 @@ lpfc_mbox_tmo_val(struct lpfc_hba *phba, int cmd)
        case MBX_LOAD_EXP_ROM:  /* 0x9C */
                return LPFC_MBOX_TMO_FLASH_CMD;
        case MBX_SLI4_CONFIG:   /* 0x9b */
+               subsys = lpfc_sli_config_mbox_subsys_get(phba, mboxq);
+               opcode = lpfc_sli_config_mbox_opcode_get(phba, mboxq);
+               if (subsys == LPFC_MBOX_SUBSYSTEM_COMMON) {
+                       switch (opcode) {
+                       case LPFC_MBOX_OPCODE_READ_OBJECT:
+                       case LPFC_MBOX_OPCODE_WRITE_OBJECT:
+                       case LPFC_MBOX_OPCODE_READ_OBJECT_LIST:
+                       case LPFC_MBOX_OPCODE_DELETE_OBJECT:
+                       case LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG:
+                       case LPFC_MBOX_OPCODE_GET_PROFILE_LIST:
+                       case LPFC_MBOX_OPCODE_SET_ACT_PROFILE:
+                       case LPFC_MBOX_OPCODE_SET_PROFILE_CONFIG:
+                       case LPFC_MBOX_OPCODE_GET_FACTORY_PROFILE_CONFIG:
+                               return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO;
+                       }
+               }
+               if (subsys == LPFC_MBOX_SUBSYSTEM_FCOE) {
+                       switch (opcode) {
+                       case LPFC_MBOX_OPCODE_FCOE_SET_FCLINK_SETTINGS:
+                               return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO;
+                       }
+               }
                return LPFC_MBOX_SLI4_CONFIG_TMO;
        }
        return LPFC_MBOX_TMO;
@@ -1859,7 +1884,7 @@ lpfc_sli4_mbox_rsrc_extent(struct lpfc_hba *phba, struct lpfcMboxq *mbox,
        }
 
        /* Complete the initialization for the particular Opcode. */
-       opcode = lpfc_sli4_mbox_opcode_get(phba, mbox);
+       opcode = lpfc_sli_config_mbox_opcode_get(phba, mbox);
        switch (opcode) {
        case LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT:
                if (emb == LPFC_SLI4_MBX_EMBED)
@@ -1886,23 +1911,56 @@ lpfc_sli4_mbox_rsrc_extent(struct lpfc_hba *phba, struct lpfcMboxq *mbox,
 }
 
 /**
- * lpfc_sli4_mbox_opcode_get - Get the opcode from a sli4 mailbox command
+ * lpfc_sli_config_mbox_subsys_get - Get subsystem from a sli_config mbox cmd
  * @phba: pointer to lpfc hba data structure.
- * @mbox: pointer to lpfc mbox command.
+ * @mbox: pointer to lpfc mbox command queue entry.
+ *
+ * This routine gets the subsystem from a SLI4 specific SLI_CONFIG mailbox
+ * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if the
+ * sub-header is not present, subsystem LPFC_MBOX_SUBSYSTEM_NA (0x0) shall
+ * be returned.
+ **/
+uint8_t
+lpfc_sli_config_mbox_subsys_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
+{
+       struct lpfc_mbx_sli4_config *sli4_cfg;
+       union lpfc_sli4_cfg_shdr *cfg_shdr;
+
+       if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG)
+               return LPFC_MBOX_SUBSYSTEM_NA;
+       sli4_cfg = &mbox->u.mqe.un.sli4_config;
+
+       /* For embedded mbox command, get opcode from embedded sub-header*/
+       if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
+               cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
+               return bf_get(lpfc_mbox_hdr_subsystem, &cfg_shdr->request);
+       }
+
+       /* For non-embedded mbox command, get opcode from first dma page */
+       if (unlikely(!mbox->sge_array))
+               return LPFC_MBOX_SUBSYSTEM_NA;
+       cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0];
+       return bf_get(lpfc_mbox_hdr_subsystem, &cfg_shdr->request);
+}
+
+/**
+ * lpfc_sli_config_mbox_opcode_get - Get opcode from a sli_config mbox cmd
+ * @phba: pointer to lpfc hba data structure.
+ * @mbox: pointer to lpfc mbox command queue entry.
  *
- * This routine gets the opcode from a SLI4 specific mailbox command for
- * sending IOCTL command. If the mailbox command is not MBX_SLI4_CONFIG
- * (0x9B) or if the IOCTL sub-header is not present, opcode 0x0 shall be
+ * This routine gets the opcode from a SLI4 specific SLI_CONFIG mailbox
+ * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if
+ * the sub-header is not present, opcode LPFC_MBOX_OPCODE_NA (0x0) be
  * returned.
  **/
 uint8_t
-lpfc_sli4_mbox_opcode_get(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
+lpfc_sli_config_mbox_opcode_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
 {
        struct lpfc_mbx_sli4_config *sli4_cfg;
        union lpfc_sli4_cfg_shdr *cfg_shdr;
 
        if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG)
-               return 0;
+               return LPFC_MBOX_OPCODE_NA;
        sli4_cfg = &mbox->u.mqe.un.sli4_config;
 
        /* For embedded mbox command, get opcode from embedded sub-header*/
@@ -1913,7 +1971,7 @@ lpfc_sli4_mbox_opcode_get(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
 
        /* For non-embedded mbox command, get opcode from first dma page */
        if (unlikely(!mbox->sge_array))
-               return 0;
+               return LPFC_MBOX_OPCODE_NA;
        cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0];
        return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
 }
index eadd241eeff113cffc7a893412c43662ba695828..5b8790b3cf4bba7a2791da9acdd68ed8f7c7cbaa 100644 (file)
@@ -58,6 +58,13 @@ static char *dif_op_str[] = {
        "SCSI_PROT_READ_PASS",
        "SCSI_PROT_WRITE_PASS",
 };
+
+struct scsi_dif_tuple {
+       __be16 guard_tag;       /* Checksum */
+       __be16 app_tag;         /* Opaque storage */
+       __be32 ref_tag;         /* Target LBA or indirect LBA */
+};
+
 static void
 lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb);
 static void
@@ -1263,6 +1270,174 @@ lpfc_scsi_prep_dma_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
        return 0;
 }
 
+static inline unsigned
+lpfc_cmd_blksize(struct scsi_cmnd *sc)
+{
+       return sc->device->sector_size;
+}
+
+#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
+/*
+ * Given a scsi cmnd, determine the BlockGuard tags to be used with it
+ * @sc: The SCSI command to examine
+ * @reftag: (out) BlockGuard reference tag for transmitted data
+ * @apptag: (out) BlockGuard application tag for transmitted data
+ * @new_guard (in) Value to replace CRC with if needed
+ *
+ * Returns (1) if error injection was performed, (0) otherwise
+ */
+static int
+lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc,
+               uint32_t *reftag, uint16_t *apptag, uint32_t new_guard)
+{
+       struct scatterlist *sgpe; /* s/g prot entry */
+       struct scatterlist *sgde; /* s/g data entry */
+       struct scsi_dif_tuple *src;
+       uint32_t op = scsi_get_prot_op(sc);
+       uint32_t blksize;
+       uint32_t numblks;
+       sector_t lba;
+       int rc = 0;
+
+       if (op == SCSI_PROT_NORMAL)
+               return 0;
+
+       lba = scsi_get_lba(sc);
+       if (phba->lpfc_injerr_lba != LPFC_INJERR_LBA_OFF) {
+               blksize = lpfc_cmd_blksize(sc);
+               numblks = (scsi_bufflen(sc) + blksize - 1) / blksize;
+
+               /* Make sure we have the right LBA if one is specified */
+               if ((phba->lpfc_injerr_lba < lba) ||
+                       (phba->lpfc_injerr_lba >= (lba + numblks)))
+                       return 0;
+       }
+
+       sgpe = scsi_prot_sglist(sc);
+       sgde = scsi_sglist(sc);
+
+       /* Should we change the Reference Tag */
+       if (reftag) {
+               /*
+                * If we are SCSI_PROT_WRITE_STRIP, the protection data is
+                * being stripped from the wire, thus it doesn't matter.
+                */
+               if ((op == SCSI_PROT_WRITE_PASS) ||
+                       (op == SCSI_PROT_WRITE_INSERT)) {
+                       if (phba->lpfc_injerr_wref_cnt) {
+
+                               /* DEADBEEF will be the reftag on the wire */
+                               *reftag = 0xDEADBEEF;
+                               phba->lpfc_injerr_wref_cnt--;
+                               phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
+                               rc = 1;
+
+                               lpfc_printf_log(phba, KERN_ERR, LOG_BG,
+                                       "9081 BLKGRD: Injecting reftag error: "
+                                       "write lba x%lx\n", (unsigned long)lba);
+                       }
+               } else {
+                       if (phba->lpfc_injerr_rref_cnt) {
+                               *reftag = 0xDEADBEEF;
+                               phba->lpfc_injerr_rref_cnt--;
+                               phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
+                               rc = 1;
+
+                               lpfc_printf_log(phba, KERN_ERR, LOG_BG,
+                                       "9076 BLKGRD: Injecting reftag error: "
+                                       "read lba x%lx\n", (unsigned long)lba);
+                       }
+               }
+       }
+
+       /* Should we change the Application Tag */
+       if (apptag) {
+               /*
+                * If we are SCSI_PROT_WRITE_STRIP, the protection data is
+                * being stripped from the wire, thus it doesn't matter.
+                */
+               if ((op == SCSI_PROT_WRITE_PASS) ||
+                       (op == SCSI_PROT_WRITE_INSERT)) {
+                       if (phba->lpfc_injerr_wapp_cnt) {
+
+                               /* DEAD will be the apptag on the wire */
+                               *apptag = 0xDEAD;
+                               phba->lpfc_injerr_wapp_cnt--;
+                               phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
+                               rc = 1;
+
+                               lpfc_printf_log(phba, KERN_ERR, LOG_BG,
+                                       "9077 BLKGRD: Injecting apptag error: "
+                                       "write lba x%lx\n", (unsigned long)lba);
+                       }
+               } else {
+                       if (phba->lpfc_injerr_rapp_cnt) {
+                               *apptag = 0xDEAD;
+                               phba->lpfc_injerr_rapp_cnt--;
+                               phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
+                               rc = 1;
+
+                               lpfc_printf_log(phba, KERN_ERR, LOG_BG,
+                                       "9078 BLKGRD: Injecting apptag error: "
+                                       "read lba x%lx\n", (unsigned long)lba);
+                       }
+               }
+       }
+
+       /* Should we change the Guard Tag */
+
+       /*
+        * If we are SCSI_PROT_WRITE_INSERT, the protection data is
+        * being on the wire is being fully generated on the HBA.
+        * The host cannot change it or force an error.
+        */
+       if (((op == SCSI_PROT_WRITE_STRIP) ||
+               (op == SCSI_PROT_WRITE_PASS)) &&
+               phba->lpfc_injerr_wgrd_cnt) {
+               if (sgpe) {
+                       src = (struct scsi_dif_tuple *)sg_virt(sgpe);
+                       /*
+                        * Just inject an error in the first
+                        * prot block.
+                        */
+                       lpfc_printf_log(phba, KERN_ERR, LOG_BG,
+                               "9079 BLKGRD: Injecting guard error: "
+                               "write lba x%lx oldGuard x%x refTag x%x\n",
+                               (unsigned long)lba, src->guard_tag,
+                               src->ref_tag);
+
+                       src->guard_tag = (uint16_t)new_guard;
+                       phba->lpfc_injerr_wgrd_cnt--;
+                       phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
+                       rc = 1;
+
+               } else {
+                       blksize = lpfc_cmd_blksize(sc);
+                       /*
+                        * Jump past the first data block
+                        * and inject an error in the
+                        * prot data. The prot data is already
+                        * embedded after the regular data.
+                        */
+                       src = (struct scsi_dif_tuple *)
+                                       (sg_virt(sgde) + blksize);
+
+                       lpfc_printf_log(phba, KERN_ERR, LOG_BG,
+                               "9080 BLKGRD: Injecting guard error: "
+                               "write lba x%lx oldGuard x%x refTag x%x\n",
+                               (unsigned long)lba, src->guard_tag,
+                               src->ref_tag);
+
+                       src->guard_tag = (uint16_t)new_guard;
+                       phba->lpfc_injerr_wgrd_cnt--;
+                       phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
+                       rc = 1;
+               }
+       }
+       return rc;
+}
+#endif
+
 /*
  * Given a scsi cmnd, determine the BlockGuard opcodes to be used with it
  * @sc: The SCSI command to examine
@@ -1341,18 +1516,6 @@ lpfc_sc_to_bg_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc,
        return ret;
 }
 
-struct scsi_dif_tuple {
-       __be16 guard_tag;       /* Checksum */
-       __be16 app_tag;         /* Opaque storage */
-       __be32 ref_tag;         /* Target LBA or indirect LBA */
-};
-
-static inline unsigned
-lpfc_cmd_blksize(struct scsi_cmnd *sc)
-{
-       return sc->device->sector_size;
-}
-
 /*
  * This function sets up buffer list for protection groups of
  * type LPFC_PG_TYPE_NO_DIF
@@ -1401,6 +1564,11 @@ lpfc_bg_setup_bpl(struct lpfc_hba *phba, struct scsi_cmnd *sc,
        blksize = lpfc_cmd_blksize(sc);
        reftag = scsi_get_lba(sc) & 0xffffffff;
 
+#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
+       /* reftag is the only error we can inject here */
+       lpfc_bg_err_inject(phba, sc, &reftag, 0, 0);
+#endif
+
        /* setup PDE5 with what we have */
        pde5 = (struct lpfc_pde5 *) bpl;
        memset(pde5, 0, sizeof(struct lpfc_pde5));
@@ -1532,6 +1700,11 @@ lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc,
        blksize = lpfc_cmd_blksize(sc);
        reftag = scsi_get_lba(sc) & 0xffffffff;
 
+#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
+       /* reftag / guard tag are the only errors we can inject here */
+       lpfc_bg_err_inject(phba, sc, &reftag, 0, 0xDEAD);
+#endif
+
        split_offset = 0;
        do {
                /* setup PDE5 with what we have */
@@ -1671,7 +1844,6 @@ lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc,
                }
 
        } while (!alldone);
-
 out:
 
        return num_bde;
@@ -2075,6 +2247,7 @@ lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
                        else
                                bf_set(lpfc_sli4_sge_last, sgl, 0);
                        bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
+                       bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA);
                        sgl->word2 = cpu_to_le32(sgl->word2);
                        sgl->sge_len = cpu_to_le32(dma_len);
                        dma_offset += dma_len;
@@ -2325,8 +2498,9 @@ lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
        }
        lp = (uint32_t *)cmnd->sense_buffer;
 
-       if (!scsi_status && (resp_info & RESID_UNDER))
-               logit = LOG_FCP;
+       if (!scsi_status && (resp_info & RESID_UNDER) &&
+               vport->cfg_log_verbose & LOG_FCP_UNDER)
+               logit = LOG_FCP_UNDER;
 
        lpfc_printf_vlog(vport, KERN_WARNING, logit,
                         "9024 FCP command x%x failed: x%x SNS x%x x%x "
@@ -2342,7 +2516,7 @@ lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
        if (resp_info & RESID_UNDER) {
                scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId));
 
-               lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
+               lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_UNDER,
                                 "9025 FCP Read Underrun, expected %d, "
                                 "residual %d Data: x%x x%x x%x\n",
                                 be32_to_cpu(fcpcmd->fcpDl),
@@ -2449,6 +2623,7 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
        struct lpfc_fast_path_event *fast_path_evt;
        struct Scsi_Host *shost;
        uint32_t queue_depth, scsi_id;
+       uint32_t logit = LOG_FCP;
 
        /* Sanity check on return of outstanding command */
        if (!(lpfc_cmd->pCmd))
@@ -2470,16 +2645,22 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
                        lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
                else if (lpfc_cmd->status >= IOSTAT_CNT)
                        lpfc_cmd->status = IOSTAT_DEFAULT;
-
-               lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
-                                "9030 FCP cmd x%x failed <%d/%d> "
-                                "status: x%x result: x%x Data: x%x x%x\n",
-                                cmd->cmnd[0],
-                                cmd->device ? cmd->device->id : 0xffff,
-                                cmd->device ? cmd->device->lun : 0xffff,
-                                lpfc_cmd->status, lpfc_cmd->result,
-                                pIocbOut->iocb.ulpContext,
-                                lpfc_cmd->cur_iocbq.iocb.ulpIoTag);
+               if (lpfc_cmd->status == IOSTAT_FCP_RSP_ERROR
+                       && !lpfc_cmd->fcp_rsp->rspStatus3
+                       && (lpfc_cmd->fcp_rsp->rspStatus2 & RESID_UNDER)
+                       && !(phba->cfg_log_verbose & LOG_FCP_UNDER))
+                       logit = 0;
+               else
+                       logit = LOG_FCP | LOG_FCP_UNDER;
+               lpfc_printf_vlog(vport, KERN_WARNING, logit,
+                        "9030 FCP cmd x%x failed <%d/%d> "
+                        "status: x%x result: x%x Data: x%x x%x\n",
+                        cmd->cmnd[0],
+                        cmd->device ? cmd->device->id : 0xffff,
+                        cmd->device ? cmd->device->lun : 0xffff,
+                        lpfc_cmd->status, lpfc_cmd->result,
+                        pIocbOut->iocb.ulpContext,
+                        lpfc_cmd->cur_iocbq.iocb.ulpIoTag);
 
                switch (lpfc_cmd->status) {
                case IOSTAT_FCP_RSP_ERROR:
@@ -3056,8 +3237,9 @@ lpfc_queuecommand_lck(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
        }
        ndlp = rdata->pnode;
 
-       if (!(phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
-               scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) {
+       if ((scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) &&
+               (!(phba->sli3_options & LPFC_SLI3_BG_ENABLED) ||
+               (phba->sli_rev == LPFC_SLI_REV4))) {
 
                lpfc_printf_log(phba, KERN_ERR, LOG_BG,
                                "9058 BLKGRD: ERROR: rcvd protected cmd:%02x"
@@ -3691,9 +3873,9 @@ lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
        fc_host_post_vendor_event(shost, fc_get_event_number(),
                sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
 
-       ret = fc_block_scsi_eh(cmnd);
-       if (ret)
-               return ret;
+       status = fc_block_scsi_eh(cmnd);
+       if (status)
+               return status;
 
        /*
         * Since the driver manages a single bus device, reset all
index 8b799f047a99fd2590a8bdbc1ddc9256887463f7..4d4104f38c9897d6be6414abf3db11c318c68e79 100644 (file)
@@ -379,10 +379,10 @@ lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
        dq->host_index = ((dq->host_index + 1) % dq->entry_count);
 
        /* Ring The Header Receive Queue Doorbell */
-       if (!(hq->host_index % LPFC_RQ_POST_BATCH)) {
+       if (!(hq->host_index % hq->entry_repost)) {
                doorbell.word0 = 0;
                bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
-                      LPFC_RQ_POST_BATCH);
+                      hq->entry_repost);
                bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
                writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
        }
@@ -1864,7 +1864,7 @@ lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
 {
        if (phba->sli_rev == LPFC_SLI_REV4)
                return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
-                                        lpfc_hbq_defs[qno]->entry_count);
+                                       lpfc_hbq_defs[qno]->entry_count);
        else
                return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
                                         lpfc_hbq_defs[qno]->init_count);
@@ -2200,10 +2200,13 @@ lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
                        /* Unknown mailbox command compl */
                        lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
                                        "(%d):0323 Unknown Mailbox command "
-                                       "x%x (x%x) Cmpl\n",
+                                       "x%x (x%x/x%x) Cmpl\n",
                                        pmb->vport ? pmb->vport->vpi : 0,
                                        pmbox->mbxCommand,
-                                       lpfc_sli4_mbox_opcode_get(phba, pmb));
+                                       lpfc_sli_config_mbox_subsys_get(phba,
+                                                                       pmb),
+                                       lpfc_sli_config_mbox_opcode_get(phba,
+                                                                       pmb));
                        phba->link_state = LPFC_HBA_ERROR;
                        phba->work_hs = HS_FFER3;
                        lpfc_handle_eratt(phba);
@@ -2215,17 +2218,19 @@ lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
                        if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
                                /* Mbox cmd cmpl error - RETRYing */
                                lpfc_printf_log(phba, KERN_INFO,
-                                               LOG_MBOX | LOG_SLI,
-                                               "(%d):0305 Mbox cmd cmpl "
-                                               "error - RETRYing Data: x%x "
-                                               "(x%x) x%x x%x x%x\n",
-                                               pmb->vport ? pmb->vport->vpi :0,
-                                               pmbox->mbxCommand,
-                                               lpfc_sli4_mbox_opcode_get(phba,
-                                                                         pmb),
-                                               pmbox->mbxStatus,
-                                               pmbox->un.varWords[0],
-                                               pmb->vport->port_state);
+                                       LOG_MBOX | LOG_SLI,
+                                       "(%d):0305 Mbox cmd cmpl "
+                                       "error - RETRYing Data: x%x "
+                                       "(x%x/x%x) x%x x%x x%x\n",
+                                       pmb->vport ? pmb->vport->vpi : 0,
+                                       pmbox->mbxCommand,
+                                       lpfc_sli_config_mbox_subsys_get(phba,
+                                                                       pmb),
+                                       lpfc_sli_config_mbox_opcode_get(phba,
+                                                                       pmb),
+                                       pmbox->mbxStatus,
+                                       pmbox->un.varWords[0],
+                                       pmb->vport->port_state);
                                pmbox->mbxStatus = 0;
                                pmbox->mbxOwner = OWN_HOST;
                                rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
@@ -2236,11 +2241,12 @@ lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
 
                /* Mailbox cmd <cmd> Cmpl <cmpl> */
                lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
-                               "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
+                               "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p "
                                "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
                                pmb->vport ? pmb->vport->vpi : 0,
                                pmbox->mbxCommand,
-                               lpfc_sli4_mbox_opcode_get(phba, pmb),
+                               lpfc_sli_config_mbox_subsys_get(phba, pmb),
+                               lpfc_sli_config_mbox_opcode_get(phba, pmb),
                                pmb->mbox_cmpl,
                                *((uint32_t *) pmbox),
                                pmbox->un.varWords[0],
@@ -4685,6 +4691,175 @@ lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
        return 0;
 }
 
+/**
+ * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
+ * @phba: pointer to lpfc hba data structure.
+ *
+ * This routine retrieves SLI4 device physical port name this PCI function
+ * is attached to.
+ *
+ * Return codes
+ *      0 - sucessful
+ *      otherwise - failed to retrieve physical port name
+ **/
+static int
+lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba)
+{
+       LPFC_MBOXQ_t *mboxq;
+       struct lpfc_mbx_read_config *rd_config;
+       struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr;
+       struct lpfc_controller_attribute *cntl_attr;
+       struct lpfc_mbx_get_port_name *get_port_name;
+       void *virtaddr = NULL;
+       uint32_t alloclen, reqlen;
+       uint32_t shdr_status, shdr_add_status;
+       union lpfc_sli4_cfg_shdr *shdr;
+       char cport_name = 0;
+       int rc;
+
+       /* We assume nothing at this point */
+       phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
+       phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON;
+
+       mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
+       if (!mboxq)
+               return -ENOMEM;
+
+       /* obtain link type and link number via READ_CONFIG */
+       lpfc_read_config(phba, mboxq);
+       rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
+       if (rc == MBX_SUCCESS) {
+               rd_config = &mboxq->u.mqe.un.rd_config;
+               if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
+                       phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
+                       phba->sli4_hba.lnk_info.lnk_tp =
+                               bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
+                       phba->sli4_hba.lnk_info.lnk_no =
+                               bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
+                       lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
+                                       "3081 lnk_type:%d, lnk_numb:%d\n",
+                                       phba->sli4_hba.lnk_info.lnk_tp,
+                                       phba->sli4_hba.lnk_info.lnk_no);
+                       goto retrieve_ppname;
+               } else
+                       lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
+                                       "3082 Mailbox (x%x) returned ldv:x0\n",
+                                       bf_get(lpfc_mqe_command,
+                                              &mboxq->u.mqe));
+       } else
+               lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
+                               "3083 Mailbox (x%x) failed, status:x%x\n",
+                               bf_get(lpfc_mqe_command, &mboxq->u.mqe),
+                               bf_get(lpfc_mqe_status, &mboxq->u.mqe));
+
+       /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
+       reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes);
+       alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
+                       LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen,
+                       LPFC_SLI4_MBX_NEMBED);
+       if (alloclen < reqlen) {
+               lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
+                               "3084 Allocated DMA memory size (%d) is "
+                               "less than the requested DMA memory size "
+                               "(%d)\n", alloclen, reqlen);
+               rc = -ENOMEM;
+               goto out_free_mboxq;
+       }
+       rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
+       virtaddr = mboxq->sge_array->addr[0];
+       mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr;
+       shdr = &mbx_cntl_attr->cfg_shdr;
+       shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
+       shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
+       if (shdr_status || shdr_add_status || rc) {
+               lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
+                               "3085 Mailbox x%x (x%x/x%x) failed, "
+                               "rc:x%x, status:x%x, add_status:x%x\n",
+                               bf_get(lpfc_mqe_command, &mboxq->u.mqe),
+                               lpfc_sli_config_mbox_subsys_get(phba, mboxq),
+                               lpfc_sli_config_mbox_opcode_get(phba, mboxq),
+                               rc, shdr_status, shdr_add_status);
+               rc = -ENXIO;
+               goto out_free_mboxq;
+       }
+       cntl_attr = &mbx_cntl_attr->cntl_attr;
+       phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
+       phba->sli4_hba.lnk_info.lnk_tp =
+               bf_get(lpfc_cntl_attr_lnk_type, cntl_attr);
+       phba->sli4_hba.lnk_info.lnk_no =
+               bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr);
+       lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
+                       "3086 lnk_type:%d, lnk_numb:%d\n",
+                       phba->sli4_hba.lnk_info.lnk_tp,
+                       phba->sli4_hba.lnk_info.lnk_no);
+
+retrieve_ppname:
+       lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
+               LPFC_MBOX_OPCODE_GET_PORT_NAME,
+               sizeof(struct lpfc_mbx_get_port_name) -
+               sizeof(struct lpfc_sli4_cfg_mhdr),
+               LPFC_SLI4_MBX_EMBED);
+       get_port_name = &mboxq->u.mqe.un.get_port_name;
+       shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr;
+       bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1);
+       bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request,
+               phba->sli4_hba.lnk_info.lnk_tp);
+       rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
+       shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
+       shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
+       if (shdr_status || shdr_add_status || rc) {
+               lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
+                               "3087 Mailbox x%x (x%x/x%x) failed: "
+                               "rc:x%x, status:x%x, add_status:x%x\n",
+                               bf_get(lpfc_mqe_command, &mboxq->u.mqe),
+                               lpfc_sli_config_mbox_subsys_get(phba, mboxq),
+                               lpfc_sli_config_mbox_opcode_get(phba, mboxq),
+                               rc, shdr_status, shdr_add_status);
+               rc = -ENXIO;
+               goto out_free_mboxq;
+       }
+       switch (phba->sli4_hba.lnk_info.lnk_no) {
+       case LPFC_LINK_NUMBER_0:
+               cport_name = bf_get(lpfc_mbx_get_port_name_name0,
+                               &get_port_name->u.response);
+               phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
+               break;
+       case LPFC_LINK_NUMBER_1:
+               cport_name = bf_get(lpfc_mbx_get_port_name_name1,
+                               &get_port_name->u.response);
+               phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
+               break;
+       case LPFC_LINK_NUMBER_2:
+               cport_name = bf_get(lpfc_mbx_get_port_name_name2,
+                               &get_port_name->u.response);
+               phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
+               break;
+       case LPFC_LINK_NUMBER_3:
+               cport_name = bf_get(lpfc_mbx_get_port_name_name3,
+                               &get_port_name->u.response);
+               phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
+               break;
+       default:
+               break;
+       }
+
+       if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) {
+               phba->Port[0] = cport_name;
+               phba->Port[1] = '\0';
+               lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
+                               "3091 SLI get port name: %s\n", phba->Port);
+       }
+
+out_free_mboxq:
+       if (rc != MBX_TIMEOUT) {
+               if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
+                       lpfc_sli4_mbox_cmd_free(phba, mboxq);
+               else
+                       mempool_free(mboxq, phba->mbox_mem_pool);
+       }
+       return rc;
+}
+
 /**
  * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  * @phba: pointer to lpfc hba data structure.
@@ -4754,7 +4929,7 @@ lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type,
        if (!phba->sli4_hba.intr_enable)
                rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
        else {
-               mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
+               mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
                rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
        }
        if (unlikely(rc)) {
@@ -4911,7 +5086,7 @@ lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t *extnt_cnt,
        if (!phba->sli4_hba.intr_enable)
                rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
        else {
-               mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
+               mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
                rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
        }
 
@@ -5194,7 +5369,7 @@ lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type)
        if (!phba->sli4_hba.intr_enable)
                rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
        else {
-               mbox_tmo = lpfc_mbox_tmo_val(phba, mbox_tmo);
+               mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
                rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
        }
        if (unlikely(rc)) {
@@ -5619,7 +5794,7 @@ lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type,
        if (!phba->sli4_hba.intr_enable)
                rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
        else {
-               mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
+               mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
                rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
        }
 
@@ -5748,6 +5923,17 @@ lpfc_sli4_hba_setup(struct lpfc_hba *phba)
                kfree(vpd);
                goto out_free_mbox;
        }
+
+       /*
+        * Retrieve sli4 device physical port name, failure of doing it
+        * is considered as non-fatal.
+        */
+       rc = lpfc_sli4_retrieve_pport_name(phba);
+       if (!rc)
+               lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
+                               "3080 Successful retrieving SLI4 device "
+                               "physical port name: %s.\n", phba->Port);
+
        /*
         * Evaluate the read rev and vpd data. Populate the driver
         * state with the results. If this routine fails, the failure
@@ -5818,9 +6004,13 @@ lpfc_sli4_hba_setup(struct lpfc_hba *phba)
         * then turn off the global config parameters to disable the
         * feature in the driver.  This is not a fatal error.
         */
-       if ((phba->cfg_enable_bg) &&
-           !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
-               ftr_rsp++;
+       phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
+       if (phba->cfg_enable_bg) {
+               if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))
+                       phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
+               else
+                       ftr_rsp++;
+       }
 
        if (phba->max_vpi && phba->cfg_enable_npiv &&
            !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
@@ -5937,12 +6127,20 @@ lpfc_sli4_hba_setup(struct lpfc_hba *phba)
                goto out_free_mbox;
        }
 
+       /* Create all the SLI4 queues */
+       rc = lpfc_sli4_queue_create(phba);
+       if (rc) {
+               lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
+                               "3089 Failed to allocate queues\n");
+               rc = -ENODEV;
+               goto out_stop_timers;
+       }
        /* Set up all the queues to the device */
        rc = lpfc_sli4_queue_setup(phba);
        if (unlikely(rc)) {
                lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
                                "0381 Error %d during queue setup.\n ", rc);
-               goto out_stop_timers;
+               goto out_destroy_queue;
        }
 
        /* Arm the CQs and then EQs on device */
@@ -6015,15 +6213,20 @@ lpfc_sli4_hba_setup(struct lpfc_hba *phba)
        spin_lock_irq(&phba->hbalock);
        phba->link_state = LPFC_LINK_DOWN;
        spin_unlock_irq(&phba->hbalock);
-       if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK)
+       if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
                rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
+               if (rc)
+                       goto out_unset_queue;
+       }
+       mempool_free(mboxq, phba->mbox_mem_pool);
+       return rc;
 out_unset_queue:
        /* Unset all the queues set up in this routine when error out */
-       if (rc)
-               lpfc_sli4_queue_unset(phba);
+       lpfc_sli4_queue_unset(phba);
+out_destroy_queue:
+       lpfc_sli4_queue_destroy(phba);
 out_stop_timers:
-       if (rc)
-               lpfc_stop_hba_timers(phba);
+       lpfc_stop_hba_timers(phba);
 out_free_mbox:
        mempool_free(mboxq, phba->mbox_mem_pool);
        return rc;
@@ -6318,7 +6521,7 @@ lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
                }
                /* timeout active mbox command */
                mod_timer(&psli->mbox_tmo, (jiffies +
-                              (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
+                              (HZ * lpfc_mbox_tmo_val(phba, pmbox))));
        }
 
        /* Mailbox cmd <cmd> issue */
@@ -6442,9 +6645,8 @@ lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
                                                       drvr_flag);
                        goto out_not_finished;
                }
-               timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
-                                                            mb->mbxCommand) *
-                                          1000) + jiffies;
+               timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
+                                                       1000) + jiffies;
                i = 0;
                /* Wait for command to complete */
                while (((word0 & OWN_CHIP) == OWN_CHIP) ||
@@ -6555,21 +6757,21 @@ static int
 lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
 {
        struct lpfc_sli *psli = &phba->sli;
-       uint8_t actcmd = MBX_HEARTBEAT;
        int rc = 0;
-       unsigned long timeout;
+       unsigned long timeout = 0;
 
        /* Mark the asynchronous mailbox command posting as blocked */
        spin_lock_irq(&phba->hbalock);
        psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
-       if (phba->sli.mbox_active)
-               actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
-       spin_unlock_irq(&phba->hbalock);
        /* Determine how long we might wait for the active mailbox
         * command to be gracefully completed by firmware.
         */
-       timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
-                                  jiffies;
+       if (phba->sli.mbox_active)
+               timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
+                                               phba->sli.mbox_active) *
+                                               1000) + jiffies;
+       spin_unlock_irq(&phba->hbalock);
+
        /* Wait for the outstnading mailbox command to complete */
        while (phba->sli.mbox_active) {
                /* Check active mailbox complete status every 2ms */
@@ -6664,11 +6866,12 @@ lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
        if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
                spin_unlock_irqrestore(&phba->hbalock, iflag);
                lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
-                               "(%d):2532 Mailbox command x%x (x%x) "
+                               "(%d):2532 Mailbox command x%x (x%x/x%x) "
                                "cannot issue Data: x%x x%x\n",
                                mboxq->vport ? mboxq->vport->vpi : 0,
                                mboxq->u.mb.mbxCommand,
-                               lpfc_sli4_mbox_opcode_get(phba, mboxq),
+                               lpfc_sli_config_mbox_subsys_get(phba, mboxq),
+                               lpfc_sli_config_mbox_opcode_get(phba, mboxq),
                                psli->sli_flag, MBX_POLL);
                return MBXERR_ERROR;
        }
@@ -6691,7 +6894,7 @@ lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
        dma_address = &phba->sli4_hba.bmbx.dma_address;
        writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
 
-       timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
+       timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
                                   * 1000) + jiffies;
        do {
                bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
@@ -6707,7 +6910,7 @@ lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
 
        /* Post the low mailbox dma address to the port. */
        writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
-       timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
+       timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
                                   * 1000) + jiffies;
        do {
                bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
@@ -6746,11 +6949,12 @@ lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
                lpfc_sli4_swap_str(phba, mboxq);
 
        lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
-                       "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
+                       "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
                        "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
                        " x%x x%x CQ: x%x x%x x%x x%x\n",
-                       mboxq->vport ? mboxq->vport->vpi : 0,
-                       mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
+                       mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
+                       lpfc_sli_config_mbox_subsys_get(phba, mboxq),
+                       lpfc_sli_config_mbox_opcode_get(phba, mboxq),
                        bf_get(lpfc_mqe_status, mb),
                        mb->un.mb_words[0], mb->un.mb_words[1],
                        mb->un.mb_words[2], mb->un.mb_words[3],
@@ -6796,11 +7000,12 @@ lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
        rc = lpfc_mbox_dev_check(phba);
        if (unlikely(rc)) {
                lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
-                               "(%d):2544 Mailbox command x%x (x%x) "
+                               "(%d):2544 Mailbox command x%x (x%x/x%x) "
                                "cannot issue Data: x%x x%x\n",
                                mboxq->vport ? mboxq->vport->vpi : 0,
                                mboxq->u.mb.mbxCommand,
-                               lpfc_sli4_mbox_opcode_get(phba, mboxq),
+                               lpfc_sli_config_mbox_subsys_get(phba, mboxq),
+                               lpfc_sli_config_mbox_opcode_get(phba, mboxq),
                                psli->sli_flag, flag);
                goto out_not_finished;
        }
@@ -6814,20 +7019,25 @@ lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
                if (rc != MBX_SUCCESS)
                        lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
                                        "(%d):2541 Mailbox command x%x "
-                                       "(x%x) cannot issue Data: x%x x%x\n",
+                                       "(x%x/x%x) cannot issue Data: "
+                                       "x%x x%x\n",
                                        mboxq->vport ? mboxq->vport->vpi : 0,
                                        mboxq->u.mb.mbxCommand,
-                                       lpfc_sli4_mbox_opcode_get(phba, mboxq),
+                                       lpfc_sli_config_mbox_subsys_get(phba,
+                                                                       mboxq),
+                                       lpfc_sli_config_mbox_opcode_get(phba,
+                                                                       mboxq),
                                        psli->sli_flag, flag);
                return rc;
        } else if (flag == MBX_POLL) {
                lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
                                "(%d):2542 Try to issue mailbox command "
-                               "x%x (x%x) synchronously ahead of async"
+                               "x%x (x%x/x%x) synchronously ahead of async"
                                "mailbox command queue: x%x x%x\n",
                                mboxq->vport ? mboxq->vport->vpi : 0,
                                mboxq->u.mb.mbxCommand,
-                               lpfc_sli4_mbox_opcode_get(phba, mboxq),
+                               lpfc_sli_config_mbox_subsys_get(phba, mboxq),
+                               lpfc_sli_config_mbox_opcode_get(phba, mboxq),
                                psli->sli_flag, flag);
                /* Try to block the asynchronous mailbox posting */
                rc = lpfc_sli4_async_mbox_block(phba);
@@ -6836,16 +7046,18 @@ lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
                        rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
                        if (rc != MBX_SUCCESS)
                                lpfc_printf_log(phba, KERN_ERR,
-                                               LOG_MBOX | LOG_SLI,
-                                               "(%d):2597 Mailbox command "
-                                               "x%x (x%x) cannot issue "
-                                               "Data: x%x x%x\n",
-                                               mboxq->vport ?
-                                               mboxq->vport->vpi : 0,
-                                               mboxq->u.mb.mbxCommand,
-                                               lpfc_sli4_mbox_opcode_get(phba,
-                                                               mboxq),
-                                               psli->sli_flag, flag);
+                                       LOG_MBOX | LOG_SLI,
+                                       "(%d):2597 Mailbox command "
+                                       "x%x (x%x/x%x) cannot issue "
+                                       "Data: x%x x%x\n",
+                                       mboxq->vport ?
+                                       mboxq->vport->vpi : 0,
+                                       mboxq->u.mb.mbxCommand,
+                                       lpfc_sli_config_mbox_subsys_get(phba,
+                                                                       mboxq),
+                                       lpfc_sli_config_mbox_opcode_get(phba,
+                                                                       mboxq),
+                                       psli->sli_flag, flag);
                        /* Unblock the async mailbox posting afterward */
                        lpfc_sli4_async_mbox_unblock(phba);
                }
@@ -6856,11 +7068,12 @@ lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
        rc = lpfc_mbox_cmd_check(phba, mboxq);
        if (rc) {
                lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
-                               "(%d):2543 Mailbox command x%x (x%x) "
+                               "(%d):2543 Mailbox command x%x (x%x/x%x) "
                                "cannot issue Data: x%x x%x\n",
                                mboxq->vport ? mboxq->vport->vpi : 0,
                                mboxq->u.mb.mbxCommand,
-                               lpfc_sli4_mbox_opcode_get(phba, mboxq),
+                               lpfc_sli_config_mbox_subsys_get(phba, mboxq),
+                               lpfc_sli_config_mbox_opcode_get(phba, mboxq),
                                psli->sli_flag, flag);
                goto out_not_finished;
        }
@@ -6872,10 +7085,11 @@ lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
        spin_unlock_irqrestore(&phba->hbalock, iflags);
        lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
                        "(%d):0354 Mbox cmd issue - Enqueue Data: "
-                       "x%x (x%x) x%x x%x x%x\n",
+                       "x%x (x%x/x%x) x%x x%x x%x\n",
                        mboxq->vport ? mboxq->vport->vpi : 0xffffff,
                        bf_get(lpfc_mqe_command, &mboxq->u.mqe),
-                       lpfc_sli4_mbox_opcode_get(phba, mboxq),
+                       lpfc_sli_config_mbox_subsys_get(phba, mboxq),
+                       lpfc_sli_config_mbox_opcode_get(phba, mboxq),
                        phba->pport->port_state,
                        psli->sli_flag, MBX_NOWAIT);
        /* Wake up worker thread to transport mailbox command from head */
@@ -6952,13 +7166,14 @@ lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
 
        /* Start timer for the mbox_tmo and log some mailbox post messages */
        mod_timer(&psli->mbox_tmo, (jiffies +
-                 (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
+                 (HZ * lpfc_mbox_tmo_val(phba, mboxq))));
 
        lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
-                       "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
+                       "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
                        "x%x x%x\n",
                        mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
-                       lpfc_sli4_mbox_opcode_get(phba, mboxq),
+                       lpfc_sli_config_mbox_subsys_get(phba, mboxq),
+                       lpfc_sli_config_mbox_opcode_get(phba, mboxq),
                        phba->pport->port_state, psli->sli_flag);
 
        if (mbx_cmnd != MBX_HEARTBEAT) {
@@ -6982,11 +7197,12 @@ lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
        rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
        if (rc != MBX_SUCCESS) {
                lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
-                               "(%d):2533 Mailbox command x%x (x%x) "
+                               "(%d):2533 Mailbox command x%x (x%x/x%x) "
                                "cannot issue Data: x%x x%x\n",
                                mboxq->vport ? mboxq->vport->vpi : 0,
                                mboxq->u.mb.mbxCommand,
-                               lpfc_sli4_mbox_opcode_get(phba, mboxq),
+                               lpfc_sli_config_mbox_subsys_get(phba, mboxq),
+                               lpfc_sli_config_mbox_opcode_get(phba, mboxq),
                                psli->sli_flag, MBX_NOWAIT);
                goto out_not_finished;
        }
@@ -7322,6 +7538,8 @@ lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
                                if (inbound == 1)
                                        offset = 0;
                                bf_set(lpfc_sli4_sge_offset, sgl, offset);
+                               bf_set(lpfc_sli4_sge_type, sgl,
+                                       LPFC_SGE_TYPE_DATA);
                                offset += bde.tus.f.bdeSize;
                        }
                        sgl->word2 = cpu_to_le32(sgl->word2);
@@ -9359,7 +9577,6 @@ lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
 
        /* now issue the command */
        retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
-
        if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
                wait_event_interruptible_timeout(done_q,
                                pmboxq->mbox_flag & LPFC_MBX_WAKE,
@@ -9403,23 +9620,24 @@ void
 lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
 {
        struct lpfc_sli *psli = &phba->sli;
-       uint8_t actcmd = MBX_HEARTBEAT;
        unsigned long timeout;
 
+       timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
        spin_lock_irq(&phba->hbalock);
        psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
        spin_unlock_irq(&phba->hbalock);
 
        if (psli->sli_flag & LPFC_SLI_ACTIVE) {
                spin_lock_irq(&phba->hbalock);
-               if (phba->sli.mbox_active)
-                       actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
-               spin_unlock_irq(&phba->hbalock);
                /* Determine how long we might wait for the active mailbox
                 * command to be gracefully completed by firmware.
                 */
-               timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
-                                          1000) + jiffies;
+               if (phba->sli.mbox_active)
+                       timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
+                                               phba->sli.mbox_active) *
+                                               1000) + jiffies;
+               spin_unlock_irq(&phba->hbalock);
+
                while (phba->sli.mbox_active) {
                        /* Check active mailbox complete status every 2ms */
                        msleep(2);
@@ -10415,12 +10633,17 @@ lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
        /* Move mbox data to caller's mailbox region, do endian swapping */
        if (pmb->mbox_cmpl && mbox)
                lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
-       /* Set the mailbox status with SLI4 range 0x4000 */
-       mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
-       if (mcqe_status != MB_CQE_STATUS_SUCCESS)
-               bf_set(lpfc_mqe_status, mqe,
-                      (LPFC_MBX_ERROR_RANGE | mcqe_status));
 
+       /*
+        * For mcqe errors, conditionally move a modified error code to
+        * the mbox so that the error will not be missed.
+        */
+       mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
+       if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
+               if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS)
+                       bf_set(lpfc_mqe_status, mqe,
+                              (LPFC_MBX_ERROR_RANGE | mcqe_status));
+       }
        if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
                pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
                lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
@@ -10796,7 +11019,7 @@ lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
        case LPFC_MCQ:
                while ((cqe = lpfc_sli4_cq_get(cq))) {
                        workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
-                       if (!(++ecount % LPFC_GET_QE_REL_INT))
+                       if (!(++ecount % cq->entry_repost))
                                lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
                }
                break;
@@ -10808,7 +11031,7 @@ lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
                        else
                                workposted |= lpfc_sli4_sp_handle_cqe(phba, cq,
                                                                      cqe);
-                       if (!(++ecount % LPFC_GET_QE_REL_INT))
+                       if (!(++ecount % cq->entry_repost))
                                lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
                }
                break;
@@ -11040,7 +11263,7 @@ lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
        /* Process all the entries to the CQ */
        while ((cqe = lpfc_sli4_cq_get(cq))) {
                workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
-               if (!(++ecount % LPFC_GET_QE_REL_INT))
+               if (!(++ecount % cq->entry_repost))
                        lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
        }
 
@@ -11110,6 +11333,8 @@ lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
 
        /* Get to the EQ struct associated with this vector */
        speq = phba->sli4_hba.sp_eq;
+       if (unlikely(!speq))
+               return IRQ_NONE;
 
        /* Check device state for handling interrupt */
        if (unlikely(lpfc_intr_state_check(phba))) {
@@ -11127,7 +11352,7 @@ lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
         */
        while ((eqe = lpfc_sli4_eq_get(speq))) {
                lpfc_sli4_sp_handle_eqe(phba, eqe);
-               if (!(++ecount % LPFC_GET_QE_REL_INT))
+               if (!(++ecount % speq->entry_repost))
                        lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
        }
 
@@ -11187,6 +11412,8 @@ lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
 
        if (unlikely(!phba))
                return IRQ_NONE;
+       if (unlikely(!phba->sli4_hba.fp_eq))
+               return IRQ_NONE;
 
        /* Get to the EQ struct associated with this vector */
        fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
@@ -11207,7 +11434,7 @@ lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
         */
        while ((eqe = lpfc_sli4_eq_get(fpeq))) {
                lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
-               if (!(++ecount % LPFC_GET_QE_REL_INT))
+               if (!(++ecount % fpeq->entry_repost))
                        lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
        }
 
@@ -11359,6 +11586,15 @@ lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
        }
        queue->entry_size = entry_size;
        queue->entry_count = entry_count;
+
+       /*
+        * entry_repost is calculated based on the number of entries in the
+        * queue. This works out except for RQs. If buffers are NOT initially
+        * posted for every RQE, entry_repost should be adjusted accordingly.
+        */
+       queue->entry_repost = (entry_count >> 3);
+       if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST)
+               queue->entry_repost = LPFC_QUEUE_MIN_REPOST;
        queue->phba = phba;
 
        return queue;
@@ -11923,6 +12159,31 @@ out:
        return status;
 }
 
+/**
+ * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ
+ * @phba: HBA structure that indicates port to create a queue on.
+ * @rq:   The queue structure to use for the receive queue.
+ * @qno:  The associated HBQ number
+ *
+ *
+ * For SLI4 we need to adjust the RQ repost value based on
+ * the number of buffers that are initially posted to the RQ.
+ */
+void
+lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno)
+{
+       uint32_t cnt;
+
+       cnt = lpfc_hbq_defs[qno]->entry_count;
+
+       /* Recalc repost for RQs based on buffers initially posted */
+       cnt = (cnt >> 3);
+       if (cnt < LPFC_QUEUE_MIN_REPOST)
+               cnt = LPFC_QUEUE_MIN_REPOST;
+
+       rq->entry_repost = cnt;
+}
+
 /**
  * lpfc_rq_create - Create a Receive Queue on the HBA
  * @phba: HBA structure that indicates port to create a queue on.
@@ -12489,7 +12750,7 @@ lpfc_sli4_post_sgl(struct lpfc_hba *phba,
        if (!phba->sli4_hba.intr_enable)
                rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
        else {
-               mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
+               mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
                rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
        }
        /* The IOCTL status is embedded in the mailbox subheader. */
@@ -12704,7 +12965,7 @@ lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba)
        if (!phba->sli4_hba.intr_enable)
                rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
        else {
-               mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
+               mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
                rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
        }
        shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
@@ -12867,7 +13128,7 @@ lpfc_sli4_post_els_sgl_list_ext(struct lpfc_hba *phba)
                if (!phba->sli4_hba.intr_enable)
                        rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
                else {
-                       mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
+                       mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
                        rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
                }
                shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
@@ -12991,7 +13252,7 @@ lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
        if (!phba->sli4_hba.intr_enable)
                rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
        else {
-               mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
+               mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
                rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
        }
        shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
@@ -13147,7 +13408,7 @@ lpfc_sli4_post_scsi_sgl_blk_ext(struct lpfc_hba *phba, struct list_head *sblist,
                if (!phba->sli4_hba.intr_enable)
                        rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
                else {
-                       mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
+                       mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
                        rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
                }
                shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
@@ -13296,7 +13557,8 @@ lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
        uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
                        fc_hdr->fh_d_id[1] << 8 |
                        fc_hdr->fh_d_id[2]);
-
+       if (did == Fabric_DID)
+               return phba->pport;
        vports = lpfc_create_vport_work_array(phba);
        if (vports != NULL)
                for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
@@ -14312,7 +14574,7 @@ lpfc_sli4_init_vpi(struct lpfc_vport *vport)
        if (!mboxq)
                return -ENOMEM;
        lpfc_init_vpi(phba, mboxq, vport->vpi);
-       mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
+       mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
        rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
        if (rc != MBX_SUCCESS) {
                lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
@@ -15188,7 +15450,7 @@ lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list,
        if (!phba->sli4_hba.intr_enable)
                rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
        else {
-               mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
+               mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
                rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
        }
        /* The IOCTL status is embedded in the mailbox subheader. */
index a0075b0af1423d76fbe32081ff654f0bd2284c2e..29c13b63e323563bf30009ed4205419de3a77775 100644 (file)
@@ -293,13 +293,11 @@ struct lpfc_sli {
        struct lpfc_lnk_stat lnk_stat_offsets;
 };
 
-#define LPFC_MBOX_TMO           30     /* Sec tmo for outstanding mbox
-                                          command */
-#define LPFC_MBOX_SLI4_CONFIG_TMO 60   /* Sec tmo for outstanding mbox
-                                          command */
-#define LPFC_MBOX_TMO_FLASH_CMD 300     /* Sec tmo for outstanding FLASH write
-                                        * or erase cmds. This is especially
-                                        * long because of the potential of
-                                        * multiple flash erases that can be
-                                        * spawned.
-                                        */
+/* Timeout for normal outstanding mbox command (Seconds) */
+#define LPFC_MBOX_TMO                          30
+/* Timeout for non-flash-based outstanding sli_config mbox command (Seconds) */
+#define LPFC_MBOX_SLI4_CONFIG_TMO              60
+/* Timeout for flash-based outstanding sli_config mbox command (Seconds) */
+#define LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO     300
+/* Timeout for other flash-based outstanding mbox command (Seconds) */
+#define LPFC_MBOX_TMO_FLASH_CMD                        300
index 19bb87ae85975a84bcf060642c7ba93402638766..d5cffd8af340fde2f0c1aa9f4ca34060c5f84f01 100644 (file)
@@ -23,7 +23,6 @@
 #define LPFC_XRI_EXCH_BUSY_WAIT_T1             10
 #define LPFC_XRI_EXCH_BUSY_WAIT_T2              30000
 #define LPFC_RELEASE_NOTIFICATION_INTERVAL     32
-#define LPFC_GET_QE_REL_INT                    32
 #define LPFC_RPI_LOW_WATER_MARK                        10
 
 #define LPFC_UNREG_FCF                          1
@@ -126,6 +125,8 @@ struct lpfc_queue {
        struct list_head child_list;
        uint32_t entry_count;   /* Number of entries to support on the queue */
        uint32_t entry_size;    /* Size of each queue entry. */
+       uint32_t entry_repost;  /* Count of entries before doorbell is rung */
+#define LPFC_QUEUE_MIN_REPOST  8
        uint32_t queue_id;      /* Queue ID assigned by the hardware */
        uint32_t assoc_qid;     /* Queue ID associated with, for CQ/WQ/MQ */
        struct list_head page_list;
@@ -388,6 +389,16 @@ struct lpfc_iov {
        uint32_t vf_number;
 };
 
+struct lpfc_sli4_lnk_info {
+       uint8_t lnk_dv;
+#define LPFC_LNK_DAT_INVAL     0
+#define LPFC_LNK_DAT_VAL       1
+       uint8_t lnk_tp;
+#define LPFC_LNK_GE    0x0 /* FCoE */
+#define LPFC_LNK_FC    0x1 /* FC   */
+       uint8_t lnk_no;
+};
+
 /* SLI4 HBA data structure entries */
 struct lpfc_sli4_hba {
        void __iomem *conf_regs_memmap_p; /* Kernel memory mapped address for
@@ -503,6 +514,10 @@ struct lpfc_sli4_hba {
        struct list_head sp_els_xri_aborted_work_queue;
        struct list_head sp_unsol_work_queue;
        struct lpfc_sli4_link link_state;
+       struct lpfc_sli4_lnk_info lnk_info;
+       uint32_t pport_name_sta;
+#define LPFC_SLI4_PPNAME_NON   0
+#define LPFC_SLI4_PPNAME_GET   1
        struct lpfc_iov iov;
        spinlock_t abts_scsi_buf_list_lock; /* list of aborted SCSI IOs */
        spinlock_t abts_sgl_list_lock; /* list of aborted els IOs */
@@ -553,6 +568,7 @@ struct lpfc_rsrc_blks {
  * SLI4 specific function prototypes
  */
 int lpfc_pci_function_reset(struct lpfc_hba *);
+int lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *);
 int lpfc_sli4_hba_setup(struct lpfc_hba *);
 int lpfc_sli4_config(struct lpfc_hba *, struct lpfcMboxq *, uint8_t,
                     uint8_t, uint32_t, bool);
@@ -576,6 +592,7 @@ uint32_t lpfc_wq_create(struct lpfc_hba *, struct lpfc_queue *,
                        struct lpfc_queue *, uint32_t);
 uint32_t lpfc_rq_create(struct lpfc_hba *, struct lpfc_queue *,
                        struct lpfc_queue *, struct lpfc_queue *, uint32_t);
+void lpfc_rq_adjust_repost(struct lpfc_hba *, struct lpfc_queue *, int);
 uint32_t lpfc_eq_destroy(struct lpfc_hba *, struct lpfc_queue *);
 uint32_t lpfc_cq_destroy(struct lpfc_hba *, struct lpfc_queue *);
 uint32_t lpfc_mq_destroy(struct lpfc_hba *, struct lpfc_queue *);
@@ -632,5 +649,5 @@ void lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *, LPFC_MBOXQ_t *);
 void lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *, LPFC_MBOXQ_t *);
 int lpfc_sli4_unregister_fcf(struct lpfc_hba *);
 int lpfc_sli4_post_status_check(struct lpfc_hba *);
-uint8_t lpfc_sli4_mbox_opcode_get(struct lpfc_hba *, struct lpfcMboxq *);
-
+uint8_t lpfc_sli_config_mbox_subsys_get(struct lpfc_hba *, LPFC_MBOXQ_t *);
+uint8_t lpfc_sli_config_mbox_opcode_get(struct lpfc_hba *, LPFC_MBOXQ_t *);
index c1e0ae94d9f4e6cdc01c648e785a6bc6660a34fa..b0630e37f1ef45756e77f4db5cb87db5a6b09ddd 100644 (file)
@@ -18,7 +18,7 @@
  * included with this package.                                     *
  *******************************************************************/
 
-#define LPFC_DRIVER_VERSION "8.3.25"
+#define LPFC_DRIVER_VERSION "8.3.27"
 #define LPFC_DRIVER_NAME               "lpfc"
 #define LPFC_SP_DRIVER_HANDLER_NAME    "lpfc:sp"
 #define LPFC_FP_DRIVER_HANDLER_NAME    "lpfc:fp"
index 1feb551a57bce4cd8e8fe8cf0bb3c6522af3a154..cff6ca67415ccfc2e118e86cb4f33bd8ab53fd99 100644 (file)
@@ -692,13 +692,14 @@ lpfc_vport_delete(struct fc_vport *fc_vport)
                        /* Indicate free memory when release */
                        NLP_SET_FREE_REQ(ndlp);
                } else {
-                       if (!NLP_CHK_NODE_ACT(ndlp))
+                       if (!NLP_CHK_NODE_ACT(ndlp)) {
                                ndlp = lpfc_enable_node(vport, ndlp,
                                                NLP_STE_UNUSED_NODE);
                                if (!ndlp)
                                        goto skip_logo;
+                       }
 
-                       /* Remove ndlp from vport npld list */
+                       /* Remove ndlp from vport list */
                        lpfc_dequeue_node(vport, ndlp);
                        spin_lock_irq(&phba->ndlp_lock);
                        if (!NLP_CHK_FREE_REQ(ndlp))
@@ -711,8 +712,17 @@ lpfc_vport_delete(struct fc_vport *fc_vport)
                        }
                        spin_unlock_irq(&phba->ndlp_lock);
                }
-               if (!(vport->vpi_state & LPFC_VPI_REGISTERED))
+
+               /*
+                * If the vpi is not registered, then a valid FDISC doesn't
+                * exist and there is no need for a ELS LOGO.  Just cleanup
+                * the ndlp.
+                */
+               if (!(vport->vpi_state & LPFC_VPI_REGISTERED)) {
+                       lpfc_nlp_put(ndlp);
                        goto skip_logo;
+               }
+
                vport->unreg_vpi_cmpl = VPORT_INVAL;
                timeout = msecs_to_jiffies(phba->fc_ratov * 2000);
                if (!lpfc_issue_els_npiv_logo(vport, ndlp))
index 3893337e3dd3ff05155f7dd99cf5db356adde3f0..590ce1ef20167d407dde187924a9a0ccf2def68e 100644 (file)
@@ -230,9 +230,6 @@ static void mac_esp_send_pdma_cmd(struct esp *esp, u32 addr, u32 esp_count,
                                  u32 dma_count, int write, u8 cmd)
 {
        struct mac_esp_priv *mep = MAC_ESP_GET_PRIV(esp);
-       unsigned long flags;
-
-       local_irq_save(flags);
 
        mep->error = 0;
 
@@ -270,8 +267,6 @@ static void mac_esp_send_pdma_cmd(struct esp *esp, u32 addr, u32 esp_count,
                        esp_count = n;
                }
        } while (esp_count);
-
-       local_irq_restore(flags);
 }
 
 /*
@@ -353,8 +348,6 @@ static void mac_esp_send_pio_cmd(struct esp *esp, u32 addr, u32 esp_count,
        struct mac_esp_priv *mep = MAC_ESP_GET_PRIV(esp);
        u8 *fifo = esp->regs + ESP_FDATA * 16;
 
-       disable_irq(esp->host->irq);
-
        cmd &= ~ESP_CMD_DMA;
        mep->error = 0;
 
@@ -431,8 +424,6 @@ static void mac_esp_send_pio_cmd(struct esp *esp, u32 addr, u32 esp_count,
                        scsi_esp_cmd(esp, ESP_CMD_TI);
                }
        }
-
-       enable_irq(esp->host->irq);
 }
 
 static int mac_esp_irq_pending(struct esp *esp)
index 3948a00d81f44f536ce308e65ec8cc09dea92a6f..dd94c7d574fb8b8027f574657cbdc43b46fa906f 100644 (file)
@@ -33,9 +33,9 @@
 /*
  * MegaRAID SAS Driver meta data
  */
-#define MEGASAS_VERSION                                "00.00.05.40-rc1"
-#define MEGASAS_RELDATE                                "Jul. 26, 2011"
-#define MEGASAS_EXT_VERSION                    "Tue. Jul. 26 17:00:00 PDT 2011"
+#define MEGASAS_VERSION                                "00.00.06.12-rc1"
+#define MEGASAS_RELDATE                                "Oct. 5, 2011"
+#define MEGASAS_EXT_VERSION                    "Wed. Oct. 5 17:00:00 PDT 2011"
 
 /*
  * Device IDs
@@ -48,6 +48,7 @@
 #define        PCI_DEVICE_ID_LSI_SAS0073SKINNY         0x0073
 #define        PCI_DEVICE_ID_LSI_SAS0071SKINNY         0x0071
 #define        PCI_DEVICE_ID_LSI_FUSION                0x005b
+#define PCI_DEVICE_ID_LSI_INVADER              0x005d
 
 /*
  * =====================================
 #define MFI_CMD_ABORT                          0x06
 #define MFI_CMD_SMP                            0x07
 #define MFI_CMD_STP                            0x08
+#define MFI_CMD_INVALID                                0xff
 
 #define MR_DCMD_CTRL_GET_INFO                  0x01010000
 #define MR_DCMD_LD_GET_LIST                    0x03010000
@@ -221,6 +223,7 @@ enum MFI_STAT {
        MFI_STAT_RESERVATION_IN_PROGRESS = 0x36,
        MFI_STAT_I2C_ERRORS_DETECTED = 0x37,
        MFI_STAT_PCI_ERRORS_DETECTED = 0x38,
+       MFI_STAT_CONFIG_SEQ_MISMATCH = 0x67,
 
        MFI_STAT_INVALID_STATUS = 0xFF
 };
@@ -716,7 +719,7 @@ struct megasas_ctrl_info {
 #define MEGASAS_DEFAULT_INIT_ID                        -1
 #define MEGASAS_MAX_LUN                                8
 #define MEGASAS_MAX_LD                         64
-#define MEGASAS_DEFAULT_CMD_PER_LUN            128
+#define MEGASAS_DEFAULT_CMD_PER_LUN            256
 #define MEGASAS_MAX_PD                          (MEGASAS_MAX_PD_CHANNELS * \
                                                MEGASAS_MAX_DEV_PER_CHANNEL)
 #define MEGASAS_MAX_LD_IDS                     (MEGASAS_MAX_LD_CHANNELS * \
@@ -755,6 +758,7 @@ struct megasas_ctrl_info {
 #define MEGASAS_INT_CMDS                       32
 #define MEGASAS_SKINNY_INT_CMDS                        5
 
+#define MEGASAS_MAX_MSIX_QUEUES                        16
 /*
  * FW can accept both 32 and 64 bit SGLs. We want to allocate 32/64 bit
  * SGLs based on the size of dma_addr_t
@@ -1276,6 +1280,11 @@ struct megasas_aen_event {
        struct megasas_instance *instance;
 };
 
+struct megasas_irq_context {
+       struct megasas_instance *instance;
+       u32 MSIxIndex;
+};
+
 struct megasas_instance {
 
        u32 *producer;
@@ -1349,8 +1358,9 @@ struct megasas_instance {
 
        /* Ptr to hba specific information */
        void *ctrl_context;
-       u8      msi_flag;
-       struct msix_entry msixentry;
+       unsigned int msix_vectors;
+       struct msix_entry msixentry[MEGASAS_MAX_MSIX_QUEUES];
+       struct megasas_irq_context irq_context[MEGASAS_MAX_MSIX_QUEUES];
        u64 map_id;
        struct megasas_cmd *map_update_cmd;
        unsigned long bar;
index 776d0198866044811e521d01911958f40d888768..29a994f9c4f1e6a9c0973ecd3cebe413f4937c7b 100644 (file)
@@ -18,7 +18,7 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  *
  *  FILE: megaraid_sas_base.c
- *  Version : v00.00.05.40-rc1
+ *  Version : v00.00.06.12-rc1
  *
  *  Authors: LSI Corporation
  *           Sreenivas Bagalkote
@@ -84,7 +84,7 @@ MODULE_VERSION(MEGASAS_VERSION);
 MODULE_AUTHOR("megaraidlinux@lsi.com");
 MODULE_DESCRIPTION("LSI MegaRAID SAS Driver");
 
-int megasas_transition_to_ready(struct megasas_instance *instance);
+int megasas_transition_to_ready(struct megasas_instance *instance, int ocr);
 static int megasas_get_pd_list(struct megasas_instance *instance);
 static int megasas_issue_init_mfi(struct megasas_instance *instance);
 static int megasas_register_aen(struct megasas_instance *instance,
@@ -114,6 +114,8 @@ static struct pci_device_id megasas_pci_table[] = {
        /* xscale IOP */
        {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FUSION)},
        /* Fusion */
+       {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_INVADER)},
+       /* Invader */
        {}
 };
 
@@ -213,6 +215,10 @@ megasas_return_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd)
 
        cmd->scmd = NULL;
        cmd->frame_count = 0;
+       if ((instance->pdev->device != PCI_DEVICE_ID_LSI_FUSION) &&
+           (instance->pdev->device != PCI_DEVICE_ID_LSI_INVADER) &&
+           (reset_devices))
+               cmd->frame->hdr.cmd = MFI_CMD_INVALID;
        list_add_tail(&cmd->list, &instance->cmd_pool);
 
        spin_unlock_irqrestore(&instance->cmd_pool_lock, flags);
@@ -1583,7 +1589,8 @@ void megaraid_sas_kill_hba(struct megasas_instance *instance)
 {
        if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) ||
            (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY) ||
-           (instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION)) {
+           (instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) ||
+           (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER)) {
                writel(MFI_STOP_ADP, &instance->reg_set->doorbell);
        } else {
                writel(MFI_STOP_ADP, &instance->reg_set->inbound_doorbell);
@@ -1907,7 +1914,6 @@ static int megasas_generic_reset(struct scsi_cmnd *scmd)
 static enum
 blk_eh_timer_return megasas_reset_timer(struct scsi_cmnd *scmd)
 {
-       struct megasas_cmd *cmd = (struct megasas_cmd *)scmd->SCp.ptr;
        struct megasas_instance *instance;
        unsigned long flags;
 
@@ -1916,7 +1922,7 @@ blk_eh_timer_return megasas_reset_timer(struct scsi_cmnd *scmd)
                return BLK_EH_NOT_HANDLED;
        }
 
-       instance = cmd->instance;
+       instance = (struct megasas_instance *)scmd->device->host->hostdata;
        if (!(instance->flag & MEGASAS_FW_BUSY)) {
                /* FW is busy, throttle IO */
                spin_lock_irqsave(instance->host->host_lock, flags);
@@ -1957,7 +1963,8 @@ static int megasas_reset_bus_host(struct scsi_cmnd *scmd)
        /*
         * First wait for all commands to complete
         */
-       if (instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION)
+       if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) ||
+           (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER))
                ret = megasas_reset_fusion(scmd->device->host);
        else
                ret = megasas_generic_reset(scmd);
@@ -2161,7 +2168,16 @@ megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd,
                cmd->scmd->SCp.ptr = NULL;
 
        switch (hdr->cmd) {
-
+       case MFI_CMD_INVALID:
+               /* Some older 1068 controller FW may keep a pended
+                  MR_DCMD_CTRL_EVENT_GET_INFO left over from the main kernel
+                  when booting the kdump kernel.  Ignore this command to
+                  prevent a kernel panic on shutdown of the kdump kernel. */
+               printk(KERN_WARNING "megaraid_sas: MFI_CMD_INVALID command "
+                      "completed.\n");
+               printk(KERN_WARNING "megaraid_sas: If you have a controller "
+                      "other than PERC5, please upgrade your firmware.\n");
+               break;
        case MFI_CMD_PD_SCSI_IO:
        case MFI_CMD_LD_SCSI_IO:
 
@@ -2477,7 +2493,7 @@ process_fw_state_change_wq(struct work_struct *work)
                        msleep(1000);
                }
 
-               if (megasas_transition_to_ready(instance)) {
+               if (megasas_transition_to_ready(instance, 1)) {
                        printk(KERN_NOTICE "megaraid_sas:adapter not ready\n");
 
                        megaraid_sas_kill_hba(instance);
@@ -2532,7 +2548,7 @@ megasas_deplete_reply_queue(struct megasas_instance *instance,
                                                instance->reg_set)
                                                ) == 0) {
                /* Hardware may not set outbound_intr_status in MSI-X mode */
-               if (!instance->msi_flag)
+               if (!instance->msix_vectors)
                        return IRQ_NONE;
        }
 
@@ -2590,16 +2606,14 @@ megasas_deplete_reply_queue(struct megasas_instance *instance,
  */
 static irqreturn_t megasas_isr(int irq, void *devp)
 {
-       struct megasas_instance *instance;
+       struct megasas_irq_context *irq_context = devp;
+       struct megasas_instance *instance = irq_context->instance;
        unsigned long flags;
        irqreturn_t     rc;
 
-       if (atomic_read(
-               &(((struct megasas_instance *)devp)->fw_reset_no_pci_access)))
+       if (atomic_read(&instance->fw_reset_no_pci_access))
                return IRQ_HANDLED;
 
-       instance = (struct megasas_instance *)devp;
-
        spin_lock_irqsave(&instance->hba_lock, flags);
        rc =  megasas_deplete_reply_queue(instance, DID_OK);
        spin_unlock_irqrestore(&instance->hba_lock, flags);
@@ -2617,7 +2631,7 @@ static irqreturn_t megasas_isr(int irq, void *devp)
  * has to wait for the ready state.
  */
 int
-megasas_transition_to_ready(struct megasas_instance* instance)
+megasas_transition_to_ready(struct megasas_instance *instance, int ocr)
 {
        int i;
        u8 max_wait;
@@ -2639,11 +2653,13 @@ megasas_transition_to_ready(struct megasas_instance* instance)
                switch (fw_state) {
 
                case MFI_STATE_FAULT:
-
                        printk(KERN_DEBUG "megasas: FW in FAULT state!!\n");
-                       max_wait = MEGASAS_RESET_WAIT_TIME;
-                       cur_state = MFI_STATE_FAULT;
-                       break;
+                       if (ocr) {
+                               max_wait = MEGASAS_RESET_WAIT_TIME;
+                               cur_state = MFI_STATE_FAULT;
+                               break;
+                       } else
+                               return -ENODEV;
 
                case MFI_STATE_WAIT_HANDSHAKE:
                        /*
@@ -2654,7 +2670,9 @@ megasas_transition_to_ready(struct megasas_instance* instance)
                                (instance->pdev->device ==
                                 PCI_DEVICE_ID_LSI_SAS0071SKINNY) ||
                                (instance->pdev->device ==
-                                PCI_DEVICE_ID_LSI_FUSION)) {
+                                PCI_DEVICE_ID_LSI_FUSION) ||
+                               (instance->pdev->device ==
+                               PCI_DEVICE_ID_LSI_INVADER)) {
                                writel(
                                  MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG,
                                  &instance->reg_set->doorbell);
@@ -2674,7 +2692,9 @@ megasas_transition_to_ready(struct megasas_instance* instance)
                                (instance->pdev->device ==
                                 PCI_DEVICE_ID_LSI_SAS0071SKINNY) ||
                            (instance->pdev->device ==
-                            PCI_DEVICE_ID_LSI_FUSION)) {
+                            PCI_DEVICE_ID_LSI_FUSION) ||
+                           (instance->pdev->device ==
+                            PCI_DEVICE_ID_LSI_INVADER)) {
                                writel(MFI_INIT_HOTPLUG,
                                       &instance->reg_set->doorbell);
                        } else
@@ -2695,11 +2715,15 @@ megasas_transition_to_ready(struct megasas_instance* instance)
                                (instance->pdev->device ==
                                PCI_DEVICE_ID_LSI_SAS0071SKINNY)  ||
                                (instance->pdev->device
-                                       == PCI_DEVICE_ID_LSI_FUSION)) {
+                                       == PCI_DEVICE_ID_LSI_FUSION) ||
+                               (instance->pdev->device
+                                       == PCI_DEVICE_ID_LSI_INVADER)) {
                                writel(MFI_RESET_FLAGS,
                                        &instance->reg_set->doorbell);
-                               if (instance->pdev->device ==
-                                   PCI_DEVICE_ID_LSI_FUSION) {
+                               if ((instance->pdev->device ==
+                                   PCI_DEVICE_ID_LSI_FUSION) ||
+                                   (instance->pdev->device ==
+                                    PCI_DEVICE_ID_LSI_INVADER)) {
                                        for (i = 0; i < (10 * 1000); i += 20) {
                                                if (readl(
                                                            &instance->
@@ -2922,6 +2946,10 @@ static int megasas_create_frame_pool(struct megasas_instance *instance)
                memset(cmd->frame, 0, total_sz);
                cmd->frame->io.context = cmd->index;
                cmd->frame->io.pad_0 = 0;
+               if ((instance->pdev->device != PCI_DEVICE_ID_LSI_FUSION) &&
+                   (instance->pdev->device != PCI_DEVICE_ID_LSI_INVADER) &&
+                   (reset_devices))
+                       cmd->frame->hdr.cmd = MFI_CMD_INVALID;
        }
 
        return 0;
@@ -3474,6 +3502,7 @@ static int megasas_init_fw(struct megasas_instance *instance)
        struct megasas_register_set __iomem *reg_set;
        struct megasas_ctrl_info *ctrl_info;
        unsigned long bar_list;
+       int i;
 
        /* Find first memory bar */
        bar_list = pci_select_bars(instance->pdev, IORESOURCE_MEM);
@@ -3496,6 +3525,7 @@ static int megasas_init_fw(struct megasas_instance *instance)
 
        switch (instance->pdev->device) {
        case PCI_DEVICE_ID_LSI_FUSION:
+       case PCI_DEVICE_ID_LSI_INVADER:
                instance->instancet = &megasas_instance_template_fusion;
                break;
        case PCI_DEVICE_ID_LSI_SAS1078R:
@@ -3520,15 +3550,39 @@ static int megasas_init_fw(struct megasas_instance *instance)
        /*
         * We expect the FW state to be READY
         */
-       if (megasas_transition_to_ready(instance))
+       if (megasas_transition_to_ready(instance, 0))
                goto fail_ready_state;
 
        /* Check if MSI-X is supported while in ready state */
        msix_enable = (instance->instancet->read_fw_status_reg(reg_set) &
                       0x4000000) >> 0x1a;
-       if (msix_enable && !msix_disable &&
-           !pci_enable_msix(instance->pdev, &instance->msixentry, 1))
-               instance->msi_flag = 1;
+       if (msix_enable && !msix_disable) {
+               /* Check max MSI-X vectors */
+               if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) ||
+                   (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER)) {
+                       instance->msix_vectors = (readl(&instance->reg_set->
+                                                       outbound_scratch_pad_2
+                                                         ) & 0x1F) + 1;
+               } else
+                       instance->msix_vectors = 1;
+               /* Don't bother allocating more MSI-X vectors than cpus */
+               instance->msix_vectors = min(instance->msix_vectors,
+                                            (unsigned int)num_online_cpus());
+               for (i = 0; i < instance->msix_vectors; i++)
+                       instance->msixentry[i].entry = i;
+               i = pci_enable_msix(instance->pdev, instance->msixentry,
+                                   instance->msix_vectors);
+               if (i >= 0) {
+                       if (i) {
+                               if (!pci_enable_msix(instance->pdev,
+                                                    instance->msixentry, i))
+                                       instance->msix_vectors = i;
+                               else
+                                       instance->msix_vectors = 0;
+                       }
+               } else
+                       instance->msix_vectors = 0;
+       }
 
        /* Get operational params, sge flags, send init cmd to controller */
        if (instance->instancet->init_adapter(instance))
@@ -3892,7 +3946,8 @@ static int megasas_io_attach(struct megasas_instance *instance)
        host->max_cmd_len = 16;
 
        /* Fusion only supports host reset */
-       if (instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) {
+       if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) ||
+           (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER)) {
                host->hostt->eh_device_reset_handler = NULL;
                host->hostt->eh_bus_reset_handler = NULL;
        }
@@ -3942,7 +3997,7 @@ fail_set_dma_mask:
 static int __devinit
 megasas_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
 {
-       int rval, pos;
+       int rval, pos, i, j;
        struct Scsi_Host *host;
        struct megasas_instance *instance;
        u16 control = 0;
@@ -4002,6 +4057,7 @@ megasas_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
 
        switch (instance->pdev->device) {
        case PCI_DEVICE_ID_LSI_FUSION:
+       case PCI_DEVICE_ID_LSI_INVADER:
        {
                struct fusion_context *fusion;
 
@@ -4094,7 +4150,8 @@ megasas_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
        instance->last_time = 0;
        instance->disableOnlineCtrlReset = 1;
 
-       if (instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION)
+       if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) ||
+           (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER))
                INIT_WORK(&instance->work_init, megasas_fusion_ocr_wq);
        else
                INIT_WORK(&instance->work_init, process_fw_state_change_wq);
@@ -4108,11 +4165,32 @@ megasas_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
        /*
         * Register IRQ
         */
-       if (request_irq(instance->msi_flag ? instance->msixentry.vector :
-                       pdev->irq, instance->instancet->service_isr,
-                       IRQF_SHARED, "megasas", instance)) {
-               printk(KERN_DEBUG "megasas: Failed to register IRQ\n");
-               goto fail_irq;
+       if (instance->msix_vectors) {
+               for (i = 0 ; i < instance->msix_vectors; i++) {
+                       instance->irq_context[i].instance = instance;
+                       instance->irq_context[i].MSIxIndex = i;
+                       if (request_irq(instance->msixentry[i].vector,
+                                       instance->instancet->service_isr, 0,
+                                       "megasas",
+                                       &instance->irq_context[i])) {
+                               printk(KERN_DEBUG "megasas: Failed to "
+                                      "register IRQ for vector %d.\n", i);
+                               for (j = 0 ; j < i ; j++)
+                                       free_irq(
+                                               instance->msixentry[j].vector,
+                                               &instance->irq_context[j]);
+                               goto fail_irq;
+                       }
+               }
+       } else {
+               instance->irq_context[0].instance = instance;
+               instance->irq_context[0].MSIxIndex = 0;
+               if (request_irq(pdev->irq, instance->instancet->service_isr,
+                               IRQF_SHARED, "megasas",
+                               &instance->irq_context[0])) {
+                       printk(KERN_DEBUG "megasas: Failed to register IRQ\n");
+                       goto fail_irq;
+               }
        }
 
        instance->instancet->enable_intr(instance->reg_set);
@@ -4156,15 +4234,20 @@ megasas_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
 
        pci_set_drvdata(pdev, NULL);
        instance->instancet->disable_intr(instance->reg_set);
-       free_irq(instance->msi_flag ? instance->msixentry.vector :
-                instance->pdev->irq, instance);
+       if (instance->msix_vectors)
+               for (i = 0 ; i < instance->msix_vectors; i++)
+                       free_irq(instance->msixentry[i].vector,
+                                &instance->irq_context[i]);
+       else
+               free_irq(instance->pdev->irq, &instance->irq_context[0]);
 fail_irq:
-       if (instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION)
+       if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) ||
+           (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER))
                megasas_release_fusion(instance);
        else
                megasas_release_mfi(instance);
       fail_init_mfi:
-       if (instance->msi_flag)
+       if (instance->msix_vectors)
                pci_disable_msix(instance->pdev);
       fail_alloc_dma_buf:
        if (instance->evt_detail)
@@ -4280,6 +4363,7 @@ megasas_suspend(struct pci_dev *pdev, pm_message_t state)
 {
        struct Scsi_Host *host;
        struct megasas_instance *instance;
+       int i;
 
        instance = pci_get_drvdata(pdev);
        host = instance->host;
@@ -4303,9 +4387,14 @@ megasas_suspend(struct pci_dev *pdev, pm_message_t state)
 
        pci_set_drvdata(instance->pdev, instance);
        instance->instancet->disable_intr(instance->reg_set);
-       free_irq(instance->msi_flag ? instance->msixentry.vector :
-                instance->pdev->irq, instance);
-       if (instance->msi_flag)
+
+       if (instance->msix_vectors)
+               for (i = 0 ; i < instance->msix_vectors; i++)
+                       free_irq(instance->msixentry[i].vector,
+                                &instance->irq_context[i]);
+       else
+               free_irq(instance->pdev->irq, &instance->irq_context[0]);
+       if (instance->msix_vectors)
                pci_disable_msix(instance->pdev);
 
        pci_save_state(pdev);
@@ -4323,7 +4412,7 @@ megasas_suspend(struct pci_dev *pdev, pm_message_t state)
 static int
 megasas_resume(struct pci_dev *pdev)
 {
-       int rval;
+       int rval, i, j;
        struct Scsi_Host *host;
        struct megasas_instance *instance;
 
@@ -4357,15 +4446,17 @@ megasas_resume(struct pci_dev *pdev)
        /*
         * We expect the FW state to be READY
         */
-       if (megasas_transition_to_ready(instance))
+       if (megasas_transition_to_ready(instance, 0))
                goto fail_ready_state;
 
        /* Now re-enable MSI-X */
-       if (instance->msi_flag)
-               pci_enable_msix(instance->pdev, &instance->msixentry, 1);
+       if (instance->msix_vectors)
+               pci_enable_msix(instance->pdev, instance->msixentry,
+                               instance->msix_vectors);
 
        switch (instance->pdev->device) {
        case PCI_DEVICE_ID_LSI_FUSION:
+       case PCI_DEVICE_ID_LSI_INVADER:
        {
                megasas_reset_reply_desc(instance);
                if (megasas_ioc_init_fusion(instance)) {
@@ -4391,11 +4482,32 @@ megasas_resume(struct pci_dev *pdev)
        /*
         * Register IRQ
         */
-       if (request_irq(instance->msi_flag ? instance->msixentry.vector :
-                       pdev->irq, instance->instancet->service_isr,
-                       IRQF_SHARED, "megasas", instance)) {
-               printk(KERN_ERR "megasas: Failed to register IRQ\n");
-               goto fail_irq;
+       if (instance->msix_vectors) {
+               for (i = 0 ; i < instance->msix_vectors; i++) {
+                       instance->irq_context[i].instance = instance;
+                       instance->irq_context[i].MSIxIndex = i;
+                       if (request_irq(instance->msixentry[i].vector,
+                                       instance->instancet->service_isr, 0,
+                                       "megasas",
+                                       &instance->irq_context[i])) {
+                               printk(KERN_DEBUG "megasas: Failed to "
+                                      "register IRQ for vector %d.\n", i);
+                               for (j = 0 ; j < i ; j++)
+                                       free_irq(
+                                               instance->msixentry[j].vector,
+                                               &instance->irq_context[j]);
+                               goto fail_irq;
+                       }
+               }
+       } else {
+               instance->irq_context[0].instance = instance;
+               instance->irq_context[0].MSIxIndex = 0;
+               if (request_irq(pdev->irq, instance->instancet->service_isr,
+                               IRQF_SHARED, "megasas",
+                               &instance->irq_context[0])) {
+                       printk(KERN_DEBUG "megasas: Failed to register IRQ\n");
+                       goto fail_irq;
+               }
        }
 
        instance->instancet->enable_intr(instance->reg_set);
@@ -4492,13 +4604,18 @@ static void __devexit megasas_detach_one(struct pci_dev *pdev)
 
        instance->instancet->disable_intr(instance->reg_set);
 
-       free_irq(instance->msi_flag ? instance->msixentry.vector :
-                instance->pdev->irq, instance);
-       if (instance->msi_flag)
+       if (instance->msix_vectors)
+               for (i = 0 ; i < instance->msix_vectors; i++)
+                       free_irq(instance->msixentry[i].vector,
+                                &instance->irq_context[i]);
+       else
+               free_irq(instance->pdev->irq, &instance->irq_context[0]);
+       if (instance->msix_vectors)
                pci_disable_msix(instance->pdev);
 
        switch (instance->pdev->device) {
        case PCI_DEVICE_ID_LSI_FUSION:
+       case PCI_DEVICE_ID_LSI_INVADER:
                megasas_release_fusion(instance);
                for (i = 0; i < 2 ; i++)
                        if (fusion->ld_map[i])
@@ -4539,14 +4656,20 @@ static void __devexit megasas_detach_one(struct pci_dev *pdev)
  */
 static void megasas_shutdown(struct pci_dev *pdev)
 {
+       int i;
        struct megasas_instance *instance = pci_get_drvdata(pdev);
+
        instance->unload = 1;
        megasas_flush_cache(instance);
        megasas_shutdown_controller(instance, MR_DCMD_CTRL_SHUTDOWN);
        instance->instancet->disable_intr(instance->reg_set);
-       free_irq(instance->msi_flag ? instance->msixentry.vector :
-                instance->pdev->irq, instance);
-       if (instance->msi_flag)
+       if (instance->msix_vectors)
+               for (i = 0 ; i < instance->msix_vectors; i++)
+                       free_irq(instance->msixentry[i].vector,
+                                &instance->irq_context[i]);
+       else
+               free_irq(instance->pdev->irq, &instance->irq_context[0]);
+       if (instance->msix_vectors)
                pci_disable_msix(instance->pdev);
 }
 
index 5a5af1fe7581846fc2eeab99f73a002c7caa3e97..5255dd688aca49b807f430ffa26dd80a41fcf42e 100644 (file)
@@ -52,6 +52,7 @@
 #include <scsi/scsi_host.h>
 
 #include "megaraid_sas_fusion.h"
+#include "megaraid_sas.h"
 #include <asm/div64.h>
 
 #define ABS_DIFF(a, b)   (((a) > (b)) ? ((a) - (b)) : ((b) - (a)))
@@ -226,8 +227,9 @@ u32 MR_GetSpanBlock(u32 ld, u64 row, u64 *span_blk,
 *    span          - Span number
 *    block         - Absolute Block number in the physical disk
 */
-u8 MR_GetPhyParams(u32 ld, u64 stripRow, u16 stripRef, u64 *pdBlock,
-                  u16 *pDevHandle, struct RAID_CONTEXT *pRAID_Context,
+u8 MR_GetPhyParams(struct megasas_instance *instance, u32 ld, u64 stripRow,
+                  u16 stripRef, u64 *pdBlock, u16 *pDevHandle,
+                  struct RAID_CONTEXT *pRAID_Context,
                   struct MR_FW_RAID_MAP_ALL *map)
 {
        struct MR_LD_RAID  *raid = MR_LdRaidGet(ld, map);
@@ -279,7 +281,8 @@ u8 MR_GetPhyParams(u32 ld, u64 stripRow, u16 stripRef, u64 *pdBlock,
                *pDevHandle = MR_PdDevHandleGet(pd, map);
        else {
                *pDevHandle = MR_PD_INVALID; /* set dev handle as invalid. */
-               if (raid->level >= 5)
+               if ((raid->level >= 5) &&
+                   (instance->pdev->device != PCI_DEVICE_ID_LSI_INVADER))
                        pRAID_Context->regLockFlags = REGION_TYPE_EXCLUSIVE;
                else if (raid->level == 1) {
                        /* Get alternate Pd. */
@@ -306,7 +309,8 @@ u8 MR_GetPhyParams(u32 ld, u64 stripRow, u16 stripRef, u64 *pdBlock,
 * This function will return 0 if region lock was acquired OR return num strips
 */
 u8
-MR_BuildRaidContext(struct IO_REQUEST_INFO *io_info,
+MR_BuildRaidContext(struct megasas_instance *instance,
+                   struct IO_REQUEST_INFO *io_info,
                    struct RAID_CONTEXT *pRAID_Context,
                    struct MR_FW_RAID_MAP_ALL *map)
 {
@@ -394,8 +398,12 @@ MR_BuildRaidContext(struct IO_REQUEST_INFO *io_info,
        }
 
        pRAID_Context->timeoutValue     = map->raidMap.fpPdIoTimeoutSec;
-       pRAID_Context->regLockFlags     = (isRead) ? REGION_TYPE_SHARED_READ :
-               raid->regTypeReqOnWrite;
+       if (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER)
+               pRAID_Context->regLockFlags = (isRead) ?
+                       raid->regTypeReqOnRead : raid->regTypeReqOnWrite;
+       else
+               pRAID_Context->regLockFlags = (isRead) ?
+                       REGION_TYPE_SHARED_READ : raid->regTypeReqOnWrite;
        pRAID_Context->VirtualDiskTgtId = raid->targetId;
        pRAID_Context->regLockRowLBA    = regStart;
        pRAID_Context->regLockLength    = regSize;
@@ -404,7 +412,8 @@ MR_BuildRaidContext(struct IO_REQUEST_INFO *io_info,
        /*Get Phy Params only if FP capable, or else leave it to MR firmware
          to do the calculation.*/
        if (io_info->fpOkForIo) {
-               retval = MR_GetPhyParams(ld, start_strip, ref_in_start_stripe,
+               retval = MR_GetPhyParams(instance, ld, start_strip,
+                                        ref_in_start_stripe,
                                         &io_info->pdBlock,
                                         &io_info->devHandle, pRAID_Context,
                                         map);
@@ -415,7 +424,8 @@ MR_BuildRaidContext(struct IO_REQUEST_INFO *io_info,
        } else if (isRead) {
                uint stripIdx;
                for (stripIdx = 0; stripIdx < num_strips; stripIdx++) {
-                       if (!MR_GetPhyParams(ld, start_strip + stripIdx,
+                       if (!MR_GetPhyParams(instance, ld,
+                                            start_strip + stripIdx,
                                             ref_in_start_stripe,
                                             &io_info->pdBlock,
                                             &io_info->devHandle,
index f13e7abd345a9b3956243fc5e047207f66d0dbe8..bfd87fab39aa7ff9949d2fe423c24f91fddc273e 100644 (file)
@@ -74,7 +74,8 @@ megasas_issue_polled(struct megasas_instance *instance,
                     struct megasas_cmd *cmd);
 
 u8
-MR_BuildRaidContext(struct IO_REQUEST_INFO *io_info,
+MR_BuildRaidContext(struct megasas_instance *instance,
+                   struct IO_REQUEST_INFO *io_info,
                    struct RAID_CONTEXT *pRAID_Context,
                    struct MR_FW_RAID_MAP_ALL *map);
 u16 MR_TargetIdToLdGet(u32 ldTgtId, struct MR_FW_RAID_MAP_ALL *map);
@@ -89,7 +90,7 @@ u8 MR_ValidateMapInfo(struct MR_FW_RAID_MAP_ALL *map,
                      struct LD_LOAD_BALANCE_INFO *lbInfo);
 u16 get_updated_dev_handle(struct LD_LOAD_BALANCE_INFO *lbInfo,
                           struct IO_REQUEST_INFO *in_info);
-int megasas_transition_to_ready(struct megasas_instance *instance);
+int megasas_transition_to_ready(struct megasas_instance *instance, int ocr);
 void megaraid_sas_kill_hba(struct megasas_instance *instance);
 
 extern u32 megasas_dbg_lvl;
@@ -101,6 +102,10 @@ extern u32 megasas_dbg_lvl;
 void
 megasas_enable_intr_fusion(struct megasas_register_set __iomem *regs)
 {
+       /* For Thunderbolt/Invader also clear intr on enable */
+       writel(~0, &regs->outbound_intr_status);
+       readl(&regs->outbound_intr_status);
+
        writel(~MFI_FUSION_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask);
 
        /* Dummy readl to force pci flush */
@@ -139,11 +144,6 @@ megasas_clear_intr_fusion(struct megasas_register_set __iomem *regs)
        if (!(status & MFI_FUSION_ENABLE_INTERRUPT_MASK))
                return 0;
 
-       /*
-        * dummy read to flush PCI
-        */
-       readl(&regs->outbound_intr_status);
-
        return 1;
 }
 
@@ -385,7 +385,7 @@ static int megasas_create_frame_pool_fusion(struct megasas_instance *instance)
 int
 megasas_alloc_cmds_fusion(struct megasas_instance *instance)
 {
-       int i, j;
+       int i, j, count;
        u32 max_cmd, io_frames_sz;
        struct fusion_context *fusion;
        struct megasas_cmd_fusion *cmd;
@@ -409,9 +409,10 @@ megasas_alloc_cmds_fusion(struct megasas_instance *instance)
                goto fail_req_desc;
        }
 
+       count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
        fusion->reply_frames_desc_pool =
                pci_pool_create("reply_frames pool", instance->pdev,
-                               fusion->reply_alloc_sz, 16, 0);
+                               fusion->reply_alloc_sz * count, 16, 0);
 
        if (!fusion->reply_frames_desc_pool) {
                printk(KERN_ERR "megasas; Could not allocate memory for "
@@ -430,7 +431,7 @@ megasas_alloc_cmds_fusion(struct megasas_instance *instance)
        }
 
        reply_desc = fusion->reply_frames_desc;
-       for (i = 0; i < fusion->reply_q_depth; i++, reply_desc++)
+       for (i = 0; i < fusion->reply_q_depth * count; i++, reply_desc++)
                reply_desc->Words = ULLONG_MAX;
 
        io_frames_sz = fusion->io_frames_alloc_sz;
@@ -590,7 +591,6 @@ megasas_ioc_init_fusion(struct megasas_instance *instance)
        struct megasas_init_frame *init_frame;
        struct MPI2_IOC_INIT_REQUEST *IOCInitMessage;
        dma_addr_t      ioc_init_handle;
-       u32 context;
        struct megasas_cmd *cmd;
        u8 ret;
        struct fusion_context *fusion;
@@ -634,14 +634,13 @@ megasas_ioc_init_fusion(struct megasas_instance *instance)
                fusion->reply_frames_desc_phys;
        IOCInitMessage->SystemRequestFrameBaseAddress =
                fusion->io_request_frames_phys;
-
+       /* Set to 0 for none or 1 MSI-X vectors */
+       IOCInitMessage->HostMSIxVectors = (instance->msix_vectors > 0 ?
+                                          instance->msix_vectors : 0);
        init_frame = (struct megasas_init_frame *)cmd->frame;
        memset(init_frame, 0, MEGAMFI_FRAME_SIZE);
 
        frame_hdr = &cmd->frame->hdr;
-       context = init_frame->context;
-       init_frame->context = context;
-
        frame_hdr->cmd_status = 0xFF;
        frame_hdr->flags |= MFI_FRAME_DONT_POST_IN_REPLY_QUEUE;
 
@@ -881,7 +880,7 @@ megasas_init_adapter_fusion(struct megasas_instance *instance)
        struct megasas_register_set __iomem *reg_set;
        struct fusion_context *fusion;
        u32 max_cmd;
-       int i = 0;
+       int i = 0, count;
 
        fusion = instance->ctrl_context;
 
@@ -933,7 +932,9 @@ megasas_init_adapter_fusion(struct megasas_instance *instance)
                (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE -
                 sizeof(union MPI2_SGE_IO_UNION))/16;
 
-       fusion->last_reply_idx = 0;
+       count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
+       for (i = 0 ; i < count; i++)
+               fusion->last_reply_idx[i] = 0;
 
        /*
         * Allocate memory for descriptors
@@ -1043,7 +1044,9 @@ map_cmd_status(struct megasas_cmd_fusion *cmd, u8 status, u8 ext_status)
        case MFI_STAT_DEVICE_NOT_FOUND:
                cmd->scmd->result = DID_BAD_TARGET << 16;
                break;
-
+       case MFI_STAT_CONFIG_SEQ_MISMATCH:
+               cmd->scmd->result = DID_IMM_RETRY << 16;
+               break;
        default:
                printk(KERN_DEBUG "megasas: FW status %#x\n", status);
                cmd->scmd->result = DID_ERROR << 16;
@@ -1066,14 +1069,17 @@ megasas_make_sgl_fusion(struct megasas_instance *instance,
                        struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr,
                        struct megasas_cmd_fusion *cmd)
 {
-       int i, sg_processed;
-       int sge_count, sge_idx;
+       int i, sg_processed, sge_count;
        struct scatterlist *os_sgl;
        struct fusion_context *fusion;
 
        fusion = instance->ctrl_context;
 
-       cmd->io_request->ChainOffset = 0;
+       if (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) {
+               struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr_end = sgl_ptr;
+               sgl_ptr_end += fusion->max_sge_in_main_msg - 1;
+               sgl_ptr_end->Flags = 0;
+       }
 
        sge_count = scsi_dma_map(scp);
 
@@ -1082,16 +1088,14 @@ megasas_make_sgl_fusion(struct megasas_instance *instance,
        if (sge_count > instance->max_num_sge || !sge_count)
                return sge_count;
 
-       if (sge_count > fusion->max_sge_in_main_msg) {
-               /* One element to store the chain info */
-               sge_idx = fusion->max_sge_in_main_msg - 1;
-       } else
-               sge_idx = sge_count;
-
        scsi_for_each_sg(scp, os_sgl, sge_count, i) {
                sgl_ptr->Length = sg_dma_len(os_sgl);
                sgl_ptr->Address = sg_dma_address(os_sgl);
                sgl_ptr->Flags = 0;
+               if (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) {
+                       if (i == sge_count - 1)
+                               sgl_ptr->Flags = IEEE_SGE_FLAGS_END_OF_LIST;
+               }
                sgl_ptr++;
 
                sg_processed = i + 1;
@@ -1100,13 +1104,30 @@ megasas_make_sgl_fusion(struct megasas_instance *instance,
                    (sge_count > fusion->max_sge_in_main_msg)) {
 
                        struct MPI25_IEEE_SGE_CHAIN64 *sg_chain;
-                       cmd->io_request->ChainOffset =
-                               fusion->chain_offset_io_request;
+                       if (instance->pdev->device ==
+                           PCI_DEVICE_ID_LSI_INVADER) {
+                               if ((cmd->io_request->IoFlags &
+                               MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) !=
+                               MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH)
+                                       cmd->io_request->ChainOffset =
+                                               fusion->
+                                               chain_offset_io_request;
+                               else
+                                       cmd->io_request->ChainOffset = 0;
+                       } else
+                               cmd->io_request->ChainOffset =
+                                       fusion->chain_offset_io_request;
+
                        sg_chain = sgl_ptr;
                        /* Prepare chain element */
                        sg_chain->NextChainOffset = 0;
-                       sg_chain->Flags = (IEEE_SGE_FLAGS_CHAIN_ELEMENT |
-                                          MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR);
+                       if (instance->pdev->device ==
+                           PCI_DEVICE_ID_LSI_INVADER)
+                               sg_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT;
+                       else
+                               sg_chain->Flags =
+                                       (IEEE_SGE_FLAGS_CHAIN_ELEMENT |
+                                        MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR);
                        sg_chain->Length =  (sizeof(union MPI2_SGE_IO_UNION)
                                             *(sge_count - sg_processed));
                        sg_chain->Address = cmd->sg_frame_phys_addr;
@@ -1399,11 +1420,18 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
                io_request->RaidContext.regLockFlags  = 0;
                fp_possible = 0;
        } else {
-               if (MR_BuildRaidContext(&io_info, &io_request->RaidContext,
+               if (MR_BuildRaidContext(instance, &io_info,
+                                       &io_request->RaidContext,
                                        local_map_ptr))
                        fp_possible = io_info.fpOkForIo;
        }
 
+       /* Use smp_processor_id() for now until cmd->request->cpu is CPU
+          id by default, not CPU group id, otherwise all MSI-X queues won't
+          be utilized */
+       cmd->request_desc->SCSIIO.MSIxIndex = instance->msix_vectors ?
+               smp_processor_id() % instance->msix_vectors : 0;
+
        if (fp_possible) {
                megasas_set_pd_lba(io_request, scp->cmd_len, &io_info, scp,
                                   local_map_ptr, start_lba_lo);
@@ -1412,6 +1440,20 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
                cmd->request_desc->SCSIIO.RequestFlags =
                        (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY
                         << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
+               if (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) {
+                       if (io_request->RaidContext.regLockFlags ==
+                           REGION_TYPE_UNUSED)
+                               cmd->request_desc->SCSIIO.RequestFlags =
+                                       (MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK <<
+                                       MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
+                       io_request->RaidContext.Type = MPI2_TYPE_CUDA;
+                       io_request->RaidContext.nseg = 0x1;
+                       io_request->IoFlags |=
+                         MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH;
+                       io_request->RaidContext.regLockFlags |=
+                         (MR_RL_FLAGS_GRANT_DESTINATION_CUDA |
+                          MR_RL_FLAGS_SEQ_NUM_ENABLE);
+               }
                if ((fusion->load_balance_info[device_id].loadBalanceFlag) &&
                    (io_info.isRead)) {
                        io_info.devHandle =
@@ -1426,11 +1468,23 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
        } else {
                io_request->RaidContext.timeoutValue =
                        local_map_ptr->raidMap.fpPdIoTimeoutSec;
-               io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST;
-               io_request->DevHandle = device_id;
                cmd->request_desc->SCSIIO.RequestFlags =
                        (MEGASAS_REQ_DESCRIPT_FLAGS_LD_IO
                         << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
+               if (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) {
+                       if (io_request->RaidContext.regLockFlags ==
+                           REGION_TYPE_UNUSED)
+                               cmd->request_desc->SCSIIO.RequestFlags =
+                                       (MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK <<
+                                       MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
+                       io_request->RaidContext.Type = MPI2_TYPE_CUDA;
+                       io_request->RaidContext.regLockFlags |=
+                               (MR_RL_FLAGS_GRANT_DESTINATION_CPU0 |
+                                MR_RL_FLAGS_SEQ_NUM_ENABLE);
+                       io_request->RaidContext.nseg = 0x1;
+               }
+               io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST;
+               io_request->DevHandle = device_id;
        } /* Not FP */
 }
 
@@ -1513,8 +1567,10 @@ megasas_build_io_fusion(struct megasas_instance *instance,
        io_request->EEDPFlags = 0;
        io_request->Control = 0;
        io_request->EEDPBlockSize = 0;
-       io_request->IoFlags = 0;
+       io_request->ChainOffset = 0;
        io_request->RaidContext.RAIDFlags = 0;
+       io_request->RaidContext.Type = 0;
+       io_request->RaidContext.nseg = 0;
 
        memcpy(io_request->CDB.CDB32, scp->cmnd, scp->cmd_len);
        /*
@@ -1612,7 +1668,6 @@ megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance,
 
        req_desc->Words = 0;
        cmd->request_desc = req_desc;
-       cmd->request_desc->Words = 0;
 
        if (megasas_build_io_fusion(instance, scmd, cmd)) {
                megasas_return_cmd_fusion(instance, cmd);
@@ -1647,7 +1702,7 @@ megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance,
  * Completes all commands that is in reply descriptor queue
  */
 int
-complete_cmd_fusion(struct megasas_instance *instance)
+complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex)
 {
        union MPI2_REPLY_DESCRIPTORS_UNION *desc;
        struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *reply_desc;
@@ -1667,7 +1722,9 @@ complete_cmd_fusion(struct megasas_instance *instance)
                return IRQ_HANDLED;
 
        desc = fusion->reply_frames_desc;
-       desc += fusion->last_reply_idx;
+       desc += ((MSIxIndex * fusion->reply_alloc_sz)/
+                sizeof(union MPI2_REPLY_DESCRIPTORS_UNION)) +
+               fusion->last_reply_idx[MSIxIndex];
 
        reply_desc = (struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *)desc;
 
@@ -1740,16 +1797,19 @@ complete_cmd_fusion(struct megasas_instance *instance)
                        break;
                }
 
-               fusion->last_reply_idx++;
-               if (fusion->last_reply_idx >= fusion->reply_q_depth)
-                       fusion->last_reply_idx = 0;
+               fusion->last_reply_idx[MSIxIndex]++;
+               if (fusion->last_reply_idx[MSIxIndex] >=
+                   fusion->reply_q_depth)
+                       fusion->last_reply_idx[MSIxIndex] = 0;
 
                desc->Words = ULLONG_MAX;
                num_completed++;
 
                /* Get the next reply descriptor */
-               if (!fusion->last_reply_idx)
-                       desc = fusion->reply_frames_desc;
+               if (!fusion->last_reply_idx[MSIxIndex])
+                       desc = fusion->reply_frames_desc +
+                               ((MSIxIndex * fusion->reply_alloc_sz)/
+                                sizeof(union MPI2_REPLY_DESCRIPTORS_UNION));
                else
                        desc++;
 
@@ -1769,7 +1829,7 @@ complete_cmd_fusion(struct megasas_instance *instance)
                return IRQ_NONE;
 
        wmb();
-       writel(fusion->last_reply_idx,
+       writel((MSIxIndex << 24) | fusion->last_reply_idx[MSIxIndex],
               &instance->reg_set->reply_post_host_index);
        megasas_check_and_restore_queue_depth(instance);
        return IRQ_HANDLED;
@@ -1787,6 +1847,9 @@ megasas_complete_cmd_dpc_fusion(unsigned long instance_addr)
        struct megasas_instance *instance =
                (struct megasas_instance *)instance_addr;
        unsigned long flags;
+       u32 count, MSIxIndex;
+
+       count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
 
        /* If we have already declared adapter dead, donot complete cmds */
        spin_lock_irqsave(&instance->hba_lock, flags);
@@ -1797,7 +1860,8 @@ megasas_complete_cmd_dpc_fusion(unsigned long instance_addr)
        spin_unlock_irqrestore(&instance->hba_lock, flags);
 
        spin_lock_irqsave(&instance->completion_lock, flags);
-       complete_cmd_fusion(instance);
+       for (MSIxIndex = 0 ; MSIxIndex < count; MSIxIndex++)
+               complete_cmd_fusion(instance, MSIxIndex);
        spin_unlock_irqrestore(&instance->completion_lock, flags);
 }
 
@@ -1806,20 +1870,24 @@ megasas_complete_cmd_dpc_fusion(unsigned long instance_addr)
  */
 irqreturn_t megasas_isr_fusion(int irq, void *devp)
 {
-       struct megasas_instance *instance = (struct megasas_instance *)devp;
+       struct megasas_irq_context *irq_context = devp;
+       struct megasas_instance *instance = irq_context->instance;
        u32 mfiStatus, fw_state;
 
-       if (!instance->msi_flag) {
+       if (!instance->msix_vectors) {
                mfiStatus = instance->instancet->clear_intr(instance->reg_set);
                if (!mfiStatus)
                        return IRQ_NONE;
        }
 
        /* If we are resetting, bail */
-       if (test_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags))
+       if (test_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags)) {
+               instance->instancet->clear_intr(instance->reg_set);
                return IRQ_HANDLED;
+       }
 
-       if (!complete_cmd_fusion(instance)) {
+       if (!complete_cmd_fusion(instance, irq_context->MSIxIndex)) {
+               instance->instancet->clear_intr(instance->reg_set);
                /* If we didn't complete any commands, check for FW fault */
                fw_state = instance->instancet->read_fw_status_reg(
                        instance->reg_set) & MFI_STATE_MASK;
@@ -1866,6 +1934,14 @@ build_mpt_mfi_pass_thru(struct megasas_instance *instance,
 
        fusion = instance->ctrl_context;
        io_req = cmd->io_request;
+
+       if (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) {
+               struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr_end =
+                       (struct MPI25_IEEE_SGE_CHAIN64 *)&io_req->SGL;
+               sgl_ptr_end += fusion->max_sge_in_main_msg - 1;
+               sgl_ptr_end->Flags = 0;
+       }
+
        mpi25_ieee_chain =
          (struct MPI25_IEEE_SGE_CHAIN64 *)&io_req->SGL.IeeeChain;
 
@@ -1928,15 +2004,12 @@ megasas_issue_dcmd_fusion(struct megasas_instance *instance,
                          struct megasas_cmd *cmd)
 {
        union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
-       union desc_value d_val;
 
        req_desc = build_mpt_cmd(instance, cmd);
        if (!req_desc) {
                printk(KERN_ERR "Couldn't issue MFI pass thru cmd\n");
                return;
        }
-       d_val.word = req_desc->Words;
-
        instance->instancet->fire_cmd(instance, req_desc->u.low,
                                      req_desc->u.high, instance->reg_set);
 }
@@ -2029,14 +2102,16 @@ out:
 
 void  megasas_reset_reply_desc(struct megasas_instance *instance)
 {
-       int i;
+       int i, count;
        struct fusion_context *fusion;
        union MPI2_REPLY_DESCRIPTORS_UNION *reply_desc;
 
        fusion = instance->ctrl_context;
-       fusion->last_reply_idx = 0;
+       count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
+       for (i = 0 ; i < count ; i++)
+               fusion->last_reply_idx[i] = 0;
        reply_desc = fusion->reply_frames_desc;
-       for (i = 0 ; i < fusion->reply_q_depth; i++, reply_desc++)
+       for (i = 0 ; i < fusion->reply_q_depth * count; i++, reply_desc++)
                reply_desc->Words = ULLONG_MAX;
 }
 
@@ -2057,8 +2132,7 @@ int megasas_reset_fusion(struct Scsi_Host *shost)
        if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) {
                printk(KERN_WARNING "megaraid_sas: Hardware critical error, "
                       "returning FAILED.\n");
-               retval = FAILED;
-               goto out;
+               return FAILED;
        }
 
        mutex_lock(&instance->reset_mutex);
@@ -2173,7 +2247,7 @@ int megasas_reset_fusion(struct Scsi_Host *shost)
                        }
 
                        /* Wait for FW to become ready */
-                       if (megasas_transition_to_ready(instance)) {
+                       if (megasas_transition_to_ready(instance, 1)) {
                                printk(KERN_WARNING "megaraid_sas: Failed to "
                                       "transition controller to ready.\n");
                                continue;
@@ -2186,6 +2260,8 @@ int megasas_reset_fusion(struct Scsi_Host *shost)
                                continue;
                        }
 
+                       clear_bit(MEGASAS_FUSION_IN_RESET,
+                                 &instance->reset_flags);
                        instance->instancet->enable_intr(instance->reg_set);
                        instance->adprecovery = MEGASAS_HBA_OPERATIONAL;
 
@@ -2247,6 +2323,7 @@ int megasas_reset_fusion(struct Scsi_Host *shost)
                megaraid_sas_kill_hba(instance);
                retval = FAILED;
        } else {
+               clear_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags);
                instance->instancet->enable_intr(instance->reg_set);
                instance->adprecovery = MEGASAS_HBA_OPERATIONAL;
        }
index 82b577a72c8bc162b7aa307d2bd55ce9681046b5..088c9f91da95fc4f2a0da32e427502dcde3ea267 100644 (file)
 #define HOST_DIAG_WRITE_ENABLE                     0x80
 #define HOST_DIAG_RESET_ADAPTER                            0x4
 #define MEGASAS_FUSION_MAX_RESET_TRIES             3
+#define MAX_MSIX_QUEUES_FUSION                     16
+
+/* Invader defines */
+#define MPI2_TYPE_CUDA                             0x2
+#define MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH   0x4000
+#define        MR_RL_FLAGS_GRANT_DESTINATION_CPU0          0x00
+#define        MR_RL_FLAGS_GRANT_DESTINATION_CPU1          0x10
+#define        MR_RL_FLAGS_GRANT_DESTINATION_CUDA          0x80
+#define MR_RL_FLAGS_SEQ_NUM_ENABLE                 0x8
 
 /* T10 PI defines */
 #define MR_PROT_INFO_TYPE_CONTROLLER                0x8
@@ -70,7 +79,7 @@ enum MR_RAID_FLAGS_IO_SUB_TYPE {
  */
 #define MEGASAS_REQ_DESCRIPT_FLAGS_LD_IO           0x7
 #define MEGASAS_REQ_DESCRIPT_FLAGS_MFA             0x1
-
+#define MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK        0x2
 #define MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT      1
 
 #define MEGASAS_FP_CMD_LEN     16
@@ -82,7 +91,9 @@ enum MR_RAID_FLAGS_IO_SUB_TYPE {
  */
 
 struct RAID_CONTEXT {
-       u16     resvd0;
+       u8      Type:4;
+       u8      nseg:4;
+       u8      resvd0;
        u16     timeoutValue;
        u8      regLockFlags;
        u8      resvd1;
@@ -527,7 +538,7 @@ struct MR_LD_RAID {
        u8      ldState;
        u8      regTypeReqOnWrite;
        u8      modFactor;
-       u8      reserved2[1];
+       u8      regTypeReqOnRead;
        u16     seqNum;
 
        struct {
@@ -663,7 +674,7 @@ struct fusion_context {
        union MPI2_REPLY_DESCRIPTORS_UNION *reply_frames_desc;
        struct dma_pool *reply_frames_desc_pool;
 
-       u16 last_reply_idx;
+       u16 last_reply_idx[MAX_MSIX_QUEUES_FUSION];
 
        u32 reply_q_depth;
        u32 request_alloc_sz;
index 6825772cfd6a16199ff8b8ab1f53e85ada6b62cb..81209ca87274d9ff090f5d08ae0174c0e13c6d7c 100644 (file)
@@ -833,25 +833,31 @@ union reply_descriptor {
 static irqreturn_t
 _base_interrupt(int irq, void *bus_id)
 {
+       struct adapter_reply_queue *reply_q = bus_id;
        union reply_descriptor rd;
        u32 completed_cmds;
        u8 request_desript_type;
        u16 smid;
        u8 cb_idx;
        u32 reply;
-       u8 msix_index;
-       struct MPT2SAS_ADAPTER *ioc = bus_id;
+       u8 msix_index = reply_q->msix_index;
+       struct MPT2SAS_ADAPTER *ioc = reply_q->ioc;
        Mpi2ReplyDescriptorsUnion_t *rpf;
        u8 rc;
 
        if (ioc->mask_interrupts)
                return IRQ_NONE;
 
-       rpf = &ioc->reply_post_free[ioc->reply_post_host_index];
+       if (!atomic_add_unless(&reply_q->busy, 1, 1))
+               return IRQ_NONE;
+
+       rpf = &reply_q->reply_post_free[reply_q->reply_post_host_index];
        request_desript_type = rpf->Default.ReplyFlags
             & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
-       if (request_desript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED)
+       if (request_desript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED) {
+               atomic_dec(&reply_q->busy);
                return IRQ_NONE;
+       }
 
        completed_cmds = 0;
        cb_idx = 0xFF;
@@ -860,9 +866,7 @@ _base_interrupt(int irq, void *bus_id)
                if (rd.u.low == UINT_MAX || rd.u.high == UINT_MAX)
                        goto out;
                reply = 0;
-               cb_idx = 0xFF;
                smid = le16_to_cpu(rpf->Default.DescriptorTypeDependent1);
-               msix_index = rpf->Default.MSIxIndex;
                if (request_desript_type ==
                    MPI2_RPY_DESCRIPT_FLAGS_ADDRESS_REPLY) {
                        reply = le32_to_cpu
@@ -906,31 +910,85 @@ _base_interrupt(int irq, void *bus_id)
  next:
 
                rpf->Words = cpu_to_le64(ULLONG_MAX);
-               ioc->reply_post_host_index = (ioc->reply_post_host_index ==
+               reply_q->reply_post_host_index =
+                   (reply_q->reply_post_host_index ==
                    (ioc->reply_post_queue_depth - 1)) ? 0 :
-                   ioc->reply_post_host_index + 1;
+                   reply_q->reply_post_host_index + 1;
                request_desript_type =
-                   ioc->reply_post_free[ioc->reply_post_host_index].Default.
-                   ReplyFlags & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
+                   reply_q->reply_post_free[reply_q->reply_post_host_index].
+                   Default.ReplyFlags & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
                completed_cmds++;
                if (request_desript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED)
                        goto out;
-               if (!ioc->reply_post_host_index)
-                       rpf = ioc->reply_post_free;
+               if (!reply_q->reply_post_host_index)
+                       rpf = reply_q->reply_post_free;
                else
                        rpf++;
        } while (1);
 
  out:
 
-       if (!completed_cmds)
+       if (!completed_cmds) {
+               atomic_dec(&reply_q->busy);
                return IRQ_NONE;
-
+       }
        wmb();
-       writel(ioc->reply_post_host_index, &ioc->chip->ReplyPostHostIndex);
+       if (ioc->is_warpdrive) {
+               writel(reply_q->reply_post_host_index,
+               ioc->reply_post_host_index[msix_index]);
+               atomic_dec(&reply_q->busy);
+               return IRQ_HANDLED;
+       }
+       writel(reply_q->reply_post_host_index | (msix_index <<
+           MPI2_RPHI_MSIX_INDEX_SHIFT), &ioc->chip->ReplyPostHostIndex);
+       atomic_dec(&reply_q->busy);
        return IRQ_HANDLED;
 }
 
+/**
+ * _base_is_controller_msix_enabled - is controller support muli-reply queues
+ * @ioc: per adapter object
+ *
+ */
+static inline int
+_base_is_controller_msix_enabled(struct MPT2SAS_ADAPTER *ioc)
+{
+       return (ioc->facts.IOCCapabilities &
+           MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX) && ioc->msix_enable;
+}
+
+/**
+ * mpt2sas_base_flush_reply_queues - flushing the MSIX reply queues
+ * @ioc: per adapter object
+ * Context: ISR conext
+ *
+ * Called when a Task Management request has completed. We want
+ * to flush the other reply queues so all the outstanding IO has been
+ * completed back to OS before we process the TM completetion.
+ *
+ * Return nothing.
+ */
+void
+mpt2sas_base_flush_reply_queues(struct MPT2SAS_ADAPTER *ioc)
+{
+       struct adapter_reply_queue *reply_q;
+
+       /* If MSIX capability is turned off
+        * then multi-queues are not enabled
+        */
+       if (!_base_is_controller_msix_enabled(ioc))
+               return;
+
+       list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
+               if (ioc->shost_recovery)
+                       return;
+               /* TMs are on msix_index == 0 */
+               if (reply_q->msix_index == 0)
+                       continue;
+               _base_interrupt(reply_q->vector, (void *)reply_q);
+       }
+}
+
 /**
  * mpt2sas_base_release_callback_handler - clear interrupt callback handler
  * @cb_idx: callback index
@@ -1081,74 +1139,171 @@ _base_config_dma_addressing(struct MPT2SAS_ADAPTER *ioc, struct pci_dev *pdev)
 }
 
 /**
- * _base_save_msix_table - backup msix vector table
+ * _base_check_enable_msix - checks MSIX capabable.
  * @ioc: per adapter object
  *
- * This address an errata where diag reset clears out the table
+ * Check to see if card is capable of MSIX, and set number
+ * of available msix vectors
  */
-static void
-_base_save_msix_table(struct MPT2SAS_ADAPTER *ioc)
+static int
+_base_check_enable_msix(struct MPT2SAS_ADAPTER *ioc)
 {
-       int i;
+       int base;
+       u16 message_control;
 
-       if (!ioc->msix_enable || ioc->msix_table_backup == NULL)
-               return;
 
-       for (i = 0; i < ioc->msix_vector_count; i++)
-               ioc->msix_table_backup[i] = ioc->msix_table[i];
+       base = pci_find_capability(ioc->pdev, PCI_CAP_ID_MSIX);
+       if (!base) {
+               dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "msix not "
+                   "supported\n", ioc->name));
+               return -EINVAL;
+       }
+
+       /* get msix vector count */
+       /* NUMA_IO not supported for older controllers */
+       if (ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2004 ||
+           ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2008 ||
+           ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_1 ||
+           ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_2 ||
+           ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_3 ||
+           ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2116_1 ||
+           ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2116_2)
+               ioc->msix_vector_count = 1;
+       else {
+               pci_read_config_word(ioc->pdev, base + 2, &message_control);
+               ioc->msix_vector_count = (message_control & 0x3FF) + 1;
+       }
+       dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "msix is supported, "
+           "vector_count(%d)\n", ioc->name, ioc->msix_vector_count));
+
+       return 0;
 }
 
 /**
- * _base_restore_msix_table - this restores the msix vector table
+ * _base_free_irq - free irq
  * @ioc: per adapter object
  *
+ * Freeing respective reply_queue from the list.
  */
 static void
-_base_restore_msix_table(struct MPT2SAS_ADAPTER *ioc)
+_base_free_irq(struct MPT2SAS_ADAPTER *ioc)
 {
-       int i;
+       struct adapter_reply_queue *reply_q, *next;
 
-       if (!ioc->msix_enable || ioc->msix_table_backup == NULL)
+       if (list_empty(&ioc->reply_queue_list))
                return;
 
-       for (i = 0; i < ioc->msix_vector_count; i++)
-               ioc->msix_table[i] = ioc->msix_table_backup[i];
+       list_for_each_entry_safe(reply_q, next, &ioc->reply_queue_list, list) {
+               list_del(&reply_q->list);
+               synchronize_irq(reply_q->vector);
+               free_irq(reply_q->vector, reply_q);
+               kfree(reply_q);
+       }
 }
 
 /**
- * _base_check_enable_msix - checks MSIX capabable.
+ * _base_request_irq - request irq
  * @ioc: per adapter object
+ * @index: msix index into vector table
+ * @vector: irq vector
  *
- * Check to see if card is capable of MSIX, and set number
- * of available msix vectors
+ * Inserting respective reply_queue into the list.
  */
 static int
-_base_check_enable_msix(struct MPT2SAS_ADAPTER *ioc)
+_base_request_irq(struct MPT2SAS_ADAPTER *ioc, u8 index, u32 vector)
 {
-       int base;
-       u16 message_control;
-       u32 msix_table_offset;
+       struct adapter_reply_queue *reply_q;
+       int r;
 
-       base = pci_find_capability(ioc->pdev, PCI_CAP_ID_MSIX);
-       if (!base) {
-               dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "msix not "
-                   "supported\n", ioc->name));
-               return -EINVAL;
+       reply_q =  kzalloc(sizeof(struct adapter_reply_queue), GFP_KERNEL);
+       if (!reply_q) {
+               printk(MPT2SAS_ERR_FMT "unable to allocate memory %d!\n",
+                   ioc->name, (int)sizeof(struct adapter_reply_queue));
+               return -ENOMEM;
+       }
+       reply_q->ioc = ioc;
+       reply_q->msix_index = index;
+       reply_q->vector = vector;
+       atomic_set(&reply_q->busy, 0);
+       if (ioc->msix_enable)
+               snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d-msix%d",
+                   MPT2SAS_DRIVER_NAME, ioc->id, index);
+       else
+               snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d",
+                   MPT2SAS_DRIVER_NAME, ioc->id);
+       r = request_irq(vector, _base_interrupt, IRQF_SHARED, reply_q->name,
+           reply_q);
+       if (r) {
+               printk(MPT2SAS_ERR_FMT "unable to allocate interrupt %d!\n",
+                   reply_q->name, vector);
+               kfree(reply_q);
+               return -EBUSY;
        }
 
-       /* get msix vector count */
-       pci_read_config_word(ioc->pdev, base + 2, &message_control);
-       ioc->msix_vector_count = (message_control & 0x3FF) + 1;
+       INIT_LIST_HEAD(&reply_q->list);
+       list_add_tail(&reply_q->list, &ioc->reply_queue_list);
+       return 0;
+}
 
-       /* get msix table  */
-       pci_read_config_dword(ioc->pdev, base + 4, &msix_table_offset);
-       msix_table_offset &= 0xFFFFFFF8;
-       ioc->msix_table = (u32 *)((void *)ioc->chip + msix_table_offset);
+/**
+ * _base_assign_reply_queues - assigning msix index for each cpu
+ * @ioc: per adapter object
+ *
+ * The enduser would need to set the affinity via /proc/irq/#/smp_affinity
+ *
+ * It would nice if we could call irq_set_affinity, however it is not
+ * an exported symbol
+ */
+static void
+_base_assign_reply_queues(struct MPT2SAS_ADAPTER *ioc)
+{
+       struct adapter_reply_queue *reply_q;
+       int cpu_id;
+       int cpu_grouping, loop, grouping, grouping_mod;
 
-       dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "msix is supported, "
-           "vector_count(%d), table_offset(0x%08x), table(%p)\n", ioc->name,
-           ioc->msix_vector_count, msix_table_offset, ioc->msix_table));
-       return 0;
+       if (!_base_is_controller_msix_enabled(ioc))
+               return;
+
+       memset(ioc->cpu_msix_table, 0, ioc->cpu_msix_table_sz);
+       /* when there are more cpus than available msix vectors,
+        * then group cpus togeather on same irq
+        */
+       if (ioc->cpu_count > ioc->msix_vector_count) {
+               grouping = ioc->cpu_count / ioc->msix_vector_count;
+               grouping_mod = ioc->cpu_count % ioc->msix_vector_count;
+               if (grouping < 2 || (grouping == 2 && !grouping_mod))
+                       cpu_grouping = 2;
+               else if (grouping < 4 || (grouping == 4 && !grouping_mod))
+                       cpu_grouping = 4;
+               else if (grouping < 8 || (grouping == 8 && !grouping_mod))
+                       cpu_grouping = 8;
+               else
+                       cpu_grouping = 16;
+       } else
+               cpu_grouping = 0;
+
+       loop = 0;
+       reply_q = list_entry(ioc->reply_queue_list.next,
+            struct adapter_reply_queue, list);
+       for_each_online_cpu(cpu_id) {
+               if (!cpu_grouping) {
+                       ioc->cpu_msix_table[cpu_id] = reply_q->msix_index;
+                       reply_q = list_entry(reply_q->list.next,
+                           struct adapter_reply_queue, list);
+               } else {
+                       if (loop < cpu_grouping) {
+                               ioc->cpu_msix_table[cpu_id] =
+                                       reply_q->msix_index;
+                               loop++;
+                       } else {
+                               reply_q = list_entry(reply_q->list.next,
+                                   struct adapter_reply_queue, list);
+                               ioc->cpu_msix_table[cpu_id] =
+                                       reply_q->msix_index;
+                               loop = 1;
+                       }
+               }
+       }
 }
 
 /**
@@ -1161,8 +1316,6 @@ _base_disable_msix(struct MPT2SAS_ADAPTER *ioc)
 {
        if (ioc->msix_enable) {
                pci_disable_msix(ioc->pdev);
-               kfree(ioc->msix_table_backup);
-               ioc->msix_table_backup = NULL;
                ioc->msix_enable = 0;
        }
 }
@@ -1175,10 +1328,13 @@ _base_disable_msix(struct MPT2SAS_ADAPTER *ioc)
 static int
 _base_enable_msix(struct MPT2SAS_ADAPTER *ioc)
 {
-       struct msix_entry entries;
+       struct msix_entry *entries, *a;
        int r;
+       int i;
        u8 try_msix = 0;
 
+       INIT_LIST_HEAD(&ioc->reply_queue_list);
+
        if (msix_disable == -1 || msix_disable == 0)
                try_msix = 1;
 
@@ -1188,51 +1344,48 @@ _base_enable_msix(struct MPT2SAS_ADAPTER *ioc)
        if (_base_check_enable_msix(ioc) != 0)
                goto try_ioapic;
 
-       ioc->msix_table_backup = kcalloc(ioc->msix_vector_count,
-           sizeof(u32), GFP_KERNEL);
-       if (!ioc->msix_table_backup) {
-               dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "allocation for "
-                   "msix_table_backup failed!!!\n", ioc->name));
+       ioc->reply_queue_count = min_t(u8, ioc->cpu_count,
+           ioc->msix_vector_count);
+
+       entries = kcalloc(ioc->reply_queue_count, sizeof(struct msix_entry),
+           GFP_KERNEL);
+       if (!entries) {
+               dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "kcalloc "
+                   "failed @ at %s:%d/%s() !!!\n", ioc->name, __FILE__,
+                   __LINE__, __func__));
                goto try_ioapic;
        }
 
-       memset(&entries, 0, sizeof(struct msix_entry));
-       r = pci_enable_msix(ioc->pdev, &entries, 1);
+       for (i = 0, a = entries; i < ioc->reply_queue_count; i++, a++)
+               a->entry = i;
+
+       r = pci_enable_msix(ioc->pdev, entries, ioc->reply_queue_count);
        if (r) {
                dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "pci_enable_msix "
                    "failed (r=%d) !!!\n", ioc->name, r));
+               kfree(entries);
                goto try_ioapic;
        }
 
-       r = request_irq(entries.vector, _base_interrupt, IRQF_SHARED,
-           ioc->name, ioc);
-       if (r) {
-               dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "unable to allocate "
-                   "interrupt %d !!!\n", ioc->name, entries.vector));
-               pci_disable_msix(ioc->pdev);
-               goto try_ioapic;
+       ioc->msix_enable = 1;
+       for (i = 0, a = entries; i < ioc->reply_queue_count; i++, a++) {
+               r = _base_request_irq(ioc, i, a->vector);
+               if (r) {
+                       _base_free_irq(ioc);
+                       _base_disable_msix(ioc);
+                       kfree(entries);
+                       goto try_ioapic;
+               }
        }
 
-       ioc->pci_irq = entries.vector;
-       ioc->msix_enable = 1;
+       kfree(entries);
        return 0;
 
 /* failback to io_apic interrupt routing */
  try_ioapic:
 
-       r = request_irq(ioc->pdev->irq, _base_interrupt, IRQF_SHARED,
-           ioc->name, ioc);
-       if (r) {
-               printk(MPT2SAS_ERR_FMT "unable to allocate interrupt %d!\n",
-                   ioc->name, ioc->pdev->irq);
-               r = -EBUSY;
-               goto out_fail;
-       }
+       r = _base_request_irq(ioc, 0, ioc->pdev->irq);
 
-       ioc->pci_irq = ioc->pdev->irq;
-       return 0;
-
- out_fail:
        return r;
 }
 
@@ -1251,6 +1404,7 @@ mpt2sas_base_map_resources(struct MPT2SAS_ADAPTER *ioc)
        int i, r = 0;
        u64 pio_chip = 0;
        u64 chip_phys = 0;
+       struct adapter_reply_queue *reply_q;
 
        dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n",
            ioc->name, __func__));
@@ -1313,9 +1467,11 @@ mpt2sas_base_map_resources(struct MPT2SAS_ADAPTER *ioc)
        if (r)
                goto out_fail;
 
-       printk(MPT2SAS_INFO_FMT "%s: IRQ %d\n",
-           ioc->name,  ((ioc->msix_enable) ? "PCI-MSI-X enabled" :
-           "IO-APIC enabled"), ioc->pci_irq);
+       list_for_each_entry(reply_q, &ioc->reply_queue_list, list)
+               printk(MPT2SAS_INFO_FMT "%s: IRQ %d\n",
+                   reply_q->name,  ((ioc->msix_enable) ? "PCI-MSI-X enabled" :
+                   "IO-APIC enabled"), reply_q->vector);
+
        printk(MPT2SAS_INFO_FMT "iomem(0x%016llx), mapped(0x%p), size(%d)\n",
            ioc->name, (unsigned long long)chip_phys, ioc->chip, memap_sz);
        printk(MPT2SAS_INFO_FMT "ioport(0x%016llx), size(%d)\n",
@@ -1330,7 +1486,6 @@ mpt2sas_base_map_resources(struct MPT2SAS_ADAPTER *ioc)
        if (ioc->chip_phys)
                iounmap(ioc->chip);
        ioc->chip_phys = 0;
-       ioc->pci_irq = -1;
        pci_release_selected_regions(ioc->pdev, ioc->bars);
        pci_disable_pcie_error_reporting(pdev);
        pci_disable_device(pdev);
@@ -1577,6 +1732,12 @@ static inline void _base_writeq(__u64 b, volatile void __iomem *addr,
 }
 #endif
 
+static inline u8
+_base_get_msix_index(struct MPT2SAS_ADAPTER *ioc)
+{
+       return ioc->cpu_msix_table[smp_processor_id()];
+}
+
 /**
  * mpt2sas_base_put_smid_scsi_io - send SCSI_IO request to firmware
  * @ioc: per adapter object
@@ -1593,7 +1754,7 @@ mpt2sas_base_put_smid_scsi_io(struct MPT2SAS_ADAPTER *ioc, u16 smid, u16 handle)
 
 
        descriptor.SCSIIO.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO;
-       descriptor.SCSIIO.MSIxIndex = 0; /* TODO */
+       descriptor.SCSIIO.MSIxIndex =  _base_get_msix_index(ioc);
        descriptor.SCSIIO.SMID = cpu_to_le16(smid);
        descriptor.SCSIIO.DevHandle = cpu_to_le16(handle);
        descriptor.SCSIIO.LMID = 0;
@@ -1617,7 +1778,7 @@ mpt2sas_base_put_smid_hi_priority(struct MPT2SAS_ADAPTER *ioc, u16 smid)
 
        descriptor.HighPriority.RequestFlags =
            MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY;
-       descriptor.HighPriority.MSIxIndex = 0; /* TODO */
+       descriptor.HighPriority.MSIxIndex =  0;
        descriptor.HighPriority.SMID = cpu_to_le16(smid);
        descriptor.HighPriority.LMID = 0;
        descriptor.HighPriority.Reserved1 = 0;
@@ -1639,7 +1800,7 @@ mpt2sas_base_put_smid_default(struct MPT2SAS_ADAPTER *ioc, u16 smid)
        u64 *request = (u64 *)&descriptor;
 
        descriptor.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
-       descriptor.Default.MSIxIndex = 0; /* TODO */
+       descriptor.Default.MSIxIndex =  _base_get_msix_index(ioc);
        descriptor.Default.SMID = cpu_to_le16(smid);
        descriptor.Default.LMID = 0;
        descriptor.Default.DescriptorTypeDependent = 0;
@@ -1664,7 +1825,7 @@ mpt2sas_base_put_smid_target_assist(struct MPT2SAS_ADAPTER *ioc, u16 smid,
 
        descriptor.SCSITarget.RequestFlags =
            MPI2_REQ_DESCRIPT_FLAGS_SCSI_TARGET;
-       descriptor.SCSITarget.MSIxIndex = 0; /* TODO */
+       descriptor.SCSITarget.MSIxIndex =  _base_get_msix_index(ioc);
        descriptor.SCSITarget.SMID = cpu_to_le16(smid);
        descriptor.SCSITarget.LMID = 0;
        descriptor.SCSITarget.IoIndex = cpu_to_le16(io_index);
@@ -2171,7 +2332,7 @@ _base_allocate_memory_pools(struct MPT2SAS_ADAPTER *ioc,  int sleep_flag)
        u16 max_sge_elements;
        u16 num_of_reply_frames;
        u16 chains_needed_per_io;
-       u32 sz, total_sz;
+       u32 sz, total_sz, reply_post_free_sz;
        u32 retry_sz;
        u16 max_request_credit;
        int i;
@@ -2498,7 +2659,12 @@ chain_done:
        total_sz += sz;
 
        /* reply post queue, 16 byte align */
-       sz = ioc->reply_post_queue_depth * sizeof(Mpi2DefaultReplyDescriptor_t);
+       reply_post_free_sz = ioc->reply_post_queue_depth *
+           sizeof(Mpi2DefaultReplyDescriptor_t);
+       if (_base_is_controller_msix_enabled(ioc))
+               sz = reply_post_free_sz * ioc->reply_queue_count;
+       else
+               sz = reply_post_free_sz;
        ioc->reply_post_free_dma_pool = pci_pool_create("reply_post_free pool",
            ioc->pdev, sz, 16, 0);
        if (!ioc->reply_post_free_dma_pool) {
@@ -3186,6 +3352,7 @@ _base_get_ioc_facts(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
        facts->MaxChainDepth = mpi_reply.MaxChainDepth;
        facts->WhoInit = mpi_reply.WhoInit;
        facts->NumberOfPorts = mpi_reply.NumberOfPorts;
+       facts->MaxMSIxVectors = mpi_reply.MaxMSIxVectors;
        facts->RequestCredit = le16_to_cpu(mpi_reply.RequestCredit);
        facts->MaxReplyDescriptorPostQueueDepth =
            le16_to_cpu(mpi_reply.MaxReplyDescriptorPostQueueDepth);
@@ -3243,7 +3410,8 @@ _base_send_ioc_init(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
        mpi_request.MsgVersion = cpu_to_le16(MPI2_VERSION);
        mpi_request.HeaderVersion = cpu_to_le16(MPI2_HEADER_VERSION);
 
-
+       if (_base_is_controller_msix_enabled(ioc))
+               mpi_request.HostMSIxVectors = ioc->reply_queue_count;
        mpi_request.SystemRequestFrameSize = cpu_to_le16(ioc->request_sz/4);
        mpi_request.ReplyDescriptorPostQueueDepth =
            cpu_to_le16(ioc->reply_post_queue_depth);
@@ -3512,9 +3680,6 @@ _base_diag_reset(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
        u32 hcb_size;
 
        printk(MPT2SAS_INFO_FMT "sending diag reset !!\n", ioc->name);
-
-       _base_save_msix_table(ioc);
-
        drsprintk(ioc, printk(MPT2SAS_INFO_FMT "clear interrupts\n",
            ioc->name));
 
@@ -3610,7 +3775,6 @@ _base_diag_reset(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
                goto out;
        }
 
-       _base_restore_msix_table(ioc);
        printk(MPT2SAS_INFO_FMT "diag reset: SUCCESS\n", ioc->name);
        return 0;
 
@@ -3691,6 +3855,9 @@ _base_make_ioc_operational(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
        u16 smid;
        struct _tr_list *delayed_tr, *delayed_tr_next;
        u8 hide_flag;
+       struct adapter_reply_queue *reply_q;
+       long reply_post_free;
+       u32 reply_post_free_sz;
 
        dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
            __func__));
@@ -3756,19 +3923,43 @@ _base_make_ioc_operational(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
            ioc->reply_sz)
                ioc->reply_free[i] = cpu_to_le32(reply_address);
 
+       /* initialize reply queues */
+       _base_assign_reply_queues(ioc);
+
        /* initialize Reply Post Free Queue */
-       for (i = 0; i < ioc->reply_post_queue_depth; i++)
-               ioc->reply_post_free[i].Words = cpu_to_le64(ULLONG_MAX);
+       reply_post_free = (long)ioc->reply_post_free;
+       reply_post_free_sz = ioc->reply_post_queue_depth *
+           sizeof(Mpi2DefaultReplyDescriptor_t);
+       list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
+               reply_q->reply_post_host_index = 0;
+               reply_q->reply_post_free = (Mpi2ReplyDescriptorsUnion_t *)
+                   reply_post_free;
+               for (i = 0; i < ioc->reply_post_queue_depth; i++)
+                       reply_q->reply_post_free[i].Words =
+                                                       cpu_to_le64(ULLONG_MAX);
+               if (!_base_is_controller_msix_enabled(ioc))
+                       goto skip_init_reply_post_free_queue;
+               reply_post_free += reply_post_free_sz;
+       }
+ skip_init_reply_post_free_queue:
 
        r = _base_send_ioc_init(ioc, sleep_flag);
        if (r)
                return r;
 
-       /* initialize the index's */
+       /* initialize reply free host index */
        ioc->reply_free_host_index = ioc->reply_free_queue_depth - 1;
-       ioc->reply_post_host_index = 0;
        writel(ioc->reply_free_host_index, &ioc->chip->ReplyFreeHostIndex);
-       writel(0, &ioc->chip->ReplyPostHostIndex);
+
+       /* initialize reply post host index */
+       list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
+               writel(reply_q->msix_index << MPI2_RPHI_MSIX_INDEX_SHIFT,
+                   &ioc->chip->ReplyPostHostIndex);
+               if (!_base_is_controller_msix_enabled(ioc))
+                       goto skip_init_reply_post_host_index;
+       }
+
+ skip_init_reply_post_host_index:
 
        _base_unmask_interrupts(ioc);
        r = _base_event_notification(ioc, sleep_flag);
@@ -3819,14 +4010,10 @@ mpt2sas_base_free_resources(struct MPT2SAS_ADAPTER *ioc)
        ioc->shost_recovery = 1;
        _base_make_ioc_ready(ioc, CAN_SLEEP, SOFT_RESET);
        ioc->shost_recovery = 0;
-       if (ioc->pci_irq) {
-               synchronize_irq(pdev->irq);
-               free_irq(ioc->pci_irq, ioc);
-       }
+       _base_free_irq(ioc);
        _base_disable_msix(ioc);
        if (ioc->chip_phys)
                iounmap(ioc->chip);
-       ioc->pci_irq = -1;
        ioc->chip_phys = 0;
        pci_release_selected_regions(ioc->pdev, ioc->bars);
        pci_disable_pcie_error_reporting(pdev);
@@ -3844,14 +4031,50 @@ int
 mpt2sas_base_attach(struct MPT2SAS_ADAPTER *ioc)
 {
        int r, i;
+       int cpu_id, last_cpu_id = 0;
 
        dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
            __func__));
 
+       /* setup cpu_msix_table */
+       ioc->cpu_count = num_online_cpus();
+       for_each_online_cpu(cpu_id)
+               last_cpu_id = cpu_id;
+       ioc->cpu_msix_table_sz = last_cpu_id + 1;
+       ioc->cpu_msix_table = kzalloc(ioc->cpu_msix_table_sz, GFP_KERNEL);
+       ioc->reply_queue_count = 1;
+       if (!ioc->cpu_msix_table) {
+               dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "allocation for "
+                   "cpu_msix_table failed!!!\n", ioc->name));
+               r = -ENOMEM;
+               goto out_free_resources;
+       }
+
+       if (ioc->is_warpdrive) {
+               ioc->reply_post_host_index = kcalloc(ioc->cpu_msix_table_sz,
+                   sizeof(resource_size_t *), GFP_KERNEL);
+               if (!ioc->reply_post_host_index) {
+                       dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "allocation "
+                               "for cpu_msix_table failed!!!\n", ioc->name));
+                       r = -ENOMEM;
+                       goto out_free_resources;
+               }
+       }
+
        r = mpt2sas_base_map_resources(ioc);
        if (r)
                return r;
 
+       if (ioc->is_warpdrive) {
+               ioc->reply_post_host_index[0] =
+                   (resource_size_t *)&ioc->chip->ReplyPostHostIndex;
+
+               for (i = 1; i < ioc->cpu_msix_table_sz; i++)
+                       ioc->reply_post_host_index[i] = (resource_size_t *)
+                       ((u8 *)&ioc->chip->Doorbell + (0x4000 + ((i - 1)
+                       * 4)));
+       }
+
        pci_set_drvdata(ioc->pdev, ioc->shost);
        r = _base_get_ioc_facts(ioc, CAN_SLEEP);
        if (r)
@@ -3972,6 +4195,9 @@ mpt2sas_base_attach(struct MPT2SAS_ADAPTER *ioc)
        mpt2sas_base_free_resources(ioc);
        _base_release_memory_pools(ioc);
        pci_set_drvdata(ioc->pdev, NULL);
+       kfree(ioc->cpu_msix_table);
+       if (ioc->is_warpdrive)
+               kfree(ioc->reply_post_host_index);
        kfree(ioc->pd_handles);
        kfree(ioc->tm_cmds.reply);
        kfree(ioc->transport_cmds.reply);
@@ -4009,6 +4235,9 @@ mpt2sas_base_detach(struct MPT2SAS_ADAPTER *ioc)
        mpt2sas_base_free_resources(ioc);
        _base_release_memory_pools(ioc);
        pci_set_drvdata(ioc->pdev, NULL);
+       kfree(ioc->cpu_msix_table);
+       if (ioc->is_warpdrive)
+               kfree(ioc->reply_post_host_index);
        kfree(ioc->pd_handles);
        kfree(ioc->pfacts);
        kfree(ioc->ctl_cmds.reply);
index 8d5be2120c63ea7b9f2bcbbf99def8bf44d01c60..59354dba68c0c7619b532f619bfbb019d1e554bb 100644 (file)
 #define MPT2SAS_DRIVER_NAME            "mpt2sas"
 #define MPT2SAS_AUTHOR "LSI Corporation <DL-MPTFusionLinux@lsi.com>"
 #define MPT2SAS_DESCRIPTION    "LSI MPT Fusion SAS 2.0 Device Driver"
-#define MPT2SAS_DRIVER_VERSION         "09.100.00.00"
+#define MPT2SAS_DRIVER_VERSION         "09.100.00.01"
 #define MPT2SAS_MAJOR_VERSION          09
 #define MPT2SAS_MINOR_VERSION          100
 #define MPT2SAS_BUILD_VERSION          00
-#define MPT2SAS_RELEASE_VERSION                00
+#define MPT2SAS_RELEASE_VERSION                01
 
 /*
  * Set MPT2SAS_SG_DEPTH value based on user input.
@@ -544,6 +544,28 @@ struct _tr_list {
 
 typedef void (*MPT_ADD_SGE)(void *paddr, u32 flags_length, dma_addr_t dma_addr);
 
+/**
+ * struct adapter_reply_queue - the reply queue struct
+ * @ioc: per adapter object
+ * @msix_index: msix index into vector table
+ * @vector: irq vector
+ * @reply_post_host_index: head index in the pool where FW completes IO
+ * @reply_post_free: reply post base virt address
+ * @name: the name registered to request_irq()
+ * @busy: isr is actively processing replies on another cpu
+ * @list: this list
+*/
+struct adapter_reply_queue {
+       struct MPT2SAS_ADAPTER  *ioc;
+       u8                      msix_index;
+       unsigned int            vector;
+       u32                     reply_post_host_index;
+       Mpi2ReplyDescriptorsUnion_t *reply_post_free;
+       char                    name[MPT_NAME_LENGTH];
+       atomic_t                busy;
+       struct list_head        list;
+};
+
 /* IOC Facts and Port Facts converted from little endian to cpu */
 union mpi2_version_union {
        MPI2_VERSION_STRUCT             Struct;
@@ -606,7 +628,7 @@ enum mutex_type {
  * @list: ioc_list
  * @shost: shost object
  * @id: unique adapter id
- * @pci_irq: irq number
+ * @cpu_count: number online cpus
  * @name: generic ioc string
  * @tmp_string: tmp string used for logging
  * @pdev: pci pdev object
@@ -636,8 +658,8 @@ enum mutex_type {
  * @wait_for_port_enable_to_complete:
  * @msix_enable: flag indicating msix is enabled
  * @msix_vector_count: number msix vectors
- * @msix_table: virt address to the msix table
- * @msix_table_backup: backup msix table
+ * @cpu_msix_table: table for mapping cpus to msix index
+ * @cpu_msix_table_sz: table size
  * @scsi_io_cb_idx: shost generated commands
  * @tm_cb_idx: task management commands
  * @scsih_cb_idx: scsih internal commands
@@ -728,7 +750,8 @@ enum mutex_type {
  * @reply_post_queue_depth: reply post queue depth
  * @reply_post_free: pool for reply post (64bit descriptor)
  * @reply_post_free_dma:
- * @reply_post_free_dma_pool:
+ * @reply_queue_count: number of reply queue's
+ * @reply_queue_list: link list contaning the reply queue info
  * @reply_post_host_index: head index in the pool where FW completes IO
  * @delayed_tr_list: target reset link list
  * @delayed_tr_volume_list: volume target reset link list
@@ -737,7 +760,7 @@ struct MPT2SAS_ADAPTER {
        struct list_head list;
        struct Scsi_Host *shost;
        u8              id;
-       u32             pci_irq;
+       int             cpu_count;
        char            name[MPT_NAME_LENGTH];
        char            tmp_string[MPT_STRING_LENGTH];
        struct pci_dev  *pdev;
@@ -779,8 +802,9 @@ struct MPT2SAS_ADAPTER {
 
        u8              msix_enable;
        u16             msix_vector_count;
-       u32             *msix_table;
-       u32             *msix_table_backup;
+       u8              *cpu_msix_table;
+       resource_size_t **reply_post_host_index;
+       u16             cpu_msix_table_sz;
        u32             ioc_reset_count;
 
        /* internal commands, callback index */
@@ -911,7 +935,8 @@ struct MPT2SAS_ADAPTER {
        Mpi2ReplyDescriptorsUnion_t *reply_post_free;
        dma_addr_t      reply_post_free_dma;
        struct dma_pool *reply_post_free_dma_pool;
-       u32             reply_post_host_index;
+       u8              reply_queue_count;
+       struct list_head reply_queue_list;
 
        struct list_head delayed_tr_list;
        struct list_head delayed_tr_volume_list;
@@ -955,6 +980,7 @@ void *mpt2sas_base_get_sense_buffer(struct MPT2SAS_ADAPTER *ioc, u16 smid);
 void mpt2sas_base_build_zero_len_sge(struct MPT2SAS_ADAPTER *ioc, void *paddr);
 __le32 mpt2sas_base_get_sense_buffer_dma(struct MPT2SAS_ADAPTER *ioc,
     u16 smid);
+void mpt2sas_base_flush_reply_queues(struct MPT2SAS_ADAPTER *ioc);
 
 /* hi-priority queue */
 u16 mpt2sas_base_get_smid_hpr(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx);
index 246d5fbc6e5a3c62a3264b3b81d58fce7e2fb1cf..9adb0133d6fb92cfa9e7eab6b3e71be4adddc645 100644 (file)
@@ -2704,6 +2704,33 @@ _ctl_ioc_reset_count_show(struct device *cdev, struct device_attribute *attr,
 static DEVICE_ATTR(ioc_reset_count, S_IRUGO,
     _ctl_ioc_reset_count_show, NULL);
 
+/**
+ * _ctl_ioc_reply_queue_count_show - number of reply queues
+ * @cdev - pointer to embedded class device
+ * @buf - the buffer returned
+ *
+ * This is number of reply queues
+ *
+ * A sysfs 'read-only' shost attribute.
+ */
+static ssize_t
+_ctl_ioc_reply_queue_count_show(struct device *cdev,
+        struct device_attribute *attr, char *buf)
+{
+       u8 reply_queue_count;
+       struct Scsi_Host *shost = class_to_shost(cdev);
+       struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
+
+       if ((ioc->facts.IOCCapabilities &
+           MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX) && ioc->msix_enable)
+               reply_queue_count = ioc->reply_queue_count;
+       else
+               reply_queue_count = 1;
+       return snprintf(buf, PAGE_SIZE, "%d\n", reply_queue_count);
+}
+static DEVICE_ATTR(reply_queue_count, S_IRUGO,
+        _ctl_ioc_reply_queue_count_show, NULL);
+
 struct DIAG_BUFFER_START {
        __le32 Size;
        __le32 DiagVersion;
@@ -2914,6 +2941,7 @@ struct device_attribute *mpt2sas_host_attrs[] = {
        &dev_attr_host_trace_buffer_size,
        &dev_attr_host_trace_buffer,
        &dev_attr_host_trace_buffer_enable,
+       &dev_attr_reply_queue_count,
        NULL,
 };
 
index 5202de3f3d3fd2ec547c1e9836252e7ac13e9d24..1da1aa1a11e2360d6275f86a90c3db9126ee9233 100644 (file)
@@ -2161,6 +2161,7 @@ _scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
                return 1;
        if (ioc->tm_cmds.smid != smid)
                return 1;
+       mpt2sas_base_flush_reply_queues(ioc);
        ioc->tm_cmds.status |= MPT2_CMD_COMPLETE;
        mpi_reply =  mpt2sas_base_get_reply_virt_addr(ioc, reply);
        if (mpi_reply) {
@@ -7353,6 +7354,7 @@ _scsih_remove(struct pci_dev *pdev)
        }
 
        sas_remove_host(shost);
+       mpt2sas_base_detach(ioc);
        list_del(&ioc->list);
        scsi_remove_host(shost);
        scsi_host_put(shost);
index 15c798026217d3b1f595a68bf9eb66e02b9f37a7..230732241aa2ff86b4de8ec6aa953351f4a1d9ed 100644 (file)
@@ -163,7 +163,7 @@ _transport_set_identify(struct MPT2SAS_ADAPTER *ioc, u16 handle,
                return -EIO;
        }
 
-       memset(identify, 0, sizeof(identify));
+       memset(identify, 0, sizeof(*identify));
        device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
 
        /* sas_address */
index 3501291618fdad97c2be6bf1fc44292bce240348..7e423e5ad5e103e53e9df4868ebc3ffee0608e08 100644 (file)
@@ -398,6 +398,16 @@ static int __devinit mvs_94xx_init(struct mvs_info *mvi)
        /* init phys */
        mvs_phy_hacks(mvi);
 
+       /* disable non data frame retry */
+       tmp = mvs_cr32(mvi, CMD_SAS_CTL1);
+       if ((revision == VANIR_A0_REV) ||
+               (revision == VANIR_B0_REV) ||
+               (revision == VANIR_C0_REV)) {
+               tmp &= ~0xffff;
+               tmp |= 0x007f;
+               mvs_cw32(mvi, CMD_SAS_CTL1, tmp);
+       }
+
        /* set LED blink when IO*/
        mw32(MVS_PA_VSR_ADDR, VSR_PHY_ACT_LED);
        tmp = mr32(MVS_PA_VSR_PORT);
@@ -500,6 +510,27 @@ static int __devinit mvs_94xx_init(struct mvs_info *mvi)
        tmp |= CINT_PHY_MASK;
        mw32(MVS_INT_MASK, tmp);
 
+       tmp = mvs_cr32(mvi, CMD_LINK_TIMER);
+       tmp |= 0xFFFF0000;
+       mvs_cw32(mvi, CMD_LINK_TIMER, tmp);
+
+       /* tune STP performance */
+       tmp = 0x003F003F;
+       mvs_cw32(mvi, CMD_PL_TIMER, tmp);
+
+       /* This can improve expander large block size seq write performance */
+       tmp = mvs_cr32(mvi, CMD_PORT_LAYER_TIMER1);
+       tmp |= 0xFFFF007F;
+       mvs_cw32(mvi, CMD_PORT_LAYER_TIMER1, tmp);
+
+       /* change the connection open-close behavior (bit 9)
+        * set bit8 to 1 for performance tuning */
+       tmp = mvs_cr32(mvi, CMD_SL_MODE0);
+       tmp |= 0x00000300;
+       /* set bit0 to 0 to enable retry for no_dest reject case */
+       tmp &= 0xFFFFFFFE;
+       mvs_cw32(mvi, CMD_SL_MODE0, tmp);
+
        /* Enable SRS interrupt */
        mw32(MVS_INT_MASK_SRS_0, 0xFFFF);
 
@@ -823,6 +854,10 @@ static void mvs_94xx_fix_phy_info(struct mvs_info *mvi, int i,
                phy->att_dev_info = PORT_DEV_STP_TRGT | 1;
        }
 
+       /* enable spin up bit */
+       mvs_write_port_cfg_addr(mvi, i, PHYR_PHY_STAT);
+       mvs_write_port_cfg_data(mvi, i, 0x04);
+
 }
 
 void mvs_94xx_phy_set_link_rate(struct mvs_info *mvi, u32 phy_id,
index dec7cadb7485229d9c2612f33faeb9a2303f10c0..f5451940d289c230904fb7b504832f3723488442 100644 (file)
@@ -387,6 +387,8 @@ enum sas_cmd_port_registers {
        CMD_SL_MODE0            = 0x1BC, /* SL Mode 0 */
        CMD_SL_MODE1            = 0x1C0, /* SL Mode 1 */
        CMD_PND_FIFO_CTL1       = 0x1C4, /* Pending FIFO Control 1 */
+       CMD_PORT_LAYER_TIMER1   = 0x1E0, /* Port Layer Timer 1 */
+       CMD_LINK_TIMER          = 0x1E4, /* Link Timer */
 };
 
 enum mvs_info_flags {
index 4e9af66fd1d3ecf2ac6e996f0a9c31c1e55de379..621b5e07275871808482316c7c3c0949ff7a30b7 100644 (file)
@@ -59,7 +59,7 @@ static struct scsi_host_template mvs_sht = {
        .name                   = DRV_NAME,
        .queuecommand           = sas_queuecommand,
        .target_alloc           = sas_target_alloc,
-       .slave_configure        = mvs_slave_configure,
+       .slave_configure        = sas_slave_configure,
        .slave_destroy          = sas_slave_destroy,
        .scan_finished          = mvs_scan_finished,
        .scan_start             = mvs_scan_start,
@@ -74,7 +74,7 @@ static struct scsi_host_template mvs_sht = {
        .use_clustering         = ENABLE_CLUSTERING,
        .eh_device_reset_handler = sas_eh_device_reset_handler,
        .eh_bus_reset_handler   = sas_eh_bus_reset_handler,
-       .slave_alloc            = mvs_slave_alloc,
+       .slave_alloc            = sas_slave_alloc,
        .target_destroy         = sas_target_destroy,
        .ioctl                  = sas_ioctl,
        .shost_attrs            = mvst_host_attrs,
@@ -705,6 +705,15 @@ static struct pci_device_id __devinitdata mvs_pci_table[] = {
        { PCI_VDEVICE(TTI, 0x2740), chip_9480 },
        { PCI_VDEVICE(TTI, 0x2744), chip_9480 },
        { PCI_VDEVICE(TTI, 0x2760), chip_9480 },
+       {
+               .vendor         = 0x1b4b,
+               .device         = 0x9480,
+               .subvendor      = PCI_ANY_ID,
+               .subdevice      = 0x9480,
+               .class          = 0,
+               .class_mask     = 0,
+               .driver_data    = chip_9480,
+       },
        {
                .vendor         = 0x1b4b,
                .device         = 0x9445,
index 4958fefff36559b79de06fa4a06fa67d1bc8d237..a4884a57cf79eac395c226c5ddcde895272779e9 100644 (file)
@@ -214,7 +214,7 @@ int mvs_phy_control(struct asd_sas_phy *sas_phy, enum phy_func func,
                break;
        case PHY_FUNC_RELEASE_SPINUP_HOLD:
        default:
-               rc = -EOPNOTSUPP;
+               rc = -ENOSYS;
        }
        msleep(200);
        return rc;
@@ -265,6 +265,12 @@ static void mvs_bytes_dmaed(struct mvs_info *mvi, int i)
                id->dev_type = phy->identify.device_type;
                id->initiator_bits = SAS_PROTOCOL_ALL;
                id->target_bits = phy->identify.target_port_protocols;
+
+               /* direct attached SAS device */
+               if (phy->att_dev_info & PORT_SSP_TRGT_MASK) {
+                       MVS_CHIP_DISP->write_port_cfg_addr(mvi, i, PHYR_PHY_STAT);
+                       MVS_CHIP_DISP->write_port_cfg_data(mvi, i, 0x00);
+               }
        } else if (phy->phy_type & PORT_TYPE_SATA) {
                /*Nothing*/
        }
@@ -276,36 +282,6 @@ static void mvs_bytes_dmaed(struct mvs_info *mvi, int i)
                                   PORTE_BYTES_DMAED);
 }
 
-int mvs_slave_alloc(struct scsi_device *scsi_dev)
-{
-       struct domain_device *dev = sdev_to_domain_dev(scsi_dev);
-       if (dev_is_sata(dev)) {
-               /* We don't need to rescan targets
-                * if REPORT_LUNS request is failed
-                */
-               if (scsi_dev->lun > 0)
-                       return -ENXIO;
-               scsi_dev->tagged_supported = 1;
-       }
-
-       return sas_slave_alloc(scsi_dev);
-}
-
-int mvs_slave_configure(struct scsi_device *sdev)
-{
-       struct domain_device *dev = sdev_to_domain_dev(sdev);
-       int ret = sas_slave_configure(sdev);
-
-       if (ret)
-               return ret;
-       if (!dev_is_sata(dev)) {
-               sas_change_queue_depth(sdev,
-                       MVS_QUEUE_SIZE,
-                       SCSI_QDEPTH_DEFAULT);
-       }
-       return 0;
-}
-
 void mvs_scan_start(struct Scsi_Host *shost)
 {
        int i, j;
@@ -426,7 +402,7 @@ static int mvs_task_prep_smp(struct mvs_info *mvi,
        /* generate open address frame hdr (first 12 bytes) */
        /* initiator, SMP, ftype 1h */
        buf_oaf[0] = (1 << 7) | (PROTOCOL_SMP << 4) | 0x01;
-       buf_oaf[1] = dev->linkrate & 0xf;
+       buf_oaf[1] = min(sas_port->linkrate, dev->linkrate) & 0xf;
        *(u16 *)(buf_oaf + 2) = 0xFFFF;         /* SAS SPEC */
        memcpy(buf_oaf + 4, dev->sas_addr, SAS_ADDR_SIZE);
 
@@ -571,7 +547,7 @@ static int mvs_task_prep_ata(struct mvs_info *mvi,
        /* generate open address frame hdr (first 12 bytes) */
        /* initiator, STP, ftype 1h */
        buf_oaf[0] = (1 << 7) | (PROTOCOL_STP << 4) | 0x1;
-       buf_oaf[1] = dev->linkrate & 0xf;
+       buf_oaf[1] = min(sas_port->linkrate, dev->linkrate) & 0xf;
        *(u16 *)(buf_oaf + 2) = cpu_to_be16(mvi_dev->device_id + 1);
        memcpy(buf_oaf + 4, dev->sas_addr, SAS_ADDR_SIZE);
 
@@ -679,7 +655,7 @@ static int mvs_task_prep_ssp(struct mvs_info *mvi,
        /* generate open address frame hdr (first 12 bytes) */
        /* initiator, SSP, ftype 1h */
        buf_oaf[0] = (1 << 7) | (PROTOCOL_SSP << 4) | 0x1;
-       buf_oaf[1] = dev->linkrate & 0xf;
+       buf_oaf[1] = min(sas_port->linkrate, dev->linkrate) & 0xf;
        *(u16 *)(buf_oaf + 2) = cpu_to_be16(mvi_dev->device_id + 1);
        memcpy(buf_oaf + 4, dev->sas_addr, SAS_ADDR_SIZE);
 
@@ -1241,6 +1217,12 @@ static void mvs_port_notify_formed(struct asd_sas_phy *sas_phy, int lock)
                port->wide_port_phymap = sas_port->phy_mask;
                mv_printk("set wide port phy map %x\n", sas_port->phy_mask);
                mvs_update_wideport(mvi, sas_phy->id);
+
+               /* direct attached SAS device */
+               if (phy->att_dev_info & PORT_SSP_TRGT_MASK) {
+                       MVS_CHIP_DISP->write_port_cfg_addr(mvi, i, PHYR_PHY_STAT);
+                       MVS_CHIP_DISP->write_port_cfg_data(mvi, i, 0x04);
+               }
        }
        if (lock)
                spin_unlock_irqrestore(&mvi->lock, flags);
@@ -1387,28 +1369,6 @@ void mvs_dev_gone(struct domain_device *dev)
        mvs_dev_gone_notify(dev);
 }
 
-static  struct sas_task *mvs_alloc_task(void)
-{
-       struct sas_task *task = kzalloc(sizeof(struct sas_task), GFP_KERNEL);
-
-       if (task) {
-               INIT_LIST_HEAD(&task->list);
-               spin_lock_init(&task->task_state_lock);
-               task->task_state_flags = SAS_TASK_STATE_PENDING;
-               init_timer(&task->timer);
-               init_completion(&task->completion);
-       }
-       return task;
-}
-
-static  void mvs_free_task(struct sas_task *task)
-{
-       if (task) {
-               BUG_ON(!list_empty(&task->list));
-               kfree(task);
-       }
-}
-
 static void mvs_task_done(struct sas_task *task)
 {
        if (!del_timer(&task->timer))
@@ -1432,7 +1392,7 @@ static int mvs_exec_internal_tmf_task(struct domain_device *dev,
        struct sas_task *task = NULL;
 
        for (retry = 0; retry < 3; retry++) {
-               task = mvs_alloc_task();
+               task = sas_alloc_task(GFP_KERNEL);
                if (!task)
                        return -ENOMEM;
 
@@ -1490,15 +1450,14 @@ static int mvs_exec_internal_tmf_task(struct domain_device *dev,
                                    SAS_ADDR(dev->sas_addr),
                                    task->task_status.resp,
                                    task->task_status.stat);
-                       mvs_free_task(task);
+                       sas_free_task(task);
                        task = NULL;
 
                }
        }
 ex_err:
        BUG_ON(retry == 3 && task != NULL);
-       if (task != NULL)
-               mvs_free_task(task);
+       sas_free_task(task);
        return res;
 }
 
index 44b474513223b657fa40d447be8823f56110062d..c04a4f5b5972b2ae405eddf6a3aab5ab82dafe2b 100644 (file)
@@ -46,7 +46,7 @@
 #include "mv_defs.h"
 
 #define DRV_NAME               "mvsas"
-#define DRV_VERSION            "0.8.2"
+#define DRV_VERSION            "0.8.16"
 #define MVS_ID_NOT_MAPPED      0x7f
 #define WIDE_PORT_MAX_PHY              4
 #define mv_printk(fmt, arg ...)        \
@@ -458,8 +458,6 @@ int mvs_phy_control(struct asd_sas_phy *sas_phy, enum phy_func func,
                        void *funcdata);
 void __devinit mvs_set_sas_addr(struct mvs_info *mvi, int port_id,
                                u32 off_lo, u32 off_hi, u64 sas_addr);
-int mvs_slave_alloc(struct scsi_device *scsi_dev);
-int mvs_slave_configure(struct scsi_device *sdev);
 void mvs_scan_start(struct Scsi_Host *shost);
 int mvs_scan_finished(struct Scsi_Host *shost, unsigned long time);
 int mvs_queue_command(struct sas_task *task, const int num,
diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
new file mode 100644 (file)
index 0000000..88cf1db
--- /dev/null
@@ -0,0 +1,2018 @@
+/*
+ * Marvell UMI driver
+ *
+ * Copyright 2011 Marvell. <jyli@marvell.com>
+ *
+ * This file is licensed under GPLv2.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; version 2 of the
+ * License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+*/
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/init.h>
+#include <linux/device.h>
+#include <linux/pci.h>
+#include <linux/list.h>
+#include <linux/spinlock.h>
+#include <linux/interrupt.h>
+#include <linux/delay.h>
+#include <linux/blkdev.h>
+#include <linux/io.h>
+#include <scsi/scsi.h>
+#include <scsi/scsi_cmnd.h>
+#include <scsi/scsi_host.h>
+#include <scsi/scsi_transport.h>
+#include <scsi/scsi_eh.h>
+#include <linux/uaccess.h>
+
+#include "mvumi.h"
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("jyli@marvell.com");
+MODULE_DESCRIPTION("Marvell UMI Driver");
+
+static DEFINE_PCI_DEVICE_TABLE(mvumi_pci_table) = {
+       { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_2, PCI_DEVICE_ID_MARVELL_MV9143) },
+       { 0 }
+};
+
+MODULE_DEVICE_TABLE(pci, mvumi_pci_table);
+
+static void tag_init(struct mvumi_tag *st, unsigned short size)
+{
+       unsigned short i;
+       BUG_ON(size != st->size);
+       st->top = size;
+       for (i = 0; i < size; i++)
+               st->stack[i] = size - 1 - i;
+}
+
+static unsigned short tag_get_one(struct mvumi_hba *mhba, struct mvumi_tag *st)
+{
+       BUG_ON(st->top <= 0);
+       return st->stack[--st->top];
+}
+
+static void tag_release_one(struct mvumi_hba *mhba, struct mvumi_tag *st,
+                                                       unsigned short tag)
+{
+       BUG_ON(st->top >= st->size);
+       st->stack[st->top++] = tag;
+}
+
+static bool tag_is_empty(struct mvumi_tag *st)
+{
+       if (st->top == 0)
+               return 1;
+       else
+               return 0;
+}
+
+static void mvumi_unmap_pci_addr(struct pci_dev *dev, void **addr_array)
+{
+       int i;
+
+       for (i = 0; i < MAX_BASE_ADDRESS; i++)
+               if ((pci_resource_flags(dev, i) & IORESOURCE_MEM) &&
+                                                               addr_array[i])
+                       pci_iounmap(dev, addr_array[i]);
+}
+
+static int mvumi_map_pci_addr(struct pci_dev *dev, void **addr_array)
+{
+       int i;
+
+       for (i = 0; i < MAX_BASE_ADDRESS; i++) {
+               if (pci_resource_flags(dev, i) & IORESOURCE_MEM) {
+                       addr_array[i] = pci_iomap(dev, i, 0);
+                       if (!addr_array[i]) {
+                               dev_err(&dev->dev, "failed to map Bar[%d]\n",
+                                                                       i);
+                               mvumi_unmap_pci_addr(dev, addr_array);
+                               return -ENOMEM;
+                       }
+               } else
+                       addr_array[i] = NULL;
+
+               dev_dbg(&dev->dev, "Bar %d : %p.\n", i, addr_array[i]);
+       }
+
+       return 0;
+}
+
+static struct mvumi_res *mvumi_alloc_mem_resource(struct mvumi_hba *mhba,
+                               enum resource_type type, unsigned int size)
+{
+       struct mvumi_res *res = kzalloc(sizeof(*res), GFP_KERNEL);
+
+       if (!res) {
+               dev_err(&mhba->pdev->dev,
+                       "Failed to allocate memory for resouce manager.\n");
+               return NULL;
+       }
+
+       switch (type) {
+       case RESOURCE_CACHED_MEMORY:
+               res->virt_addr = kzalloc(size, GFP_KERNEL);
+               if (!res->virt_addr) {
+                       dev_err(&mhba->pdev->dev,
+                               "unable to allocate memory,size = %d.\n", size);
+                       kfree(res);
+                       return NULL;
+               }
+               break;
+
+       case RESOURCE_UNCACHED_MEMORY:
+               size = round_up(size, 8);
+               res->virt_addr = pci_alloc_consistent(mhba->pdev, size,
+                                                       &res->bus_addr);
+               if (!res->virt_addr) {
+                       dev_err(&mhba->pdev->dev,
+                                       "unable to allocate consistent mem,"
+                                                       "size = %d.\n", size);
+                       kfree(res);
+                       return NULL;
+               }
+               memset(res->virt_addr, 0, size);
+               break;
+
+       default:
+               dev_err(&mhba->pdev->dev, "unknown resource type %d.\n", type);
+               kfree(res);
+               return NULL;
+       }
+
+       res->type = type;
+       res->size = size;
+       INIT_LIST_HEAD(&res->entry);
+       list_add_tail(&res->entry, &mhba->res_list);
+
+       return res;
+}
+
+static void mvumi_release_mem_resource(struct mvumi_hba *mhba)
+{
+       struct mvumi_res *res, *tmp;
+
+       list_for_each_entry_safe(res, tmp, &mhba->res_list, entry) {
+               switch (res->type) {
+               case RESOURCE_UNCACHED_MEMORY:
+                       pci_free_consistent(mhba->pdev, res->size,
+                                               res->virt_addr, res->bus_addr);
+                       break;
+               case RESOURCE_CACHED_MEMORY:
+                       kfree(res->virt_addr);
+                       break;
+               default:
+                       dev_err(&mhba->pdev->dev,
+                               "unknown resource type %d\n", res->type);
+                       break;
+               }
+               list_del(&res->entry);
+               kfree(res);
+       }
+       mhba->fw_flag &= ~MVUMI_FW_ALLOC;
+}
+
+/**
+ * mvumi_make_sgl -    Prepares  SGL
+ * @mhba:              Adapter soft state
+ * @scmd:              SCSI command from the mid-layer
+ * @sgl_p:             SGL to be filled in
+ * @sg_count           return the number of SG elements
+ *
+ * If successful, this function returns 0. otherwise, it returns -1.
+ */
+static int mvumi_make_sgl(struct mvumi_hba *mhba, struct scsi_cmnd *scmd,
+                                       void *sgl_p, unsigned char *sg_count)
+{
+       struct scatterlist *sg;
+       struct mvumi_sgl *m_sg = (struct mvumi_sgl *) sgl_p;
+       unsigned int i;
+       unsigned int sgnum = scsi_sg_count(scmd);
+       dma_addr_t busaddr;
+
+       if (sgnum) {
+               sg = scsi_sglist(scmd);
+               *sg_count = pci_map_sg(mhba->pdev, sg, sgnum,
+                               (int) scmd->sc_data_direction);
+               if (*sg_count > mhba->max_sge) {
+                       dev_err(&mhba->pdev->dev, "sg count[0x%x] is bigger "
+                                               "than max sg[0x%x].\n",
+                                               *sg_count, mhba->max_sge);
+                       return -1;
+               }
+               for (i = 0; i < *sg_count; i++) {
+                       busaddr = sg_dma_address(&sg[i]);
+                       m_sg->baseaddr_l = cpu_to_le32(lower_32_bits(busaddr));
+                       m_sg->baseaddr_h = cpu_to_le32(upper_32_bits(busaddr));
+                       m_sg->flags = 0;
+                       m_sg->size = cpu_to_le32(sg_dma_len(&sg[i]));
+                       if ((i + 1) == *sg_count)
+                               m_sg->flags |= SGD_EOT;
+
+                       m_sg++;
+               }
+       } else {
+               scmd->SCp.dma_handle = scsi_bufflen(scmd) ?
+                       pci_map_single(mhba->pdev, scsi_sglist(scmd),
+                               scsi_bufflen(scmd),
+                               (int) scmd->sc_data_direction)
+                       : 0;
+               busaddr = scmd->SCp.dma_handle;
+               m_sg->baseaddr_l = cpu_to_le32(lower_32_bits(busaddr));
+               m_sg->baseaddr_h = cpu_to_le32(upper_32_bits(busaddr));
+               m_sg->flags = SGD_EOT;
+               m_sg->size = cpu_to_le32(scsi_bufflen(scmd));
+               *sg_count = 1;
+       }
+
+       return 0;
+}
+
+static int mvumi_internal_cmd_sgl(struct mvumi_hba *mhba, struct mvumi_cmd *cmd,
+                                                       unsigned int size)
+{
+       struct mvumi_sgl *m_sg;
+       void *virt_addr;
+       dma_addr_t phy_addr;
+
+       if (size == 0)
+               return 0;
+
+       virt_addr = pci_alloc_consistent(mhba->pdev, size, &phy_addr);
+       if (!virt_addr)
+               return -1;
+
+       memset(virt_addr, 0, size);
+
+       m_sg = (struct mvumi_sgl *) &cmd->frame->payload[0];
+       cmd->frame->sg_counts = 1;
+       cmd->data_buf = virt_addr;
+
+       m_sg->baseaddr_l = cpu_to_le32(lower_32_bits(phy_addr));
+       m_sg->baseaddr_h = cpu_to_le32(upper_32_bits(phy_addr));
+       m_sg->flags = SGD_EOT;
+       m_sg->size = cpu_to_le32(size);
+
+       return 0;
+}
+
+static struct mvumi_cmd *mvumi_create_internal_cmd(struct mvumi_hba *mhba,
+                               unsigned int buf_size)
+{
+       struct mvumi_cmd *cmd;
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd) {
+               dev_err(&mhba->pdev->dev, "failed to create a internal cmd\n");
+               return NULL;
+       }
+       INIT_LIST_HEAD(&cmd->queue_pointer);
+
+       cmd->frame = kzalloc(mhba->ib_max_size, GFP_KERNEL);
+       if (!cmd->frame) {
+               dev_err(&mhba->pdev->dev, "failed to allocate memory for FW"
+                       " frame,size = %d.\n", mhba->ib_max_size);
+               kfree(cmd);
+               return NULL;
+       }
+
+       if (buf_size) {
+               if (mvumi_internal_cmd_sgl(mhba, cmd, buf_size)) {
+                       dev_err(&mhba->pdev->dev, "failed to allocate memory"
+                                               " for internal frame\n");
+                       kfree(cmd->frame);
+                       kfree(cmd);
+                       return NULL;
+               }
+       } else
+               cmd->frame->sg_counts = 0;
+
+       return cmd;
+}
+
+static void mvumi_delete_internal_cmd(struct mvumi_hba *mhba,
+                                               struct mvumi_cmd *cmd)
+{
+       struct mvumi_sgl *m_sg;
+       unsigned int size;
+       dma_addr_t phy_addr;
+
+       if (cmd && cmd->frame) {
+               if (cmd->frame->sg_counts) {
+                       m_sg = (struct mvumi_sgl *) &cmd->frame->payload[0];
+                       size = m_sg->size;
+
+                       phy_addr = (dma_addr_t) m_sg->baseaddr_l |
+                               (dma_addr_t) ((m_sg->baseaddr_h << 16) << 16);
+
+                       pci_free_consistent(mhba->pdev, size, cmd->data_buf,
+                                                               phy_addr);
+               }
+               kfree(cmd->frame);
+               kfree(cmd);
+       }
+}
+
+/**
+ * mvumi_get_cmd -     Get a command from the free pool
+ * @mhba:              Adapter soft state
+ *
+ * Returns a free command from the pool
+ */
+static struct mvumi_cmd *mvumi_get_cmd(struct mvumi_hba *mhba)
+{
+       struct mvumi_cmd *cmd = NULL;
+
+       if (likely(!list_empty(&mhba->cmd_pool))) {
+               cmd = list_entry((&mhba->cmd_pool)->next,
+                               struct mvumi_cmd, queue_pointer);
+               list_del_init(&cmd->queue_pointer);
+       } else
+               dev_warn(&mhba->pdev->dev, "command pool is empty!\n");
+
+       return cmd;
+}
+
+/**
+ * mvumi_return_cmd -  Return a cmd to free command pool
+ * @mhba:              Adapter soft state
+ * @cmd:               Command packet to be returned to free command pool
+ */
+static inline void mvumi_return_cmd(struct mvumi_hba *mhba,
+                                               struct mvumi_cmd *cmd)
+{
+       cmd->scmd = NULL;
+       list_add_tail(&cmd->queue_pointer, &mhba->cmd_pool);
+}
+
+/**
+ * mvumi_free_cmds -   Free all the cmds in the free cmd pool
+ * @mhba:              Adapter soft state
+ */
+static void mvumi_free_cmds(struct mvumi_hba *mhba)
+{
+       struct mvumi_cmd *cmd;
+
+       while (!list_empty(&mhba->cmd_pool)) {
+               cmd = list_first_entry(&mhba->cmd_pool, struct mvumi_cmd,
+                                                       queue_pointer);
+               list_del(&cmd->queue_pointer);
+               kfree(cmd->frame);
+               kfree(cmd);
+       }
+}
+
+/**
+ * mvumi_alloc_cmds -  Allocates the command packets
+ * @mhba:              Adapter soft state
+ *
+ */
+static int mvumi_alloc_cmds(struct mvumi_hba *mhba)
+{
+       int i;
+       struct mvumi_cmd *cmd;
+
+       for (i = 0; i < mhba->max_io; i++) {
+               cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+               if (!cmd)
+                       goto err_exit;
+
+               INIT_LIST_HEAD(&cmd->queue_pointer);
+               list_add_tail(&cmd->queue_pointer, &mhba->cmd_pool);
+               cmd->frame = kzalloc(mhba->ib_max_size, GFP_KERNEL);
+               if (!cmd->frame)
+                       goto err_exit;
+       }
+       return 0;
+
+err_exit:
+       dev_err(&mhba->pdev->dev,
+                       "failed to allocate memory for cmd[0x%x].\n", i);
+       while (!list_empty(&mhba->cmd_pool)) {
+               cmd = list_first_entry(&mhba->cmd_pool, struct mvumi_cmd,
+                                               queue_pointer);
+               list_del(&cmd->queue_pointer);
+               kfree(cmd->frame);
+               kfree(cmd);
+       }
+       return -ENOMEM;
+}
+
+static int mvumi_get_ib_list_entry(struct mvumi_hba *mhba, void **ib_entry)
+{
+       unsigned int ib_rp_reg, cur_ib_entry;
+
+       if (atomic_read(&mhba->fw_outstanding) >= mhba->max_io) {
+               dev_warn(&mhba->pdev->dev, "firmware io overflow.\n");
+               return -1;
+       }
+       ib_rp_reg = ioread32(mhba->mmio + CLA_INB_READ_POINTER);
+
+       if (unlikely(((ib_rp_reg & CL_SLOT_NUM_MASK) ==
+                       (mhba->ib_cur_slot & CL_SLOT_NUM_MASK)) &&
+                       ((ib_rp_reg & CL_POINTER_TOGGLE) !=
+                       (mhba->ib_cur_slot & CL_POINTER_TOGGLE)))) {
+               dev_warn(&mhba->pdev->dev, "no free slot to use.\n");
+               return -1;
+       }
+
+       cur_ib_entry = mhba->ib_cur_slot & CL_SLOT_NUM_MASK;
+       cur_ib_entry++;
+       if (cur_ib_entry >= mhba->list_num_io) {
+               cur_ib_entry -= mhba->list_num_io;
+               mhba->ib_cur_slot ^= CL_POINTER_TOGGLE;
+       }
+       mhba->ib_cur_slot &= ~CL_SLOT_NUM_MASK;
+       mhba->ib_cur_slot |= (cur_ib_entry & CL_SLOT_NUM_MASK);
+       *ib_entry = mhba->ib_list + cur_ib_entry * mhba->ib_max_size;
+       atomic_inc(&mhba->fw_outstanding);
+
+       return 0;
+}
+
+static void mvumi_send_ib_list_entry(struct mvumi_hba *mhba)
+{
+       iowrite32(0xfff, mhba->ib_shadow);
+       iowrite32(mhba->ib_cur_slot, mhba->mmio + CLA_INB_WRITE_POINTER);
+}
+
+static char mvumi_check_ob_frame(struct mvumi_hba *mhba,
+               unsigned int cur_obf, struct mvumi_rsp_frame *p_outb_frame)
+{
+       unsigned short tag, request_id;
+
+       udelay(1);
+       p_outb_frame = mhba->ob_list + cur_obf * mhba->ob_max_size;
+       request_id = p_outb_frame->request_id;
+       tag = p_outb_frame->tag;
+       if (tag > mhba->tag_pool.size) {
+               dev_err(&mhba->pdev->dev, "ob frame data error\n");
+               return -1;
+       }
+       if (mhba->tag_cmd[tag] == NULL) {
+               dev_err(&mhba->pdev->dev, "tag[0x%x] with NO command\n", tag);
+               return -1;
+       } else if (mhba->tag_cmd[tag]->request_id != request_id &&
+                                               mhba->request_id_enabled) {
+                       dev_err(&mhba->pdev->dev, "request ID from FW:0x%x,"
+                                       "cmd request ID:0x%x\n", request_id,
+                                       mhba->tag_cmd[tag]->request_id);
+                       return -1;
+       }
+
+       return 0;
+}
+
+static void mvumi_receive_ob_list_entry(struct mvumi_hba *mhba)
+{
+       unsigned int ob_write_reg, ob_write_shadow_reg;
+       unsigned int cur_obf, assign_obf_end, i;
+       struct mvumi_ob_data *ob_data;
+       struct mvumi_rsp_frame *p_outb_frame;
+
+       do {
+               ob_write_reg = ioread32(mhba->mmio + CLA_OUTB_COPY_POINTER);
+               ob_write_shadow_reg = ioread32(mhba->ob_shadow);
+       } while ((ob_write_reg & CL_SLOT_NUM_MASK) != ob_write_shadow_reg);
+
+       cur_obf = mhba->ob_cur_slot & CL_SLOT_NUM_MASK;
+       assign_obf_end = ob_write_reg & CL_SLOT_NUM_MASK;
+
+       if ((ob_write_reg & CL_POINTER_TOGGLE) !=
+                               (mhba->ob_cur_slot & CL_POINTER_TOGGLE)) {
+               assign_obf_end += mhba->list_num_io;
+       }
+
+       for (i = (assign_obf_end - cur_obf); i != 0; i--) {
+               cur_obf++;
+               if (cur_obf >= mhba->list_num_io) {
+                       cur_obf -= mhba->list_num_io;
+                       mhba->ob_cur_slot ^= CL_POINTER_TOGGLE;
+               }
+
+               p_outb_frame = mhba->ob_list + cur_obf * mhba->ob_max_size;
+
+               /* Copy pointer may point to entry in outbound list
+               *  before entry has valid data
+               */
+               if (unlikely(p_outb_frame->tag > mhba->tag_pool.size ||
+                       mhba->tag_cmd[p_outb_frame->tag] == NULL ||
+                       p_outb_frame->request_id !=
+                               mhba->tag_cmd[p_outb_frame->tag]->request_id))
+                       if (mvumi_check_ob_frame(mhba, cur_obf, p_outb_frame))
+                               continue;
+
+               if (!list_empty(&mhba->ob_data_list)) {
+                       ob_data = (struct mvumi_ob_data *)
+                               list_first_entry(&mhba->ob_data_list,
+                                       struct mvumi_ob_data, list);
+                       list_del_init(&ob_data->list);
+               } else {
+                       ob_data = NULL;
+                       if (cur_obf == 0) {
+                               cur_obf = mhba->list_num_io - 1;
+                               mhba->ob_cur_slot ^= CL_POINTER_TOGGLE;
+                       } else
+                               cur_obf -= 1;
+                       break;
+               }
+
+               memcpy(ob_data->data, p_outb_frame, mhba->ob_max_size);
+               p_outb_frame->tag = 0xff;
+
+               list_add_tail(&ob_data->list, &mhba->free_ob_list);
+       }
+       mhba->ob_cur_slot &= ~CL_SLOT_NUM_MASK;
+       mhba->ob_cur_slot |= (cur_obf & CL_SLOT_NUM_MASK);
+       iowrite32(mhba->ob_cur_slot, mhba->mmio + CLA_OUTB_READ_POINTER);
+}
+
+static void mvumi_reset(void *regs)
+{
+       iowrite32(0, regs + CPU_ENPOINTA_MASK_REG);
+       if (ioread32(regs + CPU_ARM_TO_PCIEA_MSG1) != HANDSHAKE_DONESTATE)
+               return;
+
+       iowrite32(DRBL_SOFT_RESET, regs + CPU_PCIEA_TO_ARM_DRBL_REG);
+}
+
+static unsigned char mvumi_start(struct mvumi_hba *mhba);
+
+static int mvumi_wait_for_outstanding(struct mvumi_hba *mhba)
+{
+       mhba->fw_state = FW_STATE_ABORT;
+       mvumi_reset(mhba->mmio);
+
+       if (mvumi_start(mhba))
+               return FAILED;
+       else
+               return SUCCESS;
+}
+
+static int mvumi_host_reset(struct scsi_cmnd *scmd)
+{
+       struct mvumi_hba *mhba;
+
+       mhba = (struct mvumi_hba *) scmd->device->host->hostdata;
+
+       scmd_printk(KERN_NOTICE, scmd, "RESET -%ld cmd=%x retries=%x\n",
+                       scmd->serial_number, scmd->cmnd[0], scmd->retries);
+
+       return mvumi_wait_for_outstanding(mhba);
+}
+
+static int mvumi_issue_blocked_cmd(struct mvumi_hba *mhba,
+                                               struct mvumi_cmd *cmd)
+{
+       unsigned long flags;
+
+       cmd->cmd_status = REQ_STATUS_PENDING;
+
+       if (atomic_read(&cmd->sync_cmd)) {
+               dev_err(&mhba->pdev->dev,
+                       "last blocked cmd not finished, sync_cmd = %d\n",
+                                               atomic_read(&cmd->sync_cmd));
+               BUG_ON(1);
+               return -1;
+       }
+       atomic_inc(&cmd->sync_cmd);
+       spin_lock_irqsave(mhba->shost->host_lock, flags);
+       mhba->instancet->fire_cmd(mhba, cmd);
+       spin_unlock_irqrestore(mhba->shost->host_lock, flags);
+
+       wait_event_timeout(mhba->int_cmd_wait_q,
+               (cmd->cmd_status != REQ_STATUS_PENDING),
+               MVUMI_INTERNAL_CMD_WAIT_TIME * HZ);
+
+       /* command timeout */
+       if (atomic_read(&cmd->sync_cmd)) {
+               spin_lock_irqsave(mhba->shost->host_lock, flags);
+               atomic_dec(&cmd->sync_cmd);
+               if (mhba->tag_cmd[cmd->frame->tag]) {
+                       mhba->tag_cmd[cmd->frame->tag] = 0;
+                       dev_warn(&mhba->pdev->dev, "TIMEOUT:release tag [%d]\n",
+                                                       cmd->frame->tag);
+                       tag_release_one(mhba, &mhba->tag_pool, cmd->frame->tag);
+               }
+               if (!list_empty(&cmd->queue_pointer)) {
+                       dev_warn(&mhba->pdev->dev,
+                               "TIMEOUT:A internal command doesn't send!\n");
+                       list_del_init(&cmd->queue_pointer);
+               } else
+                       atomic_dec(&mhba->fw_outstanding);
+
+               spin_unlock_irqrestore(mhba->shost->host_lock, flags);
+       }
+       return 0;
+}
+
+static void mvumi_release_fw(struct mvumi_hba *mhba)
+{
+       mvumi_free_cmds(mhba);
+       mvumi_release_mem_resource(mhba);
+       mvumi_unmap_pci_addr(mhba->pdev, mhba->base_addr);
+       kfree(mhba->handshake_page);
+       pci_release_regions(mhba->pdev);
+}
+
+static unsigned char mvumi_flush_cache(struct mvumi_hba *mhba)
+{
+       struct mvumi_cmd *cmd;
+       struct mvumi_msg_frame *frame;
+       unsigned char device_id, retry = 0;
+       unsigned char bitcount = sizeof(unsigned char) * 8;
+
+       for (device_id = 0; device_id < mhba->max_target_id; device_id++) {
+               if (!(mhba->target_map[device_id / bitcount] &
+                               (1 << (device_id % bitcount))))
+                       continue;
+get_cmd:       cmd = mvumi_create_internal_cmd(mhba, 0);
+               if (!cmd) {
+                       if (retry++ >= 5) {
+                               dev_err(&mhba->pdev->dev, "failed to get memory"
+                                       " for internal flush cache cmd for "
+                                       "device %d", device_id);
+                               retry = 0;
+                               continue;
+                       } else
+                               goto get_cmd;
+               }
+               cmd->scmd = NULL;
+               cmd->cmd_status = REQ_STATUS_PENDING;
+               atomic_set(&cmd->sync_cmd, 0);
+               frame = cmd->frame;
+               frame->req_function = CL_FUN_SCSI_CMD;
+               frame->device_id = device_id;
+               frame->cmd_flag = CMD_FLAG_NON_DATA;
+               frame->data_transfer_length = 0;
+               frame->cdb_length = MAX_COMMAND_SIZE;
+               memset(frame->cdb, 0, MAX_COMMAND_SIZE);
+               frame->cdb[0] = SCSI_CMD_MARVELL_SPECIFIC;
+               frame->cdb[2] = CDB_CORE_SHUTDOWN;
+
+               mvumi_issue_blocked_cmd(mhba, cmd);
+               if (cmd->cmd_status != SAM_STAT_GOOD) {
+                       dev_err(&mhba->pdev->dev,
+                               "device %d flush cache failed, status=0x%x.\n",
+                               device_id, cmd->cmd_status);
+               }
+
+               mvumi_delete_internal_cmd(mhba, cmd);
+       }
+       return 0;
+}
+
+static unsigned char
+mvumi_calculate_checksum(struct mvumi_hs_header *p_header,
+                                                       unsigned short len)
+{
+       unsigned char *ptr;
+       unsigned char ret = 0, i;
+
+       ptr = (unsigned char *) p_header->frame_content;
+       for (i = 0; i < len; i++) {
+               ret ^= *ptr;
+               ptr++;
+       }
+
+       return ret;
+}
+
+void mvumi_hs_build_page(struct mvumi_hba *mhba,
+                               struct mvumi_hs_header *hs_header)
+{
+       struct mvumi_hs_page2 *hs_page2;
+       struct mvumi_hs_page4 *hs_page4;
+       struct mvumi_hs_page3 *hs_page3;
+       struct timeval time;
+       unsigned int local_time;
+
+       switch (hs_header->page_code) {
+       case HS_PAGE_HOST_INFO:
+               hs_page2 = (struct mvumi_hs_page2 *) hs_header;
+               hs_header->frame_length = sizeof(*hs_page2) - 4;
+               memset(hs_header->frame_content, 0, hs_header->frame_length);
+               hs_page2->host_type = 3; /* 3 mean linux*/
+               hs_page2->host_ver.ver_major = VER_MAJOR;
+               hs_page2->host_ver.ver_minor = VER_MINOR;
+               hs_page2->host_ver.ver_oem = VER_OEM;
+               hs_page2->host_ver.ver_build = VER_BUILD;
+               hs_page2->system_io_bus = 0;
+               hs_page2->slot_number = 0;
+               hs_page2->intr_level = 0;
+               hs_page2->intr_vector = 0;
+               do_gettimeofday(&time);
+               local_time = (unsigned int) (time.tv_sec -
+                                               (sys_tz.tz_minuteswest * 60));
+               hs_page2->seconds_since1970 = local_time;
+               hs_header->checksum = mvumi_calculate_checksum(hs_header,
+                                               hs_header->frame_length);
+               break;
+
+       case HS_PAGE_FIRM_CTL:
+               hs_page3 = (struct mvumi_hs_page3 *) hs_header;
+               hs_header->frame_length = sizeof(*hs_page3) - 4;
+               memset(hs_header->frame_content, 0, hs_header->frame_length);
+               hs_header->checksum = mvumi_calculate_checksum(hs_header,
+                                               hs_header->frame_length);
+               break;
+
+       case HS_PAGE_CL_INFO:
+               hs_page4 = (struct mvumi_hs_page4 *) hs_header;
+               hs_header->frame_length = sizeof(*hs_page4) - 4;
+               memset(hs_header->frame_content, 0, hs_header->frame_length);
+               hs_page4->ib_baseaddr_l = lower_32_bits(mhba->ib_list_phys);
+               hs_page4->ib_baseaddr_h = upper_32_bits(mhba->ib_list_phys);
+
+               hs_page4->ob_baseaddr_l = lower_32_bits(mhba->ob_list_phys);
+               hs_page4->ob_baseaddr_h = upper_32_bits(mhba->ob_list_phys);
+               hs_page4->ib_entry_size = mhba->ib_max_size_setting;
+               hs_page4->ob_entry_size = mhba->ob_max_size_setting;
+               hs_page4->ob_depth = mhba->list_num_io;
+               hs_page4->ib_depth = mhba->list_num_io;
+               hs_header->checksum = mvumi_calculate_checksum(hs_header,
+                                               hs_header->frame_length);
+               break;
+
+       default:
+               dev_err(&mhba->pdev->dev, "cannot build page, code[0x%x]\n",
+                       hs_header->page_code);
+               break;
+       }
+}
+
+/**
+ * mvumi_init_data -   Initialize requested date for FW
+ * @mhba:                      Adapter soft state
+ */
+static int mvumi_init_data(struct mvumi_hba *mhba)
+{
+       struct mvumi_ob_data *ob_pool;
+       struct mvumi_res *res_mgnt;
+       unsigned int tmp_size, offset, i;
+       void *virmem, *v;
+       dma_addr_t p;
+
+       if (mhba->fw_flag & MVUMI_FW_ALLOC)
+               return 0;
+
+       tmp_size = mhba->ib_max_size * mhba->max_io;
+       tmp_size += 128 + mhba->ob_max_size * mhba->max_io;
+       tmp_size += 8 + sizeof(u32) + 16;
+
+       res_mgnt = mvumi_alloc_mem_resource(mhba,
+                                       RESOURCE_UNCACHED_MEMORY, tmp_size);
+       if (!res_mgnt) {
+               dev_err(&mhba->pdev->dev,
+                       "failed to allocate memory for inbound list\n");
+               goto fail_alloc_dma_buf;
+       }
+
+       p = res_mgnt->bus_addr;
+       v = res_mgnt->virt_addr;
+       /* ib_list */
+       offset = round_up(p, 128) - p;
+       p += offset;
+       v += offset;
+       mhba->ib_list = v;
+       mhba->ib_list_phys = p;
+       v += mhba->ib_max_size * mhba->max_io;
+       p += mhba->ib_max_size * mhba->max_io;
+       /* ib shadow */
+       offset = round_up(p, 8) - p;
+       p += offset;
+       v += offset;
+       mhba->ib_shadow = v;
+       mhba->ib_shadow_phys = p;
+       p += sizeof(u32);
+       v += sizeof(u32);
+       /* ob shadow */
+       offset = round_up(p, 8) - p;
+       p += offset;
+       v += offset;
+       mhba->ob_shadow = v;
+       mhba->ob_shadow_phys = p;
+       p += 8;
+       v += 8;
+
+       /* ob list */
+       offset = round_up(p, 128) - p;
+       p += offset;
+       v += offset;
+
+       mhba->ob_list = v;
+       mhba->ob_list_phys = p;
+
+       /* ob data pool */
+       tmp_size = mhba->max_io * (mhba->ob_max_size + sizeof(*ob_pool));
+       tmp_size = round_up(tmp_size, 8);
+
+       res_mgnt = mvumi_alloc_mem_resource(mhba,
+                               RESOURCE_CACHED_MEMORY, tmp_size);
+       if (!res_mgnt) {
+               dev_err(&mhba->pdev->dev,
+                       "failed to allocate memory for outbound data buffer\n");
+               goto fail_alloc_dma_buf;
+       }
+       virmem = res_mgnt->virt_addr;
+
+       for (i = mhba->max_io; i != 0; i--) {
+               ob_pool = (struct mvumi_ob_data *) virmem;
+               list_add_tail(&ob_pool->list, &mhba->ob_data_list);
+               virmem += mhba->ob_max_size + sizeof(*ob_pool);
+       }
+
+       tmp_size = sizeof(unsigned short) * mhba->max_io +
+                               sizeof(struct mvumi_cmd *) * mhba->max_io;
+       tmp_size += round_up(mhba->max_target_id, sizeof(unsigned char) * 8) /
+                                               (sizeof(unsigned char) * 8);
+
+       res_mgnt = mvumi_alloc_mem_resource(mhba,
+                               RESOURCE_CACHED_MEMORY, tmp_size);
+       if (!res_mgnt) {
+               dev_err(&mhba->pdev->dev,
+                       "failed to allocate memory for tag and target map\n");
+               goto fail_alloc_dma_buf;
+       }
+
+       virmem = res_mgnt->virt_addr;
+       mhba->tag_pool.stack = virmem;
+       mhba->tag_pool.size = mhba->max_io;
+       tag_init(&mhba->tag_pool, mhba->max_io);
+       virmem += sizeof(unsigned short) * mhba->max_io;
+
+       mhba->tag_cmd = virmem;
+       virmem += sizeof(struct mvumi_cmd *) * mhba->max_io;
+
+       mhba->target_map = virmem;
+
+       mhba->fw_flag |= MVUMI_FW_ALLOC;
+       return 0;
+
+fail_alloc_dma_buf:
+       mvumi_release_mem_resource(mhba);
+       return -1;
+}
+
+static int mvumi_hs_process_page(struct mvumi_hba *mhba,
+                               struct mvumi_hs_header *hs_header)
+{
+       struct mvumi_hs_page1 *hs_page1;
+       unsigned char page_checksum;
+
+       page_checksum = mvumi_calculate_checksum(hs_header,
+                                               hs_header->frame_length);
+       if (page_checksum != hs_header->checksum) {
+               dev_err(&mhba->pdev->dev, "checksum error\n");
+               return -1;
+       }
+
+       switch (hs_header->page_code) {
+       case HS_PAGE_FIRM_CAP:
+               hs_page1 = (struct mvumi_hs_page1 *) hs_header;
+
+               mhba->max_io = hs_page1->max_io_support;
+               mhba->list_num_io = hs_page1->cl_inout_list_depth;
+               mhba->max_transfer_size = hs_page1->max_transfer_size;
+               mhba->max_target_id = hs_page1->max_devices_support;
+               mhba->hba_capability = hs_page1->capability;
+               mhba->ib_max_size_setting = hs_page1->cl_in_max_entry_size;
+               mhba->ib_max_size = (1 << hs_page1->cl_in_max_entry_size) << 2;
+
+               mhba->ob_max_size_setting = hs_page1->cl_out_max_entry_size;
+               mhba->ob_max_size = (1 << hs_page1->cl_out_max_entry_size) << 2;
+
+               dev_dbg(&mhba->pdev->dev, "FW version:%d\n",
+                                               hs_page1->fw_ver.ver_build);
+
+               break;
+       default:
+               dev_err(&mhba->pdev->dev, "handshake: page code error\n");
+               return -1;
+       }
+       return 0;
+}
+
+/**
+ * mvumi_handshake -   Move the FW to READY state
+ * @mhba:                              Adapter soft state
+ *
+ * During the initialization, FW passes can potentially be in any one of
+ * several possible states. If the FW in operational, waiting-for-handshake
+ * states, driver must take steps to bring it to ready state. Otherwise, it
+ * has to wait for the ready state.
+ */
+static int mvumi_handshake(struct mvumi_hba *mhba)
+{
+       unsigned int hs_state, tmp, hs_fun;
+       struct mvumi_hs_header *hs_header;
+       void *regs = mhba->mmio;
+
+       if (mhba->fw_state == FW_STATE_STARTING)
+               hs_state = HS_S_START;
+       else {
+               tmp = ioread32(regs + CPU_ARM_TO_PCIEA_MSG0);
+               hs_state = HS_GET_STATE(tmp);
+               dev_dbg(&mhba->pdev->dev, "handshake state[0x%x].\n", hs_state);
+               if (HS_GET_STATUS(tmp) != HS_STATUS_OK) {
+                       mhba->fw_state = FW_STATE_STARTING;
+                       return -1;
+               }
+       }
+
+       hs_fun = 0;
+       switch (hs_state) {
+       case HS_S_START:
+               mhba->fw_state = FW_STATE_HANDSHAKING;
+               HS_SET_STATUS(hs_fun, HS_STATUS_OK);
+               HS_SET_STATE(hs_fun, HS_S_RESET);
+               iowrite32(HANDSHAKE_SIGNATURE, regs + CPU_PCIEA_TO_ARM_MSG1);
+               iowrite32(hs_fun, regs + CPU_PCIEA_TO_ARM_MSG0);
+               iowrite32(DRBL_HANDSHAKE, regs + CPU_PCIEA_TO_ARM_DRBL_REG);
+               break;
+
+       case HS_S_RESET:
+               iowrite32(lower_32_bits(mhba->handshake_page_phys),
+                                       regs + CPU_PCIEA_TO_ARM_MSG1);
+               iowrite32(upper_32_bits(mhba->handshake_page_phys),
+                                       regs + CPU_ARM_TO_PCIEA_MSG1);
+               HS_SET_STATUS(hs_fun, HS_STATUS_OK);
+               HS_SET_STATE(hs_fun, HS_S_PAGE_ADDR);
+               iowrite32(hs_fun, regs + CPU_PCIEA_TO_ARM_MSG0);
+               iowrite32(DRBL_HANDSHAKE, regs + CPU_PCIEA_TO_ARM_DRBL_REG);
+
+               break;
+
+       case HS_S_PAGE_ADDR:
+       case HS_S_QUERY_PAGE:
+       case HS_S_SEND_PAGE:
+               hs_header = (struct mvumi_hs_header *) mhba->handshake_page;
+               if (hs_header->page_code == HS_PAGE_FIRM_CAP) {
+                       mhba->hba_total_pages =
+                       ((struct mvumi_hs_page1 *) hs_header)->total_pages;
+
+                       if (mhba->hba_total_pages == 0)
+                               mhba->hba_total_pages = HS_PAGE_TOTAL-1;
+               }
+
+               if (hs_state == HS_S_QUERY_PAGE) {
+                       if (mvumi_hs_process_page(mhba, hs_header)) {
+                               HS_SET_STATE(hs_fun, HS_S_ABORT);
+                               return -1;
+                       }
+                       if (mvumi_init_data(mhba)) {
+                               HS_SET_STATE(hs_fun, HS_S_ABORT);
+                               return -1;
+                       }
+               } else if (hs_state == HS_S_PAGE_ADDR) {
+                       hs_header->page_code = 0;
+                       mhba->hba_total_pages = HS_PAGE_TOTAL-1;
+               }
+
+               if ((hs_header->page_code + 1) <= mhba->hba_total_pages) {
+                       hs_header->page_code++;
+                       if (hs_header->page_code != HS_PAGE_FIRM_CAP) {
+                               mvumi_hs_build_page(mhba, hs_header);
+                               HS_SET_STATE(hs_fun, HS_S_SEND_PAGE);
+                       } else
+                               HS_SET_STATE(hs_fun, HS_S_QUERY_PAGE);
+               } else
+                       HS_SET_STATE(hs_fun, HS_S_END);
+
+               HS_SET_STATUS(hs_fun, HS_STATUS_OK);
+               iowrite32(hs_fun, regs + CPU_PCIEA_TO_ARM_MSG0);
+               iowrite32(DRBL_HANDSHAKE, regs + CPU_PCIEA_TO_ARM_DRBL_REG);
+               break;
+
+       case HS_S_END:
+               /* Set communication list ISR */
+               tmp = ioread32(regs + CPU_ENPOINTA_MASK_REG);
+               tmp |= INT_MAP_COMAOUT | INT_MAP_COMAERR;
+               iowrite32(tmp, regs + CPU_ENPOINTA_MASK_REG);
+               iowrite32(mhba->list_num_io, mhba->ib_shadow);
+               /* Set InBound List Avaliable count shadow */
+               iowrite32(lower_32_bits(mhba->ib_shadow_phys),
+                                       regs + CLA_INB_AVAL_COUNT_BASEL);
+               iowrite32(upper_32_bits(mhba->ib_shadow_phys),
+                                       regs + CLA_INB_AVAL_COUNT_BASEH);
+
+               /* Set OutBound List Avaliable count shadow */
+               iowrite32((mhba->list_num_io-1) | CL_POINTER_TOGGLE,
+                                               mhba->ob_shadow);
+               iowrite32(lower_32_bits(mhba->ob_shadow_phys), regs + 0x5B0);
+               iowrite32(upper_32_bits(mhba->ob_shadow_phys), regs + 0x5B4);
+
+               mhba->ib_cur_slot = (mhba->list_num_io - 1) | CL_POINTER_TOGGLE;
+               mhba->ob_cur_slot = (mhba->list_num_io - 1) | CL_POINTER_TOGGLE;
+               mhba->fw_state = FW_STATE_STARTED;
+
+               break;
+       default:
+               dev_err(&mhba->pdev->dev, "unknown handshake state [0x%x].\n",
+                                                               hs_state);
+               return -1;
+       }
+       return 0;
+}
+
+static unsigned char mvumi_handshake_event(struct mvumi_hba *mhba)
+{
+       unsigned int isr_status;
+       unsigned long before;
+
+       before = jiffies;
+       mvumi_handshake(mhba);
+       do {
+               isr_status = mhba->instancet->read_fw_status_reg(mhba->mmio);
+
+               if (mhba->fw_state == FW_STATE_STARTED)
+                       return 0;
+               if (time_after(jiffies, before + FW_MAX_DELAY * HZ)) {
+                       dev_err(&mhba->pdev->dev,
+                               "no handshake response at state 0x%x.\n",
+                                 mhba->fw_state);
+                       dev_err(&mhba->pdev->dev,
+                               "isr : global=0x%x,status=0x%x.\n",
+                                       mhba->global_isr, isr_status);
+                       return -1;
+               }
+               rmb();
+               usleep_range(1000, 2000);
+       } while (!(isr_status & DRBL_HANDSHAKE_ISR));
+
+       return 0;
+}
+
+static unsigned char mvumi_check_handshake(struct mvumi_hba *mhba)
+{
+       void *regs = mhba->mmio;
+       unsigned int tmp;
+       unsigned long before;
+
+       before = jiffies;
+       tmp = ioread32(regs + CPU_ARM_TO_PCIEA_MSG1);
+       while ((tmp != HANDSHAKE_READYSTATE) && (tmp != HANDSHAKE_DONESTATE)) {
+               if (tmp != HANDSHAKE_READYSTATE)
+                       iowrite32(DRBL_MU_RESET,
+                                       regs + CPU_PCIEA_TO_ARM_DRBL_REG);
+               if (time_after(jiffies, before + FW_MAX_DELAY * HZ)) {
+                       dev_err(&mhba->pdev->dev,
+                               "invalid signature [0x%x].\n", tmp);
+                       return -1;
+               }
+               usleep_range(1000, 2000);
+               rmb();
+               tmp = ioread32(regs + CPU_ARM_TO_PCIEA_MSG1);
+       }
+
+       mhba->fw_state = FW_STATE_STARTING;
+       dev_dbg(&mhba->pdev->dev, "start firmware handshake...\n");
+       do {
+               if (mvumi_handshake_event(mhba)) {
+                       dev_err(&mhba->pdev->dev,
+                                       "handshake failed at state 0x%x.\n",
+                                               mhba->fw_state);
+                       return -1;
+               }
+       } while (mhba->fw_state != FW_STATE_STARTED);
+
+       dev_dbg(&mhba->pdev->dev, "firmware handshake done\n");
+
+       return 0;
+}
+
+static unsigned char mvumi_start(struct mvumi_hba *mhba)
+{
+       void *regs = mhba->mmio;
+       unsigned int tmp;
+       /* clear Door bell */
+       tmp = ioread32(regs + CPU_ARM_TO_PCIEA_DRBL_REG);
+       iowrite32(tmp, regs + CPU_ARM_TO_PCIEA_DRBL_REG);
+
+       iowrite32(0x3FFFFFFF, regs + CPU_ARM_TO_PCIEA_MASK_REG);
+       tmp = ioread32(regs + CPU_ENPOINTA_MASK_REG) | INT_MAP_DL_CPU2PCIEA;
+       iowrite32(tmp, regs + CPU_ENPOINTA_MASK_REG);
+       if (mvumi_check_handshake(mhba))
+               return -1;
+
+       return 0;
+}
+
+/**
+ * mvumi_complete_cmd -        Completes a command
+ * @mhba:                      Adapter soft state
+ * @cmd:                       Command to be completed
+ */
+static void mvumi_complete_cmd(struct mvumi_hba *mhba, struct mvumi_cmd *cmd,
+                                       struct mvumi_rsp_frame *ob_frame)
+{
+       struct scsi_cmnd *scmd = cmd->scmd;
+
+       cmd->scmd->SCp.ptr = NULL;
+       scmd->result = ob_frame->req_status;
+
+       switch (ob_frame->req_status) {
+       case SAM_STAT_GOOD:
+               scmd->result |= DID_OK << 16;
+               break;
+       case SAM_STAT_BUSY:
+               scmd->result |= DID_BUS_BUSY << 16;
+               break;
+       case SAM_STAT_CHECK_CONDITION:
+               scmd->result |= (DID_OK << 16);
+               if (ob_frame->rsp_flag & CL_RSP_FLAG_SENSEDATA) {
+                       memcpy(cmd->scmd->sense_buffer, ob_frame->payload,
+                               sizeof(struct mvumi_sense_data));
+                       scmd->result |=  (DRIVER_SENSE << 24);
+               }
+               break;
+       default:
+               scmd->result |= (DRIVER_INVALID << 24) | (DID_ABORT << 16);
+               break;
+       }
+
+       if (scsi_bufflen(scmd)) {
+               if (scsi_sg_count(scmd)) {
+                       pci_unmap_sg(mhba->pdev,
+                               scsi_sglist(scmd),
+                               scsi_sg_count(scmd),
+                               (int) scmd->sc_data_direction);
+               } else {
+                       pci_unmap_single(mhba->pdev,
+                               scmd->SCp.dma_handle,
+                               scsi_bufflen(scmd),
+                               (int) scmd->sc_data_direction);
+
+                       scmd->SCp.dma_handle = 0;
+               }
+       }
+       cmd->scmd->scsi_done(scmd);
+       mvumi_return_cmd(mhba, cmd);
+}
+static void mvumi_complete_internal_cmd(struct mvumi_hba *mhba,
+                                               struct mvumi_cmd *cmd,
+                                       struct mvumi_rsp_frame *ob_frame)
+{
+       if (atomic_read(&cmd->sync_cmd)) {
+               cmd->cmd_status = ob_frame->req_status;
+
+               if ((ob_frame->req_status == SAM_STAT_CHECK_CONDITION) &&
+                               (ob_frame->rsp_flag & CL_RSP_FLAG_SENSEDATA) &&
+                               cmd->data_buf) {
+                       memcpy(cmd->data_buf, ob_frame->payload,
+                                       sizeof(struct mvumi_sense_data));
+               }
+               atomic_dec(&cmd->sync_cmd);
+               wake_up(&mhba->int_cmd_wait_q);
+       }
+}
+
+static void mvumi_show_event(struct mvumi_hba *mhba,
+                       struct mvumi_driver_event *ptr)
+{
+       unsigned int i;
+
+       dev_warn(&mhba->pdev->dev,
+               "Event[0x%x] id[0x%x] severity[0x%x] device id[0x%x]\n",
+               ptr->sequence_no, ptr->event_id, ptr->severity, ptr->device_id);
+       if (ptr->param_count) {
+               printk(KERN_WARNING "Event param(len 0x%x): ",
+                                               ptr->param_count);
+               for (i = 0; i < ptr->param_count; i++)
+                       printk(KERN_WARNING "0x%x ", ptr->params[i]);
+
+               printk(KERN_WARNING "\n");
+       }
+
+       if (ptr->sense_data_length) {
+               printk(KERN_WARNING "Event sense data(len 0x%x): ",
+                                               ptr->sense_data_length);
+               for (i = 0; i < ptr->sense_data_length; i++)
+                       printk(KERN_WARNING "0x%x ", ptr->sense_data[i]);
+               printk(KERN_WARNING "\n");
+       }
+}
+
+static void mvumi_notification(struct mvumi_hba *mhba, u8 msg, void *buffer)
+{
+       if (msg == APICDB1_EVENT_GETEVENT) {
+               int i, count;
+               struct mvumi_driver_event *param = NULL;
+               struct mvumi_event_req *er = buffer;
+               count = er->count;
+               if (count > MAX_EVENTS_RETURNED) {
+                       dev_err(&mhba->pdev->dev, "event count[0x%x] is bigger"
+                                       " than max event count[0x%x].\n",
+                                       count, MAX_EVENTS_RETURNED);
+                       return;
+               }
+               for (i = 0; i < count; i++) {
+                       param = &er->events[i];
+                       mvumi_show_event(mhba, param);
+               }
+       }
+}
+
+static int mvumi_get_event(struct mvumi_hba *mhba, unsigned char msg)
+{
+       struct mvumi_cmd *cmd;
+       struct mvumi_msg_frame *frame;
+
+       cmd = mvumi_create_internal_cmd(mhba, 512);
+       if (!cmd)
+               return -1;
+       cmd->scmd = NULL;
+       cmd->cmd_status = REQ_STATUS_PENDING;
+       atomic_set(&cmd->sync_cmd, 0);
+       frame = cmd->frame;
+       frame->device_id = 0;
+       frame->cmd_flag = CMD_FLAG_DATA_IN;
+       frame->req_function = CL_FUN_SCSI_CMD;
+       frame->cdb_length = MAX_COMMAND_SIZE;
+       frame->data_transfer_length = sizeof(struct mvumi_event_req);
+       memset(frame->cdb, 0, MAX_COMMAND_SIZE);
+       frame->cdb[0] = APICDB0_EVENT;
+       frame->cdb[1] = msg;
+       mvumi_issue_blocked_cmd(mhba, cmd);
+
+       if (cmd->cmd_status != SAM_STAT_GOOD)
+               dev_err(&mhba->pdev->dev, "get event failed, status=0x%x.\n",
+                                                       cmd->cmd_status);
+       else
+               mvumi_notification(mhba, cmd->frame->cdb[1], cmd->data_buf);
+
+       mvumi_delete_internal_cmd(mhba, cmd);
+       return 0;
+}
+
+static void mvumi_scan_events(struct work_struct *work)
+{
+       struct mvumi_events_wq *mu_ev =
+               container_of(work, struct mvumi_events_wq, work_q);
+
+       mvumi_get_event(mu_ev->mhba, mu_ev->event);
+       kfree(mu_ev);
+}
+
+static void mvumi_launch_events(struct mvumi_hba *mhba, u8 msg)
+{
+       struct mvumi_events_wq *mu_ev;
+
+       mu_ev = kzalloc(sizeof(*mu_ev), GFP_ATOMIC);
+       if (mu_ev) {
+               INIT_WORK(&mu_ev->work_q, mvumi_scan_events);
+               mu_ev->mhba = mhba;
+               mu_ev->event = msg;
+               mu_ev->param = NULL;
+               schedule_work(&mu_ev->work_q);
+       }
+}
+
+static void mvumi_handle_clob(struct mvumi_hba *mhba)
+{
+       struct mvumi_rsp_frame *ob_frame;
+       struct mvumi_cmd *cmd;
+       struct mvumi_ob_data *pool;
+
+       while (!list_empty(&mhba->free_ob_list)) {
+               pool = list_first_entry(&mhba->free_ob_list,
+                                               struct mvumi_ob_data, list);
+               list_del_init(&pool->list);
+               list_add_tail(&pool->list, &mhba->ob_data_list);
+
+               ob_frame = (struct mvumi_rsp_frame *) &pool->data[0];
+               cmd = mhba->tag_cmd[ob_frame->tag];
+
+               atomic_dec(&mhba->fw_outstanding);
+               mhba->tag_cmd[ob_frame->tag] = 0;
+               tag_release_one(mhba, &mhba->tag_pool, ob_frame->tag);
+               if (cmd->scmd)
+                       mvumi_complete_cmd(mhba, cmd, ob_frame);
+               else
+                       mvumi_complete_internal_cmd(mhba, cmd, ob_frame);
+       }
+       mhba->instancet->fire_cmd(mhba, NULL);
+}
+
+static irqreturn_t mvumi_isr_handler(int irq, void *devp)
+{
+       struct mvumi_hba *mhba = (struct mvumi_hba *) devp;
+       unsigned long flags;
+
+       spin_lock_irqsave(mhba->shost->host_lock, flags);
+       if (unlikely(mhba->instancet->clear_intr(mhba) || !mhba->global_isr)) {
+               spin_unlock_irqrestore(mhba->shost->host_lock, flags);
+               return IRQ_NONE;
+       }
+
+       if (mhba->global_isr & INT_MAP_DL_CPU2PCIEA) {
+               if (mhba->isr_status & DRBL_HANDSHAKE_ISR) {
+                       dev_warn(&mhba->pdev->dev, "enter handshake again!\n");
+                       mvumi_handshake(mhba);
+               }
+               if (mhba->isr_status & DRBL_EVENT_NOTIFY)
+                       mvumi_launch_events(mhba, APICDB1_EVENT_GETEVENT);
+       }
+
+       if (mhba->global_isr & INT_MAP_COMAOUT)
+               mvumi_receive_ob_list_entry(mhba);
+
+       mhba->global_isr = 0;
+       mhba->isr_status = 0;
+       if (mhba->fw_state == FW_STATE_STARTED)
+               mvumi_handle_clob(mhba);
+       spin_unlock_irqrestore(mhba->shost->host_lock, flags);
+       return IRQ_HANDLED;
+}
+
+static enum mvumi_qc_result mvumi_send_command(struct mvumi_hba *mhba,
+                                               struct mvumi_cmd *cmd)
+{
+       void *ib_entry;
+       struct mvumi_msg_frame *ib_frame;
+       unsigned int frame_len;
+
+       ib_frame = cmd->frame;
+       if (unlikely(mhba->fw_state != FW_STATE_STARTED)) {
+               dev_dbg(&mhba->pdev->dev, "firmware not ready.\n");
+               return MV_QUEUE_COMMAND_RESULT_NO_RESOURCE;
+       }
+       if (tag_is_empty(&mhba->tag_pool)) {
+               dev_dbg(&mhba->pdev->dev, "no free tag.\n");
+               return MV_QUEUE_COMMAND_RESULT_NO_RESOURCE;
+       }
+       if (mvumi_get_ib_list_entry(mhba, &ib_entry))
+               return MV_QUEUE_COMMAND_RESULT_NO_RESOURCE;
+
+       cmd->frame->tag = tag_get_one(mhba, &mhba->tag_pool);
+       cmd->frame->request_id = mhba->io_seq++;
+       cmd->request_id = cmd->frame->request_id;
+       mhba->tag_cmd[cmd->frame->tag] = cmd;
+       frame_len = sizeof(*ib_frame) - 4 +
+                               ib_frame->sg_counts * sizeof(struct mvumi_sgl);
+       memcpy(ib_entry, ib_frame, frame_len);
+       return MV_QUEUE_COMMAND_RESULT_SENT;
+}
+
+static void mvumi_fire_cmd(struct mvumi_hba *mhba, struct mvumi_cmd *cmd)
+{
+       unsigned short num_of_cl_sent = 0;
+       enum mvumi_qc_result result;
+
+       if (cmd)
+               list_add_tail(&cmd->queue_pointer, &mhba->waiting_req_list);
+
+       while (!list_empty(&mhba->waiting_req_list)) {
+               cmd = list_first_entry(&mhba->waiting_req_list,
+                                        struct mvumi_cmd, queue_pointer);
+               list_del_init(&cmd->queue_pointer);
+               result = mvumi_send_command(mhba, cmd);
+               switch (result) {
+               case MV_QUEUE_COMMAND_RESULT_SENT:
+                       num_of_cl_sent++;
+                       break;
+               case MV_QUEUE_COMMAND_RESULT_NO_RESOURCE:
+                       list_add(&cmd->queue_pointer, &mhba->waiting_req_list);
+                       if (num_of_cl_sent > 0)
+                               mvumi_send_ib_list_entry(mhba);
+
+                       return;
+               }
+       }
+       if (num_of_cl_sent > 0)
+               mvumi_send_ib_list_entry(mhba);
+}
+
+/**
+ * mvumi_enable_intr - Enables interrupts
+ * @regs:                      FW register set
+ */
+static void mvumi_enable_intr(void *regs)
+{
+       unsigned int mask;
+
+       iowrite32(0x3FFFFFFF, regs + CPU_ARM_TO_PCIEA_MASK_REG);
+       mask = ioread32(regs + CPU_ENPOINTA_MASK_REG);
+       mask |= INT_MAP_DL_CPU2PCIEA | INT_MAP_COMAOUT | INT_MAP_COMAERR;
+       iowrite32(mask, regs + CPU_ENPOINTA_MASK_REG);
+}
+
+/**
+ * mvumi_disable_intr -Disables interrupt
+ * @regs:                      FW register set
+ */
+static void mvumi_disable_intr(void *regs)
+{
+       unsigned int mask;
+
+       iowrite32(0, regs + CPU_ARM_TO_PCIEA_MASK_REG);
+       mask = ioread32(regs + CPU_ENPOINTA_MASK_REG);
+       mask &= ~(INT_MAP_DL_CPU2PCIEA | INT_MAP_COMAOUT | INT_MAP_COMAERR);
+       iowrite32(mask, regs + CPU_ENPOINTA_MASK_REG);
+}
+
+static int mvumi_clear_intr(void *extend)
+{
+       struct mvumi_hba *mhba = (struct mvumi_hba *) extend;
+       unsigned int status, isr_status = 0, tmp = 0;
+       void *regs = mhba->mmio;
+
+       status = ioread32(regs + CPU_MAIN_INT_CAUSE_REG);
+       if (!(status & INT_MAP_MU) || status == 0xFFFFFFFF)
+               return 1;
+       if (unlikely(status & INT_MAP_COMAERR)) {
+               tmp = ioread32(regs + CLA_ISR_CAUSE);
+               if (tmp & (CLIC_IN_ERR_IRQ | CLIC_OUT_ERR_IRQ))
+                       iowrite32(tmp & (CLIC_IN_ERR_IRQ | CLIC_OUT_ERR_IRQ),
+                                       regs + CLA_ISR_CAUSE);
+               status ^= INT_MAP_COMAERR;
+               /* inbound or outbound parity error, command will timeout */
+       }
+       if (status & INT_MAP_COMAOUT) {
+               tmp = ioread32(regs + CLA_ISR_CAUSE);
+               if (tmp & CLIC_OUT_IRQ)
+                       iowrite32(tmp & CLIC_OUT_IRQ, regs + CLA_ISR_CAUSE);
+       }
+       if (status & INT_MAP_DL_CPU2PCIEA) {
+               isr_status = ioread32(regs + CPU_ARM_TO_PCIEA_DRBL_REG);
+               if (isr_status)
+                       iowrite32(isr_status, regs + CPU_ARM_TO_PCIEA_DRBL_REG);
+       }
+
+       mhba->global_isr = status;
+       mhba->isr_status = isr_status;
+
+       return 0;
+}
+
+/**
+ * mvumi_read_fw_status_reg - returns the current FW status value
+ * @regs:                      FW register set
+ */
+static unsigned int mvumi_read_fw_status_reg(void *regs)
+{
+       unsigned int status;
+
+       status = ioread32(regs + CPU_ARM_TO_PCIEA_DRBL_REG);
+       if (status)
+               iowrite32(status, regs + CPU_ARM_TO_PCIEA_DRBL_REG);
+       return status;
+}
+
+static struct mvumi_instance_template mvumi_instance_template = {
+       .fire_cmd = mvumi_fire_cmd,
+       .enable_intr = mvumi_enable_intr,
+       .disable_intr = mvumi_disable_intr,
+       .clear_intr = mvumi_clear_intr,
+       .read_fw_status_reg = mvumi_read_fw_status_reg,
+};
+
+static int mvumi_slave_configure(struct scsi_device *sdev)
+{
+       struct mvumi_hba *mhba;
+       unsigned char bitcount = sizeof(unsigned char) * 8;
+
+       mhba = (struct mvumi_hba *) sdev->host->hostdata;
+       if (sdev->id >= mhba->max_target_id)
+               return -EINVAL;
+
+       mhba->target_map[sdev->id / bitcount] |= (1 << (sdev->id % bitcount));
+       return 0;
+}
+
+/**
+ * mvumi_build_frame - Prepares a direct cdb (DCDB) command
+ * @mhba:              Adapter soft state
+ * @scmd:              SCSI command
+ * @cmd:               Command to be prepared in
+ *
+ * This function prepares CDB commands. These are typcially pass-through
+ * commands to the devices.
+ */
+static unsigned char mvumi_build_frame(struct mvumi_hba *mhba,
+                               struct scsi_cmnd *scmd, struct mvumi_cmd *cmd)
+{
+       struct mvumi_msg_frame *pframe;
+
+       cmd->scmd = scmd;
+       cmd->cmd_status = REQ_STATUS_PENDING;
+       pframe = cmd->frame;
+       pframe->device_id = ((unsigned short) scmd->device->id) |
+                               (((unsigned short) scmd->device->lun) << 8);
+       pframe->cmd_flag = 0;
+
+       switch (scmd->sc_data_direction) {
+       case DMA_NONE:
+               pframe->cmd_flag |= CMD_FLAG_NON_DATA;
+               break;
+       case DMA_FROM_DEVICE:
+               pframe->cmd_flag |= CMD_FLAG_DATA_IN;
+               break;
+       case DMA_TO_DEVICE:
+               pframe->cmd_flag |= CMD_FLAG_DATA_OUT;
+               break;
+       case DMA_BIDIRECTIONAL:
+       default:
+               dev_warn(&mhba->pdev->dev, "unexpected data direction[%d] "
+                       "cmd[0x%x]\n", scmd->sc_data_direction, scmd->cmnd[0]);
+               goto error;
+       }
+
+       pframe->cdb_length = scmd->cmd_len;
+       memcpy(pframe->cdb, scmd->cmnd, pframe->cdb_length);
+       pframe->req_function = CL_FUN_SCSI_CMD;
+       if (scsi_bufflen(scmd)) {
+               if (mvumi_make_sgl(mhba, scmd, &pframe->payload[0],
+                       &pframe->sg_counts))
+                       goto error;
+
+               pframe->data_transfer_length = scsi_bufflen(scmd);
+       } else {
+               pframe->sg_counts = 0;
+               pframe->data_transfer_length = 0;
+       }
+       return 0;
+
+error:
+       scmd->result = (DID_OK << 16) | (DRIVER_SENSE << 24) |
+               SAM_STAT_CHECK_CONDITION;
+       scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x24,
+                                                                       0);
+       return -1;
+}
+
+/**
+ * mvumi_queue_command -       Queue entry point
+ * @scmd:                      SCSI command to be queued
+ * @done:                      Callback entry point
+ */
+static int mvumi_queue_command(struct Scsi_Host *shost,
+                                       struct scsi_cmnd *scmd)
+{
+       struct mvumi_cmd *cmd;
+       struct mvumi_hba *mhba;
+       unsigned long irq_flags;
+
+       spin_lock_irqsave(shost->host_lock, irq_flags);
+       scsi_cmd_get_serial(shost, scmd);
+
+       mhba = (struct mvumi_hba *) shost->hostdata;
+       scmd->result = 0;
+       cmd = mvumi_get_cmd(mhba);
+       if (unlikely(!cmd)) {
+               spin_unlock_irqrestore(shost->host_lock, irq_flags);
+               return SCSI_MLQUEUE_HOST_BUSY;
+       }
+
+       if (unlikely(mvumi_build_frame(mhba, scmd, cmd)))
+               goto out_return_cmd;
+
+       cmd->scmd = scmd;
+       scmd->SCp.ptr = (char *) cmd;
+       mhba->instancet->fire_cmd(mhba, cmd);
+       spin_unlock_irqrestore(shost->host_lock, irq_flags);
+       return 0;
+
+out_return_cmd:
+       mvumi_return_cmd(mhba, cmd);
+       scmd->scsi_done(scmd);
+       spin_unlock_irqrestore(shost->host_lock, irq_flags);
+       return 0;
+}
+
+static enum blk_eh_timer_return mvumi_timed_out(struct scsi_cmnd *scmd)
+{
+       struct mvumi_cmd *cmd = (struct mvumi_cmd *) scmd->SCp.ptr;
+       struct Scsi_Host *host = scmd->device->host;
+       struct mvumi_hba *mhba = shost_priv(host);
+       unsigned long flags;
+
+       spin_lock_irqsave(mhba->shost->host_lock, flags);
+
+       if (mhba->tag_cmd[cmd->frame->tag]) {
+               mhba->tag_cmd[cmd->frame->tag] = 0;
+               tag_release_one(mhba, &mhba->tag_pool, cmd->frame->tag);
+       }
+       if (!list_empty(&cmd->queue_pointer))
+               list_del_init(&cmd->queue_pointer);
+       else
+               atomic_dec(&mhba->fw_outstanding);
+
+       scmd->result = (DRIVER_INVALID << 24) | (DID_ABORT << 16);
+       scmd->SCp.ptr = NULL;
+       if (scsi_bufflen(scmd)) {
+               if (scsi_sg_count(scmd)) {
+                       pci_unmap_sg(mhba->pdev,
+                               scsi_sglist(scmd),
+                               scsi_sg_count(scmd),
+                               (int)scmd->sc_data_direction);
+               } else {
+                       pci_unmap_single(mhba->pdev,
+                               scmd->SCp.dma_handle,
+                               scsi_bufflen(scmd),
+                               (int)scmd->sc_data_direction);
+
+                       scmd->SCp.dma_handle = 0;
+               }
+       }
+       mvumi_return_cmd(mhba, cmd);
+       spin_unlock_irqrestore(mhba->shost->host_lock, flags);
+
+       return BLK_EH_NOT_HANDLED;
+}
+
+static int
+mvumi_bios_param(struct scsi_device *sdev, struct block_device *bdev,
+                       sector_t capacity, int geom[])
+{
+       int heads, sectors;
+       sector_t cylinders;
+       unsigned long tmp;
+
+       heads = 64;
+       sectors = 32;
+       tmp = heads * sectors;
+       cylinders = capacity;
+       sector_div(cylinders, tmp);
+
+       if (capacity >= 0x200000) {
+               heads = 255;
+               sectors = 63;
+               tmp = heads * sectors;
+               cylinders = capacity;
+               sector_div(cylinders, tmp);
+       }
+       geom[0] = heads;
+       geom[1] = sectors;
+       geom[2] = cylinders;
+
+       return 0;
+}
+
+static struct scsi_host_template mvumi_template = {
+
+       .module = THIS_MODULE,
+       .name = "Marvell Storage Controller",
+       .slave_configure = mvumi_slave_configure,
+       .queuecommand = mvumi_queue_command,
+       .eh_host_reset_handler = mvumi_host_reset,
+       .bios_param = mvumi_bios_param,
+       .this_id = -1,
+};
+
+static struct scsi_transport_template mvumi_transport_template = {
+       .eh_timed_out = mvumi_timed_out,
+};
+
+/**
+ * mvumi_init_fw -     Initializes the FW
+ * @mhba:              Adapter soft state
+ *
+ * This is the main function for initializing firmware.
+ */
+static int mvumi_init_fw(struct mvumi_hba *mhba)
+{
+       int ret = 0;
+
+       if (pci_request_regions(mhba->pdev, MV_DRIVER_NAME)) {
+               dev_err(&mhba->pdev->dev, "IO memory region busy!\n");
+               return -EBUSY;
+       }
+       ret = mvumi_map_pci_addr(mhba->pdev, mhba->base_addr);
+       if (ret)
+               goto fail_ioremap;
+
+       mhba->mmio = mhba->base_addr[0];
+
+       switch (mhba->pdev->device) {
+       case PCI_DEVICE_ID_MARVELL_MV9143:
+               mhba->instancet = &mvumi_instance_template;
+               mhba->io_seq = 0;
+               mhba->max_sge = MVUMI_MAX_SG_ENTRY;
+               mhba->request_id_enabled = 1;
+               break;
+       default:
+               dev_err(&mhba->pdev->dev, "device 0x%x not supported!\n",
+                                                       mhba->pdev->device);
+               mhba->instancet = NULL;
+               ret = -EINVAL;
+               goto fail_alloc_mem;
+       }
+       dev_dbg(&mhba->pdev->dev, "device id : %04X is found.\n",
+                                                       mhba->pdev->device);
+
+       mhba->handshake_page = kzalloc(HSP_MAX_SIZE, GFP_KERNEL);
+       if (!mhba->handshake_page) {
+               dev_err(&mhba->pdev->dev,
+                       "failed to allocate memory for handshake\n");
+               ret = -ENOMEM;
+               goto fail_alloc_mem;
+       }
+       mhba->handshake_page_phys = virt_to_phys(mhba->handshake_page);
+
+       if (mvumi_start(mhba)) {
+               ret = -EINVAL;
+               goto fail_ready_state;
+       }
+       ret = mvumi_alloc_cmds(mhba);
+       if (ret)
+               goto fail_ready_state;
+
+       return 0;
+
+fail_ready_state:
+       mvumi_release_mem_resource(mhba);
+       kfree(mhba->handshake_page);
+fail_alloc_mem:
+       mvumi_unmap_pci_addr(mhba->pdev, mhba->base_addr);
+fail_ioremap:
+       pci_release_regions(mhba->pdev);
+
+       return ret;
+}
+
+/**
+ * mvumi_io_attach -   Attaches this driver to SCSI mid-layer
+ * @mhba:              Adapter soft state
+ */
+static int mvumi_io_attach(struct mvumi_hba *mhba)
+{
+       struct Scsi_Host *host = mhba->shost;
+       int ret;
+       unsigned int max_sg = (mhba->ib_max_size + 4 -
+               sizeof(struct mvumi_msg_frame)) / sizeof(struct mvumi_sgl);
+
+       host->irq = mhba->pdev->irq;
+       host->unique_id = mhba->unique_id;
+       host->can_queue = (mhba->max_io - 1) ? (mhba->max_io - 1) : 1;
+       host->sg_tablesize = mhba->max_sge > max_sg ? max_sg : mhba->max_sge;
+       host->max_sectors = mhba->max_transfer_size / 512;
+       host->cmd_per_lun =  (mhba->max_io - 1) ? (mhba->max_io - 1) : 1;
+       host->max_id = mhba->max_target_id;
+       host->max_cmd_len = MAX_COMMAND_SIZE;
+       host->transportt = &mvumi_transport_template;
+
+       ret = scsi_add_host(host, &mhba->pdev->dev);
+       if (ret) {
+               dev_err(&mhba->pdev->dev, "scsi_add_host failed\n");
+               return ret;
+       }
+       mhba->fw_flag |= MVUMI_FW_ATTACH;
+       scsi_scan_host(host);
+
+       return 0;
+}
+
+/**
+ * mvumi_probe_one -   PCI hotplug entry point
+ * @pdev:              PCI device structure
+ * @id:                        PCI ids of supported hotplugged adapter
+ */
+static int __devinit mvumi_probe_one(struct pci_dev *pdev,
+                                       const struct pci_device_id *id)
+{
+       struct Scsi_Host *host;
+       struct mvumi_hba *mhba;
+       int ret;
+
+       dev_dbg(&pdev->dev, " %#4.04x:%#4.04x:%#4.04x:%#4.04x: ",
+                       pdev->vendor, pdev->device, pdev->subsystem_vendor,
+                       pdev->subsystem_device);
+
+       ret = pci_enable_device(pdev);
+       if (ret)
+               return ret;
+
+       pci_set_master(pdev);
+
+       if (IS_DMA64) {
+               ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
+               if (ret) {
+                       ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
+                       if (ret)
+                               goto fail_set_dma_mask;
+               }
+       } else {
+               ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
+               if (ret)
+                       goto fail_set_dma_mask;
+       }
+
+       host = scsi_host_alloc(&mvumi_template, sizeof(*mhba));
+       if (!host) {
+               dev_err(&pdev->dev, "scsi_host_alloc failed\n");
+               ret = -ENOMEM;
+               goto fail_alloc_instance;
+       }
+       mhba = shost_priv(host);
+
+       INIT_LIST_HEAD(&mhba->cmd_pool);
+       INIT_LIST_HEAD(&mhba->ob_data_list);
+       INIT_LIST_HEAD(&mhba->free_ob_list);
+       INIT_LIST_HEAD(&mhba->res_list);
+       INIT_LIST_HEAD(&mhba->waiting_req_list);
+       atomic_set(&mhba->fw_outstanding, 0);
+       init_waitqueue_head(&mhba->int_cmd_wait_q);
+
+       mhba->pdev = pdev;
+       mhba->shost = host;
+       mhba->unique_id = pdev->bus->number << 8 | pdev->devfn;
+
+       ret = mvumi_init_fw(mhba);
+       if (ret)
+               goto fail_init_fw;
+
+       ret = request_irq(mhba->pdev->irq, mvumi_isr_handler, IRQF_SHARED,
+                               "mvumi", mhba);
+       if (ret) {
+               dev_err(&pdev->dev, "failed to register IRQ\n");
+               goto fail_init_irq;
+       }
+       mhba->instancet->enable_intr(mhba->mmio);
+       pci_set_drvdata(pdev, mhba);
+
+       ret = mvumi_io_attach(mhba);
+       if (ret)
+               goto fail_io_attach;
+       dev_dbg(&pdev->dev, "probe mvumi driver successfully.\n");
+
+       return 0;
+
+fail_io_attach:
+       pci_set_drvdata(pdev, NULL);
+       mhba->instancet->disable_intr(mhba->mmio);
+       free_irq(mhba->pdev->irq, mhba);
+fail_init_irq:
+       mvumi_release_fw(mhba);
+fail_init_fw:
+       scsi_host_put(host);
+
+fail_alloc_instance:
+fail_set_dma_mask:
+       pci_disable_device(pdev);
+
+       return ret;
+}
+
+static void mvumi_detach_one(struct pci_dev *pdev)
+{
+       struct Scsi_Host *host;
+       struct mvumi_hba *mhba;
+
+       mhba = pci_get_drvdata(pdev);
+       host = mhba->shost;
+       scsi_remove_host(mhba->shost);
+       mvumi_flush_cache(mhba);
+
+       mhba->instancet->disable_intr(mhba->mmio);
+       free_irq(mhba->pdev->irq, mhba);
+       mvumi_release_fw(mhba);
+       scsi_host_put(host);
+       pci_set_drvdata(pdev, NULL);
+       pci_disable_device(pdev);
+       dev_dbg(&pdev->dev, "driver is removed!\n");
+}
+
+/**
+ * mvumi_shutdown -    Shutdown entry point
+ * @device:            Generic device structure
+ */
+static void mvumi_shutdown(struct pci_dev *pdev)
+{
+       struct mvumi_hba *mhba = pci_get_drvdata(pdev);
+
+       mvumi_flush_cache(mhba);
+}
+
+static int mvumi_suspend(struct pci_dev *pdev, pm_message_t state)
+{
+       struct mvumi_hba *mhba = NULL;
+
+       mhba = pci_get_drvdata(pdev);
+       mvumi_flush_cache(mhba);
+
+       pci_set_drvdata(pdev, mhba);
+       mhba->instancet->disable_intr(mhba->mmio);
+       free_irq(mhba->pdev->irq, mhba);
+       mvumi_unmap_pci_addr(pdev, mhba->base_addr);
+       pci_release_regions(pdev);
+       pci_save_state(pdev);
+       pci_disable_device(pdev);
+       pci_set_power_state(pdev, pci_choose_state(pdev, state));
+
+       return 0;
+}
+
+static int mvumi_resume(struct pci_dev *pdev)
+{
+       int ret;
+       struct mvumi_hba *mhba = NULL;
+
+       mhba = pci_get_drvdata(pdev);
+
+       pci_set_power_state(pdev, PCI_D0);
+       pci_enable_wake(pdev, PCI_D0, 0);
+       pci_restore_state(pdev);
+
+       ret = pci_enable_device(pdev);
+       if (ret) {
+               dev_err(&pdev->dev, "enable device failed\n");
+               return ret;
+       }
+       pci_set_master(pdev);
+       if (IS_DMA64) {
+               ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
+               if (ret) {
+                       ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
+                       if (ret)
+                               goto fail;
+               }
+       } else {
+               ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
+               if (ret)
+                       goto fail;
+       }
+       ret = pci_request_regions(mhba->pdev, MV_DRIVER_NAME);
+       if (ret)
+               goto fail;
+       ret = mvumi_map_pci_addr(mhba->pdev, mhba->base_addr);
+       if (ret)
+               goto release_regions;
+
+       mhba->mmio = mhba->base_addr[0];
+       mvumi_reset(mhba->mmio);
+
+       if (mvumi_start(mhba)) {
+               ret = -EINVAL;
+               goto unmap_pci_addr;
+       }
+
+       ret = request_irq(mhba->pdev->irq, mvumi_isr_handler, IRQF_SHARED,
+                               "mvumi", mhba);
+       if (ret) {
+               dev_err(&pdev->dev, "failed to register IRQ\n");
+               goto unmap_pci_addr;
+       }
+       mhba->instancet->enable_intr(mhba->mmio);
+
+       return 0;
+
+unmap_pci_addr:
+       mvumi_unmap_pci_addr(pdev, mhba->base_addr);
+release_regions:
+       pci_release_regions(pdev);
+fail:
+       pci_disable_device(pdev);
+
+       return ret;
+}
+
+static struct pci_driver mvumi_pci_driver = {
+
+       .name = MV_DRIVER_NAME,
+       .id_table = mvumi_pci_table,
+       .probe = mvumi_probe_one,
+       .remove = __devexit_p(mvumi_detach_one),
+       .shutdown = mvumi_shutdown,
+#ifdef CONFIG_PM
+       .suspend = mvumi_suspend,
+       .resume = mvumi_resume,
+#endif
+};
+
+/**
+ * mvumi_init - Driver load entry point
+ */
+static int __init mvumi_init(void)
+{
+       return pci_register_driver(&mvumi_pci_driver);
+}
+
+/**
+ * mvumi_exit - Driver unload entry point
+ */
+static void __exit mvumi_exit(void)
+{
+
+       pci_unregister_driver(&mvumi_pci_driver);
+}
+
+module_init(mvumi_init);
+module_exit(mvumi_exit);
diff --git a/drivers/scsi/mvumi.h b/drivers/scsi/mvumi.h
new file mode 100644 (file)
index 0000000..10b9237
--- /dev/null
@@ -0,0 +1,505 @@
+/*
+  * Marvell UMI head file
+  *
+  * Copyright 2011 Marvell. <jyli@marvell.com>
+  *
+  * This file is licensed under GPLv2.
+  *
+  * This program is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU General Public License as
+  * published by the Free Software Foundation; version 2 of the
+  * License.
+  *
+  * This program is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  * General Public License for more details.
+  *
+  * You should have received a copy of the GNU General Public License
+  * along with this program; if not, write to the Free Software
+  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  * USA
+ */
+
+#ifndef MVUMI_H
+#define MVUMI_H
+
+#define MAX_BASE_ADDRESS       6
+
+#define VER_MAJOR              1
+#define VER_MINOR              1
+#define VER_OEM                        0
+#define VER_BUILD              1500
+
+#define MV_DRIVER_NAME                 "mvumi"
+#define PCI_VENDOR_ID_MARVELL_2                0x1b4b
+#define PCI_DEVICE_ID_MARVELL_MV9143   0x9143
+
+#define MVUMI_INTERNAL_CMD_WAIT_TIME   45
+
+#define IS_DMA64                       (sizeof(dma_addr_t) == 8)
+
+enum mvumi_qc_result {
+       MV_QUEUE_COMMAND_RESULT_SENT    = 0,
+       MV_QUEUE_COMMAND_RESULT_NO_RESOURCE,
+};
+
+enum {
+       /*******************************************/
+
+       /* ARM Mbus Registers Map       */
+
+       /*******************************************/
+       CPU_MAIN_INT_CAUSE_REG  = 0x20200,
+       CPU_MAIN_IRQ_MASK_REG   = 0x20204,
+       CPU_MAIN_FIQ_MASK_REG   = 0x20208,
+       CPU_ENPOINTA_MASK_REG   = 0x2020C,
+       CPU_ENPOINTB_MASK_REG   = 0x20210,
+
+       INT_MAP_COMAERR         = 1 << 6,
+       INT_MAP_COMAIN          = 1 << 7,
+       INT_MAP_COMAOUT         = 1 << 8,
+       INT_MAP_COMBERR         = 1 << 9,
+       INT_MAP_COMBIN          = 1 << 10,
+       INT_MAP_COMBOUT         = 1 << 11,
+
+       INT_MAP_COMAINT = (INT_MAP_COMAOUT | INT_MAP_COMAERR),
+       INT_MAP_COMBINT = (INT_MAP_COMBOUT | INT_MAP_COMBIN | INT_MAP_COMBERR),
+
+       INT_MAP_DL_PCIEA2CPU    = 1 << 0,
+       INT_MAP_DL_CPU2PCIEA    = 1 << 1,
+
+       /***************************************/
+
+       /* ARM Doorbell Registers Map           */
+
+       /***************************************/
+       CPU_PCIEA_TO_ARM_DRBL_REG       = 0x20400,
+       CPU_PCIEA_TO_ARM_MASK_REG       = 0x20404,
+       CPU_ARM_TO_PCIEA_DRBL_REG       = 0x20408,
+       CPU_ARM_TO_PCIEA_MASK_REG       = 0x2040C,
+
+       DRBL_HANDSHAKE                  = 1 << 0,
+       DRBL_SOFT_RESET                 = 1 << 1,
+       DRBL_BUS_CHANGE                 = 1 << 2,
+       DRBL_EVENT_NOTIFY               = 1 << 3,
+       DRBL_MU_RESET                   = 1 << 4,
+       DRBL_HANDSHAKE_ISR              = DRBL_HANDSHAKE,
+
+       CPU_PCIEA_TO_ARM_MSG0           = 0x20430,
+       CPU_PCIEA_TO_ARM_MSG1           = 0x20434,
+       CPU_ARM_TO_PCIEA_MSG0           = 0x20438,
+       CPU_ARM_TO_PCIEA_MSG1           = 0x2043C,
+
+       /*******************************************/
+
+       /* ARM Communication List Registers Map    */
+
+       /*******************************************/
+       CLA_INB_LIST_BASEL              = 0x500,
+       CLA_INB_LIST_BASEH              = 0x504,
+       CLA_INB_AVAL_COUNT_BASEL        = 0x508,
+       CLA_INB_AVAL_COUNT_BASEH        = 0x50C,
+       CLA_INB_DESTI_LIST_BASEL        = 0x510,
+       CLA_INB_DESTI_LIST_BASEH        = 0x514,
+       CLA_INB_WRITE_POINTER           = 0x518,
+       CLA_INB_READ_POINTER            = 0x51C,
+
+       CLA_OUTB_LIST_BASEL             = 0x530,
+       CLA_OUTB_LIST_BASEH             = 0x534,
+       CLA_OUTB_SOURCE_LIST_BASEL      = 0x538,
+       CLA_OUTB_SOURCE_LIST_BASEH      = 0x53C,
+       CLA_OUTB_COPY_POINTER           = 0x544,
+       CLA_OUTB_READ_POINTER           = 0x548,
+
+       CLA_ISR_CAUSE                   = 0x560,
+       CLA_ISR_MASK                    = 0x564,
+
+       INT_MAP_MU              = (INT_MAP_DL_CPU2PCIEA | INT_MAP_COMAINT),
+
+       CL_POINTER_TOGGLE               = 1 << 12,
+
+       CLIC_IN_IRQ                     = 1 << 0,
+       CLIC_OUT_IRQ                    = 1 << 1,
+       CLIC_IN_ERR_IRQ                 = 1 << 8,
+       CLIC_OUT_ERR_IRQ                = 1 << 12,
+
+       CL_SLOT_NUM_MASK                = 0xFFF,
+
+       /*
+       * Command flag is the flag for the CDB command itself
+       */
+       /* 1-non data; 0-data command */
+       CMD_FLAG_NON_DATA               = 1 << 0,
+       CMD_FLAG_DMA                    = 1 << 1,
+       CMD_FLAG_PIO                    = 1 << 2,
+       /* 1-host read data */
+       CMD_FLAG_DATA_IN                = 1 << 3,
+       /* 1-host write data */
+       CMD_FLAG_DATA_OUT               = 1 << 4,
+
+       SCSI_CMD_MARVELL_SPECIFIC       = 0xE1,
+       CDB_CORE_SHUTDOWN               = 0xB,
+};
+
+#define APICDB0_EVENT                  0xF4
+#define APICDB1_EVENT_GETEVENT         0
+#define MAX_EVENTS_RETURNED            6
+
+struct mvumi_driver_event {
+       u32     time_stamp;
+       u32     sequence_no;
+       u32     event_id;
+       u8      severity;
+       u8      param_count;
+       u16     device_id;
+       u32     params[4];
+       u8      sense_data_length;
+       u8      Reserved1;
+       u8      sense_data[30];
+};
+
+struct mvumi_event_req {
+       unsigned char   count;
+       unsigned char   reserved[3];
+       struct mvumi_driver_event  events[MAX_EVENTS_RETURNED];
+};
+
+struct mvumi_events_wq {
+       struct work_struct work_q;
+       struct mvumi_hba *mhba;
+       unsigned int event;
+       void *param;
+};
+
+#define MVUMI_MAX_SG_ENTRY     32
+#define SGD_EOT                        (1L << 27)
+
+struct mvumi_sgl {
+       u32     baseaddr_l;
+       u32     baseaddr_h;
+       u32     flags;
+       u32     size;
+};
+
+struct mvumi_res {
+       struct list_head entry;
+       dma_addr_t bus_addr;
+       void *virt_addr;
+       unsigned int size;
+       unsigned short type;    /* enum Resource_Type */
+};
+
+/* Resource type */
+enum resource_type {
+       RESOURCE_CACHED_MEMORY = 0,
+       RESOURCE_UNCACHED_MEMORY
+};
+
+struct mvumi_sense_data {
+       u8 error_eode:7;
+       u8 valid:1;
+       u8 segment_number;
+       u8 sense_key:4;
+       u8 reserved:1;
+       u8 incorrect_length:1;
+       u8 end_of_media:1;
+       u8 file_mark:1;
+       u8 information[4];
+       u8 additional_sense_length;
+       u8 command_specific_information[4];
+       u8 additional_sense_code;
+       u8 additional_sense_code_qualifier;
+       u8 field_replaceable_unit_code;
+       u8 sense_key_specific[3];
+};
+
+/* Request initiator must set the status to REQ_STATUS_PENDING. */
+#define REQ_STATUS_PENDING             0x80
+
+struct mvumi_cmd {
+       struct list_head queue_pointer;
+       struct mvumi_msg_frame *frame;
+       struct scsi_cmnd *scmd;
+       atomic_t sync_cmd;
+       void *data_buf;
+       unsigned short request_id;
+       unsigned char cmd_status;
+};
+
+/*
+ * the function type of the in bound frame
+ */
+#define CL_FUN_SCSI_CMD                        0x1
+
+struct mvumi_msg_frame {
+       u16 device_id;
+       u16 tag;
+       u8 cmd_flag;
+       u8 req_function;
+       u8 cdb_length;
+       u8 sg_counts;
+       u32 data_transfer_length;
+       u16 request_id;
+       u16 reserved1;
+       u8 cdb[MAX_COMMAND_SIZE];
+       u32 payload[1];
+};
+
+/*
+ * the respond flag for data_payload of the out bound frame
+ */
+#define CL_RSP_FLAG_NODATA             0x0
+#define CL_RSP_FLAG_SENSEDATA          0x1
+
+struct mvumi_rsp_frame {
+       u16 device_id;
+       u16 tag;
+       u8 req_status;
+       u8 rsp_flag;    /* Indicates the type of Data_Payload.*/
+       u16 request_id;
+       u32 payload[1];
+};
+
+struct mvumi_ob_data {
+       struct list_head list;
+       unsigned char data[0];
+};
+
+struct version_info {
+       u32 ver_major;
+       u32 ver_minor;
+       u32 ver_oem;
+       u32 ver_build;
+};
+
+#define FW_MAX_DELAY                   30
+#define MVUMI_FW_BUSY                  (1U << 0)
+#define MVUMI_FW_ATTACH                        (1U << 1)
+#define MVUMI_FW_ALLOC                 (1U << 2)
+
+/*
+ * State is the state of the MU
+ */
+#define FW_STATE_IDLE                  0
+#define FW_STATE_STARTING              1
+#define FW_STATE_HANDSHAKING           2
+#define FW_STATE_STARTED               3
+#define FW_STATE_ABORT                 4
+
+#define HANDSHAKE_SIGNATURE            0x5A5A5A5AL
+#define HANDSHAKE_READYSTATE           0x55AA5AA5L
+#define HANDSHAKE_DONESTATE            0x55AAA55AL
+
+/* HandShake Status definition */
+#define HS_STATUS_OK                   1
+#define HS_STATUS_ERR                  2
+#define HS_STATUS_INVALID              3
+
+/* HandShake State/Cmd definition */
+#define HS_S_START                     1
+#define HS_S_RESET                     2
+#define HS_S_PAGE_ADDR                 3
+#define HS_S_QUERY_PAGE                        4
+#define HS_S_SEND_PAGE                 5
+#define HS_S_END                       6
+#define HS_S_ABORT                     7
+#define HS_PAGE_VERIFY_SIZE            128
+
+#define HS_GET_STATE(a)                        (a & 0xFFFF)
+#define HS_GET_STATUS(a)               ((a & 0xFFFF0000) >> 16)
+#define HS_SET_STATE(a, b)             (a |= (b & 0xFFFF))
+#define HS_SET_STATUS(a, b)            (a |= ((b & 0xFFFF) << 16))
+
+/* handshake frame */
+struct mvumi_hs_frame {
+       u16 size;
+       /* host information */
+       u8 host_type;
+       u8 reserved_1[1];
+       struct version_info host_ver; /* bios or driver version */
+
+       /* controller information */
+       u32 system_io_bus;
+       u32 slot_number;
+       u32 intr_level;
+       u32 intr_vector;
+
+       /* communication list configuration */
+       u32 ib_baseaddr_l;
+       u32 ib_baseaddr_h;
+       u32 ob_baseaddr_l;
+       u32 ob_baseaddr_h;
+
+       u8 ib_entry_size;
+       u8 ob_entry_size;
+       u8 ob_depth;
+       u8 ib_depth;
+
+       /* system time */
+       u64 seconds_since1970;
+};
+
+struct mvumi_hs_header {
+       u8      page_code;
+       u8      checksum;
+       u16     frame_length;
+       u32     frame_content[1];
+};
+
+/*
+ * the page code type of the handshake header
+ */
+#define HS_PAGE_FIRM_CAP       0x1
+#define HS_PAGE_HOST_INFO      0x2
+#define HS_PAGE_FIRM_CTL       0x3
+#define HS_PAGE_CL_INFO                0x4
+#define HS_PAGE_TOTAL          0x5
+
+#define HSP_SIZE(i)    sizeof(struct mvumi_hs_page##i)
+
+#define HSP_MAX_SIZE ({                                        \
+       int size, m1, m2;                               \
+       m1 = max(HSP_SIZE(1), HSP_SIZE(3));             \
+       m2 = max(HSP_SIZE(2), HSP_SIZE(4));             \
+       size = max(m1, m2);                             \
+       size;                                           \
+})
+
+/* The format of the page code for Firmware capability */
+struct mvumi_hs_page1 {
+       u8 pagecode;
+       u8 checksum;
+       u16 frame_length;
+
+       u16 number_of_ports;
+       u16 max_devices_support;
+       u16 max_io_support;
+       u16 umi_ver;
+       u32 max_transfer_size;
+       struct version_info fw_ver;
+       u8 cl_in_max_entry_size;
+       u8 cl_out_max_entry_size;
+       u8 cl_inout_list_depth;
+       u8 total_pages;
+       u16 capability;
+       u16 reserved1;
+};
+
+/* The format of the page code for Host information */
+struct mvumi_hs_page2 {
+       u8 pagecode;
+       u8 checksum;
+       u16 frame_length;
+
+       u8 host_type;
+       u8 reserved[3];
+       struct version_info host_ver;
+       u32 system_io_bus;
+       u32 slot_number;
+       u32 intr_level;
+       u32 intr_vector;
+       u64 seconds_since1970;
+};
+
+/* The format of the page code for firmware control  */
+struct mvumi_hs_page3 {
+       u8      pagecode;
+       u8      checksum;
+       u16     frame_length;
+       u16     control;
+       u8      reserved[2];
+       u32     host_bufferaddr_l;
+       u32     host_bufferaddr_h;
+       u32     host_eventaddr_l;
+       u32     host_eventaddr_h;
+};
+
+struct mvumi_hs_page4 {
+       u8      pagecode;
+       u8      checksum;
+       u16     frame_length;
+       u32     ib_baseaddr_l;
+       u32     ib_baseaddr_h;
+       u32     ob_baseaddr_l;
+       u32     ob_baseaddr_h;
+       u8      ib_entry_size;
+       u8      ob_entry_size;
+       u8      ob_depth;
+       u8      ib_depth;
+};
+
+struct mvumi_tag {
+       unsigned short *stack;
+       unsigned short top;
+       unsigned short size;
+};
+
+struct mvumi_hba {
+       void *base_addr[MAX_BASE_ADDRESS];
+       void *mmio;
+       struct list_head cmd_pool;
+       struct Scsi_Host *shost;
+       wait_queue_head_t int_cmd_wait_q;
+       struct pci_dev *pdev;
+       unsigned int unique_id;
+       atomic_t fw_outstanding;
+       struct mvumi_instance_template *instancet;
+
+       void *ib_list;
+       dma_addr_t ib_list_phys;
+
+       void *ob_list;
+       dma_addr_t ob_list_phys;
+
+       void *ib_shadow;
+       dma_addr_t ib_shadow_phys;
+
+       void *ob_shadow;
+       dma_addr_t ob_shadow_phys;
+
+       void *handshake_page;
+       dma_addr_t handshake_page_phys;
+
+       unsigned int global_isr;
+       unsigned int isr_status;
+
+       unsigned short max_sge;
+       unsigned short max_target_id;
+       unsigned char *target_map;
+       unsigned int max_io;
+       unsigned int list_num_io;
+       unsigned int ib_max_size;
+       unsigned int ob_max_size;
+       unsigned int ib_max_size_setting;
+       unsigned int ob_max_size_setting;
+       unsigned int max_transfer_size;
+       unsigned char hba_total_pages;
+       unsigned char fw_flag;
+       unsigned char request_id_enabled;
+       unsigned short hba_capability;
+       unsigned short io_seq;
+
+       unsigned int ib_cur_slot;
+       unsigned int ob_cur_slot;
+       unsigned int fw_state;
+
+       struct list_head ob_data_list;
+       struct list_head free_ob_list;
+       struct list_head res_list;
+       struct list_head waiting_req_list;
+
+       struct mvumi_tag tag_pool;
+       struct mvumi_cmd **tag_cmd;
+};
+
+struct mvumi_instance_template {
+       void (*fire_cmd)(struct mvumi_hba *, struct mvumi_cmd *);
+       void (*enable_intr)(void *) ;
+       void (*disable_intr)(void *);
+       int (*clear_intr)(void *);
+       unsigned int (*read_fw_status_reg)(void *);
+};
+
+extern struct timezone sys_tz;
+#endif
index 8b7db1e53c107f3bf04dc5ac015ef25948a1bd60..b7b92f7be2aa440afd1613149049f7bb5ea3993f 100644 (file)
@@ -567,11 +567,11 @@ static void init_pci_device_addresses(struct pm8001_hba_info *pm8001_ha)
        value = pm8001_cr32(pm8001_ha, 0, 0x44);
        offset = value & 0x03FFFFFF;
        PM8001_INIT_DBG(pm8001_ha,
-               pm8001_printk("Scratchpad 0 Offset: %x \n", offset));
+               pm8001_printk("Scratchpad 0 Offset: %x\n", offset));
        pcilogic = (value & 0xFC000000) >> 26;
        pcibar = get_pci_bar_index(pcilogic);
        PM8001_INIT_DBG(pm8001_ha,
-               pm8001_printk("Scratchpad 0 PCI BAR: %d \n", pcibar));
+               pm8001_printk("Scratchpad 0 PCI BAR: %d\n", pcibar));
        pm8001_ha->main_cfg_tbl_addr = base_addr =
                pm8001_ha->io_mem[pcibar].memvirtaddr + offset;
        pm8001_ha->general_stat_tbl_addr =
@@ -1245,7 +1245,7 @@ static int mpi_build_cmd(struct pm8001_hba_info *pm8001_ha,
 
        if (mpi_msg_free_get(circularQ, 64, &pMessage) < 0) {
                PM8001_IO_DBG(pm8001_ha,
-                       pm8001_printk("No free mpi buffer \n"));
+                       pm8001_printk("No free mpi buffer\n"));
                return -1;
        }
        BUG_ON(!payload);
@@ -1262,7 +1262,7 @@ static int mpi_build_cmd(struct pm8001_hba_info *pm8001_ha,
        pm8001_cw32(pm8001_ha, circularQ->pi_pci_bar,
                circularQ->pi_offset, circularQ->producer_idx);
        PM8001_IO_DBG(pm8001_ha,
-               pm8001_printk("after PI= %d CI= %d \n", circularQ->producer_idx,
+               pm8001_printk("after PI= %d CI= %d\n", circularQ->producer_idx,
                circularQ->consumer_index));
        return 0;
 }
@@ -1474,7 +1474,7 @@ mpi_ssp_completion(struct pm8001_hba_info *pm8001_ha , void *piomb)
        switch (status) {
        case IO_SUCCESS:
                PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_SUCCESS"
-                       ",param = %d \n", param));
+                       ",param = %d\n", param));
                if (param == 0) {
                        ts->resp = SAS_TASK_COMPLETE;
                        ts->stat = SAM_STAT_GOOD;
@@ -1490,14 +1490,14 @@ mpi_ssp_completion(struct pm8001_hba_info *pm8001_ha , void *piomb)
                break;
        case IO_ABORTED:
                PM8001_IO_DBG(pm8001_ha,
-                       pm8001_printk("IO_ABORTED IOMB Tag \n"));
+                       pm8001_printk("IO_ABORTED IOMB Tag\n"));
                ts->resp = SAS_TASK_COMPLETE;
                ts->stat = SAS_ABORTED_TASK;
                break;
        case IO_UNDERFLOW:
                /* SSP Completion with error */
                PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_UNDERFLOW"
-                       ",param = %d \n", param));
+                       ",param = %d\n", param));
                ts->resp = SAS_TASK_COMPLETE;
                ts->stat = SAS_DATA_UNDERRUN;
                ts->residual = param;
@@ -1649,6 +1649,7 @@ mpi_ssp_completion(struct pm8001_hba_info *pm8001_ha , void *piomb)
                ts->resp = SAS_TASK_COMPLETE;
                ts->stat = SAS_OPEN_REJECT;
                ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
+               break;
        default:
                PM8001_IO_DBG(pm8001_ha,
                        pm8001_printk("Unknown status 0x%x\n", status));
@@ -1937,14 +1938,14 @@ mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
                                ts->buf_valid_size = sizeof(*resp);
                        } else
                                PM8001_IO_DBG(pm8001_ha,
-                                       pm8001_printk("response to large \n"));
+                                       pm8001_printk("response to large\n"));
                }
                if (pm8001_dev)
                        pm8001_dev->running_req--;
                break;
        case IO_ABORTED:
                PM8001_IO_DBG(pm8001_ha,
-                       pm8001_printk("IO_ABORTED IOMB Tag \n"));
+                       pm8001_printk("IO_ABORTED IOMB Tag\n"));
                ts->resp = SAS_TASK_COMPLETE;
                ts->stat = SAS_ABORTED_TASK;
                if (pm8001_dev)
@@ -2728,11 +2729,11 @@ static int mpi_local_phy_ctl(struct pm8001_hba_info *pm8001_ha, void *piomb)
        u32 phy_op = le32_to_cpu(pPayload->phyop_phyid) & OP_BITS;
        if (status != 0) {
                PM8001_MSG_DBG(pm8001_ha,
-                       pm8001_printk("%x phy execute %x phy op failed! \n",
+                       pm8001_printk("%x phy execute %x phy op failed!\n",
                        phy_id, phy_op));
        } else
                PM8001_MSG_DBG(pm8001_ha,
-                       pm8001_printk("%x phy execute %x phy op success! \n",
+                       pm8001_printk("%x phy execute %x phy op success!\n",
                        phy_id, phy_op));
        return 0;
 }
@@ -3018,7 +3019,7 @@ hw_event_phy_down(struct pm8001_hba_info *pm8001_ha, void *piomb)
                break;
        case PORT_INVALID:
                PM8001_MSG_DBG(pm8001_ha,
-                       pm8001_printk(" PortInvalid portID %d \n", port_id));
+                       pm8001_printk(" PortInvalid portID %d\n", port_id));
                PM8001_MSG_DBG(pm8001_ha,
                        pm8001_printk(" Last phy Down and port invalid\n"));
                port->port_attached = 0;
@@ -3027,7 +3028,7 @@ hw_event_phy_down(struct pm8001_hba_info *pm8001_ha, void *piomb)
                break;
        case PORT_IN_RESET:
                PM8001_MSG_DBG(pm8001_ha,
-                       pm8001_printk(" Port In Reset portID %d \n", port_id));
+                       pm8001_printk(" Port In Reset portID %d\n", port_id));
                break;
        case PORT_NOT_ESTABLISHED:
                PM8001_MSG_DBG(pm8001_ha,
@@ -3220,7 +3221,7 @@ mpi_general_event(struct pm8001_hba_info *pm8001_ha , void *piomb)
                pm8001_printk(" status = 0x%x\n", status));
        for (i = 0; i < GENERAL_EVENT_PAYLOAD; i++)
                PM8001_MSG_DBG(pm8001_ha,
-                       pm8001_printk("inb_IOMB_payload[0x%x] 0x%x, \n", i,
+                       pm8001_printk("inb_IOMB_payload[0x%x] 0x%x,\n", i,
                        pPayload->inb_IOMB_payload[i]));
        return 0;
 }
@@ -3312,12 +3313,12 @@ static int mpi_hw_event(struct pm8001_hba_info *pm8001_ha, void* piomb)
                break;
        case HW_EVENT_SAS_PHY_UP:
                PM8001_MSG_DBG(pm8001_ha,
-                       pm8001_printk("HW_EVENT_PHY_START_STATUS \n"));
+                       pm8001_printk("HW_EVENT_PHY_START_STATUS\n"));
                hw_event_sas_phy_up(pm8001_ha, piomb);
                break;
        case HW_EVENT_SATA_PHY_UP:
                PM8001_MSG_DBG(pm8001_ha,
-                       pm8001_printk("HW_EVENT_SATA_PHY_UP \n"));
+                       pm8001_printk("HW_EVENT_SATA_PHY_UP\n"));
                hw_event_sata_phy_up(pm8001_ha, piomb);
                break;
        case HW_EVENT_PHY_STOP_STATUS:
@@ -3329,12 +3330,12 @@ static int mpi_hw_event(struct pm8001_hba_info *pm8001_ha, void* piomb)
                break;
        case HW_EVENT_SATA_SPINUP_HOLD:
                PM8001_MSG_DBG(pm8001_ha,
-                       pm8001_printk("HW_EVENT_SATA_SPINUP_HOLD \n"));
+                       pm8001_printk("HW_EVENT_SATA_SPINUP_HOLD\n"));
                sas_ha->notify_phy_event(&phy->sas_phy, PHYE_SPINUP_HOLD);
                break;
        case HW_EVENT_PHY_DOWN:
                PM8001_MSG_DBG(pm8001_ha,
-                       pm8001_printk("HW_EVENT_PHY_DOWN \n"));
+                       pm8001_printk("HW_EVENT_PHY_DOWN\n"));
                sas_ha->notify_phy_event(&phy->sas_phy, PHYE_LOSS_OF_SIGNAL);
                phy->phy_attached = 0;
                phy->phy_state = 0;
@@ -3446,7 +3447,7 @@ static int mpi_hw_event(struct pm8001_hba_info *pm8001_ha, void* piomb)
                break;
        case HW_EVENT_LINK_ERR_PHY_RESET_FAILED:
                PM8001_MSG_DBG(pm8001_ha,
-                       pm8001_printk("HW_EVENT_LINK_ERR_PHY_RESET_FAILED \n"));
+                       pm8001_printk("HW_EVENT_LINK_ERR_PHY_RESET_FAILED\n"));
                pm8001_hw_event_ack_req(pm8001_ha, 0,
                        HW_EVENT_LINK_ERR_PHY_RESET_FAILED,
                        port_id, phy_id, 0, 0);
@@ -3456,25 +3457,25 @@ static int mpi_hw_event(struct pm8001_hba_info *pm8001_ha, void* piomb)
                break;
        case HW_EVENT_PORT_RESET_TIMER_TMO:
                PM8001_MSG_DBG(pm8001_ha,
-                       pm8001_printk("HW_EVENT_PORT_RESET_TIMER_TMO \n"));
+                       pm8001_printk("HW_EVENT_PORT_RESET_TIMER_TMO\n"));
                sas_phy_disconnected(sas_phy);
                phy->phy_attached = 0;
                sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
                break;
        case HW_EVENT_PORT_RECOVERY_TIMER_TMO:
                PM8001_MSG_DBG(pm8001_ha,
-                       pm8001_printk("HW_EVENT_PORT_RECOVERY_TIMER_TMO \n"));
+                       pm8001_printk("HW_EVENT_PORT_RECOVERY_TIMER_TMO\n"));
                sas_phy_disconnected(sas_phy);
                phy->phy_attached = 0;
                sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
                break;
        case HW_EVENT_PORT_RECOVER:
                PM8001_MSG_DBG(pm8001_ha,
-                       pm8001_printk("HW_EVENT_PORT_RECOVER \n"));
+                       pm8001_printk("HW_EVENT_PORT_RECOVER\n"));
                break;
        case HW_EVENT_PORT_RESET_COMPLETE:
                PM8001_MSG_DBG(pm8001_ha,
-                       pm8001_printk("HW_EVENT_PORT_RESET_COMPLETE \n"));
+                       pm8001_printk("HW_EVENT_PORT_RESET_COMPLETE\n"));
                break;
        case EVENT_BROADCAST_ASYNCH_EVENT:
                PM8001_MSG_DBG(pm8001_ha,
@@ -3502,21 +3503,21 @@ static void process_one_iomb(struct pm8001_hba_info *pm8001_ha, void *piomb)
 
        switch (opc) {
        case OPC_OUB_ECHO:
-               PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_ECHO \n"));
+               PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_ECHO\n"));
                break;
        case OPC_OUB_HW_EVENT:
                PM8001_MSG_DBG(pm8001_ha,
-                       pm8001_printk("OPC_OUB_HW_EVENT \n"));
+                       pm8001_printk("OPC_OUB_HW_EVENT\n"));
                mpi_hw_event(pm8001_ha, piomb);
                break;
        case OPC_OUB_SSP_COMP:
                PM8001_MSG_DBG(pm8001_ha,
-                       pm8001_printk("OPC_OUB_SSP_COMP \n"));
+                       pm8001_printk("OPC_OUB_SSP_COMP\n"));
                mpi_ssp_completion(pm8001_ha, piomb);
                break;
        case OPC_OUB_SMP_COMP:
                PM8001_MSG_DBG(pm8001_ha,
-                       pm8001_printk("OPC_OUB_SMP_COMP \n"));
+                       pm8001_printk("OPC_OUB_SMP_COMP\n"));
                mpi_smp_completion(pm8001_ha, piomb);
                break;
        case OPC_OUB_LOCAL_PHY_CNTRL:
@@ -3526,26 +3527,26 @@ static void process_one_iomb(struct pm8001_hba_info *pm8001_ha, void *piomb)
                break;
        case OPC_OUB_DEV_REGIST:
                PM8001_MSG_DBG(pm8001_ha,
-                       pm8001_printk("OPC_OUB_DEV_REGIST \n"));
+                       pm8001_printk("OPC_OUB_DEV_REGIST\n"));
                mpi_reg_resp(pm8001_ha, piomb);
                break;
        case OPC_OUB_DEREG_DEV:
                PM8001_MSG_DBG(pm8001_ha,
-                       pm8001_printk("unresgister the deviece \n"));
+                       pm8001_printk("unresgister the deviece\n"));
                mpi_dereg_resp(pm8001_ha, piomb);
                break;
        case OPC_OUB_GET_DEV_HANDLE:
                PM8001_MSG_DBG(pm8001_ha,
-                       pm8001_printk("OPC_OUB_GET_DEV_HANDLE \n"));
+                       pm8001_printk("OPC_OUB_GET_DEV_HANDLE\n"));
                break;
        case OPC_OUB_SATA_COMP:
                PM8001_MSG_DBG(pm8001_ha,
-                       pm8001_printk("OPC_OUB_SATA_COMP \n"));
+                       pm8001_printk("OPC_OUB_SATA_COMP\n"));
                mpi_sata_completion(pm8001_ha, piomb);
                break;
        case OPC_OUB_SATA_EVENT:
                PM8001_MSG_DBG(pm8001_ha,
-                       pm8001_printk("OPC_OUB_SATA_EVENT \n"));
+                       pm8001_printk("OPC_OUB_SATA_EVENT\n"));
                mpi_sata_event(pm8001_ha, piomb);
                break;
        case OPC_OUB_SSP_EVENT:
@@ -3858,19 +3859,19 @@ static int pm8001_chip_sata_req(struct pm8001_hba_info *pm8001_ha,
        circularQ = &pm8001_ha->inbnd_q_tbl[0];
        if (task->data_dir == PCI_DMA_NONE) {
                ATAP = 0x04;  /* no data*/
-               PM8001_IO_DBG(pm8001_ha, pm8001_printk("no data \n"));
+               PM8001_IO_DBG(pm8001_ha, pm8001_printk("no data\n"));
        } else if (likely(!task->ata_task.device_control_reg_update)) {
                if (task->ata_task.dma_xfer) {
                        ATAP = 0x06; /* DMA */
-                       PM8001_IO_DBG(pm8001_ha, pm8001_printk("DMA \n"));
+                       PM8001_IO_DBG(pm8001_ha, pm8001_printk("DMA\n"));
                } else {
                        ATAP = 0x05; /* PIO*/
-                       PM8001_IO_DBG(pm8001_ha, pm8001_printk("PIO \n"));
+                       PM8001_IO_DBG(pm8001_ha, pm8001_printk("PIO\n"));
                }
                if (task->ata_task.use_ncq &&
                        dev->sata_dev.command_set != ATAPI_COMMAND_SET) {
                        ATAP = 0x07; /* FPDMA */
-                       PM8001_IO_DBG(pm8001_ha, pm8001_printk("FPDMA \n"));
+                       PM8001_IO_DBG(pm8001_ha, pm8001_printk("FPDMA\n"));
                }
        }
        if (task->ata_task.use_ncq && pm8001_get_ncq_tag(task, &hdr_tag))
index 172cefb6deb9436b2ace38f7f1477fb2d0dc40e2..c21a2163f9f6eb915072c1210b939dfeb29b479a 100644 (file)
@@ -61,7 +61,7 @@ static struct scsi_host_template pm8001_sht = {
        .name                   = DRV_NAME,
        .queuecommand           = sas_queuecommand,
        .target_alloc           = sas_target_alloc,
-       .slave_configure        = pm8001_slave_configure,
+       .slave_configure        = sas_slave_configure,
        .slave_destroy          = sas_slave_destroy,
        .scan_finished          = pm8001_scan_finished,
        .scan_start             = pm8001_scan_start,
@@ -76,7 +76,7 @@ static struct scsi_host_template pm8001_sht = {
        .use_clustering         = ENABLE_CLUSTERING,
        .eh_device_reset_handler = sas_eh_device_reset_handler,
        .eh_bus_reset_handler   = sas_eh_bus_reset_handler,
-       .slave_alloc            = pm8001_slave_alloc,
+       .slave_alloc            = sas_slave_alloc,
        .target_destroy         = sas_target_destroy,
        .ioctl                  = sas_ioctl,
        .shost_attrs            = pm8001_host_attrs,
index 6ae059ebb4bbd665a1beb59f30f2f1952fd33e38..fb3dc9978861284e575945331487122a56ddd6c3 100644 (file)
@@ -210,26 +210,12 @@ int pm8001_phy_control(struct asd_sas_phy *sas_phy, enum phy_func func,
                PM8001_CHIP_DISP->phy_stop_req(pm8001_ha, phy_id);
                break;
        default:
-               rc = -EOPNOTSUPP;
+               rc = -ENOSYS;
        }
        msleep(300);
        return rc;
 }
 
-int pm8001_slave_alloc(struct scsi_device *scsi_dev)
-{
-       struct domain_device *dev = sdev_to_domain_dev(scsi_dev);
-       if (dev_is_sata(dev)) {
-               /* We don't need to rescan targets
-               * if REPORT_LUNS request is failed
-               */
-               if (scsi_dev->lun > 0)
-                       return -ENXIO;
-               scsi_dev->tagged_supported = 1;
-       }
-       return sas_slave_alloc(scsi_dev);
-}
-
 /**
   * pm8001_scan_start - we should enable all HBA phys by sending the phy_start
   * command to HBA.
@@ -314,22 +300,7 @@ static int pm8001_task_prep_ssp(struct pm8001_hba_info *pm8001_ha,
 {
        return PM8001_CHIP_DISP->ssp_io_req(pm8001_ha, ccb);
 }
-int pm8001_slave_configure(struct scsi_device *sdev)
-{
-       struct domain_device *dev = sdev_to_domain_dev(sdev);
-       int ret = sas_slave_configure(sdev);
-       if (ret)
-               return ret;
-       if (dev_is_sata(dev)) {
-       #ifdef PM8001_DISABLE_NCQ
-               struct ata_port *ap = dev->sata_dev.ap;
-               struct ata_device *adev = ap->link.device;
-               adev->flags |= ATA_DFLAG_NCQ_OFF;
-               scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, 1);
-       #endif
-       }
-       return 0;
-}
+
  /* Find the local port id that's attached to this device */
 static int sas_find_local_port_id(struct domain_device *dev)
 {
@@ -385,21 +356,8 @@ static int pm8001_task_exec(struct sas_task *task, const int num,
        do {
                dev = t->dev;
                pm8001_dev = dev->lldd_dev;
-               if (DEV_IS_GONE(pm8001_dev)) {
-                       if (pm8001_dev) {
-                               PM8001_IO_DBG(pm8001_ha,
-                                       pm8001_printk("device %d not ready.\n",
-                                       pm8001_dev->device_id));
-                       } else {
-                               PM8001_IO_DBG(pm8001_ha,
-                                       pm8001_printk("device %016llx not "
-                                       "ready.\n", SAS_ADDR(dev->sas_addr)));
-                       }
-                       rc = SAS_PHY_DOWN;
-                       goto out_done;
-               }
                port = &pm8001_ha->port[sas_find_local_port_id(dev)];
-               if (!port->port_attached) {
+               if (DEV_IS_GONE(pm8001_dev) || !port->port_attached) {
                        if (sas_protocol_ata(t->task_proto)) {
                                struct task_status_struct *ts = &t->task_status;
                                ts->resp = SAS_TASK_UNDELIVERED;
@@ -651,7 +609,7 @@ static int pm8001_dev_found_notify(struct domain_device *dev)
                                flag = 1; /* directly sata*/
                }
        } /*register this device to HBA*/
-       PM8001_DISC_DBG(pm8001_ha, pm8001_printk("Found device \n"));
+       PM8001_DISC_DBG(pm8001_ha, pm8001_printk("Found device\n"));
        PM8001_CHIP_DISP->reg_dev_req(pm8001_ha, pm8001_device, flag);
        spin_unlock_irqrestore(&pm8001_ha->lock, flags);
        wait_for_completion(&completion);
@@ -669,30 +627,6 @@ int pm8001_dev_found(struct domain_device *dev)
        return pm8001_dev_found_notify(dev);
 }
 
-/**
-  * pm8001_alloc_task - allocate a task structure for TMF
-  */
-static struct sas_task *pm8001_alloc_task(void)
-{
-       struct sas_task *task = kzalloc(sizeof(*task), GFP_KERNEL);
-       if (task) {
-               INIT_LIST_HEAD(&task->list);
-               spin_lock_init(&task->task_state_lock);
-               task->task_state_flags = SAS_TASK_STATE_PENDING;
-               init_timer(&task->timer);
-               init_completion(&task->completion);
-       }
-       return task;
-}
-
-static void pm8001_free_task(struct sas_task *task)
-{
-       if (task) {
-               BUG_ON(!list_empty(&task->list));
-               kfree(task);
-       }
-}
-
 static void pm8001_task_done(struct sas_task *task)
 {
        if (!del_timer(&task->timer))
@@ -728,7 +662,7 @@ static int pm8001_exec_internal_tmf_task(struct domain_device *dev,
        struct pm8001_hba_info *pm8001_ha = pm8001_find_ha_by_dev(dev);
 
        for (retry = 0; retry < 3; retry++) {
-               task = pm8001_alloc_task();
+               task = sas_alloc_task(GFP_KERNEL);
                if (!task)
                        return -ENOMEM;
 
@@ -789,14 +723,13 @@ static int pm8001_exec_internal_tmf_task(struct domain_device *dev,
                                SAS_ADDR(dev->sas_addr),
                                task->task_status.resp,
                                task->task_status.stat));
-                       pm8001_free_task(task);
+                       sas_free_task(task);
                        task = NULL;
                }
        }
 ex_err:
        BUG_ON(retry == 3 && task != NULL);
-       if (task != NULL)
-               pm8001_free_task(task);
+       sas_free_task(task);
        return res;
 }
 
@@ -811,7 +744,7 @@ pm8001_exec_internal_task_abort(struct pm8001_hba_info *pm8001_ha,
        struct sas_task *task = NULL;
 
        for (retry = 0; retry < 3; retry++) {
-               task = pm8001_alloc_task();
+               task = sas_alloc_task(GFP_KERNEL);
                if (!task)
                        return -ENOMEM;
 
@@ -864,14 +797,13 @@ pm8001_exec_internal_task_abort(struct pm8001_hba_info *pm8001_ha,
                                SAS_ADDR(dev->sas_addr),
                                task->task_status.resp,
                                task->task_status.stat));
-                       pm8001_free_task(task);
+                       sas_free_task(task);
                        task = NULL;
                }
        }
 ex_err:
        BUG_ON(retry == 3 && task != NULL);
-       if (task != NULL)
-               pm8001_free_task(task);
+       sas_free_task(task);
        return res;
 }
 
@@ -1026,13 +958,14 @@ int pm8001_query_task(struct sas_task *task)
                /* The task is still in Lun, release it then */
                case TMF_RESP_FUNC_SUCC:
                        PM8001_EH_DBG(pm8001_ha,
-                               pm8001_printk("The task is still in Lun \n"));
+                               pm8001_printk("The task is still in Lun\n"));
+                       break;
                /* The task is not in Lun or failed, reset the phy */
                case TMF_RESP_FUNC_FAILED:
                case TMF_RESP_FUNC_COMPLETE:
                        PM8001_EH_DBG(pm8001_ha,
                        pm8001_printk("The task is not in Lun or failed,"
-                       " reset the phy \n"));
+                       " reset the phy\n"));
                        break;
                }
        }
index b97c8ab0c20e744f5b37ffe6e5e549381ada7c05..93959febe2051a9b0e51c8176000de09721c6f08 100644 (file)
@@ -471,8 +471,6 @@ void pm8001_ccb_task_free(struct pm8001_hba_info *pm8001_ha,
        struct sas_task *task, struct pm8001_ccb_info *ccb, u32 ccb_idx);
 int pm8001_phy_control(struct asd_sas_phy *sas_phy, enum phy_func func,
        void *funcdata);
-int pm8001_slave_alloc(struct scsi_device *scsi_dev);
-int pm8001_slave_configure(struct scsi_device *sdev);
 void pm8001_scan_start(struct Scsi_Host *shost);
 int pm8001_scan_finished(struct Scsi_Host *shost, unsigned long time);
 int pm8001_queue_command(struct sas_task *task, const int num,
index a31e05f3bfd4f214920b0b7a6ca4ba40b5f47676..ac326c41e931dcba508c6357708be557986b8d88 100644 (file)
@@ -23,11 +23,23 @@ qla2x00_sysfs_read_fw_dump(struct file *filp, struct kobject *kobj,
        struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
            struct device, kobj)));
        struct qla_hw_data *ha = vha->hw;
+       int rval = 0;
 
        if (ha->fw_dump_reading == 0)
                return 0;
 
-       return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
+       if (IS_QLA82XX(ha)) {
+               if (off < ha->md_template_size) {
+                       rval = memory_read_from_buffer(buf, count,
+                           &off, ha->md_tmplt_hdr, ha->md_template_size);
+                       return rval;
+               }
+               off -= ha->md_template_size;
+               rval = memory_read_from_buffer(buf, count,
+                   &off, ha->md_dump, ha->md_dump_size);
+               return rval;
+       } else
+               return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
                                        ha->fw_dump_len);
 }
 
@@ -41,12 +53,6 @@ qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj,
        struct qla_hw_data *ha = vha->hw;
        int reading;
 
-       if (IS_QLA82XX(ha)) {
-               ql_dbg(ql_dbg_user, vha, 0x705b,
-                   "Firmware dump not supported for ISP82xx\n");
-               return count;
-       }
-
        if (off != 0)
                return (0);
 
@@ -59,6 +65,10 @@ qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj,
                ql_log(ql_log_info, vha, 0x705d,
                    "Firmware dump cleared on (%ld).\n", vha->host_no);
 
+               if (IS_QLA82XX(vha->hw)) {
+                       qla82xx_md_free(vha);
+                       qla82xx_md_prep(vha);
+               }
                ha->fw_dump_reading = 0;
                ha->fw_dumped = 0;
                break;
@@ -75,10 +85,29 @@ qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj,
                qla2x00_alloc_fw_dump(vha);
                break;
        case 3:
-               qla2x00_system_error(vha);
+               if (IS_QLA82XX(ha)) {
+                       qla82xx_idc_lock(ha);
+                       qla82xx_set_reset_owner(vha);
+                       qla82xx_idc_unlock(ha);
+               } else
+                       qla2x00_system_error(vha);
+               break;
+       case 4:
+               if (IS_QLA82XX(ha)) {
+                       if (ha->md_tmplt_hdr)
+                               ql_dbg(ql_dbg_user, vha, 0x705b,
+                                   "MiniDump supported with this firmware.\n");
+                       else
+                               ql_dbg(ql_dbg_user, vha, 0x709d,
+                                   "MiniDump not supported with this firmware.\n");
+               }
+               break;
+       case 5:
+               if (IS_QLA82XX(ha))
+                       set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
                break;
        }
-       return (count);
+       return -EINVAL;
 }
 
 static struct bin_attribute sysfs_fw_dump_attr = {
@@ -122,7 +151,7 @@ qla2x00_sysfs_write_nvram(struct file *filp, struct kobject *kobj,
 
        if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
            !ha->isp_ops->write_nvram)
-               return 0;
+               return -EINVAL;
 
        /* Checksum NVRAM. */
        if (IS_FWI2_CAPABLE(ha)) {
@@ -165,7 +194,7 @@ qla2x00_sysfs_write_nvram(struct file *filp, struct kobject *kobj,
        qla2xxx_wake_dpc(vha);
        qla2x00_wait_for_chip_reset(vha);
 
-       return (count);
+       return count;
 }
 
 static struct bin_attribute sysfs_nvram_attr = {
@@ -239,10 +268,10 @@ qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
        int val, valid;
 
        if (off)
-               return 0;
+               return -EINVAL;
 
        if (unlikely(pci_channel_offline(ha->pdev)))
-               return 0;
+               return -EAGAIN;
 
        if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
                return -EINVAL;
@@ -253,7 +282,7 @@ qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
        case 0:
                if (ha->optrom_state != QLA_SREADING &&
                    ha->optrom_state != QLA_SWRITING)
-                       break;
+                       return -EINVAL;
 
                ha->optrom_state = QLA_SWAITING;
 
@@ -266,7 +295,7 @@ qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
                break;
        case 1:
                if (ha->optrom_state != QLA_SWAITING)
-                       break;
+                       return -EINVAL;
 
                ha->optrom_region_start = start;
                ha->optrom_region_size = start + size > ha->optrom_size ?
@@ -280,7 +309,7 @@ qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
                            "(%x).\n", ha->optrom_region_size);
 
                        ha->optrom_state = QLA_SWAITING;
-                       return count;
+                       return -ENOMEM;
                }
 
                if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
@@ -299,7 +328,7 @@ qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
                break;
        case 2:
                if (ha->optrom_state != QLA_SWAITING)
-                       break;
+                       return -EINVAL;
 
                /*
                 * We need to be more restrictive on which FLASH regions are
@@ -347,7 +376,7 @@ qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
                            "(%x)\n", ha->optrom_region_size);
 
                        ha->optrom_state = QLA_SWAITING;
-                       return count;
+                       return -ENOMEM;
                }
 
                ql_dbg(ql_dbg_user, vha, 0x7067,
@@ -358,7 +387,7 @@ qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
                break;
        case 3:
                if (ha->optrom_state != QLA_SWRITING)
-                       break;
+                       return -ENOMEM;
 
                if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
                        ql_log(ql_log_warn, vha, 0x7068,
@@ -374,7 +403,7 @@ qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
                    ha->optrom_region_start, ha->optrom_region_size);
                break;
        default:
-               count = -EINVAL;
+               return -EINVAL;
        }
        return count;
 }
@@ -398,10 +427,10 @@ qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj,
        struct qla_hw_data *ha = vha->hw;
 
        if (unlikely(pci_channel_offline(ha->pdev)))
-               return 0;
+               return -EAGAIN;
 
        if (!capable(CAP_SYS_ADMIN))
-               return 0;
+               return -EINVAL;
 
        if (IS_NOCACHE_VPD_TYPE(ha))
                ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
@@ -438,17 +467,17 @@ qla2x00_sysfs_write_vpd(struct file *filp, struct kobject *kobj,
 
        /* Update flash version information for 4Gb & above. */
        if (!IS_FWI2_CAPABLE(ha))
-               goto done;
+               return -EINVAL;
 
        tmp_data = vmalloc(256);
        if (!tmp_data) {
                ql_log(ql_log_warn, vha, 0x706b,
                    "Unable to allocate memory for VPD information update.\n");
-               goto done;
+               return -ENOMEM;
        }
        ha->isp_ops->get_flash_version(vha, tmp_data);
        vfree(tmp_data);
-done:
+
        return count;
 }
 
@@ -505,8 +534,7 @@ do_read:
                            "Unable to read SFP data (%x/%x/%x).\n", rval,
                            addr, offset);
 
-                       count = 0;
-                       break;
+                       return -EIO;
                }
                memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
                buf += SFP_BLOCK_SIZE;
@@ -536,7 +564,7 @@ qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj,
        int type;
 
        if (off != 0)
-               return 0;
+               return -EINVAL;
 
        type = simple_strtol(buf, NULL, 10);
        switch (type) {
@@ -546,13 +574,18 @@ qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj,
 
                scsi_block_requests(vha->host);
                set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
+               if (IS_QLA82XX(ha)) {
+                       qla82xx_idc_lock(ha);
+                       qla82xx_set_reset_owner(vha);
+                       qla82xx_idc_unlock(ha);
+               }
                qla2xxx_wake_dpc(vha);
                qla2x00_wait_for_chip_reset(vha);
                scsi_unblock_requests(vha->host);
                break;
        case 0x2025d:
                if (!IS_QLA81XX(ha))
-                       break;
+                       return -EPERM;
 
                ql_log(ql_log_info, vha, 0x706f,
                    "Issuing MPI reset.\n");
@@ -571,7 +604,7 @@ qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj,
                if (!IS_QLA82XX(ha) || vha != base_vha) {
                        ql_log(ql_log_info, vha, 0x7071,
                            "FCoE ctx reset no supported.\n");
-                       return count;
+                       return -EPERM;
                }
 
                ql_log(ql_log_info, vha, 0x7072,
@@ -607,7 +640,7 @@ qla2x00_sysfs_write_edc(struct file *filp, struct kobject *kobj,
        ha->edc_data_len = 0;
 
        if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
-               return 0;
+               return -EINVAL;
 
        if (!ha->edc_data) {
                ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
@@ -615,7 +648,7 @@ qla2x00_sysfs_write_edc(struct file *filp, struct kobject *kobj,
                if (!ha->edc_data) {
                        ql_log(ql_log_warn, vha, 0x7073,
                            "Unable to allocate memory for EDC write.\n");
-                       return 0;
+                       return -ENOMEM;
                }
        }
 
@@ -634,9 +667,9 @@ qla2x00_sysfs_write_edc(struct file *filp, struct kobject *kobj,
            dev, adr, len, opt);
        if (rval != QLA_SUCCESS) {
                ql_log(ql_log_warn, vha, 0x7074,
-                   "Unable to write EDC (%x) %02x:%04x:%02x:%02x\n",
+                   "Unable to write EDC (%x) %02x:%04x:%02x:%02hhx\n",
                    rval, dev, adr, opt, len, buf[8]);
-               return 0;
+               return -EIO;
        }
 
        return count;
@@ -665,7 +698,7 @@ qla2x00_sysfs_write_edc_status(struct file *filp, struct kobject *kobj,
        ha->edc_data_len = 0;
 
        if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
-               return 0;
+               return -EINVAL;
 
        if (!ha->edc_data) {
                ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
@@ -673,7 +706,7 @@ qla2x00_sysfs_write_edc_status(struct file *filp, struct kobject *kobj,
                if (!ha->edc_data) {
                        ql_log(ql_log_warn, vha, 0x708c,
                            "Unable to allocate memory for EDC status.\n");
-                       return 0;
+                       return -ENOMEM;
                }
        }
 
@@ -693,7 +726,7 @@ qla2x00_sysfs_write_edc_status(struct file *filp, struct kobject *kobj,
                ql_log(ql_log_info, vha, 0x7075,
                    "Unable to write EDC status (%x) %02x:%04x:%02x.\n",
                    rval, dev, adr, opt, len);
-               return 0;
+               return -EIO;
        }
 
        ha->edc_data_len = len;
@@ -805,7 +838,7 @@ qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj,
        if (!ha->dcbx_tlv) {
                ql_log(ql_log_warn, vha, 0x7078,
                    "Unable to allocate memory for DCBX TLV read-data.\n");
-               return 0;
+               return -ENOMEM;
        }
 
 do_read:
@@ -817,7 +850,7 @@ do_read:
        if (rval != QLA_SUCCESS) {
                ql_log(ql_log_warn, vha, 0x7079,
                    "Unable to read DCBX TLV (%x).\n", rval);
-               count = 0;
+               return -EIO;
        }
 
        memcpy(buf, ha->dcbx_tlv, count);
index 07d1767cd26b077bce15cfbd6a675595b32b7c99..8b641a8a0c74aed39307c73036de328e9cd11fee 100644 (file)
@@ -704,6 +704,7 @@ qla2x00_process_loopback(struct fc_bsg_job *bsg_job)
        elreq.options = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
 
        if ((ha->current_topology == ISP_CFG_F ||
+           (atomic_read(&vha->loop_state) == LOOP_DOWN) ||
            (IS_QLA81XX(ha) &&
            le32_to_cpu(*(uint32_t *)req_data) == ELS_OPCODE_BYTE
            && req_data_len == MAX_ELS_FRAME_PAYLOAD)) &&
@@ -1446,6 +1447,148 @@ qla2x00_update_optrom(struct fc_bsg_job *bsg_job)
        return rval;
 }
 
+static int
+qla2x00_update_fru_versions(struct fc_bsg_job *bsg_job)
+{
+       struct Scsi_Host *host = bsg_job->shost;
+       scsi_qla_host_t *vha = shost_priv(host);
+       struct qla_hw_data *ha = vha->hw;
+       int rval = 0;
+       uint8_t bsg[DMA_POOL_SIZE];
+       struct qla_image_version_list *list = (void *)bsg;
+       struct qla_image_version *image;
+       uint32_t count;
+       dma_addr_t sfp_dma;
+       void *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
+       if (!sfp) {
+               bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
+                   EXT_STATUS_NO_MEMORY;
+               goto done;
+       }
+
+       sg_copy_to_buffer(bsg_job->request_payload.sg_list,
+           bsg_job->request_payload.sg_cnt, list, sizeof(bsg));
+
+       image = list->version;
+       count = list->count;
+       while (count--) {
+               memcpy(sfp, &image->field_info, sizeof(image->field_info));
+               rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
+                   image->field_address.device, image->field_address.offset,
+                   sizeof(image->field_info), image->field_address.option);
+               if (rval) {
+                       bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
+                           EXT_STATUS_MAILBOX;
+                       goto dealloc;
+               }
+               image++;
+       }
+
+       bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
+
+dealloc:
+       dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
+
+done:
+       bsg_job->reply_len = sizeof(struct fc_bsg_reply);
+       bsg_job->reply->result = DID_OK << 16;
+       bsg_job->job_done(bsg_job);
+
+       return 0;
+}
+
+static int
+qla2x00_read_fru_status(struct fc_bsg_job *bsg_job)
+{
+       struct Scsi_Host *host = bsg_job->shost;
+       scsi_qla_host_t *vha = shost_priv(host);
+       struct qla_hw_data *ha = vha->hw;
+       int rval = 0;
+       uint8_t bsg[DMA_POOL_SIZE];
+       struct qla_status_reg *sr = (void *)bsg;
+       dma_addr_t sfp_dma;
+       uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
+       if (!sfp) {
+               bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
+                   EXT_STATUS_NO_MEMORY;
+               goto done;
+       }
+
+       sg_copy_to_buffer(bsg_job->request_payload.sg_list,
+           bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
+
+       rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
+           sr->field_address.device, sr->field_address.offset,
+           sizeof(sr->status_reg), sr->field_address.option);
+       sr->status_reg = *sfp;
+
+       if (rval) {
+               bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
+                   EXT_STATUS_MAILBOX;
+               goto dealloc;
+       }
+
+       sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
+           bsg_job->reply_payload.sg_cnt, sr, sizeof(*sr));
+
+       bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
+
+dealloc:
+       dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
+
+done:
+       bsg_job->reply_len = sizeof(struct fc_bsg_reply);
+       bsg_job->reply->reply_payload_rcv_len = sizeof(*sr);
+       bsg_job->reply->result = DID_OK << 16;
+       bsg_job->job_done(bsg_job);
+
+       return 0;
+}
+
+static int
+qla2x00_write_fru_status(struct fc_bsg_job *bsg_job)
+{
+       struct Scsi_Host *host = bsg_job->shost;
+       scsi_qla_host_t *vha = shost_priv(host);
+       struct qla_hw_data *ha = vha->hw;
+       int rval = 0;
+       uint8_t bsg[DMA_POOL_SIZE];
+       struct qla_status_reg *sr = (void *)bsg;
+       dma_addr_t sfp_dma;
+       uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
+       if (!sfp) {
+               bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
+                   EXT_STATUS_NO_MEMORY;
+               goto done;
+       }
+
+       sg_copy_to_buffer(bsg_job->request_payload.sg_list,
+           bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
+
+       *sfp = sr->status_reg;
+       rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
+           sr->field_address.device, sr->field_address.offset,
+           sizeof(sr->status_reg), sr->field_address.option);
+
+       if (rval) {
+               bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
+                   EXT_STATUS_MAILBOX;
+               goto dealloc;
+       }
+
+       bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
+
+dealloc:
+       dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
+
+done:
+       bsg_job->reply_len = sizeof(struct fc_bsg_reply);
+       bsg_job->reply->result = DID_OK << 16;
+       bsg_job->job_done(bsg_job);
+
+       return 0;
+}
+
 static int
 qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job)
 {
@@ -1474,6 +1617,15 @@ qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job)
        case QL_VND_UPDATE_FLASH:
                return qla2x00_update_optrom(bsg_job);
 
+       case QL_VND_SET_FRU_VERSION:
+               return qla2x00_update_fru_versions(bsg_job);
+
+       case QL_VND_READ_FRU_STATUS:
+               return qla2x00_read_fru_status(bsg_job);
+
+       case QL_VND_WRITE_FRU_STATUS:
+               return qla2x00_write_fru_status(bsg_job);
+
        default:
                bsg_job->reply->result = (DID_ERROR << 16);
                bsg_job->job_done(bsg_job);
index 0f0f54e35f06477d1a53fdc8a640030fbd197029..70caa63a8930e196229c1f8a5cd2654c7c21b597 100644 (file)
 #define QL_VND_FCP_PRIO_CFG_CMD        0x06
 #define QL_VND_READ_FLASH      0x07
 #define QL_VND_UPDATE_FLASH    0x08
+#define QL_VND_SET_FRU_VERSION 0x0B
+#define QL_VND_READ_FRU_STATUS 0x0C
+#define QL_VND_WRITE_FRU_STATUS        0x0D
+
+/* BSG Vendor specific subcode returns */
+#define EXT_STATUS_OK                  0
+#define EXT_STATUS_ERR                 1
+#define EXT_STATUS_INVALID_PARAM       6
+#define EXT_STATUS_MAILBOX             11
+#define EXT_STATUS_NO_MEMORY           17
 
 /* BSG definations for interpreting CommandSent field */
 #define INT_DEF_LB_LOOPBACK_CMD         0
@@ -141,4 +151,36 @@ struct qla_port_param {
        uint16_t mode;
        uint16_t speed;
 } __attribute__ ((packed));
+
+
+/* FRU VPD */
+
+#define MAX_FRU_SIZE   36
+
+struct qla_field_address {
+       uint16_t offset;
+       uint16_t device;
+       uint16_t option;
+} __packed;
+
+struct qla_field_info {
+       uint8_t version[MAX_FRU_SIZE];
+} __packed;
+
+struct qla_image_version {
+       struct qla_field_address field_address;
+       struct qla_field_info field_info;
+} __packed;
+
+struct qla_image_version_list {
+       uint32_t count;
+       struct qla_image_version version[0];
+} __packed;
+
+struct qla_status_reg {
+       struct qla_field_address field_address;
+       uint8_t status_reg;
+       uint8_t reserved[7];
+} __packed;
+
 #endif
index d79cd8a5f83181e29f41051f79e38331e1e91a22..9df4787715c0828df3dadd48cb149550600919e5 100644 (file)
@@ -12,7 +12,7 @@
  * |             Level            |   Last Value Used  |     Holes     |
  * ----------------------------------------------------------------------
  * | Module Init and Probe        |       0x0116       |               |
- * | Mailbox commands             |       0x1126       |               |
+ * | Mailbox commands             |       0x1129       |               |
  * | Device Discovery             |       0x2083       |               |
  * | Queue Command and IO tracing |       0x302e       |     0x3008     |
  * | DPC Thread                   |       0x401c       |               |
@@ -22,7 +22,7 @@
  * | Task Management              |       0x8041       |               |
  * | AER/EEH                      |       0x900f       |               |
  * | Virtual Port                 |       0xa007       |               |
- * | ISP82XX Specific             |       0xb04f       |               |
+ * | ISP82XX Specific             |       0xb051       |               |
  * | MultiQ                       |       0xc00b       |               |
  * | Misc                         |       0xd00b       |               |
  * ----------------------------------------------------------------------
@@ -403,7 +403,7 @@ qla25xx_copy_mq(struct qla_hw_data *ha, void *ptr, uint32_t **last_chain)
        return ptr + sizeof(struct qla2xxx_mq_chain);
 }
 
-static void
+void
 qla2xxx_dump_post_process(scsi_qla_host_t *vha, int rval)
 {
        struct qla_hw_data *ha = vha->hw;
index a03eaf40f377e91d10468f665b5ab8e60434aa5d..fcf052c50bf585db11d73d46a3ad43a06e5a09e3 100644 (file)
@@ -2438,7 +2438,8 @@ struct qla_hw_data {
                uint32_t        quiesce_owner:1;
                uint32_t        thermal_supported:1;
                uint32_t        isp82xx_reset_hdlr_active:1;
-               /* 26 bits */
+               uint32_t        isp82xx_reset_owner:1;
+               /* 28 bits */
        } flags;
 
        /* This spinlock is used to protect "io transactions", you must
@@ -2822,6 +2823,12 @@ struct qla_hw_data {
 
        uint8_t fw_type;
        __le32 file_prd_off;    /* File firmware product offset */
+
+       uint32_t        md_template_size;
+       void            *md_tmplt_hdr;
+       dma_addr_t      md_tmplt_hdr_dma;
+       void            *md_dump;
+       uint32_t        md_dump_size;
 };
 
 /*
index 29b1a3e282318b80164241f61c2b5f8be1a33b60..ce32d8135c9e36335f53722664eab61db46a0f18 100644 (file)
@@ -104,6 +104,8 @@ extern int ql2xenablehba_err_chk;
 extern int ql2xtargetreset;
 extern int ql2xdontresethba;
 extern unsigned int ql2xmaxlun;
+extern int ql2xmdcapmask;
+extern int ql2xmdenable;
 
 extern int qla2x00_loop_reset(scsi_qla_host_t *);
 extern void qla2x00_abort_all_cmds(scsi_qla_host_t *, int);
@@ -407,6 +409,8 @@ extern void qla2x00_beacon_blink(struct scsi_qla_host *);
 extern int qla24xx_beacon_on(struct scsi_qla_host *);
 extern int qla24xx_beacon_off(struct scsi_qla_host *);
 extern void qla24xx_beacon_blink(struct scsi_qla_host *);
+extern int qla82xx_beacon_on(struct scsi_qla_host *);
+extern int qla82xx_beacon_off(struct scsi_qla_host *);
 
 extern uint8_t *qla2x00_read_optrom_data(struct scsi_qla_host *, uint8_t *,
     uint32_t, uint32_t);
@@ -442,6 +446,7 @@ extern void qla2x00_dump_buffer_zipped(uint8_t *, uint32_t);
 extern void ql_dump_regs(uint32_t, scsi_qla_host_t *, int32_t);
 extern void ql_dump_buffer(uint32_t, scsi_qla_host_t *, int32_t,
        uint8_t *, uint32_t);
+extern void qla2xxx_dump_post_process(scsi_qla_host_t *, int);
 
 /*
  * Global Function Prototypes in qla_gs.c source file.
@@ -569,7 +574,10 @@ extern int qla82xx_mbx_intr_enable(scsi_qla_host_t *);
 extern int qla82xx_mbx_intr_disable(scsi_qla_host_t *);
 extern void qla82xx_start_iocbs(srb_t *);
 extern int qla82xx_fcoe_ctx_reset(scsi_qla_host_t *);
+extern int qla82xx_check_md_needed(scsi_qla_host_t *);
 extern void qla82xx_chip_reset_cleanup(scsi_qla_host_t *);
+extern int qla82xx_mbx_beacon_ctl(scsi_qla_host_t *, int);
+extern char *qdev_state(uint32_t);
 
 /* BSG related functions */
 extern int qla24xx_bsg_request(struct fc_bsg_job *);
@@ -579,4 +587,14 @@ extern int qla2x00_issue_iocb_timeout(scsi_qla_host_t *, void *,
        dma_addr_t, size_t, uint32_t);
 extern int qla2x00_get_idma_speed(scsi_qla_host_t *, uint16_t,
        uint16_t *, uint16_t *);
+
+/* Minidump related functions */
+extern int qla82xx_md_get_template_size(scsi_qla_host_t *);
+extern int qla82xx_md_get_template(scsi_qla_host_t *);
+extern int qla82xx_md_alloc(scsi_qla_host_t *);
+extern void qla82xx_md_free(scsi_qla_host_t *);
+extern int qla82xx_md_collect(scsi_qla_host_t *);
+extern void qla82xx_md_prep(scsi_qla_host_t *);
+extern void qla82xx_set_reset_owner(scsi_qla_host_t *);
+
 #endif /* _QLA_GBL_H */
index 37da04d3db2634a0f9fc17e55f7389eead88a27a..f03e915f187729f6b208a0e89398b2a0b8642214 100644 (file)
@@ -1480,13 +1480,19 @@ qla2x00_setup_chip(scsi_qla_host_t *vha)
                        if (rval == QLA_SUCCESS) {
 enable_82xx_npiv:
                                fw_major_version = ha->fw_major_version;
-                               rval = qla2x00_get_fw_version(vha,
-                                   &ha->fw_major_version,
-                                   &ha->fw_minor_version,
-                                   &ha->fw_subminor_version,
-                                   &ha->fw_attributes, &ha->fw_memory_size,
-                                   ha->mpi_version, &ha->mpi_capabilities,
-                                   ha->phy_version);
+                               if (IS_QLA82XX(ha))
+                                       qla82xx_check_md_needed(vha);
+                               else {
+                                       rval = qla2x00_get_fw_version(vha,
+                                           &ha->fw_major_version,
+                                           &ha->fw_minor_version,
+                                           &ha->fw_subminor_version,
+                                           &ha->fw_attributes,
+                                           &ha->fw_memory_size,
+                                           ha->mpi_version,
+                                           &ha->mpi_capabilities,
+                                           ha->phy_version);
+                               }
                                if (rval != QLA_SUCCESS)
                                        goto failed;
                                ha->flags.npiv_supported = 0;
@@ -1503,10 +1509,8 @@ enable_82xx_npiv:
                                    &ha->fw_xcb_count, NULL, NULL,
                                    &ha->max_npiv_vports, NULL);
 
-                               if (!fw_major_version && ql2xallocfwdump) {
-                                       if (!IS_QLA82XX(ha))
-                                               qla2x00_alloc_fw_dump(vha);
-                               }
+                               if (!fw_major_version && ql2xallocfwdump)
+                                       qla2x00_alloc_fw_dump(vha);
                        }
                } else {
                        ql_log(ql_log_fatal, vha, 0x00cd,
@@ -1924,7 +1928,7 @@ qla2x00_fw_ready(scsi_qla_host_t *vha)
                                        rval = qla84xx_init_chip(vha);
                                        if (rval != QLA_SUCCESS) {
                                                ql_log(ql_log_warn,
-                                                   vha, 0x8043,
+                                                   vha, 0x8026,
                                                    "Init chip failed.\n");
                                                break;
                                        }
@@ -1933,7 +1937,7 @@ qla2x00_fw_ready(scsi_qla_host_t *vha)
                                        cs84xx_time = jiffies - cs84xx_time;
                                        wtime += cs84xx_time;
                                        mtime += cs84xx_time;
-                                       ql_dbg(ql_dbg_taskm, vha, 0x8042,
+                                       ql_dbg(ql_dbg_taskm, vha, 0x8025,
                                            "Increasing wait time by %ld. "
                                            "New time %ld.\n", cs84xx_time,
                                            wtime);
@@ -5443,11 +5447,7 @@ qla82xx_restart_isp(scsi_qla_host_t *vha)
                clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
 
                /* Update the firmware version */
-               qla2x00_get_fw_version(vha, &ha->fw_major_version,
-                   &ha->fw_minor_version, &ha->fw_subminor_version,
-                   &ha->fw_attributes, &ha->fw_memory_size,
-                   ha->mpi_version, &ha->mpi_capabilities,
-                   ha->phy_version);
+               status = qla82xx_check_md_needed(vha);
 
                if (ha->fce) {
                        ha->flags.fce_enabled = 1;
index 8a7591f035e6f98937f70be6ecc70020ab5134e7..3474e86e98ab65177ee02358585e4310f81dd61f 100644 (file)
@@ -2060,6 +2060,11 @@ void qla24xx_process_response_queue(struct scsi_qla_host *vha,
                 case ELS_IOCB_TYPE:
                        qla24xx_els_ct_entry(vha, rsp->req, pkt, ELS_IOCB_TYPE);
                        break;
+               case MARKER_TYPE:
+                       /* Do nothing in this case, this check is to prevent it
+                        * from falling into default case
+                        */
+                       break;
                default:
                        /* Type Not Supported. */
                        ql_dbg(ql_dbg_async, vha, 0x5042,
index f7604ea1af836b58e10d587be15d15283301e3da..3b3cec9f6ac295dab131050b8a92d47eadb06999 100644 (file)
@@ -4186,3 +4186,130 @@ qla82xx_mbx_intr_disable(scsi_qla_host_t *vha)
 
        return rval;
 }
+
+int
+qla82xx_md_get_template_size(scsi_qla_host_t *vha)
+{
+       struct qla_hw_data *ha = vha->hw;
+       mbx_cmd_t mc;
+       mbx_cmd_t *mcp = &mc;
+       int rval = QLA_FUNCTION_FAILED;
+
+       ql_dbg(ql_dbg_mbx, vha, 0x111f, "Entered %s.\n", __func__);
+
+       memset(mcp->mb, 0 , sizeof(mcp->mb));
+       mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
+       mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
+       mcp->mb[2] = LSW(RQST_TMPLT_SIZE);
+       mcp->mb[3] = MSW(RQST_TMPLT_SIZE);
+
+       mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
+       mcp->in_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|
+           MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
+
+       mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
+       mcp->tov = MBX_TOV_SECONDS;
+       rval = qla2x00_mailbox_command(vha, mcp);
+
+       /* Always copy back return mailbox values. */
+       if (rval != QLA_SUCCESS) {
+               ql_dbg(ql_dbg_mbx, vha, 0x1120,
+                   "mailbox command FAILED=0x%x, subcode=%x.\n",
+                   (mcp->mb[1] << 16) | mcp->mb[0],
+                   (mcp->mb[3] << 16) | mcp->mb[2]);
+       } else {
+               ql_dbg(ql_dbg_mbx, vha, 0x1121, "Done %s.\n", __func__);
+               ha->md_template_size = ((mcp->mb[3] << 16) | mcp->mb[2]);
+               if (!ha->md_template_size) {
+                       ql_dbg(ql_dbg_mbx, vha, 0x1122,
+                           "Null template size obtained.\n");
+                       rval = QLA_FUNCTION_FAILED;
+               }
+       }
+       return rval;
+}
+
+int
+qla82xx_md_get_template(scsi_qla_host_t *vha)
+{
+       struct qla_hw_data *ha = vha->hw;
+       mbx_cmd_t mc;
+       mbx_cmd_t *mcp = &mc;
+       int rval = QLA_FUNCTION_FAILED;
+
+       ql_dbg(ql_dbg_mbx, vha, 0x1123, "Entered %s.\n", __func__);
+
+       ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
+          ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
+       if (!ha->md_tmplt_hdr) {
+               ql_log(ql_log_warn, vha, 0x1124,
+                   "Unable to allocate memory for Minidump template.\n");
+               return rval;
+       }
+
+       memset(mcp->mb, 0 , sizeof(mcp->mb));
+       mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
+       mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
+       mcp->mb[2] = LSW(RQST_TMPLT);
+       mcp->mb[3] = MSW(RQST_TMPLT);
+       mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma));
+       mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma));
+       mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma));
+       mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma));
+       mcp->mb[8] = LSW(ha->md_template_size);
+       mcp->mb[9] = MSW(ha->md_template_size);
+
+       mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
+       mcp->tov = MBX_TOV_SECONDS;
+       mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
+           MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
+       mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
+       rval = qla2x00_mailbox_command(vha, mcp);
+
+       if (rval != QLA_SUCCESS) {
+               ql_dbg(ql_dbg_mbx, vha, 0x1125,
+                   "mailbox command FAILED=0x%x, subcode=%x.\n",
+                   ((mcp->mb[1] << 16) | mcp->mb[0]),
+                   ((mcp->mb[3] << 16) | mcp->mb[2]));
+       } else
+               ql_dbg(ql_dbg_mbx, vha, 0x1126, "Done %s.\n", __func__);
+       return rval;
+}
+
+int
+qla82xx_mbx_beacon_ctl(scsi_qla_host_t *vha, int enable)
+{
+       int rval;
+       struct qla_hw_data *ha = vha->hw;
+       mbx_cmd_t mc;
+       mbx_cmd_t *mcp = &mc;
+
+       if (!IS_QLA82XX(ha))
+               return QLA_FUNCTION_FAILED;
+
+       ql_dbg(ql_dbg_mbx, vha, 0x1127,
+               "Entered %s.\n", __func__);
+
+       memset(mcp, 0, sizeof(mbx_cmd_t));
+       mcp->mb[0] = MBC_SET_LED_CONFIG;
+       if (enable)
+               mcp->mb[7] = 0xE;
+       else
+               mcp->mb[7] = 0xD;
+
+       mcp->out_mb = MBX_7|MBX_0;
+       mcp->in_mb = MBX_0;
+       mcp->tov = 30;
+       mcp->flags = 0;
+
+       rval = qla2x00_mailbox_command(vha, mcp);
+       if (rval != QLA_SUCCESS) {
+               ql_dbg(ql_dbg_mbx, vha, 0x1128,
+                   "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
+       } else {
+               ql_dbg(ql_dbg_mbx, vha, 0x1129,
+                   "Done %s.\n", __func__);
+       }
+
+       return rval;
+}
index 049807cda4199781eaa6c5cbd993d4451d14bc03..94bded5ddce4fe2f958dcdb8387c471eeaf790cf 100644 (file)
@@ -7,6 +7,8 @@
 #include "qla_def.h"
 #include <linux/delay.h>
 #include <linux/pci.h>
+#include <linux/ratelimit.h>
+#include <linux/vmalloc.h>
 #include <scsi/scsi_tcq.h>
 
 #define MASK(n)                        ((1ULL<<(n))-1)
@@ -328,7 +330,7 @@ unsigned qla82xx_crb_hub_agt[64] = {
 };
 
 /* Device states */
-char *qdev_state[] = {
+char *q_dev_state[] = {
         "Unknown",
        "Cold",
        "Initializing",
@@ -339,6 +341,11 @@ char *qdev_state[] = {
        "Quiescent",
 };
 
+char *qdev_state(uint32_t dev_state)
+{
+       return q_dev_state[dev_state];
+}
+
 /*
  * In: 'off' is offset from CRB space in 128M pci map
  * Out: 'off' is 2M pci map addr
@@ -2355,9 +2362,13 @@ qla82xx_need_reset(struct qla_hw_data *ha)
        uint32_t drv_state;
        int rval;
 
-       drv_state = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_STATE);
-       rval = drv_state & (QLA82XX_DRVST_RST_RDY << (ha->portnum * 4));
-       return rval;
+       if (ha->flags.isp82xx_reset_owner)
+               return 1;
+       else {
+               drv_state = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_STATE);
+               rval = drv_state & (QLA82XX_DRVST_RST_RDY << (ha->portnum * 4));
+               return rval;
+       }
 }
 
 static inline void
@@ -2374,8 +2385,8 @@ qla82xx_set_rst_ready(struct qla_hw_data *ha)
                drv_state = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_STATE);
        }
        drv_state |= (QLA82XX_DRVST_RST_RDY << (ha->portnum * 4));
-       ql_log(ql_log_info, vha, 0x00bb,
-           "drv_state = 0x%x.\n", drv_state);
+       ql_dbg(ql_dbg_init, vha, 0x00bb,
+           "drv_state = 0x%08x.\n", drv_state);
        qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, drv_state);
 }
 
@@ -2598,7 +2609,7 @@ qla2xx_build_scsi_type_6_iocbs(srb_t *sp, struct cmd_type_6 *cmd_pkt,
                        dsd_seg = (uint32_t *)&cmd_pkt->fcp_data_dseg_address;
                        *dsd_seg++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma));
                        *dsd_seg++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma));
-                       *dsd_seg++ = cpu_to_le32(dsd_list_len);
+                       cmd_pkt->fcp_data_dseg_len = cpu_to_le32(dsd_list_len);
                } else {
                        *cur_dsd++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma));
                        *cur_dsd++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma));
@@ -3529,6 +3540,7 @@ static void
 qla82xx_need_reset_handler(scsi_qla_host_t *vha)
 {
        uint32_t dev_state, drv_state, drv_active;
+       uint32_t active_mask = 0;
        unsigned long reset_timeout;
        struct qla_hw_data *ha = vha->hw;
        struct req_que *req = ha->req_q_map[0];
@@ -3541,15 +3553,32 @@ qla82xx_need_reset_handler(scsi_qla_host_t *vha)
                qla82xx_idc_lock(ha);
        }
 
-       qla82xx_set_rst_ready(ha);
+       drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
+       if (!ha->flags.isp82xx_reset_owner) {
+               ql_dbg(ql_dbg_p3p, vha, 0xb028,
+                   "reset_acknowledged by 0x%x\n", ha->portnum);
+               qla82xx_set_rst_ready(ha);
+       } else {
+               active_mask = ~(QLA82XX_DRV_ACTIVE << (ha->portnum * 4));
+               drv_active &= active_mask;
+               ql_dbg(ql_dbg_p3p, vha, 0xb029,
+                   "active_mask: 0x%08x\n", active_mask);
+       }
 
        /* wait for 10 seconds for reset ack from all functions */
        reset_timeout = jiffies + (ha->nx_reset_timeout * HZ);
 
        drv_state = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_STATE);
        drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
+       dev_state = qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
 
-       while (drv_state != drv_active) {
+       ql_dbg(ql_dbg_p3p, vha, 0xb02a,
+           "drv_state: 0x%08x, drv_active: 0x%08x, "
+           "dev_state: 0x%08x, active_mask: 0x%08x\n",
+           drv_state, drv_active, dev_state, active_mask);
+
+       while (drv_state != drv_active &&
+           dev_state != QLA82XX_DEV_INITIALIZING) {
                if (time_after_eq(jiffies, reset_timeout)) {
                        ql_log(ql_log_warn, vha, 0x00b5,
                            "Reset timeout.\n");
@@ -3560,22 +3589,86 @@ qla82xx_need_reset_handler(scsi_qla_host_t *vha)
                qla82xx_idc_lock(ha);
                drv_state = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_STATE);
                drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
+               if (ha->flags.isp82xx_reset_owner)
+                       drv_active &= active_mask;
+               dev_state = qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
        }
 
-       dev_state = qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
+       ql_dbg(ql_dbg_p3p, vha, 0xb02b,
+           "drv_state: 0x%08x, drv_active: 0x%08x, "
+           "dev_state: 0x%08x, active_mask: 0x%08x\n",
+           drv_state, drv_active, dev_state, active_mask);
+
        ql_log(ql_log_info, vha, 0x00b6,
            "Device state is 0x%x = %s.\n",
            dev_state,
-           dev_state < MAX_STATES ? qdev_state[dev_state] : "Unknown");
+           dev_state < MAX_STATES ? qdev_state(dev_state) : "Unknown");
 
        /* Force to DEV_COLD unless someone else is starting a reset */
-       if (dev_state != QLA82XX_DEV_INITIALIZING) {
+       if (dev_state != QLA82XX_DEV_INITIALIZING &&
+           dev_state != QLA82XX_DEV_COLD) {
                ql_log(ql_log_info, vha, 0x00b7,
                    "HW State: COLD/RE-INIT.\n");
                qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE, QLA82XX_DEV_COLD);
+               if (ql2xmdenable) {
+                       if (qla82xx_md_collect(vha))
+                               ql_log(ql_log_warn, vha, 0xb02c,
+                                   "Not able to collect minidump.\n");
+               } else
+                       ql_log(ql_log_warn, vha, 0xb04f,
+                           "Minidump disabled.\n");
        }
 }
 
+int
+qla82xx_check_md_needed(scsi_qla_host_t *vha)
+{
+       struct qla_hw_data *ha = vha->hw;
+       uint16_t fw_major_version, fw_minor_version, fw_subminor_version;
+       int rval = QLA_SUCCESS;
+
+       fw_major_version = ha->fw_major_version;
+       fw_minor_version = ha->fw_minor_version;
+       fw_subminor_version = ha->fw_subminor_version;
+
+       rval = qla2x00_get_fw_version(vha, &ha->fw_major_version,
+           &ha->fw_minor_version, &ha->fw_subminor_version,
+           &ha->fw_attributes, &ha->fw_memory_size,
+           ha->mpi_version, &ha->mpi_capabilities,
+           ha->phy_version);
+
+       if (rval != QLA_SUCCESS)
+               return rval;
+
+       if (ql2xmdenable) {
+               if (!ha->fw_dumped) {
+                       if (fw_major_version != ha->fw_major_version ||
+                           fw_minor_version != ha->fw_minor_version ||
+                           fw_subminor_version != ha->fw_subminor_version) {
+
+                               ql_log(ql_log_info, vha, 0xb02d,
+                                   "Firmware version differs "
+                                   "Previous version: %d:%d:%d - "
+                                   "New version: %d:%d:%d\n",
+                                   ha->fw_major_version,
+                                   ha->fw_minor_version,
+                                   ha->fw_subminor_version,
+                                   fw_major_version, fw_minor_version,
+                                   fw_subminor_version);
+                               /* Release MiniDump resources */
+                               qla82xx_md_free(vha);
+                               /* ALlocate MiniDump resources */
+                               qla82xx_md_prep(vha);
+                       } else
+                               ql_log(ql_log_info, vha, 0xb02e,
+                                   "Firmware dump available to retrieve\n",
+                                   vha->host_no);
+               }
+       }
+       return rval;
+}
+
+
 int
 qla82xx_check_fw_alive(scsi_qla_host_t *vha)
 {
@@ -3637,7 +3730,7 @@ qla82xx_device_state_handler(scsi_qla_host_t *vha)
        ql_log(ql_log_info, vha, 0x009b,
            "Device state is 0x%x = %s.\n",
            dev_state,
-           dev_state < MAX_STATES ? qdev_state[dev_state] : "Unknown");
+           dev_state < MAX_STATES ? qdev_state(dev_state) : "Unknown");
 
        /* wait for 30 seconds for device to go ready */
        dev_init_timeout = jiffies + (ha->nx_dev_init_timeout * HZ);
@@ -3659,26 +3752,33 @@ qla82xx_device_state_handler(scsi_qla_host_t *vha)
                        ql_log(ql_log_info, vha, 0x009d,
                            "Device state is 0x%x = %s.\n",
                            dev_state,
-                           dev_state < MAX_STATES ? qdev_state[dev_state] :
+                           dev_state < MAX_STATES ? qdev_state(dev_state) :
                            "Unknown");
                }
 
                switch (dev_state) {
                case QLA82XX_DEV_READY:
+                       qla82xx_check_md_needed(vha);
+                       ha->flags.isp82xx_reset_owner = 0;
                        goto exit;
                case QLA82XX_DEV_COLD:
                        rval = qla82xx_device_bootstrap(vha);
-                       goto exit;
+                       break;
                case QLA82XX_DEV_INITIALIZING:
                        qla82xx_idc_unlock(ha);
                        msleep(1000);
                        qla82xx_idc_lock(ha);
                        break;
                case QLA82XX_DEV_NEED_RESET:
-                   if (!ql2xdontresethba)
-                       qla82xx_need_reset_handler(vha);
+                       if (!ql2xdontresethba)
+                               qla82xx_need_reset_handler(vha);
+                       else {
+                               qla82xx_idc_unlock(ha);
+                               msleep(1000);
+                               qla82xx_idc_lock(ha);
+                       }
                        dev_init_timeout = jiffies +
-                               (ha->nx_dev_init_timeout * HZ);
+                           (ha->nx_dev_init_timeout * HZ);
                        break;
                case QLA82XX_DEV_NEED_QUIESCENT:
                        qla82xx_need_qsnt_handler(vha);
@@ -3791,6 +3891,28 @@ int qla82xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
        return rval;
 }
 
+void
+qla82xx_set_reset_owner(scsi_qla_host_t *vha)
+{
+       struct qla_hw_data *ha = vha->hw;
+       uint32_t dev_state;
+
+       dev_state = qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
+       if (dev_state == QLA82XX_DEV_READY) {
+               ql_log(ql_log_info, vha, 0xb02f,
+                   "HW State: NEED RESET\n");
+               qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
+                       QLA82XX_DEV_NEED_RESET);
+               ha->flags.isp82xx_reset_owner = 1;
+               ql_dbg(ql_dbg_p3p, vha, 0xb030,
+                   "reset_owner is 0x%x\n", ha->portnum);
+       } else
+               ql_log(ql_log_info, vha, 0xb031,
+                   "Device state is 0x%x = %s.\n",
+                   dev_state,
+                   dev_state < MAX_STATES ? qdev_state(dev_state) : "Unknown");
+}
+
 /*
  *  qla82xx_abort_isp
  *      Resets ISP and aborts all outstanding commands.
@@ -3806,7 +3928,6 @@ qla82xx_abort_isp(scsi_qla_host_t *vha)
 {
        int rval;
        struct qla_hw_data *ha = vha->hw;
-       uint32_t dev_state;
 
        if (vha->device_flags & DFLG_DEV_FAILED) {
                ql_log(ql_log_warn, vha, 0x8024,
@@ -3816,16 +3937,7 @@ qla82xx_abort_isp(scsi_qla_host_t *vha)
        ha->flags.isp82xx_reset_hdlr_active = 1;
 
        qla82xx_idc_lock(ha);
-       dev_state = qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
-       if (dev_state == QLA82XX_DEV_READY) {
-               ql_log(ql_log_info, vha, 0x8025,
-                   "HW State: NEED RESET.\n");
-               qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
-                       QLA82XX_DEV_NEED_RESET);
-       } else
-               ql_log(ql_log_info, vha, 0x8026,
-                   "Hw State: %s.\n", dev_state < MAX_STATES ?
-                   qdev_state[dev_state] : "Unknown");
+       qla82xx_set_reset_owner(vha);
        qla82xx_idc_unlock(ha);
 
        rval = qla82xx_device_state_handler(vha);
@@ -4016,3 +4128,803 @@ qla82xx_chip_reset_cleanup(scsi_qla_host_t *vha)
                }
        }
 }
+
+/* Minidump related functions */
+int
+qla82xx_md_rw_32(struct qla_hw_data *ha, uint32_t off, u32 data, uint8_t flag)
+{
+       uint32_t  off_value, rval = 0;
+
+       WRT_REG_DWORD((void *)(CRB_WINDOW_2M + ha->nx_pcibase),
+           (off & 0xFFFF0000));
+
+       /* Read back value to make sure write has gone through */
+       RD_REG_DWORD((void *)(CRB_WINDOW_2M + ha->nx_pcibase));
+       off_value  = (off & 0x0000FFFF);
+
+       if (flag)
+               WRT_REG_DWORD((void *)
+                   (off_value + CRB_INDIRECT_2M + ha->nx_pcibase),
+                   data);
+       else
+               rval = RD_REG_DWORD((void *)
+                   (off_value + CRB_INDIRECT_2M + ha->nx_pcibase));
+
+       return rval;
+}
+
+static int
+qla82xx_minidump_process_control(scsi_qla_host_t *vha,
+       qla82xx_md_entry_hdr_t *entry_hdr, uint32_t **d_ptr)
+{
+       struct qla_hw_data *ha = vha->hw;
+       struct qla82xx_md_entry_crb *crb_entry;
+       uint32_t read_value, opcode, poll_time;
+       uint32_t addr, index, crb_addr;
+       unsigned long wtime;
+       struct qla82xx_md_template_hdr *tmplt_hdr;
+       uint32_t rval = QLA_SUCCESS;
+       int i;
+
+       tmplt_hdr = (struct qla82xx_md_template_hdr *)ha->md_tmplt_hdr;
+       crb_entry = (struct qla82xx_md_entry_crb *)entry_hdr;
+       crb_addr = crb_entry->addr;
+
+       for (i = 0; i < crb_entry->op_count; i++) {
+               opcode = crb_entry->crb_ctrl.opcode;
+               if (opcode & QLA82XX_DBG_OPCODE_WR) {
+                       qla82xx_md_rw_32(ha, crb_addr,
+                           crb_entry->value_1, 1);
+                       opcode &= ~QLA82XX_DBG_OPCODE_WR;
+               }
+
+               if (opcode & QLA82XX_DBG_OPCODE_RW) {
+                       read_value = qla82xx_md_rw_32(ha, crb_addr, 0, 0);
+                       qla82xx_md_rw_32(ha, crb_addr, read_value, 1);
+                       opcode &= ~QLA82XX_DBG_OPCODE_RW;
+               }
+
+               if (opcode & QLA82XX_DBG_OPCODE_AND) {
+                       read_value = qla82xx_md_rw_32(ha, crb_addr, 0, 0);
+                       read_value &= crb_entry->value_2;
+                       opcode &= ~QLA82XX_DBG_OPCODE_AND;
+                       if (opcode & QLA82XX_DBG_OPCODE_OR) {
+                               read_value |= crb_entry->value_3;
+                               opcode &= ~QLA82XX_DBG_OPCODE_OR;
+                       }
+                       qla82xx_md_rw_32(ha, crb_addr, read_value, 1);
+               }
+
+               if (opcode & QLA82XX_DBG_OPCODE_OR) {
+                       read_value = qla82xx_md_rw_32(ha, crb_addr, 0, 0);
+                       read_value |= crb_entry->value_3;
+                       qla82xx_md_rw_32(ha, crb_addr, read_value, 1);
+                       opcode &= ~QLA82XX_DBG_OPCODE_OR;
+               }
+
+               if (opcode & QLA82XX_DBG_OPCODE_POLL) {
+                       poll_time = crb_entry->crb_strd.poll_timeout;
+                       wtime = jiffies + poll_time;
+                       read_value = qla82xx_md_rw_32(ha, crb_addr, 0, 0);
+
+                       do {
+                               if ((read_value & crb_entry->value_2)
+                                   == crb_entry->value_1)
+                                       break;
+                               else if (time_after_eq(jiffies, wtime)) {
+                                       /* capturing dump failed */
+                                       rval = QLA_FUNCTION_FAILED;
+                                       break;
+                               } else
+                                       read_value = qla82xx_md_rw_32(ha,
+                                           crb_addr, 0, 0);
+                       } while (1);
+                       opcode &= ~QLA82XX_DBG_OPCODE_POLL;
+               }
+
+               if (opcode & QLA82XX_DBG_OPCODE_RDSTATE) {
+                       if (crb_entry->crb_strd.state_index_a) {
+                               index = crb_entry->crb_strd.state_index_a;
+                               addr = tmplt_hdr->saved_state_array[index];
+                       } else
+                               addr = crb_addr;
+
+                       read_value = qla82xx_md_rw_32(ha, addr, 0, 0);
+                       index = crb_entry->crb_ctrl.state_index_v;
+                       tmplt_hdr->saved_state_array[index] = read_value;
+                       opcode &= ~QLA82XX_DBG_OPCODE_RDSTATE;
+               }
+
+               if (opcode & QLA82XX_DBG_OPCODE_WRSTATE) {
+                       if (crb_entry->crb_strd.state_index_a) {
+                               index = crb_entry->crb_strd.state_index_a;
+                               addr = tmplt_hdr->saved_state_array[index];
+                       } else
+                               addr = crb_addr;
+
+                       if (crb_entry->crb_ctrl.state_index_v) {
+                               index = crb_entry->crb_ctrl.state_index_v;
+                               read_value =
+                                   tmplt_hdr->saved_state_array[index];
+                       } else
+                               read_value = crb_entry->value_1;
+
+                       qla82xx_md_rw_32(ha, addr, read_value, 1);
+                       opcode &= ~QLA82XX_DBG_OPCODE_WRSTATE;
+               }
+
+               if (opcode & QLA82XX_DBG_OPCODE_MDSTATE) {
+                       index = crb_entry->crb_ctrl.state_index_v;
+                       read_value = tmplt_hdr->saved_state_array[index];
+                       read_value <<= crb_entry->crb_ctrl.shl;
+                       read_value >>= crb_entry->crb_ctrl.shr;
+                       if (crb_entry->value_2)
+                               read_value &= crb_entry->value_2;
+                       read_value |= crb_entry->value_3;
+                       read_value += crb_entry->value_1;
+                       tmplt_hdr->saved_state_array[index] = read_value;
+                       opcode &= ~QLA82XX_DBG_OPCODE_MDSTATE;
+               }
+               crb_addr += crb_entry->crb_strd.addr_stride;
+       }
+       return rval;
+}
+
+static void
+qla82xx_minidump_process_rdocm(scsi_qla_host_t *vha,
+       qla82xx_md_entry_hdr_t *entry_hdr, uint32_t **d_ptr)
+{
+       struct qla_hw_data *ha = vha->hw;
+       uint32_t r_addr, r_stride, loop_cnt, i, r_value;
+       struct qla82xx_md_entry_rdocm *ocm_hdr;
+       uint32_t *data_ptr = *d_ptr;
+
+       ocm_hdr = (struct qla82xx_md_entry_rdocm *)entry_hdr;
+       r_addr = ocm_hdr->read_addr;
+       r_stride = ocm_hdr->read_addr_stride;
+       loop_cnt = ocm_hdr->op_count;
+
+       for (i = 0; i < loop_cnt; i++) {
+               r_value = RD_REG_DWORD((void *)(r_addr + ha->nx_pcibase));
+               *data_ptr++ = cpu_to_le32(r_value);
+               r_addr += r_stride;
+       }
+       *d_ptr = data_ptr;
+}
+
+static void
+qla82xx_minidump_process_rdmux(scsi_qla_host_t *vha,
+       qla82xx_md_entry_hdr_t *entry_hdr, uint32_t **d_ptr)
+{
+       struct qla_hw_data *ha = vha->hw;
+       uint32_t r_addr, s_stride, s_addr, s_value, loop_cnt, i, r_value;
+       struct qla82xx_md_entry_mux *mux_hdr;
+       uint32_t *data_ptr = *d_ptr;
+
+       mux_hdr = (struct qla82xx_md_entry_mux *)entry_hdr;
+       r_addr = mux_hdr->read_addr;
+       s_addr = mux_hdr->select_addr;
+       s_stride = mux_hdr->select_value_stride;
+       s_value = mux_hdr->select_value;
+       loop_cnt = mux_hdr->op_count;
+
+       for (i = 0; i < loop_cnt; i++) {
+               qla82xx_md_rw_32(ha, s_addr, s_value, 1);
+               r_value = qla82xx_md_rw_32(ha, r_addr, 0, 0);
+               *data_ptr++ = cpu_to_le32(s_value);
+               *data_ptr++ = cpu_to_le32(r_value);
+               s_value += s_stride;
+       }
+       *d_ptr = data_ptr;
+}
+
+static void
+qla82xx_minidump_process_rdcrb(scsi_qla_host_t *vha,
+       qla82xx_md_entry_hdr_t *entry_hdr, uint32_t **d_ptr)
+{
+       struct qla_hw_data *ha = vha->hw;
+       uint32_t r_addr, r_stride, loop_cnt, i, r_value;
+       struct qla82xx_md_entry_crb *crb_hdr;
+       uint32_t *data_ptr = *d_ptr;
+
+       crb_hdr = (struct qla82xx_md_entry_crb *)entry_hdr;
+       r_addr = crb_hdr->addr;
+       r_stride = crb_hdr->crb_strd.addr_stride;
+       loop_cnt = crb_hdr->op_count;
+
+       for (i = 0; i < loop_cnt; i++) {
+               r_value = qla82xx_md_rw_32(ha, r_addr, 0, 0);
+               *data_ptr++ = cpu_to_le32(r_addr);
+               *data_ptr++ = cpu_to_le32(r_value);
+               r_addr += r_stride;
+       }
+       *d_ptr = data_ptr;
+}
+
+static int
+qla82xx_minidump_process_l2tag(scsi_qla_host_t *vha,
+       qla82xx_md_entry_hdr_t *entry_hdr, uint32_t **d_ptr)
+{
+       struct qla_hw_data *ha = vha->hw;
+       uint32_t addr, r_addr, c_addr, t_r_addr;
+       uint32_t i, k, loop_count, t_value, r_cnt, r_value;
+       unsigned long p_wait, w_time, p_mask;
+       uint32_t c_value_w, c_value_r;
+       struct qla82xx_md_entry_cache *cache_hdr;
+       int rval = QLA_FUNCTION_FAILED;
+       uint32_t *data_ptr = *d_ptr;
+
+       cache_hdr = (struct qla82xx_md_entry_cache *)entry_hdr;
+       loop_count = cache_hdr->op_count;
+       r_addr = cache_hdr->read_addr;
+       c_addr = cache_hdr->control_addr;
+       c_value_w = cache_hdr->cache_ctrl.write_value;
+
+       t_r_addr = cache_hdr->tag_reg_addr;
+       t_value = cache_hdr->addr_ctrl.init_tag_value;
+       r_cnt = cache_hdr->read_ctrl.read_addr_cnt;
+       p_wait = cache_hdr->cache_ctrl.poll_wait;
+       p_mask = cache_hdr->cache_ctrl.poll_mask;
+
+       for (i = 0; i < loop_count; i++) {
+               qla82xx_md_rw_32(ha, t_r_addr, t_value, 1);
+               if (c_value_w)
+                       qla82xx_md_rw_32(ha, c_addr, c_value_w, 1);
+
+               if (p_mask) {
+                       w_time = jiffies + p_wait;
+                       do {
+                               c_value_r = qla82xx_md_rw_32(ha, c_addr, 0, 0);
+                               if ((c_value_r & p_mask) == 0)
+                                       break;
+                               else if (time_after_eq(jiffies, w_time)) {
+                                       /* capturing dump failed */
+                                       ql_dbg(ql_dbg_p3p, vha, 0xb032,
+                                           "c_value_r: 0x%x, poll_mask: 0x%lx, "
+                                           "w_time: 0x%lx\n",
+                                           c_value_r, p_mask, w_time);
+                                       return rval;
+                               }
+                       } while (1);
+               }
+
+               addr = r_addr;
+               for (k = 0; k < r_cnt; k++) {
+                       r_value = qla82xx_md_rw_32(ha, addr, 0, 0);
+                       *data_ptr++ = cpu_to_le32(r_value);
+                       addr += cache_hdr->read_ctrl.read_addr_stride;
+               }
+               t_value += cache_hdr->addr_ctrl.tag_value_stride;
+       }
+       *d_ptr = data_ptr;
+       return QLA_SUCCESS;
+}
+
+static void
+qla82xx_minidump_process_l1cache(scsi_qla_host_t *vha,
+       qla82xx_md_entry_hdr_t *entry_hdr, uint32_t **d_ptr)
+{
+       struct qla_hw_data *ha = vha->hw;
+       uint32_t addr, r_addr, c_addr, t_r_addr;
+       uint32_t i, k, loop_count, t_value, r_cnt, r_value;
+       uint32_t c_value_w;
+       struct qla82xx_md_entry_cache *cache_hdr;
+       uint32_t *data_ptr = *d_ptr;
+
+       cache_hdr = (struct qla82xx_md_entry_cache *)entry_hdr;
+       loop_count = cache_hdr->op_count;
+       r_addr = cache_hdr->read_addr;
+       c_addr = cache_hdr->control_addr;
+       c_value_w = cache_hdr->cache_ctrl.write_value;
+
+       t_r_addr = cache_hdr->tag_reg_addr;
+       t_value = cache_hdr->addr_ctrl.init_tag_value;
+       r_cnt = cache_hdr->read_ctrl.read_addr_cnt;
+
+       for (i = 0; i < loop_count; i++) {
+               qla82xx_md_rw_32(ha, t_r_addr, t_value, 1);
+               qla82xx_md_rw_32(ha, c_addr, c_value_w, 1);
+               addr = r_addr;
+               for (k = 0; k < r_cnt; k++) {
+                       r_value = qla82xx_md_rw_32(ha, addr, 0, 0);
+                       *data_ptr++ = cpu_to_le32(r_value);
+                       addr += cache_hdr->read_ctrl.read_addr_stride;
+               }
+               t_value += cache_hdr->addr_ctrl.tag_value_stride;
+       }
+       *d_ptr = data_ptr;
+}
+
+static void
+qla82xx_minidump_process_queue(scsi_qla_host_t *vha,
+       qla82xx_md_entry_hdr_t *entry_hdr, uint32_t **d_ptr)
+{
+       struct qla_hw_data *ha = vha->hw;
+       uint32_t s_addr, r_addr;
+       uint32_t r_stride, r_value, r_cnt, qid = 0;
+       uint32_t i, k, loop_cnt;
+       struct qla82xx_md_entry_queue *q_hdr;
+       uint32_t *data_ptr = *d_ptr;
+
+       q_hdr = (struct qla82xx_md_entry_queue *)entry_hdr;
+       s_addr = q_hdr->select_addr;
+       r_cnt = q_hdr->rd_strd.read_addr_cnt;
+       r_stride = q_hdr->rd_strd.read_addr_stride;
+       loop_cnt = q_hdr->op_count;
+
+       for (i = 0; i < loop_cnt; i++) {
+               qla82xx_md_rw_32(ha, s_addr, qid, 1);
+               r_addr = q_hdr->read_addr;
+               for (k = 0; k < r_cnt; k++) {
+                       r_value = qla82xx_md_rw_32(ha, r_addr, 0, 0);
+                       *data_ptr++ = cpu_to_le32(r_value);
+                       r_addr += r_stride;
+               }
+               qid += q_hdr->q_strd.queue_id_stride;
+       }
+       *d_ptr = data_ptr;
+}
+
+static void
+qla82xx_minidump_process_rdrom(scsi_qla_host_t *vha,
+       qla82xx_md_entry_hdr_t *entry_hdr, uint32_t **d_ptr)
+{
+       struct qla_hw_data *ha = vha->hw;
+       uint32_t r_addr, r_value;
+       uint32_t i, loop_cnt;
+       struct qla82xx_md_entry_rdrom *rom_hdr;
+       uint32_t *data_ptr = *d_ptr;
+
+       rom_hdr = (struct qla82xx_md_entry_rdrom *)entry_hdr;
+       r_addr = rom_hdr->read_addr;
+       loop_cnt = rom_hdr->read_data_size/sizeof(uint32_t);
+
+       for (i = 0; i < loop_cnt; i++) {
+               qla82xx_md_rw_32(ha, MD_DIRECT_ROM_WINDOW,
+                   (r_addr & 0xFFFF0000), 1);
+               r_value = qla82xx_md_rw_32(ha,
+                   MD_DIRECT_ROM_READ_BASE +
+                   (r_addr & 0x0000FFFF), 0, 0);
+               *data_ptr++ = cpu_to_le32(r_value);
+               r_addr += sizeof(uint32_t);
+       }
+       *d_ptr = data_ptr;
+}
+
+static int
+qla82xx_minidump_process_rdmem(scsi_qla_host_t *vha,
+       qla82xx_md_entry_hdr_t *entry_hdr, uint32_t **d_ptr)
+{
+       struct qla_hw_data *ha = vha->hw;
+       uint32_t r_addr, r_value, r_data;
+       uint32_t i, j, loop_cnt;
+       struct qla82xx_md_entry_rdmem *m_hdr;
+       unsigned long flags;
+       int rval = QLA_FUNCTION_FAILED;
+       uint32_t *data_ptr = *d_ptr;
+
+       m_hdr = (struct qla82xx_md_entry_rdmem *)entry_hdr;
+       r_addr = m_hdr->read_addr;
+       loop_cnt = m_hdr->read_data_size/16;
+
+       if (r_addr & 0xf) {
+               ql_log(ql_log_warn, vha, 0xb033,
+                   "Read addr 0x%x not 16 bytes alligned\n", r_addr);
+               return rval;
+       }
+
+       if (m_hdr->read_data_size % 16) {
+               ql_log(ql_log_warn, vha, 0xb034,
+                   "Read data[0x%x] not multiple of 16 bytes\n",
+                   m_hdr->read_data_size);
+               return rval;
+       }
+
+       ql_dbg(ql_dbg_p3p, vha, 0xb035,
+           "[%s]: rdmem_addr: 0x%x, read_data_size: 0x%x, loop_cnt: 0x%x\n",
+           __func__, r_addr, m_hdr->read_data_size, loop_cnt);
+
+       write_lock_irqsave(&ha->hw_lock, flags);
+       for (i = 0; i < loop_cnt; i++) {
+               qla82xx_md_rw_32(ha, MD_MIU_TEST_AGT_ADDR_LO, r_addr, 1);
+               r_value = 0;
+               qla82xx_md_rw_32(ha, MD_MIU_TEST_AGT_ADDR_HI, r_value, 1);
+               r_value = MIU_TA_CTL_ENABLE;
+               qla82xx_md_rw_32(ha, MD_MIU_TEST_AGT_CTRL, r_value, 1);
+               r_value = MIU_TA_CTL_START | MIU_TA_CTL_ENABLE;
+               qla82xx_md_rw_32(ha, MD_MIU_TEST_AGT_CTRL, r_value, 1);
+
+               for (j = 0; j < MAX_CTL_CHECK; j++) {
+                       r_value = qla82xx_md_rw_32(ha,
+                           MD_MIU_TEST_AGT_CTRL, 0, 0);
+                       if ((r_value & MIU_TA_CTL_BUSY) == 0)
+                               break;
+               }
+
+               if (j >= MAX_CTL_CHECK) {
+                       printk_ratelimited(KERN_ERR
+                           "failed to read through agent\n");
+                       write_unlock_irqrestore(&ha->hw_lock, flags);
+                       return rval;
+               }
+
+               for (j = 0; j < 4; j++) {
+                       r_data = qla82xx_md_rw_32(ha,
+                           MD_MIU_TEST_AGT_RDDATA[j], 0, 0);
+                       *data_ptr++ = cpu_to_le32(r_data);
+               }
+               r_addr += 16;
+       }
+       write_unlock_irqrestore(&ha->hw_lock, flags);
+       *d_ptr = data_ptr;
+       return QLA_SUCCESS;
+}
+
+static int
+qla82xx_validate_template_chksum(scsi_qla_host_t *vha)
+{
+       struct qla_hw_data *ha = vha->hw;
+       uint64_t chksum = 0;
+       uint32_t *d_ptr = (uint32_t *)ha->md_tmplt_hdr;
+       int count = ha->md_template_size/sizeof(uint32_t);
+
+       while (count-- > 0)
+               chksum += *d_ptr++;
+       while (chksum >> 32)
+               chksum = (chksum & 0xFFFFFFFF) + (chksum >> 32);
+       return ~chksum;
+}
+
+static void
+qla82xx_mark_entry_skipped(scsi_qla_host_t *vha,
+       qla82xx_md_entry_hdr_t *entry_hdr, int index)
+{
+       entry_hdr->d_ctrl.driver_flags |= QLA82XX_DBG_SKIPPED_FLAG;
+       ql_dbg(ql_dbg_p3p, vha, 0xb036,
+           "Skipping entry[%d]: "
+           "ETYPE[0x%x]-ELEVEL[0x%x]\n",
+           index, entry_hdr->entry_type,
+           entry_hdr->d_ctrl.entry_capture_mask);
+}
+
+int
+qla82xx_md_collect(scsi_qla_host_t *vha)
+{
+       struct qla_hw_data *ha = vha->hw;
+       int no_entry_hdr = 0;
+       qla82xx_md_entry_hdr_t *entry_hdr;
+       struct qla82xx_md_template_hdr *tmplt_hdr;
+       uint32_t *data_ptr;
+       uint32_t total_data_size = 0, f_capture_mask, data_collected = 0;
+       int i = 0, rval = QLA_FUNCTION_FAILED;
+
+       tmplt_hdr = (struct qla82xx_md_template_hdr *)ha->md_tmplt_hdr;
+       data_ptr = (uint32_t *)ha->md_dump;
+
+       if (ha->fw_dumped) {
+               ql_log(ql_log_info, vha, 0xb037,
+                   "Firmware dump available to retrive\n");
+               goto md_failed;
+       }
+
+       ha->fw_dumped = 0;
+
+       if (!ha->md_tmplt_hdr || !ha->md_dump) {
+               ql_log(ql_log_warn, vha, 0xb038,
+                   "Memory not allocated for minidump capture\n");
+               goto md_failed;
+       }
+
+       if (qla82xx_validate_template_chksum(vha)) {
+               ql_log(ql_log_info, vha, 0xb039,
+                   "Template checksum validation error\n");
+               goto md_failed;
+       }
+
+       no_entry_hdr = tmplt_hdr->num_of_entries;
+       ql_dbg(ql_dbg_p3p, vha, 0xb03a,
+           "No of entry headers in Template: 0x%x\n", no_entry_hdr);
+
+       ql_dbg(ql_dbg_p3p, vha, 0xb03b,
+           "Capture Mask obtained: 0x%x\n", tmplt_hdr->capture_debug_level);
+
+       f_capture_mask = tmplt_hdr->capture_debug_level & 0xFF;
+
+       /* Validate whether required debug level is set */
+       if ((f_capture_mask & 0x3) != 0x3) {
+               ql_log(ql_log_warn, vha, 0xb03c,
+                   "Minimum required capture mask[0x%x] level not set\n",
+                   f_capture_mask);
+               goto md_failed;
+       }
+       tmplt_hdr->driver_capture_mask = ql2xmdcapmask;
+
+       tmplt_hdr->driver_info[0] = vha->host_no;
+       tmplt_hdr->driver_info[1] = (QLA_DRIVER_MAJOR_VER << 24) |
+           (QLA_DRIVER_MINOR_VER << 16) | (QLA_DRIVER_PATCH_VER << 8) |
+           QLA_DRIVER_BETA_VER;
+
+       total_data_size = ha->md_dump_size;
+
+       ql_dbg(ql_log_info, vha, 0xb03d,
+           "Total minidump data_size 0x%x to be captured\n", total_data_size);
+
+       /* Check whether template obtained is valid */
+       if (tmplt_hdr->entry_type != QLA82XX_TLHDR) {
+               ql_log(ql_log_warn, vha, 0xb04e,
+                   "Bad template header entry type: 0x%x obtained\n",
+                   tmplt_hdr->entry_type);
+               goto md_failed;
+       }
+
+       entry_hdr = (qla82xx_md_entry_hdr_t *) \
+           (((uint8_t *)ha->md_tmplt_hdr) + tmplt_hdr->first_entry_offset);
+
+       /* Walk through the entry headers */
+       for (i = 0; i < no_entry_hdr; i++) {
+
+               if (data_collected > total_data_size) {
+                       ql_log(ql_log_warn, vha, 0xb03e,
+                           "More MiniDump data collected: [0x%x]\n",
+                           data_collected);
+                       goto md_failed;
+               }
+
+               if (!(entry_hdr->d_ctrl.entry_capture_mask &
+                   ql2xmdcapmask)) {
+                       entry_hdr->d_ctrl.driver_flags |=
+                           QLA82XX_DBG_SKIPPED_FLAG;
+                       ql_dbg(ql_dbg_p3p, vha, 0xb03f,
+                           "Skipping entry[%d]: "
+                           "ETYPE[0x%x]-ELEVEL[0x%x]\n",
+                           i, entry_hdr->entry_type,
+                           entry_hdr->d_ctrl.entry_capture_mask);
+                       goto skip_nxt_entry;
+               }
+
+               ql_dbg(ql_dbg_p3p, vha, 0xb040,
+                   "[%s]: data ptr[%d]: %p, entry_hdr: %p\n"
+                   "entry_type: 0x%x, captrue_mask: 0x%x\n",
+                   __func__, i, data_ptr, entry_hdr,
+                   entry_hdr->entry_type,
+                   entry_hdr->d_ctrl.entry_capture_mask);
+
+               ql_dbg(ql_dbg_p3p, vha, 0xb041,
+                   "Data collected: [0x%x], Dump size left:[0x%x]\n",
+                   data_collected, (ha->md_dump_size - data_collected));
+
+               /* Decode the entry type and take
+                * required action to capture debug data */
+               switch (entry_hdr->entry_type) {
+               case QLA82XX_RDEND:
+                       qla82xx_mark_entry_skipped(vha, entry_hdr, i);
+                       break;
+               case QLA82XX_CNTRL:
+                       rval = qla82xx_minidump_process_control(vha,
+                           entry_hdr, &data_ptr);
+                       if (rval != QLA_SUCCESS) {
+                               qla82xx_mark_entry_skipped(vha, entry_hdr, i);
+                               goto md_failed;
+                       }
+                       break;
+               case QLA82XX_RDCRB:
+                       qla82xx_minidump_process_rdcrb(vha,
+                           entry_hdr, &data_ptr);
+                       break;
+               case QLA82XX_RDMEM:
+                       rval = qla82xx_minidump_process_rdmem(vha,
+                           entry_hdr, &data_ptr);
+                       if (rval != QLA_SUCCESS) {
+                               qla82xx_mark_entry_skipped(vha, entry_hdr, i);
+                               goto md_failed;
+                       }
+                       break;
+               case QLA82XX_BOARD:
+               case QLA82XX_RDROM:
+                       qla82xx_minidump_process_rdrom(vha,
+                           entry_hdr, &data_ptr);
+                       break;
+               case QLA82XX_L2DTG:
+               case QLA82XX_L2ITG:
+               case QLA82XX_L2DAT:
+               case QLA82XX_L2INS:
+                       rval = qla82xx_minidump_process_l2tag(vha,
+                           entry_hdr, &data_ptr);
+                       if (rval != QLA_SUCCESS) {
+                               qla82xx_mark_entry_skipped(vha, entry_hdr, i);
+                               goto md_failed;
+                       }
+                       break;
+               case QLA82XX_L1DAT:
+               case QLA82XX_L1INS:
+                       qla82xx_minidump_process_l1cache(vha,
+                           entry_hdr, &data_ptr);
+                       break;
+               case QLA82XX_RDOCM:
+                       qla82xx_minidump_process_rdocm(vha,
+                           entry_hdr, &data_ptr);
+                       break;
+               case QLA82XX_RDMUX:
+                       qla82xx_minidump_process_rdmux(vha,
+                           entry_hdr, &data_ptr);
+                       break;
+               case QLA82XX_QUEUE:
+                       qla82xx_minidump_process_queue(vha,
+                           entry_hdr, &data_ptr);
+                       break;
+               case QLA82XX_RDNOP:
+               default:
+                       qla82xx_mark_entry_skipped(vha, entry_hdr, i);
+                       break;
+               }
+
+               ql_dbg(ql_dbg_p3p, vha, 0xb042,
+                   "[%s]: data ptr[%d]: %p\n", __func__, i, data_ptr);
+
+               data_collected = (uint8_t *)data_ptr -
+                   (uint8_t *)ha->md_dump;
+skip_nxt_entry:
+               entry_hdr = (qla82xx_md_entry_hdr_t *) \
+                   (((uint8_t *)entry_hdr) + entry_hdr->entry_size);
+       }
+
+       if (data_collected != total_data_size) {
+               ql_dbg(ql_log_warn, vha, 0xb043,
+                   "MiniDump data mismatch: Data collected: [0x%x],"
+                   "total_data_size:[0x%x]\n",
+                   data_collected, total_data_size);
+               goto md_failed;
+       }
+
+       ql_log(ql_log_info, vha, 0xb044,
+           "Firmware dump saved to temp buffer (%ld/%p %ld/%p).\n",
+           vha->host_no, ha->md_tmplt_hdr, vha->host_no, ha->md_dump);
+       ha->fw_dumped = 1;
+       qla2x00_post_uevent_work(vha, QLA_UEVENT_CODE_FW_DUMP);
+
+md_failed:
+       return rval;
+}
+
+int
+qla82xx_md_alloc(scsi_qla_host_t *vha)
+{
+       struct qla_hw_data *ha = vha->hw;
+       int i, k;
+       struct qla82xx_md_template_hdr *tmplt_hdr;
+
+       tmplt_hdr = (struct qla82xx_md_template_hdr *)ha->md_tmplt_hdr;
+
+       if (ql2xmdcapmask < 0x3 || ql2xmdcapmask > 0x7F) {
+               ql2xmdcapmask = tmplt_hdr->capture_debug_level & 0xFF;
+               ql_log(ql_log_info, vha, 0xb045,
+                   "Forcing driver capture mask to firmware default capture mask: 0x%x.\n",
+                   ql2xmdcapmask);
+       }
+
+       for (i = 0x2, k = 1; (i & QLA82XX_DEFAULT_CAP_MASK); i <<= 1, k++) {
+               if (i & ql2xmdcapmask)
+                       ha->md_dump_size += tmplt_hdr->capture_size_array[k];
+       }
+
+       if (ha->md_dump) {
+               ql_log(ql_log_warn, vha, 0xb046,
+                   "Firmware dump previously allocated.\n");
+               return 1;
+       }
+
+       ha->md_dump = vmalloc(ha->md_dump_size);
+       if (ha->md_dump == NULL) {
+               ql_log(ql_log_warn, vha, 0xb047,
+                   "Unable to allocate memory for Minidump size "
+                   "(0x%x).\n", ha->md_dump_size);
+               return 1;
+       }
+       return 0;
+}
+
+void
+qla82xx_md_free(scsi_qla_host_t *vha)
+{
+       struct qla_hw_data *ha = vha->hw;
+
+       /* Release the template header allocated */
+       if (ha->md_tmplt_hdr) {
+               ql_log(ql_log_info, vha, 0xb048,
+                   "Free MiniDump template: %p, size (%d KB)\n",
+                   ha->md_tmplt_hdr, ha->md_template_size / 1024);
+               dma_free_coherent(&ha->pdev->dev, ha->md_template_size,
+                   ha->md_tmplt_hdr, ha->md_tmplt_hdr_dma);
+               ha->md_tmplt_hdr = 0;
+       }
+
+       /* Release the template data buffer allocated */
+       if (ha->md_dump) {
+               ql_log(ql_log_info, vha, 0xb049,
+                   "Free MiniDump memory: %p, size (%d KB)\n",
+                   ha->md_dump, ha->md_dump_size / 1024);
+               vfree(ha->md_dump);
+               ha->md_dump_size = 0;
+               ha->md_dump = 0;
+       }
+}
+
+void
+qla82xx_md_prep(scsi_qla_host_t *vha)
+{
+       struct qla_hw_data *ha = vha->hw;
+       int rval;
+
+       /* Get Minidump template size */
+       rval = qla82xx_md_get_template_size(vha);
+       if (rval == QLA_SUCCESS) {
+               ql_log(ql_log_info, vha, 0xb04a,
+                   "MiniDump Template size obtained (%d KB)\n",
+                   ha->md_template_size / 1024);
+
+               /* Get Minidump template */
+               rval = qla82xx_md_get_template(vha);
+               if (rval == QLA_SUCCESS) {
+                       ql_dbg(ql_dbg_p3p, vha, 0xb04b,
+                           "MiniDump Template obtained\n");
+
+                       /* Allocate memory for minidump */
+                       rval = qla82xx_md_alloc(vha);
+                       if (rval == QLA_SUCCESS)
+                               ql_log(ql_log_info, vha, 0xb04c,
+                                   "MiniDump memory allocated (%d KB)\n",
+                                   ha->md_dump_size / 1024);
+                       else {
+                               ql_log(ql_log_info, vha, 0xb04d,
+                                   "Free MiniDump template: %p, size: (%d KB)\n",
+                                   ha->md_tmplt_hdr,
+                                   ha->md_template_size / 1024);
+                               dma_free_coherent(&ha->pdev->dev,
+                                   ha->md_template_size,
+                                   ha->md_tmplt_hdr, ha->md_tmplt_hdr_dma);
+                               ha->md_tmplt_hdr = 0;
+                       }
+
+               }
+       }
+}
+
+int
+qla82xx_beacon_on(struct scsi_qla_host *vha)
+{
+
+       int rval;
+       struct qla_hw_data *ha = vha->hw;
+       qla82xx_idc_lock(ha);
+       rval = qla82xx_mbx_beacon_ctl(vha, 1);
+
+       if (rval) {
+               ql_log(ql_log_warn, vha, 0xb050,
+                   "mbx set led config failed in %s\n", __func__);
+               goto exit;
+       }
+       ha->beacon_blink_led = 1;
+exit:
+       qla82xx_idc_unlock(ha);
+       return rval;
+}
+
+int
+qla82xx_beacon_off(struct scsi_qla_host *vha)
+{
+
+       int rval;
+       struct qla_hw_data *ha = vha->hw;
+       qla82xx_idc_lock(ha);
+       rval = qla82xx_mbx_beacon_ctl(vha, 0);
+
+       if (rval) {
+               ql_log(ql_log_warn, vha, 0xb051,
+                   "mbx set led config failed in %s\n", __func__);
+               goto exit;
+       }
+       ha->beacon_blink_led = 0;
+exit:
+       qla82xx_idc_unlock(ha);
+       return rval;
+}
index 8a21832c669317203fd2f3dec79c90ffc14d5633..57820c199bc225858b836feb1d38b457dce14430 100644 (file)
 #define QLA82XX_ADDR_OCM1              (0x0000000200400000ULL)
 #define QLA82XX_ADDR_OCM1_MAX          (0x00000002004fffffULL)
 #define QLA82XX_ADDR_QDR_NET           (0x0000000300000000ULL)
-
-#define QLA82XX_P2_ADDR_QDR_NET_MAX    (0x00000003001fffffULL)
 #define QLA82XX_P3_ADDR_QDR_NET_MAX    (0x0000000303ffffffULL)
 
 #define QLA82XX_PCI_CRBSPACE           (unsigned long)0x06000000
@@ -890,6 +888,7 @@ struct ct6_dsd {
 };
 
 #define MBC_TOGGLE_INTERRUPT   0x10
+#define MBC_SET_LED_CONFIG     0x125
 
 /* Flash  offset */
 #define FLT_REG_BOOTLOAD_82XX  0x72
@@ -922,4 +921,256 @@ struct ct6_dsd {
 #define M25P_INSTR_DP          0xb9
 #define M25P_INSTR_RES         0xab
 
+/* Minidump related */
+
+/*
+ * Version of the template
+ * 4 Bytes
+ * X.Major.Minor.RELEASE
+ */
+#define QLA82XX_MINIDUMP_VERSION         0x10101
+
+/*
+ * Entry Type Defines
+ */
+#define QLA82XX_RDNOP                   0
+#define QLA82XX_RDCRB                   1
+#define QLA82XX_RDMUX                   2
+#define QLA82XX_QUEUE                   3
+#define QLA82XX_BOARD                   4
+#define QLA82XX_RDSRE                   5
+#define QLA82XX_RDOCM                   6
+#define QLA82XX_CACHE                  10
+#define QLA82XX_L1DAT                  11
+#define QLA82XX_L1INS                  12
+#define QLA82XX_L2DTG                  21
+#define QLA82XX_L2ITG                  22
+#define QLA82XX_L2DAT                  23
+#define QLA82XX_L2INS                  24
+#define QLA82XX_RDROM                  71
+#define QLA82XX_RDMEM                  72
+#define QLA82XX_CNTRL                  98
+#define QLA82XX_TLHDR                  99
+#define QLA82XX_RDEND                  255
+
+/*
+ * Opcodes for Control Entries.
+ * These Flags are bit fields.
+ */
+#define QLA82XX_DBG_OPCODE_WR        0x01
+#define QLA82XX_DBG_OPCODE_RW        0x02
+#define QLA82XX_DBG_OPCODE_AND       0x04
+#define QLA82XX_DBG_OPCODE_OR        0x08
+#define QLA82XX_DBG_OPCODE_POLL      0x10
+#define QLA82XX_DBG_OPCODE_RDSTATE   0x20
+#define QLA82XX_DBG_OPCODE_WRSTATE   0x40
+#define QLA82XX_DBG_OPCODE_MDSTATE   0x80
+
+/*
+ * Template Header and Entry Header definitions start here.
+ */
+
+/*
+ * Template Header
+ * Parts of the template header can be modified by the driver.
+ * These include the saved_state_array, capture_debug_level, driver_timestamp
+ */
+
+#define QLA82XX_DBG_STATE_ARRAY_LEN        16
+#define QLA82XX_DBG_CAP_SIZE_ARRAY_LEN     8
+#define QLA82XX_DBG_RSVD_ARRAY_LEN         8
+
+/*
+ * Driver Flags
+ */
+#define QLA82XX_DBG_SKIPPED_FLAG       0x80    /* driver skipped this entry */
+#define        QLA82XX_DEFAULT_CAP_MASK        0xFF    /* default capture mask */
+
+struct qla82xx_md_template_hdr {
+       uint32_t entry_type;
+       uint32_t first_entry_offset;
+       uint32_t size_of_template;
+       uint32_t capture_debug_level;
+
+       uint32_t num_of_entries;
+       uint32_t version;
+       uint32_t driver_timestamp;
+       uint32_t template_checksum;
+
+       uint32_t driver_capture_mask;
+       uint32_t driver_info[3];
+
+       uint32_t saved_state_array[QLA82XX_DBG_STATE_ARRAY_LEN];
+       uint32_t capture_size_array[QLA82XX_DBG_CAP_SIZE_ARRAY_LEN];
+
+       /*  markers_array used to capture some special locations on board */
+       uint32_t markers_array[QLA82XX_DBG_RSVD_ARRAY_LEN];
+       uint32_t num_of_free_entries;   /* For internal use */
+       uint32_t free_entry_offset;     /* For internal use */
+       uint32_t total_table_size;      /*  For internal use */
+       uint32_t bkup_table_offset;     /*  For internal use */
+} __packed;
+
+/*
+ * Entry Header:  Common to All Entry Types
+ */
+
+/*
+ * Driver Code is for driver to write some info about the entry.
+ * Currently not used.
+ */
+typedef struct qla82xx_md_entry_hdr {
+       uint32_t entry_type;
+       uint32_t entry_size;
+       uint32_t entry_capture_size;
+       struct {
+               uint8_t entry_capture_mask;
+               uint8_t entry_code;
+               uint8_t driver_code;
+               uint8_t driver_flags;
+       } d_ctrl;
+} __packed qla82xx_md_entry_hdr_t;
+
+/*
+ *  Read CRB entry header
+ */
+struct qla82xx_md_entry_crb {
+       qla82xx_md_entry_hdr_t h;
+       uint32_t addr;
+       struct {
+               uint8_t addr_stride;
+               uint8_t state_index_a;
+               uint16_t poll_timeout;
+       } crb_strd;
+
+       uint32_t data_size;
+       uint32_t op_count;
+
+       struct {
+               uint8_t opcode;
+               uint8_t state_index_v;
+               uint8_t shl;
+               uint8_t shr;
+       } crb_ctrl;
+
+       uint32_t value_1;
+       uint32_t value_2;
+       uint32_t value_3;
+} __packed;
+
+/*
+ * Cache entry header
+ */
+struct qla82xx_md_entry_cache {
+       qla82xx_md_entry_hdr_t h;
+
+       uint32_t tag_reg_addr;
+       struct {
+               uint16_t tag_value_stride;
+               uint16_t init_tag_value;
+       } addr_ctrl;
+
+       uint32_t data_size;
+       uint32_t op_count;
+
+       uint32_t control_addr;
+       struct {
+               uint16_t write_value;
+               uint8_t poll_mask;
+               uint8_t poll_wait;
+       } cache_ctrl;
+
+       uint32_t read_addr;
+       struct {
+               uint8_t read_addr_stride;
+               uint8_t read_addr_cnt;
+               uint16_t rsvd_1;
+       } read_ctrl;
+} __packed;
+
+/*
+ * Read OCM
+ */
+struct qla82xx_md_entry_rdocm {
+       qla82xx_md_entry_hdr_t h;
+
+       uint32_t rsvd_0;
+       uint32_t rsvd_1;
+       uint32_t data_size;
+       uint32_t op_count;
+
+       uint32_t rsvd_2;
+       uint32_t rsvd_3;
+       uint32_t read_addr;
+       uint32_t read_addr_stride;
+       uint32_t read_addr_cntrl;
+} __packed;
+
+/*
+ * Read Memory
+ */
+struct qla82xx_md_entry_rdmem {
+       qla82xx_md_entry_hdr_t h;
+       uint32_t rsvd[6];
+       uint32_t read_addr;
+       uint32_t read_data_size;
+} __packed;
+
+/*
+ * Read ROM
+ */
+struct qla82xx_md_entry_rdrom {
+       qla82xx_md_entry_hdr_t h;
+       uint32_t rsvd[6];
+       uint32_t read_addr;
+       uint32_t read_data_size;
+} __packed;
+
+struct qla82xx_md_entry_mux {
+       qla82xx_md_entry_hdr_t h;
+
+       uint32_t select_addr;
+       uint32_t rsvd_0;
+       uint32_t data_size;
+       uint32_t op_count;
+
+       uint32_t select_value;
+       uint32_t select_value_stride;
+       uint32_t read_addr;
+       uint32_t rsvd_1;
+} __packed;
+
+struct qla82xx_md_entry_queue {
+       qla82xx_md_entry_hdr_t h;
+
+       uint32_t select_addr;
+       struct {
+               uint16_t queue_id_stride;
+               uint16_t rsvd_0;
+       } q_strd;
+
+       uint32_t data_size;
+       uint32_t op_count;
+       uint32_t rsvd_1;
+       uint32_t rsvd_2;
+
+       uint32_t read_addr;
+       struct {
+               uint8_t read_addr_stride;
+               uint8_t read_addr_cnt;
+               uint16_t rsvd_3;
+       } rd_strd;
+} __packed;
+
+#define MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE 0x129
+#define RQST_TMPLT_SIZE        0x0
+#define RQST_TMPLT 0x1
+#define MD_DIRECT_ROM_WINDOW   0x42110030
+#define MD_DIRECT_ROM_READ_BASE        0x42150000
+#define MD_MIU_TEST_AGT_CTRL           0x41000090
+#define MD_MIU_TEST_AGT_ADDR_LO                0x41000094
+#define MD_MIU_TEST_AGT_ADDR_HI                0x41000098
+
+static const int MD_MIU_TEST_AGT_RDDATA[] = { 0x410000A8, 0x410000AC,
+       0x410000B8, 0x410000BC };
 #endif
index 1e69527f1e4ec21a8e66ab59f7dfb73d26c478dd..fd14c7bfc62665f698d9950210dfa3b2e1cf1f42 100644 (file)
@@ -143,7 +143,7 @@ MODULE_PARM_DESC(ql2xmultique_tag,
                "Set it to 1 to turn on the cpu affinity.");
 
 int ql2xfwloadbin;
-module_param(ql2xfwloadbin, int, S_IRUGO);
+module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
 MODULE_PARM_DESC(ql2xfwloadbin,
                "Option to specify location from which to load ISP firmware:.\n"
                " 2 -- load firmware via the request_firmware() (hotplug).\n"
@@ -158,11 +158,11 @@ MODULE_PARM_DESC(ql2xetsenable,
                "Default is 0 - skip ETS enablement.");
 
 int ql2xdbwr = 1;
-module_param(ql2xdbwr, int, S_IRUGO);
+module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
 MODULE_PARM_DESC(ql2xdbwr,
-       "Option to specify scheme for request queue posting.\n"
-       " 0 -- Regular doorbell.\n"
-       " 1 -- CAMRAM doorbell (faster).\n");
+               "Option to specify scheme for request queue posting.\n"
+               " 0 -- Regular doorbell.\n"
+               " 1 -- CAMRAM doorbell (faster).\n");
 
 int ql2xtargetreset = 1;
 module_param(ql2xtargetreset, int, S_IRUGO);
@@ -183,11 +183,11 @@ MODULE_PARM_DESC(ql2xasynctmfenable,
                "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
 
 int ql2xdontresethba;
-module_param(ql2xdontresethba, int, S_IRUGO);
+module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
 MODULE_PARM_DESC(ql2xdontresethba,
-       "Option to specify reset behaviour.\n"
-       " 0 (Default) -- Reset on failure.\n"
-       " 1 -- Do not reset on failure.\n");
+               "Option to specify reset behaviour.\n"
+               " 0 (Default) -- Reset on failure.\n"
+               " 1 -- Do not reset on failure.\n");
 
 uint ql2xmaxlun = MAX_LUNS;
 module_param(ql2xmaxlun, uint, S_IRUGO);
@@ -195,6 +195,19 @@ MODULE_PARM_DESC(ql2xmaxlun,
                "Defines the maximum LU number to register with the SCSI "
                "midlayer. Default is 65535.");
 
+int ql2xmdcapmask = 0x1F;
+module_param(ql2xmdcapmask, int, S_IRUGO);
+MODULE_PARM_DESC(ql2xmdcapmask,
+               "Set the Minidump driver capture mask level. "
+               "Default is 0x7F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
+
+int ql2xmdenable;
+module_param(ql2xmdenable, int, S_IRUGO);
+MODULE_PARM_DESC(ql2xmdenable,
+               "Enable/disable MiniDump. "
+               "0 (Default) - MiniDump disabled. "
+               "1 - MiniDump enabled.");
+
 /*
  * SCSI host template entry points
  */
@@ -1750,9 +1763,9 @@ static struct isp_operations qla82xx_isp_ops = {
        .read_nvram             = qla24xx_read_nvram_data,
        .write_nvram            = qla24xx_write_nvram_data,
        .fw_dump                = qla24xx_fw_dump,
-       .beacon_on              = qla24xx_beacon_on,
-       .beacon_off             = qla24xx_beacon_off,
-       .beacon_blink           = qla24xx_beacon_blink,
+       .beacon_on              = qla82xx_beacon_on,
+       .beacon_off             = qla82xx_beacon_off,
+       .beacon_blink           = NULL,
        .read_optrom            = qla82xx_read_optrom_data,
        .write_optrom           = qla82xx_write_optrom_data,
        .get_flash_version      = qla24xx_get_flash_version,
@@ -2670,6 +2683,8 @@ qla2x00_free_device(scsi_qla_host_t *vha)
 
        qla2x00_mem_free(ha);
 
+       qla82xx_md_free(vha);
+
        qla2x00_free_queues(ha);
 }
 
@@ -3903,8 +3918,11 @@ qla2x00_timer(scsi_qla_host_t *vha)
 
        /* Check if beacon LED needs to be blinked for physical host only */
        if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
-               set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
-               start_dpc++;
+               /* There is no beacon_blink function for ISP82xx */
+               if (!IS_QLA82XX(ha)) {
+                       set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
+                       start_dpc++;
+               }
        }
 
        /* Process any deferred work. */
index 0f5599e0abf6a6d362e0f94312faaa7abe3ea2a7..f1ad02ea212b6331f16619ca8de821b97da977de 100644 (file)
@@ -2,6 +2,7 @@ config SCSI_QLA_ISCSI
        tristate "QLogic ISP4XXX and ISP82XX host adapter family support"
        depends on PCI && SCSI && NET
        select SCSI_ISCSI_ATTRS
+       select ISCSI_BOOT_SYSFS
        ---help---
        This driver supports the QLogic 40xx (ISP4XXX) and 8022 (ISP82XX)
        iSCSI host adapter family.
index 252523d7847ea60d6539090d90377f1fce6de9b3..5b44139ff43d43e884f82895cd162bd9b9dca211 100644 (file)
@@ -1,5 +1,5 @@
 qla4xxx-y := ql4_os.o ql4_init.o ql4_mbx.o ql4_iocb.o ql4_isr.o \
-               ql4_nx.o ql4_nvram.o ql4_dbg.o ql4_attr.o
+               ql4_nx.o ql4_nvram.o ql4_dbg.o ql4_attr.o ql4_bsg.o
 
 obj-$(CONFIG_SCSI_QLA_ISCSI) += qla4xxx.o
 
index 864d018631c0b4d12a0d02d103bd3b1c853b0929..0b0a7d42137d7b3fef646ec376175d9c7a97454e 100644 (file)
@@ -55,15 +55,91 @@ qla4xxx_optrom_version_show(struct device *dev, struct device_attribute *attr,
                        ha->bootload_patch, ha->bootload_build);
 }
 
+static ssize_t
+qla4xxx_board_id_show(struct device *dev, struct device_attribute *attr,
+                     char *buf)
+{
+       struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
+       return snprintf(buf, PAGE_SIZE, "0x%08X\n", ha->board_id);
+}
+
+static ssize_t
+qla4xxx_fw_state_show(struct device *dev, struct device_attribute *attr,
+                     char *buf)
+{
+       struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
+
+       qla4xxx_get_firmware_state(ha);
+       return snprintf(buf, PAGE_SIZE, "0x%08X%8X\n", ha->firmware_state,
+                       ha->addl_fw_state);
+}
+
+static ssize_t
+qla4xxx_phy_port_cnt_show(struct device *dev, struct device_attribute *attr,
+                     char *buf)
+{
+       struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
+
+       if (!is_qla8022(ha))
+               return -ENOSYS;
+
+       return snprintf(buf, PAGE_SIZE, "0x%04X\n", ha->phy_port_cnt);
+}
+
+static ssize_t
+qla4xxx_phy_port_num_show(struct device *dev, struct device_attribute *attr,
+                     char *buf)
+{
+       struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
+
+       if (!is_qla8022(ha))
+               return -ENOSYS;
+
+       return snprintf(buf, PAGE_SIZE, "0x%04X\n", ha->phy_port_num);
+}
+
+static ssize_t
+qla4xxx_iscsi_func_cnt_show(struct device *dev, struct device_attribute *attr,
+                     char *buf)
+{
+       struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
+
+       if (!is_qla8022(ha))
+               return -ENOSYS;
+
+       return snprintf(buf, PAGE_SIZE, "0x%04X\n", ha->iscsi_pci_func_cnt);
+}
+
+static ssize_t
+qla4xxx_hba_model_show(struct device *dev, struct device_attribute *attr,
+                      char *buf)
+{
+       struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
+
+       return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_name);
+}
+
 static DEVICE_ATTR(fw_version, S_IRUGO, qla4xxx_fw_version_show, NULL);
 static DEVICE_ATTR(serial_num, S_IRUGO, qla4xxx_serial_num_show, NULL);
 static DEVICE_ATTR(iscsi_version, S_IRUGO, qla4xxx_iscsi_version_show, NULL);
 static DEVICE_ATTR(optrom_version, S_IRUGO, qla4xxx_optrom_version_show, NULL);
+static DEVICE_ATTR(board_id, S_IRUGO, qla4xxx_board_id_show, NULL);
+static DEVICE_ATTR(fw_state, S_IRUGO, qla4xxx_fw_state_show, NULL);
+static DEVICE_ATTR(phy_port_cnt, S_IRUGO, qla4xxx_phy_port_cnt_show, NULL);
+static DEVICE_ATTR(phy_port_num, S_IRUGO, qla4xxx_phy_port_num_show, NULL);
+static DEVICE_ATTR(iscsi_func_cnt, S_IRUGO, qla4xxx_iscsi_func_cnt_show, NULL);
+static DEVICE_ATTR(hba_model, S_IRUGO, qla4xxx_hba_model_show, NULL);
 
 struct device_attribute *qla4xxx_host_attrs[] = {
        &dev_attr_fw_version,
        &dev_attr_serial_num,
        &dev_attr_iscsi_version,
        &dev_attr_optrom_version,
+       &dev_attr_board_id,
+       &dev_attr_fw_state,
+       &dev_attr_phy_port_cnt,
+       &dev_attr_phy_port_num,
+       &dev_attr_iscsi_func_cnt,
+       &dev_attr_hba_model,
        NULL,
 };
diff --git a/drivers/scsi/qla4xxx/ql4_bsg.c b/drivers/scsi/qla4xxx/ql4_bsg.c
new file mode 100644 (file)
index 0000000..8acdc58
--- /dev/null
@@ -0,0 +1,513 @@
+/*
+ * QLogic iSCSI HBA Driver
+ * Copyright (c) 2011 QLogic Corporation
+ *
+ * See LICENSE.qla4xxx for copyright and licensing details.
+ */
+
+#include "ql4_def.h"
+#include "ql4_glbl.h"
+#include "ql4_bsg.h"
+
+static int
+qla4xxx_read_flash(struct bsg_job *bsg_job)
+{
+       struct Scsi_Host *host = iscsi_job_to_shost(bsg_job);
+       struct scsi_qla_host *ha = to_qla_host(host);
+       struct iscsi_bsg_reply *bsg_reply = bsg_job->reply;
+       struct iscsi_bsg_request *bsg_req = bsg_job->request;
+       uint32_t offset = 0;
+       uint32_t length = 0;
+       dma_addr_t flash_dma;
+       uint8_t *flash = NULL;
+       int rval = -EINVAL;
+
+       bsg_reply->reply_payload_rcv_len = 0;
+
+       if (unlikely(pci_channel_offline(ha->pdev)))
+               goto leave;
+
+       if (ql4xxx_reset_active(ha)) {
+               ql4_printk(KERN_ERR, ha, "%s: reset active\n", __func__);
+               rval = -EBUSY;
+               goto leave;
+       }
+
+       if (ha->flash_state != QLFLASH_WAITING) {
+               ql4_printk(KERN_ERR, ha, "%s: another flash operation "
+                          "active\n", __func__);
+               rval = -EBUSY;
+               goto leave;
+       }
+
+       ha->flash_state = QLFLASH_READING;
+       offset = bsg_req->rqst_data.h_vendor.vendor_cmd[1];
+       length = bsg_job->reply_payload.payload_len;
+
+       flash = dma_alloc_coherent(&ha->pdev->dev, length, &flash_dma,
+                                  GFP_KERNEL);
+       if (!flash) {
+               ql4_printk(KERN_ERR, ha, "%s: dma alloc failed for flash "
+                          "data\n", __func__);
+               rval = -ENOMEM;
+               goto leave;
+       }
+
+       rval = qla4xxx_get_flash(ha, flash_dma, offset, length);
+       if (rval) {
+               ql4_printk(KERN_ERR, ha, "%s: get flash failed\n", __func__);
+               bsg_reply->result = DID_ERROR << 16;
+               rval = -EIO;
+       } else {
+               bsg_reply->reply_payload_rcv_len =
+                       sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
+                                           bsg_job->reply_payload.sg_cnt,
+                                           flash, length);
+               bsg_reply->result = DID_OK << 16;
+       }
+
+       bsg_job_done(bsg_job, bsg_reply->result,
+                    bsg_reply->reply_payload_rcv_len);
+       dma_free_coherent(&ha->pdev->dev, length, flash, flash_dma);
+leave:
+       ha->flash_state = QLFLASH_WAITING;
+       return rval;
+}
+
+static int
+qla4xxx_update_flash(struct bsg_job *bsg_job)
+{
+       struct Scsi_Host *host = iscsi_job_to_shost(bsg_job);
+       struct scsi_qla_host *ha = to_qla_host(host);
+       struct iscsi_bsg_reply *bsg_reply = bsg_job->reply;
+       struct iscsi_bsg_request *bsg_req = bsg_job->request;
+       uint32_t length = 0;
+       uint32_t offset = 0;
+       uint32_t options = 0;
+       dma_addr_t flash_dma;
+       uint8_t *flash = NULL;
+       int rval = -EINVAL;
+
+       bsg_reply->reply_payload_rcv_len = 0;
+
+       if (unlikely(pci_channel_offline(ha->pdev)))
+               goto leave;
+
+       if (ql4xxx_reset_active(ha)) {
+               ql4_printk(KERN_ERR, ha, "%s: reset active\n", __func__);
+               rval = -EBUSY;
+               goto leave;
+       }
+
+       if (ha->flash_state != QLFLASH_WAITING) {
+               ql4_printk(KERN_ERR, ha, "%s: another flash operation "
+                          "active\n", __func__);
+               rval = -EBUSY;
+               goto leave;
+       }
+
+       ha->flash_state = QLFLASH_WRITING;
+       length = bsg_job->request_payload.payload_len;
+       offset = bsg_req->rqst_data.h_vendor.vendor_cmd[1];
+       options = bsg_req->rqst_data.h_vendor.vendor_cmd[2];
+
+       flash = dma_alloc_coherent(&ha->pdev->dev, length, &flash_dma,
+                                  GFP_KERNEL);
+       if (!flash) {
+               ql4_printk(KERN_ERR, ha, "%s: dma alloc failed for flash "
+                          "data\n", __func__);
+               rval = -ENOMEM;
+               goto leave;
+       }
+
+       sg_copy_to_buffer(bsg_job->request_payload.sg_list,
+                         bsg_job->request_payload.sg_cnt, flash, length);
+
+       rval = qla4xxx_set_flash(ha, flash_dma, offset, length, options);
+       if (rval) {
+               ql4_printk(KERN_ERR, ha, "%s: set flash failed\n", __func__);
+               bsg_reply->result = DID_ERROR << 16;
+               rval = -EIO;
+       } else
+               bsg_reply->result = DID_OK << 16;
+
+       bsg_job_done(bsg_job, bsg_reply->result,
+                    bsg_reply->reply_payload_rcv_len);
+       dma_free_coherent(&ha->pdev->dev, length, flash, flash_dma);
+leave:
+       ha->flash_state = QLFLASH_WAITING;
+       return rval;
+}
+
+static int
+qla4xxx_get_acb_state(struct bsg_job *bsg_job)
+{
+       struct Scsi_Host *host = iscsi_job_to_shost(bsg_job);
+       struct scsi_qla_host *ha = to_qla_host(host);
+       struct iscsi_bsg_request *bsg_req = bsg_job->request;
+       struct iscsi_bsg_reply *bsg_reply = bsg_job->reply;
+       uint32_t status[MBOX_REG_COUNT];
+       uint32_t acb_idx;
+       uint32_t ip_idx;
+       int rval = -EINVAL;
+
+       bsg_reply->reply_payload_rcv_len = 0;
+
+       if (unlikely(pci_channel_offline(ha->pdev)))
+               goto leave;
+
+       /* Only 4022 and above adapters are supported */
+       if (is_qla4010(ha))
+               goto leave;
+
+       if (ql4xxx_reset_active(ha)) {
+               ql4_printk(KERN_ERR, ha, "%s: reset active\n", __func__);
+               rval = -EBUSY;
+               goto leave;
+       }
+
+       if (bsg_job->reply_payload.payload_len < sizeof(status)) {
+               ql4_printk(KERN_ERR, ha, "%s: invalid payload len %d\n",
+                          __func__, bsg_job->reply_payload.payload_len);
+               rval = -EINVAL;
+               goto leave;
+       }
+
+       acb_idx = bsg_req->rqst_data.h_vendor.vendor_cmd[1];
+       ip_idx = bsg_req->rqst_data.h_vendor.vendor_cmd[2];
+
+       rval = qla4xxx_get_ip_state(ha, acb_idx, ip_idx, status);
+       if (rval) {
+               ql4_printk(KERN_ERR, ha, "%s: get ip state failed\n",
+                          __func__);
+               bsg_reply->result = DID_ERROR << 16;
+               rval = -EIO;
+       } else {
+               bsg_reply->reply_payload_rcv_len =
+                       sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
+                                           bsg_job->reply_payload.sg_cnt,
+                                           status, sizeof(status));
+               bsg_reply->result = DID_OK << 16;
+       }
+
+       bsg_job_done(bsg_job, bsg_reply->result,
+                    bsg_reply->reply_payload_rcv_len);
+leave:
+       return rval;
+}
+
+static int
+qla4xxx_read_nvram(struct bsg_job *bsg_job)
+{
+       struct Scsi_Host *host = iscsi_job_to_shost(bsg_job);
+       struct scsi_qla_host *ha = to_qla_host(host);
+       struct iscsi_bsg_request *bsg_req = bsg_job->request;
+       struct iscsi_bsg_reply *bsg_reply = bsg_job->reply;
+       uint32_t offset = 0;
+       uint32_t len = 0;
+       uint32_t total_len = 0;
+       dma_addr_t nvram_dma;
+       uint8_t *nvram = NULL;
+       int rval = -EINVAL;
+
+       bsg_reply->reply_payload_rcv_len = 0;
+
+       if (unlikely(pci_channel_offline(ha->pdev)))
+               goto leave;
+
+       /* Only 40xx adapters are supported */
+       if (!(is_qla4010(ha) || is_qla4022(ha) || is_qla4032(ha)))
+               goto leave;
+
+       if (ql4xxx_reset_active(ha)) {
+               ql4_printk(KERN_ERR, ha, "%s: reset active\n", __func__);
+               rval = -EBUSY;
+               goto leave;
+       }
+
+       offset = bsg_req->rqst_data.h_vendor.vendor_cmd[1];
+       len = bsg_job->reply_payload.payload_len;
+       total_len = offset + len;
+
+       /* total len should not be greater than max NVRAM size */
+       if ((is_qla4010(ha) && total_len > QL4010_NVRAM_SIZE) ||
+           ((is_qla4022(ha) || is_qla4032(ha)) &&
+            total_len > QL40X2_NVRAM_SIZE)) {
+               ql4_printk(KERN_ERR, ha, "%s: offset+len greater than max"
+                          " nvram size, offset=%d len=%d\n",
+                          __func__, offset, len);
+               goto leave;
+       }
+
+       nvram = dma_alloc_coherent(&ha->pdev->dev, len, &nvram_dma,
+                                  GFP_KERNEL);
+       if (!nvram) {
+               ql4_printk(KERN_ERR, ha, "%s: dma alloc failed for nvram "
+                          "data\n", __func__);
+               rval = -ENOMEM;
+               goto leave;
+       }
+
+       rval = qla4xxx_get_nvram(ha, nvram_dma, offset, len);
+       if (rval) {
+               ql4_printk(KERN_ERR, ha, "%s: get nvram failed\n", __func__);
+               bsg_reply->result = DID_ERROR << 16;
+               rval = -EIO;
+       } else {
+               bsg_reply->reply_payload_rcv_len =
+                       sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
+                                           bsg_job->reply_payload.sg_cnt,
+                                           nvram, len);
+               bsg_reply->result = DID_OK << 16;
+       }
+
+       bsg_job_done(bsg_job, bsg_reply->result,
+                    bsg_reply->reply_payload_rcv_len);
+       dma_free_coherent(&ha->pdev->dev, len, nvram, nvram_dma);
+leave:
+       return rval;
+}
+
+static int
+qla4xxx_update_nvram(struct bsg_job *bsg_job)
+{
+       struct Scsi_Host *host = iscsi_job_to_shost(bsg_job);
+       struct scsi_qla_host *ha = to_qla_host(host);
+       struct iscsi_bsg_request *bsg_req = bsg_job->request;
+       struct iscsi_bsg_reply *bsg_reply = bsg_job->reply;
+       uint32_t offset = 0;
+       uint32_t len = 0;
+       uint32_t total_len = 0;
+       dma_addr_t nvram_dma;
+       uint8_t *nvram = NULL;
+       int rval = -EINVAL;
+
+       bsg_reply->reply_payload_rcv_len = 0;
+
+       if (unlikely(pci_channel_offline(ha->pdev)))
+               goto leave;
+
+       if (!(is_qla4010(ha) || is_qla4022(ha) || is_qla4032(ha)))
+               goto leave;
+
+       if (ql4xxx_reset_active(ha)) {
+               ql4_printk(KERN_ERR, ha, "%s: reset active\n", __func__);
+               rval = -EBUSY;
+               goto leave;
+       }
+
+       offset = bsg_req->rqst_data.h_vendor.vendor_cmd[1];
+       len = bsg_job->request_payload.payload_len;
+       total_len = offset + len;
+
+       /* total len should not be greater than max NVRAM size */
+       if ((is_qla4010(ha) && total_len > QL4010_NVRAM_SIZE) ||
+           ((is_qla4022(ha) || is_qla4032(ha)) &&
+            total_len > QL40X2_NVRAM_SIZE)) {
+               ql4_printk(KERN_ERR, ha, "%s: offset+len greater than max"
+                          " nvram size, offset=%d len=%d\n",
+                          __func__, offset, len);
+               goto leave;
+       }
+
+       nvram = dma_alloc_coherent(&ha->pdev->dev, len, &nvram_dma,
+                                  GFP_KERNEL);
+       if (!nvram) {
+               ql4_printk(KERN_ERR, ha, "%s: dma alloc failed for flash "
+                          "data\n", __func__);
+               rval = -ENOMEM;
+               goto leave;
+       }
+
+       sg_copy_to_buffer(bsg_job->request_payload.sg_list,
+                         bsg_job->request_payload.sg_cnt, nvram, len);
+
+       rval = qla4xxx_set_nvram(ha, nvram_dma, offset, len);
+       if (rval) {
+               ql4_printk(KERN_ERR, ha, "%s: set nvram failed\n", __func__);
+               bsg_reply->result = DID_ERROR << 16;
+               rval = -EIO;
+       } else
+               bsg_reply->result = DID_OK << 16;
+
+       bsg_job_done(bsg_job, bsg_reply->result,
+                    bsg_reply->reply_payload_rcv_len);
+       dma_free_coherent(&ha->pdev->dev, len, nvram, nvram_dma);
+leave:
+       return rval;
+}
+
+static int
+qla4xxx_restore_defaults(struct bsg_job *bsg_job)
+{
+       struct Scsi_Host *host = iscsi_job_to_shost(bsg_job);
+       struct scsi_qla_host *ha = to_qla_host(host);
+       struct iscsi_bsg_request *bsg_req = bsg_job->request;
+       struct iscsi_bsg_reply *bsg_reply = bsg_job->reply;
+       uint32_t region = 0;
+       uint32_t field0 = 0;
+       uint32_t field1 = 0;
+       int rval = -EINVAL;
+
+       bsg_reply->reply_payload_rcv_len = 0;
+
+       if (unlikely(pci_channel_offline(ha->pdev)))
+               goto leave;
+
+       if (is_qla4010(ha))
+               goto leave;
+
+       if (ql4xxx_reset_active(ha)) {
+               ql4_printk(KERN_ERR, ha, "%s: reset active\n", __func__);
+               rval = -EBUSY;
+               goto leave;
+       }
+
+       region = bsg_req->rqst_data.h_vendor.vendor_cmd[1];
+       field0 = bsg_req->rqst_data.h_vendor.vendor_cmd[2];
+       field1 = bsg_req->rqst_data.h_vendor.vendor_cmd[3];
+
+       rval = qla4xxx_restore_factory_defaults(ha, region, field0, field1);
+       if (rval) {
+               ql4_printk(KERN_ERR, ha, "%s: set nvram failed\n", __func__);
+               bsg_reply->result = DID_ERROR << 16;
+               rval = -EIO;
+       } else
+               bsg_reply->result = DID_OK << 16;
+
+       bsg_job_done(bsg_job, bsg_reply->result,
+                    bsg_reply->reply_payload_rcv_len);
+leave:
+       return rval;
+}
+
+static int
+qla4xxx_bsg_get_acb(struct bsg_job *bsg_job)
+{
+       struct Scsi_Host *host = iscsi_job_to_shost(bsg_job);
+       struct scsi_qla_host *ha = to_qla_host(host);
+       struct iscsi_bsg_request *bsg_req = bsg_job->request;
+       struct iscsi_bsg_reply *bsg_reply = bsg_job->reply;
+       uint32_t acb_type = 0;
+       uint32_t len = 0;
+       dma_addr_t acb_dma;
+       uint8_t *acb = NULL;
+       int rval = -EINVAL;
+
+       bsg_reply->reply_payload_rcv_len = 0;
+
+       if (unlikely(pci_channel_offline(ha->pdev)))
+               goto leave;
+
+       /* Only 4022 and above adapters are supported */
+       if (is_qla4010(ha))
+               goto leave;
+
+       if (ql4xxx_reset_active(ha)) {
+               ql4_printk(KERN_ERR, ha, "%s: reset active\n", __func__);
+               rval = -EBUSY;
+               goto leave;
+       }
+
+       acb_type = bsg_req->rqst_data.h_vendor.vendor_cmd[1];
+       len = bsg_job->reply_payload.payload_len;
+       if (len < sizeof(struct addr_ctrl_blk)) {
+               ql4_printk(KERN_ERR, ha, "%s: invalid acb len %d\n",
+                          __func__, len);
+               rval = -EINVAL;
+               goto leave;
+       }
+
+       acb = dma_alloc_coherent(&ha->pdev->dev, len, &acb_dma, GFP_KERNEL);
+       if (!acb) {
+               ql4_printk(KERN_ERR, ha, "%s: dma alloc failed for acb "
+                          "data\n", __func__);
+               rval = -ENOMEM;
+               goto leave;
+       }
+
+       rval = qla4xxx_get_acb(ha, acb_dma, acb_type, len);
+       if (rval) {
+               ql4_printk(KERN_ERR, ha, "%s: get acb failed\n", __func__);
+               bsg_reply->result = DID_ERROR << 16;
+               rval = -EIO;
+       } else {
+               bsg_reply->reply_payload_rcv_len =
+                       sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
+                                           bsg_job->reply_payload.sg_cnt,
+                                           acb, len);
+               bsg_reply->result = DID_OK << 16;
+       }
+
+       bsg_job_done(bsg_job, bsg_reply->result,
+                    bsg_reply->reply_payload_rcv_len);
+       dma_free_coherent(&ha->pdev->dev, len, acb, acb_dma);
+leave:
+       return rval;
+}
+
+/**
+ * qla4xxx_process_vendor_specific - handle vendor specific bsg request
+ * @job: iscsi_bsg_job to handle
+ **/
+int qla4xxx_process_vendor_specific(struct bsg_job *bsg_job)
+{
+       struct iscsi_bsg_reply *bsg_reply = bsg_job->reply;
+       struct iscsi_bsg_request *bsg_req = bsg_job->request;
+       struct Scsi_Host *host = iscsi_job_to_shost(bsg_job);
+       struct scsi_qla_host *ha = to_qla_host(host);
+
+       switch (bsg_req->rqst_data.h_vendor.vendor_cmd[0]) {
+       case QLISCSI_VND_READ_FLASH:
+               return qla4xxx_read_flash(bsg_job);
+
+       case QLISCSI_VND_UPDATE_FLASH:
+               return qla4xxx_update_flash(bsg_job);
+
+       case QLISCSI_VND_GET_ACB_STATE:
+               return qla4xxx_get_acb_state(bsg_job);
+
+       case QLISCSI_VND_READ_NVRAM:
+               return qla4xxx_read_nvram(bsg_job);
+
+       case QLISCSI_VND_UPDATE_NVRAM:
+               return qla4xxx_update_nvram(bsg_job);
+
+       case QLISCSI_VND_RESTORE_DEFAULTS:
+               return qla4xxx_restore_defaults(bsg_job);
+
+       case QLISCSI_VND_GET_ACB:
+               return qla4xxx_bsg_get_acb(bsg_job);
+
+       default:
+               ql4_printk(KERN_ERR, ha, "%s: invalid BSG vendor command: "
+                          "0x%x\n", __func__, bsg_req->msgcode);
+               bsg_reply->result = (DID_ERROR << 16);
+               bsg_reply->reply_payload_rcv_len = 0;
+               bsg_job_done(bsg_job, bsg_reply->result,
+                            bsg_reply->reply_payload_rcv_len);
+               return -ENOSYS;
+       }
+}
+
+/**
+ * qla4xxx_bsg_request - handle bsg request from ISCSI transport
+ * @job: iscsi_bsg_job to handle
+ */
+int qla4xxx_bsg_request(struct bsg_job *bsg_job)
+{
+       struct iscsi_bsg_request *bsg_req = bsg_job->request;
+       struct Scsi_Host *host = iscsi_job_to_shost(bsg_job);
+       struct scsi_qla_host *ha = to_qla_host(host);
+
+       switch (bsg_req->msgcode) {
+       case ISCSI_BSG_HST_VENDOR:
+               return qla4xxx_process_vendor_specific(bsg_job);
+
+       default:
+               ql4_printk(KERN_ERR, ha, "%s: invalid BSG command: 0x%x\n",
+                          __func__, bsg_req->msgcode);
+       }
+
+       return -ENOSYS;
+}
diff --git a/drivers/scsi/qla4xxx/ql4_bsg.h b/drivers/scsi/qla4xxx/ql4_bsg.h
new file mode 100644 (file)
index 0000000..c6a0364
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * QLogic iSCSI HBA Driver
+ * Copyright (c) 2011 QLogic Corporation
+ *
+ * See LICENSE.qla4xxx for copyright and licensing details.
+ */
+#ifndef __QL4_BSG_H
+#define __QL4_BSG_H
+
+/* BSG Vendor specific commands */
+#define QLISCSI_VND_READ_FLASH         1
+#define QLISCSI_VND_UPDATE_FLASH       2
+#define QLISCSI_VND_GET_ACB_STATE      3
+#define QLISCSI_VND_READ_NVRAM         4
+#define QLISCSI_VND_UPDATE_NVRAM       5
+#define QLISCSI_VND_RESTORE_DEFAULTS   6
+#define QLISCSI_VND_GET_ACB            7
+
+#endif
index 473c5c872b397e7f02c86485e7ba56f67bac9c7f..ace637bf254e1ca2b8c9d8be7490f41027945044 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/interrupt.h>
 #include <linux/mutex.h>
 #include <linux/aer.h>
+#include <linux/bsg-lib.h>
 
 #include <net/tcp.h>
 #include <scsi/scsi.h>
 #include <scsi/scsi_cmnd.h>
 #include <scsi/scsi_transport.h>
 #include <scsi/scsi_transport_iscsi.h>
+#include <scsi/scsi_bsg_iscsi.h>
+#include <scsi/scsi_netlink.h>
+#include <scsi/libiscsi.h>
 
 #include "ql4_dbg.h"
 #include "ql4_nx.h"
+#include "ql4_fw.h"
+#include "ql4_nvram.h"
 
 #ifndef PCI_DEVICE_ID_QLOGIC_ISP4010
 #define PCI_DEVICE_ID_QLOGIC_ISP4010   0x4010
 #define MAX_BUSES              1
 #define MAX_TARGETS            MAX_DEV_DB_ENTRIES
 #define MAX_LUNS               0xffff
-#define MAX_AEN_ENTRIES                256 /* should be > EXT_DEF_MAX_AEN_QUEUE */
+#define MAX_AEN_ENTRIES                MAX_DEV_DB_ENTRIES
 #define MAX_DDB_ENTRIES                MAX_DEV_DB_ENTRIES
 #define MAX_PDU_ENTRIES                32
 #define INVALID_ENTRY          0xFFFF
 #define RELOGIN_TOV                    18
 #define ISNS_DEREG_TOV                 5
 #define HBA_ONLINE_TOV                 30
+#define DISABLE_ACB_TOV                        30
 
 #define MAX_RESET_HA_RETRIES           2
 
@@ -227,52 +234,12 @@ struct ql4_aen_log {
  * Device Database (DDB) structure
  */
 struct ddb_entry {
-       struct list_head list;  /* ddb list */
        struct scsi_qla_host *ha;
        struct iscsi_cls_session *sess;
        struct iscsi_cls_conn *conn;
 
-       atomic_t state;         /* DDB State */
-
-       unsigned long flags;    /* DDB Flags */
-
        uint16_t fw_ddb_index;  /* DDB firmware index */
-       uint16_t options;
        uint32_t fw_ddb_device_state; /* F/W Device State  -- see ql4_fw.h */
-
-       uint32_t CmdSn;
-       uint16_t target_session_id;
-       uint16_t connection_id;
-       uint16_t exe_throttle;  /* Max mumber of cmds outstanding
-                                * simultaneously */
-       uint16_t task_mgmt_timeout; /* Min time for task mgmt cmds to
-                                    * complete */
-       uint16_t default_relogin_timeout; /*  Max time to wait for
-                                          *  relogin to complete */
-       uint16_t tcp_source_port_num;
-       uint32_t default_time2wait; /* Default Min time between
-                                    * relogins (+aens) */
-
-       atomic_t retry_relogin_timer; /* Min Time between relogins
-                                      * (4000 only) */
-       atomic_t relogin_timer; /* Max Time to wait for relogin to complete */
-       atomic_t relogin_retry_count; /* Num of times relogin has been
-                                      * retried */
-
-       uint16_t port;
-       uint32_t tpgt;
-       uint8_t ip_addr[IP_ADDR_LEN];
-       uint8_t iscsi_name[ISCSI_NAME_SIZE];    /* 72 x48 */
-       uint8_t iscsi_alias[0x20];
-       uint8_t isid[6];
-       uint16_t iscsi_max_burst_len;
-       uint16_t iscsi_max_outsnd_r2t;
-       uint16_t iscsi_first_burst_len;
-       uint16_t iscsi_max_rcv_data_seg_len;
-       uint16_t iscsi_max_snd_data_seg_len;
-
-       struct in6_addr remote_ipv6_addr;
-       struct in6_addr link_local_ipv6_addr;
 };
 
 /*
@@ -293,8 +260,6 @@ struct ddb_entry {
 #define DF_FO_MASKED           3
 
 
-#include "ql4_fw.h"
-#include "ql4_nvram.h"
 
 struct ql82xx_hw_data {
        /* Offsets for flash/nvram access (set to ~0 if not used). */
@@ -312,7 +277,10 @@ struct ql82xx_hw_data {
        uint32_t flt_region_boot;
        uint32_t flt_region_bootload;
        uint32_t flt_region_fw;
-       uint32_t reserved;
+
+       uint32_t flt_iscsi_param;
+       uint32_t flt_region_chap;
+       uint32_t flt_chap_size;
 };
 
 struct qla4_8xxx_legacy_intr_set {
@@ -357,6 +325,68 @@ struct isp_operations {
        int (*get_sys_info) (struct scsi_qla_host *);
 };
 
+/*qla4xxx ipaddress configuration details */
+struct ipaddress_config {
+       uint16_t ipv4_options;
+       uint16_t tcp_options;
+       uint16_t ipv4_vlan_tag;
+       uint8_t ipv4_addr_state;
+       uint8_t ip_address[IP_ADDR_LEN];
+       uint8_t subnet_mask[IP_ADDR_LEN];
+       uint8_t gateway[IP_ADDR_LEN];
+       uint32_t ipv6_options;
+       uint32_t ipv6_addl_options;
+       uint8_t ipv6_link_local_state;
+       uint8_t ipv6_addr0_state;
+       uint8_t ipv6_addr1_state;
+       uint8_t ipv6_default_router_state;
+       uint16_t ipv6_vlan_tag;
+       struct in6_addr ipv6_link_local_addr;
+       struct in6_addr ipv6_addr0;
+       struct in6_addr ipv6_addr1;
+       struct in6_addr ipv6_default_router_addr;
+       uint16_t eth_mtu_size;
+       uint16_t ipv4_port;
+       uint16_t ipv6_port;
+};
+
+#define QL4_CHAP_MAX_NAME_LEN 256
+#define QL4_CHAP_MAX_SECRET_LEN 100
+#define LOCAL_CHAP     0
+#define BIDI_CHAP      1
+
+struct ql4_chap_format {
+       u8  intr_chap_name[QL4_CHAP_MAX_NAME_LEN];
+       u8  intr_secret[QL4_CHAP_MAX_SECRET_LEN];
+       u8  target_chap_name[QL4_CHAP_MAX_NAME_LEN];
+       u8  target_secret[QL4_CHAP_MAX_SECRET_LEN];
+       u16 intr_chap_name_length;
+       u16 intr_secret_length;
+       u16 target_chap_name_length;
+       u16 target_secret_length;
+};
+
+struct ip_address_format {
+       u8 ip_type;
+       u8 ip_address[16];
+};
+
+struct ql4_conn_info {
+       u16     dest_port;
+       struct  ip_address_format dest_ipaddr;
+       struct  ql4_chap_format chap;
+};
+
+struct ql4_boot_session_info {
+       u8      target_name[224];
+       struct  ql4_conn_info conn_list[1];
+};
+
+struct ql4_boot_tgt_info {
+       struct ql4_boot_session_info boot_pri_sess;
+       struct ql4_boot_session_info boot_sec_sess;
+};
+
 /*
  * Linux Host Adapter structure
  */
@@ -451,10 +481,6 @@ struct scsi_qla_host {
        /* --- From Init_FW --- */
        /* init_cb_t *init_cb; */
        uint16_t firmware_options;
-       uint16_t tcp_options;
-       uint8_t ip_address[IP_ADDR_LEN];
-       uint8_t subnet_mask[IP_ADDR_LEN];
-       uint8_t gateway[IP_ADDR_LEN];
        uint8_t alias[32];
        uint8_t name_string[256];
        uint8_t heartbeat_interval;
@@ -462,7 +488,7 @@ struct scsi_qla_host {
        /* --- From FlashSysInfo --- */
        uint8_t my_mac[MAC_ADDR_LEN];
        uint8_t serial_number[16];
-
+       uint16_t port_num;
        /* --- From GetFwState --- */
        uint32_t firmware_state;
        uint32_t addl_fw_state;
@@ -524,31 +550,13 @@ struct scsi_qla_host {
        volatile uint8_t mbox_status_count;
        volatile uint32_t mbox_status[MBOX_REG_COUNT];
 
-       /* local device database list (contains internal ddb entries) */
-       struct list_head ddb_list;
-
-       /* Map ddb_list entry by FW ddb index */
+       /* FW ddb index map */
        struct ddb_entry *fw_ddb_index_map[MAX_DDB_ENTRIES];
 
        /* Saved srb for status continuation entry processing */
        struct srb *status_srb;
 
-       /* IPv6 support info from InitFW */
        uint8_t acb_version;
-       uint8_t ipv4_addr_state;
-       uint16_t ipv4_options;
-
-       uint32_t resvd2;
-       uint32_t ipv6_options;
-       uint32_t ipv6_addl_options;
-       uint8_t ipv6_link_local_state;
-       uint8_t ipv6_addr0_state;
-       uint8_t ipv6_addr1_state;
-       uint8_t ipv6_default_router_state;
-       struct in6_addr ipv6_link_local_addr;
-       struct in6_addr ipv6_addr0;
-       struct in6_addr ipv6_addr1;
-       struct in6_addr ipv6_default_router_addr;
 
        /* qla82xx specific fields */
        struct device_reg_82xx  __iomem *qla4_8xxx_reg; /* Base I/O address */
@@ -584,6 +592,11 @@ struct scsi_qla_host {
 
        struct completion mbx_intr_comp;
 
+       struct ipaddress_config ip_config;
+       struct iscsi_iface *iface_ipv4;
+       struct iscsi_iface *iface_ipv6_0;
+       struct iscsi_iface *iface_ipv6_1;
+
        /* --- From About Firmware --- */
        uint16_t iscsi_major;
        uint16_t iscsi_minor;
@@ -591,16 +604,60 @@ struct scsi_qla_host {
        uint16_t bootload_minor;
        uint16_t bootload_patch;
        uint16_t bootload_build;
+
+       uint32_t flash_state;
+#define        QLFLASH_WAITING         0
+#define        QLFLASH_READING         1
+#define        QLFLASH_WRITING         2
+       struct dma_pool *chap_dma_pool;
+       uint8_t *chap_list; /* CHAP table cache */
+       struct mutex  chap_sem;
+#define CHAP_DMA_BLOCK_SIZE    512
+       struct workqueue_struct *task_wq;
+       unsigned long ddb_idx_map[MAX_DDB_ENTRIES / BITS_PER_LONG];
+#define SYSFS_FLAG_FW_SEL_BOOT 2
+       struct iscsi_boot_kset *boot_kset;
+       struct ql4_boot_tgt_info boot_tgt;
+       uint16_t phy_port_num;
+       uint16_t phy_port_cnt;
+       uint16_t iscsi_pci_func_cnt;
+       uint8_t model_name[16];
+       struct completion disable_acb_comp;
+};
+
+struct ql4_task_data {
+       struct scsi_qla_host *ha;
+       uint8_t iocb_req_cnt;
+       dma_addr_t data_dma;
+       void *req_buffer;
+       dma_addr_t req_dma;
+       uint32_t req_len;
+       void *resp_buffer;
+       dma_addr_t resp_dma;
+       uint32_t resp_len;
+       struct iscsi_task *task;
+       struct passthru_status sts;
+       struct work_struct task_work;
+};
+
+struct qla_endpoint {
+       struct Scsi_Host *host;
+       struct sockaddr dst_addr;
+};
+
+struct qla_conn {
+       struct qla_endpoint *qla_ep;
 };
 
 static inline int is_ipv4_enabled(struct scsi_qla_host *ha)
 {
-       return ((ha->ipv4_options & IPOPT_IPv4_PROTOCOL_ENABLE) != 0);
+       return ((ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE) != 0);
 }
 
 static inline int is_ipv6_enabled(struct scsi_qla_host *ha)
 {
-       return ((ha->ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE) != 0);
+       return ((ha->ip_config.ipv6_options &
+               IPV6_OPT_IPV6_PROTOCOL_ENABLE) != 0);
 }
 
 static inline int is_qla4010(struct scsi_qla_host *ha)
@@ -618,6 +675,11 @@ static inline int is_qla4032(struct scsi_qla_host *ha)
        return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP4032;
 }
 
+static inline int is_qla40XX(struct scsi_qla_host *ha)
+{
+       return is_qla4032(ha) || is_qla4022(ha) || is_qla4010(ha);
+}
+
 static inline int is_qla8022(struct scsi_qla_host *ha)
 {
        return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8022;
@@ -640,7 +702,7 @@ static inline int adapter_up(struct scsi_qla_host *ha)
 
 static inline struct scsi_qla_host* to_qla_host(struct Scsi_Host *shost)
 {
-       return (struct scsi_qla_host *)shost->hostdata;
+       return (struct scsi_qla_host *)iscsi_host_priv(shost);
 }
 
 static inline void __iomem* isp_semaphore(struct scsi_qla_host *ha)
@@ -760,6 +822,16 @@ static inline void ql4xxx_unlock_drvr(struct scsi_qla_host *a)
                ql4xxx_sem_unlock(a, QL4022_DRVR_SEM_MASK);
 }
 
+static inline int ql4xxx_reset_active(struct scsi_qla_host *ha)
+{
+       return test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
+              test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
+              test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
+              test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
+              test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
+              test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
+
+}
 /*---------------------------------------------------------------------------*/
 
 /* Defines for qla4xxx_initialize_adapter() and qla4xxx_recover_adapter() */
index 01082aa77098138dc9eed20a58b1725373420bae..cbd5a20dbbd150c7a1fbe4840b7a547a1097dc2a 100644 (file)
@@ -146,6 +146,13 @@ struct isp_reg {
 #define QL4022_NVRAM_SEM_MASK  (QL4022_RESOURCE_MASK_BASE_CODE << (10+16))
 #define QL4022_FLASH_SEM_MASK  (QL4022_RESOURCE_MASK_BASE_CODE << (13+16))
 
+/* nvram address for 4032 */
+#define NVRAM_PORT0_BOOT_MODE          0x03b1
+#define NVRAM_PORT0_BOOT_PRI_TGT       0x03b2
+#define NVRAM_PORT0_BOOT_SEC_TGT       0x03bb
+#define NVRAM_PORT1_BOOT_MODE          0x07b1
+#define NVRAM_PORT1_BOOT_PRI_TGT       0x07b2
+#define NVRAM_PORT1_BOOT_SEC_TGT       0x07bb
 
 
 /* Page # defines for 4022 */
@@ -194,6 +201,9 @@ static inline uint32_t clr_rmask(uint32_t val)
 /* ISP 4022 nvram definitions */
 #define NVR_WRITE_ENABLE                       0x00000010      /* 4022 */
 
+#define QL4010_NVRAM_SIZE                      0x200
+#define QL40X2_NVRAM_SIZE                      0x800
+
 /*  ISP port_status definitions */
 
 /*  ISP Semaphore definitions */
@@ -241,6 +251,8 @@ union external_hw_config_reg {
 #define FA_BOOT_CODE_ADDR_82           0x20000
 #define FA_RISC_CODE_ADDR_82           0x40000
 #define FA_GOLD_RISC_CODE_ADDR_82      0x80000
+#define FA_FLASH_ISCSI_CHAP            0x540000
+#define FA_FLASH_CHAP_SIZE             0xC0000
 
 /* Flash Description Table */
 struct qla_fdt_layout {
@@ -296,8 +308,11 @@ struct qla_flt_header {
 #define FLT_REG_FLT            0x1c
 #define FLT_REG_BOOTLOAD_82    0x72
 #define FLT_REG_FW_82          0x74
+#define FLT_REG_FW_82_1                0x97
 #define FLT_REG_GOLD_FW_82     0x75
 #define FLT_REG_BOOT_CODE_82   0x78
+#define FLT_REG_ISCSI_PARAM    0x65
+#define FLT_REG_ISCSI_CHAP     0x63
 
 struct qla_flt_region {
        uint32_t code;
@@ -331,9 +346,11 @@ struct qla_flt_region {
 #define MBOX_CMD_WRITE_FLASH                   0x0025
 #define MBOX_CMD_READ_FLASH                    0x0026
 #define MBOX_CMD_CLEAR_DATABASE_ENTRY          0x0031
+#define MBOX_CMD_CONN_OPEN                     0x0074
 #define MBOX_CMD_CONN_CLOSE_SESS_LOGOUT                0x0056
-#define LOGOUT_OPTION_CLOSE_SESSION            0x01
-#define LOGOUT_OPTION_RELOGIN                  0x02
+#define LOGOUT_OPTION_CLOSE_SESSION            0x0002
+#define LOGOUT_OPTION_RELOGIN                  0x0004
+#define LOGOUT_OPTION_FREE_DDB                 0x0008
 #define MBOX_CMD_EXECUTE_IOCB_A64              0x005A
 #define MBOX_CMD_INITIALIZE_FIRMWARE           0x0060
 #define MBOX_CMD_GET_INIT_FW_CTRL_BLOCK                0x0061
@@ -342,12 +359,15 @@ struct qla_flt_region {
 #define MBOX_CMD_GET_DATABASE_ENTRY            0x0064
 #define DDB_DS_UNASSIGNED                      0x00
 #define DDB_DS_NO_CONNECTION_ACTIVE            0x01
+#define DDB_DS_DISCOVERY                       0x02
 #define DDB_DS_SESSION_ACTIVE                  0x04
 #define DDB_DS_SESSION_FAILED                  0x06
 #define DDB_DS_LOGIN_IN_PROCESS                        0x07
 #define MBOX_CMD_GET_FW_STATE                  0x0069
 #define MBOX_CMD_GET_INIT_FW_CTRL_BLOCK_DEFAULTS 0x006A
 #define MBOX_CMD_GET_SYS_INFO                  0x0078
+#define MBOX_CMD_GET_NVRAM                     0x0078  /* For 40xx */
+#define MBOX_CMD_SET_NVRAM                     0x0079  /* For 40xx */
 #define MBOX_CMD_RESTORE_FACTORY_DEFAULTS      0x0087
 #define MBOX_CMD_SET_ACB                       0x0088
 #define MBOX_CMD_GET_ACB                       0x0089
@@ -375,7 +395,10 @@ struct qla_flt_region {
 #define FW_ADDSTATE_DHCPv4_LEASE_EXPIRED       0x0008
 #define FW_ADDSTATE_LINK_UP                    0x0010
 #define FW_ADDSTATE_ISNS_SVC_ENABLED           0x0020
+
 #define MBOX_CMD_GET_DATABASE_ENTRY_DEFAULTS   0x006B
+#define IPV6_DEFAULT_DDB_ENTRY                 0x0001
+
 #define MBOX_CMD_CONN_OPEN_SESS_LOGIN          0x0074
 #define MBOX_CMD_GET_CRASH_RECORD              0x0076  /* 4010 only */
 #define MBOX_CMD_GET_CONN_EVENT_LOG            0x0077
@@ -434,6 +457,14 @@ struct qla_flt_region {
 #define ACB_STATE_VALID                0x05
 #define ACB_STATE_DISABLING    0x06
 
+/* FLASH offsets */
+#define FLASH_SEGMENT_IFCB     0x04000000
+
+#define FLASH_OPT_RMW_HOLD     0
+#define FLASH_OPT_RMW_INIT     1
+#define FLASH_OPT_COMMIT       2
+#define FLASH_OPT_RMW_COMMIT   3
+
 /*************************************************************************/
 
 /* Host Adapter Initialization Control Block (from host) */
@@ -455,7 +486,8 @@ struct addr_ctrl_blk {
        uint8_t res0;   /* 07 */
        uint16_t eth_mtu_size;  /* 08-09 */
        uint16_t add_fw_options;        /* 0A-0B */
-#define SERIALIZE_TASK_MGMT            0x0400
+#define ADFWOPT_SERIALIZE_TASK_MGMT    0x0400
+#define ADFWOPT_AUTOCONN_DISABLE       0x0002
 
        uint8_t hb_interval;    /* 0C */
        uint8_t inst_num; /* 0D */
@@ -473,8 +505,10 @@ struct addr_ctrl_blk {
 
        uint16_t iscsi_opts;    /* 30-31 */
        uint16_t ipv4_tcp_opts; /* 32-33 */
+#define TCPOPT_DHCP_ENABLE             0x0200
        uint16_t ipv4_ip_opts;  /* 34-35 */
-#define  IPOPT_IPv4_PROTOCOL_ENABLE    0x8000
+#define IPOPT_IPV4_PROTOCOL_ENABLE     0x8000
+#define IPOPT_VLAN_TAGGING_ENABLE      0x2000
 
        uint16_t iscsi_max_pdu_size;    /* 36-37 */
        uint8_t ipv4_tos;       /* 38 */
@@ -526,6 +560,7 @@ struct addr_ctrl_blk {
        uint16_t ipv6_port;     /* 204-205 */
        uint16_t ipv6_opts;     /* 206-207 */
 #define IPV6_OPT_IPV6_PROTOCOL_ENABLE  0x8000
+#define IPV6_OPT_VLAN_TAGGING_ENABLE   0x2000
 
        uint16_t ipv6_addtl_opts;       /* 208-209 */
 #define IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE     0x0002 /* Pri ACB
@@ -574,13 +609,105 @@ struct init_fw_ctrl_blk {
 /*     struct addr_ctrl_blk sec;*/
 };
 
+#define PRIMARI_ACB            0
+#define SECONDARY_ACB          1
+
+struct addr_ctrl_blk_def {
+       uint8_t reserved1[1];   /* 00 */
+       uint8_t control;        /* 01 */
+       uint8_t reserved2[11];  /* 02-0C */
+       uint8_t inst_num;       /* 0D */
+       uint8_t reserved3[34];  /* 0E-2F */
+       uint16_t iscsi_opts;    /* 30-31 */
+       uint16_t ipv4_tcp_opts; /* 32-33 */
+       uint16_t ipv4_ip_opts;  /* 34-35 */
+       uint16_t iscsi_max_pdu_size;    /* 36-37 */
+       uint8_t ipv4_tos;       /* 38 */
+       uint8_t ipv4_ttl;       /* 39 */
+       uint8_t reserved4[2];   /* 3A-3B */
+       uint16_t def_timeout;   /* 3C-3D */
+       uint16_t iscsi_fburst_len;      /* 3E-3F */
+       uint8_t reserved5[4];   /* 40-43 */
+       uint16_t iscsi_max_outstnd_r2t; /* 44-45 */
+       uint8_t reserved6[2];   /* 46-47 */
+       uint16_t ipv4_port;     /* 48-49 */
+       uint16_t iscsi_max_burst_len;   /* 4A-4B */
+       uint8_t reserved7[4];   /* 4C-4F */
+       uint8_t ipv4_addr[4];   /* 50-53 */
+       uint16_t ipv4_vlan_tag; /* 54-55 */
+       uint8_t ipv4_addr_state;        /* 56 */
+       uint8_t ipv4_cacheid;   /* 57 */
+       uint8_t reserved8[8];   /* 58-5F */
+       uint8_t ipv4_subnet[4]; /* 60-63 */
+       uint8_t reserved9[12];  /* 64-6F */
+       uint8_t ipv4_gw_addr[4];        /* 70-73 */
+       uint8_t reserved10[84]; /* 74-C7 */
+       uint8_t abort_timer;    /* C8    */
+       uint8_t ipv4_tcp_wsf;   /* C9    */
+       uint8_t reserved11[10]; /* CA-D3 */
+       uint8_t ipv4_dhcp_vid_len;      /* D4 */
+       uint8_t ipv4_dhcp_vid[11];      /* D5-DF */
+       uint8_t reserved12[20]; /* E0-F3 */
+       uint8_t ipv4_dhcp_alt_cid_len;  /* F4 */
+       uint8_t ipv4_dhcp_alt_cid[11];  /* F5-FF */
+       uint8_t iscsi_name[224];        /* 100-1DF */
+       uint8_t reserved13[32]; /* 1E0-1FF */
+       uint32_t cookie;        /* 200-203 */
+       uint16_t ipv6_port;     /* 204-205 */
+       uint16_t ipv6_opts;     /* 206-207 */
+       uint16_t ipv6_addtl_opts;       /* 208-209 */
+       uint16_t ipv6_tcp_opts;         /* 20A-20B */
+       uint8_t ipv6_tcp_wsf;           /* 20C */
+       uint16_t ipv6_flow_lbl;         /* 20D-20F */
+       uint8_t ipv6_dflt_rtr_addr[16]; /* 210-21F */
+       uint16_t ipv6_vlan_tag;         /* 220-221 */
+       uint8_t ipv6_lnk_lcl_addr_state;        /* 222 */
+       uint8_t ipv6_addr0_state;       /* 223 */
+       uint8_t ipv6_addr1_state;       /* 224 */
+       uint8_t ipv6_dflt_rtr_state;    /* 225 */
+       uint8_t ipv6_traffic_class;     /* 226 */
+       uint8_t ipv6_hop_limit;         /* 227 */
+       uint8_t ipv6_if_id[8];          /* 228-22F */
+       uint8_t ipv6_addr0[16];         /* 230-23F */
+       uint8_t ipv6_addr1[16];         /* 240-24F */
+       uint32_t ipv6_nd_reach_time;    /* 250-253 */
+       uint32_t ipv6_nd_rexmit_timer;  /* 254-257 */
+       uint32_t ipv6_nd_stale_timeout; /* 258-25B */
+       uint8_t ipv6_dup_addr_detect_count;     /* 25C */
+       uint8_t ipv6_cache_id;          /* 25D */
+       uint8_t reserved14[18];         /* 25E-26F */
+       uint32_t ipv6_gw_advrt_mtu;     /* 270-273 */
+       uint8_t reserved15[140];        /* 274-2FF */
+};
+
 /*************************************************************************/
 
+#define MAX_CHAP_ENTRIES_40XX  128
+#define MAX_CHAP_ENTRIES_82XX  1024
+#define MAX_RESRV_CHAP_IDX     3
+#define FLASH_CHAP_OFFSET      0x06000000
+
+struct ql4_chap_table {
+       uint16_t link;
+       uint8_t flags;
+       uint8_t secret_len;
+#define MIN_CHAP_SECRET_LEN    12
+#define MAX_CHAP_SECRET_LEN    100
+       uint8_t secret[MAX_CHAP_SECRET_LEN];
+#define MAX_CHAP_NAME_LEN      256
+       uint8_t name[MAX_CHAP_NAME_LEN];
+       uint16_t reserved;
+#define CHAP_VALID_COOKIE      0x4092
+#define CHAP_INVALID_COOKIE    0xFFEE
+       uint16_t cookie;
+};
+
 struct dev_db_entry {
        uint16_t options;       /* 00-01 */
 #define DDB_OPT_DISC_SESSION  0x10
 #define DDB_OPT_TARGET       0x02 /* device is a target */
 #define DDB_OPT_IPV6_DEVICE    0x100
+#define DDB_OPT_AUTO_SENDTGTS_DISABLE          0x40
 #define DDB_OPT_IPV6_NULL_LINK_LOCAL           0x800 /* post connection */
 #define DDB_OPT_IPV6_FW_DEFINED_LINK_LOCAL     0x800 /* pre connection */
 
@@ -591,6 +718,7 @@ struct dev_db_entry {
        uint16_t tcp_options;   /* 0A-0B */
        uint16_t ip_options;    /* 0C-0D */
        uint16_t iscsi_max_rcv_data_seg_len;    /* 0E-0F */
+#define BYTE_UNITS     512
        uint32_t res1;  /* 10-13 */
        uint16_t iscsi_max_snd_data_seg_len;    /* 14-15 */
        uint16_t iscsi_first_burst_len; /* 16-17 */
@@ -627,7 +755,10 @@ struct dev_db_entry {
        uint8_t tcp_rcv_wsf;    /* 1C7 */
        uint32_t stat_sn;       /* 1C8-1CB */
        uint32_t exp_stat_sn;   /* 1CC-1CF */
-       uint8_t res6[0x30];     /* 1D0-1FF */
+       uint8_t res6[0x2b];     /* 1D0-1FB */
+#define DDB_VALID_COOKIE       0x9034
+       uint16_t cookie;        /* 1FC-1FD */
+       uint16_t len;           /* 1FE-1FF */
 };
 
 /*************************************************************************/
@@ -639,6 +770,14 @@ struct dev_db_entry {
 #define FLASH_EOF_OFFSET       (FLASH_DEFAULTBLOCKSIZE-8) /* 4 bytes
                                                            * for EOF
                                                            * signature */
+#define FLASH_RAW_ACCESS_ADDR  0x8e000000
+
+#define BOOT_PARAM_OFFSET_PORT0 0x3b0
+#define BOOT_PARAM_OFFSET_PORT1 0x7b0
+
+#define FLASH_OFFSET_DB_INFO   0x05000000
+#define FLASH_OFFSET_DB_END    (FLASH_OFFSET_DB_INFO + 0x7fff)
+
 
 struct sys_info_phys_addr {
        uint8_t address[6];     /* 00-05 */
@@ -774,6 +913,7 @@ struct qla4_header {
 
        uint8_t entryStatus;
        uint8_t systemDefined;
+#define SD_ISCSI_PDU   0x01
        uint8_t entryCount;
 
        /* SyetemDefined definition */
@@ -931,21 +1071,22 @@ struct passthru0 {
        struct qla4_header hdr;                /* 00-03 */
        uint32_t handle;        /* 04-07 */
        uint16_t target;        /* 08-09 */
-       uint16_t connectionID;  /* 0A-0B */
+       uint16_t connection_id; /* 0A-0B */
 #define ISNS_DEFAULT_SERVER_CONN_ID    ((uint16_t)0x8000)
 
-       uint16_t controlFlags;  /* 0C-0D */
+       uint16_t control_flags; /* 0C-0D */
 #define PT_FLAG_ETHERNET_FRAME         0x8000
 #define PT_FLAG_ISNS_PDU               0x8000
 #define PT_FLAG_SEND_BUFFER            0x0200
 #define PT_FLAG_WAIT_4_RESPONSE                0x0100
+#define PT_FLAG_ISCSI_PDU              0x1000
 
        uint16_t timeout;       /* 0E-0F */
 #define PT_DEFAULT_TIMEOUT             30 /* seconds */
 
-       struct data_seg_a64 outDataSeg64;       /* 10-1B */
+       struct data_seg_a64 out_dsd;    /* 10-1B */
        uint32_t res1;          /* 1C-1F */
-       struct data_seg_a64 inDataSeg64;        /* 20-2B */
+       struct data_seg_a64 in_dsd;     /* 20-2B */
        uint8_t res2[20];       /* 2C-3F */
 };
 
@@ -978,4 +1119,43 @@ struct response {
 #define RESPONSE_PROCESSED     0xDEADDEAD      /* Signature */
 };
 
+struct ql_iscsi_stats {
+       uint8_t reserved1[656]; /* 0000-028F */
+       uint32_t tx_cmd_pdu; /* 0290-0293 */
+       uint32_t tx_resp_pdu; /* 0294-0297 */
+       uint32_t rx_cmd_pdu; /* 0298-029B */
+       uint32_t rx_resp_pdu; /* 029C-029F */
+
+       uint64_t tx_data_octets; /* 02A0-02A7 */
+       uint64_t rx_data_octets; /* 02A8-02AF */
+
+       uint32_t hdr_digest_err; /* 02B0–02B3 */
+       uint32_t data_digest_err; /* 02B4–02B7 */
+       uint32_t conn_timeout_err; /* 02B8–02BB */
+       uint32_t framing_err; /* 02BC–02BF */
+
+       uint32_t tx_nopout_pdus; /* 02C0–02C3 */
+       uint32_t tx_scsi_cmd_pdus;  /* 02C4–02C7 */
+       uint32_t tx_tmf_cmd_pdus; /* 02C8–02CB */
+       uint32_t tx_login_cmd_pdus; /* 02CC–02CF */
+       uint32_t tx_text_cmd_pdus; /* 02D0–02D3 */
+       uint32_t tx_scsi_write_pdus; /* 02D4–02D7 */
+       uint32_t tx_logout_cmd_pdus; /* 02D8–02DB */
+       uint32_t tx_snack_req_pdus; /* 02DC–02DF */
+
+       uint32_t rx_nopin_pdus; /* 02E0–02E3 */
+       uint32_t rx_scsi_resp_pdus; /* 02E4–02E7 */
+       uint32_t rx_tmf_resp_pdus; /* 02E8–02EB */
+       uint32_t rx_login_resp_pdus; /* 02EC–02EF */
+       uint32_t rx_text_resp_pdus; /* 02F0–02F3 */
+       uint32_t rx_scsi_read_pdus; /* 02F4–02F7 */
+       uint32_t rx_logout_resp_pdus; /* 02F8–02FB */
+
+       uint32_t rx_r2t_pdus; /* 02FC–02FF */
+       uint32_t rx_async_pdus; /* 0300–0303 */
+       uint32_t rx_reject_pdus; /* 0304–0307 */
+
+       uint8_t reserved2[264]; /* 0x0308 - 0x040F */
+};
+
 #endif /*  _QLA4X_FW_H */
index a53a256c1f8d9e6443512456ba8243574307c46a..160db9d5ea2101e8ccb2ef4772c81429747a4b0d 100644 (file)
@@ -12,20 +12,15 @@ struct iscsi_cls_conn;
 
 int qla4xxx_hw_reset(struct scsi_qla_host *ha);
 int ql4xxx_lock_drvr_wait(struct scsi_qla_host *a);
-int qla4xxx_send_tgts(struct scsi_qla_host *ha, char *ip, uint16_t port);
 int qla4xxx_send_command_to_isp(struct scsi_qla_host *ha, struct srb *srb);
-int qla4xxx_initialize_adapter(struct scsi_qla_host *ha,
-                              uint8_t renew_ddb_list);
+int qla4xxx_initialize_adapter(struct scsi_qla_host *ha);
 int qla4xxx_soft_reset(struct scsi_qla_host *ha);
 irqreturn_t qla4xxx_intr_handler(int irq, void *dev_id);
 
-void qla4xxx_free_ddb_list(struct scsi_qla_host *ha);
 void qla4xxx_free_ddb(struct scsi_qla_host *ha, struct ddb_entry *ddb_entry);
 void qla4xxx_process_aen(struct scsi_qla_host *ha, uint8_t process_aen);
 
 int qla4xxx_get_dhcp_ip_address(struct scsi_qla_host *ha);
-int qla4xxx_relogin_device(struct scsi_qla_host *ha,
-                          struct ddb_entry *ddb_entry);
 int qla4xxx_abort_task(struct scsi_qla_host *ha, struct srb *srb);
 int qla4xxx_reset_lun(struct scsi_qla_host *ha, struct ddb_entry *ddb_entry,
                      int lun);
@@ -51,15 +46,24 @@ int qla4xxx_get_fwddb_entry(struct scsi_qla_host *ha,
                            uint16_t *connection_id);
 
 int qla4xxx_set_ddb_entry(struct scsi_qla_host * ha, uint16_t fw_ddb_index,
-                         dma_addr_t fw_ddb_entry_dma);
-
-void qla4xxx_mark_device_missing(struct scsi_qla_host *ha,
-                                struct ddb_entry *ddb_entry);
+                         dma_addr_t fw_ddb_entry_dma, uint32_t *mbx_sts);
+uint8_t qla4xxx_get_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
+                        uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma);
+int qla4xxx_conn_close_sess_logout(struct scsi_qla_host *ha,
+                                  uint16_t fw_ddb_index,
+                                  uint16_t connection_id,
+                                  uint16_t option);
+int qla4xxx_disable_acb(struct scsi_qla_host *ha);
+int qla4xxx_set_acb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
+                   uint32_t *mbox_sts, dma_addr_t acb_dma);
+int qla4xxx_get_acb(struct scsi_qla_host *ha, dma_addr_t acb_dma,
+                   uint32_t acb_type, uint32_t len);
+int qla4xxx_get_ip_state(struct scsi_qla_host *ha, uint32_t acb_idx,
+                        uint32_t ip_idx, uint32_t *sts);
+void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session);
 u16 rd_nvram_word(struct scsi_qla_host *ha, int offset);
+u8 rd_nvram_byte(struct scsi_qla_host *ha, int offset);
 void qla4xxx_get_crash_record(struct scsi_qla_host *ha);
-struct ddb_entry *qla4xxx_alloc_sess(struct scsi_qla_host *ha);
-int qla4xxx_add_sess(struct ddb_entry *);
-void qla4xxx_destroy_sess(struct ddb_entry *ddb_entry);
 int qla4xxx_is_nvram_configuration_valid(struct scsi_qla_host *ha);
 int qla4xxx_about_firmware(struct scsi_qla_host *ha);
 void qla4xxx_interrupt_service_routine(struct scsi_qla_host *ha,
@@ -68,14 +72,13 @@ int qla4xxx_init_rings(struct scsi_qla_host *ha);
 void qla4xxx_srb_compl(struct kref *ref);
 struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
                uint32_t index);
-int qla4xxx_reinitialize_ddb_list(struct scsi_qla_host *ha);
 int qla4xxx_process_ddb_changed(struct scsi_qla_host *ha, uint32_t fw_ddb_index,
                uint32_t state, uint32_t conn_error);
 void qla4xxx_dump_buffer(void *b, uint32_t size);
 int qla4xxx_send_marker_iocb(struct scsi_qla_host *ha,
        struct ddb_entry *ddb_entry, int lun, uint16_t mrkr_mod);
-int qla4_is_relogin_allowed(struct scsi_qla_host *ha, uint32_t conn_err);
-
+int qla4xxx_set_flash(struct scsi_qla_host *ha, dma_addr_t dma_addr,
+                     uint32_t offset, uint32_t length, uint32_t options);
 int qla4xxx_mailbox_command(struct scsi_qla_host *ha, uint8_t inCount,
                uint8_t outCount, uint32_t *mbx_cmd, uint32_t *mbx_sts);
 
@@ -95,6 +98,11 @@ void qla4xxx_wake_dpc(struct scsi_qla_host *ha);
 void qla4xxx_get_conn_event_log(struct scsi_qla_host *ha);
 void qla4xxx_mailbox_premature_completion(struct scsi_qla_host *ha);
 void qla4xxx_dump_registers(struct scsi_qla_host *ha);
+uint8_t qla4xxx_update_local_ifcb(struct scsi_qla_host *ha,
+                                 uint32_t *mbox_cmd,
+                                 uint32_t *mbox_sts,
+                                 struct addr_ctrl_blk *init_fw_cb,
+                                 dma_addr_t init_fw_cb_dma);
 
 void qla4_8xxx_pci_config(struct scsi_qla_host *);
 int qla4_8xxx_iospace_config(struct scsi_qla_host *ha);
@@ -134,6 +142,37 @@ int qla4_8xxx_device_state_handler(struct scsi_qla_host *ha);
 void qla4_8xxx_need_qsnt_handler(struct scsi_qla_host *ha);
 void qla4_8xxx_clear_drv_active(struct scsi_qla_host *ha);
 void qla4_8xxx_set_drv_active(struct scsi_qla_host *ha);
+int qla4xxx_conn_open(struct scsi_qla_host *ha, uint16_t fw_ddb_index);
+int qla4xxx_set_param_ddbentry(struct scsi_qla_host *ha,
+                              struct ddb_entry *ddb_entry,
+                              struct iscsi_cls_conn *cls_conn,
+                              uint32_t *mbx_sts);
+int qla4xxx_session_logout_ddb(struct scsi_qla_host *ha,
+                              struct ddb_entry *ddb_entry, int options);
+int qla4xxx_req_ddb_entry(struct scsi_qla_host *ha, uint32_t fw_ddb_index,
+                         uint32_t *mbx_sts);
+int qla4xxx_clear_ddb_entry(struct scsi_qla_host *ha, uint32_t fw_ddb_index);
+int qla4xxx_send_passthru0(struct iscsi_task *task);
+int qla4xxx_get_mgmt_data(struct scsi_qla_host *ha, uint16_t fw_ddb_index,
+                         uint16_t stats_size, dma_addr_t stats_dma);
+void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
+                                      struct ddb_entry *ddb_entry);
+int qla4xxx_bootdb_by_index(struct scsi_qla_host *ha,
+                           struct dev_db_entry *fw_ddb_entry,
+                           dma_addr_t fw_ddb_entry_dma, uint16_t ddb_index);
+int qla4xxx_get_chap(struct scsi_qla_host *ha, char *username,
+                    char *password, uint16_t idx);
+int qla4xxx_get_nvram(struct scsi_qla_host *ha, dma_addr_t nvram_dma,
+                     uint32_t offset, uint32_t size);
+int qla4xxx_set_nvram(struct scsi_qla_host *ha, dma_addr_t nvram_dma,
+                     uint32_t offset, uint32_t size);
+int qla4xxx_restore_factory_defaults(struct scsi_qla_host *ha,
+                                    uint32_t region, uint32_t field0,
+                                    uint32_t field1);
+
+/* BSG Functions */
+int qla4xxx_bsg_request(struct bsg_job *bsg_job);
+int qla4xxx_process_vendor_specific(struct bsg_job *bsg_job);
 
 extern int ql4xextended_error_logging;
 extern int ql4xdontresethba;
index 42ed5db2d530fafa47d96310f1eea49b8a169fc9..3075fbaef5533d6574cedce72f9c24b722696afa 100644 (file)
@@ -11,9 +11,6 @@
 #include "ql4_dbg.h"
 #include "ql4_inline.h"
 
-static struct ddb_entry *qla4xxx_alloc_ddb(struct scsi_qla_host *ha,
-                                          uint32_t fw_ddb_index);
-
 static void ql4xxx_set_mac_number(struct scsi_qla_host *ha)
 {
        uint32_t value;
@@ -48,41 +45,15 @@ static void ql4xxx_set_mac_number(struct scsi_qla_host *ha)
  * @ha: pointer to host adapter structure.
  * @ddb_entry: pointer to device database entry
  *
- * This routine deallocates and unlinks the specified ddb_entry from the
- * adapter's
+ * This routine marks a DDB entry INVALID
  **/
 void qla4xxx_free_ddb(struct scsi_qla_host *ha,
     struct ddb_entry *ddb_entry)
 {
-       /* Remove device entry from list */
-       list_del_init(&ddb_entry->list);
-
        /* Remove device pointer from index mapping arrays */
        ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] =
                (struct ddb_entry *) INVALID_ENTRY;
        ha->tot_ddbs--;
-
-       /* Free memory and scsi-ml struct for device entry */
-       qla4xxx_destroy_sess(ddb_entry);
-}
-
-/**
- * qla4xxx_free_ddb_list - deallocate all ddbs
- * @ha: pointer to host adapter structure.
- *
- * This routine deallocates and removes all devices on the sppecified adapter.
- **/
-void qla4xxx_free_ddb_list(struct scsi_qla_host *ha)
-{
-       struct list_head *ptr;
-       struct ddb_entry *ddb_entry;
-
-       while (!list_empty(&ha->ddb_list)) {
-               ptr = ha->ddb_list.next;
-               /* Free memory for device entry and remove */
-               ddb_entry = list_entry(ptr, struct ddb_entry, list);
-               qla4xxx_free_ddb(ha, ddb_entry);
-       }
 }
 
 /**
@@ -236,38 +207,44 @@ qla4xxx_wait_for_ip_config(struct scsi_qla_host *ha)
                                    FW_ADDSTATE_DHCPv4_LEASE_ACQUIRED) == 0)) {
                        ipv4_wait = 1;
                }
-               if (((ha->ipv6_addl_options &
-                           IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) != 0) &&
-                   ((ha->ipv6_link_local_state == IP_ADDRSTATE_ACQUIRING) ||
-                    (ha->ipv6_addr0_state == IP_ADDRSTATE_ACQUIRING) ||
-                    (ha->ipv6_addr1_state == IP_ADDRSTATE_ACQUIRING))) {
+               if (((ha->ip_config.ipv6_addl_options &
+                     IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) != 0) &&
+                   ((ha->ip_config.ipv6_link_local_state ==
+                     IP_ADDRSTATE_ACQUIRING) ||
+                    (ha->ip_config.ipv6_addr0_state ==
+                     IP_ADDRSTATE_ACQUIRING) ||
+                    (ha->ip_config.ipv6_addr1_state ==
+                     IP_ADDRSTATE_ACQUIRING))) {
 
                        ipv6_wait = 1;
 
-                       if ((ha->ipv6_link_local_state ==
-                                                    IP_ADDRSTATE_PREFERRED) ||
-                           (ha->ipv6_addr0_state == IP_ADDRSTATE_PREFERRED) ||
-                           (ha->ipv6_addr1_state == IP_ADDRSTATE_PREFERRED)) {
+                       if ((ha->ip_config.ipv6_link_local_state ==
+                            IP_ADDRSTATE_PREFERRED) ||
+                           (ha->ip_config.ipv6_addr0_state ==
+                            IP_ADDRSTATE_PREFERRED) ||
+                           (ha->ip_config.ipv6_addr1_state ==
+                            IP_ADDRSTATE_PREFERRED)) {
                                DEBUG2(printk(KERN_INFO "scsi%ld: %s: "
                                              "Preferred IP configured."
                                              " Don't wait!\n", ha->host_no,
                                              __func__));
                                ipv6_wait = 0;
                        }
-                       if (memcmp(&ha->ipv6_default_router_addr, ip_address,
-                               IPv6_ADDR_LEN) == 0) {
+                       if (memcmp(&ha->ip_config.ipv6_default_router_addr,
+                                  ip_address, IPv6_ADDR_LEN) == 0) {
                                DEBUG2(printk(KERN_INFO "scsi%ld: %s: "
                                              "No Router configured. "
                                              "Don't wait!\n", ha->host_no,
                                              __func__));
                                ipv6_wait = 0;
                        }
-                       if ((ha->ipv6_default_router_state ==
-                                               IPV6_RTRSTATE_MANUAL) &&
-                           (ha->ipv6_link_local_state ==
-                                               IP_ADDRSTATE_TENTATIVE) &&
-                           (memcmp(&ha->ipv6_link_local_addr,
-                                   &ha->ipv6_default_router_addr, 4) == 0)) {
+                       if ((ha->ip_config.ipv6_default_router_state ==
+                            IPV6_RTRSTATE_MANUAL) &&
+                           (ha->ip_config.ipv6_link_local_state ==
+                            IP_ADDRSTATE_TENTATIVE) &&
+                           (memcmp(&ha->ip_config.ipv6_link_local_addr,
+                            &ha->ip_config.ipv6_default_router_addr, 4) ==
+                            0)) {
                                DEBUG2(printk("scsi%ld: %s: LinkLocal Router & "
                                        "IP configured. Don't wait!\n",
                                        ha->host_no, __func__));
@@ -279,11 +256,14 @@ qla4xxx_wait_for_ip_config(struct scsi_qla_host *ha)
                                      "IP(s) \"", ha->host_no, __func__));
                        if (ipv4_wait)
                                DEBUG2(printk("IPv4 "));
-                       if (ha->ipv6_link_local_state == IP_ADDRSTATE_ACQUIRING)
+                       if (ha->ip_config.ipv6_link_local_state ==
+                           IP_ADDRSTATE_ACQUIRING)
                                DEBUG2(printk("IPv6LinkLocal "));
-                       if (ha->ipv6_addr0_state == IP_ADDRSTATE_ACQUIRING)
+                       if (ha->ip_config.ipv6_addr0_state ==
+                           IP_ADDRSTATE_ACQUIRING)
                                DEBUG2(printk("IPv6Addr0 "));
-                       if (ha->ipv6_addr1_state == IP_ADDRSTATE_ACQUIRING)
+                       if (ha->ip_config.ipv6_addr1_state ==
+                           IP_ADDRSTATE_ACQUIRING)
                                DEBUG2(printk("IPv6Addr1 "));
                        DEBUG2(printk("\"\n"));
                }
@@ -466,486 +446,19 @@ static int qla4xxx_init_firmware(struct scsi_qla_host *ha)
        return qla4xxx_get_firmware_status(ha);
 }
 
-static struct ddb_entry* qla4xxx_get_ddb_entry(struct scsi_qla_host *ha,
-                                               uint32_t fw_ddb_index,
-                                               uint32_t *new_tgt)
-{
-       struct dev_db_entry *fw_ddb_entry = NULL;
-       dma_addr_t fw_ddb_entry_dma;
-       struct ddb_entry *ddb_entry = NULL;
-       int found = 0;
-       uint32_t device_state;
-
-       *new_tgt = 0;
-       /* Make sure the dma buffer is valid */
-       fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
-                                         sizeof(*fw_ddb_entry),
-                                         &fw_ddb_entry_dma, GFP_KERNEL);
-       if (fw_ddb_entry == NULL) {
-               DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n",
-                             ha->host_no, __func__));
-               goto exit_get_ddb_entry_no_free;
-       }
-
-       if (qla4xxx_get_fwddb_entry(ha, fw_ddb_index, fw_ddb_entry,
-                                   fw_ddb_entry_dma, NULL, NULL,
-                                   &device_state, NULL, NULL, NULL) ==
-                                   QLA_ERROR) {
-               DEBUG2(printk("scsi%ld: %s: failed get_ddb_entry for "
-                             "fw_ddb_index %d\n", ha->host_no, __func__,
-                             fw_ddb_index));
-               goto exit_get_ddb_entry;
-       }
-
-       /* Allocate DDB if not already allocated. */
-       DEBUG2(printk("scsi%ld: %s: Looking for ddb[%d]\n", ha->host_no,
-                     __func__, fw_ddb_index));
-       list_for_each_entry(ddb_entry, &ha->ddb_list, list) {
-               if ((memcmp(ddb_entry->iscsi_name, fw_ddb_entry->iscsi_name,
-                          ISCSI_NAME_SIZE) == 0) &&
-                       (ddb_entry->tpgt ==
-                               le32_to_cpu(fw_ddb_entry->tgt_portal_grp)) &&
-                       (memcmp(ddb_entry->isid, fw_ddb_entry->isid,
-                               sizeof(ddb_entry->isid)) == 0)) {
-                       found++;
-                       break;
-               }
-       }
-
-       /* if not found allocate new ddb */
-       if (!found) {
-               DEBUG2(printk("scsi%ld: %s: ddb[%d] not found - allocating "
-                             "new ddb\n", ha->host_no, __func__,
-                             fw_ddb_index));
-               *new_tgt = 1;
-               ddb_entry = qla4xxx_alloc_ddb(ha, fw_ddb_index);
-       }
-
-exit_get_ddb_entry:
-       dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry,
-                         fw_ddb_entry_dma);
-
-exit_get_ddb_entry_no_free:
-       return ddb_entry;
-}
-
-/**
- * qla4xxx_update_ddb_entry - update driver's internal ddb
- * @ha: pointer to host adapter structure.
- * @ddb_entry: pointer to device database structure to be filled
- * @fw_ddb_index: index of the ddb entry in fw ddb table
- *
- * This routine updates the driver's internal device database entry
- * with information retrieved from the firmware's device database
- * entry for the specified device. The ddb_entry->fw_ddb_index field
- * must be initialized prior to        calling this routine
- *
- **/
-static int qla4xxx_update_ddb_entry(struct scsi_qla_host *ha,
-                                   struct ddb_entry *ddb_entry,
-                                   uint32_t fw_ddb_index)
-{
-       struct dev_db_entry *fw_ddb_entry = NULL;
-       dma_addr_t fw_ddb_entry_dma;
-       int status = QLA_ERROR;
-       uint32_t conn_err;
-
-       if (ddb_entry == NULL) {
-               DEBUG2(printk("scsi%ld: %s: ddb_entry is NULL\n", ha->host_no,
-                             __func__));
-
-               goto exit_update_ddb_no_free;
-       }
-
-       /* Make sure the dma buffer is valid */
-       fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
-                                         sizeof(*fw_ddb_entry),
-                                         &fw_ddb_entry_dma, GFP_KERNEL);
-       if (fw_ddb_entry == NULL) {
-               DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n",
-                             ha->host_no, __func__));
-
-               goto exit_update_ddb_no_free;
-       }
-
-       if (qla4xxx_get_fwddb_entry(ha, fw_ddb_index, fw_ddb_entry,
-                                   fw_ddb_entry_dma, NULL, NULL,
-                                   &ddb_entry->fw_ddb_device_state, &conn_err,
-                                   &ddb_entry->tcp_source_port_num,
-                                   &ddb_entry->connection_id) ==
-                                   QLA_ERROR) {
-               DEBUG2(printk("scsi%ld: %s: failed get_ddb_entry for "
-                             "fw_ddb_index %d\n", ha->host_no, __func__,
-                             fw_ddb_index));
-
-               goto exit_update_ddb;
-       }
-
-       status = QLA_SUCCESS;
-       ddb_entry->options = le16_to_cpu(fw_ddb_entry->options);
-       ddb_entry->target_session_id = le16_to_cpu(fw_ddb_entry->tsid);
-       ddb_entry->task_mgmt_timeout =
-               le16_to_cpu(fw_ddb_entry->def_timeout);
-       ddb_entry->CmdSn = 0;
-       ddb_entry->exe_throttle = le16_to_cpu(fw_ddb_entry->exec_throttle);
-       ddb_entry->default_relogin_timeout =
-               le16_to_cpu(fw_ddb_entry->def_timeout);
-       ddb_entry->default_time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
-
-       /* Update index in case it changed */
-       ddb_entry->fw_ddb_index = fw_ddb_index;
-       ha->fw_ddb_index_map[fw_ddb_index] = ddb_entry;
-
-       ddb_entry->port = le16_to_cpu(fw_ddb_entry->port);
-       ddb_entry->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
-       memcpy(ddb_entry->isid, fw_ddb_entry->isid, sizeof(ddb_entry->isid));
-
-       memcpy(&ddb_entry->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
-              min(sizeof(ddb_entry->iscsi_name),
-                  sizeof(fw_ddb_entry->iscsi_name)));
-       memcpy(&ddb_entry->iscsi_alias[0], &fw_ddb_entry->iscsi_alias[0],
-              min(sizeof(ddb_entry->iscsi_alias),
-                  sizeof(fw_ddb_entry->iscsi_alias)));
-       memcpy(&ddb_entry->ip_addr[0], &fw_ddb_entry->ip_addr[0],
-              min(sizeof(ddb_entry->ip_addr), sizeof(fw_ddb_entry->ip_addr)));
-
-       ddb_entry->iscsi_max_burst_len = fw_ddb_entry->iscsi_max_burst_len;
-       ddb_entry->iscsi_max_outsnd_r2t = fw_ddb_entry->iscsi_max_outsnd_r2t;
-       ddb_entry->iscsi_first_burst_len = fw_ddb_entry->iscsi_first_burst_len;
-       ddb_entry->iscsi_max_rcv_data_seg_len =
-                               fw_ddb_entry->iscsi_max_rcv_data_seg_len;
-       ddb_entry->iscsi_max_snd_data_seg_len =
-                               fw_ddb_entry->iscsi_max_snd_data_seg_len;
-
-       if (ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
-               memcpy(&ddb_entry->remote_ipv6_addr,
-                       fw_ddb_entry->ip_addr,
-                       min(sizeof(ddb_entry->remote_ipv6_addr),
-                       sizeof(fw_ddb_entry->ip_addr)));
-               memcpy(&ddb_entry->link_local_ipv6_addr,
-                       fw_ddb_entry->link_local_ipv6_addr,
-                       min(sizeof(ddb_entry->link_local_ipv6_addr),
-                       sizeof(fw_ddb_entry->link_local_ipv6_addr)));
-
-               DEBUG2(ql4_printk(KERN_INFO, ha, "%s: DDB[%d] State %04x"
-                                       " ConnErr %08x IP %pI6 "
-                                       ":%04d \"%s\"\n",
-                                       __func__, fw_ddb_index,
-                                       ddb_entry->fw_ddb_device_state,
-                                       conn_err, fw_ddb_entry->ip_addr,
-                                       le16_to_cpu(fw_ddb_entry->port),
-                                       fw_ddb_entry->iscsi_name));
-       } else
-               DEBUG2(ql4_printk(KERN_INFO, ha, "%s: DDB[%d] State %04x"
-                                       " ConnErr %08x IP %pI4 "
-                                       ":%04d \"%s\"\n",
-                                       __func__, fw_ddb_index,
-                                       ddb_entry->fw_ddb_device_state,
-                                       conn_err, fw_ddb_entry->ip_addr,
-                                       le16_to_cpu(fw_ddb_entry->port),
-                                       fw_ddb_entry->iscsi_name));
-exit_update_ddb:
-       if (fw_ddb_entry)
-               dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
-                                 fw_ddb_entry, fw_ddb_entry_dma);
-
-exit_update_ddb_no_free:
-       return status;
-}
-
-/**
- * qla4xxx_alloc_ddb - allocate device database entry
- * @ha: Pointer to host adapter structure.
- * @fw_ddb_index: Firmware's device database index
- *
- * This routine allocates a ddb_entry, ititializes some values, and
- * inserts it into the ddb list.
- **/
-static struct ddb_entry * qla4xxx_alloc_ddb(struct scsi_qla_host *ha,
-                                           uint32_t fw_ddb_index)
+static void qla4xxx_set_model_info(struct scsi_qla_host *ha)
 {
-       struct ddb_entry *ddb_entry;
-
-       DEBUG2(printk("scsi%ld: %s: fw_ddb_index [%d]\n", ha->host_no,
-                     __func__, fw_ddb_index));
-
-       ddb_entry = qla4xxx_alloc_sess(ha);
-       if (ddb_entry == NULL) {
-               DEBUG2(printk("scsi%ld: %s: Unable to allocate memory "
-                             "to add fw_ddb_index [%d]\n",
-                             ha->host_no, __func__, fw_ddb_index));
-               return ddb_entry;
-       }
+       uint16_t board_id_string[8];
+       int i;
+       int size = sizeof(ha->nvram->isp4022.boardIdStr);
+       int offset = offsetof(struct eeprom_data, isp4022.boardIdStr) / 2;
 
-       ddb_entry->fw_ddb_index = fw_ddb_index;
-       atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
-       atomic_set(&ddb_entry->relogin_timer, 0);
-       atomic_set(&ddb_entry->relogin_retry_count, 0);
-       atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
-       list_add_tail(&ddb_entry->list, &ha->ddb_list);
-       ha->fw_ddb_index_map[fw_ddb_index] = ddb_entry;
-       ha->tot_ddbs++;
-
-       return ddb_entry;
-}
-
-/**
- * qla4_is_relogin_allowed - Are we allowed to login?
- * @ha: Pointer to host adapter structure.
- * @conn_err: Last connection error associated with the ddb
- *
- * This routine tests the given connection error to determine if
- * we are allowed to login.
- **/
-int qla4_is_relogin_allowed(struct scsi_qla_host *ha, uint32_t conn_err)
-{
-       uint32_t err_code, login_rsp_sts_class;
-       int relogin = 1;
-
-       err_code = ((conn_err & 0x00ff0000) >> 16);
-       login_rsp_sts_class = ((conn_err & 0x0000ff00) >> 8);
-       if (err_code == 0x1c || err_code == 0x06) {
-               DEBUG2(ql4_printk(KERN_INFO, ha,
-                   ": conn_err=0x%08x, send target completed"
-                   " or access denied failure\n", conn_err));
-               relogin = 0;
-       }
-       if ((err_code == 0x08) && (login_rsp_sts_class == 0x02)) {
-               /* Login Response PDU returned an error.
-                  Login Response Status in Error Code Detail
-                  indicates login should not be retried.*/
-               DEBUG2(ql4_printk(KERN_INFO, ha,
-                   ": conn_err=0x%08x, do not retry relogin\n",
-                   conn_err));
-               relogin = 0;
+       for (i = 0; i < (size / 2) ; i++) {
+               board_id_string[i] = rd_nvram_word(ha, offset);
+               offset += 1;
        }
 
-       return relogin;
-}
-
-static void qla4xxx_flush_AENS(struct scsi_qla_host *ha)
-{
-       unsigned long wtime;
-
-       /* Flush the 0x8014 AEN from the firmware as a result of
-        * Auto connect. We are basically doing get_firmware_ddb()
-        * to determine whether we need to log back in or not.
-        * Trying to do a set ddb before we have processed 0x8014
-        * will result in another set_ddb() for the same ddb. In other
-        * words there will be stale entries in the aen_q.
-        */
-       wtime = jiffies + (2 * HZ);
-       do {
-               if (qla4xxx_get_firmware_state(ha) == QLA_SUCCESS)
-                       if (ha->firmware_state & (BIT_2 | BIT_0))
-                               return;
-
-               if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
-                       qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
-
-               msleep(1000);
-       } while (!time_after_eq(jiffies, wtime));
-}
-
-/**
- * qla4xxx_build_ddb_list - builds driver ddb list
- * @ha: Pointer to host adapter structure.
- *
- * This routine searches for all valid firmware ddb entries and builds
- * an internal ddb list. Ddbs that are considered valid are those with
- * a device state of SESSION_ACTIVE.
- * A relogin (set_ddb) is issued for DDBs that are not online.
- **/
-static int qla4xxx_build_ddb_list(struct scsi_qla_host *ha)
-{
-       int status = QLA_ERROR;
-       uint32_t fw_ddb_index = 0;
-       uint32_t next_fw_ddb_index = 0;
-       uint32_t ddb_state;
-       uint32_t conn_err;
-       struct ddb_entry *ddb_entry;
-       struct dev_db_entry *fw_ddb_entry = NULL;
-       dma_addr_t fw_ddb_entry_dma;
-       uint32_t ipv6_device;
-       uint32_t new_tgt;
-
-       qla4xxx_flush_AENS(ha);
-
-       fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
-                       &fw_ddb_entry_dma, GFP_KERNEL);
-       if (fw_ddb_entry == NULL) {
-               DEBUG2(ql4_printk(KERN_INFO, ha, "%s: DMA alloc failed\n",
-                               __func__));
-
-               goto exit_build_ddb_list_no_free;
-       }
-
-       ql4_printk(KERN_INFO, ha, "Initializing DDBs ...\n");
-       for (fw_ddb_index = 0; fw_ddb_index < MAX_DDB_ENTRIES;
-            fw_ddb_index = next_fw_ddb_index) {
-               /* First, let's see if a device exists here */
-               if (qla4xxx_get_fwddb_entry(ha, fw_ddb_index, fw_ddb_entry,
-                                           0, NULL, &next_fw_ddb_index,
-                                           &ddb_state, &conn_err,
-                                           NULL, NULL) ==
-                                           QLA_ERROR) {
-                       DEBUG2(printk("scsi%ld: %s: get_ddb_entry, "
-                                     "fw_ddb_index %d failed", ha->host_no,
-                                     __func__, fw_ddb_index));
-                       goto exit_build_ddb_list;
-               }
-
-               DEBUG2(printk("scsi%ld: %s: Getting DDB[%d] ddbstate=0x%x, "
-                             "next_fw_ddb_index=%d.\n", ha->host_no, __func__,
-                             fw_ddb_index, ddb_state, next_fw_ddb_index));
-
-               /* Issue relogin, if necessary. */
-               if (ddb_state == DDB_DS_SESSION_FAILED ||
-                   ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) {
-                       /* Try and login to device */
-                       DEBUG2(printk("scsi%ld: %s: Login to DDB[%d]\n",
-                                     ha->host_no, __func__, fw_ddb_index));
-                       ipv6_device = le16_to_cpu(fw_ddb_entry->options) &
-                                       DDB_OPT_IPV6_DEVICE;
-                       if (qla4_is_relogin_allowed(ha, conn_err) &&
-                                       ((!ipv6_device &&
-                                         *((uint32_t *)fw_ddb_entry->ip_addr))
-                                        || ipv6_device)) {
-                               qla4xxx_set_ddb_entry(ha, fw_ddb_index, 0);
-                               if (qla4xxx_get_fwddb_entry(ha, fw_ddb_index,
-                                                       NULL, 0, NULL,
-                                                       &next_fw_ddb_index,
-                                                       &ddb_state, &conn_err,
-                                                       NULL, NULL)
-                                               == QLA_ERROR) {
-                                       DEBUG2(printk("scsi%ld: %s:"
-                                               "get_ddb_entry %d failed\n",
-                                               ha->host_no,
-                                               __func__, fw_ddb_index));
-                                       goto exit_build_ddb_list;
-                               }
-                       }
-               }
-
-               if (ddb_state != DDB_DS_SESSION_ACTIVE)
-                       goto next_one;
-               /*
-                * if fw_ddb with session active state found,
-                * add to ddb_list
-                */
-               DEBUG2(printk("scsi%ld: %s: DDB[%d] added to list\n",
-                             ha->host_no, __func__, fw_ddb_index));
-
-               /* Add DDB to internal our ddb list. */
-               ddb_entry = qla4xxx_get_ddb_entry(ha, fw_ddb_index, &new_tgt);
-               if (ddb_entry == NULL) {
-                       DEBUG2(printk("scsi%ld: %s: Unable to allocate memory "
-                                     "for device at fw_ddb_index %d\n",
-                                     ha->host_no, __func__, fw_ddb_index));
-                       goto exit_build_ddb_list;
-               }
-               /* Fill in the device structure */
-               if (qla4xxx_update_ddb_entry(ha, ddb_entry, fw_ddb_index) ==
-                   QLA_ERROR) {
-                       ha->fw_ddb_index_map[fw_ddb_index] =
-                               (struct ddb_entry *)INVALID_ENTRY;
-
-                       DEBUG2(printk("scsi%ld: %s: update_ddb_entry failed "
-                                     "for fw_ddb_index %d.\n",
-                                     ha->host_no, __func__, fw_ddb_index));
-                       goto exit_build_ddb_list;
-               }
-
-next_one:
-               /* We know we've reached the last device when
-                * next_fw_ddb_index is 0 */
-               if (next_fw_ddb_index == 0)
-                       break;
-       }
-
-       status = QLA_SUCCESS;
-       ql4_printk(KERN_INFO, ha, "DDB list done..\n");
-
-exit_build_ddb_list:
-       dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry,
-               fw_ddb_entry_dma);
-
-exit_build_ddb_list_no_free:
-       return status;
-}
-
-static int qla4xxx_initialize_ddb_list(struct scsi_qla_host *ha)
-{
-       uint16_t fw_ddb_index;
-       int status = QLA_SUCCESS;
-
-       /* free the ddb list if is not empty */
-       if (!list_empty(&ha->ddb_list))
-               qla4xxx_free_ddb_list(ha);
-
-       for (fw_ddb_index = 0; fw_ddb_index < MAX_DDB_ENTRIES; fw_ddb_index++)
-               ha->fw_ddb_index_map[fw_ddb_index] =
-                   (struct ddb_entry *)INVALID_ENTRY;
-
-       ha->tot_ddbs = 0;
-
-       /* Perform device discovery and build ddb list. */
-       status = qla4xxx_build_ddb_list(ha);
-
-       return status;
-}
-
-/**
- * qla4xxx_reinitialize_ddb_list - update the driver ddb list
- * @ha: pointer to host adapter structure.
- *
- * This routine obtains device information from the F/W database after
- * firmware or adapter resets.  The device table is preserved.
- **/
-int qla4xxx_reinitialize_ddb_list(struct scsi_qla_host *ha)
-{
-       int status = QLA_SUCCESS;
-       struct ddb_entry *ddb_entry, *detemp;
-
-       /* Update the device information for all devices. */
-       list_for_each_entry_safe(ddb_entry, detemp, &ha->ddb_list, list) {
-               qla4xxx_update_ddb_entry(ha, ddb_entry,
-                                        ddb_entry->fw_ddb_index);
-               if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
-                       atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
-                       DEBUG2(printk ("scsi%ld: %s: ddb index [%d] marked "
-                                      "ONLINE\n", ha->host_no, __func__,
-                                      ddb_entry->fw_ddb_index));
-                       iscsi_unblock_session(ddb_entry->sess);
-               } else if (atomic_read(&ddb_entry->state) == DDB_STATE_ONLINE)
-                       qla4xxx_mark_device_missing(ha, ddb_entry);
-       }
-       return status;
-}
-
-/**
- * qla4xxx_relogin_device - re-establish session
- * @ha: Pointer to host adapter structure.
- * @ddb_entry: Pointer to device database entry
- *
- * This routine does a session relogin with the specified device.
- * The ddb entry must be assigned prior to making this call.
- **/
-int qla4xxx_relogin_device(struct scsi_qla_host *ha,
-                          struct ddb_entry * ddb_entry)
-{
-       uint16_t relogin_timer;
-
-       relogin_timer = max(ddb_entry->default_relogin_timeout,
-                           (uint16_t)RELOGIN_TOV);
-       atomic_set(&ddb_entry->relogin_timer, relogin_timer);
-
-       DEBUG2(printk("scsi%ld: Relogin ddb [%d]. TOV=%d\n", ha->host_no,
-                     ddb_entry->fw_ddb_index, relogin_timer));
-
-       qla4xxx_set_ddb_entry(ha, ddb_entry->fw_ddb_index, 0);
-
-       return QLA_SUCCESS;
+       memcpy(ha->model_name, board_id_string, size);
 }
 
 static int qla4xxx_config_nvram(struct scsi_qla_host *ha)
@@ -983,6 +496,12 @@ static int qla4xxx_config_nvram(struct scsi_qla_host *ha)
                else
                        return QLA_ERROR;
        }
+
+       if (is_qla4022(ha) || is_qla4032(ha))
+               qla4xxx_set_model_info(ha);
+       else
+               strcpy(ha->model_name, "QLA4010");
+
        DEBUG(printk("scsi%ld: %s: Setting extHwConfig to 0xFFFF%04x\n",
                     ha->host_no, __func__, extHwConfig.Asuint32_t));
 
@@ -1246,23 +765,56 @@ int qla4xxx_start_firmware(struct scsi_qla_host *ha)
        }
        return status;
 }
+/**
+ * qla4xxx_free_ddb_index - Free DDBs reserved by firmware
+ * @ha: pointer to adapter structure
+ *
+ * Since firmware is not running in autoconnect mode the DDB indices should
+ * be freed so that when login happens from user space there are free DDB
+ * indices available.
+ **/
+static void qla4xxx_free_ddb_index(struct scsi_qla_host *ha)
+{
+       int max_ddbs;
+       int ret;
+       uint32_t idx = 0, next_idx = 0;
+       uint32_t state = 0, conn_err = 0;
+
+       max_ddbs =  is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
+                                    MAX_DEV_DB_ENTRIES;
+
+       for (idx = 0; idx < max_ddbs; idx = next_idx) {
+               ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL,
+                                             &next_idx, &state, &conn_err,
+                                               NULL, NULL);
+               if (ret == QLA_ERROR)
+                       continue;
+               if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
+                   state == DDB_DS_SESSION_FAILED) {
+                       DEBUG2(ql4_printk(KERN_INFO, ha,
+                                         "Freeing DDB index = 0x%x\n", idx));
+                       ret = qla4xxx_clear_ddb_entry(ha, idx);
+                       if (ret == QLA_ERROR)
+                               ql4_printk(KERN_ERR, ha,
+                                          "Unable to clear DDB index = "
+                                          "0x%x\n", idx);
+               }
+               if (next_idx == 0)
+                       break;
+       }
+}
 
 
 /**
  * qla4xxx_initialize_adapter - initiailizes hba
  * @ha: Pointer to host adapter structure.
- * @renew_ddb_list: Indicates what to do with the adapter's ddb list
- *     after adapter recovery has completed.
- *     0=preserve ddb list, 1=destroy and rebuild ddb list
  *
  * This routine parforms all of the steps necessary to initialize the adapter.
  *
  **/
-int qla4xxx_initialize_adapter(struct scsi_qla_host *ha,
-                              uint8_t renew_ddb_list)
+int qla4xxx_initialize_adapter(struct scsi_qla_host *ha)
 {
        int status = QLA_ERROR;
-       int8_t ip_address[IP_ADDR_LEN] = {0} ;
 
        ha->eeprom_cmd_data = 0;
 
@@ -1288,47 +840,8 @@ int qla4xxx_initialize_adapter(struct scsi_qla_host *ha,
        if (status == QLA_ERROR)
                goto exit_init_hba;
 
-       /*
-        * FW is waiting to get an IP address from DHCP server: Skip building
-        * the ddb_list and wait for DHCP lease acquired aen to come in
-        * followed by 0x8014 aen" to trigger the tgt discovery process.
-        */
-       if (ha->firmware_state & FW_STATE_CONFIGURING_IP)
-               goto exit_init_online;
-
-       /* Skip device discovery if ip and subnet is zero */
-       if (memcmp(ha->ip_address, ip_address, IP_ADDR_LEN) == 0 ||
-           memcmp(ha->subnet_mask, ip_address, IP_ADDR_LEN) == 0)
-               goto exit_init_online;
+       qla4xxx_free_ddb_index(ha);
 
-       if (renew_ddb_list == PRESERVE_DDB_LIST) {
-               /*
-                * We want to preserve lun states (i.e. suspended, etc.)
-                * for recovery initiated by the driver.  So just update
-                * the device states for the existing ddb_list.
-                */
-               qla4xxx_reinitialize_ddb_list(ha);
-       } else if (renew_ddb_list == REBUILD_DDB_LIST) {
-               /*
-                * We want to build the ddb_list from scratch during
-                * driver initialization and recovery initiated by the
-                * INT_HBA_RESET IOCTL.
-                */
-               status = qla4xxx_initialize_ddb_list(ha);
-               if (status == QLA_ERROR) {
-                       DEBUG2(printk("%s(%ld) Error occurred during build"
-                                     "ddb list\n", __func__, ha->host_no));
-                       goto exit_init_hba;
-               }
-
-       }
-       if (!ha->tot_ddbs) {
-               DEBUG2(printk("scsi%ld: Failed to initialize devices or none "
-                             "present in Firmware device database\n",
-                             ha->host_no));
-       }
-
-exit_init_online:
        set_bit(AF_ONLINE, &ha->flags);
 exit_init_hba:
        if (is_qla8022(ha) && (status == QLA_ERROR)) {
@@ -1342,61 +855,6 @@ exit_init_hba:
        return status;
 }
 
-/**
- * qla4xxx_add_device_dynamically - ddb addition due to an AEN
- * @ha:  Pointer to host adapter structure.
- * @fw_ddb_index:  Firmware's device database index
- *
- * This routine processes adds a device as a result of an 8014h AEN.
- **/
-static void qla4xxx_add_device_dynamically(struct scsi_qla_host *ha,
-                                          uint32_t fw_ddb_index)
-{
-       struct ddb_entry * ddb_entry;
-       uint32_t new_tgt;
-
-       /* First allocate a device structure */
-       ddb_entry = qla4xxx_get_ddb_entry(ha, fw_ddb_index, &new_tgt);
-       if (ddb_entry == NULL) {
-               DEBUG2(printk(KERN_WARNING
-                             "scsi%ld: Unable to allocate memory to add "
-                             "fw_ddb_index %d\n", ha->host_no, fw_ddb_index));
-               return;
-       }
-
-       if (!new_tgt && (ddb_entry->fw_ddb_index != fw_ddb_index)) {
-               /* Target has been bound to a new fw_ddb_index */
-               qla4xxx_free_ddb(ha, ddb_entry);
-               ddb_entry = qla4xxx_alloc_ddb(ha, fw_ddb_index);
-               if (ddb_entry == NULL) {
-                       DEBUG2(printk(KERN_WARNING
-                               "scsi%ld: Unable to allocate memory"
-                               " to add fw_ddb_index %d\n",
-                               ha->host_no, fw_ddb_index));
-                       return;
-               }
-       }
-       if (qla4xxx_update_ddb_entry(ha, ddb_entry, fw_ddb_index) ==
-                                   QLA_ERROR) {
-               ha->fw_ddb_index_map[fw_ddb_index] =
-                                       (struct ddb_entry *)INVALID_ENTRY;
-               DEBUG2(printk(KERN_WARNING
-                             "scsi%ld: failed to add new device at index "
-                             "[%d]\n Unable to retrieve fw ddb entry\n",
-                             ha->host_no, fw_ddb_index));
-               qla4xxx_free_ddb(ha, ddb_entry);
-               return;
-       }
-
-       if (qla4xxx_add_sess(ddb_entry)) {
-               DEBUG2(printk(KERN_WARNING
-                             "scsi%ld: failed to add new device at index "
-                             "[%d]\n Unable to add connection and session\n",
-                             ha->host_no, fw_ddb_index));
-               qla4xxx_free_ddb(ha, ddb_entry);
-       }
-}
-
 /**
  * qla4xxx_process_ddb_changed - process ddb state change
  * @ha - Pointer to host adapter structure.
@@ -1409,88 +867,94 @@ int qla4xxx_process_ddb_changed(struct scsi_qla_host *ha, uint32_t fw_ddb_index,
                uint32_t state, uint32_t conn_err)
 {
        struct ddb_entry * ddb_entry;
+       uint32_t old_fw_ddb_device_state;
+       int status = QLA_ERROR;
 
        /* check for out of range index */
        if (fw_ddb_index >= MAX_DDB_ENTRIES)
-               return QLA_ERROR;
+               goto exit_ddb_event;
 
        /* Get the corresponging ddb entry */
        ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, fw_ddb_index);
        /* Device does not currently exist in our database. */
        if (ddb_entry == NULL) {
-               if (state == DDB_DS_SESSION_ACTIVE)
-                       qla4xxx_add_device_dynamically(ha, fw_ddb_index);
-               return QLA_SUCCESS;
+               ql4_printk(KERN_ERR, ha, "%s: No ddb_entry at FW index [%d]\n",
+                          __func__, fw_ddb_index);
+
+               if (state == DDB_DS_NO_CONNECTION_ACTIVE)
+                       clear_bit(fw_ddb_index, ha->ddb_idx_map);
+
+               goto exit_ddb_event;
        }
 
-       /* Device already exists in our database. */
-       DEBUG2(printk("scsi%ld: %s DDB - old state= 0x%x, new state=0x%x for "
-                     "index [%d]\n", ha->host_no, __func__,
-                     ddb_entry->fw_ddb_device_state, state, fw_ddb_index));
+       old_fw_ddb_device_state = ddb_entry->fw_ddb_device_state;
+       DEBUG2(ql4_printk(KERN_INFO, ha,
+                         "%s: DDB - old state = 0x%x, new state = 0x%x for "
+                         "index [%d]\n", __func__,
+                         ddb_entry->fw_ddb_device_state, state, fw_ddb_index));
 
        ddb_entry->fw_ddb_device_state = state;
-       /* Device is back online. */
-       if ((ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) &&
-          (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)) {
-               atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
-               atomic_set(&ddb_entry->relogin_retry_count, 0);
-               atomic_set(&ddb_entry->relogin_timer, 0);
-               clear_bit(DF_RELOGIN, &ddb_entry->flags);
-               iscsi_unblock_session(ddb_entry->sess);
-               iscsi_session_event(ddb_entry->sess,
-                                   ISCSI_KEVENT_CREATE_SESSION);
-               /*
-                * Change the lun state to READY in case the lun TIMEOUT before
-                * the device came back.
-                */
-       } else if (ddb_entry->fw_ddb_device_state != DDB_DS_SESSION_ACTIVE) {
-               /* Device went away, mark device missing */
-               if (atomic_read(&ddb_entry->state) == DDB_STATE_ONLINE) {
-                       DEBUG2(ql4_printk(KERN_INFO, ha, "%s mark missing "
-                                       "ddb_entry 0x%p sess 0x%p conn 0x%p\n",
-                                       __func__, ddb_entry,
-                                       ddb_entry->sess, ddb_entry->conn));
-                       qla4xxx_mark_device_missing(ha, ddb_entry);
-               }
 
-               /*
-                * Relogin if device state changed to a not active state.
-                * However, do not relogin if a RELOGIN is in process, or
-                * we are not allowed to relogin to this DDB.
-                */
-               if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_FAILED &&
-                   !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
-                   qla4_is_relogin_allowed(ha, conn_err)) {
+       switch (old_fw_ddb_device_state) {
+       case DDB_DS_LOGIN_IN_PROCESS:
+               switch (state) {
+               case DDB_DS_SESSION_ACTIVE:
+               case DDB_DS_DISCOVERY:
+                       iscsi_conn_start(ddb_entry->conn);
+                       iscsi_conn_login_event(ddb_entry->conn,
+                                              ISCSI_CONN_STATE_LOGGED_IN);
+                       qla4xxx_update_session_conn_param(ha, ddb_entry);
+                       status = QLA_SUCCESS;
+                       break;
+               case DDB_DS_SESSION_FAILED:
+               case DDB_DS_NO_CONNECTION_ACTIVE:
+                       iscsi_conn_login_event(ddb_entry->conn,
+                                              ISCSI_CONN_STATE_FREE);
+                       status = QLA_SUCCESS;
+                       break;
+               }
+               break;
+       case DDB_DS_SESSION_ACTIVE:
+               switch (state) {
+               case DDB_DS_SESSION_FAILED:
                        /*
-                        * This triggers a relogin.  After the relogin_timer
-                        * expires, the relogin gets scheduled.  We must wait a
-                        * minimum amount of time since receiving an 0x8014 AEN
-                        * with failed device_state or a logout response before
-                        * we can issue another relogin.
+                        * iscsi_session failure  will cause userspace to
+                        * stop the connection which in turn would block the
+                        * iscsi_session and start relogin
                         */
-                       /* Firmware pads this timeout: (time2wait +1).
-                        * Driver retry to login should be longer than F/W.
-                        * Otherwise F/W will fail
-                        * set_ddb() mbx cmd with 0x4005 since it still
-                        * counting down its time2wait.
-                        */
-                       atomic_set(&ddb_entry->relogin_timer, 0);
-                       atomic_set(&ddb_entry->retry_relogin_timer,
-                                  ddb_entry->default_time2wait + 4);
-                       DEBUG(printk("scsi%ld: %s: ddb[%d] "
-                           "initiate relogin after %d seconds\n",
-                           ha->host_no, __func__,
-                           ddb_entry->fw_ddb_index,
-                           ddb_entry->default_time2wait + 4));
-               } else {
-                       DEBUG(printk("scsi%ld: %s: ddb[%d] "
-                           "relogin not initiated, state = %d, "
-                           "ddb_entry->flags = 0x%lx\n",
-                           ha->host_no, __func__,
-                           ddb_entry->fw_ddb_index,
-                           ddb_entry->fw_ddb_device_state,
-                           ddb_entry->flags));
+                       iscsi_session_failure(ddb_entry->sess->dd_data,
+                                             ISCSI_ERR_CONN_FAILED);
+                       status = QLA_SUCCESS;
+                       break;
+               case DDB_DS_NO_CONNECTION_ACTIVE:
+                       clear_bit(fw_ddb_index, ha->ddb_idx_map);
+                       status = QLA_SUCCESS;
+                       break;
+               }
+               break;
+       case DDB_DS_SESSION_FAILED:
+               switch (state) {
+               case DDB_DS_SESSION_ACTIVE:
+               case DDB_DS_DISCOVERY:
+                       iscsi_conn_start(ddb_entry->conn);
+                       iscsi_conn_login_event(ddb_entry->conn,
+                                              ISCSI_CONN_STATE_LOGGED_IN);
+                       qla4xxx_update_session_conn_param(ha, ddb_entry);
+                       status = QLA_SUCCESS;
+                       break;
+               case DDB_DS_SESSION_FAILED:
+                       iscsi_session_failure(ddb_entry->sess->dd_data,
+                                             ISCSI_ERR_CONN_FAILED);
+                       status = QLA_SUCCESS;
+                       break;
                }
+               break;
+       default:
+               DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Unknown Event\n",
+                               __func__));
+               break;
        }
-       return QLA_SUCCESS;
+
+exit_ddb_event:
+       return status;
 }
index 75fcd82a8fcae40b2f56bec6d7aeacb67cbe50ee..41066935190649efc4d45427fb13b9bf87f32ad3 100644 (file)
@@ -313,10 +313,8 @@ int qla4xxx_send_command_to_isp(struct scsi_qla_host *ha, struct srb * srb)
        cmd_entry->hdr.entryType = ET_COMMAND;
        cmd_entry->handle = cpu_to_le32(index);
        cmd_entry->target = cpu_to_le16(ddb_entry->fw_ddb_index);
-       cmd_entry->connection_id = cpu_to_le16(ddb_entry->connection_id);
 
        int_to_scsilun(cmd->device->lun, &cmd_entry->lun);
-       cmd_entry->cmdSeqNum = cpu_to_le32(ddb_entry->CmdSn);
        cmd_entry->ttlByteCnt = cpu_to_le32(scsi_bufflen(cmd));
        memcpy(cmd_entry->cdb, cmd->cmnd, cmd->cmd_len);
        cmd_entry->dataSegCnt = cpu_to_le16(tot_dsds);
@@ -381,3 +379,69 @@ queuing_error:
        return QLA_ERROR;
 }
 
+int qla4xxx_send_passthru0(struct iscsi_task *task)
+{
+       struct passthru0 *passthru_iocb;
+       struct iscsi_session *sess = task->conn->session;
+       struct ddb_entry *ddb_entry = sess->dd_data;
+       struct scsi_qla_host *ha = ddb_entry->ha;
+       struct ql4_task_data *task_data = task->dd_data;
+       uint16_t ctrl_flags = 0;
+       unsigned long flags;
+       int ret = QLA_ERROR;
+
+       spin_lock_irqsave(&ha->hardware_lock, flags);
+       task_data->iocb_req_cnt = 1;
+       /* Put the IOCB on the request queue */
+       if (!qla4xxx_space_in_req_ring(ha, task_data->iocb_req_cnt))
+               goto queuing_error;
+
+       passthru_iocb = (struct passthru0 *) ha->request_ptr;
+
+       memset(passthru_iocb, 0, sizeof(struct passthru0));
+       passthru_iocb->hdr.entryType = ET_PASSTHRU0;
+       passthru_iocb->hdr.systemDefined = SD_ISCSI_PDU;
+       passthru_iocb->hdr.entryCount = task_data->iocb_req_cnt;
+       passthru_iocb->handle = task->itt;
+       passthru_iocb->target = cpu_to_le16(ddb_entry->fw_ddb_index);
+       passthru_iocb->timeout = cpu_to_le16(PT_DEFAULT_TIMEOUT);
+
+       /* Setup the out & in DSDs */
+       if (task_data->req_len) {
+               memcpy((uint8_t *)task_data->req_buffer +
+                      sizeof(struct iscsi_hdr), task->data, task->data_count);
+               ctrl_flags |= PT_FLAG_SEND_BUFFER;
+               passthru_iocb->out_dsd.base.addrLow =
+                                       cpu_to_le32(LSDW(task_data->req_dma));
+               passthru_iocb->out_dsd.base.addrHigh =
+                                       cpu_to_le32(MSDW(task_data->req_dma));
+               passthru_iocb->out_dsd.count =
+                                       cpu_to_le32(task->data_count +
+                                                   sizeof(struct iscsi_hdr));
+       }
+       if (task_data->resp_len) {
+               passthru_iocb->in_dsd.base.addrLow =
+                                       cpu_to_le32(LSDW(task_data->resp_dma));
+               passthru_iocb->in_dsd.base.addrHigh =
+                                       cpu_to_le32(MSDW(task_data->resp_dma));
+               passthru_iocb->in_dsd.count =
+                       cpu_to_le32(task_data->resp_len);
+       }
+
+       ctrl_flags |= (PT_FLAG_ISCSI_PDU | PT_FLAG_WAIT_4_RESPONSE);
+       passthru_iocb->control_flags = cpu_to_le16(ctrl_flags);
+
+       /* Update the request pointer */
+       qla4xxx_advance_req_ring_ptr(ha);
+       wmb();
+
+       /* Track IOCB used */
+       ha->iocb_cnt += task_data->iocb_req_cnt;
+       ha->req_q_count -= task_data->iocb_req_cnt;
+       ha->isp_ops->queue_iocb(ha);
+       ret = QLA_SUCCESS;
+
+queuing_error:
+       spin_unlock_irqrestore(&ha->hardware_lock, flags);
+       return ret;
+}
index 0e72921c752d497547e49e59e078aaf38d54bb36..827e93078b942bbcbc393ac8f063c8ce4ab8b183 100644 (file)
@@ -224,8 +224,8 @@ static void qla4xxx_status_entry(struct scsi_qla_host *ha,
                 * I/O to this device.  We should get a ddb state change
                 * AEN soon.
                 */
-               if (atomic_read(&ddb_entry->state) == DDB_STATE_ONLINE)
-                       qla4xxx_mark_device_missing(ha, ddb_entry);
+               if (iscsi_is_session_online(ddb_entry->sess))
+                       qla4xxx_mark_device_missing(ddb_entry->sess);
                break;
 
        case SCS_DATA_UNDERRUN:
@@ -306,8 +306,8 @@ static void qla4xxx_status_entry(struct scsi_qla_host *ha,
                 * send I/O to this device.  We should get a ddb
                 * state change AEN soon.
                 */
-               if (atomic_read(&ddb_entry->state) == DDB_STATE_ONLINE)
-                       qla4xxx_mark_device_missing(ha, ddb_entry);
+               if (iscsi_is_session_online(ddb_entry->sess))
+                       qla4xxx_mark_device_missing(ddb_entry->sess);
 
                cmd->result = DID_TRANSPORT_DISRUPTED << 16;
                break;
@@ -340,6 +340,51 @@ status_entry_exit:
                kref_put(&srb->srb_ref, qla4xxx_srb_compl);
 }
 
+/**
+ * qla4xxx_passthru_status_entry - processes passthru status IOCBs (0x3C)
+ * @ha: Pointer to host adapter structure.
+ * @sts_entry: Pointer to status entry structure.
+ **/
+static void qla4xxx_passthru_status_entry(struct scsi_qla_host *ha,
+                                         struct passthru_status *sts_entry)
+{
+       struct iscsi_task *task;
+       struct ddb_entry *ddb_entry;
+       struct ql4_task_data *task_data;
+       struct iscsi_cls_conn *cls_conn;
+       struct iscsi_conn *conn;
+       itt_t itt;
+       uint32_t fw_ddb_index;
+
+       itt = sts_entry->handle;
+       fw_ddb_index = le32_to_cpu(sts_entry->target);
+
+       ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, fw_ddb_index);
+
+       if (ddb_entry == NULL) {
+               ql4_printk(KERN_ERR, ha, "%s: Invalid target index = 0x%x\n",
+                          __func__, sts_entry->target);
+               return;
+       }
+
+       cls_conn = ddb_entry->conn;
+       conn = cls_conn->dd_data;
+       spin_lock(&conn->session->lock);
+       task = iscsi_itt_to_task(conn, itt);
+       spin_unlock(&conn->session->lock);
+
+       if (task == NULL) {
+               ql4_printk(KERN_ERR, ha, "%s: Task is NULL\n", __func__);
+               return;
+       }
+
+       task_data = task->dd_data;
+       memcpy(&task_data->sts, sts_entry, sizeof(struct passthru_status));
+       ha->req_q_count += task_data->iocb_req_cnt;
+       ha->iocb_cnt -= task_data->iocb_req_cnt;
+       queue_work(ha->task_wq, &task_data->task_work);
+}
+
 /**
  * qla4xxx_process_response_queue - process response queue completions
  * @ha: Pointer to host adapter structure.
@@ -375,6 +420,14 @@ void qla4xxx_process_response_queue(struct scsi_qla_host *ha)
                        break;
 
                case ET_PASSTHRU_STATUS:
+                       if (sts_entry->hdr.systemDefined == SD_ISCSI_PDU)
+                               qla4xxx_passthru_status_entry(ha,
+                                       (struct passthru_status *)sts_entry);
+                       else
+                               ql4_printk(KERN_ERR, ha,
+                                          "%s: Invalid status received\n",
+                                          __func__);
+
                        break;
 
                case ET_STATUS_CONTINUATION:
@@ -566,6 +619,8 @@ static void qla4xxx_isr_decode_mailbox(struct scsi_qla_host * ha,
                        else if ((mbox_sts[3] == ACB_STATE_ACQUIRING) &&
                            (mbox_sts[2] == ACB_STATE_VALID))
                                set_bit(DPC_RESET_HA, &ha->dpc_flags);
+                       else if ((mbox_sts[3] == ACB_STATE_UNCONFIGURED))
+                               complete(&ha->disable_acb_comp);
                        break;
 
                case MBOX_ASTS_MAC_ADDRESS_CHANGED:
@@ -1009,23 +1064,23 @@ void qla4xxx_process_aen(struct scsi_qla_host * ha, uint8_t process_aen)
 
                switch (mbox_sts[0]) {
                case MBOX_ASTS_DATABASE_CHANGED:
-                       if (process_aen == FLUSH_DDB_CHANGED_AENS) {
+                       switch (process_aen) {
+                       case FLUSH_DDB_CHANGED_AENS:
                                DEBUG2(printk("scsi%ld: AEN[%d] %04x, index "
                                              "[%d] state=%04x FLUSHED!\n",
                                              ha->host_no, ha->aen_out,
                                              mbox_sts[0], mbox_sts[2],
                                              mbox_sts[3]));
                                break;
+                       case PROCESS_ALL_AENS:
+                       default:
+                               /* Specific device. */
+                               if (mbox_sts[1] == 1)
+                                       qla4xxx_process_ddb_changed(ha,
+                                               mbox_sts[2], mbox_sts[3],
+                                               mbox_sts[4]);
+                               break;
                        }
-               case PROCESS_ALL_AENS:
-               default:
-                       if (mbox_sts[1] == 0) { /* Global DB change. */
-                               qla4xxx_reinitialize_ddb_list(ha);
-                       } else if (mbox_sts[1] == 1) {  /* Specific device. */
-                               qla4xxx_process_ddb_changed(ha, mbox_sts[2],
-                                               mbox_sts[3], mbox_sts[4]);
-                       }
-                       break;
                }
                spin_lock_irqsave(&ha->hardware_lock, flags);
        }
index fce8289e97525732a02857153b987f1928a2333e..4c2b84870392e16f1ed03428aa7ed9c004c9cbd9 100644 (file)
@@ -303,7 +303,7 @@ qla4xxx_set_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
        return QLA_SUCCESS;
 }
 
-static uint8_t
+uint8_t
 qla4xxx_get_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
                 uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
 {
@@ -327,43 +327,69 @@ qla4xxx_get_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
 
 static void
 qla4xxx_update_local_ip(struct scsi_qla_host *ha,
-                        struct addr_ctrl_blk  *init_fw_cb)
+                       struct addr_ctrl_blk *init_fw_cb)
 {
+       ha->ip_config.tcp_options = le16_to_cpu(init_fw_cb->ipv4_tcp_opts);
+       ha->ip_config.ipv4_options = le16_to_cpu(init_fw_cb->ipv4_ip_opts);
+       ha->ip_config.ipv4_addr_state =
+                               le16_to_cpu(init_fw_cb->ipv4_addr_state);
+       ha->ip_config.eth_mtu_size =
+                               le16_to_cpu(init_fw_cb->eth_mtu_size);
+       ha->ip_config.ipv4_port = le16_to_cpu(init_fw_cb->ipv4_port);
+
+       if (ha->acb_version == ACB_SUPPORTED) {
+               ha->ip_config.ipv6_options = le16_to_cpu(init_fw_cb->ipv6_opts);
+               ha->ip_config.ipv6_addl_options =
+                               le16_to_cpu(init_fw_cb->ipv6_addtl_opts);
+       }
+
        /* Save IPv4 Address Info */
-       memcpy(ha->ip_address, init_fw_cb->ipv4_addr,
-               min(sizeof(ha->ip_address), sizeof(init_fw_cb->ipv4_addr)));
-       memcpy(ha->subnet_mask, init_fw_cb->ipv4_subnet,
-               min(sizeof(ha->subnet_mask), sizeof(init_fw_cb->ipv4_subnet)));
-       memcpy(ha->gateway, init_fw_cb->ipv4_gw_addr,
-               min(sizeof(ha->gateway), sizeof(init_fw_cb->ipv4_gw_addr)));
+       memcpy(ha->ip_config.ip_address, init_fw_cb->ipv4_addr,
+              min(sizeof(ha->ip_config.ip_address),
+                  sizeof(init_fw_cb->ipv4_addr)));
+       memcpy(ha->ip_config.subnet_mask, init_fw_cb->ipv4_subnet,
+              min(sizeof(ha->ip_config.subnet_mask),
+                  sizeof(init_fw_cb->ipv4_subnet)));
+       memcpy(ha->ip_config.gateway, init_fw_cb->ipv4_gw_addr,
+              min(sizeof(ha->ip_config.gateway),
+                  sizeof(init_fw_cb->ipv4_gw_addr)));
+
+       ha->ip_config.ipv4_vlan_tag = be16_to_cpu(init_fw_cb->ipv4_vlan_tag);
 
        if (is_ipv6_enabled(ha)) {
                /* Save IPv6 Address */
-               ha->ipv6_link_local_state = init_fw_cb->ipv6_lnk_lcl_addr_state;
-               ha->ipv6_addr0_state = init_fw_cb->ipv6_addr0_state;
-               ha->ipv6_addr1_state = init_fw_cb->ipv6_addr1_state;
-               ha->ipv6_default_router_state = init_fw_cb->ipv6_dflt_rtr_state;
-               ha->ipv6_link_local_addr.in6_u.u6_addr8[0] = 0xFE;
-               ha->ipv6_link_local_addr.in6_u.u6_addr8[1] = 0x80;
-
-               memcpy(&ha->ipv6_link_local_addr.in6_u.u6_addr8[8],
-                       init_fw_cb->ipv6_if_id,
-                       min(sizeof(ha->ipv6_link_local_addr)/2,
-                       sizeof(init_fw_cb->ipv6_if_id)));
-               memcpy(&ha->ipv6_addr0, init_fw_cb->ipv6_addr0,
-                       min(sizeof(ha->ipv6_addr0),
-                       sizeof(init_fw_cb->ipv6_addr0)));
-               memcpy(&ha->ipv6_addr1, init_fw_cb->ipv6_addr1,
-                       min(sizeof(ha->ipv6_addr1),
-                       sizeof(init_fw_cb->ipv6_addr1)));
-               memcpy(&ha->ipv6_default_router_addr,
-                       init_fw_cb->ipv6_dflt_rtr_addr,
-                       min(sizeof(ha->ipv6_default_router_addr),
-                       sizeof(init_fw_cb->ipv6_dflt_rtr_addr)));
+               ha->ip_config.ipv6_link_local_state =
+                       le16_to_cpu(init_fw_cb->ipv6_lnk_lcl_addr_state);
+               ha->ip_config.ipv6_addr0_state =
+                               le16_to_cpu(init_fw_cb->ipv6_addr0_state);
+               ha->ip_config.ipv6_addr1_state =
+                               le16_to_cpu(init_fw_cb->ipv6_addr1_state);
+               ha->ip_config.ipv6_default_router_state =
+                               le16_to_cpu(init_fw_cb->ipv6_dflt_rtr_state);
+               ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[0] = 0xFE;
+               ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[1] = 0x80;
+
+               memcpy(&ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[8],
+                      init_fw_cb->ipv6_if_id,
+                      min(sizeof(ha->ip_config.ipv6_link_local_addr)/2,
+                          sizeof(init_fw_cb->ipv6_if_id)));
+               memcpy(&ha->ip_config.ipv6_addr0, init_fw_cb->ipv6_addr0,
+                      min(sizeof(ha->ip_config.ipv6_addr0),
+                          sizeof(init_fw_cb->ipv6_addr0)));
+               memcpy(&ha->ip_config.ipv6_addr1, init_fw_cb->ipv6_addr1,
+                      min(sizeof(ha->ip_config.ipv6_addr1),
+                          sizeof(init_fw_cb->ipv6_addr1)));
+               memcpy(&ha->ip_config.ipv6_default_router_addr,
+                      init_fw_cb->ipv6_dflt_rtr_addr,
+                      min(sizeof(ha->ip_config.ipv6_default_router_addr),
+                          sizeof(init_fw_cb->ipv6_dflt_rtr_addr)));
+               ha->ip_config.ipv6_vlan_tag =
+                               be16_to_cpu(init_fw_cb->ipv6_vlan_tag);
+               ha->ip_config.ipv6_port = le16_to_cpu(init_fw_cb->ipv6_port);
        }
 }
 
-static uint8_t
+uint8_t
 qla4xxx_update_local_ifcb(struct scsi_qla_host *ha,
                          uint32_t *mbox_cmd,
                          uint32_t *mbox_sts,
@@ -383,9 +409,6 @@ qla4xxx_update_local_ifcb(struct scsi_qla_host *ha,
        /* Save some info in adapter structure. */
        ha->acb_version = init_fw_cb->acb_version;
        ha->firmware_options = le16_to_cpu(init_fw_cb->fw_options);
-       ha->tcp_options = le16_to_cpu(init_fw_cb->ipv4_tcp_opts);
-       ha->ipv4_options = le16_to_cpu(init_fw_cb->ipv4_ip_opts);
-       ha->ipv4_addr_state = le16_to_cpu(init_fw_cb->ipv4_addr_state);
        ha->heartbeat_interval = init_fw_cb->hb_interval;
        memcpy(ha->name_string, init_fw_cb->iscsi_name,
                min(sizeof(ha->name_string),
@@ -393,10 +416,6 @@ qla4xxx_update_local_ifcb(struct scsi_qla_host *ha,
        /*memcpy(ha->alias, init_fw_cb->Alias,
               min(sizeof(ha->alias), sizeof(init_fw_cb->Alias)));*/
 
-       if (ha->acb_version == ACB_SUPPORTED) {
-               ha->ipv6_options = init_fw_cb->ipv6_opts;
-               ha->ipv6_addl_options = init_fw_cb->ipv6_addtl_opts;
-       }
        qla4xxx_update_local_ip(ha, init_fw_cb);
 
        return QLA_SUCCESS;
@@ -462,10 +481,11 @@ int qla4xxx_initialize_fw_cb(struct scsi_qla_host * ha)
 
        init_fw_cb->fw_options &= __constant_cpu_to_le16(~FWOPT_TARGET_MODE);
 
-       /* Set bit for "serialize task mgmt" all other bits need to be zero */
        init_fw_cb->add_fw_options = 0;
        init_fw_cb->add_fw_options |=
-           __constant_cpu_to_le16(SERIALIZE_TASK_MGMT);
+                       __constant_cpu_to_le16(ADFWOPT_SERIALIZE_TASK_MGMT);
+       init_fw_cb->add_fw_options |=
+                       __constant_cpu_to_le16(ADFWOPT_AUTOCONN_DISABLE);
 
        if (qla4xxx_set_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)
                != QLA_SUCCESS) {
@@ -691,19 +711,38 @@ exit_get_fwddb:
        return status;
 }
 
+int qla4xxx_conn_open(struct scsi_qla_host *ha, uint16_t fw_ddb_index)
+{
+       uint32_t mbox_cmd[MBOX_REG_COUNT];
+       uint32_t mbox_sts[MBOX_REG_COUNT];
+       int status;
+
+       memset(&mbox_cmd, 0, sizeof(mbox_cmd));
+       memset(&mbox_sts, 0, sizeof(mbox_sts));
+
+       mbox_cmd[0] = MBOX_CMD_CONN_OPEN;
+       mbox_cmd[1] = fw_ddb_index;
+
+       status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0],
+                                        &mbox_sts[0]);
+       DEBUG2(ql4_printk(KERN_INFO, ha,
+                         "%s: status = %d mbx0 = 0x%x mbx1 = 0x%x\n",
+                         __func__, status, mbox_sts[0], mbox_sts[1]));
+       return status;
+}
+
 /**
  * qla4xxx_set_fwddb_entry - sets a ddb entry.
  * @ha: Pointer to host adapter structure.
  * @fw_ddb_index: Firmware's device database index
- * @fw_ddb_entry: Pointer to firmware's ddb entry structure, or NULL.
+ * @fw_ddb_entry_dma: dma address of ddb entry
+ * @mbx_sts: mailbox 0 to be returned or NULL
  *
  * This routine initializes or updates the adapter's device database
- * entry for the specified device. It also triggers a login for the
- * specified device. Therefore, it may also be used as a secondary
- * login routine when a NULL pointer is specified for the fw_ddb_entry.
+ * entry for the specified device.
  **/
 int qla4xxx_set_ddb_entry(struct scsi_qla_host * ha, uint16_t fw_ddb_index,
-                         dma_addr_t fw_ddb_entry_dma)
+                         dma_addr_t fw_ddb_entry_dma, uint32_t *mbx_sts)
 {
        uint32_t mbox_cmd[MBOX_REG_COUNT];
        uint32_t mbox_sts[MBOX_REG_COUNT];
@@ -722,13 +761,41 @@ int qla4xxx_set_ddb_entry(struct scsi_qla_host * ha, uint16_t fw_ddb_index,
        mbox_cmd[4] = sizeof(struct dev_db_entry);
 
        status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0],
-           &mbox_sts[0]);
+                                        &mbox_sts[0]);
+       if (mbx_sts)
+               *mbx_sts = mbox_sts[0];
        DEBUG2(printk("scsi%ld: %s: status=%d mbx0=0x%x mbx4=0x%x\n",
            ha->host_no, __func__, status, mbox_sts[0], mbox_sts[4]);)
 
        return status;
 }
 
+int qla4xxx_session_logout_ddb(struct scsi_qla_host *ha,
+                              struct ddb_entry *ddb_entry, int options)
+{
+       int status;
+       uint32_t mbox_cmd[MBOX_REG_COUNT];
+       uint32_t mbox_sts[MBOX_REG_COUNT];
+
+       memset(&mbox_cmd, 0, sizeof(mbox_cmd));
+       memset(&mbox_sts, 0, sizeof(mbox_sts));
+
+       mbox_cmd[0] = MBOX_CMD_CONN_CLOSE_SESS_LOGOUT;
+       mbox_cmd[1] = ddb_entry->fw_ddb_index;
+       mbox_cmd[3] = options;
+
+       status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0],
+                                        &mbox_sts[0]);
+       if (status != QLA_SUCCESS) {
+               DEBUG2(ql4_printk(KERN_INFO, ha,
+                                 "%s: MBOX_CMD_CONN_CLOSE_SESS_LOGOUT "
+                                 "failed sts %04X %04X", __func__,
+                                 mbox_sts[0], mbox_sts[1]));
+       }
+
+       return status;
+}
+
 /**
  * qla4xxx_get_crash_record - retrieves crash record.
  * @ha: Pointer to host adapter structure.
@@ -805,7 +872,6 @@ void qla4xxx_get_conn_event_log(struct scsi_qla_host * ha)
        uint32_t        max_event_log_entries;
        uint8_t         i;
 
-
        memset(&mbox_cmd, 0, sizeof(mbox_cmd));
        memset(&mbox_sts, 0, sizeof(mbox_cmd));
 
@@ -1104,7 +1170,7 @@ exit_about_fw:
        return status;
 }
 
-static int qla4xxx_get_default_ddb(struct scsi_qla_host *ha,
+static int qla4xxx_get_default_ddb(struct scsi_qla_host *ha, uint32_t options,
                                   dma_addr_t dma_addr)
 {
        uint32_t mbox_cmd[MBOX_REG_COUNT];
@@ -1114,6 +1180,7 @@ static int qla4xxx_get_default_ddb(struct scsi_qla_host *ha,
        memset(&mbox_sts, 0, sizeof(mbox_sts));
 
        mbox_cmd[0] = MBOX_CMD_GET_DATABASE_ENTRY_DEFAULTS;
+       mbox_cmd[1] = options;
        mbox_cmd[2] = LSDW(dma_addr);
        mbox_cmd[3] = MSDW(dma_addr);
 
@@ -1126,8 +1193,10 @@ static int qla4xxx_get_default_ddb(struct scsi_qla_host *ha,
        return QLA_SUCCESS;
 }
 
-static int qla4xxx_req_ddb_entry(struct scsi_qla_host *ha, uint32_t *ddb_index)
+int qla4xxx_req_ddb_entry(struct scsi_qla_host *ha, uint32_t ddb_index,
+                         uint32_t *mbx_sts)
 {
+       int status;
        uint32_t mbox_cmd[MBOX_REG_COUNT];
        uint32_t mbox_sts[MBOX_REG_COUNT];
 
@@ -1135,75 +1204,646 @@ static int qla4xxx_req_ddb_entry(struct scsi_qla_host *ha, uint32_t *ddb_index)
        memset(&mbox_sts, 0, sizeof(mbox_sts));
 
        mbox_cmd[0] = MBOX_CMD_REQUEST_DATABASE_ENTRY;
-       mbox_cmd[1] = MAX_PRST_DEV_DB_ENTRIES;
+       mbox_cmd[1] = ddb_index;
 
-       if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0], &mbox_sts[0]) !=
-           QLA_SUCCESS) {
-               if (mbox_sts[0] == MBOX_STS_COMMAND_ERROR) {
-                       *ddb_index = mbox_sts[2];
+       status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
+                                        &mbox_sts[0]);
+       if (status != QLA_SUCCESS) {
+               DEBUG2(ql4_printk(KERN_ERR, ha, "%s: failed status %04X\n",
+                                  __func__, mbox_sts[0]));
+       }
+
+       *mbx_sts = mbox_sts[0];
+       return status;
+}
+
+int qla4xxx_clear_ddb_entry(struct scsi_qla_host *ha, uint32_t ddb_index)
+{
+       int status;
+       uint32_t mbox_cmd[MBOX_REG_COUNT];
+       uint32_t mbox_sts[MBOX_REG_COUNT];
+
+       memset(&mbox_cmd, 0, sizeof(mbox_cmd));
+       memset(&mbox_sts, 0, sizeof(mbox_sts));
+
+       mbox_cmd[0] = MBOX_CMD_CLEAR_DATABASE_ENTRY;
+       mbox_cmd[1] = ddb_index;
+
+       status = qla4xxx_mailbox_command(ha, 2, 1, &mbox_cmd[0],
+                                        &mbox_sts[0]);
+       if (status != QLA_SUCCESS) {
+               DEBUG2(ql4_printk(KERN_ERR, ha, "%s: failed status %04X\n",
+                                  __func__, mbox_sts[0]));
+       }
+
+       return status;
+}
+
+int qla4xxx_set_flash(struct scsi_qla_host *ha, dma_addr_t dma_addr,
+                     uint32_t offset, uint32_t length, uint32_t options)
+{
+       uint32_t mbox_cmd[MBOX_REG_COUNT];
+       uint32_t mbox_sts[MBOX_REG_COUNT];
+       int status = QLA_SUCCESS;
+
+       memset(&mbox_cmd, 0, sizeof(mbox_cmd));
+       memset(&mbox_sts, 0, sizeof(mbox_sts));
+
+       mbox_cmd[0] = MBOX_CMD_WRITE_FLASH;
+       mbox_cmd[1] = LSDW(dma_addr);
+       mbox_cmd[2] = MSDW(dma_addr);
+       mbox_cmd[3] = offset;
+       mbox_cmd[4] = length;
+       mbox_cmd[5] = options;
+
+       status = qla4xxx_mailbox_command(ha, 6, 2, &mbox_cmd[0], &mbox_sts[0]);
+       if (status != QLA_SUCCESS) {
+               DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_WRITE_FLASH "
+                                 "failed w/ status %04X, mbx1 %04X\n",
+                                 __func__, mbox_sts[0], mbox_sts[1]));
+       }
+       return status;
+}
+
+int qla4xxx_bootdb_by_index(struct scsi_qla_host *ha,
+                           struct dev_db_entry *fw_ddb_entry,
+                           dma_addr_t fw_ddb_entry_dma, uint16_t ddb_index)
+{
+       uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
+       uint32_t dev_db_end_offset;
+       int status = QLA_ERROR;
+
+       memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
+
+       dev_db_start_offset += (ddb_index * sizeof(*fw_ddb_entry));
+       dev_db_end_offset = FLASH_OFFSET_DB_END;
+
+       if (dev_db_start_offset > dev_db_end_offset) {
+               DEBUG2(ql4_printk(KERN_ERR, ha,
+                                 "%s:Invalid DDB index %d", __func__,
+                                 ddb_index));
+               goto exit_bootdb_failed;
+       }
+
+       if (qla4xxx_get_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
+                             sizeof(*fw_ddb_entry)) != QLA_SUCCESS) {
+               ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
+                          "failed\n", ha->host_no, __func__);
+               goto exit_bootdb_failed;
+       }
+
+       if (fw_ddb_entry->cookie == DDB_VALID_COOKIE)
+               status = QLA_SUCCESS;
+
+exit_bootdb_failed:
+       return status;
+}
+
+int qla4xxx_get_chap(struct scsi_qla_host *ha, char *username, char *password,
+                    uint16_t idx)
+{
+       int ret = 0;
+       int rval = QLA_ERROR;
+       uint32_t offset = 0, chap_size;
+       struct ql4_chap_table *chap_table;
+       dma_addr_t chap_dma;
+
+       chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
+       if (chap_table == NULL) {
+               ret = -ENOMEM;
+               goto exit_get_chap;
+       }
+
+       chap_size = sizeof(struct ql4_chap_table);
+       memset(chap_table, 0, chap_size);
+
+       if (is_qla40XX(ha))
+               offset = FLASH_CHAP_OFFSET | (idx * chap_size);
+       else {
+               offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
+               /* flt_chap_size is CHAP table size for both ports
+                * so divide it by 2 to calculate the offset for second port
+                */
+               if (ha->port_num == 1)
+                       offset += (ha->hw.flt_chap_size / 2);
+               offset += (idx * chap_size);
+       }
+
+       rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
+       if (rval != QLA_SUCCESS) {
+               ret = -EINVAL;
+               goto exit_get_chap;
+       }
+
+       DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
+               __le16_to_cpu(chap_table->cookie)));
+
+       if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
+               ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
+               goto exit_get_chap;
+       }
+
+       strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
+       strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
+       chap_table->cookie = __constant_cpu_to_le16(CHAP_VALID_COOKIE);
+
+exit_get_chap:
+       dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
+       return ret;
+}
+
+static int qla4xxx_set_chap(struct scsi_qla_host *ha, char *username,
+                           char *password, uint16_t idx, int bidi)
+{
+       int ret = 0;
+       int rval = QLA_ERROR;
+       uint32_t offset = 0;
+       struct ql4_chap_table *chap_table;
+       dma_addr_t chap_dma;
+
+       chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
+       if (chap_table == NULL) {
+               ret =  -ENOMEM;
+               goto exit_set_chap;
+       }
+
+       memset(chap_table, 0, sizeof(struct ql4_chap_table));
+       if (bidi)
+               chap_table->flags |= BIT_6; /* peer */
+       else
+               chap_table->flags |= BIT_7; /* local */
+       chap_table->secret_len = strlen(password);
+       strncpy(chap_table->secret, password, MAX_CHAP_SECRET_LEN);
+       strncpy(chap_table->name, username, MAX_CHAP_NAME_LEN);
+       chap_table->cookie = __constant_cpu_to_le16(CHAP_VALID_COOKIE);
+       offset = FLASH_CHAP_OFFSET | (idx * sizeof(struct ql4_chap_table));
+       rval = qla4xxx_set_flash(ha, chap_dma, offset,
+                               sizeof(struct ql4_chap_table),
+                               FLASH_OPT_RMW_COMMIT);
+
+       if (rval == QLA_SUCCESS && ha->chap_list) {
+               /* Update ha chap_list cache */
+               memcpy((struct ql4_chap_table *)ha->chap_list + idx,
+                      chap_table, sizeof(struct ql4_chap_table));
+       }
+       dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
+       if (rval != QLA_SUCCESS)
+               ret =  -EINVAL;
+
+exit_set_chap:
+       return ret;
+}
+
+/**
+ * qla4xxx_get_chap_index - Get chap index given username and secret
+ * @ha: pointer to adapter structure
+ * @username: CHAP username to be searched
+ * @password: CHAP password to be searched
+ * @bidi: Is this a BIDI CHAP
+ * @chap_index: CHAP index to be returned
+ *
+ * Match the username and password in the chap_list, return the index if a
+ * match is found. If a match is not found then add the entry in FLASH and
+ * return the index at which entry is written in the FLASH.
+ **/
+static int qla4xxx_get_chap_index(struct scsi_qla_host *ha, char *username,
+                           char *password, int bidi, uint16_t *chap_index)
+{
+       int i, rval;
+       int free_index = -1;
+       int found_index = 0;
+       int max_chap_entries = 0;
+       struct ql4_chap_table *chap_table;
+
+       if (is_qla8022(ha))
+               max_chap_entries = (ha->hw.flt_chap_size / 2) /
+                                               sizeof(struct ql4_chap_table);
+       else
+               max_chap_entries = MAX_CHAP_ENTRIES_40XX;
+
+       if (!ha->chap_list) {
+               ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
+               return QLA_ERROR;
+       }
+
+       mutex_lock(&ha->chap_sem);
+       for (i = 0; i < max_chap_entries; i++) {
+               chap_table = (struct ql4_chap_table *)ha->chap_list + i;
+               if (chap_table->cookie !=
+                   __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
+                       if (i > MAX_RESRV_CHAP_IDX && free_index == -1)
+                               free_index = i;
+                       continue;
+               }
+               if (bidi) {
+                       if (chap_table->flags & BIT_7)
+                               continue;
                } else {
-                       DEBUG2(printk("scsi%ld: %s: failed status %04X\n",
-                            ha->host_no, __func__, mbox_sts[0]));
-                       return QLA_ERROR;
+                       if (chap_table->flags & BIT_6)
+                               continue;
+               }
+               if (!strncmp(chap_table->secret, password,
+                            MAX_CHAP_SECRET_LEN) &&
+                   !strncmp(chap_table->name, username,
+                            MAX_CHAP_NAME_LEN)) {
+                       *chap_index = i;
+                       found_index = 1;
+                       break;
                }
-       } else {
-               *ddb_index = MAX_PRST_DEV_DB_ENTRIES;
        }
 
-       return QLA_SUCCESS;
+       /* If chap entry is not present and a free index is available then
+        * write the entry in flash
+        */
+       if (!found_index && free_index != -1) {
+               rval = qla4xxx_set_chap(ha, username, password,
+                                       free_index, bidi);
+               if (!rval) {
+                       *chap_index = free_index;
+                       found_index = 1;
+               }
+       }
+
+       mutex_unlock(&ha->chap_sem);
+
+       if (found_index)
+               return QLA_SUCCESS;
+       return QLA_ERROR;
 }
 
+int qla4xxx_conn_close_sess_logout(struct scsi_qla_host *ha,
+                                  uint16_t fw_ddb_index,
+                                  uint16_t connection_id,
+                                  uint16_t option)
+{
+       uint32_t mbox_cmd[MBOX_REG_COUNT];
+       uint32_t mbox_sts[MBOX_REG_COUNT];
+       int status = QLA_SUCCESS;
+
+       memset(&mbox_cmd, 0, sizeof(mbox_cmd));
+       memset(&mbox_sts, 0, sizeof(mbox_sts));
+
+       mbox_cmd[0] = MBOX_CMD_CONN_CLOSE_SESS_LOGOUT;
+       mbox_cmd[1] = fw_ddb_index;
+       mbox_cmd[2] = connection_id;
+       mbox_cmd[3] = option;
 
-int qla4xxx_send_tgts(struct scsi_qla_host *ha, char *ip, uint16_t port)
+       status = qla4xxx_mailbox_command(ha, 4, 2, &mbox_cmd[0], &mbox_sts[0]);
+       if (status != QLA_SUCCESS) {
+               DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_CONN_CLOSE "
+                                 "option %04x failed w/ status %04X %04X\n",
+                                 __func__, option, mbox_sts[0], mbox_sts[1]));
+       }
+       return status;
+}
+
+int qla4xxx_disable_acb(struct scsi_qla_host *ha)
 {
-       struct dev_db_entry *fw_ddb_entry;
-       dma_addr_t fw_ddb_entry_dma;
-       uint32_t ddb_index;
-       int ret_val = QLA_SUCCESS;
+       uint32_t mbox_cmd[MBOX_REG_COUNT];
+       uint32_t mbox_sts[MBOX_REG_COUNT];
+       int status = QLA_SUCCESS;
+
+       memset(&mbox_cmd, 0, sizeof(mbox_cmd));
+       memset(&mbox_sts, 0, sizeof(mbox_sts));
+
+       mbox_cmd[0] = MBOX_CMD_DISABLE_ACB;
 
+       status = qla4xxx_mailbox_command(ha, 8, 5, &mbox_cmd[0], &mbox_sts[0]);
+       if (status != QLA_SUCCESS) {
+               DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_DISABLE_ACB "
+                                 "failed w/ status %04X %04X %04X", __func__,
+                                 mbox_sts[0], mbox_sts[1], mbox_sts[2]));
+       }
+       return status;
+}
+
+int qla4xxx_get_acb(struct scsi_qla_host *ha, dma_addr_t acb_dma,
+                   uint32_t acb_type, uint32_t len)
+{
+       uint32_t mbox_cmd[MBOX_REG_COUNT];
+       uint32_t mbox_sts[MBOX_REG_COUNT];
+       int status = QLA_SUCCESS;
 
-       fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
-                                         sizeof(*fw_ddb_entry),
+       memset(&mbox_cmd, 0, sizeof(mbox_cmd));
+       memset(&mbox_sts, 0, sizeof(mbox_sts));
+
+       mbox_cmd[0] = MBOX_CMD_GET_ACB;
+       mbox_cmd[1] = acb_type;
+       mbox_cmd[2] = LSDW(acb_dma);
+       mbox_cmd[3] = MSDW(acb_dma);
+       mbox_cmd[4] = len;
+
+       status = qla4xxx_mailbox_command(ha, 5, 5, &mbox_cmd[0], &mbox_sts[0]);
+       if (status != QLA_SUCCESS) {
+               DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_GET_ACB "
+                                 "failed w/ status %04X\n", __func__,
+                                 mbox_sts[0]));
+       }
+       return status;
+}
+
+int qla4xxx_set_acb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
+                   uint32_t *mbox_sts, dma_addr_t acb_dma)
+{
+       int status = QLA_SUCCESS;
+
+       memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
+       memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
+       mbox_cmd[0] = MBOX_CMD_SET_ACB;
+       mbox_cmd[1] = 0; /* Primary ACB */
+       mbox_cmd[2] = LSDW(acb_dma);
+       mbox_cmd[3] = MSDW(acb_dma);
+       mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
+
+       status = qla4xxx_mailbox_command(ha, 5, 5, &mbox_cmd[0], &mbox_sts[0]);
+       if (status != QLA_SUCCESS) {
+               DEBUG2(ql4_printk(KERN_WARNING, ha,  "%s: MBOX_CMD_SET_ACB "
+                                 "failed w/ status %04X\n", __func__,
+                                 mbox_sts[0]));
+       }
+       return status;
+}
+
+int qla4xxx_set_param_ddbentry(struct scsi_qla_host *ha,
+                              struct ddb_entry *ddb_entry,
+                              struct iscsi_cls_conn *cls_conn,
+                              uint32_t *mbx_sts)
+{
+       struct dev_db_entry *fw_ddb_entry;
+       struct iscsi_conn *conn;
+       struct iscsi_session *sess;
+       struct qla_conn *qla_conn;
+       struct sockaddr *dst_addr;
+       dma_addr_t fw_ddb_entry_dma;
+       int status = QLA_SUCCESS;
+       int rval = 0;
+       struct sockaddr_in *addr;
+       struct sockaddr_in6 *addr6;
+       char *ip;
+       uint16_t iscsi_opts = 0;
+       uint32_t options = 0;
+       uint16_t idx;
+
+       fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
                                          &fw_ddb_entry_dma, GFP_KERNEL);
        if (!fw_ddb_entry) {
-               DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n",
-                             ha->host_no, __func__));
-               ret_val = QLA_ERROR;
-               goto exit_send_tgts_no_free;
+               DEBUG2(ql4_printk(KERN_ERR, ha,
+                                 "%s: Unable to allocate dma buffer.\n",
+                                 __func__));
+               rval = -ENOMEM;
+               goto exit_set_param_no_free;
        }
 
-       ret_val = qla4xxx_get_default_ddb(ha, fw_ddb_entry_dma);
-       if (ret_val != QLA_SUCCESS)
-               goto exit_send_tgts;
+       conn = cls_conn->dd_data;
+       qla_conn = conn->dd_data;
+       sess = conn->session;
+       dst_addr = &qla_conn->qla_ep->dst_addr;
 
-       ret_val = qla4xxx_req_ddb_entry(ha, &ddb_index);
-       if (ret_val != QLA_SUCCESS)
-               goto exit_send_tgts;
+       if (dst_addr->sa_family == AF_INET6)
+               options |= IPV6_DEFAULT_DDB_ENTRY;
 
-       memset(fw_ddb_entry->iscsi_alias, 0,
-              sizeof(fw_ddb_entry->iscsi_alias));
+       status = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
+       if (status == QLA_ERROR) {
+               rval = -EINVAL;
+               goto exit_set_param;
+       }
 
-       memset(fw_ddb_entry->iscsi_name, 0,
-              sizeof(fw_ddb_entry->iscsi_name));
+       iscsi_opts = le16_to_cpu(fw_ddb_entry->iscsi_options);
+       memset(fw_ddb_entry->iscsi_alias, 0, sizeof(fw_ddb_entry->iscsi_alias));
+
+       memset(fw_ddb_entry->iscsi_name, 0, sizeof(fw_ddb_entry->iscsi_name));
+
+       if (sess->targetname != NULL) {
+               memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
+                      min(strlen(sess->targetname),
+                      sizeof(fw_ddb_entry->iscsi_name)));
+       }
 
        memset(fw_ddb_entry->ip_addr, 0, sizeof(fw_ddb_entry->ip_addr));
-       memset(fw_ddb_entry->tgt_addr, 0,
-              sizeof(fw_ddb_entry->tgt_addr));
+       memset(fw_ddb_entry->tgt_addr, 0, sizeof(fw_ddb_entry->tgt_addr));
+
+       fw_ddb_entry->options =  DDB_OPT_TARGET | DDB_OPT_AUTO_SENDTGTS_DISABLE;
+
+       if (dst_addr->sa_family == AF_INET) {
+               addr = (struct sockaddr_in *)dst_addr;
+               ip = (char *)&addr->sin_addr;
+               memcpy(fw_ddb_entry->ip_addr, ip, IP_ADDR_LEN);
+               fw_ddb_entry->port = cpu_to_le16(ntohs(addr->sin_port));
+               DEBUG2(ql4_printk(KERN_INFO, ha,
+                                 "%s: Destination Address [%pI4]: index [%d]\n",
+                                  __func__, fw_ddb_entry->ip_addr,
+                                 ddb_entry->fw_ddb_index));
+       } else if (dst_addr->sa_family == AF_INET6) {
+               addr6 = (struct sockaddr_in6 *)dst_addr;
+               ip = (char *)&addr6->sin6_addr;
+               memcpy(fw_ddb_entry->ip_addr, ip, IPv6_ADDR_LEN);
+               fw_ddb_entry->port = cpu_to_le16(ntohs(addr6->sin6_port));
+               fw_ddb_entry->options |= DDB_OPT_IPV6_DEVICE;
+               DEBUG2(ql4_printk(KERN_INFO, ha,
+                                 "%s: Destination Address [%pI6]: index [%d]\n",
+                                  __func__, fw_ddb_entry->ip_addr,
+                                 ddb_entry->fw_ddb_index));
+       } else {
+               ql4_printk(KERN_ERR, ha,
+                          "%s: Failed to get IP Address\n",
+                          __func__);
+               rval = -EINVAL;
+               goto exit_set_param;
+       }
+
+       /* CHAP */
+       if (sess->username != NULL && sess->password != NULL) {
+               if (strlen(sess->username) && strlen(sess->password)) {
+                       iscsi_opts |= BIT_7;
+
+                       rval = qla4xxx_get_chap_index(ha, sess->username,
+                                               sess->password,
+                                               LOCAL_CHAP, &idx);
+                       if (rval)
+                               goto exit_set_param;
+
+                       fw_ddb_entry->chap_tbl_idx = cpu_to_le16(idx);
+               }
+       }
+
+       if (sess->username_in != NULL && sess->password_in != NULL) {
+               /* Check if BIDI CHAP */
+               if (strlen(sess->username_in) && strlen(sess->password_in)) {
+                       iscsi_opts |= BIT_4;
+
+                       rval = qla4xxx_get_chap_index(ha, sess->username_in,
+                                                     sess->password_in,
+                                                     BIDI_CHAP, &idx);
+                       if (rval)
+                               goto exit_set_param;
+               }
+       }
+
+       if (sess->initial_r2t_en)
+               iscsi_opts |= BIT_10;
+
+       if (sess->imm_data_en)
+               iscsi_opts |= BIT_11;
+
+       fw_ddb_entry->iscsi_options = cpu_to_le16(iscsi_opts);
+
+       if (conn->max_recv_dlength)
+               fw_ddb_entry->iscsi_max_rcv_data_seg_len =
+                 __constant_cpu_to_le16((conn->max_recv_dlength / BYTE_UNITS));
 
-       fw_ddb_entry->options = (DDB_OPT_DISC_SESSION | DDB_OPT_TARGET);
-       fw_ddb_entry->port = cpu_to_le16(ntohs(port));
+       if (sess->max_r2t)
+               fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t);
 
-       fw_ddb_entry->ip_addr[0] = *ip;
-       fw_ddb_entry->ip_addr[1] = *(ip + 1);
-       fw_ddb_entry->ip_addr[2] = *(ip + 2);
-       fw_ddb_entry->ip_addr[3] = *(ip + 3);
+       if (sess->first_burst)
+               fw_ddb_entry->iscsi_first_burst_len =
+                      __constant_cpu_to_le16((sess->first_burst / BYTE_UNITS));
 
-       ret_val = qla4xxx_set_ddb_entry(ha, ddb_index, fw_ddb_entry_dma);
+       if (sess->max_burst)
+               fw_ddb_entry->iscsi_max_burst_len =
+                       __constant_cpu_to_le16((sess->max_burst / BYTE_UNITS));
 
-exit_send_tgts:
+       if (sess->time2wait)
+               fw_ddb_entry->iscsi_def_time2wait =
+                       cpu_to_le16(sess->time2wait);
+
+       if (sess->time2retain)
+               fw_ddb_entry->iscsi_def_time2retain =
+                       cpu_to_le16(sess->time2retain);
+
+       status = qla4xxx_set_ddb_entry(ha, ddb_entry->fw_ddb_index,
+                                      fw_ddb_entry_dma, mbx_sts);
+
+       if (status != QLA_SUCCESS)
+               rval = -EINVAL;
+exit_set_param:
        dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
                          fw_ddb_entry, fw_ddb_entry_dma);
-exit_send_tgts_no_free:
-       return ret_val;
+exit_set_param_no_free:
+       return rval;
+}
+
+int qla4xxx_get_mgmt_data(struct scsi_qla_host *ha, uint16_t fw_ddb_index,
+                         uint16_t stats_size, dma_addr_t stats_dma)
+{
+       int status = QLA_SUCCESS;
+       uint32_t mbox_cmd[MBOX_REG_COUNT];
+       uint32_t mbox_sts[MBOX_REG_COUNT];
+
+       memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
+       memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
+       mbox_cmd[0] = MBOX_CMD_GET_MANAGEMENT_DATA;
+       mbox_cmd[1] = fw_ddb_index;
+       mbox_cmd[2] = LSDW(stats_dma);
+       mbox_cmd[3] = MSDW(stats_dma);
+       mbox_cmd[4] = stats_size;
+
+       status = qla4xxx_mailbox_command(ha, 5, 1, &mbox_cmd[0], &mbox_sts[0]);
+       if (status != QLA_SUCCESS) {
+               DEBUG2(ql4_printk(KERN_WARNING, ha,
+                                 "%s: MBOX_CMD_GET_MANAGEMENT_DATA "
+                                 "failed w/ status %04X\n", __func__,
+                                 mbox_sts[0]));
+       }
+       return status;
 }
 
+int qla4xxx_get_ip_state(struct scsi_qla_host *ha, uint32_t acb_idx,
+                        uint32_t ip_idx, uint32_t *sts)
+{
+       uint32_t mbox_cmd[MBOX_REG_COUNT];
+       uint32_t mbox_sts[MBOX_REG_COUNT];
+       int status = QLA_SUCCESS;
+
+       memset(&mbox_cmd, 0, sizeof(mbox_cmd));
+       memset(&mbox_sts, 0, sizeof(mbox_sts));
+       mbox_cmd[0] = MBOX_CMD_GET_IP_ADDR_STATE;
+       mbox_cmd[1] = acb_idx;
+       mbox_cmd[2] = ip_idx;
+
+       status = qla4xxx_mailbox_command(ha, 3, 8, &mbox_cmd[0], &mbox_sts[0]);
+       if (status != QLA_SUCCESS) {
+               DEBUG2(ql4_printk(KERN_WARNING, ha,  "%s: "
+                                 "MBOX_CMD_GET_IP_ADDR_STATE failed w/ "
+                                 "status %04X\n", __func__, mbox_sts[0]));
+       }
+       memcpy(sts, mbox_sts, sizeof(mbox_sts));
+       return status;
+}
+
+int qla4xxx_get_nvram(struct scsi_qla_host *ha, dma_addr_t nvram_dma,
+                     uint32_t offset, uint32_t size)
+{
+       int status = QLA_SUCCESS;
+       uint32_t mbox_cmd[MBOX_REG_COUNT];
+       uint32_t mbox_sts[MBOX_REG_COUNT];
+
+       memset(&mbox_cmd, 0, sizeof(mbox_cmd));
+       memset(&mbox_sts, 0, sizeof(mbox_sts));
+
+       mbox_cmd[0] = MBOX_CMD_GET_NVRAM;
+       mbox_cmd[1] = LSDW(nvram_dma);
+       mbox_cmd[2] = MSDW(nvram_dma);
+       mbox_cmd[3] = offset;
+       mbox_cmd[4] = size;
+
+       status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
+                                        &mbox_sts[0]);
+       if (status != QLA_SUCCESS) {
+               DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
+                                 "status %04X\n", ha->host_no, __func__,
+                                 mbox_sts[0]));
+       }
+       return status;
+}
+
+int qla4xxx_set_nvram(struct scsi_qla_host *ha, dma_addr_t nvram_dma,
+                     uint32_t offset, uint32_t size)
+{
+       int status = QLA_SUCCESS;
+       uint32_t mbox_cmd[MBOX_REG_COUNT];
+       uint32_t mbox_sts[MBOX_REG_COUNT];
+
+       memset(&mbox_cmd, 0, sizeof(mbox_cmd));
+       memset(&mbox_sts, 0, sizeof(mbox_sts));
+
+       mbox_cmd[0] = MBOX_CMD_SET_NVRAM;
+       mbox_cmd[1] = LSDW(nvram_dma);
+       mbox_cmd[2] = MSDW(nvram_dma);
+       mbox_cmd[3] = offset;
+       mbox_cmd[4] = size;
+
+       status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
+                                        &mbox_sts[0]);
+       if (status != QLA_SUCCESS) {
+               DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
+                                 "status %04X\n", ha->host_no, __func__,
+                                 mbox_sts[0]));
+       }
+       return status;
+}
+
+int qla4xxx_restore_factory_defaults(struct scsi_qla_host *ha,
+                                    uint32_t region, uint32_t field0,
+                                    uint32_t field1)
+{
+       int status = QLA_SUCCESS;
+       uint32_t mbox_cmd[MBOX_REG_COUNT];
+       uint32_t mbox_sts[MBOX_REG_COUNT];
+
+       memset(&mbox_cmd, 0, sizeof(mbox_cmd));
+       memset(&mbox_sts, 0, sizeof(mbox_sts));
+
+       mbox_cmd[0] = MBOX_CMD_RESTORE_FACTORY_DEFAULTS;
+       mbox_cmd[3] = region;
+       mbox_cmd[4] = field0;
+       mbox_cmd[5] = field1;
+
+       status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0],
+                                        &mbox_sts[0]);
+       if (status != QLA_SUCCESS) {
+               DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
+                                 "status %04X\n", ha->host_no, __func__,
+                                 mbox_sts[0]));
+       }
+       return status;
+}
index b4b859b2d47e4ea3db32dc87ede44ca4bdf40e45..7851f314ba96bd1cf5ec032dac0420b14996d4e7 100644 (file)
@@ -156,6 +156,27 @@ u16 rd_nvram_word(struct scsi_qla_host * ha, int offset)
        return val;
 }
 
+u8 rd_nvram_byte(struct scsi_qla_host *ha, int offset)
+{
+       u16 val = 0;
+       u8 rval = 0;
+       int index = 0;
+
+       if (offset & 0x1)
+               index = (offset - 1) / 2;
+       else
+               index = offset / 2;
+
+       val = le16_to_cpu(rd_nvram_word(ha, index));
+
+       if (offset & 0x1)
+               rval = (u8)((val & 0xff00) >> 8);
+       else
+               rval = (u8)((val & 0x00ff));
+
+       return rval;
+}
+
 int qla4xxx_is_nvram_configuration_valid(struct scsi_qla_host * ha)
 {
        int status = QLA_ERROR;
index fdfe27b3869807289d98c4cf75afef678a4ecf4f..f484ff43819928f5678ebff0187b7f503a609675 100644 (file)
@@ -2015,11 +2015,19 @@ qla4_8xxx_get_flt_info(struct scsi_qla_host *ha, uint32_t flt_addr)
                        hw->flt_region_boot = start;
                        break;
                case FLT_REG_FW_82:
+               case FLT_REG_FW_82_1:
                        hw->flt_region_fw = start;
                        break;
                case FLT_REG_BOOTLOAD_82:
                        hw->flt_region_bootload = start;
                        break;
+               case FLT_REG_ISCSI_PARAM:
+                       hw->flt_iscsi_param =  start;
+                       break;
+               case FLT_REG_ISCSI_CHAP:
+                       hw->flt_region_chap =  start;
+                       hw->flt_chap_size =  le32_to_cpu(region->size);
+                       break;
                }
        }
        goto done;
@@ -2032,6 +2040,9 @@ no_flash_data:
        hw->flt_region_boot     = FA_BOOT_CODE_ADDR_82;
        hw->flt_region_bootload = FA_BOOT_LOAD_ADDR_82;
        hw->flt_region_fw       = FA_RISC_CODE_ADDR_82;
+       hw->flt_region_chap     = FA_FLASH_ISCSI_CHAP;
+       hw->flt_chap_size       = FA_FLASH_CHAP_SIZE;
+
 done:
        DEBUG2(ql4_printk(KERN_INFO, ha, "FLT[%s]: flt=0x%x fdt=0x%x "
            "boot=0x%x bootload=0x%x fw=0x%x\n", loc, hw->flt_region_flt,
@@ -2258,10 +2269,16 @@ int qla4_8xxx_get_sys_info(struct scsi_qla_host *ha)
        }
 
        /* Save M.A.C. address & serial_number */
+       ha->port_num = sys_info->port_num;
        memcpy(ha->my_mac, &sys_info->mac_addr[0],
            min(sizeof(ha->my_mac), sizeof(sys_info->mac_addr)));
        memcpy(ha->serial_number, &sys_info->serial_number,
            min(sizeof(ha->serial_number), sizeof(sys_info->serial_number)));
+       memcpy(ha->model_name, &sys_info->board_id_str,
+              min(sizeof(ha->model_name), sizeof(sys_info->board_id_str)));
+       ha->phy_port_cnt = sys_info->phys_port_cnt;
+       ha->phy_port_num = sys_info->port_num;
+       ha->iscsi_pci_func_cnt = sys_info->iscsi_pci_func_cnt;
 
        DEBUG2(printk("scsi%ld: %s: "
            "mac %02x:%02x:%02x:%02x:%02x:%02x "
index f2364ec59f0349e43950fd2a4585ba7f2c26838c..30f31b127f33750dd384770cb5b1ba1b3e33807d 100644 (file)
@@ -6,6 +6,8 @@
  */
 #include <linux/moduleparam.h>
 #include <linux/slab.h>
+#include <linux/blkdev.h>
+#include <linux/iscsi_boot_sysfs.h>
 
 #include <scsi/scsi_tcq.h>
 #include <scsi/scsicam.h>
@@ -63,6 +65,7 @@ MODULE_PARM_DESC(ql4xsess_recovery_tmo,
                "Target Session Recovery Timeout.\n"
                " Default: 30 sec.");
 
+static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha);
 /*
  * SCSI host template entry points
  */
@@ -71,18 +74,41 @@ static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
 /*
  * iSCSI template entry points
  */
-static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost,
-                            enum iscsi_tgt_dscvr type, uint32_t enable,
-                            struct sockaddr *dst_addr);
 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
                                  enum iscsi_param param, char *buf);
-static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess,
-                                 enum iscsi_param param, char *buf);
 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
                                  enum iscsi_host_param param, char *buf);
-static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session);
+static int qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data,
+                                  uint32_t len);
+static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
+                                  enum iscsi_param_type param_type,
+                                  int param, char *buf);
 static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
-
+static struct iscsi_endpoint *qla4xxx_ep_connect(struct Scsi_Host *shost,
+                                                struct sockaddr *dst_addr,
+                                                int non_blocking);
+static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms);
+static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep);
+static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
+                               enum iscsi_param param, char *buf);
+static int qla4xxx_conn_start(struct iscsi_cls_conn *conn);
+static struct iscsi_cls_conn *
+qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx);
+static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
+                            struct iscsi_cls_conn *cls_conn,
+                            uint64_t transport_fd, int is_leading);
+static void qla4xxx_conn_destroy(struct iscsi_cls_conn *conn);
+static struct iscsi_cls_session *
+qla4xxx_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
+                       uint16_t qdepth, uint32_t initial_cmdsn);
+static void qla4xxx_session_destroy(struct iscsi_cls_session *sess);
+static void qla4xxx_task_work(struct work_struct *wdata);
+static int qla4xxx_alloc_pdu(struct iscsi_task *, uint8_t);
+static int qla4xxx_task_xmit(struct iscsi_task *);
+static void qla4xxx_task_cleanup(struct iscsi_task *);
+static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session);
+static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
+                                  struct iscsi_stats *stats);
 /*
  * SCSI host template entry points
  */
@@ -94,7 +120,8 @@ static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
 static int qla4xxx_slave_alloc(struct scsi_device *device);
 static int qla4xxx_slave_configure(struct scsi_device *device);
 static void qla4xxx_slave_destroy(struct scsi_device *sdev);
-static void qla4xxx_scan_start(struct Scsi_Host *shost);
+static mode_t ql4_attr_is_visible(int param_type, int param);
+static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type);
 
 static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
     QLA82XX_LEGACY_INTR_CONFIG;
@@ -115,9 +142,6 @@ static struct scsi_host_template qla4xxx_driver_template = {
        .slave_alloc            = qla4xxx_slave_alloc,
        .slave_destroy          = qla4xxx_slave_destroy,
 
-       .scan_finished          = iscsi_scan_finished,
-       .scan_start             = qla4xxx_scan_start,
-
        .this_id                = -1,
        .cmd_per_lun            = 3,
        .use_clustering         = ENABLE_CLUSTERING,
@@ -125,56 +149,394 @@ static struct scsi_host_template qla4xxx_driver_template = {
 
        .max_sectors            = 0xFFFF,
        .shost_attrs            = qla4xxx_host_attrs,
+       .host_reset             = qla4xxx_host_reset,
+       .vendor_id              = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
 };
 
 static struct iscsi_transport qla4xxx_iscsi_transport = {
        .owner                  = THIS_MODULE,
        .name                   = DRIVER_NAME,
-       .caps                   = CAP_FW_DB | CAP_SENDTARGETS_OFFLOAD |
-                                 CAP_DATA_PATH_OFFLOAD,
-       .param_mask             = ISCSI_CONN_PORT | ISCSI_CONN_ADDRESS |
-                                 ISCSI_TARGET_NAME | ISCSI_TPGT |
-                                 ISCSI_TARGET_ALIAS,
-       .host_param_mask        = ISCSI_HOST_HWADDRESS |
-                                 ISCSI_HOST_IPADDRESS |
-                                 ISCSI_HOST_INITIATOR_NAME,
-       .tgt_dscvr              = qla4xxx_tgt_dscvr,
+       .caps                   = CAP_TEXT_NEGO |
+                                 CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
+                                 CAP_DATADGST | CAP_LOGIN_OFFLOAD |
+                                 CAP_MULTI_R2T,
+       .attr_is_visible        = ql4_attr_is_visible,
+       .create_session         = qla4xxx_session_create,
+       .destroy_session        = qla4xxx_session_destroy,
+       .start_conn             = qla4xxx_conn_start,
+       .create_conn            = qla4xxx_conn_create,
+       .bind_conn              = qla4xxx_conn_bind,
+       .stop_conn              = iscsi_conn_stop,
+       .destroy_conn           = qla4xxx_conn_destroy,
+       .set_param              = iscsi_set_param,
        .get_conn_param         = qla4xxx_conn_get_param,
-       .get_session_param      = qla4xxx_sess_get_param,
+       .get_session_param      = iscsi_session_get_param,
+       .get_ep_param           = qla4xxx_get_ep_param,
+       .ep_connect             = qla4xxx_ep_connect,
+       .ep_poll                = qla4xxx_ep_poll,
+       .ep_disconnect          = qla4xxx_ep_disconnect,
+       .get_stats              = qla4xxx_conn_get_stats,
+       .send_pdu               = iscsi_conn_send_pdu,
+       .xmit_task              = qla4xxx_task_xmit,
+       .cleanup_task           = qla4xxx_task_cleanup,
+       .alloc_pdu              = qla4xxx_alloc_pdu,
+
        .get_host_param         = qla4xxx_host_get_param,
-       .session_recovery_timedout = qla4xxx_recovery_timedout,
+       .set_iface_param        = qla4xxx_iface_set_param,
+       .get_iface_param        = qla4xxx_get_iface_param,
+       .bsg_request            = qla4xxx_bsg_request,
 };
 
 static struct scsi_transport_template *qla4xxx_scsi_transport;
 
-static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
+static mode_t ql4_attr_is_visible(int param_type, int param)
 {
-       struct iscsi_cls_session *session;
-       struct ddb_entry *ddb_entry;
+       switch (param_type) {
+       case ISCSI_HOST_PARAM:
+               switch (param) {
+               case ISCSI_HOST_PARAM_HWADDRESS:
+               case ISCSI_HOST_PARAM_IPADDRESS:
+               case ISCSI_HOST_PARAM_INITIATOR_NAME:
+                       return S_IRUGO;
+               default:
+                       return 0;
+               }
+       case ISCSI_PARAM:
+               switch (param) {
+               case ISCSI_PARAM_PERSISTENT_ADDRESS:
+               case ISCSI_PARAM_PERSISTENT_PORT:
+               case ISCSI_PARAM_CONN_ADDRESS:
+               case ISCSI_PARAM_CONN_PORT:
+               case ISCSI_PARAM_TARGET_NAME:
+               case ISCSI_PARAM_TPGT:
+               case ISCSI_PARAM_TARGET_ALIAS:
+               case ISCSI_PARAM_MAX_BURST:
+               case ISCSI_PARAM_MAX_R2T:
+               case ISCSI_PARAM_FIRST_BURST:
+               case ISCSI_PARAM_MAX_RECV_DLENGTH:
+               case ISCSI_PARAM_MAX_XMIT_DLENGTH:
+               case ISCSI_PARAM_IFACE_NAME:
+                       return S_IRUGO;
+               default:
+                       return 0;
+               }
+       case ISCSI_NET_PARAM:
+               switch (param) {
+               case ISCSI_NET_PARAM_IPV4_ADDR:
+               case ISCSI_NET_PARAM_IPV4_SUBNET:
+               case ISCSI_NET_PARAM_IPV4_GW:
+               case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
+               case ISCSI_NET_PARAM_IFACE_ENABLE:
+               case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
+               case ISCSI_NET_PARAM_IPV6_ADDR:
+               case ISCSI_NET_PARAM_IPV6_ROUTER:
+               case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
+               case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
+               case ISCSI_NET_PARAM_VLAN_ID:
+               case ISCSI_NET_PARAM_VLAN_PRIORITY:
+               case ISCSI_NET_PARAM_VLAN_ENABLED:
+               case ISCSI_NET_PARAM_MTU:
+               case ISCSI_NET_PARAM_PORT:
+                       return S_IRUGO;
+               default:
+                       return 0;
+               }
+       }
 
-       session = starget_to_session(scsi_target(sc->device));
-       ddb_entry = session->dd_data;
+       return 0;
+}
 
-       /* if we are not logged in then the LLD is going to clean up the cmd */
-       if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)
-               return BLK_EH_RESET_TIMER;
-       else
-               return BLK_EH_NOT_HANDLED;
+static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
+                                  enum iscsi_param_type param_type,
+                                  int param, char *buf)
+{
+       struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
+       struct scsi_qla_host *ha = to_qla_host(shost);
+       int len = -ENOSYS;
+
+       if (param_type != ISCSI_NET_PARAM)
+               return -ENOSYS;
+
+       switch (param) {
+       case ISCSI_NET_PARAM_IPV4_ADDR:
+               len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
+               break;
+       case ISCSI_NET_PARAM_IPV4_SUBNET:
+               len = sprintf(buf, "%pI4\n", &ha->ip_config.subnet_mask);
+               break;
+       case ISCSI_NET_PARAM_IPV4_GW:
+               len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
+               break;
+       case ISCSI_NET_PARAM_IFACE_ENABLE:
+               if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
+                       len = sprintf(buf, "%s\n",
+                                     (ha->ip_config.ipv4_options &
+                                      IPOPT_IPV4_PROTOCOL_ENABLE) ?
+                                     "enabled" : "disabled");
+               else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
+                       len = sprintf(buf, "%s\n",
+                                     (ha->ip_config.ipv6_options &
+                                      IPV6_OPT_IPV6_PROTOCOL_ENABLE) ?
+                                      "enabled" : "disabled");
+               break;
+       case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
+               len = sprintf(buf, "%s\n",
+                             (ha->ip_config.tcp_options & TCPOPT_DHCP_ENABLE) ?
+                             "dhcp" : "static");
+               break;
+       case ISCSI_NET_PARAM_IPV6_ADDR:
+               if (iface->iface_num == 0)
+                       len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr0);
+               if (iface->iface_num == 1)
+                       len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr1);
+               break;
+       case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
+               len = sprintf(buf, "%pI6\n",
+                             &ha->ip_config.ipv6_link_local_addr);
+               break;
+       case ISCSI_NET_PARAM_IPV6_ROUTER:
+               len = sprintf(buf, "%pI6\n",
+                             &ha->ip_config.ipv6_default_router_addr);
+               break;
+       case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
+               len = sprintf(buf, "%s\n",
+                             (ha->ip_config.ipv6_addl_options &
+                              IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
+                              "nd" : "static");
+               break;
+       case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
+               len = sprintf(buf, "%s\n",
+                             (ha->ip_config.ipv6_addl_options &
+                              IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
+                              "auto" : "static");
+               break;
+       case ISCSI_NET_PARAM_VLAN_ID:
+               if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
+                       len = sprintf(buf, "%d\n",
+                                     (ha->ip_config.ipv4_vlan_tag &
+                                      ISCSI_MAX_VLAN_ID));
+               else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
+                       len = sprintf(buf, "%d\n",
+                                     (ha->ip_config.ipv6_vlan_tag &
+                                      ISCSI_MAX_VLAN_ID));
+               break;
+       case ISCSI_NET_PARAM_VLAN_PRIORITY:
+               if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
+                       len = sprintf(buf, "%d\n",
+                                     ((ha->ip_config.ipv4_vlan_tag >> 13) &
+                                       ISCSI_MAX_VLAN_PRIORITY));
+               else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
+                       len = sprintf(buf, "%d\n",
+                                     ((ha->ip_config.ipv6_vlan_tag >> 13) &
+                                       ISCSI_MAX_VLAN_PRIORITY));
+               break;
+       case ISCSI_NET_PARAM_VLAN_ENABLED:
+               if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
+                       len = sprintf(buf, "%s\n",
+                                     (ha->ip_config.ipv4_options &
+                                      IPOPT_VLAN_TAGGING_ENABLE) ?
+                                      "enabled" : "disabled");
+               else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
+                       len = sprintf(buf, "%s\n",
+                                     (ha->ip_config.ipv6_options &
+                                      IPV6_OPT_VLAN_TAGGING_ENABLE) ?
+                                      "enabled" : "disabled");
+               break;
+       case ISCSI_NET_PARAM_MTU:
+               len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
+               break;
+       case ISCSI_NET_PARAM_PORT:
+               if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
+                       len = sprintf(buf, "%d\n", ha->ip_config.ipv4_port);
+               else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
+                       len = sprintf(buf, "%d\n", ha->ip_config.ipv6_port);
+               break;
+       default:
+               len = -ENOSYS;
+       }
+
+       return len;
 }
 
-static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session)
+static struct iscsi_endpoint *
+qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
+                  int non_blocking)
 {
-       struct ddb_entry *ddb_entry = session->dd_data;
-       struct scsi_qla_host *ha = ddb_entry->ha;
+       int ret;
+       struct iscsi_endpoint *ep;
+       struct qla_endpoint *qla_ep;
+       struct scsi_qla_host *ha;
+       struct sockaddr_in *addr;
+       struct sockaddr_in6 *addr6;
+
+       DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
+       if (!shost) {
+               ret = -ENXIO;
+               printk(KERN_ERR "%s: shost is NULL\n",
+                      __func__);
+               return ERR_PTR(ret);
+       }
+
+       ha = iscsi_host_priv(shost);
+
+       ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
+       if (!ep) {
+               ret = -ENOMEM;
+               return ERR_PTR(ret);
+       }
+
+       qla_ep = ep->dd_data;
+       memset(qla_ep, 0, sizeof(struct qla_endpoint));
+       if (dst_addr->sa_family == AF_INET) {
+               memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
+               addr = (struct sockaddr_in *)&qla_ep->dst_addr;
+               DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
+                                 (char *)&addr->sin_addr));
+       } else if (dst_addr->sa_family == AF_INET6) {
+               memcpy(&qla_ep->dst_addr, dst_addr,
+                      sizeof(struct sockaddr_in6));
+               addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
+               DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
+                                 (char *)&addr6->sin6_addr));
+       }
+
+       qla_ep->host = shost;
+
+       return ep;
+}
+
+static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
+{
+       struct qla_endpoint *qla_ep;
+       struct scsi_qla_host *ha;
+       int ret = 0;
+
+       DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
+       qla_ep = ep->dd_data;
+       ha = to_qla_host(qla_ep->host);
+
+       if (adapter_up(ha))
+               ret = 1;
 
-       if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
-               atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
+       return ret;
+}
+
+static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
+{
+       DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
+       iscsi_destroy_endpoint(ep);
+}
+
+static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
+                               enum iscsi_param param,
+                               char *buf)
+{
+       struct qla_endpoint *qla_ep = ep->dd_data;
+       struct sockaddr *dst_addr;
+
+       DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
+
+       switch (param) {
+       case ISCSI_PARAM_CONN_PORT:
+       case ISCSI_PARAM_CONN_ADDRESS:
+               if (!qla_ep)
+                       return -ENOTCONN;
 
-               DEBUG2(printk("scsi%ld: %s: ddb [%d] session recovery timeout "
-                             "of (%d) secs exhausted, marking device DEAD.\n",
-                             ha->host_no, __func__, ddb_entry->fw_ddb_index,
-                             ddb_entry->sess->recovery_tmo));
+               dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
+               if (!dst_addr)
+                       return -ENOTCONN;
+
+               return iscsi_conn_get_addr_param((struct sockaddr_storage *)
+                                                &qla_ep->dst_addr, param, buf);
+       default:
+               return -ENOSYS;
+       }
+}
+
+static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
+                                  struct iscsi_stats *stats)
+{
+       struct iscsi_session *sess;
+       struct iscsi_cls_session *cls_sess;
+       struct ddb_entry *ddb_entry;
+       struct scsi_qla_host *ha;
+       struct ql_iscsi_stats *ql_iscsi_stats;
+       int stats_size;
+       int ret;
+       dma_addr_t iscsi_stats_dma;
+
+       DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
+
+       cls_sess = iscsi_conn_to_session(cls_conn);
+       sess = cls_sess->dd_data;
+       ddb_entry = sess->dd_data;
+       ha = ddb_entry->ha;
+
+       stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
+       /* Allocate memory */
+       ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
+                                           &iscsi_stats_dma, GFP_KERNEL);
+       if (!ql_iscsi_stats) {
+               ql4_printk(KERN_ERR, ha,
+                          "Unable to allocate memory for iscsi stats\n");
+               goto exit_get_stats;
+       }
+
+       ret =  qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
+                                    iscsi_stats_dma);
+       if (ret != QLA_SUCCESS) {
+               ql4_printk(KERN_ERR, ha,
+                          "Unable to retreive iscsi stats\n");
+               goto free_stats;
        }
+
+       /* octets */
+       stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
+       stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
+       /* xmit pdus */
+       stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
+       stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
+       stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
+       stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
+       stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
+       stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
+       stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
+       stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
+       /* recv pdus */
+       stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
+       stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
+       stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
+       stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
+       stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
+       stats->logoutrsp_pdus =
+                       le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
+       stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
+       stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
+       stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
+
+free_stats:
+       dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
+                         iscsi_stats_dma);
+exit_get_stats:
+       return;
+}
+
+static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
+{
+       struct iscsi_cls_session *session;
+       struct iscsi_session *sess;
+       unsigned long flags;
+       enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED;
+
+       session = starget_to_session(scsi_target(sc->device));
+       sess = session->dd_data;
+
+       spin_lock_irqsave(&session->lock, flags);
+       if (session->state == ISCSI_SESSION_FAILED)
+               ret = BLK_EH_RESET_TIMER;
+       spin_unlock_irqrestore(&session->lock, flags);
+
+       return ret;
 }
 
 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
@@ -188,9 +550,7 @@ static int qla4xxx_host_get_param(struct Scsi_Host *shost,
                len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
                break;
        case ISCSI_HOST_PARAM_IPADDRESS:
-               len = sprintf(buf, "%d.%d.%d.%d\n", ha->ip_address[0],
-                             ha->ip_address[1], ha->ip_address[2],
-                             ha->ip_address[3]);
+               len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
                break;
        case ISCSI_HOST_PARAM_INITIATOR_NAME:
                len = sprintf(buf, "%s\n", ha->name_string);
@@ -202,154 +562,851 @@ static int qla4xxx_host_get_param(struct Scsi_Host *shost,
        return len;
 }
 
-static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess,
-                                 enum iscsi_param param, char *buf)
+static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
 {
-       struct ddb_entry *ddb_entry = sess->dd_data;
-       int len;
+       if (ha->iface_ipv4)
+               return;
 
-       switch (param) {
-       case ISCSI_PARAM_TARGET_NAME:
-               len = snprintf(buf, PAGE_SIZE - 1, "%s\n",
-                              ddb_entry->iscsi_name);
+       /* IPv4 */
+       ha->iface_ipv4 = iscsi_create_iface(ha->host,
+                                           &qla4xxx_iscsi_transport,
+                                           ISCSI_IFACE_TYPE_IPV4, 0, 0);
+       if (!ha->iface_ipv4)
+               ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
+                          "iface0.\n");
+}
+
+static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
+{
+       if (!ha->iface_ipv6_0)
+               /* IPv6 iface-0 */
+               ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
+                                                     &qla4xxx_iscsi_transport,
+                                                     ISCSI_IFACE_TYPE_IPV6, 0,
+                                                     0);
+       if (!ha->iface_ipv6_0)
+               ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
+                          "iface0.\n");
+
+       if (!ha->iface_ipv6_1)
+               /* IPv6 iface-1 */
+               ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
+                                                     &qla4xxx_iscsi_transport,
+                                                     ISCSI_IFACE_TYPE_IPV6, 1,
+                                                     0);
+       if (!ha->iface_ipv6_1)
+               ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
+                          "iface1.\n");
+}
+
+static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
+{
+       if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
+               qla4xxx_create_ipv4_iface(ha);
+
+       if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
+               qla4xxx_create_ipv6_iface(ha);
+}
+
+static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
+{
+       if (ha->iface_ipv4) {
+               iscsi_destroy_iface(ha->iface_ipv4);
+               ha->iface_ipv4 = NULL;
+       }
+}
+
+static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
+{
+       if (ha->iface_ipv6_0) {
+               iscsi_destroy_iface(ha->iface_ipv6_0);
+               ha->iface_ipv6_0 = NULL;
+       }
+       if (ha->iface_ipv6_1) {
+               iscsi_destroy_iface(ha->iface_ipv6_1);
+               ha->iface_ipv6_1 = NULL;
+       }
+}
+
+static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
+{
+       qla4xxx_destroy_ipv4_iface(ha);
+       qla4xxx_destroy_ipv6_iface(ha);
+}
+
+static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
+                            struct iscsi_iface_param_info *iface_param,
+                            struct addr_ctrl_blk *init_fw_cb)
+{
+       /*
+        * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
+        * iface_num 1 is valid only for IPv6 Addr.
+        */
+       switch (iface_param->param) {
+       case ISCSI_NET_PARAM_IPV6_ADDR:
+               if (iface_param->iface_num & 0x1)
+                       /* IPv6 Addr 1 */
+                       memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
+                              sizeof(init_fw_cb->ipv6_addr1));
+               else
+                       /* IPv6 Addr 0 */
+                       memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
+                              sizeof(init_fw_cb->ipv6_addr0));
                break;
-       case ISCSI_PARAM_TPGT:
-               len = sprintf(buf, "%u\n", ddb_entry->tpgt);
+       case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
+               if (iface_param->iface_num & 0x1)
+                       break;
+               memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
+                      sizeof(init_fw_cb->ipv6_if_id));
+               break;
+       case ISCSI_NET_PARAM_IPV6_ROUTER:
+               if (iface_param->iface_num & 0x1)
+                       break;
+               memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
+                      sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
+               break;
+       case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
+               /* Autocfg applies to even interface */
+               if (iface_param->iface_num & 0x1)
+                       break;
+
+               if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
+                       init_fw_cb->ipv6_addtl_opts &=
+                               cpu_to_le16(
+                                 ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
+               else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
+                       init_fw_cb->ipv6_addtl_opts |=
+                               cpu_to_le16(
+                                 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
+               else
+                       ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
+                                  "IPv6 addr\n");
                break;
-       case ISCSI_PARAM_TARGET_ALIAS:
-               len = snprintf(buf, PAGE_SIZE - 1, "%s\n",
-                   ddb_entry->iscsi_alias);
+       case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
+               /* Autocfg applies to even interface */
+               if (iface_param->iface_num & 0x1)
+                       break;
+
+               if (iface_param->value[0] ==
+                   ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
+                       init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
+                                       IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
+               else if (iface_param->value[0] ==
+                        ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
+                       init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
+                                      ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
+               else
+                       ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
+                                  "IPv6 linklocal addr\n");
+               break;
+       case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
+               /* Autocfg applies to even interface */
+               if (iface_param->iface_num & 0x1)
+                       break;
+
+               if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
+                       memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
+                              sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
+               break;
+       case ISCSI_NET_PARAM_IFACE_ENABLE:
+               if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
+                       init_fw_cb->ipv6_opts |=
+                               cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
+                       qla4xxx_create_ipv6_iface(ha);
+               } else {
+                       init_fw_cb->ipv6_opts &=
+                               cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
+                                           0xFFFF);
+                       qla4xxx_destroy_ipv6_iface(ha);
+               }
+               break;
+       case ISCSI_NET_PARAM_VLAN_TAG:
+               if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
+                       break;
+               init_fw_cb->ipv6_vlan_tag =
+                               cpu_to_be16(*(uint16_t *)iface_param->value);
+               break;
+       case ISCSI_NET_PARAM_VLAN_ENABLED:
+               if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
+                       init_fw_cb->ipv6_opts |=
+                               cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
+               else
+                       init_fw_cb->ipv6_opts &=
+                               cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
+               break;
+       case ISCSI_NET_PARAM_MTU:
+               init_fw_cb->eth_mtu_size =
+                               cpu_to_le16(*(uint16_t *)iface_param->value);
+               break;
+       case ISCSI_NET_PARAM_PORT:
+               /* Autocfg applies to even interface */
+               if (iface_param->iface_num & 0x1)
+                       break;
+
+               init_fw_cb->ipv6_port =
+                               cpu_to_le16(*(uint16_t *)iface_param->value);
                break;
        default:
-               return -ENOSYS;
+               ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
+                          iface_param->param);
+               break;
        }
+}
 
-       return len;
+static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
+                            struct iscsi_iface_param_info *iface_param,
+                            struct addr_ctrl_blk *init_fw_cb)
+{
+       switch (iface_param->param) {
+       case ISCSI_NET_PARAM_IPV4_ADDR:
+               memcpy(init_fw_cb->ipv4_addr, iface_param->value,
+                      sizeof(init_fw_cb->ipv4_addr));
+               break;
+       case ISCSI_NET_PARAM_IPV4_SUBNET:
+               memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
+                      sizeof(init_fw_cb->ipv4_subnet));
+               break;
+       case ISCSI_NET_PARAM_IPV4_GW:
+               memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
+                      sizeof(init_fw_cb->ipv4_gw_addr));
+               break;
+       case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
+               if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
+                       init_fw_cb->ipv4_tcp_opts |=
+                                       cpu_to_le16(TCPOPT_DHCP_ENABLE);
+               else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
+                       init_fw_cb->ipv4_tcp_opts &=
+                                       cpu_to_le16(~TCPOPT_DHCP_ENABLE);
+               else
+                       ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
+               break;
+       case ISCSI_NET_PARAM_IFACE_ENABLE:
+               if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
+                       init_fw_cb->ipv4_ip_opts |=
+                               cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
+                       qla4xxx_create_ipv4_iface(ha);
+               } else {
+                       init_fw_cb->ipv4_ip_opts &=
+                               cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
+                                           0xFFFF);
+                       qla4xxx_destroy_ipv4_iface(ha);
+               }
+               break;
+       case ISCSI_NET_PARAM_VLAN_TAG:
+               if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
+                       break;
+               init_fw_cb->ipv4_vlan_tag =
+                               cpu_to_be16(*(uint16_t *)iface_param->value);
+               break;
+       case ISCSI_NET_PARAM_VLAN_ENABLED:
+               if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
+                       init_fw_cb->ipv4_ip_opts |=
+                                       cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
+               else
+                       init_fw_cb->ipv4_ip_opts &=
+                                       cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
+               break;
+       case ISCSI_NET_PARAM_MTU:
+               init_fw_cb->eth_mtu_size =
+                               cpu_to_le16(*(uint16_t *)iface_param->value);
+               break;
+       case ISCSI_NET_PARAM_PORT:
+               init_fw_cb->ipv4_port =
+                               cpu_to_le16(*(uint16_t *)iface_param->value);
+               break;
+       default:
+               ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
+                          iface_param->param);
+               break;
+       }
 }
 
-static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
+static void
+qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
+{
+       struct addr_ctrl_blk_def *acb;
+       acb = (struct addr_ctrl_blk_def *)init_fw_cb;
+       memset(acb->reserved1, 0, sizeof(acb->reserved1));
+       memset(acb->reserved2, 0, sizeof(acb->reserved2));
+       memset(acb->reserved3, 0, sizeof(acb->reserved3));
+       memset(acb->reserved4, 0, sizeof(acb->reserved4));
+       memset(acb->reserved5, 0, sizeof(acb->reserved5));
+       memset(acb->reserved6, 0, sizeof(acb->reserved6));
+       memset(acb->reserved7, 0, sizeof(acb->reserved7));
+       memset(acb->reserved8, 0, sizeof(acb->reserved8));
+       memset(acb->reserved9, 0, sizeof(acb->reserved9));
+       memset(acb->reserved10, 0, sizeof(acb->reserved10));
+       memset(acb->reserved11, 0, sizeof(acb->reserved11));
+       memset(acb->reserved12, 0, sizeof(acb->reserved12));
+       memset(acb->reserved13, 0, sizeof(acb->reserved13));
+       memset(acb->reserved14, 0, sizeof(acb->reserved14));
+       memset(acb->reserved15, 0, sizeof(acb->reserved15));
+}
+
+static int
+qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
+{
+       struct scsi_qla_host *ha = to_qla_host(shost);
+       int rval = 0;
+       struct iscsi_iface_param_info *iface_param = NULL;
+       struct addr_ctrl_blk *init_fw_cb = NULL;
+       dma_addr_t init_fw_cb_dma;
+       uint32_t mbox_cmd[MBOX_REG_COUNT];
+       uint32_t mbox_sts[MBOX_REG_COUNT];
+       uint32_t rem = len;
+       struct nlattr *attr;
+
+       init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
+                                       sizeof(struct addr_ctrl_blk),
+                                       &init_fw_cb_dma, GFP_KERNEL);
+       if (!init_fw_cb) {
+               ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
+                          __func__);
+               return -ENOMEM;
+       }
+
+       memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
+       memset(&mbox_cmd, 0, sizeof(mbox_cmd));
+       memset(&mbox_sts, 0, sizeof(mbox_sts));
+
+       if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
+               ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
+               rval = -EIO;
+               goto exit_init_fw_cb;
+       }
+
+       nla_for_each_attr(attr, data, len, rem) {
+               iface_param = nla_data(attr);
+
+               if (iface_param->param_type != ISCSI_NET_PARAM)
+                       continue;
+
+               switch (iface_param->iface_type) {
+               case ISCSI_IFACE_TYPE_IPV4:
+                       switch (iface_param->iface_num) {
+                       case 0:
+                               qla4xxx_set_ipv4(ha, iface_param, init_fw_cb);
+                               break;
+                       default:
+                               /* Cannot have more than one IPv4 interface */
+                               ql4_printk(KERN_ERR, ha, "Invalid IPv4 iface "
+                                          "number = %d\n",
+                                          iface_param->iface_num);
+                               break;
+                       }
+                       break;
+               case ISCSI_IFACE_TYPE_IPV6:
+                       switch (iface_param->iface_num) {
+                       case 0:
+                       case 1:
+                               qla4xxx_set_ipv6(ha, iface_param, init_fw_cb);
+                               break;
+                       default:
+                               /* Cannot have more than two IPv6 interface */
+                               ql4_printk(KERN_ERR, ha, "Invalid IPv6 iface "
+                                          "number = %d\n",
+                                          iface_param->iface_num);
+                               break;
+                       }
+                       break;
+               default:
+                       ql4_printk(KERN_ERR, ha, "Invalid iface type\n");
+                       break;
+               }
+       }
+
+       init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
+
+       rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
+                                sizeof(struct addr_ctrl_blk),
+                                FLASH_OPT_RMW_COMMIT);
+       if (rval != QLA_SUCCESS) {
+               ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
+                          __func__);
+               rval = -EIO;
+               goto exit_init_fw_cb;
+       }
+
+       qla4xxx_disable_acb(ha);
+
+       qla4xxx_initcb_to_acb(init_fw_cb);
+
+       rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
+       if (rval != QLA_SUCCESS) {
+               ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
+                          __func__);
+               rval = -EIO;
+               goto exit_init_fw_cb;
+       }
+
+       memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
+       qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
+                                 init_fw_cb_dma);
+
+exit_init_fw_cb:
+       dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
+                         init_fw_cb, init_fw_cb_dma);
+
+       return rval;
+}
+
+static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
                                  enum iscsi_param param, char *buf)
 {
-       struct iscsi_cls_session *session;
-       struct ddb_entry *ddb_entry;
-       int len;
+       struct iscsi_conn *conn;
+       struct qla_conn *qla_conn;
+       struct sockaddr *dst_addr;
+       int len = 0;
 
-       session = iscsi_dev_to_session(conn->dev.parent);
-       ddb_entry = session->dd_data;
+       conn = cls_conn->dd_data;
+       qla_conn = conn->dd_data;
+       dst_addr = &qla_conn->qla_ep->dst_addr;
 
        switch (param) {
        case ISCSI_PARAM_CONN_PORT:
-               len = sprintf(buf, "%hu\n", ddb_entry->port);
-               break;
        case ISCSI_PARAM_CONN_ADDRESS:
-               /* TODO: what are the ipv6 bits */
-               len = sprintf(buf, "%pI4\n", &ddb_entry->ip_addr);
-               break;
+               return iscsi_conn_get_addr_param((struct sockaddr_storage *)
+                                                dst_addr, param, buf);
        default:
-               return -ENOSYS;
+               return iscsi_conn_get_param(cls_conn, param, buf);
        }
 
        return len;
+
 }
 
-static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost,
-                            enum iscsi_tgt_dscvr type, uint32_t enable,
-                            struct sockaddr *dst_addr)
+static struct iscsi_cls_session *
+qla4xxx_session_create(struct iscsi_endpoint *ep,
+                       uint16_t cmds_max, uint16_t qdepth,
+                       uint32_t initial_cmdsn)
 {
+       struct iscsi_cls_session *cls_sess;
        struct scsi_qla_host *ha;
-       struct sockaddr_in *addr;
-       struct sockaddr_in6 *addr6;
+       struct qla_endpoint *qla_ep;
+       struct ddb_entry *ddb_entry;
+       uint32_t ddb_index;
+       uint32_t mbx_sts = 0;
+       struct iscsi_session *sess;
+       struct sockaddr *dst_addr;
+       int ret;
+
+       DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
+       if (!ep) {
+               printk(KERN_ERR "qla4xxx: missing ep.\n");
+               return NULL;
+       }
+
+       qla_ep = ep->dd_data;
+       dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
+       ha = to_qla_host(qla_ep->host);
+
+get_ddb_index:
+       ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
+
+       if (ddb_index >= MAX_DDB_ENTRIES) {
+               DEBUG2(ql4_printk(KERN_INFO, ha,
+                                 "Free DDB index not available\n"));
+               return NULL;
+       }
+
+       if (test_and_set_bit(ddb_index, ha->ddb_idx_map))
+               goto get_ddb_index;
+
+       DEBUG2(ql4_printk(KERN_INFO, ha,
+                         "Found a free DDB index at %d\n", ddb_index));
+       ret = qla4xxx_req_ddb_entry(ha, ddb_index, &mbx_sts);
+       if (ret == QLA_ERROR) {
+               if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
+                       ql4_printk(KERN_INFO, ha,
+                                  "DDB index = %d not available trying next\n",
+                                  ddb_index);
+                       goto get_ddb_index;
+               }
+               DEBUG2(ql4_printk(KERN_INFO, ha,
+                                 "Free FW DDB not available\n"));
+               return NULL;
+       }
+
+       cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
+                                      cmds_max, sizeof(struct ddb_entry),
+                                      sizeof(struct ql4_task_data),
+                                      initial_cmdsn, ddb_index);
+       if (!cls_sess)
+               return NULL;
+
+       sess = cls_sess->dd_data;
+       ddb_entry = sess->dd_data;
+       ddb_entry->fw_ddb_index = ddb_index;
+       ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
+       ddb_entry->ha = ha;
+       ddb_entry->sess = cls_sess;
+       cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
+       ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
+       ha->tot_ddbs++;
+
+       return cls_sess;
+}
+
+static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
+{
+       struct iscsi_session *sess;
+       struct ddb_entry *ddb_entry;
+       struct scsi_qla_host *ha;
+       unsigned long flags;
+
+       DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
+       sess = cls_sess->dd_data;
+       ddb_entry = sess->dd_data;
+       ha = ddb_entry->ha;
+
+       qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
+
+       spin_lock_irqsave(&ha->hardware_lock, flags);
+       qla4xxx_free_ddb(ha, ddb_entry);
+       spin_unlock_irqrestore(&ha->hardware_lock, flags);
+       iscsi_session_teardown(cls_sess);
+}
+
+static struct iscsi_cls_conn *
+qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
+{
+       struct iscsi_cls_conn *cls_conn;
+       struct iscsi_session *sess;
+       struct ddb_entry *ddb_entry;
+
+       DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
+       cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
+                                   conn_idx);
+       sess = cls_sess->dd_data;
+       ddb_entry = sess->dd_data;
+       ddb_entry->conn = cls_conn;
+
+       return cls_conn;
+}
+
+static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
+                            struct iscsi_cls_conn *cls_conn,
+                            uint64_t transport_fd, int is_leading)
+{
+       struct iscsi_conn *conn;
+       struct qla_conn *qla_conn;
+       struct iscsi_endpoint *ep;
+
+       DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
+
+       if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
+               return -EINVAL;
+       ep = iscsi_lookup_endpoint(transport_fd);
+       conn = cls_conn->dd_data;
+       qla_conn = conn->dd_data;
+       qla_conn->qla_ep = ep->dd_data;
+       return 0;
+}
+
+static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
+{
+       struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
+       struct iscsi_session *sess;
+       struct ddb_entry *ddb_entry;
+       struct scsi_qla_host *ha;
+       struct dev_db_entry *fw_ddb_entry;
+       dma_addr_t fw_ddb_entry_dma;
+       uint32_t mbx_sts = 0;
        int ret = 0;
+       int status = QLA_SUCCESS;
 
-       ha = (struct scsi_qla_host *) shost->hostdata;
+       DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
+       sess = cls_sess->dd_data;
+       ddb_entry = sess->dd_data;
+       ha = ddb_entry->ha;
 
-       switch (type) {
-       case ISCSI_TGT_DSCVR_SEND_TARGETS:
-               if (dst_addr->sa_family == AF_INET) {
-                       addr = (struct sockaddr_in *)dst_addr;
-                       if (qla4xxx_send_tgts(ha, (char *)&addr->sin_addr,
-                                             addr->sin_port) != QLA_SUCCESS)
-                               ret = -EIO;
-               } else if (dst_addr->sa_family == AF_INET6) {
-                       /*
-                        * TODO: fix qla4xxx_send_tgts
-                        */
-                       addr6 = (struct sockaddr_in6 *)dst_addr;
-                       if (qla4xxx_send_tgts(ha, (char *)&addr6->sin6_addr,
-                                             addr6->sin6_port) != QLA_SUCCESS)
-                               ret = -EIO;
-               } else
-                       ret = -ENOSYS;
-               break;
-       default:
-               ret = -ENOSYS;
+       fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
+                                         &fw_ddb_entry_dma, GFP_KERNEL);
+       if (!fw_ddb_entry) {
+               ql4_printk(KERN_ERR, ha,
+                          "%s: Unable to allocate dma buffer\n", __func__);
+               return -ENOMEM;
+       }
+
+       ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
+       if (ret) {
+               /* If iscsid is stopped and started then no need to do
+               * set param again since ddb state will be already
+               * active and FW does not allow set ddb to an
+               * active session.
+               */
+               if (mbx_sts)
+                       if (ddb_entry->fw_ddb_device_state ==
+                                               DDB_DS_SESSION_ACTIVE) {
+                               iscsi_conn_start(ddb_entry->conn);
+                               iscsi_conn_login_event(ddb_entry->conn,
+                                               ISCSI_CONN_STATE_LOGGED_IN);
+                               goto exit_set_param;
+                       }
+
+               ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
+                          __func__, ddb_entry->fw_ddb_index);
+               goto exit_conn_start;
        }
+
+       status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
+       if (status == QLA_ERROR) {
+               ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
+                          sess->targetname);
+               ret = -EINVAL;
+               goto exit_conn_start;
+       }
+
+       if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE)
+               ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
+
+       DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__,
+                     ddb_entry->fw_ddb_device_state));
+
+exit_set_param:
+       ret = 0;
+
+exit_conn_start:
+       dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
+                         fw_ddb_entry, fw_ddb_entry_dma);
        return ret;
 }
 
-void qla4xxx_destroy_sess(struct ddb_entry *ddb_entry)
+static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
 {
-       if (!ddb_entry->sess)
-               return;
+       struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
+       struct iscsi_session *sess;
+       struct scsi_qla_host *ha;
+       struct ddb_entry *ddb_entry;
+       int options;
 
-       if (ddb_entry->conn) {
-               atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
-               iscsi_remove_session(ddb_entry->sess);
+       DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
+       sess = cls_sess->dd_data;
+       ddb_entry = sess->dd_data;
+       ha = ddb_entry->ha;
+
+       options = LOGOUT_OPTION_CLOSE_SESSION;
+       if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
+               ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
+}
+
+static void qla4xxx_task_work(struct work_struct *wdata)
+{
+       struct ql4_task_data *task_data;
+       struct scsi_qla_host *ha;
+       struct passthru_status *sts;
+       struct iscsi_task *task;
+       struct iscsi_hdr *hdr;
+       uint8_t *data;
+       uint32_t data_len;
+       struct iscsi_conn *conn;
+       int hdr_len;
+       itt_t itt;
+
+       task_data = container_of(wdata, struct ql4_task_data, task_work);
+       ha = task_data->ha;
+       task = task_data->task;
+       sts = &task_data->sts;
+       hdr_len = sizeof(struct iscsi_hdr);
+
+       DEBUG3(printk(KERN_INFO "Status returned\n"));
+       DEBUG3(qla4xxx_dump_buffer(sts, 64));
+       DEBUG3(printk(KERN_INFO "Response buffer"));
+       DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
+
+       conn = task->conn;
+
+       switch (sts->completionStatus) {
+       case PASSTHRU_STATUS_COMPLETE:
+               hdr = (struct iscsi_hdr *)task_data->resp_buffer;
+               /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
+               itt = sts->handle;
+               hdr->itt = itt;
+               data = task_data->resp_buffer + hdr_len;
+               data_len = task_data->resp_len - hdr_len;
+               iscsi_complete_pdu(conn, hdr, data, data_len);
+               break;
+       default:
+               ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
+                          sts->completionStatus);
+               break;
        }
-       iscsi_free_session(ddb_entry->sess);
+       return;
 }
 
-int qla4xxx_add_sess(struct ddb_entry *ddb_entry)
+static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
 {
-       int err;
+       struct ql4_task_data *task_data;
+       struct iscsi_session *sess;
+       struct ddb_entry *ddb_entry;
+       struct scsi_qla_host *ha;
+       int hdr_len;
 
-       ddb_entry->sess->recovery_tmo = ql4xsess_recovery_tmo;
+       sess = task->conn->session;
+       ddb_entry = sess->dd_data;
+       ha = ddb_entry->ha;
+       task_data = task->dd_data;
+       memset(task_data, 0, sizeof(struct ql4_task_data));
 
-       err = iscsi_add_session(ddb_entry->sess, ddb_entry->fw_ddb_index);
-       if (err) {
-               DEBUG2(printk(KERN_ERR "Could not add session.\n"));
-               return err;
+       if (task->sc) {
+               ql4_printk(KERN_INFO, ha,
+                          "%s: SCSI Commands not implemented\n", __func__);
+               return -EINVAL;
        }
 
-       ddb_entry->conn = iscsi_create_conn(ddb_entry->sess, 0, 0);
-       if (!ddb_entry->conn) {
-               iscsi_remove_session(ddb_entry->sess);
-               DEBUG2(printk(KERN_ERR "Could not add connection.\n"));
-               return -ENOMEM;
+       hdr_len = sizeof(struct iscsi_hdr);
+       task_data->ha = ha;
+       task_data->task = task;
+
+       if (task->data_count) {
+               task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
+                                                    task->data_count,
+                                                    PCI_DMA_TODEVICE);
        }
 
-       /* finally ready to go */
-       iscsi_unblock_session(ddb_entry->sess);
+       DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
+                     __func__, task->conn->max_recv_dlength, hdr_len));
+
+       task_data->resp_len = task->conn->max_recv_dlength + hdr_len;
+       task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
+                                                   task_data->resp_len,
+                                                   &task_data->resp_dma,
+                                                   GFP_ATOMIC);
+       if (!task_data->resp_buffer)
+               goto exit_alloc_pdu;
+
+       task_data->req_len = task->data_count + hdr_len;
+       task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
+                                                  task_data->req_len,
+                                                  &task_data->req_dma,
+                                                  GFP_ATOMIC);
+       if (!task_data->req_buffer)
+               goto exit_alloc_pdu;
+
+       task->hdr = task_data->req_buffer;
+
+       INIT_WORK(&task_data->task_work, qla4xxx_task_work);
+
        return 0;
+
+exit_alloc_pdu:
+       if (task_data->resp_buffer)
+               dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
+                                 task_data->resp_buffer, task_data->resp_dma);
+
+       if (task_data->req_buffer)
+               dma_free_coherent(&ha->pdev->dev, task_data->req_len,
+                                 task_data->req_buffer, task_data->req_dma);
+       return -ENOMEM;
 }
 
-struct ddb_entry *qla4xxx_alloc_sess(struct scsi_qla_host *ha)
+static void qla4xxx_task_cleanup(struct iscsi_task *task)
 {
+       struct ql4_task_data *task_data;
+       struct iscsi_session *sess;
        struct ddb_entry *ddb_entry;
-       struct iscsi_cls_session *sess;
-
-       sess = iscsi_alloc_session(ha->host, &qla4xxx_iscsi_transport,
-                                  sizeof(struct ddb_entry));
-       if (!sess)
-               return NULL;
+       struct scsi_qla_host *ha;
+       int hdr_len;
 
+       hdr_len = sizeof(struct iscsi_hdr);
+       sess = task->conn->session;
        ddb_entry = sess->dd_data;
-       memset(ddb_entry, 0, sizeof(*ddb_entry));
-       ddb_entry->ha = ha;
-       ddb_entry->sess = sess;
-       return ddb_entry;
+       ha = ddb_entry->ha;
+       task_data = task->dd_data;
+
+       if (task->data_count) {
+               dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
+                                task->data_count, PCI_DMA_TODEVICE);
+       }
+
+       DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
+                     __func__, task->conn->max_recv_dlength, hdr_len));
+
+       dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
+                         task_data->resp_buffer, task_data->resp_dma);
+       dma_free_coherent(&ha->pdev->dev, task_data->req_len,
+                         task_data->req_buffer, task_data->req_dma);
+       return;
 }
 
-static void qla4xxx_scan_start(struct Scsi_Host *shost)
+static int qla4xxx_task_xmit(struct iscsi_task *task)
 {
-       struct scsi_qla_host *ha = shost_priv(shost);
-       struct ddb_entry *ddb_entry, *ddbtemp;
+       struct scsi_cmnd *sc = task->sc;
+       struct iscsi_session *sess = task->conn->session;
+       struct ddb_entry *ddb_entry = sess->dd_data;
+       struct scsi_qla_host *ha = ddb_entry->ha;
+
+       if (!sc)
+               return qla4xxx_send_passthru0(task);
+
+       ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
+                  __func__);
+       return -ENOSYS;
+}
 
-       /* finish setup of sessions that were already setup in firmware */
-       list_for_each_entry_safe(ddb_entry, ddbtemp, &ha->ddb_list, list) {
-               if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE)
-                       qla4xxx_add_sess(ddb_entry);
+void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
+                                      struct ddb_entry *ddb_entry)
+{
+       struct iscsi_cls_session *cls_sess;
+       struct iscsi_cls_conn *cls_conn;
+       struct iscsi_session *sess;
+       struct iscsi_conn *conn;
+       uint32_t ddb_state;
+       dma_addr_t fw_ddb_entry_dma;
+       struct dev_db_entry *fw_ddb_entry;
+
+       fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
+                                         &fw_ddb_entry_dma, GFP_KERNEL);
+       if (!fw_ddb_entry) {
+               ql4_printk(KERN_ERR, ha,
+                          "%s: Unable to allocate dma buffer\n", __func__);
+               return;
+       }
+
+       if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
+                                   fw_ddb_entry_dma, NULL, NULL, &ddb_state,
+                                   NULL, NULL, NULL) == QLA_ERROR) {
+               DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
+                                 "get_ddb_entry for fw_ddb_index %d\n",
+                                 ha->host_no, __func__,
+                                 ddb_entry->fw_ddb_index));
+               return;
        }
+
+       cls_sess = ddb_entry->sess;
+       sess = cls_sess->dd_data;
+
+       cls_conn = ddb_entry->conn;
+       conn = cls_conn->dd_data;
+
+       /* Update params */
+       conn->max_recv_dlength = BYTE_UNITS *
+                         le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
+
+       conn->max_xmit_dlength = BYTE_UNITS *
+                         le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
+
+       sess->initial_r2t_en =
+                           (BIT_10 & le16_to_cpu(fw_ddb_entry->iscsi_options));
+
+       sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
+
+       sess->imm_data_en = (BIT_11 & le16_to_cpu(fw_ddb_entry->iscsi_options));
+
+       sess->first_burst = BYTE_UNITS *
+                              le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
+
+       sess->max_burst = BYTE_UNITS *
+                                le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
+
+       sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
+
+       sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
+
+       sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
+
+       memcpy(sess->initiatorname, ha->name_string,
+              min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
 }
 
 /*
@@ -376,25 +1433,15 @@ static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
 }
 
 /***
- * qla4xxx_mark_device_missing - mark a device as missing.
- * @ha: Pointer to host adapter structure.
+ * qla4xxx_mark_device_missing - blocks the session
+ * @cls_session: Pointer to the session to be blocked
  * @ddb_entry: Pointer to device database entry
  *
  * This routine marks a device missing and close connection.
  **/
-void qla4xxx_mark_device_missing(struct scsi_qla_host *ha,
-                                struct ddb_entry *ddb_entry)
+void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
 {
-       if ((atomic_read(&ddb_entry->state) != DDB_STATE_DEAD)) {
-               atomic_set(&ddb_entry->state, DDB_STATE_MISSING);
-               DEBUG2(printk("scsi%ld: ddb [%d] marked MISSING\n",
-                   ha->host_no, ddb_entry->fw_ddb_index));
-       } else
-               DEBUG2(printk("scsi%ld: ddb [%d] DEAD\n", ha->host_no,
-                   ddb_entry->fw_ddb_index))
-
-       iscsi_block_session(ddb_entry->sess);
-       iscsi_conn_error_event(ddb_entry->conn, ISCSI_ERR_CONN_FAILED);
+       iscsi_block_session(cls_session);
 }
 
 /**
@@ -405,10 +1452,7 @@ void qla4xxx_mark_device_missing(struct scsi_qla_host *ha,
  **/
 void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
 {
-       struct ddb_entry *ddb_entry, *ddbtemp;
-       list_for_each_entry_safe(ddb_entry, ddbtemp, &ha->ddb_list, list) {
-               qla4xxx_mark_device_missing(ha, ddb_entry);
-       }
+       iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
 }
 
 static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
@@ -495,20 +1539,13 @@ static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
                goto qc_fail_command;
        }
 
-       if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
-               if (atomic_read(&ddb_entry->state) == DDB_STATE_DEAD) {
-                       cmd->result = DID_NO_CONNECT << 16;
-                       goto qc_fail_command;
-               }
-               return SCSI_MLQUEUE_TARGET_BUSY;
-       }
-
        if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
            test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
            test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
            test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
            test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
            !test_bit(AF_ONLINE, &ha->flags) ||
+           !test_bit(AF_LINK_UP, &ha->flags) ||
            test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
                goto qc_host_busy;
 
@@ -563,6 +1600,13 @@ static void qla4xxx_mem_free(struct scsi_qla_host *ha)
 
        ha->srb_mempool = NULL;
 
+       if (ha->chap_dma_pool)
+               dma_pool_destroy(ha->chap_dma_pool);
+
+       if (ha->chap_list)
+               vfree(ha->chap_list);
+       ha->chap_list = NULL;
+
        /* release io space registers  */
        if (is_qla8022(ha)) {
                if (ha->nx_pcibase)
@@ -636,6 +1680,15 @@ static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
                goto mem_alloc_error_exit;
        }
 
+       ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
+                                           CHAP_DMA_BLOCK_SIZE, 8, 0);
+
+       if (ha->chap_dma_pool == NULL) {
+               ql4_printk(KERN_WARNING, ha,
+                   "%s: chap_dma_pool allocation failed..\n", __func__);
+               goto mem_alloc_error_exit;
+       }
+
        return QLA_SUCCESS;
 
 mem_alloc_error_exit:
@@ -753,7 +1806,6 @@ void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
  **/
 static void qla4xxx_timer(struct scsi_qla_host *ha)
 {
-       struct ddb_entry *ddb_entry, *dtemp;
        int start_dpc = 0;
        uint16_t w;
 
@@ -767,73 +1819,10 @@ static void qla4xxx_timer(struct scsi_qla_host *ha)
 
        /* Hardware read to trigger an EEH error during mailbox waits. */
        if (!pci_channel_offline(ha->pdev))
-               pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
-
-       if (is_qla8022(ha)) {
-               qla4_8xxx_watchdog(ha);
-       }
-
-       /* Search for relogin's to time-out and port down retry. */
-       list_for_each_entry_safe(ddb_entry, dtemp, &ha->ddb_list, list) {
-               /* Count down time between sending relogins */
-               if (adapter_up(ha) &&
-                   !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
-                   atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
-                       if (atomic_read(&ddb_entry->retry_relogin_timer) !=
-                           INVALID_ENTRY) {
-                               if (atomic_read(&ddb_entry->retry_relogin_timer)
-                                               == 0) {
-                                       atomic_set(&ddb_entry->
-                                               retry_relogin_timer,
-                                               INVALID_ENTRY);
-                                       set_bit(DPC_RELOGIN_DEVICE,
-                                               &ha->dpc_flags);
-                                       set_bit(DF_RELOGIN, &ddb_entry->flags);
-                                       DEBUG2(printk("scsi%ld: %s: ddb [%d]"
-                                                     " login device\n",
-                                                     ha->host_no, __func__,
-                                                     ddb_entry->fw_ddb_index));
-                               } else
-                                       atomic_dec(&ddb_entry->
-                                                       retry_relogin_timer);
-                       }
-               }
-
-               /* Wait for relogin to timeout */
-               if (atomic_read(&ddb_entry->relogin_timer) &&
-                   (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
-                       /*
-                        * If the relogin times out and the device is
-                        * still NOT ONLINE then try and relogin again.
-                        */
-                       if (atomic_read(&ddb_entry->state) !=
-                           DDB_STATE_ONLINE &&
-                           ddb_entry->fw_ddb_device_state ==
-                           DDB_DS_SESSION_FAILED) {
-                               /* Reset retry relogin timer */
-                               atomic_inc(&ddb_entry->relogin_retry_count);
-                               DEBUG2(printk("scsi%ld: ddb [%d] relogin"
-                                             " timed out-retrying"
-                                             " relogin (%d)\n",
-                                             ha->host_no,
-                                             ddb_entry->fw_ddb_index,
-                                             atomic_read(&ddb_entry->
-                                                         relogin_retry_count))
-                                       );
-                               start_dpc++;
-                               DEBUG(printk("scsi%ld:%d:%d: ddb [%d] "
-                                            "initiate relogin after"
-                                            " %d seconds\n",
-                                            ha->host_no, ddb_entry->bus,
-                                            ddb_entry->target,
-                                            ddb_entry->fw_ddb_index,
-                                            ddb_entry->default_time2wait + 4)
-                                       );
-
-                               atomic_set(&ddb_entry->retry_relogin_timer,
-                                          ddb_entry->default_time2wait + 4);
-                       }
-               }
+               pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
+
+       if (is_qla8022(ha)) {
+               qla4_8xxx_watchdog(ha);
        }
 
        if (!is_qla8022(ha)) {
@@ -1081,6 +2070,17 @@ void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
        clear_bit(AF_INIT_DONE, &ha->flags);
 }
 
+static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
+{
+       struct iscsi_session *sess;
+       struct ddb_entry *ddb_entry;
+
+       sess = cls_session->dd_data;
+       ddb_entry = sess->dd_data;
+       ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
+       iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED);
+}
+
 /**
  * qla4xxx_recover_adapter - recovers adapter after a fatal error
  * @ha: Pointer to host adapter structure.
@@ -1093,11 +2093,14 @@ static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
        /* Stall incoming I/O until we are done */
        scsi_block_requests(ha->host);
        clear_bit(AF_ONLINE, &ha->flags);
+       clear_bit(AF_LINK_UP, &ha->flags);
 
        DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
 
        set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
 
+       iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
+
        if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
                reset_chip = 1;
 
@@ -1160,7 +2163,7 @@ recover_ha_init_adapter:
 
                /* NOTE: AF_ONLINE flag set upon successful completion of
                 *       qla4xxx_initialize_adapter */
-               status = qla4xxx_initialize_adapter(ha, PRESERVE_DDB_LIST);
+               status = qla4xxx_initialize_adapter(ha);
        }
 
        /* Retry failed adapter initialization, if necessary
@@ -1225,27 +2228,34 @@ recover_ha_init_adapter:
        return status;
 }
 
-static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
+static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
 {
-       struct ddb_entry *ddb_entry, *dtemp;
+       struct iscsi_session *sess;
+       struct ddb_entry *ddb_entry;
+       struct scsi_qla_host *ha;
 
-       list_for_each_entry_safe(ddb_entry, dtemp, &ha->ddb_list, list) {
-               if ((atomic_read(&ddb_entry->state) == DDB_STATE_MISSING) ||
-                   (atomic_read(&ddb_entry->state) == DDB_STATE_DEAD)) {
-                       if (ddb_entry->fw_ddb_device_state ==
-                           DDB_DS_SESSION_ACTIVE) {
-                               atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
-                               ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
-                                   " marked ONLINE\n", ha->host_no, __func__,
-                                   ddb_entry->fw_ddb_index);
-
-                               iscsi_unblock_session(ddb_entry->sess);
-                       } else
-                               qla4xxx_relogin_device(ha, ddb_entry);
+       sess = cls_session->dd_data;
+       ddb_entry = sess->dd_data;
+       ha = ddb_entry->ha;
+       if (!iscsi_is_session_online(cls_session)) {
+               if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
+                       ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
+                                  " unblock session\n", ha->host_no, __func__,
+                                  ddb_entry->fw_ddb_index);
+                       iscsi_unblock_session(ddb_entry->sess);
+               } else {
+                       /* Trigger relogin */
+                       iscsi_session_failure(cls_session->dd_data,
+                                             ISCSI_ERR_CONN_FAILED);
                }
        }
 }
 
+static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
+{
+       iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
+}
+
 void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
 {
        if (ha->dpc_thread)
@@ -1267,7 +2277,6 @@ static void qla4xxx_do_dpc(struct work_struct *work)
 {
        struct scsi_qla_host *ha =
                container_of(work, struct scsi_qla_host, dpc_work);
-       struct ddb_entry *ddb_entry, *dtemp;
        int status = QLA_ERROR;
 
        DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
@@ -1363,31 +2372,6 @@ dpc_post_reset_ha:
                        qla4xxx_relogin_all_devices(ha);
                }
        }
-
-       /* ---- relogin device? --- */
-       if (adapter_up(ha) &&
-           test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
-               list_for_each_entry_safe(ddb_entry, dtemp,
-                                        &ha->ddb_list, list) {
-                       if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
-                           atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)
-                               qla4xxx_relogin_device(ha, ddb_entry);
-
-                       /*
-                        * If mbx cmd times out there is no point
-                        * in continuing further.
-                        * With large no of targets this can hang
-                        * the system.
-                        */
-                       if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
-                               printk(KERN_WARNING "scsi%ld: %s: "
-                                      "need to reset hba\n",
-                                      ha->host_no, __func__);
-                               break;
-                       }
-               }
-       }
-
 }
 
 /**
@@ -1410,6 +2394,10 @@ static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
        if (ha->dpc_thread)
                destroy_workqueue(ha->dpc_thread);
 
+       /* Kill the kernel thread for this host */
+       if (ha->task_wq)
+               destroy_workqueue(ha->task_wq);
+
        /* Put firmware in known state */
        ha->isp_ops->reset_firmware(ha);
 
@@ -1462,143 +2450,731 @@ int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
                goto iospace_error_exit;
        }
 
-       /* Mapping of IO base pointer, door bell read and write pointer */
+       /* Mapping of IO base pointer, door bell read and write pointer */
+
+       /* mapping of IO base pointer */
+       ha->qla4_8xxx_reg =
+           (struct device_reg_82xx  __iomem *)((uint8_t *)ha->nx_pcibase +
+           0xbc000 + (ha->pdev->devfn << 11));
+
+       db_base = pci_resource_start(pdev, 4);  /* doorbell is on bar 4 */
+       db_len = pci_resource_len(pdev, 4);
+
+       ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
+           QLA82XX_CAM_RAM_DB2);
+
+       return 0;
+iospace_error_exit:
+       return -ENOMEM;
+}
+
+/***
+ * qla4xxx_iospace_config - maps registers
+ * @ha: pointer to adapter structure
+ *
+ * This routines maps HBA's registers from the pci address space
+ * into the kernel virtual address space for memory mapped i/o.
+ **/
+int qla4xxx_iospace_config(struct scsi_qla_host *ha)
+{
+       unsigned long pio, pio_len, pio_flags;
+       unsigned long mmio, mmio_len, mmio_flags;
+
+       pio = pci_resource_start(ha->pdev, 0);
+       pio_len = pci_resource_len(ha->pdev, 0);
+       pio_flags = pci_resource_flags(ha->pdev, 0);
+       if (pio_flags & IORESOURCE_IO) {
+               if (pio_len < MIN_IOBASE_LEN) {
+                       ql4_printk(KERN_WARNING, ha,
+                               "Invalid PCI I/O region size\n");
+                       pio = 0;
+               }
+       } else {
+               ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
+               pio = 0;
+       }
+
+       /* Use MMIO operations for all accesses. */
+       mmio = pci_resource_start(ha->pdev, 1);
+       mmio_len = pci_resource_len(ha->pdev, 1);
+       mmio_flags = pci_resource_flags(ha->pdev, 1);
+
+       if (!(mmio_flags & IORESOURCE_MEM)) {
+               ql4_printk(KERN_ERR, ha,
+                   "region #0 not an MMIO resource, aborting\n");
+
+               goto iospace_error_exit;
+       }
+
+       if (mmio_len < MIN_IOBASE_LEN) {
+               ql4_printk(KERN_ERR, ha,
+                   "Invalid PCI mem region size, aborting\n");
+               goto iospace_error_exit;
+       }
+
+       if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
+               ql4_printk(KERN_WARNING, ha,
+                   "Failed to reserve PIO/MMIO regions\n");
+
+               goto iospace_error_exit;
+       }
+
+       ha->pio_address = pio;
+       ha->pio_length = pio_len;
+       ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
+       if (!ha->reg) {
+               ql4_printk(KERN_ERR, ha,
+                   "cannot remap MMIO, aborting\n");
+
+               goto iospace_error_exit;
+       }
+
+       return 0;
+
+iospace_error_exit:
+       return -ENOMEM;
+}
+
+static struct isp_operations qla4xxx_isp_ops = {
+       .iospace_config         = qla4xxx_iospace_config,
+       .pci_config             = qla4xxx_pci_config,
+       .disable_intrs          = qla4xxx_disable_intrs,
+       .enable_intrs           = qla4xxx_enable_intrs,
+       .start_firmware         = qla4xxx_start_firmware,
+       .intr_handler           = qla4xxx_intr_handler,
+       .interrupt_service_routine = qla4xxx_interrupt_service_routine,
+       .reset_chip             = qla4xxx_soft_reset,
+       .reset_firmware         = qla4xxx_hw_reset,
+       .queue_iocb             = qla4xxx_queue_iocb,
+       .complete_iocb          = qla4xxx_complete_iocb,
+       .rd_shdw_req_q_out      = qla4xxx_rd_shdw_req_q_out,
+       .rd_shdw_rsp_q_in       = qla4xxx_rd_shdw_rsp_q_in,
+       .get_sys_info           = qla4xxx_get_sys_info,
+};
+
+static struct isp_operations qla4_8xxx_isp_ops = {
+       .iospace_config         = qla4_8xxx_iospace_config,
+       .pci_config             = qla4_8xxx_pci_config,
+       .disable_intrs          = qla4_8xxx_disable_intrs,
+       .enable_intrs           = qla4_8xxx_enable_intrs,
+       .start_firmware         = qla4_8xxx_load_risc,
+       .intr_handler           = qla4_8xxx_intr_handler,
+       .interrupt_service_routine = qla4_8xxx_interrupt_service_routine,
+       .reset_chip             = qla4_8xxx_isp_reset,
+       .reset_firmware         = qla4_8xxx_stop_firmware,
+       .queue_iocb             = qla4_8xxx_queue_iocb,
+       .complete_iocb          = qla4_8xxx_complete_iocb,
+       .rd_shdw_req_q_out      = qla4_8xxx_rd_shdw_req_q_out,
+       .rd_shdw_rsp_q_in       = qla4_8xxx_rd_shdw_rsp_q_in,
+       .get_sys_info           = qla4_8xxx_get_sys_info,
+};
+
+uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
+{
+       return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
+}
+
+uint16_t qla4_8xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
+{
+       return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->req_q_out));
+}
+
+uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
+{
+       return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
+}
+
+uint16_t qla4_8xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
+{
+       return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->rsp_q_in));
+}
+
+static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
+{
+       struct scsi_qla_host *ha = data;
+       char *str = buf;
+       int rc;
+
+       switch (type) {
+       case ISCSI_BOOT_ETH_FLAGS:
+               rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
+               break;
+       case ISCSI_BOOT_ETH_INDEX:
+               rc = sprintf(str, "0\n");
+               break;
+       case ISCSI_BOOT_ETH_MAC:
+               rc = sysfs_format_mac(str, ha->my_mac,
+                                     MAC_ADDR_LEN);
+               break;
+       default:
+               rc = -ENOSYS;
+               break;
+       }
+       return rc;
+}
+
+static mode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
+{
+       int rc;
+
+       switch (type) {
+       case ISCSI_BOOT_ETH_FLAGS:
+       case ISCSI_BOOT_ETH_MAC:
+       case ISCSI_BOOT_ETH_INDEX:
+               rc = S_IRUGO;
+               break;
+       default:
+               rc = 0;
+               break;
+       }
+       return rc;
+}
+
+static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
+{
+       struct scsi_qla_host *ha = data;
+       char *str = buf;
+       int rc;
+
+       switch (type) {
+       case ISCSI_BOOT_INI_INITIATOR_NAME:
+               rc = sprintf(str, "%s\n", ha->name_string);
+               break;
+       default:
+               rc = -ENOSYS;
+               break;
+       }
+       return rc;
+}
+
+static mode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
+{
+       int rc;
+
+       switch (type) {
+       case ISCSI_BOOT_INI_INITIATOR_NAME:
+               rc = S_IRUGO;
+               break;
+       default:
+               rc = 0;
+               break;
+       }
+       return rc;
+}
+
+static ssize_t
+qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
+                          char *buf)
+{
+       struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
+       char *str = buf;
+       int rc;
+
+       switch (type) {
+       case ISCSI_BOOT_TGT_NAME:
+               rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
+               break;
+       case ISCSI_BOOT_TGT_IP_ADDR:
+               if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
+                       rc = sprintf(buf, "%pI4\n",
+                                    &boot_conn->dest_ipaddr.ip_address);
+               else
+                       rc = sprintf(str, "%pI6\n",
+                                    &boot_conn->dest_ipaddr.ip_address);
+               break;
+       case ISCSI_BOOT_TGT_PORT:
+                       rc = sprintf(str, "%d\n", boot_conn->dest_port);
+               break;
+       case ISCSI_BOOT_TGT_CHAP_NAME:
+               rc = sprintf(str,  "%.*s\n",
+                            boot_conn->chap.target_chap_name_length,
+                            (char *)&boot_conn->chap.target_chap_name);
+               break;
+       case ISCSI_BOOT_TGT_CHAP_SECRET:
+               rc = sprintf(str,  "%.*s\n",
+                            boot_conn->chap.target_secret_length,
+                            (char *)&boot_conn->chap.target_secret);
+               break;
+       case ISCSI_BOOT_TGT_REV_CHAP_NAME:
+               rc = sprintf(str,  "%.*s\n",
+                            boot_conn->chap.intr_chap_name_length,
+                            (char *)&boot_conn->chap.intr_chap_name);
+               break;
+       case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
+               rc = sprintf(str,  "%.*s\n",
+                            boot_conn->chap.intr_secret_length,
+                            (char *)&boot_conn->chap.intr_secret);
+               break;
+       case ISCSI_BOOT_TGT_FLAGS:
+               rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
+               break;
+       case ISCSI_BOOT_TGT_NIC_ASSOC:
+               rc = sprintf(str, "0\n");
+               break;
+       default:
+               rc = -ENOSYS;
+               break;
+       }
+       return rc;
+}
+
+static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
+{
+       struct scsi_qla_host *ha = data;
+       struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
+
+       return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
+}
+
+static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
+{
+       struct scsi_qla_host *ha = data;
+       struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
+
+       return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
+}
+
+static mode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
+{
+       int rc;
+
+       switch (type) {
+       case ISCSI_BOOT_TGT_NAME:
+       case ISCSI_BOOT_TGT_IP_ADDR:
+       case ISCSI_BOOT_TGT_PORT:
+       case ISCSI_BOOT_TGT_CHAP_NAME:
+       case ISCSI_BOOT_TGT_CHAP_SECRET:
+       case ISCSI_BOOT_TGT_REV_CHAP_NAME:
+       case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
+       case ISCSI_BOOT_TGT_NIC_ASSOC:
+       case ISCSI_BOOT_TGT_FLAGS:
+               rc = S_IRUGO;
+               break;
+       default:
+               rc = 0;
+               break;
+       }
+       return rc;
+}
+
+static void qla4xxx_boot_release(void *data)
+{
+       struct scsi_qla_host *ha = data;
+
+       scsi_host_put(ha->host);
+}
+
+static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
+{
+       dma_addr_t buf_dma;
+       uint32_t addr, pri_addr, sec_addr;
+       uint32_t offset;
+       uint16_t func_num;
+       uint8_t val;
+       uint8_t *buf = NULL;
+       size_t size = 13 * sizeof(uint8_t);
+       int ret = QLA_SUCCESS;
+
+       func_num = PCI_FUNC(ha->pdev->devfn);
+
+       ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
+                  __func__, ha->pdev->device, func_num);
+
+       if (is_qla40XX(ha)) {
+               if (func_num == 1) {
+                       addr = NVRAM_PORT0_BOOT_MODE;
+                       pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
+                       sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
+               } else if (func_num == 3) {
+                       addr = NVRAM_PORT1_BOOT_MODE;
+                       pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
+                       sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
+               } else {
+                       ret = QLA_ERROR;
+                       goto exit_boot_info;
+               }
+
+               /* Check Boot Mode */
+               val = rd_nvram_byte(ha, addr);
+               if (!(val & 0x07)) {
+                       DEBUG2(ql4_printk(KERN_ERR, ha,
+                                         "%s: Failed Boot options : 0x%x\n",
+                                         __func__, val));
+                       ret = QLA_ERROR;
+                       goto exit_boot_info;
+               }
 
-       /* mapping of IO base pointer */
-       ha->qla4_8xxx_reg =
-           (struct device_reg_82xx  __iomem *)((uint8_t *)ha->nx_pcibase +
-           0xbc000 + (ha->pdev->devfn << 11));
+               /* get primary valid target index */
+               val = rd_nvram_byte(ha, pri_addr);
+               if (val & BIT_7)
+                       ddb_index[0] = (val & 0x7f);
+
+               /* get secondary valid target index */
+               val = rd_nvram_byte(ha, sec_addr);
+               if (val & BIT_7)
+                       ddb_index[1] = (val & 0x7f);
+
+       } else if (is_qla8022(ha)) {
+               buf = dma_alloc_coherent(&ha->pdev->dev, size,
+                                        &buf_dma, GFP_KERNEL);
+               if (!buf) {
+                       DEBUG2(ql4_printk(KERN_ERR, ha,
+                                         "%s: Unable to allocate dma buffer\n",
+                                          __func__));
+                       ret = QLA_ERROR;
+                       goto exit_boot_info;
+               }
 
-       db_base = pci_resource_start(pdev, 4);  /* doorbell is on bar 4 */
-       db_len = pci_resource_len(pdev, 4);
+               if (ha->port_num == 0)
+                       offset = BOOT_PARAM_OFFSET_PORT0;
+               else if (ha->port_num == 1)
+                       offset = BOOT_PARAM_OFFSET_PORT1;
+               else {
+                       ret = QLA_ERROR;
+                       goto exit_boot_info_free;
+               }
+               addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
+                      offset;
+               if (qla4xxx_get_flash(ha, buf_dma, addr,
+                                     13 * sizeof(uint8_t)) != QLA_SUCCESS) {
+                       DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
+                                         "failed\n", ha->host_no, __func__));
+                       ret = QLA_ERROR;
+                       goto exit_boot_info_free;
+               }
+               /* Check Boot Mode */
+               if (!(buf[1] & 0x07)) {
+                       DEBUG2(ql4_printk(KERN_INFO, ha,
+                                         "Failed: Boot options : 0x%x\n",
+                                         buf[1]));
+                       ret = QLA_ERROR;
+                       goto exit_boot_info_free;
+               }
 
-       ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
-           QLA82XX_CAM_RAM_DB2);
+               /* get primary valid target index */
+               if (buf[2] & BIT_7)
+                       ddb_index[0] = buf[2] & 0x7f;
 
-       return 0;
-iospace_error_exit:
-       return -ENOMEM;
+               /* get secondary valid target index */
+               if (buf[11] & BIT_7)
+                       ddb_index[1] = buf[11] & 0x7f;
+       } else {
+               ret = QLA_ERROR;
+               goto exit_boot_info;
+       }
+
+       DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
+                         " target ID %d\n", __func__, ddb_index[0],
+                         ddb_index[1]));
+
+exit_boot_info_free:
+       dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
+exit_boot_info:
+       return ret;
 }
 
-/***
- * qla4xxx_iospace_config - maps registers
+/**
+ * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
  * @ha: pointer to adapter structure
+ * @username: CHAP username to be returned
+ * @password: CHAP password to be returned
  *
- * This routines maps HBA's registers from the pci address space
- * into the kernel virtual address space for memory mapped i/o.
+ * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
+ * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
+ * So from the CHAP cache find the first BIDI CHAP entry and set it
+ * to the boot record in sysfs.
  **/
-int qla4xxx_iospace_config(struct scsi_qla_host *ha)
+static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
+                           char *password)
 {
-       unsigned long pio, pio_len, pio_flags;
-       unsigned long mmio, mmio_len, mmio_flags;
+       int i, ret = -EINVAL;
+       int max_chap_entries = 0;
+       struct ql4_chap_table *chap_table;
 
-       pio = pci_resource_start(ha->pdev, 0);
-       pio_len = pci_resource_len(ha->pdev, 0);
-       pio_flags = pci_resource_flags(ha->pdev, 0);
-       if (pio_flags & IORESOURCE_IO) {
-               if (pio_len < MIN_IOBASE_LEN) {
-                       ql4_printk(KERN_WARNING, ha,
-                               "Invalid PCI I/O region size\n");
-                       pio = 0;
+       if (is_qla8022(ha))
+               max_chap_entries = (ha->hw.flt_chap_size / 2) /
+                                               sizeof(struct ql4_chap_table);
+       else
+               max_chap_entries = MAX_CHAP_ENTRIES_40XX;
+
+       if (!ha->chap_list) {
+               ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
+               return ret;
+       }
+
+       mutex_lock(&ha->chap_sem);
+       for (i = 0; i < max_chap_entries; i++) {
+               chap_table = (struct ql4_chap_table *)ha->chap_list + i;
+               if (chap_table->cookie !=
+                   __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
+                       continue;
                }
-       } else {
-               ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
-               pio = 0;
+
+               if (chap_table->flags & BIT_7) /* local */
+                       continue;
+
+               if (!(chap_table->flags & BIT_6)) /* Not BIDI */
+                       continue;
+
+               strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
+               strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
+               ret = 0;
+               break;
        }
+       mutex_unlock(&ha->chap_sem);
 
-       /* Use MMIO operations for all accesses. */
-       mmio = pci_resource_start(ha->pdev, 1);
-       mmio_len = pci_resource_len(ha->pdev, 1);
-       mmio_flags = pci_resource_flags(ha->pdev, 1);
+       return ret;
+}
 
-       if (!(mmio_flags & IORESOURCE_MEM)) {
-               ql4_printk(KERN_ERR, ha,
-                   "region #0 not an MMIO resource, aborting\n");
 
-               goto iospace_error_exit;
+static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
+                                  struct ql4_boot_session_info *boot_sess,
+                                  uint16_t ddb_index)
+{
+       struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
+       struct dev_db_entry *fw_ddb_entry;
+       dma_addr_t fw_ddb_entry_dma;
+       uint16_t idx;
+       uint16_t options;
+       int ret = QLA_SUCCESS;
+
+       fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
+                                         &fw_ddb_entry_dma, GFP_KERNEL);
+       if (!fw_ddb_entry) {
+               DEBUG2(ql4_printk(KERN_ERR, ha,
+                                 "%s: Unable to allocate dma buffer.\n",
+                                 __func__));
+               ret = QLA_ERROR;
+               return ret;
        }
 
-       if (mmio_len < MIN_IOBASE_LEN) {
-               ql4_printk(KERN_ERR, ha,
-                   "Invalid PCI mem region size, aborting\n");
-               goto iospace_error_exit;
+       if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
+                                  fw_ddb_entry_dma, ddb_index)) {
+               DEBUG2(ql4_printk(KERN_ERR, ha,
+                                 "%s: Flash DDB read Failed\n", __func__));
+               ret = QLA_ERROR;
+               goto exit_boot_target;
        }
 
-       if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
-               ql4_printk(KERN_WARNING, ha,
-                   "Failed to reserve PIO/MMIO regions\n");
+       /* Update target name and IP from DDB */
+       memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
+              min(sizeof(boot_sess->target_name),
+                  sizeof(fw_ddb_entry->iscsi_name)));
 
-               goto iospace_error_exit;
+       options = le16_to_cpu(fw_ddb_entry->options);
+       if (options & DDB_OPT_IPV6_DEVICE) {
+               memcpy(&boot_conn->dest_ipaddr.ip_address,
+                      &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
+       } else {
+               boot_conn->dest_ipaddr.ip_type = 0x1;
+               memcpy(&boot_conn->dest_ipaddr.ip_address,
+                      &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
        }
 
-       ha->pio_address = pio;
-       ha->pio_length = pio_len;
-       ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
-       if (!ha->reg) {
-               ql4_printk(KERN_ERR, ha,
-                   "cannot remap MMIO, aborting\n");
+       boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
 
-               goto iospace_error_exit;
+       /* update chap information */
+       idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
+
+       if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options))   {
+
+               DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
+
+               ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
+                                      target_chap_name,
+                                      (char *)&boot_conn->chap.target_secret,
+                                      idx);
+               if (ret) {
+                       ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
+                       ret = QLA_ERROR;
+                       goto exit_boot_target;
+               }
+
+               boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
+               boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
        }
 
-       return 0;
+       if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
 
-iospace_error_exit:
-       return -ENOMEM;
-}
+               DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
 
-static struct isp_operations qla4xxx_isp_ops = {
-       .iospace_config         = qla4xxx_iospace_config,
-       .pci_config             = qla4xxx_pci_config,
-       .disable_intrs          = qla4xxx_disable_intrs,
-       .enable_intrs           = qla4xxx_enable_intrs,
-       .start_firmware         = qla4xxx_start_firmware,
-       .intr_handler           = qla4xxx_intr_handler,
-       .interrupt_service_routine = qla4xxx_interrupt_service_routine,
-       .reset_chip             = qla4xxx_soft_reset,
-       .reset_firmware         = qla4xxx_hw_reset,
-       .queue_iocb             = qla4xxx_queue_iocb,
-       .complete_iocb          = qla4xxx_complete_iocb,
-       .rd_shdw_req_q_out      = qla4xxx_rd_shdw_req_q_out,
-       .rd_shdw_rsp_q_in       = qla4xxx_rd_shdw_rsp_q_in,
-       .get_sys_info           = qla4xxx_get_sys_info,
-};
+               ret = qla4xxx_get_bidi_chap(ha,
+                                   (char *)&boot_conn->chap.intr_chap_name,
+                                   (char *)&boot_conn->chap.intr_secret);
 
-static struct isp_operations qla4_8xxx_isp_ops = {
-       .iospace_config         = qla4_8xxx_iospace_config,
-       .pci_config             = qla4_8xxx_pci_config,
-       .disable_intrs          = qla4_8xxx_disable_intrs,
-       .enable_intrs           = qla4_8xxx_enable_intrs,
-       .start_firmware         = qla4_8xxx_load_risc,
-       .intr_handler           = qla4_8xxx_intr_handler,
-       .interrupt_service_routine = qla4_8xxx_interrupt_service_routine,
-       .reset_chip             = qla4_8xxx_isp_reset,
-       .reset_firmware         = qla4_8xxx_stop_firmware,
-       .queue_iocb             = qla4_8xxx_queue_iocb,
-       .complete_iocb          = qla4_8xxx_complete_iocb,
-       .rd_shdw_req_q_out      = qla4_8xxx_rd_shdw_req_q_out,
-       .rd_shdw_rsp_q_in       = qla4_8xxx_rd_shdw_rsp_q_in,
-       .get_sys_info           = qla4_8xxx_get_sys_info,
-};
+               if (ret) {
+                       ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
+                       ret = QLA_ERROR;
+                       goto exit_boot_target;
+               }
 
-uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
-{
-       return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
+               boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
+               boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
+       }
+
+exit_boot_target:
+       dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
+                         fw_ddb_entry, fw_ddb_entry_dma);
+       return ret;
 }
 
-uint16_t qla4_8xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
+static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
 {
-       return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->req_q_out));
+       uint16_t ddb_index[2];
+       int ret = QLA_ERROR;
+       int rval;
+
+       memset(ddb_index, 0, sizeof(ddb_index));
+       ddb_index[0] = 0xffff;
+       ddb_index[1] = 0xffff;
+       ret = get_fw_boot_info(ha, ddb_index);
+       if (ret != QLA_SUCCESS) {
+               DEBUG2(ql4_printk(KERN_ERR, ha,
+                                 "%s: Failed to set boot info.\n", __func__));
+               return ret;
+       }
+
+       if (ddb_index[0] == 0xffff)
+               goto sec_target;
+
+       rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
+                                     ddb_index[0]);
+       if (rval != QLA_SUCCESS) {
+               DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Failed to get "
+                                 "primary target\n", __func__));
+       } else
+               ret = QLA_SUCCESS;
+
+sec_target:
+       if (ddb_index[1] == 0xffff)
+               goto exit_get_boot_info;
+
+       rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
+                                     ddb_index[1]);
+       if (rval != QLA_SUCCESS) {
+               DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Failed to get "
+                                 "secondary target\n", __func__));
+       } else
+               ret = QLA_SUCCESS;
+
+exit_get_boot_info:
+       return ret;
 }
 
-uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
+static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
 {
-       return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
+       struct iscsi_boot_kobj *boot_kobj;
+
+       if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
+               return 0;
+
+       ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
+       if (!ha->boot_kset)
+               goto kset_free;
+
+       if (!scsi_host_get(ha->host))
+               goto kset_free;
+       boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
+                                            qla4xxx_show_boot_tgt_pri_info,
+                                            qla4xxx_tgt_get_attr_visibility,
+                                            qla4xxx_boot_release);
+       if (!boot_kobj)
+               goto put_host;
+
+       if (!scsi_host_get(ha->host))
+               goto kset_free;
+       boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
+                                            qla4xxx_show_boot_tgt_sec_info,
+                                            qla4xxx_tgt_get_attr_visibility,
+                                            qla4xxx_boot_release);
+       if (!boot_kobj)
+               goto put_host;
+
+       if (!scsi_host_get(ha->host))
+               goto kset_free;
+       boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
+                                              qla4xxx_show_boot_ini_info,
+                                              qla4xxx_ini_get_attr_visibility,
+                                              qla4xxx_boot_release);
+       if (!boot_kobj)
+               goto put_host;
+
+       if (!scsi_host_get(ha->host))
+               goto kset_free;
+       boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
+                                              qla4xxx_show_boot_eth_info,
+                                              qla4xxx_eth_get_attr_visibility,
+                                              qla4xxx_boot_release);
+       if (!boot_kobj)
+               goto put_host;
+
+       return 0;
+
+put_host:
+       scsi_host_put(ha->host);
+kset_free:
+       iscsi_boot_destroy_kset(ha->boot_kset);
+       return -ENOMEM;
 }
 
-uint16_t qla4_8xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
+
+/**
+ * qla4xxx_create chap_list - Create CHAP list from FLASH
+ * @ha: pointer to adapter structure
+ *
+ * Read flash and make a list of CHAP entries, during login when a CHAP entry
+ * is received, it will be checked in this list. If entry exist then the CHAP
+ * entry index is set in the DDB. If CHAP entry does not exist in this list
+ * then a new entry is added in FLASH in CHAP table and the index obtained is
+ * used in the DDB.
+ **/
+static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
 {
-       return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->rsp_q_in));
+       int rval = 0;
+       uint8_t *chap_flash_data = NULL;
+       uint32_t offset;
+       dma_addr_t chap_dma;
+       uint32_t chap_size = 0;
+
+       if (is_qla40XX(ha))
+               chap_size = MAX_CHAP_ENTRIES_40XX  *
+                                       sizeof(struct ql4_chap_table);
+       else    /* Single region contains CHAP info for both
+                * ports which is divided into half for each port.
+                */
+               chap_size = ha->hw.flt_chap_size / 2;
+
+       chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
+                                         &chap_dma, GFP_KERNEL);
+       if (!chap_flash_data) {
+               ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
+               return;
+       }
+       if (is_qla40XX(ha))
+               offset = FLASH_CHAP_OFFSET;
+       else {
+               offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
+               if (ha->port_num == 1)
+                       offset += chap_size;
+       }
+
+       rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
+       if (rval != QLA_SUCCESS)
+               goto exit_chap_list;
+
+       if (ha->chap_list == NULL)
+               ha->chap_list = vmalloc(chap_size);
+       if (ha->chap_list == NULL) {
+               ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
+               goto exit_chap_list;
+       }
+
+       memcpy(ha->chap_list, chap_flash_data, chap_size);
+
+exit_chap_list:
+       dma_free_coherent(&ha->pdev->dev, chap_size,
+                       chap_flash_data, chap_dma);
+       return;
 }
 
 /**
@@ -1624,7 +3200,7 @@ static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
        if (pci_enable_device(pdev))
                return -1;
 
-       host = scsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha));
+       host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
        if (host == NULL) {
                printk(KERN_WARNING
                       "qla4xxx: Couldn't allocate host from scsi layer!\n");
@@ -1632,7 +3208,7 @@ static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
        }
 
        /* Clear our data area */
-       ha = (struct scsi_qla_host *) host->hostdata;
+       ha = to_qla_host(host);
        memset(ha, 0, sizeof(*ha));
 
        /* Save the information from PCI BIOS.  */
@@ -1675,11 +3251,12 @@ static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
        qla4xxx_config_dma_addressing(ha);
 
        /* Initialize lists and spinlocks. */
-       INIT_LIST_HEAD(&ha->ddb_list);
        INIT_LIST_HEAD(&ha->free_srb_q);
 
        mutex_init(&ha->mbox_sem);
+       mutex_init(&ha->chap_sem);
        init_completion(&ha->mbx_intr_comp);
+       init_completion(&ha->disable_acb_comp);
 
        spin_lock_init(&ha->hardware_lock);
 
@@ -1692,6 +3269,27 @@ static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
                goto probe_failed;
        }
 
+       host->cmd_per_lun = 3;
+       host->max_channel = 0;
+       host->max_lun = MAX_LUNS - 1;
+       host->max_id = MAX_TARGETS;
+       host->max_cmd_len = IOCB_MAX_CDB_LEN;
+       host->can_queue = MAX_SRBS ;
+       host->transportt = qla4xxx_scsi_transport;
+
+       ret = scsi_init_shared_tag_map(host, MAX_SRBS);
+       if (ret) {
+               ql4_printk(KERN_WARNING, ha,
+                          "%s: scsi_init_shared_tag_map failed\n", __func__);
+               goto probe_failed;
+       }
+
+       pci_set_drvdata(pdev, ha);
+
+       ret = scsi_add_host(host, &pdev->dev);
+       if (ret)
+               goto probe_failed;
+
        if (is_qla8022(ha))
                (void) qla4_8xxx_get_flash_info(ha);
 
@@ -1700,7 +3298,7 @@ static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
         * firmware
         * NOTE: interrupts enabled upon successful completion
         */
-       status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
+       status = qla4xxx_initialize_adapter(ha);
        while ((!test_bit(AF_ONLINE, &ha->flags)) &&
            init_retry_count++ < MAX_INIT_RETRIES) {
 
@@ -1721,7 +3319,7 @@ static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
                if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
                        continue;
 
-               status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
+               status = qla4xxx_initialize_adapter(ha);
        }
 
        if (!test_bit(AF_ONLINE, &ha->flags)) {
@@ -1736,24 +3334,9 @@ static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
                        qla4_8xxx_idc_unlock(ha);
                }
                ret = -ENODEV;
-               goto probe_failed;
+               goto remove_host;
        }
 
-       host->cmd_per_lun = 3;
-       host->max_channel = 0;
-       host->max_lun = MAX_LUNS - 1;
-       host->max_id = MAX_TARGETS;
-       host->max_cmd_len = IOCB_MAX_CDB_LEN;
-       host->can_queue = MAX_SRBS ;
-       host->transportt = qla4xxx_scsi_transport;
-
-        ret = scsi_init_shared_tag_map(host, MAX_SRBS);
-        if (ret) {
-               ql4_printk(KERN_WARNING, ha,
-                   "scsi_init_shared_tag_map failed\n");
-               goto probe_failed;
-        }
-
        /* Startup the kernel thread for this host adapter. */
        DEBUG2(printk("scsi: %s: Starting kernel thread for "
                      "qla4xxx_dpc\n", __func__));
@@ -1762,10 +3345,18 @@ static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
        if (!ha->dpc_thread) {
                ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
                ret = -ENODEV;
-               goto probe_failed;
+               goto remove_host;
        }
        INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
 
+       sprintf(buf, "qla4xxx_%lu_task", ha->host_no);
+       ha->task_wq = alloc_workqueue(buf, WQ_MEM_RECLAIM, 1);
+       if (!ha->task_wq) {
+               ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
+               ret = -ENODEV;
+               goto remove_host;
+       }
+
        /* For ISP-82XX, request_irqs is called in qla4_8xxx_load_risc
         * (which is called indirectly by qla4xxx_initialize_adapter),
         * so that irqs will be registered after crbinit but before
@@ -1776,7 +3367,7 @@ static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
                if (ret) {
                        ql4_printk(KERN_WARNING, ha, "Failed to reserve "
                            "interrupt %d already in use.\n", pdev->irq);
-                       goto probe_failed;
+                       goto remove_host;
                }
        }
 
@@ -1788,21 +3379,25 @@ static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
 
        set_bit(AF_INIT_DONE, &ha->flags);
 
-       pci_set_drvdata(pdev, ha);
-
-       ret = scsi_add_host(host, &pdev->dev);
-       if (ret)
-               goto probe_failed;
-
        printk(KERN_INFO
               " QLogic iSCSI HBA Driver version: %s\n"
               "  QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
               qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
               ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
               ha->patch_number, ha->build_number);
-       scsi_scan_host(host);
+
+       qla4xxx_create_chap_list(ha);
+
+       if (qla4xxx_setup_boot_info(ha))
+               ql4_printk(KERN_ERR, ha, "%s:ISCSI boot info setup failed\n",
+                          __func__);
+
+       qla4xxx_create_ifaces(ha);
        return 0;
 
+remove_host:
+       scsi_remove_host(ha->host);
+
 probe_failed:
        qla4xxx_free_adapter(ha);
 
@@ -1867,8 +3462,11 @@ static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev)
        if (!is_qla8022(ha))
                qla4xxx_prevent_other_port_reinit(ha);
 
-       /* remove devs from iscsi_sessions to scsi_devices */
-       qla4xxx_free_ddb_list(ha);
+       /* destroy iface from sysfs */
+       qla4xxx_destroy_ifaces(ha);
+
+       if (ha->boot_kset)
+               iscsi_boot_destroy_kset(ha->boot_kset);
 
        scsi_remove_host(ha->host);
 
@@ -1907,10 +3505,15 @@ static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
 
 static int qla4xxx_slave_alloc(struct scsi_device *sdev)
 {
-       struct iscsi_cls_session *sess = starget_to_session(sdev->sdev_target);
-       struct ddb_entry *ddb = sess->dd_data;
+       struct iscsi_cls_session *cls_sess;
+       struct iscsi_session *sess;
+       struct ddb_entry *ddb;
        int queue_depth = QL4_DEF_QDEPTH;
 
+       cls_sess = starget_to_session(sdev->sdev_target);
+       sess = cls_sess->dd_data;
+       ddb = sess->dd_data;
+
        sdev->hostdata = ddb;
        sdev->tagged_supported = 1;
 
@@ -2248,7 +3851,7 @@ static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
        int return_status = FAILED;
        struct scsi_qla_host *ha;
 
-       ha = (struct scsi_qla_host *) cmd->device->host->hostdata;
+       ha = to_qla_host(cmd->device->host);
 
        if (ql4xdontresethba) {
                DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
@@ -2284,6 +3887,110 @@ static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
        return return_status;
 }
 
+static int qla4xxx_context_reset(struct scsi_qla_host *ha)
+{
+       uint32_t mbox_cmd[MBOX_REG_COUNT];
+       uint32_t mbox_sts[MBOX_REG_COUNT];
+       struct addr_ctrl_blk_def *acb = NULL;
+       uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
+       int rval = QLA_SUCCESS;
+       dma_addr_t acb_dma;
+
+       acb = dma_alloc_coherent(&ha->pdev->dev,
+                                sizeof(struct addr_ctrl_blk_def),
+                                &acb_dma, GFP_KERNEL);
+       if (!acb) {
+               ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
+                          __func__);
+               rval = -ENOMEM;
+               goto exit_port_reset;
+       }
+
+       memset(acb, 0, acb_len);
+
+       rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
+       if (rval != QLA_SUCCESS) {
+               rval = -EIO;
+               goto exit_free_acb;
+       }
+
+       rval = qla4xxx_disable_acb(ha);
+       if (rval != QLA_SUCCESS) {
+               rval = -EIO;
+               goto exit_free_acb;
+       }
+
+       wait_for_completion_timeout(&ha->disable_acb_comp,
+                                   DISABLE_ACB_TOV * HZ);
+
+       rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
+       if (rval != QLA_SUCCESS) {
+               rval = -EIO;
+               goto exit_free_acb;
+       }
+
+exit_free_acb:
+       dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
+                         acb, acb_dma);
+exit_port_reset:
+       DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
+                         rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
+       return rval;
+}
+
+static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
+{
+       struct scsi_qla_host *ha = to_qla_host(shost);
+       int rval = QLA_SUCCESS;
+
+       if (ql4xdontresethba) {
+               DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
+                                 __func__));
+               rval = -EPERM;
+               goto exit_host_reset;
+       }
+
+       rval = qla4xxx_wait_for_hba_online(ha);
+       if (rval != QLA_SUCCESS) {
+               DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Unable to reset host "
+                                 "adapter\n", __func__));
+               rval = -EIO;
+               goto exit_host_reset;
+       }
+
+       if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
+               goto recover_adapter;
+
+       switch (reset_type) {
+       case SCSI_ADAPTER_RESET:
+               set_bit(DPC_RESET_HA, &ha->dpc_flags);
+               break;
+       case SCSI_FIRMWARE_RESET:
+               if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
+                       if (is_qla8022(ha))
+                               /* set firmware context reset */
+                               set_bit(DPC_RESET_HA_FW_CONTEXT,
+                                       &ha->dpc_flags);
+                       else {
+                               rval = qla4xxx_context_reset(ha);
+                               goto exit_host_reset;
+                       }
+               }
+               break;
+       }
+
+recover_adapter:
+       rval = qla4xxx_recover_adapter(ha);
+       if (rval != QLA_SUCCESS) {
+               DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
+                                 __func__));
+               rval = -EIO;
+       }
+
+exit_host_reset:
+       return rval;
+}
+
 /* PCI AER driver recovers from all correctable errors w/o
  * driver intervention. For uncorrectable errors PCI AER
  * driver calls the following device driver's callbacks
@@ -2360,7 +4067,8 @@ static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
 
        if (test_bit(AF_ONLINE, &ha->flags)) {
                clear_bit(AF_ONLINE, &ha->flags);
-               qla4xxx_mark_all_devices_missing(ha);
+               clear_bit(AF_LINK_UP, &ha->flags);
+               iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
                qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
        }
 
@@ -2407,7 +4115,7 @@ static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
 
                qla4_8xxx_idc_unlock(ha);
                clear_bit(AF_FW_RECOVERY, &ha->flags);
-               rval = qla4xxx_initialize_adapter(ha, PRESERVE_DDB_LIST);
+               rval = qla4xxx_initialize_adapter(ha);
                qla4_8xxx_idc_lock(ha);
 
                if (rval != QLA_SUCCESS) {
@@ -2443,8 +4151,7 @@ static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
                if ((qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
                    QLA82XX_DEV_READY)) {
                        clear_bit(AF_FW_RECOVERY, &ha->flags);
-                       rval = qla4xxx_initialize_adapter(ha,
-                           PRESERVE_DDB_LIST);
+                       rval = qla4xxx_initialize_adapter(ha);
                        if (rval == QLA_SUCCESS) {
                                ret = qla4xxx_request_irqs(ha);
                                if (ret) {
index 610492877253a8771356acae5c54ad13d43126bb..c15347d3f532099ef70127371a91caef2d90c3ee 100644 (file)
@@ -5,4 +5,4 @@
  * See LICENSE.qla4xxx for copyright and licensing details.
  */
 
-#define QLA4XXX_DRIVER_VERSION "5.02.00-k7"
+#define QLA4XXX_DRIVER_VERSION "5.02.00-k8"
index 9689d41c788887f4f3fb12e43c87b0c67ae1aa39..e40dc1cb09a0bdd89606981fe341cdd4630edbd5 100644 (file)
@@ -880,7 +880,7 @@ static inline void cmd_frob(struct Command_Entry *cmd, struct scsi_cmnd *Cmnd,
                cmd->control_flags |= CFLAG_WRITE;
        else
                cmd->control_flags |= CFLAG_READ;
-       cmd->time_out = 30;
+       cmd->time_out = Cmnd->request->timeout/HZ;
        memcpy(cmd->cdb, Cmnd->cmnd, Cmnd->cmd_len);
 }
 
index a4b9cdbaaa0b99d321a37e2fa1db8bf4063e2c86..dc6131e6a1ba2d40fe32504f1cb0e0f8d8b41def 100644 (file)
@@ -293,8 +293,16 @@ static int scsi_check_sense(struct scsi_cmnd *scmd)
                 * so that we can deal with it there.
                 */
                if (scmd->device->expecting_cc_ua) {
-                       scmd->device->expecting_cc_ua = 0;
-                       return NEEDS_RETRY;
+                       /*
+                        * Because some device does not queue unit
+                        * attentions correctly, we carefully check
+                        * additional sense code and qualifier so as
+                        * not to squash media change unit attention.
+                        */
+                       if (sshdr.asc != 0x28 || sshdr.ascq != 0x00) {
+                               scmd->device->expecting_cc_ua = 0;
+                               return NEEDS_RETRY;
+                       }
                }
                /*
                 * if the device is in the process of becoming ready, we
index e0bd3f790fca1bf50e4e66e3b2f30f9a130547f3..04c2a278076e189f568e306a06bd481e762add3d 100644 (file)
@@ -246,6 +246,43 @@ show_shost_active_mode(struct device *dev,
 
 static DEVICE_ATTR(active_mode, S_IRUGO | S_IWUSR, show_shost_active_mode, NULL);
 
+static int check_reset_type(char *str)
+{
+       if (strncmp(str, "adapter", 10) == 0)
+               return SCSI_ADAPTER_RESET;
+       else if (strncmp(str, "firmware", 10) == 0)
+               return SCSI_FIRMWARE_RESET;
+       else
+               return 0;
+}
+
+static ssize_t
+store_host_reset(struct device *dev, struct device_attribute *attr,
+               const char *buf, size_t count)
+{
+       struct Scsi_Host *shost = class_to_shost(dev);
+       struct scsi_host_template *sht = shost->hostt;
+       int ret = -EINVAL;
+       char str[10];
+       int type;
+
+       sscanf(buf, "%s", str);
+       type = check_reset_type(str);
+
+       if (!type)
+               goto exit_store_host_reset;
+
+       if (sht->host_reset)
+               ret = sht->host_reset(shost, type);
+
+exit_store_host_reset:
+       if (ret == 0)
+               ret = count;
+       return ret;
+}
+
+static DEVICE_ATTR(host_reset, S_IWUSR, NULL, store_host_reset);
+
 shost_rd_attr(unique_id, "%u\n");
 shost_rd_attr(host_busy, "%hu\n");
 shost_rd_attr(cmd_per_lun, "%hd\n");
@@ -272,6 +309,7 @@ static struct attribute *scsi_sysfs_shost_attrs[] = {
        &dev_attr_active_mode.attr,
        &dev_attr_prot_capabilities.attr,
        &dev_attr_prot_guard_type.attr,
+       &dev_attr_host_reset.attr,
        NULL
 };
 
index 3fd16d7212de2ec2eb5cb9fda7a5da35c4fb77ff..1bcd65a509e693153493356e8690a2a1ef28ca15 100644 (file)
@@ -23,6 +23,8 @@
 #include <linux/module.h>
 #include <linux/mutex.h>
 #include <linux/slab.h>
+#include <linux/bsg-lib.h>
+#include <linux/idr.h>
 #include <net/tcp.h>
 #include <scsi/scsi.h>
 #include <scsi/scsi_host.h>
 #include <scsi/scsi_transport_iscsi.h>
 #include <scsi/iscsi_if.h>
 #include <scsi/scsi_cmnd.h>
-
-#define ISCSI_SESSION_ATTRS 23
-#define ISCSI_CONN_ATTRS 13
-#define ISCSI_HOST_ATTRS 4
+#include <scsi/scsi_bsg_iscsi.h>
 
 #define ISCSI_TRANSPORT_VERSION "2.0-870"
 
@@ -76,16 +75,14 @@ struct iscsi_internal {
        struct list_head list;
        struct device dev;
 
-       struct device_attribute *host_attrs[ISCSI_HOST_ATTRS + 1];
        struct transport_container conn_cont;
-       struct device_attribute *conn_attrs[ISCSI_CONN_ATTRS + 1];
        struct transport_container session_cont;
-       struct device_attribute *session_attrs[ISCSI_SESSION_ATTRS + 1];
 };
 
 static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
 static struct workqueue_struct *iscsi_eh_timer_workq;
 
+static DEFINE_IDA(iscsi_sess_ida);
 /*
  * list of registered transports and lock that must
  * be held while accessing list. The iscsi_transport_lock must
@@ -270,6 +267,291 @@ struct iscsi_endpoint *iscsi_lookup_endpoint(u64 handle)
 }
 EXPORT_SYMBOL_GPL(iscsi_lookup_endpoint);
 
+/*
+ * Interface to display network param to sysfs
+ */
+
+static void iscsi_iface_release(struct device *dev)
+{
+       struct iscsi_iface *iface = iscsi_dev_to_iface(dev);
+       struct device *parent = iface->dev.parent;
+
+       kfree(iface);
+       put_device(parent);
+}
+
+
+static struct class iscsi_iface_class = {
+       .name = "iscsi_iface",
+       .dev_release = iscsi_iface_release,
+};
+
+#define ISCSI_IFACE_ATTR(_prefix, _name, _mode, _show, _store) \
+struct device_attribute dev_attr_##_prefix##_##_name =         \
+       __ATTR(_name, _mode, _show, _store)
+
+/* iface attrs show */
+#define iscsi_iface_attr_show(type, name, param_type, param)           \
+static ssize_t                                                         \
+show_##type##_##name(struct device *dev, struct device_attribute *attr,        \
+                    char *buf)                                         \
+{                                                                      \
+       struct iscsi_iface *iface = iscsi_dev_to_iface(dev);            \
+       struct iscsi_transport *t = iface->transport;                   \
+       return t->get_iface_param(iface, param_type, param, buf);       \
+}                                                                      \
+
+#define iscsi_iface_net_attr(type, name, param)                                \
+       iscsi_iface_attr_show(type, name, ISCSI_NET_PARAM, param)       \
+static ISCSI_IFACE_ATTR(type, name, S_IRUGO, show_##type##_##name, NULL);
+
+/* generic read only ipvi4 attribute */
+iscsi_iface_net_attr(ipv4_iface, ipaddress, ISCSI_NET_PARAM_IPV4_ADDR);
+iscsi_iface_net_attr(ipv4_iface, gateway, ISCSI_NET_PARAM_IPV4_GW);
+iscsi_iface_net_attr(ipv4_iface, subnet, ISCSI_NET_PARAM_IPV4_SUBNET);
+iscsi_iface_net_attr(ipv4_iface, bootproto, ISCSI_NET_PARAM_IPV4_BOOTPROTO);
+
+/* generic read only ipv6 attribute */
+iscsi_iface_net_attr(ipv6_iface, ipaddress, ISCSI_NET_PARAM_IPV6_ADDR);
+iscsi_iface_net_attr(ipv6_iface, link_local_addr, ISCSI_NET_PARAM_IPV6_LINKLOCAL);
+iscsi_iface_net_attr(ipv6_iface, router_addr, ISCSI_NET_PARAM_IPV6_ROUTER);
+iscsi_iface_net_attr(ipv6_iface, ipaddr_autocfg,
+                    ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG);
+iscsi_iface_net_attr(ipv6_iface, link_local_autocfg,
+                    ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG);
+
+/* common read only iface attribute */
+iscsi_iface_net_attr(iface, enabled, ISCSI_NET_PARAM_IFACE_ENABLE);
+iscsi_iface_net_attr(iface, vlan_id, ISCSI_NET_PARAM_VLAN_ID);
+iscsi_iface_net_attr(iface, vlan_priority, ISCSI_NET_PARAM_VLAN_PRIORITY);
+iscsi_iface_net_attr(iface, vlan_enabled, ISCSI_NET_PARAM_VLAN_ENABLED);
+iscsi_iface_net_attr(iface, mtu, ISCSI_NET_PARAM_MTU);
+iscsi_iface_net_attr(iface, port, ISCSI_NET_PARAM_PORT);
+
+static mode_t iscsi_iface_attr_is_visible(struct kobject *kobj,
+                                         struct attribute *attr, int i)
+{
+       struct device *dev = container_of(kobj, struct device, kobj);
+       struct iscsi_iface *iface = iscsi_dev_to_iface(dev);
+       struct iscsi_transport *t = iface->transport;
+       int param;
+
+       if (attr == &dev_attr_iface_enabled.attr)
+               param = ISCSI_NET_PARAM_IFACE_ENABLE;
+       else if (attr == &dev_attr_iface_vlan_id.attr)
+               param = ISCSI_NET_PARAM_VLAN_ID;
+       else if (attr == &dev_attr_iface_vlan_priority.attr)
+               param = ISCSI_NET_PARAM_VLAN_PRIORITY;
+       else if (attr == &dev_attr_iface_vlan_enabled.attr)
+               param = ISCSI_NET_PARAM_VLAN_ENABLED;
+       else if (attr == &dev_attr_iface_mtu.attr)
+               param = ISCSI_NET_PARAM_MTU;
+       else if (attr == &dev_attr_iface_port.attr)
+               param = ISCSI_NET_PARAM_PORT;
+       else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
+               if (attr == &dev_attr_ipv4_iface_ipaddress.attr)
+                       param = ISCSI_NET_PARAM_IPV4_ADDR;
+               else if (attr == &dev_attr_ipv4_iface_gateway.attr)
+                       param = ISCSI_NET_PARAM_IPV4_GW;
+               else if (attr == &dev_attr_ipv4_iface_subnet.attr)
+                       param = ISCSI_NET_PARAM_IPV4_SUBNET;
+               else if (attr == &dev_attr_ipv4_iface_bootproto.attr)
+                       param = ISCSI_NET_PARAM_IPV4_BOOTPROTO;
+               else
+                       return 0;
+       } else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6) {
+               if (attr == &dev_attr_ipv6_iface_ipaddress.attr)
+                       param = ISCSI_NET_PARAM_IPV6_ADDR;
+               else if (attr == &dev_attr_ipv6_iface_link_local_addr.attr)
+                       param = ISCSI_NET_PARAM_IPV6_LINKLOCAL;
+               else if (attr == &dev_attr_ipv6_iface_router_addr.attr)
+                       param = ISCSI_NET_PARAM_IPV6_ROUTER;
+               else if (attr == &dev_attr_ipv6_iface_ipaddr_autocfg.attr)
+                       param = ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG;
+               else if (attr == &dev_attr_ipv6_iface_link_local_autocfg.attr)
+                       param = ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG;
+               else
+                       return 0;
+       } else {
+               WARN_ONCE(1, "Invalid iface attr");
+               return 0;
+       }
+
+       return t->attr_is_visible(ISCSI_NET_PARAM, param);
+}
+
+static struct attribute *iscsi_iface_attrs[] = {
+       &dev_attr_iface_enabled.attr,
+       &dev_attr_iface_vlan_id.attr,
+       &dev_attr_iface_vlan_priority.attr,
+       &dev_attr_iface_vlan_enabled.attr,
+       &dev_attr_ipv4_iface_ipaddress.attr,
+       &dev_attr_ipv4_iface_gateway.attr,
+       &dev_attr_ipv4_iface_subnet.attr,
+       &dev_attr_ipv4_iface_bootproto.attr,
+       &dev_attr_ipv6_iface_ipaddress.attr,
+       &dev_attr_ipv6_iface_link_local_addr.attr,
+       &dev_attr_ipv6_iface_router_addr.attr,
+       &dev_attr_ipv6_iface_ipaddr_autocfg.attr,
+       &dev_attr_ipv6_iface_link_local_autocfg.attr,
+       &dev_attr_iface_mtu.attr,
+       &dev_attr_iface_port.attr,
+       NULL,
+};
+
+static struct attribute_group iscsi_iface_group = {
+       .attrs = iscsi_iface_attrs,
+       .is_visible = iscsi_iface_attr_is_visible,
+};
+
+struct iscsi_iface *
+iscsi_create_iface(struct Scsi_Host *shost, struct iscsi_transport *transport,
+                  uint32_t iface_type, uint32_t iface_num, int dd_size)
+{
+       struct iscsi_iface *iface;
+       int err;
+
+       iface = kzalloc(sizeof(*iface) + dd_size, GFP_KERNEL);
+       if (!iface)
+               return NULL;
+
+       iface->transport = transport;
+       iface->iface_type = iface_type;
+       iface->iface_num = iface_num;
+       iface->dev.release = iscsi_iface_release;
+       iface->dev.class = &iscsi_iface_class;
+       /* parent reference released in iscsi_iface_release */
+       iface->dev.parent = get_device(&shost->shost_gendev);
+       if (iface_type == ISCSI_IFACE_TYPE_IPV4)
+               dev_set_name(&iface->dev, "ipv4-iface-%u-%u", shost->host_no,
+                            iface_num);
+       else
+               dev_set_name(&iface->dev, "ipv6-iface-%u-%u", shost->host_no,
+                            iface_num);
+
+       err = device_register(&iface->dev);
+       if (err)
+               goto free_iface;
+
+       err = sysfs_create_group(&iface->dev.kobj, &iscsi_iface_group);
+       if (err)
+               goto unreg_iface;
+
+       if (dd_size)
+               iface->dd_data = &iface[1];
+       return iface;
+
+unreg_iface:
+       device_unregister(&iface->dev);
+       return NULL;
+
+free_iface:
+       put_device(iface->dev.parent);
+       kfree(iface);
+       return NULL;
+}
+EXPORT_SYMBOL_GPL(iscsi_create_iface);
+
+void iscsi_destroy_iface(struct iscsi_iface *iface)
+{
+       sysfs_remove_group(&iface->dev.kobj, &iscsi_iface_group);
+       device_unregister(&iface->dev);
+}
+EXPORT_SYMBOL_GPL(iscsi_destroy_iface);
+
+/*
+ * BSG support
+ */
+/**
+ * iscsi_bsg_host_dispatch - Dispatch command to LLD.
+ * @job: bsg job to be processed
+ */
+static int iscsi_bsg_host_dispatch(struct bsg_job *job)
+{
+       struct Scsi_Host *shost = iscsi_job_to_shost(job);
+       struct iscsi_bsg_request *req = job->request;
+       struct iscsi_bsg_reply *reply = job->reply;
+       struct iscsi_internal *i = to_iscsi_internal(shost->transportt);
+       int cmdlen = sizeof(uint32_t);  /* start with length of msgcode */
+       int ret;
+
+       /* check if we have the msgcode value at least */
+       if (job->request_len < sizeof(uint32_t)) {
+               ret = -ENOMSG;
+               goto fail_host_msg;
+       }
+
+       /* Validate the host command */
+       switch (req->msgcode) {
+       case ISCSI_BSG_HST_VENDOR:
+               cmdlen += sizeof(struct iscsi_bsg_host_vendor);
+               if ((shost->hostt->vendor_id == 0L) ||
+                   (req->rqst_data.h_vendor.vendor_id !=
+                       shost->hostt->vendor_id)) {
+                       ret = -ESRCH;
+                       goto fail_host_msg;
+               }
+               break;
+       default:
+               ret = -EBADR;
+               goto fail_host_msg;
+       }
+
+       /* check if we really have all the request data needed */
+       if (job->request_len < cmdlen) {
+               ret = -ENOMSG;
+               goto fail_host_msg;
+       }
+
+       ret = i->iscsi_transport->bsg_request(job);
+       if (!ret)
+               return 0;
+
+fail_host_msg:
+       /* return the errno failure code as the only status */
+       BUG_ON(job->reply_len < sizeof(uint32_t));
+       reply->reply_payload_rcv_len = 0;
+       reply->result = ret;
+       job->reply_len = sizeof(uint32_t);
+       bsg_job_done(job, ret, 0);
+       return 0;
+}
+
+/**
+ * iscsi_bsg_host_add - Create and add the bsg hooks to receive requests
+ * @shost: shost for iscsi_host
+ * @cls_host: iscsi_cls_host adding the structures to
+ */
+static int
+iscsi_bsg_host_add(struct Scsi_Host *shost, struct iscsi_cls_host *ihost)
+{
+       struct device *dev = &shost->shost_gendev;
+       struct iscsi_internal *i = to_iscsi_internal(shost->transportt);
+       struct request_queue *q;
+       char bsg_name[20];
+       int ret;
+
+       if (!i->iscsi_transport->bsg_request)
+               return -ENOTSUPP;
+
+       snprintf(bsg_name, sizeof(bsg_name), "iscsi_host%d", shost->host_no);
+
+       q = __scsi_alloc_queue(shost, bsg_request_fn);
+       if (!q)
+               return -ENOMEM;
+
+       ret = bsg_setup_queue(dev, q, bsg_name, iscsi_bsg_host_dispatch, 0);
+       if (ret) {
+               shost_printk(KERN_ERR, shost, "bsg interface failed to "
+                            "initialize - no request queue\n");
+               blk_cleanup_queue(q);
+               return ret;
+       }
+
+       ihost->bsg_q = q;
+       return 0;
+}
+
 static int iscsi_setup_host(struct transport_container *tc, struct device *dev,
                            struct device *cdev)
 {
@@ -279,13 +561,30 @@ static int iscsi_setup_host(struct transport_container *tc, struct device *dev,
        memset(ihost, 0, sizeof(*ihost));
        atomic_set(&ihost->nr_scans, 0);
        mutex_init(&ihost->mutex);
+
+       iscsi_bsg_host_add(shost, ihost);
+       /* ignore any bsg add error - we just can't do sgio */
+
+       return 0;
+}
+
+static int iscsi_remove_host(struct transport_container *tc,
+                            struct device *dev, struct device *cdev)
+{
+       struct Scsi_Host *shost = dev_to_shost(dev);
+       struct iscsi_cls_host *ihost = shost->shost_data;
+
+       if (ihost->bsg_q) {
+               bsg_remove_queue(ihost->bsg_q);
+               blk_cleanup_queue(ihost->bsg_q);
+       }
        return 0;
 }
 
 static DECLARE_TRANSPORT_CLASS(iscsi_host_class,
                               "iscsi_host",
                               iscsi_setup_host,
-                              NULL,
+                              iscsi_remove_host,
                               NULL);
 
 static DECLARE_TRANSPORT_CLASS(iscsi_session_class,
@@ -404,6 +703,19 @@ int iscsi_session_chkready(struct iscsi_cls_session *session)
 }
 EXPORT_SYMBOL_GPL(iscsi_session_chkready);
 
+int iscsi_is_session_online(struct iscsi_cls_session *session)
+{
+       unsigned long flags;
+       int ret = 0;
+
+       spin_lock_irqsave(&session->lock, flags);
+       if (session->state == ISCSI_SESSION_LOGGED_IN)
+               ret = 1;
+       spin_unlock_irqrestore(&session->lock, flags);
+       return ret;
+}
+EXPORT_SYMBOL_GPL(iscsi_is_session_online);
+
 static void iscsi_session_release(struct device *dev)
 {
        struct iscsi_cls_session *session = iscsi_dev_to_session(dev);
@@ -680,6 +992,7 @@ static void __iscsi_unbind_session(struct work_struct *work)
        struct Scsi_Host *shost = iscsi_session_to_shost(session);
        struct iscsi_cls_host *ihost = shost->shost_data;
        unsigned long flags;
+       unsigned int target_id;
 
        ISCSI_DBG_TRANS_SESSION(session, "Unbinding session\n");
 
@@ -691,10 +1004,15 @@ static void __iscsi_unbind_session(struct work_struct *work)
                mutex_unlock(&ihost->mutex);
                return;
        }
+
+       target_id = session->target_id;
        session->target_id = ISCSI_MAX_TARGET;
        spin_unlock_irqrestore(&session->lock, flags);
        mutex_unlock(&ihost->mutex);
 
+       if (session->ida_used)
+               ida_simple_remove(&iscsi_sess_ida, target_id);
+
        scsi_remove_target(&session->dev);
        iscsi_session_event(session, ISCSI_KEVENT_UNBIND_SESSION);
        ISCSI_DBG_TRANS_SESSION(session, "Completed target removal\n");
@@ -735,59 +1053,36 @@ iscsi_alloc_session(struct Scsi_Host *shost, struct iscsi_transport *transport,
 }
 EXPORT_SYMBOL_GPL(iscsi_alloc_session);
 
-static int iscsi_get_next_target_id(struct device *dev, void *data)
-{
-       struct iscsi_cls_session *session;
-       unsigned long flags;
-       int err = 0;
-
-       if (!iscsi_is_session_dev(dev))
-               return 0;
-
-       session = iscsi_dev_to_session(dev);
-       spin_lock_irqsave(&session->lock, flags);
-       if (*((unsigned int *) data) == session->target_id)
-               err = -EEXIST;
-       spin_unlock_irqrestore(&session->lock, flags);
-       return err;
-}
-
 int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
 {
        struct Scsi_Host *shost = iscsi_session_to_shost(session);
        struct iscsi_cls_host *ihost;
        unsigned long flags;
-       unsigned int id = target_id;
+       int id = 0;
        int err;
 
        ihost = shost->shost_data;
        session->sid = atomic_add_return(1, &iscsi_session_nr);
 
-       if (id == ISCSI_MAX_TARGET) {
-               for (id = 0; id < ISCSI_MAX_TARGET; id++) {
-                       err = device_for_each_child(&shost->shost_gendev, &id,
-                                                   iscsi_get_next_target_id);
-                       if (!err)
-                               break;
-               }
+       if (target_id == ISCSI_MAX_TARGET) {
+               id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
 
-               if (id == ISCSI_MAX_TARGET) {
+               if (id < 0) {
                        iscsi_cls_session_printk(KERN_ERR, session,
-                                                "Too many iscsi targets. Max "
-                                                "number of targets is %d.\n",
-                                                ISCSI_MAX_TARGET - 1);
-                       err = -EOVERFLOW;
-                       goto release_host;
+                                       "Failure in Target ID Allocation\n");
+                       return id;
                }
-       }
-       session->target_id = id;
+               session->target_id = (unsigned int)id;
+               session->ida_used = true;
+       } else
+               session->target_id = target_id;
 
        dev_set_name(&session->dev, "session%u", session->sid);
        err = device_add(&session->dev);
        if (err) {
                iscsi_cls_session_printk(KERN_ERR, session,
                                         "could not register session's dev\n");
-               goto release_host;
+               goto release_ida;
        }
        transport_register_device(&session->dev);
 
@@ -799,8 +1094,10 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
        ISCSI_DBG_TRANS_SESSION(session, "Completed session adding\n");
        return 0;
 
-release_host:
-       scsi_host_put(shost);
+release_ida:
+       if (session->ida_used)
+               ida_simple_remove(&iscsi_sess_ida, session->target_id);
+
        return err;
 }
 EXPORT_SYMBOL_GPL(iscsi_add_session);
@@ -1144,6 +1441,40 @@ void iscsi_conn_error_event(struct iscsi_cls_conn *conn, enum iscsi_err error)
 }
 EXPORT_SYMBOL_GPL(iscsi_conn_error_event);
 
+void iscsi_conn_login_event(struct iscsi_cls_conn *conn,
+                           enum iscsi_conn_state state)
+{
+       struct nlmsghdr *nlh;
+       struct sk_buff  *skb;
+       struct iscsi_uevent *ev;
+       struct iscsi_internal *priv;
+       int len = NLMSG_SPACE(sizeof(*ev));
+
+       priv = iscsi_if_transport_lookup(conn->transport);
+       if (!priv)
+               return;
+
+       skb = alloc_skb(len, GFP_ATOMIC);
+       if (!skb) {
+               iscsi_cls_conn_printk(KERN_ERR, conn, "gracefully ignored "
+                                     "conn login (%d)\n", state);
+               return;
+       }
+
+       nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
+       ev = NLMSG_DATA(nlh);
+       ev->transport_handle = iscsi_handle(conn->transport);
+       ev->type = ISCSI_KEVENT_CONN_LOGIN_STATE;
+       ev->r.conn_login.state = state;
+       ev->r.conn_login.cid = conn->cid;
+       ev->r.conn_login.sid = iscsi_conn_get_sid(conn);
+       iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_ATOMIC);
+
+       iscsi_cls_conn_printk(KERN_INFO, conn, "detected conn login (%d)\n",
+                             state);
+}
+EXPORT_SYMBOL_GPL(iscsi_conn_login_event);
+
 static int
 iscsi_if_send_reply(uint32_t group, int seq, int type, int done, int multi,
                    void *payload, int size)
@@ -1557,6 +1888,29 @@ iscsi_set_path(struct iscsi_transport *transport, struct iscsi_uevent *ev)
        return err;
 }
 
+static int
+iscsi_set_iface_params(struct iscsi_transport *transport,
+                      struct iscsi_uevent *ev, uint32_t len)
+{
+       char *data = (char *)ev + sizeof(*ev);
+       struct Scsi_Host *shost;
+       int err;
+
+       if (!transport->set_iface_param)
+               return -ENOSYS;
+
+       shost = scsi_host_lookup(ev->u.set_iface_params.host_no);
+       if (!shost) {
+               printk(KERN_ERR "set_iface_params could not find host no %u\n",
+                      ev->u.set_iface_params.host_no);
+               return -ENODEV;
+       }
+
+       err = transport->set_iface_param(shost, data, len);
+       scsi_host_put(shost);
+       return err;
+}
+
 static int
 iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, uint32_t *group)
 {
@@ -1696,6 +2050,10 @@ iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, uint32_t *group)
        case ISCSI_UEVENT_PATH_UPDATE:
                err = iscsi_set_path(transport, ev);
                break;
+       case ISCSI_UEVENT_SET_IFACE_PARAMS:
+               err = iscsi_set_iface_params(transport, ev,
+                                            nlmsg_attrlen(nlh, sizeof(*ev)));
+               break;
        default:
                err = -ENOSYS;
                break;
@@ -1824,6 +2182,70 @@ static ISCSI_CLASS_ATTR(conn, field, S_IRUGO,                            \
 iscsi_conn_ep_attr(address, ISCSI_PARAM_CONN_ADDRESS);
 iscsi_conn_ep_attr(port, ISCSI_PARAM_CONN_PORT);
 
+static struct attribute *iscsi_conn_attrs[] = {
+       &dev_attr_conn_max_recv_dlength.attr,
+       &dev_attr_conn_max_xmit_dlength.attr,
+       &dev_attr_conn_header_digest.attr,
+       &dev_attr_conn_data_digest.attr,
+       &dev_attr_conn_ifmarker.attr,
+       &dev_attr_conn_ofmarker.attr,
+       &dev_attr_conn_address.attr,
+       &dev_attr_conn_port.attr,
+       &dev_attr_conn_exp_statsn.attr,
+       &dev_attr_conn_persistent_address.attr,
+       &dev_attr_conn_persistent_port.attr,
+       &dev_attr_conn_ping_tmo.attr,
+       &dev_attr_conn_recv_tmo.attr,
+       NULL,
+};
+
+static mode_t iscsi_conn_attr_is_visible(struct kobject *kobj,
+                                        struct attribute *attr, int i)
+{
+       struct device *cdev = container_of(kobj, struct device, kobj);
+       struct iscsi_cls_conn *conn = transport_class_to_conn(cdev);
+       struct iscsi_transport *t = conn->transport;
+       int param;
+
+       if (attr == &dev_attr_conn_max_recv_dlength.attr)
+               param = ISCSI_PARAM_MAX_RECV_DLENGTH;
+       else if (attr == &dev_attr_conn_max_xmit_dlength.attr)
+               param = ISCSI_PARAM_MAX_XMIT_DLENGTH;
+       else if (attr == &dev_attr_conn_header_digest.attr)
+               param = ISCSI_PARAM_HDRDGST_EN;
+       else if (attr == &dev_attr_conn_data_digest.attr)
+               param = ISCSI_PARAM_DATADGST_EN;
+       else if (attr == &dev_attr_conn_ifmarker.attr)
+               param = ISCSI_PARAM_IFMARKER_EN;
+       else if (attr == &dev_attr_conn_ofmarker.attr)
+               param = ISCSI_PARAM_OFMARKER_EN;
+       else if (attr == &dev_attr_conn_address.attr)
+               param = ISCSI_PARAM_CONN_ADDRESS;
+       else if (attr == &dev_attr_conn_port.attr)
+               param = ISCSI_PARAM_CONN_PORT;
+       else if (attr == &dev_attr_conn_exp_statsn.attr)
+               param = ISCSI_PARAM_EXP_STATSN;
+       else if (attr == &dev_attr_conn_persistent_address.attr)
+               param = ISCSI_PARAM_PERSISTENT_ADDRESS;
+       else if (attr == &dev_attr_conn_persistent_port.attr)
+               param = ISCSI_PARAM_PERSISTENT_PORT;
+       else if (attr == &dev_attr_conn_ping_tmo.attr)
+               param = ISCSI_PARAM_PING_TMO;
+       else if (attr == &dev_attr_conn_recv_tmo.attr)
+               param = ISCSI_PARAM_RECV_TMO;
+       else {
+               WARN_ONCE(1, "Invalid conn attr");
+               return 0;
+       }
+
+       return t->attr_is_visible(ISCSI_PARAM, param);
+}
+
+static struct attribute_group iscsi_conn_group = {
+       .attrs = iscsi_conn_attrs,
+       .is_visible = iscsi_conn_attr_is_visible,
+};
+
 /*
  * iSCSI session attrs
  */
@@ -1845,7 +2267,6 @@ show_session_param_##param(struct device *dev,                            \
        iscsi_session_attr_show(param, perm)                            \
 static ISCSI_CLASS_ATTR(sess, field, S_IRUGO, show_session_param_##param, \
                        NULL);
-
 iscsi_session_attr(targetname, ISCSI_PARAM_TARGET_NAME, 0);
 iscsi_session_attr(initial_r2t, ISCSI_PARAM_INITIAL_R2T_EN, 0);
 iscsi_session_attr(max_outstanding_r2t, ISCSI_PARAM_MAX_R2T, 0);
@@ -1922,6 +2343,100 @@ static ISCSI_CLASS_ATTR(priv_sess, field, S_IRUGO | S_IWUSR,            \
                        store_priv_session_##field)
 iscsi_priv_session_rw_attr(recovery_tmo, "%d");
 
+static struct attribute *iscsi_session_attrs[] = {
+       &dev_attr_sess_initial_r2t.attr,
+       &dev_attr_sess_max_outstanding_r2t.attr,
+       &dev_attr_sess_immediate_data.attr,
+       &dev_attr_sess_first_burst_len.attr,
+       &dev_attr_sess_max_burst_len.attr,
+       &dev_attr_sess_data_pdu_in_order.attr,
+       &dev_attr_sess_data_seq_in_order.attr,
+       &dev_attr_sess_erl.attr,
+       &dev_attr_sess_targetname.attr,
+       &dev_attr_sess_tpgt.attr,
+       &dev_attr_sess_password.attr,
+       &dev_attr_sess_password_in.attr,
+       &dev_attr_sess_username.attr,
+       &dev_attr_sess_username_in.attr,
+       &dev_attr_sess_fast_abort.attr,
+       &dev_attr_sess_abort_tmo.attr,
+       &dev_attr_sess_lu_reset_tmo.attr,
+       &dev_attr_sess_tgt_reset_tmo.attr,
+       &dev_attr_sess_ifacename.attr,
+       &dev_attr_sess_initiatorname.attr,
+       &dev_attr_sess_targetalias.attr,
+       &dev_attr_priv_sess_recovery_tmo.attr,
+       &dev_attr_priv_sess_state.attr,
+       NULL,
+};
+
+static mode_t iscsi_session_attr_is_visible(struct kobject *kobj,
+                                           struct attribute *attr, int i)
+{
+       struct device *cdev = container_of(kobj, struct device, kobj);
+       struct iscsi_cls_session *session = transport_class_to_session(cdev);
+       struct iscsi_transport *t = session->transport;
+       int param;
+
+       if (attr == &dev_attr_sess_initial_r2t.attr)
+               param = ISCSI_PARAM_INITIAL_R2T_EN;
+       else if (attr == &dev_attr_sess_max_outstanding_r2t.attr)
+               param = ISCSI_PARAM_MAX_R2T;
+       else if (attr == &dev_attr_sess_immediate_data.attr)
+               param = ISCSI_PARAM_IMM_DATA_EN;
+       else if (attr == &dev_attr_sess_first_burst_len.attr)
+               param = ISCSI_PARAM_FIRST_BURST;
+       else if (attr == &dev_attr_sess_max_burst_len.attr)
+               param = ISCSI_PARAM_MAX_BURST;
+       else if (attr == &dev_attr_sess_data_pdu_in_order.attr)
+               param = ISCSI_PARAM_PDU_INORDER_EN;
+       else if (attr == &dev_attr_sess_data_seq_in_order.attr)
+               param = ISCSI_PARAM_DATASEQ_INORDER_EN;
+       else if (attr == &dev_attr_sess_erl.attr)
+               param = ISCSI_PARAM_ERL;
+       else if (attr == &dev_attr_sess_targetname.attr)
+               param = ISCSI_PARAM_TARGET_NAME;
+       else if (attr == &dev_attr_sess_tpgt.attr)
+               param = ISCSI_PARAM_TPGT;
+       else if (attr == &dev_attr_sess_password.attr)
+               param = ISCSI_PARAM_USERNAME;
+       else if (attr == &dev_attr_sess_password_in.attr)
+               param = ISCSI_PARAM_USERNAME_IN;
+       else if (attr == &dev_attr_sess_username.attr)
+               param = ISCSI_PARAM_PASSWORD;
+       else if (attr == &dev_attr_sess_username_in.attr)
+               param = ISCSI_PARAM_PASSWORD_IN;
+       else if (attr == &dev_attr_sess_fast_abort.attr)
+               param = ISCSI_PARAM_FAST_ABORT;
+       else if (attr == &dev_attr_sess_abort_tmo.attr)
+               param = ISCSI_PARAM_ABORT_TMO;
+       else if (attr == &dev_attr_sess_lu_reset_tmo.attr)
+               param = ISCSI_PARAM_LU_RESET_TMO;
+       else if (attr == &dev_attr_sess_tgt_reset_tmo.attr)
+               param = ISCSI_PARAM_TGT_RESET_TMO;
+       else if (attr == &dev_attr_sess_ifacename.attr)
+               param = ISCSI_PARAM_IFACE_NAME;
+       else if (attr == &dev_attr_sess_initiatorname.attr)
+               param = ISCSI_PARAM_INITIATOR_NAME;
+       else if (attr == &dev_attr_sess_targetalias.attr)
+               param = ISCSI_PARAM_TARGET_ALIAS;
+       else if (attr == &dev_attr_priv_sess_recovery_tmo.attr)
+               return S_IRUGO | S_IWUSR;
+       else if (attr == &dev_attr_priv_sess_state.attr)
+               return S_IRUGO;
+       else {
+               WARN_ONCE(1, "Invalid session attr");
+               return 0;
+       }
+
+       return t->attr_is_visible(ISCSI_PARAM, param);
+}
+
+static struct attribute_group iscsi_session_group = {
+       .attrs = iscsi_session_attrs,
+       .is_visible = iscsi_session_attr_is_visible,
+};
+
 /*
  * iSCSI host attrs
  */
@@ -1945,41 +2460,42 @@ iscsi_host_attr(hwaddress, ISCSI_HOST_PARAM_HWADDRESS);
 iscsi_host_attr(ipaddress, ISCSI_HOST_PARAM_IPADDRESS);
 iscsi_host_attr(initiatorname, ISCSI_HOST_PARAM_INITIATOR_NAME);
 
-#define SETUP_PRIV_SESSION_RD_ATTR(field)                              \
-do {                                                                   \
-       priv->session_attrs[count] = &dev_attr_priv_sess_##field; \
-       count++;                                                        \
-} while (0)
-
-#define SETUP_PRIV_SESSION_RW_ATTR(field)                              \
-do {                                                                   \
-       priv->session_attrs[count] = &dev_attr_priv_sess_##field;       \
-       count++;                                                        \
-} while (0)
-
-#define SETUP_SESSION_RD_ATTR(field, param_flag)                       \
-do {                                                                   \
-       if (tt->param_mask & param_flag) {                              \
-               priv->session_attrs[count] = &dev_attr_sess_##field; \
-               count++;                                                \
-       }                                                               \
-} while (0)
+static struct attribute *iscsi_host_attrs[] = {
+       &dev_attr_host_netdev.attr,
+       &dev_attr_host_hwaddress.attr,
+       &dev_attr_host_ipaddress.attr,
+       &dev_attr_host_initiatorname.attr,
+       NULL,
+};
 
-#define SETUP_CONN_RD_ATTR(field, param_flag)                          \
-do {                                                                   \
-       if (tt->param_mask & param_flag) {                              \
-               priv->conn_attrs[count] = &dev_attr_conn_##field; \
-               count++;                                                \
-       }                                                               \
-} while (0)
+static mode_t iscsi_host_attr_is_visible(struct kobject *kobj,
+                                        struct attribute *attr, int i)
+{
+       struct device *cdev = container_of(kobj, struct device, kobj);
+       struct Scsi_Host *shost = transport_class_to_shost(cdev);
+       struct iscsi_internal *priv = to_iscsi_internal(shost->transportt);
+       int param;
+
+       if (attr == &dev_attr_host_netdev.attr)
+               param = ISCSI_HOST_PARAM_NETDEV_NAME;
+       else if (attr == &dev_attr_host_hwaddress.attr)
+               param = ISCSI_HOST_PARAM_HWADDRESS;
+       else if (attr == &dev_attr_host_ipaddress.attr)
+               param = ISCSI_HOST_PARAM_IPADDRESS;
+       else if (attr == &dev_attr_host_initiatorname.attr)
+               param = ISCSI_HOST_PARAM_INITIATOR_NAME;
+       else {
+               WARN_ONCE(1, "Invalid host attr");
+               return 0;
+       }
 
-#define SETUP_HOST_RD_ATTR(field, param_flag)                          \
-do {                                                                   \
-       if (tt->host_param_mask & param_flag) {                         \
-               priv->host_attrs[count] = &dev_attr_host_##field; \
-               count++;                                                \
-       }                                                               \
-} while (0)
+       return priv->iscsi_transport->attr_is_visible(ISCSI_HOST_PARAM, param);
+}
+
+static struct attribute_group iscsi_host_group = {
+       .attrs = iscsi_host_attrs,
+       .is_visible = iscsi_host_attr_is_visible,
+};
 
 static int iscsi_session_match(struct attribute_container *cont,
                           struct device *dev)
@@ -2051,7 +2567,7 @@ iscsi_register_transport(struct iscsi_transport *tt)
 {
        struct iscsi_internal *priv;
        unsigned long flags;
-       int count = 0, err;
+       int err;
 
        BUG_ON(!tt);
 
@@ -2078,77 +2594,24 @@ iscsi_register_transport(struct iscsi_transport *tt)
                goto unregister_dev;
 
        /* host parameters */
-       priv->t.host_attrs.ac.attrs = &priv->host_attrs[0];
        priv->t.host_attrs.ac.class = &iscsi_host_class.class;
        priv->t.host_attrs.ac.match = iscsi_host_match;
+       priv->t.host_attrs.ac.grp = &iscsi_host_group;
        priv->t.host_size = sizeof(struct iscsi_cls_host);
        transport_container_register(&priv->t.host_attrs);
 
-       SETUP_HOST_RD_ATTR(netdev, ISCSI_HOST_NETDEV_NAME);
-       SETUP_HOST_RD_ATTR(ipaddress, ISCSI_HOST_IPADDRESS);
-       SETUP_HOST_RD_ATTR(hwaddress, ISCSI_HOST_HWADDRESS);
-       SETUP_HOST_RD_ATTR(initiatorname, ISCSI_HOST_INITIATOR_NAME);
-       BUG_ON(count > ISCSI_HOST_ATTRS);
-       priv->host_attrs[count] = NULL;
-       count = 0;
-
        /* connection parameters */
-       priv->conn_cont.ac.attrs = &priv->conn_attrs[0];
        priv->conn_cont.ac.class = &iscsi_connection_class.class;
        priv->conn_cont.ac.match = iscsi_conn_match;
+       priv->conn_cont.ac.grp = &iscsi_conn_group;
        transport_container_register(&priv->conn_cont);
 
-       SETUP_CONN_RD_ATTR(max_recv_dlength, ISCSI_MAX_RECV_DLENGTH);
-       SETUP_CONN_RD_ATTR(max_xmit_dlength, ISCSI_MAX_XMIT_DLENGTH);
-       SETUP_CONN_RD_ATTR(header_digest, ISCSI_HDRDGST_EN);
-       SETUP_CONN_RD_ATTR(data_digest, ISCSI_DATADGST_EN);
-       SETUP_CONN_RD_ATTR(ifmarker, ISCSI_IFMARKER_EN);
-       SETUP_CONN_RD_ATTR(ofmarker, ISCSI_OFMARKER_EN);
-       SETUP_CONN_RD_ATTR(address, ISCSI_CONN_ADDRESS);
-       SETUP_CONN_RD_ATTR(port, ISCSI_CONN_PORT);
-       SETUP_CONN_RD_ATTR(exp_statsn, ISCSI_EXP_STATSN);
-       SETUP_CONN_RD_ATTR(persistent_address, ISCSI_PERSISTENT_ADDRESS);
-       SETUP_CONN_RD_ATTR(persistent_port, ISCSI_PERSISTENT_PORT);
-       SETUP_CONN_RD_ATTR(ping_tmo, ISCSI_PING_TMO);
-       SETUP_CONN_RD_ATTR(recv_tmo, ISCSI_RECV_TMO);
-
-       BUG_ON(count > ISCSI_CONN_ATTRS);
-       priv->conn_attrs[count] = NULL;
-       count = 0;
-
        /* session parameters */
-       priv->session_cont.ac.attrs = &priv->session_attrs[0];
        priv->session_cont.ac.class = &iscsi_session_class.class;
        priv->session_cont.ac.match = iscsi_session_match;
+       priv->session_cont.ac.grp = &iscsi_session_group;
        transport_container_register(&priv->session_cont);
 
-       SETUP_SESSION_RD_ATTR(initial_r2t, ISCSI_INITIAL_R2T_EN);
-       SETUP_SESSION_RD_ATTR(max_outstanding_r2t, ISCSI_MAX_R2T);
-       SETUP_SESSION_RD_ATTR(immediate_data, ISCSI_IMM_DATA_EN);
-       SETUP_SESSION_RD_ATTR(first_burst_len, ISCSI_FIRST_BURST);
-       SETUP_SESSION_RD_ATTR(max_burst_len, ISCSI_MAX_BURST);
-       SETUP_SESSION_RD_ATTR(data_pdu_in_order, ISCSI_PDU_INORDER_EN);
-       SETUP_SESSION_RD_ATTR(data_seq_in_order, ISCSI_DATASEQ_INORDER_EN);
-       SETUP_SESSION_RD_ATTR(erl, ISCSI_ERL);
-       SETUP_SESSION_RD_ATTR(targetname, ISCSI_TARGET_NAME);
-       SETUP_SESSION_RD_ATTR(tpgt, ISCSI_TPGT);
-       SETUP_SESSION_RD_ATTR(password, ISCSI_USERNAME);
-       SETUP_SESSION_RD_ATTR(password_in, ISCSI_USERNAME_IN);
-       SETUP_SESSION_RD_ATTR(username, ISCSI_PASSWORD);
-       SETUP_SESSION_RD_ATTR(username_in, ISCSI_PASSWORD_IN);
-       SETUP_SESSION_RD_ATTR(fast_abort, ISCSI_FAST_ABORT);
-       SETUP_SESSION_RD_ATTR(abort_tmo, ISCSI_ABORT_TMO);
-       SETUP_SESSION_RD_ATTR(lu_reset_tmo,ISCSI_LU_RESET_TMO);
-       SETUP_SESSION_RD_ATTR(tgt_reset_tmo,ISCSI_TGT_RESET_TMO);
-       SETUP_SESSION_RD_ATTR(ifacename, ISCSI_IFACE_NAME);
-       SETUP_SESSION_RD_ATTR(initiatorname, ISCSI_INITIATOR_NAME);
-       SETUP_SESSION_RD_ATTR(targetalias, ISCSI_TARGET_ALIAS);
-       SETUP_PRIV_SESSION_RW_ATTR(recovery_tmo);
-       SETUP_PRIV_SESSION_RD_ATTR(state);
-
-       BUG_ON(count > ISCSI_SESSION_ATTRS);
-       priv->session_attrs[count] = NULL;
-
        spin_lock_irqsave(&iscsi_transport_lock, flags);
        list_add(&priv->list, &iscsi_transports);
        spin_unlock_irqrestore(&iscsi_transport_lock, flags);
@@ -2210,10 +2673,14 @@ static __init int iscsi_transport_init(void)
        if (err)
                goto unregister_transport_class;
 
-       err = transport_class_register(&iscsi_host_class);
+       err = class_register(&iscsi_iface_class);
        if (err)
                goto unregister_endpoint_class;
 
+       err = transport_class_register(&iscsi_host_class);
+       if (err)
+               goto unregister_iface_class;
+
        err = transport_class_register(&iscsi_connection_class);
        if (err)
                goto unregister_host_class;
@@ -2243,6 +2710,8 @@ unregister_conn_class:
        transport_class_unregister(&iscsi_connection_class);
 unregister_host_class:
        transport_class_unregister(&iscsi_host_class);
+unregister_iface_class:
+       class_unregister(&iscsi_iface_class);
 unregister_endpoint_class:
        class_unregister(&iscsi_endpoint_class);
 unregister_transport_class:
@@ -2258,6 +2727,7 @@ static void __exit iscsi_transport_exit(void)
        transport_class_unregister(&iscsi_session_class);
        transport_class_unregister(&iscsi_host_class);
        class_unregister(&iscsi_endpoint_class);
+       class_unregister(&iscsi_iface_class);
        class_unregister(&iscsi_transport_class);
 }
 
index c6fcf76cade549f2fb880d976c839b915e0b9dc3..9d9330ae4213206e5c300e5bbeeb4c3835170b9e 100644 (file)
@@ -1545,8 +1545,14 @@ int sas_rphy_add(struct sas_rphy *rphy)
 
        if (identify->device_type == SAS_END_DEVICE &&
            rphy->scsi_target_id != -1) {
-               scsi_scan_target(&rphy->dev, 0,
-                               rphy->scsi_target_id, SCAN_WILD_CARD, 0);
+               int lun;
+
+               if (identify->target_port_protocols & SAS_PROTOCOL_SSP)
+                       lun = SCAN_WILD_CARD;
+               else
+                       lun = 0;
+
+               scsi_scan_target(&rphy->dev, 0, rphy->scsi_target_id, lun, 0);
        }
 
        return 0;
index 953773cb26d9a6204a52d56e75884622632c4c0c..a7942e5c8be8c91dfc3f5dd45ee96fa4195be987 100644 (file)
@@ -1066,12 +1066,13 @@ static int sd_ioctl(struct block_device *bdev, fmode_t mode,
                    unsigned int cmd, unsigned long arg)
 {
        struct gendisk *disk = bdev->bd_disk;
-       struct scsi_device *sdp = scsi_disk(disk)->device;
+       struct scsi_disk *sdkp = scsi_disk(disk);
+       struct scsi_device *sdp = sdkp->device;
        void __user *p = (void __user *)arg;
        int error;
     
-       SCSI_LOG_IOCTL(1, printk("sd_ioctl: disk=%s, cmd=0x%x\n",
-                                               disk->disk_name, cmd));
+       SCSI_LOG_IOCTL(1, sd_printk(KERN_INFO, sdkp, "sd_ioctl: disk=%s, "
+                                   "cmd=0x%x\n", disk->disk_name, cmd));
 
        /*
         * If we are in the middle of error recovery, don't let anyone
index 4813a63ce6fbe9b05a6c52c5274239831f84ed0d..881c1967741d396502caa94194a6aae4ac6a91c3 100644 (file)
@@ -320,18 +320,7 @@ static struct platform_driver altera_spi_driver = {
                .of_match_table = altera_spi_match,
        },
 };
-
-static int __init altera_spi_init(void)
-{
-       return platform_driver_register(&altera_spi_driver);
-}
-module_init(altera_spi_init);
-
-static void __exit altera_spi_exit(void)
-{
-       platform_driver_unregister(&altera_spi_driver);
-}
-module_exit(altera_spi_exit);
+module_platform_driver(altera_spi_driver);
 
 MODULE_DESCRIPTION("Altera SPI driver");
 MODULE_AUTHOR("Thomas Chou <thomas@wytron.com.tw>");
index 03019bf5a5e907b36ba4c1512c04b9ec15a4da09..024b48aed5ca6bba6f32857965e8904fe012ca1b 100644 (file)
@@ -273,18 +273,7 @@ static struct platform_driver ath79_spi_driver = {
                .owner  = THIS_MODULE,
        },
 };
-
-static __init int ath79_spi_init(void)
-{
-       return platform_driver_register(&ath79_spi_driver);
-}
-module_init(ath79_spi_init);
-
-static __exit void ath79_spi_exit(void)
-{
-       platform_driver_unregister(&ath79_spi_driver);
-}
-module_exit(ath79_spi_exit);
+module_platform_driver(ath79_spi_driver);
 
 MODULE_DESCRIPTION("SPI controller driver for Atheros AR71XX/AR724X/AR913X");
 MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
index d3bff424286f109c6fcb1f0956096e604b0c0459..79665e2e6ec524b89f02c6aa680ca5b133009fa9 100644 (file)
@@ -1074,18 +1074,7 @@ static struct platform_driver atmel_spi_driver = {
        .resume         = atmel_spi_resume,
        .remove         = __exit_p(atmel_spi_remove),
 };
-
-static int __init atmel_spi_init(void)
-{
-       return platform_driver_probe(&atmel_spi_driver, atmel_spi_probe);
-}
-module_init(atmel_spi_init);
-
-static void __exit atmel_spi_exit(void)
-{
-       platform_driver_unregister(&atmel_spi_driver);
-}
-module_exit(atmel_spi_exit);
+module_platform_driver(atmel_spi_driver);
 
 MODULE_DESCRIPTION("Atmel AT32/AT91 SPI Controller driver");
 MODULE_AUTHOR("Haavard Skinnemoen (Atmel)");
index e557ff617b11658547fdea3cdbb352f4485492ca..248a2cc671a9bc8e6c6a83c5b515557f432c7841 100644 (file)
@@ -938,15 +938,4 @@ static struct platform_driver bfin_sport_spi_driver = {
        .suspend = bfin_sport_spi_suspend,
        .resume  = bfin_sport_spi_resume,
 };
-
-static int __init bfin_sport_spi_init(void)
-{
-       return platform_driver_register(&bfin_sport_spi_driver);
-}
-module_init(bfin_sport_spi_init);
-
-static void __exit bfin_sport_spi_exit(void)
-{
-       platform_driver_unregister(&bfin_sport_spi_driver);
-}
-module_exit(bfin_sport_spi_exit);
+module_platform_driver(bfin_sport_spi_driver);
index b8d25f2b7038a2d3c5400641b34285556fb1077e..3b83ff8b1e2b7ac60fb5494347fbc2a189b6dc14 100644 (file)
@@ -1098,7 +1098,7 @@ static int bfin_spi_setup(struct spi_device *spi)
 
        if (chip->pio_interrupt && !drv_data->irq_requested) {
                ret = request_irq(drv_data->spi_irq, bfin_spi_pio_irq_handler,
-                       IRQF_DISABLED, "BFIN_SPI", drv_data);
+                       0, "BFIN_SPI", drv_data);
                if (ret) {
                        dev_err(&spi->dev, "Unable to register spi IRQ\n");
                        goto error;
index ae2cd1c1fda8868d5febe3e151e7849045c571cd..6eee64a5d240d882647d15a2e80f2e547dda91f4 100644 (file)
@@ -487,7 +487,7 @@ static int __devinit mcfqspi_probe(struct platform_device *pdev)
                goto fail2;
        }
 
-       status = request_irq(mcfqspi->irq, mcfqspi_irq_handler, IRQF_DISABLED,
+       status = request_irq(mcfqspi->irq, mcfqspi_irq_handler, 0,
                             pdev->name, mcfqspi);
        if (status) {
                dev_dbg(&pdev->dev, "request_irq failed\n");
@@ -621,20 +621,10 @@ static struct platform_driver mcfqspi_driver = {
        .driver.name    = DRIVER_NAME,
        .driver.owner   = THIS_MODULE,
        .driver.pm      = MCFQSPI_DEV_PM_OPS,
+       .probe          = mcfqspi_probe,
        .remove         = __devexit_p(mcfqspi_remove),
 };
-
-static int __init mcfqspi_init(void)
-{
-       return platform_driver_probe(&mcfqspi_driver, mcfqspi_probe);
-}
-module_init(mcfqspi_init);
-
-static void __exit mcfqspi_exit(void)
-{
-       platform_driver_unregister(&mcfqspi_driver);
-}
-module_exit(mcfqspi_exit);
+module_platform_driver(mcfqspi_driver);
 
 MODULE_AUTHOR("Steven King <sfking@fdwdc.com>");
 MODULE_DESCRIPTION("Coldfire QSPI Controller Driver");
index 1f0ed8005c9170f3462d80a5e79e000c2ecc88ff..31bfba805cf473e51edbeb437a72666f9b735595 100644 (file)
@@ -799,7 +799,7 @@ rx_dma_failed:
  * It will invoke spi_bitbang_start to create work queue so that client driver
  * can register transfer method to work queue.
  */
-static int davinci_spi_probe(struct platform_device *pdev)
+static int __devinit davinci_spi_probe(struct platform_device *pdev)
 {
        struct spi_master *master;
        struct davinci_spi *dspi;
@@ -984,7 +984,7 @@ err:
  * It will also call spi_bitbang_stop to destroy the work queue which was
  * created by spi_bitbang_start.
  */
-static int __exit davinci_spi_remove(struct platform_device *pdev)
+static int __devexit davinci_spi_remove(struct platform_device *pdev)
 {
        struct davinci_spi *dspi;
        struct spi_master *master;
@@ -1011,20 +1011,10 @@ static struct platform_driver davinci_spi_driver = {
                .name = "spi_davinci",
                .owner = THIS_MODULE,
        },
-       .remove = __exit_p(davinci_spi_remove),
+       .probe = davinci_spi_probe,
+       .remove = __devexit_p(davinci_spi_remove),
 };
-
-static int __init davinci_spi_init(void)
-{
-       return platform_driver_probe(&davinci_spi_driver, davinci_spi_probe);
-}
-module_init(davinci_spi_init);
-
-static void __exit davinci_spi_exit(void)
-{
-       platform_driver_unregister(&davinci_spi_driver);
-}
-module_exit(davinci_spi_exit);
+module_platform_driver(davinci_spi_driver);
 
 MODULE_DESCRIPTION("TI DaVinci SPI Master Controller Driver");
 MODULE_LICENSE("GPL");
index 130e55537db602749b670464db6806227b98d867..e743a45ee92c265bd8a2e13ecec9f98cf3eb926c 100644 (file)
@@ -116,13 +116,13 @@ static int mid_spi_dma_transfer(struct dw_spi *dws, int cs_change)
        /* 1. setup DMA related registers */
        if (cs_change) {
                spi_enable_chip(dws, 0);
-               dw_writew(dws, dmardlr, 0xf);
-               dw_writew(dws, dmatdlr, 0x10);
+               dw_writew(dws, DW_SPI_DMARDLR, 0xf);
+               dw_writew(dws, DW_SPI_DMATDLR, 0x10);
                if (dws->tx_dma)
                        dma_ctrl |= 0x2;
                if (dws->rx_dma)
                        dma_ctrl |= 0x1;
-               dw_writew(dws, dmacr, dma_ctrl);
+               dw_writew(dws, DW_SPI_DMACR, dma_ctrl);
                spi_enable_chip(dws, 1);
        }
 
@@ -200,7 +200,8 @@ static struct dw_spi_dma_ops mid_dma_ops = {
 
 int dw_spi_mid_init(struct dw_spi *dws)
 {
-       u32 *clk_reg, clk_cdiv;
+       void __iomem *clk_reg;
+       u32 clk_cdiv;
 
        clk_reg = ioremap_nocache(MRST_CLK_SPI0_REG, 16);
        if (!clk_reg)
index 34eb66501dbf1ad081710cf2346e10e93dc6e66c..fac399c3022cd4a1045ac09f962309d9e9c63d23 100644 (file)
@@ -127,24 +127,14 @@ static int __devexit dw_spi_mmio_remove(struct platform_device *pdev)
 }
 
 static struct platform_driver dw_spi_mmio_driver = {
+       .probe          = dw_spi_mmio_probe,
        .remove         = __devexit_p(dw_spi_mmio_remove),
        .driver         = {
                .name   = DRIVER_NAME,
                .owner  = THIS_MODULE,
        },
 };
-
-static int __init dw_spi_mmio_init(void)
-{
-       return platform_driver_probe(&dw_spi_mmio_driver, dw_spi_mmio_probe);
-}
-module_init(dw_spi_mmio_init);
-
-static void __exit dw_spi_mmio_exit(void)
-{
-       platform_driver_unregister(&dw_spi_mmio_driver);
-}
-module_exit(dw_spi_mmio_exit);
+module_platform_driver(dw_spi_mmio_driver);
 
 MODULE_AUTHOR("Jean-Hugues Deschenes <jean-hugues.deschenes@octasic.com>");
 MODULE_DESCRIPTION("Memory-mapped I/O interface driver for DW SPI Core");
index 857cd30b44bbb7016d549df6767fe4329dec9e53..296d94f4cf723cea761c225b3497e5d01bcbb6f5 100644 (file)
@@ -88,35 +88,35 @@ static ssize_t  spi_show_regs(struct file *file, char __user *user_buf,
        len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
                        "=================================\n");
        len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
-                       "CTRL0: \t\t0x%08x\n", dw_readl(dws, ctrl0));
+                       "CTRL0: \t\t0x%08x\n", dw_readl(dws, DW_SPI_CTRL0));
        len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
-                       "CTRL1: \t\t0x%08x\n", dw_readl(dws, ctrl1));
+                       "CTRL1: \t\t0x%08x\n", dw_readl(dws, DW_SPI_CTRL1));
        len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
-                       "SSIENR: \t0x%08x\n", dw_readl(dws, ssienr));
+                       "SSIENR: \t0x%08x\n", dw_readl(dws, DW_SPI_SSIENR));
        len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
-                       "SER: \t\t0x%08x\n", dw_readl(dws, ser));
+                       "SER: \t\t0x%08x\n", dw_readl(dws, DW_SPI_SER));
        len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
-                       "BAUDR: \t\t0x%08x\n", dw_readl(dws, baudr));
+                       "BAUDR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_BAUDR));
        len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
-                       "TXFTLR: \t0x%08x\n", dw_readl(dws, txfltr));
+                       "TXFTLR: \t0x%08x\n", dw_readl(dws, DW_SPI_TXFLTR));
        len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
-                       "RXFTLR: \t0x%08x\n", dw_readl(dws, rxfltr));
+                       "RXFTLR: \t0x%08x\n", dw_readl(dws, DW_SPI_RXFLTR));
        len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
-                       "TXFLR: \t\t0x%08x\n", dw_readl(dws, txflr));
+                       "TXFLR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_TXFLR));
        len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
-                       "RXFLR: \t\t0x%08x\n", dw_readl(dws, rxflr));
+                       "RXFLR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_RXFLR));
        len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
-                       "SR: \t\t0x%08x\n", dw_readl(dws, sr));
+                       "SR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_SR));
        len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
-                       "IMR: \t\t0x%08x\n", dw_readl(dws, imr));
+                       "IMR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_IMR));
        len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
-                       "ISR: \t\t0x%08x\n", dw_readl(dws, isr));
+                       "ISR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_ISR));
        len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
-                       "DMACR: \t\t0x%08x\n", dw_readl(dws, dmacr));
+                       "DMACR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_DMACR));
        len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
-                       "DMATDLR: \t0x%08x\n", dw_readl(dws, dmatdlr));
+                       "DMATDLR: \t0x%08x\n", dw_readl(dws, DW_SPI_DMATDLR));
        len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
-                       "DMARDLR: \t0x%08x\n", dw_readl(dws, dmardlr));
+                       "DMARDLR: \t0x%08x\n", dw_readl(dws, DW_SPI_DMARDLR));
        len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
                        "=================================\n");
 
@@ -166,7 +166,7 @@ static inline u32 tx_max(struct dw_spi *dws)
        u32 tx_left, tx_room, rxtx_gap;
 
        tx_left = (dws->tx_end - dws->tx) / dws->n_bytes;
-       tx_room = dws->fifo_len - dw_readw(dws, txflr);
+       tx_room = dws->fifo_len - dw_readw(dws, DW_SPI_TXFLR);
 
        /*
         * Another concern is about the tx/rx mismatch, we
@@ -187,7 +187,7 @@ static inline u32 rx_max(struct dw_spi *dws)
 {
        u32 rx_left = (dws->rx_end - dws->rx) / dws->n_bytes;
 
-       return min(rx_left, (u32)dw_readw(dws, rxflr));
+       return min(rx_left, (u32)dw_readw(dws, DW_SPI_RXFLR));
 }
 
 static void dw_writer(struct dw_spi *dws)
@@ -203,7 +203,7 @@ static void dw_writer(struct dw_spi *dws)
                        else
                                txw = *(u16 *)(dws->tx);
                }
-               dw_writew(dws, dr, txw);
+               dw_writew(dws, DW_SPI_DR, txw);
                dws->tx += dws->n_bytes;
        }
 }
@@ -214,7 +214,7 @@ static void dw_reader(struct dw_spi *dws)
        u16 rxw;
 
        while (max--) {
-               rxw = dw_readw(dws, dr);
+               rxw = dw_readw(dws, DW_SPI_DR);
                /* Care rx only if the transfer's original "rx" is not null */
                if (dws->rx_end - dws->len) {
                        if (dws->n_bytes == 1)
@@ -322,13 +322,13 @@ EXPORT_SYMBOL_GPL(dw_spi_xfer_done);
 
 static irqreturn_t interrupt_transfer(struct dw_spi *dws)
 {
-       u16 irq_status = dw_readw(dws, isr);
+       u16 irq_status = dw_readw(dws, DW_SPI_ISR);
 
        /* Error handling */
        if (irq_status & (SPI_INT_TXOI | SPI_INT_RXOI | SPI_INT_RXUI)) {
-               dw_readw(dws, txoicr);
-               dw_readw(dws, rxoicr);
-               dw_readw(dws, rxuicr);
+               dw_readw(dws, DW_SPI_TXOICR);
+               dw_readw(dws, DW_SPI_RXOICR);
+               dw_readw(dws, DW_SPI_RXUICR);
                int_error_stop(dws, "interrupt_transfer: fifo overrun/underrun");
                return IRQ_HANDLED;
        }
@@ -352,7 +352,7 @@ static irqreturn_t interrupt_transfer(struct dw_spi *dws)
 static irqreturn_t dw_spi_irq(int irq, void *dev_id)
 {
        struct dw_spi *dws = dev_id;
-       u16 irq_status = dw_readw(dws, isr) & 0x3f;
+       u16 irq_status = dw_readw(dws, DW_SPI_ISR) & 0x3f;
 
        if (!irq_status)
                return IRQ_NONE;
@@ -520,11 +520,11 @@ static void pump_transfers(unsigned long data)
         *      2. clk_div is changed
         *      3. control value changes
         */
-       if (dw_readw(dws, ctrl0) != cr0 || cs_change || clk_div || imask) {
+       if (dw_readw(dws, DW_SPI_CTRL0) != cr0 || cs_change || clk_div || imask) {
                spi_enable_chip(dws, 0);
 
-               if (dw_readw(dws, ctrl0) != cr0)
-                       dw_writew(dws, ctrl0, cr0);
+               if (dw_readw(dws, DW_SPI_CTRL0) != cr0)
+                       dw_writew(dws, DW_SPI_CTRL0, cr0);
 
                spi_set_clk(dws, clk_div ? clk_div : chip->clk_div);
                spi_chip_sel(dws, spi->chip_select);
@@ -534,7 +534,7 @@ static void pump_transfers(unsigned long data)
                if (imask)
                        spi_umask_intr(dws, imask);
                if (txint_level)
-                       dw_writew(dws, txfltr, txint_level);
+                       dw_writew(dws, DW_SPI_TXFLTR, txint_level);
 
                spi_enable_chip(dws, 1);
                if (cs_change)
@@ -790,13 +790,13 @@ static void spi_hw_init(struct dw_spi *dws)
        if (!dws->fifo_len) {
                u32 fifo;
                for (fifo = 2; fifo <= 257; fifo++) {
-                       dw_writew(dws, txfltr, fifo);
-                       if (fifo != dw_readw(dws, txfltr))
+                       dw_writew(dws, DW_SPI_TXFLTR, fifo);
+                       if (fifo != dw_readw(dws, DW_SPI_TXFLTR))
                                break;
                }
 
                dws->fifo_len = (fifo == 257) ? 0 : fifo;
-               dw_writew(dws, txfltr, 0);
+               dw_writew(dws, DW_SPI_TXFLTR, 0);
        }
 }
 
index 8b7b07bf6c3f06580a8d26c5363e75a6738fa903..9c57c078031ead4ad4e2af02fb4b35c7b7d8b249 100644 (file)
@@ -4,6 +4,33 @@
 #include <linux/io.h>
 #include <linux/scatterlist.h>
 
+/* Register offsets */
+#define DW_SPI_CTRL0                   0x00
+#define DW_SPI_CTRL1                   0x04
+#define DW_SPI_SSIENR                  0x08
+#define DW_SPI_MWCR                    0x0c
+#define DW_SPI_SER                     0x10
+#define DW_SPI_BAUDR                   0x14
+#define DW_SPI_TXFLTR                  0x18
+#define DW_SPI_RXFLTR                  0x1c
+#define DW_SPI_TXFLR                   0x20
+#define DW_SPI_RXFLR                   0x24
+#define DW_SPI_SR                      0x28
+#define DW_SPI_IMR                     0x2c
+#define DW_SPI_ISR                     0x30
+#define DW_SPI_RISR                    0x34
+#define DW_SPI_TXOICR                  0x38
+#define DW_SPI_RXOICR                  0x3c
+#define DW_SPI_RXUICR                  0x40
+#define DW_SPI_MSTICR                  0x44
+#define DW_SPI_ICR                     0x48
+#define DW_SPI_DMACR                   0x4c
+#define DW_SPI_DMATDLR                 0x50
+#define DW_SPI_DMARDLR                 0x54
+#define DW_SPI_IDR                     0x58
+#define DW_SPI_VERSION                 0x5c
+#define DW_SPI_DR                      0x60
+
 /* Bit fields in CTRLR0 */
 #define SPI_DFS_OFFSET                 0
 
@@ -55,35 +82,6 @@ enum dw_ssi_type {
        SSI_NS_MICROWIRE,
 };
 
-struct dw_spi_reg {
-       u32     ctrl0;
-       u32     ctrl1;
-       u32     ssienr;
-       u32     mwcr;
-       u32     ser;
-       u32     baudr;
-       u32     txfltr;
-       u32     rxfltr;
-       u32     txflr;
-       u32     rxflr;
-       u32     sr;
-       u32     imr;
-       u32     isr;
-       u32     risr;
-       u32     txoicr;
-       u32     rxoicr;
-       u32     rxuicr;
-       u32     msticr;
-       u32     icr;
-       u32     dmacr;
-       u32     dmatdlr;
-       u32     dmardlr;
-       u32     idr;
-       u32     version;
-       u32     dr;             /* Currently oper as 32 bits,
-                               though only low 16 bits matters */
-} __packed;
-
 struct dw_spi;
 struct dw_spi_dma_ops {
        int (*dma_init)(struct dw_spi *dws);
@@ -161,23 +159,34 @@ struct dw_spi {
 #endif
 };
 
-#define dw_readl(dw, name) \
-       __raw_readl(&(((struct dw_spi_reg *)dw->regs)->name))
-#define dw_writel(dw, name, val) \
-       __raw_writel((val), &(((struct dw_spi_reg *)dw->regs)->name))
-#define dw_readw(dw, name) \
-       __raw_readw(&(((struct dw_spi_reg *)dw->regs)->name))
-#define dw_writew(dw, name, val) \
-       __raw_writew((val), &(((struct dw_spi_reg *)dw->regs)->name))
+static inline u32 dw_readl(struct dw_spi *dws, u32 offset)
+{
+       return __raw_readl(dws->regs + offset);
+}
+
+static inline void dw_writel(struct dw_spi *dws, u32 offset, u32 val)
+{
+       __raw_writel(val, dws->regs + offset);
+}
+
+static inline u16 dw_readw(struct dw_spi *dws, u32 offset)
+{
+       return __raw_readw(dws->regs + offset);
+}
+
+static inline void dw_writew(struct dw_spi *dws, u32 offset, u16 val)
+{
+       __raw_writew(val, dws->regs + offset);
+}
 
 static inline void spi_enable_chip(struct dw_spi *dws, int enable)
 {
-       dw_writel(dws, ssienr, (enable ? 1 : 0));
+       dw_writel(dws, DW_SPI_SSIENR, (enable ? 1 : 0));
 }
 
 static inline void spi_set_clk(struct dw_spi *dws, u16 div)
 {
-       dw_writel(dws, baudr, div);
+       dw_writel(dws, DW_SPI_BAUDR, div);
 }
 
 static inline void spi_chip_sel(struct dw_spi *dws, u16 cs)
@@ -188,7 +197,7 @@ static inline void spi_chip_sel(struct dw_spi *dws, u16 cs)
        if (dws->cs_control)
                dws->cs_control(1);
 
-       dw_writel(dws, ser, 1 << cs);
+       dw_writel(dws, DW_SPI_SER, 1 << cs);
 }
 
 /* Disable IRQ bits */
@@ -196,8 +205,8 @@ static inline void spi_mask_intr(struct dw_spi *dws, u32 mask)
 {
        u32 new_mask;
 
-       new_mask = dw_readl(dws, imr) & ~mask;
-       dw_writel(dws, imr, new_mask);
+       new_mask = dw_readl(dws, DW_SPI_IMR) & ~mask;
+       dw_writel(dws, DW_SPI_IMR, new_mask);
 }
 
 /* Enable IRQ bits */
@@ -205,8 +214,8 @@ static inline void spi_umask_intr(struct dw_spi *dws, u32 mask)
 {
        u32 new_mask;
 
-       new_mask = dw_readl(dws, imr) | mask;
-       dw_writel(dws, imr, new_mask);
+       new_mask = dw_readl(dws, DW_SPI_IMR) | mask;
+       dw_writel(dws, DW_SPI_IMR, new_mask);
 }
 
 /*
index 1cf645479bfec6b1cc7a2d2dc76d4e0e295fb8bc..0a282e5fcc9c3fe4931a871acd6d89708162bd0d 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/dmaengine.h>
 #include <linux/bitops.h>
 #include <linux/interrupt.h>
+#include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/workqueue.h>
 #include <linux/sched.h>
@@ -1025,7 +1026,7 @@ static void ep93xx_spi_release_dma(struct ep93xx_spi *espi)
                free_page((unsigned long)espi->zeropage);
 }
 
-static int __init ep93xx_spi_probe(struct platform_device *pdev)
+static int __devinit ep93xx_spi_probe(struct platform_device *pdev)
 {
        struct spi_master *master;
        struct ep93xx_spi_info *info;
@@ -1150,7 +1151,7 @@ fail_release_master:
        return error;
 }
 
-static int __exit ep93xx_spi_remove(struct platform_device *pdev)
+static int __devexit ep93xx_spi_remove(struct platform_device *pdev)
 {
        struct spi_master *master = platform_get_drvdata(pdev);
        struct ep93xx_spi *espi = spi_master_get_devdata(master);
@@ -1196,20 +1197,10 @@ static struct platform_driver ep93xx_spi_driver = {
                .name   = "ep93xx-spi",
                .owner  = THIS_MODULE,
        },
-       .remove         = __exit_p(ep93xx_spi_remove),
+       .probe          = ep93xx_spi_probe,
+       .remove         = __devexit_p(ep93xx_spi_remove),
 };
-
-static int __init ep93xx_spi_init(void)
-{
-       return platform_driver_probe(&ep93xx_spi_driver, ep93xx_spi_probe);
-}
-module_init(ep93xx_spi_init);
-
-static void __exit ep93xx_spi_exit(void)
-{
-       platform_driver_unregister(&ep93xx_spi_driver);
-}
-module_exit(ep93xx_spi_exit);
+module_platform_driver(ep93xx_spi_driver);
 
 MODULE_DESCRIPTION("EP93xx SPI Controller driver");
 MODULE_AUTHOR("Mika Westerberg <mika.westerberg@iki.fi>");
index 54e499d5f92cb043d805517db43983def2d52b01..d770f03705c32b86a661dfc0a83d7997b7bfda1c 100644 (file)
@@ -744,18 +744,7 @@ static struct platform_driver fsl_espi_driver = {
        .probe          = of_fsl_espi_probe,
        .remove         = __devexit_p(of_fsl_espi_remove),
 };
-
-static int __init fsl_espi_init(void)
-{
-       return platform_driver_register(&fsl_espi_driver);
-}
-module_init(fsl_espi_init);
-
-static void __exit fsl_espi_exit(void)
-{
-       platform_driver_unregister(&fsl_espi_driver);
-}
-module_exit(fsl_espi_exit);
+module_platform_driver(fsl_espi_driver);
 
 MODULE_AUTHOR("Mingkai Hu");
 MODULE_DESCRIPTION("Enhanced Freescale SPI Driver");
index 0e88ab7454906ddb5dce94997dc51e84965559ea..635ff08b377f999c5f46ca21603272c97f60e277 100644 (file)
@@ -311,7 +311,7 @@ done:
        return value;
 }
 
-static int __init spi_gpio_probe(struct platform_device *pdev)
+static int __devinit spi_gpio_probe(struct platform_device *pdev)
 {
        int                             status;
        struct spi_master               *master;
@@ -379,7 +379,7 @@ gpio_free:
        return status;
 }
 
-static int __exit spi_gpio_remove(struct platform_device *pdev)
+static int __devexit spi_gpio_remove(struct platform_device *pdev)
 {
        struct spi_gpio                 *spi_gpio;
        struct spi_gpio_platform_data   *pdata;
@@ -408,21 +408,10 @@ MODULE_ALIAS("platform:" DRIVER_NAME);
 static struct platform_driver spi_gpio_driver = {
        .driver.name    = DRIVER_NAME,
        .driver.owner   = THIS_MODULE,
-       .remove         = __exit_p(spi_gpio_remove),
+       .probe          = spi_gpio_probe,
+       .remove         = __devexit_p(spi_gpio_remove),
 };
-
-static int __init spi_gpio_init(void)
-{
-       return platform_driver_probe(&spi_gpio_driver, spi_gpio_probe);
-}
-module_init(spi_gpio_init);
-
-static void __exit spi_gpio_exit(void)
-{
-       platform_driver_unregister(&spi_gpio_driver);
-}
-module_exit(spi_gpio_exit);
-
+module_platform_driver(spi_gpio_driver);
 
 MODULE_DESCRIPTION("SPI master driver using generic bitbanged GPIO ");
 MODULE_AUTHOR("David Brownell");
index fa594d604acae4501986125e5ca25f6e2b8e3c22..c6e697f5e007a7642db7e30e6025160bf783ded9 100644 (file)
@@ -929,19 +929,7 @@ static struct platform_driver spi_imx_driver = {
        .probe = spi_imx_probe,
        .remove = __devexit_p(spi_imx_remove),
 };
-
-static int __init spi_imx_init(void)
-{
-       return platform_driver_register(&spi_imx_driver);
-}
-
-static void __exit spi_imx_exit(void)
-{
-       platform_driver_unregister(&spi_imx_driver);
-}
-
-module_init(spi_imx_init);
-module_exit(spi_imx_exit);
+module_platform_driver(spi_imx_driver);
 
 MODULE_DESCRIPTION("SPI Master Controller driver");
 MODULE_AUTHOR("Sascha Hauer, Pengutronix");
index 6a5b4238fb6bd2dd43a0743371ed0550996f5333..4c63f772780adaf64e1412af167c791123eecb13 100644 (file)
@@ -559,18 +559,7 @@ static struct platform_driver mpc512x_psc_spi_of_driver = {
                .of_match_table = mpc512x_psc_spi_of_match,
        },
 };
-
-static int __init mpc512x_psc_spi_init(void)
-{
-       return platform_driver_register(&mpc512x_psc_spi_of_driver);
-}
-module_init(mpc512x_psc_spi_init);
-
-static void __exit mpc512x_psc_spi_exit(void)
-{
-       platform_driver_unregister(&mpc512x_psc_spi_of_driver);
-}
-module_exit(mpc512x_psc_spi_exit);
+module_platform_driver(mpc512x_psc_spi_of_driver);
 
 MODULE_AUTHOR("John Rigby");
 MODULE_DESCRIPTION("MPC512x PSC SPI Driver");
index e30baf0852ac78bf338fd31b7869896169649d37..66047156d90dbc8d1bd9980492050629ad1f40d1 100644 (file)
@@ -511,18 +511,7 @@ static struct platform_driver mpc52xx_psc_spi_of_driver = {
                .of_match_table = mpc52xx_psc_spi_of_match,
        },
 };
-
-static int __init mpc52xx_psc_spi_init(void)
-{
-       return platform_driver_register(&mpc52xx_psc_spi_of_driver);
-}
-module_init(mpc52xx_psc_spi_init);
-
-static void __exit mpc52xx_psc_spi_exit(void)
-{
-       platform_driver_unregister(&mpc52xx_psc_spi_of_driver);
-}
-module_exit(mpc52xx_psc_spi_exit);
+module_platform_driver(mpc52xx_psc_spi_of_driver);
 
 MODULE_AUTHOR("Dragos Carp");
 MODULE_DESCRIPTION("MPC52xx PSC SPI Driver");
index 015a974bed72d83b40d15407597c84749490ba66..57633d9634565682b8d89cfb66644e623c66ced8 100644 (file)
@@ -564,16 +564,4 @@ static struct platform_driver mpc52xx_spi_of_driver = {
        .probe = mpc52xx_spi_probe,
        .remove = __devexit_p(mpc52xx_spi_remove),
 };
-
-static int __init mpc52xx_spi_init(void)
-{
-       return platform_driver_register(&mpc52xx_spi_of_driver);
-}
-module_init(mpc52xx_spi_init);
-
-static void __exit mpc52xx_spi_exit(void)
-{
-       platform_driver_unregister(&mpc52xx_spi_of_driver);
-}
-module_exit(mpc52xx_spi_exit);
-
+module_platform_driver(mpc52xx_spi_of_driver);
index c0a6ce81f9c0e4ba42246395f5f60ec712f0075a..e763254741c296169b6d662d5f398c1a90170cc2 100644 (file)
@@ -484,19 +484,7 @@ static struct platform_driver nuc900_spi_driver = {
                .owner  = THIS_MODULE,
        },
 };
-
-static int __init nuc900_spi_init(void)
-{
-       return platform_driver_register(&nuc900_spi_driver);
-}
-
-static void __exit nuc900_spi_exit(void)
-{
-       platform_driver_unregister(&nuc900_spi_driver);
-}
-
-module_init(nuc900_spi_init);
-module_exit(nuc900_spi_exit);
+module_platform_driver(nuc900_spi_driver);
 
 MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>");
 MODULE_DESCRIPTION("nuc900 spi driver!");
index f1bde66cea1940efefd812df590c415a46dd1c40..897274e8715c1913413d96b483f4fdc4f70553bf 100644 (file)
@@ -406,18 +406,7 @@ static struct platform_driver tiny_spi_driver = {
                .of_match_table = tiny_spi_match,
        },
 };
-
-static int __init tiny_spi_init(void)
-{
-       return platform_driver_register(&tiny_spi_driver);
-}
-module_init(tiny_spi_init);
-
-static void __exit tiny_spi_exit(void)
-{
-       platform_driver_unregister(&tiny_spi_driver);
-}
-module_exit(tiny_spi_exit);
+module_platform_driver(tiny_spi_driver);
 
 MODULE_DESCRIPTION("OpenCores tiny SPI driver");
 MODULE_AUTHOR("Thomas Chou <thomas@wytron.com.tw>");
index fde3a2d4f120deffdae739058622ae7c527a5529..322be7aea8b429d24e78c1de6986dbf5b91efcb3 100644 (file)
@@ -1116,15 +1116,16 @@ static int __init omap2_mcspi_probe(struct platform_device *pdev)
                status = -ENODEV;
                goto err1;
        }
+
+       r->start += pdata->regs_offset;
+       r->end += pdata->regs_offset;
+       mcspi->phys = r->start;
        if (!request_mem_region(r->start, resource_size(r),
                                dev_name(&pdev->dev))) {
                status = -EBUSY;
                goto err1;
        }
 
-       r->start += pdata->regs_offset;
-       r->end += pdata->regs_offset;
-       mcspi->phys = r->start;
        mcspi->base = ioremap(r->start, resource_size(r));
        if (!mcspi->base) {
                dev_dbg(&pdev->dev, "can't ioremap MCSPI\n");
index 1ab2fa0d37fd7d0d6dea52e0dd801cbd8a4cea52..f103e470cb6362e248a264576e457e03f0ab5409 100644 (file)
 #define SSP_CR0_MASK_CSS_ST    (0x1FUL << 16)
 #define SSP_CR0_MASK_FRF_ST    (0x3UL << 21)
 
-
 /*
  * SSP Control Register 0  - SSP_CR1
  */
 
 #define SPI_POLLING_TIMEOUT 1000
 
-
 /*
  * The type of reading going on on this chip
  */
@@ -749,7 +747,6 @@ static void readwriter(struct pl022 *pl022)
         */
 }
 
-
 /**
  * next_transfer - Move to the Next transfer in the current spi message
  * @pl022: SSP driver private data structure
@@ -1016,14 +1013,14 @@ static int configure_dma(struct pl022 *pl022)
        dmaengine_slave_config(txchan, &tx_conf);
 
        /* Create sglists for the transfers */
-       pages = (pl022->cur_transfer->len >> PAGE_SHIFT) + 1;
+       pages = DIV_ROUND_UP(pl022->cur_transfer->len, PAGE_SIZE);
        dev_dbg(&pl022->adev->dev, "using %d pages for transfer\n", pages);
 
-       ret = sg_alloc_table(&pl022->sgt_rx, pages, GFP_KERNEL);
+       ret = sg_alloc_table(&pl022->sgt_rx, pages, GFP_ATOMIC);
        if (ret)
                goto err_alloc_rx_sg;
 
-       ret = sg_alloc_table(&pl022->sgt_tx, pages, GFP_KERNEL);
+       ret = sg_alloc_table(&pl022->sgt_tx, pages, GFP_ATOMIC);
        if (ret)
                goto err_alloc_tx_sg;
 
@@ -1531,8 +1528,7 @@ static void pump_messages(struct work_struct *work)
        /* Initial message state */
        pl022->cur_msg->state = STATE_START;
        pl022->cur_transfer = list_entry(pl022->cur_msg->transfers.next,
-                                           struct spi_transfer,
-                                           transfer_list);
+                                           struct spi_transfer, transfer_list);
 
        /* Setup the SPI using the per chip configuration */
        pl022->cur_chip = spi_get_ctldata(pl022->cur_msg->spi);
@@ -1551,7 +1547,6 @@ static void pump_messages(struct work_struct *work)
                do_interrupt_dma_transfer(pl022);
 }
 
-
 static int __init init_queue(struct pl022 *pl022)
 {
        INIT_LIST_HEAD(&pl022->queue);
@@ -1560,8 +1555,8 @@ static int __init init_queue(struct pl022 *pl022)
        pl022->running = false;
        pl022->busy = false;
 
-       tasklet_init(&pl022->pump_transfers,
-                       pump_transfers, (unsigned long)pl022);
+       tasklet_init(&pl022->pump_transfers, pump_transfers,
+                       (unsigned long)pl022);
 
        INIT_WORK(&pl022->pump_messages, pump_messages);
        pl022->workqueue = create_singlethread_workqueue(
@@ -1572,7 +1567,6 @@ static int __init init_queue(struct pl022 *pl022)
        return 0;
 }
 
-
 static int start_queue(struct pl022 *pl022)
 {
        unsigned long flags;
@@ -1595,7 +1589,6 @@ static int start_queue(struct pl022 *pl022)
        return 0;
 }
 
-
 static int stop_queue(struct pl022 *pl022)
 {
        unsigned long flags;
@@ -1791,71 +1784,70 @@ static int pl022_transfer(struct spi_device *spi, struct spi_message *msg)
        return 0;
 }
 
-static int calculate_effective_freq(struct pl022 *pl022,
-                                   int freq,
-                                   struct ssp_clock_params *clk_freq)
+static inline u32 spi_rate(u32 rate, u16 cpsdvsr, u16 scr)
+{
+       return rate / (cpsdvsr * (1 + scr));
+}
+
+static int calculate_effective_freq(struct pl022 *pl022, int freq, struct
+                                   ssp_clock_params * clk_freq)
 {
        /* Lets calculate the frequency parameters */
-       u16 cpsdvsr = 2;
-       u16 scr = 0;
-       bool freq_found = false;
-       u32 rate;
-       u32 max_tclk;
-       u32 min_tclk;
+       u16 cpsdvsr = CPSDVR_MIN, scr = SCR_MIN;
+       u32 rate, max_tclk, min_tclk, best_freq = 0, best_cpsdvsr = 0,
+               best_scr = 0, tmp, found = 0;
 
        rate = clk_get_rate(pl022->clk);
        /* cpsdvscr = 2 & scr 0 */
-       max_tclk = (rate / (CPSDVR_MIN * (1 + SCR_MIN)));
+       max_tclk = spi_rate(rate, CPSDVR_MIN, SCR_MIN);
        /* cpsdvsr = 254 & scr = 255 */
-       min_tclk = (rate / (CPSDVR_MAX * (1 + SCR_MAX)));
-
-       if ((freq <= max_tclk) && (freq >= min_tclk)) {
-               while (cpsdvsr <= CPSDVR_MAX && !freq_found) {
-                       while (scr <= SCR_MAX && !freq_found) {
-                               if ((rate /
-                                    (cpsdvsr * (1 + scr))) > freq)
-                                       scr += 1;
-                               else {
-                                       /*
-                                        * This bool is made true when
-                                        * effective frequency >=
-                                        * target frequency is found
-                                        */
-                                       freq_found = true;
-                                       if ((rate /
-                                            (cpsdvsr * (1 + scr))) != freq) {
-                                               if (scr == SCR_MIN) {
-                                                       cpsdvsr -= 2;
-                                                       scr = SCR_MAX;
-                                               } else
-                                                       scr -= 1;
-                                       }
-                               }
-                       }
-                       if (!freq_found) {
-                               cpsdvsr += 2;
-                               scr = SCR_MIN;
-                       }
-               }
-               if (cpsdvsr != 0) {
-                       dev_dbg(&pl022->adev->dev,
-                               "SSP Effective Frequency is %u\n",
-                               (rate / (cpsdvsr * (1 + scr))));
-                       clk_freq->cpsdvsr = (u8) (cpsdvsr & 0xFF);
-                       clk_freq->scr = (u8) (scr & 0xFF);
-                       dev_dbg(&pl022->adev->dev,
-                               "SSP cpsdvsr = %d, scr = %d\n",
-                               clk_freq->cpsdvsr, clk_freq->scr);
-               }
-       } else {
+       min_tclk = spi_rate(rate, CPSDVR_MAX, SCR_MAX);
+
+       if (!((freq <= max_tclk) && (freq >= min_tclk))) {
                dev_err(&pl022->adev->dev,
                        "controller data is incorrect: out of range frequency");
                return -EINVAL;
        }
+
+       /*
+        * best_freq will give closest possible available rate (<= requested
+        * freq) for all values of scr & cpsdvsr.
+        */
+       while ((cpsdvsr <= CPSDVR_MAX) && !found) {
+               while (scr <= SCR_MAX) {
+                       tmp = spi_rate(rate, cpsdvsr, scr);
+
+                       if (tmp > freq)
+                               scr++;
+                       /*
+                        * If found exact value, update and break.
+                        * If found more closer value, update and continue.
+                        */
+                       else if ((tmp == freq) || (tmp > best_freq)) {
+                               best_freq = tmp;
+                               best_cpsdvsr = cpsdvsr;
+                               best_scr = scr;
+
+                               if (tmp == freq)
+                                       break;
+                       }
+                       scr++;
+               }
+               cpsdvsr += 2;
+               scr = SCR_MIN;
+       }
+
+       clk_freq->cpsdvsr = (u8) (best_cpsdvsr & 0xFF);
+       clk_freq->scr = (u8) (best_scr & 0xFF);
+       dev_dbg(&pl022->adev->dev,
+               "SSP Target Frequency is: %u, Effective Frequency is %u\n",
+               freq, best_freq);
+       dev_dbg(&pl022->adev->dev, "SSP cpsdvsr = %d, scr = %d\n",
+               clk_freq->cpsdvsr, clk_freq->scr);
+
        return 0;
 }
 
-
 /*
  * A piece of default chip info unless the platform
  * supplies it.
@@ -1873,7 +1865,6 @@ static const struct pl022_config_chip pl022_default_chip_info = {
        .cs_control = null_cs_control,
 };
 
-
 /**
  * pl022_setup - setup function registered to SPI master framework
  * @spi: spi device which is requesting setup
@@ -1950,7 +1941,6 @@ static int pl022_setup(struct spi_device *spi)
                goto err_config_params;
        }
 
-
        status = verify_controller_parameters(pl022, chip_info);
        if (status) {
                dev_err(&spi->dev, "controller data is incorrect");
@@ -2090,7 +2080,8 @@ static int pl022_setup(struct spi_device *spi)
        }
        SSP_WRITE_BITS(chip->cr1, SSP_DISABLED, SSP_CR1_MASK_SSE, 1);
        SSP_WRITE_BITS(chip->cr1, chip_info->hierarchy, SSP_CR1_MASK_MS, 2);
-       SSP_WRITE_BITS(chip->cr1, chip_info->slave_tx_disable, SSP_CR1_MASK_SOD, 3);
+       SSP_WRITE_BITS(chip->cr1, chip_info->slave_tx_disable, SSP_CR1_MASK_SOD,
+               3);
 
        /* Save controller_state */
        spi_set_ctldata(spi, chip);
@@ -2116,7 +2107,6 @@ static void pl022_cleanup(struct spi_device *spi)
        kfree(chip);
 }
 
-
 static int __devinit
 pl022_probe(struct amba_device *adev, const struct amba_id *id)
 {
@@ -2242,7 +2232,9 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id)
  err_start_queue:
  err_init_queue:
        destroy_queue(pl022);
-       pl022_dma_remove(pl022);
+       if (platform_info->enable_dma)
+               pl022_dma_remove(pl022);
+
        free_irq(adev->irq[0], pl022);
  err_no_irq:
        clk_unprepare(pl022->clk);
@@ -2277,7 +2269,9 @@ pl022_remove(struct amba_device *adev)
        if (destroy_queue(pl022) != 0)
                dev_err(&adev->dev, "queue remove failed\n");
        load_ssp_default_config(pl022);
-       pl022_dma_remove(pl022);
+       if (pl022->master_info->enable_dma)
+               pl022_dma_remove(pl022);
+
        free_irq(adev->irq[0], pl022);
        clk_disable(pl022->clk);
        clk_unprepare(pl022->clk);
@@ -2364,7 +2358,6 @@ static struct vendor_data vendor_arm = {
        .loopback = true,
 };
 
-
 static struct vendor_data vendor_st = {
        .fifodepth = 32,
        .max_bpw = 32,
@@ -2419,9 +2412,9 @@ static struct amba_id pl022_ids[] = {
                 * and 32 locations deep TX/RX FIFO but no extended
                 * CR0/CR1 register
                 */
-               .id     = 0x00080023,
-               .mask   = 0xffffffff,
-               .data   = &vendor_st_pl023,
+               .id     = 0x00080023,
+               .mask   = 0xffffffff,
+               .data   = &vendor_st_pl023,
        },
        {
                .id     = 0x10080023,
@@ -2441,19 +2434,16 @@ static struct amba_driver pl022_driver = {
        .remove         = __devexit_p(pl022_remove),
 };
 
-
 static int __init pl022_init(void)
 {
        return amba_driver_register(&pl022_driver);
 }
-
 subsys_initcall(pl022_init);
 
 static void __exit pl022_exit(void)
 {
        amba_driver_unregister(&pl022_driver);
 }
-
 module_exit(pl022_exit);
 
 MODULE_AUTHOR("Linus Walleij <linus.walleij@stericsson.com>");
index b267fd901e54d92dfefd07bcbfb1a69e87b18923..98ec53285fc7b03781160ec6da6c222e03821946 100644 (file)
@@ -514,7 +514,7 @@ static int __init spi_ppc4xx_of_probe(struct platform_device *op)
        /* Request IRQ */
        hw->irqnum = irq_of_parse_and_map(np, 0);
        ret = request_irq(hw->irqnum, spi_ppc4xx_int,
-                         IRQF_DISABLED, "spi_ppc4xx_of", (void *)hw);
+                         0, "spi_ppc4xx_of", (void *)hw);
        if (ret) {
                dev_err(dev, "unable to allocate interrupt\n");
                goto free_gpios;
@@ -594,18 +594,7 @@ static struct platform_driver spi_ppc4xx_of_driver = {
                .of_match_table = spi_ppc4xx_of_match,
        },
 };
-
-static int __init spi_ppc4xx_init(void)
-{
-       return platform_driver_register(&spi_ppc4xx_of_driver);
-}
-module_init(spi_ppc4xx_init);
-
-static void __exit spi_ppc4xx_exit(void)
-{
-       platform_driver_unregister(&spi_ppc4xx_of_driver);
-}
-module_exit(spi_ppc4xx_exit);
+module_platform_driver(spi_ppc4xx_of_driver);
 
 MODULE_AUTHOR("Gary Jennejohn & Stefan Roese");
 MODULE_DESCRIPTION("Simple PPC4xx SPI Driver");
index 1996ac57ef919186341a6c65d6a8ea89569825ef..b857a3e7af949138d136872339d17231bc7830dc 100644 (file)
@@ -505,7 +505,7 @@ static void s3c24xx_spi_initialsetup(struct s3c24xx_spi *hw)
        }
 }
 
-static int __init s3c24xx_spi_probe(struct platform_device *pdev)
+static int __devinit s3c24xx_spi_probe(struct platform_device *pdev)
 {
        struct s3c2410_spi_info *pdata;
        struct s3c24xx_spi *hw;
@@ -661,7 +661,7 @@ static int __init s3c24xx_spi_probe(struct platform_device *pdev)
        return err;
 }
 
-static int __exit s3c24xx_spi_remove(struct platform_device *dev)
+static int __devexit s3c24xx_spi_remove(struct platform_device *dev)
 {
        struct s3c24xx_spi *hw = platform_get_drvdata(dev);
 
@@ -719,26 +719,15 @@ static const struct dev_pm_ops s3c24xx_spi_pmops = {
 
 MODULE_ALIAS("platform:s3c2410-spi");
 static struct platform_driver s3c24xx_spi_driver = {
-       .remove         = __exit_p(s3c24xx_spi_remove),
+       .probe          = s3c24xx_spi_probe,
+       .remove         = __devexit_p(s3c24xx_spi_remove),
        .driver         = {
                .name   = "s3c2410-spi",
                .owner  = THIS_MODULE,
                .pm     = S3C24XX_SPI_PMOPS,
        },
 };
-
-static int __init s3c24xx_spi_init(void)
-{
-        return platform_driver_probe(&s3c24xx_spi_driver, s3c24xx_spi_probe);
-}
-
-static void __exit s3c24xx_spi_exit(void)
-{
-        platform_driver_unregister(&s3c24xx_spi_driver);
-}
-
-module_init(s3c24xx_spi_init);
-module_exit(s3c24xx_spi_exit);
+module_platform_driver(s3c24xx_spi_driver);
 
 MODULE_DESCRIPTION("S3C24XX SPI Driver");
 MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
index e00d94b22250a5d368146fa28c87aa3be9e5a565..0f4834ae28cdea08f0ff995708001a2a2c67cf56 100644 (file)
@@ -635,7 +635,7 @@ static int sh_msiof_spi_probe(struct platform_device *pdev)
                goto err2;
        }
 
-       ret = request_irq(i, sh_msiof_spi_irq, IRQF_DISABLED,
+       ret = request_irq(i, sh_msiof_spi_irq, 0,
                          dev_name(&pdev->dev), p);
        if (ret) {
                dev_err(&pdev->dev, "unable to request irq\n");
@@ -730,18 +730,7 @@ static struct platform_driver sh_msiof_spi_drv = {
                .pm             = &sh_msiof_spi_dev_pm_ops,
        },
 };
-
-static int __init sh_msiof_spi_init(void)
-{
-       return platform_driver_register(&sh_msiof_spi_drv);
-}
-module_init(sh_msiof_spi_init);
-
-static void __exit sh_msiof_spi_exit(void)
-{
-       platform_driver_unregister(&sh_msiof_spi_drv);
-}
-module_exit(sh_msiof_spi_exit);
+module_platform_driver(sh_msiof_spi_drv);
 
 MODULE_DESCRIPTION("SuperH MSIOF SPI Master Interface Driver");
 MODULE_AUTHOR("Magnus Damm");
index e7779c09f6efb0e5564dd2a4cf0880b93ac17bd3..8844bc3427824209808519db50eb94fdaccb4b8d 100644 (file)
@@ -186,18 +186,7 @@ static struct platform_driver sh_sci_spi_drv = {
                .owner  = THIS_MODULE,
        },
 };
-
-static int __init sh_sci_spi_init(void)
-{
-       return platform_driver_register(&sh_sci_spi_drv);
-}
-module_init(sh_sci_spi_init);
-
-static void __exit sh_sci_spi_exit(void)
-{
-       platform_driver_unregister(&sh_sci_spi_drv);
-}
-module_exit(sh_sci_spi_exit);
+module_platform_driver(sh_sci_spi_drv);
 
 MODULE_DESCRIPTION("SH SCI SPI Driver");
 MODULE_AUTHOR("Magnus Damm <damm@opensource.se>");
index 9eedd71ad898c172f3bf34c57909530f55b91e19..70c8af9f7cccbc7ad9c01d9202f2b34af7b976ed 100644 (file)
@@ -484,7 +484,7 @@ static int __devinit spi_sh_probe(struct platform_device *pdev)
                goto error2;
        }
 
-       ret = request_irq(irq, spi_sh_irq, IRQF_DISABLED, "spi_sh", ss);
+       ret = request_irq(irq, spi_sh_irq, 0, "spi_sh", ss);
        if (ret < 0) {
                dev_err(&pdev->dev, "request_irq error\n");
                goto error3;
@@ -524,18 +524,7 @@ static struct platform_driver spi_sh_driver = {
                .owner = THIS_MODULE,
        },
 };
-
-static int __init spi_sh_init(void)
-{
-       return platform_driver_register(&spi_sh_driver);
-}
-module_init(spi_sh_init);
-
-static void __exit spi_sh_exit(void)
-{
-       platform_driver_unregister(&spi_sh_driver);
-}
-module_exit(spi_sh_exit);
+module_platform_driver(spi_sh_driver);
 
 MODULE_DESCRIPTION("SH SPI bus driver");
 MODULE_LICENSE("GPL");
index fadff76eb7e06807e5171dc074b5416db02d032b..58e38528532393f89c0b8688469ad3af8a982b21 100644 (file)
@@ -659,19 +659,8 @@ static struct platform_driver stmp_spi_driver = {
        .suspend = stmp_spi_suspend,
        .resume  = stmp_spi_resume,
 };
+module_platform_driver(stmp_spi_driver);
 
-static int __init stmp_spi_init(void)
-{
-       return platform_driver_register(&stmp_spi_driver);
-}
-
-static void __exit stmp_spi_exit(void)
-{
-       platform_driver_unregister(&stmp_spi_driver);
-}
-
-module_init(stmp_spi_init);
-module_exit(stmp_spi_exit);
 module_param(pio, int, S_IRUGO);
 module_param(clock, int, S_IRUGO);
 MODULE_AUTHOR("dmitry pervushin <dpervushin@embeddedalley.com>");
index a5a6302dc8e062911da66693ea18903f67247879..ae6d78a3e9129a483ecf60ee5919dc4a685b3235 100644 (file)
@@ -18,6 +18,7 @@
  */
 
 #include <linux/kernel.h>
+#include <linux/module.h>
 #include <linux/init.h>
 #include <linux/err.h>
 #include <linux/platform_device.h>
@@ -464,7 +465,7 @@ static int spi_tegra_transfer(struct spi_device *spi, struct spi_message *m)
        return 0;
 }
 
-static int __init spi_tegra_probe(struct platform_device *pdev)
+static int __devinit spi_tegra_probe(struct platform_device *pdev)
 {
        struct spi_master       *master;
        struct spi_tegra_data   *tspi;
@@ -612,19 +613,9 @@ static struct platform_driver spi_tegra_driver = {
                .owner =        THIS_MODULE,
                .of_match_table = spi_tegra_of_match_table,
        },
+       .probe =        spi_tegra_probe,
        .remove =       __devexit_p(spi_tegra_remove),
 };
-
-static int __init spi_tegra_init(void)
-{
-       return platform_driver_probe(&spi_tegra_driver, spi_tegra_probe);
-}
-module_init(spi_tegra_init);
-
-static void __exit spi_tegra_exit(void)
-{
-       platform_driver_unregister(&spi_tegra_driver);
-}
-module_exit(spi_tegra_exit);
+module_platform_driver(spi_tegra_driver);
 
 MODULE_LICENSE("GPL");
index ee22795c7973fdf250a94f50b215afc8419bcb0c..7963c60063d6843bae1aea0d63dea4d7d80f13d0 100644 (file)
@@ -383,18 +383,7 @@ static struct platform_driver ti_ssp_spi_driver = {
                .owner  = THIS_MODULE,
        },
 };
-
-static int __init ti_ssp_spi_init(void)
-{
-       return platform_driver_register(&ti_ssp_spi_driver);
-}
-module_init(ti_ssp_spi_init);
-
-static void __exit ti_ssp_spi_exit(void)
-{
-       platform_driver_unregister(&ti_ssp_spi_driver);
-}
-module_exit(ti_ssp_spi_exit);
+module_platform_driver(ti_ssp_spi_driver);
 
 MODULE_DESCRIPTION("SSP SPI Master");
 MODULE_AUTHOR("Cyril Chemparathy");
index 4d2c75df886c88621e43a453db625e59e7876ccf..4c5a663b9fa897e4a510f6cf6dbba084efc6bfb6 100644 (file)
@@ -538,18 +538,7 @@ static struct platform_driver xilinx_spi_driver = {
                .of_match_table = xilinx_spi_of_match,
        },
 };
-
-static int __init xilinx_spi_pltfm_init(void)
-{
-       return platform_driver_register(&xilinx_spi_driver);
-}
-module_init(xilinx_spi_pltfm_init);
-
-static void __exit xilinx_spi_pltfm_exit(void)
-{
-       platform_driver_unregister(&xilinx_spi_driver);
-}
-module_exit(xilinx_spi_pltfm_exit);
+module_platform_driver(xilinx_spi_driver);
 
 MODULE_AUTHOR("MontaVista Software, Inc. <source@mvista.com>");
 MODULE_DESCRIPTION("Xilinx SPI driver");
index a329613057230662389ef017528a98d290e778a2..d132c27dfb3f4dd476077ec743d73a48374e2784 100644 (file)
@@ -34,8 +34,6 @@ source "drivers/staging/go7007/Kconfig"
 
 source "drivers/staging/cx25821/Kconfig"
 
-source "drivers/staging/tm6000/Kconfig"
-
 source "drivers/staging/cxd2099/Kconfig"
 
 source "drivers/staging/usbip/Kconfig"
@@ -142,8 +140,6 @@ source "drivers/staging/ste_rmi4/Kconfig"
 
 source "drivers/staging/gma500/Kconfig"
 
-source "drivers/staging/altera-stapl/Kconfig"
-
 source "drivers/staging/mei/Kconfig"
 
 source "drivers/staging/nvec/Kconfig"
index d7a5a04d0a2f37d11c873118803c3783e517070d..936b7c22e18e2eebff3232841688dba57c6e0142 100644 (file)
@@ -8,7 +8,6 @@ obj-$(CONFIG_ET131X)            += et131x/
 obj-$(CONFIG_SLICOSS)          += slicoss/
 obj-$(CONFIG_VIDEO_GO7007)     += go7007/
 obj-$(CONFIG_VIDEO_CX25821)    += cx25821/
-obj-$(CONFIG_VIDEO_TM6000)     += tm6000/
 obj-$(CONFIG_DVB_CXD2099)      += cxd2099/
 obj-$(CONFIG_LIRC_STAGING)     += lirc/
 obj-$(CONFIG_USBIP_CORE)       += usbip/
@@ -59,7 +58,6 @@ obj-$(CONFIG_BCM_WIMAX)               += bcm/
 obj-$(CONFIG_FT1000)           += ft1000/
 obj-$(CONFIG_SND_INTEL_SST)    += intel_sst/
 obj-$(CONFIG_SPEAKUP)          += speakup/
-obj-$(CONFIG_ALTERA_STAPL)     +=altera-stapl/
 obj-$(CONFIG_TOUCHSCREEN_CLEARPAD_TM1217)      += cptm1217/
 obj-$(CONFIG_TOUCHSCREEN_SYNAPTICS_I2C_RMI4)   += ste_rmi4/
 obj-$(CONFIG_DRM_PSB)          += gma500/
diff --git a/drivers/staging/altera-stapl/Makefile b/drivers/staging/altera-stapl/Makefile
deleted file mode 100644 (file)
index ddeede3..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-altera-stapl-y := altera-lpt.o altera-jtag.o altera-comp.o altera.o
-
-obj-$(CONFIG_ALTERA_STAPL) += altera-stapl.o
index 5b212dc725e1b4d38812a9d3d85f262b94d793a5..04e93c49f03a88af2d9b716fa70488461526189a 100644 (file)
@@ -193,7 +193,7 @@ dt3155_start_acq(struct dt3155_priv *pd)
        struct vb2_buffer *vb = pd->curr_buf;
        dma_addr_t dma_addr;
 
-       dma_addr = vb2_dma_contig_plane_paddr(vb, 0);
+       dma_addr = vb2_dma_contig_plane_dma_addr(vb, 0);
        iowrite32(dma_addr, pd->regs + EVEN_DMA_START);
        iowrite32(dma_addr + img_width, pd->regs + ODD_DMA_START);
        iowrite32(img_width, pd->regs + EVEN_DMA_STRIDE);
@@ -357,7 +357,7 @@ dt3155_irq_handler_even(int irq, void *dev_id)
        ivb = list_first_entry(&ipd->dmaq, typeof(*ivb), done_entry);
        list_del(&ivb->done_entry);
        ipd->curr_buf = ivb;
-       dma_addr = vb2_dma_contig_plane_paddr(ivb, 0);
+       dma_addr = vb2_dma_contig_plane_dma_addr(ivb, 0);
        iowrite32(dma_addr, ipd->regs + EVEN_DMA_START);
        iowrite32(dma_addr + img_width, ipd->regs + ODD_DMA_START);
        iowrite32(img_width, ipd->regs + EVEN_DMA_STRIDE);
index 598fcb3599f90cab87db6d231385d3c4aefddf10..5cc42a655c8857962689ec7421a49113ba5538a9 100644 (file)
@@ -115,8 +115,7 @@ void iio_trigger_poll_chained(struct iio_trigger *trig, s64 time);
 
 irqreturn_t iio_trigger_generic_data_rdy_poll(int irq, void *private);
 
-struct iio_trigger *iio_allocate_trigger(const char *fmt, ...)
-       __attribute__((format(printf, 1, 2)));
+__printf(1, 2) struct iio_trigger *iio_allocate_trigger(const char *fmt, ...);
 void iio_free_trigger(struct iio_trigger *trig);
 
 #endif /* _IIO_TRIGGER_H_ */
diff --git a/drivers/staging/tm6000/README b/drivers/staging/tm6000/README
deleted file mode 100644 (file)
index c340ebc..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-Todo:
-       - Fix the loss of some blocks when receiving the video URB's
-       - Add a lock at tm6000_read_write_usb() to prevent two simultaneous access to the
-         URB control transfers
-       - Properly add the locks at tm6000-video
-       - Add audio support
-       - Add vbi support
-       - Add IR support
-       - Do several cleanups
-       - I think that frame1/frame0 are inverted. This causes a funny effect at the image.
-         the fix is trivial, but require some tests
-       - My tm6010 devices sometimes insist on stop working. I need to turn them off, removing
-         from my machine and wait for a while for it to work again. I'm starting to think that
-         it is an overheat issue - is there a workaround that we could do?
-       - Sometimes, tm6010 doesn't read eeprom at the proper time (hardware bug). So, the device
-         got miss-detected as a "generic" tm6000. This can be really bad if the tuner is the
-         Low Power one, as it may result on loading the high power firmware, that could damage
-         the device. Maybe we may read eeprom to double check, when the device is marked as "generic"
-       - Coding Style fixes
-       - sparse cleanups
-
-Please send patches to linux-media@vger.kernel.org
diff --git a/drivers/staging/tm6000/TODO b/drivers/staging/tm6000/TODO
deleted file mode 100644 (file)
index 135d0ea..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-There a few things to do before putting this driver in production:
-       - IR NEC with tm5600/6000 TV cards
-       - IR RC5 with tm5600/6000/6010 TV cards
-       - CodingStyle;
-       - Fix audio;
-       - Fix some panic/OOPS conditions.
-
-Please send patches to linux-media@vger.kernel.org
diff --git a/drivers/staging/tm6000/tm6000-stds.c b/drivers/staging/tm6000/tm6000-stds.c
deleted file mode 100644 (file)
index 8b29d73..0000000
+++ /dev/null
@@ -1,679 +0,0 @@
-/*
- *  tm6000-stds.c - driver for TM5600/TM6000/TM6010 USB video capture devices
- *
- *  Copyright (C) 2007 Mauro Carvalho Chehab <mchehab@redhat.com>
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation version 2
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include "tm6000.h"
-#include "tm6000-regs.h"
-
-static unsigned int tm6010_a_mode = 0;
-module_param(tm6010_a_mode, int, 0644);
-MODULE_PARM_DESC(tm6010_a_mode, "set tm6010 sif audio mode");
-
-struct tm6000_reg_settings {
-       unsigned char req;
-       unsigned char reg;
-       unsigned char value;
-};
-
-
-struct tm6000_std_settings {
-       v4l2_std_id id;
-       struct tm6000_reg_settings common[27];
-};
-
-static struct tm6000_std_settings composite_stds[] = {
-       {
-               .id = V4L2_STD_PAL_M,
-               .common = {
-                       {TM6010_REQ07_R3F_RESET, 0x01},
-                       {TM6010_REQ07_R00_VIDEO_CONTROL0, 0x04},
-                       {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
-                       {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
-                       {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x00},
-                       {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31},
-                       {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e},
-                       {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x83},
-                       {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x0a},
-                       {TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0xe0},
-                       {TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c},
-                       {TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc},
-                       {TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc},
-                       {TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd},
-                       {TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x88},
-                       {TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x20},
-                       {TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0x61},
-                       {TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x0c},
-                       {TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c},
-                       {TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x52},
-                       {TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6F},
-
-                       {TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdc},
-                       {TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07},
-                       {TM6010_REQ07_R3F_RESET, 0x00},
-                       {0, 0, 0},
-               },
-        }, {
-               .id = V4L2_STD_PAL_Nc,
-               .common = {
-                       {TM6010_REQ07_R3F_RESET, 0x01},
-                       {TM6010_REQ07_R00_VIDEO_CONTROL0, 0x36},
-                       {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
-                       {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
-                       {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x02},
-                       {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31},
-                       {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e},
-                       {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x91},
-                       {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x1f},
-                       {TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0x0c},
-                       {TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c},
-                       {TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc},
-                       {TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc},
-                       {TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd},
-                       {TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x8c},
-                       {TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x2c},
-                       {TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0xc1},
-                       {TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x0c},
-                       {TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c},
-                       {TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x52},
-                       {TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6F},
-
-                       {TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdc},
-                       {TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07},
-                       {TM6010_REQ07_R3F_RESET, 0x00},
-                       {0, 0, 0},
-               },
-       }, {
-               .id = V4L2_STD_PAL,
-               .common = {
-                       {TM6010_REQ07_R3F_RESET, 0x01},
-                       {TM6010_REQ07_R00_VIDEO_CONTROL0, 0x32},
-                       {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
-                       {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
-                       {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x02},
-                       {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31},
-                       {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x25},
-                       {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0xd5},
-                       {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x63},
-                       {TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0x50},
-                       {TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c},
-                       {TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc},
-                       {TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc},
-                       {TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd},
-                       {TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x8c},
-                       {TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x2c},
-                       {TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0xc1},
-                       {TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x0c},
-                       {TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c},
-                       {TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x52},
-                       {TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6F},
-
-                       {TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdc},
-                       {TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07},
-                       {TM6010_REQ07_R3F_RESET, 0x00},
-                       {0, 0, 0},
-               },
-        }, {
-               .id = V4L2_STD_SECAM,
-               .common = {
-                       {TM6010_REQ07_R3F_RESET, 0x01},
-                       {TM6010_REQ07_R00_VIDEO_CONTROL0, 0x38},
-                       {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
-                       {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
-                       {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x02},
-                       {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31},
-                       {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x24},
-                       {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x92},
-                       {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xe8},
-                       {TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0xed},
-                       {TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c},
-                       {TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc},
-                       {TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc},
-                       {TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd},
-                       {TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x8c},
-                       {TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x2c},
-                       {TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0xc1},
-                       {TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x2c},
-                       {TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x18},
-                       {TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x42},
-                       {TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0xFF},
-
-                       {TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07},
-                       {TM6010_REQ07_R3F_RESET, 0x00},
-                       {0, 0, 0},
-               },
-       }, {
-               .id = V4L2_STD_NTSC,
-               .common = {
-                       {TM6010_REQ07_R3F_RESET, 0x01},
-                       {TM6010_REQ07_R00_VIDEO_CONTROL0, 0x00},
-                       {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0f},
-                       {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
-                       {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x00},
-                       {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31},
-                       {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e},
-                       {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x8b},
-                       {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xa2},
-                       {TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0xe9},
-                       {TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c},
-                       {TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc},
-                       {TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc},
-                       {TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd},
-                       {TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x88},
-                       {TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x22},
-                       {TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0x61},
-                       {TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x1c},
-                       {TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c},
-                       {TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x42},
-                       {TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6F},
-
-                       {TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdd},
-                       {TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07},
-                       {TM6010_REQ07_R3F_RESET, 0x00},
-                       {0, 0, 0},
-               },
-       },
-};
-
-static struct tm6000_std_settings svideo_stds[] = {
-       {
-               .id = V4L2_STD_PAL_M,
-               .common = {
-                       {TM6010_REQ07_R3F_RESET, 0x01},
-                       {TM6010_REQ07_R00_VIDEO_CONTROL0, 0x05},
-                       {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
-                       {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
-                       {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x04},
-                       {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31},
-                       {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e},
-                       {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x83},
-                       {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x0a},
-                       {TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0xe0},
-                       {TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c},
-                       {TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc},
-                       {TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc},
-                       {TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd},
-                       {TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x88},
-                       {TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x22},
-                       {TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0x61},
-                       {TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x0c},
-                       {TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c},
-                       {TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x52},
-                       {TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6F},
-
-                       {TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdc},
-                       {TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07},
-                       {TM6010_REQ07_R3F_RESET, 0x00},
-                       {0, 0, 0},
-               },
-       }, {
-               .id = V4L2_STD_PAL_Nc,
-               .common = {
-                       {TM6010_REQ07_R3F_RESET, 0x01},
-                       {TM6010_REQ07_R00_VIDEO_CONTROL0, 0x37},
-                       {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
-                       {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
-                       {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x04},
-                       {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31},
-                       {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e},
-                       {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x91},
-                       {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x1f},
-                       {TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0x0c},
-                       {TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c},
-                       {TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc},
-                       {TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc},
-                       {TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd},
-                       {TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x88},
-                       {TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x22},
-                       {TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0xc1},
-                       {TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x0c},
-                       {TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c},
-                       {TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x52},
-                       {TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6F},
-
-                       {TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdc},
-                       {TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07},
-                       {TM6010_REQ07_R3F_RESET, 0x00},
-                       {0, 0, 0},
-               },
-       }, {
-               .id = V4L2_STD_PAL,
-               .common = {
-                       {TM6010_REQ07_R3F_RESET, 0x01},
-                       {TM6010_REQ07_R00_VIDEO_CONTROL0, 0x33},
-                       {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
-                       {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
-                       {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x04},
-                       {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x30},
-                       {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x25},
-                       {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0xd5},
-                       {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x63},
-                       {TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0x50},
-                       {TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c},
-                       {TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc},
-                       {TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc},
-                       {TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd},
-                       {TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x8c},
-                       {TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x2a},
-                       {TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0xc1},
-                       {TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x0c},
-                       {TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c},
-                       {TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x52},
-                       {TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6F},
-
-                       {TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdc},
-                       {TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07},
-                       {TM6010_REQ07_R3F_RESET, 0x00},
-                       {0, 0, 0},
-               },
-        }, {
-               .id = V4L2_STD_SECAM,
-               .common = {
-                       {TM6010_REQ07_R3F_RESET, 0x01},
-                       {TM6010_REQ07_R00_VIDEO_CONTROL0, 0x39},
-                       {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
-                       {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
-                       {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x03},
-                       {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31},
-                       {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x24},
-                       {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x92},
-                       {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xe8},
-                       {TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0xed},
-                       {TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c},
-                       {TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc},
-                       {TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc},
-                       {TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd},
-                       {TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x8c},
-                       {TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x2a},
-                       {TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0xc1},
-                       {TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x2c},
-                       {TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x18},
-                       {TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x42},
-                       {TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0xFF},
-
-                       {TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07},
-                       {TM6010_REQ07_R3F_RESET, 0x00},
-                       {0, 0, 0},
-               },
-       }, {
-               .id = V4L2_STD_NTSC,
-               .common = {
-                       {TM6010_REQ07_R3F_RESET, 0x01},
-                       {TM6010_REQ07_R00_VIDEO_CONTROL0, 0x01},
-                       {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0f},
-                       {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
-                       {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x03},
-                       {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x30},
-                       {TM6010_REQ07_R17_HLOOP_MAXSTATE, 0x8b},
-                       {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e},
-                       {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x8b},
-                       {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xa2},
-                       {TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0xe9},
-                       {TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c},
-                       {TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc},
-                       {TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc},
-                       {TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd},
-                       {TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x88},
-                       {TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x22},
-                       {TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0x61},
-                       {TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x1c},
-                       {TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c},
-                       {TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x42},
-                       {TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6F},
-
-                       {TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdd},
-                       {TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07},
-                       {TM6010_REQ07_R3F_RESET, 0x00},
-                       {0, 0, 0},
-               },
-       },
-};
-
-
-static int tm6000_set_audio_std(struct tm6000_core *dev)
-{
-       uint8_t areg_02 = 0x04; /* GC1 Fixed gain 0dB */
-       uint8_t areg_05 = 0x01; /* Auto 4.5 = M Japan, Auto 6.5 = DK */
-       uint8_t areg_06 = 0x02; /* Auto de-emphasis, mannual channel mode */
-       uint8_t nicam_flag = 0; /* No NICAM */
-
-       if (dev->radio) {
-               tm6000_set_reg(dev, TM6010_REQ08_R01_A_INIT, 0x00);
-               tm6000_set_reg(dev, TM6010_REQ08_R02_A_FIX_GAIN_CTRL, 0x04);
-               tm6000_set_reg(dev, TM6010_REQ08_R03_A_AUTO_GAIN_CTRL, 0x00);
-               tm6000_set_reg(dev, TM6010_REQ08_R04_A_SIF_AMP_CTRL, 0x80);
-               tm6000_set_reg(dev, TM6010_REQ08_R05_A_STANDARD_MOD, 0x0c);
-               /* set mono or stereo */
-               if (dev->amode == V4L2_TUNER_MODE_MONO)
-                       tm6000_set_reg(dev, TM6010_REQ08_R06_A_SOUND_MOD, 0x00);
-               else if (dev->amode == V4L2_TUNER_MODE_STEREO)
-                       tm6000_set_reg(dev, TM6010_REQ08_R06_A_SOUND_MOD, 0x02);
-               tm6000_set_reg(dev, TM6010_REQ08_R09_A_MAIN_VOL, 0x18);
-               tm6000_set_reg(dev, TM6010_REQ08_R0C_A_ASD_THRES2, 0x0a);
-               tm6000_set_reg(dev, TM6010_REQ08_R0D_A_AMD_THRES, 0x40);
-               tm6000_set_reg(dev, TM6010_REQ08_RF1_AADC_POWER_DOWN, 0xfe);
-               tm6000_set_reg(dev, TM6010_REQ08_R1E_A_GAIN_DEEMPH_OUT, 0x13);
-               tm6000_set_reg(dev, TM6010_REQ08_R01_A_INIT, 0x80);
-               return 0;
-       }
-
-       switch (tm6010_a_mode) {
-       /* auto */
-       case 0:
-               switch (dev->norm) {
-               case V4L2_STD_NTSC_M_KR:
-                       areg_05 |= 0x00;
-                       break;
-               case V4L2_STD_NTSC_M_JP:
-                       areg_05 |= 0x40;
-                       break;
-               case V4L2_STD_NTSC_M:
-               case V4L2_STD_PAL_M:
-               case V4L2_STD_PAL_N:
-                       areg_05 |= 0x20;
-                       break;
-               case V4L2_STD_PAL_Nc:
-                       areg_05 |= 0x60;
-                       break;
-               case V4L2_STD_SECAM_L:
-                       areg_05 |= 0x00;
-                       break;
-               case V4L2_STD_DK:
-                       areg_05 |= 0x10;
-                       break;
-               }
-               break;
-       /* A2 */
-       case 1:
-               switch (dev->norm) {
-               case V4L2_STD_B:
-               case V4L2_STD_GH:
-                       areg_05 = 0x05;
-                       break;
-               case V4L2_STD_DK:
-                       areg_05 = 0x09;
-                       break;
-               }
-               break;
-       /* NICAM */
-       case 2:
-               switch (dev->norm) {
-               case V4L2_STD_B:
-               case V4L2_STD_GH:
-                       areg_05 = 0x07;
-                       break;
-               case V4L2_STD_DK:
-                       areg_05 = 0x06;
-                       break;
-               case V4L2_STD_PAL_I:
-                       areg_05 = 0x08;
-                       break;
-               case V4L2_STD_SECAM_L:
-                       areg_05 = 0x0a;
-                       areg_02 = 0x02;
-                       break;
-               }
-               nicam_flag = 1;
-               break;
-       /* other */
-       case 3:
-               switch (dev->norm) {
-               /* DK3_A2 */
-               case V4L2_STD_DK:
-                       areg_05 = 0x0b;
-                       break;
-               /* Korea */
-               case V4L2_STD_NTSC_M_KR:
-                       areg_05 = 0x04;
-                       break;
-               /* EIAJ */
-               case V4L2_STD_NTSC_M_JP:
-                       areg_05 = 0x03;
-                       break;
-               default:
-                       areg_05 = 0x02;
-                       break;
-               }
-               break;
-       }
-
-       tm6000_set_reg(dev, TM6010_REQ08_R01_A_INIT, 0x00);
-       tm6000_set_reg(dev, TM6010_REQ08_R02_A_FIX_GAIN_CTRL, areg_02);
-       tm6000_set_reg(dev, TM6010_REQ08_R03_A_AUTO_GAIN_CTRL, 0x00);
-       tm6000_set_reg(dev, TM6010_REQ08_R04_A_SIF_AMP_CTRL, 0xa0);
-       tm6000_set_reg(dev, TM6010_REQ08_R05_A_STANDARD_MOD, areg_05);
-       tm6000_set_reg(dev, TM6010_REQ08_R06_A_SOUND_MOD, areg_06);
-       tm6000_set_reg(dev, TM6010_REQ08_R07_A_LEFT_VOL, 0x00);
-       tm6000_set_reg(dev, TM6010_REQ08_R08_A_RIGHT_VOL, 0x00);
-       tm6000_set_reg(dev, TM6010_REQ08_R09_A_MAIN_VOL, 0x08);
-       tm6000_set_reg(dev, TM6010_REQ08_R0A_A_I2S_MOD, 0x91);
-       tm6000_set_reg(dev, TM6010_REQ08_R0B_A_ASD_THRES1, 0x20);
-       tm6000_set_reg(dev, TM6010_REQ08_R0C_A_ASD_THRES2, 0x12);
-       tm6000_set_reg(dev, TM6010_REQ08_R0D_A_AMD_THRES, 0x20);
-       tm6000_set_reg(dev, TM6010_REQ08_R0E_A_MONO_THRES1, 0xf0);
-       tm6000_set_reg(dev, TM6010_REQ08_R0F_A_MONO_THRES2, 0x80);
-       tm6000_set_reg(dev, TM6010_REQ08_R10_A_MUTE_THRES1, 0xc0);
-       tm6000_set_reg(dev, TM6010_REQ08_R11_A_MUTE_THRES2, 0x80);
-       tm6000_set_reg(dev, TM6010_REQ08_R12_A_AGC_U, 0x12);
-       tm6000_set_reg(dev, TM6010_REQ08_R13_A_AGC_ERR_T, 0xfe);
-       tm6000_set_reg(dev, TM6010_REQ08_R14_A_AGC_GAIN_INIT, 0x20);
-       tm6000_set_reg(dev, TM6010_REQ08_R15_A_AGC_STEP_THR, 0x14);
-       tm6000_set_reg(dev, TM6010_REQ08_R16_A_AGC_GAIN_MAX, 0xfe);
-       tm6000_set_reg(dev, TM6010_REQ08_R17_A_AGC_GAIN_MIN, 0x01);
-       tm6000_set_reg(dev, TM6010_REQ08_R18_A_TR_CTRL, 0xa0);
-       tm6000_set_reg(dev, TM6010_REQ08_R19_A_FH_2FH_GAIN, 0x32);
-       tm6000_set_reg(dev, TM6010_REQ08_R1A_A_NICAM_SER_MAX, 0x64);
-       tm6000_set_reg(dev, TM6010_REQ08_R1B_A_NICAM_SER_MIN, 0x20);
-       tm6000_set_reg(dev, REQ_08_SET_GET_AVREG_BIT, 0x1c, 0x00);
-       tm6000_set_reg(dev, REQ_08_SET_GET_AVREG_BIT, 0x1d, 0x00);
-       tm6000_set_reg(dev, TM6010_REQ08_R1E_A_GAIN_DEEMPH_OUT, 0x13);
-       tm6000_set_reg(dev, TM6010_REQ08_R1F_A_TEST_INTF_SEL, 0x00);
-       tm6000_set_reg(dev, TM6010_REQ08_R20_A_TEST_PIN_SEL, 0x00);
-       tm6000_set_reg(dev, TM6010_REQ08_R01_A_INIT, 0x80);
-
-       return 0;
-}
-
-void tm6000_get_std_res(struct tm6000_core *dev)
-{
-       /* Currently, those are the only supported resoltions */
-       if (dev->norm & V4L2_STD_525_60)
-               dev->height = 480;
-       else
-               dev->height = 576;
-
-       dev->width = 720;
-}
-
-static int tm6000_load_std(struct tm6000_core *dev,
-                          struct tm6000_reg_settings *set, int max_size)
-{
-       int i, rc;
-
-       /* Load board's initialization table */
-       for (i = 0; max_size; i++) {
-               if (!set[i].req)
-                       return 0;
-
-               rc = tm6000_set_reg(dev, set[i].req, set[i].reg, set[i].value);
-               if (rc < 0) {
-                       printk(KERN_ERR "Error %i while setting "
-                              "req %d, reg %d to value %d\n",
-                              rc, set[i].req, set[i].reg, set[i].value);
-                       return rc;
-               }
-       }
-
-       return 0;
-}
-
-int tm6000_set_standard(struct tm6000_core *dev)
-{
-       int i, rc = 0;
-       u8 reg_07_fe = 0x8a;
-       u8 reg_08_f1 = 0xfc;
-       u8 reg_08_e2 = 0xf0;
-       u8 reg_08_e6 = 0x0f;
-
-       tm6000_get_std_res(dev);
-
-       if (dev->radio) {
-               /* todo */
-       }
-
-       if (dev->dev_type == TM6010) {
-               switch (dev->vinput[dev->input].vmux) {
-               case TM6000_VMUX_VIDEO_A:
-                       tm6000_set_reg(dev, TM6010_REQ08_RE3_ADC_IN1_SEL, 0xf4);
-                       tm6000_set_reg(dev, TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf1);
-                       tm6000_set_reg(dev, TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xe0);
-                       tm6000_set_reg(dev, TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2);
-                       tm6000_set_reg(dev, TM6010_REQ08_RED_GAIN_SEL, 0xe8);
-                       reg_07_fe |= 0x01;
-                       break;
-               case TM6000_VMUX_VIDEO_B:
-                       tm6000_set_reg(dev, TM6010_REQ08_RE3_ADC_IN1_SEL, 0xf8);
-                       tm6000_set_reg(dev, TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf1);
-                       tm6000_set_reg(dev, TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xe0);
-                       tm6000_set_reg(dev, TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2);
-                       tm6000_set_reg(dev, TM6010_REQ08_RED_GAIN_SEL, 0xe8);
-                       reg_07_fe |= 0x01;
-                       break;
-               case TM6000_VMUX_VIDEO_AB:
-                       tm6000_set_reg(dev, TM6010_REQ08_RE3_ADC_IN1_SEL, 0xfc);
-                       tm6000_set_reg(dev, TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf8);
-                       reg_08_e6 = 0x00;
-                       tm6000_set_reg(dev, TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf2);
-                       tm6000_set_reg(dev, TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xf0);
-                       tm6000_set_reg(dev, TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2);
-                       tm6000_set_reg(dev, TM6010_REQ08_RED_GAIN_SEL, 0xe0);
-                       break;
-               default:
-                       break;
-               }
-               switch (dev->vinput[dev->input].amux) {
-               case TM6000_AMUX_ADC1:
-                       tm6000_set_reg_mask(dev, TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG,
-                               0x00, 0x0f);
-                       break;
-               case TM6000_AMUX_ADC2:
-                       tm6000_set_reg_mask(dev, TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG,
-                               0x08, 0x0f);
-                       break;
-               case TM6000_AMUX_SIF1:
-                       reg_08_e2 |= 0x02;
-                       reg_08_e6 = 0x08;
-                       reg_07_fe |= 0x40;
-                       reg_08_f1 |= 0x02;
-                       tm6000_set_reg(dev, TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf3);
-                       tm6000_set_reg_mask(dev, TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG,
-                               0x02, 0x0f);
-                       break;
-               case TM6000_AMUX_SIF2:
-                       reg_08_e2 |= 0x02;
-                       reg_08_e6 = 0x08;
-                       reg_07_fe |= 0x40;
-                       reg_08_f1 |= 0x02;
-                       tm6000_set_reg(dev, TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf7);
-                       tm6000_set_reg_mask(dev, TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG,
-                               0x02, 0x0f);
-                       break;
-               default:
-                       break;
-               }
-               tm6000_set_reg(dev, TM6010_REQ08_RE2_POWER_DOWN_CTRL1, reg_08_e2);
-               tm6000_set_reg(dev, TM6010_REQ08_RE6_POWER_DOWN_CTRL2, reg_08_e6);
-               tm6000_set_reg(dev, TM6010_REQ08_RF1_AADC_POWER_DOWN, reg_08_f1);
-               tm6000_set_reg(dev, TM6010_REQ07_RFE_POWER_DOWN, reg_07_fe);
-       } else {
-               switch (dev->vinput[dev->input].vmux) {
-               case TM6000_VMUX_VIDEO_A:
-                       tm6000_set_reg(dev, TM6000_REQ07_RE3_VADC_INP_LPF_SEL1, 0x10);
-                       tm6000_set_reg(dev, TM6000_REQ07_RE5_VADC_INP_LPF_SEL2, 0x00);
-                       tm6000_set_reg(dev, TM6000_REQ07_RE8_VADC_PWDOWN_CTL, 0x0f);
-                       tm6000_set_reg(dev,
-                           REQ_03_SET_GET_MCU_PIN, dev->vinput[dev->input].v_gpio, 0);
-                       break;
-               case TM6000_VMUX_VIDEO_B:
-                       tm6000_set_reg(dev, TM6000_REQ07_RE3_VADC_INP_LPF_SEL1, 0x00);
-                       tm6000_set_reg(dev, TM6000_REQ07_RE5_VADC_INP_LPF_SEL2, 0x00);
-                       tm6000_set_reg(dev, TM6000_REQ07_RE8_VADC_PWDOWN_CTL, 0x0f);
-                       tm6000_set_reg(dev,
-                           REQ_03_SET_GET_MCU_PIN, dev->vinput[dev->input].v_gpio, 0);
-                       break;
-               case TM6000_VMUX_VIDEO_AB:
-                       tm6000_set_reg(dev, TM6000_REQ07_RE3_VADC_INP_LPF_SEL1, 0x10);
-                       tm6000_set_reg(dev, TM6000_REQ07_RE5_VADC_INP_LPF_SEL2, 0x10);
-                       tm6000_set_reg(dev, TM6000_REQ07_RE8_VADC_PWDOWN_CTL, 0x00);
-                       tm6000_set_reg(dev,
-                           REQ_03_SET_GET_MCU_PIN, dev->vinput[dev->input].v_gpio, 1);
-                       break;
-               default:
-                       break;
-               }
-               switch (dev->vinput[dev->input].amux) {
-               case TM6000_AMUX_ADC1:
-                       tm6000_set_reg_mask(dev,
-                               TM6000_REQ07_REB_VADC_AADC_MODE, 0x00, 0x0f);
-                       break;
-               case TM6000_AMUX_ADC2:
-                       tm6000_set_reg_mask(dev,
-                               TM6000_REQ07_REB_VADC_AADC_MODE, 0x04, 0x0f);
-                       break;
-               default:
-                       break;
-               }
-       }
-       if (dev->vinput[dev->input].type == TM6000_INPUT_SVIDEO) {
-               for (i = 0; i < ARRAY_SIZE(svideo_stds); i++) {
-                       if (dev->norm & svideo_stds[i].id) {
-                               rc = tm6000_load_std(dev, svideo_stds[i].common,
-                                                    sizeof(svideo_stds[i].
-                                                           common));
-                               goto ret;
-                       }
-               }
-               return -EINVAL;
-       } else {
-               for (i = 0; i < ARRAY_SIZE(composite_stds); i++) {
-                       if (dev->norm & composite_stds[i].id) {
-                               rc = tm6000_load_std(dev,
-                                                    composite_stds[i].common,
-                                                    sizeof(composite_stds[i].
-                                                           common));
-                               goto ret;
-                       }
-               }
-               return -EINVAL;
-       }
-
-ret:
-       if (rc < 0)
-               return rc;
-
-       if ((dev->dev_type == TM6010) &&
-           ((dev->vinput[dev->input].amux == TM6000_AMUX_SIF1) ||
-           (dev->vinput[dev->input].amux == TM6000_AMUX_SIF2)))
-               tm6000_set_audio_std(dev);
-
-       msleep(40);
-
-
-       return 0;
-}
index 36db231cd804c51e6f0dc23d987857ba7d98a10a..277e408c39c58d8829bce56f5bb97a7cab4f968e 100644 (file)
@@ -1300,27 +1300,17 @@ static int XGIfb_do_set_var(struct fb_var_screeninfo *var, int isactive,
        return 0;
 }
 
-static int XGIfb_pan_var(struct xgifb_video_info *xgifb_info,
-                        struct fb_var_screeninfo *var)
+static int XGIfb_pan_var(struct fb_var_screeninfo *var, struct fb_info *info)
 {
+       struct xgifb_video_info *xgifb_info = info->par;
        unsigned int base;
 
        /* printk("Inside pan_var"); */
 
-       if (var->xoffset > (var->xres_virtual - var->xres)) {
-               /* printk("Pan: xo: %d xv %d xr %d\n",
-                       var->xoffset, var->xres_virtual, var->xres); */
-               return -EINVAL;
-       }
-       if (var->yoffset > (var->yres_virtual - var->yres)) {
-               /* printk("Pan: yo: %d yv %d yr %d\n",
-                       var->yoffset, var->yres_virtual, var->yres); */
-               return -EINVAL;
-       }
-       base = var->yoffset * var->xres_virtual + var->xoffset;
+       base = var->yoffset * info->var.xres_virtual + var->xoffset;
 
        /* calculate base bpp dep. */
-       switch (var->bits_per_pixel) {
+       switch (info->var.bits_per_pixel) {
        case 16:
                base >>= 1;
                break;
@@ -1615,13 +1605,12 @@ static int XGIfb_pan_display(struct fb_var_screeninfo *var,
                struct fb_info *info)
 {
        int err;
-       struct xgifb_video_info *xgifb_info = info->par;
 
        /* printk("\nInside pan_display:\n"); */
 
-       if (var->xoffset > (var->xres_virtual - var->xres))
+       if (var->xoffset > (info->var.xres_virtual - info->var.xres))
                return -EINVAL;
-       if (var->yoffset > (var->yres_virtual - var->yres))
+       if (var->yoffset > (info->var.yres_virtual - info->var.yres))
                return -EINVAL;
 
        if (var->vmode & FB_VMODE_YWRAP) {
@@ -1634,7 +1623,7 @@ static int XGIfb_pan_display(struct fb_var_screeninfo *var,
                                                > info->var.yres_virtual)
                        return -EINVAL;
        }
-       err = XGIfb_pan_var(xgifb_info, var);
+       err = XGIfb_pan_var(var, info);
        if (err < 0)
                return err;
 
index e58cece6f443a6bb8d48ababf6a74e4846c63557..e8c9cee07d00e2b7e9b4dfeb3a5119475d21eacc 100644 (file)
@@ -200,17 +200,7 @@ static struct platform_driver of_platform_serial_driver = {
        .remove = of_platform_serial_remove,
 };
 
-static int __init of_platform_serial_init(void)
-{
-       return platform_driver_register(&of_platform_serial_driver);
-}
-module_init(of_platform_serial_init);
-
-static void __exit of_platform_serial_exit(void)
-{
-       return platform_driver_unregister(&of_platform_serial_driver);
-};
-module_exit(of_platform_serial_exit);
+module_platform_driver(of_platform_serial_driver);
 
 MODULE_AUTHOR("Arnd Bergmann <arnd@arndb.de>");
 MODULE_LICENSE("GPL");
index 75a39eab70c38e291363473074ff8373dcf30135..a425d65d5ba2d5d2e66f513f5dfcfa29b62de186 100644 (file)
@@ -378,8 +378,8 @@ static int mc68x328fb_pan_display(struct fb_var_screeninfo *var,
                    || var->xoffset)
                        return -EINVAL;
        } else {
-               if (var->xoffset + var->xres > info->var.xres_virtual ||
-                   var->yoffset + var->yres > info->var.yres_virtual)
+               if (var->xoffset + info->var.xres > info->var.xres_virtual ||
+                   var->yoffset + info->var.yres > info->var.yres_virtual)
                        return -EINVAL;
        }
        info->var.xoffset = var->xoffset;
index 549b960667c81b5bcbff1145550a28630038c374..8165c5577d715c33a04e30b9a10d34a4a21dd93e 100644 (file)
@@ -259,6 +259,15 @@ config FB_TILEBLITTING
 comment "Frame buffer hardware drivers"
        depends on FB
 
+config FB_GRVGA
+       tristate "Aeroflex Gaisler framebuffer support"
+       depends on FB && SPARC
+       select FB_CFB_FILLRECT
+       select FB_CFB_COPYAREA
+       select FB_CFB_IMAGEBLIT
+       ---help---
+       This enables support for the SVGACTRL framebuffer in the GRLIB IP library from Aeroflex Gaisler.
+
 config FB_CIRRUS
        tristate "Cirrus Logic support"
        depends on FB && (ZORRO || PCI)
@@ -1756,9 +1765,10 @@ config FB_AU1100
 config FB_AU1200
        bool "Au1200 LCD Driver"
        depends on (FB = y) && MIPS && SOC_AU1200
-       select FB_CFB_FILLRECT
-       select FB_CFB_COPYAREA
-       select FB_CFB_IMAGEBLIT
+       select FB_SYS_FILLRECT
+       select FB_SYS_COPYAREA
+       select FB_SYS_IMAGEBLIT
+       select FB_SYS_FOPS
        help
          This is the framebuffer driver for the AMD Au1200 SOC.  It can drive
          various panels and CRTs by passing in kernel cmd line option
@@ -2027,7 +2037,7 @@ config FB_TMIO_ACCELL
 
 config FB_S3C
        tristate "Samsung S3C framebuffer support"
-       depends on FB && S3C_DEV_FB
+       depends on FB && (S3C_DEV_FB || S5P_DEV_FIMD0)
        select FB_CFB_FILLRECT
        select FB_CFB_COPYAREA
        select FB_CFB_IMAGEBLIT
@@ -2110,6 +2120,22 @@ config FB_SM501
 
          If unsure, say N.
 
+config FB_SMSCUFX
+       tristate "SMSC UFX6000/7000 USB Framebuffer support"
+       depends on FB && USB
+       select FB_MODE_HELPERS
+       select FB_SYS_FILLRECT
+       select FB_SYS_COPYAREA
+       select FB_SYS_IMAGEBLIT
+       select FB_SYS_FOPS
+       select FB_DEFERRED_IO
+       ---help---
+         This is a kernel framebuffer driver for SMSC UFX USB devices.
+         Supports fbdev clients like xf86-video-fbdev, kdrive, fbi, and
+         mplayer -vo fbdev. Supports both UFX6000 (USB 2.0) and UFX7000
+         (USB 3.0) devices.
+         To compile as a module, choose M here: the module name is smscufx.
+
 config FB_UDL
        tristate "Displaylink USB Framebuffer support"
        depends on FB && USB
index 8b83129e209ca0f943a3d624e29930a679aec110..9b9d8fff7732917d0b16e28f705d552850c738b2 100644 (file)
@@ -33,6 +33,7 @@ obj-$(CONFIG_FB_AMIGA)            += amifb.o c2p_planar.o
 obj-$(CONFIG_FB_ARC)              += arcfb.o
 obj-$(CONFIG_FB_CLPS711X)         += clps711xfb.o
 obj-$(CONFIG_FB_CYBER2000)        += cyber2000fb.o
+obj-$(CONFIG_FB_GRVGA)            += grvga.o
 obj-$(CONFIG_FB_PM2)              += pm2fb.o
 obj-$(CONFIG_FB_PM3)             += pm3fb.o
 
@@ -127,6 +128,7 @@ obj-$(CONFIG_FB_IBM_GXT4500)          += gxt4500.o
 obj-$(CONFIG_FB_PS3)             += ps3fb.o
 obj-$(CONFIG_FB_SM501)            += sm501fb.o
 obj-$(CONFIG_FB_UDL)             += udlfb.o
+obj-$(CONFIG_FB_SMSCUFX)         += smscufx.o
 obj-$(CONFIG_FB_XILINX)           += xilinxfb.o
 obj-$(CONFIG_SH_MIPI_DSI)        += sh_mipi_dsi.o
 obj-$(CONFIG_FB_SH_MOBILE_HDMI)          += sh_mobile_hdmi.o
index 6183a57eb69d8b913abcde29af3bbdb24714e725..b303f17150654a8a4d0237f41977421a29cd715b 100644 (file)
@@ -850,9 +850,10 @@ acornfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
        u_int y_bottom = var->yoffset;
 
        if (!(var->vmode & FB_VMODE_YWRAP))
-               y_bottom += var->yres;
+               y_bottom += info->var.yres;
 
-       BUG_ON(y_bottom > var->yres_virtual);
+       if (y_bottom > info->var.yres_virtual)
+               return -EINVAL;
 
        acornfb_update_dma(info, var);
 
index 8686429cbdf07b57af8564849ad64b7a8624ff16..555dd4c64f5be24a1a13986f84fe19360f1d9102 100644 (file)
@@ -908,13 +908,14 @@ static int arkfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info
        unsigned int offset;
 
        /* Calculate the offset */
-       if (var->bits_per_pixel == 0) {
-               offset = (var->yoffset / 16) * (var->xres_virtual / 2) + (var->xoffset / 2);
+       if (info->var.bits_per_pixel == 0) {
+               offset = (var->yoffset / 16) * (info->var.xres_virtual / 2)
+                      + (var->xoffset / 2);
                offset = offset >> 2;
        } else {
                offset = (var->yoffset * info->fix.line_length) +
-                        (var->xoffset * var->bits_per_pixel / 8);
-               offset = offset >> ((var->bits_per_pixel == 4) ? 2 : 3);
+                        (var->xoffset * info->var.bits_per_pixel / 8);
+               offset = offset >> ((info->var.bits_per_pixel == 4) ? 2 : 3);
        }
 
        /* Set the offset */
index dda920623c6a45b96886e5729419f9dc1c1d7534..4ac48d9ee66584a797393fd5e836ee82a5024957 100644 (file)
@@ -39,7 +39,8 @@
                                         | FBINFO_HWACCEL_YPAN)
 
 static inline void atmel_lcdfb_update_dma2d(struct atmel_lcdfb_info *sinfo,
-                                       struct fb_var_screeninfo *var)
+                                       struct fb_var_screeninfo *var,
+                                       struct fb_info *info)
 {
 
 }
@@ -50,14 +51,16 @@ static inline void atmel_lcdfb_update_dma2d(struct atmel_lcdfb_info *sinfo,
                                        | FBINFO_HWACCEL_YPAN)
 
 static void atmel_lcdfb_update_dma2d(struct atmel_lcdfb_info *sinfo,
-                                    struct fb_var_screeninfo *var)
+                                    struct fb_var_screeninfo *var,
+                                    struct fb_info *info)
 {
        u32 dma2dcfg;
        u32 pixeloff;
 
-       pixeloff = (var->xoffset * var->bits_per_pixel) & 0x1f;
+       pixeloff = (var->xoffset * info->var.bits_per_pixel) & 0x1f;
 
-       dma2dcfg = ((var->xres_virtual - var->xres) * var->bits_per_pixel) / 8;
+       dma2dcfg = (info->var.xres_virtual - info->var.xres)
+                * info->var.bits_per_pixel / 8;
        dma2dcfg |= pixeloff << ATMEL_LCDC_PIXELOFF_OFFSET;
        lcdc_writel(sinfo, ATMEL_LCDC_DMA2DCFG, dma2dcfg);
 
@@ -249,14 +252,14 @@ static void atmel_lcdfb_update_dma(struct fb_info *info,
        unsigned long dma_addr;
 
        dma_addr = (fix->smem_start + var->yoffset * fix->line_length
-                   + var->xoffset * var->bits_per_pixel / 8);
+                   + var->xoffset * info->var.bits_per_pixel / 8);
 
        dma_addr &= ~3UL;
 
        /* Set framebuffer DMA base address and pixel offset */
        lcdc_writel(sinfo, ATMEL_LCDC_DMABADDR1, dma_addr);
 
-       atmel_lcdfb_update_dma2d(sinfo, var);
+       atmel_lcdfb_update_dma2d(sinfo, var, info);
 }
 
 static inline void atmel_lcdfb_free_video_memory(struct atmel_lcdfb_info *sinfo)
index 32f8cf6200a7533ce7bce35a4896fcdb4ff7946b..150684882ef74fce86d33ea2ed14bad9afa5df5b 100644 (file)
@@ -845,16 +845,16 @@ static int radeonfb_pan_display (struct fb_var_screeninfo *var,
 {
         struct radeonfb_info *rinfo = info->par;
 
-        if ((var->xoffset + var->xres > var->xres_virtual)
-           || (var->yoffset + var->yres > var->yres_virtual))
-               return -EINVAL;
+       if ((var->xoffset + info->var.xres > info->var.xres_virtual)
+           || (var->yoffset + info->var.yres > info->var.yres_virtual))
+               return -EINVAL;
                 
         if (rinfo->asleep)
                return 0;
 
        radeon_fifo_wait(2);
-        OUTREG(CRTC_OFFSET, ((var->yoffset * var->xres_virtual + var->xoffset)
-                            * var->bits_per_pixel / 8) & ~7);
+       OUTREG(CRTC_OFFSET, (var->yoffset * info->fix.line_length +
+                            var->xoffset * info->var.bits_per_pixel / 8) & ~7);
         return 0;
 }
 
index 01a8fde67f20ab906b55ef2739159c430f905e55..649cb35de4ed401d2ffce0e1c5abcaeb71f4037a 100644 (file)
@@ -110,12 +110,6 @@ static struct fb_var_screeninfo au1100fb_var __devinitdata = {
        .vmode          = FB_VMODE_NONINTERLACED,
 };
 
-static struct au1100fb_drv_info drv_info;
-
-static int nocursor = 0;
-module_param(nocursor, int, 0644);
-MODULE_PARM_DESC(nocursor, "cursor enable/disable");
-
 /* fb_blank
  * Blank the screen. Depending on the mode, the screen will be
  * activated with the backlight color, or desactivated
@@ -132,7 +126,7 @@ static int au1100fb_fb_blank(int blank_mode, struct fb_info *fbi)
                        /* Turn on panel */
                        fbdev->regs->lcd_control |= LCD_CONTROL_GO;
 #ifdef CONFIG_MIPS_PB1100
-                       if (drv_info.panel_idx == 1) {
+                       if (fbdev->panel_idx == 1) {
                                au_writew(au_readw(PB1100_G_CONTROL)
                                          | (PB1100_G_CONTROL_BL | PB1100_G_CONTROL_VDD),
                        PB1100_G_CONTROL);
@@ -147,7 +141,7 @@ static int au1100fb_fb_blank(int blank_mode, struct fb_info *fbi)
                        /* Turn off panel */
                        fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
 #ifdef CONFIG_MIPS_PB1100
-                       if (drv_info.panel_idx == 1) {
+                       if (fbdev->panel_idx == 1) {
                                au_writew(au_readw(PB1100_G_CONTROL)
                                          & ~(PB1100_G_CONTROL_BL | PB1100_G_CONTROL_VDD),
                        PB1100_G_CONTROL);
@@ -428,17 +422,6 @@ int au1100fb_fb_mmap(struct fb_info *fbi, struct vm_area_struct *vma)
        return 0;
 }
 
-/* fb_cursor
- * Used to disable cursor drawing...
- */
-int au1100fb_fb_cursor(struct fb_info *info, struct fb_cursor *cursor)
-{
-       if (nocursor)
-               return 0;
-       else
-               return -EINVAL; /* just to force soft_cursor() call */
-}
-
 static struct fb_ops au1100fb_ops =
 {
        .owner                  = THIS_MODULE,
@@ -450,13 +433,53 @@ static struct fb_ops au1100fb_ops =
        .fb_imageblit           = cfb_imageblit,
        .fb_rotate              = au1100fb_fb_rotate,
        .fb_mmap                = au1100fb_fb_mmap,
-       .fb_cursor              = au1100fb_fb_cursor,
 };
 
 
 /*-------------------------------------------------------------------------*/
 
-/* AU1100 LCD controller device driver */
+static int au1100fb_setup(struct au1100fb_device *fbdev)
+{
+       char *this_opt, *options;
+       int num_panels = ARRAY_SIZE(known_lcd_panels);
+
+       if (num_panels <= 0) {
+               print_err("No LCD panels supported by driver!");
+               return -ENODEV;
+       }
+
+       if (fb_get_options(DRIVER_NAME, &options))
+               return -ENODEV;
+       if (!options)
+               return -ENODEV;
+
+       while ((this_opt = strsep(&options, ",")) != NULL) {
+               /* Panel option */
+               if (!strncmp(this_opt, "panel:", 6)) {
+                       int i;
+                       this_opt += 6;
+                       for (i = 0; i < num_panels; i++) {
+                               if (!strncmp(this_opt, known_lcd_panels[i].name,
+                                            strlen(this_opt))) {
+                                       fbdev->panel = &known_lcd_panels[i];
+                                       fbdev->panel_idx = i;
+                                       break;
+                               }
+                       }
+                       if (i >= num_panels) {
+                               print_warn("Panel '%s' not supported!", this_opt);
+                               return -ENODEV;
+                       }
+               }
+               /* Unsupported option */
+               else
+                       print_warn("Unsupported option \"%s\"", this_opt);
+       }
+
+       print_info("Panel=%s", fbdev->panel->name);
+
+       return 0;
+}
 
 static int __devinit au1100fb_drv_probe(struct platform_device *dev)
 {
@@ -465,22 +488,21 @@ static int __devinit au1100fb_drv_probe(struct platform_device *dev)
        unsigned long page;
        u32 sys_clksrc;
 
-       if (!dev)
-                       return -EINVAL;
-
        /* Allocate new device private */
-       if (!(fbdev = kzalloc(sizeof(struct au1100fb_device), GFP_KERNEL))) {
+       fbdev = kzalloc(sizeof(struct au1100fb_device), GFP_KERNEL);
+       if (!fbdev) {
                print_err("fail to allocate device private record");
                return -ENOMEM;
        }
 
-       fbdev->panel = &known_lcd_panels[drv_info.panel_idx];
+       if (au1100fb_setup(fbdev))
+               goto failed;
 
        platform_set_drvdata(dev, (void *)fbdev);
 
        /* Allocate region for our registers and map them */
-       if (!(regs_res = platform_get_resource(to_platform_device(dev),
-                                       IORESOURCE_MEM, 0))) {
+       regs_res = platform_get_resource(dev, IORESOURCE_MEM, 0);
+       if (!regs_res) {
                print_err("fail to retrieve registers resource");
                return -EFAULT;
        }
@@ -500,13 +522,11 @@ static int __devinit au1100fb_drv_probe(struct platform_device *dev)
        print_dbg("Register memory map at %p", fbdev->regs);
        print_dbg("phys=0x%08x, size=%d", fbdev->regs_phys, fbdev->regs_len);
 
-
-
        /* Allocate the framebuffer to the maximum screen size * nbr of video buffers */
        fbdev->fb_len = fbdev->panel->xres * fbdev->panel->yres *
                        (fbdev->panel->bpp >> 3) * AU1100FB_NBR_VIDEO_BUFFERS;
 
-       fbdev->fb_mem = dma_alloc_coherent(dev, PAGE_ALIGN(fbdev->fb_len),
+       fbdev->fb_mem = dma_alloc_coherent(&dev->dev, PAGE_ALIGN(fbdev->fb_len),
                                        &fbdev->fb_phys, GFP_KERNEL);
        if (!fbdev->fb_mem) {
                print_err("fail to allocate frambuffer (size: %dK))",
@@ -525,7 +545,7 @@ static int __devinit au1100fb_drv_probe(struct platform_device *dev)
             page < PAGE_ALIGN((unsigned long)fbdev->fb_mem + fbdev->fb_len);
             page += PAGE_SIZE) {
 #if CONFIG_DMA_NONCOHERENT
-               SetPageReserved(virt_to_page(CAC_ADDR(page)));
+               SetPageReserved(virt_to_page(CAC_ADDR((void *)page)));
 #else
                SetPageReserved(virt_to_page(page));
 #endif
@@ -578,7 +598,8 @@ failed:
                release_mem_region(fbdev->regs_phys, fbdev->regs_len);
        }
        if (fbdev->fb_mem) {
-               dma_free_noncoherent(dev, fbdev->fb_len, fbdev->fb_mem, fbdev->fb_phys);
+               dma_free_noncoherent(&dev->dev, fbdev->fb_len, fbdev->fb_mem,
+                                    fbdev->fb_phys);
        }
        if (fbdev->info.cmap.len != 0) {
                fb_dealloc_cmap(&fbdev->info.cmap);
@@ -608,7 +629,8 @@ int au1100fb_drv_remove(struct platform_device *dev)
 
        release_mem_region(fbdev->regs_phys, fbdev->regs_len);
 
-       dma_free_coherent(dev, PAGE_ALIGN(fbdev->fb_len), fbdev->fb_mem, fbdev->fb_phys);
+       dma_free_coherent(&dev->dev, PAGE_ALIGN(fbdev->fb_len), fbdev->fb_mem,
+                         fbdev->fb_phys);
 
        fb_dealloc_cmap(&fbdev->info.cmap);
        kfree(fbdev->info.pseudo_palette);
@@ -675,101 +697,18 @@ static struct platform_driver au1100fb_driver = {
         .resume                = au1100fb_drv_resume,
 };
 
-/*-------------------------------------------------------------------------*/
-
-/* Kernel driver */
-
-int au1100fb_setup(char *options)
-{
-       char* this_opt;
-       int num_panels = ARRAY_SIZE(known_lcd_panels);
-       char* mode = NULL;
-       int panel_idx = 0;
-
-       if (num_panels <= 0) {
-               print_err("No LCD panels supported by driver!");
-               return -EFAULT;
-                       }
-
-       if (options) {
-               while ((this_opt = strsep(&options,",")) != NULL) {
-                       /* Panel option */
-                       if (!strncmp(this_opt, "panel:", 6)) {
-                               int i;
-                               this_opt += 6;
-                               for (i = 0; i < num_panels; i++) {
-                                       if (!strncmp(this_opt,
-                                                    known_lcd_panels[i].name,
-                                                       strlen(this_opt))) {
-                                               panel_idx = i;
-                                               break;
-                                       }
-                               }
-                               if (i >= num_panels) {
-                                       print_warn("Panel %s not supported!", this_opt);
-                               }
-                       }
-                       if (!strncmp(this_opt, "nocursor", 8)) {
-                               this_opt += 8;
-                               nocursor = 1;
-                               print_info("Cursor disabled");
-                       }
-                       /* Mode option (only option that start with digit) */
-                       else if (isdigit(this_opt[0])) {
-                               mode = kstrdup(this_opt, GFP_KERNEL);
-                               if (!mode) {
-                                       print_err("memory allocation failed");
-                                       return -ENOMEM;
-                               }
-                       }
-                       /* Unsupported option */
-                       else {
-                               print_warn("Unsupported option \"%s\"", this_opt);
-                       }
-               }
-       }
-
-       drv_info.panel_idx = panel_idx;
-       drv_info.opt_mode = mode;
-
-       print_info("Panel=%s Mode=%s",
-                       known_lcd_panels[drv_info.panel_idx].name,
-                       drv_info.opt_mode ? drv_info.opt_mode : "default");
-
-       return 0;
-}
-
-int __init au1100fb_init(void)
+static int __init au1100fb_load(void)
 {
-       char* options;
-       int ret;
-
-       print_info("" DRIVER_DESC "");
-
-       memset(&drv_info, 0, sizeof(drv_info));
-
-       if (fb_get_options(DRIVER_NAME, &options))
-               return -ENODEV;
-
-       /* Setup driver with options */
-       ret = au1100fb_setup(options);
-       if (ret < 0) {
-               print_err("Fail to setup driver");
-               return ret;
-       }
-
        return platform_driver_register(&au1100fb_driver);
 }
 
-void __exit au1100fb_cleanup(void)
+static void __exit au1100fb_unload(void)
 {
        platform_driver_unregister(&au1100fb_driver);
-
-       kfree(drv_info.opt_mode);
 }
 
-module_init(au1100fb_init);
-module_exit(au1100fb_cleanup);
+module_init(au1100fb_load);
+module_exit(au1100fb_unload);
 
 MODULE_DESCRIPTION(DRIVER_DESC);
 MODULE_LICENSE("GPL");
index 164fe2f231ec6c9c575df9a2ddbf4547d2b53de1..12d9642d54650cabb4e2b7af4c6e96aed40aac33 100644 (file)
@@ -108,6 +108,7 @@ struct au1100fb_device {
        unsigned char*          fb_mem;         /* FrameBuffer memory map */
        size_t                  fb_len;
        dma_addr_t              fb_phys;
+       int                     panel_idx;
 };
 
 /********************************************************************/
@@ -364,11 +365,6 @@ static struct au1100fb_panel known_lcd_panels[] =
        },
 };
 
-struct au1100fb_drv_info {
-       int     panel_idx;
-       char    *opt_mode;
-};
-
 /********************************************************************/
 
 /* Inline helpers */
index 5dff32ac8044be8de287c7e4c156dd0c577eb3c8..72005598040f0668762c0a8288865c8e809c01de 100644 (file)
 #include <asm/mach-au1x00/au1000.h>
 #include "au1200fb.h"
 
-#ifdef CONFIG_PM
-#include <asm/mach-au1x00/au1xxx_pm.h>
-#endif
-
-#ifndef CONFIG_FB_AU1200_DEVS
-#define CONFIG_FB_AU1200_DEVS 4
-#endif
-
 #define DRIVER_NAME "au1200fb"
 #define DRIVER_DESC "LCD controller driver for AU1200 processors"
 
-#define DEBUG 1
+#define DEBUG 0
 
 #define print_err(f, arg...) printk(KERN_ERR DRIVER_NAME ": " f "\n", ## arg)
 #define print_warn(f, arg...) printk(KERN_WARNING DRIVER_NAME ": " f "\n", ## arg)
@@ -150,7 +142,7 @@ struct au1200_lcd_iodata_t {
 
 /* Private, per-framebuffer management information (independent of the panel itself) */
 struct au1200fb_device {
-       struct fb_info fb_info;                 /* FB driver info record */
+       struct fb_info *fb_info;                /* FB driver info record */
 
        int                                     plane;
        unsigned char*          fb_mem;         /* FrameBuffer memory map */
@@ -158,7 +150,6 @@ struct au1200fb_device {
        dma_addr_t              fb_phys;
 };
 
-static struct au1200fb_device _au1200fb_devices[CONFIG_FB_AU1200_DEVS];
 /********************************************************************/
 
 /* LCD controller restrictions */
@@ -171,10 +162,18 @@ static struct au1200fb_device _au1200fb_devices[CONFIG_FB_AU1200_DEVS];
 /* Default number of visible screen buffer to allocate */
 #define AU1200FB_NBR_VIDEO_BUFFERS 1
 
+/* Default maximum number of fb devices to create */
+#define MAX_DEVICE_COUNT       4
+
+/* Default window configuration entry to use (see windows[]) */
+#define DEFAULT_WINDOW_INDEX   2
+
 /********************************************************************/
 
+static struct fb_info *_au1200fb_infos[MAX_DEVICE_COUNT];
 static struct au1200_lcd *lcd = (struct au1200_lcd *) AU1200_LCD_ADDR;
-static int window_index = 2; /* default is zero */
+static int device_count = MAX_DEVICE_COUNT;
+static int window_index = DEFAULT_WINDOW_INDEX;        /* default is zero */
 static int panel_index = 2; /* default is zero */
 static struct window_settings *win;
 static struct panel_settings *panel;
@@ -205,12 +204,6 @@ struct window_settings {
 extern int board_au1200fb_panel_init (void);
 extern int board_au1200fb_panel_shutdown (void);
 
-#ifdef CONFIG_PM
-int au1200fb_pm_callback(au1xxx_power_dev_t *dev,
-               au1xxx_request_t request, void *data);
-au1xxx_power_dev_t *LCD_pm_dev;
-#endif
-
 /*
  * Default window configurations
  */
@@ -652,25 +645,6 @@ static struct panel_settings known_lcd_panels[] =
 
 /********************************************************************/
 
-#ifdef CONFIG_PM
-static int set_brightness(unsigned int brightness)
-{
-       unsigned int hi1, divider;
-
-       /* limit brightness pwm duty to >= 30/1600 */
-       if (brightness < 30) {
-               brightness = 30;
-       }
-       divider = (lcd->pwmdiv & 0x3FFFF) + 1;
-       hi1 = (lcd->pwmhi >> 16) + 1;
-       hi1 = (((brightness & 0xFF) + 1) * divider >> 8);
-       lcd->pwmhi &= 0xFFFF;
-       lcd->pwmhi |= (hi1 << 16);
-
-       return brightness;
-}
-#endif /* CONFIG_PM */
-
 static int winbpp (unsigned int winctrl1)
 {
        int bits = 0;
@@ -712,8 +686,8 @@ static int fbinfo2index (struct fb_info *fb_info)
 {
        int i;
 
-       for (i = 0; i < CONFIG_FB_AU1200_DEVS; ++i) {
-               if (fb_info == (struct fb_info *)(&_au1200fb_devices[i].fb_info))
+       for (i = 0; i < device_count; ++i) {
+               if (fb_info == _au1200fb_infos[i])
                        return i;
        }
        printk("au1200fb: ERROR: fbinfo2index failed!\n");
@@ -962,7 +936,7 @@ static void au1200_setmode(struct au1200fb_device *fbdev)
        lcd->window[plane].winctrl2 = ( 0
                | LCD_WINCTRL2_CKMODE_00
                | LCD_WINCTRL2_DBM
-               | LCD_WINCTRL2_BX_N( fbdev->fb_info.fix.line_length)
+               | LCD_WINCTRL2_BX_N(fbdev->fb_info->fix.line_length)
                | LCD_WINCTRL2_SCX_1
                | LCD_WINCTRL2_SCY_1
                ) ;
@@ -1050,7 +1024,7 @@ static void au1200fb_update_fbinfo(struct fb_info *fbi)
 static int au1200fb_fb_check_var(struct fb_var_screeninfo *var,
        struct fb_info *fbi)
 {
-       struct au1200fb_device *fbdev = (struct au1200fb_device *)fbi;
+       struct au1200fb_device *fbdev = fbi->par;
        u32 pixclock;
        int screen_size, plane;
 
@@ -1142,7 +1116,7 @@ static int au1200fb_fb_check_var(struct fb_var_screeninfo *var,
  */
 static int au1200fb_fb_set_par(struct fb_info *fbi)
 {
-       struct au1200fb_device *fbdev = (struct au1200fb_device *)fbi;
+       struct au1200fb_device *fbdev = fbi->par;
 
        au1200fb_update_fbinfo(fbi);
        au1200_setmode(fbdev);
@@ -1246,11 +1220,7 @@ static int au1200fb_fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
 {
        unsigned int len;
        unsigned long start=0, off;
-       struct au1200fb_device *fbdev = (struct au1200fb_device *) info;
-
-#ifdef CONFIG_PM
-       au1xxx_pm_access(LCD_pm_dev);
-#endif
+       struct au1200fb_device *fbdev = info->par;
 
        if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) {
                return -EINVAL;
@@ -1461,10 +1431,6 @@ static int au1200fb_ioctl(struct fb_info *info, unsigned int cmd,
        int plane;
        int val;
 
-#ifdef CONFIG_PM
-       au1xxx_pm_access(LCD_pm_dev);
-#endif
-
        plane = fbinfo2index(info);
        print_dbg("au1200fb: ioctl %d on plane %d\n", cmd, plane);
 
@@ -1536,9 +1502,11 @@ static struct fb_ops au1200fb_fb_ops = {
        .fb_set_par     = au1200fb_fb_set_par,
        .fb_setcolreg   = au1200fb_fb_setcolreg,
        .fb_blank       = au1200fb_fb_blank,
-       .fb_fillrect    = cfb_fillrect,
-       .fb_copyarea    = cfb_copyarea,
-       .fb_imageblit   = cfb_imageblit,
+       .fb_fillrect    = sys_fillrect,
+       .fb_copyarea    = sys_copyarea,
+       .fb_imageblit   = sys_imageblit,
+       .fb_read        = fb_sys_read,
+       .fb_write       = fb_sys_write,
        .fb_sync        = NULL,
        .fb_ioctl       = au1200fb_ioctl,
        .fb_mmap        = au1200fb_fb_mmap,
@@ -1561,10 +1529,9 @@ static irqreturn_t au1200fb_handle_irq(int irq, void* dev_id)
 
 static int au1200fb_init_fbinfo(struct au1200fb_device *fbdev)
 {
-       struct fb_info *fbi = &fbdev->fb_info;
+       struct fb_info *fbi = fbdev->fb_info;
        int bpp;
 
-       memset(fbi, 0, sizeof(struct fb_info));
        fbi->fbops = &au1200fb_fb_ops;
 
        bpp = winbpp(win->w[fbdev->plane].mode_winctrl1);
@@ -1623,24 +1590,36 @@ static int au1200fb_init_fbinfo(struct au1200fb_device *fbdev)
 
 /* AU1200 LCD controller device driver */
 
-static int au1200fb_drv_probe(struct platform_device *dev)
+static int __devinit au1200fb_drv_probe(struct platform_device *dev)
 {
        struct au1200fb_device *fbdev;
+       struct fb_info *fbi = NULL;
        unsigned long page;
-       int bpp, plane, ret;
+       int bpp, plane, ret, irq;
 
-       if (!dev)
-               return -EINVAL;
+       /* shut gcc up */
+       ret = 0;
+       fbdev = NULL;
+
+       /* Kickstart the panel */
+       au1200_setpanel(panel);
 
-       for (plane = 0; plane < CONFIG_FB_AU1200_DEVS; ++plane) {
+       for (plane = 0; plane < device_count; ++plane) {
                bpp = winbpp(win->w[plane].mode_winctrl1);
                if (win->w[plane].xres == 0)
                        win->w[plane].xres = panel->Xres;
                if (win->w[plane].yres == 0)
                        win->w[plane].yres = panel->Yres;
 
-               fbdev = &_au1200fb_devices[plane];
-               memset(fbdev, 0, sizeof(struct au1200fb_device));
+               fbi = framebuffer_alloc(sizeof(struct au1200fb_device),
+                                       &dev->dev);
+               if (!fbi)
+                       goto failed;
+
+               _au1200fb_infos[plane] = fbi;
+               fbdev = fbi->par;
+               fbdev->fb_info = fbi;
+
                fbdev->plane = plane;
 
                /* Allocate the framebuffer to the maximum screen size */
@@ -1673,30 +1652,31 @@ static int au1200fb_drv_probe(struct platform_device *dev)
                        goto failed;
 
                /* Register new framebuffer */
-               if ((ret = register_framebuffer(&fbdev->fb_info)) < 0) {
+               ret = register_framebuffer(fbi);
+               if (ret < 0) {
                        print_err("cannot register new framebuffer");
                        goto failed;
                }
 
-               au1200fb_fb_set_par(&fbdev->fb_info);
+               au1200fb_fb_set_par(fbi);
 
 #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
                if (plane == 0)
-                       if (fb_prepare_logo(&fbdev->fb_info, FB_ROTATE_UR)) {
+                       if (fb_prepare_logo(fbi, FB_ROTATE_UR)) {
                                /* Start display and show logo on boot */
-                               fb_set_cmap(&fbdev->fb_info.cmap,
-                                               &fbdev->fb_info);
-
-                               fb_show_logo(&fbdev->fb_info, FB_ROTATE_UR);
+                               fb_set_cmap(&fbi->cmap, fbi);
+                               fb_show_logo(fbi, FB_ROTATE_UR);
                        }
 #endif
        }
 
        /* Now hook interrupt too */
-       if ((ret = request_irq(AU1200_LCD_INT, au1200fb_handle_irq,
-                         IRQF_DISABLED | IRQF_SHARED, "lcd", (void *)dev)) < 0) {
+       irq = platform_get_irq(dev, 0);
+       ret = request_irq(irq, au1200fb_handle_irq,
+                         IRQF_SHARED, "lcd", (void *)dev);
+       if (ret) {
                print_err("fail to request interrupt line %d (err: %d)",
-                         AU1200_LCD_INT, ret);
+                         irq, ret);
                goto failed;
        }
 
@@ -1705,84 +1685,108 @@ static int au1200fb_drv_probe(struct platform_device *dev)
 failed:
        /* NOTE: This only does the current plane/window that failed; others are still active */
        if (fbdev->fb_mem)
-               dma_free_noncoherent(dev, PAGE_ALIGN(fbdev->fb_len),
+               dma_free_noncoherent(&dev->dev, PAGE_ALIGN(fbdev->fb_len),
                                fbdev->fb_mem, fbdev->fb_phys);
-       if (fbdev->fb_info.cmap.len != 0)
-               fb_dealloc_cmap(&fbdev->fb_info.cmap);
-       if (fbdev->fb_info.pseudo_palette)
-               kfree(fbdev->fb_info.pseudo_palette);
+       if (fbi) {
+               if (fbi->cmap.len != 0)
+                       fb_dealloc_cmap(&fbi->cmap);
+               kfree(fbi->pseudo_palette);
+       }
        if (plane == 0)
                free_irq(AU1200_LCD_INT, (void*)dev);
        return ret;
 }
 
-static int au1200fb_drv_remove(struct platform_device *dev)
+static int __devexit au1200fb_drv_remove(struct platform_device *dev)
 {
        struct au1200fb_device *fbdev;
+       struct fb_info *fbi;
        int plane;
 
-       if (!dev)
-               return -ENODEV;
-
        /* Turn off the panel */
        au1200_setpanel(NULL);
 
-       for (plane = 0; plane < CONFIG_FB_AU1200_DEVS; ++plane)
-       {
-               fbdev = &_au1200fb_devices[plane];
+       for (plane = 0; plane < device_count; ++plane)  {
+               fbi = _au1200fb_infos[plane];
+               fbdev = fbi->par;
 
                /* Clean up all probe data */
-               unregister_framebuffer(&fbdev->fb_info);
+               unregister_framebuffer(fbi);
                if (fbdev->fb_mem)
                        dma_free_noncoherent(&dev->dev,
                                        PAGE_ALIGN(fbdev->fb_len),
                                        fbdev->fb_mem, fbdev->fb_phys);
-               if (fbdev->fb_info.cmap.len != 0)
-                       fb_dealloc_cmap(&fbdev->fb_info.cmap);
-               if (fbdev->fb_info.pseudo_palette)
-                       kfree(fbdev->fb_info.pseudo_palette);
+               if (fbi->cmap.len != 0)
+                       fb_dealloc_cmap(&fbi->cmap);
+               kfree(fbi->pseudo_palette);
+
+               framebuffer_release(fbi);
+               _au1200fb_infos[plane] = NULL;
        }
 
-       free_irq(AU1200_LCD_INT, (void *)dev);
+       free_irq(platform_get_irq(dev, 0), (void *)dev);
 
        return 0;
 }
 
 #ifdef CONFIG_PM
-static int au1200fb_drv_suspend(struct platform_device *dev, u32 state)
+static int au1200fb_drv_suspend(struct device *dev)
 {
-       /* TODO */
+       au1200_setpanel(NULL);
+
+       lcd->outmask = 0;
+       au_sync();
+
        return 0;
 }
 
-static int au1200fb_drv_resume(struct platform_device *dev)
+static int au1200fb_drv_resume(struct device *dev)
 {
-       /* TODO */
+       struct fb_info *fbi;
+       int i;
+
+       /* Kickstart the panel */
+       au1200_setpanel(panel);
+
+       for (i = 0; i < device_count; i++) {
+               fbi = _au1200fb_infos[i];
+               au1200fb_fb_set_par(fbi);
+       }
+
        return 0;
 }
+
+static const struct dev_pm_ops au1200fb_pmops = {
+       .suspend        = au1200fb_drv_suspend,
+       .resume         = au1200fb_drv_resume,
+       .freeze         = au1200fb_drv_suspend,
+       .thaw           = au1200fb_drv_resume,
+};
+
+#define AU1200FB_PMOPS (&au1200fb_pmops)
+
+#else
+#define AU1200FB_PMOPS NULL
 #endif /* CONFIG_PM */
 
 static struct platform_driver au1200fb_driver = {
        .driver = {
-               .name           = "au1200-lcd",
-               .owner          = THIS_MODULE,
+               .name   = "au1200-lcd",
+               .owner  = THIS_MODULE,
+               .pm     = AU1200FB_PMOPS,
        },
        .probe          = au1200fb_drv_probe,
-       .remove         = au1200fb_drv_remove,
-#ifdef CONFIG_PM
-       .suspend        = au1200fb_drv_suspend,
-       .resume         = au1200fb_drv_resume,
-#endif
+       .remove         = __devexit_p(au1200fb_drv_remove),
 };
 
 /*-------------------------------------------------------------------------*/
 
 /* Kernel driver */
 
-static void au1200fb_setup(void)
+static int au1200fb_setup(void)
 {
-       charoptions = NULL;
-       char* this_opt;
+       char *options = NULL;
+       char *this_opt, *endptr;
        int num_panels = ARRAY_SIZE(known_lcd_panels);
        int panel_idx = -1;
 
@@ -1827,70 +1831,42 @@ static void au1200fb_setup(void)
                                nohwcursor = 1;
                        }
 
-                       /* Unsupported option */
-                       else {
-                               print_warn("Unsupported option \"%s\"", this_opt);
+                       else if (strncmp(this_opt, "devices:", 8) == 0) {
+                               this_opt += 8;
+                               device_count = simple_strtol(this_opt,
+                                                            &endptr, 0);
+                               if ((device_count < 0) ||
+                                   (device_count > MAX_DEVICE_COUNT))
+                                       device_count = MAX_DEVICE_COUNT;
                        }
-               }
-       }
-}
 
-#ifdef CONFIG_PM
-static int au1200fb_pm_callback(au1xxx_power_dev_t *dev,
-               au1xxx_request_t request, void *data) {
-       int retval = -1;
-       unsigned int d = 0;
-       unsigned int brightness = 0;
-
-       if (request == AU1XXX_PM_SLEEP) {
-               board_au1200fb_panel_shutdown();
-       }
-       else if (request == AU1XXX_PM_WAKEUP) {
-               if(dev->prev_state == SLEEP_STATE)
-               {
-                       int plane;
-                       au1200_setpanel(panel);
-                       for (plane = 0; plane < CONFIG_FB_AU1200_DEVS; ++plane)         {
-                               struct au1200fb_device *fbdev;
-                               fbdev = &_au1200fb_devices[plane];
-                               au1200fb_fb_set_par(&fbdev->fb_info);
+                       else if (strncmp(this_opt, "wincfg:", 7) == 0) {
+                               this_opt += 7;
+                               window_index = simple_strtol(this_opt,
+                                                            &endptr, 0);
+                               if ((window_index < 0) ||
+                                   (window_index >= ARRAY_SIZE(windows)))
+                                       window_index = DEFAULT_WINDOW_INDEX;
                        }
-               }
 
-               d = *((unsigned int*)data);
-               if(d <=10) brightness = 26;
-               else if(d<=20) brightness = 51;
-               else if(d<=30) brightness = 77;
-               else if(d<=40) brightness = 102;
-               else if(d<=50) brightness = 128;
-               else if(d<=60) brightness = 153;
-               else if(d<=70) brightness = 179;
-               else if(d<=80) brightness = 204;
-               else if(d<=90) brightness = 230;
-               else brightness = 255;
-               set_brightness(brightness);
-       } else if (request == AU1XXX_PM_GETSTATUS) {
-               return dev->cur_state;
-       } else if (request == AU1XXX_PM_ACCESS) {
-               if (dev->cur_state != SLEEP_STATE)
-                       return retval;
-               else {
-                       au1200_setpanel(panel);
+                       else if (strncmp(this_opt, "off", 3) == 0)
+                               return 1;
+                       /* Unsupported option */
+                       else {
+                               print_warn("Unsupported option \"%s\"", this_opt);
+                       }
                }
-       } else if (request == AU1XXX_PM_IDLE) {
-       } else if (request == AU1XXX_PM_CLEANUP) {
        }
-
-       return retval;
+       return 0;
 }
-#endif
 
 static int __init au1200fb_init(void)
 {
        print_info("" DRIVER_DESC "");
 
        /* Setup driver with options */
-       au1200fb_setup();
+       if (au1200fb_setup())
+               return -ENODEV;
 
        /* Point to the panel selected */
        panel = &known_lcd_panels[panel_index];
@@ -1899,17 +1875,6 @@ static int __init au1200fb_init(void)
        printk(DRIVER_NAME ": Panel %d %s\n", panel_index, panel->name);
        printk(DRIVER_NAME ": Win %d %s\n", window_index, win->name);
 
-       /* Kickstart the panel, the framebuffers/windows come soon enough */
-       au1200_setpanel(panel);
-
-       #ifdef CONFIG_PM
-       LCD_pm_dev = new_au1xxx_power_device("LCD", &au1200fb_pm_callback, NULL);
-       if ( LCD_pm_dev == NULL)
-               printk(KERN_INFO "Unable to create a power management device entry for the au1200fb.\n");
-       else
-               printk(KERN_INFO "Power management device entry for the au1200fb loaded.\n");
-       #endif
-
        return platform_driver_register(&au1200fb_driver);
 }
 
index 183b6f6398523d86fbb14a45f5fa08025ac71c3e..66bc74d9ce2af30889d026835d00442923cbc822 100644 (file)
@@ -7,7 +7,6 @@
  */
 
 #include <linux/module.h>
-#include <linux/version.h>
 #include <linux/init.h>
 #include <linux/errno.h>
 #include <linux/pm.h>
index d06886a2bfb564a4e1651083835037d79dbca8f1..6c68a6899e8769c0f131c91860e3467240bcb87c 100644 (file)
@@ -7,7 +7,6 @@
  */
 
 #include <linux/module.h>
-#include <linux/version.h>
 #include <linux/init.h>
 #include <linux/errno.h>
 #include <linux/pm.h>
@@ -932,7 +931,6 @@ out:
 out1:
        backlight_device_unregister(bl);
 out2:
-       i2c_set_clientdata(client, NULL);
        kfree(data);
 
        return ret;
@@ -952,7 +950,6 @@ static int __devexit adp8870_remove(struct i2c_client *client)
                        &adp8870_bl_attr_group);
 
        backlight_device_unregister(data->bl);
-       i2c_set_clientdata(client, NULL);
        kfree(data);
 
        return 0;
index 8c6befd65a33240ceed7da9f2a784a463b5f0381..adb191466d646355fdfcb5193c80b864631c3919 100644 (file)
@@ -56,7 +56,7 @@ static int genericbl_get_intensity(struct backlight_device *bd)
  * Called when the battery is low to limit the backlight intensity.
  * If limit==0 clear any limit, otherwise limit the intensity
  */
-void corgibl_limit_intensity(int limit)
+void genericbl_limit_intensity(int limit)
 {
        struct backlight_device *bd = generic_backlight_device;
 
@@ -68,7 +68,7 @@ void corgibl_limit_intensity(int limit)
        backlight_update_status(generic_backlight_device);
        mutex_unlock(&bd->ops_lock);
 }
-EXPORT_SYMBOL(corgibl_limit_intensity);
+EXPORT_SYMBOL(genericbl_limit_intensity);
 
 static const struct backlight_ops genericbl_ops = {
        .options = BL_CORE_SUSPENDRESUME,
index 98ad3e5f7c853cead7388f09e725e96c80a5e8ef..3543f1b7d5f1cbcd42e0393d9791588196fba247 100644 (file)
@@ -52,15 +52,11 @@ static void l4f00242t03_lcd_init(struct spi_device *spi)
 
        dev_dbg(&spi->dev, "initializing LCD\n");
 
-       if (priv->io_reg) {
-               regulator_set_voltage(priv->io_reg, 1800000, 1800000);
-               regulator_enable(priv->io_reg);
-       }
+       regulator_set_voltage(priv->io_reg, 1800000, 1800000);
+       regulator_enable(priv->io_reg);
 
-       if (priv->core_reg) {
-               regulator_set_voltage(priv->core_reg, 2800000, 2800000);
-               regulator_enable(priv->core_reg);
-       }
+       regulator_set_voltage(priv->core_reg, 2800000, 2800000);
+       regulator_enable(priv->core_reg);
 
        l4f00242t03_reset(pdata->reset_gpio);
 
@@ -78,11 +74,8 @@ static void l4f00242t03_lcd_powerdown(struct spi_device *spi)
 
        gpio_set_value(pdata->data_enable_gpio, 0);
 
-       if (priv->io_reg)
-               regulator_disable(priv->io_reg);
-
-       if (priv->core_reg)
-               regulator_disable(priv->core_reg);
+       regulator_disable(priv->io_reg);
+       regulator_disable(priv->core_reg);
 }
 
 static int l4f00242t03_lcd_power_get(struct lcd_device *ld)
@@ -178,47 +171,34 @@ static int __devinit l4f00242t03_probe(struct spi_device *spi)
 
        priv->spi = spi;
 
-       ret = gpio_request(pdata->reset_gpio, "lcd l4f00242t03 reset");
+       ret = gpio_request_one(pdata->reset_gpio, GPIOF_OUT_INIT_HIGH,
+                                               "lcd l4f00242t03 reset");
        if (ret) {
                dev_err(&spi->dev,
                        "Unable to get the lcd l4f00242t03 reset gpio.\n");
                goto err;
        }
 
-       ret = gpio_direction_output(pdata->reset_gpio, 1);
-       if (ret)
-               goto err2;
-
-       ret = gpio_request(pdata->data_enable_gpio,
-                               "lcd l4f00242t03 data enable");
+       ret = gpio_request_one(pdata->data_enable_gpio, GPIOF_OUT_INIT_LOW,
+                                               "lcd l4f00242t03 data enable");
        if (ret) {
                dev_err(&spi->dev,
                        "Unable to get the lcd l4f00242t03 data en gpio.\n");
                goto err2;
        }
 
-       ret = gpio_direction_output(pdata->data_enable_gpio, 0);
-       if (ret)
+       priv->io_reg = regulator_get(&spi->dev, "vdd");
+       if (IS_ERR(priv->io_reg)) {
+               dev_err(&spi->dev, "%s: Unable to get the IO regulator\n",
+                      __func__);
                goto err3;
-
-       if (pdata->io_supply) {
-               priv->io_reg = regulator_get(NULL, pdata->io_supply);
-
-               if (IS_ERR(priv->io_reg)) {
-                       pr_err("%s: Unable to get the IO regulator\n",
-                                                               __func__);
-                       goto err3;
-               }
        }
 
-       if (pdata->core_supply) {
-               priv->core_reg = regulator_get(NULL, pdata->core_supply);
-
-               if (IS_ERR(priv->core_reg)) {
-                       pr_err("%s: Unable to get the core regulator\n",
-                                                               __func__);
-                       goto err4;
-               }
+       priv->core_reg = regulator_get(&spi->dev, "vcore");
+       if (IS_ERR(priv->core_reg)) {
+               dev_err(&spi->dev, "%s: Unable to get the core regulator\n",
+                      __func__);
+               goto err4;
        }
 
        priv->ld = lcd_device_register("l4f00242t03",
@@ -238,11 +218,9 @@ static int __devinit l4f00242t03_probe(struct spi_device *spi)
        return 0;
 
 err5:
-       if (priv->core_reg)
-               regulator_put(priv->core_reg);
+       regulator_put(priv->core_reg);
 err4:
-       if (priv->io_reg)
-               regulator_put(priv->io_reg);
+       regulator_put(priv->io_reg);
 err3:
        gpio_free(pdata->data_enable_gpio);
 err2:
@@ -266,10 +244,8 @@ static int __devexit l4f00242t03_remove(struct spi_device *spi)
        gpio_free(pdata->data_enable_gpio);
        gpio_free(pdata->reset_gpio);
 
-       if (priv->io_reg)
-               regulator_put(priv->io_reg);
-       if (priv->core_reg)
-               regulator_put(priv->core_reg);
+       regulator_put(priv->io_reg);
+       regulator_put(priv->core_reg);
 
        kfree(priv);
 
index 2464b910b5905cd3fb4db743eb5904f8c13e1ea4..56720fb476b3b2548adc468d5c70ef999eecf5fe 100644 (file)
@@ -633,7 +633,7 @@ static int __devinit bfin_bf54x_probe(struct platform_device *pdev)
                goto out7;
        }
 
-       if (request_irq(info->irq, bfin_bf54x_irq_error, IRQF_DISABLED,
+       if (request_irq(info->irq, bfin_bf54x_irq_error, 0,
                        "PPI ERROR", info) < 0) {
                printk(KERN_ERR DRIVER_NAME
                       ": unable to request PPI ERROR IRQ\n");
index 23b6c4b62c78cdd642083b7b36245dca2d13d5e6..c633068372c9d733f8877b5ab8b75a776c2eeb92 100644 (file)
@@ -695,7 +695,7 @@ static int __devinit bfin_lq035q1_probe(struct platform_device *pdev)
                goto out7;
        }
 
-       ret = request_irq(info->irq, bfin_lq035q1_irq_error, IRQF_DISABLED,
+       ret = request_irq(info->irq, bfin_lq035q1_irq_error, 0,
                        DRIVER_NAME" PPI ERROR", info);
        if (ret < 0) {
                dev_err(&pdev->dev, "unable to request PPI ERROR IRQ\n");
index d8de29f0dd8d9111f772cc43a02627c20ac36e6f..d5e126759612571b52b227dcb9a8ef6b70025dc1 100644 (file)
@@ -529,7 +529,7 @@ static int __devinit bfin_t350mcqb_probe(struct platform_device *pdev)
                goto out7;
        }
 
-       ret = request_irq(info->irq, bfin_t350mcqb_irq_error, IRQF_DISABLED,
+       ret = request_irq(info->irq, bfin_t350mcqb_irq_error, 0,
                        "PPI ERROR", info);
        if (ret < 0) {
                printk(KERN_ERR DRIVER_NAME
index 8486f541156bb3ffd8807b2a8c5fecade9d53de9..811dd7f6aa415b696c7c704c17a92504f8d926ca 100644 (file)
@@ -481,7 +481,7 @@ static int __devinit bfin_adv7393_fb_probe(struct i2c_client *client,
                goto out_4;
        }
 
-       if (request_irq(IRQ_PPI_ERROR, ppi_irq_error, IRQF_DISABLED,
+       if (request_irq(IRQ_PPI_ERROR, ppi_irq_error, 0,
                        "PPI ERROR", fbdev) < 0) {
                dev_err(&client->dev, "unable to request PPI ERROR IRQ\n");
                ret = -EFAULT;
index caaa27d4a46a95c76da928a4353cd7d8087d1a95..cb09aa1fa138618c13278de877d5ecfb9b845582 100644 (file)
 #define CARMINEFB_DEFAULT_VIDEO_MODE   1
 
 static unsigned int fb_mode = CARMINEFB_DEFAULT_VIDEO_MODE;
-module_param(fb_mode, uint, 444);
+module_param(fb_mode, uint, 0444);
 MODULE_PARM_DESC(fb_mode, "Initial video mode as integer.");
 
 static char *fb_mode_str;
-module_param(fb_mode_str, charp, 444);
+module_param(fb_mode_str, charp, 0444);
 MODULE_PARM_DESC(fb_mode_str, "Initial video mode in characters.");
 
 /*
@@ -46,7 +46,7 @@ MODULE_PARM_DESC(fb_mode_str, "Initial video mode in characters.");
  * 0b010 Display 1
  */
 static int fb_displays = CARMINE_USE_DISPLAY0 | CARMINE_USE_DISPLAY1;
-module_param(fb_displays, int, 444);
+module_param(fb_displays, int, 0444);
 MODULE_PARM_DESC(fb_displays, "Bit mode, which displays are used");
 
 struct carmine_hw {
index 9075bea55879fc9c3eb507dc9e7e2a4c707111e1..7b2c40abae15b21e5ba26f460d809c216fb8e30a 100644 (file)
@@ -550,7 +550,7 @@ static void control_set_hardware(struct fb_info_control *p, struct fb_par_contro
 
 
 /*
- * Parse user speficied options (`video=controlfb:')
+ * Parse user specified options (`video=controlfb:')
  */
 static void __init control_setup(char *options)
 {
index fcdac872522d66702e0035bfda682ae189547eec..55f91d9ab00bd18bd01df877eab846a310595956 100644 (file)
@@ -35,6 +35,9 @@
 
 #define DRIVER_NAME "da8xx_lcdc"
 
+#define LCD_VERSION_1  1
+#define LCD_VERSION_2  2
+
 /* LCD Status Register */
 #define LCD_END_OF_FRAME1              BIT(9)
 #define LCD_END_OF_FRAME0              BIT(8)
@@ -49,7 +52,9 @@
 #define LCD_DMA_BURST_4                        0x2
 #define LCD_DMA_BURST_8                        0x3
 #define LCD_DMA_BURST_16               0x4
-#define LCD_END_OF_FRAME_INT_ENA       BIT(2)
+#define LCD_V1_END_OF_FRAME_INT_ENA    BIT(2)
+#define LCD_V2_END_OF_FRAME0_INT_ENA   BIT(8)
+#define LCD_V2_END_OF_FRAME1_INT_ENA   BIT(9)
 #define LCD_DUAL_FRAME_BUFFER_ENABLE   BIT(0)
 
 /* LCD Control Register */
 #define LCD_MONO_8BIT_MODE             BIT(9)
 #define LCD_RASTER_ORDER               BIT(8)
 #define LCD_TFT_MODE                   BIT(7)
-#define LCD_UNDERFLOW_INT_ENA          BIT(6)
-#define LCD_PL_ENABLE                  BIT(4)
+#define LCD_V1_UNDERFLOW_INT_ENA       BIT(6)
+#define LCD_V2_UNDERFLOW_INT_ENA       BIT(5)
+#define LCD_V1_PL_INT_ENA              BIT(4)
+#define LCD_V2_PL_INT_ENA              BIT(6)
 #define LCD_MONOCHROME_MODE            BIT(1)
 #define LCD_RASTER_ENABLE              BIT(0)
 #define LCD_TFT_ALT_ENABLE             BIT(23)
 #define LCD_STN_565_ENABLE             BIT(24)
+#define LCD_V2_DMA_CLK_EN              BIT(2)
+#define LCD_V2_LIDD_CLK_EN             BIT(1)
+#define LCD_V2_CORE_CLK_EN             BIT(0)
+#define LCD_V2_LPP_B10                 26
 
 /* LCD Raster Timing 2 Register */
 #define LCD_AC_BIAS_TRANSITIONS_PER_INT(x)     ((x) << 16)
@@ -82,6 +93,7 @@
 #define LCD_INVERT_FRAME_CLOCK                 BIT(20)
 
 /* LCD Block */
+#define  LCD_PID_REG                           0x0
 #define  LCD_CTRL_REG                          0x4
 #define  LCD_STAT_REG                          0x8
 #define  LCD_RASTER_CTRL_REG                   0x28
 #define  LCD_DMA_FRM_BUF_BASE_ADDR_1_REG       0x4C
 #define  LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG    0x50
 
+/* Interrupt Registers available only in Version 2 */
+#define  LCD_RAW_STAT_REG                      0x58
+#define  LCD_MASKED_STAT_REG                   0x5c
+#define  LCD_INT_ENABLE_SET_REG                        0x60
+#define  LCD_INT_ENABLE_CLR_REG                        0x64
+#define  LCD_END_OF_INT_IND_REG                        0x68
+
+/* Clock registers available only on Version 2 */
+#define  LCD_CLK_ENABLE_REG                    0x6c
+#define  LCD_CLK_RESET_REG                     0x70
+
 #define LCD_NUM_BUFFERS        2
 
 #define WSI_TIMEOUT    50
 
 static resource_size_t da8xx_fb_reg_base;
 static struct resource *lcdc_regs;
+static unsigned int lcd_revision;
+static irq_handler_t lcdc_irq_handler;
 
 static inline unsigned int lcdc_read(unsigned int addr)
 {
@@ -240,6 +265,7 @@ static void lcd_blit(int load_mode, struct da8xx_fb_par *par)
        u32 end;
        u32 reg_ras;
        u32 reg_dma;
+       u32 reg_int;
 
        /* init reg to clear PLM (loading mode) fields */
        reg_ras = lcdc_read(LCD_RASTER_CTRL_REG);
@@ -252,7 +278,14 @@ static void lcd_blit(int load_mode, struct da8xx_fb_par *par)
                end      = par->dma_end;
 
                reg_ras |= LCD_PALETTE_LOAD_MODE(DATA_ONLY);
-               reg_dma |= LCD_END_OF_FRAME_INT_ENA;
+               if (lcd_revision == LCD_VERSION_1) {
+                       reg_dma |= LCD_V1_END_OF_FRAME_INT_ENA;
+               } else {
+                       reg_int = lcdc_read(LCD_INT_ENABLE_SET_REG) |
+                               LCD_V2_END_OF_FRAME0_INT_ENA |
+                               LCD_V2_END_OF_FRAME1_INT_ENA;
+                       lcdc_write(reg_int, LCD_INT_ENABLE_SET_REG);
+               }
                reg_dma |= LCD_DUAL_FRAME_BUFFER_ENABLE;
 
                lcdc_write(start, LCD_DMA_FRM_BUF_BASE_ADDR_0_REG);
@@ -264,7 +297,14 @@ static void lcd_blit(int load_mode, struct da8xx_fb_par *par)
                end      = start + par->palette_sz - 1;
 
                reg_ras |= LCD_PALETTE_LOAD_MODE(PALETTE_ONLY);
-               reg_ras |= LCD_PL_ENABLE;
+
+               if (lcd_revision == LCD_VERSION_1) {
+                       reg_ras |= LCD_V1_PL_INT_ENA;
+               } else {
+                       reg_int = lcdc_read(LCD_INT_ENABLE_SET_REG) |
+                               LCD_V2_PL_INT_ENA;
+                       lcdc_write(reg_int, LCD_INT_ENABLE_SET_REG);
+               }
 
                lcdc_write(start, LCD_DMA_FRM_BUF_BASE_ADDR_0_REG);
                lcdc_write(end, LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG);
@@ -348,6 +388,7 @@ static void lcd_cfg_vertical_sync(int back_porch, int pulse_width,
 static int lcd_cfg_display(const struct lcd_ctrl_config *cfg)
 {
        u32 reg;
+       u32 reg_int;
 
        reg = lcdc_read(LCD_RASTER_CTRL_REG) & ~(LCD_TFT_MODE |
                                                LCD_MONO_8BIT_MODE |
@@ -375,7 +416,13 @@ static int lcd_cfg_display(const struct lcd_ctrl_config *cfg)
        }
 
        /* enable additional interrupts here */
-       reg |= LCD_UNDERFLOW_INT_ENA;
+       if (lcd_revision == LCD_VERSION_1) {
+               reg |= LCD_V1_UNDERFLOW_INT_ENA;
+       } else {
+               reg_int = lcdc_read(LCD_INT_ENABLE_SET_REG) |
+                       LCD_V2_UNDERFLOW_INT_ENA;
+               lcdc_write(reg_int, LCD_INT_ENABLE_SET_REG);
+       }
 
        lcdc_write(reg, LCD_RASTER_CTRL_REG);
 
@@ -413,18 +460,43 @@ static int lcd_cfg_frame_buffer(struct da8xx_fb_par *par, u32 width, u32 height,
 
        /* Set the Panel Width */
        /* Pixels per line = (PPL + 1)*16 */
-       /*0x3F in bits 4..9 gives max horisontal resolution = 1024 pixels*/
-       width &= 0x3f0;
+       if (lcd_revision == LCD_VERSION_1) {
+               /*
+                * 0x3F in bits 4..9 gives max horizontal resolution = 1024
+                * pixels.
+                */
+               width &= 0x3f0;
+       } else {
+               /*
+                * 0x7F in bits 4..10 gives max horizontal resolution = 2048
+                * pixels.
+                */
+               width &= 0x7f0;
+       }
+
        reg = lcdc_read(LCD_RASTER_TIMING_0_REG);
        reg &= 0xfffffc00;
-       reg |= ((width >> 4) - 1) << 4;
+       if (lcd_revision == LCD_VERSION_1) {
+               reg |= ((width >> 4) - 1) << 4;
+       } else {
+               width = (width >> 4) - 1;
+               reg |= ((width & 0x3f) << 4) | ((width & 0x40) >> 3);
+       }
        lcdc_write(reg, LCD_RASTER_TIMING_0_REG);
 
        /* Set the Panel Height */
+       /* Set bits 9:0 of Lines Per Pixel */
        reg = lcdc_read(LCD_RASTER_TIMING_1_REG);
        reg = ((height - 1) & 0x3ff) | (reg & 0xfffffc00);
        lcdc_write(reg, LCD_RASTER_TIMING_1_REG);
 
+       /* Set bit 10 of Lines Per Pixel */
+       if (lcd_revision == LCD_VERSION_2) {
+               reg = lcdc_read(LCD_RASTER_TIMING_2_REG);
+               reg |= ((height - 1) & 0x400) << 16;
+               lcdc_write(reg, LCD_RASTER_TIMING_2_REG);
+       }
+
        /* Set the Raster Order of the Frame Buffer */
        reg = lcdc_read(LCD_RASTER_CTRL_REG) & ~(1 << 8);
        if (raster_order)
@@ -511,6 +583,9 @@ static void lcd_reset(struct da8xx_fb_par *par)
        /* DMA has to be disabled */
        lcdc_write(0, LCD_DMA_CTRL_REG);
        lcdc_write(0, LCD_RASTER_CTRL_REG);
+
+       if (lcd_revision == LCD_VERSION_2)
+               lcdc_write(0, LCD_INT_ENABLE_SET_REG);
 }
 
 static void lcd_calc_clk_divider(struct da8xx_fb_par *par)
@@ -523,6 +598,11 @@ static void lcd_calc_clk_divider(struct da8xx_fb_par *par)
        /* Configure the LCD clock divisor. */
        lcdc_write(LCD_CLK_DIVISOR(div) |
                        (LCD_RASTER_MODE & 0x1), LCD_CTRL_REG);
+
+       if (lcd_revision == LCD_VERSION_2)
+               lcdc_write(LCD_V2_DMA_CLK_EN | LCD_V2_LIDD_CLK_EN |
+                               LCD_V2_CORE_CLK_EN, LCD_CLK_ENABLE_REG);
+
 }
 
 static int lcd_init(struct da8xx_fb_par *par, const struct lcd_ctrl_config *cfg,
@@ -583,7 +663,63 @@ static int lcd_init(struct da8xx_fb_par *par, const struct lcd_ctrl_config *cfg,
        return 0;
 }
 
-static irqreturn_t lcdc_irq_handler(int irq, void *arg)
+/* IRQ handler for version 2 of LCDC */
+static irqreturn_t lcdc_irq_handler_rev02(int irq, void *arg)
+{
+       struct da8xx_fb_par *par = arg;
+       u32 stat = lcdc_read(LCD_MASKED_STAT_REG);
+       u32 reg_int;
+
+       if ((stat & LCD_SYNC_LOST) && (stat & LCD_FIFO_UNDERFLOW)) {
+               lcd_disable_raster();
+               lcdc_write(stat, LCD_MASKED_STAT_REG);
+               lcd_enable_raster();
+       } else if (stat & LCD_PL_LOAD_DONE) {
+               /*
+                * Must disable raster before changing state of any control bit.
+                * And also must be disabled before clearing the PL loading
+                * interrupt via the following write to the status register. If
+                * this is done after then one gets multiple PL done interrupts.
+                */
+               lcd_disable_raster();
+
+               lcdc_write(stat, LCD_MASKED_STAT_REG);
+
+               /* Disable PL completion inerrupt */
+               reg_int = lcdc_read(LCD_INT_ENABLE_CLR_REG) |
+                      (LCD_V2_PL_INT_ENA);
+               lcdc_write(reg_int, LCD_INT_ENABLE_CLR_REG);
+
+               /* Setup and start data loading mode */
+               lcd_blit(LOAD_DATA, par);
+       } else {
+               lcdc_write(stat, LCD_MASKED_STAT_REG);
+
+               if (stat & LCD_END_OF_FRAME0) {
+                       lcdc_write(par->dma_start,
+                                  LCD_DMA_FRM_BUF_BASE_ADDR_0_REG);
+                       lcdc_write(par->dma_end,
+                                  LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG);
+                       par->vsync_flag = 1;
+                       wake_up_interruptible(&par->vsync_wait);
+               }
+
+               if (stat & LCD_END_OF_FRAME1) {
+                       lcdc_write(par->dma_start,
+                                  LCD_DMA_FRM_BUF_BASE_ADDR_1_REG);
+                       lcdc_write(par->dma_end,
+                                  LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG);
+                       par->vsync_flag = 1;
+                       wake_up_interruptible(&par->vsync_wait);
+               }
+       }
+
+       lcdc_write(0, LCD_END_OF_INT_IND_REG);
+       return IRQ_HANDLED;
+}
+
+/* IRQ handler for version 1 LCDC */
+static irqreturn_t lcdc_irq_handler_rev01(int irq, void *arg)
 {
        struct da8xx_fb_par *par = arg;
        u32 stat = lcdc_read(LCD_STAT_REG);
@@ -606,7 +742,7 @@ static irqreturn_t lcdc_irq_handler(int irq, void *arg)
 
                /* Disable PL completion inerrupt */
                reg_ras  = lcdc_read(LCD_RASTER_CTRL_REG);
-               reg_ras &= ~LCD_PL_ENABLE;
+               reg_ras &= ~LCD_V1_PL_INT_ENA;
                lcdc_write(reg_ras, LCD_RASTER_CTRL_REG);
 
                /* Setup and start data loading mode */
@@ -877,8 +1013,8 @@ static int da8xx_pan_display(struct fb_var_screeninfo *var,
 
                        start   = fix->smem_start +
                                new_var.yoffset * fix->line_length +
-                               new_var.xoffset * var->bits_per_pixel / 8;
-                       end     = start + var->yres * fix->line_length - 1;
+                               new_var.xoffset * fbi->var.bits_per_pixel / 8;
+                       end     = start + fbi->var.yres * fix->line_length - 1;
                        par->dma_start  = start;
                        par->dma_end    = end;
                }
@@ -945,6 +1081,22 @@ static int __devinit fb_probe(struct platform_device *device)
        if (ret)
                goto err_clk_put;
 
+       /* Determine LCD IP Version */
+       switch (lcdc_read(LCD_PID_REG)) {
+       case 0x4C100102:
+               lcd_revision = LCD_VERSION_1;
+               break;
+       case 0x4F200800:
+               lcd_revision = LCD_VERSION_2;
+               break;
+       default:
+               dev_warn(&device->dev, "Unknown PID Reg value 0x%x, "
+                               "defaulting to LCD revision 1\n",
+                               lcdc_read(LCD_PID_REG));
+               lcd_revision = LCD_VERSION_1;
+               break;
+       }
+
        for (i = 0, lcdc_info = known_lcd_panels;
                i < ARRAY_SIZE(known_lcd_panels);
                i++, lcdc_info++) {
@@ -1085,7 +1237,13 @@ static int __devinit fb_probe(struct platform_device *device)
        }
 #endif
 
-       ret = request_irq(par->irq, lcdc_irq_handler, 0, DRIVER_NAME, par);
+       if (lcd_revision == LCD_VERSION_1)
+               lcdc_irq_handler = lcdc_irq_handler_rev01;
+       else
+               lcdc_irq_handler = lcdc_irq_handler_rev02;
+
+       ret = request_irq(par->irq, lcdc_irq_handler, 0,
+                       DRIVER_NAME, par);
        if (ret)
                goto irq_freq;
        return 0;
index 27f2c57e06e9f0225f8132f5a93ce7022ba81183..60a787fa32cfe97ddc8cdbb2999492e4da99144d 100644 (file)
@@ -624,8 +624,8 @@ static int unifb_pan_display(struct fb_var_screeninfo *var,
                    || var->xoffset)
                        return -EINVAL;
        } else {
-               if (var->xoffset + var->xres > info->var.xres_virtual ||
-                   var->yoffset + var->yres > info->var.yres_virtual)
+               if (var->xoffset + info->var.xres > info->var.xres_virtual ||
+                   var->yoffset + info->var.yres > info->var.yres_virtual)
                        return -EINVAL;
        }
        info->var.xoffset = var->xoffset;
index 32814e8800e034ccb073024a0959f5764ced7d86..c27e153d8882053e2d28ab72cfc784875752f337 100644 (file)
@@ -223,8 +223,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
        int i;
 
        BUG_ON(!fbdefio);
-       cancel_delayed_work(&info->deferred_work);
-       flush_scheduled_work();
+       cancel_delayed_work_sync(&info->deferred_work);
 
        /* clear out the mapping that we setup */
        for (i = 0 ; i < info->fix.smem_len; i += PAGE_SIZE) {
index 5aac00eb1830c1724ed521f2bcc91693d9dbe646..ad936295d8f439cb61d69d88d9b6ca736c2ba930 100644 (file)
@@ -1738,8 +1738,6 @@ void fb_set_suspend(struct fb_info *info, int state)
 {
        struct fb_event event;
 
-       if (!lock_fb_info(info))
-               return;
        event.info = info;
        if (state) {
                fb_notifier_call_chain(FB_EVENT_SUSPEND, &event);
@@ -1748,7 +1746,6 @@ void fb_set_suspend(struct fb_info *info, int state)
                info->state = FBINFO_STATE_RUNNING;
                fb_notifier_call_chain(FB_EVENT_RESUME, &event);
        }
-       unlock_fb_info(info);
 }
 
 /**
index 4f57485f8c54580a30519add3a26d72779d9ebcd..cef65574db6c09bd906d3ab2eac8c235f208dedf 100644 (file)
@@ -493,7 +493,8 @@ static int get_est_timing(unsigned char *block, struct fb_videomode *mode)
        return num;
 }
 
-static int get_std_timing(unsigned char *block, struct fb_videomode *mode)
+static int get_std_timing(unsigned char *block, struct fb_videomode *mode,
+               int ver, int rev)
 {
        int xres, yres = 0, refresh, ratio, i;
 
@@ -504,7 +505,11 @@ static int get_std_timing(unsigned char *block, struct fb_videomode *mode)
        ratio = (block[1] & 0xc0) >> 6;
        switch (ratio) {
        case 0:
-               yres = xres;
+               /* in EDID 1.3 the meaning of 0 changed to 16:10 (prior 1:1) */
+               if (ver < 1 || (ver == 1 && rev < 3))
+                       yres = xres;
+               else
+                       yres = (xres * 10)/16;
                break;
        case 1:
                yres = (xres * 3)/4;
@@ -533,12 +538,12 @@ static int get_std_timing(unsigned char *block, struct fb_videomode *mode)
 }
 
 static int get_dst_timing(unsigned char *block,
-                         struct fb_videomode *mode)
+                         struct fb_videomode *mode, int ver, int rev)
 {
        int j, num = 0;
 
        for (j = 0; j < 6; j++, block += STD_TIMING_DESCRIPTION_SIZE)
-               num += get_std_timing(block, &mode[num]);
+               num += get_std_timing(block, &mode[num], ver, rev);
 
        return num;
 }
@@ -599,6 +604,10 @@ static struct fb_videomode *fb_create_modedb(unsigned char *edid, int *dbsize)
        struct fb_videomode *mode, *m;
        unsigned char *block;
        int num = 0, i, first = 1;
+       int ver, rev;
+
+       ver = edid[EDID_STRUCT_VERSION];
+       rev = edid[EDID_STRUCT_REVISION];
 
        mode = kzalloc(50 * sizeof(struct fb_videomode), GFP_KERNEL);
        if (mode == NULL)
@@ -632,12 +641,12 @@ static struct fb_videomode *fb_create_modedb(unsigned char *edid, int *dbsize)
        DPRINTK("   Standard Timings\n");
        block = edid + STD_TIMING_DESCRIPTIONS_START;
        for (i = 0; i < STD_TIMING; i++, block += STD_TIMING_DESCRIPTION_SIZE)
-               num += get_std_timing(block, &mode[num]);
+               num += get_std_timing(block, &mode[num], ver, rev);
 
        block = edid + DETAILED_TIMING_DESCRIPTIONS_START;
        for (i = 0; i < 4; i++, block+= DETAILED_TIMING_DESCRIPTION_SIZE) {
                if (block[0] == 0x00 && block[1] == 0x00 && block[3] == 0xfa)
-                       num += get_dst_timing(block + 5, &mode[num]);
+                       num += get_dst_timing(block + 5, &mode[num], ver, rev);
        }
 
        /* Yikes, EDID data is totally useless */
index 04251ce89184bbfc752e2d927f48d0f534841c7b..67afa9c2289d539e281bb831aa2260c0fba1205b 100644 (file)
@@ -399,9 +399,12 @@ static ssize_t store_fbstate(struct device *device,
 
        state = simple_strtoul(buf, &last, 0);
 
+       if (!lock_fb_info(fb_info))
+               return -ENODEV;
        console_lock();
        fb_set_suspend(fb_info, (int)state);
        console_unlock();
+       unlock_fb_info(fb_info);
 
        return count;
 }
index 0acc7d65aeaade67e5ce3d1188d030d5d842d159..a16beeb5f548637698803ac22171691454f482aa 100644 (file)
 #include <linux/clk.h>
 #include <linux/uaccess.h>
 #include <linux/vmalloc.h>
-
-#include <linux/of_platform.h>
+#include <linux/spinlock.h>
 
 #include <sysdev/fsl_soc.h>
 #include <linux/fsl-diu-fb.h>
 #include "edid.h"
 
-/*
- * These parameters give default parameters
- * for video output 1024x768,
- * FIXME - change timing to proper amounts
- * hsync 31.5kHz, vsync 60Hz
- */
-static struct fb_videomode __devinitdata fsl_diu_default_mode = {
-       .refresh        = 60,
-       .xres           = 1024,
-       .yres           = 768,
-       .pixclock       = 15385,
-       .left_margin    = 160,
-       .right_margin   = 24,
-       .upper_margin   = 29,
-       .lower_margin   = 3,
-       .hsync_len      = 136,
-       .vsync_len      = 6,
-       .sync           = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
-       .vmode          = FB_VMODE_NONINTERLACED
+#define FSL_AOI_NUM    6       /* 5 AOIs and one dummy AOI */
+                               /* 1 for plane 0, 2 for plane 1&2 each */
+
+/* HW cursor parameters */
+#define MAX_CURS               32
+
+/* INT_STATUS/INT_MASK field descriptions */
+#define INT_VSYNC      0x01    /* Vsync interrupt  */
+#define INT_VSYNC_WB   0x02    /* Vsync interrupt for write back operation */
+#define INT_UNDRUN     0x04    /* Under run exception interrupt */
+#define INT_PARERR     0x08    /* Display parameters error interrupt */
+#define INT_LS_BF_VS   0x10    /* Lines before vsync. interrupt */
+
+struct diu_addr {
+       void *vaddr;            /* Virtual address */
+       dma_addr_t paddr;       /* Physical address */
+       __u32 offset;
 };
 
+/*
+ * List of supported video modes
+ *
+ * The first entry is the default video mode.  The remain entries are in
+ * order if increasing resolution and frequency.  The 320x240-60 mode is
+ * the initial AOI for the second and third planes.
+ */
 static struct fb_videomode __devinitdata fsl_diu_mode_db[] = {
        {
-               .name           = "1024x768-60",
                .refresh        = 60,
                .xres           = 1024,
                .yres           = 768,
@@ -75,7 +78,132 @@ static struct fb_videomode __devinitdata fsl_diu_mode_db[] = {
                .vmode          = FB_VMODE_NONINTERLACED
        },
        {
-               .name           = "1024x768-70",
+               .refresh        = 60,
+               .xres           = 320,
+               .yres           = 240,
+               .pixclock       = 79440,
+               .left_margin    = 16,
+               .right_margin   = 16,
+               .upper_margin   = 16,
+               .lower_margin   = 5,
+               .hsync_len      = 48,
+               .vsync_len      = 1,
+               .sync           = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
+               .vmode          = FB_VMODE_NONINTERLACED
+       },
+       {
+               .refresh        = 60,
+               .xres           = 640,
+               .yres           = 480,
+               .pixclock       = 39722,
+               .left_margin    = 48,
+               .right_margin   = 16,
+               .upper_margin   = 33,
+               .lower_margin   = 10,
+               .hsync_len      = 96,
+               .vsync_len      = 2,
+               .sync           = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
+               .vmode          = FB_VMODE_NONINTERLACED
+       },
+       {
+               .refresh        = 72,
+               .xres           = 640,
+               .yres           = 480,
+               .pixclock       = 32052,
+               .left_margin    = 128,
+               .right_margin   = 24,
+               .upper_margin   = 28,
+               .lower_margin   = 9,
+               .hsync_len      = 40,
+               .vsync_len      = 3,
+               .sync           = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
+               .vmode          = FB_VMODE_NONINTERLACED
+       },
+       {
+               .refresh        = 75,
+               .xres           = 640,
+               .yres           = 480,
+               .pixclock       = 31747,
+               .left_margin    = 120,
+               .right_margin   = 16,
+               .upper_margin   = 16,
+               .lower_margin   = 1,
+               .hsync_len      = 64,
+               .vsync_len      = 3,
+               .sync           = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
+               .vmode          = FB_VMODE_NONINTERLACED
+       },
+       {
+               .refresh        = 90,
+               .xres           = 640,
+               .yres           = 480,
+               .pixclock       = 25057,
+               .left_margin    = 120,
+               .right_margin   = 32,
+               .upper_margin   = 14,
+               .lower_margin   = 25,
+               .hsync_len      = 40,
+               .vsync_len      = 14,
+               .sync           = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
+               .vmode          = FB_VMODE_NONINTERLACED
+       },
+       {
+               .refresh        = 100,
+               .xres           = 640,
+               .yres           = 480,
+               .pixclock       = 22272,
+               .left_margin    = 48,
+               .right_margin   = 32,
+               .upper_margin   = 17,
+               .lower_margin   = 22,
+               .hsync_len      = 128,
+               .vsync_len      = 12,
+               .sync           = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
+               .vmode          = FB_VMODE_NONINTERLACED
+       },
+       {
+               .refresh        = 60,
+               .xres           = 800,
+               .yres           = 480,
+               .pixclock       = 33805,
+               .left_margin    = 96,
+               .right_margin   = 24,
+               .upper_margin   = 10,
+               .lower_margin   = 3,
+               .hsync_len      = 72,
+               .vsync_len      = 7,
+               .sync           = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
+               .vmode          = FB_VMODE_NONINTERLACED
+       },
+       {
+               .refresh        = 60,
+               .xres           = 800,
+               .yres           = 600,
+               .pixclock       = 25000,
+               .left_margin    = 88,
+               .right_margin   = 40,
+               .upper_margin   = 23,
+               .lower_margin   = 1,
+               .hsync_len      = 128,
+               .vsync_len      = 4,
+               .sync           = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
+               .vmode          = FB_VMODE_NONINTERLACED
+       },
+       {
+               .refresh        = 60,
+               .xres           = 854,
+               .yres           = 480,
+               .pixclock       = 31518,
+               .left_margin    = 104,
+               .right_margin   = 16,
+               .upper_margin   = 13,
+               .lower_margin   = 1,
+               .hsync_len      = 88,
+               .vsync_len      = 3,
+               .sync           = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
+               .vmode          = FB_VMODE_NONINTERLACED
+       },
+       {
                .refresh        = 70,
                .xres           = 1024,
                .yres           = 768,
@@ -90,7 +218,6 @@ static struct fb_videomode __devinitdata fsl_diu_mode_db[] = {
                .vmode          = FB_VMODE_NONINTERLACED
        },
        {
-               .name           = "1024x768-75",
                .refresh        = 75,
                .xres           = 1024,
                .yres           = 768,
@@ -105,7 +232,34 @@ static struct fb_videomode __devinitdata fsl_diu_mode_db[] = {
                .vmode          = FB_VMODE_NONINTERLACED
        },
        {
-               .name           = "1280x1024-60",
+               .refresh        = 60,
+               .xres           = 1280,
+               .yres           = 480,
+               .pixclock       = 18939,
+               .left_margin    = 353,
+               .right_margin   = 47,
+               .upper_margin   = 39,
+               .lower_margin   = 4,
+               .hsync_len      = 8,
+               .vsync_len      = 2,
+               .sync           = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
+               .vmode          = FB_VMODE_NONINTERLACED
+       },
+       {
+               .refresh        = 60,
+               .xres           = 1280,
+               .yres           = 720,
+               .pixclock       = 13426,
+               .left_margin    = 192,
+               .right_margin   = 64,
+               .upper_margin   = 22,
+               .lower_margin   = 1,
+               .hsync_len      = 136,
+               .vsync_len      = 3,
+               .sync           = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
+               .vmode          = FB_VMODE_NONINTERLACED
+       },
+       {
                .refresh        = 60,
                .xres           = 1280,
                .yres           = 1024,
@@ -120,7 +274,6 @@ static struct fb_videomode __devinitdata fsl_diu_mode_db[] = {
                .vmode          = FB_VMODE_NONINTERLACED
        },
        {
-               .name           = "1280x1024-70",
                .refresh        = 70,
                .xres           = 1280,
                .yres           = 1024,
@@ -135,7 +288,6 @@ static struct fb_videomode __devinitdata fsl_diu_mode_db[] = {
                .vmode          = FB_VMODE_NONINTERLACED
        },
        {
-               .name           = "1280x1024-75",
                .refresh        = 75,
                .xres           = 1280,
                .yres           = 1024,
@@ -150,40 +302,25 @@ static struct fb_videomode __devinitdata fsl_diu_mode_db[] = {
                .vmode          = FB_VMODE_NONINTERLACED
        },
        {
-               .name           = "320x240",            /* for AOI only */
                .refresh        = 60,
-               .xres           = 320,
-               .yres           = 240,
-               .pixclock       = 15385,
-               .left_margin    = 0,
-               .right_margin   = 0,
-               .upper_margin   = 0,
-               .lower_margin   = 0,
-               .hsync_len      = 0,
-               .vsync_len      = 0,
-               .sync           = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
-               .vmode          = FB_VMODE_NONINTERLACED
-       },
-       {
-               .name           = "1280x480-60",
-               .refresh        = 60,
-               .xres           = 1280,
-               .yres           = 480,
-               .pixclock       = 18939,
-               .left_margin    = 353,
-               .right_margin   = 47,
-               .upper_margin   = 39,
-               .lower_margin   = 4,
-               .hsync_len      = 8,
-               .vsync_len      = 2,
+               .xres           = 1920,
+               .yres           = 1080,
+               .pixclock       = 5787,
+               .left_margin    = 328,
+               .right_margin   = 120,
+               .upper_margin   = 34,
+               .lower_margin   = 1,
+               .hsync_len      = 208,
+               .vsync_len      = 3,
                .sync           = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
                .vmode          = FB_VMODE_NONINTERLACED
        },
 };
 
-static char *fb_mode = "1024x768-32@60";
+static char *fb_mode;
 static unsigned long default_bpp = 32;
-static int monitor_port;
+static enum fsl_diu_monitor_port monitor_port;
+static char *monitor_string;
 
 #if defined(CONFIG_NOT_COHERENT_CACHE)
 static u8 *coherence_data;
@@ -201,15 +338,27 @@ struct fsl_diu_data {
        void *dummy_aoi_virt;
        unsigned int irq;
        int fb_enabled;
-       int monitor_port;
+       enum fsl_diu_monitor_port monitor_port;
+       struct diu __iomem *diu_reg;
+       spinlock_t reg_lock;
+       struct diu_addr ad;
+       struct diu_addr gamma;
+       struct diu_addr pallete;
+       struct diu_addr cursor;
+};
+
+enum mfb_index {
+       PLANE0 = 0,     /* Plane 0, only one AOI that fills the screen */
+       PLANE1_AOI0,    /* Plane 1, first AOI */
+       PLANE1_AOI1,    /* Plane 1, second AOI */
+       PLANE2_AOI0,    /* Plane 2, first AOI */
+       PLANE2_AOI1,    /* Plane 2, second AOI */
 };
 
 struct mfb_info {
-       int index;
-       int type;
+       enum mfb_index index;
        char *id;
        int registered;
-       int blank;
        unsigned long pseudo_palette[16];
        struct diu_ad *ad;
        int cursor_reset;
@@ -223,63 +372,82 @@ struct mfb_info {
 
 
 static struct mfb_info mfb_template[] = {
-       {               /* AOI 0 for plane 0 */
-       .index = 0,
-       .type = MFB_TYPE_OUTPUT,
-       .id = "Panel0",
-       .registered = 0,
-       .count = 0,
-       .x_aoi_d = 0,
-       .y_aoi_d = 0,
+       {
+               .index = PLANE0,
+               .id = "Panel0",
+               .registered = 0,
+               .count = 0,
+               .x_aoi_d = 0,
+               .y_aoi_d = 0,
        },
-       {               /* AOI 0 for plane 1 */
-       .index = 1,
-       .type = MFB_TYPE_OUTPUT,
-       .id = "Panel1 AOI0",
-       .registered = 0,
-       .g_alpha = 0xff,
-       .count = 0,
-       .x_aoi_d = 0,
-       .y_aoi_d = 0,
+       {
+               .index = PLANE1_AOI0,
+               .id = "Panel1 AOI0",
+               .registered = 0,
+               .g_alpha = 0xff,
+               .count = 0,
+               .x_aoi_d = 0,
+               .y_aoi_d = 0,
        },
-       {               /* AOI 1 for plane 1 */
-       .index = 2,
-       .type = MFB_TYPE_OUTPUT,
-       .id = "Panel1 AOI1",
-       .registered = 0,
-       .g_alpha = 0xff,
-       .count = 0,
-       .x_aoi_d = 0,
-       .y_aoi_d = 480,
+       {
+               .index = PLANE1_AOI1,
+               .id = "Panel1 AOI1",
+               .registered = 0,
+               .g_alpha = 0xff,
+               .count = 0,
+               .x_aoi_d = 0,
+               .y_aoi_d = 480,
        },
-       {               /* AOI 0 for plane 2 */
-       .index = 3,
-       .type = MFB_TYPE_OUTPUT,
-       .id = "Panel2 AOI0",
-       .registered = 0,
-       .g_alpha = 0xff,
-       .count = 0,
-       .x_aoi_d = 640,
-       .y_aoi_d = 0,
+       {
+               .index = PLANE2_AOI0,
+               .id = "Panel2 AOI0",
+               .registered = 0,
+               .g_alpha = 0xff,
+               .count = 0,
+               .x_aoi_d = 640,
+               .y_aoi_d = 0,
        },
-       {               /* AOI 1 for plane 2 */
-       .index = 4,
-       .type = MFB_TYPE_OUTPUT,
-       .id = "Panel2 AOI1",
-       .registered = 0,
-       .g_alpha = 0xff,
-       .count = 0,
-       .x_aoi_d = 640,
-       .y_aoi_d = 480,
+       {
+               .index = PLANE2_AOI1,
+               .id = "Panel2 AOI1",
+               .registered = 0,
+               .g_alpha = 0xff,
+               .count = 0,
+               .x_aoi_d = 640,
+               .y_aoi_d = 480,
        },
 };
 
-static struct diu_hw dr = {
-       .mode = MFB_MODE1,
-       .reg_lock = __SPIN_LOCK_UNLOCKED(diu_hw.reg_lock),
-};
+/**
+ * fsl_diu_name_to_port - convert a port name to a monitor port enum
+ *
+ * Takes the name of a monitor port ("dvi", "lvds", or "dlvds") and returns
+ * the enum fsl_diu_monitor_port that corresponds to that string.
+ *
+ * For compatibility with older versions, a number ("0", "1", or "2") is also
+ * supported.
+ *
+ * If the string is unknown, DVI is assumed.
+ *
+ * If the particular port is not supported by the platform, another port
+ * (platform-specific) is chosen instead.
+ */
+static enum fsl_diu_monitor_port fsl_diu_name_to_port(const char *s)
+{
+       enum fsl_diu_monitor_port port = FSL_DIU_PORT_DVI;
+       unsigned long val;
 
-static struct diu_pool pool;
+       if (s) {
+               if (!strict_strtoul(s, 10, &val) && (val <= 2))
+                       port = (enum fsl_diu_monitor_port) val;
+               else if (strncmp(s, "lvds", 4) == 0)
+                       port = FSL_DIU_PORT_LVDS;
+               else if (strncmp(s, "dlvds", 5) == 0)
+                       port = FSL_DIU_PORT_DLVDS;
+       }
+
+       return diu_ops.valid_monitor_port(port);
+}
 
 /**
  * fsl_diu_alloc - allocate memory for the DIU
@@ -292,14 +460,9 @@ static void *fsl_diu_alloc(size_t size, phys_addr_t *phys)
 {
        void *virt;
 
-       pr_debug("size=%zu\n", size);
-
        virt = alloc_pages_exact(size, GFP_DMA | __GFP_ZERO);
-       if (virt) {
+       if (virt)
                *phys = virt_to_phys(virt);
-               pr_debug("virt=%p phys=%llx\n", virt,
-                       (unsigned long long)*phys);
-       }
 
        return virt;
 }
@@ -313,8 +476,6 @@ static void *fsl_diu_alloc(size_t size, phys_addr_t *phys)
  */
 static void fsl_diu_free(void *virt, size_t size)
 {
-       pr_debug("virt=%p size=%zu\n", virt, size);
-
        if (virt && size)
                free_pages_exact(virt, size);
 }
@@ -330,82 +491,72 @@ void wr_reg_wa(u32 *reg, u32 val)
        } while (in_be32(reg) != val);
 }
 
-static int fsl_diu_enable_panel(struct fb_info *info)
+static void fsl_diu_enable_panel(struct fb_info *info)
 {
        struct mfb_info *pmfbi, *cmfbi, *mfbi = info->par;
-       struct diu *hw = dr.diu_reg;
        struct diu_ad *ad = mfbi->ad;
        struct fsl_diu_data *machine_data = mfbi->parent;
-       int res = 0;
+       struct diu __iomem *hw = machine_data->diu_reg;
 
-       pr_debug("enable_panel index %d\n", mfbi->index);
-       if (mfbi->type != MFB_TYPE_OFF) {
-               switch (mfbi->index) {
-               case 0:                         /* plane 0 */
-                       if (hw->desc[0] != ad->paddr)
-                               wr_reg_wa(&hw->desc[0], ad->paddr);
-                       break;
-               case 1:                         /* plane 1 AOI 0 */
-                       cmfbi = machine_data->fsl_diu_info[2]->par;
-                       if (hw->desc[1] != ad->paddr) { /* AOI0 closed */
-                               if (cmfbi->count > 0)   /* AOI1 open */
-                                       ad->next_ad =
-                                               cpu_to_le32(cmfbi->ad->paddr);
-                               else
-                                       ad->next_ad = 0;
-                               wr_reg_wa(&hw->desc[1], ad->paddr);
-                       }
-                       break;
-               case 3:                         /* plane 2 AOI 0 */
-                       cmfbi = machine_data->fsl_diu_info[4]->par;
-                       if (hw->desc[2] != ad->paddr) { /* AOI0 closed */
-                               if (cmfbi->count > 0)   /* AOI1 open */
-                                       ad->next_ad =
-                                               cpu_to_le32(cmfbi->ad->paddr);
-                               else
-                                       ad->next_ad = 0;
-                               wr_reg_wa(&hw->desc[2], ad->paddr);
-                       }
-                       break;
-               case 2:                         /* plane 1 AOI 1 */
-                       pmfbi = machine_data->fsl_diu_info[1]->par;
-                       ad->next_ad = 0;
-                       if (hw->desc[1] == machine_data->dummy_ad->paddr)
-                               wr_reg_wa(&hw->desc[1], ad->paddr);
-                       else                                    /* AOI0 open */
-                               pmfbi->ad->next_ad = cpu_to_le32(ad->paddr);
-                       break;
-               case 4:                         /* plane 2 AOI 1 */
-                       pmfbi = machine_data->fsl_diu_info[3]->par;
-                       ad->next_ad = 0;
-                       if (hw->desc[2] == machine_data->dummy_ad->paddr)
-                               wr_reg_wa(&hw->desc[2], ad->paddr);
-                       else                            /* AOI0 was open */
-                               pmfbi->ad->next_ad = cpu_to_le32(ad->paddr);
-                       break;
-               default:
-                       res = -EINVAL;
-                       break;
+       switch (mfbi->index) {
+       case PLANE0:
+               if (hw->desc[0] != ad->paddr)
+                       wr_reg_wa(&hw->desc[0], ad->paddr);
+               break;
+       case PLANE1_AOI0:
+               cmfbi = machine_data->fsl_diu_info[2]->par;
+               if (hw->desc[1] != ad->paddr) { /* AOI0 closed */
+                       if (cmfbi->count > 0)   /* AOI1 open */
+                               ad->next_ad =
+                                       cpu_to_le32(cmfbi->ad->paddr);
+                       else
+                               ad->next_ad = 0;
+                       wr_reg_wa(&hw->desc[1], ad->paddr);
                }
-       } else
-               res = -EINVAL;
-       return res;
+               break;
+       case PLANE2_AOI0:
+               cmfbi = machine_data->fsl_diu_info[4]->par;
+               if (hw->desc[2] != ad->paddr) { /* AOI0 closed */
+                       if (cmfbi->count > 0)   /* AOI1 open */
+                               ad->next_ad =
+                                       cpu_to_le32(cmfbi->ad->paddr);
+                       else
+                               ad->next_ad = 0;
+                       wr_reg_wa(&hw->desc[2], ad->paddr);
+               }
+               break;
+       case PLANE1_AOI1:
+               pmfbi = machine_data->fsl_diu_info[1]->par;
+               ad->next_ad = 0;
+               if (hw->desc[1] == machine_data->dummy_ad->paddr)
+                       wr_reg_wa(&hw->desc[1], ad->paddr);
+               else                                    /* AOI0 open */
+                       pmfbi->ad->next_ad = cpu_to_le32(ad->paddr);
+               break;
+       case PLANE2_AOI1:
+               pmfbi = machine_data->fsl_diu_info[3]->par;
+               ad->next_ad = 0;
+               if (hw->desc[2] == machine_data->dummy_ad->paddr)
+                       wr_reg_wa(&hw->desc[2], ad->paddr);
+               else                            /* AOI0 was open */
+                       pmfbi->ad->next_ad = cpu_to_le32(ad->paddr);
+               break;
+       }
 }
 
-static int fsl_diu_disable_panel(struct fb_info *info)
+static void fsl_diu_disable_panel(struct fb_info *info)
 {
        struct mfb_info *pmfbi, *cmfbi, *mfbi = info->par;
-       struct diu *hw = dr.diu_reg;
        struct diu_ad *ad = mfbi->ad;
        struct fsl_diu_data *machine_data = mfbi->parent;
-       int res = 0;
+       struct diu __iomem *hw = machine_data->diu_reg;
 
        switch (mfbi->index) {
-       case 0:                                 /* plane 0 */
+       case PLANE0:
                if (hw->desc[0] != machine_data->dummy_ad->paddr)
                        wr_reg_wa(&hw->desc[0], machine_data->dummy_ad->paddr);
                break;
-       case 1:                                 /* plane 1 AOI 0 */
+       case PLANE1_AOI0:
                cmfbi = machine_data->fsl_diu_info[2]->par;
                if (cmfbi->count > 0)   /* AOI1 is open */
                        wr_reg_wa(&hw->desc[1], cmfbi->ad->paddr);
@@ -414,7 +565,7 @@ static int fsl_diu_disable_panel(struct fb_info *info)
                        wr_reg_wa(&hw->desc[1], machine_data->dummy_ad->paddr);
                                        /* close AOI 0 */
                break;
-       case 3:                                 /* plane 2 AOI 0 */
+       case PLANE2_AOI0:
                cmfbi = machine_data->fsl_diu_info[4]->par;
                if (cmfbi->count > 0)   /* AOI1 is open */
                        wr_reg_wa(&hw->desc[2], cmfbi->ad->paddr);
@@ -423,7 +574,7 @@ static int fsl_diu_disable_panel(struct fb_info *info)
                        wr_reg_wa(&hw->desc[2], machine_data->dummy_ad->paddr);
                                        /* close AOI 0 */
                break;
-       case 2:                                 /* plane 1 AOI 1 */
+       case PLANE1_AOI1:
                pmfbi = machine_data->fsl_diu_info[1]->par;
                if (hw->desc[1] != ad->paddr) {
                                /* AOI1 is not the first in the chain */
@@ -434,7 +585,7 @@ static int fsl_diu_disable_panel(struct fb_info *info)
                        wr_reg_wa(&hw->desc[1], machine_data->dummy_ad->paddr);
                                        /* close AOI 1 */
                break;
-       case 4:                                 /* plane 2 AOI 1 */
+       case PLANE2_AOI1:
                pmfbi = machine_data->fsl_diu_info[3]->par;
                if (hw->desc[2] != ad->paddr) {
                                /* AOI1 is not the first in the chain */
@@ -445,31 +596,26 @@ static int fsl_diu_disable_panel(struct fb_info *info)
                        wr_reg_wa(&hw->desc[2], machine_data->dummy_ad->paddr);
                                /* close AOI 1 */
                break;
-       default:
-               res = -EINVAL;
-               break;
        }
-
-       return res;
 }
 
 static void enable_lcdc(struct fb_info *info)
 {
-       struct diu *hw = dr.diu_reg;
        struct mfb_info *mfbi = info->par;
        struct fsl_diu_data *machine_data = mfbi->parent;
+       struct diu __iomem *hw = machine_data->diu_reg;
 
        if (!machine_data->fb_enabled) {
-               out_be32(&hw->diu_mode, dr.mode);
+               out_be32(&hw->diu_mode, MFB_MODE1);
                machine_data->fb_enabled++;
        }
 }
 
 static void disable_lcdc(struct fb_info *info)
 {
-       struct diu *hw = dr.diu_reg;
        struct mfb_info *mfbi = info->par;
        struct fsl_diu_data *machine_data = mfbi->parent;
+       struct diu __iomem *hw = machine_data->diu_reg;
 
        if (machine_data->fb_enabled) {
                out_be32(&hw->diu_mode, 0);
@@ -482,7 +628,8 @@ static void adjust_aoi_size_position(struct fb_var_screeninfo *var,
 {
        struct mfb_info *lower_aoi_mfbi, *upper_aoi_mfbi, *mfbi = info->par;
        struct fsl_diu_data *machine_data = mfbi->parent;
-       int available_height, upper_aoi_bottom, index = mfbi->index;
+       int available_height, upper_aoi_bottom;
+       enum mfb_index index = mfbi->index;
        int lower_aoi_is_open, upper_aoi_is_open;
        __u32 base_plane_width, base_plane_height, upper_aoi_height;
 
@@ -494,14 +641,14 @@ static void adjust_aoi_size_position(struct fb_var_screeninfo *var,
        if (mfbi->y_aoi_d < 0)
                mfbi->y_aoi_d = 0;
        switch (index) {
-       case 0:
+       case PLANE0:
                if (mfbi->x_aoi_d != 0)
                        mfbi->x_aoi_d = 0;
                if (mfbi->y_aoi_d != 0)
                        mfbi->y_aoi_d = 0;
                break;
-       case 1:                 /* AOI 0 */
-       case 3:
+       case PLANE1_AOI0:
+       case PLANE2_AOI0:
                lower_aoi_mfbi = machine_data->fsl_diu_info[index+1]->par;
                lower_aoi_is_open = lower_aoi_mfbi->count > 0 ? 1 : 0;
                if (var->xres > base_plane_width)
@@ -518,8 +665,8 @@ static void adjust_aoi_size_position(struct fb_var_screeninfo *var,
                if ((mfbi->y_aoi_d + var->yres) > available_height)
                        mfbi->y_aoi_d = available_height - var->yres;
                break;
-       case 2:                 /* AOI 1 */
-       case 4:
+       case PLANE1_AOI1:
+       case PLANE2_AOI1:
                upper_aoi_mfbi = machine_data->fsl_diu_info[index-1]->par;
                upper_aoi_height =
                                machine_data->fsl_diu_info[index-1]->var.yres;
@@ -555,9 +702,6 @@ static void adjust_aoi_size_position(struct fb_var_screeninfo *var,
 static int fsl_diu_check_var(struct fb_var_screeninfo *var,
                                struct fb_info *info)
 {
-       pr_debug("check_var xres: %d\n", var->xres);
-       pr_debug("check_var yres: %d\n", var->yres);
-
        if (var->xres_virtual < var->xres)
                var->xres_virtual = var->xres;
        if (var->yres_virtual < var->yres)
@@ -652,7 +796,7 @@ static void set_fix(struct fb_info *info)
        struct fb_var_screeninfo *var = &info->var;
        struct mfb_info *mfbi = info->par;
 
-       strncpy(fix->id, mfbi->id, strlen(mfbi->id));
+       strncpy(fix->id, mfbi->id, sizeof(fix->id));
        fix->line_length = var->xres_virtual * var->bits_per_pixel / 8;
        fix->type = FB_TYPE_PACKED_PIXELS;
        fix->accel = FB_ACCEL_NONE;
@@ -666,45 +810,37 @@ static void update_lcdc(struct fb_info *info)
        struct fb_var_screeninfo *var = &info->var;
        struct mfb_info *mfbi = info->par;
        struct fsl_diu_data *machine_data = mfbi->parent;
-       struct diu *hw;
+       struct diu __iomem *hw;
        int i, j;
        char __iomem *cursor_base, *gamma_table_base;
 
        u32 temp;
 
-       hw = dr.diu_reg;
-
-       if (mfbi->type == MFB_TYPE_OFF) {
-               fsl_diu_disable_panel(info);
-               return;
-       }
+       hw = machine_data->diu_reg;
 
        diu_ops.set_monitor_port(machine_data->monitor_port);
-       gamma_table_base = pool.gamma.vaddr;
-       cursor_base = pool.cursor.vaddr;
+       gamma_table_base = machine_data->gamma.vaddr;
+       cursor_base = machine_data->cursor.vaddr;
        /* Prep for DIU init  - gamma table, cursor table */
 
        for (i = 0; i <= 2; i++)
-          for (j = 0; j <= 255; j++)
-             *gamma_table_base++ = j;
+               for (j = 0; j <= 255; j++)
+                       *gamma_table_base++ = j;
 
-       diu_ops.set_gamma_table(machine_data->monitor_port, pool.gamma.vaddr);
+       diu_ops.set_gamma_table(machine_data->monitor_port,
+                               machine_data->gamma.vaddr);
 
-       pr_debug("update-lcdc: HW - %p\n Disabling DIU\n", hw);
        disable_lcdc(info);
 
        /* Program DIU registers */
 
-       out_be32(&hw->gamma, pool.gamma.paddr);
-       out_be32(&hw->cursor, pool.cursor.paddr);
+       out_be32(&hw->gamma, machine_data->gamma.paddr);
+       out_be32(&hw->cursor, machine_data->cursor.paddr);
 
        out_be32(&hw->bgnd, 0x007F7F7F);        /* BGND */
        out_be32(&hw->bgnd_wb, 0);              /* BGND_WB */
        out_be32(&hw->disp_size, (var->yres << 16 | var->xres));
                                                /* DISP SIZE */
-       pr_debug("DIU xres: %d\n", var->xres);
-       pr_debug("DIU yres: %d\n", var->yres);
-
        out_be32(&hw->wb_size, 0); /* WB SIZE */
        out_be32(&hw->wb_mem_addr, 0); /* WB MEM ADDR */
 
@@ -721,15 +857,6 @@ static void update_lcdc(struct fb_info *info)
 
        out_be32(&hw->vsyn_para, temp);
 
-       pr_debug("DIU right_margin - %d\n", var->right_margin);
-       pr_debug("DIU left_margin - %d\n", var->left_margin);
-       pr_debug("DIU hsync_len - %d\n", var->hsync_len);
-       pr_debug("DIU upper_margin - %d\n", var->upper_margin);
-       pr_debug("DIU lower_margin - %d\n", var->lower_margin);
-       pr_debug("DIU vsync_len - %d\n", var->vsync_len);
-       pr_debug("DIU HSYNC - 0x%08x\n", hw->hsyn_para);
-       pr_debug("DIU VSYNC - 0x%08x\n", hw->vsyn_para);
-
        diu_ops.set_pixel_clock(var->pixclock);
 
        out_be32(&hw->syn_pol, 0);      /* SYNC SIGNALS POLARITY */
@@ -746,14 +873,9 @@ static int map_video_memory(struct fb_info *info)
        phys_addr_t phys;
        u32 smem_len = info->fix.line_length * info->var.yres_virtual;
 
-       pr_debug("info->var.xres_virtual = %d\n", info->var.xres_virtual);
-       pr_debug("info->var.yres_virtual = %d\n", info->var.yres_virtual);
-       pr_debug("info->fix.line_length  = %d\n", info->fix.line_length);
-       pr_debug("MAP_VIDEO_MEMORY: smem_len = %u\n", smem_len);
-
        info->screen_base = fsl_diu_alloc(smem_len, &phys);
        if (info->screen_base == NULL) {
-               printk(KERN_ERR "Unable to allocate fb memory\n");
+               dev_err(info->dev, "unable to allocate fb memory\n");
                return -ENOMEM;
        }
        mutex_lock(&info->mm_lock);
@@ -762,10 +884,6 @@ static int map_video_memory(struct fb_info *info)
        mutex_unlock(&info->mm_lock);
        info->screen_size = info->fix.smem_len;
 
-       pr_debug("Allocated fb @ paddr=0x%08lx, size=%d.\n",
-                info->fix.smem_start, info->fix.smem_len);
-       pr_debug("screen base %p\n", info->screen_base);
-
        return 0;
 }
 
@@ -810,9 +928,9 @@ static int fsl_diu_set_par(struct fb_info *info)
        struct mfb_info *mfbi = info->par;
        struct fsl_diu_data *machine_data = mfbi->parent;
        struct diu_ad *ad = mfbi->ad;
-       struct diu *hw;
+       struct diu __iomem *hw;
 
-       hw = dr.diu_reg;
+       hw = machine_data->diu_reg;
 
        set_fix(info);
        mfbi->cursor_reset = 1;
@@ -822,18 +940,16 @@ static int fsl_diu_set_par(struct fb_info *info)
        if (len != info->fix.smem_len) {
                if (info->fix.smem_start)
                        unmap_video_memory(info);
-               pr_debug("SET PAR: smem_len = %d\n", info->fix.smem_len);
 
                /* Memory allocation for framebuffer */
                if (map_video_memory(info)) {
-                       printk(KERN_ERR "Unable to allocate fb memory 1\n");
+                       dev_err(info->dev, "unable to allocate fb memory 1\n");
                        return -ENOMEM;
                }
        }
 
-       ad->pix_fmt =
-               diu_ops.get_pixel_format(var->bits_per_pixel,
-                                        machine_data->monitor_port);
+       ad->pix_fmt = diu_ops.get_pixel_format(machine_data->monitor_port,
+                                              var->bits_per_pixel);
        ad->addr    = cpu_to_le32(info->fix.smem_start);
        ad->src_size_g_alpha = cpu_to_le32((var->yres_virtual << 12) |
                                var->xres_virtual) | mfbi->g_alpha;
@@ -851,14 +967,14 @@ static int fsl_diu_set_par(struct fb_info *info)
        ad->ckmin_g = 255;
        ad->ckmin_b = 255;
 
-       if (mfbi->index == 0)
+       if (mfbi->index == PLANE0)
                update_lcdc(info);
        return 0;
 }
 
 static inline __u32 CNVT_TOHW(__u32 val, __u32 width)
 {
-       return ((val<<width) + 0x7FFF - val)>>16;
+       return ((val << width) + 0x7FFF - val) >> 16;
 }
 
 /*
@@ -870,8 +986,9 @@ static inline __u32 CNVT_TOHW(__u32 val, __u32 width)
  * pseudo_palette in struct fb_info. For pseudocolor mode we have a limited
  * color palette.
  */
-static int fsl_diu_setcolreg(unsigned regno, unsigned red, unsigned green,
-                          unsigned blue, unsigned transp, struct fb_info *info)
+static int fsl_diu_setcolreg(unsigned int regno, unsigned int red,
+                            unsigned int green, unsigned int blue,
+                            unsigned int transp, struct fb_info *info)
 {
        int ret = 1;
 
@@ -906,9 +1023,6 @@ static int fsl_diu_setcolreg(unsigned regno, unsigned red, unsigned green,
                        ret = 0;
                }
                break;
-       case FB_VISUAL_STATIC_PSEUDOCOLOR:
-       case FB_VISUAL_PSEUDOCOLOR:
-               break;
        }
 
        return ret;
@@ -944,37 +1058,6 @@ static int fsl_diu_pan_display(struct fb_var_screeninfo *var,
        return 0;
 }
 
-/*
- * Blank the screen if blank_mode != 0, else unblank. Return 0 if blanking
- * succeeded, != 0 if un-/blanking failed.
- * blank_mode == 2: suspend vsync
- * blank_mode == 3: suspend hsync
- * blank_mode == 4: powerdown
- */
-static int fsl_diu_blank(int blank_mode, struct fb_info *info)
-{
-       struct mfb_info *mfbi = info->par;
-
-       mfbi->blank = blank_mode;
-
-       switch (blank_mode) {
-       case FB_BLANK_VSYNC_SUSPEND:
-       case FB_BLANK_HSYNC_SUSPEND:
-       /* FIXME: fixes to enable_panel and enable lcdc needed */
-       case FB_BLANK_NORMAL:
-       /*      fsl_diu_disable_panel(info);*/
-               break;
-       case FB_BLANK_POWERDOWN:
-       /*      disable_lcdc(info);     */
-               break;
-       case FB_BLANK_UNBLANK:
-       /*      fsl_diu_enable_panel(info);*/
-               break;
-       }
-
-       return 0;
-}
-
 static int fsl_diu_ioctl(struct fb_info *info, unsigned int cmd,
                       unsigned long arg)
 {
@@ -989,25 +1072,29 @@ static int fsl_diu_ioctl(struct fb_info *info, unsigned int cmd,
        if (!arg)
                return -EINVAL;
        switch (cmd) {
+       case MFB_SET_PIXFMT_OLD:
+               dev_warn(info->dev,
+                        "MFB_SET_PIXFMT value of 0x%08x is deprecated.\n",
+                        MFB_SET_PIXFMT_OLD);
        case MFB_SET_PIXFMT:
                if (copy_from_user(&pix_fmt, buf, sizeof(pix_fmt)))
                        return -EFAULT;
                ad->pix_fmt = pix_fmt;
-               pr_debug("Set pixel format to 0x%08x\n", ad->pix_fmt);
                break;
+       case MFB_GET_PIXFMT_OLD:
+               dev_warn(info->dev,
+                        "MFB_GET_PIXFMT value of 0x%08x is deprecated.\n",
+                        MFB_GET_PIXFMT_OLD);
        case MFB_GET_PIXFMT:
                pix_fmt = ad->pix_fmt;
                if (copy_to_user(buf, &pix_fmt, sizeof(pix_fmt)))
                        return -EFAULT;
-               pr_debug("get pixel format 0x%08x\n", ad->pix_fmt);
                break;
        case MFB_SET_AOID:
                if (copy_from_user(&aoi_d, buf, sizeof(aoi_d)))
                        return -EFAULT;
                mfbi->x_aoi_d = aoi_d.x_aoi_d;
                mfbi->y_aoi_d = aoi_d.y_aoi_d;
-               pr_debug("set AOI display offset of index %d to (%d,%d)\n",
-                                mfbi->index, aoi_d.x_aoi_d, aoi_d.y_aoi_d);
                fsl_diu_check_var(&info->var, info);
                fsl_diu_set_aoi(info);
                break;
@@ -1016,14 +1103,11 @@ static int fsl_diu_ioctl(struct fb_info *info, unsigned int cmd,
                aoi_d.y_aoi_d = mfbi->y_aoi_d;
                if (copy_to_user(buf, &aoi_d, sizeof(aoi_d)))
                        return -EFAULT;
-               pr_debug("get AOI display offset of index %d (%d,%d)\n",
-                               mfbi->index, aoi_d.x_aoi_d, aoi_d.y_aoi_d);
                break;
        case MFB_GET_ALPHA:
                global_alpha = mfbi->g_alpha;
                if (copy_to_user(buf, &global_alpha, sizeof(global_alpha)))
                        return -EFAULT;
-               pr_debug("get global alpha of index %d\n", mfbi->index);
                break;
        case MFB_SET_ALPHA:
                /* set panel information */
@@ -1032,7 +1116,6 @@ static int fsl_diu_ioctl(struct fb_info *info, unsigned int cmd,
                ad->src_size_g_alpha = (ad->src_size_g_alpha & (~0xff)) |
                                                        (global_alpha & 0xff);
                mfbi->g_alpha = global_alpha;
-               pr_debug("set global alpha for index %d\n", mfbi->index);
                break;
        case MFB_SET_CHROMA_KEY:
                /* set panel winformation */
@@ -1060,27 +1143,9 @@ static int fsl_diu_ioctl(struct fb_info *info, unsigned int cmd,
                        ad->ckmin_g = ck.green_min;
                        ad->ckmin_b = ck.blue_min;
                }
-               pr_debug("set chroma key\n");
                break;
-       case FBIOGET_GWINFO:
-               if (mfbi->type == MFB_TYPE_OFF)
-                       return -ENODEV;
-               /* get graphic window information */
-               if (copy_to_user(buf, ad, sizeof(*ad)))
-                       return -EFAULT;
-               break;
-       case FBIOGET_HWCINFO:
-               pr_debug("FBIOGET_HWCINFO:0x%08x\n", FBIOGET_HWCINFO);
-               break;
-       case FBIOPUT_MODEINFO:
-               pr_debug("FBIOPUT_MODEINFO:0x%08x\n", FBIOPUT_MODEINFO);
-               break;
-       case FBIOGET_DISPINFO:
-               pr_debug("FBIOGET_DISPINFO:0x%08x\n", FBIOGET_DISPINFO);
-               break;
-
        default:
-               printk(KERN_ERR "Unknown ioctl command (0x%08X)\n", cmd);
+               dev_err(info->dev, "unknown ioctl command (0x%08X)\n", cmd);
                return -ENOIOCTLCMD;
        }
 
@@ -1095,22 +1160,18 @@ static int fsl_diu_open(struct fb_info *info, int user)
        int res = 0;
 
        /* free boot splash memory on first /dev/fb0 open */
-       if (!mfbi->index && diu_ops.release_bootmem)
+       if ((mfbi->index == PLANE0) && diu_ops.release_bootmem)
                diu_ops.release_bootmem();
 
        spin_lock(&diu_lock);
        mfbi->count++;
        if (mfbi->count == 1) {
-               pr_debug("open plane index %d\n", mfbi->index);
                fsl_diu_check_var(&info->var, info);
                res = fsl_diu_set_par(info);
                if (res < 0)
                        mfbi->count--;
-               else {
-                       res = fsl_diu_enable_panel(info);
-                       if (res < 0)
-                               mfbi->count--;
-               }
+               else
+                       fsl_diu_enable_panel(info);
        }
 
        spin_unlock(&diu_lock);
@@ -1126,12 +1187,9 @@ static int fsl_diu_release(struct fb_info *info, int user)
 
        spin_lock(&diu_lock);
        mfbi->count--;
-       if (mfbi->count == 0) {
-               pr_debug("release plane index %d\n", mfbi->index);
-               res = fsl_diu_disable_panel(info);
-               if (res < 0)
-                       mfbi->count++;
-       }
+       if (mfbi->count == 0)
+               fsl_diu_disable_panel(info);
+
        spin_unlock(&diu_lock);
        return res;
 }
@@ -1141,7 +1199,6 @@ static struct fb_ops fsl_diu_ops = {
        .fb_check_var = fsl_diu_check_var,
        .fb_set_par = fsl_diu_set_par,
        .fb_setcolreg = fsl_diu_setcolreg,
-       .fb_blank = fsl_diu_blank,
        .fb_pan_display = fsl_diu_pan_display,
        .fb_fillrect = cfb_fillrect,
        .fb_copyarea = cfb_copyarea,
@@ -1178,7 +1235,7 @@ static int __devinit install_fb(struct fb_info *info)
        if (init_fbinfo(info))
                return -EINVAL;
 
-       if (mfbi->index == 0) { /* plane 0 */
+       if (mfbi->index == PLANE0) {
                if (mfbi->edid_data) {
                        /* Now build modedb from EDID */
                        fb_edid_to_monspecs(mfbi->edid_data, &info->monspecs);
@@ -1192,43 +1249,23 @@ static int __devinit install_fb(struct fb_info *info)
        } else {
                aoi_mode = init_aoi_mode;
        }
-       pr_debug("mode used = %s\n", aoi_mode);
-       rc = fb_find_mode(&info->var, info, aoi_mode, db, dbsize,
-                         &fsl_diu_default_mode, default_bpp);
-       switch (rc) {
-       case 1:
-               pr_debug("using mode specified in @mode\n");
-               break;
-       case 2:
-               pr_debug("using mode specified in @mode "
-                       "with ignored refresh rate\n");
-               break;
-       case 3:
-               pr_debug("using mode default mode\n");
-               break;
-       case 4:
-               pr_debug("using mode from list\n");
-               break;
-       default:
-               pr_debug("rc = %d\n", rc);
-               pr_debug("failed to find mode\n");
+       rc = fb_find_mode(&info->var, info, aoi_mode, db, dbsize, NULL,
+                         default_bpp);
+       if (!rc) {
                /*
                 * For plane 0 we continue and look into
                 * driver's internal modedb.
                 */
-               if (mfbi->index == 0 && mfbi->edid_data)
+               if ((mfbi->index == PLANE0) && mfbi->edid_data)
                        has_default_mode = 0;
                else
                        return -EINVAL;
-               break;
        }
 
        if (!has_default_mode) {
                rc = fb_find_mode(&info->var, info, aoi_mode, fsl_diu_mode_db,
-                                 ARRAY_SIZE(fsl_diu_mode_db),
-                                 &fsl_diu_default_mode,
-                                 default_bpp);
-               if (rc > 0 && rc < 5)
+                       ARRAY_SIZE(fsl_diu_mode_db), NULL, default_bpp);
+               if (rc)
                        has_default_mode = 1;
        }
 
@@ -1256,33 +1293,22 @@ static int __devinit install_fb(struct fb_info *info)
                fb_videomode_to_var(&info->var, modedb);
        }
 
-       pr_debug("xres_virtual %d\n", info->var.xres_virtual);
-       pr_debug("bits_per_pixel %d\n", info->var.bits_per_pixel);
-
-       pr_debug("info->var.yres_virtual = %d\n", info->var.yres_virtual);
-       pr_debug("info->fix.line_length = %d\n", info->fix.line_length);
-
-       if (mfbi->type == MFB_TYPE_OFF)
-               mfbi->blank = FB_BLANK_NORMAL;
-       else
-               mfbi->blank = FB_BLANK_UNBLANK;
-
        if (fsl_diu_check_var(&info->var, info)) {
-               printk(KERN_ERR "fb_check_var failed");
+               dev_err(info->dev, "fsl_diu_check_var failed\n");
+               unmap_video_memory(info);
                fb_dealloc_cmap(&info->cmap);
                return -EINVAL;
        }
 
        if (register_framebuffer(info) < 0) {
-               printk(KERN_ERR "register_framebuffer failed");
+               dev_err(info->dev, "register_framebuffer failed\n");
                unmap_video_memory(info);
                fb_dealloc_cmap(&info->cmap);
                return -EINVAL;
        }
 
        mfbi->registered = 1;
-       printk(KERN_INFO "fb%d: %s fb device registered successfully.\n",
-                info->node, info->fix.id);
+       dev_info(info->dev, "%s registered successfully\n", mfbi->id);
 
        return 0;
 }
@@ -1294,7 +1320,7 @@ static void uninstall_fb(struct fb_info *info)
        if (!mfbi->registered)
                return;
 
-       if (mfbi->index == 0)
+       if (mfbi->index == PLANE0)
                kfree(mfbi->edid_data);
 
        unregister_framebuffer(info);
@@ -1307,20 +1333,20 @@ static void uninstall_fb(struct fb_info *info)
 
 static irqreturn_t fsl_diu_isr(int irq, void *dev_id)
 {
-       struct diu *hw = dr.diu_reg;
+       struct diu __iomem *hw = dev_id;
        unsigned int status = in_be32(&hw->int_status);
 
        if (status) {
                /* This is the workaround for underrun */
                if (status & INT_UNDRUN) {
                        out_be32(&hw->diu_mode, 0);
-                       pr_debug("Err: DIU occurs underrun!\n");
                        udelay(1);
                        out_be32(&hw->diu_mode, 1);
                }
 #if defined(CONFIG_NOT_COHERENT_CACHE)
                else if (status & INT_VSYNC) {
                        unsigned int i;
+
                        for (i = 0; i < coherence_data_size;
                                i += d_cache_line_size)
                                __asm__ __volatile__ (
@@ -1333,43 +1359,38 @@ static irqreturn_t fsl_diu_isr(int irq, void *dev_id)
        return IRQ_NONE;
 }
 
-static int request_irq_local(int irq)
+static int request_irq_local(struct fsl_diu_data *machine_data)
 {
-       unsigned long status, ints;
-       struct diu *hw;
+       struct diu __iomem *hw = machine_data->diu_reg;
+       u32 ints;
        int ret;
 
-       hw = dr.diu_reg;
-
        /* Read to clear the status */
-       status = in_be32(&hw->int_status);
+       in_be32(&hw->int_status);
 
-       ret = request_irq(irq, fsl_diu_isr, 0, "diu", NULL);
-       if (ret)
-               pr_info("Request diu IRQ failed.\n");
-       else {
+       ret = request_irq(machine_data->irq, fsl_diu_isr, 0, "fsl-diu-fb", hw);
+       if (!ret) {
                ints = INT_PARERR | INT_LS_BF_VS;
 #if !defined(CONFIG_NOT_COHERENT_CACHE)
                ints |= INT_VSYNC;
 #endif
-               if (dr.mode == MFB_MODE2 || dr.mode == MFB_MODE3)
-                       ints |= INT_VSYNC_WB;
 
                /* Read to clear the status */
-               status = in_be32(&hw->int_status);
+               in_be32(&hw->int_status);
                out_be32(&hw->int_mask, ints);
        }
+
        return ret;
 }
 
-static void free_irq_local(int irq)
+static void free_irq_local(struct fsl_diu_data *machine_data)
 {
-       struct diu *hw = dr.diu_reg;
+       struct diu __iomem *hw = machine_data->diu_reg;
 
        /* Disable all LCDC interrupt */
        out_be32(&hw->int_mask, 0x1f);
 
-       free_irq(irq, NULL);
+       free_irq(machine_data->irq, NULL);
 }
 
 #ifdef CONFIG_PM
@@ -1406,49 +1427,42 @@ static int fsl_diu_resume(struct platform_device *ofdev)
 static int allocate_buf(struct device *dev, struct diu_addr *buf, u32 size,
                        u32 bytes_align)
 {
-       u32 offset, ssize;
-       u32 mask;
-       dma_addr_t paddr = 0;
+       u32 offset;
+       dma_addr_t mask;
 
-       ssize = size + bytes_align;
-       buf->vaddr = dma_alloc_coherent(dev, ssize, &paddr, GFP_DMA |
-                                                            __GFP_ZERO);
+       buf->vaddr =
+               dma_alloc_coherent(dev, size + bytes_align, &buf->paddr,
+                                  GFP_DMA | __GFP_ZERO);
        if (!buf->vaddr)
                return -ENOMEM;
 
-       buf->paddr = (__u32) paddr;
-
        mask = bytes_align - 1;
-       offset = (u32)buf->paddr & mask;
+       offset = buf->paddr & mask;
        if (offset) {
                buf->offset = bytes_align - offset;
-               buf->paddr = (u32)buf->paddr + offset;
+               buf->paddr = buf->paddr + offset;
        } else
                buf->offset = 0;
+
        return 0;
 }
 
 static void free_buf(struct device *dev, struct diu_addr *buf, u32 size,
                     u32 bytes_align)
 {
-       dma_free_coherent(dev, size + bytes_align,
-                               buf->vaddr, (buf->paddr - buf->offset));
-       return;
+       dma_free_coherent(dev, size + bytes_align, buf->vaddr,
+                         buf->paddr - buf->offset);
 }
 
 static ssize_t store_monitor(struct device *device,
        struct device_attribute *attr, const char *buf, size_t count)
 {
-       int old_monitor_port;
-       unsigned long val;
+       enum fsl_diu_monitor_port old_monitor_port;
        struct fsl_diu_data *machine_data =
                container_of(attr, struct fsl_diu_data, dev_attr);
 
-       if (strict_strtoul(buf, 10, &val))
-               return 0;
-
        old_monitor_port = machine_data->monitor_port;
-       machine_data->monitor_port = diu_ops.set_sysfs_monitor_port(val);
+       machine_data->monitor_port = fsl_diu_name_to_port(buf);
 
        if (old_monitor_port != machine_data->monitor_port) {
                /* All AOIs need adjust pixel format
@@ -1468,16 +1482,25 @@ static ssize_t show_monitor(struct device *device,
 {
        struct fsl_diu_data *machine_data =
                container_of(attr, struct fsl_diu_data, dev_attr);
-       return diu_ops.show_monitor_port(machine_data->monitor_port, buf);
+
+       switch (machine_data->monitor_port) {
+       case FSL_DIU_PORT_DVI:
+               return sprintf(buf, "DVI\n");
+       case FSL_DIU_PORT_LVDS:
+               return sprintf(buf, "Single-link LVDS\n");
+       case FSL_DIU_PORT_DLVDS:
+               return sprintf(buf, "Dual-link LVDS\n");
+       }
+
+       return 0;
 }
 
-static int __devinit fsl_diu_probe(struct platform_device *ofdev)
+static int __devinit fsl_diu_probe(struct platform_device *pdev)
 {
-       struct device_node *np = ofdev->dev.of_node;
+       struct device_node *np = pdev->dev.of_node;
        struct mfb_info *mfbi;
-       phys_addr_t dummy_ad_addr;
+       phys_addr_t dummy_ad_addr = 0;
        int ret, i, error = 0;
-       struct resource res;
        struct fsl_diu_data *machine_data;
        int diu_mode;
 
@@ -1485,11 +1508,13 @@ static int __devinit fsl_diu_probe(struct platform_device *ofdev)
        if (!machine_data)
                return -ENOMEM;
 
+       spin_lock_init(&machine_data->reg_lock);
+
        for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++) {
                machine_data->fsl_diu_info[i] =
-                       framebuffer_alloc(sizeof(struct mfb_info), &ofdev->dev);
+                       framebuffer_alloc(sizeof(struct mfb_info), &pdev->dev);
                if (!machine_data->fsl_diu_info[i]) {
-                       dev_err(&ofdev->dev, "cannot allocate memory\n");
+                       dev_err(&pdev->dev, "cannot allocate memory\n");
                        ret = -ENOMEM;
                        goto error2;
                }
@@ -1497,7 +1522,7 @@ static int __devinit fsl_diu_probe(struct platform_device *ofdev)
                memcpy(mfbi, &mfb_template[i], sizeof(struct mfb_info));
                mfbi->parent = machine_data;
 
-               if (mfbi->index == 0) {
+               if (mfbi->index == PLANE0) {
                        const u8 *prop;
                        int len;
 
@@ -1509,60 +1534,49 @@ static int __devinit fsl_diu_probe(struct platform_device *ofdev)
                }
        }
 
-       ret = of_address_to_resource(np, 0, &res);
-       if (ret) {
-               dev_err(&ofdev->dev, "could not obtain DIU address\n");
-               goto error;
-       }
-       if (!res.start) {
-               dev_err(&ofdev->dev, "invalid DIU address\n");
-               goto error;
-       }
-       dev_dbg(&ofdev->dev, "%s, res.start: 0x%08x\n", __func__, res.start);
-
-       dr.diu_reg = ioremap(res.start, sizeof(struct diu));
-       if (!dr.diu_reg) {
-               dev_err(&ofdev->dev, "Err: can't map DIU registers!\n");
+       machine_data->diu_reg = of_iomap(np, 0);
+       if (!machine_data->diu_reg) {
+               dev_err(&pdev->dev, "cannot map DIU registers\n");
                ret = -EFAULT;
                goto error2;
        }
 
-       diu_mode = in_be32(&dr.diu_reg->diu_mode);
-       if (diu_mode != MFB_MODE1)
-               out_be32(&dr.diu_reg->diu_mode, 0);     /* disable DIU */
+       diu_mode = in_be32(&machine_data->diu_reg->diu_mode);
+       if (diu_mode == MFB_MODE0)
+               out_be32(&machine_data->diu_reg->diu_mode, 0); /* disable DIU */
 
        /* Get the IRQ of the DIU */
        machine_data->irq = irq_of_parse_and_map(np, 0);
 
        if (!machine_data->irq) {
-               dev_err(&ofdev->dev, "could not get DIU IRQ\n");
+               dev_err(&pdev->dev, "could not get DIU IRQ\n");
                ret = -EINVAL;
                goto error;
        }
        machine_data->monitor_port = monitor_port;
 
        /* Area descriptor memory pool aligns to 64-bit boundary */
-       if (allocate_buf(&ofdev->dev, &pool.ad,
+       if (allocate_buf(&pdev->dev, &machine_data->ad,
                         sizeof(struct diu_ad) * FSL_AOI_NUM, 8))
                return -ENOMEM;
 
        /* Get memory for Gamma Table  - 32-byte aligned memory */
-       if (allocate_buf(&ofdev->dev, &pool.gamma, 768, 32)) {
+       if (allocate_buf(&pdev->dev, &machine_data->gamma, 768, 32)) {
                ret = -ENOMEM;
                goto error;
        }
 
        /* For performance, cursor bitmap buffer aligns to 32-byte boundary */
-       if (allocate_buf(&ofdev->dev, &pool.cursor, MAX_CURS * MAX_CURS * 2,
-                        32)) {
+       if (allocate_buf(&pdev->dev, &machine_data->cursor,
+                        MAX_CURS * MAX_CURS * 2, 32)) {
                ret = -ENOMEM;
                goto error;
        }
 
        i = ARRAY_SIZE(machine_data->fsl_diu_info);
-       machine_data->dummy_ad = (struct diu_ad *)
-                       ((u32)pool.ad.vaddr + pool.ad.offset) + i;
-       machine_data->dummy_ad->paddr = pool.ad.paddr +
+       machine_data->dummy_ad = (struct diu_ad *)((u32)machine_data->ad.vaddr +
+                       machine_data->ad.offset) + i;
+       machine_data->dummy_ad->paddr = machine_data->ad.paddr +
                        i * sizeof(struct diu_ad);
        machine_data->dummy_aoi_virt = fsl_diu_alloc(64, &dummy_ad_addr);
        if (!machine_data->dummy_aoi_virt) {
@@ -1581,30 +1595,29 @@ static int __devinit fsl_diu_probe(struct platform_device *ofdev)
         * Let DIU display splash screen if it was pre-initialized
         * by the bootloader, set dummy area descriptor otherwise.
         */
-       if (diu_mode != MFB_MODE1)
-               out_be32(&dr.diu_reg->desc[0], machine_data->dummy_ad->paddr);
+       if (diu_mode == MFB_MODE0)
+               out_be32(&machine_data->diu_reg->desc[0],
+                        machine_data->dummy_ad->paddr);
 
-       out_be32(&dr.diu_reg->desc[1], machine_data->dummy_ad->paddr);
-       out_be32(&dr.diu_reg->desc[2], machine_data->dummy_ad->paddr);
+       out_be32(&machine_data->diu_reg->desc[1], machine_data->dummy_ad->paddr);
+       out_be32(&machine_data->diu_reg->desc[2], machine_data->dummy_ad->paddr);
 
        for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++) {
                machine_data->fsl_diu_info[i]->fix.smem_start = 0;
                mfbi = machine_data->fsl_diu_info[i]->par;
-               mfbi->ad = (struct diu_ad *)((u32)pool.ad.vaddr
-                                       + pool.ad.offset) + i;
-               mfbi->ad->paddr = pool.ad.paddr + i * sizeof(struct diu_ad);
+               mfbi->ad = (struct diu_ad *)((u32)machine_data->ad.vaddr
+                                       + machine_data->ad.offset) + i;
+               mfbi->ad->paddr =
+                       machine_data->ad.paddr + i * sizeof(struct diu_ad);
                ret = install_fb(machine_data->fsl_diu_info[i]);
                if (ret) {
-                       dev_err(&ofdev->dev,
-                               "Failed to register framebuffer %d\n",
-                               i);
+                       dev_err(&pdev->dev, "could not register fb %d\n", i);
                        goto error;
                }
        }
 
-       if (request_irq_local(machine_data->irq)) {
-               dev_err(machine_data->fsl_diu_info[0]->dev,
-                       "could not request irq for diu.");
+       if (request_irq_local(machine_data)) {
+               dev_err(&pdev->dev, "could not claim irq\n");
                goto error;
        }
 
@@ -1616,29 +1629,28 @@ static int __devinit fsl_diu_probe(struct platform_device *ofdev)
        error = device_create_file(machine_data->fsl_diu_info[0]->dev,
                                  &machine_data->dev_attr);
        if (error) {
-               dev_err(machine_data->fsl_diu_info[0]->dev,
-                       "could not create sysfs %s file\n",
+               dev_err(&pdev->dev, "could not create sysfs file %s\n",
                        machine_data->dev_attr.attr.name);
        }
 
-       dev_set_drvdata(&ofdev->dev, machine_data);
+       dev_set_drvdata(&pdev->dev, machine_data);
        return 0;
 
 error:
-       for (i = ARRAY_SIZE(machine_data->fsl_diu_info);
-               i > 0; i--)
-               uninstall_fb(machine_data->fsl_diu_info[i - 1]);
-       if (pool.ad.vaddr)
-               free_buf(&ofdev->dev, &pool.ad,
+       for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++)
+               uninstall_fb(machine_data->fsl_diu_info[i]);
+
+       if (machine_data->ad.vaddr)
+               free_buf(&pdev->dev, &machine_data->ad,
                         sizeof(struct diu_ad) * FSL_AOI_NUM, 8);
-       if (pool.gamma.vaddr)
-               free_buf(&ofdev->dev, &pool.gamma, 768, 32);
-       if (pool.cursor.vaddr)
-               free_buf(&ofdev->dev, &pool.cursor, MAX_CURS * MAX_CURS * 2,
-                        32);
+       if (machine_data->gamma.vaddr)
+               free_buf(&pdev->dev, &machine_data->gamma, 768, 32);
+       if (machine_data->cursor.vaddr)
+               free_buf(&pdev->dev, &machine_data->cursor,
+                        MAX_CURS * MAX_CURS * 2, 32);
        if (machine_data->dummy_aoi_virt)
                fsl_diu_free(machine_data->dummy_aoi_virt, 64);
-       iounmap(dr.diu_reg);
+       iounmap(machine_data->diu_reg);
 
 error2:
        for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++)
@@ -1649,28 +1661,27 @@ error2:
        return ret;
 }
 
-
-static int fsl_diu_remove(struct platform_device *ofdev)
+static int fsl_diu_remove(struct platform_device *pdev)
 {
        struct fsl_diu_data *machine_data;
        int i;
 
-       machine_data = dev_get_drvdata(&ofdev->dev);
+       machine_data = dev_get_drvdata(&pdev->dev);
        disable_lcdc(machine_data->fsl_diu_info[0]);
-       free_irq_local(machine_data->irq);
-       for (i = ARRAY_SIZE(machine_data->fsl_diu_info); i > 0; i--)
-               uninstall_fb(machine_data->fsl_diu_info[i - 1]);
-       if (pool.ad.vaddr)
-               free_buf(&ofdev->dev, &pool.ad,
+       free_irq_local(machine_data);
+       for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++)
+               uninstall_fb(machine_data->fsl_diu_info[i]);
+       if (machine_data->ad.vaddr)
+               free_buf(&pdev->dev, &machine_data->ad,
                         sizeof(struct diu_ad) * FSL_AOI_NUM, 8);
-       if (pool.gamma.vaddr)
-               free_buf(&ofdev->dev, &pool.gamma, 768, 32);
-       if (pool.cursor.vaddr)
-               free_buf(&ofdev->dev, &pool.cursor, MAX_CURS * MAX_CURS * 2,
-                        32);
+       if (machine_data->gamma.vaddr)
+               free_buf(&pdev->dev, &machine_data->gamma, 768, 32);
+       if (machine_data->cursor.vaddr)
+               free_buf(&pdev->dev, &machine_data->cursor,
+                        MAX_CURS * MAX_CURS * 2, 32);
        if (machine_data->dummy_aoi_virt)
                fsl_diu_free(machine_data->dummy_aoi_virt, 64);
-       iounmap(dr.diu_reg);
+       iounmap(machine_data->diu_reg);
        for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++)
                if (machine_data->fsl_diu_info[i])
                        framebuffer_release(machine_data->fsl_diu_info[i]);
@@ -1692,8 +1703,7 @@ static int __init fsl_diu_setup(char *options)
                if (!*opt)
                        continue;
                if (!strncmp(opt, "monitor=", 8)) {
-                       if (!strict_strtoul(opt + 8, 10, &val) && (val <= 2))
-                               monitor_port = val;
+                       monitor_port = fsl_diu_name_to_port(opt + 8);
                } else if (!strncmp(opt, "bpp=", 4)) {
                        if (!strict_strtoul(opt + 4, 10, &val))
                                default_bpp = val;
@@ -1720,7 +1730,7 @@ MODULE_DEVICE_TABLE(of, fsl_diu_match);
 
 static struct platform_driver fsl_diu_driver = {
        .driver = {
-               .name = "fsl_diu",
+               .name = "fsl-diu-fb",
                .owner = THIS_MODULE,
                .of_match_table = fsl_diu_match,
        },
@@ -1746,48 +1756,54 @@ static int __init fsl_diu_init(void)
        if (fb_get_options("fslfb", &option))
                return -ENODEV;
        fsl_diu_setup(option);
+#else
+       monitor_port = fsl_diu_name_to_port(monitor_string);
 #endif
-       printk(KERN_INFO "Freescale DIU driver\n");
+       pr_info("Freescale Display Interface Unit (DIU) framebuffer driver\n");
 
 #ifdef CONFIG_NOT_COHERENT_CACHE
        np = of_find_node_by_type(NULL, "cpu");
        if (!np) {
-               printk(KERN_ERR "Err: can't find device node 'cpu'\n");
+               pr_err("fsl-diu-fb: can't find 'cpu' device node\n");
                return -ENODEV;
        }
 
        prop = of_get_property(np, "d-cache-size", NULL);
        if (prop == NULL) {
+               pr_err("fsl-diu-fb: missing 'd-cache-size' property' "
+                      "in 'cpu' node\n");
                of_node_put(np);
                return -ENODEV;
        }
 
-       /* Freescale PLRU requires 13/8 times the cache size to do a proper
-          displacement flush
+       /*
+        * Freescale PLRU requires 13/8 times the cache size to do a proper
+        * displacement flush
         */
-       coherence_data_size = *prop * 13;
+       coherence_data_size = be32_to_cpup(prop) * 13;
        coherence_data_size /= 8;
 
        prop = of_get_property(np, "d-cache-line-size", NULL);
        if (prop == NULL) {
+               pr_err("fsl-diu-fb: missing 'd-cache-line-size' property' "
+                      "in 'cpu' node\n");
                of_node_put(np);
                return -ENODEV;
        }
-       d_cache_line_size = *prop;
+       d_cache_line_size = be32_to_cpup(prop);
 
        of_node_put(np);
        coherence_data = vmalloc(coherence_data_size);
        if (!coherence_data)
                return -ENOMEM;
 #endif
+
        ret = platform_driver_register(&fsl_diu_driver);
        if (ret) {
-               printk(KERN_ERR
-                       "fsl-diu: failed to register platform driver\n");
+               pr_err("fsl-diu-fb: failed to register platform driver\n");
 #if defined(CONFIG_NOT_COHERENT_CACHE)
                vfree(coherence_data);
 #endif
-               iounmap(dr.diu_reg);
        }
        return ret;
 }
@@ -1811,8 +1827,8 @@ module_param_named(mode, fb_mode, charp, 0);
 MODULE_PARM_DESC(mode,
        "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\" ");
 module_param_named(bpp, default_bpp, ulong, 0);
-MODULE_PARM_DESC(bpp, "Specify bit-per-pixel if not specified mode");
-module_param_named(monitor, monitor_port, int, 0);
-MODULE_PARM_DESC(monitor,
-       "Specify the monitor port (0, 1 or 2) if supported by the platform");
+MODULE_PARM_DESC(bpp, "Specify bit-per-pixel if not specified in 'mode'");
+module_param_named(monitor, monitor_string, charp, 0);
+MODULE_PARM_DESC(monitor, "Specify the monitor port "
+       "(\"dvi\", \"lvds\", or \"dlvds\") if supported by the platform");
 
index d662317d85e30fb01782b29f0bb681d327b766df..223896cc5f7d66713f98db315ada5ab364fc7d2b 100644 (file)
@@ -149,10 +149,11 @@ int g364fb_cursor(struct fb_info *info, struct fb_cursor *cursor)
 static int g364fb_pan_display(struct fb_var_screeninfo *var, 
                              struct fb_info *info)
 {
-       if (var->xoffset || var->yoffset + var->yres > var->yres_virtual)
+       if (var->xoffset ||
+           var->yoffset + info->var.yres > info->var.yres_virtual)
                return -EINVAL;
 
-       *(unsigned int *) TOP_REG = var->yoffset * var->xres;
+       *(unsigned int *) TOP_REG = var->yoffset * info->var.xres;
        return 0;
 }
 
diff --git a/drivers/video/grvga.c b/drivers/video/grvga.c
new file mode 100644 (file)
index 0000000..f37e025
--- /dev/null
@@ -0,0 +1,579 @@
+/*
+ * Driver for Aeroflex Gaisler SVGACTRL framebuffer device.
+ *
+ * 2011 (c) Aeroflex Gaisler AB
+ *
+ * Full documentation of the core can be found here:
+ * http://www.gaisler.com/products/grlib/grip.pdf
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * Contributors: Kristoffer Glembo <kristoffer@gaisler.com>
+ *
+ */
+
+#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
+#include <linux/of_platform.h>
+#include <linux/of_device.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <linux/delay.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/tty.h>
+#include <linux/mm.h>
+#include <linux/fb.h>
+#include <linux/io.h>
+
+struct grvga_regs {
+       u32 status;             /* 0x00 */
+       u32 video_length;       /* 0x04 */
+       u32 front_porch;        /* 0x08 */
+       u32 sync_length;        /* 0x0C */
+       u32 line_length;        /* 0x10 */
+       u32 fb_pos;             /* 0x14 */
+       u32 clk_vector[4];      /* 0x18 */
+       u32 clut;               /* 0x20 */
+};
+
+struct grvga_par {
+       struct grvga_regs *regs;
+       u32 color_palette[16];  /* 16 entry pseudo palette used by fbcon in true color mode */
+       int clk_sel;
+       int fb_alloced;         /* = 1 if framebuffer is allocated in main memory */
+};
+
+
+static const struct fb_videomode grvga_modedb[] = {
+    {
+       /* 640x480 @ 60 Hz */
+       NULL, 60, 640, 480, 40000, 48, 16, 39, 11, 96, 2,
+       0, FB_VMODE_NONINTERLACED
+    }, {
+       /* 800x600 @ 60 Hz */
+       NULL, 60, 800, 600, 25000, 88, 40, 23, 1, 128, 4,
+       0, FB_VMODE_NONINTERLACED
+    }, {
+       /* 800x600 @ 72 Hz */
+       NULL, 72, 800, 600, 20000, 64, 56, 23, 37, 120, 6,
+       0, FB_VMODE_NONINTERLACED
+    }, {
+       /* 1024x768 @ 60 Hz */
+       NULL, 60, 1024, 768, 15385, 160, 24, 29, 3, 136, 6,
+       0, FB_VMODE_NONINTERLACED
+    }
+ };
+
+static struct fb_fix_screeninfo grvga_fix __initdata = {
+       .id =           "AG SVGACTRL",
+       .type =         FB_TYPE_PACKED_PIXELS,
+       .visual =       FB_VISUAL_PSEUDOCOLOR,
+       .xpanstep =     0,
+       .ypanstep =     1,
+       .ywrapstep =    0,
+       .accel =        FB_ACCEL_NONE,
+};
+
+static int grvga_check_var(struct fb_var_screeninfo *var,
+                          struct fb_info *info)
+{
+       struct grvga_par *par = info->par;
+       int i;
+
+       if (!var->xres)
+               var->xres = 1;
+       if (!var->yres)
+               var->yres = 1;
+       if (var->bits_per_pixel <= 8)
+               var->bits_per_pixel = 8;
+       else if (var->bits_per_pixel <= 16)
+               var->bits_per_pixel = 16;
+       else if (var->bits_per_pixel <= 24)
+               var->bits_per_pixel = 24;
+       else if (var->bits_per_pixel <= 32)
+               var->bits_per_pixel = 32;
+       else
+               return -EINVAL;
+
+       var->xres_virtual = var->xres;
+       var->yres_virtual = 2*var->yres;
+
+       if (info->fix.smem_len) {
+               if ((var->yres_virtual*var->xres_virtual*var->bits_per_pixel/8) > info->fix.smem_len)
+                       return -ENOMEM;
+       }
+
+       /* Which clocks that are available can be read out in these registers */
+       for (i = 0; i <= 3 ; i++) {
+               if (var->pixclock == par->regs->clk_vector[i])
+                       break;
+       }
+       if (i <= 3)
+               par->clk_sel = i;
+       else
+               return -EINVAL;
+
+       switch (info->var.bits_per_pixel) {
+       case 8:
+               var->red   = (struct fb_bitfield) {0, 8, 0};      /* offset, length, msb-right */
+               var->green = (struct fb_bitfield) {0, 8, 0};
+               var->blue  = (struct fb_bitfield) {0, 8, 0};
+               var->transp = (struct fb_bitfield) {0, 0, 0};
+               break;
+       case 16:
+               var->red   = (struct fb_bitfield) {11, 5, 0};
+               var->green = (struct fb_bitfield) {5, 6, 0};
+               var->blue  = (struct fb_bitfield) {0, 5, 0};
+               var->transp = (struct fb_bitfield) {0, 0, 0};
+               break;
+       case 24:
+       case 32:
+               var->red   = (struct fb_bitfield) {16, 8, 0};
+               var->green = (struct fb_bitfield) {8, 8, 0};
+               var->blue  = (struct fb_bitfield) {0, 8, 0};
+               var->transp = (struct fb_bitfield) {24, 8, 0};
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int grvga_set_par(struct fb_info *info)
+{
+
+       u32 func = 0;
+       struct grvga_par *par = info->par;
+
+       __raw_writel(((info->var.yres - 1) << 16) | (info->var.xres - 1),
+                    &par->regs->video_length);
+
+       __raw_writel((info->var.lower_margin << 16) | (info->var.right_margin),
+                    &par->regs->front_porch);
+
+       __raw_writel((info->var.vsync_len << 16) | (info->var.hsync_len),
+                    &par->regs->sync_length);
+
+       __raw_writel(((info->var.yres + info->var.lower_margin + info->var.upper_margin + info->var.vsync_len - 1) << 16) |
+                    (info->var.xres + info->var.right_margin + info->var.left_margin + info->var.hsync_len - 1),
+                    &par->regs->line_length);
+
+       switch (info->var.bits_per_pixel) {
+       case 8:
+               info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
+               func = 1;
+               break;
+       case 16:
+               info->fix.visual = FB_VISUAL_TRUECOLOR;
+               func = 2;
+               break;
+       case 24:
+       case 32:
+               info->fix.visual = FB_VISUAL_TRUECOLOR;
+               func = 3;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       __raw_writel((par->clk_sel << 6) | (func << 4) | 1,
+                    &par->regs->status);
+
+       info->fix.line_length = (info->var.xres_virtual*info->var.bits_per_pixel)/8;
+       return 0;
+}
+
+static int grvga_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *info)
+{
+       struct grvga_par *par;
+       par = info->par;
+
+       if (regno >= 256)       /* Size of CLUT */
+               return -EINVAL;
+
+       if (info->var.grayscale) {
+               /* grayscale = 0.30*R + 0.59*G + 0.11*B */
+               red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
+       }
+
+
+
+#define CNVT_TOHW(val, width) ((((val)<<(width))+0x7FFF-(val))>>16)
+
+       red    = CNVT_TOHW(red,   info->var.red.length);
+       green  = CNVT_TOHW(green, info->var.green.length);
+       blue   = CNVT_TOHW(blue,  info->var.blue.length);
+       transp = CNVT_TOHW(transp, info->var.transp.length);
+
+#undef CNVT_TOHW
+
+       /* In PSEUDOCOLOR we use the hardware CLUT */
+       if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR)
+               __raw_writel((regno << 24) | (red << 16) | (green << 8) | blue,
+                            &par->regs->clut);
+
+       /* Truecolor uses the pseudo palette */
+       else if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
+               u32 v;
+               if (regno >= 16)
+                       return -EINVAL;
+
+
+               v =     (red    << info->var.red.offset)   |
+                       (green  << info->var.green.offset) |
+                       (blue   << info->var.blue.offset)  |
+                       (transp << info->var.transp.offset);
+
+               ((u32 *) (info->pseudo_palette))[regno] = v;
+       }
+       return 0;
+}
+
+static int grvga_pan_display(struct fb_var_screeninfo *var,
+                            struct fb_info *info)
+{
+       struct grvga_par *par = info->par;
+       struct fb_fix_screeninfo *fix = &info->fix;
+       u32 base_addr;
+
+       if (var->xoffset != 0)
+               return -EINVAL;
+
+       base_addr = fix->smem_start + (var->yoffset * fix->line_length);
+       base_addr &= ~3UL;
+
+       /* Set framebuffer base address  */
+       __raw_writel(base_addr,
+                    &par->regs->fb_pos);
+
+       return 0;
+}
+
+static struct fb_ops grvga_ops = {
+       .owner          = THIS_MODULE,
+       .fb_check_var   = grvga_check_var,
+       .fb_set_par     = grvga_set_par,
+       .fb_setcolreg   = grvga_setcolreg,
+       .fb_pan_display = grvga_pan_display,
+       .fb_fillrect    = cfb_fillrect,
+       .fb_copyarea    = cfb_copyarea,
+       .fb_imageblit   = cfb_imageblit
+};
+
+static int __init grvga_parse_custom(char *options,
+                                    struct fb_var_screeninfo *screendata)
+{
+       char *this_opt;
+       int count = 0;
+       if (!options || !*options)
+               return -1;
+
+       while ((this_opt = strsep(&options, " ")) != NULL) {
+               if (!*this_opt)
+                       continue;
+
+               switch (count) {
+               case 0:
+                       screendata->pixclock = simple_strtoul(this_opt, NULL, 0);
+                       count++;
+                       break;
+               case 1:
+                       screendata->xres = screendata->xres_virtual = simple_strtoul(this_opt, NULL, 0);
+                       count++;
+                       break;
+               case 2:
+                       screendata->right_margin = simple_strtoul(this_opt, NULL, 0);
+                       count++;
+                       break;
+               case 3:
+                       screendata->hsync_len = simple_strtoul(this_opt, NULL, 0);
+                       count++;
+                       break;
+               case 4:
+                       screendata->left_margin = simple_strtoul(this_opt, NULL, 0);
+                       count++;
+                       break;
+               case 5:
+                       screendata->yres = screendata->yres_virtual = simple_strtoul(this_opt, NULL, 0);
+                       count++;
+                       break;
+               case 6:
+                       screendata->lower_margin = simple_strtoul(this_opt, NULL, 0);
+                       count++;
+                       break;
+               case 7:
+                       screendata->vsync_len = simple_strtoul(this_opt, NULL, 0);
+                       count++;
+                       break;
+               case 8:
+                       screendata->upper_margin = simple_strtoul(this_opt, NULL, 0);
+                       count++;
+                       break;
+               case 9:
+                       screendata->bits_per_pixel = simple_strtoul(this_opt, NULL, 0);
+                       count++;
+                       break;
+               default:
+                       return -1;
+               }
+       }
+       screendata->activate  = FB_ACTIVATE_NOW;
+       screendata->vmode     = FB_VMODE_NONINTERLACED;
+       return 0;
+}
+
+static int __devinit grvga_probe(struct platform_device *dev)
+{
+       struct fb_info *info;
+       int retval = -ENOMEM;
+       unsigned long virtual_start;
+       unsigned long grvga_fix_addr = 0;
+       unsigned long physical_start = 0;
+       unsigned long grvga_mem_size = 0;
+       struct grvga_par *par = NULL;
+       char *options = NULL, *mode_opt = NULL;
+
+       info = framebuffer_alloc(sizeof(struct grvga_par), &dev->dev);
+       if (!info) {
+               dev_err(&dev->dev, "framebuffer_alloc failed\n");
+               return -ENOMEM;
+       }
+
+       /* Expecting: "grvga: modestring, [addr:<framebuffer physical address>], [size:<framebuffer size>]
+        *
+        * If modestring is custom:<custom mode string> we parse the string which then contains all videoparameters
+        * If address is left out, we allocate memory,
+        * if size is left out we only allocate enough to support the given mode.
+        */
+       if (fb_get_options("grvga", &options)) {
+               retval = -ENODEV;
+               goto err;
+       }
+
+       if (!options || !*options)
+               options =  "640x480-8@60";
+
+       while (1) {
+               char *this_opt = strsep(&options, ",");
+
+               if (!this_opt)
+                       break;
+
+               if (!strncmp(this_opt, "custom", 6)) {
+                       if (grvga_parse_custom(this_opt, &info->var) < 0) {
+                               dev_err(&dev->dev, "Failed to parse custom mode (%s).\n", this_opt);
+                               retval = -EINVAL;
+                               goto err1;
+                       }
+               } else if (!strncmp(this_opt, "addr", 4))
+                       grvga_fix_addr = simple_strtoul(this_opt + 5, NULL, 16);
+               else if (!strncmp(this_opt, "size", 4))
+                       grvga_mem_size = simple_strtoul(this_opt + 5, NULL, 0);
+               else
+                       mode_opt = this_opt;
+       }
+
+       par = info->par;
+       info->fbops = &grvga_ops;
+       info->fix = grvga_fix;
+       info->pseudo_palette = par->color_palette;
+       info->flags = FBINFO_DEFAULT | FBINFO_PARTIAL_PAN_OK | FBINFO_HWACCEL_YPAN;
+       info->fix.smem_len = grvga_mem_size;
+
+       if (!request_mem_region(dev->resource[0].start, resource_size(&dev->resource[0]), "grlib-svgactrl regs")) {
+               dev_err(&dev->dev, "registers already mapped\n");
+               retval = -EBUSY;
+               goto err;
+       }
+
+       par->regs = of_ioremap(&dev->resource[0], 0,
+                              resource_size(&dev->resource[0]),
+                              "grlib-svgactrl regs");
+
+       if (!par->regs) {
+               dev_err(&dev->dev, "failed to map registers\n");
+               retval = -ENOMEM;
+               goto err1;
+       }
+
+       retval = fb_alloc_cmap(&info->cmap, 256, 0);
+       if (retval < 0) {
+               dev_err(&dev->dev, "failed to allocate mem with fb_alloc_cmap\n");
+               retval = -ENOMEM;
+               goto err2;
+       }
+
+       if (mode_opt) {
+               retval = fb_find_mode(&info->var, info, mode_opt,
+                                     grvga_modedb, sizeof(grvga_modedb), &grvga_modedb[0], 8);
+               if (!retval || retval == 4) {
+                       retval = -EINVAL;
+                       goto err3;
+               }
+       }
+
+       if (!grvga_mem_size)
+               grvga_mem_size = info->var.xres_virtual * info->var.yres_virtual * info->var.bits_per_pixel/8;
+
+       if (grvga_fix_addr) {
+               /* Got framebuffer base address from argument list */
+
+               physical_start = grvga_fix_addr;
+
+               if (!request_mem_region(physical_start, grvga_mem_size, dev->name)) {
+                       dev_err(&dev->dev, "failed to request memory region\n");
+                       retval = -ENOMEM;
+                       goto err3;
+               }
+
+               virtual_start = (unsigned long) ioremap(physical_start, grvga_mem_size);
+
+               if (!virtual_start) {
+                       dev_err(&dev->dev, "error mapping framebuffer memory\n");
+                       retval = -ENOMEM;
+                       goto err4;
+               }
+       } else {        /* Allocate frambuffer memory */
+
+               unsigned long page;
+
+               virtual_start = (unsigned long) __get_free_pages(GFP_DMA,
+                                                                get_order(grvga_mem_size));
+               if (!virtual_start) {
+                       dev_err(&dev->dev,
+                               "unable to allocate framebuffer memory (%lu bytes)\n",
+                               grvga_mem_size);
+                       retval = -ENOMEM;
+                       goto err3;
+               }
+
+               physical_start = dma_map_single(&dev->dev, (void *)virtual_start, grvga_mem_size, DMA_TO_DEVICE);
+
+               /* Set page reserved so that mmap will work. This is necessary
+                * since we'll be remapping normal memory.
+                */
+               for (page = virtual_start;
+                    page < PAGE_ALIGN(virtual_start + grvga_mem_size);
+                    page += PAGE_SIZE) {
+                       SetPageReserved(virt_to_page(page));
+               }
+
+               par->fb_alloced = 1;
+       }
+
+       memset((unsigned long *) virtual_start, 0, grvga_mem_size);
+
+       info->screen_base = (char __iomem *) virtual_start;
+       info->fix.smem_start = physical_start;
+       info->fix.smem_len   = grvga_mem_size;
+
+       dev_set_drvdata(&dev->dev, info);
+
+       dev_info(&dev->dev,
+                "Aeroflex Gaisler framebuffer device (fb%d), %dx%d-%d, using %luK of video memory @ %p\n",
+                info->node, info->var.xres, info->var.yres, info->var.bits_per_pixel,
+                grvga_mem_size >> 10, info->screen_base);
+
+       retval = register_framebuffer(info);
+       if (retval < 0) {
+               dev_err(&dev->dev, "failed to register framebuffer\n");
+               goto err4;
+       }
+
+       __raw_writel(physical_start, &par->regs->fb_pos);
+       __raw_writel(__raw_readl(&par->regs->status) | 1,  /* Enable framebuffer */
+                    &par->regs->status);
+
+       return 0;
+
+err4:
+       dev_set_drvdata(&dev->dev, NULL);
+       if (grvga_fix_addr) {
+               release_mem_region(physical_start, grvga_mem_size);
+               iounmap((void *)virtual_start);
+       } else
+               kfree((void *)virtual_start);
+err3:
+       fb_dealloc_cmap(&info->cmap);
+err2:
+       of_iounmap(&dev->resource[0], par->regs,
+                  resource_size(&dev->resource[0]));
+err1:
+       release_mem_region(dev->resource[0].start, resource_size(&dev->resource[0]));
+err:
+       framebuffer_release(info);
+
+       return retval;
+}
+
+static int __devexit grvga_remove(struct platform_device *device)
+{
+       struct fb_info *info = dev_get_drvdata(&device->dev);
+       struct grvga_par *par = info->par;
+
+       if (info) {
+               unregister_framebuffer(info);
+               fb_dealloc_cmap(&info->cmap);
+
+               of_iounmap(&device->resource[0], par->regs,
+                          resource_size(&device->resource[0]));
+               release_mem_region(device->resource[0].start, resource_size(&device->resource[0]));
+
+               if (!par->fb_alloced) {
+                       release_mem_region(info->fix.smem_start, info->fix.smem_len);
+                       iounmap(info->screen_base);
+               } else
+                       kfree((void *)info->screen_base);
+
+               framebuffer_release(info);
+               dev_set_drvdata(&device->dev, NULL);
+       }
+
+       return 0;
+}
+
+static struct of_device_id svgactrl_of_match[] = {
+       {
+               .name = "GAISLER_SVGACTRL",
+       },
+       {
+               .name = "01_063",
+       },
+       {},
+};
+MODULE_DEVICE_TABLE(of, svgactrl_of_match);
+
+static struct platform_driver grvga_driver = {
+       .driver = {
+               .name = "grlib-svgactrl",
+               .owner = THIS_MODULE,
+               .of_match_table = svgactrl_of_match,
+       },
+       .probe          = grvga_probe,
+       .remove         = __devexit_p(grvga_remove),
+};
+
+
+static int __init grvga_init(void)
+{
+       return platform_driver_register(&grvga_driver);
+}
+
+static void __exit grvga_exit(void)
+{
+       platform_driver_unregister(&grvga_driver);
+}
+
+module_init(grvga_init);
+module_exit(grvga_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Aeroflex Gaisler");
+MODULE_DESCRIPTION("Aeroflex Gaisler framebuffer device driver");
index 896e53dea906178a30f951e4460b76b462c51b66..0fad23f810a32035faffd0fcd7e0256426947b58 100644 (file)
@@ -543,8 +543,8 @@ static int gxt4500_pan_display(struct fb_var_screeninfo *var,
 
        if (var->xoffset & 7)
                return -EINVAL;
-       if (var->xoffset + var->xres > var->xres_virtual ||
-           var->yoffset + var->yres > var->yres_virtual)
+       if (var->xoffset + info->var.xres > info->var.xres_virtual ||
+           var->yoffset + info->var.yres > info->var.yres_virtual)
                return -EINVAL;
 
        writereg(par, REFRESH_START, (var->xoffset << 16) | var->yoffset);
index 4052718eefaa09215a8706501eb9e6e47a339857..4394389caf68d8e8ffa40c5d19e2eec3970d76eb 100644 (file)
@@ -422,8 +422,8 @@ static int hgafb_pan_display(struct fb_var_screeninfo *var,
                    var->xoffset)
                        return -EINVAL;
        } else {
-               if (var->xoffset + var->xres > info->var.xres_virtual
-                || var->yoffset + var->yres > info->var.yres_virtual
+               if (var->xoffset + info->var.xres > info->var.xres_virtual
+                || var->yoffset + info->var.yres > info->var.yres_virtual
                 || var->yoffset % 8)
                        return -EINVAL;
        }
index efb2c10656b0a89aa88d23276d47926805bbb4b2..8149356471e443af26d5a4e2cb97c818bfaf9c7f 100644 (file)
@@ -749,7 +749,7 @@ set_offset (struct fb_var_screeninfo *var, struct fb_info *info)
 {
        struct imstt_par *par = info->par;
        __u32 off = var->yoffset * (info->fix.line_length >> 3)
-                   + ((var->xoffset * (var->bits_per_pixel >> 3)) >> 3);
+                   + ((var->xoffset * (info->var.bits_per_pixel >> 3)) >> 3);
        write_reg_le32(par->dc_regs, SSR, off);
 }
 
index 38065cf94ac4cf5dbaf195233871712af4607ab6..fbad61da359f796b579ae74b1dc01a78d888d4a9 100644 (file)
@@ -390,12 +390,12 @@ int intelfbhw_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
        xoffset = ROUND_DOWN_TO(var->xoffset, 8);
        yoffset = var->yoffset;
 
-       if ((xoffset + var->xres > var->xres_virtual) ||
-           (yoffset + var->yres > var->yres_virtual))
+       if ((xoffset + info->var.xres > info->var.xres_virtual) ||
+           (yoffset + info->var.yres > info->var.yres_virtual))
                return -EINVAL;
 
        offset = (yoffset * dinfo->pitch) +
-                (xoffset * var->bits_per_pixel) / 8;
+                (xoffset * info->var.bits_per_pixel) / 8;
 
        offset += dinfo->fb.offset << 12;
 
index b953099edd8eb491850fdd4ca65e6c9b3789cd39..934081d2b7ae7f199e7631e98a46025bb2e0e5c2 100644 (file)
@@ -23,7 +23,7 @@ static int mb862xx_i2c_wait_event(struct i2c_adapter *adap)
        u32 reg;
 
        do {
-               udelay(1);
+               udelay(10);
                reg = inreg(i2c, GC_I2C_BCR);
                if (reg & (I2C_INT | I2C_BER))
                        break;
index ee1de3e26dece9a80f152478ffa642cfef00beae..c16ff1d62e9183edb9098a40a9f17d7ecaa975af 100644 (file)
@@ -278,7 +278,7 @@ static int mb862xxfb_pan(struct fb_var_screeninfo *var,
        reg = pack(var->yoffset, var->xoffset);
        outreg(disp, GC_L0WY_L0WX, reg);
 
-       reg = pack(var->yres_virtual, var->xres_virtual);
+       reg = pack(info->var.yres_virtual, info->var.xres_virtual);
        outreg(disp, GC_L0WH_L0WW, reg);
        return 0;
 }
@@ -737,7 +737,7 @@ static int __devinit of_platform_mb862xx_probe(struct platform_device *ofdev)
        if (mb862xx_gdc_init(par))
                goto io_unmap;
 
-       if (request_irq(par->irq, mb862xx_intr, IRQF_DISABLED,
+       if (request_irq(par->irq, mb862xx_intr, 0,
                        DRV_NAME, (void *)par)) {
                dev_err(dev, "Cannot request irq\n");
                goto io_unmap;
@@ -1073,7 +1073,7 @@ static int __devinit mb862xx_pci_probe(struct pci_dev *pdev,
        if (mb862xx_pci_gdc_init(par))
                goto io_unmap;
 
-       if (request_irq(par->irq, mb862xx_intr, IRQF_DISABLED | IRQF_SHARED,
+       if (request_irq(par->irq, mb862xx_intr, IRQF_SHARED,
                        DRV_NAME, (void *)par)) {
                dev_err(dev, "Cannot request irq\n");
                goto io_unmap;
index cb175fe7abc0829f65d7aeb3c54082bb80a8999a..a9a907c440d73ee89f2acc8fd20d7aa905230b43 100644 (file)
@@ -491,55 +491,56 @@ EXPORT_SYMBOL(vesa_modes);
 static int fb_try_mode(struct fb_var_screeninfo *var, struct fb_info *info,
                       const struct fb_videomode *mode, unsigned int bpp)
 {
-    int err = 0;
-
-    DPRINTK("Trying mode %s %dx%d-%d@%d\n", mode->name ? mode->name : "noname",
-           mode->xres, mode->yres, bpp, mode->refresh);
-    var->xres = mode->xres;
-    var->yres = mode->yres;
-    var->xres_virtual = mode->xres;
-    var->yres_virtual = mode->yres;
-    var->xoffset = 0;
-    var->yoffset = 0;
-    var->bits_per_pixel = bpp;
-    var->activate |= FB_ACTIVATE_TEST;
-    var->pixclock = mode->pixclock;
-    var->left_margin = mode->left_margin;
-    var->right_margin = mode->right_margin;
-    var->upper_margin = mode->upper_margin;
-    var->lower_margin = mode->lower_margin;
-    var->hsync_len = mode->hsync_len;
-    var->vsync_len = mode->vsync_len;
-    var->sync = mode->sync;
-    var->vmode = mode->vmode;
-    if (info->fbops->fb_check_var)
-       err = info->fbops->fb_check_var(var, info);
-    var->activate &= ~FB_ACTIVATE_TEST;
-    return err;
+       int err = 0;
+
+       DPRINTK("Trying mode %s %dx%d-%d@%d\n",
+               mode->name ? mode->name : "noname",
+               mode->xres, mode->yres, bpp, mode->refresh);
+       var->xres = mode->xres;
+       var->yres = mode->yres;
+       var->xres_virtual = mode->xres;
+       var->yres_virtual = mode->yres;
+       var->xoffset = 0;
+       var->yoffset = 0;
+       var->bits_per_pixel = bpp;
+       var->activate |= FB_ACTIVATE_TEST;
+       var->pixclock = mode->pixclock;
+       var->left_margin = mode->left_margin;
+       var->right_margin = mode->right_margin;
+       var->upper_margin = mode->upper_margin;
+       var->lower_margin = mode->lower_margin;
+       var->hsync_len = mode->hsync_len;
+       var->vsync_len = mode->vsync_len;
+       var->sync = mode->sync;
+       var->vmode = mode->vmode;
+       if (info->fbops->fb_check_var)
+               err = info->fbops->fb_check_var(var, info);
+       var->activate &= ~FB_ACTIVATE_TEST;
+       return err;
 }
 
 /**
- *     fb_find_mode - finds a valid video mode
- *     @var: frame buffer user defined part of display
- *     @info: frame buffer info structure
- *     @mode_option: string video mode to find
- *     @db: video mode database
- *     @dbsize: size of @db
- *     @default_mode: default video mode to fall back to
- *     @default_bpp: default color depth in bits per pixel
+ *     fb_find_mode - finds a valid video mode
+ *     @var: frame buffer user defined part of display
+ *     @info: frame buffer info structure
+ *     @mode_option: string video mode to find
+ *     @db: video mode database
+ *     @dbsize: size of @db
+ *     @default_mode: default video mode to fall back to
+ *     @default_bpp: default color depth in bits per pixel
  *
- *     Finds a suitable video mode, starting with the specified mode
- *     in @mode_option with fallback to @default_mode.  If
- *     @default_mode fails, all modes in the video mode database will
- *     be tried.
+ *     Finds a suitable video mode, starting with the specified mode
+ *     in @mode_option with fallback to @default_mode.  If
+ *     @default_mode fails, all modes in the video mode database will
+ *     be tried.
  *
- *     Valid mode specifiers for @mode_option:
+ *     Valid mode specifiers for @mode_option:
  *
- *     <xres>x<yres>[M][R][-<bpp>][@<refresh>][i][m] or
- *     <name>[-<bpp>][@<refresh>]
+ *     <xres>x<yres>[M][R][-<bpp>][@<refresh>][i][m] or
+ *     <name>[-<bpp>][@<refresh>]
  *
- *     with <xres>, <yres>, <bpp> and <refresh> decimal numbers and
- *     <name> a string.
+ *     with <xres>, <yres>, <bpp> and <refresh> decimal numbers and
+ *     <name> a string.
  *
  *      If 'M' is present after yres (and before refresh/bpp if present),
  *      the function will compute the timings using VESA(tm) Coordinated
@@ -551,12 +552,12 @@ static int fb_try_mode(struct fb_var_screeninfo *var, struct fb_info *info,
  *
  *      1024x768MR-8@60m - Reduced blank with margins at 60Hz.
  *
- *     NOTE: The passed struct @var is _not_ cleared!  This allows you
- *     to supply values for e.g. the grayscale and accel_flags fields.
+ *     NOTE: The passed struct @var is _not_ cleared!  This allows you
+ *     to supply values for e.g. the grayscale and accel_flags fields.
  *
- *     Returns zero for failure, 1 if using specified @mode_option,
- *     2 if using specified @mode_option with an ignored refresh rate,
- *     3 if default mode is used, 4 if fall back to any valid mode.
+ *     Returns zero for failure, 1 if using specified @mode_option,
+ *     2 if using specified @mode_option with an ignored refresh rate,
+ *     3 if default mode is used, 4 if fall back to any valid mode.
  *
  */
 
@@ -566,198 +567,203 @@ int fb_find_mode(struct fb_var_screeninfo *var,
                 const struct fb_videomode *default_mode,
                 unsigned int default_bpp)
 {
-    int i;
-
-    /* Set up defaults */
-    if (!db) {
-       db = modedb;
-       dbsize = ARRAY_SIZE(modedb);
-    }
-
-    if (!default_mode)
-       default_mode = &db[0];
-
-    if (!default_bpp)
-       default_bpp = 8;
-
-    /* Did the user specify a video mode? */
-    if (!mode_option)
-       mode_option = fb_mode_option;
-    if (mode_option) {
-       const char *name = mode_option;
-       unsigned int namelen = strlen(name);
-       int res_specified = 0, bpp_specified = 0, refresh_specified = 0;
-       unsigned int xres = 0, yres = 0, bpp = default_bpp, refresh = 0;
-       int yres_specified = 0, cvt = 0, rb = 0, interlace = 0, margins = 0;
-       u32 best, diff, tdiff;
-
-       for (i = namelen-1; i >= 0; i--) {
-           switch (name[i]) {
-               case '@':
-                   namelen = i;
-                   if (!refresh_specified && !bpp_specified &&
-                       !yres_specified) {
-                       refresh = simple_strtol(&name[i+1], NULL, 10);
-                       refresh_specified = 1;
-                       if (cvt || rb)
-                           cvt = 0;
-                   } else
-                       goto done;
-                   break;
-               case '-':
-                   namelen = i;
-                   if (!bpp_specified && !yres_specified) {
-                       bpp = simple_strtol(&name[i+1], NULL, 10);
-                       bpp_specified = 1;
-                       if (cvt || rb)
-                           cvt = 0;
-                   } else
-                       goto done;
-                   break;
-               case 'x':
-                   if (!yres_specified) {
-                       yres = simple_strtol(&name[i+1], NULL, 10);
-                       yres_specified = 1;
-                   } else
-                       goto done;
-                   break;
-               case '0' ... '9':
-                   break;
-               case 'M':
-                   if (!yres_specified)
-                       cvt = 1;
-                   break;
-               case 'R':
-                   if (!cvt)
-                       rb = 1;
-                   break;
-               case 'm':
-                   if (!cvt)
-                       margins = 1;
-                   break;
-               case 'i':
-                   if (!cvt)
-                       interlace = 1;
-                   break;
-               default:
-                   goto done;
-           }
-       }
-       if (i < 0 && yres_specified) {
-           xres = simple_strtol(name, NULL, 10);
-           res_specified = 1;
-       }
-done:
-       if (cvt) {
-           struct fb_videomode cvt_mode;
-           int ret;
-
-           DPRINTK("CVT mode %dx%d@%dHz%s%s%s\n", xres, yres,
-                   (refresh) ? refresh : 60, (rb) ? " reduced blanking" :
-                   "", (margins) ? " with margins" : "", (interlace) ?
-                   " interlaced" : "");
-
-           memset(&cvt_mode, 0, sizeof(cvt_mode));
-           cvt_mode.xres = xres;
-           cvt_mode.yres = yres;
-           cvt_mode.refresh = (refresh) ? refresh : 60;
+       int i;
 
-           if (interlace)
-               cvt_mode.vmode |= FB_VMODE_INTERLACED;
-           else
-               cvt_mode.vmode &= ~FB_VMODE_INTERLACED;
+       /* Set up defaults */
+       if (!db) {
+               db = modedb;
+               dbsize = ARRAY_SIZE(modedb);
+       }
 
-           ret = fb_find_mode_cvt(&cvt_mode, margins, rb);
+       if (!default_mode)
+               default_mode = &db[0];
+
+       if (!default_bpp)
+               default_bpp = 8;
+
+       /* Did the user specify a video mode? */
+       if (!mode_option)
+               mode_option = fb_mode_option;
+       if (mode_option) {
+               const char *name = mode_option;
+               unsigned int namelen = strlen(name);
+               int res_specified = 0, bpp_specified = 0, refresh_specified = 0;
+               unsigned int xres = 0, yres = 0, bpp = default_bpp, refresh = 0;
+               int yres_specified = 0, cvt = 0, rb = 0, interlace = 0;
+               int margins = 0;
+               u32 best, diff, tdiff;
+
+               for (i = namelen-1; i >= 0; i--) {
+                       switch (name[i]) {
+                       case '@':
+                               namelen = i;
+                               if (!refresh_specified && !bpp_specified &&
+                                   !yres_specified) {
+                                       refresh = simple_strtol(&name[i+1], NULL,
+                                                               10);
+                                       refresh_specified = 1;
+                                       if (cvt || rb)
+                                               cvt = 0;
+                               } else
+                                       goto done;
+                               break;
+                       case '-':
+                               namelen = i;
+                               if (!bpp_specified && !yres_specified) {
+                                       bpp = simple_strtol(&name[i+1], NULL,
+                                                           10);
+                                       bpp_specified = 1;
+                                       if (cvt || rb)
+                                               cvt = 0;
+                               } else
+                                       goto done;
+                               break;
+                       case 'x':
+                               if (!yres_specified) {
+                                       yres = simple_strtol(&name[i+1], NULL,
+                                                            10);
+                                       yres_specified = 1;
+                               } else
+                                       goto done;
+                               break;
+                       case '0' ... '9':
+                               break;
+                       case 'M':
+                               if (!yres_specified)
+                                       cvt = 1;
+                               break;
+                       case 'R':
+                               if (!cvt)
+                                       rb = 1;
+                               break;
+                       case 'm':
+                               if (!cvt)
+                                       margins = 1;
+                               break;
+                       case 'i':
+                               if (!cvt)
+                                       interlace = 1;
+                               break;
+                       default:
+                               goto done;
+                       }
+               }
+               if (i < 0 && yres_specified) {
+                       xres = simple_strtol(name, NULL, 10);
+                       res_specified = 1;
+               }
+done:
+               if (cvt) {
+                       struct fb_videomode cvt_mode;
+                       int ret;
+
+                       DPRINTK("CVT mode %dx%d@%dHz%s%s%s\n", xres, yres,
+                               (refresh) ? refresh : 60,
+                               (rb) ? " reduced blanking" : "",
+                               (margins) ? " with margins" : "",
+                               (interlace) ? " interlaced" : "");
+
+                       memset(&cvt_mode, 0, sizeof(cvt_mode));
+                       cvt_mode.xres = xres;
+                       cvt_mode.yres = yres;
+                       cvt_mode.refresh = (refresh) ? refresh : 60;
+
+                       if (interlace)
+                               cvt_mode.vmode |= FB_VMODE_INTERLACED;
+                       else
+                               cvt_mode.vmode &= ~FB_VMODE_INTERLACED;
+
+                       ret = fb_find_mode_cvt(&cvt_mode, margins, rb);
+
+                       if (!ret && !fb_try_mode(var, info, &cvt_mode, bpp)) {
+                               DPRINTK("modedb CVT: CVT mode ok\n");
+                               return 1;
+                       }
 
-           if (!ret && !fb_try_mode(var, info, &cvt_mode, bpp)) {
-               DPRINTK("modedb CVT: CVT mode ok\n");
-               return 1;
-           }
+                       DPRINTK("CVT mode invalid, getting mode from database\n");
+               }
 
-           DPRINTK("CVT mode invalid, getting mode from database\n");
-       }
+               DPRINTK("Trying specified video mode%s %ix%i\n",
+                       refresh_specified ? "" : " (ignoring refresh rate)",
+                       xres, yres);
 
-       DPRINTK("Trying specified video mode%s %ix%i\n",
-           refresh_specified ? "" : " (ignoring refresh rate)", xres, yres);
-
-       if (!refresh_specified) {
-               /*
-                * If the caller has provided a custom mode database and a
-                * valid monspecs structure, we look for the mode with the
-                * highest refresh rate.  Otherwise we play it safe it and
-                * try to find a mode with a refresh rate closest to the
-                * standard 60 Hz.
-                */
-               if (db != modedb &&
-                   info->monspecs.vfmin && info->monspecs.vfmax &&
-                   info->monspecs.hfmin && info->monspecs.hfmax &&
-                   info->monspecs.dclkmax) {
-                       refresh = 1000;
-               } else {
-                       refresh = 60;
+               if (!refresh_specified) {
+                       /*
+                        * If the caller has provided a custom mode database and
+                        * a valid monspecs structure, we look for the mode with
+                        * the highest refresh rate.  Otherwise we play it safe
+                        * it and try to find a mode with a refresh rate closest
+                        * to the standard 60 Hz.
+                        */
+                       if (db != modedb &&
+                           info->monspecs.vfmin && info->monspecs.vfmax &&
+                           info->monspecs.hfmin && info->monspecs.hfmax &&
+                           info->monspecs.dclkmax) {
+                               refresh = 1000;
+                       } else {
+                               refresh = 60;
+                       }
                }
-       }
 
-       diff = -1;
-       best = -1;
-       for (i = 0; i < dbsize; i++) {
-               if ((name_matches(db[i], name, namelen) ||
-                   (res_specified && res_matches(db[i], xres, yres))) &&
-                   !fb_try_mode(var, info, &db[i], bpp)) {
-                       if (refresh_specified && db[i].refresh == refresh) {
-                               return 1;
-                       } else {
+               diff = -1;
+               best = -1;
+               for (i = 0; i < dbsize; i++) {
+                       if ((name_matches(db[i], name, namelen) ||
+                            (res_specified && res_matches(db[i], xres, yres))) &&
+                           !fb_try_mode(var, info, &db[i], bpp)) {
+                               if (refresh_specified && db[i].refresh == refresh)
+                                       return 1;
+
                                if (abs(db[i].refresh - refresh) < diff) {
                                        diff = abs(db[i].refresh - refresh);
                                        best = i;
                                }
                        }
                }
-       }
-       if (best != -1) {
-               fb_try_mode(var, info, &db[best], bpp);
-               return (refresh_specified) ? 2 : 1;
-       }
-
-       diff = 2 * (xres + yres);
-       best = -1;
-       DPRINTK("Trying best-fit modes\n");
-       for (i = 0; i < dbsize; i++) {
-               DPRINTK("Trying %ix%i\n", db[i].xres, db[i].yres);
-               if (!fb_try_mode(var, info, &db[i], bpp)) {
-                       tdiff = abs(db[i].xres - xres) +
-                               abs(db[i].yres - yres);
-
-                       /*
-                        * Penalize modes with resolutions smaller
-                        * than requested.
-                        */
-                       if (xres > db[i].xres || yres > db[i].yres)
-                               tdiff += xres + yres;
+               if (best != -1) {
+                       fb_try_mode(var, info, &db[best], bpp);
+                       return (refresh_specified) ? 2 : 1;
+               }
 
-                       if (diff > tdiff) {
-                               diff = tdiff;
-                               best = i;
+               diff = 2 * (xres + yres);
+               best = -1;
+               DPRINTK("Trying best-fit modes\n");
+               for (i = 0; i < dbsize; i++) {
+                       DPRINTK("Trying %ix%i\n", db[i].xres, db[i].yres);
+                       if (!fb_try_mode(var, info, &db[i], bpp)) {
+                               tdiff = abs(db[i].xres - xres) +
+                                       abs(db[i].yres - yres);
+
+                               /*
+                                * Penalize modes with resolutions smaller
+                                * than requested.
+                                */
+                               if (xres > db[i].xres || yres > db[i].yres)
+                                       tdiff += xres + yres;
+
+                               if (diff > tdiff) {
+                                       diff = tdiff;
+                                       best = i;
+                               }
                        }
                }
+               if (best != -1) {
+                       fb_try_mode(var, info, &db[best], bpp);
+                       return 5;
+               }
        }
-       if (best != -1) {
-           fb_try_mode(var, info, &db[best], bpp);
-           return 5;
-       }
-    }
 
-    DPRINTK("Trying default video mode\n");
-    if (!fb_try_mode(var, info, default_mode, default_bpp))
-       return 3;
+       DPRINTK("Trying default video mode\n");
+       if (!fb_try_mode(var, info, default_mode, default_bpp))
+               return 3;
 
-    DPRINTK("Trying all modes\n");
-    for (i = 0; i < dbsize; i++)
-       if (!fb_try_mode(var, info, &db[i], default_bpp))
-           return 4;
+       DPRINTK("Trying all modes\n");
+       for (i = 0; i < dbsize; i++)
+               if (!fb_try_mode(var, info, &db[i], default_bpp))
+                       return 4;
 
-    DPRINTK("No valid mode found\n");
-    return 0;
+       DPRINTK("No valid mode found\n");
+       return 0;
 }
 
 /**
index 178b0720bd79a96d55e6d786fe8a183940263de2..4527cbf0a4ec61c4aca6956bbce7be89aea202e7 100644 (file)
@@ -715,7 +715,7 @@ static int __devinit mddi_probe(struct platform_device *pdev)
 
        mddi->int_enable = 0;
        mddi_writel(mddi->int_enable, INTEN);
-       ret = request_irq(mddi->irq, mddi_isr, IRQF_DISABLED, "mddi",
+       ret = request_irq(mddi->irq, mddi_isr, 0, "mddi",
                          &mddi->client_data);
        if (ret) {
                printk(KERN_ERR "mddi: failed to request enable irq!\n");
index 243d16f09b8a2cbbfc6f5604f1775ec97cf91d72..b9344772bac9bb4422e192bed355eab65ca685a9 100644 (file)
@@ -421,10 +421,11 @@ int mdp_probe(struct platform_device *pdev)
        clk = clk_get(&pdev->dev, "mdp_clk");
        if (IS_ERR(clk)) {
                printk(KERN_INFO "mdp: failed to get mdp clk");
-               return PTR_ERR(clk);
+               ret = PTR_ERR(clk);
+               goto error_get_clk;
        }
 
-       ret = request_irq(mdp->irq, mdp_isr, IRQF_DISABLED, "msm_mdp", mdp);
+       ret = request_irq(mdp->irq, mdp_isr, 0, "msm_mdp", mdp);
        if (ret)
                goto error_request_irq;
        disable_irq(mdp->irq);
@@ -495,6 +496,7 @@ int mdp_probe(struct platform_device *pdev)
 error_device_register:
        free_irq(mdp->irq, mdp);
 error_request_irq:
+error_get_clk:
        iounmap(mdp->base);
 error_get_irq:
 error_ioremap:
index 7e3a490e8d76d882555f58a752242360a6ed948b..e3406ab313059fcde53187f7bd9ea3f6352aff11 100644 (file)
@@ -382,6 +382,9 @@ static void sdc_disable_channel(struct mx3fb_info *mx3_fbi)
        uint32_t enabled;
        unsigned long flags;
 
+       if (mx3_fbi->txd == NULL)
+               return;
+
        spin_lock_irqsave(&mx3fb->lock, flags);
 
        enabled = sdc_fb_uninit(mx3_fbi);
@@ -986,9 +989,19 @@ static void __blank(int blank, struct fb_info *fbi)
 {
        struct mx3fb_info *mx3_fbi = fbi->par;
        struct mx3fb_data *mx3fb = mx3_fbi->mx3fb;
+       int was_blank = mx3_fbi->blank;
 
        mx3_fbi->blank = blank;
 
+       /* Attention!
+        * Do not call sdc_disable_channel() for a channel that is disabled
+        * already! This will result in a kernel NULL pointer dereference
+        * (mx3_fbi->txd is NULL). Hide the fact, that all blank modes are
+        * handled equally by this driver.
+        */
+       if (blank > FB_BLANK_UNBLANK && was_blank > FB_BLANK_UNBLANK)
+               return;
+
        switch (blank) {
        case FB_BLANK_POWERDOWN:
        case FB_BLANK_VSYNC_SUSPEND:
@@ -1062,15 +1075,15 @@ static int mx3fb_pan_display(struct fb_var_screeninfo *var,
        y_bottom = var->yoffset;
 
        if (!(var->vmode & FB_VMODE_YWRAP))
-               y_bottom += var->yres;
+               y_bottom += fbi->var.yres;
 
        if (y_bottom > fbi->var.yres_virtual)
                return -EINVAL;
 
        mutex_lock(&mx3_fbi->mutex);
 
-       offset = (var->yoffset * var->xres_virtual + var->xoffset) *
-               (var->bits_per_pixel / 8);
+       offset = var->yoffset * fbi->fix.line_length
+              + var->xoffset * (fbi->var.bits_per_pixel / 8);
        base = fbi->fix.smem_start + offset;
 
        dev_dbg(fbi->device, "Updating SDC BG buf %d address=0x%08lX\n",
index 0b2f2dd41416c0cb17f992fcf80dd33c47871bd8..d837d63c456feac5f5886ec6c31bb733c405bba3 100644 (file)
@@ -39,6 +39,7 @@
  * the required value in the imx_fb_videomode structure.
  */
 
+#include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/platform_device.h>
 #include <linux/clk.h>
index 588527a254c27ead542b906d7f4045aa6aff1955..feea7b1dc3860a3f28965995d9aa24968cb7312d 100644 (file)
@@ -1185,8 +1185,8 @@ static int neofb_pan_display(struct fb_var_screeninfo *var,
 
        DBG("neofb_update_start");
 
-       Base = (var->yoffset * var->xres_virtual + var->xoffset) >> 2;
-       Base *= (var->bits_per_pixel + 7) / 8;
+       Base = (var->yoffset * info->var.xres_virtual + var->xoffset) >> 2;
+       Base *= (info->var.bits_per_pixel + 7) / 8;
 
        neoUnlock();
 
index 0fff59782e45936cd86b481c4dff09326d94e5a5..d1fbbd888cf436b6ed8ce9d05e442ff3f605514b 100644 (file)
@@ -39,7 +39,6 @@
 #include <mach/regs-clock.h>
 #include <mach/regs-ldm.h>
 #include <mach/fb.h>
-#include <mach/clkdev.h>
 
 #include "nuc900fb.h"
 
@@ -588,7 +587,7 @@ static int __devinit nuc900fb_probe(struct platform_device *pdev)
        fbinfo->flags                   = FBINFO_FLAG_DEFAULT;
        fbinfo->pseudo_palette          = &fbi->pseudo_pal;
 
-       ret = request_irq(irq, nuc900fb_irqhandler, IRQF_DISABLED,
+       ret = request_irq(irq, nuc900fb_irqhandler, 0,
                          pdev->name, fbinfo);
        if (ret) {
                dev_err(&pdev->dev, "cannot register irq handler %d -err %d\n",
index 196fa2e7f438dbf2fd3cbc1ebbd4d813917a8bbb..84ff23208c254be23ff875b2c882e0bfeae3da93 100644 (file)
@@ -9,35 +9,6 @@ config FB_OMAP
        help
           Frame buffer driver for OMAP based boards.
 
-config FB_OMAP_LCD_VGA
-        bool "Use LCD in VGA mode"
-               depends on MACH_OMAP_3430SDP || MACH_OMAP_LDP
-               help
-                 Set LCD resolution as VGA (640 X 480).
-                 Default resolution without this option is QVGA(320 X 240).
-                 Please take a look at drivers/video/omap/lcd_ldp.c file
-                 for lcd driver code.
-choice
-       depends on FB_OMAP && MACH_OVERO
-       prompt "Screen resolution"
-       default FB_OMAP_079M3R
-       help
-         Selected desired screen resolution
-
-config FB_OMAP_031M3R
-       boolean "640 x 480 @ 60 Hz Reduced blanking"
-
-config FB_OMAP_048M3R
-       boolean "800 x 600 @ 60 Hz Reduced blanking"
-
-config FB_OMAP_079M3R
-       boolean "1024 x 768 @ 60 Hz Reduced blanking"
-
-config FB_OMAP_092M9R
-       boolean "1280 x 720 @ 60 Hz Reduced blanking"
-
-endchoice
-
 config FB_OMAP_LCDC_EXTERNAL
        bool "External LCD controller support"
        depends on FB_OMAP
index 25db55696e142961dc814bdc4fe98ca40ea2d371..ef78550917ffd8ea0a5eb26bcb9b04e56d331b50 100644 (file)
@@ -17,7 +17,6 @@ objs-y$(CONFIG_FB_OMAP_LCDC_HWA742) += hwa742.o
 objs-y$(CONFIG_FB_OMAP_LCDC_BLIZZARD) += blizzard.o
 
 objs-y$(CONFIG_MACH_AMS_DELTA) += lcd_ams_delta.o
-objs-y$(CONFIG_MACH_OMAP_H4) += lcd_h4.o
 objs-y$(CONFIG_MACH_OMAP_H3) += lcd_h3.o
 objs-y$(CONFIG_MACH_OMAP_PALMTE) += lcd_palmte.o
 objs-y$(CONFIG_MACH_OMAP_PALMTT) += lcd_palmtt.o
@@ -26,14 +25,7 @@ objs-$(CONFIG_ARCH_OMAP16XX)$(CONFIG_MACH_OMAP_INNOVATOR) += lcd_inn1610.o
 objs-$(CONFIG_ARCH_OMAP15XX)$(CONFIG_MACH_OMAP_INNOVATOR) += lcd_inn1510.o
 objs-y$(CONFIG_MACH_OMAP_OSK) += lcd_osk.o
 
-objs-y$(CONFIG_MACH_OMAP_APOLLON) += lcd_apollon.o
-objs-y$(CONFIG_MACH_OMAP_2430SDP) += lcd_2430sdp.o
-objs-y$(CONFIG_MACH_OMAP_3430SDP) += lcd_2430sdp.o
-objs-y$(CONFIG_MACH_OMAP_LDP) += lcd_ldp.o
-objs-y$(CONFIG_MACH_OMAP3EVM) += lcd_omap3evm.o
-objs-y$(CONFIG_MACH_OMAP3_BEAGLE) += lcd_omap3beagle.o
 objs-y$(CONFIG_FB_OMAP_LCD_MIPID) += lcd_mipid.o
-objs-y$(CONFIG_MACH_OVERO) += lcd_overo.o
 objs-y$(CONFIG_MACH_HERALD) += lcd_htcherald.o
 
 omapfb-objs := $(objs-yy)
diff --git a/drivers/video/omap/lcd_2430sdp.c b/drivers/video/omap/lcd_2430sdp.c
deleted file mode 100644 (file)
index e3eccc9..0000000
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * LCD panel support for the TI 2430SDP board
- *
- * Copyright (C) 2007 MontaVista
- * Author: Hunyue Yau <hyau@mvista.com>
- *
- * Derived from drivers/video/omap/lcd-apollon.c
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- */
-
-#include <linux/module.h>
-#include <linux/platform_device.h>
-#include <linux/delay.h>
-#include <linux/gpio.h>
-#include <linux/i2c/twl.h>
-
-#include <plat/mux.h>
-#include <asm/mach-types.h>
-
-#include "omapfb.h"
-
-#define SDP2430_LCD_PANEL_BACKLIGHT_GPIO       91
-#define SDP2430_LCD_PANEL_ENABLE_GPIO          154
-#define SDP3430_LCD_PANEL_BACKLIGHT_GPIO       24
-#define SDP3430_LCD_PANEL_ENABLE_GPIO          28
-
-static unsigned backlight_gpio;
-static unsigned enable_gpio;
-
-#define LCD_PIXCLOCK_MAX               5400 /* freq 5.4 MHz */
-#define PM_RECEIVER             TWL4030_MODULE_PM_RECEIVER
-#define ENABLE_VAUX2_DEDICATED  0x09
-#define ENABLE_VAUX2_DEV_GRP    0x20
-#define ENABLE_VAUX3_DEDICATED 0x03
-#define ENABLE_VAUX3_DEV_GRP   0x20
-
-#define ENABLE_VPLL2_DEDICATED          0x05
-#define ENABLE_VPLL2_DEV_GRP            0xE0
-#define TWL4030_VPLL2_DEV_GRP           0x33
-#define TWL4030_VPLL2_DEDICATED         0x36
-
-#define t2_out(c, r, v) twl_i2c_write_u8(c, r, v)
-
-
-static int sdp2430_panel_init(struct lcd_panel *panel,
-                               struct omapfb_device *fbdev)
-{
-       if (machine_is_omap_3430sdp()) {
-               enable_gpio    = SDP3430_LCD_PANEL_ENABLE_GPIO;
-               backlight_gpio = SDP3430_LCD_PANEL_BACKLIGHT_GPIO;
-       } else {
-               enable_gpio    = SDP2430_LCD_PANEL_ENABLE_GPIO;
-               backlight_gpio = SDP2430_LCD_PANEL_BACKLIGHT_GPIO;
-       }
-
-       gpio_request(enable_gpio, "LCD enable");        /* LCD panel */
-       gpio_request(backlight_gpio, "LCD bl");         /* LCD backlight */
-       gpio_direction_output(enable_gpio, 0);
-       gpio_direction_output(backlight_gpio, 0);
-
-       return 0;
-}
-
-static void sdp2430_panel_cleanup(struct lcd_panel *panel)
-{
-       gpio_free(backlight_gpio);
-       gpio_free(enable_gpio);
-}
-
-static int sdp2430_panel_enable(struct lcd_panel *panel)
-{
-       u8 ded_val, ded_reg;
-       u8 grp_val, grp_reg;
-
-       if (machine_is_omap_3430sdp()) {
-               ded_reg = TWL4030_VAUX3_DEDICATED;
-               ded_val = ENABLE_VAUX3_DEDICATED;
-               grp_reg = TWL4030_VAUX3_DEV_GRP;
-               grp_val = ENABLE_VAUX3_DEV_GRP;
-
-               if (omap_rev() > OMAP3430_REV_ES1_0) {
-                       t2_out(PM_RECEIVER, ENABLE_VPLL2_DEDICATED,
-                                       TWL4030_VPLL2_DEDICATED);
-                       t2_out(PM_RECEIVER, ENABLE_VPLL2_DEV_GRP,
-                                       TWL4030_VPLL2_DEV_GRP);
-               }
-       } else {
-               ded_reg = TWL4030_VAUX2_DEDICATED;
-               ded_val = ENABLE_VAUX2_DEDICATED;
-               grp_reg = TWL4030_VAUX2_DEV_GRP;
-               grp_val = ENABLE_VAUX2_DEV_GRP;
-       }
-
-       gpio_set_value(enable_gpio, 1);
-       gpio_set_value(backlight_gpio, 1);
-
-       if (0 != t2_out(PM_RECEIVER, ded_val, ded_reg))
-               return -EIO;
-       if (0 != t2_out(PM_RECEIVER, grp_val, grp_reg))
-               return -EIO;
-
-       return 0;
-}
-
-static void sdp2430_panel_disable(struct lcd_panel *panel)
-{
-       gpio_set_value(enable_gpio, 0);
-       gpio_set_value(backlight_gpio, 0);
-       if (omap_rev() > OMAP3430_REV_ES1_0) {
-               t2_out(PM_RECEIVER, 0x0, TWL4030_VPLL2_DEDICATED);
-               t2_out(PM_RECEIVER, 0x0, TWL4030_VPLL2_DEV_GRP);
-               msleep(4);
-       }
-}
-
-static unsigned long sdp2430_panel_get_caps(struct lcd_panel *panel)
-{
-       return 0;
-}
-
-struct lcd_panel sdp2430_panel = {
-       .name           = "sdp2430",
-       .config         = OMAP_LCDC_PANEL_TFT | OMAP_LCDC_INV_VSYNC |
-                         OMAP_LCDC_INV_HSYNC,
-
-       .bpp            = 16,
-       .data_lines     = 16,
-       .x_res          = 240,
-       .y_res          = 320,
-       .hsw            = 3,            /* hsync_len (4) - 1 */
-       .hfp            = 3,            /* right_margin (4) - 1 */
-       .hbp            = 39,           /* left_margin (40) - 1 */
-       .vsw            = 1,            /* vsync_len (2) - 1 */
-       .vfp            = 2,            /* lower_margin */
-       .vbp            = 7,            /* upper_margin (8) - 1 */
-
-       .pixel_clock    = LCD_PIXCLOCK_MAX,
-
-       .init           = sdp2430_panel_init,
-       .cleanup        = sdp2430_panel_cleanup,
-       .enable         = sdp2430_panel_enable,
-       .disable        = sdp2430_panel_disable,
-       .get_caps       = sdp2430_panel_get_caps,
-};
-
-static int sdp2430_panel_probe(struct platform_device *pdev)
-{
-       omapfb_register_panel(&sdp2430_panel);
-       return 0;
-}
-
-static int sdp2430_panel_remove(struct platform_device *pdev)
-{
-       return 0;
-}
-
-static int sdp2430_panel_suspend(struct platform_device *pdev,
-                                       pm_message_t mesg)
-{
-       return 0;
-}
-
-static int sdp2430_panel_resume(struct platform_device *pdev)
-{
-       return 0;
-}
-
-struct platform_driver sdp2430_panel_driver = {
-       .probe          = sdp2430_panel_probe,
-       .remove         = sdp2430_panel_remove,
-       .suspend        = sdp2430_panel_suspend,
-       .resume         = sdp2430_panel_resume,
-       .driver         = {
-               .name   = "sdp2430_lcd",
-               .owner  = THIS_MODULE,
-       },
-};
-
-static int __init sdp2430_panel_drv_init(void)
-{
-       return platform_driver_register(&sdp2430_panel_driver);
-}
-
-static void __exit sdp2430_panel_drv_exit(void)
-{
-       platform_driver_unregister(&sdp2430_panel_driver);
-}
-
-module_init(sdp2430_panel_drv_init);
-module_exit(sdp2430_panel_drv_exit);
diff --git a/drivers/video/omap/lcd_apollon.c b/drivers/video/omap/lcd_apollon.c
deleted file mode 100644 (file)
index 4b24f54..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * LCD panel support for the Samsung OMAP2 Apollon board
- *
- * Copyright (C) 2005,2006 Samsung Electronics
- * Author: Kyungmin Park <kyungmin.park@samsung.com>
- *
- * Derived from drivers/video/omap/lcd-h4.c
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- */
-
-#include <linux/module.h>
-#include <linux/platform_device.h>
-
-#include <asm/gpio.h>
-
-#include "omapfb.h"
-
-/* #define USE_35INCH_LCD 1 */
-
-static int apollon_panel_init(struct lcd_panel *panel,
-                               struct omapfb_device *fbdev)
-{
-       return 0;
-}
-
-static void apollon_panel_cleanup(struct lcd_panel *panel)
-{
-}
-
-static int apollon_panel_enable(struct lcd_panel *panel)
-{
-       return 0;
-}
-
-static void apollon_panel_disable(struct lcd_panel *panel)
-{
-}
-
-static unsigned long apollon_panel_get_caps(struct lcd_panel *panel)
-{
-       return 0;
-}
-
-struct lcd_panel apollon_panel = {
-       .name           = "apollon",
-       .config         = OMAP_LCDC_PANEL_TFT | OMAP_LCDC_INV_VSYNC |
-                         OMAP_LCDC_INV_HSYNC,
-
-       .bpp            = 16,
-       .data_lines     = 18,
-#ifdef USE_35INCH_LCD
-       .x_res          = 240,
-       .y_res          = 320,
-       .hsw            = 2,
-       .hfp            = 3,
-       .hbp            = 9,
-       .vsw            = 4,
-       .vfp            = 3,
-       .vbp            = 5,
-#else
-       .x_res          = 480,
-       .y_res          = 272,
-       .hsw            = 41,
-       .hfp            = 2,
-       .hbp            = 2,
-       .vsw            = 10,
-       .vfp            = 2,
-       .vbp            = 2,
-#endif
-       .pixel_clock    = 6250,
-
-       .init           = apollon_panel_init,
-       .cleanup        = apollon_panel_cleanup,
-       .enable         = apollon_panel_enable,
-       .disable        = apollon_panel_disable,
-       .get_caps       = apollon_panel_get_caps,
-};
-
-static int apollon_panel_probe(struct platform_device *pdev)
-{
-       omapfb_register_panel(&apollon_panel);
-       return 0;
-}
-
-static int apollon_panel_remove(struct platform_device *pdev)
-{
-       return 0;
-}
-
-static int apollon_panel_suspend(struct platform_device *pdev,
-                                 pm_message_t mesg)
-{
-       return 0;
-}
-
-static int apollon_panel_resume(struct platform_device *pdev)
-{
-       return 0;
-}
-
-struct platform_driver apollon_panel_driver = {
-       .probe          = apollon_panel_probe,
-       .remove         = apollon_panel_remove,
-       .suspend        = apollon_panel_suspend,
-       .resume         = apollon_panel_resume,
-       .driver         = {
-               .name   = "apollon_lcd",
-               .owner  = THIS_MODULE,
-       },
-};
-
-static int __init apollon_panel_drv_init(void)
-{
-       return platform_driver_register(&apollon_panel_driver);
-}
-
-static void __exit apollon_panel_drv_exit(void)
-{
-       platform_driver_unregister(&apollon_panel_driver);
-}
-
-module_init(apollon_panel_drv_init);
-module_exit(apollon_panel_drv_exit);
diff --git a/drivers/video/omap/lcd_h4.c b/drivers/video/omap/lcd_h4.c
deleted file mode 100644 (file)
index 03a06a9..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * LCD panel support for the TI OMAP H4 board
- *
- * Copyright (C) 2004 Nokia Corporation
- * Author: Imre Deak <imre.deak@nokia.com>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- */
-
-#include <linux/module.h>
-#include <linux/platform_device.h>
-
-#include "omapfb.h"
-
-static int h4_panel_init(struct lcd_panel *panel, struct omapfb_device *fbdev)
-{
-       return 0;
-}
-
-static void h4_panel_cleanup(struct lcd_panel *panel)
-{
-}
-
-static int h4_panel_enable(struct lcd_panel *panel)
-{
-       return 0;
-}
-
-static void h4_panel_disable(struct lcd_panel *panel)
-{
-}
-
-static unsigned long h4_panel_get_caps(struct lcd_panel *panel)
-{
-       return 0;
-}
-
-static struct lcd_panel h4_panel = {
-       .name           = "h4",
-       .config         = OMAP_LCDC_PANEL_TFT,
-
-       .bpp            = 16,
-       .data_lines     = 16,
-       .x_res          = 240,
-       .y_res          = 320,
-       .pixel_clock    = 6250,
-       .hsw            = 15,
-       .hfp            = 15,
-       .hbp            = 60,
-       .vsw            = 1,
-       .vfp            = 1,
-       .vbp            = 1,
-
-       .init           = h4_panel_init,
-       .cleanup        = h4_panel_cleanup,
-       .enable         = h4_panel_enable,
-       .disable        = h4_panel_disable,
-       .get_caps       = h4_panel_get_caps,
-};
-
-static int h4_panel_probe(struct platform_device *pdev)
-{
-       omapfb_register_panel(&h4_panel);
-       return 0;
-}
-
-static int h4_panel_remove(struct platform_device *pdev)
-{
-       return 0;
-}
-
-static int h4_panel_suspend(struct platform_device *pdev, pm_message_t mesg)
-{
-       return 0;
-}
-
-static int h4_panel_resume(struct platform_device *pdev)
-{
-       return 0;
-}
-
-static struct platform_driver h4_panel_driver = {
-       .probe          = h4_panel_probe,
-       .remove         = h4_panel_remove,
-       .suspend        = h4_panel_suspend,
-       .resume         = h4_panel_resume,
-       .driver         = {
-               .name   = "lcd_h4",
-               .owner  = THIS_MODULE,
-       },
-};
-
-static int __init h4_panel_drv_init(void)
-{
-       return platform_driver_register(&h4_panel_driver);
-}
-
-static void __exit h4_panel_drv_cleanup(void)
-{
-       platform_driver_unregister(&h4_panel_driver);
-}
-
-module_init(h4_panel_drv_init);
-module_exit(h4_panel_drv_cleanup);
-
diff --git a/drivers/video/omap/lcd_ldp.c b/drivers/video/omap/lcd_ldp.c
deleted file mode 100644 (file)
index 0624664..0000000
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * LCD panel support for the TI LDP board
- *
- * Copyright (C) 2007 WindRiver
- * Author: Stanley Miao <stanley.miao@windriver.com>
- *
- * Derived from drivers/video/omap/lcd-2430sdp.c
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- */
-
-#include <linux/module.h>
-#include <linux/platform_device.h>
-#include <linux/delay.h>
-#include <linux/i2c/twl.h>
-
-#include <asm/gpio.h>
-#include <plat/mux.h>
-#include <asm/mach-types.h>
-
-#include "omapfb.h"
-
-#define LCD_PANEL_BACKLIGHT_GPIO       (15 + OMAP_MAX_GPIO_LINES)
-#define LCD_PANEL_ENABLE_GPIO          (7 + OMAP_MAX_GPIO_LINES)
-
-#define LCD_PANEL_RESET_GPIO           55
-#define LCD_PANEL_QVGA_GPIO            56
-
-#ifdef CONFIG_FB_OMAP_LCD_VGA
-#define LCD_XRES               480
-#define LCD_YRES               640
-#define LCD_PIXCLOCK_MAX       41700
-#else
-#define LCD_XRES               240
-#define LCD_YRES               320
-#define LCD_PIXCLOCK_MAX       185186
-#endif
-
-#define PM_RECEIVER             TWL4030_MODULE_PM_RECEIVER
-#define ENABLE_VAUX2_DEDICATED  0x09
-#define ENABLE_VAUX2_DEV_GRP    0x20
-#define ENABLE_VAUX3_DEDICATED 0x03
-#define ENABLE_VAUX3_DEV_GRP   0x20
-
-#define ENABLE_VPLL2_DEDICATED          0x05
-#define ENABLE_VPLL2_DEV_GRP            0xE0
-#define TWL4030_VPLL2_DEV_GRP           0x33
-#define TWL4030_VPLL2_DEDICATED         0x36
-
-#define t2_out(c, r, v) twl_i2c_write_u8(c, r, v)
-
-
-static int ldp_panel_init(struct lcd_panel *panel,
-                               struct omapfb_device *fbdev)
-{
-       gpio_request(LCD_PANEL_RESET_GPIO, "lcd reset");
-       gpio_request(LCD_PANEL_QVGA_GPIO, "lcd qvga");
-       gpio_request(LCD_PANEL_ENABLE_GPIO, "lcd panel");
-       gpio_request(LCD_PANEL_BACKLIGHT_GPIO, "lcd backlight");
-
-       gpio_direction_output(LCD_PANEL_QVGA_GPIO, 0);
-       gpio_direction_output(LCD_PANEL_RESET_GPIO, 0);
-       gpio_direction_output(LCD_PANEL_ENABLE_GPIO, 0);
-       gpio_direction_output(LCD_PANEL_BACKLIGHT_GPIO, 0);
-
-#ifdef CONFIG_FB_OMAP_LCD_VGA
-       gpio_set_value(LCD_PANEL_QVGA_GPIO, 0);
-#else
-       gpio_set_value(LCD_PANEL_QVGA_GPIO, 1);
-#endif
-       gpio_set_value(LCD_PANEL_RESET_GPIO, 1);
-
-       return 0;
-}
-
-static void ldp_panel_cleanup(struct lcd_panel *panel)
-{
-       gpio_free(LCD_PANEL_BACKLIGHT_GPIO);
-       gpio_free(LCD_PANEL_ENABLE_GPIO);
-       gpio_free(LCD_PANEL_QVGA_GPIO);
-       gpio_free(LCD_PANEL_RESET_GPIO);
-}
-
-static int ldp_panel_enable(struct lcd_panel *panel)
-{
-       if (0 != t2_out(PM_RECEIVER, ENABLE_VPLL2_DEDICATED,
-                       TWL4030_VPLL2_DEDICATED))
-               return -EIO;
-       if (0 != t2_out(PM_RECEIVER, ENABLE_VPLL2_DEV_GRP,
-                       TWL4030_VPLL2_DEV_GRP))
-               return -EIO;
-
-       gpio_direction_output(LCD_PANEL_ENABLE_GPIO, 1);
-       gpio_direction_output(LCD_PANEL_BACKLIGHT_GPIO, 1);
-
-       if (0 != t2_out(PM_RECEIVER, ENABLE_VAUX3_DEDICATED,
-                               TWL4030_VAUX3_DEDICATED))
-               return -EIO;
-       if (0 != t2_out(PM_RECEIVER, ENABLE_VAUX3_DEV_GRP,
-                               TWL4030_VAUX3_DEV_GRP))
-               return -EIO;
-
-       return 0;
-}
-
-static void ldp_panel_disable(struct lcd_panel *panel)
-{
-       gpio_direction_output(LCD_PANEL_ENABLE_GPIO, 0);
-       gpio_direction_output(LCD_PANEL_BACKLIGHT_GPIO, 0);
-
-       t2_out(PM_RECEIVER, 0x0, TWL4030_VPLL2_DEDICATED);
-       t2_out(PM_RECEIVER, 0x0, TWL4030_VPLL2_DEV_GRP);
-       msleep(4);
-}
-
-static unsigned long ldp_panel_get_caps(struct lcd_panel *panel)
-{
-       return 0;
-}
-
-struct lcd_panel ldp_panel = {
-       .name           = "ldp",
-       .config         = OMAP_LCDC_PANEL_TFT | OMAP_LCDC_INV_VSYNC |
-                         OMAP_LCDC_INV_HSYNC,
-
-       .bpp            = 16,
-       .data_lines     = 18,
-       .x_res          = LCD_XRES,
-       .y_res          = LCD_YRES,
-       .hsw            = 3,            /* hsync_len (4) - 1 */
-       .hfp            = 3,            /* right_margin (4) - 1 */
-       .hbp            = 39,           /* left_margin (40) - 1 */
-       .vsw            = 1,            /* vsync_len (2) - 1 */
-       .vfp            = 2,            /* lower_margin */
-       .vbp            = 7,            /* upper_margin (8) - 1 */
-
-       .pixel_clock    = LCD_PIXCLOCK_MAX,
-
-       .init           = ldp_panel_init,
-       .cleanup        = ldp_panel_cleanup,
-       .enable         = ldp_panel_enable,
-       .disable        = ldp_panel_disable,
-       .get_caps       = ldp_panel_get_caps,
-};
-
-static int ldp_panel_probe(struct platform_device *pdev)
-{
-       omapfb_register_panel(&ldp_panel);
-       return 0;
-}
-
-static int ldp_panel_remove(struct platform_device *pdev)
-{
-       return 0;
-}
-
-static int ldp_panel_suspend(struct platform_device *pdev, pm_message_t mesg)
-{
-       return 0;
-}
-
-static int ldp_panel_resume(struct platform_device *pdev)
-{
-       return 0;
-}
-
-struct platform_driver ldp_panel_driver = {
-       .probe          = ldp_panel_probe,
-       .remove         = ldp_panel_remove,
-       .suspend        = ldp_panel_suspend,
-       .resume         = ldp_panel_resume,
-       .driver         = {
-               .name   = "ldp_lcd",
-               .owner  = THIS_MODULE,
-       },
-};
-
-static int __init ldp_panel_drv_init(void)
-{
-       return platform_driver_register(&ldp_panel_driver);
-}
-
-static void __exit ldp_panel_drv_exit(void)
-{
-       platform_driver_unregister(&ldp_panel_driver);
-}
-
-module_init(ldp_panel_drv_init);
-module_exit(ldp_panel_drv_exit);
diff --git a/drivers/video/omap/lcd_omap3beagle.c b/drivers/video/omap/lcd_omap3beagle.c
deleted file mode 100644 (file)
index d7c6c3e..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * LCD panel support for the TI OMAP3 Beagle board
- *
- * Author: Koen Kooi <koen@openembedded.org>
- *
- * Derived from drivers/video/omap/lcd-omap3evm.c
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- */
-
-#include <linux/module.h>
-#include <linux/platform_device.h>
-#include <linux/gpio.h>
-#include <linux/i2c/twl.h>
-
-#include <asm/mach-types.h>
-
-#include "omapfb.h"
-
-#define LCD_PANEL_ENABLE_GPIO       170
-
-static int omap3beagle_panel_init(struct lcd_panel *panel,
-                               struct omapfb_device *fbdev)
-{
-       gpio_request(LCD_PANEL_ENABLE_GPIO, "LCD enable");
-       return 0;
-}
-
-static void omap3beagle_panel_cleanup(struct lcd_panel *panel)
-{
-       gpio_free(LCD_PANEL_ENABLE_GPIO);
-}
-
-static int omap3beagle_panel_enable(struct lcd_panel *panel)
-{
-       gpio_set_value(LCD_PANEL_ENABLE_GPIO, 1);
-       return 0;
-}
-
-static void omap3beagle_panel_disable(struct lcd_panel *panel)
-{
-       gpio_set_value(LCD_PANEL_ENABLE_GPIO, 0);
-}
-
-static unsigned long omap3beagle_panel_get_caps(struct lcd_panel *panel)
-{
-       return 0;
-}
-
-struct lcd_panel omap3beagle_panel = {
-       .name           = "omap3beagle",
-       .config         = OMAP_LCDC_PANEL_TFT,
-
-       .bpp            = 16,
-       .data_lines     = 24,
-       .x_res          = 1024,
-       .y_res          = 768,
-       .hsw            = 3,            /* hsync_len (4) - 1 */
-       .hfp            = 3,            /* right_margin (4) - 1 */
-       .hbp            = 39,           /* left_margin (40) - 1 */
-       .vsw            = 1,            /* vsync_len (2) - 1 */
-       .vfp            = 2,            /* lower_margin */
-       .vbp            = 7,            /* upper_margin (8) - 1 */
-
-       .pixel_clock    = 64000,
-
-       .init           = omap3beagle_panel_init,
-       .cleanup        = omap3beagle_panel_cleanup,
-       .enable         = omap3beagle_panel_enable,
-       .disable        = omap3beagle_panel_disable,
-       .get_caps       = omap3beagle_panel_get_caps,
-};
-
-static int omap3beagle_panel_probe(struct platform_device *pdev)
-{
-       omapfb_register_panel(&omap3beagle_panel);
-       return 0;
-}
-
-static int omap3beagle_panel_remove(struct platform_device *pdev)
-{
-       return 0;
-}
-
-static int omap3beagle_panel_suspend(struct platform_device *pdev,
-                                  pm_message_t mesg)
-{
-       return 0;
-}
-
-static int omap3beagle_panel_resume(struct platform_device *pdev)
-{
-       return 0;
-}
-
-struct platform_driver omap3beagle_panel_driver = {
-       .probe          = omap3beagle_panel_probe,
-       .remove         = omap3beagle_panel_remove,
-       .suspend        = omap3beagle_panel_suspend,
-       .resume         = omap3beagle_panel_resume,
-       .driver         = {
-               .name   = "omap3beagle_lcd",
-               .owner  = THIS_MODULE,
-       },
-};
-
-static int __init omap3beagle_panel_drv_init(void)
-{
-       return platform_driver_register(&omap3beagle_panel_driver);
-}
-
-static void __exit omap3beagle_panel_drv_exit(void)
-{
-       platform_driver_unregister(&omap3beagle_panel_driver);
-}
-
-module_init(omap3beagle_panel_drv_init);
-module_exit(omap3beagle_panel_drv_exit);
diff --git a/drivers/video/omap/lcd_omap3evm.c b/drivers/video/omap/lcd_omap3evm.c
deleted file mode 100644 (file)
index 06840da..0000000
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * LCD panel support for the TI OMAP3 EVM board
- *
- * Author: Steve Sakoman <steve@sakoman.com>
- *
- * Derived from drivers/video/omap/lcd-apollon.c
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- */
-
-#include <linux/module.h>
-#include <linux/platform_device.h>
-#include <linux/gpio.h>
-#include <linux/i2c/twl.h>
-
-#include <plat/mux.h>
-#include <asm/mach-types.h>
-
-#include "omapfb.h"
-
-#define LCD_PANEL_ENABLE_GPIO       153
-#define LCD_PANEL_LR                2
-#define LCD_PANEL_UD                3
-#define LCD_PANEL_INI               152
-#define LCD_PANEL_QVGA              154
-#define LCD_PANEL_RESB              155
-
-#define ENABLE_VDAC_DEDICATED  0x03
-#define ENABLE_VDAC_DEV_GRP    0x20
-#define ENABLE_VPLL2_DEDICATED 0x05
-#define ENABLE_VPLL2_DEV_GRP   0xE0
-
-#define TWL_LED_LEDEN          0x00
-#define TWL_PWMA_PWMAON                0x00
-#define TWL_PWMA_PWMAOFF       0x01
-
-static unsigned int bklight_level;
-
-static int omap3evm_panel_init(struct lcd_panel *panel,
-                               struct omapfb_device *fbdev)
-{
-       gpio_request(LCD_PANEL_LR, "LCD lr");
-       gpio_request(LCD_PANEL_UD, "LCD ud");
-       gpio_request(LCD_PANEL_INI, "LCD ini");
-       gpio_request(LCD_PANEL_RESB, "LCD resb");
-       gpio_request(LCD_PANEL_QVGA, "LCD qvga");
-
-       gpio_direction_output(LCD_PANEL_RESB, 1);
-       gpio_direction_output(LCD_PANEL_INI, 1);
-       gpio_direction_output(LCD_PANEL_QVGA, 0);
-       gpio_direction_output(LCD_PANEL_LR, 1);
-       gpio_direction_output(LCD_PANEL_UD, 1);
-
-       twl_i2c_write_u8(TWL4030_MODULE_LED, 0x11, TWL_LED_LEDEN);
-       twl_i2c_write_u8(TWL4030_MODULE_PWMA, 0x01, TWL_PWMA_PWMAON);
-       twl_i2c_write_u8(TWL4030_MODULE_PWMA, 0x02, TWL_PWMA_PWMAOFF);
-       bklight_level = 100;
-
-       return 0;
-}
-
-static void omap3evm_panel_cleanup(struct lcd_panel *panel)
-{
-       gpio_free(LCD_PANEL_QVGA);
-       gpio_free(LCD_PANEL_RESB);
-       gpio_free(LCD_PANEL_INI);
-       gpio_free(LCD_PANEL_UD);
-       gpio_free(LCD_PANEL_LR);
-}
-
-static int omap3evm_panel_enable(struct lcd_panel *panel)
-{
-       gpio_set_value(LCD_PANEL_ENABLE_GPIO, 0);
-       return 0;
-}
-
-static void omap3evm_panel_disable(struct lcd_panel *panel)
-{
-       gpio_set_value(LCD_PANEL_ENABLE_GPIO, 1);
-}
-
-static unsigned long omap3evm_panel_get_caps(struct lcd_panel *panel)
-{
-       return 0;
-}
-
-static int omap3evm_bklight_setlevel(struct lcd_panel *panel,
-                                               unsigned int level)
-{
-       u8 c;
-       if ((level >= 0) && (level <= 100)) {
-               c = (125 * (100 - level)) / 100 + 2;
-               twl_i2c_write_u8(TWL4030_MODULE_PWMA, c, TWL_PWMA_PWMAOFF);
-               bklight_level = level;
-       }
-       return 0;
-}
-
-static unsigned int omap3evm_bklight_getlevel(struct lcd_panel *panel)
-{
-       return bklight_level;
-}
-
-static unsigned int omap3evm_bklight_getmaxlevel(struct lcd_panel *panel)
-{
-       return 100;
-}
-
-struct lcd_panel omap3evm_panel = {
-       .name           = "omap3evm",
-       .config         = OMAP_LCDC_PANEL_TFT | OMAP_LCDC_INV_VSYNC |
-                         OMAP_LCDC_INV_HSYNC,
-
-       .bpp            = 16,
-       .data_lines     = 18,
-       .x_res          = 480,
-       .y_res          = 640,
-       .hsw            = 3,            /* hsync_len (4) - 1 */
-       .hfp            = 3,            /* right_margin (4) - 1 */
-       .hbp            = 39,           /* left_margin (40) - 1 */
-       .vsw            = 1,            /* vsync_len (2) - 1 */
-       .vfp            = 2,            /* lower_margin */
-       .vbp            = 7,            /* upper_margin (8) - 1 */
-
-       .pixel_clock    = 26000,
-
-       .init           = omap3evm_panel_init,
-       .cleanup        = omap3evm_panel_cleanup,
-       .enable         = omap3evm_panel_enable,
-       .disable        = omap3evm_panel_disable,
-       .get_caps       = omap3evm_panel_get_caps,
-       .set_bklight_level      = omap3evm_bklight_setlevel,
-       .get_bklight_level      = omap3evm_bklight_getlevel,
-       .get_bklight_max        = omap3evm_bklight_getmaxlevel,
-};
-
-static int omap3evm_panel_probe(struct platform_device *pdev)
-{
-       omapfb_register_panel(&omap3evm_panel);
-       return 0;
-}
-
-static int omap3evm_panel_remove(struct platform_device *pdev)
-{
-       return 0;
-}
-
-static int omap3evm_panel_suspend(struct platform_device *pdev,
-                                  pm_message_t mesg)
-{
-       return 0;
-}
-
-static int omap3evm_panel_resume(struct platform_device *pdev)
-{
-       return 0;
-}
-
-struct platform_driver omap3evm_panel_driver = {
-       .probe          = omap3evm_panel_probe,
-       .remove         = omap3evm_panel_remove,
-       .suspend        = omap3evm_panel_suspend,
-       .resume         = omap3evm_panel_resume,
-       .driver         = {
-               .name   = "omap3evm_lcd",
-               .owner  = THIS_MODULE,
-       },
-};
-
-static int __init omap3evm_panel_drv_init(void)
-{
-       return platform_driver_register(&omap3evm_panel_driver);
-}
-
-static void __exit omap3evm_panel_drv_exit(void)
-{
-       platform_driver_unregister(&omap3evm_panel_driver);
-}
-
-module_init(omap3evm_panel_drv_init);
-module_exit(omap3evm_panel_drv_exit);
diff --git a/drivers/video/omap/lcd_overo.c b/drivers/video/omap/lcd_overo.c
deleted file mode 100644 (file)
index b8fd5b2..0000000
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * LCD panel support for the Gumstix Overo
- *
- * Author: Steve Sakoman <steve@sakoman.com>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- *
- */
-
-#include <linux/module.h>
-#include <linux/platform_device.h>
-#include <linux/i2c/twl.h>
-
-#include <asm/gpio.h>
-#include <plat/mux.h>
-#include <asm/mach-types.h>
-
-#include "omapfb.h"
-
-#define LCD_ENABLE       144
-
-static int overo_panel_init(struct lcd_panel *panel,
-                               struct omapfb_device *fbdev)
-{
-       if ((gpio_request(LCD_ENABLE, "LCD_ENABLE") == 0) &&
-           (gpio_direction_output(LCD_ENABLE, 1) == 0))
-               gpio_export(LCD_ENABLE, 0);
-       else
-               printk(KERN_ERR "could not obtain gpio for LCD_ENABLE\n");
-
-       return 0;
-}
-
-static void overo_panel_cleanup(struct lcd_panel *panel)
-{
-       gpio_free(LCD_ENABLE);
-}
-
-static int overo_panel_enable(struct lcd_panel *panel)
-{
-       gpio_set_value(LCD_ENABLE, 1);
-       return 0;
-}
-
-static void overo_panel_disable(struct lcd_panel *panel)
-{
-       gpio_set_value(LCD_ENABLE, 0);
-}
-
-static unsigned long overo_panel_get_caps(struct lcd_panel *panel)
-{
-       return 0;
-}
-
-struct lcd_panel overo_panel = {
-       .name           = "overo",
-       .config         = OMAP_LCDC_PANEL_TFT,
-       .bpp            = 16,
-       .data_lines     = 24,
-
-#if defined CONFIG_FB_OMAP_031M3R
-
-       /* 640 x 480 @ 60 Hz  Reduced blanking VESA CVT 0.31M3-R */
-       .x_res          = 640,
-       .y_res          = 480,
-       .hfp            = 48,
-       .hsw            = 32,
-       .hbp            = 80,
-       .vfp            = 3,
-       .vsw            = 4,
-       .vbp            = 7,
-       .pixel_clock    = 23500,
-
-#elif defined CONFIG_FB_OMAP_048M3R
-
-       /* 800 x 600 @ 60 Hz  Reduced blanking VESA CVT 0.48M3-R */
-       .x_res          = 800,
-       .y_res          = 600,
-       .hfp            = 48,
-       .hsw            = 32,
-       .hbp            = 80,
-       .vfp            = 3,
-       .vsw            = 4,
-       .vbp            = 11,
-       .pixel_clock    = 35500,
-
-#elif defined CONFIG_FB_OMAP_079M3R
-
-       /* 1024 x 768 @ 60 Hz  Reduced blanking VESA CVT 0.79M3-R */
-       .x_res          = 1024,
-       .y_res          = 768,
-       .hfp            = 48,
-       .hsw            = 32,
-       .hbp            = 80,
-       .vfp            = 3,
-       .vsw            = 4,
-       .vbp            = 15,
-       .pixel_clock    = 56000,
-
-#elif defined CONFIG_FB_OMAP_092M9R
-
-       /* 1280 x 720 @ 60 Hz  Reduced blanking VESA CVT 0.92M9-R */
-       .x_res          = 1280,
-       .y_res          = 720,
-       .hfp            = 48,
-       .hsw            = 32,
-       .hbp            = 80,
-       .vfp            = 3,
-       .vsw            = 5,
-       .vbp            = 13,
-       .pixel_clock    = 64000,
-
-#else
-
-       /* use 640 x 480 if no config option */
-       /* 640 x 480 @ 60 Hz  Reduced blanking VESA CVT 0.31M3-R */
-       .x_res          = 640,
-       .y_res          = 480,
-       .hfp            = 48,
-       .hsw            = 32,
-       .hbp            = 80,
-       .vfp            = 3,
-       .vsw            = 4,
-       .vbp            = 7,
-       .pixel_clock    = 23500,
-
-#endif
-
-       .init           = overo_panel_init,
-       .cleanup        = overo_panel_cleanup,
-       .enable         = overo_panel_enable,
-       .disable        = overo_panel_disable,
-       .get_caps       = overo_panel_get_caps,
-};
-
-static int overo_panel_probe(struct platform_device *pdev)
-{
-       omapfb_register_panel(&overo_panel);
-       return 0;
-}
-
-static int overo_panel_remove(struct platform_device *pdev)
-{
-       /* omapfb does not have unregister_panel */
-       return 0;
-}
-
-static struct platform_driver overo_panel_driver = {
-       .probe          = overo_panel_probe,
-       .remove         = overo_panel_remove,
-       .driver         = {
-               .name   = "overo_lcd",
-               .owner  = THIS_MODULE,
-       },
-};
-
-static int __init overo_panel_drv_init(void)
-{
-       return platform_driver_register(&overo_panel_driver);
-}
-
-static void __exit overo_panel_drv_exit(void)
-{
-       platform_driver_unregister(&overo_panel_driver);
-}
-
-module_init(overo_panel_drv_init);
-module_exit(overo_panel_drv_exit);
index 609a28073178678f87069909d950745a48000a0a..8d8e1fe1901c16248f0d75743d9625580e9af3c3 100644 (file)
@@ -10,6 +10,13 @@ config PANEL_GENERIC_DPI
          Supports LCD Panel used in TI SDP3430 and EVM boards,
          OMAP3517 EVM boards and CM-T35.
 
+config PANEL_DVI
+       tristate "DVI output"
+       depends on OMAP2_DSS_DPI
+       help
+         Driver for external monitors, connected via DVI. The driver uses i2c
+         to read EDID information from the monitor.
+
 config PANEL_LGPHILIPS_LB035Q02
        tristate "LG.Philips LB035Q02 LCD Panel"
        depends on OMAP2_DSS_DPI && SPI
@@ -19,20 +26,30 @@ config PANEL_LGPHILIPS_LB035Q02
 config PANEL_SHARP_LS037V7DW01
         tristate "Sharp LS037V7DW01 LCD Panel"
         depends on OMAP2_DSS_DPI
-        select BACKLIGHT_CLASS_DEVICE
+        depends on BACKLIGHT_CLASS_DEVICE
         help
           LCD Panel used in TI's SDP3430 and EVM boards
 
 config PANEL_NEC_NL8048HL11_01B
        tristate "NEC NL8048HL11-01B Panel"
        depends on OMAP2_DSS_DPI
+       depends on SPI
+       depends on BACKLIGHT_CLASS_DEVICE
        help
                This NEC NL8048HL11-01B panel is TFT LCD
                used in the Zoom2/3/3630 sdp boards.
 
+config PANEL_PICODLP
+       tristate "TI PICO DLP mini-projector"
+       depends on OMAP2_DSS && I2C
+       help
+               A mini-projector used in TI's SDP4430 and EVM boards
+               For more info please visit http://www.dlp.com/projector/
+
 config PANEL_TAAL
         tristate "Taal DSI Panel"
         depends on OMAP2_DSS_DSI
+        depends on BACKLIGHT_CLASS_DEVICE
         help
           Taal DSI command mode panel from TPO.
 
@@ -45,7 +62,14 @@ config PANEL_TPO_TD043MTEA1
 config PANEL_ACX565AKM
        tristate "ACX565AKM Panel"
        depends on OMAP2_DSS_SDI && SPI
-       select BACKLIGHT_CLASS_DEVICE
+       depends on BACKLIGHT_CLASS_DEVICE
        help
          This is the LCD panel used on Nokia N900
+
+config PANEL_N8X0
+       tristate "N8X0 Panel"
+       depends on OMAP2_DSS_RFBI && SPI
+       depends on BACKLIGHT_CLASS_DEVICE
+       help
+         This is the LCD panel used on Nokia N8x0
 endmenu
index 0f601ab3abf490fc03473de41859e078d9a6f4ee..fbfafc6eebb4ad4a8556b427f665ff0a1d3eaacc 100644 (file)
@@ -1,8 +1,11 @@
 obj-$(CONFIG_PANEL_GENERIC_DPI) += panel-generic-dpi.o
+obj-$(CONFIG_PANEL_DVI) += panel-dvi.o
 obj-$(CONFIG_PANEL_LGPHILIPS_LB035Q02) += panel-lgphilips-lb035q02.o
 obj-$(CONFIG_PANEL_SHARP_LS037V7DW01) += panel-sharp-ls037v7dw01.o
 obj-$(CONFIG_PANEL_NEC_NL8048HL11_01B) += panel-nec-nl8048hl11-01b.o
 
 obj-$(CONFIG_PANEL_TAAL) += panel-taal.o
+obj-$(CONFIG_PANEL_PICODLP) +=  panel-picodlp.o
 obj-$(CONFIG_PANEL_TPO_TD043MTEA1) += panel-tpo-td043mtea1.o
 obj-$(CONFIG_PANEL_ACX565AKM) += panel-acx565akm.o
+obj-$(CONFIG_PANEL_N8X0) += panel-n8x0.o
diff --git a/drivers/video/omap2/displays/panel-dvi.c b/drivers/video/omap2/displays/panel-dvi.c
new file mode 100644 (file)
index 0000000..03eb14a
--- /dev/null
@@ -0,0 +1,363 @@
+/*
+ * DVI output support
+ *
+ * Copyright (C) 2011 Texas Instruments Inc
+ * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <video/omapdss.h>
+#include <linux/i2c.h>
+#include <drm/drm_edid.h>
+
+#include <video/omap-panel-dvi.h>
+
+static const struct omap_video_timings panel_dvi_default_timings = {
+       .x_res          = 640,
+       .y_res          = 480,
+
+       .pixel_clock    = 23500,
+
+       .hfp            = 48,
+       .hsw            = 32,
+       .hbp            = 80,
+
+       .vfp            = 3,
+       .vsw            = 4,
+       .vbp            = 7,
+};
+
+struct panel_drv_data {
+       struct omap_dss_device *dssdev;
+
+       struct mutex lock;
+};
+
+static inline struct panel_dvi_platform_data
+*get_pdata(const struct omap_dss_device *dssdev)
+{
+       return dssdev->data;
+}
+
+static int panel_dvi_power_on(struct omap_dss_device *dssdev)
+{
+       struct panel_dvi_platform_data *pdata = get_pdata(dssdev);
+       int r;
+
+       if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
+               return 0;
+
+       r = omapdss_dpi_display_enable(dssdev);
+       if (r)
+               goto err0;
+
+       if (pdata->platform_enable) {
+               r = pdata->platform_enable(dssdev);
+               if (r)
+                       goto err1;
+       }
+
+       return 0;
+err1:
+       omapdss_dpi_display_disable(dssdev);
+err0:
+       return r;
+}
+
+static void panel_dvi_power_off(struct omap_dss_device *dssdev)
+{
+       struct panel_dvi_platform_data *pdata = get_pdata(dssdev);
+
+       if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
+               return;
+
+       if (pdata->platform_disable)
+               pdata->platform_disable(dssdev);
+
+       omapdss_dpi_display_disable(dssdev);
+}
+
+static int panel_dvi_probe(struct omap_dss_device *dssdev)
+{
+       struct panel_drv_data *ddata;
+
+       ddata = kzalloc(sizeof(*ddata), GFP_KERNEL);
+       if (!ddata)
+               return -ENOMEM;
+
+       dssdev->panel.timings = panel_dvi_default_timings;
+       dssdev->panel.config = OMAP_DSS_LCD_TFT;
+
+       ddata->dssdev = dssdev;
+       mutex_init(&ddata->lock);
+
+       dev_set_drvdata(&dssdev->dev, ddata);
+
+       return 0;
+}
+
+static void __exit panel_dvi_remove(struct omap_dss_device *dssdev)
+{
+       struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
+
+       mutex_lock(&ddata->lock);
+
+       dev_set_drvdata(&dssdev->dev, NULL);
+
+       mutex_unlock(&ddata->lock);
+
+       kfree(ddata);
+}
+
+static int panel_dvi_enable(struct omap_dss_device *dssdev)
+{
+       struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
+       int r;
+
+       mutex_lock(&ddata->lock);
+
+       r = panel_dvi_power_on(dssdev);
+       if (r == 0)
+               dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
+
+       mutex_unlock(&ddata->lock);
+
+       return r;
+}
+
+static void panel_dvi_disable(struct omap_dss_device *dssdev)
+{
+       struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
+
+       mutex_lock(&ddata->lock);
+
+       panel_dvi_power_off(dssdev);
+
+       dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
+
+       mutex_unlock(&ddata->lock);
+}
+
+static int panel_dvi_suspend(struct omap_dss_device *dssdev)
+{
+       struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
+
+       mutex_lock(&ddata->lock);
+
+       panel_dvi_power_off(dssdev);
+
+       dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
+
+       mutex_unlock(&ddata->lock);
+
+       return 0;
+}
+
+static int panel_dvi_resume(struct omap_dss_device *dssdev)
+{
+       struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
+       int r;
+
+       mutex_lock(&ddata->lock);
+
+       r = panel_dvi_power_on(dssdev);
+       if (r == 0)
+               dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
+
+       mutex_unlock(&ddata->lock);
+
+       return r;
+}
+
+static void panel_dvi_set_timings(struct omap_dss_device *dssdev,
+               struct omap_video_timings *timings)
+{
+       struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
+
+       mutex_lock(&ddata->lock);
+       dpi_set_timings(dssdev, timings);
+       mutex_unlock(&ddata->lock);
+}
+
+static void panel_dvi_get_timings(struct omap_dss_device *dssdev,
+               struct omap_video_timings *timings)
+{
+       struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
+
+       mutex_lock(&ddata->lock);
+       *timings = dssdev->panel.timings;
+       mutex_unlock(&ddata->lock);
+}
+
+static int panel_dvi_check_timings(struct omap_dss_device *dssdev,
+               struct omap_video_timings *timings)
+{
+       struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
+       int r;
+
+       mutex_lock(&ddata->lock);
+       r = dpi_check_timings(dssdev, timings);
+       mutex_unlock(&ddata->lock);
+
+       return r;
+}
+
+
+static int panel_dvi_ddc_read(struct i2c_adapter *adapter,
+               unsigned char *buf, u16 count, u8 offset)
+{
+       int r, retries;
+
+       for (retries = 3; retries > 0; retries--) {
+               struct i2c_msg msgs[] = {
+                       {
+                               .addr   = DDC_ADDR,
+                               .flags  = 0,
+                               .len    = 1,
+                               .buf    = &offset,
+                       }, {
+                               .addr   = DDC_ADDR,
+                               .flags  = I2C_M_RD,
+                               .len    = count,
+                               .buf    = buf,
+                       }
+               };
+
+               r = i2c_transfer(adapter, msgs, 2);
+               if (r == 2)
+                       return 0;
+
+               if (r != -EAGAIN)
+                       break;
+       }
+
+       return r < 0 ? r : -EIO;
+}
+
+static int panel_dvi_read_edid(struct omap_dss_device *dssdev,
+               u8 *edid, int len)
+{
+       struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
+       struct panel_dvi_platform_data *pdata = get_pdata(dssdev);
+       struct i2c_adapter *adapter;
+       int r, l, bytes_read;
+
+       mutex_lock(&ddata->lock);
+
+       if (pdata->i2c_bus_num == 0) {
+               r = -ENODEV;
+               goto err;
+       }
+
+       adapter = i2c_get_adapter(pdata->i2c_bus_num);
+       if (!adapter) {
+               dev_err(&dssdev->dev, "Failed to get I2C adapter, bus %d\n",
+                               pdata->i2c_bus_num);
+               r = -EINVAL;
+               goto err;
+       }
+
+       l = min(EDID_LENGTH, len);
+       r = panel_dvi_ddc_read(adapter, edid, l, 0);
+       if (r)
+               goto err;
+
+       bytes_read = l;
+
+       /* if there are extensions, read second block */
+       if (len > EDID_LENGTH && edid[0x7e] > 0) {
+               l = min(EDID_LENGTH, len - EDID_LENGTH);
+
+               r = panel_dvi_ddc_read(adapter, edid + EDID_LENGTH,
+                               l, EDID_LENGTH);
+               if (r)
+                       goto err;
+
+               bytes_read += l;
+       }
+
+       mutex_unlock(&ddata->lock);
+
+       return bytes_read;
+
+err:
+       mutex_unlock(&ddata->lock);
+       return r;
+}
+
+static bool panel_dvi_detect(struct omap_dss_device *dssdev)
+{
+       struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
+       struct panel_dvi_platform_data *pdata = get_pdata(dssdev);
+       struct i2c_adapter *adapter;
+       unsigned char out;
+       int r;
+
+       mutex_lock(&ddata->lock);
+
+       if (pdata->i2c_bus_num == 0)
+               goto out;
+
+       adapter = i2c_get_adapter(pdata->i2c_bus_num);
+       if (!adapter)
+               goto out;
+
+       r = panel_dvi_ddc_read(adapter, &out, 1, 0);
+
+       mutex_unlock(&ddata->lock);
+
+       return r == 0;
+
+out:
+       mutex_unlock(&ddata->lock);
+       return true;
+}
+
+static struct omap_dss_driver panel_dvi_driver = {
+       .probe          = panel_dvi_probe,
+       .remove         = __exit_p(panel_dvi_remove),
+
+       .enable         = panel_dvi_enable,
+       .disable        = panel_dvi_disable,
+       .suspend        = panel_dvi_suspend,
+       .resume         = panel_dvi_resume,
+
+       .set_timings    = panel_dvi_set_timings,
+       .get_timings    = panel_dvi_get_timings,
+       .check_timings  = panel_dvi_check_timings,
+
+       .read_edid      = panel_dvi_read_edid,
+       .detect         = panel_dvi_detect,
+
+       .driver         = {
+               .name   = "dvi",
+               .owner  = THIS_MODULE,
+       },
+};
+
+static int __init panel_dvi_init(void)
+{
+       return omap_dss_register_driver(&panel_dvi_driver);
+}
+
+static void __exit panel_dvi_exit(void)
+{
+       omap_dss_unregister_driver(&panel_dvi_driver);
+}
+
+module_init(panel_dvi_init);
+module_exit(panel_dvi_exit);
+MODULE_LICENSE("GPL");
index 9c90f75653fb3d262489d3c9e78f04282bd8d7e2..519c47d2057f8980f6370b9ef12deb0f7b6d2955 100644 (file)
@@ -58,30 +58,6 @@ struct panel_config {
 
 /* Panel configurations */
 static struct panel_config generic_dpi_panels[] = {
-       /* Generic Panel */
-       {
-               {
-                       .x_res          = 640,
-                       .y_res          = 480,
-
-                       .pixel_clock    = 23500,
-
-                       .hfp            = 48,
-                       .hsw            = 32,
-                       .hbp            = 80,
-
-                       .vfp            = 3,
-                       .vsw            = 4,
-                       .vbp            = 7,
-               },
-               .acbi                   = 0x0,
-               .acb                    = 0x0,
-               .config                 = OMAP_DSS_LCD_TFT,
-               .power_on_delay         = 0,
-               .power_off_delay        = 0,
-               .name                   = "generic",
-       },
-
        /* Sharp LQ043T1DG01 */
        {
                {
@@ -232,6 +208,95 @@ static struct panel_config generic_dpi_panels[] = {
                .power_off_delay        = 0,
                .name                   = "powertip_ph480272t",
        },
+
+       /* Innolux AT070TN83 */
+       {
+               {
+                       .x_res          = 800,
+                       .y_res          = 480,
+
+                       .pixel_clock    = 40000,
+
+                       .hsw            = 48,
+                       .hfp            = 1,
+                       .hbp            = 1,
+
+                       .vsw            = 3,
+                       .vfp            = 12,
+                       .vbp            = 25,
+               },
+               .acbi                   = 0x0,
+               .acb                    = 0x28,
+               .config                 = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
+                                         OMAP_DSS_LCD_IHS,
+               .power_on_delay         = 0,
+               .power_off_delay        = 0,
+               .name                   = "innolux_at070tn83",
+       },
+
+       /* NEC NL2432DR22-11B */
+       {
+               {
+                       .x_res          = 240,
+                       .y_res          = 320,
+
+                       .pixel_clock    = 5400,
+
+                       .hsw            = 3,
+                       .hfp            = 3,
+                       .hbp            = 39,
+
+                       .vsw            = 1,
+                       .vfp            = 2,
+                       .vbp            = 7,
+               },
+               .config                 = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
+                                               OMAP_DSS_LCD_IHS,
+               .name                   = "nec_nl2432dr22-11b",
+       },
+
+       /* Unknown panel used in OMAP H4 */
+       {
+               {
+                       .x_res          = 240,
+                       .y_res          = 320,
+
+                       .pixel_clock    = 6250,
+
+                       .hsw            = 15,
+                       .hfp            = 15,
+                       .hbp            = 60,
+
+                       .vsw            = 1,
+                       .vfp            = 1,
+                       .vbp            = 1,
+               },
+               .config                 = OMAP_DSS_LCD_TFT,
+
+               .name                   = "h4",
+       },
+
+       /* Unknown panel used in Samsung OMAP2 Apollon */
+       {
+               {
+                       .x_res          = 480,
+                       .y_res          = 272,
+
+                       .pixel_clock    = 6250,
+
+                       .hsw            = 41,
+                       .hfp            = 2,
+                       .hbp            = 2,
+
+                       .vsw            = 10,
+                       .vfp            = 2,
+                       .vbp            = 2,
+               },
+               .config                 = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
+                                               OMAP_DSS_LCD_IHS,
+
+               .name                   = "apollon",
+       },
 };
 
 struct panel_drv_data {
diff --git a/drivers/video/omap2/displays/panel-n8x0.c b/drivers/video/omap2/displays/panel-n8x0.c
new file mode 100644 (file)
index 0000000..150e8ba
--- /dev/null
@@ -0,0 +1,747 @@
+/* #define DEBUG */
+
+#include <linux/module.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/gpio.h>
+#include <linux/spi/spi.h>
+#include <linux/backlight.h>
+#include <linux/fb.h>
+
+#include <video/omapdss.h>
+#include <video/omap-panel-n8x0.h>
+
+#define BLIZZARD_REV_CODE                      0x00
+#define BLIZZARD_CONFIG                        0x02
+#define BLIZZARD_PLL_DIV                       0x04
+#define BLIZZARD_PLL_LOCK_RANGE                0x06
+#define BLIZZARD_PLL_CLOCK_SYNTH_0             0x08
+#define BLIZZARD_PLL_CLOCK_SYNTH_1             0x0a
+#define BLIZZARD_PLL_MODE                      0x0c
+#define BLIZZARD_CLK_SRC                       0x0e
+#define BLIZZARD_MEM_BANK0_ACTIVATE            0x10
+#define BLIZZARD_MEM_BANK0_STATUS              0x14
+#define BLIZZARD_PANEL_CONFIGURATION           0x28
+#define BLIZZARD_HDISP                         0x2a
+#define BLIZZARD_HNDP                          0x2c
+#define BLIZZARD_VDISP0                        0x2e
+#define BLIZZARD_VDISP1                        0x30
+#define BLIZZARD_VNDP                          0x32
+#define BLIZZARD_HSW                           0x34
+#define BLIZZARD_VSW                           0x38
+#define BLIZZARD_DISPLAY_MODE                  0x68
+#define BLIZZARD_INPUT_WIN_X_START_0           0x6c
+#define BLIZZARD_DATA_SOURCE_SELECT            0x8e
+#define BLIZZARD_DISP_MEM_DATA_PORT            0x90
+#define BLIZZARD_DISP_MEM_READ_ADDR0           0x92
+#define BLIZZARD_POWER_SAVE                    0xE6
+#define BLIZZARD_NDISP_CTRL_STATUS             0xE8
+
+/* Data source select */
+/* For S1D13745 */
+#define BLIZZARD_SRC_WRITE_LCD_BACKGROUND      0x00
+#define BLIZZARD_SRC_WRITE_LCD_DESTRUCTIVE     0x01
+#define BLIZZARD_SRC_WRITE_OVERLAY_ENABLE      0x04
+#define BLIZZARD_SRC_DISABLE_OVERLAY           0x05
+/* For S1D13744 */
+#define BLIZZARD_SRC_WRITE_LCD                 0x00
+#define BLIZZARD_SRC_BLT_LCD                   0x06
+
+#define BLIZZARD_COLOR_RGB565                  0x01
+#define BLIZZARD_COLOR_YUV420                  0x09
+
+#define BLIZZARD_VERSION_S1D13745              0x01    /* Hailstorm */
+#define BLIZZARD_VERSION_S1D13744              0x02    /* Blizzard */
+
+#define MIPID_CMD_READ_DISP_ID         0x04
+#define MIPID_CMD_READ_RED             0x06
+#define MIPID_CMD_READ_GREEN           0x07
+#define MIPID_CMD_READ_BLUE            0x08
+#define MIPID_CMD_READ_DISP_STATUS     0x09
+#define MIPID_CMD_RDDSDR               0x0F
+#define MIPID_CMD_SLEEP_IN             0x10
+#define MIPID_CMD_SLEEP_OUT            0x11
+#define MIPID_CMD_DISP_OFF             0x28
+#define MIPID_CMD_DISP_ON              0x29
+
+static struct panel_drv_data {
+       struct mutex lock;
+
+       struct omap_dss_device *dssdev;
+       struct spi_device *spidev;
+       struct backlight_device *bldev;
+
+       int blizzard_ver;
+} s_drv_data;
+
+
+static inline
+struct panel_n8x0_data *get_board_data(const struct omap_dss_device *dssdev)
+{
+       return dssdev->data;
+}
+
+static inline
+struct panel_drv_data *get_drv_data(const struct omap_dss_device *dssdev)
+{
+       return &s_drv_data;
+}
+
+
+static inline void blizzard_cmd(u8 cmd)
+{
+       omap_rfbi_write_command(&cmd, 1);
+}
+
+static inline void blizzard_write(u8 cmd, const u8 *buf, int len)
+{
+       omap_rfbi_write_command(&cmd, 1);
+       omap_rfbi_write_data(buf, len);
+}
+
+static inline void blizzard_read(u8 cmd, u8 *buf, int len)
+{
+       omap_rfbi_write_command(&cmd, 1);
+       omap_rfbi_read_data(buf, len);
+}
+
+static u8 blizzard_read_reg(u8 cmd)
+{
+       u8 data;
+       blizzard_read(cmd, &data, 1);
+       return data;
+}
+
+static void blizzard_ctrl_setup_update(struct omap_dss_device *dssdev,
+               int x, int y, int w, int h)
+{
+       struct panel_drv_data *ddata = get_drv_data(dssdev);
+       u8 tmp[18];
+       int x_end, y_end;
+
+       x_end = x + w - 1;
+       y_end = y + h - 1;
+
+       tmp[0] = x;
+       tmp[1] = x >> 8;
+       tmp[2] = y;
+       tmp[3] = y >> 8;
+       tmp[4] = x_end;
+       tmp[5] = x_end >> 8;
+       tmp[6] = y_end;
+       tmp[7] = y_end >> 8;
+
+       /* scaling? */
+       tmp[8] = x;
+       tmp[9] = x >> 8;
+       tmp[10] = y;
+       tmp[11] = y >> 8;
+       tmp[12] = x_end;
+       tmp[13] = x_end >> 8;
+       tmp[14] = y_end;
+       tmp[15] = y_end >> 8;
+
+       tmp[16] = BLIZZARD_COLOR_RGB565;
+
+       if (ddata->blizzard_ver == BLIZZARD_VERSION_S1D13745)
+               tmp[17] = BLIZZARD_SRC_WRITE_LCD_BACKGROUND;
+       else
+               tmp[17] = ddata->blizzard_ver == BLIZZARD_VERSION_S1D13744 ?
+                       BLIZZARD_SRC_WRITE_LCD :
+                       BLIZZARD_SRC_WRITE_LCD_DESTRUCTIVE;
+
+       omap_rfbi_configure(dssdev, 16, 8);
+
+       blizzard_write(BLIZZARD_INPUT_WIN_X_START_0, tmp, 18);
+
+       omap_rfbi_configure(dssdev, 16, 16);
+}
+
+static void mipid_transfer(struct spi_device *spi, int cmd, const u8 *wbuf,
+               int wlen, u8 *rbuf, int rlen)
+{
+       struct spi_message      m;
+       struct spi_transfer     *x, xfer[4];
+       u16                     w;
+       int                     r;
+
+       spi_message_init(&m);
+
+       memset(xfer, 0, sizeof(xfer));
+       x = &xfer[0];
+
+       cmd &=  0xff;
+       x->tx_buf               = &cmd;
+       x->bits_per_word        = 9;
+       x->len                  = 2;
+       spi_message_add_tail(x, &m);
+
+       if (wlen) {
+               x++;
+               x->tx_buf               = wbuf;
+               x->len                  = wlen;
+               x->bits_per_word        = 9;
+               spi_message_add_tail(x, &m);
+       }
+
+       if (rlen) {
+               x++;
+               x->rx_buf       = &w;
+               x->len          = 1;
+               spi_message_add_tail(x, &m);
+
+               if (rlen > 1) {
+                       /* Arrange for the extra clock before the first
+                        * data bit.
+                        */
+                       x->bits_per_word = 9;
+                       x->len           = 2;
+
+                       x++;
+                       x->rx_buf        = &rbuf[1];
+                       x->len           = rlen - 1;
+                       spi_message_add_tail(x, &m);
+               }
+       }
+
+       r = spi_sync(spi, &m);
+       if (r < 0)
+               dev_dbg(&spi->dev, "spi_sync %d\n", r);
+
+       if (rlen)
+               rbuf[0] = w & 0xff;
+}
+
+static inline void mipid_cmd(struct spi_device *spi, int cmd)
+{
+       mipid_transfer(spi, cmd, NULL, 0, NULL, 0);
+}
+
+static inline void mipid_write(struct spi_device *spi,
+               int reg, const u8 *buf, int len)
+{
+       mipid_transfer(spi, reg, buf, len, NULL, 0);
+}
+
+static inline void mipid_read(struct spi_device *spi,
+               int reg, u8 *buf, int len)
+{
+       mipid_transfer(spi, reg, NULL, 0, buf, len);
+}
+
+static void set_data_lines(struct spi_device *spi, int data_lines)
+{
+       u16 par;
+
+       switch (data_lines) {
+       case 16:
+               par = 0x150;
+               break;
+       case 18:
+               par = 0x160;
+               break;
+       case 24:
+               par = 0x170;
+               break;
+       }
+
+       mipid_write(spi, 0x3a, (u8 *)&par, 2);
+}
+
+static void send_init_string(struct spi_device *spi)
+{
+       u16 initpar[] = { 0x0102, 0x0100, 0x0100 };
+       mipid_write(spi, 0xc2, (u8 *)initpar, sizeof(initpar));
+}
+
+static void send_display_on(struct spi_device *spi)
+{
+       mipid_cmd(spi, MIPID_CMD_DISP_ON);
+}
+
+static void send_display_off(struct spi_device *spi)
+{
+       mipid_cmd(spi, MIPID_CMD_DISP_OFF);
+}
+
+static void send_sleep_out(struct spi_device *spi)
+{
+       mipid_cmd(spi, MIPID_CMD_SLEEP_OUT);
+       msleep(120);
+}
+
+static void send_sleep_in(struct spi_device *spi)
+{
+       mipid_cmd(spi, MIPID_CMD_SLEEP_IN);
+       msleep(50);
+}
+
+static int n8x0_panel_power_on(struct omap_dss_device *dssdev)
+{
+       int r;
+       struct panel_n8x0_data *bdata = get_board_data(dssdev);
+       struct panel_drv_data *ddata = get_drv_data(dssdev);
+       struct spi_device *spi = ddata->spidev;
+       u8 rev, conf;
+       u8 display_id[3];
+       const char *panel_name;
+
+       if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
+               return 0;
+
+       gpio_direction_output(bdata->ctrl_pwrdown, 1);
+
+       if (bdata->platform_enable) {
+               r = bdata->platform_enable(dssdev);
+               if (r)
+                       goto err_plat_en;
+       }
+
+       r = omapdss_rfbi_display_enable(dssdev);
+       if (r)
+               goto err_rfbi_en;
+
+       rev = blizzard_read_reg(BLIZZARD_REV_CODE);
+       conf = blizzard_read_reg(BLIZZARD_CONFIG);
+
+       switch (rev & 0xfc) {
+       case 0x9c:
+               ddata->blizzard_ver = BLIZZARD_VERSION_S1D13744;
+               dev_info(&dssdev->dev, "s1d13744 LCD controller rev %d "
+                       "initialized (CNF pins %x)\n", rev & 0x03, conf & 0x07);
+               break;
+       case 0xa4:
+               ddata->blizzard_ver = BLIZZARD_VERSION_S1D13745;
+               dev_info(&dssdev->dev, "s1d13745 LCD controller rev %d "
+                       "initialized (CNF pins %x)\n", rev & 0x03, conf & 0x07);
+               break;
+       default:
+               dev_err(&dssdev->dev, "invalid s1d1374x revision %02x\n", rev);
+               r = -ENODEV;
+               goto err_inv_chip;
+       }
+
+       /* panel */
+
+       gpio_direction_output(bdata->panel_reset, 1);
+
+       mipid_read(spi, MIPID_CMD_READ_DISP_ID, display_id, 3);
+       dev_dbg(&spi->dev, "MIPI display ID: %02x%02x%02x\n",
+                       display_id[0], display_id[1], display_id[2]);
+
+       switch (display_id[0]) {
+       case 0x45:
+               panel_name = "lph8923";
+               break;
+       case 0x83:
+               panel_name = "ls041y3";
+               break;
+       default:
+               dev_err(&dssdev->dev, "invalid display ID 0x%x\n",
+                               display_id[0]);
+               r = -ENODEV;
+               goto err_inv_panel;
+       }
+
+       dev_info(&dssdev->dev, "%s rev %02x LCD detected\n",
+                       panel_name, display_id[1]);
+
+       send_sleep_out(spi);
+       send_init_string(spi);
+       set_data_lines(spi, 24);
+       send_display_on(spi);
+
+       return 0;
+
+err_inv_panel:
+       /*
+        * HACK: we should turn off the panel here, but there is some problem
+        * with the initialization sequence, and we fail to init the panel if we
+        * have turned it off
+        */
+       /* gpio_direction_output(bdata->panel_reset, 0); */
+err_inv_chip:
+       omapdss_rfbi_display_disable(dssdev);
+err_rfbi_en:
+       if (bdata->platform_disable)
+               bdata->platform_disable(dssdev);
+err_plat_en:
+       gpio_direction_output(bdata->ctrl_pwrdown, 0);
+       return r;
+}
+
+static void n8x0_panel_power_off(struct omap_dss_device *dssdev)
+{
+       struct panel_n8x0_data *bdata = get_board_data(dssdev);
+       struct panel_drv_data *ddata = get_drv_data(dssdev);
+       struct spi_device *spi = ddata->spidev;
+
+       if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
+               return;
+
+       send_display_off(spi);
+       send_sleep_in(spi);
+
+       if (bdata->platform_disable)
+               bdata->platform_disable(dssdev);
+
+       /*
+        * HACK: we should turn off the panel here, but there is some problem
+        * with the initialization sequence, and we fail to init the panel if we
+        * have turned it off
+        */
+       /* gpio_direction_output(bdata->panel_reset, 0); */
+       gpio_direction_output(bdata->ctrl_pwrdown, 0);
+       omapdss_rfbi_display_disable(dssdev);
+}
+
+static const struct rfbi_timings n8x0_panel_timings = {
+       .cs_on_time     = 0,
+
+       .we_on_time     = 9000,
+       .we_off_time    = 18000,
+       .we_cycle_time  = 36000,
+
+       .re_on_time     = 9000,
+       .re_off_time    = 27000,
+       .re_cycle_time  = 36000,
+
+       .access_time    = 27000,
+       .cs_off_time    = 36000,
+
+       .cs_pulse_width = 0,
+};
+
+static int n8x0_bl_update_status(struct backlight_device *dev)
+{
+       struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev);
+       struct panel_n8x0_data *bdata = get_board_data(dssdev);
+       struct panel_drv_data *ddata = get_drv_data(dssdev);
+       int r;
+       int level;
+
+       mutex_lock(&ddata->lock);
+
+       if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
+                       dev->props.power == FB_BLANK_UNBLANK)
+               level = dev->props.brightness;
+       else
+               level = 0;
+
+       dev_dbg(&dssdev->dev, "update brightness to %d\n", level);
+
+       if (!bdata->set_backlight)
+               r = -EINVAL;
+       else
+               r = bdata->set_backlight(dssdev, level);
+
+       mutex_unlock(&ddata->lock);
+
+       return r;
+}
+
+static int n8x0_bl_get_intensity(struct backlight_device *dev)
+{
+       if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
+                       dev->props.power == FB_BLANK_UNBLANK)
+               return dev->props.brightness;
+
+       return 0;
+}
+
+static const struct backlight_ops n8x0_bl_ops = {
+       .get_brightness = n8x0_bl_get_intensity,
+       .update_status  = n8x0_bl_update_status,
+};
+
+static int n8x0_panel_probe(struct omap_dss_device *dssdev)
+{
+       struct panel_n8x0_data *bdata = get_board_data(dssdev);
+       struct panel_drv_data *ddata;
+       struct backlight_device *bldev;
+       struct backlight_properties props;
+       int r;
+
+       dev_dbg(&dssdev->dev, "probe\n");
+
+       if (!bdata)
+               return -EINVAL;
+
+       s_drv_data.dssdev = dssdev;
+
+       ddata = &s_drv_data;
+
+       mutex_init(&ddata->lock);
+
+       dssdev->panel.config = OMAP_DSS_LCD_TFT;
+       dssdev->panel.timings.x_res = 800;
+       dssdev->panel.timings.y_res = 480;
+       dssdev->ctrl.pixel_size = 16;
+       dssdev->ctrl.rfbi_timings = n8x0_panel_timings;
+
+       memset(&props, 0, sizeof(props));
+       props.max_brightness = 127;
+       props.type = BACKLIGHT_PLATFORM;
+       bldev = backlight_device_register(dev_name(&dssdev->dev), &dssdev->dev,
+                       dssdev, &n8x0_bl_ops, &props);
+       if (IS_ERR(bldev)) {
+               r = PTR_ERR(bldev);
+               dev_err(&dssdev->dev, "register backlight failed\n");
+               return r;
+       }
+
+       ddata->bldev = bldev;
+
+       bldev->props.fb_blank = FB_BLANK_UNBLANK;
+       bldev->props.power = FB_BLANK_UNBLANK;
+       bldev->props.brightness = 127;
+
+       n8x0_bl_update_status(bldev);
+
+       return 0;
+}
+
+static void n8x0_panel_remove(struct omap_dss_device *dssdev)
+{
+       struct panel_drv_data *ddata = get_drv_data(dssdev);
+       struct backlight_device *bldev;
+
+       dev_dbg(&dssdev->dev, "remove\n");
+
+       bldev = ddata->bldev;
+       bldev->props.power = FB_BLANK_POWERDOWN;
+       n8x0_bl_update_status(bldev);
+       backlight_device_unregister(bldev);
+
+       dev_set_drvdata(&dssdev->dev, NULL);
+}
+
+static int n8x0_panel_enable(struct omap_dss_device *dssdev)
+{
+       struct panel_drv_data *ddata = get_drv_data(dssdev);
+       int r;
+
+       dev_dbg(&dssdev->dev, "enable\n");
+
+       mutex_lock(&ddata->lock);
+
+       rfbi_bus_lock();
+
+       r = n8x0_panel_power_on(dssdev);
+
+       rfbi_bus_unlock();
+
+       if (r) {
+               mutex_unlock(&ddata->lock);
+               return r;
+       }
+
+       dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
+
+       mutex_unlock(&ddata->lock);
+
+       return 0;
+}
+
+static void n8x0_panel_disable(struct omap_dss_device *dssdev)
+{
+       struct panel_drv_data *ddata = get_drv_data(dssdev);
+
+       dev_dbg(&dssdev->dev, "disable\n");
+
+       mutex_lock(&ddata->lock);
+
+       rfbi_bus_lock();
+
+       n8x0_panel_power_off(dssdev);
+
+       rfbi_bus_unlock();
+
+       dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
+
+       mutex_unlock(&ddata->lock);
+}
+
+static int n8x0_panel_suspend(struct omap_dss_device *dssdev)
+{
+       struct panel_drv_data *ddata = get_drv_data(dssdev);
+
+       dev_dbg(&dssdev->dev, "suspend\n");
+
+       mutex_lock(&ddata->lock);
+
+       rfbi_bus_lock();
+
+       n8x0_panel_power_off(dssdev);
+
+       rfbi_bus_unlock();
+
+       dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
+
+       mutex_unlock(&ddata->lock);
+
+       return 0;
+}
+
+static int n8x0_panel_resume(struct omap_dss_device *dssdev)
+{
+       struct panel_drv_data *ddata = get_drv_data(dssdev);
+       int r;
+
+       dev_dbg(&dssdev->dev, "resume\n");
+
+       mutex_lock(&ddata->lock);
+
+       rfbi_bus_lock();
+
+       r = n8x0_panel_power_on(dssdev);
+
+       rfbi_bus_unlock();
+
+       if (r) {
+               mutex_unlock(&ddata->lock);
+               return r;
+       }
+
+       dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
+
+       mutex_unlock(&ddata->lock);
+
+       return 0;
+}
+
+static void n8x0_panel_get_timings(struct omap_dss_device *dssdev,
+               struct omap_video_timings *timings)
+{
+       *timings = dssdev->panel.timings;
+}
+
+static void n8x0_panel_get_resolution(struct omap_dss_device *dssdev,
+               u16 *xres, u16 *yres)
+{
+       *xres = dssdev->panel.timings.x_res;
+       *yres = dssdev->panel.timings.y_res;
+}
+
+static void update_done(void *data)
+{
+       rfbi_bus_unlock();
+}
+
+static int n8x0_panel_update(struct omap_dss_device *dssdev,
+               u16 x, u16 y, u16 w, u16 h)
+{
+       struct panel_drv_data *ddata = get_drv_data(dssdev);
+
+       dev_dbg(&dssdev->dev, "update\n");
+
+       mutex_lock(&ddata->lock);
+       rfbi_bus_lock();
+
+       omap_rfbi_prepare_update(dssdev, &x, &y, &w, &h);
+
+       blizzard_ctrl_setup_update(dssdev, x, y, w, h);
+
+       omap_rfbi_update(dssdev, x, y, w, h, update_done, NULL);
+
+       mutex_unlock(&ddata->lock);
+
+       return 0;
+}
+
+static int n8x0_panel_sync(struct omap_dss_device *dssdev)
+{
+       struct panel_drv_data *ddata = get_drv_data(dssdev);
+
+       dev_dbg(&dssdev->dev, "sync\n");
+
+       mutex_lock(&ddata->lock);
+       rfbi_bus_lock();
+       rfbi_bus_unlock();
+       mutex_unlock(&ddata->lock);
+
+       return 0;
+}
+
+static struct omap_dss_driver n8x0_panel_driver = {
+       .probe          = n8x0_panel_probe,
+       .remove         = n8x0_panel_remove,
+
+       .enable         = n8x0_panel_enable,
+       .disable        = n8x0_panel_disable,
+       .suspend        = n8x0_panel_suspend,
+       .resume         = n8x0_panel_resume,
+
+       .update         = n8x0_panel_update,
+       .sync           = n8x0_panel_sync,
+
+       .get_resolution = n8x0_panel_get_resolution,
+       .get_recommended_bpp = omapdss_default_get_recommended_bpp,
+
+       .get_timings    = n8x0_panel_get_timings,
+
+       .driver         = {
+               .name   = "n8x0_panel",
+               .owner  = THIS_MODULE,
+       },
+};
+
+/* PANEL */
+
+static int mipid_spi_probe(struct spi_device *spi)
+{
+       dev_dbg(&spi->dev, "mipid_spi_probe\n");
+
+       spi->mode = SPI_MODE_0;
+
+       s_drv_data.spidev = spi;
+
+       return 0;
+}
+
+static int mipid_spi_remove(struct spi_device *spi)
+{
+       dev_dbg(&spi->dev, "mipid_spi_remove\n");
+       return 0;
+}
+
+static struct spi_driver mipid_spi_driver = {
+       .driver = {
+               .name   = "lcd_mipid",
+               .bus    = &spi_bus_type,
+               .owner  = THIS_MODULE,
+       },
+       .probe  = mipid_spi_probe,
+       .remove = __devexit_p(mipid_spi_remove),
+};
+
+static int __init n8x0_panel_drv_init(void)
+{
+       int r;
+
+       r = spi_register_driver(&mipid_spi_driver);
+       if (r) {
+               pr_err("n8x0_panel: spi driver registration failed\n");
+               return r;
+       }
+
+       r = omap_dss_register_driver(&n8x0_panel_driver);
+       if (r) {
+               pr_err("n8x0_panel: dss driver registration failed\n");
+               spi_unregister_driver(&mipid_spi_driver);
+               return r;
+       }
+
+       return 0;
+}
+
+static void __exit n8x0_panel_drv_exit(void)
+{
+       spi_unregister_driver(&mipid_spi_driver);
+
+       omap_dss_unregister_driver(&n8x0_panel_driver);
+}
+
+module_init(n8x0_panel_drv_init);
+module_exit(n8x0_panel_drv_exit);
+MODULE_LICENSE("GPL");
diff --git a/drivers/video/omap2/displays/panel-picodlp.c b/drivers/video/omap2/displays/panel-picodlp.c
new file mode 100644 (file)
index 0000000..98ebdad
--- /dev/null
@@ -0,0 +1,594 @@
+/*
+ * picodlp panel driver
+ * picodlp_i2c_driver: i2c_client driver
+ *
+ * Copyright (C) 2009-2011 Texas Instruments
+ * Author: Mythri P K <mythripk@ti.com>
+ * Mayuresh Janorkar <mayur@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/module.h>
+#include <linux/input.h>
+#include <linux/platform_device.h>
+#include <linux/interrupt.h>
+#include <linux/firmware.h>
+#include <linux/slab.h>
+#include <linux/mutex.h>
+#include <linux/i2c.h>
+#include <linux/delay.h>
+#include <linux/gpio.h>
+
+#include <video/omapdss.h>
+#include <video/omap-panel-picodlp.h>
+
+#include "panel-picodlp.h"
+
+struct picodlp_data {
+       struct mutex lock;
+       struct i2c_client *picodlp_i2c_client;
+};
+
+static struct i2c_board_info picodlp_i2c_board_info = {
+       I2C_BOARD_INFO("picodlp_i2c_driver", 0x1b),
+};
+
+struct picodlp_i2c_data {
+       struct mutex xfer_lock;
+};
+
+static struct i2c_device_id picodlp_i2c_id[] = {
+       { "picodlp_i2c_driver", 0 },
+};
+
+struct picodlp_i2c_command {
+       u8 reg;
+       u32 value;
+};
+
+static struct omap_video_timings pico_ls_timings = {
+       .x_res          = 864,
+       .y_res          = 480,
+       .hsw            = 7,
+       .hfp            = 11,
+       .hbp            = 7,
+
+       .pixel_clock    = 19200,
+
+       .vsw            = 2,
+       .vfp            = 3,
+       .vbp            = 14,
+};
+
+static inline struct picodlp_panel_data
+               *get_panel_data(const struct omap_dss_device *dssdev)
+{
+       return (struct picodlp_panel_data *) dssdev->data;
+}
+
+static u32 picodlp_i2c_read(struct i2c_client *client, u8 reg)
+{
+       u8 read_cmd[] = {READ_REG_SELECT, reg}, data[4];
+       struct picodlp_i2c_data *picodlp_i2c_data = i2c_get_clientdata(client);
+       struct i2c_msg msg[2];
+
+       mutex_lock(&picodlp_i2c_data->xfer_lock);
+
+       msg[0].addr = client->addr;
+       msg[0].flags = 0;
+       msg[0].len = 2;
+       msg[0].buf = read_cmd;
+
+       msg[1].addr = client->addr;
+       msg[1].flags = I2C_M_RD;
+       msg[1].len = 4;
+       msg[1].buf = data;
+
+       i2c_transfer(client->adapter, msg, 2);
+       mutex_unlock(&picodlp_i2c_data->xfer_lock);
+       return (data[3] | (data[2] << 8) | (data[1] << 16) | (data[0] << 24));
+}
+
+static int picodlp_i2c_write_block(struct i2c_client *client,
+                                       u8 *data, int len)
+{
+       struct i2c_msg msg;
+       int i, r, msg_count = 1;
+
+       struct picodlp_i2c_data *picodlp_i2c_data = i2c_get_clientdata(client);
+
+       if (len < 1 || len > 32) {
+               dev_err(&client->dev,
+                       "too long syn_write_block len %d\n", len);
+               return -EIO;
+       }
+       mutex_lock(&picodlp_i2c_data->xfer_lock);
+
+       msg.addr = client->addr;
+       msg.flags = 0;
+       msg.len = len;
+       msg.buf = data;
+       r = i2c_transfer(client->adapter, &msg, msg_count);
+       mutex_unlock(&picodlp_i2c_data->xfer_lock);
+
+       /*
+        * i2c_transfer returns:
+        * number of messages sent in case of success
+        * a negative error number in case of failure
+        */
+       if (r != msg_count)
+               goto err;
+
+       /* In case of success */
+       for (i = 0; i < len; i++)
+               dev_dbg(&client->dev,
+                       "addr %x bw 0x%02x[%d]: 0x%02x\n",
+                       client->addr, data[0] + i, i, data[i]);
+
+       return 0;
+err:
+       dev_err(&client->dev, "picodlp_i2c_write error\n");
+       return r;
+}
+
+static int picodlp_i2c_write(struct i2c_client *client, u8 reg, u32 value)
+{
+       u8 data[5];
+       int i;
+
+       data[0] = reg;
+       for (i = 1; i < 5; i++)
+               data[i] = (value >> (32 - (i) * 8)) & 0xFF;
+
+       return picodlp_i2c_write_block(client, data, 5);
+}
+
+static int picodlp_i2c_write_array(struct i2c_client *client,
+                       const struct picodlp_i2c_command commands[],
+                       int count)
+{
+       int i, r = 0;
+       for (i = 0; i < count; i++) {
+               r = picodlp_i2c_write(client, commands[i].reg,
+                                               commands[i].value);
+               if (r)
+                       return r;
+       }
+       return r;
+}
+
+static int picodlp_wait_for_dma_done(struct i2c_client *client)
+{
+       u8 trial = 100;
+
+       do {
+               msleep(1);
+               if (!trial--)
+                       return -ETIMEDOUT;
+       } while (picodlp_i2c_read(client, MAIN_STATUS) & DMA_STATUS);
+
+       return 0;
+}
+
+/**
+ * picodlp_i2c_init:   i2c_initialization routine
+ * client:     i2c_client for communication
+ *
+ * return
+ *             0       : Success, no error
+ *     error code      : Failure
+ */
+static int picodlp_i2c_init(struct i2c_client *client)
+{
+       int r;
+       static const struct picodlp_i2c_command init_cmd_set1[] = {
+               {SOFT_RESET, 1},
+               {DMD_PARK_TRIGGER, 1},
+               {MISC_REG, 5},
+               {SEQ_CONTROL, 0},
+               {SEQ_VECTOR, 0x100},
+               {DMD_BLOCK_COUNT, 7},
+               {DMD_VCC_CONTROL, 0x109},
+               {DMD_PARK_PULSE_COUNT, 0xA},
+               {DMD_PARK_PULSE_WIDTH, 0xB},
+               {DMD_PARK_DELAY, 0x2ED},
+               {DMD_SHADOW_ENABLE, 0},
+               {FLASH_OPCODE, 0xB},
+               {FLASH_DUMMY_BYTES, 1},
+               {FLASH_ADDR_BYTES, 3},
+               {PBC_CONTROL, 0},
+               {FLASH_START_ADDR, CMT_LUT_0_START_ADDR},
+               {FLASH_READ_BYTES, CMT_LUT_0_SIZE},
+               {CMT_SPLASH_LUT_START_ADDR, 0},
+               {CMT_SPLASH_LUT_DEST_SELECT, CMT_LUT_ALL},
+               {PBC_CONTROL, 1},
+       };
+
+       static const struct picodlp_i2c_command init_cmd_set2[] = {
+               {PBC_CONTROL, 0},
+               {CMT_SPLASH_LUT_DEST_SELECT, 0},
+               {PBC_CONTROL, 0},
+               {FLASH_START_ADDR, SEQUENCE_0_START_ADDR},
+               {FLASH_READ_BYTES, SEQUENCE_0_SIZE},
+               {SEQ_RESET_LUT_START_ADDR, 0},
+               {SEQ_RESET_LUT_DEST_SELECT, SEQ_SEQ_LUT},
+               {PBC_CONTROL, 1},
+       };
+
+       static const struct picodlp_i2c_command init_cmd_set3[] = {
+               {PBC_CONTROL, 0},
+               {SEQ_RESET_LUT_DEST_SELECT, 0},
+               {PBC_CONTROL, 0},
+               {FLASH_START_ADDR, DRC_TABLE_0_START_ADDR},
+               {FLASH_READ_BYTES, DRC_TABLE_0_SIZE},
+               {SEQ_RESET_LUT_START_ADDR, 0},
+               {SEQ_RESET_LUT_DEST_SELECT, SEQ_DRC_LUT_ALL},
+               {PBC_CONTROL, 1},
+       };
+
+       static const struct picodlp_i2c_command init_cmd_set4[] = {
+               {PBC_CONTROL, 0},
+               {SEQ_RESET_LUT_DEST_SELECT, 0},
+               {SDC_ENABLE, 1},
+               {AGC_CTRL, 7},
+               {CCA_C1A, 0x100},
+               {CCA_C1B, 0x0},
+               {CCA_C1C, 0x0},
+               {CCA_C2A, 0x0},
+               {CCA_C2B, 0x100},
+               {CCA_C2C, 0x0},
+               {CCA_C3A, 0x0},
+               {CCA_C3B, 0x0},
+               {CCA_C3C, 0x100},
+               {CCA_C7A, 0x100},
+               {CCA_C7B, 0x100},
+               {CCA_C7C, 0x100},
+               {CCA_ENABLE, 1},
+               {CPU_IF_MODE, 1},
+               {SHORT_FLIP, 1},
+               {CURTAIN_CONTROL, 0},
+               {DMD_PARK_TRIGGER, 0},
+               {R_DRIVE_CURRENT, 0x298},
+               {G_DRIVE_CURRENT, 0x298},
+               {B_DRIVE_CURRENT, 0x298},
+               {RGB_DRIVER_ENABLE, 7},
+               {SEQ_CONTROL, 0},
+               {ACTGEN_CONTROL, 0x10},
+               {SEQUENCE_MODE, SEQ_LOCK},
+               {DATA_FORMAT, RGB888},
+               {INPUT_RESOLUTION, WVGA_864_LANDSCAPE},
+               {INPUT_SOURCE, PARALLEL_RGB},
+               {CPU_IF_SYNC_METHOD, 1},
+               {SEQ_CONTROL, 1}
+       };
+
+       r = picodlp_i2c_write_array(client, init_cmd_set1,
+                                               ARRAY_SIZE(init_cmd_set1));
+       if (r)
+               return r;
+
+       r = picodlp_wait_for_dma_done(client);
+       if (r)
+               return r;
+
+       r = picodlp_i2c_write_array(client, init_cmd_set2,
+                                       ARRAY_SIZE(init_cmd_set2));
+       if (r)
+               return r;
+
+       r = picodlp_wait_for_dma_done(client);
+       if (r)
+               return r;
+
+       r = picodlp_i2c_write_array(client, init_cmd_set3,
+                                       ARRAY_SIZE(init_cmd_set3));
+       if (r)
+               return r;
+
+       r = picodlp_wait_for_dma_done(client);
+       if (r)
+               return r;
+
+       r = picodlp_i2c_write_array(client, init_cmd_set4,
+                                       ARRAY_SIZE(init_cmd_set4));
+       if (r)
+               return r;
+
+       return 0;
+}
+
+static int picodlp_i2c_probe(struct i2c_client *client,
+               const struct i2c_device_id *id)
+{
+       struct picodlp_i2c_data *picodlp_i2c_data;
+
+       picodlp_i2c_data = kzalloc(sizeof(struct picodlp_i2c_data), GFP_KERNEL);
+
+       if (!picodlp_i2c_data)
+               return -ENOMEM;
+
+       mutex_init(&picodlp_i2c_data->xfer_lock);
+       i2c_set_clientdata(client, picodlp_i2c_data);
+
+       return 0;
+}
+
+static int picodlp_i2c_remove(struct i2c_client *client)
+{
+       struct picodlp_i2c_data *picodlp_i2c_data =
+                                       i2c_get_clientdata(client);
+       kfree(picodlp_i2c_data);
+       return 0;
+}
+
+static struct i2c_driver picodlp_i2c_driver = {
+       .driver = {
+               .name   = "picodlp_i2c_driver",
+       },
+       .probe          = picodlp_i2c_probe,
+       .remove         = picodlp_i2c_remove,
+       .id_table       = picodlp_i2c_id,
+};
+
+static int picodlp_panel_power_on(struct omap_dss_device *dssdev)
+{
+       int r, trial = 100;
+       struct picodlp_data *picod = dev_get_drvdata(&dssdev->dev);
+       struct picodlp_panel_data *picodlp_pdata = get_panel_data(dssdev);
+
+       if (dssdev->platform_enable) {
+               r = dssdev->platform_enable(dssdev);
+               if (r)
+                       return r;
+       }
+
+       gpio_set_value(picodlp_pdata->pwrgood_gpio, 0);
+       msleep(1);
+       gpio_set_value(picodlp_pdata->pwrgood_gpio, 1);
+
+       while (!gpio_get_value(picodlp_pdata->emu_done_gpio)) {
+               if (!trial--) {
+                       dev_err(&dssdev->dev, "emu_done signal not"
+                                               " going high\n");
+                       return -ETIMEDOUT;
+               }
+               msleep(5);
+       }
+       /*
+        * As per dpp2600 programming guide,
+        * it is required to sleep for 1000ms after emu_done signal goes high
+        * then only i2c commands can be successfully sent to dpp2600
+        */
+       msleep(1000);
+       r = omapdss_dpi_display_enable(dssdev);
+       if (r) {
+               dev_err(&dssdev->dev, "failed to enable DPI\n");
+               goto err1;
+       }
+
+       r = picodlp_i2c_init(picod->picodlp_i2c_client);
+       if (r)
+               goto err;
+
+       dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
+
+       return r;
+err:
+       omapdss_dpi_display_disable(dssdev);
+err1:
+       if (dssdev->platform_disable)
+               dssdev->platform_disable(dssdev);
+
+       return r;
+}
+
+static void picodlp_panel_power_off(struct omap_dss_device *dssdev)
+{
+       struct picodlp_panel_data *picodlp_pdata = get_panel_data(dssdev);
+
+       omapdss_dpi_display_disable(dssdev);
+
+       gpio_set_value(picodlp_pdata->emu_done_gpio, 0);
+       gpio_set_value(picodlp_pdata->pwrgood_gpio, 0);
+
+       if (dssdev->platform_disable)
+               dssdev->platform_disable(dssdev);
+}
+
+static int picodlp_panel_probe(struct omap_dss_device *dssdev)
+{
+       struct picodlp_data *picod;
+       struct picodlp_panel_data *picodlp_pdata = get_panel_data(dssdev);
+       struct i2c_adapter *adapter;
+       struct i2c_client *picodlp_i2c_client;
+       int r = 0, picodlp_adapter_id;
+
+       dssdev->panel.config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_ONOFF |
+                               OMAP_DSS_LCD_IHS | OMAP_DSS_LCD_IVS;
+       dssdev->panel.acb = 0x0;
+       dssdev->panel.timings = pico_ls_timings;
+
+       picod =  kzalloc(sizeof(struct picodlp_data), GFP_KERNEL);
+       if (!picod)
+               return -ENOMEM;
+
+       mutex_init(&picod->lock);
+
+       picodlp_adapter_id = picodlp_pdata->picodlp_adapter_id;
+
+       adapter = i2c_get_adapter(picodlp_adapter_id);
+       if (!adapter) {
+               dev_err(&dssdev->dev, "can't get i2c adapter\n");
+               r = -ENODEV;
+               goto err;
+       }
+
+       picodlp_i2c_client = i2c_new_device(adapter, &picodlp_i2c_board_info);
+       if (!picodlp_i2c_client) {
+               dev_err(&dssdev->dev, "can't add i2c device::"
+                                        " picodlp_i2c_client is NULL\n");
+               r = -ENODEV;
+               goto err;
+       }
+
+       picod->picodlp_i2c_client = picodlp_i2c_client;
+
+       dev_set_drvdata(&dssdev->dev, picod);
+       return r;
+err:
+       kfree(picod);
+       return r;
+}
+
+static void picodlp_panel_remove(struct omap_dss_device *dssdev)
+{
+       struct picodlp_data *picod = dev_get_drvdata(&dssdev->dev);
+
+       i2c_unregister_device(picod->picodlp_i2c_client);
+       dev_set_drvdata(&dssdev->dev, NULL);
+       dev_dbg(&dssdev->dev, "removing picodlp panel\n");
+
+       kfree(picod);
+}
+
+static int picodlp_panel_enable(struct omap_dss_device *dssdev)
+{
+       struct picodlp_data *picod = dev_get_drvdata(&dssdev->dev);
+       int r;
+
+       dev_dbg(&dssdev->dev, "enabling picodlp panel\n");
+
+       mutex_lock(&picod->lock);
+       if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
+               mutex_unlock(&picod->lock);
+               return -EINVAL;
+       }
+
+       r = picodlp_panel_power_on(dssdev);
+       mutex_unlock(&picod->lock);
+
+       return r;
+}
+
+static void picodlp_panel_disable(struct omap_dss_device *dssdev)
+{
+       struct picodlp_data *picod = dev_get_drvdata(&dssdev->dev);
+
+       mutex_lock(&picod->lock);
+       /* Turn off DLP Power */
+       if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
+               picodlp_panel_power_off(dssdev);
+
+       dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
+       mutex_unlock(&picod->lock);
+
+       dev_dbg(&dssdev->dev, "disabling picodlp panel\n");
+}
+
+static int picodlp_panel_suspend(struct omap_dss_device *dssdev)
+{
+       struct picodlp_data *picod = dev_get_drvdata(&dssdev->dev);
+
+       mutex_lock(&picod->lock);
+       /* Turn off DLP Power */
+       if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
+               mutex_unlock(&picod->lock);
+               dev_err(&dssdev->dev, "unable to suspend picodlp panel,"
+                                       " panel is not ACTIVE\n");
+               return -EINVAL;
+       }
+
+       picodlp_panel_power_off(dssdev);
+
+       dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
+       mutex_unlock(&picod->lock);
+
+       dev_dbg(&dssdev->dev, "suspending picodlp panel\n");
+       return 0;
+}
+
+static int picodlp_panel_resume(struct omap_dss_device *dssdev)
+{
+       struct picodlp_data *picod = dev_get_drvdata(&dssdev->dev);
+       int r;
+
+       mutex_lock(&picod->lock);
+       if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
+               mutex_unlock(&picod->lock);
+               dev_err(&dssdev->dev, "unable to resume picodlp panel,"
+                       " panel is not ACTIVE\n");
+               return -EINVAL;
+       }
+
+       r = picodlp_panel_power_on(dssdev);
+       mutex_unlock(&picod->lock);
+       dev_dbg(&dssdev->dev, "resuming picodlp panel\n");
+       return r;
+}
+
+static void picodlp_get_resolution(struct omap_dss_device *dssdev,
+                                       u16 *xres, u16 *yres)
+{
+       *xres = dssdev->panel.timings.x_res;
+       *yres = dssdev->panel.timings.y_res;
+}
+
+static struct omap_dss_driver picodlp_driver = {
+       .probe          = picodlp_panel_probe,
+       .remove         = picodlp_panel_remove,
+
+       .enable         = picodlp_panel_enable,
+       .disable        = picodlp_panel_disable,
+
+       .get_resolution = picodlp_get_resolution,
+
+       .suspend        = picodlp_panel_suspend,
+       .resume         = picodlp_panel_resume,
+
+       .driver         = {
+               .name   = "picodlp_panel",
+               .owner  = THIS_MODULE,
+       },
+};
+
+static int __init picodlp_init(void)
+{
+       int r = 0;
+
+       r = i2c_add_driver(&picodlp_i2c_driver);
+       if (r) {
+               printk(KERN_WARNING "picodlp_i2c_driver" \
+                       " registration failed\n");
+               return r;
+       }
+
+       r = omap_dss_register_driver(&picodlp_driver);
+       if (r)
+               i2c_del_driver(&picodlp_i2c_driver);
+
+       return r;
+}
+
+static void __exit picodlp_exit(void)
+{
+       i2c_del_driver(&picodlp_i2c_driver);
+       omap_dss_unregister_driver(&picodlp_driver);
+}
+
+module_init(picodlp_init);
+module_exit(picodlp_exit);
+
+MODULE_AUTHOR("Mythri P K <mythripk@ti.com>");
+MODULE_DESCRIPTION("picodlp driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/video/omap2/displays/panel-picodlp.h b/drivers/video/omap2/displays/panel-picodlp.h
new file mode 100644 (file)
index 0000000..a34b431
--- /dev/null
@@ -0,0 +1,288 @@
+/*
+ * Header file required by picodlp panel driver
+ *
+ * Copyright (C) 2009-2011 Texas Instruments
+ * Author: Mythri P K <mythripk@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __OMAP2_DISPLAY_PANEL_PICODLP_H
+#define __OMAP2_DISPLAY_PANEL_PICODLP_H
+
+/* Commands used for configuring picodlp panel */
+
+#define MAIN_STATUS                    0x03
+#define PBC_CONTROL                    0x08
+#define INPUT_SOURCE                   0x0B
+#define INPUT_RESOLUTION               0x0C
+#define DATA_FORMAT                    0x0D
+#define IMG_ROTATION                   0x0E
+#define LONG_FLIP                      0x0F
+#define SHORT_FLIP                     0x10
+#define TEST_PAT_SELECT                        0x11
+#define R_DRIVE_CURRENT                        0x12
+#define G_DRIVE_CURRENT                        0x13
+#define B_DRIVE_CURRENT                        0x14
+#define READ_REG_SELECT                        0x15
+#define RGB_DRIVER_ENABLE              0x16
+
+#define CPU_IF_MODE                    0x18
+#define FRAME_RATE                     0x19
+#define CPU_IF_SYNC_METHOD             0x1A
+#define CPU_IF_SOF                     0x1B
+#define CPU_IF_EOF                     0x1C
+#define CPU_IF_SLEEP                   0x1D
+
+#define SEQUENCE_MODE                  0x1E
+#define SOFT_RESET                     0x1F
+#define FRONT_END_RESET                        0x21
+#define AUTO_PWR_ENABLE                        0x22
+
+#define VSYNC_LINE_DELAY               0x23
+#define CPU_PI_HORIZ_START             0x24
+#define CPU_PI_VERT_START              0x25
+#define CPU_PI_HORIZ_WIDTH             0x26
+#define CPU_PI_VERT_HEIGHT             0x27
+
+#define PIXEL_MASK_CROP                        0x28
+#define CROP_FIRST_LINE                        0x29
+#define CROP_LAST_LINE                 0x2A
+#define CROP_FIRST_PIXEL               0x2B
+#define CROP_LAST_PIXEL                        0x2C
+#define DMD_PARK_TRIGGER               0x2D
+
+#define MISC_REG                       0x30
+
+/* AGC registers */
+#define AGC_CTRL                       0x50
+#define AGC_CLIPPED_PIXS               0x55
+#define AGC_BRIGHT_PIXS                        0x56
+#define AGC_BG_PIXS                    0x57
+#define AGC_SAFETY_MARGIN              0x17
+
+/* Color Coordinate Adjustment registers */
+#define CCA_ENABLE             0x5E
+#define CCA_C1A                        0x5F
+#define CCA_C1B                        0x60
+#define CCA_C1C                        0x61
+#define CCA_C2A                        0x62
+#define CCA_C2B                        0x63
+#define CCA_C2C                        0x64
+#define CCA_C3A                        0x65
+#define CCA_C3B                        0x66
+#define CCA_C3C                        0x67
+#define CCA_C7A                        0x71
+#define CCA_C7B                        0x72
+#define CCA_C7C                        0x73
+
+/**
+ * DLP Pico Processor 2600 comes with flash
+ * We can do DMA operations from flash for accessing Look Up Tables
+ */
+#define DMA_STATUS                     0x100
+#define FLASH_ADDR_BYTES               0x74
+#define FLASH_DUMMY_BYTES              0x75
+#define FLASH_WRITE_BYTES              0x76
+#define FLASH_READ_BYTES               0x77
+#define FLASH_OPCODE                   0x78
+#define FLASH_START_ADDR               0x79
+#define FLASH_DUMMY2                   0x7A
+#define FLASH_WRITE_DATA               0x7B
+
+#define TEMPORAL_DITH_DISABLE          0x7E
+#define SEQ_CONTROL                    0x82
+#define SEQ_VECTOR                     0x83
+
+/* DMD is Digital Micromirror Device */
+#define DMD_BLOCK_COUNT                        0x84
+#define DMD_VCC_CONTROL                        0x86
+#define DMD_PARK_PULSE_COUNT           0x87
+#define DMD_PARK_PULSE_WIDTH           0x88
+#define DMD_PARK_DELAY                 0x89
+#define DMD_SHADOW_ENABLE              0x8E
+#define SEQ_STATUS                     0x8F
+#define FLASH_CLOCK_CONTROL            0x98
+#define DMD_PARK                       0x2D
+
+#define SDRAM_BIST_ENABLE              0x46
+#define DDR_DRIVER_STRENGTH            0x9A
+#define SDC_ENABLE                     0x9D
+#define SDC_BUFF_SWAP_DISABLE          0xA3
+#define CURTAIN_CONTROL                        0xA6
+#define DDR_BUS_SWAP_ENABLE            0xA7
+#define DMD_TRC_ENABLE                 0xA8
+#define DMD_BUS_SWAP_ENABLE            0xA9
+
+#define ACTGEN_ENABLE                  0xAE
+#define ACTGEN_CONTROL                 0xAF
+#define ACTGEN_HORIZ_BP                        0xB0
+#define ACTGEN_VERT_BP                 0xB1
+
+/* Look Up Table access */
+#define CMT_SPLASH_LUT_START_ADDR      0xFA
+#define CMT_SPLASH_LUT_DEST_SELECT     0xFB
+#define CMT_SPLASH_LUT_DATA            0xFC
+#define SEQ_RESET_LUT_START_ADDR       0xFD
+#define SEQ_RESET_LUT_DEST_SELECT      0xFE
+#define SEQ_RESET_LUT_DATA             0xFF
+
+/* Input source definitions */
+#define PARALLEL_RGB           0
+#define INT_TEST_PATTERN       1
+#define SPLASH_SCREEN          2
+#define CPU_INTF               3
+#define BT656                  4
+
+/* Standard input resolution definitions */
+#define QWVGA_LANDSCAPE                3       /* (427h*240v) */
+#define WVGA_864_LANDSCAPE     21      /* (864h*480v) */
+#define WVGA_DMD_OPTICAL_TEST  35      /* (608h*684v) */
+
+/* Standard data format definitions */
+#define RGB565                 0
+#define RGB666                 1
+#define RGB888                 2
+
+/* Test Pattern definitions */
+#define TPG_CHECKERBOARD       0
+#define TPG_BLACK              1
+#define TPG_WHITE              2
+#define TPG_RED                        3
+#define TPG_BLUE               4
+#define TPG_GREEN              5
+#define TPG_VLINES_BLACK       6
+#define TPG_HLINES_BLACK       7
+#define TPG_VLINES_ALT         8
+#define TPG_HLINES_ALT         9
+#define TPG_DIAG_LINES         10
+#define TPG_GREYRAMP_VERT      11
+#define TPG_GREYRAMP_HORIZ     12
+#define TPG_ANSI_CHECKERBOARD  13
+
+/* sequence mode definitions */
+#define SEQ_FREE_RUN           0
+#define SEQ_LOCK               1
+
+/* curtain color definitions */
+#define CURTAIN_BLACK          0
+#define CURTAIN_RED            1
+#define CURTAIN_GREEN          2
+#define CURTAIN_BLUE           3
+#define CURTAIN_YELLOW         4
+#define CURTAIN_MAGENTA                5
+#define CURTAIN_CYAN           6
+#define CURTAIN_WHITE          7
+
+/* LUT definitions */
+#define CMT_LUT_NONE           0
+#define CMT_LUT_GREEN          1
+#define CMT_LUT_RED            2
+#define CMT_LUT_BLUE           3
+#define CMT_LUT_ALL            4
+#define SPLASH_LUT             5
+
+#define SEQ_LUT_NONE           0
+#define SEQ_DRC_LUT_0          1
+#define SEQ_DRC_LUT_1          2
+#define SEQ_DRC_LUT_2          3
+#define SEQ_DRC_LUT_3          4
+#define SEQ_SEQ_LUT            5
+#define SEQ_DRC_LUT_ALL                6
+#define WPC_PROGRAM_LUT                7
+
+#define BITSTREAM_START_ADDR           0x00000000
+#define BITSTREAM_SIZE                 0x00040000
+
+#define WPC_FW_0_START_ADDR            0x00040000
+#define WPC_FW_0_SIZE                  0x00000ce8
+
+#define SEQUENCE_0_START_ADDR          0x00044000
+#define SEQUENCE_0_SIZE                        0x00001000
+
+#define SEQUENCE_1_START_ADDR          0x00045000
+#define SEQUENCE_1_SIZE                        0x00000d10
+
+#define SEQUENCE_2_START_ADDR          0x00046000
+#define SEQUENCE_2_SIZE                        0x00000d10
+
+#define SEQUENCE_3_START_ADDR          0x00047000
+#define SEQUENCE_3_SIZE                        0x00000d10
+
+#define SEQUENCE_4_START_ADDR          0x00048000
+#define SEQUENCE_4_SIZE                        0x00000d10
+
+#define SEQUENCE_5_START_ADDR          0x00049000
+#define SEQUENCE_5_SIZE                        0x00000d10
+
+#define SEQUENCE_6_START_ADDR          0x0004a000
+#define SEQUENCE_6_SIZE                        0x00000d10
+
+#define CMT_LUT_0_START_ADDR           0x0004b200
+#define CMT_LUT_0_SIZE                 0x00000600
+
+#define CMT_LUT_1_START_ADDR           0x0004b800
+#define CMT_LUT_1_SIZE                 0x00000600
+
+#define CMT_LUT_2_START_ADDR           0x0004be00
+#define CMT_LUT_2_SIZE                 0x00000600
+
+#define CMT_LUT_3_START_ADDR           0x0004c400
+#define CMT_LUT_3_SIZE                 0x00000600
+
+#define CMT_LUT_4_START_ADDR           0x0004ca00
+#define CMT_LUT_4_SIZE                 0x00000600
+
+#define CMT_LUT_5_START_ADDR           0x0004d000
+#define CMT_LUT_5_SIZE                 0x00000600
+
+#define CMT_LUT_6_START_ADDR           0x0004d600
+#define CMT_LUT_6_SIZE                 0x00000600
+
+#define DRC_TABLE_0_START_ADDR         0x0004dc00
+#define DRC_TABLE_0_SIZE               0x00000100
+
+#define SPLASH_0_START_ADDR            0x0004dd00
+#define SPLASH_0_SIZE                  0x00032280
+
+#define SEQUENCE_7_START_ADDR          0x00080000
+#define SEQUENCE_7_SIZE                        0x00000d10
+
+#define SEQUENCE_8_START_ADDR          0x00081800
+#define SEQUENCE_8_SIZE                        0x00000d10
+
+#define SEQUENCE_9_START_ADDR          0x00083000
+#define SEQUENCE_9_SIZE                        0x00000d10
+
+#define CMT_LUT_7_START_ADDR           0x0008e000
+#define CMT_LUT_7_SIZE                 0x00000600
+
+#define CMT_LUT_8_START_ADDR           0x0008e800
+#define CMT_LUT_8_SIZE                 0x00000600
+
+#define CMT_LUT_9_START_ADDR           0x0008f000
+#define CMT_LUT_9_SIZE                 0x00000600
+
+#define SPLASH_1_START_ADDR            0x0009a000
+#define SPLASH_1_SIZE                  0x00032280
+
+#define SPLASH_2_START_ADDR            0x000cd000
+#define SPLASH_2_SIZE                  0x00032280
+
+#define SPLASH_3_START_ADDR            0x00100000
+#define SPLASH_3_SIZE                  0x00032280
+
+#define OPT_SPLASH_0_START_ADDR                0x00134000
+#define OPT_SPLASH_0_SIZE              0x000cb100
+
+#endif
index 4e888ac09b3f4a79de6b263d275684affca45ba0..80c3f6ab1a94d73df39d18233c8ddc4dbd91304a 100644 (file)
 
 #include <video/omapdss.h>
 #include <video/omap-panel-nokia-dsi.h>
+#include <video/mipi_display.h>
 
 /* DSI Virtual channel. Hardcoded for now. */
 #define TCH 0
 
 #define DCS_READ_NUM_ERRORS    0x05
-#define DCS_READ_POWER_MODE    0x0a
-#define DCS_READ_MADCTL                0x0b
-#define DCS_READ_PIXEL_FORMAT  0x0c
-#define DCS_RDDSDR             0x0f
-#define DCS_SLEEP_IN           0x10
-#define DCS_SLEEP_OUT          0x11
-#define DCS_DISPLAY_OFF                0x28
-#define DCS_DISPLAY_ON         0x29
-#define DCS_COLUMN_ADDR                0x2a
-#define DCS_PAGE_ADDR          0x2b
-#define DCS_MEMORY_WRITE       0x2c
-#define DCS_TEAR_OFF           0x34
-#define DCS_TEAR_ON            0x35
-#define DCS_MEM_ACC_CTRL       0x36
-#define DCS_PIXEL_FORMAT       0x3a
 #define DCS_BRIGHTNESS         0x51
 #define DCS_CTRL_DISPLAY       0x53
 #define DCS_WRITE_CABC         0x55
@@ -222,8 +208,6 @@ struct taal_data {
 
        struct delayed_work te_timeout_work;
 
-       bool use_dsi_bl;
-
        bool cabc_broken;
        unsigned cabc_mode;
 
@@ -302,7 +286,7 @@ static int taal_sleep_in(struct taal_data *td)
 
        hw_guard_wait(td);
 
-       cmd = DCS_SLEEP_IN;
+       cmd = MIPI_DCS_ENTER_SLEEP_MODE;
        r = dsi_vc_dcs_write_nosync(td->dssdev, td->channel, &cmd, 1);
        if (r)
                return r;
@@ -321,7 +305,7 @@ static int taal_sleep_out(struct taal_data *td)
 
        hw_guard_wait(td);
 
-       r = taal_dcs_write_0(td, DCS_SLEEP_OUT);
+       r = taal_dcs_write_0(td, MIPI_DCS_EXIT_SLEEP_MODE);
        if (r)
                return r;
 
@@ -356,7 +340,7 @@ static int taal_set_addr_mode(struct taal_data *td, u8 rotate, bool mirror)
        u8 mode;
        int b5, b6, b7;
 
-       r = taal_dcs_read_1(td, DCS_READ_MADCTL, &mode);
+       r = taal_dcs_read_1(td, MIPI_DCS_GET_ADDRESS_MODE, &mode);
        if (r)
                return r;
 
@@ -390,7 +374,7 @@ static int taal_set_addr_mode(struct taal_data *td, u8 rotate, bool mirror)
        mode &= ~((1<<7) | (1<<6) | (1<<5));
        mode |= (b7 << 7) | (b6 << 6) | (b5 << 5);
 
-       return taal_dcs_write_1(td, DCS_MEM_ACC_CTRL, mode);
+       return taal_dcs_write_1(td, MIPI_DCS_SET_ADDRESS_MODE, mode);
 }
 
 static int taal_set_update_window(struct taal_data *td,
@@ -403,7 +387,7 @@ static int taal_set_update_window(struct taal_data *td,
        u16 y2 = y + h - 1;
 
        u8 buf[5];
-       buf[0] = DCS_COLUMN_ADDR;
+       buf[0] = MIPI_DCS_SET_COLUMN_ADDRESS;
        buf[1] = (x1 >> 8) & 0xff;
        buf[2] = (x1 >> 0) & 0xff;
        buf[3] = (x2 >> 8) & 0xff;
@@ -413,7 +397,7 @@ static int taal_set_update_window(struct taal_data *td,
        if (r)
                return r;
 
-       buf[0] = DCS_PAGE_ADDR;
+       buf[0] = MIPI_DCS_SET_PAGE_ADDRESS;
        buf[1] = (y1 >> 8) & 0xff;
        buf[2] = (y1 >> 0) & 0xff;
        buf[3] = (y2 >> 8) & 0xff;
@@ -555,7 +539,6 @@ static int taal_bl_update_status(struct backlight_device *dev)
 {
        struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev);
        struct taal_data *td = dev_get_drvdata(&dssdev->dev);
-       struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
        int r;
        int level;
 
@@ -569,23 +552,16 @@ static int taal_bl_update_status(struct backlight_device *dev)
 
        mutex_lock(&td->lock);
 
-       if (td->use_dsi_bl) {
-               if (td->enabled) {
-                       dsi_bus_lock(dssdev);
+       if (td->enabled) {
+               dsi_bus_lock(dssdev);
 
-                       r = taal_wake_up(dssdev);
-                       if (!r)
-                               r = taal_dcs_write_1(td, DCS_BRIGHTNESS, level);
+               r = taal_wake_up(dssdev);
+               if (!r)
+                       r = taal_dcs_write_1(td, DCS_BRIGHTNESS, level);
 
-                       dsi_bus_unlock(dssdev);
-               } else {
-                       r = 0;
-               }
+               dsi_bus_unlock(dssdev);
        } else {
-               if (!panel_data->set_backlight)
-                       r = -EINVAL;
-               else
-                       r = panel_data->set_backlight(dssdev, level);
+               r = 0;
        }
 
        mutex_unlock(&td->lock);
@@ -964,7 +940,7 @@ static int taal_probe(struct omap_dss_device *dssdev)
 {
        struct backlight_properties props;
        struct taal_data *td;
-       struct backlight_device *bldev;
+       struct backlight_device *bldev = NULL;
        struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
        struct panel_config *panel_config = NULL;
        int r, i;
@@ -990,7 +966,7 @@ static int taal_probe(struct omap_dss_device *dssdev)
 
        dssdev->panel.config = OMAP_DSS_LCD_TFT;
        dssdev->panel.timings = panel_config->timings;
-       dssdev->ctrl.pixel_size = 24;
+       dssdev->panel.dsi_pix_fmt = OMAP_DSS_DSI_FMT_RGB888;
 
        td = kzalloc(sizeof(*td), GFP_KERNEL);
        if (!td) {
@@ -1025,35 +1001,26 @@ static int taal_probe(struct omap_dss_device *dssdev)
 
        taal_hw_reset(dssdev);
 
-       /* if no platform set_backlight() defined, presume DSI backlight
-        * control */
-       memset(&props, 0, sizeof(struct backlight_properties));
-       if (!panel_data->set_backlight)
-               td->use_dsi_bl = true;
-
-       if (td->use_dsi_bl)
+       if (panel_data->use_dsi_backlight) {
+               memset(&props, 0, sizeof(struct backlight_properties));
                props.max_brightness = 255;
-       else
-               props.max_brightness = 127;
-
-       props.type = BACKLIGHT_RAW;
-       bldev = backlight_device_register(dev_name(&dssdev->dev), &dssdev->dev,
-                                       dssdev, &taal_bl_ops, &props);
-       if (IS_ERR(bldev)) {
-               r = PTR_ERR(bldev);
-               goto err_bl;
-       }
 
-       td->bldev = bldev;
+               props.type = BACKLIGHT_RAW;
+               bldev = backlight_device_register(dev_name(&dssdev->dev),
+                               &dssdev->dev, dssdev, &taal_bl_ops, &props);
+               if (IS_ERR(bldev)) {
+                       r = PTR_ERR(bldev);
+                       goto err_bl;
+               }
+
+               td->bldev = bldev;
 
-       bldev->props.fb_blank = FB_BLANK_UNBLANK;
-       bldev->props.power = FB_BLANK_UNBLANK;
-       if (td->use_dsi_bl)
+               bldev->props.fb_blank = FB_BLANK_UNBLANK;
+               bldev->props.power = FB_BLANK_UNBLANK;
                bldev->props.brightness = 255;
-       else
-               bldev->props.brightness = 127;
 
-       taal_bl_update_status(bldev);
+               taal_bl_update_status(bldev);
+       }
 
        if (panel_data->use_ext_te) {
                int gpio = panel_data->ext_te_gpio;
@@ -1067,7 +1034,7 @@ static int taal_probe(struct omap_dss_device *dssdev)
                gpio_direction_input(gpio);
 
                r = request_irq(gpio_to_irq(gpio), taal_te_isr,
-                               IRQF_DISABLED | IRQF_TRIGGER_RISING,
+                               IRQF_TRIGGER_RISING,
                                "taal vsync", dssdev);
 
                if (r) {
@@ -1111,7 +1078,8 @@ err_irq:
        if (panel_data->use_ext_te)
                gpio_free(panel_data->ext_te_gpio);
 err_gpio:
-       backlight_device_unregister(bldev);
+       if (bldev != NULL)
+               backlight_device_unregister(bldev);
 err_bl:
        destroy_workqueue(td->workqueue);
 err_wq:
@@ -1140,9 +1108,11 @@ static void __exit taal_remove(struct omap_dss_device *dssdev)
        }
 
        bldev = td->bldev;
-       bldev->props.power = FB_BLANK_POWERDOWN;
-       taal_bl_update_status(bldev);
-       backlight_device_unregister(bldev);
+       if (bldev != NULL) {
+               bldev->props.power = FB_BLANK_POWERDOWN;
+               taal_bl_update_status(bldev);
+               backlight_device_unregister(bldev);
+       }
 
        taal_cancel_ulps_work(dssdev);
        taal_cancel_esd_work(dssdev);
@@ -1195,7 +1165,8 @@ static int taal_power_on(struct omap_dss_device *dssdev)
        if (r)
                goto err;
 
-       r = taal_dcs_write_1(td, DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */
+       r = taal_dcs_write_1(td, MIPI_DCS_SET_PIXEL_FORMAT,
+               MIPI_DCS_PIXEL_FMT_24BIT);
        if (r)
                goto err;
 
@@ -1209,7 +1180,7 @@ static int taal_power_on(struct omap_dss_device *dssdev)
                        goto err;
        }
 
-       r = taal_dcs_write_0(td, DCS_DISPLAY_ON);
+       r = taal_dcs_write_0(td, MIPI_DCS_SET_DISPLAY_ON);
        if (r)
                goto err;
 
@@ -1246,7 +1217,7 @@ static void taal_power_off(struct omap_dss_device *dssdev)
        struct taal_data *td = dev_get_drvdata(&dssdev->dev);
        int r;
 
-       r = taal_dcs_write_0(td, DCS_DISPLAY_OFF);
+       r = taal_dcs_write_0(td, MIPI_DCS_SET_DISPLAY_OFF);
        if (!r)
                r = taal_sleep_in(td);
 
@@ -1529,9 +1500,9 @@ static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
        int r;
 
        if (enable)
-               r = taal_dcs_write_1(td, DCS_TEAR_ON, 0);
+               r = taal_dcs_write_1(td, MIPI_DCS_SET_TEAR_ON, 0);
        else
-               r = taal_dcs_write_0(td, DCS_TEAR_OFF);
+               r = taal_dcs_write_0(td, MIPI_DCS_SET_TEAR_OFF);
 
        if (!panel_data->use_ext_te)
                omapdss_dsi_enable_te(dssdev, enable);
@@ -1851,7 +1822,7 @@ static void taal_esd_work(struct work_struct *work)
                goto err;
        }
 
-       r = taal_dcs_read_1(td, DCS_RDDSDR, &state1);
+       r = taal_dcs_read_1(td, MIPI_DCS_GET_DIAGNOSTIC_RESULT, &state1);
        if (r) {
                dev_err(&dssdev->dev, "failed to read Taal status\n");
                goto err;
@@ -1864,7 +1835,7 @@ static void taal_esd_work(struct work_struct *work)
                goto err;
        }
 
-       r = taal_dcs_read_1(td, DCS_RDDSDR, &state2);
+       r = taal_dcs_read_1(td, MIPI_DCS_GET_DIAGNOSTIC_RESULT, &state2);
        if (r) {
                dev_err(&dssdev->dev, "failed to read Taal status\n");
                goto err;
@@ -1880,7 +1851,7 @@ static void taal_esd_work(struct work_struct *work)
        /* Self-diagnostics result is also shown on TE GPIO line. We need
         * to re-enable TE after self diagnostics */
        if (td->te_enabled && panel_data->use_ext_te) {
-               r = taal_dcs_write_1(td, DCS_TEAR_ON, 0);
+               r = taal_dcs_write_1(td, MIPI_DCS_SET_TEAR_ON, 0);
                if (r)
                        goto err;
        }
index 0d12524db14bd7c8b45f1d5813143335bd19cd0a..7be7c06a249ecd9cde3487a4862e1e1f9a2a2673 100644 (file)
@@ -1,5 +1,5 @@
 menuconfig OMAP2_DSS
-        tristate "OMAP2+ Display Subsystem support (EXPERIMENTAL)"
+        tristate "OMAP2+ Display Subsystem support"
         depends on ARCH_OMAP2PLUS
         help
          OMAP2+ Display Subsystem support.
index 10d9d3bb3e24c5b4f6eb9a9944a8ad6e9634ac32..bd34ac5b20264b21c94b58864b5239c5c3838fb3 100644 (file)
@@ -6,4 +6,4 @@ omapdss-$(CONFIG_OMAP2_DSS_VENC) += venc.o
 omapdss-$(CONFIG_OMAP2_DSS_SDI) += sdi.o
 omapdss-$(CONFIG_OMAP2_DSS_DSI) += dsi.o
 omapdss-$(CONFIG_OMAP4_DSS_HDMI) += hdmi.o \
-                                   hdmi_omap4_panel.o
+                                   hdmi_panel.o ti_hdmi_4xxx_ip.o
index 76821fefce9a9729a6134aa06e36906bfb3eb213..86ec12e16c7c4f8580a15c0e393daa3fb3420352 100644 (file)
@@ -144,6 +144,10 @@ static int dss_initialize_debugfs(void)
 #ifdef CONFIG_OMAP2_DSS_VENC
        debugfs_create_file("venc", S_IRUGO, dss_debugfs_dir,
                        &venc_dump_regs, &dss_debug_fops);
+#endif
+#ifdef CONFIG_OMAP4_DSS_HDMI
+       debugfs_create_file("hdmi", S_IRUGO, dss_debugfs_dir,
+                       &hdmi_dump_regs, &dss_debug_fops);
 #endif
        return 0;
 }
index 0f3961a1ce26b47887adfacad6a417f975ec4044..6892cfd2e3b7043755441165c8554245cb425a6d 100644 (file)
@@ -106,7 +106,7 @@ static struct {
        int irq;
        struct clk *dss_clk;
 
-       u32     fifo_size[3];
+       u32     fifo_size[MAX_DSS_OVERLAYS];
 
        spinlock_t irq_lock;
        u32 irq_error_mask;
@@ -171,172 +171,98 @@ static int dispc_get_ctx_loss_count(void)
 
 static void dispc_save_context(void)
 {
-       int i;
+       int i, j;
 
        DSSDBG("dispc_save_context\n");
 
        SR(IRQENABLE);
        SR(CONTROL);
        SR(CONFIG);
-       SR(DEFAULT_COLOR(OMAP_DSS_CHANNEL_LCD));
-       SR(DEFAULT_COLOR(OMAP_DSS_CHANNEL_DIGIT));
-       SR(TRANS_COLOR(OMAP_DSS_CHANNEL_LCD));
-       SR(TRANS_COLOR(OMAP_DSS_CHANNEL_DIGIT));
        SR(LINE_NUMBER);
-       SR(TIMING_H(OMAP_DSS_CHANNEL_LCD));
-       SR(TIMING_V(OMAP_DSS_CHANNEL_LCD));
-       SR(POL_FREQ(OMAP_DSS_CHANNEL_LCD));
-       SR(DIVISORo(OMAP_DSS_CHANNEL_LCD));
-       if (dss_has_feature(FEAT_GLOBAL_ALPHA))
+       if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
+                       dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
                SR(GLOBAL_ALPHA);
-       SR(SIZE_MGR(OMAP_DSS_CHANNEL_DIGIT));
-       SR(SIZE_MGR(OMAP_DSS_CHANNEL_LCD));
        if (dss_has_feature(FEAT_MGR_LCD2)) {
                SR(CONTROL2);
-               SR(DEFAULT_COLOR(OMAP_DSS_CHANNEL_LCD2));
-               SR(TRANS_COLOR(OMAP_DSS_CHANNEL_LCD2));
-               SR(SIZE_MGR(OMAP_DSS_CHANNEL_LCD2));
-               SR(TIMING_H(OMAP_DSS_CHANNEL_LCD2));
-               SR(TIMING_V(OMAP_DSS_CHANNEL_LCD2));
-               SR(POL_FREQ(OMAP_DSS_CHANNEL_LCD2));
-               SR(DIVISORo(OMAP_DSS_CHANNEL_LCD2));
                SR(CONFIG2);
        }
 
-       SR(OVL_BA0(OMAP_DSS_GFX));
-       SR(OVL_BA1(OMAP_DSS_GFX));
-       SR(OVL_POSITION(OMAP_DSS_GFX));
-       SR(OVL_SIZE(OMAP_DSS_GFX));
-       SR(OVL_ATTRIBUTES(OMAP_DSS_GFX));
-       SR(OVL_FIFO_THRESHOLD(OMAP_DSS_GFX));
-       SR(OVL_ROW_INC(OMAP_DSS_GFX));
-       SR(OVL_PIXEL_INC(OMAP_DSS_GFX));
-       SR(OVL_WINDOW_SKIP(OMAP_DSS_GFX));
-       SR(OVL_TABLE_BA(OMAP_DSS_GFX));
+       for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
+               SR(DEFAULT_COLOR(i));
+               SR(TRANS_COLOR(i));
+               SR(SIZE_MGR(i));
+               if (i == OMAP_DSS_CHANNEL_DIGIT)
+                       continue;
+               SR(TIMING_H(i));
+               SR(TIMING_V(i));
+               SR(POL_FREQ(i));
+               SR(DIVISORo(i));
 
-       SR(DATA_CYCLE1(OMAP_DSS_CHANNEL_LCD));
-       SR(DATA_CYCLE2(OMAP_DSS_CHANNEL_LCD));
-       SR(DATA_CYCLE3(OMAP_DSS_CHANNEL_LCD));
+               SR(DATA_CYCLE1(i));
+               SR(DATA_CYCLE2(i));
+               SR(DATA_CYCLE3(i));
 
-       if (dss_has_feature(FEAT_CPR)) {
-               SR(CPR_COEF_R(OMAP_DSS_CHANNEL_LCD));
-               SR(CPR_COEF_G(OMAP_DSS_CHANNEL_LCD));
-               SR(CPR_COEF_B(OMAP_DSS_CHANNEL_LCD));
-       }
-       if (dss_has_feature(FEAT_MGR_LCD2)) {
                if (dss_has_feature(FEAT_CPR)) {
-                       SR(CPR_COEF_B(OMAP_DSS_CHANNEL_LCD2));
-                       SR(CPR_COEF_G(OMAP_DSS_CHANNEL_LCD2));
-                       SR(CPR_COEF_R(OMAP_DSS_CHANNEL_LCD2));
+                       SR(CPR_COEF_R(i));
+                       SR(CPR_COEF_G(i));
+                       SR(CPR_COEF_B(i));
                }
-
-               SR(DATA_CYCLE1(OMAP_DSS_CHANNEL_LCD2));
-               SR(DATA_CYCLE2(OMAP_DSS_CHANNEL_LCD2));
-               SR(DATA_CYCLE3(OMAP_DSS_CHANNEL_LCD2));
        }
 
-       if (dss_has_feature(FEAT_PRELOAD))
-               SR(OVL_PRELOAD(OMAP_DSS_GFX));
-
-       /* VID1 */
-       SR(OVL_BA0(OMAP_DSS_VIDEO1));
-       SR(OVL_BA1(OMAP_DSS_VIDEO1));
-       SR(OVL_POSITION(OMAP_DSS_VIDEO1));
-       SR(OVL_SIZE(OMAP_DSS_VIDEO1));
-       SR(OVL_ATTRIBUTES(OMAP_DSS_VIDEO1));
-       SR(OVL_FIFO_THRESHOLD(OMAP_DSS_VIDEO1));
-       SR(OVL_ROW_INC(OMAP_DSS_VIDEO1));
-       SR(OVL_PIXEL_INC(OMAP_DSS_VIDEO1));
-       SR(OVL_FIR(OMAP_DSS_VIDEO1));
-       SR(OVL_PICTURE_SIZE(OMAP_DSS_VIDEO1));
-       SR(OVL_ACCU0(OMAP_DSS_VIDEO1));
-       SR(OVL_ACCU1(OMAP_DSS_VIDEO1));
-
-       for (i = 0; i < 8; i++)
-               SR(OVL_FIR_COEF_H(OMAP_DSS_VIDEO1, i));
-
-       for (i = 0; i < 8; i++)
-               SR(OVL_FIR_COEF_HV(OMAP_DSS_VIDEO1, i));
-
-       for (i = 0; i < 5; i++)
-               SR(OVL_CONV_COEF(OMAP_DSS_VIDEO1, i));
-
-       if (dss_has_feature(FEAT_FIR_COEF_V)) {
-               for (i = 0; i < 8; i++)
-                       SR(OVL_FIR_COEF_V(OMAP_DSS_VIDEO1, i));
-       }
-
-       if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
-               SR(OVL_BA0_UV(OMAP_DSS_VIDEO1));
-               SR(OVL_BA1_UV(OMAP_DSS_VIDEO1));
-               SR(OVL_FIR2(OMAP_DSS_VIDEO1));
-               SR(OVL_ACCU2_0(OMAP_DSS_VIDEO1));
-               SR(OVL_ACCU2_1(OMAP_DSS_VIDEO1));
-
-               for (i = 0; i < 8; i++)
-                       SR(OVL_FIR_COEF_H2(OMAP_DSS_VIDEO1, i));
-
-               for (i = 0; i < 8; i++)
-                       SR(OVL_FIR_COEF_HV2(OMAP_DSS_VIDEO1, i));
-
-               for (i = 0; i < 8; i++)
-                       SR(OVL_FIR_COEF_V2(OMAP_DSS_VIDEO1, i));
-       }
-       if (dss_has_feature(FEAT_ATTR2))
-               SR(OVL_ATTRIBUTES2(OMAP_DSS_VIDEO1));
-
-       if (dss_has_feature(FEAT_PRELOAD))
-               SR(OVL_PRELOAD(OMAP_DSS_VIDEO1));
-
-       /* VID2 */
-       SR(OVL_BA0(OMAP_DSS_VIDEO2));
-       SR(OVL_BA1(OMAP_DSS_VIDEO2));
-       SR(OVL_POSITION(OMAP_DSS_VIDEO2));
-       SR(OVL_SIZE(OMAP_DSS_VIDEO2));
-       SR(OVL_ATTRIBUTES(OMAP_DSS_VIDEO2));
-       SR(OVL_FIFO_THRESHOLD(OMAP_DSS_VIDEO2));
-       SR(OVL_ROW_INC(OMAP_DSS_VIDEO2));
-       SR(OVL_PIXEL_INC(OMAP_DSS_VIDEO2));
-       SR(OVL_FIR(OMAP_DSS_VIDEO2));
-       SR(OVL_PICTURE_SIZE(OMAP_DSS_VIDEO2));
-       SR(OVL_ACCU0(OMAP_DSS_VIDEO2));
-       SR(OVL_ACCU1(OMAP_DSS_VIDEO2));
+       for (i = 0; i < dss_feat_get_num_ovls(); i++) {
+               SR(OVL_BA0(i));
+               SR(OVL_BA1(i));
+               SR(OVL_POSITION(i));
+               SR(OVL_SIZE(i));
+               SR(OVL_ATTRIBUTES(i));
+               SR(OVL_FIFO_THRESHOLD(i));
+               SR(OVL_ROW_INC(i));
+               SR(OVL_PIXEL_INC(i));
+               if (dss_has_feature(FEAT_PRELOAD))
+                       SR(OVL_PRELOAD(i));
+               if (i == OMAP_DSS_GFX) {
+                       SR(OVL_WINDOW_SKIP(i));
+                       SR(OVL_TABLE_BA(i));
+                       continue;
+               }
+               SR(OVL_FIR(i));
+               SR(OVL_PICTURE_SIZE(i));
+               SR(OVL_ACCU0(i));
+               SR(OVL_ACCU1(i));
 
-       for (i = 0; i < 8; i++)
-               SR(OVL_FIR_COEF_H(OMAP_DSS_VIDEO2, i));
+               for (j = 0; j < 8; j++)
+                       SR(OVL_FIR_COEF_H(i, j));
 
-       for (i = 0; i < 8; i++)
-               SR(OVL_FIR_COEF_HV(OMAP_DSS_VIDEO2, i));
+               for (j = 0; j < 8; j++)
+                       SR(OVL_FIR_COEF_HV(i, j));
 
-       for (i = 0; i < 5; i++)
-               SR(OVL_CONV_COEF(OMAP_DSS_VIDEO2, i));
+               for (j = 0; j < 5; j++)
+                       SR(OVL_CONV_COEF(i, j));
 
-       if (dss_has_feature(FEAT_FIR_COEF_V)) {
-               for (i = 0; i < 8; i++)
-                       SR(OVL_FIR_COEF_V(OMAP_DSS_VIDEO2, i));
-       }
+               if (dss_has_feature(FEAT_FIR_COEF_V)) {
+                       for (j = 0; j < 8; j++)
+                               SR(OVL_FIR_COEF_V(i, j));
+               }
 
-       if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
-               SR(OVL_BA0_UV(OMAP_DSS_VIDEO2));
-               SR(OVL_BA1_UV(OMAP_DSS_VIDEO2));
-               SR(OVL_FIR2(OMAP_DSS_VIDEO2));
-               SR(OVL_ACCU2_0(OMAP_DSS_VIDEO2));
-               SR(OVL_ACCU2_1(OMAP_DSS_VIDEO2));
+               if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
+                       SR(OVL_BA0_UV(i));
+                       SR(OVL_BA1_UV(i));
+                       SR(OVL_FIR2(i));
+                       SR(OVL_ACCU2_0(i));
+                       SR(OVL_ACCU2_1(i));
 
-               for (i = 0; i < 8; i++)
-                       SR(OVL_FIR_COEF_H2(OMAP_DSS_VIDEO2, i));
+                       for (j = 0; j < 8; j++)
+                               SR(OVL_FIR_COEF_H2(i, j));
 
-               for (i = 0; i < 8; i++)
-                       SR(OVL_FIR_COEF_HV2(OMAP_DSS_VIDEO2, i));
+                       for (j = 0; j < 8; j++)
+                               SR(OVL_FIR_COEF_HV2(i, j));
 
-               for (i = 0; i < 8; i++)
-                       SR(OVL_FIR_COEF_V2(OMAP_DSS_VIDEO2, i));
+                       for (j = 0; j < 8; j++)
+                               SR(OVL_FIR_COEF_V2(i, j));
+               }
+               if (dss_has_feature(FEAT_ATTR2))
+                       SR(OVL_ATTRIBUTES2(i));
        }
-       if (dss_has_feature(FEAT_ATTR2))
-               SR(OVL_ATTRIBUTES2(OMAP_DSS_VIDEO2));
-
-       if (dss_has_feature(FEAT_PRELOAD))
-               SR(OVL_PRELOAD(OMAP_DSS_VIDEO2));
 
        if (dss_has_feature(FEAT_CORE_CLK_DIV))
                SR(DIVISOR);
@@ -349,7 +275,7 @@ static void dispc_save_context(void)
 
 static void dispc_restore_context(void)
 {
-       int i, ctx;
+       int i, j, ctx;
 
        DSSDBG("dispc_restore_context\n");
 
@@ -367,165 +293,89 @@ static void dispc_restore_context(void)
        /*RR(IRQENABLE);*/
        /*RR(CONTROL);*/
        RR(CONFIG);
-       RR(DEFAULT_COLOR(OMAP_DSS_CHANNEL_LCD));
-       RR(DEFAULT_COLOR(OMAP_DSS_CHANNEL_DIGIT));
-       RR(TRANS_COLOR(OMAP_DSS_CHANNEL_LCD));
-       RR(TRANS_COLOR(OMAP_DSS_CHANNEL_DIGIT));
        RR(LINE_NUMBER);
-       RR(TIMING_H(OMAP_DSS_CHANNEL_LCD));
-       RR(TIMING_V(OMAP_DSS_CHANNEL_LCD));
-       RR(POL_FREQ(OMAP_DSS_CHANNEL_LCD));
-       RR(DIVISORo(OMAP_DSS_CHANNEL_LCD));
-       if (dss_has_feature(FEAT_GLOBAL_ALPHA))
+       if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
+                       dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
                RR(GLOBAL_ALPHA);
-       RR(SIZE_MGR(OMAP_DSS_CHANNEL_DIGIT));
-       RR(SIZE_MGR(OMAP_DSS_CHANNEL_LCD));
-       if (dss_has_feature(FEAT_MGR_LCD2)) {
-               RR(DEFAULT_COLOR(OMAP_DSS_CHANNEL_LCD2));
-               RR(TRANS_COLOR(OMAP_DSS_CHANNEL_LCD2));
-               RR(SIZE_MGR(OMAP_DSS_CHANNEL_LCD2));
-               RR(TIMING_H(OMAP_DSS_CHANNEL_LCD2));
-               RR(TIMING_V(OMAP_DSS_CHANNEL_LCD2));
-               RR(POL_FREQ(OMAP_DSS_CHANNEL_LCD2));
-               RR(DIVISORo(OMAP_DSS_CHANNEL_LCD2));
+       if (dss_has_feature(FEAT_MGR_LCD2))
                RR(CONFIG2);
-       }
-
-       RR(OVL_BA0(OMAP_DSS_GFX));
-       RR(OVL_BA1(OMAP_DSS_GFX));
-       RR(OVL_POSITION(OMAP_DSS_GFX));
-       RR(OVL_SIZE(OMAP_DSS_GFX));
-       RR(OVL_ATTRIBUTES(OMAP_DSS_GFX));
-       RR(OVL_FIFO_THRESHOLD(OMAP_DSS_GFX));
-       RR(OVL_ROW_INC(OMAP_DSS_GFX));
-       RR(OVL_PIXEL_INC(OMAP_DSS_GFX));
-       RR(OVL_WINDOW_SKIP(OMAP_DSS_GFX));
-       RR(OVL_TABLE_BA(OMAP_DSS_GFX));
-
 
-       RR(DATA_CYCLE1(OMAP_DSS_CHANNEL_LCD));
-       RR(DATA_CYCLE2(OMAP_DSS_CHANNEL_LCD));
-       RR(DATA_CYCLE3(OMAP_DSS_CHANNEL_LCD));
+       for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
+               RR(DEFAULT_COLOR(i));
+               RR(TRANS_COLOR(i));
+               RR(SIZE_MGR(i));
+               if (i == OMAP_DSS_CHANNEL_DIGIT)
+                       continue;
+               RR(TIMING_H(i));
+               RR(TIMING_V(i));
+               RR(POL_FREQ(i));
+               RR(DIVISORo(i));
 
-       if (dss_has_feature(FEAT_CPR)) {
-               RR(CPR_COEF_R(OMAP_DSS_CHANNEL_LCD));
-               RR(CPR_COEF_G(OMAP_DSS_CHANNEL_LCD));
-               RR(CPR_COEF_B(OMAP_DSS_CHANNEL_LCD));
-       }
-       if (dss_has_feature(FEAT_MGR_LCD2)) {
-               RR(DATA_CYCLE1(OMAP_DSS_CHANNEL_LCD2));
-               RR(DATA_CYCLE2(OMAP_DSS_CHANNEL_LCD2));
-               RR(DATA_CYCLE3(OMAP_DSS_CHANNEL_LCD2));
+               RR(DATA_CYCLE1(i));
+               RR(DATA_CYCLE2(i));
+               RR(DATA_CYCLE3(i));
 
                if (dss_has_feature(FEAT_CPR)) {
-                       RR(CPR_COEF_B(OMAP_DSS_CHANNEL_LCD2));
-                       RR(CPR_COEF_G(OMAP_DSS_CHANNEL_LCD2));
-                       RR(CPR_COEF_R(OMAP_DSS_CHANNEL_LCD2));
+                       RR(CPR_COEF_R(i));
+                       RR(CPR_COEF_G(i));
+                       RR(CPR_COEF_B(i));
                }
        }
 
-       if (dss_has_feature(FEAT_PRELOAD))
-               RR(OVL_PRELOAD(OMAP_DSS_GFX));
-
-       /* VID1 */
-       RR(OVL_BA0(OMAP_DSS_VIDEO1));
-       RR(OVL_BA1(OMAP_DSS_VIDEO1));
-       RR(OVL_POSITION(OMAP_DSS_VIDEO1));
-       RR(OVL_SIZE(OMAP_DSS_VIDEO1));
-       RR(OVL_ATTRIBUTES(OMAP_DSS_VIDEO1));
-       RR(OVL_FIFO_THRESHOLD(OMAP_DSS_VIDEO1));
-       RR(OVL_ROW_INC(OMAP_DSS_VIDEO1));
-       RR(OVL_PIXEL_INC(OMAP_DSS_VIDEO1));
-       RR(OVL_FIR(OMAP_DSS_VIDEO1));
-       RR(OVL_PICTURE_SIZE(OMAP_DSS_VIDEO1));
-       RR(OVL_ACCU0(OMAP_DSS_VIDEO1));
-       RR(OVL_ACCU1(OMAP_DSS_VIDEO1));
-
-       for (i = 0; i < 8; i++)
-               RR(OVL_FIR_COEF_H(OMAP_DSS_VIDEO1, i));
-
-       for (i = 0; i < 8; i++)
-               RR(OVL_FIR_COEF_HV(OMAP_DSS_VIDEO1, i));
-
-       for (i = 0; i < 5; i++)
-               RR(OVL_CONV_COEF(OMAP_DSS_VIDEO1, i));
-
-       if (dss_has_feature(FEAT_FIR_COEF_V)) {
-               for (i = 0; i < 8; i++)
-                       RR(OVL_FIR_COEF_V(OMAP_DSS_VIDEO1, i));
-       }
-
-       if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
-               RR(OVL_BA0_UV(OMAP_DSS_VIDEO1));
-               RR(OVL_BA1_UV(OMAP_DSS_VIDEO1));
-               RR(OVL_FIR2(OMAP_DSS_VIDEO1));
-               RR(OVL_ACCU2_0(OMAP_DSS_VIDEO1));
-               RR(OVL_ACCU2_1(OMAP_DSS_VIDEO1));
-
-               for (i = 0; i < 8; i++)
-                       RR(OVL_FIR_COEF_H2(OMAP_DSS_VIDEO1, i));
-
-               for (i = 0; i < 8; i++)
-                       RR(OVL_FIR_COEF_HV2(OMAP_DSS_VIDEO1, i));
-
-               for (i = 0; i < 8; i++)
-                       RR(OVL_FIR_COEF_V2(OMAP_DSS_VIDEO1, i));
-       }
-       if (dss_has_feature(FEAT_ATTR2))
-               RR(OVL_ATTRIBUTES2(OMAP_DSS_VIDEO1));
-
-       if (dss_has_feature(FEAT_PRELOAD))
-               RR(OVL_PRELOAD(OMAP_DSS_VIDEO1));
-
-       /* VID2 */
-       RR(OVL_BA0(OMAP_DSS_VIDEO2));
-       RR(OVL_BA1(OMAP_DSS_VIDEO2));
-       RR(OVL_POSITION(OMAP_DSS_VIDEO2));
-       RR(OVL_SIZE(OMAP_DSS_VIDEO2));
-       RR(OVL_ATTRIBUTES(OMAP_DSS_VIDEO2));
-       RR(OVL_FIFO_THRESHOLD(OMAP_DSS_VIDEO2));
-       RR(OVL_ROW_INC(OMAP_DSS_VIDEO2));
-       RR(OVL_PIXEL_INC(OMAP_DSS_VIDEO2));
-       RR(OVL_FIR(OMAP_DSS_VIDEO2));
-       RR(OVL_PICTURE_SIZE(OMAP_DSS_VIDEO2));
-       RR(OVL_ACCU0(OMAP_DSS_VIDEO2));
-       RR(OVL_ACCU1(OMAP_DSS_VIDEO2));
+       for (i = 0; i < dss_feat_get_num_ovls(); i++) {
+               RR(OVL_BA0(i));
+               RR(OVL_BA1(i));
+               RR(OVL_POSITION(i));
+               RR(OVL_SIZE(i));
+               RR(OVL_ATTRIBUTES(i));
+               RR(OVL_FIFO_THRESHOLD(i));
+               RR(OVL_ROW_INC(i));
+               RR(OVL_PIXEL_INC(i));
+               if (dss_has_feature(FEAT_PRELOAD))
+                       RR(OVL_PRELOAD(i));
+               if (i == OMAP_DSS_GFX) {
+                       RR(OVL_WINDOW_SKIP(i));
+                       RR(OVL_TABLE_BA(i));
+                       continue;
+               }
+               RR(OVL_FIR(i));
+               RR(OVL_PICTURE_SIZE(i));
+               RR(OVL_ACCU0(i));
+               RR(OVL_ACCU1(i));
 
-       for (i = 0; i < 8; i++)
-               RR(OVL_FIR_COEF_H(OMAP_DSS_VIDEO2, i));
+               for (j = 0; j < 8; j++)
+                       RR(OVL_FIR_COEF_H(i, j));
 
-       for (i = 0; i < 8; i++)
-               RR(OVL_FIR_COEF_HV(OMAP_DSS_VIDEO2, i));
+               for (j = 0; j < 8; j++)
+                       RR(OVL_FIR_COEF_HV(i, j));
 
-       for (i = 0; i < 5; i++)
-               RR(OVL_CONV_COEF(OMAP_DSS_VIDEO2, i));
+               for (j = 0; j < 5; j++)
+                       RR(OVL_CONV_COEF(i, j));
 
-       if (dss_has_feature(FEAT_FIR_COEF_V)) {
-               for (i = 0; i < 8; i++)
-                       RR(OVL_FIR_COEF_V(OMAP_DSS_VIDEO2, i));
-       }
+               if (dss_has_feature(FEAT_FIR_COEF_V)) {
+                       for (j = 0; j < 8; j++)
+                               RR(OVL_FIR_COEF_V(i, j));
+               }
 
-       if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
-               RR(OVL_BA0_UV(OMAP_DSS_VIDEO2));
-               RR(OVL_BA1_UV(OMAP_DSS_VIDEO2));
-               RR(OVL_FIR2(OMAP_DSS_VIDEO2));
-               RR(OVL_ACCU2_0(OMAP_DSS_VIDEO2));
-               RR(OVL_ACCU2_1(OMAP_DSS_VIDEO2));
+               if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
+                       RR(OVL_BA0_UV(i));
+                       RR(OVL_BA1_UV(i));
+                       RR(OVL_FIR2(i));
+                       RR(OVL_ACCU2_0(i));
+                       RR(OVL_ACCU2_1(i));
 
-               for (i = 0; i < 8; i++)
-                       RR(OVL_FIR_COEF_H2(OMAP_DSS_VIDEO2, i));
+                       for (j = 0; j < 8; j++)
+                               RR(OVL_FIR_COEF_H2(i, j));
 
-               for (i = 0; i < 8; i++)
-                       RR(OVL_FIR_COEF_HV2(OMAP_DSS_VIDEO2, i));
+                       for (j = 0; j < 8; j++)
+                               RR(OVL_FIR_COEF_HV2(i, j));
 
-               for (i = 0; i < 8; i++)
-                       RR(OVL_FIR_COEF_V2(OMAP_DSS_VIDEO2, i));
+                       for (j = 0; j < 8; j++)
+                               RR(OVL_FIR_COEF_V2(i, j));
+               }
+               if (dss_has_feature(FEAT_ATTR2))
+                       RR(OVL_ATTRIBUTES2(i));
        }
-       if (dss_has_feature(FEAT_ATTR2))
-               RR(OVL_ATTRIBUTES2(OMAP_DSS_VIDEO2));
-
-       if (dss_has_feature(FEAT_PRELOAD))
-               RR(OVL_PRELOAD(OMAP_DSS_VIDEO2));
 
        if (dss_has_feature(FEAT_CORE_CLK_DIV))
                RR(DIVISOR);
@@ -570,13 +420,28 @@ void dispc_runtime_put(void)
        WARN_ON(r < 0);
 }
 
+static inline bool dispc_mgr_is_lcd(enum omap_channel channel)
+{
+       if (channel == OMAP_DSS_CHANNEL_LCD ||
+                       channel == OMAP_DSS_CHANNEL_LCD2)
+               return true;
+       else
+               return false;
+}
+
+static struct omap_dss_device *dispc_mgr_get_device(enum omap_channel channel)
+{
+       struct omap_overlay_manager *mgr =
+               omap_dss_get_overlay_manager(channel);
 
-bool dispc_go_busy(enum omap_channel channel)
+       return mgr ? mgr->device : NULL;
+}
+
+bool dispc_mgr_go_busy(enum omap_channel channel)
 {
        int bit;
 
-       if (channel == OMAP_DSS_CHANNEL_LCD ||
-                       channel == OMAP_DSS_CHANNEL_LCD2)
+       if (dispc_mgr_is_lcd(channel))
                bit = 5; /* GOLCD */
        else
                bit = 6; /* GODIGIT */
@@ -587,13 +452,12 @@ bool dispc_go_busy(enum omap_channel channel)
                return REG_GET(DISPC_CONTROL, bit, bit) == 1;
 }
 
-void dispc_go(enum omap_channel channel)
+void dispc_mgr_go(enum omap_channel channel)
 {
        int bit;
        bool enable_bit, go_bit;
 
-       if (channel == OMAP_DSS_CHANNEL_LCD ||
-                       channel == OMAP_DSS_CHANNEL_LCD2)
+       if (dispc_mgr_is_lcd(channel))
                bit = 0; /* LCDENABLE */
        else
                bit = 1; /* DIGITALENABLE */
@@ -607,8 +471,7 @@ void dispc_go(enum omap_channel channel)
        if (!enable_bit)
                return;
 
-       if (channel == OMAP_DSS_CHANNEL_LCD ||
-                       channel == OMAP_DSS_CHANNEL_LCD2)
+       if (dispc_mgr_is_lcd(channel))
                bit = 5; /* GOLCD */
        else
                bit = 6; /* GODIGIT */
@@ -632,43 +495,44 @@ void dispc_go(enum omap_channel channel)
                REG_FLD_MOD(DISPC_CONTROL, 1, bit, bit);
 }
 
-static void _dispc_write_firh_reg(enum omap_plane plane, int reg, u32 value)
+static void dispc_ovl_write_firh_reg(enum omap_plane plane, int reg, u32 value)
 {
        dispc_write_reg(DISPC_OVL_FIR_COEF_H(plane, reg), value);
 }
 
-static void _dispc_write_firhv_reg(enum omap_plane plane, int reg, u32 value)
+static void dispc_ovl_write_firhv_reg(enum omap_plane plane, int reg, u32 value)
 {
        dispc_write_reg(DISPC_OVL_FIR_COEF_HV(plane, reg), value);
 }
 
-static void _dispc_write_firv_reg(enum omap_plane plane, int reg, u32 value)
+static void dispc_ovl_write_firv_reg(enum omap_plane plane, int reg, u32 value)
 {
        dispc_write_reg(DISPC_OVL_FIR_COEF_V(plane, reg), value);
 }
 
-static void _dispc_write_firh2_reg(enum omap_plane plane, int reg, u32 value)
+static void dispc_ovl_write_firh2_reg(enum omap_plane plane, int reg, u32 value)
 {
        BUG_ON(plane == OMAP_DSS_GFX);
 
        dispc_write_reg(DISPC_OVL_FIR_COEF_H2(plane, reg), value);
 }
 
-static void _dispc_write_firhv2_reg(enum omap_plane plane, int reg, u32 value)
+static void dispc_ovl_write_firhv2_reg(enum omap_plane plane, int reg,
+               u32 value)
 {
        BUG_ON(plane == OMAP_DSS_GFX);
 
        dispc_write_reg(DISPC_OVL_FIR_COEF_HV2(plane, reg), value);
 }
 
-static void _dispc_write_firv2_reg(enum omap_plane plane, int reg, u32 value)
+static void dispc_ovl_write_firv2_reg(enum omap_plane plane, int reg, u32 value)
 {
        BUG_ON(plane == OMAP_DSS_GFX);
 
        dispc_write_reg(DISPC_OVL_FIR_COEF_V2(plane, reg), value);
 }
 
-static void _dispc_set_scale_coef(enum omap_plane plane, int hscaleup,
+static void dispc_ovl_set_scale_coef(enum omap_plane plane, int hscaleup,
                                  int vscaleup, int five_taps,
                                  enum omap_color_component color_comp)
 {
@@ -769,11 +633,11 @@ static void _dispc_set_scale_coef(enum omap_plane plane, int hscaleup,
                        | FLD_VAL(v_coef[i].vc2, 31, 24);
 
                if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
-                       _dispc_write_firh_reg(plane, i, h);
-                       _dispc_write_firhv_reg(plane, i, hv);
+                       dispc_ovl_write_firh_reg(plane, i, h);
+                       dispc_ovl_write_firhv_reg(plane, i, hv);
                } else {
-                       _dispc_write_firh2_reg(plane, i, h);
-                       _dispc_write_firhv2_reg(plane, i, hv);
+                       dispc_ovl_write_firh2_reg(plane, i, h);
+                       dispc_ovl_write_firhv2_reg(plane, i, hv);
                }
 
        }
@@ -784,15 +648,16 @@ static void _dispc_set_scale_coef(enum omap_plane plane, int hscaleup,
                        v = FLD_VAL(v_coef[i].vc00, 7, 0)
                                | FLD_VAL(v_coef[i].vc22, 15, 8);
                        if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y)
-                               _dispc_write_firv_reg(plane, i, v);
+                               dispc_ovl_write_firv_reg(plane, i, v);
                        else
-                               _dispc_write_firv2_reg(plane, i, v);
+                               dispc_ovl_write_firv2_reg(plane, i, v);
                }
        }
 }
 
 static void _dispc_setup_color_conv_coef(void)
 {
+       int i;
        const struct color_conv_coef {
                int  ry,  rcr,  rcb,   gy,  gcr,  gcb,   by,  bcr,  bcb;
                int  full_range;
@@ -806,65 +671,54 @@ static void _dispc_setup_color_conv_coef(void)
 
        ct = &ctbl_bt601_5;
 
-       dispc_write_reg(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO1, 0),
-               CVAL(ct->rcr, ct->ry));
-       dispc_write_reg(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO1, 1),
-               CVAL(ct->gy,  ct->rcb));
-       dispc_write_reg(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO1, 2),
-               CVAL(ct->gcb, ct->gcr));
-       dispc_write_reg(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO1, 3),
-               CVAL(ct->bcr, ct->by));
-       dispc_write_reg(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO1, 4),
-               CVAL(0, ct->bcb));
-
-       dispc_write_reg(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO2, 0),
-               CVAL(ct->rcr, ct->ry));
-       dispc_write_reg(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO2, 1),
-               CVAL(ct->gy, ct->rcb));
-       dispc_write_reg(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO2, 2),
-               CVAL(ct->gcb, ct->gcr));
-       dispc_write_reg(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO2, 3),
-               CVAL(ct->bcr, ct->by));
-       dispc_write_reg(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO2, 4),
-               CVAL(0, ct->bcb));
+       for (i = 1; i < dss_feat_get_num_ovls(); i++) {
+               dispc_write_reg(DISPC_OVL_CONV_COEF(i, 0),
+                       CVAL(ct->rcr, ct->ry));
+               dispc_write_reg(DISPC_OVL_CONV_COEF(i, 1),
+                       CVAL(ct->gy,  ct->rcb));
+               dispc_write_reg(DISPC_OVL_CONV_COEF(i, 2),
+                       CVAL(ct->gcb, ct->gcr));
+               dispc_write_reg(DISPC_OVL_CONV_COEF(i, 3),
+                       CVAL(ct->bcr, ct->by));
+               dispc_write_reg(DISPC_OVL_CONV_COEF(i, 4),
+                       CVAL(0, ct->bcb));
 
-#undef CVAL
+               REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), ct->full_range,
+                       11, 11);
+       }
 
-       REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(OMAP_DSS_VIDEO1),
-               ct->full_range, 11, 11);
-       REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(OMAP_DSS_VIDEO2),
-               ct->full_range, 11, 11);
+#undef CVAL
 }
 
 
-static void _dispc_set_plane_ba0(enum omap_plane plane, u32 paddr)
+static void dispc_ovl_set_ba0(enum omap_plane plane, u32 paddr)
 {
        dispc_write_reg(DISPC_OVL_BA0(plane), paddr);
 }
 
-static void _dispc_set_plane_ba1(enum omap_plane plane, u32 paddr)
+static void dispc_ovl_set_ba1(enum omap_plane plane, u32 paddr)
 {
        dispc_write_reg(DISPC_OVL_BA1(plane), paddr);
 }
 
-static void _dispc_set_plane_ba0_uv(enum omap_plane plane, u32 paddr)
+static void dispc_ovl_set_ba0_uv(enum omap_plane plane, u32 paddr)
 {
        dispc_write_reg(DISPC_OVL_BA0_UV(plane), paddr);
 }
 
-static void _dispc_set_plane_ba1_uv(enum omap_plane plane, u32 paddr)
+static void dispc_ovl_set_ba1_uv(enum omap_plane plane, u32 paddr)
 {
        dispc_write_reg(DISPC_OVL_BA1_UV(plane), paddr);
 }
 
-static void _dispc_set_plane_pos(enum omap_plane plane, int x, int y)
+static void dispc_ovl_set_pos(enum omap_plane plane, int x, int y)
 {
        u32 val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
 
        dispc_write_reg(DISPC_OVL_POSITION(plane), val);
 }
 
-static void _dispc_set_pic_size(enum omap_plane plane, int width, int height)
+static void dispc_ovl_set_pic_size(enum omap_plane plane, int width, int height)
 {
        u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
 
@@ -874,7 +728,7 @@ static void _dispc_set_pic_size(enum omap_plane plane, int width, int height)
                dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
 }
 
-static void _dispc_set_vid_size(enum omap_plane plane, int width, int height)
+static void dispc_ovl_set_vid_size(enum omap_plane plane, int width, int height)
 {
        u32 val;
 
@@ -885,44 +739,61 @@ static void _dispc_set_vid_size(enum omap_plane plane, int width, int height)
        dispc_write_reg(DISPC_OVL_SIZE(plane), val);
 }
 
-static void _dispc_set_pre_mult_alpha(enum omap_plane plane, bool enable)
+static void dispc_ovl_set_zorder(enum omap_plane plane, u8 zorder)
 {
-       if (!dss_has_feature(FEAT_PRE_MULT_ALPHA))
+       struct omap_overlay *ovl = omap_dss_get_overlay(plane);
+
+       if ((ovl->caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
                return;
 
-       if (!dss_has_feature(FEAT_GLOBAL_ALPHA_VID1) &&
-               plane == OMAP_DSS_VIDEO1)
+       REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), zorder, 27, 26);
+}
+
+static void dispc_ovl_enable_zorder_planes(void)
+{
+       int i;
+
+       if (!dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
                return;
 
-       REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
+       for (i = 0; i < dss_feat_get_num_ovls(); i++)
+               REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), 1, 25, 25);
 }
 
-static void _dispc_setup_global_alpha(enum omap_plane plane, u8 global_alpha)
+static void dispc_ovl_set_pre_mult_alpha(enum omap_plane plane, bool enable)
 {
-       if (!dss_has_feature(FEAT_GLOBAL_ALPHA))
+       struct omap_overlay *ovl = omap_dss_get_overlay(plane);
+
+       if ((ovl->caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
                return;
 
-       if (!dss_has_feature(FEAT_GLOBAL_ALPHA_VID1) &&
-               plane == OMAP_DSS_VIDEO1)
+       REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
+}
+
+static void dispc_ovl_setup_global_alpha(enum omap_plane plane, u8 global_alpha)
+{
+       static const unsigned shifts[] = { 0, 8, 16, 24, };
+       int shift;
+       struct omap_overlay *ovl = omap_dss_get_overlay(plane);
+
+       if ((ovl->caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
                return;
 
-       if (plane == OMAP_DSS_GFX)
-               REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, 7, 0);
-       else if (plane == OMAP_DSS_VIDEO2)
-               REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, 23, 16);
+       shift = shifts[plane];
+       REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift);
 }
 
-static void _dispc_set_pix_inc(enum omap_plane plane, s32 inc)
+static void dispc_ovl_set_pix_inc(enum omap_plane plane, s32 inc)
 {
        dispc_write_reg(DISPC_OVL_PIXEL_INC(plane), inc);
 }
 
-static void _dispc_set_row_inc(enum omap_plane plane, s32 inc)
+static void dispc_ovl_set_row_inc(enum omap_plane plane, s32 inc)
 {
        dispc_write_reg(DISPC_OVL_ROW_INC(plane), inc);
 }
 
-static void _dispc_set_color_mode(enum omap_plane plane,
+static void dispc_ovl_set_color_mode(enum omap_plane plane,
                enum omap_color_mode color_mode)
 {
        u32 m = 0;
@@ -1003,7 +874,7 @@ static void _dispc_set_color_mode(enum omap_plane plane,
        REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
 }
 
-void dispc_set_channel_out(enum omap_plane plane,
+static void dispc_ovl_set_channel_out(enum omap_plane plane,
                enum omap_channel channel)
 {
        int shift;
@@ -1016,6 +887,7 @@ void dispc_set_channel_out(enum omap_plane plane,
                break;
        case OMAP_DSS_VIDEO1:
        case OMAP_DSS_VIDEO2:
+       case OMAP_DSS_VIDEO3:
                shift = 16;
                break;
        default:
@@ -1050,24 +922,13 @@ void dispc_set_channel_out(enum omap_plane plane,
        dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
 }
 
-static void dispc_set_burst_size(enum omap_plane plane,
+static void dispc_ovl_set_burst_size(enum omap_plane plane,
                enum omap_burst_size burst_size)
 {
+       static const unsigned shifts[] = { 6, 14, 14, 14, };
        int shift;
 
-       switch (plane) {
-       case OMAP_DSS_GFX:
-               shift = 6;
-               break;
-       case OMAP_DSS_VIDEO1:
-       case OMAP_DSS_VIDEO2:
-               shift = 14;
-               break;
-       default:
-               BUG();
-               return;
-       }
-
+       shift = shifts[plane];
        REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), burst_size, shift + 1, shift);
 }
 
@@ -1078,10 +939,10 @@ static void dispc_configure_burst_sizes(void)
 
        /* Configure burst size always to maximum size */
        for (i = 0; i < omap_dss_get_num_overlays(); ++i)
-               dispc_set_burst_size(i, burst_size);
+               dispc_ovl_set_burst_size(i, burst_size);
 }
 
-u32 dispc_get_burst_size(enum omap_plane plane)
+u32 dispc_ovl_get_burst_size(enum omap_plane plane)
 {
        unsigned unit = dss_feat_get_burst_size_unit();
        /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
@@ -1102,7 +963,7 @@ void dispc_enable_gamma_table(bool enable)
        REG_FLD_MOD(DISPC_CONFIG, enable, 9, 9);
 }
 
-void dispc_enable_cpr(enum omap_channel channel, bool enable)
+void dispc_mgr_enable_cpr(enum omap_channel channel, bool enable)
 {
        u16 reg;
 
@@ -1116,12 +977,12 @@ void dispc_enable_cpr(enum omap_channel channel, bool enable)
        REG_FLD_MOD(reg, enable, 15, 15);
 }
 
-void dispc_set_cpr_coef(enum omap_channel channel,
+void dispc_mgr_set_cpr_coef(enum omap_channel channel,
                struct omap_dss_cpr_coefs *coefs)
 {
        u32 coef_r, coef_g, coef_b;
 
-       if (channel != OMAP_DSS_CHANNEL_LCD && channel != OMAP_DSS_CHANNEL_LCD2)
+       if (!dispc_mgr_is_lcd(channel))
                return;
 
        coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
@@ -1136,7 +997,7 @@ void dispc_set_cpr_coef(enum omap_channel channel,
        dispc_write_reg(DISPC_CPR_COEF_B(channel), coef_b);
 }
 
-static void _dispc_set_vid_color_conv(enum omap_plane plane, bool enable)
+static void dispc_ovl_set_vid_color_conv(enum omap_plane plane, bool enable)
 {
        u32 val;
 
@@ -1147,19 +1008,16 @@ static void _dispc_set_vid_color_conv(enum omap_plane plane, bool enable)
        dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
 }
 
-void dispc_enable_replication(enum omap_plane plane, bool enable)
+static void dispc_ovl_enable_replication(enum omap_plane plane, bool enable)
 {
-       int bit;
-
-       if (plane == OMAP_DSS_GFX)
-               bit = 5;
-       else
-               bit = 10;
+       static const unsigned shifts[] = { 5, 10, 10, 10 };
+       int shift;
 
-       REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, bit, bit);
+       shift = shifts[plane];
+       REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
 }
 
-void dispc_set_lcd_size(enum omap_channel channel, u16 width, u16 height)
+void dispc_mgr_set_lcd_size(enum omap_channel channel, u16 width, u16 height)
 {
        u32 val;
        BUG_ON((width > (1 << 11)) || (height > (1 << 11)));
@@ -1186,19 +1044,20 @@ static void dispc_read_plane_fifo_sizes(void)
 
        dss_feat_get_reg_field(FEAT_REG_FIFOSIZE, &start, &end);
 
-       for (plane = 0; plane < ARRAY_SIZE(dispc.fifo_size); ++plane) {
+       for (plane = 0; plane < dss_feat_get_num_ovls(); ++plane) {
                size = REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(plane), start, end);
                size *= unit;
                dispc.fifo_size[plane] = size;
        }
 }
 
-u32 dispc_get_plane_fifo_size(enum omap_plane plane)
+u32 dispc_ovl_get_fifo_size(enum omap_plane plane)
 {
        return dispc.fifo_size[plane];
 }
 
-void dispc_set_fifo_threshold(enum omap_plane plane, u32 low, u32 high)
+static void dispc_ovl_set_fifo_threshold(enum omap_plane plane, u32 low,
+               u32 high)
 {
        u8 hi_start, hi_end, lo_start, lo_end;
        u32 unit;
@@ -1233,7 +1092,7 @@ void dispc_enable_fifomerge(bool enable)
        REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 14, 14);
 }
 
-static void _dispc_set_fir(enum omap_plane plane,
+static void dispc_ovl_set_fir(enum omap_plane plane,
                                int hinc, int vinc,
                                enum omap_color_component color_comp)
 {
@@ -1256,7 +1115,7 @@ static void _dispc_set_fir(enum omap_plane plane,
        }
 }
 
-static void _dispc_set_vid_accu0(enum omap_plane plane, int haccu, int vaccu)
+static void dispc_ovl_set_vid_accu0(enum omap_plane plane, int haccu, int vaccu)
 {
        u32 val;
        u8 hor_start, hor_end, vert_start, vert_end;
@@ -1270,7 +1129,7 @@ static void _dispc_set_vid_accu0(enum omap_plane plane, int haccu, int vaccu)
        dispc_write_reg(DISPC_OVL_ACCU0(plane), val);
 }
 
-static void _dispc_set_vid_accu1(enum omap_plane plane, int haccu, int vaccu)
+static void dispc_ovl_set_vid_accu1(enum omap_plane plane, int haccu, int vaccu)
 {
        u32 val;
        u8 hor_start, hor_end, vert_start, vert_end;
@@ -1284,7 +1143,8 @@ static void _dispc_set_vid_accu1(enum omap_plane plane, int haccu, int vaccu)
        dispc_write_reg(DISPC_OVL_ACCU1(plane), val);
 }
 
-static void _dispc_set_vid_accu2_0(enum omap_plane plane, int haccu, int vaccu)
+static void dispc_ovl_set_vid_accu2_0(enum omap_plane plane, int haccu,
+               int vaccu)
 {
        u32 val;
 
@@ -1292,7 +1152,8 @@ static void _dispc_set_vid_accu2_0(enum omap_plane plane, int haccu, int vaccu)
        dispc_write_reg(DISPC_OVL_ACCU2_0(plane), val);
 }
 
-static void _dispc_set_vid_accu2_1(enum omap_plane plane, int haccu, int vaccu)
+static void dispc_ovl_set_vid_accu2_1(enum omap_plane plane, int haccu,
+               int vaccu)
 {
        u32 val;
 
@@ -1300,7 +1161,7 @@ static void _dispc_set_vid_accu2_1(enum omap_plane plane, int haccu, int vaccu)
        dispc_write_reg(DISPC_OVL_ACCU2_1(plane), val);
 }
 
-static void _dispc_set_scale_param(enum omap_plane plane,
+static void dispc_ovl_set_scale_param(enum omap_plane plane,
                u16 orig_width, u16 orig_height,
                u16 out_width, u16 out_height,
                bool five_taps, u8 rotation,
@@ -1312,15 +1173,16 @@ static void _dispc_set_scale_param(enum omap_plane plane,
        hscaleup = orig_width <= out_width;
        vscaleup = orig_height <= out_height;
 
-       _dispc_set_scale_coef(plane, hscaleup, vscaleup, five_taps, color_comp);
+       dispc_ovl_set_scale_coef(plane, hscaleup, vscaleup, five_taps,
+                       color_comp);
 
        fir_hinc = 1024 * orig_width / out_width;
        fir_vinc = 1024 * orig_height / out_height;
 
-       _dispc_set_fir(plane, fir_hinc, fir_vinc, color_comp);
+       dispc_ovl_set_fir(plane, fir_hinc, fir_vinc, color_comp);
 }
 
-static void _dispc_set_scaling_common(enum omap_plane plane,
+static void dispc_ovl_set_scaling_common(enum omap_plane plane,
                u16 orig_width, u16 orig_height,
                u16 out_width, u16 out_height,
                bool ilace, bool five_taps,
@@ -1331,7 +1193,7 @@ static void _dispc_set_scaling_common(enum omap_plane plane,
        int accu1 = 0;
        u32 l;
 
-       _dispc_set_scale_param(plane, orig_width, orig_height,
+       dispc_ovl_set_scale_param(plane, orig_width, orig_height,
                                out_width, out_height, five_taps,
                                rotation, DISPC_COLOR_COMPONENT_RGB_Y);
        l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
@@ -1370,11 +1232,11 @@ static void _dispc_set_scaling_common(enum omap_plane plane,
                }
        }
 
-       _dispc_set_vid_accu0(plane, 0, accu0);
-       _dispc_set_vid_accu1(plane, 0, accu1);
+       dispc_ovl_set_vid_accu0(plane, 0, accu0);
+       dispc_ovl_set_vid_accu1(plane, 0, accu1);
 }
 
-static void _dispc_set_scaling_uv(enum omap_plane plane,
+static void dispc_ovl_set_scaling_uv(enum omap_plane plane,
                u16 orig_width, u16 orig_height,
                u16 out_width, u16 out_height,
                bool ilace, bool five_taps,
@@ -1422,7 +1284,7 @@ static void _dispc_set_scaling_uv(enum omap_plane plane,
        if (out_height != orig_height)
                scale_y = true;
 
-       _dispc_set_scale_param(plane, orig_width, orig_height,
+       dispc_ovl_set_scale_param(plane, orig_width, orig_height,
                        out_width, out_height, five_taps,
                                rotation, DISPC_COLOR_COMPONENT_UV);
 
@@ -1433,11 +1295,11 @@ static void _dispc_set_scaling_uv(enum omap_plane plane,
        /* set V scaling */
        REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
 
-       _dispc_set_vid_accu2_0(plane, 0x80, 0);
-       _dispc_set_vid_accu2_1(plane, 0x80, 0);
+       dispc_ovl_set_vid_accu2_0(plane, 0x80, 0);
+       dispc_ovl_set_vid_accu2_1(plane, 0x80, 0);
 }
 
-static void _dispc_set_scaling(enum omap_plane plane,
+static void dispc_ovl_set_scaling(enum omap_plane plane,
                u16 orig_width, u16 orig_height,
                u16 out_width, u16 out_height,
                bool ilace, bool five_taps,
@@ -1446,14 +1308,14 @@ static void _dispc_set_scaling(enum omap_plane plane,
 {
        BUG_ON(plane == OMAP_DSS_GFX);
 
-       _dispc_set_scaling_common(plane,
+       dispc_ovl_set_scaling_common(plane,
                        orig_width, orig_height,
                        out_width, out_height,
                        ilace, five_taps,
                        fieldmode, color_mode,
                        rotation);
 
-       _dispc_set_scaling_uv(plane,
+       dispc_ovl_set_scaling_uv(plane,
                orig_width, orig_height,
                out_width, out_height,
                ilace, five_taps,
@@ -1461,7 +1323,7 @@ static void _dispc_set_scaling(enum omap_plane plane,
                rotation);
 }
 
-static void _dispc_set_rotation_attrs(enum omap_plane plane, u8 rotation,
+static void dispc_ovl_set_rotation_attrs(enum omap_plane plane, u8 rotation,
                bool mirroring, enum omap_color_mode color_mode)
 {
        bool row_repeat = false;
@@ -1789,12 +1651,11 @@ static unsigned long calc_fclk_five_taps(enum omap_channel channel, u16 width,
                enum omap_color_mode color_mode)
 {
        u32 fclk = 0;
-       /* FIXME venc pclk? */
-       u64 tmp, pclk = dispc_pclk_rate(channel);
+       u64 tmp, pclk = dispc_mgr_pclk_rate(channel);
 
        if (height > out_height) {
-               /* FIXME get real display PPL */
-               unsigned int ppl = 800;
+               struct omap_dss_device *dssdev = dispc_mgr_get_device(channel);
+               unsigned int ppl = dssdev->panel.timings.x_res;
 
                tmp = pclk * height * out_width;
                do_div(tmp, 2 * out_height * ppl);
@@ -1846,114 +1707,120 @@ static unsigned long calc_fclk(enum omap_channel channel, u16 width,
        else
                vf = 1;
 
-       /* FIXME venc pclk? */
-       return dispc_pclk_rate(channel) * vf * hf;
+       return dispc_mgr_pclk_rate(channel) * vf * hf;
 }
 
-int dispc_setup_plane(enum omap_plane plane,
-               u32 paddr, u16 screen_width,
-               u16 pos_x, u16 pos_y,
-               u16 width, u16 height,
+static int dispc_ovl_calc_scaling(enum omap_plane plane,
+               enum omap_channel channel, u16 width, u16 height,
                u16 out_width, u16 out_height,
-               enum omap_color_mode color_mode,
-               bool ilace,
-               enum omap_dss_rotation_type rotation_type,
-               u8 rotation, bool mirror,
-               u8 global_alpha, u8 pre_mult_alpha,
-               enum omap_channel channel, u32 puv_addr)
-{
-       const int maxdownscale = cpu_is_omap34xx() ? 4 : 2;
-       bool five_taps = 0;
-       bool fieldmode = 0;
-       int cconv = 0;
-       unsigned offset0, offset1;
-       s32 row_inc;
-       s32 pix_inc;
-       u16 frame_height = height;
-       unsigned int field_offset = 0;
+               enum omap_color_mode color_mode, bool *five_taps)
+{
+       struct omap_overlay *ovl = omap_dss_get_overlay(plane);
+       const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
+       unsigned long fclk = 0;
 
-       DSSDBG("dispc_setup_plane %d, pa %x, sw %d, %d,%d, %dx%d -> "
-              "%dx%d, ilace %d, cmode %x, rot %d, mir %d chan %d\n",
-              plane, paddr, screen_width, pos_x, pos_y,
-              width, height,
-              out_width, out_height,
-              ilace, color_mode,
-              rotation, mirror, channel);
+       if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) {
+               if (width != out_width || height != out_height)
+                       return -EINVAL;
+               else
+                       return 0;
+       }
 
-       if (paddr == 0)
+       if (out_width < width / maxdownscale ||
+                       out_width > width * 8)
                return -EINVAL;
 
-       if (ilace && height == out_height)
-               fieldmode = 1;
+       if (out_height < height / maxdownscale ||
+                       out_height > height * 8)
+               return -EINVAL;
 
-       if (ilace) {
-               if (fieldmode)
-                       height /= 2;
-               pos_y /= 2;
-               out_height /= 2;
+       /* Must use 5-tap filter? */
+       *five_taps = height > out_height * 2;
 
-               DSSDBG("adjusting for ilace: height %d, pos_y %d, "
-                               "out_height %d\n",
-                               height, pos_y, out_height);
+       if (!*five_taps) {
+               fclk = calc_fclk(channel, width, height, out_width,
+                               out_height);
+
+               /* Try 5-tap filter if 3-tap fclk is too high */
+               if (cpu_is_omap34xx() && height > out_height &&
+                               fclk > dispc_fclk_rate())
+                       *five_taps = true;
        }
 
-       if (!dss_feat_color_mode_supported(plane, color_mode))
+       if (width > (2048 >> *five_taps)) {
+               DSSERR("failed to set up scaling, fclk too low\n");
                return -EINVAL;
+       }
 
-       if (plane == OMAP_DSS_GFX) {
-               if (width != out_width || height != out_height)
-                       return -EINVAL;
-       } else {
-               /* video plane */
+       if (*five_taps)
+               fclk = calc_fclk_five_taps(channel, width, height,
+                               out_width, out_height, color_mode);
 
-               unsigned long fclk = 0;
+       DSSDBG("required fclk rate = %lu Hz\n", fclk);
+       DSSDBG("current fclk rate = %lu Hz\n", dispc_fclk_rate());
 
-               if (out_width < width / maxdownscale ||
-                  out_width > width * 8)
-                       return -EINVAL;
+       if (!fclk || fclk > dispc_fclk_rate()) {
+               DSSERR("failed to set up scaling, "
+                       "required fclk rate = %lu Hz, "
+                       "current fclk rate = %lu Hz\n",
+                       fclk, dispc_fclk_rate());
+               return -EINVAL;
+       }
 
-               if (out_height < height / maxdownscale ||
-                  out_height > height * 8)
-                       return -EINVAL;
+       return 0;
+}
 
-               if (color_mode == OMAP_DSS_COLOR_YUV2 ||
-                       color_mode == OMAP_DSS_COLOR_UYVY ||
-                       color_mode == OMAP_DSS_COLOR_NV12)
-                       cconv = 1;
+int dispc_ovl_setup(enum omap_plane plane, struct omap_overlay_info *oi,
+               bool ilace, enum omap_channel channel, bool replication,
+               u32 fifo_low, u32 fifo_high)
+{
+       struct omap_overlay *ovl = omap_dss_get_overlay(plane);
+       bool five_taps = false;
+       bool fieldmode = 0;
+       int r, cconv = 0;
+       unsigned offset0, offset1;
+       s32 row_inc;
+       s32 pix_inc;
+       u16 frame_height = oi->height;
+       unsigned int field_offset = 0;
 
-               /* Must use 5-tap filter? */
-               five_taps = height > out_height * 2;
+       DSSDBG("dispc_ovl_setup %d, pa %x, pa_uv %x, sw %d, %d,%d, %dx%d -> "
+               "%dx%d, cmode %x, rot %d, mir %d, ilace %d chan %d repl %d "
+               "fifo_low %d fifo high %d\n", plane, oi->paddr, oi->p_uv_addr,
+               oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
+               oi->out_width, oi->out_height, oi->color_mode, oi->rotation,
+               oi->mirror, ilace, channel, replication, fifo_low, fifo_high);
 
-               if (!five_taps) {
-                       fclk = calc_fclk(channel, width, height, out_width,
-                                       out_height);
+       if (oi->paddr == 0)
+               return -EINVAL;
 
-                       /* Try 5-tap filter if 3-tap fclk is too high */
-                       if (cpu_is_omap34xx() && height > out_height &&
-                                       fclk > dispc_fclk_rate())
-                               five_taps = true;
-               }
+       if (ilace && oi->height == oi->out_height)
+               fieldmode = 1;
 
-               if (width > (2048 >> five_taps)) {
-                       DSSERR("failed to set up scaling, fclk too low\n");
-                       return -EINVAL;
-               }
+       if (ilace) {
+               if (fieldmode)
+                       oi->height /= 2;
+               oi->pos_y /= 2;
+               oi->out_height /= 2;
 
-               if (five_taps)
-                       fclk = calc_fclk_five_taps(channel, width, height,
-                                       out_width, out_height, color_mode);
+               DSSDBG("adjusting for ilace: height %d, pos_y %d, "
+                               "out_height %d\n",
+                               oi->height, oi->pos_y, oi->out_height);
+       }
 
-               DSSDBG("required fclk rate = %lu Hz\n", fclk);
-               DSSDBG("current fclk rate = %lu Hz\n", dispc_fclk_rate());
+       if (!dss_feat_color_mode_supported(plane, oi->color_mode))
+               return -EINVAL;
 
-               if (!fclk || fclk > dispc_fclk_rate()) {
-                       DSSERR("failed to set up scaling, "
-                                       "required fclk rate = %lu Hz, "
-                                       "current fclk rate = %lu Hz\n",
-                                       fclk, dispc_fclk_rate());
-                       return -EINVAL;
-               }
-       }
+       r = dispc_ovl_calc_scaling(plane, channel, oi->width, oi->height,
+                       oi->out_width, oi->out_height, oi->color_mode,
+                       &five_taps);
+       if (r)
+               return r;
+
+       if (oi->color_mode == OMAP_DSS_COLOR_YUV2 ||
+                       oi->color_mode == OMAP_DSS_COLOR_UYVY ||
+                       oi->color_mode == OMAP_DSS_COLOR_NV12)
+               cconv = 1;
 
        if (ilace && !fieldmode) {
                /*
@@ -1963,69 +1830,76 @@ int dispc_setup_plane(enum omap_plane plane,
                 * so the integer part must be added to the base address of the
                 * bottom field.
                 */
-               if (!height || height == out_height)
+               if (!oi->height || oi->height == oi->out_height)
                        field_offset = 0;
                else
-                       field_offset = height / out_height / 2;
+                       field_offset = oi->height / oi->out_height / 2;
        }
 
        /* Fields are independent but interleaved in memory. */
        if (fieldmode)
                field_offset = 1;
 
-       if (rotation_type == OMAP_DSS_ROT_DMA)
-               calc_dma_rotation_offset(rotation, mirror,
-                               screen_width, width, frame_height, color_mode,
-                               fieldmode, field_offset,
+       if (oi->rotation_type == OMAP_DSS_ROT_DMA)
+               calc_dma_rotation_offset(oi->rotation, oi->mirror,
+                               oi->screen_width, oi->width, frame_height,
+                               oi->color_mode, fieldmode, field_offset,
                                &offset0, &offset1, &row_inc, &pix_inc);
        else
-               calc_vrfb_rotation_offset(rotation, mirror,
-                               screen_width, width, frame_height, color_mode,
-                               fieldmode, field_offset,
+               calc_vrfb_rotation_offset(oi->rotation, oi->mirror,
+                               oi->screen_width, oi->width, frame_height,
+                               oi->color_mode, fieldmode, field_offset,
                                &offset0, &offset1, &row_inc, &pix_inc);
 
        DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
                        offset0, offset1, row_inc, pix_inc);
 
-       _dispc_set_color_mode(plane, color_mode);
+       dispc_ovl_set_color_mode(plane, oi->color_mode);
 
-       _dispc_set_plane_ba0(plane, paddr + offset0);
-       _dispc_set_plane_ba1(plane, paddr + offset1);
+       dispc_ovl_set_ba0(plane, oi->paddr + offset0);
+       dispc_ovl_set_ba1(plane, oi->paddr + offset1);
 
-       if (OMAP_DSS_COLOR_NV12 == color_mode) {
-               _dispc_set_plane_ba0_uv(plane, puv_addr + offset0);
-               _dispc_set_plane_ba1_uv(plane, puv_addr + offset1);
+       if (OMAP_DSS_COLOR_NV12 == oi->color_mode) {
+               dispc_ovl_set_ba0_uv(plane, oi->p_uv_addr + offset0);
+               dispc_ovl_set_ba1_uv(plane, oi->p_uv_addr + offset1);
        }
 
 
-       _dispc_set_row_inc(plane, row_inc);
-       _dispc_set_pix_inc(plane, pix_inc);
+       dispc_ovl_set_row_inc(plane, row_inc);
+       dispc_ovl_set_pix_inc(plane, pix_inc);
 
-       DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, width, height,
-                       out_width, out_height);
+       DSSDBG("%d,%d %dx%d -> %dx%d\n", oi->pos_x, oi->pos_y, oi->width,
+                       oi->height, oi->out_width, oi->out_height);
 
-       _dispc_set_plane_pos(plane, pos_x, pos_y);
+       dispc_ovl_set_pos(plane, oi->pos_x, oi->pos_y);
 
-       _dispc_set_pic_size(plane, width, height);
+       dispc_ovl_set_pic_size(plane, oi->width, oi->height);
 
-       if (plane != OMAP_DSS_GFX) {
-               _dispc_set_scaling(plane, width, height,
-                                  out_width, out_height,
+       if (ovl->caps & OMAP_DSS_OVL_CAP_SCALE) {
+               dispc_ovl_set_scaling(plane, oi->width, oi->height,
+                                  oi->out_width, oi->out_height,
                                   ilace, five_taps, fieldmode,
-                                  color_mode, rotation);
-               _dispc_set_vid_size(plane, out_width, out_height);
-               _dispc_set_vid_color_conv(plane, cconv);
+                                  oi->color_mode, oi->rotation);
+               dispc_ovl_set_vid_size(plane, oi->out_width, oi->out_height);
+               dispc_ovl_set_vid_color_conv(plane, cconv);
        }
 
-       _dispc_set_rotation_attrs(plane, rotation, mirror, color_mode);
+       dispc_ovl_set_rotation_attrs(plane, oi->rotation, oi->mirror,
+                       oi->color_mode);
+
+       dispc_ovl_set_zorder(plane, oi->zorder);
+       dispc_ovl_set_pre_mult_alpha(plane, oi->pre_mult_alpha);
+       dispc_ovl_setup_global_alpha(plane, oi->global_alpha);
 
-       _dispc_set_pre_mult_alpha(plane, pre_mult_alpha);
-       _dispc_setup_global_alpha(plane, global_alpha);
+       dispc_ovl_set_channel_out(plane, channel);
+
+       dispc_ovl_enable_replication(plane, replication);
+       dispc_ovl_set_fifo_threshold(plane, fifo_low, fifo_high);
 
        return 0;
 }
 
-int dispc_enable_plane(enum omap_plane plane, bool enable)
+int dispc_ovl_enable(enum omap_plane plane, bool enable)
 {
        DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
 
@@ -2048,7 +1922,7 @@ static void _enable_lcd_out(enum omap_channel channel, bool enable)
                REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 0, 0);
 }
 
-static void dispc_enable_lcd_out(enum omap_channel channel, bool enable)
+static void dispc_mgr_enable_lcd_out(enum omap_channel channel, bool enable)
 {
        struct completion frame_done_completion;
        bool is_on;
@@ -2095,14 +1969,19 @@ static void _enable_digit_out(bool enable)
        REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 1, 1);
 }
 
-static void dispc_enable_digit_out(bool enable)
+static void dispc_mgr_enable_digit_out(bool enable)
 {
        struct completion frame_done_completion;
-       int r;
+       enum dss_hdmi_venc_clk_source_select src;
+       int r, i;
+       u32 irq_mask;
+       int num_irqs;
 
        if (REG_GET(DISPC_CONTROL, 1, 1) == enable)
                return;
 
+       src = dss_get_hdmi_venc_clk_source();
+
        if (enable) {
                unsigned long flags;
                /* When we enable digit output, we'll get an extra digit
@@ -2119,43 +1998,47 @@ static void dispc_enable_digit_out(bool enable)
         * wait for the extra sync losts */
        init_completion(&frame_done_completion);
 
+       if (src == DSS_HDMI_M_PCLK && enable == false) {
+               irq_mask = DISPC_IRQ_FRAMEDONETV;
+               num_irqs = 1;
+       } else {
+               irq_mask = DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD;
+               /* XXX I understand from TRM that we should only wait for the
+                * current field to complete. But it seems we have to wait for
+                * both fields */
+               num_irqs = 2;
+       }
+
        r = omap_dispc_register_isr(dispc_disable_isr, &frame_done_completion,
-                       DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD);
+                       irq_mask);
        if (r)
-               DSSERR("failed to register EVSYNC isr\n");
+               DSSERR("failed to register %x isr\n", irq_mask);
 
        _enable_digit_out(enable);
 
-       /* XXX I understand from TRM that we should only wait for the
-        * current field to complete. But it seems we have to wait
-        * for both fields */
-       if (!wait_for_completion_timeout(&frame_done_completion,
-                               msecs_to_jiffies(100)))
-               DSSERR("timeout waiting for EVSYNC\n");
-
-       if (!wait_for_completion_timeout(&frame_done_completion,
-                               msecs_to_jiffies(100)))
-               DSSERR("timeout waiting for EVSYNC\n");
+       for (i = 0; i < num_irqs; ++i) {
+               if (!wait_for_completion_timeout(&frame_done_completion,
+                                       msecs_to_jiffies(100)))
+                       DSSERR("timeout waiting for digit out to %s\n",
+                                       enable ? "start" : "stop");
+       }
 
-       r = omap_dispc_unregister_isr(dispc_disable_isr,
-                       &frame_done_completion,
-                       DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD);
+       r = omap_dispc_unregister_isr(dispc_disable_isr, &frame_done_completion,
+                       irq_mask);
        if (r)
-               DSSERR("failed to unregister EVSYNC isr\n");
+               DSSERR("failed to unregister %x isr\n", irq_mask);
 
        if (enable) {
                unsigned long flags;
                spin_lock_irqsave(&dispc.irq_lock, flags);
-               dispc.irq_error_mask = DISPC_IRQ_MASK_ERROR;
-               if (dss_has_feature(FEAT_MGR_LCD2))
-                       dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST2;
+               dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST_DIGIT;
                dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
                _omap_dispc_set_irqs();
                spin_unlock_irqrestore(&dispc.irq_lock, flags);
        }
 }
 
-bool dispc_is_channel_enabled(enum omap_channel channel)
+bool dispc_mgr_is_enabled(enum omap_channel channel)
 {
        if (channel == OMAP_DSS_CHANNEL_LCD)
                return !!REG_GET(DISPC_CONTROL, 0, 0);
@@ -2167,13 +2050,12 @@ bool dispc_is_channel_enabled(enum omap_channel channel)
                BUG();
 }
 
-void dispc_enable_channel(enum omap_channel channel, bool enable)
+void dispc_mgr_enable(enum omap_channel channel, bool enable)
 {
-       if (channel == OMAP_DSS_CHANNEL_LCD ||
-                       channel == OMAP_DSS_CHANNEL_LCD2)
-               dispc_enable_lcd_out(channel, enable);
+       if (dispc_mgr_is_lcd(channel))
+               dispc_mgr_enable_lcd_out(channel, enable);
        else if (channel == OMAP_DSS_CHANNEL_DIGIT)
-               dispc_enable_digit_out(enable);
+               dispc_mgr_enable_digit_out(enable);
        else
                BUG();
 }
@@ -2202,7 +2084,7 @@ void dispc_pck_free_enable(bool enable)
        REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
 }
 
-void dispc_enable_fifohandcheck(enum omap_channel channel, bool enable)
+void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable)
 {
        if (channel == OMAP_DSS_CHANNEL_LCD2)
                REG_FLD_MOD(DISPC_CONFIG2, enable ? 1 : 0, 16, 16);
@@ -2211,7 +2093,7 @@ void dispc_enable_fifohandcheck(enum omap_channel channel, bool enable)
 }
 
 
-void dispc_set_lcd_display_type(enum omap_channel channel,
+void dispc_mgr_set_lcd_display_type(enum omap_channel channel,
                enum omap_lcd_display_type type)
 {
        int mode;
@@ -2242,12 +2124,12 @@ void dispc_set_loadmode(enum omap_dss_load_mode mode)
 }
 
 
-void dispc_set_default_color(enum omap_channel channel, u32 color)
+void dispc_mgr_set_default_color(enum omap_channel channel, u32 color)
 {
        dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color);
 }
 
-u32 dispc_get_default_color(enum omap_channel channel)
+u32 dispc_mgr_get_default_color(enum omap_channel channel)
 {
        u32 l;
 
@@ -2260,7 +2142,7 @@ u32 dispc_get_default_color(enum omap_channel channel)
        return l;
 }
 
-void dispc_set_trans_key(enum omap_channel ch,
+void dispc_mgr_set_trans_key(enum omap_channel ch,
                enum omap_dss_trans_key_type type,
                u32 trans_key)
 {
@@ -2274,7 +2156,7 @@ void dispc_set_trans_key(enum omap_channel ch,
        dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key);
 }
 
-void dispc_get_trans_key(enum omap_channel ch,
+void dispc_mgr_get_trans_key(enum omap_channel ch,
                enum omap_dss_trans_key_type *type,
                u32 *trans_key)
 {
@@ -2293,7 +2175,7 @@ void dispc_get_trans_key(enum omap_channel ch,
                *trans_key = dispc_read_reg(DISPC_TRANS_COLOR(ch));
 }
 
-void dispc_enable_trans_key(enum omap_channel ch, bool enable)
+void dispc_mgr_enable_trans_key(enum omap_channel ch, bool enable)
 {
        if (ch == OMAP_DSS_CHANNEL_LCD)
                REG_FLD_MOD(DISPC_CONFIG, enable, 10, 10);
@@ -2302,39 +2184,36 @@ void dispc_enable_trans_key(enum omap_channel ch, bool enable)
        else /* OMAP_DSS_CHANNEL_LCD2 */
                REG_FLD_MOD(DISPC_CONFIG2, enable, 10, 10);
 }
-void dispc_enable_alpha_blending(enum omap_channel ch, bool enable)
+
+void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch, bool enable)
 {
-       if (!dss_has_feature(FEAT_GLOBAL_ALPHA))
+       if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
                return;
 
        if (ch == OMAP_DSS_CHANNEL_LCD)
                REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
        else if (ch == OMAP_DSS_CHANNEL_DIGIT)
                REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
-       else /* OMAP_DSS_CHANNEL_LCD2 */
-               REG_FLD_MOD(DISPC_CONFIG2, enable, 18, 18);
 }
-bool dispc_alpha_blending_enabled(enum omap_channel ch)
+
+bool dispc_mgr_alpha_fixed_zorder_enabled(enum omap_channel ch)
 {
        bool enabled;
 
-       if (!dss_has_feature(FEAT_GLOBAL_ALPHA))
+       if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
                return false;
 
        if (ch == OMAP_DSS_CHANNEL_LCD)
                enabled = REG_GET(DISPC_CONFIG, 18, 18);
        else if (ch == OMAP_DSS_CHANNEL_DIGIT)
                enabled = REG_GET(DISPC_CONFIG, 19, 19);
-       else if (ch == OMAP_DSS_CHANNEL_LCD2)
-               enabled = REG_GET(DISPC_CONFIG2, 18, 18);
        else
                BUG();
 
        return enabled;
 }
 
-
-bool dispc_trans_key_enabled(enum omap_channel ch)
+bool dispc_mgr_trans_key_enabled(enum omap_channel ch)
 {
        bool enabled;
 
@@ -2351,7 +2230,7 @@ bool dispc_trans_key_enabled(enum omap_channel ch)
 }
 
 
-void dispc_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
+void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
 {
        int code;
 
@@ -2379,46 +2258,41 @@ void dispc_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
                REG_FLD_MOD(DISPC_CONTROL, code, 9, 8);
 }
 
-void dispc_set_parallel_interface_mode(enum omap_channel channel,
-               enum omap_parallel_interface_mode mode)
+void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode)
 {
        u32 l;
-       int stallmode;
-       int gpout0 = 1;
-       int gpout1;
+       int gpout0, gpout1;
 
        switch (mode) {
-       case OMAP_DSS_PARALLELMODE_BYPASS:
-               stallmode = 0;
-               gpout1 = 1;
+       case DSS_IO_PAD_MODE_RESET:
+               gpout0 = 0;
+               gpout1 = 0;
                break;
-
-       case OMAP_DSS_PARALLELMODE_RFBI:
-               stallmode = 1;
+       case DSS_IO_PAD_MODE_RFBI:
+               gpout0 = 1;
                gpout1 = 0;
                break;
-
-       case OMAP_DSS_PARALLELMODE_DSI:
-               stallmode = 1;
+       case DSS_IO_PAD_MODE_BYPASS:
+               gpout0 = 1;
                gpout1 = 1;
                break;
-
        default:
                BUG();
                return;
        }
 
-       if (channel == OMAP_DSS_CHANNEL_LCD2) {
-               l = dispc_read_reg(DISPC_CONTROL2);
-               l = FLD_MOD(l, stallmode, 11, 11);
-               dispc_write_reg(DISPC_CONTROL2, l);
-       } else {
-               l = dispc_read_reg(DISPC_CONTROL);
-               l = FLD_MOD(l, stallmode, 11, 11);
-               l = FLD_MOD(l, gpout0, 15, 15);
-               l = FLD_MOD(l, gpout1, 16, 16);
-               dispc_write_reg(DISPC_CONTROL, l);
-       }
+       l = dispc_read_reg(DISPC_CONTROL);
+       l = FLD_MOD(l, gpout0, 15, 15);
+       l = FLD_MOD(l, gpout1, 16, 16);
+       dispc_write_reg(DISPC_CONTROL, l);
+}
+
+void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable)
+{
+       if (channel == OMAP_DSS_CHANNEL_LCD2)
+               REG_FLD_MOD(DISPC_CONTROL2, enable, 11, 11);
+       else
+               REG_FLD_MOD(DISPC_CONTROL, enable, 11, 11);
 }
 
 static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp,
@@ -2452,7 +2326,7 @@ bool dispc_lcd_timings_ok(struct omap_video_timings *timings)
                        timings->vfp, timings->vbp);
 }
 
-static void _dispc_set_lcd_timings(enum omap_channel channel, int hsw,
+static void _dispc_mgr_set_lcd_timings(enum omap_channel channel, int hsw,
                int hfp, int hbp, int vsw, int vfp, int vbp)
 {
        u32 timing_h, timing_v;
@@ -2476,7 +2350,7 @@ static void _dispc_set_lcd_timings(enum omap_channel channel, int hsw,
 }
 
 /* change name to mode? */
-void dispc_set_lcd_timings(enum omap_channel channel,
+void dispc_mgr_set_lcd_timings(enum omap_channel channel,
                struct omap_video_timings *timings)
 {
        unsigned xtot, ytot;
@@ -2487,11 +2361,11 @@ void dispc_set_lcd_timings(enum omap_channel channel,
                                timings->vfp, timings->vbp))
                BUG();
 
-       _dispc_set_lcd_timings(channel, timings->hsw, timings->hfp,
+       _dispc_mgr_set_lcd_timings(channel, timings->hsw, timings->hfp,
                        timings->hbp, timings->vsw, timings->vfp,
                        timings->vbp);
 
-       dispc_set_lcd_size(channel, timings->x_res, timings->y_res);
+       dispc_mgr_set_lcd_size(channel, timings->x_res, timings->y_res);
 
        xtot = timings->x_res + timings->hfp + timings->hsw + timings->hbp;
        ytot = timings->y_res + timings->vfp + timings->vsw + timings->vbp;
@@ -2509,17 +2383,17 @@ void dispc_set_lcd_timings(enum omap_channel channel,
        DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
 }
 
-static void dispc_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
+static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
                u16 pck_div)
 {
        BUG_ON(lck_div < 1);
-       BUG_ON(pck_div < 2);
+       BUG_ON(pck_div < 1);
 
        dispc_write_reg(DISPC_DIVISORo(channel),
                        FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
 }
 
-static void dispc_get_lcd_divisor(enum omap_channel channel, int *lck_div,
+static void dispc_mgr_get_lcd_divisor(enum omap_channel channel, int *lck_div,
                int *pck_div)
 {
        u32 l;
@@ -2552,7 +2426,7 @@ unsigned long dispc_fclk_rate(void)
        return r;
 }
 
-unsigned long dispc_lclk_rate(enum omap_channel channel)
+unsigned long dispc_mgr_lclk_rate(enum omap_channel channel)
 {
        struct platform_device *dsidev;
        int lcd;
@@ -2582,19 +2456,34 @@ unsigned long dispc_lclk_rate(enum omap_channel channel)
        return r / lcd;
 }
 
-unsigned long dispc_pclk_rate(enum omap_channel channel)
+unsigned long dispc_mgr_pclk_rate(enum omap_channel channel)
 {
-       int pcd;
        unsigned long r;
-       u32 l;
 
-       l = dispc_read_reg(DISPC_DIVISORo(channel));
+       if (dispc_mgr_is_lcd(channel)) {
+               int pcd;
+               u32 l;
 
-       pcd = FLD_GET(l, 7, 0);
+               l = dispc_read_reg(DISPC_DIVISORo(channel));
 
-       r = dispc_lclk_rate(channel);
+               pcd = FLD_GET(l, 7, 0);
 
-       return r / pcd;
+               r = dispc_mgr_lclk_rate(channel);
+
+               return r / pcd;
+       } else {
+               struct omap_dss_device *dssdev =
+                       dispc_mgr_get_device(channel);
+
+               switch (dssdev->type) {
+               case OMAP_DISPLAY_TYPE_VENC:
+                       return venc_get_pixel_clock();
+               case OMAP_DISPLAY_TYPE_HDMI:
+                       return hdmi_get_pixel_clock();
+               default:
+                       BUG();
+               }
+       }
 }
 
 void dispc_dump_clocks(struct seq_file *s)
@@ -2631,12 +2520,12 @@ void dispc_dump_clocks(struct seq_file *s)
                dss_get_generic_clk_source_name(lcd_clk_src),
                dss_feat_get_clk_source_name(lcd_clk_src));
 
-       dispc_get_lcd_divisor(OMAP_DSS_CHANNEL_LCD, &lcd, &pcd);
+       dispc_mgr_get_lcd_divisor(OMAP_DSS_CHANNEL_LCD, &lcd, &pcd);
 
        seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
-                       dispc_lclk_rate(OMAP_DSS_CHANNEL_LCD), lcd);
+                       dispc_mgr_lclk_rate(OMAP_DSS_CHANNEL_LCD), lcd);
        seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
-                       dispc_pclk_rate(OMAP_DSS_CHANNEL_LCD), pcd);
+                       dispc_mgr_pclk_rate(OMAP_DSS_CHANNEL_LCD), pcd);
        if (dss_has_feature(FEAT_MGR_LCD2)) {
                seq_printf(s, "- LCD2 -\n");
 
@@ -2646,12 +2535,12 @@ void dispc_dump_clocks(struct seq_file *s)
                        dss_get_generic_clk_source_name(lcd_clk_src),
                        dss_feat_get_clk_source_name(lcd_clk_src));
 
-               dispc_get_lcd_divisor(OMAP_DSS_CHANNEL_LCD2, &lcd, &pcd);
+               dispc_mgr_get_lcd_divisor(OMAP_DSS_CHANNEL_LCD2, &lcd, &pcd);
 
                seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
-                               dispc_lclk_rate(OMAP_DSS_CHANNEL_LCD2), lcd);
+                               dispc_mgr_lclk_rate(OMAP_DSS_CHANNEL_LCD2), lcd);
                seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
-                               dispc_pclk_rate(OMAP_DSS_CHANNEL_LCD2), pcd);
+                               dispc_mgr_pclk_rate(OMAP_DSS_CHANNEL_LCD2), pcd);
        }
 
        dispc_runtime_put();
@@ -2692,6 +2581,10 @@ void dispc_dump_irqs(struct seq_file *s)
        PIS(VID1_END_WIN);
        PIS(VID2_FIFO_UNDERFLOW);
        PIS(VID2_END_WIN);
+       if (dss_feat_get_num_ovls() > 3) {
+               PIS(VID3_FIFO_UNDERFLOW);
+               PIS(VID3_END_WIN);
+       }
        PIS(SYNC_LOST);
        PIS(SYNC_LOST_DIGIT);
        PIS(WAKEUP);
@@ -2707,11 +2600,26 @@ void dispc_dump_irqs(struct seq_file *s)
 
 void dispc_dump_regs(struct seq_file *s)
 {
+       int i, j;
+       const char *mgr_names[] = {
+               [OMAP_DSS_CHANNEL_LCD]          = "LCD",
+               [OMAP_DSS_CHANNEL_DIGIT]        = "TV",
+               [OMAP_DSS_CHANNEL_LCD2]         = "LCD2",
+       };
+       const char *ovl_names[] = {
+               [OMAP_DSS_GFX]          = "GFX",
+               [OMAP_DSS_VIDEO1]       = "VID1",
+               [OMAP_DSS_VIDEO2]       = "VID2",
+               [OMAP_DSS_VIDEO3]       = "VID3",
+       };
+       const char **p_names;
+
 #define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
 
        if (dispc_runtime_get())
                return;
 
+       /* DISPC common registers */
        DUMPREG(DISPC_REVISION);
        DUMPREG(DISPC_SYSCONFIG);
        DUMPREG(DISPC_SYSSTATUS);
@@ -2720,247 +2628,139 @@ void dispc_dump_regs(struct seq_file *s)
        DUMPREG(DISPC_CONTROL);
        DUMPREG(DISPC_CONFIG);
        DUMPREG(DISPC_CAPABLE);
-       DUMPREG(DISPC_DEFAULT_COLOR(OMAP_DSS_CHANNEL_LCD));
-       DUMPREG(DISPC_DEFAULT_COLOR(OMAP_DSS_CHANNEL_DIGIT));
-       DUMPREG(DISPC_TRANS_COLOR(OMAP_DSS_CHANNEL_LCD));
-       DUMPREG(DISPC_TRANS_COLOR(OMAP_DSS_CHANNEL_DIGIT));
        DUMPREG(DISPC_LINE_STATUS);
        DUMPREG(DISPC_LINE_NUMBER);
-       DUMPREG(DISPC_TIMING_H(OMAP_DSS_CHANNEL_LCD));
-       DUMPREG(DISPC_TIMING_V(OMAP_DSS_CHANNEL_LCD));
-       DUMPREG(DISPC_POL_FREQ(OMAP_DSS_CHANNEL_LCD));
-       DUMPREG(DISPC_DIVISORo(OMAP_DSS_CHANNEL_LCD));
-       if (dss_has_feature(FEAT_GLOBAL_ALPHA))
+       if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
+                       dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
                DUMPREG(DISPC_GLOBAL_ALPHA);
-       DUMPREG(DISPC_SIZE_MGR(OMAP_DSS_CHANNEL_DIGIT));
-       DUMPREG(DISPC_SIZE_MGR(OMAP_DSS_CHANNEL_LCD));
        if (dss_has_feature(FEAT_MGR_LCD2)) {
                DUMPREG(DISPC_CONTROL2);
                DUMPREG(DISPC_CONFIG2);
-               DUMPREG(DISPC_DEFAULT_COLOR(OMAP_DSS_CHANNEL_LCD2));
-               DUMPREG(DISPC_TRANS_COLOR(OMAP_DSS_CHANNEL_LCD2));
-               DUMPREG(DISPC_TIMING_H(OMAP_DSS_CHANNEL_LCD2));
-               DUMPREG(DISPC_TIMING_V(OMAP_DSS_CHANNEL_LCD2));
-               DUMPREG(DISPC_POL_FREQ(OMAP_DSS_CHANNEL_LCD2));
-               DUMPREG(DISPC_DIVISORo(OMAP_DSS_CHANNEL_LCD2));
-               DUMPREG(DISPC_SIZE_MGR(OMAP_DSS_CHANNEL_LCD2));
-       }
-
-       DUMPREG(DISPC_OVL_BA0(OMAP_DSS_GFX));
-       DUMPREG(DISPC_OVL_BA1(OMAP_DSS_GFX));
-       DUMPREG(DISPC_OVL_POSITION(OMAP_DSS_GFX));
-       DUMPREG(DISPC_OVL_SIZE(OMAP_DSS_GFX));
-       DUMPREG(DISPC_OVL_ATTRIBUTES(OMAP_DSS_GFX));
-       DUMPREG(DISPC_OVL_FIFO_THRESHOLD(OMAP_DSS_GFX));
-       DUMPREG(DISPC_OVL_FIFO_SIZE_STATUS(OMAP_DSS_GFX));
-       DUMPREG(DISPC_OVL_ROW_INC(OMAP_DSS_GFX));
-       DUMPREG(DISPC_OVL_PIXEL_INC(OMAP_DSS_GFX));
-       DUMPREG(DISPC_OVL_WINDOW_SKIP(OMAP_DSS_GFX));
-       DUMPREG(DISPC_OVL_TABLE_BA(OMAP_DSS_GFX));
-
-       DUMPREG(DISPC_DATA_CYCLE1(OMAP_DSS_CHANNEL_LCD));
-       DUMPREG(DISPC_DATA_CYCLE2(OMAP_DSS_CHANNEL_LCD));
-       DUMPREG(DISPC_DATA_CYCLE3(OMAP_DSS_CHANNEL_LCD));
-
-       if (dss_has_feature(FEAT_CPR)) {
-               DUMPREG(DISPC_CPR_COEF_R(OMAP_DSS_CHANNEL_LCD));
-               DUMPREG(DISPC_CPR_COEF_G(OMAP_DSS_CHANNEL_LCD));
-               DUMPREG(DISPC_CPR_COEF_B(OMAP_DSS_CHANNEL_LCD));
        }
-       if (dss_has_feature(FEAT_MGR_LCD2)) {
-               DUMPREG(DISPC_DATA_CYCLE1(OMAP_DSS_CHANNEL_LCD2));
-               DUMPREG(DISPC_DATA_CYCLE2(OMAP_DSS_CHANNEL_LCD2));
-               DUMPREG(DISPC_DATA_CYCLE3(OMAP_DSS_CHANNEL_LCD2));
+
+#undef DUMPREG
+
+#define DISPC_REG(i, name) name(i)
+#define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
+       48 - strlen(#r) - strlen(p_names[i]), " ", \
+       dispc_read_reg(DISPC_REG(i, r)))
+
+       p_names = mgr_names;
+
+       /* DISPC channel specific registers */
+       for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
+               DUMPREG(i, DISPC_DEFAULT_COLOR);
+               DUMPREG(i, DISPC_TRANS_COLOR);
+               DUMPREG(i, DISPC_SIZE_MGR);
+
+               if (i == OMAP_DSS_CHANNEL_DIGIT)
+                       continue;
+
+               DUMPREG(i, DISPC_DEFAULT_COLOR);
+               DUMPREG(i, DISPC_TRANS_COLOR);
+               DUMPREG(i, DISPC_TIMING_H);
+               DUMPREG(i, DISPC_TIMING_V);
+               DUMPREG(i, DISPC_POL_FREQ);
+               DUMPREG(i, DISPC_DIVISORo);
+               DUMPREG(i, DISPC_SIZE_MGR);
+
+               DUMPREG(i, DISPC_DATA_CYCLE1);
+               DUMPREG(i, DISPC_DATA_CYCLE2);
+               DUMPREG(i, DISPC_DATA_CYCLE3);
 
                if (dss_has_feature(FEAT_CPR)) {
-                       DUMPREG(DISPC_CPR_COEF_R(OMAP_DSS_CHANNEL_LCD2));
-                       DUMPREG(DISPC_CPR_COEF_G(OMAP_DSS_CHANNEL_LCD2));
-                       DUMPREG(DISPC_CPR_COEF_B(OMAP_DSS_CHANNEL_LCD2));
+                       DUMPREG(i, DISPC_CPR_COEF_R);
+                       DUMPREG(i, DISPC_CPR_COEF_G);
+                       DUMPREG(i, DISPC_CPR_COEF_B);
+               }
+       }
+
+       p_names = ovl_names;
+
+       for (i = 0; i < dss_feat_get_num_ovls(); i++) {
+               DUMPREG(i, DISPC_OVL_BA0);
+               DUMPREG(i, DISPC_OVL_BA1);
+               DUMPREG(i, DISPC_OVL_POSITION);
+               DUMPREG(i, DISPC_OVL_SIZE);
+               DUMPREG(i, DISPC_OVL_ATTRIBUTES);
+               DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
+               DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
+               DUMPREG(i, DISPC_OVL_ROW_INC);
+               DUMPREG(i, DISPC_OVL_PIXEL_INC);
+               if (dss_has_feature(FEAT_PRELOAD))
+                       DUMPREG(i, DISPC_OVL_PRELOAD);
+
+               if (i == OMAP_DSS_GFX) {
+                       DUMPREG(i, DISPC_OVL_WINDOW_SKIP);
+                       DUMPREG(i, DISPC_OVL_TABLE_BA);
+                       continue;
+               }
+
+               DUMPREG(i, DISPC_OVL_FIR);
+               DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
+               DUMPREG(i, DISPC_OVL_ACCU0);
+               DUMPREG(i, DISPC_OVL_ACCU1);
+               if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
+                       DUMPREG(i, DISPC_OVL_BA0_UV);
+                       DUMPREG(i, DISPC_OVL_BA1_UV);
+                       DUMPREG(i, DISPC_OVL_FIR2);
+                       DUMPREG(i, DISPC_OVL_ACCU2_0);
+                       DUMPREG(i, DISPC_OVL_ACCU2_1);
                }
+               if (dss_has_feature(FEAT_ATTR2))
+                       DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
+               if (dss_has_feature(FEAT_PRELOAD))
+                       DUMPREG(i, DISPC_OVL_PRELOAD);
        }
 
-       if (dss_has_feature(FEAT_PRELOAD))
-               DUMPREG(DISPC_OVL_PRELOAD(OMAP_DSS_GFX));
-
-       DUMPREG(DISPC_OVL_BA0(OMAP_DSS_VIDEO1));
-       DUMPREG(DISPC_OVL_BA1(OMAP_DSS_VIDEO1));
-       DUMPREG(DISPC_OVL_POSITION(OMAP_DSS_VIDEO1));
-       DUMPREG(DISPC_OVL_SIZE(OMAP_DSS_VIDEO1));
-       DUMPREG(DISPC_OVL_ATTRIBUTES(OMAP_DSS_VIDEO1));
-       DUMPREG(DISPC_OVL_FIFO_THRESHOLD(OMAP_DSS_VIDEO1));
-       DUMPREG(DISPC_OVL_FIFO_SIZE_STATUS(OMAP_DSS_VIDEO1));
-       DUMPREG(DISPC_OVL_ROW_INC(OMAP_DSS_VIDEO1));
-       DUMPREG(DISPC_OVL_PIXEL_INC(OMAP_DSS_VIDEO1));
-       DUMPREG(DISPC_OVL_FIR(OMAP_DSS_VIDEO1));
-       DUMPREG(DISPC_OVL_PICTURE_SIZE(OMAP_DSS_VIDEO1));
-       DUMPREG(DISPC_OVL_ACCU0(OMAP_DSS_VIDEO1));
-       DUMPREG(DISPC_OVL_ACCU1(OMAP_DSS_VIDEO1));
-
-       DUMPREG(DISPC_OVL_BA0(OMAP_DSS_VIDEO2));
-       DUMPREG(DISPC_OVL_BA1(OMAP_DSS_VIDEO2));
-       DUMPREG(DISPC_OVL_POSITION(OMAP_DSS_VIDEO2));
-       DUMPREG(DISPC_OVL_SIZE(OMAP_DSS_VIDEO2));
-       DUMPREG(DISPC_OVL_ATTRIBUTES(OMAP_DSS_VIDEO2));
-       DUMPREG(DISPC_OVL_FIFO_THRESHOLD(OMAP_DSS_VIDEO2));
-       DUMPREG(DISPC_OVL_FIFO_SIZE_STATUS(OMAP_DSS_VIDEO2));
-       DUMPREG(DISPC_OVL_ROW_INC(OMAP_DSS_VIDEO2));
-       DUMPREG(DISPC_OVL_PIXEL_INC(OMAP_DSS_VIDEO2));
-       DUMPREG(DISPC_OVL_FIR(OMAP_DSS_VIDEO2));
-       DUMPREG(DISPC_OVL_PICTURE_SIZE(OMAP_DSS_VIDEO2));
-       DUMPREG(DISPC_OVL_ACCU0(OMAP_DSS_VIDEO2));
-       DUMPREG(DISPC_OVL_ACCU1(OMAP_DSS_VIDEO2));
-
-       DUMPREG(DISPC_OVL_FIR_COEF_H(OMAP_DSS_VIDEO1, 0));
-       DUMPREG(DISPC_OVL_FIR_COEF_H(OMAP_DSS_VIDEO1, 1));
-       DUMPREG(DISPC_OVL_FIR_COEF_H(OMAP_DSS_VIDEO1, 2));
-       DUMPREG(DISPC_OVL_FIR_COEF_H(OMAP_DSS_VIDEO1, 3));
-       DUMPREG(DISPC_OVL_FIR_COEF_H(OMAP_DSS_VIDEO1, 4));
-       DUMPREG(DISPC_OVL_FIR_COEF_H(OMAP_DSS_VIDEO1, 5));
-       DUMPREG(DISPC_OVL_FIR_COEF_H(OMAP_DSS_VIDEO1, 6));
-       DUMPREG(DISPC_OVL_FIR_COEF_H(OMAP_DSS_VIDEO1, 7));
-       DUMPREG(DISPC_OVL_FIR_COEF_HV(OMAP_DSS_VIDEO1, 0));
-       DUMPREG(DISPC_OVL_FIR_COEF_HV(OMAP_DSS_VIDEO1, 1));
-       DUMPREG(DISPC_OVL_FIR_COEF_HV(OMAP_DSS_VIDEO1, 2));
-       DUMPREG(DISPC_OVL_FIR_COEF_HV(OMAP_DSS_VIDEO1, 3));
-       DUMPREG(DISPC_OVL_FIR_COEF_HV(OMAP_DSS_VIDEO1, 4));
-       DUMPREG(DISPC_OVL_FIR_COEF_HV(OMAP_DSS_VIDEO1, 5));
-       DUMPREG(DISPC_OVL_FIR_COEF_HV(OMAP_DSS_VIDEO1, 6));
-       DUMPREG(DISPC_OVL_FIR_COEF_HV(OMAP_DSS_VIDEO1, 7));
-       DUMPREG(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO1, 0));
-       DUMPREG(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO1, 1));
-       DUMPREG(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO1, 2));
-       DUMPREG(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO1, 3));
-       DUMPREG(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO1, 4));
-       if (dss_has_feature(FEAT_FIR_COEF_V)) {
-               DUMPREG(DISPC_OVL_FIR_COEF_V(OMAP_DSS_VIDEO1, 0));
-               DUMPREG(DISPC_OVL_FIR_COEF_V(OMAP_DSS_VIDEO1, 1));
-               DUMPREG(DISPC_OVL_FIR_COEF_V(OMAP_DSS_VIDEO1, 2));
-               DUMPREG(DISPC_OVL_FIR_COEF_V(OMAP_DSS_VIDEO1, 3));
-               DUMPREG(DISPC_OVL_FIR_COEF_V(OMAP_DSS_VIDEO1, 4));
-               DUMPREG(DISPC_OVL_FIR_COEF_V(OMAP_DSS_VIDEO1, 5));
-               DUMPREG(DISPC_OVL_FIR_COEF_V(OMAP_DSS_VIDEO1, 6));
-               DUMPREG(DISPC_OVL_FIR_COEF_V(OMAP_DSS_VIDEO1, 7));
-       }
-
-       if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
-               DUMPREG(DISPC_OVL_BA0_UV(OMAP_DSS_VIDEO1));
-               DUMPREG(DISPC_OVL_BA1_UV(OMAP_DSS_VIDEO1));
-               DUMPREG(DISPC_OVL_FIR2(OMAP_DSS_VIDEO1));
-               DUMPREG(DISPC_OVL_ACCU2_0(OMAP_DSS_VIDEO1));
-               DUMPREG(DISPC_OVL_ACCU2_1(OMAP_DSS_VIDEO1));
-
-               DUMPREG(DISPC_OVL_FIR_COEF_H2(OMAP_DSS_VIDEO1, 0));
-               DUMPREG(DISPC_OVL_FIR_COEF_H2(OMAP_DSS_VIDEO1, 1));
-               DUMPREG(DISPC_OVL_FIR_COEF_H2(OMAP_DSS_VIDEO1, 2));
-               DUMPREG(DISPC_OVL_FIR_COEF_H2(OMAP_DSS_VIDEO1, 3));
-               DUMPREG(DISPC_OVL_FIR_COEF_H2(OMAP_DSS_VIDEO1, 4));
-               DUMPREG(DISPC_OVL_FIR_COEF_H2(OMAP_DSS_VIDEO1, 5));
-               DUMPREG(DISPC_OVL_FIR_COEF_H2(OMAP_DSS_VIDEO1, 6));
-               DUMPREG(DISPC_OVL_FIR_COEF_H2(OMAP_DSS_VIDEO1, 7));
-
-               DUMPREG(DISPC_OVL_FIR_COEF_HV2(OMAP_DSS_VIDEO1, 0));
-               DUMPREG(DISPC_OVL_FIR_COEF_HV2(OMAP_DSS_VIDEO1, 1));
-               DUMPREG(DISPC_OVL_FIR_COEF_HV2(OMAP_DSS_VIDEO1, 2));
-               DUMPREG(DISPC_OVL_FIR_COEF_HV2(OMAP_DSS_VIDEO1, 3));
-               DUMPREG(DISPC_OVL_FIR_COEF_HV2(OMAP_DSS_VIDEO1, 4));
-               DUMPREG(DISPC_OVL_FIR_COEF_HV2(OMAP_DSS_VIDEO1, 5));
-               DUMPREG(DISPC_OVL_FIR_COEF_HV2(OMAP_DSS_VIDEO1, 6));
-               DUMPREG(DISPC_OVL_FIR_COEF_HV2(OMAP_DSS_VIDEO1, 7));
-
-               DUMPREG(DISPC_OVL_FIR_COEF_V2(OMAP_DSS_VIDEO1, 0));
-               DUMPREG(DISPC_OVL_FIR_COEF_V2(OMAP_DSS_VIDEO1, 1));
-               DUMPREG(DISPC_OVL_FIR_COEF_V2(OMAP_DSS_VIDEO1, 2));
-               DUMPREG(DISPC_OVL_FIR_COEF_V2(OMAP_DSS_VIDEO1, 3));
-               DUMPREG(DISPC_OVL_FIR_COEF_V2(OMAP_DSS_VIDEO1, 4));
-               DUMPREG(DISPC_OVL_FIR_COEF_V2(OMAP_DSS_VIDEO1, 5));
-               DUMPREG(DISPC_OVL_FIR_COEF_V2(OMAP_DSS_VIDEO1, 6));
-               DUMPREG(DISPC_OVL_FIR_COEF_V2(OMAP_DSS_VIDEO1, 7));
-       }
-       if (dss_has_feature(FEAT_ATTR2))
-               DUMPREG(DISPC_OVL_ATTRIBUTES2(OMAP_DSS_VIDEO1));
-
-
-       DUMPREG(DISPC_OVL_FIR_COEF_H(OMAP_DSS_VIDEO2, 0));
-       DUMPREG(DISPC_OVL_FIR_COEF_H(OMAP_DSS_VIDEO2, 1));
-       DUMPREG(DISPC_OVL_FIR_COEF_H(OMAP_DSS_VIDEO2, 2));
-       DUMPREG(DISPC_OVL_FIR_COEF_H(OMAP_DSS_VIDEO2, 3));
-       DUMPREG(DISPC_OVL_FIR_COEF_H(OMAP_DSS_VIDEO2, 4));
-       DUMPREG(DISPC_OVL_FIR_COEF_H(OMAP_DSS_VIDEO2, 5));
-       DUMPREG(DISPC_OVL_FIR_COEF_H(OMAP_DSS_VIDEO2, 6));
-       DUMPREG(DISPC_OVL_FIR_COEF_H(OMAP_DSS_VIDEO2, 7));
-       DUMPREG(DISPC_OVL_FIR_COEF_HV(OMAP_DSS_VIDEO2, 0));
-       DUMPREG(DISPC_OVL_FIR_COEF_HV(OMAP_DSS_VIDEO2, 1));
-       DUMPREG(DISPC_OVL_FIR_COEF_HV(OMAP_DSS_VIDEO2, 2));
-       DUMPREG(DISPC_OVL_FIR_COEF_HV(OMAP_DSS_VIDEO2, 3));
-       DUMPREG(DISPC_OVL_FIR_COEF_HV(OMAP_DSS_VIDEO2, 4));
-       DUMPREG(DISPC_OVL_FIR_COEF_HV(OMAP_DSS_VIDEO2, 5));
-       DUMPREG(DISPC_OVL_FIR_COEF_HV(OMAP_DSS_VIDEO2, 6));
-       DUMPREG(DISPC_OVL_FIR_COEF_HV(OMAP_DSS_VIDEO2, 7));
-       DUMPREG(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO2, 0));
-       DUMPREG(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO2, 1));
-       DUMPREG(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO2, 2));
-       DUMPREG(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO2, 3));
-       DUMPREG(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO2, 4));
-
-       if (dss_has_feature(FEAT_FIR_COEF_V)) {
-               DUMPREG(DISPC_OVL_FIR_COEF_V(OMAP_DSS_VIDEO2, 0));
-               DUMPREG(DISPC_OVL_FIR_COEF_V(OMAP_DSS_VIDEO2, 1));
-               DUMPREG(DISPC_OVL_FIR_COEF_V(OMAP_DSS_VIDEO2, 2));
-               DUMPREG(DISPC_OVL_FIR_COEF_V(OMAP_DSS_VIDEO2, 3));
-               DUMPREG(DISPC_OVL_FIR_COEF_V(OMAP_DSS_VIDEO2, 4));
-               DUMPREG(DISPC_OVL_FIR_COEF_V(OMAP_DSS_VIDEO2, 5));
-               DUMPREG(DISPC_OVL_FIR_COEF_V(OMAP_DSS_VIDEO2, 6));
-               DUMPREG(DISPC_OVL_FIR_COEF_V(OMAP_DSS_VIDEO2, 7));
-       }
-
-       if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
-               DUMPREG(DISPC_OVL_BA0_UV(OMAP_DSS_VIDEO2));
-               DUMPREG(DISPC_OVL_BA1_UV(OMAP_DSS_VIDEO2));
-               DUMPREG(DISPC_OVL_FIR2(OMAP_DSS_VIDEO2));
-               DUMPREG(DISPC_OVL_ACCU2_0(OMAP_DSS_VIDEO2));
-               DUMPREG(DISPC_OVL_ACCU2_1(OMAP_DSS_VIDEO2));
-
-               DUMPREG(DISPC_OVL_FIR_COEF_H2(OMAP_DSS_VIDEO2, 0));
-               DUMPREG(DISPC_OVL_FIR_COEF_H2(OMAP_DSS_VIDEO2, 1));
-               DUMPREG(DISPC_OVL_FIR_COEF_H2(OMAP_DSS_VIDEO2, 2));
-               DUMPREG(DISPC_OVL_FIR_COEF_H2(OMAP_DSS_VIDEO2, 3));
-               DUMPREG(DISPC_OVL_FIR_COEF_H2(OMAP_DSS_VIDEO2, 4));
-               DUMPREG(DISPC_OVL_FIR_COEF_H2(OMAP_DSS_VIDEO2, 5));
-               DUMPREG(DISPC_OVL_FIR_COEF_H2(OMAP_DSS_VIDEO2, 6));
-               DUMPREG(DISPC_OVL_FIR_COEF_H2(OMAP_DSS_VIDEO2, 7));
-
-               DUMPREG(DISPC_OVL_FIR_COEF_HV2(OMAP_DSS_VIDEO2, 0));
-               DUMPREG(DISPC_OVL_FIR_COEF_HV2(OMAP_DSS_VIDEO2, 1));
-               DUMPREG(DISPC_OVL_FIR_COEF_HV2(OMAP_DSS_VIDEO2, 2));
-               DUMPREG(DISPC_OVL_FIR_COEF_HV2(OMAP_DSS_VIDEO2, 3));
-               DUMPREG(DISPC_OVL_FIR_COEF_HV2(OMAP_DSS_VIDEO2, 4));
-               DUMPREG(DISPC_OVL_FIR_COEF_HV2(OMAP_DSS_VIDEO2, 5));
-               DUMPREG(DISPC_OVL_FIR_COEF_HV2(OMAP_DSS_VIDEO2, 6));
-               DUMPREG(DISPC_OVL_FIR_COEF_HV2(OMAP_DSS_VIDEO2, 7));
-
-               DUMPREG(DISPC_OVL_FIR_COEF_V2(OMAP_DSS_VIDEO2, 0));
-               DUMPREG(DISPC_OVL_FIR_COEF_V2(OMAP_DSS_VIDEO2, 1));
-               DUMPREG(DISPC_OVL_FIR_COEF_V2(OMAP_DSS_VIDEO2, 2));
-               DUMPREG(DISPC_OVL_FIR_COEF_V2(OMAP_DSS_VIDEO2, 3));
-               DUMPREG(DISPC_OVL_FIR_COEF_V2(OMAP_DSS_VIDEO2, 4));
-               DUMPREG(DISPC_OVL_FIR_COEF_V2(OMAP_DSS_VIDEO2, 5));
-               DUMPREG(DISPC_OVL_FIR_COEF_V2(OMAP_DSS_VIDEO2, 6));
-               DUMPREG(DISPC_OVL_FIR_COEF_V2(OMAP_DSS_VIDEO2, 7));
-       }
-       if (dss_has_feature(FEAT_ATTR2))
-               DUMPREG(DISPC_OVL_ATTRIBUTES2(OMAP_DSS_VIDEO2));
-
-       if (dss_has_feature(FEAT_PRELOAD)) {
-               DUMPREG(DISPC_OVL_PRELOAD(OMAP_DSS_VIDEO1));
-               DUMPREG(DISPC_OVL_PRELOAD(OMAP_DSS_VIDEO2));
+#undef DISPC_REG
+#undef DUMPREG
+
+#define DISPC_REG(plane, name, i) name(plane, i)
+#define DUMPREG(plane, name, i) \
+       seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
+       46 - strlen(#name) - strlen(p_names[plane]), " ", \
+       dispc_read_reg(DISPC_REG(plane, name, i)))
+
+       /* Video pipeline coefficient registers */
+
+       /* start from OMAP_DSS_VIDEO1 */
+       for (i = 1; i < dss_feat_get_num_ovls(); i++) {
+               for (j = 0; j < 8; j++)
+                       DUMPREG(i, DISPC_OVL_FIR_COEF_H, j);
+
+               for (j = 0; j < 8; j++)
+                       DUMPREG(i, DISPC_OVL_FIR_COEF_HV, j);
+
+               for (j = 0; j < 5; j++)
+                       DUMPREG(i, DISPC_OVL_CONV_COEF, j);
+
+               if (dss_has_feature(FEAT_FIR_COEF_V)) {
+                       for (j = 0; j < 8; j++)
+                               DUMPREG(i, DISPC_OVL_FIR_COEF_V, j);
+               }
+
+               if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
+                       for (j = 0; j < 8; j++)
+                               DUMPREG(i, DISPC_OVL_FIR_COEF_H2, j);
+
+                       for (j = 0; j < 8; j++)
+                               DUMPREG(i, DISPC_OVL_FIR_COEF_HV2, j);
+
+                       for (j = 0; j < 8; j++)
+                               DUMPREG(i, DISPC_OVL_FIR_COEF_V2, j);
+               }
        }
 
        dispc_runtime_put();
+
+#undef DISPC_REG
 #undef DUMPREG
 }
 
-static void _dispc_set_pol_freq(enum omap_channel channel, bool onoff, bool rf,
-               bool ieo, bool ipc, bool ihs, bool ivs, u8 acbi, u8 acb)
+static void _dispc_mgr_set_pol_freq(enum omap_channel channel, bool onoff,
+               bool rf, bool ieo, bool ipc, bool ihs, bool ivs, u8 acbi,
+               u8 acb)
 {
        u32 l = 0;
 
@@ -2979,10 +2779,10 @@ static void _dispc_set_pol_freq(enum omap_channel channel, bool onoff, bool rf,
        dispc_write_reg(DISPC_POL_FREQ(channel), l);
 }
 
-void dispc_set_pol_freq(enum omap_channel channel,
+void dispc_mgr_set_pol_freq(enum omap_channel channel,
                enum omap_panel_config config, u8 acbi, u8 acb)
 {
-       _dispc_set_pol_freq(channel, (config & OMAP_DSS_LCD_ONOFF) != 0,
+       _dispc_mgr_set_pol_freq(channel, (config & OMAP_DSS_LCD_ONOFF) != 0,
                        (config & OMAP_DSS_LCD_RF) != 0,
                        (config & OMAP_DSS_LCD_IEO) != 0,
                        (config & OMAP_DSS_LCD_IPC) != 0,
@@ -2995,11 +2795,17 @@ void dispc_set_pol_freq(enum omap_channel channel,
 void dispc_find_clk_divs(bool is_tft, unsigned long req_pck, unsigned long fck,
                struct dispc_clock_info *cinfo)
 {
-       u16 pcd_min = is_tft ? 2 : 3;
+       u16 pcd_min, pcd_max;
        unsigned long best_pck;
        u16 best_ld, cur_ld;
        u16 best_pd, cur_pd;
 
+       pcd_min = dss_feat_get_param_min(FEAT_PARAM_DSS_PCD);
+       pcd_max = dss_feat_get_param_max(FEAT_PARAM_DSS_PCD);
+
+       if (!is_tft)
+               pcd_min = 3;
+
        best_pck = 0;
        best_ld = 0;
        best_pd = 0;
@@ -3007,7 +2813,7 @@ void dispc_find_clk_divs(bool is_tft, unsigned long req_pck, unsigned long fck,
        for (cur_ld = 1; cur_ld <= 255; ++cur_ld) {
                unsigned long lck = fck / cur_ld;
 
-               for (cur_pd = pcd_min; cur_pd <= 255; ++cur_pd) {
+               for (cur_pd = pcd_min; cur_pd <= pcd_max; ++cur_pd) {
                        unsigned long pck = lck / cur_pd;
                        long old_delta = abs(best_pck - req_pck);
                        long new_delta = abs(pck - req_pck);
@@ -3042,7 +2848,7 @@ int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
 {
        if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
                return -EINVAL;
-       if (cinfo->pck_div < 2 || cinfo->pck_div > 255)
+       if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
                return -EINVAL;
 
        cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
@@ -3051,18 +2857,18 @@ int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
        return 0;
 }
 
-int dispc_set_clock_div(enum omap_channel channel,
+int dispc_mgr_set_clock_div(enum omap_channel channel,
                struct dispc_clock_info *cinfo)
 {
        DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
        DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
 
-       dispc_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
+       dispc_mgr_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
 
        return 0;
 }
 
-int dispc_get_clock_div(enum omap_channel channel,
+int dispc_mgr_get_clock_div(enum omap_channel channel,
                struct dispc_clock_info *cinfo)
 {
        unsigned long fck;
@@ -3207,6 +3013,8 @@ static void print_irq_status(u32 status)
        PIS(OCP_ERR);
        PIS(VID1_FIFO_UNDERFLOW);
        PIS(VID2_FIFO_UNDERFLOW);
+       if (dss_feat_get_num_ovls() > 3)
+               PIS(VID3_FIFO_UNDERFLOW);
        PIS(SYNC_LOST);
        PIS(SYNC_LOST_DIGIT);
        if (dss_has_feature(FEAT_MGR_LCD2))
@@ -3300,178 +3108,72 @@ static void dispc_error_worker(struct work_struct *work)
        int i;
        u32 errors;
        unsigned long flags;
+       static const unsigned fifo_underflow_bits[] = {
+               DISPC_IRQ_GFX_FIFO_UNDERFLOW,
+               DISPC_IRQ_VID1_FIFO_UNDERFLOW,
+               DISPC_IRQ_VID2_FIFO_UNDERFLOW,
+               DISPC_IRQ_VID3_FIFO_UNDERFLOW,
+       };
+
+       static const unsigned sync_lost_bits[] = {
+               DISPC_IRQ_SYNC_LOST,
+               DISPC_IRQ_SYNC_LOST_DIGIT,
+               DISPC_IRQ_SYNC_LOST2,
+       };
 
        spin_lock_irqsave(&dispc.irq_lock, flags);
        errors = dispc.error_irqs;
        dispc.error_irqs = 0;
        spin_unlock_irqrestore(&dispc.irq_lock, flags);
 
-       if (errors & DISPC_IRQ_GFX_FIFO_UNDERFLOW) {
-               DSSERR("GFX_FIFO_UNDERFLOW, disabling GFX\n");
-               for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
-                       struct omap_overlay *ovl;
-                       ovl = omap_dss_get_overlay(i);
-
-                       if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
-                               continue;
-
-                       if (ovl->id == 0) {
-                               dispc_enable_plane(ovl->id, 0);
-                               dispc_go(ovl->manager->id);
-                               mdelay(50);
-                               break;
-                       }
-               }
-       }
-
-       if (errors & DISPC_IRQ_VID1_FIFO_UNDERFLOW) {
-               DSSERR("VID1_FIFO_UNDERFLOW, disabling VID1\n");
-               for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
-                       struct omap_overlay *ovl;
-                       ovl = omap_dss_get_overlay(i);
-
-                       if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
-                               continue;
-
-                       if (ovl->id == 1) {
-                               dispc_enable_plane(ovl->id, 0);
-                               dispc_go(ovl->manager->id);
-                               mdelay(50);
-                               break;
-                       }
-               }
-       }
-
-       if (errors & DISPC_IRQ_VID2_FIFO_UNDERFLOW) {
-               DSSERR("VID2_FIFO_UNDERFLOW, disabling VID2\n");
-               for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
-                       struct omap_overlay *ovl;
-                       ovl = omap_dss_get_overlay(i);
-
-                       if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
-                               continue;
+       dispc_runtime_get();
 
-                       if (ovl->id == 2) {
-                               dispc_enable_plane(ovl->id, 0);
-                               dispc_go(ovl->manager->id);
-                               mdelay(50);
-                               break;
-                       }
-               }
-       }
-
-       if (errors & DISPC_IRQ_SYNC_LOST) {
-               struct omap_overlay_manager *manager = NULL;
-               bool enable = false;
+       for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
+               struct omap_overlay *ovl;
+               unsigned bit;
 
-               DSSERR("SYNC_LOST, disabling LCD\n");
+               ovl = omap_dss_get_overlay(i);
+               bit = fifo_underflow_bits[i];
 
-               for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
-                       struct omap_overlay_manager *mgr;
-                       mgr = omap_dss_get_overlay_manager(i);
-
-                       if (mgr->id == OMAP_DSS_CHANNEL_LCD) {
-                               manager = mgr;
-                               enable = mgr->device->state ==
-                                               OMAP_DSS_DISPLAY_ACTIVE;
-                               mgr->device->driver->disable(mgr->device);
-                               break;
-                       }
-               }
-
-               if (manager) {
-                       struct omap_dss_device *dssdev = manager->device;
-                       for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
-                               struct omap_overlay *ovl;
-                               ovl = omap_dss_get_overlay(i);
-
-                               if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
-                                       continue;
-
-                               if (ovl->id != 0 && ovl->manager == manager)
-                                       dispc_enable_plane(ovl->id, 0);
-                       }
-
-                       dispc_go(manager->id);
+               if (bit & errors) {
+                       DSSERR("FIFO UNDERFLOW on %s, disabling the overlay\n",
+                                       ovl->name);
+                       dispc_ovl_enable(ovl->id, false);
+                       dispc_mgr_go(ovl->manager->id);
                        mdelay(50);
-                       if (enable)
-                               dssdev->driver->enable(dssdev);
                }
        }
 
-       if (errors & DISPC_IRQ_SYNC_LOST_DIGIT) {
-               struct omap_overlay_manager *manager = NULL;
-               bool enable = false;
+       for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
+               struct omap_overlay_manager *mgr;
+               unsigned bit;
 
-               DSSERR("SYNC_LOST_DIGIT, disabling TV\n");
+               mgr = omap_dss_get_overlay_manager(i);
+               bit = sync_lost_bits[i];
 
-               for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
-                       struct omap_overlay_manager *mgr;
-                       mgr = omap_dss_get_overlay_manager(i);
+               if (bit & errors) {
+                       struct omap_dss_device *dssdev = mgr->device;
+                       bool enable;
 
-                       if (mgr->id == OMAP_DSS_CHANNEL_DIGIT) {
-                               manager = mgr;
-                               enable = mgr->device->state ==
-                                               OMAP_DSS_DISPLAY_ACTIVE;
-                               mgr->device->driver->disable(mgr->device);
-                               break;
-                       }
-               }
+                       DSSERR("SYNC_LOST on channel %s, restarting the output "
+                                       "with video overlays disabled\n",
+                                       mgr->name);
 
-               if (manager) {
-                       struct omap_dss_device *dssdev = manager->device;
-                       for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
-                               struct omap_overlay *ovl;
-                               ovl = omap_dss_get_overlay(i);
-
-                               if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
-                                       continue;
-
-                               if (ovl->id != 0 && ovl->manager == manager)
-                                       dispc_enable_plane(ovl->id, 0);
-                       }
+                       enable = dssdev->state == OMAP_DSS_DISPLAY_ACTIVE;
+                       dssdev->driver->disable(dssdev);
 
-                       dispc_go(manager->id);
-                       mdelay(50);
-                       if (enable)
-                               dssdev->driver->enable(dssdev);
-               }
-       }
-
-       if (errors & DISPC_IRQ_SYNC_LOST2) {
-               struct omap_overlay_manager *manager = NULL;
-               bool enable = false;
-
-               DSSERR("SYNC_LOST for LCD2, disabling LCD2\n");
-
-               for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
-                       struct omap_overlay_manager *mgr;
-                       mgr = omap_dss_get_overlay_manager(i);
-
-                       if (mgr->id == OMAP_DSS_CHANNEL_LCD2) {
-                               manager = mgr;
-                               enable = mgr->device->state ==
-                                               OMAP_DSS_DISPLAY_ACTIVE;
-                               mgr->device->driver->disable(mgr->device);
-                               break;
-                       }
-               }
-
-               if (manager) {
-                       struct omap_dss_device *dssdev = manager->device;
                        for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
                                struct omap_overlay *ovl;
                                ovl = omap_dss_get_overlay(i);
 
-                               if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
-                                       continue;
-
-                               if (ovl->id != 0 && ovl->manager == manager)
-                                       dispc_enable_plane(ovl->id, 0);
+                               if (ovl->id != OMAP_DSS_GFX &&
+                                               ovl->manager == mgr)
+                                       dispc_ovl_enable(ovl->id, false);
                        }
 
-                       dispc_go(manager->id);
+                       dispc_mgr_go(mgr->id);
                        mdelay(50);
+
                        if (enable)
                                dssdev->driver->enable(dssdev);
                }
@@ -3482,9 +3184,7 @@ static void dispc_error_worker(struct work_struct *work)
                for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
                        struct omap_overlay_manager *mgr;
                        mgr = omap_dss_get_overlay_manager(i);
-
-                       if (mgr->caps & OMAP_DSS_OVL_CAP_DISPC)
-                               mgr->device->driver->disable(mgr->device);
+                       mgr->device->driver->disable(mgr->device);
                }
        }
 
@@ -3492,6 +3192,8 @@ static void dispc_error_worker(struct work_struct *work)
        dispc.irq_error_mask |= errors;
        _omap_dispc_set_irqs();
        spin_unlock_irqrestore(&dispc.irq_lock, flags);
+
+       dispc_runtime_put();
 }
 
 int omap_dispc_wait_for_irq_timeout(u32 irqmask, unsigned long timeout)
@@ -3586,6 +3288,8 @@ static void _omap_dispc_initialize_irq(void)
        dispc.irq_error_mask = DISPC_IRQ_MASK_ERROR;
        if (dss_has_feature(FEAT_MGR_LCD2))
                dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST2;
+       if (dss_feat_get_num_ovls() > 3)
+               dispc.irq_error_mask |= DISPC_IRQ_VID3_FIFO_UNDERFLOW;
 
        /* there's SYNC_LOST_DIGIT waiting after enabling the DSS,
         * so clear it */
@@ -3635,6 +3339,8 @@ static void _omap_dispc_initial_config(void)
        dispc_read_plane_fifo_sizes();
 
        dispc_configure_burst_sizes();
+
+       dispc_ovl_enable_zorder_planes();
 }
 
 /* DISPC HW IP initialisation */
@@ -3734,7 +3440,6 @@ static int omap_dispchw_remove(struct platform_device *pdev)
 static int dispc_runtime_suspend(struct device *dev)
 {
        dispc_save_context();
-       clk_disable(dispc.dss_clk);
        dss_runtime_put();
 
        return 0;
@@ -3748,7 +3453,6 @@ static int dispc_runtime_resume(struct device *dev)
        if (r < 0)
                return r;
 
-       clk_enable(dispc.dss_clk);
        dispc_restore_context();
 
        return 0;
index 6c9ee0a0efb3208bdd5a3f1b52bc07704eb21974..c06efc38983e6ee74d8562fcfb9debaef545c843 100644 (file)
@@ -291,6 +291,8 @@ static inline u16 DISPC_OVL_BASE(enum omap_plane plane)
                return 0x00BC;
        case OMAP_DSS_VIDEO2:
                return 0x014C;
+       case OMAP_DSS_VIDEO3:
+               return 0x0300;
        default:
                BUG();
        }
@@ -304,6 +306,8 @@ static inline u16 DISPC_BA0_OFFSET(enum omap_plane plane)
        case OMAP_DSS_VIDEO1:
        case OMAP_DSS_VIDEO2:
                return 0x0000;
+       case OMAP_DSS_VIDEO3:
+               return 0x0008;
        default:
                BUG();
        }
@@ -316,6 +320,8 @@ static inline u16 DISPC_BA1_OFFSET(enum omap_plane plane)
        case OMAP_DSS_VIDEO1:
        case OMAP_DSS_VIDEO2:
                return 0x0004;
+       case OMAP_DSS_VIDEO3:
+               return 0x000C;
        default:
                BUG();
        }
@@ -330,6 +336,8 @@ static inline u16 DISPC_BA0_UV_OFFSET(enum omap_plane plane)
                return 0x0544;
        case OMAP_DSS_VIDEO2:
                return 0x04BC;
+       case OMAP_DSS_VIDEO3:
+               return 0x0310;
        default:
                BUG();
        }
@@ -344,6 +352,8 @@ static inline u16 DISPC_BA1_UV_OFFSET(enum omap_plane plane)
                return 0x0548;
        case OMAP_DSS_VIDEO2:
                return 0x04C0;
+       case OMAP_DSS_VIDEO3:
+               return 0x0314;
        default:
                BUG();
        }
@@ -356,6 +366,8 @@ static inline u16 DISPC_POS_OFFSET(enum omap_plane plane)
        case OMAP_DSS_VIDEO1:
        case OMAP_DSS_VIDEO2:
                return 0x0008;
+       case OMAP_DSS_VIDEO3:
+               return 0x009C;
        default:
                BUG();
        }
@@ -368,6 +380,8 @@ static inline u16 DISPC_SIZE_OFFSET(enum omap_plane plane)
        case OMAP_DSS_VIDEO1:
        case OMAP_DSS_VIDEO2:
                return 0x000C;
+       case OMAP_DSS_VIDEO3:
+               return 0x00A8;
        default:
                BUG();
        }
@@ -381,6 +395,8 @@ static inline u16 DISPC_ATTR_OFFSET(enum omap_plane plane)
        case OMAP_DSS_VIDEO1:
        case OMAP_DSS_VIDEO2:
                return 0x0010;
+       case OMAP_DSS_VIDEO3:
+               return 0x0070;
        default:
                BUG();
        }
@@ -395,6 +411,8 @@ static inline u16 DISPC_ATTR2_OFFSET(enum omap_plane plane)
                return 0x0568;
        case OMAP_DSS_VIDEO2:
                return 0x04DC;
+       case OMAP_DSS_VIDEO3:
+               return 0x032C;
        default:
                BUG();
        }
@@ -408,6 +426,8 @@ static inline u16 DISPC_FIFO_THRESH_OFFSET(enum omap_plane plane)
        case OMAP_DSS_VIDEO1:
        case OMAP_DSS_VIDEO2:
                return 0x0014;
+       case OMAP_DSS_VIDEO3:
+               return 0x008C;
        default:
                BUG();
        }
@@ -421,6 +441,8 @@ static inline u16 DISPC_FIFO_SIZE_STATUS_OFFSET(enum omap_plane plane)
        case OMAP_DSS_VIDEO1:
        case OMAP_DSS_VIDEO2:
                return 0x0018;
+       case OMAP_DSS_VIDEO3:
+               return 0x0088;
        default:
                BUG();
        }
@@ -434,6 +456,8 @@ static inline u16 DISPC_ROW_INC_OFFSET(enum omap_plane plane)
        case OMAP_DSS_VIDEO1:
        case OMAP_DSS_VIDEO2:
                return 0x001C;
+       case OMAP_DSS_VIDEO3:
+               return 0x00A4;
        default:
                BUG();
        }
@@ -447,6 +471,8 @@ static inline u16 DISPC_PIX_INC_OFFSET(enum omap_plane plane)
        case OMAP_DSS_VIDEO1:
        case OMAP_DSS_VIDEO2:
                return 0x0020;
+       case OMAP_DSS_VIDEO3:
+               return 0x0098;
        default:
                BUG();
        }
@@ -459,6 +485,7 @@ static inline u16 DISPC_WINDOW_SKIP_OFFSET(enum omap_plane plane)
                return 0x0034;
        case OMAP_DSS_VIDEO1:
        case OMAP_DSS_VIDEO2:
+       case OMAP_DSS_VIDEO3:
                BUG();
        default:
                BUG();
@@ -472,6 +499,7 @@ static inline u16 DISPC_TABLE_BA_OFFSET(enum omap_plane plane)
                return 0x0038;
        case OMAP_DSS_VIDEO1:
        case OMAP_DSS_VIDEO2:
+       case OMAP_DSS_VIDEO3:
                BUG();
        default:
                BUG();
@@ -486,6 +514,8 @@ static inline u16 DISPC_FIR_OFFSET(enum omap_plane plane)
        case OMAP_DSS_VIDEO1:
        case OMAP_DSS_VIDEO2:
                return 0x0024;
+       case OMAP_DSS_VIDEO3:
+               return 0x0090;
        default:
                BUG();
        }
@@ -500,6 +530,8 @@ static inline u16 DISPC_FIR2_OFFSET(enum omap_plane plane)
                return 0x0580;
        case OMAP_DSS_VIDEO2:
                return 0x055C;
+       case OMAP_DSS_VIDEO3:
+               return 0x0424;
        default:
                BUG();
        }
@@ -513,6 +545,8 @@ static inline u16 DISPC_PIC_SIZE_OFFSET(enum omap_plane plane)
        case OMAP_DSS_VIDEO1:
        case OMAP_DSS_VIDEO2:
                return 0x0028;
+       case OMAP_DSS_VIDEO3:
+               return 0x0094;
        default:
                BUG();
        }
@@ -527,6 +561,8 @@ static inline u16 DISPC_ACCU0_OFFSET(enum omap_plane plane)
        case OMAP_DSS_VIDEO1:
        case OMAP_DSS_VIDEO2:
                return 0x002C;
+       case OMAP_DSS_VIDEO3:
+               return 0x0000;
        default:
                BUG();
        }
@@ -541,6 +577,8 @@ static inline u16 DISPC_ACCU2_0_OFFSET(enum omap_plane plane)
                return 0x0584;
        case OMAP_DSS_VIDEO2:
                return 0x0560;
+       case OMAP_DSS_VIDEO3:
+               return 0x0428;
        default:
                BUG();
        }
@@ -554,6 +592,8 @@ static inline u16 DISPC_ACCU1_OFFSET(enum omap_plane plane)
        case OMAP_DSS_VIDEO1:
        case OMAP_DSS_VIDEO2:
                return 0x0030;
+       case OMAP_DSS_VIDEO3:
+               return 0x0004;
        default:
                BUG();
        }
@@ -568,6 +608,8 @@ static inline u16 DISPC_ACCU2_1_OFFSET(enum omap_plane plane)
                return 0x0588;
        case OMAP_DSS_VIDEO2:
                return 0x0564;
+       case OMAP_DSS_VIDEO3:
+               return 0x042C;
        default:
                BUG();
        }
@@ -582,6 +624,8 @@ static inline u16 DISPC_FIR_COEF_H_OFFSET(enum omap_plane plane, u16 i)
        case OMAP_DSS_VIDEO1:
        case OMAP_DSS_VIDEO2:
                return 0x0034 + i * 0x8;
+       case OMAP_DSS_VIDEO3:
+               return 0x0010 + i * 0x8;
        default:
                BUG();
        }
@@ -597,6 +641,8 @@ static inline u16 DISPC_FIR_COEF_H2_OFFSET(enum omap_plane plane, u16 i)
                return 0x058C + i * 0x8;
        case OMAP_DSS_VIDEO2:
                return 0x0568 + i * 0x8;
+       case OMAP_DSS_VIDEO3:
+               return 0x0430 + i * 0x8;
        default:
                BUG();
        }
@@ -611,6 +657,8 @@ static inline u16 DISPC_FIR_COEF_HV_OFFSET(enum omap_plane plane, u16 i)
        case OMAP_DSS_VIDEO1:
        case OMAP_DSS_VIDEO2:
                return 0x0038 + i * 0x8;
+       case OMAP_DSS_VIDEO3:
+               return 0x0014 + i * 0x8;
        default:
                BUG();
        }
@@ -626,6 +674,8 @@ static inline u16 DISPC_FIR_COEF_HV2_OFFSET(enum omap_plane plane, u16 i)
                return 0x0590 + i * 8;
        case OMAP_DSS_VIDEO2:
                return 0x056C + i * 0x8;
+       case OMAP_DSS_VIDEO3:
+               return 0x0434 + i * 0x8;
        default:
                BUG();
        }
@@ -639,6 +689,7 @@ static inline u16 DISPC_CONV_COEF_OFFSET(enum omap_plane plane, u16 i)
                BUG();
        case OMAP_DSS_VIDEO1:
        case OMAP_DSS_VIDEO2:
+       case OMAP_DSS_VIDEO3:
                return 0x0074 + i * 0x4;
        default:
                BUG();
@@ -655,6 +706,8 @@ static inline u16 DISPC_FIR_COEF_V_OFFSET(enum omap_plane plane, u16 i)
                return 0x0124 + i * 0x4;
        case OMAP_DSS_VIDEO2:
                return 0x00B4 + i * 0x4;
+       case OMAP_DSS_VIDEO3:
+               return 0x0050 + i * 0x4;
        default:
                BUG();
        }
@@ -670,6 +723,8 @@ static inline u16 DISPC_FIR_COEF_V2_OFFSET(enum omap_plane plane, u16 i)
                return 0x05CC + i * 0x4;
        case OMAP_DSS_VIDEO2:
                return 0x05A8 + i * 0x4;
+       case OMAP_DSS_VIDEO3:
+               return 0x0470 + i * 0x4;
        default:
                BUG();
        }
@@ -684,6 +739,8 @@ static inline u16 DISPC_PRELOAD_OFFSET(enum omap_plane plane)
                return 0x0174;
        case OMAP_DSS_VIDEO2:
                return 0x00E8;
+       case OMAP_DSS_VIDEO3:
+               return 0x00A0;
        default:
                BUG();
        }
index 94495e45ec5aca08e69fdb02489bab7776a68983..be331dc5a61bc04404f607c202315a26c668e50f 100644 (file)
@@ -45,14 +45,13 @@ static ssize_t display_enabled_store(struct device *dev,
                const char *buf, size_t size)
 {
        struct omap_dss_device *dssdev = to_dss_device(dev);
-       int r, enabled;
+       int r;
+       bool enabled;
 
-       r = kstrtoint(buf, 0, &enabled);
+       r = strtobool(buf, &enabled);
        if (r)
                return r;
 
-       enabled = !!enabled;
-
        if (enabled != (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)) {
                if (enabled) {
                        r = dssdev->driver->enable(dssdev);
@@ -79,17 +78,16 @@ static ssize_t display_tear_store(struct device *dev,
                struct device_attribute *attr, const char *buf, size_t size)
 {
        struct omap_dss_device *dssdev = to_dss_device(dev);
-       int te, r;
+       int r;
+       bool te;
 
        if (!dssdev->driver->enable_te || !dssdev->driver->get_te)
                return -ENOENT;
 
-       r = kstrtoint(buf, 0, &te);
+       r = strtobool(buf, &te);
        if (r)
                return r;
 
-       te = !!te;
-
        r = dssdev->driver->enable_te(dssdev, te);
        if (r)
                return r;
@@ -195,17 +193,16 @@ static ssize_t display_mirror_store(struct device *dev,
                struct device_attribute *attr, const char *buf, size_t size)
 {
        struct omap_dss_device *dssdev = to_dss_device(dev);
-       int mirror, r;
+       int r;
+       bool mirror;
 
        if (!dssdev->driver->set_mirror || !dssdev->driver->get_mirror)
                return -ENOENT;
 
-       r = kstrtoint(buf, 0, &mirror);
+       r = strtobool(buf, &mirror);
        if (r)
                return r;
 
-       mirror = !!mirror;
-
        r = dssdev->driver->set_mirror(dssdev, mirror);
        if (r)
                return r;
@@ -302,11 +299,15 @@ int omapdss_default_get_recommended_bpp(struct omap_dss_device *dssdev)
                        return 16;
 
        case OMAP_DISPLAY_TYPE_DBI:
-       case OMAP_DISPLAY_TYPE_DSI:
                if (dssdev->ctrl.pixel_size == 24)
                        return 24;
                else
                        return 16;
+       case OMAP_DISPLAY_TYPE_DSI:
+               if (dsi_get_pixel_size(dssdev->panel.dsi_pix_fmt) > 16)
+                       return 24;
+               else
+                       return 16;
        case OMAP_DISPLAY_TYPE_VENC:
        case OMAP_DISPLAY_TYPE_SDI:
        case OMAP_DISPLAY_TYPE_HDMI:
@@ -342,9 +343,11 @@ bool dss_use_replication(struct omap_dss_device *dssdev,
                bpp = 24;
                break;
        case OMAP_DISPLAY_TYPE_DBI:
-       case OMAP_DISPLAY_TYPE_DSI:
                bpp = dssdev->ctrl.pixel_size;
                break;
+       case OMAP_DISPLAY_TYPE_DSI:
+               bpp = dsi_get_pixel_size(dssdev->panel.dsi_pix_fmt);
+               break;
        default:
                BUG();
        }
index f053b180ecd7d14e00808c32afe4166e8e21d6d8..483888a85cfdbb78d5101193f67d171cc21ca451 100644 (file)
@@ -82,9 +82,11 @@ static int dpi_set_dsi_clk(struct omap_dss_device *dssdev, bool is_tft,
 
        dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
 
-       r = dispc_set_clock_div(dssdev->manager->id, &dispc_cinfo);
-       if (r)
+       r = dispc_mgr_set_clock_div(dssdev->manager->id, &dispc_cinfo);
+       if (r) {
+               dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
                return r;
+       }
 
        *fck = dsi_cinfo.dsi_pll_hsdiv_dispc_clk;
        *lck_div = dispc_cinfo.lck_div;
@@ -109,7 +111,7 @@ static int dpi_set_dispc_clk(struct omap_dss_device *dssdev, bool is_tft,
        if (r)
                return r;
 
-       r = dispc_set_clock_div(dssdev->manager->id, &dispc_cinfo);
+       r = dispc_mgr_set_clock_div(dssdev->manager->id, &dispc_cinfo);
        if (r)
                return r;
 
@@ -129,7 +131,7 @@ static int dpi_set_mode(struct omap_dss_device *dssdev)
        bool is_tft;
        int r = 0;
 
-       dispc_set_pol_freq(dssdev->manager->id, dssdev->panel.config,
+       dispc_mgr_set_pol_freq(dssdev->manager->id, dssdev->panel.config,
                        dssdev->panel.acbi, dssdev->panel.acb);
 
        is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0;
@@ -153,7 +155,7 @@ static int dpi_set_mode(struct omap_dss_device *dssdev)
                t->pixel_clock = pck;
        }
 
-       dispc_set_lcd_timings(dssdev->manager->id, t);
+       dispc_mgr_set_lcd_timings(dssdev->manager->id, t);
 
        return 0;
 }
@@ -164,11 +166,12 @@ static void dpi_basic_init(struct omap_dss_device *dssdev)
 
        is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0;
 
-       dispc_set_parallel_interface_mode(dssdev->manager->id,
-                       OMAP_DSS_PARALLELMODE_BYPASS);
-       dispc_set_lcd_display_type(dssdev->manager->id, is_tft ?
+       dispc_mgr_set_io_pad_mode(DSS_IO_PAD_MODE_BYPASS);
+       dispc_mgr_enable_stallmode(dssdev->manager->id, false);
+
+       dispc_mgr_set_lcd_display_type(dssdev->manager->id, is_tft ?
                        OMAP_DSS_LCD_DISPLAY_TFT : OMAP_DSS_LCD_DISPLAY_STN);
-       dispc_set_tft_data_lines(dssdev->manager->id,
+       dispc_mgr_set_tft_data_lines(dssdev->manager->id,
                        dssdev->phy.dpi.data_lines);
 }
 
@@ -176,6 +179,11 @@ int omapdss_dpi_display_enable(struct omap_dss_device *dssdev)
 {
        int r;
 
+       if (dssdev->manager == NULL) {
+               DSSERR("failed to enable display: no manager\n");
+               return -ENODEV;
+       }
+
        r = omap_dss_start_device(dssdev);
        if (r) {
                DSSERR("failed to start device\n");
@@ -277,7 +285,7 @@ void dpi_set_timings(struct omap_dss_device *dssdev,
                }
 
                dpi_set_mode(dssdev);
-               dispc_go(dssdev->manager->id);
+               dispc_mgr_go(dssdev->manager->id);
 
                dispc_runtime_put();
                dss_runtime_put();
index 7adbbeb84334f3a9ec857c8f7d00b394b2082f6c..43c04a9889c46214819781126d841e38bf004e62 100644 (file)
@@ -39,6 +39,7 @@
 #include <linux/pm_runtime.h>
 
 #include <video/omapdss.h>
+#include <video/mipi_display.h>
 #include <plat/clock.h>
 
 #include "dss.h"
@@ -131,7 +132,7 @@ struct dsi_reg { u16 idx; };
 #define DSI_IRQ_TA_TIMEOUT     (1 << 20)
 #define DSI_IRQ_ERROR_MASK \
        (DSI_IRQ_HS_TX_TIMEOUT | DSI_IRQ_LP_RX_TIMEOUT | DSI_IRQ_SYNC_LOST | \
-       DSI_IRQ_TA_TIMEOUT)
+       DSI_IRQ_TA_TIMEOUT | DSI_IRQ_SYNC_LOST)
 #define DSI_IRQ_CHANNEL_MASK   0xf
 
 /* Virtual channel interrupts */
@@ -198,18 +199,6 @@ struct dsi_reg { u16 idx; };
         DSI_CIO_IRQ_ERRCONTENTIONLP0_4 | DSI_CIO_IRQ_ERRCONTENTIONLP1_4 | \
         DSI_CIO_IRQ_ERRCONTENTIONLP0_5 | DSI_CIO_IRQ_ERRCONTENTIONLP1_5)
 
-#define DSI_DT_DCS_SHORT_WRITE_0       0x05
-#define DSI_DT_DCS_SHORT_WRITE_1       0x15
-#define DSI_DT_DCS_READ                        0x06
-#define DSI_DT_SET_MAX_RET_PKG_SIZE    0x37
-#define DSI_DT_NULL_PACKET             0x09
-#define DSI_DT_DCS_LONG_WRITE          0x39
-
-#define DSI_DT_RX_ACK_WITH_ERR         0x02
-#define DSI_DT_RX_DCS_LONG_READ                0x1c
-#define DSI_DT_RX_SHORT_READ_1         0x21
-#define DSI_DT_RX_SHORT_READ_2         0x22
-
 typedef void (*omap_dsi_isr_t) (void *arg, u32 mask);
 
 #define DSI_MAX_NR_ISRS                2
@@ -228,9 +217,9 @@ enum fifo_size {
        DSI_FIFO_SIZE_128       = 4,
 };
 
-enum dsi_vc_mode {
-       DSI_VC_MODE_L4 = 0,
-       DSI_VC_MODE_VP,
+enum dsi_vc_source {
+       DSI_VC_SOURCE_L4 = 0,
+       DSI_VC_SOURCE_VP,
 };
 
 enum dsi_lane {
@@ -274,7 +263,8 @@ struct dsi_data {
        struct clk *dss_clk;
        struct clk *sys_clk;
 
-       void (*dsi_mux_pads)(bool enable);
+       int (*enable_pads)(int dsi_id, unsigned lane_mask);
+       void (*disable_pads)(int dsi_id, unsigned lane_mask);
 
        struct dsi_clock_info current_cinfo;
 
@@ -282,7 +272,7 @@ struct dsi_data {
        struct regulator *vdds_dsi_reg;
 
        struct {
-               enum dsi_vc_mode mode;
+               enum dsi_vc_source source;
                struct omap_dss_device *dssdev;
                enum fifo_size fifo_size;
                int vc_id;
@@ -368,14 +358,9 @@ struct platform_device *dsi_get_dsidev_from_id(int module)
        return dsi_pdev_map[module];
 }
 
-static int dsi_get_dsidev_id(struct platform_device *dsidev)
+static inline int dsi_get_dsidev_id(struct platform_device *dsidev)
 {
-       /* TEMP: Pass 0 as the dsi module index till the time the dsi platform
-        * device names aren't changed to the form "omapdss_dsi.0",
-        * "omapdss_dsi.1" and so on */
-       BUG_ON(dsidev->id != -1);
-
-       return 0;
+       return dsidev->id;
 }
 
 static inline void dsi_write_reg(struct platform_device *dsidev,
@@ -437,6 +422,21 @@ static inline int wait_for_bit_change(struct platform_device *dsidev,
        return value;
 }
 
+u8 dsi_get_pixel_size(enum omap_dss_dsi_pixel_format fmt)
+{
+       switch (fmt) {
+       case OMAP_DSS_DSI_FMT_RGB888:
+       case OMAP_DSS_DSI_FMT_RGB666:
+               return 24;
+       case OMAP_DSS_DSI_FMT_RGB666_PACKED:
+               return 18;
+       case OMAP_DSS_DSI_FMT_RGB565:
+               return 16;
+       default:
+               BUG();
+       }
+}
+
 #ifdef DEBUG
 static void dsi_perf_mark_setup(struct platform_device *dsidev)
 {
@@ -453,6 +453,7 @@ static void dsi_perf_mark_start(struct platform_device *dsidev)
 static void dsi_perf_show(struct platform_device *dsidev, const char *name)
 {
        struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
+       struct omap_dss_device *dssdev = dsi->update_region.device;
        ktime_t t, setup_time, trans_time;
        u32 total_bytes;
        u32 setup_us, trans_us, total_us;
@@ -476,7 +477,7 @@ static void dsi_perf_show(struct platform_device *dsidev, const char *name)
 
        total_bytes = dsi->update_region.w *
                dsi->update_region.h *
-               dsi->update_region.device->ctrl.pixel_size / 8;
+               dsi_get_pixel_size(dssdev->panel.dsi_pix_fmt) / 8;
 
        printk(KERN_INFO "DSI(%s): %u us + %u us = %u us (%uHz), "
                        "%u bytes, %u kbytes/sec\n",
@@ -1287,7 +1288,7 @@ static int dsi_calc_clock_rates(struct omap_dss_device *dssdev,
                 * with DSS_SYS_CLK source also */
                cinfo->highfreq = 0;
        } else {
-               cinfo->clkin = dispc_pclk_rate(dssdev->manager->id);
+               cinfo->clkin = dispc_mgr_pclk_rate(dssdev->manager->id);
 
                if (cinfo->clkin < 32000000)
                        cinfo->highfreq = 0;
@@ -2360,6 +2361,24 @@ static int dsi_cio_wait_tx_clk_esc_reset(struct omap_dss_device *dssdev)
        return 0;
 }
 
+static unsigned dsi_get_lane_mask(struct omap_dss_device *dssdev)
+{
+       unsigned lanes = 0;
+
+       if (dssdev->phy.dsi.clk_lane != 0)
+               lanes |= 1 << (dssdev->phy.dsi.clk_lane - 1);
+       if (dssdev->phy.dsi.data1_lane != 0)
+               lanes |= 1 << (dssdev->phy.dsi.data1_lane - 1);
+       if (dssdev->phy.dsi.data2_lane != 0)
+               lanes |= 1 << (dssdev->phy.dsi.data2_lane - 1);
+       if (dssdev->phy.dsi.data3_lane != 0)
+               lanes |= 1 << (dssdev->phy.dsi.data3_lane - 1);
+       if (dssdev->phy.dsi.data4_lane != 0)
+               lanes |= 1 << (dssdev->phy.dsi.data4_lane - 1);
+
+       return lanes;
+}
+
 static int dsi_cio_init(struct omap_dss_device *dssdev)
 {
        struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
@@ -2370,8 +2389,9 @@ static int dsi_cio_init(struct omap_dss_device *dssdev)
 
        DSSDBGF();
 
-       if (dsi->dsi_mux_pads)
-               dsi->dsi_mux_pads(true);
+       r = dsi->enable_pads(dsidev->id, dsi_get_lane_mask(dssdev));
+       if (r)
+               return r;
 
        dsi_enable_scp_clk(dsidev);
 
@@ -2452,6 +2472,12 @@ static int dsi_cio_init(struct omap_dss_device *dssdev)
 
        dsi_cio_timings(dsidev);
 
+       if (dssdev->panel.dsi_mode == OMAP_DSS_DSI_VIDEO_MODE) {
+               /* DDR_CLK_ALWAYS_ON */
+               REG_FLD_MOD(dsidev, DSI_CLK_CTRL,
+                       dssdev->panel.dsi_vm_data.ddr_clk_always_on, 13, 13);
+       }
+
        dsi->ulps_enabled = false;
 
        DSSDBG("CIO init done\n");
@@ -2467,19 +2493,21 @@ err_cio_pwr:
                dsi_cio_disable_lane_override(dsidev);
 err_scp_clk_dom:
        dsi_disable_scp_clk(dsidev);
-       if (dsi->dsi_mux_pads)
-               dsi->dsi_mux_pads(false);
+       dsi->disable_pads(dsidev->id, dsi_get_lane_mask(dssdev));
        return r;
 }
 
-static void dsi_cio_uninit(struct platform_device *dsidev)
+static void dsi_cio_uninit(struct omap_dss_device *dssdev)
 {
+       struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
        struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
 
+       /* DDR_CLK_ALWAYS_ON */
+       REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 13, 13);
+
        dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF);
        dsi_disable_scp_clk(dsidev);
-       if (dsi->dsi_mux_pads)
-               dsi->dsi_mux_pads(false);
+       dsi->disable_pads(dsidev->id, dsi_get_lane_mask(dssdev));
 }
 
 static void dsi_config_tx_fifo(struct platform_device *dsidev,
@@ -2669,10 +2697,10 @@ static int dsi_sync_vc(struct platform_device *dsidev, int channel)
        if (!dsi_vc_is_enabled(dsidev, channel))
                return 0;
 
-       switch (dsi->vc[channel].mode) {
-       case DSI_VC_MODE_VP:
+       switch (dsi->vc[channel].source) {
+       case DSI_VC_SOURCE_VP:
                return dsi_sync_vc_vp(dsidev, channel);
-       case DSI_VC_MODE_L4:
+       case DSI_VC_SOURCE_L4:
                return dsi_sync_vc_l4(dsidev, channel);
        default:
                BUG();
@@ -2726,43 +2754,12 @@ static void dsi_vc_initial_config(struct platform_device *dsidev, int channel)
        dsi_write_reg(dsidev, DSI_VC_CTRL(channel), r);
 }
 
-static int dsi_vc_config_l4(struct platform_device *dsidev, int channel)
+static int dsi_vc_config_source(struct platform_device *dsidev, int channel,
+               enum dsi_vc_source source)
 {
        struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
 
-       if (dsi->vc[channel].mode == DSI_VC_MODE_L4)
-               return 0;
-
-       DSSDBGF("%d", channel);
-
-       dsi_sync_vc(dsidev, channel);
-
-       dsi_vc_enable(dsidev, channel, 0);
-
-       /* VC_BUSY */
-       if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel), 15, 0) != 0) {
-               DSSERR("vc(%d) busy when trying to config for L4\n", channel);
-               return -EIO;
-       }
-
-       REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 0, 1, 1); /* SOURCE, 0 = L4 */
-
-       /* DCS_CMD_ENABLE */
-       if (dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC))
-               REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 0, 30, 30);
-
-       dsi_vc_enable(dsidev, channel, 1);
-
-       dsi->vc[channel].mode = DSI_VC_MODE_L4;
-
-       return 0;
-}
-
-static int dsi_vc_config_vp(struct platform_device *dsidev, int channel)
-{
-       struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
-
-       if (dsi->vc[channel].mode == DSI_VC_MODE_VP)
+       if (dsi->vc[channel].source == source)
                return 0;
 
        DSSDBGF("%d", channel);
@@ -2777,21 +2774,22 @@ static int dsi_vc_config_vp(struct platform_device *dsidev, int channel)
                return -EIO;
        }
 
-       /* SOURCE, 1 = video port */
-       REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 1, 1);
+       /* SOURCE, 0 = L4, 1 = video port */
+       REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), source, 1, 1);
 
        /* DCS_CMD_ENABLE */
-       if (dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC))
-               REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 30, 30);
+       if (dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) {
+               bool enable = source == DSI_VC_SOURCE_VP;
+               REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 30, 30);
+       }
 
        dsi_vc_enable(dsidev, channel, 1);
 
-       dsi->vc[channel].mode = DSI_VC_MODE_VP;
+       dsi->vc[channel].source = source;
 
        return 0;
 }
 
-
 void omapdss_dsi_vc_enable_hs(struct omap_dss_device *dssdev, int channel,
                bool enable)
 {
@@ -2810,6 +2808,10 @@ void omapdss_dsi_vc_enable_hs(struct omap_dss_device *dssdev, int channel,
        dsi_if_enable(dsidev, 1);
 
        dsi_force_tx_stop_mode_io(dsidev);
+
+       /* start the DDR clock by sending a NULL packet */
+       if (dssdev->panel.dsi_vm_data.ddr_clk_always_on && enable)
+               dsi_vc_send_null(dssdev, channel);
 }
 EXPORT_SYMBOL(omapdss_dsi_vc_enable_hs);
 
@@ -2873,16 +2875,16 @@ static u16 dsi_vc_flush_receive_data(struct platform_device *dsidev,
                val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
                DSSERR("\trawval %#08x\n", val);
                dt = FLD_GET(val, 5, 0);
-               if (dt == DSI_DT_RX_ACK_WITH_ERR) {
+               if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) {
                        u16 err = FLD_GET(val, 23, 8);
                        dsi_show_rx_ack_with_err(err);
-               } else if (dt == DSI_DT_RX_SHORT_READ_1) {
+               } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE) {
                        DSSERR("\tDCS short response, 1 byte: %#x\n",
                                        FLD_GET(val, 23, 8));
-               } else if (dt == DSI_DT_RX_SHORT_READ_2) {
+               } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE) {
                        DSSERR("\tDCS short response, 2 byte: %#x\n",
                                        FLD_GET(val, 23, 8));
-               } else if (dt == DSI_DT_RX_DCS_LONG_READ) {
+               } else if (dt == MIPI_DSI_RX_DCS_LONG_READ_RESPONSE) {
                        DSSERR("\tDCS long response, len %d\n",
                                        FLD_GET(val, 23, 8));
                        dsi_vc_flush_long_data(dsidev, channel);
@@ -3007,7 +3009,7 @@ static int dsi_vc_send_long(struct platform_device *dsidev, int channel,
                return -EINVAL;
        }
 
-       dsi_vc_config_l4(dsidev, channel);
+       dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_L4);
 
        dsi_vc_write_long_header(dsidev, channel, data_type, len, ecc);
 
@@ -3066,7 +3068,7 @@ static int dsi_vc_send_short(struct platform_device *dsidev, int channel,
                                channel,
                                data_type, data & 0xff, (data >> 8) & 0xff);
 
-       dsi_vc_config_l4(dsidev, channel);
+       dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_L4);
 
        if (FLD_GET(dsi_read_reg(dsidev, DSI_VC_CTRL(channel)), 16, 16)) {
                DSSERR("ERROR FIFO FULL, aborting transfer\n");
@@ -3085,44 +3087,66 @@ static int dsi_vc_send_short(struct platform_device *dsidev, int channel,
 int dsi_vc_send_null(struct omap_dss_device *dssdev, int channel)
 {
        struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
-       u8 nullpkg[] = {0, 0, 0, 0};
 
-       return dsi_vc_send_long(dsidev, channel, DSI_DT_NULL_PACKET, nullpkg,
-               4, 0);
+       return dsi_vc_send_long(dsidev, channel, MIPI_DSI_NULL_PACKET, NULL,
+               0, 0);
 }
 EXPORT_SYMBOL(dsi_vc_send_null);
 
-int dsi_vc_dcs_write_nosync(struct omap_dss_device *dssdev, int channel,
-               u8 *data, int len)
+static int dsi_vc_write_nosync_common(struct omap_dss_device *dssdev,
+               int channel, u8 *data, int len, enum dss_dsi_content_type type)
 {
        struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
        int r;
 
-       BUG_ON(len == 0);
-
-       if (len == 1) {
-               r = dsi_vc_send_short(dsidev, channel, DSI_DT_DCS_SHORT_WRITE_0,
-                               data[0], 0);
+       if (len == 0) {
+               BUG_ON(type == DSS_DSI_CONTENT_DCS);
+               r = dsi_vc_send_short(dsidev, channel,
+                               MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM, 0, 0);
+       } else if (len == 1) {
+               r = dsi_vc_send_short(dsidev, channel,
+                               type == DSS_DSI_CONTENT_GENERIC ?
+                               MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM :
+                               MIPI_DSI_DCS_SHORT_WRITE, data[0], 0);
        } else if (len == 2) {
-               r = dsi_vc_send_short(dsidev, channel, DSI_DT_DCS_SHORT_WRITE_1,
+               r = dsi_vc_send_short(dsidev, channel,
+                               type == DSS_DSI_CONTENT_GENERIC ?
+                               MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM :
+                               MIPI_DSI_DCS_SHORT_WRITE_PARAM,
                                data[0] | (data[1] << 8), 0);
        } else {
-               /* 0x39 = DCS Long Write */
-               r = dsi_vc_send_long(dsidev, channel, DSI_DT_DCS_LONG_WRITE,
-                               data, len, 0);
+               r = dsi_vc_send_long(dsidev, channel,
+                               type == DSS_DSI_CONTENT_GENERIC ?
+                               MIPI_DSI_GENERIC_LONG_WRITE :
+                               MIPI_DSI_DCS_LONG_WRITE, data, len, 0);
        }
 
        return r;
 }
+
+int dsi_vc_dcs_write_nosync(struct omap_dss_device *dssdev, int channel,
+               u8 *data, int len)
+{
+       return dsi_vc_write_nosync_common(dssdev, channel, data, len,
+                       DSS_DSI_CONTENT_DCS);
+}
 EXPORT_SYMBOL(dsi_vc_dcs_write_nosync);
 
-int dsi_vc_dcs_write(struct omap_dss_device *dssdev, int channel, u8 *data,
-               int len)
+int dsi_vc_generic_write_nosync(struct omap_dss_device *dssdev, int channel,
+               u8 *data, int len)
+{
+       return dsi_vc_write_nosync_common(dssdev, channel, data, len,
+                       DSS_DSI_CONTENT_GENERIC);
+}
+EXPORT_SYMBOL(dsi_vc_generic_write_nosync);
+
+static int dsi_vc_write_common(struct omap_dss_device *dssdev, int channel,
+               u8 *data, int len, enum dss_dsi_content_type type)
 {
        struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
        int r;
 
-       r = dsi_vc_dcs_write_nosync(dssdev, channel, data, len);
+       r = dsi_vc_write_nosync_common(dssdev, channel, data, len, type);
        if (r)
                goto err;
 
@@ -3140,18 +3164,39 @@ int dsi_vc_dcs_write(struct omap_dss_device *dssdev, int channel, u8 *data,
 
        return 0;
 err:
-       DSSERR("dsi_vc_dcs_write(ch %d, cmd 0x%02x, len %d) failed\n",
+       DSSERR("dsi_vc_write_common(ch %d, cmd 0x%02x, len %d) failed\n",
                        channel, data[0], len);
        return r;
 }
+
+int dsi_vc_dcs_write(struct omap_dss_device *dssdev, int channel, u8 *data,
+               int len)
+{
+       return dsi_vc_write_common(dssdev, channel, data, len,
+                       DSS_DSI_CONTENT_DCS);
+}
 EXPORT_SYMBOL(dsi_vc_dcs_write);
 
+int dsi_vc_generic_write(struct omap_dss_device *dssdev, int channel, u8 *data,
+               int len)
+{
+       return dsi_vc_write_common(dssdev, channel, data, len,
+                       DSS_DSI_CONTENT_GENERIC);
+}
+EXPORT_SYMBOL(dsi_vc_generic_write);
+
 int dsi_vc_dcs_write_0(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd)
 {
        return dsi_vc_dcs_write(dssdev, channel, &dcs_cmd, 1);
 }
 EXPORT_SYMBOL(dsi_vc_dcs_write_0);
 
+int dsi_vc_generic_write_0(struct omap_dss_device *dssdev, int channel)
+{
+       return dsi_vc_generic_write(dssdev, channel, NULL, 0);
+}
+EXPORT_SYMBOL(dsi_vc_generic_write_0);
+
 int dsi_vc_dcs_write_1(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
                u8 param)
 {
@@ -3162,25 +3207,87 @@ int dsi_vc_dcs_write_1(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
 }
 EXPORT_SYMBOL(dsi_vc_dcs_write_1);
 
-int dsi_vc_dcs_read(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
-               u8 *buf, int buflen)
+int dsi_vc_generic_write_1(struct omap_dss_device *dssdev, int channel,
+               u8 param)
+{
+       return dsi_vc_generic_write(dssdev, channel, &param, 1);
+}
+EXPORT_SYMBOL(dsi_vc_generic_write_1);
+
+int dsi_vc_generic_write_2(struct omap_dss_device *dssdev, int channel,
+               u8 param1, u8 param2)
+{
+       u8 buf[2];
+       buf[0] = param1;
+       buf[1] = param2;
+       return dsi_vc_generic_write(dssdev, channel, buf, 2);
+}
+EXPORT_SYMBOL(dsi_vc_generic_write_2);
+
+static int dsi_vc_dcs_send_read_request(struct omap_dss_device *dssdev,
+               int channel, u8 dcs_cmd)
 {
        struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
        struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
-       u32 val;
-       u8 dt;
        int r;
 
        if (dsi->debug_read)
-               DSSDBG("dsi_vc_dcs_read(ch%d, dcs_cmd %x)\n", channel, dcs_cmd);
+               DSSDBG("dsi_vc_dcs_send_read_request(ch%d, dcs_cmd %x)\n",
+                       channel, dcs_cmd);
 
-       r = dsi_vc_send_short(dsidev, channel, DSI_DT_DCS_READ, dcs_cmd, 0);
-       if (r)
-               goto err;
+       r = dsi_vc_send_short(dsidev, channel, MIPI_DSI_DCS_READ, dcs_cmd, 0);
+       if (r) {
+               DSSERR("dsi_vc_dcs_send_read_request(ch %d, cmd 0x%02x)"
+                       " failed\n", channel, dcs_cmd);
+               return r;
+       }
 
-       r = dsi_vc_send_bta_sync(dssdev, channel);
-       if (r)
-               goto err;
+       return 0;
+}
+
+static int dsi_vc_generic_send_read_request(struct omap_dss_device *dssdev,
+               int channel, u8 *reqdata, int reqlen)
+{
+       struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
+       struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
+       u16 data;
+       u8 data_type;
+       int r;
+
+       if (dsi->debug_read)
+               DSSDBG("dsi_vc_generic_send_read_request(ch %d, reqlen %d)\n",
+                       channel, reqlen);
+
+       if (reqlen == 0) {
+               data_type = MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM;
+               data = 0;
+       } else if (reqlen == 1) {
+               data_type = MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM;
+               data = reqdata[0];
+       } else if (reqlen == 2) {
+               data_type = MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM;
+               data = reqdata[0] | (reqdata[1] << 8);
+       } else {
+               BUG();
+       }
+
+       r = dsi_vc_send_short(dsidev, channel, data_type, data, 0);
+       if (r) {
+               DSSERR("dsi_vc_generic_send_read_request(ch %d, reqlen %d)"
+                       " failed\n", channel, reqlen);
+               return r;
+       }
+
+       return 0;
+}
+
+static int dsi_vc_read_rx_fifo(struct platform_device *dsidev, int channel,
+               u8 *buf, int buflen, enum dss_dsi_content_type type)
+{
+       struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
+       u32 val;
+       u8 dt;
+       int r;
 
        /* RX_FIFO_NOT_EMPTY */
        if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20) == 0) {
@@ -3193,16 +3300,20 @@ int dsi_vc_dcs_read(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
        if (dsi->debug_read)
                DSSDBG("\theader: %08x\n", val);
        dt = FLD_GET(val, 5, 0);
-       if (dt == DSI_DT_RX_ACK_WITH_ERR) {
+       if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) {
                u16 err = FLD_GET(val, 23, 8);
                dsi_show_rx_ack_with_err(err);
                r = -EIO;
                goto err;
 
-       } else if (dt == DSI_DT_RX_SHORT_READ_1) {
+       } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ?
+                       MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_1BYTE :
+                       MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE)) {
                u8 data = FLD_GET(val, 15, 8);
                if (dsi->debug_read)
-                       DSSDBG("\tDCS short response, 1 byte: %02x\n", data);
+                       DSSDBG("\t%s short response, 1 byte: %02x\n",
+                               type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" :
+                               "DCS", data);
 
                if (buflen < 1) {
                        r = -EIO;
@@ -3212,10 +3323,14 @@ int dsi_vc_dcs_read(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
                buf[0] = data;
 
                return 1;
-       } else if (dt == DSI_DT_RX_SHORT_READ_2) {
+       } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ?
+                       MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_2BYTE :
+                       MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE)) {
                u16 data = FLD_GET(val, 23, 8);
                if (dsi->debug_read)
-                       DSSDBG("\tDCS short response, 2 byte: %04x\n", data);
+                       DSSDBG("\t%s short response, 2 byte: %04x\n",
+                               type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" :
+                               "DCS", data);
 
                if (buflen < 2) {
                        r = -EIO;
@@ -3226,11 +3341,15 @@ int dsi_vc_dcs_read(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
                buf[1] = (data >> 8) & 0xff;
 
                return 2;
-       } else if (dt == DSI_DT_RX_DCS_LONG_READ) {
+       } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ?
+                       MIPI_DSI_RX_GENERIC_LONG_READ_RESPONSE :
+                       MIPI_DSI_RX_DCS_LONG_READ_RESPONSE)) {
                int w;
                int len = FLD_GET(val, 23, 8);
                if (dsi->debug_read)
-                       DSSDBG("\tDCS long response, len %d\n", len);
+                       DSSDBG("\t%s long response, len %d\n",
+                               type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" :
+                               "DCS", len);
 
                if (len > buflen) {
                        r = -EIO;
@@ -3266,58 +3385,126 @@ int dsi_vc_dcs_read(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
 
        BUG();
 err:
-       DSSERR("dsi_vc_dcs_read(ch %d, cmd 0x%02x) failed\n",
-                       channel, dcs_cmd);
+       DSSERR("dsi_vc_read_rx_fifo(ch %d type %s) failed\n", channel,
+               type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" : "DCS");
+
        return r;
+}
 
+int dsi_vc_dcs_read(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
+               u8 *buf, int buflen)
+{
+       struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
+       int r;
+
+       r = dsi_vc_dcs_send_read_request(dssdev, channel, dcs_cmd);
+       if (r)
+               goto err;
+
+       r = dsi_vc_send_bta_sync(dssdev, channel);
+       if (r)
+               goto err;
+
+       r = dsi_vc_read_rx_fifo(dsidev, channel, buf, buflen,
+               DSS_DSI_CONTENT_DCS);
+       if (r < 0)
+               goto err;
+
+       if (r != buflen) {
+               r = -EIO;
+               goto err;
+       }
+
+       return 0;
+err:
+       DSSERR("dsi_vc_dcs_read(ch %d, cmd 0x%02x) failed\n", channel, dcs_cmd);
+       return r;
 }
 EXPORT_SYMBOL(dsi_vc_dcs_read);
 
-int dsi_vc_dcs_read_1(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
-               u8 *data)
+static int dsi_vc_generic_read(struct omap_dss_device *dssdev, int channel,
+               u8 *reqdata, int reqlen, u8 *buf, int buflen)
 {
+       struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
        int r;
 
-       r = dsi_vc_dcs_read(dssdev, channel, dcs_cmd, data, 1);
+       r = dsi_vc_generic_send_read_request(dssdev, channel, reqdata, reqlen);
+       if (r)
+               return r;
+
+       r = dsi_vc_send_bta_sync(dssdev, channel);
+       if (r)
+               return r;
 
+       r = dsi_vc_read_rx_fifo(dsidev, channel, buf, buflen,
+               DSS_DSI_CONTENT_GENERIC);
        if (r < 0)
                return r;
 
-       if (r != 1)
-               return -EIO;
+       if (r != buflen) {
+               r = -EIO;
+               return r;
+       }
 
        return 0;
 }
-EXPORT_SYMBOL(dsi_vc_dcs_read_1);
 
-int dsi_vc_dcs_read_2(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
-               u8 *data1, u8 *data2)
+int dsi_vc_generic_read_0(struct omap_dss_device *dssdev, int channel, u8 *buf,
+               int buflen)
 {
-       u8 buf[2];
        int r;
 
-       r = dsi_vc_dcs_read(dssdev, channel, dcs_cmd, buf, 2);
+       r = dsi_vc_generic_read(dssdev, channel, NULL, 0, buf, buflen);
+       if (r) {
+               DSSERR("dsi_vc_generic_read_0(ch %d) failed\n", channel);
+               return r;
+       }
 
-       if (r < 0)
+       return 0;
+}
+EXPORT_SYMBOL(dsi_vc_generic_read_0);
+
+int dsi_vc_generic_read_1(struct omap_dss_device *dssdev, int channel, u8 param,
+               u8 *buf, int buflen)
+{
+       int r;
+
+       r = dsi_vc_generic_read(dssdev, channel, &param, 1, buf, buflen);
+       if (r) {
+               DSSERR("dsi_vc_generic_read_1(ch %d) failed\n", channel);
                return r;
+       }
 
-       if (r != 2)
-               return -EIO;
+       return 0;
+}
+EXPORT_SYMBOL(dsi_vc_generic_read_1);
 
-       *data1 = buf[0];
-       *data2 = buf[1];
+int dsi_vc_generic_read_2(struct omap_dss_device *dssdev, int channel,
+               u8 param1, u8 param2, u8 *buf, int buflen)
+{
+       int r;
+       u8 reqdata[2];
+
+       reqdata[0] = param1;
+       reqdata[1] = param2;
+
+       r = dsi_vc_generic_read(dssdev, channel, reqdata, 2, buf, buflen);
+       if (r) {
+               DSSERR("dsi_vc_generic_read_2(ch %d) failed\n", channel);
+               return r;
+       }
 
        return 0;
 }
-EXPORT_SYMBOL(dsi_vc_dcs_read_2);
+EXPORT_SYMBOL(dsi_vc_generic_read_2);
 
 int dsi_vc_set_max_rx_packet_size(struct omap_dss_device *dssdev, int channel,
                u16 len)
 {
        struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
 
-       return dsi_vc_send_short(dsidev, channel, DSI_DT_SET_MAX_RET_PKG_SIZE,
-                       len, 0);
+       return dsi_vc_send_short(dsidev, channel,
+                       MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE, len, 0);
 }
 EXPORT_SYMBOL(dsi_vc_set_max_rx_packet_size);
 
@@ -3508,6 +3695,75 @@ static void dsi_set_hs_tx_timeout(struct platform_device *dsidev,
                        ticks, x4 ? " x4" : "", x16 ? " x16" : "",
                        (total_ticks * 1000) / (fck / 1000 / 1000));
 }
+
+static void dsi_config_vp_num_line_buffers(struct omap_dss_device *dssdev)
+{
+       struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
+       int num_line_buffers;
+
+       if (dssdev->panel.dsi_mode == OMAP_DSS_DSI_VIDEO_MODE) {
+               int bpp = dsi_get_pixel_size(dssdev->panel.dsi_pix_fmt);
+               unsigned line_buf_size = dsi_get_line_buf_size(dsidev);
+               struct omap_video_timings *timings = &dssdev->panel.timings;
+               /*
+                * Don't use line buffers if width is greater than the video
+                * port's line buffer size
+                */
+               if (line_buf_size <= timings->x_res * bpp / 8)
+                       num_line_buffers = 0;
+               else
+                       num_line_buffers = 2;
+       } else {
+               /* Use maximum number of line buffers in command mode */
+               num_line_buffers = 2;
+       }
+
+       /* LINE_BUFFER */
+       REG_FLD_MOD(dsidev, DSI_CTRL, num_line_buffers, 13, 12);
+}
+
+static void dsi_config_vp_sync_events(struct omap_dss_device *dssdev)
+{
+       struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
+       int de_pol = dssdev->panel.dsi_vm_data.vp_de_pol;
+       int hsync_pol = dssdev->panel.dsi_vm_data.vp_hsync_pol;
+       int vsync_pol = dssdev->panel.dsi_vm_data.vp_vsync_pol;
+       bool vsync_end = dssdev->panel.dsi_vm_data.vp_vsync_end;
+       bool hsync_end = dssdev->panel.dsi_vm_data.vp_hsync_end;
+       u32 r;
+
+       r = dsi_read_reg(dsidev, DSI_CTRL);
+       r = FLD_MOD(r, de_pol, 9, 9);           /* VP_DE_POL */
+       r = FLD_MOD(r, hsync_pol, 10, 10);      /* VP_HSYNC_POL */
+       r = FLD_MOD(r, vsync_pol, 11, 11);      /* VP_VSYNC_POL */
+       r = FLD_MOD(r, 1, 15, 15);              /* VP_VSYNC_START */
+       r = FLD_MOD(r, vsync_end, 16, 16);      /* VP_VSYNC_END */
+       r = FLD_MOD(r, 1, 17, 17);              /* VP_HSYNC_START */
+       r = FLD_MOD(r, hsync_end, 18, 18);      /* VP_HSYNC_END */
+       dsi_write_reg(dsidev, DSI_CTRL, r);
+}
+
+static void dsi_config_blanking_modes(struct omap_dss_device *dssdev)
+{
+       struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
+       int blanking_mode = dssdev->panel.dsi_vm_data.blanking_mode;
+       int hfp_blanking_mode = dssdev->panel.dsi_vm_data.hfp_blanking_mode;
+       int hbp_blanking_mode = dssdev->panel.dsi_vm_data.hbp_blanking_mode;
+       int hsa_blanking_mode = dssdev->panel.dsi_vm_data.hsa_blanking_mode;
+       u32 r;
+
+       /*
+        * 0 = TX FIFO packets sent or LPS in corresponding blanking periods
+        * 1 = Long blanking packets are sent in corresponding blanking periods
+        */
+       r = dsi_read_reg(dsidev, DSI_CTRL);
+       r = FLD_MOD(r, blanking_mode, 20, 20);          /* BLANKING_MODE */
+       r = FLD_MOD(r, hfp_blanking_mode, 21, 21);      /* HFP_BLANKING */
+       r = FLD_MOD(r, hbp_blanking_mode, 22, 22);      /* HBP_BLANKING */
+       r = FLD_MOD(r, hsa_blanking_mode, 23, 23);      /* HSA_BLANKING */
+       dsi_write_reg(dsidev, DSI_CTRL, r);
+}
+
 static int dsi_proto_config(struct omap_dss_device *dssdev)
 {
        struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
@@ -3530,7 +3786,7 @@ static int dsi_proto_config(struct omap_dss_device *dssdev)
        dsi_set_lp_rx_timeout(dsidev, 0x1fff, true, true);
        dsi_set_hs_tx_timeout(dsidev, 0x1fff, true, true);
 
-       switch (dssdev->ctrl.pixel_size) {
+       switch (dsi_get_pixel_size(dssdev->panel.dsi_pix_fmt)) {
        case 16:
                buswidth = 0;
                break;
@@ -3551,7 +3807,6 @@ static int dsi_proto_config(struct omap_dss_device *dssdev)
        r = FLD_MOD(r, 1, 4, 4);        /* VP_CLK_RATIO, always 1, see errata*/
        r = FLD_MOD(r, buswidth, 7, 6); /* VP_DATA_BUS_WIDTH */
        r = FLD_MOD(r, 0, 8, 8);        /* VP_CLK_POL */
-       r = FLD_MOD(r, 2, 13, 12);      /* LINE_BUFFER, 2 lines */
        r = FLD_MOD(r, 1, 14, 14);      /* TRIGGER_RESET_MODE */
        r = FLD_MOD(r, 1, 19, 19);      /* EOT_ENABLE */
        if (!dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) {
@@ -3562,6 +3817,13 @@ static int dsi_proto_config(struct omap_dss_device *dssdev)
 
        dsi_write_reg(dsidev, DSI_CTRL, r);
 
+       dsi_config_vp_num_line_buffers(dssdev);
+
+       if (dssdev->panel.dsi_mode == OMAP_DSS_DSI_VIDEO_MODE) {
+               dsi_config_vp_sync_events(dssdev);
+               dsi_config_blanking_modes(dssdev);
+       }
+
        dsi_vc_initial_config(dsidev, 0);
        dsi_vc_initial_config(dsidev, 1);
        dsi_vc_initial_config(dsidev, 2);
@@ -3580,6 +3842,7 @@ static void dsi_proto_timings(struct omap_dss_device *dssdev)
        unsigned ddr_clk_pre, ddr_clk_post;
        unsigned enter_hs_mode_lat, exit_hs_mode_lat;
        unsigned ths_eot;
+       int ndl = dsi_get_num_data_lanes_dssdev(dssdev);
        u32 r;
 
        r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
@@ -3602,7 +3865,7 @@ static void dsi_proto_timings(struct omap_dss_device *dssdev)
        /* min 60ns + 52*UI */
        tclk_post = ns2ddr(dsidev, 60) + 26;
 
-       ths_eot = DIV_ROUND_UP(4, dsi_get_num_data_lanes_dssdev(dssdev));
+       ths_eot = DIV_ROUND_UP(4, ndl);
 
        ddr_clk_pre = DIV_ROUND_UP(tclk_pre + tlpx + tclk_zero + tclk_prepare,
                        4);
@@ -3632,162 +3895,114 @@ static void dsi_proto_timings(struct omap_dss_device *dssdev)
 
        DSSDBG("enter_hs_mode_lat %u, exit_hs_mode_lat %u\n",
                        enter_hs_mode_lat, exit_hs_mode_lat);
-}
-
-
-#define DSI_DECL_VARS \
-       int __dsi_cb = 0; u32 __dsi_cv = 0;
 
-#define DSI_FLUSH(dsidev, ch) \
-       if (__dsi_cb > 0) { \
-               /*DSSDBG("sending long packet %#010x\n", __dsi_cv);*/ \
-               dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_PAYLOAD(ch), __dsi_cv); \
-               __dsi_cb = __dsi_cv = 0; \
+        if (dssdev->panel.dsi_mode == OMAP_DSS_DSI_VIDEO_MODE) {
+               /* TODO: Implement a video mode check_timings function */
+               int hsa = dssdev->panel.dsi_vm_data.hsa;
+               int hfp = dssdev->panel.dsi_vm_data.hfp;
+               int hbp = dssdev->panel.dsi_vm_data.hbp;
+               int vsa = dssdev->panel.dsi_vm_data.vsa;
+               int vfp = dssdev->panel.dsi_vm_data.vfp;
+               int vbp = dssdev->panel.dsi_vm_data.vbp;
+               int window_sync = dssdev->panel.dsi_vm_data.window_sync;
+               bool hsync_end = dssdev->panel.dsi_vm_data.vp_hsync_end;
+               struct omap_video_timings *timings = &dssdev->panel.timings;
+               int bpp = dsi_get_pixel_size(dssdev->panel.dsi_pix_fmt);
+               int tl, t_he, width_bytes;
+
+               t_he = hsync_end ?
+                       ((hsa == 0 && ndl == 3) ? 1 : DIV_ROUND_UP(4, ndl)) : 0;
+
+               width_bytes = DIV_ROUND_UP(timings->x_res * bpp, 8);
+
+               /* TL = t_HS + HSA + t_HE + HFP + ceil((WC + 6) / NDL) + HBP */
+               tl = DIV_ROUND_UP(4, ndl) + (hsync_end ? hsa : 0) + t_he + hfp +
+                       DIV_ROUND_UP(width_bytes + 6, ndl) + hbp;
+
+               DSSDBG("HBP: %d, HFP: %d, HSA: %d, TL: %d TXBYTECLKHS\n", hbp,
+                       hfp, hsync_end ? hsa : 0, tl);
+               DSSDBG("VBP: %d, VFP: %d, VSA: %d, VACT: %d lines\n", vbp, vfp,
+                       vsa, timings->y_res);
+
+               r = dsi_read_reg(dsidev, DSI_VM_TIMING1);
+               r = FLD_MOD(r, hbp, 11, 0);     /* HBP */
+               r = FLD_MOD(r, hfp, 23, 12);    /* HFP */
+               r = FLD_MOD(r, hsync_end ? hsa : 0, 31, 24);    /* HSA */
+               dsi_write_reg(dsidev, DSI_VM_TIMING1, r);
+
+               r = dsi_read_reg(dsidev, DSI_VM_TIMING2);
+               r = FLD_MOD(r, vbp, 7, 0);      /* VBP */
+               r = FLD_MOD(r, vfp, 15, 8);     /* VFP */
+               r = FLD_MOD(r, vsa, 23, 16);    /* VSA */
+               r = FLD_MOD(r, window_sync, 27, 24);    /* WINDOW_SYNC */
+               dsi_write_reg(dsidev, DSI_VM_TIMING2, r);
+
+               r = dsi_read_reg(dsidev, DSI_VM_TIMING3);
+               r = FLD_MOD(r, timings->y_res, 14, 0);  /* VACT */
+               r = FLD_MOD(r, tl, 31, 16);             /* TL */
+               dsi_write_reg(dsidev, DSI_VM_TIMING3, r);
        }
+}
 
-#define DSI_PUSH(dsidev, ch, data) \
-       do { \
-               __dsi_cv |= (data) << (__dsi_cb * 8); \
-               /*DSSDBG("cv = %#010x, cb = %d\n", __dsi_cv, __dsi_cb);*/ \
-               if (++__dsi_cb > 3) \
-                       DSI_FLUSH(dsidev, ch); \
-       } while (0)
-
-static int dsi_update_screen_l4(struct omap_dss_device *dssdev,
-                       int x, int y, int w, int h)
+int dsi_video_mode_enable(struct omap_dss_device *dssdev, int channel)
 {
-       /* Note: supports only 24bit colors in 32bit container */
        struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
-       struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
-       int first = 1;
-       int fifo_stalls = 0;
-       int max_dsi_packet_size;
-       int max_data_per_packet;
-       int max_pixels_per_packet;
-       int pixels_left;
-       int bytespp = dssdev->ctrl.pixel_size / 8;
-       int scr_width;
-       u32 __iomem *data;
-       int start_offset;
-       int horiz_inc;
-       int current_x;
-       struct omap_overlay *ovl;
-
-       debug_irq = 0;
-
-       DSSDBG("dsi_update_screen_l4 (%d,%d %dx%d)\n",
-                       x, y, w, h);
+       int bpp = dsi_get_pixel_size(dssdev->panel.dsi_pix_fmt);
+       u8 data_type;
+       u16 word_count;
 
-       ovl = dssdev->manager->overlays[0];
-
-       if (ovl->info.color_mode != OMAP_DSS_COLOR_RGB24U)
-               return -EINVAL;
-
-       if (dssdev->ctrl.pixel_size != 24)
-               return -EINVAL;
-
-       scr_width = ovl->info.screen_width;
-       data = ovl->info.vaddr;
-
-       start_offset = scr_width * y + x;
-       horiz_inc = scr_width - w;
-       current_x = x;
-
-       /* We need header(4) + DCSCMD(1) + pixels(numpix*bytespp) bytes
-        * in fifo */
-
-       /* When using CPU, max long packet size is TX buffer size */
-       max_dsi_packet_size = dsi->vc[0].fifo_size * 32 * 4;
-
-       /* we seem to get better perf if we divide the tx fifo to half,
-          and while the other half is being sent, we fill the other half
-          max_dsi_packet_size /= 2; */
-
-       max_data_per_packet = max_dsi_packet_size - 4 - 1;
-
-       max_pixels_per_packet = max_data_per_packet / bytespp;
-
-       DSSDBG("max_pixels_per_packet %d\n", max_pixels_per_packet);
-
-       pixels_left = w * h;
+       switch (dssdev->panel.dsi_pix_fmt) {
+       case OMAP_DSS_DSI_FMT_RGB888:
+               data_type = MIPI_DSI_PACKED_PIXEL_STREAM_24;
+               break;
+       case OMAP_DSS_DSI_FMT_RGB666:
+               data_type = MIPI_DSI_PIXEL_STREAM_3BYTE_18;
+               break;
+       case OMAP_DSS_DSI_FMT_RGB666_PACKED:
+               data_type = MIPI_DSI_PACKED_PIXEL_STREAM_18;
+               break;
+       case OMAP_DSS_DSI_FMT_RGB565:
+               data_type = MIPI_DSI_PACKED_PIXEL_STREAM_16;
+               break;
+       default:
+               BUG();
+       };
 
-       DSSDBG("total pixels %d\n", pixels_left);
+       dsi_if_enable(dsidev, false);
+       dsi_vc_enable(dsidev, channel, false);
 
-       data += start_offset;
+       /* MODE, 1 = video mode */
+       REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 4, 4);
 
-       while (pixels_left > 0) {
-               /* 0x2c = write_memory_start */
-               /* 0x3c = write_memory_continue */
-               u8 dcs_cmd = first ? 0x2c : 0x3c;
-               int pixels;
-               DSI_DECL_VARS;
-               first = 0;
+       word_count = DIV_ROUND_UP(dssdev->panel.timings.x_res * bpp, 8);
 
-#if 1
-               /* using fifo not empty */
-               /* TX_FIFO_NOT_EMPTY */
-               while (FLD_GET(dsi_read_reg(dsidev, DSI_VC_CTRL(0)), 5, 5)) {
-                       fifo_stalls++;
-                       if (fifo_stalls > 0xfffff) {
-                               DSSERR("fifo stalls overflow, pixels left %d\n",
-                                               pixels_left);
-                               dsi_if_enable(dsidev, 0);
-                               return -EIO;
-                       }
-                       udelay(1);
-               }
-#elif 1
-               /* using fifo emptiness */
-               while ((REG_GET(dsidev, DSI_TX_FIFO_VC_EMPTINESS, 7, 0)+1)*4 <
-                               max_dsi_packet_size) {
-                       fifo_stalls++;
-                       if (fifo_stalls > 0xfffff) {
-                               DSSERR("fifo stalls overflow, pixels left %d\n",
-                                              pixels_left);
-                               dsi_if_enable(dsidev, 0);
-                               return -EIO;
-                       }
-               }
-#else
-               while ((REG_GET(dsidev, DSI_TX_FIFO_VC_EMPTINESS,
-                               7, 0) + 1) * 4 == 0) {
-                       fifo_stalls++;
-                       if (fifo_stalls > 0xfffff) {
-                               DSSERR("fifo stalls overflow, pixels left %d\n",
-                                              pixels_left);
-                               dsi_if_enable(dsidev, 0);
-                               return -EIO;
-                       }
-               }
-#endif
-               pixels = min(max_pixels_per_packet, pixels_left);
+       dsi_vc_write_long_header(dsidev, channel, data_type, word_count, 0);
 
-               pixels_left -= pixels;
+       dsi_vc_enable(dsidev, channel, true);
+       dsi_if_enable(dsidev, true);
 
-               dsi_vc_write_long_header(dsidev, 0, DSI_DT_DCS_LONG_WRITE,
-                               1 + pixels * bytespp, 0);
+       dssdev->manager->enable(dssdev->manager);
 
-               DSI_PUSH(dsidev, 0, dcs_cmd);
+       return 0;
+}
+EXPORT_SYMBOL(dsi_video_mode_enable);
 
-               while (pixels-- > 0) {
-                       u32 pix = __raw_readl(data++);
+void dsi_video_mode_disable(struct omap_dss_device *dssdev, int channel)
+{
+       struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
 
-                       DSI_PUSH(dsidev, 0, (pix >> 16) & 0xff);
-                       DSI_PUSH(dsidev, 0, (pix >> 8) & 0xff);
-                       DSI_PUSH(dsidev, 0, (pix >> 0) & 0xff);
+       dsi_if_enable(dsidev, false);
+       dsi_vc_enable(dsidev, channel, false);
 
-                       current_x++;
-                       if (current_x == x+w) {
-                               current_x = x;
-                               data += horiz_inc;
-                       }
-               }
+       /* MODE, 0 = command mode */
+       REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 0, 4, 4);
 
-               DSI_FLUSH(dsidev, 0);
-       }
+       dsi_vc_enable(dsidev, channel, true);
+       dsi_if_enable(dsidev, true);
 
-       return 0;
+       dssdev->manager->disable(dssdev->manager);
 }
+EXPORT_SYMBOL(dsi_video_mode_disable);
 
 static void dsi_update_screen_dispc(struct omap_dss_device *dssdev,
                u16 x, u16 y, u16 w, u16 h)
@@ -3808,9 +4023,9 @@ static void dsi_update_screen_dispc(struct omap_dss_device *dssdev,
        DSSDBG("dsi_update_screen_dispc(%d,%d %dx%d)\n",
                        x, y, w, h);
 
-       dsi_vc_config_vp(dsidev, channel);
+       dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_VP);
 
-       bytespp = dssdev->ctrl.pixel_size / 8;
+       bytespp = dsi_get_pixel_size(dssdev->panel.dsi_pix_fmt) / 8;
        bytespl = w * bytespp;
        bytespf = bytespl * h;
 
@@ -3831,7 +4046,7 @@ static void dsi_update_screen_dispc(struct omap_dss_device *dssdev,
        l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */
        dsi_write_reg(dsidev, DSI_VC_TE(channel), l);
 
-       dsi_vc_write_long_header(dsidev, channel, DSI_DT_DCS_LONG_WRITE,
+       dsi_vc_write_long_header(dsidev, channel, MIPI_DSI_DCS_LONG_WRITE,
                packet_len, 0);
 
        if (dsi->te_enabled)
@@ -3956,11 +4171,9 @@ int omap_dsi_prepare_update(struct omap_dss_device *dssdev,
 
        dsi_perf_mark_setup(dsidev);
 
-       if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
-               dss_setup_partial_planes(dssdev, x, y, w, h,
-                               enlarge_update_area);
-               dispc_set_lcd_size(dssdev->manager->id, *w, *h);
-       }
+       dss_setup_partial_planes(dssdev, x, y, w, h,
+                       enlarge_update_area);
+       dispc_mgr_set_lcd_size(dssdev->manager->id, *w, *h);
 
        return 0;
 }
@@ -3982,27 +4195,16 @@ int omap_dsi_update(struct omap_dss_device *dssdev,
         * see rather obscure HW error happening, as DSS halts. */
        BUG_ON(x % 2 == 1);
 
-       if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
-               dsi->framedone_callback = callback;
-               dsi->framedone_data = data;
-
-               dsi->update_region.x = x;
-               dsi->update_region.y = y;
-               dsi->update_region.w = w;
-               dsi->update_region.h = h;
-               dsi->update_region.device = dssdev;
-
-               dsi_update_screen_dispc(dssdev, x, y, w, h);
-       } else {
-               int r;
+       dsi->framedone_callback = callback;
+       dsi->framedone_data = data;
 
-               r = dsi_update_screen_l4(dssdev, x, y, w, h);
-               if (r)
-                       return r;
+       dsi->update_region.x = x;
+       dsi->update_region.y = y;
+       dsi->update_region.w = w;
+       dsi->update_region.h = h;
+       dsi->update_region.device = dssdev;
 
-               dsi_perf_show(dsidev, "L4");
-               callback(0, data);
-       }
+       dsi_update_screen_dispc(dssdev, x, y, w, h);
 
        return 0;
 }
@@ -4013,28 +4215,9 @@ EXPORT_SYMBOL(omap_dsi_update);
 static int dsi_display_init_dispc(struct omap_dss_device *dssdev)
 {
        int r;
-       u32 irq;
-
-       irq = dssdev->manager->id == OMAP_DSS_CHANNEL_LCD ?
-               DISPC_IRQ_FRAMEDONE : DISPC_IRQ_FRAMEDONE2;
 
-       r = omap_dispc_register_isr(dsi_framedone_irq_callback, (void *) dssdev,
-                       irq);
-       if (r) {
-               DSSERR("can't get FRAMEDONE irq\n");
-               return r;
-       }
-
-       dispc_set_lcd_display_type(dssdev->manager->id,
-                       OMAP_DSS_LCD_DISPLAY_TFT);
-
-       dispc_set_parallel_interface_mode(dssdev->manager->id,
-                       OMAP_DSS_PARALLELMODE_DSI);
-       dispc_enable_fifohandcheck(dssdev->manager->id, 1);
-
-       dispc_set_tft_data_lines(dssdev->manager->id, dssdev->ctrl.pixel_size);
-
-       {
+       if (dssdev->panel.dsi_mode == OMAP_DSS_DSI_CMD_MODE) {
+               u32 irq;
                struct omap_video_timings timings = {
                        .hsw            = 1,
                        .hfp            = 1,
@@ -4044,21 +4227,46 @@ static int dsi_display_init_dispc(struct omap_dss_device *dssdev)
                        .vbp            = 0,
                };
 
-               dispc_set_lcd_timings(dssdev->manager->id, &timings);
+               irq = dssdev->manager->id == OMAP_DSS_CHANNEL_LCD ?
+                       DISPC_IRQ_FRAMEDONE : DISPC_IRQ_FRAMEDONE2;
+
+               r = omap_dispc_register_isr(dsi_framedone_irq_callback,
+                       (void *) dssdev, irq);
+               if (r) {
+                       DSSERR("can't get FRAMEDONE irq\n");
+                       return r;
+               }
+
+               dispc_mgr_enable_stallmode(dssdev->manager->id, true);
+               dispc_mgr_enable_fifohandcheck(dssdev->manager->id, 1);
+
+               dispc_mgr_set_lcd_timings(dssdev->manager->id, &timings);
+       } else {
+               dispc_mgr_enable_stallmode(dssdev->manager->id, false);
+               dispc_mgr_enable_fifohandcheck(dssdev->manager->id, 0);
+
+               dispc_mgr_set_lcd_timings(dssdev->manager->id,
+                       &dssdev->panel.timings);
        }
 
+               dispc_mgr_set_lcd_display_type(dssdev->manager->id,
+                       OMAP_DSS_LCD_DISPLAY_TFT);
+               dispc_mgr_set_tft_data_lines(dssdev->manager->id,
+                       dsi_get_pixel_size(dssdev->panel.dsi_pix_fmt));
        return 0;
 }
 
 static void dsi_display_uninit_dispc(struct omap_dss_device *dssdev)
 {
-       u32 irq;
+       if (dssdev->panel.dsi_mode == OMAP_DSS_DSI_CMD_MODE) {
+               u32 irq;
 
-       irq = dssdev->manager->id == OMAP_DSS_CHANNEL_LCD ?
-               DISPC_IRQ_FRAMEDONE : DISPC_IRQ_FRAMEDONE2;
+               irq = dssdev->manager->id == OMAP_DSS_CHANNEL_LCD ?
+                       DISPC_IRQ_FRAMEDONE : DISPC_IRQ_FRAMEDONE2;
 
-       omap_dispc_unregister_isr(dsi_framedone_irq_callback, (void *) dssdev,
-                       irq);
+               omap_dispc_unregister_isr(dsi_framedone_irq_callback,
+                       (void *) dssdev, irq);
+       }
 }
 
 static int dsi_configure_dsi_clocks(struct omap_dss_device *dssdev)
@@ -4106,7 +4314,7 @@ static int dsi_configure_dispc_clocks(struct omap_dss_device *dssdev)
                return r;
        }
 
-       r = dispc_set_clock_div(dssdev->manager->id, &dispc_cinfo);
+       r = dispc_mgr_set_clock_div(dssdev->manager->id, &dispc_cinfo);
        if (r) {
                DSSERR("Failed to set dispc clocks\n");
                return r;
@@ -4166,10 +4374,12 @@ static int dsi_display_init_dsi(struct omap_dss_device *dssdev)
 
        return 0;
 err3:
-       dsi_cio_uninit(dsidev);
+       dsi_cio_uninit(dssdev);
 err2:
        dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
        dss_select_dsi_clk_source(dsi_module, OMAP_DSS_CLK_SRC_FCK);
+       dss_select_lcd_clk_source(dssdev->manager->id, OMAP_DSS_CLK_SRC_FCK);
+
 err1:
        dsi_pll_uninit(dsidev, true);
 err0:
@@ -4195,7 +4405,8 @@ static void dsi_display_uninit_dsi(struct omap_dss_device *dssdev,
 
        dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
        dss_select_dsi_clk_source(dsi_module, OMAP_DSS_CLK_SRC_FCK);
-       dsi_cio_uninit(dsidev);
+       dss_select_lcd_clk_source(dssdev->manager->id, OMAP_DSS_CLK_SRC_FCK);
+       dsi_cio_uninit(dssdev);
        dsi_pll_uninit(dsidev, disconnect_lanes);
 }
 
@@ -4211,6 +4422,12 @@ int omapdss_dsi_display_enable(struct omap_dss_device *dssdev)
 
        mutex_lock(&dsi->lock);
 
+       if (dssdev->manager == NULL) {
+               DSSERR("failed to enable display: no manager\n");
+               r = -ENODEV;
+               goto err_start_dev;
+       }
+
        r = omap_dss_start_device(dssdev);
        if (r) {
                DSSERR("failed to start device\n");
@@ -4307,9 +4524,10 @@ int dsi_init_display(struct omap_dss_device *dssdev)
 
        DSSDBG("DSI init\n");
 
-       /* XXX these should be figured out dynamically */
-       dssdev->caps = OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE |
-               OMAP_DSS_DISPLAY_CAP_TEAR_ELIM;
+       if (dssdev->panel.dsi_mode == OMAP_DSS_DSI_CMD_MODE) {
+               dssdev->caps = OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE |
+                       OMAP_DSS_DISPLAY_CAP_TEAR_ELIM;
+       }
 
        if (dsi->vdds_dsi_reg == NULL) {
                struct regulator *vdds_dsi;
@@ -4435,10 +4653,7 @@ static int dsi_get_clocks(struct platform_device *dsidev)
 
        dsi->dss_clk = clk;
 
-       if (cpu_is_omap34xx() || cpu_is_omap3630())
-               clk = clk_get(&dsidev->dev, "dss2_alwon_fck");
-       else
-               clk = clk_get(&dsidev->dev, "sys_clk");
+       clk = clk_get(&dsidev->dev, "sys_clk");
        if (IS_ERR(clk)) {
                DSSERR("can't get sys_clk\n");
                clk_put(dsi->dss_clk);
@@ -4462,7 +4677,7 @@ static void dsi_put_clocks(struct platform_device *dsidev)
 }
 
 /* DSI1 HW IP initialisation */
-static int omap_dsi1hw_probe(struct platform_device *dsidev)
+static int omap_dsihw_probe(struct platform_device *dsidev)
 {
        struct omap_display_platform_data *dss_plat_data;
        struct omap_dss_board_info *board_info;
@@ -4483,7 +4698,8 @@ static int omap_dsi1hw_probe(struct platform_device *dsidev)
 
        dss_plat_data = dsidev->dev.platform_data;
        board_info = dss_plat_data->board_data;
-       dsi->dsi_mux_pads = board_info->dsi_mux_pads;
+       dsi->enable_pads = board_info->dsi_enable_pads;
+       dsi->disable_pads = board_info->dsi_disable_pads;
 
        spin_lock_init(&dsi->irq_lock);
        spin_lock_init(&dsi->errors_lock);
@@ -4539,7 +4755,7 @@ static int omap_dsi1hw_probe(struct platform_device *dsidev)
 
        /* DSI VCs initialization */
        for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) {
-               dsi->vc[i].mode = DSI_VC_MODE_L4;
+               dsi->vc[i].source = DSI_VC_SOURCE_L4;
                dsi->vc[i].dssdev = NULL;
                dsi->vc[i].vc_id = 0;
        }
@@ -4572,7 +4788,7 @@ err_alloc:
        return r;
 }
 
-static int omap_dsi1hw_remove(struct platform_device *dsidev)
+static int omap_dsihw_remove(struct platform_device *dsidev)
 {
        struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
 
@@ -4602,10 +4818,6 @@ static int omap_dsi1hw_remove(struct platform_device *dsidev)
 
 static int dsi_runtime_suspend(struct device *dev)
 {
-       struct dsi_data *dsi = dsi_get_dsidrv_data(to_platform_device(dev));
-
-       clk_disable(dsi->dss_clk);
-
        dispc_runtime_put();
        dss_runtime_put();
 
@@ -4614,7 +4826,6 @@ static int dsi_runtime_suspend(struct device *dev)
 
 static int dsi_runtime_resume(struct device *dev)
 {
-       struct dsi_data *dsi = dsi_get_dsidrv_data(to_platform_device(dev));
        int r;
 
        r = dss_runtime_get();
@@ -4625,8 +4836,6 @@ static int dsi_runtime_resume(struct device *dev)
        if (r)
                goto err_get_dispc;
 
-       clk_enable(dsi->dss_clk);
-
        return 0;
 
 err_get_dispc:
@@ -4640,11 +4849,11 @@ static const struct dev_pm_ops dsi_pm_ops = {
        .runtime_resume = dsi_runtime_resume,
 };
 
-static struct platform_driver omap_dsi1hw_driver = {
-       .probe          = omap_dsi1hw_probe,
-       .remove         = omap_dsi1hw_remove,
+static struct platform_driver omap_dsihw_driver = {
+       .probe          = omap_dsihw_probe,
+       .remove         = omap_dsihw_remove,
        .driver         = {
-               .name   = "omapdss_dsi1",
+               .name   = "omapdss_dsi",
                .owner  = THIS_MODULE,
                .pm     = &dsi_pm_ops,
        },
@@ -4652,10 +4861,10 @@ static struct platform_driver omap_dsi1hw_driver = {
 
 int dsi_init_platform_driver(void)
 {
-       return platform_driver_register(&omap_dsi1hw_driver);
+       return platform_driver_register(&omap_dsihw_driver);
 }
 
 void dsi_uninit_platform_driver(void)
 {
-       return platform_driver_unregister(&omap_dsi1hw_driver);
+       return platform_driver_unregister(&omap_dsihw_driver);
 }
index 0f9c3a6457a5cba009157f9255baf88681a5d30a..3e09726d32c7ae1f5a86e51830191a09d7574955 100644 (file)
@@ -639,6 +639,17 @@ void dss_select_hdmi_venc_clk_source(enum dss_hdmi_venc_clk_source_select hdmi)
        REG_FLD_MOD(DSS_CONTROL, hdmi, 15, 15); /* VENC_HDMI_SWITCH */
 }
 
+enum dss_hdmi_venc_clk_source_select dss_get_hdmi_venc_clk_source(void)
+{
+       enum omap_display_type displays;
+
+       displays = dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_DIGIT);
+       if ((displays & OMAP_DISPLAY_TYPE_HDMI) == 0)
+               return DSS_VENC_TV_CLK;
+
+       return REG_GET(DSS_CONTROL, 15, 15);
+}
+
 static int dss_get_clocks(void)
 {
        struct clk *clk;
@@ -691,11 +702,6 @@ static void dss_put_clocks(void)
        clk_put(dss.dss_clk);
 }
 
-struct clk *dss_get_ick(void)
-{
-       return clk_get(&dss.pdev->dev, "ick");
-}
-
 int dss_runtime_get(void)
 {
        int r;
@@ -824,13 +830,11 @@ static int omap_dsshw_remove(struct platform_device *pdev)
 static int dss_runtime_suspend(struct device *dev)
 {
        dss_save_context();
-       clk_disable(dss.dss_clk);
        return 0;
 }
 
 static int dss_runtime_resume(struct device *dev)
 {
-       clk_enable(dss.dss_clk);
        dss_restore_context();
        return 0;
 }
index 9c94b1152c208575474968d18aa90d3099276736..6308fc59fc9e97c317bc93cc33904d6e5383f3d7 100644 (file)
@@ -97,10 +97,10 @@ extern unsigned int dss_debug;
 #define FLD_MOD(orig, val, start, end) \
        (((orig) & ~FLD_MASK(start, end)) | FLD_VAL(val, start, end))
 
-enum omap_parallel_interface_mode {
-       OMAP_DSS_PARALLELMODE_BYPASS,           /* MIPI DPI */
-       OMAP_DSS_PARALLELMODE_RFBI,             /* MIPI DBI */
-       OMAP_DSS_PARALLELMODE_DSI,
+enum dss_io_pad_mode {
+       DSS_IO_PAD_MODE_RESET,
+       DSS_IO_PAD_MODE_RFBI,
+       DSS_IO_PAD_MODE_BYPASS,
 };
 
 enum dss_hdmi_venc_clk_source_select {
@@ -108,6 +108,11 @@ enum dss_hdmi_venc_clk_source_select {
        DSS_HDMI_M_PCLK = 1,
 };
 
+enum dss_dsi_content_type {
+       DSS_DSI_CONTENT_DCS,
+       DSS_DSI_CONTENT_GENERIC,
+};
+
 struct dss_clock_info {
        /* rates that we get with dividers below */
        unsigned long fck;
@@ -150,16 +155,6 @@ struct dsi_clock_info {
        bool use_sys_clk;
 };
 
-/* HDMI PLL structure */
-struct hdmi_pll_info {
-       u16 regn;
-       u16 regm;
-       u32 regmf;
-       u16 regm2;
-       u16 regsd;
-       u16 dcofreq;
-};
-
 struct seq_file;
 struct platform_device;
 
@@ -209,9 +204,8 @@ void dss_uninit_platform_driver(void);
 int dss_runtime_get(void);
 void dss_runtime_put(void);
 
-struct clk *dss_get_ick(void);
-
 void dss_select_hdmi_venc_clk_source(enum dss_hdmi_venc_clk_source_select);
+enum dss_hdmi_venc_clk_source_select dss_get_hdmi_venc_clk_source(void);
 const char *dss_get_generic_clk_source_name(enum omap_dss_clk_source clk_src);
 void dss_dump_clocks(struct seq_file *s);
 
@@ -279,6 +273,8 @@ void dsi_create_debugfs_files_reg(struct dentry *debugfs_dir,
 
 int dsi_init_display(struct omap_dss_device *display);
 void dsi_irq_handler(void);
+u8 dsi_get_pixel_size(enum omap_dss_dsi_pixel_format fmt);
+
 unsigned long dsi_get_pll_hsdiv_dispc_rate(struct platform_device *dsidev);
 int dsi_pll_set_clock_div(struct platform_device *dsidev,
                struct dsi_clock_info *cinfo);
@@ -309,6 +305,11 @@ static inline int dsi_runtime_get(struct platform_device *dsidev)
 static inline void dsi_runtime_put(struct platform_device *dsidev)
 {
 }
+static inline u8 dsi_get_pixel_size(enum omap_dss_dsi_pixel_format fmt)
+{
+       WARN("%s: DSI not compiled in, returning pixel_size as 0\n", __func__);
+       return 0;
+}
 static inline unsigned long dsi_get_pll_hsdiv_dispc_rate(struct platform_device *dsidev)
 {
        WARN("%s: DSI not compiled in, returning rate as 0\n", __func__);
@@ -385,90 +386,71 @@ void dispc_disable_sidle(void);
 void dispc_lcd_enable_signal_polarity(bool act_high);
 void dispc_lcd_enable_signal(bool enable);
 void dispc_pck_free_enable(bool enable);
-void dispc_enable_fifohandcheck(enum omap_channel channel, bool enable);
-
-void dispc_set_lcd_size(enum omap_channel channel, u16 width, u16 height);
 void dispc_set_digit_size(u16 width, u16 height);
-u32 dispc_get_plane_fifo_size(enum omap_plane plane);
-void dispc_set_fifo_threshold(enum omap_plane plane, u32 low, u32 high);
 void dispc_enable_fifomerge(bool enable);
-u32 dispc_get_burst_size(enum omap_plane plane);
-void dispc_enable_cpr(enum omap_channel channel, bool enable);
-void dispc_set_cpr_coef(enum omap_channel channel,
-               struct omap_dss_cpr_coefs *coefs);
-
-void dispc_set_plane_ba0(enum omap_plane plane, u32 paddr);
-void dispc_set_plane_ba1(enum omap_plane plane, u32 paddr);
-void dispc_set_plane_pos(enum omap_plane plane, u16 x, u16 y);
-void dispc_set_plane_size(enum omap_plane plane, u16 width, u16 height);
-void dispc_set_channel_out(enum omap_plane plane,
-               enum omap_channel channel_out);
-
 void dispc_enable_gamma_table(bool enable);
-int dispc_setup_plane(enum omap_plane plane,
-                     u32 paddr, u16 screen_width,
-                     u16 pos_x, u16 pos_y,
-                     u16 width, u16 height,
-                     u16 out_width, u16 out_height,
-                     enum omap_color_mode color_mode,
-                     bool ilace,
-                     enum omap_dss_rotation_type rotation_type,
-                     u8 rotation, bool mirror,
-                     u8 global_alpha, u8 pre_mult_alpha,
-                     enum omap_channel channel,
-                     u32 puv_addr);
-
-bool dispc_go_busy(enum omap_channel channel);
-void dispc_go(enum omap_channel channel);
-void dispc_enable_channel(enum omap_channel channel, bool enable);
-bool dispc_is_channel_enabled(enum omap_channel channel);
-int dispc_enable_plane(enum omap_plane plane, bool enable);
-void dispc_enable_replication(enum omap_plane plane, bool enable);
-
-void dispc_set_parallel_interface_mode(enum omap_channel channel,
-               enum omap_parallel_interface_mode mode);
-void dispc_set_tft_data_lines(enum omap_channel channel, u8 data_lines);
-void dispc_set_lcd_display_type(enum omap_channel channel,
-               enum omap_lcd_display_type type);
 void dispc_set_loadmode(enum omap_dss_load_mode mode);
 
-void dispc_set_default_color(enum omap_channel channel, u32 color);
-u32 dispc_get_default_color(enum omap_channel channel);
-void dispc_set_trans_key(enum omap_channel ch,
-               enum omap_dss_trans_key_type type,
-               u32 trans_key);
-void dispc_get_trans_key(enum omap_channel ch,
-               enum omap_dss_trans_key_type *type,
-               u32 *trans_key);
-void dispc_enable_trans_key(enum omap_channel ch, bool enable);
-void dispc_enable_alpha_blending(enum omap_channel ch, bool enable);
-bool dispc_trans_key_enabled(enum omap_channel ch);
-bool dispc_alpha_blending_enabled(enum omap_channel ch);
-
 bool dispc_lcd_timings_ok(struct omap_video_timings *timings);
-void dispc_set_lcd_timings(enum omap_channel channel,
-               struct omap_video_timings *timings);
 unsigned long dispc_fclk_rate(void);
-unsigned long dispc_lclk_rate(enum omap_channel channel);
-unsigned long dispc_pclk_rate(enum omap_channel channel);
-void dispc_set_pol_freq(enum omap_channel channel,
-               enum omap_panel_config config, u8 acbi, u8 acb);
 void dispc_find_clk_divs(bool is_tft, unsigned long req_pck, unsigned long fck,
                struct dispc_clock_info *cinfo);
 int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
                struct dispc_clock_info *cinfo);
-int dispc_set_clock_div(enum omap_channel channel,
+
+
+u32 dispc_ovl_get_fifo_size(enum omap_plane plane);
+u32 dispc_ovl_get_burst_size(enum omap_plane plane);
+int dispc_ovl_setup(enum omap_plane plane, struct omap_overlay_info *oi,
+               bool ilace, enum omap_channel channel, bool replication,
+               u32 fifo_low, u32 fifo_high);
+int dispc_ovl_enable(enum omap_plane plane, bool enable);
+
+
+void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable);
+void dispc_mgr_set_lcd_size(enum omap_channel channel, u16 width, u16 height);
+void dispc_mgr_enable_cpr(enum omap_channel channel, bool enable);
+void dispc_mgr_set_cpr_coef(enum omap_channel channel,
+               struct omap_dss_cpr_coefs *coefs);
+bool dispc_mgr_go_busy(enum omap_channel channel);
+void dispc_mgr_go(enum omap_channel channel);
+void dispc_mgr_enable(enum omap_channel channel, bool enable);
+bool dispc_mgr_is_channel_enabled(enum omap_channel channel);
+void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode);
+void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable);
+void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines);
+void dispc_mgr_set_lcd_display_type(enum omap_channel channel,
+               enum omap_lcd_display_type type);
+void dispc_mgr_set_default_color(enum omap_channel channel, u32 color);
+u32 dispc_mgr_get_default_color(enum omap_channel channel);
+void dispc_mgr_set_trans_key(enum omap_channel ch,
+               enum omap_dss_trans_key_type type,
+               u32 trans_key);
+void dispc_mgr_get_trans_key(enum omap_channel ch,
+               enum omap_dss_trans_key_type *type,
+               u32 *trans_key);
+void dispc_mgr_enable_trans_key(enum omap_channel ch, bool enable);
+void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch, bool enable);
+bool dispc_mgr_trans_key_enabled(enum omap_channel ch);
+bool dispc_mgr_alpha_fixed_zorder_enabled(enum omap_channel ch);
+void dispc_mgr_set_lcd_timings(enum omap_channel channel,
+               struct omap_video_timings *timings);
+void dispc_mgr_set_pol_freq(enum omap_channel channel,
+               enum omap_panel_config config, u8 acbi, u8 acb);
+unsigned long dispc_mgr_lclk_rate(enum omap_channel channel);
+unsigned long dispc_mgr_pclk_rate(enum omap_channel channel);
+int dispc_mgr_set_clock_div(enum omap_channel channel,
                struct dispc_clock_info *cinfo);
-int dispc_get_clock_div(enum omap_channel channel,
+int dispc_mgr_get_clock_div(enum omap_channel channel,
                struct dispc_clock_info *cinfo);
 
-
 /* VENC */
 #ifdef CONFIG_OMAP2_DSS_VENC
 int venc_init_platform_driver(void);
 void venc_uninit_platform_driver(void);
 void venc_dump_regs(struct seq_file *s);
 int venc_init_display(struct omap_dss_device *display);
+unsigned long venc_get_pixel_clock(void);
 #else
 static inline int venc_init_platform_driver(void)
 {
@@ -477,6 +459,11 @@ static inline int venc_init_platform_driver(void)
 static inline void venc_uninit_platform_driver(void)
 {
 }
+static inline unsigned long venc_get_pixel_clock(void)
+{
+       WARN("%s: VENC not compiled in, returning pclk as 0\n", __func__);
+       return 0;
+}
 #endif
 
 /* HDMI */
@@ -484,6 +471,8 @@ static inline void venc_uninit_platform_driver(void)
 int hdmi_init_platform_driver(void);
 void hdmi_uninit_platform_driver(void);
 int hdmi_init_display(struct omap_dss_device *dssdev);
+unsigned long hdmi_get_pixel_clock(void);
+void hdmi_dump_regs(struct seq_file *s);
 #else
 static inline int hdmi_init_display(struct omap_dss_device *dssdev)
 {
@@ -496,12 +485,19 @@ static inline int hdmi_init_platform_driver(void)
 static inline void hdmi_uninit_platform_driver(void)
 {
 }
+static inline unsigned long hdmi_get_pixel_clock(void)
+{
+       WARN("%s: HDMI not compiled in, returning pclk as 0\n", __func__);
+       return 0;
+}
 #endif
 int omapdss_hdmi_display_enable(struct omap_dss_device *dssdev);
 void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev);
 void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev);
 int omapdss_hdmi_display_check_timing(struct omap_dss_device *dssdev,
                                        struct omap_video_timings *timings);
+int omapdss_hdmi_read_edid(u8 *buf, int len);
+bool omapdss_hdmi_detect(void);
 int hdmi_panel_init(void);
 void hdmi_panel_exit(void);
 
index b415c4ee621dca2160350244f3f7c881cdf5346a..b402699168a52fe0b4f3ea8e07786eeb0afcf8a0 100644 (file)
@@ -47,6 +47,7 @@ struct omap_dss_features {
        const int num_ovls;
        const enum omap_display_type *supported_displays;
        const enum omap_color_mode *supported_color_modes;
+       const enum omap_overlay_caps *overlay_caps;
        const char * const *clksrc_names;
        const struct dss_param_range *dss_params;
 
@@ -209,6 +210,68 @@ static const enum omap_color_mode omap4_dss_supported_color_modes[] = {
        OMAP_DSS_COLOR_ARGB16 | OMAP_DSS_COLOR_XRGB16_1555 |
        OMAP_DSS_COLOR_ARGB32 | OMAP_DSS_COLOR_RGBX16 |
        OMAP_DSS_COLOR_RGBX32,
+
+       /* OMAP_DSS_VIDEO3 */
+       OMAP_DSS_COLOR_RGB16 | OMAP_DSS_COLOR_RGB12U |
+       OMAP_DSS_COLOR_YUV2 | OMAP_DSS_COLOR_ARGB16_1555 |
+       OMAP_DSS_COLOR_RGBA32 | OMAP_DSS_COLOR_NV12 |
+       OMAP_DSS_COLOR_RGBA16 | OMAP_DSS_COLOR_RGB24U |
+       OMAP_DSS_COLOR_RGB24P | OMAP_DSS_COLOR_UYVY |
+       OMAP_DSS_COLOR_ARGB16 | OMAP_DSS_COLOR_XRGB16_1555 |
+       OMAP_DSS_COLOR_ARGB32 | OMAP_DSS_COLOR_RGBX16 |
+       OMAP_DSS_COLOR_RGBX32,
+};
+
+static const enum omap_overlay_caps omap2_dss_overlay_caps[] = {
+       /* OMAP_DSS_GFX */
+       0,
+
+       /* OMAP_DSS_VIDEO1 */
+       OMAP_DSS_OVL_CAP_SCALE,
+
+       /* OMAP_DSS_VIDEO2 */
+       OMAP_DSS_OVL_CAP_SCALE,
+};
+
+static const enum omap_overlay_caps omap3430_dss_overlay_caps[] = {
+       /* OMAP_DSS_GFX */
+       OMAP_DSS_OVL_CAP_GLOBAL_ALPHA,
+
+       /* OMAP_DSS_VIDEO1 */
+       OMAP_DSS_OVL_CAP_SCALE,
+
+       /* OMAP_DSS_VIDEO2 */
+       OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA,
+};
+
+static const enum omap_overlay_caps omap3630_dss_overlay_caps[] = {
+       /* OMAP_DSS_GFX */
+       OMAP_DSS_OVL_CAP_GLOBAL_ALPHA | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA,
+
+       /* OMAP_DSS_VIDEO1 */
+       OMAP_DSS_OVL_CAP_SCALE,
+
+       /* OMAP_DSS_VIDEO2 */
+       OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
+               OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA,
+};
+
+static const enum omap_overlay_caps omap4_dss_overlay_caps[] = {
+       /* OMAP_DSS_GFX */
+       OMAP_DSS_OVL_CAP_GLOBAL_ALPHA | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA |
+               OMAP_DSS_OVL_CAP_ZORDER,
+
+       /* OMAP_DSS_VIDEO1 */
+       OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
+               OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA | OMAP_DSS_OVL_CAP_ZORDER,
+
+       /* OMAP_DSS_VIDEO2 */
+       OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
+               OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA | OMAP_DSS_OVL_CAP_ZORDER,
+
+       /* OMAP_DSS_VIDEO3 */
+       OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
+               OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA | OMAP_DSS_OVL_CAP_ZORDER,
 };
 
 static const char * const omap2_dss_clk_source_names[] = {
@@ -233,32 +296,38 @@ static const char * const omap4_dss_clk_source_names[] = {
 
 static const struct dss_param_range omap2_dss_param_range[] = {
        [FEAT_PARAM_DSS_FCK]                    = { 0, 173000000 },
+       [FEAT_PARAM_DSS_PCD]                    = { 2, 255 },
        [FEAT_PARAM_DSIPLL_REGN]                = { 0, 0 },
        [FEAT_PARAM_DSIPLL_REGM]                = { 0, 0 },
        [FEAT_PARAM_DSIPLL_REGM_DISPC]          = { 0, 0 },
        [FEAT_PARAM_DSIPLL_REGM_DSI]            = { 0, 0 },
        [FEAT_PARAM_DSIPLL_FINT]                = { 0, 0 },
        [FEAT_PARAM_DSIPLL_LPDIV]               = { 0, 0 },
+       [FEAT_PARAM_DOWNSCALE]                  = { 1, 2 },
 };
 
 static const struct dss_param_range omap3_dss_param_range[] = {
        [FEAT_PARAM_DSS_FCK]                    = { 0, 173000000 },
+       [FEAT_PARAM_DSS_PCD]                    = { 1, 255 },
        [FEAT_PARAM_DSIPLL_REGN]                = { 0, (1 << 7) - 1 },
        [FEAT_PARAM_DSIPLL_REGM]                = { 0, (1 << 11) - 1 },
        [FEAT_PARAM_DSIPLL_REGM_DISPC]          = { 0, (1 << 4) - 1 },
        [FEAT_PARAM_DSIPLL_REGM_DSI]            = { 0, (1 << 4) - 1 },
        [FEAT_PARAM_DSIPLL_FINT]                = { 750000, 2100000 },
        [FEAT_PARAM_DSIPLL_LPDIV]               = { 1, (1 << 13) - 1},
+       [FEAT_PARAM_DOWNSCALE]                  = { 1, 4 },
 };
 
 static const struct dss_param_range omap4_dss_param_range[] = {
        [FEAT_PARAM_DSS_FCK]                    = { 0, 186000000 },
+       [FEAT_PARAM_DSS_PCD]                    = { 1, 255 },
        [FEAT_PARAM_DSIPLL_REGN]                = { 0, (1 << 8) - 1 },
        [FEAT_PARAM_DSIPLL_REGM]                = { 0, (1 << 12) - 1 },
        [FEAT_PARAM_DSIPLL_REGM_DISPC]          = { 0, (1 << 5) - 1 },
        [FEAT_PARAM_DSIPLL_REGM_DSI]            = { 0, (1 << 5) - 1 },
        [FEAT_PARAM_DSIPLL_FINT]                = { 500000, 2500000 },
        [FEAT_PARAM_DSIPLL_LPDIV]               = { 0, (1 << 13) - 1 },
+       [FEAT_PARAM_DOWNSCALE]                  = { 1, 4 },
 };
 
 /* OMAP2 DSS Features */
@@ -275,6 +344,7 @@ static const struct omap_dss_features omap2_dss_features = {
        .num_ovls = 3,
        .supported_displays = omap2_dss_supported_displays,
        .supported_color_modes = omap2_dss_supported_color_modes,
+       .overlay_caps = omap2_dss_overlay_caps,
        .clksrc_names = omap2_dss_clk_source_names,
        .dss_params = omap2_dss_param_range,
        .buffer_size_unit = 1,
@@ -287,18 +357,19 @@ static const struct omap_dss_features omap3430_dss_features = {
        .num_reg_fields = ARRAY_SIZE(omap3_dss_reg_fields),
 
        .has_feature    =
-               FEAT_GLOBAL_ALPHA | FEAT_LCDENABLEPOL |
+               FEAT_LCDENABLEPOL |
                FEAT_LCDENABLESIGNAL | FEAT_PCKFREEENABLE |
                FEAT_FUNCGATED | FEAT_ROWREPEATENABLE |
                FEAT_LINEBUFFERSPLIT | FEAT_RESIZECONF |
                FEAT_DSI_PLL_FREQSEL | FEAT_DSI_REVERSE_TXCLKESC |
                FEAT_VENC_REQUIRES_TV_DAC_CLK | FEAT_CPR | FEAT_PRELOAD |
-               FEAT_FIR_COEF_V,
+               FEAT_FIR_COEF_V | FEAT_ALPHA_FIXED_ZORDER,
 
        .num_mgrs = 2,
        .num_ovls = 3,
        .supported_displays = omap3430_dss_supported_displays,
        .supported_color_modes = omap3_dss_supported_color_modes,
+       .overlay_caps = omap3430_dss_overlay_caps,
        .clksrc_names = omap3_dss_clk_source_names,
        .dss_params = omap3_dss_param_range,
        .buffer_size_unit = 1,
@@ -310,18 +381,19 @@ static const struct omap_dss_features omap3630_dss_features = {
        .num_reg_fields = ARRAY_SIZE(omap3_dss_reg_fields),
 
        .has_feature    =
-               FEAT_GLOBAL_ALPHA | FEAT_LCDENABLEPOL |
+               FEAT_LCDENABLEPOL |
                FEAT_LCDENABLESIGNAL | FEAT_PCKFREEENABLE |
-               FEAT_PRE_MULT_ALPHA | FEAT_FUNCGATED |
+               FEAT_FUNCGATED |
                FEAT_ROWREPEATENABLE | FEAT_LINEBUFFERSPLIT |
                FEAT_RESIZECONF | FEAT_DSI_PLL_PWR_BUG |
                FEAT_DSI_PLL_FREQSEL | FEAT_CPR | FEAT_PRELOAD |
-               FEAT_FIR_COEF_V,
+               FEAT_FIR_COEF_V | FEAT_ALPHA_FIXED_ZORDER,
 
        .num_mgrs = 2,
        .num_ovls = 3,
        .supported_displays = omap3630_dss_supported_displays,
        .supported_color_modes = omap3_dss_supported_color_modes,
+       .overlay_caps = omap3630_dss_overlay_caps,
        .clksrc_names = omap3_dss_clk_source_names,
        .dss_params = omap3_dss_param_range,
        .buffer_size_unit = 1,
@@ -335,17 +407,18 @@ static const struct omap_dss_features omap4430_es1_0_dss_features  = {
        .num_reg_fields = ARRAY_SIZE(omap4_dss_reg_fields),
 
        .has_feature    =
-               FEAT_GLOBAL_ALPHA | FEAT_PRE_MULT_ALPHA |
-               FEAT_MGR_LCD2 | FEAT_GLOBAL_ALPHA_VID1 |
+               FEAT_MGR_LCD2 |
                FEAT_CORE_CLK_DIV | FEAT_LCD_CLK_SRC |
                FEAT_DSI_DCS_CMD_CONFIG_VC | FEAT_DSI_VC_OCP_WIDTH |
                FEAT_DSI_GNQ | FEAT_HANDLE_UV_SEPARATE | FEAT_ATTR2 |
-               FEAT_CPR | FEAT_PRELOAD | FEAT_FIR_COEF_V,
+               FEAT_CPR | FEAT_PRELOAD | FEAT_FIR_COEF_V |
+               FEAT_ALPHA_FREE_ZORDER,
 
        .num_mgrs = 3,
-       .num_ovls = 3,
+       .num_ovls = 4,
        .supported_displays = omap4_dss_supported_displays,
        .supported_color_modes = omap4_dss_supported_color_modes,
+       .overlay_caps = omap4_dss_overlay_caps,
        .clksrc_names = omap4_dss_clk_source_names,
        .dss_params = omap4_dss_param_range,
        .buffer_size_unit = 16,
@@ -358,24 +431,50 @@ static const struct omap_dss_features omap4_dss_features = {
        .num_reg_fields = ARRAY_SIZE(omap4_dss_reg_fields),
 
        .has_feature    =
-               FEAT_GLOBAL_ALPHA | FEAT_PRE_MULT_ALPHA |
-               FEAT_MGR_LCD2 | FEAT_GLOBAL_ALPHA_VID1 |
+               FEAT_MGR_LCD2 |
                FEAT_CORE_CLK_DIV | FEAT_LCD_CLK_SRC |
                FEAT_DSI_DCS_CMD_CONFIG_VC | FEAT_DSI_VC_OCP_WIDTH |
                FEAT_DSI_GNQ | FEAT_HDMI_CTS_SWMODE |
                FEAT_HANDLE_UV_SEPARATE | FEAT_ATTR2 | FEAT_CPR |
-               FEAT_PRELOAD | FEAT_FIR_COEF_V,
+               FEAT_PRELOAD | FEAT_FIR_COEF_V | FEAT_ALPHA_FREE_ZORDER,
 
        .num_mgrs = 3,
-       .num_ovls = 3,
+       .num_ovls = 4,
        .supported_displays = omap4_dss_supported_displays,
        .supported_color_modes = omap4_dss_supported_color_modes,
+       .overlay_caps = omap4_dss_overlay_caps,
        .clksrc_names = omap4_dss_clk_source_names,
        .dss_params = omap4_dss_param_range,
        .buffer_size_unit = 16,
        .burst_size_unit = 16,
 };
 
+#if defined(CONFIG_OMAP4_DSS_HDMI)
+/* HDMI OMAP4 Functions*/
+static const struct ti_hdmi_ip_ops omap4_hdmi_functions = {
+
+       .video_configure        =       ti_hdmi_4xxx_basic_configure,
+       .phy_enable             =       ti_hdmi_4xxx_phy_enable,
+       .phy_disable            =       ti_hdmi_4xxx_phy_disable,
+       .read_edid              =       ti_hdmi_4xxx_read_edid,
+       .detect                 =       ti_hdmi_4xxx_detect,
+       .pll_enable             =       ti_hdmi_4xxx_pll_enable,
+       .pll_disable            =       ti_hdmi_4xxx_pll_disable,
+       .video_enable           =       ti_hdmi_4xxx_wp_video_start,
+       .dump_wrapper           =       ti_hdmi_4xxx_wp_dump,
+       .dump_core              =       ti_hdmi_4xxx_core_dump,
+       .dump_pll               =       ti_hdmi_4xxx_pll_dump,
+       .dump_phy               =       ti_hdmi_4xxx_phy_dump,
+
+};
+
+void dss_init_hdmi_ip_ops(struct hdmi_ip_data *ip_data)
+{
+       if (cpu_is_omap44xx())
+               ip_data->ops = &omap4_hdmi_functions;
+}
+#endif
+
 /* Functions returning values related to a DSS feature */
 int dss_feat_get_num_mgrs(void)
 {
@@ -407,6 +506,11 @@ enum omap_color_mode dss_feat_get_supported_color_modes(enum omap_plane plane)
        return omap_current_dss_features->supported_color_modes[plane];
 }
 
+enum omap_overlay_caps dss_feat_get_overlay_caps(enum omap_plane plane)
+{
+       return omap_current_dss_features->overlay_caps[plane];
+}
+
 bool dss_feat_color_mode_supported(enum omap_plane plane,
                enum omap_color_mode color_mode)
 {
index b7398cbcda5f203be1681f198cd6bc2a69326f97..6a6c05dd45ce56b45c1de6d1f2ac597932c74845 100644 (file)
 #ifndef __OMAP2_DSS_FEATURES_H
 #define __OMAP2_DSS_FEATURES_H
 
+#if defined(CONFIG_OMAP4_DSS_HDMI)
+#include "ti_hdmi.h"
+#endif
+
 #define MAX_DSS_MANAGERS       3
-#define MAX_DSS_OVERLAYS       3
+#define MAX_DSS_OVERLAYS       4
 #define MAX_DSS_LCD_MANAGERS   2
 #define MAX_NUM_DSI            2
 
 /* DSS has feature id */
 enum dss_feat_id {
-       FEAT_GLOBAL_ALPHA               = 1 << 0,
-       FEAT_GLOBAL_ALPHA_VID1          = 1 << 1,
-       FEAT_PRE_MULT_ALPHA             = 1 << 2,
        FEAT_LCDENABLEPOL               = 1 << 3,
        FEAT_LCDENABLESIGNAL            = 1 << 4,
        FEAT_PCKFREEENABLE              = 1 << 5,
@@ -55,6 +56,8 @@ enum dss_feat_id {
        FEAT_CPR                        = 1 << 23,
        FEAT_PRELOAD                    = 1 << 24,
        FEAT_FIR_COEF_V                 = 1 << 25,
+       FEAT_ALPHA_FIXED_ZORDER         = 1 << 26,
+       FEAT_ALPHA_FREE_ZORDER          = 1 << 27,
 };
 
 /* DSS register field id */
@@ -75,12 +78,14 @@ enum dss_feat_reg_field {
 
 enum dss_range_param {
        FEAT_PARAM_DSS_FCK,
+       FEAT_PARAM_DSS_PCD,
        FEAT_PARAM_DSIPLL_REGN,
        FEAT_PARAM_DSIPLL_REGM,
        FEAT_PARAM_DSIPLL_REGM_DISPC,
        FEAT_PARAM_DSIPLL_REGM_DSI,
        FEAT_PARAM_DSIPLL_FINT,
        FEAT_PARAM_DSIPLL_LPDIV,
+       FEAT_PARAM_DOWNSCALE,
 };
 
 /* DSS Feature Functions */
@@ -90,6 +95,7 @@ unsigned long dss_feat_get_param_min(enum dss_range_param param);
 unsigned long dss_feat_get_param_max(enum dss_range_param param);
 enum omap_display_type dss_feat_get_supported_displays(enum omap_channel channel);
 enum omap_color_mode dss_feat_get_supported_color_modes(enum omap_plane plane);
+enum omap_overlay_caps dss_feat_get_overlay_caps(enum omap_plane plane);
 bool dss_feat_color_mode_supported(enum omap_plane plane,
                enum omap_color_mode color_mode);
 const char *dss_feat_get_clk_source_name(enum omap_dss_clk_source id);
@@ -100,4 +106,7 @@ u32 dss_feat_get_burst_size_unit(void);             /* in bytes */
 bool dss_has_feature(enum dss_feat_id id);
 void dss_feat_get_reg_field(enum dss_feat_reg_field id, u8 *start, u8 *end);
 void dss_features_init(void);
+#if defined(CONFIG_OMAP4_DSS_HDMI)
+void dss_init_hdmi_ip_ops(struct hdmi_ip_data *ip_data);
+#endif
 #endif
index 256f27a9064ac75ee5c3397a21db07b5948d482c..3262f0f1fa35f395aec7637dc4e61f4fdf5766b1 100644 (file)
        defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
 #include <sound/soc.h>
 #include <sound/pcm_params.h>
+#include "ti_hdmi_4xxx_ip.h"
 #endif
 
+#include "ti_hdmi.h"
 #include "dss.h"
-#include "hdmi.h"
 #include "dss_features.h"
 
+#define HDMI_WP                        0x0
+#define HDMI_CORE_SYS          0x400
+#define HDMI_CORE_AV           0x900
+#define HDMI_PLLCTRL           0x200
+#define HDMI_PHY               0x300
+
+/* HDMI EDID Length move this */
+#define HDMI_EDID_MAX_LENGTH                   256
+#define EDID_TIMING_DESCRIPTOR_SIZE            0x12
+#define EDID_DESCRIPTOR_BLOCK0_ADDRESS         0x36
+#define EDID_DESCRIPTOR_BLOCK1_ADDRESS         0x80
+#define EDID_SIZE_BLOCK0_TIMING_DESCRIPTOR     4
+#define EDID_SIZE_BLOCK1_TIMING_DESCRIPTOR     4
+
+#define OMAP_HDMI_TIMINGS_NB                   34
+
+#define HDMI_DEFAULT_REGN 16
+#define HDMI_DEFAULT_REGM2 1
+
 static struct {
        struct mutex lock;
        struct omap_display_platform_data *pdata;
        struct platform_device *pdev;
-       void __iomem *base_wp;  /* HDMI wrapper */
+       struct hdmi_ip_data ip_data;
        int code;
        int mode;
-       u8 edid[HDMI_EDID_MAX_LENGTH];
-       u8 edid_set;
-       bool custom_set;
-       struct hdmi_config cfg;
 
        struct clk *sys_clk;
-       struct clk *hdmi_clk;
 } hdmi;
 
 /*
@@ -144,30 +159,6 @@ static const int code_vesa[85] = {
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
        -1, 27, 28, -1, 33};
 
-static const u8 edid_header[8] = {0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0};
-
-static inline void hdmi_write_reg(const struct hdmi_reg idx, u32 val)
-{
-       __raw_writel(val, hdmi.base_wp + idx.idx);
-}
-
-static inline u32 hdmi_read_reg(const struct hdmi_reg idx)
-{
-       return __raw_readl(hdmi.base_wp + idx.idx);
-}
-
-static inline int hdmi_wait_for_bit_change(const struct hdmi_reg idx,
-                               int b2, int b1, u32 val)
-{
-       u32 t = 0;
-       while (val != REG_GET(idx, b2, b1)) {
-               udelay(1);
-               if (t++ > 10000)
-                       return !val;
-       }
-       return val;
-}
-
 static int hdmi_runtime_get(void)
 {
        int r;
@@ -193,304 +184,7 @@ int hdmi_init_display(struct omap_dss_device *dssdev)
 {
        DSSDBG("init_display\n");
 
-       return 0;
-}
-
-static int hdmi_pll_init(enum hdmi_clk_refsel refsel, int dcofreq,
-               struct hdmi_pll_info *fmt, u16 sd)
-{
-       u32 r;
-
-       /* PLL start always use manual mode */
-       REG_FLD_MOD(PLLCTRL_PLL_CONTROL, 0x0, 0, 0);
-
-       r = hdmi_read_reg(PLLCTRL_CFG1);
-       r = FLD_MOD(r, fmt->regm, 20, 9); /* CFG1_PLL_REGM */
-       r = FLD_MOD(r, fmt->regn, 8, 1);  /* CFG1_PLL_REGN */
-
-       hdmi_write_reg(PLLCTRL_CFG1, r);
-
-       r = hdmi_read_reg(PLLCTRL_CFG2);
-
-       r = FLD_MOD(r, 0x0, 12, 12); /* PLL_HIGHFREQ divide by 2 */
-       r = FLD_MOD(r, 0x1, 13, 13); /* PLL_REFEN */
-       r = FLD_MOD(r, 0x0, 14, 14); /* PHY_CLKINEN de-assert during locking */
-
-       if (dcofreq) {
-               /* divider programming for frequency beyond 1000Mhz */
-               REG_FLD_MOD(PLLCTRL_CFG3, sd, 17, 10);
-               r = FLD_MOD(r, 0x4, 3, 1); /* 1000MHz and 2000MHz */
-       } else {
-               r = FLD_MOD(r, 0x2, 3, 1); /* 500MHz and 1000MHz */
-       }
-
-       hdmi_write_reg(PLLCTRL_CFG2, r);
-
-       r = hdmi_read_reg(PLLCTRL_CFG4);
-       r = FLD_MOD(r, fmt->regm2, 24, 18);
-       r = FLD_MOD(r, fmt->regmf, 17, 0);
-
-       hdmi_write_reg(PLLCTRL_CFG4, r);
-
-       /* go now */
-       REG_FLD_MOD(PLLCTRL_PLL_GO, 0x1, 0, 0);
-
-       /* wait for bit change */
-       if (hdmi_wait_for_bit_change(PLLCTRL_PLL_GO, 0, 0, 1) != 1) {
-               DSSERR("PLL GO bit not set\n");
-               return -ETIMEDOUT;
-       }
-
-       /* Wait till the lock bit is set in PLL status */
-       if (hdmi_wait_for_bit_change(PLLCTRL_PLL_STATUS, 1, 1, 1) != 1) {
-               DSSWARN("cannot lock PLL\n");
-               DSSWARN("CFG1 0x%x\n",
-                       hdmi_read_reg(PLLCTRL_CFG1));
-               DSSWARN("CFG2 0x%x\n",
-                       hdmi_read_reg(PLLCTRL_CFG2));
-               DSSWARN("CFG4 0x%x\n",
-                       hdmi_read_reg(PLLCTRL_CFG4));
-               return -ETIMEDOUT;
-       }
-
-       DSSDBG("PLL locked!\n");
-
-       return 0;
-}
-
-/* PHY_PWR_CMD */
-static int hdmi_set_phy_pwr(enum hdmi_phy_pwr val)
-{
-       /* Command for power control of HDMI PHY */
-       REG_FLD_MOD(HDMI_WP_PWR_CTRL, val, 7, 6);
-
-       /* Status of the power control of HDMI PHY */
-       if (hdmi_wait_for_bit_change(HDMI_WP_PWR_CTRL, 5, 4, val) != val) {
-               DSSERR("Failed to set PHY power mode to %d\n", val);
-               return -ETIMEDOUT;
-       }
-
-       return 0;
-}
-
-/* PLL_PWR_CMD */
-static int hdmi_set_pll_pwr(enum hdmi_pll_pwr val)
-{
-       /* Command for power control of HDMI PLL */
-       REG_FLD_MOD(HDMI_WP_PWR_CTRL, val, 3, 2);
-
-       /* wait till PHY_PWR_STATUS is set */
-       if (hdmi_wait_for_bit_change(HDMI_WP_PWR_CTRL, 1, 0, val) != val) {
-               DSSERR("Failed to set PHY_PWR_STATUS\n");
-               return -ETIMEDOUT;
-       }
-
-       return 0;
-}
-
-static int hdmi_pll_reset(void)
-{
-       /* SYSRESET  controlled by power FSM */
-       REG_FLD_MOD(PLLCTRL_PLL_CONTROL, 0x0, 3, 3);
-
-       /* READ 0x0 reset is in progress */
-       if (hdmi_wait_for_bit_change(PLLCTRL_PLL_STATUS, 0, 0, 1) != 1) {
-               DSSERR("Failed to sysreset PLL\n");
-               return -ETIMEDOUT;
-       }
-
-       return 0;
-}
-
-static int hdmi_phy_init(void)
-{
-       u16 r = 0;
-
-       r = hdmi_set_phy_pwr(HDMI_PHYPWRCMD_LDOON);
-       if (r)
-               return r;
-
-       r = hdmi_set_phy_pwr(HDMI_PHYPWRCMD_TXON);
-       if (r)
-               return r;
-
-       /*
-        * Read address 0 in order to get the SCP reset done completed
-        * Dummy access performed to make sure reset is done
-        */
-       hdmi_read_reg(HDMI_TXPHY_TX_CTRL);
-
-       /*
-        * Write to phy address 0 to configure the clock
-        * use HFBITCLK write HDMI_TXPHY_TX_CONTROL_FREQOUT field
-        */
-       REG_FLD_MOD(HDMI_TXPHY_TX_CTRL, 0x1, 31, 30);
-
-       /* Write to phy address 1 to start HDMI line (TXVALID and TMDSCLKEN) */
-       hdmi_write_reg(HDMI_TXPHY_DIGITAL_CTRL, 0xF0000000);
-
-       /* Setup max LDO voltage */
-       REG_FLD_MOD(HDMI_TXPHY_POWER_CTRL, 0xB, 3, 0);
-
-       /* Write to phy address 3 to change the polarity control */
-       REG_FLD_MOD(HDMI_TXPHY_PAD_CFG_CTRL, 0x1, 27, 27);
-
-       return 0;
-}
-
-static int hdmi_pll_program(struct hdmi_pll_info *fmt)
-{
-       u16 r = 0;
-       enum hdmi_clk_refsel refsel;
-
-       r = hdmi_set_pll_pwr(HDMI_PLLPWRCMD_ALLOFF);
-       if (r)
-               return r;
-
-       r = hdmi_set_pll_pwr(HDMI_PLLPWRCMD_BOTHON_ALLCLKS);
-       if (r)
-               return r;
-
-       r = hdmi_pll_reset();
-       if (r)
-               return r;
-
-       refsel = HDMI_REFSEL_SYSCLK;
-
-       r = hdmi_pll_init(refsel, fmt->dcofreq, fmt, fmt->regsd);
-       if (r)
-               return r;
-
-       return 0;
-}
-
-static void hdmi_phy_off(void)
-{
-       hdmi_set_phy_pwr(HDMI_PHYPWRCMD_OFF);
-}
-
-static int hdmi_core_ddc_edid(u8 *pedid, int ext)
-{
-       u32 i, j;
-       char checksum = 0;
-       u32 offset = 0;
-
-       /* Turn on CLK for DDC */
-       REG_FLD_MOD(HDMI_CORE_AV_DPD, 0x7, 2, 0);
-
-       /*
-        * SW HACK : Without the Delay DDC(i2c bus) reads 0 values /
-        * right shifted values( The behavior is not consistent and seen only
-        * with some TV's)
-        */
-       usleep_range(800, 1000);
-
-       if (!ext) {
-               /* Clk SCL Devices */
-               REG_FLD_MOD(HDMI_CORE_DDC_CMD, 0xA, 3, 0);
-
-               /* HDMI_CORE_DDC_STATUS_IN_PROG */
-               if (hdmi_wait_for_bit_change(HDMI_CORE_DDC_STATUS,
-                                               4, 4, 0) != 0) {
-                       DSSERR("Failed to program DDC\n");
-                       return -ETIMEDOUT;
-               }
-
-               /* Clear FIFO */
-               REG_FLD_MOD(HDMI_CORE_DDC_CMD, 0x9, 3, 0);
-
-               /* HDMI_CORE_DDC_STATUS_IN_PROG */
-               if (hdmi_wait_for_bit_change(HDMI_CORE_DDC_STATUS,
-                                               4, 4, 0) != 0) {
-                       DSSERR("Failed to program DDC\n");
-                       return -ETIMEDOUT;
-               }
-
-       } else {
-               if (ext % 2 != 0)
-                       offset = 0x80;
-       }
-
-       /* Load Segment Address Register */
-       REG_FLD_MOD(HDMI_CORE_DDC_SEGM, ext/2, 7, 0);
-
-       /* Load Slave Address Register */
-       REG_FLD_MOD(HDMI_CORE_DDC_ADDR, 0xA0 >> 1, 7, 1);
-
-       /* Load Offset Address Register */
-       REG_FLD_MOD(HDMI_CORE_DDC_OFFSET, offset, 7, 0);
-
-       /* Load Byte Count */
-       REG_FLD_MOD(HDMI_CORE_DDC_COUNT1, 0x80, 7, 0);
-       REG_FLD_MOD(HDMI_CORE_DDC_COUNT2, 0x0, 1, 0);
-
-       /* Set DDC_CMD */
-       if (ext)
-               REG_FLD_MOD(HDMI_CORE_DDC_CMD, 0x4, 3, 0);
-       else
-               REG_FLD_MOD(HDMI_CORE_DDC_CMD, 0x2, 3, 0);
-
-       /* HDMI_CORE_DDC_STATUS_BUS_LOW */
-       if (REG_GET(HDMI_CORE_DDC_STATUS, 6, 6) == 1) {
-               DSSWARN("I2C Bus Low?\n");
-               return -EIO;
-       }
-       /* HDMI_CORE_DDC_STATUS_NO_ACK */
-       if (REG_GET(HDMI_CORE_DDC_STATUS, 5, 5) == 1) {
-               DSSWARN("I2C No Ack\n");
-               return -EIO;
-       }
-
-       i = ext * 128;
-       j = 0;
-       while (((REG_GET(HDMI_CORE_DDC_STATUS, 4, 4) == 1) ||
-                       (REG_GET(HDMI_CORE_DDC_STATUS, 2, 2) == 0)) &&
-                       j < 128) {
-
-               if (REG_GET(HDMI_CORE_DDC_STATUS, 2, 2) == 0) {
-                       /* FIFO not empty */
-                       pedid[i++] = REG_GET(HDMI_CORE_DDC_DATA, 7, 0);
-                       j++;
-               }
-       }
-
-       for (j = 0; j < 128; j++)
-               checksum += pedid[j];
-
-       if (checksum != 0) {
-               DSSERR("E-EDID checksum failed!!\n");
-               return -EIO;
-       }
-
-       return 0;
-}
-
-static int read_edid(u8 *pedid, u16 max_length)
-{
-       int r = 0, n = 0, i = 0;
-       int max_ext_blocks = (max_length / 128) - 1;
-
-       r = hdmi_core_ddc_edid(pedid, 0);
-       if (r) {
-               return r;
-       } else {
-               n = pedid[0x7e];
-
-               /*
-                * README: need to comply with max_length set by the caller.
-                * Better implementation should be to allocate necessary
-                * memory to store EDID according to nb_block field found
-                * in first block
-                */
-               if (n > max_ext_blocks)
-                       n = max_ext_blocks;
-
-               for (i = 1; i <= n; i++) {
-                       r = hdmi_core_ddc_edid(pedid, i);
-                       if (r)
-                               return r;
-               }
-       }
+       dss_init_hdmi_ip_ops(&hdmi.ip_data);
        return 0;
 }
 
@@ -518,7 +212,7 @@ static struct hdmi_cm hdmi_get_code(struct omap_video_timings *timing)
 {
        int i = 0, code = -1, temp_vsync = 0, temp_hsync = 0;
        int timing_vsync = 0, timing_hsync = 0;
-       struct omap_video_timings temp;
+       struct hdmi_video_timings temp;
        struct hdmi_cm cm = {-1};
        DSSDBG("hdmi_get_code\n");
 
@@ -556,500 +250,6 @@ static struct hdmi_cm hdmi_get_code(struct omap_video_timings *timing)
        return cm;
 }
 
-static void get_horz_vert_timing_info(int current_descriptor_addrs, u8 *edid ,
-               struct omap_video_timings *timings)
-{
-       /* X and Y resolution */
-       timings->x_res = (((edid[current_descriptor_addrs + 4] & 0xF0) << 4) |
-                        edid[current_descriptor_addrs + 2]);
-       timings->y_res = (((edid[current_descriptor_addrs + 7] & 0xF0) << 4) |
-                        edid[current_descriptor_addrs + 5]);
-
-       timings->pixel_clock = ((edid[current_descriptor_addrs + 1] << 8) |
-                               edid[current_descriptor_addrs]);
-
-       timings->pixel_clock = 10 * timings->pixel_clock;
-
-       /* HORIZONTAL FRONT PORCH */
-       timings->hfp = edid[current_descriptor_addrs + 8] |
-                       ((edid[current_descriptor_addrs + 11] & 0xc0) << 2);
-       /* HORIZONTAL SYNC WIDTH */
-       timings->hsw = edid[current_descriptor_addrs + 9] |
-                       ((edid[current_descriptor_addrs + 11] & 0x30) << 4);
-       /* HORIZONTAL BACK PORCH */
-       timings->hbp = (((edid[current_descriptor_addrs + 4] & 0x0F) << 8) |
-                       edid[current_descriptor_addrs + 3]) -
-                       (timings->hfp + timings->hsw);
-       /* VERTICAL FRONT PORCH */
-       timings->vfp = ((edid[current_descriptor_addrs + 10] & 0xF0) >> 4) |
-                       ((edid[current_descriptor_addrs + 11] & 0x0f) << 2);
-       /* VERTICAL SYNC WIDTH */
-       timings->vsw = (edid[current_descriptor_addrs + 10] & 0x0F) |
-                       ((edid[current_descriptor_addrs + 11] & 0x03) << 4);
-       /* VERTICAL BACK PORCH */
-       timings->vbp = (((edid[current_descriptor_addrs + 7] & 0x0F) << 8) |
-                       edid[current_descriptor_addrs + 6]) -
-                       (timings->vfp + timings->vsw);
-
-}
-
-/* Description : This function gets the resolution information from EDID */
-static void get_edid_timing_data(u8 *edid)
-{
-       u8 count;
-       u16 current_descriptor_addrs;
-       struct hdmi_cm cm;
-       struct omap_video_timings edid_timings;
-
-       /* search block 0, there are 4 DTDs arranged in priority order */
-       for (count = 0; count < EDID_SIZE_BLOCK0_TIMING_DESCRIPTOR; count++) {
-               current_descriptor_addrs =
-                       EDID_DESCRIPTOR_BLOCK0_ADDRESS +
-                       count * EDID_TIMING_DESCRIPTOR_SIZE;
-               get_horz_vert_timing_info(current_descriptor_addrs,
-                               edid, &edid_timings);
-               cm = hdmi_get_code(&edid_timings);
-               DSSDBG("Block0[%d] value matches code = %d , mode = %d\n",
-                       count, cm.code, cm.mode);
-               if (cm.code == -1) {
-                       continue;
-               } else {
-                       hdmi.code = cm.code;
-                       hdmi.mode = cm.mode;
-                       DSSDBG("code = %d , mode = %d\n",
-                               hdmi.code, hdmi.mode);
-                       return;
-               }
-       }
-       if (edid[0x7e] != 0x00) {
-               for (count = 0; count < EDID_SIZE_BLOCK1_TIMING_DESCRIPTOR;
-                       count++) {
-                       current_descriptor_addrs =
-                       EDID_DESCRIPTOR_BLOCK1_ADDRESS +
-                       count * EDID_TIMING_DESCRIPTOR_SIZE;
-                       get_horz_vert_timing_info(current_descriptor_addrs,
-                                               edid, &edid_timings);
-                       cm = hdmi_get_code(&edid_timings);
-                       DSSDBG("Block1[%d] value matches code = %d, mode = %d",
-                               count, cm.code, cm.mode);
-                       if (cm.code == -1) {
-                               continue;
-                       } else {
-                               hdmi.code = cm.code;
-                               hdmi.mode = cm.mode;
-                               DSSDBG("code = %d , mode = %d\n",
-                                       hdmi.code, hdmi.mode);
-                               return;
-                       }
-               }
-       }
-
-       DSSINFO("no valid timing found , falling back to VGA\n");
-       hdmi.code = 4; /* setting default value of 640 480 VGA */
-       hdmi.mode = HDMI_DVI;
-}
-
-static void hdmi_read_edid(struct omap_video_timings *dp)
-{
-       int ret = 0, code;
-
-       memset(hdmi.edid, 0, HDMI_EDID_MAX_LENGTH);
-
-       if (!hdmi.edid_set)
-               ret = read_edid(hdmi.edid, HDMI_EDID_MAX_LENGTH);
-
-       if (!ret) {
-               if (!memcmp(hdmi.edid, edid_header, sizeof(edid_header))) {
-                       /* search for timings of default resolution */
-                       get_edid_timing_data(hdmi.edid);
-                       hdmi.edid_set = true;
-               }
-       } else {
-               DSSWARN("failed to read E-EDID\n");
-       }
-
-       if (!hdmi.edid_set) {
-               DSSINFO("fallback to VGA\n");
-               hdmi.code = 4; /* setting default value of 640 480 VGA */
-               hdmi.mode = HDMI_DVI;
-       }
-
-       code = get_timings_index();
-
-       *dp = cea_vesa_timings[code].timings;
-}
-
-static void hdmi_core_init(struct hdmi_core_video_config *video_cfg,
-                       struct hdmi_core_infoframe_avi *avi_cfg,
-                       struct hdmi_core_packet_enable_repeat *repeat_cfg)
-{
-       DSSDBG("Enter hdmi_core_init\n");
-
-       /* video core */
-       video_cfg->ip_bus_width = HDMI_INPUT_8BIT;
-       video_cfg->op_dither_truc = HDMI_OUTPUTTRUNCATION_8BIT;
-       video_cfg->deep_color_pkt = HDMI_DEEPCOLORPACKECTDISABLE;
-       video_cfg->pkt_mode = HDMI_PACKETMODERESERVEDVALUE;
-       video_cfg->hdmi_dvi = HDMI_DVI;
-       video_cfg->tclk_sel_clkmult = HDMI_FPLL10IDCK;
-
-       /* info frame */
-       avi_cfg->db1_format = 0;
-       avi_cfg->db1_active_info = 0;
-       avi_cfg->db1_bar_info_dv = 0;
-       avi_cfg->db1_scan_info = 0;
-       avi_cfg->db2_colorimetry = 0;
-       avi_cfg->db2_aspect_ratio = 0;
-       avi_cfg->db2_active_fmt_ar = 0;
-       avi_cfg->db3_itc = 0;
-       avi_cfg->db3_ec = 0;
-       avi_cfg->db3_q_range = 0;
-       avi_cfg->db3_nup_scaling = 0;
-       avi_cfg->db4_videocode = 0;
-       avi_cfg->db5_pixel_repeat = 0;
-       avi_cfg->db6_7_line_eoftop = 0 ;
-       avi_cfg->db8_9_line_sofbottom = 0;
-       avi_cfg->db10_11_pixel_eofleft = 0;
-       avi_cfg->db12_13_pixel_sofright = 0;
-
-       /* packet enable and repeat */
-       repeat_cfg->audio_pkt = 0;
-       repeat_cfg->audio_pkt_repeat = 0;
-       repeat_cfg->avi_infoframe = 0;
-       repeat_cfg->avi_infoframe_repeat = 0;
-       repeat_cfg->gen_cntrl_pkt = 0;
-       repeat_cfg->gen_cntrl_pkt_repeat = 0;
-       repeat_cfg->generic_pkt = 0;
-       repeat_cfg->generic_pkt_repeat = 0;
-}
-
-static void hdmi_core_powerdown_disable(void)
-{
-       DSSDBG("Enter hdmi_core_powerdown_disable\n");
-       REG_FLD_MOD(HDMI_CORE_CTRL1, 0x0, 0, 0);
-}
-
-static void hdmi_core_swreset_release(void)
-{
-       DSSDBG("Enter hdmi_core_swreset_release\n");
-       REG_FLD_MOD(HDMI_CORE_SYS_SRST, 0x0, 0, 0);
-}
-
-static void hdmi_core_swreset_assert(void)
-{
-       DSSDBG("Enter hdmi_core_swreset_assert\n");
-       REG_FLD_MOD(HDMI_CORE_SYS_SRST, 0x1, 0, 0);
-}
-
-/* DSS_HDMI_CORE_VIDEO_CONFIG */
-static void hdmi_core_video_config(struct hdmi_core_video_config *cfg)
-{
-       u32 r = 0;
-
-       /* sys_ctrl1 default configuration not tunable */
-       r = hdmi_read_reg(HDMI_CORE_CTRL1);
-       r = FLD_MOD(r, HDMI_CORE_CTRL1_VEN_FOLLOWVSYNC, 5, 5);
-       r = FLD_MOD(r, HDMI_CORE_CTRL1_HEN_FOLLOWHSYNC, 4, 4);
-       r = FLD_MOD(r, HDMI_CORE_CTRL1_BSEL_24BITBUS, 2, 2);
-       r = FLD_MOD(r, HDMI_CORE_CTRL1_EDGE_RISINGEDGE, 1, 1);
-       hdmi_write_reg(HDMI_CORE_CTRL1, r);
-
-       REG_FLD_MOD(HDMI_CORE_SYS_VID_ACEN, cfg->ip_bus_width, 7, 6);
-
-       /* Vid_Mode */
-       r = hdmi_read_reg(HDMI_CORE_SYS_VID_MODE);
-
-       /* dither truncation configuration */
-       if (cfg->op_dither_truc > HDMI_OUTPUTTRUNCATION_12BIT) {
-               r = FLD_MOD(r, cfg->op_dither_truc - 3, 7, 6);
-               r = FLD_MOD(r, 1, 5, 5);
-       } else {
-               r = FLD_MOD(r, cfg->op_dither_truc, 7, 6);
-               r = FLD_MOD(r, 0, 5, 5);
-       }
-       hdmi_write_reg(HDMI_CORE_SYS_VID_MODE, r);
-
-       /* HDMI_Ctrl */
-       r = hdmi_read_reg(HDMI_CORE_AV_HDMI_CTRL);
-       r = FLD_MOD(r, cfg->deep_color_pkt, 6, 6);
-       r = FLD_MOD(r, cfg->pkt_mode, 5, 3);
-       r = FLD_MOD(r, cfg->hdmi_dvi, 0, 0);
-       hdmi_write_reg(HDMI_CORE_AV_HDMI_CTRL, r);
-
-       /* TMDS_CTRL */
-       REG_FLD_MOD(HDMI_CORE_SYS_TMDS_CTRL,
-               cfg->tclk_sel_clkmult, 6, 5);
-}
-
-static void hdmi_core_aux_infoframe_avi_config(
-               struct hdmi_core_infoframe_avi info_avi)
-{
-       u32 val;
-       char sum = 0, checksum = 0;
-
-       sum += 0x82 + 0x002 + 0x00D;
-       hdmi_write_reg(HDMI_CORE_AV_AVI_TYPE, 0x082);
-       hdmi_write_reg(HDMI_CORE_AV_AVI_VERS, 0x002);
-       hdmi_write_reg(HDMI_CORE_AV_AVI_LEN, 0x00D);
-
-       val = (info_avi.db1_format << 5) |
-               (info_avi.db1_active_info << 4) |
-               (info_avi.db1_bar_info_dv << 2) |
-               (info_avi.db1_scan_info);
-       hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(0), val);
-       sum += val;
-
-       val = (info_avi.db2_colorimetry << 6) |
-               (info_avi.db2_aspect_ratio << 4) |
-               (info_avi.db2_active_fmt_ar);
-       hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(1), val);
-       sum += val;
-
-       val = (info_avi.db3_itc << 7) |
-               (info_avi.db3_ec << 4) |
-               (info_avi.db3_q_range << 2) |
-               (info_avi.db3_nup_scaling);
-       hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(2), val);
-       sum += val;
-
-       hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(3), info_avi.db4_videocode);
-       sum += info_avi.db4_videocode;
-
-       val = info_avi.db5_pixel_repeat;
-       hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(4), val);
-       sum += val;
-
-       val = info_avi.db6_7_line_eoftop & 0x00FF;
-       hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(5), val);
-       sum += val;
-
-       val = ((info_avi.db6_7_line_eoftop >> 8) & 0x00FF);
-       hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(6), val);
-       sum += val;
-
-       val = info_avi.db8_9_line_sofbottom & 0x00FF;
-       hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(7), val);
-       sum += val;
-
-       val = ((info_avi.db8_9_line_sofbottom >> 8) & 0x00FF);
-       hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(8), val);
-       sum += val;
-
-       val = info_avi.db10_11_pixel_eofleft & 0x00FF;
-       hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(9), val);
-       sum += val;
-
-       val = ((info_avi.db10_11_pixel_eofleft >> 8) & 0x00FF);
-       hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(10), val);
-       sum += val;
-
-       val = info_avi.db12_13_pixel_sofright & 0x00FF;
-       hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(11), val);
-       sum += val;
-
-       val = ((info_avi.db12_13_pixel_sofright >> 8) & 0x00FF);
-       hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(12), val);
-       sum += val;
-
-       checksum = 0x100 - sum;
-       hdmi_write_reg(HDMI_CORE_AV_AVI_CHSUM, checksum);
-}
-
-static void hdmi_core_av_packet_config(
-               struct hdmi_core_packet_enable_repeat repeat_cfg)
-{
-       /* enable/repeat the infoframe */
-       hdmi_write_reg(HDMI_CORE_AV_PB_CTRL1,
-               (repeat_cfg.audio_pkt << 5) |
-               (repeat_cfg.audio_pkt_repeat << 4) |
-               (repeat_cfg.avi_infoframe << 1) |
-               (repeat_cfg.avi_infoframe_repeat));
-
-       /* enable/repeat the packet */
-       hdmi_write_reg(HDMI_CORE_AV_PB_CTRL2,
-               (repeat_cfg.gen_cntrl_pkt << 3) |
-               (repeat_cfg.gen_cntrl_pkt_repeat << 2) |
-               (repeat_cfg.generic_pkt << 1) |
-               (repeat_cfg.generic_pkt_repeat));
-}
-
-static void hdmi_wp_init(struct omap_video_timings *timings,
-                       struct hdmi_video_format *video_fmt,
-                       struct hdmi_video_interface *video_int)
-{
-       DSSDBG("Enter hdmi_wp_init\n");
-
-       timings->hbp = 0;
-       timings->hfp = 0;
-       timings->hsw = 0;
-       timings->vbp = 0;
-       timings->vfp = 0;
-       timings->vsw = 0;
-
-       video_fmt->packing_mode = HDMI_PACK_10b_RGB_YUV444;
-       video_fmt->y_res = 0;
-       video_fmt->x_res = 0;
-
-       video_int->vsp = 0;
-       video_int->hsp = 0;
-
-       video_int->interlacing = 0;
-       video_int->tm = 0; /* HDMI_TIMING_SLAVE */
-
-}
-
-static void hdmi_wp_video_start(bool start)
-{
-       REG_FLD_MOD(HDMI_WP_VIDEO_CFG, start, 31, 31);
-}
-
-static void hdmi_wp_video_init_format(struct hdmi_video_format *video_fmt,
-       struct omap_video_timings *timings, struct hdmi_config *param)
-{
-       DSSDBG("Enter hdmi_wp_video_init_format\n");
-
-       video_fmt->y_res = param->timings.timings.y_res;
-       video_fmt->x_res = param->timings.timings.x_res;
-
-       timings->hbp = param->timings.timings.hbp;
-       timings->hfp = param->timings.timings.hfp;
-       timings->hsw = param->timings.timings.hsw;
-       timings->vbp = param->timings.timings.vbp;
-       timings->vfp = param->timings.timings.vfp;
-       timings->vsw = param->timings.timings.vsw;
-}
-
-static void hdmi_wp_video_config_format(
-               struct hdmi_video_format *video_fmt)
-{
-       u32 l = 0;
-
-       REG_FLD_MOD(HDMI_WP_VIDEO_CFG, video_fmt->packing_mode, 10, 8);
-
-       l |= FLD_VAL(video_fmt->y_res, 31, 16);
-       l |= FLD_VAL(video_fmt->x_res, 15, 0);
-       hdmi_write_reg(HDMI_WP_VIDEO_SIZE, l);
-}
-
-static void hdmi_wp_video_config_interface(
-               struct hdmi_video_interface *video_int)
-{
-       u32 r;
-       DSSDBG("Enter hdmi_wp_video_config_interface\n");
-
-       r = hdmi_read_reg(HDMI_WP_VIDEO_CFG);
-       r = FLD_MOD(r, video_int->vsp, 7, 7);
-       r = FLD_MOD(r, video_int->hsp, 6, 6);
-       r = FLD_MOD(r, video_int->interlacing, 3, 3);
-       r = FLD_MOD(r, video_int->tm, 1, 0);
-       hdmi_write_reg(HDMI_WP_VIDEO_CFG, r);
-}
-
-static void hdmi_wp_video_config_timing(
-               struct omap_video_timings *timings)
-{
-       u32 timing_h = 0;
-       u32 timing_v = 0;
-
-       DSSDBG("Enter hdmi_wp_video_config_timing\n");
-
-       timing_h |= FLD_VAL(timings->hbp, 31, 20);
-       timing_h |= FLD_VAL(timings->hfp, 19, 8);
-       timing_h |= FLD_VAL(timings->hsw, 7, 0);
-       hdmi_write_reg(HDMI_WP_VIDEO_TIMING_H, timing_h);
-
-       timing_v |= FLD_VAL(timings->vbp, 31, 20);
-       timing_v |= FLD_VAL(timings->vfp, 19, 8);
-       timing_v |= FLD_VAL(timings->vsw, 7, 0);
-       hdmi_write_reg(HDMI_WP_VIDEO_TIMING_V, timing_v);
-}
-
-static void hdmi_basic_configure(struct hdmi_config *cfg)
-{
-       /* HDMI */
-       struct omap_video_timings video_timing;
-       struct hdmi_video_format video_format;
-       struct hdmi_video_interface video_interface;
-       /* HDMI core */
-       struct hdmi_core_infoframe_avi avi_cfg;
-       struct hdmi_core_video_config v_core_cfg;
-       struct hdmi_core_packet_enable_repeat repeat_cfg;
-
-       hdmi_wp_init(&video_timing, &video_format,
-               &video_interface);
-
-       hdmi_core_init(&v_core_cfg,
-               &avi_cfg,
-               &repeat_cfg);
-
-       hdmi_wp_video_init_format(&video_format,
-                       &video_timing, cfg);
-
-       hdmi_wp_video_config_timing(&video_timing);
-
-       /* video config */
-       video_format.packing_mode = HDMI_PACK_24b_RGB_YUV444_YUV422;
-
-       hdmi_wp_video_config_format(&video_format);
-
-       video_interface.vsp = cfg->timings.vsync_pol;
-       video_interface.hsp = cfg->timings.hsync_pol;
-       video_interface.interlacing = cfg->interlace;
-       video_interface.tm = 1 ; /* HDMI_TIMING_MASTER_24BIT */
-
-       hdmi_wp_video_config_interface(&video_interface);
-
-       /*
-        * configure core video part
-        * set software reset in the core
-        */
-       hdmi_core_swreset_assert();
-
-       /* power down off */
-       hdmi_core_powerdown_disable();
-
-       v_core_cfg.pkt_mode = HDMI_PACKETMODE24BITPERPIXEL;
-       v_core_cfg.hdmi_dvi = cfg->cm.mode;
-
-       hdmi_core_video_config(&v_core_cfg);
-
-       /* release software reset in the core */
-       hdmi_core_swreset_release();
-
-       /*
-        * configure packet
-        * info frame video see doc CEA861-D page 65
-        */
-       avi_cfg.db1_format = HDMI_INFOFRAME_AVI_DB1Y_RGB;
-       avi_cfg.db1_active_info =
-               HDMI_INFOFRAME_AVI_DB1A_ACTIVE_FORMAT_OFF;
-       avi_cfg.db1_bar_info_dv = HDMI_INFOFRAME_AVI_DB1B_NO;
-       avi_cfg.db1_scan_info = HDMI_INFOFRAME_AVI_DB1S_0;
-       avi_cfg.db2_colorimetry = HDMI_INFOFRAME_AVI_DB2C_NO;
-       avi_cfg.db2_aspect_ratio = HDMI_INFOFRAME_AVI_DB2M_NO;
-       avi_cfg.db2_active_fmt_ar = HDMI_INFOFRAME_AVI_DB2R_SAME;
-       avi_cfg.db3_itc = HDMI_INFOFRAME_AVI_DB3ITC_NO;
-       avi_cfg.db3_ec = HDMI_INFOFRAME_AVI_DB3EC_XVYUV601;
-       avi_cfg.db3_q_range = HDMI_INFOFRAME_AVI_DB3Q_DEFAULT;
-       avi_cfg.db3_nup_scaling = HDMI_INFOFRAME_AVI_DB3SC_NO;
-       avi_cfg.db4_videocode = cfg->cm.code;
-       avi_cfg.db5_pixel_repeat = HDMI_INFOFRAME_AVI_DB5PR_NO;
-       avi_cfg.db6_7_line_eoftop = 0;
-       avi_cfg.db8_9_line_sofbottom = 0;
-       avi_cfg.db10_11_pixel_eofleft = 0;
-       avi_cfg.db12_13_pixel_sofright = 0;
-
-       hdmi_core_aux_infoframe_avi_config(avi_cfg);
-
-       /* enable/repeat the infoframe */
-       repeat_cfg.avi_infoframe = HDMI_PACKETENABLE;
-       repeat_cfg.avi_infoframe_repeat = HDMI_PACKETREPEATON;
-       /* wakeup */
-       repeat_cfg.audio_pkt = HDMI_PACKETENABLE;
-       repeat_cfg.audio_pkt_repeat = HDMI_PACKETREPEATON;
-       hdmi_core_av_packet_config(repeat_cfg);
-}
-
 static void update_hdmi_timings(struct hdmi_config *cfg,
                struct omap_video_timings *timings, int code)
 {
@@ -1066,6 +266,12 @@ static void update_hdmi_timings(struct hdmi_config *cfg,
        cfg->timings.hsync_pol = cea_vesa_timings[code].hsync_pol;
 }
 
+unsigned long hdmi_get_pixel_clock(void)
+{
+       /* HDMI Pixel Clock in Mhz */
+       return hdmi.ip_data.cfg.timings.timings.pixel_clock * 10000;
+}
+
 static void hdmi_compute_pll(struct omap_dss_device *dssdev, int phy,
                struct hdmi_pll_info *pi)
 {
@@ -1077,15 +283,23 @@ static void hdmi_compute_pll(struct omap_dss_device *dssdev, int phy,
         * Input clock is predivided by N + 1
         * out put of which is reference clk
         */
-       pi->regn = dssdev->clocks.hdmi.regn;
-       refclk = clkin / (pi->regn + 1);
+       if (dssdev->clocks.hdmi.regn == 0)
+               pi->regn = HDMI_DEFAULT_REGN;
+       else
+               pi->regn = dssdev->clocks.hdmi.regn;
+
+       refclk = clkin / pi->regn;
 
        /*
         * multiplier is pixel_clk/ref_clk
         * Multiplying by 100 to avoid fractional part removal
         */
        pi->regm = (phy * 100 / (refclk)) / 100;
-       pi->regm2 = dssdev->clocks.hdmi.regm2;
+
+       if (dssdev->clocks.hdmi.regm2 == 0)
+               pi->regm2 = HDMI_DEFAULT_REGM2;
+       else
+               pi->regm2 = dssdev->clocks.hdmi.regm2;
 
        /*
         * fractional multiplier is remainder of the difference between
@@ -1100,7 +314,10 @@ static void hdmi_compute_pll(struct omap_dss_device *dssdev, int phy,
         * is greater than 1000MHz
         */
        pi->dcofreq = phy > 1000 * 100;
-       pi->regsd = ((pi->regm * clkin / 10) / ((pi->regn + 1) * 250) + 5) / 10;
+       pi->regsd = ((pi->regm * clkin / 10) / (pi->regn * 250) + 5) / 10;
+
+       /* Set the reference clock to sysclk reference */
+       pi->refsel = HDMI_REFSEL_SYSCLK;
 
        DSSDBG("M = %d Mf = %d\n", pi->regm, pi->regmf);
        DSSDBG("range = %d sd = %d\n", pi->dcofreq, pi->regsd);
@@ -1109,7 +326,6 @@ static void hdmi_compute_pll(struct omap_dss_device *dssdev, int phy,
 static int hdmi_power_on(struct omap_dss_device *dssdev)
 {
        int r, code = 0;
-       struct hdmi_pll_info pll_data;
        struct omap_video_timings *p;
        unsigned long phy;
 
@@ -1117,7 +333,7 @@ static int hdmi_power_on(struct omap_dss_device *dssdev)
        if (r)
                return r;
 
-       dispc_enable_channel(OMAP_DSS_CHANNEL_DIGIT, 0);
+       dispc_mgr_enable(OMAP_DSS_CHANNEL_DIGIT, 0);
 
        p = &dssdev->panel.timings;
 
@@ -1125,36 +341,31 @@ static int hdmi_power_on(struct omap_dss_device *dssdev)
                dssdev->panel.timings.x_res,
                dssdev->panel.timings.y_res);
 
-       if (!hdmi.custom_set) {
-               DSSDBG("Read EDID as no EDID is not set on poweron\n");
-               hdmi_read_edid(p);
-       }
        code = get_timings_index();
-       dssdev->panel.timings = cea_vesa_timings[code].timings;
-       update_hdmi_timings(&hdmi.cfg, p, code);
+       update_hdmi_timings(&hdmi.ip_data.cfg, p, code);
 
        phy = p->pixel_clock;
 
-       hdmi_compute_pll(dssdev, phy, &pll_data);
+       hdmi_compute_pll(dssdev, phy, &hdmi.ip_data.pll_data);
 
-       hdmi_wp_video_start(0);
+       hdmi.ip_data.ops->video_enable(&hdmi.ip_data, 0);
 
-       /* config the PLL and PHY first */
-       r = hdmi_pll_program(&pll_data);
+       /* config the PLL and PHY hdmi_set_pll_pwrfirst */
+       r = hdmi.ip_data.ops->pll_enable(&hdmi.ip_data);
        if (r) {
                DSSDBG("Failed to lock PLL\n");
                goto err;
        }
 
-       r = hdmi_phy_init();
+       r = hdmi.ip_data.ops->phy_enable(&hdmi.ip_data);
        if (r) {
                DSSDBG("Failed to start PHY\n");
                goto err;
        }
 
-       hdmi.cfg.cm.mode = hdmi.mode;
-       hdmi.cfg.cm.code = hdmi.code;
-       hdmi_basic_configure(&hdmi.cfg);
+       hdmi.ip_data.cfg.cm.mode = hdmi.mode;
+       hdmi.ip_data.cfg.cm.code = hdmi.code;
+       hdmi.ip_data.ops->video_configure(&hdmi.ip_data);
 
        /* Make selection of HDMI in DSS */
        dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
@@ -1174,9 +385,9 @@ static int hdmi_power_on(struct omap_dss_device *dssdev)
        dispc_set_digit_size(dssdev->panel.timings.x_res,
                        dssdev->panel.timings.y_res);
 
-       dispc_enable_channel(OMAP_DSS_CHANNEL_DIGIT, 1);
+       hdmi.ip_data.ops->video_enable(&hdmi.ip_data, 1);
 
-       hdmi_wp_video_start(1);
+       dispc_mgr_enable(OMAP_DSS_CHANNEL_DIGIT, 1);
 
        return 0;
 err:
@@ -1186,14 +397,12 @@ err:
 
 static void hdmi_power_off(struct omap_dss_device *dssdev)
 {
-       dispc_enable_channel(OMAP_DSS_CHANNEL_DIGIT, 0);
+       dispc_mgr_enable(OMAP_DSS_CHANNEL_DIGIT, 0);
 
-       hdmi_wp_video_start(0);
-       hdmi_phy_off();
-       hdmi_set_pll_pwr(HDMI_PLLPWRCMD_ALLOFF);
+       hdmi.ip_data.ops->video_enable(&hdmi.ip_data, 0);
+       hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
+       hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
        hdmi_runtime_put();
-
-       hdmi.edid_set = 0;
 }
 
 int omapdss_hdmi_display_check_timing(struct omap_dss_device *dssdev,
@@ -1203,7 +412,6 @@ int omapdss_hdmi_display_check_timing(struct omap_dss_device *dssdev,
 
        cm = hdmi_get_code(timings);
        if (cm.code == -1) {
-               DSSERR("Invalid timing entered\n");
                return -EINVAL;
        }
 
@@ -1215,12 +423,69 @@ void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev)
 {
        struct hdmi_cm cm;
 
-       hdmi.custom_set = 1;
        cm = hdmi_get_code(&dssdev->panel.timings);
        hdmi.code = cm.code;
        hdmi.mode = cm.mode;
-       omapdss_hdmi_display_enable(dssdev);
-       hdmi.custom_set = 0;
+
+       if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
+               int r;
+
+               hdmi_power_off(dssdev);
+
+               r = hdmi_power_on(dssdev);
+               if (r)
+                       DSSERR("failed to power on device\n");
+       }
+}
+
+void hdmi_dump_regs(struct seq_file *s)
+{
+       mutex_lock(&hdmi.lock);
+
+       if (hdmi_runtime_get())
+               return;
+
+       hdmi.ip_data.ops->dump_wrapper(&hdmi.ip_data, s);
+       hdmi.ip_data.ops->dump_pll(&hdmi.ip_data, s);
+       hdmi.ip_data.ops->dump_phy(&hdmi.ip_data, s);
+       hdmi.ip_data.ops->dump_core(&hdmi.ip_data, s);
+
+       hdmi_runtime_put();
+       mutex_unlock(&hdmi.lock);
+}
+
+int omapdss_hdmi_read_edid(u8 *buf, int len)
+{
+       int r;
+
+       mutex_lock(&hdmi.lock);
+
+       r = hdmi_runtime_get();
+       BUG_ON(r);
+
+       r = hdmi.ip_data.ops->read_edid(&hdmi.ip_data, buf, len);
+
+       hdmi_runtime_put();
+       mutex_unlock(&hdmi.lock);
+
+       return r;
+}
+
+bool omapdss_hdmi_detect(void)
+{
+       int r;
+
+       mutex_lock(&hdmi.lock);
+
+       r = hdmi_runtime_get();
+       BUG_ON(r);
+
+       r = hdmi.ip_data.ops->detect(&hdmi.ip_data);
+
+       hdmi_runtime_put();
+       mutex_unlock(&hdmi.lock);
+
+       return r == 1;
 }
 
 int omapdss_hdmi_display_enable(struct omap_dss_device *dssdev)
@@ -1231,6 +496,12 @@ int omapdss_hdmi_display_enable(struct omap_dss_device *dssdev)
 
        mutex_lock(&hdmi.lock);
 
+       if (dssdev->manager == NULL) {
+               DSSERR("failed to enable display: no manager\n");
+               r = -ENODEV;
+               goto err0;
+       }
+
        r = omap_dss_start_device(dssdev);
        if (r) {
                DSSERR("failed to start device\n");
@@ -1282,219 +553,9 @@ void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev)
 
 #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
        defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
-static void hdmi_wp_audio_config_format(
-               struct hdmi_audio_format *aud_fmt)
-{
-       u32 r;
-
-       DSSDBG("Enter hdmi_wp_audio_config_format\n");
-
-       r = hdmi_read_reg(HDMI_WP_AUDIO_CFG);
-       r = FLD_MOD(r, aud_fmt->stereo_channels, 26, 24);
-       r = FLD_MOD(r, aud_fmt->active_chnnls_msk, 23, 16);
-       r = FLD_MOD(r, aud_fmt->en_sig_blk_strt_end, 5, 5);
-       r = FLD_MOD(r, aud_fmt->type, 4, 4);
-       r = FLD_MOD(r, aud_fmt->justification, 3, 3);
-       r = FLD_MOD(r, aud_fmt->sample_order, 2, 2);
-       r = FLD_MOD(r, aud_fmt->samples_per_word, 1, 1);
-       r = FLD_MOD(r, aud_fmt->sample_size, 0, 0);
-       hdmi_write_reg(HDMI_WP_AUDIO_CFG, r);
-}
-
-static void hdmi_wp_audio_config_dma(struct hdmi_audio_dma *aud_dma)
-{
-       u32 r;
-
-       DSSDBG("Enter hdmi_wp_audio_config_dma\n");
-
-       r = hdmi_read_reg(HDMI_WP_AUDIO_CFG2);
-       r = FLD_MOD(r, aud_dma->transfer_size, 15, 8);
-       r = FLD_MOD(r, aud_dma->block_size, 7, 0);
-       hdmi_write_reg(HDMI_WP_AUDIO_CFG2, r);
-
-       r = hdmi_read_reg(HDMI_WP_AUDIO_CTRL);
-       r = FLD_MOD(r, aud_dma->mode, 9, 9);
-       r = FLD_MOD(r, aud_dma->fifo_threshold, 8, 0);
-       hdmi_write_reg(HDMI_WP_AUDIO_CTRL, r);
-}
-
-static void hdmi_core_audio_config(struct hdmi_core_audio_config *cfg)
-{
-       u32 r;
-
-       /* audio clock recovery parameters */
-       r = hdmi_read_reg(HDMI_CORE_AV_ACR_CTRL);
-       r = FLD_MOD(r, cfg->use_mclk, 2, 2);
-       r = FLD_MOD(r, cfg->en_acr_pkt, 1, 1);
-       r = FLD_MOD(r, cfg->cts_mode, 0, 0);
-       hdmi_write_reg(HDMI_CORE_AV_ACR_CTRL, r);
-
-       REG_FLD_MOD(HDMI_CORE_AV_N_SVAL1, cfg->n, 7, 0);
-       REG_FLD_MOD(HDMI_CORE_AV_N_SVAL2, cfg->n >> 8, 7, 0);
-       REG_FLD_MOD(HDMI_CORE_AV_N_SVAL3, cfg->n >> 16, 7, 0);
-
-       if (cfg->cts_mode == HDMI_AUDIO_CTS_MODE_SW) {
-               REG_FLD_MOD(HDMI_CORE_AV_CTS_SVAL1, cfg->cts, 7, 0);
-               REG_FLD_MOD(HDMI_CORE_AV_CTS_SVAL2, cfg->cts >> 8, 7, 0);
-               REG_FLD_MOD(HDMI_CORE_AV_CTS_SVAL3, cfg->cts >> 16, 7, 0);
-       } else {
-               /*
-                * HDMI IP uses this configuration to divide the MCLK to
-                * update CTS value.
-                */
-               REG_FLD_MOD(HDMI_CORE_AV_FREQ_SVAL, cfg->mclk_mode, 2, 0);
-
-               /* Configure clock for audio packets */
-               REG_FLD_MOD(HDMI_CORE_AV_AUD_PAR_BUSCLK_1,
-                       cfg->aud_par_busclk, 7, 0);
-               REG_FLD_MOD(HDMI_CORE_AV_AUD_PAR_BUSCLK_2,
-                       (cfg->aud_par_busclk >> 8), 7, 0);
-               REG_FLD_MOD(HDMI_CORE_AV_AUD_PAR_BUSCLK_3,
-                       (cfg->aud_par_busclk >> 16), 7, 0);
-       }
-
-       /* Override of SPDIF sample frequency with value in I2S_CHST4 */
-       REG_FLD_MOD(HDMI_CORE_AV_SPDIF_CTRL, cfg->fs_override, 1, 1);
-
-       /* I2S parameters */
-       REG_FLD_MOD(HDMI_CORE_AV_I2S_CHST4, cfg->freq_sample, 3, 0);
-
-       r = hdmi_read_reg(HDMI_CORE_AV_I2S_IN_CTRL);
-       r = FLD_MOD(r, cfg->i2s_cfg.en_high_bitrate_aud, 7, 7);
-       r = FLD_MOD(r, cfg->i2s_cfg.sck_edge_mode, 6, 6);
-       r = FLD_MOD(r, cfg->i2s_cfg.cbit_order, 5, 5);
-       r = FLD_MOD(r, cfg->i2s_cfg.vbit, 4, 4);
-       r = FLD_MOD(r, cfg->i2s_cfg.ws_polarity, 3, 3);
-       r = FLD_MOD(r, cfg->i2s_cfg.justification, 2, 2);
-       r = FLD_MOD(r, cfg->i2s_cfg.direction, 1, 1);
-       r = FLD_MOD(r, cfg->i2s_cfg.shift, 0, 0);
-       hdmi_write_reg(HDMI_CORE_AV_I2S_IN_CTRL, r);
-
-       r = hdmi_read_reg(HDMI_CORE_AV_I2S_CHST5);
-       r = FLD_MOD(r, cfg->freq_sample, 7, 4);
-       r = FLD_MOD(r, cfg->i2s_cfg.word_length, 3, 1);
-       r = FLD_MOD(r, cfg->i2s_cfg.word_max_length, 0, 0);
-       hdmi_write_reg(HDMI_CORE_AV_I2S_CHST5, r);
-
-       REG_FLD_MOD(HDMI_CORE_AV_I2S_IN_LEN, cfg->i2s_cfg.in_length_bits, 3, 0);
-
-       /* Audio channels and mode parameters */
-       REG_FLD_MOD(HDMI_CORE_AV_HDMI_CTRL, cfg->layout, 2, 1);
-       r = hdmi_read_reg(HDMI_CORE_AV_AUD_MODE);
-       r = FLD_MOD(r, cfg->i2s_cfg.active_sds, 7, 4);
-       r = FLD_MOD(r, cfg->en_dsd_audio, 3, 3);
-       r = FLD_MOD(r, cfg->en_parallel_aud_input, 2, 2);
-       r = FLD_MOD(r, cfg->en_spdif, 1, 1);
-       hdmi_write_reg(HDMI_CORE_AV_AUD_MODE, r);
-}
-
-static void hdmi_core_audio_infoframe_config(
-               struct hdmi_core_infoframe_audio *info_aud)
-{
-       u8 val;
-       u8 sum = 0, checksum = 0;
-
-       /*
-        * Set audio info frame type, version and length as
-        * described in HDMI 1.4a Section 8.2.2 specification.
-        * Checksum calculation is defined in Section 5.3.5.
-        */
-       hdmi_write_reg(HDMI_CORE_AV_AUDIO_TYPE, 0x84);
-       hdmi_write_reg(HDMI_CORE_AV_AUDIO_VERS, 0x01);
-       hdmi_write_reg(HDMI_CORE_AV_AUDIO_LEN, 0x0a);
-       sum += 0x84 + 0x001 + 0x00a;
-
-       val = (info_aud->db1_coding_type << 4)
-                       | (info_aud->db1_channel_count - 1);
-       hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(0), val);
-       sum += val;
-
-       val = (info_aud->db2_sample_freq << 2) | info_aud->db2_sample_size;
-       hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(1), val);
-       sum += val;
-
-       hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(2), 0x00);
-
-       val = info_aud->db4_channel_alloc;
-       hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(3), val);
-       sum += val;
-
-       val = (info_aud->db5_downmix_inh << 7) | (info_aud->db5_lsv << 3);
-       hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(4), val);
-       sum += val;
-
-       hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(5), 0x00);
-       hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(6), 0x00);
-       hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(7), 0x00);
-       hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(8), 0x00);
-       hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(9), 0x00);
 
-       checksum = 0x100 - sum;
-       hdmi_write_reg(HDMI_CORE_AV_AUDIO_CHSUM, checksum);
-
-       /*
-        * TODO: Add MPEG and SPD enable and repeat cfg when EDID parsing
-        * is available.
-        */
-}
-
-static int hdmi_config_audio_acr(u32 sample_freq, u32 *n, u32 *cts)
-{
-       u32 r;
-       u32 deep_color = 0;
-       u32 pclk = hdmi.cfg.timings.timings.pixel_clock;
-
-       if (n == NULL || cts == NULL)
-               return -EINVAL;
-       /*
-        * Obtain current deep color configuration. This needed
-        * to calculate the TMDS clock based on the pixel clock.
-        */
-       r = REG_GET(HDMI_WP_VIDEO_CFG, 1, 0);
-       switch (r) {
-       case 1: /* No deep color selected */
-               deep_color = 100;
-               break;
-       case 2: /* 10-bit deep color selected */
-               deep_color = 125;
-               break;
-       case 3: /* 12-bit deep color selected */
-               deep_color = 150;
-               break;
-       default:
-               return -EINVAL;
-       }
-
-       switch (sample_freq) {
-       case 32000:
-               if ((deep_color == 125) && ((pclk == 54054)
-                               || (pclk == 74250)))
-                       *n = 8192;
-               else
-                       *n = 4096;
-               break;
-       case 44100:
-               *n = 6272;
-               break;
-       case 48000:
-               if ((deep_color == 125) && ((pclk == 54054)
-                               || (pclk == 74250)))
-                       *n = 8192;
-               else
-                       *n = 6144;
-               break;
-       default:
-               *n = 0;
-               return -EINVAL;
-       }
-
-       /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */
-       *cts = pclk * (*n / 128) * deep_color / (sample_freq / 10);
-
-       return 0;
-}
-
-static int hdmi_audio_hw_params(struct snd_pcm_substream *substream,
+static int hdmi_audio_hw_params(struct hdmi_ip_data *ip_data,
+                                       struct snd_pcm_substream *substream,
                                    struct snd_pcm_hw_params *params,
                                    struct snd_soc_dai *dai)
 {
@@ -1548,7 +609,7 @@ static int hdmi_audio_hw_params(struct snd_pcm_substream *substream,
                return -EINVAL;
        }
 
-       err = hdmi_config_audio_acr(params_rate(params), &n, &cts);
+       err = hdmi_config_audio_acr(ip_data, params_rate(params), &n, &cts);
        if (err < 0)
                return err;
 
@@ -1564,8 +625,8 @@ static int hdmi_audio_hw_params(struct snd_pcm_substream *substream,
        audio_dma.mode = HDMI_AUDIO_TRANSF_DMA;
        audio_dma.fifo_threshold = 0x20; /* in number of samples */
 
-       hdmi_wp_audio_config_dma(&audio_dma);
-       hdmi_wp_audio_config_format(&audio_format);
+       hdmi_wp_audio_config_dma(ip_data, &audio_dma);
+       hdmi_wp_audio_config_format(ip_data, &audio_format);
 
        /*
         * I2S config
@@ -1609,7 +670,7 @@ static int hdmi_audio_hw_params(struct snd_pcm_substream *substream,
        /* Use parallel audio interface */
        core_cfg.en_parallel_aud_input = true;
 
-       hdmi_core_audio_config(&core_cfg);
+       hdmi_core_audio_config(ip_data, &core_cfg);
 
        /*
         * Configure packet
@@ -1623,36 +684,10 @@ static int hdmi_audio_hw_params(struct snd_pcm_substream *substream,
        aud_if_cfg.db5_downmix_inh = false;
        aud_if_cfg.db5_lsv = 0;
 
-       hdmi_core_audio_infoframe_config(&aud_if_cfg);
+       hdmi_core_audio_infoframe_config(ip_data, &aud_if_cfg);
        return 0;
 }
 
-static int hdmi_audio_trigger(struct snd_pcm_substream *substream, int cmd,
-                                 struct snd_soc_dai *dai)
-{
-       int err = 0;
-       switch (cmd) {
-       case SNDRV_PCM_TRIGGER_START:
-       case SNDRV_PCM_TRIGGER_RESUME:
-       case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
-               REG_FLD_MOD(HDMI_CORE_AV_AUD_MODE, 1, 0, 0);
-               REG_FLD_MOD(HDMI_WP_AUDIO_CTRL, 1, 31, 31);
-               REG_FLD_MOD(HDMI_WP_AUDIO_CTRL, 1, 30, 30);
-               break;
-
-       case SNDRV_PCM_TRIGGER_STOP:
-       case SNDRV_PCM_TRIGGER_SUSPEND:
-       case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
-               REG_FLD_MOD(HDMI_CORE_AV_AUD_MODE, 0, 0, 0);
-               REG_FLD_MOD(HDMI_WP_AUDIO_CTRL, 0, 30, 30);
-               REG_FLD_MOD(HDMI_WP_AUDIO_CTRL, 0, 31, 31);
-               break;
-       default:
-               err = -EINVAL;
-       }
-       return err;
-}
-
 static int hdmi_audio_startup(struct snd_pcm_substream *substream,
                                  struct snd_soc_dai *dai)
 {
@@ -1698,15 +733,6 @@ static int hdmi_get_clocks(struct platform_device *pdev)
 
        hdmi.sys_clk = clk;
 
-       clk = clk_get(&pdev->dev, "dss_48mhz_clk");
-       if (IS_ERR(clk)) {
-               DSSERR("can't get hdmi_clk\n");
-               clk_put(hdmi.sys_clk);
-               return PTR_ERR(clk);
-       }
-
-       hdmi.hdmi_clk = clk;
-
        return 0;
 }
 
@@ -1714,8 +740,6 @@ static void hdmi_put_clocks(void)
 {
        if (hdmi.sys_clk)
                clk_put(hdmi.sys_clk);
-       if (hdmi.hdmi_clk)
-               clk_put(hdmi.hdmi_clk);
 }
 
 /* HDMI HW IP initialisation */
@@ -1736,20 +760,26 @@ static int omapdss_hdmihw_probe(struct platform_device *pdev)
        }
 
        /* Base address taken from platform */
-       hdmi.base_wp = ioremap(hdmi_mem->start, resource_size(hdmi_mem));
-       if (!hdmi.base_wp) {
+       hdmi.ip_data.base_wp = ioremap(hdmi_mem->start,
+                                               resource_size(hdmi_mem));
+       if (!hdmi.ip_data.base_wp) {
                DSSERR("can't ioremap WP\n");
                return -ENOMEM;
        }
 
        r = hdmi_get_clocks(pdev);
        if (r) {
-               iounmap(hdmi.base_wp);
+               iounmap(hdmi.ip_data.base_wp);
                return r;
        }
 
        pm_runtime_enable(&pdev->dev);
 
+       hdmi.ip_data.core_sys_offset = HDMI_CORE_SYS;
+       hdmi.ip_data.core_av_offset = HDMI_CORE_AV;
+       hdmi.ip_data.pll_offset = HDMI_PLLCTRL;
+       hdmi.ip_data.phy_offset = HDMI_PHY;
+
        hdmi_panel_init();
 
 #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
@@ -1779,14 +809,13 @@ static int omapdss_hdmihw_remove(struct platform_device *pdev)
 
        hdmi_put_clocks();
 
-       iounmap(hdmi.base_wp);
+       iounmap(hdmi.ip_data.base_wp);
 
        return 0;
 }
 
 static int hdmi_runtime_suspend(struct device *dev)
 {
-       clk_disable(hdmi.hdmi_clk);
        clk_disable(hdmi.sys_clk);
 
        dispc_runtime_put();
@@ -1809,7 +838,6 @@ static int hdmi_runtime_resume(struct device *dev)
 
 
        clk_enable(hdmi.sys_clk);
-       clk_enable(hdmi.hdmi_clk);
 
        return 0;
 
similarity index 79%
rename from drivers/video/omap2/dss/hdmi_omap4_panel.c
rename to drivers/video/omap2/dss/hdmi_panel.c
index 7d4f2bd7c50619591cbba2c6fb76bbafaa8ae6a5..533d5dc634d256374a22b9a2da8a8eb0453f9a34 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * hdmi_omap4_panel.c
+ * hdmi_panel.c
  *
  * HDMI library support functions for TI OMAP4 processors.
  *
@@ -25,6 +25,7 @@
 #include <linux/mutex.h>
 #include <linux/module.h>
 #include <video/omapdss.h>
+#include <linux/slab.h>
 
 #include "dss.h"
 
@@ -40,13 +41,7 @@ static int hdmi_panel_probe(struct omap_dss_device *dssdev)
        dssdev->panel.config = OMAP_DSS_LCD_TFT |
                        OMAP_DSS_LCD_IVS | OMAP_DSS_LCD_IHS;
 
-       /*
-        * Initialize the timings to 640 * 480
-        * This is only for framebuffer update not for TV timing setting
-        * Setting TV timing will be done only on enable
-        */
-       dssdev->panel.timings.x_res = 640;
-       dssdev->panel.timings.y_res = 480;
+       dssdev->panel.timings = (struct omap_video_timings){640, 480, 25175, 96, 16, 48, 2 , 11, 31};
 
        DSSDBG("hdmi_panel_probe x_res= %d y_res = %d\n",
                dssdev->panel.timings.x_res,
@@ -161,12 +156,7 @@ static void hdmi_set_timings(struct omap_dss_device *dssdev,
        mutex_lock(&hdmi.hdmi_lock);
 
        dssdev->panel.timings = *timings;
-
-       if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
-               /* turn the hdmi off and on to get new timings to use */
-               omapdss_hdmi_display_disable(dssdev);
-               omapdss_hdmi_display_set_timing(dssdev);
-       }
+       omapdss_hdmi_display_set_timing(dssdev);
 
        mutex_unlock(&hdmi.hdmi_lock);
 }
@@ -181,12 +171,54 @@ static int hdmi_check_timings(struct omap_dss_device *dssdev,
        mutex_lock(&hdmi.hdmi_lock);
 
        r = omapdss_hdmi_display_check_timing(dssdev, timings);
-       if (r) {
-               DSSERR("Timing cannot be applied\n");
-               goto err;
+
+       mutex_unlock(&hdmi.hdmi_lock);
+       return r;
+}
+
+static int hdmi_read_edid(struct omap_dss_device *dssdev, u8 *buf, int len)
+{
+       int r;
+
+       mutex_lock(&hdmi.hdmi_lock);
+
+       if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
+               r = omapdss_hdmi_display_enable(dssdev);
+               if (r)
+                       goto err;
+       }
+
+       r = omapdss_hdmi_read_edid(buf, len);
+
+       if (dssdev->state == OMAP_DSS_DISPLAY_DISABLED ||
+                       dssdev->state == OMAP_DSS_DISPLAY_SUSPENDED)
+               omapdss_hdmi_display_disable(dssdev);
+err:
+       mutex_unlock(&hdmi.hdmi_lock);
+
+       return r;
+}
+
+static bool hdmi_detect(struct omap_dss_device *dssdev)
+{
+       int r;
+
+       mutex_lock(&hdmi.hdmi_lock);
+
+       if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
+               r = omapdss_hdmi_display_enable(dssdev);
+               if (r)
+                       goto err;
        }
+
+       r = omapdss_hdmi_detect();
+
+       if (dssdev->state == OMAP_DSS_DISPLAY_DISABLED ||
+                       dssdev->state == OMAP_DSS_DISPLAY_SUSPENDED)
+               omapdss_hdmi_display_disable(dssdev);
 err:
        mutex_unlock(&hdmi.hdmi_lock);
+
        return r;
 }
 
@@ -200,6 +232,8 @@ static struct omap_dss_driver hdmi_driver = {
        .get_timings    = hdmi_get_timings,
        .set_timings    = hdmi_set_timings,
        .check_timings  = hdmi_check_timings,
+       .read_edid      = hdmi_read_edid,
+       .detect         = hdmi_detect,
        .driver                 = {
                .name   = "hdmi_panel",
                .owner  = THIS_MODULE,
index 13d72d5c714b10f5aa41e074b0640769989b93b5..6e63845cc7d7705ad5dd0217e5b2247564218483 100644 (file)
@@ -106,7 +106,7 @@ put_device:
 static ssize_t manager_default_color_show(struct omap_overlay_manager *mgr,
                                          char *buf)
 {
-       return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.default_color);
+       return snprintf(buf, PAGE_SIZE, "%#x\n", mgr->info.default_color);
 }
 
 static ssize_t manager_default_color_store(struct omap_overlay_manager *mgr,
@@ -116,8 +116,9 @@ static ssize_t manager_default_color_store(struct omap_overlay_manager *mgr,
        u32 color;
        int r;
 
-       if (sscanf(buf, "%d", &color) != 1)
-               return -EINVAL;
+       r = kstrtouint(buf, 0, &color);
+       if (r)
+               return r;
 
        mgr->get_manager_info(mgr, &info);
 
@@ -184,7 +185,7 @@ static ssize_t manager_trans_key_type_store(struct omap_overlay_manager *mgr,
 static ssize_t manager_trans_key_value_show(struct omap_overlay_manager *mgr,
                                            char *buf)
 {
-       return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.trans_key);
+       return snprintf(buf, PAGE_SIZE, "%#x\n", mgr->info.trans_key);
 }
 
 static ssize_t manager_trans_key_value_store(struct omap_overlay_manager *mgr,
@@ -194,8 +195,9 @@ static ssize_t manager_trans_key_value_store(struct omap_overlay_manager *mgr,
        u32 key_value;
        int r;
 
-       if (sscanf(buf, "%d", &key_value) != 1)
-               return -EINVAL;
+       r = kstrtouint(buf, 0, &key_value);
+       if (r)
+               return r;
 
        mgr->get_manager_info(mgr, &info);
 
@@ -222,15 +224,16 @@ static ssize_t manager_trans_key_enabled_store(struct omap_overlay_manager *mgr,
                                               const char *buf, size_t size)
 {
        struct omap_overlay_manager_info info;
-       int enable;
+       bool enable;
        int r;
 
-       if (sscanf(buf, "%d", &enable) != 1)
-               return -EINVAL;
+       r = strtobool(buf, &enable);
+       if (r)
+               return r;
 
        mgr->get_manager_info(mgr, &info);
 
-       info.trans_enabled = enable ? true : false;
+       info.trans_enabled = enable;
 
        r = mgr->set_manager_info(mgr, &info);
        if (r)
@@ -246,7 +249,10 @@ static ssize_t manager_trans_key_enabled_store(struct omap_overlay_manager *mgr,
 static ssize_t manager_alpha_blending_enabled_show(
                struct omap_overlay_manager *mgr, char *buf)
 {
-       return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.alpha_enabled);
+       WARN_ON(!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER));
+
+       return snprintf(buf, PAGE_SIZE, "%d\n",
+               mgr->info.partial_alpha_enabled);
 }
 
 static ssize_t manager_alpha_blending_enabled_store(
@@ -254,15 +260,18 @@ static ssize_t manager_alpha_blending_enabled_store(
                const char *buf, size_t size)
 {
        struct omap_overlay_manager_info info;
-       int enable;
+       bool enable;
        int r;
 
-       if (sscanf(buf, "%d", &enable) != 1)
-               return -EINVAL;
+       WARN_ON(!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER));
+
+       r = strtobool(buf, &enable);
+       if (r)
+               return r;
 
        mgr->get_manager_info(mgr, &info);
 
-       info.alpha_enabled = enable ? true : false;
+       info.partial_alpha_enabled = enable;
 
        r = mgr->set_manager_info(mgr, &info);
        if (r)
@@ -285,19 +294,16 @@ static ssize_t manager_cpr_enable_store(struct omap_overlay_manager *mgr,
                const char *buf, size_t size)
 {
        struct omap_overlay_manager_info info;
-       int v;
        int r;
        bool enable;
 
        if (!dss_has_feature(FEAT_CPR))
                return -ENODEV;
 
-       r = kstrtoint(buf, 0, &v);
+       r = strtobool(buf, &enable);
        if (r)
                return r;
 
-       enable = !!v;
-
        mgr->get_manager_info(mgr, &info);
 
        if (info.cpr_enable == enable)
@@ -586,6 +592,13 @@ static int omap_dss_unset_device(struct omap_overlay_manager *mgr)
                return -EINVAL;
        }
 
+       /*
+        * Don't allow currently enabled displays to have the overlay manager
+        * pulled out from underneath them
+        */
+       if (mgr->device->state != OMAP_DSS_DISPLAY_DISABLED)
+               return -EINVAL;
+
        mgr->device->manager = NULL;
        mgr->device = NULL;
        mgr->device_changed = true;
@@ -801,7 +814,7 @@ static int configure_overlay(enum omap_plane plane)
 {
        struct overlay_cache_data *c;
        struct manager_cache_data *mc;
-       struct omap_overlay_info *oi;
+       struct omap_overlay_info *oi, new_oi;
        struct omap_overlay_manager_info *mi;
        u16 outw, outh;
        u16 x, y, w, h;
@@ -815,7 +828,7 @@ static int configure_overlay(enum omap_plane plane)
        oi = &c->info;
 
        if (!c->enabled) {
-               dispc_enable_plane(plane, 0);
+               dispc_ovl_enable(plane, 0);
                return 0;
        }
 
@@ -843,7 +856,7 @@ static int configure_overlay(enum omap_plane plane)
                /* If the overlay is outside the update region, disable it */
                if (!rectangle_intersects(mc->x, mc->y, mc->w, mc->h,
                                        x, y, outw, outh)) {
-                       dispc_enable_plane(plane, 0);
+                       dispc_ovl_enable(plane, 0);
                        return 0;
                }
 
@@ -921,34 +934,27 @@ static int configure_overlay(enum omap_plane plane)
                }
        }
 
-       r = dispc_setup_plane(plane,
-                       paddr,
-                       oi->screen_width,
-                       x, y,
-                       w, h,
-                       outw, outh,
-                       oi->color_mode,
-                       c->ilace,
-                       oi->rotation_type,
-                       oi->rotation,
-                       oi->mirror,
-                       oi->global_alpha,
-                       oi->pre_mult_alpha,
-                       c->channel,
-                       oi->p_uv_addr);
+       new_oi = *oi;
+
+       /* update new_oi members which could have been possibly updated */
+       new_oi.pos_x = x;
+       new_oi.pos_y = y;
+       new_oi.width = w;
+       new_oi.height = h;
+       new_oi.out_width = outw;
+       new_oi.out_height = outh;
+       new_oi.paddr = paddr;
 
+       r = dispc_ovl_setup(plane, &new_oi, c->ilace, c->channel,
+               c->replication, c->fifo_low, c->fifo_high);
        if (r) {
                /* this shouldn't happen */
-               DSSERR("dispc_setup_plane failed for ovl %d\n", plane);
-               dispc_enable_plane(plane, 0);
+               DSSERR("dispc_ovl_setup failed for ovl %d\n", plane);
+               dispc_ovl_enable(plane, 0);
                return r;
        }
 
-       dispc_enable_replication(plane, c->replication);
-
-       dispc_set_fifo_threshold(plane, c->fifo_low, c->fifo_high);
-
-       dispc_enable_plane(plane, 1);
+       dispc_ovl_enable(plane, 1);
 
        return 0;
 }
@@ -962,13 +968,13 @@ static void configure_manager(enum omap_channel channel)
        /* picking info from the cache */
        mi = &dss_cache.manager_cache[channel].info;
 
-       dispc_set_default_color(channel, mi->default_color);
-       dispc_set_trans_key(channel, mi->trans_key_type, mi->trans_key);
-       dispc_enable_trans_key(channel, mi->trans_enabled);
-       dispc_enable_alpha_blending(channel, mi->alpha_enabled);
+       dispc_mgr_set_default_color(channel, mi->default_color);
+       dispc_mgr_set_trans_key(channel, mi->trans_key_type, mi->trans_key);
+       dispc_mgr_enable_trans_key(channel, mi->trans_enabled);
+       dispc_mgr_enable_alpha_fixed_zorder(channel, mi->partial_alpha_enabled);
        if (dss_has_feature(FEAT_CPR)) {
-               dispc_enable_cpr(channel, mi->cpr_enable);
-               dispc_set_cpr_coef(channel, &mi->cpr_coefs);
+               dispc_mgr_enable_cpr(channel, mi->cpr_enable);
+               dispc_mgr_set_cpr_coef(channel, &mi->cpr_coefs);
        }
 }
 
@@ -992,7 +998,7 @@ static int configure_dispc(void)
        busy = false;
 
        for (i = 0; i < num_mgrs; i++) {
-               mgr_busy[i] = dispc_go_busy(i);
+               mgr_busy[i] = dispc_mgr_go_busy(i);
                mgr_go[i] = false;
        }
 
@@ -1053,7 +1059,7 @@ static int configure_dispc(void)
                 * always be turned off after frame, and new settings will be
                 * taken in to use at next update */
                if (!mc->manual_update)
-                       dispc_go(i);
+                       dispc_mgr_go(i);
        }
 
        if (busy)
@@ -1258,7 +1264,7 @@ static void dss_apply_irq_handler(void *data, u32 mask)
        u32 irq_mask;
 
        for (i = 0; i < num_mgrs; i++)
-               mgr_busy[i] = dispc_go_busy(i);
+               mgr_busy[i] = dispc_mgr_go_busy(i);
 
        spin_lock(&dss_cache.lock);
 
@@ -1280,7 +1286,7 @@ static void dss_apply_irq_handler(void *data, u32 mask)
 
        /* re-read busy flags */
        for (i = 0; i < num_mgrs; i++)
-               mgr_busy[i] = dispc_go_busy(i);
+               mgr_busy[i] = dispc_mgr_go_busy(i);
 
        /* keep running as long as there are busy managers, so that
         * we can collect overlay-applied information */
@@ -1326,11 +1332,13 @@ static int omap_dss_mgr_apply(struct omap_overlay_manager *mgr)
 
                ovl = omap_dss_get_overlay(i);
 
-               if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
-                       continue;
-
                oc = &dss_cache.overlay_cache[ovl->id];
 
+               if (ovl->manager_changed) {
+                       ovl->manager_changed = false;
+                       ovl->info_dirty  = true;
+               }
+
                if (!overlay_enabled(ovl)) {
                        if (oc->enabled) {
                                oc->enabled = false;
@@ -1375,9 +1383,6 @@ static int omap_dss_mgr_apply(struct omap_overlay_manager *mgr)
        list_for_each_entry(mgr, &manager_list, list) {
                struct omap_dss_device *dssdev;
 
-               if (!(mgr->caps & OMAP_DSS_OVL_MGR_CAP_DISPC))
-                       continue;
-
                mc = &dss_cache.manager_cache[mgr->id];
 
                if (mgr->device_changed) {
@@ -1423,9 +1428,6 @@ static int omap_dss_mgr_apply(struct omap_overlay_manager *mgr)
 
                ovl = omap_dss_get_overlay(i);
 
-               if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
-                       continue;
-
                oc = &dss_cache.overlay_cache[ovl->id];
 
                if (!oc->enabled)
@@ -1433,11 +1435,11 @@ static int omap_dss_mgr_apply(struct omap_overlay_manager *mgr)
 
                dssdev = ovl->manager->device;
 
-               size = dispc_get_plane_fifo_size(ovl->id);
+               size = dispc_ovl_get_fifo_size(ovl->id);
                if (use_fifomerge)
                        size *= 3;
 
-               burst_size = dispc_get_burst_size(ovl->id);
+               burst_size = dispc_ovl_get_burst_size(ovl->id);
 
                switch (dssdev->type) {
                case OMAP_DISPLAY_TYPE_DPI:
@@ -1484,12 +1486,17 @@ static int omap_dss_mgr_apply(struct omap_overlay_manager *mgr)
 
 static int dss_check_manager(struct omap_overlay_manager *mgr)
 {
-       /* OMAP supports only graphics source transparency color key and alpha
-        * blending simultaneously. See TRM 15.4.2.4.2.2 Alpha Mode */
-
-       if (mgr->info.alpha_enabled && mgr->info.trans_enabled &&
-                       mgr->info.trans_key_type != OMAP_DSS_COLOR_KEY_GFX_DST)
-               return -EINVAL;
+       if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER)) {
+               /*
+                * OMAP3 supports only graphics source transparency color key
+                * and alpha blending simultaneously. See TRM 15.4.2.4.2.2
+                * Alpha Mode
+                */
+               if (mgr->info.partial_alpha_enabled && mgr->info.trans_enabled
+                       && mgr->info.trans_key_type !=
+                               OMAP_DSS_COLOR_KEY_GFX_DST)
+                       return -EINVAL;
+       }
 
        return 0;
 }
@@ -1522,13 +1529,13 @@ static void omap_dss_mgr_get_info(struct omap_overlay_manager *mgr,
 
 static int dss_mgr_enable(struct omap_overlay_manager *mgr)
 {
-       dispc_enable_channel(mgr->id, 1);
+       dispc_mgr_enable(mgr->id, 1);
        return 0;
 }
 
 static int dss_mgr_disable(struct omap_overlay_manager *mgr)
 {
-       dispc_enable_channel(mgr->id, 0);
+       dispc_mgr_enable(mgr->id, 0);
        return 0;
 }
 
@@ -1580,7 +1587,7 @@ int dss_init_overlay_managers(struct platform_device *pdev)
                mgr->enable = &dss_mgr_enable;
                mgr->disable = &dss_mgr_disable;
 
-               mgr->caps = OMAP_DSS_OVL_MGR_CAP_DISPC;
+               mgr->caps = 0;
                mgr->supported_displays =
                        dss_feat_get_supported_displays(mgr->id);
 
@@ -1597,42 +1604,6 @@ int dss_init_overlay_managers(struct platform_device *pdev)
                }
        }
 
-#ifdef L4_EXAMPLE
-       {
-               int omap_dss_mgr_apply_l4(struct omap_overlay_manager *mgr)
-               {
-                       DSSDBG("omap_dss_mgr_apply_l4(%s)\n", mgr->name);
-
-                       return 0;
-               }
-
-               struct omap_overlay_manager *mgr;
-               mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
-
-               BUG_ON(mgr == NULL);
-
-               mgr->name = "l4";
-               mgr->supported_displays =
-                       OMAP_DISPLAY_TYPE_DBI | OMAP_DISPLAY_TYPE_DSI;
-
-               mgr->set_device = &omap_dss_set_device;
-               mgr->unset_device = &omap_dss_unset_device;
-               mgr->apply = &omap_dss_mgr_apply_l4;
-               mgr->set_manager_info = &omap_dss_mgr_set_info;
-               mgr->get_manager_info = &omap_dss_mgr_get_info;
-
-               dss_overlay_setup_l4_manager(mgr);
-
-               omap_dss_add_overlay_manager(mgr);
-
-               r = kobject_init_and_add(&mgr->kobj, &manager_ktype,
-                               &pdev->dev.kobj, "managerl4");
-
-               if (r)
-                       DSSERR("failed to create sysfs file\n");
-       }
-#endif
-
        return 0;
 }
 
index c84380c53c390633d0ec3f7f28ba32f48eb685f4..ab8e40e48759969671bc6025a4ef610ef3f61272 100644 (file)
@@ -211,16 +211,17 @@ static ssize_t overlay_enabled_show(struct omap_overlay *ovl, char *buf)
 static ssize_t overlay_enabled_store(struct omap_overlay *ovl, const char *buf,
                size_t size)
 {
-       int r, enable;
+       int r;
+       bool enable;
        struct omap_overlay_info info;
 
        ovl->get_overlay_info(ovl, &info);
 
-       r = kstrtoint(buf, 0, &enable);
+       r = strtobool(buf, &enable);
        if (r)
                return r;
 
-       info.enabled = !!enable;
+       info.enabled = enable;
 
        r = ovl->set_overlay_info(ovl, &info);
        if (r)
@@ -248,7 +249,7 @@ static ssize_t overlay_global_alpha_store(struct omap_overlay *ovl,
        u8 alpha;
        struct omap_overlay_info info;
 
-       if (!dss_has_feature(FEAT_GLOBAL_ALPHA))
+       if ((ovl->caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
                return -ENODEV;
 
        r = kstrtou8(buf, 0, &alpha);
@@ -257,14 +258,7 @@ static ssize_t overlay_global_alpha_store(struct omap_overlay *ovl,
 
        ovl->get_overlay_info(ovl, &info);
 
-       /* Video1 plane does not support global alpha
-        * to always make it 255 completely opaque
-        */
-       if (!dss_has_feature(FEAT_GLOBAL_ALPHA_VID1) &&
-                       ovl->id == OMAP_DSS_VIDEO1)
-               info.global_alpha = 255;
-       else
-               info.global_alpha = alpha;
+       info.global_alpha = alpha;
 
        r = ovl->set_overlay_info(ovl, &info);
        if (r)
@@ -293,20 +287,52 @@ static ssize_t overlay_pre_mult_alpha_store(struct omap_overlay *ovl,
        u8 alpha;
        struct omap_overlay_info info;
 
+       if ((ovl->caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
+               return -ENODEV;
+
        r = kstrtou8(buf, 0, &alpha);
        if (r)
                return r;
 
        ovl->get_overlay_info(ovl, &info);
 
-       /* only GFX and Video2 plane support pre alpha multiplied
-        * set zero for Video1 plane
-        */
-       if (!dss_has_feature(FEAT_GLOBAL_ALPHA_VID1) &&
-               ovl->id == OMAP_DSS_VIDEO1)
-               info.pre_mult_alpha = 0;
-       else
-               info.pre_mult_alpha = alpha;
+       info.pre_mult_alpha = alpha;
+
+       r = ovl->set_overlay_info(ovl, &info);
+       if (r)
+               return r;
+
+       if (ovl->manager) {
+               r = ovl->manager->apply(ovl->manager);
+               if (r)
+                       return r;
+       }
+
+       return size;
+}
+
+static ssize_t overlay_zorder_show(struct omap_overlay *ovl, char *buf)
+{
+       return snprintf(buf, PAGE_SIZE, "%d\n", ovl->info.zorder);
+}
+
+static ssize_t overlay_zorder_store(struct omap_overlay *ovl,
+               const char *buf, size_t size)
+{
+       int r;
+       u8 zorder;
+       struct omap_overlay_info info;
+
+       if ((ovl->caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
+               return -ENODEV;
+
+       r = kstrtou8(buf, 0, &zorder);
+       if (r)
+               return r;
+
+       ovl->get_overlay_info(ovl, &info);
+
+       info.zorder = zorder;
 
        r = ovl->set_overlay_info(ovl, &info);
        if (r)
@@ -347,6 +373,8 @@ static OVERLAY_ATTR(global_alpha, S_IRUGO|S_IWUSR,
 static OVERLAY_ATTR(pre_mult_alpha, S_IRUGO|S_IWUSR,
                overlay_pre_mult_alpha_show,
                overlay_pre_mult_alpha_store);
+static OVERLAY_ATTR(zorder, S_IRUGO|S_IWUSR,
+               overlay_zorder_show, overlay_zorder_store);
 
 static struct attribute *overlay_sysfs_attrs[] = {
        &overlay_attr_name.attr,
@@ -358,6 +386,7 @@ static struct attribute *overlay_sysfs_attrs[] = {
        &overlay_attr_enabled.attr,
        &overlay_attr_global_alpha.attr,
        &overlay_attr_pre_mult_alpha.attr,
+       &overlay_attr_zorder.attr,
        NULL
 };
 
@@ -407,6 +436,7 @@ int dss_check_overlay(struct omap_overlay *ovl, struct omap_dss_device *dssdev)
        struct omap_overlay_info *info;
        u16 outw, outh;
        u16 dw, dh;
+       int i;
 
        if (!dssdev)
                return 0;
@@ -462,6 +492,31 @@ int dss_check_overlay(struct omap_overlay *ovl, struct omap_dss_device *dssdev)
                return -EINVAL;
        }
 
+       if (ovl->caps & OMAP_DSS_OVL_CAP_ZORDER) {
+               if (info->zorder < 0 || info->zorder > 3) {
+                       DSSERR("zorder out of range: %d\n",
+                               info->zorder);
+                       return -EINVAL;
+               }
+               /*
+                * Check that zorder doesn't match with zorder of any other
+                * overlay which is enabled and is also connected to the same
+                * manager
+                */
+               for (i = 0; i < omap_dss_get_num_overlays(); i++) {
+                       struct omap_overlay *tmp_ovl = omap_dss_get_overlay(i);
+
+                       if (tmp_ovl->id != ovl->id &&
+                                       tmp_ovl->manager == ovl->manager &&
+                                       tmp_ovl->info.enabled == true &&
+                                       tmp_ovl->info.zorder == info->zorder) {
+                               DSSERR("%s and %s have same zorder: %d\n",
+                                       ovl->name, tmp_ovl->name, info->zorder);
+                               return -EINVAL;
+                       }
+               }
+       }
+
        return 0;
 }
 
@@ -516,6 +571,7 @@ static int omap_dss_set_manager(struct omap_overlay *ovl,
        }
 
        ovl->manager = mgr;
+       ovl->manager_changed = true;
 
        /* XXX: When there is an overlay on a DSI manual update display, and
         * the overlay is first disabled, then moved to tv, and enabled, we
@@ -529,15 +585,12 @@ static int omap_dss_set_manager(struct omap_overlay *ovl,
         * Userspace workaround for this is to update the LCD after disabling
         * the overlay, but before moving the overlay to TV.
         */
-       dispc_set_channel_out(ovl->id, mgr->id);
 
        return 0;
 }
 
 static int omap_dss_unset_manager(struct omap_overlay *ovl)
 {
-       int r;
-
        if (!ovl->manager) {
                DSSERR("failed to detach overlay: manager not set\n");
                return -EINVAL;
@@ -548,11 +601,8 @@ static int omap_dss_unset_manager(struct omap_overlay *ovl)
                return -EINVAL;
        }
 
-       r = ovl->wait_for_go(ovl);
-       if (r)
-               return r;
-
        ovl->manager = NULL;
+       ovl->manager_changed = true;
 
        return 0;
 }
@@ -618,22 +668,29 @@ void dss_init_overlays(struct platform_device *pdev)
                case 0:
                        ovl->name = "gfx";
                        ovl->id = OMAP_DSS_GFX;
-                       ovl->caps = OMAP_DSS_OVL_CAP_DISPC;
                        ovl->info.global_alpha = 255;
+                       ovl->info.zorder = 0;
                        break;
                case 1:
                        ovl->name = "vid1";
                        ovl->id = OMAP_DSS_VIDEO1;
-                       ovl->caps = OMAP_DSS_OVL_CAP_SCALE |
-                               OMAP_DSS_OVL_CAP_DISPC;
                        ovl->info.global_alpha = 255;
+                       ovl->info.zorder =
+                               dss_has_feature(FEAT_ALPHA_FREE_ZORDER) ? 3 : 0;
                        break;
                case 2:
                        ovl->name = "vid2";
                        ovl->id = OMAP_DSS_VIDEO2;
-                       ovl->caps = OMAP_DSS_OVL_CAP_SCALE |
-                               OMAP_DSS_OVL_CAP_DISPC;
                        ovl->info.global_alpha = 255;
+                       ovl->info.zorder =
+                               dss_has_feature(FEAT_ALPHA_FREE_ZORDER) ? 2 : 0;
+                       break;
+               case 3:
+                       ovl->name = "vid3";
+                       ovl->id = OMAP_DSS_VIDEO3;
+                       ovl->info.global_alpha = 255;
+                       ovl->info.zorder =
+                               dss_has_feature(FEAT_ALPHA_FREE_ZORDER) ? 1 : 0;
                        break;
                }
 
@@ -643,6 +700,7 @@ void dss_init_overlays(struct platform_device *pdev)
                ovl->get_overlay_info = &dss_ovl_get_overlay_info;
                ovl->wait_for_go = &dss_ovl_wait_for_go;
 
+               ovl->caps = dss_feat_get_overlay_caps(ovl->id);
                ovl->supported_modes =
                        dss_feat_get_supported_color_modes(ovl->id);
 
index 39f4c597026accec26621bfc5cdedd75ad1e9c4b..1bd3703e42ffef0c7e8368564a0c2f97007023fc 100644 (file)
@@ -309,9 +309,9 @@ static void rfbi_transfer_area(struct omap_dss_device *dssdev, u16 width,
 
        DSSDBG("rfbi_transfer_area %dx%d\n", width, height);
 
-       dispc_set_lcd_size(dssdev->manager->id, width, height);
+       dispc_mgr_set_lcd_size(dssdev->manager->id, width, height);
 
-       dispc_enable_channel(dssdev->manager->id, true);
+       dispc_mgr_enable(dssdev->manager->id, true);
 
        rfbi.framedone_callback = callback;
        rfbi.framedone_callback_data = data;
@@ -783,10 +783,8 @@ int omap_rfbi_prepare_update(struct omap_dss_device *dssdev,
        if (*w == 0 || *h == 0)
                return -EINVAL;
 
-       if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
-               dss_setup_partial_planes(dssdev, x, y, w, h, true);
-               dispc_set_lcd_size(dssdev->manager->id, *w, *h);
-       }
+       dss_setup_partial_planes(dssdev, x, y, w, h, true);
+       dispc_mgr_set_lcd_size(dssdev->manager->id, *w, *h);
 
        return 0;
 }
@@ -796,22 +794,7 @@ int omap_rfbi_update(struct omap_dss_device *dssdev,
                u16 x, u16 y, u16 w, u16 h,
                void (*callback)(void *), void *data)
 {
-       if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
-               rfbi_transfer_area(dssdev, w, h, callback, data);
-       } else {
-               struct omap_overlay *ovl;
-               void __iomem *addr;
-               int scr_width;
-
-               ovl = dssdev->manager->overlays[0];
-               scr_width = ovl->info.screen_width;
-               addr = ovl->info.vaddr;
-
-               omap_rfbi_write_pixels(addr, scr_width, x, y, w, h);
-
-               callback(data);
-       }
-
+       rfbi_transfer_area(dssdev, w, h, callback, data);
        return 0;
 }
 EXPORT_SYMBOL(omap_rfbi_update);
@@ -860,6 +843,11 @@ int omapdss_rfbi_display_enable(struct omap_dss_device *dssdev)
 {
        int r;
 
+       if (dssdev->manager == NULL) {
+               DSSERR("failed to enable display: no manager\n");
+               return -ENODEV;
+       }
+
        r = rfbi_runtime_get();
        if (r)
                return r;
@@ -877,13 +865,13 @@ int omapdss_rfbi_display_enable(struct omap_dss_device *dssdev)
                goto err1;
        }
 
-       dispc_set_lcd_display_type(dssdev->manager->id,
+       dispc_mgr_set_lcd_display_type(dssdev->manager->id,
                        OMAP_DSS_LCD_DISPLAY_TFT);
 
-       dispc_set_parallel_interface_mode(dssdev->manager->id,
-                       OMAP_DSS_PARALLELMODE_RFBI);
+       dispc_mgr_set_io_pad_mode(DSS_IO_PAD_MODE_RFBI);
+       dispc_mgr_enable_stallmode(dssdev->manager->id, true);
 
-       dispc_set_tft_data_lines(dssdev->manager->id, dssdev->ctrl.pixel_size);
+       dispc_mgr_set_tft_data_lines(dssdev->manager->id, dssdev->ctrl.pixel_size);
 
        rfbi_configure(dssdev->phy.rfbi.channel,
                               dssdev->ctrl.pixel_size,
@@ -952,10 +940,7 @@ static int omap_rfbihw_probe(struct platform_device *pdev)
 
        msleep(10);
 
-       if (cpu_is_omap24xx() || cpu_is_omap34xx() || cpu_is_omap3630())
-               clk = dss_get_ick();
-       else
-               clk = clk_get(&pdev->dev, "ick");
+       clk = clk_get(&pdev->dev, "ick");
        if (IS_ERR(clk)) {
                DSSERR("can't get ick\n");
                r = PTR_ERR(clk);
index 3a688c871a45579d8a695af71e88f91160a5e67c..695dc04cabbae4a5ec42acda1dbf35850cb2d078 100644 (file)
@@ -35,13 +35,13 @@ static struct {
 static void sdi_basic_init(struct omap_dss_device *dssdev)
 
 {
-       dispc_set_parallel_interface_mode(dssdev->manager->id,
-                       OMAP_DSS_PARALLELMODE_BYPASS);
+       dispc_mgr_set_io_pad_mode(DSS_IO_PAD_MODE_BYPASS);
+       dispc_mgr_enable_stallmode(dssdev->manager->id, false);
 
-       dispc_set_lcd_display_type(dssdev->manager->id,
+       dispc_mgr_set_lcd_display_type(dssdev->manager->id,
                        OMAP_DSS_LCD_DISPLAY_TFT);
 
-       dispc_set_tft_data_lines(dssdev->manager->id, 24);
+       dispc_mgr_set_tft_data_lines(dssdev->manager->id, 24);
        dispc_lcd_enable_signal_polarity(1);
 }
 
@@ -55,6 +55,11 @@ int omapdss_sdi_display_enable(struct omap_dss_device *dssdev)
        unsigned long pck;
        int r;
 
+       if (dssdev->manager == NULL) {
+               DSSERR("failed to enable display: no manager\n");
+               return -ENODEV;
+       }
+
        r = omap_dss_start_device(dssdev);
        if (r) {
                DSSERR("failed to start device\n");
@@ -78,7 +83,7 @@ int omapdss_sdi_display_enable(struct omap_dss_device *dssdev)
        /* 15.5.9.1.2 */
        dssdev->panel.config |= OMAP_DSS_LCD_RF | OMAP_DSS_LCD_ONOFF;
 
-       dispc_set_pol_freq(dssdev->manager->id, dssdev->panel.config,
+       dispc_mgr_set_pol_freq(dssdev->manager->id, dssdev->panel.config,
                        dssdev->panel.acbi, dssdev->panel.acb);
 
        r = dss_calc_clock_div(1, t->pixel_clock * 1000,
@@ -101,13 +106,13 @@ int omapdss_sdi_display_enable(struct omap_dss_device *dssdev)
        }
 
 
-       dispc_set_lcd_timings(dssdev->manager->id, t);
+       dispc_mgr_set_lcd_timings(dssdev->manager->id, t);
 
        r = dss_set_clock_div(&dss_cinfo);
        if (r)
                goto err_set_dss_clock_div;
 
-       r = dispc_set_clock_div(dssdev->manager->id, &dispc_cinfo);
+       r = dispc_mgr_set_clock_div(dssdev->manager->id, &dispc_cinfo);
        if (r)
                goto err_set_dispc_clock_div;
 
diff --git a/drivers/video/omap2/dss/ti_hdmi.h b/drivers/video/omap2/dss/ti_hdmi.h
new file mode 100644 (file)
index 0000000..2c3443d
--- /dev/null
@@ -0,0 +1,138 @@
+/*
+ * ti_hdmi.h
+ *
+ * HDMI driver definition for TI OMAP4, DM81xx, DM38xx  Processor.
+ *
+ * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _TI_HDMI_H
+#define _TI_HDMI_H
+
+struct hdmi_ip_data;
+
+enum hdmi_pll_pwr {
+       HDMI_PLLPWRCMD_ALLOFF = 0,
+       HDMI_PLLPWRCMD_PLLONLY = 1,
+       HDMI_PLLPWRCMD_BOTHON_ALLCLKS = 2,
+       HDMI_PLLPWRCMD_BOTHON_NOPHYCLK = 3
+};
+
+enum hdmi_core_hdmi_dvi {
+       HDMI_DVI = 0,
+       HDMI_HDMI = 1
+};
+
+enum hdmi_clk_refsel {
+       HDMI_REFSEL_PCLK = 0,
+       HDMI_REFSEL_REF1 = 1,
+       HDMI_REFSEL_REF2 = 2,
+       HDMI_REFSEL_SYSCLK = 3
+};
+
+struct hdmi_video_timings {
+       u16 x_res;
+       u16 y_res;
+       /* Unit: KHz */
+       u32 pixel_clock;
+       u16 hsw;
+       u16 hfp;
+       u16 hbp;
+       u16 vsw;
+       u16 vfp;
+       u16 vbp;
+};
+
+/* HDMI timing structure */
+struct hdmi_timings {
+       struct hdmi_video_timings timings;
+       int vsync_pol;
+       int hsync_pol;
+};
+
+struct hdmi_cm {
+       int     code;
+       int     mode;
+};
+
+struct hdmi_config {
+       struct hdmi_timings timings;
+       u16     interlace;
+       struct hdmi_cm cm;
+};
+
+/* HDMI PLL structure */
+struct hdmi_pll_info {
+       u16 regn;
+       u16 regm;
+       u32 regmf;
+       u16 regm2;
+       u16 regsd;
+       u16 dcofreq;
+       enum hdmi_clk_refsel refsel;
+};
+
+struct ti_hdmi_ip_ops {
+
+       void (*video_configure)(struct hdmi_ip_data *ip_data);
+
+       int (*phy_enable)(struct hdmi_ip_data *ip_data);
+
+       void (*phy_disable)(struct hdmi_ip_data *ip_data);
+
+       int (*read_edid)(struct hdmi_ip_data *ip_data, u8 *edid, int len);
+
+       bool (*detect)(struct hdmi_ip_data *ip_data);
+
+       int (*pll_enable)(struct hdmi_ip_data *ip_data);
+
+       void (*pll_disable)(struct hdmi_ip_data *ip_data);
+
+       void (*video_enable)(struct hdmi_ip_data *ip_data, bool start);
+
+       void (*dump_wrapper)(struct hdmi_ip_data *ip_data, struct seq_file *s);
+
+       void (*dump_core)(struct hdmi_ip_data *ip_data, struct seq_file *s);
+
+       void (*dump_pll)(struct hdmi_ip_data *ip_data, struct seq_file *s);
+
+       void (*dump_phy)(struct hdmi_ip_data *ip_data, struct seq_file *s);
+
+};
+
+struct hdmi_ip_data {
+       void __iomem    *base_wp;       /* HDMI wrapper */
+       unsigned long   core_sys_offset;
+       unsigned long   core_av_offset;
+       unsigned long   pll_offset;
+       unsigned long   phy_offset;
+       const struct ti_hdmi_ip_ops *ops;
+       struct hdmi_config cfg;
+       struct hdmi_pll_info pll_data;
+};
+int ti_hdmi_4xxx_phy_enable(struct hdmi_ip_data *ip_data);
+void ti_hdmi_4xxx_phy_disable(struct hdmi_ip_data *ip_data);
+int ti_hdmi_4xxx_read_edid(struct hdmi_ip_data *ip_data, u8 *edid, int len);
+bool ti_hdmi_4xxx_detect(struct hdmi_ip_data *ip_data);
+void ti_hdmi_4xxx_wp_video_start(struct hdmi_ip_data *ip_data, bool start);
+int ti_hdmi_4xxx_pll_enable(struct hdmi_ip_data *ip_data);
+void ti_hdmi_4xxx_pll_disable(struct hdmi_ip_data *ip_data);
+void ti_hdmi_4xxx_basic_configure(struct hdmi_ip_data *ip_data);
+void ti_hdmi_4xxx_wp_dump(struct hdmi_ip_data *ip_data, struct seq_file *s);
+void ti_hdmi_4xxx_pll_dump(struct hdmi_ip_data *ip_data, struct seq_file *s);
+void ti_hdmi_4xxx_core_dump(struct hdmi_ip_data *ip_data, struct seq_file *s);
+void ti_hdmi_4xxx_phy_dump(struct hdmi_ip_data *ip_data, struct seq_file *s);
+
+#endif
diff --git a/drivers/video/omap2/dss/ti_hdmi_4xxx_ip.c b/drivers/video/omap2/dss/ti_hdmi_4xxx_ip.c
new file mode 100644 (file)
index 0000000..e1a6ce5
--- /dev/null
@@ -0,0 +1,1239 @@
+/*
+ * ti_hdmi_4xxx_ip.c
+ *
+ * HDMI TI81xx, TI38xx, TI OMAP4 etc IP driver Library
+ * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com/
+ * Authors: Yong Zhi
+ *     Mythri pk <mythripk@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/interrupt.h>
+#include <linux/mutex.h>
+#include <linux/delay.h>
+#include <linux/string.h>
+#include <linux/seq_file.h>
+
+#include "ti_hdmi_4xxx_ip.h"
+#include "dss.h"
+
+static inline void hdmi_write_reg(void __iomem *base_addr,
+                               const u16 idx, u32 val)
+{
+       __raw_writel(val, base_addr + idx);
+}
+
+static inline u32 hdmi_read_reg(void __iomem *base_addr,
+                               const u16 idx)
+{
+       return __raw_readl(base_addr + idx);
+}
+
+static inline void __iomem *hdmi_wp_base(struct hdmi_ip_data *ip_data)
+{
+       return ip_data->base_wp;
+}
+
+static inline void __iomem *hdmi_phy_base(struct hdmi_ip_data *ip_data)
+{
+       return ip_data->base_wp + ip_data->phy_offset;
+}
+
+static inline void __iomem *hdmi_pll_base(struct hdmi_ip_data *ip_data)
+{
+       return ip_data->base_wp + ip_data->pll_offset;
+}
+
+static inline void __iomem *hdmi_av_base(struct hdmi_ip_data *ip_data)
+{
+       return ip_data->base_wp + ip_data->core_av_offset;
+}
+
+static inline void __iomem *hdmi_core_sys_base(struct hdmi_ip_data *ip_data)
+{
+       return ip_data->base_wp + ip_data->core_sys_offset;
+}
+
+static inline int hdmi_wait_for_bit_change(void __iomem *base_addr,
+                               const u16 idx,
+                               int b2, int b1, u32 val)
+{
+       u32 t = 0;
+       while (val != REG_GET(base_addr, idx, b2, b1)) {
+               udelay(1);
+               if (t++ > 10000)
+                       return !val;
+       }
+       return val;
+}
+
+static int hdmi_pll_init(struct hdmi_ip_data *ip_data)
+{
+       u32 r;
+       void __iomem *pll_base = hdmi_pll_base(ip_data);
+       struct hdmi_pll_info *fmt = &ip_data->pll_data;
+
+       /* PLL start always use manual mode */
+       REG_FLD_MOD(pll_base, PLLCTRL_PLL_CONTROL, 0x0, 0, 0);
+
+       r = hdmi_read_reg(pll_base, PLLCTRL_CFG1);
+       r = FLD_MOD(r, fmt->regm, 20, 9); /* CFG1_PLL_REGM */
+       r = FLD_MOD(r, fmt->regn - 1, 8, 1);  /* CFG1_PLL_REGN */
+
+       hdmi_write_reg(pll_base, PLLCTRL_CFG1, r);
+
+       r = hdmi_read_reg(pll_base, PLLCTRL_CFG2);
+
+       r = FLD_MOD(r, 0x0, 12, 12); /* PLL_HIGHFREQ divide by 2 */
+       r = FLD_MOD(r, 0x1, 13, 13); /* PLL_REFEN */
+       r = FLD_MOD(r, 0x0, 14, 14); /* PHY_CLKINEN de-assert during locking */
+       r = FLD_MOD(r, fmt->refsel, 22, 21); /* REFSEL */
+
+       if (fmt->dcofreq) {
+               /* divider programming for frequency beyond 1000Mhz */
+               REG_FLD_MOD(pll_base, PLLCTRL_CFG3, fmt->regsd, 17, 10);
+               r = FLD_MOD(r, 0x4, 3, 1); /* 1000MHz and 2000MHz */
+       } else {
+               r = FLD_MOD(r, 0x2, 3, 1); /* 500MHz and 1000MHz */
+       }
+
+       hdmi_write_reg(pll_base, PLLCTRL_CFG2, r);
+
+       r = hdmi_read_reg(pll_base, PLLCTRL_CFG4);
+       r = FLD_MOD(r, fmt->regm2, 24, 18);
+       r = FLD_MOD(r, fmt->regmf, 17, 0);
+
+       hdmi_write_reg(pll_base, PLLCTRL_CFG4, r);
+
+       /* go now */
+       REG_FLD_MOD(pll_base, PLLCTRL_PLL_GO, 0x1, 0, 0);
+
+       /* wait for bit change */
+       if (hdmi_wait_for_bit_change(pll_base, PLLCTRL_PLL_GO,
+                                                       0, 0, 1) != 1) {
+               pr_err("PLL GO bit not set\n");
+               return -ETIMEDOUT;
+       }
+
+       /* Wait till the lock bit is set in PLL status */
+       if (hdmi_wait_for_bit_change(pll_base,
+                               PLLCTRL_PLL_STATUS, 1, 1, 1) != 1) {
+               pr_err("cannot lock PLL\n");
+               pr_err("CFG1 0x%x\n",
+                       hdmi_read_reg(pll_base, PLLCTRL_CFG1));
+               pr_err("CFG2 0x%x\n",
+                       hdmi_read_reg(pll_base, PLLCTRL_CFG2));
+               pr_err("CFG4 0x%x\n",
+                       hdmi_read_reg(pll_base, PLLCTRL_CFG4));
+               return -ETIMEDOUT;
+       }
+
+       pr_debug("PLL locked!\n");
+
+       return 0;
+}
+
+/* PHY_PWR_CMD */
+static int hdmi_set_phy_pwr(struct hdmi_ip_data *ip_data, enum hdmi_phy_pwr val)
+{
+       /* Command for power control of HDMI PHY */
+       REG_FLD_MOD(hdmi_wp_base(ip_data), HDMI_WP_PWR_CTRL, val, 7, 6);
+
+       /* Status of the power control of HDMI PHY */
+       if (hdmi_wait_for_bit_change(hdmi_wp_base(ip_data),
+                               HDMI_WP_PWR_CTRL, 5, 4, val) != val) {
+               pr_err("Failed to set PHY power mode to %d\n", val);
+               return -ETIMEDOUT;
+       }
+
+       return 0;
+}
+
+/* PLL_PWR_CMD */
+static int hdmi_set_pll_pwr(struct hdmi_ip_data *ip_data, enum hdmi_pll_pwr val)
+{
+       /* Command for power control of HDMI PLL */
+       REG_FLD_MOD(hdmi_wp_base(ip_data), HDMI_WP_PWR_CTRL, val, 3, 2);
+
+       /* wait till PHY_PWR_STATUS is set */
+       if (hdmi_wait_for_bit_change(hdmi_wp_base(ip_data), HDMI_WP_PWR_CTRL,
+                                               1, 0, val) != val) {
+               pr_err("Failed to set PLL_PWR_STATUS\n");
+               return -ETIMEDOUT;
+       }
+
+       return 0;
+}
+
+static int hdmi_pll_reset(struct hdmi_ip_data *ip_data)
+{
+       /* SYSRESET  controlled by power FSM */
+       REG_FLD_MOD(hdmi_pll_base(ip_data), PLLCTRL_PLL_CONTROL, 0x0, 3, 3);
+
+       /* READ 0x0 reset is in progress */
+       if (hdmi_wait_for_bit_change(hdmi_pll_base(ip_data),
+                               PLLCTRL_PLL_STATUS, 0, 0, 1) != 1) {
+               pr_err("Failed to sysreset PLL\n");
+               return -ETIMEDOUT;
+       }
+
+       return 0;
+}
+
+int ti_hdmi_4xxx_pll_enable(struct hdmi_ip_data *ip_data)
+{
+       u16 r = 0;
+
+       r = hdmi_set_pll_pwr(ip_data, HDMI_PLLPWRCMD_ALLOFF);
+       if (r)
+               return r;
+
+       r = hdmi_set_pll_pwr(ip_data, HDMI_PLLPWRCMD_BOTHON_ALLCLKS);
+       if (r)
+               return r;
+
+       r = hdmi_pll_reset(ip_data);
+       if (r)
+               return r;
+
+       r = hdmi_pll_init(ip_data);
+       if (r)
+               return r;
+
+       return 0;
+}
+
+void ti_hdmi_4xxx_pll_disable(struct hdmi_ip_data *ip_data)
+{
+       hdmi_set_pll_pwr(ip_data, HDMI_PLLPWRCMD_ALLOFF);
+}
+
+int ti_hdmi_4xxx_phy_enable(struct hdmi_ip_data *ip_data)
+{
+       u16 r = 0;
+       void __iomem *phy_base = hdmi_phy_base(ip_data);
+
+       r = hdmi_set_phy_pwr(ip_data, HDMI_PHYPWRCMD_LDOON);
+       if (r)
+               return r;
+
+       r = hdmi_set_phy_pwr(ip_data, HDMI_PHYPWRCMD_TXON);
+       if (r)
+               return r;
+
+       /*
+        * Read address 0 in order to get the SCP reset done completed
+        * Dummy access performed to make sure reset is done
+        */
+       hdmi_read_reg(phy_base, HDMI_TXPHY_TX_CTRL);
+
+       /*
+        * Write to phy address 0 to configure the clock
+        * use HFBITCLK write HDMI_TXPHY_TX_CONTROL_FREQOUT field
+        */
+       REG_FLD_MOD(phy_base, HDMI_TXPHY_TX_CTRL, 0x1, 31, 30);
+
+       /* Write to phy address 1 to start HDMI line (TXVALID and TMDSCLKEN) */
+       hdmi_write_reg(phy_base, HDMI_TXPHY_DIGITAL_CTRL, 0xF0000000);
+
+       /* Setup max LDO voltage */
+       REG_FLD_MOD(phy_base, HDMI_TXPHY_POWER_CTRL, 0xB, 3, 0);
+
+       /* Write to phy address 3 to change the polarity control */
+       REG_FLD_MOD(phy_base, HDMI_TXPHY_PAD_CFG_CTRL, 0x1, 27, 27);
+
+       return 0;
+}
+
+void ti_hdmi_4xxx_phy_disable(struct hdmi_ip_data *ip_data)
+{
+       hdmi_set_phy_pwr(ip_data, HDMI_PHYPWRCMD_OFF);
+}
+
+static int hdmi_core_ddc_init(struct hdmi_ip_data *ip_data)
+{
+       void __iomem *base = hdmi_core_sys_base(ip_data);
+
+       /* Turn on CLK for DDC */
+       REG_FLD_MOD(base, HDMI_CORE_AV_DPD, 0x7, 2, 0);
+
+       /* IN_PROG */
+       if (REG_GET(base, HDMI_CORE_DDC_STATUS, 4, 4) == 1) {
+               /* Abort transaction */
+               REG_FLD_MOD(base, HDMI_CORE_DDC_CMD, 0xf, 3, 0);
+               /* IN_PROG */
+               if (hdmi_wait_for_bit_change(base, HDMI_CORE_DDC_STATUS,
+                                       4, 4, 0) != 0) {
+                       DSSERR("Timeout aborting DDC transaction\n");
+                       return -ETIMEDOUT;
+               }
+       }
+
+       /* Clk SCL Devices */
+       REG_FLD_MOD(base, HDMI_CORE_DDC_CMD, 0xA, 3, 0);
+
+       /* HDMI_CORE_DDC_STATUS_IN_PROG */
+       if (hdmi_wait_for_bit_change(base, HDMI_CORE_DDC_STATUS,
+                               4, 4, 0) != 0) {
+               DSSERR("Timeout starting SCL clock\n");
+               return -ETIMEDOUT;
+       }
+
+       /* Clear FIFO */
+       REG_FLD_MOD(base, HDMI_CORE_DDC_CMD, 0x9, 3, 0);
+
+       /* HDMI_CORE_DDC_STATUS_IN_PROG */
+       if (hdmi_wait_for_bit_change(base, HDMI_CORE_DDC_STATUS,
+                               4, 4, 0) != 0) {
+               DSSERR("Timeout clearing DDC fifo\n");
+               return -ETIMEDOUT;
+       }
+
+       return 0;
+}
+
+static int hdmi_core_ddc_edid(struct hdmi_ip_data *ip_data,
+               u8 *pedid, int ext)
+{
+       void __iomem *base = hdmi_core_sys_base(ip_data);
+       u32 i;
+       char checksum;
+       u32 offset = 0;
+
+       /* HDMI_CORE_DDC_STATUS_IN_PROG */
+       if (hdmi_wait_for_bit_change(base, HDMI_CORE_DDC_STATUS,
+                               4, 4, 0) != 0) {
+               DSSERR("Timeout waiting DDC to be ready\n");
+               return -ETIMEDOUT;
+       }
+
+       if (ext % 2 != 0)
+               offset = 0x80;
+
+       /* Load Segment Address Register */
+       REG_FLD_MOD(base, HDMI_CORE_DDC_SEGM, ext / 2, 7, 0);
+
+       /* Load Slave Address Register */
+       REG_FLD_MOD(base, HDMI_CORE_DDC_ADDR, 0xA0 >> 1, 7, 1);
+
+       /* Load Offset Address Register */
+       REG_FLD_MOD(base, HDMI_CORE_DDC_OFFSET, offset, 7, 0);
+
+       /* Load Byte Count */
+       REG_FLD_MOD(base, HDMI_CORE_DDC_COUNT1, 0x80, 7, 0);
+       REG_FLD_MOD(base, HDMI_CORE_DDC_COUNT2, 0x0, 1, 0);
+
+       /* Set DDC_CMD */
+       if (ext)
+               REG_FLD_MOD(base, HDMI_CORE_DDC_CMD, 0x4, 3, 0);
+       else
+               REG_FLD_MOD(base, HDMI_CORE_DDC_CMD, 0x2, 3, 0);
+
+       /* HDMI_CORE_DDC_STATUS_BUS_LOW */
+       if (REG_GET(base, HDMI_CORE_DDC_STATUS, 6, 6) == 1) {
+               pr_err("I2C Bus Low?\n");
+               return -EIO;
+       }
+       /* HDMI_CORE_DDC_STATUS_NO_ACK */
+       if (REG_GET(base, HDMI_CORE_DDC_STATUS, 5, 5) == 1) {
+               pr_err("I2C No Ack\n");
+               return -EIO;
+       }
+
+       for (i = 0; i < 0x80; ++i) {
+               int t;
+
+               /* IN_PROG */
+               if (REG_GET(base, HDMI_CORE_DDC_STATUS, 4, 4) == 0) {
+                       DSSERR("operation stopped when reading edid\n");
+                       return -EIO;
+               }
+
+               t = 0;
+               /* FIFO_EMPTY */
+               while (REG_GET(base, HDMI_CORE_DDC_STATUS, 2, 2) == 1) {
+                       if (t++ > 10000) {
+                               DSSERR("timeout reading edid\n");
+                               return -ETIMEDOUT;
+                       }
+                       udelay(1);
+               }
+
+               pedid[i] = REG_GET(base, HDMI_CORE_DDC_DATA, 7, 0);
+       }
+
+       checksum = 0;
+       for (i = 0; i < 0x80; ++i)
+               checksum += pedid[i];
+
+       if (checksum != 0) {
+               pr_err("E-EDID checksum failed!!\n");
+               return -EIO;
+       }
+
+       return 0;
+}
+
+int ti_hdmi_4xxx_read_edid(struct hdmi_ip_data *ip_data,
+                               u8 *edid, int len)
+{
+       int r, l;
+
+       if (len < 128)
+               return -EINVAL;
+
+       r = hdmi_core_ddc_init(ip_data);
+       if (r)
+               return r;
+
+       r = hdmi_core_ddc_edid(ip_data, edid, 0);
+       if (r)
+               return r;
+
+       l = 128;
+
+       if (len >= 128 * 2 && edid[0x7e] > 0) {
+               r = hdmi_core_ddc_edid(ip_data, edid + 0x80, 1);
+               if (r)
+                       return r;
+               l += 128;
+       }
+
+       return l;
+}
+
+bool ti_hdmi_4xxx_detect(struct hdmi_ip_data *ip_data)
+{
+       int r;
+
+       void __iomem *base = hdmi_core_sys_base(ip_data);
+
+       /* HPD */
+       r = REG_GET(base, HDMI_CORE_SYS_SYS_STAT, 1, 1);
+
+       return r == 1;
+}
+
+static void hdmi_core_init(struct hdmi_core_video_config *video_cfg,
+                       struct hdmi_core_infoframe_avi *avi_cfg,
+                       struct hdmi_core_packet_enable_repeat *repeat_cfg)
+{
+       pr_debug("Enter hdmi_core_init\n");
+
+       /* video core */
+       video_cfg->ip_bus_width = HDMI_INPUT_8BIT;
+       video_cfg->op_dither_truc = HDMI_OUTPUTTRUNCATION_8BIT;
+       video_cfg->deep_color_pkt = HDMI_DEEPCOLORPACKECTDISABLE;
+       video_cfg->pkt_mode = HDMI_PACKETMODERESERVEDVALUE;
+       video_cfg->hdmi_dvi = HDMI_DVI;
+       video_cfg->tclk_sel_clkmult = HDMI_FPLL10IDCK;
+
+       /* info frame */
+       avi_cfg->db1_format = 0;
+       avi_cfg->db1_active_info = 0;
+       avi_cfg->db1_bar_info_dv = 0;
+       avi_cfg->db1_scan_info = 0;
+       avi_cfg->db2_colorimetry = 0;
+       avi_cfg->db2_aspect_ratio = 0;
+       avi_cfg->db2_active_fmt_ar = 0;
+       avi_cfg->db3_itc = 0;
+       avi_cfg->db3_ec = 0;
+       avi_cfg->db3_q_range = 0;
+       avi_cfg->db3_nup_scaling = 0;
+       avi_cfg->db4_videocode = 0;
+       avi_cfg->db5_pixel_repeat = 0;
+       avi_cfg->db6_7_line_eoftop = 0 ;
+       avi_cfg->db8_9_line_sofbottom = 0;
+       avi_cfg->db10_11_pixel_eofleft = 0;
+       avi_cfg->db12_13_pixel_sofright = 0;
+
+       /* packet enable and repeat */
+       repeat_cfg->audio_pkt = 0;
+       repeat_cfg->audio_pkt_repeat = 0;
+       repeat_cfg->avi_infoframe = 0;
+       repeat_cfg->avi_infoframe_repeat = 0;
+       repeat_cfg->gen_cntrl_pkt = 0;
+       repeat_cfg->gen_cntrl_pkt_repeat = 0;
+       repeat_cfg->generic_pkt = 0;
+       repeat_cfg->generic_pkt_repeat = 0;
+}
+
+static void hdmi_core_powerdown_disable(struct hdmi_ip_data *ip_data)
+{
+       pr_debug("Enter hdmi_core_powerdown_disable\n");
+       REG_FLD_MOD(hdmi_core_sys_base(ip_data), HDMI_CORE_CTRL1, 0x0, 0, 0);
+}
+
+static void hdmi_core_swreset_release(struct hdmi_ip_data *ip_data)
+{
+       pr_debug("Enter hdmi_core_swreset_release\n");
+       REG_FLD_MOD(hdmi_core_sys_base(ip_data), HDMI_CORE_SYS_SRST, 0x0, 0, 0);
+}
+
+static void hdmi_core_swreset_assert(struct hdmi_ip_data *ip_data)
+{
+       pr_debug("Enter hdmi_core_swreset_assert\n");
+       REG_FLD_MOD(hdmi_core_sys_base(ip_data), HDMI_CORE_SYS_SRST, 0x1, 0, 0);
+}
+
+/* HDMI_CORE_VIDEO_CONFIG */
+static void hdmi_core_video_config(struct hdmi_ip_data *ip_data,
+                               struct hdmi_core_video_config *cfg)
+{
+       u32 r = 0;
+       void __iomem *core_sys_base = hdmi_core_sys_base(ip_data);
+
+       /* sys_ctrl1 default configuration not tunable */
+       r = hdmi_read_reg(core_sys_base, HDMI_CORE_CTRL1);
+       r = FLD_MOD(r, HDMI_CORE_CTRL1_VEN_FOLLOWVSYNC, 5, 5);
+       r = FLD_MOD(r, HDMI_CORE_CTRL1_HEN_FOLLOWHSYNC, 4, 4);
+       r = FLD_MOD(r, HDMI_CORE_CTRL1_BSEL_24BITBUS, 2, 2);
+       r = FLD_MOD(r, HDMI_CORE_CTRL1_EDGE_RISINGEDGE, 1, 1);
+       hdmi_write_reg(core_sys_base, HDMI_CORE_CTRL1, r);
+
+       REG_FLD_MOD(core_sys_base,
+                       HDMI_CORE_SYS_VID_ACEN, cfg->ip_bus_width, 7, 6);
+
+       /* Vid_Mode */
+       r = hdmi_read_reg(core_sys_base, HDMI_CORE_SYS_VID_MODE);
+
+       /* dither truncation configuration */
+       if (cfg->op_dither_truc > HDMI_OUTPUTTRUNCATION_12BIT) {
+               r = FLD_MOD(r, cfg->op_dither_truc - 3, 7, 6);
+               r = FLD_MOD(r, 1, 5, 5);
+       } else {
+               r = FLD_MOD(r, cfg->op_dither_truc, 7, 6);
+               r = FLD_MOD(r, 0, 5, 5);
+       }
+       hdmi_write_reg(core_sys_base, HDMI_CORE_SYS_VID_MODE, r);
+
+       /* HDMI_Ctrl */
+       r = hdmi_read_reg(hdmi_av_base(ip_data), HDMI_CORE_AV_HDMI_CTRL);
+       r = FLD_MOD(r, cfg->deep_color_pkt, 6, 6);
+       r = FLD_MOD(r, cfg->pkt_mode, 5, 3);
+       r = FLD_MOD(r, cfg->hdmi_dvi, 0, 0);
+       hdmi_write_reg(hdmi_av_base(ip_data), HDMI_CORE_AV_HDMI_CTRL, r);
+
+       /* TMDS_CTRL */
+       REG_FLD_MOD(core_sys_base,
+                       HDMI_CORE_SYS_TMDS_CTRL, cfg->tclk_sel_clkmult, 6, 5);
+}
+
+static void hdmi_core_aux_infoframe_avi_config(struct hdmi_ip_data *ip_data,
+               struct hdmi_core_infoframe_avi info_avi)
+{
+       u32 val;
+       char sum = 0, checksum = 0;
+       void __iomem *av_base = hdmi_av_base(ip_data);
+
+       sum += 0x82 + 0x002 + 0x00D;
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_TYPE, 0x082);
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_VERS, 0x002);
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_LEN, 0x00D);
+
+       val = (info_avi.db1_format << 5) |
+               (info_avi.db1_active_info << 4) |
+               (info_avi.db1_bar_info_dv << 2) |
+               (info_avi.db1_scan_info);
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(0), val);
+       sum += val;
+
+       val = (info_avi.db2_colorimetry << 6) |
+               (info_avi.db2_aspect_ratio << 4) |
+               (info_avi.db2_active_fmt_ar);
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(1), val);
+       sum += val;
+
+       val = (info_avi.db3_itc << 7) |
+               (info_avi.db3_ec << 4) |
+               (info_avi.db3_q_range << 2) |
+               (info_avi.db3_nup_scaling);
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(2), val);
+       sum += val;
+
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(3),
+                                       info_avi.db4_videocode);
+       sum += info_avi.db4_videocode;
+
+       val = info_avi.db5_pixel_repeat;
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(4), val);
+       sum += val;
+
+       val = info_avi.db6_7_line_eoftop & 0x00FF;
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(5), val);
+       sum += val;
+
+       val = ((info_avi.db6_7_line_eoftop >> 8) & 0x00FF);
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(6), val);
+       sum += val;
+
+       val = info_avi.db8_9_line_sofbottom & 0x00FF;
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(7), val);
+       sum += val;
+
+       val = ((info_avi.db8_9_line_sofbottom >> 8) & 0x00FF);
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(8), val);
+       sum += val;
+
+       val = info_avi.db10_11_pixel_eofleft & 0x00FF;
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(9), val);
+       sum += val;
+
+       val = ((info_avi.db10_11_pixel_eofleft >> 8) & 0x00FF);
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(10), val);
+       sum += val;
+
+       val = info_avi.db12_13_pixel_sofright & 0x00FF;
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(11), val);
+       sum += val;
+
+       val = ((info_avi.db12_13_pixel_sofright >> 8) & 0x00FF);
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(12), val);
+       sum += val;
+
+       checksum = 0x100 - sum;
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_CHSUM, checksum);
+}
+
+static void hdmi_core_av_packet_config(struct hdmi_ip_data *ip_data,
+               struct hdmi_core_packet_enable_repeat repeat_cfg)
+{
+       /* enable/repeat the infoframe */
+       hdmi_write_reg(hdmi_av_base(ip_data), HDMI_CORE_AV_PB_CTRL1,
+               (repeat_cfg.audio_pkt << 5) |
+               (repeat_cfg.audio_pkt_repeat << 4) |
+               (repeat_cfg.avi_infoframe << 1) |
+               (repeat_cfg.avi_infoframe_repeat));
+
+       /* enable/repeat the packet */
+       hdmi_write_reg(hdmi_av_base(ip_data), HDMI_CORE_AV_PB_CTRL2,
+               (repeat_cfg.gen_cntrl_pkt << 3) |
+               (repeat_cfg.gen_cntrl_pkt_repeat << 2) |
+               (repeat_cfg.generic_pkt << 1) |
+               (repeat_cfg.generic_pkt_repeat));
+}
+
+static void hdmi_wp_init(struct omap_video_timings *timings,
+                       struct hdmi_video_format *video_fmt,
+                       struct hdmi_video_interface *video_int)
+{
+       pr_debug("Enter hdmi_wp_init\n");
+
+       timings->hbp = 0;
+       timings->hfp = 0;
+       timings->hsw = 0;
+       timings->vbp = 0;
+       timings->vfp = 0;
+       timings->vsw = 0;
+
+       video_fmt->packing_mode = HDMI_PACK_10b_RGB_YUV444;
+       video_fmt->y_res = 0;
+       video_fmt->x_res = 0;
+
+       video_int->vsp = 0;
+       video_int->hsp = 0;
+
+       video_int->interlacing = 0;
+       video_int->tm = 0; /* HDMI_TIMING_SLAVE */
+
+}
+
+void ti_hdmi_4xxx_wp_video_start(struct hdmi_ip_data *ip_data, bool start)
+{
+       REG_FLD_MOD(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG, start, 31, 31);
+}
+
+static void hdmi_wp_video_init_format(struct hdmi_video_format *video_fmt,
+       struct omap_video_timings *timings, struct hdmi_config *param)
+{
+       pr_debug("Enter hdmi_wp_video_init_format\n");
+
+       video_fmt->y_res = param->timings.timings.y_res;
+       video_fmt->x_res = param->timings.timings.x_res;
+
+       timings->hbp = param->timings.timings.hbp;
+       timings->hfp = param->timings.timings.hfp;
+       timings->hsw = param->timings.timings.hsw;
+       timings->vbp = param->timings.timings.vbp;
+       timings->vfp = param->timings.timings.vfp;
+       timings->vsw = param->timings.timings.vsw;
+}
+
+static void hdmi_wp_video_config_format(struct hdmi_ip_data *ip_data,
+               struct hdmi_video_format *video_fmt)
+{
+       u32 l = 0;
+
+       REG_FLD_MOD(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG,
+                       video_fmt->packing_mode, 10, 8);
+
+       l |= FLD_VAL(video_fmt->y_res, 31, 16);
+       l |= FLD_VAL(video_fmt->x_res, 15, 0);
+       hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_SIZE, l);
+}
+
+static void hdmi_wp_video_config_interface(struct hdmi_ip_data *ip_data,
+               struct hdmi_video_interface *video_int)
+{
+       u32 r;
+       pr_debug("Enter hdmi_wp_video_config_interface\n");
+
+       r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG);
+       r = FLD_MOD(r, video_int->vsp, 7, 7);
+       r = FLD_MOD(r, video_int->hsp, 6, 6);
+       r = FLD_MOD(r, video_int->interlacing, 3, 3);
+       r = FLD_MOD(r, video_int->tm, 1, 0);
+       hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG, r);
+}
+
+static void hdmi_wp_video_config_timing(struct hdmi_ip_data *ip_data,
+               struct omap_video_timings *timings)
+{
+       u32 timing_h = 0;
+       u32 timing_v = 0;
+
+       pr_debug("Enter hdmi_wp_video_config_timing\n");
+
+       timing_h |= FLD_VAL(timings->hbp, 31, 20);
+       timing_h |= FLD_VAL(timings->hfp, 19, 8);
+       timing_h |= FLD_VAL(timings->hsw, 7, 0);
+       hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_TIMING_H, timing_h);
+
+       timing_v |= FLD_VAL(timings->vbp, 31, 20);
+       timing_v |= FLD_VAL(timings->vfp, 19, 8);
+       timing_v |= FLD_VAL(timings->vsw, 7, 0);
+       hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_TIMING_V, timing_v);
+}
+
+void ti_hdmi_4xxx_basic_configure(struct hdmi_ip_data *ip_data)
+{
+       /* HDMI */
+       struct omap_video_timings video_timing;
+       struct hdmi_video_format video_format;
+       struct hdmi_video_interface video_interface;
+       /* HDMI core */
+       struct hdmi_core_infoframe_avi avi_cfg;
+       struct hdmi_core_video_config v_core_cfg;
+       struct hdmi_core_packet_enable_repeat repeat_cfg;
+       struct hdmi_config *cfg = &ip_data->cfg;
+
+       hdmi_wp_init(&video_timing, &video_format,
+               &video_interface);
+
+       hdmi_core_init(&v_core_cfg,
+               &avi_cfg,
+               &repeat_cfg);
+
+       hdmi_wp_video_init_format(&video_format, &video_timing, cfg);
+
+       hdmi_wp_video_config_timing(ip_data, &video_timing);
+
+       /* video config */
+       video_format.packing_mode = HDMI_PACK_24b_RGB_YUV444_YUV422;
+
+       hdmi_wp_video_config_format(ip_data, &video_format);
+
+       video_interface.vsp = cfg->timings.vsync_pol;
+       video_interface.hsp = cfg->timings.hsync_pol;
+       video_interface.interlacing = cfg->interlace;
+       video_interface.tm = 1 ; /* HDMI_TIMING_MASTER_24BIT */
+
+       hdmi_wp_video_config_interface(ip_data, &video_interface);
+
+       /*
+        * configure core video part
+        * set software reset in the core
+        */
+       hdmi_core_swreset_assert(ip_data);
+
+       /* power down off */
+       hdmi_core_powerdown_disable(ip_data);
+
+       v_core_cfg.pkt_mode = HDMI_PACKETMODE24BITPERPIXEL;
+       v_core_cfg.hdmi_dvi = cfg->cm.mode;
+
+       hdmi_core_video_config(ip_data, &v_core_cfg);
+
+       /* release software reset in the core */
+       hdmi_core_swreset_release(ip_data);
+
+       /*
+        * configure packet
+        * info frame video see doc CEA861-D page 65
+        */
+       avi_cfg.db1_format = HDMI_INFOFRAME_AVI_DB1Y_RGB;
+       avi_cfg.db1_active_info =
+               HDMI_INFOFRAME_AVI_DB1A_ACTIVE_FORMAT_OFF;
+       avi_cfg.db1_bar_info_dv = HDMI_INFOFRAME_AVI_DB1B_NO;
+       avi_cfg.db1_scan_info = HDMI_INFOFRAME_AVI_DB1S_0;
+       avi_cfg.db2_colorimetry = HDMI_INFOFRAME_AVI_DB2C_NO;
+       avi_cfg.db2_aspect_ratio = HDMI_INFOFRAME_AVI_DB2M_NO;
+       avi_cfg.db2_active_fmt_ar = HDMI_INFOFRAME_AVI_DB2R_SAME;
+       avi_cfg.db3_itc = HDMI_INFOFRAME_AVI_DB3ITC_NO;
+       avi_cfg.db3_ec = HDMI_INFOFRAME_AVI_DB3EC_XVYUV601;
+       avi_cfg.db3_q_range = HDMI_INFOFRAME_AVI_DB3Q_DEFAULT;
+       avi_cfg.db3_nup_scaling = HDMI_INFOFRAME_AVI_DB3SC_NO;
+       avi_cfg.db4_videocode = cfg->cm.code;
+       avi_cfg.db5_pixel_repeat = HDMI_INFOFRAME_AVI_DB5PR_NO;
+       avi_cfg.db6_7_line_eoftop = 0;
+       avi_cfg.db8_9_line_sofbottom = 0;
+       avi_cfg.db10_11_pixel_eofleft = 0;
+       avi_cfg.db12_13_pixel_sofright = 0;
+
+       hdmi_core_aux_infoframe_avi_config(ip_data, avi_cfg);
+
+       /* enable/repeat the infoframe */
+       repeat_cfg.avi_infoframe = HDMI_PACKETENABLE;
+       repeat_cfg.avi_infoframe_repeat = HDMI_PACKETREPEATON;
+       /* wakeup */
+       repeat_cfg.audio_pkt = HDMI_PACKETENABLE;
+       repeat_cfg.audio_pkt_repeat = HDMI_PACKETREPEATON;
+       hdmi_core_av_packet_config(ip_data, repeat_cfg);
+}
+
+void ti_hdmi_4xxx_wp_dump(struct hdmi_ip_data *ip_data, struct seq_file *s)
+{
+#define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r,\
+               hdmi_read_reg(hdmi_wp_base(ip_data), r))
+
+       DUMPREG(HDMI_WP_REVISION);
+       DUMPREG(HDMI_WP_SYSCONFIG);
+       DUMPREG(HDMI_WP_IRQSTATUS_RAW);
+       DUMPREG(HDMI_WP_IRQSTATUS);
+       DUMPREG(HDMI_WP_PWR_CTRL);
+       DUMPREG(HDMI_WP_IRQENABLE_SET);
+       DUMPREG(HDMI_WP_VIDEO_CFG);
+       DUMPREG(HDMI_WP_VIDEO_SIZE);
+       DUMPREG(HDMI_WP_VIDEO_TIMING_H);
+       DUMPREG(HDMI_WP_VIDEO_TIMING_V);
+       DUMPREG(HDMI_WP_WP_CLK);
+       DUMPREG(HDMI_WP_AUDIO_CFG);
+       DUMPREG(HDMI_WP_AUDIO_CFG2);
+       DUMPREG(HDMI_WP_AUDIO_CTRL);
+       DUMPREG(HDMI_WP_AUDIO_DATA);
+}
+
+void ti_hdmi_4xxx_pll_dump(struct hdmi_ip_data *ip_data, struct seq_file *s)
+{
+#define DUMPPLL(r) seq_printf(s, "%-35s %08x\n", #r,\
+               hdmi_read_reg(hdmi_pll_base(ip_data), r))
+
+       DUMPPLL(PLLCTRL_PLL_CONTROL);
+       DUMPPLL(PLLCTRL_PLL_STATUS);
+       DUMPPLL(PLLCTRL_PLL_GO);
+       DUMPPLL(PLLCTRL_CFG1);
+       DUMPPLL(PLLCTRL_CFG2);
+       DUMPPLL(PLLCTRL_CFG3);
+       DUMPPLL(PLLCTRL_CFG4);
+}
+
+void ti_hdmi_4xxx_core_dump(struct hdmi_ip_data *ip_data, struct seq_file *s)
+{
+       int i;
+
+#define CORE_REG(i, name) name(i)
+#define DUMPCORE(r) seq_printf(s, "%-35s %08x\n", #r,\
+               hdmi_read_reg(hdmi_pll_base(ip_data), r))
+#define DUMPCOREAV(i, r) seq_printf(s, "%s[%d]%*s %08x\n", #r, i, \
+               (i < 10) ? 32 - strlen(#r) : 31 - strlen(#r), " ", \
+               hdmi_read_reg(hdmi_pll_base(ip_data), CORE_REG(i, r)))
+
+       DUMPCORE(HDMI_CORE_SYS_VND_IDL);
+       DUMPCORE(HDMI_CORE_SYS_DEV_IDL);
+       DUMPCORE(HDMI_CORE_SYS_DEV_IDH);
+       DUMPCORE(HDMI_CORE_SYS_DEV_REV);
+       DUMPCORE(HDMI_CORE_SYS_SRST);
+       DUMPCORE(HDMI_CORE_CTRL1);
+       DUMPCORE(HDMI_CORE_SYS_SYS_STAT);
+       DUMPCORE(HDMI_CORE_SYS_VID_ACEN);
+       DUMPCORE(HDMI_CORE_SYS_VID_MODE);
+       DUMPCORE(HDMI_CORE_SYS_INTR_STATE);
+       DUMPCORE(HDMI_CORE_SYS_INTR1);
+       DUMPCORE(HDMI_CORE_SYS_INTR2);
+       DUMPCORE(HDMI_CORE_SYS_INTR3);
+       DUMPCORE(HDMI_CORE_SYS_INTR4);
+       DUMPCORE(HDMI_CORE_SYS_UMASK1);
+       DUMPCORE(HDMI_CORE_SYS_TMDS_CTRL);
+       DUMPCORE(HDMI_CORE_SYS_DE_DLY);
+       DUMPCORE(HDMI_CORE_SYS_DE_CTRL);
+       DUMPCORE(HDMI_CORE_SYS_DE_TOP);
+       DUMPCORE(HDMI_CORE_SYS_DE_CNTL);
+       DUMPCORE(HDMI_CORE_SYS_DE_CNTH);
+       DUMPCORE(HDMI_CORE_SYS_DE_LINL);
+       DUMPCORE(HDMI_CORE_SYS_DE_LINH_1);
+
+       DUMPCORE(HDMI_CORE_DDC_CMD);
+       DUMPCORE(HDMI_CORE_DDC_STATUS);
+       DUMPCORE(HDMI_CORE_DDC_ADDR);
+       DUMPCORE(HDMI_CORE_DDC_OFFSET);
+       DUMPCORE(HDMI_CORE_DDC_COUNT1);
+       DUMPCORE(HDMI_CORE_DDC_COUNT2);
+       DUMPCORE(HDMI_CORE_DDC_DATA);
+       DUMPCORE(HDMI_CORE_DDC_SEGM);
+
+       DUMPCORE(HDMI_CORE_AV_HDMI_CTRL);
+       DUMPCORE(HDMI_CORE_AV_DPD);
+       DUMPCORE(HDMI_CORE_AV_PB_CTRL1);
+       DUMPCORE(HDMI_CORE_AV_PB_CTRL2);
+       DUMPCORE(HDMI_CORE_AV_AVI_TYPE);
+       DUMPCORE(HDMI_CORE_AV_AVI_VERS);
+       DUMPCORE(HDMI_CORE_AV_AVI_LEN);
+       DUMPCORE(HDMI_CORE_AV_AVI_CHSUM);
+
+       for (i = 0; i < HDMI_CORE_AV_AVI_DBYTE_NELEMS; i++)
+               DUMPCOREAV(i, HDMI_CORE_AV_AVI_DBYTE);
+
+       for (i = 0; i < HDMI_CORE_AV_SPD_DBYTE_NELEMS; i++)
+               DUMPCOREAV(i, HDMI_CORE_AV_SPD_DBYTE);
+
+       for (i = 0; i < HDMI_CORE_AV_AUD_DBYTE_NELEMS; i++)
+               DUMPCOREAV(i, HDMI_CORE_AV_AUD_DBYTE);
+
+       for (i = 0; i < HDMI_CORE_AV_MPEG_DBYTE_NELEMS; i++)
+               DUMPCOREAV(i, HDMI_CORE_AV_MPEG_DBYTE);
+
+       for (i = 0; i < HDMI_CORE_AV_GEN_DBYTE_NELEMS; i++)
+               DUMPCOREAV(i, HDMI_CORE_AV_GEN_DBYTE);
+
+       for (i = 0; i < HDMI_CORE_AV_GEN2_DBYTE_NELEMS; i++)
+               DUMPCOREAV(i, HDMI_CORE_AV_GEN2_DBYTE);
+
+       DUMPCORE(HDMI_CORE_AV_ACR_CTRL);
+       DUMPCORE(HDMI_CORE_AV_FREQ_SVAL);
+       DUMPCORE(HDMI_CORE_AV_N_SVAL1);
+       DUMPCORE(HDMI_CORE_AV_N_SVAL2);
+       DUMPCORE(HDMI_CORE_AV_N_SVAL3);
+       DUMPCORE(HDMI_CORE_AV_CTS_SVAL1);
+       DUMPCORE(HDMI_CORE_AV_CTS_SVAL2);
+       DUMPCORE(HDMI_CORE_AV_CTS_SVAL3);
+       DUMPCORE(HDMI_CORE_AV_CTS_HVAL1);
+       DUMPCORE(HDMI_CORE_AV_CTS_HVAL2);
+       DUMPCORE(HDMI_CORE_AV_CTS_HVAL3);
+       DUMPCORE(HDMI_CORE_AV_AUD_MODE);
+       DUMPCORE(HDMI_CORE_AV_SPDIF_CTRL);
+       DUMPCORE(HDMI_CORE_AV_HW_SPDIF_FS);
+       DUMPCORE(HDMI_CORE_AV_SWAP_I2S);
+       DUMPCORE(HDMI_CORE_AV_SPDIF_ERTH);
+       DUMPCORE(HDMI_CORE_AV_I2S_IN_MAP);
+       DUMPCORE(HDMI_CORE_AV_I2S_IN_CTRL);
+       DUMPCORE(HDMI_CORE_AV_I2S_CHST0);
+       DUMPCORE(HDMI_CORE_AV_I2S_CHST1);
+       DUMPCORE(HDMI_CORE_AV_I2S_CHST2);
+       DUMPCORE(HDMI_CORE_AV_I2S_CHST4);
+       DUMPCORE(HDMI_CORE_AV_I2S_CHST5);
+       DUMPCORE(HDMI_CORE_AV_ASRC);
+       DUMPCORE(HDMI_CORE_AV_I2S_IN_LEN);
+       DUMPCORE(HDMI_CORE_AV_HDMI_CTRL);
+       DUMPCORE(HDMI_CORE_AV_AUDO_TXSTAT);
+       DUMPCORE(HDMI_CORE_AV_AUD_PAR_BUSCLK_1);
+       DUMPCORE(HDMI_CORE_AV_AUD_PAR_BUSCLK_2);
+       DUMPCORE(HDMI_CORE_AV_AUD_PAR_BUSCLK_3);
+       DUMPCORE(HDMI_CORE_AV_TEST_TXCTRL);
+       DUMPCORE(HDMI_CORE_AV_DPD);
+       DUMPCORE(HDMI_CORE_AV_PB_CTRL1);
+       DUMPCORE(HDMI_CORE_AV_PB_CTRL2);
+       DUMPCORE(HDMI_CORE_AV_AVI_TYPE);
+       DUMPCORE(HDMI_CORE_AV_AVI_VERS);
+       DUMPCORE(HDMI_CORE_AV_AVI_LEN);
+       DUMPCORE(HDMI_CORE_AV_AVI_CHSUM);
+       DUMPCORE(HDMI_CORE_AV_SPD_TYPE);
+       DUMPCORE(HDMI_CORE_AV_SPD_VERS);
+       DUMPCORE(HDMI_CORE_AV_SPD_LEN);
+       DUMPCORE(HDMI_CORE_AV_SPD_CHSUM);
+       DUMPCORE(HDMI_CORE_AV_AUDIO_TYPE);
+       DUMPCORE(HDMI_CORE_AV_AUDIO_VERS);
+       DUMPCORE(HDMI_CORE_AV_AUDIO_LEN);
+       DUMPCORE(HDMI_CORE_AV_AUDIO_CHSUM);
+       DUMPCORE(HDMI_CORE_AV_MPEG_TYPE);
+       DUMPCORE(HDMI_CORE_AV_MPEG_VERS);
+       DUMPCORE(HDMI_CORE_AV_MPEG_LEN);
+       DUMPCORE(HDMI_CORE_AV_MPEG_CHSUM);
+       DUMPCORE(HDMI_CORE_AV_CP_BYTE1);
+       DUMPCORE(HDMI_CORE_AV_CEC_ADDR_ID);
+}
+
+void ti_hdmi_4xxx_phy_dump(struct hdmi_ip_data *ip_data, struct seq_file *s)
+{
+#define DUMPPHY(r) seq_printf(s, "%-35s %08x\n", #r,\
+               hdmi_read_reg(hdmi_phy_base(ip_data), r))
+
+       DUMPPHY(HDMI_TXPHY_TX_CTRL);
+       DUMPPHY(HDMI_TXPHY_DIGITAL_CTRL);
+       DUMPPHY(HDMI_TXPHY_POWER_CTRL);
+       DUMPPHY(HDMI_TXPHY_PAD_CFG_CTRL);
+}
+
+#if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
+       defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
+void hdmi_wp_audio_config_format(struct hdmi_ip_data *ip_data,
+                                       struct hdmi_audio_format *aud_fmt)
+{
+       u32 r;
+
+       DSSDBG("Enter hdmi_wp_audio_config_format\n");
+
+       r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG);
+       r = FLD_MOD(r, aud_fmt->stereo_channels, 26, 24);
+       r = FLD_MOD(r, aud_fmt->active_chnnls_msk, 23, 16);
+       r = FLD_MOD(r, aud_fmt->en_sig_blk_strt_end, 5, 5);
+       r = FLD_MOD(r, aud_fmt->type, 4, 4);
+       r = FLD_MOD(r, aud_fmt->justification, 3, 3);
+       r = FLD_MOD(r, aud_fmt->sample_order, 2, 2);
+       r = FLD_MOD(r, aud_fmt->samples_per_word, 1, 1);
+       r = FLD_MOD(r, aud_fmt->sample_size, 0, 0);
+       hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG, r);
+}
+
+void hdmi_wp_audio_config_dma(struct hdmi_ip_data *ip_data,
+                                       struct hdmi_audio_dma *aud_dma)
+{
+       u32 r;
+
+       DSSDBG("Enter hdmi_wp_audio_config_dma\n");
+
+       r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG2);
+       r = FLD_MOD(r, aud_dma->transfer_size, 15, 8);
+       r = FLD_MOD(r, aud_dma->block_size, 7, 0);
+       hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG2, r);
+
+       r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CTRL);
+       r = FLD_MOD(r, aud_dma->mode, 9, 9);
+       r = FLD_MOD(r, aud_dma->fifo_threshold, 8, 0);
+       hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CTRL, r);
+}
+
+void hdmi_core_audio_config(struct hdmi_ip_data *ip_data,
+                                       struct hdmi_core_audio_config *cfg)
+{
+       u32 r;
+       void __iomem *av_base = hdmi_av_base(ip_data);
+
+       /* audio clock recovery parameters */
+       r = hdmi_read_reg(av_base, HDMI_CORE_AV_ACR_CTRL);
+       r = FLD_MOD(r, cfg->use_mclk, 2, 2);
+       r = FLD_MOD(r, cfg->en_acr_pkt, 1, 1);
+       r = FLD_MOD(r, cfg->cts_mode, 0, 0);
+       hdmi_write_reg(av_base, HDMI_CORE_AV_ACR_CTRL, r);
+
+       REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL1, cfg->n, 7, 0);
+       REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL2, cfg->n >> 8, 7, 0);
+       REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL3, cfg->n >> 16, 7, 0);
+
+       if (cfg->cts_mode == HDMI_AUDIO_CTS_MODE_SW) {
+               REG_FLD_MOD(av_base, HDMI_CORE_AV_CTS_SVAL1, cfg->cts, 7, 0);
+               REG_FLD_MOD(av_base,
+                               HDMI_CORE_AV_CTS_SVAL2, cfg->cts >> 8, 7, 0);
+               REG_FLD_MOD(av_base,
+                               HDMI_CORE_AV_CTS_SVAL3, cfg->cts >> 16, 7, 0);
+       } else {
+               /*
+                * HDMI IP uses this configuration to divide the MCLK to
+                * update CTS value.
+                */
+               REG_FLD_MOD(av_base,
+                               HDMI_CORE_AV_FREQ_SVAL, cfg->mclk_mode, 2, 0);
+
+               /* Configure clock for audio packets */
+               REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_1,
+                               cfg->aud_par_busclk, 7, 0);
+               REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_2,
+                               (cfg->aud_par_busclk >> 8), 7, 0);
+               REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_3,
+                               (cfg->aud_par_busclk >> 16), 7, 0);
+       }
+
+       /* Override of SPDIF sample frequency with value in I2S_CHST4 */
+       REG_FLD_MOD(av_base, HDMI_CORE_AV_SPDIF_CTRL,
+                                               cfg->fs_override, 1, 1);
+
+       /* I2S parameters */
+       REG_FLD_MOD(av_base, HDMI_CORE_AV_I2S_CHST4,
+                                               cfg->freq_sample, 3, 0);
+
+       r = hdmi_read_reg(av_base, HDMI_CORE_AV_I2S_IN_CTRL);
+       r = FLD_MOD(r, cfg->i2s_cfg.en_high_bitrate_aud, 7, 7);
+       r = FLD_MOD(r, cfg->i2s_cfg.sck_edge_mode, 6, 6);
+       r = FLD_MOD(r, cfg->i2s_cfg.cbit_order, 5, 5);
+       r = FLD_MOD(r, cfg->i2s_cfg.vbit, 4, 4);
+       r = FLD_MOD(r, cfg->i2s_cfg.ws_polarity, 3, 3);
+       r = FLD_MOD(r, cfg->i2s_cfg.justification, 2, 2);
+       r = FLD_MOD(r, cfg->i2s_cfg.direction, 1, 1);
+       r = FLD_MOD(r, cfg->i2s_cfg.shift, 0, 0);
+       hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_IN_CTRL, r);
+
+       r = hdmi_read_reg(av_base, HDMI_CORE_AV_I2S_CHST5);
+       r = FLD_MOD(r, cfg->freq_sample, 7, 4);
+       r = FLD_MOD(r, cfg->i2s_cfg.word_length, 3, 1);
+       r = FLD_MOD(r, cfg->i2s_cfg.word_max_length, 0, 0);
+       hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_CHST5, r);
+
+       REG_FLD_MOD(av_base, HDMI_CORE_AV_I2S_IN_LEN,
+                       cfg->i2s_cfg.in_length_bits, 3, 0);
+
+       /* Audio channels and mode parameters */
+       REG_FLD_MOD(av_base, HDMI_CORE_AV_HDMI_CTRL, cfg->layout, 2, 1);
+       r = hdmi_read_reg(av_base, HDMI_CORE_AV_AUD_MODE);
+       r = FLD_MOD(r, cfg->i2s_cfg.active_sds, 7, 4);
+       r = FLD_MOD(r, cfg->en_dsd_audio, 3, 3);
+       r = FLD_MOD(r, cfg->en_parallel_aud_input, 2, 2);
+       r = FLD_MOD(r, cfg->en_spdif, 1, 1);
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_MODE, r);
+}
+
+void hdmi_core_audio_infoframe_config(struct hdmi_ip_data *ip_data,
+               struct hdmi_core_infoframe_audio *info_aud)
+{
+       u8 val;
+       u8 sum = 0, checksum = 0;
+       void __iomem *av_base = hdmi_av_base(ip_data);
+
+       /*
+        * Set audio info frame type, version and length as
+        * described in HDMI 1.4a Section 8.2.2 specification.
+        * Checksum calculation is defined in Section 5.3.5.
+        */
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_TYPE, 0x84);
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_VERS, 0x01);
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_LEN, 0x0a);
+       sum += 0x84 + 0x001 + 0x00a;
+
+       val = (info_aud->db1_coding_type << 4)
+                       | (info_aud->db1_channel_count - 1);
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(0), val);
+       sum += val;
+
+       val = (info_aud->db2_sample_freq << 2) | info_aud->db2_sample_size;
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(1), val);
+       sum += val;
+
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(2), 0x00);
+
+       val = info_aud->db4_channel_alloc;
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(3), val);
+       sum += val;
+
+       val = (info_aud->db5_downmix_inh << 7) | (info_aud->db5_lsv << 3);
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(4), val);
+       sum += val;
+
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(5), 0x00);
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(6), 0x00);
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(7), 0x00);
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(8), 0x00);
+       hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(9), 0x00);
+
+       checksum = 0x100 - sum;
+       hdmi_write_reg(av_base,
+                                       HDMI_CORE_AV_AUDIO_CHSUM, checksum);
+
+       /*
+        * TODO: Add MPEG and SPD enable and repeat cfg when EDID parsing
+        * is available.
+        */
+}
+
+int hdmi_config_audio_acr(struct hdmi_ip_data *ip_data,
+                               u32 sample_freq, u32 *n, u32 *cts)
+{
+       u32 r;
+       u32 deep_color = 0;
+       u32 pclk = ip_data->cfg.timings.timings.pixel_clock;
+
+       if (n == NULL || cts == NULL)
+               return -EINVAL;
+       /*
+        * Obtain current deep color configuration. This needed
+        * to calculate the TMDS clock based on the pixel clock.
+        */
+       r = REG_GET(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG, 1, 0);
+       switch (r) {
+       case 1: /* No deep color selected */
+               deep_color = 100;
+               break;
+       case 2: /* 10-bit deep color selected */
+               deep_color = 125;
+               break;
+       case 3: /* 12-bit deep color selected */
+               deep_color = 150;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       switch (sample_freq) {
+       case 32000:
+               if ((deep_color == 125) && ((pclk == 54054)
+                               || (pclk == 74250)))
+                       *n = 8192;
+               else
+                       *n = 4096;
+               break;
+       case 44100:
+               *n = 6272;
+               break;
+       case 48000:
+               if ((deep_color == 125) && ((pclk == 54054)
+                               || (pclk == 74250)))
+                       *n = 8192;
+               else
+                       *n = 6144;
+               break;
+       default:
+               *n = 0;
+               return -EINVAL;
+       }
+
+       /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */
+       *cts = pclk * (*n / 128) * deep_color / (sample_freq / 10);
+
+       return 0;
+}
+
+int hdmi_audio_trigger(struct hdmi_ip_data *ip_data,
+                               struct snd_pcm_substream *substream, int cmd,
+                               struct snd_soc_dai *dai)
+{
+       int err = 0;
+       switch (cmd) {
+       case SNDRV_PCM_TRIGGER_START:
+       case SNDRV_PCM_TRIGGER_RESUME:
+       case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+               REG_FLD_MOD(hdmi_av_base(ip_data),
+                                       HDMI_CORE_AV_AUD_MODE, 1, 0, 0);
+               REG_FLD_MOD(hdmi_wp_base(ip_data),
+                                       HDMI_WP_AUDIO_CTRL, 1, 31, 31);
+               REG_FLD_MOD(hdmi_wp_base(ip_data),
+                                       HDMI_WP_AUDIO_CTRL, 1, 30, 30);
+               break;
+
+       case SNDRV_PCM_TRIGGER_STOP:
+       case SNDRV_PCM_TRIGGER_SUSPEND:
+       case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+               REG_FLD_MOD(hdmi_av_base(ip_data),
+                                       HDMI_CORE_AV_AUD_MODE, 0, 0, 0);
+               REG_FLD_MOD(hdmi_wp_base(ip_data),
+                                       HDMI_WP_AUDIO_CTRL, 0, 30, 30);
+               REG_FLD_MOD(hdmi_wp_base(ip_data),
+                                       HDMI_WP_AUDIO_CTRL, 0, 31, 31);
+               break;
+       default:
+               err = -EINVAL;
+       }
+       return err;
+}
+#endif
similarity index 54%
rename from drivers/video/omap2/dss/hdmi.h
rename to drivers/video/omap2/dss/ti_hdmi_4xxx_ip.h
index c885f9cb0659154b80b67f9a35e57004066b88f0..204095632d27bd09b0f104994ed7d568f4d47e6a 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * hdmi.h
+ * ti_hdmi_4xxx_ip.h
  *
- * HDMI driver definition for TI OMAP4 processors.
+ * HDMI header definition for DM81xx, DM38xx, TI OMAP4 etc processors.
  *
  * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com/
  *
  * this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef _OMAP4_DSS_HDMI_H_
-#define _OMAP4_DSS_HDMI_H_
+#ifndef _HDMI_TI_4xxx_H_
+#define _HDMI_TI_4xxx_H_
 
 #include <linux/string.h>
 #include <video/omapdss.h>
-
-#define HDMI_WP                0x0
-#define HDMI_CORE_SYS          0x400
-#define HDMI_CORE_AV           0x900
-#define HDMI_PLLCTRL           0x200
-#define HDMI_PHY               0x300
-
-struct hdmi_reg { u16 idx; };
-
-#define HDMI_REG(idx)                  ((const struct hdmi_reg) { idx })
+#include "ti_hdmi.h"
+#if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
+       defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
+#include <sound/soc.h>
+#include <sound/pcm_params.h>
+#endif
 
 /* HDMI Wrapper */
-#define HDMI_WP_REG(idx)                       HDMI_REG(HDMI_WP + idx)
-
-#define HDMI_WP_REVISION                       HDMI_WP_REG(0x0)
-#define HDMI_WP_SYSCONFIG                      HDMI_WP_REG(0x10)
-#define HDMI_WP_IRQSTATUS_RAW                  HDMI_WP_REG(0x24)
-#define HDMI_WP_IRQSTATUS                      HDMI_WP_REG(0x28)
-#define HDMI_WP_PWR_CTRL                       HDMI_WP_REG(0x40)
-#define HDMI_WP_IRQENABLE_SET                  HDMI_WP_REG(0x2C)
-#define HDMI_WP_VIDEO_CFG                      HDMI_WP_REG(0x50)
-#define HDMI_WP_VIDEO_SIZE                     HDMI_WP_REG(0x60)
-#define HDMI_WP_VIDEO_TIMING_H                 HDMI_WP_REG(0x68)
-#define HDMI_WP_VIDEO_TIMING_V                 HDMI_WP_REG(0x6C)
-#define HDMI_WP_WP_CLK                         HDMI_WP_REG(0x70)
-#define HDMI_WP_AUDIO_CFG                      HDMI_WP_REG(0x80)
-#define HDMI_WP_AUDIO_CFG2                     HDMI_WP_REG(0x84)
-#define HDMI_WP_AUDIO_CTRL                     HDMI_WP_REG(0x88)
-#define HDMI_WP_AUDIO_DATA                     HDMI_WP_REG(0x8C)
+
+#define HDMI_WP_REVISION                       0x0
+#define HDMI_WP_SYSCONFIG                      0x10
+#define HDMI_WP_IRQSTATUS_RAW                  0x24
+#define HDMI_WP_IRQSTATUS                      0x28
+#define HDMI_WP_PWR_CTRL                       0x40
+#define HDMI_WP_IRQENABLE_SET                  0x2C
+#define HDMI_WP_VIDEO_CFG                      0x50
+#define HDMI_WP_VIDEO_SIZE                     0x60
+#define HDMI_WP_VIDEO_TIMING_H                 0x68
+#define HDMI_WP_VIDEO_TIMING_V                 0x6C
+#define HDMI_WP_WP_CLK                         0x70
+#define HDMI_WP_AUDIO_CFG                      0x80
+#define HDMI_WP_AUDIO_CFG2                     0x84
+#define HDMI_WP_AUDIO_CTRL                     0x88
+#define HDMI_WP_AUDIO_DATA                     0x8C
 
 /* HDMI IP Core System */
-#define HDMI_CORE_SYS_REG(idx)                 HDMI_REG(HDMI_CORE_SYS + idx)
-
-#define HDMI_CORE_SYS_VND_IDL                  HDMI_CORE_SYS_REG(0x0)
-#define HDMI_CORE_SYS_DEV_IDL                  HDMI_CORE_SYS_REG(0x8)
-#define HDMI_CORE_SYS_DEV_IDH                  HDMI_CORE_SYS_REG(0xC)
-#define HDMI_CORE_SYS_DEV_REV                  HDMI_CORE_SYS_REG(0x10)
-#define HDMI_CORE_SYS_SRST                     HDMI_CORE_SYS_REG(0x14)
-#define HDMI_CORE_CTRL1                        HDMI_CORE_SYS_REG(0x20)
-#define HDMI_CORE_SYS_SYS_STAT                 HDMI_CORE_SYS_REG(0x24)
-#define HDMI_CORE_SYS_VID_ACEN                 HDMI_CORE_SYS_REG(0x124)
-#define HDMI_CORE_SYS_VID_MODE                 HDMI_CORE_SYS_REG(0x128)
-#define HDMI_CORE_SYS_INTR_STATE               HDMI_CORE_SYS_REG(0x1C0)
-#define HDMI_CORE_SYS_INTR1                    HDMI_CORE_SYS_REG(0x1C4)
-#define HDMI_CORE_SYS_INTR2                    HDMI_CORE_SYS_REG(0x1C8)
-#define HDMI_CORE_SYS_INTR3                    HDMI_CORE_SYS_REG(0x1CC)
-#define HDMI_CORE_SYS_INTR4                    HDMI_CORE_SYS_REG(0x1D0)
-#define HDMI_CORE_SYS_UMASK1                   HDMI_CORE_SYS_REG(0x1D4)
-#define HDMI_CORE_SYS_TMDS_CTRL                HDMI_CORE_SYS_REG(0x208)
-#define HDMI_CORE_SYS_DE_DLY                   HDMI_CORE_SYS_REG(0xC8)
-#define HDMI_CORE_SYS_DE_CTRL                  HDMI_CORE_SYS_REG(0xCC)
-#define HDMI_CORE_SYS_DE_TOP                   HDMI_CORE_SYS_REG(0xD0)
-#define HDMI_CORE_SYS_DE_CNTL                  HDMI_CORE_SYS_REG(0xD8)
-#define HDMI_CORE_SYS_DE_CNTH                  HDMI_CORE_SYS_REG(0xDC)
-#define HDMI_CORE_SYS_DE_LINL                  HDMI_CORE_SYS_REG(0xE0)
-#define HDMI_CORE_SYS_DE_LINH_1                HDMI_CORE_SYS_REG(0xE4)
+
+#define HDMI_CORE_SYS_VND_IDL                  0x0
+#define HDMI_CORE_SYS_DEV_IDL                  0x8
+#define HDMI_CORE_SYS_DEV_IDH                  0xC
+#define HDMI_CORE_SYS_DEV_REV                  0x10
+#define HDMI_CORE_SYS_SRST                     0x14
+#define HDMI_CORE_CTRL1                                0x20
+#define HDMI_CORE_SYS_SYS_STAT                 0x24
+#define HDMI_CORE_SYS_VID_ACEN                 0x124
+#define HDMI_CORE_SYS_VID_MODE                 0x128
+#define HDMI_CORE_SYS_INTR_STATE               0x1C0
+#define HDMI_CORE_SYS_INTR1                    0x1C4
+#define HDMI_CORE_SYS_INTR2                    0x1C8
+#define HDMI_CORE_SYS_INTR3                    0x1CC
+#define HDMI_CORE_SYS_INTR4                    0x1D0
+#define HDMI_CORE_SYS_UMASK1                   0x1D4
+#define HDMI_CORE_SYS_TMDS_CTRL                        0x208
+#define HDMI_CORE_SYS_DE_DLY                   0xC8
+#define HDMI_CORE_SYS_DE_CTRL                  0xCC
+#define HDMI_CORE_SYS_DE_TOP                   0xD0
+#define HDMI_CORE_SYS_DE_CNTL                  0xD8
+#define HDMI_CORE_SYS_DE_CNTH                  0xDC
+#define HDMI_CORE_SYS_DE_LINL                  0xE0
+#define HDMI_CORE_SYS_DE_LINH_1                        0xE4
 #define HDMI_CORE_CTRL1_VEN_FOLLOWVSYNC        0x1
 #define HDMI_CORE_CTRL1_HEN_FOLLOWHSYNC        0x1
 #define HDMI_CORE_CTRL1_BSEL_24BITBUS          0x1
 #define HDMI_CORE_CTRL1_EDGE_RISINGEDGE        0x1
 
 /* HDMI DDC E-DID */
-#define HDMI_CORE_DDC_CMD                      HDMI_CORE_SYS_REG(0x3CC)
-#define HDMI_CORE_DDC_STATUS                   HDMI_CORE_SYS_REG(0x3C8)
-#define HDMI_CORE_DDC_ADDR                     HDMI_CORE_SYS_REG(0x3B4)
-#define HDMI_CORE_DDC_OFFSET                   HDMI_CORE_SYS_REG(0x3BC)
-#define HDMI_CORE_DDC_COUNT1                   HDMI_CORE_SYS_REG(0x3C0)
-#define HDMI_CORE_DDC_COUNT2                   HDMI_CORE_SYS_REG(0x3C4)
-#define HDMI_CORE_DDC_DATA                     HDMI_CORE_SYS_REG(0x3D0)
-#define HDMI_CORE_DDC_SEGM                     HDMI_CORE_SYS_REG(0x3B8)
+#define HDMI_CORE_DDC_CMD                      0x3CC
+#define HDMI_CORE_DDC_STATUS                   0x3C8
+#define HDMI_CORE_DDC_ADDR                     0x3B4
+#define HDMI_CORE_DDC_OFFSET                   0x3BC
+#define HDMI_CORE_DDC_COUNT1                   0x3C0
+#define HDMI_CORE_DDC_COUNT2                   0x3C4
+#define HDMI_CORE_DDC_DATA                     0x3D0
+#define HDMI_CORE_DDC_SEGM                     0x3B8
 
 /* HDMI IP Core Audio Video */
-#define HDMI_CORE_AV_REG(idx)                  HDMI_REG(HDMI_CORE_AV + idx)
-
-#define HDMI_CORE_AV_HDMI_CTRL                 HDMI_CORE_AV_REG(0xBC)
-#define HDMI_CORE_AV_DPD                       HDMI_CORE_AV_REG(0xF4)
-#define HDMI_CORE_AV_PB_CTRL1                  HDMI_CORE_AV_REG(0xF8)
-#define HDMI_CORE_AV_PB_CTRL2                  HDMI_CORE_AV_REG(0xFC)
-#define HDMI_CORE_AV_AVI_TYPE                  HDMI_CORE_AV_REG(0x100)
-#define HDMI_CORE_AV_AVI_VERS                  HDMI_CORE_AV_REG(0x104)
-#define HDMI_CORE_AV_AVI_LEN                   HDMI_CORE_AV_REG(0x108)
-#define HDMI_CORE_AV_AVI_CHSUM                 HDMI_CORE_AV_REG(0x10C)
-#define HDMI_CORE_AV_AVI_DBYTE(n)              HDMI_CORE_AV_REG(n * 4 + 0x110)
-#define HDMI_CORE_AV_AVI_DBYTE_NELEMS          HDMI_CORE_AV_REG(15)
-#define HDMI_CORE_AV_SPD_DBYTE                 HDMI_CORE_AV_REG(0x190)
-#define HDMI_CORE_AV_SPD_DBYTE_NELEMS          HDMI_CORE_AV_REG(27)
-#define HDMI_CORE_AV_AUD_DBYTE(n)              HDMI_CORE_AV_REG(n * 4 + 0x210)
-#define HDMI_CORE_AV_AUD_DBYTE_NELEMS          HDMI_CORE_AV_REG(10)
-#define HDMI_CORE_AV_MPEG_DBYTE                HDMI_CORE_AV_REG(0x290)
-#define HDMI_CORE_AV_MPEG_DBYTE_NELEMS         HDMI_CORE_AV_REG(27)
-#define HDMI_CORE_AV_GEN_DBYTE                 HDMI_CORE_AV_REG(0x300)
-#define HDMI_CORE_AV_GEN_DBYTE_NELEMS          HDMI_CORE_AV_REG(31)
-#define HDMI_CORE_AV_GEN2_DBYTE                HDMI_CORE_AV_REG(0x380)
-#define HDMI_CORE_AV_GEN2_DBYTE_NELEMS         HDMI_CORE_AV_REG(31)
-#define HDMI_CORE_AV_ACR_CTRL                  HDMI_CORE_AV_REG(0x4)
-#define HDMI_CORE_AV_FREQ_SVAL                 HDMI_CORE_AV_REG(0x8)
-#define HDMI_CORE_AV_N_SVAL1                   HDMI_CORE_AV_REG(0xC)
-#define HDMI_CORE_AV_N_SVAL2                   HDMI_CORE_AV_REG(0x10)
-#define HDMI_CORE_AV_N_SVAL3                   HDMI_CORE_AV_REG(0x14)
-#define HDMI_CORE_AV_CTS_SVAL1                 HDMI_CORE_AV_REG(0x18)
-#define HDMI_CORE_AV_CTS_SVAL2                 HDMI_CORE_AV_REG(0x1C)
-#define HDMI_CORE_AV_CTS_SVAL3                 HDMI_CORE_AV_REG(0x20)
-#define HDMI_CORE_AV_CTS_HVAL1                 HDMI_CORE_AV_REG(0x24)
-#define HDMI_CORE_AV_CTS_HVAL2                 HDMI_CORE_AV_REG(0x28)
-#define HDMI_CORE_AV_CTS_HVAL3                 HDMI_CORE_AV_REG(0x2C)
-#define HDMI_CORE_AV_AUD_MODE                  HDMI_CORE_AV_REG(0x50)
-#define HDMI_CORE_AV_SPDIF_CTRL                HDMI_CORE_AV_REG(0x54)
-#define HDMI_CORE_AV_HW_SPDIF_FS               HDMI_CORE_AV_REG(0x60)
-#define HDMI_CORE_AV_SWAP_I2S                  HDMI_CORE_AV_REG(0x64)
-#define HDMI_CORE_AV_SPDIF_ERTH                HDMI_CORE_AV_REG(0x6C)
-#define HDMI_CORE_AV_I2S_IN_MAP                HDMI_CORE_AV_REG(0x70)
-#define HDMI_CORE_AV_I2S_IN_CTRL               HDMI_CORE_AV_REG(0x74)
-#define HDMI_CORE_AV_I2S_CHST0                 HDMI_CORE_AV_REG(0x78)
-#define HDMI_CORE_AV_I2S_CHST1                 HDMI_CORE_AV_REG(0x7C)
-#define HDMI_CORE_AV_I2S_CHST2                 HDMI_CORE_AV_REG(0x80)
-#define HDMI_CORE_AV_I2S_CHST4                 HDMI_CORE_AV_REG(0x84)
-#define HDMI_CORE_AV_I2S_CHST5                 HDMI_CORE_AV_REG(0x88)
-#define HDMI_CORE_AV_ASRC                      HDMI_CORE_AV_REG(0x8C)
-#define HDMI_CORE_AV_I2S_IN_LEN                HDMI_CORE_AV_REG(0x90)
-#define HDMI_CORE_AV_HDMI_CTRL                 HDMI_CORE_AV_REG(0xBC)
-#define HDMI_CORE_AV_AUDO_TXSTAT               HDMI_CORE_AV_REG(0xC0)
-#define HDMI_CORE_AV_AUD_PAR_BUSCLK_1          HDMI_CORE_AV_REG(0xCC)
-#define HDMI_CORE_AV_AUD_PAR_BUSCLK_2          HDMI_CORE_AV_REG(0xD0)
-#define HDMI_CORE_AV_AUD_PAR_BUSCLK_3          HDMI_CORE_AV_REG(0xD4)
-#define HDMI_CORE_AV_TEST_TXCTRL               HDMI_CORE_AV_REG(0xF0)
-#define HDMI_CORE_AV_DPD                       HDMI_CORE_AV_REG(0xF4)
-#define HDMI_CORE_AV_PB_CTRL1                  HDMI_CORE_AV_REG(0xF8)
-#define HDMI_CORE_AV_PB_CTRL2                  HDMI_CORE_AV_REG(0xFC)
-#define HDMI_CORE_AV_AVI_TYPE                  HDMI_CORE_AV_REG(0x100)
-#define HDMI_CORE_AV_AVI_VERS                  HDMI_CORE_AV_REG(0x104)
-#define HDMI_CORE_AV_AVI_LEN                   HDMI_CORE_AV_REG(0x108)
-#define HDMI_CORE_AV_AVI_CHSUM                 HDMI_CORE_AV_REG(0x10C)
-#define HDMI_CORE_AV_SPD_TYPE                  HDMI_CORE_AV_REG(0x180)
-#define HDMI_CORE_AV_SPD_VERS                  HDMI_CORE_AV_REG(0x184)
-#define HDMI_CORE_AV_SPD_LEN                   HDMI_CORE_AV_REG(0x188)
-#define HDMI_CORE_AV_SPD_CHSUM                 HDMI_CORE_AV_REG(0x18C)
-#define HDMI_CORE_AV_AUDIO_TYPE                HDMI_CORE_AV_REG(0x200)
-#define HDMI_CORE_AV_AUDIO_VERS                HDMI_CORE_AV_REG(0x204)
-#define HDMI_CORE_AV_AUDIO_LEN                 HDMI_CORE_AV_REG(0x208)
-#define HDMI_CORE_AV_AUDIO_CHSUM               HDMI_CORE_AV_REG(0x20C)
-#define HDMI_CORE_AV_MPEG_TYPE                 HDMI_CORE_AV_REG(0x280)
-#define HDMI_CORE_AV_MPEG_VERS                 HDMI_CORE_AV_REG(0x284)
-#define HDMI_CORE_AV_MPEG_LEN                  HDMI_CORE_AV_REG(0x288)
-#define HDMI_CORE_AV_MPEG_CHSUM                HDMI_CORE_AV_REG(0x28C)
-#define HDMI_CORE_AV_CP_BYTE1                  HDMI_CORE_AV_REG(0x37C)
-#define HDMI_CORE_AV_CEC_ADDR_ID               HDMI_CORE_AV_REG(0x3FC)
+
+#define HDMI_CORE_AV_HDMI_CTRL                 0xBC
+#define HDMI_CORE_AV_DPD                       0xF4
+#define HDMI_CORE_AV_PB_CTRL1                  0xF8
+#define HDMI_CORE_AV_PB_CTRL2                  0xFC
+#define HDMI_CORE_AV_AVI_TYPE                  0x100
+#define HDMI_CORE_AV_AVI_VERS                  0x104
+#define HDMI_CORE_AV_AVI_LEN                   0x108
+#define HDMI_CORE_AV_AVI_CHSUM                 0x10C
+#define HDMI_CORE_AV_AVI_DBYTE(n)              (n * 4 + 0x110)
+#define HDMI_CORE_AV_AVI_DBYTE_NELEMS          15
+#define HDMI_CORE_AV_SPD_DBYTE(n)              (n * 4 + 0x190)
+#define HDMI_CORE_AV_SPD_DBYTE_NELEMS          27
+#define HDMI_CORE_AV_AUD_DBYTE(n)              (n * 4 + 0x210)
+#define HDMI_CORE_AV_AUD_DBYTE_NELEMS          10
+#define HDMI_CORE_AV_MPEG_DBYTE(n)             (n * 4 + 0x290)
+#define HDMI_CORE_AV_MPEG_DBYTE_NELEMS         27
+#define HDMI_CORE_AV_GEN_DBYTE(n)              (n * 4 + 0x300)
+#define HDMI_CORE_AV_GEN_DBYTE_NELEMS          31
+#define HDMI_CORE_AV_GEN2_DBYTE(n)             (n * 4 + 0x380)
+#define HDMI_CORE_AV_GEN2_DBYTE_NELEMS         31
+#define HDMI_CORE_AV_ACR_CTRL                  0x4
+#define HDMI_CORE_AV_FREQ_SVAL                 0x8
+#define HDMI_CORE_AV_N_SVAL1                   0xC
+#define HDMI_CORE_AV_N_SVAL2                   0x10
+#define HDMI_CORE_AV_N_SVAL3                   0x14
+#define HDMI_CORE_AV_CTS_SVAL1                 0x18
+#define HDMI_CORE_AV_CTS_SVAL2                 0x1C
+#define HDMI_CORE_AV_CTS_SVAL3                 0x20
+#define HDMI_CORE_AV_CTS_HVAL1                 0x24
+#define HDMI_CORE_AV_CTS_HVAL2                 0x28
+#define HDMI_CORE_AV_CTS_HVAL3                 0x2C
+#define HDMI_CORE_AV_AUD_MODE                  0x50
+#define HDMI_CORE_AV_SPDIF_CTRL                        0x54
+#define HDMI_CORE_AV_HW_SPDIF_FS               0x60
+#define HDMI_CORE_AV_SWAP_I2S                  0x64
+#define HDMI_CORE_AV_SPDIF_ERTH                        0x6C
+#define HDMI_CORE_AV_I2S_IN_MAP                        0x70
+#define HDMI_CORE_AV_I2S_IN_CTRL               0x74
+#define HDMI_CORE_AV_I2S_CHST0                 0x78
+#define HDMI_CORE_AV_I2S_CHST1                 0x7C
+#define HDMI_CORE_AV_I2S_CHST2                 0x80
+#define HDMI_CORE_AV_I2S_CHST4                 0x84
+#define HDMI_CORE_AV_I2S_CHST5                 0x88
+#define HDMI_CORE_AV_ASRC                      0x8C
+#define HDMI_CORE_AV_I2S_IN_LEN                        0x90
+#define HDMI_CORE_AV_HDMI_CTRL                 0xBC
+#define HDMI_CORE_AV_AUDO_TXSTAT               0xC0
+#define HDMI_CORE_AV_AUD_PAR_BUSCLK_1          0xCC
+#define HDMI_CORE_AV_AUD_PAR_BUSCLK_2          0xD0
+#define HDMI_CORE_AV_AUD_PAR_BUSCLK_3          0xD4
+#define HDMI_CORE_AV_TEST_TXCTRL               0xF0
+#define HDMI_CORE_AV_DPD                       0xF4
+#define HDMI_CORE_AV_PB_CTRL1                  0xF8
+#define HDMI_CORE_AV_PB_CTRL2                  0xFC
+#define HDMI_CORE_AV_AVI_TYPE                  0x100
+#define HDMI_CORE_AV_AVI_VERS                  0x104
+#define HDMI_CORE_AV_AVI_LEN                   0x108
+#define HDMI_CORE_AV_AVI_CHSUM                 0x10C
+#define HDMI_CORE_AV_SPD_TYPE                  0x180
+#define HDMI_CORE_AV_SPD_VERS                  0x184
+#define HDMI_CORE_AV_SPD_LEN                   0x188
+#define HDMI_CORE_AV_SPD_CHSUM                 0x18C
+#define HDMI_CORE_AV_AUDIO_TYPE                        0x200
+#define HDMI_CORE_AV_AUDIO_VERS                        0x204
+#define HDMI_CORE_AV_AUDIO_LEN                 0x208
+#define HDMI_CORE_AV_AUDIO_CHSUM               0x20C
+#define HDMI_CORE_AV_MPEG_TYPE                 0x280
+#define HDMI_CORE_AV_MPEG_VERS                 0x284
+#define HDMI_CORE_AV_MPEG_LEN                  0x288
+#define HDMI_CORE_AV_MPEG_CHSUM                        0x28C
+#define HDMI_CORE_AV_CP_BYTE1                  0x37C
+#define HDMI_CORE_AV_CEC_ADDR_ID               0x3FC
 #define HDMI_CORE_AV_SPD_DBYTE_ELSIZE          0x4
 #define HDMI_CORE_AV_GEN2_DBYTE_ELSIZE         0x4
 #define HDMI_CORE_AV_MPEG_DBYTE_ELSIZE         0x4
 #define HDMI_CORE_AV_GEN_DBYTE_ELSIZE          0x4
 
 /* PLL */
-#define HDMI_PLL_REG(idx)                      HDMI_REG(HDMI_PLLCTRL + idx)
 
-#define PLLCTRL_PLL_CONTROL                    HDMI_PLL_REG(0x0)
-#define PLLCTRL_PLL_STATUS                     HDMI_PLL_REG(0x4)
-#define PLLCTRL_PLL_GO                         HDMI_PLL_REG(0x8)
-#define PLLCTRL_CFG1                           HDMI_PLL_REG(0xC)
-#define PLLCTRL_CFG2                           HDMI_PLL_REG(0x10)
-#define PLLCTRL_CFG3                           HDMI_PLL_REG(0x14)
-#define PLLCTRL_CFG4                           HDMI_PLL_REG(0x20)
+#define PLLCTRL_PLL_CONTROL                    0x0
+#define PLLCTRL_PLL_STATUS                     0x4
+#define PLLCTRL_PLL_GO                         0x8
+#define PLLCTRL_CFG1                           0xC
+#define PLLCTRL_CFG2                           0x10
+#define PLLCTRL_CFG3                           0x14
+#define PLLCTRL_CFG4                           0x20
 
 /* HDMI PHY */
-#define HDMI_PHY_REG(idx)                      HDMI_REG(HDMI_PHY + idx)
-
-#define HDMI_TXPHY_TX_CTRL                     HDMI_PHY_REG(0x0)
-#define HDMI_TXPHY_DIGITAL_CTRL                HDMI_PHY_REG(0x4)
-#define HDMI_TXPHY_POWER_CTRL                  HDMI_PHY_REG(0x8)
-#define HDMI_TXPHY_PAD_CFG_CTRL                HDMI_PHY_REG(0xC)
-
-/* HDMI EDID Length  */
-#define HDMI_EDID_MAX_LENGTH                   256
-#define EDID_TIMING_DESCRIPTOR_SIZE            0x12
-#define EDID_DESCRIPTOR_BLOCK0_ADDRESS         0x36
-#define EDID_DESCRIPTOR_BLOCK1_ADDRESS         0x80
-#define EDID_SIZE_BLOCK0_TIMING_DESCRIPTOR     4
-#define EDID_SIZE_BLOCK1_TIMING_DESCRIPTOR     4
 
-#define OMAP_HDMI_TIMINGS_NB                   34
+#define HDMI_TXPHY_TX_CTRL                     0x0
+#define HDMI_TXPHY_DIGITAL_CTRL                        0x4
+#define HDMI_TXPHY_POWER_CTRL                  0x8
+#define HDMI_TXPHY_PAD_CFG_CTRL                        0xC
 
-#define REG_FLD_MOD(idx, val, start, end) \
-       hdmi_write_reg(idx, FLD_MOD(hdmi_read_reg(idx), val, start, end))
-#define REG_GET(idx, start, end) \
-       FLD_GET(hdmi_read_reg(idx), start, end)
-
-/* HDMI timing structure */
-struct hdmi_timings {
-       struct omap_video_timings timings;
-       int vsync_pol;
-       int hsync_pol;
-};
+#define REG_FLD_MOD(base, idx, val, start, end) \
+       hdmi_write_reg(base, idx, FLD_MOD(hdmi_read_reg(base, idx),\
+                                                       val, start, end))
+#define REG_GET(base, idx, start, end) \
+       FLD_GET(hdmi_read_reg(base, idx), start, end)
 
 enum hdmi_phy_pwr {
        HDMI_PHYPWRCMD_OFF = 0,
@@ -221,20 +196,6 @@ enum hdmi_phy_pwr {
        HDMI_PHYPWRCMD_TXON = 2
 };
 
-enum hdmi_pll_pwr {
-       HDMI_PLLPWRCMD_ALLOFF = 0,
-       HDMI_PLLPWRCMD_PLLONLY = 1,
-       HDMI_PLLPWRCMD_BOTHON_ALLCLKS = 2,
-       HDMI_PLLPWRCMD_BOTHON_NOPHYCLK = 3
-};
-
-enum hdmi_clk_refsel {
-       HDMI_REFSEL_PCLK = 0,
-       HDMI_REFSEL_REF1 = 1,
-       HDMI_REFSEL_REF2 = 2,
-       HDMI_REFSEL_SYSCLK = 3
-};
-
 enum hdmi_core_inputbus_width {
        HDMI_INPUT_8BIT = 0,
        HDMI_INPUT_10BIT = 1,
@@ -263,11 +224,6 @@ enum hdmi_core_packet_mode {
        HDMI_PACKETMODE48BITPERPIXEL = 7
 };
 
-enum hdmi_core_hdmi_dvi {
-       HDMI_DVI = 0,
-       HDMI_HDMI = 1
-};
-
 enum hdmi_core_tclkselclkmult {
        HDMI_FPLL05IDCK = 0,
        HDMI_FPLL10IDCK = 1,
@@ -495,40 +451,40 @@ struct hdmi_core_video_config {
  * details about infoframe databytes
  */
 struct hdmi_core_infoframe_avi {
+       /* Y0, Y1 rgb,yCbCr */
        u8      db1_format;
-               /* Y0, Y1 rgb,yCbCr */
+       /* A0  Active information Present */
        u8      db1_active_info;
-               /* A0  Active information Present */
+       /* B0, B1 Bar info data valid */
        u8      db1_bar_info_dv;
-               /* B0, B1 Bar info data valid */
+       /* S0, S1 scan information */
        u8      db1_scan_info;
-               /* S0, S1 scan information */
+       /* C0, C1 colorimetry */
        u8      db2_colorimetry;
-               /* C0, C1 colorimetry */
+       /* M0, M1 Aspect ratio (4:3, 16:9) */
        u8      db2_aspect_ratio;
-               /* M0, M1 Aspect ratio (4:3, 16:9) */
+       /* R0...R3 Active format aspect ratio */
        u8      db2_active_fmt_ar;
-               /* R0...R3 Active format aspect ratio */
+       /* ITC IT content. */
        u8      db3_itc;
-               /* ITC IT content. */
+       /* EC0, EC1, EC2 Extended colorimetry */
        u8      db3_ec;
-               /* EC0, EC1, EC2 Extended colorimetry */
+       /* Q1, Q0 Quantization range */
        u8      db3_q_range;
-               /* Q1, Q0 Quantization range */
+       /* SC1, SC0 Non-uniform picture scaling */
        u8      db3_nup_scaling;
-               /* SC1, SC0 Non-uniform picture scaling */
+       /* VIC0..6 Video format identification */
        u8      db4_videocode;
-               /* VIC0..6 Video format identification */
+       /* PR0..PR3 Pixel repetition factor */
        u8      db5_pixel_repeat;
-               /* PR0..PR3 Pixel repetition factor */
+       /* Line number end of top bar */
        u16     db6_7_line_eoftop;
-               /* Line number end of top bar */
+       /* Line number start of bottom bar */
        u16     db8_9_line_sofbottom;
-               /* Line number start of bottom bar */
+       /* Pixel number end of left bar */
        u16     db10_11_pixel_eofleft;
-               /* Pixel number end of left bar */
+       /* Pixel number start of right bar */
        u16     db12_13_pixel_sofright;
-               /* Pixel number start of right bar */
 };
 /*
  * Refer to section 8.2 in HDMI 1.3 specification for
@@ -568,17 +524,6 @@ struct hdmi_video_interface {
        int     tm;     /* Timing mode */
 };
 
-struct hdmi_cm {
-       int     code;
-       int     mode;
-};
-
-struct hdmi_config {
-       struct hdmi_timings timings;
-       u16     interlace;
-       struct hdmi_cm cm;
-};
-
 struct hdmi_audio_format {
        enum hdmi_stereo_channels               stereo_channels;
        u8                                      active_chnnls_msk;
@@ -628,4 +573,21 @@ struct hdmi_core_audio_config {
        bool                                    en_parallel_aud_input;
        bool                                    en_spdif;
 };
+
+#if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
+       defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
+int hdmi_audio_trigger(struct hdmi_ip_data *ip_data,
+                               struct snd_pcm_substream *substream, int cmd,
+                               struct snd_soc_dai *dai);
+int hdmi_config_audio_acr(struct hdmi_ip_data *ip_data,
+                               u32 sample_freq, u32 *n, u32 *cts);
+void hdmi_core_audio_infoframe_config(struct hdmi_ip_data *ip_data,
+               struct hdmi_core_infoframe_audio *info_aud);
+void hdmi_core_audio_config(struct hdmi_ip_data *ip_data,
+                                       struct hdmi_core_audio_config *cfg);
+void hdmi_wp_audio_config_dma(struct hdmi_ip_data *ip_data,
+                                       struct hdmi_audio_dma *aud_dma);
+void hdmi_wp_audio_config_format(struct hdmi_ip_data *ip_data,
+                                       struct hdmi_audio_format *aud_fmt);
+#endif
 #endif
index 173c66430daded57cbf59013a1e17d08c1423b04..7533458ba4d24effd08aced87cff7c2ff47eb418 100644 (file)
@@ -295,7 +295,6 @@ static struct {
        u32 wss_data;
        struct regulator *vdda_dac_reg;
 
-       struct clk      *tv_clk;
        struct clk      *tv_dac_clk;
 } venc;
 
@@ -464,9 +463,11 @@ static void venc_power_off(struct omap_dss_device *dssdev)
        regulator_disable(venc.vdda_dac_reg);
 }
 
-
-
-
+unsigned long venc_get_pixel_clock(void)
+{
+       /* VENC Pixel Clock in Mhz */
+       return 13500000;
+}
 
 /* driver */
 static int venc_panel_probe(struct omap_dss_device *dssdev)
@@ -732,22 +733,10 @@ static int venc_get_clocks(struct platform_device *pdev)
 {
        struct clk *clk;
 
-       clk = clk_get(&pdev->dev, "fck");
-       if (IS_ERR(clk)) {
-               DSSERR("can't get fck\n");
-               return PTR_ERR(clk);
-       }
-
-       venc.tv_clk = clk;
-
        if (dss_has_feature(FEAT_VENC_REQUIRES_TV_DAC_CLK)) {
-               if (cpu_is_omap34xx() || cpu_is_omap3630())
-                       clk = clk_get(&pdev->dev, "dss_96m_fck");
-               else
-                       clk = clk_get(&pdev->dev, "tv_dac_clk");
+               clk = clk_get(&pdev->dev, "tv_dac_clk");
                if (IS_ERR(clk)) {
                        DSSERR("can't get tv_dac_clk\n");
-                       clk_put(venc.tv_clk);
                        return PTR_ERR(clk);
                }
        } else {
@@ -761,8 +750,6 @@ static int venc_get_clocks(struct platform_device *pdev)
 
 static void venc_put_clocks(void)
 {
-       if (venc.tv_clk)
-               clk_put(venc.tv_clk);
        if (venc.tv_dac_clk)
                clk_put(venc.tv_dac_clk);
 }
@@ -838,7 +825,6 @@ static int venc_runtime_suspend(struct device *dev)
 {
        if (venc.tv_dac_clk)
                clk_disable(venc.tv_dac_clk);
-       clk_disable(venc.tv_clk);
 
        dispc_runtime_put();
        dss_runtime_put();
@@ -858,7 +844,6 @@ static int venc_runtime_resume(struct device *dev)
        if (r < 0)
                goto err_get_dispc;
 
-       clk_enable(venc.tv_clk);
        if (venc.tv_dac_clk)
                clk_enable(venc.tv_dac_clk);
 
index aa33386c81ff25ed3502f0998ffbe59d0463886c..83d3fe7ec9ae14c4a01dd41ee3d451c2b114e846 100644 (file)
@@ -1,5 +1,5 @@
 menuconfig FB_OMAP2
-        tristate "OMAP2+ frame buffer support (EXPERIMENTAL)"
+        tristate "OMAP2+ frame buffer support"
         depends on FB && OMAP2_DSS
 
        select OMAP2_VRAM
index 602b71a92d3c3092db31f7b0fd349ce2e938b796..70aa47de7146fdc881dff6e9060976c005b1cf77 100644 (file)
@@ -808,19 +808,15 @@ static unsigned calc_rotation_offset_vrfb(const struct fb_var_screeninfo *var,
 static void omapfb_calc_addr(const struct omapfb_info *ofbi,
                             const struct fb_var_screeninfo *var,
                             const struct fb_fix_screeninfo *fix,
-                            int rotation, u32 *paddr, void __iomem **vaddr)
+                            int rotation, u32 *paddr)
 {
        u32 data_start_p;
-       void __iomem *data_start_v;
        int offset;
 
-       if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) {
+       if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB)
                data_start_p = omapfb_get_region_rot_paddr(ofbi, rotation);
-               data_start_v = NULL;
-       } else {
+       else
                data_start_p = omapfb_get_region_paddr(ofbi);
-               data_start_v = omapfb_get_region_vaddr(ofbi);
-       }
 
        if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB)
                offset = calc_rotation_offset_vrfb(var, fix, rotation);
@@ -828,16 +824,14 @@ static void omapfb_calc_addr(const struct omapfb_info *ofbi,
                offset = calc_rotation_offset_dma(var, fix, rotation);
 
        data_start_p += offset;
-       data_start_v += offset;
 
        if (offset)
                DBG("offset %d, %d = %d\n",
                    var->xoffset, var->yoffset, offset);
 
-       DBG("paddr %x, vaddr %p\n", data_start_p, data_start_v);
+       DBG("paddr %x\n", data_start_p);
 
        *paddr = data_start_p;
-       *vaddr = data_start_v;
 }
 
 /* setup overlay according to the fb */
@@ -850,7 +844,6 @@ int omapfb_setup_overlay(struct fb_info *fbi, struct omap_overlay *ovl,
        struct fb_fix_screeninfo *fix = &fbi->fix;
        enum omap_color_mode mode = 0;
        u32 data_start_p = 0;
-       void __iomem *data_start_v = NULL;
        struct omap_overlay_info info;
        int xres, yres;
        int screen_width;
@@ -880,8 +873,7 @@ int omapfb_setup_overlay(struct fb_info *fbi, struct omap_overlay *ovl,
        }
 
        if (ofbi->region->size)
-               omapfb_calc_addr(ofbi, var, fix, rotation,
-                                &data_start_p, &data_start_v);
+               omapfb_calc_addr(ofbi, var, fix, rotation, &data_start_p);
 
        r = fb_mode_to_dss_mode(var, &mode);
        if (r) {
@@ -910,7 +902,6 @@ int omapfb_setup_overlay(struct fb_info *fbi, struct omap_overlay *ovl,
                mirror = ofbi->mirror;
 
        info.paddr = data_start_p;
-       info.vaddr = data_start_v;
        info.screen_width = screen_width;
        info.width = xres;
        info.height = yres;
@@ -2276,6 +2267,87 @@ static int omapfb_parse_def_modes(struct omapfb2_device *fbdev)
        return r;
 }
 
+static void fb_videomode_to_omap_timings(struct fb_videomode *m,
+               struct omap_video_timings *t)
+{
+       t->x_res = m->xres;
+       t->y_res = m->yres;
+       t->pixel_clock = PICOS2KHZ(m->pixclock);
+       t->hsw = m->hsync_len;
+       t->hfp = m->right_margin;
+       t->hbp = m->left_margin;
+       t->vsw = m->vsync_len;
+       t->vfp = m->lower_margin;
+       t->vbp = m->upper_margin;
+}
+
+static int omapfb_find_best_mode(struct omap_dss_device *display,
+               struct omap_video_timings *timings)
+{
+       struct fb_monspecs *specs;
+       u8 *edid;
+       int r, i, best_xres, best_idx, len;
+
+       if (!display->driver->read_edid)
+               return -ENODEV;
+
+       len = 0x80 * 2;
+       edid = kmalloc(len, GFP_KERNEL);
+
+       r = display->driver->read_edid(display, edid, len);
+       if (r < 0)
+               goto err1;
+
+       specs = kzalloc(sizeof(*specs), GFP_KERNEL);
+
+       fb_edid_to_monspecs(edid, specs);
+
+       if (edid[126] > 0)
+               fb_edid_add_monspecs(edid + 0x80, specs);
+
+       best_xres = 0;
+       best_idx = -1;
+
+       for (i = 0; i < specs->modedb_len; ++i) {
+               struct fb_videomode *m;
+               struct omap_video_timings t;
+
+               m = &specs->modedb[i];
+
+               if (m->pixclock == 0)
+                       continue;
+
+               /* skip repeated pixel modes */
+               if (m->xres == 2880 || m->xres == 1440)
+                       continue;
+
+               fb_videomode_to_omap_timings(m, &t);
+
+               r = display->driver->check_timings(display, &t);
+               if (r == 0 && best_xres < m->xres) {
+                       best_xres = m->xres;
+                       best_idx = i;
+               }
+       }
+
+       if (best_xres == 0) {
+               r = -ENOENT;
+               goto err2;
+       }
+
+       fb_videomode_to_omap_timings(&specs->modedb[best_idx], timings);
+
+       r = 0;
+
+err2:
+       fb_destroy_modedb(specs->modedb);
+       kfree(specs);
+err1:
+       kfree(edid);
+
+       return r;
+}
+
 static int omapfb_init_display(struct omapfb2_device *fbdev,
                struct omap_dss_device *dssdev)
 {
@@ -2373,8 +2445,10 @@ static int omapfb_probe(struct platform_device *pdev)
                omap_dss_get_device(dssdev);
 
                if (!dssdev->driver) {
-                       dev_err(&pdev->dev, "no driver for display\n");
-                       r = -ENODEV;
+                       dev_warn(&pdev->dev, "no driver for display: %s\n",
+                               dssdev->name);
+                       omap_dss_put_device(dssdev);
+                       continue;
                }
 
                d = &fbdev->displays[fbdev->num_displays++];
@@ -2402,9 +2476,27 @@ static int omapfb_probe(struct platform_device *pdev)
        for (i = 0; i < fbdev->num_managers; i++)
                fbdev->managers[i] = omap_dss_get_overlay_manager(i);
 
+       /* gfx overlay should be the default one. find a display
+        * connected to that, and use it as default display */
+       ovl = omap_dss_get_overlay(0);
+       if (ovl->manager && ovl->manager->device) {
+               def_display = ovl->manager->device;
+       } else {
+               dev_warn(&pdev->dev, "cannot find default display\n");
+               def_display = NULL;
+       }
+
        if (def_mode && strlen(def_mode) > 0) {
                if (omapfb_parse_def_modes(fbdev))
                        dev_warn(&pdev->dev, "cannot parse default modes\n");
+       } else if (def_display && def_display->driver->set_timings &&
+                       def_display->driver->check_timings) {
+               struct omap_video_timings t;
+
+               r = omapfb_find_best_mode(def_display, &t);
+
+               if (r == 0)
+                       def_display->driver->set_timings(def_display, &t);
        }
 
        r = omapfb_create_framebuffers(fbdev);
@@ -2421,16 +2513,6 @@ static int omapfb_probe(struct platform_device *pdev)
 
        DBG("mgr->apply'ed\n");
 
-       /* gfx overlay should be the default one. find a display
-        * connected to that, and use it as default display */
-       ovl = omap_dss_get_overlay(0);
-       if (ovl->manager && ovl->manager->device) {
-               def_display = ovl->manager->device;
-       } else {
-               dev_warn(&pdev->dev, "cannot find default display\n");
-               def_display = NULL;
-       }
-
        if (def_display) {
                r = omapfb_init_display(fbdev, def_display);
                if (r) {
index 153bf1aceebcc3248051e5c29c80fc4548e6bf50..1694d5148f323fad66a03fe45f4054f4f7a4a09e 100644 (file)
@@ -104,16 +104,14 @@ static ssize_t store_mirror(struct device *dev,
 {
        struct fb_info *fbi = dev_get_drvdata(dev);
        struct omapfb_info *ofbi = FB2OFB(fbi);
-       int mirror;
+       bool mirror;
        int r;
        struct fb_var_screeninfo new_var;
 
-       r = kstrtoint(buf, 0, &mirror);
+       r = strtobool(buf, &mirror);
        if (r)
                return r;
 
-       mirror = !!mirror;
-
        if (!lock_fb_info(fbi))
                return -ENODEV;
 
index f27ae16ead2ea1671e782821a1f6836140120ee7..ae3caa6755c2f63adf6144bec61c121854cebbb9 100644 (file)
@@ -490,7 +490,7 @@ static int platinum_var_to_par(struct fb_var_screeninfo *var,
 
 
 /* 
- * Parse user speficied options (`video=platinumfb:')
+ * Parse user specified options (`video=platinumfb:')
  */
 static int __init platinumfb_setup(char *options)
 {
@@ -683,7 +683,7 @@ static struct platform_driver platinum_driver =
                .of_match_table = platinumfb_match,
        },
        .probe          = platinumfb_probe,
-       .remove         = platinumfb_remove,
+       .remove         = __devexit_p(platinumfb_remove),
 };
 
 static int __init platinumfb_init(void)
index 27f93aab6ddc008d3c61e59667993b4004a0a49a..dc7bfa91e57ab1c87bc6b2b0e4d405b050895c9a 100644 (file)
@@ -973,8 +973,8 @@ static int pm2fb_pan_display(struct fb_var_screeninfo *var,
 {
        struct pm2fb_par *p = info->par;
        u32 base;
-       u32 depth = (var->bits_per_pixel + 7) & ~7;
-       u32 xres = (var->xres + 31) & ~31;
+       u32 depth = (info->var.bits_per_pixel + 7) & ~7;
+       u32 xres = (info->var.xres + 31) & ~31;
 
        depth = (depth > 32) ? 32 : depth;
        base = to3264(var->yoffset * xres + var->xoffset, depth, 1);
@@ -1773,7 +1773,7 @@ MODULE_DEVICE_TABLE(pci, pm2fb_id_table);
 
 #ifndef MODULE
 /**
- * Parse user speficied options.
+ * Parse user specified options.
  *
  * This is, comma-separated options following `video=pm2fb:'.
  */
index 6666f45a2f8ce56e03f8ecb962caad73e5b7abdd..6632ee5ecb7e1243d2e6afc177a4a71eb6a5b6ec 100644 (file)
@@ -1147,9 +1147,9 @@ static int pm3fb_pan_display(struct fb_var_screeninfo *var,
                                 struct fb_info *info)
 {
        struct pm3_par *par = info->par;
-       const u32 xres = (var->xres + 31) & ~31;
+       const u32 xres = (info->var.xres + 31) & ~31;
 
-       par->base = pm3fb_shift_bpp(var->bits_per_pixel,
+       par->base = pm3fb_shift_bpp(info->var.bits_per_pixel,
                                        (var->yoffset * xres)
                                        + var->xoffset);
        PM3_WAIT(par, 1);
@@ -1525,7 +1525,7 @@ static int __init pm3fb_setup(char *options)
 {
        char *this_opt;
 
-       /* Parse user speficied options (`video=pm3fb:') */
+       /* Parse user specified options (`video=pm3fb:') */
        if (!options || !*options)
                return 0;
 
index 65560a1a04392a14602533eaa23d5536941b0573..213fbbcf613bdf0467eb97eec7c2c3e5649eb52d 100644 (file)
@@ -1082,7 +1082,7 @@ static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev)
        }
 
        retval = request_irq(ps3fb.irq_no, ps3fb_vsync_interrupt,
-                            IRQF_DISABLED, DEVICE_NAME, &dev->core);
+                            0, DEVICE_NAME, &dev->core);
        if (retval) {
                dev_err(&dev->core, "%s: request_irq failed %d\n", __func__,
                        retval);
index 0283c7021090d05661a3cdf9c0724f986364530f..1ed8b366618df6234b83183f46d3ac18e6641b98 100644 (file)
@@ -31,8 +31,6 @@
  */
 
 #include <linux/module.h>
-#include <linux/version.h>
-
 #include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
 #include <linux/miscdevice.h>
@@ -678,7 +676,7 @@ pxa3xx_gcu_probe(struct platform_device *dev)
        }
 
        ret = request_irq(irq, pxa3xx_gcu_handle_irq,
-                         IRQF_DISABLED, DRV_NAME, priv);
+                         0, DRV_NAME, priv);
        if (ret) {
                dev_err(&dev->dev, "request_irq failed\n");
                ret = -EBUSY;
index 0f4e8c942f9e082e7410de7983ac28f81576c5f3..e89778f4081fcd7257baa8da27275190c1d4cd78 100644 (file)
@@ -2191,7 +2191,7 @@ static int __devinit pxafb_probe(struct platform_device *dev)
                goto failed_free_mem;
        }
 
-       ret = request_irq(irq, pxafb_handle_irq, IRQF_DISABLED, "LCD", fbi);
+       ret = request_irq(irq, pxafb_handle_irq, 0, "LCD", fbi);
        if (ret) {
                dev_err(&dev->dev, "request_irq failed: %d\n", ret);
                ret = -EBUSY;
index 4aecf213c9be46cb1f37ee38d231aabcf9d089d3..0753b1cfcb8bc9eb6df5fa234ac2441b9c48470b 100644 (file)
@@ -81,6 +81,7 @@ struct s3c_fb;
  * @palette: Address of palette memory, or 0 if none.
  * @has_prtcon: Set if has PRTCON register.
  * @has_shadowcon: Set if has SHADOWCON register.
+ * @has_clksel: Set if VIDCON0 register has CLKSEL bit.
  */
 struct s3c_fb_variant {
        unsigned int    is_2443:1;
@@ -98,6 +99,7 @@ struct s3c_fb_variant {
 
        unsigned int    has_prtcon:1;
        unsigned int    has_shadowcon:1;
+       unsigned int    has_clksel:1;
 };
 
 /**
@@ -186,6 +188,7 @@ struct s3c_fb_vsync {
  * @dev: The device that we bound to, for printing, etc.
  * @regs_res: The resource we claimed for the IO registers.
  * @bus_clk: The clk (hclk) feeding our interface and possibly pixclk.
+ * @lcd_clk: The clk (sclk) feeding pixclk.
  * @regs: The mapped hardware registers.
  * @variant: Variant information for this hardware.
  * @enabled: A bitmask of enabled hardware windows.
@@ -200,6 +203,7 @@ struct s3c_fb {
        struct device           *dev;
        struct resource         *regs_res;
        struct clk              *bus_clk;
+       struct clk              *lcd_clk;
        void __iomem            *regs;
        struct s3c_fb_variant    variant;
 
@@ -336,10 +340,15 @@ static int s3c_fb_check_var(struct fb_var_screeninfo *var,
  */
 static int s3c_fb_calc_pixclk(struct s3c_fb *sfb, unsigned int pixclk)
 {
-       unsigned long clk = clk_get_rate(sfb->bus_clk);
+       unsigned long clk;
        unsigned long long tmp;
        unsigned int result;
 
+       if (sfb->variant.has_clksel)
+               clk = clk_get_rate(sfb->bus_clk);
+       else
+               clk = clk_get_rate(sfb->lcd_clk);
+
        tmp = (unsigned long long)clk;
        tmp *= pixclk;
 
@@ -883,7 +892,7 @@ static int s3c_fb_pan_display(struct fb_var_screeninfo *var,
                }
        }
        /* Offset in bytes to the end of the displayed area */
-       end_boff = start_boff + var->yres * info->fix.line_length;
+       end_boff = start_boff + info->var.yres * info->fix.line_length;
 
        /* Temporarily turn off per-vsync update from shadow registers until
         * both start and end addresses are updated to prevent corruption */
@@ -1354,13 +1363,24 @@ static int __devinit s3c_fb_probe(struct platform_device *pdev)
 
        clk_enable(sfb->bus_clk);
 
+       if (!sfb->variant.has_clksel) {
+               sfb->lcd_clk = clk_get(dev, "sclk_fimd");
+               if (IS_ERR(sfb->lcd_clk)) {
+                       dev_err(dev, "failed to get lcd clock\n");
+                       ret = PTR_ERR(sfb->lcd_clk);
+                       goto err_bus_clk;
+               }
+
+               clk_enable(sfb->lcd_clk);
+       }
+
        pm_runtime_enable(sfb->dev);
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        if (!res) {
                dev_err(dev, "failed to find registers\n");
                ret = -ENOENT;
-               goto err_clk;
+               goto err_lcd_clk;
        }
 
        sfb->regs_res = request_mem_region(res->start, resource_size(res),
@@ -1368,7 +1388,7 @@ static int __devinit s3c_fb_probe(struct platform_device *pdev)
        if (!sfb->regs_res) {
                dev_err(dev, "failed to claim register region\n");
                ret = -ENOENT;
-               goto err_clk;
+               goto err_lcd_clk;
        }
 
        sfb->regs = ioremap(res->start, resource_size(res));
@@ -1450,7 +1470,13 @@ err_ioremap:
 err_req_region:
        release_mem_region(sfb->regs_res->start, resource_size(sfb->regs_res));
 
-err_clk:
+err_lcd_clk:
+       if (!sfb->variant.has_clksel) {
+               clk_disable(sfb->lcd_clk);
+               clk_put(sfb->lcd_clk);
+       }
+
+err_bus_clk:
        clk_disable(sfb->bus_clk);
        clk_put(sfb->bus_clk);
 
@@ -1481,6 +1507,11 @@ static int __devexit s3c_fb_remove(struct platform_device *pdev)
 
        iounmap(sfb->regs);
 
+       if (!sfb->variant.has_clksel) {
+               clk_disable(sfb->lcd_clk);
+               clk_put(sfb->lcd_clk);
+       }
+
        clk_disable(sfb->bus_clk);
        clk_put(sfb->bus_clk);
 
@@ -1510,6 +1541,9 @@ static int s3c_fb_suspend(struct device *dev)
                s3c_fb_blank(FB_BLANK_POWERDOWN, win->fbinfo);
        }
 
+       if (!sfb->variant.has_clksel)
+               clk_disable(sfb->lcd_clk);
+
        clk_disable(sfb->bus_clk);
        return 0;
 }
@@ -1524,6 +1558,9 @@ static int s3c_fb_resume(struct device *dev)
 
        clk_enable(sfb->bus_clk);
 
+       if (!sfb->variant.has_clksel)
+               clk_enable(sfb->lcd_clk);
+
        /* setup gpio and output polarity controls */
        pd->setup_gpio();
        writel(pd->vidcon1, sfb->regs + VIDCON1);
@@ -1569,6 +1606,9 @@ static int s3c_fb_runtime_suspend(struct device *dev)
                s3c_fb_blank(FB_BLANK_POWERDOWN, win->fbinfo);
        }
 
+       if (!sfb->variant.has_clksel)
+               clk_disable(sfb->lcd_clk);
+
        clk_disable(sfb->bus_clk);
        return 0;
 }
@@ -1583,6 +1623,9 @@ static int s3c_fb_runtime_resume(struct device *dev)
 
        clk_enable(sfb->bus_clk);
 
+       if (!sfb->variant.has_clksel)
+               clk_enable(sfb->lcd_clk);
+
        /* setup gpio and output polarity controls */
        pd->setup_gpio();
        writel(pd->vidcon1, sfb->regs + VIDCON1);
@@ -1755,6 +1798,7 @@ static struct s3c_fb_driverdata s3c_fb_data_64xx = {
                },
 
                .has_prtcon     = 1,
+               .has_clksel     = 1,
        },
        .win[0] = &s3c_fb_data_64xx_wins[0],
        .win[1] = &s3c_fb_data_64xx_wins[1],
@@ -1785,6 +1829,7 @@ static struct s3c_fb_driverdata s3c_fb_data_s5pc100 = {
                },
 
                .has_prtcon     = 1,
+               .has_clksel     = 1,
        },
        .win[0] = &s3c_fb_data_s5p_wins[0],
        .win[1] = &s3c_fb_data_s5p_wins[1],
@@ -1794,6 +1839,37 @@ static struct s3c_fb_driverdata s3c_fb_data_s5pc100 = {
 };
 
 static struct s3c_fb_driverdata s3c_fb_data_s5pv210 = {
+       .variant = {
+               .nr_windows     = 5,
+               .vidtcon        = VIDTCON0,
+               .wincon         = WINCON(0),
+               .winmap         = WINxMAP(0),
+               .keycon         = WKEYCON,
+               .osd            = VIDOSD_BASE,
+               .osd_stride     = 16,
+               .buf_start      = VIDW_BUF_START(0),
+               .buf_size       = VIDW_BUF_SIZE(0),
+               .buf_end        = VIDW_BUF_END(0),
+
+               .palette = {
+                       [0] = 0x2400,
+                       [1] = 0x2800,
+                       [2] = 0x2c00,
+                       [3] = 0x3000,
+                       [4] = 0x3400,
+               },
+
+               .has_shadowcon  = 1,
+               .has_clksel     = 1,
+       },
+       .win[0] = &s3c_fb_data_s5p_wins[0],
+       .win[1] = &s3c_fb_data_s5p_wins[1],
+       .win[2] = &s3c_fb_data_s5p_wins[2],
+       .win[3] = &s3c_fb_data_s5p_wins[3],
+       .win[4] = &s3c_fb_data_s5p_wins[4],
+};
+
+static struct s3c_fb_driverdata s3c_fb_data_exynos4 = {
        .variant = {
                .nr_windows     = 5,
                .vidtcon        = VIDTCON0,
@@ -1843,6 +1919,7 @@ static struct s3c_fb_driverdata s3c_fb_data_s3c2443 = {
                        [0] = 0x400,
                        [1] = 0x800,
                },
+               .has_clksel     = 1,
        },
        .win[0] = &(struct s3c_fb_win_variant) {
                .palette_sz     = 256,
@@ -1859,6 +1936,30 @@ static struct s3c_fb_driverdata s3c_fb_data_s3c2443 = {
        },
 };
 
+static struct s3c_fb_driverdata s3c_fb_data_s5p64x0 = {
+       .variant = {
+               .nr_windows     = 3,
+               .vidtcon        = VIDTCON0,
+               .wincon         = WINCON(0),
+               .winmap         = WINxMAP(0),
+               .keycon         = WKEYCON,
+               .osd            = VIDOSD_BASE,
+               .osd_stride     = 16,
+               .buf_start      = VIDW_BUF_START(0),
+               .buf_size       = VIDW_BUF_SIZE(0),
+               .buf_end        = VIDW_BUF_END(0),
+
+               .palette = {
+                       [0] = 0x2400,
+                       [1] = 0x2800,
+                       [2] = 0x2c00,
+               },
+       },
+       .win[0] = &s3c_fb_data_s5p_wins[0],
+       .win[1] = &s3c_fb_data_s5p_wins[1],
+       .win[2] = &s3c_fb_data_s5p_wins[2],
+};
+
 static struct platform_device_id s3c_fb_driver_ids[] = {
        {
                .name           = "s3c-fb",
@@ -1869,9 +1970,15 @@ static struct platform_device_id s3c_fb_driver_ids[] = {
        }, {
                .name           = "s5pv210-fb",
                .driver_data    = (unsigned long)&s3c_fb_data_s5pv210,
+       }, {
+               .name           = "exynos4-fb",
+               .driver_data    = (unsigned long)&s3c_fb_data_exynos4,
        }, {
                .name           = "s3c2443-fb",
                .driver_data    = (unsigned long)&s3c_fb_data_s3c2443,
+       }, {
+               .name           = "s5p64x0-fb",
+               .driver_data    = (unsigned long)&s3c_fb_data_s5p64x0,
        },
        {},
 };
index 0aa13761de6ec3168c38569dd2a9ee479689cdfb..ee4c0df217f78bd07403873e28fda2abc3cc9abc 100644 (file)
@@ -767,7 +767,6 @@ static irqreturn_t s3c2410fb_irq(int irq, void *dev_id)
 static int s3c2410fb_cpufreq_transition(struct notifier_block *nb,
                                        unsigned long val, void *data)
 {
-       struct cpufreq_freqs *freqs = data;
        struct s3c2410fb_info *info;
        struct fb_info *fbinfo;
        long delta_f;
@@ -911,7 +910,7 @@ static int __devinit s3c24xxfb_probe(struct platform_device *pdev,
        for (i = 0; i < 256; i++)
                info->palette_buffer[i] = PALETTE_BUFF_CLEAR;
 
-       ret = request_irq(irq, s3c2410fb_irq, IRQF_DISABLED, pdev->name, info);
+       ret = request_irq(irq, s3c2410fb_irq, 0, pdev->name, info);
        if (ret) {
                dev_err(&pdev->dev, "cannot get irq %d - err %d\n", irq, ret);
                ret = -EBUSY;
index 4ca5d0c8fe84a6501ca6ef4f31898c0babac2725..946a949f4c7d44cba635432f92c7591a54b773ab 100644 (file)
@@ -1019,12 +1019,13 @@ static int s3fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
        unsigned int offset;
 
        /* Calculate the offset */
-       if (var->bits_per_pixel == 0) {
-               offset = (var->yoffset / 16) * (var->xres_virtual / 2) + (var->xoffset / 2);
+       if (info->var.bits_per_pixel == 0) {
+               offset = (var->yoffset / 16) * (info->var.xres_virtual / 2)
+                      + (var->xoffset / 2);
                offset = offset >> 2;
        } else {
                offset = (var->yoffset * info->fix.line_length) +
-                        (var->xoffset * var->bits_per_pixel / 8);
+                        (var->xoffset * info->var.bits_per_pixel / 8);
                offset = offset >> 2;
        }
 
@@ -1504,7 +1505,7 @@ static struct pci_driver s3fb_pci_driver = {
        .resume         = s3_pci_resume,
 };
 
-/* Parse user speficied options */
+/* Parse user specified options */
 
 #ifndef MODULE
 static int  __init s3fb_setup(char *options)
index e8b76d65a070f3b46c06517d17af81ece01e5bb0..98d55d0e2da5336dbb58a189c25b6f45569f1789 100644 (file)
@@ -1457,8 +1457,7 @@ static int __devinit sa1100fb_probe(struct platform_device *pdev)
        if (ret)
                goto failed;
 
-       ret = request_irq(irq, sa1100fb_handle_irq, IRQF_DISABLED,
-                         "LCD", fbi);
+       ret = request_irq(irq, sa1100fb_handle_irq, 0, "LCD", fbi);
        if (ret) {
                printk(KERN_ERR "sa1100fb: request_irq failed: %d\n", ret);
                goto failed;
index 4de541ca9c52c14d38cb95762ba86034e71d59fd..beb495044b240e5b2edc3f98656845756279e80c 100644 (file)
@@ -1477,15 +1477,9 @@ static void savagefb_set_par_int(struct savagefb_par  *par, struct savage_reg *r
        vgaHWProtect(par, 0);
 }
 
-static void savagefb_update_start(struct savagefb_par      *par,
-                                 struct fb_var_screeninfo *var)
+static void savagefb_update_start(struct savagefb_par *par, int base)
 {
-       int base;
-
-       base = ((var->yoffset * var->xres_virtual + (var->xoffset & ~1))
-               * ((var->bits_per_pixel+7) / 8)) >> 2;
-
-       /* now program the start address registers */
+       /* program the start address registers */
        vga_out16(0x3d4, (base & 0x00ff00) | 0x0c, par);
        vga_out16(0x3d4, ((base & 0x00ff) << 8) | 0x0d, par);
        vga_out8(0x3d4, 0x69, par);
@@ -1550,8 +1544,12 @@ static int savagefb_pan_display(struct fb_var_screeninfo *var,
                                struct fb_info           *info)
 {
        struct savagefb_par *par = info->par;
+       int base;
+
+       base = (var->yoffset * info->fix.line_length
+            + (var->xoffset & ~1) * ((info->var.bits_per_pixel+7) / 8)) >> 2;
 
-       savagefb_update_start(par, var);
+       savagefb_update_start(par, base);
        return 0;
 }
 
index 7d54e2c612f774c292088507d24bba47e8d4f605..647ba984f00f6b890c0fc7b9960c0ece05c31c9f 100644 (file)
@@ -1111,6 +1111,7 @@ static long sh_hdmi_clk_configure(struct sh_hdmi *hdmi, unsigned long hdmi_rate,
 static void sh_hdmi_edid_work_fn(struct work_struct *work)
 {
        struct sh_hdmi *hdmi = container_of(work, struct sh_hdmi, edid_work.work);
+       struct fb_info *info;
        struct sh_mobile_hdmi_info *pdata = hdmi->dev->platform_data;
        struct sh_mobile_lcdc_chan *ch;
        int ret;
@@ -1123,8 +1124,9 @@ static void sh_hdmi_edid_work_fn(struct work_struct *work)
 
        mutex_lock(&hdmi->mutex);
 
+       info = hdmi->info;
+
        if (hdmi->hp_state == HDMI_HOTPLUG_CONNECTED) {
-               struct fb_info *info = hdmi->info;
                unsigned long parent_rate = 0, hdmi_rate;
 
                ret = sh_hdmi_read_edid(hdmi, &hdmi_rate, &parent_rate);
@@ -1148,42 +1150,45 @@ static void sh_hdmi_edid_work_fn(struct work_struct *work)
 
                ch = info->par;
 
-               console_lock();
+               if (lock_fb_info(info)) {
+                       console_lock();
 
-               /* HDMI plug in */
-               if (!sh_hdmi_must_reconfigure(hdmi) &&
-                   info->state == FBINFO_STATE_RUNNING) {
-                       /*
-                        * First activation with the default monitor - just turn
-                        * on, if we run a resume here, the logo disappears
-                        */
-                       if (lock_fb_info(info)) {
+                       /* HDMI plug in */
+                       if (!sh_hdmi_must_reconfigure(hdmi) &&
+                           info->state == FBINFO_STATE_RUNNING) {
+                               /*
+                                * First activation with the default monitor - just turn
+                                * on, if we run a resume here, the logo disappears
+                                */
                                info->var.width = hdmi->var.width;
                                info->var.height = hdmi->var.height;
                                sh_hdmi_display_on(hdmi, info);
-                               unlock_fb_info(info);
+                       } else {
+                               /* New monitor or have to wake up */
+                               fb_set_suspend(info, 0);
                        }
-               } else {
-                       /* New monitor or have to wake up */
-                       fb_set_suspend(info, 0);
-               }
 
-               console_unlock();
+                       console_unlock();
+                       unlock_fb_info(info);
+               }
        } else {
                ret = 0;
-               if (!hdmi->info)
+               if (!info)
                        goto out;
 
                hdmi->monspec.modedb_len = 0;
                fb_destroy_modedb(hdmi->monspec.modedb);
                hdmi->monspec.modedb = NULL;
 
-               console_lock();
+               if (lock_fb_info(info)) {
+                       console_lock();
 
-               /* HDMI disconnect */
-               fb_set_suspend(hdmi->info, 1);
+                       /* HDMI disconnect */
+                       fb_set_suspend(info, 1);
 
-               console_unlock();
+                       console_unlock();
+                       unlock_fb_info(info);
+               }
        }
 
 out:
index b048417247e8f1e54268871932d68e23cdb3a9dd..3a41c013d031678243df462e5c2d60e87c07db44 100644 (file)
 #include <linux/backlight.h>
 #include <linux/gpio.h>
 #include <video/sh_mobile_lcdc.h>
+#include <video/sh_mobile_meram.h>
 #include <linux/atomic.h>
 
 #include "sh_mobile_lcdcfb.h"
-#include "sh_mobile_meram.h"
 
 #define SIDE_B_OFFSET 0x1000
 #define MIRROR_OFFSET 0x2000
 
-/* shared registers */
-#define _LDDCKR 0x410
-#define _LDDCKSTPR 0x414
-#define _LDINTR 0x468
-#define _LDSR 0x46c
-#define _LDCNT1R 0x470
-#define _LDCNT2R 0x474
-#define _LDRCNTR 0x478
-#define _LDDDSR 0x47c
-#define _LDDWD0R 0x800
-#define _LDDRDR 0x840
-#define _LDDWAR 0x900
-#define _LDDRAR 0x904
-
-/* shared registers and their order for context save/restore */
-static int lcdc_shared_regs[] = {
-       _LDDCKR,
-       _LDDCKSTPR,
-       _LDINTR,
-       _LDDDSR,
-       _LDCNT1R,
-       _LDCNT2R,
-};
-#define NR_SHARED_REGS ARRAY_SIZE(lcdc_shared_regs)
-
 #define MAX_XRES 1920
 #define MAX_YRES 1080
 
@@ -98,22 +73,6 @@ static unsigned long lcdc_offs_sublcd[NR_CH_REGS] = {
        [LDPMR] = 0x63c,
 };
 
-#define START_LCDC     0x00000001
-#define LCDC_RESET     0x00000100
-#define DISPLAY_BEU    0x00000008
-#define LCDC_ENABLE    0x00000001
-#define LDINTR_FE      0x00000400
-#define LDINTR_VSE     0x00000200
-#define LDINTR_VEE     0x00000100
-#define LDINTR_FS      0x00000004
-#define LDINTR_VSS     0x00000002
-#define LDINTR_VES     0x00000001
-#define LDRCNTR_SRS    0x00020000
-#define LDRCNTR_SRC    0x00010000
-#define LDRCNTR_MRS    0x00000002
-#define LDRCNTR_MRC    0x00000001
-#define LDSR_MRS       0x00000100
-
 static const struct fb_videomode default_720p = {
        .name = "HDMI 720p",
        .xres = 1280,
@@ -141,7 +100,6 @@ struct sh_mobile_lcdc_priv {
        unsigned long lddckr;
        struct sh_mobile_lcdc_chan ch[2];
        struct notifier_block notifier;
-       unsigned long saved_shared_regs[NR_SHARED_REGS];
        int started;
        int forced_bpp; /* 2 channel LCDC must share bpp setting */
        struct sh_mobile_meram_info *meram_dev;
@@ -218,33 +176,36 @@ static void lcdc_sys_write_index(void *handle, unsigned long data)
 {
        struct sh_mobile_lcdc_chan *ch = handle;
 
-       lcdc_write(ch->lcdc, _LDDWD0R, data | 0x10000000);
-       lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
-       lcdc_write(ch->lcdc, _LDDWAR, 1 | (lcdc_chan_is_sublcd(ch) ? 2 : 0));
-       lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
+       lcdc_write(ch->lcdc, _LDDWD0R, data | LDDWDxR_WDACT);
+       lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
+       lcdc_write(ch->lcdc, _LDDWAR, LDDWAR_WA |
+                  (lcdc_chan_is_sublcd(ch) ? 2 : 0));
+       lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
 }
 
 static void lcdc_sys_write_data(void *handle, unsigned long data)
 {
        struct sh_mobile_lcdc_chan *ch = handle;
 
-       lcdc_write(ch->lcdc, _LDDWD0R, data | 0x11000000);
-       lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
-       lcdc_write(ch->lcdc, _LDDWAR, 1 | (lcdc_chan_is_sublcd(ch) ? 2 : 0));
-       lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
+       lcdc_write(ch->lcdc, _LDDWD0R, data | LDDWDxR_WDACT | LDDWDxR_RSW);
+       lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
+       lcdc_write(ch->lcdc, _LDDWAR, LDDWAR_WA |
+                  (lcdc_chan_is_sublcd(ch) ? 2 : 0));
+       lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
 }
 
 static unsigned long lcdc_sys_read_data(void *handle)
 {
        struct sh_mobile_lcdc_chan *ch = handle;
 
-       lcdc_write(ch->lcdc, _LDDRDR, 0x01000000);
-       lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
-       lcdc_write(ch->lcdc, _LDDRAR, 1 | (lcdc_chan_is_sublcd(ch) ? 2 : 0));
+       lcdc_write(ch->lcdc, _LDDRDR, LDDRDR_RSR);
+       lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
+       lcdc_write(ch->lcdc, _LDDRAR, LDDRAR_RA |
+                  (lcdc_chan_is_sublcd(ch) ? 2 : 0));
        udelay(1);
-       lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
+       lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
 
-       return lcdc_read(ch->lcdc, _LDDRDR) & 0x3ffff;
+       return lcdc_read(ch->lcdc, _LDDRDR) & LDDRDR_DRD_MASK;
 }
 
 struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
@@ -256,18 +217,22 @@ struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
 static void sh_mobile_lcdc_clk_on(struct sh_mobile_lcdc_priv *priv)
 {
        if (atomic_inc_and_test(&priv->hw_usecnt)) {
-               pm_runtime_get_sync(priv->dev);
                if (priv->dot_clk)
                        clk_enable(priv->dot_clk);
+               pm_runtime_get_sync(priv->dev);
+               if (priv->meram_dev && priv->meram_dev->pdev)
+                       pm_runtime_get_sync(&priv->meram_dev->pdev->dev);
        }
 }
 
 static void sh_mobile_lcdc_clk_off(struct sh_mobile_lcdc_priv *priv)
 {
        if (atomic_sub_return(1, &priv->hw_usecnt) == -1) {
+               if (priv->meram_dev && priv->meram_dev->pdev)
+                       pm_runtime_put_sync(&priv->meram_dev->pdev->dev);
+               pm_runtime_put(priv->dev);
                if (priv->dot_clk)
                        clk_disable(priv->dot_clk);
-               pm_runtime_put(priv->dev);
        }
 }
 
@@ -319,13 +284,13 @@ static void sh_mobile_lcdc_deferred_io(struct fb_info *info,
                if (bcfg->start_transfer)
                        bcfg->start_transfer(bcfg->board_data, ch,
                                             &sh_mobile_lcdc_sys_bus_ops);
-               lcdc_write_chan(ch, LDSM2R, 1);
+               lcdc_write_chan(ch, LDSM2R, LDSM2R_OSTRG);
                dma_unmap_sg(info->dev, ch->sglist, nr_pages, DMA_TO_DEVICE);
        } else {
                if (bcfg->start_transfer)
                        bcfg->start_transfer(bcfg->board_data, ch,
                                             &sh_mobile_lcdc_sys_bus_ops);
-               lcdc_write_chan(ch, LDSM2R, 1);
+               lcdc_write_chan(ch, LDSM2R, LDSM2R_OSTRG);
        }
 }
 
@@ -341,22 +306,16 @@ static irqreturn_t sh_mobile_lcdc_irq(int irq, void *data)
 {
        struct sh_mobile_lcdc_priv *priv = data;
        struct sh_mobile_lcdc_chan *ch;
-       unsigned long tmp;
        unsigned long ldintr;
        int is_sub;
        int k;
 
-       /* acknowledge interrupt */
-       ldintr = tmp = lcdc_read(priv, _LDINTR);
-       /*
-        * disable further VSYNC End IRQs, preserve all other enabled IRQs,
-        * write 0 to bits 0-6 to ack all triggered IRQs.
-        */
-       tmp &= 0xffffff00 & ~LDINTR_VEE;
-       lcdc_write(priv, _LDINTR, tmp);
+       /* Acknowledge interrupts and disable further VSYNC End IRQs. */
+       ldintr = lcdc_read(priv, _LDINTR);
+       lcdc_write(priv, _LDINTR, (ldintr ^ LDINTR_STATUS_MASK) & ~LDINTR_VEE);
 
        /* figure out if this interrupt is for main or sub lcd */
-       is_sub = (lcdc_read(priv, _LDSR) & (1 << 10)) ? 1 : 0;
+       is_sub = (lcdc_read(priv, _LDSR) & LDSR_MSS) ? 1 : 0;
 
        /* wake up channel and disable clocks */
        for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
@@ -365,7 +324,7 @@ static irqreturn_t sh_mobile_lcdc_irq(int irq, void *data)
                if (!ch->enabled)
                        continue;
 
-               /* Frame Start */
+               /* Frame End */
                if (ldintr & LDINTR_FS) {
                        if (is_sub == lcdc_chan_is_sublcd(ch)) {
                                ch->frame_end = 1;
@@ -391,16 +350,17 @@ static void sh_mobile_lcdc_start_stop(struct sh_mobile_lcdc_priv *priv,
 
        /* start or stop the lcdc */
        if (start)
-               lcdc_write(priv, _LDCNT2R, tmp | START_LCDC);
+               lcdc_write(priv, _LDCNT2R, tmp | LDCNT2R_DO);
        else
-               lcdc_write(priv, _LDCNT2R, tmp & ~START_LCDC);
+               lcdc_write(priv, _LDCNT2R, tmp & ~LDCNT2R_DO);
 
        /* wait until power is applied/stopped on all channels */
        for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
                if (lcdc_read(priv, _LDCNT2R) & priv->ch[k].enabled)
                        while (1) {
-                               tmp = lcdc_read_chan(&priv->ch[k], LDPMR) & 3;
-                               if (start && tmp == 3)
+                               tmp = lcdc_read_chan(&priv->ch[k], LDPMR)
+                                   & LDPMR_LPS;
+                               if (start && tmp == LDPMR_LPS)
                                        break;
                                if (!start && tmp == 0)
                                        break;
@@ -418,13 +378,13 @@ static void sh_mobile_lcdc_geometry(struct sh_mobile_lcdc_chan *ch)
        u32 tmp;
 
        tmp = ch->ldmt1r_value;
-       tmp |= (var->sync & FB_SYNC_VERT_HIGH_ACT) ? 0 : 1 << 28;
-       tmp |= (var->sync & FB_SYNC_HOR_HIGH_ACT) ? 0 : 1 << 27;
-       tmp |= (ch->cfg.flags & LCDC_FLAGS_DWPOL) ? 1 << 26 : 0;
-       tmp |= (ch->cfg.flags & LCDC_FLAGS_DIPOL) ? 1 << 25 : 0;
-       tmp |= (ch->cfg.flags & LCDC_FLAGS_DAPOL) ? 1 << 24 : 0;
-       tmp |= (ch->cfg.flags & LCDC_FLAGS_HSCNT) ? 1 << 17 : 0;
-       tmp |= (ch->cfg.flags & LCDC_FLAGS_DWCNT) ? 1 << 16 : 0;
+       tmp |= (var->sync & FB_SYNC_VERT_HIGH_ACT) ? 0 : LDMT1R_VPOL;
+       tmp |= (var->sync & FB_SYNC_HOR_HIGH_ACT) ? 0 : LDMT1R_HPOL;
+       tmp |= (ch->cfg.flags & LCDC_FLAGS_DWPOL) ? LDMT1R_DWPOL : 0;
+       tmp |= (ch->cfg.flags & LCDC_FLAGS_DIPOL) ? LDMT1R_DIPOL : 0;
+       tmp |= (ch->cfg.flags & LCDC_FLAGS_DAPOL) ? LDMT1R_DAPOL : 0;
+       tmp |= (ch->cfg.flags & LCDC_FLAGS_HSCNT) ? LDMT1R_HSCNT : 0;
+       tmp |= (ch->cfg.flags & LCDC_FLAGS_DWCNT) ? LDMT1R_DWCNT : 0;
        lcdc_write_chan(ch, LDMT1R, tmp);
 
        /* setup SYS bus */
@@ -463,242 +423,239 @@ static void sh_mobile_lcdc_geometry(struct sh_mobile_lcdc_chan *ch)
        lcdc_write_chan(ch, LDHAJR, tmp);
 }
 
-static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv)
+/*
+ * __sh_mobile_lcdc_start - Configure and tart the LCDC
+ * @priv: LCDC device
+ *
+ * Configure all enabled channels and start the LCDC device. All external
+ * devices (clocks, MERAM, panels, ...) are not touched by this function.
+ */
+static void __sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv)
 {
        struct sh_mobile_lcdc_chan *ch;
-       struct sh_mobile_lcdc_board_cfg *board_cfg;
        unsigned long tmp;
        int bpp = 0;
-       unsigned long ldddsr;
-       int k, m, ret;
+       int k, m;
 
-       /* enable clocks before accessing the hardware */
-       for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
-               if (priv->ch[k].enabled) {
-                       sh_mobile_lcdc_clk_on(priv);
-                       if (!bpp)
-                               bpp = priv->ch[k].info->var.bits_per_pixel;
-               }
-       }
-
-       /* reset */
-       lcdc_write(priv, _LDCNT2R, lcdc_read(priv, _LDCNT2R) | LCDC_RESET);
-       lcdc_wait_bit(priv, _LDCNT2R, LCDC_RESET, 0);
-
-       /* enable LCDC channels */
-       tmp = lcdc_read(priv, _LDCNT2R);
-       tmp |= priv->ch[0].enabled;
-       tmp |= priv->ch[1].enabled;
-       lcdc_write(priv, _LDCNT2R, tmp);
-
-       /* read data from external memory, avoid using the BEU for now */
-       lcdc_write(priv, _LDCNT2R, lcdc_read(priv, _LDCNT2R) & ~DISPLAY_BEU);
+       /* Enable LCDC channels. Read data from external memory, avoid using the
+        * BEU for now.
+        */
+       lcdc_write(priv, _LDCNT2R, priv->ch[0].enabled | priv->ch[1].enabled);
 
-       /* stop the lcdc first */
+       /* Stop the LCDC first and disable all interrupts. */
        sh_mobile_lcdc_start_stop(priv, 0);
+       lcdc_write(priv, _LDINTR, 0);
 
-       /* configure clocks */
+       /* Configure power supply, dot clocks and start them. */
        tmp = priv->lddckr;
        for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
                ch = &priv->ch[k];
-
-               if (!priv->ch[k].enabled)
+               if (!ch->enabled)
                        continue;
 
+               if (!bpp)
+                       bpp = ch->info->var.bits_per_pixel;
+
+               /* Power supply */
+               lcdc_write_chan(ch, LDPMR, 0);
+
                m = ch->cfg.clock_divider;
                if (!m)
                        continue;
 
-               if (m == 1)
-                       m = 1 << 6;
-               tmp |= m << (lcdc_chan_is_sublcd(ch) ? 8 : 0);
-
-               /* FIXME: sh7724 can only use 42, 48, 54 and 60 for the divider denominator */
+               /* FIXME: sh7724 can only use 42, 48, 54 and 60 for the divider
+                * denominator.
+                */
                lcdc_write_chan(ch, LDDCKPAT1R, 0);
                lcdc_write_chan(ch, LDDCKPAT2R, (1 << (m/2)) - 1);
+
+               if (m == 1)
+                       m = LDDCKR_MOSEL;
+               tmp |= m << (lcdc_chan_is_sublcd(ch) ? 8 : 0);
        }
 
        lcdc_write(priv, _LDDCKR, tmp);
-
-       /* start dotclock again */
        lcdc_write(priv, _LDDCKSTPR, 0);
        lcdc_wait_bit(priv, _LDDCKSTPR, ~0, 0);
 
-       /* interrupts are disabled to begin with */
-       lcdc_write(priv, _LDINTR, 0);
-
+       /* Setup geometry, format, frame buffer memory and operation mode. */
        for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
                ch = &priv->ch[k];
-
                if (!ch->enabled)
                        continue;
 
                sh_mobile_lcdc_geometry(ch);
 
-               /* power supply */
-               lcdc_write_chan(ch, LDPMR, 0);
-
-               board_cfg = &ch->cfg.board_cfg;
-               if (board_cfg->setup_sys) {
-                       ret = board_cfg->setup_sys(board_cfg->board_data,
-                                               ch, &sh_mobile_lcdc_sys_bus_ops);
-                       if (ret)
-                               return ret;
-               }
-       }
-
-       /* word and long word swap */
-       ldddsr = lcdc_read(priv, _LDDDSR);
-       if  (priv->ch[0].info->var.nonstd)
-               lcdc_write(priv, _LDDDSR, ldddsr | 7);
-       else {
-               switch (bpp) {
-               case 16:
-                       lcdc_write(priv, _LDDDSR, ldddsr | 6);
-                       break;
-               case 24:
-                       lcdc_write(priv, _LDDDSR, ldddsr | 7);
-                       break;
-               case 32:
-                       lcdc_write(priv, _LDDDSR, ldddsr | 4);
-                       break;
-               }
-       }
-
-       for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
-               unsigned long base_addr_y;
-               unsigned long base_addr_c = 0;
-               int pitch;
-               ch = &priv->ch[k];
-
-               if (!priv->ch[k].enabled)
-                       continue;
-
-               /* set bpp format in PKF[4:0] */
-               tmp = lcdc_read_chan(ch, LDDFR);
-               tmp &= ~0x0003031f;
                if (ch->info->var.nonstd) {
-                       tmp |= (ch->info->var.nonstd << 16);
+                       tmp = (ch->info->var.nonstd << 16);
                        switch (ch->info->var.bits_per_pixel) {
                        case 12:
+                               tmp |= LDDFR_YF_420;
                                break;
                        case 16:
-                               tmp |= (0x1 << 8);
+                               tmp |= LDDFR_YF_422;
                                break;
                        case 24:
-                               tmp |= (0x2 << 8);
+                       default:
+                               tmp |= LDDFR_YF_444;
                                break;
                        }
                } else {
                        switch (ch->info->var.bits_per_pixel) {
                        case 16:
-                               tmp |= 0x03;
+                               tmp = LDDFR_PKF_RGB16;
                                break;
                        case 24:
-                               tmp |= 0x0b;
+                               tmp = LDDFR_PKF_RGB24;
                                break;
                        case 32:
+                       default:
+                               tmp = LDDFR_PKF_ARGB32;
                                break;
                        }
                }
+
                lcdc_write_chan(ch, LDDFR, tmp);
+               lcdc_write_chan(ch, LDMLSR, ch->pitch);
+               lcdc_write_chan(ch, LDSA1R, ch->base_addr_y);
+               if (ch->info->var.nonstd)
+                       lcdc_write_chan(ch, LDSA2R, ch->base_addr_c);
 
-               base_addr_y = ch->info->fix.smem_start;
-               base_addr_c = base_addr_y +
-                               ch->info->var.xres *
-                               ch->info->var.yres_virtual;
-               pitch = ch->info->fix.line_length;
+               /* When using deferred I/O mode, configure the LCDC for one-shot
+                * operation and enable the frame end interrupt. Otherwise use
+                * continuous read mode.
+                */
+               if (ch->ldmt1r_value & LDMT1R_IFM &&
+                   ch->cfg.sys_bus_cfg.deferred_io_msec) {
+                       lcdc_write_chan(ch, LDSM1R, LDSM1R_OS);
+                       lcdc_write(priv, _LDINTR, LDINTR_FE);
+               } else {
+                       lcdc_write_chan(ch, LDSM1R, 0);
+               }
+       }
 
-               /* test if we can enable meram */
-               if (ch->cfg.meram_cfg && priv->meram_dev &&
-                               priv->meram_dev->ops) {
-                       struct sh_mobile_meram_cfg *cfg;
-                       struct sh_mobile_meram_info *mdev;
-                       unsigned long icb_addr_y, icb_addr_c;
-                       int icb_pitch;
-                       int pf;
+       /* Word and long word swap. */
+       if  (priv->ch[0].info->var.nonstd)
+               tmp = LDDDSR_LS | LDDDSR_WS | LDDDSR_BS;
+       else {
+               switch (bpp) {
+               case 16:
+                       tmp = LDDDSR_LS | LDDDSR_WS;
+                       break;
+               case 24:
+                       tmp = LDDDSR_LS | LDDDSR_WS | LDDDSR_BS;
+                       break;
+               case 32:
+               default:
+                       tmp = LDDDSR_LS;
+                       break;
+               }
+       }
+       lcdc_write(priv, _LDDDSR, tmp);
 
-                       cfg = ch->cfg.meram_cfg;
-                       mdev = priv->meram_dev;
-                       /* we need to de-init configured ICBs before we
-                        * we can re-initialize them.
-                        */
-                       if (ch->meram_enabled)
-                               mdev->ops->meram_unregister(mdev, cfg);
+       /* Enable the display output. */
+       lcdc_write(priv, _LDCNT1R, LDCNT1R_DE);
+       sh_mobile_lcdc_start_stop(priv, 1);
+       priv->started = 1;
+}
 
-                       ch->meram_enabled = 0;
+static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv)
+{
+       struct sh_mobile_meram_info *mdev = priv->meram_dev;
+       struct sh_mobile_lcdc_board_cfg *board_cfg;
+       struct sh_mobile_lcdc_chan *ch;
+       unsigned long tmp;
+       int ret;
+       int k;
 
-                       if (ch->info->var.nonstd) {
-                               if (ch->info->var.bits_per_pixel == 24)
-                                       pf = SH_MOBILE_MERAM_PF_NV24;
-                               else
-                                       pf = SH_MOBILE_MERAM_PF_NV;
-                       } else {
-                               pf = SH_MOBILE_MERAM_PF_RGB;
-                       }
+       /* enable clocks before accessing the hardware */
+       for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
+               if (priv->ch[k].enabled)
+                       sh_mobile_lcdc_clk_on(priv);
+       }
 
-                       ret = mdev->ops->meram_register(mdev, cfg, pitch,
-                                               ch->info->var.yres,
-                                               pf,
-                                               base_addr_y,
-                                               base_addr_c,
-                                               &icb_addr_y,
-                                               &icb_addr_c,
-                                               &icb_pitch);
-                       if (!ret)  {
-                               /* set LDSA1R value */
-                               base_addr_y = icb_addr_y;
-                               pitch = icb_pitch;
-
-                               /* set LDSA2R value if required */
-                               if (base_addr_c)
-                                       base_addr_c = icb_addr_c;
-
-                               ch->meram_enabled = 1;
-                       }
-               }
+       /* reset */
+       lcdc_write(priv, _LDCNT2R, lcdc_read(priv, _LDCNT2R) | LDCNT2R_BR);
+       lcdc_wait_bit(priv, _LDCNT2R, LDCNT2R_BR, 0);
 
-               /* point out our frame buffer */
-               lcdc_write_chan(ch, LDSA1R, base_addr_y);
-               if (ch->info->var.nonstd)
-                       lcdc_write_chan(ch, LDSA2R, base_addr_c);
+       for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
+               ch = &priv->ch[k];
 
-               /* set line size */
-               lcdc_write_chan(ch, LDMLSR, pitch);
+               if (!ch->enabled)
+                       continue;
 
-               /* setup deferred io if SYS bus */
-               tmp = ch->cfg.sys_bus_cfg.deferred_io_msec;
-               if (ch->ldmt1r_value & (1 << 12) && tmp) {
-                       ch->defio.deferred_io = sh_mobile_lcdc_deferred_io;
-                       ch->defio.delay = msecs_to_jiffies(tmp);
-                       ch->info->fbdefio = &ch->defio;
-                       fb_deferred_io_init(ch->info);
+               board_cfg = &ch->cfg.board_cfg;
+               if (board_cfg->setup_sys) {
+                       ret = board_cfg->setup_sys(board_cfg->board_data, ch,
+                                                  &sh_mobile_lcdc_sys_bus_ops);
+                       if (ret)
+                               return ret;
+               }
+       }
 
-                       /* one-shot mode */
-                       lcdc_write_chan(ch, LDSM1R, 1);
+       /* Compute frame buffer base address and pitch for each channel. */
+       for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
+               struct sh_mobile_meram_cfg *cfg;
+               int pixelformat;
 
-                       /* enable "Frame End Interrupt Enable" bit */
-                       lcdc_write(priv, _LDINTR, LDINTR_FE);
+               ch = &priv->ch[k];
+               if (!ch->enabled)
+                       continue;
 
-               } else {
-                       /* continuous read mode */
-                       lcdc_write_chan(ch, LDSM1R, 0);
+               ch->base_addr_y = ch->info->fix.smem_start;
+               ch->base_addr_c = ch->base_addr_y
+                               + ch->info->var.xres
+                               * ch->info->var.yres_virtual;
+               ch->pitch = ch->info->fix.line_length;
+
+               /* Enable MERAM if possible. */
+               cfg = ch->cfg.meram_cfg;
+               if (mdev == NULL || mdev->ops == NULL || cfg == NULL)
+                       continue;
+
+               /* we need to de-init configured ICBs before we can
+                * re-initialize them.
+                */
+               if (ch->meram_enabled) {
+                       mdev->ops->meram_unregister(mdev, cfg);
+                       ch->meram_enabled = 0;
                }
+
+               if (!ch->info->var.nonstd)
+                       pixelformat = SH_MOBILE_MERAM_PF_RGB;
+               else if (ch->info->var.bits_per_pixel == 24)
+                       pixelformat = SH_MOBILE_MERAM_PF_NV24;
+               else
+                       pixelformat = SH_MOBILE_MERAM_PF_NV;
+
+               ret = mdev->ops->meram_register(mdev, cfg, ch->pitch,
+                                       ch->info->var.yres, pixelformat,
+                                       ch->base_addr_y, ch->base_addr_c,
+                                       &ch->base_addr_y, &ch->base_addr_c,
+                                       &ch->pitch);
+               if (!ret)
+                       ch->meram_enabled = 1;
        }
 
-       /* display output */
-       lcdc_write(priv, _LDCNT1R, LCDC_ENABLE);
+       /* Start the LCDC. */
+       __sh_mobile_lcdc_start(priv);
 
-       /* start the lcdc */
-       sh_mobile_lcdc_start_stop(priv, 1);
-       priv->started = 1;
-
-       /* tell the board code to enable the panel */
+       /* Setup deferred I/O, tell the board code to enable the panels, and
+        * turn backlight on.
+        */
        for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
                ch = &priv->ch[k];
                if (!ch->enabled)
                        continue;
 
+               tmp = ch->cfg.sys_bus_cfg.deferred_io_msec;
+               if (ch->ldmt1r_value & LDMT1R_IFM && tmp) {
+                       ch->defio.deferred_io = sh_mobile_lcdc_deferred_io;
+                       ch->defio.delay = msecs_to_jiffies(tmp);
+                       ch->info->fbdefio = &ch->defio;
+                       fb_deferred_io_init(ch->info);
+               }
+
                board_cfg = &ch->cfg.board_cfg;
                if (board_cfg->display_on && try_module_get(board_cfg->owner)) {
                        board_cfg->display_on(board_cfg->board_data, ch->info);
@@ -776,42 +733,42 @@ static void sh_mobile_lcdc_stop(struct sh_mobile_lcdc_priv *priv)
 
 static int sh_mobile_lcdc_check_interface(struct sh_mobile_lcdc_chan *ch)
 {
-       int ifm, miftyp;
-
-       switch (ch->cfg.interface_type) {
-       case RGB8: ifm = 0; miftyp = 0; break;
-       case RGB9: ifm = 0; miftyp = 4; break;
-       case RGB12A: ifm = 0; miftyp = 5; break;
-       case RGB12B: ifm = 0; miftyp = 6; break;
-       case RGB16: ifm = 0; miftyp = 7; break;
-       case RGB18: ifm = 0; miftyp = 10; break;
-       case RGB24: ifm = 0; miftyp = 11; break;
-       case SYS8A: ifm = 1; miftyp = 0; break;
-       case SYS8B: ifm = 1; miftyp = 1; break;
-       case SYS8C: ifm = 1; miftyp = 2; break;
-       case SYS8D: ifm = 1; miftyp = 3; break;
-       case SYS9: ifm = 1; miftyp = 4; break;
-       case SYS12: ifm = 1; miftyp = 5; break;
-       case SYS16A: ifm = 1; miftyp = 7; break;
-       case SYS16B: ifm = 1; miftyp = 8; break;
-       case SYS16C: ifm = 1; miftyp = 9; break;
-       case SYS18: ifm = 1; miftyp = 10; break;
-       case SYS24: ifm = 1; miftyp = 11; break;
-       default: goto bad;
+       int interface_type = ch->cfg.interface_type;
+
+       switch (interface_type) {
+       case RGB8:
+       case RGB9:
+       case RGB12A:
+       case RGB12B:
+       case RGB16:
+       case RGB18:
+       case RGB24:
+       case SYS8A:
+       case SYS8B:
+       case SYS8C:
+       case SYS8D:
+       case SYS9:
+       case SYS12:
+       case SYS16A:
+       case SYS16B:
+       case SYS16C:
+       case SYS18:
+       case SYS24:
+               break;
+       default:
+               return -EINVAL;
        }
 
        /* SUBLCD only supports SYS interface */
        if (lcdc_chan_is_sublcd(ch)) {
-               if (ifm == 0)
-                       goto bad;
-               else
-                       ifm = 0;
+               if (!(interface_type & LDMT1R_IFM))
+                       return -EINVAL;
+
+               interface_type &= ~LDMT1R_IFM;
        }
 
-       ch->ldmt1r_value = (ifm << 12) | miftyp;
+       ch->ldmt1r_value = interface_type;
        return 0;
- bad:
-       return -EINVAL;
 }
 
 static int sh_mobile_lcdc_setup_clocks(struct platform_device *pdev,
@@ -819,18 +776,24 @@ static int sh_mobile_lcdc_setup_clocks(struct platform_device *pdev,
                                       struct sh_mobile_lcdc_priv *priv)
 {
        char *str;
-       int icksel;
 
        switch (clock_source) {
-       case LCDC_CLK_BUS: str = "bus_clk"; icksel = 0; break;
-       case LCDC_CLK_PERIPHERAL: str = "peripheral_clk"; icksel = 1; break;
-       case LCDC_CLK_EXTERNAL: str = NULL; icksel = 2; break;
+       case LCDC_CLK_BUS:
+               str = "bus_clk";
+               priv->lddckr = LDDCKR_ICKSEL_BUS;
+               break;
+       case LCDC_CLK_PERIPHERAL:
+               str = "peripheral_clk";
+               priv->lddckr = LDDCKR_ICKSEL_MIPI;
+               break;
+       case LCDC_CLK_EXTERNAL:
+               str = NULL;
+               priv->lddckr = LDDCKR_ICKSEL_HDMI;
+               break;
        default:
                return -EINVAL;
        }
 
-       priv->lddckr = icksel << 16;
-
        if (str) {
                priv->dot_clk = clk_get(&pdev->dev, str);
                if (IS_ERR(priv->dot_clk)) {
@@ -914,12 +877,12 @@ static int sh_mobile_fb_pan_display(struct fb_var_screeninfo *var,
        unsigned long base_addr_y, base_addr_c;
        unsigned long c_offset;
 
-       if (!var->nonstd)
-               new_pan_offset = (var->yoffset * info->fix.line_length) +
-                       (var->xoffset * (info->var.bits_per_pixel / 8));
+       if (!info->var.nonstd)
+               new_pan_offset = var->yoffset * info->fix.line_length
+                              + var->xoffset * (info->var.bits_per_pixel / 8);
        else
-               new_pan_offset = (var->yoffset * info->fix.line_length) +
-                       (var->xoffset);
+               new_pan_offset = var->yoffset * info->fix.line_length
+                              + var->xoffset;
 
        if (new_pan_offset == ch->pan_offset)
                return 0;       /* No change, do nothing */
@@ -928,44 +891,40 @@ static int sh_mobile_fb_pan_display(struct fb_var_screeninfo *var,
 
        /* Set the source address for the next refresh */
        base_addr_y = ch->dma_handle + new_pan_offset;
-       if (var->nonstd) {
+       if (info->var.nonstd) {
                /* Set y offset */
-               c_offset = (var->yoffset *
-                       info->fix.line_length *
-                       (info->var.bits_per_pixel - 8)) / 8;
-               base_addr_c = ch->dma_handle + var->xres * var->yres_virtual +
-                       c_offset;
+               c_offset = var->yoffset * info->fix.line_length
+                        * (info->var.bits_per_pixel - 8) / 8;
+               base_addr_c = ch->dma_handle
+                           + info->var.xres * info->var.yres_virtual
+                           + c_offset;
                /* Set x offset */
                if (info->var.bits_per_pixel == 24)
                        base_addr_c += 2 * var->xoffset;
                else
                        base_addr_c += var->xoffset;
-       } else
-               base_addr_c = 0;
+       }
 
-       if (!ch->meram_enabled) {
-               lcdc_write_chan_mirror(ch, LDSA1R, base_addr_y);
-               if (base_addr_c)
-                       lcdc_write_chan_mirror(ch, LDSA2R, base_addr_c);
-       } else {
+       if (ch->meram_enabled) {
                struct sh_mobile_meram_cfg *cfg;
                struct sh_mobile_meram_info *mdev;
-               unsigned long icb_addr_y, icb_addr_c;
                int ret;
 
                cfg = ch->cfg.meram_cfg;
                mdev = priv->meram_dev;
                ret = mdev->ops->meram_update(mdev, cfg,
                                        base_addr_y, base_addr_c,
-                                       &icb_addr_y, &icb_addr_c);
+                                       &base_addr_y, &base_addr_c);
                if (ret)
                        return ret;
+       }
 
-               lcdc_write_chan_mirror(ch, LDSA1R, icb_addr_y);
-               if (icb_addr_c)
-                       lcdc_write_chan_mirror(ch, LDSA2R, icb_addr_c);
+       ch->base_addr_y = base_addr_y;
+       ch->base_addr_c = base_addr_c;
 
-       }
+       lcdc_write_chan_mirror(ch, LDSA1R, base_addr_y);
+       if (info->var.nonstd)
+               lcdc_write_chan_mirror(ch, LDSA2R, base_addr_c);
 
        if (lcdc_chan_is_sublcd(ch))
                lcdc_write(ch->lcdc, _LDRCNTR, ldrcntr ^ LDRCNTR_SRS);
@@ -985,9 +944,11 @@ static int sh_mobile_wait_for_vsync(struct fb_info *info)
        unsigned long ldintr;
        int ret;
 
-       /* Enable VSync End interrupt */
+       /* Enable VSync End interrupt and be careful not to acknowledge any
+        * pending interrupt.
+        */
        ldintr = lcdc_read(ch->lcdc, _LDINTR);
-       ldintr |= LDINTR_VEE;
+       ldintr |= LDINTR_VEE | LDINTR_STATUS_MASK;
        lcdc_write(ch->lcdc, _LDINTR, ldintr);
 
        ret = wait_for_completion_interruptible_timeout(&ch->vsync_completion,
@@ -1037,11 +998,6 @@ static void sh_mobile_fb_reconfig(struct fb_info *info)
                /* Couldn't reconfigure, hopefully, can continue as before */
                return;
 
-       if (info->var.nonstd)
-               info->fix.line_length = mode1.xres;
-       else
-               info->fix.line_length = mode1.xres * (ch->cfg.bpp / 8);
-
        /*
         * fb_set_var() calls the notifier change internally, only if
         * FBINFO_MISC_USEREVENT flag is set. Since we do not want to fake a
@@ -1094,30 +1050,126 @@ static int sh_mobile_check_var(struct fb_var_screeninfo *var, struct fb_info *in
 {
        struct sh_mobile_lcdc_chan *ch = info->par;
        struct sh_mobile_lcdc_priv *p = ch->lcdc;
+       unsigned int best_dist = (unsigned int)-1;
+       unsigned int best_xres = 0;
+       unsigned int best_yres = 0;
+       unsigned int i;
 
-       if (var->xres > MAX_XRES || var->yres > MAX_YRES ||
-           var->xres * var->yres * (ch->cfg.bpp / 8) * 2 > info->fix.smem_len) {
-               dev_warn(info->dev, "Invalid info: %u-%u-%u-%u x %u-%u-%u-%u @ %lukHz!\n",
-                        var->left_margin, var->xres, var->right_margin, var->hsync_len,
-                        var->upper_margin, var->yres, var->lower_margin, var->vsync_len,
-                        PICOS2KHZ(var->pixclock));
+       if (var->xres > MAX_XRES || var->yres > MAX_YRES)
                return -EINVAL;
+
+       /* If board code provides us with a list of available modes, make sure
+        * we use one of them. Find the mode closest to the requested one. The
+        * distance between two modes is defined as the size of the
+        * non-overlapping parts of the two rectangles.
+        */
+       for (i = 0; i < ch->cfg.num_cfg; ++i) {
+               const struct fb_videomode *mode = &ch->cfg.lcd_cfg[i];
+               unsigned int dist;
+
+               /* We can only round up. */
+               if (var->xres > mode->xres || var->yres > mode->yres)
+                       continue;
+
+               dist = var->xres * var->yres + mode->xres * mode->yres
+                    - 2 * min(var->xres, mode->xres)
+                        * min(var->yres, mode->yres);
+
+               if (dist < best_dist) {
+                       best_xres = mode->xres;
+                       best_yres = mode->yres;
+                       best_dist = dist;
+               }
+       }
+
+       /* If no available mode can be used, return an error. */
+       if (ch->cfg.num_cfg != 0) {
+               if (best_dist == (unsigned int)-1)
+                       return -EINVAL;
+
+               var->xres = best_xres;
+               var->yres = best_yres;
        }
 
+       /* Make sure the virtual resolution is at least as big as the visible
+        * resolution.
+        */
+       if (var->xres_virtual < var->xres)
+               var->xres_virtual = var->xres;
+       if (var->yres_virtual < var->yres)
+               var->yres_virtual = var->yres;
+
+       if (var->bits_per_pixel <= 16) {                /* RGB 565 */
+               var->bits_per_pixel = 16;
+               var->red.offset = 11;
+               var->red.length = 5;
+               var->green.offset = 5;
+               var->green.length = 6;
+               var->blue.offset = 0;
+               var->blue.length = 5;
+               var->transp.offset = 0;
+               var->transp.length = 0;
+       } else if (var->bits_per_pixel <= 24) {         /* RGB 888 */
+               var->bits_per_pixel = 24;
+               var->red.offset = 16;
+               var->red.length = 8;
+               var->green.offset = 8;
+               var->green.length = 8;
+               var->blue.offset = 0;
+               var->blue.length = 8;
+               var->transp.offset = 0;
+               var->transp.length = 0;
+       } else if (var->bits_per_pixel <= 32) {         /* RGBA 888 */
+               var->bits_per_pixel = 32;
+               var->red.offset = 16;
+               var->red.length = 8;
+               var->green.offset = 8;
+               var->green.length = 8;
+               var->blue.offset = 0;
+               var->blue.length = 8;
+               var->transp.offset = 24;
+               var->transp.length = 8;
+       } else
+               return -EINVAL;
+
+       var->red.msb_right = 0;
+       var->green.msb_right = 0;
+       var->blue.msb_right = 0;
+       var->transp.msb_right = 0;
+
+       /* Make sure we don't exceed our allocated memory. */
+       if (var->xres_virtual * var->yres_virtual * var->bits_per_pixel / 8 >
+           info->fix.smem_len)
+               return -EINVAL;
+
        /* only accept the forced_bpp for dual channel configurations */
        if (p->forced_bpp && p->forced_bpp != var->bits_per_pixel)
                return -EINVAL;
 
-       switch (var->bits_per_pixel) {
-       case 16: /* PKF[4:0] = 00011 - RGB 565 */
-       case 24: /* PKF[4:0] = 01011 - RGB 888 */
-       case 32: /* PKF[4:0] = 00000 - RGBA 888 */
-               break;
-       default:
-               return -EINVAL;
+       return 0;
+}
+
+static int sh_mobile_set_par(struct fb_info *info)
+{
+       struct sh_mobile_lcdc_chan *ch = info->par;
+       u32 line_length = info->fix.line_length;
+       int ret;
+
+       sh_mobile_lcdc_stop(ch->lcdc);
+
+       if (info->var.nonstd)
+               info->fix.line_length = info->var.xres;
+       else
+               info->fix.line_length = info->var.xres
+                                     * info->var.bits_per_pixel / 8;
+
+       ret = sh_mobile_lcdc_start(ch->lcdc);
+       if (ret < 0) {
+               dev_err(info->dev, "%s: unable to restart LCDC\n", __func__);
+               info->fix.line_length = line_length;
        }
 
-       return 0;
+       return ret;
 }
 
 /*
@@ -1177,6 +1229,7 @@ static struct fb_ops sh_mobile_lcdc_ops = {
        .fb_open        = sh_mobile_open,
        .fb_release     = sh_mobile_release,
        .fb_check_var   = sh_mobile_check_var,
+       .fb_set_par     = sh_mobile_set_par,
 };
 
 static int sh_mobile_lcdc_update_bl(struct backlight_device *bdev)
@@ -1238,66 +1291,6 @@ static void sh_mobile_lcdc_bl_remove(struct backlight_device *bdev)
        backlight_device_unregister(bdev);
 }
 
-static int sh_mobile_lcdc_set_bpp(struct fb_var_screeninfo *var, int bpp,
-                                  int nonstd)
-{
-       if (nonstd) {
-               switch (bpp) {
-               case 12:
-               case 16:
-               case 24:
-                       var->bits_per_pixel = bpp;
-                       var->nonstd = nonstd;
-                       return 0;
-               default:
-                       return -EINVAL;
-               }
-       }
-
-       switch (bpp) {
-       case 16: /* PKF[4:0] = 00011 - RGB 565 */
-               var->red.offset = 11;
-               var->red.length = 5;
-               var->green.offset = 5;
-               var->green.length = 6;
-               var->blue.offset = 0;
-               var->blue.length = 5;
-               var->transp.offset = 0;
-               var->transp.length = 0;
-               break;
-
-       case 24: /* PKF[4:0] = 01011 - RGB 888 */
-               var->red.offset = 16;
-               var->red.length = 8;
-               var->green.offset = 8;
-               var->green.length = 8;
-               var->blue.offset = 0;
-               var->blue.length = 8;
-               var->transp.offset = 0;
-               var->transp.length = 0;
-               break;
-
-       case 32: /* PKF[4:0] = 00000 - RGBA 888 */
-               var->red.offset = 16;
-               var->red.length = 8;
-               var->green.offset = 8;
-               var->green.length = 8;
-               var->blue.offset = 0;
-               var->blue.length = 8;
-               var->transp.offset = 24;
-               var->transp.length = 8;
-               break;
-       default:
-               return -EINVAL;
-       }
-       var->bits_per_pixel = bpp;
-       var->red.msb_right = 0;
-       var->green.msb_right = 0;
-       var->blue.msb_right = 0;
-       var->transp.msb_right = 0;
-       return 0;
-}
-
 static int sh_mobile_lcdc_suspend(struct device *dev)
 {
        struct platform_device *pdev = to_platform_device(dev);
@@ -1316,47 +1309,20 @@ static int sh_mobile_lcdc_resume(struct device *dev)
 static int sh_mobile_lcdc_runtime_suspend(struct device *dev)
 {
        struct platform_device *pdev = to_platform_device(dev);
-       struct sh_mobile_lcdc_priv *p = platform_get_drvdata(pdev);
-       struct sh_mobile_lcdc_chan *ch;
-       int k, n;
-
-       /* save per-channel registers */
-       for (k = 0; k < ARRAY_SIZE(p->ch); k++) {
-               ch = &p->ch[k];
-               if (!ch->enabled)
-                       continue;
-               for (n = 0; n < NR_CH_REGS; n++)
-                       ch->saved_ch_regs[n] = lcdc_read_chan(ch, n);
-       }
-
-       /* save shared registers */
-       for (n = 0; n < NR_SHARED_REGS; n++)
-               p->saved_shared_regs[n] = lcdc_read(p, lcdc_shared_regs[n]);
+       struct sh_mobile_lcdc_priv *priv = platform_get_drvdata(pdev);
 
        /* turn off LCDC hardware */
-       lcdc_write(p, _LDCNT1R, 0);
+       lcdc_write(priv, _LDCNT1R, 0);
+
        return 0;
 }
 
 static int sh_mobile_lcdc_runtime_resume(struct device *dev)
 {
        struct platform_device *pdev = to_platform_device(dev);
-       struct sh_mobile_lcdc_priv *p = platform_get_drvdata(pdev);
-       struct sh_mobile_lcdc_chan *ch;
-       int k, n;
-
-       /* restore per-channel registers */
-       for (k = 0; k < ARRAY_SIZE(p->ch); k++) {
-               ch = &p->ch[k];
-               if (!ch->enabled)
-                       continue;
-               for (n = 0; n < NR_CH_REGS; n++)
-                       lcdc_write_chan(ch, n, ch->saved_ch_regs[n]);
-       }
+       struct sh_mobile_lcdc_priv *priv = platform_get_drvdata(pdev);
 
-       /* restore shared registers */
-       for (n = 0; n < NR_SHARED_REGS; n++)
-               lcdc_write(p, lcdc_shared_regs[n], p->saved_shared_regs[n]);
+       __sh_mobile_lcdc_start(priv);
 
        return 0;
 }
@@ -1408,17 +1374,187 @@ static int sh_mobile_lcdc_notify(struct notifier_block *nb,
        return NOTIFY_OK;
 }
 
-static int sh_mobile_lcdc_remove(struct platform_device *pdev);
+static int sh_mobile_lcdc_remove(struct platform_device *pdev)
+{
+       struct sh_mobile_lcdc_priv *priv = platform_get_drvdata(pdev);
+       struct fb_info *info;
+       int i;
 
-static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
+       fb_unregister_client(&priv->notifier);
+
+       for (i = 0; i < ARRAY_SIZE(priv->ch); i++)
+               if (priv->ch[i].info && priv->ch[i].info->dev)
+                       unregister_framebuffer(priv->ch[i].info);
+
+       sh_mobile_lcdc_stop(priv);
+
+       for (i = 0; i < ARRAY_SIZE(priv->ch); i++) {
+               info = priv->ch[i].info;
+
+               if (!info || !info->device)
+                       continue;
+
+               if (priv->ch[i].sglist)
+                       vfree(priv->ch[i].sglist);
+
+               if (info->screen_base)
+                       dma_free_coherent(&pdev->dev, info->fix.smem_len,
+                                         info->screen_base,
+                                         priv->ch[i].dma_handle);
+               fb_dealloc_cmap(&info->cmap);
+               framebuffer_release(info);
+       }
+
+       for (i = 0; i < ARRAY_SIZE(priv->ch); i++) {
+               if (priv->ch[i].bl)
+                       sh_mobile_lcdc_bl_remove(priv->ch[i].bl);
+       }
+
+       if (priv->dot_clk)
+               clk_put(priv->dot_clk);
+
+       if (priv->dev)
+               pm_runtime_disable(priv->dev);
+
+       if (priv->base)
+               iounmap(priv->base);
+
+       if (priv->irq)
+               free_irq(priv->irq, priv);
+       kfree(priv);
+       return 0;
+}
+
+static int __devinit sh_mobile_lcdc_channel_init(struct sh_mobile_lcdc_chan *ch,
+                                                struct device *dev)
 {
+       struct sh_mobile_lcdc_chan_cfg *cfg = &ch->cfg;
+       const struct fb_videomode *max_mode;
+       const struct fb_videomode *mode;
+       struct fb_var_screeninfo *var;
        struct fb_info *info;
-       struct sh_mobile_lcdc_priv *priv;
+       unsigned int max_size;
+       int num_cfg;
+       void *buf;
+       int ret;
+       int i;
+
+       mutex_init(&ch->open_lock);
+
+       /* Allocate the frame buffer device. */
+       ch->info = framebuffer_alloc(0, dev);
+       if (!ch->info) {
+               dev_err(dev, "unable to allocate fb_info\n");
+               return -ENOMEM;
+       }
+
+       info = ch->info;
+       info->fbops = &sh_mobile_lcdc_ops;
+       info->par = ch;
+       info->pseudo_palette = &ch->pseudo_palette;
+       info->flags = FBINFO_FLAG_DEFAULT;
+
+       /* Iterate through the modes to validate them and find the highest
+        * resolution.
+        */
+       max_mode = NULL;
+       max_size = 0;
+
+       for (i = 0, mode = cfg->lcd_cfg; i < cfg->num_cfg; i++, mode++) {
+               unsigned int size = mode->yres * mode->xres;
+
+               /* NV12 buffers must have even number of lines */
+               if ((cfg->nonstd) && cfg->bpp == 12 &&
+                               (mode->yres & 0x1)) {
+                       dev_err(dev, "yres must be multiple of 2 for YCbCr420 "
+                               "mode.\n");
+                       return -EINVAL;
+               }
+
+               if (size > max_size) {
+                       max_mode = mode;
+                       max_size = size;
+               }
+       }
+
+       if (!max_size)
+               max_size = MAX_XRES * MAX_YRES;
+       else
+               dev_dbg(dev, "Found largest videomode %ux%u\n",
+                       max_mode->xres, max_mode->yres);
+
+       /* Initialize fixed screen information. Restrict pan to 2 lines steps
+        * for NV12.
+        */
+       info->fix = sh_mobile_lcdc_fix;
+       info->fix.smem_len = max_size * 2 * cfg->bpp / 8;
+       if (cfg->nonstd && cfg->bpp == 12)
+               info->fix.ypanstep = 2;
+
+       /* Create the mode list. */
+       if (cfg->lcd_cfg == NULL) {
+               mode = &default_720p;
+               num_cfg = 1;
+       } else {
+               mode = cfg->lcd_cfg;
+               num_cfg = cfg->num_cfg;
+       }
+
+       fb_videomode_to_modelist(mode, num_cfg, &info->modelist);
+
+       /* Initialize variable screen information using the first mode as
+        * default. The default Y virtual resolution is twice the panel size to
+        * allow for double-buffering.
+        */
+       var = &info->var;
+       fb_videomode_to_var(var, mode);
+       var->bits_per_pixel = cfg->bpp;
+       var->width = cfg->lcd_size_cfg.width;
+       var->height = cfg->lcd_size_cfg.height;
+       var->yres_virtual = var->yres * 2;
+       var->activate = FB_ACTIVATE_NOW;
+
+       ret = sh_mobile_check_var(var, info);
+       if (ret)
+               return ret;
+
+       /* Allocate frame buffer memory and color map. */
+       buf = dma_alloc_coherent(dev, info->fix.smem_len, &ch->dma_handle,
+                                GFP_KERNEL);
+       if (!buf) {
+               dev_err(dev, "unable to allocate buffer\n");
+               return -ENOMEM;
+       }
+
+       ret = fb_alloc_cmap(&info->cmap, PALETTE_NR, 0);
+       if (ret < 0) {
+               dev_err(dev, "unable to allocate cmap\n");
+               dma_free_coherent(dev, info->fix.smem_len,
+                                 buf, ch->dma_handle);
+               return ret;
+       }
+
+       info->fix.smem_start = ch->dma_handle;
+       if (var->nonstd)
+               info->fix.line_length = var->xres;
+       else
+               info->fix.line_length = var->xres * (cfg->bpp / 8);
+
+       info->screen_base = buf;
+       info->device = dev;
+       ch->display_var = *var;
+
+       return 0;
+}
+
+static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
+{
        struct sh_mobile_lcdc_info *pdata = pdev->dev.platform_data;
+       struct sh_mobile_lcdc_priv *priv;
        struct resource *res;
+       int num_channels;
        int error;
-       void *buf;
-       int i, j;
+       int i;
 
        if (!pdata) {
                dev_err(&pdev->dev, "no platform data defined\n");
@@ -1440,7 +1576,7 @@ static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
 
        platform_set_drvdata(pdev, priv);
 
-       error = request_irq(i, sh_mobile_lcdc_irq, IRQF_DISABLED,
+       error = request_irq(i, sh_mobile_lcdc_irq, 0,
                            dev_name(&pdev->dev), priv);
        if (error) {
                dev_err(&pdev->dev, "unable to request irq\n");
@@ -1450,9 +1586,8 @@ static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
        priv->irq = i;
        atomic_set(&priv->hw_usecnt, -1);
 
-       j = 0;
-       for (i = 0; i < ARRAY_SIZE(pdata->ch); i++) {
-               struct sh_mobile_lcdc_chan *ch = priv->ch + j;
+       for (i = 0, num_channels = 0; i < ARRAY_SIZE(pdata->ch); i++) {
+               struct sh_mobile_lcdc_chan *ch = priv->ch + num_channels;
 
                ch->lcdc = priv;
                memcpy(&ch->cfg, &pdata->ch[i], sizeof(pdata->ch[i]));
@@ -1472,26 +1607,26 @@ static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
 
                switch (pdata->ch[i].chan) {
                case LCDC_CHAN_MAINLCD:
-                       ch->enabled = 1 << 1;
+                       ch->enabled = LDCNT2R_ME;
                        ch->reg_offs = lcdc_offs_mainlcd;
-                       j++;
+                       num_channels++;
                        break;
                case LCDC_CHAN_SUBLCD:
-                       ch->enabled = 1 << 2;
+                       ch->enabled = LDCNT2R_SE;
                        ch->reg_offs = lcdc_offs_sublcd;
-                       j++;
+                       num_channels++;
                        break;
                }
        }
 
-       if (!j) {
+       if (!num_channels) {
                dev_err(&pdev->dev, "no channels defined\n");
                error = -EINVAL;
                goto err1;
        }
 
        /* for dual channel LCDC (MAIN + SUB) force shared bpp setting */
-       if (j == 2)
+       if (num_channels == 2)
                priv->forced_bpp = pdata->ch[0].bpp;
 
        priv->base = ioremap_nocache(res->start, resource_size(res));
@@ -1506,125 +1641,23 @@ static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
 
        priv->meram_dev = pdata->meram_dev;
 
-       for (i = 0; i < j; i++) {
-               struct fb_var_screeninfo *var;
-               const struct fb_videomode *lcd_cfg, *max_cfg = NULL;
+       for (i = 0; i < num_channels; i++) {
                struct sh_mobile_lcdc_chan *ch = priv->ch + i;
-               struct sh_mobile_lcdc_chan_cfg *cfg = &ch->cfg;
-               const struct fb_videomode *mode = cfg->lcd_cfg;
-               unsigned long max_size = 0;
-               int k;
-               int num_cfg;
-
-               ch->info = framebuffer_alloc(0, &pdev->dev);
-               if (!ch->info) {
-                       dev_err(&pdev->dev, "unable to allocate fb_info\n");
-                       error = -ENOMEM;
-                       break;
-               }
-
-               info = ch->info;
-               var = &info->var;
-               info->fbops = &sh_mobile_lcdc_ops;
-               info->par = ch;
-
-               mutex_init(&ch->open_lock);
-
-               for (k = 0, lcd_cfg = mode;
-                    k < cfg->num_cfg && lcd_cfg;
-                    k++, lcd_cfg++) {
-                       unsigned long size = lcd_cfg->yres * lcd_cfg->xres;
-                       /* NV12 buffers must have even number of lines */
-                       if ((cfg->nonstd) && cfg->bpp == 12 &&
-                                       (lcd_cfg->yres & 0x1)) {
-                               dev_err(&pdev->dev, "yres must be multiple of 2"
-                                               " for YCbCr420 mode.\n");
-                               error = -EINVAL;
-                               goto err1;
-                       }
-
-                       if (size > max_size) {
-                               max_cfg = lcd_cfg;
-                               max_size = size;
-                       }
-               }
-
-               if (!mode)
-                       max_size = MAX_XRES * MAX_YRES;
-               else if (max_cfg)
-                       dev_dbg(&pdev->dev, "Found largest videomode %ux%u\n",
-                               max_cfg->xres, max_cfg->yres);
 
-               info->fix = sh_mobile_lcdc_fix;
-               info->fix.smem_len = max_size * 2 * cfg->bpp / 8;
-
-                /* Only pan in 2 line steps for NV12 */
-               if (cfg->nonstd && cfg->bpp == 12)
-                       info->fix.ypanstep = 2;
-
-               if (!mode) {
-                       mode = &default_720p;
-                       num_cfg = 1;
-               } else {
-                       num_cfg = cfg->num_cfg;
-               }
-
-               fb_videomode_to_modelist(mode, num_cfg, &info->modelist);
-
-               fb_videomode_to_var(var, mode);
-               var->width = cfg->lcd_size_cfg.width;
-               var->height = cfg->lcd_size_cfg.height;
-               /* Default Y virtual resolution is 2x panel size */
-               var->yres_virtual = var->yres * 2;
-               var->activate = FB_ACTIVATE_NOW;
-
-               error = sh_mobile_lcdc_set_bpp(var, cfg->bpp, cfg->nonstd);
+               error = sh_mobile_lcdc_channel_init(ch, &pdev->dev);
                if (error)
-                       break;
-
-               buf = dma_alloc_coherent(&pdev->dev, info->fix.smem_len,
-                                        &ch->dma_handle, GFP_KERNEL);
-               if (!buf) {
-                       dev_err(&pdev->dev, "unable to allocate buffer\n");
-                       error = -ENOMEM;
-                       break;
-               }
-
-               info->pseudo_palette = &ch->pseudo_palette;
-               info->flags = FBINFO_FLAG_DEFAULT;
-
-               error = fb_alloc_cmap(&info->cmap, PALETTE_NR, 0);
-               if (error < 0) {
-                       dev_err(&pdev->dev, "unable to allocate cmap\n");
-                       dma_free_coherent(&pdev->dev, info->fix.smem_len,
-                                         buf, ch->dma_handle);
-                       break;
-               }
-
-               info->fix.smem_start = ch->dma_handle;
-               if (var->nonstd)
-                       info->fix.line_length = var->xres;
-               else
-                       info->fix.line_length = var->xres * (cfg->bpp / 8);
-
-               info->screen_base = buf;
-               info->device = &pdev->dev;
-               ch->display_var = *var;
+                       goto err1;
        }
 
-       if (error)
-               goto err1;
-
        error = sh_mobile_lcdc_start(priv);
        if (error) {
                dev_err(&pdev->dev, "unable to start hardware\n");
                goto err1;
        }
 
-       for (i = 0; i < j; i++) {
+       for (i = 0; i < num_channels; i++) {
                struct sh_mobile_lcdc_chan *ch = priv->ch + i;
-
-               info = ch->info;
+               struct fb_info *info = ch->info;
 
                if (info->fbdefio) {
                        ch->sglist = vmalloc(sizeof(struct scatterlist) *
@@ -1665,57 +1698,6 @@ err1:
        return error;
 }
 
-static int sh_mobile_lcdc_remove(struct platform_device *pdev)
-{
-       struct sh_mobile_lcdc_priv *priv = platform_get_drvdata(pdev);
-       struct fb_info *info;
-       int i;
-
-       fb_unregister_client(&priv->notifier);
-
-       for (i = 0; i < ARRAY_SIZE(priv->ch); i++)
-               if (priv->ch[i].info && priv->ch[i].info->dev)
-                       unregister_framebuffer(priv->ch[i].info);
-
-       sh_mobile_lcdc_stop(priv);
-
-       for (i = 0; i < ARRAY_SIZE(priv->ch); i++) {
-               info = priv->ch[i].info;
-
-               if (!info || !info->device)
-                       continue;
-
-               if (priv->ch[i].sglist)
-                       vfree(priv->ch[i].sglist);
-
-               if (info->screen_base)
-                       dma_free_coherent(&pdev->dev, info->fix.smem_len,
-                                         info->screen_base,
-                                         priv->ch[i].dma_handle);
-               fb_dealloc_cmap(&info->cmap);
-               framebuffer_release(info);
-       }
-
-       for (i = 0; i < ARRAY_SIZE(priv->ch); i++) {
-               if (priv->ch[i].bl)
-                       sh_mobile_lcdc_bl_remove(priv->ch[i].bl);
-       }
-
-       if (priv->dot_clk)
-               clk_put(priv->dot_clk);
-
-       if (priv->dev)
-               pm_runtime_disable(priv->dev);
-
-       if (priv->base)
-               iounmap(priv->base);
-
-       if (priv->irq)
-               free_irq(priv->irq, priv);
-       kfree(priv);
-       return 0;
-}
-
 static struct platform_driver sh_mobile_lcdc_driver = {
        .driver         = {
                .name           = "sh_mobile_lcdc_fb",
index aeed6687e6a737b9d51852380c48bea7e5ab0e6d..a58a0f38848b03679a649af291f3457683781121 100644 (file)
@@ -18,6 +18,13 @@ struct sh_mobile_lcdc_priv;
 struct fb_info;
 struct backlight_device;
 
+/*
+ * struct sh_mobile_lcdc_chan - LCDC display channel
+ *
+ * @base_addr_y: Frame buffer viewport base address (luma component)
+ * @base_addr_c: Frame buffer viewport base address (chroma component)
+ * @pitch: Frame buffer line pitch
+ */
 struct sh_mobile_lcdc_chan {
        struct sh_mobile_lcdc_priv *lcdc;
        unsigned long *reg_offs;
@@ -25,7 +32,6 @@ struct sh_mobile_lcdc_chan {
        unsigned long enabled; /* ME and SE in LDCNT2R */
        struct sh_mobile_lcdc_chan_cfg cfg;
        u32 pseudo_palette[PALETTE_NR];
-       unsigned long saved_ch_regs[NR_CH_REGS];
        struct fb_info *info;
        struct backlight_device *bl;
        dma_addr_t dma_handle;
@@ -40,6 +46,10 @@ struct sh_mobile_lcdc_chan {
        int blank_status;
        struct mutex open_lock;         /* protects the use counter */
        int meram_enabled;
+
+       unsigned long base_addr_y;
+       unsigned long base_addr_c;
+       unsigned int pitch;
 };
 
 #endif
index cc7d7329dc151af821153feb999998e42460267e..4d63490209cdf1431430aa343a513d29e11ba846 100644 (file)
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/device.h>
+#include <linux/pm_runtime.h>
 #include <linux/io.h>
 #include <linux/slab.h>
 #include <linux/platform_device.h>
-
-#include "sh_mobile_meram.h"
+#include <video/sh_mobile_meram.h>
 
 /* meram registers */
-#define MExxCTL 0x0
-#define MExxBSIZE 0x4
-#define MExxMNCF 0x8
-#define MExxSARA 0x10
-#define MExxSARB 0x14
-#define MExxSBSIZE 0x18
-
-#define MERAM_MExxCTL_VAL(ctl, next_icb, addr) \
-       ((ctl) | (((next_icb) & 0x1f) << 11) | (((addr) & 0x7ff) << 16))
-#define        MERAM_MExxBSIZE_VAL(a, b, c) \
-       (((a) << 28) | ((b) << 16) | (c))
-
-#define MEVCR1 0x4
-#define MEACTS 0x10
-#define MEQSEL1 0x40
-#define MEQSEL2 0x44
+#define MEVCR1                 0x4
+#define MEVCR1_RST             (1 << 31)
+#define MEVCR1_WD              (1 << 30)
+#define MEVCR1_AMD1            (1 << 29)
+#define MEVCR1_AMD0            (1 << 28)
+#define MEQSEL1                        0x40
+#define MEQSEL2                        0x44
+
+#define MExxCTL                        0x400
+#define MExxCTL_BV             (1 << 31)
+#define MExxCTL_BSZ_SHIFT      28
+#define MExxCTL_MSAR_MASK      (0x7ff << MExxCTL_MSAR_SHIFT)
+#define MExxCTL_MSAR_SHIFT     16
+#define MExxCTL_NXT_MASK       (0x1f << MExxCTL_NXT_SHIFT)
+#define MExxCTL_NXT_SHIFT      11
+#define MExxCTL_WD1            (1 << 10)
+#define MExxCTL_WD0            (1 << 9)
+#define MExxCTL_WS             (1 << 8)
+#define MExxCTL_CB             (1 << 7)
+#define MExxCTL_WBF            (1 << 6)
+#define MExxCTL_WF             (1 << 5)
+#define MExxCTL_RF             (1 << 4)
+#define MExxCTL_CM             (1 << 3)
+#define MExxCTL_MD_READ                (1 << 0)
+#define MExxCTL_MD_WRITE       (2 << 0)
+#define MExxCTL_MD_ICB_WB      (3 << 0)
+#define MExxCTL_MD_ICB         (4 << 0)
+#define MExxCTL_MD_FB          (7 << 0)
+#define MExxCTL_MD_MASK                (7 << 0)
+#define MExxBSIZE              0x404
+#define MExxBSIZE_RCNT_SHIFT   28
+#define MExxBSIZE_YSZM1_SHIFT  16
+#define MExxBSIZE_XSZM1_SHIFT  0
+#define MExxMNCF               0x408
+#define MExxMNCF_KWBNM_SHIFT   28
+#define MExxMNCF_KRBNM_SHIFT   24
+#define MExxMNCF_BNM_SHIFT     16
+#define MExxMNCF_XBV           (1 << 15)
+#define MExxMNCF_CPL_YCBCR444  (1 << 12)
+#define MExxMNCF_CPL_YCBCR420  (2 << 12)
+#define MExxMNCF_CPL_YCBCR422  (3 << 12)
+#define MExxMNCF_CPL_MSK       (3 << 12)
+#define MExxMNCF_BL            (1 << 2)
+#define MExxMNCF_LNM_SHIFT     0
+#define MExxSARA               0x410
+#define MExxSARB               0x414
+#define MExxSBSIZE             0x418
+#define MExxSBSIZE_HDV         (1 << 31)
+#define MExxSBSIZE_HSZ16       (0 << 28)
+#define MExxSBSIZE_HSZ32       (1 << 28)
+#define MExxSBSIZE_HSZ64       (2 << 28)
+#define MExxSBSIZE_HSZ128      (3 << 28)
+#define MExxSBSIZE_SBSIZZ_SHIFT        0
+
+#define MERAM_MExxCTL_VAL(next, addr)  \
+       ((((next) << MExxCTL_NXT_SHIFT) & MExxCTL_NXT_MASK) | \
+        (((addr) << MExxCTL_MSAR_SHIFT) & MExxCTL_MSAR_MASK))
+#define        MERAM_MExxBSIZE_VAL(rcnt, yszm1, xszm1) \
+       (((rcnt) << MExxBSIZE_RCNT_SHIFT) | \
+        ((yszm1) << MExxBSIZE_YSZM1_SHIFT) | \
+        ((xszm1) << MExxBSIZE_XSZM1_SHIFT))
+
+#define SH_MOBILE_MERAM_ICB_NUM                32
+
+static unsigned long common_regs[] = {
+       MEVCR1,
+       MEQSEL1,
+       MEQSEL2,
+};
+#define CMN_REGS_SIZE ARRAY_SIZE(common_regs)
+
+static unsigned long icb_regs[] = {
+       MExxCTL,
+       MExxBSIZE,
+       MExxMNCF,
+       MExxSARA,
+       MExxSARB,
+       MExxSBSIZE,
+};
+#define ICB_REGS_SIZE ARRAY_SIZE(icb_regs)
+
+struct sh_mobile_meram_priv {
+       void __iomem    *base;
+       struct mutex    lock;
+       unsigned long   used_icb;
+       int             used_meram_cache_regions;
+       unsigned long   used_meram_cache[SH_MOBILE_MERAM_ICB_NUM];
+       unsigned long   cmn_saved_regs[CMN_REGS_SIZE];
+       unsigned long   icb_saved_regs[ICB_REGS_SIZE * SH_MOBILE_MERAM_ICB_NUM];
+};
 
 /* settings */
 #define MERAM_SEC_LINE 15
  * MERAM/ICB access functions
  */
 
-#define MERAM_ICB_OFFSET(base, idx, off)       \
-       ((base) + (0x400 + ((idx) * 0x20) + (off)))
+#define MERAM_ICB_OFFSET(base, idx, off)       ((base) + (off) + (idx) * 0x20)
 
 static inline void meram_write_icb(void __iomem *base, int idx, int off,
        unsigned long val)
@@ -280,17 +353,18 @@ static int meram_init(struct sh_mobile_meram_priv *priv,
        /*
         * Set MERAM for framebuffer
         *
-        * 0x70f:  WD = 0x3, WS=0x1, CM=0x1, MD=FB mode
         * we also chain the cache_icb and the marker_icb.
         * we also split the allocated MERAM buffer between two ICBs.
         */
        meram_write_icb(priv->base, icb->cache_icb, MExxCTL,
-                       MERAM_MExxCTL_VAL(0x70f, icb->marker_icb,
-                                         icb->meram_offset));
+                       MERAM_MExxCTL_VAL(icb->marker_icb, icb->meram_offset) |
+                       MExxCTL_WD1 | MExxCTL_WD0 | MExxCTL_WS | MExxCTL_CM |
+                       MExxCTL_MD_FB);
        meram_write_icb(priv->base, icb->marker_icb, MExxCTL,
-                       MERAM_MExxCTL_VAL(0x70f, icb->cache_icb,
-                                         icb->meram_offset +
-                                         icb->meram_size / 2));
+                       MERAM_MExxCTL_VAL(icb->cache_icb, icb->meram_offset +
+                                         icb->meram_size / 2) |
+                       MExxCTL_WD1 | MExxCTL_WD0 | MExxCTL_WS | MExxCTL_CM |
+                       MExxCTL_MD_FB);
 
        return 0;
 }
@@ -299,8 +373,10 @@ static void meram_deinit(struct sh_mobile_meram_priv *priv,
                        struct sh_mobile_meram_icb *icb)
 {
        /* disable ICB */
-       meram_write_icb(priv->base, icb->cache_icb,  MExxCTL, 0);
-       meram_write_icb(priv->base, icb->marker_icb, MExxCTL, 0);
+       meram_write_icb(priv->base, icb->cache_icb,  MExxCTL,
+                       MExxCTL_WBF | MExxCTL_WF | MExxCTL_RF);
+       meram_write_icb(priv->base, icb->marker_icb, MExxCTL,
+                       MExxCTL_WBF | MExxCTL_WF | MExxCTL_RF);
        icb->cache_unit = 0;
 }
 
@@ -337,24 +413,22 @@ static int sh_mobile_meram_register(struct sh_mobile_meram_info *pdata,
                xres, yres, (!pixelformat) ? "yuv" : "rgb",
                base_addr_y, base_addr_c);
 
-       mutex_lock(&priv->lock);
-
        /* we can't handle wider than 8192px */
        if (xres > 8192) {
                dev_err(&pdev->dev, "width exceeding the limit (> 8192).");
-               error = -EINVAL;
-               goto err;
-       }
-
-       if (priv->used_meram_cache_regions + 2 > SH_MOBILE_MERAM_ICB_NUM) {
-               dev_err(&pdev->dev, "no more ICB available.");
-               error = -EINVAL;
-               goto err;
+               return -EINVAL;
        }
 
        /* do we have at least one ICB config? */
        if (cfg->icb[0].marker_icb < 0 || cfg->icb[0].cache_icb < 0) {
                dev_err(&pdev->dev, "at least one ICB is required.");
+               return -EINVAL;
+       }
+
+       mutex_lock(&priv->lock);
+
+       if (priv->used_meram_cache_regions + 2 > SH_MOBILE_MERAM_ICB_NUM) {
+               dev_err(&pdev->dev, "no more ICB available.");
                error = -EINVAL;
                goto err;
        }
@@ -460,6 +534,57 @@ static int sh_mobile_meram_update(struct sh_mobile_meram_info *pdata,
        return 0;
 }
 
+static int sh_mobile_meram_runtime_suspend(struct device *dev)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       struct sh_mobile_meram_priv *priv = platform_get_drvdata(pdev);
+       int k, j;
+
+       for (k = 0; k < CMN_REGS_SIZE; k++)
+               priv->cmn_saved_regs[k] = meram_read_reg(priv->base,
+                       common_regs[k]);
+
+       for (j = 0; j < 32; j++) {
+               if (!test_bit(j, &priv->used_icb))
+                       continue;
+               for (k = 0; k < ICB_REGS_SIZE; k++) {
+                       priv->icb_saved_regs[j * ICB_REGS_SIZE + k] =
+                               meram_read_icb(priv->base, j, icb_regs[k]);
+                       /* Reset ICB on resume */
+                       if (icb_regs[k] == MExxCTL)
+                               priv->icb_saved_regs[j * ICB_REGS_SIZE + k] |=
+                                       MExxCTL_WBF | MExxCTL_WF | MExxCTL_RF;
+               }
+       }
+       return 0;
+}
+
+static int sh_mobile_meram_runtime_resume(struct device *dev)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       struct sh_mobile_meram_priv *priv = platform_get_drvdata(pdev);
+       int k, j;
+
+       for (j = 0; j < 32; j++) {
+               if (!test_bit(j, &priv->used_icb))
+                       continue;
+               for (k = 0; k < ICB_REGS_SIZE; k++) {
+                       meram_write_icb(priv->base, j, icb_regs[k],
+                       priv->icb_saved_regs[j * ICB_REGS_SIZE + k]);
+               }
+       }
+
+       for (k = 0; k < CMN_REGS_SIZE; k++)
+               meram_write_reg(priv->base, common_regs[k],
+                       priv->cmn_saved_regs[k]);
+       return 0;
+}
+
+static const struct dev_pm_ops sh_mobile_meram_dev_pm_ops = {
+       .runtime_suspend = sh_mobile_meram_runtime_suspend,
+       .runtime_resume = sh_mobile_meram_runtime_resume,
+};
+
 static struct sh_mobile_meram_ops sh_mobile_meram_ops = {
        .module                 = THIS_MODULE,
        .meram_register         = sh_mobile_meram_register,
@@ -513,7 +638,9 @@ static int __devinit sh_mobile_meram_probe(struct platform_device *pdev)
 
        /* initialize ICB addressing mode */
        if (pdata->addr_mode == SH_MOBILE_MERAM_MODE1)
-               meram_write_reg(priv->base, MEVCR1, 1 << 29);
+               meram_write_reg(priv->base, MEVCR1, MEVCR1_AMD1);
+
+       pm_runtime_enable(&pdev->dev);
 
        dev_info(&pdev->dev, "sh_mobile_meram initialized.");
 
@@ -530,6 +657,8 @@ static int sh_mobile_meram_remove(struct platform_device *pdev)
 {
        struct sh_mobile_meram_priv *priv = platform_get_drvdata(pdev);
 
+       pm_runtime_disable(&pdev->dev);
+
        if (priv->base)
                iounmap(priv->base);
 
@@ -544,6 +673,7 @@ static struct platform_driver sh_mobile_meram_driver = {
        .driver = {
                .name           = "sh_mobile_meram",
                .owner          = THIS_MODULE,
+               .pm             = &sh_mobile_meram_dev_pm_ops,
        },
        .probe          = sh_mobile_meram_probe,
        .remove         = sh_mobile_meram_remove,
diff --git a/drivers/video/sh_mobile_meram.h b/drivers/video/sh_mobile_meram.h
deleted file mode 100644 (file)
index 82c54fb..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-#ifndef __sh_mobile_meram_h__
-#define __sh_mobile_meram_h__
-
-#include <linux/mutex.h>
-#include <video/sh_mobile_meram.h>
-
-/*
- * MERAM private
- */
-
-#define MERAM_ICB_Y 0x1
-#define MERAM_ICB_C 0x2
-
-/* MERAM cache size */
-#define SH_MOBILE_MERAM_ICB_NUM                32
-
-#define SH_MOBILE_MERAM_CACHE_OFFSET(p)        ((p) >> 16)
-#define SH_MOBILE_MERAM_CACHE_SIZE(p)  ((p) & 0xffff)
-
-struct sh_mobile_meram_priv {
-       void __iomem    *base;
-       struct mutex    lock;
-       unsigned long   used_icb;
-       int             used_meram_cache_regions;
-       unsigned long   used_meram_cache[SH_MOBILE_MERAM_ICB_NUM];
-};
-
-int sh_mobile_meram_alloc_icb(const struct sh_mobile_meram_cfg *cfg,
-                  int xres,
-                  int yres,
-                  unsigned int base_addr,
-                  int yuv_mode,
-                  int *marker_icb,
-                  int *out_pitch);
-
-void sh_mobile_meram_free_icb(int marker_icb);
-
-#define SH_MOBILE_MERAM_START(ind, ab) \
-       (0xC0000000 | ((ab & 0x1) << 23) | ((ind & 0x1F) << 24))
-
-#endif /* !__sh_mobile_meram_h__ */
index 75259845933deb53ab030a2067bb52e69259f673..078ca2167d6f9754a3fc9ad26582643b82e34c8a 100644 (file)
@@ -1333,19 +1333,14 @@ sisfb_set_base_CRT2(struct sis_video_info *ivideo, unsigned int base)
 }
 
 static int
-sisfb_pan_var(struct sis_video_info *ivideo, struct fb_var_screeninfo *var)
+sisfb_pan_var(struct sis_video_info *ivideo, struct fb_info *info,
+             struct fb_var_screeninfo *var)
 {
-       if(var->xoffset > (var->xres_virtual - var->xres)) {
-               return -EINVAL;
-       }
-       if(var->yoffset > (var->yres_virtual - var->yres)) {
-               return -EINVAL;
-       }
-
-       ivideo->current_base = (var->yoffset * var->xres_virtual) + var->xoffset;
+       ivideo->current_base = var->yoffset * info->var.xres_virtual
+                            + var->xoffset;
 
        /* calculate base bpp dep. */
-       switch(var->bits_per_pixel) {
+       switch (info->var.bits_per_pixel) {
        case 32:
                break;
        case 16:
@@ -1635,20 +1630,15 @@ sisfb_pan_display(struct fb_var_screeninfo *var, struct fb_info* info)
        struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
        int err;
 
-       if(var->xoffset > (var->xres_virtual - var->xres))
-               return -EINVAL;
-
-       if(var->yoffset > (var->yres_virtual - var->yres))
-               return -EINVAL;
-
-       if(var->vmode & FB_VMODE_YWRAP)
+       if (var->vmode & FB_VMODE_YWRAP)
                return -EINVAL;
 
-       if(var->xoffset + info->var.xres > info->var.xres_virtual ||
-          var->yoffset + info->var.yres > info->var.yres_virtual)
+       if (var->xoffset + info->var.xres > info->var.xres_virtual ||
+           var->yoffset + info->var.yres > info->var.yres_virtual)
                return -EINVAL;
 
-       if((err = sisfb_pan_var(ivideo, var)) < 0)
+       err = sisfb_pan_var(ivideo, info, var);
+       if (err < 0)
                return err;
 
        info->var.xoffset = var->xoffset;
index 89158bc71da2b3ea982d355c2e6ee0dfeaee7244..30f7a815a62bc0f36813a644ad1819d210958ca5 100644 (file)
@@ -989,7 +989,7 @@ static struct platform_device *xxxfb_device;
  */
 int __init xxxfb_setup(char *options)
 {
-    /* Parse user speficied options (`video=xxxfb:') */
+    /* Parse user specified options (`video=xxxfb:') */
 }
 #endif /* MODULE */
 
index 6294dca955005988f384fbf0bdae104f43c8037d..a78254cf8e83eb971db5bd7f6cb499745a6741f6 100644 (file)
@@ -582,7 +582,7 @@ static int sm501fb_pan_crt(struct fb_var_screeninfo *var,
 {
        struct sm501fb_par  *par = info->par;
        struct sm501fb_info *fbi = par->info;
-       unsigned int bytes_pixel = var->bits_per_pixel / 8;
+       unsigned int bytes_pixel = info->var.bits_per_pixel / 8;
        unsigned long reg;
        unsigned long xoffs;
 
@@ -614,10 +614,10 @@ static int sm501fb_pan_pnl(struct fb_var_screeninfo *var,
        struct sm501fb_info *fbi = par->info;
        unsigned long reg;
 
-       reg = var->xoffset | (var->xres_virtual << 16);
+       reg = var->xoffset | (info->var.xres_virtual << 16);
        smc501_writel(reg, fbi->regs + SM501_DC_PANEL_FB_WIDTH);
 
-       reg = var->yoffset | (var->yres_virtual << 16);
+       reg = var->yoffset | (info->var.yres_virtual << 16);
        smc501_writel(reg, fbi->regs + SM501_DC_PANEL_FB_HEIGHT);
 
        sm501fb_sync_regs(fbi);
diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
new file mode 100644 (file)
index 0000000..aaccffa
--- /dev/null
@@ -0,0 +1,1994 @@
+/*
+ * smscufx.c -- Framebuffer driver for SMSC UFX USB controller
+ *
+ * Copyright (C) 2011 Steve Glendinning <steve.glendinning@smsc.com>
+ * Copyright (C) 2009 Roberto De Ioris <roberto@unbit.it>
+ * Copyright (C) 2009 Jaya Kumar <jayakumar.lkml@gmail.com>
+ * Copyright (C) 2009 Bernie Thompson <bernie@plugable.com>
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License v2. See the file COPYING in the main directory of this archive for
+ * more details.
+ *
+ * Based on udlfb, with work from Florian Echtler, Henrik Bjerregaard Pedersen,
+ * and others.
+ *
+ * Works well with Bernie Thompson's X DAMAGE patch to xf86-video-fbdev
+ * available from http://git.plugable.com
+ *
+ * Layout is based on skeletonfb by James Simmons and Geert Uytterhoeven,
+ * usb-skeleton by GregKH.
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/usb.h>
+#include <linux/uaccess.h>
+#include <linux/mm.h>
+#include <linux/fb.h>
+#include <linux/vmalloc.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include "edid.h"
+
+#define check_warn(status, fmt, args...) \
+       ({ if (status < 0) pr_warn(fmt, ##args); })
+
+#define check_warn_return(status, fmt, args...) \
+       ({ if (status < 0) { pr_warn(fmt, ##args); return status; } })
+
+#define check_warn_goto_error(status, fmt, args...) \
+       ({ if (status < 0) { pr_warn(fmt, ##args); goto error; } })
+
+#define all_bits_set(x, bits) (((x) & (bits)) == (bits))
+
+#define USB_VENDOR_REQUEST_WRITE_REGISTER      0xA0
+#define USB_VENDOR_REQUEST_READ_REGISTER       0xA1
+
+/*
+ * TODO: Propose standard fb.h ioctl for reporting damage,
+ * using _IOWR() and one of the existing area structs from fb.h
+ * Consider these ioctls deprecated, but they're still used by the
+ * DisplayLink X server as yet - need both to be modified in tandem
+ * when new ioctl(s) are ready.
+ */
+#define UFX_IOCTL_RETURN_EDID  (0xAD)
+#define UFX_IOCTL_REPORT_DAMAGE        (0xAA)
+
+/* -BULK_SIZE as per usb-skeleton. Can we get full page and avoid overhead? */
+#define BULK_SIZE              (512)
+#define MAX_TRANSFER           (PAGE_SIZE*16 - BULK_SIZE)
+#define WRITES_IN_FLIGHT       (4)
+
+#define GET_URB_TIMEOUT                (HZ)
+#define FREE_URB_TIMEOUT       (HZ*2)
+
+#define BPP                    2
+
+#define UFX_DEFIO_WRITE_DELAY  5 /* fb_deferred_io.delay in jiffies */
+#define UFX_DEFIO_WRITE_DISABLE        (HZ*60) /* "disable" with long delay */
+
+struct dloarea {
+       int x, y;
+       int w, h;
+};
+
+struct urb_node {
+       struct list_head entry;
+       struct ufx_data *dev;
+       struct delayed_work release_urb_work;
+       struct urb *urb;
+};
+
+struct urb_list {
+       struct list_head list;
+       spinlock_t lock;
+       struct semaphore limit_sem;
+       int available;
+       int count;
+       size_t size;
+};
+
+struct ufx_data {
+       struct usb_device *udev;
+       struct device *gdev; /* &udev->dev */
+       struct fb_info *info;
+       struct urb_list urbs;
+       struct kref kref;
+       int fb_count;
+       bool virtualized; /* true when physical usb device not present */
+       struct delayed_work free_framebuffer_work;
+       atomic_t usb_active; /* 0 = update virtual buffer, but no usb traffic */
+       atomic_t lost_pixels; /* 1 = a render op failed. Need screen refresh */
+       u8 *edid; /* null until we read edid from hw or get from sysfs */
+       size_t edid_size;
+       u32 pseudo_palette[256];
+};
+
+static struct fb_fix_screeninfo ufx_fix = {
+       .id =           "smscufx",
+       .type =         FB_TYPE_PACKED_PIXELS,
+       .visual =       FB_VISUAL_TRUECOLOR,
+       .xpanstep =     0,
+       .ypanstep =     0,
+       .ywrapstep =    0,
+       .accel =        FB_ACCEL_NONE,
+};
+
+static const u32 smscufx_info_flags = FBINFO_DEFAULT | FBINFO_READS_FAST |
+       FBINFO_VIRTFB | FBINFO_HWACCEL_IMAGEBLIT | FBINFO_HWACCEL_FILLRECT |
+       FBINFO_HWACCEL_COPYAREA | FBINFO_MISC_ALWAYS_SETPAR;
+
+static struct usb_device_id id_table[] = {
+       {USB_DEVICE(0x0424, 0x9d00),},
+       {USB_DEVICE(0x0424, 0x9d01),},
+       {},
+};
+MODULE_DEVICE_TABLE(usb, id_table);
+
+/* module options */
+static int console;   /* Optionally allow fbcon to consume first framebuffer */
+static int fb_defio = true;  /* Optionally enable fb_defio mmap support */
+
+/* ufx keeps a list of urbs for efficient bulk transfers */
+static void ufx_urb_completion(struct urb *urb);
+static struct urb *ufx_get_urb(struct ufx_data *dev);
+static int ufx_submit_urb(struct ufx_data *dev, struct urb * urb, size_t len);
+static int ufx_alloc_urb_list(struct ufx_data *dev, int count, size_t size);
+static void ufx_free_urb_list(struct ufx_data *dev);
+
+/* reads a control register */
+static int ufx_reg_read(struct ufx_data *dev, u32 index, u32 *data)
+{
+       u32 *buf = kmalloc(4, GFP_KERNEL);
+       int ret;
+
+       BUG_ON(!dev);
+
+       if (!buf)
+               return -ENOMEM;
+
+       ret = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0),
+               USB_VENDOR_REQUEST_READ_REGISTER,
+               USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+               00, index, buf, 4, USB_CTRL_GET_TIMEOUT);
+
+       le32_to_cpus(buf);
+       *data = *buf;
+       kfree(buf);
+
+       if (unlikely(ret < 0))
+               pr_warn("Failed to read register index 0x%08x\n", index);
+
+       return ret;
+}
+
+/* writes a control register */
+static int ufx_reg_write(struct ufx_data *dev, u32 index, u32 data)
+{
+       u32 *buf = kmalloc(4, GFP_KERNEL);
+       int ret;
+
+       BUG_ON(!dev);
+
+       if (!buf)
+               return -ENOMEM;
+
+       *buf = data;
+       cpu_to_le32s(buf);
+
+       ret = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0),
+               USB_VENDOR_REQUEST_WRITE_REGISTER,
+               USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+               00, index, buf, 4, USB_CTRL_SET_TIMEOUT);
+
+       kfree(buf);
+
+       if (unlikely(ret < 0))
+               pr_warn("Failed to write register index 0x%08x with value "
+                       "0x%08x\n", index, data);
+
+       return ret;
+}
+
+static int ufx_reg_clear_and_set_bits(struct ufx_data *dev, u32 index,
+       u32 bits_to_clear, u32 bits_to_set)
+{
+       u32 data;
+       int status = ufx_reg_read(dev, index, &data);
+       check_warn_return(status, "ufx_reg_clear_and_set_bits error reading "
+               "0x%x", index);
+
+       data &= (~bits_to_clear);
+       data |= bits_to_set;
+
+       status = ufx_reg_write(dev, index, data);
+       check_warn_return(status, "ufx_reg_clear_and_set_bits error writing "
+               "0x%x", index);
+
+       return 0;
+}
+
+static int ufx_reg_set_bits(struct ufx_data *dev, u32 index, u32 bits)
+{
+       return ufx_reg_clear_and_set_bits(dev, index, 0, bits);
+}
+
+static int ufx_reg_clear_bits(struct ufx_data *dev, u32 index, u32 bits)
+{
+       return ufx_reg_clear_and_set_bits(dev, index, bits, 0);
+}
+
+static int ufx_lite_reset(struct ufx_data *dev)
+{
+       int status;
+       u32 value;
+
+       status = ufx_reg_write(dev, 0x3008, 0x00000001);
+       check_warn_return(status, "ufx_lite_reset error writing 0x3008");
+
+       status = ufx_reg_read(dev, 0x3008, &value);
+       check_warn_return(status, "ufx_lite_reset error reading 0x3008");
+
+       return (value == 0) ? 0 : -EIO;
+}
+
+/* If display is unblanked, then blank it */
+static int ufx_blank(struct ufx_data *dev, bool wait)
+{
+       u32 dc_ctrl, dc_sts;
+       int i;
+
+       int status = ufx_reg_read(dev, 0x2004, &dc_sts);
+       check_warn_return(status, "ufx_blank error reading 0x2004");
+
+       status = ufx_reg_read(dev, 0x2000, &dc_ctrl);
+       check_warn_return(status, "ufx_blank error reading 0x2000");
+
+       /* return success if display is already blanked */
+       if ((dc_sts & 0x00000100) || (dc_ctrl & 0x00000100))
+               return 0;
+
+       /* request the DC to blank the display */
+       dc_ctrl |= 0x00000100;
+       status = ufx_reg_write(dev, 0x2000, dc_ctrl);
+       check_warn_return(status, "ufx_blank error writing 0x2000");
+
+       /* return success immediately if we don't have to wait */
+       if (!wait)
+               return 0;
+
+       for (i = 0; i < 250; i++) {
+               status = ufx_reg_read(dev, 0x2004, &dc_sts);
+               check_warn_return(status, "ufx_blank error reading 0x2004");
+
+               if (dc_sts & 0x00000100)
+                       return 0;
+       }
+
+       /* timed out waiting for display to blank */
+       return -EIO;
+}
+
+/* If display is blanked, then unblank it */
+static int ufx_unblank(struct ufx_data *dev, bool wait)
+{
+       u32 dc_ctrl, dc_sts;
+       int i;
+
+       int status = ufx_reg_read(dev, 0x2004, &dc_sts);
+       check_warn_return(status, "ufx_unblank error reading 0x2004");
+
+       status = ufx_reg_read(dev, 0x2000, &dc_ctrl);
+       check_warn_return(status, "ufx_unblank error reading 0x2000");
+
+       /* return success if display is already unblanked */
+       if (((dc_sts & 0x00000100) == 0) || ((dc_ctrl & 0x00000100) == 0))
+               return 0;
+
+       /* request the DC to unblank the display */
+       dc_ctrl &= ~0x00000100;
+       status = ufx_reg_write(dev, 0x2000, dc_ctrl);
+       check_warn_return(status, "ufx_unblank error writing 0x2000");
+
+       /* return success immediately if we don't have to wait */
+       if (!wait)
+               return 0;
+
+       for (i = 0; i < 250; i++) {
+               status = ufx_reg_read(dev, 0x2004, &dc_sts);
+               check_warn_return(status, "ufx_unblank error reading 0x2004");
+
+               if ((dc_sts & 0x00000100) == 0)
+                       return 0;
+       }
+
+       /* timed out waiting for display to unblank */
+       return -EIO;
+}
+
+/* If display is enabled, then disable it */
+static int ufx_disable(struct ufx_data *dev, bool wait)
+{
+       u32 dc_ctrl, dc_sts;
+       int i;
+
+       int status = ufx_reg_read(dev, 0x2004, &dc_sts);
+       check_warn_return(status, "ufx_disable error reading 0x2004");
+
+       status = ufx_reg_read(dev, 0x2000, &dc_ctrl);
+       check_warn_return(status, "ufx_disable error reading 0x2000");
+
+       /* return success if display is already disabled */
+       if (((dc_sts & 0x00000001) == 0) || ((dc_ctrl & 0x00000001) == 0))
+               return 0;
+
+       /* request the DC to disable the display */
+       dc_ctrl &= ~(0x00000001);
+       status = ufx_reg_write(dev, 0x2000, dc_ctrl);
+       check_warn_return(status, "ufx_disable error writing 0x2000");
+
+       /* return success immediately if we don't have to wait */
+       if (!wait)
+               return 0;
+
+       for (i = 0; i < 250; i++) {
+               status = ufx_reg_read(dev, 0x2004, &dc_sts);
+               check_warn_return(status, "ufx_disable error reading 0x2004");
+
+               if ((dc_sts & 0x00000001) == 0)
+                       return 0;
+       }
+
+       /* timed out waiting for display to disable */
+       return -EIO;
+}
+
+/* If display is disabled, then enable it */
+static int ufx_enable(struct ufx_data *dev, bool wait)
+{
+       u32 dc_ctrl, dc_sts;
+       int i;
+
+       int status = ufx_reg_read(dev, 0x2004, &dc_sts);
+       check_warn_return(status, "ufx_enable error reading 0x2004");
+
+       status = ufx_reg_read(dev, 0x2000, &dc_ctrl);
+       check_warn_return(status, "ufx_enable error reading 0x2000");
+
+       /* return success if display is already enabled */
+       if ((dc_sts & 0x00000001) || (dc_ctrl & 0x00000001))
+               return 0;
+
+       /* request the DC to enable the display */
+       dc_ctrl |= 0x00000001;
+       status = ufx_reg_write(dev, 0x2000, dc_ctrl);
+       check_warn_return(status, "ufx_enable error writing 0x2000");
+
+       /* return success immediately if we don't have to wait */
+       if (!wait)
+               return 0;
+
+       for (i = 0; i < 250; i++) {
+               status = ufx_reg_read(dev, 0x2004, &dc_sts);
+               check_warn_return(status, "ufx_enable error reading 0x2004");
+
+               if (dc_sts & 0x00000001)
+                       return 0;
+       }
+
+       /* timed out waiting for display to enable */
+       return -EIO;
+}
+
+static int ufx_config_sys_clk(struct ufx_data *dev)
+{
+       int status = ufx_reg_write(dev, 0x700C, 0x8000000F);
+       check_warn_return(status, "error writing 0x700C");
+
+       status = ufx_reg_write(dev, 0x7014, 0x0010024F);
+       check_warn_return(status, "error writing 0x7014");
+
+       status = ufx_reg_write(dev, 0x7010, 0x00000000);
+       check_warn_return(status, "error writing 0x7010");
+
+       status = ufx_reg_clear_bits(dev, 0x700C, 0x0000000A);
+       check_warn_return(status, "error clearing PLL1 bypass in 0x700C");
+       msleep(1);
+
+       status = ufx_reg_clear_bits(dev, 0x700C, 0x80000000);
+       check_warn_return(status, "error clearing output gate in 0x700C");
+
+       return 0;
+}
+
+static int ufx_config_ddr2(struct ufx_data *dev)
+{
+       int status, i = 0;
+       u32 tmp;
+
+       status = ufx_reg_write(dev, 0x0004, 0x001F0F77);
+       check_warn_return(status, "error writing 0x0004");
+
+       status = ufx_reg_write(dev, 0x0008, 0xFFF00000);
+       check_warn_return(status, "error writing 0x0008");
+
+       status = ufx_reg_write(dev, 0x000C, 0x0FFF2222);
+       check_warn_return(status, "error writing 0x000C");
+
+       status = ufx_reg_write(dev, 0x0010, 0x00030814);
+       check_warn_return(status, "error writing 0x0010");
+
+       status = ufx_reg_write(dev, 0x0014, 0x00500019);
+       check_warn_return(status, "error writing 0x0014");
+
+       status = ufx_reg_write(dev, 0x0018, 0x020D0F15);
+       check_warn_return(status, "error writing 0x0018");
+
+       status = ufx_reg_write(dev, 0x001C, 0x02532305);
+       check_warn_return(status, "error writing 0x001C");
+
+       status = ufx_reg_write(dev, 0x0020, 0x0B030905);
+       check_warn_return(status, "error writing 0x0020");
+
+       status = ufx_reg_write(dev, 0x0024, 0x00000827);
+       check_warn_return(status, "error writing 0x0024");
+
+       status = ufx_reg_write(dev, 0x0028, 0x00000000);
+       check_warn_return(status, "error writing 0x0028");
+
+       status = ufx_reg_write(dev, 0x002C, 0x00000042);
+       check_warn_return(status, "error writing 0x002C");
+
+       status = ufx_reg_write(dev, 0x0030, 0x09520000);
+       check_warn_return(status, "error writing 0x0030");
+
+       status = ufx_reg_write(dev, 0x0034, 0x02223314);
+       check_warn_return(status, "error writing 0x0034");
+
+       status = ufx_reg_write(dev, 0x0038, 0x00430043);
+       check_warn_return(status, "error writing 0x0038");
+
+       status = ufx_reg_write(dev, 0x003C, 0xF00F000F);
+       check_warn_return(status, "error writing 0x003C");
+
+       status = ufx_reg_write(dev, 0x0040, 0xF380F00F);
+       check_warn_return(status, "error writing 0x0040");
+
+       status = ufx_reg_write(dev, 0x0044, 0xF00F0496);
+       check_warn_return(status, "error writing 0x0044");
+
+       status = ufx_reg_write(dev, 0x0048, 0x03080406);
+       check_warn_return(status, "error writing 0x0048");
+
+       status = ufx_reg_write(dev, 0x004C, 0x00001000);
+       check_warn_return(status, "error writing 0x004C");
+
+       status = ufx_reg_write(dev, 0x005C, 0x00000007);
+       check_warn_return(status, "error writing 0x005C");
+
+       status = ufx_reg_write(dev, 0x0100, 0x54F00012);
+       check_warn_return(status, "error writing 0x0100");
+
+       status = ufx_reg_write(dev, 0x0104, 0x00004012);
+       check_warn_return(status, "error writing 0x0104");
+
+       status = ufx_reg_write(dev, 0x0118, 0x40404040);
+       check_warn_return(status, "error writing 0x0118");
+
+       status = ufx_reg_write(dev, 0x0000, 0x00000001);
+       check_warn_return(status, "error writing 0x0000");
+
+       while (i++ < 500) {
+               status = ufx_reg_read(dev, 0x0000, &tmp);
+               check_warn_return(status, "error reading 0x0000");
+
+               if (all_bits_set(tmp, 0xC0000000))
+                       return 0;
+       }
+
+       pr_err("DDR2 initialisation timed out, reg 0x0000=0x%08x", tmp);
+       return -ETIMEDOUT;
+}
+
+struct pll_values {
+       u32 div_r0;
+       u32 div_f0;
+       u32 div_q0;
+       u32 range0;
+       u32 div_r1;
+       u32 div_f1;
+       u32 div_q1;
+       u32 range1;
+};
+
+static u32 ufx_calc_range(u32 ref_freq)
+{
+       if (ref_freq >= 88000000)
+               return 7;
+
+       if (ref_freq >= 54000000)
+               return 6;
+
+       if (ref_freq >= 34000000)
+               return 5;
+
+       if (ref_freq >= 21000000)
+               return 4;
+
+       if (ref_freq >= 13000000)
+               return 3;
+
+       if (ref_freq >= 8000000)
+               return 2;
+
+       return 1;
+}
+
+/* calculates PLL divider settings for a desired target frequency */
+static void ufx_calc_pll_values(const u32 clk_pixel_pll, struct pll_values *asic_pll)
+{
+       const u32 ref_clk = 25000000;
+       u32 div_r0, div_f0, div_q0, div_r1, div_f1, div_q1;
+       u32 min_error = clk_pixel_pll;
+
+       for (div_r0 = 1; div_r0 <= 32; div_r0++) {
+               u32 ref_freq0 = ref_clk / div_r0;
+               if (ref_freq0 < 5000000)
+                       break;
+
+               if (ref_freq0 > 200000000)
+                       continue;
+
+               for (div_f0 = 1; div_f0 <= 256; div_f0++) {
+                       u32 vco_freq0 = ref_freq0 * div_f0;
+
+                       if (vco_freq0 < 350000000)
+                               continue;
+
+                       if (vco_freq0 > 700000000)
+                               break;
+
+                       for (div_q0 = 0; div_q0 < 7; div_q0++) {
+                               u32 pllout_freq0 = vco_freq0 / (1 << div_q0);
+
+                               if (pllout_freq0 < 5000000)
+                                       break;
+
+                               if (pllout_freq0 > 200000000)
+                                       continue;
+
+                               for (div_r1 = 1; div_r1 <= 32; div_r1++) {
+                                       u32 ref_freq1 = pllout_freq0 / div_r1;
+
+                                       if (ref_freq1 < 5000000)
+                                               break;
+
+                                       for (div_f1 = 1; div_f1 <= 256; div_f1++) {
+                                               u32 vco_freq1 = ref_freq1 * div_f1;
+
+                                               if (vco_freq1 < 350000000)
+                                                       continue;
+
+                                               if (vco_freq1 > 700000000)
+                                                       break;
+
+                                               for (div_q1 = 0; div_q1 < 7; div_q1++) {
+                                                       u32 pllout_freq1 = vco_freq1 / (1 << div_q1);
+                                                       int error = abs(pllout_freq1 - clk_pixel_pll);
+
+                                                       if (pllout_freq1 < 5000000)
+                                                               break;
+
+                                                       if (pllout_freq1 > 700000000)
+                                                               continue;
+
+                                                       if (error < min_error) {
+                                                               min_error = error;
+
+                                                               /* final returned value is equal to calculated value - 1
+                                                                * because a value of 0 = divide by 1 */
+                                                               asic_pll->div_r0 = div_r0 - 1;
+                                                               asic_pll->div_f0 = div_f0 - 1;
+                                                               asic_pll->div_q0 = div_q0;
+                                                               asic_pll->div_r1 = div_r1 - 1;
+                                                               asic_pll->div_f1 = div_f1 - 1;
+                                                               asic_pll->div_q1 = div_q1;
+
+                                                               asic_pll->range0 = ufx_calc_range(ref_freq0);
+                                                               asic_pll->range1 = ufx_calc_range(ref_freq1);
+
+                                                               if (min_error == 0)
+                                                                       return;
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+}
+
+/* sets analog bit PLL configuration values */
+static int ufx_config_pix_clk(struct ufx_data *dev, u32 pixclock)
+{
+       struct pll_values asic_pll = {0};
+       u32 value, clk_pixel, clk_pixel_pll;
+       int status;
+
+       /* convert pixclock (in ps) to frequency (in Hz) */
+       clk_pixel = PICOS2KHZ(pixclock) * 1000;
+       pr_debug("pixclock %d ps = clk_pixel %d Hz", pixclock, clk_pixel);
+
+       /* clk_pixel = 1/2 clk_pixel_pll */
+       clk_pixel_pll = clk_pixel * 2;
+
+       ufx_calc_pll_values(clk_pixel_pll, &asic_pll);
+
+       /* Keep BYPASS and RESET signals asserted until configured */
+       status = ufx_reg_write(dev, 0x7000, 0x8000000F);
+       check_warn_return(status, "error writing 0x7000");
+
+       value = (asic_pll.div_f1 | (asic_pll.div_r1 << 8) |
+               (asic_pll.div_q1 << 16) | (asic_pll.range1 << 20));
+       status = ufx_reg_write(dev, 0x7008, value);
+       check_warn_return(status, "error writing 0x7008");
+
+       value = (asic_pll.div_f0 | (asic_pll.div_r0 << 8) |
+               (asic_pll.div_q0 << 16) | (asic_pll.range0 << 20));
+       status = ufx_reg_write(dev, 0x7004, value);
+       check_warn_return(status, "error writing 0x7004");
+
+       status = ufx_reg_clear_bits(dev, 0x7000, 0x00000005);
+       check_warn_return(status,
+               "error clearing PLL0 bypass bits in 0x7000");
+       msleep(1);
+
+       status = ufx_reg_clear_bits(dev, 0x7000, 0x0000000A);
+       check_warn_return(status,
+               "error clearing PLL1 bypass bits in 0x7000");
+       msleep(1);
+
+       status = ufx_reg_clear_bits(dev, 0x7000, 0x80000000);
+       check_warn_return(status, "error clearing gate bits in 0x7000");
+
+       return 0;
+}
+
+static int ufx_set_vid_mode(struct ufx_data *dev, struct fb_var_screeninfo *var)
+{
+       u32 temp;
+       u16 h_total, h_active, h_blank_start, h_blank_end, h_sync_start, h_sync_end;
+       u16 v_total, v_active, v_blank_start, v_blank_end, v_sync_start, v_sync_end;
+
+       int status = ufx_reg_write(dev, 0x8028, 0);
+       check_warn_return(status, "ufx_set_vid_mode error disabling RGB pad");
+
+       status = ufx_reg_write(dev, 0x8024, 0);
+       check_warn_return(status, "ufx_set_vid_mode error disabling VDAC");
+
+       /* shut everything down before changing timing */
+       status = ufx_blank(dev, true);
+       check_warn_return(status, "ufx_set_vid_mode error blanking display");
+
+       status = ufx_disable(dev, true);
+       check_warn_return(status, "ufx_set_vid_mode error disabling display");
+
+       status = ufx_config_pix_clk(dev, var->pixclock);
+       check_warn_return(status, "ufx_set_vid_mode error configuring pixclock");
+
+       status = ufx_reg_write(dev, 0x2000, 0x00000104);
+       check_warn_return(status, "ufx_set_vid_mode error writing 0x2000");
+
+       /* set horizontal timings */
+       h_total = var->xres + var->right_margin + var->hsync_len + var->left_margin;
+       h_active = var->xres;
+       h_blank_start = var->xres + var->right_margin;
+       h_blank_end = var->xres + var->right_margin + var->hsync_len;
+       h_sync_start = var->xres + var->right_margin;
+       h_sync_end = var->xres + var->right_margin + var->hsync_len;
+
+       temp = ((h_total - 1) << 16) | (h_active - 1);
+       status = ufx_reg_write(dev, 0x2008, temp);
+       check_warn_return(status, "ufx_set_vid_mode error writing 0x2008");
+
+       temp = ((h_blank_start - 1) << 16) | (h_blank_end - 1);
+       status = ufx_reg_write(dev, 0x200C, temp);
+       check_warn_return(status, "ufx_set_vid_mode error writing 0x200C");
+
+       temp = ((h_sync_start - 1) << 16) | (h_sync_end - 1);
+       status = ufx_reg_write(dev, 0x2010, temp);
+       check_warn_return(status, "ufx_set_vid_mode error writing 0x2010");
+
+       /* set vertical timings */
+       v_total = var->upper_margin + var->yres + var->lower_margin + var->vsync_len;
+       v_active = var->yres;
+       v_blank_start = var->yres + var->lower_margin;
+       v_blank_end = var->yres + var->lower_margin + var->vsync_len;
+       v_sync_start = var->yres + var->lower_margin;
+       v_sync_end = var->yres + var->lower_margin + var->vsync_len;
+
+       temp = ((v_total - 1) << 16) | (v_active - 1);
+       status = ufx_reg_write(dev, 0x2014, temp);
+       check_warn_return(status, "ufx_set_vid_mode error writing 0x2014");
+
+       temp = ((v_blank_start - 1) << 16) | (v_blank_end - 1);
+       status = ufx_reg_write(dev, 0x2018, temp);
+       check_warn_return(status, "ufx_set_vid_mode error writing 0x2018");
+
+       temp = ((v_sync_start - 1) << 16) | (v_sync_end - 1);
+       status = ufx_reg_write(dev, 0x201C, temp);
+       check_warn_return(status, "ufx_set_vid_mode error writing 0x201C");
+
+       status = ufx_reg_write(dev, 0x2020, 0x00000000);
+       check_warn_return(status, "ufx_set_vid_mode error writing 0x2020");
+
+       status = ufx_reg_write(dev, 0x2024, 0x00000000);
+       check_warn_return(status, "ufx_set_vid_mode error writing 0x2024");
+
+       /* Set the frame length register (#pix * 2 bytes/pixel) */
+       temp = var->xres * var->yres * 2;
+       temp = (temp + 7) & (~0x7);
+       status = ufx_reg_write(dev, 0x2028, temp);
+       check_warn_return(status, "ufx_set_vid_mode error writing 0x2028");
+
+       /* enable desired output interface & disable others */
+       status = ufx_reg_write(dev, 0x2040, 0);
+       check_warn_return(status, "ufx_set_vid_mode error writing 0x2040");
+
+       status = ufx_reg_write(dev, 0x2044, 0);
+       check_warn_return(status, "ufx_set_vid_mode error writing 0x2044");
+
+       status = ufx_reg_write(dev, 0x2048, 0);
+       check_warn_return(status, "ufx_set_vid_mode error writing 0x2048");
+
+       /* set the sync polarities & enable bit */
+       temp = 0x00000001;
+       if (var->sync & FB_SYNC_HOR_HIGH_ACT)
+               temp |= 0x00000010;
+
+       if (var->sync & FB_SYNC_VERT_HIGH_ACT)
+               temp |= 0x00000008;
+
+       status = ufx_reg_write(dev, 0x2040, temp);
+       check_warn_return(status, "ufx_set_vid_mode error writing 0x2040");
+
+       /* start everything back up */
+       status = ufx_enable(dev, true);
+       check_warn_return(status, "ufx_set_vid_mode error enabling display");
+
+       /* Unblank the display */
+       status = ufx_unblank(dev, true);
+       check_warn_return(status, "ufx_set_vid_mode error unblanking display");
+
+       /* enable RGB pad */
+       status = ufx_reg_write(dev, 0x8028, 0x00000003);
+       check_warn_return(status, "ufx_set_vid_mode error enabling RGB pad");
+
+       /* enable VDAC */
+       status = ufx_reg_write(dev, 0x8024, 0x00000007);
+       check_warn_return(status, "ufx_set_vid_mode error enabling VDAC");
+
+       return 0;
+}
+
+static int ufx_ops_mmap(struct fb_info *info, struct vm_area_struct *vma)
+{
+       unsigned long start = vma->vm_start;
+       unsigned long size = vma->vm_end - vma->vm_start;
+       unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
+       unsigned long page, pos;
+
+       if (offset + size > info->fix.smem_len)
+               return -EINVAL;
+
+       pos = (unsigned long)info->fix.smem_start + offset;
+
+       pr_debug("mmap() framebuffer addr:%lu size:%lu\n",
+                 pos, size);
+
+       while (size > 0) {
+               page = vmalloc_to_pfn((void *)pos);
+               if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED))
+                       return -EAGAIN;
+
+               start += PAGE_SIZE;
+               pos += PAGE_SIZE;
+               if (size > PAGE_SIZE)
+                       size -= PAGE_SIZE;
+               else
+                       size = 0;
+       }
+
+       vma->vm_flags |= VM_RESERVED;   /* avoid to swap out this VMA */
+       return 0;
+}
+
+static void ufx_raw_rect(struct ufx_data *dev, u16 *cmd, int x, int y,
+       int width, int height)
+{
+       size_t packed_line_len = ALIGN((width * 2), 4);
+       size_t packed_rect_len = packed_line_len * height;
+       int line;
+
+       BUG_ON(!dev);
+       BUG_ON(!dev->info);
+
+       /* command word */
+       *((u32 *)&cmd[0]) = cpu_to_le32(0x01);
+
+       /* length word */
+       *((u32 *)&cmd[2]) = cpu_to_le32(packed_rect_len + 16);
+
+       cmd[4] = cpu_to_le16(x);
+       cmd[5] = cpu_to_le16(y);
+       cmd[6] = cpu_to_le16(width);
+       cmd[7] = cpu_to_le16(height);
+
+       /* frame base address */
+       *((u32 *)&cmd[8]) = cpu_to_le32(0);
+
+       /* color mode and horizontal resolution */
+       cmd[10] = cpu_to_le16(0x4000 | dev->info->var.xres);
+
+       /* vertical resolution */
+       cmd[11] = cpu_to_le16(dev->info->var.yres);
+
+       /* packed data */
+       for (line = 0; line < height; line++) {
+               const int line_offset = dev->info->fix.line_length * (y + line);
+               const int byte_offset = line_offset + (x * BPP);
+               memcpy(&cmd[(24 + (packed_line_len * line)) / 2],
+                       (char *)dev->info->fix.smem_start + byte_offset, width * BPP);
+       }
+}
+
+int ufx_handle_damage(struct ufx_data *dev, int x, int y,
+       int width, int height)
+{
+       size_t packed_line_len = ALIGN((width * 2), 4);
+       int len, status, urb_lines, start_line = 0;
+
+       if ((width <= 0) || (height <= 0) ||
+           (x + width > dev->info->var.xres) ||
+           (y + height > dev->info->var.yres))
+               return -EINVAL;
+
+       if (!atomic_read(&dev->usb_active))
+               return 0;
+
+       while (start_line < height) {
+               struct urb *urb = ufx_get_urb(dev);
+               if (!urb) {
+                       pr_warn("ufx_handle_damage unable to get urb");
+                       return 0;
+               }
+
+               /* assume we have enough space to transfer at least one line */
+               BUG_ON(urb->transfer_buffer_length < (24 + (width * 2)));
+
+               /* calculate the maximum number of lines we could fit in */
+               urb_lines = (urb->transfer_buffer_length - 24) / packed_line_len;
+
+               /* but we might not need this many */
+               urb_lines = min(urb_lines, (height - start_line));
+
+               memset(urb->transfer_buffer, 0, urb->transfer_buffer_length);
+
+               ufx_raw_rect(dev, urb->transfer_buffer, x, (y + start_line), width, urb_lines);
+               len = 24 + (packed_line_len * urb_lines);
+
+               status = ufx_submit_urb(dev, urb, len);
+               check_warn_return(status, "Error submitting URB");
+
+               start_line += urb_lines;
+       }
+
+       return 0;
+}
+
+/* Path triggered by usermode clients who write to filesystem
+ * e.g. cat filename > /dev/fb1
+ * Not used by X Windows or text-mode console. But useful for testing.
+ * Slow because of extra copy and we must assume all pixels dirty. */
+static ssize_t ufx_ops_write(struct fb_info *info, const char __user *buf,
+                         size_t count, loff_t *ppos)
+{
+       ssize_t result;
+       struct ufx_data *dev = info->par;
+       u32 offset = (u32) *ppos;
+
+       result = fb_sys_write(info, buf, count, ppos);
+
+       if (result > 0) {
+               int start = max((int)(offset / info->fix.line_length) - 1, 0);
+               int lines = min((u32)((result / info->fix.line_length) + 1),
+                               (u32)info->var.yres);
+
+               ufx_handle_damage(dev, 0, start, info->var.xres, lines);
+       }
+
+       return result;
+}
+
+static void ufx_ops_copyarea(struct fb_info *info,
+                               const struct fb_copyarea *area)
+{
+
+       struct ufx_data *dev = info->par;
+
+       sys_copyarea(info, area);
+
+       ufx_handle_damage(dev, area->dx, area->dy,
+                       area->width, area->height);
+}
+
+static void ufx_ops_imageblit(struct fb_info *info,
+                               const struct fb_image *image)
+{
+       struct ufx_data *dev = info->par;
+
+       sys_imageblit(info, image);
+
+       ufx_handle_damage(dev, image->dx, image->dy,
+                       image->width, image->height);
+}
+
+static void ufx_ops_fillrect(struct fb_info *info,
+                         const struct fb_fillrect *rect)
+{
+       struct ufx_data *dev = info->par;
+
+       sys_fillrect(info, rect);
+
+       ufx_handle_damage(dev, rect->dx, rect->dy, rect->width,
+                             rect->height);
+}
+
+/* NOTE: fb_defio.c is holding info->fbdefio.mutex
+ *   Touching ANY framebuffer memory that triggers a page fault
+ *   in fb_defio will cause a deadlock, when it also tries to
+ *   grab the same mutex. */
+static void ufx_dpy_deferred_io(struct fb_info *info,
+                               struct list_head *pagelist)
+{
+       struct page *cur;
+       struct fb_deferred_io *fbdefio = info->fbdefio;
+       struct ufx_data *dev = info->par;
+
+       if (!fb_defio)
+               return;
+
+       if (!atomic_read(&dev->usb_active))
+               return;
+
+       /* walk the written page list and render each to device */
+       list_for_each_entry(cur, &fbdefio->pagelist, lru) {
+               /* create a rectangle of full screen width that encloses the
+                * entire dirty framebuffer page */
+               const int x = 0;
+               const int width = dev->info->var.xres;
+               const int y = (cur->index << PAGE_SHIFT) / (width * 2);
+               int height = (PAGE_SIZE / (width * 2)) + 1;
+               height = min(height, (int)(dev->info->var.yres - y));
+
+               BUG_ON(y >= dev->info->var.yres);
+               BUG_ON((y + height) > dev->info->var.yres);
+
+               ufx_handle_damage(dev, x, y, width, height);
+       }
+}
+
+static int ufx_ops_ioctl(struct fb_info *info, unsigned int cmd,
+                        unsigned long arg)
+{
+       struct ufx_data *dev = info->par;
+       struct dloarea *area = NULL;
+
+       if (!atomic_read(&dev->usb_active))
+               return 0;
+
+       /* TODO: Update X server to get this from sysfs instead */
+       if (cmd == UFX_IOCTL_RETURN_EDID) {
+               u8 __user *edid = (u8 __user *)arg;
+               if (copy_to_user(edid, dev->edid, dev->edid_size))
+                       return -EFAULT;
+               return 0;
+       }
+
+       /* TODO: Help propose a standard fb.h ioctl to report mmap damage */
+       if (cmd == UFX_IOCTL_REPORT_DAMAGE) {
+               /* If we have a damage-aware client, turn fb_defio "off"
+                * To avoid perf imact of unecessary page fault handling.
+                * Done by resetting the delay for this fb_info to a very
+                * long period. Pages will become writable and stay that way.
+                * Reset to normal value when all clients have closed this fb.
+                */
+               if (info->fbdefio)
+                       info->fbdefio->delay = UFX_DEFIO_WRITE_DISABLE;
+
+               area = (struct dloarea *)arg;
+
+               if (area->x < 0)
+                       area->x = 0;
+
+               if (area->x > info->var.xres)
+                       area->x = info->var.xres;
+
+               if (area->y < 0)
+                       area->y = 0;
+
+               if (area->y > info->var.yres)
+                       area->y = info->var.yres;
+
+               ufx_handle_damage(dev, area->x, area->y, area->w, area->h);
+       }
+
+       return 0;
+}
+
+/* taken from vesafb */
+static int
+ufx_ops_setcolreg(unsigned regno, unsigned red, unsigned green,
+              unsigned blue, unsigned transp, struct fb_info *info)
+{
+       int err = 0;
+
+       if (regno >= info->cmap.len)
+               return 1;
+
+       if (regno < 16) {
+               if (info->var.red.offset == 10) {
+                       /* 1:5:5:5 */
+                       ((u32 *) (info->pseudo_palette))[regno] =
+                           ((red & 0xf800) >> 1) |
+                           ((green & 0xf800) >> 6) | ((blue & 0xf800) >> 11);
+               } else {
+                       /* 0:5:6:5 */
+                       ((u32 *) (info->pseudo_palette))[regno] =
+                           ((red & 0xf800)) |
+                           ((green & 0xfc00) >> 5) | ((blue & 0xf800) >> 11);
+               }
+       }
+
+       return err;
+}
+
+/* It's common for several clients to have framebuffer open simultaneously.
+ * e.g. both fbcon and X. Makes things interesting.
+ * Assumes caller is holding info->lock (for open and release at least) */
+static int ufx_ops_open(struct fb_info *info, int user)
+{
+       struct ufx_data *dev = info->par;
+
+       /* fbcon aggressively connects to first framebuffer it finds,
+        * preventing other clients (X) from working properly. Usually
+        * not what the user wants. Fail by default with option to enable. */
+       if (user == 0 && !console)
+               return -EBUSY;
+
+       /* If the USB device is gone, we don't accept new opens */
+       if (dev->virtualized)
+               return -ENODEV;
+
+       dev->fb_count++;
+
+       kref_get(&dev->kref);
+
+       if (fb_defio && (info->fbdefio == NULL)) {
+               /* enable defio at last moment if not disabled by client */
+
+               struct fb_deferred_io *fbdefio;
+
+               fbdefio = kmalloc(sizeof(struct fb_deferred_io), GFP_KERNEL);
+
+               if (fbdefio) {
+                       fbdefio->delay = UFX_DEFIO_WRITE_DELAY;
+                       fbdefio->deferred_io = ufx_dpy_deferred_io;
+               }
+
+               info->fbdefio = fbdefio;
+               fb_deferred_io_init(info);
+       }
+
+       pr_debug("open /dev/fb%d user=%d fb_info=%p count=%d",
+               info->node, user, info, dev->fb_count);
+
+       return 0;
+}
+
+/*
+ * Called when all client interfaces to start transactions have been disabled,
+ * and all references to our device instance (ufx_data) are released.
+ * Every transaction must have a reference, so we know are fully spun down
+ */
+static void ufx_free(struct kref *kref)
+{
+       struct ufx_data *dev = container_of(kref, struct ufx_data, kref);
+
+       /* this function will wait for all in-flight urbs to complete */
+       if (dev->urbs.count > 0)
+               ufx_free_urb_list(dev);
+
+       pr_debug("freeing ufx_data %p", dev);
+
+       kfree(dev);
+}
+
+static void ufx_release_urb_work(struct work_struct *work)
+{
+       struct urb_node *unode = container_of(work, struct urb_node,
+                                             release_urb_work.work);
+
+       up(&unode->dev->urbs.limit_sem);
+}
+
+static void ufx_free_framebuffer_work(struct work_struct *work)
+{
+       struct ufx_data *dev = container_of(work, struct ufx_data,
+                                           free_framebuffer_work.work);
+       struct fb_info *info = dev->info;
+       int node = info->node;
+
+       unregister_framebuffer(info);
+
+       if (info->cmap.len != 0)
+               fb_dealloc_cmap(&info->cmap);
+       if (info->monspecs.modedb)
+               fb_destroy_modedb(info->monspecs.modedb);
+       if (info->screen_base)
+               vfree(info->screen_base);
+
+       fb_destroy_modelist(&info->modelist);
+
+       dev->info = 0;
+
+       /* Assume info structure is freed after this point */
+       framebuffer_release(info);
+
+       pr_debug("fb_info for /dev/fb%d has been freed", node);
+
+       /* ref taken in probe() as part of registering framebfufer */
+       kref_put(&dev->kref, ufx_free);
+}
+
+/*
+ * Assumes caller is holding info->lock mutex (for open and release at least)
+ */
+static int ufx_ops_release(struct fb_info *info, int user)
+{
+       struct ufx_data *dev = info->par;
+
+       dev->fb_count--;
+
+       /* We can't free fb_info here - fbmem will touch it when we return */
+       if (dev->virtualized && (dev->fb_count == 0))
+               schedule_delayed_work(&dev->free_framebuffer_work, HZ);
+
+       if ((dev->fb_count == 0) && (info->fbdefio)) {
+               fb_deferred_io_cleanup(info);
+               kfree(info->fbdefio);
+               info->fbdefio = NULL;
+               info->fbops->fb_mmap = ufx_ops_mmap;
+       }
+
+       pr_debug("released /dev/fb%d user=%d count=%d",
+                 info->node, user, dev->fb_count);
+
+       kref_put(&dev->kref, ufx_free);
+
+       return 0;
+}
+
+/* Check whether a video mode is supported by the chip
+ * We start from monitor's modes, so don't need to filter that here */
+static int ufx_is_valid_mode(struct fb_videomode *mode,
+               struct fb_info *info)
+{
+       if ((mode->xres * mode->yres) > (2048 * 1152)) {
+               pr_debug("%dx%d too many pixels",
+                      mode->xres, mode->yres);
+               return 0;
+       }
+
+       if (mode->pixclock < 5000) {
+               pr_debug("%dx%d %dps pixel clock too fast",
+                      mode->xres, mode->yres, mode->pixclock);
+               return 0;
+       }
+
+       pr_debug("%dx%d (pixclk %dps %dMHz) valid mode", mode->xres, mode->yres,
+               mode->pixclock, (1000000 / mode->pixclock));
+       return 1;
+}
+
+static void ufx_var_color_format(struct fb_var_screeninfo *var)
+{
+       const struct fb_bitfield red = { 11, 5, 0 };
+       const struct fb_bitfield green = { 5, 6, 0 };
+       const struct fb_bitfield blue = { 0, 5, 0 };
+
+       var->bits_per_pixel = 16;
+       var->red = red;
+       var->green = green;
+       var->blue = blue;
+}
+
+static int ufx_ops_check_var(struct fb_var_screeninfo *var,
+                               struct fb_info *info)
+{
+       struct fb_videomode mode;
+
+       /* TODO: support dynamically changing framebuffer size */
+       if ((var->xres * var->yres * 2) > info->fix.smem_len)
+               return -EINVAL;
+
+       /* set device-specific elements of var unrelated to mode */
+       ufx_var_color_format(var);
+
+       fb_var_to_videomode(&mode, var);
+
+       if (!ufx_is_valid_mode(&mode, info))
+               return -EINVAL;
+
+       return 0;
+}
+
+static int ufx_ops_set_par(struct fb_info *info)
+{
+       struct ufx_data *dev = info->par;
+       int result;
+       u16 *pix_framebuffer;
+       int i;
+
+       pr_debug("set_par mode %dx%d", info->var.xres, info->var.yres);
+       result = ufx_set_vid_mode(dev, &info->var);
+
+       if ((result == 0) && (dev->fb_count == 0)) {
+               /* paint greenscreen */
+               pix_framebuffer = (u16 *) info->screen_base;
+               for (i = 0; i < info->fix.smem_len / 2; i++)
+                       pix_framebuffer[i] = 0x37e6;
+
+               ufx_handle_damage(dev, 0, 0, info->var.xres, info->var.yres);
+       }
+
+       /* re-enable defio if previously disabled by damage tracking */
+       if (info->fbdefio)
+               info->fbdefio->delay = UFX_DEFIO_WRITE_DELAY;
+
+       return result;
+}
+
+/* In order to come back from full DPMS off, we need to set the mode again */
+static int ufx_ops_blank(int blank_mode, struct fb_info *info)
+{
+       struct ufx_data *dev = info->par;
+       ufx_set_vid_mode(dev, &info->var);
+       return 0;
+}
+
+static struct fb_ops ufx_ops = {
+       .owner = THIS_MODULE,
+       .fb_read = fb_sys_read,
+       .fb_write = ufx_ops_write,
+       .fb_setcolreg = ufx_ops_setcolreg,
+       .fb_fillrect = ufx_ops_fillrect,
+       .fb_copyarea = ufx_ops_copyarea,
+       .fb_imageblit = ufx_ops_imageblit,
+       .fb_mmap = ufx_ops_mmap,
+       .fb_ioctl = ufx_ops_ioctl,
+       .fb_open = ufx_ops_open,
+       .fb_release = ufx_ops_release,
+       .fb_blank = ufx_ops_blank,
+       .fb_check_var = ufx_ops_check_var,
+       .fb_set_par = ufx_ops_set_par,
+};
+
+/* Assumes &info->lock held by caller
+ * Assumes no active clients have framebuffer open */
+static int ufx_realloc_framebuffer(struct ufx_data *dev, struct fb_info *info)
+{
+       int retval = -ENOMEM;
+       int old_len = info->fix.smem_len;
+       int new_len;
+       unsigned char *old_fb = info->screen_base;
+       unsigned char *new_fb;
+
+       pr_debug("Reallocating framebuffer. Addresses will change!");
+
+       new_len = info->fix.line_length * info->var.yres;
+
+       if (PAGE_ALIGN(new_len) > old_len) {
+               /*
+                * Alloc system memory for virtual framebuffer
+                */
+               new_fb = vmalloc(new_len);
+               if (!new_fb) {
+                       pr_err("Virtual framebuffer alloc failed");
+                       goto error;
+               }
+
+               if (info->screen_base) {
+                       memcpy(new_fb, old_fb, old_len);
+                       vfree(info->screen_base);
+               }
+
+               info->screen_base = new_fb;
+               info->fix.smem_len = PAGE_ALIGN(new_len);
+               info->fix.smem_start = (unsigned long) new_fb;
+               info->flags = smscufx_info_flags;
+       }
+
+       retval = 0;
+
+error:
+       return retval;
+}
+
+/* sets up I2C Controller for 100 Kbps, std. speed, 7-bit addr, master,
+ * restart enabled, but no start byte, enable controller */
+static int ufx_i2c_init(struct ufx_data *dev)
+{
+       u32 tmp;
+
+       /* disable the controller before it can be reprogrammed */
+       int status = ufx_reg_write(dev, 0x106C, 0x00);
+       check_warn_return(status, "failed to disable I2C");
+
+       /* Setup the clock count registers
+        * (12+1) = 13 clks @ 2.5 MHz = 5.2 uS */
+       status = ufx_reg_write(dev, 0x1018, 12);
+       check_warn_return(status, "error writing 0x1018");
+
+       /* (6+8) = 14 clks @ 2.5 MHz = 5.6 uS */
+       status = ufx_reg_write(dev, 0x1014, 6);
+       check_warn_return(status, "error writing 0x1014");
+
+       status = ufx_reg_read(dev, 0x1000, &tmp);
+       check_warn_return(status, "error reading 0x1000");
+
+       /* set speed to std mode */
+       tmp &= ~(0x06);
+       tmp |= 0x02;
+
+       /* 7-bit (not 10-bit) addressing */
+       tmp &= ~(0x10);
+
+       /* enable restart conditions and master mode */
+       tmp |= 0x21;
+
+       status = ufx_reg_write(dev, 0x1000, tmp);
+       check_warn_return(status, "error writing 0x1000");
+
+       /* Set normal tx using target address 0 */
+       status = ufx_reg_clear_and_set_bits(dev, 0x1004, 0xC00, 0x000);
+       check_warn_return(status, "error setting TX mode bits in 0x1004");
+
+       /* Enable the controller */
+       status = ufx_reg_write(dev, 0x106C, 0x01);
+       check_warn_return(status, "failed to enable I2C");
+
+       return 0;
+}
+
+/* sets the I2C port mux and target address */
+static int ufx_i2c_configure(struct ufx_data *dev)
+{
+       int status = ufx_reg_write(dev, 0x106C, 0x00);
+       check_warn_return(status, "failed to disable I2C");
+
+       status = ufx_reg_write(dev, 0x3010, 0x00000000);
+       check_warn_return(status, "failed to write 0x3010");
+
+       /* A0h is std for any EDID, right shifted by one */
+       status = ufx_reg_clear_and_set_bits(dev, 0x1004, 0x3FF, (0xA0 >> 1));
+       check_warn_return(status, "failed to set TAR bits in 0x1004");
+
+       status = ufx_reg_write(dev, 0x106C, 0x01);
+       check_warn_return(status, "failed to enable I2C");
+
+       return 0;
+}
+
+/* wait for BUSY to clear, with a timeout of 50ms with 10ms sleeps. if no
+ * monitor is connected, there is no error except for timeout */
+static int ufx_i2c_wait_busy(struct ufx_data *dev)
+{
+       u32 tmp;
+       int i, status;
+
+       for (i = 0; i < 15; i++) {
+               status = ufx_reg_read(dev, 0x1100, &tmp);
+               check_warn_return(status, "0x1100 read failed");
+
+               /* if BUSY is clear, check for error */
+               if ((tmp & 0x80000000) == 0) {
+                       if (tmp & 0x20000000) {
+                               pr_warn("I2C read failed, 0x1100=0x%08x", tmp);
+                               return -EIO;
+                       }
+
+                       return 0;
+               }
+
+               /* perform the first 10 retries without delay */
+               if (i >= 10)
+                       msleep(10);
+       }
+
+       pr_warn("I2C access timed out, resetting I2C hardware");
+       status =  ufx_reg_write(dev, 0x1100, 0x40000000);
+       check_warn_return(status, "0x1100 write failed");
+
+       return -ETIMEDOUT;
+}
+
+/* reads a 128-byte EDID block from the currently selected port and TAR */
+static int ufx_read_edid(struct ufx_data *dev, u8 *edid, int edid_len)
+{
+       int i, j, status;
+       u32 *edid_u32 = (u32 *)edid;
+
+       BUG_ON(edid_len != EDID_LENGTH);
+
+       status = ufx_i2c_configure(dev);
+       if (status < 0) {
+               pr_err("ufx_i2c_configure failed");
+               return status;
+       }
+
+       memset(edid, 0xff, EDID_LENGTH);
+
+       /* Read the 128-byte EDID as 2 bursts of 64 bytes */
+       for (i = 0; i < 2; i++) {
+               u32 temp = 0x28070000 | (63 << 20) | (((u32)(i * 64)) << 8);
+               status = ufx_reg_write(dev, 0x1100, temp);
+               check_warn_return(status, "Failed to write 0x1100");
+
+               temp |= 0x80000000;
+               status = ufx_reg_write(dev, 0x1100, temp);
+               check_warn_return(status, "Failed to write 0x1100");
+
+               status = ufx_i2c_wait_busy(dev);
+               check_warn_return(status, "Timeout waiting for I2C BUSY to clear");
+
+               for (j = 0; j < 16; j++) {
+                       u32 data_reg_addr = 0x1110 + (j * 4);
+                       status = ufx_reg_read(dev, data_reg_addr, edid_u32++);
+                       check_warn_return(status, "Error reading i2c data");
+               }
+       }
+
+       /* all FF's in the first 16 bytes indicates nothing is connected */
+       for (i = 0; i < 16; i++) {
+               if (edid[i] != 0xFF) {
+                       pr_debug("edid data read succesfully");
+                       return EDID_LENGTH;
+               }
+       }
+
+       pr_warn("edid data contains all 0xff");
+       return -ETIMEDOUT;
+}
+
+/* 1) use sw default
+ * 2) Parse into various fb_info structs
+ * 3) Allocate virtual framebuffer memory to back highest res mode
+ *
+ * Parses EDID into three places used by various parts of fbdev:
+ * fb_var_screeninfo contains the timing of the monitor's preferred mode
+ * fb_info.monspecs is full parsed EDID info, including monspecs.modedb
+ * fb_info.modelist is a linked list of all monitor & VESA modes which work
+ *
+ * If EDID is not readable/valid, then modelist is all VESA modes,
+ * monspecs is NULL, and fb_var_screeninfo is set to safe VESA mode
+ * Returns 0 if successful */
+static int ufx_setup_modes(struct ufx_data *dev, struct fb_info *info,
+       char *default_edid, size_t default_edid_size)
+{
+       const struct fb_videomode *default_vmode = NULL;
+       u8 *edid;
+       int i, result = 0, tries = 3;
+
+       if (info->dev) /* only use mutex if info has been registered */
+               mutex_lock(&info->lock);
+
+       edid = kmalloc(EDID_LENGTH, GFP_KERNEL);
+       if (!edid) {
+               result = -ENOMEM;
+               goto error;
+       }
+
+       fb_destroy_modelist(&info->modelist);
+       memset(&info->monspecs, 0, sizeof(info->monspecs));
+
+       /* Try to (re)read EDID from hardware first
+        * EDID data may return, but not parse as valid
+        * Try again a few times, in case of e.g. analog cable noise */
+       while (tries--) {
+               i = ufx_read_edid(dev, edid, EDID_LENGTH);
+
+               if (i >= EDID_LENGTH)
+                       fb_edid_to_monspecs(edid, &info->monspecs);
+
+               if (info->monspecs.modedb_len > 0) {
+                       dev->edid = edid;
+                       dev->edid_size = i;
+                       break;
+               }
+       }
+
+       /* If that fails, use a previously returned EDID if available */
+       if (info->monspecs.modedb_len == 0) {
+               pr_err("Unable to get valid EDID from device/display\n");
+
+               if (dev->edid) {
+                       fb_edid_to_monspecs(dev->edid, &info->monspecs);
+                       if (info->monspecs.modedb_len > 0)
+                               pr_err("Using previously queried EDID\n");
+               }
+       }
+
+       /* If that fails, use the default EDID we were handed */
+       if (info->monspecs.modedb_len == 0) {
+               if (default_edid_size >= EDID_LENGTH) {
+                       fb_edid_to_monspecs(default_edid, &info->monspecs);
+                       if (info->monspecs.modedb_len > 0) {
+                               memcpy(edid, default_edid, default_edid_size);
+                               dev->edid = edid;
+                               dev->edid_size = default_edid_size;
+                               pr_err("Using default/backup EDID\n");
+                       }
+               }
+       }
+
+       /* If we've got modes, let's pick a best default mode */
+       if (info->monspecs.modedb_len > 0) {
+
+               for (i = 0; i < info->monspecs.modedb_len; i++) {
+                       if (ufx_is_valid_mode(&info->monspecs.modedb[i], info))
+                               fb_add_videomode(&info->monspecs.modedb[i],
+                                       &info->modelist);
+                       else /* if we've removed top/best mode */
+                               info->monspecs.misc &= ~FB_MISC_1ST_DETAIL;
+               }
+
+               default_vmode = fb_find_best_display(&info->monspecs,
+                                                    &info->modelist);
+       }
+
+       /* If everything else has failed, fall back to safe default mode */
+       if (default_vmode == NULL) {
+
+               struct fb_videomode fb_vmode = {0};
+
+               /* Add the standard VESA modes to our modelist
+                * Since we don't have EDID, there may be modes that
+                * overspec monitor and/or are incorrect aspect ratio, etc.
+                * But at least the user has a chance to choose
+                */
+               for (i = 0; i < VESA_MODEDB_SIZE; i++) {
+                       if (ufx_is_valid_mode((struct fb_videomode *)
+                                               &vesa_modes[i], info))
+                               fb_add_videomode(&vesa_modes[i],
+                                                &info->modelist);
+               }
+
+               /* default to resolution safe for projectors
+                * (since they are most common case without EDID)
+                */
+               fb_vmode.xres = 800;
+               fb_vmode.yres = 600;
+               fb_vmode.refresh = 60;
+               default_vmode = fb_find_nearest_mode(&fb_vmode,
+                                                    &info->modelist);
+       }
+
+       /* If we have good mode and no active clients */
+       if ((default_vmode != NULL) && (dev->fb_count == 0)) {
+
+               fb_videomode_to_var(&info->var, default_vmode);
+               ufx_var_color_format(&info->var);
+
+               /* with mode size info, we can now alloc our framebuffer */
+               memcpy(&info->fix, &ufx_fix, sizeof(ufx_fix));
+               info->fix.line_length = info->var.xres *
+                       (info->var.bits_per_pixel / 8);
+
+               result = ufx_realloc_framebuffer(dev, info);
+
+       } else
+               result = -EINVAL;
+
+error:
+       if (edid && (dev->edid != edid))
+               kfree(edid);
+
+       if (info->dev)
+               mutex_unlock(&info->lock);
+
+       return result;
+}
+
+static int ufx_usb_probe(struct usb_interface *interface,
+                       const struct usb_device_id *id)
+{
+       struct usb_device *usbdev;
+       struct ufx_data *dev;
+       struct fb_info *info = 0;
+       int retval = -ENOMEM;
+       u32 id_rev, fpga_rev;
+
+       /* usb initialization */
+       usbdev = interface_to_usbdev(interface);
+       BUG_ON(!usbdev);
+
+       dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+       if (dev == NULL) {
+               dev_err(&usbdev->dev, "ufx_usb_probe: failed alloc of dev struct\n");
+               goto error;
+       }
+
+       /* we need to wait for both usb and fbdev to spin down on disconnect */
+       kref_init(&dev->kref); /* matching kref_put in usb .disconnect fn */
+       kref_get(&dev->kref); /* matching kref_put in free_framebuffer_work */
+
+       dev->udev = usbdev;
+       dev->gdev = &usbdev->dev; /* our generic struct device * */
+       usb_set_intfdata(interface, dev);
+
+       dev_dbg(dev->gdev, "%s %s - serial #%s\n",
+               usbdev->manufacturer, usbdev->product, usbdev->serial);
+       dev_dbg(dev->gdev, "vid_%04x&pid_%04x&rev_%04x driver's ufx_data struct at %p\n",
+               usbdev->descriptor.idVendor, usbdev->descriptor.idProduct,
+               usbdev->descriptor.bcdDevice, dev);
+       dev_dbg(dev->gdev, "console enable=%d\n", console);
+       dev_dbg(dev->gdev, "fb_defio enable=%d\n", fb_defio);
+
+       if (!ufx_alloc_urb_list(dev, WRITES_IN_FLIGHT, MAX_TRANSFER)) {
+               retval = -ENOMEM;
+               dev_err(dev->gdev, "ufx_alloc_urb_list failed\n");
+               goto error;
+       }
+
+       /* We don't register a new USB class. Our client interface is fbdev */
+
+       /* allocates framebuffer driver structure, not framebuffer memory */
+       info = framebuffer_alloc(0, &usbdev->dev);
+       if (!info) {
+               retval = -ENOMEM;
+               dev_err(dev->gdev, "framebuffer_alloc failed\n");
+               goto error;
+       }
+
+       dev->info = info;
+       info->par = dev;
+       info->pseudo_palette = dev->pseudo_palette;
+       info->fbops = &ufx_ops;
+
+       retval = fb_alloc_cmap(&info->cmap, 256, 0);
+       if (retval < 0) {
+               dev_err(dev->gdev, "fb_alloc_cmap failed %x\n", retval);
+               goto error;
+       }
+
+       INIT_DELAYED_WORK(&dev->free_framebuffer_work,
+                         ufx_free_framebuffer_work);
+
+       INIT_LIST_HEAD(&info->modelist);
+
+       retval = ufx_reg_read(dev, 0x3000, &id_rev);
+       check_warn_goto_error(retval, "error %d reading 0x3000 register from device", retval);
+       dev_dbg(dev->gdev, "ID_REV register value 0x%08x", id_rev);
+
+       retval = ufx_reg_read(dev, 0x3004, &fpga_rev);
+       check_warn_goto_error(retval, "error %d reading 0x3004 register from device", retval);
+       dev_dbg(dev->gdev, "FPGA_REV register value 0x%08x", fpga_rev);
+
+       dev_dbg(dev->gdev, "resetting device");
+       retval = ufx_lite_reset(dev);
+       check_warn_goto_error(retval, "error %d resetting device", retval);
+
+       dev_dbg(dev->gdev, "configuring system clock");
+       retval = ufx_config_sys_clk(dev);
+       check_warn_goto_error(retval, "error %d configuring system clock", retval);
+
+       dev_dbg(dev->gdev, "configuring DDR2 controller");
+       retval = ufx_config_ddr2(dev);
+       check_warn_goto_error(retval, "error %d initialising DDR2 controller", retval);
+
+       dev_dbg(dev->gdev, "configuring I2C controller");
+       retval = ufx_i2c_init(dev);
+       check_warn_goto_error(retval, "error %d initialising I2C controller", retval);
+
+       dev_dbg(dev->gdev, "selecting display mode");
+       retval = ufx_setup_modes(dev, info, NULL, 0);
+       check_warn_goto_error(retval, "unable to find common mode for display and adapter");
+
+       retval = ufx_reg_set_bits(dev, 0x4000, 0x00000001);
+       check_warn_goto_error(retval, "error %d enabling graphics engine", retval);
+
+       /* ready to begin using device */
+       atomic_set(&dev->usb_active, 1);
+
+       dev_dbg(dev->gdev, "checking var");
+       retval = ufx_ops_check_var(&info->var, info);
+       check_warn_goto_error(retval, "error %d ufx_ops_check_var", retval);
+
+       dev_dbg(dev->gdev, "setting par");
+       retval = ufx_ops_set_par(info);
+       check_warn_goto_error(retval, "error %d ufx_ops_set_par", retval);
+
+       dev_dbg(dev->gdev, "registering framebuffer");
+       retval = register_framebuffer(info);
+       check_warn_goto_error(retval, "error %d register_framebuffer", retval);
+
+       dev_info(dev->gdev, "SMSC UDX USB device /dev/fb%d attached. %dx%d resolution."
+               " Using %dK framebuffer memory\n", info->node,
+               info->var.xres, info->var.yres, info->fix.smem_len >> 10);
+
+       return 0;
+
+error:
+       if (dev) {
+               if (info) {
+                       if (info->cmap.len != 0)
+                               fb_dealloc_cmap(&info->cmap);
+                       if (info->monspecs.modedb)
+                               fb_destroy_modedb(info->monspecs.modedb);
+                       if (info->screen_base)
+                               vfree(info->screen_base);
+
+                       fb_destroy_modelist(&info->modelist);
+
+                       framebuffer_release(info);
+               }
+
+               kref_put(&dev->kref, ufx_free); /* ref for framebuffer */
+               kref_put(&dev->kref, ufx_free); /* last ref from kref_init */
+
+               /* dev has been deallocated. Do not dereference */
+       }
+
+       return retval;
+}
+
+static void ufx_usb_disconnect(struct usb_interface *interface)
+{
+       struct ufx_data *dev;
+       struct fb_info *info;
+
+       dev = usb_get_intfdata(interface);
+       info = dev->info;
+
+       pr_debug("USB disconnect starting\n");
+
+       /* we virtualize until all fb clients release. Then we free */
+       dev->virtualized = true;
+
+       /* When non-active we'll update virtual framebuffer, but no new urbs */
+       atomic_set(&dev->usb_active, 0);
+
+       usb_set_intfdata(interface, NULL);
+
+       /* if clients still have us open, will be freed on last close */
+       if (dev->fb_count == 0)
+               schedule_delayed_work(&dev->free_framebuffer_work, 0);
+
+       /* release reference taken by kref_init in probe() */
+       kref_put(&dev->kref, ufx_free);
+
+       /* consider ufx_data freed */
+}
+
+static struct usb_driver ufx_driver = {
+       .name = "smscufx",
+       .probe = ufx_usb_probe,
+       .disconnect = ufx_usb_disconnect,
+       .id_table = id_table,
+};
+
+static int __init ufx_module_init(void)
+{
+       int res;
+
+       res = usb_register(&ufx_driver);
+       if (res)
+               err("usb_register failed. Error number %d", res);
+
+       return res;
+}
+
+static void __exit ufx_module_exit(void)
+{
+       usb_deregister(&ufx_driver);
+}
+
+module_init(ufx_module_init);
+module_exit(ufx_module_exit);
+
+static void ufx_urb_completion(struct urb *urb)
+{
+       struct urb_node *unode = urb->context;
+       struct ufx_data *dev = unode->dev;
+       unsigned long flags;
+
+       /* sync/async unlink faults aren't errors */
+       if (urb->status) {
+               if (!(urb->status == -ENOENT ||
+                   urb->status == -ECONNRESET ||
+                   urb->status == -ESHUTDOWN)) {
+                       pr_err("%s - nonzero write bulk status received: %d\n",
+                               __func__, urb->status);
+                       atomic_set(&dev->lost_pixels, 1);
+               }
+       }
+
+       urb->transfer_buffer_length = dev->urbs.size; /* reset to actual */
+
+       spin_lock_irqsave(&dev->urbs.lock, flags);
+       list_add_tail(&unode->entry, &dev->urbs.list);
+       dev->urbs.available++;
+       spin_unlock_irqrestore(&dev->urbs.lock, flags);
+
+       /* When using fb_defio, we deadlock if up() is called
+        * while another is waiting. So queue to another process */
+       if (fb_defio)
+               schedule_delayed_work(&unode->release_urb_work, 0);
+       else
+               up(&dev->urbs.limit_sem);
+}
+
+static void ufx_free_urb_list(struct ufx_data *dev)
+{
+       int count = dev->urbs.count;
+       struct list_head *node;
+       struct urb_node *unode;
+       struct urb *urb;
+       int ret;
+       unsigned long flags;
+
+       pr_debug("Waiting for completes and freeing all render urbs\n");
+
+       /* keep waiting and freeing, until we've got 'em all */
+       while (count--) {
+               /* Getting interrupted means a leak, but ok at shutdown*/
+               ret = down_interruptible(&dev->urbs.limit_sem);
+               if (ret)
+                       break;
+
+               spin_lock_irqsave(&dev->urbs.lock, flags);
+
+               node = dev->urbs.list.next; /* have reserved one with sem */
+               list_del_init(node);
+
+               spin_unlock_irqrestore(&dev->urbs.lock, flags);
+
+               unode = list_entry(node, struct urb_node, entry);
+               urb = unode->urb;
+
+               /* Free each separately allocated piece */
+               usb_free_coherent(urb->dev, dev->urbs.size,
+                                 urb->transfer_buffer, urb->transfer_dma);
+               usb_free_urb(urb);
+               kfree(node);
+       }
+}
+
+static int ufx_alloc_urb_list(struct ufx_data *dev, int count, size_t size)
+{
+       int i = 0;
+       struct urb *urb;
+       struct urb_node *unode;
+       char *buf;
+
+       spin_lock_init(&dev->urbs.lock);
+
+       dev->urbs.size = size;
+       INIT_LIST_HEAD(&dev->urbs.list);
+
+       while (i < count) {
+               unode = kzalloc(sizeof(struct urb_node), GFP_KERNEL);
+               if (!unode)
+                       break;
+               unode->dev = dev;
+
+               INIT_DELAYED_WORK(&unode->release_urb_work,
+                         ufx_release_urb_work);
+
+               urb = usb_alloc_urb(0, GFP_KERNEL);
+               if (!urb) {
+                       kfree(unode);
+                       break;
+               }
+               unode->urb = urb;
+
+               buf = usb_alloc_coherent(dev->udev, size, GFP_KERNEL,
+                                        &urb->transfer_dma);
+               if (!buf) {
+                       kfree(unode);
+                       usb_free_urb(urb);
+                       break;
+               }
+
+               /* urb->transfer_buffer_length set to actual before submit */
+               usb_fill_bulk_urb(urb, dev->udev, usb_sndbulkpipe(dev->udev, 1),
+                       buf, size, ufx_urb_completion, unode);
+               urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
+
+               list_add_tail(&unode->entry, &dev->urbs.list);
+
+               i++;
+       }
+
+       sema_init(&dev->urbs.limit_sem, i);
+       dev->urbs.count = i;
+       dev->urbs.available = i;
+
+       pr_debug("allocated %d %d byte urbs\n", i, (int) size);
+
+       return i;
+}
+
+static struct urb *ufx_get_urb(struct ufx_data *dev)
+{
+       int ret = 0;
+       struct list_head *entry;
+       struct urb_node *unode;
+       struct urb *urb = NULL;
+       unsigned long flags;
+
+       /* Wait for an in-flight buffer to complete and get re-queued */
+       ret = down_timeout(&dev->urbs.limit_sem, GET_URB_TIMEOUT);
+       if (ret) {
+               atomic_set(&dev->lost_pixels, 1);
+               pr_warn("wait for urb interrupted: %x available: %d\n",
+                      ret, dev->urbs.available);
+               goto error;
+       }
+
+       spin_lock_irqsave(&dev->urbs.lock, flags);
+
+       BUG_ON(list_empty(&dev->urbs.list)); /* reserved one with limit_sem */
+       entry = dev->urbs.list.next;
+       list_del_init(entry);
+       dev->urbs.available--;
+
+       spin_unlock_irqrestore(&dev->urbs.lock, flags);
+
+       unode = list_entry(entry, struct urb_node, entry);
+       urb = unode->urb;
+
+error:
+       return urb;
+}
+
+static int ufx_submit_urb(struct ufx_data *dev, struct urb *urb, size_t len)
+{
+       int ret;
+
+       BUG_ON(len > dev->urbs.size);
+
+       urb->transfer_buffer_length = len; /* set to actual payload len */
+       ret = usb_submit_urb(urb, GFP_KERNEL);
+       if (ret) {
+               ufx_urb_completion(urb); /* because no one else will */
+               atomic_set(&dev->lost_pixels, 1);
+               pr_err("usb_submit_urb error %x\n", ret);
+       }
+       return ret;
+}
+
+module_param(console, bool, S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP);
+MODULE_PARM_DESC(console, "Allow fbcon to be used on this display");
+
+module_param(fb_defio, bool, S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP);
+MODULE_PARM_DESC(fb_defio, "Enable fb_defio mmap support");
+
+MODULE_AUTHOR("Steve Glendinning <steve.glendinning@smsc.com>");
+MODULE_DESCRIPTION("SMSC UFX kernel framebuffer driver");
+MODULE_LICENSE("GPL");
index cd1c4dcef8fdc0f0d79b1e33f7a84593416854fe..8e4a446b5ed111054ed52f0ff62abbe79edb006d 100644 (file)
@@ -744,7 +744,7 @@ static int __devinit tmiofb_probe(struct platform_device *dev)
                goto err_ioremap_vram;
        }
 
-       retval = request_irq(irq, &tmiofb_irq, IRQF_DISABLED,
+       retval = request_irq(irq, &tmiofb_irq, 0,
                                        dev_name(&dev->dev), info);
 
        if (retval)
index c6c77562839d9663cef133f9b23e0d1607a5d2c8..34cf019bba44b64dc9c5a09ec4683efac8ff262c 100644 (file)
@@ -987,8 +987,8 @@ static int tridentfb_pan_display(struct fb_var_screeninfo *var,
        unsigned int offset;
 
        debug("enter\n");
-       offset = (var->xoffset + (var->yoffset * var->xres_virtual))
-               * var->bits_per_pixel / 32;
+       offset = (var->xoffset + (var->yoffset * info->var.xres_virtual))
+               * info->var.bits_per_pixel / 32;
        set_screen_start(par, offset);
        debug("exit\n");
        return 0;
index 087fc9960bb9bbb2d1b60136631f815dd2325685..3473e75ce78511106905f68d66d638b63a886972 100644 (file)
@@ -48,20 +48,30 @@ static const u32 udlfb_info_flags = FBINFO_DEFAULT | FBINFO_READS_FAST |
                FBINFO_HWACCEL_COPYAREA | FBINFO_MISC_ALWAYS_SETPAR;
 
 /*
- * There are many DisplayLink-based products, all with unique PIDs. We are able
- * to support all volume ones (circa 2009) with a single driver, so we match
- * globally on VID. TODO: Probe() needs to detect when we might be running
- * "future" chips, and bail on those, so a compatible driver can match.
+ * There are many DisplayLink-based graphics products, all with unique PIDs.
+ * So we match on DisplayLink's VID + Vendor-Defined Interface Class (0xff)
+ * We also require a match on SubClass (0x00) and Protocol (0x00),
+ * which is compatible with all known USB 2.0 era graphics chips and firmware,
+ * but allows DisplayLink to increment those for any future incompatible chips
  */
 static struct usb_device_id id_table[] = {
-       {.idVendor = 0x17e9, .match_flags = USB_DEVICE_ID_MATCH_VENDOR,},
+       {.idVendor = 0x17e9,
+        .bInterfaceClass = 0xff,
+        .bInterfaceSubClass = 0x00,
+        .bInterfaceProtocol = 0x00,
+        .match_flags = USB_DEVICE_ID_MATCH_VENDOR |
+               USB_DEVICE_ID_MATCH_INT_CLASS |
+               USB_DEVICE_ID_MATCH_INT_SUBCLASS |
+               USB_DEVICE_ID_MATCH_INT_PROTOCOL,
+       },
        {},
 };
 MODULE_DEVICE_TABLE(usb, id_table);
 
 /* module options */
-static int console;   /* Optionally allow fbcon to consume first framebuffer */
-static int fb_defio;  /* Optionally enable experimental fb_defio mmap support */
+static int console = 1; /* Allow fbcon to open framebuffer */
+static int fb_defio = 1;  /* Detect mmap writes using page faults */
+static int shadow = 1; /* Optionally disable shadow framebuffer */
 
 /* dlfb keeps a list of urbs for efficient bulk transfers */
 static void dlfb_urb_completion(struct urb *urb);
@@ -94,17 +104,39 @@ static char *dlfb_vidreg_unlock(char *buf)
 }
 
 /*
- * On/Off for driving the DisplayLink framebuffer to the display
- *  0x00 H and V sync on
- *  0x01 H and V sync off (screen blank but powered)
- *  0x07 DPMS powerdown (requires modeset to come back)
+ * Map FB_BLANK_* to DisplayLink register
+ * DLReg FB_BLANK_*
+ * ----- -----------------------------
+ *  0x00 FB_BLANK_UNBLANK (0)
+ *  0x01 FB_BLANK (1)
+ *  0x03 FB_BLANK_VSYNC_SUSPEND (2)
+ *  0x05 FB_BLANK_HSYNC_SUSPEND (3)
+ *  0x07 FB_BLANK_POWERDOWN (4) Note: requires modeset to come back
  */
-static char *dlfb_enable_hvsync(char *buf, bool enable)
+static char *dlfb_blanking(char *buf, int fb_blank)
 {
-       if (enable)
-               return dlfb_set_register(buf, 0x1F, 0x00);
-       else
-               return dlfb_set_register(buf, 0x1F, 0x07);
+       u8 reg;
+
+       switch (fb_blank) {
+       case FB_BLANK_POWERDOWN:
+               reg = 0x07;
+               break;
+       case FB_BLANK_HSYNC_SUSPEND:
+               reg = 0x05;
+               break;
+       case FB_BLANK_VSYNC_SUSPEND:
+               reg = 0x03;
+               break;
+       case FB_BLANK_NORMAL:
+               reg = 0x01;
+               break;
+       default:
+               reg = 0x00;
+       }
+
+       buf = dlfb_set_register(buf, 0x1F, reg);
+
+       return buf;
 }
 
 static char *dlfb_set_color_depth(char *buf, u8 selection)
@@ -272,13 +304,15 @@ static int dlfb_set_video_mode(struct dlfb_data *dev,
        wrptr = dlfb_set_base8bpp(wrptr, dev->info->fix.smem_len);
 
        wrptr = dlfb_set_vid_cmds(wrptr, var);
-       wrptr = dlfb_enable_hvsync(wrptr, true);
+       wrptr = dlfb_blanking(wrptr, FB_BLANK_UNBLANK);
        wrptr = dlfb_vidreg_unlock(wrptr);
 
        writesize = wrptr - buf;
 
        retval = dlfb_submit_urb(dev, urb, writesize);
 
+       dev->blank_mode = FB_BLANK_UNBLANK;
+
        return retval;
 }
 
@@ -752,14 +786,13 @@ static int dlfb_ops_ioctl(struct fb_info *info, unsigned int cmd,
 {
 
        struct dlfb_data *dev = info->par;
-       struct dloarea *area = NULL;
 
        if (!atomic_read(&dev->usb_active))
                return 0;
 
        /* TODO: Update X server to get this from sysfs instead */
        if (cmd == DLFB_IOCTL_RETURN_EDID) {
-               char *edid = (char *)arg;
+               void __user *edid = (void __user *)arg;
                if (copy_to_user(edid, dev->edid, dev->edid_size))
                        return -EFAULT;
                return 0;
@@ -767,6 +800,11 @@ static int dlfb_ops_ioctl(struct fb_info *info, unsigned int cmd,
 
        /* TODO: Help propose a standard fb.h ioctl to report mmap damage */
        if (cmd == DLFB_IOCTL_REPORT_DAMAGE) {
+               struct dloarea area;
+
+               if (copy_from_user(&area, (void __user *)arg,
+                                 sizeof(struct dloarea)))
+                       return -EFAULT;
 
                /*
                 * If we have a damage-aware client, turn fb_defio "off"
@@ -778,21 +816,19 @@ static int dlfb_ops_ioctl(struct fb_info *info, unsigned int cmd,
                if (info->fbdefio)
                        info->fbdefio->delay = DL_DEFIO_WRITE_DISABLE;
 
-               area = (struct dloarea *)arg;
+               if (area.x < 0)
+                       area.x = 0;
 
-               if (area->x < 0)
-                       area->x = 0;
+               if (area.x > info->var.xres)
+                       area.x = info->var.xres;
 
-               if (area->x > info->var.xres)
-                       area->x = info->var.xres;
+               if (area.y < 0)
+                       area.y = 0;
 
-               if (area->y < 0)
-                       area->y = 0;
+               if (area.y > info->var.yres)
+                       area.y = info->var.yres;
 
-               if (area->y > info->var.yres)
-                       area->y = info->var.yres;
-
-               dlfb_handle_damage(dev, area->x, area->y, area->w, area->h,
+               dlfb_handle_damage(dev, area.x, area.y, area.w, area.h,
                           info->screen_base);
        }
 
@@ -840,7 +876,7 @@ static int dlfb_ops_open(struct fb_info *info, int user)
         * preventing other clients (X) from working properly. Usually
         * not what the user wants. Fail by default with option to enable.
         */
-       if ((user == 0) & (!console))
+       if ((user == 0) && (!console))
                return -EBUSY;
 
        /* If the USB device is gone, we don't accept new opens */
@@ -1039,32 +1075,57 @@ static int dlfb_ops_set_par(struct fb_info *info)
        return result;
 }
 
+/* To fonzi the jukebox (e.g. make blanking changes take effect) */
+static char *dlfb_dummy_render(char *buf)
+{
+       *buf++ = 0xAF;
+       *buf++ = 0x6A; /* copy */
+       *buf++ = 0x00; /* from address*/
+       *buf++ = 0x00;
+       *buf++ = 0x00;
+       *buf++ = 0x01; /* one pixel */
+       *buf++ = 0x00; /* to address */
+       *buf++ = 0x00;
+       *buf++ = 0x00;
+       return buf;
+}
+
 /*
  * In order to come back from full DPMS off, we need to set the mode again
  */
 static int dlfb_ops_blank(int blank_mode, struct fb_info *info)
 {
        struct dlfb_data *dev = info->par;
+       char *bufptr;
+       struct urb *urb;
 
-       if (blank_mode != FB_BLANK_UNBLANK) {
-               char *bufptr;
-               struct urb *urb;
-
-               urb = dlfb_get_urb(dev);
-               if (!urb)
-                       return 0;
+       pr_info("/dev/fb%d FB_BLANK mode %d --> %d\n",
+               info->node, dev->blank_mode, blank_mode);
 
-               bufptr = (char *) urb->transfer_buffer;
-               bufptr = dlfb_vidreg_lock(bufptr);
-               bufptr = dlfb_enable_hvsync(bufptr, false);
-               bufptr = dlfb_vidreg_unlock(bufptr);
+       if ((dev->blank_mode == FB_BLANK_POWERDOWN) &&
+           (blank_mode != FB_BLANK_POWERDOWN)) {
 
-               dlfb_submit_urb(dev, urb, bufptr -
-                               (char *) urb->transfer_buffer);
-       } else {
+               /* returning from powerdown requires a fresh modeset */
                dlfb_set_video_mode(dev, &info->var);
        }
 
+       urb = dlfb_get_urb(dev);
+       if (!urb)
+               return 0;
+
+       bufptr = (char *) urb->transfer_buffer;
+       bufptr = dlfb_vidreg_lock(bufptr);
+       bufptr = dlfb_blanking(bufptr, blank_mode);
+       bufptr = dlfb_vidreg_unlock(bufptr);
+
+       /* seems like a render op is needed to have blank change take effect */
+       bufptr = dlfb_dummy_render(bufptr);
+
+       dlfb_submit_urb(dev, urb, bufptr -
+                       (char *) urb->transfer_buffer);
+
+       dev->blank_mode = blank_mode;
+
        return 0;
 }
 
@@ -1097,7 +1158,7 @@ static int dlfb_realloc_framebuffer(struct dlfb_data *dev, struct fb_info *info)
        int new_len;
        unsigned char *old_fb = info->screen_base;
        unsigned char *new_fb;
-       unsigned char *new_back;
+       unsigned char *new_back = 0;
 
        pr_warn("Reallocating framebuffer. Addresses will change!\n");
 
@@ -1129,7 +1190,8 @@ static int dlfb_realloc_framebuffer(struct dlfb_data *dev, struct fb_info *info)
                 * But with imperfect damage info we may send pixels over USB
                 * that were, in fact, unchanged - wasting limited USB bandwidth
                 */
-               new_back = vzalloc(new_len);
+               if (shadow)
+                       new_back = vzalloc(new_len);
                if (!new_back)
                        pr_info("No shadow/backing buffer allocated\n");
                else {
@@ -1430,21 +1492,30 @@ static int dlfb_select_std_channel(struct dlfb_data *dev)
 }
 
 static int dlfb_parse_vendor_descriptor(struct dlfb_data *dev,
-                                       struct usb_device *usbdev)
+                                       struct usb_interface *interface)
 {
        char *desc;
        char *buf;
        char *desc_end;
 
-       u8 total_len = 0;
+       int total_len = 0;
 
        buf = kzalloc(MAX_VENDOR_DESCRIPTOR_SIZE, GFP_KERNEL);
        if (!buf)
                return false;
        desc = buf;
 
-       total_len = usb_get_descriptor(usbdev, 0x5f, /* vendor specific */
-                                   0, desc, MAX_VENDOR_DESCRIPTOR_SIZE);
+       total_len = usb_get_descriptor(interface_to_usbdev(interface),
+                                       0x5f, /* vendor specific */
+                                       0, desc, MAX_VENDOR_DESCRIPTOR_SIZE);
+
+       /* if not found, look in configuration descriptor */
+       if (total_len < 0) {
+               if (0 == usb_get_extra_descriptor(interface->cur_altsetting,
+                       0x5f, &desc))
+                       total_len = (int) desc[0];
+       }
+
        if (total_len > 5) {
                pr_info("vendor descriptor length:%x data:%02x %02x %02x %02x" \
                        "%02x %02x %02x %02x %02x %02x %02x\n",
@@ -1485,6 +1556,8 @@ static int dlfb_parse_vendor_descriptor(struct dlfb_data *dev,
                        }
                        desc += length;
                }
+       } else {
+               pr_info("vendor descriptor not available (%d)\n", total_len);
        }
 
        goto success;
@@ -1531,10 +1604,11 @@ static int dlfb_usb_probe(struct usb_interface *interface,
                usbdev->descriptor.bcdDevice, dev);
        pr_info("console enable=%d\n", console);
        pr_info("fb_defio enable=%d\n", fb_defio);
+       pr_info("shadow enable=%d\n", shadow);
 
        dev->sku_pixel_limit = 2048 * 1152; /* default to maximum */
 
-       if (!dlfb_parse_vendor_descriptor(dev, usbdev)) {
+       if (!dlfb_parse_vendor_descriptor(dev, interface)) {
                pr_err("firmware not recognized. Assume incompatible device\n");
                goto error;
        }
@@ -1548,7 +1622,7 @@ static int dlfb_usb_probe(struct usb_interface *interface,
        /* We don't register a new USB class. Our client interface is fbdev */
 
        /* allocates framebuffer driver structure, not framebuffer memory */
-       info = framebuffer_alloc(0, &usbdev->dev);
+       info = framebuffer_alloc(0, &interface->dev);
        if (!info) {
                retval = -ENOMEM;
                pr_err("framebuffer_alloc failed\n");
@@ -1883,10 +1957,13 @@ static int dlfb_submit_urb(struct dlfb_data *dev, struct urb *urb, size_t len)
 }
 
 module_param(console, bool, S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP);
-MODULE_PARM_DESC(console, "Allow fbcon to consume first framebuffer found");
+MODULE_PARM_DESC(console, "Allow fbcon to open framebuffer");
 
 module_param(fb_defio, bool, S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP);
-MODULE_PARM_DESC(fb_defio, "Enable fb_defio mmap support. *Experimental*");
+MODULE_PARM_DESC(fb_defio, "Page fault detection of mmap writes");
+
+module_param(shadow, bool, S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP);
+MODULE_PARM_DESC(shadow, "Shadow vid mem. Disable to save mem but lose perf");
 
 MODULE_AUTHOR("Roberto De Ioris <roberto@unbit.it>, "
              "Jaya Kumar <jayakumar.lkml@gmail.com>, "
index 6b52bf65f0b57fc3ddced265a76a8ce5b03b0f6e..3f5a041601dafd77a6088096f6d5dab6331461d1 100644 (file)
@@ -555,7 +555,7 @@ static int __init valkyrie_init_info(struct fb_info *info,
 
 
 /*
- * Parse user speficied options (`video=valkyriefb:')
+ * Parse user specified options (`video=valkyriefb:')
  */
 int __init valkyriefb_setup(char *options)
 {
index bc67251f1a2f1d0e3662d4bec1f46f91bd2884d8..bf2f78065cf97d8d0bcdf492087244946783e99c 100644 (file)
@@ -395,8 +395,8 @@ static int vfb_pan_display(struct fb_var_screeninfo *var,
                    || var->xoffset)
                        return -EINVAL;
        } else {
-               if (var->xoffset + var->xres > info->var.xres_virtual ||
-                   var->yoffset + var->yres > info->var.yres_virtual)
+               if (var->xoffset + info->var.xres > info->var.xres_virtual ||
+                   var->yoffset + info->var.yres > info->var.yres_virtual)
                        return -EINVAL;
        }
        info->var.xoffset = var->xoffset;
index 305c975b1787ea0628d600d2ac89c89cd0afdee9..0267acd8dc832690e3f02709a9e99361a8979805 100644 (file)
@@ -207,7 +207,7 @@ static void vga16fb_pan_var(struct fb_info *info,
         * granularity if someone supports xoffset in bit resolution */
        vga_io_r(VGA_IS1_RC);           /* reset flip-flop */
        vga_io_w(VGA_ATT_IW, VGA_ATC_PEL);
-       if (var->bits_per_pixel == 8)
+       if (info->var.bits_per_pixel == 8)
                vga_io_w(VGA_ATT_IW, (xoffset & 3) << 1);
        else
                vga_io_w(VGA_ATT_IW, xoffset & 7);
index b1f364745ca007d8774566955d6f0d8bdf28b87b..9138e517267c1e67cfeed4db7ad111dd379eb426 100644 (file)
@@ -172,30 +172,20 @@ static int tmds_register_read_bytes(int index, u8 *buff, int buff_len)
 }
 
 /* DVI Set Mode */
-void viafb_dvi_set_mode(struct VideoModeTable *mode, int mode_bpp,
-       int set_iga)
+void viafb_dvi_set_mode(const struct fb_var_screeninfo *var, int iga)
 {
-       struct VideoModeTable *rb_mode;
-       struct crt_mode_table *pDviTiming;
-       unsigned long desirePixelClock, maxPixelClock;
-       pDviTiming = mode->crtc;
-       desirePixelClock = pDviTiming->refresh_rate
-               * pDviTiming->crtc.hor_total * pDviTiming->crtc.ver_total
-               / 1000000;
-       maxPixelClock = (unsigned long)viaparinfo->
-               tmds_setting_info->max_pixel_clock;
-
-       DEBUG_MSG(KERN_INFO "\nDVI_set_mode!!\n");
-
-       if ((maxPixelClock != 0) && (desirePixelClock > maxPixelClock)) {
-               rb_mode = viafb_get_rb_mode(mode->crtc[0].crtc.hor_addr,
-                       mode->crtc[0].crtc.ver_addr);
-               if (rb_mode) {
-                       mode = rb_mode;
-                       pDviTiming = rb_mode->crtc;
-               }
+       struct fb_var_screeninfo dvi_var = *var;
+       struct crt_mode_table *rb_mode;
+       int maxPixelClock;
+
+       maxPixelClock = viaparinfo->shared->tmds_setting_info.max_pixel_clock;
+       if (maxPixelClock && PICOS2KHZ(var->pixclock) / 1000 > maxPixelClock) {
+               rb_mode = viafb_get_best_rb_mode(var->xres, var->yres, 60);
+               if (rb_mode)
+                       viafb_fill_var_timing_info(&dvi_var, rb_mode);
        }
-       viafb_fill_crtc_timing(pDviTiming, mode, mode_bpp / 8, set_iga);
+
+       viafb_fill_crtc_timing(&dvi_var, iga);
 }
 
 /* Sense DVI Connector */
index f473dd010977ba1222da41a8f04878f124317a51..e2116aaf797a23973c91baefaf837dfe14828935 100644 (file)
@@ -59,7 +59,6 @@ void viafb_dvi_enable(void);
 bool __devinit viafb_tmds_trasmitter_identify(void);
 void __devinit viafb_init_dvi_size(struct tmds_chip_information *tmds_chip,
        struct tmds_setting_information *tmds_setting);
-void viafb_dvi_set_mode(struct VideoModeTable *videoMode, int mode_bpp,
-       int set_iga);
+void viafb_dvi_set_mode(const struct fb_var_screeninfo *var, int iga);
 
 #endif /* __DVI_H__ */
index e10d8249534c682543f0a43cfb9398240e357219..3102171c16743200ce3fc8e1462a00ffe1839fff 100644 (file)
@@ -35,6 +35,8 @@ int viafb_LCD_ON ;
 int viafb_LCD2_ON;
 int viafb_SAMM_ON;
 int viafb_dual_fb;
+unsigned int viafb_second_xres = 640;
+unsigned int viafb_second_yres = 480;
 int viafb_hotplug_Xres = 640;
 int viafb_hotplug_Yres = 480;
 int viafb_hotplug_bpp = 32;
index ff969dc3459352bbfea5df7dec88e111576584c3..275dbbbd6b81227ac690028588ac24c7691ffe8a 100644 (file)
@@ -67,6 +67,8 @@ extern int viafb_lcd_dsp_method;
 extern int viafb_lcd_mode;
 
 extern int viafb_CRT_ON;
+extern unsigned int viafb_second_xres;
+extern unsigned int viafb_second_yres;
 extern int viafb_hotplug_Xres;
 extern int viafb_hotplug_Yres;
 extern int viafb_hotplug_bpp;
index 47b13535ed2b6279a568a3f7c0b7ed00edd2a8c3..d5aaca9cfa7e2b7b6a4e5770b5965cbc199e262a 100644 (file)
@@ -191,67 +191,6 @@ static struct fetch_count fetch_count_reg = {
        {IGA2_FETCH_COUNT_REG_NUM, {{CR65, 0, 7}, {CR67, 2, 3} } }
 };
 
-static struct iga1_crtc_timing iga1_crtc_reg = {
-       /* IGA1 Horizontal Total */
-       {IGA1_HOR_TOTAL_REG_NUM, {{CR00, 0, 7}, {CR36, 3, 3} } },
-       /* IGA1 Horizontal Addressable Video */
-       {IGA1_HOR_ADDR_REG_NUM, {{CR01, 0, 7} } },
-       /* IGA1 Horizontal Blank Start */
-       {IGA1_HOR_BLANK_START_REG_NUM, {{CR02, 0, 7} } },
-       /* IGA1 Horizontal Blank End */
-       {IGA1_HOR_BLANK_END_REG_NUM,
-        {{CR03, 0, 4}, {CR05, 7, 7}, {CR33, 5, 5} } },
-       /* IGA1 Horizontal Sync Start */
-       {IGA1_HOR_SYNC_START_REG_NUM, {{CR04, 0, 7}, {CR33, 4, 4} } },
-       /* IGA1 Horizontal Sync End */
-       {IGA1_HOR_SYNC_END_REG_NUM, {{CR05, 0, 4} } },
-       /* IGA1 Vertical Total */
-       {IGA1_VER_TOTAL_REG_NUM,
-        {{CR06, 0, 7}, {CR07, 0, 0}, {CR07, 5, 5}, {CR35, 0, 0} } },
-       /* IGA1 Vertical Addressable Video */
-       {IGA1_VER_ADDR_REG_NUM,
-        {{CR12, 0, 7}, {CR07, 1, 1}, {CR07, 6, 6}, {CR35, 2, 2} } },
-       /* IGA1 Vertical Blank Start */
-       {IGA1_VER_BLANK_START_REG_NUM,
-        {{CR15, 0, 7}, {CR07, 3, 3}, {CR09, 5, 5}, {CR35, 3, 3} } },
-       /* IGA1 Vertical Blank End */
-       {IGA1_VER_BLANK_END_REG_NUM, {{CR16, 0, 7} } },
-       /* IGA1 Vertical Sync Start */
-       {IGA1_VER_SYNC_START_REG_NUM,
-        {{CR10, 0, 7}, {CR07, 2, 2}, {CR07, 7, 7}, {CR35, 1, 1} } },
-       /* IGA1 Vertical Sync End */
-       {IGA1_VER_SYNC_END_REG_NUM, {{CR11, 0, 3} } }
-};
-
-static struct iga2_crtc_timing iga2_crtc_reg = {
-       /* IGA2 Horizontal Total */
-       {IGA2_HOR_TOTAL_REG_NUM, {{CR50, 0, 7}, {CR55, 0, 3} } },
-       /* IGA2 Horizontal Addressable Video */
-       {IGA2_HOR_ADDR_REG_NUM, {{CR51, 0, 7}, {CR55, 4, 6} } },
-       /* IGA2 Horizontal Blank Start */
-       {IGA2_HOR_BLANK_START_REG_NUM, {{CR52, 0, 7}, {CR54, 0, 2} } },
-       /* IGA2 Horizontal Blank End */
-       {IGA2_HOR_BLANK_END_REG_NUM,
-        {{CR53, 0, 7}, {CR54, 3, 5}, {CR5D, 6, 6} } },
-       /* IGA2 Horizontal Sync Start */
-       {IGA2_HOR_SYNC_START_REG_NUM,
-        {{CR56, 0, 7}, {CR54, 6, 7}, {CR5C, 7, 7}, {CR5D, 7, 7} } },
-       /* IGA2 Horizontal Sync End */
-       {IGA2_HOR_SYNC_END_REG_NUM, {{CR57, 0, 7}, {CR5C, 6, 6} } },
-       /* IGA2 Vertical Total */
-       {IGA2_VER_TOTAL_REG_NUM, {{CR58, 0, 7}, {CR5D, 0, 2} } },
-       /* IGA2 Vertical Addressable Video */
-       {IGA2_VER_ADDR_REG_NUM, {{CR59, 0, 7}, {CR5D, 3, 5} } },
-       /* IGA2 Vertical Blank Start */
-       {IGA2_VER_BLANK_START_REG_NUM, {{CR5A, 0, 7}, {CR5C, 0, 2} } },
-       /* IGA2 Vertical Blank End */
-       {IGA2_VER_BLANK_END_REG_NUM, {{CR5B, 0, 7}, {CR5C, 3, 5} } },
-       /* IGA2 Vertical Sync Start */
-       {IGA2_VER_SYNC_START_REG_NUM, {{CR5E, 0, 7}, {CR5F, 5, 7} } },
-       /* IGA2 Vertical Sync End */
-       {IGA2_VER_SYNC_END_REG_NUM, {{CR5F, 0, 4} } }
-};
-
 static struct rgbLUT palLUT_table[] = {
        /* {R,G,B} */
        /* Index 0x00~0x03 */
@@ -1528,302 +1467,40 @@ void viafb_set_vclock(u32 clk, int set_iga)
        via_write_misc_reg_mask(0x0C, 0x0C); /* select external clock */
 }
 
-void viafb_load_crtc_timing(struct display_timing device_timing,
-       int set_iga)
+static struct display_timing var_to_timing(const struct fb_var_screeninfo *var)
 {
-       int i;
-       int viafb_load_reg_num = 0;
-       int reg_value = 0;
-       struct io_register *reg = NULL;
-
-       viafb_unlock_crt();
-
-       for (i = 0; i < 12; i++) {
-               if (set_iga == IGA1) {
-                       switch (i) {
-                       case H_TOTAL_INDEX:
-                               reg_value =
-                                   IGA1_HOR_TOTAL_FORMULA(device_timing.
-                                                          hor_total);
-                               viafb_load_reg_num =
-                                       iga1_crtc_reg.hor_total.reg_num;
-                               reg = iga1_crtc_reg.hor_total.reg;
-                               break;
-                       case H_ADDR_INDEX:
-                               reg_value =
-                                   IGA1_HOR_ADDR_FORMULA(device_timing.
-                                                         hor_addr);
-                               viafb_load_reg_num =
-                                       iga1_crtc_reg.hor_addr.reg_num;
-                               reg = iga1_crtc_reg.hor_addr.reg;
-                               break;
-                       case H_BLANK_START_INDEX:
-                               reg_value =
-                                   IGA1_HOR_BLANK_START_FORMULA
-                                   (device_timing.hor_blank_start);
-                               viafb_load_reg_num =
-                                   iga1_crtc_reg.hor_blank_start.reg_num;
-                               reg = iga1_crtc_reg.hor_blank_start.reg;
-                               break;
-                       case H_BLANK_END_INDEX:
-                               reg_value =
-                                   IGA1_HOR_BLANK_END_FORMULA
-                                   (device_timing.hor_blank_start,
-                                    device_timing.hor_blank_end);
-                               viafb_load_reg_num =
-                                   iga1_crtc_reg.hor_blank_end.reg_num;
-                               reg = iga1_crtc_reg.hor_blank_end.reg;
-                               break;
-                       case H_SYNC_START_INDEX:
-                               reg_value =
-                                   IGA1_HOR_SYNC_START_FORMULA
-                                   (device_timing.hor_sync_start);
-                               viafb_load_reg_num =
-                                   iga1_crtc_reg.hor_sync_start.reg_num;
-                               reg = iga1_crtc_reg.hor_sync_start.reg;
-                               break;
-                       case H_SYNC_END_INDEX:
-                               reg_value =
-                                   IGA1_HOR_SYNC_END_FORMULA
-                                   (device_timing.hor_sync_start,
-                                    device_timing.hor_sync_end);
-                               viafb_load_reg_num =
-                                   iga1_crtc_reg.hor_sync_end.reg_num;
-                               reg = iga1_crtc_reg.hor_sync_end.reg;
-                               break;
-                       case V_TOTAL_INDEX:
-                               reg_value =
-                                   IGA1_VER_TOTAL_FORMULA(device_timing.
-                                                          ver_total);
-                               viafb_load_reg_num =
-                                       iga1_crtc_reg.ver_total.reg_num;
-                               reg = iga1_crtc_reg.ver_total.reg;
-                               break;
-                       case V_ADDR_INDEX:
-                               reg_value =
-                                   IGA1_VER_ADDR_FORMULA(device_timing.
-                                                         ver_addr);
-                               viafb_load_reg_num =
-                                       iga1_crtc_reg.ver_addr.reg_num;
-                               reg = iga1_crtc_reg.ver_addr.reg;
-                               break;
-                       case V_BLANK_START_INDEX:
-                               reg_value =
-                                   IGA1_VER_BLANK_START_FORMULA
-                                   (device_timing.ver_blank_start);
-                               viafb_load_reg_num =
-                                   iga1_crtc_reg.ver_blank_start.reg_num;
-                               reg = iga1_crtc_reg.ver_blank_start.reg;
-                               break;
-                       case V_BLANK_END_INDEX:
-                               reg_value =
-                                   IGA1_VER_BLANK_END_FORMULA
-                                   (device_timing.ver_blank_start,
-                                    device_timing.ver_blank_end);
-                               viafb_load_reg_num =
-                                   iga1_crtc_reg.ver_blank_end.reg_num;
-                               reg = iga1_crtc_reg.ver_blank_end.reg;
-                               break;
-                       case V_SYNC_START_INDEX:
-                               reg_value =
-                                   IGA1_VER_SYNC_START_FORMULA
-                                   (device_timing.ver_sync_start);
-                               viafb_load_reg_num =
-                                   iga1_crtc_reg.ver_sync_start.reg_num;
-                               reg = iga1_crtc_reg.ver_sync_start.reg;
-                               break;
-                       case V_SYNC_END_INDEX:
-                               reg_value =
-                                   IGA1_VER_SYNC_END_FORMULA
-                                   (device_timing.ver_sync_start,
-                                    device_timing.ver_sync_end);
-                               viafb_load_reg_num =
-                                   iga1_crtc_reg.ver_sync_end.reg_num;
-                               reg = iga1_crtc_reg.ver_sync_end.reg;
-                               break;
-
-                       }
-               }
-
-               if (set_iga == IGA2) {
-                       switch (i) {
-                       case H_TOTAL_INDEX:
-                               reg_value =
-                                   IGA2_HOR_TOTAL_FORMULA(device_timing.
-                                                          hor_total);
-                               viafb_load_reg_num =
-                                       iga2_crtc_reg.hor_total.reg_num;
-                               reg = iga2_crtc_reg.hor_total.reg;
-                               break;
-                       case H_ADDR_INDEX:
-                               reg_value =
-                                   IGA2_HOR_ADDR_FORMULA(device_timing.
-                                                         hor_addr);
-                               viafb_load_reg_num =
-                                       iga2_crtc_reg.hor_addr.reg_num;
-                               reg = iga2_crtc_reg.hor_addr.reg;
-                               break;
-                       case H_BLANK_START_INDEX:
-                               reg_value =
-                                   IGA2_HOR_BLANK_START_FORMULA
-                                   (device_timing.hor_blank_start);
-                               viafb_load_reg_num =
-                                   iga2_crtc_reg.hor_blank_start.reg_num;
-                               reg = iga2_crtc_reg.hor_blank_start.reg;
-                               break;
-                       case H_BLANK_END_INDEX:
-                               reg_value =
-                                   IGA2_HOR_BLANK_END_FORMULA
-                                   (device_timing.hor_blank_start,
-                                    device_timing.hor_blank_end);
-                               viafb_load_reg_num =
-                                   iga2_crtc_reg.hor_blank_end.reg_num;
-                               reg = iga2_crtc_reg.hor_blank_end.reg;
-                               break;
-                       case H_SYNC_START_INDEX:
-                               reg_value =
-                                   IGA2_HOR_SYNC_START_FORMULA
-                                   (device_timing.hor_sync_start);
-                               if (UNICHROME_CN700 <=
-                                       viaparinfo->chip_info->gfx_chip_name)
-                                       viafb_load_reg_num =
-                                           iga2_crtc_reg.hor_sync_start.
-                                           reg_num;
-                               else
-                                       viafb_load_reg_num = 3;
-                               reg = iga2_crtc_reg.hor_sync_start.reg;
-                               break;
-                       case H_SYNC_END_INDEX:
-                               reg_value =
-                                   IGA2_HOR_SYNC_END_FORMULA
-                                   (device_timing.hor_sync_start,
-                                    device_timing.hor_sync_end);
-                               viafb_load_reg_num =
-                                   iga2_crtc_reg.hor_sync_end.reg_num;
-                               reg = iga2_crtc_reg.hor_sync_end.reg;
-                               break;
-                       case V_TOTAL_INDEX:
-                               reg_value =
-                                   IGA2_VER_TOTAL_FORMULA(device_timing.
-                                                          ver_total);
-                               viafb_load_reg_num =
-                                       iga2_crtc_reg.ver_total.reg_num;
-                               reg = iga2_crtc_reg.ver_total.reg;
-                               break;
-                       case V_ADDR_INDEX:
-                               reg_value =
-                                   IGA2_VER_ADDR_FORMULA(device_timing.
-                                                         ver_addr);
-                               viafb_load_reg_num =
-                                       iga2_crtc_reg.ver_addr.reg_num;
-                               reg = iga2_crtc_reg.ver_addr.reg;
-                               break;
-                       case V_BLANK_START_INDEX:
-                               reg_value =
-                                   IGA2_VER_BLANK_START_FORMULA
-                                   (device_timing.ver_blank_start);
-                               viafb_load_reg_num =
-                                   iga2_crtc_reg.ver_blank_start.reg_num;
-                               reg = iga2_crtc_reg.ver_blank_start.reg;
-                               break;
-                       case V_BLANK_END_INDEX:
-                               reg_value =
-                                   IGA2_VER_BLANK_END_FORMULA
-                                   (device_timing.ver_blank_start,
-                                    device_timing.ver_blank_end);
-                               viafb_load_reg_num =
-                                   iga2_crtc_reg.ver_blank_end.reg_num;
-                               reg = iga2_crtc_reg.ver_blank_end.reg;
-                               break;
-                       case V_SYNC_START_INDEX:
-                               reg_value =
-                                   IGA2_VER_SYNC_START_FORMULA
-                                   (device_timing.ver_sync_start);
-                               viafb_load_reg_num =
-                                   iga2_crtc_reg.ver_sync_start.reg_num;
-                               reg = iga2_crtc_reg.ver_sync_start.reg;
-                               break;
-                       case V_SYNC_END_INDEX:
-                               reg_value =
-                                   IGA2_VER_SYNC_END_FORMULA
-                                   (device_timing.ver_sync_start,
-                                    device_timing.ver_sync_end);
-                               viafb_load_reg_num =
-                                   iga2_crtc_reg.ver_sync_end.reg_num;
-                               reg = iga2_crtc_reg.ver_sync_end.reg;
-                               break;
-
-                       }
-               }
-               viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIACR);
-       }
-
-       viafb_lock_crt();
+       struct display_timing timing;
+
+       timing.hor_addr = var->xres;
+       timing.hor_sync_start = timing.hor_addr + var->right_margin;
+       timing.hor_sync_end = timing.hor_sync_start + var->hsync_len;
+       timing.hor_total = timing.hor_sync_end + var->left_margin;
+       timing.hor_blank_start = timing.hor_addr;
+       timing.hor_blank_end = timing.hor_total;
+       timing.ver_addr = var->yres;
+       timing.ver_sync_start = timing.ver_addr + var->lower_margin;
+       timing.ver_sync_end = timing.ver_sync_start + var->vsync_len;
+       timing.ver_total = timing.ver_sync_end + var->upper_margin;
+       timing.ver_blank_start = timing.ver_addr;
+       timing.ver_blank_end = timing.ver_total;
+       return timing;
 }
 
-void viafb_fill_crtc_timing(struct crt_mode_table *crt_table,
-       struct VideoModeTable *video_mode, int bpp_byte, int set_iga)
+void viafb_fill_crtc_timing(const struct fb_var_screeninfo *var, int iga)
 {
-       struct display_timing crt_reg;
-       int i;
-       int index = 0;
-       int h_addr, v_addr;
-       u32 clock, refresh = viafb_refresh;
-
-       if (viafb_SAMM_ON && set_iga == IGA2)
-               refresh = viafb_refresh1;
-
-       for (i = 0; i < video_mode->mode_array; i++) {
-               index = i;
-
-               if (crt_table[i].refresh_rate == refresh)
-                       break;
-       }
+       struct display_timing crt_reg = var_to_timing(var);
 
-       crt_reg = crt_table[index].crtc;
+       if (iga == IGA1)
+               via_set_primary_timing(&crt_reg);
+       else if (iga == IGA2)
+               via_set_secondary_timing(&crt_reg);
 
-       /* Mode 640x480 has border, but LCD/DFP didn't have border. */
-       /* So we would delete border. */
-       if ((viafb_LCD_ON | viafb_DVI_ON)
-           && video_mode->crtc[0].crtc.hor_addr == 640
-           && video_mode->crtc[0].crtc.ver_addr == 480
-           && refresh == 60) {
-               /* The border is 8 pixels. */
-               crt_reg.hor_blank_start = crt_reg.hor_blank_start - 8;
-
-               /* Blanking time should add left and right borders. */
-               crt_reg.hor_blank_end = crt_reg.hor_blank_end + 16;
-       }
-
-       h_addr = crt_reg.hor_addr;
-       v_addr = crt_reg.ver_addr;
-       if (set_iga == IGA1) {
-               viafb_unlock_crt();
-               viafb_write_reg_mask(CR17, VIACR, 0x00, BIT7);
-       }
-
-       switch (set_iga) {
-       case IGA1:
-               viafb_load_crtc_timing(crt_reg, IGA1);
-               break;
-       case IGA2:
-               viafb_load_crtc_timing(crt_reg, IGA2);
-               break;
-       }
-
-       viafb_lock_crt();
-       viafb_write_reg_mask(CR17, VIACR, 0x80, BIT7);
-       viafb_load_fetch_count_reg(h_addr, bpp_byte, set_iga);
-
-       /* load FIFO */
-       if ((viaparinfo->chip_info->gfx_chip_name != UNICHROME_CLE266)
-           && (viaparinfo->chip_info->gfx_chip_name != UNICHROME_K400))
-               viafb_load_FIFO_reg(set_iga, h_addr, v_addr);
-
-       clock = crt_reg.hor_total * crt_reg.ver_total
-               * crt_table[index].refresh_rate;
-       viafb_set_vclock(clock, set_iga);
+       viafb_load_fetch_count_reg(var->xres, var->bits_per_pixel / 8, iga);
+       if (viaparinfo->chip_info->gfx_chip_name != UNICHROME_CLE266
+               && viaparinfo->chip_info->gfx_chip_name != UNICHROME_K400)
+               viafb_load_FIFO_reg(iga, var->xres, var->yres);
 
+       viafb_set_vclock(PICOS2KHZ(var->pixclock) * 1000, iga);
 }
 
 void __devinit viafb_init_chip_info(int chip_type)
@@ -2092,23 +1769,9 @@ static u8 get_sync(struct fb_info *info)
        return polarity;
 }
 
-int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp,
-       struct VideoModeTable *vmode_tbl1, int video_bpp1)
+static void hw_init(void)
 {
-       int i, j;
-       int port;
-       u32 devices = viaparinfo->shared->iga1_devices
-               | viaparinfo->shared->iga2_devices;
-       u8 value, index, mask;
-       struct crt_mode_table *crt_timing;
-       struct crt_mode_table *crt_timing1 = NULL;
-
-       device_screen_off();
-       crt_timing = vmode_tbl->crtc;
-
-       if (viafb_SAMM_ON == 1) {
-               crt_timing1 = vmode_tbl1->crtc;
-       }
+       int i;
 
        inb(VIAStatus);
        outb(0x00, VIAAR);
@@ -2147,9 +1810,8 @@ int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp,
                break;
        }
 
+       /* probably this should go to the scaling code one day */
        viafb_write_regx(scaling_parameters, ARRAY_SIZE(scaling_parameters));
-       device_off();
-       via_set_state(devices, VIA_STATE_OFF);
 
        /* Fill VPIT Parameters */
        /* Write Misc Register */
@@ -2175,12 +1837,29 @@ int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp,
        inb(VIAStatus);
        outb(0x20, VIAAR);
 
+       load_fix_bit_crtc_reg();
+}
+
+int viafb_setmode(int video_bpp, int video_bpp1)
+{
+       int j;
+       int port;
+       u32 devices = viaparinfo->shared->iga1_devices
+               | viaparinfo->shared->iga2_devices;
+       u8 value, index, mask;
+       struct fb_var_screeninfo var2;
+
+       device_screen_off();
+       device_off();
+       via_set_state(devices, VIA_STATE_OFF);
+
+       hw_init();
+
        /* Update Patch Register */
 
        if ((viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266
-           || viaparinfo->chip_info->gfx_chip_name == UNICHROME_K400)
-           && vmode_tbl->crtc[0].crtc.hor_addr == 1024
-           && vmode_tbl->crtc[0].crtc.ver_addr == 768) {
+               || viaparinfo->chip_info->gfx_chip_name == UNICHROME_K400)
+               && viafbinfo->var.xres == 1024 && viafbinfo->var.yres == 768) {
                for (j = 0; j < res_patch_table[0].table_length; j++) {
                        index = res_patch_table[0].io_reg_table[j].index;
                        port = res_patch_table[0].io_reg_table[j].port;
@@ -2190,7 +1869,6 @@ int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp,
                }
        }
 
-       load_fix_bit_crtc_reg();
        via_set_primary_pitch(viafbinfo->fix.line_length);
        via_set_secondary_pitch(viafb_dual_fb ? viafbinfo1->fix.line_length
                : viafbinfo->fix.line_length);
@@ -2208,23 +1886,28 @@ int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp,
 
        /* Clear On Screen */
 
+       if (viafb_dual_fb) {
+               var2 = viafbinfo1->var;
+       } else if (viafb_SAMM_ON) {
+               viafb_fill_var_timing_info(&var2, viafb_get_best_mode(
+                       viafb_second_xres, viafb_second_yres, viafb_refresh1));
+               var2.bits_per_pixel = viafbinfo->var.bits_per_pixel;
+       }
+
        /* CRT set mode */
        if (viafb_CRT_ON) {
-               if (viafb_SAMM_ON &&
-                       viaparinfo->shared->iga2_devices & VIA_CRT) {
-                       viafb_fill_crtc_timing(crt_timing1, vmode_tbl1,
-                               video_bpp1 / 8, IGA2);
-               } else {
-                       viafb_fill_crtc_timing(crt_timing, vmode_tbl,
-                               video_bpp / 8,
+               if (viaparinfo->shared->iga2_devices & VIA_CRT
+                       && viafb_SAMM_ON)
+                       viafb_fill_crtc_timing(&var2, IGA2);
+               else
+                       viafb_fill_crtc_timing(&viafbinfo->var,
                                (viaparinfo->shared->iga1_devices & VIA_CRT)
                                ? IGA1 : IGA2);
-               }
 
                /* Patch if set_hres is not 8 alignment (1366) to viafb_setmode
                to 8 alignment (1368),there is several pixels (2 pixels)
                on right side of screen. */
-               if (vmode_tbl->crtc[0].crtc.hor_addr % 8) {
+               if (viafbinfo->var.xres % 8) {
                        viafb_unlock_crt();
                        viafb_write_reg(CR02, VIACR,
                                viafb_read_reg(VIACR, CR02) - 1);
@@ -2233,31 +1916,20 @@ int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp,
        }
 
        if (viafb_DVI_ON) {
-               if (viafb_SAMM_ON &&
-                       (viaparinfo->tmds_setting_info->iga_path == IGA2)) {
-                       viafb_dvi_set_mode(viafb_get_mode
-                                    (viaparinfo->tmds_setting_info->h_active,
-                                     viaparinfo->tmds_setting_info->
-                                     v_active),
-                                    video_bpp1, viaparinfo->
-                                    tmds_setting_info->iga_path);
-               } else {
-                       viafb_dvi_set_mode(viafb_get_mode
-                                    (viaparinfo->tmds_setting_info->h_active,
-                                     viaparinfo->
-                                     tmds_setting_info->v_active),
-                                    video_bpp, viaparinfo->
-                                    tmds_setting_info->iga_path);
-               }
+               if (viaparinfo->shared->tmds_setting_info.iga_path == IGA2
+                       && viafb_SAMM_ON)
+                       viafb_dvi_set_mode(&var2, IGA2);
+               else
+                       viafb_dvi_set_mode(&viafbinfo->var,
+                               viaparinfo->tmds_setting_info->iga_path);
        }
 
        if (viafb_LCD_ON) {
                if (viafb_SAMM_ON &&
                        (viaparinfo->lvds_setting_info->iga_path == IGA2)) {
                        viaparinfo->lvds_setting_info->bpp = video_bpp1;
-                       viafb_lcd_set_mode(crt_timing1, viaparinfo->
-                               lvds_setting_info,
-                                    &viaparinfo->chip_info->lvds_chip_info);
+                       viafb_lcd_set_mode(viaparinfo->lvds_setting_info,
+                               &viaparinfo->chip_info->lvds_chip_info);
                } else {
                        /* IGA1 doesn't have LCD scaling, so set it center. */
                        if (viaparinfo->lvds_setting_info->iga_path == IGA1) {
@@ -2265,18 +1937,16 @@ int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp,
                                    LCD_CENTERING;
                        }
                        viaparinfo->lvds_setting_info->bpp = video_bpp;
-                       viafb_lcd_set_mode(crt_timing, viaparinfo->
-                               lvds_setting_info,
-                                    &viaparinfo->chip_info->lvds_chip_info);
+                       viafb_lcd_set_mode(viaparinfo->lvds_setting_info,
+                               &viaparinfo->chip_info->lvds_chip_info);
                }
        }
        if (viafb_LCD2_ON) {
                if (viafb_SAMM_ON &&
                        (viaparinfo->lvds_setting_info2->iga_path == IGA2)) {
                        viaparinfo->lvds_setting_info2->bpp = video_bpp1;
-                       viafb_lcd_set_mode(crt_timing1, viaparinfo->
-                               lvds_setting_info2,
-                                    &viaparinfo->chip_info->lvds_chip_info2);
+                       viafb_lcd_set_mode(viaparinfo->lvds_setting_info2,
+                               &viaparinfo->chip_info->lvds_chip_info2);
                } else {
                        /* IGA1 doesn't have LCD scaling, so set it center. */
                        if (viaparinfo->lvds_setting_info2->iga_path == IGA1) {
@@ -2284,9 +1954,8 @@ int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp,
                                    LCD_CENTERING;
                        }
                        viaparinfo->lvds_setting_info2->bpp = video_bpp;
-                       viafb_lcd_set_mode(crt_timing, viaparinfo->
-                               lvds_setting_info2,
-                                    &viaparinfo->chip_info->lvds_chip_info2);
+                       viafb_lcd_set_mode(viaparinfo->lvds_setting_info2,
+                               &viaparinfo->chip_info->lvds_chip_info2);
                }
        }
 
@@ -2296,8 +1965,8 @@ int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp,
 
        /* If set mode normally, save resolution information for hot-plug . */
        if (!viafb_hotplug) {
-               viafb_hotplug_Xres = vmode_tbl->crtc[0].crtc.hor_addr;
-               viafb_hotplug_Yres = vmode_tbl->crtc[0].crtc.ver_addr;
+               viafb_hotplug_Xres = viafbinfo->var.xres;
+               viafb_hotplug_Yres = viafbinfo->var.yres;
                viafb_hotplug_bpp = video_bpp;
                viafb_hotplug_refresh = viafb_refresh;
 
@@ -2348,42 +2017,14 @@ int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp,
        return 1;
 }
 
-int viafb_get_pixclock(int hres, int vres, int vmode_refresh)
-{
-       int i;
-       struct crt_mode_table *best;
-       struct VideoModeTable *vmode = viafb_get_mode(hres, vres);
-
-       if (!vmode)
-               return RES_640X480_60HZ_PIXCLOCK;
-
-       best = &vmode->crtc[0];
-       for (i = 1; i < vmode->mode_array; i++) {
-               if (abs(vmode->crtc[i].refresh_rate - vmode_refresh)
-                       < abs(best->refresh_rate - vmode_refresh))
-                       best = &vmode->crtc[i];
-       }
-
-       return 1000000000 / (best->crtc.hor_total * best->crtc.ver_total)
-               * 1000 / best->refresh_rate;
-}
-
 int viafb_get_refresh(int hres, int vres, u32 long_refresh)
 {
-       int i;
        struct crt_mode_table *best;
-       struct VideoModeTable *vmode = viafb_get_mode(hres, vres);
 
-       if (!vmode)
+       best = viafb_get_best_mode(hres, vres, long_refresh);
+       if (!best)
                return 60;
 
-       best = &vmode->crtc[0];
-       for (i = 1; i < vmode->mode_array; i++) {
-               if (abs(vmode->crtc[i].refresh_rate - long_refresh)
-                       < abs(best->refresh_rate - long_refresh))
-                       best = &vmode->crtc[i];
-       }
-
        if (abs(best->refresh_rate - long_refresh) > 3) {
                if (hres == 1200 && vres == 900)
                        return 49; /* OLPC DCON only supports 50 Hz */
@@ -2485,21 +2126,14 @@ void viafb_set_dpa_gfx(int output_interface, struct GFX_DPA_SETTING\
 }
 
 /*According var's xres, yres fill var's other timing information*/
-void viafb_fill_var_timing_info(struct fb_var_screeninfo *var, int refresh,
-       struct VideoModeTable *vmode_tbl)
+void viafb_fill_var_timing_info(struct fb_var_screeninfo *var,
+       struct crt_mode_table *mode)
 {
-       struct crt_mode_table *crt_timing = NULL;
        struct display_timing crt_reg;
-       int i = 0, index = 0;
-       crt_timing = vmode_tbl->crtc;
-       for (i = 0; i < vmode_tbl->mode_array; i++) {
-               index = i;
-               if (crt_timing[i].refresh_rate == refresh)
-                       break;
-       }
 
-       crt_reg = crt_timing[index].crtc;
-       var->pixclock = viafb_get_pixclock(var->xres, var->yres, refresh);
+       crt_reg = mode->crtc;
+       var->pixclock = 1000000000 / (crt_reg.hor_total * crt_reg.ver_total)
+               * 1000 / mode->refresh_rate;
        var->left_margin =
            crt_reg.hor_total - (crt_reg.hor_sync_start + crt_reg.hor_sync_end);
        var->right_margin = crt_reg.hor_sync_start - crt_reg.hor_addr;
@@ -2509,8 +2143,8 @@ void viafb_fill_var_timing_info(struct fb_var_screeninfo *var, int refresh,
        var->lower_margin = crt_reg.ver_sync_start - crt_reg.ver_addr;
        var->vsync_len = crt_reg.ver_sync_end;
        var->sync = 0;
-       if (crt_timing[index].h_sync_polarity == POSITIVE)
+       if (mode->h_sync_polarity == POSITIVE)
                var->sync |= FB_SYNC_HOR_HIGH_ACT;
-       if (crt_timing[index].v_sync_polarity == POSITIVE)
+       if (mode->v_sync_polarity == POSITIVE)
                var->sync |= FB_SYNC_VERT_HIGH_ACT;
 }
index c7239eb83bae30aaad17e356b7a712d973751d50..4db5b6e8d8d092cfe4ad59f922010552277d40a0 100644 (file)
 #define VIA_HSYNC_NEGATIVE     0x01
 #define VIA_VSYNC_NEGATIVE     0x02
 
-/***************************************************
-* Definition IGA1 Design Method of CRTC Registers *
-****************************************************/
-#define IGA1_HOR_TOTAL_FORMULA(x)           (((x)/8)-5)
-#define IGA1_HOR_ADDR_FORMULA(x)            (((x)/8)-1)
-#define IGA1_HOR_BLANK_START_FORMULA(x)     (((x)/8)-1)
-#define IGA1_HOR_BLANK_END_FORMULA(x, y)     (((x+y)/8)-1)
-#define IGA1_HOR_SYNC_START_FORMULA(x)      ((x)/8)
-#define IGA1_HOR_SYNC_END_FORMULA(x, y)      ((x+y)/8)
-
-#define IGA1_VER_TOTAL_FORMULA(x)           ((x)-2)
-#define IGA1_VER_ADDR_FORMULA(x)            ((x)-1)
-#define IGA1_VER_BLANK_START_FORMULA(x)     ((x)-1)
-#define IGA1_VER_BLANK_END_FORMULA(x, y)     ((x+y)-1)
-#define IGA1_VER_SYNC_START_FORMULA(x)      ((x)-1)
-#define IGA1_VER_SYNC_END_FORMULA(x, y)      ((x+y)-1)
-
-/***************************************************
-** Definition IGA2 Design Method of CRTC Registers *
-****************************************************/
-#define IGA2_HOR_TOTAL_FORMULA(x)           ((x)-1)
-#define IGA2_HOR_ADDR_FORMULA(x)            ((x)-1)
-#define IGA2_HOR_BLANK_START_FORMULA(x)     ((x)-1)
-#define IGA2_HOR_BLANK_END_FORMULA(x, y)     ((x+y)-1)
-#define IGA2_HOR_SYNC_START_FORMULA(x)      ((x)-1)
-#define IGA2_HOR_SYNC_END_FORMULA(x, y)      ((x+y)-1)
-
-#define IGA2_VER_TOTAL_FORMULA(x)           ((x)-1)
-#define IGA2_VER_ADDR_FORMULA(x)            ((x)-1)
-#define IGA2_VER_BLANK_START_FORMULA(x)     ((x)-1)
-#define IGA2_VER_BLANK_END_FORMULA(x, y)     ((x+y)-1)
-#define IGA2_VER_SYNC_START_FORMULA(x)      ((x)-1)
-#define IGA2_VER_SYNC_END_FORMULA(x, y)      ((x+y)-1)
-
 /**********************************************************/
 /* Definition IGA2 Design Method of CRTC Shadow Registers */
 /**********************************************************/
 #define IGA2_VER_SYNC_START_SHADOW_FORMULA(x)      (x)
 #define IGA2_VER_SYNC_END_SHADOW_FORMULA(x, y)      (x+y)
 
-/* Define Register Number for IGA1 CRTC Timing */
-
-/* location: {CR00,0,7},{CR36,3,3} */
-#define IGA1_HOR_TOTAL_REG_NUM         2
-/* location: {CR01,0,7} */
-#define IGA1_HOR_ADDR_REG_NUM          1
-/* location: {CR02,0,7} */
-#define IGA1_HOR_BLANK_START_REG_NUM    1
-/* location: {CR03,0,4},{CR05,7,7},{CR33,5,5} */
-#define IGA1_HOR_BLANK_END_REG_NUM     3
-/* location: {CR04,0,7},{CR33,4,4} */
-#define IGA1_HOR_SYNC_START_REG_NUM    2
-/* location: {CR05,0,4} */
-#define IGA1_HOR_SYNC_END_REG_NUM       1
-/* location: {CR06,0,7},{CR07,0,0},{CR07,5,5},{CR35,0,0} */
-#define IGA1_VER_TOTAL_REG_NUM          4
-/* location: {CR12,0,7},{CR07,1,1},{CR07,6,6},{CR35,2,2} */
-#define IGA1_VER_ADDR_REG_NUM           4
-/* location: {CR15,0,7},{CR07,3,3},{CR09,5,5},{CR35,3,3} */
-#define IGA1_VER_BLANK_START_REG_NUM    4
-/* location: {CR16,0,7} */
-#define IGA1_VER_BLANK_END_REG_NUM      1
-/* location: {CR10,0,7},{CR07,2,2},{CR07,7,7},{CR35,1,1} */
-#define IGA1_VER_SYNC_START_REG_NUM     4
-/* location: {CR11,0,3} */
-#define IGA1_VER_SYNC_END_REG_NUM       1
-
 /* Define Register Number for IGA2 Shadow CRTC Timing */
 
 /* location: {CR6D,0,7},{CR71,3,3} */
 /* location: {CR76,0,3} */
 #define IGA2_SHADOW_VER_SYNC_END_REG_NUM    1
 
-/* Define Register Number for IGA2 CRTC Timing */
-
-/* location: {CR50,0,7},{CR55,0,3} */
-#define IGA2_HOR_TOTAL_REG_NUM          2
-/* location: {CR51,0,7},{CR55,4,6} */
-#define IGA2_HOR_ADDR_REG_NUM           2
-/* location: {CR52,0,7},{CR54,0,2} */
-#define IGA2_HOR_BLANK_START_REG_NUM    2
-/* location: CLE266: {CR53,0,7},{CR54,3,5} => CLE266's CR5D[6]
-is reserved, so it may have problem to set 1600x1200 on IGA2. */
-/*             Others: {CR53,0,7},{CR54,3,5},{CR5D,6,6} */
-#define IGA2_HOR_BLANK_END_REG_NUM      3
-/* location: {CR56,0,7},{CR54,6,7},{CR5C,7,7} */
-/* VT3314 and Later: {CR56,0,7},{CR54,6,7},{CR5C,7,7}, {CR5D,7,7} */
-#define IGA2_HOR_SYNC_START_REG_NUM     4
-
-/* location: {CR57,0,7},{CR5C,6,6} */
-#define IGA2_HOR_SYNC_END_REG_NUM       2
-/* location: {CR58,0,7},{CR5D,0,2} */
-#define IGA2_VER_TOTAL_REG_NUM          2
-/* location: {CR59,0,7},{CR5D,3,5} */
-#define IGA2_VER_ADDR_REG_NUM           2
-/* location: {CR5A,0,7},{CR5C,0,2} */
-#define IGA2_VER_BLANK_START_REG_NUM    2
-/* location: {CR5E,0,7},{CR5C,3,5} */
-#define IGA2_VER_BLANK_END_REG_NUM      2
-/* location: {CR5E,0,7},{CR5F,5,7} */
-#define IGA2_VER_SYNC_START_REG_NUM     2
-/* location: {CR5F,0,4} */
-#define IGA2_VER_SYNC_END_REG_NUM       1
-
 /* Define Fetch Count Register*/
 
 /* location: {SR1C,0,7},{SR1D,0,1} */
@@ -446,87 +354,12 @@ is reserved, so it may have problem to set 1600x1200 on IGA2. */
 /* location: {CR78,0,7},{CR79,6,7} */
 #define LCD_VER_SCALING_FACTOR_REG_NUM_CLE  2
 
-/************************************************
- *****     Define IGA1 Display Timing       *****
- ************************************************/
 struct io_register {
        u8 io_addr;
        u8 start_bit;
        u8 end_bit;
 };
 
-/* IGA1 Horizontal Total */
-struct iga1_hor_total {
-       int reg_num;
-       struct io_register reg[IGA1_HOR_TOTAL_REG_NUM];
-};
-
-/* IGA1 Horizontal Addressable Video */
-struct iga1_hor_addr {
-       int reg_num;
-       struct io_register reg[IGA1_HOR_ADDR_REG_NUM];
-};
-
-/* IGA1 Horizontal Blank Start */
-struct iga1_hor_blank_start {
-       int reg_num;
-       struct io_register reg[IGA1_HOR_BLANK_START_REG_NUM];
-};
-
-/* IGA1 Horizontal Blank End */
-struct iga1_hor_blank_end {
-       int reg_num;
-       struct io_register reg[IGA1_HOR_BLANK_END_REG_NUM];
-};
-
-/* IGA1 Horizontal Sync Start */
-struct iga1_hor_sync_start {
-       int reg_num;
-       struct io_register reg[IGA1_HOR_SYNC_START_REG_NUM];
-};
-
-/* IGA1 Horizontal Sync End */
-struct iga1_hor_sync_end {
-       int reg_num;
-       struct io_register reg[IGA1_HOR_SYNC_END_REG_NUM];
-};
-
-/* IGA1 Vertical Total */
-struct iga1_ver_total {
-       int reg_num;
-       struct io_register reg[IGA1_VER_TOTAL_REG_NUM];
-};
-
-/* IGA1 Vertical Addressable Video */
-struct iga1_ver_addr {
-       int reg_num;
-       struct io_register reg[IGA1_VER_ADDR_REG_NUM];
-};
-
-/* IGA1 Vertical Blank Start */
-struct iga1_ver_blank_start {
-       int reg_num;
-       struct io_register reg[IGA1_VER_BLANK_START_REG_NUM];
-};
-
-/* IGA1 Vertical Blank End */
-struct iga1_ver_blank_end {
-       int reg_num;
-       struct io_register reg[IGA1_VER_BLANK_END_REG_NUM];
-};
-
-/* IGA1 Vertical Sync Start */
-struct iga1_ver_sync_start {
-       int reg_num;
-       struct io_register reg[IGA1_VER_SYNC_START_REG_NUM];
-};
-
-/* IGA1 Vertical Sync End */
-struct iga1_ver_sync_end {
-       int reg_num;
-       struct io_register reg[IGA1_VER_SYNC_END_REG_NUM];
-};
-
 /*****************************************************
 **      Define IGA2 Shadow Display Timing         ****
 *****************************************************/
@@ -579,82 +412,6 @@ struct iga2_shadow_ver_sync_end {
        struct io_register reg[IGA2_SHADOW_VER_SYNC_END_REG_NUM];
 };
 
-/*****************************************************
-**      Define IGA2 Display Timing                ****
-******************************************************/
-
-/* IGA2 Horizontal Total */
-struct iga2_hor_total {
-       int reg_num;
-       struct io_register reg[IGA2_HOR_TOTAL_REG_NUM];
-};
-
-/* IGA2 Horizontal Addressable Video */
-struct iga2_hor_addr {
-       int reg_num;
-       struct io_register reg[IGA2_HOR_ADDR_REG_NUM];
-};
-
-/* IGA2 Horizontal Blank Start */
-struct iga2_hor_blank_start {
-       int reg_num;
-       struct io_register reg[IGA2_HOR_BLANK_START_REG_NUM];
-};
-
-/* IGA2 Horizontal Blank End */
-struct iga2_hor_blank_end {
-       int reg_num;
-       struct io_register reg[IGA2_HOR_BLANK_END_REG_NUM];
-};
-
-/* IGA2 Horizontal Sync Start */
-struct iga2_hor_sync_start {
-       int reg_num;
-       struct io_register reg[IGA2_HOR_SYNC_START_REG_NUM];
-};
-
-/* IGA2 Horizontal Sync End */
-struct iga2_hor_sync_end {
-       int reg_num;
-       struct io_register reg[IGA2_HOR_SYNC_END_REG_NUM];
-};
-
-/* IGA2 Vertical Total */
-struct iga2_ver_total {
-       int reg_num;
-       struct io_register reg[IGA2_VER_TOTAL_REG_NUM];
-};
-
-/* IGA2 Vertical Addressable Video */
-struct iga2_ver_addr {
-       int reg_num;
-       struct io_register reg[IGA2_VER_ADDR_REG_NUM];
-};
-
-/* IGA2 Vertical Blank Start */
-struct iga2_ver_blank_start {
-       int reg_num;
-       struct io_register reg[IGA2_VER_BLANK_START_REG_NUM];
-};
-
-/* IGA2 Vertical Blank End */
-struct iga2_ver_blank_end {
-       int reg_num;
-       struct io_register reg[IGA2_VER_BLANK_END_REG_NUM];
-};
-
-/* IGA2 Vertical Sync Start */
-struct iga2_ver_sync_start {
-       int reg_num;
-       struct io_register reg[IGA2_VER_SYNC_START_REG_NUM];
-};
-
-/* IGA2 Vertical Sync End */
-struct iga2_ver_sync_end {
-       int reg_num;
-       struct io_register reg[IGA2_VER_SYNC_END_REG_NUM];
-};
-
 /* IGA1 Fetch Count Register */
 struct iga1_fetch_count {
        int reg_num;
@@ -817,21 +574,6 @@ struct display_queue_expire_num {
         iga2_display_queue_expire_num_reg;
 };
 
-struct iga1_crtc_timing {
-       struct iga1_hor_total hor_total;
-       struct iga1_hor_addr hor_addr;
-       struct iga1_hor_blank_start hor_blank_start;
-       struct iga1_hor_blank_end hor_blank_end;
-       struct iga1_hor_sync_start hor_sync_start;
-       struct iga1_hor_sync_end hor_sync_end;
-       struct iga1_ver_total ver_total;
-       struct iga1_ver_addr ver_addr;
-       struct iga1_ver_blank_start ver_blank_start;
-       struct iga1_ver_blank_end ver_blank_end;
-       struct iga1_ver_sync_start ver_sync_start;
-       struct iga1_ver_sync_end ver_sync_end;
-};
-
 struct iga2_shadow_crtc_timing {
        struct iga2_shadow_hor_total hor_total_shadow;
        struct iga2_shadow_hor_blank_end hor_blank_end_shadow;
@@ -843,21 +585,6 @@ struct iga2_shadow_crtc_timing {
        struct iga2_shadow_ver_sync_end ver_sync_end_shadow;
 };
 
-struct iga2_crtc_timing {
-       struct iga2_hor_total hor_total;
-       struct iga2_hor_addr hor_addr;
-       struct iga2_hor_blank_start hor_blank_start;
-       struct iga2_hor_blank_end hor_blank_end;
-       struct iga2_hor_sync_start hor_sync_start;
-       struct iga2_hor_sync_end hor_sync_end;
-       struct iga2_ver_total ver_total;
-       struct iga2_ver_addr ver_addr;
-       struct iga2_ver_blank_start ver_blank_start;
-       struct iga2_ver_blank_end ver_blank_end;
-       struct iga2_ver_sync_start ver_sync_start;
-       struct iga2_ver_sync_end ver_sync_end;
-};
-
 /* device ID */
 #define CLE266_FUNCTION3    0x3123
 #define KM400_FUNCTION3     0x3205
@@ -910,9 +637,7 @@ extern int viafb_LCD_ON;
 extern int viafb_DVI_ON;
 extern int viafb_hotplug;
 
-void viafb_fill_crtc_timing(struct crt_mode_table *crt_table,
-       struct VideoModeTable *video_mode, int bpp_byte, int set_iga);
-
+void viafb_fill_crtc_timing(const struct fb_var_screeninfo *var, int iga);
 void viafb_set_vclock(u32 CLK, int set_iga);
 void viafb_load_reg(int timing_value, int viafb_load_reg_num,
        struct io_register *reg,
@@ -932,13 +657,11 @@ void viafb_load_FIFO_reg(int set_iga, int hor_active, int ver_active);
 void viafb_set_dpa_gfx(int output_interface, struct GFX_DPA_SETTING\
                                        *p_gfx_dpa_setting);
 
-int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp,
-       struct VideoModeTable *vmode_tbl1, int video_bpp1);
-void viafb_fill_var_timing_info(struct fb_var_screeninfo *var, int refresh,
-       struct VideoModeTable *vmode_tbl);
+int viafb_setmode(int video_bpp, int video_bpp1);
+void viafb_fill_var_timing_info(struct fb_var_screeninfo *var,
+       struct crt_mode_table *mode);
 void __devinit viafb_init_chip_info(int chip_type);
 void __devinit viafb_init_dac(int set_iga);
-int viafb_get_pixclock(int hres, int vres, int vmode_refresh);
 int viafb_get_refresh(int hres, int vres, u32 float_refresh);
 void viafb_update_device_setting(int hres, int vres, int bpp, int flag);
 
index 6e06981d638be99f44c0b5ef9fc5ef2d90cfb883..5f3b4e394e82133c8668bbdaada42d523fed2bc7 100644 (file)
@@ -548,9 +548,8 @@ static void lcd_patch_skew(struct lvds_setting_information
 }
 
 /* LCD Set Mode */
-void viafb_lcd_set_mode(struct crt_mode_table *mode_crt_table,
-                 struct lvds_setting_information *plvds_setting_info,
-                 struct lvds_chip_information *plvds_chip_info)
+void viafb_lcd_set_mode(struct lvds_setting_information *plvds_setting_info,
+       struct lvds_chip_information *plvds_chip_info)
 {
        int set_iga = plvds_setting_info->iga_path;
        int mode_bpp = plvds_setting_info->bpp;
@@ -559,16 +558,15 @@ void viafb_lcd_set_mode(struct crt_mode_table *mode_crt_table,
        int panel_hres = plvds_setting_info->lcd_panel_hres;
        int panel_vres = plvds_setting_info->lcd_panel_vres;
        u32 clock;
-       struct display_timing mode_crt_reg, panel_crt_reg;
-       struct crt_mode_table *panel_crt_table = NULL;
-       struct VideoModeTable *vmode_tbl = viafb_get_mode(panel_hres,
-               panel_vres);
+       struct display_timing mode_crt_reg, panel_crt_reg, timing;
+       struct crt_mode_table *mode_crt_table, *panel_crt_table;
 
        DEBUG_MSG(KERN_INFO "viafb_lcd_set_mode!!\n");
        /* Get mode table */
+       mode_crt_table = viafb_get_best_mode(set_hres, set_vres, 60);
        mode_crt_reg = mode_crt_table->crtc;
        /* Get panel table Pointer */
-       panel_crt_table = vmode_tbl->crtc;
+       panel_crt_table = viafb_get_best_mode(panel_hres, panel_vres, 60);
        panel_crt_reg = panel_crt_table->crtc;
        DEBUG_MSG(KERN_INFO "bellow viafb_lcd_set_mode!!\n");
        if (VT1636_LVDS == plvds_chip_info->lvds_chip_name)
@@ -576,31 +574,28 @@ void viafb_lcd_set_mode(struct crt_mode_table *mode_crt_table,
        clock = panel_crt_reg.hor_total * panel_crt_reg.ver_total
                * panel_crt_table->refresh_rate;
        plvds_setting_info->vclk = clock;
-       if (set_iga == IGA1) {
-               /* IGA1 doesn't have LCD scaling, so set it as centering. */
-               viafb_load_crtc_timing(lcd_centering_timging
-                                (mode_crt_reg, panel_crt_reg), IGA1);
+
+       if (set_iga == IGA2 && (set_hres < panel_hres || set_vres < panel_vres)
+               && plvds_setting_info->display_method == LCD_EXPANDSION) {
+               timing = panel_crt_reg;
+               load_lcd_scaling(set_hres, set_vres, panel_hres, panel_vres);
        } else {
-               /* Expansion */
-               if (plvds_setting_info->display_method == LCD_EXPANDSION
-                       && (set_hres < panel_hres || set_vres < panel_vres)) {
-                       /* expansion timing IGA2 loaded panel set timing*/
-                       viafb_load_crtc_timing(panel_crt_reg, IGA2);
-                       DEBUG_MSG(KERN_INFO "viafb_load_crtc_timing!!\n");
-                       load_lcd_scaling(set_hres, set_vres, panel_hres,
-                                        panel_vres);
-                       DEBUG_MSG(KERN_INFO "load_lcd_scaling!!\n");
-               } else {        /* Centering */
-                       /* centering timing IGA2 always loaded panel
-                          and mode releative timing */
-                       viafb_load_crtc_timing(lcd_centering_timging
-                                        (mode_crt_reg, panel_crt_reg), IGA2);
-                       viafb_write_reg_mask(CR79, VIACR, 0x00,
+               timing = lcd_centering_timging(mode_crt_reg, panel_crt_reg);
+               if (set_iga == IGA2)
+                       /* disable scaling */
+                       via_write_reg_mask(VIACR, 0x79, 0x00,
                                BIT0 + BIT1 + BIT2);
-                       /* LCD scaling disabled */
-               }
        }
 
+       timing.hor_blank_end += timing.hor_blank_start;
+       timing.hor_sync_end += timing.hor_sync_start;
+       timing.ver_blank_end += timing.ver_blank_start;
+       timing.ver_sync_end += timing.ver_sync_start;
+       if (set_iga == IGA1)
+               via_set_primary_timing(&timing);
+       else if (set_iga == IGA2)
+               via_set_secondary_timing(&timing);
+
        /* Fetch count for IGA2 only */
        viafb_load_fetch_count_reg(set_hres, mode_bpp / 8, set_iga);
 
index 75f60a655b0e09c334a77d8418a656edefb8c467..77ca7b862e6830b9f7ddaac37551c3c2b73fc3b9 100644 (file)
@@ -76,16 +76,13 @@ void __devinit viafb_init_lvds_output_interface(struct lvds_chip_information
                                *plvds_chip_info,
                                struct lvds_setting_information
                                *plvds_setting_info);
-void viafb_lcd_set_mode(struct crt_mode_table *mode_crt_table,
-                 struct lvds_setting_information *plvds_setting_info,
-                 struct lvds_chip_information *plvds_chip_info);
+void viafb_lcd_set_mode(struct lvds_setting_information *plvds_setting_info,
+       struct lvds_chip_information *plvds_chip_info);
 bool __devinit viafb_lvds_trasmitter_identify(void);
 void viafb_init_lvds_output_interface(struct lvds_chip_information
                                *plvds_chip_info,
                                struct lvds_setting_information
                                *plvds_setting_info);
 bool viafb_lcd_get_mobile_state(bool *mobile);
-void viafb_load_crtc_timing(struct display_timing device_timing,
-       int set_iga);
 
 #endif /* __LCD_H__ */
index 61b0bd596b85db28553cbae06bcdeb8f6d4128ca..69d882cbe7095f0acde27c9e61e12ea3236948d8 100644 (file)
@@ -22,6 +22,8 @@
 #ifndef __SHARE_H__
 #define __SHARE_H__
 
+#include "via_modesetting.h"
+
 /* Define Bit Field */
 #define BIT0    0x01
 #define BIT1    0x02
 #define V_SYNC_SATRT_SHADOW_INDEX   18
 #define V_SYNC_END_SHADOW_INDEX     19
 
-/* Definition Video Mode Pixel Clock (picoseconds)
-*/
-#define RES_640X480_60HZ_PIXCLOCK    39722
-
 /* LCD display method
 */
 #define     LCD_EXPANDSION              0x00
 #define     LCD_OPENLDI               0x00
 #define     LCD_SPWG                  0x01
 
-/* Define display timing
-*/
-struct display_timing {
-       u16 hor_total;
-       u16 hor_addr;
-       u16 hor_blank_start;
-       u16 hor_blank_end;
-       u16 hor_sync_start;
-       u16 hor_sync_end;
-       u16 ver_total;
-       u16 ver_addr;
-       u16 ver_blank_start;
-       u16 ver_blank_end;
-       u16 ver_sync_start;
-       u16 ver_sync_end;
-};
-
 struct crt_mode_table {
        int refresh_rate;
        int h_sync_polarity;
index eb112b62173565984c28e68b400b40f798b1877e..dd58b530c0dffde2a1f511a059cb6bc42279f7c9 100644 (file)
@@ -35,7 +35,7 @@ static struct via_port_cfg adap_configs[] = {
  * The OLPC XO-1.5 puts the camera power and reset lines onto
  * GPIO 2C.
  */
-static const struct via_port_cfg olpc_adap_configs[] = {
+static struct via_port_cfg olpc_adap_configs[] = {
        [VIA_PORT_26]   = { VIA_PORT_I2C,  VIA_MODE_I2C, VIASR, 0x26 },
        [VIA_PORT_31]   = { VIA_PORT_I2C,  VIA_MODE_I2C, VIASR, 0x31 },
        [VIA_PORT_25]   = { VIA_PORT_GPIO, VIA_MODE_GPIO, VIASR, 0x25 },
index 3cddcff88ab90400b8bf4b58cd7f14b7bf9b099f..0e431aee17bbcc83a330ffdda6623d477a84ac8f 100644 (file)
 #include "share.h"
 #include "debug.h"
 
+
+void via_set_primary_timing(const struct display_timing *timing)
+{
+       struct display_timing raw;
+
+       raw.hor_total = timing->hor_total / 8 - 5;
+       raw.hor_addr = timing->hor_addr / 8 - 1;
+       raw.hor_blank_start = timing->hor_blank_start / 8 - 1;
+       raw.hor_blank_end = timing->hor_blank_end / 8 - 1;
+       raw.hor_sync_start = timing->hor_sync_start / 8;
+       raw.hor_sync_end = timing->hor_sync_end / 8;
+       raw.ver_total = timing->ver_total - 2;
+       raw.ver_addr = timing->ver_addr - 1;
+       raw.ver_blank_start = timing->ver_blank_start - 1;
+       raw.ver_blank_end = timing->ver_blank_end - 1;
+       raw.ver_sync_start = timing->ver_sync_start - 1;
+       raw.ver_sync_end = timing->ver_sync_end - 1;
+
+       /* unlock timing registers */
+       via_write_reg_mask(VIACR, 0x11, 0x00, 0x80);
+
+       via_write_reg(VIACR, 0x00, raw.hor_total & 0xFF);
+       via_write_reg(VIACR, 0x01, raw.hor_addr & 0xFF);
+       via_write_reg(VIACR, 0x02, raw.hor_blank_start & 0xFF);
+       via_write_reg_mask(VIACR, 0x03, raw.hor_blank_end & 0x1F, 0x1F);
+       via_write_reg(VIACR, 0x04, raw.hor_sync_start & 0xFF);
+       via_write_reg_mask(VIACR, 0x05, (raw.hor_sync_end & 0x1F)
+               | (raw.hor_blank_end << (7 - 5) & 0x80), 0x9F);
+       via_write_reg(VIACR, 0x06, raw.ver_total & 0xFF);
+       via_write_reg_mask(VIACR, 0x07, (raw.ver_total >> 8 & 0x01)
+               | (raw.ver_addr >> (8 - 1) & 0x02)
+               | (raw.ver_sync_start >> (8 - 2) & 0x04)
+               | (raw.ver_blank_start >> (8 - 3) & 0x08)
+               | (raw.ver_total >> (9 - 5) & 0x20)
+               | (raw.ver_addr >> (9 - 6) & 0x40)
+               | (raw.ver_sync_start >> (9 - 7) & 0x80), 0xEF);
+       via_write_reg_mask(VIACR, 0x09, raw.ver_blank_start >> (9 - 5) & 0x20,
+               0x20);
+       via_write_reg(VIACR, 0x10, raw.ver_sync_start & 0xFF);
+       via_write_reg_mask(VIACR, 0x11, raw.ver_sync_end & 0x0F, 0x0F);
+       via_write_reg(VIACR, 0x12, raw.ver_addr & 0xFF);
+       via_write_reg(VIACR, 0x15, raw.ver_blank_start & 0xFF);
+       via_write_reg(VIACR, 0x16, raw.ver_blank_end & 0xFF);
+       via_write_reg_mask(VIACR, 0x33, (raw.hor_sync_start >> (8 - 4) & 0x10)
+               | (raw.hor_blank_end >> (6 - 5) & 0x20), 0x30);
+       via_write_reg_mask(VIACR, 0x35, (raw.ver_total >> 10 & 0x01)
+               | (raw.ver_sync_start >> (10 - 1) & 0x02)
+               | (raw.ver_addr >> (10 - 2) & 0x04)
+               | (raw.ver_blank_start >> (10 - 3) & 0x08), 0x0F);
+       via_write_reg_mask(VIACR, 0x36, raw.hor_total >> (8 - 3) & 0x08, 0x08);
+
+       /* lock timing registers */
+       via_write_reg_mask(VIACR, 0x11, 0x80, 0x80);
+
+       /* reset timing control */
+       via_write_reg_mask(VIACR, 0x17, 0x00, 0x80);
+       via_write_reg_mask(VIACR, 0x17, 0x80, 0x80);
+}
+
+void via_set_secondary_timing(const struct display_timing *timing)
+{
+       struct display_timing raw;
+
+       raw.hor_total = timing->hor_total - 1;
+       raw.hor_addr = timing->hor_addr - 1;
+       raw.hor_blank_start = timing->hor_blank_start - 1;
+       raw.hor_blank_end = timing->hor_blank_end - 1;
+       raw.hor_sync_start = timing->hor_sync_start - 1;
+       raw.hor_sync_end = timing->hor_sync_end - 1;
+       raw.ver_total = timing->ver_total - 1;
+       raw.ver_addr = timing->ver_addr - 1;
+       raw.ver_blank_start = timing->ver_blank_start - 1;
+       raw.ver_blank_end = timing->ver_blank_end - 1;
+       raw.ver_sync_start = timing->ver_sync_start - 1;
+       raw.ver_sync_end = timing->ver_sync_end - 1;
+
+       via_write_reg(VIACR, 0x50, raw.hor_total & 0xFF);
+       via_write_reg(VIACR, 0x51, raw.hor_addr & 0xFF);
+       via_write_reg(VIACR, 0x52, raw.hor_blank_start & 0xFF);
+       via_write_reg(VIACR, 0x53, raw.hor_blank_end & 0xFF);
+       via_write_reg(VIACR, 0x54, (raw.hor_blank_start >> 8 & 0x07)
+               | (raw.hor_blank_end >> (8 - 3) & 0x38)
+               | (raw.hor_sync_start >> (8 - 6) & 0xC0));
+       via_write_reg_mask(VIACR, 0x55, (raw.hor_total >> 8 & 0x0F)
+               | (raw.hor_addr >> (8 - 4) & 0x70), 0x7F);
+       via_write_reg(VIACR, 0x56, raw.hor_sync_start & 0xFF);
+       via_write_reg(VIACR, 0x57, raw.hor_sync_end & 0xFF);
+       via_write_reg(VIACR, 0x58, raw.ver_total & 0xFF);
+       via_write_reg(VIACR, 0x59, raw.ver_addr & 0xFF);
+       via_write_reg(VIACR, 0x5A, raw.ver_blank_start & 0xFF);
+       via_write_reg(VIACR, 0x5B, raw.ver_blank_end & 0xFF);
+       via_write_reg(VIACR, 0x5C, (raw.ver_blank_start >> 8 & 0x07)
+               | (raw.ver_blank_end >> (8 - 3) & 0x38)
+               | (raw.hor_sync_end >> (8 - 6) & 0x40)
+               | (raw.hor_sync_start >> (10 - 7) & 0x80));
+       via_write_reg(VIACR, 0x5D, (raw.ver_total >> 8 & 0x07)
+               | (raw.ver_addr >> (8 - 3) & 0x38)
+               | (raw.hor_blank_end >> (11 - 6) & 0x40)
+               | (raw.hor_sync_start >> (11 - 7) & 0x80));
+       via_write_reg(VIACR, 0x5E, raw.ver_sync_start & 0xFF);
+       via_write_reg(VIACR, 0x5F, (raw.ver_sync_end & 0x1F)
+               | (raw.ver_sync_start >> (8 - 5) & 0xE0));
+}
+
 void via_set_primary_address(u32 addr)
 {
        DEBUG_MSG(KERN_DEBUG "via_set_primary_address(0x%08X)\n", addr);
index ae35cfdeb37cd0de853c9f1c82b1fc7614011fed..06e09fe351ae86a209b139e88687d1f8f8f9d7e2 100644 (file)
 
 #include <linux/types.h>
 
+
+#define VIA_PITCH_SIZE (1<<3)
+#define VIA_PITCH_MAX  0x3FF8
+
+
+struct display_timing {
+       u16 hor_total;
+       u16 hor_addr;
+       u16 hor_blank_start;
+       u16 hor_blank_end;
+       u16 hor_sync_start;
+       u16 hor_sync_end;
+       u16 ver_total;
+       u16 ver_addr;
+       u16 ver_blank_start;
+       u16 ver_blank_end;
+       u16 ver_sync_start;
+       u16 ver_sync_end;
+};
+
+
+void via_set_primary_timing(const struct display_timing *timing);
+void via_set_secondary_timing(const struct display_timing *timing);
 void via_set_primary_address(u32 addr);
 void via_set_secondary_address(u32 addr);
 void via_set_primary_pitch(u32 pitch);
index 53aa4430d86ea74cb525a1adc37484ee60c07b07..a13c258bd32f45ed1abe7126fdc3728b1657b5e7 100644 (file)
@@ -38,8 +38,6 @@ static char *viafb_mode1;
 static int viafb_bpp = 32;
 static int viafb_bpp1 = 32;
 
-static unsigned int viafb_second_xres = 640;
-static unsigned int viafb_second_yres = 480;
 static unsigned int viafb_second_offset;
 static int viafb_second_size;
 
@@ -151,7 +149,8 @@ static void viafb_update_fix(struct fb_info *info)
 
        info->fix.visual =
                bpp == 8 ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
-       info->fix.line_length = (info->var.xres_virtual * bpp / 8 + 7) & ~7;
+       info->fix.line_length = ALIGN(info->var.xres_virtual * bpp / 8,
+               VIA_PITCH_SIZE);
 }
 
 static void viafb_setup_fixinfo(struct fb_fix_screeninfo *fix,
@@ -200,7 +199,6 @@ static int viafb_check_var(struct fb_var_screeninfo *var,
        struct fb_info *info)
 {
        int depth, refresh;
-       struct VideoModeTable *vmode_entry;
        struct viafb_par *ppar = info->par;
        u32 line;
 
@@ -210,8 +208,10 @@ static int viafb_check_var(struct fb_var_screeninfo *var,
        if (var->vmode & FB_VMODE_INTERLACED || var->vmode & FB_VMODE_DOUBLE)
                return -EINVAL;
 
-       vmode_entry = viafb_get_mode(var->xres, var->yres);
-       if (!vmode_entry) {
+       /* the refresh rate is not important here, as we only want to know
+        * whether the resolution exists
+        */
+       if (!viafb_get_best_mode(var->xres, var->yres, 60)) {
                DEBUG_MSG(KERN_INFO
                          "viafb: Mode %dx%dx%d not supported!!\n",
                          var->xres, var->yres, var->bits_per_pixel);
@@ -238,8 +238,12 @@ static int viafb_check_var(struct fb_var_screeninfo *var,
                depth = 24;
 
        viafb_fill_var_color_info(var, depth);
-       line = (var->xres_virtual * var->bits_per_pixel / 8 + 7) & ~7;
-       if (line * var->yres_virtual > ppar->memsize)
+       if (var->xres_virtual < var->xres)
+               var->xres_virtual = var->xres;
+
+       line = ALIGN(var->xres_virtual * var->bits_per_pixel / 8,
+               VIA_PITCH_SIZE);
+       if (line > VIA_PITCH_MAX || line * var->yres_virtual > ppar->memsize)
                return -EINVAL;
 
        /* Based on var passed in to calculate the refresh,
@@ -249,7 +253,8 @@ static int viafb_check_var(struct fb_var_screeninfo *var,
                get_var_refresh(var));
 
        /* Adjust var according to our driver's own table */
-       viafb_fill_var_timing_info(var, refresh, vmode_entry);
+       viafb_fill_var_timing_info(var,
+               viafb_get_best_mode(var->xres, var->yres, refresh));
        if (var->accel_flags & FB_ACCELF_TEXT &&
                !ppar->shared->vdev->engine_mmio)
                var->accel_flags = 0;
@@ -260,7 +265,6 @@ static int viafb_check_var(struct fb_var_screeninfo *var,
 static int viafb_set_par(struct fb_info *info)
 {
        struct viafb_par *viapar = info->par;
-       struct VideoModeTable *vmode_entry, *vmode_entry1 = NULL;
        int refresh;
        DEBUG_MSG(KERN_INFO "viafb_set_par!\n");
 
@@ -269,10 +273,7 @@ static int viafb_set_par(struct fb_info *info)
        viafb_update_device_setting(viafbinfo->var.xres, viafbinfo->var.yres,
                viafbinfo->var.bits_per_pixel, 0);
 
-       vmode_entry = viafb_get_mode(viafbinfo->var.xres, viafbinfo->var.yres);
        if (viafb_dual_fb) {
-               vmode_entry1 = viafb_get_mode(viafbinfo1->var.xres,
-                       viafbinfo1->var.yres);
                viafb_update_device_setting(viafbinfo1->var.xres,
                        viafbinfo1->var.yres, viafbinfo1->var.bits_per_pixel,
                        1);
@@ -280,8 +281,6 @@ static int viafb_set_par(struct fb_info *info)
                DEBUG_MSG(KERN_INFO
                "viafb_second_xres = %d, viafb_second_yres = %d, bpp = %d\n",
                          viafb_second_xres, viafb_second_yres, viafb_bpp1);
-               vmode_entry1 = viafb_get_mode(viafb_second_xres,
-                       viafb_second_yres);
 
                viafb_update_device_setting(viafb_second_xres,
                        viafb_second_yres, viafb_bpp1, 1);
@@ -289,7 +288,8 @@ static int viafb_set_par(struct fb_info *info)
 
        refresh = viafb_get_refresh(info->var.xres, info->var.yres,
                get_var_refresh(&info->var));
-       if (vmode_entry) {
+       if (viafb_get_best_mode(viafbinfo->var.xres, viafbinfo->var.yres,
+               refresh)) {
                if (viafb_dual_fb && viapar->iga_path == IGA2) {
                        viafb_bpp1 = info->var.bits_per_pixel;
                        viafb_refresh1 = refresh;
@@ -302,8 +302,7 @@ static int viafb_set_par(struct fb_info *info)
                        info->flags &= ~FBINFO_HWACCEL_DISABLED;
                else
                        info->flags |= FBINFO_HWACCEL_DISABLED;
-               viafb_setmode(vmode_entry, info->var.bits_per_pixel,
-                       vmode_entry1, viafb_bpp1);
+               viafb_setmode(info->var.bits_per_pixel, viafb_bpp1);
                viafb_pan_display(&info->var, info);
        }
 
@@ -348,8 +347,9 @@ static int viafb_pan_display(struct fb_var_screeninfo *var,
        struct fb_info *info)
 {
        struct viafb_par *viapar = info->par;
-       u32 vram_addr = (var->yoffset * var->xres_virtual + var->xoffset)
-               * (var->bits_per_pixel / 8) + viapar->vram_addr;
+       u32 vram_addr = viapar->vram_addr
+               + var->yoffset * info->fix.line_length
+               + var->xoffset * info->var.bits_per_pixel / 8;
 
        DEBUG_MSG(KERN_DEBUG "viafb_pan_display, address = %d\n", vram_addr);
        if (!viafb_dual_fb) {
@@ -1158,7 +1158,8 @@ static ssize_t viafb_dvp0_proc_write(struct file *file,
        for (i = 0; i < 3; i++) {
                value = strsep(&pbuf, " ");
                if (value != NULL) {
-                       strict_strtoul(value, 0, (unsigned long *)&reg_val);
+                       if (kstrtou8(value, 0, &reg_val) < 0)
+                               return -EINVAL;
                        DEBUG_MSG(KERN_INFO "DVP0:reg_val[%l]=:%x\n", i,
                                  reg_val);
                        switch (i) {
@@ -1228,7 +1229,8 @@ static ssize_t viafb_dvp1_proc_write(struct file *file,
        for (i = 0; i < 3; i++) {
                value = strsep(&pbuf, " ");
                if (value != NULL) {
-                       strict_strtoul(value, 0, (unsigned long *)&reg_val);
+                       if (kstrtou8(value, 0, &reg_val) < 0)
+                               return -EINVAL;
                        switch (i) {
                        case 0:
                                viafb_write_reg_mask(CR9B, VIACR,
@@ -1286,7 +1288,8 @@ static ssize_t viafb_dfph_proc_write(struct file *file,
        if (copy_from_user(&buf[0], buffer, length))
                return -EFAULT;
        buf[length - 1] = '\0'; /*Ensure end string */
-       strict_strtoul(&buf[0], 0, (unsigned long *)&reg_val);
+       if (kstrtou8(buf, 0, &reg_val) < 0)
+               return -EINVAL;
        viafb_write_reg_mask(CR97, VIACR, reg_val, 0x0f);
        return count;
 }
@@ -1325,7 +1328,8 @@ static ssize_t viafb_dfpl_proc_write(struct file *file,
        if (copy_from_user(&buf[0], buffer, length))
                return -EFAULT;
        buf[length - 1] = '\0'; /*Ensure end string */
-       strict_strtoul(&buf[0], 0, (unsigned long *)&reg_val);
+       if (kstrtou8(buf, 0, &reg_val) < 0)
+               return -EINVAL;
        viafb_write_reg_mask(CR99, VIACR, reg_val, 0x0f);
        return count;
 }
@@ -1394,8 +1398,8 @@ static ssize_t viafb_vt1636_proc_write(struct file *file,
                for (i = 0; i < 2; i++) {
                        value = strsep(&pbuf, " ");
                        if (value != NULL) {
-                               strict_strtoul(value, 0,
-                                       (unsigned long *)&reg_val.Data);
+                               if (kstrtou8(value, 0, &reg_val.Data) < 0)
+                                       return -EINVAL;
                                switch (i) {
                                case 0:
                                        reg_val.Index = 0x08;
@@ -1431,8 +1435,8 @@ static ssize_t viafb_vt1636_proc_write(struct file *file,
                for (i = 0; i < 2; i++) {
                        value = strsep(&pbuf, " ");
                        if (value != NULL) {
-                               strict_strtoul(value, 0,
-                                       (unsigned long *)&reg_val.Data);
+                               if (kstrtou8(value, 0, &reg_val.Data) < 0)
+                                       return -EINVAL;
                                switch (i) {
                                case 0:
                                        reg_val.Index = 0x08;
@@ -1729,7 +1733,6 @@ static struct viafb_pm_hooks viafb_fb_pm_hooks = {
 int __devinit via_fb_pci_probe(struct viafb_dev *vdev)
 {
        u32 default_xres, default_yres;
-       struct VideoModeTable *vmode_entry;
        struct fb_var_screeninfo default_var;
        int rc;
        u32 viafb_par_length;
@@ -1802,7 +1805,6 @@ int __devinit via_fb_pci_probe(struct viafb_dev *vdev)
        }
 
        parse_mode(viafb_mode, &default_xres, &default_yres);
-       vmode_entry = viafb_get_mode(default_xres, default_yres);
        if (viafb_SAMM_ON == 1)
                parse_mode(viafb_mode1, &viafb_second_xres,
                        &viafb_second_yres);
@@ -1812,9 +1814,8 @@ int __devinit via_fb_pci_probe(struct viafb_dev *vdev)
        default_var.xres_virtual = default_xres;
        default_var.yres_virtual = default_yres;
        default_var.bits_per_pixel = viafb_bpp;
-       viafb_fill_var_timing_info(&default_var, viafb_get_refresh(
-               default_var.xres, default_var.yres, viafb_refresh),
-               viafb_get_mode(default_var.xres, default_var.yres));
+       viafb_fill_var_timing_info(&default_var, viafb_get_best_mode(
+               default_var.xres, default_var.yres, viafb_refresh));
        viafb_setup_fixinfo(&viafbinfo->fix, viaparinfo);
        viafbinfo->var = default_var;
 
@@ -1853,9 +1854,8 @@ int __devinit via_fb_pci_probe(struct viafb_dev *vdev)
                default_var.xres_virtual = viafb_second_xres;
                default_var.yres_virtual = viafb_second_yres;
                default_var.bits_per_pixel = viafb_bpp1;
-               viafb_fill_var_timing_info(&default_var, viafb_get_refresh(
-                       default_var.xres, default_var.yres, viafb_refresh1),
-                       viafb_get_mode(default_var.xres, default_var.yres));
+               viafb_fill_var_timing_info(&default_var, viafb_get_best_mode(
+                       default_var.xres, default_var.yres, viafb_refresh1));
 
                viafb_setup_fixinfo(&viafbinfo1->fix, viaparinfo1);
                viafb_check_var(&default_var, viafbinfo1);
@@ -1950,61 +1950,67 @@ static int __init viafb_setup(void)
                if (!*this_opt)
                        continue;
 
-               if (!strncmp(this_opt, "viafb_mode1=", 12))
+               if (!strncmp(this_opt, "viafb_mode1=", 12)) {
                        viafb_mode1 = kstrdup(this_opt + 12, GFP_KERNEL);
-               else if (!strncmp(this_opt, "viafb_mode=", 11))
+               } else if (!strncmp(this_opt, "viafb_mode=", 11)) {
                        viafb_mode = kstrdup(this_opt + 11, GFP_KERNEL);
-               else if (!strncmp(this_opt, "viafb_bpp1=", 11))
-                       strict_strtoul(this_opt + 11, 0,
-                               (unsigned long *)&viafb_bpp1);
-               else if (!strncmp(this_opt, "viafb_bpp=", 10))
-                       strict_strtoul(this_opt + 10, 0,
-                               (unsigned long *)&viafb_bpp);
-               else if (!strncmp(this_opt, "viafb_refresh1=", 15))
-                       strict_strtoul(this_opt + 15, 0,
-                               (unsigned long *)&viafb_refresh1);
-               else if (!strncmp(this_opt, "viafb_refresh=", 14))
-                       strict_strtoul(this_opt + 14, 0,
-                               (unsigned long *)&viafb_refresh);
-               else if (!strncmp(this_opt, "viafb_lcd_dsp_method=", 21))
-                       strict_strtoul(this_opt + 21, 0,
-                               (unsigned long *)&viafb_lcd_dsp_method);
-               else if (!strncmp(this_opt, "viafb_lcd_panel_id=", 19))
-                       strict_strtoul(this_opt + 19, 0,
-                               (unsigned long *)&viafb_lcd_panel_id);
-               else if (!strncmp(this_opt, "viafb_accel=", 12))
-                       strict_strtoul(this_opt + 12, 0,
-                               (unsigned long *)&viafb_accel);
-               else if (!strncmp(this_opt, "viafb_SAMM_ON=", 14))
-                       strict_strtoul(this_opt + 14, 0,
-                               (unsigned long *)&viafb_SAMM_ON);
-               else if (!strncmp(this_opt, "viafb_active_dev=", 17))
+               } else if (!strncmp(this_opt, "viafb_bpp1=", 11)) {
+                       if (kstrtouint(this_opt + 11, 0, &viafb_bpp1) < 0)
+                               return -EINVAL;
+               } else if (!strncmp(this_opt, "viafb_bpp=", 10)) {
+                       if (kstrtouint(this_opt + 10, 0, &viafb_bpp) < 0)
+                               return -EINVAL;
+               } else if (!strncmp(this_opt, "viafb_refresh1=", 15)) {
+                       if (kstrtoint(this_opt + 15, 0, &viafb_refresh1) < 0)
+                               return -EINVAL;
+               } else if (!strncmp(this_opt, "viafb_refresh=", 14)) {
+                       if (kstrtoint(this_opt + 14, 0, &viafb_refresh) < 0)
+                               return -EINVAL;
+               } else if (!strncmp(this_opt, "viafb_lcd_dsp_method=", 21)) {
+                       if (kstrtoint(this_opt + 21, 0,
+                                     &viafb_lcd_dsp_method) < 0)
+                               return -EINVAL;
+               } else if (!strncmp(this_opt, "viafb_lcd_panel_id=", 19)) {
+                       if (kstrtoint(this_opt + 19, 0,
+                                     &viafb_lcd_panel_id) < 0)
+                               return -EINVAL;
+               } else if (!strncmp(this_opt, "viafb_accel=", 12)) {
+                       if (kstrtoint(this_opt + 12, 0, &viafb_accel) < 0)
+                               return -EINVAL;
+               } else if (!strncmp(this_opt, "viafb_SAMM_ON=", 14)) {
+                       if (kstrtoint(this_opt + 14, 0, &viafb_SAMM_ON) < 0)
+                               return -EINVAL;
+               } else if (!strncmp(this_opt, "viafb_active_dev=", 17)) {
                        viafb_active_dev = kstrdup(this_opt + 17, GFP_KERNEL);
-               else if (!strncmp(this_opt,
-                       "viafb_display_hardware_layout=", 30))
-                       strict_strtoul(this_opt + 30, 0,
-                       (unsigned long *)&viafb_display_hardware_layout);
-               else if (!strncmp(this_opt, "viafb_second_size=", 18))
-                       strict_strtoul(this_opt + 18, 0,
-                               (unsigned long *)&viafb_second_size);
-               else if (!strncmp(this_opt,
-                       "viafb_platform_epia_dvi=", 24))
-                       strict_strtoul(this_opt + 24, 0,
-                               (unsigned long *)&viafb_platform_epia_dvi);
-               else if (!strncmp(this_opt,
-                       "viafb_device_lcd_dualedge=", 26))
-                       strict_strtoul(this_opt + 26, 0,
-                               (unsigned long *)&viafb_device_lcd_dualedge);
-               else if (!strncmp(this_opt, "viafb_bus_width=", 16))
-                       strict_strtoul(this_opt + 16, 0,
-                               (unsigned long *)&viafb_bus_width);
-               else if (!strncmp(this_opt, "viafb_lcd_mode=", 15))
-                       strict_strtoul(this_opt + 15, 0,
-                               (unsigned long *)&viafb_lcd_mode);
-               else if (!strncmp(this_opt, "viafb_lcd_port=", 15))
+               } else if (!strncmp(this_opt,
+                       "viafb_display_hardware_layout=", 30)) {
+                       if (kstrtoint(this_opt + 30, 0,
+                                     &viafb_display_hardware_layout) < 0)
+                               return -EINVAL;
+               } else if (!strncmp(this_opt, "viafb_second_size=", 18)) {
+                       if (kstrtoint(this_opt + 18, 0, &viafb_second_size) < 0)
+                               return -EINVAL;
+               } else if (!strncmp(this_opt,
+                       "viafb_platform_epia_dvi=", 24)) {
+                       if (kstrtoint(this_opt + 24, 0,
+                                     &viafb_platform_epia_dvi) < 0)
+                               return -EINVAL;
+               } else if (!strncmp(this_opt,
+                       "viafb_device_lcd_dualedge=", 26)) {
+                       if (kstrtoint(this_opt + 26, 0,
+                                     &viafb_device_lcd_dualedge) < 0)
+                               return -EINVAL;
+               } else if (!strncmp(this_opt, "viafb_bus_width=", 16)) {
+                       if (kstrtoint(this_opt + 16, 0, &viafb_bus_width) < 0)
+                               return -EINVAL;
+               } else if (!strncmp(this_opt, "viafb_lcd_mode=", 15)) {
+                       if (kstrtoint(this_opt + 15, 0, &viafb_lcd_mode) < 0)
+                               return -EINVAL;
+               } else if (!strncmp(this_opt, "viafb_lcd_port=", 15)) {
                        viafb_lcd_port = kstrdup(this_opt + 15, GFP_KERNEL);
-               else if (!strncmp(this_opt, "viafb_dvi_port=", 15))
+               } else if (!strncmp(this_opt, "viafb_dvi_port=", 15)) {
                        viafb_dvi_port = kstrdup(this_opt + 15, GFP_KERNEL);
+               }
        }
        return 0;
 }
@@ -2028,9 +2034,9 @@ int __init viafb_init(void)
                return r;
 #endif
        if (parse_mode(viafb_mode, &dummy_x, &dummy_y)
-               || !viafb_get_mode(dummy_x, dummy_y)
+               || !viafb_get_best_mode(dummy_x, dummy_y, viafb_refresh)
                || parse_mode(viafb_mode1, &dummy_x, &dummy_y)
-               || !viafb_get_mode(dummy_x, dummy_y)
+               || !viafb_get_best_mode(dummy_x, dummy_y, viafb_refresh1)
                || viafb_bpp < 0 || viafb_bpp > 32
                || viafb_bpp1 < 0 || viafb_bpp1 > 32
                || parse_active_dev())
index 58df74e1417e0a744ddd2f822accf4647cfd48ba..0911cac1b2ffb9cd3731b0c77f3040f035231f04 100644 (file)
@@ -281,7 +281,7 @@ static struct crt_mode_table CRTM640x480[] = {
        /*r_rate,hsp,vsp */
        /*HT,  HA,  HBS, HBE, HSS, HSE, VT,  VA,  VBS, VBE, VSS, VSE */
        {REFRESH_60, M640X480_R60_HSP, M640X480_R60_VSP,
-        {800, 640, 648, 144, 656, 96, 525, 480, 480, 45, 490, 2} },
+        {800, 640, 640, 160, 656, 96, 525, 480, 480, 45, 490, 2} },
        {REFRESH_75, M640X480_R75_HSP, M640X480_R75_VSP,
         {840, 640, 640, 200, 656, 64, 500, 480, 480, 20, 481, 3} },
        {REFRESH_85, M640X480_R85_HSP, M640X480_R85_VSP,
@@ -863,26 +863,56 @@ int NUM_TOTAL_CLE266_ModeXregs = ARRAY_SIZE(CLE266_ModeXregs);
 int NUM_TOTAL_PATCH_MODE = ARRAY_SIZE(res_patch_table);
 
 
-struct VideoModeTable *viafb_get_mode(int hres, int vres)
+static struct VideoModeTable *get_modes(struct VideoModeTable *vmt, int n,
+       int hres, int vres)
 {
-       u32 i;
-       for (i = 0; i < ARRAY_SIZE(viafb_modes); i++)
-               if (viafb_modes[i].mode_array &&
-                       viafb_modes[i].crtc[0].crtc.hor_addr == hres &&
-                       viafb_modes[i].crtc[0].crtc.ver_addr == vres)
+       int i;
+
+       for (i = 0; i < n; i++)
+               if (vmt[i].mode_array &&
+                       vmt[i].crtc[0].crtc.hor_addr == hres &&
+                       vmt[i].crtc[0].crtc.ver_addr == vres)
                        return &viafb_modes[i];
 
        return NULL;
 }
 
-struct VideoModeTable *viafb_get_rb_mode(int hres, int vres)
+static struct crt_mode_table *get_best_mode(struct VideoModeTable *vmt,
+       int refresh)
 {
-       u32 i;
-       for (i = 0; i < ARRAY_SIZE(viafb_rb_modes); i++)
-               if (viafb_rb_modes[i].mode_array &&
-                       viafb_rb_modes[i].crtc[0].crtc.hor_addr == hres &&
-                       viafb_rb_modes[i].crtc[0].crtc.ver_addr == vres)
-                       return &viafb_rb_modes[i];
+       struct crt_mode_table *best;
+       int i;
 
-       return NULL;
+       if (!vmt)
+               return NULL;
+
+       best = &vmt->crtc[0];
+       for (i = 1; i < vmt->mode_array; i++) {
+               if (abs(vmt->crtc[i].refresh_rate - refresh)
+                       < abs(best->refresh_rate - refresh))
+                       best = &vmt->crtc[i];
+       }
+
+       return best;
+}
+
+static struct VideoModeTable *viafb_get_mode(int hres, int vres)
+{
+       return get_modes(viafb_modes, ARRAY_SIZE(viafb_modes), hres, vres);
+}
+
+struct crt_mode_table *viafb_get_best_mode(int hres, int vres, int refresh)
+{
+       return get_best_mode(viafb_get_mode(hres, vres), refresh);
+}
+
+static struct VideoModeTable *viafb_get_rb_mode(int hres, int vres)
+{
+       return get_modes(viafb_rb_modes, ARRAY_SIZE(viafb_rb_modes), hres,
+               vres);
+}
+
+struct crt_mode_table *viafb_get_best_rb_mode(int hres, int vres, int refresh)
+{
+       return get_best_mode(viafb_get_rb_mode(hres, vres), refresh);
 }
index 3751289eb4506a1faa2a87a187dd6737ce37c598..5917a2b00e1ba7b69dec0b0d3bcc262bfc4b9e0b 100644 (file)
@@ -60,7 +60,7 @@ extern struct io_reg PM1024x768[];
 extern struct patch_table res_patch_table[];
 extern struct VPITTable VPIT;
 
-struct VideoModeTable *viafb_get_mode(int hres, int vres);
-struct VideoModeTable *viafb_get_rb_mode(int hres, int vres);
+struct crt_mode_table *viafb_get_best_mode(int hres, int vres, int refresh);
+struct crt_mode_table *viafb_get_best_rb_mode(int hres, int vres, int refresh);
 
 #endif /* __VIAMODE_H__ */
index 0e120d67eb65074eb0f337ff9d29e10cdae134a3..777c21dd7a6ba8b126d4a63feec5765b48a24db7 100644 (file)
@@ -210,8 +210,8 @@ static int vt8500lcd_pan_display(struct fb_var_screeninfo *var,
        struct vt8500lcd_info *fbi = to_vt8500lcd_info(info);
 
        writel((1 << 31)
-               | (((var->xres_virtual - var->xres) * pixlen / 4) << 20)
-               | (off >> 2), fbi->regbase + 0x20);
+            | (((info->var.xres_virtual - info->var.xres) * pixlen / 4) << 20)
+            | (off >> 2), fbi->regbase + 0x20);
        return 0;
 }
 
@@ -355,7 +355,7 @@ static int __devinit vt8500lcd_probe(struct platform_device *pdev)
                goto failed_free_palette;
        }
 
-       ret = request_irq(irq, vt8500lcd_handle_irq, IRQF_DISABLED, "LCD", fbi);
+       ret = request_irq(irq, vt8500lcd_handle_irq, 0, "LCD", fbi);
        if (ret) {
                dev_err(&pdev->dev, "request_irq failed: %d\n", ret);
                ret = -EBUSY;
index f9b3e3dc24219fcdabcf9235a95720292c107c12..4e74d262cf3e9f338c1eb0cb46a5835794a532d3 100644 (file)
@@ -620,13 +620,14 @@ static int vt8623fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *i
        unsigned int offset;
 
        /* Calculate the offset */
-       if (var->bits_per_pixel == 0) {
-               offset = (var->yoffset / 16) * var->xres_virtual + var->xoffset;
+       if (info->var.bits_per_pixel == 0) {
+               offset = (var->yoffset / 16) * info->var.xres_virtual
+                      + var->xoffset;
                offset = offset >> 3;
        } else {
                offset = (var->yoffset * info->fix.line_length) +
-                        (var->xoffset * var->bits_per_pixel / 8);
-               offset = offset >> ((var->bits_per_pixel == 4) ? 2 : 1);
+                        (var->xoffset * info->var.bits_per_pixel / 8);
+               offset = offset >> ((info->var.bits_per_pixel == 4) ? 2 : 1);
        }
 
        /* Set the offset */
index 77dea015ff69a7524261296ea91ed33975b338a9..fcb6cd90f64d8ade134626076a622ac4a2a16118 100644 (file)
@@ -23,7 +23,6 @@
 #include <linux/device.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
-#include <linux/version.h>
 #include <linux/errno.h>
 #include <linux/string.h>
 #include <linux/mm.h>
index 9fe0b349f4cd9e58c6a4bef810239f2f149e0b39..5f4c45d4aa10ba4439ed6d6ee50db178b3637a52 100644 (file)
@@ -109,7 +109,7 @@ source "fs/proc/Kconfig"
 source "fs/sysfs/Kconfig"
 
 config TMPFS
-       bool "Virtual memory file system support (former shm fs)"
+       bool "Tmpfs virtual memory file system support (former shm fs)"
        depends on SHMEM
        help
          Tmpfs is a file system which keeps all files in virtual memory.
index e29ec485af255822b8414be128fc8ef66da9a204..632b235f4fbe02c237de17fbde271c8bfe6f1240 100644 (file)
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -1387,13 +1387,13 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
                ret = compat_rw_copy_check_uvector(type,
                                (struct compat_iovec __user *)kiocb->ki_buf,
                                kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
-                               &kiocb->ki_iovec);
+                               &kiocb->ki_iovec, 1);
        else
 #endif
                ret = rw_copy_check_uvector(type,
                                (struct iovec __user *)kiocb->ki_buf,
                                kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
-                               &kiocb->ki_iovec);
+                               &kiocb->ki_iovec, 1);
        if (ret < 0)
                goto out;
 
index 936d6035f6e2b81581ea95b7b54a65436a8e2280..70a19745cb61d1e1b1c92c26370668d298c15e13 100644 (file)
@@ -213,13 +213,16 @@ __find_get_block_slow(struct block_device *bdev, sector_t block)
         * elsewhere, don't buffer_error if we had some unmapped buffers
         */
        if (all_mapped) {
+               char b[BDEVNAME_SIZE];
+
                printk("__find_get_block_slow() failed. "
                        "block=%llu, b_blocknr=%llu\n",
                        (unsigned long long)block,
                        (unsigned long long)bh->b_blocknr);
                printk("b_state=0x%08lx, b_size=%zu\n",
                        bh->b_state, bh->b_size);
-               printk("device blocksize: %d\n", 1 << bd_inode->i_blkbits);
+               printk("device %s blocksize: %d\n", bdevname(bdev, b),
+                       1 << bd_inode->i_blkbits);
        }
 out_unlock:
        spin_unlock(&bd_mapping->private_lock);
index 5a3953db81184170a8f221fc6c231996993724d2..4144caf2f9d3a5ef95a7a9162b1de0cfa326cf4e 100644 (file)
@@ -228,102 +228,155 @@ static int ceph_readpage(struct file *filp, struct page *page)
 }
 
 /*
- * Build a vector of contiguous pages from the provided page list.
+ * Finish an async read(ahead) op.
  */
-static struct page **page_vector_from_list(struct list_head *page_list,
-                                          unsigned *nr_pages)
+static void finish_read(struct ceph_osd_request *req, struct ceph_msg *msg)
 {
-       struct page **pages;
-       struct page *page;
-       int next_index, contig_pages = 0;
+       struct inode *inode = req->r_inode;
+       struct ceph_osd_reply_head *replyhead;
+       int rc, bytes;
+       int i;
 
-       /* build page vector */
-       pages = kmalloc(sizeof(*pages) * *nr_pages, GFP_NOFS);
-       if (!pages)
-               return ERR_PTR(-ENOMEM);
+       /* parse reply */
+       replyhead = msg->front.iov_base;
+       WARN_ON(le32_to_cpu(replyhead->num_ops) == 0);
+       rc = le32_to_cpu(replyhead->result);
+       bytes = le32_to_cpu(msg->hdr.data_len);
 
-       BUG_ON(list_empty(page_list));
-       next_index = list_entry(page_list->prev, struct page, lru)->index;
-       list_for_each_entry_reverse(page, page_list, lru) {
-               if (page->index == next_index) {
-                       dout("readpages page %d %p\n", contig_pages, page);
-                       pages[contig_pages] = page;
-                       contig_pages++;
-                       next_index++;
-               } else {
-                       break;
+       dout("finish_read %p req %p rc %d bytes %d\n", inode, req, rc, bytes);
+
+       /* unlock all pages, zeroing any data we didn't read */
+       for (i = 0; i < req->r_num_pages; i++, bytes -= PAGE_CACHE_SIZE) {
+               struct page *page = req->r_pages[i];
+
+               if (bytes < (int)PAGE_CACHE_SIZE) {
+                       /* zero (remainder of) page */
+                       int s = bytes < 0 ? 0 : bytes;
+                       zero_user_segment(page, s, PAGE_CACHE_SIZE);
                }
+               dout("finish_read %p uptodate %p idx %lu\n", inode, page,
+                    page->index);
+               flush_dcache_page(page);
+               SetPageUptodate(page);
+               unlock_page(page);
+               page_cache_release(page);
        }
-       *nr_pages = contig_pages;
-       return pages;
+       kfree(req->r_pages);
 }
 
 /*
- * Read multiple pages.  Leave pages we don't read + unlock in page_list;
- * the caller (VM) cleans them up.
+ * start an async read(ahead) operation.  return nr_pages we submitted
+ * a read for on success, or negative error code.
  */
-static int ceph_readpages(struct file *file, struct address_space *mapping,
-                         struct list_head *page_list, unsigned nr_pages)
+static int start_read(struct inode *inode, struct list_head *page_list, int max)
 {
-       struct inode *inode = file->f_dentry->d_inode;
-       struct ceph_inode_info *ci = ceph_inode(inode);
        struct ceph_osd_client *osdc =
                &ceph_inode_to_client(inode)->client->osdc;
-       int rc = 0;
-       struct page **pages;
-       loff_t offset;
+       struct ceph_inode_info *ci = ceph_inode(inode);
+       struct page *page = list_entry(page_list->prev, struct page, lru);
+       struct ceph_osd_request *req;
+       u64 off;
        u64 len;
+       int i;
+       struct page **pages;
+       pgoff_t next_index;
+       int nr_pages = 0;
+       int ret;
 
-       dout("readpages %p file %p nr_pages %d\n",
-            inode, file, nr_pages);
-
-       pages = page_vector_from_list(page_list, &nr_pages);
-       if (IS_ERR(pages))
-               return PTR_ERR(pages);
+       off = page->index << PAGE_CACHE_SHIFT;
 
-       /* guess read extent */
-       offset = pages[0]->index << PAGE_CACHE_SHIFT;
+       /* count pages */
+       next_index = page->index;
+       list_for_each_entry_reverse(page, page_list, lru) {
+               if (page->index != next_index)
+                       break;
+               nr_pages++;
+               next_index++;
+               if (max && nr_pages == max)
+                       break;
+       }
        len = nr_pages << PAGE_CACHE_SHIFT;
-       rc = ceph_osdc_readpages(osdc, ceph_vino(inode), &ci->i_layout,
-                                offset, &len,
-                                ci->i_truncate_seq, ci->i_truncate_size,
-                                pages, nr_pages, 0);
-       if (rc == -ENOENT)
-               rc = 0;
-       if (rc < 0)
-               goto out;
-
-       for (; !list_empty(page_list) && len > 0;
-            rc -= PAGE_CACHE_SIZE, len -= PAGE_CACHE_SIZE) {
-               struct page *page =
-                       list_entry(page_list->prev, struct page, lru);
+       dout("start_read %p nr_pages %d is %lld~%lld\n", inode, nr_pages,
+            off, len);
+
+       req = ceph_osdc_new_request(osdc, &ci->i_layout, ceph_vino(inode),
+                                   off, &len,
+                                   CEPH_OSD_OP_READ, CEPH_OSD_FLAG_READ,
+                                   NULL, 0,
+                                   ci->i_truncate_seq, ci->i_truncate_size,
+                                   NULL, false, 1, 0);
+       if (!req)
+               return -ENOMEM;
 
+       /* build page vector */
+       nr_pages = len >> PAGE_CACHE_SHIFT;
+       pages = kmalloc(sizeof(*pages) * nr_pages, GFP_NOFS);
+       ret = -ENOMEM;
+       if (!pages)
+               goto out;
+       for (i = 0; i < nr_pages; ++i) {
+               page = list_entry(page_list->prev, struct page, lru);
+               BUG_ON(PageLocked(page));
                list_del(&page->lru);
-
-               if (rc < (int)PAGE_CACHE_SIZE) {
-                       /* zero (remainder of) page */
-                       int s = rc < 0 ? 0 : rc;
-                       zero_user_segment(page, s, PAGE_CACHE_SIZE);
-               }
-
-               if (add_to_page_cache_lru(page, mapping, page->index,
+               
+               dout("start_read %p adding %p idx %lu\n", inode, page,
+                    page->index);
+               if (add_to_page_cache_lru(page, &inode->i_data, page->index,
                                          GFP_NOFS)) {
                        page_cache_release(page);
-                       dout("readpages %p add_to_page_cache failed %p\n",
+                       dout("start_read %p add_to_page_cache failed %p\n",
                             inode, page);
-                       continue;
+                       nr_pages = i;
+                       goto out_pages;
                }
-               dout("readpages %p adding %p idx %lu\n", inode, page,
-                    page->index);
-               flush_dcache_page(page);
-               SetPageUptodate(page);
-               unlock_page(page);
-               page_cache_release(page);
+               pages[i] = page;
        }
-       rc = 0;
+       req->r_pages = pages;
+       req->r_num_pages = nr_pages;
+       req->r_callback = finish_read;
+       req->r_inode = inode;
+
+       dout("start_read %p starting %p %lld~%lld\n", inode, req, off, len);
+       ret = ceph_osdc_start_request(osdc, req, false);
+       if (ret < 0)
+               goto out_pages;
+       ceph_osdc_put_request(req);
+       return nr_pages;
 
+out_pages:
+       ceph_release_page_vector(pages, nr_pages);
+out:
+       ceph_osdc_put_request(req);
+       return ret;
+}
+
+
+/*
+ * Read multiple pages.  Leave pages we don't read + unlock in page_list;
+ * the caller (VM) cleans them up.
+ */
+static int ceph_readpages(struct file *file, struct address_space *mapping,
+                         struct list_head *page_list, unsigned nr_pages)
+{
+       struct inode *inode = file->f_dentry->d_inode;
+       struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
+       int rc = 0;
+       int max = 0;
+
+       if (fsc->mount_options->rsize >= PAGE_CACHE_SIZE)
+               max = (fsc->mount_options->rsize + PAGE_CACHE_SIZE - 1)
+                       >> PAGE_SHIFT;
+
+       dout("readpages %p file %p nr_pages %d max %d\n", inode, file, nr_pages,
+            max);
+       while (!list_empty(page_list)) {
+               rc = start_read(inode, page_list, max);
+               if (rc < 0)
+                       goto out;
+               BUG_ON(rc == 0);
+       }
 out:
-       kfree(pages);
+       dout("readpages %p file %p ret %d\n", inode, file, rc);
        return rc;
 }
 
index 8d74ad7ba556624c4eb80e1f598ac908e5356d04..b8731bf3ef1f01c9e728788cc23a9aaecb76bbca 100644 (file)
@@ -945,7 +945,7 @@ static int send_cap_msg(struct ceph_mds_session *session,
             seq, issue_seq, mseq, follows, size, max_size,
             xattr_version, xattrs_buf ? (int)xattrs_buf->vec.iov_len : 0);
 
-       msg = ceph_msg_new(CEPH_MSG_CLIENT_CAPS, sizeof(*fc), GFP_NOFS);
+       msg = ceph_msg_new(CEPH_MSG_CLIENT_CAPS, sizeof(*fc), GFP_NOFS, false);
        if (!msg)
                return -ENOMEM;
 
index 095799ba9dd1e02cba91a991561d9c0b69f609e3..5dde7d51dc1141ed04d692dddb55de431178aee8 100644 (file)
@@ -9,7 +9,6 @@
 #include <linux/namei.h>
 #include <linux/writeback.h>
 #include <linux/vmalloc.h>
-#include <linux/pagevec.h>
 
 #include "super.h"
 #include "mds_client.h"
@@ -1363,49 +1362,6 @@ void ceph_queue_invalidate(struct inode *inode)
        }
 }
 
-/*
- * invalidate any pages that are not dirty or under writeback.  this
- * includes pages that are clean and mapped.
- */
-static void ceph_invalidate_nondirty_pages(struct address_space *mapping)
-{
-       struct pagevec pvec;
-       pgoff_t next = 0;
-       int i;
-
-       pagevec_init(&pvec, 0);
-       while (pagevec_lookup(&pvec, mapping, next, PAGEVEC_SIZE)) {
-               for (i = 0; i < pagevec_count(&pvec); i++) {
-                       struct page *page = pvec.pages[i];
-                       pgoff_t index;
-                       int skip_page =
-                               (PageDirty(page) || PageWriteback(page));
-
-                       if (!skip_page)
-                               skip_page = !trylock_page(page);
-
-                       /*
-                        * We really shouldn't be looking at the ->index of an
-                        * unlocked page.  But we're not allowed to lock these
-                        * pages.  So we rely upon nobody altering the ->index
-                        * of this (pinned-by-us) page.
-                        */
-                       index = page->index;
-                       if (index > next)
-                               next = index;
-                       next++;
-
-                       if (skip_page)
-                               continue;
-
-                       generic_error_remove_page(mapping, page);
-                       unlock_page(page);
-               }
-               pagevec_release(&pvec);
-               cond_resched();
-       }
-}
-
 /*
  * Invalidate inode pages in a worker thread.  (This can't be done
  * in the message handler context.)
@@ -1429,7 +1385,7 @@ static void ceph_invalidate_work(struct work_struct *work)
        orig_gen = ci->i_rdcache_gen;
        spin_unlock(&inode->i_lock);
 
-       ceph_invalidate_nondirty_pages(inode->i_mapping);
+       truncate_inode_pages(&inode->i_data, 0);
 
        spin_lock(&inode->i_lock);
        if (orig_gen == ci->i_rdcache_gen &&
index 3b256b50f7d8e5c75be483877f881a57b7bbfc88..5a14c29cbba6f82b00ca42e8ac0327dbc12fd8bb 100644 (file)
@@ -42,17 +42,39 @@ static long ceph_ioctl_set_layout(struct file *file, void __user *arg)
        struct ceph_mds_client *mdsc = ceph_sb_to_client(inode->i_sb)->mdsc;
        struct ceph_mds_request *req;
        struct ceph_ioctl_layout l;
+       struct ceph_inode_info *ci = ceph_inode(file->f_dentry->d_inode);
+       struct ceph_ioctl_layout nl;
        int err, i;
 
-       /* copy and validate */
        if (copy_from_user(&l, arg, sizeof(l)))
                return -EFAULT;
 
-       if ((l.object_size & ~PAGE_MASK) ||
-           (l.stripe_unit & ~PAGE_MASK) ||
-           !l.stripe_unit ||
-           (l.object_size &&
-            (unsigned)l.object_size % (unsigned)l.stripe_unit))
+       /* validate changed params against current layout */
+       err = ceph_do_getattr(file->f_dentry->d_inode, CEPH_STAT_CAP_LAYOUT);
+       if (!err) {
+               nl.stripe_unit = ceph_file_layout_su(ci->i_layout);
+               nl.stripe_count = ceph_file_layout_stripe_count(ci->i_layout);
+               nl.object_size = ceph_file_layout_object_size(ci->i_layout);
+               nl.data_pool = le32_to_cpu(ci->i_layout.fl_pg_pool);
+               nl.preferred_osd =
+                               (s32)le32_to_cpu(ci->i_layout.fl_pg_preferred);
+       } else
+               return err;
+
+       if (l.stripe_count)
+               nl.stripe_count = l.stripe_count;
+       if (l.stripe_unit)
+               nl.stripe_unit = l.stripe_unit;
+       if (l.object_size)
+               nl.object_size = l.object_size;
+       if (l.data_pool)
+               nl.data_pool = l.data_pool;
+       if (l.preferred_osd)
+               nl.preferred_osd = l.preferred_osd;
+
+       if ((nl.object_size & ~PAGE_MASK) ||
+           (nl.stripe_unit & ~PAGE_MASK) ||
+           ((unsigned)nl.object_size % (unsigned)nl.stripe_unit))
                return -EINVAL;
 
        /* make sure it's a valid data pool */
index 0c5167e43180c9a0f41b24f39a35b0a4e5de1246..be4a604873331dc7c547950650a899b514f56d26 100644 (file)
@@ -6,7 +6,31 @@
 
 #define CEPH_IOCTL_MAGIC 0x97
 
-/* just use u64 to align sanely on all archs */
+/*
+ * CEPH_IOC_GET_LAYOUT - get file layout or dir layout policy
+ * CEPH_IOC_SET_LAYOUT - set file layout
+ * CEPH_IOC_SET_LAYOUT_POLICY - set dir layout policy
+ *
+ * The file layout specifies how file data is striped over objects in
+ * the distributed object store, which object pool they belong to (if
+ * it differs from the default), and an optional 'preferred osd' to
+ * store them on.
+ *
+ * Files get a new layout based on the policy set on the containing
+ * directory or one of its ancestors.  The GET_LAYOUT ioctl will let
+ * you examine the layout for a file or the policy on a directory.
+ *
+ * SET_LAYOUT will let you set a layout on a newly created file.  This
+ * only works immediately after the file is created and before any
+ * data is written to it.
+ *
+ * SET_LAYOUT_POLICY will let you set a layout policy (default layout)
+ * on a directory that will apply to any new files created in that
+ * directory (or any child directory that doesn't specify a layout of
+ * its own).
+ */
+
+/* use u64 to align sanely on all archs */
 struct ceph_ioctl_layout {
        __u64 stripe_unit, stripe_count, object_size;
        __u64 data_pool;
@@ -21,6 +45,8 @@ struct ceph_ioctl_layout {
                                   struct ceph_ioctl_layout)
 
 /*
+ * CEPH_IOC_GET_DATALOC - get location of file data in the cluster
+ *
  * Extract identity, address of the OSD and object storing a given
  * file offset.
  */
@@ -39,7 +65,34 @@ struct ceph_ioctl_dataloc {
 #define CEPH_IOC_GET_DATALOC _IOWR(CEPH_IOCTL_MAGIC, 3,        \
                                   struct ceph_ioctl_dataloc)
 
+/*
+ * CEPH_IOC_LAZYIO - relax consistency
+ *
+ * Normally Ceph switches to synchronous IO when multiple clients have
+ * the file open (and or more for write).  Reads and writes bypass the
+ * page cache and go directly to the OSD.  Setting this flag on a file
+ * descriptor will allow buffered IO for this file in cases where the
+ * application knows it won't interfere with other nodes (or doesn't
+ * care).
+ */
 #define CEPH_IOC_LAZYIO _IO(CEPH_IOCTL_MAGIC, 4)
+
+/*
+ * CEPH_IOC_SYNCIO - force synchronous IO
+ *
+ * This ioctl sets a file flag that forces the synchronous IO that
+ * bypasses the page cache, even if it is not necessary.  This is
+ * essentially the opposite behavior of IOC_LAZYIO.  This forces the
+ * same read/write path as a file opened by multiple clients when one
+ * or more of those clients is opened for write.
+ *
+ * Note that this type of sync IO takes a different path than a file
+ * opened with O_SYNC/D_SYNC (writes hit the page cache and are
+ * immediately flushed on page boundaries).  It is very similar to
+ * O_DIRECT (writes bypass the page cache) excep that O_DIRECT writes
+ * are not copied (user page must remain stable) and O_DIRECT writes
+ * have alignment restrictions (on the buffer and file offset).
+ */
 #define CEPH_IOC_SYNCIO _IO(CEPH_IOCTL_MAGIC, 5)
 
 #endif
index 86c59e16ba74e459ad0c3f29743ace6663f29206..1d72f15fe9f4570aee8a033e120478ff1fc66a97 100644 (file)
@@ -764,7 +764,8 @@ static struct ceph_msg *create_session_msg(u32 op, u64 seq)
        struct ceph_msg *msg;
        struct ceph_mds_session_head *h;
 
-       msg = ceph_msg_new(CEPH_MSG_CLIENT_SESSION, sizeof(*h), GFP_NOFS);
+       msg = ceph_msg_new(CEPH_MSG_CLIENT_SESSION, sizeof(*h), GFP_NOFS,
+                          false);
        if (!msg) {
                pr_err("create_session_msg ENOMEM creating msg\n");
                return NULL;
@@ -1240,7 +1241,7 @@ int ceph_add_cap_releases(struct ceph_mds_client *mdsc,
        while (session->s_num_cap_releases < session->s_nr_caps + extra) {
                spin_unlock(&session->s_cap_lock);
                msg = ceph_msg_new(CEPH_MSG_CLIENT_CAPRELEASE, PAGE_CACHE_SIZE,
-                                  GFP_NOFS);
+                                  GFP_NOFS, false);
                if (!msg)
                        goto out_unlocked;
                dout("add_cap_releases %p msg %p now %d\n", session, msg,
@@ -1652,7 +1653,7 @@ static struct ceph_msg *create_request_message(struct ceph_mds_client *mdsc,
        if (req->r_old_dentry_drop)
                len += req->r_old_dentry->d_name.len;
 
-       msg = ceph_msg_new(CEPH_MSG_CLIENT_REQUEST, len, GFP_NOFS);
+       msg = ceph_msg_new(CEPH_MSG_CLIENT_REQUEST, len, GFP_NOFS, false);
        if (!msg) {
                msg = ERR_PTR(-ENOMEM);
                goto out_free2;
@@ -2518,7 +2519,7 @@ static void send_mds_reconnect(struct ceph_mds_client *mdsc,
                goto fail_nopagelist;
        ceph_pagelist_init(pagelist);
 
-       reply = ceph_msg_new(CEPH_MSG_CLIENT_RECONNECT, 0, GFP_NOFS);
+       reply = ceph_msg_new(CEPH_MSG_CLIENT_RECONNECT, 0, GFP_NOFS, false);
        if (!reply)
                goto fail_nomsg;
 
@@ -2831,7 +2832,7 @@ void ceph_mdsc_lease_send_msg(struct ceph_mds_session *session,
        dnamelen = dentry->d_name.len;
        len += dnamelen;
 
-       msg = ceph_msg_new(CEPH_MSG_CLIENT_LEASE, len, GFP_NOFS);
+       msg = ceph_msg_new(CEPH_MSG_CLIENT_LEASE, len, GFP_NOFS, false);
        if (!msg)
                return;
        lease = msg->front.iov_base;
index 88bacaf385d960fcd1ba98e99049e7a47658abe7..788f5ad8e66de6e3be4c7a3530584024b9e98883 100644 (file)
@@ -114,6 +114,7 @@ static int ceph_sync_fs(struct super_block *sb, int wait)
 enum {
        Opt_wsize,
        Opt_rsize,
+       Opt_rasize,
        Opt_caps_wanted_delay_min,
        Opt_caps_wanted_delay_max,
        Opt_cap_release_safety,
@@ -136,6 +137,7 @@ enum {
 static match_table_t fsopt_tokens = {
        {Opt_wsize, "wsize=%d"},
        {Opt_rsize, "rsize=%d"},
+       {Opt_rasize, "rasize=%d"},
        {Opt_caps_wanted_delay_min, "caps_wanted_delay_min=%d"},
        {Opt_caps_wanted_delay_max, "caps_wanted_delay_max=%d"},
        {Opt_cap_release_safety, "cap_release_safety=%d"},
@@ -196,6 +198,9 @@ static int parse_fsopt_token(char *c, void *private)
        case Opt_rsize:
                fsopt->rsize = intval;
                break;
+       case Opt_rasize:
+               fsopt->rasize = intval;
+               break;
        case Opt_caps_wanted_delay_min:
                fsopt->caps_wanted_delay_min = intval;
                break;
@@ -289,28 +294,29 @@ static int parse_mount_options(struct ceph_mount_options **pfsopt,
 
        dout("parse_mount_options %p, dev_name '%s'\n", fsopt, dev_name);
 
-        fsopt->sb_flags = flags;
-        fsopt->flags = CEPH_MOUNT_OPT_DEFAULT;
+       fsopt->sb_flags = flags;
+       fsopt->flags = CEPH_MOUNT_OPT_DEFAULT;
 
-        fsopt->rsize = CEPH_RSIZE_DEFAULT;
-        fsopt->snapdir_name = kstrdup(CEPH_SNAPDIRNAME_DEFAULT, GFP_KERNEL);
+       fsopt->rsize = CEPH_RSIZE_DEFAULT;
+       fsopt->rasize = CEPH_RASIZE_DEFAULT;
+       fsopt->snapdir_name = kstrdup(CEPH_SNAPDIRNAME_DEFAULT, GFP_KERNEL);
        fsopt->caps_wanted_delay_min = CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT;
        fsopt->caps_wanted_delay_max = CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT;
-        fsopt->cap_release_safety = CEPH_CAP_RELEASE_SAFETY_DEFAULT;
-        fsopt->max_readdir = CEPH_MAX_READDIR_DEFAULT;
-        fsopt->max_readdir_bytes = CEPH_MAX_READDIR_BYTES_DEFAULT;
-        fsopt->congestion_kb = default_congestion_kb();
-       
-        /* ip1[:port1][,ip2[:port2]...]:/subdir/in/fs */
-        err = -EINVAL;
-        if (!dev_name)
-                goto out;
-        *path = strstr(dev_name, ":/");
-        if (*path == NULL) {
-                pr_err("device name is missing path (no :/ in %s)\n",
-                       dev_name);
-                goto out;
-        }
+       fsopt->cap_release_safety = CEPH_CAP_RELEASE_SAFETY_DEFAULT;
+       fsopt->max_readdir = CEPH_MAX_READDIR_DEFAULT;
+       fsopt->max_readdir_bytes = CEPH_MAX_READDIR_BYTES_DEFAULT;
+       fsopt->congestion_kb = default_congestion_kb();
+
+       /* ip1[:port1][,ip2[:port2]...]:/subdir/in/fs */
+       err = -EINVAL;
+       if (!dev_name)
+               goto out;
+       *path = strstr(dev_name, ":/");
+       if (*path == NULL) {
+               pr_err("device name is missing path (no :/ in %s)\n",
+                               dev_name);
+               goto out;
+       }
        dev_name_end = *path;
        dout("device name '%.*s'\n", (int)(dev_name_end - dev_name), dev_name);
 
@@ -376,6 +382,8 @@ static int ceph_show_options(struct seq_file *m, struct vfsmount *mnt)
                seq_printf(m, ",wsize=%d", fsopt->wsize);
        if (fsopt->rsize != CEPH_RSIZE_DEFAULT)
                seq_printf(m, ",rsize=%d", fsopt->rsize);
+       if (fsopt->rasize != CEPH_RASIZE_DEFAULT)
+               seq_printf(m, ",rasize=%d", fsopt->rsize);
        if (fsopt->congestion_kb != default_congestion_kb())
                seq_printf(m, ",write_congestion_kb=%d", fsopt->congestion_kb);
        if (fsopt->caps_wanted_delay_min != CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT)
@@ -422,20 +430,23 @@ struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt,
                                        struct ceph_options *opt)
 {
        struct ceph_fs_client *fsc;
+       const unsigned supported_features =
+               CEPH_FEATURE_FLOCK |
+               CEPH_FEATURE_DIRLAYOUTHASH;
+       const unsigned required_features = 0;
        int err = -ENOMEM;
 
        fsc = kzalloc(sizeof(*fsc), GFP_KERNEL);
        if (!fsc)
                return ERR_PTR(-ENOMEM);
 
-       fsc->client = ceph_create_client(opt, fsc);
+       fsc->client = ceph_create_client(opt, fsc, supported_features,
+                                        required_features);
        if (IS_ERR(fsc->client)) {
                err = PTR_ERR(fsc->client);
                goto fail;
        }
        fsc->client->extra_mon_dispatch = extra_mon_dispatch;
-       fsc->client->supported_features |= CEPH_FEATURE_FLOCK |
-               CEPH_FEATURE_DIRLAYOUTHASH;
        fsc->client->monc.want_mdsmap = 1;
 
        fsc->mount_options = fsopt;
@@ -774,10 +785,10 @@ static int ceph_register_bdi(struct super_block *sb,
 {
        int err;
 
-       /* set ra_pages based on rsize mount option? */
-       if (fsc->mount_options->rsize >= PAGE_CACHE_SIZE)
+       /* set ra_pages based on rasize mount option? */
+       if (fsc->mount_options->rasize >= PAGE_CACHE_SIZE)
                fsc->backing_dev_info.ra_pages =
-                       (fsc->mount_options->rsize + PAGE_CACHE_SIZE - 1)
+                       (fsc->mount_options->rasize + PAGE_CACHE_SIZE - 1)
                        >> PAGE_SHIFT;
        else
                fsc->backing_dev_info.ra_pages =
index a23eed526f05c5c1509c2c9f713681a5d5a4fd18..b01442aaf278eff165f10596ba291c8953dee99e 100644 (file)
@@ -36,7 +36,8 @@
 #define ceph_test_mount_opt(fsc, opt) \
        (!!((fsc)->mount_options->flags & CEPH_MOUNT_OPT_##opt))
 
-#define CEPH_RSIZE_DEFAULT             (512*1024) /* readahead */
+#define CEPH_RSIZE_DEFAULT             0           /* max read size */
+#define CEPH_RASIZE_DEFAULT            (8192*1024) /* readahead */
 #define CEPH_MAX_READDIR_DEFAULT        1024
 #define CEPH_MAX_READDIR_BYTES_DEFAULT  (512*1024)
 #define CEPH_SNAPDIRNAME_DEFAULT        ".snap"
@@ -45,8 +46,9 @@ struct ceph_mount_options {
        int flags;
        int sb_flags;
 
-       int wsize;
-       int rsize;            /* max readahead */
+       int wsize;            /* max write size */
+       int rsize;            /* max read size */
+       int rasize;           /* max readahead */
        int congestion_kb;    /* max writeback in flight */
        int caps_wanted_delay_min, caps_wanted_delay_max;
        int cap_release_safety;
@@ -344,9 +346,10 @@ static inline struct ceph_vino ceph_vino(struct inode *inode)
  * x86_64+ino32  64                     32
  * x86_64        64                     64
  */
-static inline u32 ceph_ino_to_ino32(ino_t ino)
+static inline u32 ceph_ino_to_ino32(__u64 vino)
 {
-       ino ^= ino >> (sizeof(ino) * 8 - 32);
+       u32 ino = vino & 0xffffffff;
+       ino ^= vino >> 32;
        if (!ino)
                ino = 1;
        return ino;
@@ -357,11 +360,11 @@ static inline u32 ceph_ino_to_ino32(ino_t ino)
  */
 static inline ino_t ceph_vino_to_ino(struct ceph_vino vino)
 {
-       ino_t ino = (ino_t)vino.ino;  /* ^ (vino.snap << 20); */
 #if BITS_PER_LONG == 32
-       ino = ceph_ino_to_ino32(ino);
+       return ceph_ino_to_ino32(vino.ino);
+#else
+       return (ino_t)vino.ino;
 #endif
-       return ino;
 }
 
 /*
index 302e761bd0aa643712c4626424d4d708919017e0..c98787536bb888969c37afed2f0a5c5409098682 100644 (file)
@@ -546,7 +546,7 @@ out:
 ssize_t compat_rw_copy_check_uvector(int type,
                const struct compat_iovec __user *uvector, unsigned long nr_segs,
                unsigned long fast_segs, struct iovec *fast_pointer,
-               struct iovec **ret_pointer)
+               struct iovec **ret_pointer, int check_access)
 {
        compat_ssize_t tot_len;
        struct iovec *iov = *ret_pointer = fast_pointer;
@@ -593,7 +593,8 @@ ssize_t compat_rw_copy_check_uvector(int type,
                }
                if (len < 0)    /* size_t not fitting in compat_ssize_t .. */
                        goto out;
-               if (!access_ok(vrfy_dir(type), compat_ptr(buf), len)) {
+               if (check_access &&
+                   !access_ok(vrfy_dir(type), compat_ptr(buf), len)) {
                        ret = -EFAULT;
                        goto out;
                }
@@ -1107,7 +1108,7 @@ static ssize_t compat_do_readv_writev(int type, struct file *file,
                goto out;
 
        tot_len = compat_rw_copy_check_uvector(type, uvector, nr_segs,
-                                              UIO_FASTIOV, iovstack, &iov);
+                                              UIO_FASTIOV, iovstack, &iov, 1);
        if (tot_len == 0) {
                ret = 0;
                goto out;
index b36c5572b3f3739c1cae2d970d14196ed10d8ceb..54481a3b2c7960e6ba205696c9d69ec44b331194 100644 (file)
@@ -514,7 +514,7 @@ ecryptfs_set_dentry_lower_mnt(struct dentry *dentry, struct vfsmount *lower_mnt)
 
 #define ecryptfs_printk(type, fmt, arg...) \
         __ecryptfs_printk(type "%s: " fmt, __func__, ## arg);
-__attribute__ ((format(printf, 1, 2)))
+__printf(1, 2)
 void __ecryptfs_printk(const char *fmt, ...);
 
 extern const struct file_operations ecryptfs_main_fops;
index 9026fc91fe3bf34f2b8d71fd084dfac3ef1aa05c..828e750af23a7923cb9782c9cd3c3b87ed6b4964 100644 (file)
  * simultaneous inserts (A into B and B into A) from racing and
  * constructing a cycle without either insert observing that it is
  * going to.
+ * It is necessary to acquire multiple "ep->mtx"es at once in the
+ * case when one epoll fd is added to another. In this case, we
+ * always acquire the locks in the order of nesting (i.e. after
+ * epoll_ctl(e1, EPOLL_CTL_ADD, e2), e1->mtx will always be acquired
+ * before e2->mtx). Since we disallow cycles of epoll file
+ * descriptors, this ensures that the mutexes are well-ordered. In
+ * order to communicate this nesting to lockdep, when walking a tree
+ * of epoll file descriptors, we use the current recursion depth as
+ * the lockdep subkey.
  * It is possible to drop the "ep->mtx" and to use the global
  * mutex "epmutex" (together with "ep->lock") to have it working,
  * but having "ep->mtx" will make the interface more scalable.
@@ -464,13 +473,15 @@ static void ep_unregister_pollwait(struct eventpoll *ep, struct epitem *epi)
  * @ep: Pointer to the epoll private data structure.
  * @sproc: Pointer to the scan callback.
  * @priv: Private opaque data passed to the @sproc callback.
+ * @depth: The current depth of recursive f_op->poll calls.
  *
  * Returns: The same integer error code returned by the @sproc callback.
  */
 static int ep_scan_ready_list(struct eventpoll *ep,
                              int (*sproc)(struct eventpoll *,
                                           struct list_head *, void *),
-                             void *priv)
+                             void *priv,
+                             int depth)
 {
        int error, pwake = 0;
        unsigned long flags;
@@ -481,7 +492,7 @@ static int ep_scan_ready_list(struct eventpoll *ep,
         * We need to lock this because we could be hit by
         * eventpoll_release_file() and epoll_ctl().
         */
-       mutex_lock(&ep->mtx);
+       mutex_lock_nested(&ep->mtx, depth);
 
        /*
         * Steal the ready list, and re-init the original one to the
@@ -670,7 +681,7 @@ static int ep_read_events_proc(struct eventpoll *ep, struct list_head *head,
 
 static int ep_poll_readyevents_proc(void *priv, void *cookie, int call_nests)
 {
-       return ep_scan_ready_list(priv, ep_read_events_proc, NULL);
+       return ep_scan_ready_list(priv, ep_read_events_proc, NULL, call_nests + 1);
 }
 
 static unsigned int ep_eventpoll_poll(struct file *file, poll_table *wait)
@@ -737,7 +748,7 @@ void eventpoll_release_file(struct file *file)
 
                ep = epi->ep;
                list_del_init(&epi->fllink);
-               mutex_lock(&ep->mtx);
+               mutex_lock_nested(&ep->mtx, 0);
                ep_remove(ep, epi);
                mutex_unlock(&ep->mtx);
        }
@@ -1134,7 +1145,7 @@ static int ep_send_events(struct eventpoll *ep,
        esed.maxevents = maxevents;
        esed.events = events;
 
-       return ep_scan_ready_list(ep, ep_send_events_proc, &esed);
+       return ep_scan_ready_list(ep, ep_send_events_proc, &esed, 0);
 }
 
 static inline struct timespec ep_set_mstimeout(long ms)
@@ -1267,7 +1278,7 @@ static int ep_loop_check_proc(void *priv, void *cookie, int call_nests)
        struct rb_node *rbp;
        struct epitem *epi;
 
-       mutex_lock(&ep->mtx);
+       mutex_lock_nested(&ep->mtx, call_nests + 1);
        for (rbp = rb_first(&ep->rbr); rbp; rbp = rb_next(rbp)) {
                epi = rb_entry(rbp, struct epitem, rbn);
                if (unlikely(is_file_epoll(epi->ffd.file))) {
@@ -1409,7 +1420,7 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
        }
 
 
-       mutex_lock(&ep->mtx);
+       mutex_lock_nested(&ep->mtx, 0);
 
        /*
         * Try to lookup the file inside our RB tree, Since we grabbed "mtx"
index 25dcbe5fc35664d6f389ce48f051d6528d607014..36254645b7cc4d81f7c73b2940767fe06de1642c 100644 (file)
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -841,10 +841,6 @@ static int exec_mmap(struct mm_struct *mm)
        tsk->mm = mm;
        tsk->active_mm = mm;
        activate_mm(active_mm, mm);
-       if (old_mm && tsk->signal->oom_score_adj == OOM_SCORE_ADJ_MIN) {
-               atomic_dec(&old_mm->oom_disable_count);
-               atomic_inc(&tsk->mm->oom_disable_count);
-       }
        task_unlock(tsk);
        arch_pick_mmap_layout(mm);
        if (old_mm) {
index af9fc89b1b2d3e92994e63db97023f2ebf32ecac..9a4e5e206d08cb11cef8470c4921bb6b9a2f1573 100644 (file)
@@ -135,10 +135,10 @@ extern long ext2_compat_ioctl(struct file *, unsigned int, unsigned long);
 struct dentry *ext2_get_parent(struct dentry *child);
 
 /* super.c */
-extern void ext2_error (struct super_block *, const char *, const char *, ...)
-       __attribute__ ((format (printf, 3, 4)));
-extern void ext2_msg(struct super_block *, const char *, const char *, ...)
-       __attribute__ ((format (printf, 3, 4)));
+extern __printf(3, 4)
+void ext2_error(struct super_block *, const char *, const char *, ...);
+extern __printf(3, 4)
+void ext2_msg(struct super_block *, const char *, const char *, ...);
 extern void ext2_update_dynamic_rev (struct super_block *sb);
 extern void ext2_write_super (struct super_block *);
 
index b7d7bd0f066ef4d02d9cba1cf2f72704cb44a4f5..cec3145e532ce7f1486ef6d20a46b5b267bc9ea3 100644 (file)
@@ -1878,40 +1878,40 @@ extern int ext4_group_extend(struct super_block *sb,
 extern void *ext4_kvmalloc(size_t size, gfp_t flags);
 extern void *ext4_kvzalloc(size_t size, gfp_t flags);
 extern void ext4_kvfree(void *ptr);
-extern void __ext4_error(struct super_block *, const char *, unsigned int,
-                        const char *, ...)
-       __attribute__ ((format (printf, 4, 5)));
+extern __printf(4, 5)
+void __ext4_error(struct super_block *, const char *, unsigned int,
+                 const char *, ...);
 #define ext4_error(sb, message...)     __ext4_error(sb, __func__,      \
                                                     __LINE__, ## message)
-extern void ext4_error_inode(struct inode *, const char *, unsigned int,
-                            ext4_fsblk_t, const char *, ...)
-       __attribute__ ((format (printf, 5, 6)));
-extern void ext4_error_file(struct file *, const char *, unsigned int,
-                           ext4_fsblk_t, const char *, ...)
-       __attribute__ ((format (printf, 5, 6)));
+extern __printf(5, 6)
+void ext4_error_inode(struct inode *, const char *, unsigned int, ext4_fsblk_t,
+                     const char *, ...);
+extern __printf(5, 6)
+void ext4_error_file(struct file *, const char *, unsigned int, ext4_fsblk_t,
+                    const char *, ...);
 extern void __ext4_std_error(struct super_block *, const char *,
                             unsigned int, int);
-extern void __ext4_abort(struct super_block *, const char *, unsigned int,
-                      const char *, ...)
-       __attribute__ ((format (printf, 4, 5)));
+extern __printf(4, 5)
+void __ext4_abort(struct super_block *, const char *, unsigned int,
+                 const char *, ...);
 #define ext4_abort(sb, message...)     __ext4_abort(sb, __func__, \
                                                       __LINE__, ## message)
-extern void __ext4_warning(struct super_block *, const char *, unsigned int,
-                         const char *, ...)
-       __attribute__ ((format (printf, 4, 5)));
+extern __printf(4, 5)
+void __ext4_warning(struct super_block *, const char *, unsigned int,
+                   const char *, ...);
 #define ext4_warning(sb, message...)   __ext4_warning(sb, __func__, \
                                                       __LINE__, ## message)
-extern void ext4_msg(struct super_block *, const char *, const char *, ...)
-       __attribute__ ((format (printf, 3, 4)));
+extern __printf(3, 4)
+void ext4_msg(struct super_block *, const char *, const char *, ...);
 extern void __dump_mmp_msg(struct super_block *, struct mmp_struct *mmp,
                           const char *, unsigned int, const char *);
 #define dump_mmp_msg(sb, mmp, msg)     __dump_mmp_msg(sb, mmp, __func__, \
                                                       __LINE__, msg)
-extern void __ext4_grp_locked_error(const char *, unsigned int, \
-                                   struct super_block *, ext4_group_t, \
-                                   unsigned long, ext4_fsblk_t, \
-                                   const char *, ...)
-       __attribute__ ((format (printf, 7, 8)));
+extern __printf(7, 8)
+void __ext4_grp_locked_error(const char *, unsigned int,
+                            struct super_block *, ext4_group_t,
+                            unsigned long, ext4_fsblk_t,
+                            const char *, ...);
 #define ext4_grp_locked_error(sb, grp, message...) \
        __ext4_grp_locked_error(__func__, __LINE__, (sb), (grp), ## message)
 extern void ext4_update_dynamic_rev(struct super_block *sb);
index 986e2388f031dd3ccb2ceec8c07d0a31b058eed1..0defe0bfe019a3083f0156f6473b303caf65f93b 100644 (file)
@@ -1811,8 +1811,12 @@ static int ext4_writepage(struct page *page,
                 * We don't want to do block allocation, so redirty
                 * the page and return.  We may reach here when we do
                 * a journal commit via journal_submit_inode_data_buffers.
-                * We can also reach here via shrink_page_list
+                * We can also reach here via shrink_page_list but it
+                * should never be for direct reclaim so warn if that
+                * happens
                 */
+               WARN_ON_ONCE((current->flags & (PF_MEMALLOC|PF_KSWAPD)) ==
+                                                               PF_MEMALLOC);
                goto redirty_page;
        }
        if (commit_write)
index 5efbd5d7701a1d63721f646958d92f36830807f0..aca191bd5f8fa66bcef77c549b647fce81e28b0f 100644 (file)
@@ -156,8 +156,8 @@ static int uni16_to_x8(struct super_block *sb, unsigned char *ascii,
                } else {
                        if (uni_xlate == 1) {
                                *op++ = ':';
-                               op = pack_hex_byte(op, ec >> 8);
-                               op = pack_hex_byte(op, ec);
+                               op = hex_byte_pack(op, ec >> 8);
+                               op = hex_byte_pack(op, ec);
                                len -= 5;
                        } else {
                                *op++ = '?';
index a5d3853822e07b68f5434007725ddf4acec0330f..1510a4d5199002bb9b7744e9301120fc691dbf28 100644 (file)
@@ -326,15 +326,14 @@ extern int fat_fill_super(struct super_block *sb, void *data, int silent,
 extern int fat_flush_inodes(struct super_block *sb, struct inode *i1,
                            struct inode *i2);
 /* fat/misc.c */
-extern void
-__fat_fs_error(struct super_block *sb, int report, const char *fmt, ...)
-       __attribute__ ((format (printf, 3, 4))) __cold;
+extern __printf(3, 4) __cold
+void __fat_fs_error(struct super_block *sb, int report, const char *fmt, ...);
 #define fat_fs_error(sb, fmt, args...)         \
        __fat_fs_error(sb, 1, fmt , ## args)
 #define fat_fs_error_ratelimit(sb, fmt, args...) \
        __fat_fs_error(sb, __ratelimit(&MSDOS_SB(sb)->ratelimit), fmt , ## args)
-void fat_msg(struct super_block *sb, const char *level, const char *fmt, ...)
-       __attribute__ ((format (printf, 3, 4))) __cold;
+__printf(3, 4) __cold
+void fat_msg(struct super_block *sb, const char *level, const char *fmt, ...);
 extern int fat_clusters_flush(struct super_block *sb);
 extern int fat_chain_add(struct inode *inode, int new_dclus, int nr_cluster);
 extern void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec *ts,
index 66707118af2512be474bda424c232b2eb5813c4c..2553b858a72e8374b04ea765938da1eacb7d925c 100644 (file)
@@ -201,7 +201,7 @@ int gfs2_glock_nq_m(unsigned int num_gh, struct gfs2_holder *ghs);
 void gfs2_glock_dq_m(unsigned int num_gh, struct gfs2_holder *ghs);
 void gfs2_glock_dq_uninit_m(unsigned int num_gh, struct gfs2_holder *ghs);
 
-__attribute__ ((format(printf, 2, 3)))
+__printf(2, 3)
 void gfs2_print_dbg(struct seq_file *seq, const char *fmt, ...);
 
 /**
index 331b5e234ef3aca66c93c27f7f90fd357b14f8d3..de946170ebb1092937a1efd5f8dbd104f064d170 100644 (file)
@@ -311,8 +311,8 @@ static inline struct hpfs_sb_info *hpfs_sb(struct super_block *sb)
 
 /* super.c */
 
-void hpfs_error(struct super_block *, const char *, ...)
-       __attribute__((format (printf, 2, 3)));
+__printf(2, 3)
+void hpfs_error(struct super_block *, const char *, ...);
 int hpfs_stop_cycles(struct super_block *, int, int *, int *, char *);
 unsigned hpfs_count_one_bitmap(struct super_block *, secno);
 
index f22d108bfa5dd54d4ea81129561f093076559a9f..398ecff6e548f1f521251285a2b4cff3277b720b 100644 (file)
@@ -618,7 +618,6 @@ static inline int logfs_buf_recover(struct logfs_area *area, u64 ofs,
 struct page *emergency_read_begin(struct address_space *mapping, pgoff_t index);
 void emergency_read_end(struct page *page);
 void logfs_crash_dump(struct super_block *sb);
-void *memchr_inv(const void *s, int c, size_t n);
 int logfs_statfs(struct dentry *dentry, struct kstatfs *stats);
 int logfs_check_ds(struct logfs_disk_super *ds);
 int logfs_write_sb(struct super_block *sb);
index ce03a182c771c42e39e90c0f7b3737b897d02215..f2697e4df10919f1d87d7ae39346fe96e128d32e 100644 (file)
@@ -90,28 +90,6 @@ void logfs_crash_dump(struct super_block *sb)
        dump_segfile(sb);
 }
 
-/*
- * TODO: move to lib/string.c
- */
-/**
- * memchr_inv - Find a character in an area of memory.
- * @s: The memory area
- * @c: The byte to search for
- * @n: The size of the area.
- *
- * returns the address of the first character other than @c, or %NULL
- * if the whole buffer contains just @c.
- */
-void *memchr_inv(const void *s, int c, size_t n)
-{
-       const unsigned char *p = s;
-       while (n-- != 0)
-               if ((unsigned char)c != *p++)
-                       return (void *)(p - 1);
-
-       return NULL;
-}
-
 /*
  * FIXME: There should be a reserve for root, similar to ext2.
  */
index 255d5e1c03b74197046877181fb1c205c094aafd..3777d138f895b931a7648aea3d7f32896acc3bf5 100644 (file)
@@ -276,10 +276,10 @@ int nilfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
 /* super.c */
 extern struct inode *nilfs_alloc_inode(struct super_block *);
 extern void nilfs_destroy_inode(struct inode *);
-extern void nilfs_error(struct super_block *, const char *, const char *, ...)
-       __attribute__ ((format (printf, 3, 4)));
-extern void nilfs_warning(struct super_block *, const char *, const char *, ...)
-       __attribute__ ((format (printf, 3, 4)));
+extern __printf(3, 4)
+void nilfs_error(struct super_block *, const char *, const char *, ...);
+extern __printf(3, 4)
+void nilfs_warning(struct super_block *, const char *, const char *, ...);
 extern struct nilfs_super_block *
 nilfs_read_super_block(struct super_block *, u64, int, struct buffer_head **);
 extern int nilfs_store_magic_and_option(struct super_block *,
index 2142b1c68b618d7de730b26bcf257d7a116e12c1..53c27eaf2307500fc9ec616a3f38c09aea890cc2 100644 (file)
@@ -30,8 +30,9 @@
 
 extern int debug_msgs;
 
-extern void __ntfs_debug(const char *file, int line, const char *function,
-       const char *format, ...) __attribute__ ((format (printf, 4, 5)));
+extern __printf(4, 5)
+void __ntfs_debug(const char *file, int line, const char *function,
+                 const char *format, ...);
 /**
  * ntfs_debug - write a debug level message to syslog
  * @f:         a printf format string containing the message
@@ -52,12 +53,14 @@ extern void ntfs_debug_dump_runlist(const runlist_element *rl);
 
 #endif /* !DEBUG */
 
-extern void __ntfs_warning(const char *function, const struct super_block *sb,
-               const char *fmt, ...) __attribute__ ((format (printf, 3, 4)));
+extern  __printf(3, 4)
+void __ntfs_warning(const char *function, const struct super_block *sb,
+                   const char *fmt, ...);
 #define ntfs_warning(sb, f, a...)      __ntfs_warning(__func__, sb, f, ##a)
 
-extern void __ntfs_error(const char *function, const struct super_block *sb,
-               const char *fmt, ...) __attribute__ ((format (printf, 3, 4)));
+extern  __printf(3, 4)
+void __ntfs_error(const char *function, const struct super_block *sb,
+                 const char *fmt, ...);
 #define ntfs_error(sb, f, a...)                __ntfs_error(__func__, sb, f, ##a)
 
 #endif /* _LINUX_NTFS_DEBUG_H */
index 40c7de084c100cbacd8b7e47b8aa4c4c69737792..74ff74cf78fe9202a110ff353e05163b3ce779d3 100644 (file)
@@ -31,17 +31,15 @@ extern struct workqueue_struct *ocfs2_wq;
 int ocfs2_publish_get_mount_state(struct ocfs2_super *osb,
                                  int node_num);
 
-void __ocfs2_error(struct super_block *sb,
-                  const char *function,
-                  const char *fmt, ...)
-       __attribute__ ((format (printf, 3, 4)));
+__printf(3, 4)
+void __ocfs2_error(struct super_block *sb, const char *function,
+                  const char *fmt, ...);
 
 #define ocfs2_error(sb, fmt, args...) __ocfs2_error(sb, __PRETTY_FUNCTION__, fmt, ##args)
 
-void __ocfs2_abort(struct super_block *sb,
-                  const char *function,
-                  const char *fmt, ...)
-       __attribute__ ((format (printf, 3, 4)));
+__printf(3, 4)
+void __ocfs2_abort(struct super_block *sb, const char *function,
+                  const char *fmt, ...);
 
 #define ocfs2_abort(sb, fmt, args...) __ocfs2_abort(sb, __PRETTY_FUNCTION__, fmt, ##args)
 
index af9fdf04676953b07cb3f13ffcbcee1c5b5ef1ee..bd8ae788f689129a1ae6cc75c4687655031a868d 100644 (file)
 #define ldm_error(f, a...) _ldm_printk (KERN_ERR,   __func__, f, ##a)
 #define ldm_info(f, a...)  _ldm_printk (KERN_INFO,  __func__, f, ##a)
 
-__attribute__ ((format (printf, 3, 4)))
-static void _ldm_printk (const char *level, const char *function,
-                        const char *fmt, ...)
+static __printf(3, 4)
+void _ldm_printk(const char *level, const char *function, const char *fmt, ...)
 {
-       static char buf[128];
+       struct va_format vaf;
        va_list args;
 
        va_start (args, fmt);
-       vsnprintf (buf, sizeof (buf), fmt, args);
-       va_end (args);
 
-       printk ("%s%s(): %s\n", level, function, buf);
+       vaf.fmt = fmt;
+       vaf.va = &args;
+
+       printk("%s%s(): %pV\n", level, function, &vaf);
+
+       va_end(args);
 }
 
 /**
index 0e0be1dc0f8ef67e433cefb9d46c708b2a2ca52d..4065f07366b37e2982b1841aeaf308492a351a3d 100644 (file)
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -1254,6 +1254,7 @@ out:
 
 static const struct super_operations pipefs_ops = {
        .destroy_inode = free_inode_nonrcu,
+       .statfs = simple_statfs,
 };
 
 /*
index 5eb02069e1b817730050b7b46304a9244c064bde..8f0087e20e168ee04e6b14e7ef05a68f13e4b58e 100644 (file)
@@ -1107,13 +1107,6 @@ static ssize_t oom_adjust_write(struct file *file, const char __user *buf,
                goto err_sighand;
        }
 
-       if (oom_adjust != task->signal->oom_adj) {
-               if (oom_adjust == OOM_DISABLE)
-                       atomic_inc(&task->mm->oom_disable_count);
-               if (task->signal->oom_adj == OOM_DISABLE)
-                       atomic_dec(&task->mm->oom_disable_count);
-       }
-
        /*
         * Warn that /proc/pid/oom_adj is deprecated, see
         * Documentation/feature-removal-schedule.txt.
@@ -1215,12 +1208,6 @@ static ssize_t oom_score_adj_write(struct file *file, const char __user *buf,
                goto err_sighand;
        }
 
-       if (oom_score_adj != task->signal->oom_score_adj) {
-               if (oom_score_adj == OOM_SCORE_ADJ_MIN)
-                       atomic_inc(&task->mm->oom_disable_count);
-               if (task->signal->oom_score_adj == OOM_SCORE_ADJ_MIN)
-                       atomic_dec(&task->mm->oom_disable_count);
-       }
        task->signal->oom_score_adj = oom_score_adj;
        if (has_capability_noaudit(current, CAP_SYS_RESOURCE))
                task->signal->oom_score_adj_min = oom_score_adj;
index 5afaa58a863012d83a69763b2e65c9db67fe2ada..e418c5abdb0ef954eed21771ca0ff1fe9958077d 100644 (file)
@@ -44,6 +44,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
                "VmPeak:\t%8lu kB\n"
                "VmSize:\t%8lu kB\n"
                "VmLck:\t%8lu kB\n"
+               "VmPin:\t%8lu kB\n"
                "VmHWM:\t%8lu kB\n"
                "VmRSS:\t%8lu kB\n"
                "VmData:\t%8lu kB\n"
@@ -55,6 +56,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
                hiwater_vm << (PAGE_SHIFT-10),
                (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
                mm->locked_vm << (PAGE_SHIFT-10),
+               mm->pinned_vm << (PAGE_SHIFT-10),
                hiwater_rss << (PAGE_SHIFT-10),
                total_rss << (PAGE_SHIFT-10),
                data << (PAGE_SHIFT-10),
@@ -1039,6 +1041,9 @@ static int show_numa_map(struct seq_file *m, void *v)
                seq_printf(m, " stack");
        }
 
+       if (is_vm_hugetlb_page(vma))
+               seq_printf(m, " huge");
+
        walk_page_range(vma->vm_start, vma->vm_end, &walk);
 
        if (!md->pages)
index 893b961dcfd8b45219a9266ca4db78ee9b44fb71..379a02dc1217adf24450af7bae64279e78d85793 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/highmem.h>
 #include <linux/time.h>
 #include <linux/init.h>
+#include <linux/list.h>
 #include <linux/string.h>
 #include <linux/mount.h>
 #include <linux/ramfs.h>
 #include <linux/magic.h>
 #include <linux/pstore.h>
 #include <linux/slab.h>
+#include <linux/spinlock.h>
 #include <linux/uaccess.h>
 
 #include "internal.h"
 
 #define        PSTORE_NAMELEN  64
 
+static DEFINE_SPINLOCK(allpstore_lock);
+static LIST_HEAD(allpstore);
+
 struct pstore_private {
+       struct list_head list;
        struct pstore_info *psi;
        enum pstore_type_id type;
        u64     id;
@@ -81,8 +87,16 @@ static int pstore_unlink(struct inode *dir, struct dentry *dentry)
 
 static void pstore_evict_inode(struct inode *inode)
 {
+       struct pstore_private   *p = inode->i_private;
+       unsigned long           flags;
+
        end_writeback(inode);
-       kfree(inode->i_private);
+       if (p) {
+               spin_lock_irqsave(&allpstore_lock, flags);
+               list_del(&p->list);
+               spin_unlock_irqrestore(&allpstore_lock, flags);
+               kfree(p);
+       }
 }
 
 static const struct inode_operations pstore_dir_inode_operations = {
@@ -182,9 +196,23 @@ int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id,
        struct dentry           *root = pstore_sb->s_root;
        struct dentry           *dentry;
        struct inode            *inode;
-       int                     rc;
+       int                     rc = 0;
        char                    name[PSTORE_NAMELEN];
-       struct pstore_private   *private;
+       struct pstore_private   *private, *pos;
+       unsigned long           flags;
+
+       spin_lock_irqsave(&allpstore_lock, flags);
+       list_for_each_entry(pos, &allpstore, list) {
+               if (pos->type == type &&
+                   pos->id == id &&
+                   pos->psi == psi) {
+                       rc = -EEXIST;
+                       break;
+               }
+       }
+       spin_unlock_irqrestore(&allpstore_lock, flags);
+       if (rc)
+               return rc;
 
        rc = -ENOMEM;
        inode = pstore_get_inode(pstore_sb, root->d_inode, S_IFREG | 0444, 0);
@@ -229,6 +257,10 @@ int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id,
 
        d_add(dentry, inode);
 
+       spin_lock_irqsave(&allpstore_lock, flags);
+       list_add(&private->list, &allpstore);
+       spin_unlock_irqrestore(&allpstore_lock, flags);
+
        mutex_unlock(&root->d_inode->i_mutex);
 
        return 0;
@@ -277,7 +309,7 @@ int pstore_fill_super(struct super_block *sb, void *data, int silent)
                goto fail;
        }
 
-       pstore_get_records();
+       pstore_get_records(0);
 
        return 0;
 fail:
index 611c1b3c46fae9b71756e1c2bd9df54e6466c17d..3bde461c3f349cfe1932d94a5f3b424e9184bebc 100644 (file)
@@ -1,5 +1,5 @@
 extern void    pstore_set_kmsg_bytes(int);
-extern void    pstore_get_records(void);
+extern void    pstore_get_records(int);
 extern int     pstore_mkfile(enum pstore_type_id, char *psname, u64 id,
                              char *data, size_t size,
                              struct timespec time, struct pstore_info *psi);
index c5300ec316965ac456091ae91ec18f1704b97681..2bd620f0d796cf5dee01590c65b7ac8802e33bf9 100644 (file)
 #include <linux/module.h>
 #include <linux/pstore.h>
 #include <linux/string.h>
+#include <linux/timer.h>
 #include <linux/slab.h>
 #include <linux/uaccess.h>
+#include <linux/hardirq.h>
+#include <linux/workqueue.h>
 
 #include "internal.h"
 
+/*
+ * We defer making "oops" entries appear in pstore - see
+ * whether the system is actually still running well enough
+ * to let someone see the entry
+ */
+#define        PSTORE_INTERVAL (60 * HZ)
+
+static int pstore_new_entry;
+
+static void pstore_timefunc(unsigned long);
+static DEFINE_TIMER(pstore_timer, pstore_timefunc, 0, 0);
+
+static void pstore_dowork(struct work_struct *);
+static DECLARE_WORK(pstore_work, pstore_dowork);
+
 /*
  * pstore_lock just protects "psinfo" during
  * calls to pstore_register()
@@ -69,15 +87,22 @@ static void pstore_dump(struct kmsg_dumper *dumper,
        unsigned long   size, total = 0;
        char            *dst, *why;
        u64             id;
-       int             hsize;
+       int             hsize, ret;
        unsigned int    part = 1;
+       unsigned long   flags = 0;
+       int             is_locked = 0;
 
        if (reason < ARRAY_SIZE(reason_str))
                why = reason_str[reason];
        else
                why = "Unknown";
 
-       mutex_lock(&psinfo->buf_mutex);
+       if (in_nmi()) {
+               is_locked = spin_trylock(&psinfo->buf_lock);
+               if (!is_locked)
+                       pr_err("pstore dump routine blocked in NMI, may corrupt error record\n");
+       } else
+               spin_lock_irqsave(&psinfo->buf_lock, flags);
        oopscount++;
        while (total < kmsg_bytes) {
                dst = psinfo->buf;
@@ -97,18 +122,20 @@ static void pstore_dump(struct kmsg_dumper *dumper,
                memcpy(dst, s1 + s1_start, l1_cpy);
                memcpy(dst + l1_cpy, s2 + s2_start, l2_cpy);
 
-               id = psinfo->write(PSTORE_TYPE_DMESG, part,
+               ret = psinfo->write(PSTORE_TYPE_DMESG, &id, part,
                                   hsize + l1_cpy + l2_cpy, psinfo);
-               if (reason == KMSG_DUMP_OOPS && pstore_is_mounted())
-                       pstore_mkfile(PSTORE_TYPE_DMESG, psinfo->name, id,
-                                     psinfo->buf, hsize + l1_cpy + l2_cpy,
-                                     CURRENT_TIME, psinfo);
+               if (ret == 0 && reason == KMSG_DUMP_OOPS && pstore_is_mounted())
+                       pstore_new_entry = 1;
                l1 -= l1_cpy;
                l2 -= l2_cpy;
                total += l1_cpy + l2_cpy;
                part++;
        }
-       mutex_unlock(&psinfo->buf_mutex);
+       if (in_nmi()) {
+               if (is_locked)
+                       spin_unlock(&psinfo->buf_lock);
+       } else
+               spin_unlock_irqrestore(&psinfo->buf_lock, flags);
 }
 
 static struct kmsg_dumper pstore_dumper = {
@@ -148,19 +175,24 @@ int pstore_register(struct pstore_info *psi)
        }
 
        if (pstore_is_mounted())
-               pstore_get_records();
+               pstore_get_records(0);
 
        kmsg_dump_register(&pstore_dumper);
 
+       pstore_timer.expires = jiffies + PSTORE_INTERVAL;
+       add_timer(&pstore_timer);
+
        return 0;
 }
 EXPORT_SYMBOL_GPL(pstore_register);
 
 /*
- * Read all the records from the persistent store. Create and
- * file files in our filesystem.
+ * Read all the records from the persistent store. Create
+ * files in our filesystem.  Don't warn about -EEXIST errors
+ * when we are re-scanning the backing store looking to add new
+ * error records.
  */
-void pstore_get_records(void)
+void pstore_get_records(int quiet)
 {
        struct pstore_info *psi = psinfo;
        ssize_t                 size;
@@ -168,36 +200,55 @@ void pstore_get_records(void)
        enum pstore_type_id     type;
        struct timespec         time;
        int                     failed = 0, rc;
+       unsigned long           flags;
 
        if (!psi)
                return;
 
-       mutex_lock(&psinfo->buf_mutex);
+       spin_lock_irqsave(&psinfo->buf_lock, flags);
        rc = psi->open(psi);
        if (rc)
                goto out;
 
        while ((size = psi->read(&id, &type, &time, psi)) > 0) {
-               if (pstore_mkfile(type, psi->name, id, psi->buf, (size_t)size,
-                                 time, psi))
+               rc = pstore_mkfile(type, psi->name, id, psi->buf, (size_t)size,
+                                 time, psi);
+               if (rc && (rc != -EEXIST || !quiet))
                        failed++;
        }
        psi->close(psi);
 out:
-       mutex_unlock(&psinfo->buf_mutex);
+       spin_unlock_irqrestore(&psinfo->buf_lock, flags);
 
        if (failed)
                printk(KERN_WARNING "pstore: failed to load %d record(s) from '%s'\n",
                       failed, psi->name);
 }
 
+static void pstore_dowork(struct work_struct *work)
+{
+       pstore_get_records(1);
+}
+
+static void pstore_timefunc(unsigned long dummy)
+{
+       if (pstore_new_entry) {
+               pstore_new_entry = 0;
+               schedule_work(&pstore_work);
+       }
+
+       mod_timer(&pstore_timer, jiffies + PSTORE_INTERVAL);
+}
+
 /*
  * Call platform driver to write a record to the
  * persistent store.
  */
 int pstore_write(enum pstore_type_id type, char *buf, size_t size)
 {
-       u64     id;
+       u64             id;
+       int             ret;
+       unsigned long   flags;
 
        if (!psinfo)
                return -ENODEV;
@@ -205,13 +256,13 @@ int pstore_write(enum pstore_type_id type, char *buf, size_t size)
        if (size > psinfo->bufsize)
                return -EFBIG;
 
-       mutex_lock(&psinfo->buf_mutex);
+       spin_lock_irqsave(&psinfo->buf_lock, flags);
        memcpy(psinfo->buf, buf, size);
-       id = psinfo->write(type, 0, size, psinfo);
-       if (pstore_is_mounted())
+       ret = psinfo->write(type, &id, 0, size, psinfo);
+       if (ret == 0 && pstore_is_mounted())
                pstore_mkfile(PSTORE_TYPE_DMESG, psinfo->name, id, psinfo->buf,
                              size, CURRENT_TIME, psinfo);
-       mutex_unlock(&psinfo->buf_mutex);
+       spin_unlock_irqrestore(&psinfo->buf_lock, flags);
 
        return 0;
 }
index dfd125798791161c6c1cea427a791522169902ce..5ad4248b0cd8f00e545ac68d477566a9ea12fdc1 100644 (file)
@@ -633,7 +633,8 @@ ssize_t do_loop_readv_writev(struct file *filp, struct iovec *iov,
 ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
                              unsigned long nr_segs, unsigned long fast_segs,
                              struct iovec *fast_pointer,
-                             struct iovec **ret_pointer)
+                             struct iovec **ret_pointer,
+                             int check_access)
 {
        unsigned long seg;
        ssize_t ret;
@@ -689,7 +690,8 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
                        ret = -EINVAL;
                        goto out;
                }
-               if (unlikely(!access_ok(vrfy_dir(type), buf, len))) {
+               if (check_access
+                   && unlikely(!access_ok(vrfy_dir(type), buf, len))) {
                        ret = -EFAULT;
                        goto out;
                }
@@ -721,7 +723,7 @@ static ssize_t do_readv_writev(int type, struct file *file,
        }
 
        ret = rw_copy_check_uvector(type, uvector, nr_segs,
-                       ARRAY_SIZE(iovstack), iovstack, &iov);
+                                   ARRAY_SIZE(iovstack), iovstack, &iov, 1);
        if (ret <= 0)
                goto out;
 
index 3f56a269a4f4e30c4c31feb0b73b05064cc974b9..32a81f3467e06835abdf8e5a3beb91acc3a2c161 100644 (file)
@@ -61,7 +61,7 @@ static int prune_super(struct shrinker *shrink, struct shrink_control *sc)
                return -1;
 
        if (!grab_super_passive(sb))
-               return -1;
+               return !sc->nr_to_scan ? 0 : -1;
 
        if (sb->s_op && sb->s_op->nr_cached_objects)
                fs_objects = sb->s_op->nr_cached_objects(sb);
index 48ffbdf0d0178e65e333841d8e5f7fcd11a868ac..7fdf6a7b743663fe44a78ea12f9c9ec30eecfe5b 100644 (file)
@@ -865,15 +865,13 @@ int sysfs_rename(struct sysfs_dirent *sd,
                sd->s_name = new_name;
        }
 
-       /* Remove from old parent's list and insert into new parent's list. */
-       if (sd->s_parent != new_parent_sd) {
-               sysfs_unlink_sibling(sd);
-               sysfs_get(new_parent_sd);
-               sysfs_put(sd->s_parent);
-               sd->s_parent = new_parent_sd;
-               sysfs_link_sibling(sd);
-       }
+       /* Move to the appropriate place in the appropriate directories rbtree. */
+       sysfs_unlink_sibling(sd);
+       sysfs_get(new_parent_sd);
+       sysfs_put(sd->s_parent);
        sd->s_ns = new_ns;
+       sd->s_parent = new_parent_sd;
+       sysfs_link_sibling(sd);
 
        error = 0;
  out:
index dbd52d4b5eed9f01382a0be8cddfa2c79f353e0c..dc8a8dcc5ae101d70cec4b5bd05a532f45d62e39 100644 (file)
@@ -112,8 +112,8 @@ struct extent_position {
 
 /* super.c */
 
-__attribute__((format(printf, 3, 4)))
-extern void udf_warning(struct super_block *, const char *, const char *, ...);
+extern __printf(3, 4) void udf_warning(struct super_block *, const char *,
+                                       const char *, ...);
 static inline void udf_updated_lvid(struct super_block *sb)
 {
        struct buffer_head *bh = UDF_SB(sb)->s_lvid_bh;
index 5be2755dd7152b3f09c325ea8188434d15113821..c26f2bcec264489849fcfa214969c4694a2d3bcf 100644 (file)
@@ -117,9 +117,12 @@ extern int ufs_getfrag_block (struct inode *inode, sector_t fragment, struct buf
 extern const struct file_operations ufs_dir_operations;
 
 /* super.c */
-extern void ufs_warning (struct super_block *, const char *, const char *, ...) __attribute__ ((format (printf, 3, 4)));
-extern void ufs_error (struct super_block *, const char *, const char *, ...) __attribute__ ((format (printf, 3, 4)));
-extern void ufs_panic (struct super_block *, const char *, const char *, ...) __attribute__ ((format (printf, 3, 4)));
+extern __printf(3, 4)
+void ufs_warning(struct super_block *, const char *, const char *, ...);
+extern __printf(3, 4)
+void ufs_error(struct super_block *, const char *, const char *, ...);
+extern __printf(3, 4)
+void ufs_panic(struct super_block *, const char *, const char *, ...);
 
 /* symlink.c */
 extern const struct inode_operations ufs_fast_symlink_inode_operations;
index 11b2aad982d46b0704ade9aa02347d712c0cc23f..33b13310ee0c2f2ddf0c68abaa57e95c7f47d963 100644 (file)
@@ -902,11 +902,11 @@ xfs_vm_writepage(
         * random callers for direct reclaim or memcg reclaim.  We explicitly
         * allow reclaim from kswapd as the stack usage there is relatively low.
         *
-        * This should really be done by the core VM, but until that happens
-        * filesystems like XFS, btrfs and ext4 have to take care of this
-        * by themselves.
+        * This should never happen except in the case of a VM regression so
+        * warn about it.
         */
-       if ((current->flags & (PF_MEMALLOC|PF_KSWAPD)) == PF_MEMALLOC)
+       if (WARN_ON_ONCE((current->flags & (PF_MEMALLOC|PF_KSWAPD)) ==
+                       PF_MEMALLOC))
                goto redirty;
 
        /*
index 7fb7ea007672f04cf59e544363e9a7877b0b9191..56dc0c17f16a6578cade092c3cb553c48a729fc0 100644 (file)
@@ -3,31 +3,29 @@
 
 struct xfs_mount;
 
-extern void xfs_emerg(const struct xfs_mount *mp, const char *fmt, ...)
-        __attribute__ ((format (printf, 2, 3)));
-extern void xfs_alert(const struct xfs_mount *mp, const char *fmt, ...)
-        __attribute__ ((format (printf, 2, 3)));
-extern void xfs_alert_tag(const struct xfs_mount *mp, int tag,
-                        const char *fmt, ...)
-        __attribute__ ((format (printf, 3, 4)));
-extern void xfs_crit(const struct xfs_mount *mp, const char *fmt, ...)
-        __attribute__ ((format (printf, 2, 3)));
-extern void xfs_err(const struct xfs_mount *mp, const char *fmt, ...)
-        __attribute__ ((format (printf, 2, 3)));
-extern void xfs_warn(const struct xfs_mount *mp, const char *fmt, ...)
-        __attribute__ ((format (printf, 2, 3)));
-extern void xfs_notice(const struct xfs_mount *mp, const char *fmt, ...)
-        __attribute__ ((format (printf, 2, 3)));
-extern void xfs_info(const struct xfs_mount *mp, const char *fmt, ...)
-        __attribute__ ((format (printf, 2, 3)));
+extern __printf(2, 3)
+void xfs_emerg(const struct xfs_mount *mp, const char *fmt, ...);
+extern __printf(2, 3)
+void xfs_alert(const struct xfs_mount *mp, const char *fmt, ...);
+extern __printf(3, 4)
+void xfs_alert_tag(const struct xfs_mount *mp, int tag, const char *fmt, ...);
+extern __printf(2, 3)
+void xfs_crit(const struct xfs_mount *mp, const char *fmt, ...);
+extern __printf(2, 3)
+void xfs_err(const struct xfs_mount *mp, const char *fmt, ...);
+extern __printf(2, 3)
+void xfs_warn(const struct xfs_mount *mp, const char *fmt, ...);
+extern __printf(2, 3)
+void xfs_notice(const struct xfs_mount *mp, const char *fmt, ...);
+extern __printf(2, 3)
+void xfs_info(const struct xfs_mount *mp, const char *fmt, ...);
 
 #ifdef DEBUG
-extern void xfs_debug(const struct xfs_mount *mp, const char *fmt, ...)
-        __attribute__ ((format (printf, 2, 3)));
+extern __printf(2, 3)
+void xfs_debug(const struct xfs_mount *mp, const char *fmt, ...);
 #else
-static inline void
-__attribute__ ((format (printf, 2, 3)))
-xfs_debug(const struct xfs_mount *mp, const char *fmt, ...)
+static inline __printf(2, 3)
+void xfs_debug(const struct xfs_mount *mp, const char *fmt, ...)
 {
 }
 #endif
index 4543b6f75867dfa4e6695e52e764cdd20c8f778d..83062ed0ef2f7177285e6688a07e81db8c1a90e4 100644 (file)
@@ -189,6 +189,8 @@ void acpi_os_fixed_event_count(u32 fixed_event_number);
 /*
  * Threads and Scheduling
  */
+extern struct workqueue_struct *kacpi_hotplug_wq;
+
 acpi_thread_id acpi_os_get_thread_id(void);
 
 acpi_status
index dfb0ec666c9441d08ab1e81166e27c6a290b56c9..84458b0c38d15f76fc100447a88291b5256a02ae 100644 (file)
@@ -61,11 +61,12 @@ struct bug_entry {
  */
 #ifndef __WARN_TAINT
 #ifndef __ASSEMBLY__
-extern void warn_slowpath_fmt(const char *file, const int line,
-               const char *fmt, ...) __attribute__((format(printf, 3, 4)));
-extern void warn_slowpath_fmt_taint(const char *file, const int line,
-                                   unsigned taint, const char *fmt, ...)
-       __attribute__((format(printf, 4, 5)));
+extern __printf(3, 4)
+void warn_slowpath_fmt(const char *file, const int line,
+                      const char *fmt, ...);
+extern __printf(4, 5)
+void warn_slowpath_fmt_taint(const char *file, const int line, unsigned taint,
+                            const char *fmt, ...);
 extern void warn_slowpath_null(const char *file, const int line);
 #define WANT_WARN_ON_SLOWPATH
 #endif
index 4647c762d970601b9e36f1bdd9e263de49d29071..c084767c88bcc78215f71a2758144754c17cf82d 100644 (file)
@@ -33,8 +33,10 @@ extern __wsum csum_partial_copy(const void *src, void *dst, int len, __wsum sum)
 extern __wsum csum_partial_copy_from_user(const void __user *src, void *dst,
                                        int len, __wsum sum, int *csum_err);
 
+#ifndef csum_partial_copy_nocheck
 #define csum_partial_copy_nocheck(src, dst, len, sum)  \
        csum_partial_copy((src), (dst), (len), (sum))
+#endif
 
 /*
  * This is a version of ip_compute_csum() optimized for IP headers,
@@ -63,12 +65,14 @@ csum_tcpudp_nofold(__be32 saddr, __be32 daddr, unsigned short len,
                unsigned short proto, __wsum sum);
 #endif
 
+#ifndef csum_tcpudp_magic
 static inline __sum16
 csum_tcpudp_magic(__be32 saddr, __be32 daddr, unsigned short len,
                  unsigned short proto, __wsum sum)
 {
        return csum_fold(csum_tcpudp_nofold(saddr, daddr, len, proto, sum));
 }
+#endif
 
 /*
  * this routine is used for miscellaneous IP-like checksums, mainly
index 0c80bb38773f142ef829dcbc190c60f2cf6ccff8..9fa3f96e38cf291a298232e6051c6af651a205c0 100644 (file)
@@ -123,7 +123,12 @@ static inline void dma_sync_single_range_for_cpu(struct device *dev,
                                                 size_t size,
                                                 enum dma_data_direction dir)
 {
-       dma_sync_single_for_cpu(dev, addr + offset, size, dir);
+       const struct dma_map_ops *ops = get_dma_ops(dev);
+
+       BUG_ON(!valid_dma_direction(dir));
+       if (ops->sync_single_for_cpu)
+               ops->sync_single_for_cpu(dev, addr + offset, size, dir);
+       debug_dma_sync_single_range_for_cpu(dev, addr, offset, size, dir);
 }
 
 static inline void dma_sync_single_range_for_device(struct device *dev,
@@ -132,7 +137,12 @@ static inline void dma_sync_single_range_for_device(struct device *dev,
                                                    size_t size,
                                                    enum dma_data_direction dir)
 {
-       dma_sync_single_for_device(dev, addr + offset, size, dir);
+       const struct dma_map_ops *ops = get_dma_ops(dev);
+
+       BUG_ON(!valid_dma_direction(dir));
+       if (ops->sync_single_for_device)
+               ops->sync_single_for_device(dev, addr + offset, size, dir);
+       debug_dma_sync_single_range_for_device(dev, addr, offset, size, dir);
 }
 
 static inline void
index d494001b12260a2f56b9337e01226f17dcee3634..8c8621097fa0916f770e18eeffa08a410ecf43dd 100644 (file)
@@ -41,6 +41,7 @@ static inline bool gpio_is_valid(int number)
 }
 
 struct device;
+struct gpio;
 struct seq_file;
 struct module;
 struct device_node;
@@ -170,18 +171,6 @@ extern int __gpio_cansleep(unsigned gpio);
 
 extern int __gpio_to_irq(unsigned gpio);
 
-/**
- * struct gpio - a structure describing a GPIO with configuration
- * @gpio:      the GPIO number
- * @flags:     GPIO configuration as specified by GPIOF_*
- * @label:     a literal description string of this GPIO
- */
-struct gpio {
-       unsigned        gpio;
-       unsigned long   flags;
-       const char      *label;
-};
-
 extern int gpio_request_one(unsigned gpio, unsigned long flags, const char *label);
 extern int gpio_request_array(const struct gpio *array, size_t num);
 extern void gpio_free_array(const struct gpio *array, size_t num);
@@ -220,13 +209,13 @@ static inline int gpio_cansleep(unsigned gpio)
 static inline int gpio_get_value_cansleep(unsigned gpio)
 {
        might_sleep();
-       return gpio_get_value(gpio);
+       return __gpio_get_value(gpio);
 }
 
 static inline void gpio_set_value_cansleep(unsigned gpio, int value)
 {
        might_sleep();
-       gpio_set_value(gpio, value);
+       __gpio_set_value(gpio, value);
 }
 
 #endif /* !CONFIG_GPIOLIB */
index 75fec18cdc59e1f92ee55ce5f93414e47e76dc5a..351889d1de19282fdb10155d06d32301d148ba13 100644 (file)
@@ -79,8 +79,8 @@ extern unsigned long memory_end;
 #define virt_to_pfn(kaddr)     (__pa(kaddr) >> PAGE_SHIFT)
 #define pfn_to_virt(pfn)       __va((pfn) << PAGE_SHIFT)
 
-#define virt_to_page(addr)     (mem_map + (((unsigned long)(addr)-PAGE_OFFSET) >> PAGE_SHIFT))
-#define page_to_virt(page)     ((((page) - mem_map) << PAGE_SHIFT) + PAGE_OFFSET)
+#define virt_to_page(addr)     pfn_to_page(virt_to_pfn(addr))
+#define page_to_virt(page)     pfn_to_virt(page_to_pfn(page))
 
 #ifndef page_to_phys
 #define page_to_phys(page)      ((dma_addr_t)page_to_pfn(page) << PAGE_SHIFT)
diff --git a/include/asm-generic/rwsem.h b/include/asm-generic/rwsem.h
new file mode 100644 (file)
index 0000000..bb1e2cd
--- /dev/null
@@ -0,0 +1,132 @@
+#ifndef _ASM_POWERPC_RWSEM_H
+#define _ASM_POWERPC_RWSEM_H
+
+#ifndef _LINUX_RWSEM_H
+#error "Please don't include <asm/rwsem.h> directly, use <linux/rwsem.h> instead."
+#endif
+
+#ifdef __KERNEL__
+
+/*
+ * R/W semaphores for PPC using the stuff in lib/rwsem.c.
+ * Adapted largely from include/asm-i386/rwsem.h
+ * by Paul Mackerras <paulus@samba.org>.
+ */
+
+/*
+ * the semaphore definition
+ */
+#ifdef CONFIG_PPC64
+# define RWSEM_ACTIVE_MASK             0xffffffffL
+#else
+# define RWSEM_ACTIVE_MASK             0x0000ffffL
+#endif
+
+#define RWSEM_UNLOCKED_VALUE           0x00000000L
+#define RWSEM_ACTIVE_BIAS              0x00000001L
+#define RWSEM_WAITING_BIAS             (-RWSEM_ACTIVE_MASK-1)
+#define RWSEM_ACTIVE_READ_BIAS         RWSEM_ACTIVE_BIAS
+#define RWSEM_ACTIVE_WRITE_BIAS                (RWSEM_WAITING_BIAS + RWSEM_ACTIVE_BIAS)
+
+/*
+ * lock for reading
+ */
+static inline void __down_read(struct rw_semaphore *sem)
+{
+       if (unlikely(atomic_long_inc_return((atomic_long_t *)&sem->count) <= 0))
+               rwsem_down_read_failed(sem);
+}
+
+static inline int __down_read_trylock(struct rw_semaphore *sem)
+{
+       long tmp;
+
+       while ((tmp = sem->count) >= 0) {
+               if (tmp == cmpxchg(&sem->count, tmp,
+                                  tmp + RWSEM_ACTIVE_READ_BIAS)) {
+                       return 1;
+               }
+       }
+       return 0;
+}
+
+/*
+ * lock for writing
+ */
+static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
+{
+       long tmp;
+
+       tmp = atomic_long_add_return(RWSEM_ACTIVE_WRITE_BIAS,
+                                    (atomic_long_t *)&sem->count);
+       if (unlikely(tmp != RWSEM_ACTIVE_WRITE_BIAS))
+               rwsem_down_write_failed(sem);
+}
+
+static inline void __down_write(struct rw_semaphore *sem)
+{
+       __down_write_nested(sem, 0);
+}
+
+static inline int __down_write_trylock(struct rw_semaphore *sem)
+{
+       long tmp;
+
+       tmp = cmpxchg(&sem->count, RWSEM_UNLOCKED_VALUE,
+                     RWSEM_ACTIVE_WRITE_BIAS);
+       return tmp == RWSEM_UNLOCKED_VALUE;
+}
+
+/*
+ * unlock after reading
+ */
+static inline void __up_read(struct rw_semaphore *sem)
+{
+       long tmp;
+
+       tmp = atomic_long_dec_return((atomic_long_t *)&sem->count);
+       if (unlikely(tmp < -1 && (tmp & RWSEM_ACTIVE_MASK) == 0))
+               rwsem_wake(sem);
+}
+
+/*
+ * unlock after writing
+ */
+static inline void __up_write(struct rw_semaphore *sem)
+{
+       if (unlikely(atomic_long_sub_return(RWSEM_ACTIVE_WRITE_BIAS,
+                                (atomic_long_t *)&sem->count) < 0))
+               rwsem_wake(sem);
+}
+
+/*
+ * implement atomic add functionality
+ */
+static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
+{
+       atomic_long_add(delta, (atomic_long_t *)&sem->count);
+}
+
+/*
+ * downgrade write lock to read lock
+ */
+static inline void __downgrade_write(struct rw_semaphore *sem)
+{
+       long tmp;
+
+       tmp = atomic_long_add_return(-RWSEM_WAITING_BIAS,
+                                    (atomic_long_t *)&sem->count);
+       if (tmp < 0)
+               rwsem_downgrade_wake(sem);
+}
+
+/*
+ * implement exchange and add functionality
+ */
+static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
+{
+       return atomic_long_add_return(delta, (atomic_long_t *)&sem->count);
+}
+
+#endif /* __KERNEL__ */
+#endif /* _ASM_POWERPC_RWSEM_H */
index 59c3e5bd2c064cb59baa4248f75618f15270b543..ecc721def10c8ae2a6ba4dee6fead57d20af48f0 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/crypto.h>
 #include <linux/list.h>
 #include <linux/kernel.h>
+#include <linux/skbuff.h>
 
 struct module;
 struct rtattr;
@@ -26,6 +27,7 @@ struct crypto_type {
        int (*init)(struct crypto_tfm *tfm, u32 type, u32 mask);
        int (*init_tfm)(struct crypto_tfm *tfm);
        void (*show)(struct seq_file *m, struct crypto_alg *alg);
+       int (*report)(struct sk_buff *skb, struct crypto_alg *alg);
        struct crypto_alg *(*lookup)(const char *name, u32 type, u32 mask);
 
        unsigned int type;
diff --git a/include/crypto/blowfish.h b/include/crypto/blowfish.h
new file mode 100644 (file)
index 0000000..1450d4a
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * Common values for blowfish algorithms
+ */
+
+#ifndef _CRYPTO_BLOWFISH_H
+#define _CRYPTO_BLOWFISH_H
+
+#include <linux/types.h>
+#include <linux/crypto.h>
+
+#define BF_BLOCK_SIZE 8
+#define BF_MIN_KEY_SIZE 4
+#define BF_MAX_KEY_SIZE 56
+
+struct bf_ctx {
+       u32 p[18];
+       u32 s[1024];
+};
+
+int blowfish_setkey(struct crypto_tfm *tfm, const u8 *key,
+                   unsigned int key_len);
+
+#endif
index 069e85ba97e1874a6f92cb98dc0f4794e8969249..c6c9c1fe460c20e1d11e923c500a872f225d3c29 100644 (file)
@@ -82,4 +82,9 @@ struct sha512_state {
        u8 buf[SHA512_BLOCK_SIZE];
 };
 
+struct shash_desc;
+
+extern int crypto_sha1_update(struct shash_desc *desc, const u8 *data,
+                             unsigned int len);
+
 #endif
index 43538b64356032a19d3ac62bc69a85b49c48b72a..cf3b446139ea8a3f7ea1ecea86f7f41e4cdc4c09 100644 (file)
@@ -122,12 +122,12 @@ struct drm_device;
  * using the DRM_DEBUG_KMS and DRM_DEBUG.
  */
 
-extern __attribute__((format (printf, 4, 5)))
+extern __printf(4, 5)
 void drm_ut_debug_printk(unsigned int request_level,
-                               const char *prefix,
-                               const char *function_name,
-                               const char *format, ...);
-extern __attribute__((format (printf, 2, 3)))
+                        const char *prefix,
+                        const char *function_name,
+                        const char *format, ...);
+extern __printf(2, 3)
 int drm_err(const char *func, const char *format, ...);
 
 /***********************************************************************/
index 5ddd9ad4b19c9c381d77ab5c24a01031b4127ba3..2412af944f1f584dcc611e17b910e8f55eb79cfc 100644 (file)
@@ -7,8 +7,7 @@ struct pl061_platform_data {
        unsigned        gpio_base;
 
        /* number of the first IRQ.
-        * If the IRQ functionality in not desired this must be set to
-        * (unsigned) -1.
+        * If the IRQ functionality in not desired this must be set to NO_IRQ.
         */
        unsigned        irq_base;
 
index 3e09b345f4d675ffddcab95e6d6b72039d141237..4c7a4b2104bfc6b105f5258763fda8f0fa6685df 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef __LINUX_ATMEL_MCI_H
 #define __LINUX_ATMEL_MCI_H
 
-#define ATMEL_MCI_MAX_NR_SLOTS 2
+#define ATMCI_MAX_NR_SLOTS     2
 
 /**
  * struct mci_slot_pdata - board-specific per-slot configuration
@@ -33,7 +33,7 @@ struct mci_slot_pdata {
  */
 struct mci_platform_data {
        struct mci_dma_data     *dma_slave;
-       struct mci_slot_pdata   slot[ATMEL_MCI_MAX_NR_SLOTS];
+       struct mci_slot_pdata   slot[ATMCI_MAX_NR_SLOTS];
 };
 
 #endif /* __LINUX_ATMEL_MCI_H */
index 5058a31d2ce8d19ff297ea1d71464e56b146c3ba..63499ce806eaf984c00bbc93b2fb018e5b3de999 100644 (file)
@@ -33,4 +33,6 @@
 
 #define ATMEL_PDC_PTSR         0x124   /* Transfer Status Register */
 
+#define ATMEL_PDC_SCND_BUF_OFF 0x10    /* Offset between first and second buffer registers */
+
 #endif
index 0c8006129fb2795195443eee29f1b8a84d511652..2f81c6f3b630d74e38240e1b9415d3635b0e358f 100644 (file)
@@ -584,14 +584,13 @@ extern int audit_signals;
 #ifdef CONFIG_AUDIT
 /* These are defined in audit.c */
                                /* Public API */
-extern void                audit_log(struct audit_context *ctx, gfp_t gfp_mask,
-                                     int type, const char *fmt, ...)
-                                     __attribute__((format(printf,4,5)));
+extern __printf(4, 5)
+void audit_log(struct audit_context *ctx, gfp_t gfp_mask, int type,
+              const char *fmt, ...);
 
 extern struct audit_buffer *audit_log_start(struct audit_context *ctx, gfp_t gfp_mask, int type);
-extern void                audit_log_format(struct audit_buffer *ab,
-                                            const char *fmt, ...)
-                           __attribute__((format(printf,2,3)));
+extern __printf(2, 3)
+void audit_log_format(struct audit_buffer *ab, const char *fmt, ...);
 extern void                audit_log_end(struct audit_buffer *ab);
 extern int                 audit_string_contains_control(const char *string,
                                                          size_t len);
index 8e9e4bc6d73b4b5351748afca97a2b4a43b66654..4d1a0748eaf8721c0cd4a34c0baf29ce455fc2d2 100644 (file)
@@ -170,7 +170,7 @@ extern void blk_trace_shutdown(struct request_queue *);
 extern int do_blk_trace_setup(struct request_queue *q, char *name,
                              dev_t dev, struct block_device *bdev,
                              struct blk_user_trace_setup *buts);
-extern __attribute__((format(printf, 2, 3)))
+extern __printf(2, 3)
 void __trace_note_message(struct blk_trace *, const char *fmt, ...);
 
 /**
index 563755181c1ea33e7a4c8ff99565704b5432d566..95bd8502e715e48f8222345e1274761fee030662 100644 (file)
@@ -215,7 +215,9 @@ extern void ceph_destroy_options(struct ceph_options *opt);
 extern int ceph_compare_options(struct ceph_options *new_opt,
                                struct ceph_client *client);
 extern struct ceph_client *ceph_create_client(struct ceph_options *opt,
-                                             void *private);
+                                             void *private,
+                                             unsigned supported_features,
+                                             unsigned required_features);
 extern u64 ceph_client_id(struct ceph_client *client);
 extern void ceph_destroy_client(struct ceph_client *client);
 extern int __ceph_open_session(struct ceph_client *client,
index ca768ae729b44683983c3b478cf5c3a22e1ac253..ffbeb2c217b442036a2675cc4cb4e6d5e1bf0d8b 100644 (file)
@@ -237,7 +237,8 @@ extern void ceph_con_keepalive(struct ceph_connection *con);
 extern struct ceph_connection *ceph_con_get(struct ceph_connection *con);
 extern void ceph_con_put(struct ceph_connection *con);
 
-extern struct ceph_msg *ceph_msg_new(int type, int front_len, gfp_t flags);
+extern struct ceph_msg *ceph_msg_new(int type, int front_len, gfp_t flags,
+                                    bool can_fail);
 extern void ceph_msg_kfree(struct ceph_msg *m);
 
 
index cc9f7a4286490a3bae2d47db3fe74d2dabfd4aac..bb2bbdbe546495e1f0ab94e87b58578bc5c0c53f 100644 (file)
@@ -24,8 +24,6 @@ extern unsigned long try_to_compact_pages(struct zonelist *zonelist,
                        int order, gfp_t gfp_mask, nodemask_t *mask,
                        bool sync);
 extern unsigned long compaction_suitable(struct zone *zone, int order);
-extern unsigned long compact_zone_order(struct zone *zone, int order,
-                                       gfp_t gfp_mask, bool sync);
 
 /* Do not skip compaction more than 64 times */
 #define COMPACT_MAX_DEFER_SHIFT 6
@@ -69,12 +67,6 @@ static inline unsigned long compaction_suitable(struct zone *zone, int order)
        return COMPACT_SKIPPED;
 }
 
-static inline unsigned long compact_zone_order(struct zone *zone, int order,
-                                              gfp_t gfp_mask, bool sync)
-{
-       return COMPACT_CONTINUE;
-}
-
 static inline void defer_compaction(struct zone *zone)
 {
 }
index c6e7523bf7652ab050285c2c02dad3715a010cab..154bf56830156876d56c1ced7d4c1e6c96973805 100644 (file)
@@ -547,7 +547,8 @@ extern ssize_t compat_rw_copy_check_uvector(int type,
                const struct compat_iovec __user *uvector,
                unsigned long nr_segs,
                unsigned long fast_segs, struct iovec *fast_pointer,
-               struct iovec **ret_pointer);
+               struct iovec **ret_pointer,
+               int check_access);
 
 extern void __user *compat_alloc_user_space(unsigned long len);
 
index 74054074e876d8da1ae9de24dc8ae64f856391c7..5c4abce94ad1665803c79fd61a501e6969477029 100644 (file)
@@ -10,6 +10,7 @@
 #define ELFCORE_ADDR_ERR       (-2ULL)
 
 extern unsigned long long elfcorehdr_addr;
+extern unsigned long long elfcorehdr_size;
 
 extern ssize_t copy_oldmem_page(unsigned long, char *, size_t,
                                                unsigned long, int);
index e5e468e9133d645411fe18314bb24d81e8701471..de9adec5693c7fd17a9c738439c6d6dda6facf8c 100644 (file)
 
 #define CRYPTO_ALG_TESTED              0x00000400
 
+/*
+ * Set if the algorithm is an instance that is build from templates.
+ */
+#define CRYPTO_ALG_INSTANCE            0x00000800
+
 /*
  * Transform masks and values (for crt_flags).
  */
diff --git a/include/linux/cryptouser.h b/include/linux/cryptouser.h
new file mode 100644 (file)
index 0000000..532fb58
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * Crypto user configuration API.
+ *
+ * Copyright (C) 2011 secunet Security Networks AG
+ * Copyright (C) 2011 Steffen Klassert <steffen.klassert@secunet.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/* Netlink configuration messages.  */
+enum {
+       CRYPTO_MSG_BASE = 0x10,
+       CRYPTO_MSG_NEWALG = 0x10,
+       CRYPTO_MSG_DELALG,
+       CRYPTO_MSG_UPDATEALG,
+       CRYPTO_MSG_GETALG,
+       __CRYPTO_MSG_MAX
+};
+#define CRYPTO_MSG_MAX (__CRYPTO_MSG_MAX - 1)
+#define CRYPTO_NR_MSGTYPES (CRYPTO_MSG_MAX + 1 - CRYPTO_MSG_BASE)
+
+#define CRYPTO_MAX_NAME CRYPTO_MAX_ALG_NAME
+
+/* Netlink message attributes.  */
+enum crypto_attr_type_t {
+       CRYPTOCFGA_UNSPEC,
+       CRYPTOCFGA_PRIORITY_VAL,        /* __u32 */
+       CRYPTOCFGA_REPORT_LARVAL,       /* struct crypto_report_larval */
+       CRYPTOCFGA_REPORT_HASH,         /* struct crypto_report_hash */
+       CRYPTOCFGA_REPORT_BLKCIPHER,    /* struct crypto_report_blkcipher */
+       CRYPTOCFGA_REPORT_AEAD,         /* struct crypto_report_aead */
+       CRYPTOCFGA_REPORT_COMPRESS,     /* struct crypto_report_comp */
+       CRYPTOCFGA_REPORT_RNG,          /* struct crypto_report_rng */
+       CRYPTOCFGA_REPORT_CIPHER,       /* struct crypto_report_cipher */
+       __CRYPTOCFGA_MAX
+
+#define CRYPTOCFGA_MAX (__CRYPTOCFGA_MAX - 1)
+};
+
+struct crypto_user_alg {
+       char cru_name[CRYPTO_MAX_ALG_NAME];
+       char cru_driver_name[CRYPTO_MAX_ALG_NAME];
+       char cru_module_name[CRYPTO_MAX_ALG_NAME];
+       __u32 cru_type;
+       __u32 cru_mask;
+       __u32 cru_refcnt;
+       __u32 cru_flags;
+};
+
+struct crypto_report_larval {
+       char type[CRYPTO_MAX_NAME];
+};
+
+struct crypto_report_hash {
+       char type[CRYPTO_MAX_NAME];
+       unsigned int blocksize;
+       unsigned int digestsize;
+};
+
+struct crypto_report_cipher {
+       char type[CRYPTO_MAX_ALG_NAME];
+       unsigned int blocksize;
+       unsigned int min_keysize;
+       unsigned int max_keysize;
+};
+
+struct crypto_report_blkcipher {
+       char type[CRYPTO_MAX_NAME];
+       char geniv[CRYPTO_MAX_NAME];
+       unsigned int blocksize;
+       unsigned int min_keysize;
+       unsigned int max_keysize;
+       unsigned int ivsize;
+};
+
+struct crypto_report_aead {
+       char type[CRYPTO_MAX_NAME];
+       char geniv[CRYPTO_MAX_NAME];
+       unsigned int blocksize;
+       unsigned int maxauthsize;
+       unsigned int ivsize;
+};
+
+struct crypto_report_comp {
+       char type[CRYPTO_MAX_NAME];
+};
+
+struct crypto_report_rng {
+       char type[CRYPTO_MAX_NAME];
+       unsigned int seedsize;
+};
index bdcf361ca938d26fbf4c7792b031ddc427cee4bc..e88abeecfadf44b45b3325e66cdcac82e8901185 100644 (file)
@@ -33,6 +33,7 @@ struct class;
 struct subsys_private;
 struct bus_type;
 struct device_node;
+struct iommu_ops;
 
 struct bus_attribute {
        struct attribute        attr;
@@ -67,6 +68,9 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *);
  * @resume:    Called to bring a device on this bus out of sleep mode.
  * @pm:                Power management operations of this bus, callback the specific
  *             device driver's pm-ops.
+ * @iommu_ops   IOMMU specific operations for this bus, used to attach IOMMU
+ *              driver implementations to a bus and allow the driver to do
+ *              bus-specific setup
  * @p:         The private data of the driver core, only the driver core can
  *             touch this.
  *
@@ -96,6 +100,8 @@ struct bus_type {
 
        const struct dev_pm_ops *pm;
 
+       struct iommu_ops *iommu_ops;
+
        struct subsys_private *p;
 };
 
@@ -616,8 +622,8 @@ static inline const char *dev_name(const struct device *dev)
        return kobject_name(&dev->kobj);
 }
 
-extern int dev_set_name(struct device *dev, const char *name, ...)
-                       __attribute__((format(printf, 2, 3)));
+extern __printf(2, 3)
+int dev_set_name(struct device *dev, const char *name, ...);
 
 #ifdef CONFIG_NUMA
 static inline int dev_to_node(struct device *dev)
@@ -747,10 +753,10 @@ extern struct device *device_create_vargs(struct class *cls,
                                          void *drvdata,
                                          const char *fmt,
                                          va_list vargs);
-extern struct device *device_create(struct class *cls, struct device *parent,
-                                   dev_t devt, void *drvdata,
-                                   const char *fmt, ...)
-                                   __attribute__((format(printf, 5, 6)));
+extern __printf(5, 6)
+struct device *device_create(struct class *cls, struct device *parent,
+                            dev_t devt, void *drvdata,
+                            const char *fmt, ...);
 extern void device_destroy(struct class *cls, dev_t devt);
 
 /*
@@ -794,64 +800,56 @@ extern const char *dev_driver_string(const struct device *dev);
 
 extern int __dev_printk(const char *level, const struct device *dev,
                        struct va_format *vaf);
-extern int dev_printk(const char *level, const struct device *dev,
-                     const char *fmt, ...)
-       __attribute__ ((format (printf, 3, 4)));
-extern int dev_emerg(const struct device *dev, const char *fmt, ...)
-       __attribute__ ((format (printf, 2, 3)));
-extern int dev_alert(const struct device *dev, const char *fmt, ...)
-       __attribute__ ((format (printf, 2, 3)));
-extern int dev_crit(const struct device *dev, const char *fmt, ...)
-       __attribute__ ((format (printf, 2, 3)));
-extern int dev_err(const struct device *dev, const char *fmt, ...)
-       __attribute__ ((format (printf, 2, 3)));
-extern int dev_warn(const struct device *dev, const char *fmt, ...)
-       __attribute__ ((format (printf, 2, 3)));
-extern int dev_notice(const struct device *dev, const char *fmt, ...)
-       __attribute__ ((format (printf, 2, 3)));
-extern int _dev_info(const struct device *dev, const char *fmt, ...)
-       __attribute__ ((format (printf, 2, 3)));
+extern __printf(3, 4)
+int dev_printk(const char *level, const struct device *dev,
+              const char *fmt, ...)
+       ;
+extern __printf(2, 3)
+int dev_emerg(const struct device *dev, const char *fmt, ...);
+extern __printf(2, 3)
+int dev_alert(const struct device *dev, const char *fmt, ...);
+extern __printf(2, 3)
+int dev_crit(const struct device *dev, const char *fmt, ...);
+extern __printf(2, 3)
+int dev_err(const struct device *dev, const char *fmt, ...);
+extern __printf(2, 3)
+int dev_warn(const struct device *dev, const char *fmt, ...);
+extern __printf(2, 3)
+int dev_notice(const struct device *dev, const char *fmt, ...);
+extern __printf(2, 3)
+int _dev_info(const struct device *dev, const char *fmt, ...);
 
 #else
 
 static inline int __dev_printk(const char *level, const struct device *dev,
                               struct va_format *vaf)
-        { return 0; }
-static inline int dev_printk(const char *level, const struct device *dev,
-                     const char *fmt, ...)
-       __attribute__ ((format (printf, 3, 4)));
-static inline int dev_printk(const char *level, const struct device *dev,
-                     const char *fmt, ...)
-        { return 0; }
-
-static inline int dev_emerg(const struct device *dev, const char *fmt, ...)
-       __attribute__ ((format (printf, 2, 3)));
-static inline int dev_emerg(const struct device *dev, const char *fmt, ...)
-       { return 0; }
-static inline int dev_crit(const struct device *dev, const char *fmt, ...)
-       __attribute__ ((format (printf, 2, 3)));
-static inline int dev_crit(const struct device *dev, const char *fmt, ...)
-       { return 0; }
-static inline int dev_alert(const struct device *dev, const char *fmt, ...)
-       __attribute__ ((format (printf, 2, 3)));
-static inline int dev_alert(const struct device *dev, const char *fmt, ...)
-       { return 0; }
-static inline int dev_err(const struct device *dev, const char *fmt, ...)
-       __attribute__ ((format (printf, 2, 3)));
-static inline int dev_err(const struct device *dev, const char *fmt, ...)
-       { return 0; }
-static inline int dev_warn(const struct device *dev, const char *fmt, ...)
-       __attribute__ ((format (printf, 2, 3)));
-static inline int dev_warn(const struct device *dev, const char *fmt, ...)
-       { return 0; }
-static inline int dev_notice(const struct device *dev, const char *fmt, ...)
-       __attribute__ ((format (printf, 2, 3)));
-static inline int dev_notice(const struct device *dev, const char *fmt, ...)
-       { return 0; }
-static inline int _dev_info(const struct device *dev, const char *fmt, ...)
-       __attribute__ ((format (printf, 2, 3)));
-static inline int _dev_info(const struct device *dev, const char *fmt, ...)
-       { return 0; }
+{ return 0; }
+static inline __printf(3, 4)
+int dev_printk(const char *level, const struct device *dev,
+              const char *fmt, ...)
+{ return 0; }
+
+static inline __printf(2, 3)
+int dev_emerg(const struct device *dev, const char *fmt, ...)
+{ return 0; }
+static inline __printf(2, 3)
+int dev_crit(const struct device *dev, const char *fmt, ...)
+{ return 0; }
+static inline __printf(2, 3)
+int dev_alert(const struct device *dev, const char *fmt, ...)
+{ return 0; }
+static inline __printf(2, 3)
+int dev_err(const struct device *dev, const char *fmt, ...)
+{ return 0; }
+static inline __printf(2, 3)
+int dev_warn(const struct device *dev, const char *fmt, ...)
+{ return 0; }
+static inline __printf(2, 3)
+int dev_notice(const struct device *dev, const char *fmt, ...)
+{ return 0; }
+static inline __printf(2, 3)
+int _dev_info(const struct device *dev, const char *fmt, ...)
+{ return 0; }
 
 #endif
 
index a8b1a847c103bb5cefed7aa7dbb6f4f847079fd5..731a60975101ce76c8e6aa045acde8409c0c2059 100644 (file)
@@ -26,6 +26,8 @@
 #include <linux/msi.h>
 #include <linux/irqreturn.h>
 
+struct acpi_dmar_header;
+
 /* DMAR Flags */
 #define DMAR_INTR_REMAP                0x1
 #define DMAR_X2APIC_OPT_OUT    0x2
index 36a3ed63f571e88a468acdeb1c82933c0015e38b..1b1094c35e4fd979f6b49d35b9f6c725ee0eac9b 100644 (file)
@@ -349,6 +349,7 @@ typedef enum fe_delivery_system {
        SYS_CMMB,
        SYS_DAB,
        SYS_DVBT2,
+       SYS_TURBO,
 } fe_delivery_system_t;
 
 struct dtv_cmds_h {
index 1421cc84afaa6cf7561145c14cd4f8b408205797..66594b1d5d7b01a766c359ce96d3e6dbc290c984 100644 (file)
@@ -24,6 +24,6 @@
 #define _DVBVERSION_H_
 
 #define DVB_API_VERSION 5
-#define DVB_API_VERSION_MINOR 3
+#define DVB_API_VERSION_MINOR 4
 
 #endif /*_DVBVERSION_H_*/
index 13aae8087b560b7a487489afac198e4b4ef9dae1..0564e3c39882fc20e7e4c3e08d8ea2840d32302d 100644 (file)
@@ -37,22 +37,21 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n,
 
 #if defined(CONFIG_DYNAMIC_DEBUG)
 extern int ddebug_remove_module(const char *mod_name);
-extern int __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...)
-       __attribute__ ((format (printf, 2, 3)));
+extern __printf(2, 3)
+int __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...);
 
 struct device;
 
-extern int __dynamic_dev_dbg(struct _ddebug *descriptor,
-                            const struct device *dev,
-                            const char *fmt, ...)
-       __attribute__ ((format (printf, 3, 4)));
+extern __printf(3, 4)
+int __dynamic_dev_dbg(struct _ddebug *descriptor, const struct device *dev,
+                     const char *fmt, ...);
 
 struct net_device;
 
-extern int __dynamic_netdev_dbg(struct _ddebug *descriptor,
-                            const struct net_device *dev,
-                            const char *fmt, ...)
-       __attribute__ ((format (printf, 3, 4)));
+extern __printf(3, 4)
+int __dynamic_netdev_dbg(struct _ddebug *descriptor,
+                        const struct net_device *dev,
+                        const char *fmt, ...);
 
 #define DEFINE_DYNAMIC_DEBUG_METADATA(name, fmt)               \
        static struct _ddebug __used __aligned(8)               \
index 110821cb6ea5fb5c8789da31f26af10ee61fc68d..31f0508d7da7a3274e207cc3389edb824ed77fd3 100644 (file)
@@ -395,6 +395,7 @@ typedef struct elf64_shdr {
 #define NT_S390_CTRS   0x304           /* s390 control registers */
 #define NT_S390_PREFIX 0x305           /* s390 prefix register */
 #define NT_S390_LAST_BREAK     0x306   /* s390 breaking event address */
+#define NT_S390_SYSTEM_CALL    0x307   /* s390 system call restart data */
 #define NT_ARM_VFP     0x400           /* ARM VFP/NEON registers */
 
 
index 67a803aee619c0b75593e4c740abc35087f28d49..81965cce6bfafb96e146e0b0f67ad473aa0bf455 100644 (file)
@@ -937,15 +937,15 @@ extern int ext3_group_extend(struct super_block *sb,
                                ext3_fsblk_t n_blocks_count);
 
 /* super.c */
-extern void ext3_error (struct super_block *, const char *, const char *, ...)
-       __attribute__ ((format (printf, 3, 4)));
+extern __printf(3, 4)
+void ext3_error(struct super_block *, const char *, const char *, ...);
 extern void __ext3_std_error (struct super_block *, const char *, int);
-extern void ext3_abort (struct super_block *, const char *, const char *, ...)
-       __attribute__ ((format (printf, 3, 4)));
-extern void ext3_warning (struct super_block *, const char *, const char *, ...)
-       __attribute__ ((format (printf, 3, 4)));
-extern void ext3_msg(struct super_block *, const char *, const char *, ...)
-       __attribute__ ((format (printf, 3, 4)));
+extern __printf(3, 4)
+void ext3_abort(struct super_block *, const char *, const char *, ...);
+extern __printf(3, 4)
+void ext3_warning(struct super_block *, const char *, const char *, ...);
+extern __printf(3, 4)
+void ext3_msg(struct super_block *, const char *, const char *, ...);
 extern void ext3_update_dynamic_rev (struct super_block *sb);
 
 #define ext3_std_error(sb, errno)                              \
index 14493a2d5a0360452dab19c01ba5ebc8605359e8..7a049fd2aa4cca0860f9dd51f7a317d7fe3b58d5 100644 (file)
@@ -1633,9 +1633,10 @@ struct inode_operations {
 struct seq_file;
 
 ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
-                               unsigned long nr_segs, unsigned long fast_segs,
-                               struct iovec *fast_pointer,
-                               struct iovec **ret_pointer);
+                             unsigned long nr_segs, unsigned long fast_segs,
+                             struct iovec *fast_pointer,
+                             struct iovec **ret_pointer,
+                             int check_access);
 
 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
 extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
@@ -2634,8 +2635,8 @@ static const struct file_operations __fops = {                            \
        .llseek  = generic_file_llseek,                                 \
 };
 
-static inline void __attribute__((format(printf, 1, 2)))
-__simple_attr_check_format(const char *fmt, ...)
+static inline __printf(1, 2)
+void __simple_attr_check_format(const char *fmt, ...)
 {
        /* don't do anything, just let the compiler check the arguments; */
 }
index af095b54502e35471cad25d0e74e042fb50ecc4f..ce31408b1e47d6e6cfb81ad25a3ca0fdaefaef84 100644 (file)
@@ -492,10 +492,10 @@ static inline void fscache_end_io(struct fscache_retrieval *op,
 /*
  * out-of-line cache backend functions
  */
-extern void fscache_init_cache(struct fscache_cache *cache,
-                              const struct fscache_cache_ops *ops,
-                              const char *idfmt,
-                              ...) __attribute__ ((format (printf, 3, 4)));
+extern __printf(3, 4)
+void fscache_init_cache(struct fscache_cache *cache,
+                       const struct fscache_cache_ops *ops,
+                       const char *idfmt, ...);
 
 extern int fscache_add_cache(struct fscache_cache *cache,
                             struct fscache_object *fsdef,
index daa9952d2174ad811cab346e9842d932079dd87c..11c16a1fb9e3d8316ac4098ca450af8089dffdb3 100644 (file)
 #ifndef __FSL_DIU_FB_H__
 #define __FSL_DIU_FB_H__
 
-/* Arbitrary threshold to determine the allocation method
- * See mpc8610fb_set_par(), map_video_memory(), and unmap_video_memory()
- */
-#define MEM_ALLOC_THRESHOLD (1024*768*4+32)
-
 #include <linux/types.h>
 
-struct mfb_alpha {
-       int enable;
-       int alpha;
-};
-
 struct mfb_chroma_key {
        int enable;
        __u8  red_max;
@@ -43,25 +33,29 @@ struct mfb_chroma_key {
 };
 
 struct aoi_display_offset {
-       int x_aoi_d;
-       int y_aoi_d;
+       __s32 x_aoi_d;
+       __s32 y_aoi_d;
 };
 
 #define MFB_SET_CHROMA_KEY     _IOW('M', 1, struct mfb_chroma_key)
 #define MFB_SET_BRIGHTNESS     _IOW('M', 3, __u8)
+#define MFB_SET_ALPHA          _IOW('M', 0, __u8)
+#define MFB_GET_ALPHA          _IOR('M', 0, __u8)
+#define MFB_SET_AOID           _IOW('M', 4, struct aoi_display_offset)
+#define MFB_GET_AOID           _IOR('M', 4, struct aoi_display_offset)
+#define MFB_SET_PIXFMT         _IOW('M', 8, __u32)
+#define MFB_GET_PIXFMT         _IOR('M', 8, __u32)
 
-#define MFB_SET_ALPHA          0x80014d00
-#define MFB_GET_ALPHA          0x40014d00
-#define MFB_SET_AOID           0x80084d04
-#define MFB_GET_AOID           0x40084d04
-#define MFB_SET_PIXFMT         0x80014d08
-#define MFB_GET_PIXFMT         0x40014d08
-
-#define FBIOGET_GWINFO         0x46E0
-#define FBIOPUT_GWINFO         0x46E1
+/*
+ * The original definitions of MFB_SET_PIXFMT and MFB_GET_PIXFMT used the
+ * wrong value for 'size' field of the ioctl.  The current macros above use the
+ * right size, but we still need to provide backwards compatibility, at least
+ * for a while.
+*/
+#define MFB_SET_PIXFMT_OLD     0x80014d08
+#define MFB_GET_PIXFMT_OLD     0x40014d08
 
 #ifdef __KERNEL__
-#include <linux/spinlock.h>
 
 /*
  * These are the fields of area descriptor(in DDR memory) for every plane
@@ -159,58 +153,12 @@ struct diu {
        __be32 plut;
 } __attribute__ ((packed));
 
-struct diu_hw {
-       struct diu *diu_reg;
-       spinlock_t reg_lock;
-
-       __u32 mode;             /* DIU operation mode */
-};
-
-struct diu_addr {
-       __u8 __iomem *vaddr;    /* Virtual address */
-       dma_addr_t paddr;       /* Physical address */
-       __u32      offset;
-};
-
-struct diu_pool {
-       struct diu_addr ad;
-       struct diu_addr gamma;
-       struct diu_addr pallete;
-       struct diu_addr cursor;
-};
-
-#define FSL_DIU_BASE_OFFSET    0x2C000 /* Offset of DIU */
-#define INT_LCDC               64      /* DIU interrupt number */
-
-#define FSL_AOI_NUM    6       /* 5 AOIs and one dummy AOI */
-                               /* 1 for plane 0, 2 for plane 1&2 each */
-
-/* Minimum X and Y resolutions */
-#define MIN_XRES       64
-#define MIN_YRES       64
-
-/* HW cursor parameters */
-#define MAX_CURS               32
-
-/* Modes of operation of DIU */
+/*
+ * Modes of operation of DIU.  The DIU supports five different modes, but
+ * the driver only supports modes 0 and 1.
+ */
 #define MFB_MODE0      0       /* DIU off */
 #define MFB_MODE1      1       /* All three planes output to display */
-#define MFB_MODE2      2       /* Plane 1 to display, planes 2+3 written back*/
-#define MFB_MODE3      3       /* All three planes written back to memory */
-#define MFB_MODE4      4       /* Color bar generation */
-
-/* INT_STATUS/INT_MASK field descriptions */
-#define INT_VSYNC      0x01    /* Vsync interrupt  */
-#define INT_VSYNC_WB   0x02    /* Vsync interrupt for write back operation */
-#define INT_UNDRUN     0x04    /* Under run exception interrupt */
-#define INT_PARERR     0x08    /* Display parameters error interrupt */
-#define INT_LS_BF_VS   0x10    /* Lines before vsync. interrupt */
-
-/* Panels'operation modes */
-#define MFB_TYPE_OUTPUT        0       /* Panel output to display */
-#define MFB_TYPE_OFF   1       /* Panel off */
-#define MFB_TYPE_WB    2       /* Panel written back to memory */
-#define MFB_TYPE_TEST  3       /* Panel generate color bar */
 
 #endif /* __KERNEL__ */
 #endif /* __FSL_DIU_FB_H__ */
index b65a6f472775db8cc542f1e515bce9ffec2b1a9c..069ee41391055477101204a44f5a6143e7caec2b 100644 (file)
@@ -78,8 +78,8 @@ static inline void gameport_register_port(struct gameport *gameport)
 
 void gameport_unregister_port(struct gameport *gameport);
 
-void gameport_set_phys(struct gameport *gameport, const char *fmt, ...)
-       __attribute__ ((format (printf, 2, 3)));
+__printf(2, 3)
+void gameport_set_phys(struct gameport *gameport, const char *fmt, ...);
 
 #else
 
@@ -93,8 +93,8 @@ static inline void gameport_unregister_port(struct gameport *gameport)
        return;
 }
 
-static inline void gameport_set_phys(struct gameport *gameport,
-                                    const char *fmt, ...)
+static inline __printf(2, 3)
+void gameport_set_phys(struct gameport *gameport, const char *fmt, ...)
 {
        return;
 }
index 02fa4697a0e51b679d8b3962e87a919541956a1f..6957350e122f2444173ff94e0d650e0dc01ef8c6 100644 (file)
@@ -21,6 +21,8 @@
 #define dev_to_part(device)    container_of((device), struct hd_struct, __dev)
 #define disk_to_dev(disk)      (&(disk)->part0.__dev)
 #define part_to_dev(part)      (&((part)->__dev))
+#define alias_name(disk)       ((disk)->alias ? (disk)->alias : \
+                                                (disk)->disk_name)
 
 extern struct device_type part_type;
 extern struct kobject *block_depr;
@@ -58,6 +60,7 @@ enum {
 
 #define DISK_MAX_PARTS                 256
 #define DISK_NAME_LEN                  32
+#define ALIAS_LEN                      256
 
 #include <linux/major.h>
 #include <linux/device.h>
@@ -162,6 +165,7 @@ struct gendisk {
                                          * disks that can't be partitioned. */
 
        char disk_name[DISK_NAME_LEN];  /* name of major driver */
+       char *alias;                    /* alias name of disk */
        char *(*devnode)(struct gendisk *gd, mode_t *mode);
 
        unsigned int events;            /* supported events */
index 17b5a0d80e4239cc10fceb670be29dbf4e49a0f0..38ac48b7d3a8db90bf0ff7630df25c2d8880ecb9 100644 (file)
 #define GPIOF_OUT_INIT_LOW     (GPIOF_DIR_OUT | GPIOF_INIT_LOW)
 #define GPIOF_OUT_INIT_HIGH    (GPIOF_DIR_OUT | GPIOF_INIT_HIGH)
 
+/**
+ * struct gpio - a structure describing a GPIO with configuration
+ * @gpio:      the GPIO number
+ * @flags:     GPIO configuration as specified by GPIOF_*
+ * @label:     a literal description string of this GPIO
+ */
+struct gpio {
+       unsigned        gpio;
+       unsigned long   flags;
+       const char      *label;
+};
+
 #ifdef CONFIG_GENERIC_GPIO
 #include <asm/gpio.h>
 
 #include <linux/errno.h>
 
 struct device;
-struct gpio;
 struct gpio_chip;
 
-/*
- * Some platforms don't support the GPIO programming interface.
- *
- * In case some driver uses it anyway (it should normally have
- * depended on GENERIC_GPIO), these routines help the compiler
- * optimize out much GPIO-related code ... or trigger a runtime
- * warning when something is wrongly called.
- */
-
 static inline bool gpio_is_valid(int number)
 {
        return false;
index 48c32ebf65a77a2c19b35fe900bc28daf3f64e86..a9ace9c32507e31a851bcd719d0a56759b3a4428 100644 (file)
@@ -22,6 +22,11 @@ extern int zap_huge_pmd(struct mmu_gather *tlb,
 extern int mincore_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
                        unsigned long addr, unsigned long end,
                        unsigned char *vec);
+extern int move_huge_pmd(struct vm_area_struct *vma,
+                        struct vm_area_struct *new_vma,
+                        unsigned long old_addr,
+                        unsigned long new_addr, unsigned long old_end,
+                        pmd_t *old_pmd, pmd_t *new_pmd);
 extern int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
                        unsigned long addr, pgprot_t newprot);
 
index a6c652ef516d559dc405cefe5607d08772436e63..38a21c3edd2cb01191949efe8db7f14b76f084c9 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/sched.h>       /* for completion */
 #include <linux/mutex.h>
 #include <linux/of.h>          /* for struct device_node */
+#include <linux/swab.h>                /* for swab16 */
 
 extern struct bus_type i2c_bus_type;
 extern struct device_type i2c_adapter_type;
@@ -88,6 +89,22 @@ extern s32 i2c_smbus_read_word_data(const struct i2c_client *client,
                                    u8 command);
 extern s32 i2c_smbus_write_word_data(const struct i2c_client *client,
                                     u8 command, u16 value);
+
+static inline s32
+i2c_smbus_read_word_swapped(const struct i2c_client *client, u8 command)
+{
+       s32 value = i2c_smbus_read_word_data(client, command);
+
+       return (value < 0) ? value : swab16(value);
+}
+
+static inline s32
+i2c_smbus_write_word_swapped(const struct i2c_client *client,
+                            u8 command, u16 value)
+{
+       return i2c_smbus_write_word_data(client, command, swab16(value));
+}
+
 /* Returns the number of read bytes */
 extern s32 i2c_smbus_read_block_data(const struct i2c_client *client,
                                     u8 command, u8 *values);
index 44da4822bcabc8a2c51163049568f326a6b6eaf3..12d5543b14f25198d5754582ed49a6f0cc0913cb 100644 (file)
@@ -106,7 +106,7 @@ extern struct net_device *__vlan_find_dev_deep(struct net_device *real_dev,
 extern struct net_device *vlan_dev_real_dev(const struct net_device *dev);
 extern u16 vlan_dev_vlan_id(const struct net_device *dev);
 
-extern bool vlan_do_receive(struct sk_buff **skb);
+extern bool vlan_do_receive(struct sk_buff **skb, bool last_handler);
 extern struct sk_buff *vlan_untag(struct sk_buff *skb);
 
 #else
@@ -128,9 +128,9 @@ static inline u16 vlan_dev_vlan_id(const struct net_device *dev)
        return 0;
 }
 
-static inline bool vlan_do_receive(struct sk_buff **skb)
+static inline bool vlan_do_receive(struct sk_buff **skb, bool last_handler)
 {
-       if ((*skb)->vlan_tci & VLAN_VID_MASK)
+       if (((*skb)->vlan_tci & VLAN_VID_MASK) && last_handler)
                (*skb)->pkt_type = PACKET_OTHERHOST;
        return false;
 }
index 6d5eddb18c8210191ea2fd459371099f4a576059..3862e32c4eeb38076d4768c70a958a7b58dd6cf8 100644 (file)
@@ -815,6 +815,7 @@ struct input_keymap_entry {
 #define SW_KEYPAD_SLIDE                0x0a  /* set = keypad slide out */
 #define SW_FRONT_PROXIMITY     0x0b  /* set = front proximity sensor active */
 #define SW_ROTATE_LOCK         0x0c  /* set = rotate locked/disabled */
+#define SW_LINEIN_INSERT       0x0d  /* set = inserted */
 #define SW_MAX                 0x0f
 #define SW_CNT                 (SW_MAX+1)
 
index 9940319d6f9d3ab0d1442a5fa31a7db9be6dafa3..432acc4c054df1134dddb9be501de5c27d84d926 100644 (file)
 #define IOMMU_WRITE    (2)
 #define IOMMU_CACHE    (4) /* DMA cache coherency */
 
+struct iommu_ops;
+struct bus_type;
 struct device;
+struct iommu_domain;
+
+/* iommu fault flags */
+#define IOMMU_FAULT_READ       0x0
+#define IOMMU_FAULT_WRITE      0x1
+
+typedef int (*iommu_fault_handler_t)(struct iommu_domain *,
+                               struct device *, unsigned long, int);
 
 struct iommu_domain {
+       struct iommu_ops *ops;
        void *priv;
+       iommu_fault_handler_t handler;
 };
 
 #define IOMMU_CAP_CACHE_COHERENCY      0x1
 #define IOMMU_CAP_INTR_REMAP           0x2     /* isolates device intrs */
 
+#ifdef CONFIG_IOMMU_API
+
 struct iommu_ops {
        int (*domain_init)(struct iommu_domain *domain);
        void (*domain_destroy)(struct iommu_domain *domain);
@@ -49,11 +63,9 @@ struct iommu_ops {
                              unsigned long cap);
 };
 
-#ifdef CONFIG_IOMMU_API
-
-extern void register_iommu(struct iommu_ops *ops);
-extern bool iommu_found(void);
-extern struct iommu_domain *iommu_domain_alloc(void);
+extern int bus_set_iommu(struct bus_type *bus, struct iommu_ops *ops);
+extern bool iommu_present(struct bus_type *bus);
+extern struct iommu_domain *iommu_domain_alloc(struct bus_type *bus);
 extern void iommu_domain_free(struct iommu_domain *domain);
 extern int iommu_attach_device(struct iommu_domain *domain,
                               struct device *dev);
@@ -67,19 +79,58 @@ extern phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain,
                                      unsigned long iova);
 extern int iommu_domain_has_cap(struct iommu_domain *domain,
                                unsigned long cap);
+extern void iommu_set_fault_handler(struct iommu_domain *domain,
+                                       iommu_fault_handler_t handler);
+
+/**
+ * report_iommu_fault() - report about an IOMMU fault to the IOMMU framework
+ * @domain: the iommu domain where the fault has happened
+ * @dev: the device where the fault has happened
+ * @iova: the faulting address
+ * @flags: mmu fault flags (e.g. IOMMU_FAULT_READ/IOMMU_FAULT_WRITE/...)
+ *
+ * This function should be called by the low-level IOMMU implementations
+ * whenever IOMMU faults happen, to allow high-level users, that are
+ * interested in such events, to know about them.
+ *
+ * This event may be useful for several possible use cases:
+ * - mere logging of the event
+ * - dynamic TLB/PTE loading
+ * - if restarting of the faulting device is required
+ *
+ * Returns 0 on success and an appropriate error code otherwise (if dynamic
+ * PTE/TLB loading will one day be supported, implementations will be able
+ * to tell whether it succeeded or not according to this return value).
+ *
+ * Specifically, -ENOSYS is returned if a fault handler isn't installed
+ * (though fault handlers can also return -ENOSYS, in case they want to
+ * elicit the default behavior of the IOMMU drivers).
+ */
+static inline int report_iommu_fault(struct iommu_domain *domain,
+               struct device *dev, unsigned long iova, int flags)
+{
+       int ret = -ENOSYS;
 
-#else /* CONFIG_IOMMU_API */
+       /*
+        * if upper layers showed interest and installed a fault handler,
+        * invoke it.
+        */
+       if (domain->handler)
+               ret = domain->handler(domain, dev, iova, flags);
 
-static inline void register_iommu(struct iommu_ops *ops)
-{
+       return ret;
 }
 
-static inline bool iommu_found(void)
+#else /* CONFIG_IOMMU_API */
+
+struct iommu_ops {};
+
+static inline bool iommu_present(struct bus_type *bus)
 {
        return false;
 }
 
-static inline struct iommu_domain *iommu_domain_alloc(void)
+static inline struct iommu_domain *iommu_domain_alloc(struct bus_type *bus)
 {
        return NULL;
 }
@@ -123,6 +174,11 @@ static inline int domain_has_cap(struct iommu_domain *domain,
        return 0;
 }
 
+static inline void iommu_set_fault_handler(struct iommu_domain *domain,
+                                       iommu_fault_handler_t handler)
+{
+}
+
 #endif /* CONFIG_IOMMU_API */
 
 #endif /* __LINUX_IOMMU_H */
index 0df513b7a9f8670674a491338852d9a5570f5186..387571959dd9a1219c90dc952c29f8382698f397 100644 (file)
@@ -101,9 +101,8 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
 #endif /*CONFIG_KALLSYMS*/
 
 /* This macro allows us to keep printk typechecking */
-static void __check_printsym_format(const char *fmt, ...)
-__attribute__((format(printf,1,2)));
-static inline void __check_printsym_format(const char *fmt, ...)
+static __printf(1, 2)
+void __check_printsym_format(const char *fmt, ...)
 {
 }
 
index 529d9a0c75a5bb26249f2d766800e58a1b1440da..064725854db8c7eff3c5a38a093aec190a6c6c7f 100644 (file)
@@ -114,12 +114,9 @@ typedef enum {
 } kdb_reason_t;
 
 extern int kdb_trap_printk;
-extern int vkdb_printf(const char *fmt, va_list args)
-           __attribute__ ((format (printf, 1, 0)));
-extern int kdb_printf(const char *, ...)
-           __attribute__ ((format (printf, 1, 2)));
-typedef int (*kdb_printf_t)(const char *, ...)
-            __attribute__ ((format (printf, 1, 2)));
+extern __printf(1, 0) int vkdb_printf(const char *fmt, va_list args);
+extern __printf(1, 2) int kdb_printf(const char *, ...);
+typedef __printf(1, 2) int (*kdb_printf_t)(const char *, ...);
 
 extern void kdb_init(int level);
 
index 8eefcf7e95eb18cabef6066498a7f9ca55cf521f..4c0d3b2fd5fc9182034918835a25482868414fd8 100644 (file)
@@ -287,6 +287,8 @@ static inline int __must_check kstrtos32_from_user(const char __user *s, size_t
        return kstrtoint_from_user(s, count, base, res);
 }
 
+/* Obsolete, do not use.  Use kstrto<foo> instead */
+
 extern unsigned long simple_strtoul(const char *,char **,unsigned int);
 extern long simple_strtol(const char *,char **,unsigned int);
 extern unsigned long long simple_strtoull(const char *,char **,unsigned int);
@@ -296,20 +298,20 @@ extern long long simple_strtoll(const char *,char **,unsigned int);
 #define strict_strtoull        kstrtoull
 #define strict_strtoll kstrtoll
 
-extern int sprintf(char * buf, const char * fmt, ...)
-       __attribute__ ((format (printf, 2, 3)));
-extern int vsprintf(char *buf, const char *, va_list)
-       __attribute__ ((format (printf, 2, 0)));
-extern int snprintf(char * buf, size_t size, const char * fmt, ...)
-       __attribute__ ((format (printf, 3, 4)));
-extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
-       __attribute__ ((format (printf, 3, 0)));
-extern int scnprintf(char * buf, size_t size, const char * fmt, ...)
-       __attribute__ ((format (printf, 3, 4)));
-extern int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
-       __attribute__ ((format (printf, 3, 0)));
-extern char *kasprintf(gfp_t gfp, const char *fmt, ...)
-       __attribute__ ((format (printf, 2, 3)));
+/* lib/printf utilities */
+
+extern __printf(2, 3) int sprintf(char *buf, const char * fmt, ...);
+extern __printf(2, 0) int vsprintf(char *buf, const char *, va_list);
+extern __printf(3, 4)
+int snprintf(char *buf, size_t size, const char *fmt, ...);
+extern __printf(3, 0)
+int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
+extern __printf(3, 4)
+int scnprintf(char *buf, size_t size, const char *fmt, ...);
+extern __printf(3, 0)
+int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
+extern __printf(2, 3)
+char *kasprintf(gfp_t gfp, const char *fmt, ...);
 extern char *kvasprintf(gfp_t gfp, const char *fmt, va_list args);
 
 extern int sscanf(const char *, const char *, ...)
@@ -374,13 +376,18 @@ extern const char hex_asc[];
 #define hex_asc_lo(x)  hex_asc[((x) & 0x0f)]
 #define hex_asc_hi(x)  hex_asc[((x) & 0xf0) >> 4]
 
-static inline char *pack_hex_byte(char *buf, u8 byte)
+static inline char *hex_byte_pack(char *buf, u8 byte)
 {
        *buf++ = hex_asc_hi(byte);
        *buf++ = hex_asc_lo(byte);
        return buf;
 }
 
+static inline char * __deprecated pack_hex_byte(char *buf, u8 byte)
+{
+       return hex_byte_pack(buf, byte);
+}
+
 extern int hex_to_bin(char ch);
 extern int __must_check hex2bin(u8 *dst, const char *src, size_t count);
 
@@ -427,8 +434,8 @@ extern void tracing_start(void);
 extern void tracing_stop(void);
 extern void ftrace_off_permanent(void);
 
-static inline void __attribute__ ((format (printf, 1, 2)))
-____trace_printk_check_format(const char *fmt, ...)
+static inline __printf(1, 2)
+void ____trace_printk_check_format(const char *fmt, ...)
 {
 }
 #define __trace_printk_check_format(fmt, args...)                      \
@@ -467,13 +474,11 @@ do {                                                                      \
                __trace_printk(_THIS_IP_, fmt, ##args);         \
 } while (0)
 
-extern int
-__trace_bprintk(unsigned long ip, const char *fmt, ...)
-       __attribute__ ((format (printf, 2, 3)));
+extern __printf(2, 3)
+int __trace_bprintk(unsigned long ip, const char *fmt, ...);
 
-extern int
-__trace_printk(unsigned long ip, const char *fmt, ...)
-       __attribute__ ((format (printf, 2, 3)));
+extern __printf(2, 3)
+int __trace_printk(unsigned long ip, const char *fmt, ...);
 
 extern void trace_dump_stack(void);
 
@@ -502,8 +507,8 @@ __ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap);
 
 extern void ftrace_dump(enum ftrace_dump_mode oops_dump_mode);
 #else
-static inline int
-trace_printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
+static inline __printf(1, 2)
+int trace_printk(const char *fmt, ...);
 
 static inline void tracing_start(void) { }
 static inline void tracing_stop(void) { }
index c2478a342cd7d9f9b4a754cb73f906745cf4f42c..2fa0901219d4b7fe69158689e08b33db5ac69db1 100644 (file)
 #error KEXEC_ARCH not defined
 #endif
 
+#ifndef KEXEC_CRASH_CONTROL_MEMORY_LIMIT
+#define KEXEC_CRASH_CONTROL_MEMORY_LIMIT KEXEC_CONTROL_MEMORY_LIMIT
+#endif
+
+#ifndef KEXEC_CRASH_MEM_ALIGN
+#define KEXEC_CRASH_MEM_ALIGN PAGE_SIZE
+#endif
+
 #define KEXEC_NOTE_HEAD_BYTES ALIGN(sizeof(struct elf_note), 4)
 #define KEXEC_CORE_NOTE_NAME "CORE"
 #define KEXEC_CORE_NOTE_NAME_BYTES ALIGN(sizeof(KEXEC_CORE_NOTE_NAME), 4)
@@ -129,9 +137,11 @@ extern void crash_kexec(struct pt_regs *);
 int kexec_should_crash(struct task_struct *);
 void crash_save_cpu(struct pt_regs *regs, int cpu);
 void crash_save_vmcoreinfo(void);
+void crash_map_reserved_pages(void);
+void crash_unmap_reserved_pages(void);
 void arch_crash_save_vmcoreinfo(void);
-void vmcoreinfo_append_str(const char *fmt, ...)
-       __attribute__ ((format (printf, 1, 2)));
+__printf(1, 2)
+void vmcoreinfo_append_str(const char *fmt, ...);
 unsigned long paddr_vmcoreinfo_note(void);
 
 #define VMCOREINFO_OSRELEASE(value) \
index 0da38cf7db7bddc8841d14620a9e831866afcfd2..b16f6539073432ca9b206ac0be6531854942363c 100644 (file)
@@ -32,8 +32,8 @@
 extern char modprobe_path[]; /* for sysctl */
 /* modprobe exit status on success, -ve on error.  Return value
  * usually useless though. */
-extern int __request_module(bool wait, const char *name, ...) \
-       __attribute__((format(printf, 2, 3)));
+extern __printf(2, 3)
+int __request_module(bool wait, const char *name, ...);
 #define request_module(mod...) __request_module(true, mod)
 #define request_module_nowait(mod...) __request_module(false, mod)
 #define try_then_request_module(x, mod...) \
index 668729cc0fe9d4774c78797a521a67d97cdd2b69..ad81e1c51487def091ffea196d36c1ee005f7698 100644 (file)
@@ -72,8 +72,8 @@ struct kobject {
        unsigned int uevent_suppress:1;
 };
 
-extern int kobject_set_name(struct kobject *kobj, const char *name, ...)
-                           __attribute__((format(printf, 2, 3)));
+extern __printf(2, 3)
+int kobject_set_name(struct kobject *kobj, const char *name, ...);
 extern int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
                                  va_list vargs);
 
@@ -83,15 +83,13 @@ static inline const char *kobject_name(const struct kobject *kobj)
 }
 
 extern void kobject_init(struct kobject *kobj, struct kobj_type *ktype);
-extern int __must_check kobject_add(struct kobject *kobj,
-                                   struct kobject *parent,
-                                   const char *fmt, ...)
-       __attribute__((format(printf, 3, 4)));
-extern int __must_check kobject_init_and_add(struct kobject *kobj,
-                                            struct kobj_type *ktype,
-                                            struct kobject *parent,
-                                            const char *fmt, ...)
-       __attribute__((format(printf, 4, 5)));
+extern __printf(3, 4) __must_check
+int kobject_add(struct kobject *kobj, struct kobject *parent,
+               const char *fmt, ...);
+extern __printf(4, 5) __must_check
+int kobject_init_and_add(struct kobject *kobj,
+                        struct kobj_type *ktype, struct kobject *parent,
+                        const char *fmt, ...);
 
 extern void kobject_del(struct kobject *kobj);
 
@@ -212,8 +210,8 @@ int kobject_uevent(struct kobject *kobj, enum kobject_action action);
 int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
                        char *envp[]);
 
-int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...)
-       __attribute__((format (printf, 2, 3)));
+__printf(2, 3)
+int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...);
 
 int kobject_action_type(const char *buf, size_t count,
                        enum kobject_action *type);
@@ -226,7 +224,7 @@ static inline int kobject_uevent_env(struct kobject *kobj,
                                      char *envp[])
 { return 0; }
 
-static inline __attribute__((format(printf, 2, 3)))
+static inline __printf(2, 3)
 int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...)
 { return 0; }
 
index 1e923e5e88e81cdc83c8455eefb776eb1b5de588..5cac19b3a26676adad682d1a5cc06d080dbd2885 100644 (file)
@@ -4,11 +4,11 @@
 #include <linux/err.h>
 #include <linux/sched.h>
 
+__printf(4, 5)
 struct task_struct *kthread_create_on_node(int (*threadfn)(void *data),
                                           void *data,
                                           int node,
-                                          const char namefmt[], ...)
-       __attribute__((format(printf, 4, 5)));
+                                          const char namefmt[], ...);
 
 #define kthread_create(threadfn, data, namefmt, arg...) \
        kthread_create_on_node(threadfn, data, -1, namefmt, ##arg)
index aace6b8691a2eee8b921dc46bcd7ff3ea624e45f..f47fcd30273dd2ce904b6ac0cf11fb963c04826c 100644 (file)
@@ -371,6 +371,7 @@ struct kvm_s390_psw {
 #define KVM_S390_INT_VIRTIO            0xffff2603u
 #define KVM_S390_INT_SERVICE           0xffff2401u
 #define KVM_S390_INT_EMERGENCY         0xffff1201u
+#define KVM_S390_INT_EXTERNAL_CALL     0xffff1202u
 
 struct kvm_s390_interrupt {
        __u32 type;
@@ -463,7 +464,7 @@ struct kvm_ppc_pvinfo {
 #define KVM_CAP_VAPIC 6
 #define KVM_CAP_EXT_CPUID 7
 #define KVM_CAP_CLOCKSOURCE 8
-#define KVM_CAP_NR_VCPUS 9       /* returns max vcpus per vm */
+#define KVM_CAP_NR_VCPUS 9       /* returns recommended max vcpus per vm */
 #define KVM_CAP_NR_MEMSLOTS 10   /* returns max memory slots per vm */
 #define KVM_CAP_PIT 11
 #define KVM_CAP_NOP_IO_DELAY 12
@@ -553,6 +554,9 @@ struct kvm_ppc_pvinfo {
 #define KVM_CAP_SPAPR_TCE 63
 #define KVM_CAP_PPC_SMT 64
 #define KVM_CAP_PPC_RMA        65
+#define KVM_CAP_MAX_VCPUS 66       /* returns max vcpus per vm */
+#define KVM_CAP_PPC_HIOR 67
+#define KVM_CAP_PPC_PAPR 68
 #define KVM_CAP_S390_GMAP 71
 
 #ifdef KVM_CAP_IRQ_ROUTING
index eabb21a30c34c134c9342d659a3df16a75ee4a47..d5262319997806bb6f1fdfcfb50b6cef37428b0e 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/msi.h>
 #include <linux/slab.h>
 #include <linux/rcupdate.h>
+#include <linux/ratelimit.h>
 #include <asm/signal.h>
 
 #include <linux/kvm.h>
@@ -48,6 +49,7 @@
 #define KVM_REQ_EVENT             11
 #define KVM_REQ_APF_HALT          12
 #define KVM_REQ_STEAL_UPDATE      13
+#define KVM_REQ_NMI               14
 
 #define KVM_USERSPACE_IRQ_SOURCE_ID    0
 
@@ -55,16 +57,16 @@ struct kvm;
 struct kvm_vcpu;
 extern struct kmem_cache *kvm_vcpu_cache;
 
-/*
- * It would be nice to use something smarter than a linear search, TBD...
- * Thankfully we dont expect many devices to register (famous last words :),
- * so until then it will suffice.  At least its abstracted so we can change
- * in one place.
- */
+struct kvm_io_range {
+       gpa_t addr;
+       int len;
+       struct kvm_io_device *dev;
+};
+
 struct kvm_io_bus {
        int                   dev_count;
-#define NR_IOBUS_DEVS 200
-       struct kvm_io_device *devs[NR_IOBUS_DEVS];
+#define NR_IOBUS_DEVS 300
+       struct kvm_io_range range[NR_IOBUS_DEVS];
 };
 
 enum kvm_bus {
@@ -77,8 +79,8 @@ int kvm_io_bus_write(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
                     int len, const void *val);
 int kvm_io_bus_read(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, int len,
                    void *val);
-int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx,
-                           struct kvm_io_device *dev);
+int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
+                           int len, struct kvm_io_device *dev);
 int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx,
                              struct kvm_io_device *dev);
 
@@ -256,8 +258,9 @@ struct kvm {
        struct kvm_arch arch;
        atomic_t users_count;
 #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
-       struct kvm_coalesced_mmio_dev *coalesced_mmio_dev;
        struct kvm_coalesced_mmio_ring *coalesced_mmio_ring;
+       spinlock_t ring_lock;
+       struct list_head coalesced_zones;
 #endif
 
        struct mutex irq_lock;
@@ -281,11 +284,8 @@ struct kvm {
 
 /* The guest did something we don't support. */
 #define pr_unimpl(vcpu, fmt, ...)                                      \
- do {                                                                  \
-       if (printk_ratelimit())                                         \
-               printk(KERN_ERR "kvm: %i: cpu%i " fmt,                  \
-                      current->tgid, (vcpu)->vcpu_id , ## __VA_ARGS__); \
- } while (0)
+       pr_err_ratelimited("kvm: %i: cpu%i " fmt,                       \
+                          current->tgid, (vcpu)->vcpu_id , ## __VA_ARGS__)
 
 #define kvm_printf(kvm, fmt ...) printk(KERN_DEBUG fmt)
 #define vcpu_printf(vcpu, fmt...) kvm_printf(vcpu->kvm, fmt)
index efd6f9800762a71fc6ae091edbd9f841b84568d2..cafc09a64fe43636cbc1cf9f16366eb5c3e9ef06 100644 (file)
@@ -1052,6 +1052,8 @@ extern int ata_scsi_slave_config(struct scsi_device *sdev);
 extern void ata_scsi_slave_destroy(struct scsi_device *sdev);
 extern int ata_scsi_change_queue_depth(struct scsi_device *sdev,
                                       int queue_depth, int reason);
+extern int __ata_change_queue_depth(struct ata_port *ap, struct scsi_device *sdev,
+                                   int queue_depth, int reason);
 extern struct ata_device *ata_dev_pair(struct ata_device *adev);
 extern int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev);
 extern void ata_scsi_port_error_handler(struct Scsi_Host *host, struct ata_port *ap);
@@ -1254,13 +1256,13 @@ static inline int sata_srst_pmp(struct ata_link *link)
 /*
  * printk helpers
  */
-__attribute__((format (printf, 3, 4)))
+__printf(3, 4)
 int ata_port_printk(const struct ata_port *ap, const char *level,
                    const char *fmt, ...);
-__attribute__((format (printf, 3, 4)))
+__printf(3, 4)
 int ata_link_printk(const struct ata_link *link, const char *level,
                    const char *fmt, ...);
-__attribute__((format (printf, 3, 4)))
+__printf(3, 4)
 int ata_dev_printk(const struct ata_device *dev, const char *level,
                   const char *fmt, ...);
 
@@ -1302,10 +1304,10 @@ void ata_print_version(const struct device *dev, const char *version);
 /*
  * ata_eh_info helpers
  */
-extern void __ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...)
-       __attribute__ ((format (printf, 2, 3)));
-extern void ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...)
-       __attribute__ ((format (printf, 2, 3)));
+extern __printf(2, 3)
+void __ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...);
+extern __printf(2, 3)
+void ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...);
 extern void ata_ehi_clear_desc(struct ata_eh_info *ehi);
 
 static inline void ata_ehi_hotplugged(struct ata_eh_info *ehi)
@@ -1319,8 +1321,8 @@ static inline void ata_ehi_hotplugged(struct ata_eh_info *ehi)
 /*
  * port description helpers
  */
-extern void ata_port_desc(struct ata_port *ap, const char *fmt, ...)
-       __attribute__ ((format (printf, 2, 3)));
+extern __printf(2, 3)
+void ata_port_desc(struct ata_port *ap, const char *fmt, ...);
 #ifdef CONFIG_PCI
 extern void ata_port_pbar_desc(struct ata_port *ap, int bar, ssize_t offset,
                               const char *name);
index d4292c8431e069a52e62431bfb47ecb8b39f84f1..f1664c636af096ef487f545a91ab8127bd625d71 100644 (file)
@@ -113,7 +113,6 @@ struct lis3lv02d_platform_data {
        s8 axis_x;
        s8 axis_y;
        s8 axis_z;
-#define LIS3_USE_REGULATOR_CTRL 0x01
 #define LIS3_USE_BLOCK_READ    0x02
        u16 driver_features;
        int default_rate;
index 7287734e08d1ac0fb662862491fb3719ba8fa9a4..801b44b07aac9ed2738d7efcbce164ea349adef6 100644 (file)
@@ -148,7 +148,7 @@ static inline struct llist_node *llist_next(struct llist_node *node)
  * @new:       new entry to be added
  * @head:      the head for your lock-less list
  *
- * Return whether list is empty before adding.
+ * Returns true if the list was empty prior to adding this entry.
  */
 static inline bool llist_add(struct llist_node *new, struct llist_head *head)
 {
index 7525e38c434d64fa690c454922d99df75d75c983..e6b843e16e81d592131e74a47974182cadb301d9 100644 (file)
@@ -80,6 +80,7 @@ extern phys_addr_t __memblock_alloc_base(phys_addr_t size,
                                           phys_addr_t align,
                                           phys_addr_t max_addr);
 extern phys_addr_t memblock_phys_mem_size(void);
+extern phys_addr_t memblock_start_of_DRAM(void);
 extern phys_addr_t memblock_end_of_DRAM(void);
 extern void memblock_enforce_memory_limit(phys_addr_t memory_limit);
 extern int memblock_is_memory(phys_addr_t addr);
index 343bd7661f2ac648360daf5ca96a1c87ee24567d..ac797fa03ef83503668c0cf56c16e18004bc50c4 100644 (file)
@@ -35,7 +35,8 @@ enum mem_cgroup_page_stat_item {
 extern unsigned long mem_cgroup_isolate_pages(unsigned long nr_to_scan,
                                        struct list_head *dst,
                                        unsigned long *scanned, int order,
-                                       int mode, struct zone *z,
+                                       isolate_mode_t mode,
+                                       struct zone *z,
                                        struct mem_cgroup *mem_cont,
                                        int active, int file);
 
index b6bab1b04e25882460cb6166b5b34dfd04dffb7a..b19176eab44d1fc0202a69485b1e03d36dc6df6e 100644 (file)
@@ -1,6 +1,18 @@
 #ifndef __LINUX_MFD_TPS6586X_H
 #define __LINUX_MFD_TPS6586X_H
 
+#define TPS6586X_SLEW_RATE_INSTANTLY   0x00
+#define TPS6586X_SLEW_RATE_110UV       0x01
+#define TPS6586X_SLEW_RATE_220UV       0x02
+#define TPS6586X_SLEW_RATE_440UV       0x03
+#define TPS6586X_SLEW_RATE_880UV       0x04
+#define TPS6586X_SLEW_RATE_1760UV      0x05
+#define TPS6586X_SLEW_RATE_3520UV      0x06
+#define TPS6586X_SLEW_RATE_7040UV      0x07
+
+#define TPS6586X_SLEW_RATE_SET         0x08
+#define TPS6586X_SLEW_RATE_MASK         0x07
+
 enum {
        TPS6586X_ID_SM_0,
        TPS6586X_ID_SM_1,
@@ -48,6 +60,10 @@ enum {
        TPS6586X_INT_RTC_ALM2,
 };
 
+struct tps6586x_settings {
+       int slew_rate;
+};
+
 struct tps6586x_subdev_info {
        int             id;
        const char      *name;
index 4c806f6d663e0d0f9cbc03d221577f4e7190dea9..2463c2619596fab1667b1ca1c5365c5963bf29ea 100644 (file)
 #define TWL6040_REG_ACCCTL             0x2D
 #define TWL6040_REG_STATUS             0x2E
 
-#define TWL6040_CACHEREGNUM            (TWL6040_REG_STATUS + 1)
-
-#define TWL6040_VIOREGNUM              18
-#define TWL6040_VDDREGNUM              21
-
 /* INTID (0x03) fields */
 
 #define TWL6040_THINT                  0x01
 #define TWL6040_LPLLFIN                        0x08
 #define TWL6040_HPLLSEL                        0x10
 
-/* HSLCTL (0x10) fields */
-
-#define TWL6040_HSDACMODEL             0x02
-#define TWL6040_HSDRVMODEL             0x08
-
-/* HSRCTL (0x11) fields */
+/* HSLCTL/R (0x10/0x11) fields */
 
-#define TWL6040_HSDACMODER             0x02
-#define TWL6040_HSDRVMODER             0x08
+#define TWL6040_HSDACENA               (1 << 0)
+#define TWL6040_HSDACMODE              (1 << 1)
+#define TWL6040_HSDRVMODE              (1 << 3)
 
-/* VIBCTLL (0x18) fields */
+/* VIBCTLL/R (0x18/0x1A) fields */
 
-#define TWL6040_VIBENAL                        0x01
-#define TWL6040_VIBCTRLL               0x04
-#define TWL6040_VIBCTRLLP              0x08
-#define TWL6040_VIBCTRLLN              0x10
+#define TWL6040_VIBENA                 (1 << 0)
+#define TWL6040_VIBSEL                 (1 << 1)
+#define TWL6040_VIBCTRL                        (1 << 2)
+#define TWL6040_VIBCTRL_P              (1 << 3)
+#define TWL6040_VIBCTRL_N              (1 << 4)
 
-/* VIBDATL (0x19) fields */
+/* VIBDATL/R (0x19/0x1B) fields */
 
 #define TWL6040_VIBDAT_MAX             0x64
 
-/* VIBCTLR (0x1A) fields */
-
-#define TWL6040_VIBENAR                        0x01
-#define TWL6040_VIBCTRLR               0x04
-#define TWL6040_VIBCTRLRP              0x08
-#define TWL6040_VIBCTRLRN              0x10
-
 /* GPOCTL (0x1E) fields */
 
 #define TWL6040_GPO1                   0x01
@@ -200,6 +185,7 @@ struct twl6040 {
        int audpwron;
        int power_count;
        int rev;
+       u8 vibra_ctrl_cache[2];
 
        int pll;
        unsigned int sysclk;
@@ -224,5 +210,13 @@ int twl6040_get_pll(struct twl6040 *twl6040);
 unsigned int twl6040_get_sysclk(struct twl6040 *twl6040);
 int twl6040_irq_init(struct twl6040 *twl6040);
 void twl6040_irq_exit(struct twl6040 *twl6040);
+/* Get the combined status of the vibra control register */
+int twl6040_get_vibralr_status(struct twl6040 *twl6040);
+
+static inline int twl6040_get_revid(struct twl6040 *twl6040)
+{
+       return twl6040->rev;
+}
+
 
 #endif  /* End of __TWL6040_CODEC_H__ */
index 45df450d869f577897e5194f85ee315099431f3b..62680914762434e2652a085e35de603d3e1855ac 100644 (file)
@@ -20,6 +20,7 @@
 enum wm8994_type {
        WM8994 = 0,
        WM8958 = 1,
+       WM1811 = 2,
 };
 
 struct regulator_dev;
index f3ee84284670f5e42fc4871cdfc18bc2f7171d87..fae295048a8b00e3dbdbd6d8471a8d7c7f728358 100644 (file)
@@ -72,6 +72,7 @@
 #define WM8994_DC_SERVO_2                       0x55
 #define WM8994_DC_SERVO_4                       0x57
 #define WM8994_DC_SERVO_READBACK                0x58
+#define WM8994_DC_SERVO_4E                     0x59
 #define WM8994_ANALOGUE_HP_1                    0x60
 #define WM8958_MIC_DETECT_1                     0xD0
 #define WM8958_MIC_DETECT_2                     0xD1
 #define WM8994_AIF1_DAC1_FILTERS_2              0x421
 #define WM8994_AIF1_DAC2_FILTERS_1              0x422
 #define WM8994_AIF1_DAC2_FILTERS_2              0x423
+#define WM8958_AIF1_DAC1_NOISE_GATE             0x430
+#define WM8958_AIF1_DAC2_NOISE_GATE             0x431
 #define WM8994_AIF1_DRC1_1                      0x440
 #define WM8994_AIF1_DRC1_2                      0x441
 #define WM8994_AIF1_DRC1_3                      0x442
 #define WM8994_AIF2_ADC_FILTERS                 0x510
 #define WM8994_AIF2_DAC_FILTERS_1               0x520
 #define WM8994_AIF2_DAC_FILTERS_2               0x521
+#define WM8958_AIF2_DAC_NOISE_GATE              0x530
 #define WM8994_AIF2_DRC_1                       0x540
 #define WM8994_AIF2_DRC_2                       0x541
 #define WM8994_AIF2_DRC_3                       0x542
 #define WM8994_LDO2_DISCH_SHIFT                      0  /* LDO2_DISCH */
 #define WM8994_LDO2_DISCH_WIDTH                      1  /* LDO2_DISCH */
 
+/*
+ * R61 (0x3D) - MICBIAS1
+ */
+#define WM8958_MICB1_RATE                       0x0020  /* MICB1_RATE */
+#define WM8958_MICB1_RATE_MASK                  0x0020  /* MICB1_RATE */
+#define WM8958_MICB1_RATE_SHIFT                      5  /* MICB1_RATE */
+#define WM8958_MICB1_RATE_WIDTH                      1  /* MICB1_RATE */
+#define WM8958_MICB1_MODE                       0x0010  /* MICB1_MODE */
+#define WM8958_MICB1_MODE_MASK                  0x0010  /* MICB1_MODE */
+#define WM8958_MICB1_MODE_SHIFT                      4  /* MICB1_MODE */
+#define WM8958_MICB1_MODE_WIDTH                      1  /* MICB1_MODE */
+#define WM8958_MICB1_LVL_MASK                   0x000E  /* MICB1_LVL - [3:1] */
+#define WM8958_MICB1_LVL_SHIFT                       1  /* MICB1_LVL - [3:1] */
+#define WM8958_MICB1_LVL_WIDTH                       3  /* MICB1_LVL - [3:1] */
+#define WM8958_MICB1_DISCH                      0x0001  /* MICB1_DISCH */
+#define WM8958_MICB1_DISCH_MASK                 0x0001  /* MICB1_DISCH */
+#define WM8958_MICB1_DISCH_SHIFT                     0  /* MICB1_DISCH */
+#define WM8958_MICB1_DISCH_WIDTH                     1  /* MICB1_DISCH */
+
+/*
+ * R62 (0x3E) - MICBIAS2
+ */
+#define WM8958_MICB2_RATE                       0x0020  /* MICB2_RATE */
+#define WM8958_MICB2_RATE_MASK                  0x0020  /* MICB2_RATE */
+#define WM8958_MICB2_RATE_SHIFT                      5  /* MICB2_RATE */
+#define WM8958_MICB2_RATE_WIDTH                      1  /* MICB2_RATE */
+#define WM8958_MICB2_MODE                       0x0010  /* MICB2_MODE */
+#define WM8958_MICB2_MODE_MASK                  0x0010  /* MICB2_MODE */
+#define WM8958_MICB2_MODE_SHIFT                      4  /* MICB2_MODE */
+#define WM8958_MICB2_MODE_WIDTH                      1  /* MICB2_MODE */
+#define WM8958_MICB2_LVL_MASK                   0x000E  /* MICB2_LVL - [3:1] */
+#define WM8958_MICB2_LVL_SHIFT                       1  /* MICB2_LVL - [3:1] */
+#define WM8958_MICB2_LVL_WIDTH                       3  /* MICB2_LVL - [3:1] */
+#define WM8958_MICB2_DISCH                      0x0001  /* MICB2_DISCH */
+#define WM8958_MICB2_DISCH_MASK                 0x0001  /* MICB2_DISCH */
+#define WM8958_MICB2_DISCH_SHIFT                     0  /* MICB2_DISCH */
+#define WM8958_MICB2_DISCH_WIDTH                     1  /* MICB2_DISCH */
+
 /*
  * R76 (0x4C) - Charge Pump (1)
  */
 /*
  * R96 (0x60) - Analogue HP (1)
  */
+#define WM1811_HPOUT1_ATTN                      0x0100  /* HPOUT1_ATTN */
+#define WM1811_HPOUT1_ATTN_MASK                 0x0100  /* HPOUT1_ATTN */
+#define WM1811_HPOUT1_ATTN_SHIFT                     8  /* HPOUT1_ATTN */
+#define WM1811_HPOUT1_ATTN_WIDTH                     1  /* HPOUT1_ATTN */
 #define WM8994_HPOUT1L_RMV_SHORT                0x0080  /* HPOUT1L_RMV_SHORT */
 #define WM8994_HPOUT1L_RMV_SHORT_MASK           0x0080  /* HPOUT1L_RMV_SHORT */
 #define WM8994_HPOUT1L_RMV_SHORT_SHIFT               7  /* HPOUT1L_RMV_SHORT */
 #define WM8994_AIF1DAC2_3D_ENA_SHIFT                 8  /* AIF1DAC2_3D_ENA */
 #define WM8994_AIF1DAC2_3D_ENA_WIDTH                 1  /* AIF1DAC2_3D_ENA */
 
+/*
+ * R1072 (0x430) - AIF1 DAC1 Noise Gate
+ */
+#define WM8958_AIF1DAC1_NG_HLD_MASK             0x0060  /* AIF1DAC1_NG_HLD - [6:5] */
+#define WM8958_AIF1DAC1_NG_HLD_SHIFT                 5  /* AIF1DAC1_NG_HLD - [6:5] */
+#define WM8958_AIF1DAC1_NG_HLD_WIDTH                 2  /* AIF1DAC1_NG_HLD - [6:5] */
+#define WM8958_AIF1DAC1_NG_THR_MASK             0x000E  /* AIF1DAC1_NG_THR - [3:1] */
+#define WM8958_AIF1DAC1_NG_THR_SHIFT                 1  /* AIF1DAC1_NG_THR - [3:1] */
+#define WM8958_AIF1DAC1_NG_THR_WIDTH                 3  /* AIF1DAC1_NG_THR - [3:1] */
+#define WM8958_AIF1DAC1_NG_ENA                  0x0001  /* AIF1DAC1_NG_ENA */
+#define WM8958_AIF1DAC1_NG_ENA_MASK             0x0001  /* AIF1DAC1_NG_ENA */
+#define WM8958_AIF1DAC1_NG_ENA_SHIFT                 0  /* AIF1DAC1_NG_ENA */
+#define WM8958_AIF1DAC1_NG_ENA_WIDTH                 1  /* AIF1DAC1_NG_ENA */
+
+/*
+ * R1073 (0x431) - AIF1 DAC2 Noise Gate
+ */
+#define WM8958_AIF1DAC2_NG_HLD_MASK             0x0060  /* AIF1DAC2_NG_HLD - [6:5] */
+#define WM8958_AIF1DAC2_NG_HLD_SHIFT                 5  /* AIF1DAC2_NG_HLD - [6:5] */
+#define WM8958_AIF1DAC2_NG_HLD_WIDTH                 2  /* AIF1DAC2_NG_HLD - [6:5] */
+#define WM8958_AIF1DAC2_NG_THR_MASK             0x000E  /* AIF1DAC2_NG_THR - [3:1] */
+#define WM8958_AIF1DAC2_NG_THR_SHIFT                 1  /* AIF1DAC2_NG_THR - [3:1] */
+#define WM8958_AIF1DAC2_NG_THR_WIDTH                 3  /* AIF1DAC2_NG_THR - [3:1] */
+#define WM8958_AIF1DAC2_NG_ENA                  0x0001  /* AIF1DAC2_NG_ENA */
+#define WM8958_AIF1DAC2_NG_ENA_MASK             0x0001  /* AIF1DAC2_NG_ENA */
+#define WM8958_AIF1DAC2_NG_ENA_SHIFT                 0  /* AIF1DAC2_NG_ENA */
+#define WM8958_AIF1DAC2_NG_ENA_WIDTH                 1  /* AIF1DAC2_NG_ENA */
+
 /*
  * R1088 (0x440) - AIF1 DRC1 (1)
  */
 #define WM8994_AIF2DAC_3D_ENA_SHIFT                  8  /* AIF2DAC_3D_ENA */
 #define WM8994_AIF2DAC_3D_ENA_WIDTH                  1  /* AIF2DAC_3D_ENA */
 
+/*
+ * R1328 (0x530) - AIF2 DAC Noise Gate
+ */
+#define WM8958_AIF2DAC_NG_HLD_MASK              0x0060  /* AIF2DAC_NG_HLD - [6:5] */
+#define WM8958_AIF2DAC_NG_HLD_SHIFT                  5  /* AIF2DAC_NG_HLD - [6:5] */
+#define WM8958_AIF2DAC_NG_HLD_WIDTH                  2  /* AIF2DAC_NG_HLD - [6:5] */
+#define WM8958_AIF2DAC_NG_THR_MASK              0x000E  /* AIF2DAC_NG_THR - [3:1] */
+#define WM8958_AIF2DAC_NG_THR_SHIFT                  1  /* AIF2DAC_NG_THR - [3:1] */
+#define WM8958_AIF2DAC_NG_THR_WIDTH                  3  /* AIF2DAC_NG_THR - [3:1] */
+#define WM8958_AIF2DAC_NG_ENA                   0x0001  /* AIF2DAC_NG_ENA */
+#define WM8958_AIF2DAC_NG_ENA_MASK              0x0001  /* AIF2DAC_NG_ENA */
+#define WM8958_AIF2DAC_NG_ENA_SHIFT                  0  /* AIF2DAC_NG_ENA */
+#define WM8958_AIF2DAC_NG_ENA_WIDTH                  1  /* AIF2DAC_NG_ENA */
+
 /*
  * R1344 (0x540) - AIF2 DRC (1)
  */
index 2366f94a095a60e61bc9ebeef73770387feb5d2e..84b0b1848f17180c3e14d264f017a17c4d041c79 100644 (file)
@@ -61,6 +61,7 @@ enum {
        MLX4_DEV_CAP_FLAG_RC            = 1LL <<  0,
        MLX4_DEV_CAP_FLAG_UC            = 1LL <<  1,
        MLX4_DEV_CAP_FLAG_UD            = 1LL <<  2,
+       MLX4_DEV_CAP_FLAG_XRC           = 1LL <<  3,
        MLX4_DEV_CAP_FLAG_SRQ           = 1LL <<  6,
        MLX4_DEV_CAP_FLAG_IPOIB_CSUM    = 1LL <<  7,
        MLX4_DEV_CAP_FLAG_BAD_PKEY_CNTR = 1LL <<  8,
@@ -83,6 +84,12 @@ enum {
        MLX4_DEV_CAP_FLAG_COUNTERS      = 1LL << 48
 };
 
+#define MLX4_ATTR_EXTENDED_PORT_INFO   cpu_to_be16(0xff90)
+
+enum {
+       MLX_EXT_PORT_CAP_FLAG_EXTENDED_PORT_INFO        = 1 <<  0
+};
+
 enum {
        MLX4_BMME_FLAG_LOCAL_INV        = 1 <<  6,
        MLX4_BMME_FLAG_REMOTE_INV       = 1 <<  7,
@@ -257,6 +264,8 @@ struct mlx4_caps {
        int                     num_qp_per_mgm;
        int                     num_pds;
        int                     reserved_pds;
+       int                     max_xrcds;
+       int                     reserved_xrcds;
        int                     mtt_entry_sz;
        u32                     max_msg_sz;
        u32                     page_size_cap;
@@ -277,6 +286,7 @@ struct mlx4_caps {
        u32                     port_mask;
        enum mlx4_port_type     possible_type[MLX4_MAX_PORTS + 1];
        u32                     max_counters;
+       u8                      ext_port_cap[MLX4_MAX_PORTS + 1];
 };
 
 struct mlx4_buf_list {
@@ -500,6 +510,8 @@ static inline void *mlx4_buf_offset(struct mlx4_buf *buf, int offset)
 
 int mlx4_pd_alloc(struct mlx4_dev *dev, u32 *pdn);
 void mlx4_pd_free(struct mlx4_dev *dev, u32 pdn);
+int mlx4_xrcd_alloc(struct mlx4_dev *dev, u32 *xrcdn);
+void mlx4_xrcd_free(struct mlx4_dev *dev, u32 xrcdn);
 
 int mlx4_uar_alloc(struct mlx4_dev *dev, struct mlx4_uar *uar);
 void mlx4_uar_free(struct mlx4_dev *dev, struct mlx4_uar *uar);
@@ -539,8 +551,8 @@ void mlx4_qp_release_range(struct mlx4_dev *dev, int base_qpn, int cnt);
 int mlx4_qp_alloc(struct mlx4_dev *dev, int qpn, struct mlx4_qp *qp);
 void mlx4_qp_free(struct mlx4_dev *dev, struct mlx4_qp *qp);
 
-int mlx4_srq_alloc(struct mlx4_dev *dev, u32 pdn, struct mlx4_mtt *mtt,
-                  u64 db_rec, struct mlx4_srq *srq);
+int mlx4_srq_alloc(struct mlx4_dev *dev, u32 pdn, u32 cqn, u16 xrcdn,
+                  struct mlx4_mtt *mtt, u64 db_rec, struct mlx4_srq *srq);
 void mlx4_srq_free(struct mlx4_dev *dev, struct mlx4_srq *srq);
 int mlx4_srq_arm(struct mlx4_dev *dev, struct mlx4_srq *srq, int limit_watermark);
 int mlx4_srq_query(struct mlx4_dev *dev, struct mlx4_srq *srq, int *limit_watermark);
index 4001c8249dbb7f74668fe5e5d935cfeb51ad1cc0..48cc4cb9785856b5469e322250672b3e9a1a2449 100644 (file)
@@ -75,6 +75,7 @@ enum {
        MLX4_QP_ST_UC                           = 0x1,
        MLX4_QP_ST_RD                           = 0x2,
        MLX4_QP_ST_UD                           = 0x3,
+       MLX4_QP_ST_XRC                          = 0x6,
        MLX4_QP_ST_MLX                          = 0x7
 };
 
@@ -137,7 +138,7 @@ struct mlx4_qp_context {
        __be32                  ssn;
        __be32                  params2;
        __be32                  rnr_nextrecvpsn;
-       __be32                  srcd;
+       __be32                  xrcd;
        __be32                  cqn_recv;
        __be64                  db_rec_addr;
        __be32                  qkey;
index 7438071b44aa7d3c5f12a60824941de05940eb42..3b3e3b8bb70652fa1d1669a9520b4b5969d6c935 100644 (file)
@@ -1334,7 +1334,8 @@ extern void si_meminfo(struct sysinfo * val);
 extern void si_meminfo_node(struct sysinfo *val, int nid);
 extern int after_bootmem;
 
-extern void warn_alloc_failed(gfp_t gfp_mask, int order, const char *fmt, ...);
+extern __printf(3, 4)
+void warn_alloc_failed(gfp_t gfp_mask, int order, const char *fmt, ...);
 
 extern void setup_per_cpu_pageset(void);
 
index c93d00a6e95d19ca347ab52761de58bf91141c74..3e01a19a91e8025f6f6f7499369071af53aef947 100644 (file)
@@ -304,8 +304,15 @@ struct mm_struct {
        unsigned long hiwater_rss;      /* High-watermark of RSS usage */
        unsigned long hiwater_vm;       /* High-water virtual memory usage */
 
-       unsigned long total_vm, locked_vm, shared_vm, exec_vm;
-       unsigned long stack_vm, reserved_vm, def_flags, nr_ptes;
+       unsigned long total_vm;         /* Total pages mapped */
+       unsigned long locked_vm;        /* Pages that have PG_mlocked set */
+       unsigned long pinned_vm;        /* Refcount permanently increased */
+       unsigned long shared_vm;        /* Shared pages (files) */
+       unsigned long exec_vm;          /* VM_EXEC & ~VM_WRITE */
+       unsigned long stack_vm;         /* VM_GROWSUP/DOWN */
+       unsigned long reserved_vm;      /* VM_RESERVED|VM_IO pages */
+       unsigned long def_flags;
+       unsigned long nr_ptes;          /* Page table pages */
        unsigned long start_code, end_code, start_data, end_data;
        unsigned long start_brk, brk, start_stack;
        unsigned long arg_start, arg_end, env_start, env_end;
@@ -336,9 +343,6 @@ struct mm_struct {
        unsigned int token_priority;
        unsigned int last_interval;
 
-       /* How many tasks sharing this mm are OOM_DISABLE */
-       atomic_t oom_disable_count;
-
        unsigned long flags; /* Must use atomic bitops to access the bits */
 
        struct core_state *core_state; /* coredumping support */
index b460fc2af8a1228d7f84dae2c1a2de56e181c4f5..415f2db414e17cd7c885b84e88b7b806746d3fe2 100644 (file)
@@ -50,8 +50,12 @@ struct mmc_ext_csd {
        u8                      rel_sectors;
        u8                      rel_param;
        u8                      part_config;
+       u8                      cache_ctrl;
+       u8                      rst_n_function;
        unsigned int            part_time;              /* Units: ms */
        unsigned int            sa_timeout;             /* Units: 100ns */
+       unsigned int            generic_cmd6_time;      /* Units: 10ms */
+       unsigned int            power_off_longtime;     /* Units: ms */
        unsigned int            hs_max_dtr;
        unsigned int            sectors;
        unsigned int            card_type;
@@ -63,11 +67,15 @@ struct mmc_ext_csd {
        bool                    enhanced_area_en;       /* enable bit */
        unsigned long long      enhanced_area_offset;   /* Units: Byte */
        unsigned int            enhanced_area_size;     /* Units: KB */
-       unsigned int            boot_size;              /* in bytes */
+       unsigned int            cache_size;             /* Units: KB */
+       bool                    hpi_en;                 /* HPI enablebit */
+       bool                    hpi;                    /* HPI support bit */
+       unsigned int            hpi_cmd;                /* cmd used as HPI */
        u8                      raw_partition_support;  /* 160 */
        u8                      raw_erased_mem_count;   /* 181 */
        u8                      raw_ext_csd_structure;  /* 194 */
        u8                      raw_card_type;          /* 196 */
+       u8                      out_of_int_time;        /* 198 */
        u8                      raw_s_a_timeout;                /* 217 */
        u8                      raw_hc_erase_gap_size;  /* 221 */
        u8                      raw_erase_timeout_mult; /* 223 */
@@ -77,6 +85,9 @@ struct mmc_ext_csd {
        u8                      raw_sec_feature_support;/* 231 */
        u8                      raw_trim_mult;          /* 232 */
        u8                      raw_sectors[4];         /* 212 - 4 bytes */
+
+       unsigned int            feature_support;
+#define MMC_DISCARD_FEATURE    BIT(0)                  /* CMD38 feature */
 };
 
 struct sd_scr {
@@ -157,6 +168,24 @@ struct sdio_func_tuple;
 
 #define SDIO_MAX_FUNCS         7
 
+/* The number of MMC physical partitions.  These consist of:
+ * boot partitions (2), general purpose partitions (4) in MMC v4.4.
+ */
+#define MMC_NUM_BOOT_PARTITION 2
+#define MMC_NUM_GP_PARTITION   4
+#define MMC_NUM_PHY_PARTITION  6
+#define MAX_MMC_PART_NAME_LEN  20
+
+/*
+ * MMC Physical partitions
+ */
+struct mmc_part {
+       unsigned int    size;   /* partition size (in bytes) */
+       unsigned int    part_cfg;       /* partition type */
+       char    name[MAX_MMC_PART_NAME_LEN];
+       bool    force_ro;       /* to make boot parts RO by default */
+};
+
 /*
  * MMC device
  */
@@ -188,6 +217,13 @@ struct mmc_card {
 #define MMC_QUIRK_DISABLE_CD   (1<<5)          /* disconnect CD/DAT[3] resistor */
 #define MMC_QUIRK_INAND_CMD38  (1<<6)          /* iNAND devices have broken CMD38 */
 #define MMC_QUIRK_BLK_NO_CMD23 (1<<7)          /* Avoid CMD23 for regular multiblock */
+#define MMC_QUIRK_BROKEN_BYTE_MODE_512 (1<<8)  /* Avoid sending 512 bytes in */
+                                               /* byte mode */
+       unsigned int    poweroff_notify_state;  /* eMMC4.5 notify feature */
+#define MMC_NO_POWER_NOTIFICATION      0
+#define MMC_POWERED_ON                 1
+#define MMC_POWEROFF_SHORT             2
+#define MMC_POWEROFF_LONG              3
 
        unsigned int            erase_size;     /* erase size in sectors */
        unsigned int            erase_shift;    /* if erase unit is power 2 */
@@ -216,8 +252,23 @@ struct mmc_card {
        unsigned int            sd_bus_speed;   /* Bus Speed Mode set for the card */
 
        struct dentry           *debugfs_root;
+       struct mmc_part part[MMC_NUM_PHY_PARTITION]; /* physical partitions */
+       unsigned int    nr_parts;
 };
 
+/*
+ * This function fill contents in mmc_part.
+ */
+static inline void mmc_part_add(struct mmc_card *card, unsigned int size,
+                       unsigned int part_cfg, char *name, int idx, bool ro)
+{
+       card->part[card->nr_parts].size = size;
+       card->part[card->nr_parts].part_cfg = part_cfg;
+       sprintf(card->part[card->nr_parts].name, name, idx);
+       card->part[card->nr_parts].force_ro = ro;
+       card->nr_parts++;
+}
+
 /*
  *  The world is not perfect and supplies us with broken mmc/sdio devices.
  *  For at least some of these bugs we need a work-around.
@@ -377,6 +428,11 @@ static inline int mmc_card_nonstd_func_interface(const struct mmc_card *c)
        return c->quirks & MMC_QUIRK_NONSTD_FUNC_IF;
 }
 
+static inline int mmc_card_broken_byte_mode_512(const struct mmc_card *c)
+{
+       return c->quirks & MMC_QUIRK_BROKEN_BYTE_MODE_512;
+}
+
 #define mmc_card_name(c)       ((c)->cid.prod_name)
 #define mmc_card_id(c)         (dev_name(&(c)->dev))
 
index b8b1b7a311f1d9b42dfc7d905373d804a5c35d06..174a844a5dda67fae26d87514432a0080bf3d7b3 100644 (file)
@@ -136,6 +136,7 @@ struct mmc_async_req;
 
 extern struct mmc_async_req *mmc_start_req(struct mmc_host *,
                                           struct mmc_async_req *, int *);
+extern int mmc_interrupt_hpi(struct mmc_card *);
 extern void mmc_wait_for_req(struct mmc_host *, struct mmc_request *);
 extern int mmc_wait_for_cmd(struct mmc_host *, struct mmc_command *, int);
 extern int mmc_app_cmd(struct mmc_host *, struct mmc_card *);
@@ -146,6 +147,7 @@ extern int mmc_switch(struct mmc_card *, u8, u8, u8, unsigned int);
 #define MMC_ERASE_ARG          0x00000000
 #define MMC_SECURE_ERASE_ARG   0x80000000
 #define MMC_TRIM_ARG           0x00000001
+#define MMC_DISCARD_ARG                0x00000003
 #define MMC_SECURE_TRIM1_ARG   0x80000001
 #define MMC_SECURE_TRIM2_ARG   0x80008000
 
@@ -156,12 +158,17 @@ extern int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
                     unsigned int arg);
 extern int mmc_can_erase(struct mmc_card *card);
 extern int mmc_can_trim(struct mmc_card *card);
+extern int mmc_can_discard(struct mmc_card *card);
+extern int mmc_can_sanitize(struct mmc_card *card);
 extern int mmc_can_secure_erase_trim(struct mmc_card *card);
 extern int mmc_erase_group_aligned(struct mmc_card *card, unsigned int from,
                                   unsigned int nr);
 extern unsigned int mmc_calc_max_discard(struct mmc_card *card);
 
 extern int mmc_set_blocklen(struct mmc_card *card, unsigned int blocklen);
+extern int mmc_hw_reset(struct mmc_host *host);
+extern int mmc_hw_reset_check(struct mmc_host *host);
+extern int mmc_can_reset(struct mmc_card *card);
 
 extern void mmc_set_data_timeout(struct mmc_data *, const struct mmc_card *);
 extern unsigned int mmc_align_data_size(struct mmc_card *, unsigned int);
@@ -171,6 +178,8 @@ extern void mmc_release_host(struct mmc_host *host);
 extern void mmc_do_release_host(struct mmc_host *host);
 extern int mmc_try_claim_host(struct mmc_host *host);
 
+extern int mmc_flush_cache(struct mmc_card *);
+
 /**
  *     mmc_claim_host - exclusively claim a host
  *     @host: mmc host to claim
index 6b46819705d186e0d6604ed1a23a821a5bd7be2d..6dc9b80568a0d7766d6b8e447ca19b9dbd1d802c 100644 (file)
@@ -72,6 +72,8 @@ struct mmc_data;
  *     rate and timeout calculations.
  * @current_speed: Configured rate of the controller.
  * @num_slots: Number of slots available.
+ * @verid: Denote Version ID.
+ * @data_offset: Set the offset of DATA register according to VERID.
  * @pdev: Platform device associated with the MMC controller.
  * @pdata: Platform data associated with the MMC controller.
  * @slot: Slots sharing this MMC controller.
@@ -147,6 +149,8 @@ struct dw_mci {
        u32                     current_speed;
        u32                     num_slots;
        u32                     fifoth_val;
+       u16                     verid;
+       u16                     data_offset;
        struct platform_device  *pdev;
        struct dw_mci_board     *pdata;
        struct dw_mci_slot      *slot[MAX_MCI_SLOTS];
index 1d09562ccf7394b2ae0a2cdf38cf52e17ccd53ec..a3ac9c48e5de60dc71fe71f3eb5d067e315ac4fb 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <linux/leds.h>
 #include <linux/sched.h>
+#include <linux/fault-inject.h>
 
 #include <linux/mmc/core.h>
 #include <linux/mmc/pm.h>
@@ -108,6 +109,9 @@ struct mmc_host_ops {
         * It is optional for the host to implement pre_req and post_req in
         * order to support double buffering of requests (prepare one
         * request while another request is active).
+        * pre_req() must always be followed by a post_req().
+        * To undo a call made to pre_req(), call post_req() with
+        * a nonzero err condition.
         */
        void    (*post_req)(struct mmc_host *host, struct mmc_request *req,
                            int err);
@@ -147,6 +151,7 @@ struct mmc_host_ops {
        int     (*execute_tuning)(struct mmc_host *host);
        void    (*enable_preset_value)(struct mmc_host *host, bool enable);
        int     (*select_drive_strength)(unsigned int max_dtr, int host_drv, int card_drv);
+       void    (*hw_reset)(struct mmc_host *host);
 };
 
 struct mmc_card;
@@ -229,8 +234,20 @@ struct mmc_host {
 #define MMC_CAP_MAX_CURRENT_600        (1 << 28)       /* Host max current limit is 600mA */
 #define MMC_CAP_MAX_CURRENT_800        (1 << 29)       /* Host max current limit is 800mA */
 #define MMC_CAP_CMD23          (1 << 30)       /* CMD23 supported. */
+#define MMC_CAP_HW_RESET       (1 << 31)       /* Hardware reset */
+
+       unsigned int            caps2;          /* More host capabilities */
+
+#define MMC_CAP2_BOOTPART_NOACC        (1 << 0)        /* Boot partition no access */
+#define MMC_CAP2_CACHE_CTRL    (1 << 1)        /* Allow cache control */
+#define MMC_CAP2_POWEROFF_NOTIFY (1 << 2)      /* Notify poweroff supported */
+#define MMC_CAP2_NO_MULTI_READ (1 << 3)        /* Multiblock reads don't work */
 
        mmc_pm_flag_t           pm_caps;        /* supported pm features */
+       unsigned int        power_notify_type;
+#define MMC_HOST_PW_NOTIFY_NONE                0
+#define MMC_HOST_PW_NOTIFY_SHORT       1
+#define MMC_HOST_PW_NOTIFY_LONG                2
 
 #ifdef CONFIG_MMC_CLKGATE
        int                     clk_requests;   /* internal reference counter */
@@ -302,6 +319,10 @@ struct mmc_host {
 
        struct mmc_async_req    *areq;          /* active async req */
 
+#ifdef CONFIG_FAIL_MMC_REQUEST
+       struct fault_attr       fail_mmc_request;
+#endif
+
        unsigned long           private[0] ____cacheline_aligned;
 };
 
@@ -330,6 +351,8 @@ extern int mmc_power_restore_host(struct mmc_host *host);
 extern void mmc_detect_change(struct mmc_host *, unsigned long delay);
 extern void mmc_request_done(struct mmc_host *, struct mmc_request *);
 
+extern int mmc_cache_ctrl(struct mmc_host *, u8);
+
 static inline void mmc_signal_sdio_irq(struct mmc_host *host)
 {
        host->ops->enable_sdio_irq(host, 0);
@@ -394,4 +417,10 @@ static inline int mmc_host_cmd23(struct mmc_host *host)
 {
        return host->caps & MMC_CAP_CMD23;
 }
+
+static inline int mmc_boot_partition_access(struct mmc_host *host)
+{
+       return !(host->caps2 & MMC_CAP2_BOOTPART_NOACC);
+}
+
 #endif /* LINUX_MMC_HOST_H */
index 5a794cb503ea77eadf3ed7dc3330872fd5fe9973..0e7135697d1110923d6553f35f51171806be2251 100644 (file)
@@ -270,18 +270,31 @@ struct _mmc_csd {
  * EXT_CSD fields
  */
 
+#define EXT_CSD_FLUSH_CACHE            32      /* W */
+#define EXT_CSD_CACHE_CTRL             33      /* R/W */
+#define EXT_CSD_POWER_OFF_NOTIFICATION 34      /* R/W */
+#define EXT_CSD_GP_SIZE_MULT           143     /* R/W */
 #define EXT_CSD_PARTITION_ATTRIBUTE    156     /* R/W */
 #define EXT_CSD_PARTITION_SUPPORT      160     /* RO */
+#define EXT_CSD_HPI_MGMT               161     /* R/W */
+#define EXT_CSD_RST_N_FUNCTION         162     /* R/W */
+#define EXT_CSD_SANITIZE_START         165     /* W */
 #define EXT_CSD_WR_REL_PARAM           166     /* RO */
 #define EXT_CSD_ERASE_GROUP_DEF                175     /* R/W */
 #define EXT_CSD_PART_CONFIG            179     /* R/W */
 #define EXT_CSD_ERASED_MEM_CONT                181     /* RO */
 #define EXT_CSD_BUS_WIDTH              183     /* R/W */
 #define EXT_CSD_HS_TIMING              185     /* R/W */
+#define EXT_CSD_POWER_CLASS            187     /* R/W */
 #define EXT_CSD_REV                    192     /* RO */
 #define EXT_CSD_STRUCTURE              194     /* RO */
 #define EXT_CSD_CARD_TYPE              196     /* RO */
+#define EXT_CSD_OUT_OF_INTERRUPT_TIME  198     /* RO */
 #define EXT_CSD_PART_SWITCH_TIME        199     /* RO */
+#define EXT_CSD_PWR_CL_52_195          200     /* RO */
+#define EXT_CSD_PWR_CL_26_195          201     /* RO */
+#define EXT_CSD_PWR_CL_52_360          202     /* RO */
+#define EXT_CSD_PWR_CL_26_360          203     /* RO */
 #define EXT_CSD_SEC_CNT                        212     /* RO, 4 bytes */
 #define EXT_CSD_S_A_TIMEOUT            217     /* RO */
 #define EXT_CSD_REL_WR_SEC_C           222     /* RO */
@@ -293,6 +306,14 @@ struct _mmc_csd {
 #define EXT_CSD_SEC_ERASE_MULT         230     /* RO */
 #define EXT_CSD_SEC_FEATURE_SUPPORT    231     /* RO */
 #define EXT_CSD_TRIM_MULT              232     /* RO */
+#define EXT_CSD_PWR_CL_200_195         236     /* RO */
+#define EXT_CSD_PWR_CL_200_360         237     /* RO */
+#define EXT_CSD_PWR_CL_DDR_52_195      238     /* RO */
+#define EXT_CSD_PWR_CL_DDR_52_360      239     /* RO */
+#define EXT_CSD_POWER_OFF_LONG_TIME    247     /* RO */
+#define EXT_CSD_GENERIC_CMD6_TIME      248     /* RO */
+#define EXT_CSD_CACHE_SIZE             249     /* RO, 4 bytes */
+#define EXT_CSD_HPI_FEATURES           503     /* RO */
 
 /*
  * EXT_CSD field definitions
@@ -302,7 +323,9 @@ struct _mmc_csd {
 
 #define EXT_CSD_PART_CONFIG_ACC_MASK   (0x7)
 #define EXT_CSD_PART_CONFIG_ACC_BOOT0  (0x1)
-#define EXT_CSD_PART_CONFIG_ACC_BOOT1  (0x2)
+#define EXT_CSD_PART_CONFIG_ACC_GP0    (0x4)
+
+#define EXT_CSD_PART_SUPPORT_PART_EN   (0x1)
 
 #define EXT_CSD_CMD_SET_NORMAL         (1<<0)
 #define EXT_CSD_CMD_SET_SECURE         (1<<1)
@@ -327,7 +350,20 @@ struct _mmc_csd {
 #define EXT_CSD_SEC_ER_EN      BIT(0)
 #define EXT_CSD_SEC_BD_BLK_EN  BIT(2)
 #define EXT_CSD_SEC_GB_CL_EN   BIT(4)
+#define EXT_CSD_SEC_SANITIZE   BIT(6)  /* v4.5 only */
+
+#define EXT_CSD_RST_N_EN_MASK  0x3
+#define EXT_CSD_RST_N_ENABLED  1       /* RST_n is enabled on card */
+
+#define EXT_CSD_NO_POWER_NOTIFICATION  0
+#define EXT_CSD_POWER_ON               1
+#define EXT_CSD_POWER_OFF_SHORT                2
+#define EXT_CSD_POWER_OFF_LONG         3
 
+#define EXT_CSD_PWR_CL_8BIT_MASK       0xF0    /* 8 bit PWR CLS */
+#define EXT_CSD_PWR_CL_4BIT_MASK       0x0F    /* 8 bit PWR CLS */
+#define EXT_CSD_PWR_CL_8BIT_SHIFT      4
+#define EXT_CSD_PWR_CL_4BIT_SHIFT      0
 /*
  * MMC_SWITCH access modes
  */
index 5666f3abfab78bd44fa92a3f73f78dcc9119b31b..e4b69353678d0c69a97af270e02911e756f44863 100644 (file)
@@ -88,6 +88,10 @@ struct sdhci_host {
 /* The read-only detection via SDHCI_PRESENT_STATE register is unstable */
 #define SDHCI_QUIRK_UNSTABLE_RO_DETECT                 (1<<31)
 
+       unsigned int quirks2;   /* More deviations from spec. */
+
+#define SDHCI_QUIRK2_OWN_CARD_DETECTION                        (1<<0)
+
        int irq;                /* Device IRQ */
        void __iomem *ioaddr;   /* Mapped address */
 
@@ -115,6 +119,8 @@ struct sdhci_host {
 #define SDHCI_NEEDS_RETUNING   (1<<5)  /* Host needs retuning */
 #define SDHCI_AUTO_CMD12       (1<<6)  /* Auto CMD12 support */
 #define SDHCI_AUTO_CMD23       (1<<7)  /* Auto CMD23 support */
+#define SDHCI_PV_ENABLED       (1<<8)  /* Preset value enabled */
+#define SDHCI_SDIO_IRQ_ENABLED (1<<9)  /* SDIO irq enabled */
 
        unsigned int version;   /* SDHCI spec. version */
 
@@ -125,6 +131,8 @@ struct sdhci_host {
        unsigned int clock;     /* Current clock (MHz) */
        u8 pwr;                 /* Current voltage */
 
+       bool runtime_suspended; /* Host is runtime suspended */
+
        struct mmc_request *mrq;        /* Current request */
        struct mmc_command *cmd;        /* Current command */
        struct mmc_data *data;  /* Current data request */
index 2a2e9905a2473d4d5db8bad16e5cd62e05e0b10b..e0b1123497b9b5adba34126bc8f187e6c7d98a91 100644 (file)
 #define  SDIO_CCCR_REV_1_00    0       /* CCCR/FBR Version 1.00 */
 #define  SDIO_CCCR_REV_1_10    1       /* CCCR/FBR Version 1.10 */
 #define  SDIO_CCCR_REV_1_20    2       /* CCCR/FBR Version 1.20 */
+#define  SDIO_CCCR_REV_3_00    3       /* CCCR/FBR Version 3.00 */
 
 #define  SDIO_SDIO_REV_1_00    0       /* SDIO Spec Version 1.00 */
 #define  SDIO_SDIO_REV_1_10    1       /* SDIO Spec Version 1.10 */
 #define  SDIO_SDIO_REV_1_20    2       /* SDIO Spec Version 1.20 */
 #define  SDIO_SDIO_REV_2_00    3       /* SDIO Spec Version 2.00 */
+#define  SDIO_SDIO_REV_3_00    4       /* SDIO Spec Version 3.00 */
 
 #define SDIO_CCCR_SD           0x01
 
index 0222cd8ebe76cd6e089d342e7c8d7885c6907bb0..04ff452bf5c3e5eebd7251be8c8fd6c4d5861d0c 100644 (file)
@@ -41,7 +41,9 @@ struct sh_mmcif_plat_data {
        void (*set_pwr)(struct platform_device *pdev, int state);
        void (*down_pwr)(struct platform_device *pdev);
        int (*get_cd)(struct platform_device *pdef);
-       struct sh_mmcif_dma     *dma;
+       struct sh_mmcif_dma     *dma;           /* Deprecated. Instead */
+       unsigned int            slave_id_tx;    /* use embedded slave_id_[tr]x */
+       unsigned int            slave_id_rx;
        u8                      sup_pclk;       /* 1 :SH7757, 0: SH7724/SH7372 */
        unsigned long           caps;
        u32                     ocr;
index bd50b365167f25586848d18b23d04c3a6f2917e8..71b805451bd82d9175ae2dff99a467edb62a83b2 100644 (file)
@@ -6,6 +6,10 @@
 struct platform_device;
 struct tmio_mmc_data;
 
+#define SH_MOBILE_SDHI_IRQ_CARD_DETECT "card_detect"
+#define SH_MOBILE_SDHI_IRQ_SDCARD      "sdcard"
+#define SH_MOBILE_SDHI_IRQ_SDIO                "sdio"
+
 struct sh_mobile_sdhi_info {
        int dma_slave_tx;
        int dma_slave_rx;
index 97491f78b08cd72138ed25750145275ca1dabb90..c5d52780d6a02fe27ec67cb892b447c43a6beefb 100644 (file)
@@ -49,8 +49,7 @@ extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
 extern void mmiotrace_iounmap(volatile void __iomem *addr);
 
 /* For anyone to insert markers. Remember trailing newline. */
-extern int mmiotrace_printk(const char *fmt, ...)
-                               __attribute__ ((format (printf, 1, 2)));
+extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
 #else /* !CONFIG_MMIOTRACE: */
 static inline int is_kmmio_active(void)
 {
@@ -71,10 +70,7 @@ static inline void mmiotrace_iounmap(volatile void __iomem *addr)
 {
 }
 
-static inline int mmiotrace_printk(const char *fmt, ...)
-                               __attribute__ ((format (printf, 1, 0)));
-
-static inline int mmiotrace_printk(const char *fmt, ...)
+static inline __printf(1, 2) int mmiotrace_printk(const char *fmt, ...)
 {
        return 0;
 }
index be1ac8d7789be37b21dd5fdf72832aea621926bd..188cb2ffe8db2685a5b1b50e584026a1ffcfd9f6 100644 (file)
@@ -100,6 +100,7 @@ enum zone_stat_item {
        NR_UNSTABLE_NFS,        /* NFS unstable pages */
        NR_BOUNCE,
        NR_VMSCAN_WRITE,
+       NR_VMSCAN_IMMEDIATE,    /* Prioritise for reclaim when writeback ends */
        NR_WRITEBACK_TEMP,      /* Writeback using temporary buffers */
        NR_ISOLATED_ANON,       /* Temporary isolated pages from anon lru */
        NR_ISOLATED_FILE,       /* Temporary isolated pages from file lru */
@@ -164,6 +165,18 @@ static inline int is_unevictable_lru(enum lru_list l)
 #define LRU_ALL_EVICTABLE (LRU_ALL_FILE | LRU_ALL_ANON)
 #define LRU_ALL             ((1 << NR_LRU_LISTS) - 1)
 
+/* Isolate inactive pages */
+#define ISOLATE_INACTIVE       ((__force isolate_mode_t)0x1)
+/* Isolate active pages */
+#define ISOLATE_ACTIVE         ((__force isolate_mode_t)0x2)
+/* Isolate clean file */
+#define ISOLATE_CLEAN          ((__force isolate_mode_t)0x4)
+/* Isolate unmapped file */
+#define ISOLATE_UNMAPPED       ((__force isolate_mode_t)0x8)
+
+/* LRU Isolation modes. */
+typedef unsigned __bitwise__ isolate_mode_t;
+
 enum zone_watermarks {
        WMARK_MIN,
        WMARK_LOW,
index df1c836e694841762a8eb2088e2cf20d2cf117c1..cbeb5867cff79d7d70952cc6285063c3feb92e7c 100644 (file)
@@ -2622,23 +2622,23 @@ static inline const char *netdev_name(const struct net_device *dev)
 extern int __netdev_printk(const char *level, const struct net_device *dev,
                        struct va_format *vaf);
 
-extern int netdev_printk(const char *level, const struct net_device *dev,
-                        const char *format, ...)
-       __attribute__ ((format (printf, 3, 4)));
-extern int netdev_emerg(const struct net_device *dev, const char *format, ...)
-       __attribute__ ((format (printf, 2, 3)));
-extern int netdev_alert(const struct net_device *dev, const char *format, ...)
-       __attribute__ ((format (printf, 2, 3)));
-extern int netdev_crit(const struct net_device *dev, const char *format, ...)
-       __attribute__ ((format (printf, 2, 3)));
-extern int netdev_err(const struct net_device *dev, const char *format, ...)
-       __attribute__ ((format (printf, 2, 3)));
-extern int netdev_warn(const struct net_device *dev, const char *format, ...)
-       __attribute__ ((format (printf, 2, 3)));
-extern int netdev_notice(const struct net_device *dev, const char *format, ...)
-       __attribute__ ((format (printf, 2, 3)));
-extern int netdev_info(const struct net_device *dev, const char *format, ...)
-       __attribute__ ((format (printf, 2, 3)));
+extern __printf(3, 4)
+int netdev_printk(const char *level, const struct net_device *dev,
+                 const char *format, ...);
+extern __printf(2, 3)
+int netdev_emerg(const struct net_device *dev, const char *format, ...);
+extern __printf(2, 3)
+int netdev_alert(const struct net_device *dev, const char *format, ...);
+extern __printf(2, 3)
+int netdev_crit(const struct net_device *dev, const char *format, ...);
+extern __printf(2, 3)
+int netdev_err(const struct net_device *dev, const char *format, ...);
+extern __printf(2, 3)
+int netdev_warn(const struct net_device *dev, const char *format, ...);
+extern __printf(2, 3)
+int netdev_notice(const struct net_device *dev, const char *format, ...);
+extern __printf(2, 3)
+int netdev_info(const struct net_device *dev, const char *format, ...);
 
 #define MODULE_ALIAS_NETDEV(device) \
        MODULE_ALIAS("netdev-" device)
index 8180cd9d73d5b13d61d65c14326e9918d5f4f890..8374d29673625db129e01ba4a13b29761d769688 100644 (file)
@@ -25,6 +25,7 @@
 #define NETLINK_SCSITRANSPORT  18      /* SCSI Transports */
 #define NETLINK_ECRYPTFS       19
 #define NETLINK_RDMA           20
+#define NETLINK_CRYPTO         21      /* Crypto layer */
 
 #define MAX_LINKS 32           
 
index 92c40a14224350ec2a24d9f158d0340e5bd17cfb..5dbe263462a94611518ebb81482d164ce5469d5d 100644 (file)
@@ -17,6 +17,7 @@
  */
 #include <linux/types.h>
 #include <linux/bitops.h>
+#include <linux/errno.h>
 #include <linux/kref.h>
 #include <linux/mod_devicetable.h>
 #include <linux/spinlock.h>
index b6111f8cd49a0976025680a6a295e40038a47774..c73a34c3434d75150cc4f6440e3ba3a5a8ffc47f 100644 (file)
  * V4L2_EVENT_OMAP3ISP_AEWB: AEWB statistics data ready
  * V4L2_EVENT_OMAP3ISP_AF: AF statistics data ready
  * V4L2_EVENT_OMAP3ISP_HIST: Histogram statistics data ready
- * V4L2_EVENT_OMAP3ISP_HS_VS: Horizontal/vertical synchronization detected
  */
 
 #define V4L2_EVENT_OMAP3ISP_CLASS      (V4L2_EVENT_PRIVATE_START | 0x100)
 #define V4L2_EVENT_OMAP3ISP_AEWB       (V4L2_EVENT_OMAP3ISP_CLASS | 0x1)
 #define V4L2_EVENT_OMAP3ISP_AF         (V4L2_EVENT_OMAP3ISP_CLASS | 0x2)
 #define V4L2_EVENT_OMAP3ISP_HIST       (V4L2_EVENT_OMAP3ISP_CLASS | 0x3)
-#define V4L2_EVENT_OMAP3ISP_HS_VS      (V4L2_EVENT_OMAP3ISP_CLASS | 0x4)
 
 struct omap3isp_stat_event_status {
        __u32 frame_number;
index 13b7b02e599aed40fcf09c2eea96dc0f03dc3d32..6f9d04a8533606afa788c351909c5dba74e54438 100644 (file)
@@ -40,6 +40,7 @@ enum oom_constraint {
        CONSTRAINT_MEMCG,
 };
 
+extern void compare_swap_oom_score_adj(int old_val, int new_val);
 extern int test_set_oom_score_adj(int new_val);
 
 extern unsigned int oom_badness(struct task_struct *p, struct mem_cgroup *mem,
index 655824fa4c76aab29aaf00b21c6ed522cbaaf288..e3d0b3890249163881eec330894cdd8bb945295a 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef LINUX_PCI_ATS_H
 #define LINUX_PCI_ATS_H
 
+#include <linux/pci.h>
+
 /* Address Translation Service */
 struct pci_ats {
        int pos;        /* capability position */
@@ -15,6 +17,7 @@ struct pci_ats {
 extern int pci_enable_ats(struct pci_dev *dev, int ps);
 extern void pci_disable_ats(struct pci_dev *dev);
 extern int pci_ats_queue_depth(struct pci_dev *dev);
+
 /**
  * pci_ats_enabled - query the ATS status
  * @dev: the PCI device
@@ -49,4 +52,76 @@ static inline int pci_ats_enabled(struct pci_dev *dev)
 
 #endif /* CONFIG_PCI_IOV */
 
+#ifdef CONFIG_PCI_PRI
+
+extern int  pci_enable_pri(struct pci_dev *pdev, u32 reqs);
+extern void pci_disable_pri(struct pci_dev *pdev);
+extern bool pci_pri_enabled(struct pci_dev *pdev);
+extern int  pci_reset_pri(struct pci_dev *pdev);
+extern bool pci_pri_stopped(struct pci_dev *pdev);
+extern int  pci_pri_status(struct pci_dev *pdev);
+
+#else /* CONFIG_PCI_PRI */
+
+static inline int pci_enable_pri(struct pci_dev *pdev, u32 reqs)
+{
+       return -ENODEV;
+}
+
+static inline void pci_disable_pri(struct pci_dev *pdev)
+{
+}
+
+static inline bool pci_pri_enabled(struct pci_dev *pdev)
+{
+       return false;
+}
+
+static inline int pci_reset_pri(struct pci_dev *pdev)
+{
+       return -ENODEV;
+}
+
+static inline bool pci_pri_stopped(struct pci_dev *pdev)
+{
+       return true;
+}
+
+static inline int pci_pri_status(struct pci_dev *pdev)
+{
+       return -ENODEV;
+}
+#endif /* CONFIG_PCI_PRI */
+
+#ifdef CONFIG_PCI_PASID
+
+extern int pci_enable_pasid(struct pci_dev *pdev, int features);
+extern void pci_disable_pasid(struct pci_dev *pdev);
+extern int pci_pasid_features(struct pci_dev *pdev);
+extern int pci_max_pasids(struct pci_dev *pdev);
+
+#else  /* CONFIG_PCI_PASID */
+
+static inline int pci_enable_pasid(struct pci_dev *pdev, int features)
+{
+       return -EINVAL;
+}
+
+static inline void pci_disable_pasid(struct pci_dev *pdev)
+{
+}
+
+static inline int pci_pasid_features(struct pci_dev *pdev)
+{
+       return -EINVAL;
+}
+
+static inline int pci_max_pasids(struct pci_dev *pdev)
+{
+       return -EINVAL;
+}
+
+#endif /* CONFIG_PCI_PASID */
+
+
 #endif /* LINUX_PCI_ATS_H*/
index f1b1ca1a09e180bd6cdb7a3b698fa07534127807..337df0d5d5f7eb2e80410e4e0980afe4ef4ed83a 100644 (file)
@@ -275,6 +275,7 @@ struct pci_dev {
        unsigned int    pme_support:5;  /* Bitmask of states from which PME#
                                           can be generated */
        unsigned int    pme_interrupt:1;
+       unsigned int    pme_poll:1;     /* Poll device's PME status bit */
        unsigned int    d1_support:1;   /* Low power state D1 is supported */
        unsigned int    d2_support:1;   /* Low power state D2 is supported */
        unsigned int    no_d1d2:1;      /* Only allow D0 and D3 */
@@ -957,6 +958,7 @@ void pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *),
 int pci_cfg_space_size_ext(struct pci_dev *dev);
 int pci_cfg_space_size(struct pci_dev *dev);
 unsigned char pci_bus_max_busnr(struct pci_bus *bus);
+void pci_setup_bridge(struct pci_bus *bus);
 
 #define PCI_VGA_STATE_CHANGE_BRIDGE (1 << 0)
 #define PCI_VGA_STATE_CHANGE_DECODES (1 << 1)
index ae96bbe54518449fc66357b5405d0a175e61ca28..1679ff6931f977146bade5b851bb245dd72cec7c 100644 (file)
 #define PCI_DEVICE_ID_RENESAS_SH7785   0x0007
 #define PCI_DEVICE_ID_RENESAS_SH7786   0x0010
 
+#define PCI_VENDOR_ID_SOLARFLARE       0x1924
+#define PCI_DEVICE_ID_SOLARFLARE_SFC4000A_0    0x0703
+#define PCI_DEVICE_ID_SOLARFLARE_SFC4000A_1    0x6703
+#define PCI_DEVICE_ID_SOLARFLARE_SFC4000B      0x0710
+
 #define PCI_VENDOR_ID_TDI               0x192E
 #define PCI_DEVICE_ID_TDI_EHCI          0x0101
 
index e8840964aca135c023dd2780bd36703197ea936b..b5d9657f31004d64e53d9467646c1f268f4d51ab 100644 (file)
 #define  PCI_ATS_CTRL_STU(x)   ((x) & 0x1f)    /* Smallest Translation Unit */
 #define  PCI_ATS_MIN_STU       12      /* shift of minimum STU block */
 
+/* Page Request Interface */
+#define PCI_PRI_CAP            0x13    /* PRI capability ID */
+#define PCI_PRI_CONTROL_OFF    0x04    /* Offset of control register */
+#define PCI_PRI_STATUS_OFF     0x06    /* Offset of status register */
+#define PCI_PRI_ENABLE         0x0001  /* Enable mask */
+#define PCI_PRI_RESET          0x0002  /* Reset bit mask */
+#define PCI_PRI_STATUS_RF      0x0001  /* Request Failure */
+#define PCI_PRI_STATUS_UPRGI   0x0002  /* Unexpected PRG index */
+#define PCI_PRI_STATUS_STOPPED 0x0100  /* PRI Stopped */
+#define PCI_PRI_MAX_REQ_OFF    0x08    /* Cap offset for max reqs supported */
+#define PCI_PRI_ALLOC_REQ_OFF  0x0c    /* Cap offset for max reqs allowed */
+
+/* PASID capability */
+#define PCI_PASID_CAP          0x1b    /* PASID capability ID */
+#define PCI_PASID_CAP_OFF      0x04    /* PASID feature register */
+#define PCI_PASID_CONTROL_OFF   0x06    /* PASID control register */
+#define PCI_PASID_ENABLE       0x01    /* Enable/Supported bit */
+#define PCI_PASID_EXEC         0x02    /* Exec permissions Enable/Supported */
+#define PCI_PASID_PRIV         0x04    /* Priviledge Mode Enable/Support */
+
 /* Single Root I/O Virtualization */
 #define PCI_SRIOV_CAP          0x04    /* SR-IOV Capabilities */
 #define  PCI_SRIOV_CAP_VFM     0x01    /* VF Migration Capable */
diff --git a/include/linux/platform_data/leds-renesas-tpu.h b/include/linux/platform_data/leds-renesas-tpu.h
new file mode 100644 (file)
index 0000000..0553870
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef __LEDS_RENESAS_TPU_H__
+#define __LEDS_RENESAS_TPU_H__
+
+struct led_renesas_tpu_config {
+       char *name;
+       unsigned pin_gpio_fn;
+       unsigned pin_gpio;
+       unsigned int channel_offset;
+       unsigned int timer_bit;
+       unsigned int max_brightness;
+       unsigned int refresh_rate;
+};
+
+#endif /* __LEDS_RENESAS_TPU_H__ */
index 651a066686ac6a40e52f7f1229bc14735d430b64..2a23f7d1a8252807055d58f29f8d0833c75ed999 100644 (file)
@@ -190,6 +190,23 @@ static inline void platform_set_drvdata(struct platform_device *pdev, void *data
        dev_set_drvdata(&pdev->dev, data);
 }
 
+/* module_platform_driver() - Helper macro for drivers that don't do
+ * anything special in module init/exit.  This eliminates a lot of
+ * boilerplate.  Each module may only use this macro once, and
+ * calling it replaces module_init() and module_exit()
+ */
+#define module_platform_driver(__platform_driver) \
+static int __init __platform_driver##_init(void) \
+{ \
+       return platform_driver_register(&(__platform_driver)); \
+} \
+module_init(__platform_driver##_init); \
+static void __exit __platform_driver##_exit(void) \
+{ \
+       platform_driver_unregister(&(__platform_driver)); \
+} \
+module_exit(__platform_driver##_exit);
+
 extern struct platform_device *platform_create_bundle(struct platform_driver *driver,
                                        int (*probe)(struct platform_device *),
                                        struct resource *res, unsigned int n_res,
index 0101d55d9651f3cc1dc48858ba0ca1b301ec6425..f0e22f75143f67e3b4d8dc72ba4bc8e81e3a5570 100644 (file)
@@ -82,22 +82,22 @@ struct va_format {
  * Dummy printk for disabled debugging statements to use whilst maintaining
  * gcc's format and side-effect checking.
  */
-static inline __attribute__ ((format (printf, 1, 2)))
+static inline __printf(1, 2)
 int no_printk(const char *fmt, ...)
 {
        return 0;
 }
 
-extern asmlinkage __attribute__ ((format (printf, 1, 2)))
+extern asmlinkage __printf(1, 2)
 void early_printk(const char *fmt, ...);
 
 extern int printk_needs_cpu(int cpu);
 extern void printk_tick(void);
 
 #ifdef CONFIG_PRINTK
-asmlinkage __attribute__ ((format (printf, 1, 0)))
+asmlinkage __printf(1, 0)
 int vprintk(const char *fmt, va_list args);
-asmlinkage __attribute__ ((format (printf, 1, 2))) __cold
+asmlinkage __printf(1, 2) __cold
 int printk(const char *fmt, ...);
 
 /*
@@ -117,12 +117,12 @@ extern int kptr_restrict;
 void log_buf_kexec_setup(void);
 void __init setup_log_buf(int early);
 #else
-static inline __attribute__ ((format (printf, 1, 0)))
+static inline __printf(1, 0)
 int vprintk(const char *s, va_list args)
 {
        return 0;
 }
-static inline __attribute__ ((format (printf, 1, 2))) __cold
+static inline __printf(1, 2) __cold
 int printk(const char *s, ...)
 {
        return 0;
index cc03bbf5c4b8e4dbe8c2b91b39f7a1b83b866fcb..ea567321ae3c3b2ac02967680f99de1687f99982 100644 (file)
@@ -32,15 +32,15 @@ enum pstore_type_id {
 struct pstore_info {
        struct module   *owner;
        char            *name;
-       struct mutex    buf_mutex;      /* serialize access to 'buf' */
+       spinlock_t      buf_lock;       /* serialize access to 'buf' */
        char            *buf;
        size_t          bufsize;
        int             (*open)(struct pstore_info *psi);
        int             (*close)(struct pstore_info *psi);
        ssize_t         (*read)(u64 *id, enum pstore_type_id *type,
                        struct timespec *time, struct pstore_info *psi);
-       u64             (*write)(enum pstore_type_id type, unsigned int part,
-                       size_t size, struct pstore_info *psi);
+       int             (*write)(enum pstore_type_id type, u64 *id,
+                       unsigned int part, size_t size, struct pstore_info *psi);
        int             (*erase)(enum pstore_type_id type, u64 id,
                        struct pstore_info *psi);
        void            *data;
index 26f9e3612e0f6618e8d15285db9b354d63ffbb96..d93f95e6177ce4bc583538f1dfb3366fe9f9b322 100644 (file)
@@ -31,7 +31,7 @@ static inline bool is_quota_modification(struct inode *inode, struct iattr *ia)
 #define quota_error(sb, fmt, args...) \
        __quota_error((sb), __func__, fmt , ## args)
 
-extern __attribute__((format (printf, 3, 4)))
+extern __printf(3, 4)
 void __quota_error(struct super_block *sb, const char *func,
                   const char *fmt, ...);
 
index b47771aa57180b6d553fbdb9363973f28569fde6..f7756d146c6164560fd919f16699b0d601a09f26 100644 (file)
@@ -141,6 +141,7 @@ int regulator_enable(struct regulator *regulator);
 int regulator_disable(struct regulator *regulator);
 int regulator_force_disable(struct regulator *regulator);
 int regulator_is_enabled(struct regulator *regulator);
+int regulator_disable_deferred(struct regulator *regulator, int ms);
 
 int regulator_bulk_get(struct device *dev, int num_consumers,
                       struct regulator_bulk_data *consumers);
@@ -211,6 +212,12 @@ static inline int regulator_disable(struct regulator *regulator)
        return 0;
 }
 
+static inline int regulator_disable_deferred(struct regulator *regulator,
+                                            int ms)
+{
+       return 0;
+}
+
 static inline int regulator_is_enabled(struct regulator *regulator)
 {
        return 1;
index 1a80bc77517d03870ea9f34a6d2c317953445bc4..12a1aa04b720cdb3491a2d35f32cb85a9bdcc6ff 100644 (file)
@@ -199,6 +199,9 @@ struct regulator_dev {
        struct regulation_constraints *constraints;
        struct regulator *supply;       /* for tree */
 
+       struct delayed_work disable_work;
+       int deferred_disables;
+
        void *reg_data;         /* regulator_dev data */
 
 #ifdef CONFIG_DEBUG_FS
diff --git a/include/linux/regulator/gpio-regulator.h b/include/linux/regulator/gpio-regulator.h
new file mode 100644 (file)
index 0000000..19fbd26
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * gpio-regulator.h
+ *
+ * Copyright 2011 Heiko Stuebner <heiko@sntech.de>
+ *
+ * based on fixed.h
+ *
+ * Copyright 2008 Wolfson Microelectronics PLC.
+ *
+ * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
+ *
+ * Copyright (c) 2009 Nokia Corporation
+ * Roger Quadros <ext-roger.quadros@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ */
+
+#ifndef __REGULATOR_GPIO_H
+#define __REGULATOR_GPIO_H
+
+struct regulator_init_data;
+
+enum regulator_type;
+
+/**
+ * struct gpio_regulator_state - state description
+ * @value:             microvolts or microamps
+ * @gpios:             bitfield of gpio target-states for the value
+ *
+ * This structure describes a supported setting of the regulator
+ * and the necessary gpio-state to achieve it.
+ *
+ * The n-th bit in the bitfield describes the state of the n-th GPIO
+ * from the gpios-array defined in gpio_regulator_config below.
+ */
+struct gpio_regulator_state {
+       int value;
+       int gpios;
+};
+
+/**
+ * struct gpio_regulator_config - config structure
+ * @supply_name:       Name of the regulator supply
+ * @enable_gpio:       GPIO to use for enable control
+ *                     set to -EINVAL if not used
+ * @enable_high:       Polarity of enable GPIO
+ *                     1 = Active high, 0 = Active low
+ * @enabled_at_boot:   Whether regulator has been enabled at
+ *                     boot or not. 1 = Yes, 0 = No
+ *                     This is used to keep the regulator at
+ *                     the default state
+ * @startup_delay:     Start-up time in microseconds
+ * @gpios:             Array containing the gpios needed to control
+ *                     the setting of the regulator
+ * @nr_gpios:          Number of gpios
+ * @states:            Array of gpio_regulator_state entries describing
+ *                     the gpio state for specific voltages
+ * @nr_states:         Number of states available
+ * @regulator_type:    either REGULATOR_CURRENT or REGULATOR_VOLTAGE
+ * @init_data:         regulator_init_data
+ *
+ * This structure contains gpio-voltage regulator configuration
+ * information that must be passed by platform code to the
+ * gpio-voltage regulator driver.
+ */
+struct gpio_regulator_config {
+       const char *supply_name;
+
+       int enable_gpio;
+       unsigned enable_high:1;
+       unsigned enabled_at_boot:1;
+       unsigned startup_delay;
+
+       struct gpio *gpios;
+       int nr_gpios;
+
+       struct gpio_regulator_state *states;
+       int nr_states;
+
+       enum regulator_type type;
+       struct regulator_init_data *init_data;
+};
+
+#endif
index ce3127a75c8866a27afeeb875bd5943c2dc61976..f3f13fd5868fae18e3dad5c42943396297d76808 100644 (file)
@@ -95,7 +95,7 @@ struct regulator_state {
  */
 struct regulation_constraints {
 
-       char *name;
+       const char *name;
 
        /* voltage output range (inclusive) - for voltage control */
        int min_uV;
index be720cd2038d3704d30d9f183798be084936c914..0b69a46842160770807197b7470075bf6ae16bde 100644 (file)
@@ -84,8 +84,7 @@ int seq_putc(struct seq_file *m, char c);
 int seq_puts(struct seq_file *m, const char *s);
 int seq_write(struct seq_file *seq, const void *data, size_t len);
 
-int seq_printf(struct seq_file *, const char *, ...)
-       __attribute__ ((format (printf,2,3)));
+__printf(2, 3) int seq_printf(struct seq_file *, const char *, ...);
 
 int seq_path(struct seq_file *, struct path *, char *);
 int seq_dentry(struct seq_file *, struct dentry *, char *);
index 790651b4e5baf6ea9625cd186065019e8133784e..a83833a1f7a26f589a7584252ff413333286f5ea 100644 (file)
@@ -20,6 +20,7 @@ struct shrink_control {
  * 'nr_to_scan' entries and attempt to free them up.  It should return
  * the number of objects which remain in the cache.  If it returns -1, it means
  * it cannot do any scanning at this time (eg. there is a risk of deadlock).
+ * The callback must not return -1 if nr_to_scan is zero.
  *
  * The 'gfpmask' refers to the allocation we are currently trying to
  * fulfil.
index aee1dbda4edc2b4a8a53134c0fdc24575d1e65aa..bc8677c8eba92c2ed22e23a1089d19486062a512 100644 (file)
@@ -24,8 +24,6 @@
 struct l4f00242t03_pdata {
        unsigned int    reset_gpio;
        unsigned int    data_enable_gpio;
-       const char      *io_supply;     /* will be set to 1.8 V */
-       const char      *core_supply;   /* will be set to 2.8 V */
 };
 
 #endif /* _INCLUDE_LINUX_SPI_L4F00242T03_H_ */
index a176db2f2c854755c360202358a227b4f42435d3..e033564f10baec5b9b39a75c29f956f5d512e7c4 100644 (file)
@@ -114,6 +114,7 @@ extern int memcmp(const void *,const void *,__kernel_size_t);
 #ifndef __HAVE_ARCH_MEMCHR
 extern void * memchr(const void *,int,__kernel_size_t);
 #endif
+void *memchr_inv(const void *s, int c, size_t n);
 
 extern char *kstrdup(const char *s, gfp_t gfp);
 extern char *kstrndup(const char *s, size_t len, gfp_t gfp);
index c71f84bb62ecbae2b7ad6efac084eb175ad3a4ea..1e22e126d2acc7a880f449c5241c3a56e901e519 100644 (file)
@@ -243,15 +243,10 @@ static inline void lru_cache_add_file(struct page *page)
        __lru_cache_add(page, LRU_INACTIVE_FILE);
 }
 
-/* LRU Isolation modes. */
-#define ISOLATE_INACTIVE 0     /* Isolate inactive pages. */
-#define ISOLATE_ACTIVE 1       /* Isolate active pages. */
-#define ISOLATE_BOTH 2         /* Isolate both active and inactive pages. */
-
 /* linux/mm/vmscan.c */
 extern unsigned long try_to_free_pages(struct zonelist *zonelist, int order,
                                        gfp_t gfp_mask, nodemask_t *mask);
-extern int __isolate_lru_page(struct page *page, int mode, int file);
+extern int __isolate_lru_page(struct page *page, isolate_mode_t mode, int file);
 extern unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *mem,
                                                  gfp_t gfp_mask, bool noswap);
 extern unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem,
index 1ff0ec2a5e8d29a2a4519bb882900c56f39c0dab..86a24b1166d16d28bb49f44bd0317cff51fb1ff8 100644 (file)
@@ -844,4 +844,17 @@ asmlinkage long sys_open_by_handle_at(int mountdirfd,
                                      struct file_handle __user *handle,
                                      int flags);
 asmlinkage long sys_setns(int fd, int nstype);
+asmlinkage long sys_process_vm_readv(pid_t pid,
+                                    const struct iovec __user *lvec,
+                                    unsigned long liovcnt,
+                                    const struct iovec __user *rvec,
+                                    unsigned long riovcnt,
+                                    unsigned long flags);
+asmlinkage long sys_process_vm_writev(pid_t pid,
+                                     const struct iovec __user *lvec,
+                                     unsigned long liovcnt,
+                                     const struct iovec __user *rvec,
+                                     unsigned long riovcnt,
+                                     unsigned long flags);
+
 #endif
index 5cf397ceb726fee2c48da416f8ade27c1ae6a7f5..7dadc3df0c77da531483d17210589b8294f5bc8f 100644 (file)
@@ -29,10 +29,10 @@ trace_seq_init(struct trace_seq *s)
  * Currently only defined when tracing is enabled.
  */
 #ifdef CONFIG_TRACING
-extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
-       __attribute__ ((format (printf, 2, 3)));
-extern int trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args)
-       __attribute__ ((format (printf, 2, 0)));
+extern __printf(2, 3)
+int trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
+extern __printf(2, 0)
+int trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args);
 extern int
 trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary);
 extern int trace_print_seq(struct seq_file *m, struct trace_seq *s);
index ed91fb62674b03edc96aa70a6fef735f9fabfb90..b607f3532e880011453fd04462cbe90801538a6d 100644 (file)
@@ -7,3 +7,4 @@ header-y += gadgetfs.h
 header-y += midi.h
 header-y += g_printer.h
 header-y += tmc.h
+header-y += video.h
index f32a64e57f9784c65d69520adf02e73c37ffa7b5..d5da6c68c250b463552eef060430631af0541098 100644 (file)
@@ -383,12 +383,6 @@ struct usb_endpoint_descriptor {
 #define USB_ENDPOINT_NUMBER_MASK       0x0f    /* in bEndpointAddress */
 #define USB_ENDPOINT_DIR_MASK          0x80
 
-#define USB_ENDPOINT_SYNCTYPE          0x0c
-#define USB_ENDPOINT_SYNC_NONE         (0 << 2)
-#define USB_ENDPOINT_SYNC_ASYNC                (1 << 2)
-#define USB_ENDPOINT_SYNC_ADAPTIVE     (2 << 2)
-#define USB_ENDPOINT_SYNC_SYNC         (3 << 2)
-
 #define USB_ENDPOINT_XFERTYPE_MASK     0x03    /* in bmAttributes */
 #define USB_ENDPOINT_XFER_CONTROL      0
 #define USB_ENDPOINT_XFER_ISOC         1
@@ -396,6 +390,17 @@ struct usb_endpoint_descriptor {
 #define USB_ENDPOINT_XFER_INT          3
 #define USB_ENDPOINT_MAX_ADJUSTABLE    0x80
 
+#define USB_ENDPOINT_SYNCTYPE          0x0c
+#define USB_ENDPOINT_SYNC_NONE         (0 << 2)
+#define USB_ENDPOINT_SYNC_ASYNC                (1 << 2)
+#define USB_ENDPOINT_SYNC_ADAPTIVE     (2 << 2)
+#define USB_ENDPOINT_SYNC_SYNC         (3 << 2)
+
+#define USB_ENDPOINT_USAGE_MASK                0x30
+#define USB_ENDPOINT_USAGE_DATA                0x00
+#define USB_ENDPOINT_USAGE_FEEDBACK    0x10
+#define USB_ENDPOINT_USAGE_IMPLICIT_FB 0x20    /* Implicit feedback Data endpoint */
+
 /*-------------------------------------------------------------------------*/
 
 /**
index fca24cc504367ea6218c6d6c01c03ccf497ffb38..225560c1a10fc0b7af1de3c497ce7777c6d092b5 100644 (file)
@@ -759,10 +759,10 @@ typedef __u64 v4l2_std_id;
 #define V4L2_STD_PAL_Nc         ((v4l2_std_id)0x00000400)
 #define V4L2_STD_PAL_60         ((v4l2_std_id)0x00000800)
 
-#define V4L2_STD_NTSC_M         ((v4l2_std_id)0x00001000)
-#define V4L2_STD_NTSC_M_JP      ((v4l2_std_id)0x00002000)
+#define V4L2_STD_NTSC_M         ((v4l2_std_id)0x00001000)      /* BTSC */
+#define V4L2_STD_NTSC_M_JP      ((v4l2_std_id)0x00002000)      /* EIA-J */
 #define V4L2_STD_NTSC_443       ((v4l2_std_id)0x00004000)
-#define V4L2_STD_NTSC_M_KR      ((v4l2_std_id)0x00008000)
+#define V4L2_STD_NTSC_M_KR      ((v4l2_std_id)0x00008000)      /* FM A2 */
 
 #define V4L2_STD_SECAM_B        ((v4l2_std_id)0x00010000)
 #define V4L2_STD_SECAM_D        ((v4l2_std_id)0x00020000)
@@ -786,47 +786,86 @@ typedef __u64 v4l2_std_id;
    v4l2-common.c should be fixed.
  */
 
-/* some merged standards */
-#define V4L2_STD_MN    (V4L2_STD_PAL_M|V4L2_STD_PAL_N|V4L2_STD_PAL_Nc|V4L2_STD_NTSC)
-#define V4L2_STD_B     (V4L2_STD_PAL_B|V4L2_STD_PAL_B1|V4L2_STD_SECAM_B)
-#define V4L2_STD_GH    (V4L2_STD_PAL_G|V4L2_STD_PAL_H|V4L2_STD_SECAM_G|V4L2_STD_SECAM_H)
-#define V4L2_STD_DK    (V4L2_STD_PAL_DK|V4L2_STD_SECAM_DK)
+/*
+ * Some macros to merge video standards in order to make live easier for the
+ * drivers and V4L2 applications
+ */
 
-/* some common needed stuff */
-#define V4L2_STD_PAL_BG                (V4L2_STD_PAL_B         |\
-                                V4L2_STD_PAL_B1        |\
-                                V4L2_STD_PAL_G)
-#define V4L2_STD_PAL_DK                (V4L2_STD_PAL_D         |\
-                                V4L2_STD_PAL_D1        |\
-                                V4L2_STD_PAL_K)
-#define V4L2_STD_PAL           (V4L2_STD_PAL_BG        |\
-                                V4L2_STD_PAL_DK        |\
-                                V4L2_STD_PAL_H         |\
-                                V4L2_STD_PAL_I)
+/*
+ * "Common" NTSC/M - It should be noticed that V4L2_STD_NTSC_443 is
+ * Missing here.
+ */
 #define V4L2_STD_NTSC           (V4L2_STD_NTSC_M       |\
                                 V4L2_STD_NTSC_M_JP     |\
                                 V4L2_STD_NTSC_M_KR)
+/* Secam macros */
 #define V4L2_STD_SECAM_DK              (V4L2_STD_SECAM_D       |\
                                 V4L2_STD_SECAM_K       |\
                                 V4L2_STD_SECAM_K1)
+/* All Secam Standards */
 #define V4L2_STD_SECAM         (V4L2_STD_SECAM_B       |\
                                 V4L2_STD_SECAM_G       |\
                                 V4L2_STD_SECAM_H       |\
                                 V4L2_STD_SECAM_DK      |\
                                 V4L2_STD_SECAM_L       |\
                                 V4L2_STD_SECAM_LC)
+/* PAL macros */
+#define V4L2_STD_PAL_BG                (V4L2_STD_PAL_B         |\
+                                V4L2_STD_PAL_B1        |\
+                                V4L2_STD_PAL_G)
+#define V4L2_STD_PAL_DK                (V4L2_STD_PAL_D         |\
+                                V4L2_STD_PAL_D1        |\
+                                V4L2_STD_PAL_K)
+/*
+ * "Common" PAL - This macro is there to be compatible with the old
+ * V4L1 concept of "PAL": /BGDKHI.
+ * Several PAL standards are mising here: /M, /N and /Nc
+ */
+#define V4L2_STD_PAL           (V4L2_STD_PAL_BG        |\
+                                V4L2_STD_PAL_DK        |\
+                                V4L2_STD_PAL_H         |\
+                                V4L2_STD_PAL_I)
+/* Chroma "agnostic" standards */
+#define V4L2_STD_B             (V4L2_STD_PAL_B         |\
+                                V4L2_STD_PAL_B1        |\
+                                V4L2_STD_SECAM_B)
+#define V4L2_STD_G             (V4L2_STD_PAL_G         |\
+                                V4L2_STD_SECAM_G)
+#define V4L2_STD_H             (V4L2_STD_PAL_H         |\
+                                V4L2_STD_SECAM_H)
+#define V4L2_STD_L             (V4L2_STD_SECAM_L       |\
+                                V4L2_STD_SECAM_LC)
+#define V4L2_STD_GH            (V4L2_STD_G             |\
+                                V4L2_STD_H)
+#define V4L2_STD_DK            (V4L2_STD_PAL_DK        |\
+                                V4L2_STD_SECAM_DK)
+#define V4L2_STD_BG            (V4L2_STD_B             |\
+                                V4L2_STD_G)
+#define V4L2_STD_MN            (V4L2_STD_PAL_M         |\
+                                V4L2_STD_PAL_N         |\
+                                V4L2_STD_PAL_Nc        |\
+                                V4L2_STD_NTSC)
+
+/* Standards where MTS/BTSC stereo could be found */
+#define V4L2_STD_MTS           (V4L2_STD_NTSC_M        |\
+                                V4L2_STD_PAL_M         |\
+                                V4L2_STD_PAL_N         |\
+                                V4L2_STD_PAL_Nc)
 
+/* Standards for Countries with 60Hz Line frequency */
 #define V4L2_STD_525_60                (V4L2_STD_PAL_M         |\
                                 V4L2_STD_PAL_60        |\
                                 V4L2_STD_NTSC          |\
                                 V4L2_STD_NTSC_443)
+/* Standards for Countries with 50Hz Line frequency */
 #define V4L2_STD_625_50                (V4L2_STD_PAL           |\
                                 V4L2_STD_PAL_N         |\
                                 V4L2_STD_PAL_Nc        |\
                                 V4L2_STD_SECAM)
+
 #define V4L2_STD_ATSC           (V4L2_STD_ATSC_8_VSB    |\
                                 V4L2_STD_ATSC_16_VSB)
-
+/* Macros with none and all analog standards */
 #define V4L2_STD_UNKNOWN        0
 #define V4L2_STD_ALL            (V4L2_STD_525_60       |\
                                 V4L2_STD_625_50)
@@ -1082,6 +1121,7 @@ struct v4l2_querymenu {
 #define V4L2_CTRL_FLAG_INACTIVE        0x0010
 #define V4L2_CTRL_FLAG_SLIDER          0x0020
 #define V4L2_CTRL_FLAG_WRITE_ONLY      0x0040
+#define V4L2_CTRL_FLAG_VOLATILE                0x0080
 
 /*  Query flag, to be ORed with the control ID */
 #define V4L2_CTRL_FLAG_NEXT_CTRL       0x80000000
@@ -2006,6 +2046,7 @@ struct v4l2_streamparm {
 #define V4L2_EVENT_VSYNC                       1
 #define V4L2_EVENT_EOS                         2
 #define V4L2_EVENT_CTRL                                3
+#define V4L2_EVENT_FRAME_SYNC                  4
 #define V4L2_EVENT_PRIVATE_START               0x08000000
 
 /* Payload for V4L2_EVENT_VSYNC */
@@ -2032,12 +2073,17 @@ struct v4l2_event_ctrl {
        __s32 default_value;
 };
 
+struct v4l2_event_frame_sync {
+       __u32 frame_sequence;
+};
+
 struct v4l2_event {
        __u32                           type;
        union {
-               struct v4l2_event_vsync vsync;
-               struct v4l2_event_ctrl  ctrl;
-               __u8                    data[64];
+               struct v4l2_event_vsync         vsync;
+               struct v4l2_event_ctrl          ctrl;
+               struct v4l2_event_frame_sync    frame_sync;
+               __u8                            data[64];
        } u;
        __u32                           pending;
        __u32                           sequence;
index 9332e52ea8c270aadacb79b61446336202e1fea6..687fb11e20107d9c22467e1923d5e736bde16d3e 100644 (file)
@@ -13,6 +13,7 @@ struct vm_area_struct;                /* vma defining user mapping in mm_types.h */
 #define VM_MAP         0x00000004      /* vmap()ed pages */
 #define VM_USERMAP     0x00000008      /* suitable for remap_vmalloc_range */
 #define VM_VPAGES      0x00000010      /* buffer for pages was vmalloc'ed */
+#define VM_UNLIST      0x00000020      /* vm_struct is not listed in vmlist */
 /* bits [20..32] reserved for arch specific ioremap internals */
 
 /*
index aac2c0e06d5ee78c6795f23efdd99b6aedf4767e..4a825ae5c6c8ec2469c7b46968089cf683718385 100644 (file)
 
 /**
  * struct m5mols_platform_data - platform data for M-5MOLS driver
- * @irq:       GPIO getting the irq pin of M-5MOLS
  * @gpio_reset:        GPIO driving the reset pin of M-5MOLS
- * @reset_polarity: active state for gpio_rst pin, 0 or 1
+ * @reset_polarity: active state for gpio_reset pin, 0 or 1
  * @set_power: an additional callback to the board setup code
  *             to be called after enabling and before disabling
  *             the sensor's supply regulators
  */
 struct m5mols_platform_data {
-       int irq;
        int gpio_reset;
        u8 reset_polarity;
        int (*set_power)(struct device *dev, int on);
diff --git a/include/media/mt9p031.h b/include/media/mt9p031.h
new file mode 100644 (file)
index 0000000..96448c7
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef MT9P031_H
+#define MT9P031_H
+
+struct v4l2_subdev;
+
+enum {
+       MT9P031_COLOR_VERSION,
+       MT9P031_MONOCHROME_VERSION,
+};
+
+struct mt9p031_platform_data {
+       int (*set_xclk)(struct v4l2_subdev *subdev, int hz);
+       int (*reset)(struct v4l2_subdev *subdev, int active);
+       int ext_freq; /* input frequency to the mt9p031 for PLL dividers */
+       int target_freq; /* frequency target for the PLL */
+       int version; /* MT9P031_COLOR_VERSION or MT9P031_MONOCHROME_VERSION */
+};
+
+#endif
diff --git a/include/media/mt9t001.h b/include/media/mt9t001.h
new file mode 100644 (file)
index 0000000..e839a78
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef _MEDIA_MT9T001_H
+#define _MEDIA_MT9T001_H
+
+struct mt9t001_platform_data {
+       unsigned int clk_pol:1;
+};
+
+#endif
diff --git a/include/media/omap3isp.h b/include/media/omap3isp.h
new file mode 100644 (file)
index 0000000..e917b1d
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+ * omap3isp.h
+ *
+ * TI OMAP3 ISP - Platform data
+ *
+ * Copyright (C) 2011 Nokia Corporation
+ *
+ * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ *          Sakari Ailus <sakari.ailus@iki.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#ifndef __MEDIA_OMAP3ISP_H__
+#define __MEDIA_OMAP3ISP_H__
+
+struct i2c_board_info;
+struct isp_device;
+
+enum isp_interface_type {
+       ISP_INTERFACE_PARALLEL,
+       ISP_INTERFACE_CSI2A_PHY2,
+       ISP_INTERFACE_CCP2B_PHY1,
+       ISP_INTERFACE_CCP2B_PHY2,
+       ISP_INTERFACE_CSI2C_PHY1,
+};
+
+enum {
+       ISP_BRIDGE_DISABLE = 0,
+       ISP_BRIDGE_LITTLE_ENDIAN = 2,
+       ISP_BRIDGE_BIG_ENDIAN = 3,
+};
+
+enum {
+       ISP_LANE_SHIFT_0 = 0,
+       ISP_LANE_SHIFT_2 = 1,
+       ISP_LANE_SHIFT_4 = 2,
+       ISP_LANE_SHIFT_6 = 3,
+};
+
+/**
+ * struct isp_parallel_platform_data - Parallel interface platform data
+ * @data_lane_shift: Data lane shifter
+ *             ISP_LANE_SHIFT_0 - CAMEXT[13:0] -> CAM[13:0]
+ *             ISP_LANE_SHIFT_2 - CAMEXT[13:2] -> CAM[11:0]
+ *             ISP_LANE_SHIFT_4 - CAMEXT[13:4] -> CAM[9:0]
+ *             ISP_LANE_SHIFT_6 - CAMEXT[13:6] -> CAM[7:0]
+ * @clk_pol: Pixel clock polarity
+ *             0 - Non Inverted, 1 - Inverted
+ * @hs_pol: Horizontal synchronization polarity
+ *             0 - Active high, 1 - Active low
+ * @vs_pol: Vertical synchronization polarity
+ *             0 - Active high, 1 - Active low
+ * @bridge: CCDC Bridge input control
+ *             ISP_BRIDGE_DISABLE - Disable
+ *             ISP_BRIDGE_LITTLE_ENDIAN - Little endian
+ *             ISP_BRIDGE_BIG_ENDIAN - Big endian
+ */
+struct isp_parallel_platform_data {
+       unsigned int data_lane_shift:2;
+       unsigned int clk_pol:1;
+       unsigned int hs_pol:1;
+       unsigned int vs_pol:1;
+       unsigned int bridge:2;
+};
+
+enum {
+       ISP_CCP2_PHY_DATA_CLOCK = 0,
+       ISP_CCP2_PHY_DATA_STROBE = 1,
+};
+
+enum {
+       ISP_CCP2_MODE_MIPI = 0,
+       ISP_CCP2_MODE_CCP2 = 1,
+};
+
+/**
+ * struct isp_ccp2_platform_data - CCP2 interface platform data
+ * @strobe_clk_pol: Strobe/clock polarity
+ *             0 - Non Inverted, 1 - Inverted
+ * @crc: Enable the cyclic redundancy check
+ * @ccp2_mode: Enable CCP2 compatibility mode
+ *             ISP_CCP2_MODE_MIPI - MIPI-CSI1 mode
+ *             ISP_CCP2_MODE_CCP2 - CCP2 mode
+ * @phy_layer: Physical layer selection
+ *             ISP_CCP2_PHY_DATA_CLOCK - Data/clock physical layer
+ *             ISP_CCP2_PHY_DATA_STROBE - Data/strobe physical layer
+ * @vpclk_div: Video port output clock control
+ */
+struct isp_ccp2_platform_data {
+       unsigned int strobe_clk_pol:1;
+       unsigned int crc:1;
+       unsigned int ccp2_mode:1;
+       unsigned int phy_layer:1;
+       unsigned int vpclk_div:2;
+};
+
+/**
+ * struct isp_csi2_platform_data - CSI2 interface platform data
+ * @crc: Enable the cyclic redundancy check
+ * @vpclk_div: Video port output clock control
+ */
+struct isp_csi2_platform_data {
+       unsigned crc:1;
+       unsigned vpclk_div:2;
+};
+
+struct isp_subdev_i2c_board_info {
+       struct i2c_board_info *board_info;
+       int i2c_adapter_id;
+};
+
+struct isp_v4l2_subdevs_group {
+       struct isp_subdev_i2c_board_info *subdevs;
+       enum isp_interface_type interface;
+       union {
+               struct isp_parallel_platform_data parallel;
+               struct isp_ccp2_platform_data ccp2;
+               struct isp_csi2_platform_data csi2;
+       } bus; /* gcc < 4.6.0 chokes on anonymous union initializers */
+};
+
+struct isp_platform_data {
+       struct isp_v4l2_subdevs_group *subdevs;
+       void (*set_constraints)(struct isp_device *isp, bool enable);
+};
+
+#endif /* __MEDIA_OMAP3ISP_H__ */
index b1f19b77ecd44c570f6d54c4e3018e877aa783f1..b0c494a6907904b9ceb38dac8be868f06b276d5a 100644 (file)
 #include <media/rc-map.h>
 
 extern int rc_core_debug;
-#define IR_dprintk(level, fmt, arg...) if (rc_core_debug >= level) \
-       printk(KERN_DEBUG "%s: " fmt , __func__, ## arg)
+#define IR_dprintk(level, fmt, ...)                            \
+do {                                                           \
+       if (rc_core_debug >= level)                             \
+               pr_debug("%s: " fmt, __func__, ##__VA_ARGS__);  \
+} while (0)
 
 enum rc_driver_type {
        RC_DRIVER_SCANCODE = 0, /* Driver or hardware generates a scancode */
index 17c9759ae77bfbcc67241e33a9a6f1cfba8f8729..26a3bd0fe57ca7a393afe27c1004970f5354a701 100644 (file)
@@ -61,6 +61,7 @@ void rc_map_init(void);
 #define RC_MAP_APAC_VIEWCOMP             "rc-apac-viewcomp"
 #define RC_MAP_ASUS_PC39                 "rc-asus-pc39"
 #define RC_MAP_ATI_TV_WONDER_HD_600      "rc-ati-tv-wonder-hd-600"
+#define RC_MAP_ATI_X10                   "rc-ati-x10"
 #define RC_MAP_AVERMEDIA_A16D            "rc-avermedia-a16d"
 #define RC_MAP_AVERMEDIA_CARDBUS         "rc-avermedia-cardbus"
 #define RC_MAP_AVERMEDIA_DVBT            "rc-avermedia-dvbt"
@@ -106,6 +107,7 @@ void rc_map_init(void);
 #define RC_MAP_LIRC                      "rc-lirc"
 #define RC_MAP_LME2510                   "rc-lme2510"
 #define RC_MAP_MANLI                     "rc-manli"
+#define RC_MAP_MEDION_X10                "rc-medion-x10"
 #define RC_MAP_MSI_DIGIVOX_II            "rc-msi-digivox-ii"
 #define RC_MAP_MSI_DIGIVOX_III           "rc-msi-digivox-iii"
 #define RC_MAP_MSI_TVANYWHERE_PLUS       "rc-msi-tvanywhere-plus"
@@ -130,6 +132,7 @@ void rc_map_init(void);
 #define RC_MAP_RC5_TV                    "rc-rc5-tv"
 #define RC_MAP_RC6_MCE                   "rc-rc6-mce"
 #define RC_MAP_REAL_AUDIO_220_32_KEYS    "rc-real-audio-220-32-keys"
+#define RC_MAP_SNAPSTREAM_FIREFLY        "rc-snapstream-firefly"
 #define RC_MAP_STREAMZAP                 "rc-streamzap"
 #define RC_MAP_TBS_NEC                   "rc-tbs-nec"
 #define RC_MAP_TECHNISAT_USB2            "rc-technisat-usb2"
index 9fdff8a4ed2667f36beb2b3d551419f561ba2626..688fb3f1dc3566913965cd2281d344f40e9c8e59 100644 (file)
@@ -19,11 +19,6 @@ enum cam_bus_type {
        FIMC_LCD_WB, /* FIFO link from LCD mixer */
 };
 
-#define FIMC_CLK_INV_PCLK      (1 << 0)
-#define FIMC_CLK_INV_VSYNC     (1 << 1)
-#define FIMC_CLK_INV_HREF      (1 << 2)
-#define FIMC_CLK_INV_HSYNC     (1 << 3)
-
 struct i2c_board_info;
 
 /**
@@ -36,7 +31,8 @@ struct i2c_board_info;
  * @csi_data_align: MIPI-CSI interface data alignment in bits
  * @i2c_bus_num: i2c control bus id the sensor is attached to
  * @mux_id: FIMC camera interface multiplexer index (separate for MIPI and ITU)
- * @flags: flags defining bus signals polarity inversion (High by default)
+ * @clk_id: index of the SoC peripheral clock for sensors
+ * @flags: the parallel bus flags defining signals polarity (V4L2_MBUS_*)
  */
 struct s5p_fimc_isp_info {
        struct i2c_board_info *board_info;
@@ -46,6 +42,7 @@ struct s5p_fimc_isp_info {
        u16 i2c_bus_num;
        u16 mux_id;
        u16 flags;
+       u8 clk_id;
 };
 
 /**
@@ -58,4 +55,13 @@ struct s5p_platform_fimc {
        struct s5p_fimc_isp_info *isp_info;
        int num_clients;
 };
+
+/*
+ * v4l2_device notification id. This is only for internal use in the kernel.
+ * Sensor subdevs should issue S5P_FIMC_TX_END_NOTIFY notification in single
+ * frame capture mode when there is only one VSYNC pulse issued by the sensor
+ * at begining of the frame transmission.
+ */
+#define S5P_FIMC_TX_END_NOTIFY _IO('e', 0)
+
 #endif /* S5P_FIMC_H_ */
index 79827143d5acd925510f3ad7a4de2f912c49ff48..5017500eda1bfc42e83a77b1d2088899acc60c6c 100644 (file)
 
 extern unsigned int saa7146_debug;
 
-//#define DEBUG_PROLOG printk("(0x%08x)(0x%08x) %s: %s(): ",(dev==0?-1:(dev->mem==0?-1:saa7146_read(dev,RPS_ADDR0))),(dev==0?-1:(dev->mem==0?-1:saa7146_read(dev,IER))),KBUILD_MODNAME,__func__)
-
 #ifndef DEBUG_VARIABLE
        #define DEBUG_VARIABLE saa7146_debug
 #endif
 
-#define DEBUG_PROLOG printk("%s: %s(): ",KBUILD_MODNAME, __func__)
-#define INFO(x) { printk("%s: ",KBUILD_MODNAME); printk x; }
-
-#define ERR(x) { DEBUG_PROLOG; printk x; }
-
-#define DEB_S(x)    if (0!=(DEBUG_VARIABLE&0x01)) { DEBUG_PROLOG; printk x; } /* simple debug messages */
-#define DEB_D(x)    if (0!=(DEBUG_VARIABLE&0x02)) { DEBUG_PROLOG; printk x; } /* more detailed debug messages */
-#define DEB_EE(x)   if (0!=(DEBUG_VARIABLE&0x04)) { DEBUG_PROLOG; printk x; } /* print enter and exit of functions */
-#define DEB_I2C(x)  if (0!=(DEBUG_VARIABLE&0x08)) { DEBUG_PROLOG; printk x; } /* i2c debug messages */
-#define DEB_VBI(x)  if (0!=(DEBUG_VARIABLE&0x10)) { DEBUG_PROLOG; printk x; } /* vbi debug messages */
-#define DEB_INT(x)  if (0!=(DEBUG_VARIABLE&0x20)) { DEBUG_PROLOG; printk x; } /* interrupt debug messages */
-#define DEB_CAP(x)  if (0!=(DEBUG_VARIABLE&0x40)) { DEBUG_PROLOG; printk x; } /* capture debug messages */
+#define ERR(fmt, ...)  pr_err("%s: " fmt, __func__, ##__VA_ARGS__)
+
+#define _DBG(mask, fmt, ...)                                           \
+do {                                                                   \
+       if (DEBUG_VARIABLE & mask)                                      \
+               pr_debug("%s(): " fmt, __func__, ##__VA_ARGS__);        \
+} while (0)
+
+/* simple debug messages */
+#define DEB_S(fmt, ...)                _DBG(0x01, fmt, ##__VA_ARGS__)
+/* more detailed debug messages */
+#define DEB_D(fmt, ...)                _DBG(0x02, fmt, ##__VA_ARGS__)
+/* print enter and exit of functions */
+#define DEB_EE(fmt, ...)       _DBG(0x04, fmt, ##__VA_ARGS__)
+/* i2c debug messages */
+#define DEB_I2C(fmt, ...)      _DBG(0x08, fmt, ##__VA_ARGS__)
+/* vbi debug messages */
+#define DEB_VBI(fmt, ...)      _DBG(0x10, fmt, ##__VA_ARGS__)
+/* interrupt debug messages */
+#define DEB_INT(fmt, ...)      _DBG(0x20, fmt, ##__VA_ARGS__)
+/* capture debug messages */
+#define DEB_CAP(fmt, ...)      _DBG(0x40, fmt, ##__VA_ARGS__)
 
 #define SAA7146_ISR_CLEAR(x,y) \
        saa7146_write(x, ISR, (y));
index 63fd9d3db296aae685bc0672daadd9f4d703a92e..810a20928a2177fa8e6bdf1ffae6c929d1c78fc5 100644 (file)
@@ -212,9 +212,6 @@ enum {
        /* module sn9c20x: just ident 10000 */
        V4L2_IDENT_SN9C20X = 10000,
 
-       /* Siliconfile sensors: reserved range 10100 - 10199 */
-       V4L2_IDENT_NOON010PC30  = 10100,
-
        /* module cx231xx and cx25840 */
        V4L2_IDENT_CX2310X_AV = 23099, /* Integrated A/V decoder; not in '100 */
        V4L2_IDENT_CX23100    = 23100,
index 13fe4d744aba0563f6664996e584eb9998ab9ed3..eeb3df637144cd12ed16209ca07836c70364f36c 100644 (file)
@@ -65,14 +65,12 @@ struct v4l2_ctrl_ops {
   * @is_private: If set, then this control is private to its handler and it
   *            will not be added to any other handlers. Drivers can set
   *            this flag.
-  * @is_volatile: If set, then this control is volatile. This means that the
-  *            control's current value cannot be cached and needs to be
-  *            retrieved through the g_volatile_ctrl op. Drivers can set
-  *            this flag.
   * @is_auto:   If set, then this control selects whether the other cluster
   *            members are in 'automatic' mode or 'manual' mode. This is
   *            used for autogain/gain type clusters. Drivers should never
   *            set this flag directly.
+  * @has_volatiles: If set, then one or more members of the cluster are volatile.
+  *            Drivers should never touch this flag.
   * @manual_mode_value: If the is_auto flag is set, then this is the value
   *            of the auto control that determines if that control is in
   *            manual mode. So if the value of the auto control equals this
@@ -118,8 +116,8 @@ struct v4l2_ctrl {
 
        unsigned int is_new:1;
        unsigned int is_private:1;
-       unsigned int is_volatile:1;
        unsigned int is_auto:1;
+       unsigned int has_volatiles:1;
        unsigned int manual_mode_value:8;
 
        const struct v4l2_ctrl_ops *ops;
@@ -208,9 +206,6 @@ struct v4l2_ctrl_handler {
   *            must be NULL.
   * @is_private: If set, then this control is private to its handler and it
   *            will not be added to any other handlers.
-  * @is_volatile: If set, then this control is volatile. This means that the
-  *            control's current value cannot be cached and needs to be
-  *            retrieved through the g_volatile_ctrl op.
   */
 struct v4l2_ctrl_config {
        const struct v4l2_ctrl_ops *ops;
@@ -225,7 +220,6 @@ struct v4l2_ctrl_config {
        u32 menu_skip_mask;
        const char * const *qmenu;
        unsigned int is_private:1;
-       unsigned int is_volatile:1;
 };
 
 /** v4l2_ctrl_fill() - Fill in the control fields based on the control ID.
@@ -389,8 +383,7 @@ void v4l2_ctrl_cluster(unsigned ncontrols, struct v4l2_ctrl **controls);
   * @manual_val: The value for the first control in the cluster that equals the
   *            manual setting.
   * @set_volatile: If true, then all controls except the first auto control will
-  *            have is_volatile set to true. If false, then is_volatile will not
-  *            be touched.
+  *            be volatile.
   *
   * Use for control groups where one control selects some automatic feature and
   * the other controls are only active whenever the automatic feature is turned
index 6114007c8c744d053dd328a883f378e19bfd9681..83ae07e533507cd86546b0741dc34fa93cacf604 100644 (file)
  */
 #define V4L2_MBUS_MASTER                       (1 << 0)
 #define V4L2_MBUS_SLAVE                                (1 << 1)
-/* Which signal polarities it supports */
-/* Note: in BT.656 mode HSYNC and VSYNC are unused */
+/*
+ * Signal polarity flags
+ * Note: in BT.656 mode HSYNC, FIELD, and VSYNC are unused
+ * V4L2_MBUS_[HV]SYNC* flags should be also used for specifying
+ * configuration of hardware that uses [HV]REF signals
+ */
 #define V4L2_MBUS_HSYNC_ACTIVE_HIGH            (1 << 2)
 #define V4L2_MBUS_HSYNC_ACTIVE_LOW             (1 << 3)
 #define V4L2_MBUS_VSYNC_ACTIVE_HIGH            (1 << 4)
 #define V4L2_MBUS_PCLK_SAMPLE_FALLING          (1 << 7)
 #define V4L2_MBUS_DATA_ACTIVE_HIGH             (1 << 8)
 #define V4L2_MBUS_DATA_ACTIVE_LOW              (1 << 9)
+/* FIELD = 0/1 - Field1 (odd)/Field2 (even) */
+#define V4L2_MBUS_FIELD_EVEN_HIGH              (1 << 10)
+/* FIELD = 1/0 - Field1 (odd)/Field2 (even) */
+#define V4L2_MBUS_FIELD_EVEN_LOW               (1 << 11)
 
 /* Serial flags */
 /* How many lanes the client can use */
index f87472acbc5172ddb8fe1e8f10dae988c12ef37b..ea55c08eddfb04843a634430648f4c65fe79b76b 100644 (file)
@@ -75,7 +75,6 @@ struct vb2_mem_ops {
 
 struct vb2_plane {
        void                    *mem_priv;
-       int                     mapped:1;
 };
 
 /**
@@ -147,7 +146,6 @@ struct vb2_queue;
  * @done_entry:                entry on the list that stores all buffers ready to
  *                     be dequeued to userspace
  * @planes:            private per-plane information; do not change
- * @num_planes_mapped: number of mapped planes; do not change
  */
 struct vb2_buffer {
        struct v4l2_buffer      v4l2_buf;
@@ -164,7 +162,6 @@ struct vb2_buffer {
        struct list_head        done_entry;
 
        struct vb2_plane        planes[VIDEO_MAX_PLANES];
-       unsigned int            num_planes_mapped;
 };
 
 /**
@@ -199,19 +196,28 @@ struct vb2_buffer {
  *                     before userspace accesses the buffer; optional
  * @buf_cleanup:       called once before the buffer is freed; drivers may
  *                     perform any additional cleanup; optional
- * @start_streaming:   called once before entering 'streaming' state; enables
- *                     driver to receive buffers over buf_queue() callback
+ * @start_streaming:   called once to enter 'streaming' state; the driver may
+ *                     receive buffers with @buf_queue callback before
+ *                     @start_streaming is called; the driver gets the number
+ *                     of already queued buffers in count parameter; driver
+ *                     can return an error if hardware fails or not enough
+ *                     buffers has been queued, in such case all buffers that
+ *                     have been already given by the @buf_queue callback are
+ *                     invalidated.
  * @stop_streaming:    called when 'streaming' state must be disabled; driver
  *                     should stop any DMA transactions or wait until they
  *                     finish and give back all buffers it got from buf_queue()
  *                     callback; may use vb2_wait_for_all_buffers() function
  * @buf_queue:         passes buffer vb to the driver; driver may start
  *                     hardware operation on this buffer; driver should give
- *                     the buffer back by calling vb2_buffer_done() function
+ *                     the buffer back by calling vb2_buffer_done() function;
+ *                     it is allways called after calling STREAMON ioctl;
+ *                     might be called before start_streaming callback if user
+ *                     pre-queued buffers before calling STREAMON
  */
 struct vb2_ops {
        int (*queue_setup)(struct vb2_queue *q, unsigned int *num_buffers,
-                          unsigned int *num_planes, unsigned long sizes[],
+                          unsigned int *num_planes, unsigned int sizes[],
                           void *alloc_ctxs[]);
 
        void (*wait_prepare)(struct vb2_queue *q);
@@ -222,7 +228,7 @@ struct vb2_ops {
        int (*buf_finish)(struct vb2_buffer *vb);
        void (*buf_cleanup)(struct vb2_buffer *vb);
 
-       int (*start_streaming)(struct vb2_queue *q);
+       int (*start_streaming)(struct vb2_queue *q, unsigned int count);
        int (*stop_streaming)(struct vb2_queue *q);
 
        void (*buf_queue)(struct vb2_buffer *vb);
@@ -276,6 +282,7 @@ struct vb2_queue {
        wait_queue_head_t               done_wq;
 
        void                            *alloc_ctx[VIDEO_MAX_PLANES];
+       unsigned int                    plane_sizes[VIDEO_MAX_PLANES];
 
        unsigned int                    streaming:1;
 
index 7e6c68b23773b7d9fa237fbea8d84c085670a9ea..19ae1e3505678bb32aa810823d619b06b88993d4 100644 (file)
 #include <linux/dma-mapping.h>
 
 static inline dma_addr_t
-vb2_dma_contig_plane_paddr(struct vb2_buffer *vb, unsigned int plane_no)
+vb2_dma_contig_plane_dma_addr(struct vb2_buffer *vb, unsigned int plane_no)
 {
-       dma_addr_t *paddr = vb2_plane_cookie(vb, plane_no);
+       dma_addr_t *addr = vb2_plane_cookie(vb, plane_no);
 
-       return *paddr;
+       return *addr;
 }
 
 void *vb2_dma_contig_init_ctx(struct device *dev);
index e727555d4ee9bc479df54d32fc5b9e6ce9ac52cd..e86af08293a8217153b48a98a4802015376185db 100644 (file)
@@ -77,7 +77,7 @@ struct bt_power {
 #define BT_POWER_FORCE_ACTIVE_OFF 0
 #define BT_POWER_FORCE_ACTIVE_ON  1
 
-__attribute__((format (printf, 2, 3)))
+__printf(2, 3)
 int bt_printk(const char *level, const char *fmt, ...);
 
 #define BT_INFO(fmt, arg...)   bt_printk(KERN_INFO, pr_fmt(fmt), ##arg)
index 180231c5bbbe8335275aa4611467a31d0dcc8e3b..f91a1fb5da7ce470f44409af0cfb8fcae51fabf3 100644 (file)
@@ -134,6 +134,7 @@ struct inet_timewait_sock {
        struct inet_bind_bucket *tw_tb;
        struct hlist_node       tw_death_node;
 };
+#define tw_tclass tw_tos
 
 static inline void inet_twsk_add_node_rcu(struct inet_timewait_sock *tw,
                                      struct hlist_nulls_head *list)
index 3b5ac1fbff39f50c51e55b07bd743172d1a9e0e5..a366a8a1fe2380e92ce604a21d44e8e598e484f4 100644 (file)
@@ -486,7 +486,8 @@ extern int                  ip6_rcv_finish(struct sk_buff *skb);
 extern int                     ip6_xmit(struct sock *sk,
                                         struct sk_buff *skb,
                                         struct flowi6 *fl6,
-                                        struct ipv6_txoptions *opt);
+                                        struct ipv6_txoptions *opt,
+                                        int tclass);
 
 extern int                     ip6_nd_hdr(struct sock *sk,
                                           struct sk_buff *skb,
index 920997f1aff0ff11868f78fcd2bc5f31f41905d5..e991bd0a27afcaa87c4afcb5622188b9b5070f30 100644 (file)
@@ -53,12 +53,13 @@ int nf_log_bind_pf(u_int8_t pf, const struct nf_logger *logger);
 void nf_log_unbind_pf(u_int8_t pf);
 
 /* Calls the registered backend logging function */
+__printf(7, 8)
 void nf_log_packet(u_int8_t pf,
                   unsigned int hooknum,
                   const struct sk_buff *skb,
                   const struct net_device *in,
                   const struct net_device *out,
                   const struct nf_loginfo *li,
-                  const char *fmt, ...) __attribute__ ((format(printf,7,8)));
+                  const char *fmt, ...);
 
 #endif /* _NF_LOG_H */
index 5ac682f73d6389ab4fe4977fb183ab13044929b1..c6658bef7f328dc72f801503a6b982d5c5ce9e27 100644 (file)
@@ -76,8 +76,8 @@
                                        printk(KERN_DEBUG msg); } while (0)
 #else
 /* Validate arguments and do nothing */
-static inline void __attribute__ ((format (printf, 2, 3)))
-SOCK_DEBUG(struct sock *sk, const char *msg, ...)
+static inline __printf(2, 3)
+void SOCK_DEBUG(struct sock *sk, const char *msg, ...)
 {
 }
 #endif
index fe5b05177a2cb4fe9195cb2b95e4f1aca0242759..81aba3a73aa325a195da25bfb50a3a6d5782f0d7 100644 (file)
@@ -81,7 +81,11 @@ enum {
        IB_USER_VERBS_CMD_MODIFY_SRQ,
        IB_USER_VERBS_CMD_QUERY_SRQ,
        IB_USER_VERBS_CMD_DESTROY_SRQ,
-       IB_USER_VERBS_CMD_POST_SRQ_RECV
+       IB_USER_VERBS_CMD_POST_SRQ_RECV,
+       IB_USER_VERBS_CMD_OPEN_XRCD,
+       IB_USER_VERBS_CMD_CLOSE_XRCD,
+       IB_USER_VERBS_CMD_CREATE_XSRQ,
+       IB_USER_VERBS_CMD_OPEN_QP
 };
 
 /*
@@ -222,6 +226,21 @@ struct ib_uverbs_dealloc_pd {
        __u32 pd_handle;
 };
 
+struct ib_uverbs_open_xrcd {
+       __u64 response;
+       __u32 fd;
+       __u32 oflags;
+       __u64 driver_data[0];
+};
+
+struct ib_uverbs_open_xrcd_resp {
+       __u32 xrcd_handle;
+};
+
+struct ib_uverbs_close_xrcd {
+       __u32 xrcd_handle;
+};
+
 struct ib_uverbs_reg_mr {
        __u64 response;
        __u64 start;
@@ -404,6 +423,17 @@ struct ib_uverbs_create_qp {
        __u64 driver_data[0];
 };
 
+struct ib_uverbs_open_qp {
+       __u64 response;
+       __u64 user_handle;
+       __u32 pd_handle;
+       __u32 qpn;
+       __u8  qp_type;
+       __u8  reserved[7];
+       __u64 driver_data[0];
+};
+
+/* also used for open response */
 struct ib_uverbs_create_qp_resp {
        __u32 qp_handle;
        __u32 qpn;
@@ -648,11 +678,25 @@ struct ib_uverbs_create_srq {
        __u64 driver_data[0];
 };
 
+struct ib_uverbs_create_xsrq {
+       __u64 response;
+       __u64 user_handle;
+       __u32 srq_type;
+       __u32 pd_handle;
+       __u32 max_wr;
+       __u32 max_sge;
+       __u32 srq_limit;
+       __u32 reserved;
+       __u32 xrcd_handle;
+       __u32 cq_handle;
+       __u64 driver_data[0];
+};
+
 struct ib_uverbs_create_srq_resp {
        __u32 srq_handle;
        __u32 max_wr;
        __u32 max_sge;
-       __u32 reserved;
+       __u32 srqn;
 };
 
 struct ib_uverbs_modify_srq {
index 228be3e220d93738867943834c9ccbc7366d7076..bf5daafe8ecc09ca4d846906ed76c6599cdd1a53 100644 (file)
@@ -112,6 +112,7 @@ enum ib_device_cap_flags {
         */
        IB_DEVICE_UD_IP_CSUM            = (1<<18),
        IB_DEVICE_UD_TSO                = (1<<19),
+       IB_DEVICE_XRC                   = (1<<20),
        IB_DEVICE_MEM_MGT_EXTENSIONS    = (1<<21),
        IB_DEVICE_BLOCK_MULTICAST_LOOPBACK = (1<<22),
 };
@@ -207,6 +208,7 @@ enum ib_port_cap_flags {
        IB_PORT_SM_DISABLED                     = 1 << 10,
        IB_PORT_SYS_IMAGE_GUID_SUP              = 1 << 11,
        IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP       = 1 << 12,
+       IB_PORT_EXTENDED_SPEEDS_SUP             = 1 << 14,
        IB_PORT_CM_SUP                          = 1 << 16,
        IB_PORT_SNMP_TUNNEL_SUP                 = 1 << 17,
        IB_PORT_REINIT_SUP                      = 1 << 18,
@@ -415,7 +417,15 @@ enum ib_rate {
        IB_RATE_40_GBPS  = 7,
        IB_RATE_60_GBPS  = 8,
        IB_RATE_80_GBPS  = 9,
-       IB_RATE_120_GBPS = 10
+       IB_RATE_120_GBPS = 10,
+       IB_RATE_14_GBPS  = 11,
+       IB_RATE_56_GBPS  = 12,
+       IB_RATE_112_GBPS = 13,
+       IB_RATE_168_GBPS = 14,
+       IB_RATE_25_GBPS  = 15,
+       IB_RATE_100_GBPS = 16,
+       IB_RATE_200_GBPS = 17,
+       IB_RATE_300_GBPS = 18
 };
 
 /**
@@ -426,6 +436,13 @@ enum ib_rate {
  */
 int ib_rate_to_mult(enum ib_rate rate) __attribute_const__;
 
+/**
+ * ib_rate_to_mbps - Convert the IB rate enum to Mbps.
+ * For example, IB_RATE_2_5_GBPS will be converted to 2500.
+ * @rate: rate to convert.
+ */
+int ib_rate_to_mbps(enum ib_rate rate) __attribute_const__;
+
 /**
  * mult_to_ib_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate
  * enum.
@@ -522,6 +539,11 @@ enum ib_cq_notify_flags {
        IB_CQ_REPORT_MISSED_EVENTS      = 1 << 2,
 };
 
+enum ib_srq_type {
+       IB_SRQT_BASIC,
+       IB_SRQT_XRC
+};
+
 enum ib_srq_attr_mask {
        IB_SRQ_MAX_WR   = 1 << 0,
        IB_SRQ_LIMIT    = 1 << 1,
@@ -537,6 +559,14 @@ struct ib_srq_init_attr {
        void                  (*event_handler)(struct ib_event *, void *);
        void                   *srq_context;
        struct ib_srq_attr      attr;
+       enum ib_srq_type        srq_type;
+
+       union {
+               struct {
+                       struct ib_xrcd *xrcd;
+                       struct ib_cq   *cq;
+               } xrc;
+       } ext;
 };
 
 struct ib_qp_cap {
@@ -565,7 +595,11 @@ enum ib_qp_type {
        IB_QPT_UC,
        IB_QPT_UD,
        IB_QPT_RAW_IPV6,
-       IB_QPT_RAW_ETHERTYPE
+       IB_QPT_RAW_ETHERTYPE,
+       /* Save 8 for RAW_PACKET */
+       IB_QPT_XRC_INI = 9,
+       IB_QPT_XRC_TGT,
+       IB_QPT_MAX
 };
 
 enum ib_qp_create_flags {
@@ -579,6 +613,7 @@ struct ib_qp_init_attr {
        struct ib_cq           *send_cq;
        struct ib_cq           *recv_cq;
        struct ib_srq          *srq;
+       struct ib_xrcd         *xrcd;     /* XRC TGT QPs only */
        struct ib_qp_cap        cap;
        enum ib_sig_type        sq_sig_type;
        enum ib_qp_type         qp_type;
@@ -586,6 +621,13 @@ struct ib_qp_init_attr {
        u8                      port_num; /* special QP types only */
 };
 
+struct ib_qp_open_attr {
+       void                  (*event_handler)(struct ib_event *, void *);
+       void                   *qp_context;
+       u32                     qp_num;
+       enum ib_qp_type         qp_type;
+};
+
 enum ib_rnr_timeout {
        IB_RNR_TIMER_655_36 =  0,
        IB_RNR_TIMER_000_01 =  1,
@@ -770,6 +812,7 @@ struct ib_send_wr {
                        u32                             rkey;
                } fast_reg;
        } wr;
+       u32                     xrc_remote_srq_num;     /* XRC TGT QPs only */
 };
 
 struct ib_recv_wr {
@@ -831,6 +874,7 @@ struct ib_ucontext {
        struct list_head        qp_list;
        struct list_head        srq_list;
        struct list_head        ah_list;
+       struct list_head        xrcd_list;
        int                     closing;
 };
 
@@ -858,6 +902,15 @@ struct ib_pd {
        atomic_t                usecnt; /* count all resources */
 };
 
+struct ib_xrcd {
+       struct ib_device       *device;
+       atomic_t                usecnt; /* count all exposed resources */
+       struct inode           *inode;
+
+       struct mutex            tgt_qp_mutex;
+       struct list_head        tgt_qp_list;
+};
+
 struct ib_ah {
        struct ib_device        *device;
        struct ib_pd            *pd;
@@ -882,7 +935,16 @@ struct ib_srq {
        struct ib_uobject      *uobject;
        void                  (*event_handler)(struct ib_event *, void *);
        void                   *srq_context;
+       enum ib_srq_type        srq_type;
        atomic_t                usecnt;
+
+       union {
+               struct {
+                       struct ib_xrcd *xrcd;
+                       struct ib_cq   *cq;
+                       u32             srq_num;
+               } xrc;
+       } ext;
 };
 
 struct ib_qp {
@@ -891,6 +953,11 @@ struct ib_qp {
        struct ib_cq           *send_cq;
        struct ib_cq           *recv_cq;
        struct ib_srq          *srq;
+       struct ib_xrcd         *xrcd; /* XRC TGT QPs only */
+       struct list_head        xrcd_list;
+       atomic_t                usecnt; /* count times opened */
+       struct list_head        open_list;
+       struct ib_qp           *real_qp;
        struct ib_uobject      *uobject;
        void                  (*event_handler)(struct ib_event *, void *);
        void                   *qp_context;
@@ -1149,6 +1216,10 @@ struct ib_device {
                                                  struct ib_grh *in_grh,
                                                  struct ib_mad *in_mad,
                                                  struct ib_mad *out_mad);
+       struct ib_xrcd *           (*alloc_xrcd)(struct ib_device *device,
+                                                struct ib_ucontext *ucontext,
+                                                struct ib_udata *udata);
+       int                        (*dealloc_xrcd)(struct ib_xrcd *xrcd);
 
        struct ib_dma_mapping_ops   *dma_ops;
 
@@ -1442,6 +1513,25 @@ int ib_query_qp(struct ib_qp *qp,
  */
 int ib_destroy_qp(struct ib_qp *qp);
 
+/**
+ * ib_open_qp - Obtain a reference to an existing sharable QP.
+ * @xrcd - XRC domain
+ * @qp_open_attr: Attributes identifying the QP to open.
+ *
+ * Returns a reference to a sharable QP.
+ */
+struct ib_qp *ib_open_qp(struct ib_xrcd *xrcd,
+                        struct ib_qp_open_attr *qp_open_attr);
+
+/**
+ * ib_close_qp - Release an external reference to a QP.
+ * @qp: The QP handle to release
+ *
+ * The opened QP handle is released by the caller.  The underlying
+ * shared QP is not destroyed until all internal references are released.
+ */
+int ib_close_qp(struct ib_qp *qp);
+
 /**
  * ib_post_send - Posts a list of work requests to the send queue of
  *   the specified QP.
@@ -2060,4 +2150,16 @@ int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
  */
 int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
 
+/**
+ * ib_alloc_xrcd - Allocates an XRC domain.
+ * @device: The device on which to allocate the XRC domain.
+ */
+struct ib_xrcd *ib_alloc_xrcd(struct ib_device *device);
+
+/**
+ * ib_dealloc_xrcd - Deallocates an XRC domain.
+ * @xrcd: The XRC domain to deallocate.
+ */
+int ib_dealloc_xrcd(struct ib_xrcd *xrcd);
+
 #endif /* IB_VERBS_H */
index 2d0191c90f9eeda08da64fbbd0d9d6ba946442b7..1a046b1595ccd2ad4e24b78f8bb5647aadbee29b 100644 (file)
@@ -52,8 +52,10 @@ struct iw_cm_event {
        struct sockaddr_in local_addr;
        struct sockaddr_in remote_addr;
        void *private_data;
-       u8 private_data_len;
        void *provider_data;
+       u8 private_data_len;
+       u8 ord;
+       u8 ird;
 };
 
 /**
index 26977c149c414df2a9f166b3dcb9539f0aca6205..51988f8081812f8c0f55f2bae2ac03110a05eb29 100644 (file)
@@ -65,6 +65,7 @@ enum rdma_cm_event_type {
 enum rdma_port_space {
        RDMA_PS_SDP   = 0x0001,
        RDMA_PS_IPOIB = 0x0002,
+       RDMA_PS_IB    = 0x013F,
        RDMA_PS_TCP   = 0x0106,
        RDMA_PS_UDP   = 0x0111,
 };
index fc82c1896f751a0e9f1c94c6761433f7ac7a8ad6..5348a000c8f31f4472c6802afea665c4938ad01d 100644 (file)
@@ -77,7 +77,8 @@ struct rdma_ucm_create_id {
        __u64 uid;
        __u64 response;
        __u16 ps;
-       __u8  reserved[6];
+       __u8  qp_type;
+       __u8  reserved[5];
 };
 
 struct rdma_ucm_create_id_resp {
index ddb04568a50976195d228b83bed743d0d44ac39c..2703e3bedbf5694b5a2a1debeb2434f32fee8afa 100644 (file)
@@ -59,6 +59,7 @@ enum iscsi_uevent_e {
        ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST  = UEVENT_BASE + 19,
 
        ISCSI_UEVENT_PATH_UPDATE        = UEVENT_BASE + 20,
+       ISCSI_UEVENT_SET_IFACE_PARAMS   = UEVENT_BASE + 21,
 
        /* up events */
        ISCSI_KEVENT_RECV_PDU           = KEVENT_BASE + 1,
@@ -70,6 +71,7 @@ enum iscsi_uevent_e {
 
        ISCSI_KEVENT_PATH_REQ           = KEVENT_BASE + 7,
        ISCSI_KEVENT_IF_DOWN            = KEVENT_BASE + 8,
+       ISCSI_KEVENT_CONN_LOGIN_STATE   = KEVENT_BASE + 9,
 };
 
 enum iscsi_tgt_dscvr {
@@ -172,6 +174,10 @@ struct iscsi_uevent {
                struct msg_set_path {
                        uint32_t        host_no;
                } set_path;
+               struct msg_set_iface_params {
+                       uint32_t        host_no;
+                       uint32_t        count;
+               } set_iface_params;
        } u;
        union {
                /* messages k -> u */
@@ -193,6 +199,11 @@ struct iscsi_uevent {
                        uint32_t        cid;
                        uint64_t        recv_handle;
                } recv_req;
+               struct msg_conn_login {
+                       uint32_t        sid;
+                       uint32_t        cid;
+                       uint32_t        state; /* enum iscsi_conn_state */
+               } conn_login;
                struct msg_conn_error {
                        uint32_t        sid;
                        uint32_t        cid;
@@ -214,6 +225,21 @@ struct iscsi_uevent {
        } r;
 } __attribute__ ((aligned (sizeof(uint64_t))));
 
+enum iscsi_param_type {
+       ISCSI_PARAM,            /* iscsi_param (session, conn, target, LU) */
+       ISCSI_HOST_PARAM,       /* iscsi_host_param */
+       ISCSI_NET_PARAM,        /* iscsi_net_param */
+};
+
+struct iscsi_iface_param_info {
+       uint32_t iface_num;     /* iface number, 0 - n */
+       uint32_t len;           /* Actual length of the param */
+       uint16_t param;         /* iscsi param value */
+       uint8_t iface_type;     /* IPv4 or IPv6 */
+       uint8_t param_type;     /* iscsi_param_type */
+       uint8_t value[0];       /* length sized value follows */
+} __packed;
+
 /*
  * To keep the struct iscsi_uevent size the same for userspace code
  * compatibility, the main structure for ISCSI_UEVENT_PATH_UPDATE and
@@ -237,6 +263,71 @@ struct iscsi_path {
        uint16_t        pmtu;
 } __attribute__ ((aligned (sizeof(uint64_t))));
 
+/* iscsi iface enabled/disabled setting */
+#define ISCSI_IFACE_DISABLE    0x01
+#define ISCSI_IFACE_ENABLE     0x02
+
+/* ipv4 bootproto */
+#define ISCSI_BOOTPROTO_STATIC         0x01
+#define ISCSI_BOOTPROTO_DHCP           0x02
+
+/* ipv6 addr autoconfig type */
+#define ISCSI_IPV6_AUTOCFG_DISABLE             0x01
+#define ISCSI_IPV6_AUTOCFG_ND_ENABLE           0x02
+#define ISCSI_IPV6_AUTOCFG_DHCPV6_ENABLE       0x03
+
+/* ipv6 link local addr type */
+#define ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE    0x01
+#define ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE   0x02
+
+/* ipv6 router addr type */
+#define ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE       0x01
+#define ISCSI_IPV6_ROUTER_AUTOCFG_DISABLE      0x02
+
+#define ISCSI_IFACE_TYPE_IPV4          0x01
+#define ISCSI_IFACE_TYPE_IPV6          0x02
+
+#define ISCSI_MAX_VLAN_ID              4095
+#define ISCSI_MAX_VLAN_PRIORITY                7
+
+/* iscsi vlan enable/disabled setting */
+#define ISCSI_VLAN_DISABLE     0x01
+#define ISCSI_VLAN_ENABLE      0x02
+
+/* iSCSI network params */
+enum iscsi_net_param {
+       ISCSI_NET_PARAM_IPV4_ADDR               = 1,
+       ISCSI_NET_PARAM_IPV4_SUBNET             = 2,
+       ISCSI_NET_PARAM_IPV4_GW                 = 3,
+       ISCSI_NET_PARAM_IPV4_BOOTPROTO          = 4,
+       ISCSI_NET_PARAM_MAC                     = 5,
+       ISCSI_NET_PARAM_IPV6_LINKLOCAL          = 6,
+       ISCSI_NET_PARAM_IPV6_ADDR               = 7,
+       ISCSI_NET_PARAM_IPV6_ROUTER             = 8,
+       ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG       = 9,
+       ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG  = 10,
+       ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG     = 11,
+       ISCSI_NET_PARAM_IFACE_ENABLE            = 12,
+       ISCSI_NET_PARAM_VLAN_ID                 = 13,
+       ISCSI_NET_PARAM_VLAN_PRIORITY           = 14,
+       ISCSI_NET_PARAM_VLAN_ENABLED            = 15,
+       ISCSI_NET_PARAM_VLAN_TAG                = 16,
+       ISCSI_NET_PARAM_IFACE_TYPE              = 17,
+       ISCSI_NET_PARAM_IFACE_NAME              = 18,
+       ISCSI_NET_PARAM_MTU                     = 19,
+       ISCSI_NET_PARAM_PORT                    = 20,
+};
+
+enum iscsi_conn_state {
+       ISCSI_CONN_STATE_FREE,
+       ISCSI_CONN_STATE_XPT_WAIT,
+       ISCSI_CONN_STATE_IN_LOGIN,
+       ISCSI_CONN_STATE_LOGGED_IN,
+       ISCSI_CONN_STATE_IN_LOGOUT,
+       ISCSI_CONN_STATE_LOGOUT_REQUESTED,
+       ISCSI_CONN_STATE_CLEANUP_WAIT,
+};
+
 /*
  * Common error codes
  */
@@ -319,44 +410,6 @@ enum iscsi_param {
        ISCSI_PARAM_MAX,
 };
 
-#define ISCSI_MAX_RECV_DLENGTH         (1ULL << ISCSI_PARAM_MAX_RECV_DLENGTH)
-#define ISCSI_MAX_XMIT_DLENGTH         (1ULL << ISCSI_PARAM_MAX_XMIT_DLENGTH)
-#define ISCSI_HDRDGST_EN               (1ULL << ISCSI_PARAM_HDRDGST_EN)
-#define ISCSI_DATADGST_EN              (1ULL << ISCSI_PARAM_DATADGST_EN)
-#define ISCSI_INITIAL_R2T_EN           (1ULL << ISCSI_PARAM_INITIAL_R2T_EN)
-#define ISCSI_MAX_R2T                  (1ULL << ISCSI_PARAM_MAX_R2T)
-#define ISCSI_IMM_DATA_EN              (1ULL << ISCSI_PARAM_IMM_DATA_EN)
-#define ISCSI_FIRST_BURST              (1ULL << ISCSI_PARAM_FIRST_BURST)
-#define ISCSI_MAX_BURST                        (1ULL << ISCSI_PARAM_MAX_BURST)
-#define ISCSI_PDU_INORDER_EN           (1ULL << ISCSI_PARAM_PDU_INORDER_EN)
-#define ISCSI_DATASEQ_INORDER_EN       (1ULL << ISCSI_PARAM_DATASEQ_INORDER_EN)
-#define ISCSI_ERL                      (1ULL << ISCSI_PARAM_ERL)
-#define ISCSI_IFMARKER_EN              (1ULL << ISCSI_PARAM_IFMARKER_EN)
-#define ISCSI_OFMARKER_EN              (1ULL << ISCSI_PARAM_OFMARKER_EN)
-#define ISCSI_EXP_STATSN               (1ULL << ISCSI_PARAM_EXP_STATSN)
-#define ISCSI_TARGET_NAME              (1ULL << ISCSI_PARAM_TARGET_NAME)
-#define ISCSI_TPGT                     (1ULL << ISCSI_PARAM_TPGT)
-#define ISCSI_PERSISTENT_ADDRESS       (1ULL << ISCSI_PARAM_PERSISTENT_ADDRESS)
-#define ISCSI_PERSISTENT_PORT          (1ULL << ISCSI_PARAM_PERSISTENT_PORT)
-#define ISCSI_SESS_RECOVERY_TMO                (1ULL << ISCSI_PARAM_SESS_RECOVERY_TMO)
-#define ISCSI_CONN_PORT                        (1ULL << ISCSI_PARAM_CONN_PORT)
-#define ISCSI_CONN_ADDRESS             (1ULL << ISCSI_PARAM_CONN_ADDRESS)
-#define ISCSI_USERNAME                 (1ULL << ISCSI_PARAM_USERNAME)
-#define ISCSI_USERNAME_IN              (1ULL << ISCSI_PARAM_USERNAME_IN)
-#define ISCSI_PASSWORD                 (1ULL << ISCSI_PARAM_PASSWORD)
-#define ISCSI_PASSWORD_IN              (1ULL << ISCSI_PARAM_PASSWORD_IN)
-#define ISCSI_FAST_ABORT               (1ULL << ISCSI_PARAM_FAST_ABORT)
-#define ISCSI_ABORT_TMO                        (1ULL << ISCSI_PARAM_ABORT_TMO)
-#define ISCSI_LU_RESET_TMO             (1ULL << ISCSI_PARAM_LU_RESET_TMO)
-#define ISCSI_HOST_RESET_TMO           (1ULL << ISCSI_PARAM_HOST_RESET_TMO)
-#define ISCSI_PING_TMO                 (1ULL << ISCSI_PARAM_PING_TMO)
-#define ISCSI_RECV_TMO                 (1ULL << ISCSI_PARAM_RECV_TMO)
-#define ISCSI_IFACE_NAME               (1ULL << ISCSI_PARAM_IFACE_NAME)
-#define ISCSI_ISID                     (1ULL << ISCSI_PARAM_ISID)
-#define ISCSI_INITIATOR_NAME           (1ULL << ISCSI_PARAM_INITIATOR_NAME)
-#define ISCSI_TGT_RESET_TMO            (1ULL << ISCSI_PARAM_TGT_RESET_TMO)
-#define ISCSI_TARGET_ALIAS             (1ULL << ISCSI_PARAM_TARGET_ALIAS)
-
 /* iSCSI HBA params */
 enum iscsi_host_param {
        ISCSI_HOST_PARAM_HWADDRESS,
@@ -366,11 +419,6 @@ enum iscsi_host_param {
        ISCSI_HOST_PARAM_MAX,
 };
 
-#define ISCSI_HOST_HWADDRESS           (1ULL << ISCSI_HOST_PARAM_HWADDRESS)
-#define ISCSI_HOST_INITIATOR_NAME      (1ULL << ISCSI_HOST_PARAM_INITIATOR_NAME)
-#define ISCSI_HOST_NETDEV_NAME         (1ULL << ISCSI_HOST_PARAM_NETDEV_NAME)
-#define ISCSI_HOST_IPADDRESS           (1ULL << ISCSI_HOST_PARAM_IPADDRESS)
-
 #define iscsi_ptr(_handle) ((void*)(unsigned long)_handle)
 #define iscsi_handle(_ptr) ((uint64_t)(unsigned long)_ptr)
 
@@ -392,6 +440,7 @@ enum iscsi_host_param {
 #define CAP_DIGEST_OFFLOAD     0x1000  /* offload hdr and data digests */
 #define CAP_PADDING_OFFLOAD    0x2000  /* offload padding insertion, removal,
                                         and verification */
+#define CAP_LOGIN_OFFLOAD      0x4000  /* offload session login */
 
 /*
  * These flags describes reason of stop_conn() call
index 7d96829b0c003bc623c969f5e15f210e81f76d7d..5d1a758e05950a7669157914a15b6025da11a7cc 100644 (file)
@@ -281,9 +281,6 @@ struct fc_seq_els_data {
  * @timer:           The command timer
  * @tm_done:         Completion indicator
  * @wait_for_comp:   Indicator to wait for completion of the I/O (in jiffies)
- * @start_time:      Timestamp indicating the start of the I/O (in jiffies)
- * @end_time:        Timestamp indicating the end of the I/O (in jiffies)
- * @last_pkt_time:   Timestamp of the last frame received (in jiffies)
  * @data_len:        The length of the data
  * @cdb_cmd:         The CDB command
  * @xfer_len:        The transfer length
@@ -304,50 +301,46 @@ struct fc_seq_els_data {
  * @recov_seq:       The sequence for REC or SRR
  */
 struct fc_fcp_pkt {
-       /* Housekeeping information */
-       struct fc_lport   *lp;
-       u16               state;
-       atomic_t          ref_cnt;
        spinlock_t        scsi_pkt_lock;
+       atomic_t          ref_cnt;
+
+       /* SCSI command and data transfer information */
+       u32               data_len;
 
        /* SCSI I/O related information */
        struct scsi_cmnd  *cmd;
        struct list_head  list;
 
-       /* Timeout related information */
-       struct timer_list timer;
-       struct completion tm_done;
-       int               wait_for_comp;
-       unsigned long     start_time;
-       unsigned long     end_time;
-       unsigned long     last_pkt_time;
-
-       /* SCSI command and data transfer information */
-       u32               data_len;
-
-       /* Transport related veriables */
-       struct fcp_cmnd   cdb_cmd;
-       size_t            xfer_len;
-       u16               xfer_ddp;
-       u32               xfer_contig_end;
-       u16               max_payload;
+       /* Housekeeping information */
+       struct fc_lport   *lp;
+       u8                state;
 
        /* SCSI/FCP return status */
-       u32               io_status;
        u8                cdb_status;
        u8                status_code;
        u8                scsi_comp_flags;
+       u32               io_status;
        u32               req_flags;
        u32               scsi_resid;
 
+       /* Transport related veriables */
+       size_t            xfer_len;
+       struct fcp_cmnd   cdb_cmd;
+       u32               xfer_contig_end;
+       u16               max_payload;
+       u16               xfer_ddp;
+
        /* Associated structures */
        struct fc_rport   *rport;
        struct fc_seq     *seq_ptr;
 
-       /* Error Processing information */
-       u8                recov_retry;
+       /* Timeout/error related information */
+       struct timer_list timer;
+       int               wait_for_comp;
+       u32               recov_retry;
        struct fc_seq     *recov_seq;
-};
+       struct completion tm_done;
+} ____cacheline_aligned_in_smp;
 
 /*
  * Structure and function definitions for managing Fibre Channel Exchanges
@@ -413,35 +406,32 @@ struct fc_seq {
  *     sequence allocation
  */
 struct fc_exch {
+       spinlock_t          ex_lock;
+       atomic_t            ex_refcnt;
+       enum fc_class       class;
        struct fc_exch_mgr  *em;
        struct fc_exch_pool *pool;
-       u32                 state;
-       u16                 xid;
        struct list_head    ex_list;
-       spinlock_t          ex_lock;
-       atomic_t            ex_refcnt;
-       struct delayed_work timeout_work;
        struct fc_lport     *lp;
+       u32                 esb_stat;
+       u8                  state;
+       u8                  fh_type;
+       u8                  seq_id;
+       u8                  encaps;
+       u16                 xid;
        u16                 oxid;
        u16                 rxid;
        u32                 oid;
        u32                 sid;
        u32                 did;
-       u32                 esb_stat;
        u32                 r_a_tov;
-       u8                  seq_id;
-       u8                  encaps;
        u32                 f_ctl;
-       u8                  fh_type;
-       enum fc_class       class;
-       struct fc_seq       seq;
-
+       struct fc_seq       seq;
        void                (*resp)(struct fc_seq *, struct fc_frame *, void *);
        void                *arg;
-
        void                (*destructor)(struct fc_seq *, void *);
-
-};
+       struct delayed_work timeout_work;
+} ____cacheline_aligned_in_smp;
 #define        fc_seq_exch(sp) container_of(sp, struct fc_exch, seq)
 
 
index 8c1638b8c28e776b9261cd604a1036708a8f6933..d1e95c6ac7769b2d7e328eefddf8c6f4a3077010 100644 (file)
@@ -229,6 +229,11 @@ int fcoe_libfc_config(struct fc_lport *, struct fcoe_ctlr *,
                      const struct libfc_function_template *, int init_fcp);
 u32 fcoe_fc_crc(struct fc_frame *fp);
 int fcoe_start_io(struct sk_buff *skb);
+int fcoe_get_wwn(struct net_device *netdev, u64 *wwn, int type);
+void __fcoe_get_lesb(struct fc_lport *lport, struct fc_els_lesb *fc_lesb,
+                    struct net_device *netdev);
+void fcoe_wwn_to_str(u64 wwn, char *buf, int len);
+int fcoe_validate_vport_create(struct fc_vport *vport);
 
 /**
  * is_fip_mode() - returns true if FIP mode selected.
index ee866060f8a4d2c6441cba43d6c27a454bacf1ed..6a308d42d98f4ea4402203f9e6e216ce21b2821b 100644 (file)
@@ -142,8 +142,11 @@ struct expander_device {
        u16    ex_change_count;
        u16    max_route_indexes;
        u8     num_phys;
+
+       u8     t2t_supp:1;
        u8     configuring:1;
        u8     conf_route_table:1;
+
        u8     enclosure_logical_id[8];
 
        struct ex_phy *ex_phy;
@@ -386,6 +389,11 @@ sdev_to_domain_dev(struct scsi_device *sdev) {
        return starget_to_domain_dev(sdev->sdev_target);
 }
 
+static inline struct ata_device *sas_to_ata_dev(struct domain_device *dev)
+{
+       return &dev->sata_dev.ap->link.device[0];
+}
+
 static inline struct domain_device *
 cmd_to_domain_dev(struct scsi_cmnd *cmd)
 {
@@ -405,6 +413,20 @@ static inline void sas_phy_disconnected(struct asd_sas_phy *phy)
        phy->linkrate = SAS_LINK_RATE_UNKNOWN;
 }
 
+static inline unsigned int to_sas_gpio_od(int device, int bit)
+{
+       return 3 * device + bit;
+}
+
+#ifdef CONFIG_SCSI_SAS_HOST_SMP
+int try_test_sas_gpio_gp_bit(unsigned int od, u8 *data, u8 index, u8 count);
+#else
+static inline int try_test_sas_gpio_gp_bit(unsigned int od, u8 *data, u8 index, u8 count)
+{
+       return -1;
+}
+#endif
+
 /* ---------- Tasks ---------- */
 /*
       service_response |  SAS_TASK_COMPLETE  |  SAS_TASK_UNDELIVERED |
@@ -555,36 +577,14 @@ struct sas_task {
        struct work_struct abort_work;
 };
 
-extern struct kmem_cache *sas_task_cache;
-
 #define SAS_TASK_STATE_PENDING      1
 #define SAS_TASK_STATE_DONE         2
 #define SAS_TASK_STATE_ABORTED      4
 #define SAS_TASK_NEED_DEV_RESET     8
 #define SAS_TASK_AT_INITIATOR       16
 
-static inline struct sas_task *sas_alloc_task(gfp_t flags)
-{
-       struct sas_task *task = kmem_cache_zalloc(sas_task_cache, flags);
-
-       if (task) {
-               INIT_LIST_HEAD(&task->list);
-               spin_lock_init(&task->task_state_lock);
-               task->task_state_flags = SAS_TASK_STATE_PENDING;
-               init_timer(&task->timer);
-               init_completion(&task->completion);
-       }
-
-       return task;
-}
-
-static inline void sas_free_task(struct sas_task *task)
-{
-       if (task) {
-               BUG_ON(!list_empty(&task->list));
-               kmem_cache_free(sas_task_cache, task);
-       }
-}
+extern struct sas_task *sas_alloc_task(gfp_t flags);
+extern void sas_free_task(struct sas_task *task);
 
 struct sas_domain_function_template {
        /* The class calls these to notify the LLDD of an event. */
@@ -614,6 +614,10 @@ struct sas_domain_function_template {
 
        /* Phy management */
        int (*lldd_control_phy)(struct asd_sas_phy *, enum phy_func, void *);
+
+       /* GPIO support */
+       int (*lldd_write_gpio)(struct sas_ha_struct *, u8 reg_type,
+                              u8 reg_index, u8 reg_count, u8 *write_data);
 };
 
 extern int sas_register_ha(struct sas_ha_struct *);
@@ -652,7 +656,7 @@ int  sas_discover_event(struct asd_sas_port *, enum discover_event ev);
 int  sas_discover_sata(struct domain_device *);
 int  sas_discover_end_dev(struct domain_device *);
 
-void sas_unregister_dev(struct domain_device *);
+void sas_unregister_dev(struct asd_sas_port *port, struct domain_device *);
 
 void sas_init_dev(struct domain_device *);
 
index e9fd022813814145726c2296e459909de9ae3676..3673d685e6ad6fd0323f95d039b72230cd603055 100644 (file)
@@ -108,6 +108,7 @@ enum sas_protocol {
        SAS_PROTOCOL_STP                = 0x04,
        SAS_PROTOCOL_SSP                = 0x08,
        SAS_PROTOCOL_ALL                = 0x0E,
+       SAS_PROTOCOL_STP_ALL            = SAS_PROTOCOL_STP|SAS_PROTOCOL_SATA,
 };
 
 /* From the spec; local phys only */
@@ -121,6 +122,7 @@ enum phy_func {
        PHY_FUNC_TX_SATA_PS_SIGNAL,
        PHY_FUNC_RELEASE_SPINUP_HOLD = 0x10, /* LOCAL PORT ONLY! */
        PHY_FUNC_SET_LINK_RATE,
+       PHY_FUNC_GET_EVENTS,
 };
 
 /* SAS LLDD would need to report only _very_few_ of those, like BROADCAST.
@@ -195,6 +197,14 @@ enum sas_open_rej_reason {
        SAS_OREJ_RSVD_RETRY = 18,
 };
 
+enum sas_gpio_reg_type {
+       SAS_GPIO_REG_CFG   = 0,
+       SAS_GPIO_REG_RX    = 1,
+       SAS_GPIO_REG_RX_GP = 2,
+       SAS_GPIO_REG_TX    = 3,
+       SAS_GPIO_REG_TX_GP = 4,
+};
+
 struct  dev_to_host_fis {
        u8     fis_type;          /* 0x34 */
        u8     flags;
@@ -341,7 +351,12 @@ struct report_general_resp {
 
        u8      conf_route_table:1;
        u8      configuring:1;
-       u8      _r_b:6;
+       u8      config_others:1;
+       u8      orej_retry_supp:1;
+       u8      stp_cont_awt:1;
+       u8      self_config:1;
+       u8      zone_config:1;
+       u8      t2t_supp:1;
 
        u8      _r_c;
 
@@ -528,7 +543,12 @@ struct report_general_resp {
        u8      _r_a;
        u8      num_phys;
 
-       u8      _r_b:6;
+       u8      t2t_supp:1;
+       u8      zone_config:1;
+       u8      self_config:1;
+       u8      stp_cont_awt:1;
+       u8      orej_retry_supp:1;
+       u8      config_others:1;
        u8      configuring:1;
        u8      conf_route_table:1;
 
diff --git a/include/scsi/scsi_bsg_iscsi.h b/include/scsi/scsi_bsg_iscsi.h
new file mode 100644 (file)
index 0000000..fd5689d
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ *  iSCSI Transport BSG Interface
+ *
+ *  Copyright (C) 2009   James Smart, Emulex Corporation
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#ifndef SCSI_BSG_ISCSI_H
+#define SCSI_BSG_ISCSI_H
+
+/*
+ * This file intended to be included by both kernel and user space
+ */
+
+#include <scsi/scsi.h>
+
+/*
+ * iSCSI Transport SGIO v4 BSG Message Support
+ */
+
+/* Default BSG request timeout (in seconds) */
+#define ISCSI_DEFAULT_BSG_TIMEOUT      (10 * HZ)
+
+
+/*
+ * Request Message Codes supported by the iSCSI Transport
+ */
+
+/* define the class masks for the message codes */
+#define ISCSI_BSG_CLS_MASK     0xF0000000      /* find object class */
+#define ISCSI_BSG_HST_MASK     0x80000000      /* iscsi host class */
+
+/* iscsi host Message Codes */
+#define ISCSI_BSG_HST_VENDOR           (ISCSI_BSG_HST_MASK | 0x000000FF)
+
+
+/*
+ * iSCSI Host Messages
+ */
+
+/* ISCSI_BSG_HST_VENDOR : */
+
+/* Request:
+ * Note: When specifying vendor_id, be sure to read the Vendor Type and ID
+ *   formatting requirements specified in scsi_netlink.h
+ */
+struct iscsi_bsg_host_vendor {
+       /*
+        * Identifies the vendor that the message is formatted for. This
+        * should be the recipient of the message.
+        */
+       uint64_t vendor_id;
+
+       /* start of vendor command area */
+       uint32_t vendor_cmd[0];
+};
+
+/* Response:
+ */
+struct iscsi_bsg_host_vendor_reply {
+       /* start of vendor response area */
+       uint32_t vendor_rsp[0];
+};
+
+
+/* request (CDB) structure of the sg_io_v4 */
+struct iscsi_bsg_request {
+       uint32_t msgcode;
+       union {
+               struct iscsi_bsg_host_vendor    h_vendor;
+       } rqst_data;
+} __attribute__((packed));
+
+
+/* response (request sense data) structure of the sg_io_v4 */
+struct iscsi_bsg_reply {
+       /*
+        * The completion result. Result exists in two forms:
+        * if negative, it is an -Exxx system errno value. There will
+        * be no further reply information supplied.
+        * else, it's the 4-byte scsi error result, with driver, host,
+        * msg and status fields. The per-msgcode reply structure
+        * will contain valid data.
+        */
+       uint32_t result;
+
+       /* If there was reply_payload, how much was recevied ? */
+       uint32_t reply_payload_rcv_len;
+
+       union {
+               struct iscsi_bsg_host_vendor_reply      vendor_reply;
+       } reply_data;
+};
+
+
+#endif /* SCSI_BSG_ISCSI_H */
index d371c3ca90c3f167046db0c64e2bd2d6a54c2bae..5591ed54dc93ad67650c1dad43d0aae9b9b60b25 100644 (file)
@@ -197,6 +197,7 @@ struct scsi_device_handler {
        int (*activate)(struct scsi_device *, activate_complete, void *);
        int (*prep_fn)(struct scsi_device *, struct request *);
        int (*set_params)(struct scsi_device *, const char *);
+       bool (*match)(struct scsi_device *);
 };
 
 struct scsi_dh_data {
@@ -471,6 +472,11 @@ static inline int scsi_device_protection(struct scsi_device *sdev)
        return sdev->scsi_level > SCSI_2 && sdev->inquiry[5] & (1<<0);
 }
 
+static inline int scsi_device_tpgs(struct scsi_device *sdev)
+{
+       return sdev->inquiry ? (sdev->inquiry[5] >> 4) & 0x3 : 0;
+}
+
 #define MODULE_ALIAS_SCSI_DEVICE(type) \
        MODULE_ALIAS("scsi:t-" __stringify(type) "*")
 #define SCSI_DEVICE_MODALIAS_FMT "scsi:t-0x%02x"
index f1f2644137b87a1848403665ff396af423eb4398..50266c9405fced26eb7a48f386d1889c1f3a6253 100644 (file)
@@ -355,6 +355,19 @@ struct scsi_host_template {
         */
        enum blk_eh_timer_return (*eh_timed_out)(struct scsi_cmnd *);
 
+       /* This is an optional routine that allows transport to initiate
+        * LLD adapter or firmware reset using sysfs attribute.
+        *
+        * Return values: 0 on success, -ve value on failure.
+        *
+        * Status: OPTIONAL
+        */
+
+       int (*host_reset)(struct Scsi_Host *shost, int reset_type);
+#define SCSI_ADAPTER_RESET     1
+#define SCSI_FIRMWARE_RESET    2
+
+
        /*
         * Name of proc directory
         */
@@ -791,7 +804,8 @@ static inline struct device *scsi_get_device(struct Scsi_Host *shost)
  **/
 static inline int scsi_host_scan_allowed(struct Scsi_Host *shost)
 {
-       return shost->shost_state == SHOST_RUNNING;
+       return shost->shost_state == SHOST_RUNNING ||
+              shost->shost_state == SHOST_RECOVERY;
 }
 
 extern void scsi_unblock_requests(struct Scsi_Host *);
index bf8f529656755704970e4da850dd8624c1e159e7..5994bcc1b017932d8ccebc63dde12924272d2a04 100644 (file)
@@ -37,6 +37,8 @@ struct iscsi_cls_conn;
 struct iscsi_conn;
 struct iscsi_task;
 struct sockaddr;
+struct iscsi_iface;
+struct bsg_job;
 
 /**
  * struct iscsi_transport - iSCSI Transport template
@@ -84,9 +86,7 @@ struct iscsi_transport {
        struct module *owner;
        char *name;
        unsigned int caps;
-       /* LLD sets this to indicate what values it can export to sysfs */
-       uint64_t param_mask;
-       uint64_t host_param_mask;
+
        struct iscsi_cls_session *(*create_session) (struct iscsi_endpoint *ep,
                                        uint16_t cmds_max, uint16_t qdepth,
                                        uint32_t sn);
@@ -137,6 +137,13 @@ struct iscsi_transport {
        int (*tgt_dscvr) (struct Scsi_Host *shost, enum iscsi_tgt_dscvr type,
                          uint32_t enable, struct sockaddr *dst_addr);
        int (*set_path) (struct Scsi_Host *shost, struct iscsi_path *params);
+       int (*set_iface_param) (struct Scsi_Host *shost, void *data,
+                               uint32_t len);
+       int (*get_iface_param) (struct iscsi_iface *iface,
+                               enum iscsi_param_type param_type,
+                               int param, char *buf);
+       mode_t (*attr_is_visible)(int param_type, int param);
+       int (*bsg_request)(struct bsg_job *job);
 };
 
 /*
@@ -150,6 +157,8 @@ extern int iscsi_unregister_transport(struct iscsi_transport *tt);
  */
 extern void iscsi_conn_error_event(struct iscsi_cls_conn *conn,
                                   enum iscsi_err error);
+extern void iscsi_conn_login_event(struct iscsi_cls_conn *conn,
+                                  enum iscsi_conn_state state);
 extern int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
                          char *data, uint32_t data_size);
 
@@ -171,6 +180,9 @@ struct iscsi_cls_conn {
 #define iscsi_dev_to_conn(_dev) \
        container_of(_dev, struct iscsi_cls_conn, dev)
 
+#define transport_class_to_conn(_cdev) \
+       iscsi_dev_to_conn(_cdev->parent)
+
 #define iscsi_conn_to_session(_conn) \
        iscsi_dev_to_session(_conn->dev.parent)
 
@@ -197,6 +209,7 @@ struct iscsi_cls_session {
        struct delayed_work recovery_work;
 
        unsigned int target_id;
+       bool ida_used;
 
        int state;
        int sid;                                /* session id */
@@ -207,6 +220,9 @@ struct iscsi_cls_session {
 #define iscsi_dev_to_session(_dev) \
        container_of(_dev, struct iscsi_cls_session, dev)
 
+#define transport_class_to_session(_cdev) \
+       iscsi_dev_to_session(_cdev->parent)
+
 #define iscsi_session_to_shost(_session) \
        dev_to_shost(_session->dev.parent)
 
@@ -216,8 +232,12 @@ struct iscsi_cls_session {
 struct iscsi_cls_host {
        atomic_t nr_scans;
        struct mutex mutex;
+       struct request_queue *bsg_q;
 };
 
+#define iscsi_job_to_shost(_job) \
+        dev_to_shost(_job->dev)
+
 extern void iscsi_host_for_each_session(struct Scsi_Host *shost,
                                void (*fn)(struct iscsi_cls_session *));
 
@@ -228,6 +248,20 @@ struct iscsi_endpoint {
        struct iscsi_cls_conn *conn;
 };
 
+struct iscsi_iface {
+       struct device dev;
+       struct iscsi_transport *transport;
+       uint32_t iface_type;    /* IPv4 or IPv6 */
+       uint32_t iface_num;     /* iface number, 0 - n */
+       void *dd_data;          /* LLD private data */
+};
+
+#define iscsi_dev_to_iface(_dev) \
+       container_of(_dev, struct iscsi_iface, dev)
+
+#define iscsi_iface_to_shost(_iface) \
+       dev_to_shost(_iface->dev.parent)
+
 /*
  * session and connection functions that can be used by HW iSCSI LLDs
  */
@@ -238,6 +272,7 @@ struct iscsi_endpoint {
        dev_printk(prefix, &(_cls_conn)->dev, fmt, ##a)
 
 extern int iscsi_session_chkready(struct iscsi_cls_session *session);
+extern int iscsi_is_session_online(struct iscsi_cls_session *session);
 extern struct iscsi_cls_session *iscsi_alloc_session(struct Scsi_Host *shost,
                                struct iscsi_transport *transport, int dd_size);
 extern int iscsi_add_session(struct iscsi_cls_session *session,
@@ -261,5 +296,11 @@ extern struct iscsi_endpoint *iscsi_create_endpoint(int dd_size);
 extern void iscsi_destroy_endpoint(struct iscsi_endpoint *ep);
 extern struct iscsi_endpoint *iscsi_lookup_endpoint(u64 handle);
 extern int iscsi_block_scsi_eh(struct scsi_cmnd *cmd);
+extern struct iscsi_iface *iscsi_create_iface(struct Scsi_Host *shost,
+                                             struct iscsi_transport *t,
+                                             uint32_t iface_type,
+                                             uint32_t iface_num, int dd_size);
+extern void iscsi_destroy_iface(struct iscsi_iface *iface);
+extern struct iscsi_iface *iscsi_lookup_iface(int handle);
 
 #endif
diff --git a/include/sound/adau1373.h b/include/sound/adau1373.h
new file mode 100644 (file)
index 0000000..1b19c76
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Analog Devices ADAU1373 Audio Codec drive
+ *
+ * Copyright 2011 Analog Devices Inc.
+ * Author: Lars-Peter Clausen <lars@metafoo.de>
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#ifndef __SOUND_ADAU1373_H__
+#define __SOUND_ADAU1373_H__
+
+enum adau1373_micbias_voltage {
+       ADAU1373_MICBIAS_2_9V = 0,
+       ADAU1373_MICBIAS_2_2V = 1,
+       ADAU1373_MICBIAS_2_6V = 2,
+       ADAU1373_MICBIAS_1_8V = 3,
+};
+
+#define ADAU1373_DRC_SIZE 13
+
+struct adau1373_platform_data {
+       bool input_differential[4];
+       bool lineout_differential;
+       bool lineout_ground_sense;
+
+       unsigned int num_drc;
+       uint8_t drc_setting[3][ADAU1373_DRC_SIZE];
+
+       enum adau1373_micbias_voltage micbias1;
+       enum adau1373_micbias_voltage micbias2;
+};
+
+#endif
index 5d6074faa279adabd3f45c7adf792fa578913ebb..a2e4ff5ba9e9f12be58de88d38fdf0645289ca4b 100644 (file)
@@ -706,7 +706,7 @@ struct snd_timer_tread {
  *                                                                          *
  ****************************************************************************/
 
-#define SNDRV_CTL_VERSION              SNDRV_PROTOCOL_VERSION(2, 0, 6)
+#define SNDRV_CTL_VERSION              SNDRV_PROTOCOL_VERSION(2, 0, 7)
 
 struct snd_ctl_card_info {
        int card;                       /* card number */
@@ -803,6 +803,8 @@ struct snd_ctl_elem_info {
                        unsigned int items;     /* R: number of items */
                        unsigned int item;      /* W: item number */
                        char name[64];          /* R: value name */
+                       __u64 names_ptr;        /* W: names list (ELEM_ADD only) */
+                       unsigned int names_length;
                } enumerated;
                unsigned char reserved[128];
        } value;
index 1fa2407c966fdc5240d9853395fd22af6f435724..91d513879a7834043dfa6e7c591cc221bc60e571 100644 (file)
@@ -326,9 +326,9 @@ void release_and_free_resource(struct resource *res);
 /* --- */
 
 #if defined(CONFIG_SND_DEBUG) || defined(CONFIG_SND_VERBOSE_PRINTK)
+__printf(4, 5)
 void __snd_printk(unsigned int level, const char *file, int line,
-                 const char *format, ...)
-     __attribute__ ((format (printf, 4, 5)));
+                 const char *format, ...);
 #else
 #define __snd_printk(level, file, line, format, args...) \
        printk(format, ##args)
index 4e94cf1ff7621c65b83560eb5eb9fc428b23fef0..5492cc40dc575f07fc55028febe883d522d00bb3 100644 (file)
@@ -110,8 +110,8 @@ void snd_card_info_read_oss(struct snd_info_buffer *buffer);
 static inline void snd_card_info_read_oss(struct snd_info_buffer *buffer) {}
 #endif
 
-int snd_iprintf(struct snd_info_buffer *buffer, const char *fmt, ...) \
-                               __attribute__ ((format (printf, 2, 3)));
+__printf(2, 3)
+int snd_iprintf(struct snd_info_buffer *buffer, const char *fmt, ...);
 int snd_info_init(void);
 int snd_info_done(void);
 
index 1daa6dff82974e8db05bdb6b0c43ce9075cc4d6e..f99a0d2ddfe7b9e4e099fc386161be546a08fca4 100644 (file)
@@ -62,7 +62,7 @@ static int snd_legacy_find_free_irq(int *irq_table)
 {
        while (*irq_table != -1) {
                if (!request_irq(*irq_table, snd_legacy_empty_irq_handler,
-                                IRQF_DISABLED | IRQF_PROBE_SHARED, "ALSA Test IRQ",
+                                IRQF_PROBE_SHARED, "ALSA Test IRQ",
                                 (void *) irq_table)) {
                        free_irq(*irq_table, (void *) irq_table);
                        return *irq_table;
index c140fc7cbd3f276470a949c2701c9989e4f9a2f8..63c790742db47be586cd995cda581bfae9c33b80 100644 (file)
@@ -42,6 +42,7 @@ enum snd_jack_types {
        SND_JACK_MECHANICAL     = 0x0008, /* If detected separately */
        SND_JACK_VIDEOOUT       = 0x0010,
        SND_JACK_AVOUT          = SND_JACK_LINEOUT | SND_JACK_VIDEOOUT,
+       SND_JACK_LINEIN         = 0x0020,
 
        /* Kept separate from switches to facilitate implementation */
        SND_JACK_BTN_0          = 0x4000,
index 1f1d53f8830b55036dbf241bb38e227d8e121b5f..20230db00ef17095d899de2f9287ba9a5e1ff0e6 100644 (file)
 #define MPU401_INFO_INTEGRATED (1 << 2)        /* integrated h/w port */
 #define MPU401_INFO_MMIO       (1 << 3)        /* MMIO access */
 #define MPU401_INFO_TX_IRQ     (1 << 4)        /* independent TX irq */
+#define MPU401_INFO_IRQ_HOOK   (1 << 5)        /* mpu401 irq handler is called
+                                                  from driver irq handler */
 #define MPU401_INFO_NO_ACK     (1 << 6)        /* No ACK cmd needed */
+#define MPU401_INFO_USE_TIMER  (1 << 15)       /* internal */
 
 #define MPU401_MODE_BIT_INPUT          0
 #define MPU401_MODE_BIT_OUTPUT         1
@@ -73,8 +76,7 @@ struct snd_mpu401 {
        unsigned long port;             /* base port of MPU-401 chip */
        unsigned long cport;            /* port + 1 (usually) */
        struct resource *res;           /* port resource */
-       int irq;                        /* IRQ number of MPU-401 chip (-1 = poll) */
-       int irq_flags;
+       int irq;                        /* IRQ number of MPU-401 chip */
 
        unsigned long mode;             /* MPU401_MODE_XXXX */
        int timer_invoked;
@@ -131,7 +133,6 @@ int snd_mpu401_uart_new(struct snd_card *card,
                        unsigned long port,
                        unsigned int info_flags,
                        int irq,
-                       int irq_flags,
                        struct snd_rawmidi ** rrawmidi);
 
 #endif /* __SOUND_MPU401_H */
index 54cb079b7bf16b7a0b7057135d105ece7db0b986..0cf91b2f08caaf4f9a8a70cee07a25cacc108986 100644 (file)
@@ -825,6 +825,8 @@ int snd_pcm_hw_constraint_step(struct snd_pcm_runtime *runtime,
 int snd_pcm_hw_constraint_pow2(struct snd_pcm_runtime *runtime,
                               unsigned int cond,
                               snd_pcm_hw_param_t var);
+int snd_pcm_hw_rule_noresample(struct snd_pcm_runtime *runtime,
+                              unsigned int base_rate);
 int snd_pcm_hw_rule_add(struct snd_pcm_runtime *runtime,
                        unsigned int cond,
                        int var,
@@ -1035,6 +1037,8 @@ static inline void snd_pcm_mmap_data_close(struct vm_area_struct *area)
        atomic_dec(&substream->mmap_count);
 }
 
+int snd_pcm_lib_default_mmap(struct snd_pcm_substream *substream,
+                            struct vm_area_struct *area);
 /* mmap for io-memory area */
 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_ALPHA)
 #define SNDRV_PCM_INFO_MMAP_IOMEM      SNDRV_PCM_INFO_MMAP
diff --git a/include/sound/saif.h b/include/sound/saif.h
new file mode 100644 (file)
index 0000000..d0e0de7
--- /dev/null
@@ -0,0 +1,16 @@
+/*
+ * Copyright 2011 Freescale Semiconductor, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __SOUND_SAIF_H__
+#define __SOUND_SAIF_H__
+
+struct mxs_saif_platform_data {
+       int (*init) (void);
+       int (*get_master_id) (unsigned int saif_id);
+};
+#endif
index 3d9afb6a8c9cd86b5ead0d9ccccaa49614f47fd8..f352a98ce4f41927d7ec201a0336fee624fb008c 100644 (file)
@@ -75,9 +75,9 @@ struct snd_seq_port_callback {
 };
 
 /* interface for kernel client */
+__printf(3, 4)
 int snd_seq_create_kernel_client(struct snd_card *card, int client_index,
-                                const char *name_fmt, ...)
-       __attribute__ ((format (printf, 3, 4)));
+                                const char *name_fmt, ...);
 int snd_seq_delete_kernel_client(int client);
 int snd_seq_kernel_client_enqueue(int client, struct snd_seq_event *ev, int atomic, int hop);
 int snd_seq_kernel_client_dispatch(int client, struct snd_seq_event *ev, int atomic, int hop);
index 5ad5f3a50c68ec09122de85e2199c351f3ab9fd5..2413acc54883aad471cf0256b3fc2f8fc6d7ae11 100644 (file)
@@ -24,13 +24,13 @@ struct snd_pcm_substream;
  * Describes the physical PCM data formating and clocking. Add new formats
  * to the end.
  */
-#define SND_SOC_DAIFMT_I2S             0 /* I2S mode */
-#define SND_SOC_DAIFMT_RIGHT_J         1 /* Right Justified mode */
-#define SND_SOC_DAIFMT_LEFT_J          2 /* Left Justified mode */
-#define SND_SOC_DAIFMT_DSP_A           3 /* L data MSB after FRM LRC */
-#define SND_SOC_DAIFMT_DSP_B           4 /* L data MSB during FRM LRC */
-#define SND_SOC_DAIFMT_AC97            5 /* AC97 */
-#define SND_SOC_DAIFMT_PDM             6 /* Pulse density modulation */
+#define SND_SOC_DAIFMT_I2S             1 /* I2S mode */
+#define SND_SOC_DAIFMT_RIGHT_J         2 /* Right Justified mode */
+#define SND_SOC_DAIFMT_LEFT_J          3 /* Left Justified mode */
+#define SND_SOC_DAIFMT_DSP_A           4 /* L data MSB after FRM LRC */
+#define SND_SOC_DAIFMT_DSP_B           5 /* L data MSB during FRM LRC */
+#define SND_SOC_DAIFMT_AC97            6 /* AC97 */
+#define SND_SOC_DAIFMT_PDM             7 /* Pulse density modulation */
 
 /* left and right justified also known as MSB and LSB respectively */
 #define SND_SOC_DAIFMT_MSB             SND_SOC_DAIFMT_LEFT_J
@@ -42,8 +42,8 @@ struct snd_pcm_substream;
  * DAI bit clocks can be be gated (disabled) when the DAI is not
  * sending or receiving PCM data in a frame. This can be used to save power.
  */
-#define SND_SOC_DAIFMT_CONT            (0 << 4) /* continuous clock */
-#define SND_SOC_DAIFMT_GATED           (1 << 4) /* clock is gated */
+#define SND_SOC_DAIFMT_CONT            (1 << 4) /* continuous clock */
+#define SND_SOC_DAIFMT_GATED           (2 << 4) /* clock is gated */
 
 /*
  * DAI hardware signal inversions.
@@ -51,10 +51,10 @@ struct snd_pcm_substream;
  * Specifies whether the DAI can also support inverted clocks for the specified
  * format.
  */
-#define SND_SOC_DAIFMT_NB_NF           (0 << 8) /* normal bit clock + frame */
-#define SND_SOC_DAIFMT_NB_IF           (1 << 8) /* normal BCLK + inv FRM */
-#define SND_SOC_DAIFMT_IB_NF           (2 << 8) /* invert BCLK + nor FRM */
-#define SND_SOC_DAIFMT_IB_IF           (3 << 8) /* invert BCLK + FRM */
+#define SND_SOC_DAIFMT_NB_NF           (1 << 8) /* normal bit clock + frame */
+#define SND_SOC_DAIFMT_NB_IF           (2 << 8) /* normal BCLK + inv FRM */
+#define SND_SOC_DAIFMT_IB_NF           (3 << 8) /* invert BCLK + nor FRM */
+#define SND_SOC_DAIFMT_IB_IF           (4 << 8) /* invert BCLK + FRM */
 
 /*
  * DAI hardware clock masters.
@@ -63,10 +63,10 @@ struct snd_pcm_substream;
  * i.e. if the codec is clk and FRM master then the interface is
  * clk and frame slave.
  */
-#define SND_SOC_DAIFMT_CBM_CFM         (0 << 12) /* codec clk & FRM master */
-#define SND_SOC_DAIFMT_CBS_CFM         (1 << 12) /* codec clk slave & FRM master */
-#define SND_SOC_DAIFMT_CBM_CFS         (2 << 12) /* codec clk master & frame slave */
-#define SND_SOC_DAIFMT_CBS_CFS         (3 << 12) /* codec clk & FRM slave */
+#define SND_SOC_DAIFMT_CBM_CFM         (1 << 12) /* codec clk & FRM master */
+#define SND_SOC_DAIFMT_CBS_CFM         (2 << 12) /* codec clk slave & FRM master */
+#define SND_SOC_DAIFMT_CBM_CFS         (3 << 12) /* codec clk master & frame slave */
+#define SND_SOC_DAIFMT_CBS_CFS         (4 << 12) /* codec clk & FRM slave */
 
 #define SND_SOC_DAIFMT_FORMAT_MASK     0x000f
 #define SND_SOC_DAIFMT_CLOCK_MASK      0x00f0
@@ -242,6 +242,9 @@ struct snd_soc_dai {
        void *playback_dma_data;
        void *capture_dma_data;
 
+       /* Symmetry data - only valid if symmetry is being enforced */
+       unsigned int rate;
+
        /* parent platform/codec */
        union {
                struct snd_soc_platform *platform;
index e0583b7769cb505648f005be33f8b6c10f3c4049..17a4c17f19f5ff672030d448bb84ea5b3d8a354a 100644 (file)
@@ -381,6 +381,9 @@ int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
                                const char *pin);
 
+/* Mostly internal - should not normally be used */
+void dapm_mark_dirty(struct snd_soc_dapm_widget *w, const char *reason);
+
 /* dapm widget types */
 enum snd_soc_dapm_type {
        snd_soc_dapm_input = 0,         /* input pin */
@@ -473,6 +476,8 @@ struct snd_soc_dapm_widget {
        unsigned char ext:1;                    /* has external widgets */
        unsigned char force:1;                  /* force state */
        unsigned char ignore_suspend:1;         /* kept enabled over suspend */
+       unsigned char new_power:1;              /* power from this run */
+       unsigned char power_checked:1;          /* power checked this run */
        int subseq;                             /* sort within widget type */
 
        int (*power_check)(struct snd_soc_dapm_widget *w);
@@ -492,6 +497,9 @@ struct snd_soc_dapm_widget {
 
        /* used during DAPM updates */
        struct list_head power_list;
+       struct list_head dirty;
+       int inputs;
+       int outputs;
 };
 
 struct snd_soc_dapm_update {
@@ -524,6 +532,8 @@ struct snd_soc_dapm_context {
        enum snd_soc_bias_level target_bias_level;
        struct list_head list;
 
+       int (*stream_event)(struct snd_soc_dapm_context *dapm, int event);
+
 #ifdef CONFIG_DEBUG_FS
        struct dentry *debugfs_dapm;
 #endif
@@ -535,4 +545,10 @@ struct snd_soc_dapm_widget_list {
        struct snd_soc_dapm_widget *widgets[0];
 };
 
+struct snd_soc_dapm_stats {
+       int power_checks;
+       int path_checks;
+       int neighbour_checks;
+};
+
 #endif
index aa19f5a32ba8774a085a085d52866ede8d63fd3f..11cfb5953e06eb82c22f52319aa2c4ea31d7f99a 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/workqueue.h>
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
+#include <linux/regmap.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/control.h>
 /*
  * Convenience kcontrol builders
  */
-#define SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) \
+#define SOC_DOUBLE_VALUE(xreg, shift_left, shift_right, xmax, xinvert) \
        ((unsigned long)&(struct soc_mixer_control) \
-       {.reg = xreg, .shift = xshift, .rshift = xshift, .max = xmax, \
-       .platform_max = xmax, .invert = xinvert})
+       {.reg = xreg, .rreg = xreg, .shift = shift_left, \
+       .rshift = shift_right, .max = xmax, .platform_max = xmax, \
+       .invert = xinvert})
+#define SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) \
+       SOC_DOUBLE_VALUE(xreg, xshift, xshift, xmax, xinvert)
 #define SOC_SINGLE_VALUE_EXT(xreg, xmax, xinvert) \
        ((unsigned long)&(struct soc_mixer_control) \
        {.reg = xreg, .max = xmax, .platform_max = xmax, .invert = xinvert})
+#define SOC_DOUBLE_R_VALUE(xlreg, xrreg, xshift, xmax, xinvert) \
+       ((unsigned long)&(struct soc_mixer_control) \
+       {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \
+       .max = xmax, .platform_max = xmax, .invert = xinvert})
 #define SOC_SINGLE(xname, reg, shift, max, invert) \
 {      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
        .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
        .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
        .put = snd_soc_put_volsw, \
        .private_value =  SOC_SINGLE_VALUE(reg, shift, max, invert) }
-#define SOC_DOUBLE(xname, xreg, shift_left, shift_right, xmax, xinvert) \
+#define SOC_DOUBLE(xname, reg, shift_left, shift_right, max, invert) \
 {      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
        .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
        .put = snd_soc_put_volsw, \
-       .private_value = (unsigned long)&(struct soc_mixer_control) \
-               {.reg = xreg, .shift = shift_left, .rshift = shift_right, \
-                .max = xmax, .platform_max = xmax, .invert = xinvert} }
+       .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
+                                         max, invert) }
 #define SOC_DOUBLE_R(xname, reg_left, reg_right, xshift, xmax, xinvert) \
 {      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
-       .info = snd_soc_info_volsw_2r, \
-       .get = snd_soc_get_volsw_2r, .put = snd_soc_put_volsw_2r, \
-       .private_value = (unsigned long)&(struct soc_mixer_control) \
-               {.reg = reg_left, .rreg = reg_right, .shift = xshift, \
-               .max = xmax, .platform_max = xmax, .invert = xinvert} }
-#define SOC_DOUBLE_TLV(xname, xreg, shift_left, shift_right, xmax, xinvert, tlv_array) \
+       .info = snd_soc_info_volsw, \
+       .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
+       .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
+                                           xmax, xinvert) }
+#define SOC_DOUBLE_TLV(xname, reg, shift_left, shift_right, max, invert, tlv_array) \
 {      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
        .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
                 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
        .tlv.p = (tlv_array), \
        .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
        .put = snd_soc_put_volsw, \
-       .private_value = (unsigned long)&(struct soc_mixer_control) \
-               {.reg = xreg, .shift = shift_left, .rshift = shift_right,\
-                .max = xmax, .platform_max = xmax, .invert = xinvert} }
+       .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
+                                         max, invert) }
 #define SOC_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert, tlv_array) \
 {      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
        .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
                 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
        .tlv.p = (tlv_array), \
-       .info = snd_soc_info_volsw_2r, \
-       .get = snd_soc_get_volsw_2r, .put = snd_soc_put_volsw_2r, \
-       .private_value = (unsigned long)&(struct soc_mixer_control) \
-               {.reg = reg_left, .rreg = reg_right, .shift = xshift, \
-               .max = xmax, .platform_max = xmax, .invert = xinvert} }
+       .info = snd_soc_info_volsw, \
+       .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
+       .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
+                                           xmax, xinvert) }
 #define SOC_DOUBLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \
 {      .iface  = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
        .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
        .info = snd_soc_info_volsw, \
        .get = xhandler_get, .put = xhandler_put, \
        .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) }
-#define SOC_DOUBLE_EXT(xname, xreg, shift_left, shift_right, xmax, xinvert,\
+#define SOC_DOUBLE_EXT(xname, reg, shift_left, shift_right, max, invert,\
         xhandler_get, xhandler_put) \
 {      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
        .info = snd_soc_info_volsw, \
        .get = xhandler_get, .put = xhandler_put, \
-       .private_value = (unsigned long)&(struct soc_mixer_control) \
-               {.reg = xreg, .shift = shift_left, .rshift = shift_right, \
-                .max = xmax, .platform_max = xmax, .invert = xinvert} }
+       .private_value = \
+               SOC_DOUBLE_VALUE(reg, shift_left, shift_right, max, invert) }
 #define SOC_SINGLE_EXT_TLV(xname, xreg, xshift, xmax, xinvert,\
         xhandler_get, xhandler_put, tlv_array) \
 {      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
        .tlv.p = (tlv_array), \
        .info = snd_soc_info_volsw, \
        .get = xhandler_get, .put = xhandler_put, \
-       .private_value = (unsigned long)&(struct soc_mixer_control) \
-               {.reg = xreg, .shift = shift_left, .rshift = shift_right, \
-               .max = xmax, .platform_max = xmax, .invert = xinvert} }
+       .private_value = SOC_DOUBLE_VALUE(xreg, shift_left, shift_right, \
+                                         xmax, xinvert) }
 #define SOC_DOUBLE_R_EXT_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert,\
         xhandler_get, xhandler_put, tlv_array) \
 {      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
        .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
                 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
        .tlv.p = (tlv_array), \
-       .info = snd_soc_info_volsw_2r, \
+       .info = snd_soc_info_volsw, \
        .get = xhandler_get, .put = xhandler_put, \
-       .private_value = (unsigned long)&(struct soc_mixer_control) \
-               {.reg = reg_left, .rreg = reg_right, .shift = xshift, \
-               .max = xmax, .platform_max = xmax, .invert = xinvert} }
+       .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
+                                           xmax, xinvert) }
 #define SOC_SINGLE_BOOL_EXT(xname, xdata, xhandler_get, xhandler_put) \
 {      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
        .info = snd_soc_info_bool_ext, \
@@ -260,6 +261,7 @@ extern struct snd_ac97_bus_ops soc_ac97_ops;
 enum snd_soc_control_type {
        SND_SOC_I2C = 1,
        SND_SOC_SPI,
+       SND_SOC_REGMAP,
 };
 
 enum snd_soc_compress_type {
@@ -274,7 +276,7 @@ enum snd_soc_pcm_subclass {
 };
 
 int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
-                            unsigned int freq, int dir);
+                            int source, unsigned int freq, int dir);
 int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
                          unsigned int freq_in, unsigned int freq_out);
 
@@ -391,12 +393,8 @@ int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
        struct snd_ctl_elem_value *ucontrol);
 int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
        struct snd_ctl_elem_value *ucontrol);
-int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
-       struct snd_ctl_elem_info *uinfo);
-int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
-       struct snd_ctl_elem_value *ucontrol);
-int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
-       struct snd_ctl_elem_value *ucontrol);
+#define snd_soc_get_volsw_2r snd_soc_get_volsw
+#define snd_soc_put_volsw_2r snd_soc_put_volsw
 int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
        struct snd_ctl_elem_info *uinfo);
 int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
@@ -576,9 +574,11 @@ struct snd_soc_codec {
        const void *reg_def_copy;
        const struct snd_soc_cache_ops *cache_ops;
        struct mutex cache_rw_mutex;
+       int val_bytes;
 
        /* dapm */
        struct snd_soc_dapm_context dapm;
+       unsigned int ignore_pmdown_time:1; /* pmdown_time is ignored at stop */
 
 #ifdef CONFIG_DEBUG_FS
        struct dentry *debugfs_codec_root;
@@ -607,7 +607,7 @@ struct snd_soc_codec_driver {
 
        /* codec wide operations */
        int (*set_sysclk)(struct snd_soc_codec *codec,
-                         int clk_id, unsigned int freq, int dir);
+                         int clk_id, int source, unsigned int freq, int dir);
        int (*set_pll)(struct snd_soc_codec *codec, int pll_id, int source,
                unsigned int freq_in, unsigned int freq_out);
 
@@ -619,7 +619,7 @@ struct snd_soc_codec_driver {
        int (*volatile_register)(struct snd_soc_codec *, unsigned int);
        int (*readable_register)(struct snd_soc_codec *, unsigned int);
        int (*writable_register)(struct snd_soc_codec *, unsigned int);
-       short reg_cache_size;
+       unsigned int reg_cache_size;
        short reg_cache_step;
        short reg_word_size;
        const void *reg_cache_default;
@@ -630,10 +630,14 @@ struct snd_soc_codec_driver {
        /* codec bias level */
        int (*set_bias_level)(struct snd_soc_codec *,
                              enum snd_soc_bias_level level);
+       bool idle_bias_off;
 
        void (*seq_notifier)(struct snd_soc_dapm_context *,
                             enum snd_soc_dapm_type, int);
 
+       /* codec stream completion event */
+       int (*stream_event)(struct snd_soc_dapm_context *dapm, int event);
+
        /* probe ordering - for components with runtime dependencies */
        int probe_order;
        int remove_order;
@@ -669,6 +673,9 @@ struct snd_soc_platform_driver {
        /* platform stream ops */
        struct snd_pcm_ops *ops;
 
+       /* platform stream completion event */
+       int (*stream_event)(struct snd_soc_dapm_context *dapm, int event);
+
        /* probe ordering - for components with runtime dependencies */
        int probe_order;
        int remove_order;
@@ -703,6 +710,8 @@ struct snd_soc_dai_link {
        const char *cpu_dai_name;
        const char *codec_dai_name;
 
+       unsigned int dai_fmt;           /* format to set on init */
+
        /* Keep DAI active over suspend */
        unsigned int ignore_suspend:1;
 
@@ -815,9 +824,11 @@ struct snd_soc_card {
        struct list_head widgets;
        struct list_head paths;
        struct list_head dapm_list;
+       struct list_head dapm_dirty;
 
        /* Generic DAPM context for the card */
        struct snd_soc_dapm_context dapm;
+       struct snd_soc_dapm_stats dapm_stats;
 
 #ifdef CONFIG_DEBUG_FS
        struct dentry *debugfs_card_root;
@@ -840,8 +851,6 @@ struct snd_soc_pcm_runtime  {
        unsigned int complete:1;
        unsigned int dev_registered:1;
 
-       /* Symmetry data - only valid if symmetry is being enforced */
-       unsigned int rate;
        long pmdown_time;
 
        /* runtime devices */
@@ -936,6 +945,18 @@ static inline void snd_soc_initialize_card_lists(struct snd_soc_card *card)
        INIT_LIST_HEAD(&card->dapm_list);
 }
 
+static inline bool snd_soc_volsw_is_stereo(struct soc_mixer_control *mc)
+{
+       if (mc->reg == mc->rreg && mc->shift == mc->rshift)
+               return 0;
+       /*
+        * mc->reg == mc->rreg && mc->shift != mc->rshift, or
+        * mc->reg != mc->rreg means that the control is
+        * stereo (bits in one register or in two registers)
+        */
+       return 1;
+}
+
 int snd_soc_util_init(void);
 void snd_soc_util_exit(void);
 
index 89beccb57edd578bfdf2f8d460204f71e4ea80b4..4cc1093844c8a8c319c4ade6e7d0e60b795c2642 100644 (file)
 #ifndef TPA6130A2_PLAT_H
 #define TPA6130A2_PLAT_H
 
-enum tpa_model {
-       TPA6130A2,
-       TPA6140A2,
-};
-
 struct tpa6130a2_platform_data {
-       enum tpa_model id;
        int power_gpio;
 };
 
diff --git a/include/sound/wm1250-ev1.h b/include/sound/wm1250-ev1.h
new file mode 100644 (file)
index 0000000..7dff828
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * linux/sound/wm1250-ev1.h - Platform data for WM1250-EV1
+ *
+ * Copyright 2011 Wolfson Microelectronics. PLC.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __LINUX_SND_WM1250_EV1_H
+#define __LINUX_SND_WM1250_EV1_H
+
+#define WM1250_EV1_NUM_GPIOS 5
+
+#define WM1250_EV1_GPIO_CLK_ENA  0
+#define WM1250_EV1_GPIO_CLK_SEL0 1
+#define WM1250_EV1_GPIO_CLK_SEL1 2
+#define WM1250_EV1_GPIO_OSR      3
+#define WM1250_EV1_GPIO_MASTER   4
+
+
+struct wm1250_ev1_pdata {
+       int gpios[WM1250_EV1_NUM_GPIOS];
+};
+
+#endif
diff --git a/include/sound/wm5100.h b/include/sound/wm5100.h
new file mode 100644 (file)
index 0000000..617d0c4
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * linux/sound/wm5100.h -- Platform data for WM5100
+ *
+ * Copyright 2011 Wolfson Microelectronics. PLC.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __LINUX_SND_WM5100_H
+#define __LINUX_SND_WM5100_H
+
+enum wm5100_in_mode {
+       WM5100_IN_SE = 0,
+       WM5100_IN_DIFF = 1,
+       WM5100_IN_DMIC = 2,
+};
+
+enum wm5100_dmic_sup {
+       WM5100_DMIC_SUP_MICVDD = 0,
+       WM5100_DMIC_SUP_MICBIAS1 = 1,
+       WM5100_DMIC_SUP_MICBIAS2 = 2,
+       WM5100_DMIC_SUP_MICBIAS3 = 3,
+};
+
+enum wm5100_micdet_bias {
+       WM5100_MICDET_MICBIAS1 = 0,
+       WM5100_MICDET_MICBIAS2 = 1,
+       WM5100_MICDET_MICBIAS3 = 2,
+};
+
+struct wm5100_jack_mode {
+       enum wm5100_micdet_bias bias;
+       int hp_pol;
+       int micd_src;
+};
+
+#define WM5100_GPIO_SET 0x10000
+
+struct wm5100_pdata {
+       int reset;      /** GPIO controlling /RESET, if any */
+       int ldo_ena;    /** GPIO controlling LODENA, if any */
+       int hp_pol;     /** GPIO controlling headset polarity, if any */
+       int irq_flags;
+       int gpio_base;
+
+       struct wm5100_jack_mode jack_modes[2];
+
+       /* Input pin mode selection */
+       enum wm5100_in_mode in_mode[4];
+
+       /* DMIC supply selection */
+       enum wm5100_dmic_sup dmic_sup[4];
+
+       int gpio_defaults[6];
+};
+
+#endif
index 603f5a0f0365019eb758d2d2aec492a1b8f89b6c..ab26f8aa3c781819ca442268acf5b9f81ff8d6c7 100644 (file)
@@ -216,6 +216,31 @@ DEFINE_EVENT(snd_soc_dapm_widget, snd_soc_dapm_widget_event_done,
 
 );
 
+TRACE_EVENT(snd_soc_dapm_walk_done,
+
+       TP_PROTO(struct snd_soc_card *card),
+
+       TP_ARGS(card),
+
+       TP_STRUCT__entry(
+               __string(       name,   card->name              )
+               __field(        int,    power_checks            )
+               __field(        int,    path_checks             )
+               __field(        int,    neighbour_checks        )
+       ),
+
+       TP_fast_assign(
+               __assign_str(name, card->name);
+               __entry->power_checks = card->dapm_stats.power_checks;
+               __entry->path_checks = card->dapm_stats.path_checks;
+               __entry->neighbour_checks = card->dapm_stats.neighbour_checks;
+       ),
+
+       TP_printk("%s: checks %d power, %d path, %d neighbour",
+                 __get_str(name), (int)__entry->power_checks,
+                 (int)__entry->path_checks, (int)__entry->neighbour_checks)
+);
+
 TRACE_EVENT(snd_soc_jack_irq,
 
        TP_PROTO(const char *name),
index 36851f7f13daf558107d0df16052f5d8939bd1d1..edc4b3d25a2d4e38917c83554eccd23a32fc8815 100644 (file)
@@ -266,7 +266,7 @@ DECLARE_EVENT_CLASS(mm_vmscan_lru_isolate_template,
                unsigned long nr_lumpy_taken,
                unsigned long nr_lumpy_dirty,
                unsigned long nr_lumpy_failed,
-               int isolate_mode),
+               isolate_mode_t isolate_mode),
 
        TP_ARGS(order, nr_requested, nr_scanned, nr_taken, nr_lumpy_taken, nr_lumpy_dirty, nr_lumpy_failed, isolate_mode),
 
@@ -278,7 +278,7 @@ DECLARE_EVENT_CLASS(mm_vmscan_lru_isolate_template,
                __field(unsigned long, nr_lumpy_taken)
                __field(unsigned long, nr_lumpy_dirty)
                __field(unsigned long, nr_lumpy_failed)
-               __field(int, isolate_mode)
+               __field(isolate_mode_t, isolate_mode)
        ),
 
        TP_fast_assign(
@@ -312,7 +312,7 @@ DEFINE_EVENT(mm_vmscan_lru_isolate_template, mm_vmscan_lru_isolate,
                unsigned long nr_lumpy_taken,
                unsigned long nr_lumpy_dirty,
                unsigned long nr_lumpy_failed,
-               int isolate_mode),
+               isolate_mode_t isolate_mode),
 
        TP_ARGS(order, nr_requested, nr_scanned, nr_taken, nr_lumpy_taken, nr_lumpy_dirty, nr_lumpy_failed, isolate_mode)
 
@@ -327,7 +327,7 @@ DEFINE_EVENT(mm_vmscan_lru_isolate_template, mm_vmscan_memcg_isolate,
                unsigned long nr_lumpy_taken,
                unsigned long nr_lumpy_dirty,
                unsigned long nr_lumpy_failed,
-               int isolate_mode),
+               isolate_mode_t isolate_mode),
 
        TP_ARGS(order, nr_requested, nr_scanned, nr_taken, nr_lumpy_taken, nr_lumpy_dirty, nr_lumpy_failed, isolate_mode)
 
diff --git a/include/video/omap-panel-dvi.h b/include/video/omap-panel-dvi.h
new file mode 100644 (file)
index 0000000..87ad567
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Header for DVI output driver
+ *
+ * Copyright (C) 2011 Texas Instruments Inc
+ * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __OMAP_PANEL_DVI_H
+#define __OMAP_PANEL_DVI_H
+
+struct omap_dss_device;
+
+/**
+ * struct panel_dvi_platform_data - panel driver configuration data
+ * @platform_enable: platform specific panel enable function
+ * @platform_disable: platform specific panel disable function
+ * @i2c_bus_num: i2c bus id for the panel
+ */
+struct panel_dvi_platform_data {
+       int (*platform_enable)(struct omap_dss_device *dssdev);
+       void (*platform_disable)(struct omap_dss_device *dssdev);
+       u16 i2c_bus_num;
+};
+
+#endif /* __OMAP_PANEL_DVI_H */
diff --git a/include/video/omap-panel-n8x0.h b/include/video/omap-panel-n8x0.h
new file mode 100644 (file)
index 0000000..50a1302
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef __OMAP_PANEL_N8X0_H
+#define __OMAP_PANEL_N8X0_H
+
+struct omap_dss_device;
+
+struct panel_n8x0_data {
+       int (*platform_enable)(struct omap_dss_device *dssdev);
+       void (*platform_disable)(struct omap_dss_device *dssdev);
+       int panel_reset;
+       int ctrl_pwrdown;
+
+       int (*set_backlight)(struct omap_dss_device *dssdev, int level);
+};
+
+#endif
index 921ae9327228cb7592b1f908fc4de2ed3eba4192..7dc71f9c13e6a2eece19e6f7c956f5a7048e5631 100644 (file)
@@ -10,9 +10,7 @@ struct omap_dss_device;
  * @ext_te_gpio: external TE GPIO
  * @esd_interval: interval of ESD checks, 0 = disabled (ms)
  * @ulps_timeout: time to wait before entering ULPS, 0 = disabled (ms)
- * @max_backlight_level: maximum backlight level
- * @set_backlight: pointer to backlight set function
- * @get_backlight: pointer to backlight get function
+ * @use_dsi_backlight: true if panel uses DSI command to control backlight
  */
 struct nokia_dsi_panel_data {
        const char *name;
@@ -25,9 +23,7 @@ struct nokia_dsi_panel_data {
        unsigned esd_interval;
        unsigned ulps_timeout;
 
-       int max_backlight_level;
-       int (*set_backlight)(struct omap_dss_device *dssdev, int level);
-       int (*get_backlight)(struct omap_dss_device *dssdev);
+       bool use_dsi_backlight;
 };
 
 #endif /* __OMAP_NOKIA_DSI_PANEL_H */
diff --git a/include/video/omap-panel-picodlp.h b/include/video/omap-panel-picodlp.h
new file mode 100644 (file)
index 0000000..1c342ef
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * panel data for picodlp panel
+ *
+ * Copyright (C) 2011 Texas Instruments
+ *
+ * Author: Mayuresh Janorkar <mayur@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#ifndef __PANEL_PICODLP_H
+#define __PANEL_PICODLP_H
+/**
+ * struct : picodlp panel data
+ * picodlp_adapter_id: i2c_adapter number for picodlp
+ */
+struct picodlp_panel_data {
+       int picodlp_adapter_id;
+       int emu_done_gpio;
+       int pwrgood_gpio;
+};
+#endif /* __PANEL_PICODLP_H */
index 3b55ef22f8db2415ee10de5675f435da59fec44f..b66ebb2032c6d6b87c928876cab69c235d2425f3 100644 (file)
 #define DISPC_IRQ_WAKEUP               (1 << 16)
 #define DISPC_IRQ_SYNC_LOST2           (1 << 17)
 #define DISPC_IRQ_VSYNC2               (1 << 18)
+#define DISPC_IRQ_VID3_END_WIN         (1 << 19)
+#define DISPC_IRQ_VID3_FIFO_UNDERFLOW  (1 << 20)
 #define DISPC_IRQ_ACBIAS_COUNT_STAT2   (1 << 21)
 #define DISPC_IRQ_FRAMEDONE2           (1 << 22)
+#define DISPC_IRQ_FRAMEDONEWB          (1 << 23)
+#define DISPC_IRQ_FRAMEDONETV          (1 << 24)
+#define DISPC_IRQ_WBBUFFEROVERFLOW     (1 << 25)
 
 struct omap_dss_device;
 struct omap_overlay_manager;
@@ -60,7 +65,8 @@ enum omap_display_type {
 enum omap_plane {
        OMAP_DSS_GFX    = 0,
        OMAP_DSS_VIDEO1 = 1,
-       OMAP_DSS_VIDEO2 = 2
+       OMAP_DSS_VIDEO2 = 2,
+       OMAP_DSS_VIDEO3 = 3,
 };
 
 enum omap_channel {
@@ -129,6 +135,18 @@ enum omap_dss_venc_type {
        OMAP_DSS_VENC_TYPE_SVIDEO,
 };
 
+enum omap_dss_dsi_pixel_format {
+       OMAP_DSS_DSI_FMT_RGB888,
+       OMAP_DSS_DSI_FMT_RGB666,
+       OMAP_DSS_DSI_FMT_RGB666_PACKED,
+       OMAP_DSS_DSI_FMT_RGB565,
+};
+
+enum omap_dss_dsi_mode {
+       OMAP_DSS_DSI_CMD_MODE = 0,
+       OMAP_DSS_DSI_VIDEO_MODE,
+};
+
 enum omap_display_caps {
        OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE      = 1 << 0,
        OMAP_DSS_DISPLAY_CAP_TEAR_ELIM          = 1 << 1,
@@ -162,11 +180,13 @@ enum omap_dss_rotation_angle {
 
 enum omap_overlay_caps {
        OMAP_DSS_OVL_CAP_SCALE = 1 << 0,
-       OMAP_DSS_OVL_CAP_DISPC = 1 << 1,
+       OMAP_DSS_OVL_CAP_GLOBAL_ALPHA = 1 << 1,
+       OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA = 1 << 2,
+       OMAP_DSS_OVL_CAP_ZORDER = 1 << 3,
 };
 
 enum omap_overlay_manager_caps {
-       OMAP_DSS_OVL_MGR_CAP_DISPC = 1 << 0,
+       OMAP_DSS_DUMMY_VALUE, /* add a dummy value to prevent compiler error */
 };
 
 enum omap_dss_clk_source {
@@ -215,26 +235,67 @@ void rfbi_bus_lock(void);
 void rfbi_bus_unlock(void);
 
 /* DSI */
+
+struct omap_dss_dsi_videomode_data {
+       /* DSI video mode blanking data */
+       /* Unit: byte clock cycles */
+       u16 hsa;
+       u16 hfp;
+       u16 hbp;
+       /* Unit: line clocks */
+       u16 vsa;
+       u16 vfp;
+       u16 vbp;
+
+       /* DSI blanking modes */
+       int blanking_mode;
+       int hsa_blanking_mode;
+       int hbp_blanking_mode;
+       int hfp_blanking_mode;
+
+       /* Video port sync events */
+       int vp_de_pol;
+       int vp_hsync_pol;
+       int vp_vsync_pol;
+       bool vp_vsync_end;
+       bool vp_hsync_end;
+
+       bool ddr_clk_always_on;
+       int window_sync;
+};
+
 void dsi_bus_lock(struct omap_dss_device *dssdev);
 void dsi_bus_unlock(struct omap_dss_device *dssdev);
 int dsi_vc_dcs_write(struct omap_dss_device *dssdev, int channel, u8 *data,
                int len);
-int dsi_vc_dcs_write_0(struct omap_dss_device *dssdev, int channel,
-               u8 dcs_cmd);
+int dsi_vc_generic_write(struct omap_dss_device *dssdev, int channel, u8 *data,
+               int len);
+int dsi_vc_dcs_write_0(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd);
+int dsi_vc_generic_write_0(struct omap_dss_device *dssdev, int channel);
 int dsi_vc_dcs_write_1(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
                u8 param);
+int dsi_vc_generic_write_1(struct omap_dss_device *dssdev, int channel,
+               u8 param);
+int dsi_vc_generic_write_2(struct omap_dss_device *dssdev, int channel,
+               u8 param1, u8 param2);
 int dsi_vc_dcs_write_nosync(struct omap_dss_device *dssdev, int channel,
                u8 *data, int len);
+int dsi_vc_generic_write_nosync(struct omap_dss_device *dssdev, int channel,
+               u8 *data, int len);
 int dsi_vc_dcs_read(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
                u8 *buf, int buflen);
-int dsi_vc_dcs_read_1(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
-               u8 *data);
-int dsi_vc_dcs_read_2(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
-               u8 *data1, u8 *data2);
+int dsi_vc_generic_read_0(struct omap_dss_device *dssdev, int channel, u8 *buf,
+               int buflen);
+int dsi_vc_generic_read_1(struct omap_dss_device *dssdev, int channel, u8 param,
+               u8 *buf, int buflen);
+int dsi_vc_generic_read_2(struct omap_dss_device *dssdev, int channel,
+               u8 param1, u8 param2, u8 *buf, int buflen);
 int dsi_vc_set_max_rx_packet_size(struct omap_dss_device *dssdev, int channel,
                u16 len);
 int dsi_vc_send_null(struct omap_dss_device *dssdev, int channel);
 int dsi_vc_send_bta_sync(struct omap_dss_device *dssdev, int channel);
+int dsi_video_mode_enable(struct omap_dss_device *dssdev, int channel);
+void dsi_video_mode_disable(struct omap_dss_device *dssdev, int channel);
 
 /* Board specific data */
 struct omap_dss_board_info {
@@ -242,7 +303,8 @@ struct omap_dss_board_info {
        int num_devices;
        struct omap_dss_device **devices;
        struct omap_dss_device *default_device;
-       void (*dsi_mux_pads)(bool enable);
+       int (*dsi_enable_pads)(int dsi_id, unsigned lane_mask);
+       void (*dsi_disable_pads)(int dsi_id, unsigned lane_mask);
 };
 
 #if defined(CONFIG_OMAP2_DSS_MODULE) || defined(CONFIG_OMAP2_DSS)
@@ -300,7 +362,6 @@ struct omap_overlay_info {
        bool enabled;
 
        u32 paddr;
-       void __iomem *vaddr;
        u32 p_uv_addr;  /* for NV12 format */
        u16 screen_width;
        u16 width;
@@ -316,6 +377,7 @@ struct omap_overlay_info {
        u16 out_height; /* if 0, out_height == height */
        u8 global_alpha;
        u8 pre_mult_alpha;
+       u8 zorder;
 };
 
 struct omap_overlay {
@@ -324,7 +386,7 @@ struct omap_overlay {
 
        /* static fields */
        const char *name;
-       int id;
+       enum omap_plane id;
        enum omap_color_mode supported_modes;
        enum omap_overlay_caps caps;
 
@@ -332,6 +394,7 @@ struct omap_overlay {
        struct omap_overlay_manager *manager;
        struct omap_overlay_info info;
 
+       bool manager_changed;
        /* if true, info has been changed, but not applied() yet */
        bool info_dirty;
 
@@ -354,7 +417,7 @@ struct omap_overlay_manager_info {
        u32 trans_key;
        bool trans_enabled;
 
-       bool alpha_enabled;
+       bool partial_alpha_enabled;
 
        bool cpr_enable;
        struct omap_dss_cpr_coefs cpr_coefs;
@@ -366,7 +429,7 @@ struct omap_overlay_manager {
 
        /* static fields */
        const char *name;
-       int id;
+       enum omap_channel id;
        enum omap_overlay_manager_caps caps;
        int num_overlays;
        struct omap_overlay **overlays;
@@ -454,6 +517,7 @@ struct omap_dss_device {
                } dispc;
 
                struct {
+                       /* regn is one greater than TRM's REGN value */
                        u16 regn;
                        u16 regm;
                        u16 regm_dispc;
@@ -464,6 +528,7 @@ struct omap_dss_device {
                } dsi;
 
                struct {
+                       /* regn is one greater than TRM's REGN value */
                        u16 regn;
                        u16 regm2;
                } hdmi;
@@ -477,6 +542,10 @@ struct omap_dss_device {
                int acb;        /* ac-bias pin frequency */
 
                enum omap_panel_config config;
+
+               enum omap_dss_dsi_pixel_format dsi_pix_fmt;
+               enum omap_dss_dsi_mode dsi_mode;
+               struct omap_dss_dsi_videomode_data dsi_vm_data;
        } panel;
 
        struct {
@@ -557,6 +626,9 @@ struct omap_dss_driver {
 
        int (*set_wss)(struct omap_dss_device *dssdev, u32 wss);
        u32 (*get_wss)(struct omap_dss_device *dssdev);
+
+       int (*read_edid)(struct omap_dss_device *dssdev, u8 *buf, int len);
+       bool (*detect)(struct omap_dss_device *dssdev);
 };
 
 int omap_dss_register_driver(struct omap_dss_driver *);
index d964e68fc61dab119e504f3f8feb1a5d0a44d36d..8101b726b48a273240558cb57a8b7b348b222f24 100644 (file)
 #include <linux/fb.h>
 #include <video/sh_mobile_meram.h>
 
+/* Register definitions */
+#define _LDDCKR                        0x410
+#define LDDCKR_ICKSEL_BUS      (0 << 16)
+#define LDDCKR_ICKSEL_MIPI     (1 << 16)
+#define LDDCKR_ICKSEL_HDMI     (2 << 16)
+#define LDDCKR_ICKSEL_EXT      (3 << 16)
+#define LDDCKR_ICKSEL_MASK     (7 << 16)
+#define LDDCKR_MOSEL           (1 << 6)
+#define _LDDCKSTPR             0x414
+#define _LDINTR                        0x468
+#define LDINTR_FE              (1 << 10)
+#define LDINTR_VSE             (1 << 9)
+#define LDINTR_VEE             (1 << 8)
+#define LDINTR_FS              (1 << 2)
+#define LDINTR_VSS             (1 << 1)
+#define LDINTR_VES             (1 << 0)
+#define LDINTR_STATUS_MASK     (0xff << 0)
+#define _LDSR                  0x46c
+#define LDSR_MSS               (1 << 10)
+#define LDSR_MRS               (1 << 8)
+#define LDSR_AS                        (1 << 1)
+#define _LDCNT1R               0x470
+#define LDCNT1R_DE             (1 << 0)
+#define _LDCNT2R               0x474
+#define LDCNT2R_BR             (1 << 8)
+#define LDCNT2R_MD             (1 << 3)
+#define LDCNT2R_SE             (1 << 2)
+#define LDCNT2R_ME             (1 << 1)
+#define LDCNT2R_DO             (1 << 0)
+#define _LDRCNTR               0x478
+#define LDRCNTR_SRS            (1 << 17)
+#define LDRCNTR_SRC            (1 << 16)
+#define LDRCNTR_MRS            (1 << 1)
+#define LDRCNTR_MRC            (1 << 0)
+#define _LDDDSR                        0x47c
+#define LDDDSR_LS              (1 << 2)
+#define LDDDSR_WS              (1 << 1)
+#define LDDDSR_BS              (1 << 0)
+
+#define LDMT1R_VPOL            (1 << 28)
+#define LDMT1R_HPOL            (1 << 27)
+#define LDMT1R_DWPOL           (1 << 26)
+#define LDMT1R_DIPOL           (1 << 25)
+#define LDMT1R_DAPOL           (1 << 24)
+#define LDMT1R_HSCNT           (1 << 17)
+#define LDMT1R_DWCNT           (1 << 16)
+#define LDMT1R_IFM             (1 << 12)
+#define LDMT1R_MIFTYP_RGB8     (0x0 << 0)
+#define LDMT1R_MIFTYP_RGB9     (0x4 << 0)
+#define LDMT1R_MIFTYP_RGB12A   (0x5 << 0)
+#define LDMT1R_MIFTYP_RGB12B   (0x6 << 0)
+#define LDMT1R_MIFTYP_RGB16    (0x7 << 0)
+#define LDMT1R_MIFTYP_RGB18    (0xa << 0)
+#define LDMT1R_MIFTYP_RGB24    (0xb << 0)
+#define LDMT1R_MIFTYP_YCBCR    (0xf << 0)
+#define LDMT1R_MIFTYP_SYS8A    (0x0 << 0)
+#define LDMT1R_MIFTYP_SYS8B    (0x1 << 0)
+#define LDMT1R_MIFTYP_SYS8C    (0x2 << 0)
+#define LDMT1R_MIFTYP_SYS8D    (0x3 << 0)
+#define LDMT1R_MIFTYP_SYS9     (0x4 << 0)
+#define LDMT1R_MIFTYP_SYS12    (0x5 << 0)
+#define LDMT1R_MIFTYP_SYS16A   (0x7 << 0)
+#define LDMT1R_MIFTYP_SYS16B   (0x8 << 0)
+#define LDMT1R_MIFTYP_SYS16C   (0x9 << 0)
+#define LDMT1R_MIFTYP_SYS18    (0xa << 0)
+#define LDMT1R_MIFTYP_SYS24    (0xb << 0)
+#define LDMT1R_MIFTYP_MASK     (0xf << 0)
+
+#define LDDFR_CF1              (1 << 18)
+#define LDDFR_CF0              (1 << 17)
+#define LDDFR_CC               (1 << 16)
+#define LDDFR_YF_420           (0 << 8)
+#define LDDFR_YF_422           (1 << 8)
+#define LDDFR_YF_444           (2 << 8)
+#define LDDFR_YF_MASK          (3 << 8)
+#define LDDFR_PKF_ARGB32       (0x00 << 0)
+#define LDDFR_PKF_RGB16                (0x03 << 0)
+#define LDDFR_PKF_RGB24                (0x0b << 0)
+#define LDDFR_PKF_MASK         (0x1f << 0)
+
+#define LDSM1R_OS              (1 << 0)
+
+#define LDSM2R_OSTRG           (1 << 0)
+
+#define LDPMR_LPS              (3 << 0)
+
+#define _LDDWD0R               0x800
+#define LDDWDxR_WDACT          (1 << 28)
+#define LDDWDxR_RSW            (1 << 24)
+#define _LDDRDR                        0x840
+#define LDDRDR_RSR             (1 << 24)
+#define LDDRDR_DRD_MASK                (0x3ffff << 0)
+#define _LDDWAR                        0x900
+#define LDDWAR_WA              (1 << 0)
+#define _LDDRAR                        0x904
+#define LDDRAR_RA              (1 << 0)
+
 enum {
-       RGB8,   /* 24bpp, 8:8:8 */
-       RGB9,   /* 18bpp, 9:9 */
-       RGB12A, /* 24bpp, 12:12 */
-       RGB12B, /* 12bpp */
-       RGB16,  /* 16bpp */
-       RGB18,  /* 18bpp */
-       RGB24,  /* 24bpp */
-       YUV422, /* 16bpp */
-       SYS8A,  /* 24bpp, 8:8:8 */
-       SYS8B,  /* 18bpp, 8:8:2 */
-       SYS8C,  /* 18bpp, 2:8:8 */
-       SYS8D,  /* 16bpp, 8:8 */
-       SYS9,   /* 18bpp, 9:9 */
-       SYS12,  /* 24bpp, 12:12 */
-       SYS16A, /* 16bpp */
-       SYS16B, /* 18bpp, 16:2 */
-       SYS16C, /* 18bpp, 2:16 */
-       SYS18,  /* 18bpp */
-       SYS24,  /* 24bpp */
+       RGB8    = LDMT1R_MIFTYP_RGB8,   /* 24bpp, 8:8:8 */
+       RGB9    = LDMT1R_MIFTYP_RGB9,   /* 18bpp, 9:9 */
+       RGB12A  = LDMT1R_MIFTYP_RGB12A, /* 24bpp, 12:12 */
+       RGB12B  = LDMT1R_MIFTYP_RGB12B, /* 12bpp */
+       RGB16   = LDMT1R_MIFTYP_RGB16,  /* 16bpp */
+       RGB18   = LDMT1R_MIFTYP_RGB18,  /* 18bpp */
+       RGB24   = LDMT1R_MIFTYP_RGB24,  /* 24bpp */
+       YUV422  = LDMT1R_MIFTYP_YCBCR,  /* 16bpp */
+       SYS8A   = LDMT1R_IFM | LDMT1R_MIFTYP_SYS8A,     /* 24bpp, 8:8:8 */
+       SYS8B   = LDMT1R_IFM | LDMT1R_MIFTYP_SYS8B,     /* 18bpp, 8:8:2 */
+       SYS8C   = LDMT1R_IFM | LDMT1R_MIFTYP_SYS8C,     /* 18bpp, 2:8:8 */
+       SYS8D   = LDMT1R_IFM | LDMT1R_MIFTYP_SYS8D,     /* 16bpp, 8:8 */
+       SYS9    = LDMT1R_IFM | LDMT1R_MIFTYP_SYS9,      /* 18bpp, 9:9 */
+       SYS12   = LDMT1R_IFM | LDMT1R_MIFTYP_SYS12,     /* 24bpp, 12:12 */
+       SYS16A  = LDMT1R_IFM | LDMT1R_MIFTYP_SYS16A,    /* 16bpp */
+       SYS16B  = LDMT1R_IFM | LDMT1R_MIFTYP_SYS16B,    /* 18bpp, 16:2 */
+       SYS16C  = LDMT1R_IFM | LDMT1R_MIFTYP_SYS16C,    /* 18bpp, 2:16 */
+       SYS18   = LDMT1R_IFM | LDMT1R_MIFTYP_SYS18,     /* 18bpp */
+       SYS24   = LDMT1R_IFM | LDMT1R_MIFTYP_SYS24,     /* 24bpp */
 };
 
 enum { LCDC_CHAN_DISABLED = 0,
index 69d485a4a026b9887366d1f84f0acf959b6eedda..c41f308c963626d900972f843d2853458cff89da 100644 (file)
@@ -50,6 +50,7 @@ struct dlfb_data {
        int base16;
        int base8;
        u32 pseudo_palette[256];
+       int blank_mode; /*one of FB_BLANK_ */
        /* blit-only rendering path metrics, exposed through sysfs */
        atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
        atomic_t bytes_identical; /* saved effort with backbuffer comparison */
index 901724dc528d35f9b28f8376b791da4f8e1613e1..b62dfef15f61ad8d0cdcf53b5d4b8730ec0f9ea5 100644 (file)
@@ -6,12 +6,12 @@ extern struct console xenboot_console;
 #ifdef CONFIG_HVC_XEN
 void xen_console_resume(void);
 void xen_raw_console_write(const char *str);
-__attribute__((format(printf, 1, 2)))
+__printf(1, 2)
 void xen_raw_printk(const char *fmt, ...);
 #else
 static inline void xen_console_resume(void) { }
 static inline void xen_raw_console_write(const char *str) { }
-static inline __attribute__((format(printf, 1, 2)))
+static inline __printf(1, 2)
 void xen_raw_printk(const char *fmt, ...) { }
 #endif
 
index aceeca799fd7689958d26b9dd9b98bbb4d21bbd6..b9f9fb5af0d844d5e89c23fbb825653c33829645 100644 (file)
@@ -156,9 +156,9 @@ int xenbus_scanf(struct xenbus_transaction t,
        __attribute__((format(scanf, 4, 5)));
 
 /* Single printf and write: returns -errno or 0. */
+__printf(4, 5)
 int xenbus_printf(struct xenbus_transaction t,
-                 const char *dir, const char *node, const char *fmt, ...)
-       __attribute__((format(printf, 4, 5)));
+                 const char *dir, const char *node, const char *fmt, ...);
 
 /* Generic read function: NULL-terminated triples of name,
  * sprintf-style type string, and pointer. Returns 0 or errno.*/
@@ -200,11 +200,11 @@ int xenbus_watch_path(struct xenbus_device *dev, const char *path,
                      struct xenbus_watch *watch,
                      void (*callback)(struct xenbus_watch *,
                                       const char **, unsigned int));
+__printf(4, 5)
 int xenbus_watch_pathfmt(struct xenbus_device *dev, struct xenbus_watch *watch,
                         void (*callback)(struct xenbus_watch *,
                                          const char **, unsigned int),
-                        const char *pathfmt, ...)
-       __attribute__ ((format (printf, 4, 5)));
+                        const char *pathfmt, ...);
 
 int xenbus_switch_state(struct xenbus_device *dev, enum xenbus_state new_state);
 int xenbus_grant_ring(struct xenbus_device *dev, unsigned long ring_mfn);
@@ -223,9 +223,9 @@ int xenbus_free_evtchn(struct xenbus_device *dev, int port);
 
 enum xenbus_state xenbus_read_driver_state(const char *path);
 
-__attribute__((format(printf, 3, 4)))
+__printf(3, 4)
 void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt, ...);
-__attribute__((format(printf, 3, 4)))
+__printf(3, 4)
 void xenbus_dev_fatal(struct xenbus_device *dev, int err, const char *fmt, ...);
 
 const char *xenbus_strstate(enum xenbus_state state);
index ed049ea568f45ee6026941b5d8335853c33efcd8..2e0ecfcc881dd124e3b2a2d868971fd1e6dea6f8 100644 (file)
@@ -449,8 +449,8 @@ static int wq_sleep(struct mqueue_inode_info *info, int sr,
                set_current_state(TASK_INTERRUPTIBLE);
 
                spin_unlock(&info->lock);
-               time = schedule_hrtimeout_range_clock(timeout,
-                   HRTIMER_MODE_ABS, 0, CLOCK_REALTIME);
+               time = schedule_hrtimeout_range_clock(timeout, 0,
+                       HRTIMER_MODE_ABS, CLOCK_REALTIME);
 
                while (ewp->state == STATE_PENDING)
                        cpu_relax();
index 5f85690285d489543bf3b447d788f2ca09790d8b..69ebf3380bac362afc73904be855dc87abdb52ee 100644 (file)
@@ -19,9 +19,16 @@ unsigned long saved_max_pfn;
  */
 unsigned long long elfcorehdr_addr = ELFCORE_ADDR_MAX;
 
+/*
+ * stores the size of elf header of crash image
+ */
+unsigned long long elfcorehdr_size;
+
 /*
  * elfcorehdr= specifies the location of elf core header stored by the crashed
  * kernel. This option will be passed by kexec loader to the capture kernel.
+ *
+ * Syntax: elfcorehdr=[size[KMG]@]offset[KMG]
  */
 static int __init setup_elfcorehdr(char *arg)
 {
@@ -29,6 +36,10 @@ static int __init setup_elfcorehdr(char *arg)
        if (!arg)
                return -EINVAL;
        elfcorehdr_addr = memparse(arg, &end);
+       if (*end == '@') {
+               elfcorehdr_size = elfcorehdr_addr;
+               elfcorehdr_addr = memparse(end + 1, &end);
+       }
        return end > arg ? 0 : -EINVAL;
 }
 early_param("elfcorehdr", setup_elfcorehdr);
index 34872482315e28eade2a7a1d92bfcb0e6cdd5813..c22d8c28ad848c63003ffb00bf235d9d0ab34649 100644 (file)
@@ -217,7 +217,7 @@ void gdbstub_msg_write(const char *s, int len)
 
                /* Pack in hex chars */
                for (i = 0; i < wcount; i++)
-                       bufptr = pack_hex_byte(bufptr, s[i]);
+                       bufptr = hex_byte_pack(bufptr, s[i]);
                *bufptr = '\0';
 
                /* Move up */
@@ -249,7 +249,7 @@ char *kgdb_mem2hex(char *mem, char *buf, int count)
        if (err)
                return NULL;
        while (count > 0) {
-               buf = pack_hex_byte(buf, *tmp);
+               buf = hex_byte_pack(buf, *tmp);
                tmp++;
                count--;
        }
@@ -411,14 +411,14 @@ static char *pack_threadid(char *pkt, unsigned char *id)
        limit = id + (BUF_THREAD_ID_SIZE / 2);
        while (id < limit) {
                if (!lzero || *id != 0) {
-                       pkt = pack_hex_byte(pkt, *id);
+                       pkt = hex_byte_pack(pkt, *id);
                        lzero = 0;
                }
                id++;
        }
 
        if (lzero)
-               pkt = pack_hex_byte(pkt, 0);
+               pkt = hex_byte_pack(pkt, 0);
 
        return pkt;
 }
@@ -486,7 +486,7 @@ static void gdb_cmd_status(struct kgdb_state *ks)
        dbg_remove_all_break();
 
        remcom_out_buffer[0] = 'S';
-       pack_hex_byte(&remcom_out_buffer[1], ks->signo);
+       hex_byte_pack(&remcom_out_buffer[1], ks->signo);
 }
 
 static void gdb_get_regs_helper(struct kgdb_state *ks)
@@ -954,7 +954,7 @@ int gdb_serial_stub(struct kgdb_state *ks)
                /* Reply to host that an exception has occurred */
                ptr = remcom_out_buffer;
                *ptr++ = 'T';
-               ptr = pack_hex_byte(ptr, ks->signo);
+               ptr = hex_byte_pack(ptr, ks->signo);
                ptr += strlen(strcpy(ptr, "thread:"));
                int_to_threadref(thref, shadow_pid(current->pid));
                ptr = pack_threadid(ptr, thref);
index d1a1bee35228ce06bd77862909278a33d0158a4f..12a0287e03582c6969e1268ac4e7456222b111be 100644 (file)
@@ -3544,7 +3544,7 @@ static void perf_mmap_close(struct vm_area_struct *vma)
                struct ring_buffer *rb = event->rb;
 
                atomic_long_sub((size >> PAGE_SHIFT) + 1, &user->locked_vm);
-               vma->vm_mm->locked_vm -= event->mmap_locked;
+               vma->vm_mm->pinned_vm -= event->mmap_locked;
                rcu_assign_pointer(event->rb, NULL);
                mutex_unlock(&event->mmap_mutex);
 
@@ -3625,7 +3625,7 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
 
        lock_limit = rlimit(RLIMIT_MEMLOCK);
        lock_limit >>= PAGE_SHIFT;
-       locked = vma->vm_mm->locked_vm + extra;
+       locked = vma->vm_mm->pinned_vm + extra;
 
        if ((locked > lock_limit) && perf_paranoid_tracepoint_raw() &&
                !capable(CAP_IPC_LOCK)) {
@@ -3651,7 +3651,7 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
        atomic_long_add(user_extra, &user->locked_vm);
        event->mmap_locked = extra;
        event->mmap_user = get_current_user();
-       vma->vm_mm->locked_vm += event->mmap_locked;
+       vma->vm_mm->pinned_vm += event->mmap_locked;
 
 unlock:
        if (!ret)
index 2913b3509d4288026990cc087894e69eace6c564..d0b7d988f8735beb6e1e7b5f7b42ecbd04b91bf5 100644 (file)
@@ -681,8 +681,6 @@ static void exit_mm(struct task_struct * tsk)
        enter_lazy_tlb(mm, current);
        /* We don't want this task to be frozen prematurely */
        clear_freeze_flag(tsk);
-       if (tsk->signal->oom_score_adj == OOM_SCORE_ADJ_MIN)
-               atomic_dec(&mm->oom_disable_count);
        task_unlock(tsk);
        mm_update_next_owner(mm);
        mmput(mm);
index 8e6b6f4fb272ba498a4acdbcb6a29c8f7e6c87dd..70d76191afb9449033f09ef2c3532d450defdd49 100644 (file)
@@ -501,7 +501,6 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p)
        mm->cached_hole_size = ~0UL;
        mm_init_aio(mm);
        mm_init_owner(mm, p);
-       atomic_set(&mm->oom_disable_count, 0);
 
        if (likely(!mm_alloc_pgd(mm))) {
                mm->def_flags = 0;
@@ -816,8 +815,6 @@ good_mm:
        /* Initializing for Swap token stuff */
        mm->token_priority = 0;
        mm->last_interval = 0;
-       if (tsk->signal->oom_score_adj == OOM_SCORE_ADJ_MIN)
-               atomic_inc(&mm->oom_disable_count);
 
        tsk->mm = mm;
        tsk->active_mm = mm;
@@ -1391,13 +1388,8 @@ bad_fork_cleanup_io:
 bad_fork_cleanup_namespaces:
        exit_task_namespaces(p);
 bad_fork_cleanup_mm:
-       if (p->mm) {
-               task_lock(p);
-               if (p->signal->oom_score_adj == OOM_SCORE_ADJ_MIN)
-                       atomic_dec(&p->mm->oom_disable_count);
-               task_unlock(p);
+       if (p->mm)
                mmput(p->mm);
-       }
 bad_fork_cleanup_signal:
        if (!(clone_flags & CLONE_THREAD))
                free_signal_struct(p->signal);
index e38544dddb18a143e2a63f2827a56e45f8b1aa53..6cb7613e4bf4250e57ad05c54f0a0a62668676a4 100644 (file)
@@ -211,6 +211,7 @@ irq_alloc_generic_chip(const char *name, int num_ct, unsigned int irq_base,
        }
        return gc;
 }
+EXPORT_SYMBOL_GPL(irq_alloc_generic_chip);
 
 /*
  * Separate lockdep class for interrupt chip which can nest irq_desc
@@ -258,6 +259,7 @@ void irq_setup_generic_chip(struct irq_chip_generic *gc, u32 msk,
        }
        gc->irq_cnt = i - gc->irq_base;
 }
+EXPORT_SYMBOL_GPL(irq_setup_generic_chip);
 
 /**
  * irq_setup_alt_chip - Switch to alternative chip
@@ -281,6 +283,7 @@ int irq_setup_alt_chip(struct irq_data *d, unsigned int type)
        }
        return -EINVAL;
 }
+EXPORT_SYMBOL_GPL(irq_setup_alt_chip);
 
 /**
  * irq_remove_generic_chip - Remove a chip
@@ -311,6 +314,7 @@ void irq_remove_generic_chip(struct irq_chip_generic *gc, u32 msk,
                irq_modify_status(i, clr, set);
        }
 }
+EXPORT_SYMBOL_GPL(irq_remove_generic_chip);
 
 #ifdef CONFIG_PM
 static int irq_gc_suspend(void)
index 296fbc84d659d7d5749353e06d814b579ff50989..dc7bc0829286d60cd5e37e162441bdc7a8d12b46 100644 (file)
@@ -498,7 +498,7 @@ static struct page *kimage_alloc_crash_control_pages(struct kimage *image,
        while (hole_end <= crashk_res.end) {
                unsigned long i;
 
-               if (hole_end > KEXEC_CONTROL_MEMORY_LIMIT)
+               if (hole_end > KEXEC_CRASH_CONTROL_MEMORY_LIMIT)
                        break;
                if (hole_end > crashk_res.end)
                        break;
@@ -999,6 +999,7 @@ SYSCALL_DEFINE4(kexec_load, unsigned long, entry, unsigned long, nr_segments,
                        kimage_free(xchg(&kexec_crash_image, NULL));
                        result = kimage_crash_alloc(&image, entry,
                                                     nr_segments, segments);
+                       crash_map_reserved_pages();
                }
                if (result)
                        goto out;
@@ -1015,6 +1016,8 @@ SYSCALL_DEFINE4(kexec_load, unsigned long, entry, unsigned long, nr_segments,
                                goto out;
                }
                kimage_terminate(image);
+               if (flags & KEXEC_ON_CRASH)
+                       crash_unmap_reserved_pages();
        }
        /* Install the new kernel, and  Uninstall the old */
        image = xchg(dest_image, image);
@@ -1026,6 +1029,18 @@ out:
        return result;
 }
 
+/*
+ * Add and remove page tables for crashkernel memory
+ *
+ * Provide an empty default implementation here -- architecture
+ * code may override this
+ */
+void __weak crash_map_reserved_pages(void)
+{}
+
+void __weak crash_unmap_reserved_pages(void)
+{}
+
 #ifdef CONFIG_COMPAT
 asmlinkage long compat_sys_kexec_load(unsigned long entry,
                                unsigned long nr_segments,
@@ -1134,14 +1149,16 @@ int crash_shrink_memory(unsigned long new_size)
                goto unlock;
        }
 
-       start = roundup(start, PAGE_SIZE);
-       end = roundup(start + new_size, PAGE_SIZE);
+       start = roundup(start, KEXEC_CRASH_MEM_ALIGN);
+       end = roundup(start + new_size, KEXEC_CRASH_MEM_ALIGN);
 
+       crash_map_reserved_pages();
        crash_free_reserved_phys_range(end, crashk_res.end);
 
        if ((start == end) && (crashk_res.parent != NULL))
                release_resource(&crashk_res);
        crashk_res.end = end - 1;
+       crash_unmap_reserved_pages();
 
 unlock:
        mutex_unlock(&kexec_mutex);
@@ -1380,24 +1397,23 @@ int __init parse_crashkernel(char                *cmdline,
 }
 
 
-
-void crash_save_vmcoreinfo(void)
+static void update_vmcoreinfo_note(void)
 {
-       u32 *buf;
+       u32 *buf = vmcoreinfo_note;
 
        if (!vmcoreinfo_size)
                return;
-
-       vmcoreinfo_append_str("CRASHTIME=%ld", get_seconds());
-
-       buf = (u32 *)vmcoreinfo_note;
-
        buf = append_elf_note(buf, VMCOREINFO_NOTE_NAME, 0, vmcoreinfo_data,
                              vmcoreinfo_size);
-
        final_note(buf);
 }
 
+void crash_save_vmcoreinfo(void)
+{
+       vmcoreinfo_append_str("CRASHTIME=%ld", get_seconds());
+       update_vmcoreinfo_note();
+}
+
 void vmcoreinfo_append_str(const char *fmt, ...)
 {
        va_list args;
@@ -1483,6 +1499,7 @@ static int __init crash_save_vmcoreinfo_init(void)
        VMCOREINFO_NUMBER(PG_swapcache);
 
        arch_crash_save_vmcoreinfo();
+       update_vmcoreinfo_note();
 
        return 0;
 }
index b7da18391c388d543ac0eaa7cd9fbf6a4c367520..1455a0d4eedd4b386c759d689f939ba5d7a9007a 100644 (file)
@@ -532,6 +532,9 @@ static int __init ignore_loglevel_setup(char *str)
 }
 
 early_param("ignore_loglevel", ignore_loglevel_setup);
+module_param_named(ignore_loglevel, ignore_loglevel, bool, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(ignore_loglevel, "ignore loglevel setting, to"
+       "print all kernel messages to the console.");
 
 /*
  * Write out chars from start to end - 1 inclusive
@@ -592,9 +595,6 @@ static size_t log_prefix(const char *p, unsigned int *level, char *special)
                /* multi digit including the level and facility number */
                char *endp = NULL;
 
-               if (p[1] < '0' && p[1] > '9')
-                       return 0;
-
                lev = (simple_strtoul(&p[1], &endp, 10) & 7);
                if (endp == NULL || endp[0] != '>')
                        return 0;
@@ -1108,6 +1108,10 @@ static int __init console_suspend_disable(char *str)
        return 1;
 }
 __setup("no_console_suspend", console_suspend_disable);
+module_param_named(console_suspend, console_suspend_enabled,
+               bool, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(console_suspend, "suspend console during suspend"
+       " and hibernate operations");
 
 /**
  * suspend_console - suspend the console subsystem
index ba5070ce576541cfb1736c6bd5e17c486e1f3a16..5b0951aa04963dc6834e8ed1e8a9d26e08659bac 100644 (file)
@@ -41,6 +41,7 @@ struct cpu_stopper {
 };
 
 static DEFINE_PER_CPU(struct cpu_stopper, cpu_stopper);
+static bool stop_machine_initialized = false;
 
 static void cpu_stop_init_done(struct cpu_stop_done *done, unsigned int nr_todo)
 {
@@ -386,6 +387,8 @@ static int __init cpu_stop_init(void)
        cpu_stop_cpu_callback(&cpu_stop_cpu_notifier, CPU_ONLINE, bcpu);
        register_cpu_notifier(&cpu_stop_cpu_notifier);
 
+       stop_machine_initialized = true;
+
        return 0;
 }
 early_initcall(cpu_stop_init);
@@ -485,6 +488,25 @@ int __stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus)
                                            .num_threads = num_online_cpus(),
                                            .active_cpus = cpus };
 
+       if (!stop_machine_initialized) {
+               /*
+                * Handle the case where stop_machine() is called
+                * early in boot before stop_machine() has been
+                * initialized.
+                */
+               unsigned long flags;
+               int ret;
+
+               WARN_ON_ONCE(smdata.num_threads != 1);
+
+               local_irq_save(flags);
+               hard_irq_disable();
+               ret = (*fn)(data);
+               local_irq_restore(flags);
+
+               return ret;
+       }
+
        /* Set the initial state and stop all online cpus. */
        set_state(&smdata, STOPMACHINE_PREPARE);
        return stop_cpus(cpu_online_mask, stop_machine_cpu_stop, &smdata);
index a9a5de07c4f16e1310616cb9dd51903f710199ff..47bfa16430d7dc764c17a06f4c40dd142ef6a88a 100644 (file)
@@ -145,6 +145,10 @@ cond_syscall(sys_io_submit);
 cond_syscall(sys_io_cancel);
 cond_syscall(sys_io_getevents);
 cond_syscall(sys_syslog);
+cond_syscall(sys_process_vm_readv);
+cond_syscall(sys_process_vm_writev);
+cond_syscall(compat_sys_process_vm_readv);
+cond_syscall(compat_sys_process_vm_writev);
 
 /* arch-specific weak syscall entries */
 cond_syscall(sys_pciconfig_read);
index 2d2ecdcc8cdbb070999d46ae79b158dbbb28c8a3..ae27196438541384fbfdc1a5c405681169ac8921 100644 (file)
@@ -57,6 +57,7 @@
 #include <linux/pipe_fs_i.h>
 #include <linux/oom.h>
 #include <linux/kmod.h>
+#include <linux/capability.h>
 
 #include <asm/uaccess.h>
 #include <asm/processor.h>
@@ -134,6 +135,7 @@ static int minolduid;
 static int min_percpu_pagelist_fract = 8;
 
 static int ngroups_max = NGROUPS_MAX;
+static const int cap_last_cap = CAP_LAST_CAP;
 
 #ifdef CONFIG_INOTIFY_USER
 #include <linux/inotify.h>
@@ -151,14 +153,6 @@ extern int pwrsw_enabled;
 extern int unaligned_enabled;
 #endif
 
-#ifdef CONFIG_S390
-#ifdef CONFIG_MATHEMU
-extern int sysctl_ieee_emulation_warnings;
-#endif
-extern int sysctl_userprocess_debug;
-extern int spin_retry;
-#endif
-
 #ifdef CONFIG_IA64
 extern int no_unaligned_warning;
 extern int unaligned_dump_stack;
@@ -740,6 +734,13 @@ static struct ctl_table kern_table[] = {
                .mode           = 0444,
                .proc_handler   = proc_dointvec,
        },
+       {
+               .procname       = "cap_last_cap",
+               .data           = (void *)&cap_last_cap,
+               .maxlen         = sizeof(int),
+               .mode           = 0444,
+               .proc_handler   = proc_dointvec,
+       },
 #if defined(CONFIG_LOCKUP_DETECTOR)
        {
                .procname       = "watchdog",
index d680381b0e9ccfc6fc0f008ae92e4141aa93ca56..1d7bca7f4f527c2f25b741da9fc914980a0c43bb 100644 (file)
@@ -481,6 +481,8 @@ static void watchdog_disable(int cpu)
        }
 }
 
+/* sysctl functions */
+#ifdef CONFIG_SYSCTL
 static void watchdog_enable_all_cpus(void)
 {
        int cpu;
@@ -510,8 +512,6 @@ static void watchdog_disable_all_cpus(void)
 }
 
 
-/* sysctl functions */
-#ifdef CONFIG_SYSCTL
 /*
  * proc handler for /proc/sys/kernel/nmi_watchdog,watchdog_thresh
  */
index 75330bd8756562eaf46dd365d7c047f34edacb5d..82928f5ea0494936e83e9751fb6a1e4107a6efc2 100644 (file)
@@ -248,8 +248,9 @@ config DEFAULT_HUNG_TASK_TIMEOUT
          to determine when a task has become non-responsive and should
          be considered hung.
 
-         It can be adjusted at runtime via the kernel.hung_task_timeout
-         sysctl or by writing a value to /proc/sys/kernel/hung_task_timeout.
+         It can be adjusted at runtime via the kernel.hung_task_timeout_secs
+         sysctl or by writing a value to
+         /proc/sys/kernel/hung_task_timeout_secs.
 
          A timeout of 0 disables the check.  The default is two minutes.
          Keeping the default should be fine in most cases.
@@ -1070,6 +1071,17 @@ config FAIL_IO_TIMEOUT
          Only works with drivers that use the generic timeout handling,
          for others it wont do anything.
 
+config FAIL_MMC_REQUEST
+       bool "Fault-injection capability for MMC IO"
+       select DEBUG_FS
+       depends on FAULT_INJECTION && MMC
+       help
+         Provide fault-injection capability for MMC IO.
+         This will make the mmc core return data errors. This is
+         useful to test the error handling in the mmc block device
+         and to test how the mmc host driver handles retries from
+         the block device.
+
 config FAULT_INJECTION_DEBUG_FS
        bool "Debugfs entries for fault-injection capabilities"
        depends on FAULT_INJECTION && SYSFS && DEBUG_FS
index 2f4412e4d0719c25ca1d4948d489eee8c998f444..0d4a127dd9b3d478091a471df6386b7f85b25bbc 100644 (file)
@@ -419,7 +419,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
 {
        int c, old_c, totaldigits, ndigits, nchunks, nbits;
        u32 chunk;
-       const char __user *ubuf = buf;
+       const char __user __force *ubuf = (const char __user __force *)buf;
 
        bitmap_zero(maskp, nmaskbits);
 
@@ -504,7 +504,9 @@ int bitmap_parse_user(const char __user *ubuf,
 {
        if (!access_ok(VERIFY_READ, ubuf, ulen))
                return -EFAULT;
-       return __bitmap_parse((const char *)ubuf, ulen, 1, maskp, nmaskbits);
+       return __bitmap_parse((const char __force *)ubuf,
+                               ulen, 1, maskp, nmaskbits);
+
 }
 EXPORT_SYMBOL(bitmap_parse_user);
 
@@ -594,7 +596,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
 {
        unsigned a, b;
        int c, old_c, totaldigits;
-       const char __user *ubuf = buf;
+       const char __user __force *ubuf = (const char __user __force *)buf;
        int exp_digit, in_range;
 
        totaldigits = c = 0;
@@ -694,7 +696,7 @@ int bitmap_parselist_user(const char __user *ubuf,
 {
        if (!access_ok(VERIFY_READ, ubuf, ulen))
                return -EFAULT;
-       return __bitmap_parselist((const char *)ubuf,
+       return __bitmap_parselist((const char __force *)ubuf,
                                        ulen, 1, maskp, nmaskbits);
 }
 EXPORT_SYMBOL(bitmap_parselist_user);
index db07bfd9298ea93d4ddcdf76a8a0c868b955371b..79700fa2dfc4402b2b336f90bded2bbdcb190cf3 100644 (file)
@@ -62,6 +62,8 @@ struct dma_debug_entry {
 #endif
 };
 
+typedef bool (*match_fn)(struct dma_debug_entry *, struct dma_debug_entry *);
+
 struct hash_bucket {
        struct list_head list;
        spinlock_t lock;
@@ -240,18 +242,37 @@ static void put_hash_bucket(struct hash_bucket *bucket,
        spin_unlock_irqrestore(&bucket->lock, __flags);
 }
 
+static bool exact_match(struct dma_debug_entry *a, struct dma_debug_entry *b)
+{
+       return ((a->dev_addr == a->dev_addr) &&
+               (a->dev == b->dev)) ? true : false;
+}
+
+static bool containing_match(struct dma_debug_entry *a,
+                            struct dma_debug_entry *b)
+{
+       if (a->dev != b->dev)
+               return false;
+
+       if ((b->dev_addr <= a->dev_addr) &&
+           ((b->dev_addr + b->size) >= (a->dev_addr + a->size)))
+               return true;
+
+       return false;
+}
+
 /*
  * Search a given entry in the hash bucket list
  */
-static struct dma_debug_entry *hash_bucket_find(struct hash_bucket *bucket,
-                                               struct dma_debug_entry *ref)
+static struct dma_debug_entry *__hash_bucket_find(struct hash_bucket *bucket,
+                                                 struct dma_debug_entry *ref,
+                                                 match_fn match)
 {
        struct dma_debug_entry *entry, *ret = NULL;
        int matches = 0, match_lvl, last_lvl = 0;
 
        list_for_each_entry(entry, &bucket->list, list) {
-               if ((entry->dev_addr != ref->dev_addr) ||
-                   (entry->dev != ref->dev))
+               if (!match(ref, entry))
                        continue;
 
                /*
@@ -293,6 +314,39 @@ static struct dma_debug_entry *hash_bucket_find(struct hash_bucket *bucket,
        return ret;
 }
 
+static struct dma_debug_entry *bucket_find_exact(struct hash_bucket *bucket,
+                                                struct dma_debug_entry *ref)
+{
+       return __hash_bucket_find(bucket, ref, exact_match);
+}
+
+static struct dma_debug_entry *bucket_find_contain(struct hash_bucket **bucket,
+                                                  struct dma_debug_entry *ref,
+                                                  unsigned long *flags)
+{
+
+       unsigned int max_range = dma_get_max_seg_size(ref->dev);
+       struct dma_debug_entry *entry, index = *ref;
+       unsigned int range = 0;
+
+       while (range <= max_range) {
+               entry = __hash_bucket_find(*bucket, &index, containing_match);
+
+               if (entry)
+                       return entry;
+
+               /*
+                * Nothing found, go back a hash bucket
+                */
+               put_hash_bucket(*bucket, flags);
+               range          += (1 << HASH_FN_SHIFT);
+               index.dev_addr -= (1 << HASH_FN_SHIFT);
+               *bucket = get_hash_bucket(&index, flags);
+       }
+
+       return NULL;
+}
+
 /*
  * Add an entry to a hash bucket
  */
@@ -802,7 +856,7 @@ static void check_unmap(struct dma_debug_entry *ref)
        }
 
        bucket = get_hash_bucket(ref, &flags);
-       entry = hash_bucket_find(bucket, ref);
+       entry = bucket_find_exact(bucket, ref);
 
        if (!entry) {
                err_printk(ref->dev, NULL, "DMA-API: device driver tries "
@@ -902,7 +956,7 @@ static void check_sync(struct device *dev,
 
        bucket = get_hash_bucket(ref, &flags);
 
-       entry = hash_bucket_find(bucket, ref);
+       entry = bucket_find_contain(&bucket, ref, &flags);
 
        if (!entry) {
                err_printk(dev, NULL, "DMA-API: device driver tries "
@@ -1060,7 +1114,7 @@ static int get_nr_mapped_entries(struct device *dev,
        int mapped_ents;
 
        bucket       = get_hash_bucket(ref, &flags);
-       entry        = hash_bucket_find(bucket, ref);
+       entry        = bucket_find_exact(bucket, ref);
        mapped_ents  = 0;
 
        if (entry)
index f193b7796449a04870b401f96931ef71c18f808d..4f7554025e30e48da1e81b2a090fdf2131f86179 100644 (file)
@@ -14,7 +14,7 @@
  * setup_fault_attr() is a helper function for various __setup handlers, so it
  * returns 0 on error, because that is what __setup handlers do.
  */
-int __init setup_fault_attr(struct fault_attr *attr, char *str)
+int setup_fault_attr(struct fault_attr *attr, char *str)
 {
        unsigned long probability;
        unsigned long interval;
@@ -36,6 +36,7 @@ int __init setup_fault_attr(struct fault_attr *attr, char *str)
 
        return 1;
 }
+EXPORT_SYMBOL_GPL(setup_fault_attr);
 
 static void fail_dump(struct fault_attr *attr)
 {
@@ -130,6 +131,7 @@ bool should_fail(struct fault_attr *attr, ssize_t size)
 
        return true;
 }
+EXPORT_SYMBOL_GPL(should_fail);
 
 #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
 
@@ -243,5 +245,6 @@ fail:
 
        return ERR_PTR(-ENOMEM);
 }
+EXPORT_SYMBOL_GPL(fault_create_debugfs_attr);
 
 #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
index 5acf9bb10968caa97ec123ca464906fff4de42bc..bbf211aea4ebed20f0190ccdf97c91baed7ad422 100644 (file)
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -767,8 +767,8 @@ EXPORT_SYMBOL(ida_pre_get);
  * @starting_id: id to start search at
  * @p_id:      pointer to the allocated handle
  *
- * Allocate new ID above or equal to @ida.  It should be called with
- * any required locks.
+ * Allocate new ID above or equal to @starting_id.  It should be called
+ * with any required locks.
  *
  * If memory is required, it will return %-EAGAIN, you should unlock
  * and go back to the ida_pre_get() call.  If the ida is full, it will
index 5e066759f551ef61feb3acd5ab72c147e554dd98..7a94c8f14e295faaa2a80958081f961dba6561ce 100644 (file)
 #include <linux/module.h>
 #include <linux/types.h>
 #include <asm/uaccess.h>
+#include "kstrtox.h"
 
-static int _kstrtoull(const char *s, unsigned int base, unsigned long long *res)
+const char *_parse_integer_fixup_radix(const char *s, unsigned int *base)
 {
-       unsigned long long acc;
-       int ok;
-
-       if (base == 0) {
+       if (*base == 0) {
                if (s[0] == '0') {
                        if (_tolower(s[1]) == 'x' && isxdigit(s[2]))
-                               base = 16;
+                               *base = 16;
                        else
-                               base = 8;
+                               *base = 8;
                } else
-                       base = 10;
+                       *base = 10;
        }
-       if (base == 16 && s[0] == '0' && _tolower(s[1]) == 'x')
+       if (*base == 16 && s[0] == '0' && _tolower(s[1]) == 'x')
                s += 2;
+       return s;
+}
 
-       acc = 0;
-       ok = 0;
+/*
+ * Convert non-negative integer string representation in explicitly given radix
+ * to an integer.
+ * Return number of characters consumed maybe or-ed with overflow bit.
+ * If overflow occurs, result integer (incorrect) is still returned.
+ *
+ * Don't you dare use this function.
+ */
+unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long *res)
+{
+       unsigned int rv;
+       int overflow;
+
+       *res = 0;
+       rv = 0;
+       overflow = 0;
        while (*s) {
                unsigned int val;
 
@@ -45,23 +59,40 @@ static int _kstrtoull(const char *s, unsigned int base, unsigned long long *res)
                        val = *s - '0';
                else if ('a' <= _tolower(*s) && _tolower(*s) <= 'f')
                        val = _tolower(*s) - 'a' + 10;
-               else if (*s == '\n' && *(s + 1) == '\0')
-                       break;
                else
-                       return -EINVAL;
+                       break;
 
                if (val >= base)
-                       return -EINVAL;
-               if (acc > div_u64(ULLONG_MAX - val, base))
-                       return -ERANGE;
-               acc = acc * base + val;
-               ok = 1;
-
+                       break;
+               if (*res > div_u64(ULLONG_MAX - val, base))
+                       overflow = 1;
+               *res = *res * base + val;
+               rv++;
                s++;
        }
-       if (!ok)
+       if (overflow)
+               rv |= KSTRTOX_OVERFLOW;
+       return rv;
+}
+
+static int _kstrtoull(const char *s, unsigned int base, unsigned long long *res)
+{
+       unsigned long long _res;
+       unsigned int rv;
+
+       s = _parse_integer_fixup_radix(s, &base);
+       rv = _parse_integer(s, base, &_res);
+       if (rv & KSTRTOX_OVERFLOW)
+               return -ERANGE;
+       rv &= ~KSTRTOX_OVERFLOW;
+       if (rv == 0)
+               return -EINVAL;
+       s += rv;
+       if (*s == '\n')
+               s++;
+       if (*s)
                return -EINVAL;
-       *res = acc;
+       *res = _res;
        return 0;
 }
 
diff --git a/lib/kstrtox.h b/lib/kstrtox.h
new file mode 100644 (file)
index 0000000..f13eeea
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef _LIB_KSTRTOX_H
+#define _LIB_KSTRTOX_H
+
+#define KSTRTOX_OVERFLOW       (1U << 31)
+const char *_parse_integer_fixup_radix(const char *s, unsigned int *base);
+unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long *res);
+
+#endif
index f087105ed91454e054b4cf9c4da75a864e2b1edb..f8a3f1a829b8a9d767bed39c5138c7015380196b 100644 (file)
 #include <linux/module.h>
 #include <linux/debugobjects.h>
 
+#ifdef CONFIG_HOTPLUG_CPU
 static LIST_HEAD(percpu_counters);
 static DEFINE_MUTEX(percpu_counters_lock);
+#endif
 
 #ifdef CONFIG_DEBUG_OBJECTS_PERCPU_COUNTER
 
index a2f9da59c1970cfab2a55c94f43da8843551ef05..d9df7454519cd546c71aa10adf14204bee86ef7f 100644 (file)
@@ -576,7 +576,6 @@ int radix_tree_tag_get(struct radix_tree_root *root,
 {
        unsigned int height, shift;
        struct radix_tree_node *node;
-       int saw_unset_tag = 0;
 
        /* check the root's tag bit */
        if (!root_tag_get(root, tag))
@@ -603,15 +602,10 @@ int radix_tree_tag_get(struct radix_tree_root *root,
                        return 0;
 
                offset = (index >> shift) & RADIX_TREE_MAP_MASK;
-
-               /*
-                * This is just a debug check.  Later, we can bale as soon as
-                * we see an unset tag.
-                */
                if (!tag_get(node, tag, offset))
-                       saw_unset_tag = 1;
+                       return 0;
                if (height == 1)
-                       return !!tag_get(node, tag, offset);
+                       return 1;
                node = rcu_dereference_raw(node->slots[offset]);
                shift -= RADIX_TREE_MAP_SHIFT;
                height--;
index 4755b98b6dfb83b01055a1856739b7a805839466..5f3eacdd6178d122b9d35fc8e8f9daf12e3b119b 100644 (file)
@@ -49,13 +49,10 @@ void __rwlock_init(rwlock_t *lock, const char *name,
 
 EXPORT_SYMBOL(__rwlock_init);
 
-static void spin_bug(raw_spinlock_t *lock, const char *msg)
+static void spin_dump(raw_spinlock_t *lock, const char *msg)
 {
        struct task_struct *owner = NULL;
 
-       if (!debug_locks_off())
-               return;
-
        if (lock->owner && lock->owner != SPINLOCK_OWNER_INIT)
                owner = lock->owner;
        printk(KERN_EMERG "BUG: spinlock %s on CPU#%d, %s/%d\n",
@@ -70,6 +67,14 @@ static void spin_bug(raw_spinlock_t *lock, const char *msg)
        dump_stack();
 }
 
+static void spin_bug(raw_spinlock_t *lock, const char *msg)
+{
+       if (!debug_locks_off())
+               return;
+
+       spin_dump(lock, msg);
+}
+
 #define SPIN_BUG_ON(cond, lock, msg) if (unlikely(cond)) spin_bug(lock, msg)
 
 static inline void
@@ -113,11 +118,7 @@ static void __spin_lock_debug(raw_spinlock_t *lock)
                /* lockup suspected: */
                if (print_once) {
                        print_once = 0;
-                       printk(KERN_EMERG "BUG: spinlock lockup on CPU#%d, "
-                                       "%s/%d, %p\n",
-                               raw_smp_processor_id(), current->comm,
-                               task_pid_nr(current), lock);
-                       dump_stack();
+                       spin_dump(lock, "lockup");
 #ifdef CONFIG_SMP
                        trigger_all_cpu_backtrace();
 #endif
index 01fad9b203e192eb8a3299d669c29e11e4cf2e04..dc4a86341f914f0c26b92977d6f99dcc4df482c2 100644 (file)
@@ -360,7 +360,6 @@ char *strim(char *s)
        size_t size;
        char *end;
 
-       s = skip_spaces(s);
        size = strlen(s);
        if (!size)
                return s;
@@ -370,7 +369,7 @@ char *strim(char *s)
                end--;
        *(end + 1) = '\0';
 
-       return s;
+       return skip_spaces(s);
 }
 EXPORT_SYMBOL(strim);
 
@@ -756,3 +755,57 @@ void *memchr(const void *s, int c, size_t n)
 }
 EXPORT_SYMBOL(memchr);
 #endif
+
+static void *check_bytes8(const u8 *start, u8 value, unsigned int bytes)
+{
+       while (bytes) {
+               if (*start != value)
+                       return (void *)start;
+               start++;
+               bytes--;
+       }
+       return NULL;
+}
+
+/**
+ * memchr_inv - Find an unmatching character in an area of memory.
+ * @start: The memory area
+ * @c: Find a character other than c
+ * @bytes: The size of the area.
+ *
+ * returns the address of the first character other than @c, or %NULL
+ * if the whole buffer contains just @c.
+ */
+void *memchr_inv(const void *start, int c, size_t bytes)
+{
+       u8 value = c;
+       u64 value64;
+       unsigned int words, prefix;
+
+       if (bytes <= 16)
+               return check_bytes8(start, value, bytes);
+
+       value64 = value | value << 8 | value << 16 | value << 24;
+       value64 = (value64 & 0xffffffff) | value64 << 32;
+       prefix = 8 - ((unsigned long)start) % 8;
+
+       if (prefix) {
+               u8 *r = check_bytes8(start, value, prefix);
+               if (r)
+                       return r;
+               start += prefix;
+               bytes -= prefix;
+       }
+
+       words = bytes / 8;
+
+       while (words) {
+               if (*(u64 *)start != value64)
+                       return check_bytes8(start, value, 8);
+               start += 8;
+               words--;
+       }
+
+       return check_bytes8(start, value, bytes % 8);
+}
+EXPORT_SYMBOL(memchr_inv);
index d7222a9c82671ea835377022fc3fbaf9f2364cd0..993599e66e5a91bf4a5ff22565b4a7560651128c 100644 (file)
 #include <asm/div64.h>
 #include <asm/sections.h>      /* for dereference_function_descriptor() */
 
-static unsigned int simple_guess_base(const char *cp)
-{
-       if (cp[0] == '0') {
-               if (_tolower(cp[1]) == 'x' && isxdigit(cp[2]))
-                       return 16;
-               else
-                       return 8;
-       } else {
-               return 10;
-       }
-}
+#include "kstrtox.h"
 
 /**
  * simple_strtoull - convert a string to an unsigned long long
@@ -51,23 +41,14 @@ static unsigned int simple_guess_base(const char *cp)
  */
 unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base)
 {
-       unsigned long long result = 0;
+       unsigned long long result;
+       unsigned int rv;
 
-       if (!base)
-               base = simple_guess_base(cp);
+       cp = _parse_integer_fixup_radix(cp, &base);
+       rv = _parse_integer(cp, base, &result);
+       /* FIXME */
+       cp += (rv & ~KSTRTOX_OVERFLOW);
 
-       if (base == 16 && cp[0] == '0' && _tolower(cp[1]) == 'x')
-               cp += 2;
-
-       while (isxdigit(*cp)) {
-               unsigned int value;
-
-               value = isdigit(*cp) ? *cp - '0' : _tolower(*cp) - 'a' + 10;
-               if (value >= base)
-                       break;
-               result = result * base + value;
-               cp++;
-       }
        if (endp)
                *endp = (char *)cp;
 
@@ -566,7 +547,7 @@ char *mac_address_string(char *buf, char *end, u8 *addr,
        }
 
        for (i = 0; i < 6; i++) {
-               p = pack_hex_byte(p, addr[i]);
+               p = hex_byte_pack(p, addr[i]);
                if (fmt[0] == 'M' && i != 5)
                        *p++ = separator;
        }
@@ -686,13 +667,13 @@ char *ip6_compressed_string(char *p, const char *addr)
                lo = word & 0xff;
                if (hi) {
                        if (hi > 0x0f)
-                               p = pack_hex_byte(p, hi);
+                               p = hex_byte_pack(p, hi);
                        else
                                *p++ = hex_asc_lo(hi);
-                       p = pack_hex_byte(p, lo);
+                       p = hex_byte_pack(p, lo);
                }
                else if (lo > 0x0f)
-                       p = pack_hex_byte(p, lo);
+                       p = hex_byte_pack(p, lo);
                else
                        *p++ = hex_asc_lo(lo);
                needcolon = true;
@@ -714,8 +695,8 @@ char *ip6_string(char *p, const char *addr, const char *fmt)
        int i;
 
        for (i = 0; i < 8; i++) {
-               p = pack_hex_byte(p, *addr++);
-               p = pack_hex_byte(p, *addr++);
+               p = hex_byte_pack(p, *addr++);
+               p = hex_byte_pack(p, *addr++);
                if (fmt[0] == 'I' && i != 7)
                        *p++ = ':';
        }
@@ -773,7 +754,7 @@ char *uuid_string(char *buf, char *end, const u8 *addr,
        }
 
        for (i = 0; i < 16; i++) {
-               p = pack_hex_byte(p, addr[index[i]]);
+               p = hex_byte_pack(p, addr[index[i]]);
                switch (i) {
                case 3:
                case 5:
index f2f1ca19ed535916af50fcce19a58febda83d38e..011b110365c8681d7b1c546223bdb8a2daccc59d 100644 (file)
@@ -131,6 +131,9 @@ config SPARSEMEM_VMEMMAP
 config HAVE_MEMBLOCK
        boolean
 
+config NO_BOOTMEM
+       boolean
+
 # eventually, we can have this option just 'select SPARSEMEM'
 config MEMORY_HOTPLUG
        bool "Allow for memory hot-add"
index 836e4163c1bfd91c5742c9f5227fc105d79a3b76..50ec00ef2a0e85a11ef8202529b405b069702a8d 100644 (file)
@@ -5,7 +5,8 @@
 mmu-y                  := nommu.o
 mmu-$(CONFIG_MMU)      := fremap.o highmem.o madvise.o memory.o mincore.o \
                           mlock.o mmap.o mprotect.o mremap.o msync.o rmap.o \
-                          vmalloc.o pagewalk.o pgtable-generic.o
+                          vmalloc.o pagewalk.o pgtable-generic.o \
+                          process_vm_access.o
 
 obj-y                  := filemap.o mempool.o oom_kill.o fadvise.o \
                           maccess.o page_alloc.o page-writeback.o \
index a87da524a4a01ad288e10e9648593d8934adb4fc..7520ef0bfd47932653948f0f3b047abd021d2ef1 100644 (file)
@@ -404,9 +404,8 @@ static int bdi_forker_thread(void *ptr)
                /*
                 * In the following loop we are going to check whether we have
                 * some work to do without any synchronization with tasks
-                * waking us up to do work for them. So we have to set task
-                * state already here so that we don't miss wakeups coming
-                * after we verify some condition.
+                * waking us up to do work for them. Set the task state here
+                * so that we don't miss wakeups after verifying conditions.
                 */
                set_current_state(TASK_INTERRUPTIBLE);
 
index 6cc604bd56496e2742e371d63234af08f9f0859b..899d95638586fcc65b44d631705845bef6245be3 100644 (file)
@@ -35,10 +35,6 @@ struct compact_control {
        unsigned long migrate_pfn;      /* isolate_migratepages search base */
        bool sync;                      /* Synchronous migration */
 
-       /* Account for isolated anon and file pages */
-       unsigned long nr_anon;
-       unsigned long nr_file;
-
        unsigned int order;             /* order a direct compactor needs */
        int migratetype;                /* MOVABLE, RECLAIMABLE etc */
        struct zone *zone;
@@ -223,17 +219,13 @@ static void isolate_freepages(struct zone *zone,
 static void acct_isolated(struct zone *zone, struct compact_control *cc)
 {
        struct page *page;
-       unsigned int count[NR_LRU_LISTS] = { 0, };
+       unsigned int count[2] = { 0, };
 
-       list_for_each_entry(page, &cc->migratepages, lru) {
-               int lru = page_lru_base_type(page);
-               count[lru]++;
-       }
+       list_for_each_entry(page, &cc->migratepages, lru)
+               count[!!page_is_file_cache(page)]++;
 
-       cc->nr_anon = count[LRU_ACTIVE_ANON] + count[LRU_INACTIVE_ANON];
-       cc->nr_file = count[LRU_ACTIVE_FILE] + count[LRU_INACTIVE_FILE];
-       __mod_zone_page_state(zone, NR_ISOLATED_ANON, cc->nr_anon);
-       __mod_zone_page_state(zone, NR_ISOLATED_FILE, cc->nr_file);
+       __mod_zone_page_state(zone, NR_ISOLATED_ANON, count[0]);
+       __mod_zone_page_state(zone, NR_ISOLATED_FILE, count[1]);
 }
 
 /* Similar to reclaim, but different enough that they don't share logic */
@@ -269,6 +261,7 @@ static isolate_migrate_t isolate_migratepages(struct zone *zone,
        unsigned long last_pageblock_nr = 0, pageblock_nr;
        unsigned long nr_scanned = 0, nr_isolated = 0;
        struct list_head *migratelist = &cc->migratepages;
+       isolate_mode_t mode = ISOLATE_ACTIVE|ISOLATE_INACTIVE;
 
        /* Do not scan outside zone boundaries */
        low_pfn = max(cc->migrate_pfn, zone->zone_start_pfn);
@@ -356,8 +349,11 @@ static isolate_migrate_t isolate_migratepages(struct zone *zone,
                        continue;
                }
 
+               if (!cc->sync)
+                       mode |= ISOLATE_CLEAN;
+
                /* Try isolate the page */
-               if (__isolate_lru_page(page, ISOLATE_BOTH, 0) != 0)
+               if (__isolate_lru_page(page, mode, 0) != 0)
                        continue;
 
                VM_BUG_ON(PageTransCompound(page));
@@ -586,7 +582,7 @@ out:
        return ret;
 }
 
-unsigned long compact_zone_order(struct zone *zone,
+static unsigned long compact_zone_order(struct zone *zone,
                                 int order, gfp_t gfp_mask,
                                 bool sync)
 {
index a1e3324de2b5ead95f5ab35371d46f953e816adc..7cea557407f40ef96351a91ade5fd3b9cbe915c0 100644 (file)
@@ -1,7 +1,10 @@
 #include <linux/kernel.h>
+#include <linux/string.h>
 #include <linux/mm.h>
+#include <linux/highmem.h>
 #include <linux/page-debug-flags.h>
 #include <linux/poison.h>
+#include <linux/ratelimit.h>
 
 static inline void set_page_poison(struct page *page)
 {
@@ -18,28 +21,13 @@ static inline bool page_poison(struct page *page)
        return test_bit(PAGE_DEBUG_FLAG_POISON, &page->debug_flags);
 }
 
-static void poison_highpage(struct page *page)
-{
-       /*
-        * Page poisoning for highmem pages is not implemented.
-        *
-        * This can be called from interrupt contexts.
-        * So we need to create a new kmap_atomic slot for this
-        * application and it will need interrupt protection.
-        */
-}
-
 static void poison_page(struct page *page)
 {
-       void *addr;
+       void *addr = kmap_atomic(page);
 
-       if (PageHighMem(page)) {
-               poison_highpage(page);
-               return;
-       }
        set_page_poison(page);
-       addr = page_address(page);
        memset(addr, PAGE_POISON, PAGE_SIZE);
+       kunmap_atomic(addr);
 }
 
 static void poison_pages(struct page *page, int n)
@@ -59,14 +47,12 @@ static bool single_bit_flip(unsigned char a, unsigned char b)
 
 static void check_poison_mem(unsigned char *mem, size_t bytes)
 {
+       static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 10);
        unsigned char *start;
        unsigned char *end;
 
-       for (start = mem; start < mem + bytes; start++) {
-               if (*start != PAGE_POISON)
-                       break;
-       }
-       if (start == mem + bytes)
+       start = memchr_inv(mem, PAGE_POISON, bytes);
+       if (!start)
                return;
 
        for (end = mem + bytes - 1; end > start; end--) {
@@ -74,7 +60,7 @@ static void check_poison_mem(unsigned char *mem, size_t bytes)
                        break;
        }
 
-       if (!printk_ratelimit())
+       if (!__ratelimit(&ratelimit))
                return;
        else if (start == end && single_bit_flip(*start, PAGE_POISON))
                printk(KERN_ERR "pagealloc: single bit error\n");
@@ -86,27 +72,17 @@ static void check_poison_mem(unsigned char *mem, size_t bytes)
        dump_stack();
 }
 
-static void unpoison_highpage(struct page *page)
-{
-       /*
-        * See comment in poison_highpage().
-        * Highmem pages should not be poisoned for now
-        */
-       BUG_ON(page_poison(page));
-}
-
 static void unpoison_page(struct page *page)
 {
-       if (PageHighMem(page)) {
-               unpoison_highpage(page);
+       void *addr;
+
+       if (!page_poison(page))
                return;
-       }
-       if (page_poison(page)) {
-               void *addr = page_address(page);
 
-               check_poison_mem(addr, PAGE_SIZE);
-               clear_page_poison(page);
-       }
+       addr = kmap_atomic(page);
+       check_poison_mem(addr, PAGE_SIZE);
+       clear_page_poison(page);
+       kunmap_atomic(addr);
 }
 
 static void unpoison_pages(struct page *page, int n)
index 5ef672c07f752a68938623651b8caa574285222c..e159a7b1cc226c72cdb369f30852eb343491eddd 100644 (file)
@@ -250,7 +250,7 @@ void *kmap_high_get(struct page *page)
 #endif
 
 /**
- * kunmap_high - map a highmem page into memory
+ * kunmap_high - unmap a highmem page into memory
  * @page: &struct page to unmap
  *
  * If ARCH_NEEDS_KMAP_HIGH_GET is not defined then this may be called
index e2d1587be269bf475a5ce2c05e6d10d9648a2121..860ec211ddd667175eca0abb95e82a01cdaa8e1e 100644 (file)
@@ -89,7 +89,8 @@ struct khugepaged_scan {
        struct list_head mm_head;
        struct mm_slot *mm_slot;
        unsigned long address;
-} khugepaged_scan = {
+};
+static struct khugepaged_scan khugepaged_scan = {
        .mm_head = LIST_HEAD_INIT(khugepaged_scan.mm_head),
 };
 
@@ -829,7 +830,7 @@ static int do_huge_pmd_wp_page_fallback(struct mm_struct *mm,
 
        for (i = 0; i < HPAGE_PMD_NR; i++) {
                copy_user_highpage(pages[i], page + i,
-                                  haddr + PAGE_SHIFT*i, vma);
+                                  haddr + PAGE_SIZE * i, vma);
                __SetPageUptodate(pages[i]);
                cond_resched();
        }
@@ -1052,6 +1053,51 @@ int mincore_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
        return ret;
 }
 
+int move_huge_pmd(struct vm_area_struct *vma, struct vm_area_struct *new_vma,
+                 unsigned long old_addr,
+                 unsigned long new_addr, unsigned long old_end,
+                 pmd_t *old_pmd, pmd_t *new_pmd)
+{
+       int ret = 0;
+       pmd_t pmd;
+
+       struct mm_struct *mm = vma->vm_mm;
+
+       if ((old_addr & ~HPAGE_PMD_MASK) ||
+           (new_addr & ~HPAGE_PMD_MASK) ||
+           old_end - old_addr < HPAGE_PMD_SIZE ||
+           (new_vma->vm_flags & VM_NOHUGEPAGE))
+               goto out;
+
+       /*
+        * The destination pmd shouldn't be established, free_pgtables()
+        * should have release it.
+        */
+       if (WARN_ON(!pmd_none(*new_pmd))) {
+               VM_BUG_ON(pmd_trans_huge(*new_pmd));
+               goto out;
+       }
+
+       spin_lock(&mm->page_table_lock);
+       if (likely(pmd_trans_huge(*old_pmd))) {
+               if (pmd_trans_splitting(*old_pmd)) {
+                       spin_unlock(&mm->page_table_lock);
+                       wait_split_huge_page(vma->anon_vma, old_pmd);
+                       ret = -1;
+               } else {
+                       pmd = pmdp_get_and_clear(mm, old_addr, old_pmd);
+                       VM_BUG_ON(!pmd_none(*new_pmd));
+                       set_pmd_at(mm, new_addr, new_pmd, pmd);
+                       spin_unlock(&mm->page_table_lock);
+                       ret = 1;
+               }
+       } else {
+               spin_unlock(&mm->page_table_lock);
+       }
+out:
+       return ret;
+}
+
 int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
                unsigned long addr, pgprot_t newprot)
 {
@@ -1906,7 +1952,7 @@ static void collapse_huge_page(struct mm_struct *mm,
        BUG_ON(!pmd_none(*pmd));
        page_add_new_anon_rmap(new_page, vma, address);
        set_pmd_at(mm, address, pmd, _pmd);
-       update_mmu_cache(vma, address, entry);
+       update_mmu_cache(vma, address, _pmd);
        prepare_pmd_huge_pte(pgtable, mm);
        mm->nr_ptes--;
        spin_unlock(&mm->page_table_lock);
@@ -2024,6 +2070,8 @@ static void collect_mm_slot(struct mm_slot *mm_slot)
 
 static unsigned int khugepaged_scan_mm_slot(unsigned int pages,
                                            struct page **hpage)
+       __releases(&khugepaged_mm_lock)
+       __acquires(&khugepaged_mm_lock)
 {
        struct mm_slot *mm_slot;
        struct mm_struct *mm;
index 9a68b0cf0a1c4c8009ee25d2990530d7e2927132..310544a379ae9c7b886b3b50815e5f3d5a991ba8 100644 (file)
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -1905,7 +1905,8 @@ static ssize_t run_store(struct kobject *kobj, struct kobj_attribute *attr,
 
                        oom_score_adj = test_set_oom_score_adj(OOM_SCORE_ADJ_MAX);
                        err = unmerge_and_remove_all_rmap_items();
-                       test_set_oom_score_adj(oom_score_adj);
+                       compare_swap_oom_score_adj(OOM_SCORE_ADJ_MAX,
+                                                               oom_score_adj);
                        if (err) {
                                ksm_run = KSM_RUN_STOP;
                                count = err;
index ccbf97339592fe2335dfe6994fed8112f3ecdfc5..84bec4969ed5d3a27d9c6035da6e39ebf1dfdd18 100644 (file)
@@ -58,7 +58,8 @@ static unsigned long __init_memblock memblock_addrs_overlap(phys_addr_t base1, p
        return ((base1 < (base2 + size2)) && (base2 < (base1 + size1)));
 }
 
-long __init_memblock memblock_overlaps_region(struct memblock_type *type, phys_addr_t base, phys_addr_t size)
+static long __init_memblock memblock_overlaps_region(struct memblock_type *type,
+                                       phys_addr_t base, phys_addr_t size)
 {
        unsigned long i;
 
@@ -267,7 +268,7 @@ static int __init_memblock memblock_double_array(struct memblock_type *type)
        return 0;
 }
 
-extern int __init_memblock __weak memblock_memory_can_coalesce(phys_addr_t addr1, phys_addr_t size1,
+int __init_memblock __weak memblock_memory_can_coalesce(phys_addr_t addr1, phys_addr_t size1,
                                          phys_addr_t addr2, phys_addr_t size2)
 {
        return 1;
@@ -626,6 +627,12 @@ phys_addr_t __init memblock_phys_mem_size(void)
        return memblock.memory_size;
 }
 
+/* lowest address */
+phys_addr_t __init_memblock memblock_start_of_DRAM(void)
+{
+       return memblock.memory.regions[0].base;
+}
+
 phys_addr_t __init_memblock memblock_end_of_DRAM(void)
 {
        int idx = memblock.memory.cnt - 1;
index 3508777837c70824a946e931f7cf7fa7b1424399..2d5755544afe5fa165e1524e2500ab56bf8ad8c8 100644 (file)
@@ -1185,7 +1185,8 @@ mem_cgroup_get_reclaim_stat_from_page(struct page *page)
 unsigned long mem_cgroup_isolate_pages(unsigned long nr_to_scan,
                                        struct list_head *dst,
                                        unsigned long *scanned, int order,
-                                       int mode, struct zone *z,
+                                       isolate_mode_t mode,
+                                       struct zone *z,
                                        struct mem_cgroup *mem_cont,
                                        int active, int file)
 {
index 2b43ba051ac94f0512744707fe197d27a6d562b1..edc388db730a2cb41f6290e98853fbbc0ac04a7b 100644 (file)
@@ -1310,7 +1310,7 @@ int unpoison_memory(unsigned long pfn)
                 * to the end.
                 */
                if (PageHuge(page)) {
-                       pr_debug("MCE: Memory failure is now running on free hugepage %#lx\n", pfn);
+                       pr_info("MCE: Memory failure is now running on free hugepage %#lx\n", pfn);
                        return 0;
                }
                if (TestClearPageHWPoison(p))
@@ -1419,7 +1419,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
 
        if (PageHWPoison(hpage)) {
                put_page(hpage);
-               pr_debug("soft offline: %#lx hugepage already poisoned\n", pfn);
+               pr_info("soft offline: %#lx hugepage already poisoned\n", pfn);
                return -EBUSY;
        }
 
@@ -1433,8 +1433,8 @@ static int soft_offline_huge_page(struct page *page, int flags)
                list_for_each_entry_safe(page1, page2, &pagelist, lru)
                        put_page(page1);
 
-               pr_debug("soft offline: %#lx: migration failed %d, type %lx\n",
-                        pfn, ret, page->flags);
+               pr_info("soft offline: %#lx: migration failed %d, type %lx\n",
+                       pfn, ret, page->flags);
                if (ret > 0)
                        ret = -EIO;
                return ret;
@@ -1505,7 +1505,7 @@ int soft_offline_page(struct page *page, int flags)
        }
        if (!PageLRU(page)) {
                pr_info("soft_offline: %#lx: unknown non LRU page type %lx\n",
-                               pfn, page->flags);
+                       pfn, page->flags);
                return -EIO;
        }
 
@@ -1566,7 +1566,7 @@ int soft_offline_page(struct page *page, int flags)
                }
        } else {
                pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
-                               pfn, ret, page_count(page), page->flags);
+                       pfn, ret, page_count(page), page->flags);
        }
        if (ret)
                return ret;
index 9c51f9f58cacc8d4a9c9f363fd5f8778ebfac190..cd237f478304152bdd107bd8cbbb108ed39b7154 100644 (file)
@@ -111,7 +111,7 @@ enum zone_type policy_zone = 0;
 /*
  * run-time system-wide default policy => local allocation
  */
-struct mempolicy default_policy = {
+static struct mempolicy default_policy = {
        .refcnt = ATOMIC_INIT(1), /* never free it */
        .mode = MPOL_PREFERRED,
        .flags = MPOL_F_LOCAL,
index 14d0a6a632f6f8fb2dd0240d35c4853ff67d176d..33358f8781118ae9153ac4eb3e00530ca2f20e93 100644 (file)
@@ -621,38 +621,18 @@ static int move_to_new_page(struct page *newpage, struct page *page,
        return rc;
 }
 
-/*
- * Obtain the lock on page, remove all ptes and migrate the page
- * to the newly allocated page in newpage.
- */
-static int unmap_and_move(new_page_t get_new_page, unsigned long private,
-                       struct page *page, int force, bool offlining, bool sync)
+static int __unmap_and_move(struct page *page, struct page *newpage,
+                               int force, bool offlining, bool sync)
 {
-       int rc = 0;
-       int *result = NULL;
-       struct page *newpage = get_new_page(page, private, &result);
+       int rc = -EAGAIN;
        int remap_swapcache = 1;
        int charge = 0;
        struct mem_cgroup *mem;
        struct anon_vma *anon_vma = NULL;
 
-       if (!newpage)
-               return -ENOMEM;
-
-       if (page_count(page) == 1) {
-               /* page was freed from under us. So we are done. */
-               goto move_newpage;
-       }
-       if (unlikely(PageTransHuge(page)))
-               if (unlikely(split_huge_page(page)))
-                       goto move_newpage;
-
-       /* prepare cgroup just returns 0 or -ENOMEM */
-       rc = -EAGAIN;
-
        if (!trylock_page(page)) {
                if (!force || !sync)
-                       goto move_newpage;
+                       goto out;
 
                /*
                 * It's not safe for direct compaction to call lock_page.
@@ -668,7 +648,7 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private,
                 * altogether.
                 */
                if (current->flags & PF_MEMALLOC)
-                       goto move_newpage;
+                       goto out;
 
                lock_page(page);
        }
@@ -785,27 +765,52 @@ uncharge:
                mem_cgroup_end_migration(mem, page, newpage, rc == 0);
 unlock:
        unlock_page(page);
+out:
+       return rc;
+}
 
-move_newpage:
+/*
+ * Obtain the lock on page, remove all ptes and migrate the page
+ * to the newly allocated page in newpage.
+ */
+static int unmap_and_move(new_page_t get_new_page, unsigned long private,
+                       struct page *page, int force, bool offlining, bool sync)
+{
+       int rc = 0;
+       int *result = NULL;
+       struct page *newpage = get_new_page(page, private, &result);
+
+       if (!newpage)
+               return -ENOMEM;
+
+       if (page_count(page) == 1) {
+               /* page was freed from under us. So we are done. */
+               goto out;
+       }
+
+       if (unlikely(PageTransHuge(page)))
+               if (unlikely(split_huge_page(page)))
+                       goto out;
+
+       rc = __unmap_and_move(page, newpage, force, offlining, sync);
+out:
        if (rc != -EAGAIN) {
-               /*
-                * A page that has been migrated has all references
-                * removed and will be freed. A page that has not been
-                * migrated will have kepts its references and be
-                * restored.
-                */
-               list_del(&page->lru);
+               /*
+                * A page that has been migrated has all references
+                * removed and will be freed. A page that has not been
+                * migrated will have kepts its references and be
+                * restored.
+                */
+               list_del(&page->lru);
                dec_zone_page_state(page, NR_ISOLATED_ANON +
                                page_is_file_cache(page));
                putback_lru_page(page);
        }
-
        /*
         * Move the new page to the LRU. If migration was not successful
         * then this will free the page.
         */
        putback_lru_page(newpage);
-
        if (result) {
                if (rc)
                        *result = rc;
index 048260c4e02ea7ced2692cc05fba67c9798c9145..bd34b3a10852c3d3ac3b1808653721a6114549c2 100644 (file)
@@ -110,7 +110,15 @@ void munlock_vma_page(struct page *page)
        if (TestClearPageMlocked(page)) {
                dec_zone_page_state(page, NR_MLOCK);
                if (!isolate_lru_page(page)) {
-                       int ret = try_to_munlock(page);
+                       int ret = SWAP_AGAIN;
+
+                       /*
+                        * Optimization: if the page was mapped just once,
+                        * that's our mapping and we don't need to check all the
+                        * other vmas.
+                        */
+                       if (page_mapcount(page) > 1)
+                               ret = try_to_munlock(page);
                        /*
                         * did try_to_unlock() succeed or punt?
                         */
@@ -549,7 +557,8 @@ SYSCALL_DEFINE1(mlockall, int, flags)
        if (!can_do_mlock())
                goto out;
 
-       lru_add_drain_all();    /* flush pagevec */
+       if (flags & MCL_CURRENT)
+               lru_add_drain_all();    /* flush pagevec */
 
        down_write(&current->mm->mmap_sem);
 
index a65efd4db3e1e9e8228d7f33d787f431edff9df2..3c0061f744f50cad8fd79eab118d7a54561fa654 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2558,7 +2558,6 @@ int mm_take_all_locks(struct mm_struct *mm)
 {
        struct vm_area_struct *vma;
        struct anon_vma_chain *avc;
-       int ret = -EINTR;
 
        BUG_ON(down_read_trylock(&mm->mmap_sem));
 
@@ -2579,13 +2578,11 @@ int mm_take_all_locks(struct mm_struct *mm)
                                vm_lock_anon_vma(mm, avc->anon_vma);
        }
 
-       ret = 0;
+       return 0;
 
 out_unlock:
-       if (ret)
-               mm_drop_all_locks(mm);
-
-       return ret;
+       mm_drop_all_locks(mm);
+       return -EINTR;
 }
 
 static void vm_unlock_anon_vma(struct anon_vma *anon_vma)
index 506fa44403df5cc3215cb69ec2d1098a96bb7919..d6959cb4df58f1d694c179898553bf7e3150cc49 100644 (file)
@@ -41,8 +41,7 @@ static pmd_t *get_old_pmd(struct mm_struct *mm, unsigned long addr)
                return NULL;
 
        pmd = pmd_offset(pud, addr);
-       split_huge_page_pmd(mm, pmd);
-       if (pmd_none_or_clear_bad(pmd))
+       if (pmd_none(*pmd))
                return NULL;
 
        return pmd;
@@ -65,8 +64,6 @@ static pmd_t *alloc_new_pmd(struct mm_struct *mm, struct vm_area_struct *vma,
                return NULL;
 
        VM_BUG_ON(pmd_trans_huge(*pmd));
-       if (pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, addr))
-               return NULL;
 
        return pmd;
 }
@@ -80,11 +77,7 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
        struct mm_struct *mm = vma->vm_mm;
        pte_t *old_pte, *new_pte, pte;
        spinlock_t *old_ptl, *new_ptl;
-       unsigned long old_start;
 
-       old_start = old_addr;
-       mmu_notifier_invalidate_range_start(vma->vm_mm,
-                                           old_start, old_end);
        if (vma->vm_file) {
                /*
                 * Subtle point from Rajesh Venkatasubramanian: before
@@ -111,7 +104,7 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
                                   new_pte++, new_addr += PAGE_SIZE) {
                if (pte_none(*old_pte))
                        continue;
-               pte = ptep_clear_flush(vma, old_addr, old_pte);
+               pte = ptep_get_and_clear(mm, old_addr, old_pte);
                pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
                set_pte_at(mm, new_addr, new_pte, pte);
        }
@@ -123,7 +116,6 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
        pte_unmap_unlock(old_pte - 1, old_ptl);
        if (mapping)
                mutex_unlock(&mapping->i_mmap_mutex);
-       mmu_notifier_invalidate_range_end(vma->vm_mm, old_start, old_end);
 }
 
 #define LATENCY_LIMIT  (64 * PAGE_SIZE)
@@ -134,22 +126,43 @@ unsigned long move_page_tables(struct vm_area_struct *vma,
 {
        unsigned long extent, next, old_end;
        pmd_t *old_pmd, *new_pmd;
+       bool need_flush = false;
 
        old_end = old_addr + len;
        flush_cache_range(vma, old_addr, old_end);
 
+       mmu_notifier_invalidate_range_start(vma->vm_mm, old_addr, old_end);
+
        for (; old_addr < old_end; old_addr += extent, new_addr += extent) {
                cond_resched();
                next = (old_addr + PMD_SIZE) & PMD_MASK;
-               if (next - 1 > old_end)
-                       next = old_end;
+               /* even if next overflowed, extent below will be ok */
                extent = next - old_addr;
+               if (extent > old_end - old_addr)
+                       extent = old_end - old_addr;
                old_pmd = get_old_pmd(vma->vm_mm, old_addr);
                if (!old_pmd)
                        continue;
                new_pmd = alloc_new_pmd(vma->vm_mm, vma, new_addr);
                if (!new_pmd)
                        break;
+               if (pmd_trans_huge(*old_pmd)) {
+                       int err = 0;
+                       if (extent == HPAGE_PMD_SIZE)
+                               err = move_huge_pmd(vma, new_vma, old_addr,
+                                                   new_addr, old_end,
+                                                   old_pmd, new_pmd);
+                       if (err > 0) {
+                               need_flush = true;
+                               continue;
+                       } else if (!err) {
+                               split_huge_page_pmd(vma->vm_mm, old_pmd);
+                       }
+                       VM_BUG_ON(pmd_trans_huge(*old_pmd));
+               }
+               if (pmd_none(*new_pmd) && __pte_alloc(new_vma->vm_mm, new_vma,
+                                                     new_pmd, new_addr))
+                       break;
                next = (new_addr + PMD_SIZE) & PMD_MASK;
                if (extent > next - new_addr)
                        extent = next - new_addr;
@@ -157,7 +170,12 @@ unsigned long move_page_tables(struct vm_area_struct *vma,
                        extent = LATENCY_LIMIT;
                move_ptes(vma, old_pmd, old_addr, old_addr + extent,
                                new_vma, new_pmd, new_addr);
+               need_flush = true;
        }
+       if (likely(need_flush))
+               flush_tlb_range(vma, old_end-len, old_addr);
+
+       mmu_notifier_invalidate_range_end(vma->vm_mm, old_end-len, old_end);
 
        return len + old_addr - old_end;        /* how much done */
 }
index 626303b52f3ce0764d3bb1029f6bce8b5bcaa896..e916168b6e0a8e6b70b4cb513f28591442ed8746 100644 (file)
 #include <linux/mempolicy.h>
 #include <linux/security.h>
 #include <linux/ptrace.h>
+#include <linux/freezer.h>
 
 int sysctl_panic_on_oom;
 int sysctl_oom_kill_allocating_task;
 int sysctl_oom_dump_tasks = 1;
 static DEFINE_SPINLOCK(zone_scan_lock);
 
+/*
+ * compare_swap_oom_score_adj() - compare and swap current's oom_score_adj
+ * @old_val: old oom_score_adj for compare
+ * @new_val: new oom_score_adj for swap
+ *
+ * Sets the oom_score_adj value for current to @new_val iff its present value is
+ * @old_val.  Usually used to reinstate a previous value to prevent racing with
+ * userspacing tuning the value in the interim.
+ */
+void compare_swap_oom_score_adj(int old_val, int new_val)
+{
+       struct sighand_struct *sighand = current->sighand;
+
+       spin_lock_irq(&sighand->siglock);
+       if (current->signal->oom_score_adj == old_val)
+               current->signal->oom_score_adj = new_val;
+       spin_unlock_irq(&sighand->siglock);
+}
+
 /**
  * test_set_oom_score_adj() - set current's oom_score_adj and return old value
  * @new_val: new oom_score_adj value
@@ -53,13 +73,7 @@ int test_set_oom_score_adj(int new_val)
 
        spin_lock_irq(&sighand->siglock);
        old_val = current->signal->oom_score_adj;
-       if (new_val != old_val) {
-               if (new_val == OOM_SCORE_ADJ_MIN)
-                       atomic_inc(&current->mm->oom_disable_count);
-               else if (old_val == OOM_SCORE_ADJ_MIN)
-                       atomic_dec(&current->mm->oom_disable_count);
-               current->signal->oom_score_adj = new_val;
-       }
+       current->signal->oom_score_adj = new_val;
        spin_unlock_irq(&sighand->siglock);
 
        return old_val;
@@ -171,16 +185,6 @@ unsigned int oom_badness(struct task_struct *p, struct mem_cgroup *mem,
        if (!p)
                return 0;
 
-       /*
-        * Shortcut check for a thread sharing p->mm that is OOM_SCORE_ADJ_MIN
-        * so the entire heuristic doesn't need to be executed for something
-        * that cannot be killed.
-        */
-       if (atomic_read(&p->mm->oom_disable_count)) {
-               task_unlock(p);
-               return 0;
-       }
-
        /*
         * The memory controller may have a limit of 0 bytes, so avoid a divide
         * by zero, if necessary.
@@ -317,8 +321,11 @@ static struct task_struct *select_bad_process(unsigned int *ppoints,
                 * blocked waiting for another task which itself is waiting
                 * for memory. Is there a better alternative?
                 */
-               if (test_tsk_thread_flag(p, TIF_MEMDIE))
+               if (test_tsk_thread_flag(p, TIF_MEMDIE)) {
+                       if (unlikely(frozen(p)))
+                               thaw_process(p);
                        return ERR_PTR(-1UL);
+               }
                if (!p->mm)
                        continue;
 
@@ -435,7 +442,7 @@ static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
        task_unlock(p);
 
        /*
-        * Kill all processes sharing p->mm in other thread groups, if any.
+        * Kill all user processes sharing p->mm in other thread groups, if any.
         * They don't get access to memory reserves or a higher scheduler
         * priority, though, to avoid depletion of all memory or task
         * starvation.  This prevents mm->mmap_sem livelock when an oom killed
@@ -445,7 +452,11 @@ static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
         * signal.
         */
        for_each_process(q)
-               if (q->mm == mm && !same_thread_group(q, p)) {
+               if (q->mm == mm && !same_thread_group(q, p) &&
+                   !(q->flags & PF_KTHREAD)) {
+                       if (q->signal->oom_score_adj == OOM_SCORE_ADJ_MIN)
+                               continue;
+
                        task_lock(q);   /* Protect ->comm from prctl() */
                        pr_err("Kill process %d (%s) sharing same memory\n",
                                task_pid_nr(q), q->comm);
@@ -722,7 +733,7 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
        read_lock(&tasklist_lock);
        if (sysctl_oom_kill_allocating_task &&
            !oom_unkillable_task(current, NULL, nodemask) &&
-           current->mm && !atomic_read(&current->mm->oom_disable_count)) {
+           current->mm) {
                /*
                 * oom_kill_process() needs tasklist_lock held.  If it returns
                 * non-zero, current could not be killed so we must fallback to
index 0e309cd1b5b9a2e2841a10205d7d91ad87083dc7..793e9874de51f39f1a1b4a2e86c974a671b6574d 100644 (file)
@@ -305,7 +305,9 @@ static unsigned long task_min_dirty_limit(unsigned long bdi_dirty)
 }
 
 /*
- *
+ * bdi_min_ratio keeps the sum of the minimum dirty shares of all
+ * registered backing devices, which, for obvious reasons, can not
+ * exceed 100%.
  */
 static unsigned int bdi_min_ratio;
 
index 6e8ecb6e021c7ebc4056a2eb23576c314721b858..9dd443d89d8be665813bbeb4e17e54fafde46428 100644 (file)
@@ -318,6 +318,7 @@ static void bad_page(struct page *page)
                current->comm, page_to_pfn(page));
        dump_page(page);
 
+       print_modules();
        dump_stack();
 out:
        /* Leave bad fields for debug, except PageBuddy could make trouble */
@@ -1753,7 +1754,6 @@ static DEFINE_RATELIMIT_STATE(nopage_rs,
 
 void warn_alloc_failed(gfp_t gfp_mask, int order, const char *fmt, ...)
 {
-       va_list args;
        unsigned int filter = SHOW_MEM_FILTER_NODES;
 
        if ((gfp_mask & __GFP_NOWARN) || !__ratelimit(&nopage_rs))
@@ -1772,14 +1772,21 @@ void warn_alloc_failed(gfp_t gfp_mask, int order, const char *fmt, ...)
                filter &= ~SHOW_MEM_FILTER_NODES;
 
        if (fmt) {
-               printk(KERN_WARNING);
+               struct va_format vaf;
+               va_list args;
+
                va_start(args, fmt);
-               vprintk(fmt, args);
+
+               vaf.fmt = fmt;
+               vaf.va = &args;
+
+               pr_warn("%pV", &vaf);
+
                va_end(args);
        }
 
-       pr_warning("%s: page allocation failure: order:%d, mode:0x%x\n",
-                  current->comm, order, gfp_mask);
+       pr_warn("%s: page allocation failure: order:%d, mode:0x%x\n",
+               current->comm, order, gfp_mask);
 
        dump_stack();
        if (!should_suppress_show_mem())
diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
new file mode 100644 (file)
index 0000000..e920aa3
--- /dev/null
@@ -0,0 +1,496 @@
+/*
+ * linux/mm/process_vm_access.c
+ *
+ * Copyright (C) 2010-2011 Christopher Yeoh <cyeoh@au1.ibm.com>, IBM Corp.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include <linux/mm.h>
+#include <linux/uio.h>
+#include <linux/sched.h>
+#include <linux/highmem.h>
+#include <linux/ptrace.h>
+#include <linux/slab.h>
+#include <linux/syscalls.h>
+
+#ifdef CONFIG_COMPAT
+#include <linux/compat.h>
+#endif
+
+/**
+ * process_vm_rw_pages - read/write pages from task specified
+ * @task: task to read/write from
+ * @mm: mm for task
+ * @process_pages: struct pages area that can store at least
+ *  nr_pages_to_copy struct page pointers
+ * @pa: address of page in task to start copying from/to
+ * @start_offset: offset in page to start copying from/to
+ * @len: number of bytes to copy
+ * @lvec: iovec array specifying where to copy to/from
+ * @lvec_cnt: number of elements in iovec array
+ * @lvec_current: index in iovec array we are up to
+ * @lvec_offset: offset in bytes from current iovec iov_base we are up to
+ * @vm_write: 0 means copy from, 1 means copy to
+ * @nr_pages_to_copy: number of pages to copy
+ * @bytes_copied: returns number of bytes successfully copied
+ * Returns 0 on success, error code otherwise
+ */
+static int process_vm_rw_pages(struct task_struct *task,
+                              struct mm_struct *mm,
+                              struct page **process_pages,
+                              unsigned long pa,
+                              unsigned long start_offset,
+                              unsigned long len,
+                              const struct iovec *lvec,
+                              unsigned long lvec_cnt,
+                              unsigned long *lvec_current,
+                              size_t *lvec_offset,
+                              int vm_write,
+                              unsigned int nr_pages_to_copy,
+                              ssize_t *bytes_copied)
+{
+       int pages_pinned;
+       void *target_kaddr;
+       int pgs_copied = 0;
+       int j;
+       int ret;
+       ssize_t bytes_to_copy;
+       ssize_t rc = 0;
+
+       *bytes_copied = 0;
+
+       /* Get the pages we're interested in */
+       down_read(&mm->mmap_sem);
+       pages_pinned = get_user_pages(task, mm, pa,
+                                     nr_pages_to_copy,
+                                     vm_write, 0, process_pages, NULL);
+       up_read(&mm->mmap_sem);
+
+       if (pages_pinned != nr_pages_to_copy) {
+               rc = -EFAULT;
+               goto end;
+       }
+
+       /* Do the copy for each page */
+       for (pgs_copied = 0;
+            (pgs_copied < nr_pages_to_copy) && (*lvec_current < lvec_cnt);
+            pgs_copied++) {
+               /* Make sure we have a non zero length iovec */
+               while (*lvec_current < lvec_cnt
+                      && lvec[*lvec_current].iov_len == 0)
+                       (*lvec_current)++;
+               if (*lvec_current == lvec_cnt)
+                       break;
+
+               /*
+                * Will copy smallest of:
+                * - bytes remaining in page
+                * - bytes remaining in destination iovec
+                */
+               bytes_to_copy = min_t(ssize_t, PAGE_SIZE - start_offset,
+                                     len - *bytes_copied);
+               bytes_to_copy = min_t(ssize_t, bytes_to_copy,
+                                     lvec[*lvec_current].iov_len
+                                     - *lvec_offset);
+
+               target_kaddr = kmap(process_pages[pgs_copied]) + start_offset;
+
+               if (vm_write)
+                       ret = copy_from_user(target_kaddr,
+                                            lvec[*lvec_current].iov_base
+                                            + *lvec_offset,
+                                            bytes_to_copy);
+               else
+                       ret = copy_to_user(lvec[*lvec_current].iov_base
+                                          + *lvec_offset,
+                                          target_kaddr, bytes_to_copy);
+               kunmap(process_pages[pgs_copied]);
+               if (ret) {
+                       *bytes_copied += bytes_to_copy - ret;
+                       pgs_copied++;
+                       rc = -EFAULT;
+                       goto end;
+               }
+               *bytes_copied += bytes_to_copy;
+               *lvec_offset += bytes_to_copy;
+               if (*lvec_offset == lvec[*lvec_current].iov_len) {
+                       /*
+                        * Need to copy remaining part of page into the
+                        * next iovec if there are any bytes left in page
+                        */
+                       (*lvec_current)++;
+                       *lvec_offset = 0;
+                       start_offset = (start_offset + bytes_to_copy)
+                               % PAGE_SIZE;
+                       if (start_offset)
+                               pgs_copied--;
+               } else {
+                       start_offset = 0;
+               }
+       }
+
+end:
+       if (vm_write) {
+               for (j = 0; j < pages_pinned; j++) {
+                       if (j < pgs_copied)
+                               set_page_dirty_lock(process_pages[j]);
+                       put_page(process_pages[j]);
+               }
+       } else {
+               for (j = 0; j < pages_pinned; j++)
+                       put_page(process_pages[j]);
+       }
+
+       return rc;
+}
+
+/* Maximum number of pages kmalloc'd to hold struct page's during copy */
+#define PVM_MAX_KMALLOC_PAGES (PAGE_SIZE * 2)
+
+/**
+ * process_vm_rw_single_vec - read/write pages from task specified
+ * @addr: start memory address of target process
+ * @len: size of area to copy to/from
+ * @lvec: iovec array specifying where to copy to/from locally
+ * @lvec_cnt: number of elements in iovec array
+ * @lvec_current: index in iovec array we are up to
+ * @lvec_offset: offset in bytes from current iovec iov_base we are up to
+ * @process_pages: struct pages area that can store at least
+ *  nr_pages_to_copy struct page pointers
+ * @mm: mm for task
+ * @task: task to read/write from
+ * @vm_write: 0 means copy from, 1 means copy to
+ * @bytes_copied: returns number of bytes successfully copied
+ * Returns 0 on success or on failure error code
+ */
+static int process_vm_rw_single_vec(unsigned long addr,
+                                   unsigned long len,
+                                   const struct iovec *lvec,
+                                   unsigned long lvec_cnt,
+                                   unsigned long *lvec_current,
+                                   size_t *lvec_offset,
+                                   struct page **process_pages,
+                                   struct mm_struct *mm,
+                                   struct task_struct *task,
+                                   int vm_write,
+                                   ssize_t *bytes_copied)
+{
+       unsigned long pa = addr & PAGE_MASK;
+       unsigned long start_offset = addr - pa;
+       unsigned long nr_pages;
+       ssize_t bytes_copied_loop;
+       ssize_t rc = 0;
+       unsigned long nr_pages_copied = 0;
+       unsigned long nr_pages_to_copy;
+       unsigned long max_pages_per_loop = PVM_MAX_KMALLOC_PAGES
+               / sizeof(struct pages *);
+
+       *bytes_copied = 0;
+
+       /* Work out address and page range required */
+       if (len == 0)
+               return 0;
+       nr_pages = (addr + len - 1) / PAGE_SIZE - addr / PAGE_SIZE + 1;
+
+       while ((nr_pages_copied < nr_pages) && (*lvec_current < lvec_cnt)) {
+               nr_pages_to_copy = min(nr_pages - nr_pages_copied,
+                                      max_pages_per_loop);
+
+               rc = process_vm_rw_pages(task, mm, process_pages, pa,
+                                        start_offset, len,
+                                        lvec, lvec_cnt,
+                                        lvec_current, lvec_offset,
+                                        vm_write, nr_pages_to_copy,
+                                        &bytes_copied_loop);
+               start_offset = 0;
+               *bytes_copied += bytes_copied_loop;
+
+               if (rc < 0) {
+                       return rc;
+               } else {
+                       len -= bytes_copied_loop;
+                       nr_pages_copied += nr_pages_to_copy;
+                       pa += nr_pages_to_copy * PAGE_SIZE;
+               }
+       }
+
+       return rc;
+}
+
+/* Maximum number of entries for process pages array
+   which lives on stack */
+#define PVM_MAX_PP_ARRAY_COUNT 16
+
+/**
+ * process_vm_rw_core - core of reading/writing pages from task specified
+ * @pid: PID of process to read/write from/to
+ * @lvec: iovec array specifying where to copy to/from locally
+ * @liovcnt: size of lvec array
+ * @rvec: iovec array specifying where to copy to/from in the other process
+ * @riovcnt: size of rvec array
+ * @flags: currently unused
+ * @vm_write: 0 if reading from other process, 1 if writing to other process
+ * Returns the number of bytes read/written or error code. May
+ *  return less bytes than expected if an error occurs during the copying
+ *  process.
+ */
+static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
+                                 unsigned long liovcnt,
+                                 const struct iovec *rvec,
+                                 unsigned long riovcnt,
+                                 unsigned long flags, int vm_write)
+{
+       struct task_struct *task;
+       struct page *pp_stack[PVM_MAX_PP_ARRAY_COUNT];
+       struct page **process_pages = pp_stack;
+       struct mm_struct *mm;
+       unsigned long i;
+       ssize_t rc = 0;
+       ssize_t bytes_copied_loop;
+       ssize_t bytes_copied = 0;
+       unsigned long nr_pages = 0;
+       unsigned long nr_pages_iov;
+       unsigned long iov_l_curr_idx = 0;
+       size_t iov_l_curr_offset = 0;
+       ssize_t iov_len;
+
+       /*
+        * Work out how many pages of struct pages we're going to need
+        * when eventually calling get_user_pages
+        */
+       for (i = 0; i < riovcnt; i++) {
+               iov_len = rvec[i].iov_len;
+               if (iov_len > 0) {
+                       nr_pages_iov = ((unsigned long)rvec[i].iov_base
+                                       + iov_len)
+                               / PAGE_SIZE - (unsigned long)rvec[i].iov_base
+                               / PAGE_SIZE + 1;
+                       nr_pages = max(nr_pages, nr_pages_iov);
+               }
+       }
+
+       if (nr_pages == 0)
+               return 0;
+
+       if (nr_pages > PVM_MAX_PP_ARRAY_COUNT) {
+               /* For reliability don't try to kmalloc more than
+                  2 pages worth */
+               process_pages = kmalloc(min_t(size_t, PVM_MAX_KMALLOC_PAGES,
+                                             sizeof(struct pages *)*nr_pages),
+                                       GFP_KERNEL);
+
+               if (!process_pages)
+                       return -ENOMEM;
+       }
+
+       /* Get process information */
+       rcu_read_lock();
+       task = find_task_by_vpid(pid);
+       if (task)
+               get_task_struct(task);
+       rcu_read_unlock();
+       if (!task) {
+               rc = -ESRCH;
+               goto free_proc_pages;
+       }
+
+       task_lock(task);
+       if (__ptrace_may_access(task, PTRACE_MODE_ATTACH)) {
+               task_unlock(task);
+               rc = -EPERM;
+               goto put_task_struct;
+       }
+       mm = task->mm;
+
+       if (!mm || (task->flags & PF_KTHREAD)) {
+               task_unlock(task);
+               rc = -EINVAL;
+               goto put_task_struct;
+       }
+
+       atomic_inc(&mm->mm_users);
+       task_unlock(task);
+
+       for (i = 0; i < riovcnt && iov_l_curr_idx < liovcnt; i++) {
+               rc = process_vm_rw_single_vec(
+                       (unsigned long)rvec[i].iov_base, rvec[i].iov_len,
+                       lvec, liovcnt, &iov_l_curr_idx, &iov_l_curr_offset,
+                       process_pages, mm, task, vm_write, &bytes_copied_loop);
+               bytes_copied += bytes_copied_loop;
+               if (rc != 0) {
+                       /* If we have managed to copy any data at all then
+                          we return the number of bytes copied. Otherwise
+                          we return the error code */
+                       if (bytes_copied)
+                               rc = bytes_copied;
+                       goto put_mm;
+               }
+       }
+
+       rc = bytes_copied;
+put_mm:
+       mmput(mm);
+
+put_task_struct:
+       put_task_struct(task);
+
+free_proc_pages:
+       if (process_pages != pp_stack)
+               kfree(process_pages);
+       return rc;
+}
+
+/**
+ * process_vm_rw - check iovecs before calling core routine
+ * @pid: PID of process to read/write from/to
+ * @lvec: iovec array specifying where to copy to/from locally
+ * @liovcnt: size of lvec array
+ * @rvec: iovec array specifying where to copy to/from in the other process
+ * @riovcnt: size of rvec array
+ * @flags: currently unused
+ * @vm_write: 0 if reading from other process, 1 if writing to other process
+ * Returns the number of bytes read/written or error code. May
+ *  return less bytes than expected if an error occurs during the copying
+ *  process.
+ */
+static ssize_t process_vm_rw(pid_t pid,
+                            const struct iovec __user *lvec,
+                            unsigned long liovcnt,
+                            const struct iovec __user *rvec,
+                            unsigned long riovcnt,
+                            unsigned long flags, int vm_write)
+{
+       struct iovec iovstack_l[UIO_FASTIOV];
+       struct iovec iovstack_r[UIO_FASTIOV];
+       struct iovec *iov_l = iovstack_l;
+       struct iovec *iov_r = iovstack_r;
+       ssize_t rc;
+
+       if (flags != 0)
+               return -EINVAL;
+
+       /* Check iovecs */
+       if (vm_write)
+               rc = rw_copy_check_uvector(WRITE, lvec, liovcnt, UIO_FASTIOV,
+                                          iovstack_l, &iov_l, 1);
+       else
+               rc = rw_copy_check_uvector(READ, lvec, liovcnt, UIO_FASTIOV,
+                                          iovstack_l, &iov_l, 1);
+       if (rc <= 0)
+               goto free_iovecs;
+
+       rc = rw_copy_check_uvector(READ, rvec, riovcnt, UIO_FASTIOV,
+                                  iovstack_r, &iov_r, 0);
+       if (rc <= 0)
+               goto free_iovecs;
+
+       rc = process_vm_rw_core(pid, iov_l, liovcnt, iov_r, riovcnt, flags,
+                               vm_write);
+
+free_iovecs:
+       if (iov_r != iovstack_r)
+               kfree(iov_r);
+       if (iov_l != iovstack_l)
+               kfree(iov_l);
+
+       return rc;
+}
+
+SYSCALL_DEFINE6(process_vm_readv, pid_t, pid, const struct iovec __user *, lvec,
+               unsigned long, liovcnt, const struct iovec __user *, rvec,
+               unsigned long, riovcnt, unsigned long, flags)
+{
+       return process_vm_rw(pid, lvec, liovcnt, rvec, riovcnt, flags, 0);
+}
+
+SYSCALL_DEFINE6(process_vm_writev, pid_t, pid,
+               const struct iovec __user *, lvec,
+               unsigned long, liovcnt, const struct iovec __user *, rvec,
+               unsigned long, riovcnt, unsigned long, flags)
+{
+       return process_vm_rw(pid, lvec, liovcnt, rvec, riovcnt, flags, 1);
+}
+
+#ifdef CONFIG_COMPAT
+
+asmlinkage ssize_t
+compat_process_vm_rw(compat_pid_t pid,
+                    const struct compat_iovec __user *lvec,
+                    unsigned long liovcnt,
+                    const struct compat_iovec __user *rvec,
+                    unsigned long riovcnt,
+                    unsigned long flags, int vm_write)
+{
+       struct iovec iovstack_l[UIO_FASTIOV];
+       struct iovec iovstack_r[UIO_FASTIOV];
+       struct iovec *iov_l = iovstack_l;
+       struct iovec *iov_r = iovstack_r;
+       ssize_t rc = -EFAULT;
+
+       if (flags != 0)
+               return -EINVAL;
+
+       if (!access_ok(VERIFY_READ, lvec, liovcnt * sizeof(*lvec)))
+               goto out;
+
+       if (!access_ok(VERIFY_READ, rvec, riovcnt * sizeof(*rvec)))
+               goto out;
+
+       if (vm_write)
+               rc = compat_rw_copy_check_uvector(WRITE, lvec, liovcnt,
+                                                 UIO_FASTIOV, iovstack_l,
+                                                 &iov_l, 1);
+       else
+               rc = compat_rw_copy_check_uvector(READ, lvec, liovcnt,
+                                                 UIO_FASTIOV, iovstack_l,
+                                                 &iov_l, 1);
+       if (rc <= 0)
+               goto free_iovecs;
+       rc = compat_rw_copy_check_uvector(READ, rvec, riovcnt,
+                                         UIO_FASTIOV, iovstack_r,
+                                         &iov_r, 0);
+       if (rc <= 0)
+               goto free_iovecs;
+
+       rc = process_vm_rw_core(pid, iov_l, liovcnt, iov_r, riovcnt, flags,
+                          vm_write);
+
+free_iovecs:
+       if (iov_r != iovstack_r)
+               kfree(iov_r);
+       if (iov_l != iovstack_l)
+               kfree(iov_l);
+
+out:
+       return rc;
+}
+
+asmlinkage ssize_t
+compat_sys_process_vm_readv(compat_pid_t pid,
+                           const struct compat_iovec __user *lvec,
+                           unsigned long liovcnt,
+                           const struct compat_iovec __user *rvec,
+                           unsigned long riovcnt,
+                           unsigned long flags)
+{
+       return compat_process_vm_rw(pid, lvec, liovcnt, rvec,
+                                   riovcnt, flags, 0);
+}
+
+asmlinkage ssize_t
+compat_sys_process_vm_writev(compat_pid_t pid,
+                            const struct compat_iovec __user *lvec,
+                            unsigned long liovcnt,
+                            const struct compat_iovec __user *rvec,
+                            unsigned long riovcnt,
+                            unsigned long flags)
+{
+       return compat_process_vm_rw(pid, lvec, liovcnt, rvec,
+                                   riovcnt, flags, 1);
+}
+
+#endif
index 8005080fb9e361316870e684c4057a569d86acf3..6541cf7fd1d3286ee6bb50edcaba39700092f2f4 100644 (file)
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1164,7 +1164,7 @@ void page_remove_rmap(struct page *page)
 
 /*
  * Subfunctions of try_to_unmap: try_to_unmap_one called
- * repeatedly from either try_to_unmap_anon or try_to_unmap_file.
+ * repeatedly from try_to_unmap_ksm, try_to_unmap_anon or try_to_unmap_file.
  */
 int try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
                     unsigned long address, enum ttu_flags flags)
index 2d357729529880b29f18704edda807108f6cdc5b..fa4fa6ce13bc431c65de6725d9b86f6db24bf041 100644 (file)
@@ -1068,6 +1068,12 @@ int shmem_lock(struct file *file, int lock, struct user_struct *user)
                user_shm_unlock(inode->i_size, user);
                info->flags &= ~VM_LOCKED;
                mapping_clear_unevictable(file->f_mapping);
+               /*
+                * Ensure that a racing putback_lru_page() can see
+                * the pages of this mapping are evictable when we
+                * skip them due to !PageLRU during the scan.
+                */
+               smp_mb__after_clear_bit();
                scan_mapping_unevictable_pages(file->f_mapping);
        }
        retval = 0;
index 95215aa6a75e4ffa42676355a5fadc86fc1466d2..7d2a996c307e4306bd233f4ae340a02d6915ffb1 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -655,49 +655,6 @@ static void init_object(struct kmem_cache *s, void *object, u8 val)
                memset(p + s->objsize, val, s->inuse - s->objsize);
 }
 
-static u8 *check_bytes8(u8 *start, u8 value, unsigned int bytes)
-{
-       while (bytes) {
-               if (*start != value)
-                       return start;
-               start++;
-               bytes--;
-       }
-       return NULL;
-}
-
-static u8 *check_bytes(u8 *start, u8 value, unsigned int bytes)
-{
-       u64 value64;
-       unsigned int words, prefix;
-
-       if (bytes <= 16)
-               return check_bytes8(start, value, bytes);
-
-       value64 = value | value << 8 | value << 16 | value << 24;
-       value64 = (value64 & 0xffffffff) | value64 << 32;
-       prefix = 8 - ((unsigned long)start) % 8;
-
-       if (prefix) {
-               u8 *r = check_bytes8(start, value, prefix);
-               if (r)
-                       return r;
-               start += prefix;
-               bytes -= prefix;
-       }
-
-       words = bytes / 8;
-
-       while (words) {
-               if (*(u64 *)start != value64)
-                       return check_bytes8(start, value, 8);
-               start += 8;
-               words--;
-       }
-
-       return check_bytes8(start, value, bytes % 8);
-}
-
 static void restore_bytes(struct kmem_cache *s, char *message, u8 data,
                                                void *from, void *to)
 {
@@ -712,7 +669,7 @@ static int check_bytes_and_report(struct kmem_cache *s, struct page *page,
        u8 *fault;
        u8 *end;
 
-       fault = check_bytes(start, value, bytes);
+       fault = memchr_inv(start, value, bytes);
        if (!fault)
                return 1;
 
@@ -805,7 +762,7 @@ static int slab_pad_check(struct kmem_cache *s, struct page *page)
        if (!remainder)
                return 1;
 
-       fault = check_bytes(end - remainder, POISON_INUSE, remainder);
+       fault = memchr_inv(end - remainder, POISON_INUSE, remainder);
        if (!fault)
                return 1;
        while (end > fault && end[-1] == POISON_INUSE)
index 17bc224bce68c618285e9c74a3a2db0a4ec24c0f..c9d654009125d506053059262a63fe6e0637a394 100644 (file)
@@ -1617,7 +1617,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
 
        oom_score_adj = test_set_oom_score_adj(OOM_SCORE_ADJ_MAX);
        err = try_to_unuse(type);
-       test_set_oom_score_adj(oom_score_adj);
+       compare_swap_oom_score_adj(OOM_SCORE_ADJ_MAX, oom_score_adj);
 
        if (err) {
                /*
index e53f7d02c17cd682c27f0bef1275c416586a9c26..57ad495dbd54392ff5d1d23125f38f605e4d2763 100644 (file)
@@ -29,7 +29,7 @@
 
 static DEFINE_SPINLOCK(swap_token_lock);
 struct mm_struct *swap_token_mm;
-struct mem_cgroup *swap_token_memcg;
+static struct mem_cgroup *swap_token_memcg;
 
 #ifdef CONFIG_CGROUP_MEM_RES_CTLR
 static struct mem_cgroup *swap_token_memcg_from_mm(struct mm_struct *mm)
index 5016f19e1661637373059dcc05124e883533fa87..b669aa6f6caff34f41fac15a527a791576f9026a 100644 (file)
@@ -1253,18 +1253,22 @@ EXPORT_SYMBOL_GPL(map_vm_area);
 DEFINE_RWLOCK(vmlist_lock);
 struct vm_struct *vmlist;
 
-static void insert_vmalloc_vm(struct vm_struct *vm, struct vmap_area *va,
+static void setup_vmalloc_vm(struct vm_struct *vm, struct vmap_area *va,
                              unsigned long flags, void *caller)
 {
-       struct vm_struct *tmp, **p;
-
        vm->flags = flags;
        vm->addr = (void *)va->va_start;
        vm->size = va->va_end - va->va_start;
        vm->caller = caller;
        va->private = vm;
        va->flags |= VM_VM_AREA;
+}
 
+static void insert_vmalloc_vmlist(struct vm_struct *vm)
+{
+       struct vm_struct *tmp, **p;
+
+       vm->flags &= ~VM_UNLIST;
        write_lock(&vmlist_lock);
        for (p = &vmlist; (tmp = *p) != NULL; p = &tmp->next) {
                if (tmp->addr >= vm->addr)
@@ -1275,6 +1279,13 @@ static void insert_vmalloc_vm(struct vm_struct *vm, struct vmap_area *va,
        write_unlock(&vmlist_lock);
 }
 
+static void insert_vmalloc_vm(struct vm_struct *vm, struct vmap_area *va,
+                             unsigned long flags, void *caller)
+{
+       setup_vmalloc_vm(vm, va, flags, caller);
+       insert_vmalloc_vmlist(vm);
+}
+
 static struct vm_struct *__get_vm_area_node(unsigned long size,
                unsigned long align, unsigned long flags, unsigned long start,
                unsigned long end, int node, gfp_t gfp_mask, void *caller)
@@ -1313,7 +1324,18 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
                return NULL;
        }
 
-       insert_vmalloc_vm(area, va, flags, caller);
+       /*
+        * When this function is called from __vmalloc_node_range,
+        * we do not add vm_struct to vmlist here to avoid
+        * accessing uninitialized members of vm_struct such as
+        * pages and nr_pages fields. They will be set later.
+        * To distinguish it from others, we use a VM_UNLIST flag.
+        */
+       if (flags & VM_UNLIST)
+               setup_vmalloc_vm(area, va, flags, caller);
+       else
+               insert_vmalloc_vm(area, va, flags, caller);
+
        return area;
 }
 
@@ -1381,17 +1403,20 @@ struct vm_struct *remove_vm_area(const void *addr)
        va = find_vmap_area((unsigned long)addr);
        if (va && va->flags & VM_VM_AREA) {
                struct vm_struct *vm = va->private;
-               struct vm_struct *tmp, **p;
-               /*
-                * remove from list and disallow access to this vm_struct
-                * before unmap. (address range confliction is maintained by
-                * vmap.)
-                */
-               write_lock(&vmlist_lock);
-               for (p = &vmlist; (tmp = *p) != vm; p = &tmp->next)
-                       ;
-               *p = tmp->next;
-               write_unlock(&vmlist_lock);
+
+               if (!(vm->flags & VM_UNLIST)) {
+                       struct vm_struct *tmp, **p;
+                       /*
+                        * remove from list and disallow access to
+                        * this vm_struct before unmap. (address range
+                        * confliction is maintained by vmap.)
+                        */
+                       write_lock(&vmlist_lock);
+                       for (p = &vmlist; (tmp = *p) != vm; p = &tmp->next)
+                               ;
+                       *p = tmp->next;
+                       write_unlock(&vmlist_lock);
+               }
 
                vmap_debug_free_range(va->va_start, va->va_end);
                free_unmap_vmap_area(va);
@@ -1568,8 +1593,8 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
        return area->addr;
 
 fail:
-       warn_alloc_failed(gfp_mask, order, "vmalloc: allocation failure, "
-                         "allocated %ld of %ld bytes\n",
+       warn_alloc_failed(gfp_mask, order,
+                         "vmalloc: allocation failure, allocated %ld of %ld bytes\n",
                          (area->nr_pages*PAGE_SIZE), area->size);
        vfree(area->addr);
        return NULL;
@@ -1600,16 +1625,21 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
 
        size = PAGE_ALIGN(size);
        if (!size || (size >> PAGE_SHIFT) > totalram_pages)
-               return NULL;
-
-       area = __get_vm_area_node(size, align, VM_ALLOC, start, end, node,
-                                 gfp_mask, caller);
+               goto fail;
 
+       area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
+                                 start, end, node, gfp_mask, caller);
        if (!area)
-               return NULL;
+               goto fail;
 
        addr = __vmalloc_area_node(area, gfp_mask, prot, node, caller);
 
+       /*
+        * In this function, newly allocated vm_struct is not added
+        * to vmlist at __get_vm_area_node(). so, it is added here.
+        */
+       insert_vmalloc_vmlist(area);
+
        /*
         * A ref_count = 3 is needed because the vm_struct and vmap_area
         * structures allocated in the __get_vm_area_node() function contain
@@ -1618,6 +1648,12 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
        kmemleak_alloc(addr, real_size, 3, gfp_mask);
 
        return addr;
+
+fail:
+       warn_alloc_failed(gfp_mask, 0,
+                         "vmalloc: allocation failure: %lu bytes\n",
+                         real_size);
+       return NULL;
 }
 
 /**
index 9fdfce7ba4039a19026d39db3bae3c6f0bd18f97..a90c603a8d02937fd41bac6a7e72d2891f86bfaa 100644 (file)
@@ -495,15 +495,6 @@ static pageout_t pageout(struct page *page, struct address_space *mapping,
                        return PAGE_ACTIVATE;
                }
 
-               /*
-                * Wait on writeback if requested to. This happens when
-                * direct reclaiming a large contiguous area and the
-                * first attempt to free a range of pages fails.
-                */
-               if (PageWriteback(page) &&
-                   (sc->reclaim_mode & RECLAIM_MODE_SYNC))
-                       wait_on_page_writeback(page);
-
                if (!PageWriteback(page)) {
                        /* synchronous write or broken a_ops? */
                        ClearPageReclaim(page);
@@ -642,13 +633,14 @@ redo:
                lru = LRU_UNEVICTABLE;
                add_page_to_unevictable_list(page);
                /*
-                * When racing with an mlock clearing (page is
-                * unlocked), make sure that if the other thread does
-                * not observe our setting of PG_lru and fails
-                * isolation, we see PG_mlocked cleared below and move
+                * When racing with an mlock or AS_UNEVICTABLE clearing
+                * (page is unlocked) make sure that if the other thread
+                * does not observe our setting of PG_lru and fails
+                * isolation/check_move_unevictable_page,
+                * we see PG_mlocked/AS_UNEVICTABLE cleared below and move
                 * the page back to the evictable list.
                 *
-                * The other side is TestClearPageMlocked().
+                * The other side is TestClearPageMlocked() or shmem_lock().
                 */
                smp_mb();
        }
@@ -759,7 +751,10 @@ static noinline_for_stack void free_page_list(struct list_head *free_pages)
  */
 static unsigned long shrink_page_list(struct list_head *page_list,
                                      struct zone *zone,
-                                     struct scan_control *sc)
+                                     struct scan_control *sc,
+                                     int priority,
+                                     unsigned long *ret_nr_dirty,
+                                     unsigned long *ret_nr_writeback)
 {
        LIST_HEAD(ret_pages);
        LIST_HEAD(free_pages);
@@ -767,6 +762,7 @@ static unsigned long shrink_page_list(struct list_head *page_list,
        unsigned long nr_dirty = 0;
        unsigned long nr_congested = 0;
        unsigned long nr_reclaimed = 0;
+       unsigned long nr_writeback = 0;
 
        cond_resched();
 
@@ -803,13 +799,12 @@ static unsigned long shrink_page_list(struct list_head *page_list,
                        (PageSwapCache(page) && (sc->gfp_mask & __GFP_IO));
 
                if (PageWriteback(page)) {
+                       nr_writeback++;
                        /*
-                        * Synchronous reclaim is performed in two passes,
-                        * first an asynchronous pass over the list to
-                        * start parallel writeback, and a second synchronous
-                        * pass to wait for the IO to complete.  Wait here
-                        * for any page for which writeback has already
-                        * started.
+                        * Synchronous reclaim cannot queue pages for
+                        * writeback due to the possibility of stack overflow
+                        * but if it encounters a page under writeback, wait
+                        * for the IO to complete.
                         */
                        if ((sc->reclaim_mode & RECLAIM_MODE_SYNC) &&
                            may_enter_fs)
@@ -865,6 +860,25 @@ static unsigned long shrink_page_list(struct list_head *page_list,
                if (PageDirty(page)) {
                        nr_dirty++;
 
+                       /*
+                        * Only kswapd can writeback filesystem pages to
+                        * avoid risk of stack overflow but do not writeback
+                        * unless under significant pressure.
+                        */
+                       if (page_is_file_cache(page) &&
+                                       (!current_is_kswapd() || priority >= DEF_PRIORITY - 2)) {
+                               /*
+                                * Immediately reclaim when written back.
+                                * Similar in principal to deactivate_page()
+                                * except we already have the page isolated
+                                * and know it's dirty
+                                */
+                               inc_zone_page_state(page, NR_VMSCAN_IMMEDIATE);
+                               SetPageReclaim(page);
+
+                               goto keep_locked;
+                       }
+
                        if (references == PAGEREF_RECLAIM_CLEAN)
                                goto keep_locked;
                        if (!may_enter_fs)
@@ -999,6 +1013,8 @@ keep_lumpy:
 
        list_splice(&ret_pages, page_list);
        count_vm_events(PGACTIVATE, pgactivate);
+       *ret_nr_dirty += nr_dirty;
+       *ret_nr_writeback += nr_writeback;
        return nr_reclaimed;
 }
 
@@ -1012,23 +1028,27 @@ keep_lumpy:
  *
  * returns 0 on success, -ve errno on failure.
  */
-int __isolate_lru_page(struct page *page, int mode, int file)
+int __isolate_lru_page(struct page *page, isolate_mode_t mode, int file)
 {
+       bool all_lru_mode;
        int ret = -EINVAL;
 
        /* Only take pages on the LRU. */
        if (!PageLRU(page))
                return ret;
 
+       all_lru_mode = (mode & (ISOLATE_ACTIVE|ISOLATE_INACTIVE)) ==
+               (ISOLATE_ACTIVE|ISOLATE_INACTIVE);
+
        /*
         * When checking the active state, we need to be sure we are
         * dealing with comparible boolean values.  Take the logical not
         * of each.
         */
-       if (mode != ISOLATE_BOTH && (!PageActive(page) != !mode))
+       if (!all_lru_mode && !PageActive(page) != !(mode & ISOLATE_ACTIVE))
                return ret;
 
-       if (mode != ISOLATE_BOTH && page_is_file_cache(page) != file)
+       if (!all_lru_mode && !!page_is_file_cache(page) != file)
                return ret;
 
        /*
@@ -1041,6 +1061,12 @@ int __isolate_lru_page(struct page *page, int mode, int file)
 
        ret = -EBUSY;
 
+       if ((mode & ISOLATE_CLEAN) && (PageDirty(page) || PageWriteback(page)))
+               return ret;
+
+       if ((mode & ISOLATE_UNMAPPED) && page_mapped(page))
+               return ret;
+
        if (likely(get_page_unless_zero(page))) {
                /*
                 * Be careful not to clear PageLRU until after we're
@@ -1076,7 +1102,8 @@ int __isolate_lru_page(struct page *page, int mode, int file)
  */
 static unsigned long isolate_lru_pages(unsigned long nr_to_scan,
                struct list_head *src, struct list_head *dst,
-               unsigned long *scanned, int order, int mode, int file)
+               unsigned long *scanned, int order, isolate_mode_t mode,
+               int file)
 {
        unsigned long nr_taken = 0;
        unsigned long nr_lumpy_taken = 0;
@@ -1201,8 +1228,8 @@ static unsigned long isolate_lru_pages(unsigned long nr_to_scan,
 static unsigned long isolate_pages_global(unsigned long nr,
                                        struct list_head *dst,
                                        unsigned long *scanned, int order,
-                                       int mode, struct zone *z,
-                                       int active, int file)
+                                       isolate_mode_t mode,
+                                       struct zone *z, int active, int file)
 {
        int lru = LRU_BASE;
        if (active)
@@ -1394,7 +1421,7 @@ static noinline_for_stack void update_isolated_counts(struct zone *zone,
 }
 
 /*
- * Returns true if the caller should wait to clean dirty/writeback pages.
+ * Returns true if a direct reclaim should wait on pages under writeback.
  *
  * If we are direct reclaiming for contiguous pages and we do not reclaim
  * everything in the list, try again and wait for writeback IO to complete.
@@ -1448,6 +1475,9 @@ shrink_inactive_list(unsigned long nr_to_scan, struct zone *zone,
        unsigned long nr_taken;
        unsigned long nr_anon;
        unsigned long nr_file;
+       unsigned long nr_dirty = 0;
+       unsigned long nr_writeback = 0;
+       isolate_mode_t reclaim_mode = ISOLATE_INACTIVE;
 
        while (unlikely(too_many_isolated(zone, file, sc))) {
                congestion_wait(BLK_RW_ASYNC, HZ/10);
@@ -1458,15 +1488,21 @@ shrink_inactive_list(unsigned long nr_to_scan, struct zone *zone,
        }
 
        set_reclaim_mode(priority, sc, false);
+       if (sc->reclaim_mode & RECLAIM_MODE_LUMPYRECLAIM)
+               reclaim_mode |= ISOLATE_ACTIVE;
+
        lru_add_drain();
+
+       if (!sc->may_unmap)
+               reclaim_mode |= ISOLATE_UNMAPPED;
+       if (!sc->may_writepage)
+               reclaim_mode |= ISOLATE_CLEAN;
+
        spin_lock_irq(&zone->lru_lock);
 
        if (scanning_global_lru(sc)) {
-               nr_taken = isolate_pages_global(nr_to_scan,
-                       &page_list, &nr_scanned, sc->order,
-                       sc->reclaim_mode & RECLAIM_MODE_LUMPYRECLAIM ?
-                                       ISOLATE_BOTH : ISOLATE_INACTIVE,
-                       zone, 0, file);
+               nr_taken = isolate_pages_global(nr_to_scan, &page_list,
+                       &nr_scanned, sc->order, reclaim_mode, zone, 0, file);
                zone->pages_scanned += nr_scanned;
                if (current_is_kswapd())
                        __count_zone_vm_events(PGSCAN_KSWAPD, zone,
@@ -1475,12 +1511,9 @@ shrink_inactive_list(unsigned long nr_to_scan, struct zone *zone,
                        __count_zone_vm_events(PGSCAN_DIRECT, zone,
                                               nr_scanned);
        } else {
-               nr_taken = mem_cgroup_isolate_pages(nr_to_scan,
-                       &page_list, &nr_scanned, sc->order,
-                       sc->reclaim_mode & RECLAIM_MODE_LUMPYRECLAIM ?
-                                       ISOLATE_BOTH : ISOLATE_INACTIVE,
-                       zone, sc->mem_cgroup,
-                       0, file);
+               nr_taken = mem_cgroup_isolate_pages(nr_to_scan, &page_list,
+                       &nr_scanned, sc->order, reclaim_mode, zone,
+                       sc->mem_cgroup, 0, file);
                /*
                 * mem_cgroup_isolate_pages() keeps track of
                 * scanned pages on its own.
@@ -1496,12 +1529,14 @@ shrink_inactive_list(unsigned long nr_to_scan, struct zone *zone,
 
        spin_unlock_irq(&zone->lru_lock);
 
-       nr_reclaimed = shrink_page_list(&page_list, zone, sc);
+       nr_reclaimed = shrink_page_list(&page_list, zone, sc, priority,
+                                               &nr_dirty, &nr_writeback);
 
        /* Check if we should syncronously wait for writeback */
        if (should_reclaim_stall(nr_taken, nr_reclaimed, priority, sc)) {
                set_reclaim_mode(priority, sc, true);
-               nr_reclaimed += shrink_page_list(&page_list, zone, sc);
+               nr_reclaimed += shrink_page_list(&page_list, zone, sc,
+                                       priority, &nr_dirty, &nr_writeback);
        }
 
        local_irq_disable();
@@ -1511,6 +1546,32 @@ shrink_inactive_list(unsigned long nr_to_scan, struct zone *zone,
 
        putback_lru_pages(zone, sc, nr_anon, nr_file, &page_list);
 
+       /*
+        * If reclaim is isolating dirty pages under writeback, it implies
+        * that the long-lived page allocation rate is exceeding the page
+        * laundering rate. Either the global limits are not being effective
+        * at throttling processes due to the page distribution throughout
+        * zones or there is heavy usage of a slow backing device. The
+        * only option is to throttle from reclaim context which is not ideal
+        * as there is no guarantee the dirtying process is throttled in the
+        * same way balance_dirty_pages() manages.
+        *
+        * This scales the number of dirty pages that must be under writeback
+        * before throttling depending on priority. It is a simple backoff
+        * function that has the most effect in the range DEF_PRIORITY to
+        * DEF_PRIORITY-2 which is the priority reclaim is considered to be
+        * in trouble and reclaim is considered to be in trouble.
+        *
+        * DEF_PRIORITY   100% isolated pages must be PageWriteback to throttle
+        * DEF_PRIORITY-1  50% must be PageWriteback
+        * DEF_PRIORITY-2  25% must be PageWriteback, kswapd in trouble
+        * ...
+        * DEF_PRIORITY-6 For SWAP_CLUSTER_MAX isolated pages, throttle if any
+        *                     isolated page is PageWriteback
+        */
+       if (nr_writeback && nr_writeback >= (nr_taken >> (DEF_PRIORITY-priority)))
+               wait_iff_congested(zone, BLK_RW_ASYNC, HZ/10);
+
        trace_mm_vmscan_lru_shrink_inactive(zone->zone_pgdat->node_id,
                zone_idx(zone),
                nr_scanned, nr_reclaimed,
@@ -1582,19 +1643,26 @@ static void shrink_active_list(unsigned long nr_pages, struct zone *zone,
        struct page *page;
        struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc);
        unsigned long nr_rotated = 0;
+       isolate_mode_t reclaim_mode = ISOLATE_ACTIVE;
 
        lru_add_drain();
+
+       if (!sc->may_unmap)
+               reclaim_mode |= ISOLATE_UNMAPPED;
+       if (!sc->may_writepage)
+               reclaim_mode |= ISOLATE_CLEAN;
+
        spin_lock_irq(&zone->lru_lock);
        if (scanning_global_lru(sc)) {
                nr_taken = isolate_pages_global(nr_pages, &l_hold,
                                                &pgscanned, sc->order,
-                                               ISOLATE_ACTIVE, zone,
+                                               reclaim_mode, zone,
                                                1, file);
                zone->pages_scanned += pgscanned;
        } else {
                nr_taken = mem_cgroup_isolate_pages(nr_pages, &l_hold,
                                                &pgscanned, sc->order,
-                                               ISOLATE_ACTIVE, zone,
+                                               reclaim_mode, zone,
                                                sc->mem_cgroup, 1, file);
                /*
                 * mem_cgroup_isolate_pages() keeps track of
@@ -1795,12 +1863,19 @@ static void get_scan_count(struct zone *zone, struct scan_control *sc,
        enum lru_list l;
        int noswap = 0;
        bool force_scan = false;
-       unsigned long nr_force_scan[2];
 
-       /* kswapd does zone balancing and needs to scan this zone */
+       /*
+        * If the zone or memcg is small, nr[l] can be 0.  This
+        * results in no scanning on this priority and a potential
+        * priority drop.  Global direct reclaim can go to the next
+        * zone and tends to have no problems. Global kswapd is for
+        * zone balancing and it needs to scan a minimum amount. When
+        * reclaiming for a memcg, a priority drop can cause high
+        * latencies, so it's better to scan a minimum amount there as
+        * well.
+        */
        if (scanning_global_lru(sc) && current_is_kswapd())
                force_scan = true;
-       /* memcg may have small limit and need to avoid priority drop */
        if (!scanning_global_lru(sc))
                force_scan = true;
 
@@ -1810,8 +1885,6 @@ static void get_scan_count(struct zone *zone, struct scan_control *sc,
                fraction[0] = 0;
                fraction[1] = 1;
                denominator = 1;
-               nr_force_scan[0] = 0;
-               nr_force_scan[1] = SWAP_CLUSTER_MAX;
                goto out;
        }
 
@@ -1828,8 +1901,6 @@ static void get_scan_count(struct zone *zone, struct scan_control *sc,
                        fraction[0] = 1;
                        fraction[1] = 0;
                        denominator = 1;
-                       nr_force_scan[0] = SWAP_CLUSTER_MAX;
-                       nr_force_scan[1] = 0;
                        goto out;
                }
        }
@@ -1878,11 +1949,6 @@ static void get_scan_count(struct zone *zone, struct scan_control *sc,
        fraction[0] = ap;
        fraction[1] = fp;
        denominator = ap + fp + 1;
-       if (force_scan) {
-               unsigned long scan = SWAP_CLUSTER_MAX;
-               nr_force_scan[0] = div64_u64(scan * ap, denominator);
-               nr_force_scan[1] = div64_u64(scan * fp, denominator);
-       }
 out:
        for_each_evictable_lru(l) {
                int file = is_file_lru(l);
@@ -1891,20 +1957,10 @@ out:
                scan = zone_nr_lru_pages(zone, sc, l);
                if (priority || noswap) {
                        scan >>= priority;
+                       if (!scan && force_scan)
+                               scan = SWAP_CLUSTER_MAX;
                        scan = div64_u64(scan * fraction[file], denominator);
                }
-
-               /*
-                * If zone is small or memcg is small, nr[l] can be 0.
-                * This results no-scan on this priority and priority drop down.
-                * For global direct reclaim, it can visit next zone and tend
-                * not to have problems. For global kswapd, it's for zone
-                * balancing and it need to scan a small amounts. When using
-                * memcg, priority drop can cause big latency. So, it's better
-                * to scan small amount. See may_noscan above.
-                */
-               if (!scan && force_scan)
-                       scan = nr_force_scan[file];
                nr[l] = scan;
        }
 }
@@ -1983,12 +2039,14 @@ static void shrink_zone(int priority, struct zone *zone,
        enum lru_list l;
        unsigned long nr_reclaimed, nr_scanned;
        unsigned long nr_to_reclaim = sc->nr_to_reclaim;
+       struct blk_plug plug;
 
 restart:
        nr_reclaimed = 0;
        nr_scanned = sc->nr_scanned;
        get_scan_count(zone, sc, nr, priority);
 
+       blk_start_plug(&plug);
        while (nr[LRU_INACTIVE_ANON] || nr[LRU_ACTIVE_FILE] ||
                                        nr[LRU_INACTIVE_FILE]) {
                for_each_evictable_lru(l) {
@@ -2012,6 +2070,7 @@ restart:
                if (nr_reclaimed >= nr_to_reclaim && priority < DEF_PRIORITY)
                        break;
        }
+       blk_finish_plug(&plug);
        sc->nr_reclaimed += nr_reclaimed;
 
        /*
@@ -2044,14 +2103,19 @@ restart:
  *
  * If a zone is deemed to be full of pinned pages then just give it a light
  * scan then give up on it.
+ *
+ * This function returns true if a zone is being reclaimed for a costly
+ * high-order allocation and compaction is either ready to begin or deferred.
+ * This indicates to the caller that it should retry the allocation or fail.
  */
-static void shrink_zones(int priority, struct zonelist *zonelist,
+static bool shrink_zones(int priority, struct zonelist *zonelist,
                                        struct scan_control *sc)
 {
        struct zoneref *z;
        struct zone *zone;
        unsigned long nr_soft_reclaimed;
        unsigned long nr_soft_scanned;
+       bool should_abort_reclaim = false;
 
        for_each_zone_zonelist_nodemask(zone, z, zonelist,
                                        gfp_zone(sc->gfp_mask), sc->nodemask) {
@@ -2066,6 +2130,23 @@ static void shrink_zones(int priority, struct zonelist *zonelist,
                                continue;
                        if (zone->all_unreclaimable && priority != DEF_PRIORITY)
                                continue;       /* Let kswapd poll it */
+                       if (COMPACTION_BUILD) {
+                               /*
+                                * If we already have plenty of memory free for
+                                * compaction in this zone, don't free any more.
+                                * Even though compaction is invoked for any
+                                * non-zero order, only frequent costly order
+                                * reclamation is disruptive enough to become a
+                                * noticable problem, like transparent huge page
+                                * allocations.
+                                */
+                               if (sc->order > PAGE_ALLOC_COSTLY_ORDER &&
+                                       (compaction_suitable(zone, sc->order) ||
+                                        compaction_deferred(zone))) {
+                                       should_abort_reclaim = true;
+                                       continue;
+                               }
+                       }
                        /*
                         * This steals pages from memory cgroups over softlimit
                         * and returns the number of reclaimed pages and
@@ -2083,6 +2164,8 @@ static void shrink_zones(int priority, struct zonelist *zonelist,
 
                shrink_zone(priority, zone, sc);
        }
+
+       return should_abort_reclaim;
 }
 
 static bool zone_reclaimable(struct zone *zone)
@@ -2147,7 +2230,9 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist,
                sc->nr_scanned = 0;
                if (!priority)
                        disable_swap_token(sc->mem_cgroup);
-               shrink_zones(priority, zonelist, sc);
+               if (shrink_zones(priority, zonelist, sc))
+                       break;
+
                /*
                 * Don't shrink slabs when reclaiming memory from
                 * over limit cgroups
@@ -2690,6 +2775,8 @@ out:
 
                        /* If balanced, clear the congested flag */
                        zone_clear_flag(zone, ZONE_CONGESTED);
+                       if (i <= *classzone_idx)
+                               balanced += zone->present_pages;
                }
        }
 
@@ -2763,7 +2850,9 @@ static void kswapd_try_to_sleep(pg_data_t *pgdat, int order, int classzone_idx)
 static int kswapd(void *p)
 {
        unsigned long order, new_order;
+       unsigned balanced_order;
        int classzone_idx, new_classzone_idx;
+       int balanced_classzone_idx;
        pg_data_t *pgdat = (pg_data_t*)p;
        struct task_struct *tsk = current;
 
@@ -2794,7 +2883,9 @@ static int kswapd(void *p)
        set_freezable();
 
        order = new_order = 0;
+       balanced_order = 0;
        classzone_idx = new_classzone_idx = pgdat->nr_zones - 1;
+       balanced_classzone_idx = classzone_idx;
        for ( ; ; ) {
                int ret;
 
@@ -2803,7 +2894,8 @@ static int kswapd(void *p)
                 * new request of a similar or harder type will succeed soon
                 * so consider going to sleep on the basis we reclaimed at
                 */
-               if (classzone_idx >= new_classzone_idx && order == new_order) {
+               if (balanced_classzone_idx >= new_classzone_idx &&
+                                       balanced_order == new_order) {
                        new_order = pgdat->kswapd_max_order;
                        new_classzone_idx = pgdat->classzone_idx;
                        pgdat->kswapd_max_order =  0;
@@ -2818,9 +2910,12 @@ static int kswapd(void *p)
                        order = new_order;
                        classzone_idx = new_classzone_idx;
                } else {
-                       kswapd_try_to_sleep(pgdat, order, classzone_idx);
+                       kswapd_try_to_sleep(pgdat, balanced_order,
+                                               balanced_classzone_idx);
                        order = pgdat->kswapd_max_order;
                        classzone_idx = pgdat->classzone_idx;
+                       new_order = order;
+                       new_classzone_idx = classzone_idx;
                        pgdat->kswapd_max_order = 0;
                        pgdat->classzone_idx = pgdat->nr_zones - 1;
                }
@@ -2835,7 +2930,9 @@ static int kswapd(void *p)
                 */
                if (!ret) {
                        trace_mm_vmscan_kswapd_wake(pgdat->node_id, order);
-                       order = balance_pgdat(pgdat, order, &classzone_idx);
+                       balanced_classzone_idx = classzone_idx;
+                       balanced_order = balance_pgdat(pgdat, order,
+                                               &balanced_classzone_idx);
                }
        }
        return 0;
@@ -3347,66 +3444,12 @@ void scan_mapping_unevictable_pages(struct address_space *mapping)
 
 }
 
-/**
- * scan_zone_unevictable_pages - check unevictable list for evictable pages
- * @zone - zone of which to scan the unevictable list
- *
- * Scan @zone's unevictable LRU lists to check for pages that have become
- * evictable.  Move those that have to @zone's inactive list where they
- * become candidates for reclaim, unless shrink_inactive_zone() decides
- * to reactivate them.  Pages that are still unevictable are rotated
- * back onto @zone's unevictable list.
- */
-#define SCAN_UNEVICTABLE_BATCH_SIZE 16UL /* arbitrary lock hold batch size */
-static void scan_zone_unevictable_pages(struct zone *zone)
+static void warn_scan_unevictable_pages(void)
 {
-       struct list_head *l_unevictable = &zone->lru[LRU_UNEVICTABLE].list;
-       unsigned long scan;
-       unsigned long nr_to_scan = zone_page_state(zone, NR_UNEVICTABLE);
-
-       while (nr_to_scan > 0) {
-               unsigned long batch_size = min(nr_to_scan,
-                                               SCAN_UNEVICTABLE_BATCH_SIZE);
-
-               spin_lock_irq(&zone->lru_lock);
-               for (scan = 0;  scan < batch_size; scan++) {
-                       struct page *page = lru_to_page(l_unevictable);
-
-                       if (!trylock_page(page))
-                               continue;
-
-                       prefetchw_prev_lru_page(page, l_unevictable, flags);
-
-                       if (likely(PageLRU(page) && PageUnevictable(page)))
-                               check_move_unevictable_page(page, zone);
-
-                       unlock_page(page);
-               }
-               spin_unlock_irq(&zone->lru_lock);
-
-               nr_to_scan -= batch_size;
-       }
-}
-
-
-/**
- * scan_all_zones_unevictable_pages - scan all unevictable lists for evictable pages
- *
- * A really big hammer:  scan all zones' unevictable LRU lists to check for
- * pages that have become evictable.  Move those back to the zones'
- * inactive list where they become candidates for reclaim.
- * This occurs when, e.g., we have unswappable pages on the unevictable lists,
- * and we add swap to the system.  As such, it runs in the context of a task
- * that has possibly/probably made some previously unevictable pages
- * evictable.
- */
-static void scan_all_zones_unevictable_pages(void)
-{
-       struct zone *zone;
-
-       for_each_zone(zone) {
-               scan_zone_unevictable_pages(zone);
-       }
+       printk_once(KERN_WARNING
+                   "The scan_unevictable_pages sysctl/node-interface has been "
+                   "disabled for lack of a legitimate use case.  If you have "
+                   "one, please send an email to linux-mm@kvack.org.\n");
 }
 
 /*
@@ -3419,11 +3462,8 @@ int scan_unevictable_handler(struct ctl_table *table, int write,
                           void __user *buffer,
                           size_t *length, loff_t *ppos)
 {
+       warn_scan_unevictable_pages();
        proc_doulongvec_minmax(table, write, buffer, length, ppos);
-
-       if (write && *(unsigned long *)table->data)
-               scan_all_zones_unevictable_pages();
-
        scan_unevictable_pages = 0;
        return 0;
 }
@@ -3438,6 +3478,7 @@ static ssize_t read_scan_unevictable_node(struct sys_device *dev,
                                          struct sysdev_attribute *attr,
                                          char *buf)
 {
+       warn_scan_unevictable_pages();
        return sprintf(buf, "0\n");     /* always zero; should fit... */
 }
 
@@ -3445,19 +3486,7 @@ static ssize_t write_scan_unevictable_node(struct sys_device *dev,
                                           struct sysdev_attribute *attr,
                                        const char *buf, size_t count)
 {
-       struct zone *node_zones = NODE_DATA(dev->id)->node_zones;
-       struct zone *zone;
-       unsigned long res;
-       unsigned long req = strict_strtoul(buf, 10, &res);
-
-       if (!req)
-               return 1;       /* zero is no-op */
-
-       for (zone = node_zones; zone - node_zones < MAX_NR_ZONES; ++zone) {
-               if (!populated_zone(zone))
-                       continue;
-               scan_zone_unevictable_pages(zone);
-       }
+       warn_scan_unevictable_pages();
        return 1;
 }
 
index d52b13d28e8f4b25b827cd386693330655ff9174..8fd603b1665e5be65bc10c93f146b860f706925d 100644 (file)
@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
  *
  * vm_stat contains the global counters
  */
-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
+atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
 EXPORT_SYMBOL(vm_stat);
 
 #ifdef CONFIG_SMP
@@ -702,6 +702,7 @@ const char * const vmstat_text[] = {
        "nr_unstable",
        "nr_bounce",
        "nr_vmscan_write",
+       "nr_vmscan_immediate_reclaim",
        "nr_writeback_temp",
        "nr_isolated_anon",
        "nr_isolated_file",
index f1f2f7bb6661e18c77276d20598e59caba8c34ed..163397f1fd5adefd655efcfb681544b1a56655bf 100644 (file)
@@ -4,7 +4,7 @@
 #include <linux/netpoll.h>
 #include "vlan.h"
 
-bool vlan_do_receive(struct sk_buff **skbp)
+bool vlan_do_receive(struct sk_buff **skbp, bool last_handler)
 {
        struct sk_buff *skb = *skbp;
        u16 vlan_id = skb->vlan_tci & VLAN_VID_MASK;
@@ -13,7 +13,10 @@ bool vlan_do_receive(struct sk_buff **skbp)
 
        vlan_dev = vlan_find_dev(skb->dev, vlan_id);
        if (!vlan_dev) {
-               if (vlan_id)
+               /* Only the last call to vlan_do_receive() should change
+                * pkt_type to PACKET_OTHERHOST
+                */
+               if (vlan_id && last_handler)
                        skb->pkt_type = PACKET_OTHERHOST;
                return false;
        }
index 873fb3d8e56f6ac3b51792598ec76ba886171c84..c7aafc7c5ed4854b2a46f6e37b5386ef937fee8e 100644 (file)
@@ -137,10 +137,22 @@ static void tt_local_entry_free_ref(struct tt_local_entry *tt_local_entry)
                kfree_rcu(tt_local_entry, rcu);
 }
 
+static void tt_global_entry_free_rcu(struct rcu_head *rcu)
+{
+       struct tt_global_entry *tt_global_entry;
+
+       tt_global_entry = container_of(rcu, struct tt_global_entry, rcu);
+
+       if (tt_global_entry->orig_node)
+               orig_node_free_ref(tt_global_entry->orig_node);
+
+       kfree(tt_global_entry);
+}
+
 static void tt_global_entry_free_ref(struct tt_global_entry *tt_global_entry)
 {
        if (atomic_dec_and_test(&tt_global_entry->refcount))
-               kfree_rcu(tt_global_entry, rcu);
+               call_rcu(&tt_global_entry->rcu, tt_global_entry_free_rcu);
 }
 
 static void tt_local_event(struct bat_priv *bat_priv, const uint8_t *addr,
@@ -710,6 +722,9 @@ void tt_global_del_orig(struct bat_priv *bat_priv,
        struct hlist_head *head;
        spinlock_t *list_lock; /* protects write access to the hash lists */
 
+       if (!hash)
+               return;
+
        for (i = 0; i < hash->size; i++) {
                head = &hash->table[i];
                list_lock = &hash->list_locks[i];
index 1ae3557505116318461da7fd33bb4892045e4ac5..ab8d0fe6df5a4ed6c16092705e79e23675838d0c 100644 (file)
@@ -224,22 +224,22 @@ struct socket_packet {
 
 struct tt_local_entry {
        uint8_t addr[ETH_ALEN];
+       struct hlist_node hash_entry;
        unsigned long last_seen;
        uint16_t flags;
        atomic_t refcount;
        struct rcu_head rcu;
-       struct hlist_node hash_entry;
 };
 
 struct tt_global_entry {
        uint8_t addr[ETH_ALEN];
+       struct hlist_node hash_entry; /* entry in the global table */
        struct orig_node *orig_node;
        uint8_t ttvn;
        uint16_t flags; /* only TT_GLOBAL_ROAM is used */
        unsigned long roam_at; /* time at which TT_GLOBAL_ROAM was set */
        atomic_t refcount;
        struct rcu_head rcu;
-       struct hlist_node hash_entry; /* entry in the global table */
 };
 
 struct tt_change_node {
index be683f2d401f9cb95a00b2652a5b87a657d3db2f..cc04dd667a10b9b032c0d10bd3caeb0751ae70c7 100644 (file)
@@ -27,3 +27,17 @@ config CEPH_LIB_PRETTYDEBUG
 
          If unsure, say N.
 
+config CEPH_LIB_USE_DNS_RESOLVER
+       bool "Use in-kernel support for DNS lookup"
+       depends on CEPH_LIB
+       select DNS_RESOLVER
+       default n
+       help
+         If you say Y here, hostnames (e.g. monitor addresses) will
+         be resolved using the CONFIG_DNS_RESOLVER facility.
+
+         For information on how to use CONFIG_DNS_RESOLVER consult
+         Documentation/networking/dns_resolver.txt
+
+         If unsure, say N.
+
index 2883ea01e68018fcefad3e02cd412e48a8799dc6..97f70e50ad3bb4ed806534fbc74d8a5230000acf 100644 (file)
@@ -432,9 +432,12 @@ EXPORT_SYMBOL(ceph_client_id);
 /*
  * create a fresh client instance
  */
-struct ceph_client *ceph_create_client(struct ceph_options *opt, void *private)
+struct ceph_client *ceph_create_client(struct ceph_options *opt, void *private,
+                                      unsigned supported_features,
+                                      unsigned required_features)
 {
        struct ceph_client *client;
+       struct ceph_entity_addr *myaddr = NULL;
        int err = -ENOMEM;
 
        client = kzalloc(sizeof(*client), GFP_KERNEL);
@@ -449,15 +452,27 @@ struct ceph_client *ceph_create_client(struct ceph_options *opt, void *private)
        client->auth_err = 0;
 
        client->extra_mon_dispatch = NULL;
-       client->supported_features = CEPH_FEATURE_SUPPORTED_DEFAULT;
-       client->required_features = CEPH_FEATURE_REQUIRED_DEFAULT;
-
-       client->msgr = NULL;
+       client->supported_features = CEPH_FEATURE_SUPPORTED_DEFAULT |
+               supported_features;
+       client->required_features = CEPH_FEATURE_REQUIRED_DEFAULT |
+               required_features;
+
+       /* msgr */
+       if (ceph_test_opt(client, MYIP))
+               myaddr = &client->options->my_addr;
+       client->msgr = ceph_messenger_create(myaddr,
+                                            client->supported_features,
+                                            client->required_features);
+       if (IS_ERR(client->msgr)) {
+               err = PTR_ERR(client->msgr);
+               goto fail;
+       }
+       client->msgr->nocrc = ceph_test_opt(client, NOCRC);
 
        /* subsystems */
        err = ceph_monc_init(&client->monc, client);
        if (err < 0)
-               goto fail;
+               goto fail_msgr;
        err = ceph_osdc_init(&client->osdc, client);
        if (err < 0)
                goto fail_monc;
@@ -466,6 +481,8 @@ struct ceph_client *ceph_create_client(struct ceph_options *opt, void *private)
 
 fail_monc:
        ceph_monc_stop(&client->monc);
+fail_msgr:
+       ceph_messenger_destroy(client->msgr);
 fail:
        kfree(client);
        return ERR_PTR(err);
@@ -490,8 +507,7 @@ void ceph_destroy_client(struct ceph_client *client)
 
        ceph_debugfs_client_cleanup(client);
 
-       if (client->msgr)
-               ceph_messenger_destroy(client->msgr);
+       ceph_messenger_destroy(client->msgr);
 
        ceph_destroy_options(client->options);
 
@@ -514,24 +530,9 @@ static int have_mon_and_osd_map(struct ceph_client *client)
  */
 int __ceph_open_session(struct ceph_client *client, unsigned long started)
 {
-       struct ceph_entity_addr *myaddr = NULL;
        int err;
        unsigned long timeout = client->options->mount_timeout * HZ;
 
-       /* initialize the messenger */
-       if (client->msgr == NULL) {
-               if (ceph_test_opt(client, MYIP))
-                       myaddr = &client->options->my_addr;
-               client->msgr = ceph_messenger_create(myaddr,
-                                       client->supported_features,
-                                       client->required_features);
-               if (IS_ERR(client->msgr)) {
-                       client->msgr = NULL;
-                       return PTR_ERR(client->msgr);
-               }
-               client->msgr->nocrc = ceph_test_opt(client, NOCRC);
-       }
-
        /* open session, and wait for mon and osd maps */
        err = ceph_monc_open_session(&client->monc);
        if (err < 0)
index 9918e9eb276e783ac2e359821209d076484c85c0..f466930e26faf9a9b8f43730641cdf5a1b7f7dee 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/string.h>
 #include <linux/bio.h>
 #include <linux/blkdev.h>
+#include <linux/dns_resolver.h>
 #include <net/tcp.h>
 
 #include <linux/ceph/libceph.h>
@@ -1077,6 +1078,101 @@ static void addr_set_port(struct sockaddr_storage *ss, int p)
        }
 }
 
+/*
+ * Unlike other *_pton function semantics, zero indicates success.
+ */
+static int ceph_pton(const char *str, size_t len, struct sockaddr_storage *ss,
+               char delim, const char **ipend)
+{
+       struct sockaddr_in *in4 = (void *)ss;
+       struct sockaddr_in6 *in6 = (void *)ss;
+
+       memset(ss, 0, sizeof(*ss));
+
+       if (in4_pton(str, len, (u8 *)&in4->sin_addr.s_addr, delim, ipend)) {
+               ss->ss_family = AF_INET;
+               return 0;
+       }
+
+       if (in6_pton(str, len, (u8 *)&in6->sin6_addr.s6_addr, delim, ipend)) {
+               ss->ss_family = AF_INET6;
+               return 0;
+       }
+
+       return -EINVAL;
+}
+
+/*
+ * Extract hostname string and resolve using kernel DNS facility.
+ */
+#ifdef CONFIG_CEPH_LIB_USE_DNS_RESOLVER
+static int ceph_dns_resolve_name(const char *name, size_t namelen,
+               struct sockaddr_storage *ss, char delim, const char **ipend)
+{
+       const char *end, *delim_p;
+       char *colon_p, *ip_addr = NULL;
+       int ip_len, ret;
+
+       /*
+        * The end of the hostname occurs immediately preceding the delimiter or
+        * the port marker (':') where the delimiter takes precedence.
+        */
+       delim_p = memchr(name, delim, namelen);
+       colon_p = memchr(name, ':', namelen);
+
+       if (delim_p && colon_p)
+               end = delim_p < colon_p ? delim_p : colon_p;
+       else if (!delim_p && colon_p)
+               end = colon_p;
+       else {
+               end = delim_p;
+               if (!end) /* case: hostname:/ */
+                       end = name + namelen;
+       }
+
+       if (end <= name)
+               return -EINVAL;
+
+       /* do dns_resolve upcall */
+       ip_len = dns_query(NULL, name, end - name, NULL, &ip_addr, NULL);
+       if (ip_len > 0)
+               ret = ceph_pton(ip_addr, ip_len, ss, -1, NULL);
+       else
+               ret = -ESRCH;
+
+       kfree(ip_addr);
+
+       *ipend = end;
+
+       pr_info("resolve '%.*s' (ret=%d): %s\n", (int)(end - name), name,
+                       ret, ret ? "failed" : ceph_pr_addr(ss));
+
+       return ret;
+}
+#else
+static inline int ceph_dns_resolve_name(const char *name, size_t namelen,
+               struct sockaddr_storage *ss, char delim, const char **ipend)
+{
+       return -EINVAL;
+}
+#endif
+
+/*
+ * Parse a server name (IP or hostname). If a valid IP address is not found
+ * then try to extract a hostname to resolve using userspace DNS upcall.
+ */
+static int ceph_parse_server_name(const char *name, size_t namelen,
+                       struct sockaddr_storage *ss, char delim, const char **ipend)
+{
+       int ret;
+
+       ret = ceph_pton(name, namelen, ss, delim, ipend);
+       if (ret)
+               ret = ceph_dns_resolve_name(name, namelen, ss, delim, ipend);
+
+       return ret;
+}
+
 /*
  * Parse an ip[:port] list into an addr array.  Use the default
  * monitor port if a port isn't specified.
@@ -1085,15 +1181,13 @@ int ceph_parse_ips(const char *c, const char *end,
                   struct ceph_entity_addr *addr,
                   int max_count, int *count)
 {
-       int i;
+       int i, ret = -EINVAL;
        const char *p = c;
 
        dout("parse_ips on '%.*s'\n", (int)(end-c), c);
        for (i = 0; i < max_count; i++) {
                const char *ipend;
                struct sockaddr_storage *ss = &addr[i].in_addr;
-               struct sockaddr_in *in4 = (void *)ss;
-               struct sockaddr_in6 *in6 = (void *)ss;
                int port;
                char delim = ',';
 
@@ -1102,15 +1196,11 @@ int ceph_parse_ips(const char *c, const char *end,
                        p++;
                }
 
-               memset(ss, 0, sizeof(*ss));
-               if (in4_pton(p, end - p, (u8 *)&in4->sin_addr.s_addr,
-                            delim, &ipend))
-                       ss->ss_family = AF_INET;
-               else if (in6_pton(p, end - p, (u8 *)&in6->sin6_addr.s6_addr,
-                                 delim, &ipend))
-                       ss->ss_family = AF_INET6;
-               else
+               ret = ceph_parse_server_name(p, end - p, ss, delim, &ipend);
+               if (ret)
                        goto bad;
+               ret = -EINVAL;
+
                p = ipend;
 
                if (delim == ']') {
@@ -1155,7 +1245,7 @@ int ceph_parse_ips(const char *c, const char *end,
 
 bad:
        pr_err("parse_ips bad ip '%.*s'\n", (int)(end - c), c);
-       return -EINVAL;
+       return ret;
 }
 EXPORT_SYMBOL(ceph_parse_ips);
 
@@ -2281,7 +2371,8 @@ EXPORT_SYMBOL(ceph_con_keepalive);
  * construct a new message with given type, size
  * the new msg has a ref count of 1.
  */
-struct ceph_msg *ceph_msg_new(int type, int front_len, gfp_t flags)
+struct ceph_msg *ceph_msg_new(int type, int front_len, gfp_t flags,
+                             bool can_fail)
 {
        struct ceph_msg *m;
 
@@ -2333,7 +2424,7 @@ struct ceph_msg *ceph_msg_new(int type, int front_len, gfp_t flags)
                        m->front.iov_base = kmalloc(front_len, flags);
                }
                if (m->front.iov_base == NULL) {
-                       pr_err("msg_new can't allocate %d bytes\n",
+                       dout("ceph_msg_new can't allocate %d bytes\n",
                             front_len);
                        goto out2;
                }
@@ -2348,7 +2439,14 @@ struct ceph_msg *ceph_msg_new(int type, int front_len, gfp_t flags)
 out2:
        ceph_msg_put(m);
 out:
-       pr_err("msg_new can't create type %d front %d\n", type, front_len);
+       if (!can_fail) {
+               pr_err("msg_new can't create type %d front %d\n", type,
+                      front_len);
+               WARN_ON(1);
+       } else {
+               dout("msg_new can't create type %d front %d\n", type,
+                    front_len);
+       }
        return NULL;
 }
 EXPORT_SYMBOL(ceph_msg_new);
@@ -2398,7 +2496,7 @@ static struct ceph_msg *ceph_alloc_msg(struct ceph_connection *con,
        }
        if (!msg) {
                *skip = 0;
-               msg = ceph_msg_new(type, front_len, GFP_NOFS);
+               msg = ceph_msg_new(type, front_len, GFP_NOFS, false);
                if (!msg) {
                        pr_err("unable to allocate msg type %d len %d\n",
                               type, front_len);
index cbe31fa45508ce8fc06e55edd43b914cc513258f..0b62deae42bd88930f408e0473f13c11b0c252bd 100644 (file)
@@ -116,14 +116,12 @@ static void __send_prepared_auth_request(struct ceph_mon_client *monc, int len)
  */
 static void __close_session(struct ceph_mon_client *monc)
 {
-       if (monc->con) {
-               dout("__close_session closing mon%d\n", monc->cur_mon);
-               ceph_con_revoke(monc->con, monc->m_auth);
-               ceph_con_close(monc->con);
-               monc->cur_mon = -1;
-               monc->pending_auth = 0;
-               ceph_auth_reset(monc->auth);
-       }
+       dout("__close_session closing mon%d\n", monc->cur_mon);
+       ceph_con_revoke(monc->con, monc->m_auth);
+       ceph_con_close(monc->con);
+       monc->cur_mon = -1;
+       monc->pending_auth = 0;
+       ceph_auth_reset(monc->auth);
 }
 
 /*
@@ -302,15 +300,6 @@ void ceph_monc_request_next_osdmap(struct ceph_mon_client *monc)
  */
 int ceph_monc_open_session(struct ceph_mon_client *monc)
 {
-       if (!monc->con) {
-               monc->con = kmalloc(sizeof(*monc->con), GFP_KERNEL);
-               if (!monc->con)
-                       return -ENOMEM;
-               ceph_con_init(monc->client->msgr, monc->con);
-               monc->con->private = monc;
-               monc->con->ops = &mon_con_ops;
-       }
-
        mutex_lock(&monc->mutex);
        __open_session(monc);
        __schedule_delayed(monc);
@@ -528,10 +517,12 @@ int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf)
        init_completion(&req->completion);
 
        err = -ENOMEM;
-       req->request = ceph_msg_new(CEPH_MSG_STATFS, sizeof(*h), GFP_NOFS);
+       req->request = ceph_msg_new(CEPH_MSG_STATFS, sizeof(*h), GFP_NOFS,
+                                   true);
        if (!req->request)
                goto out;
-       req->reply = ceph_msg_new(CEPH_MSG_STATFS_REPLY, 1024, GFP_NOFS);
+       req->reply = ceph_msg_new(CEPH_MSG_STATFS_REPLY, 1024, GFP_NOFS,
+                                 true);
        if (!req->reply)
                goto out;
 
@@ -626,10 +617,12 @@ int ceph_monc_do_poolop(struct ceph_mon_client *monc, u32 op,
        init_completion(&req->completion);
 
        err = -ENOMEM;
-       req->request = ceph_msg_new(CEPH_MSG_POOLOP, sizeof(*h), GFP_NOFS);
+       req->request = ceph_msg_new(CEPH_MSG_POOLOP, sizeof(*h), GFP_NOFS,
+                                   true);
        if (!req->request)
                goto out;
-       req->reply = ceph_msg_new(CEPH_MSG_POOLOP_REPLY, 1024, GFP_NOFS);
+       req->reply = ceph_msg_new(CEPH_MSG_POOLOP_REPLY, 1024, GFP_NOFS,
+                                 true);
        if (!req->reply)
                goto out;
 
@@ -755,13 +748,21 @@ int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl)
        if (err)
                goto out;
 
-       monc->con = NULL;
+       /* connection */
+       monc->con = kmalloc(sizeof(*monc->con), GFP_KERNEL);
+       if (!monc->con)
+               goto out_monmap;
+       ceph_con_init(monc->client->msgr, monc->con);
+       monc->con->private = monc;
+       monc->con->ops = &mon_con_ops;
 
        /* authentication */
        monc->auth = ceph_auth_init(cl->options->name,
                                    cl->options->key);
-       if (IS_ERR(monc->auth))
-               return PTR_ERR(monc->auth);
+       if (IS_ERR(monc->auth)) {
+               err = PTR_ERR(monc->auth);
+               goto out_con;
+       }
        monc->auth->want_keys =
                CEPH_ENTITY_TYPE_AUTH | CEPH_ENTITY_TYPE_MON |
                CEPH_ENTITY_TYPE_OSD | CEPH_ENTITY_TYPE_MDS;
@@ -770,19 +771,21 @@ int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl)
        err = -ENOMEM;
        monc->m_subscribe_ack = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE_ACK,
                                     sizeof(struct ceph_mon_subscribe_ack),
-                                    GFP_NOFS);
+                                    GFP_NOFS, true);
        if (!monc->m_subscribe_ack)
-               goto out_monmap;
+               goto out_auth;
 
-       monc->m_subscribe = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE, 96, GFP_NOFS);
+       monc->m_subscribe = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE, 96, GFP_NOFS,
+                                        true);
        if (!monc->m_subscribe)
                goto out_subscribe_ack;
 
-       monc->m_auth_reply = ceph_msg_new(CEPH_MSG_AUTH_REPLY, 4096, GFP_NOFS);
+       monc->m_auth_reply = ceph_msg_new(CEPH_MSG_AUTH_REPLY, 4096, GFP_NOFS,
+                                         true);
        if (!monc->m_auth_reply)
                goto out_subscribe;
 
-       monc->m_auth = ceph_msg_new(CEPH_MSG_AUTH, 4096, GFP_NOFS);
+       monc->m_auth = ceph_msg_new(CEPH_MSG_AUTH, 4096, GFP_NOFS, true);
        monc->pending_auth = 0;
        if (!monc->m_auth)
                goto out_auth_reply;
@@ -808,6 +811,10 @@ out_subscribe:
        ceph_msg_put(monc->m_subscribe);
 out_subscribe_ack:
        ceph_msg_put(monc->m_subscribe_ack);
+out_auth:
+       ceph_auth_destroy(monc->auth);
+out_con:
+       monc->con->ops->put(monc->con);
 out_monmap:
        kfree(monc->monmap);
 out:
@@ -822,11 +829,11 @@ void ceph_monc_stop(struct ceph_mon_client *monc)
 
        mutex_lock(&monc->mutex);
        __close_session(monc);
-       if (monc->con) {
-               monc->con->private = NULL;
-               monc->con->ops->put(monc->con);
-               monc->con = NULL;
-       }
+
+       monc->con->private = NULL;
+       monc->con->ops->put(monc->con);
+       monc->con = NULL;
+
        mutex_unlock(&monc->mutex);
 
        ceph_auth_destroy(monc->auth);
@@ -973,7 +980,7 @@ static struct ceph_msg *mon_alloc_msg(struct ceph_connection *con,
        case CEPH_MSG_MON_MAP:
        case CEPH_MSG_MDS_MAP:
        case CEPH_MSG_OSD_MAP:
-               m = ceph_msg_new(type, front_len, GFP_NOFS);
+               m = ceph_msg_new(type, front_len, GFP_NOFS, false);
                break;
        }
 
@@ -1000,7 +1007,7 @@ static void mon_fault(struct ceph_connection *con)
        if (!con->private)
                goto out;
 
-       if (monc->con && !monc->hunting)
+       if (!monc->hunting)
                pr_info("mon%d %s session lost, "
                        "hunting for new mon\n", monc->cur_mon,
                        ceph_pr_addr(&monc->con->peer_addr.in_addr));
index 1f4cb30a42c558e89cfa696af9efcacc4209c0d6..11d5f4196a73cfeef3492389c76f9f285c50188d 100644 (file)
@@ -12,7 +12,7 @@ static void *msgpool_alloc(gfp_t gfp_mask, void *arg)
        struct ceph_msgpool *pool = arg;
        struct ceph_msg *msg;
 
-       msg = ceph_msg_new(0, pool->front_len, gfp_mask);
+       msg = ceph_msg_new(0, pool->front_len, gfp_mask, true);
        if (!msg) {
                dout("msgpool_alloc %s failed\n", pool->name);
        } else {
@@ -61,7 +61,7 @@ struct ceph_msg *ceph_msgpool_get(struct ceph_msgpool *pool,
                WARN_ON(1);
 
                /* try to alloc a fresh message */
-               return ceph_msg_new(0, front_len, GFP_NOFS);
+               return ceph_msg_new(0, front_len, GFP_NOFS, false);
        }
 
        msg = mempool_alloc(pool->pool, GFP_NOFS);
index 88ad8a2501b56d10484465ee01453f262bee8b2a..733e46008b89d6e67397d779edf9ccb5cb3e5c8a 100644 (file)
@@ -227,7 +227,7 @@ struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
                msg = ceph_msgpool_get(&osdc->msgpool_op_reply, 0);
        else
                msg = ceph_msg_new(CEPH_MSG_OSD_OPREPLY,
-                                  OSD_OPREPLY_FRONT_LEN, gfp_flags);
+                                  OSD_OPREPLY_FRONT_LEN, gfp_flags, true);
        if (!msg) {
                ceph_osdc_put_request(req);
                return NULL;
@@ -250,7 +250,7 @@ struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
        if (use_mempool)
                msg = ceph_msgpool_get(&osdc->msgpool_op, 0);
        else
-               msg = ceph_msg_new(CEPH_MSG_OSD_OP, msg_size, gfp_flags);
+               msg = ceph_msg_new(CEPH_MSG_OSD_OP, msg_size, gfp_flags, true);
        if (!msg) {
                ceph_osdc_put_request(req);
                return NULL;
@@ -943,7 +943,7 @@ EXPORT_SYMBOL(ceph_osdc_set_request_linger);
  * Caller should hold map_sem for read and request_mutex.
  */
 static int __map_request(struct ceph_osd_client *osdc,
-                        struct ceph_osd_request *req)
+                        struct ceph_osd_request *req, int force_resend)
 {
        struct ceph_osd_request_head *reqhead = req->r_request->front.iov_base;
        struct ceph_pg pgid;
@@ -967,7 +967,8 @@ static int __map_request(struct ceph_osd_client *osdc,
                num = err;
        }
 
-       if ((req->r_osd && req->r_osd->o_osd == o &&
+       if ((!force_resend &&
+            req->r_osd && req->r_osd->o_osd == o &&
             req->r_sent >= req->r_osd->o_incarnation &&
             req->r_num_pg_osds == num &&
             memcmp(req->r_pg_osds, acting, sizeof(acting[0])*num) == 0) ||
@@ -1289,18 +1290,18 @@ static void reset_changed_osds(struct ceph_osd_client *osdc)
  *
  * Caller should hold map_sem for read and request_mutex.
  */
-static void kick_requests(struct ceph_osd_client *osdc)
+static void kick_requests(struct ceph_osd_client *osdc, int force_resend)
 {
        struct ceph_osd_request *req, *nreq;
        struct rb_node *p;
        int needmap = 0;
        int err;
 
-       dout("kick_requests\n");
+       dout("kick_requests %s\n", force_resend ? " (force resend)" : "");
        mutex_lock(&osdc->request_mutex);
        for (p = rb_first(&osdc->requests); p; p = rb_next(p)) {
                req = rb_entry(p, struct ceph_osd_request, r_node);
-               err = __map_request(osdc, req);
+               err = __map_request(osdc, req, force_resend);
                if (err < 0)
                        continue;  /* error */
                if (req->r_osd == NULL) {
@@ -1318,7 +1319,7 @@ static void kick_requests(struct ceph_osd_client *osdc)
                                 r_linger_item) {
                dout("linger req=%p req->r_osd=%p\n", req, req->r_osd);
 
-               err = __map_request(osdc, req);
+               err = __map_request(osdc, req, force_resend);
                if (err == 0)
                        continue;  /* no change and no osd was specified */
                if (err < 0)
@@ -1395,7 +1396,7 @@ void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg)
                                ceph_osdmap_destroy(osdc->osdmap);
                                osdc->osdmap = newmap;
                        }
-                       kick_requests(osdc);
+                       kick_requests(osdc, 0);
                        reset_changed_osds(osdc);
                } else {
                        dout("ignoring incremental map %u len %d\n",
@@ -1423,6 +1424,8 @@ void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg)
                             "older than our %u\n", epoch, maplen,
                             osdc->osdmap->epoch);
                } else {
+                       int skipped_map = 0;
+
                        dout("taking full map %u len %d\n", epoch, maplen);
                        newmap = osdmap_decode(&p, p+maplen);
                        if (IS_ERR(newmap)) {
@@ -1432,9 +1435,12 @@ void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg)
                        BUG_ON(!newmap);
                        oldmap = osdc->osdmap;
                        osdc->osdmap = newmap;
-                       if (oldmap)
+                       if (oldmap) {
+                               if (oldmap->epoch + 1 < newmap->epoch)
+                                       skipped_map = 1;
                                ceph_osdmap_destroy(oldmap);
-                       kick_requests(osdc);
+                       }
+                       kick_requests(osdc, skipped_map);
                }
                p += maplen;
                nr_maps--;
@@ -1707,7 +1713,7 @@ int ceph_osdc_start_request(struct ceph_osd_client *osdc,
         * the request still han't been touched yet.
         */
        if (req->r_sent == 0) {
-               rc = __map_request(osdc, req);
+               rc = __map_request(osdc, req, 0);
                if (rc < 0) {
                        if (nofail) {
                                dout("osdc_start_request failed map, "
@@ -2032,7 +2038,7 @@ static struct ceph_msg *get_reply(struct ceph_connection *con,
        if (front > req->r_reply->front.iov_len) {
                pr_warning("get_reply front %d > preallocated %d\n",
                           front, (int)req->r_reply->front.iov_len);
-               m = ceph_msg_new(CEPH_MSG_OSD_OPREPLY, front, GFP_NOFS);
+               m = ceph_msg_new(CEPH_MSG_OSD_OPREPLY, front, GFP_NOFS, false);
                if (!m)
                        goto out;
                ceph_msg_put(req->r_reply);
@@ -2080,7 +2086,7 @@ static struct ceph_msg *alloc_msg(struct ceph_connection *con,
        switch (type) {
        case CEPH_MSG_OSD_MAP:
        case CEPH_MSG_WATCH_NOTIFY:
-               return ceph_msg_new(type, front, GFP_NOFS);
+               return ceph_msg_new(type, front, GFP_NOFS, false);
        case CEPH_MSG_OSD_OPREPLY:
                return get_reply(con, hdr, skip);
        default:
index edcf019c056dcffe2673abe26f5dd8e36717aa6c..6ba50a1e404c4bac04cc7d56718865d5a1749c2f 100644 (file)
@@ -3283,18 +3283,18 @@ another_round:
 ncls:
 #endif
 
+       rx_handler = rcu_dereference(skb->dev->rx_handler);
        if (vlan_tx_tag_present(skb)) {
                if (pt_prev) {
                        ret = deliver_skb(skb, pt_prev, orig_dev);
                        pt_prev = NULL;
                }
-               if (vlan_do_receive(&skb))
+               if (vlan_do_receive(&skb, !rx_handler))
                        goto another_round;
                else if (unlikely(!skb))
                        goto out;
        }
 
-       rx_handler = rcu_dereference(skb->dev->rx_handler);
        if (rx_handler) {
                if (pt_prev) {
                        ret = deliver_skb(skb, pt_prev, orig_dev);
index b74f76117dcf6fde6e660cafe7334d22225bf40f..17ee85ce148dee3ac5e12e572a61f38dcfa8d381 100644 (file)
@@ -271,7 +271,7 @@ static int dccp_v6_send_response(struct sock *sk, struct request_sock *req,
                                                         &ireq6->loc_addr,
                                                         &ireq6->rmt_addr);
                ipv6_addr_copy(&fl6.daddr, &ireq6->rmt_addr);
-               err = ip6_xmit(sk, skb, &fl6, opt);
+               err = ip6_xmit(sk, skb, &fl6, opt, np->tclass);
                err = net_xmit_eval(err);
        }
 
@@ -326,7 +326,7 @@ static void dccp_v6_ctl_send_reset(struct sock *sk, struct sk_buff *rxskb)
        dst = ip6_dst_lookup_flow(ctl_sk, &fl6, NULL, false);
        if (!IS_ERR(dst)) {
                skb_dst_set(skb, dst);
-               ip6_xmit(ctl_sk, skb, &fl6, NULL);
+               ip6_xmit(ctl_sk, skb, &fl6, NULL, 0);
                DCCP_INC_STATS_BH(DCCP_MIB_OUTSEGS);
                DCCP_INC_STATS_BH(DCCP_MIB_OUTRSTS);
                return;
index 85a2fbebd7ef63f30b17770442097d3f049dc39e..66363b689ad652586e35ecc49362fee864cf7685 100644 (file)
@@ -345,6 +345,7 @@ void tcp_time_wait(struct sock *sk, int state, int timeo)
                        tw6 = inet6_twsk((struct sock *)tw);
                        ipv6_addr_copy(&tw6->tw_v6_daddr, &np->daddr);
                        ipv6_addr_copy(&tw6->tw_v6_rcv_saddr, &np->rcv_saddr);
+                       tw->tw_tclass = np->tclass;
                        tw->tw_ipv6only = np->ipv6only;
                }
 #endif
index e39239e6426edbc5d5e462ff35e39266873431f9..d0611a5de45fbbb32a5ca5d78338fa02fb06e8fe 100644 (file)
@@ -1713,6 +1713,40 @@ addrconf_prefix_route(struct in6_addr *pfx, int plen, struct net_device *dev,
        ip6_route_add(&cfg);
 }
 
+
+static struct rt6_info *addrconf_get_prefix_route(const struct in6_addr *pfx,
+                                                 int plen,
+                                                 const struct net_device *dev,
+                                                 u32 flags, u32 noflags)
+{
+       struct fib6_node *fn;
+       struct rt6_info *rt = NULL;
+       struct fib6_table *table;
+
+       table = fib6_get_table(dev_net(dev), RT6_TABLE_PREFIX);
+       if (table == NULL)
+               return NULL;
+
+       write_lock_bh(&table->tb6_lock);
+       fn = fib6_locate(&table->tb6_root, pfx, plen, NULL, 0);
+       if (!fn)
+               goto out;
+       for (rt = fn->leaf; rt; rt = rt->dst.rt6_next) {
+               if (rt->rt6i_dev->ifindex != dev->ifindex)
+                       continue;
+               if ((rt->rt6i_flags & flags) != flags)
+                       continue;
+               if ((noflags != 0) && ((rt->rt6i_flags & flags) != 0))
+                       continue;
+               dst_hold(&rt->dst);
+               break;
+       }
+out:
+       write_unlock_bh(&table->tb6_lock);
+       return rt;
+}
+
+
 /* Create "default" multicast route to the interface */
 
 static void addrconf_add_mroute(struct net_device *dev)
@@ -1842,10 +1876,13 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len)
                if (addrconf_finite_timeout(rt_expires))
                        rt_expires *= HZ;
 
-               rt = rt6_lookup(net, &pinfo->prefix, NULL,
-                               dev->ifindex, 1);
+               rt = addrconf_get_prefix_route(&pinfo->prefix,
+                                              pinfo->prefix_len,
+                                              dev,
+                                              RTF_ADDRCONF | RTF_PREFIX_RT,
+                                              RTF_GATEWAY | RTF_DEFAULT);
 
-               if (rt && addrconf_is_prefix_route(rt)) {
+               if (rt) {
                        /* Autoconf prefix route */
                        if (valid_lft == 0) {
                                ip6_del_rt(rt);
index 2916200f90c1d21541e43012c5346929831b89c9..fee46d5a2f125f54451f5115dbddd050138af3a7 100644 (file)
@@ -248,7 +248,7 @@ int inet6_csk_xmit(struct sk_buff *skb, struct flowi *fl_unused)
        /* Restore final destination back after routing done */
        ipv6_addr_copy(&fl6.daddr, &np->daddr);
 
-       res = ip6_xmit(sk, skb, &fl6, np->opt);
+       res = ip6_xmit(sk, skb, &fl6, np->opt, np->tclass);
        rcu_read_unlock();
        return res;
 }
index 1c9bf8b5c30adad2e1250177aaffa9f70036a590..84d0bd5cac939814edaed4379f09464a958d61bf 100644 (file)
@@ -180,7 +180,7 @@ int ip6_output(struct sk_buff *skb)
  */
 
 int ip6_xmit(struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6,
-            struct ipv6_txoptions *opt)
+            struct ipv6_txoptions *opt, int tclass)
 {
        struct net *net = sock_net(sk);
        struct ipv6_pinfo *np = inet6_sk(sk);
@@ -190,7 +190,6 @@ int ip6_xmit(struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6,
        u8  proto = fl6->flowi6_proto;
        int seg_len = skb->len;
        int hlimit = -1;
-       int tclass = 0;
        u32 mtu;
 
        if (opt) {
@@ -228,10 +227,8 @@ int ip6_xmit(struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6,
        /*
         *      Fill in the IPv6 header
         */
-       if (np) {
-               tclass = np->tclass;
+       if (np)
                hlimit = np->hop_limit;
-       }
        if (hlimit < 0)
                hlimit = ip6_dst_hoplimit(dst);
 
@@ -1126,7 +1123,7 @@ static inline int ip6_ufo_append_data(struct sock *sk,
                        hh_len + fragheaderlen + transhdrlen + 20,
                        (flags & MSG_DONTWAIT), &err);
                if (skb == NULL)
-                       return -ENOMEM;
+                       return err;
 
                /* reserve space for Hardware header */
                skb_reserve(skb, hh_len);
index fb545edef6ea63e235d6ef161fb057bc0face6dc..57b82dc1ae91c8426b0894b5e4e6030453c66352 100644 (file)
@@ -1086,11 +1086,10 @@ struct dst_entry *icmp6_dst_alloc(struct net_device *dev,
        rt->dst.output  = ip6_output;
        dst_set_neighbour(&rt->dst, neigh);
        atomic_set(&rt->dst.__refcnt, 1);
-       dst_metric_set(&rt->dst, RTAX_HOPLIMIT, 255);
-
        ipv6_addr_copy(&rt->rt6i_dst.addr, addr);
        rt->rt6i_dst.plen = 128;
        rt->rt6i_idev     = idev;
+       dst_metric_set(&rt->dst, RTAX_HOPLIMIT, 255);
 
        spin_lock_bh(&icmp6_dst_lock);
        rt->dst.next = icmp6_dst_gc_list;
index c8683fcc487a82c97b3e14ba4d170057818a092e..10b2b3165a1aff4ebc6cde947aae64a687b11a5b 100644 (file)
@@ -513,7 +513,7 @@ static int tcp_v6_send_synack(struct sock *sk, struct request_sock *req,
                __tcp_v6_send_check(skb, &treq->loc_addr, &treq->rmt_addr);
 
                ipv6_addr_copy(&fl6.daddr, &treq->rmt_addr);
-               err = ip6_xmit(sk, skb, &fl6, opt);
+               err = ip6_xmit(sk, skb, &fl6, opt, np->tclass);
                err = net_xmit_eval(err);
        }
 
@@ -979,7 +979,7 @@ static int tcp6_gro_complete(struct sk_buff *skb)
 }
 
 static void tcp_v6_send_response(struct sk_buff *skb, u32 seq, u32 ack, u32 win,
-                                u32 ts, struct tcp_md5sig_key *key, int rst)
+                                u32 ts, struct tcp_md5sig_key *key, int rst, u8 tclass)
 {
        const struct tcphdr *th = tcp_hdr(skb);
        struct tcphdr *t1;
@@ -1060,7 +1060,7 @@ static void tcp_v6_send_response(struct sk_buff *skb, u32 seq, u32 ack, u32 win,
        dst = ip6_dst_lookup_flow(ctl_sk, &fl6, NULL, false);
        if (!IS_ERR(dst)) {
                skb_dst_set(buff, dst);
-               ip6_xmit(ctl_sk, buff, &fl6, NULL);
+               ip6_xmit(ctl_sk, buff, &fl6, NULL, tclass);
                TCP_INC_STATS_BH(net, TCP_MIB_OUTSEGS);
                if (rst)
                        TCP_INC_STATS_BH(net, TCP_MIB_OUTRSTS);
@@ -1093,13 +1093,13 @@ static void tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb)
                ack_seq = ntohl(th->seq) + th->syn + th->fin + skb->len -
                          (th->doff << 2);
 
-       tcp_v6_send_response(skb, seq, ack_seq, 0, 0, key, 1);
+       tcp_v6_send_response(skb, seq, ack_seq, 0, 0, key, 1, 0);
 }
 
 static void tcp_v6_send_ack(struct sk_buff *skb, u32 seq, u32 ack, u32 win, u32 ts,
-                           struct tcp_md5sig_key *key)
+                           struct tcp_md5sig_key *key, u8 tclass)
 {
-       tcp_v6_send_response(skb, seq, ack, win, ts, key, 0);
+       tcp_v6_send_response(skb, seq, ack, win, ts, key, 0, tclass);
 }
 
 static void tcp_v6_timewait_ack(struct sock *sk, struct sk_buff *skb)
@@ -1109,7 +1109,8 @@ static void tcp_v6_timewait_ack(struct sock *sk, struct sk_buff *skb)
 
        tcp_v6_send_ack(skb, tcptw->tw_snd_nxt, tcptw->tw_rcv_nxt,
                        tcptw->tw_rcv_wnd >> tw->tw_rcv_wscale,
-                       tcptw->tw_ts_recent, tcp_twsk_md5_key(tcptw));
+                       tcptw->tw_ts_recent, tcp_twsk_md5_key(tcptw),
+                       tw->tw_tclass);
 
        inet_twsk_put(tw);
 }
@@ -1118,7 +1119,7 @@ static void tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
                                  struct request_sock *req)
 {
        tcp_v6_send_ack(skb, tcp_rsk(req)->snt_isn + 1, tcp_rsk(req)->rcv_isn + 1, req->rcv_wnd, req->ts_recent,
-                       tcp_v6_md5_do_lookup(sk, &ipv6_hdr(skb)->daddr));
+                       tcp_v6_md5_do_lookup(sk, &ipv6_hdr(skb)->daddr), 0);
 }
 
 
index b6753f45624e3e3fdd17c4338173778ee21b136b..d86583f4831d73f7fd4ee6a8d4f898eb3b1a3f3e 100644 (file)
@@ -27,7 +27,7 @@
 #include <net/nfc/nfc.h>
 #include <net/sock.h>
 
-__attribute__((format (printf, 2, 3)))
+__printf(2, 3)
 int nfc_printk(const char *level, const char *fmt, ...);
 
 #define nfc_info(fmt, arg...) nfc_printk(KERN_INFO, fmt, ##arg)
index da8adac2bf06f95504ba21e8fdc6c5e09435ca9e..7eaba1831f0d522ffbe38e82ce60d3cb80d1065f 100644 (file)
@@ -36,8 +36,8 @@
 #define rdsdebug(fmt, args...) pr_debug("%s(): " fmt, __func__ , ##args)
 #else
 /* sigh, pr_debug() causes unused variable warnings */
-static inline void __attribute__ ((format (printf, 1, 2)))
-rdsdebug(char *fmt, ...)
+static inline __printf(1, 2)
+void rdsdebug(char *fmt, ...)
 {
 }
 #endif
@@ -625,8 +625,8 @@ void rds_for_each_conn_info(struct socket *sock, unsigned int len,
                          struct rds_info_lengths *lens,
                          int (*visitor)(struct rds_connection *, void *),
                          size_t item_len);
-void __rds_conn_error(struct rds_connection *conn, const char *, ...)
-                               __attribute__ ((format (printf, 2, 3)));
+__printf(2, 3)
+void __rds_conn_error(struct rds_connection *conn, const char *, ...);
 #define rds_conn_error(conn, fmt...) \
        __rds_conn_error(conn, KERN_WARNING "RDS: " fmt)
 
index aabaee41dd3eb07613629e78462601003902dee6..810427833bcdc9096e0105bfdb1c731fd71baf31 100644 (file)
@@ -243,7 +243,7 @@ static int sctp_v6_xmit(struct sk_buff *skb, struct sctp_transport *transport)
        if (!(transport->param_flags & SPP_PMTUD_ENABLE))
                skb->local_df = 1;
 
-       return ip6_xmit(sk, skb, &fl6, np->opt);
+       return ip6_xmit(sk, skb, &fl6, np->opt, np->tclass);
 }
 
 /* Returns the dst cache entry for the given source and destination ip
index 30d70abb4e2c7e7577758b4857401a04b1992b0f..dd5cc00ed5593c04e66825ab9cdb0beb19810592 100644 (file)
@@ -971,9 +971,8 @@ static void svc_unregister(const struct svc_serv *serv)
 /*
  * Printk the given error with the address of the client that caused it.
  */
-static int
-__attribute__ ((format (printf, 2, 3)))
-svc_printk(struct svc_rqst *rqstp, const char *fmt, ...)
+static __printf(2, 3)
+int svc_printk(struct svc_rqst *rqstp, const char *fmt, ...)
 {
        va_list args;
        int     r;
index 0b3e35c9ef08552b4b67f62479895ad826388523..5e93342d22f9aa6c3ba9144ddd7926ff8f800f67 100755 (executable)
@@ -240,9 +240,8 @@ our $NonptrType;
 our $Type;
 our $Declare;
 
-our $UTF8      = qr {
-       [\x09\x0A\x0D\x20-\x7E]              # ASCII
-       | [\xC2-\xDF][\x80-\xBF]             # non-overlong 2-byte
+our $NON_ASCII_UTF8    = qr{
+       [\xC2-\xDF][\x80-\xBF]               # non-overlong 2-byte
        |  \xE0[\xA0-\xBF][\x80-\xBF]        # excluding overlongs
        | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}  # straight 3-byte
        |  \xED[\x80-\x9F][\x80-\xBF]        # excluding surrogates
@@ -251,6 +250,11 @@ our $UTF8  = qr {
        |  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
 }x;
 
+our $UTF8      = qr{
+       [\x09\x0A\x0D\x20-\x7E]              # ASCII
+       | $NON_ASCII_UTF8
+}x;
+
 our $typeTypedefs = qr{(?x:
        (?:__)?(?:u|s|be|le)(?:8|16|32|64)|
        atomic_t
@@ -1330,6 +1334,9 @@ sub process {
        my $signoff = 0;
        my $is_patch = 0;
 
+       my $in_header_lines = 1;
+       my $in_commit_log = 0;          #Scanning lines before patch
+
        our @report = ();
        our $cnt_lines = 0;
        our $cnt_error = 0;
@@ -1497,7 +1504,6 @@ sub process {
                if ($line =~ /^diff --git.*?(\S+)$/) {
                        $realfile = $1;
                        $realfile =~ s@^([^/]*)/@@;
-
                } elsif ($line =~ /^\+\+\+\s+(\S+)/) {
                        $realfile = $1;
                        $realfile =~ s@^([^/]*)/@@;
@@ -1536,6 +1542,7 @@ sub process {
 # Check the patch for a signoff:
                if ($line =~ /^\s*signed-off-by:/i) {
                        $signoff++;
+                       $in_commit_log = 0;
                }
 
 # Check signature styles
@@ -1613,6 +1620,21 @@ sub process {
                            "Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr);
                }
 
+# Check if it's the start of a commit log
+# (not a header line and we haven't seen the patch filename)
+               if ($in_header_lines && $realfile =~ /^$/ &&
+                   $rawline !~ /^(commit\b|from\b|\w+:).+$/i) {
+                       $in_header_lines = 0;
+                       $in_commit_log = 1;
+               }
+
+# Still not yet in a patch, check for any UTF-8
+               if ($in_commit_log && $realfile =~ /^$/ &&
+                   $rawline =~ /$NON_ASCII_UTF8/) {
+                       CHK("UTF8_BEFORE_PATCH",
+                           "8-bit UTF-8 used in possible commit log\n" . $herecurr);
+               }
+
 # ignore non-hunk lines and lines being removed
                next if (!$hunk_line || $line =~ /^-/);
 
@@ -3151,10 +3173,10 @@ sub process {
                             "consider using a completion\n" . $herecurr);
 
                }
-# recommend kstrto* over simple_strto*
-               if ($line =~ /\bsimple_(strto.*?)\s*\(/) {
+# recommend kstrto* over simple_strto* and strict_strto*
+               if ($line =~ /\b((simple|strict)_(strto(l|ll|ul|ull)))\s*\(/) {
                        WARN("CONSIDER_KSTRTO",
-                            "consider using kstrto* in preference to simple_$1\n" . $herecurr);
+                            "$1 is obsolete, use k$3 instead\n" . $herecurr);
                }
 # check for __initcall(), use device_initcall() explicitly please
                if ($line =~ /^.\s*__initcall\s*\(/) {
index 338b510e90275b1da873ed83aa907c404997d353..4c48e13448f84e0df200ab0a2f0895d0eb5a709c 100644 (file)
@@ -38,7 +38,7 @@ long compat_keyctl_instantiate_key_iov(
 
        ret = compat_rw_copy_check_uvector(WRITE, _payload_iov, ioc,
                                           ARRAY_SIZE(iovstack),
-                                          iovstack, &iov);
+                                          iovstack, &iov, 1);
        if (ret < 0)
                return ret;
        if (ret == 0)
index f33804c1b4c8105b3f66c4daa10475625b286723..dcc843cb0f80de0f899ada23d8bf80d25e023e5e 100644 (file)
@@ -293,7 +293,7 @@ static char *datablob_format(struct encrypted_key_payload *epayload,
        /* convert the hex encoded iv, encrypted-data and HMAC to ascii */
        bufp = &ascii_buf[len];
        for (i = 0; i < (asciiblob_len - len) / 2; i++)
-               bufp = pack_hex_byte(bufp, iv[i]);
+               bufp = hex_byte_pack(bufp, iv[i]);
 out:
        return ascii_buf;
 }
index eca51918c951d3a28db16bf0f61c749722b6ac64..0b3f5d72af1cecbd06b33c2151ec570a4cfaa2ee 100644 (file)
@@ -1065,7 +1065,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
                goto no_payload;
 
        ret = rw_copy_check_uvector(WRITE, _payload_iov, ioc,
-                                   ARRAY_SIZE(iovstack), iovstack, &iov);
+                                   ARRAY_SIZE(iovstack), iovstack, &iov, 1);
        if (ret < 0)
                return ret;
        if (ret == 0)
index 0964fc236946c0ec310c63bd9b3159583835df34..0ed5fdf238a22c6712e5375207f5bd6d8a168ef6 100644 (file)
@@ -1098,7 +1098,7 @@ static long trusted_read(const struct key *key, char __user *buffer,
 
        bufp = ascii_buf;
        for (i = 0; i < p->blob_len; i++)
-               bufp = pack_hex_byte(bufp, p->blob[i]);
+               bufp = hex_byte_pack(bufp, p->blob[i]);
        if ((copy_to_user(buffer, ascii_buf, 2 * p->blob_len)) != 0) {
                kfree(ascii_buf);
                return -EFAULT;
index 3687a6cc9881edf17a0e4e9ba8966d840c6cff79..762af68c8996fbb83a822638f76f2c29a7d63f9a 100644 (file)
@@ -1067,7 +1067,6 @@ static int onyx_i2c_probe(struct i2c_client *client,
        printk(KERN_DEBUG PFX "created and attached onyx instance\n");
        return 0;
  fail:
-       i2c_set_clientdata(client, NULL);
        kfree(onyx);
        return -ENODEV;
 }
@@ -1112,8 +1111,7 @@ static int onyx_i2c_remove(struct i2c_client *client)
 
        aoa_codec_unregister(&onyx->codec);
        of_node_put(onyx->codec.node);
-       if (onyx->codec_info)
-               kfree(onyx->codec_info);
+       kfree(onyx->codec_info);
        kfree(onyx);
        return 0;
 }
index d0cead38d5fb785acc2812f107d88802db0f47a4..e518d38b1c7465fc11fa62db2f4795f8468e235e 100644 (file)
@@ -443,7 +443,7 @@ static int aaci_pcm_open(struct snd_pcm_substream *substream)
        mutex_lock(&aaci->irq_lock);
        if (!aaci->users++) {
                ret = request_irq(aaci->dev->irq[0], aaci_irq,
-                          IRQF_SHARED | IRQF_DISABLED, DRIVER_NAME, aaci);
+                          IRQF_SHARED, DRIVER_NAME, aaci);
                if (ret != 0)
                        aaci->users--;
        }
index 88eec3847df24b88aabd6228de410e369bf8abb8..8ad65352bf91367f4e4ce84e78fe786738688e4a 100644 (file)
@@ -359,7 +359,7 @@ int __devinit pxa2xx_ac97_hw_probe(struct platform_device *dev)
        if (ret)
                goto err_clk2;
 
-       ret = request_irq(IRQ_AC97, pxa2xx_ac97_irq, IRQF_DISABLED, "AC97", NULL);
+       ret = request_irq(IRQ_AC97, pxa2xx_ac97_irq, 0, "AC97", NULL);
        if (ret < 0)
                goto err_irq;
 
index f8c5be46451058ba5a7f25d9a81195fd02643f92..978fe1a8e9f0877ece853c788a5ed371f9bdfa77 100644 (file)
@@ -989,7 +989,6 @@ struct user_element {
        void *tlv_data;                 /* TLV data */
        unsigned long tlv_data_size;    /* TLV data size */
        void *priv_data;                /* private data (like strings for enumerated type) */
-       unsigned long priv_data_size;   /* size of private data in bytes */
 };
 
 static int snd_ctl_elem_user_info(struct snd_kcontrol *kcontrol,
@@ -1001,6 +1000,28 @@ static int snd_ctl_elem_user_info(struct snd_kcontrol *kcontrol,
        return 0;
 }
 
+static int snd_ctl_elem_user_enum_info(struct snd_kcontrol *kcontrol,
+                                      struct snd_ctl_elem_info *uinfo)
+{
+       struct user_element *ue = kcontrol->private_data;
+       const char *names;
+       unsigned int item;
+
+       item = uinfo->value.enumerated.item;
+
+       *uinfo = ue->info;
+
+       item = min(item, uinfo->value.enumerated.items - 1);
+       uinfo->value.enumerated.item = item;
+
+       names = ue->priv_data;
+       for (; item > 0; --item)
+               names += strlen(names) + 1;
+       strcpy(uinfo->value.enumerated.name, names);
+
+       return 0;
+}
+
 static int snd_ctl_elem_user_get(struct snd_kcontrol *kcontrol,
                                 struct snd_ctl_elem_value *ucontrol)
 {
@@ -1055,11 +1076,46 @@ static int snd_ctl_elem_user_tlv(struct snd_kcontrol *kcontrol,
        return change;
 }
 
+static int snd_ctl_elem_init_enum_names(struct user_element *ue)
+{
+       char *names, *p;
+       size_t buf_len, name_len;
+       unsigned int i;
+
+       if (ue->info.value.enumerated.names_length > 64 * 1024)
+               return -EINVAL;
+
+       names = memdup_user(
+               (const void __user *)ue->info.value.enumerated.names_ptr,
+               ue->info.value.enumerated.names_length);
+       if (IS_ERR(names))
+               return PTR_ERR(names);
+
+       /* check that there are enough valid names */
+       buf_len = ue->info.value.enumerated.names_length;
+       p = names;
+       for (i = 0; i < ue->info.value.enumerated.items; ++i) {
+               name_len = strnlen(p, buf_len);
+               if (name_len == 0 || name_len >= 64 || name_len == buf_len) {
+                       kfree(names);
+                       return -EINVAL;
+               }
+               p += name_len + 1;
+               buf_len -= name_len + 1;
+       }
+
+       ue->priv_data = names;
+       ue->info.value.enumerated.names_ptr = 0;
+
+       return 0;
+}
+
 static void snd_ctl_elem_user_free(struct snd_kcontrol *kcontrol)
 {
        struct user_element *ue = kcontrol->private_data;
-       if (ue->tlv_data)
-               kfree(ue->tlv_data);
+
+       kfree(ue->tlv_data);
+       kfree(ue->priv_data);
        kfree(ue);
 }
 
@@ -1072,8 +1128,8 @@ static int snd_ctl_elem_add(struct snd_ctl_file *file,
        long private_size;
        struct user_element *ue;
        int idx, err;
-       
-       if (card->user_ctl_count >= MAX_USER_CONTROLS)
+
+       if (!replace && card->user_ctl_count >= MAX_USER_CONTROLS)
                return -ENOMEM;
        if (info->count < 1)
                return -EINVAL;
@@ -1101,7 +1157,10 @@ static int snd_ctl_elem_add(struct snd_ctl_file *file,
        memcpy(&kctl.id, &info->id, sizeof(info->id));
        kctl.count = info->owner ? info->owner : 1;
        access |= SNDRV_CTL_ELEM_ACCESS_USER;
-       kctl.info = snd_ctl_elem_user_info;
+       if (info->type == SNDRV_CTL_ELEM_TYPE_ENUMERATED)
+               kctl.info = snd_ctl_elem_user_enum_info;
+       else
+               kctl.info = snd_ctl_elem_user_info;
        if (access & SNDRV_CTL_ELEM_ACCESS_READ)
                kctl.get = snd_ctl_elem_user_get;
        if (access & SNDRV_CTL_ELEM_ACCESS_WRITE)
@@ -1122,6 +1181,11 @@ static int snd_ctl_elem_add(struct snd_ctl_file *file,
                if (info->count > 64)
                        return -EINVAL;
                break;
+       case SNDRV_CTL_ELEM_TYPE_ENUMERATED:
+               private_size = sizeof(unsigned int);
+               if (info->count > 128 || info->value.enumerated.items == 0)
+                       return -EINVAL;
+               break;
        case SNDRV_CTL_ELEM_TYPE_BYTES:
                private_size = sizeof(unsigned char);
                if (info->count > 512)
@@ -1143,9 +1207,17 @@ static int snd_ctl_elem_add(struct snd_ctl_file *file,
        ue->info.access = 0;
        ue->elem_data = (char *)ue + sizeof(*ue);
        ue->elem_data_size = private_size;
+       if (ue->info.type == SNDRV_CTL_ELEM_TYPE_ENUMERATED) {
+               err = snd_ctl_elem_init_enum_names(ue);
+               if (err < 0) {
+                       kfree(ue);
+                       return err;
+               }
+       }
        kctl.private_free = snd_ctl_elem_user_free;
        _kctl = snd_ctl_new(&kctl, access);
        if (_kctl == NULL) {
+               kfree(ue->priv_data);
                kfree(ue);
                return -ENOMEM;
        }
index 426874429a5e088cf50414f6ab1f76dd7f8d1fd2..2bb95a7a8809fed3a042e8796b5431ce2afbee46 100644 (file)
@@ -83,6 +83,8 @@ struct snd_ctl_elem_info32 {
                        u32 items;
                        u32 item;
                        char name[64];
+                       u64 names_ptr;
+                       u32 names_length;
                } enumerated;
                unsigned char reserved[128];
        } value;
@@ -372,6 +374,8 @@ static int snd_ctl_elem_add_compat(struct snd_ctl_file *file,
                                   &data32->value.enumerated,
                                   sizeof(data->value.enumerated)))
                        goto error;
+               data->value.enumerated.names_ptr =
+                       (uintptr_t)compat_ptr(data->value.enumerated.names_ptr);
                break;
        default:
                break;
index 53b53e97c8960e4415b7c45801d5368cb611690c..240a3e13470dfe3e718dd9fdc22fdadf8900b763 100644 (file)
@@ -30,6 +30,7 @@ static int jack_switch_types[] = {
        SW_LINEOUT_INSERT,
        SW_JACK_PHYSICAL_INSERT,
        SW_VIDEOOUT_INSERT,
+       SW_LINEIN_INSERT,
 };
 
 static int snd_jack_dev_free(struct snd_device *device)
index d8359cfeca15a43484eb3bdc710123bfefe234a2..1b5e0c49a0addeb2698df665961773893690ced2 100644 (file)
@@ -499,7 +499,7 @@ static struct snd_kcontrol *snd_mixer_oss_test_id(struct snd_mixer_oss *mixer, c
        
        memset(&id, 0, sizeof(id));
        id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
-       strcpy(id.name, name);
+       strlcpy(id.name, name, sizeof(id.name));
        id.index = index;
        return snd_ctl_find_id(card, &id);
 }
index 62e90b862a0ddd2a1b7a0c49d34e76686a13b869..95d1e789715f13b0ae9185dc213da64728d43c76 100644 (file)
@@ -1399,6 +1399,32 @@ int snd_pcm_hw_constraint_pow2(struct snd_pcm_runtime *runtime,
 
 EXPORT_SYMBOL(snd_pcm_hw_constraint_pow2);
 
+static int snd_pcm_hw_rule_noresample_func(struct snd_pcm_hw_params *params,
+                                          struct snd_pcm_hw_rule *rule)
+{
+       unsigned int base_rate = (unsigned int)(uintptr_t)rule->private;
+       struct snd_interval *rate;
+
+       rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
+       return snd_interval_list(rate, 1, &base_rate, 0);
+}
+
+/**
+ * snd_pcm_hw_rule_noresample - add a rule to allow disabling hw resampling
+ * @runtime: PCM runtime instance
+ * @base_rate: the rate at which the hardware does not resample
+ */
+int snd_pcm_hw_rule_noresample(struct snd_pcm_runtime *runtime,
+                              unsigned int base_rate)
+{
+       return snd_pcm_hw_rule_add(runtime, SNDRV_PCM_HW_PARAMS_NORESAMPLE,
+                                  SNDRV_PCM_HW_PARAM_RATE,
+                                  snd_pcm_hw_rule_noresample_func,
+                                  (void *)(uintptr_t)base_rate,
+                                  SNDRV_PCM_HW_PARAM_RATE, -1);
+}
+EXPORT_SYMBOL(snd_pcm_hw_rule_noresample);
+
 static void _snd_pcm_hw_param_any(struct snd_pcm_hw_params *params,
                                  snd_pcm_hw_param_t var)
 {
index c74e228731ed8ffb36788f5443581dbd0d4fdae2..d7d2179c03636a4bae1bb513387001d932ea660a 100644 (file)
@@ -2058,16 +2058,12 @@ EXPORT_SYMBOL(snd_pcm_open_substream);
 
 static int snd_pcm_open_file(struct file *file,
                             struct snd_pcm *pcm,
-                            int stream,
-                            struct snd_pcm_file **rpcm_file)
+                            int stream)
 {
        struct snd_pcm_file *pcm_file;
        struct snd_pcm_substream *substream;
        int err;
 
-       if (rpcm_file)
-               *rpcm_file = NULL;
-
        err = snd_pcm_open_substream(pcm, stream, file, &substream);
        if (err < 0)
                return err;
@@ -2083,8 +2079,7 @@ static int snd_pcm_open_file(struct file *file,
                substream->pcm_release = pcm_release_private;
        }
        file->private_data = pcm_file;
-       if (rpcm_file)
-               *rpcm_file = pcm_file;
+
        return 0;
 }
 
@@ -2113,7 +2108,6 @@ static int snd_pcm_capture_open(struct inode *inode, struct file *file)
 static int snd_pcm_open(struct file *file, struct snd_pcm *pcm, int stream)
 {
        int err;
-       struct snd_pcm_file *pcm_file;
        wait_queue_t wait;
 
        if (pcm == NULL) {
@@ -2131,7 +2125,7 @@ static int snd_pcm_open(struct file *file, struct snd_pcm *pcm, int stream)
        add_wait_queue(&pcm->open_wait, &wait);
        mutex_lock(&pcm->open_mutex);
        while (1) {
-               err = snd_pcm_open_file(file, pcm, stream, &pcm_file);
+               err = snd_pcm_open_file(file, pcm, stream);
                if (err >= 0)
                        break;
                if (err == -EAGAIN) {
@@ -3156,8 +3150,8 @@ static const struct vm_operations_struct snd_pcm_vm_ops_data_fault = {
 /*
  * mmap the DMA buffer on RAM
  */
-static int snd_pcm_default_mmap(struct snd_pcm_substream *substream,
-                               struct vm_area_struct *area)
+int snd_pcm_lib_default_mmap(struct snd_pcm_substream *substream,
+                            struct vm_area_struct *area)
 {
        area->vm_flags |= VM_RESERVED;
 #ifdef ARCH_HAS_DMA_MMAP_COHERENT
@@ -3177,6 +3171,7 @@ static int snd_pcm_default_mmap(struct snd_pcm_substream *substream,
        area->vm_ops = &snd_pcm_vm_ops_data_fault;
        return 0;
 }
+EXPORT_SYMBOL_GPL(snd_pcm_lib_default_mmap);
 
 /*
  * mmap the DMA buffer on I/O memory area
@@ -3242,7 +3237,7 @@ int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file,
        if (substream->ops->mmap)
                err = substream->ops->mmap(substream, area);
        else
-               err = snd_pcm_default_mmap(substream, area);
+               err = snd_pcm_lib_default_mmap(substream, area);
        if (!err)
                atomic_inc(&substream->mmap_count);
        return err;
index a0da7755fceaad0236c5ef013164df8770e1a5df..4067f1548949b83eb37d0d564e4b1f7a724217a1 100644 (file)
@@ -575,7 +575,8 @@ static void loopback_runtime_free(struct snd_pcm_runtime *runtime)
 static int loopback_hw_params(struct snd_pcm_substream *substream,
                              struct snd_pcm_hw_params *params)
 {
-       return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
+       return snd_pcm_lib_alloc_vmalloc_buffer(substream,
+                                               params_buffer_bytes(params));
 }
 
 static int loopback_hw_free(struct snd_pcm_substream *substream)
@@ -587,7 +588,7 @@ static int loopback_hw_free(struct snd_pcm_substream *substream)
        mutex_lock(&dpcm->loopback->cable_lock);
        cable->valid &= ~(1 << substream->stream);
        mutex_unlock(&dpcm->loopback->cable_lock);
-       return snd_pcm_lib_free_pages(substream);
+       return snd_pcm_lib_free_vmalloc_buffer(substream);
 }
 
 static unsigned int get_cable_index(struct snd_pcm_substream *substream)
@@ -740,6 +741,8 @@ static struct snd_pcm_ops loopback_playback_ops = {
        .prepare =      loopback_prepare,
        .trigger =      loopback_trigger,
        .pointer =      loopback_pointer,
+       .page =         snd_pcm_lib_get_vmalloc_page,
+       .mmap =         snd_pcm_lib_mmap_vmalloc,
 };
 
 static struct snd_pcm_ops loopback_capture_ops = {
@@ -751,6 +754,8 @@ static struct snd_pcm_ops loopback_capture_ops = {
        .prepare =      loopback_prepare,
        .trigger =      loopback_trigger,
        .pointer =      loopback_pointer,
+       .page =         snd_pcm_lib_get_vmalloc_page,
+       .mmap =         snd_pcm_lib_mmap_vmalloc,
 };
 
 static int __devinit loopback_pcm_new(struct loopback *loopback,
@@ -771,10 +776,6 @@ static int __devinit loopback_pcm_new(struct loopback *loopback,
        strcpy(pcm->name, "Loopback PCM");
 
        loopback->pcm[device] = pcm;
-
-       snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
-                       snd_dma_continuous_data(GFP_KERNEL),
-                       0, 2 * 1024 * 1024);
        return 0;
 }
 
index 5cfcb908c43061d11f0a9e219c9dc8738e07343f..2c7a7636f47296d67a281c9a0e21c7e04e203799 100644 (file)
@@ -1153,7 +1153,7 @@ snd_ml403_ac97cr_create(struct snd_card *card, struct platform_device *pfdev,
                   "0x%x done\n", (unsigned int)ml403_ac97cr->port);
        /* get irq */
        irq = platform_get_irq(pfdev, 0);
-       if (request_irq(irq, snd_ml403_ac97cr_irq, IRQF_DISABLED,
+       if (request_irq(irq, snd_ml403_ac97cr_irq, 0,
                        dev_name(&pfdev->dev), (void *)ml403_ac97cr)) {
                snd_printk(KERN_ERR SND_ML403_AC97CR_DRIVER ": "
                           "unable to grab IRQ %d\n",
@@ -1166,7 +1166,7 @@ snd_ml403_ac97cr_create(struct snd_card *card, struct platform_device *pfdev,
                   "request (playback) irq %d done\n",
                   ml403_ac97cr->irq);
        irq = platform_get_irq(pfdev, 1);
-       if (request_irq(irq, snd_ml403_ac97cr_irq, IRQF_DISABLED,
+       if (request_irq(irq, snd_ml403_ac97cr_irq, 0,
                        dev_name(&pfdev->dev), (void *)ml403_ac97cr)) {
                snd_printk(KERN_ERR SND_ML403_AC97CR_DRIVER ": "
                           "unable to grab IRQ %d\n",
index 149d05a8202d58bf381c3eb059e3302f89e2a188..1c02852aceea771f82f9d4a9b424c86bc8e93f83 100644 (file)
@@ -86,8 +86,7 @@ static int snd_mpu401_create(int dev, struct snd_card **rcard)
        }
 
        err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, port[dev], 0,
-                                 irq[dev], irq[dev] >= 0 ? IRQF_DISABLED : 0,
-                                 NULL);
+                                 irq[dev], NULL);
        if (err < 0) {
                printk(KERN_ERR "MPU401 not detected at 0x%lx\n", port[dev]);
                goto _err;
index 2af09996a3d01a39d4b913a23c1d08855ed54f06..e91698a634b2ca21d64f35df0831df7d72a0070d 100644 (file)
@@ -3,7 +3,7 @@
  *  Routines for control of MPU-401 in UART mode
  *
  *  MPU-401 supports UART mode which is not capable generate transmit
- *  interrupts thus output is done via polling. Also, if irq < 0, then
+ *  interrupts thus output is done via polling. Without interrupt,
  *  input is done also via polling. Do not expect good performance.
  *
  *
@@ -374,7 +374,7 @@ snd_mpu401_uart_input_trigger(struct snd_rawmidi_substream *substream, int up)
                        /* first time - flush FIFO */
                        while (max-- > 0)
                                mpu->read(mpu, MPU401D(mpu));
-                       if (mpu->irq < 0)
+                       if (mpu->info_flags & MPU401_INFO_USE_TIMER)
                                snd_mpu401_uart_add_timer(mpu, 1);
                }
                
@@ -383,7 +383,7 @@ snd_mpu401_uart_input_trigger(struct snd_rawmidi_substream *substream, int up)
                snd_mpu401_uart_input_read(mpu);
                spin_unlock_irqrestore(&mpu->input_lock, flags);
        } else {
-               if (mpu->irq < 0)
+               if (mpu->info_flags & MPU401_INFO_USE_TIMER)
                        snd_mpu401_uart_remove_timer(mpu, 1);
                clear_bit(MPU401_MODE_BIT_INPUT_TRIGGER, &mpu->mode);
        }
@@ -496,7 +496,7 @@ static struct snd_rawmidi_ops snd_mpu401_uart_input =
 static void snd_mpu401_uart_free(struct snd_rawmidi *rmidi)
 {
        struct snd_mpu401 *mpu = rmidi->private_data;
-       if (mpu->irq_flags && mpu->irq >= 0)
+       if (mpu->irq >= 0)
                free_irq(mpu->irq, (void *) mpu);
        release_and_free_resource(mpu->res);
        kfree(mpu);
@@ -509,8 +509,7 @@ static void snd_mpu401_uart_free(struct snd_rawmidi *rmidi)
  * @hardware: the hardware type, MPU401_HW_XXXX
  * @port: the base address of MPU401 port
  * @info_flags: bitflags MPU401_INFO_XXX
- * @irq: the irq number, -1 if no interrupt for mpu
- * @irq_flags: the irq request flags (SA_XXX), 0 if irq was already reserved.
+ * @irq: the ISA irq number, -1 if not to be allocated
  * @rrawmidi: the pointer to store the new rawmidi instance
  *
  * Creates a new MPU-401 instance.
@@ -525,7 +524,7 @@ int snd_mpu401_uart_new(struct snd_card *card, int device,
                        unsigned short hardware,
                        unsigned long port,
                        unsigned int info_flags,
-                       int irq, int irq_flags,
+                       int irq,
                        struct snd_rawmidi ** rrawmidi)
 {
        struct snd_mpu401 *mpu;
@@ -577,8 +576,8 @@ int snd_mpu401_uart_new(struct snd_card *card, int device,
                mpu->cport = port + 2;
        else
                mpu->cport = port + 1;
-       if (irq >= 0 && irq_flags) {
-               if (request_irq(irq, snd_mpu401_uart_interrupt, irq_flags,
+       if (irq >= 0) {
+               if (request_irq(irq, snd_mpu401_uart_interrupt, 0,
                                "MPU401 UART", (void *) mpu)) {
                        snd_printk(KERN_ERR "mpu401_uart: "
                                   "unable to grab IRQ %d\n", irq);
@@ -586,9 +585,10 @@ int snd_mpu401_uart_new(struct snd_card *card, int device,
                        return -EBUSY;
                }
        }
+       if (irq < 0 && !(info_flags & MPU401_INFO_IRQ_HOOK))
+               info_flags |= MPU401_INFO_USE_TIMER;
        mpu->info_flags = info_flags;
        mpu->irq = irq;
-       mpu->irq_flags = irq_flags;
        if (card->shortname[0])
                snprintf(rmidi->name, sizeof(rmidi->name), "%s MIDI",
                         card->shortname);
index 5c426df8767878e299c930f22863df1f9a710bc6..1eef4ccebe4b8b8afbf5d71084a51ac78400b0c7 100644 (file)
@@ -589,7 +589,7 @@ static int __devinit snd_mtpav_get_ISA(struct mtpav * mcard)
                return -EBUSY;
        }
        mcard->port = port;
-       if (request_irq(irq, snd_mtpav_irqh, IRQF_DISABLED, "MOTU MTPAV", mcard)) {
+       if (request_irq(irq, snd_mtpav_irqh, 0, "MOTU MTPAV", mcard)) {
                snd_printk(KERN_ERR "MTVAP IRQ %d busy\n", irq);
                return -EBUSY;
        }
index a25fb7b1f4414c883a4a0e071f26099f389085b1..fc1d822802c360b5a072ac88ea23bf3658ef32fd 100644 (file)
@@ -816,7 +816,7 @@ static int __devinit snd_uart16550_create(struct snd_card *card,
 
        if (irq >= 0 && irq != SNDRV_AUTO_IRQ) {
                if (request_irq(irq, snd_uart16550_interrupt,
-                               IRQF_DISABLED, "Serial MIDI", uart)) {
+                               0, "Serial MIDI", uart)) {
                        snd_printk(KERN_WARNING
                                   "irq %d busy. Using Polling.\n", irq);
                } else {
index 14cacbc655dd790261db8962090c075d7a993a70..76294f2ae47f142fe128da90d5243a7ce2eac589 100644 (file)
@@ -32,7 +32,7 @@ enum bus_reset_handling {
        SUCCEED_ON_BUS_RESET,
 };
 
-static __attribute__((format(printf, 2, 3)))
+static __printf(2, 3)
 void cmp_error(struct cmp_connection *c, const char *fmt, ...)
 {
        va_list va;
index 440030818db70c88c582d0047790baed074297c9..cd094ecaca3befb440ad1dea44b279fdfbca7930 100644 (file)
@@ -51,7 +51,6 @@ struct isight {
        struct fw_unit *unit;
        struct fw_device *device;
        u64 audio_base;
-       struct fw_address_handler iris_handler;
        struct snd_pcm_substream *pcm;
        struct mutex mutex;
        struct iso_packets_buffer buffer;
index 3fc257da180ce0076d6af792046d1c64cfb584cb..cbe6bb9e53b6fa2a268580da649f78885ca31863 100644 (file)
@@ -778,9 +778,10 @@ static int __devexit fwspk_remove(struct device *dev)
 {
        struct fwspk *fwspk = dev_get_drvdata(dev);
 
-       mutex_lock(&fwspk->mutex);
        amdtp_out_stream_pcm_abort(&fwspk->stream);
        snd_card_disconnect(fwspk->card);
+
+       mutex_lock(&fwspk->mutex);
        fwspk_stop_stream(fwspk);
        mutex_unlock(&fwspk->mutex);
 
@@ -796,8 +797,8 @@ static void fwspk_bus_reset(struct fw_unit *unit)
        fcp_bus_reset(fwspk->unit);
 
        if (cmp_connection_update(&fwspk->connection) < 0) {
-               mutex_lock(&fwspk->mutex);
                amdtp_out_stream_pcm_abort(&fwspk->stream);
+               mutex_lock(&fwspk->mutex);
                fwspk_stop_stream(fwspk);
                mutex_unlock(&fwspk->mutex);
                return;
index 3cb75bc9769927a303974783c7667b728eed798b..a87a2b566e19e4fbce67cb0a90aa88c5e53c1968 100644 (file)
@@ -204,7 +204,7 @@ static int __devinit snd_card_ad1816a_probe(int dev, struct pnp_card_link *pcard
 
        if (mpu_port[dev] > 0) {
                if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
-                                       mpu_port[dev], 0, mpu_irq[dev], IRQF_DISABLED,
+                                       mpu_port[dev], 0, mpu_irq[dev],
                                        NULL) < 0)
                        printk(KERN_ERR PFX "no MPU-401 device at 0x%lx.\n", mpu_port[dev]);
        }
index 05aef8b97e968e1e2d9678a805ac04d2df4eb481..177eed3271bc4215683ffe58f6650d87af58e376 100644 (file)
@@ -595,7 +595,7 @@ int __devinit snd_ad1816a_create(struct snd_card *card,
                snd_ad1816a_free(chip);
                return -EBUSY;
        }
-       if (request_irq(irq, snd_ad1816a_interrupt, IRQF_DISABLED, "AD1816A", (void *) chip)) {
+       if (request_irq(irq, snd_ad1816a_interrupt, 0, "AD1816A", (void *) chip)) {
                snd_printk(KERN_ERR "ad1816a: can't grab IRQ %d\n", irq);
                snd_ad1816a_free(chip);
                return -EBUSY;
index 20becc89f6f6f45ab35a456591add0b93f89f038..706effd6b3cd8d800c43bc001e7a37ae16894c80 100644 (file)
@@ -256,7 +256,6 @@ static int __devinit snd_card_als100_probe(int dev,
                                        mpu_type,
                                        mpu_port[dev], 0, 
                                        mpu_irq[dev],
-                                       mpu_irq[dev] >= 0 ? IRQF_DISABLED : 0,
                                        NULL) < 0)
                        snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n", mpu_port[dev]);
        }
index aac8dc15c2fe6eaf0329b780545068789d38ce6c..b7bdbf30774025e3bbc61ef0a01852a68530bf49 100644 (file)
@@ -234,8 +234,7 @@ static int __devinit snd_card_azt2320_probe(int dev,
        if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
                if (snd_mpu401_uart_new(card, 0, MPU401_HW_AZT2320,
                                mpu_port[dev], 0,
-                               mpu_irq[dev], IRQF_DISABLED,
-                               NULL) < 0)
+                               mpu_irq[dev], NULL) < 0)
                        snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n", mpu_port[dev]);
        }
 
index fe79a169acb52e794e9e33b74c5851b84659da70..dca69f80305fb8f4ecdd4ec47014dd6de093c61d 100644 (file)
@@ -597,7 +597,7 @@ static int __devinit snd_cmi8330_probe(struct snd_card *card, int dev)
        if (mpuport[dev] != SNDRV_AUTO_PORT) {
                if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
                                        mpuport[dev], 0, mpuirq[dev],
-                                       IRQF_DISABLED, NULL) < 0)
+                                       NULL) < 0)
                        printk(KERN_ERR PFX "no MPU-401 device at 0x%lx.\n",
                                mpuport[dev]);
        }
index cb9153e75b8228ab75851b42d74900dae4c263e8..409fa0ad7843b17f518b7b75678fed01f794f242 100644 (file)
@@ -131,7 +131,6 @@ static int __devinit snd_cs4231_probe(struct device *dev, unsigned int n)
                        mpu_irq[n] = -1;
                if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232,
                                        mpu_port[n], 0, mpu_irq[n],
-                                       mpu_irq[n] >= 0 ? IRQF_DISABLED : 0,
                                        NULL) < 0)
                        dev_warn(dev, "MPU401 not detected\n");
        }
index 999dc1e0fdbd5fb95546ef0403a85b5715162c05..0dbde461e6c1b0050f3884fa76b6f654076fbdb0 100644 (file)
@@ -449,8 +449,7 @@ static int __devinit snd_cs423x_probe(struct snd_card *card, int dev)
                        mpu_irq[dev] = -1;
                if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232,
                                        mpu_port[dev], 0,
-                                       mpu_irq[dev],
-                                       mpu_irq[dev] >= 0 ? IRQF_DISABLED : 0, NULL) < 0)
+                                       mpu_irq[dev], NULL) < 0)
                        printk(KERN_WARNING IDENT ": MPU401 not detected\n");
        }
 
index 0cde8131a57544b3c4b7dd6ad745f1b6d0383038..5493e9e4bcd5dc1ed38b327bdfb2668d4cd5f444 100644 (file)
@@ -174,7 +174,7 @@ static int __devinit snd_es1688_probe(struct snd_card *card, unsigned int n)
                        chip->mpu_port > 0) {
                error = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688,
                                chip->mpu_port, 0,
-                               mpu_irq[n], IRQF_DISABLED, NULL);
+                               mpu_irq[n], NULL);
                if (error < 0)
                        return error;
        }
index 07676200496ae607313354d886378b4f549af4e4..d3eab6fb08660d6fe60671d03e7cc754e1acfc64 100644 (file)
@@ -661,7 +661,7 @@ int snd_es1688_create(struct snd_card *card,
                snd_printk(KERN_ERR "es1688: can't grab port 0x%lx\n", port + 4);
                return -EBUSY;
        }
-       if (request_irq(irq, snd_es1688_interrupt, IRQF_DISABLED, "ES1688", (void *) chip)) {
+       if (request_irq(irq, snd_es1688_interrupt, 0, "ES1688", (void *) chip)) {
                snd_printk(KERN_ERR "es1688: can't grab IRQ %d\n", irq);
                return -EBUSY;
        }
index fb4d6b34bbca5c3e9dce8caeb7c885efd3f6e256..bf6ad0bf51c63107e3489fcf8dece22937857edc 100644 (file)
@@ -1805,7 +1805,7 @@ static int __devinit snd_es18xx_new_device(struct snd_card *card,
                return -EBUSY;
        }
 
-       if (request_irq(irq, snd_es18xx_interrupt, IRQF_DISABLED, "ES18xx",
+       if (request_irq(irq, snd_es18xx_interrupt, 0, "ES18xx",
                        (void *) card)) {
                snd_es18xx_free(card);
                snd_printk(KERN_ERR PFX "unable to grap IRQ %d\n", irq);
@@ -2160,8 +2160,8 @@ static int __devinit snd_audiodrive_probe(struct snd_card *card, int dev)
 
        if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
                err = snd_mpu401_uart_new(card, 0, MPU401_HW_ES18XX,
-                                         mpu_port[dev], 0,
-                                         irq[dev], 0, &chip->rmidi);
+                                         mpu_port[dev], MPU401_INFO_IRQ_HOOK,
+                                         -1, &chip->rmidi);
                if (err < 0)
                        return err;
        }
index ee54df082b9c079b667ff192737f1dd30b32818a..e51d3244742af23dc673496dd822f20e7d5cfa73 100644 (file)
@@ -585,8 +585,7 @@ static int __devinit snd_galaxy_probe(struct device *dev, unsigned int n)
 
        if (mpu_port[n] >= 0) {
                err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
-                                         mpu_port[n], 0, mpu_irq[n],
-                                         IRQF_DISABLED, NULL);
+                                         mpu_port[n], 0, mpu_irq[n], NULL);
                if (err < 0)
                        goto error;
        }
index 12eb98f2f931e123c583419134064c1fb7004e33..3167e5ac3699bd72905ea38e83f93cc7a9ee3230 100644 (file)
@@ -180,7 +180,7 @@ int snd_gus_create(struct snd_card *card,
                snd_gus_free(gus);
                return -EBUSY;
        }
-       if (irq >= 0 && request_irq(irq, snd_gus_interrupt, IRQF_DISABLED, "GUS GF1", (void *) gus)) {
+       if (irq >= 0 && request_irq(irq, snd_gus_interrupt, 0, "GUS GF1", (void *) gus)) {
                snd_printk(KERN_ERR "gus: can't grab irq %d\n", irq);
                snd_gus_free(gus);
                return -EBUSY;
index 008e8e5bfa37ae76e235d1c8b873b5c1f4e3ff4a..c4733c08b60b2d7c3b17e6f2d701ab0355591b89 100644 (file)
@@ -317,8 +317,7 @@ static int __devinit snd_gusextreme_probe(struct device *dev, unsigned int n)
 
        if (es1688->mpu_port >= 0x300) {
                error = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688,
-                               es1688->mpu_port, 0,
-                               mpu_irq[n], IRQF_DISABLED, NULL);
+                               es1688->mpu_port, 0, mpu_irq[n], NULL);
                if (error < 0)
                        goto out;
        }
index 3e4a58b72913d613e719a9ccc912d0bf75661a0d..c43faa057ff6247219ac37b2ffa0daeba1a2a231 100644 (file)
@@ -291,7 +291,7 @@ static int __devinit snd_gusmax_probe(struct device *pdev, unsigned int dev)
                goto _err;
        }
 
-       if (request_irq(xirq, snd_gusmax_interrupt, IRQF_DISABLED, "GUS MAX", (void *)maxcard)) {
+       if (request_irq(xirq, snd_gusmax_interrupt, 0, "GUS MAX", (void *)maxcard)) {
                snd_printk(KERN_ERR PFX "unable to grab IRQ %d\n", xirq);
                err = -EBUSY;
                goto _err;
index c7b80e4730fc280f7b3a24698bba5b1b59e503a2..5f869a32b48ce9427b2eedffc1b7de2d3b45efd8 100644 (file)
@@ -684,7 +684,7 @@ static int __devinit snd_interwave_probe(struct snd_card *card, int dev)
        if ((err = snd_gus_initialize(gus)) < 0)
                return err;
 
-       if (request_irq(xirq, snd_interwave_interrupt, IRQF_DISABLED,
+       if (request_irq(xirq, snd_interwave_interrupt, 0,
                        "InterWave", iwcard)) {
                snd_printk(KERN_ERR PFX "unable to grab IRQ %d\n", xirq);
                return -EBUSY;
index 91d6023a63e57c6b14227e158c171b8edf4b8087..0961e2cf20caa8c0697f4775e0621ad0540af242 100644 (file)
@@ -600,7 +600,7 @@ static int __devinit snd_msnd_attach(struct snd_card *card)
                                          mpu_io[0],
                                          MPU401_MODE_INPUT |
                                          MPU401_MODE_OUTPUT,
-                                         mpu_irq[0], IRQF_DISABLED,
+                                         mpu_irq[0],
                                          &chip->rmidi);
                if (err < 0) {
                        printk(KERN_ERR LOGNAME
index 9b915e27b5bd7d422e3b9defd39b3c921795e5cf..bbafb0b543eadebadae7b18b512d94a98aa8875a 100644 (file)
@@ -667,7 +667,7 @@ static int __devinit snd_opl3sa2_probe(struct snd_card *card, int dev)
        err = snd_opl3sa2_detect(card);
        if (err < 0)
                return err;
-       err = request_irq(xirq, snd_opl3sa2_interrupt, IRQF_DISABLED,
+       err = request_irq(xirq, snd_opl3sa2_interrupt, 0,
                          "OPL3-SA2", card);
        if (err) {
                snd_printk(KERN_ERR PFX "can't grab IRQ %d\n", xirq);
@@ -707,8 +707,9 @@ static int __devinit snd_opl3sa2_probe(struct snd_card *card, int dev)
        }
        if (midi_port[dev] >= 0x300 && midi_port[dev] < 0x340) {
                if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_OPL3SA2,
-                                              midi_port[dev], 0,
-                                              xirq, 0, &chip->rmidi)) < 0)
+                                              midi_port[dev],
+                                              MPU401_INFO_IRQ_HOOK, -1,
+                                              &chip->rmidi)) < 0)
                        return err;
        }
        sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
index 8c24102d0d9389aeca007de307f38fe836e38b53..d94d0f35cb765c92ff503f2d9547ee4a6020a45e 100644 (file)
@@ -1377,8 +1377,7 @@ static int __devinit snd_miro_probe(struct snd_card *card)
                rmidi = NULL;
        else {
                error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
-                               mpu_port, 0, miro->mpu_irq, IRQF_DISABLED,
-                               &rmidi);
+                               mpu_port, 0, miro->mpu_irq, &rmidi);
                if (error < 0)
                        snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n",
                                   mpu_port);
index c35dc68930dc52ddd3ca0990aa2870995f84e753..6dbbfa76b440a4cf47f79f31430084dcc2830f73 100644 (file)
@@ -892,7 +892,7 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card)
 #endif
 #ifdef OPTi93X
        error = request_irq(irq, snd_opti93x_interrupt,
-                           IRQF_DISABLED, DEV_NAME" - WSS", chip);
+                           0, DEV_NAME" - WSS", chip);
        if (error < 0) {
                snd_printk(KERN_ERR "opti9xx: can't grab IRQ %d\n", irq);
                return error;
@@ -914,7 +914,7 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card)
                rmidi = NULL;
        else {
                error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
-                               mpu_port, 0, mpu_irq, IRQF_DISABLED, &rmidi);
+                               mpu_port, 0, mpu_irq, &rmidi);
                if (error)
                        snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n",
                                   mpu_port);
index 8ccbcddf08e19d11b153684caba68eeb72da6fac..54e3c2c1806075689609c9ab9076e799504a24ee 100644 (file)
@@ -322,7 +322,6 @@ static int __devinit snd_jazz16_probe(struct device *devptr, unsigned int dev)
                                        MPU401_HW_MPU401,
                                        mpu_port[dev], 0,
                                        mpu_irq[dev],
-                                       mpu_irq[dev] >= 0 ? IRQF_DISABLED : 0,
                                        NULL) < 0)
                        snd_printk(KERN_ERR "no MPU-401 device at 0x%lx\n",
                                        mpu_port[dev]);
index 4d1c5a300ff84de4e75854dcfd17d2540ed4b453..237f8bd7fbe422f6676402e9632b278289f7b223 100644 (file)
@@ -394,8 +394,9 @@ static int __devinit snd_sb16_probe(struct snd_card *card, int dev)
 
        if (chip->mpu_port > 0 && chip->mpu_port != SNDRV_AUTO_PORT) {
                if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_SB,
-                                              chip->mpu_port, 0,
-                                              xirq, 0, &chip->rmidi)) < 0)
+                                              chip->mpu_port,
+                                              MPU401_INFO_IRQ_HOOK, -1,
+                                              &chip->rmidi)) < 0)
                        return err;
                chip->rmidi_callback = snd_mpu401_uart_interrupt;
        }
index eae6c1c0eff9bc536d87f8fb3eb2b7abb578a7e1..d2e19215813e3f9de145f068108a7c75857547ad 100644 (file)
@@ -240,7 +240,7 @@ int snd_sbdsp_create(struct snd_card *card,
        if (request_irq(irq, irq_handler,
                        (hardware == SB_HW_ALS4000 ||
                         hardware == SB_HW_CS5530) ?
-                       IRQF_SHARED : IRQF_DISABLED,
+                       IRQF_SHARED : 0,
                        "SoundBlaster", (void *) chip)) {
                snd_printk(KERN_ERR "sb: can't grab irq %d\n", irq);
                snd_sbdsp_free(chip);
index 9a8bbf6dd62aeaecc1f51ee28d1b66db3d819f4c..207c161f100c5bd06f416fe5c11bfaa08757a2db 100644 (file)
@@ -658,8 +658,7 @@ static int __devinit snd_sc6000_probe(struct device *devptr, unsigned int dev)
                if (snd_mpu401_uart_new(card, 0,
                                        MPU401_HW_MPU401,
                                        mpu_port[dev], 0,
-                                       mpu_irq[dev], IRQF_DISABLED,
-                                       NULL) < 0)
+                                       mpu_irq[dev], NULL) < 0)
                        snd_printk(KERN_ERR "no MPU-401 device at 0x%lx ?\n",
                                        mpu_port[dev]);
        }
index e2d5d2d3ed96472c30a09c302e4a65442624d4f6..f2379e102b63e6a29503a3c1df24c4d96a3cd456 100644 (file)
@@ -825,8 +825,7 @@ static int __devinit create_mpu401(struct snd_card *card, int devnum,
        int err;
 
        err = snd_mpu401_uart_new(card, devnum, MPU401_HW_MPU401, port,
-                                 MPU401_INFO_INTEGRATED, irq, IRQF_DISABLED,
-                                 &rawmidi);
+                                 MPU401_INFO_INTEGRATED, irq, &rawmidi);
        if (err == 0) {
                struct snd_mpu401 *mpu = rawmidi->private_data;
                mpu->open_input = mpu401_open;
index 711670e4a4251e9cdc91a3b48350ec81a6c03a5c..87142977335a58051bac5e339a75d1a0fc9cfa76 100644 (file)
@@ -418,7 +418,7 @@ snd_wavefront_probe (struct snd_card *card, int dev)
                return -EBUSY;
        }
        if (request_irq(ics2115_irq[dev], snd_wavefront_ics2115_interrupt,
-                       IRQF_DISABLED, "ICS2115", acard)) {
+                       0, "ICS2115", acard)) {
                snd_printk(KERN_ERR "unable to use ICS2115 IRQ %d\n", ics2115_irq[dev]);
                return -EBUSY;
        }
@@ -449,8 +449,7 @@ snd_wavefront_probe (struct snd_card *card, int dev)
        if (cs4232_mpu_port[dev] > 0 && cs4232_mpu_port[dev] != SNDRV_AUTO_PORT) {
                err = snd_mpu401_uart_new(card, midi_dev, MPU401_HW_CS4232,
                                          cs4232_mpu_port[dev], 0,
-                                         cs4232_mpu_irq[dev], IRQF_DISABLED,
-                                         NULL);
+                                         cs4232_mpu_irq[dev], NULL);
                if (err < 0) {
                        snd_printk (KERN_ERR "can't allocate CS4232 MPU-401 device\n");
                        return err;
index 2a42cc37795721c63f48e1939bd5ad1948cd0ae9..7277c5b7df6cd750f3a39842aef8eec2157a8b14 100644 (file)
@@ -1833,7 +1833,7 @@ int snd_wss_create(struct snd_card *card,
        }
        chip->cport = cport;
        if (!(hwshare & WSS_HWSHARE_IRQ))
-               if (request_irq(irq, snd_wss_interrupt, IRQF_DISABLED,
+               if (request_irq(irq, snd_wss_interrupt, 0,
                                "WSS", (void *) chip)) {
                        snd_printk(KERN_ERR "wss: can't grab IRQ %d\n", irq);
                        snd_wss_free(chip);
index a9823fad85c2d9ecaf0bbc2bfd0ad13d3e254796..77dd0a13aecc40f59ac9361f241f376a61173934 100644 (file)
@@ -23,12 +23,15 @@ config SND_SGI_HAL2
 
 
 config SND_AU1X00
-       tristate "Au1x00 AC97 Port Driver"
+       tristate "Au1x00 AC97 Port Driver (DEPRECATED)"
        depends on SOC_AU1000 || SOC_AU1100 || SOC_AU1500
        select SND_PCM
        select SND_AC97_CODEC
        help
          ALSA Sound driver for the Au1x00's AC97 port.
 
+         Newer drivers for ASoC are available, please do not use
+         this driver as it will be removed in the future.
+
 endif  # SND_MIPS
 
index 446cf9748664dde623a5c0320a3746b9e2d8225b..7567ebd719139b4624a0924daa6a690a185eba75 100644 (file)
@@ -465,13 +465,13 @@ snd_au1000_pcm_new(struct snd_au1000 *au1000)
 
        flags = claim_dma_lock();
        if ((au1000->stream[PLAYBACK]->dma = request_au1000_dma(DMA_ID_AC97C_TX,
-                       "AC97 TX", au1000_dma_interrupt, IRQF_DISABLED,
+                       "AC97 TX", au1000_dma_interrupt, 0,
                        au1000->stream[PLAYBACK])) < 0) {
                release_dma_lock(flags);
                return -EBUSY;
        }
        if ((au1000->stream[CAPTURE]->dma = request_au1000_dma(DMA_ID_AC97C_RX,
-                       "AC97 RX", au1000_dma_interrupt, IRQF_DISABLED,
+                       "AC97 RX", au1000_dma_interrupt, 0,
                        au1000->stream[CAPTURE])) < 0){
                release_dma_lock(flags);
                return -EBUSY;
index 48cda6c4c257b34d191d3512ff52658de4329669..8021c85f076d09aa1c118473607e67219b04fc16 100644 (file)
@@ -320,7 +320,7 @@ void  sound_timer_init(struct sound_lowlev_timer *t, char *name)
        n = sound_alloc_timerdev();
        if (n == -1)
                n = 0;          /* Overwrite the system timer */
-       strcpy(sound_timer.info.name, name);
+       strlcpy(sound_timer.info.name, name, sizeof(sound_timer.info.name));
        sound_timer_devs[n] = &sound_timer;
 }
 EXPORT_SYMBOL(sound_timer_init);
index a9c1af33f276623931f826b91971a1a6a5937152..04628696eb082adadcef4b6d2b40c21d5195b304 100644 (file)
@@ -931,8 +931,9 @@ static int __devinit snd_card_als4000_probe(struct pci_dev *pci,
 
        if ((err = snd_mpu401_uart_new( card, 0, MPU401_HW_ALS4000,
                                        iobase + ALS4K_IOB_30_MIDI_DATA,
-                                       MPU401_INFO_INTEGRATED,
-                                       pci->irq, 0, &chip->rmidi)) < 0) {
+                                       MPU401_INFO_INTEGRATED |
+                                       MPU401_INFO_IRQ_HOOK,
+                                       -1, &chip->rmidi)) < 0) {
                printk(KERN_ERR "als4000: no MPU-401 device at 0x%lx?\n",
                                iobase + ALS4K_IOB_30_MIDI_DATA);
                goto out_err;
index 0dc8d259d1ed09a708ad8affe38a29dfead7a27f..e6c6a0febb752ab75c951a16dd08e1be01a2dd2a 100644 (file)
@@ -84,7 +84,7 @@ static int __devinit snd_vortex_midi(vortex_t * vortex)
 #ifdef VORTEX_MPU401_LEGACY
        if ((temp =
             snd_mpu401_uart_new(vortex->card, 0, MPU401_HW_MPU401, 0x330,
-                                0, 0, 0, &rmidi)) != 0) {
+                                MPU401_INFO_IRQ_HOOK, -1, &rmidi)) != 0) {
                hwwrite(vortex->mmio, VORTEX_CTRL,
                        (hwread(vortex->mmio, VORTEX_CTRL) &
                         ~CTRL_MIDI_PORT) & ~CTRL_MIDI_EN);
@@ -94,8 +94,8 @@ static int __devinit snd_vortex_midi(vortex_t * vortex)
        port = (unsigned long)(vortex->mmio + VORTEX_MIDI_DATA);
        if ((temp =
             snd_mpu401_uart_new(vortex->card, 0, MPU401_HW_AUREAL, port,
-                                MPU401_INFO_INTEGRATED | MPU401_INFO_MMIO,
-                                0, 0, &rmidi)) != 0) {
+                                MPU401_INFO_INTEGRATED | MPU401_INFO_MMIO |
+                                MPU401_INFO_IRQ_HOOK, -1, &rmidi)) != 0) {
                hwwrite(vortex->mmio, VORTEX_CTRL,
                        (hwread(vortex->mmio, VORTEX_CTRL) &
                         ~CTRL_MIDI_PORT) & ~CTRL_MIDI_EN);
index 579fc0dce12850e8e7cf604039def20abd54b025..d24fe425e87f4500c87059c56557a962ad1e8192 100644 (file)
@@ -2652,8 +2652,9 @@ snd_azf3328_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
           since our hardware ought to be similar, thus use same ID. */
        err = snd_mpu401_uart_new(
                card, 0,
-               MPU401_HW_AZT2320, chip->mpu_io, MPU401_INFO_INTEGRATED,
-               pci->irq, 0, &chip->rmidi
+               MPU401_HW_AZT2320, chip->mpu_io,
+               MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK,
+               -1, &chip->rmidi
        );
        if (err < 0) {
                snd_printk(KERN_ERR "azf3328: no MPU-401 device at 0x%lx?\n",
index 9cf99fb7eb9c5b872ab100615f24ff7ca4ce1c72..da9c73211eca7cabe78aee41bb0d5abc3584716f 100644 (file)
@@ -3228,8 +3228,9 @@ static int __devinit snd_cmipci_create(struct snd_card *card, struct pci_dev *pc
                if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_CMIPCI,
                                               iomidi,
                                               (integrated_midi ?
-                                               MPU401_INFO_INTEGRATED : 0),
-                                              cm->irq, 0, &cm->rmidi)) < 0) {
+                                               MPU401_INFO_INTEGRATED : 0) |
+                                              MPU401_INFO_IRQ_HOOK,
+                                              -1, &cm->rmidi)) < 0) {
                        printk(KERN_ERR "cmipci: no UART401 device at 0x%lx\n", iomidi);
                }
        }
index 457d21189b0db1fc5b2fcd2af22e30d20089dcb1..2c8622617c8c4cac7df6f01535cc97adc165c206 100644 (file)
@@ -404,7 +404,7 @@ int ct_alsa_pcm_create(struct ct_atc *atc,
        int err;
        int playback_count, capture_count;
 
-       playback_count = (IEC958 == device) ? 1 : 8;
+       playback_count = (IEC958 == device) ? 1 : 256;
        capture_count = (FRONT == device) ? 1 : 0;
        err = snd_pcm_new(atc->card, "ctxfi", device,
                          playback_count, capture_count, &pcm);
index c749fa72088996c75843927f7470997288a6e669..e134b3a5780da709d9ccbf3fce4c9f99f7f82fc5 100644 (file)
@@ -20,7 +20,7 @@
 #include "cthardware.h"
 #include <linux/slab.h>
 
-#define SRC_RESOURCE_NUM       64
+#define SRC_RESOURCE_NUM       256
 #define SRCIMP_RESOURCE_NUM    256
 
 static unsigned int conj_mask;
index b23adfca4de6eb90f0dbbf08fda38696df5cac61..e6da60eb19ceb76d64ce92fbcbd62f2bb144b6c3 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef CTVMEM_H
 #define CTVMEM_H
 
-#define CT_PTP_NUM     1       /* num of device page table pages */
+#define CT_PTP_NUM     4       /* num of device page table pages */
 
 #include <linux/mutex.h>
 #include <linux/list.h>
index 622bace148e3c4e5e4de3efa1936b56245004c69..e22b8e2bbd884099339b807045176ceb33ee37d9 100644 (file)
@@ -1146,6 +1146,11 @@ static int snd_emu10k1_playback_open(struct snd_pcm_substream *substream)
                kfree(epcm);
                return err;
        }
+       err = snd_pcm_hw_rule_noresample(runtime, 48000);
+       if (err < 0) {
+               kfree(epcm);
+               return err;
+       }
        mix = &emu->pcm_mixer[substream->number];
        for (i = 0; i < 4; i++)
                mix->send_routing[0][i] = mix->send_routing[1][i] = mix->send_routing[2][i] = i;
index 26a5a2f25d4bc890a6ff42c96580edfd4b5b70ec..718a2643474e5bbb8249b639be2d55d6b7218752 100644 (file)
@@ -1854,8 +1854,9 @@ static int __devinit snd_es1938_probe(struct pci_dev *pci,
                }
        }
        if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
-                               chip->mpu_port, MPU401_INFO_INTEGRATED,
-                               chip->irq, 0, &chip->rmidi) < 0) {
+                               chip->mpu_port,
+                               MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK,
+                               -1, &chip->rmidi) < 0) {
                printk(KERN_ERR "es1938: unable to initialize MPU-401\n");
        } else {
                // this line is vital for MIDI interrupt handling on ess-solo1
index 99ea9320c6b5592ac22ca11cdce0a9347ca37f37..407e4abc43568ee4e728f77b72ee39a645ebee23 100644 (file)
@@ -2843,8 +2843,9 @@ static int __devinit snd_es1968_probe(struct pci_dev *pci,
        if (enable_mpu[dev]) {
                if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
                                               chip->io_port + ESM_MPU401_PORT,
-                                              MPU401_INFO_INTEGRATED,
-                                              chip->irq, 0, &chip->rmidi)) < 0) {
+                                              MPU401_INFO_INTEGRATED |
+                                              MPU401_INFO_IRQ_HOOK,
+                                              -1, &chip->rmidi)) < 0) {
                        printk(KERN_WARNING "es1968: skipping MPU-401 MIDI support..\n");
                }
        }
index 32b02d906703c2d599dcdf4e30c4752b35388a77..136f7232bb7cf0cc568cfff17e89c2334486cde1 100644 (file)
@@ -729,11 +729,14 @@ static struct snd_fm801_tea575x_gpio snd_fm801_tea575x_gpios[] = {
        { .data = 2, .clk = 0, .wren = 1, .most = 3, .name = "SF64-PCR" },
 };
 
+#define get_tea575x_gpio(chip) \
+       (&snd_fm801_tea575x_gpios[((chip)->tea575x_tuner & TUNER_TYPE_MASK) - 1])
+
 static void snd_fm801_tea575x_set_pins(struct snd_tea575x *tea, u8 pins)
 {
        struct fm801 *chip = tea->private_data;
        unsigned short reg = inw(FM801_REG(chip, GPIO_CTRL));
-       struct snd_fm801_tea575x_gpio gpio = snd_fm801_tea575x_gpios[(chip->tea575x_tuner & TUNER_TYPE_MASK) - 1];
+       struct snd_fm801_tea575x_gpio gpio = *get_tea575x_gpio(chip);
 
        reg &= ~(FM801_GPIO_GP(gpio.data) |
                 FM801_GPIO_GP(gpio.clk) |
@@ -751,7 +754,7 @@ static u8 snd_fm801_tea575x_get_pins(struct snd_tea575x *tea)
 {
        struct fm801 *chip = tea->private_data;
        unsigned short reg = inw(FM801_REG(chip, GPIO_CTRL));
-       struct snd_fm801_tea575x_gpio gpio = snd_fm801_tea575x_gpios[(chip->tea575x_tuner & TUNER_TYPE_MASK) - 1];
+       struct snd_fm801_tea575x_gpio gpio = *get_tea575x_gpio(chip);
 
        return  (reg & FM801_GPIO_GP(gpio.data)) ? TEA575X_DATA : 0 |
                (reg & FM801_GPIO_GP(gpio.most)) ? TEA575X_MOST : 0;
@@ -761,7 +764,7 @@ static void snd_fm801_tea575x_set_direction(struct snd_tea575x *tea, bool output
 {
        struct fm801 *chip = tea->private_data;
        unsigned short reg = inw(FM801_REG(chip, GPIO_CTRL));
-       struct snd_fm801_tea575x_gpio gpio = snd_fm801_tea575x_gpios[(chip->tea575x_tuner & TUNER_TYPE_MASK) - 1];
+       struct snd_fm801_tea575x_gpio gpio = *get_tea575x_gpio(chip);
 
        /* use GPIO lines and set write enable bit */
        reg |= FM801_GPIO_GS(gpio.data) |
@@ -1246,7 +1249,7 @@ static int __devinit snd_fm801_create(struct snd_card *card,
                        chip->tea575x_tuner = tea575x_tuner;
                        if (!snd_tea575x_init(&chip->tea)) {
                                snd_printk(KERN_INFO "detected TEA575x radio type %s\n",
-                                       snd_fm801_tea575x_gpios[tea575x_tuner - 1].name);
+                                          get_tea575x_gpio(chip)->name);
                                break;
                        }
                }
@@ -1256,9 +1259,7 @@ static int __devinit snd_fm801_create(struct snd_card *card,
                }
        }
        if (!(chip->tea575x_tuner & TUNER_DISABLED)) {
-               strlcpy(chip->tea.card,
-                       snd_fm801_tea575x_gpios[(tea575x_tuner &
-                                                TUNER_TYPE_MASK) - 1].name,
+               strlcpy(chip->tea.card, get_tea575x_gpio(chip)->name,
                        sizeof(chip->tea.card));
        }
 #endif
@@ -1311,8 +1312,9 @@ static int __devinit snd_card_fm801_probe(struct pci_dev *pci,
        }
        if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_FM801,
                                       FM801_REG(chip, MPU401_DATA),
-                                      MPU401_INFO_INTEGRATED,
-                                      chip->irq, 0, &chip->rmidi)) < 0) {
+                                      MPU401_INFO_INTEGRATED |
+                                      MPU401_INFO_IRQ_HOOK,
+                                      -1, &chip->rmidi)) < 0) {
                snd_card_free(card);
                return err;
        }
index 87365d5ea2a9e6cb561667a453232917157ef97a..f928d663472322f00d0f7fdb835e6bf589bd65f7 100644 (file)
@@ -6,6 +6,9 @@ snd-hda-codec-$(CONFIG_PROC_FS) += hda_proc.o
 snd-hda-codec-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o
 snd-hda-codec-$(CONFIG_SND_HDA_INPUT_BEEP) += hda_beep.o
 
+# for trace-points
+CFLAGS_hda_codec.o := -I$(src)
+
 snd-hda-codec-realtek-objs :=  patch_realtek.o
 snd-hda-codec-cmedia-objs :=   patch_cmedia.o
 snd-hda-codec-analog-objs :=   patch_analog.o
index 21ec2cb100b06e9c289b69eecc3f3ff6ceb32ebe..3b5170b9700f03b0c49d47ef0842e17a1eef1dd7 100644 (file)
@@ -7,9 +7,6 @@
 enum {
        ALC260_AUTO,
        ALC260_BASIC,
-       ALC260_HP,
-       ALC260_HP_DC7600,
-       ALC260_HP_3013,
        ALC260_FUJITSU_S702X,
        ALC260_ACER,
        ALC260_WILL,
@@ -142,8 +139,6 @@ static const struct hda_channel_mode alc260_modes[1] = {
 /* Mixer combinations
  *
  * basic: base_output + input + pc_beep + capture
- * HP: base_output + input + capture_alt
- * HP_3013: hp_3013 + input + capture
  * fujitsu: fujitsu + capture
  * acer: acer + capture
  */
@@ -170,145 +165,6 @@ static const struct snd_kcontrol_new alc260_input_mixer[] = {
        { } /* end */
 };
 
-/* update HP, line and mono out pins according to the master switch */
-static void alc260_hp_master_update(struct hda_codec *codec)
-{
-       update_speakers(codec);
-}
-
-static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
-                                  struct snd_ctl_elem_value *ucontrol)
-{
-       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct alc_spec *spec = codec->spec;
-       *ucontrol->value.integer.value = !spec->master_mute;
-       return 0;
-}
-
-static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
-                                  struct snd_ctl_elem_value *ucontrol)
-{
-       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct alc_spec *spec = codec->spec;
-       int val = !*ucontrol->value.integer.value;
-
-       if (val == spec->master_mute)
-               return 0;
-       spec->master_mute = val;
-       alc260_hp_master_update(codec);
-       return 1;
-}
-
-static const struct snd_kcontrol_new alc260_hp_output_mixer[] = {
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "Master Playback Switch",
-               .subdevice = HDA_SUBDEV_NID_FLAG | 0x11,
-               .info = snd_ctl_boolean_mono_info,
-               .get = alc260_hp_master_sw_get,
-               .put = alc260_hp_master_sw_put,
-       },
-       HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
-       HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
-       HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
-       HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
-       HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
-                             HDA_OUTPUT),
-       HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
-       { } /* end */
-};
-
-static const struct hda_verb alc260_hp_unsol_verbs[] = {
-       {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
-       {},
-};
-
-static void alc260_hp_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-
-       spec->autocfg.hp_pins[0] = 0x0f;
-       spec->autocfg.speaker_pins[0] = 0x10;
-       spec->autocfg.speaker_pins[1] = 0x11;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_PIN;
-}
-
-static const struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "Master Playback Switch",
-               .subdevice = HDA_SUBDEV_NID_FLAG | 0x11,
-               .info = snd_ctl_boolean_mono_info,
-               .get = alc260_hp_master_sw_get,
-               .put = alc260_hp_master_sw_put,
-       },
-       HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
-       HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
-       HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
-       { } /* end */
-};
-
-static void alc260_hp_3013_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-
-       spec->autocfg.hp_pins[0] = 0x15;
-       spec->autocfg.speaker_pins[0] = 0x10;
-       spec->autocfg.speaker_pins[1] = 0x11;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_PIN;
-}
-
-static const struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
-       .ops = &snd_hda_bind_vol,
-       .values = {
-               HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
-               HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
-               HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
-               0
-       },
-};
-
-static const struct hda_bind_ctls alc260_dc7600_bind_switch = {
-       .ops = &snd_hda_bind_sw,
-       .values = {
-               HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
-               HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
-               0
-       },
-};
-
-static const struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
-       HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
-       HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
-       HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
-       { } /* end */
-};
-
-static const struct hda_verb alc260_hp_3013_unsol_verbs[] = {
-       {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
-       {},
-};
-
-static void alc260_hp_3012_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-
-       spec->autocfg.hp_pins[0] = 0x10;
-       spec->autocfg.speaker_pins[0] = 0x0f;
-       spec->autocfg.speaker_pins[1] = 0x11;
-       spec->autocfg.speaker_pins[2] = 0x15;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_PIN;
-}
-
 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
  */
@@ -480,106 +336,6 @@ static const struct hda_verb alc260_init_verbs[] = {
        { }
 };
 
-#if 0 /* should be identical with alc260_init_verbs? */
-static const struct hda_verb alc260_hp_init_verbs[] = {
-       /* Headphone and output */
-       {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
-       /* mono output */
-       {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
-       /* Mic1 (rear panel) pin widget for input and vref at 80% */
-       {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
-       /* Mic2 (front panel) pin widget for input and vref at 80% */
-       {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
-       /* Line In pin widget for input */
-       {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
-       /* Line-2 pin widget for output */
-       {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
-       /* CD pin widget for input */
-       {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
-       /* unmute amp left and right */
-       {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
-       /* set connection select to line in (default select for this ADC) */
-       {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
-       /* unmute Line-Out mixer amp left and right (volume = 0) */
-       {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
-       /* mute pin widget amp left and right (no gain on this amp) */
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
-       /* unmute HP mixer amp left and right (volume = 0) */
-       {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
-       /* mute pin widget amp left and right (no gain on this amp) */
-       {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
-       /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
-        * Line In 2 = 0x03
-        */
-       /* mute analog inputs */
-       {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
-       {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
-       {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
-       {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
-       {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
-       /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
-       /* Unmute Front out path */
-       {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
-       {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
-       /* Unmute Headphone out path */
-       {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
-       {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
-       /* Unmute Mono out path */
-       {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
-       {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
-       { }
-};
-#endif
-
-static const struct hda_verb alc260_hp_3013_init_verbs[] = {
-       /* Line out and output */
-       {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
-       /* mono output */
-       {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
-       /* Mic1 (rear panel) pin widget for input and vref at 80% */
-       {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
-       /* Mic2 (front panel) pin widget for input and vref at 80% */
-       {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
-       /* Line In pin widget for input */
-       {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
-       /* Headphone pin widget for output */
-       {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
-       /* CD pin widget for input */
-       {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
-       /* unmute amp left and right */
-       {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
-       /* set connection select to line in (default select for this ADC) */
-       {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
-       /* unmute Line-Out mixer amp left and right (volume = 0) */
-       {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
-       /* mute pin widget amp left and right (no gain on this amp) */
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
-       /* unmute HP mixer amp left and right (volume = 0) */
-       {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
-       /* mute pin widget amp left and right (no gain on this amp) */
-       {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
-       /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
-        * Line In 2 = 0x03
-        */
-       /* mute analog inputs */
-       {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
-       {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
-       {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
-       {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
-       {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
-       /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
-       /* Unmute Front out path */
-       {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
-       {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
-       /* Unmute Headphone out path */
-       {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
-       {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
-       /* Unmute Mono out path */
-       {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
-       {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
-       { }
-};
-
 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
  * audio = 0x16, internal speaker = 0x10.
@@ -1093,9 +849,6 @@ static const struct hda_verb alc260_test_init_verbs[] = {
  */
 static const char * const alc260_models[ALC260_MODEL_LAST] = {
        [ALC260_BASIC]          = "basic",
-       [ALC260_HP]             = "hp",
-       [ALC260_HP_3013]        = "hp-3013",
-       [ALC260_HP_DC7600]      = "hp-dc7600",
        [ALC260_FUJITSU_S702X]  = "fujitsu",
        [ALC260_ACER]           = "acer",
        [ALC260_WILL]           = "will",
@@ -1112,15 +865,6 @@ static const struct snd_pci_quirk alc260_cfg_tbl[] = {
        SND_PCI_QUIRK(0x1025, 0x007f, "Acer", ALC260_WILL),
        SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
        SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FAVORIT100),
-       SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
-       SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_AUTO), /* no quirk */
-       SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
-       SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
-       SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
-       SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
-       SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
-       SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
-       SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
        SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
        SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
        SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
@@ -1144,54 +888,6 @@ static const struct alc_config_preset alc260_presets[] = {
                .channel_mode = alc260_modes,
                .input_mux = &alc260_capture_source,
        },
-       [ALC260_HP] = {
-               .mixers = { alc260_hp_output_mixer,
-                           alc260_input_mixer },
-               .init_verbs = { alc260_init_verbs,
-                               alc260_hp_unsol_verbs },
-               .num_dacs = ARRAY_SIZE(alc260_dac_nids),
-               .dac_nids = alc260_dac_nids,
-               .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
-               .adc_nids = alc260_adc_nids_alt,
-               .num_channel_mode = ARRAY_SIZE(alc260_modes),
-               .channel_mode = alc260_modes,
-               .input_mux = &alc260_capture_source,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc260_hp_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC260_HP_DC7600] = {
-               .mixers = { alc260_hp_dc7600_mixer,
-                           alc260_input_mixer },
-               .init_verbs = { alc260_init_verbs,
-                               alc260_hp_dc7600_verbs },
-               .num_dacs = ARRAY_SIZE(alc260_dac_nids),
-               .dac_nids = alc260_dac_nids,
-               .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
-               .adc_nids = alc260_adc_nids_alt,
-               .num_channel_mode = ARRAY_SIZE(alc260_modes),
-               .channel_mode = alc260_modes,
-               .input_mux = &alc260_capture_source,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc260_hp_3012_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC260_HP_3013] = {
-               .mixers = { alc260_hp_3013_mixer,
-                           alc260_input_mixer },
-               .init_verbs = { alc260_hp_3013_init_verbs,
-                               alc260_hp_3013_unsol_verbs },
-               .num_dacs = ARRAY_SIZE(alc260_dac_nids),
-               .dac_nids = alc260_dac_nids,
-               .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
-               .adc_nids = alc260_adc_nids_alt,
-               .num_channel_mode = ARRAY_SIZE(alc260_modes),
-               .channel_mode = alc260_modes,
-               .input_mux = &alc260_capture_source,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc260_hp_3013_setup,
-               .init_hook = alc_inithook,
-       },
        [ALC260_FUJITSU_S702X] = {
                .mixers = { alc260_fujitsu_mixer },
                .init_verbs = { alc260_fujitsu_init_verbs },
index 8d2097d776422e52fab49fe6140a79a6f8f2286f..7894b2b5aacffcc343741ddf4cc0e64ccd4d17f9 100644 (file)
@@ -10,13 +10,7 @@ enum {
        ALC262_HIPPO,
        ALC262_HIPPO_1,
        ALC262_FUJITSU,
-       ALC262_HP_BPC,
-       ALC262_HP_BPC_D7000_WL,
-       ALC262_HP_BPC_D7000_WF,
-       ALC262_HP_TC_T5735,
-       ALC262_HP_RP5700,
        ALC262_BENQ_ED8,
-       ALC262_SONY_ASSAMD,
        ALC262_BENQ_T31,
        ALC262_ULTRA,
        ALC262_LENOVO_3000,
@@ -66,164 +60,31 @@ static const struct snd_kcontrol_new alc262_base_mixer[] = {
        { } /* end */
 };
 
-/* update HP, line and mono-out pins according to the master switch */
-#define alc262_hp_master_update                alc260_hp_master_update
+/* bind hp and internal speaker mute (with plug check) as master switch */
 
-static void alc262_hp_bpc_setup(struct hda_codec *codec)
+static int alc262_hippo_master_sw_get(struct snd_kcontrol *kcontrol,
+                                     struct snd_ctl_elem_value *ucontrol)
 {
+       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
        struct alc_spec *spec = codec->spec;
-
-       spec->autocfg.hp_pins[0] = 0x1b;
-       spec->autocfg.speaker_pins[0] = 0x16;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_PIN;
+       *ucontrol->value.integer.value = !spec->master_mute;
+       return 0;
 }
 
-static void alc262_hp_wildwest_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-
-       spec->autocfg.hp_pins[0] = 0x15;
-       spec->autocfg.speaker_pins[0] = 0x16;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_PIN;
-}
-
-#define alc262_hp_master_sw_get                alc260_hp_master_sw_get
-#define alc262_hp_master_sw_put                alc260_hp_master_sw_put
-
-#define ALC262_HP_MASTER_SWITCH                                        \
-       {                                                       \
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,            \
-               .name = "Master Playback Switch",               \
-               .info = snd_ctl_boolean_mono_info,              \
-               .get = alc262_hp_master_sw_get,                 \
-               .put = alc262_hp_master_sw_put,                 \
-       }, \
-       {                                                       \
-               .iface = NID_MAPPING,                           \
-               .name = "Master Playback Switch",               \
-               .private_value = 0x15 | (0x16 << 8) | (0x1b << 16),     \
-       }
-
-
-static const struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
-       ALC262_HP_MASTER_SWITCH,
-       HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
-                             HDA_OUTPUT),
-       HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
-                           HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
-       HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
-       HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
-       HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
-       HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
-       HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
-       HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
-       HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
-       { } /* end */
-};
-
-static const struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
-       ALC262_HP_MASTER_SWITCH,
-       HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
-                             HDA_OUTPUT),
-       HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
-                           HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
-       HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
-       HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x1a, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
-       HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
-       HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
-       HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
-       { } /* end */
-};
-
-static const struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
-       HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Rear Mic Boost Volume", 0x18, 0, HDA_INPUT),
-       { } /* end */
-};
-
-/* mute/unmute internal speaker according to the hp jack and mute state */
-static void alc262_hp_t5735_setup(struct hda_codec *codec)
+static int alc262_hippo_master_sw_put(struct snd_kcontrol *kcontrol,
+                                    struct snd_ctl_elem_value *ucontrol)
 {
+       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
        struct alc_spec *spec = codec->spec;
+       int val = !*ucontrol->value.integer.value;
 
-       spec->autocfg.hp_pins[0] = 0x15;
-       spec->autocfg.speaker_pins[0] = 0x14;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_PIN;
+       if (val == spec->master_mute)
+               return 0;
+       spec->master_mute = val;
+       update_outputs(codec);
+       return 1;
 }
 
-static const struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
-       HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
-       { } /* end */
-};
-
-static const struct hda_verb alc262_hp_t5735_verbs[] = {
-       {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
-       {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-
-       {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_HP_EVENT | AC_USRSP_EN},
-       { }
-};
-
-static const struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
-       HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
-       HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
-       { } /* end */
-};
-
-static const struct hda_verb alc262_hp_rp5700_verbs[] = {
-       {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
-       {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
-       {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
-       {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
-       {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
-       {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
-       {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
-       {}
-};
-
-static const struct hda_input_mux alc262_hp_rp5700_capture_source = {
-       .num_items = 1,
-       .items = {
-               { "Line", 0x1 },
-       },
-};
-
-/* bind hp and internal speaker mute (with plug check) as master switch */
-#define alc262_hippo_master_update     alc262_hp_master_update
-#define alc262_hippo_master_sw_get     alc262_hp_master_sw_get
-#define alc262_hippo_master_sw_put     alc262_hp_master_sw_put
-
 #define ALC262_HIPPO_MASTER_SWITCH                             \
        {                                                       \
                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,            \
@@ -239,6 +100,9 @@ static const struct hda_input_mux alc262_hp_rp5700_capture_source = {
                             (SUBDEV_SPEAKER(0) << 16), \
        }
 
+#define alc262_hp_master_sw_get                alc262_hippo_master_sw_get
+#define alc262_hp_master_sw_put                alc262_hippo_master_sw_put
+
 static const struct snd_kcontrol_new alc262_hippo_mixer[] = {
        ALC262_HIPPO_MASTER_SWITCH,
        HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
@@ -279,8 +143,7 @@ static void alc262_hippo_setup(struct hda_codec *codec)
 
        spec->autocfg.hp_pins[0] = 0x15;
        spec->autocfg.speaker_pins[0] = 0x14;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 static void alc262_hippo1_setup(struct hda_codec *codec)
@@ -289,8 +152,7 @@ static void alc262_hippo1_setup(struct hda_codec *codec)
 
        spec->autocfg.hp_pins[0] = 0x1b;
        spec->autocfg.speaker_pins[0] = 0x14;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 
@@ -353,8 +215,7 @@ static void alc262_tyan_setup(struct hda_codec *codec)
 
        spec->autocfg.hp_pins[0] = 0x1b;
        spec->autocfg.speaker_pins[0] = 0x15;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 
@@ -496,8 +357,7 @@ static void alc262_toshiba_s06_setup(struct hda_codec *codec)
        spec->ext_mic_pin = 0x18;
        spec->int_mic_pin = 0x12;
        spec->auto_mic = 1;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_PIN;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_PIN);
 }
 
 /*
@@ -571,27 +431,6 @@ static const struct hda_input_mux alc262_fujitsu_capture_source = {
        },
 };
 
-static const struct hda_input_mux alc262_HP_capture_source = {
-       .num_items = 5,
-       .items = {
-               { "Mic", 0x0 },
-               { "Front Mic", 0x1 },
-               { "Line", 0x2 },
-               { "CD", 0x4 },
-               { "AUX IN", 0x6 },
-       },
-};
-
-static const struct hda_input_mux alc262_HP_D7000_capture_source = {
-       .num_items = 4,
-       .items = {
-               { "Mic", 0x0 },
-               { "Front Mic", 0x2 },
-               { "Line", 0x1 },
-               { "CD", 0x4 },
-       },
-};
-
 static void alc262_fujitsu_setup(struct hda_codec *codec)
 {
        struct alc_spec *spec = codec->spec;
@@ -599,8 +438,7 @@ static void alc262_fujitsu_setup(struct hda_codec *codec)
        spec->autocfg.hp_pins[0] = 0x14;
        spec->autocfg.hp_pins[1] = 0x1b;
        spec->autocfg.speaker_pins[0] = 0x15;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 /* bind volumes of both NID 0x0c and 0x0d */
@@ -646,8 +484,7 @@ static void alc262_lenovo_3000_setup(struct hda_codec *codec)
        spec->autocfg.hp_pins[0] = 0x1b;
        spec->autocfg.speaker_pins[0] = 0x14;
        spec->autocfg.speaker_pins[1] = 0x16;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 static const struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
@@ -752,8 +589,8 @@ static void alc262_ultra_automute(struct hda_codec *codec)
        mute = 0;
        /* auto-mute only when HP is used as HP */
        if (!spec->cur_mux[0]) {
-               spec->jack_present = snd_hda_jack_detect(codec, 0x15);
-               if (spec->jack_present)
+               spec->hp_jack_present = snd_hda_jack_detect(codec, 0x15);
+               if (spec->hp_jack_present)
                        mute = HDA_AMP_MUTE;
        }
        /* mute/unmute internal speaker */
@@ -817,206 +654,6 @@ static const struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
        { } /* end */
 };
 
-static const struct hda_verb alc262_HP_BPC_init_verbs[] = {
-       /*
-        * Unmute ADC0-2 and set the default input to mic-in
-        */
-       {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
-       {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
-       {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
-       {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-
-       /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
-        * mixer widget
-        * Note: PASD motherboards uses the Line In 2 as the input for
-        * front panel mic (mic 2)
-        */
-       /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
-       {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
-       {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
-       {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
-       {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
-       {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
-       {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
-        {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
-
-       /*
-        * Set up output mixers (0x0c - 0x0e)
-        */
-       /* set vol=0 to output mixers */
-       {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
-       {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
-       {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
-
-       /* set up input amps for analog loopback */
-       /* Amp Indices: DAC = 0, mixer = 1 */
-       {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-
-       {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
-       {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
-
-       {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
-
-       {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
-       {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
-
-       {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
-       {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
-        {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
-       {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
-       {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
-
-       {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
-       {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
-        {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
-       {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
-       {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
-       {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
-
-
-       /* FIXME: use matrix-type input source selection */
-       /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 0b, 12 */
-       /* Input mixer1: only unmute Mic */
-       {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
-       {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
-       {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
-       {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
-       {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
-       {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
-       {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
-       {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
-       {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
-       /* Input mixer2 */
-       {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
-       {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
-       {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
-       {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
-       {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
-       {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
-       {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
-       {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
-       {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
-       /* Input mixer3 */
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
-
-       {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_HP_EVENT | AC_USRSP_EN},
-
-       { }
-};
-
-static const struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
-       /*
-        * Unmute ADC0-2 and set the default input to mic-in
-        */
-       {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
-       {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
-       {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
-       {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-
-       /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
-        * mixer widget
-        * Note: PASD motherboards uses the Line In 2 as the input for front
-        * panel mic (mic 2)
-        */
-       /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
-       {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
-       {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
-       {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
-       {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
-       {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
-       {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
-       {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
-       {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
-       /*
-        * Set up output mixers (0x0c - 0x0e)
-        */
-       /* set vol=0 to output mixers */
-       {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
-       {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
-       {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
-
-       /* set up input amps for analog loopback */
-       /* Amp Indices: DAC = 0, mixer = 1 */
-       {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-
-
-       {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
-       {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
-       {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
-       {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
-       {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
-       {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
-       {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
-
-       {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
-
-       {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
-       {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
-
-       /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
-       {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
-       {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
-       {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
-       {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
-       {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
-
-       /* FIXME: use matrix-type input source selection */
-       /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
-       /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
-       {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
-       {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
-       {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
-       {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
-       {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
-        /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
-       {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
-       /* Input mixer2 */
-       {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
-       {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
-       {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
-       {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
-       {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
-        /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
-       {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
-       /* Input mixer3 */
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
-        /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
-
-       {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_HP_EVENT | AC_USRSP_EN},
-
-       { }
-};
-
 static const struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
 
        {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Front Speaker */
@@ -1042,13 +679,8 @@ static const char * const alc262_models[ALC262_MODEL_LAST] = {
        [ALC262_HIPPO]          = "hippo",
        [ALC262_HIPPO_1]        = "hippo_1",
        [ALC262_FUJITSU]        = "fujitsu",
-       [ALC262_HP_BPC]         = "hp-bpc",
-       [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
-       [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
-       [ALC262_HP_RP5700]      = "hp-rp5700",
        [ALC262_BENQ_ED8]       = "benq",
        [ALC262_BENQ_T31]       = "benq-t31",
-       [ALC262_SONY_ASSAMD]    = "sony-assamd",
        [ALC262_TOSHIBA_S06]    = "toshiba-s06",
        [ALC262_TOSHIBA_RX1]    = "toshiba-rx1",
        [ALC262_ULTRA]          = "ultra",
@@ -1061,41 +693,6 @@ static const char * const alc262_models[ALC262_MODEL_LAST] = {
 static const struct snd_pci_quirk alc262_cfg_tbl[] = {
        SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
        SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
-       SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1200, "HP xw series",
-                          ALC262_HP_BPC),
-       SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1300, "HP xw series",
-                          ALC262_HP_BPC),
-       SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1500, "HP z series",
-                          ALC262_HP_BPC),
-       SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200",
-                          ALC262_AUTO),
-       SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1700, "HP xw series",
-                          ALC262_HP_BPC),
-       SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
-       SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
-       SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
-       SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
-       SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
-       SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
-       SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
-       SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
-       SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
-       SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
-       SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
-       SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
-                     ALC262_HP_TC_T5735),
-       SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
-       SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
-       SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
-       SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
-       SND_PCI_QUIRK(0x104d, 0x9016, "Sony VAIO", ALC262_AUTO), /* dig-only */
-       SND_PCI_QUIRK(0x104d, 0x9025, "Sony VAIO Z21MN", ALC262_TOSHIBA_S06),
-       SND_PCI_QUIRK(0x104d, 0x9035, "Sony VAIO VGN-FW170J", ALC262_AUTO),
-       SND_PCI_QUIRK(0x104d, 0x9047, "Sony VAIO Type G", ALC262_AUTO),
-#if 0 /* disable the quirk since model=auto works better in recent versions */
-       SND_PCI_QUIRK_MASK(0x104d, 0xff00, 0x9000, "Sony VAIO",
-                          ALC262_SONY_ASSAMD),
-#endif
        SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
                      ALC262_TOSHIBA_RX1),
        SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
@@ -1166,68 +763,6 @@ static const struct alc_config_preset alc262_presets[] = {
                .setup = alc262_fujitsu_setup,
                .init_hook = alc_inithook,
        },
-       [ALC262_HP_BPC] = {
-               .mixers = { alc262_HP_BPC_mixer },
-               .init_verbs = { alc262_HP_BPC_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc262_dac_nids),
-               .dac_nids = alc262_dac_nids,
-               .hp_nid = 0x03,
-               .num_channel_mode = ARRAY_SIZE(alc262_modes),
-               .channel_mode = alc262_modes,
-               .input_mux = &alc262_HP_capture_source,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc262_hp_bpc_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC262_HP_BPC_D7000_WF] = {
-               .mixers = { alc262_HP_BPC_WildWest_mixer },
-               .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc262_dac_nids),
-               .dac_nids = alc262_dac_nids,
-               .hp_nid = 0x03,
-               .num_channel_mode = ARRAY_SIZE(alc262_modes),
-               .channel_mode = alc262_modes,
-               .input_mux = &alc262_HP_D7000_capture_source,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc262_hp_wildwest_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC262_HP_BPC_D7000_WL] = {
-               .mixers = { alc262_HP_BPC_WildWest_mixer,
-                           alc262_HP_BPC_WildWest_option_mixer },
-               .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc262_dac_nids),
-               .dac_nids = alc262_dac_nids,
-               .hp_nid = 0x03,
-               .num_channel_mode = ARRAY_SIZE(alc262_modes),
-               .channel_mode = alc262_modes,
-               .input_mux = &alc262_HP_D7000_capture_source,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc262_hp_wildwest_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC262_HP_TC_T5735] = {
-               .mixers = { alc262_hp_t5735_mixer },
-               .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
-               .num_dacs = ARRAY_SIZE(alc262_dac_nids),
-               .dac_nids = alc262_dac_nids,
-               .hp_nid = 0x03,
-               .num_channel_mode = ARRAY_SIZE(alc262_modes),
-               .channel_mode = alc262_modes,
-               .input_mux = &alc262_capture_source,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc262_hp_t5735_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC262_HP_RP5700] = {
-               .mixers = { alc262_hp_rp5700_mixer },
-               .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
-               .num_dacs = ARRAY_SIZE(alc262_dac_nids),
-               .dac_nids = alc262_dac_nids,
-               .num_channel_mode = ARRAY_SIZE(alc262_modes),
-               .channel_mode = alc262_modes,
-               .input_mux = &alc262_hp_rp5700_capture_source,
-        },
        [ALC262_BENQ_ED8] = {
                .mixers = { alc262_base_mixer },
                .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
@@ -1238,19 +773,6 @@ static const struct alc_config_preset alc262_presets[] = {
                .channel_mode = alc262_modes,
                .input_mux = &alc262_capture_source,
        },
-       [ALC262_SONY_ASSAMD] = {
-               .mixers = { alc262_sony_mixer },
-               .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
-               .num_dacs = ARRAY_SIZE(alc262_dac_nids),
-               .dac_nids = alc262_dac_nids,
-               .hp_nid = 0x02,
-               .num_channel_mode = ARRAY_SIZE(alc262_modes),
-               .channel_mode = alc262_modes,
-               .input_mux = &alc262_capture_source,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc262_hippo_setup,
-               .init_hook = alc_inithook,
-       },
        [ALC262_BENQ_T31] = {
                .mixers = { alc262_benq_t31_mixer },
                .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs,
diff --git a/sound/pci/hda/alc268_quirks.c b/sound/pci/hda/alc268_quirks.c
deleted file mode 100644 (file)
index 2e5876c..0000000
+++ /dev/null
@@ -1,636 +0,0 @@
-/*
- * ALC267/ALC268 quirk models
- * included by patch_realtek.c
- */
-
-/* ALC268 models */
-enum {
-       ALC268_AUTO,
-       ALC267_QUANTA_IL1,
-       ALC268_3ST,
-       ALC268_TOSHIBA,
-       ALC268_ACER,
-       ALC268_ACER_DMIC,
-       ALC268_ACER_ASPIRE_ONE,
-       ALC268_DELL,
-       ALC268_ZEPTO,
-#ifdef CONFIG_SND_DEBUG
-       ALC268_TEST,
-#endif
-       ALC268_MODEL_LAST /* last tag */
-};
-
-/*
- *  ALC268 channel source setting (2 channel)
- */
-#define ALC268_DIGOUT_NID      ALC880_DIGOUT_NID
-#define alc268_modes           alc260_modes
-
-static const hda_nid_t alc268_dac_nids[2] = {
-       /* front, hp */
-       0x02, 0x03
-};
-
-static const hda_nid_t alc268_adc_nids[2] = {
-       /* ADC0-1 */
-       0x08, 0x07
-};
-
-static const hda_nid_t alc268_adc_nids_alt[1] = {
-       /* ADC0 */
-       0x08
-};
-
-static const hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
-
-static const struct snd_kcontrol_new alc268_base_mixer[] = {
-       /* output mixer control */
-       HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Line In Boost Volume", 0x1a, 0, HDA_INPUT),
-       { }
-};
-
-static const struct snd_kcontrol_new alc268_toshiba_mixer[] = {
-       /* output mixer control */
-       HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
-       ALC262_HIPPO_MASTER_SWITCH,
-       HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Line In Boost Volume", 0x1a, 0, HDA_INPUT),
-       { }
-};
-
-static const struct hda_verb alc268_eapd_verbs[] = {
-       {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
-       {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
-       { }
-};
-
-/* Toshiba specific */
-static const struct hda_verb alc268_toshiba_verbs[] = {
-       {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_HP_EVENT | AC_USRSP_EN},
-       { } /* end */
-};
-
-/* Acer specific */
-/* bind volumes of both NID 0x02 and 0x03 */
-static const struct hda_bind_ctls alc268_acer_bind_master_vol = {
-       .ops = &snd_hda_bind_vol,
-       .values = {
-               HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
-               HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
-               0
-       },
-};
-
-static void alc268_acer_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-
-       spec->autocfg.hp_pins[0] = 0x14;
-       spec->autocfg.speaker_pins[0] = 0x15;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
-}
-
-#define alc268_acer_master_sw_get      alc262_hp_master_sw_get
-#define alc268_acer_master_sw_put      alc262_hp_master_sw_put
-
-static const struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
-       /* output mixer control */
-       HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "Master Playback Switch",
-               .subdevice = HDA_SUBDEV_NID_FLAG | 0x15,
-               .info = snd_ctl_boolean_mono_info,
-               .get = alc268_acer_master_sw_get,
-               .put = alc268_acer_master_sw_put,
-       },
-       HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
-       { }
-};
-
-static const struct snd_kcontrol_new alc268_acer_mixer[] = {
-       /* output mixer control */
-       HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "Master Playback Switch",
-               .subdevice = HDA_SUBDEV_NID_FLAG | 0x14,
-               .info = snd_ctl_boolean_mono_info,
-               .get = alc268_acer_master_sw_get,
-               .put = alc268_acer_master_sw_put,
-       },
-       HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Line In Boost Volume", 0x1a, 0, HDA_INPUT),
-       { }
-};
-
-static const struct snd_kcontrol_new alc268_acer_dmic_mixer[] = {
-       /* output mixer control */
-       HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "Master Playback Switch",
-               .subdevice = HDA_SUBDEV_NID_FLAG | 0x14,
-               .info = snd_ctl_boolean_mono_info,
-               .get = alc268_acer_master_sw_get,
-               .put = alc268_acer_master_sw_put,
-       },
-       HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Line In Boost Volume", 0x1a, 0, HDA_INPUT),
-       { }
-};
-
-static const struct hda_verb alc268_acer_aspire_one_verbs[] = {
-       {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_HP_EVENT | AC_USRSP_EN},
-       {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
-       {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
-       {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
-       { }
-};
-
-static const struct hda_verb alc268_acer_verbs[] = {
-       {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
-       {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
-       {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
-       {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
-       {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_HP_EVENT | AC_USRSP_EN},
-       { }
-};
-
-/* unsolicited event for HP jack sensing */
-#define alc268_toshiba_setup           alc262_hippo_setup
-
-static void alc268_acer_lc_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-       spec->autocfg.hp_pins[0] = 0x15;
-       spec->autocfg.speaker_pins[0] = 0x14;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
-       spec->ext_mic_pin = 0x18;
-       spec->int_mic_pin = 0x12;
-       spec->auto_mic = 1;
-}
-
-static const struct snd_kcontrol_new alc268_dell_mixer[] = {
-       /* output mixer control */
-       HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
-       { }
-};
-
-static const struct hda_verb alc268_dell_verbs[] = {
-       {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_HP_EVENT | AC_USRSP_EN},
-       {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_MIC_EVENT | AC_USRSP_EN},
-       { }
-};
-
-/* mute/unmute internal speaker according to the hp jack and mute state */
-static void alc268_dell_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-
-       spec->autocfg.hp_pins[0] = 0x15;
-       spec->autocfg.speaker_pins[0] = 0x14;
-       spec->ext_mic_pin = 0x18;
-       spec->int_mic_pin = 0x19;
-       spec->auto_mic = 1;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_PIN;
-}
-
-static const struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
-       HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
-       HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
-       { }
-};
-
-static const struct hda_verb alc267_quanta_il1_verbs[] = {
-       {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_HP_EVENT | AC_USRSP_EN},
-       {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_MIC_EVENT | AC_USRSP_EN},
-       { }
-};
-
-static void alc267_quanta_il1_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-       spec->autocfg.hp_pins[0] = 0x15;
-       spec->autocfg.speaker_pins[0] = 0x14;
-       spec->ext_mic_pin = 0x18;
-       spec->int_mic_pin = 0x19;
-       spec->auto_mic = 1;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_PIN;
-}
-
-/*
- * generic initialization of ADC, input mixers and output mixers
- */
-static const struct hda_verb alc268_base_init_verbs[] = {
-       /* Unmute DAC0-1 and set vol = 0 */
-       {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
-       {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
-
-       /*
-        * Set up output mixers (0x0c - 0x0e)
-        */
-       /* set vol=0 to output mixers */
-       {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-        {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
-
-       {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-
-       {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
-       {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
-       {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
-       {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
-       {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
-       {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
-       {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
-       {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
-
-       {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
-       {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
-       {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
-       {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
-
-       /* set PCBEEP vol = 0, mute connections */
-       {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
-       {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
-
-       /* Unmute Selector 23h,24h and set the default input to mic-in */
-
-       {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
-       {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
-       {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-
-       { }
-};
-
-/* only for model=test */
-#ifdef CONFIG_SND_DEBUG
-/*
- * generic initialization of ADC, input mixers and output mixers
- */
-static const struct hda_verb alc268_volume_init_verbs[] = {
-       /* set output DAC */
-       {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
-       {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
-
-       {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
-       {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
-       {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
-       {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
-       {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
-
-       {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-
-       {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
-       {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
-       { }
-};
-#endif /* CONFIG_SND_DEBUG */
-
-static const struct snd_kcontrol_new alc268_capture_nosrc_mixer[] = {
-       HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
-       { } /* end */
-};
-
-static const struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
-       HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
-       _DEFINE_CAPSRC(1),
-       { } /* end */
-};
-
-static const struct snd_kcontrol_new alc268_capture_mixer[] = {
-       HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
-       _DEFINE_CAPSRC(2),
-       { } /* end */
-};
-
-static const struct hda_input_mux alc268_capture_source = {
-       .num_items = 4,
-       .items = {
-               { "Mic", 0x0 },
-               { "Front Mic", 0x1 },
-               { "Line", 0x2 },
-               { "CD", 0x3 },
-       },
-};
-
-static const struct hda_input_mux alc268_acer_capture_source = {
-       .num_items = 3,
-       .items = {
-               { "Mic", 0x0 },
-               { "Internal Mic", 0x1 },
-               { "Line", 0x2 },
-       },
-};
-
-static const struct hda_input_mux alc268_acer_dmic_capture_source = {
-       .num_items = 3,
-       .items = {
-               { "Mic", 0x0 },
-               { "Internal Mic", 0x6 },
-               { "Line", 0x2 },
-       },
-};
-
-#ifdef CONFIG_SND_DEBUG
-static const struct snd_kcontrol_new alc268_test_mixer[] = {
-       /* Volume widgets */
-       HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
-       HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
-       HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
-       HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
-       HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
-       HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
-       HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
-       HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
-       HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
-       /* The below appears problematic on some hardwares */
-       /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
-       HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
-       HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
-       HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
-
-       /* Modes for retasking pin widgets */
-       ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
-       ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
-       ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
-       ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
-
-       /* Controls for GPIO pins, assuming they are configured as outputs */
-       ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
-       ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
-       ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
-       ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
-
-       /* Switches to allow the digital SPDIF output pin to be enabled.
-        * The ALC268 does not have an SPDIF input.
-        */
-       ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
-
-       /* A switch allowing EAPD to be enabled.  Some laptops seem to use
-        * this output to turn on an external amplifier.
-        */
-       ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
-       ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
-
-       { } /* end */
-};
-#endif
-
-/*
- * configuration and preset
- */
-static const char * const alc268_models[ALC268_MODEL_LAST] = {
-       [ALC267_QUANTA_IL1]     = "quanta-il1",
-       [ALC268_3ST]            = "3stack",
-       [ALC268_TOSHIBA]        = "toshiba",
-       [ALC268_ACER]           = "acer",
-       [ALC268_ACER_DMIC]      = "acer-dmic",
-       [ALC268_ACER_ASPIRE_ONE]        = "acer-aspire",
-       [ALC268_DELL]           = "dell",
-       [ALC268_ZEPTO]          = "zepto",
-#ifdef CONFIG_SND_DEBUG
-       [ALC268_TEST]           = "test",
-#endif
-       [ALC268_AUTO]           = "auto",
-};
-
-static const struct snd_pci_quirk alc268_cfg_tbl[] = {
-       SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
-       SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
-       SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
-       SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
-       SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
-       SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
-                                               ALC268_ACER_ASPIRE_ONE),
-       SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
-       SND_PCI_QUIRK(0x1028, 0x02b0, "Dell Inspiron 910", ALC268_AUTO),
-       SND_PCI_QUIRK_MASK(0x1028, 0xfff0, 0x02b0,
-                       "Dell Inspiron Mini9/Vostro A90", ALC268_DELL),
-       /* almost compatible with toshiba but with optional digital outs;
-        * auto-probing seems working fine
-        */
-       SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP TX25xx series",
-                          ALC268_AUTO),
-       SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
-       SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
-       SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
-       SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
-       {}
-};
-
-/* Toshiba laptops have no unique PCI SSID but only codec SSID */
-static const struct snd_pci_quirk alc268_ssid_cfg_tbl[] = {
-       SND_PCI_QUIRK(0x1179, 0xff0a, "TOSHIBA X-200", ALC268_AUTO),
-       SND_PCI_QUIRK(0x1179, 0xff0e, "TOSHIBA X-200 HDMI", ALC268_AUTO),
-       SND_PCI_QUIRK_MASK(0x1179, 0xff00, 0xff00, "TOSHIBA A/Lx05",
-                          ALC268_TOSHIBA),
-       {}
-};
-
-static const struct alc_config_preset alc268_presets[] = {
-       [ALC267_QUANTA_IL1] = {
-               .mixers = { alc267_quanta_il1_mixer, alc268_beep_mixer },
-               .cap_mixer = alc268_capture_nosrc_mixer,
-               .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
-                               alc267_quanta_il1_verbs },
-               .num_dacs = ARRAY_SIZE(alc268_dac_nids),
-               .dac_nids = alc268_dac_nids,
-               .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
-               .adc_nids = alc268_adc_nids_alt,
-               .hp_nid = 0x03,
-               .num_channel_mode = ARRAY_SIZE(alc268_modes),
-               .channel_mode = alc268_modes,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc267_quanta_il1_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC268_3ST] = {
-               .mixers = { alc268_base_mixer, alc268_beep_mixer },
-               .cap_mixer = alc268_capture_alt_mixer,
-               .init_verbs = { alc268_base_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc268_dac_nids),
-               .dac_nids = alc268_dac_nids,
-                .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
-                .adc_nids = alc268_adc_nids_alt,
-               .capsrc_nids = alc268_capsrc_nids,
-               .hp_nid = 0x03,
-               .dig_out_nid = ALC268_DIGOUT_NID,
-               .num_channel_mode = ARRAY_SIZE(alc268_modes),
-               .channel_mode = alc268_modes,
-               .input_mux = &alc268_capture_source,
-       },
-       [ALC268_TOSHIBA] = {
-               .mixers = { alc268_toshiba_mixer, alc268_beep_mixer },
-               .cap_mixer = alc268_capture_alt_mixer,
-               .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
-                               alc268_toshiba_verbs },
-               .num_dacs = ARRAY_SIZE(alc268_dac_nids),
-               .dac_nids = alc268_dac_nids,
-               .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
-               .adc_nids = alc268_adc_nids_alt,
-               .capsrc_nids = alc268_capsrc_nids,
-               .hp_nid = 0x03,
-               .num_channel_mode = ARRAY_SIZE(alc268_modes),
-               .channel_mode = alc268_modes,
-               .input_mux = &alc268_capture_source,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc268_toshiba_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC268_ACER] = {
-               .mixers = { alc268_acer_mixer, alc268_beep_mixer },
-               .cap_mixer = alc268_capture_alt_mixer,
-               .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
-                               alc268_acer_verbs },
-               .num_dacs = ARRAY_SIZE(alc268_dac_nids),
-               .dac_nids = alc268_dac_nids,
-               .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
-               .adc_nids = alc268_adc_nids_alt,
-               .capsrc_nids = alc268_capsrc_nids,
-               .hp_nid = 0x02,
-               .num_channel_mode = ARRAY_SIZE(alc268_modes),
-               .channel_mode = alc268_modes,
-               .input_mux = &alc268_acer_capture_source,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc268_acer_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC268_ACER_DMIC] = {
-               .mixers = { alc268_acer_dmic_mixer, alc268_beep_mixer },
-               .cap_mixer = alc268_capture_alt_mixer,
-               .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
-                               alc268_acer_verbs },
-               .num_dacs = ARRAY_SIZE(alc268_dac_nids),
-               .dac_nids = alc268_dac_nids,
-               .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
-               .adc_nids = alc268_adc_nids_alt,
-               .capsrc_nids = alc268_capsrc_nids,
-               .hp_nid = 0x02,
-               .num_channel_mode = ARRAY_SIZE(alc268_modes),
-               .channel_mode = alc268_modes,
-               .input_mux = &alc268_acer_dmic_capture_source,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc268_acer_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC268_ACER_ASPIRE_ONE] = {
-               .mixers = { alc268_acer_aspire_one_mixer, alc268_beep_mixer},
-               .cap_mixer = alc268_capture_nosrc_mixer,
-               .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
-                               alc268_acer_aspire_one_verbs },
-               .num_dacs = ARRAY_SIZE(alc268_dac_nids),
-               .dac_nids = alc268_dac_nids,
-               .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
-               .adc_nids = alc268_adc_nids_alt,
-               .capsrc_nids = alc268_capsrc_nids,
-               .hp_nid = 0x03,
-               .num_channel_mode = ARRAY_SIZE(alc268_modes),
-               .channel_mode = alc268_modes,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc268_acer_lc_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC268_DELL] = {
-               .mixers = { alc268_dell_mixer, alc268_beep_mixer},
-               .cap_mixer = alc268_capture_nosrc_mixer,
-               .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
-                               alc268_dell_verbs },
-               .num_dacs = ARRAY_SIZE(alc268_dac_nids),
-               .dac_nids = alc268_dac_nids,
-               .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
-               .adc_nids = alc268_adc_nids_alt,
-               .capsrc_nids = alc268_capsrc_nids,
-               .hp_nid = 0x02,
-               .num_channel_mode = ARRAY_SIZE(alc268_modes),
-               .channel_mode = alc268_modes,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc268_dell_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC268_ZEPTO] = {
-               .mixers = { alc268_base_mixer, alc268_beep_mixer },
-               .cap_mixer = alc268_capture_alt_mixer,
-               .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
-                               alc268_toshiba_verbs },
-               .num_dacs = ARRAY_SIZE(alc268_dac_nids),
-               .dac_nids = alc268_dac_nids,
-               .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
-               .adc_nids = alc268_adc_nids_alt,
-               .capsrc_nids = alc268_capsrc_nids,
-               .hp_nid = 0x03,
-               .dig_out_nid = ALC268_DIGOUT_NID,
-               .num_channel_mode = ARRAY_SIZE(alc268_modes),
-               .channel_mode = alc268_modes,
-               .input_mux = &alc268_capture_source,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc268_toshiba_setup,
-               .init_hook = alc_inithook,
-       },
-#ifdef CONFIG_SND_DEBUG
-       [ALC268_TEST] = {
-               .mixers = { alc268_test_mixer },
-               .cap_mixer = alc268_capture_mixer,
-               .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
-                               alc268_volume_init_verbs,
-                               alc268_beep_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc268_dac_nids),
-               .dac_nids = alc268_dac_nids,
-               .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
-               .adc_nids = alc268_adc_nids_alt,
-               .capsrc_nids = alc268_capsrc_nids,
-               .hp_nid = 0x03,
-               .dig_out_nid = ALC268_DIGOUT_NID,
-               .num_channel_mode = ARRAY_SIZE(alc268_modes),
-               .channel_mode = alc268_modes,
-               .input_mux = &alc268_capture_source,
-       },
-#endif
-};
-
diff --git a/sound/pci/hda/alc269_quirks.c b/sound/pci/hda/alc269_quirks.c
deleted file mode 100644 (file)
index 5ac0e21..0000000
+++ /dev/null
@@ -1,674 +0,0 @@
-/*
- * ALC269/ALC270/ALC275/ALC276 quirk models
- * included by patch_realtek.c
- */
-
-/* ALC269 models */
-enum {
-       ALC269_AUTO,
-       ALC269_BASIC,
-       ALC269_QUANTA_FL1,
-       ALC269_AMIC,
-       ALC269_DMIC,
-       ALC269VB_AMIC,
-       ALC269VB_DMIC,
-       ALC269_FUJITSU,
-       ALC269_LIFEBOOK,
-       ALC271_ACER,
-       ALC269_MODEL_LAST /* last tag */
-};
-
-/*
- *  ALC269 channel source setting (2 channel)
- */
-#define ALC269_DIGOUT_NID      ALC880_DIGOUT_NID
-
-#define alc269_dac_nids                alc260_dac_nids
-
-static const hda_nid_t alc269_adc_nids[1] = {
-       /* ADC1 */
-       0x08,
-};
-
-static const hda_nid_t alc269_capsrc_nids[1] = {
-       0x23,
-};
-
-static const hda_nid_t alc269vb_adc_nids[1] = {
-       /* ADC1 */
-       0x09,
-};
-
-static const hda_nid_t alc269vb_capsrc_nids[1] = {
-       0x22,
-};
-
-#define alc269_modes           alc260_modes
-#define alc269_capture_source  alc880_lg_lw_capture_source
-
-static const struct snd_kcontrol_new alc269_base_mixer[] = {
-       HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
-       HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
-       HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
-       HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
-       { } /* end */
-};
-
-static const struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
-       /* output mixer control */
-       HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "Master Playback Switch",
-               .subdevice = HDA_SUBDEV_AMP_FLAG,
-               .info = snd_hda_mixer_amp_switch_info,
-               .get = snd_hda_mixer_amp_switch_get,
-               .put = alc268_acer_master_sw_put,
-               .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
-       },
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
-       HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
-       HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
-       { }
-};
-
-static const struct snd_kcontrol_new alc269_lifebook_mixer[] = {
-       /* output mixer control */
-       HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "Master Playback Switch",
-               .subdevice = HDA_SUBDEV_AMP_FLAG,
-               .info = snd_hda_mixer_amp_switch_info,
-               .get = snd_hda_mixer_amp_switch_get,
-               .put = alc268_acer_master_sw_put,
-               .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
-       },
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
-       HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
-       HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT),
-       HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT),
-       HDA_CODEC_VOLUME("Dock Mic Boost Volume", 0x1b, 0, HDA_INPUT),
-       { }
-};
-
-static const struct snd_kcontrol_new alc269_laptop_mixer[] = {
-       HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
-       { } /* end */
-};
-
-static const struct snd_kcontrol_new alc269vb_laptop_mixer[] = {
-       HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
-       { } /* end */
-};
-
-static const struct snd_kcontrol_new alc269_asus_mixer[] = {
-       HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x0, HDA_INPUT),
-       { } /* end */
-};
-
-/* capture mixer elements */
-static const struct snd_kcontrol_new alc269_laptop_analog_capture_mixer[] = {
-       HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
-       { } /* end */
-};
-
-static const struct snd_kcontrol_new alc269_laptop_digital_capture_mixer[] = {
-       HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
-       { } /* end */
-};
-
-static const struct snd_kcontrol_new alc269vb_laptop_analog_capture_mixer[] = {
-       HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
-       { } /* end */
-};
-
-static const struct snd_kcontrol_new alc269vb_laptop_digital_capture_mixer[] = {
-       HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
-       { } /* end */
-};
-
-/* FSC amilo */
-#define alc269_fujitsu_mixer   alc269_laptop_mixer
-
-static const struct hda_verb alc269_quanta_fl1_verbs[] = {
-       {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
-       {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_HP_EVENT | AC_USRSP_EN},
-       {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
-       {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       { }
-};
-
-static const struct hda_verb alc269_lifebook_verbs[] = {
-       {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
-       {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
-       {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_HP_EVENT | AC_USRSP_EN},
-       {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_HP_EVENT | AC_USRSP_EN},
-       {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
-       {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       { }
-};
-
-/* toggle speaker-output according to the hp-jack state */
-static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
-{
-       alc_hp_automute(codec);
-
-       snd_hda_codec_write(codec, 0x20, 0,
-                       AC_VERB_SET_COEF_INDEX, 0x0c);
-       snd_hda_codec_write(codec, 0x20, 0,
-                       AC_VERB_SET_PROC_COEF, 0x680);
-
-       snd_hda_codec_write(codec, 0x20, 0,
-                       AC_VERB_SET_COEF_INDEX, 0x0c);
-       snd_hda_codec_write(codec, 0x20, 0,
-                       AC_VERB_SET_PROC_COEF, 0x480);
-}
-
-#define alc269_lifebook_speaker_automute \
-       alc269_quanta_fl1_speaker_automute
-
-static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
-{
-       unsigned int present_laptop;
-       unsigned int present_dock;
-
-       present_laptop  = snd_hda_jack_detect(codec, 0x18);
-       present_dock    = snd_hda_jack_detect(codec, 0x1b);
-
-       /* Laptop mic port overrides dock mic port, design decision */
-       if (present_dock)
-               snd_hda_codec_write(codec, 0x23, 0,
-                               AC_VERB_SET_CONNECT_SEL, 0x3);
-       if (present_laptop)
-               snd_hda_codec_write(codec, 0x23, 0,
-                               AC_VERB_SET_CONNECT_SEL, 0x0);
-       if (!present_dock && !present_laptop)
-               snd_hda_codec_write(codec, 0x23, 0,
-                               AC_VERB_SET_CONNECT_SEL, 0x1);
-}
-
-static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
-                                   unsigned int res)
-{
-       switch (res >> 26) {
-       case ALC_HP_EVENT:
-               alc269_quanta_fl1_speaker_automute(codec);
-               break;
-       case ALC_MIC_EVENT:
-               alc_mic_automute(codec);
-               break;
-       }
-}
-
-static void alc269_lifebook_unsol_event(struct hda_codec *codec,
-                                       unsigned int res)
-{
-       if ((res >> 26) == ALC_HP_EVENT)
-               alc269_lifebook_speaker_automute(codec);
-       if ((res >> 26) == ALC_MIC_EVENT)
-               alc269_lifebook_mic_autoswitch(codec);
-}
-
-static void alc269_quanta_fl1_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-       spec->autocfg.hp_pins[0] = 0x15;
-       spec->autocfg.speaker_pins[0] = 0x14;
-       spec->automute_mixer_nid[0] = 0x0c;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_MIXER;
-       spec->ext_mic_pin = 0x18;
-       spec->int_mic_pin = 0x19;
-       spec->auto_mic = 1;
-}
-
-static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
-{
-       alc269_quanta_fl1_speaker_automute(codec);
-       alc_mic_automute(codec);
-}
-
-static void alc269_lifebook_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-       spec->autocfg.hp_pins[0] = 0x15;
-       spec->autocfg.hp_pins[1] = 0x1a;
-       spec->autocfg.speaker_pins[0] = 0x14;
-       spec->automute_mixer_nid[0] = 0x0c;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_MIXER;
-}
-
-static void alc269_lifebook_init_hook(struct hda_codec *codec)
-{
-       alc269_lifebook_speaker_automute(codec);
-       alc269_lifebook_mic_autoswitch(codec);
-}
-
-static const struct hda_verb alc269_laptop_dmic_init_verbs[] = {
-       {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
-       {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
-       {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
-       {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
-       {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
-       {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
-       {}
-};
-
-static const struct hda_verb alc269_laptop_amic_init_verbs[] = {
-       {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
-       {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
-       {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
-       {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
-       {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
-       {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
-       {}
-};
-
-static const struct hda_verb alc269vb_laptop_dmic_init_verbs[] = {
-       {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},
-       {0x22, AC_VERB_SET_CONNECT_SEL, 0x06},
-       {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
-       {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
-       {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
-       {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
-       {}
-};
-
-static const struct hda_verb alc269vb_laptop_amic_init_verbs[] = {
-       {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},
-       {0x22, AC_VERB_SET_CONNECT_SEL, 0x01},
-       {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
-       {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
-       {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
-       {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
-       {}
-};
-
-static const struct hda_verb alc271_acer_dmic_verbs[] = {
-       {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
-       {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
-       {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
-       {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},
-       {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
-       {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
-       {0x22, AC_VERB_SET_CONNECT_SEL, 6},
-       { }
-};
-
-static void alc269_laptop_amic_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-       spec->autocfg.hp_pins[0] = 0x15;
-       spec->autocfg.speaker_pins[0] = 0x14;
-       spec->automute_mixer_nid[0] = 0x0c;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_MIXER;
-       spec->ext_mic_pin = 0x18;
-       spec->int_mic_pin = 0x19;
-       spec->auto_mic = 1;
-}
-
-static void alc269_laptop_dmic_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-       spec->autocfg.hp_pins[0] = 0x15;
-       spec->autocfg.speaker_pins[0] = 0x14;
-       spec->automute_mixer_nid[0] = 0x0c;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_MIXER;
-       spec->ext_mic_pin = 0x18;
-       spec->int_mic_pin = 0x12;
-       spec->auto_mic = 1;
-}
-
-static void alc269vb_laptop_amic_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-       spec->autocfg.hp_pins[0] = 0x21;
-       spec->autocfg.speaker_pins[0] = 0x14;
-       spec->automute_mixer_nid[0] = 0x0c;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_MIXER;
-       spec->ext_mic_pin = 0x18;
-       spec->int_mic_pin = 0x19;
-       spec->auto_mic = 1;
-}
-
-static void alc269vb_laptop_dmic_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-       spec->autocfg.hp_pins[0] = 0x21;
-       spec->autocfg.speaker_pins[0] = 0x14;
-       spec->automute_mixer_nid[0] = 0x0c;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_MIXER;
-       spec->ext_mic_pin = 0x18;
-       spec->int_mic_pin = 0x12;
-       spec->auto_mic = 1;
-}
-
-/*
- * generic initialization of ADC, input mixers and output mixers
- */
-static const struct hda_verb alc269_init_verbs[] = {
-       /*
-        * Unmute ADC0 and set the default input to mic-in
-        */
-       {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-
-       /*
-        * Set up output mixers (0x02 - 0x03)
-        */
-       /* set vol=0 to output mixers */
-       {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
-       {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
-
-       /* set up input amps for analog loopback */
-       /* Amp Indices: DAC = 0, mixer = 1 */
-       {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-
-       {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
-       {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
-       {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
-       {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
-       {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-
-       {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-
-       /* FIXME: use Mux-type input source selection */
-       /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
-       /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
-       {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
-
-       /* set EAPD */
-       {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
-       { }
-};
-
-static const struct hda_verb alc269vb_init_verbs[] = {
-       /*
-        * Unmute ADC0 and set the default input to mic-in
-        */
-       {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-
-       /*
-        * Set up output mixers (0x02 - 0x03)
-        */
-       /* set vol=0 to output mixers */
-       {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
-       {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
-
-       /* set up input amps for analog loopback */
-       /* Amp Indices: DAC = 0, mixer = 1 */
-       {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-
-       {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
-       {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
-       {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
-       {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
-       {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-
-       {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-
-       /* FIXME: use Mux-type input source selection */
-       /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
-       /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
-       {0x22, AC_VERB_SET_CONNECT_SEL, 0x00},
-
-       /* set EAPD */
-       {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
-       { }
-};
-
-/*
- * configuration and preset
- */
-static const char * const alc269_models[ALC269_MODEL_LAST] = {
-       [ALC269_BASIC]                  = "basic",
-       [ALC269_QUANTA_FL1]             = "quanta",
-       [ALC269_AMIC]                   = "laptop-amic",
-       [ALC269_DMIC]                   = "laptop-dmic",
-       [ALC269_FUJITSU]                = "fujitsu",
-       [ALC269_LIFEBOOK]               = "lifebook",
-       [ALC269_AUTO]                   = "auto",
-};
-
-static const struct snd_pci_quirk alc269_cfg_tbl[] = {
-       SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
-       SND_PCI_QUIRK(0x1025, 0x047c, "ACER ZGA", ALC271_ACER),
-       SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
-                     ALC269_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269VB_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x1113, "ASUS N63Jn", ALC269VB_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269VB_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269VB_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269VB_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269VB_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269VB_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269VB_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_AMIC),
-       SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_AMIC),
-       SND_PCI_QUIRK(0x104d, 0x9071, "Sony VAIO", ALC269_AUTO),
-       SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
-       SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_DMIC),
-       SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
-       SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_AMIC),
-       SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_AMIC),
-       SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_DMIC),
-       SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_DMIC),
-       {}
-};
-
-static const struct alc_config_preset alc269_presets[] = {
-       [ALC269_BASIC] = {
-               .mixers = { alc269_base_mixer },
-               .init_verbs = { alc269_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc269_dac_nids),
-               .dac_nids = alc269_dac_nids,
-               .hp_nid = 0x03,
-               .num_channel_mode = ARRAY_SIZE(alc269_modes),
-               .channel_mode = alc269_modes,
-               .input_mux = &alc269_capture_source,
-       },
-       [ALC269_QUANTA_FL1] = {
-               .mixers = { alc269_quanta_fl1_mixer },
-               .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
-               .num_dacs = ARRAY_SIZE(alc269_dac_nids),
-               .dac_nids = alc269_dac_nids,
-               .hp_nid = 0x03,
-               .num_channel_mode = ARRAY_SIZE(alc269_modes),
-               .channel_mode = alc269_modes,
-               .input_mux = &alc269_capture_source,
-               .unsol_event = alc269_quanta_fl1_unsol_event,
-               .setup = alc269_quanta_fl1_setup,
-               .init_hook = alc269_quanta_fl1_init_hook,
-       },
-       [ALC269_AMIC] = {
-               .mixers = { alc269_laptop_mixer },
-               .cap_mixer = alc269_laptop_analog_capture_mixer,
-               .init_verbs = { alc269_init_verbs,
-                               alc269_laptop_amic_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc269_dac_nids),
-               .dac_nids = alc269_dac_nids,
-               .hp_nid = 0x03,
-               .num_channel_mode = ARRAY_SIZE(alc269_modes),
-               .channel_mode = alc269_modes,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc269_laptop_amic_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC269_DMIC] = {
-               .mixers = { alc269_laptop_mixer },
-               .cap_mixer = alc269_laptop_digital_capture_mixer,
-               .init_verbs = { alc269_init_verbs,
-                               alc269_laptop_dmic_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc269_dac_nids),
-               .dac_nids = alc269_dac_nids,
-               .hp_nid = 0x03,
-               .num_channel_mode = ARRAY_SIZE(alc269_modes),
-               .channel_mode = alc269_modes,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc269_laptop_dmic_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC269VB_AMIC] = {
-               .mixers = { alc269vb_laptop_mixer },
-               .cap_mixer = alc269vb_laptop_analog_capture_mixer,
-               .init_verbs = { alc269vb_init_verbs,
-                               alc269vb_laptop_amic_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc269_dac_nids),
-               .dac_nids = alc269_dac_nids,
-               .hp_nid = 0x03,
-               .num_channel_mode = ARRAY_SIZE(alc269_modes),
-               .channel_mode = alc269_modes,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc269vb_laptop_amic_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC269VB_DMIC] = {
-               .mixers = { alc269vb_laptop_mixer },
-               .cap_mixer = alc269vb_laptop_digital_capture_mixer,
-               .init_verbs = { alc269vb_init_verbs,
-                               alc269vb_laptop_dmic_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc269_dac_nids),
-               .dac_nids = alc269_dac_nids,
-               .hp_nid = 0x03,
-               .num_channel_mode = ARRAY_SIZE(alc269_modes),
-               .channel_mode = alc269_modes,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc269vb_laptop_dmic_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC269_FUJITSU] = {
-               .mixers = { alc269_fujitsu_mixer },
-               .cap_mixer = alc269_laptop_digital_capture_mixer,
-               .init_verbs = { alc269_init_verbs,
-                               alc269_laptop_dmic_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc269_dac_nids),
-               .dac_nids = alc269_dac_nids,
-               .hp_nid = 0x03,
-               .num_channel_mode = ARRAY_SIZE(alc269_modes),
-               .channel_mode = alc269_modes,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc269_laptop_dmic_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC269_LIFEBOOK] = {
-               .mixers = { alc269_lifebook_mixer },
-               .init_verbs = { alc269_init_verbs, alc269_lifebook_verbs },
-               .num_dacs = ARRAY_SIZE(alc269_dac_nids),
-               .dac_nids = alc269_dac_nids,
-               .hp_nid = 0x03,
-               .num_channel_mode = ARRAY_SIZE(alc269_modes),
-               .channel_mode = alc269_modes,
-               .input_mux = &alc269_capture_source,
-               .unsol_event = alc269_lifebook_unsol_event,
-               .setup = alc269_lifebook_setup,
-               .init_hook = alc269_lifebook_init_hook,
-       },
-       [ALC271_ACER] = {
-               .mixers = { alc269_asus_mixer },
-               .cap_mixer = alc269vb_laptop_digital_capture_mixer,
-               .init_verbs = { alc269_init_verbs, alc271_acer_dmic_verbs },
-               .num_dacs = ARRAY_SIZE(alc269_dac_nids),
-               .dac_nids = alc269_dac_nids,
-               .adc_nids = alc262_dmic_adc_nids,
-               .num_adc_nids = ARRAY_SIZE(alc262_dmic_adc_nids),
-               .capsrc_nids = alc262_dmic_capsrc_nids,
-               .num_channel_mode = ARRAY_SIZE(alc269_modes),
-               .channel_mode = alc269_modes,
-               .input_mux = &alc269_capture_source,
-               .dig_out_nid = ALC880_DIGOUT_NID,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc269vb_laptop_dmic_setup,
-               .init_hook = alc_inithook,
-       },
-};
-
diff --git a/sound/pci/hda/alc662_quirks.c b/sound/pci/hda/alc662_quirks.c
deleted file mode 100644 (file)
index e69a6ea..0000000
+++ /dev/null
@@ -1,1408 +0,0 @@
-/*
- * ALC662/ALC663/ALC665/ALC670 quirk models
- * included by patch_realtek.c
- */
-
-/* ALC662 models */
-enum {
-       ALC662_AUTO,
-       ALC662_3ST_2ch_DIG,
-       ALC662_3ST_6ch_DIG,
-       ALC662_3ST_6ch,
-       ALC662_5ST_DIG,
-       ALC662_LENOVO_101E,
-       ALC662_ASUS_EEEPC_P701,
-       ALC662_ASUS_EEEPC_EP20,
-       ALC663_ASUS_M51VA,
-       ALC663_ASUS_G71V,
-       ALC663_ASUS_H13,
-       ALC663_ASUS_G50V,
-       ALC662_ECS,
-       ALC663_ASUS_MODE1,
-       ALC662_ASUS_MODE2,
-       ALC663_ASUS_MODE3,
-       ALC663_ASUS_MODE4,
-       ALC663_ASUS_MODE5,
-       ALC663_ASUS_MODE6,
-       ALC663_ASUS_MODE7,
-       ALC663_ASUS_MODE8,
-       ALC272_DELL,
-       ALC272_DELL_ZM1,
-       ALC272_SAMSUNG_NC10,
-       ALC662_MODEL_LAST,
-};
-
-#define ALC662_DIGOUT_NID      0x06
-#define ALC662_DIGIN_NID       0x0a
-
-static const hda_nid_t alc662_dac_nids[3] = {
-       /* front, rear, clfe */
-       0x02, 0x03, 0x04
-};
-
-static const hda_nid_t alc272_dac_nids[2] = {
-       0x02, 0x03
-};
-
-static const hda_nid_t alc662_adc_nids[2] = {
-       /* ADC1-2 */
-       0x09, 0x08
-};
-
-static const hda_nid_t alc272_adc_nids[1] = {
-       /* ADC1-2 */
-       0x08,
-};
-
-static const hda_nid_t alc662_capsrc_nids[2] = { 0x22, 0x23 };
-static const hda_nid_t alc272_capsrc_nids[1] = { 0x23 };
-
-
-/* input MUX */
-/* FIXME: should be a matrix-type input source selection */
-static const struct hda_input_mux alc662_capture_source = {
-       .num_items = 4,
-       .items = {
-               { "Mic", 0x0 },
-               { "Front Mic", 0x1 },
-               { "Line", 0x2 },
-               { "CD", 0x4 },
-       },
-};
-
-static const struct hda_input_mux alc662_lenovo_101e_capture_source = {
-       .num_items = 2,
-       .items = {
-               { "Mic", 0x1 },
-               { "Line", 0x2 },
-       },
-};
-
-static const struct hda_input_mux alc663_capture_source = {
-       .num_items = 3,
-       .items = {
-               { "Mic", 0x0 },
-               { "Front Mic", 0x1 },
-               { "Line", 0x2 },
-       },
-};
-
-#if 0 /* set to 1 for testing other input sources below */
-static const struct hda_input_mux alc272_nc10_capture_source = {
-       .num_items = 16,
-       .items = {
-               { "Autoselect Mic", 0x0 },
-               { "Internal Mic", 0x1 },
-               { "In-0x02", 0x2 },
-               { "In-0x03", 0x3 },
-               { "In-0x04", 0x4 },
-               { "In-0x05", 0x5 },
-               { "In-0x06", 0x6 },
-               { "In-0x07", 0x7 },
-               { "In-0x08", 0x8 },
-               { "In-0x09", 0x9 },
-               { "In-0x0a", 0x0a },
-               { "In-0x0b", 0x0b },
-               { "In-0x0c", 0x0c },
-               { "In-0x0d", 0x0d },
-               { "In-0x0e", 0x0e },
-               { "In-0x0f", 0x0f },
-       },
-};
-#endif
-
-/*
- * 2ch mode
- */
-static const struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
-       { 2, NULL }
-};
-
-/*
- * 2ch mode
- */
-static const struct hda_verb alc662_3ST_ch2_init[] = {
-       { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
-       { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
-       { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
-       { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
-       { } /* end */
-};
-
-/*
- * 6ch mode
- */
-static const struct hda_verb alc662_3ST_ch6_init[] = {
-       { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
-       { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
-       { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
-       { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
-       { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
-       { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
-       { } /* end */
-};
-
-static const struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
-       { 2, alc662_3ST_ch2_init },
-       { 6, alc662_3ST_ch6_init },
-};
-
-/*
- * 2ch mode
- */
-static const struct hda_verb alc662_sixstack_ch6_init[] = {
-       { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
-       { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
-       { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
-       { } /* end */
-};
-
-/*
- * 6ch mode
- */
-static const struct hda_verb alc662_sixstack_ch8_init[] = {
-       { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
-       { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
-       { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
-       { } /* end */
-};
-
-static const struct hda_channel_mode alc662_5stack_modes[2] = {
-       { 2, alc662_sixstack_ch6_init },
-       { 6, alc662_sixstack_ch8_init },
-};
-
-/* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
- *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
- */
-
-static const struct snd_kcontrol_new alc662_base_mixer[] = {
-       /* output mixer control */
-       HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
-
-       /*Input mixer control */
-       HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
-       HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
-       HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
-       HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
-       HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
-       { } /* end */
-};
-
-static const struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
-       HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
-       HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
-       HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
-       HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
-       HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
-       { } /* end */
-};
-
-static const struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
-       HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
-       HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
-       HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
-       HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
-       HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
-       { } /* end */
-};
-
-static const struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
-       HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
-       HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
-       HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
-       HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
-       HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
-       { } /* end */
-};
-
-static const struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
-       HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
-       ALC262_HIPPO_MASTER_SWITCH,
-
-       HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
-
-       HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
-       HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
-       { } /* end */
-};
-
-static const struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
-       ALC262_HIPPO_MASTER_SWITCH,
-       HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
-       HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
-       HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
-       HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
-       { } /* end */
-};
-
-static const struct hda_bind_ctls alc663_asus_bind_master_vol = {
-       .ops = &snd_hda_bind_vol,
-       .values = {
-               HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
-               HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
-               0
-       },
-};
-
-static const struct hda_bind_ctls alc663_asus_one_bind_switch = {
-       .ops = &snd_hda_bind_sw,
-       .values = {
-               HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
-               HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
-               0
-       },
-};
-
-static const struct snd_kcontrol_new alc663_m51va_mixer[] = {
-       HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
-       HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
-       { } /* end */
-};
-
-static const struct hda_bind_ctls alc663_asus_tree_bind_switch = {
-       .ops = &snd_hda_bind_sw,
-       .values = {
-               HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
-               HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
-               HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
-               0
-       },
-};
-
-static const struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
-       HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
-       HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
-       HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
-
-       { } /* end */
-};
-
-static const struct hda_bind_ctls alc663_asus_four_bind_switch = {
-       .ops = &snd_hda_bind_sw,
-       .values = {
-               HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
-               HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
-               HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
-               0
-       },
-};
-
-static const struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
-       HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
-       HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
-       HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
-       { } /* end */
-};
-
-static const struct snd_kcontrol_new alc662_1bjd_mixer[] = {
-       HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
-       HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
-       { } /* end */
-};
-
-static const struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
-       .ops = &snd_hda_bind_vol,
-       .values = {
-               HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
-               HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
-               0
-       },
-};
-
-static const struct hda_bind_ctls alc663_asus_two_bind_switch = {
-       .ops = &snd_hda_bind_sw,
-       .values = {
-               HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
-               HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
-               0
-       },
-};
-
-static const struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
-       HDA_BIND_VOL("Master Playback Volume",
-                               &alc663_asus_two_bind_master_vol),
-       HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
-       HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
-       { } /* end */
-};
-
-static const struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
-       HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
-       HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
-       HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
-       { } /* end */
-};
-
-static const struct snd_kcontrol_new alc663_g71v_mixer[] = {
-       HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
-
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
-       HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
-       { } /* end */
-};
-
-static const struct snd_kcontrol_new alc663_g50v_mixer[] = {
-       HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
-
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
-       HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
-       HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
-       HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
-       { } /* end */
-};
-
-static const struct hda_bind_ctls alc663_asus_mode7_8_all_bind_switch = {
-       .ops = &snd_hda_bind_sw,
-       .values = {
-               HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
-               HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
-               HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
-               HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
-               HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
-               0
-       },
-};
-
-static const struct hda_bind_ctls alc663_asus_mode7_8_sp_bind_switch = {
-       .ops = &snd_hda_bind_sw,
-       .values = {
-               HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
-               HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
-               0
-       },
-};
-
-static const struct snd_kcontrol_new alc663_mode7_mixer[] = {
-       HDA_BIND_SW("Master Playback Switch", &alc663_asus_mode7_8_all_bind_switch),
-       HDA_BIND_VOL("Speaker Playback Volume", &alc663_asus_bind_master_vol),
-       HDA_BIND_SW("Speaker Playback Switch", &alc663_asus_mode7_8_sp_bind_switch),
-       HDA_CODEC_MUTE("Headphone1 Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Headphone2 Playback Switch", 0x21, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("IntMic Playback Volume", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("IntMic Playback Switch", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
-       { } /* end */
-};
-
-static const struct snd_kcontrol_new alc663_mode8_mixer[] = {
-       HDA_BIND_SW("Master Playback Switch", &alc663_asus_mode7_8_all_bind_switch),
-       HDA_BIND_VOL("Speaker Playback Volume", &alc663_asus_bind_master_vol),
-       HDA_BIND_SW("Speaker Playback Switch", &alc663_asus_mode7_8_sp_bind_switch),
-       HDA_CODEC_MUTE("Headphone1 Playback Switch", 0x15, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Headphone2 Playback Switch", 0x21, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
-       { } /* end */
-};
-
-
-static const struct snd_kcontrol_new alc662_chmode_mixer[] = {
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "Channel Mode",
-               .info = alc_ch_mode_info,
-               .get = alc_ch_mode_get,
-               .put = alc_ch_mode_put,
-       },
-       { } /* end */
-};
-
-static const struct hda_verb alc662_init_verbs[] = {
-       /* ADC: mute amp left and right */
-       {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
-       {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
-
-       {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-
-       /* Front Pin: output 0 (0x0c) */
-       {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
-       {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-
-       /* Rear Pin: output 1 (0x0d) */
-       {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-
-       /* CLFE Pin: output 2 (0x0e) */
-       {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
-       {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-
-       /* Mic (rear) pin: input vref at 80% */
-       {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
-       {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
-       /* Front Mic pin: input vref at 80% */
-       {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
-       {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
-       /* Line In pin: input */
-       {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
-       /* Line-2 In: Headphone output (output 0 - 0x0c) */
-       {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
-       /* CD pin widget for input */
-       {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-
-       /* FIXME: use matrix-type input source selection */
-       /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
-       /* Input mixer */
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-
-       { }
-};
-
-static const struct hda_verb alc662_eapd_init_verbs[] = {
-       /* always trun on EAPD */
-       {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
-       {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
-       { }
-};
-
-static const struct hda_verb alc662_sue_init_verbs[] = {
-       {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC_FRONT_EVENT},
-       {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC_HP_EVENT},
-       {}
-};
-
-static const struct hda_verb alc662_eeepc_sue_init_verbs[] = {
-       {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
-       {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
-       {}
-};
-
-/* Set Unsolicited Event*/
-static const struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
-       {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
-       {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
-       {}
-};
-
-static const struct hda_verb alc663_m51va_init_verbs[] = {
-       {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
-       {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
-       {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
-       {}
-};
-
-static const struct hda_verb alc663_21jd_amic_init_verbs[] = {
-       {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
-       {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
-       {}
-};
-
-static const struct hda_verb alc662_1bjd_amic_init_verbs[] = {
-       {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
-       {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
-       {}
-};
-
-static const struct hda_verb alc663_15jd_amic_init_verbs[] = {
-       {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
-       {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
-       {}
-};
-
-static const struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
-       {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x21, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
-       {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
-       {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
-       {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
-       {}
-};
-
-static const struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
-       {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
-       {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
-       {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
-       {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
-       {}
-};
-
-static const struct hda_verb alc663_g71v_init_verbs[] = {
-       {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
-       /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
-
-       {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
-
-       {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC_FRONT_EVENT},
-       {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC_MIC_EVENT},
-       {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC_HP_EVENT},
-       {}
-};
-
-static const struct hda_verb alc663_g50v_init_verbs[] = {
-       {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
-
-       {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
-       {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
-       {}
-};
-
-static const struct hda_verb alc662_ecs_init_verbs[] = {
-       {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
-       {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
-       {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
-       {}
-};
-
-static const struct hda_verb alc272_dell_zm1_init_verbs[] = {
-       {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
-       {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
-       {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
-       {}
-};
-
-static const struct hda_verb alc272_dell_init_verbs[] = {
-       {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
-       {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
-       {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
-       {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
-       {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
-       {}
-};
-
-static const struct hda_verb alc663_mode7_init_verbs[] = {
-       {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
-       {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},
-       {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
-       {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
-       {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
-       {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
-       {}
-};
-
-static const struct hda_verb alc663_mode8_init_verbs[] = {
-       {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
-       {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
-       {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
-       {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
-       {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
-       {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
-       {}
-};
-
-static const struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
-       HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
-       { } /* end */
-};
-
-static const struct snd_kcontrol_new alc272_auto_capture_mixer[] = {
-       HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
-       { } /* end */
-};
-
-static void alc662_lenovo_101e_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-
-       spec->autocfg.hp_pins[0] = 0x1b;
-       spec->autocfg.line_out_pins[0] = 0x14;
-       spec->autocfg.speaker_pins[0] = 0x15;
-       spec->automute = 1;
-       spec->detect_line = 1;
-       spec->automute_lines = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
-}
-
-static void alc662_eeepc_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-
-       alc262_hippo1_setup(codec);
-       spec->ext_mic_pin = 0x18;
-       spec->int_mic_pin = 0x19;
-       spec->auto_mic = 1;
-}
-
-static void alc662_eeepc_ep20_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-
-       spec->autocfg.hp_pins[0] = 0x14;
-       spec->autocfg.speaker_pins[0] = 0x1b;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
-}
-
-static void alc663_m51va_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-       spec->autocfg.hp_pins[0] = 0x21;
-       spec->autocfg.speaker_pins[0] = 0x14;
-       spec->automute_mixer_nid[0] = 0x0c;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_MIXER;
-       spec->ext_mic_pin = 0x18;
-       spec->int_mic_pin = 0x12;
-       spec->auto_mic = 1;
-}
-
-/* ***************** Mode1 ******************************/
-static void alc663_mode1_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-       spec->autocfg.hp_pins[0] = 0x21;
-       spec->autocfg.speaker_pins[0] = 0x14;
-       spec->automute_mixer_nid[0] = 0x0c;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_MIXER;
-       spec->ext_mic_pin = 0x18;
-       spec->int_mic_pin = 0x19;
-       spec->auto_mic = 1;
-}
-
-/* ***************** Mode2 ******************************/
-static void alc662_mode2_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-       spec->autocfg.hp_pins[0] = 0x1b;
-       spec->autocfg.speaker_pins[0] = 0x14;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_PIN;
-       spec->ext_mic_pin = 0x18;
-       spec->int_mic_pin = 0x19;
-       spec->auto_mic = 1;
-}
-
-/* ***************** Mode3 ******************************/
-static void alc663_mode3_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-       spec->autocfg.hp_pins[0] = 0x21;
-       spec->autocfg.hp_pins[0] = 0x15;
-       spec->autocfg.speaker_pins[0] = 0x14;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_PIN;
-       spec->ext_mic_pin = 0x18;
-       spec->int_mic_pin = 0x19;
-       spec->auto_mic = 1;
-}
-
-/* ***************** Mode4 ******************************/
-static void alc663_mode4_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-       spec->autocfg.hp_pins[0] = 0x21;
-       spec->autocfg.speaker_pins[0] = 0x14;
-       spec->autocfg.speaker_pins[1] = 0x16;
-       spec->automute_mixer_nid[0] = 0x0c;
-       spec->automute_mixer_nid[1] = 0x0e;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_MIXER;
-       spec->ext_mic_pin = 0x18;
-       spec->int_mic_pin = 0x19;
-       spec->auto_mic = 1;
-}
-
-/* ***************** Mode5 ******************************/
-static void alc663_mode5_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-       spec->autocfg.hp_pins[0] = 0x15;
-       spec->autocfg.speaker_pins[0] = 0x14;
-       spec->autocfg.speaker_pins[1] = 0x16;
-       spec->automute_mixer_nid[0] = 0x0c;
-       spec->automute_mixer_nid[1] = 0x0e;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_MIXER;
-       spec->ext_mic_pin = 0x18;
-       spec->int_mic_pin = 0x19;
-       spec->auto_mic = 1;
-}
-
-/* ***************** Mode6 ******************************/
-static void alc663_mode6_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-       spec->autocfg.hp_pins[0] = 0x1b;
-       spec->autocfg.hp_pins[0] = 0x15;
-       spec->autocfg.speaker_pins[0] = 0x14;
-       spec->automute_mixer_nid[0] = 0x0c;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_MIXER;
-       spec->ext_mic_pin = 0x18;
-       spec->int_mic_pin = 0x19;
-       spec->auto_mic = 1;
-}
-
-/* ***************** Mode7 ******************************/
-static void alc663_mode7_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-       spec->autocfg.hp_pins[0] = 0x1b;
-       spec->autocfg.hp_pins[0] = 0x21;
-       spec->autocfg.speaker_pins[0] = 0x14;
-       spec->autocfg.speaker_pins[0] = 0x17;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_PIN;
-       spec->ext_mic_pin = 0x18;
-       spec->int_mic_pin = 0x19;
-       spec->auto_mic = 1;
-}
-
-/* ***************** Mode8 ******************************/
-static void alc663_mode8_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-       spec->autocfg.hp_pins[0] = 0x21;
-       spec->autocfg.hp_pins[1] = 0x15;
-       spec->autocfg.speaker_pins[0] = 0x14;
-       spec->autocfg.speaker_pins[0] = 0x17;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_PIN;
-       spec->ext_mic_pin = 0x18;
-       spec->int_mic_pin = 0x12;
-       spec->auto_mic = 1;
-}
-
-static void alc663_g71v_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-       spec->autocfg.hp_pins[0] = 0x21;
-       spec->autocfg.line_out_pins[0] = 0x15;
-       spec->autocfg.speaker_pins[0] = 0x14;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
-       spec->detect_line = 1;
-       spec->automute_lines = 1;
-       spec->ext_mic_pin = 0x18;
-       spec->int_mic_pin = 0x12;
-       spec->auto_mic = 1;
-}
-
-#define alc663_g50v_setup      alc663_m51va_setup
-
-static const struct snd_kcontrol_new alc662_ecs_mixer[] = {
-       HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
-       ALC262_HIPPO_MASTER_SWITCH,
-
-       HDA_CODEC_VOLUME("Mic/LineIn Boost Volume", 0x18, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
-
-       HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
-       HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
-       { } /* end */
-};
-
-static const struct snd_kcontrol_new alc272_nc10_mixer[] = {
-       /* Master Playback automatically created from Speaker and Headphone */
-       HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
-
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
-
-       HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
-       HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
-       HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
-       { } /* end */
-};
-
-
-/*
- * configuration and preset
- */
-static const char * const alc662_models[ALC662_MODEL_LAST] = {
-       [ALC662_3ST_2ch_DIG]    = "3stack-dig",
-       [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
-       [ALC662_3ST_6ch]        = "3stack-6ch",
-       [ALC662_5ST_DIG]        = "5stack-dig",
-       [ALC662_LENOVO_101E]    = "lenovo-101e",
-       [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
-       [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
-       [ALC662_ECS] = "ecs",
-       [ALC663_ASUS_M51VA] = "m51va",
-       [ALC663_ASUS_G71V] = "g71v",
-       [ALC663_ASUS_H13] = "h13",
-       [ALC663_ASUS_G50V] = "g50v",
-       [ALC663_ASUS_MODE1] = "asus-mode1",
-       [ALC662_ASUS_MODE2] = "asus-mode2",
-       [ALC663_ASUS_MODE3] = "asus-mode3",
-       [ALC663_ASUS_MODE4] = "asus-mode4",
-       [ALC663_ASUS_MODE5] = "asus-mode5",
-       [ALC663_ASUS_MODE6] = "asus-mode6",
-       [ALC663_ASUS_MODE7] = "asus-mode7",
-       [ALC663_ASUS_MODE8] = "asus-mode8",
-       [ALC272_DELL]           = "dell",
-       [ALC272_DELL_ZM1]       = "dell-zm1",
-       [ALC272_SAMSUNG_NC10]   = "samsung-nc10",
-       [ALC662_AUTO]           = "auto",
-};
-
-static const struct snd_pci_quirk alc662_cfg_tbl[] = {
-       SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
-       SND_PCI_QUIRK(0x1028, 0x02d6, "DELL", ALC272_DELL),
-       SND_PCI_QUIRK(0x1028, 0x02f4, "DELL ZM1", ALC272_DELL_ZM1),
-       SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
-       SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
-       SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC663_ASUS_MODE1),
-       SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
-       SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
-       SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
-       SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
-       SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC663_ASUS_MODE1),
-       SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC663_ASUS_MODE1),
-       SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
-       SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC663_ASUS_MODE7),
-       SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC663_ASUS_MODE7),
-       SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC663_ASUS_MODE8),
-       SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC663_ASUS_MODE3),
-       SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC663_ASUS_MODE1),
-       SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
-       SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_ASUS_MODE2),
-       SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC663_ASUS_MODE1),
-       SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
-       SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
-       SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
-       SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
-       SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC663_ASUS_MODE1),
-       SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC663_ASUS_MODE3),
-       SND_PCI_QUIRK(0x1043, 0x17c3, "ASUS UX20", ALC663_ASUS_M51VA),
-       SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_ASUS_MODE2),
-       SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
-       SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
-       SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
-       SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
-       SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC663_ASUS_MODE1),
-       SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
-       SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
-       SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
-       /*SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),*/
-       SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
-       SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
-       SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC663_ASUS_MODE1),
-       SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC663_ASUS_MODE1),
-       SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC663_ASUS_MODE1),
-       SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC663_ASUS_MODE1),
-       SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
-       SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
-       SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
-       SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC663_ASUS_MODE1),
-       SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
-       SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
-       SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC663_ASUS_MODE1),
-       SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
-       SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
-       /*SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),*/
-       SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
-       SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
-       SND_PCI_QUIRK(0x1043, 0x19d3, "ASUS NB", ALC663_ASUS_M51VA),
-       SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
-       SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
-       SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
-       SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
-       SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
-       SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
-       SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
-                     ALC662_3ST_6ch_DIG),
-       SND_PCI_QUIRK(0x1179, 0xff6e, "Toshiba NB20x", ALC662_AUTO),
-       SND_PCI_QUIRK(0x144d, 0xca00, "Samsung NC10", ALC272_SAMSUNG_NC10),
-       SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
-                     ALC662_3ST_6ch_DIG),
-       SND_PCI_QUIRK(0x152d, 0x2304, "Quanta WH1", ALC663_ASUS_H13),
-       SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
-       SND_PCI_QUIRK(0x1631, 0xc10c, "PB RS65", ALC663_ASUS_M51VA),
-       SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
-       SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
-                                       ALC662_3ST_6ch_DIG),
-       SND_PCI_QUIRK_MASK(0x1854, 0xf000, 0x2000, "ASUS H13-200x",
-                          ALC663_ASUS_H13),
-       SND_PCI_QUIRK(0x1991, 0x5628, "Ordissimo EVE", ALC662_LENOVO_101E),
-       {}
-};
-
-static const struct alc_config_preset alc662_presets[] = {
-       [ALC662_3ST_2ch_DIG] = {
-               .mixers = { alc662_3ST_2ch_mixer },
-               .init_verbs = { alc662_init_verbs, alc662_eapd_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc662_dac_nids),
-               .dac_nids = alc662_dac_nids,
-               .dig_out_nid = ALC662_DIGOUT_NID,
-               .dig_in_nid = ALC662_DIGIN_NID,
-               .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
-               .channel_mode = alc662_3ST_2ch_modes,
-               .input_mux = &alc662_capture_source,
-       },
-       [ALC662_3ST_6ch_DIG] = {
-               .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
-               .init_verbs = { alc662_init_verbs, alc662_eapd_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc662_dac_nids),
-               .dac_nids = alc662_dac_nids,
-               .dig_out_nid = ALC662_DIGOUT_NID,
-               .dig_in_nid = ALC662_DIGIN_NID,
-               .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
-               .channel_mode = alc662_3ST_6ch_modes,
-               .need_dac_fix = 1,
-               .input_mux = &alc662_capture_source,
-       },
-       [ALC662_3ST_6ch] = {
-               .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
-               .init_verbs = { alc662_init_verbs, alc662_eapd_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc662_dac_nids),
-               .dac_nids = alc662_dac_nids,
-               .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
-               .channel_mode = alc662_3ST_6ch_modes,
-               .need_dac_fix = 1,
-               .input_mux = &alc662_capture_source,
-       },
-       [ALC662_5ST_DIG] = {
-               .mixers = { alc662_base_mixer, alc662_chmode_mixer },
-               .init_verbs = { alc662_init_verbs, alc662_eapd_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc662_dac_nids),
-               .dac_nids = alc662_dac_nids,
-               .dig_out_nid = ALC662_DIGOUT_NID,
-               .dig_in_nid = ALC662_DIGIN_NID,
-               .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
-               .channel_mode = alc662_5stack_modes,
-               .input_mux = &alc662_capture_source,
-       },
-       [ALC662_LENOVO_101E] = {
-               .mixers = { alc662_lenovo_101e_mixer },
-               .init_verbs = { alc662_init_verbs,
-                               alc662_eapd_init_verbs,
-                               alc662_sue_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc662_dac_nids),
-               .dac_nids = alc662_dac_nids,
-               .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
-               .channel_mode = alc662_3ST_2ch_modes,
-               .input_mux = &alc662_lenovo_101e_capture_source,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc662_lenovo_101e_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC662_ASUS_EEEPC_P701] = {
-               .mixers = { alc662_eeepc_p701_mixer },
-               .init_verbs = { alc662_init_verbs,
-                               alc662_eapd_init_verbs,
-                               alc662_eeepc_sue_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc662_dac_nids),
-               .dac_nids = alc662_dac_nids,
-               .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
-               .channel_mode = alc662_3ST_2ch_modes,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc662_eeepc_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC662_ASUS_EEEPC_EP20] = {
-               .mixers = { alc662_eeepc_ep20_mixer,
-                           alc662_chmode_mixer },
-               .init_verbs = { alc662_init_verbs,
-                               alc662_eapd_init_verbs,
-                               alc662_eeepc_ep20_sue_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc662_dac_nids),
-               .dac_nids = alc662_dac_nids,
-               .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
-               .channel_mode = alc662_3ST_6ch_modes,
-               .input_mux = &alc662_lenovo_101e_capture_source,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc662_eeepc_ep20_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC662_ECS] = {
-               .mixers = { alc662_ecs_mixer },
-               .init_verbs = { alc662_init_verbs,
-                               alc662_eapd_init_verbs,
-                               alc662_ecs_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc662_dac_nids),
-               .dac_nids = alc662_dac_nids,
-               .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
-               .channel_mode = alc662_3ST_2ch_modes,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc662_eeepc_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC663_ASUS_M51VA] = {
-               .mixers = { alc663_m51va_mixer },
-               .init_verbs = { alc662_init_verbs,
-                               alc662_eapd_init_verbs,
-                               alc663_m51va_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc662_dac_nids),
-               .dac_nids = alc662_dac_nids,
-               .dig_out_nid = ALC662_DIGOUT_NID,
-               .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
-               .channel_mode = alc662_3ST_2ch_modes,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc663_m51va_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC663_ASUS_G71V] = {
-               .mixers = { alc663_g71v_mixer },
-               .init_verbs = { alc662_init_verbs,
-                               alc662_eapd_init_verbs,
-                               alc663_g71v_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc662_dac_nids),
-               .dac_nids = alc662_dac_nids,
-               .dig_out_nid = ALC662_DIGOUT_NID,
-               .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
-               .channel_mode = alc662_3ST_2ch_modes,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc663_g71v_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC663_ASUS_H13] = {
-               .mixers = { alc663_m51va_mixer },
-               .init_verbs = { alc662_init_verbs,
-                               alc662_eapd_init_verbs,
-                               alc663_m51va_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc662_dac_nids),
-               .dac_nids = alc662_dac_nids,
-               .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
-               .channel_mode = alc662_3ST_2ch_modes,
-               .setup = alc663_m51va_setup,
-               .unsol_event = alc_sku_unsol_event,
-               .init_hook = alc_inithook,
-       },
-       [ALC663_ASUS_G50V] = {
-               .mixers = { alc663_g50v_mixer },
-               .init_verbs = { alc662_init_verbs,
-                               alc662_eapd_init_verbs,
-                               alc663_g50v_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc662_dac_nids),
-               .dac_nids = alc662_dac_nids,
-               .dig_out_nid = ALC662_DIGOUT_NID,
-               .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
-               .channel_mode = alc662_3ST_6ch_modes,
-               .input_mux = &alc663_capture_source,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc663_g50v_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC663_ASUS_MODE1] = {
-               .mixers = { alc663_m51va_mixer },
-               .cap_mixer = alc662_auto_capture_mixer,
-               .init_verbs = { alc662_init_verbs,
-                               alc662_eapd_init_verbs,
-                               alc663_21jd_amic_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc662_dac_nids),
-               .hp_nid = 0x03,
-               .dac_nids = alc662_dac_nids,
-               .dig_out_nid = ALC662_DIGOUT_NID,
-               .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
-               .channel_mode = alc662_3ST_2ch_modes,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc663_mode1_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC662_ASUS_MODE2] = {
-               .mixers = { alc662_1bjd_mixer },
-               .cap_mixer = alc662_auto_capture_mixer,
-               .init_verbs = { alc662_init_verbs,
-                               alc662_eapd_init_verbs,
-                               alc662_1bjd_amic_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc662_dac_nids),
-               .dac_nids = alc662_dac_nids,
-               .dig_out_nid = ALC662_DIGOUT_NID,
-               .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
-               .channel_mode = alc662_3ST_2ch_modes,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc662_mode2_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC663_ASUS_MODE3] = {
-               .mixers = { alc663_two_hp_m1_mixer },
-               .cap_mixer = alc662_auto_capture_mixer,
-               .init_verbs = { alc662_init_verbs,
-                               alc662_eapd_init_verbs,
-                               alc663_two_hp_amic_m1_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc662_dac_nids),
-               .hp_nid = 0x03,
-               .dac_nids = alc662_dac_nids,
-               .dig_out_nid = ALC662_DIGOUT_NID,
-               .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
-               .channel_mode = alc662_3ST_2ch_modes,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc663_mode3_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC663_ASUS_MODE4] = {
-               .mixers = { alc663_asus_21jd_clfe_mixer },
-               .cap_mixer = alc662_auto_capture_mixer,
-               .init_verbs = { alc662_init_verbs,
-                               alc662_eapd_init_verbs,
-                               alc663_21jd_amic_init_verbs},
-               .num_dacs = ARRAY_SIZE(alc662_dac_nids),
-               .hp_nid = 0x03,
-               .dac_nids = alc662_dac_nids,
-               .dig_out_nid = ALC662_DIGOUT_NID,
-               .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
-               .channel_mode = alc662_3ST_2ch_modes,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc663_mode4_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC663_ASUS_MODE5] = {
-               .mixers = { alc663_asus_15jd_clfe_mixer },
-               .cap_mixer = alc662_auto_capture_mixer,
-               .init_verbs = { alc662_init_verbs,
-                               alc662_eapd_init_verbs,
-                               alc663_15jd_amic_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc662_dac_nids),
-               .hp_nid = 0x03,
-               .dac_nids = alc662_dac_nids,
-               .dig_out_nid = ALC662_DIGOUT_NID,
-               .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
-               .channel_mode = alc662_3ST_2ch_modes,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc663_mode5_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC663_ASUS_MODE6] = {
-               .mixers = { alc663_two_hp_m2_mixer },
-               .cap_mixer = alc662_auto_capture_mixer,
-               .init_verbs = { alc662_init_verbs,
-                               alc662_eapd_init_verbs,
-                               alc663_two_hp_amic_m2_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc662_dac_nids),
-               .hp_nid = 0x03,
-               .dac_nids = alc662_dac_nids,
-               .dig_out_nid = ALC662_DIGOUT_NID,
-               .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
-               .channel_mode = alc662_3ST_2ch_modes,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc663_mode6_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC663_ASUS_MODE7] = {
-               .mixers = { alc663_mode7_mixer },
-               .cap_mixer = alc662_auto_capture_mixer,
-               .init_verbs = { alc662_init_verbs,
-                               alc662_eapd_init_verbs,
-                               alc663_mode7_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc662_dac_nids),
-               .hp_nid = 0x03,
-               .dac_nids = alc662_dac_nids,
-               .dig_out_nid = ALC662_DIGOUT_NID,
-               .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
-               .channel_mode = alc662_3ST_2ch_modes,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc663_mode7_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC663_ASUS_MODE8] = {
-               .mixers = { alc663_mode8_mixer },
-               .cap_mixer = alc662_auto_capture_mixer,
-               .init_verbs = { alc662_init_verbs,
-                               alc662_eapd_init_verbs,
-                               alc663_mode8_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc662_dac_nids),
-               .hp_nid = 0x03,
-               .dac_nids = alc662_dac_nids,
-               .dig_out_nid = ALC662_DIGOUT_NID,
-               .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
-               .channel_mode = alc662_3ST_2ch_modes,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc663_mode8_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC272_DELL] = {
-               .mixers = { alc663_m51va_mixer },
-               .cap_mixer = alc272_auto_capture_mixer,
-               .init_verbs = { alc662_init_verbs,
-                               alc662_eapd_init_verbs,
-                               alc272_dell_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc272_dac_nids),
-               .dac_nids = alc272_dac_nids,
-               .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
-               .adc_nids = alc272_adc_nids,
-               .num_adc_nids = ARRAY_SIZE(alc272_adc_nids),
-               .capsrc_nids = alc272_capsrc_nids,
-               .channel_mode = alc662_3ST_2ch_modes,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc663_m51va_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC272_DELL_ZM1] = {
-               .mixers = { alc663_m51va_mixer },
-               .cap_mixer = alc662_auto_capture_mixer,
-               .init_verbs = { alc662_init_verbs,
-                               alc662_eapd_init_verbs,
-                               alc272_dell_zm1_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc272_dac_nids),
-               .dac_nids = alc272_dac_nids,
-               .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
-               .adc_nids = alc662_adc_nids,
-               .num_adc_nids = 1,
-               .capsrc_nids = alc662_capsrc_nids,
-               .channel_mode = alc662_3ST_2ch_modes,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc663_m51va_setup,
-               .init_hook = alc_inithook,
-       },
-       [ALC272_SAMSUNG_NC10] = {
-               .mixers = { alc272_nc10_mixer },
-               .init_verbs = { alc662_init_verbs,
-                               alc662_eapd_init_verbs,
-                               alc663_21jd_amic_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc272_dac_nids),
-               .dac_nids = alc272_dac_nids,
-               .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
-               .channel_mode = alc662_3ST_2ch_modes,
-               /*.input_mux = &alc272_nc10_capture_source,*/
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc663_mode4_setup,
-               .init_hook = alc_inithook,
-       },
-};
-
-
diff --git a/sound/pci/hda/alc680_quirks.c b/sound/pci/hda/alc680_quirks.c
deleted file mode 100644 (file)
index 0eeb227..0000000
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * ALC680 quirk models
- * included by patch_realtek.c
- */
-
-/* ALC680 models */
-enum {
-       ALC680_AUTO,
-       ALC680_BASE,
-       ALC680_MODEL_LAST,
-};
-
-#define ALC680_DIGIN_NID       ALC880_DIGIN_NID
-#define ALC680_DIGOUT_NID      ALC880_DIGOUT_NID
-#define alc680_modes           alc260_modes
-
-static const hda_nid_t alc680_dac_nids[3] = {
-       /* Lout1, Lout2, hp */
-       0x02, 0x03, 0x04
-};
-
-static const hda_nid_t alc680_adc_nids[3] = {
-       /* ADC0-2 */
-       /* DMIC, MIC, Line-in*/
-       0x07, 0x08, 0x09
-};
-
-/*
- * Analog capture ADC cgange
- */
-static hda_nid_t alc680_get_cur_adc(struct hda_codec *codec)
-{
-       static hda_nid_t pins[] = {0x18, 0x19};
-       static hda_nid_t adcs[] = {0x08, 0x09};
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(pins); i++) {
-               if (!is_jack_detectable(codec, pins[i]))
-                       continue;
-               if (snd_hda_jack_detect(codec, pins[i]))
-                       return adcs[i];
-       }
-       return 0x07;
-}
-
-static void alc680_rec_autoswitch(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-       hda_nid_t nid = alc680_get_cur_adc(codec);
-       if (spec->cur_adc && nid != spec->cur_adc) {
-               __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
-               spec->cur_adc = nid;
-               snd_hda_codec_setup_stream(codec, nid,
-                                          spec->cur_adc_stream_tag, 0,
-                                          spec->cur_adc_format);
-       }
-}
-
-static int alc680_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
-                                     struct hda_codec *codec,
-                                     unsigned int stream_tag,
-                                     unsigned int format,
-                                     struct snd_pcm_substream *substream)
-{
-       struct alc_spec *spec = codec->spec;
-       hda_nid_t nid = alc680_get_cur_adc(codec);
-
-       spec->cur_adc = nid;
-       spec->cur_adc_stream_tag = stream_tag;
-       spec->cur_adc_format = format;
-       snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
-       return 0;
-}
-
-static int alc680_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
-                                     struct hda_codec *codec,
-                                     struct snd_pcm_substream *substream)
-{
-       struct alc_spec *spec = codec->spec;
-       snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
-       spec->cur_adc = 0;
-       return 0;
-}
-
-static const struct hda_pcm_stream alc680_pcm_analog_auto_capture = {
-       .substreams = 1, /* can be overridden */
-       .channels_min = 2,
-       .channels_max = 2,
-       /* NID is set in alc_build_pcms */
-       .ops = {
-               .prepare = alc680_capture_pcm_prepare,
-               .cleanup = alc680_capture_pcm_cleanup
-       },
-};
-
-static const struct snd_kcontrol_new alc680_base_mixer[] = {
-       /* output mixer control */
-       HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Headphone Playback Volume", 0x4, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x16, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x12, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Line In Boost Volume", 0x19, 0, HDA_INPUT),
-       { }
-};
-
-static const struct hda_bind_ctls alc680_bind_cap_vol = {
-       .ops = &snd_hda_bind_vol,
-       .values = {
-               HDA_COMPOSE_AMP_VAL(0x07, 3, 0, HDA_INPUT),
-               HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
-               HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
-               0
-       },
-};
-
-static const struct hda_bind_ctls alc680_bind_cap_switch = {
-       .ops = &snd_hda_bind_sw,
-       .values = {
-               HDA_COMPOSE_AMP_VAL(0x07, 3, 0, HDA_INPUT),
-               HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
-               HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
-               0
-       },
-};
-
-static const struct snd_kcontrol_new alc680_master_capture_mixer[] = {
-       HDA_BIND_VOL("Capture Volume", &alc680_bind_cap_vol),
-       HDA_BIND_SW("Capture Switch", &alc680_bind_cap_switch),
-       { } /* end */
-};
-
-/*
- * generic initialization of ADC, input mixers and output mixers
- */
-static const struct hda_verb alc680_init_verbs[] = {
-       {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-
-       {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
-       {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
-       {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
-       {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-
-       {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
-       {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
-       {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
-       {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
-
-       {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_HP_EVENT   | AC_USRSP_EN},
-       {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_MIC_EVENT  | AC_USRSP_EN},
-       {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_MIC_EVENT  | AC_USRSP_EN},
-
-       { }
-};
-
-/* toggle speaker-output according to the hp-jack state */
-static void alc680_base_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-
-       spec->autocfg.hp_pins[0] = 0x16;
-       spec->autocfg.speaker_pins[0] = 0x14;
-       spec->autocfg.speaker_pins[1] = 0x15;
-       spec->autocfg.num_inputs = 2;
-       spec->autocfg.inputs[0].pin = 0x18;
-       spec->autocfg.inputs[0].type = AUTO_PIN_MIC;
-       spec->autocfg.inputs[1].pin = 0x19;
-       spec->autocfg.inputs[1].type = AUTO_PIN_LINE_IN;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
-}
-
-static void alc680_unsol_event(struct hda_codec *codec,
-                                          unsigned int res)
-{
-       if ((res >> 26) == ALC_HP_EVENT)
-               alc_hp_automute(codec);
-       if ((res >> 26) == ALC_MIC_EVENT)
-               alc680_rec_autoswitch(codec);
-}
-
-static void alc680_inithook(struct hda_codec *codec)
-{
-       alc_hp_automute(codec);
-       alc680_rec_autoswitch(codec);
-}
-
-/*
- * configuration and preset
- */
-static const char * const alc680_models[ALC680_MODEL_LAST] = {
-       [ALC680_BASE]           = "base",
-       [ALC680_AUTO]           = "auto",
-};
-
-static const struct snd_pci_quirk alc680_cfg_tbl[] = {
-       SND_PCI_QUIRK(0x1043, 0x12f3, "ASUS NX90", ALC680_BASE),
-       {}
-};
-
-static const struct alc_config_preset alc680_presets[] = {
-       [ALC680_BASE] = {
-               .mixers = { alc680_base_mixer },
-               .cap_mixer =  alc680_master_capture_mixer,
-               .init_verbs = { alc680_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc680_dac_nids),
-               .dac_nids = alc680_dac_nids,
-               .dig_out_nid = ALC680_DIGOUT_NID,
-               .num_channel_mode = ARRAY_SIZE(alc680_modes),
-               .channel_mode = alc680_modes,
-               .unsol_event = alc680_unsol_event,
-               .setup = alc680_base_setup,
-               .init_hook = alc680_inithook,
-
-       },
-};
diff --git a/sound/pci/hda/alc861_quirks.c b/sound/pci/hda/alc861_quirks.c
deleted file mode 100644 (file)
index d719ec6..0000000
+++ /dev/null
@@ -1,725 +0,0 @@
-/*
- * ALC660/ALC861 quirk models
- * included by patch_realtek.c
- */
-
-/* ALC861 models */
-enum {
-       ALC861_AUTO,
-       ALC861_3ST,
-       ALC660_3ST,
-       ALC861_3ST_DIG,
-       ALC861_6ST_DIG,
-       ALC861_UNIWILL_M31,
-       ALC861_TOSHIBA,
-       ALC861_ASUS,
-       ALC861_ASUS_LAPTOP,
-       ALC861_MODEL_LAST,
-};
-
-/*
- *  ALC861 channel source setting (2/6 channel selection for 3-stack)
- */
-
-/*
- * set the path ways for 2 channel output
- * need to set the codec line out and mic 1 pin widgets to inputs
- */
-static const struct hda_verb alc861_threestack_ch2_init[] = {
-       /* set pin widget 1Ah (line in) for input */
-       { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
-       /* set pin widget 18h (mic1/2) for input, for mic also enable
-        * the vref
-        */
-       { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
-
-       { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
-#if 0
-       { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
-       { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
-#endif
-       { } /* end */
-};
-/*
- * 6ch mode
- * need to set the codec line out and mic 1 pin widgets to outputs
- */
-static const struct hda_verb alc861_threestack_ch6_init[] = {
-       /* set pin widget 1Ah (line in) for output (Back Surround)*/
-       { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
-       /* set pin widget 18h (mic1) for output (CLFE)*/
-       { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
-
-       { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
-       { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
-
-       { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
-#if 0
-       { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
-       { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
-#endif
-       { } /* end */
-};
-
-static const struct hda_channel_mode alc861_threestack_modes[2] = {
-       { 2, alc861_threestack_ch2_init },
-       { 6, alc861_threestack_ch6_init },
-};
-/* Set mic1 as input and unmute the mixer */
-static const struct hda_verb alc861_uniwill_m31_ch2_init[] = {
-       { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
-       { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
-       { } /* end */
-};
-/* Set mic1 as output and mute mixer */
-static const struct hda_verb alc861_uniwill_m31_ch4_init[] = {
-       { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
-       { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
-       { } /* end */
-};
-
-static const struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
-       { 2, alc861_uniwill_m31_ch2_init },
-       { 4, alc861_uniwill_m31_ch4_init },
-};
-
-/* Set mic1 and line-in as input and unmute the mixer */
-static const struct hda_verb alc861_asus_ch2_init[] = {
-       /* set pin widget 1Ah (line in) for input */
-       { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
-       /* set pin widget 18h (mic1/2) for input, for mic also enable
-        * the vref
-        */
-       { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
-
-       { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
-#if 0
-       { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
-       { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
-#endif
-       { } /* end */
-};
-/* Set mic1 nad line-in as output and mute mixer */
-static const struct hda_verb alc861_asus_ch6_init[] = {
-       /* set pin widget 1Ah (line in) for output (Back Surround)*/
-       { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
-       /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
-       /* set pin widget 18h (mic1) for output (CLFE)*/
-       { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
-       /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
-       { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
-       { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
-
-       { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
-#if 0
-       { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
-       { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
-#endif
-       { } /* end */
-};
-
-static const struct hda_channel_mode alc861_asus_modes[2] = {
-       { 2, alc861_asus_ch2_init },
-       { 6, alc861_asus_ch6_init },
-};
-
-/* patch-ALC861 */
-
-static const struct snd_kcontrol_new alc861_base_mixer[] = {
-        /* output mixer control */
-       HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
-
-        /*Input mixer control */
-       /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
-          HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
-       HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
-       HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
-       HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
-
-       { } /* end */
-};
-
-static const struct snd_kcontrol_new alc861_3ST_mixer[] = {
-        /* output mixer control */
-       HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
-       /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
-
-       /* Input mixer control */
-       /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
-          HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
-       HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
-       HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
-       HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
-
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "Channel Mode",
-               .info = alc_ch_mode_info,
-               .get = alc_ch_mode_get,
-               .put = alc_ch_mode_put,
-                .private_value = ARRAY_SIZE(alc861_threestack_modes),
-       },
-       { } /* end */
-};
-
-static const struct snd_kcontrol_new alc861_toshiba_mixer[] = {
-        /* output mixer control */
-       HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
-
-       { } /* end */
-};
-
-static const struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
-        /* output mixer control */
-       HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
-       /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
-
-       /* Input mixer control */
-       /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
-          HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
-       HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
-       HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
-       HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
-
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "Channel Mode",
-               .info = alc_ch_mode_info,
-               .get = alc_ch_mode_get,
-               .put = alc_ch_mode_put,
-                .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
-       },
-       { } /* end */
-};
-
-static const struct snd_kcontrol_new alc861_asus_mixer[] = {
-        /* output mixer control */
-       HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
-
-       /* Input mixer control */
-       HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
-       HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
-       HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
-
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "Channel Mode",
-               .info = alc_ch_mode_info,
-               .get = alc_ch_mode_get,
-               .put = alc_ch_mode_put,
-                .private_value = ARRAY_SIZE(alc861_asus_modes),
-       },
-       { }
-};
-
-/* additional mixer */
-static const struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
-       HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
-       { }
-};
-
-/*
- * generic initialization of ADC, input mixers and output mixers
- */
-static const struct hda_verb alc861_base_init_verbs[] = {
-       /*
-        * Unmute ADC0 and set the default input to mic-in
-        */
-       /* port-A for surround (rear panel) */
-       { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
-       { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
-       /* port-B for mic-in (rear panel) with vref */
-       { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
-       /* port-C for line-in (rear panel) */
-       { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
-       /* port-D for Front */
-       { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
-       { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
-       /* port-E for HP out (front panel) */
-       { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
-       /* route front PCM to HP */
-       { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
-       /* port-F for mic-in (front panel) with vref */
-       { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
-       /* port-G for CLFE (rear panel) */
-       { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
-       { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
-       /* port-H for side (rear panel) */
-       { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
-       { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
-       /* CD-in */
-       { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
-       /* route front mic to ADC1*/
-       {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
-       {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-
-       /* Unmute DAC0~3 & spdif out*/
-       {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-
-       /* Unmute Mixer 14 (mic) 1c (Line in)*/
-       {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-        {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-        {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-
-       /* Unmute Stereo Mixer 15 */
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
-
-       {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       /* hp used DAC 3 (Front) */
-       {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
-        {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
-
-       { }
-};
-
-static const struct hda_verb alc861_threestack_init_verbs[] = {
-       /*
-        * Unmute ADC0 and set the default input to mic-in
-        */
-       /* port-A for surround (rear panel) */
-       { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
-       /* port-B for mic-in (rear panel) with vref */
-       { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
-       /* port-C for line-in (rear panel) */
-       { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
-       /* port-D for Front */
-       { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
-       { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
-       /* port-E for HP out (front panel) */
-       { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
-       /* route front PCM to HP */
-       { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
-       /* port-F for mic-in (front panel) with vref */
-       { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
-       /* port-G for CLFE (rear panel) */
-       { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
-       /* port-H for side (rear panel) */
-       { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
-       /* CD-in */
-       { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
-       /* route front mic to ADC1*/
-       {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
-       {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       /* Unmute DAC0~3 & spdif out*/
-       {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-
-       /* Unmute Mixer 14 (mic) 1c (Line in)*/
-       {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-        {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-        {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-
-       /* Unmute Stereo Mixer 15 */
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
-
-       {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       /* hp used DAC 3 (Front) */
-       {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
-        {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
-       { }
-};
-
-static const struct hda_verb alc861_uniwill_m31_init_verbs[] = {
-       /*
-        * Unmute ADC0 and set the default input to mic-in
-        */
-       /* port-A for surround (rear panel) */
-       { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
-       /* port-B for mic-in (rear panel) with vref */
-       { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
-       /* port-C for line-in (rear panel) */
-       { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
-       /* port-D for Front */
-       { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
-       { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
-       /* port-E for HP out (front panel) */
-       /* this has to be set to VREF80 */
-       { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
-       /* route front PCM to HP */
-       { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
-       /* port-F for mic-in (front panel) with vref */
-       { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
-       /* port-G for CLFE (rear panel) */
-       { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
-       /* port-H for side (rear panel) */
-       { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
-       /* CD-in */
-       { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
-       /* route front mic to ADC1*/
-       {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
-       {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       /* Unmute DAC0~3 & spdif out*/
-       {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-
-       /* Unmute Mixer 14 (mic) 1c (Line in)*/
-       {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-        {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-        {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-
-       /* Unmute Stereo Mixer 15 */
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
-
-       {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       /* hp used DAC 3 (Front) */
-       {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
-        {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
-       { }
-};
-
-static const struct hda_verb alc861_asus_init_verbs[] = {
-       /*
-        * Unmute ADC0 and set the default input to mic-in
-        */
-       /* port-A for surround (rear panel)
-        * according to codec#0 this is the HP jack
-        */
-       { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
-       /* route front PCM to HP */
-       { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
-       /* port-B for mic-in (rear panel) with vref */
-       { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
-       /* port-C for line-in (rear panel) */
-       { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
-       /* port-D for Front */
-       { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
-       { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
-       /* port-E for HP out (front panel) */
-       /* this has to be set to VREF80 */
-       { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
-       /* route front PCM to HP */
-       { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
-       /* port-F for mic-in (front panel) with vref */
-       { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
-       /* port-G for CLFE (rear panel) */
-       { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
-       /* port-H for side (rear panel) */
-       { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
-       /* CD-in */
-       { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
-       /* route front mic to ADC1*/
-       {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
-       {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       /* Unmute DAC0~3 & spdif out*/
-       {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       /* Unmute Mixer 14 (mic) 1c (Line in)*/
-       {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-        {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-        {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-
-       /* Unmute Stereo Mixer 15 */
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
-
-       {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       /* hp used DAC 3 (Front) */
-       {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
-       {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
-       { }
-};
-
-/* additional init verbs for ASUS laptops */
-static const struct hda_verb alc861_asus_laptop_init_verbs[] = {
-       { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
-       { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
-       { }
-};
-
-static const struct hda_verb alc861_toshiba_init_verbs[] = {
-       {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
-
-       { }
-};
-
-/* toggle speaker-output according to the hp-jack state */
-static void alc861_toshiba_automute(struct hda_codec *codec)
-{
-       unsigned int present = snd_hda_jack_detect(codec, 0x0f);
-
-       snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
-                                HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
-       snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
-                                HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
-}
-
-static void alc861_toshiba_unsol_event(struct hda_codec *codec,
-                                      unsigned int res)
-{
-       if ((res >> 26) == ALC_HP_EVENT)
-               alc861_toshiba_automute(codec);
-}
-
-#define ALC861_DIGOUT_NID      0x07
-
-static const struct hda_channel_mode alc861_8ch_modes[1] = {
-       { 8, NULL }
-};
-
-static const hda_nid_t alc861_dac_nids[4] = {
-       /* front, surround, clfe, side */
-       0x03, 0x06, 0x05, 0x04
-};
-
-static const hda_nid_t alc660_dac_nids[3] = {
-       /* front, clfe, surround */
-       0x03, 0x05, 0x06
-};
-
-static const hda_nid_t alc861_adc_nids[1] = {
-       /* ADC0-2 */
-       0x08,
-};
-
-static const struct hda_input_mux alc861_capture_source = {
-       .num_items = 5,
-       .items = {
-               { "Mic", 0x0 },
-               { "Front Mic", 0x3 },
-               { "Line", 0x1 },
-               { "CD", 0x4 },
-               { "Mixer", 0x5 },
-       },
-};
-
-/*
- * configuration and preset
- */
-static const char * const alc861_models[ALC861_MODEL_LAST] = {
-       [ALC861_3ST]            = "3stack",
-       [ALC660_3ST]            = "3stack-660",
-       [ALC861_3ST_DIG]        = "3stack-dig",
-       [ALC861_6ST_DIG]        = "6stack-dig",
-       [ALC861_UNIWILL_M31]    = "uniwill-m31",
-       [ALC861_TOSHIBA]        = "toshiba",
-       [ALC861_ASUS]           = "asus",
-       [ALC861_ASUS_LAPTOP]    = "asus-laptop",
-       [ALC861_AUTO]           = "auto",
-};
-
-static const struct snd_pci_quirk alc861_cfg_tbl[] = {
-       SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
-       SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
-       SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
-       SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
-       SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
-       SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
-       SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
-       /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
-        *        Any other models that need this preset?
-        */
-       /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
-       SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
-       SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
-       SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
-       SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
-       SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
-       /* FIXME: the below seems conflict */
-       /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
-       SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
-       SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
-       {}
-};
-
-static const struct alc_config_preset alc861_presets[] = {
-       [ALC861_3ST] = {
-               .mixers = { alc861_3ST_mixer },
-               .init_verbs = { alc861_threestack_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc861_dac_nids),
-               .dac_nids = alc861_dac_nids,
-               .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
-               .channel_mode = alc861_threestack_modes,
-               .need_dac_fix = 1,
-               .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
-               .adc_nids = alc861_adc_nids,
-               .input_mux = &alc861_capture_source,
-       },
-       [ALC861_3ST_DIG] = {
-               .mixers = { alc861_base_mixer },
-               .init_verbs = { alc861_threestack_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc861_dac_nids),
-               .dac_nids = alc861_dac_nids,
-               .dig_out_nid = ALC861_DIGOUT_NID,
-               .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
-               .channel_mode = alc861_threestack_modes,
-               .need_dac_fix = 1,
-               .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
-               .adc_nids = alc861_adc_nids,
-               .input_mux = &alc861_capture_source,
-       },
-       [ALC861_6ST_DIG] = {
-               .mixers = { alc861_base_mixer },
-               .init_verbs = { alc861_base_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc861_dac_nids),
-               .dac_nids = alc861_dac_nids,
-               .dig_out_nid = ALC861_DIGOUT_NID,
-               .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
-               .channel_mode = alc861_8ch_modes,
-               .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
-               .adc_nids = alc861_adc_nids,
-               .input_mux = &alc861_capture_source,
-       },
-       [ALC660_3ST] = {
-               .mixers = { alc861_3ST_mixer },
-               .init_verbs = { alc861_threestack_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc660_dac_nids),
-               .dac_nids = alc660_dac_nids,
-               .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
-               .channel_mode = alc861_threestack_modes,
-               .need_dac_fix = 1,
-               .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
-               .adc_nids = alc861_adc_nids,
-               .input_mux = &alc861_capture_source,
-       },
-       [ALC861_UNIWILL_M31] = {
-               .mixers = { alc861_uniwill_m31_mixer },
-               .init_verbs = { alc861_uniwill_m31_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc861_dac_nids),
-               .dac_nids = alc861_dac_nids,
-               .dig_out_nid = ALC861_DIGOUT_NID,
-               .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
-               .channel_mode = alc861_uniwill_m31_modes,
-               .need_dac_fix = 1,
-               .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
-               .adc_nids = alc861_adc_nids,
-               .input_mux = &alc861_capture_source,
-       },
-       [ALC861_TOSHIBA] = {
-               .mixers = { alc861_toshiba_mixer },
-               .init_verbs = { alc861_base_init_verbs,
-                               alc861_toshiba_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc861_dac_nids),
-               .dac_nids = alc861_dac_nids,
-               .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
-               .channel_mode = alc883_3ST_2ch_modes,
-               .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
-               .adc_nids = alc861_adc_nids,
-               .input_mux = &alc861_capture_source,
-               .unsol_event = alc861_toshiba_unsol_event,
-               .init_hook = alc861_toshiba_automute,
-       },
-       [ALC861_ASUS] = {
-               .mixers = { alc861_asus_mixer },
-               .init_verbs = { alc861_asus_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc861_dac_nids),
-               .dac_nids = alc861_dac_nids,
-               .dig_out_nid = ALC861_DIGOUT_NID,
-               .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
-               .channel_mode = alc861_asus_modes,
-               .need_dac_fix = 1,
-               .hp_nid = 0x06,
-               .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
-               .adc_nids = alc861_adc_nids,
-               .input_mux = &alc861_capture_source,
-       },
-       [ALC861_ASUS_LAPTOP] = {
-               .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
-               .init_verbs = { alc861_asus_init_verbs,
-                               alc861_asus_laptop_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc861_dac_nids),
-               .dac_nids = alc861_dac_nids,
-               .dig_out_nid = ALC861_DIGOUT_NID,
-               .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
-               .channel_mode = alc883_3ST_2ch_modes,
-               .need_dac_fix = 1,
-               .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
-               .adc_nids = alc861_adc_nids,
-               .input_mux = &alc861_capture_source,
-       },
-};
-
diff --git a/sound/pci/hda/alc861vd_quirks.c b/sound/pci/hda/alc861vd_quirks.c
deleted file mode 100644 (file)
index 8f28450..0000000
+++ /dev/null
@@ -1,605 +0,0 @@
-/*
- * ALC660-VD/ALC861-VD quirk models
- * included by patch_realtek.c
- */
-
-/* ALC861-VD models */
-enum {
-       ALC861VD_AUTO,
-       ALC660VD_3ST,
-       ALC660VD_3ST_DIG,
-       ALC660VD_ASUS_V1S,
-       ALC861VD_3ST,
-       ALC861VD_3ST_DIG,
-       ALC861VD_6ST_DIG,
-       ALC861VD_LENOVO,
-       ALC861VD_DALLAS,
-       ALC861VD_HP,
-       ALC861VD_MODEL_LAST,
-};
-
-#define ALC861VD_DIGOUT_NID    0x06
-
-static const hda_nid_t alc861vd_dac_nids[4] = {
-       /* front, surr, clfe, side surr */
-       0x02, 0x03, 0x04, 0x05
-};
-
-/* dac_nids for ALC660vd are in a different order - according to
- * Realtek's driver.
- * This should probably result in a different mixer for 6stack models
- * of ALC660vd codecs, but for now there is only 3stack mixer
- * - and it is the same as in 861vd.
- * adc_nids in ALC660vd are (is) the same as in 861vd
- */
-static const hda_nid_t alc660vd_dac_nids[3] = {
-       /* front, rear, clfe, rear_surr */
-       0x02, 0x04, 0x03
-};
-
-static const hda_nid_t alc861vd_adc_nids[1] = {
-       /* ADC0 */
-       0x09,
-};
-
-static const hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
-
-/* input MUX */
-/* FIXME: should be a matrix-type input source selection */
-static const struct hda_input_mux alc861vd_capture_source = {
-       .num_items = 4,
-       .items = {
-               { "Mic", 0x0 },
-               { "Front Mic", 0x1 },
-               { "Line", 0x2 },
-               { "CD", 0x4 },
-       },
-};
-
-static const struct hda_input_mux alc861vd_dallas_capture_source = {
-       .num_items = 2,
-       .items = {
-               { "Mic", 0x0 },
-               { "Internal Mic", 0x1 },
-       },
-};
-
-static const struct hda_input_mux alc861vd_hp_capture_source = {
-       .num_items = 2,
-       .items = {
-               { "Front Mic", 0x0 },
-               { "ATAPI Mic", 0x1 },
-       },
-};
-
-/*
- * 2ch mode
- */
-static const struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
-       { 2, NULL }
-};
-
-/*
- * 6ch mode
- */
-static const struct hda_verb alc861vd_6stack_ch6_init[] = {
-       { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
-       { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
-       { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
-       { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
-       { } /* end */
-};
-
-/*
- * 8ch mode
- */
-static const struct hda_verb alc861vd_6stack_ch8_init[] = {
-       { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
-       { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
-       { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
-       { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
-       { } /* end */
-};
-
-static const struct hda_channel_mode alc861vd_6stack_modes[2] = {
-       { 6, alc861vd_6stack_ch6_init },
-       { 8, alc861vd_6stack_ch8_init },
-};
-
-static const struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "Channel Mode",
-               .info = alc_ch_mode_info,
-               .get = alc_ch_mode_get,
-               .put = alc_ch_mode_put,
-       },
-       { } /* end */
-};
-
-/* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
- *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
- */
-static const struct snd_kcontrol_new alc861vd_6st_mixer[] = {
-       HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
-       HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
-
-       HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
-       HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
-
-       HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
-                               HDA_OUTPUT),
-       HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
-                               HDA_OUTPUT),
-       HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
-       HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
-
-       HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
-       HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
-
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
-
-       HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
-
-       HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
-       HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
-
-       HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
-       HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
-
-       HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
-       HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
-
-       { } /* end */
-};
-
-static const struct snd_kcontrol_new alc861vd_3st_mixer[] = {
-       HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
-       HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
-
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
-
-       HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
-
-       HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
-       HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
-
-       HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
-       HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
-
-       HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
-       HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
-
-       { } /* end */
-};
-
-static const struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
-       HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
-       /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
-       HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
-
-       HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
-
-       HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
-
-       HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
-       HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
-
-       HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
-       HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
-
-       { } /* end */
-};
-
-/* Pin assignment: Speaker=0x14, HP = 0x15,
- *                 Mic=0x18, Internal Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
- */
-static const struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
-       HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
-       HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
-       HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
-       HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
-       HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
-       { } /* end */
-};
-
-/* Pin assignment: Speaker=0x14, Line-out = 0x15,
- *                 Front Mic=0x18, ATAPI Mic = 0x19,
- */
-static const struct snd_kcontrol_new alc861vd_hp_mixer[] = {
-       HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
-       HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
-       HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
-       HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
-       HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
-       HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
-
-       { } /* end */
-};
-
-/*
- * generic initialization of ADC, input mixers and output mixers
- */
-static const struct hda_verb alc861vd_volume_init_verbs[] = {
-       /*
-        * Unmute ADC0 and set the default input to mic-in
-        */
-       {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
-       {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-
-       /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
-        * the analog-loopback mixer widget
-        */
-       /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
-       {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
-       {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
-       {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
-       {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
-       {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
-
-       /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
-
-       /*
-        * Set up output mixers (0x02 - 0x05)
-        */
-       /* set vol=0 to output mixers */
-       {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
-       {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
-       {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
-       {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
-
-       /* set up input amps for analog loopback */
-       /* Amp Indices: DAC = 0, mixer = 1 */
-       {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
-       {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
-       {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
-       {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
-       {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
-       {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
-       {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
-       {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
-
-       { }
-};
-
-/*
- * 3-stack pin configuration:
- * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
- */
-static const struct hda_verb alc861vd_3stack_init_verbs[] = {
-       /*
-        * Set pin mode and muting
-        */
-       /* set front pin widgets 0x14 for output */
-       {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
-       {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
-
-       /* Mic (rear) pin: input vref at 80% */
-       {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
-       {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
-       /* Front Mic pin: input vref at 80% */
-       {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
-       {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
-       /* Line In pin: input */
-       {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
-       /* Line-2 In: Headphone output (output 0 - 0x0c) */
-       {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
-       /* CD pin widget for input */
-       {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-
-       { }
-};
-
-/*
- * 6-stack pin configuration:
- */
-static const struct hda_verb alc861vd_6stack_init_verbs[] = {
-       /*
-        * Set pin mode and muting
-        */
-       /* set front pin widgets 0x14 for output */
-       {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
-       {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
-
-       /* Rear Pin: output 1 (0x0d) */
-       {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
-       /* CLFE Pin: output 2 (0x0e) */
-       {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
-       {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
-       /* Side Pin: output 3 (0x0f) */
-       {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
-       {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
-
-       /* Mic (rear) pin: input vref at 80% */
-       {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
-       {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
-       /* Front Mic pin: input vref at 80% */
-       {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
-       {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
-       /* Line In pin: input */
-       {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
-       /* Line-2 In: Headphone output (output 0 - 0x0c) */
-       {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
-       /* CD pin widget for input */
-       {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-
-       { }
-};
-
-static const struct hda_verb alc861vd_eapd_verbs[] = {
-       {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
-       { }
-};
-
-static const struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
-       {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
-       {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
-       {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
-       {}
-};
-
-static void alc861vd_lenovo_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-       spec->autocfg.hp_pins[0] = 0x1b;
-       spec->autocfg.speaker_pins[0] = 0x14;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
-}
-
-static void alc861vd_lenovo_init_hook(struct hda_codec *codec)
-{
-       alc_hp_automute(codec);
-       alc88x_simple_mic_automute(codec);
-}
-
-static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
-                                       unsigned int res)
-{
-       switch (res >> 26) {
-       case ALC_MIC_EVENT:
-               alc88x_simple_mic_automute(codec);
-               break;
-       default:
-               alc_sku_unsol_event(codec, res);
-               break;
-       }
-}
-
-static const struct hda_verb alc861vd_dallas_verbs[] = {
-       {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
-       {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
-       {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
-       {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
-
-       {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
-       {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
-       {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
-       {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
-       {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
-       {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
-
-       {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
-       {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
-       {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
-       {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-
-       {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
-       {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
-       {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
-       {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
-       {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
-       {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
-
-       {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
-       {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
-       {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
-
-       { } /* end */
-};
-
-/* toggle speaker-output according to the hp-jack state */
-static void alc861vd_dallas_setup(struct hda_codec *codec)
-{
-       struct alc_spec *spec = codec->spec;
-
-       spec->autocfg.hp_pins[0] = 0x15;
-       spec->autocfg.speaker_pins[0] = 0x14;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
-}
-
-/*
- * configuration and preset
- */
-static const char * const alc861vd_models[ALC861VD_MODEL_LAST] = {
-       [ALC660VD_3ST]          = "3stack-660",
-       [ALC660VD_3ST_DIG]      = "3stack-660-digout",
-       [ALC660VD_ASUS_V1S]     = "asus-v1s",
-       [ALC861VD_3ST]          = "3stack",
-       [ALC861VD_3ST_DIG]      = "3stack-digout",
-       [ALC861VD_6ST_DIG]      = "6stack-digout",
-       [ALC861VD_LENOVO]       = "lenovo",
-       [ALC861VD_DALLAS]       = "dallas",
-       [ALC861VD_HP]           = "hp",
-       [ALC861VD_AUTO]         = "auto",
-};
-
-static const struct snd_pci_quirk alc861vd_cfg_tbl[] = {
-       SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
-       SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
-       SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
-       /*SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),*/ /* auto */
-       SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC660VD_ASUS_V1S),
-       SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
-       SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
-       SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
-       /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
-       SND_PCI_QUIRK(0x1179, 0xff01, "Toshiba A135", ALC861VD_LENOVO),
-       SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
-       SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
-       SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
-       SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", ALC861VD_LENOVO),
-       SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
-       {}
-};
-
-static const struct alc_config_preset alc861vd_presets[] = {
-       [ALC660VD_3ST] = {
-               .mixers = { alc861vd_3st_mixer },
-               .init_verbs = { alc861vd_volume_init_verbs,
-                                alc861vd_3stack_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
-               .dac_nids = alc660vd_dac_nids,
-               .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
-               .channel_mode = alc861vd_3stack_2ch_modes,
-               .input_mux = &alc861vd_capture_source,
-       },
-       [ALC660VD_3ST_DIG] = {
-               .mixers = { alc861vd_3st_mixer },
-               .init_verbs = { alc861vd_volume_init_verbs,
-                                alc861vd_3stack_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
-               .dac_nids = alc660vd_dac_nids,
-               .dig_out_nid = ALC861VD_DIGOUT_NID,
-               .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
-               .channel_mode = alc861vd_3stack_2ch_modes,
-               .input_mux = &alc861vd_capture_source,
-       },
-       [ALC861VD_3ST] = {
-               .mixers = { alc861vd_3st_mixer },
-               .init_verbs = { alc861vd_volume_init_verbs,
-                                alc861vd_3stack_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
-               .dac_nids = alc861vd_dac_nids,
-               .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
-               .channel_mode = alc861vd_3stack_2ch_modes,
-               .input_mux = &alc861vd_capture_source,
-       },
-       [ALC861VD_3ST_DIG] = {
-               .mixers = { alc861vd_3st_mixer },
-               .init_verbs = { alc861vd_volume_init_verbs,
-                                alc861vd_3stack_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
-               .dac_nids = alc861vd_dac_nids,
-               .dig_out_nid = ALC861VD_DIGOUT_NID,
-               .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
-               .channel_mode = alc861vd_3stack_2ch_modes,
-               .input_mux = &alc861vd_capture_source,
-       },
-       [ALC861VD_6ST_DIG] = {
-               .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
-               .init_verbs = { alc861vd_volume_init_verbs,
-                               alc861vd_6stack_init_verbs },
-               .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
-               .dac_nids = alc861vd_dac_nids,
-               .dig_out_nid = ALC861VD_DIGOUT_NID,
-               .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
-               .channel_mode = alc861vd_6stack_modes,
-               .input_mux = &alc861vd_capture_source,
-       },
-       [ALC861VD_LENOVO] = {
-               .mixers = { alc861vd_lenovo_mixer },
-               .init_verbs = { alc861vd_volume_init_verbs,
-                               alc861vd_3stack_init_verbs,
-                               alc861vd_eapd_verbs,
-                               alc861vd_lenovo_unsol_verbs },
-               .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
-               .dac_nids = alc660vd_dac_nids,
-               .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
-               .channel_mode = alc861vd_3stack_2ch_modes,
-               .input_mux = &alc861vd_capture_source,
-               .unsol_event = alc861vd_lenovo_unsol_event,
-               .setup = alc861vd_lenovo_setup,
-               .init_hook = alc861vd_lenovo_init_hook,
-       },
-       [ALC861VD_DALLAS] = {
-               .mixers = { alc861vd_dallas_mixer },
-               .init_verbs = { alc861vd_dallas_verbs },
-               .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
-               .dac_nids = alc861vd_dac_nids,
-               .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
-               .channel_mode = alc861vd_3stack_2ch_modes,
-               .input_mux = &alc861vd_dallas_capture_source,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc861vd_dallas_setup,
-               .init_hook = alc_hp_automute,
-       },
-       [ALC861VD_HP] = {
-               .mixers = { alc861vd_hp_mixer },
-               .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
-               .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
-               .dac_nids = alc861vd_dac_nids,
-               .dig_out_nid = ALC861VD_DIGOUT_NID,
-               .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
-               .channel_mode = alc861vd_3stack_2ch_modes,
-               .input_mux = &alc861vd_hp_capture_source,
-               .unsol_event = alc_sku_unsol_event,
-               .setup = alc861vd_dallas_setup,
-               .init_hook = alc_hp_automute,
-       },
-       [ALC660VD_ASUS_V1S] = {
-               .mixers = { alc861vd_lenovo_mixer },
-               .init_verbs = { alc861vd_volume_init_verbs,
-                               alc861vd_3stack_init_verbs,
-                               alc861vd_eapd_verbs,
-                               alc861vd_lenovo_unsol_verbs },
-               .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
-               .dac_nids = alc660vd_dac_nids,
-               .dig_out_nid = ALC861VD_DIGOUT_NID,
-               .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
-               .channel_mode = alc861vd_3stack_2ch_modes,
-               .input_mux = &alc861vd_capture_source,
-               .unsol_event = alc861vd_lenovo_unsol_event,
-               .setup = alc861vd_lenovo_setup,
-               .init_hook = alc861vd_lenovo_init_hook,
-       },
-};
-
index c844d2b5998841c3103e7c51b0612110ad81e58a..bea22edcfd8ca2ef79d5f2c71d4ad8614887d85d 100644 (file)
@@ -749,8 +749,7 @@ static void alc880_uniwill_setup(struct hda_codec *codec)
        spec->autocfg.hp_pins[0] = 0x14;
        spec->autocfg.speaker_pins[0] = 0x15;
        spec->autocfg.speaker_pins[0] = 0x16;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 static void alc880_uniwill_init_hook(struct hda_codec *codec)
@@ -781,8 +780,7 @@ static void alc880_uniwill_p53_setup(struct hda_codec *codec)
 
        spec->autocfg.hp_pins[0] = 0x14;
        spec->autocfg.speaker_pins[0] = 0x15;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
@@ -1051,8 +1049,7 @@ static void alc880_lg_setup(struct hda_codec *codec)
 
        spec->autocfg.hp_pins[0] = 0x1b;
        spec->autocfg.speaker_pins[0] = 0x17;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 /*
@@ -1137,8 +1134,7 @@ static void alc880_lg_lw_setup(struct hda_codec *codec)
 
        spec->autocfg.hp_pins[0] = 0x1b;
        spec->autocfg.speaker_pins[0] = 0x14;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 static const struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
@@ -1188,7 +1184,7 @@ static void alc880_medion_rim_automute(struct hda_codec *codec)
        struct alc_spec *spec = codec->spec;
        alc_hp_automute(codec);
        /* toggle EAPD */
-       if (spec->jack_present)
+       if (spec->hp_jack_present)
                snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
        else
                snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
@@ -1210,8 +1206,7 @@ static void alc880_medion_rim_setup(struct hda_codec *codec)
 
        spec->autocfg.hp_pins[0] = 0x14;
        spec->autocfg.speaker_pins[0] = 0x1b;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 #ifdef CONFIG_SND_HDA_POWER_SAVE
index 617d04723b82961775ea8384a19d1eb760cc87ba..e251514a26a4bddccd95d3acdd2c8e468c3518bc 100644 (file)
@@ -173,8 +173,7 @@ static void alc889_automute_setup(struct hda_codec *codec)
        spec->autocfg.speaker_pins[2] = 0x17;
        spec->autocfg.speaker_pins[3] = 0x19;
        spec->autocfg.speaker_pins[4] = 0x1a;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 static void alc889_intel_init_hook(struct hda_codec *codec)
@@ -191,8 +190,7 @@ static void alc888_fujitsu_xa3530_setup(struct hda_codec *codec)
        spec->autocfg.hp_pins[1] = 0x1b; /* hp */
        spec->autocfg.speaker_pins[0] = 0x14; /* speaker */
        spec->autocfg.speaker_pins[1] = 0x15; /* bass */
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 /*
@@ -475,8 +473,7 @@ static void alc888_acer_aspire_4930g_setup(struct hda_codec *codec)
        spec->autocfg.speaker_pins[0] = 0x14;
        spec->autocfg.speaker_pins[1] = 0x16;
        spec->autocfg.speaker_pins[2] = 0x17;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 static void alc888_acer_aspire_6530g_setup(struct hda_codec *codec)
@@ -487,8 +484,7 @@ static void alc888_acer_aspire_6530g_setup(struct hda_codec *codec)
        spec->autocfg.speaker_pins[0] = 0x14;
        spec->autocfg.speaker_pins[1] = 0x16;
        spec->autocfg.speaker_pins[2] = 0x17;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 static void alc888_acer_aspire_7730g_setup(struct hda_codec *codec)
@@ -499,8 +495,7 @@ static void alc888_acer_aspire_7730g_setup(struct hda_codec *codec)
        spec->autocfg.speaker_pins[0] = 0x14;
        spec->autocfg.speaker_pins[1] = 0x16;
        spec->autocfg.speaker_pins[2] = 0x17;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 static void alc889_acer_aspire_8930g_setup(struct hda_codec *codec)
@@ -511,8 +506,7 @@ static void alc889_acer_aspire_8930g_setup(struct hda_codec *codec)
        spec->autocfg.speaker_pins[0] = 0x14;
        spec->autocfg.speaker_pins[1] = 0x16;
        spec->autocfg.speaker_pins[2] = 0x1b;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 #define ALC882_DIGOUT_NID      0x06
@@ -1711,8 +1705,7 @@ static void alc885_imac24_setup(struct hda_codec *codec)
        spec->autocfg.hp_pins[0] = 0x14;
        spec->autocfg.speaker_pins[0] = 0x18;
        spec->autocfg.speaker_pins[1] = 0x1a;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 #define alc885_mb5_setup       alc885_imac24_setup
@@ -1721,12 +1714,11 @@ static void alc885_imac24_setup(struct hda_codec *codec)
 /* Macbook Air 2,1 */
 static void alc885_mba21_setup(struct hda_codec *codec)
 {
-       struct alc_spec *spec = codec->spec;
+       struct alc_spec *spec = codec->spec;
 
-       spec->autocfg.hp_pins[0] = 0x14;
-       spec->autocfg.speaker_pins[0] = 0x18;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       spec->autocfg.hp_pins[0] = 0x14;
+       spec->autocfg.speaker_pins[0] = 0x18;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 
@@ -1737,8 +1729,7 @@ static void alc885_mbp3_setup(struct hda_codec *codec)
 
        spec->autocfg.hp_pins[0] = 0x15;
        spec->autocfg.speaker_pins[0] = 0x14;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 static void alc885_imac91_setup(struct hda_codec *codec)
@@ -1748,8 +1739,7 @@ static void alc885_imac91_setup(struct hda_codec *codec)
        spec->autocfg.hp_pins[0] = 0x14;
        spec->autocfg.speaker_pins[0] = 0x18;
        spec->autocfg.speaker_pins[1] = 0x1a;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 static const struct hda_verb alc882_targa_verbs[] = {
@@ -1773,7 +1763,7 @@ static void alc882_targa_automute(struct hda_codec *codec)
        struct alc_spec *spec = codec->spec;
        alc_hp_automute(codec);
        snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
-                                 spec->jack_present ? 1 : 3);
+                                 spec->hp_jack_present ? 1 : 3);
 }
 
 static void alc882_targa_setup(struct hda_codec *codec)
@@ -1782,8 +1772,7 @@ static void alc882_targa_setup(struct hda_codec *codec)
 
        spec->autocfg.hp_pins[0] = 0x14;
        spec->autocfg.speaker_pins[0] = 0x1b;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
@@ -2187,8 +2176,7 @@ static void alc883_medion_wim2160_setup(struct hda_codec *codec)
 
        spec->autocfg.hp_pins[0] = 0x1a;
        spec->autocfg.speaker_pins[0] = 0x15;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 static const struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
@@ -2341,8 +2329,7 @@ static void alc883_mitac_setup(struct hda_codec *codec)
        spec->autocfg.hp_pins[0] = 0x15;
        spec->autocfg.speaker_pins[0] = 0x14;
        spec->autocfg.speaker_pins[1] = 0x17;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 static const struct hda_verb alc883_mitac_verbs[] = {
@@ -2507,8 +2494,7 @@ static void alc888_3st_hp_setup(struct hda_codec *codec)
        spec->autocfg.speaker_pins[0] = 0x14;
        spec->autocfg.speaker_pins[1] = 0x16;
        spec->autocfg.speaker_pins[2] = 0x18;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 static const struct hda_verb alc888_3st_hp_verbs[] = {
@@ -2568,8 +2554,7 @@ static void alc888_lenovo_ms7195_setup(struct hda_codec *codec)
        spec->autocfg.hp_pins[0] = 0x1b;
        spec->autocfg.line_out_pins[0] = 0x14;
        spec->autocfg.speaker_pins[0] = 0x15;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 /* toggle speaker-output according to the hp-jack state */
@@ -2579,8 +2564,7 @@ static void alc883_lenovo_nb0763_setup(struct hda_codec *codec)
 
        spec->autocfg.hp_pins[0] = 0x14;
        spec->autocfg.speaker_pins[0] = 0x15;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 /* toggle speaker-output according to the hp-jack state */
@@ -2593,8 +2577,7 @@ static void alc883_clevo_m720_setup(struct hda_codec *codec)
 
        spec->autocfg.hp_pins[0] = 0x15;
        spec->autocfg.speaker_pins[0] = 0x14;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 static void alc883_clevo_m720_init_hook(struct hda_codec *codec)
@@ -2623,8 +2606,7 @@ static void alc883_2ch_fujitsu_pi2515_setup(struct hda_codec *codec)
 
        spec->autocfg.hp_pins[0] = 0x14;
        spec->autocfg.speaker_pins[0] = 0x15;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 static void alc883_haier_w66_setup(struct hda_codec *codec)
@@ -2633,8 +2615,7 @@ static void alc883_haier_w66_setup(struct hda_codec *codec)
 
        spec->autocfg.hp_pins[0] = 0x1b;
        spec->autocfg.speaker_pins[0] = 0x14;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 static void alc883_lenovo_101e_setup(struct hda_codec *codec)
@@ -2644,10 +2625,7 @@ static void alc883_lenovo_101e_setup(struct hda_codec *codec)
        spec->autocfg.hp_pins[0] = 0x1b;
        spec->autocfg.line_out_pins[0] = 0x14;
        spec->autocfg.speaker_pins[0] = 0x15;
-       spec->automute = 1;
-       spec->detect_line = 1;
-       spec->automute_lines = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 /* toggle speaker-output according to the hp-jack state */
@@ -2658,8 +2636,7 @@ static void alc883_acer_aspire_setup(struct hda_codec *codec)
        spec->autocfg.hp_pins[0] = 0x14;
        spec->autocfg.speaker_pins[0] = 0x15;
        spec->autocfg.speaker_pins[1] = 0x16;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 static const struct hda_verb alc883_acer_eapd_verbs[] = {
@@ -2689,8 +2666,7 @@ static void alc888_6st_dell_setup(struct hda_codec *codec)
        spec->autocfg.speaker_pins[1] = 0x15;
        spec->autocfg.speaker_pins[2] = 0x16;
        spec->autocfg.speaker_pins[3] = 0x17;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 static void alc888_lenovo_sky_setup(struct hda_codec *codec)
@@ -2703,8 +2679,7 @@ static void alc888_lenovo_sky_setup(struct hda_codec *codec)
        spec->autocfg.speaker_pins[2] = 0x16;
        spec->autocfg.speaker_pins[3] = 0x17;
        spec->autocfg.speaker_pins[4] = 0x1a;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 static void alc883_vaiott_setup(struct hda_codec *codec)
@@ -2714,8 +2689,7 @@ static void alc883_vaiott_setup(struct hda_codec *codec)
        spec->autocfg.hp_pins[0] = 0x15;
        spec->autocfg.speaker_pins[0] = 0x14;
        spec->autocfg.speaker_pins[1] = 0x17;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 static const struct hda_verb alc888_asus_m90v_verbs[] = {
@@ -2739,8 +2713,7 @@ static void alc883_mode2_setup(struct hda_codec *codec)
        spec->ext_mic_pin = 0x18;
        spec->int_mic_pin = 0x19;
        spec->auto_mic = 1;
-       spec->automute = 1;
-       spec->automute_mode = ALC_AUTOMUTE_AMP;
+       alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
 }
 
 static const struct hda_verb alc888_asus_eee1601_verbs[] = {
index 2be1129cf458ae09f2ceef62640029bd319eb3e7..a18952ed4311993e9a56d1a1c356b819cb6c7de7 100644 (file)
@@ -453,6 +453,19 @@ static void setup_preset(struct hda_codec *codec,
        alc_fixup_autocfg_pin_nums(codec);
 }
 
+static void alc_simple_setup_automute(struct alc_spec *spec, int mode)
+{
+       int lo_pin = spec->autocfg.line_out_pins[0];
+
+       if (lo_pin == spec->autocfg.speaker_pins[0] ||
+               lo_pin == spec->autocfg.hp_pins[0])
+               lo_pin = 0;
+       spec->automute_mode = mode;
+       spec->detect_hp = !!spec->autocfg.hp_pins[0];
+       spec->detect_lo = !!lo_pin;
+       spec->automute_lo = spec->automute_lo_possible = !!lo_pin;
+       spec->automute_speaker = spec->automute_speaker_possible = !!spec->autocfg.speaker_pins[0];
+}
 
 /* auto-toggle front mic */
 static void alc88x_simple_mic_automute(struct hda_codec *codec)
index f3aefef3721614a7eb7c1bb2fcc2f25c0a87252e..1715e8b24ff02048036aea077b96b07f610ba8c1 100644 (file)
@@ -34,6 +34,9 @@
 #include "hda_beep.h"
 #include <sound/hda_hwdep.h>
 
+#define CREATE_TRACE_POINTS
+#include "hda_trace.h"
+
 /*
  * vendor / preset table
  */
@@ -208,15 +211,19 @@ static int codec_exec_verb(struct hda_codec *codec, unsigned int cmd,
  again:
        snd_hda_power_up(codec);
        mutex_lock(&bus->cmd_mutex);
+       trace_hda_send_cmd(codec, cmd);
        err = bus->ops.command(bus, cmd);
-       if (!err && res)
+       if (!err && res) {
                *res = bus->ops.get_response(bus, codec->addr);
+               trace_hda_get_response(codec, *res);
+       }
        mutex_unlock(&bus->cmd_mutex);
        snd_hda_power_down(codec);
        if (res && *res == -1 && bus->rirb_error) {
                if (bus->response_reset) {
                        snd_printd("hda_codec: resetting BUS due to "
                                   "fatal communication error\n");
+                       trace_hda_bus_reset(bus);
                        bus->ops.bus_reset(bus);
                }
                goto again;
@@ -607,6 +614,7 @@ int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex)
        struct hda_bus_unsolicited *unsol;
        unsigned int wp;
 
+       trace_hda_unsol_event(bus, res, res_ex);
        unsol = bus->unsol;
        if (!unsol)
                return 0;
@@ -1483,8 +1491,11 @@ static void really_cleanup_stream(struct hda_codec *codec,
                                  struct hda_cvt_setup *q)
 {
        hda_nid_t nid = q->nid;
-       snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
-       snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0);
+       if (q->stream_tag || q->channel_id)
+               snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
+       if (q->format_id)
+               snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0
+);
        memset(q, 0, sizeof(*q));
        q->nid = nid;
 }
@@ -1688,6 +1699,29 @@ u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid)
 }
 EXPORT_SYMBOL_HDA(snd_hda_query_pin_caps);
 
+/**
+ * snd_hda_override_pin_caps - Override the pin capabilities
+ * @codec: the CODEC
+ * @nid: the NID to override
+ * @caps: the capability bits to set
+ *
+ * Override the cached PIN capabilitiy bits value by the given one.
+ *
+ * Returns zero if successful or a negative error code.
+ */
+int snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid,
+                             unsigned int caps)
+{
+       struct hda_amp_info *info;
+       info = get_alloc_amp_hash(codec, HDA_HASH_PINCAP_KEY(nid));
+       if (!info)
+               return -ENOMEM;
+       info->amp_caps = caps;
+       info->head.val |= INFO_AMP_CAPS;
+       return 0;
+}
+EXPORT_SYMBOL_HDA(snd_hda_override_pin_caps);
+
 /**
  * snd_hda_pin_sense - execute pin sense measurement
  * @codec: the CODEC to sense
@@ -4087,6 +4121,7 @@ static void hda_power_work(struct work_struct *work)
                return;
        }
 
+       trace_hda_power_down(codec);
        hda_call_codec_suspend(codec);
        if (bus->ops.pm_notify)
                bus->ops.pm_notify(bus);
@@ -4125,6 +4160,7 @@ void snd_hda_power_up(struct hda_codec *codec)
        if (codec->power_on || codec->power_transition)
                return;
 
+       trace_hda_power_up(codec);
        snd_hda_update_power_acct(codec);
        codec->power_on = 1;
        codec->power_jiffies = jiffies;
@@ -4537,6 +4573,11 @@ int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
                snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
                                           0, format);
        /* extra outputs copied from front */
+       for (i = 0; i < ARRAY_SIZE(mout->hp_out_nid); i++)
+               if (!mout->no_share_stream && mout->hp_out_nid[i])
+                       snd_hda_codec_setup_stream(codec,
+                                                  mout->hp_out_nid[i],
+                                                  stream_tag, 0, format);
        for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
                if (!mout->no_share_stream && mout->extra_out_nid[i])
                        snd_hda_codec_setup_stream(codec,
@@ -4569,6 +4610,10 @@ int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
                snd_hda_codec_cleanup_stream(codec, nids[i]);
        if (mout->hp_nid)
                snd_hda_codec_cleanup_stream(codec, mout->hp_nid);
+       for (i = 0; i < ARRAY_SIZE(mout->hp_out_nid); i++)
+               if (mout->hp_out_nid[i])
+                       snd_hda_codec_cleanup_stream(codec,
+                                                    mout->hp_out_nid[i]);
        for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
                if (mout->extra_out_nid[i])
                        snd_hda_codec_cleanup_stream(codec,
@@ -4649,6 +4694,27 @@ static void sort_autocfg_input_pins(struct auto_pin_cfg *cfg)
        }
 }
 
+/* Reorder the surround channels
+ * ALSA sequence is front/surr/clfe/side
+ * HDA sequence is:
+ *    4-ch: front/surr  =>  OK as it is
+ *    6-ch: front/clfe/surr
+ *    8-ch: front/clfe/rear/side|fc
+ */
+static void reorder_outputs(unsigned int nums, hda_nid_t *pins)
+{
+       hda_nid_t nid;
+
+       switch (nums) {
+       case 3:
+       case 4:
+               nid = pins[1];
+               pins[1] = pins[2];
+               pins[2] = nid;
+               break;
+       }
+}
+
 /*
  * Parse all pin widgets and store the useful pin nids to cfg
  *
@@ -4666,12 +4732,13 @@ static void sort_autocfg_input_pins(struct auto_pin_cfg *cfg)
  * The digital input/output pins are assigned to dig_in_pin and dig_out_pin,
  * respectively.
  */
-int snd_hda_parse_pin_def_config(struct hda_codec *codec,
-                                struct auto_pin_cfg *cfg,
-                                const hda_nid_t *ignore_nids)
+int snd_hda_parse_pin_defcfg(struct hda_codec *codec,
+                            struct auto_pin_cfg *cfg,
+                            const hda_nid_t *ignore_nids,
+                            unsigned int cond_flags)
 {
        hda_nid_t nid, end_nid;
-       short seq, assoc_line_out, assoc_speaker;
+       short seq, assoc_line_out;
        short sequences_line_out[ARRAY_SIZE(cfg->line_out_pins)];
        short sequences_speaker[ARRAY_SIZE(cfg->speaker_pins)];
        short sequences_hp[ARRAY_SIZE(cfg->hp_pins)];
@@ -4682,7 +4749,7 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
        memset(sequences_line_out, 0, sizeof(sequences_line_out));
        memset(sequences_speaker, 0, sizeof(sequences_speaker));
        memset(sequences_hp, 0, sizeof(sequences_hp));
-       assoc_line_out = assoc_speaker = 0;
+       assoc_line_out = 0;
 
        end_nid = codec->start_nid + codec->num_nodes;
        for (nid = codec->start_nid; nid < end_nid; nid++) {
@@ -4734,16 +4801,10 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
                case AC_JACK_SPEAKER:
                        seq = get_defcfg_sequence(def_conf);
                        assoc = get_defcfg_association(def_conf);
-                       if (!assoc)
-                               continue;
-                       if (!assoc_speaker)
-                               assoc_speaker = assoc;
-                       else if (assoc_speaker != assoc)
-                               continue;
                        if (cfg->speaker_outs >= ARRAY_SIZE(cfg->speaker_pins))
                                continue;
                        cfg->speaker_pins[cfg->speaker_outs] = nid;
-                       sequences_speaker[cfg->speaker_outs] = seq;
+                       sequences_speaker[cfg->speaker_outs] = (assoc << 4) | seq;
                        cfg->speaker_outs++;
                        break;
                case AC_JACK_HP_OUT:
@@ -4792,7 +4853,8 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
         * If no line-out is defined but multiple HPs are found,
         * some of them might be the real line-outs.
         */
-       if (!cfg->line_outs && cfg->hp_outs > 1) {
+       if (!cfg->line_outs && cfg->hp_outs > 1 &&
+           !(cond_flags & HDA_PINCFG_NO_HP_FIXUP)) {
                int i = 0;
                while (i < cfg->hp_outs) {
                        /* The real HPs should have the sequence 0x0f */
@@ -4829,7 +4891,8 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
         * FIX-UP: if no line-outs are detected, try to use speaker or HP pin
         * as a primary output
         */
-       if (!cfg->line_outs) {
+       if (!cfg->line_outs &&
+           !(cond_flags & HDA_PINCFG_NO_LO_FIXUP)) {
                if (cfg->speaker_outs) {
                        cfg->line_outs = cfg->speaker_outs;
                        memcpy(cfg->line_out_pins, cfg->speaker_pins,
@@ -4847,21 +4910,9 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
                }
        }
 
-       /* Reorder the surround channels
-        * ALSA sequence is front/surr/clfe/side
-        * HDA sequence is:
-        *    4-ch: front/surr  =>  OK as it is
-        *    6-ch: front/clfe/surr
-        *    8-ch: front/clfe/rear/side|fc
-        */
-       switch (cfg->line_outs) {
-       case 3:
-       case 4:
-               nid = cfg->line_out_pins[1];
-               cfg->line_out_pins[1] = cfg->line_out_pins[2];
-               cfg->line_out_pins[2] = nid;
-               break;
-       }
+       reorder_outputs(cfg->line_outs, cfg->line_out_pins);
+       reorder_outputs(cfg->hp_outs, cfg->hp_pins);
+       reorder_outputs(cfg->speaker_outs, cfg->speaker_pins);
 
        sort_autocfg_input_pins(cfg);
 
@@ -4899,7 +4950,7 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
 
        return 0;
 }
-EXPORT_SYMBOL_HDA(snd_hda_parse_pin_def_config);
+EXPORT_SYMBOL_HDA(snd_hda_parse_pin_defcfg);
 
 int snd_hda_get_input_pin_attr(unsigned int def_conf)
 {
@@ -5157,30 +5208,6 @@ void snd_array_free(struct snd_array *array)
 }
 EXPORT_SYMBOL_HDA(snd_array_free);
 
-/**
- * snd_print_pcm_rates - Print the supported PCM rates to the string buffer
- * @pcm: PCM caps bits
- * @buf: the string buffer to write
- * @buflen: the max buffer length
- *
- * used by hda_proc.c and hda_eld.c
- */
-void snd_print_pcm_rates(int pcm, char *buf, int buflen)
-{
-       static unsigned int rates[] = {
-               8000, 11025, 16000, 22050, 32000, 44100, 48000, 88200,
-               96000, 176400, 192000, 384000
-       };
-       int i, j;
-
-       for (i = 0, j = 0; i < ARRAY_SIZE(rates); i++)
-               if (pcm & (1 << i))
-                       j += snprintf(buf + j, buflen - j,  " %d", rates[i]);
-
-       buf[j] = '\0'; /* necessary when j == 0 */
-}
-EXPORT_SYMBOL_HDA(snd_print_pcm_rates);
-
 /**
  * snd_print_pcm_bits - Print the supported PCM fmt bits to the string buffer
  * @pcm: PCM caps bits
@@ -5222,6 +5249,8 @@ static const char *get_jack_default_name(struct hda_codec *codec, hda_nid_t nid,
                return "Mic";
        case SND_JACK_LINEOUT:
                return "Line-out";
+       case SND_JACK_LINEIN:
+               return "Line-in";
        case SND_JACK_HEADSET:
                return "Headset";
        case SND_JACK_VIDEOOUT:
index c34f730f481568042b334e4973ae0569f5fdea9b..1c8ddf547a2dde5b1426fdfb6d26261ea35e6872 100644 (file)
@@ -318,6 +318,11 @@ int snd_hdmi_get_eld(struct hdmi_eld *eld,
        int size;
        unsigned char *buf;
 
+       /*
+        * ELD size is initialized to zero in caller function. If no errors and
+        * ELD is valid, actual eld_size is assigned in hdmi_update_eld()
+        */
+
        if (!eld->eld_valid)
                return -ENOENT;
 
@@ -327,14 +332,13 @@ int snd_hdmi_get_eld(struct hdmi_eld *eld,
                snd_printd(KERN_INFO "HDMI: ELD buf size is 0, force 128\n");
                size = 128;
        }
-       if (size < ELD_FIXED_BYTES || size > PAGE_SIZE) {
+       if (size < ELD_FIXED_BYTES || size > ELD_MAX_SIZE) {
                snd_printd(KERN_INFO "HDMI: invalid ELD buf size %d\n", size);
                return -ERANGE;
        }
 
-       buf = kmalloc(size, GFP_KERNEL);
-       if (!buf)
-               return -ENOMEM;
+       /* set ELD buffer */
+       buf = eld->eld_buffer;
 
        for (i = 0; i < size; i++) {
                unsigned int val = hdmi_get_eld_data(codec, nid, i);
@@ -356,10 +360,31 @@ int snd_hdmi_get_eld(struct hdmi_eld *eld,
        ret = hdmi_update_eld(eld, buf, size);
 
 error:
-       kfree(buf);
        return ret;
 }
 
+/**
+ * SNDRV_PCM_RATE_* and AC_PAR_PCM values don't match, print correct rates with
+ * hdmi-specific routine.
+ */
+static void hdmi_print_pcm_rates(int pcm, char *buf, int buflen)
+{
+       static unsigned int alsa_rates[] = {
+               5512, 8000, 11025, 16000, 22050, 32000, 44100, 48000, 88200,
+               96000, 176400, 192000, 384000
+       };
+       int i, j;
+
+       for (i = 0, j = 0; i < ARRAY_SIZE(alsa_rates); i++)
+               if (pcm & (1 << i))
+                       j += snprintf(buf + j, buflen - j,  " %d",
+                               alsa_rates[i]);
+
+       buf[j] = '\0'; /* necessary when j == 0 */
+}
+
+#define SND_PRINT_RATES_ADVISED_BUFSIZE        80
+
 static void hdmi_show_short_audio_desc(struct cea_sad *a)
 {
        char buf[SND_PRINT_RATES_ADVISED_BUFSIZE];
@@ -368,7 +393,7 @@ static void hdmi_show_short_audio_desc(struct cea_sad *a)
        if (!a->format)
                return;
 
-       snd_print_pcm_rates(a->rates, buf, sizeof(buf));
+       hdmi_print_pcm_rates(a->rates, buf, sizeof(buf));
 
        if (a->format == AUDIO_CODING_TYPE_LPCM)
                snd_print_pcm_bits(a->sample_bits, buf2 + 8, sizeof(buf2) - 8);
@@ -427,7 +452,7 @@ static void hdmi_print_sad_info(int i, struct cea_sad *a,
                        i, a->format, cea_audio_coding_type_names[a->format]);
        snd_iprintf(buffer, "sad%d_channels\t\t%d\n", i, a->channels);
 
-       snd_print_pcm_rates(a->rates, buf, sizeof(buf));
+       hdmi_print_pcm_rates(a->rates, buf, sizeof(buf));
        snd_iprintf(buffer, "sad%d_rates\t\t[0x%x]%s\n", i, a->rates, buf);
 
        if (a->format == AUDIO_CODING_TYPE_LPCM) {
index bf3ced51e0f8440ba11b6910311dfcd269d416bc..72e5885007ccfa39887389f644bd06fa1c77bcd2 100644 (file)
@@ -643,14 +643,14 @@ static inline int strmatch(const char *a, const char *b)
 static void parse_codec_mode(char *buf, struct hda_bus *bus,
                             struct hda_codec **codecp)
 {
-       unsigned int vendorid, subid, caddr;
+       int vendorid, subid, caddr;
        struct hda_codec *codec;
 
        *codecp = NULL;
        if (sscanf(buf, "%i %i %i", &vendorid, &subid, &caddr) == 3) {
                list_for_each_entry(codec, &bus->codec_list, list) {
-                       if (codec->vendor_id == vendorid &&
-                           codec->subsystem_id == subid &&
+                       if ((vendorid <= 0 || codec->vendor_id == vendorid) &&
+                           (subid <= 0 || codec->subsystem_id == subid) &&
                            codec->addr == caddr) {
                                *codecp = codec;
                                break;
index 191284a1c0ae0225dfea8f23c277a6390371af87..bd7fc99af18775f2a838ae8e58a1064146b9446a 100644 (file)
@@ -34,7 +34,6 @@
  * 
  */
 
-#include <asm/io.h>
 #include <linux/delay.h>
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
 #include <linux/pci.h>
 #include <linux/mutex.h>
 #include <linux/reboot.h>
+#include <linux/io.h>
+#ifdef CONFIG_X86
+/* for snoop control */
+#include <asm/pgtable.h>
+#include <asm/cacheflush.h>
+#endif
 #include <sound/core.h>
 #include <sound/initval.h>
 #include "hda_codec.h"
@@ -116,6 +121,22 @@ module_param(power_save_controller, bool, 0644);
 MODULE_PARM_DESC(power_save_controller, "Reset controller in power save mode.");
 #endif
 
+static int align_buffer_size = 1;
+module_param(align_buffer_size, bool, 0644);
+MODULE_PARM_DESC(align_buffer_size,
+               "Force buffer and period sizes to be multiple of 128 bytes.");
+
+#ifdef CONFIG_X86
+static bool hda_snoop = true;
+module_param_named(snoop, hda_snoop, bool, 0444);
+MODULE_PARM_DESC(snoop, "Enable/disable snooping");
+#define azx_snoop(chip)                (chip)->snoop
+#else
+#define hda_snoop              true
+#define azx_snoop(chip)                true
+#endif
+
+
 MODULE_LICENSE("GPL");
 MODULE_SUPPORTED_DEVICE("{{Intel, ICH6},"
                         "{Intel, ICH6M},"
@@ -360,7 +381,7 @@ struct azx_dev {
                                         */
        unsigned char stream_tag;       /* assigned stream */
        unsigned char index;            /* stream index */
-       int device;                     /* last device number assigned to */
+       int assigned_key;               /* last device# key assigned to */
 
        unsigned int opened :1;
        unsigned int running :1;
@@ -371,6 +392,7 @@ struct azx_dev {
         *  when link position is not greater than FIFO size
         */
        unsigned int insufficient :1;
+       unsigned int wc_marked:1;
 };
 
 /* CORB/RIRB */
@@ -438,6 +460,7 @@ struct azx {
        unsigned int msi :1;
        unsigned int irq_pending_warned :1;
        unsigned int probing :1; /* codec probing phase */
+       unsigned int snoop:1;
 
        /* for debugging */
        unsigned int last_cmd[AZX_MAX_CODECS];
@@ -481,6 +504,7 @@ enum {
 #define AZX_DCAPS_NO_64BIT     (1 << 18)       /* No 64bit address */
 #define AZX_DCAPS_SYNC_WRITE   (1 << 19)       /* sync each cmd write */
 #define AZX_DCAPS_OLD_SSYNC    (1 << 20)       /* Old SSYNC reg for ICH */
+#define AZX_DCAPS_BUFSIZE      (1 << 21)       /* no buffer size alignment */
 
 /* quirks for ATI SB / AMD Hudson */
 #define AZX_DCAPS_PRESET_ATI_SB \
@@ -542,6 +566,45 @@ static char *driver_short_names[] __devinitdata = {
 /* for pcm support */
 #define get_azx_dev(substream) (substream->runtime->private_data)
 
+#ifdef CONFIG_X86
+static void __mark_pages_wc(struct azx *chip, void *addr, size_t size, bool on)
+{
+       if (azx_snoop(chip))
+               return;
+       if (addr && size) {
+               int pages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
+               if (on)
+                       set_memory_wc((unsigned long)addr, pages);
+               else
+                       set_memory_wb((unsigned long)addr, pages);
+       }
+}
+
+static inline void mark_pages_wc(struct azx *chip, struct snd_dma_buffer *buf,
+                                bool on)
+{
+       __mark_pages_wc(chip, buf->area, buf->bytes, on);
+}
+static inline void mark_runtime_wc(struct azx *chip, struct azx_dev *azx_dev,
+                                  struct snd_pcm_runtime *runtime, bool on)
+{
+       if (azx_dev->wc_marked != on) {
+               __mark_pages_wc(chip, runtime->dma_area, runtime->dma_bytes, on);
+               azx_dev->wc_marked = on;
+       }
+}
+#else
+/* NOP for other archs */
+static inline void mark_pages_wc(struct azx *chip, struct snd_dma_buffer *buf,
+                                bool on)
+{
+}
+static inline void mark_runtime_wc(struct azx *chip, struct azx_dev *azx_dev,
+                                  struct snd_pcm_runtime *runtime, bool on)
+{
+}
+#endif
+
 static int azx_acquire_irq(struct azx *chip, int do_disconnect);
 static int azx_send_cmd(struct hda_bus *bus, unsigned int val);
 /*
@@ -563,6 +626,7 @@ static int azx_alloc_cmd_io(struct azx *chip)
                snd_printk(KERN_ERR SFX "cannot allocate CORB/RIRB\n");
                return err;
        }
+       mark_pages_wc(chip, &chip->rb, true);
        return 0;
 }
 
@@ -1079,7 +1143,15 @@ static void update_pci_byte(struct pci_dev *pci, unsigned int reg,
 
 static void azx_init_pci(struct azx *chip)
 {
-       unsigned short snoop;
+       /* force to non-snoop mode for a new VIA controller when BIOS is set */
+       if (chip->snoop && chip->driver_type == AZX_DRIVER_VIA) {
+               u8 snoop;
+               pci_read_config_byte(chip->pci, 0x42, &snoop);
+               if (!(snoop & 0x80) && chip->pci->revision == 0x30) {
+                       chip->snoop = 0;
+                       snd_printdd(SFX "Force to non-snoop mode\n");
+               }
+       }
 
        /* Clear bits 0-2 of PCI register TCSEL (at offset 0x44)
         * TCSEL == Traffic Class Select Register, which sets PCI express QOS
@@ -1096,15 +1168,15 @@ static void azx_init_pci(struct azx *chip)
         * we need to enable snoop.
         */
        if (chip->driver_caps & AZX_DCAPS_ATI_SNOOP) {
-               snd_printdd(SFX "Enabling ATI snoop\n");
+               snd_printdd(SFX "Setting ATI snoop: %d\n", azx_snoop(chip));
                update_pci_byte(chip->pci,
-                               ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR, 
-                               0x07, ATI_SB450_HDAUDIO_ENABLE_SNOOP);
+                               ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR, 0x07,
+                               azx_snoop(chip) ? ATI_SB450_HDAUDIO_ENABLE_SNOOP : 0);
        }
 
        /* For NVIDIA HDA, enable snoop */
        if (chip->driver_caps & AZX_DCAPS_NVIDIA_SNOOP) {
-               snd_printdd(SFX "Enabling Nvidia snoop\n");
+               snd_printdd(SFX "Setting Nvidia snoop: %d\n", azx_snoop(chip));
                update_pci_byte(chip->pci,
                                NVIDIA_HDA_TRANSREG_ADDR,
                                0x0f, NVIDIA_HDA_ENABLE_COHBITS);
@@ -1118,16 +1190,20 @@ static void azx_init_pci(struct azx *chip)
 
        /* Enable SCH/PCH snoop if needed */
        if (chip->driver_caps & AZX_DCAPS_SCH_SNOOP) {
+               unsigned short snoop;
                pci_read_config_word(chip->pci, INTEL_SCH_HDA_DEVC, &snoop);
-               if (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP) {
-                       pci_write_config_word(chip->pci, INTEL_SCH_HDA_DEVC,
-                               snoop & (~INTEL_SCH_HDA_DEVC_NOSNOOP));
+               if ((!azx_snoop(chip) && !(snoop & INTEL_SCH_HDA_DEVC_NOSNOOP)) ||
+                   (azx_snoop(chip) && (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP))) {
+                       snoop &= ~INTEL_SCH_HDA_DEVC_NOSNOOP;
+                       if (!azx_snoop(chip))
+                               snoop |= INTEL_SCH_HDA_DEVC_NOSNOOP;
+                       pci_write_config_word(chip->pci, INTEL_SCH_HDA_DEVC, snoop);
                        pci_read_config_word(chip->pci,
                                INTEL_SCH_HDA_DEVC, &snoop);
-                       snd_printdd(SFX "HDA snoop disabled, enabling ... %s\n",
-                               (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP)
-                               ? "Failed" : "OK");
                }
+               snd_printdd(SFX "SCH snoop: %s\n",
+                               (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP)
+                               ? "Disabled" : "Enabled");
         }
 }
 
@@ -1334,12 +1410,16 @@ static void azx_stream_reset(struct azx *chip, struct azx_dev *azx_dev)
  */
 static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev)
 {
+       unsigned int val;
        /* make sure the run bit is zero for SD */
        azx_stream_clear(chip, azx_dev);
        /* program the stream_tag */
-       azx_sd_writel(azx_dev, SD_CTL,
-                     (azx_sd_readl(azx_dev, SD_CTL) & ~SD_CTL_STREAM_TAG_MASK)|
-                     (azx_dev->stream_tag << SD_CTL_STREAM_TAG_SHIFT));
+       val = azx_sd_readl(azx_dev, SD_CTL);
+       val = (val & ~SD_CTL_STREAM_TAG_MASK) |
+               (azx_dev->stream_tag << SD_CTL_STREAM_TAG_SHIFT);
+       if (!azx_snoop(chip))
+               val |= SD_CTL_TRAFFIC_PRIO;
+       azx_sd_writel(azx_dev, SD_CTL, val);
 
        /* program the length of samples in cyclic buffer */
        azx_sd_writel(azx_dev, SD_CBL, azx_dev->bufsize);
@@ -1533,6 +1613,9 @@ azx_assign_device(struct azx *chip, struct snd_pcm_substream *substream)
 {
        int dev, i, nums;
        struct azx_dev *res = NULL;
+       /* make a non-zero unique key for the substream */
+       int key = (substream->pcm->device << 16) | (substream->number << 2) |
+               (substream->stream + 1);
 
        if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
                dev = chip->playback_index_offset;
@@ -1544,12 +1627,12 @@ azx_assign_device(struct azx *chip, struct snd_pcm_substream *substream)
        for (i = 0; i < nums; i++, dev++)
                if (!chip->azx_dev[dev].opened) {
                        res = &chip->azx_dev[dev];
-                       if (res->device == substream->pcm->device)
+                       if (res->assigned_key == key)
                                break;
                }
        if (res) {
                res->opened = 1;
-               res->device = substream->pcm->device;
+               res->assigned_key = key;
        }
        return res;
 }
@@ -1599,6 +1682,7 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
        struct snd_pcm_runtime *runtime = substream->runtime;
        unsigned long flags;
        int err;
+       int buff_step;
 
        mutex_lock(&chip->open_mutex);
        azx_dev = azx_assign_device(chip, substream);
@@ -1613,10 +1697,25 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
        runtime->hw.rates = hinfo->rates;
        snd_pcm_limit_hw_rates(runtime);
        snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
+       if (align_buffer_size)
+               /* constrain buffer sizes to be multiple of 128
+                  bytes. This is more efficient in terms of memory
+                  access but isn't required by the HDA spec and
+                  prevents users from specifying exact period/buffer
+                  sizes. For example for 44.1kHz, a period size set
+                  to 20ms will be rounded to 19.59ms. */
+               buff_step = 128;
+       else
+               /* Don't enforce steps on buffer sizes, still need to
+                  be multiple of 4 bytes (HDA spec). Tested on Intel
+                  HDA controllers, may not work on all devices where
+                  option needs to be disabled */
+               buff_step = 4;
+
        snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
-                                  128);
+                                  buff_step);
        snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
-                                  128);
+                                  buff_step);
        snd_hda_power_up(apcm->codec);
        err = hinfo->ops.open(hinfo, apcm->codec, substream);
        if (err < 0) {
@@ -1671,19 +1770,30 @@ static int azx_pcm_close(struct snd_pcm_substream *substream)
 static int azx_pcm_hw_params(struct snd_pcm_substream *substream,
                             struct snd_pcm_hw_params *hw_params)
 {
+       struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
+       struct azx *chip = apcm->chip;
+       struct snd_pcm_runtime *runtime = substream->runtime;
        struct azx_dev *azx_dev = get_azx_dev(substream);
+       int ret;
 
+       mark_runtime_wc(chip, azx_dev, runtime, false);
        azx_dev->bufsize = 0;
        azx_dev->period_bytes = 0;
        azx_dev->format_val = 0;
-       return snd_pcm_lib_malloc_pages(substream,
+       ret = snd_pcm_lib_malloc_pages(substream,
                                        params_buffer_bytes(hw_params));
+       if (ret < 0)
+               return ret;
+       mark_runtime_wc(chip, azx_dev, runtime, true);
+       return ret;
 }
 
 static int azx_pcm_hw_free(struct snd_pcm_substream *substream)
 {
        struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
        struct azx_dev *azx_dev = get_azx_dev(substream);
+       struct azx *chip = apcm->chip;
+       struct snd_pcm_runtime *runtime = substream->runtime;
        struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
 
        /* reset BDL address */
@@ -1696,6 +1806,7 @@ static int azx_pcm_hw_free(struct snd_pcm_substream *substream)
 
        snd_hda_codec_cleanup(apcm->codec, hinfo, substream);
 
+       mark_runtime_wc(chip, azx_dev, runtime, false);
        return snd_pcm_lib_free_pages(substream);
 }
 
@@ -2055,6 +2166,20 @@ static void azx_clear_irq_pending(struct azx *chip)
        spin_unlock_irq(&chip->reg_lock);
 }
 
+#ifdef CONFIG_X86
+static int azx_pcm_mmap(struct snd_pcm_substream *substream,
+                       struct vm_area_struct *area)
+{
+       struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
+       struct azx *chip = apcm->chip;
+       if (!azx_snoop(chip))
+               area->vm_page_prot = pgprot_writecombine(area->vm_page_prot);
+       return snd_pcm_lib_default_mmap(substream, area);
+}
+#else
+#define azx_pcm_mmap   NULL
+#endif
+
 static struct snd_pcm_ops azx_pcm_ops = {
        .open = azx_pcm_open,
        .close = azx_pcm_close,
@@ -2064,6 +2189,7 @@ static struct snd_pcm_ops azx_pcm_ops = {
        .prepare = azx_pcm_prepare,
        .trigger = azx_pcm_trigger,
        .pointer = azx_pcm_pointer,
+       .mmap = azx_pcm_mmap,
        .page = snd_pcm_sgbuf_ops_page,
 };
 
@@ -2344,13 +2470,19 @@ static int azx_free(struct azx *chip)
 
        if (chip->azx_dev) {
                for (i = 0; i < chip->num_streams; i++)
-                       if (chip->azx_dev[i].bdl.area)
+                       if (chip->azx_dev[i].bdl.area) {
+                               mark_pages_wc(chip, &chip->azx_dev[i].bdl, false);
                                snd_dma_free_pages(&chip->azx_dev[i].bdl);
+                       }
        }
-       if (chip->rb.area)
+       if (chip->rb.area) {
+               mark_pages_wc(chip, &chip->rb, false);
                snd_dma_free_pages(&chip->rb);
-       if (chip->posbuf.area)
+       }
+       if (chip->posbuf.area) {
+               mark_pages_wc(chip, &chip->posbuf, false);
                snd_dma_free_pages(&chip->posbuf);
+       }
        pci_release_regions(chip->pci);
        pci_disable_device(chip->pci);
        kfree(chip->azx_dev);
@@ -2546,6 +2678,7 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
        check_probe_mask(chip, dev);
 
        chip->single_cmd = single_cmd;
+       chip->snoop = hda_snoop;
 
        if (bdl_pos_adj[dev] < 0) {
                switch (chip->driver_type) {
@@ -2618,6 +2751,10 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
                gcap &= ~ICH6_GCAP_64OK;
        }
 
+       /* disable buffer size rounding to 128-byte multiples if supported */
+       if (chip->driver_caps & AZX_DCAPS_BUFSIZE)
+               align_buffer_size = 0;
+
        /* allow 64bit DMA address if supported by H/W */
        if ((gcap & ICH6_GCAP_64OK) && !pci_set_dma_mask(pci, DMA_BIT_MASK(64)))
                pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(64));
@@ -2669,6 +2806,7 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
                        snd_printk(KERN_ERR SFX "cannot allocate BDL\n");
                        goto errout;
                }
+               mark_pages_wc(chip, &chip->azx_dev[i].bdl, true);
        }
        /* allocate memory for the position buffer */
        err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
@@ -2678,6 +2816,7 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
                snd_printk(KERN_ERR SFX "cannot allocate posbuf\n");
                goto errout;
        }
+       mark_pages_wc(chip, &chip->posbuf, true);
        /* allocate CORB/RIRB */
        err = azx_alloc_cmd_io(chip);
        if (err < 0)
@@ -2819,37 +2958,49 @@ static void __devexit azx_remove(struct pci_dev *pci)
 static DEFINE_PCI_DEVICE_TABLE(azx_ids) = {
        /* CPT */
        { PCI_DEVICE(0x8086, 0x1c20),
-         .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_SCH_SNOOP },
+         .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_SCH_SNOOP |
+         AZX_DCAPS_BUFSIZE },
        /* PBG */
        { PCI_DEVICE(0x8086, 0x1d20),
-         .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_SCH_SNOOP },
+         .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_SCH_SNOOP |
+         AZX_DCAPS_BUFSIZE},
        /* Panther Point */
        { PCI_DEVICE(0x8086, 0x1e20),
-         .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_SCH_SNOOP },
+         .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_SCH_SNOOP |
+         AZX_DCAPS_BUFSIZE},
        /* SCH */
        { PCI_DEVICE(0x8086, 0x811b),
-         .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_SCH_SNOOP },
+         .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_SCH_SNOOP |
+         AZX_DCAPS_BUFSIZE},
        { PCI_DEVICE(0x8086, 0x2668),
-         .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC },  /* ICH6 */
+         .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC |
+         AZX_DCAPS_BUFSIZE },  /* ICH6 */
        { PCI_DEVICE(0x8086, 0x27d8),
-         .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC },  /* ICH7 */
+         .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC |
+         AZX_DCAPS_BUFSIZE },  /* ICH7 */
        { PCI_DEVICE(0x8086, 0x269a),
-         .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC },  /* ESB2 */
+         .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC |
+         AZX_DCAPS_BUFSIZE },  /* ESB2 */
        { PCI_DEVICE(0x8086, 0x284b),
-         .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC },  /* ICH8 */
+         .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC |
+         AZX_DCAPS_BUFSIZE },  /* ICH8 */
        { PCI_DEVICE(0x8086, 0x293e),
-         .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC },  /* ICH9 */
+         .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC |
+         AZX_DCAPS_BUFSIZE },  /* ICH9 */
        { PCI_DEVICE(0x8086, 0x293f),
-         .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC },  /* ICH9 */
+         .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC |
+         AZX_DCAPS_BUFSIZE },  /* ICH9 */
        { PCI_DEVICE(0x8086, 0x3a3e),
-         .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC },  /* ICH10 */
+         .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC |
+         AZX_DCAPS_BUFSIZE },  /* ICH10 */
        { PCI_DEVICE(0x8086, 0x3a6e),
-         .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC },  /* ICH10 */
+         .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC |
+         AZX_DCAPS_BUFSIZE },  /* ICH10 */
        /* Generic Intel */
        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_ANY_ID),
          .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
          .class_mask = 0xffffff,
-         .driver_data = AZX_DRIVER_ICH },
+         .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_BUFSIZE },
        /* ATI SB 450/600/700/800/900 */
        { PCI_DEVICE(0x1002, 0x437b),
          .driver_data = AZX_DRIVER_ATI | AZX_DCAPS_PRESET_ATI_SB },
index 2e7ac31afa8df9b320c0e263c1754df5620c7357..81e12c0ed0a2aa260a8f2725a2138a0ddbbf40e4 100644 (file)
@@ -267,11 +267,14 @@ int snd_hda_ch_mode_put(struct hda_codec *codec,
 enum { HDA_FRONT, HDA_REAR, HDA_CLFE, HDA_SIDE }; /* index for dac_nidx */
 enum { HDA_DIG_NONE, HDA_DIG_EXCLUSIVE, HDA_DIG_ANALOG_DUP }; /* dig_out_used */
 
+#define HDA_MAX_OUTS   5
+
 struct hda_multi_out {
        int num_dacs;           /* # of DACs, must be more than 1 */
        const hda_nid_t *dac_nids;      /* DAC list */
        hda_nid_t hp_nid;       /* optional DAC for HP, 0 when not exists */
-       hda_nid_t extra_out_nid[3];     /* optional DACs, 0 when not exists */
+       hda_nid_t hp_out_nid[HDA_MAX_OUTS];     /* DACs for multiple HPs */
+       hda_nid_t extra_out_nid[HDA_MAX_OUTS];  /* other (e.g. speaker) DACs */
        hda_nid_t dig_out_nid;  /* digital out audio widget */
        const hda_nid_t *slave_dig_outs;
        int max_channels;       /* currently supported analog channels */
@@ -333,9 +336,6 @@ int snd_hda_codec_proc_new(struct hda_codec *codec);
 static inline int snd_hda_codec_proc_new(struct hda_codec *codec) { return 0; }
 #endif
 
-#define SND_PRINT_RATES_ADVISED_BUFSIZE        80
-void snd_print_pcm_rates(int pcm, char *buf, int buflen);
-
 #define SND_PRINT_BITS_ADVISED_BUFSIZE 16
 void snd_print_pcm_bits(int pcm, char *buf, int buflen);
 
@@ -385,7 +385,7 @@ enum {
        AUTO_PIN_HP_OUT
 };
 
-#define AUTO_CFG_MAX_OUTS      5
+#define AUTO_CFG_MAX_OUTS      HDA_MAX_OUTS
 #define AUTO_CFG_MAX_INS       8
 
 struct auto_pin_cfg_item {
@@ -443,9 +443,18 @@ struct auto_pin_cfg {
 #define get_defcfg_device(cfg) \
        ((cfg & AC_DEFCFG_DEVICE) >> AC_DEFCFG_DEVICE_SHIFT)
 
-int snd_hda_parse_pin_def_config(struct hda_codec *codec,
-                                struct auto_pin_cfg *cfg,
-                                const hda_nid_t *ignore_nids);
+/* bit-flags for snd_hda_parse_pin_def_config() behavior */
+#define HDA_PINCFG_NO_HP_FIXUP (1 << 0) /* no HP-split */
+#define HDA_PINCFG_NO_LO_FIXUP (1 << 1) /* don't take other outs as LO */
+
+int snd_hda_parse_pin_defcfg(struct hda_codec *codec,
+                            struct auto_pin_cfg *cfg,
+                            const hda_nid_t *ignore_nids,
+                            unsigned int cond_flags);
+
+/* older function */
+#define snd_hda_parse_pin_def_config(codec, cfg, ignore) \
+       snd_hda_parse_pin_defcfg(codec, cfg, ignore, 0)
 
 /* amp values */
 #define AMP_IN_MUTE(idx)       (0x7080 | ((idx)<<8))
@@ -492,6 +501,8 @@ u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction);
 int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
                              unsigned int caps);
 u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid);
+int snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid,
+                             unsigned int caps);
 u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid);
 int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid);
 
@@ -589,7 +600,8 @@ int snd_hda_check_amp_list_power(struct hda_codec *codec,
 #define get_amp_nid_(pv)       ((pv) & 0xffff)
 #define get_amp_nid(kc)                get_amp_nid_((kc)->private_value)
 #define get_amp_channels(kc)   (((kc)->private_value >> 16) & 0x3)
-#define get_amp_direction(kc)  (((kc)->private_value >> 18) & 0x1)
+#define get_amp_direction_(pv) (((pv) >> 18) & 0x1)
+#define get_amp_direction(kc)  get_amp_direction_((kc)->private_value)
 #define get_amp_index(kc)      (((kc)->private_value >> 19) & 0xf)
 #define get_amp_offset(kc)     (((kc)->private_value >> 23) & 0x3f)
 #define get_amp_min_mute(kc)   (((kc)->private_value >> 29) & 0x1)
@@ -607,6 +619,7 @@ struct cea_sad {
 };
 
 #define ELD_FIXED_BYTES        20
+#define ELD_MAX_SIZE    256
 #define ELD_MAX_MNL    16
 #define ELD_MAX_SAD    16
 
@@ -631,6 +644,7 @@ struct hdmi_eld {
        int     spk_alloc;
        int     sad_count;
        struct cea_sad sad[ELD_MAX_SAD];
+       char    eld_buffer[ELD_MAX_SIZE];
 #ifdef CONFIG_PROC_FS
        struct snd_info_entry *proc_entry;
 #endif
index 2be57b051aa27c60145d808899cf0375b0b2f6e0..2c981b55940b1d170971ea703fe13d21d563cb49 100644 (file)
@@ -152,12 +152,18 @@ static void print_amp_vals(struct snd_info_buffer *buffer,
 
 static void print_pcm_rates(struct snd_info_buffer *buffer, unsigned int pcm)
 {
-       char buf[SND_PRINT_RATES_ADVISED_BUFSIZE];
+       static unsigned int rates[] = {
+               8000, 11025, 16000, 22050, 32000, 44100, 48000, 88200,
+               96000, 176400, 192000, 384000
+       };
+       int i;
 
        pcm &= AC_SUPPCM_RATES;
        snd_iprintf(buffer, "    rates [0x%x]:", pcm);
-       snd_print_pcm_rates(pcm, buf, sizeof(buf));
-       snd_iprintf(buffer, "%s\n", buf);
+       for (i = 0; i < ARRAY_SIZE(rates); i++)
+               if (pcm & (1 << i))
+                       snd_iprintf(buffer,  " %d", rates[i]);
+       snd_iprintf(buffer, "\n");
 }
 
 static void print_pcm_bits(struct snd_info_buffer *buffer, unsigned int pcm)
diff --git a/sound/pci/hda/hda_trace.h b/sound/pci/hda/hda_trace.h
new file mode 100644 (file)
index 0000000..9884871
--- /dev/null
@@ -0,0 +1,117 @@
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM hda
+#define TRACE_INCLUDE_FILE hda_trace
+
+#if !defined(_TRACE_HDA_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_HDA_H
+
+#include <linux/tracepoint.h>
+
+struct hda_bus;
+struct hda_codec;
+
+DECLARE_EVENT_CLASS(hda_cmd,
+
+       TP_PROTO(struct hda_codec *codec, unsigned int val),
+
+       TP_ARGS(codec, val),
+
+       TP_STRUCT__entry(
+               __field( unsigned int, card )
+               __field( unsigned int, addr )
+               __field( unsigned int, val )
+       ),
+
+       TP_fast_assign(
+               __entry->card = (codec)->bus->card->number;
+               __entry->addr = (codec)->addr;
+               __entry->val = (val);
+       ),
+
+       TP_printk("[%d:%d] val=%x", __entry->card, __entry->addr, __entry->val)
+);
+
+DEFINE_EVENT(hda_cmd, hda_send_cmd,
+       TP_PROTO(struct hda_codec *codec, unsigned int val),
+       TP_ARGS(codec, val)
+);
+
+DEFINE_EVENT(hda_cmd, hda_get_response,
+       TP_PROTO(struct hda_codec *codec, unsigned int val),
+       TP_ARGS(codec, val)
+);
+
+TRACE_EVENT(hda_bus_reset,
+
+       TP_PROTO(struct hda_bus *bus),
+
+       TP_ARGS(bus),
+
+       TP_STRUCT__entry(
+               __field( unsigned int, card )
+       ),
+
+       TP_fast_assign(
+               __entry->card = (bus)->card->number;
+       ),
+
+       TP_printk("[%d]", __entry->card)
+);
+
+DECLARE_EVENT_CLASS(hda_power,
+
+       TP_PROTO(struct hda_codec *codec),
+
+       TP_ARGS(codec),
+
+       TP_STRUCT__entry(
+               __field( unsigned int, card )
+               __field( unsigned int, addr )
+       ),
+
+       TP_fast_assign(
+               __entry->card = (codec)->bus->card->number;
+               __entry->addr = (codec)->addr;
+       ),
+
+       TP_printk("[%d:%d]", __entry->card, __entry->addr)
+);
+
+DEFINE_EVENT(hda_power, hda_power_down,
+       TP_PROTO(struct hda_codec *codec),
+       TP_ARGS(codec)
+);
+
+DEFINE_EVENT(hda_power, hda_power_up,
+       TP_PROTO(struct hda_codec *codec),
+       TP_ARGS(codec)
+);
+
+TRACE_EVENT(hda_unsol_event,
+
+       TP_PROTO(struct hda_bus *bus, u32 res, u32 res_ex),
+
+       TP_ARGS(bus, res, res_ex),
+
+       TP_STRUCT__entry(
+               __field( unsigned int, card )
+               __field( u32, res )
+               __field( u32, res_ex )
+       ),
+
+       TP_fast_assign(
+               __entry->card = (bus)->card->number;
+               __entry->res = res;
+               __entry->res_ex = res_ex;
+       ),
+
+       TP_printk("[%d] res=%x, res_ex=%x", __entry->card,
+                 __entry->res, __entry->res_ex)
+);
+
+#endif /* _TRACE_HDA_H */
+
+/* This part must be outside protection */
+#undef TRACE_INCLUDE_PATH
+#define TRACE_INCLUDE_PATH .
+#include <trace/define_trace.h>
index 8648917acffb57f3af713ef7e9f57828e04b8ef4..d8aac588f23ba3b827a6ffa34199065c29103e93 100644 (file)
@@ -48,6 +48,8 @@ struct ad198x_spec {
 
        const hda_nid_t *alt_dac_nid;
        const struct hda_pcm_stream *stream_analog_alt_playback;
+       int independent_hp;
+       int num_active_streams;
 
        /* capture */
        unsigned int num_adc_nids;
@@ -302,6 +304,72 @@ static int ad198x_check_power_status(struct hda_codec *codec, hda_nid_t nid)
 }
 #endif
 
+static void activate_ctl(struct hda_codec *codec, const char *name, int active)
+{
+       struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
+       if (ctl) {
+               ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
+               ctl->vd[0].access |= active ? 0 :
+                       SNDRV_CTL_ELEM_ACCESS_INACTIVE;
+               ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_WRITE;
+               ctl->vd[0].access |= active ?
+                       SNDRV_CTL_ELEM_ACCESS_WRITE : 0;
+               snd_ctl_notify(codec->bus->card,
+                              SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
+       }
+}
+
+static void set_stream_active(struct hda_codec *codec, bool active)
+{
+       struct ad198x_spec *spec = codec->spec;
+       if (active)
+               spec->num_active_streams++;
+       else
+               spec->num_active_streams--;
+       activate_ctl(codec, "Independent HP", spec->num_active_streams == 0);
+}
+
+static int ad1988_independent_hp_info(struct snd_kcontrol *kcontrol,
+                                  struct snd_ctl_elem_info *uinfo)
+{
+       static const char * const texts[] = { "OFF", "ON", NULL};
+       int index;
+       uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+       uinfo->count = 1;
+       uinfo->value.enumerated.items = 2;
+       index = uinfo->value.enumerated.item;
+       if (index >= 2)
+               index = 1;
+       strcpy(uinfo->value.enumerated.name, texts[index]);
+       return 0;
+}
+
+static int ad1988_independent_hp_get(struct snd_kcontrol *kcontrol,
+                                 struct snd_ctl_elem_value *ucontrol)
+{
+       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
+       struct ad198x_spec *spec = codec->spec;
+       ucontrol->value.enumerated.item[0] = spec->independent_hp;
+       return 0;
+}
+
+static int ad1988_independent_hp_put(struct snd_kcontrol *kcontrol,
+                                 struct snd_ctl_elem_value *ucontrol)
+{
+       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
+       struct ad198x_spec *spec = codec->spec;
+       unsigned int select = ucontrol->value.enumerated.item[0];
+       if (spec->independent_hp != select) {
+               spec->independent_hp = select;
+               if (spec->independent_hp)
+                       spec->multiout.hp_nid = 0;
+               else
+                       spec->multiout.hp_nid = spec->alt_dac_nid[0];
+               return 1;
+       }
+       return 0;
+}
+
 /*
  * Analog playback callbacks
  */
@@ -310,8 +378,15 @@ static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
                                    struct snd_pcm_substream *substream)
 {
        struct ad198x_spec *spec = codec->spec;
-       return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
+       int err;
+       set_stream_active(codec, true);
+       err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
                                             hinfo);
+       if (err < 0) {
+               set_stream_active(codec, false);
+               return err;
+       }
+       return 0;
 }
 
 static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
@@ -333,11 +408,41 @@ static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
        return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
 }
 
+static int ad198x_playback_pcm_close(struct hda_pcm_stream *hinfo,
+                                struct hda_codec *codec,
+                                struct snd_pcm_substream *substream)
+{
+       set_stream_active(codec, false);
+       return 0;
+}
+
+static int ad1988_alt_playback_pcm_open(struct hda_pcm_stream *hinfo,
+                                struct hda_codec *codec,
+                                struct snd_pcm_substream *substream)
+{
+       struct ad198x_spec *spec = codec->spec;
+       if (!spec->independent_hp)
+               return -EBUSY;
+       set_stream_active(codec, true);
+       return 0;
+}
+
+static int ad1988_alt_playback_pcm_close(struct hda_pcm_stream *hinfo,
+                                struct hda_codec *codec,
+                                struct snd_pcm_substream *substream)
+{
+       set_stream_active(codec, false);
+       return 0;
+}
+
 static const struct hda_pcm_stream ad198x_pcm_analog_alt_playback = {
        .substreams = 1,
        .channels_min = 2,
        .channels_max = 2,
-       /* NID is set in ad198x_build_pcms */
+       .ops = {
+               .open  = ad1988_alt_playback_pcm_open,
+               .close = ad1988_alt_playback_pcm_close
+       },
 };
 
 /*
@@ -402,7 +507,6 @@ static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
        return 0;
 }
 
-
 /*
  */
 static const struct hda_pcm_stream ad198x_pcm_analog_playback = {
@@ -413,7 +517,8 @@ static const struct hda_pcm_stream ad198x_pcm_analog_playback = {
        .ops = {
                .open = ad198x_playback_pcm_open,
                .prepare = ad198x_playback_pcm_prepare,
-               .cleanup = ad198x_playback_pcm_cleanup
+               .cleanup = ad198x_playback_pcm_cleanup,
+               .close = ad198x_playback_pcm_close
        },
 };
 
@@ -2058,7 +2163,6 @@ static int patch_ad1981(struct hda_codec *codec)
 enum {
        AD1988_6STACK,
        AD1988_6STACK_DIG,
-       AD1988_6STACK_DIG_FP,
        AD1988_3STACK,
        AD1988_3STACK_DIG,
        AD1988_LAPTOP,
@@ -2168,6 +2272,17 @@ static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
        return err;
 }
 
+static const struct snd_kcontrol_new ad1988_hp_mixers[] = {
+       {
+               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+               .name = "Independent HP",
+               .info = ad1988_independent_hp_info,
+               .get = ad1988_independent_hp_get,
+               .put = ad1988_independent_hp_put,
+       },
+       { } /* end */
+};
+
 /* 6-stack mode */
 static const struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
        HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
@@ -2188,6 +2303,7 @@ static const struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
 };
 
 static const struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
+       HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
        HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
        HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
        HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
@@ -2210,13 +2326,6 @@ static const struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
 
        HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
        HDA_CODEC_VOLUME("Mic Boost Volume", 0x3c, 0x0, HDA_OUTPUT),
-
-       { } /* end */
-};
-
-static const struct snd_kcontrol_new ad1988_6stack_fp_mixers[] = {
-       HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
-
        { } /* end */
 };
 
@@ -2238,6 +2347,7 @@ static const struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
 };
 
 static const struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
+       HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
        HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
        HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
        HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
@@ -2272,6 +2382,7 @@ static const struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
 
 /* laptop mode */
 static const struct snd_kcontrol_new ad1988_laptop_mixers[] = {
+       HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
        HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
        HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
        HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
@@ -2446,7 +2557,7 @@ static const struct hda_verb ad1988_6stack_init_verbs[] = {
        {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
        {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
        /* Port-A front headphon path */
-       {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
+       {0x37, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC0:03h */
        {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
        {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
        {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
@@ -2594,7 +2705,7 @@ static const struct hda_verb ad1988_3stack_init_verbs[] = {
        {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
        {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
        /* Port-A front headphon path */
-       {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
+       {0x37, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC0:03h */
        {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
        {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
        {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
@@ -2669,7 +2780,7 @@ static const struct hda_verb ad1988_laptop_init_verbs[] = {
        {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
        {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
        /* Port-A front headphon path */
-       {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
+       {0x37, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC0:03h */
        {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
        {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
        {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
@@ -2782,11 +2893,11 @@ static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
 {
        static const hda_nid_t idx_to_dac[8] = {
                /* A     B     C     D     E     F     G     H */
-               0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
+               0x03, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
        };
        static const hda_nid_t idx_to_dac_rev2[8] = {
                /* A     B     C     D     E     F     G     H */
-               0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
+               0x03, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
        };
        if (is_rev2(codec))
                return idx_to_dac_rev2[idx];
@@ -3023,8 +3134,8 @@ static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
        snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
        snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
        switch (nid) {
-       case 0x11: /* port-A - DAC 04 */
-               snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
+       case 0x11: /* port-A - DAC 03 */
+               snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
                break;
        case 0x14: /* port-B - DAC 06 */
                snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
@@ -3150,7 +3261,6 @@ static int ad1988_auto_init(struct hda_codec *codec)
 static const char * const ad1988_models[AD1988_MODEL_LAST] = {
        [AD1988_6STACK]         = "6stack",
        [AD1988_6STACK_DIG]     = "6stack-dig",
-       [AD1988_6STACK_DIG_FP]  = "6stack-dig-fp",
        [AD1988_3STACK]         = "3stack",
        [AD1988_3STACK_DIG]     = "3stack-dig",
        [AD1988_LAPTOP]         = "laptop",
@@ -3208,10 +3318,11 @@ static int patch_ad1988(struct hda_codec *codec)
        }
        set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
 
+       if (!spec->multiout.hp_nid)
+               spec->multiout.hp_nid = ad1988_alt_dac_nid[0];
        switch (board_config) {
        case AD1988_6STACK:
        case AD1988_6STACK_DIG:
-       case AD1988_6STACK_DIG_FP:
                spec->multiout.max_channels = 8;
                spec->multiout.num_dacs = 4;
                if (is_rev2(codec))
@@ -3227,19 +3338,7 @@ static int patch_ad1988(struct hda_codec *codec)
                spec->mixers[1] = ad1988_6stack_mixers2;
                spec->num_init_verbs = 1;
                spec->init_verbs[0] = ad1988_6stack_init_verbs;
-               if (board_config == AD1988_6STACK_DIG_FP) {
-                       spec->num_mixers++;
-                       spec->mixers[2] = ad1988_6stack_fp_mixers;
-                       spec->num_init_verbs++;
-                       spec->init_verbs[1] = ad1988_6stack_fp_init_verbs;
-                       spec->slave_vols = ad1988_6stack_fp_slave_vols;
-                       spec->slave_sws = ad1988_6stack_fp_slave_sws;
-                       spec->alt_dac_nid = ad1988_alt_dac_nid;
-                       spec->stream_analog_alt_playback =
-                               &ad198x_pcm_analog_alt_playback;
-               }
-               if ((board_config == AD1988_6STACK_DIG) ||
-                       (board_config == AD1988_6STACK_DIG_FP)) {
+               if (board_config == AD1988_6STACK_DIG) {
                        spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
                        spec->dig_in_nid = AD1988_SPDIF_IN;
                }
@@ -3282,6 +3381,15 @@ static int patch_ad1988(struct hda_codec *codec)
                break;
        }
 
+       if (spec->autocfg.hp_pins[0]) {
+               spec->mixers[spec->num_mixers++] = ad1988_hp_mixers;
+               spec->slave_vols = ad1988_6stack_fp_slave_vols;
+               spec->slave_sws = ad1988_6stack_fp_slave_sws;
+               spec->alt_dac_nid = ad1988_alt_dac_nid;
+               spec->stream_analog_alt_playback =
+                       &ad198x_pcm_analog_alt_playback;
+       }
+
        spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
        spec->adc_nids = ad1988_adc_nids;
        spec->capsrc_nids = ad1988_capsrc_nids;
index 76752d8ea73305b3bd0c15fa910319b6d3b9544e..0c8b5a1993edbc277ec95e4e12a30dbc3361f837 100644 (file)
@@ -136,6 +136,8 @@ struct conexant_spec {
        unsigned int thinkpad:1;
        unsigned int hp_laptop:1;
        unsigned int asus:1;
+       unsigned int pin_eapd_ctrls:1;
+       unsigned int single_adc_amp:1;
 
        unsigned int adc_switching:1;
 
@@ -1867,39 +1869,6 @@ static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
        { } /* end */
 };
 
-static const struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
-       /* Line in, Mic */
-       {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
-       {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
-       {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
-       {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
-       {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
-       {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
-       /* SPK  */
-       {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
-       {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
-       /* HP, Amp  */
-       {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
-       /* Docking HP */
-       {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
-       {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
-       /* DAC1 */
-       {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
-       /* Record selector: Internal mic */
-       {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
-       {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
-       /* SPDIF route: PCM */
-       {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */
-       {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
-       /* EAPD */
-       {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
-       {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
-       {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
-       { } /* end */
-};
-
 static const struct hda_verb cxt5051_f700_init_verbs[] = {
        /* Line in, Mic */
        {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
@@ -1968,7 +1937,6 @@ enum {
        CXT5051_LAPTOP,  /* Laptops w/ EAPD support */
        CXT5051_HP,     /* no docking */
        CXT5051_HP_DV6736,      /* HP without mic switch */
-       CXT5051_LENOVO_X200,    /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
        CXT5051_F700,       /* HP Compaq Presario F700 */
        CXT5051_TOSHIBA,        /* Toshiba M300 & co */
        CXT5051_IDEAPAD,        /* Lenovo IdeaPad Y430 */
@@ -1980,7 +1948,6 @@ static const char *const cxt5051_models[CXT5051_MODELS] = {
        [CXT5051_LAPTOP]        = "laptop",
        [CXT5051_HP]            = "hp",
        [CXT5051_HP_DV6736]     = "hp-dv6736",
-       [CXT5051_LENOVO_X200]   = "lenovo-x200",
        [CXT5051_F700]          = "hp-700",
        [CXT5051_TOSHIBA]       = "toshiba",
        [CXT5051_IDEAPAD]       = "ideapad",
@@ -1995,7 +1962,6 @@ static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
        SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
                      CXT5051_LAPTOP),
        SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
-       SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
        SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
        {}
 };
@@ -2053,13 +2019,6 @@ static int patch_cxt5051(struct hda_codec *codec)
                spec->mixers[0] = cxt5051_hp_dv6736_mixers;
                spec->auto_mic = 0;
                break;
-       case CXT5051_LENOVO_X200:
-               spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
-               /* Thinkpad X301 does not have S/PDIF wired and no ability
-                  to use a docking station. */
-               if (codec->subsystem_id == 0x17aa211f)
-                       spec->multiout.dig_out_nid = 0;
-               break;
        case CXT5051_F700:
                spec->init_verbs[0] = cxt5051_f700_init_verbs;
                spec->mixers[0] = cxt5051_f700_mixers;
@@ -3473,12 +3432,14 @@ static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
 static void do_automute(struct hda_codec *codec, int num_pins,
                        hda_nid_t *pins, bool on)
 {
+       struct conexant_spec *spec = codec->spec;
        int i;
        for (i = 0; i < num_pins; i++)
                snd_hda_codec_write(codec, pins[i], 0,
                                    AC_VERB_SET_PIN_WIDGET_CONTROL,
                                    on ? PIN_OUT : 0);
-       cx_auto_turn_eapd(codec, num_pins, pins, on);
+       if (spec->pin_eapd_ctrls)
+               cx_auto_turn_eapd(codec, num_pins, pins, on);
 }
 
 static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
@@ -3503,9 +3464,12 @@ static void cx_auto_update_speakers(struct hda_codec *codec)
        int on = 1;
 
        /* turn on HP EAPD when HP jacks are present */
-       if (spec->auto_mute)
-               on = spec->hp_present;
-       cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
+       if (spec->pin_eapd_ctrls) {
+               if (spec->auto_mute)
+                       on = spec->hp_present;
+               cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
+       }
+
        /* mute speakers in auto-mode if HP or LO jacks are plugged */
        if (spec->auto_mute)
                on = !(spec->hp_present ||
@@ -3932,20 +3896,10 @@ static void cx_auto_parse_beep(struct hda_codec *codec)
 #define cx_auto_parse_beep(codec)
 #endif
 
-static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
-{
-       int i;
-       for (i = 0; i < nums; i++)
-               if (list[i] == nid)
-                       return true;
-       return false;
-}
-
-/* parse extra-EAPD that aren't assigned to any pins */
+/* parse EAPDs */
 static void cx_auto_parse_eapd(struct hda_codec *codec)
 {
        struct conexant_spec *spec = codec->spec;
-       struct auto_pin_cfg *cfg = &spec->autocfg;
        hda_nid_t nid, end_nid;
 
        end_nid = codec->start_nid + codec->num_nodes;
@@ -3954,14 +3908,18 @@ static void cx_auto_parse_eapd(struct hda_codec *codec)
                        continue;
                if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
                        continue;
-               if (found_in_nid_list(nid, cfg->line_out_pins, cfg->line_outs) ||
-                   found_in_nid_list(nid, cfg->hp_pins, cfg->hp_outs) ||
-                   found_in_nid_list(nid, cfg->speaker_pins, cfg->speaker_outs))
-                       continue;
                spec->eapds[spec->num_eapds++] = nid;
                if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
                        break;
        }
+
+       /* NOTE: below is a wild guess; if we have more than two EAPDs,
+        * it's a new chip, where EAPDs are supposed to be associated to
+        * pins, and we can control EAPD per pin.
+        * OTOH, if only one or two EAPDs are found, it's an old chip,
+        * thus it might control over all pins.
+        */
+       spec->pin_eapd_ctrls = spec->num_eapds > 2;
 }
 
 static int cx_auto_parse_auto_config(struct hda_codec *codec)
@@ -4067,8 +4025,9 @@ static void cx_auto_init_output(struct hda_codec *codec)
                }
        }
        cx_auto_update_speakers(codec);
-       /* turn on/off extra EAPDs, too */
-       cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
+       /* turn on all EAPDs if no individual EAPD control is available */
+       if (!spec->pin_eapd_ctrls)
+               cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
 }
 
 static void cx_auto_init_input(struct hda_codec *codec)
@@ -4255,6 +4214,8 @@ static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
                int idx = get_input_connection(codec, adc_nid, nid);
                if (idx < 0)
                        continue;
+               if (spec->single_adc_amp)
+                       idx = 0;
                return cx_auto_add_volume_idx(codec, label, pfx,
                                              cidx, adc_nid, HDA_INPUT, idx);
        }
@@ -4295,14 +4256,21 @@ static int cx_auto_build_input_controls(struct hda_codec *codec)
        struct hda_input_mux *imux = &spec->private_imux;
        const char *prev_label;
        int input_conn[HDA_MAX_NUM_INPUTS];
-       int i, err, cidx;
+       int i, j, err, cidx;
        int multi_connection;
 
+       if (!imux->num_items)
+               return 0;
+
        multi_connection = 0;
        for (i = 0; i < imux->num_items; i++) {
                cidx = get_input_connection(codec, spec->imux_info[i].adc,
                                            spec->imux_info[i].pin);
-               input_conn[i] = (spec->imux_info[i].adc << 8) | cidx;
+               if (cidx < 0)
+                       continue;
+               input_conn[i] = spec->imux_info[i].adc;
+               if (!spec->single_adc_amp)
+                       input_conn[i] |= cidx << 8;
                if (i > 0 && input_conn[i] != input_conn[0])
                        multi_connection = 1;
        }
@@ -4331,6 +4299,15 @@ static int cx_auto_build_input_controls(struct hda_codec *codec)
                        err = cx_auto_add_capture_volume(codec, nid,
                                                         "Capture", "", cidx);
                } else {
+                       bool dup_found = false;
+                       for (j = 0; j < i; j++) {
+                               if (input_conn[j] == input_conn[i]) {
+                                       dup_found = true;
+                                       break;
+                               }
+                       }
+                       if (dup_found)
+                               continue;
                        err = cx_auto_add_capture_volume(codec, nid,
                                                         label, " Capture", cidx);
                }
@@ -4394,6 +4371,53 @@ static const struct hda_codec_ops cx_auto_patch_ops = {
        .reboot_notify = snd_hda_shutup_pins,
 };
 
+/*
+ * pin fix-up
+ */
+struct cxt_pincfg {
+       hda_nid_t nid;
+       u32 val;
+};
+
+static void apply_pincfg(struct hda_codec *codec, const struct cxt_pincfg *cfg)
+{
+       for (; cfg->nid; cfg++)
+               snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
+
+}
+
+static void apply_pin_fixup(struct hda_codec *codec,
+                           const struct snd_pci_quirk *quirk,
+                           const struct cxt_pincfg **table)
+{
+       quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
+       if (quirk) {
+               snd_printdd(KERN_INFO "hda_codec: applying pincfg for %s\n",
+                           quirk->name);
+               apply_pincfg(codec, table[quirk->value]);
+       }
+}
+
+enum {
+       CXT_PINCFG_LENOVO_X200,
+};
+
+static const struct cxt_pincfg cxt_pincfg_lenovo_x200[] = {
+       { 0x16, 0x042140ff }, /* HP (seq# overridden) */
+       { 0x17, 0x21a11000 }, /* dock-mic */
+       { 0x19, 0x2121103f }, /* dock-HP */
+       {}
+};
+
+static const struct cxt_pincfg *cxt_pincfg_tbl[] = {
+       [CXT_PINCFG_LENOVO_X200] = cxt_pincfg_lenovo_x200,
+};
+
+static const struct snd_pci_quirk cxt_fixups[] = {
+       SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
+       {}
+};
+
 static int patch_conexant_auto(struct hda_codec *codec)
 {
        struct conexant_spec *spec;
@@ -4407,6 +4431,15 @@ static int patch_conexant_auto(struct hda_codec *codec)
                return -ENOMEM;
        codec->spec = spec;
        codec->pin_amp_workaround = 1;
+
+       switch (codec->vendor_id) {
+       case 0x14f15045:
+               spec->single_adc_amp = 1;
+               break;
+       }
+
+       apply_pin_fixup(codec, cxt_fixups, cxt_pincfg_tbl);
+
        err = cx_auto_search_adcs(codec);
        if (err < 0)
                return err;
index 19cb72db9c38df1261f3ded1fe1c0471bd906aef..342540128fb8f2bc4c8ce18b9f53e9c859c1c5d7 100644 (file)
@@ -324,6 +324,66 @@ static int cvt_nid_to_cvt_index(struct hdmi_spec *spec, hda_nid_t cvt_nid)
        return -EINVAL;
 }
 
+static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol,
+                       struct snd_ctl_elem_info *uinfo)
+{
+       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
+       struct hdmi_spec *spec;
+       int pin_idx;
+
+       spec = codec->spec;
+       uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
+
+       pin_idx = kcontrol->private_value;
+       uinfo->count = spec->pins[pin_idx].sink_eld.eld_size;
+
+       return 0;
+}
+
+static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol,
+                       struct snd_ctl_elem_value *ucontrol)
+{
+       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
+       struct hdmi_spec *spec;
+       int pin_idx;
+
+       spec = codec->spec;
+       pin_idx = kcontrol->private_value;
+
+       memcpy(ucontrol->value.bytes.data,
+               spec->pins[pin_idx].sink_eld.eld_buffer, ELD_MAX_SIZE);
+
+       return 0;
+}
+
+static struct snd_kcontrol_new eld_bytes_ctl = {
+       .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
+       .iface = SNDRV_CTL_ELEM_IFACE_PCM,
+       .name = "ELD",
+       .info = hdmi_eld_ctl_info,
+       .get = hdmi_eld_ctl_get,
+};
+
+static int hdmi_create_eld_ctl(struct hda_codec *codec, int pin_idx,
+                       int device)
+{
+       struct snd_kcontrol *kctl;
+       struct hdmi_spec *spec = codec->spec;
+       int err;
+
+       kctl = snd_ctl_new1(&eld_bytes_ctl, codec);
+       if (!kctl)
+               return -ENOMEM;
+       kctl->private_value = pin_idx;
+       kctl->id.device = device;
+
+       err = snd_hda_ctl_add(codec, spec->pins[pin_idx].pin_nid, kctl);
+       if (err < 0)
+               return err;
+
+       return 0;
+}
+
 #ifdef BE_PARANOID
 static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
                                int *packet_index, int *byte_index)
@@ -967,19 +1027,12 @@ static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
 
        per_pin->pin_nid = pin_nid;
 
-       err = snd_hda_input_jack_add(codec, pin_nid,
-                                    SND_JACK_VIDEOOUT, NULL);
-       if (err < 0)
-               return err;
-
        err = hdmi_read_pin_conn(codec, pin_idx);
        if (err < 0)
                return err;
 
        spec->num_pins++;
 
-       hdmi_present_sense(codec, pin_nid, eld);
-
        return 0;
 }
 
@@ -1162,6 +1215,25 @@ static int generic_hdmi_build_pcms(struct hda_codec *codec)
        return 0;
 }
 
+static int generic_hdmi_build_jack(struct hda_codec *codec, int pin_idx)
+{
+       int err;
+       char hdmi_str[32];
+       struct hdmi_spec *spec = codec->spec;
+       struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx];
+       int pcmdev = spec->pcm_rec[pin_idx].device;
+
+       snprintf(hdmi_str, sizeof(hdmi_str), "HDMI/DP,pcm=%d", pcmdev);
+
+       err = snd_hda_input_jack_add(codec, per_pin->pin_nid,
+                            SND_JACK_VIDEOOUT, pcmdev > 0 ? hdmi_str : NULL);
+       if (err < 0)
+               return err;
+
+       hdmi_present_sense(codec, per_pin->pin_nid, &per_pin->sink_eld);
+       return 0;
+}
+
 static int generic_hdmi_build_controls(struct hda_codec *codec)
 {
        struct hdmi_spec *spec = codec->spec;
@@ -1170,12 +1242,25 @@ static int generic_hdmi_build_controls(struct hda_codec *codec)
 
        for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
                struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx];
+
+               err = generic_hdmi_build_jack(codec, pin_idx);
+               if (err < 0)
+                       return err;
+
                err = snd_hda_create_spdif_out_ctls(codec,
                                                    per_pin->pin_nid,
                                                    per_pin->mux_nids[0]);
                if (err < 0)
                        return err;
                snd_hda_spdif_ctls_unassign(codec, pin_idx);
+
+               /* add control for ELD Bytes */
+               err = hdmi_create_eld_ctl(codec,
+                                       pin_idx,
+                                       spec->pcm_rec[pin_idx].device);
+
+               if (err < 0)
+                       return err;
        }
 
        return 0;
index 7a73621a89090e7a7b6bd482bbfd54dafb610722..8f93b97559a59f05c1a63e6e3d9ef2b95a781707 100644 (file)
@@ -116,6 +116,8 @@ struct alc_spec {
        const hda_nid_t *capsrc_nids;
        hda_nid_t dig_in_nid;           /* digital-in NID; optional */
        hda_nid_t mixer_nid;            /* analog-mixer NID */
+       DECLARE_BITMAP(vol_ctls, 0x20 << 1);
+       DECLARE_BITMAP(sw_ctls, 0x20 << 1);
 
        /* capture setup for dynamic dual-adc switch */
        hda_nid_t cur_adc;
@@ -159,23 +161,27 @@ struct alc_spec {
        void (*power_hook)(struct hda_codec *codec);
 #endif
        void (*shutup)(struct hda_codec *codec);
+       void (*automute_hook)(struct hda_codec *codec);
 
        /* for pin sensing */
-       unsigned int jack_present: 1;
+       unsigned int hp_jack_present:1;
        unsigned int line_jack_present:1;
        unsigned int master_mute:1;
        unsigned int auto_mic:1;
        unsigned int auto_mic_valid_imux:1;     /* valid imux for auto-mic */
-       unsigned int automute:1;        /* HP automute enabled */
-       unsigned int detect_line:1;     /* Line-out detection enabled */
-       unsigned int automute_lines:1;  /* automute line-out as well; NOP when automute_hp_lo isn't set */
-       unsigned int automute_hp_lo:1;  /* both HP and LO available */
+       unsigned int automute_speaker:1; /* automute speaker outputs */
+       unsigned int automute_lo:1; /* automute LO outputs */
+       unsigned int detect_hp:1;       /* Headphone detection enabled */
+       unsigned int detect_lo:1;       /* Line-out detection enabled */
+       unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
+       unsigned int automute_lo_possible:1;      /* there are line outs and HP */
 
        /* other flags */
        unsigned int no_analog :1; /* digital I/O only */
        unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
        unsigned int single_input_src:1;
        unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
+       unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
 
        /* auto-mute control */
        int automute_mode;
@@ -193,6 +199,7 @@ struct alc_spec {
        /* for PLL fix */
        hda_nid_t pll_nid;
        unsigned int pll_coef_idx, pll_coef_bit;
+       unsigned int coef0;
 
        /* fix-up list */
        int fixup_id;
@@ -202,6 +209,9 @@ struct alc_spec {
        /* multi-io */
        int multi_ios;
        struct alc_multi_io multi_io[4];
+
+       /* bind volumes */
+       struct snd_array bind_ctls;
 };
 
 #define ALC_MODEL_AUTO         0       /* common for all chips */
@@ -525,8 +535,8 @@ static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
        }
 }
 
-/* Toggle internal speakers muting */
-static void update_speakers(struct hda_codec *codec)
+/* Toggle outputs muting */
+static void update_outputs(struct hda_codec *codec)
 {
        struct alc_spec *spec = codec->spec;
        int on;
@@ -538,10 +548,10 @@ static void update_speakers(struct hda_codec *codec)
        do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
                    spec->autocfg.hp_pins, spec->master_mute, true);
 
-       if (!spec->automute)
+       if (!spec->automute_speaker)
                on = 0;
        else
-               on = spec->jack_present | spec->line_jack_present;
+               on = spec->hp_jack_present | spec->line_jack_present;
        on |= spec->master_mute;
        do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
                    spec->autocfg.speaker_pins, on, false);
@@ -551,26 +561,35 @@ static void update_speakers(struct hda_codec *codec)
        if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
            spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
                return;
-       if (!spec->automute || (spec->automute_hp_lo && !spec->automute_lines))
+       if (!spec->automute_lo)
                on = 0;
        else
-               on = spec->jack_present;
+               on = spec->hp_jack_present;
        on |= spec->master_mute;
        do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
                    spec->autocfg.line_out_pins, on, false);
 }
 
+static void call_update_outputs(struct hda_codec *codec)
+{
+       struct alc_spec *spec = codec->spec;
+       if (spec->automute_hook)
+               spec->automute_hook(codec);
+       else
+               update_outputs(codec);
+}
+
 /* standard HP-automute helper */
 static void alc_hp_automute(struct hda_codec *codec)
 {
        struct alc_spec *spec = codec->spec;
 
-       spec->jack_present =
+       spec->hp_jack_present =
                detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
                             spec->autocfg.hp_pins);
-       if (!spec->automute)
+       if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
                return;
-       update_speakers(codec);
+       call_update_outputs(codec);
 }
 
 /* standard line-out-automute helper */
@@ -585,9 +604,9 @@ static void alc_line_automute(struct hda_codec *codec)
        spec->line_jack_present =
                detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
                             spec->autocfg.line_out_pins);
-       if (!spec->automute || !spec->detect_line)
+       if (!spec->automute_speaker || !spec->detect_lo)
                return;
-       update_speakers(codec);
+       call_update_outputs(codec);
 }
 
 #define get_connection_index(codec, mux, nid) \
@@ -785,7 +804,7 @@ static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
 
        uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
        uinfo->count = 1;
-       if (spec->automute_hp_lo) {
+       if (spec->automute_speaker_possible && spec->automute_lo_possible) {
                uinfo->value.enumerated.items = 3;
                texts = texts3;
        } else {
@@ -804,13 +823,12 @@ static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
 {
        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
        struct alc_spec *spec = codec->spec;
-       unsigned int val;
-       if (!spec->automute)
-               val = 0;
-       else if (!spec->automute_hp_lo || !spec->automute_lines)
-               val = 1;
-       else
-               val = 2;
+       unsigned int val = 0;
+       if (spec->automute_speaker)
+               val++;
+       if (spec->automute_lo)
+               val++;
+
        ucontrol->value.enumerated.item[0] = val;
        return 0;
 }
@@ -823,29 +841,36 @@ static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
 
        switch (ucontrol->value.enumerated.item[0]) {
        case 0:
-               if (!spec->automute)
+               if (!spec->automute_speaker && !spec->automute_lo)
                        return 0;
-               spec->automute = 0;
+               spec->automute_speaker = 0;
+               spec->automute_lo = 0;
                break;
        case 1:
-               if (spec->automute &&
-                   (!spec->automute_hp_lo || !spec->automute_lines))
-                       return 0;
-               spec->automute = 1;
-               spec->automute_lines = 0;
+               if (spec->automute_speaker_possible) {
+                       if (!spec->automute_lo && spec->automute_speaker)
+                               return 0;
+                       spec->automute_speaker = 1;
+                       spec->automute_lo = 0;
+               } else if (spec->automute_lo_possible) {
+                       if (spec->automute_lo)
+                               return 0;
+                       spec->automute_lo = 1;
+               } else
+                       return -EINVAL;
                break;
        case 2:
-               if (!spec->automute_hp_lo)
+               if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
                        return -EINVAL;
-               if (spec->automute && spec->automute_lines)
+               if (spec->automute_speaker && spec->automute_lo)
                        return 0;
-               spec->automute = 1;
-               spec->automute_lines = 1;
+               spec->automute_speaker = 1;
+               spec->automute_lo = 1;
                break;
        default:
                return -EINVAL;
        }
-       update_speakers(codec);
+       call_update_outputs(codec);
        return 1;
 }
 
@@ -882,7 +907,7 @@ static int alc_add_automute_mode_enum(struct hda_codec *codec)
  * Check the availability of HP/line-out auto-mute;
  * Set up appropriately if really supported
  */
-static void alc_init_auto_hp(struct hda_codec *codec)
+static void alc_init_automute(struct hda_codec *codec)
 {
        struct alc_spec *spec = codec->spec;
        struct auto_pin_cfg *cfg = &spec->autocfg;
@@ -897,8 +922,6 @@ static void alc_init_auto_hp(struct hda_codec *codec)
                present++;
        if (present < 2) /* need two different output types */
                return;
-       if (present == 3)
-               spec->automute_hp_lo = 1; /* both HP and LO automute */
 
        if (!cfg->speaker_pins[0] &&
            cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
@@ -914,6 +937,8 @@ static void alc_init_auto_hp(struct hda_codec *codec)
                cfg->hp_outs = cfg->line_outs;
        }
 
+       spec->automute_mode = ALC_AUTOMUTE_PIN;
+
        for (i = 0; i < cfg->hp_outs; i++) {
                hda_nid_t nid = cfg->hp_pins[i];
                if (!is_jack_detectable(codec, nid))
@@ -923,28 +948,32 @@ static void alc_init_auto_hp(struct hda_codec *codec)
                snd_hda_codec_write_cache(codec, nid, 0,
                                  AC_VERB_SET_UNSOLICITED_ENABLE,
                                  AC_USRSP_EN | ALC_HP_EVENT);
-               spec->automute = 1;
-               spec->automute_mode = ALC_AUTOMUTE_PIN;
-       }
-       if (spec->automute && cfg->line_out_pins[0] &&
-           cfg->speaker_pins[0] &&
-           cfg->line_out_pins[0] != cfg->hp_pins[0] &&
-           cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
-               for (i = 0; i < cfg->line_outs; i++) {
-                       hda_nid_t nid = cfg->line_out_pins[i];
-                       if (!is_jack_detectable(codec, nid))
-                               continue;
-                       snd_printdd("realtek: Enable Line-Out auto-muting "
-                                   "on NID 0x%x\n", nid);
-                       snd_hda_codec_write_cache(codec, nid, 0,
-                                       AC_VERB_SET_UNSOLICITED_ENABLE,
-                                       AC_USRSP_EN | ALC_FRONT_EVENT);
-                       spec->detect_line = 1;
+               spec->detect_hp = 1;
+       }
+
+       if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
+               if (cfg->speaker_outs)
+                       for (i = 0; i < cfg->line_outs; i++) {
+                               hda_nid_t nid = cfg->line_out_pins[i];
+                               if (!is_jack_detectable(codec, nid))
+                                       continue;
+                               snd_printdd("realtek: Enable Line-Out "
+                                           "auto-muting on NID 0x%x\n", nid);
+                               snd_hda_codec_write_cache(codec, nid, 0,
+                                               AC_VERB_SET_UNSOLICITED_ENABLE,
+                                               AC_USRSP_EN | ALC_FRONT_EVENT);
+                               spec->detect_lo = 1;
                }
-               spec->automute_lines = spec->detect_line;
+               spec->automute_lo_possible = spec->detect_hp;
        }
 
-       if (spec->automute) {
+       spec->automute_speaker_possible = cfg->speaker_outs &&
+               (spec->detect_hp || spec->detect_lo);
+
+       spec->automute_lo = spec->automute_lo_possible;
+       spec->automute_speaker = spec->automute_speaker_possible;
+
+       if (spec->automute_speaker_possible || spec->automute_lo_possible) {
                /* create a control for automute mode */
                alc_add_automute_mode_enum(codec);
                spec->unsol_event = alc_sku_unsol_event;
@@ -1145,7 +1174,7 @@ static void alc_init_auto_mic(struct hda_codec *codec)
 /* check the availabilities of auto-mute and auto-mic switches */
 static void alc_auto_check_switches(struct hda_codec *codec)
 {
-       alc_init_auto_hp(codec);
+       alc_init_automute(codec);
        alc_init_auto_mic(codec);
 }
 
@@ -1528,6 +1557,15 @@ static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
                            coef_val);
 }
 
+/* a special bypass for COEF 0; read the cached value at the second time */
+static unsigned int alc_get_coef0(struct hda_codec *codec)
+{
+       struct alc_spec *spec = codec->spec;
+       if (!spec->coef0)
+               spec->coef0 = alc_read_coef_idx(codec, 0);
+       return spec->coef0;
+}
+
 /*
  * Digital I/O handling
  */
@@ -2368,6 +2406,18 @@ static void alc_free_kctls(struct hda_codec *codec)
        snd_array_free(&spec->kctls);
 }
 
+static void alc_free_bind_ctls(struct hda_codec *codec)
+{
+       struct alc_spec *spec = codec->spec;
+       if (spec->bind_ctls.list) {
+               struct hda_bind_ctls **ctl = spec->bind_ctls.list;
+               int i;
+               for (i = 0; i < spec->bind_ctls.used; i++)
+                       kfree(ctl[i]);
+       }
+       snd_array_free(&spec->bind_ctls);
+}
+
 static void alc_free(struct hda_codec *codec)
 {
        struct alc_spec *spec = codec->spec;
@@ -2378,6 +2428,7 @@ static void alc_free(struct hda_codec *codec)
        alc_shutup(codec);
        snd_hda_input_jack_free(codec);
        alc_free_kctls(codec);
+       alc_free_bind_ctls(codec);
        kfree(spec);
        snd_hda_detach_beep_device(codec);
 }
@@ -2440,6 +2491,47 @@ static int alc_codec_rename(struct hda_codec *codec, const char *name)
        return 0;
 }
 
+/*
+ * Rename codecs appropriately from COEF value
+ */
+struct alc_codec_rename_table {
+       unsigned int vendor_id;
+       unsigned short coef_mask;
+       unsigned short coef_bits;
+       const char *name;
+};
+
+static struct alc_codec_rename_table rename_tbl[] = {
+       { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
+       { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
+       { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
+       { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
+       { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
+       { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
+       { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
+       { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
+       { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
+       { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
+       { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
+       { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
+       { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
+       { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
+       { } /* terminator */
+};
+
+static int alc_codec_rename_from_preset(struct hda_codec *codec)
+{
+       const struct alc_codec_rename_table *p;
+
+       for (p = rename_tbl; p->vendor_id; p++) {
+               if (p->vendor_id != codec->vendor_id)
+                       continue;
+               if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
+                       return alc_codec_rename(codec, p->name);
+       }
+       return 0;
+}
+
 /*
  * Automatic parse of I/O pins from the BIOS configuration
  */
@@ -2448,11 +2540,15 @@ enum {
        ALC_CTL_WIDGET_VOL,
        ALC_CTL_WIDGET_MUTE,
        ALC_CTL_BIND_MUTE,
+       ALC_CTL_BIND_VOL,
+       ALC_CTL_BIND_SW,
 };
 static const struct snd_kcontrol_new alc_control_templates[] = {
        HDA_CODEC_VOLUME(NULL, 0, 0, 0),
        HDA_CODEC_MUTE(NULL, 0, 0, 0),
        HDA_BIND_MUTE(NULL, 0, 0, 0),
+       HDA_BIND_VOL(NULL, 0),
+       HDA_BIND_SW(NULL, 0),
 };
 
 /* add dynamic controls */
@@ -2493,13 +2589,14 @@ static int add_control_with_pfx(struct alc_spec *spec, int type,
 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val)                   \
        add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
 
+static const char * const channel_name[4] = {
+       "Front", "Surround", "CLFE", "Side"
+};
+
 static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
                                        bool can_be_master, int *index)
 {
        struct auto_pin_cfg *cfg = &spec->autocfg;
-       static const char * const chname[4] = {
-               "Front", "Surround", NULL /*CLFE*/, "Side"
-       };
 
        *index = 0;
        if (cfg->line_outs == 1 && !spec->multi_ios &&
@@ -2522,7 +2619,10 @@ static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
                        return "PCM";
                break;
        }
-       return chname[ch];
+       if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
+               return "PCM";
+
+       return channel_name[ch];
 }
 
 /* create input playback/capture controls for the given pin */
@@ -2786,8 +2886,9 @@ static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
                if (found_in_nid_list(nid, spec->multiout.dac_nids,
                                      spec->multiout.num_dacs))
                        continue;
-               if (spec->multiout.hp_nid == nid)
-                       continue;
+               if (found_in_nid_list(nid, spec->multiout.hp_out_nid,
+                                     ARRAY_SIZE(spec->multiout.hp_out_nid)))
+                   continue;
                if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
                                      ARRAY_SIZE(spec->multiout.extra_out_nid)))
                    continue;
@@ -2804,6 +2905,29 @@ static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
        return 0;
 }
 
+static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs,
+                                   const hda_nid_t *pins, hda_nid_t *dacs)
+{
+       int i;
+
+       if (num_outs && !dacs[0]) {
+               dacs[0] = alc_auto_look_for_dac(codec, pins[0]);
+               if (!dacs[0])
+                       return 0;
+       }
+
+       for (i = 1; i < num_outs; i++)
+               dacs[i] = get_dac_if_single(codec, pins[i]);
+       for (i = 1; i < num_outs; i++) {
+               if (!dacs[i])
+                       dacs[i] = alc_auto_look_for_dac(codec, pins[i]);
+       }
+       return 0;
+}
+
+static int alc_auto_fill_multi_ios(struct hda_codec *codec,
+                                  unsigned int location);
+
 /* fill in the dac_nids table from the parsed pin configuration */
 static int alc_auto_fill_dac_nids(struct hda_codec *codec)
 {
@@ -2815,7 +2939,7 @@ static int alc_auto_fill_dac_nids(struct hda_codec *codec)
  again:
        /* set num_dacs once to full for alc_auto_look_for_dac() */
        spec->multiout.num_dacs = cfg->line_outs;
-       spec->multiout.hp_nid = 0;
+       spec->multiout.hp_out_nid[0] = 0;
        spec->multiout.extra_out_nid[0] = 0;
        memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
        spec->multiout.dac_nids = spec->private_dac_nids;
@@ -2826,7 +2950,7 @@ static int alc_auto_fill_dac_nids(struct hda_codec *codec)
                        spec->private_dac_nids[i] =
                                get_dac_if_single(codec, cfg->line_out_pins[i]);
                if (cfg->hp_outs)
-                       spec->multiout.hp_nid =
+                       spec->multiout.hp_out_nid[0] =
                                get_dac_if_single(codec, cfg->hp_pins[0]);
                if (cfg->speaker_outs)
                        spec->multiout.extra_out_nid[0] =
@@ -2858,24 +2982,58 @@ static int alc_auto_fill_dac_nids(struct hda_codec *codec)
                                sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
        }
 
-       if (cfg->hp_outs && !spec->multiout.hp_nid)
-               spec->multiout.hp_nid =
-                       alc_auto_look_for_dac(codec, cfg->hp_pins[0]);
-       if (cfg->speaker_outs && !spec->multiout.extra_out_nid[0])
-               spec->multiout.extra_out_nid[0] =
-                       alc_auto_look_for_dac(codec, cfg->speaker_pins[0]);
+       if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
+               /* try to fill multi-io first */
+               unsigned int location, defcfg;
+               int num_pins;
+
+               defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
+               location = get_defcfg_location(defcfg);
+
+               num_pins = alc_auto_fill_multi_ios(codec, location);
+               if (num_pins > 0) {
+                       spec->multi_ios = num_pins;
+                       spec->ext_channel_count = 2;
+                       spec->multiout.num_dacs = num_pins + 1;
+               }
+       }
+
+       if (cfg->line_out_type != AUTO_PIN_HP_OUT)
+               alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins,
+                                spec->multiout.hp_out_nid);
+       if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
+               alc_auto_fill_extra_dacs(codec, cfg->speaker_outs, cfg->speaker_pins,
+                                spec->multiout.extra_out_nid);
 
        return 0;
 }
 
+static inline unsigned int get_ctl_pos(unsigned int data)
+{
+       hda_nid_t nid = get_amp_nid_(data);
+       unsigned int dir = get_amp_direction_(data);
+       return (nid << 1) | dir;
+}
+
+#define is_ctl_used(bits, data) \
+       test_bit(get_ctl_pos(data), bits)
+#define mark_ctl_usage(bits, data) \
+       set_bit(get_ctl_pos(data), bits)
+
 static int alc_auto_add_vol_ctl(struct hda_codec *codec,
                              const char *pfx, int cidx,
                              hda_nid_t nid, unsigned int chs)
 {
+       struct alc_spec *spec = codec->spec;
+       unsigned int val;
        if (!nid)
                return 0;
+       val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
+       if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
+               return 0;
+       mark_ctl_usage(spec->vol_ctls, val);
        return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
-                                HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
+                                val);
 }
 
 #define alc_auto_add_stereo_vol(codec, pfx, cidx, nid) \
@@ -2888,6 +3046,7 @@ static int alc_auto_add_sw_ctl(struct hda_codec *codec,
                             const char *pfx, int cidx,
                             hda_nid_t nid, unsigned int chs)
 {
+       struct alc_spec *spec = codec->spec;
        int wid_type;
        int type;
        unsigned long val;
@@ -2904,6 +3063,9 @@ static int alc_auto_add_sw_ctl(struct hda_codec *codec,
                type = ALC_CTL_BIND_MUTE;
                val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
        }
+       if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
+               return 0;
+       mark_ctl_usage(spec->sw_ctls, val);
        return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
 }
 
@@ -2964,7 +3126,7 @@ static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
                sw = alc_look_for_out_mute_nid(codec, pin, dac);
                vol = alc_look_for_out_vol_nid(codec, pin, dac);
                name = alc_get_line_out_pfx(spec, i, true, &index);
-               if (!name) {
+               if (!name || !strcmp(name, "CLFE")) {
                        /* Center/LFE */
                        err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
                        if (err < 0)
@@ -2990,23 +3152,24 @@ static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
        return 0;
 }
 
-/* add playback controls for speaker and HP outputs */
 static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
-                                       hda_nid_t dac, const char *pfx)
+                                    hda_nid_t dac, const char *pfx)
 {
        struct alc_spec *spec = codec->spec;
        hda_nid_t sw, vol;
        int err;
 
-       if (!pin)
-               return 0;
        if (!dac) {
+               unsigned int val;
                /* the corresponding DAC is already occupied */
                if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
                        return 0; /* no way */
                /* create a switch only */
-               return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
-                                  HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
+               val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
+               if (is_ctl_used(spec->sw_ctls, val))
+                       return 0; /* already created */
+               mark_ctl_usage(spec->sw_ctls, val);
+               return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, val);
        }
 
        sw = alc_look_for_out_mute_nid(codec, pin, dac);
@@ -3020,20 +3183,112 @@ static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
        return 0;
 }
 
+static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
+                                         unsigned int nums,
+                                         struct hda_ctl_ops *ops)
+{
+       struct alc_spec *spec = codec->spec;
+       struct hda_bind_ctls **ctlp, *ctl;
+       snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
+       ctlp = snd_array_new(&spec->bind_ctls);
+       if (!ctlp)
+               return NULL;
+       ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
+       *ctlp = ctl;
+       if (ctl)
+               ctl->ops = ops;
+       return ctl;
+}
+
+/* add playback controls for speaker and HP outputs */
+static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
+                                     const hda_nid_t *pins,
+                                     const hda_nid_t *dacs,
+                                     const char *pfx)
+{
+       struct alc_spec *spec = codec->spec;
+       struct hda_bind_ctls *ctl;
+       char name[32];
+       int i, n, err;
+
+       if (!num_pins || !pins[0])
+               return 0;
+
+       if (num_pins == 1) {
+               hda_nid_t dac = *dacs;
+               if (!dac)
+                       dac = spec->multiout.dac_nids[0];
+               return alc_auto_create_extra_out(codec, *pins, dac, pfx);
+       }
+
+       if (dacs[num_pins - 1]) {
+               /* OK, we have a multi-output system with individual volumes */
+               for (i = 0; i < num_pins; i++) {
+                       snprintf(name, sizeof(name), "%s %s",
+                                pfx, channel_name[i]);
+                       err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
+                                                       name);
+                       if (err < 0)
+                               return err;
+               }
+               return 0;
+       }
+
+       /* Let's create a bind-controls */
+       ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
+       if (!ctl)
+               return -ENOMEM;
+       n = 0;
+       for (i = 0; i < num_pins; i++) {
+               if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
+                       ctl->values[n++] =
+                               HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
+       }
+       if (n) {
+               snprintf(name, sizeof(name), "%s Playback Switch", pfx);
+               err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
+               if (err < 0)
+                       return err;
+       }
+
+       ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
+       if (!ctl)
+               return -ENOMEM;
+       n = 0;
+       for (i = 0; i < num_pins; i++) {
+               hda_nid_t vol;
+               if (!pins[i] || !dacs[i])
+                       continue;
+               vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
+               if (vol)
+                       ctl->values[n++] =
+                               HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
+       }
+       if (n) {
+               snprintf(name, sizeof(name), "%s Playback Volume", pfx);
+               err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
+               if (err < 0)
+                       return err;
+       }
+       return 0;
+}
+
 static int alc_auto_create_hp_out(struct hda_codec *codec)
 {
        struct alc_spec *spec = codec->spec;
-       return alc_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
-                                        spec->multiout.hp_nid,
-                                        "Headphone");
+       return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
+                                         spec->autocfg.hp_pins,
+                                         spec->multiout.hp_out_nid,
+                                         "Headphone");
 }
 
 static int alc_auto_create_speaker_out(struct hda_codec *codec)
 {
        struct alc_spec *spec = codec->spec;
-       return alc_auto_create_extra_out(codec, spec->autocfg.speaker_pins[0],
-                                        spec->multiout.extra_out_nid[0],
-                                        "Speaker");
+       return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
+                                         spec->autocfg.speaker_pins,
+                                         spec->multiout.extra_out_nid,
+                                         "Speaker");
 }
 
 static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
@@ -3090,20 +3345,37 @@ static void alc_auto_init_multi_out(struct hda_codec *codec)
 static void alc_auto_init_extra_out(struct hda_codec *codec)
 {
        struct alc_spec *spec = codec->spec;
+       int i;
        hda_nid_t pin, dac;
 
-       pin = spec->autocfg.hp_pins[0];
-       if (pin) {
-               dac = spec->multiout.hp_nid;
-               if (!dac)
-                       dac = spec->multiout.dac_nids[0];
+       for (i = 0; i < spec->autocfg.hp_outs; i++) {
+               if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
+                       break;
+               pin = spec->autocfg.hp_pins[i];
+               if (!pin)
+                       break;
+               dac = spec->multiout.hp_out_nid[i];
+               if (!dac) {
+                       if (i > 0 && spec->multiout.hp_out_nid[0])
+                               dac = spec->multiout.hp_out_nid[0];
+                       else
+                               dac = spec->multiout.dac_nids[0];
+               }
                alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
        }
-       pin = spec->autocfg.speaker_pins[0];
-       if (pin) {
-               dac = spec->multiout.extra_out_nid[0];
-               if (!dac)
-                       dac = spec->multiout.dac_nids[0];
+       for (i = 0; i < spec->autocfg.speaker_outs; i++) {
+               if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
+                       break;
+               pin = spec->autocfg.speaker_pins[i];
+               if (!pin)
+                       break;
+               dac = spec->multiout.extra_out_nid[i];
+               if (!dac) {
+                       if (i > 0 && spec->multiout.extra_out_nid[0])
+                               dac = spec->multiout.extra_out_nid[0];
+                       else
+                               dac = spec->multiout.dac_nids[0];
+               }
                alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
        }
 }
@@ -3116,6 +3388,7 @@ static int alc_auto_fill_multi_ios(struct hda_codec *codec,
 {
        struct alc_spec *spec = codec->spec;
        struct auto_pin_cfg *cfg = &spec->autocfg;
+       hda_nid_t prime_dac = spec->private_dac_nids[0];
        int type, i, num_pins = 0;
 
        for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
@@ -3143,8 +3416,13 @@ static int alc_auto_fill_multi_ios(struct hda_codec *codec,
                }
        }
        spec->multiout.num_dacs = 1;
-       if (num_pins < 2)
+       if (num_pins < 2) {
+               /* clear up again */
+               memset(spec->private_dac_nids, 0,
+                      sizeof(spec->private_dac_nids));
+               spec->private_dac_nids[0] = prime_dac;
                return 0;
+       }
        return num_pins;
 }
 
@@ -3230,36 +3508,11 @@ static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
        .put = alc_auto_ch_mode_put,
 };
 
-static int alc_auto_add_multi_channel_mode(struct hda_codec *codec,
-                                          int (*fill_dac)(struct hda_codec *))
+static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
 {
        struct alc_spec *spec = codec->spec;
-       struct auto_pin_cfg *cfg = &spec->autocfg;
-       unsigned int location, defcfg;
-       int num_pins;
-
-       if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && cfg->hp_outs == 1) {
-               /* use HP as primary out */
-               cfg->speaker_outs = cfg->line_outs;
-               memcpy(cfg->speaker_pins, cfg->line_out_pins,
-                      sizeof(cfg->speaker_pins));
-               cfg->line_outs = cfg->hp_outs;
-               memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
-               cfg->hp_outs = 0;
-               memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
-               cfg->line_out_type = AUTO_PIN_HP_OUT;
-               if (fill_dac)
-                       fill_dac(codec);
-       }
-       if (cfg->line_outs != 1 ||
-           cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
-               return 0;
-
-       defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
-       location = get_defcfg_location(defcfg);
 
-       num_pins = alc_auto_fill_multi_ios(codec, location);
-       if (num_pins > 0) {
+       if (spec->multi_ios > 0) {
                struct snd_kcontrol_new *knew;
 
                knew = alc_kcontrol_new(spec);
@@ -3269,10 +3522,6 @@ static int alc_auto_add_multi_channel_mode(struct hda_codec *codec,
                knew->name = kstrdup("Channel Mode", GFP_KERNEL);
                if (!knew->name)
                        return -ENOMEM;
-
-               spec->multi_ios = num_pins;
-               spec->ext_channel_count = 2;
-               spec->multiout.num_dacs = num_pins + 1;
        }
        return 0;
 }
@@ -3555,27 +3804,42 @@ static int alc_parse_auto_config(struct hda_codec *codec,
                                 const hda_nid_t *ssid_nids)
 {
        struct alc_spec *spec = codec->spec;
+       struct auto_pin_cfg *cfg = &spec->autocfg;
        int err;
 
-       err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
-                                          ignore_nids);
+       err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
+                                      spec->parse_flags);
        if (err < 0)
                return err;
-       if (!spec->autocfg.line_outs) {
-               if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
+       if (!cfg->line_outs) {
+               if (cfg->dig_outs || cfg->dig_in_pin) {
                        spec->multiout.max_channels = 2;
                        spec->no_analog = 1;
                        goto dig_only;
                }
                return 0; /* can't find valid BIOS pin config */
        }
+
+       if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
+           cfg->line_outs <= cfg->hp_outs) {
+               /* use HP as primary out */
+               cfg->speaker_outs = cfg->line_outs;
+               memcpy(cfg->speaker_pins, cfg->line_out_pins,
+                      sizeof(cfg->speaker_pins));
+               cfg->line_outs = cfg->hp_outs;
+               memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
+               cfg->hp_outs = 0;
+               memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
+               cfg->line_out_type = AUTO_PIN_HP_OUT;
+       }
+
        err = alc_auto_fill_dac_nids(codec);
        if (err < 0)
                return err;
-       err = alc_auto_add_multi_channel_mode(codec, alc_auto_fill_dac_nids);
+       err = alc_auto_add_multi_channel_mode(codec);
        if (err < 0)
                return err;
-       err = alc_auto_create_multi_out_ctls(codec, &spec->autocfg);
+       err = alc_auto_create_multi_out_ctls(codec, cfg);
        if (err < 0)
                return err;
        err = alc_auto_create_hp_out(codec);
@@ -3678,10 +3942,8 @@ static int patch_alc880(struct hda_codec *codec)
        if (board_config == ALC_MODEL_AUTO) {
                /* automatic parse from the BIOS config */
                err = alc880_parse_auto_config(codec);
-               if (err < 0) {
-                       alc_free(codec);
-                       return err;
-               }
+               if (err < 0)
+                       goto error;
 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
                else if (!err) {
                        printk(KERN_INFO
@@ -3706,10 +3968,8 @@ static int patch_alc880(struct hda_codec *codec)
 
        if (!spec->no_analog) {
                err = snd_hda_attach_beep_device(codec, 0x1);
-               if (err < 0) {
-                       alc_free(codec);
-                       return err;
-               }
+               if (err < 0)
+                       goto error;
                set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
        }
 
@@ -3724,6 +3984,10 @@ static int patch_alc880(struct hda_codec *codec)
 #endif
 
        return 0;
+
+ error:
+       alc_free(codec);
+       return err;
 }
 
 
@@ -3805,10 +4069,8 @@ static int patch_alc260(struct hda_codec *codec)
        if (board_config == ALC_MODEL_AUTO) {
                /* automatic parse from the BIOS config */
                err = alc260_parse_auto_config(codec);
-               if (err < 0) {
-                       alc_free(codec);
-                       return err;
-               }
+               if (err < 0)
+                       goto error;
 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
                else if (!err) {
                        printk(KERN_INFO
@@ -3833,10 +4095,8 @@ static int patch_alc260(struct hda_codec *codec)
 
        if (!spec->no_analog) {
                err = snd_hda_attach_beep_device(codec, 0x1);
-               if (err < 0) {
-                       alc_free(codec);
-                       return err;
-               }
+               if (err < 0)
+                       goto error;
                set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
        }
 
@@ -3854,6 +4114,10 @@ static int patch_alc260(struct hda_codec *codec)
 #endif
 
        return 0;
+
+ error:
+       alc_free(codec);
+       return err;
 }
 
 
@@ -3880,6 +4144,7 @@ enum {
        PINFIX_LENOVO_Y530,
        PINFIX_PB_M5210,
        PINFIX_ACER_ASPIRE_7736,
+       PINFIX_ASUS_W90V,
 };
 
 static const struct alc_fixup alc882_fixups[] = {
@@ -3911,10 +4176,18 @@ static const struct alc_fixup alc882_fixups[] = {
                .type = ALC_FIXUP_SKU,
                .v.sku = ALC_FIXUP_SKU_IGNORE,
        },
+       [PINFIX_ASUS_W90V] = {
+               .type = ALC_FIXUP_PINS,
+               .v.pins = (const struct alc_pincfg[]) {
+                       { 0x16, 0x99130110 }, /* fix sequence for CLFE */
+                       { }
+               }
+       },
 };
 
 static const struct snd_pci_quirk alc882_fixup_tbl[] = {
        SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", PINFIX_PB_M5210),
+       SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", PINFIX_ASUS_W90V),
        SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", PINFIX_LENOVO_Y530),
        SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
        SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", PINFIX_ACER_ASPIRE_7736),
@@ -3961,6 +4234,10 @@ static int patch_alc882(struct hda_codec *codec)
                break;
        }
 
+       err = alc_codec_rename_from_preset(codec);
+       if (err < 0)
+               goto error;
+
        board_config = alc_board_config(codec, ALC882_MODEL_LAST,
                                        alc882_models, alc882_cfg_tbl);
 
@@ -3984,10 +4261,8 @@ static int patch_alc882(struct hda_codec *codec)
        if (board_config == ALC_MODEL_AUTO) {
                /* automatic parse from the BIOS config */
                err = alc882_parse_auto_config(codec);
-               if (err < 0) {
-                       alc_free(codec);
-                       return err;
-               }
+               if (err < 0)
+                       goto error;
 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
                else if (!err) {
                        printk(KERN_INFO
@@ -4012,10 +4287,8 @@ static int patch_alc882(struct hda_codec *codec)
 
        if (!spec->no_analog && has_cdefine_beep(codec)) {
                err = snd_hda_attach_beep_device(codec, 0x1);
-               if (err < 0) {
-                       alc_free(codec);
-                       return err;
-               }
+               if (err < 0)
+                       goto error;
                set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
        }
 
@@ -4034,6 +4307,10 @@ static int patch_alc882(struct hda_codec *codec)
 #endif
 
        return 0;
+
+ error:
+       alc_free(codec);
+       return err;
 }
 
 
@@ -4138,10 +4415,8 @@ static int patch_alc262(struct hda_codec *codec)
        if (board_config == ALC_MODEL_AUTO) {
                /* automatic parse from the BIOS config */
                err = alc262_parse_auto_config(codec);
-               if (err < 0) {
-                       alc_free(codec);
-                       return err;
-               }
+               if (err < 0)
+                       goto error;
 #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
                else if (!err) {
                        printk(KERN_INFO
@@ -4166,10 +4441,8 @@ static int patch_alc262(struct hda_codec *codec)
 
        if (!spec->no_analog && has_cdefine_beep(codec)) {
                err = snd_hda_attach_beep_device(codec, 0x1);
-               if (err < 0) {
-                       alc_free(codec);
-                       return err;
-               }
+               if (err < 0)
+                       goto error;
                set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
        }
 
@@ -4189,6 +4462,10 @@ static int patch_alc262(struct hda_codec *codec)
 #endif
 
        return 0;
+
+ error:
+       alc_free(codec);
+       return err;
 }
 
 /*
@@ -4237,14 +4514,9 @@ static int alc268_parse_auto_config(struct hda_codec *codec)
 
 /*
  */
-#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
-#include "alc268_quirks.c"
-#endif
-
 static int patch_alc268(struct hda_codec *codec)
 {
        struct alc_spec *spec;
-       int board_config;
        int i, has_beep, err;
 
        spec = kzalloc(sizeof(*spec), GFP_KERNEL);
@@ -4255,38 +4527,10 @@ static int patch_alc268(struct hda_codec *codec)
 
        /* ALC268 has no aa-loopback mixer */
 
-       board_config = alc_board_config(codec, ALC268_MODEL_LAST,
-                                       alc268_models, alc268_cfg_tbl);
-
-       if (board_config < 0)
-               board_config = alc_board_codec_sid_config(codec,
-                       ALC268_MODEL_LAST, alc268_models, alc268_ssid_cfg_tbl);
-
-       if (board_config < 0) {
-               printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
-                      codec->chip_name);
-               board_config = ALC_MODEL_AUTO;
-       }
-
-       if (board_config == ALC_MODEL_AUTO) {
-               /* automatic parse from the BIOS config */
-               err = alc268_parse_auto_config(codec);
-               if (err < 0) {
-                       alc_free(codec);
-                       return err;
-               }
-#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
-               else if (!err) {
-                       printk(KERN_INFO
-                              "hda_codec: Cannot set up configuration "
-                              "from BIOS.  Using base mode...\n");
-                       board_config = ALC268_3ST;
-               }
-#endif
-       }
-
-       if (board_config != ALC_MODEL_AUTO)
-               setup_preset(codec, &alc268_presets[board_config]);
+       /* automatic parse from the BIOS config */
+       err = alc268_parse_auto_config(codec);
+       if (err < 0)
+               goto error;
 
        has_beep = 0;
        for (i = 0; i < spec->num_mixers; i++) {
@@ -4298,10 +4542,8 @@ static int patch_alc268(struct hda_codec *codec)
 
        if (has_beep) {
                err = snd_hda_attach_beep_device(codec, 0x1);
-               if (err < 0) {
-                       alc_free(codec);
-                       return err;
-               }
+               if (err < 0)
+                       goto error;
                if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
                        /* override the amp caps for beep generator */
                        snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
@@ -4323,13 +4565,16 @@ static int patch_alc268(struct hda_codec *codec)
        spec->vmaster_nid = 0x02;
 
        codec->patch_ops = alc_patch_ops;
-       if (board_config == ALC_MODEL_AUTO)
-               spec->init_hook = alc_auto_init_std;
+       spec->init_hook = alc_auto_init_std;
        spec->shutup = alc_eapd_shutup;
 
        alc_init_jacks(codec);
 
        return 0;
+
+ error:
+       alc_free(codec);
+       return err;
 }
 
 /*
@@ -4423,9 +4668,9 @@ static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
 
 static void alc269_shutup(struct hda_codec *codec)
 {
-       if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017)
+       if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
                alc269_toggle_power_output(codec, 0);
-       if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
+       if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
                alc269_toggle_power_output(codec, 0);
                msleep(150);
        }
@@ -4434,19 +4679,19 @@ static void alc269_shutup(struct hda_codec *codec)
 #ifdef CONFIG_PM
 static int alc269_resume(struct hda_codec *codec)
 {
-       if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
+       if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
                alc269_toggle_power_output(codec, 0);
                msleep(150);
        }
 
        codec->patch_ops.init(codec);
 
-       if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) {
+       if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
                alc269_toggle_power_output(codec, 1);
                msleep(200);
        }
 
-       if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018)
+       if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
                alc269_toggle_power_output(codec, 1);
 
        snd_hda_codec_resume_amp(codec);
@@ -4515,6 +4760,30 @@ static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
        alc_write_coef_idx(codec, 0x07, coef | 0x80);
 }
 
+static void alc269_quanta_automute(struct hda_codec *codec)
+{
+       update_outputs(codec);
+
+       snd_hda_codec_write(codec, 0x20, 0,
+                       AC_VERB_SET_COEF_INDEX, 0x0c);
+       snd_hda_codec_write(codec, 0x20, 0,
+                       AC_VERB_SET_PROC_COEF, 0x680);
+
+       snd_hda_codec_write(codec, 0x20, 0,
+                       AC_VERB_SET_COEF_INDEX, 0x0c);
+       snd_hda_codec_write(codec, 0x20, 0,
+                       AC_VERB_SET_PROC_COEF, 0x480);
+}
+
+static void alc269_fixup_quanta_mute(struct hda_codec *codec,
+                                    const struct alc_fixup *fix, int action)
+{
+       struct alc_spec *spec = codec->spec;
+       if (action != ALC_FIXUP_ACT_PROBE)
+               return;
+       spec->automute_hook = alc269_quanta_automute;
+}
+
 enum {
        ALC269_FIXUP_SONY_VAIO,
        ALC275_FIXUP_SONY_VAIO_GPIO2,
@@ -4526,6 +4795,12 @@ enum {
        ALC271_FIXUP_DMIC,
        ALC269_FIXUP_PCM_44K,
        ALC269_FIXUP_STEREO_DMIC,
+       ALC269_FIXUP_QUANTA_MUTE,
+       ALC269_FIXUP_LIFEBOOK,
+       ALC269_FIXUP_AMIC,
+       ALC269_FIXUP_DMIC,
+       ALC269VB_FIXUP_AMIC,
+       ALC269VB_FIXUP_DMIC,
 };
 
 static const struct alc_fixup alc269_fixups[] = {
@@ -4592,10 +4867,64 @@ static const struct alc_fixup alc269_fixups[] = {
                .type = ALC_FIXUP_FUNC,
                .v.func = alc269_fixup_stereo_dmic,
        },
-};
-
-static const struct snd_pci_quirk alc269_fixup_tbl[] = {
-       SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
+       [ALC269_FIXUP_QUANTA_MUTE] = {
+               .type = ALC_FIXUP_FUNC,
+               .v.func = alc269_fixup_quanta_mute,
+       },
+       [ALC269_FIXUP_LIFEBOOK] = {
+               .type = ALC_FIXUP_PINS,
+               .v.pins = (const struct alc_pincfg[]) {
+                       { 0x1a, 0x2101103f }, /* dock line-out */
+                       { 0x1b, 0x23a11040 }, /* dock mic-in */
+                       { }
+               },
+               .chained = true,
+               .chain_id = ALC269_FIXUP_QUANTA_MUTE
+       },
+       [ALC269_FIXUP_AMIC] = {
+               .type = ALC_FIXUP_PINS,
+               .v.pins = (const struct alc_pincfg[]) {
+                       { 0x14, 0x99130110 }, /* speaker */
+                       { 0x15, 0x0121401f }, /* HP out */
+                       { 0x18, 0x01a19c20 }, /* mic */
+                       { 0x19, 0x99a3092f }, /* int-mic */
+                       { }
+               },
+       },
+       [ALC269_FIXUP_DMIC] = {
+               .type = ALC_FIXUP_PINS,
+               .v.pins = (const struct alc_pincfg[]) {
+                       { 0x12, 0x99a3092f }, /* int-mic */
+                       { 0x14, 0x99130110 }, /* speaker */
+                       { 0x15, 0x0121401f }, /* HP out */
+                       { 0x18, 0x01a19c20 }, /* mic */
+                       { }
+               },
+       },
+       [ALC269VB_FIXUP_AMIC] = {
+               .type = ALC_FIXUP_PINS,
+               .v.pins = (const struct alc_pincfg[]) {
+                       { 0x14, 0x99130110 }, /* speaker */
+                       { 0x18, 0x01a19c20 }, /* mic */
+                       { 0x19, 0x99a3092f }, /* int-mic */
+                       { 0x21, 0x0121401f }, /* HP out */
+                       { }
+               },
+       },
+       [ALC269_FIXUP_DMIC] = {
+               .type = ALC_FIXUP_PINS,
+               .v.pins = (const struct alc_pincfg[]) {
+                       { 0x12, 0x99a3092f }, /* int-mic */
+                       { 0x14, 0x99130110 }, /* speaker */
+                       { 0x18, 0x01a19c20 }, /* mic */
+                       { 0x21, 0x0121401f }, /* HP out */
+                       { }
+               },
+       },
+};
+
+static const struct snd_pci_quirk alc269_fixup_tbl[] = {
+       SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
        SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
        SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
        SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
@@ -4607,13 +4936,71 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
        SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
        SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
        SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
+       SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
        SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
        SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
        SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
        SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
        SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
+       SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
        SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
        SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
+
+#if 1
+       /* Below is a quirk table taken from the old code.
+        * Basically the device should work as is without the fixup table.
+        * If BIOS doesn't give a proper info, enable the corresponding
+        * fixup entry.
+        */ 
+       SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
+                     ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x1113, "ASUS N63Jn", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
+       SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
+       SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
+       SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
+#endif
+       {}
+};
+
+static const struct alc_model_fixup alc269_fixup_models[] = {
+       {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
+       {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
        {}
 };
 
@@ -4622,23 +5009,23 @@ static int alc269_fill_coef(struct hda_codec *codec)
 {
        int val;
 
-       if ((alc_read_coef_idx(codec, 0) & 0x00ff) < 0x015) {
+       if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
                alc_write_coef_idx(codec, 0xf, 0x960b);
                alc_write_coef_idx(codec, 0xe, 0x8817);
        }
 
-       if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x016) {
+       if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
                alc_write_coef_idx(codec, 0xf, 0x960b);
                alc_write_coef_idx(codec, 0xe, 0x8814);
        }
 
-       if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) {
+       if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
                val = alc_read_coef_idx(codec, 0x04);
                /* Power up output pin */
                alc_write_coef_idx(codec, 0x04, val | (1<<11));
        }
 
-       if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
+       if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
                val = alc_read_coef_idx(codec, 0xd);
                if ((val & 0x0c00) >> 10 != 0x1) {
                        /* Capless ramp up clock control */
@@ -4662,15 +5049,10 @@ static int alc269_fill_coef(struct hda_codec *codec)
 
 /*
  */
-#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
-#include "alc269_quirks.c"
-#endif
-
 static int patch_alc269(struct hda_codec *codec)
 {
        struct alc_spec *spec;
-       int board_config, coef;
-       int err;
+       int err = 0;
 
        spec = kzalloc(sizeof(*spec), GFP_KERNEL);
        if (spec == NULL)
@@ -4682,72 +5064,41 @@ static int patch_alc269(struct hda_codec *codec)
 
        alc_auto_parse_customize_define(codec);
 
+       err = alc_codec_rename_from_preset(codec);
+       if (err < 0)
+               goto error;
+
        if (codec->vendor_id == 0x10ec0269) {
                spec->codec_variant = ALC269_TYPE_ALC269VA;
-               coef = alc_read_coef_idx(codec, 0);
-               if ((coef & 0x00f0) == 0x0010) {
+               switch (alc_get_coef0(codec) & 0x00f0) {
+               case 0x0010:
                        if (codec->bus->pci->subsystem_vendor == 0x1025 &&
-                           spec->cdefine.platform_type == 1) {
-                               alc_codec_rename(codec, "ALC271X");
-                       } else if ((coef & 0xf000) == 0x2000) {
-                               alc_codec_rename(codec, "ALC259");
-                       } else if ((coef & 0xf000) == 0x3000) {
-                               alc_codec_rename(codec, "ALC258");
-                       } else if ((coef & 0xfff0) == 0x3010) {
-                               alc_codec_rename(codec, "ALC277");
-                       } else {
-                               alc_codec_rename(codec, "ALC269VB");
-                       }
+                           spec->cdefine.platform_type == 1)
+                               err = alc_codec_rename(codec, "ALC271X");
                        spec->codec_variant = ALC269_TYPE_ALC269VB;
-               } else if ((coef & 0x00f0) == 0x0020) {
-                       if (coef == 0xa023)
-                               alc_codec_rename(codec, "ALC259");
-                       else if (coef == 0x6023)
-                               alc_codec_rename(codec, "ALC281X");
-                       else if (codec->bus->pci->subsystem_vendor == 0x17aa &&
-                                codec->bus->pci->subsystem_device == 0x21f3)
-                               alc_codec_rename(codec, "ALC3202");
-                       else
-                               alc_codec_rename(codec, "ALC269VC");
+                       break;
+               case 0x0020:
+                       if (codec->bus->pci->subsystem_vendor == 0x17aa &&
+                           codec->bus->pci->subsystem_device == 0x21f3)
+                               err = alc_codec_rename(codec, "ALC3202");
                        spec->codec_variant = ALC269_TYPE_ALC269VC;
-               } else
+                       break;
+               default:
                        alc_fix_pll_init(codec, 0x20, 0x04, 15);
+               }
+               if (err < 0)
+                       goto error;
                alc269_fill_coef(codec);
        }
 
-       board_config = alc_board_config(codec, ALC269_MODEL_LAST,
-                                       alc269_models, alc269_cfg_tbl);
-
-       if (board_config < 0) {
-               printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
-                      codec->chip_name);
-               board_config = ALC_MODEL_AUTO;
-       }
-
-       if (board_config == ALC_MODEL_AUTO) {
-               alc_pick_fixup(codec, NULL, alc269_fixup_tbl, alc269_fixups);
-               alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
-       }
-
-       if (board_config == ALC_MODEL_AUTO) {
-               /* automatic parse from the BIOS config */
-               err = alc269_parse_auto_config(codec);
-               if (err < 0) {
-                       alc_free(codec);
-                       return err;
-               }
-#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
-               else if (!err) {
-                       printk(KERN_INFO
-                              "hda_codec: Cannot set up configuration "
-                              "from BIOS.  Using base mode...\n");
-                       board_config = ALC269_BASIC;
-               }
-#endif
-       }
+       alc_pick_fixup(codec, alc269_fixup_models,
+                      alc269_fixup_tbl, alc269_fixups);
+       alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
 
-       if (board_config != ALC_MODEL_AUTO)
-               setup_preset(codec, &alc269_presets[board_config]);
+       /* automatic parse from the BIOS config */
+       err = alc269_parse_auto_config(codec);
+       if (err < 0)
+               goto error;
 
        if (!spec->no_analog && !spec->adc_nids) {
                alc_auto_fill_adc_caps(codec);
@@ -4760,10 +5111,8 @@ static int patch_alc269(struct hda_codec *codec)
 
        if (!spec->no_analog && has_cdefine_beep(codec)) {
                err = snd_hda_attach_beep_device(codec, 0x1);
-               if (err < 0) {
-                       alc_free(codec);
-                       return err;
-               }
+               if (err < 0)
+                       goto error;
                set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
        }
 
@@ -4775,8 +5124,7 @@ static int patch_alc269(struct hda_codec *codec)
 #ifdef CONFIG_PM
        codec->patch_ops.resume = alc269_resume;
 #endif
-       if (board_config == ALC_MODEL_AUTO)
-               spec->init_hook = alc_auto_init_std;
+       spec->init_hook = alc_auto_init_std;
        spec->shutup = alc269_shutup;
 
        alc_init_jacks(codec);
@@ -4788,6 +5136,10 @@ static int patch_alc269(struct hda_codec *codec)
 #endif
 
        return 0;
+
+ error:
+       alc_free(codec);
+       return err;
 }
 
 /*
@@ -4835,14 +5187,9 @@ static const struct snd_pci_quirk alc861_fixup_tbl[] = {
 
 /*
  */
-#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
-#include "alc861_quirks.c"
-#endif
-
 static int patch_alc861(struct hda_codec *codec)
 {
        struct alc_spec *spec;
-       int board_config;
        int err;
 
        spec = kzalloc(sizeof(*spec), GFP_KERNEL);
@@ -4853,39 +5200,13 @@ static int patch_alc861(struct hda_codec *codec)
 
        spec->mixer_nid = 0x15;
 
-        board_config = alc_board_config(codec, ALC861_MODEL_LAST,
-                                       alc861_models, alc861_cfg_tbl);
-
-       if (board_config < 0) {
-               printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
-                      codec->chip_name);
-               board_config = ALC_MODEL_AUTO;
-       }
-
-       if (board_config == ALC_MODEL_AUTO) {
-               alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
-               alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
-       }
-
-       if (board_config == ALC_MODEL_AUTO) {
-               /* automatic parse from the BIOS config */
-               err = alc861_parse_auto_config(codec);
-               if (err < 0) {
-                       alc_free(codec);
-                       return err;
-               }
-#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
-               else if (!err) {
-                       printk(KERN_INFO
-                              "hda_codec: Cannot set up configuration "
-                              "from BIOS.  Using base mode...\n");
-                  board_config = ALC861_3ST_DIG;
-               }
-#endif
-       }
+       alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
+       alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
 
-       if (board_config != ALC_MODEL_AUTO)
-               setup_preset(codec, &alc861_presets[board_config]);
+       /* automatic parse from the BIOS config */
+       err = alc861_parse_auto_config(codec);
+       if (err < 0)
+               goto error;
 
        if (!spec->no_analog && !spec->adc_nids) {
                alc_auto_fill_adc_caps(codec);
@@ -4898,10 +5219,8 @@ static int patch_alc861(struct hda_codec *codec)
 
        if (!spec->no_analog) {
                err = snd_hda_attach_beep_device(codec, 0x23);
-               if (err < 0) {
-                       alc_free(codec);
-                       return err;
-               }
+               if (err < 0)
+                       goto error;
                set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
        }
 
@@ -4910,18 +5229,18 @@ static int patch_alc861(struct hda_codec *codec)
        alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
 
        codec->patch_ops = alc_patch_ops;
-       if (board_config == ALC_MODEL_AUTO) {
-               spec->init_hook = alc_auto_init_std;
-#ifdef CONFIG_SND_HDA_POWER_SAVE
-               spec->power_hook = alc_power_eapd;
-#endif
-       }
+       spec->init_hook = alc_auto_init_std;
 #ifdef CONFIG_SND_HDA_POWER_SAVE
+       spec->power_hook = alc_power_eapd;
        if (!spec->loopback.amplist)
                spec->loopback.amplist = alc861_loopbacks;
 #endif
 
        return 0;
+
+ error:
+       alc_free(codec);
+       return err;
 }
 
 /*
@@ -4943,24 +5262,41 @@ static int alc861vd_parse_auto_config(struct hda_codec *codec)
 }
 
 enum {
-       ALC660VD_FIX_ASUS_GPIO1
+       ALC660VD_FIX_ASUS_GPIO1,
+       ALC861VD_FIX_DALLAS,
 };
 
-/* reset GPIO1 */
+/* exclude VREF80 */
+static void alc861vd_fixup_dallas(struct hda_codec *codec,
+                                 const struct alc_fixup *fix, int action)
+{
+       if (action == ALC_FIXUP_ACT_PRE_PROBE) {
+               snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
+               snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
+       }
+}
+
 static const struct alc_fixup alc861vd_fixups[] = {
        [ALC660VD_FIX_ASUS_GPIO1] = {
                .type = ALC_FIXUP_VERBS,
                .v.verbs = (const struct hda_verb[]) {
+                       /* reset GPIO1 */
                        {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
                        {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
                        {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
                        { }
                }
        },
+       [ALC861VD_FIX_DALLAS] = {
+               .type = ALC_FIXUP_FUNC,
+               .v.func = alc861vd_fixup_dallas,
+       },
 };
 
 static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
+       SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
        SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
+       SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
        {}
 };
 
@@ -4972,14 +5308,10 @@ static const struct hda_verb alc660vd_eapd_verbs[] = {
 
 /*
  */
-#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
-#include "alc861vd_quirks.c"
-#endif
-
 static int patch_alc861vd(struct hda_codec *codec)
 {
        struct alc_spec *spec;
-       int err, board_config;
+       int err;
 
        spec = kzalloc(sizeof(*spec), GFP_KERNEL);
        if (spec == NULL)
@@ -4989,39 +5321,13 @@ static int patch_alc861vd(struct hda_codec *codec)
 
        spec->mixer_nid = 0x0b;
 
-       board_config = alc_board_config(codec, ALC861VD_MODEL_LAST,
-                                       alc861vd_models, alc861vd_cfg_tbl);
-
-       if (board_config < 0) {
-               printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
-                      codec->chip_name);
-               board_config = ALC_MODEL_AUTO;
-       }
+       alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
+       alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
 
-       if (board_config == ALC_MODEL_AUTO) {
-               alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
-               alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
-       }
-
-       if (board_config == ALC_MODEL_AUTO) {
-               /* automatic parse from the BIOS config */
-               err = alc861vd_parse_auto_config(codec);
-               if (err < 0) {
-                       alc_free(codec);
-                       return err;
-               }
-#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
-               else if (!err) {
-                       printk(KERN_INFO
-                              "hda_codec: Cannot set up configuration "
-                              "from BIOS.  Using base mode...\n");
-                       board_config = ALC861VD_3ST;
-               }
-#endif
-       }
-
-       if (board_config != ALC_MODEL_AUTO)
-               setup_preset(codec, &alc861vd_presets[board_config]);
+       /* automatic parse from the BIOS config */
+       err = alc861vd_parse_auto_config(codec);
+       if (err < 0)
+               goto error;
 
        if (codec->vendor_id == 0x10ec0660) {
                /* always turn on EAPD */
@@ -5039,10 +5345,8 @@ static int patch_alc861vd(struct hda_codec *codec)
 
        if (!spec->no_analog) {
                err = snd_hda_attach_beep_device(codec, 0x23);
-               if (err < 0) {
-                       alc_free(codec);
-                       return err;
-               }
+               if (err < 0)
+                       goto error;
                set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
        }
 
@@ -5052,8 +5356,7 @@ static int patch_alc861vd(struct hda_codec *codec)
 
        codec->patch_ops = alc_patch_ops;
 
-       if (board_config == ALC_MODEL_AUTO)
-               spec->init_hook = alc_auto_init_std;
+       spec->init_hook = alc_auto_init_std;
        spec->shutup = alc_eapd_shutup;
 #ifdef CONFIG_SND_HDA_POWER_SAVE
        if (!spec->loopback.amplist)
@@ -5061,6 +5364,10 @@ static int patch_alc861vd(struct hda_codec *codec)
 #endif
 
        return 0;
+
+ error:
+       alc_free(codec);
+       return err;
 }
 
 /*
@@ -5118,6 +5425,14 @@ enum {
        ALC662_FIXUP_CZC_P10T,
        ALC662_FIXUP_SKU_IGNORE,
        ALC662_FIXUP_HP_RP5800,
+       ALC662_FIXUP_ASUS_MODE1,
+       ALC662_FIXUP_ASUS_MODE2,
+       ALC662_FIXUP_ASUS_MODE3,
+       ALC662_FIXUP_ASUS_MODE4,
+       ALC662_FIXUP_ASUS_MODE5,
+       ALC662_FIXUP_ASUS_MODE6,
+       ALC662_FIXUP_ASUS_MODE7,
+       ALC662_FIXUP_ASUS_MODE8,
 };
 
 static const struct alc_fixup alc662_fixups[] = {
@@ -5159,37 +5474,204 @@ static const struct alc_fixup alc662_fixups[] = {
                .chained = true,
                .chain_id = ALC662_FIXUP_SKU_IGNORE
        },
+       [ALC662_FIXUP_ASUS_MODE1] = {
+               .type = ALC_FIXUP_PINS,
+               .v.pins = (const struct alc_pincfg[]) {
+                       { 0x14, 0x99130110 }, /* speaker */
+                       { 0x18, 0x01a19c20 }, /* mic */
+                       { 0x19, 0x99a3092f }, /* int-mic */
+                       { 0x21, 0x0121401f }, /* HP out */
+                       { }
+               },
+               .chained = true,
+               .chain_id = ALC662_FIXUP_SKU_IGNORE
+       },
+       [ALC662_FIXUP_ASUS_MODE2] = {
+               .type = ALC_FIXUP_PINS,
+               .v.pins = (const struct alc_pincfg[]) {
+                       { 0x14, 0x99130110 }, /* speaker */
+                       { 0x18, 0x01a19820 }, /* mic */
+                       { 0x19, 0x99a3092f }, /* int-mic */
+                       { 0x1b, 0x0121401f }, /* HP out */
+                       { }
+               },
+               .chained = true,
+               .chain_id = ALC662_FIXUP_SKU_IGNORE
+       },
+       [ALC662_FIXUP_ASUS_MODE3] = {
+               .type = ALC_FIXUP_PINS,
+               .v.pins = (const struct alc_pincfg[]) {
+                       { 0x14, 0x99130110 }, /* speaker */
+                       { 0x15, 0x0121441f }, /* HP */
+                       { 0x18, 0x01a19840 }, /* mic */
+                       { 0x19, 0x99a3094f }, /* int-mic */
+                       { 0x21, 0x01211420 }, /* HP2 */
+                       { }
+               },
+               .chained = true,
+               .chain_id = ALC662_FIXUP_SKU_IGNORE
+       },
+       [ALC662_FIXUP_ASUS_MODE4] = {
+               .type = ALC_FIXUP_PINS,
+               .v.pins = (const struct alc_pincfg[]) {
+                       { 0x14, 0x99130110 }, /* speaker */
+                       { 0x16, 0x99130111 }, /* speaker */
+                       { 0x18, 0x01a19840 }, /* mic */
+                       { 0x19, 0x99a3094f }, /* int-mic */
+                       { 0x21, 0x0121441f }, /* HP */
+                       { }
+               },
+               .chained = true,
+               .chain_id = ALC662_FIXUP_SKU_IGNORE
+       },
+       [ALC662_FIXUP_ASUS_MODE5] = {
+               .type = ALC_FIXUP_PINS,
+               .v.pins = (const struct alc_pincfg[]) {
+                       { 0x14, 0x99130110 }, /* speaker */
+                       { 0x15, 0x0121441f }, /* HP */
+                       { 0x16, 0x99130111 }, /* speaker */
+                       { 0x18, 0x01a19840 }, /* mic */
+                       { 0x19, 0x99a3094f }, /* int-mic */
+                       { }
+               },
+               .chained = true,
+               .chain_id = ALC662_FIXUP_SKU_IGNORE
+       },
+       [ALC662_FIXUP_ASUS_MODE6] = {
+               .type = ALC_FIXUP_PINS,
+               .v.pins = (const struct alc_pincfg[]) {
+                       { 0x14, 0x99130110 }, /* speaker */
+                       { 0x15, 0x01211420 }, /* HP2 */
+                       { 0x18, 0x01a19840 }, /* mic */
+                       { 0x19, 0x99a3094f }, /* int-mic */
+                       { 0x1b, 0x0121441f }, /* HP */
+                       { }
+               },
+               .chained = true,
+               .chain_id = ALC662_FIXUP_SKU_IGNORE
+       },
+       [ALC662_FIXUP_ASUS_MODE7] = {
+               .type = ALC_FIXUP_PINS,
+               .v.pins = (const struct alc_pincfg[]) {
+                       { 0x14, 0x99130110 }, /* speaker */
+                       { 0x17, 0x99130111 }, /* speaker */
+                       { 0x18, 0x01a19840 }, /* mic */
+                       { 0x19, 0x99a3094f }, /* int-mic */
+                       { 0x1b, 0x01214020 }, /* HP */
+                       { 0x21, 0x0121401f }, /* HP */
+                       { }
+               },
+               .chained = true,
+               .chain_id = ALC662_FIXUP_SKU_IGNORE
+       },
+       [ALC662_FIXUP_ASUS_MODE8] = {
+               .type = ALC_FIXUP_PINS,
+               .v.pins = (const struct alc_pincfg[]) {
+                       { 0x14, 0x99130110 }, /* speaker */
+                       { 0x12, 0x99a30970 }, /* int-mic */
+                       { 0x15, 0x01214020 }, /* HP */
+                       { 0x17, 0x99130111 }, /* speaker */
+                       { 0x18, 0x01a19840 }, /* mic */
+                       { 0x21, 0x0121401f }, /* HP */
+                       { }
+               },
+               .chained = true,
+               .chain_id = ALC662_FIXUP_SKU_IGNORE
+       },
 };
 
 static const struct snd_pci_quirk alc662_fixup_tbl[] = {
+       SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
        SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
        SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
        SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
        SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
+       SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
        SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
        SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
        SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
        SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
+
+#if 0
+       /* Below is a quirk table taken from the old code.
+        * Basically the device should work as is without the fixup table.
+        * If BIOS doesn't give a proper info, enable the corresponding
+        * fixup entry.
+        */ 
+       SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
+       SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
+       SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
+       SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
+       SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
+       SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
+       SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
+       SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
+       SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
+       SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
+       SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
+       SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
+       SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
+       SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
+       SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
+       SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
+       SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
+       SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
+       SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
+       SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
+       SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
+       SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
+       SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
+       SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
+       SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
+       SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
+       SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
+       SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
+       SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
+       SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
+       SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
+       SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
+       SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
+       SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
+       SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
+       SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
+       SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
+       SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
+       SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
+       SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
+       SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
+       SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
+       SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
+       SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
+       SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
+       SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
+       SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
+       SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
+       SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
+       SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
+#endif
        {}
 };
 
 static const struct alc_model_fixup alc662_fixup_models[] = {
        {.id = ALC272_FIXUP_MARIO, .name = "mario"},
+       {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
+       {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
+       {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
+       {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
+       {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
+       {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
+       {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
+       {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
        {}
 };
 
 
 /*
  */
-#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
-#include "alc662_quirks.c"
-#endif
-
 static int patch_alc662(struct hda_codec *codec)
 {
        struct alc_spec *spec;
-       int err, board_config;
-       int coef;
+       int err = 0;
 
        spec = kzalloc(sizeof(*spec), GFP_KERNEL);
        if (!spec)
@@ -5199,50 +5681,31 @@ static int patch_alc662(struct hda_codec *codec)
 
        spec->mixer_nid = 0x0b;
 
+       /* handle multiple HPs as is */
+       spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
+
        alc_auto_parse_customize_define(codec);
 
        alc_fix_pll_init(codec, 0x20, 0x04, 15);
 
-       coef = alc_read_coef_idx(codec, 0);
-       if (coef == 0x8020 || coef == 0x8011)
-               alc_codec_rename(codec, "ALC661");
-       else if (coef & (1 << 14) &&
-               codec->bus->pci->subsystem_vendor == 0x1025 &&
-               spec->cdefine.platform_type == 1)
-               alc_codec_rename(codec, "ALC272X");
-       else if (coef == 0x4011)
-               alc_codec_rename(codec, "ALC656");
-
-       board_config = alc_board_config(codec, ALC662_MODEL_LAST,
-                                       alc662_models, alc662_cfg_tbl);
-       if (board_config < 0) {
-               printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
-                      codec->chip_name);
-               board_config = ALC_MODEL_AUTO;
-       }
+       err = alc_codec_rename_from_preset(codec);
+       if (err < 0)
+               goto error;
 
-       if (board_config == ALC_MODEL_AUTO) {
-               alc_pick_fixup(codec, alc662_fixup_models,
-                              alc662_fixup_tbl, alc662_fixups);
-               alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
-               /* automatic parse from the BIOS config */
-               err = alc662_parse_auto_config(codec);
-               if (err < 0) {
-                       alc_free(codec);
-                       return err;
-               }
-#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
-               else if (!err) {
-                       printk(KERN_INFO
-                              "hda_codec: Cannot set up configuration "
-                              "from BIOS.  Using base mode...\n");
-                       board_config = ALC662_3ST_2ch_DIG;
-               }
-#endif
+       if ((alc_get_coef0(codec) & (1 << 14)) &&
+           codec->bus->pci->subsystem_vendor == 0x1025 &&
+           spec->cdefine.platform_type == 1) {
+               if (alc_codec_rename(codec, "ALC272X") < 0)
+                       goto error;
        }
 
-       if (board_config != ALC_MODEL_AUTO)
-               setup_preset(codec, &alc662_presets[board_config]);
+       alc_pick_fixup(codec, alc662_fixup_models,
+                      alc662_fixup_tbl, alc662_fixups);
+       alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
+       /* automatic parse from the BIOS config */
+       err = alc662_parse_auto_config(codec);
+       if (err < 0)
+               goto error;
 
        if (!spec->no_analog && !spec->adc_nids) {
                alc_auto_fill_adc_caps(codec);
@@ -5255,10 +5718,8 @@ static int patch_alc662(struct hda_codec *codec)
 
        if (!spec->no_analog && has_cdefine_beep(codec)) {
                err = snd_hda_attach_beep_device(codec, 0x1);
-               if (err < 0) {
-                       alc_free(codec);
-                       return err;
-               }
+               if (err < 0)
+                       goto error;
                switch (codec->vendor_id) {
                case 0x10ec0662:
                        set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
@@ -5278,8 +5739,7 @@ static int patch_alc662(struct hda_codec *codec)
        alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
 
        codec->patch_ops = alc_patch_ops;
-       if (board_config == ALC_MODEL_AUTO)
-               spec->init_hook = alc_auto_init_std;
+       spec->init_hook = alc_auto_init_std;
        spec->shutup = alc_eapd_shutup;
 
        alc_init_jacks(codec);
@@ -5290,32 +5750,10 @@ static int patch_alc662(struct hda_codec *codec)
 #endif
 
        return 0;
-}
-
-static int patch_alc888(struct hda_codec *codec)
-{
-       if ((alc_read_coef_idx(codec, 0) & 0x00f0)==0x0030){
-               kfree(codec->chip_name);
-               if (codec->vendor_id == 0x10ec0887)
-                       codec->chip_name = kstrdup("ALC887-VD", GFP_KERNEL);
-               else
-                       codec->chip_name = kstrdup("ALC888-VD", GFP_KERNEL);
-               if (!codec->chip_name) {
-                       alc_free(codec);
-                       return -ENOMEM;
-               }
-               return patch_alc662(codec);
-       }
-       return patch_alc882(codec);
-}
 
-static int patch_alc899(struct hda_codec *codec)
-{
-       if ((alc_read_coef_idx(codec, 0) & 0x2000) != 0x2000) {
-               kfree(codec->chip_name);
-               codec->chip_name = kstrdup("ALC898", GFP_KERNEL);
-       }
-       return patch_alc882(codec);
+ error:
+       alc_free(codec);
+       return err;
 }
 
 /*
@@ -5329,14 +5767,9 @@ static int alc680_parse_auto_config(struct hda_codec *codec)
 
 /*
  */
-#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
-#include "alc680_quirks.c"
-#endif
-
 static int patch_alc680(struct hda_codec *codec)
 {
        struct alc_spec *spec;
-       int board_config;
        int err;
 
        spec = kzalloc(sizeof(*spec), GFP_KERNEL);
@@ -5347,43 +5780,11 @@ static int patch_alc680(struct hda_codec *codec)
 
        /* ALC680 has no aa-loopback mixer */
 
-       board_config = alc_board_config(codec, ALC680_MODEL_LAST,
-                                       alc680_models, alc680_cfg_tbl);
-
-       if (board_config < 0) {
-               printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
-                      codec->chip_name);
-               board_config = ALC_MODEL_AUTO;
-       }
-
-       if (board_config == ALC_MODEL_AUTO) {
-               /* automatic parse from the BIOS config */
-               err = alc680_parse_auto_config(codec);
-               if (err < 0) {
-                       alc_free(codec);
-                       return err;
-               }
-#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
-               else if (!err) {
-                       printk(KERN_INFO
-                              "hda_codec: Cannot set up configuration "
-                              "from BIOS.  Using base mode...\n");
-                       board_config = ALC680_BASE;
-               }
-#endif
-       }
-
-       if (board_config != ALC_MODEL_AUTO) {
-               setup_preset(codec, &alc680_presets[board_config]);
-#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
-               spec->stream_analog_capture = &alc680_pcm_analog_auto_capture;
-#endif
-       }
-
-       if (!spec->no_analog && !spec->adc_nids) {
-               alc_auto_fill_adc_caps(codec);
-               alc_rebuild_imux_for_auto_mic(codec);
-               alc_remove_invalid_adc_nids(codec);
+       /* automatic parse from the BIOS config */
+       err = alc680_parse_auto_config(codec);
+       if (err < 0) {
+               alc_free(codec);
+               return err;
        }
 
        if (!spec->no_analog && !spec->cap_mixer)
@@ -5392,8 +5793,7 @@ static int patch_alc680(struct hda_codec *codec)
        spec->vmaster_nid = 0x02;
 
        codec->patch_ops = alc_patch_ops;
-       if (board_config == ALC_MODEL_AUTO)
-               spec->init_hook = alc_auto_init_std;
+       spec->init_hook = alc_auto_init_std;
 
        return 0;
 }
@@ -5421,6 +5821,8 @@ static const struct hda_codec_preset snd_hda_preset_realtek[] = {
          .patch = patch_alc882 },
        { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
          .patch = patch_alc662 },
+       { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
+         .patch = patch_alc662 },
        { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
        { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
        { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
@@ -5433,13 +5835,13 @@ static const struct hda_codec_preset snd_hda_preset_realtek[] = {
        { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
          .patch = patch_alc882 },
        { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
-       { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc888 },
+       { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
        { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
          .patch = patch_alc882 },
-       { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc888 },
+       { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
        { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
        { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
-       { .id = 0x10ec0899, .name = "ALC899", .patch = patch_alc899 },
+       { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
        {} /* terminator */
 };
 
index 987e3cf71a0b8445697d4a1343001b56d765762f..59a52a430f2458ac7969192b313c74df5c3855c5 100644 (file)
@@ -2972,8 +2972,9 @@ static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
 static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
 {
        struct sigmatel_spec *spec = codec->spec;
+       struct auto_pin_cfg *cfg = &spec->autocfg;
        int j, conn_len;
-       hda_nid_t conn[HDA_MAX_CONNECTIONS];
+       hda_nid_t conn[HDA_MAX_CONNECTIONS], fallback_dac;
        unsigned int wcaps, wtype;
 
        conn_len = snd_hda_get_connections(codec, nid, conn,
@@ -3001,10 +3002,21 @@ static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
                        return conn[j];
                }
        }
-       /* if all DACs are already assigned, connect to the primary DAC */
+
+       /* if all DACs are already assigned, connect to the primary DAC,
+          unless we're assigning a secondary headphone */
+       fallback_dac = spec->multiout.dac_nids[0];
+       if (spec->multiout.hp_nid) {
+               for (j = 0; j < cfg->hp_outs; j++)
+                       if (cfg->hp_pins[j] == nid) {
+                               fallback_dac = spec->multiout.hp_nid;
+                               break;
+                       }
+       }
+
        if (conn_len > 1) {
                for (j = 0; j < conn_len; j++) {
-                       if (conn[j] == spec->multiout.dac_nids[0]) {
+                       if (conn[j] == fallback_dac) {
                                snd_hda_codec_write_cache(codec, nid, 0,
                                                  AC_VERB_SET_CONNECT_SEL, j);
                                break;
@@ -4130,22 +4142,14 @@ static int stac92xx_add_jack(struct hda_codec *codec,
 #ifdef CONFIG_SND_HDA_INPUT_JACK
        int def_conf = snd_hda_codec_get_pincfg(codec, nid);
        int connectivity = get_defcfg_connect(def_conf);
-       char name[32];
-       int err;
 
        if (connectivity && connectivity != AC_JACK_PORT_FIXED)
                return 0;
 
-       snprintf(name, sizeof(name), "%s at %s %s Jack",
-               snd_hda_get_jack_type(def_conf),
-               snd_hda_get_jack_connectivity(def_conf),
-               snd_hda_get_jack_location(def_conf));
-
-       err = snd_hda_input_jack_add(codec, nid, type, name);
-       if (err < 0)
-               return err;
-#endif /* CONFIG_SND_HDA_INPUT_JACK */
+       return snd_hda_input_jack_add(codec, nid, type, NULL);
+#else
        return 0;
+#endif /* CONFIG_SND_HDA_INPUT_JACK */
 }
 
 static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
@@ -5585,9 +5589,7 @@ static void stac92hd8x_fill_auto_spec(struct hda_codec *codec)
 static int patch_stac92hd83xxx(struct hda_codec *codec)
 {
        struct sigmatel_spec *spec;
-       hda_nid_t conn[STAC92HD83_DAC_COUNT + 1];
        int err;
-       int num_dacs;
 
        spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
        if (spec == NULL)
@@ -5689,22 +5691,6 @@ again:
                return err;
        }
 
-       /* docking output support */
-       num_dacs = snd_hda_get_connections(codec, 0xF,
-                               conn, STAC92HD83_DAC_COUNT + 1) - 1;
-       /* skip non-DAC connections */
-       while (num_dacs >= 0 &&
-                       (get_wcaps_type(get_wcaps(codec, conn[num_dacs]))
-                                       != AC_WID_AUD_OUT))
-               num_dacs--;
-       /* set port E and F to select the last DAC */
-       if (num_dacs >= 0) {
-               snd_hda_codec_write_cache(codec, 0xE, 0,
-                       AC_VERB_SET_CONNECT_SEL, num_dacs);
-               snd_hda_codec_write_cache(codec, 0xF, 0,
-                       AC_VERB_SET_CONNECT_SEL, num_dacs);
-       }
-
        codec->proc_widget_hook = stac92hd_proc_hook;
 
        return 0;
index 4ebfbd874c9a81db01fe3961c5d1c65656735ab5..417d62ad3b96c89bd5f05f23e7c41e3edddb59c0 100644 (file)
@@ -1506,39 +1506,49 @@ static int via_build_pcms(struct hda_codec *codec)
        struct via_spec *spec = codec->spec;
        struct hda_pcm *info = spec->pcm_rec;
 
-       codec->num_pcms = 1;
+       codec->num_pcms = 0;
        codec->pcm_info = info;
 
-       snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
-                "%s Analog", codec->chip_name);
-       info->name = spec->stream_name_analog;
+       if (spec->multiout.num_dacs || spec->num_adc_nids) {
+               snprintf(spec->stream_name_analog,
+                        sizeof(spec->stream_name_analog),
+                        "%s Analog", codec->chip_name);
+               info->name = spec->stream_name_analog;
 
-       if (!spec->stream_analog_playback)
-               spec->stream_analog_playback = &via_pcm_analog_playback;
-       info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
-               *spec->stream_analog_playback;
-       info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
-               spec->multiout.dac_nids[0];
-       info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
-               spec->multiout.max_channels;
+               if (spec->multiout.num_dacs) {
+                       if (!spec->stream_analog_playback)
+                               spec->stream_analog_playback =
+                                       &via_pcm_analog_playback;
+                       info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
+                               *spec->stream_analog_playback;
+                       info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
+                               spec->multiout.dac_nids[0];
+                       info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
+                               spec->multiout.max_channels;
+               }
 
-       if (!spec->stream_analog_capture) {
-               if (spec->dyn_adc_switch)
-                       spec->stream_analog_capture =
-                               &via_pcm_dyn_adc_analog_capture;
-               else
-                       spec->stream_analog_capture = &via_pcm_analog_capture;
+               if (!spec->stream_analog_capture) {
+                       if (spec->dyn_adc_switch)
+                               spec->stream_analog_capture =
+                                       &via_pcm_dyn_adc_analog_capture;
+                       else
+                               spec->stream_analog_capture =
+                                       &via_pcm_analog_capture;
+               }
+               if (spec->num_adc_nids) {
+                       info->stream[SNDRV_PCM_STREAM_CAPTURE] =
+                               *spec->stream_analog_capture;
+                       info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
+                               spec->adc_nids[0];
+                       if (!spec->dyn_adc_switch)
+                               info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
+                                       spec->num_adc_nids;
+               }
+               codec->num_pcms++;
+               info++;
        }
-       info->stream[SNDRV_PCM_STREAM_CAPTURE] =
-               *spec->stream_analog_capture;
-       info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
-       if (!spec->dyn_adc_switch)
-               info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
-                       spec->num_adc_nids;
 
        if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
-               codec->num_pcms++;
-               info++;
                snprintf(spec->stream_name_digital,
                         sizeof(spec->stream_name_digital),
                         "%s Digital", codec->chip_name);
@@ -1562,17 +1572,19 @@ static int via_build_pcms(struct hda_codec *codec)
                        info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
                                spec->dig_in_nid;
                }
+               codec->num_pcms++;
+               info++;
        }
 
        if (spec->hp_dac_nid) {
-               codec->num_pcms++;
-               info++;
                snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp),
                         "%s HP", codec->chip_name);
                info->name = spec->stream_name_hp;
                info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback;
                info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
                        spec->hp_dac_nid;
+               codec->num_pcms++;
+               info++;
        }
        return 0;
 }
index 0ccc0eb75775dd3f6ab4215f6098fb1f3311d2f5..8531b983f3aff90bbc3e76ee5527b01e0bb53629 100644 (file)
@@ -2748,8 +2748,9 @@ static int __devinit snd_ice1712_probe(struct pci_dev *pci,
        if (!c->no_mpu401) {
                err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712,
                        ICEREG(ice, MPU1_CTRL),
-                       (c->mpu401_1_info_flags | MPU401_INFO_INTEGRATED),
-                       ice->irq, 0, &ice->rmidi[0]);
+                       c->mpu401_1_info_flags |
+                       MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK,
+                       -1, &ice->rmidi[0]);
                if (err < 0) {
                        snd_card_free(card);
                        return err;
@@ -2764,8 +2765,9 @@ static int __devinit snd_ice1712_probe(struct pci_dev *pci,
                        /*  2nd port used  */
                        err = snd_mpu401_uart_new(card, 1, MPU401_HW_ICE1712,
                                ICEREG(ice, MPU2_CTRL),
-                               (c->mpu401_2_info_flags | MPU401_INFO_INTEGRATED),
-                               ice->irq, 0, &ice->rmidi[1]);
+                               c->mpu401_2_info_flags |
+                               MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK,
+                               -1, &ice->rmidi[1]);
 
                        if (err < 0) {
                                snd_card_free(card);
index 0378126e6272b2b5e59d725d26bb627452abb364..2fd4bf2d6653dbba8015a440de385c198afe8a7f 100644 (file)
@@ -2820,8 +2820,8 @@ snd_m3_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
        /* TODO enable MIDI IRQ and I/O */
        err = snd_mpu401_uart_new(chip->card, 0, MPU401_HW_MPU401,
                                  chip->iobase + MPU401_DATA_PORT,
-                                 MPU401_INFO_INTEGRATED,
-                                 chip->irq, 0, &chip->rmidi);
+                                 MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK,
+                                 -1, &chip->rmidi);
        if (err < 0)
                printk(KERN_WARNING "maestro3: no MIDI support.\n");
 #endif
index 82311fcb86f6d37e80e6c03e3c7b2503f5a03bba..53e5508abcbf58a69cd345af5d3b6dd113708ec1 100644 (file)
@@ -678,15 +678,15 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
                goto err_card;
 
        if (chip->model.device_config & (MIDI_OUTPUT | MIDI_INPUT)) {
-               unsigned int info_flags = MPU401_INFO_INTEGRATED;
+               unsigned int info_flags =
+                               MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK;
                if (chip->model.device_config & MIDI_OUTPUT)
                        info_flags |= MPU401_INFO_OUTPUT;
                if (chip->model.device_config & MIDI_INPUT)
                        info_flags |= MPU401_INFO_INPUT;
                err = snd_mpu401_uart_new(card, 0, MPU401_HW_CMIPCI,
                                          chip->addr + OXYGEN_MPU401,
-                                         info_flags, 0, 0,
-                                         &chip->midi);
+                                         info_flags, -1, &chip->midi);
                if (err < 0)
                        goto err_card;
        }
index 32d096c98f5bc2f6f1ca45e3261b1faed3e2e629..8433aa7c3d754064f9e0b57cae437277161f09f5 100644 (file)
@@ -1074,6 +1074,7 @@ static const struct oxygen_model model_xonar_st = {
        .device_config = PLAYBACK_0_TO_I2S |
                         PLAYBACK_1_TO_SPDIF |
                         CAPTURE_0_FROM_I2S_2 |
+                        CAPTURE_1_FROM_SPDIF |
                         AC97_FMIC_SWITCH,
        .dac_channels_pcm = 2,
        .dac_channels_mixer = 2,
index e34ae14908b312df02b4c5708c924415b09d7cf5..88cc776aa38b1bb7d41c2c35d8f6c91d3c50b290 100644 (file)
@@ -2109,7 +2109,7 @@ snd_card_riptide_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
                val = mpu_port[dev];
                pci_write_config_word(chip->pci, PCI_EXT_MPU_Base, val);
                err = snd_mpu401_uart_new(card, 0, MPU401_HW_RIPTIDE,
-                                         val, 0, chip->irq, 0,
+                                         val, MPU401_INFO_IRQ_HOOK, -1,
                                          &chip->rmidi);
                if (err < 0)
                        snd_printk(KERN_WARNING
index 493e3946756f9e30cecbb700d96cc48bea3df94e..6e2f7ef7ddb155189fc4800f1c67adc0d8405854 100644 (file)
@@ -1241,10 +1241,30 @@ static int hdspm_external_sample_rate(struct hdspm *hdspm)
        return rate;
 }
 
+/* return latency in samples per period */
+static int hdspm_get_latency(struct hdspm *hdspm)
+{
+       int n;
+
+       n = hdspm_decode_latency(hdspm->control_register);
+
+       /* Special case for new RME cards with 32 samples period size.
+        * The three latency bits in the control register
+        * (HDSP_LatencyMask) encode latency values of 64 samples as
+        * 0, 128 samples as 1 ... 4096 samples as 6. For old cards, 7
+        * denotes 8192 samples, but on new cards like RayDAT or AIO,
+        * it corresponds to 32 samples.
+        */
+       if ((7 == n) && (RayDAT == hdspm->io_type || AIO == hdspm->io_type))
+               n = -1;
+
+       return 1 << (n + 6);
+}
+
 /* Latency function */
 static inline void hdspm_compute_period_size(struct hdspm *hdspm)
 {
-       hdspm->period_bytes = 1 << ((hdspm_decode_latency(hdspm->control_register) + 8));
+       hdspm->period_bytes = 4 * hdspm_get_latency(hdspm);
 }
 
 
@@ -1303,12 +1323,27 @@ static int hdspm_set_interrupt_interval(struct hdspm *s, unsigned int frames)
 
        spin_lock_irq(&s->lock);
 
-       frames >>= 7;
-       n = 0;
-       while (frames) {
-               n++;
-               frames >>= 1;
+       if (32 == frames) {
+               /* Special case for new RME cards like RayDAT/AIO which
+                * support period sizes of 32 samples. Since latency is
+                * encoded in the three bits of HDSP_LatencyMask, we can only
+                * have values from 0 .. 7. While 0 still means 64 samples and
+                * 6 represents 4096 samples on all cards, 7 represents 8192
+                * on older cards and 32 samples on new cards.
+                *
+                * In other words, period size in samples is calculated by
+                * 2^(n+6) with n ranging from 0 .. 7.
+                */
+               n = 7;
+       } else {
+               frames >>= 7;
+               n = 0;
+               while (frames) {
+                       n++;
+                       frames >>= 1;
+               }
        }
+
        s->control_register &= ~HDSPM_LatencyMask;
        s->control_register |= hdspm_encode_latency(n);
 
@@ -4801,8 +4836,7 @@ snd_hdspm_proc_read_madi(struct snd_info_entry * entry,
 
        snd_iprintf(buffer, "--- Settings ---\n");
 
-       x = 1 << (6 + hdspm_decode_latency(hdspm->control_register &
-                                                       HDSPM_LatencyMask));
+       x = hdspm_get_latency(hdspm);
 
        snd_iprintf(buffer,
                "Size (Latency): %d samples (2 periods of %lu bytes)\n",
@@ -4965,8 +4999,7 @@ snd_hdspm_proc_read_aes32(struct snd_info_entry * entry,
 
        snd_iprintf(buffer, "--- Settings ---\n");
 
-       x = 1 << (6 + hdspm_decode_latency(hdspm->control_register &
-                               HDSPM_LatencyMask));
+       x = hdspm_get_latency(hdspm);
 
        snd_iprintf(buffer,
                    "Size (Latency): %d samples (2 periods of %lu bytes)\n",
@@ -5672,19 +5705,6 @@ static int snd_hdspm_prepare(struct snd_pcm_substream *substream)
        return 0;
 }
 
-static unsigned int period_sizes_old[] = {
-       64, 128, 256, 512, 1024, 2048, 4096
-};
-
-static unsigned int period_sizes_new[] = {
-       32, 64, 128, 256, 512, 1024, 2048, 4096
-};
-
-/* RayDAT and AIO always have a buffer of 16384 samples per channel */
-static unsigned int raydat_aio_buffer_sizes[] = {
-       16384
-};
-
 static struct snd_pcm_hardware snd_hdspm_playback_subinfo = {
        .info = (SNDRV_PCM_INFO_MMAP |
                 SNDRV_PCM_INFO_MMAP_VALID |
@@ -5703,8 +5723,8 @@ static struct snd_pcm_hardware snd_hdspm_playback_subinfo = {
        .channels_max = HDSPM_MAX_CHANNELS,
        .buffer_bytes_max =
            HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS,
-       .period_bytes_min = (64 * 4),
-       .period_bytes_max = (4096 * 4) * HDSPM_MAX_CHANNELS,
+       .period_bytes_min = (32 * 4),
+       .period_bytes_max = (8192 * 4) * HDSPM_MAX_CHANNELS,
        .periods_min = 2,
        .periods_max = 512,
        .fifo_size = 0
@@ -5728,31 +5748,13 @@ static struct snd_pcm_hardware snd_hdspm_capture_subinfo = {
        .channels_max = HDSPM_MAX_CHANNELS,
        .buffer_bytes_max =
            HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS,
-       .period_bytes_min = (64 * 4),
-       .period_bytes_max = (4096 * 4) * HDSPM_MAX_CHANNELS,
+       .period_bytes_min = (32 * 4),
+       .period_bytes_max = (8192 * 4) * HDSPM_MAX_CHANNELS,
        .periods_min = 2,
        .periods_max = 512,
        .fifo_size = 0
 };
 
-static struct snd_pcm_hw_constraint_list hw_constraints_period_sizes_old = {
-       .count = ARRAY_SIZE(period_sizes_old),
-       .list = period_sizes_old,
-       .mask = 0
-};
-
-static struct snd_pcm_hw_constraint_list hw_constraints_period_sizes_new = {
-       .count = ARRAY_SIZE(period_sizes_new),
-       .list = period_sizes_new,
-       .mask = 0
-};
-
-static struct snd_pcm_hw_constraint_list hw_constraints_raydat_io_buffer = {
-       .count = ARRAY_SIZE(raydat_aio_buffer_sizes),
-       .list = raydat_aio_buffer_sizes,
-       .mask = 0
-};
-
 static int snd_hdspm_hw_rule_in_channels_rate(struct snd_pcm_hw_params *params,
                                           struct snd_pcm_hw_rule *rule)
 {
@@ -5953,26 +5955,29 @@ static int snd_hdspm_playback_open(struct snd_pcm_substream *substream)
        spin_unlock_irq(&hdspm->lock);
 
        snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
+       snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
 
        switch (hdspm->io_type) {
        case AIO:
        case RayDAT:
-               snd_pcm_hw_constraint_list(runtime, 0,
-                               SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
-                               &hw_constraints_period_sizes_new);
-               snd_pcm_hw_constraint_list(runtime, 0,
-                               SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
-                               &hw_constraints_raydat_io_buffer);
-
+               snd_pcm_hw_constraint_minmax(runtime,
+                                            SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
+                                            32, 4096);
+               /* RayDAT & AIO have a fixed buffer of 16384 samples per channel */
+               snd_pcm_hw_constraint_minmax(runtime,
+                                            SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
+                                            16384, 16384);
                break;
 
        default:
-               snd_pcm_hw_constraint_list(runtime, 0,
-                               SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
-                               &hw_constraints_period_sizes_old);
+               snd_pcm_hw_constraint_minmax(runtime,
+                                            SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
+                                            64, 8192);
+               break;
        }
 
        if (AES32 == hdspm->io_type) {
+               runtime->hw.rates |= SNDRV_PCM_RATE_KNOT;
                snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
                                &hdspm_hw_constraints_aes32_sample_rates);
        } else {
@@ -6025,24 +6030,28 @@ static int snd_hdspm_capture_open(struct snd_pcm_substream *substream)
        spin_unlock_irq(&hdspm->lock);
 
        snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
+       snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
+
        switch (hdspm->io_type) {
        case AIO:
        case RayDAT:
-         snd_pcm_hw_constraint_list(runtime, 0,
-                                    SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
-                                    &hw_constraints_period_sizes_new);
-         snd_pcm_hw_constraint_list(runtime, 0,
-                                    SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
-                                    &hw_constraints_raydat_io_buffer);
-         break;
+               snd_pcm_hw_constraint_minmax(runtime,
+                                            SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
+                                            32, 4096);
+               snd_pcm_hw_constraint_minmax(runtime,
+                                            SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
+                                            16384, 16384);
+               break;
 
        default:
-         snd_pcm_hw_constraint_list(runtime, 0,
-                                    SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
-                                    &hw_constraints_period_sizes_old);
+               snd_pcm_hw_constraint_minmax(runtime,
+                                            SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
+                                            64, 8192);
+               break;
        }
 
        if (AES32 == hdspm->io_type) {
+               runtime->hw.rates |= SNDRV_PCM_RATE_KNOT;
                snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
                                &hdspm_hw_constraints_aes32_sample_rates);
        } else {
@@ -6088,7 +6097,7 @@ static inline int copy_u32_le(void __user *dest, void __iomem *src)
 }
 
 static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
-               unsigned int cmd, unsigned long __user arg)
+               unsigned int cmd, unsigned long arg)
 {
        void __user *argp = (void __user *)arg;
        struct hdspm *hdspm = hw->private_data;
@@ -6213,11 +6222,13 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
                info.line_out = hdspm_line_out(hdspm);
                info.passthru = 0;
                spin_unlock_irq(&hdspm->lock);
-               if (copy_to_user((void __user *) arg, &info, sizeof(info)))
+               if (copy_to_user(argp, &info, sizeof(info)))
                        return -EFAULT;
                break;
 
        case SNDRV_HDSPM_IOCTL_GET_STATUS:
+               memset(&status, 0, sizeof(status));
+
                status.card_type = hdspm->io_type;
 
                status.autosync_source = hdspm_autosync_ref(hdspm);
@@ -6250,13 +6261,15 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
                        break;
                }
 
-               if (copy_to_user((void __user *) arg, &status, sizeof(status)))
+               if (copy_to_user(argp, &status, sizeof(status)))
                        return -EFAULT;
 
 
                break;
 
        case SNDRV_HDSPM_IOCTL_GET_VERSION:
+               memset(&hdspm_version, 0, sizeof(hdspm_version));
+
                hdspm_version.card_type = hdspm->io_type;
                strncpy(hdspm_version.cardname, hdspm->card_name,
                                sizeof(hdspm_version.cardname));
@@ -6267,13 +6280,13 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
                if (hdspm->tco)
                        hdspm_version.addons |= HDSPM_ADDON_TCO;
 
-               if (copy_to_user((void __user *) arg, &hdspm_version,
+               if (copy_to_user(argp, &hdspm_version,
                                        sizeof(hdspm_version)))
                        return -EFAULT;
                break;
 
        case SNDRV_HDSPM_IOCTL_GET_MIXER:
-               if (copy_from_user(&mixer, (void __user *)arg, sizeof(mixer)))
+               if (copy_from_user(&mixer, argp, sizeof(mixer)))
                        return -EFAULT;
                if (copy_to_user((void __user *)mixer.mixer, hdspm->mixer,
                                        sizeof(struct hdspm_mixer)))
index bcf61524a13f7ae92ee0abdc7a4cd0ac8294dfba..5ffb20b187861c9eb49b38fd7de6a427b1552332 100644 (file)
@@ -1234,7 +1234,7 @@ static int sis_resume(struct pci_dev *pci)
                goto error;
        }
 
-       if (request_irq(pci->irq, sis_interrupt, IRQF_DISABLED|IRQF_SHARED,
+       if (request_irq(pci->irq, sis_interrupt, IRQF_SHARED,
                        KBUILD_MODNAME, sis)) {
                printk(KERN_ERR "sis7019: unable to regain IRQ %d\n", pci->irq);
                goto error;
@@ -1340,7 +1340,7 @@ static int __devinit sis_chip_create(struct snd_card *card,
        if (rc)
                goto error_out_cleanup;
 
-       if (request_irq(pci->irq, sis_interrupt, IRQF_DISABLED|IRQF_SHARED,
+       if (request_irq(pci->irq, sis_interrupt, IRQF_SHARED,
                        KBUILD_MODNAME, sis)) {
                printk(KERN_ERR "unable to allocate irq %d\n", sis->irq);
                goto error_out_cleanup;
index 2571a67b389a1488d83c78ce1d200c343b0aa57a..c5008166cf1f0d67fe0623c07f9e3950639a44a0 100644 (file)
@@ -1493,9 +1493,10 @@ static int __devinit snd_sonic_probe(struct pci_dev *pci,
                return err;
        }
        if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_SONICVIBES,
-                                      sonic->midi_port, MPU401_INFO_INTEGRATED,
-                                      sonic->irq, 0,
-                                      &midi_uart)) < 0) {
+                                      sonic->midi_port,
+                                      MPU401_INFO_INTEGRATED |
+                                      MPU401_INFO_IRQ_HOOK,
+                                      -1, &midi_uart)) < 0) {
                snd_card_free(card);
                return err;
        }
index d8a128f6fc0269e8ecbf4760879547179651b441..5e707effdc7cac127d30db367e7228469b526170 100644 (file)
@@ -148,8 +148,9 @@ static int __devinit snd_trident_probe(struct pci_dev *pci,
        if (trident->device != TRIDENT_DEVICE_ID_SI7018 &&
            (err = snd_mpu401_uart_new(card, 0, MPU401_HW_TRID4DWAVE,
                                       trident->midi_port,
-                                      MPU401_INFO_INTEGRATED,
-                                      trident->irq, 0, &trident->rmidi)) < 0) {
+                                      MPU401_INFO_INTEGRATED |
+                                      MPU401_INFO_IRQ_HOOK,
+                                      -1, &trident->rmidi)) < 0) {
                snd_card_free(card);
                return err;
        }
index f03fd620a2a0760b1f028529dd5ad17c654dbc27..c3656fffdb50d3da870b2b3d70e7a1319999e221 100644 (file)
@@ -1175,6 +1175,7 @@ static int snd_via82xx_pcm_open(struct via82xx *chip, struct viadev *viadev,
        struct snd_pcm_runtime *runtime = substream->runtime;
        int err;
        struct via_rate_lock *ratep;
+       bool use_src = false;
 
        runtime->hw = snd_via82xx_hw;
        
@@ -1196,6 +1197,7 @@ static int snd_via82xx_pcm_open(struct via82xx *chip, struct viadev *viadev,
                                     SNDRV_PCM_RATE_8000_48000);
                runtime->hw.rate_min = 8000;
                runtime->hw.rate_max = 48000;
+               use_src = true;
        } else if (! ratep->rate) {
                int idx = viadev->direction ? AC97_RATES_ADC : AC97_RATES_FRONT_DAC;
                runtime->hw.rates = chip->ac97->rates[idx];
@@ -1212,6 +1214,12 @@ static int snd_via82xx_pcm_open(struct via82xx *chip, struct viadev *viadev,
        if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
                return err;
 
+       if (use_src) {
+               err = snd_pcm_hw_rule_noresample(runtime, 48000);
+               if (err < 0)
+                       return err;
+       }
+
        runtime->private_data = viadev;
        viadev->substream = substream;
 
@@ -2068,8 +2076,9 @@ static int __devinit snd_via686_init_misc(struct via82xx *chip)
        pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, legacy_cfg);
        if (chip->mpu_res) {
                if (snd_mpu401_uart_new(chip->card, 0, MPU401_HW_VIA686A,
-                                       mpu_port, MPU401_INFO_INTEGRATED,
-                                       chip->irq, 0, &chip->rmidi) < 0) {
+                                       mpu_port, MPU401_INFO_INTEGRATED |
+                                       MPU401_INFO_IRQ_HOOK, -1,
+                                       &chip->rmidi) < 0) {
                        printk(KERN_WARNING "unable to initialize MPU-401"
                               " at 0x%lx, skipping\n", mpu_port);
                        legacy &= ~VIA_FUNC_ENABLE_MIDI;
index 511d5765312495bb71b8ed2d37cb7cf284a725de..3253b04da18449ecd7a2a0dfad911b9c2c065b64 100644 (file)
@@ -305,8 +305,9 @@ static int __devinit snd_card_ymfpci_probe(struct pci_dev *pci,
        if (chip->mpu_res) {
                if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_YMFPCI,
                                               mpu_port[dev],
-                                              MPU401_INFO_INTEGRATED,
-                                              pci->irq, 0, &chip->rawmidi)) < 0) {
+                                              MPU401_INFO_INTEGRATED |
+                                              MPU401_INFO_IRQ_HOOK,
+                                              -1, &chip->rawmidi)) < 0) {
                        printk(KERN_WARNING "ymfpci: cannot initialize MPU401 at 0x%lx, skipping...\n", mpu_port[dev]);
                        legacy_ctrl &= ~YMFPCI_LEGACY_MIEN; /* disable MPU401 irq */
                        pci_write_config_word(pci, PCIR_DSXG_LEGACY, legacy_ctrl);
index f3260e658b8add161237a6458722d59335792c98..66ea71b2a70d0968b12cebbea383bd8f9a1f23d2 100644 (file)
@@ -897,6 +897,18 @@ static int snd_ymfpci_playback_open_1(struct snd_pcm_substream *substream)
        struct snd_ymfpci *chip = snd_pcm_substream_chip(substream);
        struct snd_pcm_runtime *runtime = substream->runtime;
        struct snd_ymfpci_pcm *ypcm;
+       int err;
+
+       runtime->hw = snd_ymfpci_playback;
+       /* FIXME? True value is 256/48 = 5.33333 ms */
+       err = snd_pcm_hw_constraint_minmax(runtime,
+                                          SNDRV_PCM_HW_PARAM_PERIOD_TIME,
+                                          5334, UINT_MAX);
+       if (err < 0)
+               return err;
+       err = snd_pcm_hw_rule_noresample(runtime, 48000);
+       if (err < 0)
+               return err;
 
        ypcm = kzalloc(sizeof(*ypcm), GFP_KERNEL);
        if (ypcm == NULL)
@@ -904,11 +916,8 @@ static int snd_ymfpci_playback_open_1(struct snd_pcm_substream *substream)
        ypcm->chip = chip;
        ypcm->type = PLAYBACK_VOICE;
        ypcm->substream = substream;
-       runtime->hw = snd_ymfpci_playback;
        runtime->private_data = ypcm;
        runtime->private_free = snd_ymfpci_pcm_free_substream;
-       /* FIXME? True value is 256/48 = 5.33333 ms */
-       snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_TIME, 5333, UINT_MAX);
        return 0;
 }
 
@@ -1013,6 +1022,18 @@ static int snd_ymfpci_capture_open(struct snd_pcm_substream *substream,
        struct snd_ymfpci *chip = snd_pcm_substream_chip(substream);
        struct snd_pcm_runtime *runtime = substream->runtime;
        struct snd_ymfpci_pcm *ypcm;
+       int err;
+
+       runtime->hw = snd_ymfpci_capture;
+       /* FIXME? True value is 256/48 = 5.33333 ms */
+       err = snd_pcm_hw_constraint_minmax(runtime,
+                                          SNDRV_PCM_HW_PARAM_PERIOD_TIME,
+                                          5334, UINT_MAX);
+       if (err < 0)
+               return err;
+       err = snd_pcm_hw_rule_noresample(runtime, 48000);
+       if (err < 0)
+               return err;
 
        ypcm = kzalloc(sizeof(*ypcm), GFP_KERNEL);
        if (ypcm == NULL)
@@ -1022,9 +1043,6 @@ static int snd_ymfpci_capture_open(struct snd_pcm_substream *substream,
        ypcm->substream = substream;    
        ypcm->capture_bank_number = capture_bank_number;
        chip->capture_substream[capture_bank_number] = substream;
-       runtime->hw = snd_ymfpci_capture;
-       /* FIXME? True value is 256/48 = 5.33333 ms */
-       snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_TIME, 5333, UINT_MAX);
        runtime->private_data = ypcm;
        runtime->private_free = snd_ymfpci_pcm_free_substream;
        snd_ymfpci_hw_start(chip);
@@ -1615,7 +1633,7 @@ YMFPCI_DOUBLE("ADC Playback Volume", 0, YDSXGR_PRIADCOUTVOL),
 YMFPCI_DOUBLE("ADC Capture Volume", 0, YDSXGR_PRIADCLOOPVOL),
 YMFPCI_DOUBLE("ADC Playback Volume", 1, YDSXGR_SECADCOUTVOL),
 YMFPCI_DOUBLE("ADC Capture Volume", 1, YDSXGR_SECADCLOOPVOL),
-YMFPCI_DOUBLE("FM Legacy Volume", 0, YDSXGR_LEGACYOUTVOL),
+YMFPCI_DOUBLE("FM Legacy Playback Volume", 0, YDSXGR_LEGACYOUTVOL),
 YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("AC97 ", PLAYBACK,VOLUME), 0, YDSXGR_ZVOUTVOL),
 YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("", CAPTURE,VOLUME), 0, YDSXGR_ZVLOOPVOL),
 YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("AC97 ",PLAYBACK,VOLUME), 1, YDSXGR_SPDIFOUTVOL),
index 8f064c7ce74569348d0af6a035f97c353af9ac71..4080becf4cef0f892d453143b517dd23df46f59d 100644 (file)
@@ -82,7 +82,6 @@ static int keywest_attach_adapter(struct i2c_adapter *adapter)
 
 static int keywest_remove(struct i2c_client *client)
 {
-       i2c_set_clientdata(client, NULL);
        if (! keywest_ctx)
                return 0;
        if (client == keywest_ctx->client)
index bc823a547550c740ab9d7871fc2e401a09d7afbd..775bd95d4be6594ceb478c4824e27d4a8c815337 100644 (file)
@@ -845,7 +845,7 @@ static int __devinit snd_ps3_allocate_irq(void)
                return ret;
        }
 
-       ret = request_irq(the_card.irq_no, snd_ps3_interrupt, IRQF_DISABLED,
+       ret = request_irq(the_card.irq_no, snd_ps3_interrupt, 0,
                          SND_PS3_DRIVER_NAME, &the_card);
        if (ret) {
                pr_info("%s: request_irq failed (%d)\n", __func__, ret);
index 8224db5f0434ffa7c16b93899f06401ae7c9ed3b..1381db853ef0f8b5d875c6ba220de0f90476add5 100644 (file)
@@ -7,6 +7,8 @@ menuconfig SND_SOC
        select SND_PCM
        select AC97_BUS if SND_SOC_AC97_BUS
        select SND_JACK if INPUT=y || INPUT=SND
+       select REGMAP_I2C if I2C
+       select REGMAP_SPI if SPI_MASTER
        ---help---
 
          If you want ASoC support, you should say Y here and also to the
@@ -51,6 +53,7 @@ source "sound/soc/nuc900/Kconfig"
 source "sound/soc/omap/Kconfig"
 source "sound/soc/kirkwood/Kconfig"
 source "sound/soc/mid-x86/Kconfig"
+source "sound/soc/mxs/Kconfig"
 source "sound/soc/pxa/Kconfig"
 source "sound/soc/samsung/Kconfig"
 source "sound/soc/s6000/Kconfig"
index 4f913876f3324e0e29fa297560cfce2ec3b84bd4..9ea8ac827adc37327d955acd30a7639b571030d3 100644 (file)
@@ -12,6 +12,7 @@ obj-$(CONFIG_SND_SOC) += fsl/
 obj-$(CONFIG_SND_SOC)   += imx/
 obj-$(CONFIG_SND_SOC)  += jz4740/
 obj-$(CONFIG_SND_SOC)  += mid-x86/
+obj-$(CONFIG_SND_SOC)  += mxs/
 obj-$(CONFIG_SND_SOC)  += nuc900/
 obj-$(CONFIG_SND_SOC)  += omap/
 obj-$(CONFIG_SND_SOC)  += kirkwood/
index 1aac2f4dbcf61b84b4700c5179b03e8bee995f54..73ae99ad45787061a4cb5deb3816ac9cec6a81e0 100644 (file)
@@ -338,7 +338,6 @@ static int playpaq_wm8510_init(struct snd_soc_pcm_runtime *rtd)
        /* always connected pins */
        snd_soc_dapm_enable_pin(dapm, "Int Mic");
        snd_soc_dapm_enable_pin(dapm, "Ext Spk");
-       snd_soc_dapm_sync(dapm);
 
 
 
@@ -383,14 +382,17 @@ static int __init playpaq_asoc_init(void)
        _gclk0 = clk_get(NULL, "gclk0");
        if (IS_ERR(_gclk0)) {
                _gclk0 = NULL;
+               ret = PTR_ERR(_gclk0);
                goto err_gclk0;
        }
        _pll0 = clk_get(NULL, "pll0");
        if (IS_ERR(_pll0)) {
                _pll0 = NULL;
+               ret = PTR_ERR(_pll0);
                goto err_pll0;
        }
-       if (clk_set_parent(_gclk0, _pll0)) {
+       ret = clk_set_parent(_gclk0, _pll0);
+       if (ret) {
                pr_warning("snd-soc-playpaq: "
                           "Failed to set PLL0 as parent for DAC clock\n");
                goto err_set_clk;
index bad3aa14d5b39cad30bfc877b51dfd0deaf45bf9..0377c5451aed9bbe1e9f61f2959dab6b6637da93 100644 (file)
@@ -173,8 +173,6 @@ static int at91sam9g20ek_wm8731_init(struct snd_soc_pcm_runtime *rtd)
        /* always connected */
        snd_soc_dapm_enable_pin(dapm, "Ext Spk");
 
-       snd_soc_dapm_sync(dapm);
-
        return 0;
 }
 
index 5e4d499d8434ea7377e68419aa34c9b90f8bacd0..d427e9217ce4c264ff8f0b8ad44ec41e25d17c31 100644 (file)
@@ -117,8 +117,6 @@ static int afeb9260_tlv320aic23_init(struct snd_soc_pcm_runtime *rtd)
        snd_soc_dapm_enable_pin(dapm, "Line In");
        snd_soc_dapm_enable_pin(dapm, "Mic Jack");
 
-       snd_soc_dapm_sync(dapm);
-
        return 0;
 }
 
index 4b67140fdec3cb8e98b8ecc39dc54c8e8160ea86..6d592546e8fcc2bd2a0ea343baf929f0a930762f 100644 (file)
@@ -18,10 +18,38 @@ config SND_SOC_AU1XPSC_AC97
        select SND_AC97_CODEC
        select SND_SOC_AC97_BUS
 
+##
+## Au1000/1500/1100 DMA + AC97C/I2SC
+##
+config SND_SOC_AU1XAUDIO
+       tristate "SoC Audio for Au1000/Au1500/Au1100"
+       depends on MIPS_ALCHEMY
+       help
+         This is a driver set for the AC97 unit and the
+         old DMA controller as found on the Au1000/Au1500/Au1100 chips.
+
+config SND_SOC_AU1XAC97C
+       tristate
+       select AC97_BUS
+       select SND_AC97_CODEC
+       select SND_SOC_AC97_BUS
+
+config SND_SOC_AU1XI2SC
+       tristate
+
 
 ##
 ## Boards
 ##
+config SND_SOC_DB1000
+       tristate "DB1000 Audio support"
+       depends on SND_SOC_AU1XAUDIO
+       select SND_SOC_AU1XAC97C
+       select SND_SOC_AC97_CODEC
+       help
+         Select this option to enable AC97 audio on the early DB1x00 series
+         of boards (DB1000/DB1500/DB1100).
+
 config SND_SOC_DB1200
        tristate "DB1200 AC97+I2S audio support"
        depends on SND_SOC_AU1XPSC
index 16873076e8c44044a803076eff2cfabcd53cc000..920710514ea07baaaa734fb55fefe1a96ca92215 100644 (file)
@@ -3,11 +3,21 @@ snd-soc-au1xpsc-dbdma-objs := dbdma2.o
 snd-soc-au1xpsc-i2s-objs := psc-i2s.o
 snd-soc-au1xpsc-ac97-objs := psc-ac97.o
 
+# Au1000/1500/1100 Audio units
+snd-soc-au1x-dma-objs := dma.o
+snd-soc-au1x-ac97c-objs := ac97c.o
+snd-soc-au1x-i2sc-objs := i2sc.o
+
 obj-$(CONFIG_SND_SOC_AU1XPSC) += snd-soc-au1xpsc-dbdma.o
 obj-$(CONFIG_SND_SOC_AU1XPSC_I2S) += snd-soc-au1xpsc-i2s.o
 obj-$(CONFIG_SND_SOC_AU1XPSC_AC97) += snd-soc-au1xpsc-ac97.o
+obj-$(CONFIG_SND_SOC_AU1XAUDIO) += snd-soc-au1x-dma.o
+obj-$(CONFIG_SND_SOC_AU1XAC97C) += snd-soc-au1x-ac97c.o
+obj-$(CONFIG_SND_SOC_AU1XI2SC) += snd-soc-au1x-i2sc.o
 
 # Boards
+snd-soc-db1000-objs := db1000.o
 snd-soc-db1200-objs := db1200.o
 
+obj-$(CONFIG_SND_SOC_DB1000) += snd-soc-db1000.o
 obj-$(CONFIG_SND_SOC_DB1200) += snd-soc-db1200.o
diff --git a/sound/soc/au1x/ac97c.c b/sound/soc/au1x/ac97c.c
new file mode 100644 (file)
index 0000000..726bd65
--- /dev/null
@@ -0,0 +1,366 @@
+/*
+ * Au1000/Au1500/Au1100 AC97C controller driver for ASoC
+ *
+ * (c) 2011 Manuel Lauss <manuel.lauss@googlemail.com>
+ *
+ * based on the old ALSA driver originally written by
+ *                     Charles Eidsness <charles@cooper-street.com>
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/device.h>
+#include <linux/delay.h>
+#include <linux/mutex.h>
+#include <linux/platform_device.h>
+#include <linux/suspend.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/initval.h>
+#include <sound/soc.h>
+#include <asm/mach-au1x00/au1000.h>
+
+#include "psc.h"
+
+/* register offsets and bits */
+#define AC97_CONFIG    0x00
+#define AC97_STATUS    0x04
+#define AC97_DATA      0x08
+#define AC97_CMDRESP   0x0c
+#define AC97_ENABLE    0x10
+
+#define CFG_RC(x)      (((x) & 0x3ff) << 13)   /* valid rx slots mask */
+#define CFG_XS(x)      (((x) & 0x3ff) << 3)    /* valid tx slots mask */
+#define CFG_SG         (1 << 2)        /* sync gate */
+#define CFG_SN         (1 << 1)        /* sync control */
+#define CFG_RS         (1 << 0)        /* acrst# control */
+#define STAT_XU                (1 << 11)       /* tx underflow */
+#define STAT_XO                (1 << 10)       /* tx overflow */
+#define STAT_RU                (1 << 9)        /* rx underflow */
+#define STAT_RO                (1 << 8)        /* rx overflow */
+#define STAT_RD                (1 << 7)        /* codec ready */
+#define STAT_CP                (1 << 6)        /* command pending */
+#define STAT_TE                (1 << 4)        /* tx fifo empty */
+#define STAT_TF                (1 << 3)        /* tx fifo full */
+#define STAT_RE                (1 << 1)        /* rx fifo empty */
+#define STAT_RF                (1 << 0)        /* rx fifo full */
+#define CMD_SET_DATA(x)        (((x) & 0xffff) << 16)
+#define CMD_GET_DATA(x)        ((x) & 0xffff)
+#define CMD_READ       (1 << 7)
+#define CMD_WRITE      (0 << 7)
+#define CMD_IDX(x)     ((x) & 0x7f)
+#define EN_D           (1 << 1)        /* DISable bit */
+#define EN_CE          (1 << 0)        /* clock enable bit */
+
+/* how often to retry failed codec register reads/writes */
+#define AC97_RW_RETRIES        5
+
+#define AC97_RATES     \
+       SNDRV_PCM_RATE_CONTINUOUS
+
+#define AC97_FMTS      \
+       (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE)
+
+/* instance data. There can be only one, MacLeod!!!!, fortunately there IS only
+ * once AC97C on early Alchemy chips. The newer ones aren't so lucky.
+ */
+static struct au1xpsc_audio_data *ac97c_workdata;
+#define ac97_to_ctx(x)         ac97c_workdata
+
+static inline unsigned long RD(struct au1xpsc_audio_data *ctx, int reg)
+{
+       return __raw_readl(ctx->mmio + reg);
+}
+
+static inline void WR(struct au1xpsc_audio_data *ctx, int reg, unsigned long v)
+{
+       __raw_writel(v, ctx->mmio + reg);
+       wmb();
+}
+
+static unsigned short au1xac97c_ac97_read(struct snd_ac97 *ac97,
+                                         unsigned short r)
+{
+       struct au1xpsc_audio_data *ctx = ac97_to_ctx(ac97);
+       unsigned int tmo, retry;
+       unsigned long data;
+
+       data = ~0;
+       retry = AC97_RW_RETRIES;
+       do {
+               mutex_lock(&ctx->lock);
+
+               tmo = 5;
+               while ((RD(ctx, AC97_STATUS) & STAT_CP) && tmo--)
+                       udelay(21);     /* wait an ac97 frame time */
+               if (!tmo) {
+                       pr_debug("ac97rd timeout #1\n");
+                       goto next;
+               }
+
+               WR(ctx, AC97_CMDRESP, CMD_IDX(r) | CMD_READ);
+
+               /* stupid errata: data is only valid for 21us, so
+                * poll, Forrest, poll...
+                */
+               tmo = 0x10000;
+               while ((RD(ctx, AC97_STATUS) & STAT_CP) && tmo--)
+                       asm volatile ("nop");
+               data = RD(ctx, AC97_CMDRESP);
+
+               if (!tmo)
+                       pr_debug("ac97rd timeout #2\n");
+
+next:
+               mutex_unlock(&ctx->lock);
+       } while (--retry && !tmo);
+
+       pr_debug("AC97RD %04x %04lx %d\n", r, data, retry);
+
+       return retry ? data & 0xffff : 0xffff;
+}
+
+static void au1xac97c_ac97_write(struct snd_ac97 *ac97, unsigned short r,
+                                unsigned short v)
+{
+       struct au1xpsc_audio_data *ctx = ac97_to_ctx(ac97);
+       unsigned int tmo, retry;
+
+       retry = AC97_RW_RETRIES;
+       do {
+               mutex_lock(&ctx->lock);
+
+               for (tmo = 5; (RD(ctx, AC97_STATUS) & STAT_CP) && tmo; tmo--)
+                       udelay(21);
+               if (!tmo) {
+                       pr_debug("ac97wr timeout #1\n");
+                       goto next;
+               }
+
+               WR(ctx, AC97_CMDRESP, CMD_WRITE | CMD_IDX(r) | CMD_SET_DATA(v));
+
+               for (tmo = 10; (RD(ctx, AC97_STATUS) & STAT_CP) && tmo; tmo--)
+                       udelay(21);
+               if (!tmo)
+                       pr_debug("ac97wr timeout #2\n");
+next:
+               mutex_unlock(&ctx->lock);
+       } while (--retry && !tmo);
+
+       pr_debug("AC97WR %04x %04x %d\n", r, v, retry);
+}
+
+static void au1xac97c_ac97_warm_reset(struct snd_ac97 *ac97)
+{
+       struct au1xpsc_audio_data *ctx = ac97_to_ctx(ac97);
+
+       WR(ctx, AC97_CONFIG, ctx->cfg | CFG_SG | CFG_SN);
+       msleep(20);
+       WR(ctx, AC97_CONFIG, ctx->cfg | CFG_SG);
+       WR(ctx, AC97_CONFIG, ctx->cfg);
+}
+
+static void au1xac97c_ac97_cold_reset(struct snd_ac97 *ac97)
+{
+       struct au1xpsc_audio_data *ctx = ac97_to_ctx(ac97);
+       int i;
+
+       WR(ctx, AC97_CONFIG, ctx->cfg | CFG_RS);
+       msleep(500);
+       WR(ctx, AC97_CONFIG, ctx->cfg);
+
+       /* wait for codec ready */
+       i = 50;
+       while (((RD(ctx, AC97_STATUS) & STAT_RD) == 0) && --i)
+               msleep(20);
+       if (!i)
+               printk(KERN_ERR "ac97c: codec not ready after cold reset\n");
+}
+
+/* AC97 controller operations */
+struct snd_ac97_bus_ops soc_ac97_ops = {
+       .read           = au1xac97c_ac97_read,
+       .write          = au1xac97c_ac97_write,
+       .reset          = au1xac97c_ac97_cold_reset,
+       .warm_reset     = au1xac97c_ac97_warm_reset,
+};
+EXPORT_SYMBOL_GPL(soc_ac97_ops);       /* globals be gone! */
+
+static int alchemy_ac97c_startup(struct snd_pcm_substream *substream,
+                                struct snd_soc_dai *dai)
+{
+       struct au1xpsc_audio_data *ctx = snd_soc_dai_get_drvdata(dai);
+       snd_soc_dai_set_dma_data(dai, substream, &ctx->dmaids[0]);
+       return 0;
+}
+
+static struct snd_soc_dai_ops alchemy_ac97c_ops = {
+       .startup                = alchemy_ac97c_startup,
+};
+
+static int au1xac97c_dai_probe(struct snd_soc_dai *dai)
+{
+       return ac97c_workdata ? 0 : -ENODEV;
+}
+
+static struct snd_soc_dai_driver au1xac97c_dai_driver = {
+       .name                   = "alchemy-ac97c",
+       .ac97_control           = 1,
+       .probe                  = au1xac97c_dai_probe,
+       .playback = {
+               .rates          = AC97_RATES,
+               .formats        = AC97_FMTS,
+               .channels_min   = 2,
+               .channels_max   = 2,
+       },
+       .capture = {
+               .rates          = AC97_RATES,
+               .formats        = AC97_FMTS,
+               .channels_min   = 2,
+               .channels_max   = 2,
+       },
+       .ops                    = &alchemy_ac97c_ops,
+};
+
+static int __devinit au1xac97c_drvprobe(struct platform_device *pdev)
+{
+       int ret;
+       struct resource *iores, *dmares;
+       struct au1xpsc_audio_data *ctx;
+
+       ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
+       if (!ctx)
+               return -ENOMEM;
+
+       mutex_init(&ctx->lock);
+
+       iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!iores) {
+               ret = -ENODEV;
+               goto out0;
+       }
+
+       ret = -EBUSY;
+       if (!request_mem_region(iores->start, resource_size(iores),
+                               pdev->name))
+               goto out0;
+
+       ctx->mmio = ioremap_nocache(iores->start, resource_size(iores));
+       if (!ctx->mmio)
+               goto out1;
+
+       dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0);
+       if (!dmares)
+               goto out2;
+       ctx->dmaids[SNDRV_PCM_STREAM_PLAYBACK] = dmares->start;
+
+       dmares = platform_get_resource(pdev, IORESOURCE_DMA, 1);
+       if (!dmares)
+               goto out2;
+       ctx->dmaids[SNDRV_PCM_STREAM_CAPTURE] = dmares->start;
+
+       /* switch it on */
+       WR(ctx, AC97_ENABLE, EN_D | EN_CE);
+       WR(ctx, AC97_ENABLE, EN_CE);
+
+       ctx->cfg = CFG_RC(3) | CFG_XS(3);
+       WR(ctx, AC97_CONFIG, ctx->cfg);
+
+       platform_set_drvdata(pdev, ctx);
+
+       ret = snd_soc_register_dai(&pdev->dev, &au1xac97c_dai_driver);
+       if (ret)
+               goto out2;
+
+       ac97c_workdata = ctx;
+       return 0;
+
+out2:
+       iounmap(ctx->mmio);
+out1:
+       release_mem_region(iores->start, resource_size(iores));
+out0:
+       kfree(ctx);
+       return ret;
+}
+
+static int __devexit au1xac97c_drvremove(struct platform_device *pdev)
+{
+       struct au1xpsc_audio_data *ctx = platform_get_drvdata(pdev);
+       struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+
+       snd_soc_unregister_dai(&pdev->dev);
+
+       WR(ctx, AC97_ENABLE, EN_D);     /* clock off, disable */
+
+       iounmap(ctx->mmio);
+       release_mem_region(r->start, resource_size(r));
+       kfree(ctx);
+
+       ac97c_workdata = NULL;  /* MDEV */
+
+       return 0;
+}
+
+#ifdef CONFIG_PM
+static int au1xac97c_drvsuspend(struct device *dev)
+{
+       struct au1xpsc_audio_data *ctx = dev_get_drvdata(dev);
+
+       WR(ctx, AC97_ENABLE, EN_D);     /* clock off, disable */
+
+       return 0;
+}
+
+static int au1xac97c_drvresume(struct device *dev)
+{
+       struct au1xpsc_audio_data *ctx = dev_get_drvdata(dev);
+
+       WR(ctx, AC97_ENABLE, EN_D | EN_CE);
+       WR(ctx, AC97_ENABLE, EN_CE);
+       WR(ctx, AC97_CONFIG, ctx->cfg);
+
+       return 0;
+}
+
+static const struct dev_pm_ops au1xpscac97_pmops = {
+       .suspend        = au1xac97c_drvsuspend,
+       .resume         = au1xac97c_drvresume,
+};
+
+#define AU1XPSCAC97_PMOPS (&au1xpscac97_pmops)
+
+#else
+
+#define AU1XPSCAC97_PMOPS NULL
+
+#endif
+
+static struct platform_driver au1xac97c_driver = {
+       .driver = {
+               .name   = "alchemy-ac97c",
+               .owner  = THIS_MODULE,
+               .pm     = AU1XPSCAC97_PMOPS,
+       },
+       .probe          = au1xac97c_drvprobe,
+       .remove         = __devexit_p(au1xac97c_drvremove),
+};
+
+static int __init au1xac97c_load(void)
+{
+       ac97c_workdata = NULL;
+       return platform_driver_register(&au1xac97c_driver);
+}
+
+static void __exit au1xac97c_unload(void)
+{
+       platform_driver_unregister(&au1xac97c_driver);
+}
+
+module_init(au1xac97c_load);
+module_exit(au1xac97c_unload);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Au1000/1500/1100 AC97C ASoC driver");
+MODULE_AUTHOR("Manuel Lauss");
diff --git a/sound/soc/au1x/db1000.c b/sound/soc/au1x/db1000.c
new file mode 100644 (file)
index 0000000..127477a
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * DB1000/DB1500/DB1100 ASoC audio fabric support code.
+ *
+ * (c) 2011 Manuel Lauss <manuel.lauss@googlemail.com>
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/timer.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/soc.h>
+#include <asm/mach-au1x00/au1000.h>
+#include <asm/mach-db1x00/bcsr.h>
+
+#include "psc.h"
+
+static struct snd_soc_dai_link db1000_ac97_dai = {
+       .name           = "AC97",
+       .stream_name    = "AC97 HiFi",
+       .codec_dai_name = "ac97-hifi",
+       .cpu_dai_name   = "alchemy-ac97c",
+       .platform_name  = "alchemy-pcm-dma.0",
+       .codec_name     = "ac97-codec",
+};
+
+static struct snd_soc_card db1000_ac97 = {
+       .name           = "DB1000_AC97",
+       .dai_link       = &db1000_ac97_dai,
+       .num_links      = 1,
+};
+
+static int __devinit db1000_audio_probe(struct platform_device *pdev)
+{
+       struct snd_soc_card *card = &db1000_ac97;
+       card->dev = &pdev->dev;
+       return snd_soc_register_card(card);
+}
+
+static int __devexit db1000_audio_remove(struct platform_device *pdev)
+{
+       struct snd_soc_card *card = platform_get_drvdata(pdev);
+       snd_soc_unregister_card(card);
+       return 0;
+}
+
+static struct platform_driver db1000_audio_driver = {
+       .driver = {
+               .name   = "db1000-audio",
+               .owner  = THIS_MODULE,
+               .pm     = &snd_soc_pm_ops,
+       },
+       .probe          = db1000_audio_probe,
+       .remove         = __devexit_p(db1000_audio_remove),
+};
+
+static int __init db1000_audio_load(void)
+{
+       return platform_driver_register(&db1000_audio_driver);
+}
+
+static void __exit db1000_audio_unload(void)
+{
+       platform_driver_unregister(&db1000_audio_driver);
+}
+
+module_init(db1000_audio_load);
+module_exit(db1000_audio_unload);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("DB1000/DB1500/DB1100 ASoC audio");
+MODULE_AUTHOR("Manuel Lauss");
index 1d3e258c9ea8ec861cf19c88a9bd7c99e5384940..289312c14b99bf62d13355e7ae5e585bf297991f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * DB1200 ASoC audio fabric support code.
  *
- * (c) 2008-9 Manuel Lauss <manuel.lauss@gmail.com>
+ * (c) 2008-2011 Manuel Lauss <manuel.lauss@googlemail.com>
  *
  */
 
 #include "../codecs/wm8731.h"
 #include "psc.h"
 
+static struct platform_device_id db1200_pids[] = {
+       {
+               .name           = "db1200-ac97",
+               .driver_data    = 0,
+       }, {
+               .name           = "db1200-i2s",
+               .driver_data    = 1,
+       },
+       {},
+};
+
 /*-------------------------  AC97 PART  ---------------------------*/
 
 static struct snd_soc_dai_link db1200_ac97_dai = {
@@ -89,36 +100,47 @@ static struct snd_soc_card db1200_i2s_machine = {
 
 /*-------------------------  COMMON PART  ---------------------------*/
 
-static struct platform_device *db1200_asoc_dev;
+static struct snd_soc_card *db1200_cards[] __devinitdata = {
+       &db1200_ac97_machine,
+       &db1200_i2s_machine,
+};
 
-static int __init db1200_audio_load(void)
+static int __devinit db1200_audio_probe(struct platform_device *pdev)
 {
-       int ret;
+       const struct platform_device_id *pid = platform_get_device_id(pdev);
+       struct snd_soc_card *card;
 
-       ret = -ENOMEM;
-       db1200_asoc_dev = platform_device_alloc("soc-audio", 1); /* PSC1 */
-       if (!db1200_asoc_dev)
-               goto out;
+       card = db1200_cards[pid->driver_data];
+       card->dev = &pdev->dev;
+       return snd_soc_register_card(card);
+}
 
-       /* DB1200 board setup set PSC1MUX to preferred audio device */
-       if (bcsr_read(BCSR_RESETS) & BCSR_RESETS_PSC1MUX)
-               platform_set_drvdata(db1200_asoc_dev, &db1200_i2s_machine);
-       else
-               platform_set_drvdata(db1200_asoc_dev, &db1200_ac97_machine);
+static int __devexit db1200_audio_remove(struct platform_device *pdev)
+{
+       struct snd_soc_card *card = platform_get_drvdata(pdev);
+       snd_soc_unregister_card(card);
+       return 0;
+}
 
-       ret = platform_device_add(db1200_asoc_dev);
+static struct platform_driver db1200_audio_driver = {
+       .driver = {
+               .name   = "db1200-ac97",
+               .owner  = THIS_MODULE,
+               .pm     = &snd_soc_pm_ops,
+       },
+       .id_table       = db1200_pids,
+       .probe          = db1200_audio_probe,
+       .remove         = __devexit_p(db1200_audio_remove),
+};
 
-       if (ret) {
-               platform_device_put(db1200_asoc_dev);
-               db1200_asoc_dev = NULL;
-       }
-out:
-       return ret;
+static int __init db1200_audio_load(void)
+{
+       return platform_driver_register(&db1200_audio_driver);
 }
 
 static void __exit db1200_audio_unload(void)
 {
-       platform_device_unregister(db1200_asoc_dev);
+       platform_driver_unregister(&db1200_audio_driver);
 }
 
 module_init(db1200_audio_load);
index 20bb53a837b152b7e207dfc691d59a76222d221f..d7d04e26eee504524f7952c86825b44c5d7a4fa7 100644 (file)
@@ -169,7 +169,7 @@ static int au1x_pcm_dbdma_realloc(struct au1xpsc_audio_dmadata *pcd,
 
        au1x_pcm_dbdma_free(pcd);
 
-       if (stype == PCM_RX)
+       if (stype == SNDRV_PCM_STREAM_CAPTURE)
                pcd->ddma_chan = au1xxx_dbdma_chan_alloc(pcd->ddma_id,
                                        DSCR_CMD0_ALWAYS,
                                        au1x_pcm_dmarx_cb, (void *)pcd);
@@ -198,7 +198,7 @@ static inline struct au1xpsc_audio_dmadata *to_dmadata(struct snd_pcm_substream
        struct snd_soc_pcm_runtime *rtd = ss->private_data;
        struct au1xpsc_audio_dmadata *pcd =
                                snd_soc_platform_get_drvdata(rtd->platform);
-       return &pcd[SUBSTREAM_TYPE(ss)];
+       return &pcd[ss->stream];
 }
 
 static int au1xpsc_pcm_hw_params(struct snd_pcm_substream *substream,
@@ -212,7 +212,7 @@ static int au1xpsc_pcm_hw_params(struct snd_pcm_substream *substream,
        if (ret < 0)
                goto out;
 
-       stype = SUBSTREAM_TYPE(substream);
+       stype = substream->stream;
        pcd = to_dmadata(substream);
 
        DBG("runtime->dma_area = 0x%08lx dma_addr_t = 0x%08lx dma_size = %d "
@@ -255,7 +255,7 @@ static int au1xpsc_pcm_prepare(struct snd_pcm_substream *substream)
 
        au1xxx_dbdma_reset(pcd->ddma_chan);
 
-       if (SUBSTREAM_TYPE(substream) == PCM_RX) {
+       if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
                au1x_pcm_queue_rx(pcd);
                au1x_pcm_queue_rx(pcd);
        } else {
@@ -293,6 +293,16 @@ au1xpsc_pcm_pointer(struct snd_pcm_substream *substream)
 
 static int au1xpsc_pcm_open(struct snd_pcm_substream *substream)
 {
+       struct au1xpsc_audio_dmadata *pcd = to_dmadata(substream);
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       int stype = substream->stream, *dmaids;
+
+       dmaids = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
+       if (!dmaids)
+               return -ENODEV; /* whoa, has ordering changed? */
+
+       pcd->ddma_id = dmaids[stype];
+
        snd_soc_set_runtime_hwparams(substream, &au1xpsc_pcm_hardware);
        return 0;
 }
@@ -340,36 +350,18 @@ struct snd_soc_platform_driver au1xpsc_soc_platform = {
 static int __devinit au1xpsc_pcm_drvprobe(struct platform_device *pdev)
 {
        struct au1xpsc_audio_dmadata *dmadata;
-       struct resource *r;
        int ret;
 
        dmadata = kzalloc(2 * sizeof(struct au1xpsc_audio_dmadata), GFP_KERNEL);
        if (!dmadata)
                return -ENOMEM;
 
-       r = platform_get_resource(pdev, IORESOURCE_DMA, 0);
-       if (!r) {
-               ret = -ENODEV;
-               goto out1;
-       }
-       dmadata[PCM_TX].ddma_id = r->start;
-
-       /* RX DMA */
-       r = platform_get_resource(pdev, IORESOURCE_DMA, 1);
-       if (!r) {
-               ret = -ENODEV;
-               goto out1;
-       }
-       dmadata[PCM_RX].ddma_id = r->start;
-
        platform_set_drvdata(pdev, dmadata);
 
        ret = snd_soc_register_platform(&pdev->dev, &au1xpsc_soc_platform);
-       if (!ret)
-               return ret;
+       if (ret)
+               kfree(dmadata);
 
-out1:
-       kfree(dmadata);
        return ret;
 }
 
@@ -405,57 +397,6 @@ static void __exit au1xpsc_audio_dbdma_unload(void)
 module_init(au1xpsc_audio_dbdma_load);
 module_exit(au1xpsc_audio_dbdma_unload);
 
-
-struct platform_device *au1xpsc_pcm_add(struct platform_device *pdev)
-{
-       struct resource *res, *r;
-       struct platform_device *pd;
-       int id[2];
-       int ret;
-
-       r = platform_get_resource(pdev, IORESOURCE_DMA, 0);
-       if (!r)
-               return NULL;
-       id[0] = r->start;
-
-       r = platform_get_resource(pdev, IORESOURCE_DMA, 1);
-       if (!r)
-               return NULL;
-       id[1] = r->start;
-
-       res = kzalloc(sizeof(struct resource) * 2, GFP_KERNEL);
-       if (!res)
-               return NULL;
-
-       res[0].start = res[0].end = id[0];
-       res[1].start = res[1].end = id[1];
-       res[0].flags = res[1].flags = IORESOURCE_DMA;
-
-       pd = platform_device_alloc("au1xpsc-pcm", pdev->id);
-       if (!pd)
-               goto out;
-
-       pd->resource = res;
-       pd->num_resources = 2;
-
-       ret = platform_device_add(pd);
-       if (!ret)
-               return pd;
-
-       platform_device_put(pd);
-out:
-       kfree(res);
-       return NULL;
-}
-EXPORT_SYMBOL_GPL(au1xpsc_pcm_add);
-
-void au1xpsc_pcm_destroy(struct platform_device *dmapd)
-{
-       if (dmapd)
-               platform_device_unregister(dmapd);
-}
-EXPORT_SYMBOL_GPL(au1xpsc_pcm_destroy);
-
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("Au12x0/Au1550 PSC Audio DMA driver");
 MODULE_AUTHOR("Manuel Lauss");
diff --git a/sound/soc/au1x/dma.c b/sound/soc/au1x/dma.c
new file mode 100644 (file)
index 0000000..177f713
--- /dev/null
@@ -0,0 +1,377 @@
+/*
+ * Au1000/Au1500/Au1100 Audio DMA support.
+ *
+ * (c) 2011 Manuel Lauss <manuel.lauss@googlemail.com>
+ *
+ * copied almost verbatim from the old ALSA driver, written by
+ *                     Charles Eidsness <charles@cooper-street.com>
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/dma-mapping.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <asm/mach-au1x00/au1000.h>
+#include <asm/mach-au1x00/au1000_dma.h>
+
+#include "psc.h"
+
+#define ALCHEMY_PCM_FMTS                                       \
+       (SNDRV_PCM_FMTBIT_S8     | SNDRV_PCM_FMTBIT_U8 |        \
+        SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE |    \
+        SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE |    \
+        SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE |    \
+        SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE |    \
+        0)
+
+struct pcm_period {
+       u32 start;
+       u32 relative_end;       /* relative to start of buffer */
+       struct pcm_period *next;
+};
+
+struct audio_stream {
+       struct snd_pcm_substream *substream;
+       int dma;
+       struct pcm_period *buffer;
+       unsigned int period_size;
+       unsigned int periods;
+};
+
+struct alchemy_pcm_ctx {
+       struct audio_stream stream[2];  /* playback & capture */
+};
+
+static void au1000_release_dma_link(struct audio_stream *stream)
+{
+       struct pcm_period *pointer;
+       struct pcm_period *pointer_next;
+
+       stream->period_size = 0;
+       stream->periods = 0;
+       pointer = stream->buffer;
+       if (!pointer)
+               return;
+       do {
+               pointer_next = pointer->next;
+               kfree(pointer);
+               pointer = pointer_next;
+       } while (pointer != stream->buffer);
+       stream->buffer = NULL;
+}
+
+static int au1000_setup_dma_link(struct audio_stream *stream,
+                                unsigned int period_bytes,
+                                unsigned int periods)
+{
+       struct snd_pcm_substream *substream = stream->substream;
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct pcm_period *pointer;
+       unsigned long dma_start;
+       int i;
+
+       dma_start = virt_to_phys(runtime->dma_area);
+
+       if (stream->period_size == period_bytes &&
+           stream->periods == periods)
+               return 0; /* not changed */
+
+       au1000_release_dma_link(stream);
+
+       stream->period_size = period_bytes;
+       stream->periods = periods;
+
+       stream->buffer = kmalloc(sizeof(struct pcm_period), GFP_KERNEL);
+       if (!stream->buffer)
+               return -ENOMEM;
+       pointer = stream->buffer;
+       for (i = 0; i < periods; i++) {
+               pointer->start = (u32)(dma_start + (i * period_bytes));
+               pointer->relative_end = (u32) (((i+1) * period_bytes) - 0x1);
+               if (i < periods - 1) {
+                       pointer->next = kmalloc(sizeof(struct pcm_period),
+                                               GFP_KERNEL);
+                       if (!pointer->next) {
+                               au1000_release_dma_link(stream);
+                               return -ENOMEM;
+                       }
+                       pointer = pointer->next;
+               }
+       }
+       pointer->next = stream->buffer;
+       return 0;
+}
+
+static void au1000_dma_stop(struct audio_stream *stream)
+{
+       if (stream->buffer)
+               disable_dma(stream->dma);
+}
+
+static void au1000_dma_start(struct audio_stream *stream)
+{
+       if (!stream->buffer)
+               return;
+
+       init_dma(stream->dma);
+       if (get_dma_active_buffer(stream->dma) == 0) {
+               clear_dma_done0(stream->dma);
+               set_dma_addr0(stream->dma, stream->buffer->start);
+               set_dma_count0(stream->dma, stream->period_size >> 1);
+               set_dma_addr1(stream->dma, stream->buffer->next->start);
+               set_dma_count1(stream->dma, stream->period_size >> 1);
+       } else {
+               clear_dma_done1(stream->dma);
+               set_dma_addr1(stream->dma, stream->buffer->start);
+               set_dma_count1(stream->dma, stream->period_size >> 1);
+               set_dma_addr0(stream->dma, stream->buffer->next->start);
+               set_dma_count0(stream->dma, stream->period_size >> 1);
+       }
+       enable_dma_buffers(stream->dma);
+       start_dma(stream->dma);
+}
+
+static irqreturn_t au1000_dma_interrupt(int irq, void *ptr)
+{
+       struct audio_stream *stream = (struct audio_stream *)ptr;
+       struct snd_pcm_substream *substream = stream->substream;
+
+       switch (get_dma_buffer_done(stream->dma)) {
+       case DMA_D0:
+               stream->buffer = stream->buffer->next;
+               clear_dma_done0(stream->dma);
+               set_dma_addr0(stream->dma, stream->buffer->next->start);
+               set_dma_count0(stream->dma, stream->period_size >> 1);
+               enable_dma_buffer0(stream->dma);
+               break;
+       case DMA_D1:
+               stream->buffer = stream->buffer->next;
+               clear_dma_done1(stream->dma);
+               set_dma_addr1(stream->dma, stream->buffer->next->start);
+               set_dma_count1(stream->dma, stream->period_size >> 1);
+               enable_dma_buffer1(stream->dma);
+               break;
+       case (DMA_D0 | DMA_D1):
+               pr_debug("DMA %d missed interrupt.\n", stream->dma);
+               au1000_dma_stop(stream);
+               au1000_dma_start(stream);
+               break;
+       case (~DMA_D0 & ~DMA_D1):
+               pr_debug("DMA %d empty irq.\n", stream->dma);
+       }
+       snd_pcm_period_elapsed(substream);
+       return IRQ_HANDLED;
+}
+
+static const struct snd_pcm_hardware alchemy_pcm_hardware = {
+       .info             = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
+                           SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BATCH,
+       .formats          = ALCHEMY_PCM_FMTS,
+       .rates            = SNDRV_PCM_RATE_8000_192000,
+       .rate_min         = SNDRV_PCM_RATE_8000,
+       .rate_max         = SNDRV_PCM_RATE_192000,
+       .channels_min     = 2,
+       .channels_max     = 2,
+       .period_bytes_min = 1024,
+       .period_bytes_max = 16 * 1024 - 1,
+       .periods_min      = 4,
+       .periods_max      = 255,
+       .buffer_bytes_max = 128 * 1024,
+       .fifo_size        = 16,
+};
+
+static inline struct alchemy_pcm_ctx *ss_to_ctx(struct snd_pcm_substream *ss)
+{
+       struct snd_soc_pcm_runtime *rtd = ss->private_data;
+       return snd_soc_platform_get_drvdata(rtd->platform);
+}
+
+static inline struct audio_stream *ss_to_as(struct snd_pcm_substream *ss)
+{
+       struct alchemy_pcm_ctx *ctx = ss_to_ctx(ss);
+       return &(ctx->stream[ss->stream]);
+}
+
+static int alchemy_pcm_open(struct snd_pcm_substream *substream)
+{
+       struct alchemy_pcm_ctx *ctx = ss_to_ctx(substream);
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       int *dmaids, s = substream->stream;
+       char *name;
+
+       dmaids = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
+       if (!dmaids)
+               return -ENODEV; /* whoa, has ordering changed? */
+
+       /* DMA setup */
+       name = (s == SNDRV_PCM_STREAM_PLAYBACK) ? "audio-tx" : "audio-rx";
+       ctx->stream[s].dma = request_au1000_dma(dmaids[s], name,
+                                       au1000_dma_interrupt, 0,
+                                       &ctx->stream[s]);
+       set_dma_mode(ctx->stream[s].dma,
+                    get_dma_mode(ctx->stream[s].dma) & ~DMA_NC);
+
+       ctx->stream[s].substream = substream;
+       ctx->stream[s].buffer = NULL;
+       snd_soc_set_runtime_hwparams(substream, &alchemy_pcm_hardware);
+
+       return 0;
+}
+
+static int alchemy_pcm_close(struct snd_pcm_substream *substream)
+{
+       struct alchemy_pcm_ctx *ctx = ss_to_ctx(substream);
+       int stype = substream->stream;
+
+       ctx->stream[stype].substream = NULL;
+       free_au1000_dma(ctx->stream[stype].dma);
+
+       return 0;
+}
+
+static int alchemy_pcm_hw_params(struct snd_pcm_substream *substream,
+                                struct snd_pcm_hw_params *hw_params)
+{
+       struct audio_stream *stream = ss_to_as(substream);
+       int err;
+
+       err = snd_pcm_lib_malloc_pages(substream,
+                                      params_buffer_bytes(hw_params));
+       if (err < 0)
+               return err;
+       err = au1000_setup_dma_link(stream,
+                                   params_period_bytes(hw_params),
+                                   params_periods(hw_params));
+       if (err)
+               snd_pcm_lib_free_pages(substream);
+
+       return err;
+}
+
+static int alchemy_pcm_hw_free(struct snd_pcm_substream *substream)
+{
+       struct audio_stream *stream = ss_to_as(substream);
+       au1000_release_dma_link(stream);
+       return snd_pcm_lib_free_pages(substream);
+}
+
+static int alchemy_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
+{
+       struct audio_stream *stream = ss_to_as(substream);
+       int err = 0;
+
+       switch (cmd) {
+       case SNDRV_PCM_TRIGGER_START:
+               au1000_dma_start(stream);
+               break;
+       case SNDRV_PCM_TRIGGER_STOP:
+               au1000_dma_stop(stream);
+               break;
+       default:
+               err = -EINVAL;
+               break;
+       }
+       return err;
+}
+
+static snd_pcm_uframes_t alchemy_pcm_pointer(struct snd_pcm_substream *ss)
+{
+       struct audio_stream *stream = ss_to_as(ss);
+       long location;
+
+       location = get_dma_residue(stream->dma);
+       location = stream->buffer->relative_end - location;
+       if (location == -1)
+               location = 0;
+       return bytes_to_frames(ss->runtime, location);
+}
+
+static struct snd_pcm_ops alchemy_pcm_ops = {
+       .open                   = alchemy_pcm_open,
+       .close                  = alchemy_pcm_close,
+       .ioctl                  = snd_pcm_lib_ioctl,
+       .hw_params              = alchemy_pcm_hw_params,
+       .hw_free                = alchemy_pcm_hw_free,
+       .trigger                = alchemy_pcm_trigger,
+       .pointer                = alchemy_pcm_pointer,
+};
+
+static void alchemy_pcm_free_dma_buffers(struct snd_pcm *pcm)
+{
+       snd_pcm_lib_preallocate_free_for_all(pcm);
+}
+
+static int alchemy_pcm_new(struct snd_soc_pcm_runtime *rtd)
+{
+       struct snd_pcm *pcm = rtd->pcm;
+
+       snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
+               snd_dma_continuous_data(GFP_KERNEL), 65536, (4096 * 1024) - 1);
+
+       return 0;
+}
+
+struct snd_soc_platform_driver alchemy_pcm_soc_platform = {
+       .ops            = &alchemy_pcm_ops,
+       .pcm_new        = alchemy_pcm_new,
+       .pcm_free       = alchemy_pcm_free_dma_buffers,
+};
+
+static int __devinit alchemy_pcm_drvprobe(struct platform_device *pdev)
+{
+       struct alchemy_pcm_ctx *ctx;
+       int ret;
+
+       ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
+       if (!ctx)
+               return -ENOMEM;
+
+       platform_set_drvdata(pdev, ctx);
+
+       ret = snd_soc_register_platform(&pdev->dev, &alchemy_pcm_soc_platform);
+       if (ret)
+               kfree(ctx);
+
+       return ret;
+}
+
+static int __devexit alchemy_pcm_drvremove(struct platform_device *pdev)
+{
+       struct alchemy_pcm_ctx *ctx = platform_get_drvdata(pdev);
+
+       snd_soc_unregister_platform(&pdev->dev);
+       kfree(ctx);
+
+       return 0;
+}
+
+static struct platform_driver alchemy_pcmdma_driver = {
+       .driver = {
+               .name   = "alchemy-pcm-dma",
+               .owner  = THIS_MODULE,
+       },
+       .probe          = alchemy_pcm_drvprobe,
+       .remove         = __devexit_p(alchemy_pcm_drvremove),
+};
+
+static int __init alchemy_pcmdma_load(void)
+{
+       return platform_driver_register(&alchemy_pcmdma_driver);
+}
+
+static void __exit alchemy_pcmdma_unload(void)
+{
+       platform_driver_unregister(&alchemy_pcmdma_driver);
+}
+
+module_init(alchemy_pcmdma_load);
+module_exit(alchemy_pcmdma_unload);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Au1000/Au1500/Au1100 Audio DMA driver");
+MODULE_AUTHOR("Manuel Lauss");
diff --git a/sound/soc/au1x/i2sc.c b/sound/soc/au1x/i2sc.c
new file mode 100644 (file)
index 0000000..6bcf48f
--- /dev/null
@@ -0,0 +1,349 @@
+/*
+ * Au1000/Au1500/Au1100 I2S controller driver for ASoC
+ *
+ * (c) 2011 Manuel Lauss <manuel.lauss@googlemail.com>
+ *
+ * Note: clock supplied to the I2S controller must be 256x samplerate.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/suspend.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/initval.h>
+#include <sound/soc.h>
+#include <asm/mach-au1x00/au1000.h>
+
+#include "psc.h"
+
+#define I2S_RXTX       0x00
+#define I2S_CFG                0x04
+#define I2S_ENABLE     0x08
+
+#define CFG_XU         (1 << 25)       /* tx underflow */
+#define CFG_XO         (1 << 24)
+#define CFG_RU         (1 << 23)
+#define CFG_RO         (1 << 22)
+#define CFG_TR         (1 << 21)
+#define CFG_TE         (1 << 20)
+#define CFG_TF         (1 << 19)
+#define CFG_RR         (1 << 18)
+#define CFG_RF         (1 << 17)
+#define CFG_ICK                (1 << 12)       /* clock invert */
+#define CFG_PD         (1 << 11)       /* set to make I2SDIO INPUT */
+#define CFG_LB         (1 << 10)       /* loopback */
+#define CFG_IC         (1 << 9)        /* word select invert */
+#define CFG_FM_I2S     (0 << 7)        /* I2S format */
+#define CFG_FM_LJ      (1 << 7)        /* left-justified */
+#define CFG_FM_RJ      (2 << 7)        /* right-justified */
+#define CFG_FM_MASK    (3 << 7)
+#define CFG_TN         (1 << 6)        /* tx fifo en */
+#define CFG_RN         (1 << 5)        /* rx fifo en */
+#define CFG_SZ_8       (0x08)
+#define CFG_SZ_16      (0x10)
+#define CFG_SZ_18      (0x12)
+#define CFG_SZ_20      (0x14)
+#define CFG_SZ_24      (0x18)
+#define CFG_SZ_MASK    (0x1f)
+#define EN_D           (1 << 1)        /* DISable */
+#define EN_CE          (1 << 0)        /* clock enable */
+
+/* only limited by clock generator and board design */
+#define AU1XI2SC_RATES \
+       SNDRV_PCM_RATE_CONTINUOUS
+
+#define AU1XI2SC_FMTS \
+       (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8 |            \
+       SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE |     \
+       SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE |     \
+       SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_U18_3LE |   \
+       SNDRV_PCM_FMTBIT_S18_3BE | SNDRV_PCM_FMTBIT_U18_3BE |   \
+       SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_U20_3LE |   \
+       SNDRV_PCM_FMTBIT_S20_3BE | SNDRV_PCM_FMTBIT_U20_3BE |   \
+       SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE |     \
+       SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE |     \
+       0)
+
+static inline unsigned long RD(struct au1xpsc_audio_data *ctx, int reg)
+{
+       return __raw_readl(ctx->mmio + reg);
+}
+
+static inline void WR(struct au1xpsc_audio_data *ctx, int reg, unsigned long v)
+{
+       __raw_writel(v, ctx->mmio + reg);
+       wmb();
+}
+
+static int au1xi2s_set_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt)
+{
+       struct au1xpsc_audio_data *ctx = snd_soc_dai_get_drvdata(cpu_dai);
+       unsigned long c;
+       int ret;
+
+       ret = -EINVAL;
+       c = ctx->cfg;
+
+       c &= ~CFG_FM_MASK;
+       switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+       case SND_SOC_DAIFMT_I2S:
+               c |= CFG_FM_I2S;
+               break;
+       case SND_SOC_DAIFMT_MSB:
+               c |= CFG_FM_RJ;
+               break;
+       case SND_SOC_DAIFMT_LSB:
+               c |= CFG_FM_LJ;
+               break;
+       default:
+               goto out;
+       }
+
+       c &= ~(CFG_IC | CFG_ICK);               /* IB-IF */
+       switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
+       case SND_SOC_DAIFMT_NB_NF:
+               c |= CFG_IC | CFG_ICK;
+               break;
+       case SND_SOC_DAIFMT_NB_IF:
+               c |= CFG_IC;
+               break;
+       case SND_SOC_DAIFMT_IB_NF:
+               c |= CFG_ICK;
+               break;
+       case SND_SOC_DAIFMT_IB_IF:
+               break;
+       default:
+               goto out;
+       }
+
+       /* I2S controller only supports master */
+       switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
+       case SND_SOC_DAIFMT_CBS_CFS:    /* CODEC slave */
+               break;
+       default:
+               goto out;
+       }
+
+       ret = 0;
+       ctx->cfg = c;
+out:
+       return ret;
+}
+
+static int au1xi2s_trigger(struct snd_pcm_substream *substream,
+                          int cmd, struct snd_soc_dai *dai)
+{
+       struct au1xpsc_audio_data *ctx = snd_soc_dai_get_drvdata(dai);
+       int stype = SUBSTREAM_TYPE(substream);
+
+       switch (cmd) {
+       case SNDRV_PCM_TRIGGER_START:
+       case SNDRV_PCM_TRIGGER_RESUME:
+               /* power up */
+               WR(ctx, I2S_ENABLE, EN_D | EN_CE);
+               WR(ctx, I2S_ENABLE, EN_CE);
+               ctx->cfg |= (stype == PCM_TX) ? CFG_TN : CFG_RN;
+               WR(ctx, I2S_CFG, ctx->cfg);
+               break;
+       case SNDRV_PCM_TRIGGER_STOP:
+       case SNDRV_PCM_TRIGGER_SUSPEND:
+               ctx->cfg &= ~((stype == PCM_TX) ? CFG_TN : CFG_RN);
+               WR(ctx, I2S_CFG, ctx->cfg);
+               WR(ctx, I2S_ENABLE, EN_D);              /* power off */
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static unsigned long msbits_to_reg(int msbits)
+{
+       switch (msbits) {
+       case 8:
+               return CFG_SZ_8;
+       case 16:
+               return CFG_SZ_16;
+       case 18:
+               return CFG_SZ_18;
+       case 20:
+               return CFG_SZ_20;
+       case 24:
+               return CFG_SZ_24;
+       }
+       return 0;
+}
+
+static int au1xi2s_hw_params(struct snd_pcm_substream *substream,
+                            struct snd_pcm_hw_params *params,
+                            struct snd_soc_dai *dai)
+{
+       struct au1xpsc_audio_data *ctx = snd_soc_dai_get_drvdata(dai);
+       unsigned long v;
+
+       v = msbits_to_reg(params->msbits);
+       if (!v)
+               return -EINVAL;
+
+       ctx->cfg &= ~CFG_SZ_MASK;
+       ctx->cfg |= v;
+       return 0;
+}
+
+static int au1xi2s_startup(struct snd_pcm_substream *substream,
+                          struct snd_soc_dai *dai)
+{
+       struct au1xpsc_audio_data *ctx = snd_soc_dai_get_drvdata(dai);
+       snd_soc_dai_set_dma_data(dai, substream, &ctx->dmaids[0]);
+       return 0;
+}
+
+static const struct snd_soc_dai_ops au1xi2s_dai_ops = {
+       .startup        = au1xi2s_startup,
+       .trigger        = au1xi2s_trigger,
+       .hw_params      = au1xi2s_hw_params,
+       .set_fmt        = au1xi2s_set_fmt,
+};
+
+static struct snd_soc_dai_driver au1xi2s_dai_driver = {
+       .symmetric_rates        = 1,
+       .playback = {
+               .rates          = AU1XI2SC_RATES,
+               .formats        = AU1XI2SC_FMTS,
+               .channels_min   = 2,
+               .channels_max   = 2,
+       },
+       .capture = {
+               .rates          = AU1XI2SC_RATES,
+               .formats        = AU1XI2SC_FMTS,
+               .channels_min   = 2,
+               .channels_max   = 2,
+       },
+       .ops = &au1xi2s_dai_ops,
+};
+
+static int __devinit au1xi2s_drvprobe(struct platform_device *pdev)
+{
+       int ret;
+       struct resource *iores, *dmares;
+       struct au1xpsc_audio_data *ctx;
+
+       ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
+       if (!ctx)
+               return -ENOMEM;
+
+       iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!iores) {
+               ret = -ENODEV;
+               goto out0;
+       }
+
+       ret = -EBUSY;
+       if (!request_mem_region(iores->start, resource_size(iores),
+                               pdev->name))
+               goto out0;
+
+       ctx->mmio = ioremap_nocache(iores->start, resource_size(iores));
+       if (!ctx->mmio)
+               goto out1;
+
+       dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0);
+       if (!dmares)
+               goto out2;
+       ctx->dmaids[SNDRV_PCM_STREAM_PLAYBACK] = dmares->start;
+
+       dmares = platform_get_resource(pdev, IORESOURCE_DMA, 1);
+       if (!dmares)
+               goto out2;
+       ctx->dmaids[SNDRV_PCM_STREAM_CAPTURE] = dmares->start;
+
+       platform_set_drvdata(pdev, ctx);
+
+       ret = snd_soc_register_dai(&pdev->dev, &au1xi2s_dai_driver);
+       if (ret)
+               goto out2;
+
+       return 0;
+
+out2:
+       iounmap(ctx->mmio);
+out1:
+       release_mem_region(iores->start, resource_size(iores));
+out0:
+       kfree(ctx);
+       return ret;
+}
+
+static int __devexit au1xi2s_drvremove(struct platform_device *pdev)
+{
+       struct au1xpsc_audio_data *ctx = platform_get_drvdata(pdev);
+       struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+
+       snd_soc_unregister_dai(&pdev->dev);
+
+       WR(ctx, I2S_ENABLE, EN_D);      /* clock off, disable */
+
+       iounmap(ctx->mmio);
+       release_mem_region(r->start, resource_size(r));
+       kfree(ctx);
+
+       return 0;
+}
+
+#ifdef CONFIG_PM
+static int au1xi2s_drvsuspend(struct device *dev)
+{
+       struct au1xpsc_audio_data *ctx = dev_get_drvdata(dev);
+
+       WR(ctx, I2S_ENABLE, EN_D);      /* clock off, disable */
+
+       return 0;
+}
+
+static int au1xi2s_drvresume(struct device *dev)
+{
+       return 0;
+}
+
+static const struct dev_pm_ops au1xi2sc_pmops = {
+       .suspend        = au1xi2s_drvsuspend,
+       .resume         = au1xi2s_drvresume,
+};
+
+#define AU1XI2SC_PMOPS (&au1xi2sc_pmops)
+
+#else
+
+#define AU1XI2SC_PMOPS NULL
+
+#endif
+
+static struct platform_driver au1xi2s_driver = {
+       .driver = {
+               .name   = "alchemy-i2sc",
+               .owner  = THIS_MODULE,
+               .pm     = AU1XI2SC_PMOPS,
+       },
+       .probe          = au1xi2s_drvprobe,
+       .remove         = __devexit_p(au1xi2s_drvremove),
+};
+
+static int __init au1xi2s_load(void)
+{
+       return platform_driver_register(&au1xi2s_driver);
+}
+
+static void __exit au1xi2s_unload(void)
+{
+       platform_driver_unregister(&au1xi2s_driver);
+}
+
+module_init(au1xi2s_load);
+module_exit(au1xi2s_unload);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Au1000/1500/1100 I2S ASoC driver");
+MODULE_AUTHOR("Manuel Lauss");
index d0db66f24a00cc0ce68f622161bef3b4155a7c82..0c6acd54714100b09401fac0278f4b412821f0b9 100644 (file)
        (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3BE)
 
 #define AC97PCR_START(stype)   \
-       ((stype) == PCM_TX ? PSC_AC97PCR_TS : PSC_AC97PCR_RS)
+       ((stype) == SNDRV_PCM_STREAM_PLAYBACK ? PSC_AC97PCR_TS : PSC_AC97PCR_RS)
 #define AC97PCR_STOP(stype)    \
-       ((stype) == PCM_TX ? PSC_AC97PCR_TP : PSC_AC97PCR_RP)
+       ((stype) == SNDRV_PCM_STREAM_PLAYBACK ? PSC_AC97PCR_TP : PSC_AC97PCR_RP)
 #define AC97PCR_CLRFIFO(stype) \
-       ((stype) == PCM_TX ? PSC_AC97PCR_TC : PSC_AC97PCR_RC)
+       ((stype) == SNDRV_PCM_STREAM_PLAYBACK ? PSC_AC97PCR_TC : PSC_AC97PCR_RC)
 
 #define AC97STAT_BUSY(stype)   \
-       ((stype) == PCM_TX ? PSC_AC97STAT_TB : PSC_AC97STAT_RB)
+       ((stype) == SNDRV_PCM_STREAM_PLAYBACK ? PSC_AC97STAT_TB : PSC_AC97STAT_RB)
 
 /* instance data. There can be only one, MacLeod!!!! */
 static struct au1xpsc_audio_data *au1xpsc_ac97_workdata;
@@ -215,7 +215,7 @@ static int au1xpsc_ac97_hw_params(struct snd_pcm_substream *substream,
 {
        struct au1xpsc_audio_data *pscdata = snd_soc_dai_get_drvdata(dai);
        unsigned long r, ro, stat;
-       int chans, t, stype = SUBSTREAM_TYPE(substream);
+       int chans, t, stype = substream->stream;
 
        chans = params_channels(params);
 
@@ -235,7 +235,7 @@ static int au1xpsc_ac97_hw_params(struct snd_pcm_substream *substream,
                r |= PSC_AC97CFG_SET_LEN(params->msbits);
 
                /* channels: enable slots for front L/R channel */
-               if (stype == PCM_TX) {
+               if (stype == SNDRV_PCM_STREAM_PLAYBACK) {
                        r &= ~PSC_AC97CFG_TXSLOT_MASK;
                        r |= PSC_AC97CFG_TXSLOT_ENA(3);
                        r |= PSC_AC97CFG_TXSLOT_ENA(4);
@@ -294,7 +294,7 @@ static int au1xpsc_ac97_trigger(struct snd_pcm_substream *substream,
                                int cmd, struct snd_soc_dai *dai)
 {
        struct au1xpsc_audio_data *pscdata = snd_soc_dai_get_drvdata(dai);
-       int ret, stype = SUBSTREAM_TYPE(substream);
+       int ret, stype = substream->stream;
 
        ret = 0;
 
@@ -324,12 +324,21 @@ static int au1xpsc_ac97_trigger(struct snd_pcm_substream *substream,
        return ret;
 }
 
+static int au1xpsc_ac97_startup(struct snd_pcm_substream *substream,
+                               struct snd_soc_dai *dai)
+{
+       struct au1xpsc_audio_data *pscdata = snd_soc_dai_get_drvdata(dai);
+       snd_soc_dai_set_dma_data(dai, substream, &pscdata->dmaids[0]);
+       return 0;
+}
+
 static int au1xpsc_ac97_probe(struct snd_soc_dai *dai)
 {
        return au1xpsc_ac97_workdata ? 0 : -ENODEV;
 }
 
 static struct snd_soc_dai_ops au1xpsc_ac97_dai_ops = {
+       .startup        = au1xpsc_ac97_startup,
        .trigger        = au1xpsc_ac97_trigger,
        .hw_params      = au1xpsc_ac97_hw_params,
 };
@@ -355,7 +364,7 @@ static const struct snd_soc_dai_driver au1xpsc_ac97_dai_template = {
 static int __devinit au1xpsc_ac97_drvprobe(struct platform_device *pdev)
 {
        int ret;
-       struct resource *r;
+       struct resource *iores, *dmares;
        unsigned long sel;
        struct au1xpsc_audio_data *wd;
 
@@ -365,20 +374,31 @@ static int __devinit au1xpsc_ac97_drvprobe(struct platform_device *pdev)
 
        mutex_init(&wd->lock);
 
-       r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       if (!r) {
+       iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!iores) {
                ret = -ENODEV;
                goto out0;
        }
 
        ret = -EBUSY;
-       if (!request_mem_region(r->start, resource_size(r), pdev->name))
+       if (!request_mem_region(iores->start, resource_size(iores),
+                               pdev->name))
                goto out0;
 
-       wd->mmio = ioremap(r->start, resource_size(r));
+       wd->mmio = ioremap(iores->start, resource_size(iores));
        if (!wd->mmio)
                goto out1;
 
+       dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0);
+       if (!dmares)
+               goto out2;
+       wd->dmaids[SNDRV_PCM_STREAM_PLAYBACK] = dmares->start;
+
+       dmares = platform_get_resource(pdev, IORESOURCE_DMA, 1);
+       if (!dmares)
+               goto out2;
+       wd->dmaids[SNDRV_PCM_STREAM_CAPTURE] = dmares->start;
+
        /* configuration: max dma trigger threshold, enable ac97 */
        wd->cfg = PSC_AC97CFG_RT_FIFO8 | PSC_AC97CFG_TT_FIFO8 |
                  PSC_AC97CFG_DE_ENABLE;
@@ -401,17 +421,15 @@ static int __devinit au1xpsc_ac97_drvprobe(struct platform_device *pdev)
 
        ret = snd_soc_register_dai(&pdev->dev, &wd->dai_drv);
        if (ret)
-               goto out1;
+               goto out2;
 
-       wd->dmapd = au1xpsc_pcm_add(pdev);
-       if (wd->dmapd) {
-               au1xpsc_ac97_workdata = wd;
-               return 0;
-       }
+       au1xpsc_ac97_workdata = wd;
+       return 0;
 
-       snd_soc_unregister_dai(&pdev->dev);
+out2:
+       iounmap(wd->mmio);
 out1:
-       release_mem_region(r->start, resource_size(r));
+       release_mem_region(iores->start, resource_size(iores));
 out0:
        kfree(wd);
        return ret;
@@ -422,9 +440,6 @@ static int __devexit au1xpsc_ac97_drvremove(struct platform_device *pdev)
        struct au1xpsc_audio_data *wd = platform_get_drvdata(pdev);
        struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 
-       if (wd->dmapd)
-               au1xpsc_pcm_destroy(wd->dmapd);
-
        snd_soc_unregister_dai(&pdev->dev);
 
        /* disable PSC completely */
index fca091276320930e7f8abd230556dabbc392e2d7..e03c5ce01b304ef680e1790f4fd9c39d1313483d 100644 (file)
        (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE)
 
 #define I2SSTAT_BUSY(stype)    \
-       ((stype) == PCM_TX ? PSC_I2SSTAT_TB : PSC_I2SSTAT_RB)
+       ((stype) == SNDRV_PCM_STREAM_PLAYBACK ? PSC_I2SSTAT_TB : PSC_I2SSTAT_RB)
 #define I2SPCR_START(stype)    \
-       ((stype) == PCM_TX ? PSC_I2SPCR_TS : PSC_I2SPCR_RS)
+       ((stype) == SNDRV_PCM_STREAM_PLAYBACK ? PSC_I2SPCR_TS : PSC_I2SPCR_RS)
 #define I2SPCR_STOP(stype)     \
-       ((stype) == PCM_TX ? PSC_I2SPCR_TP : PSC_I2SPCR_RP)
+       ((stype) == SNDRV_PCM_STREAM_PLAYBACK ? PSC_I2SPCR_TP : PSC_I2SPCR_RP)
 #define I2SPCR_CLRFIFO(stype)  \
-       ((stype) == PCM_TX ? PSC_I2SPCR_TC : PSC_I2SPCR_RC)
+       ((stype) == SNDRV_PCM_STREAM_PLAYBACK ? PSC_I2SPCR_TC : PSC_I2SPCR_RC)
 
 
 static int au1xpsc_i2s_set_fmt(struct snd_soc_dai *cpu_dai,
@@ -240,7 +240,7 @@ static int au1xpsc_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
                               struct snd_soc_dai *dai)
 {
        struct au1xpsc_audio_data *pscdata = snd_soc_dai_get_drvdata(dai);
-       int ret, stype = SUBSTREAM_TYPE(substream);
+       int ret, stype = substream->stream;
 
        switch (cmd) {
        case SNDRV_PCM_TRIGGER_START:
@@ -257,7 +257,16 @@ static int au1xpsc_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
        return ret;
 }
 
+static int au1xpsc_i2s_startup(struct snd_pcm_substream *substream,
+                              struct snd_soc_dai *dai)
+{
+       struct au1xpsc_audio_data *pscdata = snd_soc_dai_get_drvdata(dai);
+       snd_soc_dai_set_dma_data(dai, substream, &pscdata->dmaids[0]);
+       return 0;
+}
+
 static struct snd_soc_dai_ops au1xpsc_i2s_dai_ops = {
+       .startup        = au1xpsc_i2s_startup,
        .trigger        = au1xpsc_i2s_trigger,
        .hw_params      = au1xpsc_i2s_hw_params,
        .set_fmt        = au1xpsc_i2s_set_fmt,
@@ -281,7 +290,7 @@ static const struct snd_soc_dai_driver au1xpsc_i2s_dai_template = {
 
 static int __devinit au1xpsc_i2s_drvprobe(struct platform_device *pdev)
 {
-       struct resource *r;
+       struct resource *iores, *dmares;
        unsigned long sel;
        int ret;
        struct au1xpsc_audio_data *wd;
@@ -290,20 +299,31 @@ static int __devinit au1xpsc_i2s_drvprobe(struct platform_device *pdev)
        if (!wd)
                return -ENOMEM;
 
-       r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       if (!r) {
+       iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!iores) {
                ret = -ENODEV;
                goto out0;
        }
 
        ret = -EBUSY;
-       if (!request_mem_region(r->start, resource_size(r), pdev->name))
+       if (!request_mem_region(iores->start, resource_size(iores),
+                               pdev->name))
                goto out0;
 
-       wd->mmio = ioremap(r->start, resource_size(r));
+       wd->mmio = ioremap(iores->start, resource_size(iores));
        if (!wd->mmio)
                goto out1;
 
+       dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0);
+       if (!dmares)
+               goto out2;
+       wd->dmaids[SNDRV_PCM_STREAM_PLAYBACK] = dmares->start;
+
+       dmares = platform_get_resource(pdev, IORESOURCE_DMA, 1);
+       if (!dmares)
+               goto out2;
+       wd->dmaids[SNDRV_PCM_STREAM_CAPTURE] = dmares->start;
+
        /* preserve PSC clock source set up by platform (dev.platform_data
         * is already occupied by soc layer)
         */
@@ -330,17 +350,13 @@ static int __devinit au1xpsc_i2s_drvprobe(struct platform_device *pdev)
        platform_set_drvdata(pdev, wd);
 
        ret = snd_soc_register_dai(&pdev->dev, &wd->dai_drv);
-       if (ret)
-               goto out1;
-
-       /* finally add the DMA device for this PSC */
-       wd->dmapd = au1xpsc_pcm_add(pdev);
-       if (wd->dmapd)
+       if (!ret)
                return 0;
 
-       snd_soc_unregister_dai(&pdev->dev);
+out2:
+       iounmap(wd->mmio);
 out1:
-       release_mem_region(r->start, resource_size(r));
+       release_mem_region(iores->start, resource_size(iores));
 out0:
        kfree(wd);
        return ret;
@@ -351,9 +367,6 @@ static int __devexit au1xpsc_i2s_drvremove(struct platform_device *pdev)
        struct au1xpsc_audio_data *wd = platform_get_drvdata(pdev);
        struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 
-       if (wd->dmapd)
-               au1xpsc_pcm_destroy(wd->dmapd);
-
        snd_soc_unregister_dai(&pdev->dev);
 
        au_writel(0, I2S_CFG(wd));
index b30eadd422a7fb7aee4856e671d491d769d2c6ac..b16b2e02e0c9dec6dac5450ab922255059ee2283 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * Au12x0/Au1550 PSC ALSA ASoC audio support.
+ * Alchemy ALSA ASoC audio support.
  *
- * (c) 2007-2008 MSC Vertriebsges.m.b.H.,
+ * (c) 2007-2011 MSC Vertriebsges.m.b.H.,
  *     Manuel Lauss <manuel.lauss@gmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
 #ifndef _AU1X_PCM_H
 #define _AU1X_PCM_H
 
-/* DBDMA helpers */
-extern struct platform_device *au1xpsc_pcm_add(struct platform_device *pdev);
-extern void au1xpsc_pcm_destroy(struct platform_device *dmapd);
-
 struct au1xpsc_audio_data {
        void __iomem *mmio;
 
@@ -27,15 +23,9 @@ struct au1xpsc_audio_data {
 
        unsigned long pm[2];
        struct mutex lock;
-       struct platform_device *dmapd;
+       int dmaids[2];
 };
 
-#define PCM_TX 0
-#define PCM_RX 1
-
-#define SUBSTREAM_TYPE(substream) \
-       ((substream)->stream == SNDRV_PCM_STREAM_PLAYBACK ? PCM_TX : PCM_RX)
-
 /* easy access macros */
 #define PSC_CTRL(x)    ((unsigned long)((x)->mmio) + PSC_CTRL_OFFSET)
 #define PSC_SEL(x)     ((unsigned long)((x)->mmio) + PSC_SEL_OFFSET)
index fe9d548a683705ae1627a7b4a005ca5adfb760cd..9f6bc55fc399301c60dd4603e17642cb92f26d9b 100644 (file)
@@ -27,6 +27,19 @@ config SND_SOC_BFIN_EVAL_ADAU1701
          board connected to one of the Blackfin evaluation boards like the
          BF5XX-STAMP or BF5XX-EZKIT.
 
+config SND_SOC_BFIN_EVAL_ADAU1373
+       tristate "Support for the EVAL-ADAU1373 board on Blackfin eval boards"
+       depends on SND_BF5XX_I2S && I2C
+       select SND_BF5XX_SOC_I2S
+       select SND_SOC_ADAU1373
+       help
+         Say Y if you want to add support for the Analog Devices EVAL-ADAU1373
+         board connected to one of the Blackfin evaluation boards like the
+         BF5XX-STAMP or BF5XX-EZKIT.
+
+         Note: This driver assumes that first ADAU1373 DAI is connected to the
+         first SPORT port on the BF5XX board.
+
 config SND_SOC_BFIN_EVAL_ADAV80X
        tristate "Support for the EVAL-ADAV80X boards on Blackfin eval boards"
        depends on SND_BF5XX_I2S && (SPI_MASTER || I2C)
index 6018bf52a234f9592ae1b00d34243c83e9d113f4..1bf86ccaa8de2071f0bcce1bdec796a870eaa3e6 100644 (file)
@@ -21,6 +21,7 @@ snd-ad1980-objs := bf5xx-ad1980.o
 snd-ssm2602-objs := bf5xx-ssm2602.o
 snd-ad73311-objs := bf5xx-ad73311.o
 snd-ad193x-objs := bf5xx-ad193x.o
+snd-soc-bfin-eval-adau1373-objs := bfin-eval-adau1373.o
 snd-soc-bfin-eval-adau1701-objs := bfin-eval-adau1701.o
 snd-soc-bfin-eval-adav80x-objs := bfin-eval-adav80x.o
 
@@ -29,5 +30,6 @@ obj-$(CONFIG_SND_BF5XX_SOC_AD1980) += snd-ad1980.o
 obj-$(CONFIG_SND_BF5XX_SOC_SSM2602) += snd-ssm2602.o
 obj-$(CONFIG_SND_BF5XX_SOC_AD73311) += snd-ad73311.o
 obj-$(CONFIG_SND_BF5XX_SOC_AD193X) += snd-ad193x.o
+obj-$(CONFIG_SND_SOC_BFIN_EVAL_ADAU1373) += snd-soc-bfin-eval-adau1373.o
 obj-$(CONFIG_SND_SOC_BFIN_EVAL_ADAU1701) += snd-soc-bfin-eval-adau1701.o
 obj-$(CONFIG_SND_SOC_BFIN_EVAL_ADAV80X) += snd-soc-bfin-eval-adav80x.o
index 9e59f680bc197224e642b9b61339bf67eb75fba9..56815c1d47b3fdb36f278e05894fc54a6ace93d7 100644 (file)
@@ -418,7 +418,7 @@ static void bf5xx_pcm_free_dma_buffers(struct snd_pcm *pcm)
 
 static u64 bf5xx_pcm_dmamask = DMA_BIT_MASK(32);
 
-int bf5xx_pcm_ac97_new(struct snd_soc_pcm_runtime *rtd)
+static int bf5xx_pcm_ac97_new(struct snd_soc_pcm_runtime *rtd)
 {
        struct snd_card *card = rtd->card->snd_card;
        struct snd_soc_dai *dai = rtd->cpu_dai;
index 61ddf942fd4d0269c499c936d631d0959d261453..7565e1576ffa47a04ab165423cda019eb53c7375 100644 (file)
@@ -257,7 +257,7 @@ static void bf5xx_pcm_free_dma_buffers(struct snd_pcm *pcm)
 
 static u64 bf5xx_pcm_dmamask = DMA_BIT_MASK(32);
 
-int bf5xx_pcm_i2s_new(struct snd_soc_pcm_runtime *rtd)
+static int bf5xx_pcm_i2s_new(struct snd_soc_pcm_runtime *rtd)
 {
        struct snd_card *card = rtd->card->snd_card;
        struct snd_soc_dai *dai = rtd->cpu_dai;
diff --git a/sound/soc/blackfin/bfin-eval-adau1373.c b/sound/soc/blackfin/bfin-eval-adau1373.c
new file mode 100644 (file)
index 0000000..8df2a3b
--- /dev/null
@@ -0,0 +1,202 @@
+/*
+ * Machine driver for EVAL-ADAU1373 on Analog Devices bfin
+ * evaluation boards.
+ *
+ * Copyright 2011 Analog Devices Inc.
+ * Author: Lars-Peter Clausen <lars@metafoo.de>
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#include <linux/module.h>
+#include <linux/device.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/soc.h>
+#include <sound/pcm_params.h>
+
+#include "../codecs/adau1373.h"
+
+static const struct snd_soc_dapm_widget bfin_eval_adau1373_dapm_widgets[] = {
+       SND_SOC_DAPM_LINE("Line In1", NULL),
+       SND_SOC_DAPM_LINE("Line In2", NULL),
+       SND_SOC_DAPM_LINE("Line In3", NULL),
+       SND_SOC_DAPM_LINE("Line In4", NULL),
+
+       SND_SOC_DAPM_LINE("Line Out1", NULL),
+       SND_SOC_DAPM_LINE("Line Out2", NULL),
+       SND_SOC_DAPM_LINE("Stereo Out", NULL),
+       SND_SOC_DAPM_HP("Headphone", NULL),
+       SND_SOC_DAPM_HP("Earpiece", NULL),
+       SND_SOC_DAPM_SPK("Speaker", NULL),
+};
+
+static const struct snd_soc_dapm_route bfin_eval_adau1373_dapm_routes[] = {
+       { "AIN1L", NULL, "Line In1" },
+       { "AIN1R", NULL, "Line In1" },
+       { "AIN2L", NULL, "Line In2" },
+       { "AIN2R", NULL, "Line In2" },
+       { "AIN3L", NULL, "Line In3" },
+       { "AIN3R", NULL, "Line In3" },
+       { "AIN4L", NULL, "Line In4" },
+       { "AIN4R", NULL, "Line In4" },
+
+       /* MICBIAS can be connected via a jumper to the line-in jack, since w
+          don't know which one is going to be used, just power both. */
+       { "Line In1", NULL, "MICBIAS1" },
+       { "Line In2", NULL, "MICBIAS1" },
+       { "Line In3", NULL, "MICBIAS1" },
+       { "Line In4", NULL, "MICBIAS1" },
+       { "Line In1", NULL, "MICBIAS2" },
+       { "Line In2", NULL, "MICBIAS2" },
+       { "Line In3", NULL, "MICBIAS2" },
+       { "Line In4", NULL, "MICBIAS2" },
+
+       { "Line Out1", NULL, "LOUT1L" },
+       { "Line Out1", NULL, "LOUT1R" },
+       { "Line Out2", NULL, "LOUT2L" },
+       { "Line Out2", NULL, "LOUT2R" },
+       { "Headphone", NULL, "HPL" },
+       { "Headphone", NULL, "HPR" },
+       { "Earpiece", NULL, "EP" },
+       { "Speaker", NULL, "SPKL" },
+       { "Stereo Out", NULL, "SPKR" },
+};
+
+static int bfin_eval_adau1373_hw_params(struct snd_pcm_substream *substream,
+       struct snd_pcm_hw_params *params)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+       struct snd_soc_dai *codec_dai = rtd->codec_dai;
+       int ret;
+       int pll_rate;
+
+       ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
+                       SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
+       if (ret)
+               return ret;
+
+       ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
+                       SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
+       if (ret)
+               return ret;
+
+       switch (params_rate(params)) {
+       case 48000:
+       case 8000:
+       case 12000:
+       case 16000:
+       case 24000:
+       case 32000:
+               pll_rate = 48000 * 1024;
+               break;
+       case 44100:
+       case 7350:
+       case 11025:
+       case 14700:
+       case 22050:
+       case 29400:
+               pll_rate = 44100 * 1024;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       ret = snd_soc_dai_set_pll(codec_dai, ADAU1373_PLL1,
+                       ADAU1373_PLL_SRC_MCLK1, 12288000, pll_rate);
+       if (ret)
+               return ret;
+
+       ret = snd_soc_dai_set_sysclk(codec_dai, ADAU1373_CLK_SRC_PLL1, pll_rate,
+                       SND_SOC_CLOCK_IN);
+
+       return ret;
+}
+
+static int bfin_eval_adau1373_codec_init(struct snd_soc_pcm_runtime *rtd)
+{
+       struct snd_soc_dai *codec_dai = rtd->codec_dai;
+       unsigned int pll_rate = 48000 * 1024;
+       int ret;
+
+       ret = snd_soc_dai_set_pll(codec_dai, ADAU1373_PLL1,
+                       ADAU1373_PLL_SRC_MCLK1, 12288000, pll_rate);
+       if (ret)
+               return ret;
+
+       ret = snd_soc_dai_set_sysclk(codec_dai, ADAU1373_CLK_SRC_PLL1, pll_rate,
+                       SND_SOC_CLOCK_IN);
+
+       return ret;
+}
+static struct snd_soc_ops bfin_eval_adau1373_ops = {
+       .hw_params = bfin_eval_adau1373_hw_params,
+};
+
+static struct snd_soc_dai_link bfin_eval_adau1373_dai = {
+       .name = "adau1373",
+       .stream_name = "adau1373",
+       .cpu_dai_name = "bfin-i2s.0",
+       .codec_dai_name = "adau1373-aif1",
+       .platform_name = "bfin-i2s-pcm-audio",
+       .codec_name = "adau1373.0-001a",
+       .ops = &bfin_eval_adau1373_ops,
+       .init = bfin_eval_adau1373_codec_init,
+};
+
+static struct snd_soc_card bfin_eval_adau1373 = {
+       .name = "bfin-eval-adau1373",
+       .dai_link = &bfin_eval_adau1373_dai,
+       .num_links = 1,
+
+       .dapm_widgets           = bfin_eval_adau1373_dapm_widgets,
+       .num_dapm_widgets       = ARRAY_SIZE(bfin_eval_adau1373_dapm_widgets),
+       .dapm_routes            = bfin_eval_adau1373_dapm_routes,
+       .num_dapm_routes        = ARRAY_SIZE(bfin_eval_adau1373_dapm_routes),
+};
+
+static int bfin_eval_adau1373_probe(struct platform_device *pdev)
+{
+       struct snd_soc_card *card = &bfin_eval_adau1373;
+
+       card->dev = &pdev->dev;
+
+       return snd_soc_register_card(&bfin_eval_adau1373);
+}
+
+static int __devexit bfin_eval_adau1373_remove(struct platform_device *pdev)
+{
+       struct snd_soc_card *card = platform_get_drvdata(pdev);
+
+       snd_soc_unregister_card(card);
+
+       return 0;
+}
+
+static struct platform_driver bfin_eval_adau1373_driver = {
+       .driver = {
+               .name = "bfin-eval-adau1373",
+               .owner = THIS_MODULE,
+               .pm = &snd_soc_pm_ops,
+       },
+       .probe = bfin_eval_adau1373_probe,
+       .remove = __devexit_p(bfin_eval_adau1373_remove),
+};
+
+static int __init bfin_eval_adau1373_init(void)
+{
+       return platform_driver_register(&bfin_eval_adau1373_driver);
+}
+module_init(bfin_eval_adau1373_init);
+
+static void __exit bfin_eval_adau1373_exit(void)
+{
+       platform_driver_unregister(&bfin_eval_adau1373_driver);
+}
+module_exit(bfin_eval_adau1373_exit);
+
+MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
+MODULE_DESCRIPTION("ALSA SoC bfin adau1373 driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:bfin-eval-adau1373");
index 19241576b6b590a9982b457fe405d0e245c7aca7..5ca122e51183a4531c612613c0bbf6c94da9f272 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/platform_device.h>
 #include <linux/mfd/88pm860x.h>
 #include <linux/slab.h>
+#include <linux/delay.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
@@ -772,11 +773,12 @@ static const struct snd_soc_dapm_widget pm860x_dapm_widgets[] = {
 
 
        SND_SOC_DAPM_AIF_IN("I2S DIN", "I2S Playback", 0,
-                           PM860X_DAC_EN_2, 0, 0),
+                           SND_SOC_NOPM, 0, 0),
        SND_SOC_DAPM_AIF_IN("I2S DIN1", "I2S Playback", 0,
-                           PM860X_DAC_EN_2, 0, 0),
+                           SND_SOC_NOPM, 0, 0),
        SND_SOC_DAPM_AIF_OUT("I2S DOUT", "I2S Capture", 0,
                             PM860X_I2S_IFACE_3, 5, 1),
+       SND_SOC_DAPM_SUPPLY("I2S CLK", PM860X_DAC_EN_2, 0, 0, NULL, 0),
        SND_SOC_DAPM_MUX("I2S Mic Mux", SND_SOC_NOPM, 0, 0, &i2s_mic_mux),
        SND_SOC_DAPM_MUX("ADC Left Mux", SND_SOC_NOPM, 0, 0, &adcl_mux),
        SND_SOC_DAPM_MUX("ADC Right Mux", SND_SOC_NOPM, 0, 0, &adcr_mux),
@@ -868,6 +870,11 @@ static const struct snd_soc_dapm_route audio_map[] = {
        {"Left ADC", NULL, "Left ADC MOD"},
        {"Right ADC", NULL, "Right ADC MOD"},
 
+       /* I2S Clock */
+       {"I2S DIN", NULL, "I2S CLK"},
+       {"I2S DIN1", NULL, "I2S CLK"},
+       {"I2S DOUT", NULL, "I2S CLK"},
+
        /* PCM/AIF1 Inputs */
        {"PCM SDO", NULL, "ADC Left Mux"},
        {"PCM SDO", NULL, "ADCR EC Mux"},
@@ -1173,6 +1180,9 @@ static int pm860x_set_bias_level(struct snd_soc_codec *codec,
        case SND_SOC_BIAS_STANDBY:
                if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
                        /* Enable Audio PLL & Audio section */
+                       data = AUDIO_PLL | AUDIO_SECTION_ON;
+                       pm860x_reg_write(codec->control_data, REG_MISC2, data);
+                       udelay(300);
                        data = AUDIO_PLL | AUDIO_SECTION_RESET
                                | AUDIO_SECTION_ON;
                        pm860x_reg_write(codec->control_data, REG_MISC2, data);
index 665d9240c4ae46e7005a46484598333052a752d3..4584514d93d4fd21a92de37847d318951e824bf8 100644 (file)
@@ -17,6 +17,7 @@ config SND_SOC_ALL_CODECS
        select SND_SOC_AD193X if SND_SOC_I2C_AND_SPI
        select SND_SOC_AD1980 if SND_SOC_AC97_BUS
        select SND_SOC_AD73311
+       select SND_SOC_ADAU1373 if I2C
        select SND_SOC_ADAV80X
        select SND_SOC_ADS117X
        select SND_SOC_AK4104 if SPI_MASTER
@@ -39,6 +40,7 @@ config SND_SOC_ALL_CODECS
        select SND_SOC_MAX9850 if I2C
        select SND_SOC_MAX9877 if I2C
        select SND_SOC_PCM3008
+       select SND_SOC_RT5631 if I2C
        select SND_SOC_SGTL5000 if I2C
        select SND_SOC_SN95031 if INTEL_SCU_IPC
        select SND_SOC_SPDIF
@@ -47,7 +49,7 @@ config SND_SOC_ALL_CODECS
        select SND_SOC_STAC9766 if SND_SOC_AC97_BUS
        select SND_SOC_TLV320AIC23 if I2C
        select SND_SOC_TLV320AIC26 if SPI_MASTER
-       select SND_SOC_TVL320AIC32X4 if I2C
+       select SND_SOC_TLV320AIC32X4 if I2C
        select SND_SOC_TLV320AIC3X if I2C
        select SND_SOC_TPA6130A2 if I2C
        select SND_SOC_TLV320DAC33 if I2C
@@ -58,6 +60,7 @@ config SND_SOC_ALL_CODECS
        select SND_SOC_WL1273 if MFD_WL1273_CORE
        select SND_SOC_WM1250_EV1 if I2C
        select SND_SOC_WM2000 if I2C
+       select SND_SOC_WM5100 if I2C
        select SND_SOC_WM8350 if MFD_WM8350
        select SND_SOC_WM8400 if MFD_WM8400
        select SND_SOC_WM8510 if SND_SOC_I2C_AND_SPI
@@ -139,6 +142,9 @@ config SND_SOC_ADAU1701
        select SIGMA
        tristate
 
+config SND_SOC_ADAU1373
+       tristate
+
 config SND_SOC_ADAV80X
        tristate
 
@@ -214,6 +220,9 @@ config SND_SOC_MAX9850
 config SND_SOC_PCM3008
        tristate
 
+config SND_SOC_RT5631
+       tristate
+
 #Freescale sgtl5000 codec
 config SND_SOC_SGTL5000
        tristate
@@ -240,7 +249,7 @@ config SND_SOC_TLV320AIC26
        tristate "TI TLV320AIC26 Codec support" if SND_SOC_OF_SIMPLE
        depends on SPI
 
-config SND_SOC_TVL320AIC32X4
+config SND_SOC_TLV320AIC32X4
        tristate
 
 config SND_SOC_TLV320AIC3X
@@ -269,6 +278,9 @@ config SND_SOC_WL1273
 config SND_SOC_WM1250_EV1
        tristate
 
+config SND_SOC_WM5100
+       tristate
+
 config SND_SOC_WM8350
        tristate
 
index 5119a7e2c1a843b438ebed2865723f836c60b152..a2c7842e357b6c3aa899a9e93155bed9855c2bbf 100644 (file)
@@ -5,6 +5,7 @@ snd-soc-ad193x-objs := ad193x.o
 snd-soc-ad1980-objs := ad1980.o
 snd-soc-ad73311-objs := ad73311.o
 snd-soc-adau1701-objs := adau1701.o
+snd-soc-adau1373-objs := adau1373.o
 snd-soc-adav80x-objs := adav80x.o
 snd-soc-ads117x-objs := ads117x.o
 snd-soc-ak4104-objs := ak4104.o
@@ -25,6 +26,7 @@ snd-soc-max98088-objs := max98088.o
 snd-soc-max98095-objs := max98095.o
 snd-soc-max9850-objs := max9850.o
 snd-soc-pcm3008-objs := pcm3008.o
+snd-soc-rt5631-objs := rt5631.o
 snd-soc-sgtl5000-objs := sgtl5000.o
 snd-soc-alc5623-objs := alc5623.o
 snd-soc-sn95031-objs := sn95031.o
@@ -43,6 +45,7 @@ snd-soc-uda134x-objs := uda134x.o
 snd-soc-uda1380-objs := uda1380.o
 snd-soc-wl1273-objs := wl1273.o
 snd-soc-wm1250-ev1-objs := wm1250-ev1.o
+snd-soc-wm5100-objs := wm5100.o wm5100-tables.o
 snd-soc-wm8350-objs := wm8350.o
 snd-soc-wm8400-objs := wm8400.o
 snd-soc-wm8510-objs := wm8510.o
@@ -100,6 +103,7 @@ obj-$(CONFIG_SND_SOC_AD1836)        += snd-soc-ad1836.o
 obj-$(CONFIG_SND_SOC_AD193X)   += snd-soc-ad193x.o
 obj-$(CONFIG_SND_SOC_AD1980)   += snd-soc-ad1980.o
 obj-$(CONFIG_SND_SOC_AD73311) += snd-soc-ad73311.o
+obj-$(CONFIG_SND_SOC_ADAU1373) += snd-soc-adau1373.o
 obj-$(CONFIG_SND_SOC_ADAU1701)  += snd-soc-adau1701.o
 obj-$(CONFIG_SND_SOC_ADAV80X)  += snd-soc-adav80x.o
 obj-$(CONFIG_SND_SOC_ADS117X)  += snd-soc-ads117x.o
@@ -123,6 +127,7 @@ obj-$(CONFIG_SND_SOC_MAX98088)      += snd-soc-max98088.o
 obj-$(CONFIG_SND_SOC_MAX98095) += snd-soc-max98095.o
 obj-$(CONFIG_SND_SOC_MAX9850)  += snd-soc-max9850.o
 obj-$(CONFIG_SND_SOC_PCM3008)  += snd-soc-pcm3008.o
+obj-$(CONFIG_SND_SOC_RT5631)   += snd-soc-rt5631.o
 obj-$(CONFIG_SND_SOC_SGTL5000)  += snd-soc-sgtl5000.o
 obj-$(CONFIG_SND_SOC_SN95031)  +=snd-soc-sn95031.o
 obj-$(CONFIG_SND_SOC_SPDIF)    += snd-soc-spdif.o
@@ -132,7 +137,7 @@ obj-$(CONFIG_SND_SOC_STAC9766)      += snd-soc-stac9766.o
 obj-$(CONFIG_SND_SOC_TLV320AIC23)      += snd-soc-tlv320aic23.o
 obj-$(CONFIG_SND_SOC_TLV320AIC26)      += snd-soc-tlv320aic26.o
 obj-$(CONFIG_SND_SOC_TLV320AIC3X)      += snd-soc-tlv320aic3x.o
-obj-$(CONFIG_SND_SOC_TVL320AIC32X4)     += snd-soc-tlv320aic32x4.o
+obj-$(CONFIG_SND_SOC_TLV320AIC32X4)     += snd-soc-tlv320aic32x4.o
 obj-$(CONFIG_SND_SOC_TLV320DAC33)      += snd-soc-tlv320dac33.o
 obj-$(CONFIG_SND_SOC_TWL4030)  += snd-soc-twl4030.o
 obj-$(CONFIG_SND_SOC_TWL6040)  += snd-soc-twl6040.o
@@ -140,6 +145,7 @@ obj-$(CONFIG_SND_SOC_UDA134X)       += snd-soc-uda134x.o
 obj-$(CONFIG_SND_SOC_UDA1380)  += snd-soc-uda1380.o
 obj-$(CONFIG_SND_SOC_WL1273)   += snd-soc-wl1273.o
 obj-$(CONFIG_SND_SOC_WM1250_EV1) += snd-soc-wm1250-ev1.o
+obj-$(CONFIG_SND_SOC_WM5100)   += snd-soc-wm5100.o
 obj-$(CONFIG_SND_SOC_WM8350)   += snd-soc-wm8350.o
 obj-$(CONFIG_SND_SOC_WM8400)   += snd-soc-wm8400.o
 obj-$(CONFIG_SND_SOC_WM8510)   += snd-soc-wm8510.o
index eedb6f5e5823499919e14611db21a747a2a023b6..120602130b5c0a667cc612ab97877d016bb5a667 100644 (file)
@@ -23,7 +23,7 @@
 
 /* codec private data */
 struct ad193x_priv {
-       enum snd_soc_control_type control_type;
+       struct regmap *regmap;
        int sysclk;
 };
 
@@ -103,12 +103,14 @@ static const struct snd_soc_dapm_route audio_paths[] = {
 static int ad193x_mute(struct snd_soc_dai *dai, int mute)
 {
        struct snd_soc_codec *codec = dai->codec;
-       int reg;
 
-       reg = snd_soc_read(codec, AD193X_DAC_CTRL2);
-       reg = (mute > 0) ? reg | AD193X_DAC_MASTER_MUTE : reg &
-               (~AD193X_DAC_MASTER_MUTE);
-       snd_soc_write(codec, AD193X_DAC_CTRL2, reg);
+       if (mute)
+               snd_soc_update_bits(codec, AD193X_DAC_CTRL2,
+                                   AD193X_DAC_MASTER_MUTE,
+                                   AD193X_DAC_MASTER_MUTE);
+       else
+               snd_soc_update_bits(codec, AD193X_DAC_CTRL2,
+                                   AD193X_DAC_MASTER_MUTE, 0);
 
        return 0;
 }
@@ -262,7 +264,7 @@ static int ad193x_hw_params(struct snd_pcm_substream *substream,
                struct snd_pcm_hw_params *params,
                struct snd_soc_dai *dai)
 {
-       int word_len = 0, reg = 0, master_rate = 0;
+       int word_len = 0, master_rate = 0;
 
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_codec *codec = rtd->codec;
@@ -297,18 +299,15 @@ static int ad193x_hw_params(struct snd_pcm_substream *substream,
                break;
        }
 
-       reg = snd_soc_read(codec, AD193X_PLL_CLK_CTRL0);
-       reg = (reg & AD193X_PLL_INPUT_MASK) | master_rate;
-       snd_soc_write(codec, AD193X_PLL_CLK_CTRL0, reg);
+       snd_soc_update_bits(codec, AD193X_PLL_CLK_CTRL0,
+                           AD193X_PLL_INPUT_MASK, master_rate);
 
-       reg = snd_soc_read(codec, AD193X_DAC_CTRL2);
-       reg = (reg & (~AD193X_DAC_WORD_LEN_MASK))
-               | (word_len << AD193X_DAC_WORD_LEN_SHFT);
-       snd_soc_write(codec, AD193X_DAC_CTRL2, reg);
+       snd_soc_update_bits(codec, AD193X_DAC_CTRL2,
+                           AD193X_DAC_WORD_LEN_MASK,
+                           word_len << AD193X_DAC_WORD_LEN_SHFT);
 
-       reg = snd_soc_read(codec, AD193X_ADC_CTRL1);
-       reg = (reg & (~AD193X_ADC_WORD_LEN_MASK)) | word_len;
-       snd_soc_write(codec, AD193X_ADC_CTRL1, reg);
+       snd_soc_update_bits(codec, AD193X_ADC_CTRL1,
+                           AD193X_ADC_WORD_LEN_MASK, word_len);
 
        return 0;
 }
@@ -349,10 +348,8 @@ static int ad193x_probe(struct snd_soc_codec *codec)
        struct snd_soc_dapm_context *dapm = &codec->dapm;
        int ret;
 
-       if (ad193x->control_type == SND_SOC_I2C)
-               ret = snd_soc_codec_set_cache_io(codec, 8, 8, ad193x->control_type);
-       else
-               ret = snd_soc_codec_set_cache_io(codec, 16, 8, ad193x->control_type);
+       codec->control_data = ad193x->regmap;
+       ret = snd_soc_codec_set_cache_io(codec, 0, 0, SND_SOC_REGMAP);
        if (ret < 0) {
                dev_err(codec->dev, "failed to set cache I/O: %d\n", ret);
                return ret;
@@ -388,6 +385,14 @@ static struct snd_soc_codec_driver soc_codec_dev_ad193x = {
 };
 
 #if defined(CONFIG_SPI_MASTER)
+
+static const struct regmap_config ad193x_spi_regmap_config = {
+       .val_bits = 8,
+       .reg_bits = 16,
+       .read_flag_mask = 0x09,
+       .write_flag_mask = 0x08,
+};
+
 static int __devinit ad193x_spi_probe(struct spi_device *spi)
 {
        struct ad193x_priv *ad193x;
@@ -397,20 +402,36 @@ static int __devinit ad193x_spi_probe(struct spi_device *spi)
        if (ad193x == NULL)
                return -ENOMEM;
 
+       ad193x->regmap = regmap_init_spi(spi, &ad193x_spi_regmap_config);
+       if (IS_ERR(ad193x->regmap)) {
+               ret = PTR_ERR(ad193x->regmap);
+               goto err_free;
+       }
+
        spi_set_drvdata(spi, ad193x);
-       ad193x->control_type = SND_SOC_SPI;
 
        ret = snd_soc_register_codec(&spi->dev,
                        &soc_codec_dev_ad193x, &ad193x_dai, 1);
        if (ret < 0)
-               kfree(ad193x);
+               goto err_regmap_exit;
+
+       return 0;
+
+err_regmap_exit:
+       regmap_exit(ad193x->regmap);
+err_free:
+       kfree(ad193x);
+
        return ret;
 }
 
 static int __devexit ad193x_spi_remove(struct spi_device *spi)
 {
+       struct ad193x_priv *ad193x = spi_get_drvdata(spi);
+
        snd_soc_unregister_codec(&spi->dev);
-       kfree(spi_get_drvdata(spi));
+       regmap_exit(ad193x->regmap);
+       kfree(ad193x);
        return 0;
 }
 
@@ -425,6 +446,12 @@ static struct spi_driver ad193x_spi_driver = {
 #endif
 
 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
+
+static const struct regmap_config ad193x_i2c_regmap_config = {
+       .val_bits = 8,
+       .reg_bits = 8,
+};
+
 static const struct i2c_device_id ad193x_id[] = {
        { "ad1936", 0 },
        { "ad1937", 0 },
@@ -442,20 +469,35 @@ static int __devinit ad193x_i2c_probe(struct i2c_client *client,
        if (ad193x == NULL)
                return -ENOMEM;
 
+       ad193x->regmap = regmap_init_i2c(client, &ad193x_i2c_regmap_config);
+       if (IS_ERR(ad193x->regmap)) {
+               ret = PTR_ERR(ad193x->regmap);
+               goto err_free;
+       }
+
        i2c_set_clientdata(client, ad193x);
-       ad193x->control_type = SND_SOC_I2C;
 
        ret =  snd_soc_register_codec(&client->dev,
                        &soc_codec_dev_ad193x, &ad193x_dai, 1);
        if (ret < 0)
-               kfree(ad193x);
+               goto err_regmap_exit;
+
+       return 0;
+
+err_regmap_exit:
+       regmap_exit(ad193x->regmap);
+err_free:
+       kfree(ad193x);
        return ret;
 }
 
 static int __devexit ad193x_i2c_remove(struct i2c_client *client)
 {
+       struct ad193x_priv *ad193x = i2c_get_clientdata(client);
+
        snd_soc_unregister_codec(&client->dev);
-       kfree(i2c_get_clientdata(client));
+       regmap_exit(ad193x->regmap);
+       kfree(ad193x);
        return 0;
 }
 
index cccc2e8e5fbd3e830a3a402ed565a2c981ad7f2b..1507eaa425a3a06d8114e6c42ca3d7e175c17b51 100644 (file)
@@ -9,20 +9,20 @@
 #ifndef __AD193X_H__
 #define __AD193X_H__
 
-#define AD193X_PLL_CLK_CTRL0    0x800
+#define AD193X_PLL_CLK_CTRL0    0x00
 #define AD193X_PLL_POWERDOWN           0x01
-#define AD193X_PLL_INPUT_MASK   (~0x6)
+#define AD193X_PLL_INPUT_MASK   0x6
 #define AD193X_PLL_INPUT_256    (0 << 1)
 #define AD193X_PLL_INPUT_384    (1 << 1)
 #define AD193X_PLL_INPUT_512    (2 << 1)
 #define AD193X_PLL_INPUT_768    (3 << 1)
-#define AD193X_PLL_CLK_CTRL1    0x801
-#define AD193X_DAC_CTRL0        0x802
+#define AD193X_PLL_CLK_CTRL1    0x01
+#define AD193X_DAC_CTRL0        0x02
 #define AD193X_DAC_POWERDOWN           0x01
 #define AD193X_DAC_SERFMT_MASK         0xC0
 #define AD193X_DAC_SERFMT_STEREO       (0 << 6)
 #define AD193X_DAC_SERFMT_TDM          (1 << 6)
-#define AD193X_DAC_CTRL1        0x803
+#define AD193X_DAC_CTRL1        0x03
 #define AD193X_DAC_2_CHANNELS   0
 #define AD193X_DAC_4_CHANNELS   1
 #define AD193X_DAC_8_CHANNELS   2
 #define AD193X_DAC_BCLK_MASTER  (1 << 5)
 #define AD193X_DAC_LEFT_HIGH    (1 << 3)
 #define AD193X_DAC_BCLK_INV     (1 << 7)
-#define AD193X_DAC_CTRL2        0x804
+#define AD193X_DAC_CTRL2        0x04
 #define AD193X_DAC_WORD_LEN_SHFT        3
 #define AD193X_DAC_WORD_LEN_MASK        0x18
 #define AD193X_DAC_MASTER_MUTE  1
-#define AD193X_DAC_CHNL_MUTE    0x805
+#define AD193X_DAC_CHNL_MUTE    0x05
 #define AD193X_DACL1_MUTE       0
 #define AD193X_DACR1_MUTE       1
 #define AD193X_DACL2_MUTE       2
 #define AD193X_DACR3_MUTE       5
 #define AD193X_DACL4_MUTE       6
 #define AD193X_DACR4_MUTE       7
-#define AD193X_DAC_L1_VOL       0x806
-#define AD193X_DAC_R1_VOL       0x807
-#define AD193X_DAC_L2_VOL       0x808
-#define AD193X_DAC_R2_VOL       0x809
-#define AD193X_DAC_L3_VOL       0x80a
-#define AD193X_DAC_R3_VOL       0x80b
-#define AD193X_DAC_L4_VOL       0x80c
-#define AD193X_DAC_R4_VOL       0x80d
-#define AD193X_ADC_CTRL0        0x80e
+#define AD193X_DAC_L1_VOL       0x06
+#define AD193X_DAC_R1_VOL       0x07
+#define AD193X_DAC_L2_VOL       0x08
+#define AD193X_DAC_R2_VOL       0x09
+#define AD193X_DAC_L3_VOL       0x0a
+#define AD193X_DAC_R3_VOL       0x0b
+#define AD193X_DAC_L4_VOL       0x0c
+#define AD193X_DAC_R4_VOL       0x0d
+#define AD193X_ADC_CTRL0        0x0e
 #define AD193X_ADC_POWERDOWN           0x01
 #define AD193X_ADC_HIGHPASS_FILTER     1
 #define AD193X_ADCL1_MUTE              2
 #define AD193X_ADCR1_MUTE              3
 #define AD193X_ADCL2_MUTE              4
 #define AD193X_ADCR2_MUTE              5
-#define AD193X_ADC_CTRL1        0x80f
+#define AD193X_ADC_CTRL1        0x0f
 #define AD193X_ADC_SERFMT_MASK         0x60
 #define AD193X_ADC_SERFMT_STEREO       (0 << 5)
 #define AD193X_ADC_SERFMT_TDM          (1 << 5)
 #define AD193X_ADC_SERFMT_AUX          (2 << 5)
 #define AD193X_ADC_WORD_LEN_MASK       0x3
-#define AD193X_ADC_CTRL2        0x810
+#define AD193X_ADC_CTRL2        0x10
 #define AD193X_ADC_2_CHANNELS   0
 #define AD193X_ADC_4_CHANNELS   1
 #define AD193X_ADC_8_CHANNELS   2
index 923b364a3e41926e88c99025c11326ab49236773..e3931cc5e66c6736d75fa053e7755acfda7a8b8e 100644 (file)
@@ -148,7 +148,6 @@ static struct snd_soc_dai_driver ad1980_dai = {
                .rates = SNDRV_PCM_RATE_48000,
                .formats = SND_SOC_STD_AC97_FMTS, },
 };
-EXPORT_SYMBOL_GPL(ad1980_dai);
 
 static int ad1980_reset(struct snd_soc_codec *codec, int try_warm)
 {
@@ -200,18 +199,22 @@ static int ad1980_soc_probe(struct snd_soc_codec *codec)
        }
 
        /* Read out vendor ID to make sure it is ad1980 */
-       if (ac97_read(codec, AC97_VENDOR_ID1) != 0x4144)
+       if (ac97_read(codec, AC97_VENDOR_ID1) != 0x4144) {
+               ret = -ENODEV;
                goto reset_err;
+       }
 
        vendor_id2 = ac97_read(codec, AC97_VENDOR_ID2);
 
        if (vendor_id2 != 0x5370) {
-               if (vendor_id2 != 0x5374)
+               if (vendor_id2 != 0x5374) {
+                       ret = -ENODEV;
                        goto reset_err;
-               else
+               } else {
                        printk(KERN_WARNING "ad1980: "
                                "Found AD1981 - only 2/2 IN/OUT Channels "
                                "supported\n");
+               }
        }
 
        /* unmute captures and playbacks volume */
diff --git a/sound/soc/codecs/adau1373.c b/sound/soc/codecs/adau1373.c
new file mode 100644 (file)
index 0000000..1ccf8dd
--- /dev/null
@@ -0,0 +1,1414 @@
+/*
+ * Analog Devices ADAU1373 Audio Codec drive
+ *
+ * Copyright 2011 Analog Devices Inc.
+ * Author: Lars-Peter Clausen <lars@metafoo.de>
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/pm.h>
+#include <linux/i2c.h>
+#include <linux/slab.h>
+#include <linux/gcd.h>
+
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/tlv.h>
+#include <sound/soc.h>
+#include <sound/adau1373.h>
+
+#include "adau1373.h"
+
+struct adau1373_dai {
+       unsigned int clk_src;
+       unsigned int sysclk;
+       bool enable_src;
+       bool master;
+};
+
+struct adau1373 {
+       struct adau1373_dai dais[3];
+};
+
+#define ADAU1373_INPUT_MODE    0x00
+#define ADAU1373_AINL_CTRL(x)  (0x01 + (x) * 2)
+#define ADAU1373_AINR_CTRL(x)  (0x02 + (x) * 2)
+#define ADAU1373_LLINE_OUT(x)  (0x9 + (x) * 2)
+#define ADAU1373_RLINE_OUT(x)  (0xa + (x) * 2)
+#define ADAU1373_LSPK_OUT      0x0d
+#define ADAU1373_RSPK_OUT      0x0e
+#define ADAU1373_LHP_OUT       0x0f
+#define ADAU1373_RHP_OUT       0x10
+#define ADAU1373_ADC_GAIN      0x11
+#define ADAU1373_LADC_MIXER    0x12
+#define ADAU1373_RADC_MIXER    0x13
+#define ADAU1373_LLINE1_MIX    0x14
+#define ADAU1373_RLINE1_MIX    0x15
+#define ADAU1373_LLINE2_MIX    0x16
+#define ADAU1373_RLINE2_MIX    0x17
+#define ADAU1373_LSPK_MIX      0x18
+#define ADAU1373_RSPK_MIX      0x19
+#define ADAU1373_LHP_MIX       0x1a
+#define ADAU1373_RHP_MIX       0x1b
+#define ADAU1373_EP_MIX                0x1c
+#define ADAU1373_HP_CTRL       0x1d
+#define ADAU1373_HP_CTRL2      0x1e
+#define ADAU1373_LS_CTRL       0x1f
+#define ADAU1373_EP_CTRL       0x21
+#define ADAU1373_MICBIAS_CTRL1 0x22
+#define ADAU1373_MICBIAS_CTRL2 0x23
+#define ADAU1373_OUTPUT_CTRL   0x24
+#define ADAU1373_PWDN_CTRL1    0x25
+#define ADAU1373_PWDN_CTRL2    0x26
+#define ADAU1373_PWDN_CTRL3    0x27
+#define ADAU1373_DPLL_CTRL(x)  (0x28 + (x) * 7)
+#define ADAU1373_PLL_CTRL1(x)  (0x29 + (x) * 7)
+#define ADAU1373_PLL_CTRL2(x)  (0x2a + (x) * 7)
+#define ADAU1373_PLL_CTRL3(x)  (0x2b + (x) * 7)
+#define ADAU1373_PLL_CTRL4(x)  (0x2c + (x) * 7)
+#define ADAU1373_PLL_CTRL5(x)  (0x2d + (x) * 7)
+#define ADAU1373_PLL_CTRL6(x)  (0x2e + (x) * 7)
+#define ADAU1373_PLL_CTRL7(x)  (0x2f + (x) * 7)
+#define ADAU1373_HEADDECT      0x36
+#define ADAU1373_ADC_DAC_STATUS        0x37
+#define ADAU1373_ADC_CTRL      0x3c
+#define ADAU1373_DAI(x)                (0x44 + (x))
+#define ADAU1373_CLK_SRC_DIV(x)        (0x40 + (x) * 2)
+#define ADAU1373_BCLKDIV(x)    (0x47 + (x))
+#define ADAU1373_SRC_RATIOA(x) (0x4a + (x) * 2)
+#define ADAU1373_SRC_RATIOB(x) (0x4b + (x) * 2)
+#define ADAU1373_DEEMP_CTRL    0x50
+#define ADAU1373_SRC_DAI_CTRL(x) (0x51 + (x))
+#define ADAU1373_DIN_MIX_CTRL(x) (0x56 + (x))
+#define ADAU1373_DOUT_MIX_CTRL(x) (0x5b + (x))
+#define ADAU1373_DAI_PBL_VOL(x)        (0x62 + (x) * 2)
+#define ADAU1373_DAI_PBR_VOL(x)        (0x63 + (x) * 2)
+#define ADAU1373_DAI_RECL_VOL(x) (0x68 + (x) * 2)
+#define ADAU1373_DAI_RECR_VOL(x) (0x69 + (x) * 2)
+#define ADAU1373_DAC1_PBL_VOL  0x6e
+#define ADAU1373_DAC1_PBR_VOL  0x6f
+#define ADAU1373_DAC2_PBL_VOL  0x70
+#define ADAU1373_DAC2_PBR_VOL  0x71
+#define ADAU1373_ADC_RECL_VOL  0x72
+#define ADAU1373_ADC_RECR_VOL  0x73
+#define ADAU1373_DMIC_RECL_VOL 0x74
+#define ADAU1373_DMIC_RECR_VOL 0x75
+#define ADAU1373_VOL_GAIN1     0x76
+#define ADAU1373_VOL_GAIN2     0x77
+#define ADAU1373_VOL_GAIN3     0x78
+#define ADAU1373_HPF_CTRL      0x7d
+#define ADAU1373_BASS1         0x7e
+#define ADAU1373_BASS2         0x7f
+#define ADAU1373_DRC(x)                (0x80 + (x) * 0x10)
+#define ADAU1373_3D_CTRL1      0xc0
+#define ADAU1373_3D_CTRL2      0xc1
+#define ADAU1373_FDSP_SEL1     0xdc
+#define ADAU1373_FDSP_SEL2     0xdd
+#define ADAU1373_FDSP_SEL3     0xde
+#define ADAU1373_FDSP_SEL4     0xdf
+#define ADAU1373_DIGMICCTRL    0xe2
+#define ADAU1373_DIGEN         0xeb
+#define ADAU1373_SOFT_RESET    0xff
+
+
+#define ADAU1373_PLL_CTRL6_DPLL_BYPASS BIT(1)
+#define ADAU1373_PLL_CTRL6_PLL_EN      BIT(0)
+
+#define ADAU1373_DAI_INVERT_BCLK       BIT(7)
+#define ADAU1373_DAI_MASTER            BIT(6)
+#define ADAU1373_DAI_INVERT_LRCLK      BIT(4)
+#define ADAU1373_DAI_WLEN_16           0x0
+#define ADAU1373_DAI_WLEN_20           0x4
+#define ADAU1373_DAI_WLEN_24           0x8
+#define ADAU1373_DAI_WLEN_32           0xc
+#define ADAU1373_DAI_WLEN_MASK         0xc
+#define ADAU1373_DAI_FORMAT_RIGHT_J    0x0
+#define ADAU1373_DAI_FORMAT_LEFT_J     0x1
+#define ADAU1373_DAI_FORMAT_I2S                0x2
+#define ADAU1373_DAI_FORMAT_DSP                0x3
+
+#define ADAU1373_BCLKDIV_SOURCE                BIT(5)
+#define ADAU1373_BCLKDIV_32            0x03
+#define ADAU1373_BCLKDIV_64            0x02
+#define ADAU1373_BCLKDIV_128           0x01
+#define ADAU1373_BCLKDIV_256           0x00
+
+#define ADAU1373_ADC_CTRL_PEAK_DETECT  BIT(0)
+#define ADAU1373_ADC_CTRL_RESET                BIT(1)
+#define ADAU1373_ADC_CTRL_RESET_FORCE  BIT(2)
+
+#define ADAU1373_OUTPUT_CTRL_LDIFF     BIT(3)
+#define ADAU1373_OUTPUT_CTRL_LNFBEN    BIT(2)
+
+#define ADAU1373_PWDN_CTRL3_PWR_EN BIT(0)
+
+#define ADAU1373_EP_CTRL_MICBIAS1_OFFSET 4
+#define ADAU1373_EP_CTRL_MICBIAS2_OFFSET 2
+
+static const uint8_t adau1373_default_regs[] = {
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00 */
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10 */
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20 */
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, /* 0x30 */
+       0x00, 0x00, 0x00, 0x80, 0x00, 0x01, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00, 0x0a, 0x0a, 0x0a, 0x00, /* 0x40 */
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+       0x00, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, /* 0x50 */
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60 */
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70 */
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+       0x78, 0x18, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, /* 0x80 */
+       0x00, 0xc0, 0x88, 0x7a, 0xdf, 0x20, 0x00, 0x00,
+       0x78, 0x18, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, /* 0x90 */
+       0x00, 0xc0, 0x88, 0x7a, 0xdf, 0x20, 0x00, 0x00,
+       0x78, 0x18, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, /* 0xa0 */
+       0x00, 0xc0, 0x88, 0x7a, 0xdf, 0x20, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb0 */
+       0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0 */
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0 */
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, /* 0xe0 */
+       0x00, 0x1f, 0x0f, 0x00, 0x00,
+};
+
+static const unsigned int adau1373_out_tlv[] = {
+       TLV_DB_RANGE_HEAD(4),
+       0, 7, TLV_DB_SCALE_ITEM(-7900, 400, 1),
+       8, 15, TLV_DB_SCALE_ITEM(-4700, 300, 0),
+       16, 23, TLV_DB_SCALE_ITEM(-2300, 200, 0),
+       24, 31, TLV_DB_SCALE_ITEM(-700, 100, 0),
+};
+
+static const DECLARE_TLV_DB_MINMAX(adau1373_digital_tlv, -9563, 0);
+static const DECLARE_TLV_DB_SCALE(adau1373_in_pga_tlv, -1300, 100, 1);
+static const DECLARE_TLV_DB_SCALE(adau1373_ep_tlv, -600, 600, 1);
+
+static const DECLARE_TLV_DB_SCALE(adau1373_input_boost_tlv, 0, 2000, 0);
+static const DECLARE_TLV_DB_SCALE(adau1373_gain_boost_tlv, 0, 600, 0);
+static const DECLARE_TLV_DB_SCALE(adau1373_speaker_boost_tlv, 1200, 600, 0);
+
+static const char *adau1373_fdsp_sel_text[] = {
+       "None",
+       "Channel 1",
+       "Channel 2",
+       "Channel 3",
+       "Channel 4",
+       "Channel 5",
+};
+
+static const SOC_ENUM_SINGLE_DECL(adau1373_drc1_channel_enum,
+       ADAU1373_FDSP_SEL1, 4, adau1373_fdsp_sel_text);
+static const SOC_ENUM_SINGLE_DECL(adau1373_drc2_channel_enum,
+       ADAU1373_FDSP_SEL1, 0, adau1373_fdsp_sel_text);
+static const SOC_ENUM_SINGLE_DECL(adau1373_drc3_channel_enum,
+       ADAU1373_FDSP_SEL2, 0, adau1373_fdsp_sel_text);
+static const SOC_ENUM_SINGLE_DECL(adau1373_hpf_channel_enum,
+       ADAU1373_FDSP_SEL3, 0, adau1373_fdsp_sel_text);
+static const SOC_ENUM_SINGLE_DECL(adau1373_bass_channel_enum,
+       ADAU1373_FDSP_SEL4, 4, adau1373_fdsp_sel_text);
+
+static const char *adau1373_hpf_cutoff_text[] = {
+       "3.7Hz", "50Hz", "100Hz", "150Hz", "200Hz", "250Hz", "300Hz", "350Hz",
+       "400Hz", "450Hz", "500Hz", "550Hz", "600Hz", "650Hz", "700Hz", "750Hz",
+       "800Hz",
+};
+
+static const SOC_ENUM_SINGLE_DECL(adau1373_hpf_cutoff_enum,
+       ADAU1373_HPF_CTRL, 3, adau1373_hpf_cutoff_text);
+
+static const char *adau1373_bass_lpf_cutoff_text[] = {
+       "801Hz", "1001Hz",
+};
+
+static const char *adau1373_bass_clip_level_text[] = {
+       "0.125", "0.250", "0.370", "0.500", "0.625", "0.750", "0.875",
+};
+
+static const unsigned int adau1373_bass_clip_level_values[] = {
+       1, 2, 3, 4, 5, 6, 7,
+};
+
+static const char *adau1373_bass_hpf_cutoff_text[] = {
+       "158Hz", "232Hz", "347Hz", "520Hz",
+};
+
+static const unsigned int adau1373_bass_tlv[] = {
+       TLV_DB_RANGE_HEAD(4),
+       0, 2, TLV_DB_SCALE_ITEM(-600, 600, 1),
+       3, 4, TLV_DB_SCALE_ITEM(950, 250, 0),
+       5, 7, TLV_DB_SCALE_ITEM(1400, 150, 0),
+};
+
+static const SOC_ENUM_SINGLE_DECL(adau1373_bass_lpf_cutoff_enum,
+       ADAU1373_BASS1, 5, adau1373_bass_lpf_cutoff_text);
+
+static const SOC_VALUE_ENUM_SINGLE_DECL(adau1373_bass_clip_level_enum,
+       ADAU1373_BASS1, 2, 7, adau1373_bass_clip_level_text,
+       adau1373_bass_clip_level_values);
+
+static const SOC_ENUM_SINGLE_DECL(adau1373_bass_hpf_cutoff_enum,
+       ADAU1373_BASS1, 0, adau1373_bass_hpf_cutoff_text);
+
+static const char *adau1373_3d_level_text[] = {
+       "0%", "6.67%", "13.33%", "20%", "26.67%", "33.33%",
+       "40%", "46.67%", "53.33%", "60%", "66.67%", "73.33%",
+       "80%", "86.67", "99.33%", "100%"
+};
+
+static const char *adau1373_3d_cutoff_text[] = {
+       "No 3D", "0.03125 fs", "0.04583 fs", "0.075 fs", "0.11458 fs",
+       "0.16875 fs", "0.27083 fs"
+};
+
+static const SOC_ENUM_SINGLE_DECL(adau1373_3d_level_enum,
+       ADAU1373_3D_CTRL1, 4, adau1373_3d_level_text);
+static const SOC_ENUM_SINGLE_DECL(adau1373_3d_cutoff_enum,
+       ADAU1373_3D_CTRL1, 0, adau1373_3d_cutoff_text);
+
+static const unsigned int adau1373_3d_tlv[] = {
+       TLV_DB_RANGE_HEAD(2),
+       0, 0, TLV_DB_SCALE_ITEM(0, 0, 0),
+       1, 7, TLV_DB_LINEAR_ITEM(-1800, -120),
+};
+
+static const char *adau1373_lr_mux_text[] = {
+       "Mute",
+       "Right Channel (L+R)",
+       "Left Channel (L+R)",
+       "Stereo",
+};
+
+static const SOC_ENUM_SINGLE_DECL(adau1373_lineout1_lr_mux_enum,
+       ADAU1373_OUTPUT_CTRL, 4, adau1373_lr_mux_text);
+static const SOC_ENUM_SINGLE_DECL(adau1373_lineout2_lr_mux_enum,
+       ADAU1373_OUTPUT_CTRL, 6, adau1373_lr_mux_text);
+static const SOC_ENUM_SINGLE_DECL(adau1373_speaker_lr_mux_enum,
+       ADAU1373_LS_CTRL, 4, adau1373_lr_mux_text);
+
+static const struct snd_kcontrol_new adau1373_controls[] = {
+       SOC_DOUBLE_R_TLV("AIF1 Capture Volume", ADAU1373_DAI_RECL_VOL(0),
+               ADAU1373_DAI_RECR_VOL(0), 0, 0xff, 1, adau1373_digital_tlv),
+       SOC_DOUBLE_R_TLV("AIF2 Capture Volume", ADAU1373_DAI_RECL_VOL(1),
+               ADAU1373_DAI_RECR_VOL(1), 0, 0xff, 1, adau1373_digital_tlv),
+       SOC_DOUBLE_R_TLV("AIF3 Capture Volume", ADAU1373_DAI_RECL_VOL(2),
+               ADAU1373_DAI_RECR_VOL(2), 0, 0xff, 1, adau1373_digital_tlv),
+
+       SOC_DOUBLE_R_TLV("ADC Capture Volume", ADAU1373_ADC_RECL_VOL,
+               ADAU1373_ADC_RECR_VOL, 0, 0xff, 1, adau1373_digital_tlv),
+       SOC_DOUBLE_R_TLV("DMIC Capture Volume", ADAU1373_DMIC_RECL_VOL,
+               ADAU1373_DMIC_RECR_VOL, 0, 0xff, 1, adau1373_digital_tlv),
+
+       SOC_DOUBLE_R_TLV("AIF1 Playback Volume", ADAU1373_DAI_PBL_VOL(0),
+               ADAU1373_DAI_PBR_VOL(0), 0, 0xff, 1, adau1373_digital_tlv),
+       SOC_DOUBLE_R_TLV("AIF2 Playback Volume", ADAU1373_DAI_PBL_VOL(1),
+               ADAU1373_DAI_PBR_VOL(1), 0, 0xff, 1, adau1373_digital_tlv),
+       SOC_DOUBLE_R_TLV("AIF3 Playback Volume", ADAU1373_DAI_PBL_VOL(2),
+               ADAU1373_DAI_PBR_VOL(2), 0, 0xff, 1, adau1373_digital_tlv),
+
+       SOC_DOUBLE_R_TLV("DAC1 Playback Volume", ADAU1373_DAC1_PBL_VOL,
+               ADAU1373_DAC1_PBR_VOL, 0, 0xff, 1, adau1373_digital_tlv),
+       SOC_DOUBLE_R_TLV("DAC2 Playback Volume", ADAU1373_DAC2_PBL_VOL,
+               ADAU1373_DAC2_PBR_VOL, 0, 0xff, 1, adau1373_digital_tlv),
+
+       SOC_DOUBLE_R_TLV("Lineout1 Playback Volume", ADAU1373_LLINE_OUT(0),
+               ADAU1373_RLINE_OUT(0), 0, 0x1f, 0, adau1373_out_tlv),
+       SOC_DOUBLE_R_TLV("Speaker Playback Volume", ADAU1373_LSPK_OUT,
+               ADAU1373_RSPK_OUT, 0, 0x1f, 0, adau1373_out_tlv),
+       SOC_DOUBLE_R_TLV("Headphone Playback Volume", ADAU1373_LHP_OUT,
+               ADAU1373_RHP_OUT, 0, 0x1f, 0, adau1373_out_tlv),
+
+       SOC_DOUBLE_R_TLV("Input 1 Capture Volume", ADAU1373_AINL_CTRL(0),
+               ADAU1373_AINR_CTRL(0), 0, 0x1f, 0, adau1373_in_pga_tlv),
+       SOC_DOUBLE_R_TLV("Input 2 Capture Volume", ADAU1373_AINL_CTRL(1),
+               ADAU1373_AINR_CTRL(1), 0, 0x1f, 0, adau1373_in_pga_tlv),
+       SOC_DOUBLE_R_TLV("Input 3 Capture Volume", ADAU1373_AINL_CTRL(2),
+               ADAU1373_AINR_CTRL(2), 0, 0x1f, 0, adau1373_in_pga_tlv),
+       SOC_DOUBLE_R_TLV("Input 4 Capture Volume", ADAU1373_AINL_CTRL(3),
+               ADAU1373_AINR_CTRL(3), 0, 0x1f, 0, adau1373_in_pga_tlv),
+
+       SOC_SINGLE_TLV("Earpiece Playback Volume", ADAU1373_EP_CTRL, 0, 3, 0,
+               adau1373_ep_tlv),
+
+       SOC_DOUBLE_TLV("AIF3 Boost Playback Volume", ADAU1373_VOL_GAIN1, 4, 5,
+               1, 0, adau1373_gain_boost_tlv),
+       SOC_DOUBLE_TLV("AIF2 Boost Playback Volume", ADAU1373_VOL_GAIN1, 2, 3,
+               1, 0, adau1373_gain_boost_tlv),
+       SOC_DOUBLE_TLV("AIF1 Boost Playback Volume", ADAU1373_VOL_GAIN1, 0, 1,
+               1, 0, adau1373_gain_boost_tlv),
+       SOC_DOUBLE_TLV("AIF3 Boost Capture Volume", ADAU1373_VOL_GAIN2, 4, 5,
+               1, 0, adau1373_gain_boost_tlv),
+       SOC_DOUBLE_TLV("AIF2 Boost Capture Volume", ADAU1373_VOL_GAIN2, 2, 3,
+               1, 0, adau1373_gain_boost_tlv),
+       SOC_DOUBLE_TLV("AIF1 Boost Capture Volume", ADAU1373_VOL_GAIN2, 0, 1,
+               1, 0, adau1373_gain_boost_tlv),
+       SOC_DOUBLE_TLV("DMIC Boost Capture Volume", ADAU1373_VOL_GAIN3, 6, 7,
+               1, 0, adau1373_gain_boost_tlv),
+       SOC_DOUBLE_TLV("ADC Boost Capture Volume", ADAU1373_VOL_GAIN3, 4, 5,
+               1, 0, adau1373_gain_boost_tlv),
+       SOC_DOUBLE_TLV("DAC2 Boost Playback Volume", ADAU1373_VOL_GAIN3, 2, 3,
+               1, 0, adau1373_gain_boost_tlv),
+       SOC_DOUBLE_TLV("DAC1 Boost Playback Volume", ADAU1373_VOL_GAIN3, 0, 1,
+               1, 0, adau1373_gain_boost_tlv),
+
+       SOC_DOUBLE_TLV("Input 1 Boost Capture Volume", ADAU1373_ADC_GAIN, 0, 4,
+               1, 0, adau1373_input_boost_tlv),
+       SOC_DOUBLE_TLV("Input 2 Boost Capture Volume", ADAU1373_ADC_GAIN, 1, 5,
+               1, 0, adau1373_input_boost_tlv),
+       SOC_DOUBLE_TLV("Input 3 Boost Capture Volume", ADAU1373_ADC_GAIN, 2, 6,
+               1, 0, adau1373_input_boost_tlv),
+       SOC_DOUBLE_TLV("Input 4 Boost Capture Volume", ADAU1373_ADC_GAIN, 3, 7,
+               1, 0, adau1373_input_boost_tlv),
+
+       SOC_DOUBLE_TLV("Speaker Boost Playback Volume", ADAU1373_LS_CTRL, 2, 3,
+               1, 0, adau1373_speaker_boost_tlv),
+
+       SOC_ENUM("Lineout1 LR Mux", adau1373_lineout1_lr_mux_enum),
+       SOC_ENUM("Speaker LR Mux", adau1373_speaker_lr_mux_enum),
+
+       SOC_ENUM("HPF Cutoff", adau1373_hpf_cutoff_enum),
+       SOC_DOUBLE("HPF Switch", ADAU1373_HPF_CTRL, 1, 0, 1, 0),
+       SOC_ENUM("HPF Channel", adau1373_hpf_channel_enum),
+
+       SOC_ENUM("Bass HPF Cutoff", adau1373_bass_hpf_cutoff_enum),
+       SOC_VALUE_ENUM("Bass Clip Level Threshold",
+           adau1373_bass_clip_level_enum),
+       SOC_ENUM("Bass LPF Cutoff", adau1373_bass_lpf_cutoff_enum),
+       SOC_DOUBLE("Bass Playback Switch", ADAU1373_BASS2, 0, 1, 1, 0),
+       SOC_SINGLE_TLV("Bass Playback Volume", ADAU1373_BASS2, 2, 7, 0,
+           adau1373_bass_tlv),
+       SOC_ENUM("Bass Channel", adau1373_bass_channel_enum),
+
+       SOC_ENUM("3D Freq", adau1373_3d_cutoff_enum),
+       SOC_ENUM("3D Level", adau1373_3d_level_enum),
+       SOC_SINGLE("3D Playback Switch", ADAU1373_3D_CTRL2, 0, 1, 0),
+       SOC_SINGLE_TLV("3D Playback Volume", ADAU1373_3D_CTRL2, 2, 7, 0,
+               adau1373_3d_tlv),
+       SOC_ENUM("3D Channel", adau1373_bass_channel_enum),
+
+       SOC_SINGLE("Zero Cross Switch", ADAU1373_PWDN_CTRL3, 7, 1, 0),
+};
+
+static const struct snd_kcontrol_new adau1373_lineout2_controls[] = {
+       SOC_DOUBLE_R_TLV("Lineout2 Playback Volume", ADAU1373_LLINE_OUT(1),
+               ADAU1373_RLINE_OUT(1), 0, 0x1f, 0, adau1373_out_tlv),
+       SOC_ENUM("Lineout2 LR Mux", adau1373_lineout2_lr_mux_enum),
+};
+
+static const struct snd_kcontrol_new adau1373_drc_controls[] = {
+       SOC_ENUM("DRC1 Channel", adau1373_drc1_channel_enum),
+       SOC_ENUM("DRC2 Channel", adau1373_drc2_channel_enum),
+       SOC_ENUM("DRC3 Channel", adau1373_drc3_channel_enum),
+};
+
+static int adau1373_pll_event(struct snd_soc_dapm_widget *w,
+       struct snd_kcontrol *kcontrol, int event)
+{
+       struct snd_soc_codec *codec = w->codec;
+       unsigned int pll_id = w->name[3] - '1';
+       unsigned int val;
+
+       if (SND_SOC_DAPM_EVENT_ON(event))
+               val = ADAU1373_PLL_CTRL6_PLL_EN;
+       else
+               val = 0;
+
+       snd_soc_update_bits(codec, ADAU1373_PLL_CTRL6(pll_id),
+               ADAU1373_PLL_CTRL6_PLL_EN, val);
+
+       if (SND_SOC_DAPM_EVENT_ON(event))
+               mdelay(5);
+
+       return 0;
+}
+
+static const char *adau1373_decimator_text[] = {
+       "ADC",
+       "DMIC1",
+};
+
+static const struct soc_enum adau1373_decimator_enum =
+       SOC_ENUM_SINGLE(0, 0, 2, adau1373_decimator_text);
+
+static const struct snd_kcontrol_new adau1373_decimator_mux =
+       SOC_DAPM_ENUM_VIRT("Decimator Mux", adau1373_decimator_enum);
+
+static const struct snd_kcontrol_new adau1373_left_adc_mixer_controls[] = {
+       SOC_DAPM_SINGLE("DAC1 Switch", ADAU1373_LADC_MIXER, 4, 1, 0),
+       SOC_DAPM_SINGLE("Input 4 Switch", ADAU1373_LADC_MIXER, 3, 1, 0),
+       SOC_DAPM_SINGLE("Input 3 Switch", ADAU1373_LADC_MIXER, 2, 1, 0),
+       SOC_DAPM_SINGLE("Input 2 Switch", ADAU1373_LADC_MIXER, 1, 1, 0),
+       SOC_DAPM_SINGLE("Input 1 Switch", ADAU1373_LADC_MIXER, 0, 1, 0),
+};
+
+static const struct snd_kcontrol_new adau1373_right_adc_mixer_controls[] = {
+       SOC_DAPM_SINGLE("DAC1 Switch", ADAU1373_RADC_MIXER, 4, 1, 0),
+       SOC_DAPM_SINGLE("Input 4 Switch", ADAU1373_RADC_MIXER, 3, 1, 0),
+       SOC_DAPM_SINGLE("Input 3 Switch", ADAU1373_RADC_MIXER, 2, 1, 0),
+       SOC_DAPM_SINGLE("Input 2 Switch", ADAU1373_RADC_MIXER, 1, 1, 0),
+       SOC_DAPM_SINGLE("Input 1 Switch", ADAU1373_RADC_MIXER, 0, 1, 0),
+};
+
+#define DECLARE_ADAU1373_OUTPUT_MIXER_CTRLS(_name, _reg) \
+const struct snd_kcontrol_new _name[] = { \
+       SOC_DAPM_SINGLE("Left DAC2 Switch", _reg, 7, 1, 0), \
+       SOC_DAPM_SINGLE("Right DAC2 Switch", _reg, 6, 1, 0), \
+       SOC_DAPM_SINGLE("Left DAC1 Switch", _reg, 5, 1, 0), \
+       SOC_DAPM_SINGLE("Right DAC1 Switch", _reg, 4, 1, 0), \
+       SOC_DAPM_SINGLE("Input 4 Bypass Switch", _reg, 3, 1, 0), \
+       SOC_DAPM_SINGLE("Input 3 Bypass Switch", _reg, 2, 1, 0), \
+       SOC_DAPM_SINGLE("Input 2 Bypass Switch", _reg, 1, 1, 0), \
+       SOC_DAPM_SINGLE("Input 1 Bypass Switch", _reg, 0, 1, 0), \
+}
+
+static DECLARE_ADAU1373_OUTPUT_MIXER_CTRLS(adau1373_left_line1_mixer_controls,
+       ADAU1373_LLINE1_MIX);
+static DECLARE_ADAU1373_OUTPUT_MIXER_CTRLS(adau1373_right_line1_mixer_controls,
+       ADAU1373_RLINE1_MIX);
+static DECLARE_ADAU1373_OUTPUT_MIXER_CTRLS(adau1373_left_line2_mixer_controls,
+       ADAU1373_LLINE2_MIX);
+static DECLARE_ADAU1373_OUTPUT_MIXER_CTRLS(adau1373_right_line2_mixer_controls,
+       ADAU1373_RLINE2_MIX);
+static DECLARE_ADAU1373_OUTPUT_MIXER_CTRLS(adau1373_left_spk_mixer_controls,
+       ADAU1373_LSPK_MIX);
+static DECLARE_ADAU1373_OUTPUT_MIXER_CTRLS(adau1373_right_spk_mixer_controls,
+       ADAU1373_RSPK_MIX);
+static DECLARE_ADAU1373_OUTPUT_MIXER_CTRLS(adau1373_ep_mixer_controls,
+       ADAU1373_EP_MIX);
+
+static const struct snd_kcontrol_new adau1373_left_hp_mixer_controls[] = {
+       SOC_DAPM_SINGLE("Left DAC1 Switch", ADAU1373_LHP_MIX, 5, 1, 0),
+       SOC_DAPM_SINGLE("Left DAC2 Switch", ADAU1373_LHP_MIX, 4, 1, 0),
+       SOC_DAPM_SINGLE("Input 4 Bypass Switch", ADAU1373_LHP_MIX, 3, 1, 0),
+       SOC_DAPM_SINGLE("Input 3 Bypass Switch", ADAU1373_LHP_MIX, 2, 1, 0),
+       SOC_DAPM_SINGLE("Input 2 Bypass Switch", ADAU1373_LHP_MIX, 1, 1, 0),
+       SOC_DAPM_SINGLE("Input 1 Bypass Switch", ADAU1373_LHP_MIX, 0, 1, 0),
+};
+
+static const struct snd_kcontrol_new adau1373_right_hp_mixer_controls[] = {
+       SOC_DAPM_SINGLE("Right DAC1 Switch", ADAU1373_RHP_MIX, 5, 1, 0),
+       SOC_DAPM_SINGLE("Right DAC2 Switch", ADAU1373_RHP_MIX, 4, 1, 0),
+       SOC_DAPM_SINGLE("Input 4 Bypass Switch", ADAU1373_RHP_MIX, 3, 1, 0),
+       SOC_DAPM_SINGLE("Input 3 Bypass Switch", ADAU1373_RHP_MIX, 2, 1, 0),
+       SOC_DAPM_SINGLE("Input 2 Bypass Switch", ADAU1373_RHP_MIX, 1, 1, 0),
+       SOC_DAPM_SINGLE("Input 1 Bypass Switch", ADAU1373_RHP_MIX, 0, 1, 0),
+};
+
+#define DECLARE_ADAU1373_DSP_CHANNEL_MIXER_CTRLS(_name, _reg) \
+const struct snd_kcontrol_new _name[] = { \
+       SOC_DAPM_SINGLE("DMIC2 Swapped Switch", _reg, 6, 1, 0), \
+       SOC_DAPM_SINGLE("DMIC2 Switch", _reg, 5, 1, 0), \
+       SOC_DAPM_SINGLE("ADC/DMIC1 Swapped Switch", _reg, 4, 1, 0), \
+       SOC_DAPM_SINGLE("ADC/DMIC1 Switch", _reg, 3, 1, 0), \
+       SOC_DAPM_SINGLE("AIF3 Switch", _reg, 2, 1, 0), \
+       SOC_DAPM_SINGLE("AIF2 Switch", _reg, 1, 1, 0), \
+       SOC_DAPM_SINGLE("AIF1 Switch", _reg, 0, 1, 0), \
+}
+
+static DECLARE_ADAU1373_DSP_CHANNEL_MIXER_CTRLS(adau1373_dsp_channel1_mixer_controls,
+       ADAU1373_DIN_MIX_CTRL(0));
+static DECLARE_ADAU1373_DSP_CHANNEL_MIXER_CTRLS(adau1373_dsp_channel2_mixer_controls,
+       ADAU1373_DIN_MIX_CTRL(1));
+static DECLARE_ADAU1373_DSP_CHANNEL_MIXER_CTRLS(adau1373_dsp_channel3_mixer_controls,
+       ADAU1373_DIN_MIX_CTRL(2));
+static DECLARE_ADAU1373_DSP_CHANNEL_MIXER_CTRLS(adau1373_dsp_channel4_mixer_controls,
+       ADAU1373_DIN_MIX_CTRL(3));
+static DECLARE_ADAU1373_DSP_CHANNEL_MIXER_CTRLS(adau1373_dsp_channel5_mixer_controls,
+       ADAU1373_DIN_MIX_CTRL(4));
+
+#define DECLARE_ADAU1373_DSP_OUTPUT_MIXER_CTRLS(_name, _reg) \
+const struct snd_kcontrol_new _name[] = { \
+       SOC_DAPM_SINGLE("DSP Channel5 Switch", _reg, 4, 1, 0), \
+       SOC_DAPM_SINGLE("DSP Channel4 Switch", _reg, 3, 1, 0), \
+       SOC_DAPM_SINGLE("DSP Channel3 Switch", _reg, 2, 1, 0), \
+       SOC_DAPM_SINGLE("DSP Channel2 Switch", _reg, 1, 1, 0), \
+       SOC_DAPM_SINGLE("DSP Channel1 Switch", _reg, 0, 1, 0), \
+}
+
+static DECLARE_ADAU1373_DSP_OUTPUT_MIXER_CTRLS(adau1373_aif1_mixer_controls,
+       ADAU1373_DOUT_MIX_CTRL(0));
+static DECLARE_ADAU1373_DSP_OUTPUT_MIXER_CTRLS(adau1373_aif2_mixer_controls,
+       ADAU1373_DOUT_MIX_CTRL(1));
+static DECLARE_ADAU1373_DSP_OUTPUT_MIXER_CTRLS(adau1373_aif3_mixer_controls,
+       ADAU1373_DOUT_MIX_CTRL(2));
+static DECLARE_ADAU1373_DSP_OUTPUT_MIXER_CTRLS(adau1373_dac1_mixer_controls,
+       ADAU1373_DOUT_MIX_CTRL(3));
+static DECLARE_ADAU1373_DSP_OUTPUT_MIXER_CTRLS(adau1373_dac2_mixer_controls,
+       ADAU1373_DOUT_MIX_CTRL(4));
+
+static const struct snd_soc_dapm_widget adau1373_dapm_widgets[] = {
+       /* Datasheet claims Left ADC is bit 6 and Right ADC is bit 7, but that
+        * doesn't seem to be the case. */
+       SND_SOC_DAPM_ADC("Left ADC", NULL, ADAU1373_PWDN_CTRL1, 7, 0),
+       SND_SOC_DAPM_ADC("Right ADC", NULL, ADAU1373_PWDN_CTRL1, 6, 0),
+
+       SND_SOC_DAPM_ADC("DMIC1", NULL, ADAU1373_DIGMICCTRL, 0, 0),
+       SND_SOC_DAPM_ADC("DMIC2", NULL, ADAU1373_DIGMICCTRL, 2, 0),
+
+       SND_SOC_DAPM_VIRT_MUX("Decimator Mux", SND_SOC_NOPM, 0, 0,
+               &adau1373_decimator_mux),
+
+       SND_SOC_DAPM_SUPPLY("MICBIAS2", ADAU1373_PWDN_CTRL1, 5, 0, NULL, 0),
+       SND_SOC_DAPM_SUPPLY("MICBIAS1", ADAU1373_PWDN_CTRL1, 4, 0, NULL, 0),
+
+       SND_SOC_DAPM_PGA("IN4PGA", ADAU1373_PWDN_CTRL1, 3, 0, NULL, 0),
+       SND_SOC_DAPM_PGA("IN3PGA", ADAU1373_PWDN_CTRL1, 2, 0, NULL, 0),
+       SND_SOC_DAPM_PGA("IN2PGA", ADAU1373_PWDN_CTRL1, 1, 0, NULL, 0),
+       SND_SOC_DAPM_PGA("IN1PGA", ADAU1373_PWDN_CTRL1, 0, 0, NULL, 0),
+
+       SND_SOC_DAPM_DAC("Left DAC2", NULL, ADAU1373_PWDN_CTRL2, 7, 0),
+       SND_SOC_DAPM_DAC("Right DAC2", NULL, ADAU1373_PWDN_CTRL2, 6, 0),
+       SND_SOC_DAPM_DAC("Left DAC1", NULL, ADAU1373_PWDN_CTRL2, 5, 0),
+       SND_SOC_DAPM_DAC("Right DAC1", NULL, ADAU1373_PWDN_CTRL2, 4, 0),
+
+       SOC_MIXER_ARRAY("Left ADC Mixer", SND_SOC_NOPM, 0, 0,
+               adau1373_left_adc_mixer_controls),
+       SOC_MIXER_ARRAY("Right ADC Mixer", SND_SOC_NOPM, 0, 0,
+               adau1373_right_adc_mixer_controls),
+
+       SOC_MIXER_ARRAY("Left Lineout2 Mixer", ADAU1373_PWDN_CTRL2, 3, 0,
+               adau1373_left_line2_mixer_controls),
+       SOC_MIXER_ARRAY("Right Lineout2 Mixer", ADAU1373_PWDN_CTRL2, 2, 0,
+               adau1373_right_line2_mixer_controls),
+       SOC_MIXER_ARRAY("Left Lineout1 Mixer", ADAU1373_PWDN_CTRL2, 1, 0,
+               adau1373_left_line1_mixer_controls),
+       SOC_MIXER_ARRAY("Right Lineout1 Mixer", ADAU1373_PWDN_CTRL2, 0, 0,
+               adau1373_right_line1_mixer_controls),
+
+       SOC_MIXER_ARRAY("Earpiece Mixer", ADAU1373_PWDN_CTRL3, 4, 0,
+               adau1373_ep_mixer_controls),
+       SOC_MIXER_ARRAY("Left Speaker Mixer", ADAU1373_PWDN_CTRL3, 3, 0,
+               adau1373_left_spk_mixer_controls),
+       SOC_MIXER_ARRAY("Right Speaker Mixer", ADAU1373_PWDN_CTRL3, 2, 0,
+               adau1373_right_spk_mixer_controls),
+       SOC_MIXER_ARRAY("Left Headphone Mixer", SND_SOC_NOPM, 0, 0,
+               adau1373_left_hp_mixer_controls),
+       SOC_MIXER_ARRAY("Right Headphone Mixer", SND_SOC_NOPM, 0, 0,
+               adau1373_right_hp_mixer_controls),
+       SND_SOC_DAPM_SUPPLY("Headphone Enable", ADAU1373_PWDN_CTRL3, 1, 0,
+               NULL, 0),
+
+       SND_SOC_DAPM_SUPPLY("AIF1 CLK", ADAU1373_SRC_DAI_CTRL(0), 0, 0,
+           NULL, 0),
+       SND_SOC_DAPM_SUPPLY("AIF2 CLK", ADAU1373_SRC_DAI_CTRL(1), 0, 0,
+           NULL, 0),
+       SND_SOC_DAPM_SUPPLY("AIF3 CLK", ADAU1373_SRC_DAI_CTRL(2), 0, 0,
+           NULL, 0),
+       SND_SOC_DAPM_SUPPLY("AIF1 IN SRC", ADAU1373_SRC_DAI_CTRL(0), 2, 0,
+           NULL, 0),
+       SND_SOC_DAPM_SUPPLY("AIF1 OUT SRC", ADAU1373_SRC_DAI_CTRL(0), 1, 0,
+           NULL, 0),
+       SND_SOC_DAPM_SUPPLY("AIF2 IN SRC", ADAU1373_SRC_DAI_CTRL(1), 2, 0,
+           NULL, 0),
+       SND_SOC_DAPM_SUPPLY("AIF2 OUT SRC", ADAU1373_SRC_DAI_CTRL(1), 1, 0,
+           NULL, 0),
+       SND_SOC_DAPM_SUPPLY("AIF3 IN SRC", ADAU1373_SRC_DAI_CTRL(2), 2, 0,
+           NULL, 0),
+       SND_SOC_DAPM_SUPPLY("AIF3 OUT SRC", ADAU1373_SRC_DAI_CTRL(2), 1, 0,
+           NULL, 0),
+
+       SND_SOC_DAPM_AIF_IN("AIF1 IN", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
+       SND_SOC_DAPM_AIF_OUT("AIF1 OUT", "AIF1 Capture", 0, SND_SOC_NOPM, 0, 0),
+       SND_SOC_DAPM_AIF_IN("AIF2 IN", "AIF2 Playback", 0, SND_SOC_NOPM, 0, 0),
+       SND_SOC_DAPM_AIF_OUT("AIF2 OUT", "AIF2 Capture", 0, SND_SOC_NOPM, 0, 0),
+       SND_SOC_DAPM_AIF_IN("AIF3 IN", "AIF3 Playback", 0, SND_SOC_NOPM, 0, 0),
+       SND_SOC_DAPM_AIF_OUT("AIF3 OUT", "AIF3 Capture", 0, SND_SOC_NOPM, 0, 0),
+
+       SOC_MIXER_ARRAY("DSP Channel1 Mixer", SND_SOC_NOPM, 0, 0,
+               adau1373_dsp_channel1_mixer_controls),
+       SOC_MIXER_ARRAY("DSP Channel2 Mixer", SND_SOC_NOPM, 0, 0,
+               adau1373_dsp_channel2_mixer_controls),
+       SOC_MIXER_ARRAY("DSP Channel3 Mixer", SND_SOC_NOPM, 0, 0,
+               adau1373_dsp_channel3_mixer_controls),
+       SOC_MIXER_ARRAY("DSP Channel4 Mixer", SND_SOC_NOPM, 0, 0,
+               adau1373_dsp_channel4_mixer_controls),
+       SOC_MIXER_ARRAY("DSP Channel5 Mixer", SND_SOC_NOPM, 0, 0,
+               adau1373_dsp_channel5_mixer_controls),
+
+       SOC_MIXER_ARRAY("AIF1 Mixer", SND_SOC_NOPM, 0, 0,
+               adau1373_aif1_mixer_controls),
+       SOC_MIXER_ARRAY("AIF2 Mixer", SND_SOC_NOPM, 0, 0,
+               adau1373_aif2_mixer_controls),
+       SOC_MIXER_ARRAY("AIF3 Mixer", SND_SOC_NOPM, 0, 0,
+               adau1373_aif3_mixer_controls),
+       SOC_MIXER_ARRAY("DAC1 Mixer", SND_SOC_NOPM, 0, 0,
+               adau1373_dac1_mixer_controls),
+       SOC_MIXER_ARRAY("DAC2 Mixer", SND_SOC_NOPM, 0, 0,
+               adau1373_dac2_mixer_controls),
+
+       SND_SOC_DAPM_SUPPLY("DSP", ADAU1373_DIGEN, 4, 0, NULL, 0),
+       SND_SOC_DAPM_SUPPLY("Recording Engine B", ADAU1373_DIGEN, 3, 0, NULL, 0),
+       SND_SOC_DAPM_SUPPLY("Recording Engine A", ADAU1373_DIGEN, 2, 0, NULL, 0),
+       SND_SOC_DAPM_SUPPLY("Playback Engine B", ADAU1373_DIGEN, 1, 0, NULL, 0),
+       SND_SOC_DAPM_SUPPLY("Playback Engine A", ADAU1373_DIGEN, 0, 0, NULL, 0),
+
+       SND_SOC_DAPM_SUPPLY("PLL1", SND_SOC_NOPM, 0, 0, adau1373_pll_event,
+               SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
+       SND_SOC_DAPM_SUPPLY("PLL2", SND_SOC_NOPM, 0, 0, adau1373_pll_event,
+               SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
+       SND_SOC_DAPM_SUPPLY("SYSCLK1", ADAU1373_CLK_SRC_DIV(0), 7, 0, NULL, 0),
+       SND_SOC_DAPM_SUPPLY("SYSCLK2", ADAU1373_CLK_SRC_DIV(1), 7, 0, NULL, 0),
+
+       SND_SOC_DAPM_INPUT("AIN1L"),
+       SND_SOC_DAPM_INPUT("AIN1R"),
+       SND_SOC_DAPM_INPUT("AIN2L"),
+       SND_SOC_DAPM_INPUT("AIN2R"),
+       SND_SOC_DAPM_INPUT("AIN3L"),
+       SND_SOC_DAPM_INPUT("AIN3R"),
+       SND_SOC_DAPM_INPUT("AIN4L"),
+       SND_SOC_DAPM_INPUT("AIN4R"),
+
+       SND_SOC_DAPM_INPUT("DMIC1DAT"),
+       SND_SOC_DAPM_INPUT("DMIC2DAT"),
+
+       SND_SOC_DAPM_OUTPUT("LOUT1L"),
+       SND_SOC_DAPM_OUTPUT("LOUT1R"),
+       SND_SOC_DAPM_OUTPUT("LOUT2L"),
+       SND_SOC_DAPM_OUTPUT("LOUT2R"),
+       SND_SOC_DAPM_OUTPUT("HPL"),
+       SND_SOC_DAPM_OUTPUT("HPR"),
+       SND_SOC_DAPM_OUTPUT("SPKL"),
+       SND_SOC_DAPM_OUTPUT("SPKR"),
+       SND_SOC_DAPM_OUTPUT("EP"),
+};
+
+static int adau1373_check_aif_clk(struct snd_soc_dapm_widget *source,
+       struct snd_soc_dapm_widget *sink)
+{
+       struct snd_soc_codec *codec = source->codec;
+       struct adau1373 *adau1373 = snd_soc_codec_get_drvdata(codec);
+       unsigned int dai;
+       const char *clk;
+
+       dai = sink->name[3] - '1';
+
+       if (!adau1373->dais[dai].master)
+               return 0;
+
+       if (adau1373->dais[dai].clk_src == ADAU1373_CLK_SRC_PLL1)
+               clk = "SYSCLK1";
+       else
+               clk = "SYSCLK2";
+
+       return strcmp(source->name, clk) == 0;
+}
+
+static int adau1373_check_src(struct snd_soc_dapm_widget *source,
+       struct snd_soc_dapm_widget *sink)
+{
+       struct snd_soc_codec *codec = source->codec;
+       struct adau1373 *adau1373 = snd_soc_codec_get_drvdata(codec);
+       unsigned int dai;
+
+       dai = sink->name[3] - '1';
+
+       return adau1373->dais[dai].enable_src;
+}
+
+#define DSP_CHANNEL_MIXER_ROUTES(_sink) \
+       { _sink, "DMIC2 Swapped Switch", "DMIC2" }, \
+       { _sink, "DMIC2 Switch", "DMIC2" }, \
+       { _sink, "ADC/DMIC1 Swapped Switch", "Decimator Mux" }, \
+       { _sink, "ADC/DMIC1 Switch", "Decimator Mux" }, \
+       { _sink, "AIF1 Switch", "AIF1 IN" }, \
+       { _sink, "AIF2 Switch", "AIF2 IN" }, \
+       { _sink, "AIF3 Switch", "AIF3 IN" }
+
+#define DSP_OUTPUT_MIXER_ROUTES(_sink) \
+       { _sink, "DSP Channel1 Switch", "DSP Channel1 Mixer" }, \
+       { _sink, "DSP Channel2 Switch", "DSP Channel2 Mixer" }, \
+       { _sink, "DSP Channel3 Switch", "DSP Channel3 Mixer" }, \
+       { _sink, "DSP Channel4 Switch", "DSP Channel4 Mixer" }, \
+       { _sink, "DSP Channel5 Switch", "DSP Channel5 Mixer" }
+
+#define LEFT_OUTPUT_MIXER_ROUTES(_sink) \
+       { _sink, "Right DAC2 Switch", "Right DAC2" }, \
+       { _sink, "Left DAC2 Switch", "Left DAC2" }, \
+       { _sink, "Right DAC1 Switch", "Right DAC1" }, \
+       { _sink, "Left DAC1 Switch", "Left DAC1" }, \
+       { _sink, "Input 1 Bypass Switch", "IN1PGA" }, \
+       { _sink, "Input 2 Bypass Switch", "IN2PGA" }, \
+       { _sink, "Input 3 Bypass Switch", "IN3PGA" }, \
+       { _sink, "Input 4 Bypass Switch", "IN4PGA" }
+
+#define RIGHT_OUTPUT_MIXER_ROUTES(_sink) \
+       { _sink, "Right DAC2 Switch", "Right DAC2" }, \
+       { _sink, "Left DAC2 Switch", "Left DAC2" }, \
+       { _sink, "Right DAC1 Switch", "Right DAC1" }, \
+       { _sink, "Left DAC1 Switch", "Left DAC1" }, \
+       { _sink, "Input 1 Bypass Switch", "IN1PGA" }, \
+       { _sink, "Input 2 Bypass Switch", "IN2PGA" }, \
+       { _sink, "Input 3 Bypass Switch", "IN3PGA" }, \
+       { _sink, "Input 4 Bypass Switch", "IN4PGA" }
+
+static const struct snd_soc_dapm_route adau1373_dapm_routes[] = {
+       { "Left ADC Mixer", "DAC1 Switch", "Left DAC1" },
+       { "Left ADC Mixer", "Input 1 Switch", "IN1PGA" },
+       { "Left ADC Mixer", "Input 2 Switch", "IN2PGA" },
+       { "Left ADC Mixer", "Input 3 Switch", "IN3PGA" },
+       { "Left ADC Mixer", "Input 4 Switch", "IN4PGA" },
+
+       { "Right ADC Mixer", "DAC1 Switch", "Right DAC1" },
+       { "Right ADC Mixer", "Input 1 Switch", "IN1PGA" },
+       { "Right ADC Mixer", "Input 2 Switch", "IN2PGA" },
+       { "Right ADC Mixer", "Input 3 Switch", "IN3PGA" },
+       { "Right ADC Mixer", "Input 4 Switch", "IN4PGA" },
+
+       { "Left ADC", NULL, "Left ADC Mixer" },
+       { "Right ADC", NULL, "Right ADC Mixer" },
+
+       { "Decimator Mux", "ADC", "Left ADC" },
+       { "Decimator Mux", "ADC", "Right ADC" },
+       { "Decimator Mux", "DMIC1", "DMIC1" },
+
+       DSP_CHANNEL_MIXER_ROUTES("DSP Channel1 Mixer"),
+       DSP_CHANNEL_MIXER_ROUTES("DSP Channel2 Mixer"),
+       DSP_CHANNEL_MIXER_ROUTES("DSP Channel3 Mixer"),
+       DSP_CHANNEL_MIXER_ROUTES("DSP Channel4 Mixer"),
+       DSP_CHANNEL_MIXER_ROUTES("DSP Channel5 Mixer"),
+
+       DSP_OUTPUT_MIXER_ROUTES("AIF1 Mixer"),
+       DSP_OUTPUT_MIXER_ROUTES("AIF2 Mixer"),
+       DSP_OUTPUT_MIXER_ROUTES("AIF3 Mixer"),
+       DSP_OUTPUT_MIXER_ROUTES("DAC1 Mixer"),
+       DSP_OUTPUT_MIXER_ROUTES("DAC2 Mixer"),
+
+       { "AIF1 OUT", NULL, "AIF1 Mixer" },
+       { "AIF2 OUT", NULL, "AIF2 Mixer" },
+       { "AIF3 OUT", NULL, "AIF3 Mixer" },
+       { "Left DAC1", NULL, "DAC1 Mixer" },
+       { "Right DAC1", NULL, "DAC1 Mixer" },
+       { "Left DAC2", NULL, "DAC2 Mixer" },
+       { "Right DAC2", NULL, "DAC2 Mixer" },
+
+       LEFT_OUTPUT_MIXER_ROUTES("Left Lineout1 Mixer"),
+       RIGHT_OUTPUT_MIXER_ROUTES("Right Lineout1 Mixer"),
+       LEFT_OUTPUT_MIXER_ROUTES("Left Lineout2 Mixer"),
+       RIGHT_OUTPUT_MIXER_ROUTES("Right Lineout2 Mixer"),
+       LEFT_OUTPUT_MIXER_ROUTES("Left Speaker Mixer"),
+       RIGHT_OUTPUT_MIXER_ROUTES("Right Speaker Mixer"),
+
+       { "Left Headphone Mixer", "Left DAC2 Switch", "Left DAC2" },
+       { "Left Headphone Mixer", "Left DAC1 Switch", "Left DAC1" },
+       { "Left Headphone Mixer", "Input 1 Bypass Switch", "IN1PGA" },
+       { "Left Headphone Mixer", "Input 2 Bypass Switch", "IN2PGA" },
+       { "Left Headphone Mixer", "Input 3 Bypass Switch", "IN3PGA" },
+       { "Left Headphone Mixer", "Input 4 Bypass Switch", "IN4PGA" },
+       { "Right Headphone Mixer", "Right DAC2 Switch", "Right DAC2" },
+       { "Right Headphone Mixer", "Right DAC1 Switch", "Right DAC1" },
+       { "Right Headphone Mixer", "Input 1 Bypass Switch", "IN1PGA" },
+       { "Right Headphone Mixer", "Input 2 Bypass Switch", "IN2PGA" },
+       { "Right Headphone Mixer", "Input 3 Bypass Switch", "IN3PGA" },
+       { "Right Headphone Mixer", "Input 4 Bypass Switch", "IN4PGA" },
+
+       { "Left Headphone Mixer", NULL, "Headphone Enable" },
+       { "Right Headphone Mixer", NULL, "Headphone Enable" },
+
+       { "Earpiece Mixer", "Right DAC2 Switch", "Right DAC2" },
+       { "Earpiece Mixer", "Left DAC2 Switch", "Left DAC2" },
+       { "Earpiece Mixer", "Right DAC1 Switch", "Right DAC1" },
+       { "Earpiece Mixer", "Left DAC1 Switch", "Left DAC1" },
+       { "Earpiece Mixer", "Input 1 Bypass Switch", "IN1PGA" },
+       { "Earpiece Mixer", "Input 2 Bypass Switch", "IN2PGA" },
+       { "Earpiece Mixer", "Input 3 Bypass Switch", "IN3PGA" },
+       { "Earpiece Mixer", "Input 4 Bypass Switch", "IN4PGA" },
+
+       { "LOUT1L", NULL, "Left Lineout1 Mixer" },
+       { "LOUT1R", NULL, "Right Lineout1 Mixer" },
+       { "LOUT2L", NULL, "Left Lineout2 Mixer" },
+       { "LOUT2R", NULL, "Right Lineout2 Mixer" },
+       { "SPKL", NULL, "Left Speaker Mixer" },
+       { "SPKR", NULL, "Right Speaker Mixer" },
+       { "HPL", NULL, "Left Headphone Mixer" },
+       { "HPR", NULL, "Right Headphone Mixer" },
+       { "EP", NULL, "Earpiece Mixer" },
+
+       { "IN1PGA", NULL, "AIN1L" },
+       { "IN2PGA", NULL, "AIN2L" },
+       { "IN3PGA", NULL, "AIN3L" },
+       { "IN4PGA", NULL, "AIN4L" },
+       { "IN1PGA", NULL, "AIN1R" },
+       { "IN2PGA", NULL, "AIN2R" },
+       { "IN3PGA", NULL, "AIN3R" },
+       { "IN4PGA", NULL, "AIN4R" },
+
+       { "SYSCLK1", NULL, "PLL1" },
+       { "SYSCLK2", NULL, "PLL2" },
+
+       { "Left DAC1", NULL, "SYSCLK1" },
+       { "Right DAC1", NULL, "SYSCLK1" },
+       { "Left DAC2", NULL, "SYSCLK1" },
+       { "Right DAC2", NULL, "SYSCLK1" },
+       { "Left ADC", NULL, "SYSCLK1" },
+       { "Right ADC", NULL, "SYSCLK1" },
+
+       { "DSP", NULL, "SYSCLK1" },
+
+       { "AIF1 Mixer", NULL, "DSP" },
+       { "AIF2 Mixer", NULL, "DSP" },
+       { "AIF3 Mixer", NULL, "DSP" },
+       { "DAC1 Mixer", NULL, "DSP" },
+       { "DAC2 Mixer", NULL, "DSP" },
+       { "DAC1 Mixer", NULL, "Playback Engine A" },
+       { "DAC2 Mixer", NULL, "Playback Engine B" },
+       { "Left ADC Mixer", NULL, "Recording Engine A" },
+       { "Right ADC Mixer", NULL, "Recording Engine A" },
+
+       { "AIF1 CLK", NULL, "SYSCLK1", adau1373_check_aif_clk },
+       { "AIF2 CLK", NULL, "SYSCLK1", adau1373_check_aif_clk },
+       { "AIF3 CLK", NULL, "SYSCLK1", adau1373_check_aif_clk },
+       { "AIF1 CLK", NULL, "SYSCLK2", adau1373_check_aif_clk },
+       { "AIF2 CLK", NULL, "SYSCLK2", adau1373_check_aif_clk },
+       { "AIF3 CLK", NULL, "SYSCLK2", adau1373_check_aif_clk },
+
+       { "AIF1 IN", NULL, "AIF1 CLK" },
+       { "AIF1 OUT", NULL, "AIF1 CLK" },
+       { "AIF2 IN", NULL, "AIF2 CLK" },
+       { "AIF2 OUT", NULL, "AIF2 CLK" },
+       { "AIF3 IN", NULL, "AIF3 CLK" },
+       { "AIF3 OUT", NULL, "AIF3 CLK" },
+       { "AIF1 IN", NULL, "AIF1 IN SRC", adau1373_check_src },
+       { "AIF1 OUT", NULL, "AIF1 OUT SRC", adau1373_check_src },
+       { "AIF2 IN", NULL, "AIF2 IN SRC", adau1373_check_src },
+       { "AIF2 OUT", NULL, "AIF2 OUT SRC", adau1373_check_src },
+       { "AIF3 IN", NULL, "AIF3 IN SRC", adau1373_check_src },
+       { "AIF3 OUT", NULL, "AIF3 OUT SRC", adau1373_check_src },
+
+       { "DMIC1", NULL, "DMIC1DAT" },
+       { "DMIC1", NULL, "SYSCLK1" },
+       { "DMIC1", NULL, "Recording Engine A" },
+       { "DMIC2", NULL, "DMIC2DAT" },
+       { "DMIC2", NULL, "SYSCLK1" },
+       { "DMIC2", NULL, "Recording Engine B" },
+};
+
+static int adau1373_hw_params(struct snd_pcm_substream *substream,
+       struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
+{
+       struct snd_soc_codec *codec = dai->codec;
+       struct adau1373 *adau1373 = snd_soc_codec_get_drvdata(codec);
+       struct adau1373_dai *adau1373_dai = &adau1373->dais[dai->id];
+       unsigned int div;
+       unsigned int freq;
+       unsigned int ctrl;
+
+       freq = adau1373_dai->sysclk;
+
+       if (freq % params_rate(params) != 0)
+               return -EINVAL;
+
+       switch (freq / params_rate(params)) {
+       case 1024: /* sysclk / 256 */
+               div = 0;
+               break;
+       case 1536: /* 2/3 sysclk / 256 */
+               div = 1;
+               break;
+       case 2048: /* 1/2 sysclk / 256 */
+               div = 2;
+               break;
+       case 3072: /* 1/3 sysclk / 256 */
+               div = 3;
+               break;
+       case 4096: /* 1/4 sysclk / 256 */
+               div = 4;
+               break;
+       case 6144: /* 1/6 sysclk / 256 */
+               div = 5;
+               break;
+       case 5632: /* 2/11 sysclk / 256 */
+               div = 6;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       adau1373_dai->enable_src = (div != 0);
+
+       snd_soc_update_bits(codec, ADAU1373_BCLKDIV(dai->id),
+               ~ADAU1373_BCLKDIV_SOURCE, (div << 2) | ADAU1373_BCLKDIV_64);
+
+       switch (params_format(params)) {
+       case SNDRV_PCM_FORMAT_S16_LE:
+               ctrl = ADAU1373_DAI_WLEN_16;
+               break;
+       case SNDRV_PCM_FORMAT_S20_3LE:
+               ctrl = ADAU1373_DAI_WLEN_20;
+               break;
+       case SNDRV_PCM_FORMAT_S24_LE:
+               ctrl = ADAU1373_DAI_WLEN_24;
+               break;
+       case SNDRV_PCM_FORMAT_S32_LE:
+               ctrl = ADAU1373_DAI_WLEN_32;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return snd_soc_update_bits(codec, ADAU1373_DAI(dai->id),
+                       ADAU1373_DAI_WLEN_MASK, ctrl);
+}
+
+static int adau1373_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
+{
+       struct snd_soc_codec *codec = dai->codec;
+       struct adau1373 *adau1373 = snd_soc_codec_get_drvdata(codec);
+       struct adau1373_dai *adau1373_dai = &adau1373->dais[dai->id];
+       unsigned int ctrl;
+
+       switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
+       case SND_SOC_DAIFMT_CBM_CFM:
+               ctrl = ADAU1373_DAI_MASTER;
+               adau1373_dai->master = true;
+               break;
+       case SND_SOC_DAIFMT_CBS_CFS:
+               ctrl = 0;
+               adau1373_dai->master = false;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+       case SND_SOC_DAIFMT_I2S:
+               ctrl |= ADAU1373_DAI_FORMAT_I2S;
+               break;
+       case SND_SOC_DAIFMT_LEFT_J:
+               ctrl |= ADAU1373_DAI_FORMAT_LEFT_J;
+               break;
+       case SND_SOC_DAIFMT_RIGHT_J:
+               ctrl |= ADAU1373_DAI_FORMAT_RIGHT_J;
+               break;
+       case SND_SOC_DAIFMT_DSP_B:
+               ctrl |= ADAU1373_DAI_FORMAT_DSP;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
+       case SND_SOC_DAIFMT_NB_NF:
+               break;
+       case SND_SOC_DAIFMT_IB_NF:
+               ctrl |= ADAU1373_DAI_INVERT_BCLK;
+               break;
+       case SND_SOC_DAIFMT_NB_IF:
+               ctrl |= ADAU1373_DAI_INVERT_LRCLK;
+               break;
+       case SND_SOC_DAIFMT_IB_IF:
+               ctrl |= ADAU1373_DAI_INVERT_LRCLK | ADAU1373_DAI_INVERT_BCLK;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       snd_soc_update_bits(codec, ADAU1373_DAI(dai->id),
+               ~ADAU1373_DAI_WLEN_MASK, ctrl);
+
+       return 0;
+}
+
+static int adau1373_set_dai_sysclk(struct snd_soc_dai *dai,
+       int clk_id, unsigned int freq, int dir)
+{
+       struct adau1373 *adau1373 = snd_soc_codec_get_drvdata(dai->codec);
+       struct adau1373_dai *adau1373_dai = &adau1373->dais[dai->id];
+
+       switch (clk_id) {
+       case ADAU1373_CLK_SRC_PLL1:
+       case ADAU1373_CLK_SRC_PLL2:
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       adau1373_dai->sysclk = freq;
+       adau1373_dai->clk_src = clk_id;
+
+       snd_soc_update_bits(dai->codec, ADAU1373_BCLKDIV(dai->id),
+               ADAU1373_BCLKDIV_SOURCE, clk_id << 5);
+
+       return 0;
+}
+
+static const struct snd_soc_dai_ops adau1373_dai_ops = {
+       .hw_params      = adau1373_hw_params,
+       .set_sysclk     = adau1373_set_dai_sysclk,
+       .set_fmt        = adau1373_set_dai_fmt,
+};
+
+#define ADAU1373_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
+       SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
+
+static struct snd_soc_dai_driver adau1373_dai_driver[] = {
+       {
+               .id = 0,
+               .name = "adau1373-aif1",
+               .playback = {
+                       .stream_name = "AIF1 Playback",
+                       .channels_min = 2,
+                       .channels_max = 2,
+                       .rates = SNDRV_PCM_RATE_8000_48000,
+                       .formats = ADAU1373_FORMATS,
+               },
+               .capture = {
+                       .stream_name = "AIF1 Capture",
+                       .channels_min = 2,
+                       .channels_max = 2,
+                       .rates = SNDRV_PCM_RATE_8000_48000,
+                       .formats = ADAU1373_FORMATS,
+               },
+               .ops = &adau1373_dai_ops,
+               .symmetric_rates = 1,
+       },
+       {
+               .id = 1,
+               .name = "adau1373-aif2",
+               .playback = {
+                       .stream_name = "AIF2 Playback",
+                       .channels_min = 2,
+                       .channels_max = 2,
+                       .rates = SNDRV_PCM_RATE_8000_48000,
+                       .formats = ADAU1373_FORMATS,
+               },
+               .capture = {
+                       .stream_name = "AIF2 Capture",
+                       .channels_min = 2,
+                       .channels_max = 2,
+                       .rates = SNDRV_PCM_RATE_8000_48000,
+                       .formats = ADAU1373_FORMATS,
+               },
+               .ops = &adau1373_dai_ops,
+               .symmetric_rates = 1,
+       },
+       {
+               .id = 2,
+               .name = "adau1373-aif3",
+               .playback = {
+                       .stream_name = "AIF3 Playback",
+                       .channels_min = 2,
+                       .channels_max = 2,
+                       .rates = SNDRV_PCM_RATE_8000_48000,
+                       .formats = ADAU1373_FORMATS,
+               },
+               .capture = {
+                       .stream_name = "AIF3 Capture",
+                       .channels_min = 2,
+                       .channels_max = 2,
+                       .rates = SNDRV_PCM_RATE_8000_48000,
+                       .formats = ADAU1373_FORMATS,
+               },
+               .ops = &adau1373_dai_ops,
+               .symmetric_rates = 1,
+       },
+};
+
+static int adau1373_set_pll(struct snd_soc_codec *codec, int pll_id,
+       int source, unsigned int freq_in, unsigned int freq_out)
+{
+       unsigned int dpll_div = 0;
+       unsigned int x, r, n, m, i, j, mode;
+
+       switch (pll_id) {
+       case ADAU1373_PLL1:
+       case ADAU1373_PLL2:
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       switch (source) {
+       case ADAU1373_PLL_SRC_BCLK1:
+       case ADAU1373_PLL_SRC_BCLK2:
+       case ADAU1373_PLL_SRC_BCLK3:
+       case ADAU1373_PLL_SRC_LRCLK1:
+       case ADAU1373_PLL_SRC_LRCLK2:
+       case ADAU1373_PLL_SRC_LRCLK3:
+       case ADAU1373_PLL_SRC_MCLK1:
+       case ADAU1373_PLL_SRC_MCLK2:
+       case ADAU1373_PLL_SRC_GPIO1:
+       case ADAU1373_PLL_SRC_GPIO2:
+       case ADAU1373_PLL_SRC_GPIO3:
+       case ADAU1373_PLL_SRC_GPIO4:
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       if (freq_in < 7813 || freq_in > 27000000)
+               return -EINVAL;
+
+       if (freq_out < 45158000 || freq_out > 49152000)
+               return -EINVAL;
+
+       /* APLL input needs to be >= 8Mhz, so in case freq_in is less we use the
+        * DPLL to get it there. DPLL_out = (DPLL_in / div) * 1024 */
+       while (freq_in < 8000000) {
+               freq_in *= 2;
+               dpll_div++;
+       }
+
+       if (freq_out % freq_in != 0) {
+               /* fout = fin * (r + (n/m)) / x */
+               x = DIV_ROUND_UP(freq_in, 13500000);
+               freq_in /= x;
+               r = freq_out / freq_in;
+               i = freq_out % freq_in;
+               j = gcd(i, freq_in);
+               n = i / j;
+               m = freq_in / j;
+               x--;
+               mode = 1;
+       } else {
+               /* fout = fin / r */
+               r = freq_out / freq_in;
+               n = 0;
+               m = 0;
+               x = 0;
+               mode = 0;
+       }
+
+       if (r < 2 || r > 8 || x > 3 || m > 0xffff || n > 0xffff)
+               return -EINVAL;
+
+       if (dpll_div) {
+               dpll_div = 11 - dpll_div;
+               snd_soc_update_bits(codec, ADAU1373_PLL_CTRL6(pll_id),
+                       ADAU1373_PLL_CTRL6_DPLL_BYPASS, 0);
+       } else {
+               snd_soc_update_bits(codec, ADAU1373_PLL_CTRL6(pll_id),
+                       ADAU1373_PLL_CTRL6_DPLL_BYPASS,
+                       ADAU1373_PLL_CTRL6_DPLL_BYPASS);
+       }
+
+       snd_soc_write(codec, ADAU1373_DPLL_CTRL(pll_id),
+               (source << 4) | dpll_div);
+       snd_soc_write(codec, ADAU1373_PLL_CTRL1(pll_id), (m >> 8) & 0xff);
+       snd_soc_write(codec, ADAU1373_PLL_CTRL2(pll_id), m & 0xff);
+       snd_soc_write(codec, ADAU1373_PLL_CTRL3(pll_id), (n >> 8) & 0xff);
+       snd_soc_write(codec, ADAU1373_PLL_CTRL4(pll_id), n & 0xff);
+       snd_soc_write(codec, ADAU1373_PLL_CTRL5(pll_id),
+               (r << 3) | (x << 1) | mode);
+
+       /* Set sysclk to pll_rate / 4 */
+       snd_soc_update_bits(codec, ADAU1373_CLK_SRC_DIV(pll_id), 0x3f, 0x09);
+
+       return 0;
+}
+
+static void adau1373_load_drc_settings(struct snd_soc_codec *codec,
+       unsigned int nr, uint8_t *drc)
+{
+       unsigned int i;
+
+       for (i = 0; i < ADAU1373_DRC_SIZE; ++i)
+               snd_soc_write(codec, ADAU1373_DRC(nr) + i, drc[i]);
+}
+
+static bool adau1373_valid_micbias(enum adau1373_micbias_voltage micbias)
+{
+       switch (micbias) {
+       case ADAU1373_MICBIAS_2_9V:
+       case ADAU1373_MICBIAS_2_2V:
+       case ADAU1373_MICBIAS_2_6V:
+       case ADAU1373_MICBIAS_1_8V:
+               return true;
+       default:
+               break;
+       }
+       return false;
+}
+
+static int adau1373_probe(struct snd_soc_codec *codec)
+{
+       struct adau1373_platform_data *pdata = codec->dev->platform_data;
+       bool lineout_differential = false;
+       unsigned int val;
+       int ret;
+       int i;
+
+       ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C);
+       if (ret) {
+               dev_err(codec->dev, "failed to set cache I/O: %d\n", ret);
+               return ret;
+       }
+
+       codec->dapm.idle_bias_off = true;
+
+       if (pdata) {
+               if (pdata->num_drc > ARRAY_SIZE(pdata->drc_setting))
+                       return -EINVAL;
+
+               if (!adau1373_valid_micbias(pdata->micbias1) ||
+                       !adau1373_valid_micbias(pdata->micbias2))
+                       return -EINVAL;
+
+               for (i = 0; i < pdata->num_drc; ++i) {
+                       adau1373_load_drc_settings(codec, i,
+                               pdata->drc_setting[i]);
+               }
+
+               snd_soc_add_controls(codec, adau1373_drc_controls,
+                       pdata->num_drc);
+
+               val = 0;
+               for (i = 0; i < 4; ++i) {
+                       if (pdata->input_differential[i])
+                               val |= BIT(i);
+               }
+               snd_soc_write(codec, ADAU1373_INPUT_MODE, val);
+
+               val = 0;
+               if (pdata->lineout_differential)
+                       val |= ADAU1373_OUTPUT_CTRL_LDIFF;
+               if (pdata->lineout_ground_sense)
+                       val |= ADAU1373_OUTPUT_CTRL_LNFBEN;
+               snd_soc_write(codec, ADAU1373_OUTPUT_CTRL, val);
+
+               lineout_differential = pdata->lineout_differential;
+
+               snd_soc_write(codec, ADAU1373_EP_CTRL,
+                       (pdata->micbias1 << ADAU1373_EP_CTRL_MICBIAS1_OFFSET) |
+                       (pdata->micbias2 << ADAU1373_EP_CTRL_MICBIAS2_OFFSET));
+       }
+
+       if (!lineout_differential) {
+               snd_soc_add_controls(codec, adau1373_lineout2_controls,
+                       ARRAY_SIZE(adau1373_lineout2_controls));
+       }
+
+       snd_soc_write(codec, ADAU1373_ADC_CTRL,
+           ADAU1373_ADC_CTRL_RESET_FORCE | ADAU1373_ADC_CTRL_PEAK_DETECT);
+
+       return 0;
+}
+
+static int adau1373_set_bias_level(struct snd_soc_codec *codec,
+       enum snd_soc_bias_level level)
+{
+       switch (level) {
+       case SND_SOC_BIAS_ON:
+               break;
+       case SND_SOC_BIAS_PREPARE:
+               break;
+       case SND_SOC_BIAS_STANDBY:
+               snd_soc_update_bits(codec, ADAU1373_PWDN_CTRL3,
+                       ADAU1373_PWDN_CTRL3_PWR_EN, ADAU1373_PWDN_CTRL3_PWR_EN);
+               break;
+       case SND_SOC_BIAS_OFF:
+               snd_soc_update_bits(codec, ADAU1373_PWDN_CTRL3,
+                       ADAU1373_PWDN_CTRL3_PWR_EN, 0);
+               break;
+       }
+       codec->dapm.bias_level = level;
+       return 0;
+}
+
+static int adau1373_remove(struct snd_soc_codec *codec)
+{
+       adau1373_set_bias_level(codec, SND_SOC_BIAS_OFF);
+       return 0;
+}
+
+static int adau1373_suspend(struct snd_soc_codec *codec, pm_message_t state)
+{
+       return adau1373_set_bias_level(codec, SND_SOC_BIAS_OFF);
+}
+
+static int adau1373_resume(struct snd_soc_codec *codec)
+{
+       adau1373_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+       snd_soc_cache_sync(codec);
+
+       return 0;
+}
+
+static struct snd_soc_codec_driver adau1373_codec_driver = {
+       .probe =        adau1373_probe,
+       .remove =       adau1373_remove,
+       .suspend =      adau1373_suspend,
+       .resume =       adau1373_resume,
+       .set_bias_level = adau1373_set_bias_level,
+       .reg_cache_size = ARRAY_SIZE(adau1373_default_regs),
+       .reg_cache_default = adau1373_default_regs,
+       .reg_word_size = sizeof(uint8_t),
+
+       .set_pll = adau1373_set_pll,
+
+       .controls = adau1373_controls,
+       .num_controls = ARRAY_SIZE(adau1373_controls),
+       .dapm_widgets = adau1373_dapm_widgets,
+       .num_dapm_widgets = ARRAY_SIZE(adau1373_dapm_widgets),
+       .dapm_routes = adau1373_dapm_routes,
+       .num_dapm_routes = ARRAY_SIZE(adau1373_dapm_routes),
+};
+
+static int __devinit adau1373_i2c_probe(struct i2c_client *client,
+       const struct i2c_device_id *id)
+{
+       struct adau1373 *adau1373;
+       int ret;
+
+       adau1373 = kzalloc(sizeof(*adau1373), GFP_KERNEL);
+       if (!adau1373)
+               return -ENOMEM;
+
+       dev_set_drvdata(&client->dev, adau1373);
+
+       ret = snd_soc_register_codec(&client->dev, &adau1373_codec_driver,
+                       adau1373_dai_driver, ARRAY_SIZE(adau1373_dai_driver));
+       if (ret < 0)
+               kfree(adau1373);
+
+       return ret;
+}
+
+static int __devexit adau1373_i2c_remove(struct i2c_client *client)
+{
+       snd_soc_unregister_codec(&client->dev);
+       kfree(dev_get_drvdata(&client->dev));
+       return 0;
+}
+
+static const struct i2c_device_id adau1373_i2c_id[] = {
+       { "adau1373", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, adau1373_i2c_id);
+
+static struct i2c_driver adau1373_i2c_driver = {
+       .driver = {
+               .name = "adau1373",
+               .owner = THIS_MODULE,
+       },
+       .probe = adau1373_i2c_probe,
+       .remove = __devexit_p(adau1373_i2c_remove),
+       .id_table = adau1373_i2c_id,
+};
+
+static int __init adau1373_init(void)
+{
+       return i2c_add_driver(&adau1373_i2c_driver);
+}
+module_init(adau1373_init);
+
+static void __exit adau1373_exit(void)
+{
+       i2c_del_driver(&adau1373_i2c_driver);
+}
+module_exit(adau1373_exit);
+
+MODULE_DESCRIPTION("ASoC ADAU1373 driver");
+MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/adau1373.h b/sound/soc/codecs/adau1373.h
new file mode 100644 (file)
index 0000000..c6ab553
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef __ADAU1373_H__
+#define __ADAU1373_H__
+
+enum adau1373_pll_src {
+       ADAU1373_PLL_SRC_MCLK1 = 0,
+       ADAU1373_PLL_SRC_BCLK1 = 1,
+       ADAU1373_PLL_SRC_BCLK2 = 2,
+       ADAU1373_PLL_SRC_BCLK3 = 3,
+       ADAU1373_PLL_SRC_LRCLK1 = 4,
+       ADAU1373_PLL_SRC_LRCLK2 = 5,
+       ADAU1373_PLL_SRC_LRCLK3 = 6,
+       ADAU1373_PLL_SRC_GPIO1 = 7,
+       ADAU1373_PLL_SRC_GPIO2 = 8,
+       ADAU1373_PLL_SRC_GPIO3 = 9,
+       ADAU1373_PLL_SRC_GPIO4 = 10,
+       ADAU1373_PLL_SRC_MCLK2 = 11,
+};
+
+enum adau1373_pll {
+       ADAU1373_PLL1 = 0,
+       ADAU1373_PLL2 = 1,
+};
+
+enum adau1373_clk_src {
+       ADAU1373_CLK_SRC_PLL1 = 0,
+       ADAU1373_CLK_SRC_PLL2 = 1,
+};
+
+#endif
index 2758d5fc60d6555ed2709e43afa25a4fe02865d4..8b7e1c50d6e9df43d2a25956a698094eb2bb6738 100644 (file)
@@ -401,7 +401,7 @@ static int adau1701_digital_mute(struct snd_soc_dai *dai, int mute)
 }
 
 static int adau1701_set_sysclk(struct snd_soc_codec *codec, int clk_id,
-       unsigned int freq, int dir)
+       int source, unsigned int freq, int dir)
 {
        unsigned int val;
 
@@ -458,6 +458,7 @@ static int adau1701_probe(struct snd_soc_codec *codec)
        int ret;
 
        codec->dapm.idle_bias_off = 1;
+       codec->control_data = to_i2c_client(codec->dev);
 
        ret = adau1701_load_firmware(codec);
        if (ret)
index 300c04b70e71ba3680a1f522451a94277682a059..f9f08948e5e878f12d40a1f337d6d40c7247119e 100644 (file)
@@ -523,7 +523,8 @@ static int adav80x_hw_params(struct snd_pcm_substream *substream,
 }
 
 static int adav80x_set_sysclk(struct snd_soc_codec *codec,
-               int clk_id, unsigned int freq, int dir)
+                             int clk_id, int source,
+                             unsigned int freq, int dir)
 {
        struct adav80x *adav80x = snd_soc_codec_get_drvdata(codec);
 
diff --git a/sound/soc/codecs/ads117x.h b/sound/soc/codecs/ads117x.h
deleted file mode 100644 (file)
index 3ce0286..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * ads117x.h  --  Driver for ads1174/8 ADC chips
- *
- * Copyright 2009 ShotSpotter Inc.
- * Author: Graeme Gregory <gg@slimlogic.co.uk>
- *
- *  This program is free software; you can redistribute  it and/or modify it
- *  under  the terms of  the GNU General  Public License as published by the
- *  Free Software Foundation;  either version 2 of the  License, or (at your
- *  option) any later version.
- */
-extern struct snd_soc_dai_driver ads117x_dai;
-extern struct snd_soc_codec_driver soc_codec_dev_ads117x;
index cbf0b6d400b8d22d899854e6cd1d38b3d9fe2636..d3b29dce6ed7f27c080e7059ed5fc067d0d3ad0a 100644 (file)
@@ -247,7 +247,7 @@ static struct snd_soc_codec_driver soc_codec_device_ak4104 = {
        .probe =        ak4104_probe,
        .remove =       ak4104_remove,
        .reg_cache_size = AK4104_NUM_REGS,
-       .reg_word_size = sizeof(u16),
+       .reg_word_size = sizeof(u8),
 };
 
 static int ak4104_spi_probe(struct spi_device *spi)
index e1a214ee757ffaa2621572ebb084fb0033bd621c..95d782d86e7d5fc906e122c23dd7ae48ff39fd4a 100644 (file)
 struct ak4535_priv {
        unsigned int sysclk;
        enum snd_soc_control_type control_type;
-       void *control_data;
 };
 
 /*
  * ak4535 register cache
  */
-static const u16 ak4535_reg[AK4535_CACHEREGNUM] = {
-    0x0000, 0x0080, 0x0000, 0x0003,
-    0x0002, 0x0000, 0x0011, 0x0001,
-    0x0000, 0x0040, 0x0036, 0x0010,
-    0x0000, 0x0000, 0x0057, 0x0000,
-};
-
-/*
- * read ak4535 register cache
- */
-static inline unsigned int ak4535_read_reg_cache(struct snd_soc_codec *codec,
-       unsigned int reg)
-{
-       u16 *cache = codec->reg_cache;
-       if (reg >= AK4535_CACHEREGNUM)
-               return -1;
-       return cache[reg];
-}
-
-/*
- * write ak4535 register cache
- */
-static inline void ak4535_write_reg_cache(struct snd_soc_codec *codec,
-       u16 reg, unsigned int value)
-{
-       u16 *cache = codec->reg_cache;
-       if (reg >= AK4535_CACHEREGNUM)
-               return;
-       cache[reg] = value;
-}
-
-/*
- * write to the AK4535 register space
- */
-static int ak4535_write(struct snd_soc_codec *codec, unsigned int reg,
-       unsigned int value)
-{
-       u8 data[2];
-
-       /* data is
-        *   D15..D8 AK4535 register offset
-        *   D7...D0 register data
-        */
-       data[0] = reg & 0xff;
-       data[1] = value & 0xff;
-
-       ak4535_write_reg_cache(codec, reg, value);
-       if (codec->hw_write(codec->control_data, data, 2) == 2)
-               return 0;
-       else
-               return -EIO;
-}
-
-static int ak4535_sync(struct snd_soc_codec *codec)
-{
-       u16 *cache = codec->reg_cache;
-       int i, r = 0;
-
-       for (i = 0; i < AK4535_CACHEREGNUM; i++)
-               r |= ak4535_write(codec, i, cache[i]);
-
-       return r;
+static const u8 ak4535_reg[AK4535_CACHEREGNUM] = {
+       0x00, 0x80, 0x00, 0x03,
+       0x02, 0x00, 0x11, 0x01,
+       0x00, 0x40, 0x36, 0x10,
+       0x00, 0x00, 0x57, 0x00,
 };
 
 static const char *ak4535_mono_gain[] = {"+6dB", "-17dB"};
@@ -304,7 +246,7 @@ static int ak4535_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_codec *codec = rtd->codec;
        struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec);
-       u8 mode2 = ak4535_read_reg_cache(codec, AK4535_MODE2) & ~(0x3 << 5);
+       u8 mode2 = snd_soc_read(codec, AK4535_MODE2) & ~(0x3 << 5);
        int rate = params_rate(params), fs = 256;
 
        if (rate)
@@ -323,7 +265,7 @@ static int ak4535_hw_params(struct snd_pcm_substream *substream,
        }
 
        /* set rate */
-       ak4535_write(codec, AK4535_MODE2, mode2);
+       snd_soc_write(codec, AK4535_MODE2, mode2);
        return 0;
 }
 
@@ -348,44 +290,37 @@ static int ak4535_set_dai_fmt(struct snd_soc_dai *codec_dai,
        /* use 32 fs for BCLK to save power */
        mode1 |= 0x4;
 
-       ak4535_write(codec, AK4535_MODE1, mode1);
+       snd_soc_write(codec, AK4535_MODE1, mode1);
        return 0;
 }
 
 static int ak4535_mute(struct snd_soc_dai *dai, int mute)
 {
        struct snd_soc_codec *codec = dai->codec;
-       u16 mute_reg = ak4535_read_reg_cache(codec, AK4535_DAC);
+       u16 mute_reg = snd_soc_read(codec, AK4535_DAC);
        if (!mute)
-               ak4535_write(codec, AK4535_DAC, mute_reg & ~0x20);
+               snd_soc_write(codec, AK4535_DAC, mute_reg & ~0x20);
        else
-               ak4535_write(codec, AK4535_DAC, mute_reg | 0x20);
+               snd_soc_write(codec, AK4535_DAC, mute_reg | 0x20);
        return 0;
 }
 
 static int ak4535_set_bias_level(struct snd_soc_codec *codec,
        enum snd_soc_bias_level level)
 {
-       u16 i, mute_reg;
-
        switch (level) {
        case SND_SOC_BIAS_ON:
-               mute_reg = ak4535_read_reg_cache(codec, AK4535_DAC);
-               ak4535_write(codec, AK4535_DAC, mute_reg & ~0x20);
+               snd_soc_update_bits(codec, AK4535_DAC, 0x20, 0);
                break;
        case SND_SOC_BIAS_PREPARE:
-               mute_reg = ak4535_read_reg_cache(codec, AK4535_DAC);
-               ak4535_write(codec, AK4535_DAC, mute_reg | 0x20);
+               snd_soc_update_bits(codec, AK4535_DAC, 0x20, 0x20);
                break;
        case SND_SOC_BIAS_STANDBY:
-               i = ak4535_read_reg_cache(codec, AK4535_PM1);
-               ak4535_write(codec, AK4535_PM1, i | 0x80);
-               i = ak4535_read_reg_cache(codec, AK4535_PM2);
-               ak4535_write(codec, AK4535_PM2, i & (~0x80));
+               snd_soc_update_bits(codec, AK4535_PM1, 0x80, 0x80);
+               snd_soc_update_bits(codec, AK4535_PM2, 0x80, 0);
                break;
        case SND_SOC_BIAS_OFF:
-               i = ak4535_read_reg_cache(codec, AK4535_PM1);
-               ak4535_write(codec, AK4535_PM1, i & (~0x80));
+               snd_soc_update_bits(codec, AK4535_PM1, 0x80, 0);
                break;
        }
        codec->dapm.bias_level = level;
@@ -428,7 +363,7 @@ static int ak4535_suspend(struct snd_soc_codec *codec, pm_message_t state)
 
 static int ak4535_resume(struct snd_soc_codec *codec)
 {
-       ak4535_sync(codec);
+       snd_soc_cache_sync(codec);
        ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
        return 0;
 }
@@ -436,11 +371,15 @@ static int ak4535_resume(struct snd_soc_codec *codec)
 static int ak4535_probe(struct snd_soc_codec *codec)
 {
        struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec);
+       int ret;
 
        printk(KERN_INFO "AK4535 Audio Codec %s", AK4535_VERSION);
 
-       codec->control_data = ak4535->control_data;
-
+       ret = snd_soc_codec_set_cache_io(codec, 8, 8, ak4535->control_type);
+       if (ret < 0) {
+               dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
+               return ret;
+       }
        /* power on device */
        ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
@@ -461,8 +400,6 @@ static struct snd_soc_codec_driver soc_codec_dev_ak4535 = {
        .remove =       ak4535_remove,
        .suspend =      ak4535_suspend,
        .resume =       ak4535_resume,
-       .read = ak4535_read_reg_cache,
-       .write = ak4535_write,
        .set_bias_level = ak4535_set_bias_level,
        .reg_cache_size = ARRAY_SIZE(ak4535_reg),
        .reg_word_size = sizeof(u8),
@@ -485,7 +422,6 @@ static __devinit int ak4535_i2c_probe(struct i2c_client *i2c,
                return -ENOMEM;
 
        i2c_set_clientdata(i2c, ak4535);
-       ak4535->control_data = i2c;
        ak4535->control_type = SND_SOC_I2C;
 
        ret = snd_soc_register_codec(&i2c->dev,
index 7a64e58cddc4bb4d83472a2e7f8914d7eed3afd0..77838586f3588ffc61960f70cfaea2a29b6bfccf 100644 (file)
@@ -31,7 +31,6 @@
 
 /* codec private data */
 struct ak4641_priv {
-       struct snd_soc_codec *codec;
        unsigned int sysclk;
        int deemph;
        int playback_fs;
@@ -226,7 +225,7 @@ static const struct snd_soc_dapm_widget ak4641_dapm_widgets[] = {
        SND_SOC_DAPM_PGA("Mono Out 2", AK4641_PM2, 3, 0, NULL, 0),
 
        SND_SOC_DAPM_ADC("Voice ADC", "Voice Capture", AK4641_BTIF, 0, 0),
-       SND_SOC_DAPM_ADC("Voice DAC", "Voice Playback", AK4641_BTIF, 1, 0),
+       SND_SOC_DAPM_DAC("Voice DAC", "Voice Playback", AK4641_BTIF, 1, 0),
 
        SND_SOC_DAPM_MICBIAS("Mic Int Bias", AK4641_MIC, 3, 0),
        SND_SOC_DAPM_MICBIAS("Mic Ext Bias", AK4641_MIC, 4, 0),
index 65f46047b1cbd21d0d9441966ae6ceb6c5c6120e..d8fc04486abbf31546d4da99f46d5b2cd916fc5a 100644 (file)
@@ -156,81 +156,22 @@ static const struct snd_kcontrol_new ak4642_snd_controls[] = {
 struct ak4642_priv {
        unsigned int sysclk;
        enum snd_soc_control_type control_type;
-       void *control_data;
 };
 
 /*
  * ak4642 register cache
  */
-static const u16 ak4642_reg[AK4642_CACHEREGNUM] = {
-       0x0000, 0x0000, 0x0001, 0x0000,
-       0x0002, 0x0000, 0x0000, 0x0000,
-       0x00e1, 0x00e1, 0x0018, 0x0000,
-       0x00e1, 0x0018, 0x0011, 0x0008,
-       0x0000, 0x0000, 0x0000, 0x0000,
-       0x0000, 0x0000, 0x0000, 0x0000,
-       0x0000, 0x0000, 0x0000, 0x0000,
-       0x0000, 0x0000, 0x0000, 0x0000,
-       0x0000, 0x0000, 0x0000, 0x0000,
-       0x0000,
-};
-
-/*
- * read ak4642 register cache
- */
-static inline unsigned int ak4642_read_reg_cache(struct snd_soc_codec *codec,
-       unsigned int reg)
-{
-       u16 *cache = codec->reg_cache;
-       if (reg >= AK4642_CACHEREGNUM)
-               return -1;
-       return cache[reg];
-}
-
-/*
- * write ak4642 register cache
- */
-static inline void ak4642_write_reg_cache(struct snd_soc_codec *codec,
-       u16 reg, unsigned int value)
-{
-       u16 *cache = codec->reg_cache;
-       if (reg >= AK4642_CACHEREGNUM)
-               return;
-
-       cache[reg] = value;
-}
-
-/*
- * write to the AK4642 register space
- */
-static int ak4642_write(struct snd_soc_codec *codec, unsigned int reg,
-       unsigned int value)
-{
-       u8 data[2];
-
-       /* data is
-        *   D15..D8 AK4642 register offset
-        *   D7...D0 register data
-        */
-       data[0] = reg & 0xff;
-       data[1] = value & 0xff;
-
-       if (codec->hw_write(codec->control_data, data, 2) == 2) {
-               ak4642_write_reg_cache(codec, reg, value);
-               return 0;
-       } else
-               return -EIO;
-}
-
-static int ak4642_sync(struct snd_soc_codec *codec)
-{
-       u16 *cache = codec->reg_cache;
-       int i, r = 0;
-
-       for (i = 0; i < AK4642_CACHEREGNUM; i++)
-               r |= ak4642_write(codec, i, cache[i]);
-
-       return r;
+static const u8 ak4642_reg[AK4642_CACHEREGNUM] = {
+       0x00, 0x00, 0x01, 0x00,
+       0x02, 0x00, 0x00, 0x00,
+       0xe1, 0xe1, 0x18, 0x00,
+       0xe1, 0x18, 0x11, 0x08,
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00,
+       0x00,
 };
 
 static int ak4642_dai_startup(struct snd_pcm_substream *substream,
@@ -252,8 +193,8 @@ static int ak4642_dai_startup(struct snd_pcm_substream *substream,
                 */
                snd_soc_update_bits(codec, MD_CTL4, DACH, DACH);
                snd_soc_update_bits(codec, MD_CTL3, BST1, BST1);
-               ak4642_write(codec, L_IVC, 0x91); /* volume */
-               ak4642_write(codec, R_IVC, 0x91); /* volume */
+               snd_soc_write(codec, L_IVC, 0x91); /* volume */
+               snd_soc_write(codec, R_IVC, 0x91); /* volume */
                snd_soc_update_bits(codec, PW_MGMT1, PMVCM | PMMIN | PMDAC,
                                                     PMVCM | PMMIN | PMDAC);
                snd_soc_update_bits(codec, PW_MGMT2, PMHP_MASK, PMHP);
@@ -272,9 +213,9 @@ static int ak4642_dai_startup(struct snd_pcm_substream *substream,
                 * This operation came from example code of
                 * "ASAHI KASEI AK4642" (japanese) manual p94.
                 */
-               ak4642_write(codec, SG_SL1, PMMP | MGAIN0);
-               ak4642_write(codec, TIMER, ZTM(0x3) | WTM(0x3));
-               ak4642_write(codec, ALC_CTL1, ALC | LMTH0);
+               snd_soc_write(codec, SG_SL1, PMMP | MGAIN0);
+               snd_soc_write(codec, TIMER, ZTM(0x3) | WTM(0x3));
+               snd_soc_write(codec, ALC_CTL1, ALC | LMTH0);
                snd_soc_update_bits(codec, PW_MGMT1, PMVCM | PMADL,
                                                     PMVCM | PMADL);
                snd_soc_update_bits(codec, PW_MGMT3, PMADR, PMADR);
@@ -462,7 +403,7 @@ static struct snd_soc_dai_driver ak4642_dai = {
 
 static int ak4642_resume(struct snd_soc_codec *codec)
 {
-       ak4642_sync(codec);
+       snd_soc_cache_sync(codec);
        return 0;
 }
 
@@ -470,11 +411,15 @@ static int ak4642_resume(struct snd_soc_codec *codec)
 static int ak4642_probe(struct snd_soc_codec *codec)
 {
        struct ak4642_priv *ak4642 = snd_soc_codec_get_drvdata(codec);
+       int ret;
 
        dev_info(codec->dev, "AK4642 Audio Codec %s", AK4642_VERSION);
 
-       codec->hw_write         = (hw_write_t)i2c_master_send;
-       codec->control_data     = ak4642->control_data;
+       ret = snd_soc_codec_set_cache_io(codec, 8, 8, ak4642->control_type);
+       if (ret < 0) {
+               dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
+               return ret;
+       }
 
        snd_soc_add_controls(codec, ak4642_snd_controls,
                             ARRAY_SIZE(ak4642_snd_controls));
@@ -485,8 +430,6 @@ static int ak4642_probe(struct snd_soc_codec *codec)
 static struct snd_soc_codec_driver soc_codec_dev_ak4642 = {
        .probe                  = ak4642_probe,
        .resume                 = ak4642_resume,
-       .read                   = ak4642_read_reg_cache,
-       .write                  = ak4642_write,
        .reg_cache_size         = ARRAY_SIZE(ak4642_reg),
        .reg_word_size          = sizeof(u8),
        .reg_cache_default      = ak4642_reg,
@@ -504,7 +447,6 @@ static __devinit int ak4642_i2c_probe(struct i2c_client *i2c,
                return -ENOMEM;
 
        i2c_set_clientdata(i2c, ak4642);
-       ak4642->control_data = i2c;
        ak4642->control_type = SND_SOC_I2C;
 
        ret =  snd_soc_register_codec(&i2c->dev,
index 88b29f8c748bf09a1908ecad84b088a6dd6c270f..de9ff66d3721d5dd367b2fc3f60178d9d5ee9e7c 100644 (file)
@@ -26,7 +26,6 @@
 /* codec private data */
 struct ak4671_priv {
        enum snd_soc_control_type control_type;
-       void *control_data;
 };
 
 /* ak4671 register cache & default register settings */
@@ -169,18 +168,15 @@ static int ak4671_out2_event(struct snd_soc_dapm_widget *w,
                struct snd_kcontrol *kcontrol, int event)
 {
        struct snd_soc_codec *codec = w->codec;
-       u8 reg;
 
        switch (event) {
        case SND_SOC_DAPM_POST_PMU:
-               reg = snd_soc_read(codec, AK4671_LOUT2_POWER_MANAGERMENT);
-               reg |= AK4671_MUTEN;
-               snd_soc_write(codec, AK4671_LOUT2_POWER_MANAGERMENT, reg);
+               snd_soc_update_bits(codec, AK4671_LOUT2_POWER_MANAGERMENT,
+                                   AK4671_MUTEN, AK4671_MUTEN);
                break;
        case SND_SOC_DAPM_PRE_PMD:
-               reg = snd_soc_read(codec, AK4671_LOUT2_POWER_MANAGERMENT);
-               reg &= ~AK4671_MUTEN;
-               snd_soc_write(codec, AK4671_LOUT2_POWER_MANAGERMENT, reg);
+               snd_soc_update_bits(codec, AK4671_LOUT2_POWER_MANAGERMENT,
+                                   AK4671_MUTEN, 0);
                break;
        }
 
@@ -576,15 +572,12 @@ static int ak4671_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
 static int ak4671_set_bias_level(struct snd_soc_codec *codec,
                enum snd_soc_bias_level level)
 {
-       u8 reg;
-
        switch (level) {
        case SND_SOC_BIAS_ON:
        case SND_SOC_BIAS_PREPARE:
        case SND_SOC_BIAS_STANDBY:
-               reg = snd_soc_read(codec, AK4671_AD_DA_POWER_MANAGEMENT);
-               snd_soc_write(codec, AK4671_AD_DA_POWER_MANAGEMENT,
-                               reg | AK4671_PMVCM);
+               snd_soc_update_bits(codec, AK4671_AD_DA_POWER_MANAGEMENT,
+                                   AK4671_PMVCM, AK4671_PMVCM);
                break;
        case SND_SOC_BIAS_OFF:
                snd_soc_write(codec, AK4671_AD_DA_POWER_MANAGEMENT, 0x00);
@@ -629,8 +622,6 @@ static int ak4671_probe(struct snd_soc_codec *codec)
        struct ak4671_priv *ak4671 = snd_soc_codec_get_drvdata(codec);
        int ret;
 
-       codec->hw_write = (hw_write_t)i2c_master_send;
-
        ret = snd_soc_codec_set_cache_io(codec, 8, 8, ak4671->control_type);
        if (ret < 0) {
                dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
@@ -675,7 +666,6 @@ static int __devinit ak4671_i2c_probe(struct i2c_client *client,
                return -ENOMEM;
 
        i2c_set_clientdata(client, ak4671);
-       ak4671->control_data = client;
        ak4671->control_type = SND_SOC_I2C;
 
        ret = snd_soc_register_codec(&client->dev,
index eecffb5489476dff195d04a9061fae68d37af638..984b14bcb6054bfbaa3d5f84ac7d60613d0f5c2c 100644 (file)
@@ -40,8 +40,6 @@ MODULE_PARM_DESC(caps_charge, "ALC5623 cap charge time (msecs)");
 /* codec private data */
 struct alc5623_priv {
        enum snd_soc_control_type control_type;
-       void *control_data;
-       struct mutex mutex;
        u8 id;
        unsigned int sysclk;
        u16 reg_cache[ALC5623_VENDOR_ID2+2];
@@ -55,8 +53,10 @@ static void alc5623_fill_cache(struct snd_soc_codec *codec)
        u16 *cache = codec->reg_cache;
 
        /* not really efficient ... */
+       codec->cache_bypass = 1;
        for (i = 0 ; i < codec->driver->reg_cache_size ; i += step)
-               cache[i] = codec->hw_read(codec, i);
+               cache[i] = snd_soc_read(codec, i);
+       codec->cache_bypass = 0;
 }
 
 static inline int alc5623_reset(struct snd_soc_codec *codec)
@@ -1050,9 +1050,7 @@ static int alc5623_i2c_probe(struct i2c_client *client,
        }
 
        i2c_set_clientdata(client, alc5623);
-       alc5623->control_data = client;
        alc5623->control_type = SND_SOC_I2C;
-       mutex_init(&alc5623->mutex);
 
        ret =  snd_soc_register_codec(&client->dev,
                &soc_codec_device_alc5623, &alc5623_dai, 1);
index 6cc8678f49f3b11d31453dcffd35b8ac8a430a8e..f1f237ecec2a6c43dcdf9ee31b72da7f0cdecff6 100644 (file)
@@ -128,7 +128,6 @@ static const char *supply_names[] = {
 /* Private data for the CS4270 */
 struct cs4270_private {
        enum snd_soc_control_type control_type;
-       void *control_data;
        unsigned int mclk; /* Input frequency of the MCLK pin */
        unsigned int mode; /* The mode (I2S or left-justified) */
        unsigned int slave_mode;
@@ -262,7 +261,6 @@ static int cs4270_set_dai_fmt(struct snd_soc_dai *codec_dai,
 {
        struct snd_soc_codec *codec = codec_dai->codec;
        struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
-       int ret = 0;
 
        /* set DAI format */
        switch (format & SND_SOC_DAIFMT_FORMAT_MASK) {
@@ -272,7 +270,7 @@ static int cs4270_set_dai_fmt(struct snd_soc_dai *codec_dai,
                break;
        default:
                dev_err(codec->dev, "invalid dai format\n");
-               ret = -EINVAL;
+               return -EINVAL;
        }
 
        /* set master/slave audio interface */
@@ -285,10 +283,11 @@ static int cs4270_set_dai_fmt(struct snd_soc_dai *codec_dai,
                break;
        default:
                /* all other modes are unsupported by the hardware */
-               ret = -EINVAL;
+               dev_err(codec->dev, "Unknown master/slave configuration\n");
+               return -EINVAL;
        }
 
-       return ret;
+       return 0;
 }
 
 /**
@@ -490,8 +489,6 @@ static int cs4270_probe(struct snd_soc_codec *codec)
        struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
        int i, ret;
 
-       codec->control_data = cs4270->control_data;
-
        /* Tell ASoC what kind of I/O to use to read the registers.  ASoC will
         * then do the I2C transactions itself.
         */
@@ -604,7 +601,7 @@ static int cs4270_soc_suspend(struct snd_soc_codec *codec, pm_message_t mesg)
 static int cs4270_soc_resume(struct snd_soc_codec *codec)
 {
        struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
-       struct i2c_client *i2c_client = codec->control_data;
+       struct i2c_client *i2c_client = to_i2c_client(codec->dev);
        int reg;
 
        regulator_bulk_enable(ARRAY_SIZE(cs4270->supplies),
@@ -690,7 +687,6 @@ static int cs4270_i2c_probe(struct i2c_client *i2c_client,
        }
 
        i2c_set_clientdata(i2c_client, cs4270);
-       cs4270->control_data = i2c_client;
        cs4270->control_type = SND_SOC_I2C;
 
        ret = snd_soc_register_codec(&i2c_client->dev,
index 083aab96ca80d33745aa651ac4438c872b9a2af8..23d1bd5dadda36185e2c56702e7fd17a739f9a1a 100644 (file)
@@ -156,7 +156,6 @@ static const u8 cs4271_dflt_reg[CS4271_NR_REGS] = {
 struct cs4271_private {
        /* SND_SOC_I2C or SND_SOC_SPI */
        enum snd_soc_control_type       bus_type;
-       void                            *control_data;
        unsigned int                    mclk;
        bool                            master;
        bool                            deemph;
@@ -466,8 +465,6 @@ static int cs4271_probe(struct snd_soc_codec *codec)
        int ret;
        int gpio_nreset = -EINVAL;
 
-       codec->control_data = cs4271->control_data;
-
        if (cs4271plat && gpio_is_valid(cs4271plat->gpio_nreset))
                gpio_nreset = cs4271plat->gpio_nreset;
 
@@ -555,7 +552,6 @@ static int __devinit cs4271_spi_probe(struct spi_device *spi)
                return -ENOMEM;
 
        spi_set_drvdata(spi, cs4271);
-       cs4271->control_data = spi;
        cs4271->bus_type = SND_SOC_SPI;
 
        return snd_soc_register_codec(&spi->dev, &soc_codec_dev_cs4271,
@@ -595,7 +591,6 @@ static int __devinit cs4271_i2c_probe(struct i2c_client *client,
                return -ENOMEM;
 
        i2c_set_clientdata(client, cs4271);
-       cs4271->control_data = client;
        cs4271->bus_type = SND_SOC_I2C;
 
        return snd_soc_register_codec(&client->dev, &soc_codec_dev_cs4271,
index 8fb7070108dd8fddfd3b8d1998f3a3461730208e..8c3c8205d19e99016e47b1564aa58cbdf91b0bab 100644 (file)
@@ -42,7 +42,6 @@ enum master_slave_mode {
 
 struct cs42l51_private {
        enum snd_soc_control_type control_type;
-       void *control_data;
        unsigned int mclk;
        unsigned int audio_mode;        /* The mode (I2S or left-justified) */
        enum master_slave_mode func;
@@ -57,7 +56,7 @@ struct cs42l51_private {
 static int cs42l51_fill_cache(struct snd_soc_codec *codec)
 {
        u8 *cache = codec->reg_cache + 1;
-       struct i2c_client *i2c_client = codec->control_data;
+       struct i2c_client *i2c_client = to_i2c_client(codec->dev);
        s32 length;
 
        length = i2c_smbus_read_i2c_block_data(i2c_client,
@@ -289,7 +288,6 @@ static int cs42l51_set_dai_fmt(struct snd_soc_dai *codec_dai,
 {
        struct snd_soc_codec *codec = codec_dai->codec;
        struct cs42l51_private *cs42l51 = snd_soc_codec_get_drvdata(codec);
-       int ret = 0;
 
        switch (format & SND_SOC_DAIFMT_FORMAT_MASK) {
        case SND_SOC_DAIFMT_I2S:
@@ -299,7 +297,7 @@ static int cs42l51_set_dai_fmt(struct snd_soc_dai *codec_dai,
                break;
        default:
                dev_err(codec->dev, "invalid DAI format\n");
-               ret = -EINVAL;
+               return -EINVAL;
        }
 
        switch (format & SND_SOC_DAIFMT_MASTER_MASK) {
@@ -310,11 +308,11 @@ static int cs42l51_set_dai_fmt(struct snd_soc_dai *codec_dai,
                cs42l51->func = MODE_SLAVE_AUTO;
                break;
        default:
-               ret = -EINVAL;
-               break;
+               dev_err(codec->dev, "Unknown master/slave configuration\n");
+               return -EINVAL;
        }
 
-       return ret;
+       return 0;
 }
 
 struct cs42l51_ratios {
@@ -520,8 +518,6 @@ static int cs42l51_probe(struct snd_soc_codec *codec)
        struct snd_soc_dapm_context *dapm = &codec->dapm;
        int ret, reg;
 
-       codec->control_data = cs42l51->control_data;
-
        ret = cs42l51_fill_cache(codec);
        if (ret < 0) {
                dev_err(codec->dev, "failed to fill register cache\n");
@@ -593,7 +589,6 @@ static int cs42l51_i2c_probe(struct i2c_client *i2c_client,
        }
 
        i2c_set_clientdata(i2c_client, cs42l51);
-       cs42l51->control_data = i2c_client;
        cs42l51->control_type = SND_SOC_I2C;
 
        ret =  snd_soc_register_codec(&i2c_client->dev,
index 92fd9d7a92211a06d2417066b0ea00916ab718f9..0ebcbd534490c7ac7d7ab10921e6278aea55befa 100644 (file)
 #include <sound/tlv.h>
 
 /* DA7210 register space */
+#define DA7210_CONTROL                 0x01
 #define DA7210_STATUS                  0x02
 #define DA7210_STARTUP1                        0x03
+#define DA7210_STARTUP2                        0x04
+#define DA7210_STARTUP3                        0x05
 #define DA7210_MIC_L                   0x07
 #define DA7210_MIC_R                   0x08
+#define DA7210_AUX1_L                  0x09
+#define DA7210_AUX1_R                  0x0A
+#define DA7210_AUX2                    0x0B
+#define DA7210_IN_GAIN                 0x0C
 #define DA7210_INMIX_L                 0x0D
 #define DA7210_INMIX_R                 0x0E
 #define DA7210_ADC_HPF                 0x0F
 #define DA7210_ADC                     0x10
+#define DA7210_ADC_EQ1_2               0X11
+#define DA7210_ADC_EQ3_4               0x12
+#define DA7210_ADC_EQ5                 0x13
 #define DA7210_DAC_HPF                 0x14
 #define DA7210_DAC_L                   0x15
 #define DA7210_DAC_R                   0x16
 #define DA7210_DAC_SEL                 0x17
+#define DA7210_SOFTMUTE                        0x18
+#define DA7210_DAC_EQ1_2               0x19
+#define DA7210_DAC_EQ3_4               0x1A
+#define DA7210_DAC_EQ5                 0x1B
 #define DA7210_OUTMIX_L                        0x1C
 #define DA7210_OUTMIX_R                        0x1D
+#define DA7210_OUT1_L                  0x1E
+#define DA7210_OUT1_R                  0x1F
+#define DA7210_OUT2                    0x20
 #define DA7210_HP_L_VOL                        0x21
 #define DA7210_HP_R_VOL                        0x22
 #define DA7210_HP_CFG                  0x23
+#define DA7210_ZERO_CROSS              0x24
 #define DA7210_DAI_SRC_SEL             0x25
 #define DA7210_DAI_CFG1                        0x26
 #define DA7210_DAI_CFG3                        0x28
 #define DA7210_PLL_DIV2                        0x2A
 #define DA7210_PLL_DIV3                        0x2B
 #define DA7210_PLL                     0x2C
+#define DA7210_ALC_MAX                 0x83
+#define DA7210_ALC_MIN                 0x84
+#define DA7210_ALC_NOIS                        0x85
+#define DA7210_ALC_ATT                 0x86
+#define DA7210_ALC_REL                 0x87
+#define DA7210_ALC_DEL                 0x88
 #define DA7210_A_HID_UNLOCK            0x8A
 #define DA7210_A_TEST_UNLOCK           0x8B
 #define DA7210_A_PLL1                  0x90
@@ -72,6 +96,7 @@
 #define DA7210_IN_R_EN                 (1 << 7)
 
 /* ADC bit fields */
+#define DA7210_ADC_ALC_EN              (1 << 0)
 #define DA7210_ADC_L_EN                        (1 << 3)
 #define DA7210_ADC_R_EN                        (1 << 7)
 
 
 /* DAI_CFG1 bit fields */
 #define DA7210_DAI_WORD_S16_LE         (0 << 0)
+#define DA7210_DAI_WORD_S20_3LE                (1 << 0)
 #define DA7210_DAI_WORD_S24_LE         (2 << 0)
+#define DA7210_DAI_WORD_S32_LE         (3 << 0)
 #define DA7210_DAI_FLEN_64BIT          (1 << 2)
+#define DA7210_DAI_MODE_SLAVE          (0 << 7)
 #define DA7210_DAI_MODE_MASTER         (1 << 7)
 
 /* DAI_CFG3 bit fields */
 #define DA7210_DAI_FORMAT_I2SMODE      (0 << 0)
+#define DA7210_DAI_FORMAT_LEFT_J       (1 << 0)
+#define DA7210_DAI_FORMAT_RIGHT_J      (2 << 0)
 #define DA7210_DAI_OE                  (1 << 3)
 #define DA7210_DAI_EN                  (1 << 7)
 
 #define DA7210_PLL_FS_96000            (0xF << 0)
 #define DA7210_PLL_EN                  (0x1 << 7)
 
+/* SOFTMUTE bit fields */
+#define DA7210_RAMP_EN                 (1 << 6)
+
+/* CONTROL bit fields */
+#define DA7210_NOISE_SUP_EN            (1 << 3)
+
+/* IN_GAIN bit fields */
+#define DA7210_INPGA_L_VOL             (0x0F << 0)
+#define DA7210_INPGA_R_VOL             (0xF0 << 0)
+
+/* ZERO_CROSS bit fields */
+#define DA7210_AUX1_L_ZC               (1 << 0)
+#define DA7210_AUX1_R_ZC               (1 << 1)
+#define DA7210_HP_L_ZC                 (1 << 6)
+#define DA7210_HP_R_ZC                 (1 << 7)
+
+/* AUX1_L bit fields */
+#define DA7210_AUX1_L_VOL              (0x3F << 0)
+
+/* AUX1_R bit fields */
+#define DA7210_AUX1_R_VOL              (0x3F << 0)
+
+/* Minimum INPGA and AUX1 volume to enable noise suppression */
+#define DA7210_INPGA_MIN_VOL_NS                0x0A  /* 10.5dB */
+#define DA7210_AUX1_MIN_VOL_NS         0x35  /* 6dB */
+
+/* OUT1_L bit fields */
+#define DA7210_OUT1_L_EN               (1 << 7)
+
+/* OUT1_R bit fields */
+#define DA7210_OUT1_R_EN               (1 << 7)
+
+/* OUT2 bit fields */
+#define DA7210_OUT2_OUTMIX_R           (1 << 5)
+#define DA7210_OUT2_OUTMIX_L           (1 << 6)
+#define DA7210_OUT2_EN                 (1 << 7)
+
 #define DA7210_VERSION "0.0.1"
 
 /*
  * mute                : 0x10
  * reserved    : 0x00 - 0x0F
  *
- * ** FIXME **
- *
  * Reserved area are considered as "mute".
- * -> min = -79.5 dB
  */
-static const DECLARE_TLV_DB_SCALE(hp_out_tlv, -7950, 150, 1);
+static const unsigned int hp_out_tlv[] = {
+       TLV_DB_RANGE_HEAD(2),
+       0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
+       /* -54 dB to +15 dB */
+       0x11, 0x3f, TLV_DB_SCALE_ITEM(-5400, 150, 0),
+};
+
+static const unsigned int lineout_vol_tlv[] = {
+       TLV_DB_RANGE_HEAD(2),
+       0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
+       /* -54dB to 15dB */
+       0x11, 0x3f, TLV_DB_SCALE_ITEM(-5400, 150, 0)
+};
+
+static const unsigned int mono_vol_tlv[] = {
+       TLV_DB_RANGE_HEAD(2),
+       0x0, 0x2, TLV_DB_SCALE_ITEM(-1800, 0, 1),
+       /* -18dB to 6dB */
+       0x3, 0x7, TLV_DB_SCALE_ITEM(-1800, 600, 0)
+};
+
+static const DECLARE_TLV_DB_SCALE(eq_gain_tlv, -1050, 150, 0);
+static const DECLARE_TLV_DB_SCALE(adc_eq_master_gain_tlv, -1800, 600, 1);
+static const DECLARE_TLV_DB_SCALE(dac_gain_tlv, -7725, 75, 0);
+
+/* ADC and DAC high pass filter f0 value */
+static const char const *da7210_hpf_cutoff_txt[] = {
+       "Fs/8192*pi", "Fs/4096*pi", "Fs/2048*pi", "Fs/1024*pi"
+};
+
+static const struct soc_enum da7210_dac_hpf_cutoff =
+       SOC_ENUM_SINGLE(DA7210_DAC_HPF, 0, 4, da7210_hpf_cutoff_txt);
+
+static const struct soc_enum da7210_adc_hpf_cutoff =
+       SOC_ENUM_SINGLE(DA7210_ADC_HPF, 0, 4, da7210_hpf_cutoff_txt);
+
+/* ADC and DAC voice (8kHz) high pass cutoff value */
+static const char const *da7210_vf_cutoff_txt[] = {
+       "2.5Hz", "25Hz", "50Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz"
+};
+
+static const struct soc_enum da7210_dac_vf_cutoff =
+       SOC_ENUM_SINGLE(DA7210_DAC_HPF, 4, 8, da7210_vf_cutoff_txt);
+
+static const struct soc_enum da7210_adc_vf_cutoff =
+       SOC_ENUM_SINGLE(DA7210_ADC_HPF, 4, 8, da7210_vf_cutoff_txt);
+
+static const char *da7210_hp_mode_txt[] = {
+       "Class H", "Class G"
+};
+
+static const struct soc_enum da7210_hp_mode_sel =
+       SOC_ENUM_SINGLE(DA7210_HP_CFG, 0, 2, da7210_hp_mode_txt);
+
+/* ALC can be enabled only if noise suppression is disabled */
+static int da7210_put_alc_sw(struct snd_kcontrol *kcontrol,
+                            struct snd_ctl_elem_value *ucontrol)
+{
+       struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+
+       if (ucontrol->value.integer.value[0]) {
+               /* Check if noise suppression is enabled */
+               if (snd_soc_read(codec, DA7210_CONTROL) & DA7210_NOISE_SUP_EN) {
+                       dev_dbg(codec->dev,
+                               "Disable noise suppression to enable ALC\n");
+                       return -EINVAL;
+               }
+       }
+       /* If all conditions are met or we are actually disabling ALC */
+       return snd_soc_put_volsw(kcontrol, ucontrol);
+}
+
+/* Noise suppression can be enabled only if following conditions are met
+ *  ALC disabled
+ *  ZC enabled for HP and AUX1 PGA
+ *  INPGA_L_VOL and INPGA_R_VOL >= 10.5 dB
+ *  AUX1_L_VOL and AUX1_R_VOL >= 6 dB
+ */
+static int da7210_put_noise_sup_sw(struct snd_kcontrol *kcontrol,
+                                  struct snd_ctl_elem_value *ucontrol)
+{
+       struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+       u8 val;
+
+       if (ucontrol->value.integer.value[0]) {
+               /* Check if ALC is enabled */
+               if (snd_soc_read(codec, DA7210_ADC) & DA7210_ADC_ALC_EN)
+                       goto err;
+
+               /* Check ZC for HP and AUX1 PGA */
+               if ((snd_soc_read(codec, DA7210_ZERO_CROSS) &
+                       (DA7210_AUX1_L_ZC | DA7210_AUX1_R_ZC | DA7210_HP_L_ZC |
+                       DA7210_HP_R_ZC)) != (DA7210_AUX1_L_ZC |
+                       DA7210_AUX1_R_ZC | DA7210_HP_L_ZC | DA7210_HP_R_ZC))
+                       goto err;
+
+               /* Check INPGA_L_VOL and INPGA_R_VOL */
+               val = snd_soc_read(codec, DA7210_IN_GAIN);
+               if (((val & DA7210_INPGA_L_VOL) < DA7210_INPGA_MIN_VOL_NS) ||
+                       (((val & DA7210_INPGA_R_VOL) >> 4) <
+                       DA7210_INPGA_MIN_VOL_NS))
+                       goto err;
+
+               /* Check AUX1_L_VOL and AUX1_R_VOL */
+               if (((snd_soc_read(codec, DA7210_AUX1_L) & DA7210_AUX1_L_VOL) <
+                   DA7210_AUX1_MIN_VOL_NS) ||
+                   ((snd_soc_read(codec, DA7210_AUX1_R) & DA7210_AUX1_R_VOL) <
+                   DA7210_AUX1_MIN_VOL_NS))
+                       goto err;
+       }
+       /* If all conditions are met or we are actually disabling Noise sup */
+       return snd_soc_put_volsw(kcontrol, ucontrol);
+
+err:
+       return -EINVAL;
+}
 
 static const struct snd_kcontrol_new da7210_snd_controls[] = {
 
        SOC_DOUBLE_R_TLV("HeadPhone Playback Volume",
                         DA7210_HP_L_VOL, DA7210_HP_R_VOL,
                         0, 0x3F, 0, hp_out_tlv),
+       SOC_DOUBLE_R_TLV("Digital Playback Volume",
+                        DA7210_DAC_L, DA7210_DAC_R,
+                        0, 0x77, 1, dac_gain_tlv),
+       SOC_DOUBLE_R_TLV("Lineout Playback Volume",
+                        DA7210_OUT1_L, DA7210_OUT1_R,
+                        0, 0x3f, 0, lineout_vol_tlv),
+       SOC_SINGLE_TLV("Mono Playback Volume", DA7210_OUT2, 0, 0x7, 0,
+                      mono_vol_tlv),
+
+       /* DAC Equalizer  controls */
+       SOC_SINGLE("DAC EQ Switch", DA7210_DAC_EQ5, 7, 1, 0),
+       SOC_SINGLE_TLV("DAC EQ1 Volume", DA7210_DAC_EQ1_2, 0, 0xf, 1,
+                      eq_gain_tlv),
+       SOC_SINGLE_TLV("DAC EQ2 Volume", DA7210_DAC_EQ1_2, 4, 0xf, 1,
+                      eq_gain_tlv),
+       SOC_SINGLE_TLV("DAC EQ3 Volume", DA7210_DAC_EQ3_4, 0, 0xf, 1,
+                      eq_gain_tlv),
+       SOC_SINGLE_TLV("DAC EQ4 Volume", DA7210_DAC_EQ3_4, 4, 0xf, 1,
+                      eq_gain_tlv),
+       SOC_SINGLE_TLV("DAC EQ5 Volume", DA7210_DAC_EQ5, 0, 0xf, 1,
+                      eq_gain_tlv),
+
+       /* ADC Equalizer  controls */
+       SOC_SINGLE("ADC EQ Switch", DA7210_ADC_EQ5, 7, 1, 0),
+       SOC_SINGLE_TLV("ADC EQ Master Volume", DA7210_ADC_EQ5, 4, 0x3,
+                      1, adc_eq_master_gain_tlv),
+       SOC_SINGLE_TLV("ADC EQ1 Volume", DA7210_ADC_EQ1_2, 0, 0xf, 1,
+                      eq_gain_tlv),
+       SOC_SINGLE_TLV("ADC EQ2 Volume", DA7210_ADC_EQ1_2, 4, 0xf, 1,
+                      eq_gain_tlv),
+       SOC_SINGLE_TLV("ADC EQ3 Volume", DA7210_ADC_EQ3_4, 0, 0xf, 1,
+                      eq_gain_tlv),
+       SOC_SINGLE_TLV("ADC EQ4 Volume", DA7210_ADC_EQ3_4, 4, 0xf, 1,
+                      eq_gain_tlv),
+       SOC_SINGLE_TLV("ADC EQ5 Volume", DA7210_ADC_EQ5, 0, 0xf, 1,
+                      eq_gain_tlv),
+
+       SOC_SINGLE("DAC HPF Switch", DA7210_DAC_HPF, 3, 1, 0),
+       SOC_ENUM("DAC HPF Cutoff", da7210_dac_hpf_cutoff),
+       SOC_SINGLE("DAC Voice Mode Switch", DA7210_DAC_HPF, 7, 1, 0),
+       SOC_ENUM("DAC Voice Cutoff", da7210_dac_vf_cutoff),
+
+       SOC_SINGLE("ADC HPF Switch", DA7210_ADC_HPF, 3, 1, 0),
+       SOC_ENUM("ADC HPF Cutoff", da7210_adc_hpf_cutoff),
+       SOC_SINGLE("ADC Voice Mode Switch", DA7210_ADC_HPF, 7, 1, 0),
+       SOC_ENUM("ADC Voice Cutoff", da7210_adc_vf_cutoff),
+
+       /* Mute controls */
+       SOC_DOUBLE_R("Mic Capture Switch", DA7210_MIC_L, DA7210_MIC_R, 3, 1, 0),
+       SOC_SINGLE("Aux2 Capture Switch", DA7210_AUX2, 2, 1, 0),
+       SOC_DOUBLE("ADC Capture Switch", DA7210_ADC, 2, 6, 1, 0),
+       SOC_SINGLE("Digital Soft Mute Switch", DA7210_SOFTMUTE, 7, 1, 0),
+       SOC_SINGLE("Digital Soft Mute Rate", DA7210_SOFTMUTE, 0, 0x7, 0),
+
+       /* Zero cross controls */
+       SOC_DOUBLE("Aux1 ZC Switch", DA7210_ZERO_CROSS, 0, 1, 1, 0),
+       SOC_DOUBLE("In PGA ZC Switch", DA7210_ZERO_CROSS, 2, 3, 1, 0),
+       SOC_DOUBLE("Lineout ZC Switch", DA7210_ZERO_CROSS, 4, 5, 1, 0),
+       SOC_DOUBLE("Headphone ZC Switch", DA7210_ZERO_CROSS, 6, 7, 1, 0),
+
+       SOC_ENUM("Headphone Class", da7210_hp_mode_sel),
+
+       /* ALC controls */
+       SOC_SINGLE_EXT("ALC Enable Switch", DA7210_ADC, 0, 1, 0,
+                      snd_soc_get_volsw, da7210_put_alc_sw),
+       SOC_SINGLE("ALC Capture Max Volume", DA7210_ALC_MAX, 0, 0x3F, 0),
+       SOC_SINGLE("ALC Capture Min Volume", DA7210_ALC_MIN, 0, 0x3F, 0),
+       SOC_SINGLE("ALC Capture Noise Volume", DA7210_ALC_NOIS, 0, 0x3F, 0),
+       SOC_SINGLE("ALC Capture Attack Rate", DA7210_ALC_ATT, 0, 0xFF, 0),
+       SOC_SINGLE("ALC Capture Release Rate", DA7210_ALC_REL, 0, 0xFF, 0),
+       SOC_SINGLE("ALC Capture Release Delay", DA7210_ALC_DEL, 0, 0xFF, 0),
+
+       SOC_SINGLE_EXT("Noise Suppression Enable Switch", DA7210_CONTROL, 3, 1,
+                      0, snd_soc_get_volsw, da7210_put_noise_sup_sw),
+};
+
+/*
+ * DAPM Controls
+ *
+ * Current DAPM implementation covers almost all codec components e.g. IOs,
+ * mixers, PGAs,ADC and DAC.
+ */
+/* In Mixer Left */
+static const struct snd_kcontrol_new da7210_dapm_inmixl_controls[] = {
+       SOC_DAPM_SINGLE("Mic Left Switch", DA7210_INMIX_L, 0, 1, 0),
+       SOC_DAPM_SINGLE("Mic Right Switch", DA7210_INMIX_L, 1, 1, 0),
+};
+
+/* In Mixer Right */
+static const struct snd_kcontrol_new da7210_dapm_inmixr_controls[] = {
+       SOC_DAPM_SINGLE("Mic Right Switch", DA7210_INMIX_R, 0, 1, 0),
+       SOC_DAPM_SINGLE("Mic Left Switch", DA7210_INMIX_R, 1, 1, 0),
+};
+
+/* Out Mixer Left */
+static const struct snd_kcontrol_new da7210_dapm_outmixl_controls[] = {
+       SOC_DAPM_SINGLE("DAC Left Switch", DA7210_OUTMIX_L, 4, 1, 0),
+};
+
+/* Out Mixer Right */
+static const struct snd_kcontrol_new da7210_dapm_outmixr_controls[] = {
+       SOC_DAPM_SINGLE("DAC Right Switch", DA7210_OUTMIX_R, 4, 1, 0),
+};
+
+/* Mono Mixer */
+static const struct snd_kcontrol_new da7210_dapm_monomix_controls[] = {
+       SOC_DAPM_SINGLE("Outmix Right Switch", DA7210_OUT2, 5, 1, 0),
+       SOC_DAPM_SINGLE("Outmix Left Switch", DA7210_OUT2, 6, 1, 0),
+};
+
+/* DAPM widgets */
+static const struct snd_soc_dapm_widget da7210_dapm_widgets[] = {
+       /* Input Side */
+       /* Input Lines */
+       SND_SOC_DAPM_INPUT("MICL"),
+       SND_SOC_DAPM_INPUT("MICR"),
+
+       /* Input PGAs */
+       SND_SOC_DAPM_PGA("Mic Left", DA7210_STARTUP3, 0, 1, NULL, 0),
+       SND_SOC_DAPM_PGA("Mic Right", DA7210_STARTUP3, 1, 1, NULL, 0),
+
+       SND_SOC_DAPM_PGA("INPGA Left", DA7210_INMIX_L, 7, 0, NULL, 0),
+       SND_SOC_DAPM_PGA("INPGA Right", DA7210_INMIX_R, 7, 0, NULL, 0),
+
+       /* Input Mixers */
+       SND_SOC_DAPM_MIXER("In Mixer Left", SND_SOC_NOPM, 0, 0,
+               &da7210_dapm_inmixl_controls[0],
+               ARRAY_SIZE(da7210_dapm_inmixl_controls)),
+
+       SND_SOC_DAPM_MIXER("In Mixer Right", SND_SOC_NOPM, 0, 0,
+               &da7210_dapm_inmixr_controls[0],
+               ARRAY_SIZE(da7210_dapm_inmixr_controls)),
+
+       /* ADCs */
+       SND_SOC_DAPM_ADC("ADC Left", "Capture", DA7210_STARTUP3, 5, 1),
+       SND_SOC_DAPM_ADC("ADC Right", "Capture", DA7210_STARTUP3, 6, 1),
+
+       /* Output Side */
+       /* DACs */
+       SND_SOC_DAPM_DAC("DAC Left", "Playback", DA7210_STARTUP2, 5, 1),
+       SND_SOC_DAPM_DAC("DAC Right", "Playback", DA7210_STARTUP2, 6, 1),
+
+       /* Output Mixers */
+       SND_SOC_DAPM_MIXER("Out Mixer Left", SND_SOC_NOPM, 0, 0,
+               &da7210_dapm_outmixl_controls[0],
+               ARRAY_SIZE(da7210_dapm_outmixl_controls)),
+
+       SND_SOC_DAPM_MIXER("Out Mixer Right", SND_SOC_NOPM, 0, 0,
+               &da7210_dapm_outmixr_controls[0],
+               ARRAY_SIZE(da7210_dapm_outmixr_controls)),
+
+       SND_SOC_DAPM_MIXER("Mono Mixer", SND_SOC_NOPM, 0, 0,
+               &da7210_dapm_monomix_controls[0],
+               ARRAY_SIZE(da7210_dapm_monomix_controls)),
+
+       /* Output PGAs */
+       SND_SOC_DAPM_PGA("OUTPGA Left Enable", DA7210_OUTMIX_L, 7, 0, NULL, 0),
+       SND_SOC_DAPM_PGA("OUTPGA Right Enable", DA7210_OUTMIX_R, 7, 0, NULL, 0),
+
+       SND_SOC_DAPM_PGA("Out1 Left", DA7210_STARTUP2, 0, 1, NULL, 0),
+       SND_SOC_DAPM_PGA("Out1 Right", DA7210_STARTUP2, 1, 1, NULL, 0),
+       SND_SOC_DAPM_PGA("Out2 Mono", DA7210_STARTUP2, 2, 1, NULL, 0),
+       SND_SOC_DAPM_PGA("Headphone Left", DA7210_STARTUP2, 3, 1, NULL, 0),
+       SND_SOC_DAPM_PGA("Headphone Right", DA7210_STARTUP2, 4, 1, NULL, 0),
+
+       /* Output Lines */
+       SND_SOC_DAPM_OUTPUT("OUT1L"),
+       SND_SOC_DAPM_OUTPUT("OUT1R"),
+       SND_SOC_DAPM_OUTPUT("HPL"),
+       SND_SOC_DAPM_OUTPUT("HPR"),
+       SND_SOC_DAPM_OUTPUT("OUT2"),
+};
+
+/* DAPM audio route definition */
+static const struct snd_soc_dapm_route da7210_audio_map[] = {
+       /* Dest       Connecting Widget    source */
+       /* Input path */
+       {"Mic Left", NULL, "MICL"},
+       {"Mic Right", NULL, "MICR"},
+
+       {"In Mixer Left", "Mic Left Switch", "Mic Left"},
+       {"In Mixer Left", "Mic Right Switch", "Mic Right"},
+
+       {"In Mixer Right", "Mic Right Switch", "Mic Right"},
+       {"In Mixer Right", "Mic Left Switch", "Mic Left"},
+
+       {"INPGA Left", NULL, "In Mixer Left"},
+       {"ADC Left", NULL, "INPGA Left"},
+
+       {"INPGA Right", NULL, "In Mixer Right"},
+       {"ADC Right", NULL, "INPGA Right"},
+
+       /* Output path */
+       {"Out Mixer Left", "DAC Left Switch", "DAC Left"},
+       {"Out Mixer Right", "DAC Right Switch", "DAC Right"},
+
+       {"Mono Mixer", "Outmix Right Switch", "Out Mixer Right"},
+       {"Mono Mixer", "Outmix Left Switch", "Out Mixer Left"},
+
+       {"OUTPGA Left Enable", NULL, "Out Mixer Left"},
+       {"OUTPGA Right Enable", NULL, "Out Mixer Right"},
+
+       {"Out1 Left", NULL, "OUTPGA Left Enable"},
+       {"OUT1L", NULL, "Out1 Left"},
+
+       {"Out1 Right", NULL, "OUTPGA Right Enable"},
+       {"OUT1R", NULL, "Out1 Right"},
+
+       {"Headphone Left", NULL, "OUTPGA Left Enable"},
+       {"HPL", NULL, "Headphone Left"},
+
+       {"Headphone Right", NULL, "OUTPGA Right Enable"},
+       {"HPR", NULL, "Headphone Right"},
+
+       {"Out2 Mono", NULL, "Mono Mixer"},
+       {"OUT2", NULL, "Out2 Mono"},
 };
 
 /* Codec private data */
 struct da7210_priv {
        enum snd_soc_control_type control_type;
-       void *control_data;
 };
 
 /*
@@ -188,72 +582,15 @@ static const u8 da7210_reg[] = {
        0x00,                                           /* R88       */
 };
 
-/*
- * Read da7210 register cache
- */
-static inline u32 da7210_read_reg_cache(struct snd_soc_codec *codec, u32 reg)
-{
-       u8 *cache = codec->reg_cache;
-       BUG_ON(reg >= ARRAY_SIZE(da7210_reg));
-       return cache[reg];
-}
-
-/*
- * Write to the da7210 register space
- */
-static int da7210_write(struct snd_soc_codec *codec, u32 reg, u32 value)
+static int da7210_volatile_register(struct snd_soc_codec *codec,
+                                   unsigned int reg)
 {
-       u8 *cache = codec->reg_cache;
-       u8 data[2];
-
-       BUG_ON(codec->driver->volatile_register);
-
-       data[0] = reg & 0xff;
-       data[1] = value & 0xff;
-
-       if (reg >= codec->driver->reg_cache_size)
-               return -EIO;
-
-       if (2 != codec->hw_write(codec->control_data, data, 2))
-               return -EIO;
-
-       cache[reg] = value;
-       return 0;
-}
-
-/*
- * Read from the da7210 register space.
- */
-static inline u32 da7210_read(struct snd_soc_codec *codec, u32 reg)
-{
-       if (DA7210_STATUS == reg)
-               return i2c_smbus_read_byte_data(codec->control_data, reg);
-
-       return da7210_read_reg_cache(codec, reg);
-}
-
-static int da7210_startup(struct snd_pcm_substream *substream,
-                         struct snd_soc_dai *dai)
-{
-       int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
-       struct snd_soc_codec *codec = dai->codec;
-
-       if (is_play) {
-               /* Enable Out */
-               snd_soc_update_bits(codec, DA7210_OUTMIX_L, 0x1F, 0x10);
-               snd_soc_update_bits(codec, DA7210_OUTMIX_R, 0x1F, 0x10);
-
-       } else {
-               /* Volume 7 */
-               snd_soc_update_bits(codec, DA7210_MIC_L, 0x7, 0x7);
-               snd_soc_update_bits(codec, DA7210_MIC_R, 0x7, 0x7);
-
-               /* Enable Mic */
-               snd_soc_update_bits(codec, DA7210_INMIX_L, 0x1F, 0x1);
-               snd_soc_update_bits(codec, DA7210_INMIX_R, 0x1F, 0x1);
+       switch (reg) {
+       case DA7210_STATUS:
+               return 1;
+       default:
+               return 0;
        }
-
-       return 0;
 }
 
 /*
@@ -266,93 +603,75 @@ static int da7210_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_codec *codec = rtd->codec;
        u32 dai_cfg1;
-       u32 hpf_reg, hpf_mask, hpf_value;
        u32 fs, bypass;
 
        /* set DAI source to Left and Right ADC */
-       da7210_write(codec, DA7210_DAI_SRC_SEL,
+       snd_soc_write(codec, DA7210_DAI_SRC_SEL,
                     DA7210_DAI_OUT_R_SRC | DA7210_DAI_OUT_L_SRC);
 
        /* Enable DAI */
-       da7210_write(codec, DA7210_DAI_CFG3, DA7210_DAI_OE | DA7210_DAI_EN);
+       snd_soc_write(codec, DA7210_DAI_CFG3, DA7210_DAI_OE | DA7210_DAI_EN);
 
-       dai_cfg1 = 0xFC & da7210_read(codec, DA7210_DAI_CFG1);
+       dai_cfg1 = 0xFC & snd_soc_read(codec, DA7210_DAI_CFG1);
 
        switch (params_format(params)) {
        case SNDRV_PCM_FORMAT_S16_LE:
                dai_cfg1 |= DA7210_DAI_WORD_S16_LE;
                break;
+       case SNDRV_PCM_FORMAT_S20_3LE:
+               dai_cfg1 |= DA7210_DAI_WORD_S20_3LE;
+               break;
        case SNDRV_PCM_FORMAT_S24_LE:
                dai_cfg1 |= DA7210_DAI_WORD_S24_LE;
                break;
+       case SNDRV_PCM_FORMAT_S32_LE:
+               dai_cfg1 |= DA7210_DAI_WORD_S32_LE;
+               break;
        default:
                return -EINVAL;
        }
 
-       da7210_write(codec, DA7210_DAI_CFG1, dai_cfg1);
-
-       hpf_reg = (SNDRV_PCM_STREAM_PLAYBACK == substream->stream) ?
-               DA7210_DAC_HPF : DA7210_ADC_HPF;
+       snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1);
 
        switch (params_rate(params)) {
        case 8000:
                fs              = DA7210_PLL_FS_8000;
-               hpf_mask        = DA7210_VOICE_F0_MASK  | DA7210_VOICE_EN;
-               hpf_value       = DA7210_VOICE_F0_25    | DA7210_VOICE_EN;
                bypass          = DA7210_PLL_BYP;
                break;
        case 11025:
                fs              = DA7210_PLL_FS_11025;
-               hpf_mask        = DA7210_VOICE_F0_MASK  | DA7210_VOICE_EN;
-               hpf_value       = DA7210_VOICE_F0_25    | DA7210_VOICE_EN;
                bypass          = 0;
                break;
        case 12000:
                fs              = DA7210_PLL_FS_12000;
-               hpf_mask        = DA7210_VOICE_F0_MASK  | DA7210_VOICE_EN;
-               hpf_value       = DA7210_VOICE_F0_25    | DA7210_VOICE_EN;
                bypass          = DA7210_PLL_BYP;
                break;
        case 16000:
                fs              = DA7210_PLL_FS_16000;
-               hpf_mask        = DA7210_VOICE_F0_MASK  | DA7210_VOICE_EN;
-               hpf_value       = DA7210_VOICE_F0_25    | DA7210_VOICE_EN;
                bypass          = DA7210_PLL_BYP;
                break;
        case 22050:
                fs              = DA7210_PLL_FS_22050;
-               hpf_mask        = DA7210_VOICE_EN;
-               hpf_value       = 0;
                bypass          = 0;
                break;
        case 32000:
                fs              = DA7210_PLL_FS_32000;
-               hpf_mask        = DA7210_VOICE_EN;
-               hpf_value       = 0;
                bypass          = DA7210_PLL_BYP;
                break;
        case 44100:
                fs              = DA7210_PLL_FS_44100;
-               hpf_mask        = DA7210_VOICE_EN;
-               hpf_value       = 0;
                bypass          = 0;
                break;
        case 48000:
                fs              = DA7210_PLL_FS_48000;
-               hpf_mask        = DA7210_VOICE_EN;
-               hpf_value       = 0;
                bypass          = DA7210_PLL_BYP;
                break;
        case 88200:
                fs              = DA7210_PLL_FS_88200;
-               hpf_mask        = DA7210_VOICE_EN;
-               hpf_value       = 0;
                bypass          = 0;
                break;
        case 96000:
                fs              = DA7210_PLL_FS_96000;
-               hpf_mask        = DA7210_VOICE_EN;
-               hpf_value       = 0;
                bypass          = DA7210_PLL_BYP;
                break;
        default:
@@ -362,7 +681,6 @@ static int da7210_hw_params(struct snd_pcm_substream *substream,
        /* Disable active mode */
        snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, 0);
 
-       snd_soc_update_bits(codec, hpf_reg, hpf_mask, hpf_value);
        snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_FS_MASK, fs);
        snd_soc_update_bits(codec, DA7210_PLL_DIV3, DA7210_PLL_BYP, bypass);
 
@@ -382,13 +700,16 @@ static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt)
        u32 dai_cfg1;
        u32 dai_cfg3;
 
-       dai_cfg1 = 0x7f & da7210_read(codec, DA7210_DAI_CFG1);
-       dai_cfg3 = 0xfc & da7210_read(codec, DA7210_DAI_CFG3);
+       dai_cfg1 = 0x7f & snd_soc_read(codec, DA7210_DAI_CFG1);
+       dai_cfg3 = 0xfc & snd_soc_read(codec, DA7210_DAI_CFG3);
 
        switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
        case SND_SOC_DAIFMT_CBM_CFM:
                dai_cfg1 |= DA7210_DAI_MODE_MASTER;
                break;
+       case SND_SOC_DAIFMT_CBS_CFS:
+               dai_cfg1 |= DA7210_DAI_MODE_SLAVE;
+               break;
        default:
                return -EINVAL;
        }
@@ -401,6 +722,12 @@ static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt)
        case SND_SOC_DAIFMT_I2S:
                dai_cfg3 |= DA7210_DAI_FORMAT_I2SMODE;
                break;
+       case SND_SOC_DAIFMT_LEFT_J:
+               dai_cfg3 |= DA7210_DAI_FORMAT_LEFT_J;
+               break;
+       case SND_SOC_DAIFMT_RIGHT_J:
+               dai_cfg3 |= DA7210_DAI_FORMAT_RIGHT_J;
+               break;
        default:
                return -EINVAL;
        }
@@ -411,19 +738,32 @@ static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt)
         */
        dai_cfg1 |= DA7210_DAI_FLEN_64BIT;
 
-       da7210_write(codec, DA7210_DAI_CFG1, dai_cfg1);
-       da7210_write(codec, DA7210_DAI_CFG3, dai_cfg3);
+       snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1);
+       snd_soc_write(codec, DA7210_DAI_CFG3, dai_cfg3);
+
+       return 0;
+}
+
+static int da7210_mute(struct snd_soc_dai *dai, int mute)
+{
+       struct snd_soc_codec *codec = dai->codec;
+       u8 mute_reg = snd_soc_read(codec, DA7210_DAC_HPF) & 0xFB;
 
+       if (mute)
+               snd_soc_write(codec, DA7210_DAC_HPF, mute_reg | 0x4);
+       else
+               snd_soc_write(codec, DA7210_DAC_HPF, mute_reg);
        return 0;
 }
 
-#define DA7210_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE)
+#define DA7210_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
+                       SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
 
 /* DAI operations */
 static struct snd_soc_dai_ops da7210_dai_ops = {
-       .startup        = da7210_startup,
        .hw_params      = da7210_hw_params,
        .set_fmt        = da7210_set_dai_fmt,
+       .digital_mute   = da7210_mute,
 };
 
 static struct snd_soc_dai_driver da7210_dai = {
@@ -451,11 +791,15 @@ static struct snd_soc_dai_driver da7210_dai = {
 static int da7210_probe(struct snd_soc_codec *codec)
 {
        struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
+       int ret;
 
        dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
 
-       codec->control_data     = da7210->control_data;
-       codec->hw_write         = (hw_write_t)i2c_master_send;
+       ret = snd_soc_codec_set_cache_io(codec, 8, 8, da7210->control_type);
+       if (ret < 0) {
+               dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
+               return ret;
+       }
 
        /* FIXME
         *
@@ -472,8 +816,8 @@ static int da7210_probe(struct snd_soc_codec *codec)
        /*
         * make sure that DA7210 use bypass mode before start up
         */
-       da7210_write(codec, DA7210_STARTUP1, 0);
-       da7210_write(codec, DA7210_PLL_DIV3,
+       snd_soc_write(codec, DA7210_STARTUP1, 0);
+       snd_soc_write(codec, DA7210_PLL_DIV3,
                     DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
 
        /*
@@ -481,36 +825,70 @@ static int da7210_probe(struct snd_soc_codec *codec)
         */
 
        /* Enable Left & Right MIC PGA and Mic Bias */
-       da7210_write(codec, DA7210_MIC_L, DA7210_MIC_L_EN | DA7210_MICBIAS_EN);
-       da7210_write(codec, DA7210_MIC_R, DA7210_MIC_R_EN);
+       snd_soc_write(codec, DA7210_MIC_L, DA7210_MIC_L_EN | DA7210_MICBIAS_EN);
+       snd_soc_write(codec, DA7210_MIC_R, DA7210_MIC_R_EN);
 
        /* Enable Left and Right input PGA */
-       da7210_write(codec, DA7210_INMIX_L, DA7210_IN_L_EN);
-       da7210_write(codec, DA7210_INMIX_R, DA7210_IN_R_EN);
+       snd_soc_write(codec, DA7210_INMIX_L, DA7210_IN_L_EN);
+       snd_soc_write(codec, DA7210_INMIX_R, DA7210_IN_R_EN);
 
        /* Enable Left and Right ADC */
-       da7210_write(codec, DA7210_ADC, DA7210_ADC_L_EN | DA7210_ADC_R_EN);
+       snd_soc_write(codec, DA7210_ADC, DA7210_ADC_L_EN | DA7210_ADC_R_EN);
 
        /*
         * DAC settings
         */
 
        /* Enable Left and Right DAC */
-       da7210_write(codec, DA7210_DAC_SEL,
+       snd_soc_write(codec, DA7210_DAC_SEL,
                     DA7210_DAC_L_SRC_DAI_L | DA7210_DAC_L_EN |
                     DA7210_DAC_R_SRC_DAI_R | DA7210_DAC_R_EN);
 
        /* Enable Left and Right out PGA */
-       da7210_write(codec, DA7210_OUTMIX_L, DA7210_OUT_L_EN);
-       da7210_write(codec, DA7210_OUTMIX_R, DA7210_OUT_R_EN);
+       snd_soc_write(codec, DA7210_OUTMIX_L, DA7210_OUT_L_EN);
+       snd_soc_write(codec, DA7210_OUTMIX_R, DA7210_OUT_R_EN);
 
        /* Enable Left and Right HeadPhone PGA */
-       da7210_write(codec, DA7210_HP_CFG,
+       snd_soc_write(codec, DA7210_HP_CFG,
                     DA7210_HP_2CAP_MODE | DA7210_HP_SENSE_EN |
                     DA7210_HP_L_EN | DA7210_HP_MODE | DA7210_HP_R_EN);
 
+       /* Enable ramp mode for DAC gain update */
+       snd_soc_write(codec, DA7210_SOFTMUTE, DA7210_RAMP_EN);
+
+       /*
+        * For DA7210 codec, there are two ways to enable/disable analog IOs
+        * and ADC/DAC,
+        * (1) Using "Enable Bit" of register associated with that IO
+        * (or ADC/DAC)
+        *      e.g. Mic Left can be enabled using bit 7 of MIC_L(0x7) reg
+        *
+        * (2) Using "Standby Bit" of STARTUP2 or STARTUP3 register
+        *      e.g. Mic left can be put to STANDBY using bit 0 of STARTUP3(0x5)
+        *
+        * Out of these two methods, the one using STANDBY bits is preferred
+        * way to enable/disable individual blocks. This is because STANDBY
+        * registers are part of system controller which allows system power
+        * up/down in a controlled, pop-free manner. Also, as per application
+        * note of DA7210, STANDBY register bits are only effective if a
+        * particular IO (or ADC/DAC) is already enabled using enable/disable
+        * register bits. Keeping these things in mind, current DAPM
+        * implementation manipulates only STANDBY bits.
+        *
+        * Overall implementation can be outlined as below,
+        *
+        * - "Enable bit" of an IO or ADC/DAC is used to enable it in probe()
+        * - "STANDBY bit" is controlled by DAPM
+        */
+
+       /* Enable Line out amplifiers */
+       snd_soc_write(codec, DA7210_OUT1_L, DA7210_OUT1_L_EN);
+       snd_soc_write(codec, DA7210_OUT1_R, DA7210_OUT1_R_EN);
+       snd_soc_write(codec, DA7210_OUT2, DA7210_OUT2_EN |
+                    DA7210_OUT2_OUTMIX_L | DA7210_OUT2_OUTMIX_R);
+
        /* Diable PLL and bypass it */
-       da7210_write(codec, DA7210_PLL, DA7210_PLL_FS_48000);
+       snd_soc_write(codec, DA7210_PLL, DA7210_PLL_FS_48000);
 
        /*
         * If 48kHz sound came, it use bypass mode,
@@ -521,25 +899,22 @@ static int da7210_probe(struct snd_soc_codec *codec)
         * DA7210_PLL_DIV3 :: DA7210_PLL_BYP bit.
         *   see da7210_hw_params
         */
-       da7210_write(codec, DA7210_PLL_DIV1, 0xE5); /* MCLK = 12.288MHz */
-       da7210_write(codec, DA7210_PLL_DIV2, 0x99);
-       da7210_write(codec, DA7210_PLL_DIV3, 0x0A |
+       snd_soc_write(codec, DA7210_PLL_DIV1, 0xE5); /* MCLK = 12.288MHz */
+       snd_soc_write(codec, DA7210_PLL_DIV2, 0x99);
+       snd_soc_write(codec, DA7210_PLL_DIV3, 0x0A |
                     DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
        snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN);
 
        /* As suggested by Dialog */
-       da7210_write(codec, DA7210_A_HID_UNLOCK,        0x8B); /* unlock */
-       da7210_write(codec, DA7210_A_TEST_UNLOCK,       0xB4);
-       da7210_write(codec, DA7210_A_PLL1,              0x01);
-       da7210_write(codec, DA7210_A_CP_MODE,           0x7C);
-       da7210_write(codec, DA7210_A_HID_UNLOCK,        0x00); /* re-lock */
-       da7210_write(codec, DA7210_A_TEST_UNLOCK,       0x00);
+       snd_soc_write(codec, DA7210_A_HID_UNLOCK,       0x8B); /* unlock */
+       snd_soc_write(codec, DA7210_A_TEST_UNLOCK,      0xB4);
+       snd_soc_write(codec, DA7210_A_PLL1,             0x01);
+       snd_soc_write(codec, DA7210_A_CP_MODE,          0x7C);
+       snd_soc_write(codec, DA7210_A_HID_UNLOCK,       0x00); /* re-lock */
+       snd_soc_write(codec, DA7210_A_TEST_UNLOCK,      0x00);
 
        /* Activate all enabled subsystem */
-       da7210_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN);
-
-       snd_soc_add_controls(codec, da7210_snd_controls,
-                            ARRAY_SIZE(da7210_snd_controls));
+       snd_soc_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN);
 
        dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
 
@@ -548,11 +923,18 @@ static int da7210_probe(struct snd_soc_codec *codec)
 
 static struct snd_soc_codec_driver soc_codec_dev_da7210 = {
        .probe                  = da7210_probe,
-       .read                   = da7210_read,
-       .write                  = da7210_write,
        .reg_cache_size         = ARRAY_SIZE(da7210_reg),
        .reg_word_size          = sizeof(u8),
        .reg_cache_default      = da7210_reg,
+       .volatile_register      = da7210_volatile_register,
+
+       .controls               = da7210_snd_controls,
+       .num_controls           = ARRAY_SIZE(da7210_snd_controls),
+
+       .dapm_widgets           = da7210_dapm_widgets,
+       .num_dapm_widgets       = ARRAY_SIZE(da7210_dapm_widgets),
+       .dapm_routes            = da7210_audio_map,
+       .num_dapm_routes        = ARRAY_SIZE(da7210_audio_map),
 };
 
 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
@@ -567,7 +949,6 @@ static int __devinit da7210_i2c_probe(struct i2c_client *i2c,
                return -ENOMEM;
 
        i2c_set_clientdata(i2c, da7210);
-       da7210->control_data = i2c;
        da7210->control_type = SND_SOC_I2C;
 
        ret =  snd_soc_register_codec(&i2c->dev,
index 2c2a681da0d7538ab663fcf707b179efe0c62059..c387dafc6ab6970245f03ec8ad6a32712e0c31fd 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2007 Wolfson Microelectronics PLC.
  * Author: Graeme Gregory
- *         graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com
+ *         graeme.gregory@wolfsonmicro.com
  * Copyright 2011 Lars-Peter Clausen <lars@metafoo.de>
  *
  *  This program is free software; you can redistribute  it and/or modify it
index ac65a2d3640860944f1d292f2fb482a5beccf2ca..ebbf63c79c34e2873088aa2faaf6bcce400d99a0 100644 (file)
@@ -40,7 +40,6 @@ struct max98088_cdata {
 
 struct max98088_priv {
        enum max98088_type devtype;
-       void *control_data;
        struct max98088_pdata *pdata;
        unsigned int sysclk;
        struct max98088_cdata dai[2];
@@ -1697,13 +1696,19 @@ static struct snd_soc_dai_driver max98088_dai[] = {
 }
 };
 
-static int max98088_get_channel(const char *name)
+static const char *eq_mode_name[] = {"EQ1 Mode", "EQ2 Mode"};
+
+static int max98088_get_channel(struct snd_soc_codec *codec, const char *name)
 {
-       if (strcmp(name, "EQ1 Mode") == 0)
-               return 0;
-       if (strcmp(name, "EQ2 Mode") == 0)
-               return 1;
-       return -EINVAL;
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(eq_mode_name); i++)
+               if (strcmp(name, eq_mode_name[i]) == 0)
+                       return i;
+
+       /* Shouldn't happen */
+       dev_err(codec->dev, "Bad EQ channel name '%s'\n", name);
+       return -EINVAL;
 }
 
 static void max98088_setup_eq1(struct snd_soc_codec *codec)
@@ -1807,10 +1812,13 @@ static int max98088_put_eq_enum(struct snd_kcontrol *kcontrol,
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
        struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
        struct max98088_pdata *pdata = max98088->pdata;
-       int channel = max98088_get_channel(kcontrol->id.name);
+       int channel = max98088_get_channel(codec, kcontrol->id.name);
        struct max98088_cdata *cdata;
        int sel = ucontrol->value.integer.value[0];
 
+       if (channel < 0)
+              return channel;
+
        cdata = &max98088->dai[channel];
 
        if (sel >= pdata->eq_cfgcnt)
@@ -1835,9 +1843,12 @@ static int max98088_get_eq_enum(struct snd_kcontrol *kcontrol,
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
        struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
-       int channel = max98088_get_channel(kcontrol->id.name);
+       int channel = max98088_get_channel(codec, kcontrol->id.name);
        struct max98088_cdata *cdata;
 
+       if (channel < 0)
+              return channel;
+
        cdata = &max98088->dai[channel];
        ucontrol->value.enumerated.item[0] = cdata->eq_sel;
        return 0;
@@ -1852,17 +1863,17 @@ static void max98088_handle_eq_pdata(struct snd_soc_codec *codec)
        int i, j;
        const char **t;
        int ret;
-
        struct snd_kcontrol_new controls[] = {
-               SOC_ENUM_EXT("EQ1 Mode",
+               SOC_ENUM_EXT((char *)eq_mode_name[0],
                        max98088->eq_enum,
                        max98088_get_eq_enum,
                        max98088_put_eq_enum),
-               SOC_ENUM_EXT("EQ2 Mode",
+               SOC_ENUM_EXT((char *)eq_mode_name[1],
                        max98088->eq_enum,
                        max98088_get_eq_enum,
                        max98088_put_eq_enum),
        };
+       BUILD_BUG_ON(ARRAY_SIZE(controls) != ARRAY_SIZE(eq_mode_name));
 
        cfg = pdata->eq_cfg;
        cfgcnt = pdata->eq_cfgcnt;
@@ -2066,7 +2077,6 @@ static int max98088_i2c_probe(struct i2c_client *i2c,
        max98088->devtype = id->driver_data;
 
        i2c_set_clientdata(i2c, max98088);
-       max98088->control_data = i2c;
        max98088->pdata = i2c->dev.platform_data;
 
        ret = snd_soc_register_codec(&i2c->dev,
index 668434d44303ea6c84e748b9d6029ac8c6732977..26d7b089fb9c27836c2a6721dceec1350bc5300f 100644 (file)
@@ -40,7 +40,6 @@ struct max98095_cdata {
 
 struct max98095_priv {
        enum max98095_type devtype;
-       void *control_data;
        struct max98095_pdata *pdata;
        unsigned int sysclk;
        struct max98095_cdata dai[3];
@@ -618,14 +617,13 @@ static int max98095_volatile(struct snd_soc_codec *codec, unsigned int reg)
 static int max98095_hw_write(struct snd_soc_codec *codec, unsigned int reg,
                             unsigned int value)
 {
-       u8 data[2];
+       int ret;
 
-       data[0] = reg;
-       data[1] = value;
-       if (codec->hw_write(codec->control_data, data, 2) == 2)
-               return 0;
-       else
-               return -EIO;
+       codec->cache_bypass = 1;
+       ret = snd_soc_write(codec, reg, value);
+       codec->cache_bypass = 0;
+
+       return ret ? -EIO : 0;
 }
 
 /*
@@ -1992,12 +1990,19 @@ static void max98095_handle_eq_pdata(struct snd_soc_codec *codec)
                dev_err(codec->dev, "Failed to add EQ control: %d\n", ret);
 }
 
-static int max98095_get_bq_channel(const char *name)
+static const char *bq_mode_name[] = {"Biquad1 Mode", "Biquad2 Mode"};
+
+static int max98095_get_bq_channel(struct snd_soc_codec *codec,
+                                  const char *name)
 {
-       if (strcmp(name, "Biquad1 Mode") == 0)
-               return 0;
-       if (strcmp(name, "Biquad2 Mode") == 0)
-               return 1;
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(bq_mode_name); i++)
+               if (strcmp(name, bq_mode_name[i]) == 0)
+                       return i;
+
+       /* Shouldn't happen */
+       dev_err(codec->dev, "Bad biquad channel name '%s'\n", name);
        return -EINVAL;
 }
 
@@ -2007,14 +2012,15 @@ static int max98095_put_bq_enum(struct snd_kcontrol *kcontrol,
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
        struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
        struct max98095_pdata *pdata = max98095->pdata;
-       int channel = max98095_get_bq_channel(kcontrol->id.name);
+       int channel = max98095_get_bq_channel(codec, kcontrol->id.name);
        struct max98095_cdata *cdata;
        int sel = ucontrol->value.integer.value[0];
        struct max98095_biquad_cfg *coef_set;
        int fs, best, best_val, i;
        int regmask, regsave;
 
-       BUG_ON(channel > 1);
+       if (channel < 0)
+               return channel;
 
        if (!pdata || !max98095->bq_textcnt)
                return 0;
@@ -2066,9 +2072,12 @@ static int max98095_get_bq_enum(struct snd_kcontrol *kcontrol,
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
        struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
-       int channel = max98095_get_bq_channel(kcontrol->id.name);
+       int channel = max98095_get_bq_channel(codec, kcontrol->id.name);
        struct max98095_cdata *cdata;
 
+       if (channel < 0)
+               return channel;
+
        cdata = &max98095->dai[channel];
        ucontrol->value.enumerated.item[0] = cdata->bq_sel;
 
@@ -2086,15 +2095,16 @@ static void max98095_handle_bq_pdata(struct snd_soc_codec *codec)
        int ret;
 
        struct snd_kcontrol_new controls[] = {
-               SOC_ENUM_EXT("Biquad1 Mode",
+               SOC_ENUM_EXT((char *)bq_mode_name[0],
                        max98095->bq_enum,
                        max98095_get_bq_enum,
                        max98095_put_bq_enum),
-               SOC_ENUM_EXT("Biquad2 Mode",
+               SOC_ENUM_EXT((char *)bq_mode_name[1],
                        max98095->bq_enum,
                        max98095_get_bq_enum,
                        max98095_put_bq_enum),
        };
+       BUILD_BUG_ON(ARRAY_SIZE(controls) != ARRAY_SIZE(bq_mode_name));
 
        cfg = pdata->bq_cfg;
        cfgcnt = pdata->bq_cfgcnt;
@@ -2337,7 +2347,6 @@ static int max98095_i2c_probe(struct i2c_client *i2c,
 
        max98095->devtype = id->driver_data;
        i2c_set_clientdata(i2c, max98095);
-       max98095->control_data = i2c;
        max98095->pdata = i2c->dev.platform_data;
 
        ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_max98095,
diff --git a/sound/soc/codecs/rt5631.c b/sound/soc/codecs/rt5631.c
new file mode 100644 (file)
index 0000000..27a078c
--- /dev/null
@@ -0,0 +1,1773 @@
+/*
+ * rt5631.c  --  RT5631 ALSA Soc Audio driver
+ *
+ * Copyright 2011 Realtek Microelectronics
+ *
+ * Author: flove <flove@realtek.com>
+ *
+ * Based on WM8753.c
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/pm.h>
+#include <linux/i2c.h>
+#include <linux/platform_device.h>
+#include <linux/spi/spi.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+#include <sound/initval.h>
+#include <sound/tlv.h>
+
+#include "rt5631.h"
+
+struct rt5631_priv {
+       int codec_version;
+       int master;
+       int sysclk;
+       int rx_rate;
+       int bclk_rate;
+       int dmic_used_flag;
+};
+
+static const u16 rt5631_reg[RT5631_VENDOR_ID2 + 1] = {
+       [RT5631_SPK_OUT_VOL] = 0x8888,
+       [RT5631_HP_OUT_VOL] = 0x8080,
+       [RT5631_MONO_AXO_1_2_VOL] = 0xa080,
+       [RT5631_AUX_IN_VOL] = 0x0808,
+       [RT5631_ADC_REC_MIXER] = 0xf0f0,
+       [RT5631_VDAC_DIG_VOL] = 0x0010,
+       [RT5631_OUTMIXER_L_CTRL] = 0xffc0,
+       [RT5631_OUTMIXER_R_CTRL] = 0xffc0,
+       [RT5631_AXO1MIXER_CTRL] = 0x88c0,
+       [RT5631_AXO2MIXER_CTRL] = 0x88c0,
+       [RT5631_DIG_MIC_CTRL] = 0x3000,
+       [RT5631_MONO_INPUT_VOL] = 0x8808,
+       [RT5631_SPK_MIXER_CTRL] = 0xf8f8,
+       [RT5631_SPK_MONO_OUT_CTRL] = 0xfc00,
+       [RT5631_SPK_MONO_HP_OUT_CTRL] = 0x4440,
+       [RT5631_SDP_CTRL] = 0x8000,
+       [RT5631_MONO_SDP_CTRL] = 0x8000,
+       [RT5631_STEREO_AD_DA_CLK_CTRL] = 0x2010,
+       [RT5631_GEN_PUR_CTRL_REG] = 0x0e00,
+       [RT5631_INT_ST_IRQ_CTRL_2] = 0x071a,
+       [RT5631_MISC_CTRL] = 0x2040,
+       [RT5631_DEPOP_FUN_CTRL_2] = 0x8000,
+       [RT5631_SOFT_VOL_CTRL] = 0x07e0,
+       [RT5631_ALC_CTRL_1] = 0x0206,
+       [RT5631_ALC_CTRL_3] = 0x2000,
+       [RT5631_PSEUDO_SPATL_CTRL] = 0x0553,
+};
+
+/**
+ * rt5631_write_index - write index register of 2nd layer
+ */
+static void rt5631_write_index(struct snd_soc_codec *codec,
+               unsigned int reg, unsigned int value)
+{
+       snd_soc_write(codec, RT5631_INDEX_ADD, reg);
+       snd_soc_write(codec, RT5631_INDEX_DATA, value);
+}
+
+/**
+ * rt5631_read_index - read index register of 2nd layer
+ */
+static unsigned int rt5631_read_index(struct snd_soc_codec *codec,
+                               unsigned int reg)
+{
+       unsigned int value;
+
+       snd_soc_write(codec, RT5631_INDEX_ADD, reg);
+       value = snd_soc_read(codec, RT5631_INDEX_DATA);
+
+       return value;
+}
+
+static int rt5631_reset(struct snd_soc_codec *codec)
+{
+       return snd_soc_write(codec, RT5631_RESET, 0);
+}
+
+static int rt5631_volatile_register(struct snd_soc_codec *codec,
+                                   unsigned int reg)
+{
+       switch (reg) {
+       case RT5631_RESET:
+       case RT5631_INT_ST_IRQ_CTRL_2:
+       case RT5631_INDEX_ADD:
+       case RT5631_INDEX_DATA:
+       case RT5631_EQ_CTRL:
+               return 1;
+       default:
+               return 0;
+       }
+}
+
+static int rt5631_readable_register(struct snd_soc_codec *codec,
+                                   unsigned int reg)
+{
+       switch (reg) {
+       case RT5631_RESET:
+       case RT5631_SPK_OUT_VOL:
+       case RT5631_HP_OUT_VOL:
+       case RT5631_MONO_AXO_1_2_VOL:
+       case RT5631_AUX_IN_VOL:
+       case RT5631_STEREO_DAC_VOL_1:
+       case RT5631_MIC_CTRL_1:
+       case RT5631_STEREO_DAC_VOL_2:
+       case RT5631_ADC_CTRL_1:
+       case RT5631_ADC_REC_MIXER:
+       case RT5631_ADC_CTRL_2:
+       case RT5631_VDAC_DIG_VOL:
+       case RT5631_OUTMIXER_L_CTRL:
+       case RT5631_OUTMIXER_R_CTRL:
+       case RT5631_AXO1MIXER_CTRL:
+       case RT5631_AXO2MIXER_CTRL:
+       case RT5631_MIC_CTRL_2:
+       case RT5631_DIG_MIC_CTRL:
+       case RT5631_MONO_INPUT_VOL:
+       case RT5631_SPK_MIXER_CTRL:
+       case RT5631_SPK_MONO_OUT_CTRL:
+       case RT5631_SPK_MONO_HP_OUT_CTRL:
+       case RT5631_SDP_CTRL:
+       case RT5631_MONO_SDP_CTRL:
+       case RT5631_STEREO_AD_DA_CLK_CTRL:
+       case RT5631_PWR_MANAG_ADD1:
+       case RT5631_PWR_MANAG_ADD2:
+       case RT5631_PWR_MANAG_ADD3:
+       case RT5631_PWR_MANAG_ADD4:
+       case RT5631_GEN_PUR_CTRL_REG:
+       case RT5631_GLOBAL_CLK_CTRL:
+       case RT5631_PLL_CTRL:
+       case RT5631_INT_ST_IRQ_CTRL_1:
+       case RT5631_INT_ST_IRQ_CTRL_2:
+       case RT5631_GPIO_CTRL:
+       case RT5631_MISC_CTRL:
+       case RT5631_DEPOP_FUN_CTRL_1:
+       case RT5631_DEPOP_FUN_CTRL_2:
+       case RT5631_JACK_DET_CTRL:
+       case RT5631_SOFT_VOL_CTRL:
+       case RT5631_ALC_CTRL_1:
+       case RT5631_ALC_CTRL_2:
+       case RT5631_ALC_CTRL_3:
+       case RT5631_PSEUDO_SPATL_CTRL:
+       case RT5631_INDEX_ADD:
+       case RT5631_INDEX_DATA:
+       case RT5631_EQ_CTRL:
+       case RT5631_VENDOR_ID:
+       case RT5631_VENDOR_ID1:
+       case RT5631_VENDOR_ID2:
+               return 1;
+       default:
+               return 0;
+       }
+}
+
+static const DECLARE_TLV_DB_SCALE(out_vol_tlv, -4650, 150, 0);
+static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -95625, 375, 0);
+static const DECLARE_TLV_DB_SCALE(in_vol_tlv, -3450, 150, 0);
+/* {0, +20, +24, +30, +35, +40, +44, +50, +52}dB */
+static unsigned int mic_bst_tlv[] = {
+       TLV_DB_RANGE_HEAD(6),
+       0, 0, TLV_DB_SCALE_ITEM(0, 0, 0),
+       1, 1, TLV_DB_SCALE_ITEM(2000, 0, 0),
+       2, 2, TLV_DB_SCALE_ITEM(2400, 0, 0),
+       3, 5, TLV_DB_SCALE_ITEM(3000, 500, 0),
+       6, 6, TLV_DB_SCALE_ITEM(4400, 0, 0),
+       7, 7, TLV_DB_SCALE_ITEM(5000, 0, 0),
+       8, 8, TLV_DB_SCALE_ITEM(5200, 0, 0),
+};
+
+static int rt5631_dmic_get(struct snd_kcontrol *kcontrol,
+               struct snd_ctl_elem_value *ucontrol)
+{
+       struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+       struct rt5631_priv *rt5631 = snd_soc_codec_get_drvdata(codec);
+
+       ucontrol->value.integer.value[0] = rt5631->dmic_used_flag;
+
+       return 0;
+}
+
+static int rt5631_dmic_put(struct snd_kcontrol *kcontrol,
+               struct snd_ctl_elem_value *ucontrol)
+{
+       struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+       struct rt5631_priv *rt5631 = snd_soc_codec_get_drvdata(codec);
+
+       rt5631->dmic_used_flag = ucontrol->value.integer.value[0];
+       return 0;
+}
+
+/* MIC Input Type */
+static const char *rt5631_input_mode[] = {
+       "Single ended", "Differential"};
+
+static const SOC_ENUM_SINGLE_DECL(
+       rt5631_mic1_mode_enum, RT5631_MIC_CTRL_1,
+       RT5631_MIC1_DIFF_INPUT_SHIFT, rt5631_input_mode);
+
+static const SOC_ENUM_SINGLE_DECL(
+       rt5631_mic2_mode_enum, RT5631_MIC_CTRL_1,
+       RT5631_MIC2_DIFF_INPUT_SHIFT, rt5631_input_mode);
+
+/* MONO Input Type */
+static const SOC_ENUM_SINGLE_DECL(
+       rt5631_monoin_mode_enum, RT5631_MONO_INPUT_VOL,
+       RT5631_MONO_DIFF_INPUT_SHIFT, rt5631_input_mode);
+
+/* SPK Ratio Gain Control */
+static const char *rt5631_spk_ratio[] = {"1.00x", "1.09x", "1.27x", "1.44x",
+                       "1.56x", "1.68x", "1.99x", "2.34x"};
+
+static const SOC_ENUM_SINGLE_DECL(
+       rt5631_spk_ratio_enum, RT5631_GEN_PUR_CTRL_REG,
+       RT5631_SPK_AMP_RATIO_CTRL_SHIFT, rt5631_spk_ratio);
+
+static const struct snd_kcontrol_new rt5631_snd_controls[] = {
+       /* MIC */
+       SOC_ENUM("MIC1 Mode Control",  rt5631_mic1_mode_enum),
+       SOC_SINGLE_TLV("MIC1 Boost", RT5631_MIC_CTRL_2,
+               RT5631_MIC1_BOOST_SHIFT, 8, 0, mic_bst_tlv),
+       SOC_ENUM("MIC2 Mode Control", rt5631_mic2_mode_enum),
+       SOC_SINGLE_TLV("MIC2 Boost", RT5631_MIC_CTRL_2,
+               RT5631_MIC2_BOOST_SHIFT, 8, 0, mic_bst_tlv),
+       /* MONO IN */
+       SOC_ENUM("MONOIN Mode Control", rt5631_monoin_mode_enum),
+       SOC_DOUBLE_TLV("MONOIN_RX Capture Volume", RT5631_MONO_INPUT_VOL,
+                       RT5631_L_VOL_SHIFT, RT5631_R_VOL_SHIFT,
+                       RT5631_VOL_MASK, 1, in_vol_tlv),
+       /* AXI */
+       SOC_DOUBLE_TLV("AXI Capture Volume", RT5631_AUX_IN_VOL,
+                       RT5631_L_VOL_SHIFT, RT5631_R_VOL_SHIFT,
+                       RT5631_VOL_MASK, 1, in_vol_tlv),
+       /* DAC */
+       SOC_DOUBLE_TLV("PCM Playback Volume", RT5631_STEREO_DAC_VOL_2,
+                       RT5631_L_VOL_SHIFT, RT5631_R_VOL_SHIFT,
+                       RT5631_DAC_VOL_MASK, 1, dac_vol_tlv),
+       SOC_DOUBLE("PCM Playback Switch", RT5631_STEREO_DAC_VOL_1,
+                       RT5631_L_MUTE_SHIFT, RT5631_R_MUTE_SHIFT, 1, 1),
+       /* AXO */
+       SOC_SINGLE("AXO1 Playback Switch", RT5631_MONO_AXO_1_2_VOL,
+                               RT5631_L_MUTE_SHIFT, 1, 1),
+       SOC_SINGLE("AXO2 Playback Switch", RT5631_MONO_AXO_1_2_VOL,
+                               RT5631_R_VOL_SHIFT, 1, 1),
+       /* OUTVOL */
+       SOC_DOUBLE("OUTVOL Channel Switch", RT5631_SPK_OUT_VOL,
+               RT5631_L_EN_SHIFT, RT5631_R_EN_SHIFT, 1, 0),
+
+       /* SPK */
+       SOC_DOUBLE("Speaker Playback Switch", RT5631_SPK_OUT_VOL,
+               RT5631_L_MUTE_SHIFT, RT5631_R_MUTE_SHIFT, 1, 1),
+       SOC_DOUBLE_TLV("Speaker Playback Volume", RT5631_SPK_OUT_VOL,
+               RT5631_L_VOL_SHIFT, RT5631_R_VOL_SHIFT, 39, 1, out_vol_tlv),
+       /* MONO OUT */
+       SOC_SINGLE("MONO Playback Switch", RT5631_MONO_AXO_1_2_VOL,
+                               RT5631_MUTE_MONO_SHIFT, 1, 1),
+       /* HP */
+       SOC_DOUBLE("HP Playback Switch", RT5631_HP_OUT_VOL,
+               RT5631_L_MUTE_SHIFT, RT5631_R_MUTE_SHIFT, 1, 1),
+       SOC_DOUBLE_TLV("HP Playback Volume", RT5631_HP_OUT_VOL,
+               RT5631_L_VOL_SHIFT, RT5631_R_VOL_SHIFT,
+               RT5631_VOL_MASK, 1, out_vol_tlv),
+       /* DMIC */
+       SOC_SINGLE_EXT("DMIC Switch", 0, 0, 1, 0,
+               rt5631_dmic_get, rt5631_dmic_put),
+       SOC_DOUBLE("DMIC Capture Switch", RT5631_DIG_MIC_CTRL,
+               RT5631_DMIC_L_CH_MUTE_SHIFT,
+               RT5631_DMIC_R_CH_MUTE_SHIFT, 1, 1),
+
+       /* SPK Ratio Gain Control */
+       SOC_ENUM("SPK Ratio Control", rt5631_spk_ratio_enum),
+};
+
+static int check_sysclk1_source(struct snd_soc_dapm_widget *source,
+                        struct snd_soc_dapm_widget *sink)
+{
+       unsigned int reg;
+
+       reg = snd_soc_read(source->codec, RT5631_GLOBAL_CLK_CTRL);
+       return reg & RT5631_SYSCLK_SOUR_SEL_PLL;
+}
+
+static int check_dmic_used(struct snd_soc_dapm_widget *source,
+                        struct snd_soc_dapm_widget *sink)
+{
+       struct rt5631_priv *rt5631 = snd_soc_codec_get_drvdata(source->codec);
+       return rt5631->dmic_used_flag;
+}
+
+static int check_dacl_to_outmixl(struct snd_soc_dapm_widget *source,
+                        struct snd_soc_dapm_widget *sink)
+{
+       unsigned int reg;
+
+       reg = snd_soc_read(source->codec, RT5631_OUTMIXER_L_CTRL);
+       return !(reg & RT5631_M_DAC_L_TO_OUTMIXER_L);
+}
+
+static int check_dacr_to_outmixr(struct snd_soc_dapm_widget *source,
+                        struct snd_soc_dapm_widget *sink)
+{
+       unsigned int reg;
+
+       reg = snd_soc_read(source->codec, RT5631_OUTMIXER_R_CTRL);
+       return !(reg & RT5631_M_DAC_R_TO_OUTMIXER_R);
+}
+
+static int check_dacl_to_spkmixl(struct snd_soc_dapm_widget *source,
+                        struct snd_soc_dapm_widget *sink)
+{
+       unsigned int reg;
+
+       reg = snd_soc_read(source->codec, RT5631_SPK_MIXER_CTRL);
+       return !(reg & RT5631_M_DAC_L_TO_SPKMIXER_L);
+}
+
+static int check_dacr_to_spkmixr(struct snd_soc_dapm_widget *source,
+                        struct snd_soc_dapm_widget *sink)
+{
+       unsigned int reg;
+
+       reg = snd_soc_read(source->codec, RT5631_SPK_MIXER_CTRL);
+       return !(reg & RT5631_M_DAC_R_TO_SPKMIXER_R);
+}
+
+static int check_adcl_select(struct snd_soc_dapm_widget *source,
+                        struct snd_soc_dapm_widget *sink)
+{
+       unsigned int reg;
+
+       reg = snd_soc_read(source->codec, RT5631_ADC_REC_MIXER);
+       return !(reg & RT5631_M_MIC1_TO_RECMIXER_L);
+}
+
+static int check_adcr_select(struct snd_soc_dapm_widget *source,
+                        struct snd_soc_dapm_widget *sink)
+{
+       unsigned int reg;
+
+       reg = snd_soc_read(source->codec, RT5631_ADC_REC_MIXER);
+       return !(reg & RT5631_M_MIC2_TO_RECMIXER_R);
+}
+
+/**
+ * onebit_depop_power_stage - auto depop in power stage.
+ * @enable: power on/off
+ *
+ * When power on/off headphone, the depop sequence is done by hardware.
+ */
+static void onebit_depop_power_stage(struct snd_soc_codec *codec, int enable)
+{
+       unsigned int soft_vol, hp_zc;
+
+       /* enable one-bit depop function */
+       snd_soc_update_bits(codec, RT5631_DEPOP_FUN_CTRL_2,
+                               RT5631_EN_ONE_BIT_DEPOP, 0);
+
+       /* keep soft volume and zero crossing setting */
+       soft_vol = snd_soc_read(codec, RT5631_SOFT_VOL_CTRL);
+       snd_soc_write(codec, RT5631_SOFT_VOL_CTRL, 0);
+       hp_zc = snd_soc_read(codec, RT5631_INT_ST_IRQ_CTRL_2);
+       snd_soc_write(codec, RT5631_INT_ST_IRQ_CTRL_2, hp_zc & 0xf7ff);
+       if (enable) {
+               /* config one-bit depop parameter */
+               rt5631_write_index(codec, RT5631_TEST_MODE_CTRL, 0x84c0);
+               rt5631_write_index(codec, RT5631_SPK_INTL_CTRL, 0x309f);
+               rt5631_write_index(codec, RT5631_CP_INTL_REG2, 0x6530);
+               /* power on capless block */
+               snd_soc_write(codec, RT5631_DEPOP_FUN_CTRL_2,
+                               RT5631_EN_CAP_FREE_DEPOP);
+       } else {
+               /* power off capless block */
+               snd_soc_write(codec, RT5631_DEPOP_FUN_CTRL_2, 0);
+               msleep(100);
+       }
+
+       /* recover soft volume and zero crossing setting */
+       snd_soc_write(codec, RT5631_SOFT_VOL_CTRL, soft_vol);
+       snd_soc_write(codec, RT5631_INT_ST_IRQ_CTRL_2, hp_zc);
+}
+
+/**
+ * onebit_depop_mute_stage - auto depop in mute stage.
+ * @enable: mute/unmute
+ *
+ * When mute/unmute headphone, the depop sequence is done by hardware.
+ */
+static void onebit_depop_mute_stage(struct snd_soc_codec *codec, int enable)
+{
+       unsigned int soft_vol, hp_zc;
+
+       /* enable one-bit depop function */
+       snd_soc_update_bits(codec, RT5631_DEPOP_FUN_CTRL_2,
+                               RT5631_EN_ONE_BIT_DEPOP, 0);
+
+       /* keep soft volume and zero crossing setting */
+       soft_vol = snd_soc_read(codec, RT5631_SOFT_VOL_CTRL);
+       snd_soc_write(codec, RT5631_SOFT_VOL_CTRL, 0);
+       hp_zc = snd_soc_read(codec, RT5631_INT_ST_IRQ_CTRL_2);
+       snd_soc_write(codec, RT5631_INT_ST_IRQ_CTRL_2, hp_zc & 0xf7ff);
+       if (enable) {
+               schedule_timeout_uninterruptible(msecs_to_jiffies(10));
+               /* config one-bit depop parameter */
+               rt5631_write_index(codec, RT5631_SPK_INTL_CTRL, 0x307f);
+               snd_soc_update_bits(codec, RT5631_HP_OUT_VOL,
+                               RT5631_L_MUTE | RT5631_R_MUTE, 0);
+               msleep(300);
+       } else {
+               snd_soc_update_bits(codec, RT5631_HP_OUT_VOL,
+                       RT5631_L_MUTE | RT5631_R_MUTE,
+                       RT5631_L_MUTE | RT5631_R_MUTE);
+               msleep(100);
+       }
+
+       /* recover soft volume and zero crossing setting */
+       snd_soc_write(codec, RT5631_SOFT_VOL_CTRL, soft_vol);
+       snd_soc_write(codec, RT5631_INT_ST_IRQ_CTRL_2, hp_zc);
+}
+
+/**
+ * onebit_depop_power_stage - step by step depop sequence in power stage.
+ * @enable: power on/off
+ *
+ * When power on/off headphone, the depop sequence is done in step by step.
+ */
+static void depop_seq_power_stage(struct snd_soc_codec *codec, int enable)
+{
+       unsigned int soft_vol, hp_zc;
+
+       /* depop control by register */
+       snd_soc_update_bits(codec, RT5631_DEPOP_FUN_CTRL_2,
+               RT5631_EN_ONE_BIT_DEPOP, RT5631_EN_ONE_BIT_DEPOP);
+
+       /* keep soft volume and zero crossing setting */
+       soft_vol = snd_soc_read(codec, RT5631_SOFT_VOL_CTRL);
+       snd_soc_write(codec, RT5631_SOFT_VOL_CTRL, 0);
+       hp_zc = snd_soc_read(codec, RT5631_INT_ST_IRQ_CTRL_2);
+       snd_soc_write(codec, RT5631_INT_ST_IRQ_CTRL_2, hp_zc & 0xf7ff);
+       if (enable) {
+               /* config depop sequence parameter */
+               rt5631_write_index(codec, RT5631_SPK_INTL_CTRL, 0x303e);
+
+               /* power on headphone and charge pump */
+               snd_soc_update_bits(codec, RT5631_PWR_MANAG_ADD3,
+                       RT5631_PWR_CHARGE_PUMP | RT5631_PWR_HP_L_AMP |
+                       RT5631_PWR_HP_R_AMP,
+                       RT5631_PWR_CHARGE_PUMP | RT5631_PWR_HP_L_AMP |
+                       RT5631_PWR_HP_R_AMP);
+
+               /* power on soft generator and depop mode2 */
+               snd_soc_write(codec, RT5631_DEPOP_FUN_CTRL_1,
+                       RT5631_POW_ON_SOFT_GEN | RT5631_EN_DEPOP2_FOR_HP);
+               msleep(100);
+
+               /* stop depop mode */
+               snd_soc_update_bits(codec, RT5631_PWR_MANAG_ADD3,
+                       RT5631_PWR_HP_DEPOP_DIS, RT5631_PWR_HP_DEPOP_DIS);
+       } else {
+               /* config depop sequence parameter */
+               rt5631_write_index(codec, RT5631_SPK_INTL_CTRL, 0x303F);
+               snd_soc_write(codec, RT5631_DEPOP_FUN_CTRL_1,
+                       RT5631_POW_ON_SOFT_GEN | RT5631_EN_MUTE_UNMUTE_DEPOP |
+                       RT5631_PD_HPAMP_L_ST_UP | RT5631_PD_HPAMP_R_ST_UP);
+               msleep(75);
+               snd_soc_write(codec, RT5631_DEPOP_FUN_CTRL_1,
+                       RT5631_POW_ON_SOFT_GEN | RT5631_PD_HPAMP_L_ST_UP |
+                       RT5631_PD_HPAMP_R_ST_UP);
+
+               /* start depop mode */
+               snd_soc_update_bits(codec, RT5631_PWR_MANAG_ADD3,
+                               RT5631_PWR_HP_DEPOP_DIS, 0);
+
+               /* config depop sequence parameter */
+               snd_soc_write(codec, RT5631_DEPOP_FUN_CTRL_1,
+                       RT5631_POW_ON_SOFT_GEN | RT5631_EN_DEPOP2_FOR_HP |
+                       RT5631_PD_HPAMP_L_ST_UP | RT5631_PD_HPAMP_R_ST_UP);
+               msleep(80);
+               snd_soc_write(codec, RT5631_DEPOP_FUN_CTRL_1,
+                       RT5631_POW_ON_SOFT_GEN);
+
+               /* power down headphone and charge pump */
+               snd_soc_update_bits(codec, RT5631_PWR_MANAG_ADD3,
+                       RT5631_PWR_CHARGE_PUMP | RT5631_PWR_HP_L_AMP |
+                       RT5631_PWR_HP_R_AMP, 0);
+       }
+
+       /* recover soft volume and zero crossing setting */
+       snd_soc_write(codec, RT5631_SOFT_VOL_CTRL, soft_vol);
+       snd_soc_write(codec, RT5631_INT_ST_IRQ_CTRL_2, hp_zc);
+}
+
+/**
+ * depop_seq_mute_stage - step by step depop sequence in mute stage.
+ * @enable: mute/unmute
+ *
+ * When mute/unmute headphone, the depop sequence is done in step by step.
+ */
+static void depop_seq_mute_stage(struct snd_soc_codec *codec, int enable)
+{
+       unsigned int soft_vol, hp_zc;
+
+       /* depop control by register */
+       snd_soc_update_bits(codec, RT5631_DEPOP_FUN_CTRL_2,
+               RT5631_EN_ONE_BIT_DEPOP, RT5631_EN_ONE_BIT_DEPOP);
+
+       /* keep soft volume and zero crossing setting */
+       soft_vol = snd_soc_read(codec, RT5631_SOFT_VOL_CTRL);
+       snd_soc_write(codec, RT5631_SOFT_VOL_CTRL, 0);
+       hp_zc = snd_soc_read(codec, RT5631_INT_ST_IRQ_CTRL_2);
+       snd_soc_write(codec, RT5631_INT_ST_IRQ_CTRL_2, hp_zc & 0xf7ff);
+       if (enable) {
+               schedule_timeout_uninterruptible(msecs_to_jiffies(10));
+
+               /* config depop sequence parameter */
+               rt5631_write_index(codec, RT5631_SPK_INTL_CTRL, 0x302f);
+               snd_soc_write(codec, RT5631_DEPOP_FUN_CTRL_1,
+                       RT5631_POW_ON_SOFT_GEN | RT5631_EN_MUTE_UNMUTE_DEPOP |
+                       RT5631_EN_HP_R_M_UN_MUTE_DEPOP |
+                       RT5631_EN_HP_L_M_UN_MUTE_DEPOP);
+
+               snd_soc_update_bits(codec, RT5631_HP_OUT_VOL,
+                               RT5631_L_MUTE | RT5631_R_MUTE, 0);
+               msleep(160);
+       } else {
+               /* config depop sequence parameter */
+               rt5631_write_index(codec, RT5631_SPK_INTL_CTRL, 0x302f);
+               snd_soc_write(codec, RT5631_DEPOP_FUN_CTRL_1,
+                       RT5631_POW_ON_SOFT_GEN | RT5631_EN_MUTE_UNMUTE_DEPOP |
+                       RT5631_EN_HP_R_M_UN_MUTE_DEPOP |
+                       RT5631_EN_HP_L_M_UN_MUTE_DEPOP);
+
+               snd_soc_update_bits(codec, RT5631_HP_OUT_VOL,
+                       RT5631_L_MUTE | RT5631_R_MUTE,
+                       RT5631_L_MUTE | RT5631_R_MUTE);
+               msleep(150);
+       }
+
+       /* recover soft volume and zero crossing setting */
+       snd_soc_write(codec, RT5631_SOFT_VOL_CTRL, soft_vol);
+       snd_soc_write(codec, RT5631_INT_ST_IRQ_CTRL_2, hp_zc);
+}
+
+static int hp_event(struct snd_soc_dapm_widget *w,
+       struct snd_kcontrol *kcontrol, int event)
+{
+       struct snd_soc_codec *codec = w->codec;
+       struct rt5631_priv *rt5631 = snd_soc_codec_get_drvdata(codec);
+
+       switch (event) {
+       case SND_SOC_DAPM_PRE_PMD:
+               if (rt5631->codec_version) {
+                       onebit_depop_mute_stage(codec, 0);
+                       onebit_depop_power_stage(codec, 0);
+               } else {
+                       depop_seq_mute_stage(codec, 0);
+                       depop_seq_power_stage(codec, 0);
+               }
+               break;
+
+       case SND_SOC_DAPM_POST_PMU:
+               if (rt5631->codec_version) {
+                       onebit_depop_power_stage(codec, 1);
+                       onebit_depop_mute_stage(codec, 1);
+               } else {
+                       depop_seq_power_stage(codec, 1);
+                       depop_seq_mute_stage(codec, 1);
+               }
+               break;
+
+       default:
+               break;
+       }
+
+       return 0;
+}
+
+static int set_dmic_params(struct snd_soc_dapm_widget *w,
+       struct snd_kcontrol *kcontrol, int event)
+{
+       struct snd_soc_codec *codec = w->codec;
+       struct rt5631_priv *rt5631 = snd_soc_codec_get_drvdata(codec);
+
+       switch (rt5631->rx_rate) {
+       case 44100:
+       case 48000:
+               snd_soc_update_bits(codec, RT5631_DIG_MIC_CTRL,
+                       RT5631_DMIC_CLK_CTRL_MASK,
+                       RT5631_DMIC_CLK_CTRL_TO_32FS);
+               break;
+
+       case 32000:
+       case 22050:
+               snd_soc_update_bits(codec, RT5631_DIG_MIC_CTRL,
+                       RT5631_DMIC_CLK_CTRL_MASK,
+                       RT5631_DMIC_CLK_CTRL_TO_64FS);
+               break;
+
+       case 16000:
+       case 11025:
+       case 8000:
+               snd_soc_update_bits(codec, RT5631_DIG_MIC_CTRL,
+                       RT5631_DMIC_CLK_CTRL_MASK,
+                       RT5631_DMIC_CLK_CTRL_TO_128FS);
+               break;
+
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static const struct snd_kcontrol_new rt5631_recmixl_mixer_controls[] = {
+       SOC_DAPM_SINGLE("OUTMIXL Capture Switch", RT5631_ADC_REC_MIXER,
+                       RT5631_M_OUTMIXL_RECMIXL_BIT, 1, 1),
+       SOC_DAPM_SINGLE("MIC1_BST1 Capture Switch", RT5631_ADC_REC_MIXER,
+                       RT5631_M_MIC1_RECMIXL_BIT, 1, 1),
+       SOC_DAPM_SINGLE("AXILVOL Capture Switch", RT5631_ADC_REC_MIXER,
+                       RT5631_M_AXIL_RECMIXL_BIT, 1, 1),
+       SOC_DAPM_SINGLE("MONOIN_RX Capture Switch", RT5631_ADC_REC_MIXER,
+                       RT5631_M_MONO_IN_RECMIXL_BIT, 1, 1),
+};
+
+static const struct snd_kcontrol_new rt5631_recmixr_mixer_controls[] = {
+       SOC_DAPM_SINGLE("MONOIN_RX Capture Switch", RT5631_ADC_REC_MIXER,
+                       RT5631_M_MONO_IN_RECMIXR_BIT, 1, 1),
+       SOC_DAPM_SINGLE("AXIRVOL Capture Switch", RT5631_ADC_REC_MIXER,
+                       RT5631_M_AXIR_RECMIXR_BIT, 1, 1),
+       SOC_DAPM_SINGLE("MIC2_BST2 Capture Switch", RT5631_ADC_REC_MIXER,
+                       RT5631_M_MIC2_RECMIXR_BIT, 1, 1),
+       SOC_DAPM_SINGLE("OUTMIXR Capture Switch", RT5631_ADC_REC_MIXER,
+                       RT5631_M_OUTMIXR_RECMIXR_BIT, 1, 1),
+};
+
+static const struct snd_kcontrol_new rt5631_spkmixl_mixer_controls[] = {
+       SOC_DAPM_SINGLE("RECMIXL Playback Switch", RT5631_SPK_MIXER_CTRL,
+                       RT5631_M_RECMIXL_SPKMIXL_BIT, 1, 1),
+       SOC_DAPM_SINGLE("MIC1_P Playback Switch", RT5631_SPK_MIXER_CTRL,
+                       RT5631_M_MIC1P_SPKMIXL_BIT, 1, 1),
+       SOC_DAPM_SINGLE("DACL Playback Switch", RT5631_SPK_MIXER_CTRL,
+                       RT5631_M_DACL_SPKMIXL_BIT, 1, 1),
+       SOC_DAPM_SINGLE("OUTMIXL Playback Switch", RT5631_SPK_MIXER_CTRL,
+                       RT5631_M_OUTMIXL_SPKMIXL_BIT, 1, 1),
+};
+
+static const struct snd_kcontrol_new rt5631_spkmixr_mixer_controls[] = {
+       SOC_DAPM_SINGLE("OUTMIXR Playback Switch", RT5631_SPK_MIXER_CTRL,
+                       RT5631_M_OUTMIXR_SPKMIXR_BIT, 1, 1),
+       SOC_DAPM_SINGLE("DACR Playback Switch", RT5631_SPK_MIXER_CTRL,
+                       RT5631_M_DACR_SPKMIXR_BIT, 1, 1),
+       SOC_DAPM_SINGLE("MIC2_P Playback Switch", RT5631_SPK_MIXER_CTRL,
+                       RT5631_M_MIC2P_SPKMIXR_BIT, 1, 1),
+       SOC_DAPM_SINGLE("RECMIXR Playback Switch", RT5631_SPK_MIXER_CTRL,
+                       RT5631_M_RECMIXR_SPKMIXR_BIT, 1, 1),
+};
+
+static const struct snd_kcontrol_new rt5631_outmixl_mixer_controls[] = {
+       SOC_DAPM_SINGLE("RECMIXL Playback Switch", RT5631_OUTMIXER_L_CTRL,
+                               RT5631_M_RECMIXL_OUTMIXL_BIT, 1, 1),
+       SOC_DAPM_SINGLE("RECMIXR Playback Switch", RT5631_OUTMIXER_L_CTRL,
+                               RT5631_M_RECMIXR_OUTMIXL_BIT, 1, 1),
+       SOC_DAPM_SINGLE("DACL Playback Switch", RT5631_OUTMIXER_L_CTRL,
+                               RT5631_M_DACL_OUTMIXL_BIT, 1, 1),
+       SOC_DAPM_SINGLE("MIC1_BST1 Playback Switch", RT5631_OUTMIXER_L_CTRL,
+                               RT5631_M_MIC1_OUTMIXL_BIT, 1, 1),
+       SOC_DAPM_SINGLE("MIC2_BST2 Playback Switch", RT5631_OUTMIXER_L_CTRL,
+                               RT5631_M_MIC2_OUTMIXL_BIT, 1, 1),
+       SOC_DAPM_SINGLE("MONOIN_RXP Playback Switch", RT5631_OUTMIXER_L_CTRL,
+                               RT5631_M_MONO_INP_OUTMIXL_BIT, 1, 1),
+       SOC_DAPM_SINGLE("AXILVOL Playback Switch", RT5631_OUTMIXER_L_CTRL,
+                               RT5631_M_AXIL_OUTMIXL_BIT, 1, 1),
+       SOC_DAPM_SINGLE("AXIRVOL Playback Switch", RT5631_OUTMIXER_L_CTRL,
+                               RT5631_M_AXIR_OUTMIXL_BIT, 1, 1),
+       SOC_DAPM_SINGLE("VDAC Playback Switch", RT5631_OUTMIXER_L_CTRL,
+                               RT5631_M_VDAC_OUTMIXL_BIT, 1, 1),
+};
+
+static const struct snd_kcontrol_new rt5631_outmixr_mixer_controls[] = {
+       SOC_DAPM_SINGLE("VDAC Playback Switch", RT5631_OUTMIXER_R_CTRL,
+                               RT5631_M_VDAC_OUTMIXR_BIT, 1, 1),
+       SOC_DAPM_SINGLE("AXIRVOL Playback Switch", RT5631_OUTMIXER_R_CTRL,
+                               RT5631_M_AXIR_OUTMIXR_BIT, 1, 1),
+       SOC_DAPM_SINGLE("AXILVOL Playback Switch", RT5631_OUTMIXER_R_CTRL,
+                               RT5631_M_AXIL_OUTMIXR_BIT, 1, 1),
+       SOC_DAPM_SINGLE("MONOIN_RXN Playback Switch", RT5631_OUTMIXER_R_CTRL,
+                               RT5631_M_MONO_INN_OUTMIXR_BIT, 1, 1),
+       SOC_DAPM_SINGLE("MIC2_BST2 Playback Switch", RT5631_OUTMIXER_R_CTRL,
+                               RT5631_M_MIC2_OUTMIXR_BIT, 1, 1),
+       SOC_DAPM_SINGLE("MIC1_BST1 Playback Switch", RT5631_OUTMIXER_R_CTRL,
+                               RT5631_M_MIC1_OUTMIXR_BIT, 1, 1),
+       SOC_DAPM_SINGLE("DACR Playback Switch", RT5631_OUTMIXER_R_CTRL,
+                               RT5631_M_DACR_OUTMIXR_BIT, 1, 1),
+       SOC_DAPM_SINGLE("RECMIXR Playback Switch", RT5631_OUTMIXER_R_CTRL,
+                               RT5631_M_RECMIXR_OUTMIXR_BIT, 1, 1),
+       SOC_DAPM_SINGLE("RECMIXL Playback Switch", RT5631_OUTMIXER_R_CTRL,
+                               RT5631_M_RECMIXL_OUTMIXR_BIT, 1, 1),
+};
+
+static const struct snd_kcontrol_new rt5631_AXO1MIX_mixer_controls[] = {
+       SOC_DAPM_SINGLE("MIC1_BST1 Playback Switch", RT5631_AXO1MIXER_CTRL,
+                               RT5631_M_MIC1_AXO1MIX_BIT , 1, 1),
+       SOC_DAPM_SINGLE("MIC2_BST2 Playback Switch", RT5631_AXO1MIXER_CTRL,
+                               RT5631_M_MIC2_AXO1MIX_BIT, 1, 1),
+       SOC_DAPM_SINGLE("OUTVOLL Playback Switch", RT5631_AXO1MIXER_CTRL,
+                               RT5631_M_OUTMIXL_AXO1MIX_BIT , 1 , 1),
+       SOC_DAPM_SINGLE("OUTVOLR Playback Switch", RT5631_AXO1MIXER_CTRL,
+                               RT5631_M_OUTMIXR_AXO1MIX_BIT, 1, 1),
+};
+
+static const struct snd_kcontrol_new rt5631_AXO2MIX_mixer_controls[] = {
+       SOC_DAPM_SINGLE("MIC1_BST1 Playback Switch", RT5631_AXO2MIXER_CTRL,
+                               RT5631_M_MIC1_AXO2MIX_BIT, 1, 1),
+       SOC_DAPM_SINGLE("MIC2_BST2 Playback Switch", RT5631_AXO2MIXER_CTRL,
+                               RT5631_M_MIC2_AXO2MIX_BIT, 1, 1),
+       SOC_DAPM_SINGLE("OUTVOLL Playback Switch", RT5631_AXO2MIXER_CTRL,
+                               RT5631_M_OUTMIXL_AXO2MIX_BIT, 1, 1),
+       SOC_DAPM_SINGLE("OUTVOLR Playback Switch", RT5631_AXO2MIXER_CTRL,
+                               RT5631_M_OUTMIXR_AXO2MIX_BIT, 1 , 1),
+};
+
+static const struct snd_kcontrol_new rt5631_spolmix_mixer_controls[] = {
+       SOC_DAPM_SINGLE("SPKVOLL Playback Switch", RT5631_SPK_MONO_OUT_CTRL,
+                               RT5631_M_SPKVOLL_SPOLMIX_BIT, 1, 1),
+       SOC_DAPM_SINGLE("SPKVOLR Playback Switch", RT5631_SPK_MONO_OUT_CTRL,
+                               RT5631_M_SPKVOLR_SPOLMIX_BIT, 1, 1),
+};
+
+static const struct snd_kcontrol_new rt5631_spormix_mixer_controls[] = {
+       SOC_DAPM_SINGLE("SPKVOLL Playback Switch", RT5631_SPK_MONO_OUT_CTRL,
+                               RT5631_M_SPKVOLL_SPORMIX_BIT, 1, 1),
+       SOC_DAPM_SINGLE("SPKVOLR Playback Switch", RT5631_SPK_MONO_OUT_CTRL,
+                               RT5631_M_SPKVOLR_SPORMIX_BIT, 1, 1),
+};
+
+static const struct snd_kcontrol_new rt5631_monomix_mixer_controls[] = {
+       SOC_DAPM_SINGLE("OUTVOLL Playback Switch", RT5631_SPK_MONO_OUT_CTRL,
+                               RT5631_M_OUTVOLL_MONOMIX_BIT, 1, 1),
+       SOC_DAPM_SINGLE("OUTVOLR Playback Switch", RT5631_SPK_MONO_OUT_CTRL,
+                               RT5631_M_OUTVOLR_MONOMIX_BIT, 1, 1),
+};
+
+/* Left SPK Volume Input */
+static const char *rt5631_spkvoll_sel[] = {"Vmid", "SPKMIXL"};
+
+static const SOC_ENUM_SINGLE_DECL(
+       rt5631_spkvoll_enum, RT5631_SPK_OUT_VOL,
+       RT5631_L_EN_SHIFT, rt5631_spkvoll_sel);
+
+static const struct snd_kcontrol_new rt5631_spkvoll_mux_control =
+       SOC_DAPM_ENUM("Left SPKVOL SRC", rt5631_spkvoll_enum);
+
+/* Left HP Volume Input */
+static const char *rt5631_hpvoll_sel[] = {"Vmid", "OUTMIXL"};
+
+static const SOC_ENUM_SINGLE_DECL(
+       rt5631_hpvoll_enum, RT5631_HP_OUT_VOL,
+       RT5631_L_EN_SHIFT, rt5631_hpvoll_sel);
+
+static const struct snd_kcontrol_new rt5631_hpvoll_mux_control =
+       SOC_DAPM_ENUM("Left HPVOL SRC", rt5631_hpvoll_enum);
+
+/* Left Out Volume Input */
+static const char *rt5631_outvoll_sel[] = {"Vmid", "OUTMIXL"};
+
+static const SOC_ENUM_SINGLE_DECL(
+       rt5631_outvoll_enum, RT5631_MONO_AXO_1_2_VOL,
+       RT5631_L_EN_SHIFT, rt5631_outvoll_sel);
+
+static const struct snd_kcontrol_new rt5631_outvoll_mux_control =
+       SOC_DAPM_ENUM("Left OUTVOL SRC", rt5631_outvoll_enum);
+
+/* Right Out Volume Input */
+static const char *rt5631_outvolr_sel[] = {"Vmid", "OUTMIXR"};
+
+static const SOC_ENUM_SINGLE_DECL(
+       rt5631_outvolr_enum, RT5631_MONO_AXO_1_2_VOL,
+       RT5631_R_EN_SHIFT, rt5631_outvolr_sel);
+
+static const struct snd_kcontrol_new rt5631_outvolr_mux_control =
+       SOC_DAPM_ENUM("Right OUTVOL SRC", rt5631_outvolr_enum);
+
+/* Right HP Volume Input */
+static const char *rt5631_hpvolr_sel[] = {"Vmid", "OUTMIXR"};
+
+static const SOC_ENUM_SINGLE_DECL(
+       rt5631_hpvolr_enum, RT5631_HP_OUT_VOL,
+       RT5631_R_EN_SHIFT, rt5631_hpvolr_sel);
+
+static const struct snd_kcontrol_new rt5631_hpvolr_mux_control =
+       SOC_DAPM_ENUM("Right HPVOL SRC", rt5631_hpvolr_enum);
+
+/* Right SPK Volume Input */
+static const char *rt5631_spkvolr_sel[] = {"Vmid", "SPKMIXR"};
+
+static const SOC_ENUM_SINGLE_DECL(
+       rt5631_spkvolr_enum, RT5631_SPK_OUT_VOL,
+       RT5631_R_EN_SHIFT, rt5631_spkvolr_sel);
+
+static const struct snd_kcontrol_new rt5631_spkvolr_mux_control =
+       SOC_DAPM_ENUM("Right SPKVOL SRC", rt5631_spkvolr_enum);
+
+/* SPO Left Channel Input */
+static const char *rt5631_spol_src_sel[] = {
+       "SPOLMIX", "MONOIN_RX", "VDAC", "DACL"};
+
+static const SOC_ENUM_SINGLE_DECL(
+       rt5631_spol_src_enum, RT5631_SPK_MONO_HP_OUT_CTRL,
+       RT5631_SPK_L_MUX_SEL_SHIFT, rt5631_spol_src_sel);
+
+static const struct snd_kcontrol_new rt5631_spol_mux_control =
+       SOC_DAPM_ENUM("SPOL SRC", rt5631_spol_src_enum);
+
+/* SPO Right Channel Input */
+static const char *rt5631_spor_src_sel[] = {
+       "SPORMIX", "MONOIN_RX", "VDAC", "DACR"};
+
+static const SOC_ENUM_SINGLE_DECL(
+       rt5631_spor_src_enum, RT5631_SPK_MONO_HP_OUT_CTRL,
+       RT5631_SPK_R_MUX_SEL_SHIFT, rt5631_spor_src_sel);
+
+static const struct snd_kcontrol_new rt5631_spor_mux_control =
+       SOC_DAPM_ENUM("SPOR SRC", rt5631_spor_src_enum);
+
+/* MONO Input */
+static const char *rt5631_mono_src_sel[] = {"MONOMIX", "MONOIN_RX", "VDAC"};
+
+static const SOC_ENUM_SINGLE_DECL(
+       rt5631_mono_src_enum, RT5631_SPK_MONO_HP_OUT_CTRL,
+       RT5631_MONO_MUX_SEL_SHIFT, rt5631_mono_src_sel);
+
+static const struct snd_kcontrol_new rt5631_mono_mux_control =
+       SOC_DAPM_ENUM("MONO SRC", rt5631_mono_src_enum);
+
+/* Left HPO Input */
+static const char *rt5631_hpl_src_sel[] = {"Left HPVOL", "Left DAC"};
+
+static const SOC_ENUM_SINGLE_DECL(
+       rt5631_hpl_src_enum, RT5631_SPK_MONO_HP_OUT_CTRL,
+       RT5631_HP_L_MUX_SEL_SHIFT, rt5631_hpl_src_sel);
+
+static const struct snd_kcontrol_new rt5631_hpl_mux_control =
+       SOC_DAPM_ENUM("HPL SRC", rt5631_hpl_src_enum);
+
+/* Right HPO Input */
+static const char *rt5631_hpr_src_sel[] = {"Right HPVOL", "Right DAC"};
+
+static const SOC_ENUM_SINGLE_DECL(
+       rt5631_hpr_src_enum, RT5631_SPK_MONO_HP_OUT_CTRL,
+       RT5631_HP_R_MUX_SEL_SHIFT, rt5631_hpr_src_sel);
+
+static const struct snd_kcontrol_new rt5631_hpr_mux_control =
+       SOC_DAPM_ENUM("HPR SRC", rt5631_hpr_src_enum);
+
+static const struct snd_soc_dapm_widget rt5631_dapm_widgets[] = {
+       /* Vmid */
+       SND_SOC_DAPM_VMID("Vmid"),
+       /* PLL1 */
+       SND_SOC_DAPM_SUPPLY("PLL1", RT5631_PWR_MANAG_ADD2,
+                       RT5631_PWR_PLL1_BIT, 0, NULL, 0),
+
+       /* Input Side */
+       /* Input Lines */
+       SND_SOC_DAPM_INPUT("MIC1"),
+       SND_SOC_DAPM_INPUT("MIC2"),
+       SND_SOC_DAPM_INPUT("AXIL"),
+       SND_SOC_DAPM_INPUT("AXIR"),
+       SND_SOC_DAPM_INPUT("MONOIN_RXN"),
+       SND_SOC_DAPM_INPUT("MONOIN_RXP"),
+       SND_SOC_DAPM_INPUT("DMIC"),
+
+       /* MICBIAS */
+       SND_SOC_DAPM_MICBIAS("MIC Bias1", RT5631_PWR_MANAG_ADD2,
+                       RT5631_PWR_MICBIAS1_VOL_BIT, 0),
+       SND_SOC_DAPM_MICBIAS("MIC Bias2", RT5631_PWR_MANAG_ADD2,
+                       RT5631_PWR_MICBIAS2_VOL_BIT, 0),
+
+       /* Boost */
+       SND_SOC_DAPM_PGA("MIC1 Boost", RT5631_PWR_MANAG_ADD2,
+                       RT5631_PWR_MIC1_BOOT_GAIN_BIT, 0, NULL, 0),
+       SND_SOC_DAPM_PGA("MIC2 Boost", RT5631_PWR_MANAG_ADD2,
+                       RT5631_PWR_MIC2_BOOT_GAIN_BIT, 0, NULL, 0),
+       SND_SOC_DAPM_PGA("MONOIN_RXP Boost", RT5631_PWR_MANAG_ADD4,
+                       RT5631_PWR_MONO_IN_P_VOL_BIT, 0, NULL, 0),
+       SND_SOC_DAPM_PGA("MONOIN_RXN Boost", RT5631_PWR_MANAG_ADD4,
+                       RT5631_PWR_MONO_IN_N_VOL_BIT, 0, NULL, 0),
+       SND_SOC_DAPM_PGA("AXIL Boost", RT5631_PWR_MANAG_ADD4,
+                       RT5631_PWR_AXIL_IN_VOL_BIT, 0, NULL, 0),
+       SND_SOC_DAPM_PGA("AXIR Boost", RT5631_PWR_MANAG_ADD4,
+                       RT5631_PWR_AXIR_IN_VOL_BIT, 0, NULL, 0),
+
+       /* MONO In */
+       SND_SOC_DAPM_MIXER("MONO_IN", SND_SOC_NOPM, 0, 0, NULL, 0),
+
+       /* REC Mixer */
+       SND_SOC_DAPM_MIXER("RECMIXL Mixer", RT5631_PWR_MANAG_ADD2,
+               RT5631_PWR_RECMIXER_L_BIT, 0,
+               &rt5631_recmixl_mixer_controls[0],
+               ARRAY_SIZE(rt5631_recmixl_mixer_controls)),
+       SND_SOC_DAPM_MIXER("RECMIXR Mixer", RT5631_PWR_MANAG_ADD2,
+               RT5631_PWR_RECMIXER_R_BIT, 0,
+               &rt5631_recmixr_mixer_controls[0],
+               ARRAY_SIZE(rt5631_recmixr_mixer_controls)),
+       /* Because of record duplication for L/R channel,
+        * L/R ADCs need power up at the same time */
+       SND_SOC_DAPM_MIXER("ADC Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
+
+       /* DMIC */
+       SND_SOC_DAPM_SUPPLY("DMIC Supply", RT5631_DIG_MIC_CTRL,
+               RT5631_DMIC_ENA_SHIFT, 0,
+               set_dmic_params, SND_SOC_DAPM_PRE_PMU),
+       /* ADC Data Srouce */
+       SND_SOC_DAPM_SUPPLY("Left ADC Select", RT5631_INT_ST_IRQ_CTRL_2,
+                       RT5631_ADC_DATA_SEL_MIC1_SHIFT, 0, NULL, 0),
+       SND_SOC_DAPM_SUPPLY("Right ADC Select", RT5631_INT_ST_IRQ_CTRL_2,
+                       RT5631_ADC_DATA_SEL_MIC2_SHIFT, 0, NULL, 0),
+
+       /* ADCs */
+       SND_SOC_DAPM_ADC("Left ADC", "HIFI Capture",
+               RT5631_PWR_MANAG_ADD1, RT5631_PWR_ADC_L_CLK_BIT, 0),
+       SND_SOC_DAPM_ADC("Right ADC", "HIFI Capture",
+               RT5631_PWR_MANAG_ADD1, RT5631_PWR_ADC_R_CLK_BIT, 0),
+
+       /* DAC and ADC supply power */
+       SND_SOC_DAPM_SUPPLY("I2S", RT5631_PWR_MANAG_ADD1,
+                       RT5631_PWR_MAIN_I2S_BIT, 0, NULL, 0),
+       SND_SOC_DAPM_SUPPLY("DAC REF", RT5631_PWR_MANAG_ADD1,
+                       RT5631_PWR_DAC_REF_BIT, 0, NULL, 0),
+
+       /* Output Side */
+       /* DACs */
+       SND_SOC_DAPM_DAC("Left DAC", "HIFI Playback",
+               RT5631_PWR_MANAG_ADD1, RT5631_PWR_DAC_L_CLK_BIT, 0),
+       SND_SOC_DAPM_DAC("Right DAC", "HIFI Playback",
+               RT5631_PWR_MANAG_ADD1, RT5631_PWR_DAC_R_CLK_BIT, 0),
+       SND_SOC_DAPM_DAC("Voice DAC", "Voice DAC Mono Playback",
+                               SND_SOC_NOPM, 0, 0),
+       SND_SOC_DAPM_PGA("Voice DAC Boost", SND_SOC_NOPM, 0, 0, NULL, 0),
+       /* DAC supply power */
+       SND_SOC_DAPM_SUPPLY("Left DAC To Mixer", RT5631_PWR_MANAG_ADD1,
+                       RT5631_PWR_DAC_L_TO_MIXER_BIT, 0, NULL, 0),
+       SND_SOC_DAPM_SUPPLY("Right DAC To Mixer", RT5631_PWR_MANAG_ADD1,
+                       RT5631_PWR_DAC_R_TO_MIXER_BIT, 0, NULL, 0),
+
+       /* Left SPK Mixer */
+       SND_SOC_DAPM_MIXER("SPKMIXL Mixer", RT5631_PWR_MANAG_ADD2,
+                       RT5631_PWR_SPKMIXER_L_BIT, 0,
+                       &rt5631_spkmixl_mixer_controls[0],
+                       ARRAY_SIZE(rt5631_spkmixl_mixer_controls)),
+       /* Left Out Mixer */
+       SND_SOC_DAPM_MIXER("OUTMIXL Mixer", RT5631_PWR_MANAG_ADD2,
+                       RT5631_PWR_OUTMIXER_L_BIT, 0,
+                       &rt5631_outmixl_mixer_controls[0],
+                       ARRAY_SIZE(rt5631_outmixl_mixer_controls)),
+       /* Right Out Mixer */
+       SND_SOC_DAPM_MIXER("OUTMIXR Mixer", RT5631_PWR_MANAG_ADD2,
+                       RT5631_PWR_OUTMIXER_R_BIT, 0,
+                       &rt5631_outmixr_mixer_controls[0],
+                       ARRAY_SIZE(rt5631_outmixr_mixer_controls)),
+       /* Right SPK Mixer */
+       SND_SOC_DAPM_MIXER("SPKMIXR Mixer", RT5631_PWR_MANAG_ADD2,
+                       RT5631_PWR_SPKMIXER_R_BIT, 0,
+                       &rt5631_spkmixr_mixer_controls[0],
+                       ARRAY_SIZE(rt5631_spkmixr_mixer_controls)),
+
+       /* Volume Mux */
+       SND_SOC_DAPM_MUX("Left SPKVOL Mux", RT5631_PWR_MANAG_ADD4,
+                       RT5631_PWR_SPK_L_VOL_BIT, 0,
+                       &rt5631_spkvoll_mux_control),
+       SND_SOC_DAPM_MUX("Left HPVOL Mux", RT5631_PWR_MANAG_ADD4,
+                       RT5631_PWR_HP_L_OUT_VOL_BIT, 0,
+                       &rt5631_hpvoll_mux_control),
+       SND_SOC_DAPM_MUX("Left OUTVOL Mux", RT5631_PWR_MANAG_ADD4,
+                       RT5631_PWR_LOUT_VOL_BIT, 0,
+                       &rt5631_outvoll_mux_control),
+       SND_SOC_DAPM_MUX("Right OUTVOL Mux", RT5631_PWR_MANAG_ADD4,
+                       RT5631_PWR_ROUT_VOL_BIT, 0,
+                       &rt5631_outvolr_mux_control),
+       SND_SOC_DAPM_MUX("Right HPVOL Mux", RT5631_PWR_MANAG_ADD4,
+                       RT5631_PWR_HP_R_OUT_VOL_BIT, 0,
+                       &rt5631_hpvolr_mux_control),
+       SND_SOC_DAPM_MUX("Right SPKVOL Mux", RT5631_PWR_MANAG_ADD4,
+                       RT5631_PWR_SPK_R_VOL_BIT, 0,
+                       &rt5631_spkvolr_mux_control),
+
+       /* DAC To HP */
+       SND_SOC_DAPM_PGA_S("Left DAC_HP", 0, SND_SOC_NOPM, 0, 0, NULL, 0),
+       SND_SOC_DAPM_PGA_S("Right DAC_HP", 0, SND_SOC_NOPM, 0, 0, NULL, 0),
+
+       /* HP Depop */
+       SND_SOC_DAPM_PGA_S("HP Depop", 1, SND_SOC_NOPM, 0, 0,
+               hp_event, SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),
+
+       /* AXO1 Mixer */
+       SND_SOC_DAPM_MIXER("AXO1MIX Mixer", RT5631_PWR_MANAG_ADD3,
+                       RT5631_PWR_AXO1MIXER_BIT, 0,
+                       &rt5631_AXO1MIX_mixer_controls[0],
+                       ARRAY_SIZE(rt5631_AXO1MIX_mixer_controls)),
+       /* SPOL Mixer */
+       SND_SOC_DAPM_MIXER("SPOLMIX Mixer", SND_SOC_NOPM, 0, 0,
+                       &rt5631_spolmix_mixer_controls[0],
+                       ARRAY_SIZE(rt5631_spolmix_mixer_controls)),
+       /* MONO Mixer */
+       SND_SOC_DAPM_MIXER("MONOMIX Mixer", RT5631_PWR_MANAG_ADD3,
+                       RT5631_PWR_MONOMIXER_BIT, 0,
+                       &rt5631_monomix_mixer_controls[0],
+                       ARRAY_SIZE(rt5631_monomix_mixer_controls)),
+       /* SPOR Mixer */
+       SND_SOC_DAPM_MIXER("SPORMIX Mixer", SND_SOC_NOPM, 0, 0,
+                       &rt5631_spormix_mixer_controls[0],
+                       ARRAY_SIZE(rt5631_spormix_mixer_controls)),
+       /* AXO2 Mixer */
+       SND_SOC_DAPM_MIXER("AXO2MIX Mixer", RT5631_PWR_MANAG_ADD3,
+                       RT5631_PWR_AXO2MIXER_BIT, 0,
+                       &rt5631_AXO2MIX_mixer_controls[0],
+                       ARRAY_SIZE(rt5631_AXO2MIX_mixer_controls)),
+
+       /* Mux */
+       SND_SOC_DAPM_MUX("SPOL Mux", SND_SOC_NOPM, 0, 0,
+                       &rt5631_spol_mux_control),
+       SND_SOC_DAPM_MUX("SPOR Mux", SND_SOC_NOPM, 0, 0,
+                       &rt5631_spor_mux_control),
+       SND_SOC_DAPM_MUX("MONO Mux", SND_SOC_NOPM, 0, 0,
+                       &rt5631_mono_mux_control),
+       SND_SOC_DAPM_MUX("HPL Mux", SND_SOC_NOPM, 0, 0,
+                       &rt5631_hpl_mux_control),
+       SND_SOC_DAPM_MUX("HPR Mux", SND_SOC_NOPM, 0, 0,
+                       &rt5631_hpr_mux_control),
+
+       /* AMP supply */
+       SND_SOC_DAPM_SUPPLY("MONO Depop", RT5631_PWR_MANAG_ADD3,
+                       RT5631_PWR_MONO_DEPOP_DIS_BIT, 0, NULL, 0),
+       SND_SOC_DAPM_SUPPLY("Class D", RT5631_PWR_MANAG_ADD1,
+                       RT5631_PWR_CLASS_D_BIT, 0, NULL, 0),
+
+       /* Output Lines */
+       SND_SOC_DAPM_OUTPUT("AUXO1"),
+       SND_SOC_DAPM_OUTPUT("AUXO2"),
+       SND_SOC_DAPM_OUTPUT("SPOL"),
+       SND_SOC_DAPM_OUTPUT("SPOR"),
+       SND_SOC_DAPM_OUTPUT("HPOL"),
+       SND_SOC_DAPM_OUTPUT("HPOR"),
+       SND_SOC_DAPM_OUTPUT("MONO"),
+};
+
+static const struct snd_soc_dapm_route rt5631_dapm_routes[] = {
+       {"MIC1 Boost", NULL, "MIC1"},
+       {"MIC2 Boost", NULL, "MIC2"},
+       {"MONOIN_RXP Boost", NULL, "MONOIN_RXP"},
+       {"MONOIN_RXN Boost", NULL, "MONOIN_RXN"},
+       {"AXIL Boost", NULL, "AXIL"},
+       {"AXIR Boost", NULL, "AXIR"},
+
+       {"MONO_IN", NULL, "MONOIN_RXP Boost"},
+       {"MONO_IN", NULL, "MONOIN_RXN Boost"},
+
+       {"RECMIXL Mixer", "OUTMIXL Capture Switch", "OUTMIXL Mixer"},
+       {"RECMIXL Mixer", "MIC1_BST1 Capture Switch", "MIC1 Boost"},
+       {"RECMIXL Mixer", "AXILVOL Capture Switch", "AXIL Boost"},
+       {"RECMIXL Mixer", "MONOIN_RX Capture Switch", "MONO_IN"},
+
+       {"RECMIXR Mixer", "OUTMIXR Capture Switch", "OUTMIXR Mixer"},
+       {"RECMIXR Mixer", "MIC2_BST2 Capture Switch", "MIC2 Boost"},
+       {"RECMIXR Mixer", "AXIRVOL Capture Switch", "AXIR Boost"},
+       {"RECMIXR Mixer", "MONOIN_RX Capture Switch", "MONO_IN"},
+
+       {"ADC Mixer", NULL, "RECMIXL Mixer"},
+       {"ADC Mixer", NULL, "RECMIXR Mixer"},
+
+       {"Left ADC", NULL, "ADC Mixer"},
+       {"Left ADC", NULL, "Left ADC Select", check_adcl_select},
+       {"Left ADC", NULL, "PLL1", check_sysclk1_source},
+       {"Left ADC", NULL, "I2S"},
+       {"Left ADC", NULL, "DAC REF"},
+
+       {"Right ADC", NULL, "ADC Mixer"},
+       {"Right ADC", NULL, "Right ADC Select", check_adcr_select},
+       {"Right ADC", NULL, "PLL1", check_sysclk1_source},
+       {"Right ADC", NULL, "I2S"},
+       {"Right ADC", NULL, "DAC REF"},
+
+       {"DMIC", NULL, "DMIC Supply", check_dmic_used},
+       {"Left ADC", NULL, "DMIC"},
+       {"Right ADC", NULL, "DMIC"},
+
+       {"Left DAC", NULL, "PLL1", check_sysclk1_source},
+       {"Left DAC", NULL, "I2S"},
+       {"Left DAC", NULL, "DAC REF"},
+       {"Right DAC", NULL, "PLL1", check_sysclk1_source},
+       {"Right DAC", NULL, "I2S"},
+       {"Right DAC", NULL, "DAC REF"},
+
+       {"Voice DAC Boost", NULL, "Voice DAC"},
+
+       {"SPKMIXL Mixer", NULL, "Left DAC To Mixer", check_dacl_to_spkmixl},
+       {"SPKMIXL Mixer", "RECMIXL Playback Switch", "RECMIXL Mixer"},
+       {"SPKMIXL Mixer", "MIC1_P Playback Switch", "MIC1"},
+       {"SPKMIXL Mixer", "DACL Playback Switch", "Left DAC"},
+       {"SPKMIXL Mixer", "OUTMIXL Playback Switch", "OUTMIXL Mixer"},
+
+       {"SPKMIXR Mixer", NULL, "Right DAC To Mixer", check_dacr_to_spkmixr},
+       {"SPKMIXR Mixer", "OUTMIXR Playback Switch", "OUTMIXR Mixer"},
+       {"SPKMIXR Mixer", "DACR Playback Switch", "Right DAC"},
+       {"SPKMIXR Mixer", "MIC2_P Playback Switch", "MIC2"},
+       {"SPKMIXR Mixer", "RECMIXR Playback Switch", "RECMIXR Mixer"},
+
+       {"OUTMIXL Mixer", NULL, "Left DAC To Mixer", check_dacl_to_outmixl},
+       {"OUTMIXL Mixer", "RECMIXL Playback Switch", "RECMIXL Mixer"},
+       {"OUTMIXL Mixer", "RECMIXR Playback Switch", "RECMIXR Mixer"},
+       {"OUTMIXL Mixer", "DACL Playback Switch", "Left DAC"},
+       {"OUTMIXL Mixer", "MIC1_BST1 Playback Switch", "MIC1 Boost"},
+       {"OUTMIXL Mixer", "MIC2_BST2 Playback Switch", "MIC2 Boost"},
+       {"OUTMIXL Mixer", "MONOIN_RXP Playback Switch", "MONOIN_RXP Boost"},
+       {"OUTMIXL Mixer", "AXILVOL Playback Switch", "AXIL Boost"},
+       {"OUTMIXL Mixer", "AXIRVOL Playback Switch", "AXIR Boost"},
+       {"OUTMIXL Mixer", "VDAC Playback Switch", "Voice DAC Boost"},
+
+       {"OUTMIXR Mixer", NULL, "Right DAC To Mixer", check_dacr_to_outmixr},
+       {"OUTMIXR Mixer", "RECMIXL Playback Switch", "RECMIXL Mixer"},
+       {"OUTMIXR Mixer", "RECMIXR Playback Switch", "RECMIXR Mixer"},
+       {"OUTMIXR Mixer", "DACR Playback Switch", "Right DAC"},
+       {"OUTMIXR Mixer", "MIC1_BST1 Playback Switch", "MIC1 Boost"},
+       {"OUTMIXR Mixer", "MIC2_BST2 Playback Switch", "MIC2 Boost"},
+       {"OUTMIXR Mixer", "MONOIN_RXN Playback Switch", "MONOIN_RXN Boost"},
+       {"OUTMIXR Mixer", "AXILVOL Playback Switch", "AXIL Boost"},
+       {"OUTMIXR Mixer", "AXIRVOL Playback Switch", "AXIR Boost"},
+       {"OUTMIXR Mixer", "VDAC Playback Switch", "Voice DAC Boost"},
+
+       {"Left SPKVOL Mux",  "SPKMIXL", "SPKMIXL Mixer"},
+       {"Left SPKVOL Mux",  "Vmid", "Vmid"},
+       {"Left HPVOL Mux",  "OUTMIXL", "OUTMIXL Mixer"},
+       {"Left HPVOL Mux",  "Vmid", "Vmid"},
+       {"Left OUTVOL Mux",  "OUTMIXL", "OUTMIXL Mixer"},
+       {"Left OUTVOL Mux",  "Vmid", "Vmid"},
+       {"Right OUTVOL Mux",  "OUTMIXR", "OUTMIXR Mixer"},
+       {"Right OUTVOL Mux",  "Vmid", "Vmid"},
+       {"Right HPVOL Mux",  "OUTMIXR", "OUTMIXR Mixer"},
+       {"Right HPVOL Mux",  "Vmid", "Vmid"},
+       {"Right SPKVOL Mux",  "SPKMIXR", "SPKMIXR Mixer"},
+       {"Right SPKVOL Mux",  "Vmid", "Vmid"},
+
+       {"AXO1MIX Mixer", "MIC1_BST1 Playback Switch", "MIC1 Boost"},
+       {"AXO1MIX Mixer", "OUTVOLL Playback Switch", "Left OUTVOL Mux"},
+       {"AXO1MIX Mixer", "OUTVOLR Playback Switch", "Right OUTVOL Mux"},
+       {"AXO1MIX Mixer", "MIC2_BST2 Playback Switch", "MIC2 Boost"},
+
+       {"AXO2MIX Mixer", "MIC1_BST1 Playback Switch", "MIC1 Boost"},
+       {"AXO2MIX Mixer", "OUTVOLL Playback Switch", "Left OUTVOL Mux"},
+       {"AXO2MIX Mixer", "OUTVOLR Playback Switch", "Right OUTVOL Mux"},
+       {"AXO2MIX Mixer", "MIC2_BST2 Playback Switch", "MIC2 Boost"},
+
+       {"SPOLMIX Mixer", "SPKVOLL Playback Switch", "Left SPKVOL Mux"},
+       {"SPOLMIX Mixer", "SPKVOLR Playback Switch", "Right SPKVOL Mux"},
+
+       {"SPORMIX Mixer", "SPKVOLL Playback Switch", "Left SPKVOL Mux"},
+       {"SPORMIX Mixer", "SPKVOLR Playback Switch", "Right SPKVOL Mux"},
+
+       {"MONOMIX Mixer", "OUTVOLL Playback Switch", "Left OUTVOL Mux"},
+       {"MONOMIX Mixer", "OUTVOLR Playback Switch", "Right OUTVOL Mux"},
+
+       {"SPOL Mux", "SPOLMIX", "SPOLMIX Mixer"},
+       {"SPOL Mux", "MONOIN_RX", "MONO_IN"},
+       {"SPOL Mux", "VDAC", "Voice DAC Boost"},
+       {"SPOL Mux", "DACL", "Left DAC"},
+
+       {"SPOR Mux", "SPORMIX", "SPORMIX Mixer"},
+       {"SPOR Mux", "MONOIN_RX", "MONO_IN"},
+       {"SPOR Mux", "VDAC", "Voice DAC Boost"},
+       {"SPOR Mux", "DACR", "Right DAC"},
+
+       {"MONO Mux", "MONOMIX", "MONOMIX Mixer"},
+       {"MONO Mux", "MONOIN_RX", "MONO_IN"},
+       {"MONO Mux", "VDAC", "Voice DAC Boost"},
+
+       {"Right DAC_HP", NULL, "Right DAC"},
+       {"Left DAC_HP", NULL, "Left DAC"},
+
+       {"HPL Mux", "Left HPVOL", "Left HPVOL Mux"},
+       {"HPL Mux", "Left DAC", "Left DAC_HP"},
+       {"HPR Mux", "Right HPVOL", "Right HPVOL Mux"},
+       {"HPR Mux", "Right DAC", "Right DAC_HP"},
+
+       {"HP Depop", NULL, "HPL Mux"},
+       {"HP Depop", NULL, "HPR Mux"},
+
+       {"AUXO1", NULL, "AXO1MIX Mixer"},
+       {"AUXO2", NULL, "AXO2MIX Mixer"},
+
+       {"SPOL", NULL, "Class D"},
+       {"SPOL", NULL, "SPOL Mux"},
+       {"SPOR", NULL, "Class D"},
+       {"SPOR", NULL, "SPOR Mux"},
+
+       {"HPOL", NULL, "HP Depop"},
+       {"HPOR", NULL, "HP Depop"},
+
+       {"MONO", NULL, "MONO Depop"},
+       {"MONO", NULL, "MONO Mux"},
+};
+
+struct coeff_clk_div {
+       u32 mclk;
+       u32 bclk;
+       u32 rate;
+       u16 reg_val;
+};
+
+/* PLL divisors */
+struct pll_div {
+       u32 pll_in;
+       u32 pll_out;
+       u16 reg_val;
+};
+
+static const struct pll_div codec_master_pll_div[] = {
+       {2048000,  8192000,  0x0ea0},
+       {3686400,  8192000,  0x4e27},
+       {12000000,  8192000,  0x456b},
+       {13000000,  8192000,  0x495f},
+       {13100000,  8192000,  0x0320},
+       {2048000,  11289600,  0xf637},
+       {3686400,  11289600,  0x2f22},
+       {12000000,  11289600,  0x3e2f},
+       {13000000,  11289600,  0x4d5b},
+       {13100000,  11289600,  0x363b},
+       {2048000,  16384000,  0x1ea0},
+       {3686400,  16384000,  0x9e27},
+       {12000000,  16384000,  0x452b},
+       {13000000,  16384000,  0x542f},
+       {13100000,  16384000,  0x03a0},
+       {2048000,  16934400,  0xe625},
+       {3686400,  16934400,  0x9126},
+       {12000000,  16934400,  0x4d2c},
+       {13000000,  16934400,  0x742f},
+       {13100000,  16934400,  0x3c27},
+       {2048000,  22579200,  0x2aa0},
+       {3686400,  22579200,  0x2f20},
+       {12000000,  22579200,  0x7e2f},
+       {13000000,  22579200,  0x742f},
+       {13100000,  22579200,  0x3c27},
+       {2048000,  24576000,  0x2ea0},
+       {3686400,  24576000,  0xee27},
+       {12000000,  24576000,  0x2915},
+       {13000000,  24576000,  0x772e},
+       {13100000,  24576000,  0x0d20},
+       {26000000,  24576000,  0x2027},
+       {26000000,  22579200,  0x392f},
+       {24576000,  22579200,  0x0921},
+       {24576000,  24576000,  0x02a0},
+};
+
+static const struct pll_div codec_slave_pll_div[] = {
+       {256000,  2048000,  0x46f0},
+       {256000,  4096000,  0x3ea0},
+       {352800,  5644800,  0x3ea0},
+       {512000,  8192000,  0x3ea0},
+       {1024000,  8192000,  0x46f0},
+       {705600,  11289600,  0x3ea0},
+       {1024000,  16384000,  0x3ea0},
+       {1411200,  22579200,  0x3ea0},
+       {1536000,  24576000,  0x3ea0},
+       {2048000,  16384000,  0x1ea0},
+       {2822400,  22579200,  0x1ea0},
+       {2822400,  45158400,  0x5ec0},
+       {5644800,  45158400,  0x46f0},
+       {3072000,  24576000,  0x1ea0},
+       {3072000,  49152000,  0x5ec0},
+       {6144000,  49152000,  0x46f0},
+       {705600,  11289600,  0x3ea0},
+       {705600,  8467200,  0x3ab0},
+       {24576000,  24576000,  0x02a0},
+       {1411200,  11289600,  0x1690},
+       {2822400,  11289600,  0x0a90},
+       {1536000,  12288000,  0x1690},
+       {3072000,  12288000,  0x0a90},
+};
+
+static struct coeff_clk_div coeff_div[] = {
+       /* sysclk is 256fs */
+       {2048000,  8000 * 32,  8000, 0x1000},
+       {2048000,  8000 * 64,  8000, 0x0000},
+       {2822400,  11025 * 32,  11025,  0x1000},
+       {2822400,  11025 * 64,  11025,  0x0000},
+       {4096000,  16000 * 32,  16000,  0x1000},
+       {4096000,  16000 * 64,  16000,  0x0000},
+       {5644800,  22050 * 32,  22050,  0x1000},
+       {5644800,  22050 * 64,  22050,  0x0000},
+       {8192000,  32000 * 32,  32000,  0x1000},
+       {8192000,  32000 * 64,  32000,  0x0000},
+       {11289600,  44100 * 32,  44100,  0x1000},
+       {11289600,  44100 * 64,  44100,  0x0000},
+       {12288000,  48000 * 32,  48000,  0x1000},
+       {12288000,  48000 * 64,  48000,  0x0000},
+       {22579200,  88200 * 32,  88200,  0x1000},
+       {22579200,  88200 * 64,  88200,  0x0000},
+       {24576000,  96000 * 32,  96000,  0x1000},
+       {24576000,  96000 * 64,  96000,  0x0000},
+       /* sysclk is 512fs */
+       {4096000,  8000 * 32,  8000, 0x3000},
+       {4096000,  8000 * 64,  8000, 0x2000},
+       {5644800,  11025 * 32,  11025, 0x3000},
+       {5644800,  11025 * 64,  11025, 0x2000},
+       {8192000,  16000 * 32,  16000, 0x3000},
+       {8192000,  16000 * 64,  16000, 0x2000},
+       {11289600,  22050 * 32,  22050, 0x3000},
+       {11289600,  22050 * 64,  22050, 0x2000},
+       {16384000,  32000 * 32,  32000, 0x3000},
+       {16384000,  32000 * 64,  32000, 0x2000},
+       {22579200,  44100 * 32,  44100, 0x3000},
+       {22579200,  44100 * 64,  44100, 0x2000},
+       {24576000,  48000 * 32,  48000, 0x3000},
+       {24576000,  48000 * 64,  48000, 0x2000},
+       {45158400,  88200 * 32,  88200, 0x3000},
+       {45158400,  88200 * 64,  88200, 0x2000},
+       {49152000,  96000 * 32,  96000, 0x3000},
+       {49152000,  96000 * 64,  96000, 0x2000},
+       /* sysclk is 24.576Mhz or 22.5792Mhz */
+       {24576000,  8000 * 32,  8000,  0x7080},
+       {24576000,  8000 * 64,  8000,  0x6080},
+       {24576000,  16000 * 32,  16000,  0x5080},
+       {24576000,  16000 * 64,  16000,  0x4080},
+       {24576000,  24000 * 32,  24000,  0x5000},
+       {24576000,  24000 * 64,  24000,  0x4000},
+       {24576000,  32000 * 32,  32000,  0x3080},
+       {24576000,  32000 * 64,  32000,  0x2080},
+       {22579200,  11025 * 32,  11025,  0x7000},
+       {22579200,  11025 * 64,  11025,  0x6000},
+       {22579200,  22050 * 32,  22050,  0x5000},
+       {22579200,  22050 * 64,  22050,  0x4000},
+};
+
+static int get_coeff(int mclk, int rate, int timesofbclk)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(coeff_div); i++) {
+               if (coeff_div[i].mclk == mclk && coeff_div[i].rate == rate &&
+                       (coeff_div[i].bclk / coeff_div[i].rate) == timesofbclk)
+                       return i;
+       }
+       return -EINVAL;
+}
+
+static int rt5631_hifi_pcm_params(struct snd_pcm_substream *substream,
+               struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_codec *codec = rtd->codec;
+       struct rt5631_priv *rt5631 = snd_soc_codec_get_drvdata(codec);
+       int timesofbclk = 32, coeff;
+       unsigned int iface = 0;
+
+       dev_dbg(codec->dev, "enter %s\n", __func__);
+
+       rt5631->bclk_rate = snd_soc_params_to_bclk(params);
+       if (rt5631->bclk_rate < 0) {
+               dev_err(codec->dev, "Fail to get BCLK rate\n");
+               return rt5631->bclk_rate;
+       }
+       rt5631->rx_rate = params_rate(params);
+
+       if (rt5631->master)
+               coeff = get_coeff(rt5631->sysclk, rt5631->rx_rate,
+                       rt5631->bclk_rate / rt5631->rx_rate);
+       else
+               coeff = get_coeff(rt5631->sysclk, rt5631->rx_rate,
+                                       timesofbclk);
+       if (coeff < 0) {
+               dev_err(codec->dev, "Fail to get coeff\n");
+               return -EINVAL;
+       }
+
+       switch (params_format(params)) {
+       case SNDRV_PCM_FORMAT_S16_LE:
+               break;
+       case SNDRV_PCM_FORMAT_S20_3LE:
+               iface |= RT5631_SDP_I2S_DL_20;
+               break;
+       case SNDRV_PCM_FORMAT_S24_LE:
+               iface |= RT5631_SDP_I2S_DL_24;
+               break;
+       case SNDRV_PCM_FORMAT_S8:
+               iface |= RT5631_SDP_I2S_DL_8;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       snd_soc_update_bits(codec, RT5631_SDP_CTRL,
+               RT5631_SDP_I2S_DL_MASK, iface);
+       snd_soc_write(codec, RT5631_STEREO_AD_DA_CLK_CTRL,
+                                       coeff_div[coeff].reg_val);
+
+       return 0;
+}
+
+static int rt5631_hifi_codec_set_dai_fmt(struct snd_soc_dai *codec_dai,
+                                               unsigned int fmt)
+{
+       struct snd_soc_codec *codec = codec_dai->codec;
+       struct rt5631_priv *rt5631 = snd_soc_codec_get_drvdata(codec);
+       unsigned int iface = 0;
+
+       dev_dbg(codec->dev, "enter %s\n", __func__);
+
+       switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
+       case SND_SOC_DAIFMT_CBM_CFM:
+               rt5631->master = 1;
+               break;
+       case SND_SOC_DAIFMT_CBS_CFS:
+               iface |= RT5631_SDP_MODE_SEL_SLAVE;
+               rt5631->master = 0;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+       case SND_SOC_DAIFMT_I2S:
+               break;
+       case SND_SOC_DAIFMT_LEFT_J:
+               iface |= RT5631_SDP_I2S_DF_LEFT;
+               break;
+       case SND_SOC_DAIFMT_DSP_A:
+               iface |= RT5631_SDP_I2S_DF_PCM_A;
+               break;
+       case SND_SOC_DAIFMT_DSP_B:
+               iface  |= RT5631_SDP_I2S_DF_PCM_B;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
+       case SND_SOC_DAIFMT_NB_NF:
+               break;
+       case SND_SOC_DAIFMT_IB_NF:
+               iface |= RT5631_SDP_I2S_BCLK_POL_CTRL;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       snd_soc_write(codec, RT5631_SDP_CTRL, iface);
+
+       return 0;
+}
+
+static int rt5631_hifi_codec_set_dai_sysclk(struct snd_soc_dai *codec_dai,
+                               int clk_id, unsigned int freq, int dir)
+{
+       struct snd_soc_codec *codec = codec_dai->codec;
+       struct rt5631_priv *rt5631 = snd_soc_codec_get_drvdata(codec);
+
+       dev_dbg(codec->dev, "enter %s, syclk=%d\n", __func__, freq);
+
+       if ((freq >= (256 * 8000)) && (freq <= (512 * 96000))) {
+               rt5631->sysclk = freq;
+               return 0;
+       }
+
+       return -EINVAL;
+}
+
+static int rt5631_codec_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
+               int source, unsigned int freq_in, unsigned int freq_out)
+{
+       struct snd_soc_codec *codec = codec_dai->codec;
+       struct rt5631_priv *rt5631 = snd_soc_codec_get_drvdata(codec);
+       int i, ret = -EINVAL;
+
+       dev_dbg(codec->dev, "enter %s\n", __func__);
+
+       if (!freq_in || !freq_out) {
+               dev_dbg(codec->dev, "PLL disabled\n");
+
+               snd_soc_update_bits(codec, RT5631_GLOBAL_CLK_CTRL,
+                       RT5631_SYSCLK_SOUR_SEL_MASK,
+                       RT5631_SYSCLK_SOUR_SEL_MCLK);
+
+               return 0;
+       }
+
+       if (rt5631->master) {
+               for (i = 0; i < ARRAY_SIZE(codec_master_pll_div); i++)
+                       if (freq_in == codec_master_pll_div[i].pll_in &&
+                       freq_out == codec_master_pll_div[i].pll_out) {
+                               dev_info(codec->dev,
+                                       "change PLL in master mode\n");
+                               snd_soc_write(codec, RT5631_PLL_CTRL,
+                                       codec_master_pll_div[i].reg_val);
+                               schedule_timeout_uninterruptible(
+                                       msecs_to_jiffies(20));
+                               snd_soc_update_bits(codec,
+                                       RT5631_GLOBAL_CLK_CTRL,
+                                       RT5631_SYSCLK_SOUR_SEL_MASK |
+                                       RT5631_PLLCLK_SOUR_SEL_MASK,
+                                       RT5631_SYSCLK_SOUR_SEL_PLL |
+                                       RT5631_PLLCLK_SOUR_SEL_MCLK);
+                               ret = 0;
+                               break;
+                       }
+       } else {
+               for (i = 0; i < ARRAY_SIZE(codec_slave_pll_div); i++)
+                       if (freq_in == codec_slave_pll_div[i].pll_in &&
+                       freq_out == codec_slave_pll_div[i].pll_out) {
+                               dev_info(codec->dev,
+                                       "change PLL in slave mode\n");
+                               snd_soc_write(codec, RT5631_PLL_CTRL,
+                                       codec_slave_pll_div[i].reg_val);
+                               schedule_timeout_uninterruptible(
+                                       msecs_to_jiffies(20));
+                               snd_soc_update_bits(codec,
+                                       RT5631_GLOBAL_CLK_CTRL,
+                                       RT5631_SYSCLK_SOUR_SEL_MASK |
+                                       RT5631_PLLCLK_SOUR_SEL_MASK,
+                                       RT5631_SYSCLK_SOUR_SEL_PLL |
+                                       RT5631_PLLCLK_SOUR_SEL_BCLK);
+                               ret = 0;
+                               break;
+                       }
+       }
+
+       return ret;
+}
+
+static int rt5631_set_bias_level(struct snd_soc_codec *codec,
+                       enum snd_soc_bias_level level)
+{
+       switch (level) {
+       case SND_SOC_BIAS_ON:
+       case SND_SOC_BIAS_PREPARE:
+               snd_soc_update_bits(codec, RT5631_PWR_MANAG_ADD2,
+                       RT5631_PWR_MICBIAS1_VOL | RT5631_PWR_MICBIAS2_VOL,
+                       RT5631_PWR_MICBIAS1_VOL | RT5631_PWR_MICBIAS2_VOL);
+               break;
+
+       case SND_SOC_BIAS_STANDBY:
+               if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
+                       snd_soc_update_bits(codec, RT5631_PWR_MANAG_ADD3,
+                               RT5631_PWR_VREF | RT5631_PWR_MAIN_BIAS,
+                               RT5631_PWR_VREF | RT5631_PWR_MAIN_BIAS);
+                       msleep(80);
+                       snd_soc_update_bits(codec, RT5631_PWR_MANAG_ADD3,
+                               RT5631_PWR_FAST_VREF_CTRL,
+                               RT5631_PWR_FAST_VREF_CTRL);
+                       codec->cache_only = false;
+                       snd_soc_cache_sync(codec);
+               }
+               break;
+
+       case SND_SOC_BIAS_OFF:
+               snd_soc_write(codec, RT5631_PWR_MANAG_ADD1, 0x0000);
+               snd_soc_write(codec, RT5631_PWR_MANAG_ADD2, 0x0000);
+               snd_soc_write(codec, RT5631_PWR_MANAG_ADD3, 0x0000);
+               snd_soc_write(codec, RT5631_PWR_MANAG_ADD4, 0x0000);
+               break;
+
+       default:
+               break;
+       }
+       codec->dapm.bias_level = level;
+
+       return 0;
+}
+
+static int rt5631_probe(struct snd_soc_codec *codec)
+{
+       struct rt5631_priv *rt5631 = snd_soc_codec_get_drvdata(codec);
+       unsigned int val;
+       int ret;
+
+       ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_I2C);
+       if (ret != 0) {
+               dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
+               return ret;
+       }
+
+       val = rt5631_read_index(codec, RT5631_ADDA_MIXER_INTL_REG3);
+       if (val & 0x0002)
+               rt5631->codec_version = 1;
+       else
+               rt5631->codec_version = 0;
+
+       rt5631_reset(codec);
+       snd_soc_update_bits(codec, RT5631_PWR_MANAG_ADD3,
+               RT5631_PWR_VREF | RT5631_PWR_MAIN_BIAS,
+               RT5631_PWR_VREF | RT5631_PWR_MAIN_BIAS);
+       msleep(80);
+       snd_soc_update_bits(codec, RT5631_PWR_MANAG_ADD3,
+               RT5631_PWR_FAST_VREF_CTRL, RT5631_PWR_FAST_VREF_CTRL);
+       /* enable HP zero cross */
+       snd_soc_write(codec, RT5631_INT_ST_IRQ_CTRL_2, 0x0f18);
+       /* power off ClassD auto Recovery */
+       if (rt5631->codec_version)
+               snd_soc_update_bits(codec, RT5631_INT_ST_IRQ_CTRL_2,
+                                       0x2000, 0x2000);
+       else
+               snd_soc_update_bits(codec, RT5631_INT_ST_IRQ_CTRL_2,
+                                       0x2000, 0);
+       /* DMIC */
+       if (rt5631->dmic_used_flag) {
+               snd_soc_update_bits(codec, RT5631_GPIO_CTRL,
+                       RT5631_GPIO_PIN_FUN_SEL_MASK |
+                       RT5631_GPIO_DMIC_FUN_SEL_MASK,
+                       RT5631_GPIO_PIN_FUN_SEL_GPIO_DIMC |
+                       RT5631_GPIO_DMIC_FUN_SEL_DIMC);
+               snd_soc_update_bits(codec, RT5631_DIG_MIC_CTRL,
+                       RT5631_DMIC_L_CH_LATCH_MASK |
+                       RT5631_DMIC_R_CH_LATCH_MASK,
+                       RT5631_DMIC_L_CH_LATCH_FALLING |
+                       RT5631_DMIC_R_CH_LATCH_RISING);
+       }
+
+       codec->dapm.bias_level = SND_SOC_BIAS_STANDBY;
+
+       return 0;
+}
+
+static int rt5631_remove(struct snd_soc_codec *codec)
+{
+       rt5631_set_bias_level(codec, SND_SOC_BIAS_OFF);
+       return 0;
+}
+
+#ifdef CONFIG_PM
+static int rt5631_suspend(struct snd_soc_codec *codec, pm_message_t state)
+{
+       rt5631_set_bias_level(codec, SND_SOC_BIAS_OFF);
+       return 0;
+}
+
+static int rt5631_resume(struct snd_soc_codec *codec)
+{
+       rt5631_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+       return 0;
+}
+#else
+#define rt5631_suspend NULL
+#define rt5631_resume NULL
+#endif
+
+#define RT5631_STEREO_RATES SNDRV_PCM_RATE_8000_96000
+#define RT5631_FORMAT  (SNDRV_PCM_FMTBIT_S16_LE | \
+                       SNDRV_PCM_FMTBIT_S20_3LE | \
+                       SNDRV_PCM_FMTBIT_S24_LE | \
+                       SNDRV_PCM_FMTBIT_S8)
+
+static struct snd_soc_dai_ops rt5631_ops = {
+       .hw_params = rt5631_hifi_pcm_params,
+       .set_fmt = rt5631_hifi_codec_set_dai_fmt,
+       .set_sysclk = rt5631_hifi_codec_set_dai_sysclk,
+       .set_pll = rt5631_codec_set_dai_pll,
+};
+
+static struct snd_soc_dai_driver rt5631_dai[] = {
+       {
+               .name = "rt5631-hifi",
+               .id = 1,
+               .playback = {
+                       .stream_name = "HIFI Playback",
+                       .channels_min = 1,
+                       .channels_max = 2,
+                       .rates = RT5631_STEREO_RATES,
+                       .formats = RT5631_FORMAT,
+               },
+               .capture = {
+                       .stream_name = "HIFI Capture",
+                       .channels_min = 1,
+                       .channels_max = 2,
+                       .rates = RT5631_STEREO_RATES,
+                       .formats = RT5631_FORMAT,
+               },
+               .ops = &rt5631_ops,
+       },
+};
+
+static struct snd_soc_codec_driver soc_codec_dev_rt5631 = {
+       .probe = rt5631_probe,
+       .remove = rt5631_remove,
+       .suspend = rt5631_suspend,
+       .resume = rt5631_resume,
+       .set_bias_level = rt5631_set_bias_level,
+       .reg_cache_size = RT5631_VENDOR_ID2 + 1,
+       .reg_word_size = sizeof(u16),
+       .reg_cache_default = rt5631_reg,
+       .volatile_register = rt5631_volatile_register,
+       .readable_register = rt5631_readable_register,
+       .reg_cache_step = 1,
+       .controls = rt5631_snd_controls,
+       .num_controls = ARRAY_SIZE(rt5631_snd_controls),
+       .dapm_widgets = rt5631_dapm_widgets,
+       .num_dapm_widgets = ARRAY_SIZE(rt5631_dapm_widgets),
+       .dapm_routes = rt5631_dapm_routes,
+       .num_dapm_routes = ARRAY_SIZE(rt5631_dapm_routes),
+};
+
+static const struct i2c_device_id rt5631_i2c_id[] = {
+       { "rt5631", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, rt5631_i2c_id);
+
+static int rt5631_i2c_probe(struct i2c_client *i2c,
+                   const struct i2c_device_id *id)
+{
+       struct rt5631_priv *rt5631;
+       int ret;
+
+       rt5631 = kzalloc(sizeof(struct rt5631_priv), GFP_KERNEL);
+       if (NULL == rt5631)
+               return -ENOMEM;
+
+       i2c_set_clientdata(i2c, rt5631);
+
+       ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt5631,
+                       rt5631_dai, ARRAY_SIZE(rt5631_dai));
+       if (ret < 0)
+               kfree(rt5631);
+
+       return ret;
+}
+
+static __devexit int rt5631_i2c_remove(struct i2c_client *client)
+{
+       snd_soc_unregister_codec(&client->dev);
+       kfree(i2c_get_clientdata(client));
+       return 0;
+}
+
+static struct i2c_driver rt5631_i2c_driver = {
+       .driver = {
+               .name = "rt5631",
+               .owner = THIS_MODULE,
+       },
+       .probe = rt5631_i2c_probe,
+       .remove   = __devexit_p(rt5631_i2c_remove),
+       .id_table = rt5631_i2c_id,
+};
+
+static int __init rt5631_modinit(void)
+{
+       return i2c_add_driver(&rt5631_i2c_driver);
+}
+module_init(rt5631_modinit);
+
+static void __exit rt5631_modexit(void)
+{
+       i2c_del_driver(&rt5631_i2c_driver);
+}
+module_exit(rt5631_modexit);
+
+MODULE_DESCRIPTION("ASoC RT5631 driver");
+MODULE_AUTHOR("flove <flove@realtek.com>");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/rt5631.h b/sound/soc/codecs/rt5631.h
new file mode 100644 (file)
index 0000000..1340158
--- /dev/null
@@ -0,0 +1,701 @@
+#ifndef __RTCODEC5631_H__
+#define __RTCODEC5631_H__
+
+
+#define RT5631_RESET                           0x00
+#define RT5631_SPK_OUT_VOL                     0x02
+#define RT5631_HP_OUT_VOL                      0x04
+#define RT5631_MONO_AXO_1_2_VOL                0x06
+#define RT5631_AUX_IN_VOL                      0x0A
+#define RT5631_STEREO_DAC_VOL_1                0x0C
+#define RT5631_MIC_CTRL_1                      0x0E
+#define RT5631_STEREO_DAC_VOL_2                0x10
+#define RT5631_ADC_CTRL_1                      0x12
+#define RT5631_ADC_REC_MIXER                   0x14
+#define RT5631_ADC_CTRL_2                      0x16
+#define RT5631_VDAC_DIG_VOL                    0x18
+#define RT5631_OUTMIXER_L_CTRL                 0x1A
+#define RT5631_OUTMIXER_R_CTRL                 0x1C
+#define RT5631_AXO1MIXER_CTRL                  0x1E
+#define RT5631_AXO2MIXER_CTRL                  0x20
+#define RT5631_MIC_CTRL_2                      0x22
+#define RT5631_DIG_MIC_CTRL                    0x24
+#define RT5631_MONO_INPUT_VOL                  0x26
+#define RT5631_SPK_MIXER_CTRL                  0x28
+#define RT5631_SPK_MONO_OUT_CTRL               0x2A
+#define RT5631_SPK_MONO_HP_OUT_CTRL            0x2C
+#define RT5631_SDP_CTRL                                0x34
+#define RT5631_MONO_SDP_CTRL                   0x36
+#define RT5631_STEREO_AD_DA_CLK_CTRL           0x38
+#define RT5631_PWR_MANAG_ADD1          0x3A
+#define RT5631_PWR_MANAG_ADD2          0x3B
+#define RT5631_PWR_MANAG_ADD3          0x3C
+#define RT5631_PWR_MANAG_ADD4          0x3E
+#define RT5631_GEN_PUR_CTRL_REG                0x40
+#define RT5631_GLOBAL_CLK_CTRL                 0x42
+#define RT5631_PLL_CTRL                                0x44
+#define RT5631_INT_ST_IRQ_CTRL_1               0x48
+#define RT5631_INT_ST_IRQ_CTRL_2               0x4A
+#define RT5631_GPIO_CTRL                       0x4C
+#define RT5631_MISC_CTRL                       0x52
+#define RT5631_DEPOP_FUN_CTRL_1                0x54
+#define RT5631_DEPOP_FUN_CTRL_2                0x56
+#define RT5631_JACK_DET_CTRL                   0x5A
+#define RT5631_SOFT_VOL_CTRL                   0x5C
+#define RT5631_ALC_CTRL_1                      0x64
+#define RT5631_ALC_CTRL_2                      0x65
+#define RT5631_ALC_CTRL_3                      0x66
+#define RT5631_PSEUDO_SPATL_CTRL               0x68
+#define RT5631_INDEX_ADD                       0x6A
+#define RT5631_INDEX_DATA                      0x6C
+#define RT5631_EQ_CTRL                         0x6E
+#define RT5631_VENDOR_ID                       0x7A
+#define RT5631_VENDOR_ID1                      0x7C
+#define RT5631_VENDOR_ID2                      0x7E
+
+/* Index of Codec Private Register definition */
+#define RT5631_EQ_BW_LOP                       0x00
+#define RT5631_EQ_GAIN_LOP                     0x01
+#define RT5631_EQ_FC_BP1                       0x02
+#define RT5631_EQ_BW_BP1                       0x03
+#define RT5631_EQ_GAIN_BP1                     0x04
+#define RT5631_EQ_FC_BP2                       0x05
+#define RT5631_EQ_BW_BP2                       0x06
+#define RT5631_EQ_GAIN_BP2                     0x07
+#define RT5631_EQ_FC_BP3                       0x08
+#define RT5631_EQ_BW_BP3                       0x09
+#define RT5631_EQ_GAIN_BP3                     0x0a
+#define RT5631_EQ_BW_HIP                       0x0b
+#define RT5631_EQ_GAIN_HIP                     0x0c
+#define RT5631_EQ_HPF_A1                       0x0d
+#define RT5631_EQ_HPF_A2                       0x0e
+#define RT5631_EQ_HPF_GAIN                     0x0f
+#define RT5631_EQ_PRE_VOL_CTRL                 0x11
+#define RT5631_EQ_POST_VOL_CTRL                0x12
+#define RT5631_TEST_MODE_CTRL                  0x39
+#define RT5631_CP_INTL_REG2                    0x45
+#define RT5631_ADDA_MIXER_INTL_REG3            0x52
+#define RT5631_SPK_INTL_CTRL                   0x56
+
+
+/* global definition */
+#define RT5631_L_MUTE                                  (0x1 << 15)
+#define RT5631_L_MUTE_SHIFT                            15
+#define RT5631_L_EN                                    (0x1 << 14)
+#define RT5631_L_EN_SHIFT                              14
+#define RT5631_R_MUTE                                  (0x1 << 7)
+#define RT5631_R_MUTE_SHIFT                            7
+#define RT5631_R_EN                                    (0x1 << 6)
+#define RT5631_R_EN_SHIFT                              6
+#define RT5631_VOL_MASK                                0x1f
+#define RT5631_L_VOL_SHIFT                             8
+#define RT5631_R_VOL_SHIFT                             0
+
+/* Speaker Output Control(0x02) */
+#define RT5631_SPK_L_VOL_SEL_MASK                      (0x1 << 14)
+#define RT5631_SPK_L_VOL_SEL_VMID                      (0x0 << 14)
+#define RT5631_SPK_L_VOL_SEL_SPKMIX_L                  (0x1 << 14)
+#define RT5631_SPK_R_VOL_SEL_MASK                      (0x1 << 6)
+#define RT5631_SPK_R_VOL_SEL_VMID                      (0x0 << 6)
+#define RT5631_SPK_R_VOL_SEL_SPKMIX_R                  (0x1 << 6)
+
+/* Headphone Output Control(0x04) */
+#define RT5631_HP_L_VOL_SEL_MASK                       (0x1 << 14)
+#define RT5631_HP_L_VOL_SEL_VMID                       (0x0 << 14)
+#define RT5631_HP_L_VOL_SEL_OUTMIX_L                   (0x1 << 14)
+#define RT5631_HP_R_VOL_SEL_MASK                       (0x1 << 6)
+#define RT5631_HP_R_VOL_SEL_VMID                       (0x0 << 6)
+#define RT5631_HP_R_VOL_SEL_OUTMIX_R                   (0x1 << 6)
+
+/* Output Control for AUXOUT/MONO(0x06) */
+#define RT5631_AUXOUT_1_VOL_SEL_MASK                   (0x1 << 14)
+#define RT5631_AUXOUT_1_VOL_SEL_VMID                   (0x0 << 14)
+#define RT5631_AUXOUT_1_VOL_SEL_OUTMIX_L               (0x1 << 14)
+#define RT5631_MUTE_MONO                               (0x1 << 13)
+#define RT5631_MUTE_MONO_SHIFT                 13
+#define RT5631_AUXOUT_2_VOL_SEL_MASK                   (0x1 << 6)
+#define RT5631_AUXOUT_2_VOL_SEL_VMID                   (0x0 << 6)
+#define RT5631_AUXOUT_2_VOL_SEL_OUTMIX_R               (0x1 << 6)
+
+/* Microphone Input Control 1(0x0E) */
+#define RT5631_MIC1_DIFF_INPUT_CTRL                    (0x1 << 15)
+#define RT5631_MIC1_DIFF_INPUT_SHIFT                   15
+#define RT5631_MIC2_DIFF_INPUT_CTRL                    (0x1 << 7)
+#define RT5631_MIC2_DIFF_INPUT_SHIFT                   7
+
+/* Stereo DAC Digital Volume2(0x10) */
+#define RT5631_DAC_VOL_MASK                            0xff
+
+/* ADC Recording Mixer Control(0x14) */
+#define RT5631_M_OUTMIXER_L_TO_RECMIXER_L              (0x1 << 15)
+#define RT5631_M_OUTMIXL_RECMIXL_BIT                   15
+#define RT5631_M_MIC1_TO_RECMIXER_L                    (0x1 << 14)
+#define RT5631_M_MIC1_RECMIXL_BIT                      14
+#define RT5631_M_AXIL_TO_RECMIXER_L                    (0x1 << 13)
+#define RT5631_M_AXIL_RECMIXL_BIT                      13
+#define RT5631_M_MONO_IN_TO_RECMIXER_L         (0x1 << 12)
+#define RT5631_M_MONO_IN_RECMIXL_BIT                   12
+#define RT5631_M_OUTMIXER_R_TO_RECMIXER_R              (0x1 << 7)
+#define RT5631_M_OUTMIXR_RECMIXR_BIT                   7
+#define RT5631_M_MIC2_TO_RECMIXER_R                    (0x1 << 6)
+#define RT5631_M_MIC2_RECMIXR_BIT                      6
+#define RT5631_M_AXIR_TO_RECMIXER_R                    (0x1 << 5)
+#define RT5631_M_AXIR_RECMIXR_BIT                      5
+#define RT5631_M_MONO_IN_TO_RECMIXER_R         (0x1 << 4)
+#define RT5631_M_MONO_IN_RECMIXR_BIT                   4
+
+/* Left Output Mixer Control(0x1A) */
+#define RT5631_M_RECMIXER_L_TO_OUTMIXER_L              (0x1 << 15)
+#define RT5631_M_RECMIXL_OUTMIXL_BIT                   15
+#define RT5631_M_RECMIXER_R_TO_OUTMIXER_L              (0x1 << 14)
+#define RT5631_M_RECMIXR_OUTMIXL_BIT                   14
+#define RT5631_M_DAC_L_TO_OUTMIXER_L                   (0x1 << 13)
+#define RT5631_M_DACL_OUTMIXL_BIT                      13
+#define RT5631_M_MIC1_TO_OUTMIXER_L                    (0x1 << 12)
+#define RT5631_M_MIC1_OUTMIXL_BIT                      12
+#define RT5631_M_MIC2_TO_OUTMIXER_L                    (0x1 << 11)
+#define RT5631_M_MIC2_OUTMIXL_BIT                      11
+#define RT5631_M_MONO_IN_P_TO_OUTMIXER_L               (0x1 << 10)
+#define RT5631_M_MONO_INP_OUTMIXL_BIT          10
+#define RT5631_M_AXIL_TO_OUTMIXER_L                    (0x1 << 9)
+#define RT5631_M_AXIL_OUTMIXL_BIT                      9
+#define RT5631_M_AXIR_TO_OUTMIXER_L                    (0x1 << 8)
+#define RT5631_M_AXIR_OUTMIXL_BIT                      8
+#define RT5631_M_VDAC_TO_OUTMIXER_L                    (0x1 << 7)
+#define RT5631_M_VDAC_OUTMIXL_BIT                      7
+
+/* Right Output Mixer Control(0x1C) */
+#define RT5631_M_RECMIXER_L_TO_OUTMIXER_R              (0x1 << 15)
+#define RT5631_M_RECMIXL_OUTMIXR_BIT                   15
+#define RT5631_M_RECMIXER_R_TO_OUTMIXER_R              (0x1 << 14)
+#define RT5631_M_RECMIXR_OUTMIXR_BIT                   14
+#define RT5631_M_DAC_R_TO_OUTMIXER_R                   (0x1 << 13)
+#define RT5631_M_DACR_OUTMIXR_BIT                      13
+#define RT5631_M_MIC1_TO_OUTMIXER_R                    (0x1 << 12)
+#define RT5631_M_MIC1_OUTMIXR_BIT                      12
+#define RT5631_M_MIC2_TO_OUTMIXER_R                    (0x1 << 11)
+#define RT5631_M_MIC2_OUTMIXR_BIT                      11
+#define RT5631_M_MONO_IN_N_TO_OUTMIXER_R               (0x1 << 10)
+#define RT5631_M_MONO_INN_OUTMIXR_BIT          10
+#define RT5631_M_AXIL_TO_OUTMIXER_R                    (0x1 << 9)
+#define RT5631_M_AXIL_OUTMIXR_BIT                      9
+#define RT5631_M_AXIR_TO_OUTMIXER_R                    (0x1 << 8)
+#define RT5631_M_AXIR_OUTMIXR_BIT                      8
+#define RT5631_M_VDAC_TO_OUTMIXER_R                    (0x1 << 7)
+#define RT5631_M_VDAC_OUTMIXR_BIT                      7
+
+/* Lout Mixer Control(0x1E) */
+#define RT5631_M_MIC1_TO_AXO1MIXER                     (0x1 << 15)
+#define RT5631_M_MIC1_AXO1MIX_BIT                      15
+#define RT5631_M_MIC2_TO_AXO1MIXER                     (0x1 << 11)
+#define RT5631_M_MIC2_AXO1MIX_BIT                      11
+#define RT5631_M_OUTMIXER_L_TO_AXO1MIXER               (0x1 << 7)
+#define RT5631_M_OUTMIXL_AXO1MIX_BIT                   7
+#define RT5631_M_OUTMIXER_R_TO_AXO1MIXER               (0x1 << 6)
+#define RT5631_M_OUTMIXR_AXO1MIX_BIT                   6
+
+/* Rout Mixer Control(0x20) */
+#define RT5631_M_MIC1_TO_AXO2MIXER                     (0x1 << 15)
+#define RT5631_M_MIC1_AXO2MIX_BIT                      15
+#define RT5631_M_MIC2_TO_AXO2MIXER                     (0x1 << 11)
+#define RT5631_M_MIC2_AXO2MIX_BIT                      11
+#define RT5631_M_OUTMIXER_L_TO_AXO2MIXER               (0x1 << 7)
+#define RT5631_M_OUTMIXL_AXO2MIX_BIT                   7
+#define RT5631_M_OUTMIXER_R_TO_AXO2MIXER               (0x1 << 6)
+#define RT5631_M_OUTMIXR_AXO2MIX_BIT                   6
+
+/* Micphone Input Control 2(0x22) */
+#define RT5631_MIC_BIAS_90_PRECNET_AVDD 1
+#define RT5631_MIC_BIAS_75_PRECNET_AVDD 2
+
+#define RT5631_MIC1_BOOST_CTRL_MASK                    (0xf << 12)
+#define RT5631_MIC1_BOOST_CTRL_BYPASS          (0x0 << 12)
+#define RT5631_MIC1_BOOST_CTRL_20DB                    (0x1 << 12)
+#define RT5631_MIC1_BOOST_CTRL_24DB                    (0x2 << 12)
+#define RT5631_MIC1_BOOST_CTRL_30DB                    (0x3 << 12)
+#define RT5631_MIC1_BOOST_CTRL_35DB                    (0x4 << 12)
+#define RT5631_MIC1_BOOST_CTRL_40DB                    (0x5 << 12)
+#define RT5631_MIC1_BOOST_CTRL_34DB                    (0x6 << 12)
+#define RT5631_MIC1_BOOST_CTRL_50DB                    (0x7 << 12)
+#define RT5631_MIC1_BOOST_CTRL_52DB                    (0x8 << 12)
+#define RT5631_MIC1_BOOST_SHIFT                        12
+
+#define RT5631_MIC2_BOOST_CTRL_MASK                    (0xf << 8)
+#define RT5631_MIC2_BOOST_CTRL_BYPASS          (0x0 << 8)
+#define RT5631_MIC2_BOOST_CTRL_20DB                    (0x1 << 8)
+#define RT5631_MIC2_BOOST_CTRL_24DB                    (0x2 << 8)
+#define RT5631_MIC2_BOOST_CTRL_30DB                    (0x3 << 8)
+#define RT5631_MIC2_BOOST_CTRL_35DB                    (0x4 << 8)
+#define RT5631_MIC2_BOOST_CTRL_40DB                    (0x5 << 8)
+#define RT5631_MIC2_BOOST_CTRL_34DB                    (0x6 << 8)
+#define RT5631_MIC2_BOOST_CTRL_50DB                    (0x7 << 8)
+#define RT5631_MIC2_BOOST_CTRL_52DB                    (0x8 << 8)
+#define RT5631_MIC2_BOOST_SHIFT                        8
+
+#define RT5631_MICBIAS1_VOLT_CTRL_MASK         (0x1 << 7)
+#define RT5631_MICBIAS1_VOLT_CTRL_90P                  (0x0 << 7)
+#define RT5631_MICBIAS1_VOLT_CTRL_75P                  (0x1 << 7)
+
+#define RT5631_MICBIAS1_S_C_DET_MASK                   (0x1 << 6)
+#define RT5631_MICBIAS1_S_C_DET_DIS                    (0x0 << 6)
+#define RT5631_MICBIAS1_S_C_DET_ENA                    (0x1 << 6)
+
+#define RT5631_MICBIAS1_SHORT_CURR_DET_MASK            (0x3 << 4)
+#define RT5631_MICBIAS1_SHORT_CURR_DET_600UA   (0x0 << 4)
+#define RT5631_MICBIAS1_SHORT_CURR_DET_1500UA  (0x1 << 4)
+#define RT5631_MICBIAS1_SHORT_CURR_DET_2000UA  (0x2 << 4)
+
+#define RT5631_MICBIAS2_VOLT_CTRL_MASK         (0x1 << 3)
+#define RT5631_MICBIAS2_VOLT_CTRL_90P                  (0x0 << 3)
+#define RT5631_MICBIAS2_VOLT_CTRL_75P                  (0x1 << 3)
+
+#define RT5631_MICBIAS2_S_C_DET_MASK                   (0x1 << 2)
+#define RT5631_MICBIAS2_S_C_DET_DIS                    (0x0 << 2)
+#define RT5631_MICBIAS2_S_C_DET_ENA                    (0x1 << 2)
+
+#define RT5631_MICBIAS2_SHORT_CURR_DET_MASK            (0x3)
+#define RT5631_MICBIAS2_SHORT_CURR_DET_600UA   (0x0)
+#define RT5631_MICBIAS2_SHORT_CURR_DET_1500UA  (0x1)
+#define RT5631_MICBIAS2_SHORT_CURR_DET_2000UA  (0x2)
+
+
+/* Digital Microphone Control(0x24) */
+#define RT5631_DMIC_ENA_MASK                           (0x1 << 15)
+#define RT5631_DMIC_ENA_SHIFT                          15
+/* DMIC_ENA: DMIC to ADC Digital filter */
+#define RT5631_DMIC_ENA                                (0x1 << 15)
+/* DMIC_DIS: ADC mixer to ADC Digital filter */
+#define RT5631_DMIC_DIS                                        (0x0 << 15)
+#define RT5631_DMIC_L_CH_MUTE                          (0x1 << 13)
+#define RT5631_DMIC_L_CH_MUTE_SHIFT                    13
+#define RT5631_DMIC_R_CH_MUTE                          (0x1 << 12)
+#define RT5631_DMIC_R_CH_MUTE_SHIFT                    12
+#define RT5631_DMIC_L_CH_LATCH_MASK                    (0x1 << 9)
+#define RT5631_DMIC_L_CH_LATCH_RISING                  (0x1 << 9)
+#define RT5631_DMIC_L_CH_LATCH_FALLING         (0x0 << 9)
+#define RT5631_DMIC_R_CH_LATCH_MASK                    (0x1 << 8)
+#define RT5631_DMIC_R_CH_LATCH_RISING                  (0x1 << 8)
+#define RT5631_DMIC_R_CH_LATCH_FALLING         (0x0 << 8)
+#define RT5631_DMIC_CLK_CTRL_MASK                      (0x3 << 4)
+#define RT5631_DMIC_CLK_CTRL_TO_128FS                  (0x0 << 4)
+#define RT5631_DMIC_CLK_CTRL_TO_64FS                   (0x1 << 4)
+#define RT5631_DMIC_CLK_CTRL_TO_32FS                   (0x2 << 4)
+
+/* Microphone Input Volume(0x26) */
+#define RT5631_MONO_DIFF_INPUT_SHIFT                   15
+
+/* Speaker Mixer Control(0x28) */
+#define RT5631_M_RECMIXER_L_TO_SPKMIXER_L              (0x1 << 15)
+#define RT5631_M_RECMIXL_SPKMIXL_BIT                   15
+#define RT5631_M_MIC1_P_TO_SPKMIXER_L          (0x1 << 14)
+#define RT5631_M_MIC1P_SPKMIXL_BIT                     14
+#define RT5631_M_DAC_L_TO_SPKMIXER_L                   (0x1 << 13)
+#define RT5631_M_DACL_SPKMIXL_BIT                      13
+#define RT5631_M_OUTMIXER_L_TO_SPKMIXER_L              (0x1 << 12)
+#define RT5631_M_OUTMIXL_SPKMIXL_BIT                   12
+
+#define RT5631_M_RECMIXER_R_TO_SPKMIXER_R              (0x1 << 7)
+#define RT5631_M_RECMIXR_SPKMIXR_BIT                   7
+#define RT5631_M_MIC2_P_TO_SPKMIXER_R          (0x1 << 6)
+#define RT5631_M_MIC2P_SPKMIXR_BIT                     6
+#define RT5631_M_DAC_R_TO_SPKMIXER_R                   (0x1 << 5)
+#define RT5631_M_DACR_SPKMIXR_BIT                      5
+#define RT5631_M_OUTMIXER_R_TO_SPKMIXER_R              (0x1 << 4)
+#define RT5631_M_OUTMIXR_SPKMIXR_BIT                   4
+
+/* Speaker/Mono Output Control(0x2A) */
+#define RT5631_M_SPKVOL_L_TO_SPOL_MIXER                (0x1 << 15)
+#define RT5631_M_SPKVOLL_SPOLMIX_BIT                   15
+#define RT5631_M_SPKVOL_R_TO_SPOL_MIXER                (0x1 << 14)
+#define RT5631_M_SPKVOLR_SPOLMIX_BIT                   14
+#define RT5631_M_SPKVOL_L_TO_SPOR_MIXER                (0x1 << 13)
+#define RT5631_M_SPKVOLL_SPORMIX_BIT                   13
+#define RT5631_M_SPKVOL_R_TO_SPOR_MIXER                (0x1 << 12)
+#define RT5631_M_SPKVOLR_SPORMIX_BIT                   12
+#define RT5631_M_OUTVOL_L_TO_MONOMIXER         (0x1 << 11)
+#define RT5631_M_OUTVOLL_MONOMIX_BIT                   11
+#define RT5631_M_OUTVOL_R_TO_MONOMIXER         (0x1 << 10)
+#define RT5631_M_OUTVOLR_MONOMIX_BIT                   10
+
+/* Speaker/Mono/HP Output Control(0x2C) */
+#define RT5631_SPK_L_MUX_SEL_MASK                      (0x3 << 14)
+#define RT5631_SPK_L_MUX_SEL_SPKMIXER_L                (0x0 << 14)
+#define RT5631_SPK_L_MUX_SEL_MONO_IN                   (0x1 << 14)
+#define RT5631_SPK_L_MUX_SEL_DAC_L                     (0x3 << 14)
+#define RT5631_SPK_L_MUX_SEL_SHIFT                     14
+
+#define RT5631_SPK_R_MUX_SEL_MASK                      (0x3 << 10)
+#define RT5631_SPK_R_MUX_SEL_SPKMIXER_R                (0x0 << 10)
+#define RT5631_SPK_R_MUX_SEL_MONO_IN                   (0x1 << 10)
+#define RT5631_SPK_R_MUX_SEL_DAC_R                     (0x3 << 10)
+#define RT5631_SPK_R_MUX_SEL_SHIFT                     10
+
+#define RT5631_MONO_MUX_SEL_MASK                       (0x3 << 6)
+#define RT5631_MONO_MUX_SEL_MONOMIXER          (0x0 << 6)
+#define RT5631_MONO_MUX_SEL_MONO_IN                    (0x1 << 6)
+#define RT5631_MONO_MUX_SEL_SHIFT                      6
+
+#define RT5631_HP_L_MUX_SEL_MASK                       (0x1 << 3)
+#define RT5631_HP_L_MUX_SEL_HPVOL_L                    (0x0 << 3)
+#define RT5631_HP_L_MUX_SEL_DAC_L                      (0x1 << 3)
+#define RT5631_HP_L_MUX_SEL_SHIFT                      3
+
+#define RT5631_HP_R_MUX_SEL_MASK                       (0x1 << 2)
+#define RT5631_HP_R_MUX_SEL_HPVOL_R                    (0x0 << 2)
+#define RT5631_HP_R_MUX_SEL_DAC_R                      (0x1 << 2)
+#define RT5631_HP_R_MUX_SEL_SHIFT                      2
+
+/* Stereo I2S Serial Data Port Control(0x34) */
+#define RT5631_SDP_MODE_SEL_MASK                       (0x1 << 15)
+#define RT5631_SDP_MODE_SEL_MASTER                     (0x0 << 15)
+#define RT5631_SDP_MODE_SEL_SLAVE                      (0x1 << 15)
+
+#define RT5631_SDP_ADC_CPS_SEL_MASK                    (0x3 << 10)
+#define RT5631_SDP_ADC_CPS_SEL_OFF                     (0x0 << 10)
+#define RT5631_SDP_ADC_CPS_SEL_U_LAW                   (0x1 << 10)
+#define RT5631_SDP_ADC_CPS_SEL_A_LAW                   (0x2 << 10)
+
+#define RT5631_SDP_DAC_CPS_SEL_MASK                    (0x3 << 8)
+#define RT5631_SDP_DAC_CPS_SEL_OFF                     (0x0 << 8)
+#define RT5631_SDP_DAC_CPS_SEL_U_LAW                   (0x1 << 8)
+#define RT5631_SDP_DAC_CPS_SEL_A_LAW                   (0x2 << 8)
+/* 0:Normal 1:Invert */
+#define RT5631_SDP_I2S_BCLK_POL_CTRL                   (0x1 << 7)
+/* 0:Normal 1:Invert */
+#define RT5631_SDP_DAC_R_INV                           (0x1 << 6)
+/* 0:ADC data appear at left phase of LRCK
+ * 1:ADC data appear at right phase of LRCK
+ */
+#define RT5631_SDP_ADC_DATA_L_R_SWAP                   (0x1 << 5)
+/* 0:DAC data appear at left phase of LRCK
+ * 1:DAC data appear at right phase of LRCK
+ */
+#define RT5631_SDP_DAC_DATA_L_R_SWAP                   (0x1 << 4)
+
+/* Data Length Slection */
+#define RT5631_SDP_I2S_DL_MASK                         (0x3 << 2)
+#define RT5631_SDP_I2S_DL_16                           (0x0 << 2)
+#define RT5631_SDP_I2S_DL_20                           (0x1 << 2)
+#define RT5631_SDP_I2S_DL_24                           (0x2 << 2)
+#define RT5631_SDP_I2S_DL_8                            (0x3 << 2)
+
+/* PCM Data Format Selection */
+#define RT5631_SDP_I2S_DF_MASK                         (0x3)
+#define RT5631_SDP_I2S_DF_I2S                          (0x0)
+#define RT5631_SDP_I2S_DF_LEFT                         (0x1)
+#define RT5631_SDP_I2S_DF_PCM_A                        (0x2)
+#define RT5631_SDP_I2S_DF_PCM_B                        (0x3)
+
+/* Stereo AD/DA Clock Control(0x38h) */
+#define RT5631_I2S_PRE_DIV_MASK                        (0x7 << 13)
+#define RT5631_I2S_PRE_DIV_1                           (0x0 << 13)
+#define RT5631_I2S_PRE_DIV_2                           (0x1 << 13)
+#define RT5631_I2S_PRE_DIV_4                           (0x2 << 13)
+#define RT5631_I2S_PRE_DIV_8                           (0x3 << 13)
+#define RT5631_I2S_PRE_DIV_16                          (0x4 << 13)
+#define RT5631_I2S_PRE_DIV_32                          (0x5 << 13)
+/* CLOCK RELATIVE OF BCLK AND LCRK */
+#define RT5631_I2S_LRCK_SEL_N_BCLK_MASK                (0x1 << 12)
+#define RT5631_I2S_LRCK_SEL_64_BCLK                    (0x0 << 12) /* 64FS */
+#define RT5631_I2S_LRCK_SEL_32_BCLK                    (0x1 << 12) /* 32FS */
+
+#define RT5631_DAC_OSR_SEL_MASK                        (0x3 << 10)
+#define RT5631_DAC_OSR_SEL_128FS                       (0x3 << 10)
+#define RT5631_DAC_OSR_SEL_64FS                        (0x3 << 10)
+#define RT5631_DAC_OSR_SEL_32FS                        (0x3 << 10)
+#define RT5631_DAC_OSR_SEL_16FS                        (0x3 << 10)
+
+#define RT5631_ADC_OSR_SEL_MASK                        (0x3 << 8)
+#define RT5631_ADC_OSR_SEL_128FS                       (0x3 << 8)
+#define RT5631_ADC_OSR_SEL_64FS                        (0x3 << 8)
+#define RT5631_ADC_OSR_SEL_32FS                        (0x3 << 8)
+#define RT5631_ADC_OSR_SEL_16FS                        (0x3 << 8)
+
+#define RT5631_ADDA_FILTER_CLK_SEL_256FS               (0 << 7) /* 256FS */
+#define RT5631_ADDA_FILTER_CLK_SEL_384FS               (1 << 7) /* 384FS */
+
+/* Power managment addition 1 (0x3A) */
+#define RT5631_PWR_MAIN_I2S_EN                 (0x1 << 15)
+#define RT5631_PWR_MAIN_I2S_BIT                        15
+#define RT5631_PWR_CLASS_D                             (0x1 << 12)
+#define RT5631_PWR_CLASS_D_BIT                 12
+#define RT5631_PWR_ADC_L_CLK                           (0x1 << 11)
+#define RT5631_PWR_ADC_L_CLK_BIT                       11
+#define RT5631_PWR_ADC_R_CLK                           (0x1 << 10)
+#define RT5631_PWR_ADC_R_CLK_BIT                       10
+#define RT5631_PWR_DAC_L_CLK                           (0x1 << 9)
+#define RT5631_PWR_DAC_L_CLK_BIT                       9
+#define RT5631_PWR_DAC_R_CLK                           (0x1 << 8)
+#define RT5631_PWR_DAC_R_CLK_BIT                       8
+#define RT5631_PWR_DAC_REF                             (0x1 << 7)
+#define RT5631_PWR_DAC_REF_BIT                 7
+#define RT5631_PWR_DAC_L_TO_MIXER                      (0x1 << 6)
+#define RT5631_PWR_DAC_L_TO_MIXER_BIT          6
+#define RT5631_PWR_DAC_R_TO_MIXER                      (0x1 << 5)
+#define RT5631_PWR_DAC_R_TO_MIXER_BIT          5
+
+/* Power managment addition 2 (0x3B) */
+#define RT5631_PWR_OUTMIXER_L                          (0x1 << 15)
+#define RT5631_PWR_OUTMIXER_L_BIT                      15
+#define RT5631_PWR_OUTMIXER_R                          (0x1 << 14)
+#define RT5631_PWR_OUTMIXER_R_BIT                      14
+#define RT5631_PWR_SPKMIXER_L                          (0x1 << 13)
+#define RT5631_PWR_SPKMIXER_L_BIT                      13
+#define RT5631_PWR_SPKMIXER_R                          (0x1 << 12)
+#define RT5631_PWR_SPKMIXER_R_BIT                      12
+#define RT5631_PWR_RECMIXER_L                          (0x1 << 11)
+#define RT5631_PWR_RECMIXER_L_BIT                      11
+#define RT5631_PWR_RECMIXER_R                          (0x1 << 10)
+#define RT5631_PWR_RECMIXER_R_BIT                      10
+#define RT5631_PWR_MIC1_BOOT_GAIN                      (0x1 << 5)
+#define RT5631_PWR_MIC1_BOOT_GAIN_BIT          5
+#define RT5631_PWR_MIC2_BOOT_GAIN                      (0x1 << 4)
+#define RT5631_PWR_MIC2_BOOT_GAIN_BIT          4
+#define RT5631_PWR_MICBIAS1_VOL                        (0x1 << 3)
+#define RT5631_PWR_MICBIAS1_VOL_BIT                    3
+#define RT5631_PWR_MICBIAS2_VOL                        (0x1 << 2)
+#define RT5631_PWR_MICBIAS2_VOL_BIT                    2
+#define RT5631_PWR_PLL1                                (0x1 << 1)
+#define RT5631_PWR_PLL1_BIT                            1
+#define RT5631_PWR_PLL2                                (0x1 << 0)
+#define RT5631_PWR_PLL2_BIT                            0
+
+/* Power managment addition 3(0x3C) */
+#define RT5631_PWR_VREF                                (0x1 << 15)
+#define RT5631_PWR_VREF_BIT                            15
+#define RT5631_PWR_FAST_VREF_CTRL                      (0x1 << 14)
+#define RT5631_PWR_FAST_VREF_CTRL_BIT                  14
+#define RT5631_PWR_MAIN_BIAS                           (0x1 << 13)
+#define RT5631_PWR_MAIN_BIAS_BIT                       13
+#define RT5631_PWR_AXO1MIXER                           (0x1 << 11)
+#define RT5631_PWR_AXO1MIXER_BIT                       11
+#define RT5631_PWR_AXO2MIXER                           (0x1 << 10)
+#define RT5631_PWR_AXO2MIXER_BIT                       10
+#define RT5631_PWR_MONOMIXER                           (0x1 << 9)
+#define RT5631_PWR_MONOMIXER_BIT                       9
+#define RT5631_PWR_MONO_DEPOP_DIS                      (0x1 << 8)
+#define RT5631_PWR_MONO_DEPOP_DIS_BIT          8
+#define RT5631_PWR_MONO_AMP_EN                 (0x1 << 7)
+#define RT5631_PWR_MONO_AMP_EN_BIT                     7
+#define RT5631_PWR_CHARGE_PUMP                 (0x1 << 4)
+#define RT5631_PWR_CHARGE_PUMP_BIT                     4
+#define RT5631_PWR_HP_L_AMP                            (0x1 << 3)
+#define RT5631_PWR_HP_L_AMP_BIT                        3
+#define RT5631_PWR_HP_R_AMP                            (0x1 << 2)
+#define RT5631_PWR_HP_R_AMP_BIT                        2
+#define RT5631_PWR_HP_DEPOP_DIS                        (0x1 << 1)
+#define RT5631_PWR_HP_DEPOP_DIS_BIT                    1
+#define RT5631_PWR_HP_AMP_DRIVING                      (0x1 << 0)
+#define RT5631_PWR_HP_AMP_DRIVING_BIT          0
+
+/* Power managment addition 4(0x3E) */
+#define RT5631_PWR_SPK_L_VOL                           (0x1 << 15)
+#define RT5631_PWR_SPK_L_VOL_BIT                       15
+#define RT5631_PWR_SPK_R_VOL                           (0x1 << 14)
+#define RT5631_PWR_SPK_R_VOL_BIT                       14
+#define RT5631_PWR_LOUT_VOL                            (0x1 << 13)
+#define RT5631_PWR_LOUT_VOL_BIT                        13
+#define RT5631_PWR_ROUT_VOL                            (0x1 << 12)
+#define RT5631_PWR_ROUT_VOL_BIT                        12
+#define RT5631_PWR_HP_L_OUT_VOL                        (0x1 << 11)
+#define RT5631_PWR_HP_L_OUT_VOL_BIT                    11
+#define RT5631_PWR_HP_R_OUT_VOL                        (0x1 << 10)
+#define RT5631_PWR_HP_R_OUT_VOL_BIT                    10
+#define RT5631_PWR_AXIL_IN_VOL                         (0x1 << 9)
+#define RT5631_PWR_AXIL_IN_VOL_BIT                     9
+#define RT5631_PWR_AXIR_IN_VOL                 (0x1 << 8)
+#define RT5631_PWR_AXIR_IN_VOL_BIT                     8
+#define RT5631_PWR_MONO_IN_P_VOL                       (0x1 << 7)
+#define RT5631_PWR_MONO_IN_P_VOL_BIT                   7
+#define RT5631_PWR_MONO_IN_N_VOL                       (0x1 << 6)
+#define RT5631_PWR_MONO_IN_N_VOL_BIT                   6
+
+/* General Purpose Control Register(0x40) */
+#define RT5631_SPK_AMP_AUTO_RATIO_EN                   (0x1 << 15)
+
+#define RT5631_SPK_AMP_RATIO_CTRL_MASK         (0x7 << 12)
+#define RT5631_SPK_AMP_RATIO_CTRL_2_34         (0x0 << 12) /* 7.40DB */
+#define RT5631_SPK_AMP_RATIO_CTRL_1_99         (0x1 << 12) /* 5.99DB */
+#define RT5631_SPK_AMP_RATIO_CTRL_1_68         (0x2 << 12) /* 4.50DB */
+#define RT5631_SPK_AMP_RATIO_CTRL_1_56         (0x3 << 12) /* 3.86DB */
+#define RT5631_SPK_AMP_RATIO_CTRL_1_44         (0x4 << 12) /* 3.16DB */
+#define RT5631_SPK_AMP_RATIO_CTRL_1_27         (0x5 << 12) /* 2.10DB */
+#define RT5631_SPK_AMP_RATIO_CTRL_1_09         (0x6 << 12) /* 0.80DB */
+#define RT5631_SPK_AMP_RATIO_CTRL_1_00         (0x7 << 12) /* 0.00DB */
+#define RT5631_SPK_AMP_RATIO_CTRL_SHIFT                12
+
+#define RT5631_STEREO_DAC_HI_PASS_FILT_EN              (0x1 << 11)
+#define RT5631_STEREO_ADC_HI_PASS_FILT_EN              (0x1 << 10)
+/* Select ADC Wind Filter Clock type */
+#define RT5631_ADC_WIND_FILT_MASK                      (0x3 << 4)
+#define RT5631_ADC_WIND_FILT_8_16_32K                  (0x0 << 4) /*8/16/32k*/
+#define RT5631_ADC_WIND_FILT_11_22_44K         (0x1 << 4) /*11/22/44k*/
+#define RT5631_ADC_WIND_FILT_12_24_48K         (0x2 << 4) /*12/24/48k*/
+#define RT5631_ADC_WIND_FILT_EN                        (0x1 << 3)
+/* SelectADC Wind Filter Corner Frequency */
+#define RT5631_ADC_WIND_CNR_FREQ_MASK  (0x7 << 0)
+#define RT5631_ADC_WIND_CNR_FREQ_82_113_122    (0x0 << 0) /* 82/113/122 Hz */
+#define RT5631_ADC_WIND_CNR_FREQ_102_141_153 (0x1 << 0) /* 102/141/153 Hz */
+#define RT5631_ADC_WIND_CNR_FREQ_131_180_156 (0x2 << 0) /* 131/180/156 Hz */
+#define RT5631_ADC_WIND_CNR_FREQ_163_225_245 (0x3 << 0) /* 163/225/245 Hz */
+#define RT5631_ADC_WIND_CNR_FREQ_204_281_306 (0x4 << 0) /* 204/281/306 Hz */
+#define RT5631_ADC_WIND_CNR_FREQ_261_360_392 (0x5 << 0) /* 261/360/392 Hz */
+#define RT5631_ADC_WIND_CNR_FREQ_327_450_490 (0x6 << 0) /* 327/450/490 Hz */
+#define RT5631_ADC_WIND_CNR_FREQ_408_563_612 (0x7 << 0) /* 408/563/612 Hz */
+
+/* Global Clock Control Register(0x42) */
+#define RT5631_SYSCLK_SOUR_SEL_MASK                    (0x3 << 14)
+#define RT5631_SYSCLK_SOUR_SEL_MCLK                    (0x0 << 14)
+#define RT5631_SYSCLK_SOUR_SEL_PLL                     (0x1 << 14)
+#define RT5631_SYSCLK_SOUR_SEL_PLL_TCK         (0x2 << 14)
+
+#define RT5631_PLLCLK_SOUR_SEL_MASK                    (0x3 << 12)
+#define RT5631_PLLCLK_SOUR_SEL_MCLK                    (0x0 << 12)
+#define RT5631_PLLCLK_SOUR_SEL_BCLK                    (0x1 << 12)
+#define RT5631_PLLCLK_SOUR_SEL_VBCLK                   (0x2 << 12)
+
+#define RT5631_PLLCLK_PRE_DIV1                         (0x0 << 11)
+#define RT5631_PLLCLK_PRE_DIV2                         (0x1 << 11)
+
+/* PLL Control(0x44) */
+#define RT5631_PLL_CTRL_M_VAL(m)                       ((m)&0xf)
+#define RT5631_PLL_CTRL_K_VAL(k)                       (((k)&0x7) << 4)
+#define RT5631_PLL_CTRL_N_VAL(n)                       (((n)&0xff) << 8)
+
+/* Internal Status and IRQ Control2(0x4A) */
+#define RT5631_ADC_DATA_SEL_MASK                       (0x3 << 14)
+#define RT5631_ADC_DATA_SEL_Disable                    (0x0 << 14)
+#define RT5631_ADC_DATA_SEL_MIC1                       (0x1 << 14)
+#define RT5631_ADC_DATA_SEL_MIC1_SHIFT         14
+#define RT5631_ADC_DATA_SEL_MIC2                       (0x2 << 14)
+#define RT5631_ADC_DATA_SEL_MIC2_SHIFT         15
+#define RT5631_ADC_DATA_SEL_STO                        (0x3 << 14)
+#define RT5631_ADC_DATA_SEL_SHIFT                      14
+
+/* GPIO Pin Configuration(0x4C) */
+#define RT5631_GPIO_PIN_FUN_SEL_MASK                   (0x1 << 15)
+#define RT5631_GPIO_PIN_FUN_SEL_IRQ                    (0x1 << 15)
+#define RT5631_GPIO_PIN_FUN_SEL_GPIO_DIMC              (0x0 << 15)
+
+#define RT5631_GPIO_DMIC_FUN_SEL_MASK          (0x1 << 3)
+#define RT5631_GPIO_DMIC_FUN_SEL_DIMC          (0x1 << 3)
+#define RT5631_GPIO_DMIC_FUN_SEL_GPIO                  (0x0 << 3)
+
+#define RT5631_GPIO_PIN_CON_MASK                       (0x1 << 2)
+#define RT5631_GPIO_PIN_SET_INPUT                      (0x0 << 2)
+#define RT5631_GPIO_PIN_SET_OUTPUT                     (0x1 << 2)
+
+/* De-POP function Control 1(0x54) */
+#define RT5631_POW_ON_SOFT_GEN                 (0x1 << 15)
+#define RT5631_EN_MUTE_UNMUTE_DEPOP                    (0x1 << 14)
+#define RT5631_EN_DEPOP2_FOR_HP                        (0x1 << 7)
+/* Power Down HPAMP_L Starts Up Signal */
+#define RT5631_PD_HPAMP_L_ST_UP                        (0x1 << 5)
+/* Power Down HPAMP_R Starts Up Signal */
+#define RT5631_PD_HPAMP_R_ST_UP                        (0x1 << 4)
+/* Enable left HP mute/unmute depop */
+#define RT5631_EN_HP_L_M_UN_MUTE_DEPOP         (0x1 << 1)
+/* Enable right HP mute/unmute depop */
+#define RT5631_EN_HP_R_M_UN_MUTE_DEPOP         (0x1 << 0)
+
+/* De-POP Fnction Control(0x56) */
+#define RT5631_EN_ONE_BIT_DEPOP                        (0x1 << 15)
+#define RT5631_EN_CAP_FREE_DEPOP                       (0x1 << 14)
+
+/* Jack Detect Control Register(0x5A) */
+#define RT5631_JD_USE_MASK                             (0x3 << 14)
+#define RT5631_JD_USE_JD2                              (0x3 << 14)
+#define RT5631_JD_USE_JD1                              (0x2 << 14)
+#define RT5631_JD_USE_GPIO                             (0x1 << 14)
+#define RT5631_JD_OFF                                  (0x0 << 14)
+/* JD trigger enable for HP */
+#define RT5631_JD_HP_EN                                        (0x1 << 11)
+#define RT5631_JD_HP_TRI_MASK                          (0x1 << 10)
+#define RT5631_JD_HP_TRI_HI                            (0x1 << 10)
+#define RT5631_JD_HP_TRI_LO                            (0x1 << 10)
+/* JD trigger enable for speaker LP/LN */
+#define RT5631_JD_SPK_L_EN                             (0x1 << 9)
+#define RT5631_JD_SPK_L_TRI_MASK                       (0x1 << 8)
+#define RT5631_JD_SPK_L_TRI_HI                         (0x1 << 8)
+#define RT5631_JD_SPK_L_TRI_LO                         (0x0 << 8)
+/* JD trigger enable for speaker RP/RN */
+#define RT5631_JD_SPK_R_EN                             (0x1 << 7)
+#define RT5631_JD_SPK_R_TRI_MASK                       (0x1 << 6)
+#define RT5631_JD_SPK_R_TRI_HI                         (0x1 << 6)
+#define RT5631_JD_SPK_R_TRI_LO                         (0x0 << 6)
+/* JD trigger enable for monoout */
+#define RT5631_JD_MONO_EN                              (0x1 << 5)
+#define RT5631_JD_MONO_TRI_MASK                        (0x1 << 4)
+#define RT5631_JD_MONO_TRI_HI                          (0x1 << 4)
+#define RT5631_JD_MONO_TRI_LO                          (0x0 << 4)
+/* JD trigger enable for Lout */
+#define RT5631_JD_AUX_1_EN                             (0x1 << 3)
+#define RT5631_JD_AUX_1_MASK                           (0x1 << 2)
+#define RT5631_JD_AUX_1_TRI_HI                         (0x1 << 2)
+#define RT5631_JD_AUX_1_TRI_LO                         (0x0 << 2)
+/* JD trigger enable for Rout */
+#define RT5631_JD_AUX_2_EN                             (0x1 << 1)
+#define RT5631_JD_AUX_2_MASK                           (0x1 << 0)
+#define RT5631_JD_AUX_2_TRI_HI                         (0x1 << 0)
+#define RT5631_JD_AUX_2_TRI_LO                         (0x0 << 0)
+
+/* ALC CONTROL 1(0x64) */
+#define RT5631_ALC_ATTACK_RATE_MASK                    (0x1F << 8)
+#define RT5631_ALC_RECOVERY_RATE_MASK          (0x1F << 0)
+
+/* ALC CONTROL 2(0x65) */
+/* select Compensation gain for Noise gate function */
+#define RT5631_ALC_COM_NOISE_GATE_MASK         (0xF << 0)
+
+/* ALC CONTROL 3(0x66) */
+#define RT5631_ALC_FUN_MASK                            (0x3 << 14)
+#define RT5631_ALC_FUN_DIS                             (0x0 << 14)
+#define RT5631_ALC_ENA_DAC_PATH                        (0x1 << 14)
+#define RT5631_ALC_ENA_ADC_PATH                        (0x3 << 14)
+#define RT5631_ALC_PARA_UPDATE                 (0x1 << 13)
+#define RT5631_ALC_LIMIT_LEVEL_MASK                    (0x1F << 8)
+#define RT5631_ALC_NOISE_GATE_FUN_MASK         (0x1 << 7)
+#define RT5631_ALC_NOISE_GATE_FUN_DIS                  (0x0 << 7)
+#define RT5631_ALC_NOISE_GATE_FUN_ENA          (0x1 << 7)
+/* ALC noise gate hold data function */
+#define RT5631_ALC_NOISE_GATE_H_D_MASK         (0x1 << 6)
+#define RT5631_ALC_NOISE_GATE_H_D_DIS                  (0x0 << 6)
+#define RT5631_ALC_NOISE_GATE_H_D_ENA          (0x1 << 6)
+
+/* Psedueo Stereo & Spatial Effect Block Control(0x68) */
+#define RT5631_SPATIAL_CTRL_EN                         (0x1 << 15)
+#define RT5631_ALL_PASS_FILTER_EN                      (0x1 << 14)
+#define RT5631_PSEUDO_STEREO_EN                        (0x1 << 13)
+#define RT5631_STEREO_EXPENSION_EN                     (0x1 << 12)
+/* 3D gain parameter */
+#define RT5631_GAIN_3D_PARA_MASK               (0x3 << 6)
+#define RT5631_GAIN_3D_PARA_1_00               (0x0 << 6) /* 3D gain 1.0 */
+#define RT5631_GAIN_3D_PARA_1_50               (0x1 << 6) /* 3D gain 1.5 */
+#define RT5631_GAIN_3D_PARA_2_00               (0x2 << 6) /* 3D gain 2.0 */
+/* 3D ratio parameter */
+#define RT5631_RATIO_3D_MASK                   (0x3 << 4)
+#define RT5631_RATIO_3D_0_0                    (0x0 << 4) /* 3D ratio 0.0 */
+#define RT5631_RATIO_3D_0_66                   (0x1 << 4) /* 3D ratio 0.66 */
+#define RT5631_RATIO_3D_1_0                    (0x2 << 4) /* 3D ratio 1.0 */
+/* select samplerate for all pass filter */
+#define RT5631_APF_FUN_SLE_MASK                        (0x3 << 0)
+#define RT5631_APF_FUN_SEL_48K                         (0x3 << 0)
+#define RT5631_APF_FUN_SEL_44_1K                       (0x2 << 0)
+#define RT5631_APF_FUN_SEL_32K                         (0x1 << 0)
+#define RT5631_APF_FUN_DIS                             (0x0 << 0)
+
+/* EQ CONTROL 1(0x6E) */
+#define RT5631_HW_EQ_PATH_SEL_MASK                     (0x1 << 15)
+#define RT5631_HW_EQ_PATH_SEL_DAC                      (0x0 << 15)
+#define RT5631_HW_EQ_PATH_SEL_ADC                      (0x1 << 15)
+#define RT5631_HW_EQ_UPDATE_CTRL                       (0x1 << 14)
+
+#define RT5631_EN_HW_EQ_HPF2                           (0x1 << 5)
+#define RT5631_EN_HW_EQ_HPF1                           (0x1 << 4)
+#define RT5631_EN_HW_EQ_BP3                            (0x1 << 3)
+#define RT5631_EN_HW_EQ_BP2                            (0x1 << 2)
+#define RT5631_EN_HW_EQ_BP1                            (0x1 << 1)
+#define RT5631_EN_HW_EQ_LPF                            (0x1 << 0)
+
+
+#endif /* __RTCODEC5631_H__ */
index 7e4066e131e64ac95ed0eee06bb470a4ee23a6f2..d15695d1c27397a7b3f2966c1806584e5e9a39bc 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/regulator/driver.h>
 #include <linux/regulator/machine.h>
 #include <linux/regulator/consumer.h>
+#include <linux/of_device.h>
 #include <sound/core.h>
 #include <sound/tlv.h>
 #include <sound/pcm.h>
@@ -130,16 +131,13 @@ static int mic_bias_event(struct snd_soc_dapm_widget *w,
        case SND_SOC_DAPM_POST_PMU:
                /* change mic bias resistor to 4Kohm */
                snd_soc_update_bits(w->codec, SGTL5000_CHIP_MIC_CTRL,
-                               SGTL5000_BIAS_R_4k, SGTL5000_BIAS_R_4k);
+                               SGTL5000_BIAS_R_MASK,
+                               SGTL5000_BIAS_R_4k << SGTL5000_BIAS_R_SHIFT);
                break;
 
        case SND_SOC_DAPM_PRE_PMD:
-               /*
-                * SGTL5000_BIAS_R_8k as mask to clean the two bits
-                * of mic bias and output impedance
-                */
                snd_soc_update_bits(w->codec, SGTL5000_CHIP_MIC_CTRL,
-                               SGTL5000_BIAS_R_8k, 0);
+                               SGTL5000_BIAS_R_MASK, 0);
                break;
        }
        return 0;
@@ -725,7 +723,9 @@ static int sgtl5000_pcm_hw_params(struct snd_pcm_substream *substream,
                return -EINVAL;
        }
 
-       snd_soc_update_bits(codec, SGTL5000_CHIP_I2S_CTRL, i2s_ctl, i2s_ctl);
+       snd_soc_update_bits(codec, SGTL5000_CHIP_I2S_CTRL,
+                           SGTL5000_I2S_DLEN_MASK | SGTL5000_I2S_SCLKFREQ_MASK,
+                           i2s_ctl);
 
        return 0;
 }
@@ -756,7 +756,7 @@ static int ldo_regulator_enable(struct regulator_dev *dev)
 
        /* set voltage to register */
        snd_soc_update_bits(codec, SGTL5000_CHIP_LINREG_CTRL,
-                               (0x1 << 4) - 1, reg);
+                               SGTL5000_LINREG_VDDD_MASK, reg);
 
        snd_soc_update_bits(codec, SGTL5000_CHIP_ANA_POWER,
                                SGTL5000_LINEREG_D_POWERUP,
@@ -782,7 +782,7 @@ static int ldo_regulator_disable(struct regulator_dev *dev)
 
        /* clear voltage info */
        snd_soc_update_bits(codec, SGTL5000_CHIP_LINREG_CTRL,
-                               (0x1 << 4) - 1, 0);
+                               SGTL5000_LINREG_VDDD_MASK, 0);
 
        ldo->enabled = 0;
 
@@ -808,6 +808,7 @@ static int ldo_regulator_register(struct snd_soc_codec *codec,
                                int voltage)
 {
        struct ldo_regulator *ldo;
+       struct sgtl5000_priv *sgtl5000 = snd_soc_codec_get_drvdata(codec);
 
        ldo = kzalloc(sizeof(struct ldo_regulator), GFP_KERNEL);
 
@@ -842,6 +843,7 @@ static int ldo_regulator_register(struct snd_soc_codec *codec,
 
                return ret;
        }
+       sgtl5000->ldo = ldo;
 
        return 0;
 }
@@ -1115,7 +1117,7 @@ static int sgtl5000_set_power_regs(struct snd_soc_codec *codec)
 
        /* set voltage to register */
        snd_soc_update_bits(codec, SGTL5000_CHIP_LINREG_CTRL,
-                               (0x1 << 4) - 1, 0x8);
+                               SGTL5000_LINREG_VDDD_MASK, 0x8);
 
        /*
         * if vddd linear reg has been enabled,
@@ -1146,8 +1148,7 @@ static int sgtl5000_set_power_regs(struct snd_soc_codec *codec)
                vag = (vag - SGTL5000_ANA_GND_BASE) / SGTL5000_ANA_GND_STP;
 
        snd_soc_update_bits(codec, SGTL5000_CHIP_REF_CTRL,
-                       vag << SGTL5000_ANA_GND_SHIFT,
-                       vag << SGTL5000_ANA_GND_SHIFT);
+                       SGTL5000_ANA_GND_MASK, vag << SGTL5000_ANA_GND_SHIFT);
 
        /* set line out VAG to vddio / 2, in range (0.8v, 1.675v) */
        vag = vddio / 2;
@@ -1161,9 +1162,8 @@ static int sgtl5000_set_power_regs(struct snd_soc_codec *codec)
                    SGTL5000_LINE_OUT_GND_STP;
 
        snd_soc_update_bits(codec, SGTL5000_CHIP_LINE_OUT_CTRL,
-                       vag << SGTL5000_LINE_OUT_GND_SHIFT |
-                       SGTL5000_LINE_OUT_CURRENT_360u <<
-                               SGTL5000_LINE_OUT_CURRENT_SHIFT,
+                       SGTL5000_LINE_OUT_CURRENT_MASK |
+                       SGTL5000_LINE_OUT_GND_MASK,
                        vag << SGTL5000_LINE_OUT_GND_SHIFT |
                        SGTL5000_LINE_OUT_CURRENT_360u <<
                                SGTL5000_LINE_OUT_CURRENT_SHIFT);
@@ -1436,10 +1436,17 @@ static const struct i2c_device_id sgtl5000_id[] = {
 
 MODULE_DEVICE_TABLE(i2c, sgtl5000_id);
 
+static const struct of_device_id sgtl5000_dt_ids[] = {
+       { .compatible = "fsl,sgtl5000", },
+       { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, sgtl5000_dt_ids);
+
 static struct i2c_driver sgtl5000_i2c_driver = {
        .driver = {
                   .name = "sgtl5000",
                   .owner = THIS_MODULE,
+                  .of_match_table = sgtl5000_dt_ids,
                   },
        .probe = sgtl5000_i2c_probe,
        .remove = __devexit_p(sgtl5000_i2c_remove),
index eec3ab368f39b9327dcdaf8ab5fc3631e26a4aaa..8a9f43534b79569bb69c0ce0b012a74489ca815d 100644 (file)
 /*
  * SGTL5000_CHIP_MIC_CTRL
  */
-#define SGTL5000_BIAS_R_MASK                   0x0200
+#define SGTL5000_BIAS_R_MASK                   0x0300
 #define SGTL5000_BIAS_R_SHIFT                  8
 #define SGTL5000_BIAS_R_WIDTH                  2
 #define SGTL5000_BIAS_R_off                    0x0
index 84ffdebb8a8b9c937c9ffa1323f4de40f2874e81..f681e41fc12efa291b61ed9308eb853d85a6c14f 100644 (file)
@@ -79,7 +79,7 @@ static void configure_adc(struct snd_soc_codec *sn95031_codec, int val)
  */
 static int find_free_channel(struct snd_soc_codec *sn95031_codec)
 {
-       int ret = 0, i, value;
+       int i, value;
 
        /* check whether ADC is enabled */
        value = snd_soc_read(sn95031_codec, SN95031_ADC1CNTL1);
@@ -91,12 +91,10 @@ static int find_free_channel(struct snd_soc_codec *sn95031_codec)
        for (i = 0; i < SN95031_ADC_CHANLS_MAX; i++) {
                value = snd_soc_read(sn95031_codec,
                                SN95031_ADC_CHNL_START_ADDR + i);
-               if (value & SN95031_STOPBIT_MASK) {
-                       ret = i;
+               if (value & SN95031_STOPBIT_MASK)
                        break;
-               }
        }
-       return (ret > SN95031_ADC_LOOP_MAX) ? (-EINVAL) : ret;
+       return (i == SN95031_ADC_CHANLS_MAX) ? (-EINVAL) : i;
 }
 
 /* Initialize the ADC for reading micbias values. Can sleep. */
@@ -104,7 +102,7 @@ static int sn95031_initialize_adc(struct snd_soc_codec *sn95031_codec)
 {
        int base_addr, chnl_addr;
        int value;
-       static int channel_index;
+       int channel_index;
 
        /* Index of the first channel in which the stop bit is set */
        channel_index = find_free_channel(sn95031_codec);
@@ -163,7 +161,6 @@ static unsigned int sn95031_get_mic_bias(struct snd_soc_codec *codec)
        pr_debug("mic bias = %dmV\n", mic_bias);
        return mic_bias;
 }
-EXPORT_SYMBOL_GPL(sn95031_get_mic_bias);
 /*end - adc helper functions */
 
 static inline unsigned int sn95031_read(struct snd_soc_codec *codec,
@@ -660,7 +657,7 @@ static int sn95031_pcm_spkr_mute(struct snd_soc_dai *dai, int mute)
        return 0;
 }
 
-int sn95031_pcm_hw_params(struct snd_pcm_substream *substream,
+static int sn95031_pcm_hw_params(struct snd_pcm_substream *substream,
                struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
 {
        unsigned int format, rate;
@@ -718,7 +715,7 @@ static struct snd_soc_dai_ops sn95031_vib2_dai_ops = {
        .hw_params      = sn95031_pcm_hw_params,
 };
 
-struct snd_soc_dai_driver sn95031_dais[] = {
+static struct snd_soc_dai_driver sn95031_dais[] = {
 {
        .name = "SN95031 Headset",
        .playback = {
@@ -829,7 +826,6 @@ static int sn95031_codec_probe(struct snd_soc_codec *codec)
 {
        pr_debug("codec_probe called\n");
 
-       codec->dapm.bias_level = SND_SOC_BIAS_OFF;
        codec->dapm.idle_bias_off = 1;
 
        /* PCM interface config
index 9801cd7cfcb55ca108c3689d504e7b78a7944a04..3cb3271c5fe2019501cde20e9f1b73f872476282 100644 (file)
@@ -59,6 +59,7 @@ struct ssm2602_priv {
        struct snd_pcm_substream *slave_substream;
 
        enum ssm2602_type type;
+       unsigned int clk_out_pwr;
 };
 
 /*
@@ -294,7 +295,6 @@ static int ssm2602_startup(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_codec *codec = rtd->codec;
        struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
-       struct i2c_client *i2c = codec->control_data;
        struct snd_pcm_runtime *master_runtime;
 
        /* The DAI has shared clocks so if we already have a playback or
@@ -303,7 +303,7 @@ static int ssm2602_startup(struct snd_pcm_substream *substream,
         */
        if (ssm2602->master_substream) {
                master_runtime = ssm2602->master_substream->runtime;
-               dev_dbg(&i2c->dev, "Constraining to %d bits at %dHz\n",
+               dev_dbg(codec->dev, "Constraining to %d bits at %dHz\n",
                        master_runtime->sample_bits,
                        master_runtime->rate);
 
@@ -343,12 +343,14 @@ static void ssm2602_shutdown(struct snd_pcm_substream *substream,
 static int ssm2602_mute(struct snd_soc_dai *dai, int mute)
 {
        struct snd_soc_codec *codec = dai->codec;
-       u16 mute_reg = snd_soc_read(codec, SSM2602_APDIGI) & ~APDIGI_ENABLE_DAC_MUTE;
+
        if (mute)
-               snd_soc_write(codec, SSM2602_APDIGI,
-                               mute_reg | APDIGI_ENABLE_DAC_MUTE);
+               snd_soc_update_bits(codec, SSM2602_APDIGI,
+                                   APDIGI_ENABLE_DAC_MUTE,
+                                   APDIGI_ENABLE_DAC_MUTE);
        else
-               snd_soc_write(codec, SSM2602_APDIGI, mute_reg);
+               snd_soc_update_bits(codec, SSM2602_APDIGI,
+                                   APDIGI_ENABLE_DAC_MUTE, 0);
        return 0;
 }
 
@@ -357,16 +359,46 @@ static int ssm2602_set_dai_sysclk(struct snd_soc_dai *codec_dai,
 {
        struct snd_soc_codec *codec = codec_dai->codec;
        struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
-       switch (freq) {
-       case 11289600:
-       case 12000000:
-       case 12288000:
-       case 16934400:
-       case 18432000:
-               ssm2602->sysclk = freq;
-               return 0;
+
+       if (dir == SND_SOC_CLOCK_IN) {
+               if (clk_id != SSM2602_SYSCLK)
+                       return -EINVAL;
+
+               switch (freq) {
+               case 11289600:
+               case 12000000:
+               case 12288000:
+               case 16934400:
+               case 18432000:
+                       ssm2602->sysclk = freq;
+                       break;
+               default:
+                       return -EINVAL;
+               }
+       } else {
+               unsigned int mask;
+
+               switch (clk_id) {
+               case SSM2602_CLK_CLKOUT:
+                       mask = PWR_CLK_OUT_PDN;
+                       break;
+               case SSM2602_CLK_XTO:
+                       mask = PWR_OSC_PDN;
+                       break;
+               default:
+                       return -EINVAL;
+               }
+
+               if (freq == 0)
+                       ssm2602->clk_out_pwr |= mask;
+               else
+                       ssm2602->clk_out_pwr &= ~mask;
+
+               snd_soc_update_bits(codec, SSM2602_PWR,
+                       PWR_CLK_OUT_PDN | PWR_OSC_PDN, ssm2602->clk_out_pwr);
        }
-       return -EINVAL;
+
+       return 0;
 }
 
 static int ssm2602_set_dai_fmt(struct snd_soc_dai *codec_dai,
@@ -431,23 +463,27 @@ static int ssm2602_set_dai_fmt(struct snd_soc_dai *codec_dai,
 static int ssm2602_set_bias_level(struct snd_soc_codec *codec,
                                 enum snd_soc_bias_level level)
 {
-       u16 reg = snd_soc_read(codec, SSM2602_PWR);
-       reg &= ~(PWR_POWER_OFF | PWR_OSC_PDN);
+       struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
 
        switch (level) {
        case SND_SOC_BIAS_ON:
-               /* vref/mid, osc on, dac unmute */
-               snd_soc_write(codec, SSM2602_PWR, reg);
+               /* vref/mid on, osc and clkout on if enabled */
+               snd_soc_update_bits(codec, SSM2602_PWR,
+                       PWR_POWER_OFF | PWR_CLK_OUT_PDN | PWR_OSC_PDN,
+                       ssm2602->clk_out_pwr);
                break;
        case SND_SOC_BIAS_PREPARE:
                break;
        case SND_SOC_BIAS_STANDBY:
                /* everything off except vref/vmid, */
-               snd_soc_write(codec, SSM2602_PWR, reg | PWR_CLK_OUT_PDN);
+               snd_soc_update_bits(codec, SSM2602_PWR,
+                       PWR_POWER_OFF | PWR_CLK_OUT_PDN | PWR_OSC_PDN,
+                       PWR_CLK_OUT_PDN | PWR_OSC_PDN);
                break;
        case SND_SOC_BIAS_OFF:
-               /* everything off, dac mute, inactive */
-               snd_soc_write(codec, SSM2602_PWR, 0xffff);
+               /* everything off */
+               snd_soc_update_bits(codec, SSM2602_PWR,
+                       PWR_POWER_OFF, PWR_POWER_OFF);
                break;
 
        }
@@ -506,12 +542,12 @@ static int ssm2602_resume(struct snd_soc_codec *codec)
 static int ssm2602_probe(struct snd_soc_codec *codec)
 {
        struct snd_soc_dapm_context *dapm = &codec->dapm;
-       int ret, reg;
+       int ret;
 
-       reg = snd_soc_read(codec, SSM2602_LOUT1V);
-       snd_soc_write(codec, SSM2602_LOUT1V, reg | LOUT1V_LRHP_BOTH);
-       reg = snd_soc_read(codec, SSM2602_ROUT1V);
-       snd_soc_write(codec, SSM2602_ROUT1V, reg | ROUT1V_RLHP_BOTH);
+       snd_soc_update_bits(codec, SSM2602_LOUT1V,
+                           LOUT1V_LRHP_BOTH, LOUT1V_LRHP_BOTH);
+       snd_soc_update_bits(codec, SSM2602_ROUT1V,
+                           ROUT1V_RLHP_BOTH, ROUT1V_RLHP_BOTH);
 
        ret = snd_soc_add_controls(codec, ssm2602_snd_controls,
                        ARRAY_SIZE(ssm2602_snd_controls));
@@ -544,7 +580,7 @@ static int ssm2604_probe(struct snd_soc_codec *codec)
 static int ssm260x_probe(struct snd_soc_codec *codec)
 {
        struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
-       int ret, reg;
+       int ret;
 
        pr_info("ssm2602 Audio Codec %s", SSM2602_VERSION);
 
@@ -561,10 +597,10 @@ static int ssm260x_probe(struct snd_soc_codec *codec)
        }
 
        /* set the update bits */
-       reg = snd_soc_read(codec, SSM2602_LINVOL);
-       snd_soc_write(codec, SSM2602_LINVOL, reg | LINVOL_LRIN_BOTH);
-       reg = snd_soc_read(codec, SSM2602_RINVOL);
-       snd_soc_write(codec, SSM2602_RINVOL, reg | RINVOL_RLIN_BOTH);
+       snd_soc_update_bits(codec, SSM2602_LINVOL,
+                           LINVOL_LRIN_BOTH, LINVOL_LRIN_BOTH);
+       snd_soc_update_bits(codec, SSM2602_RINVOL,
+                           RINVOL_RLIN_BOTH, RINVOL_RLIN_BOTH);
        /*select Line in as default input*/
        snd_soc_write(codec, SSM2602_APANA, APANA_SELECT_DAC |
                        APANA_ENABLE_MIC_BOOST);
@@ -578,7 +614,12 @@ static int ssm260x_probe(struct snd_soc_codec *codec)
                break;
        }
 
-       return ret;
+       if (ret)
+               return ret;
+
+       ssm2602_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+
+       return 0;
 }
 
 /* remove everything here */
index b98c69168036d5b84744e42621e8d0732de3796d..fbd07d7b73ca2ad7bfced7147de22cec746e7bc4 100644 (file)
 
 #define SSM2602_CACHEREGNUM    10
 
-#define SSM2602_SYSCLK 0
+enum ssm2602_clk {
+       SSM2602_SYSCLK,
+       SSM2602_CLK_CLKOUT,
+       SSM2602_CLK_XTO
+};
 
 #endif
index fbd7eb9e61ce197ae9c5bb22df308d618f9545eb..bb82408ab8e1bb93f187dac610e5a1141501bd72 100644 (file)
@@ -524,13 +524,17 @@ static int sta32x_hw_params(struct snd_pcm_substream *substream,
        rate = params_rate(params);
        pr_debug("rate: %u\n", rate);
        for (i = 0; i < ARRAY_SIZE(interpolation_ratios); i++)
-               if (interpolation_ratios[i].fs == rate)
+               if (interpolation_ratios[i].fs == rate) {
                        ir = interpolation_ratios[i].ir;
+                       break;
+               }
        if (ir < 0)
                return -EINVAL;
        for (i = 0; mclk_ratios[ir][i].ratio; i++)
-               if (mclk_ratios[ir][i].ratio * rate == sta32x->mclk)
+               if (mclk_ratios[ir][i].ratio * rate == sta32x->mclk) {
                        mcs = mclk_ratios[ir][i].mcs;
+                       break;
+               }
        if (mcs < 0)
                return -EINVAL;
 
@@ -752,25 +756,19 @@ static int sta32x_probe(struct snd_soc_codec *codec)
                return ret;
        }
 
-       /* read reg reset values into cache */
-       for (i = 0; i < STA32X_REGISTER_COUNT; i++)
-               snd_soc_cache_write(codec, i, sta32x_regs[i]);
-
-       /* preserve reset values of reserved register bits */
-       snd_soc_cache_write(codec, STA32X_CONFC,
-                           codec->hw_read(codec, STA32X_CONFC));
-       snd_soc_cache_write(codec, STA32X_CONFE,
-                           codec->hw_read(codec, STA32X_CONFE));
-       snd_soc_cache_write(codec, STA32X_CONFF,
-                           codec->hw_read(codec, STA32X_CONFF));
-       snd_soc_cache_write(codec, STA32X_MMUTE,
-                           codec->hw_read(codec, STA32X_MMUTE));
-       snd_soc_cache_write(codec, STA32X_AUTO1,
-                           codec->hw_read(codec, STA32X_AUTO1));
-       snd_soc_cache_write(codec, STA32X_AUTO3,
-                           codec->hw_read(codec, STA32X_AUTO3));
-       snd_soc_cache_write(codec, STA32X_C3CFG,
-                           codec->hw_read(codec, STA32X_C3CFG));
+       /* Chip documentation explicitly requires that the reset values
+        * of reserved register bits are left untouched.
+        * Write the register default value to cache for reserved registers,
+        * so the write to the these registers are suppressed by the cache
+        * restore code when it skips writes of default registers.
+        */
+       snd_soc_cache_write(codec, STA32X_CONFC, 0xc2);
+       snd_soc_cache_write(codec, STA32X_CONFE, 0xc2);
+       snd_soc_cache_write(codec, STA32X_CONFF, 0x5c);
+       snd_soc_cache_write(codec, STA32X_MMUTE, 0x10);
+       snd_soc_cache_write(codec, STA32X_AUTO1, 0x60);
+       snd_soc_cache_write(codec, STA32X_AUTO3, 0x00);
+       snd_soc_cache_write(codec, STA32X_C3CFG, 0x40);
 
        /* FIXME enable thermal warning adjustment and recovery  */
        snd_soc_update_bits(codec, STA32X_CONFA,
@@ -808,6 +806,7 @@ static int sta32x_remove(struct snd_soc_codec *codec)
 {
        struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec);
 
+       sta32x_set_bias_level(codec, SND_SOC_BIAS_OFF);
        regulator_bulk_disable(ARRAY_SIZE(sta32x->supplies), sta32x->supplies);
        regulator_bulk_free(ARRAY_SIZE(sta32x->supplies), sta32x->supplies);
 
@@ -832,6 +831,7 @@ static const struct snd_soc_codec_driver sta32x_codec = {
        .resume =               sta32x_resume,
        .reg_cache_size =       STA32X_REGISTER_COUNT,
        .reg_word_size =        sizeof(u8),
+       .reg_cache_default =    sta32x_regs,
        .volatile_register =    sta32x_reg_is_volatile,
        .set_bias_level =       sta32x_set_bias_level,
        .controls =             sta32x_snd_controls,
@@ -867,18 +867,8 @@ static __devinit int sta32x_i2c_probe(struct i2c_client *i2c,
 static __devexit int sta32x_i2c_remove(struct i2c_client *client)
 {
        struct sta32x_priv *sta32x = i2c_get_clientdata(client);
-       struct snd_soc_codec *codec = sta32x->codec;
-
-       if (codec)
-               sta32x_set_bias_level(codec, SND_SOC_BIAS_OFF);
-
-       regulator_bulk_free(ARRAY_SIZE(sta32x->supplies), sta32x->supplies);
-
-       if (codec) {
-               snd_soc_unregister_codec(&client->dev);
-               snd_soc_codec_set_drvdata(codec, NULL);
-       }
 
+       snd_soc_unregister_codec(&client->dev);
        kfree(sta32x);
        return 0;
 }
index 33bb52f3f68306686025890cd287a52292373fec..ab27dbcd1262937f841cc3b6d1331c6d0025adff 100644 (file)
@@ -47,63 +47,6 @@ static const u16 tlv320aic23_reg[] = {
        0x0000, 0x0000, 0x0000, 0x0000, /* 12 */
 };
 
-/*
- * read tlv320aic23 register cache
- */
-static inline unsigned int tlv320aic23_read_reg_cache(struct snd_soc_codec
-                                                     *codec, unsigned int reg)
-{
-       u16 *cache = codec->reg_cache;
-       if (reg >= ARRAY_SIZE(tlv320aic23_reg))
-               return -1;
-       return cache[reg];
-}
-
-/*
- * write tlv320aic23 register cache
- */
-static inline void tlv320aic23_write_reg_cache(struct snd_soc_codec *codec,
-                                              u8 reg, u16 value)
-{
-       u16 *cache = codec->reg_cache;
-       if (reg >= ARRAY_SIZE(tlv320aic23_reg))
-               return;
-       cache[reg] = value;
-}
-
-/*
- * write to the tlv320aic23 register space
- */
-static int tlv320aic23_write(struct snd_soc_codec *codec, unsigned int reg,
-                            unsigned int value)
-{
-
-       u8 data[2];
-
-       /* TLV320AIC23 has 7 bit address and 9 bits of data
-        * so we need to switch one data bit into reg and rest
-        * of data into val
-        */
-
-       if (reg > 9 && reg != 15) {
-               printk(KERN_WARNING "%s Invalid register R%u\n", __func__, reg);
-               return -1;
-       }
-
-       data[0] = (reg << 1) | (value >> 8 & 0x01);
-       data[1] = value & 0xff;
-
-       tlv320aic23_write_reg_cache(codec, reg, value);
-
-       if (codec->hw_write(codec->control_data, data, 2) == 2)
-               return 0;
-
-       printk(KERN_ERR "%s cannot write %03x to register R%u\n", __func__,
-              value, reg);
-
-       return -EIO;
-}
-
 static const char *rec_src_text[] = { "Line", "Mic" };
 static const char *deemph_text[] = {"None", "32Khz", "44.1Khz", "48Khz"};
 
@@ -139,8 +82,8 @@ static int snd_soc_tlv320aic23_put_volsw(struct snd_kcontrol *kcontrol,
        */
        val = (val >= 4) ? 4  : (3 - val);
 
-       reg = tlv320aic23_read_reg_cache(codec, TLV320AIC23_ANLG) & (~0x1C0);
-       tlv320aic23_write(codec, TLV320AIC23_ANLG, reg | (val << 6));
+       reg = snd_soc_read(codec, TLV320AIC23_ANLG) & (~0x1C0);
+       snd_soc_write(codec, TLV320AIC23_ANLG, reg | (val << 6));
 
        return 0;
 }
@@ -151,7 +94,7 @@ static int snd_soc_tlv320aic23_get_volsw(struct snd_kcontrol *kcontrol,
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
        u16 val;
 
-       val = tlv320aic23_read_reg_cache(codec, TLV320AIC23_ANLG) & (0x1C0);
+       val = snd_soc_read(codec, TLV320AIC23_ANLG) & (0x1C0);
        val = val >> 6;
        val = (val >= 4) ? 4  : (3 -  val);
        ucontrol->value.integer.value[0] = val;
@@ -159,15 +102,6 @@ static int snd_soc_tlv320aic23_get_volsw(struct snd_kcontrol *kcontrol,
 
 }
 
-#define SOC_TLV320AIC23_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \
-{      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
-       .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
-                SNDRV_CTL_ELEM_ACCESS_READWRITE,\
-       .tlv.p = (tlv_array), \
-       .info = snd_soc_info_volsw, .get = snd_soc_tlv320aic23_get_volsw,\
-       .put = snd_soc_tlv320aic23_put_volsw, \
-       .private_value =  SOC_SINGLE_VALUE(reg, shift, max, invert) }
-
 static const struct snd_kcontrol_new tlv320aic23_snd_controls[] = {
        SOC_DOUBLE_R_TLV("Digital Playback Volume", TLV320AIC23_LCHNVOL,
                         TLV320AIC23_RCHNVOL, 0, 127, 0, out_gain_tlv),
@@ -178,8 +112,9 @@ static const struct snd_kcontrol_new tlv320aic23_snd_controls[] = {
                         TLV320AIC23_RINVOL, 0, 31, 0, input_gain_tlv),
        SOC_SINGLE("Mic Input Switch", TLV320AIC23_ANLG, 1, 1, 1),
        SOC_SINGLE("Mic Booster Switch", TLV320AIC23_ANLG, 0, 1, 0),
-       SOC_TLV320AIC23_SINGLE_TLV("Sidetone Volume", TLV320AIC23_ANLG,
-                                 6, 4, 0, sidetone_vol_tlv),
+       SOC_SINGLE_EXT_TLV("Sidetone Volume", TLV320AIC23_ANLG, 6, 4, 0,
+                          snd_soc_tlv320aic23_get_volsw,
+                          snd_soc_tlv320aic23_put_volsw, sidetone_vol_tlv),
        SOC_ENUM("Playback De-emphasis", tlv320aic23_deemph),
 };
 
@@ -240,7 +175,6 @@ static const struct snd_soc_dapm_route tlv320aic23_intercon[] = {
 /* AIC23 driver data */
 struct aic23 {
        enum snd_soc_control_type control_type;
-       void *control_data;
        int mclk;
        int requested_adc;
        int requested_dac;
@@ -352,7 +286,7 @@ static int find_rate(int mclk, u32 need_adc, u32 need_dac)
 static void get_current_sample_rates(struct snd_soc_codec *codec, int mclk,
                u32 *sample_rate_adc, u32 *sample_rate_dac)
 {
-       int src = tlv320aic23_read_reg_cache(codec, TLV320AIC23_SRATE);
+       int src = snd_soc_read(codec, TLV320AIC23_SRATE);
        int sr = (src >> 2) & 0x0f;
        int val = (mclk / bosr_usb_divisor_table[src & 3]);
        int adc = (val * sr_adc_mult_table[sr]) / SR_MULT;
@@ -376,7 +310,7 @@ static int set_sample_rate_control(struct snd_soc_codec *codec, int mclk,
                                __func__, sample_rate_adc, sample_rate_dac);
                return -EINVAL;
        }
-       tlv320aic23_write(codec, TLV320AIC23_SRATE, data);
+       snd_soc_write(codec, TLV320AIC23_SRATE, data);
 #ifdef DEBUG
        {
                u32 adc, dac;
@@ -415,9 +349,8 @@ static int tlv320aic23_hw_params(struct snd_pcm_substream *substream,
        if (ret < 0)
                return ret;
 
-       iface_reg =
-           tlv320aic23_read_reg_cache(codec,
-                                      TLV320AIC23_DIGT_FMT) & ~(0x03 << 2);
+       iface_reg = snd_soc_read(codec, TLV320AIC23_DIGT_FMT) & ~(0x03 << 2);
+
        switch (params_format(params)) {
        case SNDRV_PCM_FORMAT_S16_LE:
                break;
@@ -431,7 +364,7 @@ static int tlv320aic23_hw_params(struct snd_pcm_substream *substream,
                iface_reg |= (0x03 << 2);
                break;
        }
-       tlv320aic23_write(codec, TLV320AIC23_DIGT_FMT, iface_reg);
+       snd_soc_write(codec, TLV320AIC23_DIGT_FMT, iface_reg);
 
        return 0;
 }
@@ -443,7 +376,7 @@ static int tlv320aic23_pcm_prepare(struct snd_pcm_substream *substream,
        struct snd_soc_codec *codec = rtd->codec;
 
        /* set active */
-       tlv320aic23_write(codec, TLV320AIC23_ACTIVE, 0x0001);
+       snd_soc_write(codec, TLV320AIC23_ACTIVE, 0x0001);
 
        return 0;
 }
@@ -458,7 +391,7 @@ static void tlv320aic23_shutdown(struct snd_pcm_substream *substream,
        /* deactivate */
        if (!codec->active) {
                udelay(50);
-               tlv320aic23_write(codec, TLV320AIC23_ACTIVE, 0x0);
+               snd_soc_write(codec, TLV320AIC23_ACTIVE, 0x0);
        }
        if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
                aic23->requested_dac = 0;
@@ -471,14 +404,14 @@ static int tlv320aic23_mute(struct snd_soc_dai *dai, int mute)
        struct snd_soc_codec *codec = dai->codec;
        u16 reg;
 
-       reg = tlv320aic23_read_reg_cache(codec, TLV320AIC23_DIGT);
+       reg = snd_soc_read(codec, TLV320AIC23_DIGT);
        if (mute)
                reg |= TLV320AIC23_DACM_MUTE;
 
        else
                reg &= ~TLV320AIC23_DACM_MUTE;
 
-       tlv320aic23_write(codec, TLV320AIC23_DIGT, reg);
+       snd_soc_write(codec, TLV320AIC23_DIGT, reg);
 
        return 0;
 }
@@ -489,8 +422,7 @@ static int tlv320aic23_set_dai_fmt(struct snd_soc_dai *codec_dai,
        struct snd_soc_codec *codec = codec_dai->codec;
        u16 iface_reg;
 
-       iface_reg =
-           tlv320aic23_read_reg_cache(codec, TLV320AIC23_DIGT_FMT) & (~0x03);
+       iface_reg = snd_soc_read(codec, TLV320AIC23_DIGT_FMT) & (~0x03);
 
        /* set master/slave audio interface */
        switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
@@ -524,7 +456,7 @@ static int tlv320aic23_set_dai_fmt(struct snd_soc_dai *codec_dai,
 
        }
 
-       tlv320aic23_write(codec, TLV320AIC23_DIGT_FMT, iface_reg);
+       snd_soc_write(codec, TLV320AIC23_DIGT_FMT, iface_reg);
 
        return 0;
 }
@@ -540,26 +472,26 @@ static int tlv320aic23_set_dai_sysclk(struct snd_soc_dai *codec_dai,
 static int tlv320aic23_set_bias_level(struct snd_soc_codec *codec,
                                      enum snd_soc_bias_level level)
 {
-       u16 reg = tlv320aic23_read_reg_cache(codec, TLV320AIC23_PWR) & 0xff7f;
+       u16 reg = snd_soc_read(codec, TLV320AIC23_PWR) & 0xff7f;
 
        switch (level) {
        case SND_SOC_BIAS_ON:
                /* vref/mid, osc on, dac unmute */
                reg &= ~(TLV320AIC23_DEVICE_PWR_OFF | TLV320AIC23_OSC_OFF | \
                        TLV320AIC23_DAC_OFF);
-               tlv320aic23_write(codec, TLV320AIC23_PWR, reg);
+               snd_soc_write(codec, TLV320AIC23_PWR, reg);
                break;
        case SND_SOC_BIAS_PREPARE:
                break;
        case SND_SOC_BIAS_STANDBY:
                /* everything off except vref/vmid, */
-               tlv320aic23_write(codec, TLV320AIC23_PWR, reg | \
-                       TLV320AIC23_CLK_OFF);
+               snd_soc_write(codec, TLV320AIC23_PWR,
+                             reg | TLV320AIC23_CLK_OFF);
                break;
        case SND_SOC_BIAS_OFF:
                /* everything off, dac mute, inactive */
-               tlv320aic23_write(codec, TLV320AIC23_ACTIVE, 0x0);
-               tlv320aic23_write(codec, TLV320AIC23_PWR, 0xffff);
+               snd_soc_write(codec, TLV320AIC23_ACTIVE, 0x0);
+               snd_soc_write(codec, TLV320AIC23_PWR, 0xffff);
                break;
        }
        codec->dapm.bias_level = level;
@@ -606,13 +538,7 @@ static int tlv320aic23_suspend(struct snd_soc_codec *codec,
 
 static int tlv320aic23_resume(struct snd_soc_codec *codec)
 {
-       u16 reg;
-
-       /* Sync reg_cache with the hardware */
-       for (reg = 0; reg <= TLV320AIC23_ACTIVE; reg++) {
-               u16 val = tlv320aic23_read_reg_cache(codec, reg);
-               tlv320aic23_write(codec, reg, val);
-       }
+       snd_soc_cache_sync(codec);
        tlv320aic23_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
        return 0;
@@ -621,46 +547,52 @@ static int tlv320aic23_resume(struct snd_soc_codec *codec)
 static int tlv320aic23_probe(struct snd_soc_codec *codec)
 {
        struct aic23 *aic23 = snd_soc_codec_get_drvdata(codec);
-       int reg;
+       int ret;
 
        printk(KERN_INFO "AIC23 Audio Codec %s\n", AIC23_VERSION);
-       codec->control_data = aic23->control_data;
-       codec->hw_write = (hw_write_t)i2c_master_send;
-       codec->hw_read = NULL;
+
+       ret = snd_soc_codec_set_cache_io(codec, 7, 9, aic23->control_type);
+       if (ret < 0) {
+               dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
+               return ret;
+       }
 
        /* Reset codec */
-       tlv320aic23_write(codec, TLV320AIC23_RESET, 0);
+       snd_soc_write(codec, TLV320AIC23_RESET, 0);
+
+       /* Write the register default value to cache for reserved registers,
+        * so the write to the these registers are suppressed by the cache
+        * restore code when it skips writes of default registers.
+        */
+       snd_soc_cache_write(codec, 0x0A, 0);
+       snd_soc_cache_write(codec, 0x0B, 0);
+       snd_soc_cache_write(codec, 0x0C, 0);
+       snd_soc_cache_write(codec, 0x0D, 0);
+       snd_soc_cache_write(codec, 0x0E, 0);
 
        /* power on device */
        tlv320aic23_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
-       tlv320aic23_write(codec, TLV320AIC23_DIGT, TLV320AIC23_DEEMP_44K);
+       snd_soc_write(codec, TLV320AIC23_DIGT, TLV320AIC23_DEEMP_44K);
 
        /* Unmute input */
-       reg = tlv320aic23_read_reg_cache(codec, TLV320AIC23_LINVOL);
-       tlv320aic23_write(codec, TLV320AIC23_LINVOL,
-                         (reg & (~TLV320AIC23_LIM_MUTED)) |
-                         (TLV320AIC23_LRS_ENABLED));
+       snd_soc_update_bits(codec, TLV320AIC23_LINVOL,
+                           TLV320AIC23_LIM_MUTED, TLV320AIC23_LRS_ENABLED);
 
-       reg = tlv320aic23_read_reg_cache(codec, TLV320AIC23_RINVOL);
-       tlv320aic23_write(codec, TLV320AIC23_RINVOL,
-                         (reg & (~TLV320AIC23_LIM_MUTED)) |
-                         TLV320AIC23_LRS_ENABLED);
+       snd_soc_update_bits(codec, TLV320AIC23_RINVOL,
+                           TLV320AIC23_LIM_MUTED, TLV320AIC23_LRS_ENABLED);
 
-       reg = tlv320aic23_read_reg_cache(codec, TLV320AIC23_ANLG);
-       tlv320aic23_write(codec, TLV320AIC23_ANLG,
-                        (reg) & (~TLV320AIC23_BYPASS_ON) &
-                        (~TLV320AIC23_MICM_MUTED));
+       snd_soc_update_bits(codec, TLV320AIC23_ANLG,
+                           TLV320AIC23_BYPASS_ON | TLV320AIC23_MICM_MUTED,
+                           0);
 
        /* Default output volume */
-       tlv320aic23_write(codec, TLV320AIC23_LCHNVOL,
-                         TLV320AIC23_DEFAULT_OUT_VOL &
-                         TLV320AIC23_OUT_VOL_MASK);
-       tlv320aic23_write(codec, TLV320AIC23_RCHNVOL,
-                         TLV320AIC23_DEFAULT_OUT_VOL &
-                         TLV320AIC23_OUT_VOL_MASK);
+       snd_soc_write(codec, TLV320AIC23_LCHNVOL,
+                     TLV320AIC23_DEFAULT_OUT_VOL & TLV320AIC23_OUT_VOL_MASK);
+       snd_soc_write(codec, TLV320AIC23_RCHNVOL,
+                     TLV320AIC23_DEFAULT_OUT_VOL & TLV320AIC23_OUT_VOL_MASK);
 
-       tlv320aic23_write(codec, TLV320AIC23_ACTIVE, 0x1);
+       snd_soc_write(codec, TLV320AIC23_ACTIVE, 0x1);
 
        snd_soc_add_controls(codec, tlv320aic23_snd_controls,
                                ARRAY_SIZE(tlv320aic23_snd_controls));
@@ -682,8 +614,6 @@ static struct snd_soc_codec_driver soc_codec_dev_tlv320aic23 = {
        .remove = tlv320aic23_remove,
        .suspend = tlv320aic23_suspend,
        .resume = tlv320aic23_resume,
-       .read = tlv320aic23_read_reg_cache,
-       .write = tlv320aic23_write,
        .set_bias_level = tlv320aic23_set_bias_level,
        .dapm_widgets = tlv320aic23_dapm_widgets,
        .num_dapm_widgets = ARRAY_SIZE(tlv320aic23_dapm_widgets),
@@ -710,7 +640,6 @@ static int tlv320aic23_codec_probe(struct i2c_client *i2c,
                return -ENOMEM;
 
        i2c_set_clientdata(i2c, aic23);
-       aic23->control_data = i2c;
        aic23->control_type = SND_SOC_I2C;
 
        ret =  snd_soc_register_codec(&i2c->dev,
index e93b9d1ae1dde9eb6046e34f95a32936e0f63b2f..b21c610051c0f53c03ab2f6c42bf9b12ef20dda9 100644 (file)
@@ -528,40 +528,33 @@ static int aic32x4_set_bias_level(struct snd_soc_codec *codec,
                                  enum snd_soc_bias_level level)
 {
        struct aic32x4_priv *aic32x4 = snd_soc_codec_get_drvdata(codec);
-       u8 value;
 
        switch (level) {
        case SND_SOC_BIAS_ON:
                if (aic32x4->master) {
                        /* Switch on PLL */
-                       value = snd_soc_read(codec, AIC32X4_PLLPR);
-                       snd_soc_write(codec, AIC32X4_PLLPR,
-                                     (value | AIC32X4_PLLEN));
+                       snd_soc_update_bits(codec, AIC32X4_PLLPR,
+                                           AIC32X4_PLLEN, AIC32X4_PLLEN);
 
                        /* Switch on NDAC Divider */
-                       value = snd_soc_read(codec, AIC32X4_NDAC);
-                       snd_soc_write(codec, AIC32X4_NDAC,
-                                     value | AIC32X4_NDACEN);
+                       snd_soc_update_bits(codec, AIC32X4_NDAC,
+                                           AIC32X4_NDACEN, AIC32X4_NDACEN);
 
                        /* Switch on MDAC Divider */
-                       value = snd_soc_read(codec, AIC32X4_MDAC);
-                       snd_soc_write(codec, AIC32X4_MDAC,
-                                     value | AIC32X4_MDACEN);
+                       snd_soc_update_bits(codec, AIC32X4_MDAC,
+                                           AIC32X4_MDACEN, AIC32X4_MDACEN);
 
                        /* Switch on NADC Divider */
-                       value = snd_soc_read(codec, AIC32X4_NADC);
-                       snd_soc_write(codec, AIC32X4_NADC,
-                                     value | AIC32X4_MDACEN);
+                       snd_soc_update_bits(codec, AIC32X4_NADC,
+                                           AIC32X4_NADCEN, AIC32X4_NADCEN);
 
                        /* Switch on MADC Divider */
-                       value = snd_soc_read(codec, AIC32X4_MADC);
-                       snd_soc_write(codec, AIC32X4_MADC,
-                                     value | AIC32X4_MDACEN);
+                       snd_soc_update_bits(codec, AIC32X4_MADC,
+                                           AIC32X4_MADCEN, AIC32X4_MADCEN);
 
                        /* Switch on BCLK_N Divider */
-                       value = snd_soc_read(codec, AIC32X4_BCLKN);
-                       snd_soc_write(codec, AIC32X4_BCLKN,
-                                     value | AIC32X4_BCLKEN);
+                       snd_soc_update_bits(codec, AIC32X4_BCLKN,
+                                           AIC32X4_BCLKEN, AIC32X4_BCLKEN);
                }
                break;
        case SND_SOC_BIAS_PREPARE:
@@ -569,34 +562,28 @@ static int aic32x4_set_bias_level(struct snd_soc_codec *codec,
        case SND_SOC_BIAS_STANDBY:
                if (aic32x4->master) {
                        /* Switch off PLL */
-                       value = snd_soc_read(codec, AIC32X4_PLLPR);
-                       snd_soc_write(codec, AIC32X4_PLLPR,
-                                     (value & ~AIC32X4_PLLEN));
+                       snd_soc_update_bits(codec, AIC32X4_PLLPR,
+                                           AIC32X4_PLLEN, 0);
 
                        /* Switch off NDAC Divider */
-                       value = snd_soc_read(codec, AIC32X4_NDAC);
-                       snd_soc_write(codec, AIC32X4_NDAC,
-                                     value & ~AIC32X4_NDACEN);
+                       snd_soc_update_bits(codec, AIC32X4_NDAC,
+                                           AIC32X4_NDACEN, 0);
 
                        /* Switch off MDAC Divider */
-                       value = snd_soc_read(codec, AIC32X4_MDAC);
-                       snd_soc_write(codec, AIC32X4_MDAC,
-                                     value & ~AIC32X4_MDACEN);
+                       snd_soc_update_bits(codec, AIC32X4_MDAC,
+                                           AIC32X4_MDACEN, 0);
 
                        /* Switch off NADC Divider */
-                       value = snd_soc_read(codec, AIC32X4_NADC);
-                       snd_soc_write(codec, AIC32X4_NADC,
-                                     value & ~AIC32X4_NDACEN);
+                       snd_soc_update_bits(codec, AIC32X4_NADC,
+                                           AIC32X4_NADCEN, 0);
 
                        /* Switch off MADC Divider */
-                       value = snd_soc_read(codec, AIC32X4_MADC);
-                       snd_soc_write(codec, AIC32X4_MADC,
-                                     value & ~AIC32X4_MDACEN);
-                       value = snd_soc_read(codec, AIC32X4_BCLKN);
+                       snd_soc_update_bits(codec, AIC32X4_MADC,
+                                           AIC32X4_MADCEN, 0);
 
                        /* Switch off BCLK_N Divider */
-                       snd_soc_write(codec, AIC32X4_BCLKN,
-                                     value & ~AIC32X4_BCLKEN);
+                       snd_soc_update_bits(codec, AIC32X4_BCLKN,
+                                           AIC32X4_BCLKEN, 0);
                }
                break;
        case SND_SOC_BIAS_OFF:
@@ -685,10 +672,10 @@ static int aic32x4_probe(struct snd_soc_codec *codec)
        }
 
        /* Mic PGA routing */
-       if (aic32x4->micpga_routing | AIC32X4_MICPGA_ROUTE_LMIC_IN2R_10K) {
+       if (aic32x4->micpga_routing & AIC32X4_MICPGA_ROUTE_LMIC_IN2R_10K) {
                snd_soc_write(codec, AIC32X4_LMICPGANIN, AIC32X4_LMICPGANIN_IN2R_10K);
        }
-       if (aic32x4->micpga_routing | AIC32X4_MICPGA_ROUTE_RMIC_IN1L_10K) {
+       if (aic32x4->micpga_routing & AIC32X4_MICPGA_ROUTE_RMIC_IN1L_10K) {
                snd_soc_write(codec, AIC32X4_RMICPGANIN, AIC32X4_RMICPGANIN_IN1L_10K);
        }
 
index 0963c4c7a83f7bae464c4b2b7165d82d42370e5b..7a49390bc30d44b89d35ba432af6b69693bb8188 100644 (file)
@@ -76,7 +76,6 @@ struct aic3x_priv {
        struct aic3x_disable_nb disable_nb[AIC3X_NUM_SUPPLIES];
        enum snd_soc_control_type control_type;
        struct aic3x_setup_data *setup;
-       void *control_data;
        unsigned int sysclk;
        struct list_head list;
        int master;
@@ -138,7 +137,10 @@ static int aic3x_read(struct snd_soc_codec *codec, unsigned int reg,
        if (reg >= AIC3X_CACHEREGNUM)
                return -1;
 
-       *value = codec->hw_read(codec, reg);
+       codec->cache_bypass = 1;
+       *value = snd_soc_read(codec, reg);
+       codec->cache_bypass = 0;
+
        cache[reg] = *value;
 
        return 0;
@@ -198,6 +200,10 @@ static int snd_soc_dapm_put_volsw_aic3x(struct snd_kcontrol *kcontrol,
                        else
                                /* old connection must be powered down */
                                path->connect = invert ? 1 : 0;
+
+                       dapm_mark_dirty(path->source, "tlv320aic3x source");
+                       dapm_mark_dirty(path->sink, "tlv320aic3x sink");
+
                        break;
                }
 
@@ -1383,7 +1389,6 @@ static int aic3x_probe(struct snd_soc_codec *codec)
        int ret, i;
 
        INIT_LIST_HEAD(&aic3x->list);
-       codec->control_data = aic3x->control_data;
        aic3x->codec = codec;
        codec->dapm.idle_bias_off = 1;
 
@@ -1495,9 +1500,9 @@ static struct snd_soc_codec_driver soc_codec_dev_aic3x = {
  */
 
 static const struct i2c_device_id aic3x_i2c_id[] = {
-       [AIC3X_MODEL_3X] = { "tlv320aic3x", 0 },
-       [AIC3X_MODEL_33] = { "tlv320aic33", 0 },
-       [AIC3X_MODEL_3007] = { "tlv320aic3007", 0 },
+       { "tlv320aic3x", AIC3X_MODEL_3X },
+       { "tlv320aic33", AIC3X_MODEL_33 },
+       { "tlv320aic3007", AIC3X_MODEL_3007 },
        { }
 };
 MODULE_DEVICE_TABLE(i2c, aic3x_i2c_id);
@@ -1512,7 +1517,6 @@ static int aic3x_i2c_probe(struct i2c_client *i2c,
        struct aic3x_pdata *pdata = i2c->dev.platform_data;
        struct aic3x_priv *aic3x;
        int ret;
-       const struct i2c_device_id *tbl;
 
        aic3x = kzalloc(sizeof(struct aic3x_priv), GFP_KERNEL);
        if (aic3x == NULL) {
@@ -1520,7 +1524,6 @@ static int aic3x_i2c_probe(struct i2c_client *i2c,
                return -ENOMEM;
        }
 
-       aic3x->control_data = i2c;
        aic3x->control_type = SND_SOC_I2C;
 
        i2c_set_clientdata(i2c, aic3x);
@@ -1531,11 +1534,7 @@ static int aic3x_i2c_probe(struct i2c_client *i2c,
                aic3x->gpio_reset = -1;
        }
 
-       for (tbl = aic3x_i2c_id; tbl->name[0]; tbl++) {
-               if (!strcmp(tbl->name, id->name))
-                       break;
-       }
-       aic3x->model = tbl - aic3x_i2c_id;
+       aic3x->model = id->driver_data;
 
        ret = snd_soc_register_codec(&i2c->dev,
                        &soc_codec_dev_aic3x, &aic3x_dai, 1);
index faa5e9fb1471de20e93a4fb108ffb884b0eb6f38..dc8a2b2bdc1ce73b939cc0455f7ba4931c153c2e 100644 (file)
 #define BURST_BASEFREQ_HZ      49152000
 
 #define SAMPLES_TO_US(rate, samples) \
-       (1000000000 / ((rate * 1000) / samples))
+       (1000000000 / (((rate) * 1000) / (samples)))
 
 #define US_TO_SAMPLES(rate, us) \
-       (rate / (1000000 / (us < 1000000 ? us : 1000000)))
+       ((rate) / (1000000 / ((us) < 1000000 ? (us) : 1000000)))
 
 #define UTHR_FROM_PERIOD_SIZE(samples, playrate, burstrate) \
-       ((samples * 5000) / ((burstrate * 5000) / (burstrate - playrate)))
+       (((samples)*5000) / (((burstrate)*5000) / ((burstrate) - (playrate))))
 
 static void dac33_calculate_times(struct snd_pcm_substream *substream);
 static int dac33_prepare_chip(struct snd_pcm_substream *substream);
@@ -627,18 +627,6 @@ static const struct snd_soc_dapm_route audio_map[] = {
        {"RIGHT_LO", NULL, "Codec Power"},
 };
 
-static int dac33_add_widgets(struct snd_soc_codec *codec)
-{
-       struct snd_soc_dapm_context *dapm = &codec->dapm;
-
-       snd_soc_dapm_new_controls(dapm, dac33_dapm_widgets,
-                                 ARRAY_SIZE(dac33_dapm_widgets));
-       /* set up audio path interconnects */
-       snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
-
-       return 0;
-}
-
 static int dac33_set_bias_level(struct snd_soc_codec *codec,
                                enum snd_soc_bias_level level)
 {
@@ -1431,7 +1419,7 @@ static int dac33_soc_probe(struct snd_soc_codec *codec)
        /* Check if the IRQ number is valid and request it */
        if (dac33->irq >= 0) {
                ret = request_irq(dac33->irq, dac33_interrupt_handler,
-                                 IRQF_TRIGGER_RISING | IRQF_DISABLED,
+                                 IRQF_TRIGGER_RISING,
                                  codec->name, codec);
                if (ret < 0) {
                        dev_err(codec->dev, "Could not request IRQ%d (%d)\n",
@@ -1451,15 +1439,11 @@ static int dac33_soc_probe(struct snd_soc_codec *codec)
                }
        }
 
-       snd_soc_add_controls(codec, dac33_snd_controls,
-                            ARRAY_SIZE(dac33_snd_controls));
        /* Only add the FIFO controls, if we have valid IRQ number */
        if (dac33->irq >= 0)
                snd_soc_add_controls(codec, dac33_mode_snd_controls,
                                     ARRAY_SIZE(dac33_mode_snd_controls));
 
-       dac33_add_widgets(codec);
-
 err_power:
        return ret;
 }
@@ -1502,6 +1486,13 @@ static struct snd_soc_codec_driver soc_codec_dev_tlv320dac33 = {
        .remove = dac33_soc_remove,
        .suspend = dac33_soc_suspend,
        .resume = dac33_soc_resume,
+
+       .controls = dac33_snd_controls,
+       .num_controls = ARRAY_SIZE(dac33_snd_controls),
+       .dapm_widgets = dac33_dapm_widgets,
+       .num_dapm_widgets = ARRAY_SIZE(dac33_dapm_widgets),
+       .dapm_routes = audio_map,
+       .num_dapm_routes = ARRAY_SIZE(audio_map),
 };
 
 #define DAC33_RATES    (SNDRV_PCM_RATE_44100 | \
index 239e0c461068bebb2189a0d7aaff22f472fc8d78..7eeca79d738784e612a3cca65bb15faa67a0a4b8 100644 (file)
 
 #include "tpa6130a2.h"
 
+enum tpa_model {
+       TPA6130A2,
+       TPA6140A2,
+};
+
 static struct i2c_client *tpa6130a2_client;
 
 /* This struct is used to save the context */
@@ -383,7 +388,7 @@ static int __devinit tpa6130a2_probe(struct i2c_client *client,
 
        pdata = client->dev.platform_data;
        data->power_gpio = pdata->power_gpio;
-       data->id = pdata->id;
+       data->id = id->driver_data;
 
        mutex_init(&data->mutex);
 
@@ -405,7 +410,7 @@ static int __devinit tpa6130a2_probe(struct i2c_client *client,
        switch (data->id) {
        default:
                dev_warn(dev, "Unknown TPA model (%d). Assuming 6130A2\n",
-                        pdata->id);
+                        data->id);
        case TPA6130A2:
                regulator = "Vdd";
                break;
@@ -446,7 +451,6 @@ err_regulator:
                gpio_free(data->power_gpio);
 err_gpio:
        kfree(data);
-       i2c_set_clientdata(tpa6130a2_client, NULL);
        tpa6130a2_client = NULL;
 
        return ret;
@@ -470,7 +474,8 @@ static int __devexit tpa6130a2_remove(struct i2c_client *client)
 }
 
 static const struct i2c_device_id tpa6130a2_id[] = {
-       { "tpa6130a2", 0 },
+       { "tpa6130a2", TPA6130A2 },
+       { "tpa6140a2", TPA6140A2 },
        { }
 };
 MODULE_DEVICE_TABLE(i2c, tpa6130a2_id);
index 71674bec9604fcceddf630ffaacfbf80895c0e0e..f798247ac1b2071e7316200be605734ed87faf6d 100644 (file)
@@ -863,34 +863,6 @@ static int digimic_event(struct snd_soc_dapm_widget *w,
  * Inverting not going to help with these.
  * Custom volsw and volsw_2r get/put functions to handle these gain bits.
  */
-#define SOC_DOUBLE_TLV_TWL4030(xname, xreg, shift_left, shift_right, xmax,\
-                              xinvert, tlv_array) \
-{      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
-       .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
-                SNDRV_CTL_ELEM_ACCESS_READWRITE,\
-       .tlv.p = (tlv_array), \
-       .info = snd_soc_info_volsw, \
-       .get = snd_soc_get_volsw_twl4030, \
-       .put = snd_soc_put_volsw_twl4030, \
-       .private_value = (unsigned long)&(struct soc_mixer_control) \
-               {.reg = xreg, .shift = shift_left, .rshift = shift_right,\
-                .max = xmax, .invert = xinvert} }
-#define SOC_DOUBLE_R_TLV_TWL4030(xname, reg_left, reg_right, xshift, xmax,\
-                                xinvert, tlv_array) \
-{      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
-       .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
-                SNDRV_CTL_ELEM_ACCESS_READWRITE,\
-       .tlv.p = (tlv_array), \
-       .info = snd_soc_info_volsw_2r, \
-       .get = snd_soc_get_volsw_r2_twl4030,\
-       .put = snd_soc_put_volsw_r2_twl4030, \
-       .private_value = (unsigned long)&(struct soc_mixer_control) \
-               {.reg = reg_left, .rreg = reg_right, .shift = xshift, \
-                .rshift = xshift, .max = xmax, .invert = xinvert} }
-#define SOC_SINGLE_TLV_TWL4030(xname, xreg, xshift, xmax, xinvert, tlv_array) \
-       SOC_DOUBLE_TLV_TWL4030(xname, xreg, xshift, xshift, xmax, \
-                              xinvert, tlv_array)
-
 static int snd_soc_get_volsw_twl4030(struct snd_kcontrol *kcontrol,
        struct snd_ctl_elem_value *ucontrol)
 {
@@ -1197,19 +1169,23 @@ static const struct snd_kcontrol_new twl4030_snd_controls[] = {
                TWL4030_REG_VDL_APGA_CTL, 1, 1, 0),
 
        /* Separate output gain controls */
-       SOC_DOUBLE_R_TLV_TWL4030("PreDriv Playback Volume",
+       SOC_DOUBLE_R_EXT_TLV("PreDriv Playback Volume",
                TWL4030_REG_PREDL_CTL, TWL4030_REG_PREDR_CTL,
-               4, 3, 0, output_tvl),
+               4, 3, 0, snd_soc_get_volsw_r2_twl4030,
+               snd_soc_put_volsw_r2_twl4030, output_tvl),
 
-       SOC_DOUBLE_TLV_TWL4030("Headset Playback Volume",
-               TWL4030_REG_HS_GAIN_SET, 0, 2, 3, 0, output_tvl),
+       SOC_DOUBLE_EXT_TLV("Headset Playback Volume",
+               TWL4030_REG_HS_GAIN_SET, 0, 2, 3, 0, snd_soc_get_volsw_twl4030,
+               snd_soc_put_volsw_twl4030, output_tvl),
 
-       SOC_DOUBLE_R_TLV_TWL4030("Carkit Playback Volume",
+       SOC_DOUBLE_R_EXT_TLV("Carkit Playback Volume",
                TWL4030_REG_PRECKL_CTL, TWL4030_REG_PRECKR_CTL,
-               4, 3, 0, output_tvl),
+               4, 3, 0, snd_soc_get_volsw_r2_twl4030,
+               snd_soc_put_volsw_r2_twl4030, output_tvl),
 
-       SOC_SINGLE_TLV_TWL4030("Earpiece Playback Volume",
-               TWL4030_REG_EAR_CTL, 4, 3, 0, output_ear_tvl),
+       SOC_SINGLE_EXT_TLV("Earpiece Playback Volume",
+               TWL4030_REG_EAR_CTL, 4, 3, 0, snd_soc_get_volsw_twl4030,
+               snd_soc_put_volsw_twl4030, output_ear_tvl),
 
        /* Common capture gain controls */
        SOC_DOUBLE_R_TLV("TX1 Digital Capture Volume",
@@ -1633,17 +1609,6 @@ static const struct snd_soc_dapm_route intercon[] = {
 
 };
 
-static int twl4030_add_widgets(struct snd_soc_codec *codec)
-{
-       struct snd_soc_dapm_context *dapm = &codec->dapm;
-
-       snd_soc_dapm_new_controls(dapm, twl4030_dapm_widgets,
-                                ARRAY_SIZE(twl4030_dapm_widgets));
-       snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
-
-       return 0;
-}
-
 static int twl4030_set_bias_level(struct snd_soc_codec *codec,
                                  enum snd_soc_bias_level level)
 {
@@ -2265,9 +2230,6 @@ static int twl4030_soc_probe(struct snd_soc_codec *codec)
 
        twl4030_init_chip(codec);
 
-       snd_soc_add_controls(codec, twl4030_snd_controls,
-                               ARRAY_SIZE(twl4030_snd_controls));
-       twl4030_add_widgets(codec);
        return 0;
 }
 
@@ -2293,6 +2255,13 @@ static struct snd_soc_codec_driver soc_codec_dev_twl4030 = {
        .reg_cache_size = sizeof(twl4030_reg),
        .reg_word_size = sizeof(u8),
        .reg_cache_default = twl4030_reg,
+
+       .controls = twl4030_snd_controls,
+       .num_controls = ARRAY_SIZE(twl4030_snd_controls),
+       .dapm_widgets = twl4030_dapm_widgets,
+       .num_dapm_widgets = ARRAY_SIZE(twl4030_dapm_widgets),
+       .dapm_routes = intercon,
+       .num_dapm_routes = ARRAY_SIZE(intercon),
 };
 
 static int __devinit twl4030_codec_probe(struct platform_device *pdev)
index 443032b3b3296baca51be67e7660a3c3d937f2c3..73e11f022dedc944c1010064435b17402b96194c 100644 (file)
 #define TWL6040_HF_VOL_MASK    0x1F
 #define TWL6040_HF_VOL_SHIFT   0
 
+/* Shadow register used by the driver */
+#define TWL6040_REG_SW_SHADOW  0x2F
+#define TWL6040_CACHEREGNUM    (TWL6040_REG_SW_SHADOW + 1)
+
+/* TWL6040_REG_SW_SHADOW (0x2F) fields */
+#define TWL6040_EAR_PATH_ENABLE        0x01
+
 struct twl6040_output {
        u16 active;
        u16 left_vol;
@@ -65,12 +72,13 @@ struct twl6040_output {
        u16 right_step;
        unsigned int step_delay;
        u16 ramp;
-       u16 mute;
+       struct delayed_work work;
        struct completion ramp_done;
 };
 
 struct twl6040_jack_data {
        struct snd_soc_jack *jack;
+       struct delayed_work work;
        int report;
 };
 
@@ -79,7 +87,6 @@ struct twl6040_data {
        int plug_irq;
        int codec_powered;
        int pll;
-       int non_lp;
        int pll_power_mode;
        int hs_power_mode;
        int hs_power_mode_locked;
@@ -92,104 +99,68 @@ struct twl6040_data {
        struct twl6040_jack_data hs_jack;
        struct snd_soc_codec *codec;
        struct workqueue_struct *workqueue;
-       struct delayed_work delayed_work;
        struct mutex mutex;
        struct twl6040_output headset;
        struct twl6040_output handsfree;
-       struct workqueue_struct *hf_workqueue;
-       struct workqueue_struct *hs_workqueue;
-       struct delayed_work hs_delayed_work;
-       struct delayed_work hf_delayed_work;
 };
 
 /*
  * twl6040 register cache & default register settings
  */
 static const u8 twl6040_reg[TWL6040_CACHEREGNUM] = {
-       0x00, /* not used               0x00    */
-       0x4B, /* TWL6040_ASICID (ro)    0x01    */
-       0x00, /* TWL6040_ASICREV (ro)   0x02    */
-       0x00, /* TWL6040_INTID          0x03    */
-       0x00, /* TWL6040_INTMR          0x04    */
-       0x00, /* TWL6040_NCPCTRL        0x05    */
-       0x00, /* TWL6040_LDOCTL         0x06    */
-       0x60, /* TWL6040_HPPLLCTL       0x07    */
-       0x00, /* TWL6040_LPPLLCTL       0x08    */
-       0x4A, /* TWL6040_LPPLLDIV       0x09    */
-       0x00, /* TWL6040_AMICBCTL       0x0A    */
-       0x00, /* TWL6040_DMICBCTL       0x0B    */
-       0x18, /* TWL6040_MICLCTL        0x0C    - No input selected on Left Mic */
-       0x18, /* TWL6040_MICRCTL        0x0D    - No input selected on Right Mic */
-       0x00, /* TWL6040_MICGAIN        0x0E    */
-       0x1B, /* TWL6040_LINEGAIN       0x0F    */
-       0x00, /* TWL6040_HSLCTL         0x10    */
-       0x00, /* TWL6040_HSRCTL         0x11    */
-       0x00, /* TWL6040_HSGAIN         0x12    */
-       0x00, /* TWL6040_EARCTL         0x13    */
-       0x00, /* TWL6040_HFLCTL         0x14    */
-       0x00, /* TWL6040_HFLGAIN        0x15    */
-       0x00, /* TWL6040_HFRCTL         0x16    */
-       0x00, /* TWL6040_HFRGAIN        0x17    */
-       0x00, /* TWL6040_VIBCTLL        0x18    */
-       0x00, /* TWL6040_VIBDATL        0x19    */
-       0x00, /* TWL6040_VIBCTLR        0x1A    */
-       0x00, /* TWL6040_VIBDATR        0x1B    */
-       0x00, /* TWL6040_HKCTL1         0x1C    */
-       0x00, /* TWL6040_HKCTL2         0x1D    */
-       0x00, /* TWL6040_GPOCTL         0x1E    */
-       0x00, /* TWL6040_ALB            0x1F    */
-       0x00, /* TWL6040_DLB            0x20    */
-       0x00, /* not used               0x21    */
-       0x00, /* not used               0x22    */
-       0x00, /* not used               0x23    */
-       0x00, /* not used               0x24    */
-       0x00, /* not used               0x25    */
-       0x00, /* not used               0x26    */
-       0x00, /* not used               0x27    */
-       0x00, /* TWL6040_TRIM1          0x28    */
-       0x00, /* TWL6040_TRIM2          0x29    */
-       0x00, /* TWL6040_TRIM3          0x2A    */
-       0x00, /* TWL6040_HSOTRIM        0x2B    */
-       0x00, /* TWL6040_HFOTRIM        0x2C    */
-       0x09, /* TWL6040_ACCCTL         0x2D    */
-       0x00, /* TWL6040_STATUS (ro)    0x2E    */
-};
-
-/*
- * twl6040 vio/gnd registers:
- * registers under vio/gnd supply can be accessed
- * before the power-up sequence, after NRESPWRON goes high
- */
-static const int twl6040_vio_reg[TWL6040_VIOREGNUM] = {
-       TWL6040_REG_ASICID,
-       TWL6040_REG_ASICREV,
-       TWL6040_REG_INTID,
-       TWL6040_REG_INTMR,
-       TWL6040_REG_NCPCTL,
-       TWL6040_REG_LDOCTL,
-       TWL6040_REG_AMICBCTL,
-       TWL6040_REG_DMICBCTL,
-       TWL6040_REG_HKCTL1,
-       TWL6040_REG_HKCTL2,
-       TWL6040_REG_GPOCTL,
-       TWL6040_REG_TRIM1,
-       TWL6040_REG_TRIM2,
-       TWL6040_REG_TRIM3,
-       TWL6040_REG_HSOTRIM,
-       TWL6040_REG_HFOTRIM,
-       TWL6040_REG_ACCCTL,
-       TWL6040_REG_STATUS,
+       0x00, /* not used       0x00    */
+       0x4B, /* REG_ASICID     0x01 (ro) */
+       0x00, /* REG_ASICREV    0x02 (ro) */
+       0x00, /* REG_INTID      0x03    */
+       0x00, /* REG_INTMR      0x04    */
+       0x00, /* REG_NCPCTRL    0x05    */
+       0x00, /* REG_LDOCTL     0x06    */
+       0x60, /* REG_HPPLLCTL   0x07    */
+       0x00, /* REG_LPPLLCTL   0x08    */
+       0x4A, /* REG_LPPLLDIV   0x09    */
+       0x00, /* REG_AMICBCTL   0x0A    */
+       0x00, /* REG_DMICBCTL   0x0B    */
+       0x00, /* REG_MICLCTL    0x0C    */
+       0x00, /* REG_MICRCTL    0x0D    */
+       0x00, /* REG_MICGAIN    0x0E    */
+       0x1B, /* REG_LINEGAIN   0x0F    */
+       0x00, /* REG_HSLCTL     0x10    */
+       0x00, /* REG_HSRCTL     0x11    */
+       0x00, /* REG_HSGAIN     0x12    */
+       0x00, /* REG_EARCTL     0x13    */
+       0x00, /* REG_HFLCTL     0x14    */
+       0x00, /* REG_HFLGAIN    0x15    */
+       0x00, /* REG_HFRCTL     0x16    */
+       0x00, /* REG_HFRGAIN    0x17    */
+       0x00, /* REG_VIBCTLL    0x18    */
+       0x00, /* REG_VIBDATL    0x19    */
+       0x00, /* REG_VIBCTLR    0x1A    */
+       0x00, /* REG_VIBDATR    0x1B    */
+       0x00, /* REG_HKCTL1     0x1C    */
+       0x00, /* REG_HKCTL2     0x1D    */
+       0x00, /* REG_GPOCTL     0x1E    */
+       0x00, /* REG_ALB        0x1F    */
+       0x00, /* REG_DLB        0x20    */
+       0x00, /* not used       0x21    */
+       0x00, /* not used       0x22    */
+       0x00, /* not used       0x23    */
+       0x00, /* not used       0x24    */
+       0x00, /* not used       0x25    */
+       0x00, /* not used       0x26    */
+       0x00, /* not used       0x27    */
+       0x00, /* REG_TRIM1      0x28    */
+       0x00, /* REG_TRIM2      0x29    */
+       0x00, /* REG_TRIM3      0x2A    */
+       0x00, /* REG_HSOTRIM    0x2B    */
+       0x00, /* REG_HFOTRIM    0x2C    */
+       0x09, /* REG_ACCCTL     0x2D    */
+       0x00, /* REG_STATUS     0x2E (ro) */
+
+       0x00, /* REG_SW_SHADOW  0x2F - Shadow, non HW register */
 };
 
-/*
- * twl6040 vdd/vss registers:
- * registers under vdd/vss supplies can only be accessed
- * after the power-up sequence
- */
-static const int twl6040_vdd_reg[TWL6040_VDDREGNUM] = {
-       TWL6040_REG_HPPLLCTL,
-       TWL6040_REG_LPPLLCTL,
-       TWL6040_REG_LPPLLDIV,
+/* List of registers to be restored after power up */
+static const int twl6040_restore_list[] = {
        TWL6040_REG_MICLCTL,
        TWL6040_REG_MICRCTL,
        TWL6040_REG_MICGAIN,
@@ -202,12 +173,6 @@ static const int twl6040_vdd_reg[TWL6040_VDDREGNUM] = {
        TWL6040_REG_HFLGAIN,
        TWL6040_REG_HFRCTL,
        TWL6040_REG_HFRGAIN,
-       TWL6040_REG_VIBCTLL,
-       TWL6040_REG_VIBDATL,
-       TWL6040_REG_VIBCTLR,
-       TWL6040_REG_VIBDATR,
-       TWL6040_REG_ALB,
-       TWL6040_REG_DLB,
 };
 
 /* set of rates for each pll: low-power and high-performance */
@@ -275,8 +240,12 @@ static int twl6040_read_reg_volatile(struct snd_soc_codec *codec,
        if (reg >= TWL6040_CACHEREGNUM)
                return -EIO;
 
-       value = twl6040_reg_read(twl6040, reg);
-       twl6040_write_reg_cache(codec, reg, value);
+       if (likely(reg < TWL6040_REG_SW_SHADOW)) {
+               value = twl6040_reg_read(twl6040, reg);
+               twl6040_write_reg_cache(codec, reg, value);
+       } else {
+               value = twl6040_read_reg_cache(codec, reg);
+       }
 
        return value;
 }
@@ -293,59 +262,51 @@ static int twl6040_write(struct snd_soc_codec *codec,
                return -EIO;
 
        twl6040_write_reg_cache(codec, reg, value);
-       return twl6040_reg_write(twl6040, reg, value);
+       if (likely(reg < TWL6040_REG_SW_SHADOW))
+               return twl6040_reg_write(twl6040, reg, value);
+       else
+               return 0;
 }
 
-static void twl6040_init_vio_regs(struct snd_soc_codec *codec)
+static void twl6040_init_chip(struct snd_soc_codec *codec)
 {
-       u8 *cache = codec->reg_cache;
-       int reg, i;
-
-       for (i = 0; i < TWL6040_VIOREGNUM; i++) {
-               reg = twl6040_vio_reg[i];
-               /*
-                * skip read-only registers (ASICID, ASICREV, STATUS)
-                * and registers shared among MFD children
-                */
-               switch (reg) {
-               case TWL6040_REG_ASICID:
-               case TWL6040_REG_ASICREV:
-               case TWL6040_REG_INTID:
-               case TWL6040_REG_INTMR:
-               case TWL6040_REG_NCPCTL:
-               case TWL6040_REG_LDOCTL:
-               case TWL6040_REG_GPOCTL:
-               case TWL6040_REG_ACCCTL:
-               case TWL6040_REG_STATUS:
-                       continue;
-               default:
-                       break;
-               }
-               twl6040_write(codec, reg, cache[reg]);
-       }
+       struct twl6040 *twl6040 = codec->control_data;
+       u8 val;
+
+       /* Update reg_cache: ASICREV, and TRIM values */
+       val = twl6040_get_revid(twl6040);
+       twl6040_write_reg_cache(codec, TWL6040_REG_ASICREV, val);
+
+       twl6040_read_reg_volatile(codec, TWL6040_REG_TRIM1);
+       twl6040_read_reg_volatile(codec, TWL6040_REG_TRIM2);
+       twl6040_read_reg_volatile(codec, TWL6040_REG_TRIM3);
+       twl6040_read_reg_volatile(codec, TWL6040_REG_HSOTRIM);
+       twl6040_read_reg_volatile(codec, TWL6040_REG_HFOTRIM);
+
+       /* Change chip defaults */
+       /* No imput selected for microphone amplifiers */
+       twl6040_write_reg_cache(codec, TWL6040_REG_MICLCTL, 0x18);
+       twl6040_write_reg_cache(codec, TWL6040_REG_MICRCTL, 0x18);
+
+       /*
+        * We need to lower the default gain values, so the ramp code
+        * can work correctly for the first playback.
+        * This reduces the pop noise heard at the first playback.
+        */
+       twl6040_write_reg_cache(codec, TWL6040_REG_HSGAIN, 0xff);
+       twl6040_write_reg_cache(codec, TWL6040_REG_EARCTL, 0x1e);
+       twl6040_write_reg_cache(codec, TWL6040_REG_HFLGAIN, 0x1d);
+       twl6040_write_reg_cache(codec, TWL6040_REG_HFRGAIN, 0x1d);
+       twl6040_write_reg_cache(codec, TWL6040_REG_LINEGAIN, 0);
 }
 
-static void twl6040_init_vdd_regs(struct snd_soc_codec *codec)
+static void twl6040_restore_regs(struct snd_soc_codec *codec)
 {
        u8 *cache = codec->reg_cache;
        int reg, i;
 
-       for (i = 0; i < TWL6040_VDDREGNUM; i++) {
-               reg = twl6040_vdd_reg[i];
-               /* skip vibra and PLL registers */
-               switch (reg) {
-               case TWL6040_REG_VIBCTLL:
-               case TWL6040_REG_VIBDATL:
-               case TWL6040_REG_VIBCTLR:
-               case TWL6040_REG_VIBDATR:
-               case TWL6040_REG_HPPLLCTL:
-               case TWL6040_REG_LPPLLCTL:
-               case TWL6040_REG_LPPLLDIV:
-                       continue;
-               default:
-                       break;
-               }
-
+       for (i = 0; i < ARRAY_SIZE(twl6040_restore_list); i++) {
+               reg = twl6040_restore_list[i];
                twl6040_write(codec, reg, cache[reg]);
        }
 }
@@ -524,18 +485,17 @@ static inline int twl6040_hf_ramp_step(struct snd_soc_codec *codec,
 static void twl6040_pga_hs_work(struct work_struct *work)
 {
        struct twl6040_data *priv =
-               container_of(work, struct twl6040_data, hs_delayed_work.work);
+               container_of(work, struct twl6040_data, headset.work.work);
        struct snd_soc_codec *codec = priv->codec;
        struct twl6040_output *headset = &priv->headset;
-       unsigned int delay = headset->step_delay;
        int i, headset_complete;
 
        /* do we need to ramp at all ? */
        if (headset->ramp == TWL6040_RAMP_NONE)
                return;
 
-       /* HS PGA volumes have 4 bits of resolution to ramp */
-       for (i = 0; i <= 16; i++) {
+       /* HS PGA gain range: 0x0 - 0xf (0 - 15) */
+       for (i = 0; i < 16; i++) {
                headset_complete = twl6040_hs_ramp_step(codec,
                                                headset->left_step,
                                                headset->right_step);
@@ -544,15 +504,8 @@ static void twl6040_pga_hs_work(struct work_struct *work)
                if (headset_complete)
                        break;
 
-               /*
-                * TODO: tune: delay is longer over 0dB
-                * as increases are larger.
-                */
-               if (i >= 8)
-                       schedule_timeout_interruptible(msecs_to_jiffies(delay +
-                                                       (delay >> 1)));
-               else
-                       schedule_timeout_interruptible(msecs_to_jiffies(delay));
+               schedule_timeout_interruptible(
+                               msecs_to_jiffies(headset->step_delay));
        }
 
        if (headset->ramp == TWL6040_RAMP_DOWN) {
@@ -567,18 +520,18 @@ static void twl6040_pga_hs_work(struct work_struct *work)
 static void twl6040_pga_hf_work(struct work_struct *work)
 {
        struct twl6040_data *priv =
-               container_of(work, struct twl6040_data, hf_delayed_work.work);
+               container_of(work, struct twl6040_data, handsfree.work.work);
        struct snd_soc_codec *codec = priv->codec;
        struct twl6040_output *handsfree = &priv->handsfree;
-       unsigned int delay = handsfree->step_delay;
        int i, handsfree_complete;
 
        /* do we need to ramp at all ? */
        if (handsfree->ramp == TWL6040_RAMP_NONE)
                return;
 
-       /* HF PGA volumes have 5 bits of resolution to ramp */
-       for (i = 0; i <= 32; i++) {
+       /*
+        * HF PGA gain range: 0x00 - 0x1d (0 - 29) */
+       for (i = 0; i < 30; i++) {
                handsfree_complete = twl6040_hf_ramp_step(codec,
                                                handsfree->left_step,
                                                handsfree->right_step);
@@ -587,15 +540,8 @@ static void twl6040_pga_hf_work(struct work_struct *work)
                if (handsfree_complete)
                        break;
 
-               /*
-                * TODO: tune: delay is longer over 0dB
-                * as increases are larger.
-                */
-               if (i >= 16)
-                       schedule_timeout_interruptible(msecs_to_jiffies(delay +
-                                                      (delay >> 1)));
-               else
-                       schedule_timeout_interruptible(msecs_to_jiffies(delay));
+               schedule_timeout_interruptible(
+                               msecs_to_jiffies(handsfree->step_delay));
        }
 
 
@@ -607,36 +553,40 @@ static void twl6040_pga_hf_work(struct work_struct *work)
        handsfree->ramp = TWL6040_RAMP_NONE;
 }
 
-static int pga_event(struct snd_soc_dapm_widget *w,
+static int out_drv_event(struct snd_soc_dapm_widget *w,
                        struct snd_kcontrol *kcontrol, int event)
 {
        struct snd_soc_codec *codec = w->codec;
        struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
        struct twl6040_output *out;
        struct delayed_work *work;
-       struct workqueue_struct *queue;
 
        switch (w->shift) {
-       case 2:
-       case 3:
+       case 2: /* Headset output driver */
                out = &priv->headset;
-               work = &priv->hs_delayed_work;
-               queue = priv->hs_workqueue;
+               work = &out->work;
+               /*
+                * Make sure, that we do not mess up variables for already
+                * executing work.
+                */
+               cancel_delayed_work_sync(work);
+
                out->left_step = priv->hs_left_step;
                out->right_step = priv->hs_right_step;
                out->step_delay = 5;    /* 5 ms between volume ramp steps */
                break;
-       case 4:
+       case 4: /* Handsfree output driver */
                out = &priv->handsfree;
-               work = &priv->hf_delayed_work;
-               queue = priv->hf_workqueue;
+               work = &out->work;
+               /*
+                * Make sure, that we do not mess up variables for already
+                * executing work.
+                */
+               cancel_delayed_work_sync(work);
+
                out->left_step = priv->hf_left_step;
                out->right_step = priv->hf_right_step;
                out->step_delay = 5;    /* 5 ms between volume ramp steps */
-               if (SND_SOC_DAPM_EVENT_ON(event))
-                       priv->non_lp++;
-               else
-                       priv->non_lp--;
                break;
        default:
                return -1;
@@ -648,31 +598,25 @@ static int pga_event(struct snd_soc_dapm_widget *w,
                        break;
 
                /* don't use volume ramp for power-up */
+               out->ramp = TWL6040_RAMP_UP;
                out->left_step = out->left_vol;
                out->right_step = out->right_vol;
 
-               if (!delayed_work_pending(work)) {
-                       out->ramp = TWL6040_RAMP_UP;
-                       queue_delayed_work(queue, work,
-                                       msecs_to_jiffies(1));
-               }
+               queue_delayed_work(priv->workqueue, work, msecs_to_jiffies(1));
                break;
 
        case SND_SOC_DAPM_PRE_PMD:
                if (!out->active)
                        break;
 
-               if (!delayed_work_pending(work)) {
-                       /* use volume ramp for power-down */
-                       out->ramp = TWL6040_RAMP_DOWN;
-                       INIT_COMPLETION(out->ramp_done);
+               /* use volume ramp for power-down */
+               out->ramp = TWL6040_RAMP_DOWN;
+               INIT_COMPLETION(out->ramp_done);
 
-                       queue_delayed_work(queue, work,
-                                       msecs_to_jiffies(1));
+               queue_delayed_work(priv->workqueue, work, msecs_to_jiffies(1));
 
-                       wait_for_completion_timeout(&out->ramp_done,
-                                       msecs_to_jiffies(2000));
-               }
+               wait_for_completion_timeout(&out->ramp_done,
+                                           msecs_to_jiffies(2000));
                break;
        }
 
@@ -683,7 +627,7 @@ static int pga_event(struct snd_soc_dapm_widget *w,
 static int headset_power_mode(struct snd_soc_codec *codec, int high_perf)
 {
        int hslctl, hsrctl;
-       int mask = TWL6040_HSDRVMODEL | TWL6040_HSDACMODEL;
+       int mask = TWL6040_HSDRVMODE | TWL6040_HSDACMODE;
 
        hslctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSLCTL);
        hsrctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSRCTL);
@@ -705,11 +649,31 @@ static int headset_power_mode(struct snd_soc_codec *codec, int high_perf)
 static int twl6040_hs_dac_event(struct snd_soc_dapm_widget *w,
                        struct snd_kcontrol *kcontrol, int event)
 {
+       struct snd_soc_codec *codec = w->codec;
+       u8 hslctl, hsrctl;
+
+       /*
+        * Workaround for Headset DC offset caused pop noise:
+        * Both HS DAC need to be turned on (before the HS driver) and off at
+        * the same time.
+        */
+       hslctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSLCTL);
+       hsrctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSRCTL);
+       if (SND_SOC_DAPM_EVENT_ON(event)) {
+               hslctl |= TWL6040_HSDACENA;
+               hsrctl |= TWL6040_HSDACENA;
+       } else {
+               hslctl &= ~TWL6040_HSDACENA;
+               hsrctl &= ~TWL6040_HSDACENA;
+       }
+       twl6040_write(codec, TWL6040_REG_HSLCTL, hslctl);
+       twl6040_write(codec, TWL6040_REG_HSRCTL, hsrctl);
+
        msleep(1);
        return 0;
 }
 
-static int twl6040_power_mode_event(struct snd_soc_dapm_widget *w,
+static int twl6040_ep_drv_event(struct snd_soc_dapm_widget *w,
                        struct snd_kcontrol *kcontrol, int event)
 {
        struct snd_soc_codec *codec = w->codec;
@@ -717,18 +681,12 @@ static int twl6040_power_mode_event(struct snd_soc_dapm_widget *w,
        int ret = 0;
 
        if (SND_SOC_DAPM_EVENT_ON(event)) {
-               priv->non_lp++;
-               if (!strcmp(w->name, "Earphone Driver")) {
-                       /* Earphone doesn't support low power mode */
-                       priv->hs_power_mode_locked = 1;
-                       ret = headset_power_mode(codec, 1);
-               }
+               /* Earphone doesn't support low power mode */
+               priv->hs_power_mode_locked = 1;
+               ret = headset_power_mode(codec, 1);
        } else {
-               priv->non_lp--;
-               if (!strcmp(w->name, "Earphone Driver")) {
-                       priv->hs_power_mode_locked = 0;
-                       ret = headset_power_mode(codec, priv->hs_power_mode);
-               }
+               priv->hs_power_mode_locked = 0;
+               ret = headset_power_mode(codec, priv->hs_power_mode);
        }
 
        msleep(1);
@@ -770,7 +728,7 @@ EXPORT_SYMBOL_GPL(twl6040_hs_jack_detect);
 static void twl6040_accessory_work(struct work_struct *work)
 {
        struct twl6040_data *priv = container_of(work,
-                                       struct twl6040_data, delayed_work.work);
+                                       struct twl6040_data, hs_jack.work.work);
        struct snd_soc_codec *codec = priv->codec;
        struct twl6040_jack_data *hs_jack = &priv->hs_jack;
 
@@ -781,15 +739,10 @@ static void twl6040_accessory_work(struct work_struct *work)
 static irqreturn_t twl6040_audio_handler(int irq, void *data)
 {
        struct snd_soc_codec *codec = data;
-       struct twl6040 *twl6040 = codec->control_data;
        struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
-       u8 intid;
-
-       intid = twl6040_reg_read(twl6040, TWL6040_REG_INTID);
 
-       if ((intid & TWL6040_PLUGINT) || (intid & TWL6040_UNPLUGINT))
-               queue_delayed_work(priv->workqueue, &priv->delayed_work,
-                                                       msecs_to_jiffies(200));
+       queue_delayed_work(priv->workqueue, &priv->hs_jack.work,
+                          msecs_to_jiffies(200));
 
        return IRQ_HANDLED;
 }
@@ -803,25 +756,27 @@ static int twl6040_put_volsw(struct snd_kcontrol *kcontrol,
        struct soc_mixer_control *mc =
                (struct soc_mixer_control *)kcontrol->private_value;
        int ret;
-       unsigned int reg = mc->reg;
 
        /* For HS and HF we shadow the values and only actually write
         * them out when active in order to ensure the amplifier comes on
         * as quietly as possible. */
-       switch (reg) {
+       switch (mc->reg) {
        case TWL6040_REG_HSGAIN:
                out = &twl6040_priv->headset;
                break;
-       default:
+       case TWL6040_REG_HFLGAIN:
+               out = &twl6040_priv->handsfree;
                break;
+       default:
+               dev_warn(codec->dev, "%s: Unexpected register: 0x%02x\n",
+                                       __func__, mc->reg);
+               return -EINVAL;
        }
 
-       if (out) {
-               out->left_vol = ucontrol->value.integer.value[0];
-               out->right_vol = ucontrol->value.integer.value[1];
-               if (!out->active)
-                       return 1;
-       }
+       out->left_vol = ucontrol->value.integer.value[0];
+       out->right_vol = ucontrol->value.integer.value[1];
+       if (!out->active)
+               return 1;
 
        ret = snd_soc_put_volsw(kcontrol, ucontrol);
        if (ret < 0)
@@ -838,112 +793,42 @@ static int twl6040_get_volsw(struct snd_kcontrol *kcontrol,
        struct twl6040_output *out = &twl6040_priv->headset;
        struct soc_mixer_control *mc =
                (struct soc_mixer_control *)kcontrol->private_value;
-       unsigned int reg = mc->reg;
 
-       switch (reg) {
+       switch (mc->reg) {
        case TWL6040_REG_HSGAIN:
                out = &twl6040_priv->headset;
-               ucontrol->value.integer.value[0] = out->left_vol;
-               ucontrol->value.integer.value[1] = out->right_vol;
-               return 0;
-
-       default:
                break;
-       }
-
-       return snd_soc_get_volsw(kcontrol, ucontrol);
-}
-
-static int twl6040_put_volsw_2r_vu(struct snd_kcontrol *kcontrol,
-                                 struct snd_ctl_elem_value *ucontrol)
-{
-       struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct twl6040_data *twl6040_priv = snd_soc_codec_get_drvdata(codec);
-       struct twl6040_output *out = NULL;
-       struct soc_mixer_control *mc =
-               (struct soc_mixer_control *)kcontrol->private_value;
-       int ret;
-       unsigned int reg = mc->reg;
-
-       /* For HS and HF we shadow the values and only actually write
-        * them out when active in order to ensure the amplifier comes on
-        * as quietly as possible. */
-       switch (reg) {
        case TWL6040_REG_HFLGAIN:
-       case TWL6040_REG_HFRGAIN:
                out = &twl6040_priv->handsfree;
                break;
        default:
-               break;
-       }
-
-       if (out) {
-               out->left_vol = ucontrol->value.integer.value[0];
-               out->right_vol = ucontrol->value.integer.value[1];
-               if (!out->active)
-                       return 1;
+               dev_warn(codec->dev, "%s: Unexpected register: 0x%02x\n",
+                                       __func__, mc->reg);
+               return -EINVAL;
        }
 
-       ret = snd_soc_put_volsw_2r(kcontrol, ucontrol);
-       if (ret < 0)
-               return ret;
-
-       return 1;
+       ucontrol->value.integer.value[0] = out->left_vol;
+       ucontrol->value.integer.value[1] = out->right_vol;
+       return 0;
 }
 
-static int twl6040_get_volsw_2r(struct snd_kcontrol *kcontrol,
-                               struct snd_ctl_elem_value *ucontrol)
+static int twl6040_soc_dapm_put_vibra_enum(struct snd_kcontrol *kcontrol,
+       struct snd_ctl_elem_value *ucontrol)
 {
-       struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct twl6040_data *twl6040_priv = snd_soc_codec_get_drvdata(codec);
-       struct twl6040_output *out = &twl6040_priv->handsfree;
-       struct soc_mixer_control *mc =
-               (struct soc_mixer_control *)kcontrol->private_value;
-       unsigned int reg = mc->reg;
-
-       /* If these are cached registers use the cache */
-       switch (reg) {
-       case TWL6040_REG_HFLGAIN:
-       case TWL6040_REG_HFRGAIN:
-               out = &twl6040_priv->handsfree;
-               ucontrol->value.integer.value[0] = out->left_vol;
-               ucontrol->value.integer.value[1] = out->right_vol;
-               return 0;
-
-       default:
-               break;
-       }
-
-       return snd_soc_get_volsw_2r(kcontrol, ucontrol);
+       struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
+       struct snd_soc_dapm_widget *widget = wlist->widgets[0];
+       struct snd_soc_codec *codec = widget->codec;
+       struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
+       unsigned int val;
+
+       /* Do not allow changes while Input/FF efect is running */
+       val = twl6040_read_reg_volatile(codec, e->reg);
+       if (val & TWL6040_VIBENA && !(val & TWL6040_VIBSEL))
+               return -EBUSY;
+
+       return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
 }
 
-/* double control with volume update */
-#define SOC_TWL6040_DOUBLE_TLV(xname, xreg, shift_left, shift_right, xmax,\
-                                                       xinvert, tlv_array)\
-{      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
-       .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
-                SNDRV_CTL_ELEM_ACCESS_READWRITE,\
-       .tlv.p = (tlv_array), \
-       .info = snd_soc_info_volsw, .get = twl6040_get_volsw, \
-       .put = twl6040_put_volsw, \
-       .private_value = (unsigned long)&(struct soc_mixer_control) \
-               {.reg = xreg, .shift = shift_left, .rshift = shift_right,\
-                .max = xmax, .platform_max = xmax, .invert = xinvert} }
-
-/* double control with volume update */
-#define SOC_TWL6040_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax,\
-                               xinvert, tlv_array)\
-{      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
-       .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
-               SNDRV_CTL_ELEM_ACCESS_READWRITE | \
-               SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
-       .tlv.p = (tlv_array), \
-       .info = snd_soc_info_volsw_2r, \
-       .get = twl6040_get_volsw_2r, .put = twl6040_put_volsw_2r_vu, \
-       .private_value = (unsigned long)&(struct soc_mixer_control) \
-               {.reg = reg_left, .rreg = reg_right, .shift = xshift, \
-                .rshift = xshift, .max = xmax, .invert = xinvert}, }
-
 /*
  * MICATT volume control:
  * from -6 to 0 dB in 6 dB steps
@@ -1015,6 +900,19 @@ static const struct soc_enum twl6040_hf_enum[] = {
                        twl6040_hf_texts),
 };
 
+static const char *twl6040_vibrapath_texts[] = {
+       "Input FF", "Audio PDM"
+};
+
+static const struct soc_enum twl6040_vibra_enum[] = {
+       SOC_ENUM_SINGLE(TWL6040_REG_VIBCTLL, 1,
+                       ARRAY_SIZE(twl6040_vibrapath_texts),
+                       twl6040_vibrapath_texts),
+       SOC_ENUM_SINGLE(TWL6040_REG_VIBCTLR, 1,
+                       ARRAY_SIZE(twl6040_vibrapath_texts),
+                       twl6040_vibrapath_texts),
+};
+
 static const struct snd_kcontrol_new amicl_control =
        SOC_DAPM_ENUM("Route", twl6040_enum[0]);
 
@@ -1035,8 +933,25 @@ static const struct snd_kcontrol_new hfl_mux_controls =
 static const struct snd_kcontrol_new hfr_mux_controls =
        SOC_DAPM_ENUM("Route", twl6040_hf_enum[1]);
 
-static const struct snd_kcontrol_new ep_driver_switch_controls =
-       SOC_DAPM_SINGLE("Switch", TWL6040_REG_EARCTL, 0, 1, 0);
+static const struct snd_kcontrol_new ep_path_enable_control =
+       SOC_DAPM_SINGLE("Switch", TWL6040_REG_SW_SHADOW, 0, 1, 0);
+
+static const struct snd_kcontrol_new auxl_switch_control =
+       SOC_DAPM_SINGLE("Switch", TWL6040_REG_HFLCTL, 6, 1, 0);
+
+static const struct snd_kcontrol_new auxr_switch_control =
+       SOC_DAPM_SINGLE("Switch", TWL6040_REG_HFRCTL, 6, 1, 0);
+
+/* Vibra playback switches */
+static const struct snd_kcontrol_new vibral_mux_controls =
+       SOC_DAPM_ENUM_EXT("Route", twl6040_vibra_enum[0],
+               snd_soc_dapm_get_enum_double,
+               twl6040_soc_dapm_put_vibra_enum);
+
+static const struct snd_kcontrol_new vibrar_mux_controls =
+       SOC_DAPM_ENUM_EXT("Route", twl6040_vibra_enum[1],
+               snd_soc_dapm_get_enum_double,
+               twl6040_soc_dapm_put_vibra_enum);
 
 /* Headset power mode */
 static const char *twl6040_power_mode_texts[] = {
@@ -1105,6 +1020,15 @@ int twl6040_get_clk_id(struct snd_soc_codec *codec)
 }
 EXPORT_SYMBOL_GPL(twl6040_get_clk_id);
 
+int twl6040_get_trim_value(struct snd_soc_codec *codec, enum twl6040_trim trim)
+{
+       if (unlikely(trim >= TWL6040_TRIM_INVAL))
+               return -EINVAL;
+
+       return twl6040_read_reg_cache(codec, TWL6040_REG_TRIM1 + trim);
+}
+EXPORT_SYMBOL_GPL(twl6040_get_trim_value);
+
 static const struct snd_kcontrol_new twl6040_snd_controls[] = {
        /* Capture gains */
        SOC_DOUBLE_TLV("Capture Preamplifier Volume",
@@ -1117,10 +1041,12 @@ static const struct snd_kcontrol_new twl6040_snd_controls[] = {
                TWL6040_REG_LINEGAIN, 0, 3, 7, 0, afm_amp_tlv),
 
        /* Playback gains */
-       SOC_TWL6040_DOUBLE_TLV("Headset Playback Volume",
-               TWL6040_REG_HSGAIN, 0, 4, 0xF, 1, hs_tlv),
-       SOC_TWL6040_DOUBLE_R_TLV("Handsfree Playback Volume",
-               TWL6040_REG_HFLGAIN, TWL6040_REG_HFRGAIN, 0, 0x1D, 1, hf_tlv),
+       SOC_DOUBLE_EXT_TLV("Headset Playback Volume",
+               TWL6040_REG_HSGAIN, 0, 4, 0xF, 1, twl6040_get_volsw,
+               twl6040_put_volsw, hs_tlv),
+       SOC_DOUBLE_R_EXT_TLV("Handsfree Playback Volume",
+               TWL6040_REG_HFLGAIN, TWL6040_REG_HFRGAIN, 0, 0x1D, 1,
+               twl6040_get_volsw, twl6040_put_volsw, hf_tlv),
        SOC_SINGLE_TLV("Earphone Playback Volume",
                TWL6040_REG_EARCTL, 1, 0xF, 1, ep_tlv),
 
@@ -1146,6 +1072,10 @@ static const struct snd_soc_dapm_widget twl6040_dapm_widgets[] = {
        SND_SOC_DAPM_OUTPUT("HFL"),
        SND_SOC_DAPM_OUTPUT("HFR"),
        SND_SOC_DAPM_OUTPUT("EP"),
+       SND_SOC_DAPM_OUTPUT("AUXL"),
+       SND_SOC_DAPM_OUTPUT("AUXR"),
+       SND_SOC_DAPM_OUTPUT("VIBRAL"),
+       SND_SOC_DAPM_OUTPUT("VIBRAR"),
 
        /* Analog input muxes for the capture amplifiers */
        SND_SOC_DAPM_MUX("Analog Left Capture Route",
@@ -1182,59 +1112,76 @@ static const struct snd_soc_dapm_widget twl6040_dapm_widgets[] = {
                        TWL6040_REG_DMICBCTL, 4, 0),
 
        /* DACs */
-       SND_SOC_DAPM_DAC_E("HSDAC Left", "Headset Playback",
-                       TWL6040_REG_HSLCTL, 0, 0,
-                       twl6040_hs_dac_event,
-                       SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
-       SND_SOC_DAPM_DAC_E("HSDAC Right", "Headset Playback",
-                       TWL6040_REG_HSRCTL, 0, 0,
-                       twl6040_hs_dac_event,
-                       SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
-       SND_SOC_DAPM_DAC_E("HFDAC Left", "Handsfree Playback",
-                       TWL6040_REG_HFLCTL, 0, 0,
-                       twl6040_power_mode_event,
-                       SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
-       SND_SOC_DAPM_DAC_E("HFDAC Right", "Handsfree Playback",
-                       TWL6040_REG_HFRCTL, 0, 0,
-                       twl6040_power_mode_event,
-                       SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
-
-       SND_SOC_DAPM_MUX("HF Left Playback",
+       SND_SOC_DAPM_DAC("HSDAC Left", "Headset Playback", SND_SOC_NOPM, 0, 0),
+       SND_SOC_DAPM_DAC("HSDAC Right", "Headset Playback", SND_SOC_NOPM, 0, 0),
+       SND_SOC_DAPM_DAC("HFDAC Left", "Handsfree Playback",
+                        TWL6040_REG_HFLCTL, 0, 0),
+       SND_SOC_DAPM_DAC("HFDAC Right", "Handsfree Playback",
+                        TWL6040_REG_HFRCTL, 0, 0),
+       /* Virtual DAC for vibra path (DL4 channel) */
+       SND_SOC_DAPM_DAC("VIBRA DAC", "Vibra Playback",
+                       SND_SOC_NOPM, 0, 0),
+
+       SND_SOC_DAPM_MUX("Handsfree Left Playback",
                        SND_SOC_NOPM, 0, 0, &hfl_mux_controls),
-       SND_SOC_DAPM_MUX("HF Right Playback",
+       SND_SOC_DAPM_MUX("Handsfree Right Playback",
                        SND_SOC_NOPM, 0, 0, &hfr_mux_controls),
        /* Analog playback Muxes */
-       SND_SOC_DAPM_MUX("HS Left Playback",
+       SND_SOC_DAPM_MUX("Headset Left Playback",
                        SND_SOC_NOPM, 0, 0, &hsl_mux_controls),
-       SND_SOC_DAPM_MUX("HS Right Playback",
+       SND_SOC_DAPM_MUX("Headset Right Playback",
                        SND_SOC_NOPM, 0, 0, &hsr_mux_controls),
 
+       SND_SOC_DAPM_MUX("Vibra Left Playback", SND_SOC_NOPM, 0, 0,
+                       &vibral_mux_controls),
+       SND_SOC_DAPM_MUX("Vibra Right Playback", SND_SOC_NOPM, 0, 0,
+                       &vibrar_mux_controls),
+
+       SND_SOC_DAPM_SWITCH("Earphone Playback", SND_SOC_NOPM, 0, 0,
+                       &ep_path_enable_control),
+       SND_SOC_DAPM_SWITCH("AUXL Playback", SND_SOC_NOPM, 0, 0,
+                       &auxl_switch_control),
+       SND_SOC_DAPM_SWITCH("AUXR Playback", SND_SOC_NOPM, 0, 0,
+                       &auxr_switch_control),
+
        /* Analog playback drivers */
-       SND_SOC_DAPM_OUT_DRV_E("Handsfree Left Driver",
+       SND_SOC_DAPM_OUT_DRV_E("HF Left Driver",
                        TWL6040_REG_HFLCTL, 4, 0, NULL, 0,
-                       pga_event,
+                       out_drv_event,
                        SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
-       SND_SOC_DAPM_OUT_DRV_E("Handsfree Right Driver",
+       SND_SOC_DAPM_OUT_DRV_E("HF Right Driver",
                        TWL6040_REG_HFRCTL, 4, 0, NULL, 0,
-                       pga_event,
+                       out_drv_event,
                        SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
-       SND_SOC_DAPM_OUT_DRV_E("Headset Left Driver",
+       SND_SOC_DAPM_OUT_DRV_E("HS Left Driver",
                        TWL6040_REG_HSLCTL, 2, 0, NULL, 0,
-                       pga_event,
+                       out_drv_event,
                        SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
-       SND_SOC_DAPM_OUT_DRV_E("Headset Right Driver",
+       SND_SOC_DAPM_OUT_DRV_E("HS Right Driver",
                        TWL6040_REG_HSRCTL, 2, 0, NULL, 0,
-                       pga_event,
+                       out_drv_event,
                        SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
-       SND_SOC_DAPM_SWITCH_E("Earphone Driver",
-                       SND_SOC_NOPM, 0, 0, &ep_driver_switch_controls,
-                       twl6040_power_mode_event,
-                       SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
+       SND_SOC_DAPM_OUT_DRV_E("Earphone Driver",
+                       TWL6040_REG_EARCTL, 0, 0, NULL, 0,
+                       twl6040_ep_drv_event,
+                       SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
+       SND_SOC_DAPM_OUT_DRV("Vibra Left Driver",
+                       TWL6040_REG_VIBCTLL, 0, 0, NULL, 0),
+       SND_SOC_DAPM_OUT_DRV("Vibra Right Driver",
+                       TWL6040_REG_VIBCTLR, 0, 0, NULL, 0),
+
+       SND_SOC_DAPM_SUPPLY("Vibra Left Control", TWL6040_REG_VIBCTLL, 2, 0,
+                           NULL, 0),
+       SND_SOC_DAPM_SUPPLY("Vibra Right Control", TWL6040_REG_VIBCTLR, 2, 0,
+                           NULL, 0),
+       SND_SOC_DAPM_SUPPLY_S("HSDAC Power", 1, SND_SOC_NOPM, 0, 0,
+                             twl6040_hs_dac_event,
+                             SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
 
        /* Analog playback PGAs */
-       SND_SOC_DAPM_PGA("HFDAC Left PGA",
+       SND_SOC_DAPM_PGA("HF Left PGA",
                        TWL6040_REG_HFLCTL, 1, 0, NULL, 0),
-       SND_SOC_DAPM_PGA("HFDAC Right PGA",
+       SND_SOC_DAPM_PGA("HF Right PGA",
                        TWL6040_REG_HFRCTL, 1, 0, NULL, 0),
 
 };
@@ -1256,52 +1203,62 @@ static const struct snd_soc_dapm_route intercon[] = {
        {"ADC Right", NULL, "MicAmpR"},
 
        /* AFM path */
-       {"AFMAmpL", "NULL", "AFML"},
-       {"AFMAmpR", "NULL", "AFMR"},
+       {"AFMAmpL", NULL, "AFML"},
+       {"AFMAmpR", NULL, "AFMR"},
+
+       {"HSDAC Left", NULL, "HSDAC Power"},
+       {"HSDAC Right", NULL, "HSDAC Power"},
 
-       {"HS Left Playback", "HS DAC", "HSDAC Left"},
-       {"HS Left Playback", "Line-In amp", "AFMAmpL"},
+       {"Headset Left Playback", "HS DAC", "HSDAC Left"},
+       {"Headset Left Playback", "Line-In amp", "AFMAmpL"},
 
-       {"HS Right Playback", "HS DAC", "HSDAC Right"},
-       {"HS Right Playback", "Line-In amp", "AFMAmpR"},
+       {"Headset Right Playback", "HS DAC", "HSDAC Right"},
+       {"Headset Right Playback", "Line-In amp", "AFMAmpR"},
 
-       {"Headset Left Driver", "NULL", "HS Left Playback"},
-       {"Headset Right Driver", "NULL", "HS Right Playback"},
+       {"HS Left Driver", NULL, "Headset Left Playback"},
+       {"HS Right Driver", NULL, "Headset Right Playback"},
 
-       {"HSOL", NULL, "Headset Left Driver"},
-       {"HSOR", NULL, "Headset Right Driver"},
+       {"HSOL", NULL, "HS Left Driver"},
+       {"HSOR", NULL, "HS Right Driver"},
 
        /* Earphone playback path */
-       {"Earphone Driver", "Switch", "HSDAC Left"},
+       {"Earphone Playback", "Switch", "HSDAC Left"},
+       {"Earphone Driver", NULL, "Earphone Playback"},
        {"EP", NULL, "Earphone Driver"},
 
-       {"HF Left Playback", "HF DAC", "HFDAC Left"},
-       {"HF Left Playback", "Line-In amp", "AFMAmpL"},
+       {"Handsfree Left Playback", "HF DAC", "HFDAC Left"},
+       {"Handsfree Left Playback", "Line-In amp", "AFMAmpL"},
 
-       {"HF Right Playback", "HF DAC", "HFDAC Right"},
-       {"HF Right Playback", "Line-In amp", "AFMAmpR"},
+       {"Handsfree Right Playback", "HF DAC", "HFDAC Right"},
+       {"Handsfree Right Playback", "Line-In amp", "AFMAmpR"},
 
-       {"HFDAC Left PGA", NULL, "HF Left Playback"},
-       {"HFDAC Right PGA", NULL, "HF Right Playback"},
+       {"HF Left PGA", NULL, "Handsfree Left Playback"},
+       {"HF Right PGA", NULL, "Handsfree Right Playback"},
 
-       {"Handsfree Left Driver", "Switch", "HFDAC Left PGA"},
-       {"Handsfree Right Driver", "Switch", "HFDAC Right PGA"},
+       {"HF Left Driver", NULL, "HF Left PGA"},
+       {"HF Right Driver", NULL, "HF Right PGA"},
 
-       {"HFL", NULL, "Handsfree Left Driver"},
-       {"HFR", NULL, "Handsfree Right Driver"},
-};
+       {"HFL", NULL, "HF Left Driver"},
+       {"HFR", NULL, "HF Right Driver"},
 
-static int twl6040_add_widgets(struct snd_soc_codec *codec)
-{
-       struct snd_soc_dapm_context *dapm = &codec->dapm;
+       {"AUXL Playback", "Switch", "HF Left PGA"},
+       {"AUXR Playback", "Switch", "HF Right PGA"},
 
-       snd_soc_dapm_new_controls(dapm, twl6040_dapm_widgets,
-                                ARRAY_SIZE(twl6040_dapm_widgets));
-       snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
-       snd_soc_dapm_new_widgets(dapm);
+       {"AUXL", NULL, "AUXL Playback"},
+       {"AUXR", NULL, "AUXR Playback"},
 
-       return 0;
-}
+       /* Vibrator paths */
+       {"Vibra Left Playback", "Audio PDM", "VIBRA DAC"},
+       {"Vibra Right Playback", "Audio PDM", "VIBRA DAC"},
+
+       {"Vibra Left Driver", NULL, "Vibra Left Playback"},
+       {"Vibra Right Driver", NULL, "Vibra Right Playback"},
+       {"Vibra Left Driver", NULL, "Vibra Left Control"},
+       {"Vibra Right Driver", NULL, "Vibra Right Control"},
+
+       {"VIBRAL", NULL, "Vibra Left Driver"},
+       {"VIBRAR", NULL, "Vibra Right Driver"},
+};
 
 static int twl6040_set_bias_level(struct snd_soc_codec *codec,
                                enum snd_soc_bias_level level)
@@ -1325,8 +1282,7 @@ static int twl6040_set_bias_level(struct snd_soc_codec *codec,
 
                priv->codec_powered = 1;
 
-               /* initialize vdd/vss registers with reg_cache */
-               twl6040_init_vdd_regs(codec);
+               twl6040_restore_regs(codec);
 
                /* Set external boost GPO */
                twl6040_write(codec, TWL6040_REG_GPOCTL, 0x02);
@@ -1380,13 +1336,6 @@ static int twl6040_hw_params(struct snd_pcm_substream *substream,
                                rate);
                        return -EINVAL;
                }
-               /* Capture is not supported with 17.64MHz sysclk */
-               if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
-                       dev_err(codec->dev,
-                               "capture mode is not supported at %dHz\n",
-                               rate);
-                       return -EINVAL;
-               }
                priv->sysclk = 17640000;
                break;
        case 8000:
@@ -1419,13 +1368,6 @@ static int twl6040_prepare(struct snd_pcm_substream *substream,
                return -EINVAL;
        }
 
-       if ((priv->sysclk == 17640000) && priv->non_lp) {
-                       dev_err(codec->dev,
-                               "some enabled paths aren't supported at %dHz\n",
-                               priv->sysclk);
-                       return -EPERM;
-       }
-
        ret = twl6040_set_pll(twl6040, priv->pll, priv->clk_in, priv->sysclk);
        if (ret) {
                dev_err(codec->dev, "Can not set PLL (%d)\n", ret);
@@ -1464,11 +1406,11 @@ static struct snd_soc_dai_ops twl6040_dai_ops = {
 
 static struct snd_soc_dai_driver twl6040_dai[] = {
 {
-       .name = "twl6040-hifi",
+       .name = "twl6040-legacy",
        .playback = {
                .stream_name = "Playback",
                .channels_min = 1,
-               .channels_max = 2,
+               .channels_max = 5,
                .rates = TWL6040_RATES,
                .formats = TWL6040_FORMATS,
        },
@@ -1518,8 +1460,8 @@ static struct snd_soc_dai_driver twl6040_dai[] = {
        .name = "twl6040-vib",
        .playback = {
                .stream_name = "Vibra Playback",
-               .channels_min = 2,
-               .channels_max = 2,
+               .channels_min = 1,
+               .channels_max = 1,
                .rates = SNDRV_PCM_RATE_CONTINUOUS,
                .formats = TWL6040_FORMATS,
        },
@@ -1562,6 +1504,7 @@ static int twl6040_probe(struct snd_soc_codec *codec)
 
        priv->codec = codec;
        codec->control_data = dev_get_drvdata(codec->dev->parent);
+       codec->ignore_pmdown_time = 1;
 
        if (pdata && pdata->hs_left_step && pdata->hs_right_step) {
                priv->hs_left_step = pdata->hs_left_step;
@@ -1586,33 +1529,21 @@ static int twl6040_probe(struct snd_soc_codec *codec)
                goto work_err;
        }
 
-       priv->workqueue = create_singlethread_workqueue("twl6040-codec");
+       priv->workqueue = alloc_workqueue("twl6040-codec", 0, 0);
        if (!priv->workqueue) {
                ret = -ENOMEM;
                goto work_err;
        }
 
-       INIT_DELAYED_WORK(&priv->delayed_work, twl6040_accessory_work);
+       INIT_DELAYED_WORK(&priv->hs_jack.work, twl6040_accessory_work);
+       INIT_DELAYED_WORK(&priv->headset.work, twl6040_pga_hs_work);
+       INIT_DELAYED_WORK(&priv->handsfree.work, twl6040_pga_hf_work);
 
        mutex_init(&priv->mutex);
 
        init_completion(&priv->headset.ramp_done);
        init_completion(&priv->handsfree.ramp_done);
 
-       priv->hf_workqueue = create_singlethread_workqueue("twl6040-hf");
-       if (priv->hf_workqueue == NULL) {
-               ret = -ENOMEM;
-               goto hfwq_err;
-       }
-       priv->hs_workqueue = create_singlethread_workqueue("twl6040-hs");
-       if (priv->hs_workqueue == NULL) {
-               ret = -ENOMEM;
-               goto hswq_err;
-       }
-
-       INIT_DELAYED_WORK(&priv->hs_delayed_work, twl6040_pga_hs_work);
-       INIT_DELAYED_WORK(&priv->hf_delayed_work, twl6040_pga_hf_work);
-
        ret = request_threaded_irq(priv->plug_irq, NULL, twl6040_audio_handler,
                                   0, "twl6040_irq_plug", codec);
        if (ret) {
@@ -1620,27 +1551,16 @@ static int twl6040_probe(struct snd_soc_codec *codec)
                goto plugirq_err;
        }
 
-       /* init vio registers */
-       twl6040_init_vio_regs(codec);
+       twl6040_init_chip(codec);
 
        /* power on device */
        ret = twl6040_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-       if (ret)
-               goto bias_err;
-
-       snd_soc_add_controls(codec, twl6040_snd_controls,
-                               ARRAY_SIZE(twl6040_snd_controls));
-       twl6040_add_widgets(codec);
-
-       return 0;
+       if (!ret)
+               return 0;
 
-bias_err:
+       /* Error path */
        free_irq(priv->plug_irq, codec);
 plugirq_err:
-       destroy_workqueue(priv->hs_workqueue);
-hswq_err:
-       destroy_workqueue(priv->hf_workqueue);
-hfwq_err:
        destroy_workqueue(priv->workqueue);
 work_err:
        kfree(priv);
@@ -1654,8 +1574,6 @@ static int twl6040_remove(struct snd_soc_codec *codec)
        twl6040_set_bias_level(codec, SND_SOC_BIAS_OFF);
        free_irq(priv->plug_irq, codec);
        destroy_workqueue(priv->workqueue);
-       destroy_workqueue(priv->hf_workqueue);
-       destroy_workqueue(priv->hs_workqueue);
        kfree(priv);
 
        return 0;
@@ -1672,6 +1590,13 @@ static struct snd_soc_codec_driver soc_codec_dev_twl6040 = {
        .reg_cache_size = ARRAY_SIZE(twl6040_reg),
        .reg_word_size = sizeof(u8),
        .reg_cache_default = twl6040_reg,
+
+       .controls = twl6040_snd_controls,
+       .num_controls = ARRAY_SIZE(twl6040_snd_controls),
+       .dapm_widgets = twl6040_dapm_widgets,
+       .num_dapm_widgets = ARRAY_SIZE(twl6040_dapm_widgets),
+       .dapm_routes = intercon,
+       .num_dapm_routes = ARRAY_SIZE(intercon),
 };
 
 static int __devinit twl6040_codec_probe(struct platform_device *pdev)
index d8de67869dd9340c31f040a755d8dae1d8591278..a83277bdb851129c5fb7a3db84e11e42d50dab0e 100644 (file)
 #ifndef __TWL6040_H__
 #define __TWL6040_H__
 
+enum twl6040_trim {
+       TWL6040_TRIM_TRIM1 = 0,
+       TWL6040_TRIM_TRIM2,
+       TWL6040_TRIM_TRIM3,
+       TWL6040_TRIM_HSOTRIM,
+       TWL6040_TRIM_HFOTRIM,
+       TWL6040_TRIM_INVAL,
+};
+
+#define TWL6040_HSF_TRIM_LEFT(x)       (x & 0x0f)
+#define TWL6040_HSF_TRIM_RIGHT(x)      ((x >> 4) & 0x0f)
+
 void twl6040_hs_jack_detect(struct snd_soc_codec *codec,
                            struct snd_soc_jack *jack, int report);
 int twl6040_get_clk_id(struct snd_soc_codec *codec);
+int twl6040_get_trim_value(struct snd_soc_codec *codec, enum twl6040_trim trim);
 
 #endif /* End of __TWL6040_H__ */
index 5836201834d97dcc769347ab98827841fce013ca..9fa14299cf2c1c4079fe5860f4b3ca793a3f4a1b 100644 (file)
@@ -462,7 +462,6 @@ static int wl1273_probe(struct snd_soc_codec *codec)
        wl1273->core = *core;
 
        snd_soc_codec_set_drvdata(codec, wl1273);
-       mutex_init(&codec->mutex);
 
        r = snd_soc_add_controls(codec, wl1273_controls,
                                 ARRAY_SIZE(wl1273_controls));
index bcc208967917f149956985e7c8f5c290a1506aad..cd0ec0fd1dbab536579b296884275cc14828326a 100644 (file)
 
 #include <linux/init.h>
 #include <linux/module.h>
+#include <linux/slab.h>
 #include <linux/i2c.h>
+#include <linux/gpio.h>
 
 #include <sound/soc.h>
 #include <sound/soc-dapm.h>
+#include <sound/wm1250-ev1.h>
+
+static const char *wm1250_gpio_names[WM1250_EV1_NUM_GPIOS] = {
+       "WM1250 CLK_ENA",
+       "WM1250 CLK_SEL0",
+       "WM1250 CLK_SEL1",
+       "WM1250 OSR",
+       "WM1250 MASTER",
+};
+
+struct wm1250_priv {
+       struct gpio gpios[WM1250_EV1_NUM_GPIOS];
+};
+
+static int wm1250_ev1_set_bias_level(struct snd_soc_codec *codec,
+                                    enum snd_soc_bias_level level)
+{
+       struct wm1250_priv *wm1250 = dev_get_drvdata(codec->dev);
+       int ena;
+
+       if (wm1250)
+               ena = wm1250->gpios[WM1250_EV1_GPIO_CLK_ENA].gpio;
+       else
+               ena = -1;
+
+       switch (level) {
+       case SND_SOC_BIAS_ON:
+               break;
+
+       case SND_SOC_BIAS_PREPARE:
+               break;
+
+       case SND_SOC_BIAS_STANDBY:
+               if (ena >= 0)
+                       gpio_set_value_cansleep(ena, 1);
+               break;
+
+       case SND_SOC_BIAS_OFF:
+               if (ena >= 0)
+                       gpio_set_value_cansleep(ena, 0);
+               break;
+       }
+
+       codec->dapm.bias_level = level;
+
+       return 0;
+}
 
 static const struct snd_soc_dapm_widget wm1250_ev1_dapm_widgets[] = {
 SND_SOC_DAPM_ADC("ADC", "wm1250-ev1 Capture", SND_SOC_NOPM, 0, 0),
@@ -53,18 +102,103 @@ static struct snd_soc_codec_driver soc_codec_dev_wm1250_ev1 = {
        .num_dapm_widgets = ARRAY_SIZE(wm1250_ev1_dapm_widgets),
        .dapm_routes = wm1250_ev1_dapm_routes,
        .num_dapm_routes = ARRAY_SIZE(wm1250_ev1_dapm_routes),
+
+       .set_bias_level = wm1250_ev1_set_bias_level,
+       .idle_bias_off = true,
 };
 
+static int __devinit wm1250_ev1_pdata(struct i2c_client *i2c)
+{
+       struct wm1250_ev1_pdata *pdata = dev_get_platdata(&i2c->dev);
+       struct wm1250_priv *wm1250;
+       int i, ret;
+
+       if (!pdata)
+               return 0;
+
+       wm1250 = kzalloc(sizeof(*wm1250), GFP_KERNEL);
+       if (!wm1250) {
+               dev_err(&i2c->dev, "Unable to allocate private data\n");
+               ret = -ENOMEM;
+               goto err;
+       }
+
+       for (i = 0; i < ARRAY_SIZE(wm1250->gpios); i++) {
+               wm1250->gpios[i].gpio = pdata->gpios[i];
+               wm1250->gpios[i].label = wm1250_gpio_names[i];
+               wm1250->gpios[i].flags = GPIOF_OUT_INIT_LOW;
+       }
+       wm1250->gpios[WM1250_EV1_GPIO_CLK_SEL0].flags = GPIOF_OUT_INIT_HIGH;
+       wm1250->gpios[WM1250_EV1_GPIO_CLK_SEL1].flags = GPIOF_OUT_INIT_HIGH;
+
+       ret = gpio_request_array(wm1250->gpios, ARRAY_SIZE(wm1250->gpios));
+       if (ret != 0) {
+               dev_err(&i2c->dev, "Failed to get GPIOs: %d\n", ret);
+               goto err_alloc;
+       }
+
+       dev_set_drvdata(&i2c->dev, wm1250);
+
+       return ret;
+
+err_alloc:
+       kfree(wm1250);
+err:
+       return ret;
+}
+
+static void wm1250_ev1_free(struct i2c_client *i2c)
+{
+       struct wm1250_priv *wm1250 = dev_get_drvdata(&i2c->dev);
+
+       if (wm1250) {
+               gpio_free_array(wm1250->gpios, ARRAY_SIZE(wm1250->gpios));
+               kfree(wm1250);
+       }
+}
+
 static int __devinit wm1250_ev1_probe(struct i2c_client *i2c,
-                                     const struct i2c_device_id *id)
+                                     const struct i2c_device_id *i2c_id)
 {
-       return snd_soc_register_codec(&i2c->dev, &soc_codec_dev_wm1250_ev1,
-                                     &wm1250_ev1_dai, 1);
+       int id, board, rev, ret;
+
+       dev_set_drvdata(&i2c->dev, NULL);
+
+       board = i2c_smbus_read_byte_data(i2c, 0);
+       if (board < 0) {
+               dev_err(&i2c->dev, "Failed to read ID: %d\n", board);
+               return board;
+       }
+
+       id = (board & 0xfe) >> 2;
+       rev = board & 0x3;
+
+       if (id != 1) {
+               dev_err(&i2c->dev, "Unknown board ID %d\n", id);
+               return -ENODEV;
+       }
+
+       dev_info(&i2c->dev, "revision %d\n", rev + 1);
+
+       ret = wm1250_ev1_pdata(i2c);
+       if (ret != 0)
+               return ret;
+
+       ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_wm1250_ev1,
+                                    &wm1250_ev1_dai, 1);
+       if (ret != 0) {
+               dev_err(&i2c->dev, "Failed to register CODEC: %d\n", ret);
+               wm1250_ev1_free(i2c);
+               return ret;
+       }
+
+       return 0;
 }
 
 static int __devexit wm1250_ev1_remove(struct i2c_client *i2c)
 {
        snd_soc_unregister_codec(&i2c->dev);
+       wm1250_ev1_free(i2c);
 
        return 0;
 }
diff --git a/sound/soc/codecs/wm5100-tables.c b/sound/soc/codecs/wm5100-tables.c
new file mode 100644 (file)
index 0000000..e9ce81a
--- /dev/null
@@ -0,0 +1,1531 @@
+/*
+ * wm5100-tables.c  --  WM5100 ALSA SoC Audio driver data
+ *
+ * Copyright 2011 Wolfson Microelectronics plc
+ *
+ * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include "wm5100.h"
+
+int wm5100_volatile_register(struct snd_soc_codec *codec, unsigned int reg)
+{
+       switch (reg) {
+       case WM5100_SOFTWARE_RESET:
+       case WM5100_DEVICE_REVISION:
+       case WM5100_FX_CTRL:
+       case WM5100_INTERRUPT_STATUS_1:
+       case WM5100_INTERRUPT_STATUS_2:
+       case WM5100_INTERRUPT_STATUS_3:
+       case WM5100_INTERRUPT_STATUS_4:
+       case WM5100_INTERRUPT_RAW_STATUS_2:
+       case WM5100_INTERRUPT_RAW_STATUS_3:
+       case WM5100_INTERRUPT_RAW_STATUS_4:
+       case WM5100_OUTPUT_STATUS_1:
+       case WM5100_OUTPUT_STATUS_2:
+       case WM5100_INPUT_ENABLES_STATUS:
+       case WM5100_MIC_DETECT_3:
+               return 1;
+       default:
+               return 0;
+       }
+}
+
+int wm5100_readable_register(struct snd_soc_codec *codec, unsigned int reg)
+{
+       switch (reg) {
+       case WM5100_SOFTWARE_RESET:
+       case WM5100_DEVICE_REVISION:
+       case WM5100_CTRL_IF_1:
+       case WM5100_TONE_GENERATOR_1:
+       case WM5100_PWM_DRIVE_1:
+       case WM5100_PWM_DRIVE_2:
+       case WM5100_PWM_DRIVE_3:
+       case WM5100_CLOCKING_1:
+       case WM5100_CLOCKING_3:
+       case WM5100_CLOCKING_4:
+       case WM5100_CLOCKING_5:
+       case WM5100_CLOCKING_6:
+       case WM5100_CLOCKING_7:
+       case WM5100_CLOCKING_8:
+       case WM5100_ASRC_ENABLE:
+       case WM5100_ASRC_STATUS:
+       case WM5100_ASRC_RATE1:
+       case WM5100_ISRC_1_CTRL_1:
+       case WM5100_ISRC_1_CTRL_2:
+       case WM5100_ISRC_2_CTRL1:
+       case WM5100_ISRC_2_CTRL_2:
+       case WM5100_FLL1_CONTROL_1:
+       case WM5100_FLL1_CONTROL_2:
+       case WM5100_FLL1_CONTROL_3:
+       case WM5100_FLL1_CONTROL_5:
+       case WM5100_FLL1_CONTROL_6:
+       case WM5100_FLL1_EFS_1:
+       case WM5100_FLL2_CONTROL_1:
+       case WM5100_FLL2_CONTROL_2:
+       case WM5100_FLL2_CONTROL_3:
+       case WM5100_FLL2_CONTROL_5:
+       case WM5100_FLL2_CONTROL_6:
+       case WM5100_FLL2_EFS_1:
+       case WM5100_MIC_CHARGE_PUMP_1:
+       case WM5100_MIC_CHARGE_PUMP_2:
+       case WM5100_HP_CHARGE_PUMP_1:
+       case WM5100_LDO1_CONTROL:
+       case WM5100_MIC_BIAS_CTRL_1:
+       case WM5100_MIC_BIAS_CTRL_2:
+       case WM5100_MIC_BIAS_CTRL_3:
+       case WM5100_ACCESSORY_DETECT_MODE_1:
+       case WM5100_HEADPHONE_DETECT_1:
+       case WM5100_HEADPHONE_DETECT_2:
+       case WM5100_MIC_DETECT_1:
+       case WM5100_MIC_DETECT_2:
+       case WM5100_MIC_DETECT_3:
+       case WM5100_INPUT_ENABLES:
+       case WM5100_INPUT_ENABLES_STATUS:
+       case WM5100_IN1L_CONTROL:
+       case WM5100_IN1R_CONTROL:
+       case WM5100_IN2L_CONTROL:
+       case WM5100_IN2R_CONTROL:
+       case WM5100_IN3L_CONTROL:
+       case WM5100_IN3R_CONTROL:
+       case WM5100_IN4L_CONTROL:
+       case WM5100_IN4R_CONTROL:
+       case WM5100_RXANC_SRC:
+       case WM5100_INPUT_VOLUME_RAMP:
+       case WM5100_ADC_DIGITAL_VOLUME_1L:
+       case WM5100_ADC_DIGITAL_VOLUME_1R:
+       case WM5100_ADC_DIGITAL_VOLUME_2L:
+       case WM5100_ADC_DIGITAL_VOLUME_2R:
+       case WM5100_ADC_DIGITAL_VOLUME_3L:
+       case WM5100_ADC_DIGITAL_VOLUME_3R:
+       case WM5100_ADC_DIGITAL_VOLUME_4L:
+       case WM5100_ADC_DIGITAL_VOLUME_4R:
+       case WM5100_OUTPUT_ENABLES_2:
+       case WM5100_OUTPUT_STATUS_1:
+       case WM5100_OUTPUT_STATUS_2:
+       case WM5100_CHANNEL_ENABLES_1:
+       case WM5100_OUT_VOLUME_1L:
+       case WM5100_OUT_VOLUME_1R:
+       case WM5100_DAC_VOLUME_LIMIT_1L:
+       case WM5100_DAC_VOLUME_LIMIT_1R:
+       case WM5100_OUT_VOLUME_2L:
+       case WM5100_OUT_VOLUME_2R:
+       case WM5100_DAC_VOLUME_LIMIT_2L:
+       case WM5100_DAC_VOLUME_LIMIT_2R:
+       case WM5100_OUT_VOLUME_3L:
+       case WM5100_OUT_VOLUME_3R:
+       case WM5100_DAC_VOLUME_LIMIT_3L:
+       case WM5100_DAC_VOLUME_LIMIT_3R:
+       case WM5100_OUT_VOLUME_4L:
+       case WM5100_OUT_VOLUME_4R:
+       case WM5100_DAC_VOLUME_LIMIT_5L:
+       case WM5100_DAC_VOLUME_LIMIT_5R:
+       case WM5100_DAC_VOLUME_LIMIT_6L:
+       case WM5100_DAC_VOLUME_LIMIT_6R:
+       case WM5100_DAC_AEC_CONTROL_1:
+       case WM5100_OUTPUT_VOLUME_RAMP:
+       case WM5100_DAC_DIGITAL_VOLUME_1L:
+       case WM5100_DAC_DIGITAL_VOLUME_1R:
+       case WM5100_DAC_DIGITAL_VOLUME_2L:
+       case WM5100_DAC_DIGITAL_VOLUME_2R:
+       case WM5100_DAC_DIGITAL_VOLUME_3L:
+       case WM5100_DAC_DIGITAL_VOLUME_3R:
+       case WM5100_DAC_DIGITAL_VOLUME_4L:
+       case WM5100_DAC_DIGITAL_VOLUME_4R:
+       case WM5100_DAC_DIGITAL_VOLUME_5L:
+       case WM5100_DAC_DIGITAL_VOLUME_5R:
+       case WM5100_DAC_DIGITAL_VOLUME_6L:
+       case WM5100_DAC_DIGITAL_VOLUME_6R:
+       case WM5100_PDM_SPK1_CTRL_1:
+       case WM5100_PDM_SPK1_CTRL_2:
+       case WM5100_PDM_SPK2_CTRL_1:
+       case WM5100_PDM_SPK2_CTRL_2:
+       case WM5100_AUDIO_IF_1_1:
+       case WM5100_AUDIO_IF_1_2:
+       case WM5100_AUDIO_IF_1_3:
+       case WM5100_AUDIO_IF_1_4:
+       case WM5100_AUDIO_IF_1_5:
+       case WM5100_AUDIO_IF_1_6:
+       case WM5100_AUDIO_IF_1_7:
+       case WM5100_AUDIO_IF_1_8:
+       case WM5100_AUDIO_IF_1_9:
+       case WM5100_AUDIO_IF_1_10:
+       case WM5100_AUDIO_IF_1_11:
+       case WM5100_AUDIO_IF_1_12:
+       case WM5100_AUDIO_IF_1_13:
+       case WM5100_AUDIO_IF_1_14:
+       case WM5100_AUDIO_IF_1_15:
+       case WM5100_AUDIO_IF_1_16:
+       case WM5100_AUDIO_IF_1_17:
+       case WM5100_AUDIO_IF_1_18:
+       case WM5100_AUDIO_IF_1_19:
+       case WM5100_AUDIO_IF_1_20:
+       case WM5100_AUDIO_IF_1_21:
+       case WM5100_AUDIO_IF_1_22:
+       case WM5100_AUDIO_IF_1_23:
+       case WM5100_AUDIO_IF_1_24:
+       case WM5100_AUDIO_IF_1_25:
+       case WM5100_AUDIO_IF_1_26:
+       case WM5100_AUDIO_IF_1_27:
+       case WM5100_AUDIO_IF_2_1:
+       case WM5100_AUDIO_IF_2_2:
+       case WM5100_AUDIO_IF_2_3:
+       case WM5100_AUDIO_IF_2_4:
+       case WM5100_AUDIO_IF_2_5:
+       case WM5100_AUDIO_IF_2_6:
+       case WM5100_AUDIO_IF_2_7:
+       case WM5100_AUDIO_IF_2_8:
+       case WM5100_AUDIO_IF_2_9:
+       case WM5100_AUDIO_IF_2_10:
+       case WM5100_AUDIO_IF_2_11:
+       case WM5100_AUDIO_IF_2_18:
+       case WM5100_AUDIO_IF_2_19:
+       case WM5100_AUDIO_IF_2_26:
+       case WM5100_AUDIO_IF_2_27:
+       case WM5100_AUDIO_IF_3_1:
+       case WM5100_AUDIO_IF_3_2:
+       case WM5100_AUDIO_IF_3_3:
+       case WM5100_AUDIO_IF_3_4:
+       case WM5100_AUDIO_IF_3_5:
+       case WM5100_AUDIO_IF_3_6:
+       case WM5100_AUDIO_IF_3_7:
+       case WM5100_AUDIO_IF_3_8:
+       case WM5100_AUDIO_IF_3_9:
+       case WM5100_AUDIO_IF_3_10:
+       case WM5100_AUDIO_IF_3_11:
+       case WM5100_AUDIO_IF_3_18:
+       case WM5100_AUDIO_IF_3_19:
+       case WM5100_AUDIO_IF_3_26:
+       case WM5100_AUDIO_IF_3_27:
+       case WM5100_PWM1MIX_INPUT_1_SOURCE:
+       case WM5100_PWM1MIX_INPUT_1_VOLUME:
+       case WM5100_PWM1MIX_INPUT_2_SOURCE:
+       case WM5100_PWM1MIX_INPUT_2_VOLUME:
+       case WM5100_PWM1MIX_INPUT_3_SOURCE:
+       case WM5100_PWM1MIX_INPUT_3_VOLUME:
+       case WM5100_PWM1MIX_INPUT_4_SOURCE:
+       case WM5100_PWM1MIX_INPUT_4_VOLUME:
+       case WM5100_PWM2MIX_INPUT_1_SOURCE:
+       case WM5100_PWM2MIX_INPUT_1_VOLUME:
+       case WM5100_PWM2MIX_INPUT_2_SOURCE:
+       case WM5100_PWM2MIX_INPUT_2_VOLUME:
+       case WM5100_PWM2MIX_INPUT_3_SOURCE:
+       case WM5100_PWM2MIX_INPUT_3_VOLUME:
+       case WM5100_PWM2MIX_INPUT_4_SOURCE:
+       case WM5100_PWM2MIX_INPUT_4_VOLUME:
+       case WM5100_OUT1LMIX_INPUT_1_SOURCE:
+       case WM5100_OUT1LMIX_INPUT_1_VOLUME:
+       case WM5100_OUT1LMIX_INPUT_2_SOURCE:
+       case WM5100_OUT1LMIX_INPUT_2_VOLUME:
+       case WM5100_OUT1LMIX_INPUT_3_SOURCE:
+       case WM5100_OUT1LMIX_INPUT_3_VOLUME:
+       case WM5100_OUT1LMIX_INPUT_4_SOURCE:
+       case WM5100_OUT1LMIX_INPUT_4_VOLUME:
+       case WM5100_OUT1RMIX_INPUT_1_SOURCE:
+       case WM5100_OUT1RMIX_INPUT_1_VOLUME:
+       case WM5100_OUT1RMIX_INPUT_2_SOURCE:
+       case WM5100_OUT1RMIX_INPUT_2_VOLUME:
+       case WM5100_OUT1RMIX_INPUT_3_SOURCE:
+       case WM5100_OUT1RMIX_INPUT_3_VOLUME:
+       case WM5100_OUT1RMIX_INPUT_4_SOURCE:
+       case WM5100_OUT1RMIX_INPUT_4_VOLUME:
+       case WM5100_OUT2LMIX_INPUT_1_SOURCE:
+       case WM5100_OUT2LMIX_INPUT_1_VOLUME:
+       case WM5100_OUT2LMIX_INPUT_2_SOURCE:
+       case WM5100_OUT2LMIX_INPUT_2_VOLUME:
+       case WM5100_OUT2LMIX_INPUT_3_SOURCE:
+       case WM5100_OUT2LMIX_INPUT_3_VOLUME:
+       case WM5100_OUT2LMIX_INPUT_4_SOURCE:
+       case WM5100_OUT2LMIX_INPUT_4_VOLUME:
+       case WM5100_OUT2RMIX_INPUT_1_SOURCE:
+       case WM5100_OUT2RMIX_INPUT_1_VOLUME:
+       case WM5100_OUT2RMIX_INPUT_2_SOURCE:
+       case WM5100_OUT2RMIX_INPUT_2_VOLUME:
+       case WM5100_OUT2RMIX_INPUT_3_SOURCE:
+       case WM5100_OUT2RMIX_INPUT_3_VOLUME:
+       case WM5100_OUT2RMIX_INPUT_4_SOURCE:
+       case WM5100_OUT2RMIX_INPUT_4_VOLUME:
+       case WM5100_OUT3LMIX_INPUT_1_SOURCE:
+       case WM5100_OUT3LMIX_INPUT_1_VOLUME:
+       case WM5100_OUT3LMIX_INPUT_2_SOURCE:
+       case WM5100_OUT3LMIX_INPUT_2_VOLUME:
+       case WM5100_OUT3LMIX_INPUT_3_SOURCE:
+       case WM5100_OUT3LMIX_INPUT_3_VOLUME:
+       case WM5100_OUT3LMIX_INPUT_4_SOURCE:
+       case WM5100_OUT3LMIX_INPUT_4_VOLUME:
+       case WM5100_OUT3RMIX_INPUT_1_SOURCE:
+       case WM5100_OUT3RMIX_INPUT_1_VOLUME:
+       case WM5100_OUT3RMIX_INPUT_2_SOURCE:
+       case WM5100_OUT3RMIX_INPUT_2_VOLUME:
+       case WM5100_OUT3RMIX_INPUT_3_SOURCE:
+       case WM5100_OUT3RMIX_INPUT_3_VOLUME:
+       case WM5100_OUT3RMIX_INPUT_4_SOURCE:
+       case WM5100_OUT3RMIX_INPUT_4_VOLUME:
+       case WM5100_OUT4LMIX_INPUT_1_SOURCE:
+       case WM5100_OUT4LMIX_INPUT_1_VOLUME:
+       case WM5100_OUT4LMIX_INPUT_2_SOURCE:
+       case WM5100_OUT4LMIX_INPUT_2_VOLUME:
+       case WM5100_OUT4LMIX_INPUT_3_SOURCE:
+       case WM5100_OUT4LMIX_INPUT_3_VOLUME:
+       case WM5100_OUT4LMIX_INPUT_4_SOURCE:
+       case WM5100_OUT4LMIX_INPUT_4_VOLUME:
+       case WM5100_OUT4RMIX_INPUT_1_SOURCE:
+       case WM5100_OUT4RMIX_INPUT_1_VOLUME:
+       case WM5100_OUT4RMIX_INPUT_2_SOURCE:
+       case WM5100_OUT4RMIX_INPUT_2_VOLUME:
+       case WM5100_OUT4RMIX_INPUT_3_SOURCE:
+       case WM5100_OUT4RMIX_INPUT_3_VOLUME:
+       case WM5100_OUT4RMIX_INPUT_4_SOURCE:
+       case WM5100_OUT4RMIX_INPUT_4_VOLUME:
+       case WM5100_OUT5LMIX_INPUT_1_SOURCE:
+       case WM5100_OUT5LMIX_INPUT_1_VOLUME:
+       case WM5100_OUT5LMIX_INPUT_2_SOURCE:
+       case WM5100_OUT5LMIX_INPUT_2_VOLUME:
+       case WM5100_OUT5LMIX_INPUT_3_SOURCE:
+       case WM5100_OUT5LMIX_INPUT_3_VOLUME:
+       case WM5100_OUT5LMIX_INPUT_4_SOURCE:
+       case WM5100_OUT5LMIX_INPUT_4_VOLUME:
+       case WM5100_OUT5RMIX_INPUT_1_SOURCE:
+       case WM5100_OUT5RMIX_INPUT_1_VOLUME:
+       case WM5100_OUT5RMIX_INPUT_2_SOURCE:
+       case WM5100_OUT5RMIX_INPUT_2_VOLUME:
+       case WM5100_OUT5RMIX_INPUT_3_SOURCE:
+       case WM5100_OUT5RMIX_INPUT_3_VOLUME:
+       case WM5100_OUT5RMIX_INPUT_4_SOURCE:
+       case WM5100_OUT5RMIX_INPUT_4_VOLUME:
+       case WM5100_OUT6LMIX_INPUT_1_SOURCE:
+       case WM5100_OUT6LMIX_INPUT_1_VOLUME:
+       case WM5100_OUT6LMIX_INPUT_2_SOURCE:
+       case WM5100_OUT6LMIX_INPUT_2_VOLUME:
+       case WM5100_OUT6LMIX_INPUT_3_SOURCE:
+       case WM5100_OUT6LMIX_INPUT_3_VOLUME:
+       case WM5100_OUT6LMIX_INPUT_4_SOURCE:
+       case WM5100_OUT6LMIX_INPUT_4_VOLUME:
+       case WM5100_OUT6RMIX_INPUT_1_SOURCE:
+       case WM5100_OUT6RMIX_INPUT_1_VOLUME:
+       case WM5100_OUT6RMIX_INPUT_2_SOURCE:
+       case WM5100_OUT6RMIX_INPUT_2_VOLUME:
+       case WM5100_OUT6RMIX_INPUT_3_SOURCE:
+       case WM5100_OUT6RMIX_INPUT_3_VOLUME:
+       case WM5100_OUT6RMIX_INPUT_4_SOURCE:
+       case WM5100_OUT6RMIX_INPUT_4_VOLUME:
+       case WM5100_AIF1TX1MIX_INPUT_1_SOURCE:
+       case WM5100_AIF1TX1MIX_INPUT_1_VOLUME:
+       case WM5100_AIF1TX1MIX_INPUT_2_SOURCE:
+       case WM5100_AIF1TX1MIX_INPUT_2_VOLUME:
+       case WM5100_AIF1TX1MIX_INPUT_3_SOURCE:
+       case WM5100_AIF1TX1MIX_INPUT_3_VOLUME:
+       case WM5100_AIF1TX1MIX_INPUT_4_SOURCE:
+       case WM5100_AIF1TX1MIX_INPUT_4_VOLUME:
+       case WM5100_AIF1TX2MIX_INPUT_1_SOURCE:
+       case WM5100_AIF1TX2MIX_INPUT_1_VOLUME:
+       case WM5100_AIF1TX2MIX_INPUT_2_SOURCE:
+       case WM5100_AIF1TX2MIX_INPUT_2_VOLUME:
+       case WM5100_AIF1TX2MIX_INPUT_3_SOURCE:
+       case WM5100_AIF1TX2MIX_INPUT_3_VOLUME:
+       case WM5100_AIF1TX2MIX_INPUT_4_SOURCE:
+       case WM5100_AIF1TX2MIX_INPUT_4_VOLUME:
+       case WM5100_AIF1TX3MIX_INPUT_1_SOURCE:
+       case WM5100_AIF1TX3MIX_INPUT_1_VOLUME:
+       case WM5100_AIF1TX3MIX_INPUT_2_SOURCE:
+       case WM5100_AIF1TX3MIX_INPUT_2_VOLUME:
+       case WM5100_AIF1TX3MIX_INPUT_3_SOURCE:
+       case WM5100_AIF1TX3MIX_INPUT_3_VOLUME:
+       case WM5100_AIF1TX3MIX_INPUT_4_SOURCE:
+       case WM5100_AIF1TX3MIX_INPUT_4_VOLUME:
+       case WM5100_AIF1TX4MIX_INPUT_1_SOURCE:
+       case WM5100_AIF1TX4MIX_INPUT_1_VOLUME:
+       case WM5100_AIF1TX4MIX_INPUT_2_SOURCE:
+       case WM5100_AIF1TX4MIX_INPUT_2_VOLUME:
+       case WM5100_AIF1TX4MIX_INPUT_3_SOURCE:
+       case WM5100_AIF1TX4MIX_INPUT_3_VOLUME:
+       case WM5100_AIF1TX4MIX_INPUT_4_SOURCE:
+       case WM5100_AIF1TX4MIX_INPUT_4_VOLUME:
+       case WM5100_AIF1TX5MIX_INPUT_1_SOURCE:
+       case WM5100_AIF1TX5MIX_INPUT_1_VOLUME:
+       case WM5100_AIF1TX5MIX_INPUT_2_SOURCE:
+       case WM5100_AIF1TX5MIX_INPUT_2_VOLUME:
+       case WM5100_AIF1TX5MIX_INPUT_3_SOURCE:
+       case WM5100_AIF1TX5MIX_INPUT_3_VOLUME:
+       case WM5100_AIF1TX5MIX_INPUT_4_SOURCE:
+       case WM5100_AIF1TX5MIX_INPUT_4_VOLUME:
+       case WM5100_AIF1TX6MIX_INPUT_1_SOURCE:
+       case WM5100_AIF1TX6MIX_INPUT_1_VOLUME:
+       case WM5100_AIF1TX6MIX_INPUT_2_SOURCE:
+       case WM5100_AIF1TX6MIX_INPUT_2_VOLUME:
+       case WM5100_AIF1TX6MIX_INPUT_3_SOURCE:
+       case WM5100_AIF1TX6MIX_INPUT_3_VOLUME:
+       case WM5100_AIF1TX6MIX_INPUT_4_SOURCE:
+       case WM5100_AIF1TX6MIX_INPUT_4_VOLUME:
+       case WM5100_AIF1TX7MIX_INPUT_1_SOURCE:
+       case WM5100_AIF1TX7MIX_INPUT_1_VOLUME:
+       case WM5100_AIF1TX7MIX_INPUT_2_SOURCE:
+       case WM5100_AIF1TX7MIX_INPUT_2_VOLUME:
+       case WM5100_AIF1TX7MIX_INPUT_3_SOURCE:
+       case WM5100_AIF1TX7MIX_INPUT_3_VOLUME:
+       case WM5100_AIF1TX7MIX_INPUT_4_SOURCE:
+       case WM5100_AIF1TX7MIX_INPUT_4_VOLUME:
+       case WM5100_AIF1TX8MIX_INPUT_1_SOURCE:
+       case WM5100_AIF1TX8MIX_INPUT_1_VOLUME:
+       case WM5100_AIF1TX8MIX_INPUT_2_SOURCE:
+       case WM5100_AIF1TX8MIX_INPUT_2_VOLUME:
+       case WM5100_AIF1TX8MIX_INPUT_3_SOURCE:
+       case WM5100_AIF1TX8MIX_INPUT_3_VOLUME:
+       case WM5100_AIF1TX8MIX_INPUT_4_SOURCE:
+       case WM5100_AIF1TX8MIX_INPUT_4_VOLUME:
+       case WM5100_AIF2TX1MIX_INPUT_1_SOURCE:
+       case WM5100_AIF2TX1MIX_INPUT_1_VOLUME:
+       case WM5100_AIF2TX1MIX_INPUT_2_SOURCE:
+       case WM5100_AIF2TX1MIX_INPUT_2_VOLUME:
+       case WM5100_AIF2TX1MIX_INPUT_3_SOURCE:
+       case WM5100_AIF2TX1MIX_INPUT_3_VOLUME:
+       case WM5100_AIF2TX1MIX_INPUT_4_SOURCE:
+       case WM5100_AIF2TX1MIX_INPUT_4_VOLUME:
+       case WM5100_AIF2TX2MIX_INPUT_1_SOURCE:
+       case WM5100_AIF2TX2MIX_INPUT_1_VOLUME:
+       case WM5100_AIF2TX2MIX_INPUT_2_SOURCE:
+       case WM5100_AIF2TX2MIX_INPUT_2_VOLUME:
+       case WM5100_AIF2TX2MIX_INPUT_3_SOURCE:
+       case WM5100_AIF2TX2MIX_INPUT_3_VOLUME:
+       case WM5100_AIF2TX2MIX_INPUT_4_SOURCE:
+       case WM5100_AIF2TX2MIX_INPUT_4_VOLUME:
+       case WM5100_AIF3TX1MIX_INPUT_1_SOURCE:
+       case WM5100_AIF3TX1MIX_INPUT_1_VOLUME:
+       case WM5100_AIF3TX1MIX_INPUT_2_SOURCE:
+       case WM5100_AIF3TX1MIX_INPUT_2_VOLUME:
+       case WM5100_AIF3TX1MIX_INPUT_3_SOURCE:
+       case WM5100_AIF3TX1MIX_INPUT_3_VOLUME:
+       case WM5100_AIF3TX1MIX_INPUT_4_SOURCE:
+       case WM5100_AIF3TX1MIX_INPUT_4_VOLUME:
+       case WM5100_AIF3TX2MIX_INPUT_1_SOURCE:
+       case WM5100_AIF3TX2MIX_INPUT_1_VOLUME:
+       case WM5100_AIF3TX2MIX_INPUT_2_SOURCE:
+       case WM5100_AIF3TX2MIX_INPUT_2_VOLUME:
+       case WM5100_AIF3TX2MIX_INPUT_3_SOURCE:
+       case WM5100_AIF3TX2MIX_INPUT_3_VOLUME:
+       case WM5100_AIF3TX2MIX_INPUT_4_SOURCE:
+       case WM5100_AIF3TX2MIX_INPUT_4_VOLUME:
+       case WM5100_EQ1MIX_INPUT_1_SOURCE:
+       case WM5100_EQ1MIX_INPUT_1_VOLUME:
+       case WM5100_EQ1MIX_INPUT_2_SOURCE:
+       case WM5100_EQ1MIX_INPUT_2_VOLUME:
+       case WM5100_EQ1MIX_INPUT_3_SOURCE:
+       case WM5100_EQ1MIX_INPUT_3_VOLUME:
+       case WM5100_EQ1MIX_INPUT_4_SOURCE:
+       case WM5100_EQ1MIX_INPUT_4_VOLUME:
+       case WM5100_EQ2MIX_INPUT_1_SOURCE:
+       case WM5100_EQ2MIX_INPUT_1_VOLUME:
+       case WM5100_EQ2MIX_INPUT_2_SOURCE:
+       case WM5100_EQ2MIX_INPUT_2_VOLUME:
+       case WM5100_EQ2MIX_INPUT_3_SOURCE:
+       case WM5100_EQ2MIX_INPUT_3_VOLUME:
+       case WM5100_EQ2MIX_INPUT_4_SOURCE:
+       case WM5100_EQ2MIX_INPUT_4_VOLUME:
+       case WM5100_EQ3MIX_INPUT_1_SOURCE:
+       case WM5100_EQ3MIX_INPUT_1_VOLUME:
+       case WM5100_EQ3MIX_INPUT_2_SOURCE:
+       case WM5100_EQ3MIX_INPUT_2_VOLUME:
+       case WM5100_EQ3MIX_INPUT_3_SOURCE:
+       case WM5100_EQ3MIX_INPUT_3_VOLUME:
+       case WM5100_EQ3MIX_INPUT_4_SOURCE:
+       case WM5100_EQ3MIX_INPUT_4_VOLUME:
+       case WM5100_EQ4MIX_INPUT_1_SOURCE:
+       case WM5100_EQ4MIX_INPUT_1_VOLUME:
+       case WM5100_EQ4MIX_INPUT_2_SOURCE:
+       case WM5100_EQ4MIX_INPUT_2_VOLUME:
+       case WM5100_EQ4MIX_INPUT_3_SOURCE:
+       case WM5100_EQ4MIX_INPUT_3_VOLUME:
+       case WM5100_EQ4MIX_INPUT_4_SOURCE:
+       case WM5100_EQ4MIX_INPUT_4_VOLUME:
+       case WM5100_DRC1LMIX_INPUT_1_SOURCE:
+       case WM5100_DRC1LMIX_INPUT_1_VOLUME:
+       case WM5100_DRC1LMIX_INPUT_2_SOURCE:
+       case WM5100_DRC1LMIX_INPUT_2_VOLUME:
+       case WM5100_DRC1LMIX_INPUT_3_SOURCE:
+       case WM5100_DRC1LMIX_INPUT_3_VOLUME:
+       case WM5100_DRC1LMIX_INPUT_4_SOURCE:
+       case WM5100_DRC1LMIX_INPUT_4_VOLUME:
+       case WM5100_DRC1RMIX_INPUT_1_SOURCE:
+       case WM5100_DRC1RMIX_INPUT_1_VOLUME:
+       case WM5100_DRC1RMIX_INPUT_2_SOURCE:
+       case WM5100_DRC1RMIX_INPUT_2_VOLUME:
+       case WM5100_DRC1RMIX_INPUT_3_SOURCE:
+       case WM5100_DRC1RMIX_INPUT_3_VOLUME:
+       case WM5100_DRC1RMIX_INPUT_4_SOURCE:
+       case WM5100_DRC1RMIX_INPUT_4_VOLUME:
+       case WM5100_HPLP1MIX_INPUT_1_SOURCE:
+       case WM5100_HPLP1MIX_INPUT_1_VOLUME:
+       case WM5100_HPLP1MIX_INPUT_2_SOURCE:
+       case WM5100_HPLP1MIX_INPUT_2_VOLUME:
+       case WM5100_HPLP1MIX_INPUT_3_SOURCE:
+       case WM5100_HPLP1MIX_INPUT_3_VOLUME:
+       case WM5100_HPLP1MIX_INPUT_4_SOURCE:
+       case WM5100_HPLP1MIX_INPUT_4_VOLUME:
+       case WM5100_HPLP2MIX_INPUT_1_SOURCE:
+       case WM5100_HPLP2MIX_INPUT_1_VOLUME:
+       case WM5100_HPLP2MIX_INPUT_2_SOURCE:
+       case WM5100_HPLP2MIX_INPUT_2_VOLUME:
+       case WM5100_HPLP2MIX_INPUT_3_SOURCE:
+       case WM5100_HPLP2MIX_INPUT_3_VOLUME:
+       case WM5100_HPLP2MIX_INPUT_4_SOURCE:
+       case WM5100_HPLP2MIX_INPUT_4_VOLUME:
+       case WM5100_HPLP3MIX_INPUT_1_SOURCE:
+       case WM5100_HPLP3MIX_INPUT_1_VOLUME:
+       case WM5100_HPLP3MIX_INPUT_2_SOURCE:
+       case WM5100_HPLP3MIX_INPUT_2_VOLUME:
+       case WM5100_HPLP3MIX_INPUT_3_SOURCE:
+       case WM5100_HPLP3MIX_INPUT_3_VOLUME:
+       case WM5100_HPLP3MIX_INPUT_4_SOURCE:
+       case WM5100_HPLP3MIX_INPUT_4_VOLUME:
+       case WM5100_HPLP4MIX_INPUT_1_SOURCE:
+       case WM5100_HPLP4MIX_INPUT_1_VOLUME:
+       case WM5100_HPLP4MIX_INPUT_2_SOURCE:
+       case WM5100_HPLP4MIX_INPUT_2_VOLUME:
+       case WM5100_HPLP4MIX_INPUT_3_SOURCE:
+       case WM5100_HPLP4MIX_INPUT_3_VOLUME:
+       case WM5100_HPLP4MIX_INPUT_4_SOURCE:
+       case WM5100_HPLP4MIX_INPUT_4_VOLUME:
+       case WM5100_DSP1LMIX_INPUT_1_SOURCE:
+       case WM5100_DSP1LMIX_INPUT_1_VOLUME:
+       case WM5100_DSP1LMIX_INPUT_2_SOURCE:
+       case WM5100_DSP1LMIX_INPUT_2_VOLUME:
+       case WM5100_DSP1LMIX_INPUT_3_SOURCE:
+       case WM5100_DSP1LMIX_INPUT_3_VOLUME:
+       case WM5100_DSP1LMIX_INPUT_4_SOURCE:
+       case WM5100_DSP1LMIX_INPUT_4_VOLUME:
+       case WM5100_DSP1RMIX_INPUT_1_SOURCE:
+       case WM5100_DSP1RMIX_INPUT_1_VOLUME:
+       case WM5100_DSP1RMIX_INPUT_2_SOURCE:
+       case WM5100_DSP1RMIX_INPUT_2_VOLUME:
+       case WM5100_DSP1RMIX_INPUT_3_SOURCE:
+       case WM5100_DSP1RMIX_INPUT_3_VOLUME:
+       case WM5100_DSP1RMIX_INPUT_4_SOURCE:
+       case WM5100_DSP1RMIX_INPUT_4_VOLUME:
+       case WM5100_DSP1AUX1MIX_INPUT_1_SOURCE:
+       case WM5100_DSP1AUX2MIX_INPUT_1_SOURCE:
+       case WM5100_DSP1AUX3MIX_INPUT_1_SOURCE:
+       case WM5100_DSP1AUX4MIX_INPUT_1_SOURCE:
+       case WM5100_DSP1AUX5MIX_INPUT_1_SOURCE:
+       case WM5100_DSP1AUX6MIX_INPUT_1_SOURCE:
+       case WM5100_DSP2LMIX_INPUT_1_SOURCE:
+       case WM5100_DSP2LMIX_INPUT_1_VOLUME:
+       case WM5100_DSP2LMIX_INPUT_2_SOURCE:
+       case WM5100_DSP2LMIX_INPUT_2_VOLUME:
+       case WM5100_DSP2LMIX_INPUT_3_SOURCE:
+       case WM5100_DSP2LMIX_INPUT_3_VOLUME:
+       case WM5100_DSP2LMIX_INPUT_4_SOURCE:
+       case WM5100_DSP2LMIX_INPUT_4_VOLUME:
+       case WM5100_DSP2RMIX_INPUT_1_SOURCE:
+       case WM5100_DSP2RMIX_INPUT_1_VOLUME:
+       case WM5100_DSP2RMIX_INPUT_2_SOURCE:
+       case WM5100_DSP2RMIX_INPUT_2_VOLUME:
+       case WM5100_DSP2RMIX_INPUT_3_SOURCE:
+       case WM5100_DSP2RMIX_INPUT_3_VOLUME:
+       case WM5100_DSP2RMIX_INPUT_4_SOURCE:
+       case WM5100_DSP2RMIX_INPUT_4_VOLUME:
+       case WM5100_DSP2AUX1MIX_INPUT_1_SOURCE:
+       case WM5100_DSP2AUX2MIX_INPUT_1_SOURCE:
+       case WM5100_DSP2AUX3MIX_INPUT_1_SOURCE:
+       case WM5100_DSP2AUX4MIX_INPUT_1_SOURCE:
+       case WM5100_DSP2AUX5MIX_INPUT_1_SOURCE:
+       case WM5100_DSP2AUX6MIX_INPUT_1_SOURCE:
+       case WM5100_DSP3LMIX_INPUT_1_SOURCE:
+       case WM5100_DSP3LMIX_INPUT_1_VOLUME:
+       case WM5100_DSP3LMIX_INPUT_2_SOURCE:
+       case WM5100_DSP3LMIX_INPUT_2_VOLUME:
+       case WM5100_DSP3LMIX_INPUT_3_SOURCE:
+       case WM5100_DSP3LMIX_INPUT_3_VOLUME:
+       case WM5100_DSP3LMIX_INPUT_4_SOURCE:
+       case WM5100_DSP3LMIX_INPUT_4_VOLUME:
+       case WM5100_DSP3RMIX_INPUT_1_SOURCE:
+       case WM5100_DSP3RMIX_INPUT_1_VOLUME:
+       case WM5100_DSP3RMIX_INPUT_2_SOURCE:
+       case WM5100_DSP3RMIX_INPUT_2_VOLUME:
+       case WM5100_DSP3RMIX_INPUT_3_SOURCE:
+       case WM5100_DSP3RMIX_INPUT_3_VOLUME:
+       case WM5100_DSP3RMIX_INPUT_4_SOURCE:
+       case WM5100_DSP3RMIX_INPUT_4_VOLUME:
+       case WM5100_DSP3AUX1MIX_INPUT_1_SOURCE:
+       case WM5100_DSP3AUX2MIX_INPUT_1_SOURCE:
+       case WM5100_DSP3AUX3MIX_INPUT_1_SOURCE:
+       case WM5100_DSP3AUX4MIX_INPUT_1_SOURCE:
+       case WM5100_DSP3AUX5MIX_INPUT_1_SOURCE:
+       case WM5100_DSP3AUX6MIX_INPUT_1_SOURCE:
+       case WM5100_ASRC1LMIX_INPUT_1_SOURCE:
+       case WM5100_ASRC1RMIX_INPUT_1_SOURCE:
+       case WM5100_ASRC2LMIX_INPUT_1_SOURCE:
+       case WM5100_ASRC2RMIX_INPUT_1_SOURCE:
+       case WM5100_ISRC1DEC1MIX_INPUT_1_SOURCE:
+       case WM5100_ISRC1DEC2MIX_INPUT_1_SOURCE:
+       case WM5100_ISRC1DEC3MIX_INPUT_1_SOURCE:
+       case WM5100_ISRC1DEC4MIX_INPUT_1_SOURCE:
+       case WM5100_ISRC1INT1MIX_INPUT_1_SOURCE:
+       case WM5100_ISRC1INT2MIX_INPUT_1_SOURCE:
+       case WM5100_ISRC1INT3MIX_INPUT_1_SOURCE:
+       case WM5100_ISRC1INT4MIX_INPUT_1_SOURCE:
+       case WM5100_ISRC2DEC1MIX_INPUT_1_SOURCE:
+       case WM5100_ISRC2DEC2MIX_INPUT_1_SOURCE:
+       case WM5100_ISRC2DEC3MIX_INPUT_1_SOURCE:
+       case WM5100_ISRC2DEC4MIX_INPUT_1_SOURCE:
+       case WM5100_ISRC2INT1MIX_INPUT_1_SOURCE:
+       case WM5100_ISRC2INT2MIX_INPUT_1_SOURCE:
+       case WM5100_ISRC2INT3MIX_INPUT_1_SOURCE:
+       case WM5100_ISRC2INT4MIX_INPUT_1_SOURCE:
+       case WM5100_GPIO_CTRL_1:
+       case WM5100_GPIO_CTRL_2:
+       case WM5100_GPIO_CTRL_3:
+       case WM5100_GPIO_CTRL_4:
+       case WM5100_GPIO_CTRL_5:
+       case WM5100_GPIO_CTRL_6:
+       case WM5100_MISC_PAD_CTRL_1:
+       case WM5100_MISC_PAD_CTRL_2:
+       case WM5100_MISC_PAD_CTRL_3:
+       case WM5100_MISC_PAD_CTRL_4:
+       case WM5100_MISC_PAD_CTRL_5:
+       case WM5100_MISC_GPIO_1:
+       case WM5100_INTERRUPT_STATUS_1:
+       case WM5100_INTERRUPT_STATUS_2:
+       case WM5100_INTERRUPT_STATUS_3:
+       case WM5100_INTERRUPT_STATUS_4:
+       case WM5100_INTERRUPT_RAW_STATUS_2:
+       case WM5100_INTERRUPT_RAW_STATUS_3:
+       case WM5100_INTERRUPT_RAW_STATUS_4:
+       case WM5100_INTERRUPT_STATUS_1_MASK:
+       case WM5100_INTERRUPT_STATUS_2_MASK:
+       case WM5100_INTERRUPT_STATUS_3_MASK:
+       case WM5100_INTERRUPT_STATUS_4_MASK:
+       case WM5100_INTERRUPT_CONTROL:
+       case WM5100_IRQ_DEBOUNCE_1:
+       case WM5100_IRQ_DEBOUNCE_2:
+       case WM5100_FX_CTRL:
+       case WM5100_EQ1_1:
+       case WM5100_EQ1_2:
+       case WM5100_EQ1_3:
+       case WM5100_EQ1_4:
+       case WM5100_EQ1_5:
+       case WM5100_EQ1_6:
+       case WM5100_EQ1_7:
+       case WM5100_EQ1_8:
+       case WM5100_EQ1_9:
+       case WM5100_EQ1_10:
+       case WM5100_EQ1_11:
+       case WM5100_EQ1_12:
+       case WM5100_EQ1_13:
+       case WM5100_EQ1_14:
+       case WM5100_EQ1_15:
+       case WM5100_EQ1_16:
+       case WM5100_EQ1_17:
+       case WM5100_EQ1_18:
+       case WM5100_EQ1_19:
+       case WM5100_EQ1_20:
+       case WM5100_EQ2_1:
+       case WM5100_EQ2_2:
+       case WM5100_EQ2_3:
+       case WM5100_EQ2_4:
+       case WM5100_EQ2_5:
+       case WM5100_EQ2_6:
+       case WM5100_EQ2_7:
+       case WM5100_EQ2_8:
+       case WM5100_EQ2_9:
+       case WM5100_EQ2_10:
+       case WM5100_EQ2_11:
+       case WM5100_EQ2_12:
+       case WM5100_EQ2_13:
+       case WM5100_EQ2_14:
+       case WM5100_EQ2_15:
+       case WM5100_EQ2_16:
+       case WM5100_EQ2_17:
+       case WM5100_EQ2_18:
+       case WM5100_EQ2_19:
+       case WM5100_EQ2_20:
+       case WM5100_EQ3_1:
+       case WM5100_EQ3_2:
+       case WM5100_EQ3_3:
+       case WM5100_EQ3_4:
+       case WM5100_EQ3_5:
+       case WM5100_EQ3_6:
+       case WM5100_EQ3_7:
+       case WM5100_EQ3_8:
+       case WM5100_EQ3_9:
+       case WM5100_EQ3_10:
+       case WM5100_EQ3_11:
+       case WM5100_EQ3_12:
+       case WM5100_EQ3_13:
+       case WM5100_EQ3_14:
+       case WM5100_EQ3_15:
+       case WM5100_EQ3_16:
+       case WM5100_EQ3_17:
+       case WM5100_EQ3_18:
+       case WM5100_EQ3_19:
+       case WM5100_EQ3_20:
+       case WM5100_EQ4_1:
+       case WM5100_EQ4_2:
+       case WM5100_EQ4_3:
+       case WM5100_EQ4_4:
+       case WM5100_EQ4_5:
+       case WM5100_EQ4_6:
+       case WM5100_EQ4_7:
+       case WM5100_EQ4_8:
+       case WM5100_EQ4_9:
+       case WM5100_EQ4_10:
+       case WM5100_EQ4_11:
+       case WM5100_EQ4_12:
+       case WM5100_EQ4_13:
+       case WM5100_EQ4_14:
+       case WM5100_EQ4_15:
+       case WM5100_EQ4_16:
+       case WM5100_EQ4_17:
+       case WM5100_EQ4_18:
+       case WM5100_EQ4_19:
+       case WM5100_EQ4_20:
+       case WM5100_DRC1_CTRL1:
+       case WM5100_DRC1_CTRL2:
+       case WM5100_DRC1_CTRL3:
+       case WM5100_DRC1_CTRL4:
+       case WM5100_DRC1_CTRL5:
+       case WM5100_HPLPF1_1:
+       case WM5100_HPLPF1_2:
+       case WM5100_HPLPF2_1:
+       case WM5100_HPLPF2_2:
+       case WM5100_HPLPF3_1:
+       case WM5100_HPLPF3_2:
+       case WM5100_HPLPF4_1:
+       case WM5100_HPLPF4_2:
+       case WM5100_DSP1_DM_0:
+       case WM5100_DSP1_DM_1:
+       case WM5100_DSP1_DM_2:
+       case WM5100_DSP1_DM_3:
+       case WM5100_DSP1_DM_508:
+       case WM5100_DSP1_DM_509:
+       case WM5100_DSP1_DM_510:
+       case WM5100_DSP1_DM_511:
+       case WM5100_DSP1_PM_0:
+       case WM5100_DSP1_PM_1:
+       case WM5100_DSP1_PM_2:
+       case WM5100_DSP1_PM_3:
+       case WM5100_DSP1_PM_4:
+       case WM5100_DSP1_PM_5:
+       case WM5100_DSP1_PM_1530:
+       case WM5100_DSP1_PM_1531:
+       case WM5100_DSP1_PM_1532:
+       case WM5100_DSP1_PM_1533:
+       case WM5100_DSP1_PM_1534:
+       case WM5100_DSP1_PM_1535:
+       case WM5100_DSP1_ZM_0:
+       case WM5100_DSP1_ZM_1:
+       case WM5100_DSP1_ZM_2:
+       case WM5100_DSP1_ZM_3:
+       case WM5100_DSP1_ZM_2044:
+       case WM5100_DSP1_ZM_2045:
+       case WM5100_DSP1_ZM_2046:
+       case WM5100_DSP1_ZM_2047:
+       case WM5100_DSP2_DM_0:
+       case WM5100_DSP2_DM_1:
+       case WM5100_DSP2_DM_2:
+       case WM5100_DSP2_DM_3:
+       case WM5100_DSP2_DM_508:
+       case WM5100_DSP2_DM_509:
+       case WM5100_DSP2_DM_510:
+       case WM5100_DSP2_DM_511:
+       case WM5100_DSP2_PM_0:
+       case WM5100_DSP2_PM_1:
+       case WM5100_DSP2_PM_2:
+       case WM5100_DSP2_PM_3:
+       case WM5100_DSP2_PM_4:
+       case WM5100_DSP2_PM_5:
+       case WM5100_DSP2_PM_1530:
+       case WM5100_DSP2_PM_1531:
+       case WM5100_DSP2_PM_1532:
+       case WM5100_DSP2_PM_1533:
+       case WM5100_DSP2_PM_1534:
+       case WM5100_DSP2_PM_1535:
+       case WM5100_DSP2_ZM_0:
+       case WM5100_DSP2_ZM_1:
+       case WM5100_DSP2_ZM_2:
+       case WM5100_DSP2_ZM_3:
+       case WM5100_DSP2_ZM_2044:
+       case WM5100_DSP2_ZM_2045:
+       case WM5100_DSP2_ZM_2046:
+       case WM5100_DSP2_ZM_2047:
+       case WM5100_DSP3_DM_0:
+       case WM5100_DSP3_DM_1:
+       case WM5100_DSP3_DM_2:
+       case WM5100_DSP3_DM_3:
+       case WM5100_DSP3_DM_508:
+       case WM5100_DSP3_DM_509:
+       case WM5100_DSP3_DM_510:
+       case WM5100_DSP3_DM_511:
+       case WM5100_DSP3_PM_0:
+       case WM5100_DSP3_PM_1:
+       case WM5100_DSP3_PM_2:
+       case WM5100_DSP3_PM_3:
+       case WM5100_DSP3_PM_4:
+       case WM5100_DSP3_PM_5:
+       case WM5100_DSP3_PM_1530:
+       case WM5100_DSP3_PM_1531:
+       case WM5100_DSP3_PM_1532:
+       case WM5100_DSP3_PM_1533:
+       case WM5100_DSP3_PM_1534:
+       case WM5100_DSP3_PM_1535:
+       case WM5100_DSP3_ZM_0:
+       case WM5100_DSP3_ZM_1:
+       case WM5100_DSP3_ZM_2:
+       case WM5100_DSP3_ZM_3:
+       case WM5100_DSP3_ZM_2044:
+       case WM5100_DSP3_ZM_2045:
+       case WM5100_DSP3_ZM_2046:
+       case WM5100_DSP3_ZM_2047:
+               return 1;
+       default:
+               return 0;
+       }
+}
+
+u16 wm5100_reg_defaults[WM5100_MAX_REGISTER + 1] = {
+       [0x0000] = 0x0000,     /* R0     - software reset */
+       [0x0001] = 0x0000,     /* R1     - Device Revision */
+       [0x0010] = 0x0801,     /* R16    - Ctrl IF 1 */
+       [0x0020] = 0x0000,     /* R32    - Tone Generator 1 */
+       [0x0030] = 0x0000,     /* R48    - PWM Drive 1 */
+       [0x0031] = 0x0100,     /* R49    - PWM Drive 2 */
+       [0x0032] = 0x0100,     /* R50    - PWM Drive 3 */
+       [0x0100] = 0x0002,     /* R256   - Clocking 1 */
+       [0x0101] = 0x0000,     /* R257   - Clocking 3 */
+       [0x0102] = 0x0011,     /* R258   - Clocking 4 */
+       [0x0103] = 0x0011,     /* R259   - Clocking 5 */
+       [0x0104] = 0x0011,     /* R260   - Clocking 6 */
+       [0x0107] = 0x0000,     /* R263   - Clocking 7 */
+       [0x0108] = 0x0000,     /* R264   - Clocking 8 */
+       [0x0120] = 0x0000,     /* R288   - ASRC_ENABLE */
+       [0x0121] = 0x0000,     /* R289   - ASRC_STATUS */
+       [0x0122] = 0x0000,     /* R290   - ASRC_RATE1 */
+       [0x0141] = 0x8000,     /* R321   - ISRC 1 CTRL 1 */
+       [0x0142] = 0x0000,     /* R322   - ISRC 1 CTRL 2 */
+       [0x0143] = 0x8000,     /* R323   - ISRC 2 CTRL1 */
+       [0x0144] = 0x0000,     /* R324   - ISRC 2 CTRL 2 */
+       [0x0182] = 0x0000,     /* R386   - FLL1 Control 1 */
+       [0x0183] = 0x0000,     /* R387   - FLL1 Control 2 */
+       [0x0184] = 0x0000,     /* R388   - FLL1 Control 3 */
+       [0x0186] = 0x0177,     /* R390   - FLL1 Control 5 */
+       [0x0187] = 0x0001,     /* R391   - FLL1 Control 6 */
+       [0x0188] = 0x0000,     /* R392   - FLL1 EFS 1 */
+       [0x01A2] = 0x0000,     /* R418   - FLL2 Control 1 */
+       [0x01A3] = 0x0000,     /* R419   - FLL2 Control 2 */
+       [0x01A4] = 0x0000,     /* R420   - FLL2 Control 3 */
+       [0x01A6] = 0x0177,     /* R422   - FLL2 Control 5 */
+       [0x01A7] = 0x0001,     /* R423   - FLL2 Control 6 */
+       [0x01A8] = 0x0000,     /* R424   - FLL2 EFS 1 */
+       [0x0200] = 0x0020,     /* R512   - Mic Charge Pump 1 */
+       [0x0201] = 0xB084,     /* R513   - Mic Charge Pump 2 */
+       [0x0202] = 0xBBDE,     /* R514   - HP Charge Pump 1 */
+       [0x0211] = 0x20D4,     /* R529   - LDO1 Control */
+       [0x0215] = 0x0062,     /* R533   - Mic Bias Ctrl 1 */
+       [0x0216] = 0x0062,     /* R534   - Mic Bias Ctrl 2 */
+       [0x0217] = 0x0062,     /* R535   - Mic Bias Ctrl 3 */
+       [0x0280] = 0x0004,     /* R640   - Accessory Detect Mode 1 */
+       [0x0288] = 0x0020,     /* R648   - Headphone Detect 1 */
+       [0x0289] = 0x0000,     /* R649   - Headphone Detect 2 */
+       [0x0290] = 0x1100,     /* R656   - Mic Detect 1 */
+       [0x0291] = 0x009F,     /* R657   - Mic Detect 2 */
+       [0x0292] = 0x0000,     /* R658   - Mic Detect 3 */
+       [0x0301] = 0x0000,     /* R769   - Input Enables */
+       [0x0302] = 0x0000,     /* R770   - Input Enables Status */
+       [0x0310] = 0x2280,     /* R784   - Status */
+       [0x0311] = 0x0080,     /* R785   - IN1R Control */
+       [0x0312] = 0x2280,     /* R786   - IN2L Control */
+       [0x0313] = 0x0080,     /* R787   - IN2R Control */
+       [0x0314] = 0x2280,     /* R788   - IN3L Control */
+       [0x0315] = 0x0080,     /* R789   - IN3R Control */
+       [0x0316] = 0x2280,     /* R790   - IN4L Control */
+       [0x0317] = 0x0080,     /* R791   - IN4R Control */
+       [0x0318] = 0x0000,     /* R792   - RXANC_SRC */
+       [0x0319] = 0x0022,     /* R793   - Input Volume Ramp */
+       [0x0320] = 0x0180,     /* R800   - ADC Digital Volume 1L */
+       [0x0321] = 0x0180,     /* R801   - ADC Digital Volume 1R */
+       [0x0322] = 0x0180,     /* R802   - ADC Digital Volume 2L */
+       [0x0323] = 0x0180,     /* R803   - ADC Digital Volume 2R */
+       [0x0324] = 0x0180,     /* R804   - ADC Digital Volume 3L */
+       [0x0325] = 0x0180,     /* R805   - ADC Digital Volume 3R */
+       [0x0326] = 0x0180,     /* R806   - ADC Digital Volume 4L */
+       [0x0327] = 0x0180,     /* R807   - ADC Digital Volume 4R */
+       [0x0401] = 0x0000,     /* R1025  - Output Enables 2 */
+       [0x0402] = 0x0000,     /* R1026  - Output Status 1 */
+       [0x0403] = 0x0000,     /* R1027  - Output Status 2 */
+       [0x0408] = 0x0000,     /* R1032  - Channel Enables 1 */
+       [0x0410] = 0x0080,     /* R1040  - Out Volume 1L */
+       [0x0411] = 0x0080,     /* R1041  - Out Volume 1R */
+       [0x0412] = 0x0080,     /* R1042  - DAC Volume Limit 1L */
+       [0x0413] = 0x0080,     /* R1043  - DAC Volume Limit 1R */
+       [0x0414] = 0x0080,     /* R1044  - Out Volume 2L */
+       [0x0415] = 0x0080,     /* R1045  - Out Volume 2R */
+       [0x0416] = 0x0080,     /* R1046  - DAC Volume Limit 2L */
+       [0x0417] = 0x0080,     /* R1047  - DAC Volume Limit 2R */
+       [0x0418] = 0x0080,     /* R1048  - Out Volume 3L */
+       [0x0419] = 0x0080,     /* R1049  - Out Volume 3R */
+       [0x041A] = 0x0080,     /* R1050  - DAC Volume Limit 3L */
+       [0x041B] = 0x0080,     /* R1051  - DAC Volume Limit 3R */
+       [0x041C] = 0x0080,     /* R1052  - Out Volume 4L */
+       [0x041D] = 0x0080,     /* R1053  - Out Volume 4R */
+       [0x041E] = 0x0080,     /* R1054  - DAC Volume Limit 5L */
+       [0x041F] = 0x0080,     /* R1055  - DAC Volume Limit 5R */
+       [0x0420] = 0x0080,     /* R1056  - DAC Volume Limit 6L */
+       [0x0421] = 0x0080,     /* R1057  - DAC Volume Limit 6R */
+       [0x0440] = 0x0000,     /* R1088  - DAC AEC Control 1 */
+       [0x0441] = 0x0022,     /* R1089  - Output Volume Ramp */
+       [0x0480] = 0x0180,     /* R1152  - DAC Digital Volume 1L */
+       [0x0481] = 0x0180,     /* R1153  - DAC Digital Volume 1R */
+       [0x0482] = 0x0180,     /* R1154  - DAC Digital Volume 2L */
+       [0x0483] = 0x0180,     /* R1155  - DAC Digital Volume 2R */
+       [0x0484] = 0x0180,     /* R1156  - DAC Digital Volume 3L */
+       [0x0485] = 0x0180,     /* R1157  - DAC Digital Volume 3R */
+       [0x0486] = 0x0180,     /* R1158  - DAC Digital Volume 4L */
+       [0x0487] = 0x0180,     /* R1159  - DAC Digital Volume 4R */
+       [0x0488] = 0x0180,     /* R1160  - DAC Digital Volume 5L */
+       [0x0489] = 0x0180,     /* R1161  - DAC Digital Volume 5R */
+       [0x048A] = 0x0180,     /* R1162  - DAC Digital Volume 6L */
+       [0x048B] = 0x0180,     /* R1163  - DAC Digital Volume 6R */
+       [0x04C0] = 0x0069,     /* R1216  - PDM SPK1 CTRL 1 */
+       [0x04C1] = 0x0000,     /* R1217  - PDM SPK1 CTRL 2 */
+       [0x04C2] = 0x0069,     /* R1218  - PDM SPK2 CTRL 1 */
+       [0x04C3] = 0x0000,     /* R1219  - PDM SPK2 CTRL 2 */
+       [0x0500] = 0x000C,     /* R1280  - Audio IF 1_1 */
+       [0x0501] = 0x0008,     /* R1281  - Audio IF 1_2 */
+       [0x0502] = 0x0000,     /* R1282  - Audio IF 1_3 */
+       [0x0503] = 0x0000,     /* R1283  - Audio IF 1_4 */
+       [0x0504] = 0x0000,     /* R1284  - Audio IF 1_5 */
+       [0x0505] = 0x0300,     /* R1285  - Audio IF 1_6 */
+       [0x0506] = 0x0300,     /* R1286  - Audio IF 1_7 */
+       [0x0507] = 0x1820,     /* R1287  - Audio IF 1_8 */
+       [0x0508] = 0x1820,     /* R1288  - Audio IF 1_9 */
+       [0x0509] = 0x0000,     /* R1289  - Audio IF 1_10 */
+       [0x050A] = 0x0001,     /* R1290  - Audio IF 1_11 */
+       [0x050B] = 0x0002,     /* R1291  - Audio IF 1_12 */
+       [0x050C] = 0x0003,     /* R1292  - Audio IF 1_13 */
+       [0x050D] = 0x0004,     /* R1293  - Audio IF 1_14 */
+       [0x050E] = 0x0005,     /* R1294  - Audio IF 1_15 */
+       [0x050F] = 0x0006,     /* R1295  - Audio IF 1_16 */
+       [0x0510] = 0x0007,     /* R1296  - Audio IF 1_17 */
+       [0x0511] = 0x0000,     /* R1297  - Audio IF 1_18 */
+       [0x0512] = 0x0001,     /* R1298  - Audio IF 1_19 */
+       [0x0513] = 0x0002,     /* R1299  - Audio IF 1_20 */
+       [0x0514] = 0x0003,     /* R1300  - Audio IF 1_21 */
+       [0x0515] = 0x0004,     /* R1301  - Audio IF 1_22 */
+       [0x0516] = 0x0005,     /* R1302  - Audio IF 1_23 */
+       [0x0517] = 0x0006,     /* R1303  - Audio IF 1_24 */
+       [0x0518] = 0x0007,     /* R1304  - Audio IF 1_25 */
+       [0x0519] = 0x0000,     /* R1305  - Audio IF 1_26 */
+       [0x051A] = 0x0000,     /* R1306  - Audio IF 1_27 */
+       [0x0540] = 0x000C,     /* R1344  - Audio IF 2_1 */
+       [0x0541] = 0x0008,     /* R1345  - Audio IF 2_2 */
+       [0x0542] = 0x0000,     /* R1346  - Audio IF 2_3 */
+       [0x0543] = 0x0000,     /* R1347  - Audio IF 2_4 */
+       [0x0544] = 0x0000,     /* R1348  - Audio IF 2_5 */
+       [0x0545] = 0x0300,     /* R1349  - Audio IF 2_6 */
+       [0x0546] = 0x0300,     /* R1350  - Audio IF 2_7 */
+       [0x0547] = 0x1820,     /* R1351  - Audio IF 2_8 */
+       [0x0548] = 0x1820,     /* R1352  - Audio IF 2_9 */
+       [0x0549] = 0x0000,     /* R1353  - Audio IF 2_10 */
+       [0x054A] = 0x0001,     /* R1354  - Audio IF 2_11 */
+       [0x0551] = 0x0000,     /* R1361  - Audio IF 2_18 */
+       [0x0552] = 0x0001,     /* R1362  - Audio IF 2_19 */
+       [0x0559] = 0x0000,     /* R1369  - Audio IF 2_26 */
+       [0x055A] = 0x0000,     /* R1370  - Audio IF 2_27 */
+       [0x0580] = 0x000C,     /* R1408  - Audio IF 3_1 */
+       [0x0581] = 0x0008,     /* R1409  - Audio IF 3_2 */
+       [0x0582] = 0x0000,     /* R1410  - Audio IF 3_3 */
+       [0x0583] = 0x0000,     /* R1411  - Audio IF 3_4 */
+       [0x0584] = 0x0000,     /* R1412  - Audio IF 3_5 */
+       [0x0585] = 0x0300,     /* R1413  - Audio IF 3_6 */
+       [0x0586] = 0x0300,     /* R1414  - Audio IF 3_7 */
+       [0x0587] = 0x1820,     /* R1415  - Audio IF 3_8 */
+       [0x0588] = 0x1820,     /* R1416  - Audio IF 3_9 */
+       [0x0589] = 0x0000,     /* R1417  - Audio IF 3_10 */
+       [0x058A] = 0x0001,     /* R1418  - Audio IF 3_11 */
+       [0x0591] = 0x0000,     /* R1425  - Audio IF 3_18 */
+       [0x0592] = 0x0001,     /* R1426  - Audio IF 3_19 */
+       [0x0599] = 0x0000,     /* R1433  - Audio IF 3_26 */
+       [0x059A] = 0x0000,     /* R1434  - Audio IF 3_27 */
+       [0x0640] = 0x0000,     /* R1600  - PWM1MIX Input 1 Source */
+       [0x0641] = 0x0080,     /* R1601  - PWM1MIX Input 1 Volume */
+       [0x0642] = 0x0000,     /* R1602  - PWM1MIX Input 2 Source */
+       [0x0643] = 0x0080,     /* R1603  - PWM1MIX Input 2 Volume */
+       [0x0644] = 0x0000,     /* R1604  - PWM1MIX Input 3 Source */
+       [0x0645] = 0x0080,     /* R1605  - PWM1MIX Input 3 Volume */
+       [0x0646] = 0x0000,     /* R1606  - PWM1MIX Input 4 Source */
+       [0x0647] = 0x0080,     /* R1607  - PWM1MIX Input 4 Volume */
+       [0x0648] = 0x0000,     /* R1608  - PWM2MIX Input 1 Source */
+       [0x0649] = 0x0080,     /* R1609  - PWM2MIX Input 1 Volume */
+       [0x064A] = 0x0000,     /* R1610  - PWM2MIX Input 2 Source */
+       [0x064B] = 0x0080,     /* R1611  - PWM2MIX Input 2 Volume */
+       [0x064C] = 0x0000,     /* R1612  - PWM2MIX Input 3 Source */
+       [0x064D] = 0x0080,     /* R1613  - PWM2MIX Input 3 Volume */
+       [0x064E] = 0x0000,     /* R1614  - PWM2MIX Input 4 Source */
+       [0x064F] = 0x0080,     /* R1615  - PWM2MIX Input 4 Volume */
+       [0x0680] = 0x0000,     /* R1664  - OUT1LMIX Input 1 Source */
+       [0x0681] = 0x0080,     /* R1665  - OUT1LMIX Input 1 Volume */
+       [0x0682] = 0x0000,     /* R1666  - OUT1LMIX Input 2 Source */
+       [0x0683] = 0x0080,     /* R1667  - OUT1LMIX Input 2 Volume */
+       [0x0684] = 0x0000,     /* R1668  - OUT1LMIX Input 3 Source */
+       [0x0685] = 0x0080,     /* R1669  - OUT1LMIX Input 3 Volume */
+       [0x0686] = 0x0000,     /* R1670  - OUT1LMIX Input 4 Source */
+       [0x0687] = 0x0080,     /* R1671  - OUT1LMIX Input 4 Volume */
+       [0x0688] = 0x0000,     /* R1672  - OUT1RMIX Input 1 Source */
+       [0x0689] = 0x0080,     /* R1673  - OUT1RMIX Input 1 Volume */
+       [0x068A] = 0x0000,     /* R1674  - OUT1RMIX Input 2 Source */
+       [0x068B] = 0x0080,     /* R1675  - OUT1RMIX Input 2 Volume */
+       [0x068C] = 0x0000,     /* R1676  - OUT1RMIX Input 3 Source */
+       [0x068D] = 0x0080,     /* R1677  - OUT1RMIX Input 3 Volume */
+       [0x068E] = 0x0000,     /* R1678  - OUT1RMIX Input 4 Source */
+       [0x068F] = 0x0080,     /* R1679  - OUT1RMIX Input 4 Volume */
+       [0x0690] = 0x0000,     /* R1680  - OUT2LMIX Input 1 Source */
+       [0x0691] = 0x0080,     /* R1681  - OUT2LMIX Input 1 Volume */
+       [0x0692] = 0x0000,     /* R1682  - OUT2LMIX Input 2 Source */
+       [0x0693] = 0x0080,     /* R1683  - OUT2LMIX Input 2 Volume */
+       [0x0694] = 0x0000,     /* R1684  - OUT2LMIX Input 3 Source */
+       [0x0695] = 0x0080,     /* R1685  - OUT2LMIX Input 3 Volume */
+       [0x0696] = 0x0000,     /* R1686  - OUT2LMIX Input 4 Source */
+       [0x0697] = 0x0080,     /* R1687  - OUT2LMIX Input 4 Volume */
+       [0x0698] = 0x0000,     /* R1688  - OUT2RMIX Input 1 Source */
+       [0x0699] = 0x0080,     /* R1689  - OUT2RMIX Input 1 Volume */
+       [0x069A] = 0x0000,     /* R1690  - OUT2RMIX Input 2 Source */
+       [0x069B] = 0x0080,     /* R1691  - OUT2RMIX Input 2 Volume */
+       [0x069C] = 0x0000,     /* R1692  - OUT2RMIX Input 3 Source */
+       [0x069D] = 0x0080,     /* R1693  - OUT2RMIX Input 3 Volume */
+       [0x069E] = 0x0000,     /* R1694  - OUT2RMIX Input 4 Source */
+       [0x069F] = 0x0080,     /* R1695  - OUT2RMIX Input 4 Volume */
+       [0x06A0] = 0x0000,     /* R1696  - OUT3LMIX Input 1 Source */
+       [0x06A1] = 0x0080,     /* R1697  - OUT3LMIX Input 1 Volume */
+       [0x06A2] = 0x0000,     /* R1698  - OUT3LMIX Input 2 Source */
+       [0x06A3] = 0x0080,     /* R1699  - OUT3LMIX Input 2 Volume */
+       [0x06A4] = 0x0000,     /* R1700  - OUT3LMIX Input 3 Source */
+       [0x06A5] = 0x0080,     /* R1701  - OUT3LMIX Input 3 Volume */
+       [0x06A6] = 0x0000,     /* R1702  - OUT3LMIX Input 4 Source */
+       [0x06A7] = 0x0080,     /* R1703  - OUT3LMIX Input 4 Volume */
+       [0x06A8] = 0x0000,     /* R1704  - OUT3RMIX Input 1 Source */
+       [0x06A9] = 0x0080,     /* R1705  - OUT3RMIX Input 1 Volume */
+       [0x06AA] = 0x0000,     /* R1706  - OUT3RMIX Input 2 Source */
+       [0x06AB] = 0x0080,     /* R1707  - OUT3RMIX Input 2 Volume */
+       [0x06AC] = 0x0000,     /* R1708  - OUT3RMIX Input 3 Source */
+       [0x06AD] = 0x0080,     /* R1709  - OUT3RMIX Input 3 Volume */
+       [0x06AE] = 0x0000,     /* R1710  - OUT3RMIX Input 4 Source */
+       [0x06AF] = 0x0080,     /* R1711  - OUT3RMIX Input 4 Volume */
+       [0x06B0] = 0x0000,     /* R1712  - OUT4LMIX Input 1 Source */
+       [0x06B1] = 0x0080,     /* R1713  - OUT4LMIX Input 1 Volume */
+       [0x06B2] = 0x0000,     /* R1714  - OUT4LMIX Input 2 Source */
+       [0x06B3] = 0x0080,     /* R1715  - OUT4LMIX Input 2 Volume */
+       [0x06B4] = 0x0000,     /* R1716  - OUT4LMIX Input 3 Source */
+       [0x06B5] = 0x0080,     /* R1717  - OUT4LMIX Input 3 Volume */
+       [0x06B6] = 0x0000,     /* R1718  - OUT4LMIX Input 4 Source */
+       [0x06B7] = 0x0080,     /* R1719  - OUT4LMIX Input 4 Volume */
+       [0x06B8] = 0x0000,     /* R1720  - OUT4RMIX Input 1 Source */
+       [0x06B9] = 0x0080,     /* R1721  - OUT4RMIX Input 1 Volume */
+       [0x06BA] = 0x0000,     /* R1722  - OUT4RMIX Input 2 Source */
+       [0x06BB] = 0x0080,     /* R1723  - OUT4RMIX Input 2 Volume */
+       [0x06BC] = 0x0000,     /* R1724  - OUT4RMIX Input 3 Source */
+       [0x06BD] = 0x0080,     /* R1725  - OUT4RMIX Input 3 Volume */
+       [0x06BE] = 0x0000,     /* R1726  - OUT4RMIX Input 4 Source */
+       [0x06BF] = 0x0080,     /* R1727  - OUT4RMIX Input 4 Volume */
+       [0x06C0] = 0x0000,     /* R1728  - OUT5LMIX Input 1 Source */
+       [0x06C1] = 0x0080,     /* R1729  - OUT5LMIX Input 1 Volume */
+       [0x06C2] = 0x0000,     /* R1730  - OUT5LMIX Input 2 Source */
+       [0x06C3] = 0x0080,     /* R1731  - OUT5LMIX Input 2 Volume */
+       [0x06C4] = 0x0000,     /* R1732  - OUT5LMIX Input 3 Source */
+       [0x06C5] = 0x0080,     /* R1733  - OUT5LMIX Input 3 Volume */
+       [0x06C6] = 0x0000,     /* R1734  - OUT5LMIX Input 4 Source */
+       [0x06C7] = 0x0080,     /* R1735  - OUT5LMIX Input 4 Volume */
+       [0x06C8] = 0x0000,     /* R1736  - OUT5RMIX Input 1 Source */
+       [0x06C9] = 0x0080,     /* R1737  - OUT5RMIX Input 1 Volume */
+       [0x06CA] = 0x0000,     /* R1738  - OUT5RMIX Input 2 Source */
+       [0x06CB] = 0x0080,     /* R1739  - OUT5RMIX Input 2 Volume */
+       [0x06CC] = 0x0000,     /* R1740  - OUT5RMIX Input 3 Source */
+       [0x06CD] = 0x0080,     /* R1741  - OUT5RMIX Input 3 Volume */
+       [0x06CE] = 0x0000,     /* R1742  - OUT5RMIX Input 4 Source */
+       [0x06CF] = 0x0080,     /* R1743  - OUT5RMIX Input 4 Volume */
+       [0x06D0] = 0x0000,     /* R1744  - OUT6LMIX Input 1 Source */
+       [0x06D1] = 0x0080,     /* R1745  - OUT6LMIX Input 1 Volume */
+       [0x06D2] = 0x0000,     /* R1746  - OUT6LMIX Input 2 Source */
+       [0x06D3] = 0x0080,     /* R1747  - OUT6LMIX Input 2 Volume */
+       [0x06D4] = 0x0000,     /* R1748  - OUT6LMIX Input 3 Source */
+       [0x06D5] = 0x0080,     /* R1749  - OUT6LMIX Input 3 Volume */
+       [0x06D6] = 0x0000,     /* R1750  - OUT6LMIX Input 4 Source */
+       [0x06D7] = 0x0080,     /* R1751  - OUT6LMIX Input 4 Volume */
+       [0x06D8] = 0x0000,     /* R1752  - OUT6RMIX Input 1 Source */
+       [0x06D9] = 0x0080,     /* R1753  - OUT6RMIX Input 1 Volume */
+       [0x06DA] = 0x0000,     /* R1754  - OUT6RMIX Input 2 Source */
+       [0x06DB] = 0x0080,     /* R1755  - OUT6RMIX Input 2 Volume */
+       [0x06DC] = 0x0000,     /* R1756  - OUT6RMIX Input 3 Source */
+       [0x06DD] = 0x0080,     /* R1757  - OUT6RMIX Input 3 Volume */
+       [0x06DE] = 0x0000,     /* R1758  - OUT6RMIX Input 4 Source */
+       [0x06DF] = 0x0080,     /* R1759  - OUT6RMIX Input 4 Volume */
+       [0x0700] = 0x0000,     /* R1792  - AIF1TX1MIX Input 1 Source */
+       [0x0701] = 0x0080,     /* R1793  - AIF1TX1MIX Input 1 Volume */
+       [0x0702] = 0x0000,     /* R1794  - AIF1TX1MIX Input 2 Source */
+       [0x0703] = 0x0080,     /* R1795  - AIF1TX1MIX Input 2 Volume */
+       [0x0704] = 0x0000,     /* R1796  - AIF1TX1MIX Input 3 Source */
+       [0x0705] = 0x0080,     /* R1797  - AIF1TX1MIX Input 3 Volume */
+       [0x0706] = 0x0000,     /* R1798  - AIF1TX1MIX Input 4 Source */
+       [0x0707] = 0x0080,     /* R1799  - AIF1TX1MIX Input 4 Volume */
+       [0x0708] = 0x0000,     /* R1800  - AIF1TX2MIX Input 1 Source */
+       [0x0709] = 0x0080,     /* R1801  - AIF1TX2MIX Input 1 Volume */
+       [0x070A] = 0x0000,     /* R1802  - AIF1TX2MIX Input 2 Source */
+       [0x070B] = 0x0080,     /* R1803  - AIF1TX2MIX Input 2 Volume */
+       [0x070C] = 0x0000,     /* R1804  - AIF1TX2MIX Input 3 Source */
+       [0x070D] = 0x0080,     /* R1805  - AIF1TX2MIX Input 3 Volume */
+       [0x070E] = 0x0000,     /* R1806  - AIF1TX2MIX Input 4 Source */
+       [0x070F] = 0x0080,     /* R1807  - AIF1TX2MIX Input 4 Volume */
+       [0x0710] = 0x0000,     /* R1808  - AIF1TX3MIX Input 1 Source */
+       [0x0711] = 0x0080,     /* R1809  - AIF1TX3MIX Input 1 Volume */
+       [0x0712] = 0x0000,     /* R1810  - AIF1TX3MIX Input 2 Source */
+       [0x0713] = 0x0080,     /* R1811  - AIF1TX3MIX Input 2 Volume */
+       [0x0714] = 0x0000,     /* R1812  - AIF1TX3MIX Input 3 Source */
+       [0x0715] = 0x0080,     /* R1813  - AIF1TX3MIX Input 3 Volume */
+       [0x0716] = 0x0000,     /* R1814  - AIF1TX3MIX Input 4 Source */
+       [0x0717] = 0x0080,     /* R1815  - AIF1TX3MIX Input 4 Volume */
+       [0x0718] = 0x0000,     /* R1816  - AIF1TX4MIX Input 1 Source */
+       [0x0719] = 0x0080,     /* R1817  - AIF1TX4MIX Input 1 Volume */
+       [0x071A] = 0x0000,     /* R1818  - AIF1TX4MIX Input 2 Source */
+       [0x071B] = 0x0080,     /* R1819  - AIF1TX4MIX Input 2 Volume */
+       [0x071C] = 0x0000,     /* R1820  - AIF1TX4MIX Input 3 Source */
+       [0x071D] = 0x0080,     /* R1821  - AIF1TX4MIX Input 3 Volume */
+       [0x071E] = 0x0000,     /* R1822  - AIF1TX4MIX Input 4 Source */
+       [0x071F] = 0x0080,     /* R1823  - AIF1TX4MIX Input 4 Volume */
+       [0x0720] = 0x0000,     /* R1824  - AIF1TX5MIX Input 1 Source */
+       [0x0721] = 0x0080,     /* R1825  - AIF1TX5MIX Input 1 Volume */
+       [0x0722] = 0x0000,     /* R1826  - AIF1TX5MIX Input 2 Source */
+       [0x0723] = 0x0080,     /* R1827  - AIF1TX5MIX Input 2 Volume */
+       [0x0724] = 0x0000,     /* R1828  - AIF1TX5MIX Input 3 Source */
+       [0x0725] = 0x0080,     /* R1829  - AIF1TX5MIX Input 3 Volume */
+       [0x0726] = 0x0000,     /* R1830  - AIF1TX5MIX Input 4 Source */
+       [0x0727] = 0x0080,     /* R1831  - AIF1TX5MIX Input 4 Volume */
+       [0x0728] = 0x0000,     /* R1832  - AIF1TX6MIX Input 1 Source */
+       [0x0729] = 0x0080,     /* R1833  - AIF1TX6MIX Input 1 Volume */
+       [0x072A] = 0x0000,     /* R1834  - AIF1TX6MIX Input 2 Source */
+       [0x072B] = 0x0080,     /* R1835  - AIF1TX6MIX Input 2 Volume */
+       [0x072C] = 0x0000,     /* R1836  - AIF1TX6MIX Input 3 Source */
+       [0x072D] = 0x0080,     /* R1837  - AIF1TX6MIX Input 3 Volume */
+       [0x072E] = 0x0000,     /* R1838  - AIF1TX6MIX Input 4 Source */
+       [0x072F] = 0x0080,     /* R1839  - AIF1TX6MIX Input 4 Volume */
+       [0x0730] = 0x0000,     /* R1840  - AIF1TX7MIX Input 1 Source */
+       [0x0731] = 0x0080,     /* R1841  - AIF1TX7MIX Input 1 Volume */
+       [0x0732] = 0x0000,     /* R1842  - AIF1TX7MIX Input 2 Source */
+       [0x0733] = 0x0080,     /* R1843  - AIF1TX7MIX Input 2 Volume */
+       [0x0734] = 0x0000,     /* R1844  - AIF1TX7MIX Input 3 Source */
+       [0x0735] = 0x0080,     /* R1845  - AIF1TX7MIX Input 3 Volume */
+       [0x0736] = 0x0000,     /* R1846  - AIF1TX7MIX Input 4 Source */
+       [0x0737] = 0x0080,     /* R1847  - AIF1TX7MIX Input 4 Volume */
+       [0x0738] = 0x0000,     /* R1848  - AIF1TX8MIX Input 1 Source */
+       [0x0739] = 0x0080,     /* R1849  - AIF1TX8MIX Input 1 Volume */
+       [0x073A] = 0x0000,     /* R1850  - AIF1TX8MIX Input 2 Source */
+       [0x073B] = 0x0080,     /* R1851  - AIF1TX8MIX Input 2 Volume */
+       [0x073C] = 0x0000,     /* R1852  - AIF1TX8MIX Input 3 Source */
+       [0x073D] = 0x0080,     /* R1853  - AIF1TX8MIX Input 3 Volume */
+       [0x073E] = 0x0000,     /* R1854  - AIF1TX8MIX Input 4 Source */
+       [0x073F] = 0x0080,     /* R1855  - AIF1TX8MIX Input 4 Volume */
+       [0x0740] = 0x0000,     /* R1856  - AIF2TX1MIX Input 1 Source */
+       [0x0741] = 0x0080,     /* R1857  - AIF2TX1MIX Input 1 Volume */
+       [0x0742] = 0x0000,     /* R1858  - AIF2TX1MIX Input 2 Source */
+       [0x0743] = 0x0080,     /* R1859  - AIF2TX1MIX Input 2 Volume */
+       [0x0744] = 0x0000,     /* R1860  - AIF2TX1MIX Input 3 Source */
+       [0x0745] = 0x0080,     /* R1861  - AIF2TX1MIX Input 3 Volume */
+       [0x0746] = 0x0000,     /* R1862  - AIF2TX1MIX Input 4 Source */
+       [0x0747] = 0x0080,     /* R1863  - AIF2TX1MIX Input 4 Volume */
+       [0x0748] = 0x0000,     /* R1864  - AIF2TX2MIX Input 1 Source */
+       [0x0749] = 0x0080,     /* R1865  - AIF2TX2MIX Input 1 Volume */
+       [0x074A] = 0x0000,     /* R1866  - AIF2TX2MIX Input 2 Source */
+       [0x074B] = 0x0080,     /* R1867  - AIF2TX2MIX Input 2 Volume */
+       [0x074C] = 0x0000,     /* R1868  - AIF2TX2MIX Input 3 Source */
+       [0x074D] = 0x0080,     /* R1869  - AIF2TX2MIX Input 3 Volume */
+       [0x074E] = 0x0000,     /* R1870  - AIF2TX2MIX Input 4 Source */
+       [0x074F] = 0x0080,     /* R1871  - AIF2TX2MIX Input 4 Volume */
+       [0x0780] = 0x0000,     /* R1920  - AIF3TX1MIX Input 1 Source */
+       [0x0781] = 0x0080,     /* R1921  - AIF3TX1MIX Input 1 Volume */
+       [0x0782] = 0x0000,     /* R1922  - AIF3TX1MIX Input 2 Source */
+       [0x0783] = 0x0080,     /* R1923  - AIF3TX1MIX Input 2 Volume */
+       [0x0784] = 0x0000,     /* R1924  - AIF3TX1MIX Input 3 Source */
+       [0x0785] = 0x0080,     /* R1925  - AIF3TX1MIX Input 3 Volume */
+       [0x0786] = 0x0000,     /* R1926  - AIF3TX1MIX Input 4 Source */
+       [0x0787] = 0x0080,     /* R1927  - AIF3TX1MIX Input 4 Volume */
+       [0x0788] = 0x0000,     /* R1928  - AIF3TX2MIX Input 1 Source */
+       [0x0789] = 0x0080,     /* R1929  - AIF3TX2MIX Input 1 Volume */
+       [0x078A] = 0x0000,     /* R1930  - AIF3TX2MIX Input 2 Source */
+       [0x078B] = 0x0080,     /* R1931  - AIF3TX2MIX Input 2 Volume */
+       [0x078C] = 0x0000,     /* R1932  - AIF3TX2MIX Input 3 Source */
+       [0x078D] = 0x0080,     /* R1933  - AIF3TX2MIX Input 3 Volume */
+       [0x078E] = 0x0000,     /* R1934  - AIF3TX2MIX Input 4 Source */
+       [0x078F] = 0x0080,     /* R1935  - AIF3TX2MIX Input 4 Volume */
+       [0x0880] = 0x0000,     /* R2176  - EQ1MIX Input 1 Source */
+       [0x0881] = 0x0080,     /* R2177  - EQ1MIX Input 1 Volume */
+       [0x0882] = 0x0000,     /* R2178  - EQ1MIX Input 2 Source */
+       [0x0883] = 0x0080,     /* R2179  - EQ1MIX Input 2 Volume */
+       [0x0884] = 0x0000,     /* R2180  - EQ1MIX Input 3 Source */
+       [0x0885] = 0x0080,     /* R2181  - EQ1MIX Input 3 Volume */
+       [0x0886] = 0x0000,     /* R2182  - EQ1MIX Input 4 Source */
+       [0x0887] = 0x0080,     /* R2183  - EQ1MIX Input 4 Volume */
+       [0x0888] = 0x0000,     /* R2184  - EQ2MIX Input 1 Source */
+       [0x0889] = 0x0080,     /* R2185  - EQ2MIX Input 1 Volume */
+       [0x088A] = 0x0000,     /* R2186  - EQ2MIX Input 2 Source */
+       [0x088B] = 0x0080,     /* R2187  - EQ2MIX Input 2 Volume */
+       [0x088C] = 0x0000,     /* R2188  - EQ2MIX Input 3 Source */
+       [0x088D] = 0x0080,     /* R2189  - EQ2MIX Input 3 Volume */
+       [0x088E] = 0x0000,     /* R2190  - EQ2MIX Input 4 Source */
+       [0x088F] = 0x0080,     /* R2191  - EQ2MIX Input 4 Volume */
+       [0x0890] = 0x0000,     /* R2192  - EQ3MIX Input 1 Source */
+       [0x0891] = 0x0080,     /* R2193  - EQ3MIX Input 1 Volume */
+       [0x0892] = 0x0000,     /* R2194  - EQ3MIX Input 2 Source */
+       [0x0893] = 0x0080,     /* R2195  - EQ3MIX Input 2 Volume */
+       [0x0894] = 0x0000,     /* R2196  - EQ3MIX Input 3 Source */
+       [0x0895] = 0x0080,     /* R2197  - EQ3MIX Input 3 Volume */
+       [0x0896] = 0x0000,     /* R2198  - EQ3MIX Input 4 Source */
+       [0x0897] = 0x0080,     /* R2199  - EQ3MIX Input 4 Volume */
+       [0x0898] = 0x0000,     /* R2200  - EQ4MIX Input 1 Source */
+       [0x0899] = 0x0080,     /* R2201  - EQ4MIX Input 1 Volume */
+       [0x089A] = 0x0000,     /* R2202  - EQ4MIX Input 2 Source */
+       [0x089B] = 0x0080,     /* R2203  - EQ4MIX Input 2 Volume */
+       [0x089C] = 0x0000,     /* R2204  - EQ4MIX Input 3 Source */
+       [0x089D] = 0x0080,     /* R2205  - EQ4MIX Input 3 Volume */
+       [0x089E] = 0x0000,     /* R2206  - EQ4MIX Input 4 Source */
+       [0x089F] = 0x0080,     /* R2207  - EQ4MIX Input 4 Volume */
+       [0x08C0] = 0x0000,     /* R2240  - DRC1LMIX Input 1 Source */
+       [0x08C1] = 0x0080,     /* R2241  - DRC1LMIX Input 1 Volume */
+       [0x08C2] = 0x0000,     /* R2242  - DRC1LMIX Input 2 Source */
+       [0x08C3] = 0x0080,     /* R2243  - DRC1LMIX Input 2 Volume */
+       [0x08C4] = 0x0000,     /* R2244  - DRC1LMIX Input 3 Source */
+       [0x08C5] = 0x0080,     /* R2245  - DRC1LMIX Input 3 Volume */
+       [0x08C6] = 0x0000,     /* R2246  - DRC1LMIX Input 4 Source */
+       [0x08C7] = 0x0080,     /* R2247  - DRC1LMIX Input 4 Volume */
+       [0x08C8] = 0x0000,     /* R2248  - DRC1RMIX Input 1 Source */
+       [0x08C9] = 0x0080,     /* R2249  - DRC1RMIX Input 1 Volume */
+       [0x08CA] = 0x0000,     /* R2250  - DRC1RMIX Input 2 Source */
+       [0x08CB] = 0x0080,     /* R2251  - DRC1RMIX Input 2 Volume */
+       [0x08CC] = 0x0000,     /* R2252  - DRC1RMIX Input 3 Source */
+       [0x08CD] = 0x0080,     /* R2253  - DRC1RMIX Input 3 Volume */
+       [0x08CE] = 0x0000,     /* R2254  - DRC1RMIX Input 4 Source */
+       [0x08CF] = 0x0080,     /* R2255  - DRC1RMIX Input 4 Volume */
+       [0x0900] = 0x0000,     /* R2304  - HPLP1MIX Input 1 Source */
+       [0x0901] = 0x0080,     /* R2305  - HPLP1MIX Input 1 Volume */
+       [0x0902] = 0x0000,     /* R2306  - HPLP1MIX Input 2 Source */
+       [0x0903] = 0x0080,     /* R2307  - HPLP1MIX Input 2 Volume */
+       [0x0904] = 0x0000,     /* R2308  - HPLP1MIX Input 3 Source */
+       [0x0905] = 0x0080,     /* R2309  - HPLP1MIX Input 3 Volume */
+       [0x0906] = 0x0000,     /* R2310  - HPLP1MIX Input 4 Source */
+       [0x0907] = 0x0080,     /* R2311  - HPLP1MIX Input 4 Volume */
+       [0x0908] = 0x0000,     /* R2312  - HPLP2MIX Input 1 Source */
+       [0x0909] = 0x0080,     /* R2313  - HPLP2MIX Input 1 Volume */
+       [0x090A] = 0x0000,     /* R2314  - HPLP2MIX Input 2 Source */
+       [0x090B] = 0x0080,     /* R2315  - HPLP2MIX Input 2 Volume */
+       [0x090C] = 0x0000,     /* R2316  - HPLP2MIX Input 3 Source */
+       [0x090D] = 0x0080,     /* R2317  - HPLP2MIX Input 3 Volume */
+       [0x090E] = 0x0000,     /* R2318  - HPLP2MIX Input 4 Source */
+       [0x090F] = 0x0080,     /* R2319  - HPLP2MIX Input 4 Volume */
+       [0x0910] = 0x0000,     /* R2320  - HPLP3MIX Input 1 Source */
+       [0x0911] = 0x0080,     /* R2321  - HPLP3MIX Input 1 Volume */
+       [0x0912] = 0x0000,     /* R2322  - HPLP3MIX Input 2 Source */
+       [0x0913] = 0x0080,     /* R2323  - HPLP3MIX Input 2 Volume */
+       [0x0914] = 0x0000,     /* R2324  - HPLP3MIX Input 3 Source */
+       [0x0915] = 0x0080,     /* R2325  - HPLP3MIX Input 3 Volume */
+       [0x0916] = 0x0000,     /* R2326  - HPLP3MIX Input 4 Source */
+       [0x0917] = 0x0080,     /* R2327  - HPLP3MIX Input 4 Volume */
+       [0x0918] = 0x0000,     /* R2328  - HPLP4MIX Input 1 Source */
+       [0x0919] = 0x0080,     /* R2329  - HPLP4MIX Input 1 Volume */
+       [0x091A] = 0x0000,     /* R2330  - HPLP4MIX Input 2 Source */
+       [0x091B] = 0x0080,     /* R2331  - HPLP4MIX Input 2 Volume */
+       [0x091C] = 0x0000,     /* R2332  - HPLP4MIX Input 3 Source */
+       [0x091D] = 0x0080,     /* R2333  - HPLP4MIX Input 3 Volume */
+       [0x091E] = 0x0000,     /* R2334  - HPLP4MIX Input 4 Source */
+       [0x091F] = 0x0080,     /* R2335  - HPLP4MIX Input 4 Volume */
+       [0x0940] = 0x0000,     /* R2368  - DSP1LMIX Input 1 Source */
+       [0x0941] = 0x0080,     /* R2369  - DSP1LMIX Input 1 Volume */
+       [0x0942] = 0x0000,     /* R2370  - DSP1LMIX Input 2 Source */
+       [0x0943] = 0x0080,     /* R2371  - DSP1LMIX Input 2 Volume */
+       [0x0944] = 0x0000,     /* R2372  - DSP1LMIX Input 3 Source */
+       [0x0945] = 0x0080,     /* R2373  - DSP1LMIX Input 3 Volume */
+       [0x0946] = 0x0000,     /* R2374  - DSP1LMIX Input 4 Source */
+       [0x0947] = 0x0080,     /* R2375  - DSP1LMIX Input 4 Volume */
+       [0x0948] = 0x0000,     /* R2376  - DSP1RMIX Input 1 Source */
+       [0x0949] = 0x0080,     /* R2377  - DSP1RMIX Input 1 Volume */
+       [0x094A] = 0x0000,     /* R2378  - DSP1RMIX Input 2 Source */
+       [0x094B] = 0x0080,     /* R2379  - DSP1RMIX Input 2 Volume */
+       [0x094C] = 0x0000,     /* R2380  - DSP1RMIX Input 3 Source */
+       [0x094D] = 0x0080,     /* R2381  - DSP1RMIX Input 3 Volume */
+       [0x094E] = 0x0000,     /* R2382  - DSP1RMIX Input 4 Source */
+       [0x094F] = 0x0080,     /* R2383  - DSP1RMIX Input 4 Volume */
+       [0x0950] = 0x0000,     /* R2384  - DSP1AUX1MIX Input 1 Source */
+       [0x0958] = 0x0000,     /* R2392  - DSP1AUX2MIX Input 1 Source */
+       [0x0960] = 0x0000,     /* R2400  - DSP1AUX3MIX Input 1 Source */
+       [0x0968] = 0x0000,     /* R2408  - DSP1AUX4MIX Input 1 Source */
+       [0x0970] = 0x0000,     /* R2416  - DSP1AUX5MIX Input 1 Source */
+       [0x0978] = 0x0000,     /* R2424  - DSP1AUX6MIX Input 1 Source */
+       [0x0980] = 0x0000,     /* R2432  - DSP2LMIX Input 1 Source */
+       [0x0981] = 0x0080,     /* R2433  - DSP2LMIX Input 1 Volume */
+       [0x0982] = 0x0000,     /* R2434  - DSP2LMIX Input 2 Source */
+       [0x0983] = 0x0080,     /* R2435  - DSP2LMIX Input 2 Volume */
+       [0x0984] = 0x0000,     /* R2436  - DSP2LMIX Input 3 Source */
+       [0x0985] = 0x0080,     /* R2437  - DSP2LMIX Input 3 Volume */
+       [0x0986] = 0x0000,     /* R2438  - DSP2LMIX Input 4 Source */
+       [0x0987] = 0x0080,     /* R2439  - DSP2LMIX Input 4 Volume */
+       [0x0988] = 0x0000,     /* R2440  - DSP2RMIX Input 1 Source */
+       [0x0989] = 0x0080,     /* R2441  - DSP2RMIX Input 1 Volume */
+       [0x098A] = 0x0000,     /* R2442  - DSP2RMIX Input 2 Source */
+       [0x098B] = 0x0080,     /* R2443  - DSP2RMIX Input 2 Volume */
+       [0x098C] = 0x0000,     /* R2444  - DSP2RMIX Input 3 Source */
+       [0x098D] = 0x0080,     /* R2445  - DSP2RMIX Input 3 Volume */
+       [0x098E] = 0x0000,     /* R2446  - DSP2RMIX Input 4 Source */
+       [0x098F] = 0x0080,     /* R2447  - DSP2RMIX Input 4 Volume */
+       [0x0990] = 0x0000,     /* R2448  - DSP2AUX1MIX Input 1 Source */
+       [0x0998] = 0x0000,     /* R2456  - DSP2AUX2MIX Input 1 Source */
+       [0x09A0] = 0x0000,     /* R2464  - DSP2AUX3MIX Input 1 Source */
+       [0x09A8] = 0x0000,     /* R2472  - DSP2AUX4MIX Input 1 Source */
+       [0x09B0] = 0x0000,     /* R2480  - DSP2AUX5MIX Input 1 Source */
+       [0x09B8] = 0x0000,     /* R2488  - DSP2AUX6MIX Input 1 Source */
+       [0x09C0] = 0x0000,     /* R2496  - DSP3LMIX Input 1 Source */
+       [0x09C1] = 0x0080,     /* R2497  - DSP3LMIX Input 1 Volume */
+       [0x09C2] = 0x0000,     /* R2498  - DSP3LMIX Input 2 Source */
+       [0x09C3] = 0x0080,     /* R2499  - DSP3LMIX Input 2 Volume */
+       [0x09C4] = 0x0000,     /* R2500  - DSP3LMIX Input 3 Source */
+       [0x09C5] = 0x0080,     /* R2501  - DSP3LMIX Input 3 Volume */
+       [0x09C6] = 0x0000,     /* R2502  - DSP3LMIX Input 4 Source */
+       [0x09C7] = 0x0080,     /* R2503  - DSP3LMIX Input 4 Volume */
+       [0x09C8] = 0x0000,     /* R2504  - DSP3RMIX Input 1 Source */
+       [0x09C9] = 0x0080,     /* R2505  - DSP3RMIX Input 1 Volume */
+       [0x09CA] = 0x0000,     /* R2506  - DSP3RMIX Input 2 Source */
+       [0x09CB] = 0x0080,     /* R2507  - DSP3RMIX Input 2 Volume */
+       [0x09CC] = 0x0000,     /* R2508  - DSP3RMIX Input 3 Source */
+       [0x09CD] = 0x0080,     /* R2509  - DSP3RMIX Input 3 Volume */
+       [0x09CE] = 0x0000,     /* R2510  - DSP3RMIX Input 4 Source */
+       [0x09CF] = 0x0080,     /* R2511  - DSP3RMIX Input 4 Volume */
+       [0x09D0] = 0x0000,     /* R2512  - DSP3AUX1MIX Input 1 Source */
+       [0x09D8] = 0x0000,     /* R2520  - DSP3AUX2MIX Input 1 Source */
+       [0x09E0] = 0x0000,     /* R2528  - DSP3AUX3MIX Input 1 Source */
+       [0x09E8] = 0x0000,     /* R2536  - DSP3AUX4MIX Input 1 Source */
+       [0x09F0] = 0x0000,     /* R2544  - DSP3AUX5MIX Input 1 Source */
+       [0x09F8] = 0x0000,     /* R2552  - DSP3AUX6MIX Input 1 Source */
+       [0x0A80] = 0x0000,     /* R2688  - ASRC1LMIX Input 1 Source */
+       [0x0A88] = 0x0000,     /* R2696  - ASRC1RMIX Input 1 Source */
+       [0x0A90] = 0x0000,     /* R2704  - ASRC2LMIX Input 1 Source */
+       [0x0A98] = 0x0000,     /* R2712  - ASRC2RMIX Input 1 Source */
+       [0x0B00] = 0x0000,     /* R2816  - ISRC1DEC1MIX Input 1 Source */
+       [0x0B08] = 0x0000,     /* R2824  - ISRC1DEC2MIX Input 1 Source */
+       [0x0B10] = 0x0000,     /* R2832  - ISRC1DEC3MIX Input 1 Source */
+       [0x0B18] = 0x0000,     /* R2840  - ISRC1DEC4MIX Input 1 Source */
+       [0x0B20] = 0x0000,     /* R2848  - ISRC1INT1MIX Input 1 Source */
+       [0x0B28] = 0x0000,     /* R2856  - ISRC1INT2MIX Input 1 Source */
+       [0x0B30] = 0x0000,     /* R2864  - ISRC1INT3MIX Input 1 Source */
+       [0x0B38] = 0x0000,     /* R2872  - ISRC1INT4MIX Input 1 Source */
+       [0x0B40] = 0x0000,     /* R2880  - ISRC2DEC1MIX Input 1 Source */
+       [0x0B48] = 0x0000,     /* R2888  - ISRC2DEC2MIX Input 1 Source */
+       [0x0B50] = 0x0000,     /* R2896  - ISRC2DEC3MIX Input 1 Source */
+       [0x0B58] = 0x0000,     /* R2904  - ISRC2DEC4MIX Input 1 Source */
+       [0x0B60] = 0x0000,     /* R2912  - ISRC2INT1MIX Input 1 Source */
+       [0x0B68] = 0x0000,     /* R2920  - ISRC2INT2MIX Input 1 Source */
+       [0x0B70] = 0x0000,     /* R2928  - ISRC2INT3MIX Input 1 Source */
+       [0x0B78] = 0x0000,     /* R2936  - ISRC2INT4MIX Input 1 Source */
+       [0x0C00] = 0xA001,     /* R3072  - GPIO CTRL 1 */
+       [0x0C01] = 0xA001,     /* R3073  - GPIO CTRL 2 */
+       [0x0C02] = 0xA001,     /* R3074  - GPIO CTRL 3 */
+       [0x0C03] = 0xA001,     /* R3075  - GPIO CTRL 4 */
+       [0x0C04] = 0xA001,     /* R3076  - GPIO CTRL 5 */
+       [0x0C05] = 0xA001,     /* R3077  - GPIO CTRL 6 */
+       [0x0C23] = 0x4003,     /* R3107  - Misc Pad Ctrl 1 */
+       [0x0C24] = 0x0000,     /* R3108  - Misc Pad Ctrl 2 */
+       [0x0C25] = 0x0000,     /* R3109  - Misc Pad Ctrl 3 */
+       [0x0C26] = 0x0000,     /* R3110  - Misc Pad Ctrl 4 */
+       [0x0C27] = 0x0000,     /* R3111  - Misc Pad Ctrl 5 */
+       [0x0C28] = 0x0000,     /* R3112  - Misc GPIO 1 */
+       [0x0D00] = 0x0000,     /* R3328  - Interrupt Status 1 */
+       [0x0D01] = 0x0000,     /* R3329  - Interrupt Status 2 */
+       [0x0D02] = 0x0000,     /* R3330  - Interrupt Status 3 */
+       [0x0D03] = 0x0000,     /* R3331  - Interrupt Status 4 */
+       [0x0D04] = 0x0000,     /* R3332  - Interrupt Raw Status 2 */
+       [0x0D05] = 0x0000,     /* R3333  - Interrupt Raw Status 3 */
+       [0x0D06] = 0x0000,     /* R3334  - Interrupt Raw Status 4 */
+       [0x0D07] = 0xFFFF,     /* R3335  - Interrupt Status 1 Mask */
+       [0x0D08] = 0xFFFF,     /* R3336  - Interrupt Status 2 Mask */
+       [0x0D09] = 0xFFFF,     /* R3337  - Interrupt Status 3 Mask */
+       [0x0D0A] = 0xFFFF,     /* R3338  - Interrupt Status 4 Mask */
+       [0x0D1F] = 0x0000,     /* R3359  - Interrupt Control */
+       [0x0D20] = 0xFFFF,     /* R3360  - IRQ Debounce 1 */
+       [0x0D21] = 0xFFFF,     /* R3361  - IRQ Debounce 2 */
+       [0x0E00] = 0x0000,     /* R3584  - FX_Ctrl */
+       [0x0E10] = 0x6318,     /* R3600  - EQ1_1 */
+       [0x0E11] = 0x6300,     /* R3601  - EQ1_2 */
+       [0x0E12] = 0x0FC8,     /* R3602  - EQ1_3 */
+       [0x0E13] = 0x03FE,     /* R3603  - EQ1_4 */
+       [0x0E14] = 0x00E0,     /* R3604  - EQ1_5 */
+       [0x0E15] = 0x1EC4,     /* R3605  - EQ1_6 */
+       [0x0E16] = 0xF136,     /* R3606  - EQ1_7 */
+       [0x0E17] = 0x0409,     /* R3607  - EQ1_8 */
+       [0x0E18] = 0x04CC,     /* R3608  - EQ1_9 */
+       [0x0E19] = 0x1C9B,     /* R3609  - EQ1_10 */
+       [0x0E1A] = 0xF337,     /* R3610  - EQ1_11 */
+       [0x0E1B] = 0x040B,     /* R3611  - EQ1_12 */
+       [0x0E1C] = 0x0CBB,     /* R3612  - EQ1_13 */
+       [0x0E1D] = 0x16F8,     /* R3613  - EQ1_14 */
+       [0x0E1E] = 0xF7D9,     /* R3614  - EQ1_15 */
+       [0x0E1F] = 0x040A,     /* R3615  - EQ1_16 */
+       [0x0E20] = 0x1F14,     /* R3616  - EQ1_17 */
+       [0x0E21] = 0x058C,     /* R3617  - EQ1_18 */
+       [0x0E22] = 0x0563,     /* R3618  - EQ1_19 */
+       [0x0E23] = 0x4000,     /* R3619  - EQ1_20 */
+       [0x0E26] = 0x6318,     /* R3622  - EQ2_1 */
+       [0x0E27] = 0x6300,     /* R3623  - EQ2_2 */
+       [0x0E28] = 0x0FC8,     /* R3624  - EQ2_3 */
+       [0x0E29] = 0x03FE,     /* R3625  - EQ2_4 */
+       [0x0E2A] = 0x00E0,     /* R3626  - EQ2_5 */
+       [0x0E2B] = 0x1EC4,     /* R3627  - EQ2_6 */
+       [0x0E2C] = 0xF136,     /* R3628  - EQ2_7 */
+       [0x0E2D] = 0x0409,     /* R3629  - EQ2_8 */
+       [0x0E2E] = 0x04CC,     /* R3630  - EQ2_9 */
+       [0x0E2F] = 0x1C9B,     /* R3631  - EQ2_10 */
+       [0x0E30] = 0xF337,     /* R3632  - EQ2_11 */
+       [0x0E31] = 0x040B,     /* R3633  - EQ2_12 */
+       [0x0E32] = 0x0CBB,     /* R3634  - EQ2_13 */
+       [0x0E33] = 0x16F8,     /* R3635  - EQ2_14 */
+       [0x0E34] = 0xF7D9,     /* R3636  - EQ2_15 */
+       [0x0E35] = 0x040A,     /* R3637  - EQ2_16 */
+       [0x0E36] = 0x1F14,     /* R3638  - EQ2_17 */
+       [0x0E37] = 0x058C,     /* R3639  - EQ2_18 */
+       [0x0E38] = 0x0563,     /* R3640  - EQ2_19 */
+       [0x0E39] = 0x4000,     /* R3641  - EQ2_20 */
+       [0x0E3C] = 0x6318,     /* R3644  - EQ3_1 */
+       [0x0E3D] = 0x6300,     /* R3645  - EQ3_2 */
+       [0x0E3E] = 0x0FC8,     /* R3646  - EQ3_3 */
+       [0x0E3F] = 0x03FE,     /* R3647  - EQ3_4 */
+       [0x0E40] = 0x00E0,     /* R3648  - EQ3_5 */
+       [0x0E41] = 0x1EC4,     /* R3649  - EQ3_6 */
+       [0x0E42] = 0xF136,     /* R3650  - EQ3_7 */
+       [0x0E43] = 0x0409,     /* R3651  - EQ3_8 */
+       [0x0E44] = 0x04CC,     /* R3652  - EQ3_9 */
+       [0x0E45] = 0x1C9B,     /* R3653  - EQ3_10 */
+       [0x0E46] = 0xF337,     /* R3654  - EQ3_11 */
+       [0x0E47] = 0x040B,     /* R3655  - EQ3_12 */
+       [0x0E48] = 0x0CBB,     /* R3656  - EQ3_13 */
+       [0x0E49] = 0x16F8,     /* R3657  - EQ3_14 */
+       [0x0E4A] = 0xF7D9,     /* R3658  - EQ3_15 */
+       [0x0E4B] = 0x040A,     /* R3659  - EQ3_16 */
+       [0x0E4C] = 0x1F14,     /* R3660  - EQ3_17 */
+       [0x0E4D] = 0x058C,     /* R3661  - EQ3_18 */
+       [0x0E4E] = 0x0563,     /* R3662  - EQ3_19 */
+       [0x0E4F] = 0x4000,     /* R3663  - EQ3_20 */
+       [0x0E52] = 0x6318,     /* R3666  - EQ4_1 */
+       [0x0E53] = 0x6300,     /* R3667  - EQ4_2 */
+       [0x0E54] = 0x0FC8,     /* R3668  - EQ4_3 */
+       [0x0E55] = 0x03FE,     /* R3669  - EQ4_4 */
+       [0x0E56] = 0x00E0,     /* R3670  - EQ4_5 */
+       [0x0E57] = 0x1EC4,     /* R3671  - EQ4_6 */
+       [0x0E58] = 0xF136,     /* R3672  - EQ4_7 */
+       [0x0E59] = 0x0409,     /* R3673  - EQ4_8 */
+       [0x0E5A] = 0x04CC,     /* R3674  - EQ4_9 */
+       [0x0E5B] = 0x1C9B,     /* R3675  - EQ4_10 */
+       [0x0E5C] = 0xF337,     /* R3676  - EQ4_11 */
+       [0x0E5D] = 0x040B,     /* R3677  - EQ4_12 */
+       [0x0E5E] = 0x0CBB,     /* R3678  - EQ4_13 */
+       [0x0E5F] = 0x16F8,     /* R3679  - EQ4_14 */
+       [0x0E60] = 0xF7D9,     /* R3680  - EQ4_15 */
+       [0x0E61] = 0x040A,     /* R3681  - EQ4_16 */
+       [0x0E62] = 0x1F14,     /* R3682  - EQ4_17 */
+       [0x0E63] = 0x058C,     /* R3683  - EQ4_18 */
+       [0x0E64] = 0x0563,     /* R3684  - EQ4_19 */
+       [0x0E65] = 0x4000,     /* R3685  - EQ4_20 */
+       [0x0E80] = 0x0018,     /* R3712  - DRC1 ctrl1 */
+       [0x0E81] = 0x0933,     /* R3713  - DRC1 ctrl2 */
+       [0x0E82] = 0x0018,     /* R3714  - DRC1 ctrl3 */
+       [0x0E83] = 0x0000,     /* R3715  - DRC1 ctrl4 */
+       [0x0E84] = 0x0000,     /* R3716  - DRC1 ctrl5 */
+       [0x0EC0] = 0x0000,     /* R3776  - HPLPF1_1 */
+       [0x0EC1] = 0x0000,     /* R3777  - HPLPF1_2 */
+       [0x0EC4] = 0x0000,     /* R3780  - HPLPF2_1 */
+       [0x0EC5] = 0x0000,     /* R3781  - HPLPF2_2 */
+       [0x0EC8] = 0x0000,     /* R3784  - HPLPF3_1 */
+       [0x0EC9] = 0x0000,     /* R3785  - HPLPF3_2 */
+       [0x0ECC] = 0x0000,     /* R3788  - HPLPF4_1 */
+       [0x0ECD] = 0x0000,     /* R3789  - HPLPF4_2 */
+       [0x4000] = 0x0000,     /* R16384 - DSP1 DM 0 */
+       [0x4001] = 0x0000,     /* R16385 - DSP1 DM 1 */
+       [0x4002] = 0x0000,     /* R16386 - DSP1 DM 2 */
+       [0x4003] = 0x0000,     /* R16387 - DSP1 DM 3 */
+       [0x41FC] = 0x0000,     /* R16892 - DSP1 DM 508 */
+       [0x41FD] = 0x0000,     /* R16893 - DSP1 DM 509 */
+       [0x41FE] = 0x0000,     /* R16894 - DSP1 DM 510 */
+       [0x41FF] = 0x0000,     /* R16895 - DSP1 DM 511 */
+       [0x4800] = 0x0000,     /* R18432 - DSP1 PM 0 */
+       [0x4801] = 0x0000,     /* R18433 - DSP1 PM 1 */
+       [0x4802] = 0x0000,     /* R18434 - DSP1 PM 2 */
+       [0x4803] = 0x0000,     /* R18435 - DSP1 PM 3 */
+       [0x4804] = 0x0000,     /* R18436 - DSP1 PM 4 */
+       [0x4805] = 0x0000,     /* R18437 - DSP1 PM 5 */
+       [0x4DFA] = 0x0000,     /* R19962 - DSP1 PM 1530 */
+       [0x4DFB] = 0x0000,     /* R19963 - DSP1 PM 1531 */
+       [0x4DFC] = 0x0000,     /* R19964 - DSP1 PM 1532 */
+       [0x4DFD] = 0x0000,     /* R19965 - DSP1 PM 1533 */
+       [0x4DFE] = 0x0000,     /* R19966 - DSP1 PM 1534 */
+       [0x4DFF] = 0x0000,     /* R19967 - DSP1 PM 1535 */
+       [0x5000] = 0x0000,     /* R20480 - DSP1 ZM 0 */
+       [0x5001] = 0x0000,     /* R20481 - DSP1 ZM 1 */
+       [0x5002] = 0x0000,     /* R20482 - DSP1 ZM 2 */
+       [0x5003] = 0x0000,     /* R20483 - DSP1 ZM 3 */
+       [0x57FC] = 0x0000,     /* R22524 - DSP1 ZM 2044 */
+       [0x57FD] = 0x0000,     /* R22525 - DSP1 ZM 2045 */
+       [0x57FE] = 0x0000,     /* R22526 - DSP1 ZM 2046 */
+       [0x57FF] = 0x0000,     /* R22527 - DSP1 ZM 2047 */
+       [0x6000] = 0x0000,     /* R24576 - DSP2 DM 0 */
+       [0x6001] = 0x0000,     /* R24577 - DSP2 DM 1 */
+       [0x6002] = 0x0000,     /* R24578 - DSP2 DM 2 */
+       [0x6003] = 0x0000,     /* R24579 - DSP2 DM 3 */
+       [0x61FC] = 0x0000,     /* R25084 - DSP2 DM 508 */
+       [0x61FD] = 0x0000,     /* R25085 - DSP2 DM 509 */
+       [0x61FE] = 0x0000,     /* R25086 - DSP2 DM 510 */
+       [0x61FF] = 0x0000,     /* R25087 - DSP2 DM 511 */
+       [0x6800] = 0x0000,     /* R26624 - DSP2 PM 0 */
+       [0x6801] = 0x0000,     /* R26625 - DSP2 PM 1 */
+       [0x6802] = 0x0000,     /* R26626 - DSP2 PM 2 */
+       [0x6803] = 0x0000,     /* R26627 - DSP2 PM 3 */
+       [0x6804] = 0x0000,     /* R26628 - DSP2 PM 4 */
+       [0x6805] = 0x0000,     /* R26629 - DSP2 PM 5 */
+       [0x6DFA] = 0x0000,     /* R28154 - DSP2 PM 1530 */
+       [0x6DFB] = 0x0000,     /* R28155 - DSP2 PM 1531 */
+       [0x6DFC] = 0x0000,     /* R28156 - DSP2 PM 1532 */
+       [0x6DFD] = 0x0000,     /* R28157 - DSP2 PM 1533 */
+       [0x6DFE] = 0x0000,     /* R28158 - DSP2 PM 1534 */
+       [0x6DFF] = 0x0000,     /* R28159 - DSP2 PM 1535 */
+       [0x7000] = 0x0000,     /* R28672 - DSP2 ZM 0 */
+       [0x7001] = 0x0000,     /* R28673 - DSP2 ZM 1 */
+       [0x7002] = 0x0000,     /* R28674 - DSP2 ZM 2 */
+       [0x7003] = 0x0000,     /* R28675 - DSP2 ZM 3 */
+       [0x77FC] = 0x0000,     /* R30716 - DSP2 ZM 2044 */
+       [0x77FD] = 0x0000,     /* R30717 - DSP2 ZM 2045 */
+       [0x77FE] = 0x0000,     /* R30718 - DSP2 ZM 2046 */
+       [0x77FF] = 0x0000,     /* R30719 - DSP2 ZM 2047 */
+       [0x8000] = 0x0000,     /* R32768 - DSP3 DM 0 */
+       [0x8001] = 0x0000,     /* R32769 - DSP3 DM 1 */
+       [0x8002] = 0x0000,     /* R32770 - DSP3 DM 2 */
+       [0x8003] = 0x0000,     /* R32771 - DSP3 DM 3 */
+       [0x81FC] = 0x0000,     /* R33276 - DSP3 DM 508 */
+       [0x81FD] = 0x0000,     /* R33277 - DSP3 DM 509 */
+       [0x81FE] = 0x0000,     /* R33278 - DSP3 DM 510 */
+       [0x81FF] = 0x0000,     /* R33279 - DSP3 DM 511 */
+       [0x8800] = 0x0000,     /* R34816 - DSP3 PM 0 */
+       [0x8801] = 0x0000,     /* R34817 - DSP3 PM 1 */
+       [0x8802] = 0x0000,     /* R34818 - DSP3 PM 2 */
+       [0x8803] = 0x0000,     /* R34819 - DSP3 PM 3 */
+       [0x8804] = 0x0000,     /* R34820 - DSP3 PM 4 */
+       [0x8805] = 0x0000,     /* R34821 - DSP3 PM 5 */
+       [0x8DFA] = 0x0000,     /* R36346 - DSP3 PM 1530 */
+       [0x8DFB] = 0x0000,     /* R36347 - DSP3 PM 1531 */
+       [0x8DFC] = 0x0000,     /* R36348 - DSP3 PM 1532 */
+       [0x8DFD] = 0x0000,     /* R36349 - DSP3 PM 1533 */
+       [0x8DFE] = 0x0000,     /* R36350 - DSP3 PM 1534 */
+       [0x8DFF] = 0x0000,     /* R36351 - DSP3 PM 1535 */
+       [0x9000] = 0x0000,     /* R36864 - DSP3 ZM 0 */
+       [0x9001] = 0x0000,     /* R36865 - DSP3 ZM 1 */
+       [0x9002] = 0x0000,     /* R36866 - DSP3 ZM 2 */
+       [0x9003] = 0x0000,     /* R36867 - DSP3 ZM 3 */
+       [0x97FC] = 0x0000,     /* R38908 - DSP3 ZM 2044 */
+       [0x97FD] = 0x0000,     /* R38909 - DSP3 ZM 2045 */
+       [0x97FE] = 0x0000,     /* R38910 - DSP3 ZM 2046 */
+       [0x97FF] = 0x0000      /* R38911 - DSP3 ZM 2047 */
+};
diff --git a/sound/soc/codecs/wm5100.c b/sound/soc/codecs/wm5100.c
new file mode 100644 (file)
index 0000000..5d88c99
--- /dev/null
@@ -0,0 +1,2809 @@
+/*
+ * wm5100.c  --  WM5100 ALSA SoC Audio driver
+ *
+ * Copyright 2011 Wolfson Microelectronics plc
+ *
+ * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/pm.h>
+#include <linux/gcd.h>
+#include <linux/gpio.h>
+#include <linux/i2c.h>
+#include <linux/platform_device.h>
+#include <linux/regulator/consumer.h>
+#include <linux/regulator/fixed.h>
+#include <linux/slab.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/jack.h>
+#include <sound/initval.h>
+#include <sound/tlv.h>
+#include <sound/wm5100.h>
+
+#include "wm5100.h"
+
+#define WM5100_NUM_CORE_SUPPLIES 2
+static const char *wm5100_core_supply_names[WM5100_NUM_CORE_SUPPLIES] = {
+       "DBVDD1",
+       "LDOVDD", /* If DCVDD is supplied externally specify as LDOVDD */
+};
+
+#define WM5100_AIFS     3
+#define WM5100_SYNC_SRS 3
+
+struct wm5100_fll {
+       int fref;
+       int fout;
+       int src;
+       struct completion lock;
+};
+
+/* codec private data */
+struct wm5100_priv {
+       struct snd_soc_codec *codec;
+
+       struct regulator_bulk_data core_supplies[WM5100_NUM_CORE_SUPPLIES];
+       struct regulator *cpvdd;
+       struct regulator *dbvdd2;
+       struct regulator *dbvdd3;
+
+       int rev;
+
+       int sysclk;
+       int asyncclk;
+
+       bool aif_async[WM5100_AIFS];
+       bool aif_symmetric[WM5100_AIFS];
+       int sr_ref[WM5100_SYNC_SRS];
+
+       bool out_ena[2];
+
+       struct snd_soc_jack *jack;
+       bool jack_detecting;
+       bool jack_mic;
+       int jack_mode;
+
+       struct wm5100_fll fll[2];
+
+       struct wm5100_pdata pdata;
+
+#ifdef CONFIG_GPIOLIB
+       struct gpio_chip gpio_chip;
+#endif
+};
+
+static int wm5100_sr_code[] = {
+       0,
+       12000,
+       24000,
+       48000,
+       96000,
+       192000,
+       384000,
+       768000,
+       0,
+       11025,
+       22050,
+       44100,
+       88200,
+       176400,
+       352800,
+       705600,
+       4000,
+       8000,
+       16000,
+       32000,
+       64000,
+       128000,
+       256000,
+       512000,
+};
+
+static int wm5100_sr_regs[WM5100_SYNC_SRS] = {
+       WM5100_CLOCKING_4,
+       WM5100_CLOCKING_5,
+       WM5100_CLOCKING_6,
+};
+
+static int wm5100_alloc_sr(struct snd_soc_codec *codec, int rate)
+{
+       struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
+       int sr_code, sr_free, i;
+
+       for (i = 0; i < ARRAY_SIZE(wm5100_sr_code); i++)
+               if (wm5100_sr_code[i] == rate)
+                       break;
+       if (i == ARRAY_SIZE(wm5100_sr_code)) {
+               dev_err(codec->dev, "Unsupported sample rate: %dHz\n", rate);
+               return -EINVAL;
+       }
+       sr_code = i;
+
+       if ((wm5100->sysclk % rate) == 0) {
+               /* Is this rate already in use? */
+               sr_free = -1;
+               for (i = 0; i < ARRAY_SIZE(wm5100_sr_regs); i++) {
+                       if (!wm5100->sr_ref[i] && sr_free == -1) {
+                               sr_free = i;
+                               continue;
+                       }
+                       if ((snd_soc_read(codec, wm5100_sr_regs[i]) &
+                            WM5100_SAMPLE_RATE_1_MASK) == sr_code)
+                               break;
+               }
+
+               if (i < ARRAY_SIZE(wm5100_sr_regs)) {
+                       wm5100->sr_ref[i]++;
+                       dev_dbg(codec->dev, "SR %dHz, slot %d, ref %d\n",
+                               rate, i, wm5100->sr_ref[i]);
+                       return i;
+               }
+
+               if (sr_free == -1) {
+                       dev_err(codec->dev, "All SR slots already in use\n");
+                       return -EBUSY;
+               }
+
+               dev_dbg(codec->dev, "Allocating SR slot %d for %dHz\n",
+                       sr_free, rate);
+               wm5100->sr_ref[sr_free]++;
+               snd_soc_update_bits(codec, wm5100_sr_regs[sr_free],
+                                   WM5100_SAMPLE_RATE_1_MASK,
+                                   sr_code);
+
+               return sr_free;
+
+       } else {
+               dev_err(codec->dev,
+                       "SR %dHz incompatible with %dHz SYSCLK and %dHz ASYNCCLK\n",
+                       rate, wm5100->sysclk, wm5100->asyncclk);
+               return -EINVAL;
+       }
+}
+
+static void wm5100_free_sr(struct snd_soc_codec *codec, int rate)
+{
+       struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
+       int i, sr_code;
+
+       for (i = 0; i < ARRAY_SIZE(wm5100_sr_code); i++)
+               if (wm5100_sr_code[i] == rate)
+                       break;
+       if (i == ARRAY_SIZE(wm5100_sr_code)) {
+               dev_err(codec->dev, "Unsupported sample rate: %dHz\n", rate);
+               return;
+       }
+       sr_code = wm5100_sr_code[i];
+
+       for (i = 0; i < ARRAY_SIZE(wm5100_sr_regs); i++) {
+               if (!wm5100->sr_ref[i])
+                       continue;
+
+               if ((snd_soc_read(codec, wm5100_sr_regs[i]) &
+                    WM5100_SAMPLE_RATE_1_MASK) == sr_code)
+                       break;
+       }
+       if (i < ARRAY_SIZE(wm5100_sr_regs)) {
+               wm5100->sr_ref[i]--;
+               dev_dbg(codec->dev, "Dereference SR %dHz, count now %d\n",
+                       rate, wm5100->sr_ref[i]);
+       } else {
+               dev_warn(codec->dev, "Freeing unreferenced sample rate %dHz\n",
+                        rate);
+       }
+}
+
+static int wm5100_reset(struct snd_soc_codec *codec)
+{
+       struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
+
+       if (wm5100->pdata.reset) {
+               gpio_set_value_cansleep(wm5100->pdata.reset, 0);
+               gpio_set_value_cansleep(wm5100->pdata.reset, 1);
+
+               return 0;
+       } else {
+               return snd_soc_write(codec, WM5100_SOFTWARE_RESET, 0);
+       }
+}
+
+static DECLARE_TLV_DB_SCALE(in_tlv, -6300, 100, 0);
+static DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
+static DECLARE_TLV_DB_SCALE(mixer_tlv, -3200, 100, 0);
+static DECLARE_TLV_DB_SCALE(out_tlv, -6400, 100, 0);
+static DECLARE_TLV_DB_SCALE(digital_tlv, -6400, 50, 0);
+
+static const char *wm5100_mixer_texts[] = {
+       "None",
+       "Tone Generator 1",
+       "Tone Generator 2",
+       "AEC loopback",
+       "IN1L",
+       "IN1R",
+       "IN2L",
+       "IN2R",
+       "IN3L",
+       "IN3R",
+       "IN4L",
+       "IN4R",
+       "AIF1RX1",
+       "AIF1RX2",
+       "AIF1RX3",
+       "AIF1RX4",
+       "AIF1RX5",
+       "AIF1RX6",
+       "AIF1RX7",
+       "AIF1RX8",
+       "AIF2RX1",
+       "AIF2RX2",
+       "AIF3RX1",
+       "AIF3RX2",
+       "EQ1",
+       "EQ2",
+       "EQ3",
+       "EQ4",
+       "DRC1L",
+       "DRC1R",
+       "LHPF1",
+       "LHPF2",
+       "LHPF3",
+       "LHPF4",
+       "DSP1.1",
+       "DSP1.2",
+       "DSP1.3",
+       "DSP1.4",
+       "DSP1.5",
+       "DSP1.6",
+       "DSP2.1",
+       "DSP2.2",
+       "DSP2.3",
+       "DSP2.4",
+       "DSP2.5",
+       "DSP2.6",
+       "DSP3.1",
+       "DSP3.2",
+       "DSP3.3",
+       "DSP3.4",
+       "DSP3.5",
+       "DSP3.6",
+       "ASRC1L",
+       "ASRC1R",
+       "ASRC2L",
+       "ASRC2R",
+       "ISRC1INT1",
+       "ISRC1INT2",
+       "ISRC1INT3",
+       "ISRC1INT4",
+       "ISRC2INT1",
+       "ISRC2INT2",
+       "ISRC2INT3",
+       "ISRC2INT4",
+       "ISRC1DEC1",
+       "ISRC1DEC2",
+       "ISRC1DEC3",
+       "ISRC1DEC4",
+       "ISRC2DEC1",
+       "ISRC2DEC2",
+       "ISRC2DEC3",
+       "ISRC2DEC4",
+};
+
+static int wm5100_mixer_values[] = {
+       0x00,
+       0x04,   /* Tone */
+       0x05,
+       0x08,   /* AEC */
+       0x10,   /* Input */
+       0x11,
+       0x12,
+       0x13,
+       0x14,
+       0x15,
+       0x16,
+       0x17,
+       0x20,   /* AIF */
+       0x21,
+       0x22,
+       0x23,
+       0x24,
+       0x25,
+       0x26,
+       0x27,
+       0x28,
+       0x29,
+       0x30,   /* AIF3 - check */
+       0x31,
+       0x50,   /* EQ */
+       0x51,
+       0x52,
+       0x53,
+       0x54,
+       0x58,   /* DRC */
+       0x59,
+       0x60,   /* LHPF1 */
+       0x61,   /* LHPF2 */
+       0x62,   /* LHPF3 */
+       0x63,   /* LHPF4 */
+       0x68,   /* DSP1 */
+       0x69,
+       0x6a,
+       0x6b,
+       0x6c,
+       0x6d,
+       0x70,   /* DSP2 */
+       0x71,
+       0x72,
+       0x73,
+       0x74,
+       0x75,
+       0x78,   /* DSP3 */
+       0x79,
+       0x7a,
+       0x7b,
+       0x7c,
+       0x7d,
+       0x90,   /* ASRC1 */
+       0x91,
+       0x92,   /* ASRC2 */
+       0x93,
+       0xa0,   /* ISRC1DEC1 */
+       0xa1,
+       0xa2,
+       0xa3,
+       0xa4,   /* ISRC1INT1 */
+       0xa5,
+       0xa6,
+       0xa7,
+       0xa8,   /* ISRC2DEC1 */
+       0xa9,
+       0xaa,
+       0xab,
+       0xac,   /* ISRC2INT1 */
+       0xad,
+       0xae,
+       0xaf,
+};
+
+#define WM5100_MIXER_CONTROLS(name, base) \
+       SOC_SINGLE_TLV(name " Input 1 Volume", base + 1 , \
+                      WM5100_MIXER_VOL_SHIFT, 80, 0, mixer_tlv), \
+       SOC_SINGLE_TLV(name " Input 2 Volume", base + 3 , \
+                      WM5100_MIXER_VOL_SHIFT, 80, 0, mixer_tlv), \
+       SOC_SINGLE_TLV(name " Input 3 Volume", base + 5 , \
+                      WM5100_MIXER_VOL_SHIFT, 80, 0, mixer_tlv), \
+       SOC_SINGLE_TLV(name " Input 4 Volume", base + 7 , \
+                      WM5100_MIXER_VOL_SHIFT, 80, 0, mixer_tlv)
+
+#define WM5100_MUX_ENUM_DECL(name, reg) \
+       SOC_VALUE_ENUM_SINGLE_DECL(name, reg, 0, 0xff,                  \
+                                  wm5100_mixer_texts, wm5100_mixer_values)
+
+#define WM5100_MUX_CTL_DECL(name) \
+       const struct snd_kcontrol_new name##_mux =      \
+               SOC_DAPM_VALUE_ENUM("Route", name##_enum)
+
+#define WM5100_MIXER_ENUMS(name, base_reg) \
+       static WM5100_MUX_ENUM_DECL(name##_in1_enum, base_reg);      \
+       static WM5100_MUX_ENUM_DECL(name##_in2_enum, base_reg + 2);  \
+       static WM5100_MUX_ENUM_DECL(name##_in3_enum, base_reg + 4);  \
+       static WM5100_MUX_ENUM_DECL(name##_in4_enum, base_reg + 6);  \
+       static WM5100_MUX_CTL_DECL(name##_in1); \
+       static WM5100_MUX_CTL_DECL(name##_in2); \
+       static WM5100_MUX_CTL_DECL(name##_in3); \
+       static WM5100_MUX_CTL_DECL(name##_in4) 
+
+WM5100_MIXER_ENUMS(HPOUT1L, WM5100_OUT1LMIX_INPUT_1_SOURCE);
+WM5100_MIXER_ENUMS(HPOUT1R, WM5100_OUT1RMIX_INPUT_1_SOURCE);
+WM5100_MIXER_ENUMS(HPOUT2L, WM5100_OUT2LMIX_INPUT_1_SOURCE);
+WM5100_MIXER_ENUMS(HPOUT2R, WM5100_OUT2RMIX_INPUT_1_SOURCE);
+WM5100_MIXER_ENUMS(HPOUT3L, WM5100_OUT3LMIX_INPUT_1_SOURCE);
+WM5100_MIXER_ENUMS(HPOUT3R, WM5100_OUT3RMIX_INPUT_1_SOURCE);
+
+WM5100_MIXER_ENUMS(SPKOUTL, WM5100_OUT4LMIX_INPUT_1_SOURCE);
+WM5100_MIXER_ENUMS(SPKOUTR, WM5100_OUT4RMIX_INPUT_1_SOURCE);
+WM5100_MIXER_ENUMS(SPKDAT1L, WM5100_OUT5LMIX_INPUT_1_SOURCE);
+WM5100_MIXER_ENUMS(SPKDAT1R, WM5100_OUT5RMIX_INPUT_1_SOURCE);
+WM5100_MIXER_ENUMS(SPKDAT2L, WM5100_OUT6LMIX_INPUT_1_SOURCE);
+WM5100_MIXER_ENUMS(SPKDAT2R, WM5100_OUT6RMIX_INPUT_1_SOURCE);
+
+WM5100_MIXER_ENUMS(PWM1, WM5100_PWM1MIX_INPUT_1_SOURCE);
+WM5100_MIXER_ENUMS(PWM2, WM5100_PWM1MIX_INPUT_1_SOURCE);
+
+WM5100_MIXER_ENUMS(AIF1TX1, WM5100_AIF1TX1MIX_INPUT_1_SOURCE);
+WM5100_MIXER_ENUMS(AIF1TX2, WM5100_AIF1TX2MIX_INPUT_1_SOURCE);
+WM5100_MIXER_ENUMS(AIF1TX3, WM5100_AIF1TX3MIX_INPUT_1_SOURCE);
+WM5100_MIXER_ENUMS(AIF1TX4, WM5100_AIF1TX4MIX_INPUT_1_SOURCE);
+WM5100_MIXER_ENUMS(AIF1TX5, WM5100_AIF1TX5MIX_INPUT_1_SOURCE);
+WM5100_MIXER_ENUMS(AIF1TX6, WM5100_AIF1TX6MIX_INPUT_1_SOURCE);
+WM5100_MIXER_ENUMS(AIF1TX7, WM5100_AIF1TX7MIX_INPUT_1_SOURCE);
+WM5100_MIXER_ENUMS(AIF1TX8, WM5100_AIF1TX8MIX_INPUT_1_SOURCE);
+
+WM5100_MIXER_ENUMS(AIF2TX1, WM5100_AIF2TX1MIX_INPUT_1_SOURCE);
+WM5100_MIXER_ENUMS(AIF2TX2, WM5100_AIF2TX2MIX_INPUT_1_SOURCE);
+
+WM5100_MIXER_ENUMS(AIF3TX1, WM5100_AIF1TX1MIX_INPUT_1_SOURCE);
+WM5100_MIXER_ENUMS(AIF3TX2, WM5100_AIF1TX2MIX_INPUT_1_SOURCE);
+
+WM5100_MIXER_ENUMS(EQ1, WM5100_EQ1MIX_INPUT_1_SOURCE);
+WM5100_MIXER_ENUMS(EQ2, WM5100_EQ2MIX_INPUT_1_SOURCE);
+WM5100_MIXER_ENUMS(EQ3, WM5100_EQ3MIX_INPUT_1_SOURCE);
+WM5100_MIXER_ENUMS(EQ4, WM5100_EQ4MIX_INPUT_1_SOURCE);
+
+WM5100_MIXER_ENUMS(DRC1L, WM5100_DRC1LMIX_INPUT_1_SOURCE);
+WM5100_MIXER_ENUMS(DRC1R, WM5100_DRC1RMIX_INPUT_1_SOURCE);
+
+WM5100_MIXER_ENUMS(LHPF1, WM5100_HPLP1MIX_INPUT_1_SOURCE);
+WM5100_MIXER_ENUMS(LHPF2, WM5100_HPLP2MIX_INPUT_1_SOURCE);
+WM5100_MIXER_ENUMS(LHPF3, WM5100_HPLP3MIX_INPUT_1_SOURCE);
+WM5100_MIXER_ENUMS(LHPF4, WM5100_HPLP4MIX_INPUT_1_SOURCE);
+
+#define WM5100_MUX(name, ctrl) \
+       SND_SOC_DAPM_VALUE_MUX(name, SND_SOC_NOPM, 0, 0, ctrl)
+
+#define WM5100_MIXER_WIDGETS(name, name_str)   \
+       WM5100_MUX(name_str " Input 1", &name##_in1_mux), \
+       WM5100_MUX(name_str " Input 2", &name##_in2_mux), \
+       WM5100_MUX(name_str " Input 3", &name##_in3_mux), \
+       WM5100_MUX(name_str " Input 4", &name##_in4_mux), \
+       SND_SOC_DAPM_MIXER(name_str " Mixer", SND_SOC_NOPM, 0, 0, NULL, 0)
+
+#define WM5100_MIXER_INPUT_ROUTES(name)        \
+       { name, "Tone Generator 1", "Tone Generator 1" }, \
+        { name, "Tone Generator 2", "Tone Generator 2" }, \
+        { name, "IN1L", "IN1L PGA" }, \
+        { name, "IN1R", "IN1R PGA" }, \
+        { name, "IN2L", "IN2L PGA" }, \
+        { name, "IN2R", "IN2R PGA" }, \
+        { name, "IN3L", "IN3L PGA" }, \
+        { name, "IN3R", "IN3R PGA" }, \
+        { name, "IN4L", "IN4L PGA" }, \
+        { name, "IN4R", "IN4R PGA" }, \
+        { name, "AIF1RX1", "AIF1RX1" }, \
+        { name, "AIF1RX2", "AIF1RX2" }, \
+        { name, "AIF1RX3", "AIF1RX3" }, \
+        { name, "AIF1RX4", "AIF1RX4" }, \
+        { name, "AIF1RX5", "AIF1RX5" }, \
+        { name, "AIF1RX6", "AIF1RX6" }, \
+        { name, "AIF1RX7", "AIF1RX7" }, \
+        { name, "AIF1RX8", "AIF1RX8" }, \
+        { name, "AIF2RX1", "AIF2RX1" }, \
+        { name, "AIF2RX2", "AIF2RX2" }, \
+        { name, "AIF3RX1", "AIF3RX1" }, \
+        { name, "AIF3RX2", "AIF3RX2" }, \
+        { name, "EQ1", "EQ1" }, \
+        { name, "EQ2", "EQ2" }, \
+        { name, "EQ3", "EQ3" }, \
+        { name, "EQ4", "EQ4" }, \
+        { name, "DRC1L", "DRC1L" }, \
+        { name, "DRC1R", "DRC1R" }, \
+        { name, "LHPF1", "LHPF1" }, \
+        { name, "LHPF2", "LHPF2" }, \
+        { name, "LHPF3", "LHPF3" }, \
+        { name, "LHPF4", "LHPF4" }
+
+#define WM5100_MIXER_ROUTES(widget, name) \
+       { widget, NULL, name " Mixer" },         \
+       { name " Mixer", NULL, name " Input 1" }, \
+       { name " Mixer", NULL, name " Input 2" }, \
+       { name " Mixer", NULL, name " Input 3" }, \
+       { name " Mixer", NULL, name " Input 4" }, \
+       WM5100_MIXER_INPUT_ROUTES(name " Input 1"), \
+       WM5100_MIXER_INPUT_ROUTES(name " Input 2"), \
+       WM5100_MIXER_INPUT_ROUTES(name " Input 3"), \
+       WM5100_MIXER_INPUT_ROUTES(name " Input 4")
+
+static const char *wm5100_lhpf_mode_text[] = {
+       "Low-pass", "High-pass"
+};
+
+static const struct soc_enum wm5100_lhpf1_mode =
+       SOC_ENUM_SINGLE(WM5100_HPLPF1_1, WM5100_LHPF1_MODE_SHIFT, 2,
+                       wm5100_lhpf_mode_text);
+
+static const struct soc_enum wm5100_lhpf2_mode =
+       SOC_ENUM_SINGLE(WM5100_HPLPF2_1, WM5100_LHPF2_MODE_SHIFT, 2,
+                       wm5100_lhpf_mode_text);
+
+static const struct soc_enum wm5100_lhpf3_mode =
+       SOC_ENUM_SINGLE(WM5100_HPLPF3_1, WM5100_LHPF3_MODE_SHIFT, 2,
+                       wm5100_lhpf_mode_text);
+
+static const struct soc_enum wm5100_lhpf4_mode =
+       SOC_ENUM_SINGLE(WM5100_HPLPF4_1, WM5100_LHPF4_MODE_SHIFT, 2,
+                       wm5100_lhpf_mode_text);
+
+static const struct snd_kcontrol_new wm5100_snd_controls[] = {
+SOC_SINGLE("IN1 High Performance Switch", WM5100_IN1L_CONTROL,
+          WM5100_IN1_OSR_SHIFT, 1, 0),
+SOC_SINGLE("IN2 High Performance Switch", WM5100_IN2L_CONTROL,
+          WM5100_IN2_OSR_SHIFT, 1, 0),
+SOC_SINGLE("IN3 High Performance Switch", WM5100_IN3L_CONTROL,
+          WM5100_IN3_OSR_SHIFT, 1, 0),
+SOC_SINGLE("IN4 High Performance Switch", WM5100_IN4L_CONTROL,
+          WM5100_IN4_OSR_SHIFT, 1, 0),
+
+/* Only applicable for analogue inputs */
+SOC_DOUBLE_R_TLV("IN1 Volume", WM5100_IN1L_CONTROL, WM5100_IN1R_CONTROL,
+                WM5100_IN1L_PGA_VOL_SHIFT, 94, 0, in_tlv),
+SOC_DOUBLE_R_TLV("IN2 Volume", WM5100_IN2L_CONTROL, WM5100_IN2R_CONTROL,
+                WM5100_IN2L_PGA_VOL_SHIFT, 94, 0, in_tlv),
+SOC_DOUBLE_R_TLV("IN3 Volume", WM5100_IN3L_CONTROL, WM5100_IN3R_CONTROL,
+                WM5100_IN3L_PGA_VOL_SHIFT, 94, 0, in_tlv),
+SOC_DOUBLE_R_TLV("IN4 Volume", WM5100_IN4L_CONTROL, WM5100_IN4R_CONTROL,
+                WM5100_IN4L_PGA_VOL_SHIFT, 94, 0, in_tlv),
+
+SOC_DOUBLE_R_TLV("IN1 Digital Volume", WM5100_ADC_DIGITAL_VOLUME_1L,
+                WM5100_ADC_DIGITAL_VOLUME_1R, WM5100_IN1L_VOL_SHIFT, 191,
+                0, digital_tlv),
+SOC_DOUBLE_R_TLV("IN2 Digital Volume", WM5100_ADC_DIGITAL_VOLUME_2L,
+                WM5100_ADC_DIGITAL_VOLUME_2R, WM5100_IN2L_VOL_SHIFT, 191,
+                0, digital_tlv),
+SOC_DOUBLE_R_TLV("IN3 Digital Volume", WM5100_ADC_DIGITAL_VOLUME_3L,
+                WM5100_ADC_DIGITAL_VOLUME_3R, WM5100_IN3L_VOL_SHIFT, 191,
+                0, digital_tlv),
+SOC_DOUBLE_R_TLV("IN4 Digital Volume", WM5100_ADC_DIGITAL_VOLUME_4L,
+                WM5100_ADC_DIGITAL_VOLUME_4R, WM5100_IN4L_VOL_SHIFT, 191,
+                0, digital_tlv),
+
+SOC_DOUBLE_R("IN1 Switch", WM5100_ADC_DIGITAL_VOLUME_1L,
+            WM5100_ADC_DIGITAL_VOLUME_1R, WM5100_IN1L_MUTE_SHIFT, 1, 1),
+SOC_DOUBLE_R("IN2 Switch", WM5100_ADC_DIGITAL_VOLUME_2L,
+            WM5100_ADC_DIGITAL_VOLUME_2R, WM5100_IN2L_MUTE_SHIFT, 1, 1),
+SOC_DOUBLE_R("IN3 Switch", WM5100_ADC_DIGITAL_VOLUME_3L,
+            WM5100_ADC_DIGITAL_VOLUME_3R, WM5100_IN3L_MUTE_SHIFT, 1, 1),
+SOC_DOUBLE_R("IN4 Switch", WM5100_ADC_DIGITAL_VOLUME_4L,
+            WM5100_ADC_DIGITAL_VOLUME_4R, WM5100_IN4L_MUTE_SHIFT, 1, 1),
+
+SOC_SINGLE("HPOUT1 High Performance Switch", WM5100_OUT_VOLUME_1L,
+          WM5100_OUT1_OSR_SHIFT, 1, 0),
+SOC_SINGLE("HPOUT2 High Performance Switch", WM5100_OUT_VOLUME_2L,
+          WM5100_OUT2_OSR_SHIFT, 1, 0),
+SOC_SINGLE("HPOUT3 High Performance Switch", WM5100_OUT_VOLUME_3L,
+          WM5100_OUT3_OSR_SHIFT, 1, 0),
+SOC_SINGLE("SPKOUT High Performance Switch", WM5100_OUT_VOLUME_4L,
+          WM5100_OUT4_OSR_SHIFT, 1, 0),
+SOC_SINGLE("SPKDAT1 High Performance Switch", WM5100_DAC_VOLUME_LIMIT_5L,
+          WM5100_OUT5_OSR_SHIFT, 1, 0),
+SOC_SINGLE("SPKDAT2 High Performance Switch", WM5100_DAC_VOLUME_LIMIT_6L,
+          WM5100_OUT6_OSR_SHIFT, 1, 0),
+
+SOC_DOUBLE_R_TLV("HPOUT1 Digital Volume", WM5100_DAC_DIGITAL_VOLUME_1L,
+                WM5100_DAC_DIGITAL_VOLUME_1R, WM5100_OUT1L_VOL_SHIFT, 159, 0,
+                digital_tlv),
+SOC_DOUBLE_R_TLV("HPOUT2 Digital Volume", WM5100_DAC_DIGITAL_VOLUME_2L,
+                WM5100_DAC_DIGITAL_VOLUME_2R, WM5100_OUT2L_VOL_SHIFT, 159, 0,
+                digital_tlv),
+SOC_DOUBLE_R_TLV("HPOUT3 Digital Volume", WM5100_DAC_DIGITAL_VOLUME_3L,
+                WM5100_DAC_DIGITAL_VOLUME_3R, WM5100_OUT3L_VOL_SHIFT, 159, 0,
+                digital_tlv),
+SOC_DOUBLE_R_TLV("SPKOUT Digital Volume", WM5100_DAC_DIGITAL_VOLUME_4L,
+                WM5100_DAC_DIGITAL_VOLUME_4R, WM5100_OUT4L_VOL_SHIFT, 159, 0,
+                digital_tlv),
+SOC_DOUBLE_R_TLV("SPKDAT1 Digital Volume", WM5100_DAC_DIGITAL_VOLUME_5L,
+                WM5100_DAC_DIGITAL_VOLUME_5R, WM5100_OUT5L_VOL_SHIFT, 159, 0,
+                digital_tlv),
+SOC_DOUBLE_R_TLV("SPKDAT2 Digital Volume", WM5100_DAC_DIGITAL_VOLUME_6L,
+                WM5100_DAC_DIGITAL_VOLUME_6R, WM5100_OUT6L_VOL_SHIFT, 159, 0,
+                digital_tlv),
+
+SOC_DOUBLE_R("HPOUT1 Digital Switch", WM5100_DAC_DIGITAL_VOLUME_1L,
+            WM5100_DAC_DIGITAL_VOLUME_1R, WM5100_OUT1L_MUTE_SHIFT, 1, 1),
+SOC_DOUBLE_R("HPOUT2 Digital Switch", WM5100_DAC_DIGITAL_VOLUME_2L,
+            WM5100_DAC_DIGITAL_VOLUME_2R, WM5100_OUT2L_MUTE_SHIFT, 1, 1),
+SOC_DOUBLE_R("HPOUT3 Digital Switch", WM5100_DAC_DIGITAL_VOLUME_3L,
+            WM5100_DAC_DIGITAL_VOLUME_3R, WM5100_OUT3L_MUTE_SHIFT, 1, 1),
+SOC_DOUBLE_R("SPKOUT Digital Switch", WM5100_DAC_DIGITAL_VOLUME_4L,
+            WM5100_DAC_DIGITAL_VOLUME_4R, WM5100_OUT4L_MUTE_SHIFT, 1, 1),
+SOC_DOUBLE_R("SPKDAT1 Digital Switch", WM5100_DAC_DIGITAL_VOLUME_5L,
+            WM5100_DAC_DIGITAL_VOLUME_5R, WM5100_OUT5L_MUTE_SHIFT, 1, 1),
+SOC_DOUBLE_R("SPKDAT2 Digital Switch", WM5100_DAC_DIGITAL_VOLUME_6L,
+            WM5100_DAC_DIGITAL_VOLUME_6R, WM5100_OUT6L_MUTE_SHIFT, 1, 1),
+
+/* FIXME: Only valid from -12dB to 0dB (52-64) */
+SOC_DOUBLE_R_TLV("HPOUT1 Volume", WM5100_OUT_VOLUME_1L, WM5100_OUT_VOLUME_1R,
+                WM5100_OUT1L_PGA_VOL_SHIFT, 64, 0, out_tlv),
+SOC_DOUBLE_R_TLV("HPOUT2 Volume", WM5100_OUT_VOLUME_2L, WM5100_OUT_VOLUME_2R,
+                WM5100_OUT2L_PGA_VOL_SHIFT, 64, 0, out_tlv),
+SOC_DOUBLE_R_TLV("HPOUT3 Volume", WM5100_OUT_VOLUME_3L, WM5100_OUT_VOLUME_3R,
+                WM5100_OUT2L_PGA_VOL_SHIFT, 64, 0, out_tlv),
+
+SOC_DOUBLE("SPKDAT1 Switch", WM5100_PDM_SPK1_CTRL_1, WM5100_SPK1L_MUTE_SHIFT,
+          WM5100_SPK1R_MUTE_SHIFT, 1, 1),
+SOC_DOUBLE("SPKDAT2 Switch", WM5100_PDM_SPK2_CTRL_1, WM5100_SPK2L_MUTE_SHIFT,
+          WM5100_SPK2R_MUTE_SHIFT, 1, 1),
+
+SOC_SINGLE_TLV("EQ1 Band 1 Volume", WM5100_EQ1_1, WM5100_EQ1_B1_GAIN_SHIFT,
+              24, 0, eq_tlv),
+SOC_SINGLE_TLV("EQ1 Band 2 Volume", WM5100_EQ1_1, WM5100_EQ1_B2_GAIN_SHIFT,
+              24, 0, eq_tlv),
+SOC_SINGLE_TLV("EQ1 Band 3 Volume", WM5100_EQ1_1, WM5100_EQ1_B3_GAIN_SHIFT,
+              24, 0, eq_tlv),
+SOC_SINGLE_TLV("EQ1 Band 4 Volume", WM5100_EQ1_2, WM5100_EQ1_B4_GAIN_SHIFT,
+              24, 0, eq_tlv),
+SOC_SINGLE_TLV("EQ1 Band 5 Volume", WM5100_EQ1_2, WM5100_EQ1_B5_GAIN_SHIFT,
+              24, 0, eq_tlv),
+
+SOC_SINGLE_TLV("EQ2 Band 1 Volume", WM5100_EQ2_1, WM5100_EQ2_B1_GAIN_SHIFT,
+              24, 0, eq_tlv),
+SOC_SINGLE_TLV("EQ2 Band 2 Volume", WM5100_EQ2_1, WM5100_EQ2_B2_GAIN_SHIFT,
+              24, 0, eq_tlv),
+SOC_SINGLE_TLV("EQ2 Band 3 Volume", WM5100_EQ2_1, WM5100_EQ2_B3_GAIN_SHIFT,
+              24, 0, eq_tlv),
+SOC_SINGLE_TLV("EQ2 Band 4 Volume", WM5100_EQ2_2, WM5100_EQ2_B4_GAIN_SHIFT,
+              24, 0, eq_tlv),
+SOC_SINGLE_TLV("EQ2 Band 5 Volume", WM5100_EQ2_2, WM5100_EQ2_B5_GAIN_SHIFT,
+              24, 0, eq_tlv),
+
+SOC_SINGLE_TLV("EQ3 Band 1 Volume", WM5100_EQ1_1, WM5100_EQ3_B1_GAIN_SHIFT,
+              24, 0, eq_tlv),
+SOC_SINGLE_TLV("EQ3 Band 2 Volume", WM5100_EQ3_1, WM5100_EQ3_B2_GAIN_SHIFT,
+              24, 0, eq_tlv),
+SOC_SINGLE_TLV("EQ3 Band 3 Volume", WM5100_EQ3_1, WM5100_EQ3_B3_GAIN_SHIFT,
+              24, 0, eq_tlv),
+SOC_SINGLE_TLV("EQ3 Band 4 Volume", WM5100_EQ3_2, WM5100_EQ3_B4_GAIN_SHIFT,
+              24, 0, eq_tlv),
+SOC_SINGLE_TLV("EQ3 Band 5 Volume", WM5100_EQ3_2, WM5100_EQ3_B5_GAIN_SHIFT,
+              24, 0, eq_tlv),
+
+SOC_SINGLE_TLV("EQ4 Band 1 Volume", WM5100_EQ4_1, WM5100_EQ4_B1_GAIN_SHIFT,
+              24, 0, eq_tlv),
+SOC_SINGLE_TLV("EQ4 Band 2 Volume", WM5100_EQ4_1, WM5100_EQ4_B2_GAIN_SHIFT,
+              24, 0, eq_tlv),
+SOC_SINGLE_TLV("EQ4 Band 3 Volume", WM5100_EQ4_1, WM5100_EQ4_B3_GAIN_SHIFT,
+              24, 0, eq_tlv),
+SOC_SINGLE_TLV("EQ4 Band 4 Volume", WM5100_EQ4_2, WM5100_EQ4_B4_GAIN_SHIFT,
+              24, 0, eq_tlv),
+SOC_SINGLE_TLV("EQ4 Band 5 Volume", WM5100_EQ4_2, WM5100_EQ4_B5_GAIN_SHIFT,
+              24, 0, eq_tlv),
+
+SOC_ENUM("LHPF1 Mode", wm5100_lhpf1_mode),
+SOC_ENUM("LHPF2 Mode", wm5100_lhpf2_mode),
+SOC_ENUM("LHPF3 Mode", wm5100_lhpf3_mode),
+SOC_ENUM("LHPF4 Mode", wm5100_lhpf4_mode),
+
+WM5100_MIXER_CONTROLS("HPOUT1L", WM5100_OUT1LMIX_INPUT_1_SOURCE),
+WM5100_MIXER_CONTROLS("HPOUT1R", WM5100_OUT1RMIX_INPUT_1_SOURCE),
+WM5100_MIXER_CONTROLS("HPOUT2L", WM5100_OUT2LMIX_INPUT_1_SOURCE),
+WM5100_MIXER_CONTROLS("HPOUT2R", WM5100_OUT2RMIX_INPUT_1_SOURCE),
+WM5100_MIXER_CONTROLS("HPOUT3L", WM5100_OUT3LMIX_INPUT_1_SOURCE),
+WM5100_MIXER_CONTROLS("HPOUT3R", WM5100_OUT3RMIX_INPUT_1_SOURCE),
+
+WM5100_MIXER_CONTROLS("SPKOUTL", WM5100_OUT4LMIX_INPUT_1_SOURCE),
+WM5100_MIXER_CONTROLS("SPKOUTR", WM5100_OUT4RMIX_INPUT_1_SOURCE),
+WM5100_MIXER_CONTROLS("SPKDAT1L", WM5100_OUT5LMIX_INPUT_1_SOURCE),
+WM5100_MIXER_CONTROLS("SPKDAT1R", WM5100_OUT5RMIX_INPUT_1_SOURCE),
+WM5100_MIXER_CONTROLS("SPKDAT2L", WM5100_OUT6LMIX_INPUT_1_SOURCE),
+WM5100_MIXER_CONTROLS("SPKDAT2R", WM5100_OUT6RMIX_INPUT_1_SOURCE),
+
+WM5100_MIXER_CONTROLS("PWM1", WM5100_PWM1MIX_INPUT_1_SOURCE),
+WM5100_MIXER_CONTROLS("PWM2", WM5100_PWM2MIX_INPUT_1_SOURCE),
+
+WM5100_MIXER_CONTROLS("AIF1TX1", WM5100_AIF1TX1MIX_INPUT_1_SOURCE),
+WM5100_MIXER_CONTROLS("AIF1TX2", WM5100_AIF1TX2MIX_INPUT_1_SOURCE),
+WM5100_MIXER_CONTROLS("AIF1TX3", WM5100_AIF1TX3MIX_INPUT_1_SOURCE),
+WM5100_MIXER_CONTROLS("AIF1TX4", WM5100_AIF1TX4MIX_INPUT_1_SOURCE),
+WM5100_MIXER_CONTROLS("AIF1TX5", WM5100_AIF1TX5MIX_INPUT_1_SOURCE),
+WM5100_MIXER_CONTROLS("AIF1TX6", WM5100_AIF1TX6MIX_INPUT_1_SOURCE),
+WM5100_MIXER_CONTROLS("AIF1TX7", WM5100_AIF1TX7MIX_INPUT_1_SOURCE),
+WM5100_MIXER_CONTROLS("AIF1TX8", WM5100_AIF1TX8MIX_INPUT_1_SOURCE),
+
+WM5100_MIXER_CONTROLS("AIF2TX1", WM5100_AIF2TX1MIX_INPUT_1_SOURCE),
+WM5100_MIXER_CONTROLS("AIF2TX2", WM5100_AIF2TX2MIX_INPUT_1_SOURCE),
+
+WM5100_MIXER_CONTROLS("AIF3TX1", WM5100_AIF3TX1MIX_INPUT_1_SOURCE),
+WM5100_MIXER_CONTROLS("AIF3TX2", WM5100_AIF3TX2MIX_INPUT_1_SOURCE),
+
+WM5100_MIXER_CONTROLS("EQ1", WM5100_EQ1MIX_INPUT_1_SOURCE),
+WM5100_MIXER_CONTROLS("EQ2", WM5100_EQ2MIX_INPUT_1_SOURCE),
+WM5100_MIXER_CONTROLS("EQ3", WM5100_EQ3MIX_INPUT_1_SOURCE),
+WM5100_MIXER_CONTROLS("EQ4", WM5100_EQ4MIX_INPUT_1_SOURCE),
+
+WM5100_MIXER_CONTROLS("DRC1L", WM5100_DRC1LMIX_INPUT_1_SOURCE),
+WM5100_MIXER_CONTROLS("DRC1R", WM5100_DRC1RMIX_INPUT_1_SOURCE),
+
+WM5100_MIXER_CONTROLS("LHPF1", WM5100_HPLP1MIX_INPUT_1_SOURCE),
+WM5100_MIXER_CONTROLS("LHPF2", WM5100_HPLP2MIX_INPUT_1_SOURCE),
+WM5100_MIXER_CONTROLS("LHPF3", WM5100_HPLP3MIX_INPUT_1_SOURCE),
+WM5100_MIXER_CONTROLS("LHPF4", WM5100_HPLP4MIX_INPUT_1_SOURCE),
+};
+
+static void wm5100_seq_notifier(struct snd_soc_dapm_context *dapm,
+                               enum snd_soc_dapm_type event, int subseq)
+{
+       struct snd_soc_codec *codec = container_of(dapm,
+                                                  struct snd_soc_codec, dapm);
+       struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
+       u16 val, expect, i;
+
+       /* Wait for the outputs to flag themselves as enabled */
+       if (wm5100->out_ena[0]) {
+               expect = snd_soc_read(codec, WM5100_CHANNEL_ENABLES_1);
+               for (i = 0; i < 200; i++) {
+                       val = snd_soc_read(codec, WM5100_OUTPUT_STATUS_1);
+                       if (val == expect) {
+                               wm5100->out_ena[0] = false;
+                               break;
+                       }
+               }
+               if (i == 200) {
+                       dev_err(codec->dev, "Timeout waiting for OUTPUT1 %x\n",
+                               expect);
+               }
+       }
+
+       if (wm5100->out_ena[1]) {
+               expect = snd_soc_read(codec, WM5100_OUTPUT_ENABLES_2);
+               for (i = 0; i < 200; i++) {
+                       val = snd_soc_read(codec, WM5100_OUTPUT_STATUS_2);
+                       if (val == expect) {
+                               wm5100->out_ena[1] = false;
+                               break;
+                       }
+               }
+               if (i == 200) {
+                       dev_err(codec->dev, "Timeout waiting for OUTPUT2 %x\n",
+                               expect);
+               }
+       }
+}
+
+static int wm5100_out_ev(struct snd_soc_dapm_widget *w,
+                        struct snd_kcontrol *kcontrol,
+                        int event)
+{
+       struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(w->codec);
+
+       switch (w->reg) {
+       case WM5100_CHANNEL_ENABLES_1:
+               wm5100->out_ena[0] = true;
+               break;
+       case WM5100_OUTPUT_ENABLES_2:
+               wm5100->out_ena[0] = true;
+               break;
+       default:
+               break;
+       }
+
+       return 0;
+}
+
+static int wm5100_cp_ev(struct snd_soc_dapm_widget *w,
+                       struct snd_kcontrol *kcontrol,
+                       int event)
+{
+       struct snd_soc_codec *codec = w->codec;
+       struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
+       int ret;
+
+       switch (event) {
+       case SND_SOC_DAPM_PRE_PMU:
+               ret = regulator_enable(wm5100->cpvdd);
+               if (ret != 0) {
+                       dev_err(codec->dev, "Failed to enable CPVDD: %d\n",
+                               ret);
+                       return ret;
+               }
+               return ret;
+
+       case SND_SOC_DAPM_POST_PMD:
+               ret = regulator_disable_deferred(wm5100->cpvdd, 20);
+               if (ret != 0) {
+                       dev_err(codec->dev, "Failed to disable CPVDD: %d\n",
+                               ret);
+                       return ret;
+               }
+               return ret;
+
+       default:
+               BUG();
+               return 0;
+       }
+}
+
+static int wm5100_dbvdd_ev(struct snd_soc_dapm_widget *w,
+                          struct snd_kcontrol *kcontrol,
+                          int event)
+{
+       struct snd_soc_codec *codec = w->codec;
+       struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
+       struct regulator *regulator;
+       int ret;
+
+       switch (w->shift) {
+       case 2:
+               regulator = wm5100->dbvdd2;
+               break;
+       case 3:
+               regulator = wm5100->dbvdd3;
+               break;
+       default:
+               BUG();
+               return 0;
+       }
+
+       switch (event) {
+       case SND_SOC_DAPM_PRE_PMU:
+               ret = regulator_enable(regulator);
+               if (ret != 0) {
+                       dev_err(codec->dev, "Failed to enable DBVDD%d: %d\n",
+                               w->shift, ret);
+                       return ret;
+               }
+               return ret;
+
+       case SND_SOC_DAPM_POST_PMD:
+               ret = regulator_disable(regulator);
+               if (ret != 0) {
+                       dev_err(codec->dev, "Failed to enable DBVDD%d: %d\n",
+                               w->shift, ret);
+                       return ret;
+               }
+               return ret;
+
+       default:
+               BUG();
+               return 0;
+       }
+}
+
+static void wm5100_log_status3(struct snd_soc_codec *codec, int val)
+{
+       if (val & WM5100_SPK_SHUTDOWN_WARN_EINT)
+               dev_crit(codec->dev, "Speaker shutdown warning\n");
+       if (val & WM5100_SPK_SHUTDOWN_EINT)
+               dev_crit(codec->dev, "Speaker shutdown\n");
+       if (val & WM5100_CLKGEN_ERR_EINT)
+               dev_crit(codec->dev, "SYSCLK underclocked\n");
+       if (val & WM5100_CLKGEN_ERR_ASYNC_EINT)
+               dev_crit(codec->dev, "ASYNCCLK underclocked\n");
+}
+
+static void wm5100_log_status4(struct snd_soc_codec *codec, int val)
+{
+       if (val & WM5100_AIF3_ERR_EINT)
+               dev_err(codec->dev, "AIF3 configuration error\n");
+       if (val & WM5100_AIF2_ERR_EINT)
+               dev_err(codec->dev, "AIF2 configuration error\n");
+       if (val & WM5100_AIF1_ERR_EINT)
+               dev_err(codec->dev, "AIF1 configuration error\n");
+       if (val & WM5100_CTRLIF_ERR_EINT)
+               dev_err(codec->dev, "Control interface error\n");
+       if (val & WM5100_ISRC2_UNDERCLOCKED_EINT)
+               dev_err(codec->dev, "ISRC2 underclocked\n");
+       if (val & WM5100_ISRC1_UNDERCLOCKED_EINT)
+               dev_err(codec->dev, "ISRC1 underclocked\n");
+       if (val & WM5100_FX_UNDERCLOCKED_EINT)
+               dev_err(codec->dev, "FX underclocked\n");
+       if (val & WM5100_AIF3_UNDERCLOCKED_EINT)
+               dev_err(codec->dev, "AIF3 underclocked\n");
+       if (val & WM5100_AIF2_UNDERCLOCKED_EINT)
+               dev_err(codec->dev, "AIF2 underclocked\n");
+       if (val & WM5100_AIF1_UNDERCLOCKED_EINT)
+               dev_err(codec->dev, "AIF1 underclocked\n");
+       if (val & WM5100_ASRC_UNDERCLOCKED_EINT)
+               dev_err(codec->dev, "ASRC underclocked\n");
+       if (val & WM5100_DAC_UNDERCLOCKED_EINT)
+               dev_err(codec->dev, "DAC underclocked\n");
+       if (val & WM5100_ADC_UNDERCLOCKED_EINT)
+               dev_err(codec->dev, "ADC underclocked\n");
+       if (val & WM5100_MIXER_UNDERCLOCKED_EINT)
+               dev_err(codec->dev, "Mixer underclocked\n");
+}
+
+static int wm5100_post_ev(struct snd_soc_dapm_widget *w,
+                         struct snd_kcontrol *kcontrol,
+                         int event)
+{
+       struct snd_soc_codec *codec = w->codec;
+       int ret;
+
+       ret = snd_soc_read(codec, WM5100_INTERRUPT_RAW_STATUS_3);
+       ret &= WM5100_SPK_SHUTDOWN_WARN_STS |
+               WM5100_SPK_SHUTDOWN_STS | WM5100_CLKGEN_ERR_STS |
+               WM5100_CLKGEN_ERR_ASYNC_STS;
+       wm5100_log_status3(codec, ret);
+
+       ret = snd_soc_read(codec, WM5100_INTERRUPT_RAW_STATUS_4);
+       wm5100_log_status4(codec, ret);
+
+       return 0;
+}
+
+static const struct snd_soc_dapm_widget wm5100_dapm_widgets[] = {
+SND_SOC_DAPM_SUPPLY("SYSCLK", WM5100_CLOCKING_3, WM5100_SYSCLK_ENA_SHIFT, 0,
+                   NULL, 0),
+SND_SOC_DAPM_SUPPLY("ASYNCCLK", WM5100_CLOCKING_6, WM5100_ASYNC_CLK_ENA_SHIFT,
+                   0, NULL, 0),
+
+SND_SOC_DAPM_SUPPLY("CP1", WM5100_HP_CHARGE_PUMP_1, WM5100_CP1_ENA_SHIFT, 0,
+                   wm5100_cp_ev,
+                   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
+SND_SOC_DAPM_SUPPLY("CP2", WM5100_MIC_CHARGE_PUMP_1, WM5100_CP2_ENA_SHIFT, 0,
+                   NULL, 0),
+SND_SOC_DAPM_SUPPLY("CP2 Active", WM5100_MIC_CHARGE_PUMP_1,
+                   WM5100_CP2_BYPASS_SHIFT, 1, wm5100_cp_ev,
+                   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
+SND_SOC_DAPM_SUPPLY("DBVDD2", SND_SOC_NOPM, 2, 0, wm5100_dbvdd_ev,
+                   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
+SND_SOC_DAPM_SUPPLY("DBVDD3", SND_SOC_NOPM, 3, 0, wm5100_dbvdd_ev,
+                   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
+
+SND_SOC_DAPM_SUPPLY("MICBIAS1", WM5100_MIC_BIAS_CTRL_1, WM5100_MICB1_ENA_SHIFT,
+                   0, NULL, 0),
+SND_SOC_DAPM_SUPPLY("MICBIAS2", WM5100_MIC_BIAS_CTRL_2, WM5100_MICB2_ENA_SHIFT,
+                   0, NULL, 0),
+SND_SOC_DAPM_SUPPLY("MICBIAS3", WM5100_MIC_BIAS_CTRL_3, WM5100_MICB3_ENA_SHIFT,
+                   0, NULL, 0),
+
+SND_SOC_DAPM_INPUT("IN1L"),
+SND_SOC_DAPM_INPUT("IN1R"),
+SND_SOC_DAPM_INPUT("IN2L"),
+SND_SOC_DAPM_INPUT("IN2R"),
+SND_SOC_DAPM_INPUT("IN3L"),
+SND_SOC_DAPM_INPUT("IN3R"),
+SND_SOC_DAPM_INPUT("IN4L"),
+SND_SOC_DAPM_INPUT("IN4R"),
+SND_SOC_DAPM_INPUT("TONE"),
+
+SND_SOC_DAPM_PGA_E("IN1L PGA", WM5100_INPUT_ENABLES, WM5100_IN1L_ENA_SHIFT, 0,
+                  NULL, 0, wm5100_out_ev, SND_SOC_DAPM_POST_PMU),
+SND_SOC_DAPM_PGA_E("IN1R PGA", WM5100_INPUT_ENABLES, WM5100_IN1R_ENA_SHIFT, 0,
+                  NULL, 0, wm5100_out_ev, SND_SOC_DAPM_POST_PMU),
+SND_SOC_DAPM_PGA_E("IN2L PGA", WM5100_INPUT_ENABLES, WM5100_IN2L_ENA_SHIFT, 0,
+                  NULL, 0, wm5100_out_ev, SND_SOC_DAPM_POST_PMU),
+SND_SOC_DAPM_PGA_E("IN2R PGA", WM5100_INPUT_ENABLES, WM5100_IN2R_ENA_SHIFT, 0,
+                  NULL, 0, wm5100_out_ev, SND_SOC_DAPM_POST_PMU),
+SND_SOC_DAPM_PGA_E("IN3L PGA", WM5100_INPUT_ENABLES, WM5100_IN3L_ENA_SHIFT, 0,
+                  NULL, 0, wm5100_out_ev, SND_SOC_DAPM_POST_PMU),
+SND_SOC_DAPM_PGA_E("IN3R PGA", WM5100_INPUT_ENABLES, WM5100_IN3R_ENA_SHIFT, 0,
+                  NULL, 0, wm5100_out_ev, SND_SOC_DAPM_POST_PMU),
+SND_SOC_DAPM_PGA_E("IN4L PGA", WM5100_INPUT_ENABLES, WM5100_IN4L_ENA_SHIFT, 0,
+                  NULL, 0, wm5100_out_ev, SND_SOC_DAPM_POST_PMU),
+SND_SOC_DAPM_PGA_E("IN4R PGA", WM5100_INPUT_ENABLES, WM5100_IN4R_ENA_SHIFT, 0,
+                  NULL, 0, wm5100_out_ev, SND_SOC_DAPM_POST_PMU),
+
+SND_SOC_DAPM_PGA("Tone Generator 1", WM5100_TONE_GENERATOR_1,
+                WM5100_TONE1_ENA_SHIFT, 0, NULL, 0),
+SND_SOC_DAPM_PGA("Tone Generator 2", WM5100_TONE_GENERATOR_1,
+                WM5100_TONE2_ENA_SHIFT, 0, NULL, 0),
+
+SND_SOC_DAPM_AIF_IN("AIF1RX1", "AIF1 Playback", 0,
+                   WM5100_AUDIO_IF_1_27, WM5100_AIF1RX1_ENA_SHIFT, 0),
+SND_SOC_DAPM_AIF_IN("AIF1RX2", "AIF1 Playback", 1,
+                   WM5100_AUDIO_IF_1_27, WM5100_AIF1RX2_ENA_SHIFT, 0),
+SND_SOC_DAPM_AIF_IN("AIF1RX3", "AIF1 Playback", 2,
+                   WM5100_AUDIO_IF_1_27, WM5100_AIF1RX3_ENA_SHIFT, 0),
+SND_SOC_DAPM_AIF_IN("AIF1RX4", "AIF1 Playback", 3,
+                   WM5100_AUDIO_IF_1_27, WM5100_AIF1RX4_ENA_SHIFT, 0),
+SND_SOC_DAPM_AIF_IN("AIF1RX5", "AIF1 Playback", 4,
+                   WM5100_AUDIO_IF_1_27, WM5100_AIF1RX5_ENA_SHIFT, 0),
+SND_SOC_DAPM_AIF_IN("AIF1RX6", "AIF1 Playback", 5,
+                   WM5100_AUDIO_IF_1_27, WM5100_AIF1RX6_ENA_SHIFT, 0),
+SND_SOC_DAPM_AIF_IN("AIF1RX7", "AIF1 Playback", 6,
+                   WM5100_AUDIO_IF_1_27, WM5100_AIF1RX7_ENA_SHIFT, 0),
+SND_SOC_DAPM_AIF_IN("AIF1RX8", "AIF1 Playback", 7,
+                   WM5100_AUDIO_IF_1_27, WM5100_AIF1RX8_ENA_SHIFT, 0),
+
+SND_SOC_DAPM_AIF_IN("AIF2RX1", "AIF2 Playback", 0,
+                   WM5100_AUDIO_IF_2_27, WM5100_AIF2RX1_ENA_SHIFT, 0),
+SND_SOC_DAPM_AIF_IN("AIF2RX2", "AIF2 Playback", 1,
+                   WM5100_AUDIO_IF_2_27, WM5100_AIF2RX2_ENA_SHIFT, 0),
+
+SND_SOC_DAPM_AIF_IN("AIF3RX1", "AIF3 Playback", 0,
+                   WM5100_AUDIO_IF_3_27, WM5100_AIF3RX1_ENA_SHIFT, 0),
+SND_SOC_DAPM_AIF_IN("AIF3RX2", "AIF3 Playback", 1,
+                   WM5100_AUDIO_IF_3_27, WM5100_AIF3RX2_ENA_SHIFT, 0),
+
+SND_SOC_DAPM_AIF_OUT("AIF1TX1", "AIF1 Capture", 0,
+                   WM5100_AUDIO_IF_1_26, WM5100_AIF1TX1_ENA_SHIFT, 0),
+SND_SOC_DAPM_AIF_OUT("AIF1TX2", "AIF1 Capture", 1,
+                   WM5100_AUDIO_IF_1_26, WM5100_AIF1TX2_ENA_SHIFT, 0),
+SND_SOC_DAPM_AIF_OUT("AIF1TX3", "AIF1 Capture", 2,
+                   WM5100_AUDIO_IF_1_26, WM5100_AIF1TX3_ENA_SHIFT, 0),
+SND_SOC_DAPM_AIF_OUT("AIF1TX4", "AIF1 Capture", 3,
+                   WM5100_AUDIO_IF_1_26, WM5100_AIF1TX4_ENA_SHIFT, 0),
+SND_SOC_DAPM_AIF_OUT("AIF1TX5", "AIF1 Capture", 4,
+                   WM5100_AUDIO_IF_1_26, WM5100_AIF1TX5_ENA_SHIFT, 0),
+SND_SOC_DAPM_AIF_OUT("AIF1TX6", "AIF1 Capture", 5,
+                   WM5100_AUDIO_IF_1_26, WM5100_AIF1TX6_ENA_SHIFT, 0),
+SND_SOC_DAPM_AIF_OUT("AIF1TX7", "AIF1 Capture", 6,
+                   WM5100_AUDIO_IF_1_26, WM5100_AIF1TX7_ENA_SHIFT, 0),
+SND_SOC_DAPM_AIF_OUT("AIF1TX8", "AIF1 Capture", 7,
+                   WM5100_AUDIO_IF_1_26, WM5100_AIF1TX8_ENA_SHIFT, 0),
+
+SND_SOC_DAPM_AIF_OUT("AIF2TX1", "AIF2 Capture", 0,
+                   WM5100_AUDIO_IF_2_26, WM5100_AIF2TX1_ENA_SHIFT, 0),
+SND_SOC_DAPM_AIF_OUT("AIF2TX2", "AIF2 Capture", 1,
+                   WM5100_AUDIO_IF_2_26, WM5100_AIF2TX2_ENA_SHIFT, 0),
+
+SND_SOC_DAPM_AIF_OUT("AIF3TX1", "AIF3 Capture", 0,
+                   WM5100_AUDIO_IF_3_26, WM5100_AIF3TX1_ENA_SHIFT, 0),
+SND_SOC_DAPM_AIF_OUT("AIF3TX2", "AIF3 Capture", 1,
+                   WM5100_AUDIO_IF_3_26, WM5100_AIF3TX2_ENA_SHIFT, 0),
+
+SND_SOC_DAPM_PGA_E("OUT6L", WM5100_OUTPUT_ENABLES_2, WM5100_OUT6L_ENA_SHIFT, 0,
+                  NULL, 0, wm5100_out_ev, SND_SOC_DAPM_POST_PMU),
+SND_SOC_DAPM_PGA_E("OUT6R", WM5100_OUTPUT_ENABLES_2, WM5100_OUT6R_ENA_SHIFT, 0,
+                  NULL, 0, wm5100_out_ev, SND_SOC_DAPM_POST_PMU),
+SND_SOC_DAPM_PGA_E("OUT5L", WM5100_OUTPUT_ENABLES_2, WM5100_OUT5L_ENA_SHIFT, 0,
+                  NULL, 0, wm5100_out_ev, SND_SOC_DAPM_POST_PMU),
+SND_SOC_DAPM_PGA_E("OUT5R", WM5100_OUTPUT_ENABLES_2, WM5100_OUT5R_ENA_SHIFT, 0,
+                  NULL, 0, wm5100_out_ev, SND_SOC_DAPM_POST_PMU),
+SND_SOC_DAPM_PGA_E("OUT4L", WM5100_OUTPUT_ENABLES_2, WM5100_OUT4L_ENA_SHIFT, 0,
+                  NULL, 0, wm5100_out_ev, SND_SOC_DAPM_POST_PMU),
+SND_SOC_DAPM_PGA_E("OUT4R", WM5100_OUTPUT_ENABLES_2, WM5100_OUT4R_ENA_SHIFT, 0,
+                  NULL, 0, wm5100_out_ev, SND_SOC_DAPM_POST_PMU),
+SND_SOC_DAPM_PGA_E("OUT3L", WM5100_CHANNEL_ENABLES_1, WM5100_HP3L_ENA_SHIFT, 0,
+                  NULL, 0, wm5100_out_ev, SND_SOC_DAPM_POST_PMU),
+SND_SOC_DAPM_PGA_E("OUT3R", WM5100_CHANNEL_ENABLES_1, WM5100_HP3R_ENA_SHIFT, 0,
+                  NULL, 0, wm5100_out_ev, SND_SOC_DAPM_POST_PMU),
+SND_SOC_DAPM_PGA_E("OUT2L", WM5100_CHANNEL_ENABLES_1, WM5100_HP2L_ENA_SHIFT, 0,
+                  NULL, 0, wm5100_out_ev, SND_SOC_DAPM_POST_PMU),
+SND_SOC_DAPM_PGA_E("OUT2R", WM5100_CHANNEL_ENABLES_1, WM5100_HP2R_ENA_SHIFT, 0,
+                  NULL, 0, wm5100_out_ev, SND_SOC_DAPM_POST_PMU),
+SND_SOC_DAPM_PGA_E("OUT1L", WM5100_CHANNEL_ENABLES_1, WM5100_HP1L_ENA_SHIFT, 0,
+                  NULL, 0, wm5100_out_ev, SND_SOC_DAPM_POST_PMU),
+SND_SOC_DAPM_PGA_E("OUT1R", WM5100_CHANNEL_ENABLES_1, WM5100_HP1R_ENA_SHIFT, 0,
+                  NULL, 0, wm5100_out_ev, SND_SOC_DAPM_POST_PMU),
+SND_SOC_DAPM_PGA_E("PWM1 Driver", WM5100_PWM_DRIVE_1, WM5100_PWM1_ENA_SHIFT, 0,
+                  NULL, 0, wm5100_out_ev, SND_SOC_DAPM_POST_PMU),
+SND_SOC_DAPM_PGA_E("PWM2 Driver", WM5100_PWM_DRIVE_1, WM5100_PWM2_ENA_SHIFT, 0,
+                  NULL, 0, wm5100_out_ev, SND_SOC_DAPM_POST_PMU),
+
+SND_SOC_DAPM_PGA("EQ1", WM5100_EQ1_1, WM5100_EQ1_ENA_SHIFT, 0, NULL, 0),
+SND_SOC_DAPM_PGA("EQ2", WM5100_EQ2_1, WM5100_EQ2_ENA_SHIFT, 0, NULL, 0),
+SND_SOC_DAPM_PGA("EQ3", WM5100_EQ3_1, WM5100_EQ3_ENA_SHIFT, 0, NULL, 0),
+SND_SOC_DAPM_PGA("EQ4", WM5100_EQ4_1, WM5100_EQ4_ENA_SHIFT, 0, NULL, 0),
+
+SND_SOC_DAPM_PGA("DRC1L", WM5100_DRC1_CTRL1, WM5100_DRCL_ENA_SHIFT, 0,
+                NULL, 0),
+SND_SOC_DAPM_PGA("DRC1R", WM5100_DRC1_CTRL1, WM5100_DRCR_ENA_SHIFT, 0,
+                NULL, 0),
+
+SND_SOC_DAPM_PGA("LHPF1", WM5100_HPLPF1_1, WM5100_LHPF1_ENA_SHIFT, 0,
+                NULL, 0),
+SND_SOC_DAPM_PGA("LHPF2", WM5100_HPLPF2_1, WM5100_LHPF2_ENA_SHIFT, 0,
+                NULL, 0),
+SND_SOC_DAPM_PGA("LHPF3", WM5100_HPLPF3_1, WM5100_LHPF3_ENA_SHIFT, 0,
+                NULL, 0),
+SND_SOC_DAPM_PGA("LHPF4", WM5100_HPLPF4_1, WM5100_LHPF4_ENA_SHIFT, 0,
+                NULL, 0),
+
+WM5100_MIXER_WIDGETS(EQ1, "EQ1"),
+WM5100_MIXER_WIDGETS(EQ2, "EQ2"),
+WM5100_MIXER_WIDGETS(EQ3, "EQ3"),
+WM5100_MIXER_WIDGETS(EQ4, "EQ4"),
+
+WM5100_MIXER_WIDGETS(DRC1L, "DRC1L"),
+WM5100_MIXER_WIDGETS(DRC1R, "DRC1R"),
+
+WM5100_MIXER_WIDGETS(LHPF1, "LHPF1"),
+WM5100_MIXER_WIDGETS(LHPF2, "LHPF2"),
+WM5100_MIXER_WIDGETS(LHPF3, "LHPF3"),
+WM5100_MIXER_WIDGETS(LHPF4, "LHPF4"),
+
+WM5100_MIXER_WIDGETS(AIF1TX1, "AIF1TX1"),
+WM5100_MIXER_WIDGETS(AIF1TX2, "AIF1TX2"),
+WM5100_MIXER_WIDGETS(AIF1TX3, "AIF1TX3"),
+WM5100_MIXER_WIDGETS(AIF1TX4, "AIF1TX4"),
+WM5100_MIXER_WIDGETS(AIF1TX5, "AIF1TX5"),
+WM5100_MIXER_WIDGETS(AIF1TX6, "AIF1TX6"),
+WM5100_MIXER_WIDGETS(AIF1TX7, "AIF1TX7"),
+WM5100_MIXER_WIDGETS(AIF1TX8, "AIF1TX8"),
+
+WM5100_MIXER_WIDGETS(AIF2TX1, "AIF2TX1"),
+WM5100_MIXER_WIDGETS(AIF2TX2, "AIF2TX2"),
+
+WM5100_MIXER_WIDGETS(AIF3TX1, "AIF3TX1"),
+WM5100_MIXER_WIDGETS(AIF3TX2, "AIF3TX2"),
+
+WM5100_MIXER_WIDGETS(HPOUT1L, "HPOUT1L"),
+WM5100_MIXER_WIDGETS(HPOUT1R, "HPOUT1R"),
+WM5100_MIXER_WIDGETS(HPOUT2L, "HPOUT2L"),
+WM5100_MIXER_WIDGETS(HPOUT2R, "HPOUT2R"),
+WM5100_MIXER_WIDGETS(HPOUT3L, "HPOUT3L"),
+WM5100_MIXER_WIDGETS(HPOUT3R, "HPOUT3R"),
+
+WM5100_MIXER_WIDGETS(SPKOUTL, "SPKOUTL"),
+WM5100_MIXER_WIDGETS(SPKOUTR, "SPKOUTR"),
+WM5100_MIXER_WIDGETS(SPKDAT1L, "SPKDAT1L"),
+WM5100_MIXER_WIDGETS(SPKDAT1R, "SPKDAT1R"),
+WM5100_MIXER_WIDGETS(SPKDAT2L, "SPKDAT2L"),
+WM5100_MIXER_WIDGETS(SPKDAT2R, "SPKDAT2R"),
+
+WM5100_MIXER_WIDGETS(PWM1, "PWM1"),
+WM5100_MIXER_WIDGETS(PWM2, "PWM2"),
+
+SND_SOC_DAPM_OUTPUT("HPOUT1L"),
+SND_SOC_DAPM_OUTPUT("HPOUT1R"),
+SND_SOC_DAPM_OUTPUT("HPOUT2L"),
+SND_SOC_DAPM_OUTPUT("HPOUT2R"),
+SND_SOC_DAPM_OUTPUT("HPOUT3L"),
+SND_SOC_DAPM_OUTPUT("HPOUT3R"),
+SND_SOC_DAPM_OUTPUT("SPKOUTL"),
+SND_SOC_DAPM_OUTPUT("SPKOUTR"),
+SND_SOC_DAPM_OUTPUT("SPKDAT1"),
+SND_SOC_DAPM_OUTPUT("SPKDAT2"),
+SND_SOC_DAPM_OUTPUT("PWM1"),
+SND_SOC_DAPM_OUTPUT("PWM2"),
+};
+
+/* We register a _POST event if we don't have IRQ support so we can
+ * look at the error status from the CODEC - if we've got the IRQ
+ * hooked up then we will get prompted to look by an interrupt.
+ */
+static const struct snd_soc_dapm_widget wm5100_dapm_widgets_noirq[] = {
+SND_SOC_DAPM_POST("Post", wm5100_post_ev),
+};
+
+static const struct snd_soc_dapm_route wm5100_dapm_routes[] = {
+       { "IN1L", NULL, "SYSCLK" },
+       { "IN1R", NULL, "SYSCLK" },
+       { "IN2L", NULL, "SYSCLK" },
+       { "IN2R", NULL, "SYSCLK" },
+       { "IN3L", NULL, "SYSCLK" },
+       { "IN3R", NULL, "SYSCLK" },
+       { "IN4L", NULL, "SYSCLK" },
+       { "IN4R", NULL, "SYSCLK" },
+
+       { "OUT1L", NULL, "SYSCLK" },
+       { "OUT1R", NULL, "SYSCLK" },
+       { "OUT2L", NULL, "SYSCLK" },
+       { "OUT2R", NULL, "SYSCLK" },
+       { "OUT3L", NULL, "SYSCLK" },
+       { "OUT3R", NULL, "SYSCLK" },
+       { "OUT4L", NULL, "SYSCLK" },
+       { "OUT4R", NULL, "SYSCLK" },
+       { "OUT5L", NULL, "SYSCLK" },
+       { "OUT5R", NULL, "SYSCLK" },
+       { "OUT6L", NULL, "SYSCLK" },
+       { "OUT6R", NULL, "SYSCLK" },
+
+       { "AIF1RX1", NULL, "SYSCLK" },
+       { "AIF1RX2", NULL, "SYSCLK" },
+       { "AIF1RX3", NULL, "SYSCLK" },
+       { "AIF1RX4", NULL, "SYSCLK" },
+       { "AIF1RX5", NULL, "SYSCLK" },
+       { "AIF1RX6", NULL, "SYSCLK" },
+       { "AIF1RX7", NULL, "SYSCLK" },
+       { "AIF1RX8", NULL, "SYSCLK" },
+
+       { "AIF2RX1", NULL, "SYSCLK" },
+       { "AIF2RX1", NULL, "DBVDD2" },
+       { "AIF2RX2", NULL, "SYSCLK" },
+       { "AIF2RX2", NULL, "DBVDD2" },
+
+       { "AIF3RX1", NULL, "SYSCLK" },
+       { "AIF3RX1", NULL, "DBVDD3" },
+       { "AIF3RX2", NULL, "SYSCLK" },
+       { "AIF3RX2", NULL, "DBVDD3" },
+
+       { "AIF1TX1", NULL, "SYSCLK" },
+       { "AIF1TX2", NULL, "SYSCLK" },
+       { "AIF1TX3", NULL, "SYSCLK" },
+       { "AIF1TX4", NULL, "SYSCLK" },
+       { "AIF1TX5", NULL, "SYSCLK" },
+       { "AIF1TX6", NULL, "SYSCLK" },
+       { "AIF1TX7", NULL, "SYSCLK" },
+       { "AIF1TX8", NULL, "SYSCLK" },
+
+       { "AIF2TX1", NULL, "SYSCLK" },
+       { "AIF2TX1", NULL, "DBVDD2" },
+       { "AIF2TX2", NULL, "SYSCLK" },
+       { "AIF2TX2", NULL, "DBVDD2" },
+
+       { "AIF3TX1", NULL, "SYSCLK" },
+       { "AIF3TX1", NULL, "DBVDD3" },
+       { "AIF3TX2", NULL, "SYSCLK" },
+       { "AIF3TX2", NULL, "DBVDD3" },
+
+       { "MICBIAS1", NULL, "CP2" },
+       { "MICBIAS2", NULL, "CP2" },
+       { "MICBIAS3", NULL, "CP2" },
+
+       { "IN1L PGA", NULL, "CP2" },
+       { "IN1R PGA", NULL, "CP2" },
+       { "IN2L PGA", NULL, "CP2" },
+       { "IN2R PGA", NULL, "CP2" },
+       { "IN3L PGA", NULL, "CP2" },
+       { "IN3R PGA", NULL, "CP2" },
+       { "IN4L PGA", NULL, "CP2" },
+       { "IN4R PGA", NULL, "CP2" },
+
+       { "IN1L PGA", NULL, "CP2 Active" },
+       { "IN1R PGA", NULL, "CP2 Active" },
+       { "IN2L PGA", NULL, "CP2 Active" },
+       { "IN2R PGA", NULL, "CP2 Active" },
+       { "IN3L PGA", NULL, "CP2 Active" },
+       { "IN3R PGA", NULL, "CP2 Active" },
+       { "IN4L PGA", NULL, "CP2 Active" },
+       { "IN4R PGA", NULL, "CP2 Active" },
+
+       { "OUT1L", NULL, "CP1" },
+       { "OUT1R", NULL, "CP1" },
+       { "OUT2L", NULL, "CP1" },
+       { "OUT2R", NULL, "CP1" },
+       { "OUT3L", NULL, "CP1" },
+       { "OUT3R", NULL, "CP1" },
+
+       { "Tone Generator 1", NULL, "TONE" },
+       { "Tone Generator 2", NULL, "TONE" },
+
+       { "IN1L PGA", NULL, "IN1L" },
+       { "IN1R PGA", NULL, "IN1R" },
+       { "IN2L PGA", NULL, "IN2L" },
+       { "IN2R PGA", NULL, "IN2R" },
+       { "IN3L PGA", NULL, "IN3L" },
+       { "IN3R PGA", NULL, "IN3R" },
+       { "IN4L PGA", NULL, "IN4L" },
+       { "IN4R PGA", NULL, "IN4R" },
+
+       WM5100_MIXER_ROUTES("OUT1L", "HPOUT1L"),
+       WM5100_MIXER_ROUTES("OUT1R", "HPOUT1R"),
+       WM5100_MIXER_ROUTES("OUT2L", "HPOUT2L"),
+       WM5100_MIXER_ROUTES("OUT2R", "HPOUT2R"),
+       WM5100_MIXER_ROUTES("OUT3L", "HPOUT3L"),
+       WM5100_MIXER_ROUTES("OUT3R", "HPOUT3R"),
+
+       WM5100_MIXER_ROUTES("OUT4L", "SPKOUTL"),
+       WM5100_MIXER_ROUTES("OUT4R", "SPKOUTR"),
+       WM5100_MIXER_ROUTES("OUT5L", "SPKDAT1L"),
+       WM5100_MIXER_ROUTES("OUT5R", "SPKDAT1R"),
+       WM5100_MIXER_ROUTES("OUT6L", "SPKDAT2L"),
+       WM5100_MIXER_ROUTES("OUT6R", "SPKDAT2R"),
+
+       WM5100_MIXER_ROUTES("PWM1 Driver", "PWM1"),
+       WM5100_MIXER_ROUTES("PWM2 Driver", "PWM2"),
+
+       WM5100_MIXER_ROUTES("AIF1TX1", "AIF1TX1"),
+       WM5100_MIXER_ROUTES("AIF1TX2", "AIF1TX2"),
+       WM5100_MIXER_ROUTES("AIF1TX3", "AIF1TX3"),
+       WM5100_MIXER_ROUTES("AIF1TX4", "AIF1TX4"),
+       WM5100_MIXER_ROUTES("AIF1TX5", "AIF1TX5"),
+       WM5100_MIXER_ROUTES("AIF1TX6", "AIF1TX6"),
+       WM5100_MIXER_ROUTES("AIF1TX7", "AIF1TX7"),
+       WM5100_MIXER_ROUTES("AIF1TX8", "AIF1TX8"),
+
+       WM5100_MIXER_ROUTES("AIF2TX1", "AIF2TX1"),
+       WM5100_MIXER_ROUTES("AIF2TX2", "AIF2TX2"),
+
+       WM5100_MIXER_ROUTES("AIF3TX1", "AIF3TX1"),
+       WM5100_MIXER_ROUTES("AIF3TX2", "AIF3TX2"),
+
+       WM5100_MIXER_ROUTES("EQ1", "EQ1"),
+       WM5100_MIXER_ROUTES("EQ2", "EQ2"),
+       WM5100_MIXER_ROUTES("EQ3", "EQ3"),
+       WM5100_MIXER_ROUTES("EQ4", "EQ4"),
+
+       WM5100_MIXER_ROUTES("DRC1L", "DRC1L"),
+       WM5100_MIXER_ROUTES("DRC1R", "DRC1R"),
+
+       WM5100_MIXER_ROUTES("LHPF1", "LHPF1"),
+       WM5100_MIXER_ROUTES("LHPF2", "LHPF2"),
+       WM5100_MIXER_ROUTES("LHPF3", "LHPF3"),
+       WM5100_MIXER_ROUTES("LHPF4", "LHPF4"),
+
+       { "HPOUT1L", NULL, "OUT1L" },
+       { "HPOUT1R", NULL, "OUT1R" },
+       { "HPOUT2L", NULL, "OUT2L" },
+       { "HPOUT2R", NULL, "OUT2R" },
+       { "HPOUT3L", NULL, "OUT3L" },
+       { "HPOUT3R", NULL, "OUT3R" },
+       { "SPKOUTL", NULL, "OUT4L" },
+       { "SPKOUTR", NULL, "OUT4R" },
+       { "SPKDAT1", NULL, "OUT5L" },
+       { "SPKDAT1", NULL, "OUT5R" },
+       { "SPKDAT2", NULL, "OUT6L" },
+       { "SPKDAT2", NULL, "OUT6R" },
+       { "PWM1", NULL, "PWM1 Driver" },
+       { "PWM2", NULL, "PWM2 Driver" },
+};
+
+static struct {
+       int reg;
+       int val;
+} wm5100_reva_patches[] = {
+       { WM5100_AUDIO_IF_1_10, 0 },
+       { WM5100_AUDIO_IF_1_11, 1 },
+       { WM5100_AUDIO_IF_1_12, 2 },
+       { WM5100_AUDIO_IF_1_13, 3 },
+       { WM5100_AUDIO_IF_1_14, 4 },
+       { WM5100_AUDIO_IF_1_15, 5 },
+       { WM5100_AUDIO_IF_1_16, 6 },
+       { WM5100_AUDIO_IF_1_17, 7 },
+
+       { WM5100_AUDIO_IF_1_18, 0 },
+       { WM5100_AUDIO_IF_1_19, 1 },
+       { WM5100_AUDIO_IF_1_20, 2 },
+       { WM5100_AUDIO_IF_1_21, 3 },
+       { WM5100_AUDIO_IF_1_22, 4 },
+       { WM5100_AUDIO_IF_1_23, 5 },
+       { WM5100_AUDIO_IF_1_24, 6 },
+       { WM5100_AUDIO_IF_1_25, 7 },
+
+       { WM5100_AUDIO_IF_2_10, 0 },
+       { WM5100_AUDIO_IF_2_11, 1 },
+
+       { WM5100_AUDIO_IF_2_18, 0 },
+       { WM5100_AUDIO_IF_2_19, 1 },
+
+       { WM5100_AUDIO_IF_3_10, 0 },
+       { WM5100_AUDIO_IF_3_11, 1 },
+
+       { WM5100_AUDIO_IF_3_18, 0 },
+       { WM5100_AUDIO_IF_3_19, 1 },
+};
+
+static int wm5100_set_bias_level(struct snd_soc_codec *codec,
+                                enum snd_soc_bias_level level)
+{
+       struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
+       int ret, i;
+
+       switch (level) {
+       case SND_SOC_BIAS_ON:
+               break;
+
+       case SND_SOC_BIAS_PREPARE:
+               break;
+
+       case SND_SOC_BIAS_STANDBY:
+               if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
+                       ret = regulator_bulk_enable(ARRAY_SIZE(wm5100->core_supplies),
+                                                   wm5100->core_supplies);
+                       if (ret != 0) {
+                               dev_err(codec->dev,
+                                       "Failed to enable supplies: %d\n",
+                                       ret);
+                               return ret;
+                       }
+
+                       if (wm5100->pdata.ldo_ena) {
+                               gpio_set_value_cansleep(wm5100->pdata.ldo_ena,
+                                                       1);
+                               msleep(2);
+                       }
+
+                       codec->cache_only = false;
+
+                       switch (wm5100->rev) {
+                       case 0:
+                               snd_soc_write(codec, 0x11, 0x3);
+                               snd_soc_write(codec, 0x203, 0xc);
+                               snd_soc_write(codec, 0x206, 0);
+                               snd_soc_write(codec, 0x207, 0xf0);
+                               snd_soc_write(codec, 0x208, 0x3c);
+                               snd_soc_write(codec, 0x209, 0);
+                               snd_soc_write(codec, 0x211, 0x20d8);
+                               snd_soc_write(codec, 0x11, 0);
+
+                               for (i = 0;
+                                    i < ARRAY_SIZE(wm5100_reva_patches);
+                                    i++)
+                                       snd_soc_write(codec,
+                                                     wm5100_reva_patches[i].reg,
+                                                     wm5100_reva_patches[i].val);
+                               break;
+                       default:
+                               break;
+                       }
+
+                       snd_soc_cache_sync(codec);
+               }
+               break;
+
+       case SND_SOC_BIAS_OFF:
+               if (wm5100->pdata.ldo_ena)
+                       gpio_set_value_cansleep(wm5100->pdata.ldo_ena, 0);
+               regulator_bulk_disable(ARRAY_SIZE(wm5100->core_supplies),
+                                      wm5100->core_supplies);
+               break;
+       }
+       codec->dapm.bias_level = level;
+
+       return 0;
+}
+
+static int wm5100_dai_to_base(struct snd_soc_dai *dai)
+{
+       switch (dai->id) {
+       case 0:
+               return WM5100_AUDIO_IF_1_1 - 1;
+       case 1:
+               return WM5100_AUDIO_IF_2_1 - 1;
+       case 2:
+               return WM5100_AUDIO_IF_3_1 - 1;
+       default:
+               BUG();
+               return -EINVAL;
+       }
+}
+
+static int wm5100_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
+{
+       struct snd_soc_codec *codec = dai->codec;
+       int lrclk, bclk, mask, base;
+
+       base = wm5100_dai_to_base(dai);
+       if (base < 0)
+               return base;
+
+       lrclk = 0;
+       bclk = 0;
+
+       switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+       case SND_SOC_DAIFMT_DSP_A:
+               mask = 0;
+               break;
+       case SND_SOC_DAIFMT_DSP_B:
+               mask = 1;
+               break;
+       case SND_SOC_DAIFMT_I2S:
+               mask = 2;
+               break;
+       case SND_SOC_DAIFMT_LEFT_J:
+               mask = 3;
+               break;
+       default:
+               dev_err(codec->dev, "Unsupported DAI format %d\n",
+                       fmt & SND_SOC_DAIFMT_FORMAT_MASK);
+               return -EINVAL;
+       }
+
+       switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
+       case SND_SOC_DAIFMT_CBS_CFS:
+               break;
+       case SND_SOC_DAIFMT_CBS_CFM:
+               lrclk |= WM5100_AIF1TX_LRCLK_MSTR;
+               break;
+       case SND_SOC_DAIFMT_CBM_CFS:
+               bclk |= WM5100_AIF1_BCLK_MSTR;
+               break;
+       case SND_SOC_DAIFMT_CBM_CFM:
+               lrclk |= WM5100_AIF1TX_LRCLK_MSTR;
+               bclk |= WM5100_AIF1_BCLK_MSTR;
+               break;
+       default:
+               dev_err(codec->dev, "Unsupported master mode %d\n",
+                       fmt & SND_SOC_DAIFMT_MASTER_MASK);
+               return -EINVAL;
+       }
+
+       switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
+       case SND_SOC_DAIFMT_NB_NF:
+               break;
+       case SND_SOC_DAIFMT_IB_IF:
+               bclk |= WM5100_AIF1_BCLK_INV;
+               lrclk |= WM5100_AIF1TX_LRCLK_INV;
+               break;
+       case SND_SOC_DAIFMT_IB_NF:
+               bclk |= WM5100_AIF1_BCLK_INV;
+               break;
+       case SND_SOC_DAIFMT_NB_IF:
+               lrclk |= WM5100_AIF1TX_LRCLK_INV;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       snd_soc_update_bits(codec, base + 1, WM5100_AIF1_BCLK_MSTR |
+                           WM5100_AIF1_BCLK_INV, bclk);
+       snd_soc_update_bits(codec, base + 2, WM5100_AIF1TX_LRCLK_MSTR |
+                           WM5100_AIF1TX_LRCLK_INV, lrclk);
+       snd_soc_update_bits(codec, base + 3, WM5100_AIF1TX_LRCLK_MSTR |
+                           WM5100_AIF1TX_LRCLK_INV, lrclk);
+       snd_soc_update_bits(codec, base + 5, WM5100_AIF1_FMT_MASK, mask);
+
+       return 0;
+}
+
+#define WM5100_NUM_BCLK_RATES 19
+
+static int wm5100_bclk_rates_dat[WM5100_NUM_BCLK_RATES] = {
+       32000,
+       48000,
+       64000,
+       96000,
+       128000,
+       192000,
+       256000,
+       384000,
+       512000,
+       768000,
+       1024000,
+       1536000,
+       2048000,
+       3072000,
+       4096000,
+       6144000,
+       8192000,
+       12288000,
+       24576000,
+};
+
+static int wm5100_bclk_rates_cd[WM5100_NUM_BCLK_RATES] = {
+       29400,
+       44100,
+       58800,
+       88200,
+       117600,
+       176400,
+       235200,
+       352800,
+       470400,
+       705600,
+       940800,
+       1411200,
+       1881600,
+       2882400,
+       3763200,
+       5644800,
+       7526400,
+       11289600,
+       22579600,
+};
+
+static int wm5100_hw_params(struct snd_pcm_substream *substream,
+                           struct snd_pcm_hw_params *params,
+                           struct snd_soc_dai *dai)
+{
+       struct snd_soc_codec *codec = dai->codec;
+       struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
+       bool async = wm5100->aif_async[dai->id];
+       int i, base, bclk, aif_rate, lrclk, wl, fl, sr;
+       int *bclk_rates;
+
+       base = wm5100_dai_to_base(dai);
+       if (base < 0)
+               return base;
+
+       /* Data sizes if not using TDM */
+       wl = snd_pcm_format_width(params_format(params));
+       if (wl < 0)
+               return wl;
+       fl = snd_soc_params_to_frame_size(params);
+       if (fl < 0)
+               return fl;
+
+       dev_dbg(codec->dev, "Word length %d bits, frame length %d bits\n",
+               wl, fl);
+
+       /* Target BCLK rate */
+       bclk = snd_soc_params_to_bclk(params);
+       if (bclk < 0)
+               return bclk;
+
+       /* Root for BCLK depends on SYS/ASYNCCLK */
+       if (!async) {
+               aif_rate = wm5100->sysclk;
+               sr = wm5100_alloc_sr(codec, params_rate(params));
+               if (sr < 0)
+                       return sr;
+       } else {
+               /* If we're in ASYNCCLK set the ASYNC sample rate */
+               aif_rate = wm5100->asyncclk;
+               sr = 3;
+
+               for (i = 0; i < ARRAY_SIZE(wm5100_sr_code); i++)
+                       if (params_rate(params) == wm5100_sr_code[i])
+                               break;
+               if (i == ARRAY_SIZE(wm5100_sr_code)) {
+                       dev_err(codec->dev, "Invalid rate %dHzn",
+                               params_rate(params));
+                       return -EINVAL;
+               }
+
+               /* TODO: We should really check for symmetry */
+               snd_soc_update_bits(codec, WM5100_CLOCKING_8,
+                                   WM5100_ASYNC_SAMPLE_RATE_MASK, i);
+       }
+
+       if (!aif_rate) {
+               dev_err(codec->dev, "%s has no rate set\n",
+                       async ? "ASYNCCLK" : "SYSCLK");
+               return -EINVAL;
+       }
+
+       dev_dbg(codec->dev, "Target BCLK is %dHz, using %dHz %s\n",
+               bclk, aif_rate, async ? "ASYNCCLK" : "SYSCLK");
+
+       if (aif_rate % 4000)
+               bclk_rates = wm5100_bclk_rates_cd;
+       else
+               bclk_rates = wm5100_bclk_rates_dat;
+
+       for (i = 0; i < WM5100_NUM_BCLK_RATES; i++)
+               if (bclk_rates[i] >= bclk && (bclk_rates[i] % bclk == 0))
+                       break;
+       if (i == WM5100_NUM_BCLK_RATES) {
+               dev_err(codec->dev,
+                       "No valid BCLK for %dHz found from %dHz %s\n",
+                       bclk, aif_rate, async ? "ASYNCCLK" : "SYSCLK");
+               return -EINVAL;
+       }
+
+       bclk = i;
+       dev_dbg(codec->dev, "Setting %dHz BCLK\n", bclk_rates[bclk]);
+       snd_soc_update_bits(codec, base + 1, WM5100_AIF1_BCLK_FREQ_MASK, bclk);
+
+       lrclk = bclk_rates[bclk] / params_rate(params);
+       dev_dbg(codec->dev, "Setting %dHz LRCLK\n", bclk_rates[bclk] / lrclk);
+       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
+           wm5100->aif_symmetric[dai->id])
+               snd_soc_update_bits(codec, base + 7,
+                                   WM5100_AIF1RX_BCPF_MASK, lrclk);
+       else
+               snd_soc_update_bits(codec, base + 6,
+                                   WM5100_AIF1TX_BCPF_MASK, lrclk);
+
+       i = (wl << WM5100_AIF1TX_WL_SHIFT) | fl;
+       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+               snd_soc_update_bits(codec, base + 9,
+                                   WM5100_AIF1RX_WL_MASK |
+                                   WM5100_AIF1RX_SLOT_LEN_MASK, i);
+       else
+               snd_soc_update_bits(codec, base + 8,
+                                   WM5100_AIF1TX_WL_MASK |
+                                   WM5100_AIF1TX_SLOT_LEN_MASK, i);
+
+       snd_soc_update_bits(codec, base + 4, WM5100_AIF1_RATE_MASK, sr);
+
+       return 0;
+}
+
+static struct snd_soc_dai_ops wm5100_dai_ops = {
+       .set_fmt = wm5100_set_fmt,
+       .hw_params = wm5100_hw_params,
+};
+
+static int wm5100_set_sysclk(struct snd_soc_codec *codec, int clk_id,
+                            int source, unsigned int freq, int dir)
+{
+       struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
+       int *rate_store;
+       int fval, audio_rate, ret, reg;
+
+       switch (clk_id) {
+       case WM5100_CLK_SYSCLK:
+               reg = WM5100_CLOCKING_3;
+               rate_store = &wm5100->sysclk;
+               break;
+       case WM5100_CLK_ASYNCCLK:
+               reg = WM5100_CLOCKING_7;
+               rate_store = &wm5100->asyncclk;
+               break;
+       case WM5100_CLK_32KHZ:
+               /* The 32kHz clock is slightly different to the others */
+               switch (source) {
+               case WM5100_CLKSRC_MCLK1:
+               case WM5100_CLKSRC_MCLK2:
+               case WM5100_CLKSRC_SYSCLK:
+                       snd_soc_update_bits(codec, WM5100_CLOCKING_1,
+                                           WM5100_CLK_32K_SRC_MASK,
+                                           source);
+                       break;
+               default:
+                       return -EINVAL;
+               }
+               return 0;
+
+       case WM5100_CLK_AIF1:
+       case WM5100_CLK_AIF2:
+       case WM5100_CLK_AIF3:
+               /* Not real clocks, record which clock domain they're in */
+               switch (source) {
+               case WM5100_CLKSRC_SYSCLK:
+                       wm5100->aif_async[clk_id - 1] = false;
+                       break;
+               case WM5100_CLKSRC_ASYNCCLK:
+                       wm5100->aif_async[clk_id - 1] = true;
+                       break;
+               default:
+                       dev_err(codec->dev, "Invalid source %d\n", source);
+                       return -EINVAL;
+               }       
+               return 0;
+
+       case WM5100_CLK_OPCLK:
+               switch (freq) {
+               case 5644800:
+               case 6144000:
+                       snd_soc_update_bits(codec, WM5100_MISC_GPIO_1,
+                                           WM5100_OPCLK_SEL_MASK, 0);
+                       break;
+               case 11289600:
+               case 12288000:
+                       snd_soc_update_bits(codec, WM5100_MISC_GPIO_1,
+                                           WM5100_OPCLK_SEL_MASK, 0);
+                       break;
+               case 22579200:
+               case 24576000:
+                       snd_soc_update_bits(codec, WM5100_MISC_GPIO_1,
+                                           WM5100_OPCLK_SEL_MASK, 0);
+                       break;
+               default:
+                       dev_err(codec->dev, "Unsupported OPCLK %dHz\n",
+                               freq);
+                       return -EINVAL;
+               }
+               return 0;
+
+       default:
+               dev_err(codec->dev, "Unknown clock %d\n", clk_id);
+               return -EINVAL;
+       }
+
+       switch (source) {
+       case WM5100_CLKSRC_SYSCLK:
+       case WM5100_CLKSRC_ASYNCCLK:
+               dev_err(codec->dev, "Invalid source %d\n", source);
+               return -EINVAL;
+       }
+
+       switch (freq) {
+       case 5644800:
+       case 6144000:
+               fval = 0;
+               break;
+       case 11289600:
+       case 12288000:
+               fval = 1;
+               break;
+       case 22579200:
+       case 24576000:
+               fval = 2;
+               break;
+       default:
+               dev_err(codec->dev, "Invalid clock rate: %d\n", freq);
+               return -EINVAL;
+       }
+
+       switch (freq) {
+       case 5644800:
+       case 11289600:
+       case 22579200:
+               audio_rate = 44100;
+               break;
+
+       case 6144000:
+       case 12288000:
+       case 24576000:
+               audio_rate = 48000;
+               break;
+
+       default:
+               BUG();
+               audio_rate = 0;
+               break;
+       }
+
+       /* TODO: Check if MCLKs are in use and enable/disable pulls to
+        * match.
+        */
+
+       snd_soc_update_bits(codec, reg, WM5100_SYSCLK_FREQ_MASK |
+                           WM5100_SYSCLK_SRC_MASK,
+                           fval << WM5100_SYSCLK_FREQ_SHIFT | source);
+
+       /* If this is SYSCLK then configure the clock rate for the
+        * internal audio functions to the natural sample rate for
+        * this clock rate.
+        */
+       if (clk_id == WM5100_CLK_SYSCLK) {
+               dev_dbg(codec->dev, "Setting primary audio rate to %dHz",
+                       audio_rate);
+               if (0 && *rate_store)
+                       wm5100_free_sr(codec, audio_rate);
+               ret = wm5100_alloc_sr(codec, audio_rate);
+               if (ret != 0)
+                       dev_warn(codec->dev, "Primary audio slot is %d\n",
+                                ret);
+       }
+
+       *rate_store = freq;
+
+       return 0;
+}
+
+struct _fll_div {
+       u16 fll_fratio;
+       u16 fll_outdiv;
+       u16 fll_refclk_div;
+       u16 n;
+       u16 theta;
+       u16 lambda;
+};
+
+static struct {
+       unsigned int min;
+       unsigned int max;
+       u16 fll_fratio;
+       int ratio;
+} fll_fratios[] = {
+       {       0,    64000, 4, 16 },
+       {   64000,   128000, 3,  8 },
+       {  128000,   256000, 2,  4 },
+       {  256000,  1000000, 1,  2 },
+       { 1000000, 13500000, 0,  1 },
+};
+
+static int fll_factors(struct _fll_div *fll_div, unsigned int Fref,
+                      unsigned int Fout)
+{
+       unsigned int target;
+       unsigned int div;
+       unsigned int fratio, gcd_fll;
+       int i;
+
+       /* Fref must be <=13.5MHz */
+       div = 1;
+       fll_div->fll_refclk_div = 0;
+       while ((Fref / div) > 13500000) {
+               div *= 2;
+               fll_div->fll_refclk_div++;
+
+               if (div > 8) {
+                       pr_err("Can't scale %dMHz input down to <=13.5MHz\n",
+                              Fref);
+                       return -EINVAL;
+               }
+       }
+
+       pr_debug("FLL Fref=%u Fout=%u\n", Fref, Fout);
+
+       /* Apply the division for our remaining calculations */
+       Fref /= div;
+
+       /* Fvco should be 90-100MHz; don't check the upper bound */
+       div = 2;
+       while (Fout * div < 90000000) {
+               div++;
+               if (div > 64) {
+                       pr_err("Unable to find FLL_OUTDIV for Fout=%uHz\n",
+                              Fout);
+                       return -EINVAL;
+               }
+       }
+       target = Fout * div;
+       fll_div->fll_outdiv = div - 1;
+
+       pr_debug("FLL Fvco=%dHz\n", target);
+
+       /* Find an appropraite FLL_FRATIO and factor it out of the target */
+       for (i = 0; i < ARRAY_SIZE(fll_fratios); i++) {
+               if (fll_fratios[i].min <= Fref && Fref <= fll_fratios[i].max) {
+                       fll_div->fll_fratio = fll_fratios[i].fll_fratio;
+                       fratio = fll_fratios[i].ratio;
+                       break;
+               }
+       }
+       if (i == ARRAY_SIZE(fll_fratios)) {
+               pr_err("Unable to find FLL_FRATIO for Fref=%uHz\n", Fref);
+               return -EINVAL;
+       }
+
+       fll_div->n = target / (fratio * Fref);
+
+       if (target % Fref == 0) {
+               fll_div->theta = 0;
+               fll_div->lambda = 0;
+       } else {
+               gcd_fll = gcd(target, fratio * Fref);
+
+               fll_div->theta = (target - (fll_div->n * fratio * Fref))
+                       / gcd_fll;
+               fll_div->lambda = (fratio * Fref) / gcd_fll;
+       }
+
+       pr_debug("FLL N=%x THETA=%x LAMBDA=%x\n",
+                fll_div->n, fll_div->theta, fll_div->lambda);
+       pr_debug("FLL_FRATIO=%x(%d) FLL_OUTDIV=%x FLL_REFCLK_DIV=%x\n",
+                fll_div->fll_fratio, fratio, fll_div->fll_outdiv,
+                fll_div->fll_refclk_div);
+
+       return 0;
+}
+
+static int wm5100_set_fll(struct snd_soc_codec *codec, int fll_id, int source,
+                         unsigned int Fref, unsigned int Fout)
+{
+       struct i2c_client *i2c = to_i2c_client(codec->dev);
+       struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
+       struct _fll_div factors;
+       struct wm5100_fll *fll;
+       int ret, base, lock, i, timeout;
+
+       switch (fll_id) {
+       case WM5100_FLL1:
+               fll = &wm5100->fll[0];
+               base = WM5100_FLL1_CONTROL_1 - 1;
+               lock = WM5100_FLL1_LOCK_STS;
+               break;
+       case WM5100_FLL2:
+               fll = &wm5100->fll[1];
+               base = WM5100_FLL2_CONTROL_2 - 1;
+               lock = WM5100_FLL2_LOCK_STS;
+               break;
+       default:
+               dev_err(codec->dev, "Unknown FLL %d\n",fll_id);
+               return -EINVAL;
+       }
+
+       if (!Fout) {
+               dev_dbg(codec->dev, "FLL%d disabled", fll_id);
+               fll->fout = 0;
+               snd_soc_update_bits(codec, base + 1, WM5100_FLL1_ENA, 0);
+               return 0;
+       }
+
+       switch (source) {
+       case WM5100_FLL_SRC_MCLK1:
+       case WM5100_FLL_SRC_MCLK2:
+       case WM5100_FLL_SRC_FLL1:
+       case WM5100_FLL_SRC_FLL2:
+       case WM5100_FLL_SRC_AIF1BCLK:
+       case WM5100_FLL_SRC_AIF2BCLK:
+       case WM5100_FLL_SRC_AIF3BCLK:
+               break;
+       default:
+               dev_err(codec->dev, "Invalid FLL source %d\n", source);
+               return -EINVAL;
+       }
+
+       ret = fll_factors(&factors, Fref, Fout);
+       if (ret < 0)
+               return ret;
+
+       /* Disable the FLL while we reconfigure */
+       snd_soc_update_bits(codec, base + 1, WM5100_FLL1_ENA, 0);
+
+       snd_soc_update_bits(codec, base + 2,
+                           WM5100_FLL1_OUTDIV_MASK | WM5100_FLL1_FRATIO_MASK,
+                           (factors.fll_outdiv << WM5100_FLL1_OUTDIV_SHIFT) |
+                           factors.fll_fratio);
+       snd_soc_update_bits(codec, base + 3, WM5100_FLL1_THETA_MASK,
+                           factors.theta);
+       snd_soc_update_bits(codec, base + 5, WM5100_FLL1_N_MASK, factors.n);
+       snd_soc_update_bits(codec, base + 6,
+                           WM5100_FLL1_REFCLK_DIV_MASK |
+                           WM5100_FLL1_REFCLK_SRC_MASK,
+                           (factors.fll_refclk_div
+                            << WM5100_FLL1_REFCLK_DIV_SHIFT) | source);
+       snd_soc_update_bits(codec, base + 7, WM5100_FLL1_LAMBDA_MASK,
+                           factors.lambda);
+
+       /* Clear any pending completions */
+       try_wait_for_completion(&fll->lock);
+
+       snd_soc_update_bits(codec, base + 1, WM5100_FLL1_ENA, WM5100_FLL1_ENA);
+
+       if (i2c->irq)
+               timeout = 2;
+       else
+               timeout = 50;
+
+       /* Poll for the lock; will use interrupt when we can test */
+       for (i = 0; i < timeout; i++) {
+               if (i2c->irq) {
+                       ret = wait_for_completion_timeout(&fll->lock,
+                                                         msecs_to_jiffies(25));
+                       if (ret > 0)
+                               break;
+               } else {
+                       msleep(1);
+               }
+
+               ret = snd_soc_read(codec,
+                                  WM5100_INTERRUPT_RAW_STATUS_3);
+               if (ret < 0) {
+                       dev_err(codec->dev,
+                               "Failed to read FLL status: %d\n",
+                               ret);
+                       continue;
+               }
+               if (ret & lock)
+                       break;
+       }
+       if (i == timeout) {
+               dev_err(codec->dev, "FLL%d lock timed out\n", fll_id);
+               return -ETIMEDOUT;
+       }
+
+       fll->src = source;
+       fll->fref = Fref;
+       fll->fout = Fout;
+
+       dev_dbg(codec->dev, "FLL%d running %dHz->%dHz\n", fll_id,
+               Fref, Fout);
+
+       return 0;
+}
+
+/* Actually go much higher */
+#define WM5100_RATES SNDRV_PCM_RATE_8000_192000
+
+#define WM5100_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
+                       SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
+
+static struct snd_soc_dai_driver wm5100_dai[] = {
+       {
+               .name = "wm5100-aif1",
+               .playback = {
+                       .stream_name = "AIF1 Playback",
+                       .channels_min = 2,
+                       .channels_max = 2,
+                       .rates = WM5100_RATES,
+                       .formats = WM5100_FORMATS,
+               },
+               .capture = {
+                        .stream_name = "AIF1 Capture",
+                        .channels_min = 2,
+                        .channels_max = 2,
+                        .rates = WM5100_RATES,
+                        .formats = WM5100_FORMATS,
+                },
+               .ops = &wm5100_dai_ops,
+       },
+       {
+               .name = "wm5100-aif2",
+               .id = 1,
+               .playback = {
+                       .stream_name = "AIF2 Playback",
+                       .channels_min = 2,
+                       .channels_max = 2,
+                       .rates = WM5100_RATES,
+                       .formats = WM5100_FORMATS,
+               },
+               .capture = {
+                        .stream_name = "AIF2 Capture",
+                        .channels_min = 2,
+                        .channels_max = 2,
+                        .rates = WM5100_RATES,
+                        .formats = WM5100_FORMATS,
+                },
+               .ops = &wm5100_dai_ops,
+       },
+       {
+               .name = "wm5100-aif3",
+               .id = 2,
+               .playback = {
+                       .stream_name = "AIF3 Playback",
+                       .channels_min = 2,
+                       .channels_max = 2,
+                       .rates = WM5100_RATES,
+                       .formats = WM5100_FORMATS,
+               },
+               .capture = {
+                        .stream_name = "AIF3 Capture",
+                        .channels_min = 2,
+                        .channels_max = 2,
+                        .rates = WM5100_RATES,
+                        .formats = WM5100_FORMATS,
+                },
+               .ops = &wm5100_dai_ops,
+       },
+};
+
+static int wm5100_dig_vu[] = {
+       WM5100_ADC_DIGITAL_VOLUME_1L,
+       WM5100_ADC_DIGITAL_VOLUME_1R,
+       WM5100_ADC_DIGITAL_VOLUME_2L,
+       WM5100_ADC_DIGITAL_VOLUME_2R,
+       WM5100_ADC_DIGITAL_VOLUME_3L,
+       WM5100_ADC_DIGITAL_VOLUME_3R,
+       WM5100_ADC_DIGITAL_VOLUME_4L,
+       WM5100_ADC_DIGITAL_VOLUME_4R,
+
+       WM5100_DAC_DIGITAL_VOLUME_1L,
+       WM5100_DAC_DIGITAL_VOLUME_1R,
+       WM5100_DAC_DIGITAL_VOLUME_2L,
+       WM5100_DAC_DIGITAL_VOLUME_2R,
+       WM5100_DAC_DIGITAL_VOLUME_3L,
+       WM5100_DAC_DIGITAL_VOLUME_3R,
+       WM5100_DAC_DIGITAL_VOLUME_4L,
+       WM5100_DAC_DIGITAL_VOLUME_4R,
+       WM5100_DAC_DIGITAL_VOLUME_5L,
+       WM5100_DAC_DIGITAL_VOLUME_5R,
+       WM5100_DAC_DIGITAL_VOLUME_6L,
+       WM5100_DAC_DIGITAL_VOLUME_6R,
+};
+
+static void wm5100_set_detect_mode(struct snd_soc_codec *codec, int the_mode)
+{
+       struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
+       struct wm5100_jack_mode *mode = &wm5100->pdata.jack_modes[the_mode];
+
+       BUG_ON(the_mode >= ARRAY_SIZE(wm5100->pdata.jack_modes));
+
+       gpio_set_value_cansleep(wm5100->pdata.hp_pol, mode->hp_pol);
+       snd_soc_update_bits(codec, WM5100_ACCESSORY_DETECT_MODE_1,
+                           WM5100_ACCDET_BIAS_SRC_MASK |
+                           WM5100_ACCDET_SRC,
+                           (mode->bias << WM5100_ACCDET_BIAS_SRC_SHIFT) |
+                           mode->micd_src << WM5100_ACCDET_SRC_SHIFT);
+       snd_soc_update_bits(codec, WM5100_MISC_CONTROL,
+                           WM5100_HPCOM_SRC,
+                           mode->micd_src << WM5100_HPCOM_SRC_SHIFT);
+
+       wm5100->jack_mode = the_mode;
+
+       dev_dbg(codec->dev, "Set microphone polarity to %d\n",
+               wm5100->jack_mode);
+}
+
+static void wm5100_micd_irq(struct snd_soc_codec *codec)
+{
+       struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
+       int val;
+
+       val = snd_soc_read(codec, WM5100_MIC_DETECT_3);
+
+       dev_dbg(codec->dev, "Microphone event: %x\n", val);
+
+       if (!(val & WM5100_ACCDET_VALID)) {
+               dev_warn(codec->dev, "Microphone detection state invalid\n");
+               return;
+       }
+
+       /* No accessory, reset everything and report removal */
+       if (!(val & WM5100_ACCDET_STS)) {
+               dev_dbg(codec->dev, "Jack removal detected\n");
+               wm5100->jack_mic = false;
+               wm5100->jack_detecting = true;
+               snd_soc_jack_report(wm5100->jack, 0,
+                                   SND_JACK_LINEOUT | SND_JACK_HEADSET |
+                                   SND_JACK_BTN_0);
+
+               snd_soc_update_bits(codec, WM5100_MIC_DETECT_1,
+                                   WM5100_ACCDET_RATE_MASK,
+                                   WM5100_ACCDET_RATE_MASK);
+               return;
+       }
+
+       /* If the measurement is very high we've got a microphone,
+        * either we just detected one or if we already reported then
+        * we've got a button release event.
+        */
+       if (val & 0x400) {
+               if (wm5100->jack_detecting) {
+                       dev_dbg(codec->dev, "Microphone detected\n");
+                       wm5100->jack_mic = true;
+                       snd_soc_jack_report(wm5100->jack,
+                                           SND_JACK_HEADSET,
+                                           SND_JACK_HEADSET | SND_JACK_BTN_0);
+
+                       /* Increase poll rate to give better responsiveness
+                        * for buttons */
+                       snd_soc_update_bits(codec, WM5100_MIC_DETECT_1,
+                                           WM5100_ACCDET_RATE_MASK,
+                                           5 << WM5100_ACCDET_RATE_SHIFT);
+               } else {
+                       dev_dbg(codec->dev, "Mic button up\n");
+                       snd_soc_jack_report(wm5100->jack, 0, SND_JACK_BTN_0);
+               }
+
+               return;
+       }
+
+       /* If we detected a lower impedence during initial startup
+        * then we probably have the wrong polarity, flip it.  Don't
+        * do this for the lowest impedences to speed up detection of
+        * plain headphones.
+        */
+       if (wm5100->jack_detecting && (val & 0x3f8)) {
+               wm5100_set_detect_mode(codec, !wm5100->jack_mode);
+
+               return;
+       }
+
+       /* Don't distinguish between buttons, just report any low
+        * impedence as BTN_0.
+        */
+       if (val & 0x3fc) {
+               if (wm5100->jack_mic) {
+                       dev_dbg(codec->dev, "Mic button detected\n");
+                       snd_soc_jack_report(wm5100->jack, SND_JACK_BTN_0,
+                                           SND_JACK_BTN_0);
+               } else if (wm5100->jack_detecting) {
+                       dev_dbg(codec->dev, "Headphone detected\n");
+                       snd_soc_jack_report(wm5100->jack, SND_JACK_HEADPHONE,
+                                           SND_JACK_HEADPHONE);
+
+                       /* Increase the detection rate a bit for
+                        * responsiveness.
+                        */
+                       snd_soc_update_bits(codec, WM5100_MIC_DETECT_1,
+                                           WM5100_ACCDET_RATE_MASK,
+                                           7 << WM5100_ACCDET_RATE_SHIFT);
+               }
+       }
+}
+
+int wm5100_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack)
+{
+       struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
+
+       if (jack) {
+               wm5100->jack = jack;
+               wm5100->jack_detecting = true;
+
+               wm5100_set_detect_mode(codec, 0);
+
+               /* Slowest detection rate, gives debounce for initial
+                * detection */
+               snd_soc_update_bits(codec, WM5100_MIC_DETECT_1,
+                                   WM5100_ACCDET_BIAS_STARTTIME_MASK |
+                                   WM5100_ACCDET_RATE_MASK,
+                                   (7 << WM5100_ACCDET_BIAS_STARTTIME_SHIFT) |
+                                   WM5100_ACCDET_RATE_MASK);
+
+               /* We need the charge pump to power MICBIAS */
+               snd_soc_dapm_force_enable_pin(&codec->dapm, "CP2");
+               snd_soc_dapm_force_enable_pin(&codec->dapm, "SYSCLK");
+               snd_soc_dapm_sync(&codec->dapm);
+
+               /* We start off just enabling microphone detection - even a
+                * plain headphone will trigger detection.
+                */
+               snd_soc_update_bits(codec, WM5100_MIC_DETECT_1,
+                                   WM5100_ACCDET_ENA, WM5100_ACCDET_ENA);
+
+               snd_soc_update_bits(codec, WM5100_INTERRUPT_STATUS_3_MASK,
+                                   WM5100_IM_ACCDET_EINT, 0);
+       } else {
+               snd_soc_update_bits(codec, WM5100_INTERRUPT_STATUS_3_MASK,
+                                   WM5100_IM_HPDET_EINT |
+                                   WM5100_IM_ACCDET_EINT,
+                                   WM5100_IM_HPDET_EINT |
+                                   WM5100_IM_ACCDET_EINT);
+               snd_soc_update_bits(codec, WM5100_MIC_DETECT_1,
+                                   WM5100_ACCDET_ENA, 0);
+               wm5100->jack = NULL;
+       }
+
+       return 0;
+}
+
+static irqreturn_t wm5100_irq(int irq, void *data)
+{
+       struct snd_soc_codec *codec = data;
+       struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
+       irqreturn_t status = IRQ_NONE;
+       int irq_val;
+
+       irq_val = snd_soc_read(codec, WM5100_INTERRUPT_STATUS_3);
+       if (irq_val < 0) {
+               dev_err(codec->dev, "Failed to read IRQ status 3: %d\n",
+                       irq_val);
+               irq_val = 0;
+       }
+       irq_val &= ~snd_soc_read(codec, WM5100_INTERRUPT_STATUS_3_MASK);
+
+       snd_soc_write(codec, WM5100_INTERRUPT_STATUS_3, irq_val);
+
+       if (irq_val)
+               status = IRQ_HANDLED;
+
+       wm5100_log_status3(codec, irq_val);
+
+       if (irq_val & WM5100_FLL1_LOCK_EINT) {
+               dev_dbg(codec->dev, "FLL1 locked\n");
+               complete(&wm5100->fll[0].lock);
+       }
+       if (irq_val & WM5100_FLL2_LOCK_EINT) {
+               dev_dbg(codec->dev, "FLL2 locked\n");
+               complete(&wm5100->fll[1].lock);
+       }
+
+       if (irq_val & WM5100_ACCDET_EINT)
+               wm5100_micd_irq(codec);
+
+       irq_val = snd_soc_read(codec, WM5100_INTERRUPT_STATUS_4);
+       if (irq_val < 0) {
+               dev_err(codec->dev, "Failed to read IRQ status 4: %d\n",
+                       irq_val);
+               irq_val = 0;
+       }
+       irq_val &= ~snd_soc_read(codec, WM5100_INTERRUPT_STATUS_4_MASK);
+
+       if (irq_val)
+               status = IRQ_HANDLED;
+
+       snd_soc_write(codec, WM5100_INTERRUPT_STATUS_4, irq_val);
+
+       wm5100_log_status4(codec, irq_val);
+
+       return status;
+}
+
+static irqreturn_t wm5100_edge_irq(int irq, void *data)
+{
+       irqreturn_t ret = IRQ_NONE;
+       irqreturn_t val;
+
+       do {
+               val = wm5100_irq(irq, data);
+               if (val != IRQ_NONE)
+                       ret = val;
+       } while (val != IRQ_NONE);
+
+       return ret;
+}
+
+#ifdef CONFIG_GPIOLIB
+static inline struct wm5100_priv *gpio_to_wm5100(struct gpio_chip *chip)
+{
+       return container_of(chip, struct wm5100_priv, gpio_chip);
+}
+
+static void wm5100_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
+{
+       struct wm5100_priv *wm5100 = gpio_to_wm5100(chip);
+       struct snd_soc_codec *codec = wm5100->codec;
+
+       snd_soc_update_bits(codec, WM5100_GPIO_CTRL_1 + offset,
+                           WM5100_GP1_LVL, !!value << WM5100_GP1_LVL_SHIFT);
+}
+
+static int wm5100_gpio_direction_out(struct gpio_chip *chip,
+                                    unsigned offset, int value)
+{
+       struct wm5100_priv *wm5100 = gpio_to_wm5100(chip);
+       struct snd_soc_codec *codec = wm5100->codec;
+       int val;
+
+       val = (1 << WM5100_GP1_FN_SHIFT) | (!!value << WM5100_GP1_LVL_SHIFT);
+
+       return snd_soc_update_bits(codec, WM5100_GPIO_CTRL_1 + offset,
+                                  WM5100_GP1_FN_MASK | WM5100_GP1_DIR |
+                                  WM5100_GP1_LVL, val);
+}
+
+static int wm5100_gpio_get(struct gpio_chip *chip, unsigned offset)
+{
+       struct wm5100_priv *wm5100 = gpio_to_wm5100(chip);
+       struct snd_soc_codec *codec = wm5100->codec;
+       int ret;
+
+       ret = snd_soc_read(codec, WM5100_GPIO_CTRL_1 + offset);
+       if (ret < 0)
+               return ret;
+
+       return (ret & WM5100_GP1_LVL) != 0;
+}
+
+static int wm5100_gpio_direction_in(struct gpio_chip *chip, unsigned offset)
+{
+       struct wm5100_priv *wm5100 = gpio_to_wm5100(chip);
+       struct snd_soc_codec *codec = wm5100->codec;
+
+       return snd_soc_update_bits(codec, WM5100_GPIO_CTRL_1 + offset,
+                                  WM5100_GP1_FN_MASK | WM5100_GP1_DIR,
+                                  (1 << WM5100_GP1_FN_SHIFT) |
+                                  (1 << WM5100_GP1_DIR_SHIFT));
+}
+
+static struct gpio_chip wm5100_template_chip = {
+       .label                  = "wm5100",
+       .owner                  = THIS_MODULE,
+       .direction_output       = wm5100_gpio_direction_out,
+       .set                    = wm5100_gpio_set,
+       .direction_input        = wm5100_gpio_direction_in,
+       .get                    = wm5100_gpio_get,
+       .can_sleep              = 1,
+};
+
+static void wm5100_init_gpio(struct snd_soc_codec *codec)
+{
+       struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
+       int ret;
+
+       wm5100->gpio_chip = wm5100_template_chip;
+       wm5100->gpio_chip.ngpio = 6;
+       wm5100->gpio_chip.dev = codec->dev;
+
+       if (wm5100->pdata.gpio_base)
+               wm5100->gpio_chip.base = wm5100->pdata.gpio_base;
+       else
+               wm5100->gpio_chip.base = -1;
+
+       ret = gpiochip_add(&wm5100->gpio_chip);
+       if (ret != 0)
+               dev_err(codec->dev, "Failed to add GPIOs: %d\n", ret);
+}
+
+static void wm5100_free_gpio(struct snd_soc_codec *codec)
+{
+       struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
+       int ret;
+
+       ret = gpiochip_remove(&wm5100->gpio_chip);
+       if (ret != 0)
+               dev_err(codec->dev, "Failed to remove GPIOs: %d\n", ret);
+}
+#else
+static void wm5100_init_gpio(struct snd_soc_codec *codec)
+{
+}
+
+static void wm5100_free_gpio(struct snd_soc_codec *codec)
+{
+}
+#endif
+
+static int wm5100_probe(struct snd_soc_codec *codec)
+{
+       struct i2c_client *i2c = to_i2c_client(codec->dev);
+       struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
+       int ret, i, irq_flags;
+
+       wm5100->codec = codec;
+
+       ret = snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_I2C);
+       if (ret != 0) {
+               dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
+               return ret;
+       }
+
+       for (i = 0; i < ARRAY_SIZE(wm5100->core_supplies); i++)
+               wm5100->core_supplies[i].supply = wm5100_core_supply_names[i];
+
+       ret = regulator_bulk_get(&i2c->dev, ARRAY_SIZE(wm5100->core_supplies),
+                                wm5100->core_supplies);
+       if (ret != 0) {
+               dev_err(codec->dev, "Failed to request core supplies: %d\n",
+                       ret);
+               return ret;
+       }
+
+       wm5100->cpvdd = regulator_get(&i2c->dev, "CPVDD");
+       if (IS_ERR(wm5100->cpvdd)) {
+               ret = PTR_ERR(wm5100->cpvdd);
+               dev_err(&i2c->dev, "Failed to get CPVDD: %d\n", ret);
+               goto err_core;
+       }
+
+       wm5100->dbvdd2 = regulator_get(&i2c->dev, "DBVDD2");
+       if (IS_ERR(wm5100->dbvdd2)) {
+               ret = PTR_ERR(wm5100->dbvdd2);
+               dev_err(&i2c->dev, "Failed to get DBVDD2: %d\n", ret);
+               goto err_cpvdd;
+       }
+
+       wm5100->dbvdd3 = regulator_get(&i2c->dev, "DBVDD3");
+       if (IS_ERR(wm5100->dbvdd3)) {
+               ret = PTR_ERR(wm5100->dbvdd3);
+               dev_err(&i2c->dev, "Failed to get DBVDD2: %d\n", ret);
+               goto err_dbvdd2;
+       }
+
+       ret = regulator_bulk_enable(ARRAY_SIZE(wm5100->core_supplies),
+                                   wm5100->core_supplies);
+       if (ret != 0) {
+               dev_err(codec->dev, "Failed to enable core supplies: %d\n",
+                       ret);
+               goto err_dbvdd3;
+       }
+
+       if (wm5100->pdata.ldo_ena) {
+               ret = gpio_request_one(wm5100->pdata.ldo_ena,
+                                      GPIOF_OUT_INIT_HIGH, "WM5100 LDOENA");
+               if (ret < 0) {
+                       dev_err(&i2c->dev, "Failed to request LDOENA %d: %d\n",
+                               wm5100->pdata.ldo_ena, ret);
+                       goto err_enable;
+               }
+               msleep(2);
+       }
+
+       if (wm5100->pdata.reset) {
+               ret = gpio_request_one(wm5100->pdata.reset,
+                                      GPIOF_OUT_INIT_HIGH, "WM5100 /RESET");
+               if (ret < 0) {
+                       dev_err(&i2c->dev, "Failed to request /RESET %d: %d\n",
+                               wm5100->pdata.reset, ret);
+                       goto err_ldo;
+               }
+       }
+
+       ret = snd_soc_read(codec, WM5100_SOFTWARE_RESET);
+       if (ret < 0) {
+               dev_err(codec->dev, "Failed to read ID register\n");
+               goto err_reset;
+       }
+       switch (ret) {
+       case 0x8997:
+       case 0x5100:
+               break;
+
+       default:
+               dev_err(codec->dev, "Device is not a WM5100, ID is %x\n", ret);
+               ret = -EINVAL;
+               goto err_reset;
+       }
+
+       ret = snd_soc_read(codec, WM5100_DEVICE_REVISION);
+       if (ret < 0) {
+               dev_err(codec->dev, "Failed to read revision register\n");
+               goto err_reset;
+       }
+       wm5100->rev = ret & WM5100_DEVICE_REVISION_MASK;
+
+       dev_info(codec->dev, "revision %c\n", wm5100->rev + 'A');
+
+       ret = wm5100_reset(codec);
+       if (ret < 0) {
+               dev_err(codec->dev, "Failed to issue reset\n");
+               goto err_reset;
+       }
+
+       codec->cache_only = true;
+
+       wm5100_init_gpio(codec);
+
+       for (i = 0; i < ARRAY_SIZE(wm5100_dig_vu); i++)
+               snd_soc_update_bits(codec, wm5100_dig_vu[i], WM5100_OUT_VU,
+                                   WM5100_OUT_VU);
+
+       for (i = 0; i < ARRAY_SIZE(wm5100->pdata.in_mode); i++) {
+               snd_soc_update_bits(codec, WM5100_IN1L_CONTROL,
+                                   WM5100_IN1_MODE_MASK |
+                                   WM5100_IN1_DMIC_SUP_MASK,
+                                   (wm5100->pdata.in_mode[i] <<
+                                    WM5100_IN1_MODE_SHIFT) |
+                                   (wm5100->pdata.dmic_sup[i] <<
+                                    WM5100_IN1_DMIC_SUP_SHIFT));
+       }
+
+       for (i = 0; i < ARRAY_SIZE(wm5100->pdata.gpio_defaults); i++) {
+               if (!wm5100->pdata.gpio_defaults[i])
+                       continue;
+
+               snd_soc_write(codec, WM5100_GPIO_CTRL_1 + i,
+                             wm5100->pdata.gpio_defaults[i]);
+       }
+
+       /* Don't debounce interrupts to support use of SYSCLK only */
+       snd_soc_write(codec, WM5100_IRQ_DEBOUNCE_1, 0);
+       snd_soc_write(codec, WM5100_IRQ_DEBOUNCE_2, 0);
+
+       /* TODO: check if we're symmetric */
+
+       if (i2c->irq) {
+               if (wm5100->pdata.irq_flags)
+                       irq_flags = wm5100->pdata.irq_flags;
+               else
+                       irq_flags = IRQF_TRIGGER_LOW;
+
+               irq_flags |= IRQF_ONESHOT;
+
+               if (irq_flags & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING))
+                       ret = request_threaded_irq(i2c->irq, NULL,
+                                                  wm5100_edge_irq,
+                                                  irq_flags, "wm5100", codec);
+               else
+                       ret = request_threaded_irq(i2c->irq, NULL, wm5100_irq,
+                                                  irq_flags, "wm5100", codec);
+
+               if (ret != 0) {
+                       dev_err(codec->dev, "Failed to request IRQ %d: %d\n",
+                               i2c->irq, ret);
+               } else {
+                       /* Enable default interrupts */
+                       snd_soc_update_bits(codec,
+                                           WM5100_INTERRUPT_STATUS_3_MASK,
+                                           WM5100_IM_SPK_SHUTDOWN_WARN_EINT |
+                                           WM5100_IM_SPK_SHUTDOWN_EINT |
+                                           WM5100_IM_ASRC2_LOCK_EINT |
+                                           WM5100_IM_ASRC1_LOCK_EINT |
+                                           WM5100_IM_FLL2_LOCK_EINT |
+                                           WM5100_IM_FLL1_LOCK_EINT |
+                                           WM5100_CLKGEN_ERR_EINT |
+                                           WM5100_CLKGEN_ERR_ASYNC_EINT, 0);
+
+                       snd_soc_update_bits(codec,
+                                           WM5100_INTERRUPT_STATUS_4_MASK,
+                                           WM5100_AIF3_ERR_EINT |
+                                           WM5100_AIF2_ERR_EINT |
+                                           WM5100_AIF1_ERR_EINT |
+                                           WM5100_CTRLIF_ERR_EINT |
+                                           WM5100_ISRC2_UNDERCLOCKED_EINT |
+                                           WM5100_ISRC1_UNDERCLOCKED_EINT |
+                                           WM5100_FX_UNDERCLOCKED_EINT |
+                                           WM5100_AIF3_UNDERCLOCKED_EINT |
+                                           WM5100_AIF2_UNDERCLOCKED_EINT |
+                                           WM5100_AIF1_UNDERCLOCKED_EINT |
+                                           WM5100_ASRC_UNDERCLOCKED_EINT |
+                                           WM5100_DAC_UNDERCLOCKED_EINT |
+                                           WM5100_ADC_UNDERCLOCKED_EINT |
+                                           WM5100_MIXER_UNDERCLOCKED_EINT, 0);
+               }
+       } else {
+               snd_soc_dapm_new_controls(&codec->dapm,
+                                         wm5100_dapm_widgets_noirq,
+                                         ARRAY_SIZE(wm5100_dapm_widgets_noirq));
+       }
+
+       if (wm5100->pdata.hp_pol) {
+               ret = gpio_request_one(wm5100->pdata.hp_pol,
+                                      GPIOF_OUT_INIT_HIGH, "WM5100 HP_POL");
+               if (ret < 0) {
+                       dev_err(&i2c->dev, "Failed to request HP_POL %d: %d\n",
+                               wm5100->pdata.hp_pol, ret);
+                       goto err_gpio;
+               }
+       }
+
+       /* We'll get woken up again when the system has something useful
+        * for us to do.
+        */
+       if (wm5100->pdata.ldo_ena)
+               gpio_set_value_cansleep(wm5100->pdata.ldo_ena, 0);
+       regulator_bulk_disable(ARRAY_SIZE(wm5100->core_supplies),
+                              wm5100->core_supplies);
+
+       return 0;
+
+err_gpio:
+       if (i2c->irq)
+               free_irq(i2c->irq, codec);
+       wm5100_free_gpio(codec);
+err_reset:
+       if (wm5100->pdata.reset) {
+               gpio_set_value_cansleep(wm5100->pdata.reset, 1);
+               gpio_free(wm5100->pdata.reset);
+       }
+err_ldo:
+       if (wm5100->pdata.ldo_ena) {
+               gpio_set_value_cansleep(wm5100->pdata.ldo_ena, 0);
+               gpio_free(wm5100->pdata.ldo_ena);
+       }
+err_enable:
+       regulator_bulk_disable(ARRAY_SIZE(wm5100->core_supplies),
+                              wm5100->core_supplies);
+err_dbvdd3:
+       regulator_put(wm5100->dbvdd3);
+err_dbvdd2:
+       regulator_put(wm5100->dbvdd2);
+err_cpvdd:
+       regulator_put(wm5100->cpvdd);
+err_core:
+       regulator_bulk_free(ARRAY_SIZE(wm5100->core_supplies),
+                           wm5100->core_supplies);
+
+       return ret;
+}
+
+static int wm5100_remove(struct snd_soc_codec *codec)
+{
+       struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
+       struct i2c_client *i2c = to_i2c_client(codec->dev);
+
+       wm5100_set_bias_level(codec, SND_SOC_BIAS_OFF);
+       if (wm5100->pdata.hp_pol) {
+               gpio_free(wm5100->pdata.hp_pol);
+       }
+       if (i2c->irq)
+               free_irq(i2c->irq, codec);
+       wm5100_free_gpio(codec);
+       if (wm5100->pdata.reset) {
+               gpio_set_value_cansleep(wm5100->pdata.reset, 1);
+               gpio_free(wm5100->pdata.reset);
+       }
+       if (wm5100->pdata.ldo_ena) {
+               gpio_set_value_cansleep(wm5100->pdata.ldo_ena, 0);
+               gpio_free(wm5100->pdata.ldo_ena);
+       }
+       regulator_put(wm5100->dbvdd3);
+       regulator_put(wm5100->dbvdd2);
+       regulator_put(wm5100->cpvdd);
+       regulator_bulk_free(ARRAY_SIZE(wm5100->core_supplies),
+                           wm5100->core_supplies);
+       return 0;
+}
+
+static struct snd_soc_codec_driver soc_codec_dev_wm5100 = {
+       .probe =        wm5100_probe,
+       .remove =       wm5100_remove,
+
+       .set_sysclk = wm5100_set_sysclk,
+       .set_pll = wm5100_set_fll,
+       .set_bias_level = wm5100_set_bias_level,
+       .idle_bias_off = 1,
+
+       .seq_notifier = wm5100_seq_notifier,
+       .controls = wm5100_snd_controls,
+       .num_controls = ARRAY_SIZE(wm5100_snd_controls),
+       .dapm_widgets = wm5100_dapm_widgets,
+       .num_dapm_widgets = ARRAY_SIZE(wm5100_dapm_widgets),
+       .dapm_routes = wm5100_dapm_routes,
+       .num_dapm_routes = ARRAY_SIZE(wm5100_dapm_routes),
+
+       .reg_cache_size = ARRAY_SIZE(wm5100_reg_defaults),
+       .reg_word_size = sizeof(u16),
+       .compress_type = SND_SOC_RBTREE_COMPRESSION,
+       .reg_cache_default = wm5100_reg_defaults,
+
+       .volatile_register = wm5100_volatile_register,
+       .readable_register = wm5100_readable_register,
+};
+
+static __devinit int wm5100_i2c_probe(struct i2c_client *i2c,
+                                     const struct i2c_device_id *id)
+{
+       struct wm5100_pdata *pdata = dev_get_platdata(&i2c->dev);
+       struct wm5100_priv *wm5100;
+       int ret, i;
+
+       wm5100 = kzalloc(sizeof(struct wm5100_priv), GFP_KERNEL);
+       if (wm5100 == NULL)
+               return -ENOMEM;
+
+       for (i = 0; i < ARRAY_SIZE(wm5100->fll); i++)
+               init_completion(&wm5100->fll[i].lock);
+
+       if (pdata)
+               wm5100->pdata = *pdata;
+
+       i2c_set_clientdata(i2c, wm5100);
+
+       ret = snd_soc_register_codec(&i2c->dev,
+                                    &soc_codec_dev_wm5100, wm5100_dai,
+                                    ARRAY_SIZE(wm5100_dai));
+       if (ret < 0) {
+               dev_err(&i2c->dev, "Failed to register WM5100: %d\n", ret);
+               kfree(wm5100);
+       }
+
+       return ret;
+}
+
+static __devexit int wm5100_i2c_remove(struct i2c_client *client)
+{
+       snd_soc_unregister_codec(&client->dev);
+       kfree(i2c_get_clientdata(client));
+       return 0;
+}
+
+static const struct i2c_device_id wm5100_i2c_id[] = {
+       { "wm5100", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, wm5100_i2c_id);
+
+static struct i2c_driver wm5100_i2c_driver = {
+       .driver = {
+               .name = "wm5100",
+               .owner = THIS_MODULE,
+       },
+       .probe =    wm5100_i2c_probe,
+       .remove =   __devexit_p(wm5100_i2c_remove),
+       .id_table = wm5100_i2c_id,
+};
+
+static int __init wm5100_modinit(void)
+{
+       return i2c_add_driver(&wm5100_i2c_driver);
+}
+module_init(wm5100_modinit);
+
+static void __exit wm5100_exit(void)
+{
+       i2c_del_driver(&wm5100_i2c_driver);
+}
+module_exit(wm5100_exit);
+
+MODULE_DESCRIPTION("ASoC WM5100 driver");
+MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/wm5100.h b/sound/soc/codecs/wm5100.h
new file mode 100644 (file)
index 0000000..9707596
--- /dev/null
@@ -0,0 +1,5155 @@
+/*
+ * wm5100.h  --  WM5100 ALSA SoC Audio driver
+ *
+ * Copyright 2011 Wolfson Microelectronics plc
+ *
+ * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef WM5100_ASOC_H
+#define WM5100_ASOC_H
+
+#include <sound/soc.h>
+
+int wm5100_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack);
+
+#define WM5100_CLK_AIF1     1
+#define WM5100_CLK_AIF2     2
+#define WM5100_CLK_AIF3     3
+#define WM5100_CLK_SYSCLK   4
+#define WM5100_CLK_ASYNCCLK 5
+#define WM5100_CLK_32KHZ    6
+#define WM5100_CLK_OPCLK    7
+
+#define WM5100_CLKSRC_MCLK1    0
+#define WM5100_CLKSRC_MCLK2    1
+#define WM5100_CLKSRC_SYSCLK   2
+#define WM5100_CLKSRC_FLL1     4
+#define WM5100_CLKSRC_FLL2     5
+#define WM5100_CLKSRC_AIF1BCLK 8
+#define WM5100_CLKSRC_AIF2BCLK 9
+#define WM5100_CLKSRC_AIF3BCLK 10
+#define WM5100_CLKSRC_ASYNCCLK 0x100
+
+#define WM5100_FLL1 1
+#define WM5100_FLL2 2
+
+#define WM5100_FLL_SRC_MCLK1    0x0
+#define WM5100_FLL_SRC_MCLK2    0x1
+#define WM5100_FLL_SRC_FLL1     0x4
+#define WM5100_FLL_SRC_FLL2     0x5
+#define WM5100_FLL_SRC_AIF1BCLK 0x8
+#define WM5100_FLL_SRC_AIF2BCLK 0x9
+#define WM5100_FLL_SRC_AIF3BCLK 0xa
+
+/*
+ * Register values.
+ */
+#define WM5100_SOFTWARE_RESET                   0x00
+#define WM5100_DEVICE_REVISION                  0x01
+#define WM5100_CTRL_IF_1                        0x10
+#define WM5100_TONE_GENERATOR_1                 0x20
+#define WM5100_PWM_DRIVE_1                      0x30
+#define WM5100_PWM_DRIVE_2                      0x31
+#define WM5100_PWM_DRIVE_3                      0x32
+#define WM5100_CLOCKING_1                       0x100
+#define WM5100_CLOCKING_3                       0x101
+#define WM5100_CLOCKING_4                       0x102
+#define WM5100_CLOCKING_5                       0x103
+#define WM5100_CLOCKING_6                       0x104
+#define WM5100_CLOCKING_7                       0x107
+#define WM5100_CLOCKING_8                       0x108
+#define WM5100_ASRC_ENABLE                      0x120
+#define WM5100_ASRC_STATUS                      0x121
+#define WM5100_ASRC_RATE1                       0x122
+#define WM5100_ISRC_1_CTRL_1                    0x141
+#define WM5100_ISRC_1_CTRL_2                    0x142
+#define WM5100_ISRC_2_CTRL1                     0x143
+#define WM5100_ISRC_2_CTRL_2                    0x144
+#define WM5100_FLL1_CONTROL_1                   0x182
+#define WM5100_FLL1_CONTROL_2                   0x183
+#define WM5100_FLL1_CONTROL_3                   0x184
+#define WM5100_FLL1_CONTROL_5                   0x186
+#define WM5100_FLL1_CONTROL_6                   0x187
+#define WM5100_FLL1_EFS_1                       0x188
+#define WM5100_FLL2_CONTROL_1                   0x1A2
+#define WM5100_FLL2_CONTROL_2                   0x1A3
+#define WM5100_FLL2_CONTROL_3                   0x1A4
+#define WM5100_FLL2_CONTROL_5                   0x1A6
+#define WM5100_FLL2_CONTROL_6                   0x1A7
+#define WM5100_FLL2_EFS_1                       0x1A8
+#define WM5100_MIC_CHARGE_PUMP_1                0x200
+#define WM5100_MIC_CHARGE_PUMP_2                0x201
+#define WM5100_HP_CHARGE_PUMP_1                 0x202
+#define WM5100_LDO1_CONTROL                     0x211
+#define WM5100_MIC_BIAS_CTRL_1                  0x215
+#define WM5100_MIC_BIAS_CTRL_2                  0x216
+#define WM5100_MIC_BIAS_CTRL_3                  0x217
+#define WM5100_ACCESSORY_DETECT_MODE_1          0x280
+#define WM5100_HEADPHONE_DETECT_1               0x288
+#define WM5100_HEADPHONE_DETECT_2               0x289
+#define WM5100_MIC_DETECT_1                     0x290
+#define WM5100_MIC_DETECT_2                     0x291
+#define WM5100_MIC_DETECT_3                     0x292
+#define WM5100_MISC_CONTROL                     0x2BB
+#define WM5100_INPUT_ENABLES                    0x301
+#define WM5100_INPUT_ENABLES_STATUS             0x302
+#define WM5100_IN1L_CONTROL                     0x310
+#define WM5100_IN1R_CONTROL                     0x311
+#define WM5100_IN2L_CONTROL                     0x312
+#define WM5100_IN2R_CONTROL                     0x313
+#define WM5100_IN3L_CONTROL                     0x314
+#define WM5100_IN3R_CONTROL                     0x315
+#define WM5100_IN4L_CONTROL                     0x316
+#define WM5100_IN4R_CONTROL                     0x317
+#define WM5100_RXANC_SRC                        0x318
+#define WM5100_INPUT_VOLUME_RAMP                0x319
+#define WM5100_ADC_DIGITAL_VOLUME_1L            0x320
+#define WM5100_ADC_DIGITAL_VOLUME_1R            0x321
+#define WM5100_ADC_DIGITAL_VOLUME_2L            0x322
+#define WM5100_ADC_DIGITAL_VOLUME_2R            0x323
+#define WM5100_ADC_DIGITAL_VOLUME_3L            0x324
+#define WM5100_ADC_DIGITAL_VOLUME_3R            0x325
+#define WM5100_ADC_DIGITAL_VOLUME_4L            0x326
+#define WM5100_ADC_DIGITAL_VOLUME_4R            0x327
+#define WM5100_OUTPUT_ENABLES_2                 0x401
+#define WM5100_OUTPUT_STATUS_1                  0x402
+#define WM5100_OUTPUT_STATUS_2                  0x403
+#define WM5100_CHANNEL_ENABLES_1                0x408
+#define WM5100_OUT_VOLUME_1L                    0x410
+#define WM5100_OUT_VOLUME_1R                    0x411
+#define WM5100_DAC_VOLUME_LIMIT_1L              0x412
+#define WM5100_DAC_VOLUME_LIMIT_1R              0x413
+#define WM5100_OUT_VOLUME_2L                    0x414
+#define WM5100_OUT_VOLUME_2R                    0x415
+#define WM5100_DAC_VOLUME_LIMIT_2L              0x416
+#define WM5100_DAC_VOLUME_LIMIT_2R              0x417
+#define WM5100_OUT_VOLUME_3L                    0x418
+#define WM5100_OUT_VOLUME_3R                    0x419
+#define WM5100_DAC_VOLUME_LIMIT_3L              0x41A
+#define WM5100_DAC_VOLUME_LIMIT_3R              0x41B
+#define WM5100_OUT_VOLUME_4L                    0x41C
+#define WM5100_OUT_VOLUME_4R                    0x41D
+#define WM5100_DAC_VOLUME_LIMIT_5L              0x41E
+#define WM5100_DAC_VOLUME_LIMIT_5R              0x41F
+#define WM5100_DAC_VOLUME_LIMIT_6L              0x420
+#define WM5100_DAC_VOLUME_LIMIT_6R              0x421
+#define WM5100_DAC_AEC_CONTROL_1                0x440
+#define WM5100_OUTPUT_VOLUME_RAMP               0x441
+#define WM5100_DAC_DIGITAL_VOLUME_1L            0x480
+#define WM5100_DAC_DIGITAL_VOLUME_1R            0x481
+#define WM5100_DAC_DIGITAL_VOLUME_2L            0x482
+#define WM5100_DAC_DIGITAL_VOLUME_2R            0x483
+#define WM5100_DAC_DIGITAL_VOLUME_3L            0x484
+#define WM5100_DAC_DIGITAL_VOLUME_3R            0x485
+#define WM5100_DAC_DIGITAL_VOLUME_4L            0x486
+#define WM5100_DAC_DIGITAL_VOLUME_4R            0x487
+#define WM5100_DAC_DIGITAL_VOLUME_5L            0x488
+#define WM5100_DAC_DIGITAL_VOLUME_5R            0x489
+#define WM5100_DAC_DIGITAL_VOLUME_6L            0x48A
+#define WM5100_DAC_DIGITAL_VOLUME_6R            0x48B
+#define WM5100_PDM_SPK1_CTRL_1                  0x4C0
+#define WM5100_PDM_SPK1_CTRL_2                  0x4C1
+#define WM5100_PDM_SPK2_CTRL_1                  0x4C2
+#define WM5100_PDM_SPK2_CTRL_2                  0x4C3
+#define WM5100_AUDIO_IF_1_1                     0x500
+#define WM5100_AUDIO_IF_1_2                     0x501
+#define WM5100_AUDIO_IF_1_3                     0x502
+#define WM5100_AUDIO_IF_1_4                     0x503
+#define WM5100_AUDIO_IF_1_5                     0x504
+#define WM5100_AUDIO_IF_1_6                     0x505
+#define WM5100_AUDIO_IF_1_7                     0x506
+#define WM5100_AUDIO_IF_1_8                     0x507
+#define WM5100_AUDIO_IF_1_9                     0x508
+#define WM5100_AUDIO_IF_1_10                    0x509
+#define WM5100_AUDIO_IF_1_11                    0x50A
+#define WM5100_AUDIO_IF_1_12                    0x50B
+#define WM5100_AUDIO_IF_1_13                    0x50C
+#define WM5100_AUDIO_IF_1_14                    0x50D
+#define WM5100_AUDIO_IF_1_15                    0x50E
+#define WM5100_AUDIO_IF_1_16                    0x50F
+#define WM5100_AUDIO_IF_1_17                    0x510
+#define WM5100_AUDIO_IF_1_18                    0x511
+#define WM5100_AUDIO_IF_1_19                    0x512
+#define WM5100_AUDIO_IF_1_20                    0x513
+#define WM5100_AUDIO_IF_1_21                    0x514
+#define WM5100_AUDIO_IF_1_22                    0x515
+#define WM5100_AUDIO_IF_1_23                    0x516
+#define WM5100_AUDIO_IF_1_24                    0x517
+#define WM5100_AUDIO_IF_1_25                    0x518
+#define WM5100_AUDIO_IF_1_26                    0x519
+#define WM5100_AUDIO_IF_1_27                    0x51A
+#define WM5100_AUDIO_IF_2_1                     0x540
+#define WM5100_AUDIO_IF_2_2                     0x541
+#define WM5100_AUDIO_IF_2_3                     0x542
+#define WM5100_AUDIO_IF_2_4                     0x543
+#define WM5100_AUDIO_IF_2_5                     0x544
+#define WM5100_AUDIO_IF_2_6                     0x545
+#define WM5100_AUDIO_IF_2_7                     0x546
+#define WM5100_AUDIO_IF_2_8                     0x547
+#define WM5100_AUDIO_IF_2_9                     0x548
+#define WM5100_AUDIO_IF_2_10                    0x549
+#define WM5100_AUDIO_IF_2_11                    0x54A
+#define WM5100_AUDIO_IF_2_18                    0x551
+#define WM5100_AUDIO_IF_2_19                    0x552
+#define WM5100_AUDIO_IF_2_26                    0x559
+#define WM5100_AUDIO_IF_2_27                    0x55A
+#define WM5100_AUDIO_IF_3_1                     0x580
+#define WM5100_AUDIO_IF_3_2                     0x581
+#define WM5100_AUDIO_IF_3_3                     0x582
+#define WM5100_AUDIO_IF_3_4                     0x583
+#define WM5100_AUDIO_IF_3_5                     0x584
+#define WM5100_AUDIO_IF_3_6                     0x585
+#define WM5100_AUDIO_IF_3_7                     0x586
+#define WM5100_AUDIO_IF_3_8                     0x587
+#define WM5100_AUDIO_IF_3_9                     0x588
+#define WM5100_AUDIO_IF_3_10                    0x589
+#define WM5100_AUDIO_IF_3_11                    0x58A
+#define WM5100_AUDIO_IF_3_18                    0x591
+#define WM5100_AUDIO_IF_3_19                    0x592
+#define WM5100_AUDIO_IF_3_26                    0x599
+#define WM5100_AUDIO_IF_3_27                    0x59A
+#define WM5100_PWM1MIX_INPUT_1_SOURCE           0x640
+#define WM5100_PWM1MIX_INPUT_1_VOLUME           0x641
+#define WM5100_PWM1MIX_INPUT_2_SOURCE           0x642
+#define WM5100_PWM1MIX_INPUT_2_VOLUME           0x643
+#define WM5100_PWM1MIX_INPUT_3_SOURCE           0x644
+#define WM5100_PWM1MIX_INPUT_3_VOLUME           0x645
+#define WM5100_PWM1MIX_INPUT_4_SOURCE           0x646
+#define WM5100_PWM1MIX_INPUT_4_VOLUME           0x647
+#define WM5100_PWM2MIX_INPUT_1_SOURCE           0x648
+#define WM5100_PWM2MIX_INPUT_1_VOLUME           0x649
+#define WM5100_PWM2MIX_INPUT_2_SOURCE           0x64A
+#define WM5100_PWM2MIX_INPUT_2_VOLUME           0x64B
+#define WM5100_PWM2MIX_INPUT_3_SOURCE           0x64C
+#define WM5100_PWM2MIX_INPUT_3_VOLUME           0x64D
+#define WM5100_PWM2MIX_INPUT_4_SOURCE           0x64E
+#define WM5100_PWM2MIX_INPUT_4_VOLUME           0x64F
+#define WM5100_OUT1LMIX_INPUT_1_SOURCE          0x680
+#define WM5100_OUT1LMIX_INPUT_1_VOLUME          0x681
+#define WM5100_OUT1LMIX_INPUT_2_SOURCE          0x682
+#define WM5100_OUT1LMIX_INPUT_2_VOLUME          0x683
+#define WM5100_OUT1LMIX_INPUT_3_SOURCE          0x684
+#define WM5100_OUT1LMIX_INPUT_3_VOLUME          0x685
+#define WM5100_OUT1LMIX_INPUT_4_SOURCE          0x686
+#define WM5100_OUT1LMIX_INPUT_4_VOLUME          0x687
+#define WM5100_OUT1RMIX_INPUT_1_SOURCE          0x688
+#define WM5100_OUT1RMIX_INPUT_1_VOLUME          0x689
+#define WM5100_OUT1RMIX_INPUT_2_SOURCE          0x68A
+#define WM5100_OUT1RMIX_INPUT_2_VOLUME          0x68B
+#define WM5100_OUT1RMIX_INPUT_3_SOURCE          0x68C
+#define WM5100_OUT1RMIX_INPUT_3_VOLUME          0x68D
+#define WM5100_OUT1RMIX_INPUT_4_SOURCE          0x68E
+#define WM5100_OUT1RMIX_INPUT_4_VOLUME          0x68F
+#define WM5100_OUT2LMIX_INPUT_1_SOURCE          0x690
+#define WM5100_OUT2LMIX_INPUT_1_VOLUME          0x691
+#define WM5100_OUT2LMIX_INPUT_2_SOURCE          0x692
+#define WM5100_OUT2LMIX_INPUT_2_VOLUME          0x693
+#define WM5100_OUT2LMIX_INPUT_3_SOURCE          0x694
+#define WM5100_OUT2LMIX_INPUT_3_VOLUME          0x695
+#define WM5100_OUT2LMIX_INPUT_4_SOURCE          0x696
+#define WM5100_OUT2LMIX_INPUT_4_VOLUME          0x697
+#define WM5100_OUT2RMIX_INPUT_1_SOURCE          0x698
+#define WM5100_OUT2RMIX_INPUT_1_VOLUME          0x699
+#define WM5100_OUT2RMIX_INPUT_2_SOURCE          0x69A
+#define WM5100_OUT2RMIX_INPUT_2_VOLUME          0x69B
+#define WM5100_OUT2RMIX_INPUT_3_SOURCE          0x69C
+#define WM5100_OUT2RMIX_INPUT_3_VOLUME          0x69D
+#define WM5100_OUT2RMIX_INPUT_4_SOURCE          0x69E
+#define WM5100_OUT2RMIX_INPUT_4_VOLUME          0x69F
+#define WM5100_OUT3LMIX_INPUT_1_SOURCE          0x6A0
+#define WM5100_OUT3LMIX_INPUT_1_VOLUME          0x6A1
+#define WM5100_OUT3LMIX_INPUT_2_SOURCE          0x6A2
+#define WM5100_OUT3LMIX_INPUT_2_VOLUME          0x6A3
+#define WM5100_OUT3LMIX_INPUT_3_SOURCE          0x6A4
+#define WM5100_OUT3LMIX_INPUT_3_VOLUME          0x6A5
+#define WM5100_OUT3LMIX_INPUT_4_SOURCE          0x6A6
+#define WM5100_OUT3LMIX_INPUT_4_VOLUME          0x6A7
+#define WM5100_OUT3RMIX_INPUT_1_SOURCE          0x6A8
+#define WM5100_OUT3RMIX_INPUT_1_VOLUME          0x6A9
+#define WM5100_OUT3RMIX_INPUT_2_SOURCE          0x6AA
+#define WM5100_OUT3RMIX_INPUT_2_VOLUME          0x6AB
+#define WM5100_OUT3RMIX_INPUT_3_SOURCE          0x6AC
+#define WM5100_OUT3RMIX_INPUT_3_VOLUME          0x6AD
+#define WM5100_OUT3RMIX_INPUT_4_SOURCE          0x6AE
+#define WM5100_OUT3RMIX_INPUT_4_VOLUME          0x6AF
+#define WM5100_OUT4LMIX_INPUT_1_SOURCE          0x6B0
+#define WM5100_OUT4LMIX_INPUT_1_VOLUME          0x6B1
+#define WM5100_OUT4LMIX_INPUT_2_SOURCE          0x6B2
+#define WM5100_OUT4LMIX_INPUT_2_VOLUME          0x6B3
+#define WM5100_OUT4LMIX_INPUT_3_SOURCE          0x6B4
+#define WM5100_OUT4LMIX_INPUT_3_VOLUME          0x6B5
+#define WM5100_OUT4LMIX_INPUT_4_SOURCE          0x6B6
+#define WM5100_OUT4LMIX_INPUT_4_VOLUME          0x6B7
+#define WM5100_OUT4RMIX_INPUT_1_SOURCE          0x6B8
+#define WM5100_OUT4RMIX_INPUT_1_VOLUME          0x6B9
+#define WM5100_OUT4RMIX_INPUT_2_SOURCE          0x6BA
+#define WM5100_OUT4RMIX_INPUT_2_VOLUME          0x6BB
+#define WM5100_OUT4RMIX_INPUT_3_SOURCE          0x6BC
+#define WM5100_OUT4RMIX_INPUT_3_VOLUME          0x6BD
+#define WM5100_OUT4RMIX_INPUT_4_SOURCE          0x6BE
+#define WM5100_OUT4RMIX_INPUT_4_VOLUME          0x6BF
+#define WM5100_OUT5LMIX_INPUT_1_SOURCE          0x6C0
+#define WM5100_OUT5LMIX_INPUT_1_VOLUME          0x6C1
+#define WM5100_OUT5LMIX_INPUT_2_SOURCE          0x6C2
+#define WM5100_OUT5LMIX_INPUT_2_VOLUME          0x6C3
+#define WM5100_OUT5LMIX_INPUT_3_SOURCE          0x6C4
+#define WM5100_OUT5LMIX_INPUT_3_VOLUME          0x6C5
+#define WM5100_OUT5LMIX_INPUT_4_SOURCE          0x6C6
+#define WM5100_OUT5LMIX_INPUT_4_VOLUME          0x6C7
+#define WM5100_OUT5RMIX_INPUT_1_SOURCE          0x6C8
+#define WM5100_OUT5RMIX_INPUT_1_VOLUME          0x6C9
+#define WM5100_OUT5RMIX_INPUT_2_SOURCE          0x6CA
+#define WM5100_OUT5RMIX_INPUT_2_VOLUME          0x6CB
+#define WM5100_OUT5RMIX_INPUT_3_SOURCE          0x6CC
+#define WM5100_OUT5RMIX_INPUT_3_VOLUME          0x6CD
+#define WM5100_OUT5RMIX_INPUT_4_SOURCE          0x6CE
+#define WM5100_OUT5RMIX_INPUT_4_VOLUME          0x6CF
+#define WM5100_OUT6LMIX_INPUT_1_SOURCE          0x6D0
+#define WM5100_OUT6LMIX_INPUT_1_VOLUME          0x6D1
+#define WM5100_OUT6LMIX_INPUT_2_SOURCE          0x6D2
+#define WM5100_OUT6LMIX_INPUT_2_VOLUME          0x6D3
+#define WM5100_OUT6LMIX_INPUT_3_SOURCE          0x6D4
+#define WM5100_OUT6LMIX_INPUT_3_VOLUME          0x6D5
+#define WM5100_OUT6LMIX_INPUT_4_SOURCE          0x6D6
+#define WM5100_OUT6LMIX_INPUT_4_VOLUME          0x6D7
+#define WM5100_OUT6RMIX_INPUT_1_SOURCE          0x6D8
+#define WM5100_OUT6RMIX_INPUT_1_VOLUME          0x6D9
+#define WM5100_OUT6RMIX_INPUT_2_SOURCE          0x6DA
+#define WM5100_OUT6RMIX_INPUT_2_VOLUME          0x6DB
+#define WM5100_OUT6RMIX_INPUT_3_SOURCE          0x6DC
+#define WM5100_OUT6RMIX_INPUT_3_VOLUME          0x6DD
+#define WM5100_OUT6RMIX_INPUT_4_SOURCE          0x6DE
+#define WM5100_OUT6RMIX_INPUT_4_VOLUME          0x6DF
+#define WM5100_AIF1TX1MIX_INPUT_1_SOURCE        0x700
+#define WM5100_AIF1TX1MIX_INPUT_1_VOLUME        0x701
+#define WM5100_AIF1TX1MIX_INPUT_2_SOURCE        0x702
+#define WM5100_AIF1TX1MIX_INPUT_2_VOLUME        0x703
+#define WM5100_AIF1TX1MIX_INPUT_3_SOURCE        0x704
+#define WM5100_AIF1TX1MIX_INPUT_3_VOLUME        0x705
+#define WM5100_AIF1TX1MIX_INPUT_4_SOURCE        0x706
+#define WM5100_AIF1TX1MIX_INPUT_4_VOLUME        0x707
+#define WM5100_AIF1TX2MIX_INPUT_1_SOURCE        0x708
+#define WM5100_AIF1TX2MIX_INPUT_1_VOLUME        0x709
+#define WM5100_AIF1TX2MIX_INPUT_2_SOURCE        0x70A
+#define WM5100_AIF1TX2MIX_INPUT_2_VOLUME        0x70B
+#define WM5100_AIF1TX2MIX_INPUT_3_SOURCE        0x70C
+#define WM5100_AIF1TX2MIX_INPUT_3_VOLUME        0x70D
+#define WM5100_AIF1TX2MIX_INPUT_4_SOURCE        0x70E
+#define WM5100_AIF1TX2MIX_INPUT_4_VOLUME        0x70F
+#define WM5100_AIF1TX3MIX_INPUT_1_SOURCE        0x710
+#define WM5100_AIF1TX3MIX_INPUT_1_VOLUME        0x711
+#define WM5100_AIF1TX3MIX_INPUT_2_SOURCE        0x712
+#define WM5100_AIF1TX3MIX_INPUT_2_VOLUME        0x713
+#define WM5100_AIF1TX3MIX_INPUT_3_SOURCE        0x714
+#define WM5100_AIF1TX3MIX_INPUT_3_VOLUME        0x715
+#define WM5100_AIF1TX3MIX_INPUT_4_SOURCE        0x716
+#define WM5100_AIF1TX3MIX_INPUT_4_VOLUME        0x717
+#define WM5100_AIF1TX4MIX_INPUT_1_SOURCE        0x718
+#define WM5100_AIF1TX4MIX_INPUT_1_VOLUME        0x719
+#define WM5100_AIF1TX4MIX_INPUT_2_SOURCE        0x71A
+#define WM5100_AIF1TX4MIX_INPUT_2_VOLUME        0x71B
+#define WM5100_AIF1TX4MIX_INPUT_3_SOURCE        0x71C
+#define WM5100_AIF1TX4MIX_INPUT_3_VOLUME        0x71D
+#define WM5100_AIF1TX4MIX_INPUT_4_SOURCE        0x71E
+#define WM5100_AIF1TX4MIX_INPUT_4_VOLUME        0x71F
+#define WM5100_AIF1TX5MIX_INPUT_1_SOURCE        0x720
+#define WM5100_AIF1TX5MIX_INPUT_1_VOLUME        0x721
+#define WM5100_AIF1TX5MIX_INPUT_2_SOURCE        0x722
+#define WM5100_AIF1TX5MIX_INPUT_2_VOLUME        0x723
+#define WM5100_AIF1TX5MIX_INPUT_3_SOURCE        0x724
+#define WM5100_AIF1TX5MIX_INPUT_3_VOLUME        0x725
+#define WM5100_AIF1TX5MIX_INPUT_4_SOURCE        0x726
+#define WM5100_AIF1TX5MIX_INPUT_4_VOLUME        0x727
+#define WM5100_AIF1TX6MIX_INPUT_1_SOURCE        0x728
+#define WM5100_AIF1TX6MIX_INPUT_1_VOLUME        0x729
+#define WM5100_AIF1TX6MIX_INPUT_2_SOURCE        0x72A
+#define WM5100_AIF1TX6MIX_INPUT_2_VOLUME        0x72B
+#define WM5100_AIF1TX6MIX_INPUT_3_SOURCE        0x72C
+#define WM5100_AIF1TX6MIX_INPUT_3_VOLUME        0x72D
+#define WM5100_AIF1TX6MIX_INPUT_4_SOURCE        0x72E
+#define WM5100_AIF1TX6MIX_INPUT_4_VOLUME        0x72F
+#define WM5100_AIF1TX7MIX_INPUT_1_SOURCE        0x730
+#define WM5100_AIF1TX7MIX_INPUT_1_VOLUME        0x731
+#define WM5100_AIF1TX7MIX_INPUT_2_SOURCE        0x732
+#define WM5100_AIF1TX7MIX_INPUT_2_VOLUME        0x733
+#define WM5100_AIF1TX7MIX_INPUT_3_SOURCE        0x734
+#define WM5100_AIF1TX7MIX_INPUT_3_VOLUME        0x735
+#define WM5100_AIF1TX7MIX_INPUT_4_SOURCE        0x736
+#define WM5100_AIF1TX7MIX_INPUT_4_VOLUME        0x737
+#define WM5100_AIF1TX8MIX_INPUT_1_SOURCE        0x738
+#define WM5100_AIF1TX8MIX_INPUT_1_VOLUME        0x739
+#define WM5100_AIF1TX8MIX_INPUT_2_SOURCE        0x73A
+#define WM5100_AIF1TX8MIX_INPUT_2_VOLUME        0x73B
+#define WM5100_AIF1TX8MIX_INPUT_3_SOURCE        0x73C
+#define WM5100_AIF1TX8MIX_INPUT_3_VOLUME        0x73D
+#define WM5100_AIF1TX8MIX_INPUT_4_SOURCE        0x73E
+#define WM5100_AIF1TX8MIX_INPUT_4_VOLUME        0x73F
+#define WM5100_AIF2TX1MIX_INPUT_1_SOURCE        0x740
+#define WM5100_AIF2TX1MIX_INPUT_1_VOLUME        0x741
+#define WM5100_AIF2TX1MIX_INPUT_2_SOURCE        0x742
+#define WM5100_AIF2TX1MIX_INPUT_2_VOLUME        0x743
+#define WM5100_AIF2TX1MIX_INPUT_3_SOURCE        0x744
+#define WM5100_AIF2TX1MIX_INPUT_3_VOLUME        0x745
+#define WM5100_AIF2TX1MIX_INPUT_4_SOURCE        0x746
+#define WM5100_AIF2TX1MIX_INPUT_4_VOLUME        0x747
+#define WM5100_AIF2TX2MIX_INPUT_1_SOURCE        0x748
+#define WM5100_AIF2TX2MIX_INPUT_1_VOLUME        0x749
+#define WM5100_AIF2TX2MIX_INPUT_2_SOURCE        0x74A
+#define WM5100_AIF2TX2MIX_INPUT_2_VOLUME        0x74B
+#define WM5100_AIF2TX2MIX_INPUT_3_SOURCE        0x74C
+#define WM5100_AIF2TX2MIX_INPUT_3_VOLUME        0x74D
+#define WM5100_AIF2TX2MIX_INPUT_4_SOURCE        0x74E
+#define WM5100_AIF2TX2MIX_INPUT_4_VOLUME        0x74F
+#define WM5100_AIF3TX1MIX_INPUT_1_SOURCE        0x780
+#define WM5100_AIF3TX1MIX_INPUT_1_VOLUME        0x781
+#define WM5100_AIF3TX1MIX_INPUT_2_SOURCE        0x782
+#define WM5100_AIF3TX1MIX_INPUT_2_VOLUME        0x783
+#define WM5100_AIF3TX1MIX_INPUT_3_SOURCE        0x784
+#define WM5100_AIF3TX1MIX_INPUT_3_VOLUME        0x785
+#define WM5100_AIF3TX1MIX_INPUT_4_SOURCE        0x786
+#define WM5100_AIF3TX1MIX_INPUT_4_VOLUME        0x787
+#define WM5100_AIF3TX2MIX_INPUT_1_SOURCE        0x788
+#define WM5100_AIF3TX2MIX_INPUT_1_VOLUME        0x789
+#define WM5100_AIF3TX2MIX_INPUT_2_SOURCE        0x78A
+#define WM5100_AIF3TX2MIX_INPUT_2_VOLUME        0x78B
+#define WM5100_AIF3TX2MIX_INPUT_3_SOURCE        0x78C
+#define WM5100_AIF3TX2MIX_INPUT_3_VOLUME        0x78D
+#define WM5100_AIF3TX2MIX_INPUT_4_SOURCE        0x78E
+#define WM5100_AIF3TX2MIX_INPUT_4_VOLUME        0x78F
+#define WM5100_EQ1MIX_INPUT_1_SOURCE            0x880
+#define WM5100_EQ1MIX_INPUT_1_VOLUME            0x881
+#define WM5100_EQ1MIX_INPUT_2_SOURCE            0x882
+#define WM5100_EQ1MIX_INPUT_2_VOLUME            0x883
+#define WM5100_EQ1MIX_INPUT_3_SOURCE            0x884
+#define WM5100_EQ1MIX_INPUT_3_VOLUME            0x885
+#define WM5100_EQ1MIX_INPUT_4_SOURCE            0x886
+#define WM5100_EQ1MIX_INPUT_4_VOLUME            0x887
+#define WM5100_EQ2MIX_INPUT_1_SOURCE            0x888
+#define WM5100_EQ2MIX_INPUT_1_VOLUME            0x889
+#define WM5100_EQ2MIX_INPUT_2_SOURCE            0x88A
+#define WM5100_EQ2MIX_INPUT_2_VOLUME            0x88B
+#define WM5100_EQ2MIX_INPUT_3_SOURCE            0x88C
+#define WM5100_EQ2MIX_INPUT_3_VOLUME            0x88D
+#define WM5100_EQ2MIX_INPUT_4_SOURCE            0x88E
+#define WM5100_EQ2MIX_INPUT_4_VOLUME            0x88F
+#define WM5100_EQ3MIX_INPUT_1_SOURCE            0x890
+#define WM5100_EQ3MIX_INPUT_1_VOLUME            0x891
+#define WM5100_EQ3MIX_INPUT_2_SOURCE            0x892
+#define WM5100_EQ3MIX_INPUT_2_VOLUME            0x893
+#define WM5100_EQ3MIX_INPUT_3_SOURCE            0x894
+#define WM5100_EQ3MIX_INPUT_3_VOLUME            0x895
+#define WM5100_EQ3MIX_INPUT_4_SOURCE            0x896
+#define WM5100_EQ3MIX_INPUT_4_VOLUME            0x897
+#define WM5100_EQ4MIX_INPUT_1_SOURCE            0x898
+#define WM5100_EQ4MIX_INPUT_1_VOLUME            0x899
+#define WM5100_EQ4MIX_INPUT_2_SOURCE            0x89A
+#define WM5100_EQ4MIX_INPUT_2_VOLUME            0x89B
+#define WM5100_EQ4MIX_INPUT_3_SOURCE            0x89C
+#define WM5100_EQ4MIX_INPUT_3_VOLUME            0x89D
+#define WM5100_EQ4MIX_INPUT_4_SOURCE            0x89E
+#define WM5100_EQ4MIX_INPUT_4_VOLUME            0x89F
+#define WM5100_DRC1LMIX_INPUT_1_SOURCE          0x8C0
+#define WM5100_DRC1LMIX_INPUT_1_VOLUME          0x8C1
+#define WM5100_DRC1LMIX_INPUT_2_SOURCE          0x8C2
+#define WM5100_DRC1LMIX_INPUT_2_VOLUME          0x8C3
+#define WM5100_DRC1LMIX_INPUT_3_SOURCE          0x8C4
+#define WM5100_DRC1LMIX_INPUT_3_VOLUME          0x8C5
+#define WM5100_DRC1LMIX_INPUT_4_SOURCE          0x8C6
+#define WM5100_DRC1LMIX_INPUT_4_VOLUME          0x8C7
+#define WM5100_DRC1RMIX_INPUT_1_SOURCE          0x8C8
+#define WM5100_DRC1RMIX_INPUT_1_VOLUME          0x8C9
+#define WM5100_DRC1RMIX_INPUT_2_SOURCE          0x8CA
+#define WM5100_DRC1RMIX_INPUT_2_VOLUME          0x8CB
+#define WM5100_DRC1RMIX_INPUT_3_SOURCE          0x8CC
+#define WM5100_DRC1RMIX_INPUT_3_VOLUME          0x8CD
+#define WM5100_DRC1RMIX_INPUT_4_SOURCE          0x8CE
+#define WM5100_DRC1RMIX_INPUT_4_VOLUME          0x8CF
+#define WM5100_HPLP1MIX_INPUT_1_SOURCE          0x900
+#define WM5100_HPLP1MIX_INPUT_1_VOLUME          0x901
+#define WM5100_HPLP1MIX_INPUT_2_SOURCE          0x902
+#define WM5100_HPLP1MIX_INPUT_2_VOLUME          0x903
+#define WM5100_HPLP1MIX_INPUT_3_SOURCE          0x904
+#define WM5100_HPLP1MIX_INPUT_3_VOLUME          0x905
+#define WM5100_HPLP1MIX_INPUT_4_SOURCE          0x906
+#define WM5100_HPLP1MIX_INPUT_4_VOLUME          0x907
+#define WM5100_HPLP2MIX_INPUT_1_SOURCE          0x908
+#define WM5100_HPLP2MIX_INPUT_1_VOLUME          0x909
+#define WM5100_HPLP2MIX_INPUT_2_SOURCE          0x90A
+#define WM5100_HPLP2MIX_INPUT_2_VOLUME          0x90B
+#define WM5100_HPLP2MIX_INPUT_3_SOURCE          0x90C
+#define WM5100_HPLP2MIX_INPUT_3_VOLUME          0x90D
+#define WM5100_HPLP2MIX_INPUT_4_SOURCE          0x90E
+#define WM5100_HPLP2MIX_INPUT_4_VOLUME          0x90F
+#define WM5100_HPLP3MIX_INPUT_1_SOURCE          0x910
+#define WM5100_HPLP3MIX_INPUT_1_VOLUME          0x911
+#define WM5100_HPLP3MIX_INPUT_2_SOURCE          0x912
+#define WM5100_HPLP3MIX_INPUT_2_VOLUME          0x913
+#define WM5100_HPLP3MIX_INPUT_3_SOURCE          0x914
+#define WM5100_HPLP3MIX_INPUT_3_VOLUME          0x915
+#define WM5100_HPLP3MIX_INPUT_4_SOURCE          0x916
+#define WM5100_HPLP3MIX_INPUT_4_VOLUME          0x917
+#define WM5100_HPLP4MIX_INPUT_1_SOURCE          0x918
+#define WM5100_HPLP4MIX_INPUT_1_VOLUME          0x919
+#define WM5100_HPLP4MIX_INPUT_2_SOURCE          0x91A
+#define WM5100_HPLP4MIX_INPUT_2_VOLUME          0x91B
+#define WM5100_HPLP4MIX_INPUT_3_SOURCE          0x91C
+#define WM5100_HPLP4MIX_INPUT_3_VOLUME          0x91D
+#define WM5100_HPLP4MIX_INPUT_4_SOURCE          0x91E
+#define WM5100_HPLP4MIX_INPUT_4_VOLUME          0x91F
+#define WM5100_DSP1LMIX_INPUT_1_SOURCE          0x940
+#define WM5100_DSP1LMIX_INPUT_1_VOLUME          0x941
+#define WM5100_DSP1LMIX_INPUT_2_SOURCE          0x942
+#define WM5100_DSP1LMIX_INPUT_2_VOLUME          0x943
+#define WM5100_DSP1LMIX_INPUT_3_SOURCE          0x944
+#define WM5100_DSP1LMIX_INPUT_3_VOLUME          0x945
+#define WM5100_DSP1LMIX_INPUT_4_SOURCE          0x946
+#define WM5100_DSP1LMIX_INPUT_4_VOLUME          0x947
+#define WM5100_DSP1RMIX_INPUT_1_SOURCE          0x948
+#define WM5100_DSP1RMIX_INPUT_1_VOLUME          0x949
+#define WM5100_DSP1RMIX_INPUT_2_SOURCE          0x94A
+#define WM5100_DSP1RMIX_INPUT_2_VOLUME          0x94B
+#define WM5100_DSP1RMIX_INPUT_3_SOURCE          0x94C
+#define WM5100_DSP1RMIX_INPUT_3_VOLUME          0x94D
+#define WM5100_DSP1RMIX_INPUT_4_SOURCE          0x94E
+#define WM5100_DSP1RMIX_INPUT_4_VOLUME          0x94F
+#define WM5100_DSP1AUX1MIX_INPUT_1_SOURCE       0x950
+#define WM5100_DSP1AUX2MIX_INPUT_1_SOURCE       0x958
+#define WM5100_DSP1AUX3MIX_INPUT_1_SOURCE       0x960
+#define WM5100_DSP1AUX4MIX_INPUT_1_SOURCE       0x968
+#define WM5100_DSP1AUX5MIX_INPUT_1_SOURCE       0x970
+#define WM5100_DSP1AUX6MIX_INPUT_1_SOURCE       0x978
+#define WM5100_DSP2LMIX_INPUT_1_SOURCE          0x980
+#define WM5100_DSP2LMIX_INPUT_1_VOLUME          0x981
+#define WM5100_DSP2LMIX_INPUT_2_SOURCE          0x982
+#define WM5100_DSP2LMIX_INPUT_2_VOLUME          0x983
+#define WM5100_DSP2LMIX_INPUT_3_SOURCE          0x984
+#define WM5100_DSP2LMIX_INPUT_3_VOLUME          0x985
+#define WM5100_DSP2LMIX_INPUT_4_SOURCE          0x986
+#define WM5100_DSP2LMIX_INPUT_4_VOLUME          0x987
+#define WM5100_DSP2RMIX_INPUT_1_SOURCE          0x988
+#define WM5100_DSP2RMIX_INPUT_1_VOLUME          0x989
+#define WM5100_DSP2RMIX_INPUT_2_SOURCE          0x98A
+#define WM5100_DSP2RMIX_INPUT_2_VOLUME          0x98B
+#define WM5100_DSP2RMIX_INPUT_3_SOURCE          0x98C
+#define WM5100_DSP2RMIX_INPUT_3_VOLUME          0x98D
+#define WM5100_DSP2RMIX_INPUT_4_SOURCE          0x98E
+#define WM5100_DSP2RMIX_INPUT_4_VOLUME          0x98F
+#define WM5100_DSP2AUX1MIX_INPUT_1_SOURCE       0x990
+#define WM5100_DSP2AUX2MIX_INPUT_1_SOURCE       0x998
+#define WM5100_DSP2AUX3MIX_INPUT_1_SOURCE       0x9A0
+#define WM5100_DSP2AUX4MIX_INPUT_1_SOURCE       0x9A8
+#define WM5100_DSP2AUX5MIX_INPUT_1_SOURCE       0x9B0
+#define WM5100_DSP2AUX6MIX_INPUT_1_SOURCE       0x9B8
+#define WM5100_DSP3LMIX_INPUT_1_SOURCE          0x9C0
+#define WM5100_DSP3LMIX_INPUT_1_VOLUME          0x9C1
+#define WM5100_DSP3LMIX_INPUT_2_SOURCE          0x9C2
+#define WM5100_DSP3LMIX_INPUT_2_VOLUME          0x9C3
+#define WM5100_DSP3LMIX_INPUT_3_SOURCE          0x9C4
+#define WM5100_DSP3LMIX_INPUT_3_VOLUME          0x9C5
+#define WM5100_DSP3LMIX_INPUT_4_SOURCE          0x9C6
+#define WM5100_DSP3LMIX_INPUT_4_VOLUME          0x9C7
+#define WM5100_DSP3RMIX_INPUT_1_SOURCE          0x9C8
+#define WM5100_DSP3RMIX_INPUT_1_VOLUME          0x9C9
+#define WM5100_DSP3RMIX_INPUT_2_SOURCE          0x9CA
+#define WM5100_DSP3RMIX_INPUT_2_VOLUME          0x9CB
+#define WM5100_DSP3RMIX_INPUT_3_SOURCE          0x9CC
+#define WM5100_DSP3RMIX_INPUT_3_VOLUME          0x9CD
+#define WM5100_DSP3RMIX_INPUT_4_SOURCE          0x9CE
+#define WM5100_DSP3RMIX_INPUT_4_VOLUME          0x9CF
+#define WM5100_DSP3AUX1MIX_INPUT_1_SOURCE       0x9D0
+#define WM5100_DSP3AUX2MIX_INPUT_1_SOURCE       0x9D8
+#define WM5100_DSP3AUX3MIX_INPUT_1_SOURCE       0x9E0
+#define WM5100_DSP3AUX4MIX_INPUT_1_SOURCE       0x9E8
+#define WM5100_DSP3AUX5MIX_INPUT_1_SOURCE       0x9F0
+#define WM5100_DSP3AUX6MIX_INPUT_1_SOURCE       0x9F8
+#define WM5100_ASRC1LMIX_INPUT_1_SOURCE         0xA80
+#define WM5100_ASRC1RMIX_INPUT_1_SOURCE         0xA88
+#define WM5100_ASRC2LMIX_INPUT_1_SOURCE         0xA90
+#define WM5100_ASRC2RMIX_INPUT_1_SOURCE         0xA98
+#define WM5100_ISRC1DEC1MIX_INPUT_1_SOURCE      0xB00
+#define WM5100_ISRC1DEC2MIX_INPUT_1_SOURCE      0xB08
+#define WM5100_ISRC1DEC3MIX_INPUT_1_SOURCE      0xB10
+#define WM5100_ISRC1DEC4MIX_INPUT_1_SOURCE      0xB18
+#define WM5100_ISRC1INT1MIX_INPUT_1_SOURCE      0xB20
+#define WM5100_ISRC1INT2MIX_INPUT_1_SOURCE      0xB28
+#define WM5100_ISRC1INT3MIX_INPUT_1_SOURCE      0xB30
+#define WM5100_ISRC1INT4MIX_INPUT_1_SOURCE      0xB38
+#define WM5100_ISRC2DEC1MIX_INPUT_1_SOURCE      0xB40
+#define WM5100_ISRC2DEC2MIX_INPUT_1_SOURCE      0xB48
+#define WM5100_ISRC2DEC3MIX_INPUT_1_SOURCE      0xB50
+#define WM5100_ISRC2DEC4MIX_INPUT_1_SOURCE      0xB58
+#define WM5100_ISRC2INT1MIX_INPUT_1_SOURCE      0xB60
+#define WM5100_ISRC2INT2MIX_INPUT_1_SOURCE      0xB68
+#define WM5100_ISRC2INT3MIX_INPUT_1_SOURCE      0xB70
+#define WM5100_ISRC2INT4MIX_INPUT_1_SOURCE      0xB78
+#define WM5100_GPIO_CTRL_1                      0xC00
+#define WM5100_GPIO_CTRL_2                      0xC01
+#define WM5100_GPIO_CTRL_3                      0xC02
+#define WM5100_GPIO_CTRL_4                      0xC03
+#define WM5100_GPIO_CTRL_5                      0xC04
+#define WM5100_GPIO_CTRL_6                      0xC05
+#define WM5100_MISC_PAD_CTRL_1                  0xC23
+#define WM5100_MISC_PAD_CTRL_2                  0xC24
+#define WM5100_MISC_PAD_CTRL_3                  0xC25
+#define WM5100_MISC_PAD_CTRL_4                  0xC26
+#define WM5100_MISC_PAD_CTRL_5                  0xC27
+#define WM5100_MISC_GPIO_1                      0xC28
+#define WM5100_INTERRUPT_STATUS_1               0xD00
+#define WM5100_INTERRUPT_STATUS_2               0xD01
+#define WM5100_INTERRUPT_STATUS_3               0xD02
+#define WM5100_INTERRUPT_STATUS_4               0xD03
+#define WM5100_INTERRUPT_RAW_STATUS_2           0xD04
+#define WM5100_INTERRUPT_RAW_STATUS_3           0xD05
+#define WM5100_INTERRUPT_RAW_STATUS_4           0xD06
+#define WM5100_INTERRUPT_STATUS_1_MASK          0xD07
+#define WM5100_INTERRUPT_STATUS_2_MASK          0xD08
+#define WM5100_INTERRUPT_STATUS_3_MASK          0xD09
+#define WM5100_INTERRUPT_STATUS_4_MASK          0xD0A
+#define WM5100_INTERRUPT_CONTROL                0xD1F
+#define WM5100_IRQ_DEBOUNCE_1                   0xD20
+#define WM5100_IRQ_DEBOUNCE_2                   0xD21
+#define WM5100_FX_CTRL                          0xE00
+#define WM5100_EQ1_1                            0xE10
+#define WM5100_EQ1_2                            0xE11
+#define WM5100_EQ1_3                            0xE12
+#define WM5100_EQ1_4                            0xE13
+#define WM5100_EQ1_5                            0xE14
+#define WM5100_EQ1_6                            0xE15
+#define WM5100_EQ1_7                            0xE16
+#define WM5100_EQ1_8                            0xE17
+#define WM5100_EQ1_9                            0xE18
+#define WM5100_EQ1_10                           0xE19
+#define WM5100_EQ1_11                           0xE1A
+#define WM5100_EQ1_12                           0xE1B
+#define WM5100_EQ1_13                           0xE1C
+#define WM5100_EQ1_14                           0xE1D
+#define WM5100_EQ1_15                           0xE1E
+#define WM5100_EQ1_16                           0xE1F
+#define WM5100_EQ1_17                           0xE20
+#define WM5100_EQ1_18                           0xE21
+#define WM5100_EQ1_19                           0xE22
+#define WM5100_EQ1_20                           0xE23
+#define WM5100_EQ2_1                            0xE26
+#define WM5100_EQ2_2                            0xE27
+#define WM5100_EQ2_3                            0xE28
+#define WM5100_EQ2_4                            0xE29
+#define WM5100_EQ2_5                            0xE2A
+#define WM5100_EQ2_6                            0xE2B
+#define WM5100_EQ2_7                            0xE2C
+#define WM5100_EQ2_8                            0xE2D
+#define WM5100_EQ2_9                            0xE2E
+#define WM5100_EQ2_10                           0xE2F
+#define WM5100_EQ2_11                           0xE30
+#define WM5100_EQ2_12                           0xE31
+#define WM5100_EQ2_13                           0xE32
+#define WM5100_EQ2_14                           0xE33
+#define WM5100_EQ2_15                           0xE34
+#define WM5100_EQ2_16                           0xE35
+#define WM5100_EQ2_17                           0xE36
+#define WM5100_EQ2_18                           0xE37
+#define WM5100_EQ2_19                           0xE38
+#define WM5100_EQ2_20                           0xE39
+#define WM5100_EQ3_1                            0xE3C
+#define WM5100_EQ3_2                            0xE3D
+#define WM5100_EQ3_3                            0xE3E
+#define WM5100_EQ3_4                            0xE3F
+#define WM5100_EQ3_5                            0xE40
+#define WM5100_EQ3_6                            0xE41
+#define WM5100_EQ3_7                            0xE42
+#define WM5100_EQ3_8                            0xE43
+#define WM5100_EQ3_9                            0xE44
+#define WM5100_EQ3_10                           0xE45
+#define WM5100_EQ3_11                           0xE46
+#define WM5100_EQ3_12                           0xE47
+#define WM5100_EQ3_13                           0xE48
+#define WM5100_EQ3_14                           0xE49
+#define WM5100_EQ3_15                           0xE4A
+#define WM5100_EQ3_16                           0xE4B
+#define WM5100_EQ3_17                           0xE4C
+#define WM5100_EQ3_18                           0xE4D
+#define WM5100_EQ3_19                           0xE4E
+#define WM5100_EQ3_20                           0xE4F
+#define WM5100_EQ4_1                            0xE52
+#define WM5100_EQ4_2                            0xE53
+#define WM5100_EQ4_3                            0xE54
+#define WM5100_EQ4_4                            0xE55
+#define WM5100_EQ4_5                            0xE56
+#define WM5100_EQ4_6                            0xE57
+#define WM5100_EQ4_7                            0xE58
+#define WM5100_EQ4_8                            0xE59
+#define WM5100_EQ4_9                            0xE5A
+#define WM5100_EQ4_10                           0xE5B
+#define WM5100_EQ4_11                           0xE5C
+#define WM5100_EQ4_12                           0xE5D
+#define WM5100_EQ4_13                           0xE5E
+#define WM5100_EQ4_14                           0xE5F
+#define WM5100_EQ4_15                           0xE60
+#define WM5100_EQ4_16                           0xE61
+#define WM5100_EQ4_17                           0xE62
+#define WM5100_EQ4_18                           0xE63
+#define WM5100_EQ4_19                           0xE64
+#define WM5100_EQ4_20                           0xE65
+#define WM5100_DRC1_CTRL1                       0xE80
+#define WM5100_DRC1_CTRL2                       0xE81
+#define WM5100_DRC1_CTRL3                       0xE82
+#define WM5100_DRC1_CTRL4                       0xE83
+#define WM5100_DRC1_CTRL5                       0xE84
+#define WM5100_HPLPF1_1                         0xEC0
+#define WM5100_HPLPF1_2                         0xEC1
+#define WM5100_HPLPF2_1                         0xEC4
+#define WM5100_HPLPF2_2                         0xEC5
+#define WM5100_HPLPF3_1                         0xEC8
+#define WM5100_HPLPF3_2                         0xEC9
+#define WM5100_HPLPF4_1                         0xECC
+#define WM5100_HPLPF4_2                         0xECD
+#define WM5100_DSP1_DM_0                        0x4000
+#define WM5100_DSP1_DM_1                        0x4001
+#define WM5100_DSP1_DM_2                        0x4002
+#define WM5100_DSP1_DM_3                        0x4003
+#define WM5100_DSP1_DM_508                      0x41FC
+#define WM5100_DSP1_DM_509                      0x41FD
+#define WM5100_DSP1_DM_510                      0x41FE
+#define WM5100_DSP1_DM_511                      0x41FF
+#define WM5100_DSP1_PM_0                        0x4800
+#define WM5100_DSP1_PM_1                        0x4801
+#define WM5100_DSP1_PM_2                        0x4802
+#define WM5100_DSP1_PM_3                        0x4803
+#define WM5100_DSP1_PM_4                        0x4804
+#define WM5100_DSP1_PM_5                        0x4805
+#define WM5100_DSP1_PM_1530                     0x4DFA
+#define WM5100_DSP1_PM_1531                     0x4DFB
+#define WM5100_DSP1_PM_1532                     0x4DFC
+#define WM5100_DSP1_PM_1533                     0x4DFD
+#define WM5100_DSP1_PM_1534                     0x4DFE
+#define WM5100_DSP1_PM_1535                     0x4DFF
+#define WM5100_DSP1_ZM_0                        0x5000
+#define WM5100_DSP1_ZM_1                        0x5001
+#define WM5100_DSP1_ZM_2                        0x5002
+#define WM5100_DSP1_ZM_3                        0x5003
+#define WM5100_DSP1_ZM_2044                     0x57FC
+#define WM5100_DSP1_ZM_2045                     0x57FD
+#define WM5100_DSP1_ZM_2046                     0x57FE
+#define WM5100_DSP1_ZM_2047                     0x57FF
+#define WM5100_DSP2_DM_0                        0x6000
+#define WM5100_DSP2_DM_1                        0x6001
+#define WM5100_DSP2_DM_2                        0x6002
+#define WM5100_DSP2_DM_3                        0x6003
+#define WM5100_DSP2_DM_508                      0x61FC
+#define WM5100_DSP2_DM_509                      0x61FD
+#define WM5100_DSP2_DM_510                      0x61FE
+#define WM5100_DSP2_DM_511                      0x61FF
+#define WM5100_DSP2_PM_0                        0x6800
+#define WM5100_DSP2_PM_1                        0x6801
+#define WM5100_DSP2_PM_2                        0x6802
+#define WM5100_DSP2_PM_3                        0x6803
+#define WM5100_DSP2_PM_4                        0x6804
+#define WM5100_DSP2_PM_5                        0x6805
+#define WM5100_DSP2_PM_1530                     0x6DFA
+#define WM5100_DSP2_PM_1531                     0x6DFB
+#define WM5100_DSP2_PM_1532                     0x6DFC
+#define WM5100_DSP2_PM_1533                     0x6DFD
+#define WM5100_DSP2_PM_1534                     0x6DFE
+#define WM5100_DSP2_PM_1535                     0x6DFF
+#define WM5100_DSP2_ZM_0                        0x7000
+#define WM5100_DSP2_ZM_1                        0x7001
+#define WM5100_DSP2_ZM_2                        0x7002
+#define WM5100_DSP2_ZM_3                        0x7003
+#define WM5100_DSP2_ZM_2044                     0x77FC
+#define WM5100_DSP2_ZM_2045                     0x77FD
+#define WM5100_DSP2_ZM_2046                     0x77FE
+#define WM5100_DSP2_ZM_2047                     0x77FF
+#define WM5100_DSP3_DM_0                        0x8000
+#define WM5100_DSP3_DM_1                        0x8001
+#define WM5100_DSP3_DM_2                        0x8002
+#define WM5100_DSP3_DM_3                        0x8003
+#define WM5100_DSP3_DM_508                      0x81FC
+#define WM5100_DSP3_DM_509                      0x81FD
+#define WM5100_DSP3_DM_510                      0x81FE
+#define WM5100_DSP3_DM_511                      0x81FF
+#define WM5100_DSP3_PM_0                        0x8800
+#define WM5100_DSP3_PM_1                        0x8801
+#define WM5100_DSP3_PM_2                        0x8802
+#define WM5100_DSP3_PM_3                        0x8803
+#define WM5100_DSP3_PM_4                        0x8804
+#define WM5100_DSP3_PM_5                        0x8805
+#define WM5100_DSP3_PM_1530                     0x8DFA
+#define WM5100_DSP3_PM_1531                     0x8DFB
+#define WM5100_DSP3_PM_1532                     0x8DFC
+#define WM5100_DSP3_PM_1533                     0x8DFD
+#define WM5100_DSP3_PM_1534                     0x8DFE
+#define WM5100_DSP3_PM_1535                     0x8DFF
+#define WM5100_DSP3_ZM_0                        0x9000
+#define WM5100_DSP3_ZM_1                        0x9001
+#define WM5100_DSP3_ZM_2                        0x9002
+#define WM5100_DSP3_ZM_3                        0x9003
+#define WM5100_DSP3_ZM_2044                     0x97FC
+#define WM5100_DSP3_ZM_2045                     0x97FD
+#define WM5100_DSP3_ZM_2046                     0x97FE
+#define WM5100_DSP3_ZM_2047                     0x97FF
+
+#define WM5100_REGISTER_COUNT                   1435
+#define WM5100_MAX_REGISTER                     0x97FF
+
+/*
+ * Field Definitions.
+ */
+
+/*
+ * R0 (0x00) - software reset
+ */
+#define WM5100_SW_RST_DEV_ID1_MASK              0xFFFF  /* SW_RST_DEV_ID1 - [15:0] */
+#define WM5100_SW_RST_DEV_ID1_SHIFT                  0  /* SW_RST_DEV_ID1 - [15:0] */
+#define WM5100_SW_RST_DEV_ID1_WIDTH                 16  /* SW_RST_DEV_ID1 - [15:0] */
+
+/*
+ * R1 (0x01) - Device Revision
+ */
+#define WM5100_DEVICE_REVISION_MASK             0x000F  /* DEVICE_REVISION - [3:0] */
+#define WM5100_DEVICE_REVISION_SHIFT                 0  /* DEVICE_REVISION - [3:0] */
+#define WM5100_DEVICE_REVISION_WIDTH                 4  /* DEVICE_REVISION - [3:0] */
+
+/*
+ * R16 (0x10) - Ctrl IF 1
+ */
+#define WM5100_AUTO_INC                         0x0001  /* AUTO_INC */
+#define WM5100_AUTO_INC_MASK                    0x0001  /* AUTO_INC */
+#define WM5100_AUTO_INC_SHIFT                        0  /* AUTO_INC */
+#define WM5100_AUTO_INC_WIDTH                        1  /* AUTO_INC */
+
+/*
+ * R32 (0x20) - Tone Generator 1
+ */
+#define WM5100_TONE_RATE_MASK                   0x3000  /* TONE_RATE - [13:12] */
+#define WM5100_TONE_RATE_SHIFT                      12  /* TONE_RATE - [13:12] */
+#define WM5100_TONE_RATE_WIDTH                       2  /* TONE_RATE - [13:12] */
+#define WM5100_TONE_OFFSET_MASK                 0x0300  /* TONE_OFFSET - [9:8] */
+#define WM5100_TONE_OFFSET_SHIFT                     8  /* TONE_OFFSET - [9:8] */
+#define WM5100_TONE_OFFSET_WIDTH                     2  /* TONE_OFFSET - [9:8] */
+#define WM5100_TONE2_ENA                        0x0002  /* TONE2_ENA */
+#define WM5100_TONE2_ENA_MASK                   0x0002  /* TONE2_ENA */
+#define WM5100_TONE2_ENA_SHIFT                       1  /* TONE2_ENA */
+#define WM5100_TONE2_ENA_WIDTH                       1  /* TONE2_ENA */
+#define WM5100_TONE1_ENA                        0x0001  /* TONE1_ENA */
+#define WM5100_TONE1_ENA_MASK                   0x0001  /* TONE1_ENA */
+#define WM5100_TONE1_ENA_SHIFT                       0  /* TONE1_ENA */
+#define WM5100_TONE1_ENA_WIDTH                       1  /* TONE1_ENA */
+
+/*
+ * R48 (0x30) - PWM Drive 1
+ */
+#define WM5100_PWM_RATE_MASK                    0x3000  /* PWM_RATE - [13:12] */
+#define WM5100_PWM_RATE_SHIFT                       12  /* PWM_RATE - [13:12] */
+#define WM5100_PWM_RATE_WIDTH                        2  /* PWM_RATE - [13:12] */
+#define WM5100_PWM_CLK_SEL_MASK                 0x0300  /* PWM_CLK_SEL - [9:8] */
+#define WM5100_PWM_CLK_SEL_SHIFT                     8  /* PWM_CLK_SEL - [9:8] */
+#define WM5100_PWM_CLK_SEL_WIDTH                     2  /* PWM_CLK_SEL - [9:8] */
+#define WM5100_PWM2_OVD                         0x0020  /* PWM2_OVD */
+#define WM5100_PWM2_OVD_MASK                    0x0020  /* PWM2_OVD */
+#define WM5100_PWM2_OVD_SHIFT                        5  /* PWM2_OVD */
+#define WM5100_PWM2_OVD_WIDTH                        1  /* PWM2_OVD */
+#define WM5100_PWM1_OVD                         0x0010  /* PWM1_OVD */
+#define WM5100_PWM1_OVD_MASK                    0x0010  /* PWM1_OVD */
+#define WM5100_PWM1_OVD_SHIFT                        4  /* PWM1_OVD */
+#define WM5100_PWM1_OVD_WIDTH                        1  /* PWM1_OVD */
+#define WM5100_PWM2_ENA                         0x0002  /* PWM2_ENA */
+#define WM5100_PWM2_ENA_MASK                    0x0002  /* PWM2_ENA */
+#define WM5100_PWM2_ENA_SHIFT                        1  /* PWM2_ENA */
+#define WM5100_PWM2_ENA_WIDTH                        1  /* PWM2_ENA */
+#define WM5100_PWM1_ENA                         0x0001  /* PWM1_ENA */
+#define WM5100_PWM1_ENA_MASK                    0x0001  /* PWM1_ENA */
+#define WM5100_PWM1_ENA_SHIFT                        0  /* PWM1_ENA */
+#define WM5100_PWM1_ENA_WIDTH                        1  /* PWM1_ENA */
+
+/*
+ * R49 (0x31) - PWM Drive 2
+ */
+#define WM5100_PWM1_LVL_MASK                    0x03FF  /* PWM1_LVL - [9:0] */
+#define WM5100_PWM1_LVL_SHIFT                        0  /* PWM1_LVL - [9:0] */
+#define WM5100_PWM1_LVL_WIDTH                       10  /* PWM1_LVL - [9:0] */
+
+/*
+ * R50 (0x32) - PWM Drive 3
+ */
+#define WM5100_PWM2_LVL_MASK                    0x03FF  /* PWM2_LVL - [9:0] */
+#define WM5100_PWM2_LVL_SHIFT                        0  /* PWM2_LVL - [9:0] */
+#define WM5100_PWM2_LVL_WIDTH                       10  /* PWM2_LVL - [9:0] */
+
+/*
+ * R256 (0x100) - Clocking 1
+ */
+#define WM5100_CLK_32K_SRC_MASK                 0x000F  /* CLK_32K_SRC - [3:0] */
+#define WM5100_CLK_32K_SRC_SHIFT                     0  /* CLK_32K_SRC - [3:0] */
+#define WM5100_CLK_32K_SRC_WIDTH                     4  /* CLK_32K_SRC - [3:0] */
+
+/*
+ * R257 (0x101) - Clocking 3
+ */
+#define WM5100_SYSCLK_FREQ_MASK                 0x0700  /* SYSCLK_FREQ - [10:8] */
+#define WM5100_SYSCLK_FREQ_SHIFT                     8  /* SYSCLK_FREQ - [10:8] */
+#define WM5100_SYSCLK_FREQ_WIDTH                     3  /* SYSCLK_FREQ - [10:8] */
+#define WM5100_SYSCLK_ENA                       0x0040  /* SYSCLK_ENA */
+#define WM5100_SYSCLK_ENA_MASK                  0x0040  /* SYSCLK_ENA */
+#define WM5100_SYSCLK_ENA_SHIFT                      6  /* SYSCLK_ENA */
+#define WM5100_SYSCLK_ENA_WIDTH                      1  /* SYSCLK_ENA */
+#define WM5100_SYSCLK_SRC_MASK                  0x000F  /* SYSCLK_SRC - [3:0] */
+#define WM5100_SYSCLK_SRC_SHIFT                      0  /* SYSCLK_SRC - [3:0] */
+#define WM5100_SYSCLK_SRC_WIDTH                      4  /* SYSCLK_SRC - [3:0] */
+
+/*
+ * R258 (0x102) - Clocking 4
+ */
+#define WM5100_SAMPLE_RATE_1_MASK               0x001F  /* SAMPLE_RATE_1 - [4:0] */
+#define WM5100_SAMPLE_RATE_1_SHIFT                   0  /* SAMPLE_RATE_1 - [4:0] */
+#define WM5100_SAMPLE_RATE_1_WIDTH                   5  /* SAMPLE_RATE_1 - [4:0] */
+
+/*
+ * R259 (0x103) - Clocking 5
+ */
+#define WM5100_SAMPLE_RATE_2_MASK               0x001F  /* SAMPLE_RATE_2 - [4:0] */
+#define WM5100_SAMPLE_RATE_2_SHIFT                   0  /* SAMPLE_RATE_2 - [4:0] */
+#define WM5100_SAMPLE_RATE_2_WIDTH                   5  /* SAMPLE_RATE_2 - [4:0] */
+
+/*
+ * R260 (0x104) - Clocking 6
+ */
+#define WM5100_SAMPLE_RATE_3_MASK               0x001F  /* SAMPLE_RATE_3 - [4:0] */
+#define WM5100_SAMPLE_RATE_3_SHIFT                   0  /* SAMPLE_RATE_3 - [4:0] */
+#define WM5100_SAMPLE_RATE_3_WIDTH                   5  /* SAMPLE_RATE_3 - [4:0] */
+
+/*
+ * R263 (0x107) - Clocking 7
+ */
+#define WM5100_ASYNC_CLK_FREQ_MASK              0x0700  /* ASYNC_CLK_FREQ - [10:8] */
+#define WM5100_ASYNC_CLK_FREQ_SHIFT                  8  /* ASYNC_CLK_FREQ - [10:8] */
+#define WM5100_ASYNC_CLK_FREQ_WIDTH                  3  /* ASYNC_CLK_FREQ - [10:8] */
+#define WM5100_ASYNC_CLK_ENA                    0x0040  /* ASYNC_CLK_ENA */
+#define WM5100_ASYNC_CLK_ENA_MASK               0x0040  /* ASYNC_CLK_ENA */
+#define WM5100_ASYNC_CLK_ENA_SHIFT                   6  /* ASYNC_CLK_ENA */
+#define WM5100_ASYNC_CLK_ENA_WIDTH                   1  /* ASYNC_CLK_ENA */
+#define WM5100_ASYNC_CLK_SRC_MASK               0x000F  /* ASYNC_CLK_SRC - [3:0] */
+#define WM5100_ASYNC_CLK_SRC_SHIFT                   0  /* ASYNC_CLK_SRC - [3:0] */
+#define WM5100_ASYNC_CLK_SRC_WIDTH                   4  /* ASYNC_CLK_SRC - [3:0] */
+
+/*
+ * R264 (0x108) - Clocking 8
+ */
+#define WM5100_ASYNC_SAMPLE_RATE_MASK           0x001F  /* ASYNC_SAMPLE_RATE - [4:0] */
+#define WM5100_ASYNC_SAMPLE_RATE_SHIFT               0  /* ASYNC_SAMPLE_RATE - [4:0] */
+#define WM5100_ASYNC_SAMPLE_RATE_WIDTH               5  /* ASYNC_SAMPLE_RATE - [4:0] */
+
+/*
+ * R288 (0x120) - ASRC_ENABLE
+ */
+#define WM5100_ASRC2L_ENA                       0x0008  /* ASRC2L_ENA */
+#define WM5100_ASRC2L_ENA_MASK                  0x0008  /* ASRC2L_ENA */
+#define WM5100_ASRC2L_ENA_SHIFT                      3  /* ASRC2L_ENA */
+#define WM5100_ASRC2L_ENA_WIDTH                      1  /* ASRC2L_ENA */
+#define WM5100_ASRC2R_ENA                       0x0004  /* ASRC2R_ENA */
+#define WM5100_ASRC2R_ENA_MASK                  0x0004  /* ASRC2R_ENA */
+#define WM5100_ASRC2R_ENA_SHIFT                      2  /* ASRC2R_ENA */
+#define WM5100_ASRC2R_ENA_WIDTH                      1  /* ASRC2R_ENA */
+#define WM5100_ASRC1L_ENA                       0x0002  /* ASRC1L_ENA */
+#define WM5100_ASRC1L_ENA_MASK                  0x0002  /* ASRC1L_ENA */
+#define WM5100_ASRC1L_ENA_SHIFT                      1  /* ASRC1L_ENA */
+#define WM5100_ASRC1L_ENA_WIDTH                      1  /* ASRC1L_ENA */
+#define WM5100_ASRC1R_ENA                       0x0001  /* ASRC1R_ENA */
+#define WM5100_ASRC1R_ENA_MASK                  0x0001  /* ASRC1R_ENA */
+#define WM5100_ASRC1R_ENA_SHIFT                      0  /* ASRC1R_ENA */
+#define WM5100_ASRC1R_ENA_WIDTH                      1  /* ASRC1R_ENA */
+
+/*
+ * R289 (0x121) - ASRC_STATUS
+ */
+#define WM5100_ASRC2L_ENA_STS                   0x0008  /* ASRC2L_ENA_STS */
+#define WM5100_ASRC2L_ENA_STS_MASK              0x0008  /* ASRC2L_ENA_STS */
+#define WM5100_ASRC2L_ENA_STS_SHIFT                  3  /* ASRC2L_ENA_STS */
+#define WM5100_ASRC2L_ENA_STS_WIDTH                  1  /* ASRC2L_ENA_STS */
+#define WM5100_ASRC2R_ENA_STS                   0x0004  /* ASRC2R_ENA_STS */
+#define WM5100_ASRC2R_ENA_STS_MASK              0x0004  /* ASRC2R_ENA_STS */
+#define WM5100_ASRC2R_ENA_STS_SHIFT                  2  /* ASRC2R_ENA_STS */
+#define WM5100_ASRC2R_ENA_STS_WIDTH                  1  /* ASRC2R_ENA_STS */
+#define WM5100_ASRC1L_ENA_STS                   0x0002  /* ASRC1L_ENA_STS */
+#define WM5100_ASRC1L_ENA_STS_MASK              0x0002  /* ASRC1L_ENA_STS */
+#define WM5100_ASRC1L_ENA_STS_SHIFT                  1  /* ASRC1L_ENA_STS */
+#define WM5100_ASRC1L_ENA_STS_WIDTH                  1  /* ASRC1L_ENA_STS */
+#define WM5100_ASRC1R_ENA_STS                   0x0001  /* ASRC1R_ENA_STS */
+#define WM5100_ASRC1R_ENA_STS_MASK              0x0001  /* ASRC1R_ENA_STS */
+#define WM5100_ASRC1R_ENA_STS_SHIFT                  0  /* ASRC1R_ENA_STS */
+#define WM5100_ASRC1R_ENA_STS_WIDTH                  1  /* ASRC1R_ENA_STS */
+
+/*
+ * R290 (0x122) - ASRC_RATE1
+ */
+#define WM5100_ASRC_RATE1_MASK                  0x0006  /* ASRC_RATE1 - [2:1] */
+#define WM5100_ASRC_RATE1_SHIFT                      1  /* ASRC_RATE1 - [2:1] */
+#define WM5100_ASRC_RATE1_WIDTH                      2  /* ASRC_RATE1 - [2:1] */
+
+/*
+ * R321 (0x141) - ISRC 1 CTRL 1
+ */
+#define WM5100_ISRC1_DFS_ENA                    0x2000  /* ISRC1_DFS_ENA */
+#define WM5100_ISRC1_DFS_ENA_MASK               0x2000  /* ISRC1_DFS_ENA */
+#define WM5100_ISRC1_DFS_ENA_SHIFT                  13  /* ISRC1_DFS_ENA */
+#define WM5100_ISRC1_DFS_ENA_WIDTH                   1  /* ISRC1_DFS_ENA */
+#define WM5100_ISRC1_CLK_SEL_MASK               0x0300  /* ISRC1_CLK_SEL - [9:8] */
+#define WM5100_ISRC1_CLK_SEL_SHIFT                   8  /* ISRC1_CLK_SEL - [9:8] */
+#define WM5100_ISRC1_CLK_SEL_WIDTH                   2  /* ISRC1_CLK_SEL - [9:8] */
+#define WM5100_ISRC1_FSH_MASK                   0x000C  /* ISRC1_FSH - [3:2] */
+#define WM5100_ISRC1_FSH_SHIFT                       2  /* ISRC1_FSH - [3:2] */
+#define WM5100_ISRC1_FSH_WIDTH                       2  /* ISRC1_FSH - [3:2] */
+#define WM5100_ISRC1_FSL_MASK                   0x0003  /* ISRC1_FSL - [1:0] */
+#define WM5100_ISRC1_FSL_SHIFT                       0  /* ISRC1_FSL - [1:0] */
+#define WM5100_ISRC1_FSL_WIDTH                       2  /* ISRC1_FSL - [1:0] */
+
+/*
+ * R322 (0x142) - ISRC 1 CTRL 2
+ */
+#define WM5100_ISRC1_INT1_ENA                   0x8000  /* ISRC1_INT1_ENA */
+#define WM5100_ISRC1_INT1_ENA_MASK              0x8000  /* ISRC1_INT1_ENA */
+#define WM5100_ISRC1_INT1_ENA_SHIFT                 15  /* ISRC1_INT1_ENA */
+#define WM5100_ISRC1_INT1_ENA_WIDTH                  1  /* ISRC1_INT1_ENA */
+#define WM5100_ISRC1_INT2_ENA                   0x4000  /* ISRC1_INT2_ENA */
+#define WM5100_ISRC1_INT2_ENA_MASK              0x4000  /* ISRC1_INT2_ENA */
+#define WM5100_ISRC1_INT2_ENA_SHIFT                 14  /* ISRC1_INT2_ENA */
+#define WM5100_ISRC1_INT2_ENA_WIDTH                  1  /* ISRC1_INT2_ENA */
+#define WM5100_ISRC1_INT3_ENA                   0x2000  /* ISRC1_INT3_ENA */
+#define WM5100_ISRC1_INT3_ENA_MASK              0x2000  /* ISRC1_INT3_ENA */
+#define WM5100_ISRC1_INT3_ENA_SHIFT                 13  /* ISRC1_INT3_ENA */
+#define WM5100_ISRC1_INT3_ENA_WIDTH                  1  /* ISRC1_INT3_ENA */
+#define WM5100_ISRC1_INT4_ENA                   0x1000  /* ISRC1_INT4_ENA */
+#define WM5100_ISRC1_INT4_ENA_MASK              0x1000  /* ISRC1_INT4_ENA */
+#define WM5100_ISRC1_INT4_ENA_SHIFT                 12  /* ISRC1_INT4_ENA */
+#define WM5100_ISRC1_INT4_ENA_WIDTH                  1  /* ISRC1_INT4_ENA */
+#define WM5100_ISRC1_DEC1_ENA                   0x0200  /* ISRC1_DEC1_ENA */
+#define WM5100_ISRC1_DEC1_ENA_MASK              0x0200  /* ISRC1_DEC1_ENA */
+#define WM5100_ISRC1_DEC1_ENA_SHIFT                  9  /* ISRC1_DEC1_ENA */
+#define WM5100_ISRC1_DEC1_ENA_WIDTH                  1  /* ISRC1_DEC1_ENA */
+#define WM5100_ISRC1_DEC2_ENA                   0x0100  /* ISRC1_DEC2_ENA */
+#define WM5100_ISRC1_DEC2_ENA_MASK              0x0100  /* ISRC1_DEC2_ENA */
+#define WM5100_ISRC1_DEC2_ENA_SHIFT                  8  /* ISRC1_DEC2_ENA */
+#define WM5100_ISRC1_DEC2_ENA_WIDTH                  1  /* ISRC1_DEC2_ENA */
+#define WM5100_ISRC1_DEC3_ENA                   0x0080  /* ISRC1_DEC3_ENA */
+#define WM5100_ISRC1_DEC3_ENA_MASK              0x0080  /* ISRC1_DEC3_ENA */
+#define WM5100_ISRC1_DEC3_ENA_SHIFT                  7  /* ISRC1_DEC3_ENA */
+#define WM5100_ISRC1_DEC3_ENA_WIDTH                  1  /* ISRC1_DEC3_ENA */
+#define WM5100_ISRC1_DEC4_ENA                   0x0040  /* ISRC1_DEC4_ENA */
+#define WM5100_ISRC1_DEC4_ENA_MASK              0x0040  /* ISRC1_DEC4_ENA */
+#define WM5100_ISRC1_DEC4_ENA_SHIFT                  6  /* ISRC1_DEC4_ENA */
+#define WM5100_ISRC1_DEC4_ENA_WIDTH                  1  /* ISRC1_DEC4_ENA */
+#define WM5100_ISRC1_NOTCH_ENA                  0x0001  /* ISRC1_NOTCH_ENA */
+#define WM5100_ISRC1_NOTCH_ENA_MASK             0x0001  /* ISRC1_NOTCH_ENA */
+#define WM5100_ISRC1_NOTCH_ENA_SHIFT                 0  /* ISRC1_NOTCH_ENA */
+#define WM5100_ISRC1_NOTCH_ENA_WIDTH                 1  /* ISRC1_NOTCH_ENA */
+
+/*
+ * R323 (0x143) - ISRC 2 CTRL1
+ */
+#define WM5100_ISRC2_DFS_ENA                    0x2000  /* ISRC2_DFS_ENA */
+#define WM5100_ISRC2_DFS_ENA_MASK               0x2000  /* ISRC2_DFS_ENA */
+#define WM5100_ISRC2_DFS_ENA_SHIFT                  13  /* ISRC2_DFS_ENA */
+#define WM5100_ISRC2_DFS_ENA_WIDTH                   1  /* ISRC2_DFS_ENA */
+#define WM5100_ISRC2_CLK_SEL_MASK               0x0300  /* ISRC2_CLK_SEL - [9:8] */
+#define WM5100_ISRC2_CLK_SEL_SHIFT                   8  /* ISRC2_CLK_SEL - [9:8] */
+#define WM5100_ISRC2_CLK_SEL_WIDTH                   2  /* ISRC2_CLK_SEL - [9:8] */
+#define WM5100_ISRC2_FSH_MASK                   0x000C  /* ISRC2_FSH - [3:2] */
+#define WM5100_ISRC2_FSH_SHIFT                       2  /* ISRC2_FSH - [3:2] */
+#define WM5100_ISRC2_FSH_WIDTH                       2  /* ISRC2_FSH - [3:2] */
+#define WM5100_ISRC2_FSL_MASK                   0x0003  /* ISRC2_FSL - [1:0] */
+#define WM5100_ISRC2_FSL_SHIFT                       0  /* ISRC2_FSL - [1:0] */
+#define WM5100_ISRC2_FSL_WIDTH                       2  /* ISRC2_FSL - [1:0] */
+
+/*
+ * R324 (0x144) - ISRC 2 CTRL 2
+ */
+#define WM5100_ISRC2_INT1_ENA                   0x8000  /* ISRC2_INT1_ENA */
+#define WM5100_ISRC2_INT1_ENA_MASK              0x8000  /* ISRC2_INT1_ENA */
+#define WM5100_ISRC2_INT1_ENA_SHIFT                 15  /* ISRC2_INT1_ENA */
+#define WM5100_ISRC2_INT1_ENA_WIDTH                  1  /* ISRC2_INT1_ENA */
+#define WM5100_ISRC2_INT2_ENA                   0x4000  /* ISRC2_INT2_ENA */
+#define WM5100_ISRC2_INT2_ENA_MASK              0x4000  /* ISRC2_INT2_ENA */
+#define WM5100_ISRC2_INT2_ENA_SHIFT                 14  /* ISRC2_INT2_ENA */
+#define WM5100_ISRC2_INT2_ENA_WIDTH                  1  /* ISRC2_INT2_ENA */
+#define WM5100_ISRC2_INT3_ENA                   0x2000  /* ISRC2_INT3_ENA */
+#define WM5100_ISRC2_INT3_ENA_MASK              0x2000  /* ISRC2_INT3_ENA */
+#define WM5100_ISRC2_INT3_ENA_SHIFT                 13  /* ISRC2_INT3_ENA */
+#define WM5100_ISRC2_INT3_ENA_WIDTH                  1  /* ISRC2_INT3_ENA */
+#define WM5100_ISRC2_INT4_ENA                   0x1000  /* ISRC2_INT4_ENA */
+#define WM5100_ISRC2_INT4_ENA_MASK              0x1000  /* ISRC2_INT4_ENA */
+#define WM5100_ISRC2_INT4_ENA_SHIFT                 12  /* ISRC2_INT4_ENA */
+#define WM5100_ISRC2_INT4_ENA_WIDTH                  1  /* ISRC2_INT4_ENA */
+#define WM5100_ISRC2_DEC1_ENA                   0x0200  /* ISRC2_DEC1_ENA */
+#define WM5100_ISRC2_DEC1_ENA_MASK              0x0200  /* ISRC2_DEC1_ENA */
+#define WM5100_ISRC2_DEC1_ENA_SHIFT                  9  /* ISRC2_DEC1_ENA */
+#define WM5100_ISRC2_DEC1_ENA_WIDTH                  1  /* ISRC2_DEC1_ENA */
+#define WM5100_ISRC2_DEC2_ENA                   0x0100  /* ISRC2_DEC2_ENA */
+#define WM5100_ISRC2_DEC2_ENA_MASK              0x0100  /* ISRC2_DEC2_ENA */
+#define WM5100_ISRC2_DEC2_ENA_SHIFT                  8  /* ISRC2_DEC2_ENA */
+#define WM5100_ISRC2_DEC2_ENA_WIDTH                  1  /* ISRC2_DEC2_ENA */
+#define WM5100_ISRC2_DEC3_ENA                   0x0080  /* ISRC2_DEC3_ENA */
+#define WM5100_ISRC2_DEC3_ENA_MASK              0x0080  /* ISRC2_DEC3_ENA */
+#define WM5100_ISRC2_DEC3_ENA_SHIFT                  7  /* ISRC2_DEC3_ENA */
+#define WM5100_ISRC2_DEC3_ENA_WIDTH                  1  /* ISRC2_DEC3_ENA */
+#define WM5100_ISRC2_DEC4_ENA                   0x0040  /* ISRC2_DEC4_ENA */
+#define WM5100_ISRC2_DEC4_ENA_MASK              0x0040  /* ISRC2_DEC4_ENA */
+#define WM5100_ISRC2_DEC4_ENA_SHIFT                  6  /* ISRC2_DEC4_ENA */
+#define WM5100_ISRC2_DEC4_ENA_WIDTH                  1  /* ISRC2_DEC4_ENA */
+#define WM5100_ISRC2_NOTCH_ENA                  0x0001  /* ISRC2_NOTCH_ENA */
+#define WM5100_ISRC2_NOTCH_ENA_MASK             0x0001  /* ISRC2_NOTCH_ENA */
+#define WM5100_ISRC2_NOTCH_ENA_SHIFT                 0  /* ISRC2_NOTCH_ENA */
+#define WM5100_ISRC2_NOTCH_ENA_WIDTH                 1  /* ISRC2_NOTCH_ENA */
+
+/*
+ * R386 (0x182) - FLL1 Control 1
+ */
+#define WM5100_FLL1_ENA                         0x0001  /* FLL1_ENA */
+#define WM5100_FLL1_ENA_MASK                    0x0001  /* FLL1_ENA */
+#define WM5100_FLL1_ENA_SHIFT                        0  /* FLL1_ENA */
+#define WM5100_FLL1_ENA_WIDTH                        1  /* FLL1_ENA */
+
+/*
+ * R387 (0x183) - FLL1 Control 2
+ */
+#define WM5100_FLL1_OUTDIV_MASK                 0x3F00  /* FLL1_OUTDIV - [13:8] */
+#define WM5100_FLL1_OUTDIV_SHIFT                     8  /* FLL1_OUTDIV - [13:8] */
+#define WM5100_FLL1_OUTDIV_WIDTH                     6  /* FLL1_OUTDIV - [13:8] */
+#define WM5100_FLL1_FRATIO_MASK                 0x0007  /* FLL1_FRATIO - [2:0] */
+#define WM5100_FLL1_FRATIO_SHIFT                     0  /* FLL1_FRATIO - [2:0] */
+#define WM5100_FLL1_FRATIO_WIDTH                     3  /* FLL1_FRATIO - [2:0] */
+
+/*
+ * R388 (0x184) - FLL1 Control 3
+ */
+#define WM5100_FLL1_THETA_MASK                  0xFFFF  /* FLL1_THETA - [15:0] */
+#define WM5100_FLL1_THETA_SHIFT                      0  /* FLL1_THETA - [15:0] */
+#define WM5100_FLL1_THETA_WIDTH                     16  /* FLL1_THETA - [15:0] */
+
+/*
+ * R390 (0x186) - FLL1 Control 5
+ */
+#define WM5100_FLL1_N_MASK                      0x03FF  /* FLL1_N - [9:0] */
+#define WM5100_FLL1_N_SHIFT                          0  /* FLL1_N - [9:0] */
+#define WM5100_FLL1_N_WIDTH                         10  /* FLL1_N - [9:0] */
+
+/*
+ * R391 (0x187) - FLL1 Control 6
+ */
+#define WM5100_FLL1_REFCLK_DIV_MASK             0x00C0  /* FLL1_REFCLK_DIV - [7:6] */
+#define WM5100_FLL1_REFCLK_DIV_SHIFT                 6  /* FLL1_REFCLK_DIV - [7:6] */
+#define WM5100_FLL1_REFCLK_DIV_WIDTH                 2  /* FLL1_REFCLK_DIV - [7:6] */
+#define WM5100_FLL1_REFCLK_SRC_MASK             0x000F  /* FLL1_REFCLK_SRC - [3:0] */
+#define WM5100_FLL1_REFCLK_SRC_SHIFT                 0  /* FLL1_REFCLK_SRC - [3:0] */
+#define WM5100_FLL1_REFCLK_SRC_WIDTH                 4  /* FLL1_REFCLK_SRC - [3:0] */
+
+/*
+ * R392 (0x188) - FLL1 EFS 1
+ */
+#define WM5100_FLL1_LAMBDA_MASK                 0xFFFF  /* FLL1_LAMBDA - [15:0] */
+#define WM5100_FLL1_LAMBDA_SHIFT                     0  /* FLL1_LAMBDA - [15:0] */
+#define WM5100_FLL1_LAMBDA_WIDTH                    16  /* FLL1_LAMBDA - [15:0] */
+
+/*
+ * R418 (0x1A2) - FLL2 Control 1
+ */
+#define WM5100_FLL2_ENA                         0x0001  /* FLL2_ENA */
+#define WM5100_FLL2_ENA_MASK                    0x0001  /* FLL2_ENA */
+#define WM5100_FLL2_ENA_SHIFT                        0  /* FLL2_ENA */
+#define WM5100_FLL2_ENA_WIDTH                        1  /* FLL2_ENA */
+
+/*
+ * R419 (0x1A3) - FLL2 Control 2
+ */
+#define WM5100_FLL2_OUTDIV_MASK                 0x3F00  /* FLL2_OUTDIV - [13:8] */
+#define WM5100_FLL2_OUTDIV_SHIFT                     8  /* FLL2_OUTDIV - [13:8] */
+#define WM5100_FLL2_OUTDIV_WIDTH                     6  /* FLL2_OUTDIV - [13:8] */
+#define WM5100_FLL2_FRATIO_MASK                 0x0007  /* FLL2_FRATIO - [2:0] */
+#define WM5100_FLL2_FRATIO_SHIFT                     0  /* FLL2_FRATIO - [2:0] */
+#define WM5100_FLL2_FRATIO_WIDTH                     3  /* FLL2_FRATIO - [2:0] */
+
+/*
+ * R420 (0x1A4) - FLL2 Control 3
+ */
+#define WM5100_FLL2_THETA_MASK                  0xFFFF  /* FLL2_THETA - [15:0] */
+#define WM5100_FLL2_THETA_SHIFT                      0  /* FLL2_THETA - [15:0] */
+#define WM5100_FLL2_THETA_WIDTH                     16  /* FLL2_THETA - [15:0] */
+
+/*
+ * R422 (0x1A6) - FLL2 Control 5
+ */
+#define WM5100_FLL2_N_MASK                      0x03FF  /* FLL2_N - [9:0] */
+#define WM5100_FLL2_N_SHIFT                          0  /* FLL2_N - [9:0] */
+#define WM5100_FLL2_N_WIDTH                         10  /* FLL2_N - [9:0] */
+
+/*
+ * R423 (0x1A7) - FLL2 Control 6
+ */
+#define WM5100_FLL2_REFCLK_DIV_MASK             0x00C0  /* FLL2_REFCLK_DIV - [7:6] */
+#define WM5100_FLL2_REFCLK_DIV_SHIFT                 6  /* FLL2_REFCLK_DIV - [7:6] */
+#define WM5100_FLL2_REFCLK_DIV_WIDTH                 2  /* FLL2_REFCLK_DIV - [7:6] */
+#define WM5100_FLL2_REFCLK_SRC_MASK             0x000F  /* FLL2_REFCLK_SRC - [3:0] */
+#define WM5100_FLL2_REFCLK_SRC_SHIFT                 0  /* FLL2_REFCLK_SRC - [3:0] */
+#define WM5100_FLL2_REFCLK_SRC_WIDTH                 4  /* FLL2_REFCLK_SRC - [3:0] */
+
+/*
+ * R424 (0x1A8) - FLL2 EFS 1
+ */
+#define WM5100_FLL2_LAMBDA_MASK                 0xFFFF  /* FLL2_LAMBDA - [15:0] */
+#define WM5100_FLL2_LAMBDA_SHIFT                     0  /* FLL2_LAMBDA - [15:0] */
+#define WM5100_FLL2_LAMBDA_WIDTH                    16  /* FLL2_LAMBDA - [15:0] */
+
+/*
+ * R512 (0x200) - Mic Charge Pump 1
+ */
+#define WM5100_CP2_BYPASS                       0x0020  /* CP2_BYPASS */
+#define WM5100_CP2_BYPASS_MASK                  0x0020  /* CP2_BYPASS */
+#define WM5100_CP2_BYPASS_SHIFT                      5  /* CP2_BYPASS */
+#define WM5100_CP2_BYPASS_WIDTH                      1  /* CP2_BYPASS */
+#define WM5100_CP2_ENA                          0x0001  /* CP2_ENA */
+#define WM5100_CP2_ENA_MASK                     0x0001  /* CP2_ENA */
+#define WM5100_CP2_ENA_SHIFT                         0  /* CP2_ENA */
+#define WM5100_CP2_ENA_WIDTH                         1  /* CP2_ENA */
+
+/*
+ * R513 (0x201) - Mic Charge Pump 2
+ */
+#define WM5100_LDO2_VSEL_MASK                   0xF800  /* LDO2_VSEL - [15:11] */
+#define WM5100_LDO2_VSEL_SHIFT                      11  /* LDO2_VSEL - [15:11] */
+#define WM5100_LDO2_VSEL_WIDTH                       5  /* LDO2_VSEL - [15:11] */
+
+/*
+ * R514 (0x202) - HP Charge Pump 1
+ */
+#define WM5100_CP1_ENA                          0x0001  /* CP1_ENA */
+#define WM5100_CP1_ENA_MASK                     0x0001  /* CP1_ENA */
+#define WM5100_CP1_ENA_SHIFT                         0  /* CP1_ENA */
+#define WM5100_CP1_ENA_WIDTH                         1  /* CP1_ENA */
+
+/*
+ * R529 (0x211) - LDO1 Control
+ */
+#define WM5100_LDO1_BYPASS                      0x0002  /* LDO1_BYPASS */
+#define WM5100_LDO1_BYPASS_MASK                 0x0002  /* LDO1_BYPASS */
+#define WM5100_LDO1_BYPASS_SHIFT                     1  /* LDO1_BYPASS */
+#define WM5100_LDO1_BYPASS_WIDTH                     1  /* LDO1_BYPASS */
+
+/*
+ * R533 (0x215) - Mic Bias Ctrl 1
+ */
+#define WM5100_MICB1_DISCH                      0x0040  /* MICB1_DISCH */
+#define WM5100_MICB1_DISCH_MASK                 0x0040  /* MICB1_DISCH */
+#define WM5100_MICB1_DISCH_SHIFT                     6  /* MICB1_DISCH */
+#define WM5100_MICB1_DISCH_WIDTH                     1  /* MICB1_DISCH */
+#define WM5100_MICB1_RATE                       0x0020  /* MICB1_RATE */
+#define WM5100_MICB1_RATE_MASK                  0x0020  /* MICB1_RATE */
+#define WM5100_MICB1_RATE_SHIFT                      5  /* MICB1_RATE */
+#define WM5100_MICB1_RATE_WIDTH                      1  /* MICB1_RATE */
+#define WM5100_MICB1_LVL_MASK                   0x001C  /* MICB1_LVL - [4:2] */
+#define WM5100_MICB1_LVL_SHIFT                       2  /* MICB1_LVL - [4:2] */
+#define WM5100_MICB1_LVL_WIDTH                       3  /* MICB1_LVL - [4:2] */
+#define WM5100_MICB1_BYPASS                     0x0002  /* MICB1_BYPASS */
+#define WM5100_MICB1_BYPASS_MASK                0x0002  /* MICB1_BYPASS */
+#define WM5100_MICB1_BYPASS_SHIFT                    1  /* MICB1_BYPASS */
+#define WM5100_MICB1_BYPASS_WIDTH                    1  /* MICB1_BYPASS */
+#define WM5100_MICB1_ENA                        0x0001  /* MICB1_ENA */
+#define WM5100_MICB1_ENA_MASK                   0x0001  /* MICB1_ENA */
+#define WM5100_MICB1_ENA_SHIFT                       0  /* MICB1_ENA */
+#define WM5100_MICB1_ENA_WIDTH                       1  /* MICB1_ENA */
+
+/*
+ * R534 (0x216) - Mic Bias Ctrl 2
+ */
+#define WM5100_MICB2_DISCH                      0x0040  /* MICB2_DISCH */
+#define WM5100_MICB2_DISCH_MASK                 0x0040  /* MICB2_DISCH */
+#define WM5100_MICB2_DISCH_SHIFT                     6  /* MICB2_DISCH */
+#define WM5100_MICB2_DISCH_WIDTH                     1  /* MICB2_DISCH */
+#define WM5100_MICB2_RATE                       0x0020  /* MICB2_RATE */
+#define WM5100_MICB2_RATE_MASK                  0x0020  /* MICB2_RATE */
+#define WM5100_MICB2_RATE_SHIFT                      5  /* MICB2_RATE */
+#define WM5100_MICB2_RATE_WIDTH                      1  /* MICB2_RATE */
+#define WM5100_MICB2_LVL_MASK                   0x001C  /* MICB2_LVL - [4:2] */
+#define WM5100_MICB2_LVL_SHIFT                       2  /* MICB2_LVL - [4:2] */
+#define WM5100_MICB2_LVL_WIDTH                       3  /* MICB2_LVL - [4:2] */
+#define WM5100_MICB2_BYPASS                     0x0002  /* MICB2_BYPASS */
+#define WM5100_MICB2_BYPASS_MASK                0x0002  /* MICB2_BYPASS */
+#define WM5100_MICB2_BYPASS_SHIFT                    1  /* MICB2_BYPASS */
+#define WM5100_MICB2_BYPASS_WIDTH                    1  /* MICB2_BYPASS */
+#define WM5100_MICB2_ENA                        0x0001  /* MICB2_ENA */
+#define WM5100_MICB2_ENA_MASK                   0x0001  /* MICB2_ENA */
+#define WM5100_MICB2_ENA_SHIFT                       0  /* MICB2_ENA */
+#define WM5100_MICB2_ENA_WIDTH                       1  /* MICB2_ENA */
+
+/*
+ * R535 (0x217) - Mic Bias Ctrl 3
+ */
+#define WM5100_MICB3_DISCH                      0x0040  /* MICB3_DISCH */
+#define WM5100_MICB3_DISCH_MASK                 0x0040  /* MICB3_DISCH */
+#define WM5100_MICB3_DISCH_SHIFT                     6  /* MICB3_DISCH */
+#define WM5100_MICB3_DISCH_WIDTH                     1  /* MICB3_DISCH */
+#define WM5100_MICB3_RATE                       0x0020  /* MICB3_RATE */
+#define WM5100_MICB3_RATE_MASK                  0x0020  /* MICB3_RATE */
+#define WM5100_MICB3_RATE_SHIFT                      5  /* MICB3_RATE */
+#define WM5100_MICB3_RATE_WIDTH                      1  /* MICB3_RATE */
+#define WM5100_MICB3_LVL_MASK                   0x001C  /* MICB3_LVL - [4:2] */
+#define WM5100_MICB3_LVL_SHIFT                       2  /* MICB3_LVL - [4:2] */
+#define WM5100_MICB3_LVL_WIDTH                       3  /* MICB3_LVL - [4:2] */
+#define WM5100_MICB3_BYPASS                     0x0002  /* MICB3_BYPASS */
+#define WM5100_MICB3_BYPASS_MASK                0x0002  /* MICB3_BYPASS */
+#define WM5100_MICB3_BYPASS_SHIFT                    1  /* MICB3_BYPASS */
+#define WM5100_MICB3_BYPASS_WIDTH                    1  /* MICB3_BYPASS */
+#define WM5100_MICB3_ENA                        0x0001  /* MICB3_ENA */
+#define WM5100_MICB3_ENA_MASK                   0x0001  /* MICB3_ENA */
+#define WM5100_MICB3_ENA_SHIFT                       0  /* MICB3_ENA */
+#define WM5100_MICB3_ENA_WIDTH                       1  /* MICB3_ENA */
+
+/*
+ * R640 (0x280) - Accessory Detect Mode 1
+ */
+#define WM5100_ACCDET_BIAS_SRC_MASK             0xC000  /* ACCDET_BIAS_SRC - [15:14] */
+#define WM5100_ACCDET_BIAS_SRC_SHIFT                14  /* ACCDET_BIAS_SRC - [15:14] */
+#define WM5100_ACCDET_BIAS_SRC_WIDTH                 2  /* ACCDET_BIAS_SRC - [15:14] */
+#define WM5100_ACCDET_SRC                       0x2000  /* ACCDET_SRC */
+#define WM5100_ACCDET_SRC_MASK                  0x2000  /* ACCDET_SRC */
+#define WM5100_ACCDET_SRC_SHIFT                     13  /* ACCDET_SRC */
+#define WM5100_ACCDET_SRC_WIDTH                      1  /* ACCDET_SRC */
+#define WM5100_ACCDET_MODE_MASK                 0x0003  /* ACCDET_MODE - [1:0] */
+#define WM5100_ACCDET_MODE_SHIFT                     0  /* ACCDET_MODE - [1:0] */
+#define WM5100_ACCDET_MODE_WIDTH                     2  /* ACCDET_MODE - [1:0] */
+
+/*
+ * R648 (0x288) - Headphone Detect 1
+ */
+#define WM5100_HP_HOLDTIME_MASK                 0x00E0  /* HP_HOLDTIME - [7:5] */
+#define WM5100_HP_HOLDTIME_SHIFT                     5  /* HP_HOLDTIME - [7:5] */
+#define WM5100_HP_HOLDTIME_WIDTH                     3  /* HP_HOLDTIME - [7:5] */
+#define WM5100_HP_CLK_DIV_MASK                  0x0018  /* HP_CLK_DIV - [4:3] */
+#define WM5100_HP_CLK_DIV_SHIFT                      3  /* HP_CLK_DIV - [4:3] */
+#define WM5100_HP_CLK_DIV_WIDTH                      2  /* HP_CLK_DIV - [4:3] */
+#define WM5100_HP_STEP_SIZE                     0x0002  /* HP_STEP_SIZE */
+#define WM5100_HP_STEP_SIZE_MASK                0x0002  /* HP_STEP_SIZE */
+#define WM5100_HP_STEP_SIZE_SHIFT                    1  /* HP_STEP_SIZE */
+#define WM5100_HP_STEP_SIZE_WIDTH                    1  /* HP_STEP_SIZE */
+#define WM5100_HP_POLL                          0x0001  /* HP_POLL */
+#define WM5100_HP_POLL_MASK                     0x0001  /* HP_POLL */
+#define WM5100_HP_POLL_SHIFT                         0  /* HP_POLL */
+#define WM5100_HP_POLL_WIDTH                         1  /* HP_POLL */
+
+/*
+ * R649 (0x289) - Headphone Detect 2
+ */
+#define WM5100_HP_DONE                          0x0080  /* HP_DONE */
+#define WM5100_HP_DONE_MASK                     0x0080  /* HP_DONE */
+#define WM5100_HP_DONE_SHIFT                         7  /* HP_DONE */
+#define WM5100_HP_DONE_WIDTH                         1  /* HP_DONE */
+#define WM5100_HP_LVL_MASK                      0x007F  /* HP_LVL - [6:0] */
+#define WM5100_HP_LVL_SHIFT                          0  /* HP_LVL - [6:0] */
+#define WM5100_HP_LVL_WIDTH                          7  /* HP_LVL - [6:0] */
+
+/*
+ * R656 (0x290) - Mic Detect 1
+ */
+#define WM5100_ACCDET_BIAS_STARTTIME_MASK       0xF000  /* ACCDET_BIAS_STARTTIME - [15:12] */
+#define WM5100_ACCDET_BIAS_STARTTIME_SHIFT          12  /* ACCDET_BIAS_STARTTIME - [15:12] */
+#define WM5100_ACCDET_BIAS_STARTTIME_WIDTH           4  /* ACCDET_BIAS_STARTTIME - [15:12] */
+#define WM5100_ACCDET_RATE_MASK                 0x0F00  /* ACCDET_RATE - [11:8] */
+#define WM5100_ACCDET_RATE_SHIFT                     8  /* ACCDET_RATE - [11:8] */
+#define WM5100_ACCDET_RATE_WIDTH                     4  /* ACCDET_RATE - [11:8] */
+#define WM5100_ACCDET_DBTIME                    0x0002  /* ACCDET_DBTIME */
+#define WM5100_ACCDET_DBTIME_MASK               0x0002  /* ACCDET_DBTIME */
+#define WM5100_ACCDET_DBTIME_SHIFT                   1  /* ACCDET_DBTIME */
+#define WM5100_ACCDET_DBTIME_WIDTH                   1  /* ACCDET_DBTIME */
+#define WM5100_ACCDET_ENA                       0x0001  /* ACCDET_ENA */
+#define WM5100_ACCDET_ENA_MASK                  0x0001  /* ACCDET_ENA */
+#define WM5100_ACCDET_ENA_SHIFT                      0  /* ACCDET_ENA */
+#define WM5100_ACCDET_ENA_WIDTH                      1  /* ACCDET_ENA */
+
+/*
+ * R657 (0x291) - Mic Detect 2
+ */
+#define WM5100_ACCDET_LVL_SEL_MASK              0x00FF  /* ACCDET_LVL_SEL - [7:0] */
+#define WM5100_ACCDET_LVL_SEL_SHIFT                  0  /* ACCDET_LVL_SEL - [7:0] */
+#define WM5100_ACCDET_LVL_SEL_WIDTH                  8  /* ACCDET_LVL_SEL - [7:0] */
+
+/*
+ * R658 (0x292) - Mic Detect 3
+ */
+#define WM5100_ACCDET_LVL_MASK                  0x07FC  /* ACCDET_LVL - [10:2] */
+#define WM5100_ACCDET_LVL_SHIFT                      2  /* ACCDET_LVL - [10:2] */
+#define WM5100_ACCDET_LVL_WIDTH                      9  /* ACCDET_LVL - [10:2] */
+#define WM5100_ACCDET_VALID                     0x0002  /* ACCDET_VALID */
+#define WM5100_ACCDET_VALID_MASK                0x0002  /* ACCDET_VALID */
+#define WM5100_ACCDET_VALID_SHIFT                    1  /* ACCDET_VALID */
+#define WM5100_ACCDET_VALID_WIDTH                    1  /* ACCDET_VALID */
+#define WM5100_ACCDET_STS                       0x0001  /* ACCDET_STS */
+#define WM5100_ACCDET_STS_MASK                  0x0001  /* ACCDET_STS */
+#define WM5100_ACCDET_STS_SHIFT                      0  /* ACCDET_STS */
+#define WM5100_ACCDET_STS_WIDTH                      1  /* ACCDET_STS */
+
+/*
+ * R699 (0x2BB) - Misc Control
+ */
+#define WM5100_HPCOM_SRC                         0x200  /* HPCOM_SRC */
+#define WM5100_HPCOM_SRC_SHIFT                       9  /* HPCOM_SRC */
+
+/*
+ * R769 (0x301) - Input Enables
+ */
+#define WM5100_IN4L_ENA                         0x0080  /* IN4L_ENA */
+#define WM5100_IN4L_ENA_MASK                    0x0080  /* IN4L_ENA */
+#define WM5100_IN4L_ENA_SHIFT                        7  /* IN4L_ENA */
+#define WM5100_IN4L_ENA_WIDTH                        1  /* IN4L_ENA */
+#define WM5100_IN4R_ENA                         0x0040  /* IN4R_ENA */
+#define WM5100_IN4R_ENA_MASK                    0x0040  /* IN4R_ENA */
+#define WM5100_IN4R_ENA_SHIFT                        6  /* IN4R_ENA */
+#define WM5100_IN4R_ENA_WIDTH                        1  /* IN4R_ENA */
+#define WM5100_IN3L_ENA                         0x0020  /* IN3L_ENA */
+#define WM5100_IN3L_ENA_MASK                    0x0020  /* IN3L_ENA */
+#define WM5100_IN3L_ENA_SHIFT                        5  /* IN3L_ENA */
+#define WM5100_IN3L_ENA_WIDTH                        1  /* IN3L_ENA */
+#define WM5100_IN3R_ENA                         0x0010  /* IN3R_ENA */
+#define WM5100_IN3R_ENA_MASK                    0x0010  /* IN3R_ENA */
+#define WM5100_IN3R_ENA_SHIFT                        4  /* IN3R_ENA */
+#define WM5100_IN3R_ENA_WIDTH                        1  /* IN3R_ENA */
+#define WM5100_IN2L_ENA                         0x0008  /* IN2L_ENA */
+#define WM5100_IN2L_ENA_MASK                    0x0008  /* IN2L_ENA */
+#define WM5100_IN2L_ENA_SHIFT                        3  /* IN2L_ENA */
+#define WM5100_IN2L_ENA_WIDTH                        1  /* IN2L_ENA */
+#define WM5100_IN2R_ENA                         0x0004  /* IN2R_ENA */
+#define WM5100_IN2R_ENA_MASK                    0x0004  /* IN2R_ENA */
+#define WM5100_IN2R_ENA_SHIFT                        2  /* IN2R_ENA */
+#define WM5100_IN2R_ENA_WIDTH                        1  /* IN2R_ENA */
+#define WM5100_IN1L_ENA                         0x0002  /* IN1L_ENA */
+#define WM5100_IN1L_ENA_MASK                    0x0002  /* IN1L_ENA */
+#define WM5100_IN1L_ENA_SHIFT                        1  /* IN1L_ENA */
+#define WM5100_IN1L_ENA_WIDTH                        1  /* IN1L_ENA */
+#define WM5100_IN1R_ENA                         0x0001  /* IN1R_ENA */
+#define WM5100_IN1R_ENA_MASK                    0x0001  /* IN1R_ENA */
+#define WM5100_IN1R_ENA_SHIFT                        0  /* IN1R_ENA */
+#define WM5100_IN1R_ENA_WIDTH                        1  /* IN1R_ENA */
+
+/*
+ * R770 (0x302) - Input Enables Status
+ */
+#define WM5100_IN4L_ENA_STS                     0x0080  /* IN4L_ENA_STS */
+#define WM5100_IN4L_ENA_STS_MASK                0x0080  /* IN4L_ENA_STS */
+#define WM5100_IN4L_ENA_STS_SHIFT                    7  /* IN4L_ENA_STS */
+#define WM5100_IN4L_ENA_STS_WIDTH                    1  /* IN4L_ENA_STS */
+#define WM5100_IN4R_ENA_STS                     0x0040  /* IN4R_ENA_STS */
+#define WM5100_IN4R_ENA_STS_MASK                0x0040  /* IN4R_ENA_STS */
+#define WM5100_IN4R_ENA_STS_SHIFT                    6  /* IN4R_ENA_STS */
+#define WM5100_IN4R_ENA_STS_WIDTH                    1  /* IN4R_ENA_STS */
+#define WM5100_IN3L_ENA_STS                     0x0020  /* IN3L_ENA_STS */
+#define WM5100_IN3L_ENA_STS_MASK                0x0020  /* IN3L_ENA_STS */
+#define WM5100_IN3L_ENA_STS_SHIFT                    5  /* IN3L_ENA_STS */
+#define WM5100_IN3L_ENA_STS_WIDTH                    1  /* IN3L_ENA_STS */
+#define WM5100_IN3R_ENA_STS                     0x0010  /* IN3R_ENA_STS */
+#define WM5100_IN3R_ENA_STS_MASK                0x0010  /* IN3R_ENA_STS */
+#define WM5100_IN3R_ENA_STS_SHIFT                    4  /* IN3R_ENA_STS */
+#define WM5100_IN3R_ENA_STS_WIDTH                    1  /* IN3R_ENA_STS */
+#define WM5100_IN2L_ENA_STS                     0x0008  /* IN2L_ENA_STS */
+#define WM5100_IN2L_ENA_STS_MASK                0x0008  /* IN2L_ENA_STS */
+#define WM5100_IN2L_ENA_STS_SHIFT                    3  /* IN2L_ENA_STS */
+#define WM5100_IN2L_ENA_STS_WIDTH                    1  /* IN2L_ENA_STS */
+#define WM5100_IN2R_ENA_STS                     0x0004  /* IN2R_ENA_STS */
+#define WM5100_IN2R_ENA_STS_MASK                0x0004  /* IN2R_ENA_STS */
+#define WM5100_IN2R_ENA_STS_SHIFT                    2  /* IN2R_ENA_STS */
+#define WM5100_IN2R_ENA_STS_WIDTH                    1  /* IN2R_ENA_STS */
+#define WM5100_IN1L_ENA_STS                     0x0002  /* IN1L_ENA_STS */
+#define WM5100_IN1L_ENA_STS_MASK                0x0002  /* IN1L_ENA_STS */
+#define WM5100_IN1L_ENA_STS_SHIFT                    1  /* IN1L_ENA_STS */
+#define WM5100_IN1L_ENA_STS_WIDTH                    1  /* IN1L_ENA_STS */
+#define WM5100_IN1R_ENA_STS                     0x0001  /* IN1R_ENA_STS */
+#define WM5100_IN1R_ENA_STS_MASK                0x0001  /* IN1R_ENA_STS */
+#define WM5100_IN1R_ENA_STS_SHIFT                    0  /* IN1R_ENA_STS */
+#define WM5100_IN1R_ENA_STS_WIDTH                    1  /* IN1R_ENA_STS */
+
+/*
+ * R784 (0x310) - IN1L Control
+ */
+#define WM5100_IN_RATE_MASK                     0xC000  /* IN_RATE - [15:14] */
+#define WM5100_IN_RATE_SHIFT                        14  /* IN_RATE - [15:14] */
+#define WM5100_IN_RATE_WIDTH                         2  /* IN_RATE - [15:14] */
+#define WM5100_IN1_OSR                          0x2000  /* IN1_OSR */
+#define WM5100_IN1_OSR_MASK                     0x2000  /* IN1_OSR */
+#define WM5100_IN1_OSR_SHIFT                        13  /* IN1_OSR */
+#define WM5100_IN1_OSR_WIDTH                         1  /* IN1_OSR */
+#define WM5100_IN1_DMIC_SUP_MASK                0x1800  /* IN1_DMIC_SUP - [12:11] */
+#define WM5100_IN1_DMIC_SUP_SHIFT                   11  /* IN1_DMIC_SUP - [12:11] */
+#define WM5100_IN1_DMIC_SUP_WIDTH                    2  /* IN1_DMIC_SUP - [12:11] */
+#define WM5100_IN1_MODE_MASK                    0x0600  /* IN1_MODE - [10:9] */
+#define WM5100_IN1_MODE_SHIFT                        9  /* IN1_MODE - [10:9] */
+#define WM5100_IN1_MODE_WIDTH                        2  /* IN1_MODE - [10:9] */
+#define WM5100_IN1L_PGA_VOL_MASK                0x00FE  /* IN1L_PGA_VOL - [7:1] */
+#define WM5100_IN1L_PGA_VOL_SHIFT                    1  /* IN1L_PGA_VOL - [7:1] */
+#define WM5100_IN1L_PGA_VOL_WIDTH                    7  /* IN1L_PGA_VOL - [7:1] */
+
+/*
+ * R785 (0x311) - IN1R Control
+ */
+#define WM5100_IN1R_PGA_VOL_MASK                0x00FE  /* IN1R_PGA_VOL - [7:1] */
+#define WM5100_IN1R_PGA_VOL_SHIFT                    1  /* IN1R_PGA_VOL - [7:1] */
+#define WM5100_IN1R_PGA_VOL_WIDTH                    7  /* IN1R_PGA_VOL - [7:1] */
+
+/*
+ * R786 (0x312) - IN2L Control
+ */
+#define WM5100_IN2_OSR                          0x2000  /* IN2_OSR */
+#define WM5100_IN2_OSR_MASK                     0x2000  /* IN2_OSR */
+#define WM5100_IN2_OSR_SHIFT                        13  /* IN2_OSR */
+#define WM5100_IN2_OSR_WIDTH                         1  /* IN2_OSR */
+#define WM5100_IN2_DMIC_SUP_MASK                0x1800  /* IN2_DMIC_SUP - [12:11] */
+#define WM5100_IN2_DMIC_SUP_SHIFT                   11  /* IN2_DMIC_SUP - [12:11] */
+#define WM5100_IN2_DMIC_SUP_WIDTH                    2  /* IN2_DMIC_SUP - [12:11] */
+#define WM5100_IN2_MODE_MASK                    0x0600  /* IN2_MODE - [10:9] */
+#define WM5100_IN2_MODE_SHIFT                        9  /* IN2_MODE - [10:9] */
+#define WM5100_IN2_MODE_WIDTH                        2  /* IN2_MODE - [10:9] */
+#define WM5100_IN2L_PGA_VOL_MASK                0x00FE  /* IN2L_PGA_VOL - [7:1] */
+#define WM5100_IN2L_PGA_VOL_SHIFT                    1  /* IN2L_PGA_VOL - [7:1] */
+#define WM5100_IN2L_PGA_VOL_WIDTH                    7  /* IN2L_PGA_VOL - [7:1] */
+
+/*
+ * R787 (0x313) - IN2R Control
+ */
+#define WM5100_IN2R_PGA_VOL_MASK                0x00FE  /* IN2R_PGA_VOL - [7:1] */
+#define WM5100_IN2R_PGA_VOL_SHIFT                    1  /* IN2R_PGA_VOL - [7:1] */
+#define WM5100_IN2R_PGA_VOL_WIDTH                    7  /* IN2R_PGA_VOL - [7:1] */
+
+/*
+ * R788 (0x314) - IN3L Control
+ */
+#define WM5100_IN3_OSR                          0x2000  /* IN3_OSR */
+#define WM5100_IN3_OSR_MASK                     0x2000  /* IN3_OSR */
+#define WM5100_IN3_OSR_SHIFT                        13  /* IN3_OSR */
+#define WM5100_IN3_OSR_WIDTH                         1  /* IN3_OSR */
+#define WM5100_IN3_DMIC_SUP_MASK                0x1800  /* IN3_DMIC_SUP - [12:11] */
+#define WM5100_IN3_DMIC_SUP_SHIFT                   11  /* IN3_DMIC_SUP - [12:11] */
+#define WM5100_IN3_DMIC_SUP_WIDTH                    2  /* IN3_DMIC_SUP - [12:11] */
+#define WM5100_IN3_MODE_MASK                    0x0600  /* IN3_MODE - [10:9] */
+#define WM5100_IN3_MODE_SHIFT                        9  /* IN3_MODE - [10:9] */
+#define WM5100_IN3_MODE_WIDTH                        2  /* IN3_MODE - [10:9] */
+#define WM5100_IN3L_PGA_VOL_MASK                0x00FE  /* IN3L_PGA_VOL - [7:1] */
+#define WM5100_IN3L_PGA_VOL_SHIFT                    1  /* IN3L_PGA_VOL - [7:1] */
+#define WM5100_IN3L_PGA_VOL_WIDTH                    7  /* IN3L_PGA_VOL - [7:1] */
+
+/*
+ * R789 (0x315) - IN3R Control
+ */
+#define WM5100_IN3R_PGA_VOL_MASK                0x00FE  /* IN3R_PGA_VOL - [7:1] */
+#define WM5100_IN3R_PGA_VOL_SHIFT                    1  /* IN3R_PGA_VOL - [7:1] */
+#define WM5100_IN3R_PGA_VOL_WIDTH                    7  /* IN3R_PGA_VOL - [7:1] */
+
+/*
+ * R790 (0x316) - IN4L Control
+ */
+#define WM5100_IN4_OSR                          0x2000  /* IN4_OSR */
+#define WM5100_IN4_OSR_MASK                     0x2000  /* IN4_OSR */
+#define WM5100_IN4_OSR_SHIFT                        13  /* IN4_OSR */
+#define WM5100_IN4_OSR_WIDTH                         1  /* IN4_OSR */
+#define WM5100_IN4_DMIC_SUP_MASK                0x1800  /* IN4_DMIC_SUP - [12:11] */
+#define WM5100_IN4_DMIC_SUP_SHIFT                   11  /* IN4_DMIC_SUP - [12:11] */
+#define WM5100_IN4_DMIC_SUP_WIDTH                    2  /* IN4_DMIC_SUP - [12:11] */
+#define WM5100_IN4_MODE_MASK                    0x0600  /* IN4_MODE - [10:9] */
+#define WM5100_IN4_MODE_SHIFT                        9  /* IN4_MODE - [10:9] */
+#define WM5100_IN4_MODE_WIDTH                        2  /* IN4_MODE - [10:9] */
+#define WM5100_IN4L_PGA_VOL_MASK                0x00FE  /* IN4L_PGA_VOL - [7:1] */
+#define WM5100_IN4L_PGA_VOL_SHIFT                    1  /* IN4L_PGA_VOL - [7:1] */
+#define WM5100_IN4L_PGA_VOL_WIDTH                    7  /* IN4L_PGA_VOL - [7:1] */
+
+/*
+ * R791 (0x317) - IN4R Control
+ */
+#define WM5100_IN4R_PGA_VOL_MASK                0x00FE  /* IN4R_PGA_VOL - [7:1] */
+#define WM5100_IN4R_PGA_VOL_SHIFT                    1  /* IN4R_PGA_VOL - [7:1] */
+#define WM5100_IN4R_PGA_VOL_WIDTH                    7  /* IN4R_PGA_VOL - [7:1] */
+
+/*
+ * R792 (0x318) - RXANC_SRC
+ */
+#define WM5100_IN_RXANC_SEL_MASK                0x0007  /* IN_RXANC_SEL - [2:0] */
+#define WM5100_IN_RXANC_SEL_SHIFT                    0  /* IN_RXANC_SEL - [2:0] */
+#define WM5100_IN_RXANC_SEL_WIDTH                    3  /* IN_RXANC_SEL - [2:0] */
+
+/*
+ * R793 (0x319) - Input Volume Ramp
+ */
+#define WM5100_IN_VD_RAMP_MASK                  0x0070  /* IN_VD_RAMP - [6:4] */
+#define WM5100_IN_VD_RAMP_SHIFT                      4  /* IN_VD_RAMP - [6:4] */
+#define WM5100_IN_VD_RAMP_WIDTH                      3  /* IN_VD_RAMP - [6:4] */
+#define WM5100_IN_VI_RAMP_MASK                  0x0007  /* IN_VI_RAMP - [2:0] */
+#define WM5100_IN_VI_RAMP_SHIFT                      0  /* IN_VI_RAMP - [2:0] */
+#define WM5100_IN_VI_RAMP_WIDTH                      3  /* IN_VI_RAMP - [2:0] */
+
+/*
+ * R800 (0x320) - ADC Digital Volume 1L
+ */
+#define WM5100_IN_VU                            0x0200  /* IN_VU */
+#define WM5100_IN_VU_MASK                       0x0200  /* IN_VU */
+#define WM5100_IN_VU_SHIFT                           9  /* IN_VU */
+#define WM5100_IN_VU_WIDTH                           1  /* IN_VU */
+#define WM5100_IN1L_MUTE                        0x0100  /* IN1L_MUTE */
+#define WM5100_IN1L_MUTE_MASK                   0x0100  /* IN1L_MUTE */
+#define WM5100_IN1L_MUTE_SHIFT                       8  /* IN1L_MUTE */
+#define WM5100_IN1L_MUTE_WIDTH                       1  /* IN1L_MUTE */
+#define WM5100_IN1L_VOL_MASK                    0x00FF  /* IN1L_VOL - [7:0] */
+#define WM5100_IN1L_VOL_SHIFT                        0  /* IN1L_VOL - [7:0] */
+#define WM5100_IN1L_VOL_WIDTH                        8  /* IN1L_VOL - [7:0] */
+
+/*
+ * R801 (0x321) - ADC Digital Volume 1R
+ */
+#define WM5100_IN_VU                            0x0200  /* IN_VU */
+#define WM5100_IN_VU_MASK                       0x0200  /* IN_VU */
+#define WM5100_IN_VU_SHIFT                           9  /* IN_VU */
+#define WM5100_IN_VU_WIDTH                           1  /* IN_VU */
+#define WM5100_IN1R_MUTE                        0x0100  /* IN1R_MUTE */
+#define WM5100_IN1R_MUTE_MASK                   0x0100  /* IN1R_MUTE */
+#define WM5100_IN1R_MUTE_SHIFT                       8  /* IN1R_MUTE */
+#define WM5100_IN1R_MUTE_WIDTH                       1  /* IN1R_MUTE */
+#define WM5100_IN1R_VOL_MASK                    0x00FF  /* IN1R_VOL - [7:0] */
+#define WM5100_IN1R_VOL_SHIFT                        0  /* IN1R_VOL - [7:0] */
+#define WM5100_IN1R_VOL_WIDTH                        8  /* IN1R_VOL - [7:0] */
+
+/*
+ * R802 (0x322) - ADC Digital Volume 2L
+ */
+#define WM5100_IN_VU                            0x0200  /* IN_VU */
+#define WM5100_IN_VU_MASK                       0x0200  /* IN_VU */
+#define WM5100_IN_VU_SHIFT                           9  /* IN_VU */
+#define WM5100_IN_VU_WIDTH                           1  /* IN_VU */
+#define WM5100_IN2L_MUTE                        0x0100  /* IN2L_MUTE */
+#define WM5100_IN2L_MUTE_MASK                   0x0100  /* IN2L_MUTE */
+#define WM5100_IN2L_MUTE_SHIFT                       8  /* IN2L_MUTE */
+#define WM5100_IN2L_MUTE_WIDTH                       1  /* IN2L_MUTE */
+#define WM5100_IN2L_VOL_MASK                    0x00FF  /* IN2L_VOL - [7:0] */
+#define WM5100_IN2L_VOL_SHIFT                        0  /* IN2L_VOL - [7:0] */
+#define WM5100_IN2L_VOL_WIDTH                        8  /* IN2L_VOL - [7:0] */
+
+/*
+ * R803 (0x323) - ADC Digital Volume 2R
+ */
+#define WM5100_IN_VU                            0x0200  /* IN_VU */
+#define WM5100_IN_VU_MASK                       0x0200  /* IN_VU */
+#define WM5100_IN_VU_SHIFT                           9  /* IN_VU */
+#define WM5100_IN_VU_WIDTH                           1  /* IN_VU */
+#define WM5100_IN2R_MUTE                        0x0100  /* IN2R_MUTE */
+#define WM5100_IN2R_MUTE_MASK                   0x0100  /* IN2R_MUTE */
+#define WM5100_IN2R_MUTE_SHIFT                       8  /* IN2R_MUTE */
+#define WM5100_IN2R_MUTE_WIDTH                       1  /* IN2R_MUTE */
+#define WM5100_IN2R_VOL_MASK                    0x00FF  /* IN2R_VOL - [7:0] */
+#define WM5100_IN2R_VOL_SHIFT                        0  /* IN2R_VOL - [7:0] */
+#define WM5100_IN2R_VOL_WIDTH                        8  /* IN2R_VOL - [7:0] */
+
+/*
+ * R804 (0x324) - ADC Digital Volume 3L
+ */
+#define WM5100_IN_VU                            0x0200  /* IN_VU */
+#define WM5100_IN_VU_MASK                       0x0200  /* IN_VU */
+#define WM5100_IN_VU_SHIFT                           9  /* IN_VU */
+#define WM5100_IN_VU_WIDTH                           1  /* IN_VU */
+#define WM5100_IN3L_MUTE                        0x0100  /* IN3L_MUTE */
+#define WM5100_IN3L_MUTE_MASK                   0x0100  /* IN3L_MUTE */
+#define WM5100_IN3L_MUTE_SHIFT                       8  /* IN3L_MUTE */
+#define WM5100_IN3L_MUTE_WIDTH                       1  /* IN3L_MUTE */
+#define WM5100_IN3L_VOL_MASK                    0x00FF  /* IN3L_VOL - [7:0] */
+#define WM5100_IN3L_VOL_SHIFT                        0  /* IN3L_VOL - [7:0] */
+#define WM5100_IN3L_VOL_WIDTH                        8  /* IN3L_VOL - [7:0] */
+
+/*
+ * R805 (0x325) - ADC Digital Volume 3R
+ */
+#define WM5100_IN_VU                            0x0200  /* IN_VU */
+#define WM5100_IN_VU_MASK                       0x0200  /* IN_VU */
+#define WM5100_IN_VU_SHIFT                           9  /* IN_VU */
+#define WM5100_IN_VU_WIDTH                           1  /* IN_VU */
+#define WM5100_IN3R_MUTE                        0x0100  /* IN3R_MUTE */
+#define WM5100_IN3R_MUTE_MASK                   0x0100  /* IN3R_MUTE */
+#define WM5100_IN3R_MUTE_SHIFT                       8  /* IN3R_MUTE */
+#define WM5100_IN3R_MUTE_WIDTH                       1  /* IN3R_MUTE */
+#define WM5100_IN3R_VOL_MASK                    0x00FF  /* IN3R_VOL - [7:0] */
+#define WM5100_IN3R_VOL_SHIFT                        0  /* IN3R_VOL - [7:0] */
+#define WM5100_IN3R_VOL_WIDTH                        8  /* IN3R_VOL - [7:0] */
+
+/*
+ * R806 (0x326) - ADC Digital Volume 4L
+ */
+#define WM5100_IN_VU                            0x0200  /* IN_VU */
+#define WM5100_IN_VU_MASK                       0x0200  /* IN_VU */
+#define WM5100_IN_VU_SHIFT                           9  /* IN_VU */
+#define WM5100_IN_VU_WIDTH                           1  /* IN_VU */
+#define WM5100_IN4L_MUTE                        0x0100  /* IN4L_MUTE */
+#define WM5100_IN4L_MUTE_MASK                   0x0100  /* IN4L_MUTE */
+#define WM5100_IN4L_MUTE_SHIFT                       8  /* IN4L_MUTE */
+#define WM5100_IN4L_MUTE_WIDTH                       1  /* IN4L_MUTE */
+#define WM5100_IN4L_VOL_MASK                    0x00FF  /* IN4L_VOL - [7:0] */
+#define WM5100_IN4L_VOL_SHIFT                        0  /* IN4L_VOL - [7:0] */
+#define WM5100_IN4L_VOL_WIDTH                        8  /* IN4L_VOL - [7:0] */
+
+/*
+ * R807 (0x327) - ADC Digital Volume 4R
+ */
+#define WM5100_IN_VU                            0x0200  /* IN_VU */
+#define WM5100_IN_VU_MASK                       0x0200  /* IN_VU */
+#define WM5100_IN_VU_SHIFT                           9  /* IN_VU */
+#define WM5100_IN_VU_WIDTH                           1  /* IN_VU */
+#define WM5100_IN4R_MUTE                        0x0100  /* IN4R_MUTE */
+#define WM5100_IN4R_MUTE_MASK                   0x0100  /* IN4R_MUTE */
+#define WM5100_IN4R_MUTE_SHIFT                       8  /* IN4R_MUTE */
+#define WM5100_IN4R_MUTE_WIDTH                       1  /* IN4R_MUTE */
+#define WM5100_IN4R_VOL_MASK                    0x00FF  /* IN4R_VOL - [7:0] */
+#define WM5100_IN4R_VOL_SHIFT                        0  /* IN4R_VOL - [7:0] */
+#define WM5100_IN4R_VOL_WIDTH                        8  /* IN4R_VOL - [7:0] */
+
+/*
+ * R1025 (0x401) - Output Enables 2
+ */
+#define WM5100_OUT6L_ENA                        0x0800  /* OUT6L_ENA */
+#define WM5100_OUT6L_ENA_MASK                   0x0800  /* OUT6L_ENA */
+#define WM5100_OUT6L_ENA_SHIFT                      11  /* OUT6L_ENA */
+#define WM5100_OUT6L_ENA_WIDTH                       1  /* OUT6L_ENA */
+#define WM5100_OUT6R_ENA                        0x0400  /* OUT6R_ENA */
+#define WM5100_OUT6R_ENA_MASK                   0x0400  /* OUT6R_ENA */
+#define WM5100_OUT6R_ENA_SHIFT                      10  /* OUT6R_ENA */
+#define WM5100_OUT6R_ENA_WIDTH                       1  /* OUT6R_ENA */
+#define WM5100_OUT5L_ENA                        0x0200  /* OUT5L_ENA */
+#define WM5100_OUT5L_ENA_MASK                   0x0200  /* OUT5L_ENA */
+#define WM5100_OUT5L_ENA_SHIFT                       9  /* OUT5L_ENA */
+#define WM5100_OUT5L_ENA_WIDTH                       1  /* OUT5L_ENA */
+#define WM5100_OUT5R_ENA                        0x0100  /* OUT5R_ENA */
+#define WM5100_OUT5R_ENA_MASK                   0x0100  /* OUT5R_ENA */
+#define WM5100_OUT5R_ENA_SHIFT                       8  /* OUT5R_ENA */
+#define WM5100_OUT5R_ENA_WIDTH                       1  /* OUT5R_ENA */
+#define WM5100_OUT4L_ENA                        0x0080  /* OUT4L_ENA */
+#define WM5100_OUT4L_ENA_MASK                   0x0080  /* OUT4L_ENA */
+#define WM5100_OUT4L_ENA_SHIFT                       7  /* OUT4L_ENA */
+#define WM5100_OUT4L_ENA_WIDTH                       1  /* OUT4L_ENA */
+#define WM5100_OUT4R_ENA                        0x0040  /* OUT4R_ENA */
+#define WM5100_OUT4R_ENA_MASK                   0x0040  /* OUT4R_ENA */
+#define WM5100_OUT4R_ENA_SHIFT                       6  /* OUT4R_ENA */
+#define WM5100_OUT4R_ENA_WIDTH                       1  /* OUT4R_ENA */
+
+/*
+ * R1026 (0x402) - Output Status 1
+ */
+#define WM5100_OUT3L_ENA_STS                    0x0020  /* OUT3L_ENA_STS */
+#define WM5100_OUT3L_ENA_STS_MASK               0x0020  /* OUT3L_ENA_STS */
+#define WM5100_OUT3L_ENA_STS_SHIFT                   5  /* OUT3L_ENA_STS */
+#define WM5100_OUT3L_ENA_STS_WIDTH                   1  /* OUT3L_ENA_STS */
+#define WM5100_OUT3R_ENA_STS                    0x0010  /* OUT3R_ENA_STS */
+#define WM5100_OUT3R_ENA_STS_MASK               0x0010  /* OUT3R_ENA_STS */
+#define WM5100_OUT3R_ENA_STS_SHIFT                   4  /* OUT3R_ENA_STS */
+#define WM5100_OUT3R_ENA_STS_WIDTH                   1  /* OUT3R_ENA_STS */
+#define WM5100_OUT2L_ENA_STS                    0x0008  /* OUT2L_ENA_STS */
+#define WM5100_OUT2L_ENA_STS_MASK               0x0008  /* OUT2L_ENA_STS */
+#define WM5100_OUT2L_ENA_STS_SHIFT                   3  /* OUT2L_ENA_STS */
+#define WM5100_OUT2L_ENA_STS_WIDTH                   1  /* OUT2L_ENA_STS */
+#define WM5100_OUT2R_ENA_STS                    0x0004  /* OUT2R_ENA_STS */
+#define WM5100_OUT2R_ENA_STS_MASK               0x0004  /* OUT2R_ENA_STS */
+#define WM5100_OUT2R_ENA_STS_SHIFT                   2  /* OUT2R_ENA_STS */
+#define WM5100_OUT2R_ENA_STS_WIDTH                   1  /* OUT2R_ENA_STS */
+#define WM5100_OUT1L_ENA_STS                    0x0002  /* OUT1L_ENA_STS */
+#define WM5100_OUT1L_ENA_STS_MASK               0x0002  /* OUT1L_ENA_STS */
+#define WM5100_OUT1L_ENA_STS_SHIFT                   1  /* OUT1L_ENA_STS */
+#define WM5100_OUT1L_ENA_STS_WIDTH                   1  /* OUT1L_ENA_STS */
+#define WM5100_OUT1R_ENA_STS                    0x0001  /* OUT1R_ENA_STS */
+#define WM5100_OUT1R_ENA_STS_MASK               0x0001  /* OUT1R_ENA_STS */
+#define WM5100_OUT1R_ENA_STS_SHIFT                   0  /* OUT1R_ENA_STS */
+#define WM5100_OUT1R_ENA_STS_WIDTH                   1  /* OUT1R_ENA_STS */
+
+/*
+ * R1027 (0x403) - Output Status 2
+ */
+#define WM5100_OUT6L_ENA_STS                    0x0800  /* OUT6L_ENA_STS */
+#define WM5100_OUT6L_ENA_STS_MASK               0x0800  /* OUT6L_ENA_STS */
+#define WM5100_OUT6L_ENA_STS_SHIFT                  11  /* OUT6L_ENA_STS */
+#define WM5100_OUT6L_ENA_STS_WIDTH                   1  /* OUT6L_ENA_STS */
+#define WM5100_OUT6R_ENA_STS                    0x0400  /* OUT6R_ENA_STS */
+#define WM5100_OUT6R_ENA_STS_MASK               0x0400  /* OUT6R_ENA_STS */
+#define WM5100_OUT6R_ENA_STS_SHIFT                  10  /* OUT6R_ENA_STS */
+#define WM5100_OUT6R_ENA_STS_WIDTH                   1  /* OUT6R_ENA_STS */
+#define WM5100_OUT5L_ENA_STS                    0x0200  /* OUT5L_ENA_STS */
+#define WM5100_OUT5L_ENA_STS_MASK               0x0200  /* OUT5L_ENA_STS */
+#define WM5100_OUT5L_ENA_STS_SHIFT                   9  /* OUT5L_ENA_STS */
+#define WM5100_OUT5L_ENA_STS_WIDTH                   1  /* OUT5L_ENA_STS */
+#define WM5100_OUT5R_ENA_STS                    0x0100  /* OUT5R_ENA_STS */
+#define WM5100_OUT5R_ENA_STS_MASK               0x0100  /* OUT5R_ENA_STS */
+#define WM5100_OUT5R_ENA_STS_SHIFT                   8  /* OUT5R_ENA_STS */
+#define WM5100_OUT5R_ENA_STS_WIDTH                   1  /* OUT5R_ENA_STS */
+#define WM5100_OUT4L_ENA_STS                    0x0080  /* OUT4L_ENA_STS */
+#define WM5100_OUT4L_ENA_STS_MASK               0x0080  /* OUT4L_ENA_STS */
+#define WM5100_OUT4L_ENA_STS_SHIFT                   7  /* OUT4L_ENA_STS */
+#define WM5100_OUT4L_ENA_STS_WIDTH                   1  /* OUT4L_ENA_STS */
+#define WM5100_OUT4R_ENA_STS                    0x0040  /* OUT4R_ENA_STS */
+#define WM5100_OUT4R_ENA_STS_MASK               0x0040  /* OUT4R_ENA_STS */
+#define WM5100_OUT4R_ENA_STS_SHIFT                   6  /* OUT4R_ENA_STS */
+#define WM5100_OUT4R_ENA_STS_WIDTH                   1  /* OUT4R_ENA_STS */
+
+/*
+ * R1032 (0x408) - Channel Enables 1
+ */
+#define WM5100_HP3L_ENA                         0x0020  /* HP3L_ENA */
+#define WM5100_HP3L_ENA_MASK                    0x0020  /* HP3L_ENA */
+#define WM5100_HP3L_ENA_SHIFT                        5  /* HP3L_ENA */
+#define WM5100_HP3L_ENA_WIDTH                        1  /* HP3L_ENA */
+#define WM5100_HP3R_ENA                         0x0010  /* HP3R_ENA */
+#define WM5100_HP3R_ENA_MASK                    0x0010  /* HP3R_ENA */
+#define WM5100_HP3R_ENA_SHIFT                        4  /* HP3R_ENA */
+#define WM5100_HP3R_ENA_WIDTH                        1  /* HP3R_ENA */
+#define WM5100_HP2L_ENA                         0x0008  /* HP2L_ENA */
+#define WM5100_HP2L_ENA_MASK                    0x0008  /* HP2L_ENA */
+#define WM5100_HP2L_ENA_SHIFT                        3  /* HP2L_ENA */
+#define WM5100_HP2L_ENA_WIDTH                        1  /* HP2L_ENA */
+#define WM5100_HP2R_ENA                         0x0004  /* HP2R_ENA */
+#define WM5100_HP2R_ENA_MASK                    0x0004  /* HP2R_ENA */
+#define WM5100_HP2R_ENA_SHIFT                        2  /* HP2R_ENA */
+#define WM5100_HP2R_ENA_WIDTH                        1  /* HP2R_ENA */
+#define WM5100_HP1L_ENA                         0x0002  /* HP1L_ENA */
+#define WM5100_HP1L_ENA_MASK                    0x0002  /* HP1L_ENA */
+#define WM5100_HP1L_ENA_SHIFT                        1  /* HP1L_ENA */
+#define WM5100_HP1L_ENA_WIDTH                        1  /* HP1L_ENA */
+#define WM5100_HP1R_ENA                         0x0001  /* HP1R_ENA */
+#define WM5100_HP1R_ENA_MASK                    0x0001  /* HP1R_ENA */
+#define WM5100_HP1R_ENA_SHIFT                        0  /* HP1R_ENA */
+#define WM5100_HP1R_ENA_WIDTH                        1  /* HP1R_ENA */
+
+/*
+ * R1040 (0x410) - Out Volume 1L
+ */
+#define WM5100_OUT_RATE_MASK                    0xC000  /* OUT_RATE - [15:14] */
+#define WM5100_OUT_RATE_SHIFT                       14  /* OUT_RATE - [15:14] */
+#define WM5100_OUT_RATE_WIDTH                        2  /* OUT_RATE - [15:14] */
+#define WM5100_OUT1_OSR                         0x2000  /* OUT1_OSR */
+#define WM5100_OUT1_OSR_MASK                    0x2000  /* OUT1_OSR */
+#define WM5100_OUT1_OSR_SHIFT                       13  /* OUT1_OSR */
+#define WM5100_OUT1_OSR_WIDTH                        1  /* OUT1_OSR */
+#define WM5100_OUT1_MONO                        0x1000  /* OUT1_MONO */
+#define WM5100_OUT1_MONO_MASK                   0x1000  /* OUT1_MONO */
+#define WM5100_OUT1_MONO_SHIFT                      12  /* OUT1_MONO */
+#define WM5100_OUT1_MONO_WIDTH                       1  /* OUT1_MONO */
+#define WM5100_OUT1L_ANC_SRC                    0x0800  /* OUT1L_ANC_SRC */
+#define WM5100_OUT1L_ANC_SRC_MASK               0x0800  /* OUT1L_ANC_SRC */
+#define WM5100_OUT1L_ANC_SRC_SHIFT                  11  /* OUT1L_ANC_SRC */
+#define WM5100_OUT1L_ANC_SRC_WIDTH                   1  /* OUT1L_ANC_SRC */
+#define WM5100_OUT1L_PGA_VOL_MASK               0x00FE  /* OUT1L_PGA_VOL - [7:1] */
+#define WM5100_OUT1L_PGA_VOL_SHIFT                   1  /* OUT1L_PGA_VOL - [7:1] */
+#define WM5100_OUT1L_PGA_VOL_WIDTH                   7  /* OUT1L_PGA_VOL - [7:1] */
+
+/*
+ * R1041 (0x411) - Out Volume 1R
+ */
+#define WM5100_OUT1R_ANC_SRC                    0x0800  /* OUT1R_ANC_SRC */
+#define WM5100_OUT1R_ANC_SRC_MASK               0x0800  /* OUT1R_ANC_SRC */
+#define WM5100_OUT1R_ANC_SRC_SHIFT                  11  /* OUT1R_ANC_SRC */
+#define WM5100_OUT1R_ANC_SRC_WIDTH                   1  /* OUT1R_ANC_SRC */
+#define WM5100_OUT1R_PGA_VOL_MASK               0x00FE  /* OUT1R_PGA_VOL - [7:1] */
+#define WM5100_OUT1R_PGA_VOL_SHIFT                   1  /* OUT1R_PGA_VOL - [7:1] */
+#define WM5100_OUT1R_PGA_VOL_WIDTH                   7  /* OUT1R_PGA_VOL - [7:1] */
+
+/*
+ * R1042 (0x412) - DAC Volume Limit 1L
+ */
+#define WM5100_OUT1L_VOL_LIM_MASK               0x00FF  /* OUT1L_VOL_LIM - [7:0] */
+#define WM5100_OUT1L_VOL_LIM_SHIFT                   0  /* OUT1L_VOL_LIM - [7:0] */
+#define WM5100_OUT1L_VOL_LIM_WIDTH                   8  /* OUT1L_VOL_LIM - [7:0] */
+
+/*
+ * R1043 (0x413) - DAC Volume Limit 1R
+ */
+#define WM5100_OUT1R_VOL_LIM_MASK               0x00FF  /* OUT1R_VOL_LIM - [7:0] */
+#define WM5100_OUT1R_VOL_LIM_SHIFT                   0  /* OUT1R_VOL_LIM - [7:0] */
+#define WM5100_OUT1R_VOL_LIM_WIDTH                   8  /* OUT1R_VOL_LIM - [7:0] */
+
+/*
+ * R1044 (0x414) - Out Volume 2L
+ */
+#define WM5100_OUT2_OSR                         0x2000  /* OUT2_OSR */
+#define WM5100_OUT2_OSR_MASK                    0x2000  /* OUT2_OSR */
+#define WM5100_OUT2_OSR_SHIFT                       13  /* OUT2_OSR */
+#define WM5100_OUT2_OSR_WIDTH                        1  /* OUT2_OSR */
+#define WM5100_OUT2_MONO                        0x1000  /* OUT2_MONO */
+#define WM5100_OUT2_MONO_MASK                   0x1000  /* OUT2_MONO */
+#define WM5100_OUT2_MONO_SHIFT                      12  /* OUT2_MONO */
+#define WM5100_OUT2_MONO_WIDTH                       1  /* OUT2_MONO */
+#define WM5100_OUT2L_ANC_SRC                    0x0800  /* OUT2L_ANC_SRC */
+#define WM5100_OUT2L_ANC_SRC_MASK               0x0800  /* OUT2L_ANC_SRC */
+#define WM5100_OUT2L_ANC_SRC_SHIFT                  11  /* OUT2L_ANC_SRC */
+#define WM5100_OUT2L_ANC_SRC_WIDTH                   1  /* OUT2L_ANC_SRC */
+#define WM5100_OUT2L_PGA_VOL_MASK               0x00FE  /* OUT2L_PGA_VOL - [7:1] */
+#define WM5100_OUT2L_PGA_VOL_SHIFT                   1  /* OUT2L_PGA_VOL - [7:1] */
+#define WM5100_OUT2L_PGA_VOL_WIDTH                   7  /* OUT2L_PGA_VOL - [7:1] */
+
+/*
+ * R1045 (0x415) - Out Volume 2R
+ */
+#define WM5100_OUT2R_ANC_SRC                    0x0800  /* OUT2R_ANC_SRC */
+#define WM5100_OUT2R_ANC_SRC_MASK               0x0800  /* OUT2R_ANC_SRC */
+#define WM5100_OUT2R_ANC_SRC_SHIFT                  11  /* OUT2R_ANC_SRC */
+#define WM5100_OUT2R_ANC_SRC_WIDTH                   1  /* OUT2R_ANC_SRC */
+#define WM5100_OUT2R_PGA_VOL_MASK               0x00FE  /* OUT2R_PGA_VOL - [7:1] */
+#define WM5100_OUT2R_PGA_VOL_SHIFT                   1  /* OUT2R_PGA_VOL - [7:1] */
+#define WM5100_OUT2R_PGA_VOL_WIDTH                   7  /* OUT2R_PGA_VOL - [7:1] */
+
+/*
+ * R1046 (0x416) - DAC Volume Limit 2L
+ */
+#define WM5100_OUT2L_VOL_LIM_MASK               0x00FF  /* OUT2L_VOL_LIM - [7:0] */
+#define WM5100_OUT2L_VOL_LIM_SHIFT                   0  /* OUT2L_VOL_LIM - [7:0] */
+#define WM5100_OUT2L_VOL_LIM_WIDTH                   8  /* OUT2L_VOL_LIM - [7:0] */
+
+/*
+ * R1047 (0x417) - DAC Volume Limit 2R
+ */
+#define WM5100_OUT2R_VOL_LIM_MASK               0x00FF  /* OUT2R_VOL_LIM - [7:0] */
+#define WM5100_OUT2R_VOL_LIM_SHIFT                   0  /* OUT2R_VOL_LIM - [7:0] */
+#define WM5100_OUT2R_VOL_LIM_WIDTH                   8  /* OUT2R_VOL_LIM - [7:0] */
+
+/*
+ * R1048 (0x418) - Out Volume 3L
+ */
+#define WM5100_OUT3_OSR                         0x2000  /* OUT3_OSR */
+#define WM5100_OUT3_OSR_MASK                    0x2000  /* OUT3_OSR */
+#define WM5100_OUT3_OSR_SHIFT                       13  /* OUT3_OSR */
+#define WM5100_OUT3_OSR_WIDTH                        1  /* OUT3_OSR */
+#define WM5100_OUT3_MONO                        0x1000  /* OUT3_MONO */
+#define WM5100_OUT3_MONO_MASK                   0x1000  /* OUT3_MONO */
+#define WM5100_OUT3_MONO_SHIFT                      12  /* OUT3_MONO */
+#define WM5100_OUT3_MONO_WIDTH                       1  /* OUT3_MONO */
+#define WM5100_OUT3L_ANC_SRC                    0x0800  /* OUT3L_ANC_SRC */
+#define WM5100_OUT3L_ANC_SRC_MASK               0x0800  /* OUT3L_ANC_SRC */
+#define WM5100_OUT3L_ANC_SRC_SHIFT                  11  /* OUT3L_ANC_SRC */
+#define WM5100_OUT3L_ANC_SRC_WIDTH                   1  /* OUT3L_ANC_SRC */
+#define WM5100_OUT3L_PGA_VOL_MASK               0x00FE  /* OUT3L_PGA_VOL - [7:1] */
+#define WM5100_OUT3L_PGA_VOL_SHIFT                   1  /* OUT3L_PGA_VOL - [7:1] */
+#define WM5100_OUT3L_PGA_VOL_WIDTH                   7  /* OUT3L_PGA_VOL - [7:1] */
+
+/*
+ * R1049 (0x419) - Out Volume 3R
+ */
+#define WM5100_OUT3R_ANC_SRC                    0x0800  /* OUT3R_ANC_SRC */
+#define WM5100_OUT3R_ANC_SRC_MASK               0x0800  /* OUT3R_ANC_SRC */
+#define WM5100_OUT3R_ANC_SRC_SHIFT                  11  /* OUT3R_ANC_SRC */
+#define WM5100_OUT3R_ANC_SRC_WIDTH                   1  /* OUT3R_ANC_SRC */
+#define WM5100_OUT3R_PGA_VOL_MASK               0x00FE  /* OUT3R_PGA_VOL - [7:1] */
+#define WM5100_OUT3R_PGA_VOL_SHIFT                   1  /* OUT3R_PGA_VOL - [7:1] */
+#define WM5100_OUT3R_PGA_VOL_WIDTH                   7  /* OUT3R_PGA_VOL - [7:1] */
+
+/*
+ * R1050 (0x41A) - DAC Volume Limit 3L
+ */
+#define WM5100_OUT3L_VOL_LIM_MASK               0x00FF  /* OUT3L_VOL_LIM - [7:0] */
+#define WM5100_OUT3L_VOL_LIM_SHIFT                   0  /* OUT3L_VOL_LIM - [7:0] */
+#define WM5100_OUT3L_VOL_LIM_WIDTH                   8  /* OUT3L_VOL_LIM - [7:0] */
+
+/*
+ * R1051 (0x41B) - DAC Volume Limit 3R
+ */
+#define WM5100_OUT3R_VOL_LIM_MASK               0x00FF  /* OUT3R_VOL_LIM - [7:0] */
+#define WM5100_OUT3R_VOL_LIM_SHIFT                   0  /* OUT3R_VOL_LIM - [7:0] */
+#define WM5100_OUT3R_VOL_LIM_WIDTH                   8  /* OUT3R_VOL_LIM - [7:0] */
+
+/*
+ * R1052 (0x41C) - Out Volume 4L
+ */
+#define WM5100_OUT4_OSR                         0x2000  /* OUT4_OSR */
+#define WM5100_OUT4_OSR_MASK                    0x2000  /* OUT4_OSR */
+#define WM5100_OUT4_OSR_SHIFT                       13  /* OUT4_OSR */
+#define WM5100_OUT4_OSR_WIDTH                        1  /* OUT4_OSR */
+#define WM5100_OUT4L_ANC_SRC                    0x0800  /* OUT4L_ANC_SRC */
+#define WM5100_OUT4L_ANC_SRC_MASK               0x0800  /* OUT4L_ANC_SRC */
+#define WM5100_OUT4L_ANC_SRC_SHIFT                  11  /* OUT4L_ANC_SRC */
+#define WM5100_OUT4L_ANC_SRC_WIDTH                   1  /* OUT4L_ANC_SRC */
+#define WM5100_OUT4L_VOL_LIM_MASK               0x00FF  /* OUT4L_VOL_LIM - [7:0] */
+#define WM5100_OUT4L_VOL_LIM_SHIFT                   0  /* OUT4L_VOL_LIM - [7:0] */
+#define WM5100_OUT4L_VOL_LIM_WIDTH                   8  /* OUT4L_VOL_LIM - [7:0] */
+
+/*
+ * R1053 (0x41D) - Out Volume 4R
+ */
+#define WM5100_OUT4R_ANC_SRC                    0x0800  /* OUT4R_ANC_SRC */
+#define WM5100_OUT4R_ANC_SRC_MASK               0x0800  /* OUT4R_ANC_SRC */
+#define WM5100_OUT4R_ANC_SRC_SHIFT                  11  /* OUT4R_ANC_SRC */
+#define WM5100_OUT4R_ANC_SRC_WIDTH                   1  /* OUT4R_ANC_SRC */
+#define WM5100_OUT4R_VOL_LIM_MASK               0x00FF  /* OUT4R_VOL_LIM - [7:0] */
+#define WM5100_OUT4R_VOL_LIM_SHIFT                   0  /* OUT4R_VOL_LIM - [7:0] */
+#define WM5100_OUT4R_VOL_LIM_WIDTH                   8  /* OUT4R_VOL_LIM - [7:0] */
+
+/*
+ * R1054 (0x41E) - DAC Volume Limit 5L
+ */
+#define WM5100_OUT5_OSR                         0x2000  /* OUT5_OSR */
+#define WM5100_OUT5_OSR_MASK                    0x2000  /* OUT5_OSR */
+#define WM5100_OUT5_OSR_SHIFT                       13  /* OUT5_OSR */
+#define WM5100_OUT5_OSR_WIDTH                        1  /* OUT5_OSR */
+#define WM5100_OUT5L_ANC_SRC                    0x0800  /* OUT5L_ANC_SRC */
+#define WM5100_OUT5L_ANC_SRC_MASK               0x0800  /* OUT5L_ANC_SRC */
+#define WM5100_OUT5L_ANC_SRC_SHIFT                  11  /* OUT5L_ANC_SRC */
+#define WM5100_OUT5L_ANC_SRC_WIDTH                   1  /* OUT5L_ANC_SRC */
+#define WM5100_OUT5L_VOL_LIM_MASK               0x00FF  /* OUT5L_VOL_LIM - [7:0] */
+#define WM5100_OUT5L_VOL_LIM_SHIFT                   0  /* OUT5L_VOL_LIM - [7:0] */
+#define WM5100_OUT5L_VOL_LIM_WIDTH                   8  /* OUT5L_VOL_LIM - [7:0] */
+
+/*
+ * R1055 (0x41F) - DAC Volume Limit 5R
+ */
+#define WM5100_OUT5R_ANC_SRC                    0x0800  /* OUT5R_ANC_SRC */
+#define WM5100_OUT5R_ANC_SRC_MASK               0x0800  /* OUT5R_ANC_SRC */
+#define WM5100_OUT5R_ANC_SRC_SHIFT                  11  /* OUT5R_ANC_SRC */
+#define WM5100_OUT5R_ANC_SRC_WIDTH                   1  /* OUT5R_ANC_SRC */
+#define WM5100_OUT5R_VOL_LIM_MASK               0x00FF  /* OUT5R_VOL_LIM - [7:0] */
+#define WM5100_OUT5R_VOL_LIM_SHIFT                   0  /* OUT5R_VOL_LIM - [7:0] */
+#define WM5100_OUT5R_VOL_LIM_WIDTH                   8  /* OUT5R_VOL_LIM - [7:0] */
+
+/*
+ * R1056 (0x420) - DAC Volume Limit 6L
+ */
+#define WM5100_OUT6_OSR                         0x2000  /* OUT6_OSR */
+#define WM5100_OUT6_OSR_MASK                    0x2000  /* OUT6_OSR */
+#define WM5100_OUT6_OSR_SHIFT                       13  /* OUT6_OSR */
+#define WM5100_OUT6_OSR_WIDTH                        1  /* OUT6_OSR */
+#define WM5100_OUT6L_ANC_SRC                    0x0800  /* OUT6L_ANC_SRC */
+#define WM5100_OUT6L_ANC_SRC_MASK               0x0800  /* OUT6L_ANC_SRC */
+#define WM5100_OUT6L_ANC_SRC_SHIFT                  11  /* OUT6L_ANC_SRC */
+#define WM5100_OUT6L_ANC_SRC_WIDTH                   1  /* OUT6L_ANC_SRC */
+#define WM5100_OUT6L_VOL_LIM_MASK               0x00FF  /* OUT6L_VOL_LIM - [7:0] */
+#define WM5100_OUT6L_VOL_LIM_SHIFT                   0  /* OUT6L_VOL_LIM - [7:0] */
+#define WM5100_OUT6L_VOL_LIM_WIDTH                   8  /* OUT6L_VOL_LIM - [7:0] */
+
+/*
+ * R1057 (0x421) - DAC Volume Limit 6R
+ */
+#define WM5100_OUT6R_ANC_SRC                    0x0800  /* OUT6R_ANC_SRC */
+#define WM5100_OUT6R_ANC_SRC_MASK               0x0800  /* OUT6R_ANC_SRC */
+#define WM5100_OUT6R_ANC_SRC_SHIFT                  11  /* OUT6R_ANC_SRC */
+#define WM5100_OUT6R_ANC_SRC_WIDTH                   1  /* OUT6R_ANC_SRC */
+#define WM5100_OUT6R_VOL_LIM_MASK               0x00FF  /* OUT6R_VOL_LIM - [7:0] */
+#define WM5100_OUT6R_VOL_LIM_SHIFT                   0  /* OUT6R_VOL_LIM - [7:0] */
+#define WM5100_OUT6R_VOL_LIM_WIDTH                   8  /* OUT6R_VOL_LIM - [7:0] */
+
+/*
+ * R1088 (0x440) - DAC AEC Control 1
+ */
+#define WM5100_AEC_LOOPBACK_SRC_MASK            0x003C  /* AEC_LOOPBACK_SRC - [5:2] */
+#define WM5100_AEC_LOOPBACK_SRC_SHIFT                2  /* AEC_LOOPBACK_SRC - [5:2] */
+#define WM5100_AEC_LOOPBACK_SRC_WIDTH                4  /* AEC_LOOPBACK_SRC - [5:2] */
+#define WM5100_AEC_ENA_STS                      0x0002  /* AEC_ENA_STS */
+#define WM5100_AEC_ENA_STS_MASK                 0x0002  /* AEC_ENA_STS */
+#define WM5100_AEC_ENA_STS_SHIFT                     1  /* AEC_ENA_STS */
+#define WM5100_AEC_ENA_STS_WIDTH                     1  /* AEC_ENA_STS */
+#define WM5100_AEC_LOOPBACK_ENA                 0x0001  /* AEC_LOOPBACK_ENA */
+#define WM5100_AEC_LOOPBACK_ENA_MASK            0x0001  /* AEC_LOOPBACK_ENA */
+#define WM5100_AEC_LOOPBACK_ENA_SHIFT                0  /* AEC_LOOPBACK_ENA */
+#define WM5100_AEC_LOOPBACK_ENA_WIDTH                1  /* AEC_LOOPBACK_ENA */
+
+/*
+ * R1089 (0x441) - Output Volume Ramp
+ */
+#define WM5100_OUT_VD_RAMP_MASK                 0x0070  /* OUT_VD_RAMP - [6:4] */
+#define WM5100_OUT_VD_RAMP_SHIFT                     4  /* OUT_VD_RAMP - [6:4] */
+#define WM5100_OUT_VD_RAMP_WIDTH                     3  /* OUT_VD_RAMP - [6:4] */
+#define WM5100_OUT_VI_RAMP_MASK                 0x0007  /* OUT_VI_RAMP - [2:0] */
+#define WM5100_OUT_VI_RAMP_SHIFT                     0  /* OUT_VI_RAMP - [2:0] */
+#define WM5100_OUT_VI_RAMP_WIDTH                     3  /* OUT_VI_RAMP - [2:0] */
+
+/*
+ * R1152 (0x480) - DAC Digital Volume 1L
+ */
+#define WM5100_OUT_VU                           0x0200  /* OUT_VU */
+#define WM5100_OUT_VU_MASK                      0x0200  /* OUT_VU */
+#define WM5100_OUT_VU_SHIFT                          9  /* OUT_VU */
+#define WM5100_OUT_VU_WIDTH                          1  /* OUT_VU */
+#define WM5100_OUT1L_MUTE                       0x0100  /* OUT1L_MUTE */
+#define WM5100_OUT1L_MUTE_MASK                  0x0100  /* OUT1L_MUTE */
+#define WM5100_OUT1L_MUTE_SHIFT                      8  /* OUT1L_MUTE */
+#define WM5100_OUT1L_MUTE_WIDTH                      1  /* OUT1L_MUTE */
+#define WM5100_OUT1L_VOL_MASK                   0x00FF  /* OUT1L_VOL - [7:0] */
+#define WM5100_OUT1L_VOL_SHIFT                       0  /* OUT1L_VOL - [7:0] */
+#define WM5100_OUT1L_VOL_WIDTH                       8  /* OUT1L_VOL - [7:0] */
+
+/*
+ * R1153 (0x481) - DAC Digital Volume 1R
+ */
+#define WM5100_OUT_VU                           0x0200  /* OUT_VU */
+#define WM5100_OUT_VU_MASK                      0x0200  /* OUT_VU */
+#define WM5100_OUT_VU_SHIFT                          9  /* OUT_VU */
+#define WM5100_OUT_VU_WIDTH                          1  /* OUT_VU */
+#define WM5100_OUT1R_MUTE                       0x0100  /* OUT1R_MUTE */
+#define WM5100_OUT1R_MUTE_MASK                  0x0100  /* OUT1R_MUTE */
+#define WM5100_OUT1R_MUTE_SHIFT                      8  /* OUT1R_MUTE */
+#define WM5100_OUT1R_MUTE_WIDTH                      1  /* OUT1R_MUTE */
+#define WM5100_OUT1R_VOL_MASK                   0x00FF  /* OUT1R_VOL - [7:0] */
+#define WM5100_OUT1R_VOL_SHIFT                       0  /* OUT1R_VOL - [7:0] */
+#define WM5100_OUT1R_VOL_WIDTH                       8  /* OUT1R_VOL - [7:0] */
+
+/*
+ * R1154 (0x482) - DAC Digital Volume 2L
+ */
+#define WM5100_OUT_VU                           0x0200  /* OUT_VU */
+#define WM5100_OUT_VU_MASK                      0x0200  /* OUT_VU */
+#define WM5100_OUT_VU_SHIFT                          9  /* OUT_VU */
+#define WM5100_OUT_VU_WIDTH                          1  /* OUT_VU */
+#define WM5100_OUT2L_MUTE                       0x0100  /* OUT2L_MUTE */
+#define WM5100_OUT2L_MUTE_MASK                  0x0100  /* OUT2L_MUTE */
+#define WM5100_OUT2L_MUTE_SHIFT                      8  /* OUT2L_MUTE */
+#define WM5100_OUT2L_MUTE_WIDTH                      1  /* OUT2L_MUTE */
+#define WM5100_OUT2L_VOL_MASK                   0x00FF  /* OUT2L_VOL - [7:0] */
+#define WM5100_OUT2L_VOL_SHIFT                       0  /* OUT2L_VOL - [7:0] */
+#define WM5100_OUT2L_VOL_WIDTH                       8  /* OUT2L_VOL - [7:0] */
+
+/*
+ * R1155 (0x483) - DAC Digital Volume 2R
+ */
+#define WM5100_OUT_VU                           0x0200  /* OUT_VU */
+#define WM5100_OUT_VU_MASK                      0x0200  /* OUT_VU */
+#define WM5100_OUT_VU_SHIFT                          9  /* OUT_VU */
+#define WM5100_OUT_VU_WIDTH                          1  /* OUT_VU */
+#define WM5100_OUT2R_MUTE                       0x0100  /* OUT2R_MUTE */
+#define WM5100_OUT2R_MUTE_MASK                  0x0100  /* OUT2R_MUTE */
+#define WM5100_OUT2R_MUTE_SHIFT                      8  /* OUT2R_MUTE */
+#define WM5100_OUT2R_MUTE_WIDTH                      1  /* OUT2R_MUTE */
+#define WM5100_OUT2R_VOL_MASK                   0x00FF  /* OUT2R_VOL - [7:0] */
+#define WM5100_OUT2R_VOL_SHIFT                       0  /* OUT2R_VOL - [7:0] */
+#define WM5100_OUT2R_VOL_WIDTH                       8  /* OUT2R_VOL - [7:0] */
+
+/*
+ * R1156 (0x484) - DAC Digital Volume 3L
+ */
+#define WM5100_OUT_VU                           0x0200  /* OUT_VU */
+#define WM5100_OUT_VU_MASK                      0x0200  /* OUT_VU */
+#define WM5100_OUT_VU_SHIFT                          9  /* OUT_VU */
+#define WM5100_OUT_VU_WIDTH                          1  /* OUT_VU */
+#define WM5100_OUT3L_MUTE                       0x0100  /* OUT3L_MUTE */
+#define WM5100_OUT3L_MUTE_MASK                  0x0100  /* OUT3L_MUTE */
+#define WM5100_OUT3L_MUTE_SHIFT                      8  /* OUT3L_MUTE */
+#define WM5100_OUT3L_MUTE_WIDTH                      1  /* OUT3L_MUTE */
+#define WM5100_OUT3L_VOL_MASK                   0x00FF  /* OUT3L_VOL - [7:0] */
+#define WM5100_OUT3L_VOL_SHIFT                       0  /* OUT3L_VOL - [7:0] */
+#define WM5100_OUT3L_VOL_WIDTH                       8  /* OUT3L_VOL - [7:0] */
+
+/*
+ * R1157 (0x485) - DAC Digital Volume 3R
+ */
+#define WM5100_OUT_VU                           0x0200  /* OUT_VU */
+#define WM5100_OUT_VU_MASK                      0x0200  /* OUT_VU */
+#define WM5100_OUT_VU_SHIFT                          9  /* OUT_VU */
+#define WM5100_OUT_VU_WIDTH                          1  /* OUT_VU */
+#define WM5100_OUT3R_MUTE                       0x0100  /* OUT3R_MUTE */
+#define WM5100_OUT3R_MUTE_MASK                  0x0100  /* OUT3R_MUTE */
+#define WM5100_OUT3R_MUTE_SHIFT                      8  /* OUT3R_MUTE */
+#define WM5100_OUT3R_MUTE_WIDTH                      1  /* OUT3R_MUTE */
+#define WM5100_OUT3R_VOL_MASK                   0x00FF  /* OUT3R_VOL - [7:0] */
+#define WM5100_OUT3R_VOL_SHIFT                       0  /* OUT3R_VOL - [7:0] */
+#define WM5100_OUT3R_VOL_WIDTH                       8  /* OUT3R_VOL - [7:0] */
+
+/*
+ * R1158 (0x486) - DAC Digital Volume 4L
+ */
+#define WM5100_OUT_VU                           0x0200  /* OUT_VU */
+#define WM5100_OUT_VU_MASK                      0x0200  /* OUT_VU */
+#define WM5100_OUT_VU_SHIFT                          9  /* OUT_VU */
+#define WM5100_OUT_VU_WIDTH                          1  /* OUT_VU */
+#define WM5100_OUT4L_MUTE                       0x0100  /* OUT4L_MUTE */
+#define WM5100_OUT4L_MUTE_MASK                  0x0100  /* OUT4L_MUTE */
+#define WM5100_OUT4L_MUTE_SHIFT                      8  /* OUT4L_MUTE */
+#define WM5100_OUT4L_MUTE_WIDTH                      1  /* OUT4L_MUTE */
+#define WM5100_OUT4L_VOL_MASK                   0x00FF  /* OUT4L_VOL - [7:0] */
+#define WM5100_OUT4L_VOL_SHIFT                       0  /* OUT4L_VOL - [7:0] */
+#define WM5100_OUT4L_VOL_WIDTH                       8  /* OUT4L_VOL - [7:0] */
+
+/*
+ * R1159 (0x487) - DAC Digital Volume 4R
+ */
+#define WM5100_OUT_VU                           0x0200  /* OUT_VU */
+#define WM5100_OUT_VU_MASK                      0x0200  /* OUT_VU */
+#define WM5100_OUT_VU_SHIFT                          9  /* OUT_VU */
+#define WM5100_OUT_VU_WIDTH                          1  /* OUT_VU */
+#define WM5100_OUT4R_MUTE                       0x0100  /* OUT4R_MUTE */
+#define WM5100_OUT4R_MUTE_MASK                  0x0100  /* OUT4R_MUTE */
+#define WM5100_OUT4R_MUTE_SHIFT                      8  /* OUT4R_MUTE */
+#define WM5100_OUT4R_MUTE_WIDTH                      1  /* OUT4R_MUTE */
+#define WM5100_OUT4R_VOL_MASK                   0x00FF  /* OUT4R_VOL - [7:0] */
+#define WM5100_OUT4R_VOL_SHIFT                       0  /* OUT4R_VOL - [7:0] */
+#define WM5100_OUT4R_VOL_WIDTH                       8  /* OUT4R_VOL - [7:0] */
+
+/*
+ * R1160 (0x488) - DAC Digital Volume 5L
+ */
+#define WM5100_OUT_VU                           0x0200  /* OUT_VU */
+#define WM5100_OUT_VU_MASK                      0x0200  /* OUT_VU */
+#define WM5100_OUT_VU_SHIFT                          9  /* OUT_VU */
+#define WM5100_OUT_VU_WIDTH                          1  /* OUT_VU */
+#define WM5100_OUT5L_MUTE                       0x0100  /* OUT5L_MUTE */
+#define WM5100_OUT5L_MUTE_MASK                  0x0100  /* OUT5L_MUTE */
+#define WM5100_OUT5L_MUTE_SHIFT                      8  /* OUT5L_MUTE */
+#define WM5100_OUT5L_MUTE_WIDTH                      1  /* OUT5L_MUTE */
+#define WM5100_OUT5L_VOL_MASK                   0x00FF  /* OUT5L_VOL - [7:0] */
+#define WM5100_OUT5L_VOL_SHIFT                       0  /* OUT5L_VOL - [7:0] */
+#define WM5100_OUT5L_VOL_WIDTH                       8  /* OUT5L_VOL - [7:0] */
+
+/*
+ * R1161 (0x489) - DAC Digital Volume 5R
+ */
+#define WM5100_OUT_VU                           0x0200  /* OUT_VU */
+#define WM5100_OUT_VU_MASK                      0x0200  /* OUT_VU */
+#define WM5100_OUT_VU_SHIFT                          9  /* OUT_VU */
+#define WM5100_OUT_VU_WIDTH                          1  /* OUT_VU */
+#define WM5100_OUT5R_MUTE                       0x0100  /* OUT5R_MUTE */
+#define WM5100_OUT5R_MUTE_MASK                  0x0100  /* OUT5R_MUTE */
+#define WM5100_OUT5R_MUTE_SHIFT                      8  /* OUT5R_MUTE */
+#define WM5100_OUT5R_MUTE_WIDTH                      1  /* OUT5R_MUTE */
+#define WM5100_OUT5R_VOL_MASK                   0x00FF  /* OUT5R_VOL - [7:0] */
+#define WM5100_OUT5R_VOL_SHIFT                       0  /* OUT5R_VOL - [7:0] */
+#define WM5100_OUT5R_VOL_WIDTH                       8  /* OUT5R_VOL - [7:0] */
+
+/*
+ * R1162 (0x48A) - DAC Digital Volume 6L
+ */
+#define WM5100_OUT_VU                           0x0200  /* OUT_VU */
+#define WM5100_OUT_VU_MASK                      0x0200  /* OUT_VU */
+#define WM5100_OUT_VU_SHIFT                          9  /* OUT_VU */
+#define WM5100_OUT_VU_WIDTH                          1  /* OUT_VU */
+#define WM5100_OUT6L_MUTE                       0x0100  /* OUT6L_MUTE */
+#define WM5100_OUT6L_MUTE_MASK                  0x0100  /* OUT6L_MUTE */
+#define WM5100_OUT6L_MUTE_SHIFT                      8  /* OUT6L_MUTE */
+#define WM5100_OUT6L_MUTE_WIDTH                      1  /* OUT6L_MUTE */
+#define WM5100_OUT6L_VOL_MASK                   0x00FF  /* OUT6L_VOL - [7:0] */
+#define WM5100_OUT6L_VOL_SHIFT                       0  /* OUT6L_VOL - [7:0] */
+#define WM5100_OUT6L_VOL_WIDTH                       8  /* OUT6L_VOL - [7:0] */
+
+/*
+ * R1163 (0x48B) - DAC Digital Volume 6R
+ */
+#define WM5100_OUT_VU                           0x0200  /* OUT_VU */
+#define WM5100_OUT_VU_MASK                      0x0200  /* OUT_VU */
+#define WM5100_OUT_VU_SHIFT                          9  /* OUT_VU */
+#define WM5100_OUT_VU_WIDTH                          1  /* OUT_VU */
+#define WM5100_OUT6R_MUTE                       0x0100  /* OUT6R_MUTE */
+#define WM5100_OUT6R_MUTE_MASK                  0x0100  /* OUT6R_MUTE */
+#define WM5100_OUT6R_MUTE_SHIFT                      8  /* OUT6R_MUTE */
+#define WM5100_OUT6R_MUTE_WIDTH                      1  /* OUT6R_MUTE */
+#define WM5100_OUT6R_VOL_MASK                   0x00FF  /* OUT6R_VOL - [7:0] */
+#define WM5100_OUT6R_VOL_SHIFT                       0  /* OUT6R_VOL - [7:0] */
+#define WM5100_OUT6R_VOL_WIDTH                       8  /* OUT6R_VOL - [7:0] */
+
+/*
+ * R1216 (0x4C0) - PDM SPK1 CTRL 1
+ */
+#define WM5100_SPK1R_MUTE                       0x2000  /* SPK1R_MUTE */
+#define WM5100_SPK1R_MUTE_MASK                  0x2000  /* SPK1R_MUTE */
+#define WM5100_SPK1R_MUTE_SHIFT                     13  /* SPK1R_MUTE */
+#define WM5100_SPK1R_MUTE_WIDTH                      1  /* SPK1R_MUTE */
+#define WM5100_SPK1L_MUTE                       0x1000  /* SPK1L_MUTE */
+#define WM5100_SPK1L_MUTE_MASK                  0x1000  /* SPK1L_MUTE */
+#define WM5100_SPK1L_MUTE_SHIFT                     12  /* SPK1L_MUTE */
+#define WM5100_SPK1L_MUTE_WIDTH                      1  /* SPK1L_MUTE */
+#define WM5100_SPK1_MUTE_ENDIAN                 0x0100  /* SPK1_MUTE_ENDIAN */
+#define WM5100_SPK1_MUTE_ENDIAN_MASK            0x0100  /* SPK1_MUTE_ENDIAN */
+#define WM5100_SPK1_MUTE_ENDIAN_SHIFT                8  /* SPK1_MUTE_ENDIAN */
+#define WM5100_SPK1_MUTE_ENDIAN_WIDTH                1  /* SPK1_MUTE_ENDIAN */
+#define WM5100_SPK1_MUTE_SEQ1_MASK              0x00FF  /* SPK1_MUTE_SEQ1 - [7:0] */
+#define WM5100_SPK1_MUTE_SEQ1_SHIFT                  0  /* SPK1_MUTE_SEQ1 - [7:0] */
+#define WM5100_SPK1_MUTE_SEQ1_WIDTH                  8  /* SPK1_MUTE_SEQ1 - [7:0] */
+
+/*
+ * R1217 (0x4C1) - PDM SPK1 CTRL 2
+ */
+#define WM5100_SPK1_FMT                         0x0001  /* SPK1_FMT */
+#define WM5100_SPK1_FMT_MASK                    0x0001  /* SPK1_FMT */
+#define WM5100_SPK1_FMT_SHIFT                        0  /* SPK1_FMT */
+#define WM5100_SPK1_FMT_WIDTH                        1  /* SPK1_FMT */
+
+/*
+ * R1218 (0x4C2) - PDM SPK2 CTRL 1
+ */
+#define WM5100_SPK2R_MUTE                       0x2000  /* SPK2R_MUTE */
+#define WM5100_SPK2R_MUTE_MASK                  0x2000  /* SPK2R_MUTE */
+#define WM5100_SPK2R_MUTE_SHIFT                     13  /* SPK2R_MUTE */
+#define WM5100_SPK2R_MUTE_WIDTH                      1  /* SPK2R_MUTE */
+#define WM5100_SPK2L_MUTE                       0x1000  /* SPK2L_MUTE */
+#define WM5100_SPK2L_MUTE_MASK                  0x1000  /* SPK2L_MUTE */
+#define WM5100_SPK2L_MUTE_SHIFT                     12  /* SPK2L_MUTE */
+#define WM5100_SPK2L_MUTE_WIDTH                      1  /* SPK2L_MUTE */
+#define WM5100_SPK2_MUTE_ENDIAN                 0x0100  /* SPK2_MUTE_ENDIAN */
+#define WM5100_SPK2_MUTE_ENDIAN_MASK            0x0100  /* SPK2_MUTE_ENDIAN */
+#define WM5100_SPK2_MUTE_ENDIAN_SHIFT                8  /* SPK2_MUTE_ENDIAN */
+#define WM5100_SPK2_MUTE_ENDIAN_WIDTH                1  /* SPK2_MUTE_ENDIAN */
+#define WM5100_SPK2_MUTE_SEQ1_MASK              0x00FF  /* SPK2_MUTE_SEQ1 - [7:0] */
+#define WM5100_SPK2_MUTE_SEQ1_SHIFT                  0  /* SPK2_MUTE_SEQ1 - [7:0] */
+#define WM5100_SPK2_MUTE_SEQ1_WIDTH                  8  /* SPK2_MUTE_SEQ1 - [7:0] */
+
+/*
+ * R1219 (0x4C3) - PDM SPK2 CTRL 2
+ */
+#define WM5100_SPK2_FMT                         0x0001  /* SPK2_FMT */
+#define WM5100_SPK2_FMT_MASK                    0x0001  /* SPK2_FMT */
+#define WM5100_SPK2_FMT_SHIFT                        0  /* SPK2_FMT */
+#define WM5100_SPK2_FMT_WIDTH                        1  /* SPK2_FMT */
+
+/*
+ * R1280 (0x500) - Audio IF 1_1
+ */
+#define WM5100_AIF1_BCLK_INV                    0x0080  /* AIF1_BCLK_INV */
+#define WM5100_AIF1_BCLK_INV_MASK               0x0080  /* AIF1_BCLK_INV */
+#define WM5100_AIF1_BCLK_INV_SHIFT                   7  /* AIF1_BCLK_INV */
+#define WM5100_AIF1_BCLK_INV_WIDTH                   1  /* AIF1_BCLK_INV */
+#define WM5100_AIF1_BCLK_FRC                    0x0040  /* AIF1_BCLK_FRC */
+#define WM5100_AIF1_BCLK_FRC_MASK               0x0040  /* AIF1_BCLK_FRC */
+#define WM5100_AIF1_BCLK_FRC_SHIFT                   6  /* AIF1_BCLK_FRC */
+#define WM5100_AIF1_BCLK_FRC_WIDTH                   1  /* AIF1_BCLK_FRC */
+#define WM5100_AIF1_BCLK_MSTR                   0x0020  /* AIF1_BCLK_MSTR */
+#define WM5100_AIF1_BCLK_MSTR_MASK              0x0020  /* AIF1_BCLK_MSTR */
+#define WM5100_AIF1_BCLK_MSTR_SHIFT                  5  /* AIF1_BCLK_MSTR */
+#define WM5100_AIF1_BCLK_MSTR_WIDTH                  1  /* AIF1_BCLK_MSTR */
+#define WM5100_AIF1_BCLK_FREQ_MASK              0x001F  /* AIF1_BCLK_FREQ - [4:0] */
+#define WM5100_AIF1_BCLK_FREQ_SHIFT                  0  /* AIF1_BCLK_FREQ - [4:0] */
+#define WM5100_AIF1_BCLK_FREQ_WIDTH                  5  /* AIF1_BCLK_FREQ - [4:0] */
+
+/*
+ * R1281 (0x501) - Audio IF 1_2
+ */
+#define WM5100_AIF1TX_DAT_TRI                   0x0020  /* AIF1TX_DAT_TRI */
+#define WM5100_AIF1TX_DAT_TRI_MASK              0x0020  /* AIF1TX_DAT_TRI */
+#define WM5100_AIF1TX_DAT_TRI_SHIFT                  5  /* AIF1TX_DAT_TRI */
+#define WM5100_AIF1TX_DAT_TRI_WIDTH                  1  /* AIF1TX_DAT_TRI */
+#define WM5100_AIF1TX_LRCLK_SRC                 0x0008  /* AIF1TX_LRCLK_SRC */
+#define WM5100_AIF1TX_LRCLK_SRC_MASK            0x0008  /* AIF1TX_LRCLK_SRC */
+#define WM5100_AIF1TX_LRCLK_SRC_SHIFT                3  /* AIF1TX_LRCLK_SRC */
+#define WM5100_AIF1TX_LRCLK_SRC_WIDTH                1  /* AIF1TX_LRCLK_SRC */
+#define WM5100_AIF1TX_LRCLK_INV                 0x0004  /* AIF1TX_LRCLK_INV */
+#define WM5100_AIF1TX_LRCLK_INV_MASK            0x0004  /* AIF1TX_LRCLK_INV */
+#define WM5100_AIF1TX_LRCLK_INV_SHIFT                2  /* AIF1TX_LRCLK_INV */
+#define WM5100_AIF1TX_LRCLK_INV_WIDTH                1  /* AIF1TX_LRCLK_INV */
+#define WM5100_AIF1TX_LRCLK_FRC                 0x0002  /* AIF1TX_LRCLK_FRC */
+#define WM5100_AIF1TX_LRCLK_FRC_MASK            0x0002  /* AIF1TX_LRCLK_FRC */
+#define WM5100_AIF1TX_LRCLK_FRC_SHIFT                1  /* AIF1TX_LRCLK_FRC */
+#define WM5100_AIF1TX_LRCLK_FRC_WIDTH                1  /* AIF1TX_LRCLK_FRC */
+#define WM5100_AIF1TX_LRCLK_MSTR                0x0001  /* AIF1TX_LRCLK_MSTR */
+#define WM5100_AIF1TX_LRCLK_MSTR_MASK           0x0001  /* AIF1TX_LRCLK_MSTR */
+#define WM5100_AIF1TX_LRCLK_MSTR_SHIFT               0  /* AIF1TX_LRCLK_MSTR */
+#define WM5100_AIF1TX_LRCLK_MSTR_WIDTH               1  /* AIF1TX_LRCLK_MSTR */
+
+/*
+ * R1282 (0x502) - Audio IF 1_3
+ */
+#define WM5100_AIF1RX_LRCLK_INV                 0x0004  /* AIF1RX_LRCLK_INV */
+#define WM5100_AIF1RX_LRCLK_INV_MASK            0x0004  /* AIF1RX_LRCLK_INV */
+#define WM5100_AIF1RX_LRCLK_INV_SHIFT                2  /* AIF1RX_LRCLK_INV */
+#define WM5100_AIF1RX_LRCLK_INV_WIDTH                1  /* AIF1RX_LRCLK_INV */
+#define WM5100_AIF1RX_LRCLK_FRC                 0x0002  /* AIF1RX_LRCLK_FRC */
+#define WM5100_AIF1RX_LRCLK_FRC_MASK            0x0002  /* AIF1RX_LRCLK_FRC */
+#define WM5100_AIF1RX_LRCLK_FRC_SHIFT                1  /* AIF1RX_LRCLK_FRC */
+#define WM5100_AIF1RX_LRCLK_FRC_WIDTH                1  /* AIF1RX_LRCLK_FRC */
+#define WM5100_AIF1RX_LRCLK_MSTR                0x0001  /* AIF1RX_LRCLK_MSTR */
+#define WM5100_AIF1RX_LRCLK_MSTR_MASK           0x0001  /* AIF1RX_LRCLK_MSTR */
+#define WM5100_AIF1RX_LRCLK_MSTR_SHIFT               0  /* AIF1RX_LRCLK_MSTR */
+#define WM5100_AIF1RX_LRCLK_MSTR_WIDTH               1  /* AIF1RX_LRCLK_MSTR */
+
+/*
+ * R1283 (0x503) - Audio IF 1_4
+ */
+#define WM5100_AIF1_TRI                         0x0040  /* AIF1_TRI */
+#define WM5100_AIF1_TRI_MASK                    0x0040  /* AIF1_TRI */
+#define WM5100_AIF1_TRI_SHIFT                        6  /* AIF1_TRI */
+#define WM5100_AIF1_TRI_WIDTH                        1  /* AIF1_TRI */
+#define WM5100_AIF1_RATE_MASK                   0x0003  /* AIF1_RATE - [1:0] */
+#define WM5100_AIF1_RATE_SHIFT                       0  /* AIF1_RATE - [1:0] */
+#define WM5100_AIF1_RATE_WIDTH                       2  /* AIF1_RATE - [1:0] */
+
+/*
+ * R1284 (0x504) - Audio IF 1_5
+ */
+#define WM5100_AIF1_FMT_MASK                    0x0007  /* AIF1_FMT - [2:0] */
+#define WM5100_AIF1_FMT_SHIFT                        0  /* AIF1_FMT - [2:0] */
+#define WM5100_AIF1_FMT_WIDTH                        3  /* AIF1_FMT - [2:0] */
+
+/*
+ * R1285 (0x505) - Audio IF 1_6
+ */
+#define WM5100_AIF1TX_BCPF_MASK                 0x1FFF  /* AIF1TX_BCPF - [12:0] */
+#define WM5100_AIF1TX_BCPF_SHIFT                     0  /* AIF1TX_BCPF - [12:0] */
+#define WM5100_AIF1TX_BCPF_WIDTH                    13  /* AIF1TX_BCPF - [12:0] */
+
+/*
+ * R1286 (0x506) - Audio IF 1_7
+ */
+#define WM5100_AIF1RX_BCPF_MASK                 0x1FFF  /* AIF1RX_BCPF - [12:0] */
+#define WM5100_AIF1RX_BCPF_SHIFT                     0  /* AIF1RX_BCPF - [12:0] */
+#define WM5100_AIF1RX_BCPF_WIDTH                    13  /* AIF1RX_BCPF - [12:0] */
+
+/*
+ * R1287 (0x507) - Audio IF 1_8
+ */
+#define WM5100_AIF1TX_WL_MASK                   0x3F00  /* AIF1TX_WL - [13:8] */
+#define WM5100_AIF1TX_WL_SHIFT                       8  /* AIF1TX_WL - [13:8] */
+#define WM5100_AIF1TX_WL_WIDTH                       6  /* AIF1TX_WL - [13:8] */
+#define WM5100_AIF1TX_SLOT_LEN_MASK             0x00FF  /* AIF1TX_SLOT_LEN - [7:0] */
+#define WM5100_AIF1TX_SLOT_LEN_SHIFT                 0  /* AIF1TX_SLOT_LEN - [7:0] */
+#define WM5100_AIF1TX_SLOT_LEN_WIDTH                 8  /* AIF1TX_SLOT_LEN - [7:0] */
+
+/*
+ * R1288 (0x508) - Audio IF 1_9
+ */
+#define WM5100_AIF1RX_WL_MASK                   0x3F00  /* AIF1RX_WL - [13:8] */
+#define WM5100_AIF1RX_WL_SHIFT                       8  /* AIF1RX_WL - [13:8] */
+#define WM5100_AIF1RX_WL_WIDTH                       6  /* AIF1RX_WL - [13:8] */
+#define WM5100_AIF1RX_SLOT_LEN_MASK             0x00FF  /* AIF1RX_SLOT_LEN - [7:0] */
+#define WM5100_AIF1RX_SLOT_LEN_SHIFT                 0  /* AIF1RX_SLOT_LEN - [7:0] */
+#define WM5100_AIF1RX_SLOT_LEN_WIDTH                 8  /* AIF1RX_SLOT_LEN - [7:0] */
+
+/*
+ * R1289 (0x509) - Audio IF 1_10
+ */
+#define WM5100_AIF1TX1_SLOT_MASK                0x003F  /* AIF1TX1_SLOT - [5:0] */
+#define WM5100_AIF1TX1_SLOT_SHIFT                    0  /* AIF1TX1_SLOT - [5:0] */
+#define WM5100_AIF1TX1_SLOT_WIDTH                    6  /* AIF1TX1_SLOT - [5:0] */
+
+/*
+ * R1290 (0x50A) - Audio IF 1_11
+ */
+#define WM5100_AIF1TX2_SLOT_MASK                0x003F  /* AIF1TX2_SLOT - [5:0] */
+#define WM5100_AIF1TX2_SLOT_SHIFT                    0  /* AIF1TX2_SLOT - [5:0] */
+#define WM5100_AIF1TX2_SLOT_WIDTH                    6  /* AIF1TX2_SLOT - [5:0] */
+
+/*
+ * R1291 (0x50B) - Audio IF 1_12
+ */
+#define WM5100_AIF1TX3_SLOT_MASK                0x003F  /* AIF1TX3_SLOT - [5:0] */
+#define WM5100_AIF1TX3_SLOT_SHIFT                    0  /* AIF1TX3_SLOT - [5:0] */
+#define WM5100_AIF1TX3_SLOT_WIDTH                    6  /* AIF1TX3_SLOT - [5:0] */
+
+/*
+ * R1292 (0x50C) - Audio IF 1_13
+ */
+#define WM5100_AIF1TX4_SLOT_MASK                0x003F  /* AIF1TX4_SLOT - [5:0] */
+#define WM5100_AIF1TX4_SLOT_SHIFT                    0  /* AIF1TX4_SLOT - [5:0] */
+#define WM5100_AIF1TX4_SLOT_WIDTH                    6  /* AIF1TX4_SLOT - [5:0] */
+
+/*
+ * R1293 (0x50D) - Audio IF 1_14
+ */
+#define WM5100_AIF1TX5_SLOT_MASK                0x003F  /* AIF1TX5_SLOT - [5:0] */
+#define WM5100_AIF1TX5_SLOT_SHIFT                    0  /* AIF1TX5_SLOT - [5:0] */
+#define WM5100_AIF1TX5_SLOT_WIDTH                    6  /* AIF1TX5_SLOT - [5:0] */
+
+/*
+ * R1294 (0x50E) - Audio IF 1_15
+ */
+#define WM5100_AIF1TX6_SLOT_MASK                0x003F  /* AIF1TX6_SLOT - [5:0] */
+#define WM5100_AIF1TX6_SLOT_SHIFT                    0  /* AIF1TX6_SLOT - [5:0] */
+#define WM5100_AIF1TX6_SLOT_WIDTH                    6  /* AIF1TX6_SLOT - [5:0] */
+
+/*
+ * R1295 (0x50F) - Audio IF 1_16
+ */
+#define WM5100_AIF1TX7_SLOT_MASK                0x003F  /* AIF1TX7_SLOT - [5:0] */
+#define WM5100_AIF1TX7_SLOT_SHIFT                    0  /* AIF1TX7_SLOT - [5:0] */
+#define WM5100_AIF1TX7_SLOT_WIDTH                    6  /* AIF1TX7_SLOT - [5:0] */
+
+/*
+ * R1296 (0x510) - Audio IF 1_17
+ */
+#define WM5100_AIF1TX8_SLOT_MASK                0x003F  /* AIF1TX8_SLOT - [5:0] */
+#define WM5100_AIF1TX8_SLOT_SHIFT                    0  /* AIF1TX8_SLOT - [5:0] */
+#define WM5100_AIF1TX8_SLOT_WIDTH                    6  /* AIF1TX8_SLOT - [5:0] */
+
+/*
+ * R1297 (0x511) - Audio IF 1_18
+ */
+#define WM5100_AIF1RX1_SLOT_MASK                0x003F  /* AIF1RX1_SLOT - [5:0] */
+#define WM5100_AIF1RX1_SLOT_SHIFT                    0  /* AIF1RX1_SLOT - [5:0] */
+#define WM5100_AIF1RX1_SLOT_WIDTH                    6  /* AIF1RX1_SLOT - [5:0] */
+
+/*
+ * R1298 (0x512) - Audio IF 1_19
+ */
+#define WM5100_AIF1RX2_SLOT_MASK                0x003F  /* AIF1RX2_SLOT - [5:0] */
+#define WM5100_AIF1RX2_SLOT_SHIFT                    0  /* AIF1RX2_SLOT - [5:0] */
+#define WM5100_AIF1RX2_SLOT_WIDTH                    6  /* AIF1RX2_SLOT - [5:0] */
+
+/*
+ * R1299 (0x513) - Audio IF 1_20
+ */
+#define WM5100_AIF1RX3_SLOT_MASK                0x003F  /* AIF1RX3_SLOT - [5:0] */
+#define WM5100_AIF1RX3_SLOT_SHIFT                    0  /* AIF1RX3_SLOT - [5:0] */
+#define WM5100_AIF1RX3_SLOT_WIDTH                    6  /* AIF1RX3_SLOT - [5:0] */
+
+/*
+ * R1300 (0x514) - Audio IF 1_21
+ */
+#define WM5100_AIF1RX4_SLOT_MASK                0x003F  /* AIF1RX4_SLOT - [5:0] */
+#define WM5100_AIF1RX4_SLOT_SHIFT                    0  /* AIF1RX4_SLOT - [5:0] */
+#define WM5100_AIF1RX4_SLOT_WIDTH                    6  /* AIF1RX4_SLOT - [5:0] */
+
+/*
+ * R1301 (0x515) - Audio IF 1_22
+ */
+#define WM5100_AIF1RX5_SLOT_MASK                0x003F  /* AIF1RX5_SLOT - [5:0] */
+#define WM5100_AIF1RX5_SLOT_SHIFT                    0  /* AIF1RX5_SLOT - [5:0] */
+#define WM5100_AIF1RX5_SLOT_WIDTH                    6  /* AIF1RX5_SLOT - [5:0] */
+
+/*
+ * R1302 (0x516) - Audio IF 1_23
+ */
+#define WM5100_AIF1RX6_SLOT_MASK                0x003F  /* AIF1RX6_SLOT - [5:0] */
+#define WM5100_AIF1RX6_SLOT_SHIFT                    0  /* AIF1RX6_SLOT - [5:0] */
+#define WM5100_AIF1RX6_SLOT_WIDTH                    6  /* AIF1RX6_SLOT - [5:0] */
+
+/*
+ * R1303 (0x517) - Audio IF 1_24
+ */
+#define WM5100_AIF1RX7_SLOT_MASK                0x003F  /* AIF1RX7_SLOT - [5:0] */
+#define WM5100_AIF1RX7_SLOT_SHIFT                    0  /* AIF1RX7_SLOT - [5:0] */
+#define WM5100_AIF1RX7_SLOT_WIDTH                    6  /* AIF1RX7_SLOT - [5:0] */
+
+/*
+ * R1304 (0x518) - Audio IF 1_25
+ */
+#define WM5100_AIF1RX8_SLOT_MASK                0x003F  /* AIF1RX8_SLOT - [5:0] */
+#define WM5100_AIF1RX8_SLOT_SHIFT                    0  /* AIF1RX8_SLOT - [5:0] */
+#define WM5100_AIF1RX8_SLOT_WIDTH                    6  /* AIF1RX8_SLOT - [5:0] */
+
+/*
+ * R1305 (0x519) - Audio IF 1_26
+ */
+#define WM5100_AIF1TX8_ENA                      0x0080  /* AIF1TX8_ENA */
+#define WM5100_AIF1TX8_ENA_MASK                 0x0080  /* AIF1TX8_ENA */
+#define WM5100_AIF1TX8_ENA_SHIFT                     7  /* AIF1TX8_ENA */
+#define WM5100_AIF1TX8_ENA_WIDTH                     1  /* AIF1TX8_ENA */
+#define WM5100_AIF1TX7_ENA                      0x0040  /* AIF1TX7_ENA */
+#define WM5100_AIF1TX7_ENA_MASK                 0x0040  /* AIF1TX7_ENA */
+#define WM5100_AIF1TX7_ENA_SHIFT                     6  /* AIF1TX7_ENA */
+#define WM5100_AIF1TX7_ENA_WIDTH                     1  /* AIF1TX7_ENA */
+#define WM5100_AIF1TX6_ENA                      0x0020  /* AIF1TX6_ENA */
+#define WM5100_AIF1TX6_ENA_MASK                 0x0020  /* AIF1TX6_ENA */
+#define WM5100_AIF1TX6_ENA_SHIFT                     5  /* AIF1TX6_ENA */
+#define WM5100_AIF1TX6_ENA_WIDTH                     1  /* AIF1TX6_ENA */
+#define WM5100_AIF1TX5_ENA                      0x0010  /* AIF1TX5_ENA */
+#define WM5100_AIF1TX5_ENA_MASK                 0x0010  /* AIF1TX5_ENA */
+#define WM5100_AIF1TX5_ENA_SHIFT                     4  /* AIF1TX5_ENA */
+#define WM5100_AIF1TX5_ENA_WIDTH                     1  /* AIF1TX5_ENA */
+#define WM5100_AIF1TX4_ENA                      0x0008  /* AIF1TX4_ENA */
+#define WM5100_AIF1TX4_ENA_MASK                 0x0008  /* AIF1TX4_ENA */
+#define WM5100_AIF1TX4_ENA_SHIFT                     3  /* AIF1TX4_ENA */
+#define WM5100_AIF1TX4_ENA_WIDTH                     1  /* AIF1TX4_ENA */
+#define WM5100_AIF1TX3_ENA                      0x0004  /* AIF1TX3_ENA */
+#define WM5100_AIF1TX3_ENA_MASK                 0x0004  /* AIF1TX3_ENA */
+#define WM5100_AIF1TX3_ENA_SHIFT                     2  /* AIF1TX3_ENA */
+#define WM5100_AIF1TX3_ENA_WIDTH                     1  /* AIF1TX3_ENA */
+#define WM5100_AIF1TX2_ENA                      0x0002  /* AIF1TX2_ENA */
+#define WM5100_AIF1TX2_ENA_MASK                 0x0002  /* AIF1TX2_ENA */
+#define WM5100_AIF1TX2_ENA_SHIFT                     1  /* AIF1TX2_ENA */
+#define WM5100_AIF1TX2_ENA_WIDTH                     1  /* AIF1TX2_ENA */
+#define WM5100_AIF1TX1_ENA                      0x0001  /* AIF1TX1_ENA */
+#define WM5100_AIF1TX1_ENA_MASK                 0x0001  /* AIF1TX1_ENA */
+#define WM5100_AIF1TX1_ENA_SHIFT                     0  /* AIF1TX1_ENA */
+#define WM5100_AIF1TX1_ENA_WIDTH                     1  /* AIF1TX1_ENA */
+
+/*
+ * R1306 (0x51A) - Audio IF 1_27
+ */
+#define WM5100_AIF1RX8_ENA                      0x0080  /* AIF1RX8_ENA */
+#define WM5100_AIF1RX8_ENA_MASK                 0x0080  /* AIF1RX8_ENA */
+#define WM5100_AIF1RX8_ENA_SHIFT                     7  /* AIF1RX8_ENA */
+#define WM5100_AIF1RX8_ENA_WIDTH                     1  /* AIF1RX8_ENA */
+#define WM5100_AIF1RX7_ENA                      0x0040  /* AIF1RX7_ENA */
+#define WM5100_AIF1RX7_ENA_MASK                 0x0040  /* AIF1RX7_ENA */
+#define WM5100_AIF1RX7_ENA_SHIFT                     6  /* AIF1RX7_ENA */
+#define WM5100_AIF1RX7_ENA_WIDTH                     1  /* AIF1RX7_ENA */
+#define WM5100_AIF1RX6_ENA                      0x0020  /* AIF1RX6_ENA */
+#define WM5100_AIF1RX6_ENA_MASK                 0x0020  /* AIF1RX6_ENA */
+#define WM5100_AIF1RX6_ENA_SHIFT                     5  /* AIF1RX6_ENA */
+#define WM5100_AIF1RX6_ENA_WIDTH                     1  /* AIF1RX6_ENA */
+#define WM5100_AIF1RX5_ENA                      0x0010  /* AIF1RX5_ENA */
+#define WM5100_AIF1RX5_ENA_MASK                 0x0010  /* AIF1RX5_ENA */
+#define WM5100_AIF1RX5_ENA_SHIFT                     4  /* AIF1RX5_ENA */
+#define WM5100_AIF1RX5_ENA_WIDTH                     1  /* AIF1RX5_ENA */
+#define WM5100_AIF1RX4_ENA                      0x0008  /* AIF1RX4_ENA */
+#define WM5100_AIF1RX4_ENA_MASK                 0x0008  /* AIF1RX4_ENA */
+#define WM5100_AIF1RX4_ENA_SHIFT                     3  /* AIF1RX4_ENA */
+#define WM5100_AIF1RX4_ENA_WIDTH                     1  /* AIF1RX4_ENA */
+#define WM5100_AIF1RX3_ENA                      0x0004  /* AIF1RX3_ENA */
+#define WM5100_AIF1RX3_ENA_MASK                 0x0004  /* AIF1RX3_ENA */
+#define WM5100_AIF1RX3_ENA_SHIFT                     2  /* AIF1RX3_ENA */
+#define WM5100_AIF1RX3_ENA_WIDTH                     1  /* AIF1RX3_ENA */
+#define WM5100_AIF1RX2_ENA                      0x0002  /* AIF1RX2_ENA */
+#define WM5100_AIF1RX2_ENA_MASK                 0x0002  /* AIF1RX2_ENA */
+#define WM5100_AIF1RX2_ENA_SHIFT                     1  /* AIF1RX2_ENA */
+#define WM5100_AIF1RX2_ENA_WIDTH                     1  /* AIF1RX2_ENA */
+#define WM5100_AIF1RX1_ENA                      0x0001  /* AIF1RX1_ENA */
+#define WM5100_AIF1RX1_ENA_MASK                 0x0001  /* AIF1RX1_ENA */
+#define WM5100_AIF1RX1_ENA_SHIFT                     0  /* AIF1RX1_ENA */
+#define WM5100_AIF1RX1_ENA_WIDTH                     1  /* AIF1RX1_ENA */
+
+/*
+ * R1344 (0x540) - Audio IF 2_1
+ */
+#define WM5100_AIF2_BCLK_INV                    0x0080  /* AIF2_BCLK_INV */
+#define WM5100_AIF2_BCLK_INV_MASK               0x0080  /* AIF2_BCLK_INV */
+#define WM5100_AIF2_BCLK_INV_SHIFT                   7  /* AIF2_BCLK_INV */
+#define WM5100_AIF2_BCLK_INV_WIDTH                   1  /* AIF2_BCLK_INV */
+#define WM5100_AIF2_BCLK_FRC                    0x0040  /* AIF2_BCLK_FRC */
+#define WM5100_AIF2_BCLK_FRC_MASK               0x0040  /* AIF2_BCLK_FRC */
+#define WM5100_AIF2_BCLK_FRC_SHIFT                   6  /* AIF2_BCLK_FRC */
+#define WM5100_AIF2_BCLK_FRC_WIDTH                   1  /* AIF2_BCLK_FRC */
+#define WM5100_AIF2_BCLK_MSTR                   0x0020  /* AIF2_BCLK_MSTR */
+#define WM5100_AIF2_BCLK_MSTR_MASK              0x0020  /* AIF2_BCLK_MSTR */
+#define WM5100_AIF2_BCLK_MSTR_SHIFT                  5  /* AIF2_BCLK_MSTR */
+#define WM5100_AIF2_BCLK_MSTR_WIDTH                  1  /* AIF2_BCLK_MSTR */
+#define WM5100_AIF2_BCLK_FREQ_MASK              0x001F  /* AIF2_BCLK_FREQ - [4:0] */
+#define WM5100_AIF2_BCLK_FREQ_SHIFT                  0  /* AIF2_BCLK_FREQ - [4:0] */
+#define WM5100_AIF2_BCLK_FREQ_WIDTH                  5  /* AIF2_BCLK_FREQ - [4:0] */
+
+/*
+ * R1345 (0x541) - Audio IF 2_2
+ */
+#define WM5100_AIF2TX_DAT_TRI                   0x0020  /* AIF2TX_DAT_TRI */
+#define WM5100_AIF2TX_DAT_TRI_MASK              0x0020  /* AIF2TX_DAT_TRI */
+#define WM5100_AIF2TX_DAT_TRI_SHIFT                  5  /* AIF2TX_DAT_TRI */
+#define WM5100_AIF2TX_DAT_TRI_WIDTH                  1  /* AIF2TX_DAT_TRI */
+#define WM5100_AIF2TX_LRCLK_SRC                 0x0008  /* AIF2TX_LRCLK_SRC */
+#define WM5100_AIF2TX_LRCLK_SRC_MASK            0x0008  /* AIF2TX_LRCLK_SRC */
+#define WM5100_AIF2TX_LRCLK_SRC_SHIFT                3  /* AIF2TX_LRCLK_SRC */
+#define WM5100_AIF2TX_LRCLK_SRC_WIDTH                1  /* AIF2TX_LRCLK_SRC */
+#define WM5100_AIF2TX_LRCLK_INV                 0x0004  /* AIF2TX_LRCLK_INV */
+#define WM5100_AIF2TX_LRCLK_INV_MASK            0x0004  /* AIF2TX_LRCLK_INV */
+#define WM5100_AIF2TX_LRCLK_INV_SHIFT                2  /* AIF2TX_LRCLK_INV */
+#define WM5100_AIF2TX_LRCLK_INV_WIDTH                1  /* AIF2TX_LRCLK_INV */
+#define WM5100_AIF2TX_LRCLK_FRC                 0x0002  /* AIF2TX_LRCLK_FRC */
+#define WM5100_AIF2TX_LRCLK_FRC_MASK            0x0002  /* AIF2TX_LRCLK_FRC */
+#define WM5100_AIF2TX_LRCLK_FRC_SHIFT                1  /* AIF2TX_LRCLK_FRC */
+#define WM5100_AIF2TX_LRCLK_FRC_WIDTH                1  /* AIF2TX_LRCLK_FRC */
+#define WM5100_AIF2TX_LRCLK_MSTR                0x0001  /* AIF2TX_LRCLK_MSTR */
+#define WM5100_AIF2TX_LRCLK_MSTR_MASK           0x0001  /* AIF2TX_LRCLK_MSTR */
+#define WM5100_AIF2TX_LRCLK_MSTR_SHIFT               0  /* AIF2TX_LRCLK_MSTR */
+#define WM5100_AIF2TX_LRCLK_MSTR_WIDTH               1  /* AIF2TX_LRCLK_MSTR */
+
+/*
+ * R1346 (0x542) - Audio IF 2_3
+ */
+#define WM5100_AIF2RX_LRCLK_INV                 0x0004  /* AIF2RX_LRCLK_INV */
+#define WM5100_AIF2RX_LRCLK_INV_MASK            0x0004  /* AIF2RX_LRCLK_INV */
+#define WM5100_AIF2RX_LRCLK_INV_SHIFT                2  /* AIF2RX_LRCLK_INV */
+#define WM5100_AIF2RX_LRCLK_INV_WIDTH                1  /* AIF2RX_LRCLK_INV */
+#define WM5100_AIF2RX_LRCLK_FRC                 0x0002  /* AIF2RX_LRCLK_FRC */
+#define WM5100_AIF2RX_LRCLK_FRC_MASK            0x0002  /* AIF2RX_LRCLK_FRC */
+#define WM5100_AIF2RX_LRCLK_FRC_SHIFT                1  /* AIF2RX_LRCLK_FRC */
+#define WM5100_AIF2RX_LRCLK_FRC_WIDTH                1  /* AIF2RX_LRCLK_FRC */
+#define WM5100_AIF2RX_LRCLK_MSTR                0x0001  /* AIF2RX_LRCLK_MSTR */
+#define WM5100_AIF2RX_LRCLK_MSTR_MASK           0x0001  /* AIF2RX_LRCLK_MSTR */
+#define WM5100_AIF2RX_LRCLK_MSTR_SHIFT               0  /* AIF2RX_LRCLK_MSTR */
+#define WM5100_AIF2RX_LRCLK_MSTR_WIDTH               1  /* AIF2RX_LRCLK_MSTR */
+
+/*
+ * R1347 (0x543) - Audio IF 2_4
+ */
+#define WM5100_AIF2_TRI                         0x0040  /* AIF2_TRI */
+#define WM5100_AIF2_TRI_MASK                    0x0040  /* AIF2_TRI */
+#define WM5100_AIF2_TRI_SHIFT                        6  /* AIF2_TRI */
+#define WM5100_AIF2_TRI_WIDTH                        1  /* AIF2_TRI */
+#define WM5100_AIF2_RATE_MASK                   0x0003  /* AIF2_RATE - [1:0] */
+#define WM5100_AIF2_RATE_SHIFT                       0  /* AIF2_RATE - [1:0] */
+#define WM5100_AIF2_RATE_WIDTH                       2  /* AIF2_RATE - [1:0] */
+
+/*
+ * R1348 (0x544) - Audio IF 2_5
+ */
+#define WM5100_AIF2_FMT_MASK                    0x0007  /* AIF2_FMT - [2:0] */
+#define WM5100_AIF2_FMT_SHIFT                        0  /* AIF2_FMT - [2:0] */
+#define WM5100_AIF2_FMT_WIDTH                        3  /* AIF2_FMT - [2:0] */
+
+/*
+ * R1349 (0x545) - Audio IF 2_6
+ */
+#define WM5100_AIF2TX_BCPF_MASK                 0x1FFF  /* AIF2TX_BCPF - [12:0] */
+#define WM5100_AIF2TX_BCPF_SHIFT                     0  /* AIF2TX_BCPF - [12:0] */
+#define WM5100_AIF2TX_BCPF_WIDTH                    13  /* AIF2TX_BCPF - [12:0] */
+
+/*
+ * R1350 (0x546) - Audio IF 2_7
+ */
+#define WM5100_AIF2RX_BCPF_MASK                 0x1FFF  /* AIF2RX_BCPF - [12:0] */
+#define WM5100_AIF2RX_BCPF_SHIFT                     0  /* AIF2RX_BCPF - [12:0] */
+#define WM5100_AIF2RX_BCPF_WIDTH                    13  /* AIF2RX_BCPF - [12:0] */
+
+/*
+ * R1351 (0x547) - Audio IF 2_8
+ */
+#define WM5100_AIF2TX_WL_MASK                   0x3F00  /* AIF2TX_WL - [13:8] */
+#define WM5100_AIF2TX_WL_SHIFT                       8  /* AIF2TX_WL - [13:8] */
+#define WM5100_AIF2TX_WL_WIDTH                       6  /* AIF2TX_WL - [13:8] */
+#define WM5100_AIF2TX_SLOT_LEN_MASK             0x00FF  /* AIF2TX_SLOT_LEN - [7:0] */
+#define WM5100_AIF2TX_SLOT_LEN_SHIFT                 0  /* AIF2TX_SLOT_LEN - [7:0] */
+#define WM5100_AIF2TX_SLOT_LEN_WIDTH                 8  /* AIF2TX_SLOT_LEN - [7:0] */
+
+/*
+ * R1352 (0x548) - Audio IF 2_9
+ */
+#define WM5100_AIF2RX_WL_MASK                   0x3F00  /* AIF2RX_WL - [13:8] */
+#define WM5100_AIF2RX_WL_SHIFT                       8  /* AIF2RX_WL - [13:8] */
+#define WM5100_AIF2RX_WL_WIDTH                       6  /* AIF2RX_WL - [13:8] */
+#define WM5100_AIF2RX_SLOT_LEN_MASK             0x00FF  /* AIF2RX_SLOT_LEN - [7:0] */
+#define WM5100_AIF2RX_SLOT_LEN_SHIFT                 0  /* AIF2RX_SLOT_LEN - [7:0] */
+#define WM5100_AIF2RX_SLOT_LEN_WIDTH                 8  /* AIF2RX_SLOT_LEN - [7:0] */
+
+/*
+ * R1353 (0x549) - Audio IF 2_10
+ */
+#define WM5100_AIF2TX1_SLOT_MASK                0x003F  /* AIF2TX1_SLOT - [5:0] */
+#define WM5100_AIF2TX1_SLOT_SHIFT                    0  /* AIF2TX1_SLOT - [5:0] */
+#define WM5100_AIF2TX1_SLOT_WIDTH                    6  /* AIF2TX1_SLOT - [5:0] */
+
+/*
+ * R1354 (0x54A) - Audio IF 2_11
+ */
+#define WM5100_AIF2TX2_SLOT_MASK                0x003F  /* AIF2TX2_SLOT - [5:0] */
+#define WM5100_AIF2TX2_SLOT_SHIFT                    0  /* AIF2TX2_SLOT - [5:0] */
+#define WM5100_AIF2TX2_SLOT_WIDTH                    6  /* AIF2TX2_SLOT - [5:0] */
+
+/*
+ * R1361 (0x551) - Audio IF 2_18
+ */
+#define WM5100_AIF2RX1_SLOT_MASK                0x003F  /* AIF2RX1_SLOT - [5:0] */
+#define WM5100_AIF2RX1_SLOT_SHIFT                    0  /* AIF2RX1_SLOT - [5:0] */
+#define WM5100_AIF2RX1_SLOT_WIDTH                    6  /* AIF2RX1_SLOT - [5:0] */
+
+/*
+ * R1362 (0x552) - Audio IF 2_19
+ */
+#define WM5100_AIF2RX2_SLOT_MASK                0x003F  /* AIF2RX2_SLOT - [5:0] */
+#define WM5100_AIF2RX2_SLOT_SHIFT                    0  /* AIF2RX2_SLOT - [5:0] */
+#define WM5100_AIF2RX2_SLOT_WIDTH                    6  /* AIF2RX2_SLOT - [5:0] */
+
+/*
+ * R1369 (0x559) - Audio IF 2_26
+ */
+#define WM5100_AIF2TX2_ENA                      0x0002  /* AIF2TX2_ENA */
+#define WM5100_AIF2TX2_ENA_MASK                 0x0002  /* AIF2TX2_ENA */
+#define WM5100_AIF2TX2_ENA_SHIFT                     1  /* AIF2TX2_ENA */
+#define WM5100_AIF2TX2_ENA_WIDTH                     1  /* AIF2TX2_ENA */
+#define WM5100_AIF2TX1_ENA                      0x0001  /* AIF2TX1_ENA */
+#define WM5100_AIF2TX1_ENA_MASK                 0x0001  /* AIF2TX1_ENA */
+#define WM5100_AIF2TX1_ENA_SHIFT                     0  /* AIF2TX1_ENA */
+#define WM5100_AIF2TX1_ENA_WIDTH                     1  /* AIF2TX1_ENA */
+
+/*
+ * R1370 (0x55A) - Audio IF 2_27
+ */
+#define WM5100_AIF2RX2_ENA                      0x0002  /* AIF2RX2_ENA */
+#define WM5100_AIF2RX2_ENA_MASK                 0x0002  /* AIF2RX2_ENA */
+#define WM5100_AIF2RX2_ENA_SHIFT                     1  /* AIF2RX2_ENA */
+#define WM5100_AIF2RX2_ENA_WIDTH                     1  /* AIF2RX2_ENA */
+#define WM5100_AIF2RX1_ENA                      0x0001  /* AIF2RX1_ENA */
+#define WM5100_AIF2RX1_ENA_MASK                 0x0001  /* AIF2RX1_ENA */
+#define WM5100_AIF2RX1_ENA_SHIFT                     0  /* AIF2RX1_ENA */
+#define WM5100_AIF2RX1_ENA_WIDTH                     1  /* AIF2RX1_ENA */
+
+/*
+ * R1408 (0x580) - Audio IF 3_1
+ */
+#define WM5100_AIF3_BCLK_INV                    0x0080  /* AIF3_BCLK_INV */
+#define WM5100_AIF3_BCLK_INV_MASK               0x0080  /* AIF3_BCLK_INV */
+#define WM5100_AIF3_BCLK_INV_SHIFT                   7  /* AIF3_BCLK_INV */
+#define WM5100_AIF3_BCLK_INV_WIDTH                   1  /* AIF3_BCLK_INV */
+#define WM5100_AIF3_BCLK_FRC                    0x0040  /* AIF3_BCLK_FRC */
+#define WM5100_AIF3_BCLK_FRC_MASK               0x0040  /* AIF3_BCLK_FRC */
+#define WM5100_AIF3_BCLK_FRC_SHIFT                   6  /* AIF3_BCLK_FRC */
+#define WM5100_AIF3_BCLK_FRC_WIDTH                   1  /* AIF3_BCLK_FRC */
+#define WM5100_AIF3_BCLK_MSTR                   0x0020  /* AIF3_BCLK_MSTR */
+#define WM5100_AIF3_BCLK_MSTR_MASK              0x0020  /* AIF3_BCLK_MSTR */
+#define WM5100_AIF3_BCLK_MSTR_SHIFT                  5  /* AIF3_BCLK_MSTR */
+#define WM5100_AIF3_BCLK_MSTR_WIDTH                  1  /* AIF3_BCLK_MSTR */
+#define WM5100_AIF3_BCLK_FREQ_MASK              0x001F  /* AIF3_BCLK_FREQ - [4:0] */
+#define WM5100_AIF3_BCLK_FREQ_SHIFT                  0  /* AIF3_BCLK_FREQ - [4:0] */
+#define WM5100_AIF3_BCLK_FREQ_WIDTH                  5  /* AIF3_BCLK_FREQ - [4:0] */
+
+/*
+ * R1409 (0x581) - Audio IF 3_2
+ */
+#define WM5100_AIF3TX_DAT_TRI                   0x0020  /* AIF3TX_DAT_TRI */
+#define WM5100_AIF3TX_DAT_TRI_MASK              0x0020  /* AIF3TX_DAT_TRI */
+#define WM5100_AIF3TX_DAT_TRI_SHIFT                  5  /* AIF3TX_DAT_TRI */
+#define WM5100_AIF3TX_DAT_TRI_WIDTH                  1  /* AIF3TX_DAT_TRI */
+#define WM5100_AIF3TX_LRCLK_SRC                 0x0008  /* AIF3TX_LRCLK_SRC */
+#define WM5100_AIF3TX_LRCLK_SRC_MASK            0x0008  /* AIF3TX_LRCLK_SRC */
+#define WM5100_AIF3TX_LRCLK_SRC_SHIFT                3  /* AIF3TX_LRCLK_SRC */
+#define WM5100_AIF3TX_LRCLK_SRC_WIDTH                1  /* AIF3TX_LRCLK_SRC */
+#define WM5100_AIF3TX_LRCLK_INV                 0x0004  /* AIF3TX_LRCLK_INV */
+#define WM5100_AIF3TX_LRCLK_INV_MASK            0x0004  /* AIF3TX_LRCLK_INV */
+#define WM5100_AIF3TX_LRCLK_INV_SHIFT                2  /* AIF3TX_LRCLK_INV */
+#define WM5100_AIF3TX_LRCLK_INV_WIDTH                1  /* AIF3TX_LRCLK_INV */
+#define WM5100_AIF3TX_LRCLK_FRC                 0x0002  /* AIF3TX_LRCLK_FRC */
+#define WM5100_AIF3TX_LRCLK_FRC_MASK            0x0002  /* AIF3TX_LRCLK_FRC */
+#define WM5100_AIF3TX_LRCLK_FRC_SHIFT                1  /* AIF3TX_LRCLK_FRC */
+#define WM5100_AIF3TX_LRCLK_FRC_WIDTH                1  /* AIF3TX_LRCLK_FRC */
+#define WM5100_AIF3TX_LRCLK_MSTR                0x0001  /* AIF3TX_LRCLK_MSTR */
+#define WM5100_AIF3TX_LRCLK_MSTR_MASK           0x0001  /* AIF3TX_LRCLK_MSTR */
+#define WM5100_AIF3TX_LRCLK_MSTR_SHIFT               0  /* AIF3TX_LRCLK_MSTR */
+#define WM5100_AIF3TX_LRCLK_MSTR_WIDTH               1  /* AIF3TX_LRCLK_MSTR */
+
+/*
+ * R1410 (0x582) - Audio IF 3_3
+ */
+#define WM5100_AIF3RX_LRCLK_INV                 0x0004  /* AIF3RX_LRCLK_INV */
+#define WM5100_AIF3RX_LRCLK_INV_MASK            0x0004  /* AIF3RX_LRCLK_INV */
+#define WM5100_AIF3RX_LRCLK_INV_SHIFT                2  /* AIF3RX_LRCLK_INV */
+#define WM5100_AIF3RX_LRCLK_INV_WIDTH                1  /* AIF3RX_LRCLK_INV */
+#define WM5100_AIF3RX_LRCLK_FRC                 0x0002  /* AIF3RX_LRCLK_FRC */
+#define WM5100_AIF3RX_LRCLK_FRC_MASK            0x0002  /* AIF3RX_LRCLK_FRC */
+#define WM5100_AIF3RX_LRCLK_FRC_SHIFT                1  /* AIF3RX_LRCLK_FRC */
+#define WM5100_AIF3RX_LRCLK_FRC_WIDTH                1  /* AIF3RX_LRCLK_FRC */
+#define WM5100_AIF3RX_LRCLK_MSTR                0x0001  /* AIF3RX_LRCLK_MSTR */
+#define WM5100_AIF3RX_LRCLK_MSTR_MASK           0x0001  /* AIF3RX_LRCLK_MSTR */
+#define WM5100_AIF3RX_LRCLK_MSTR_SHIFT               0  /* AIF3RX_LRCLK_MSTR */
+#define WM5100_AIF3RX_LRCLK_MSTR_WIDTH               1  /* AIF3RX_LRCLK_MSTR */
+
+/*
+ * R1411 (0x583) - Audio IF 3_4
+ */
+#define WM5100_AIF3_TRI                         0x0040  /* AIF3_TRI */
+#define WM5100_AIF3_TRI_MASK                    0x0040  /* AIF3_TRI */
+#define WM5100_AIF3_TRI_SHIFT                        6  /* AIF3_TRI */
+#define WM5100_AIF3_TRI_WIDTH                        1  /* AIF3_TRI */
+#define WM5100_AIF3_RATE_MASK                   0x0003  /* AIF3_RATE - [1:0] */
+#define WM5100_AIF3_RATE_SHIFT                       0  /* AIF3_RATE - [1:0] */
+#define WM5100_AIF3_RATE_WIDTH                       2  /* AIF3_RATE - [1:0] */
+
+/*
+ * R1412 (0x584) - Audio IF 3_5
+ */
+#define WM5100_AIF3_FMT_MASK                    0x0007  /* AIF3_FMT - [2:0] */
+#define WM5100_AIF3_FMT_SHIFT                        0  /* AIF3_FMT - [2:0] */
+#define WM5100_AIF3_FMT_WIDTH                        3  /* AIF3_FMT - [2:0] */
+
+/*
+ * R1413 (0x585) - Audio IF 3_6
+ */
+#define WM5100_AIF3TX_BCPF_MASK                 0x1FFF  /* AIF3TX_BCPF - [12:0] */
+#define WM5100_AIF3TX_BCPF_SHIFT                     0  /* AIF3TX_BCPF - [12:0] */
+#define WM5100_AIF3TX_BCPF_WIDTH                    13  /* AIF3TX_BCPF - [12:0] */
+
+/*
+ * R1414 (0x586) - Audio IF 3_7
+ */
+#define WM5100_AIF3RX_BCPF_MASK                 0x1FFF  /* AIF3RX_BCPF - [12:0] */
+#define WM5100_AIF3RX_BCPF_SHIFT                     0  /* AIF3RX_BCPF - [12:0] */
+#define WM5100_AIF3RX_BCPF_WIDTH                    13  /* AIF3RX_BCPF - [12:0] */
+
+/*
+ * R1415 (0x587) - Audio IF 3_8
+ */
+#define WM5100_AIF3TX_WL_MASK                   0x3F00  /* AIF3TX_WL - [13:8] */
+#define WM5100_AIF3TX_WL_SHIFT                       8  /* AIF3TX_WL - [13:8] */
+#define WM5100_AIF3TX_WL_WIDTH                       6  /* AIF3TX_WL - [13:8] */
+#define WM5100_AIF3TX_SLOT_LEN_MASK             0x00FF  /* AIF3TX_SLOT_LEN - [7:0] */
+#define WM5100_AIF3TX_SLOT_LEN_SHIFT                 0  /* AIF3TX_SLOT_LEN - [7:0] */
+#define WM5100_AIF3TX_SLOT_LEN_WIDTH                 8  /* AIF3TX_SLOT_LEN - [7:0] */
+
+/*
+ * R1416 (0x588) - Audio IF 3_9
+ */
+#define WM5100_AIF3RX_WL_MASK                   0x3F00  /* AIF3RX_WL - [13:8] */
+#define WM5100_AIF3RX_WL_SHIFT                       8  /* AIF3RX_WL - [13:8] */
+#define WM5100_AIF3RX_WL_WIDTH                       6  /* AIF3RX_WL - [13:8] */
+#define WM5100_AIF3RX_SLOT_LEN_MASK             0x00FF  /* AIF3RX_SLOT_LEN - [7:0] */
+#define WM5100_AIF3RX_SLOT_LEN_SHIFT                 0  /* AIF3RX_SLOT_LEN - [7:0] */
+#define WM5100_AIF3RX_SLOT_LEN_WIDTH                 8  /* AIF3RX_SLOT_LEN - [7:0] */
+
+/*
+ * R1417 (0x589) - Audio IF 3_10
+ */
+#define WM5100_AIF3TX1_SLOT_MASK                0x003F  /* AIF3TX1_SLOT - [5:0] */
+#define WM5100_AIF3TX1_SLOT_SHIFT                    0  /* AIF3TX1_SLOT - [5:0] */
+#define WM5100_AIF3TX1_SLOT_WIDTH                    6  /* AIF3TX1_SLOT - [5:0] */
+
+/*
+ * R1418 (0x58A) - Audio IF 3_11
+ */
+#define WM5100_AIF3TX2_SLOT_MASK                0x003F  /* AIF3TX2_SLOT - [5:0] */
+#define WM5100_AIF3TX2_SLOT_SHIFT                    0  /* AIF3TX2_SLOT - [5:0] */
+#define WM5100_AIF3TX2_SLOT_WIDTH                    6  /* AIF3TX2_SLOT - [5:0] */
+
+/*
+ * R1425 (0x591) - Audio IF 3_18
+ */
+#define WM5100_AIF3RX1_SLOT_MASK                0x003F  /* AIF3RX1_SLOT - [5:0] */
+#define WM5100_AIF3RX1_SLOT_SHIFT                    0  /* AIF3RX1_SLOT - [5:0] */
+#define WM5100_AIF3RX1_SLOT_WIDTH                    6  /* AIF3RX1_SLOT - [5:0] */
+
+/*
+ * R1426 (0x592) - Audio IF 3_19
+ */
+#define WM5100_AIF3RX2_SLOT_MASK                0x003F  /* AIF3RX2_SLOT - [5:0] */
+#define WM5100_AIF3RX2_SLOT_SHIFT                    0  /* AIF3RX2_SLOT - [5:0] */
+#define WM5100_AIF3RX2_SLOT_WIDTH                    6  /* AIF3RX2_SLOT - [5:0] */
+
+/*
+ * R1433 (0x599) - Audio IF 3_26
+ */
+#define WM5100_AIF3TX2_ENA                      0x0002  /* AIF3TX2_ENA */
+#define WM5100_AIF3TX2_ENA_MASK                 0x0002  /* AIF3TX2_ENA */
+#define WM5100_AIF3TX2_ENA_SHIFT                     1  /* AIF3TX2_ENA */
+#define WM5100_AIF3TX2_ENA_WIDTH                     1  /* AIF3TX2_ENA */
+#define WM5100_AIF3TX1_ENA                      0x0001  /* AIF3TX1_ENA */
+#define WM5100_AIF3TX1_ENA_MASK                 0x0001  /* AIF3TX1_ENA */
+#define WM5100_AIF3TX1_ENA_SHIFT                     0  /* AIF3TX1_ENA */
+#define WM5100_AIF3TX1_ENA_WIDTH                     1  /* AIF3TX1_ENA */
+
+/*
+ * R1434 (0x59A) - Audio IF 3_27
+ */
+#define WM5100_AIF3RX2_ENA                      0x0002  /* AIF3RX2_ENA */
+#define WM5100_AIF3RX2_ENA_MASK                 0x0002  /* AIF3RX2_ENA */
+#define WM5100_AIF3RX2_ENA_SHIFT                     1  /* AIF3RX2_ENA */
+#define WM5100_AIF3RX2_ENA_WIDTH                     1  /* AIF3RX2_ENA */
+#define WM5100_AIF3RX1_ENA                      0x0001  /* AIF3RX1_ENA */
+#define WM5100_AIF3RX1_ENA_MASK                 0x0001  /* AIF3RX1_ENA */
+#define WM5100_AIF3RX1_ENA_SHIFT                     0  /* AIF3RX1_ENA */
+#define WM5100_AIF3RX1_ENA_WIDTH                     1  /* AIF3RX1_ENA */
+
+#define WM5100_MIXER_VOL_MASK                0x00FE  /* MIXER_VOL - [7:1] */
+#define WM5100_MIXER_VOL_SHIFT                    1  /* MIXER_VOL - [7:1] */
+#define WM5100_MIXER_VOL_WIDTH                    7  /* MIXER_VOL - [7:1] */
+
+/*
+ * R3072 (0xC00) - GPIO CTRL 1
+ */
+#define WM5100_GP1_DIR                          0x8000  /* GP1_DIR */
+#define WM5100_GP1_DIR_MASK                     0x8000  /* GP1_DIR */
+#define WM5100_GP1_DIR_SHIFT                        15  /* GP1_DIR */
+#define WM5100_GP1_DIR_WIDTH                         1  /* GP1_DIR */
+#define WM5100_GP1_PU                           0x4000  /* GP1_PU */
+#define WM5100_GP1_PU_MASK                      0x4000  /* GP1_PU */
+#define WM5100_GP1_PU_SHIFT                         14  /* GP1_PU */
+#define WM5100_GP1_PU_WIDTH                          1  /* GP1_PU */
+#define WM5100_GP1_PD                           0x2000  /* GP1_PD */
+#define WM5100_GP1_PD_MASK                      0x2000  /* GP1_PD */
+#define WM5100_GP1_PD_SHIFT                         13  /* GP1_PD */
+#define WM5100_GP1_PD_WIDTH                          1  /* GP1_PD */
+#define WM5100_GP1_POL                          0x0400  /* GP1_POL */
+#define WM5100_GP1_POL_MASK                     0x0400  /* GP1_POL */
+#define WM5100_GP1_POL_SHIFT                        10  /* GP1_POL */
+#define WM5100_GP1_POL_WIDTH                         1  /* GP1_POL */
+#define WM5100_GP1_OP_CFG                       0x0200  /* GP1_OP_CFG */
+#define WM5100_GP1_OP_CFG_MASK                  0x0200  /* GP1_OP_CFG */
+#define WM5100_GP1_OP_CFG_SHIFT                      9  /* GP1_OP_CFG */
+#define WM5100_GP1_OP_CFG_WIDTH                      1  /* GP1_OP_CFG */
+#define WM5100_GP1_DB                           0x0100  /* GP1_DB */
+#define WM5100_GP1_DB_MASK                      0x0100  /* GP1_DB */
+#define WM5100_GP1_DB_SHIFT                          8  /* GP1_DB */
+#define WM5100_GP1_DB_WIDTH                          1  /* GP1_DB */
+#define WM5100_GP1_LVL                          0x0040  /* GP1_LVL */
+#define WM5100_GP1_LVL_MASK                     0x0040  /* GP1_LVL */
+#define WM5100_GP1_LVL_SHIFT                         6  /* GP1_LVL */
+#define WM5100_GP1_LVL_WIDTH                         1  /* GP1_LVL */
+#define WM5100_GP1_FN_MASK                      0x003F  /* GP1_FN - [5:0] */
+#define WM5100_GP1_FN_SHIFT                          0  /* GP1_FN - [5:0] */
+#define WM5100_GP1_FN_WIDTH                          6  /* GP1_FN - [5:0] */
+
+/*
+ * R3073 (0xC01) - GPIO CTRL 2
+ */
+#define WM5100_GP2_DIR                          0x8000  /* GP2_DIR */
+#define WM5100_GP2_DIR_MASK                     0x8000  /* GP2_DIR */
+#define WM5100_GP2_DIR_SHIFT                        15  /* GP2_DIR */
+#define WM5100_GP2_DIR_WIDTH                         1  /* GP2_DIR */
+#define WM5100_GP2_PU                           0x4000  /* GP2_PU */
+#define WM5100_GP2_PU_MASK                      0x4000  /* GP2_PU */
+#define WM5100_GP2_PU_SHIFT                         14  /* GP2_PU */
+#define WM5100_GP2_PU_WIDTH                          1  /* GP2_PU */
+#define WM5100_GP2_PD                           0x2000  /* GP2_PD */
+#define WM5100_GP2_PD_MASK                      0x2000  /* GP2_PD */
+#define WM5100_GP2_PD_SHIFT                         13  /* GP2_PD */
+#define WM5100_GP2_PD_WIDTH                          1  /* GP2_PD */
+#define WM5100_GP2_POL                          0x0400  /* GP2_POL */
+#define WM5100_GP2_POL_MASK                     0x0400  /* GP2_POL */
+#define WM5100_GP2_POL_SHIFT                        10  /* GP2_POL */
+#define WM5100_GP2_POL_WIDTH                         1  /* GP2_POL */
+#define WM5100_GP2_OP_CFG                       0x0200  /* GP2_OP_CFG */
+#define WM5100_GP2_OP_CFG_MASK                  0x0200  /* GP2_OP_CFG */
+#define WM5100_GP2_OP_CFG_SHIFT                      9  /* GP2_OP_CFG */
+#define WM5100_GP2_OP_CFG_WIDTH                      1  /* GP2_OP_CFG */
+#define WM5100_GP2_DB                           0x0100  /* GP2_DB */
+#define WM5100_GP2_DB_MASK                      0x0100  /* GP2_DB */
+#define WM5100_GP2_DB_SHIFT                          8  /* GP2_DB */
+#define WM5100_GP2_DB_WIDTH                          1  /* GP2_DB */
+#define WM5100_GP2_LVL                          0x0040  /* GP2_LVL */
+#define WM5100_GP2_LVL_MASK                     0x0040  /* GP2_LVL */
+#define WM5100_GP2_LVL_SHIFT                         6  /* GP2_LVL */
+#define WM5100_GP2_LVL_WIDTH                         1  /* GP2_LVL */
+#define WM5100_GP2_FN_MASK                      0x003F  /* GP2_FN - [5:0] */
+#define WM5100_GP2_FN_SHIFT                          0  /* GP2_FN - [5:0] */
+#define WM5100_GP2_FN_WIDTH                          6  /* GP2_FN - [5:0] */
+
+/*
+ * R3074 (0xC02) - GPIO CTRL 3
+ */
+#define WM5100_GP3_DIR                          0x8000  /* GP3_DIR */
+#define WM5100_GP3_DIR_MASK                     0x8000  /* GP3_DIR */
+#define WM5100_GP3_DIR_SHIFT                        15  /* GP3_DIR */
+#define WM5100_GP3_DIR_WIDTH                         1  /* GP3_DIR */
+#define WM5100_GP3_PU                           0x4000  /* GP3_PU */
+#define WM5100_GP3_PU_MASK                      0x4000  /* GP3_PU */
+#define WM5100_GP3_PU_SHIFT                         14  /* GP3_PU */
+#define WM5100_GP3_PU_WIDTH                          1  /* GP3_PU */
+#define WM5100_GP3_PD                           0x2000  /* GP3_PD */
+#define WM5100_GP3_PD_MASK                      0x2000  /* GP3_PD */
+#define WM5100_GP3_PD_SHIFT                         13  /* GP3_PD */
+#define WM5100_GP3_PD_WIDTH                          1  /* GP3_PD */
+#define WM5100_GP3_POL                          0x0400  /* GP3_POL */
+#define WM5100_GP3_POL_MASK                     0x0400  /* GP3_POL */
+#define WM5100_GP3_POL_SHIFT                        10  /* GP3_POL */
+#define WM5100_GP3_POL_WIDTH                         1  /* GP3_POL */
+#define WM5100_GP3_OP_CFG                       0x0200  /* GP3_OP_CFG */
+#define WM5100_GP3_OP_CFG_MASK                  0x0200  /* GP3_OP_CFG */
+#define WM5100_GP3_OP_CFG_SHIFT                      9  /* GP3_OP_CFG */
+#define WM5100_GP3_OP_CFG_WIDTH                      1  /* GP3_OP_CFG */
+#define WM5100_GP3_DB                           0x0100  /* GP3_DB */
+#define WM5100_GP3_DB_MASK                      0x0100  /* GP3_DB */
+#define WM5100_GP3_DB_SHIFT                          8  /* GP3_DB */
+#define WM5100_GP3_DB_WIDTH                          1  /* GP3_DB */
+#define WM5100_GP3_LVL                          0x0040  /* GP3_LVL */
+#define WM5100_GP3_LVL_MASK                     0x0040  /* GP3_LVL */
+#define WM5100_GP3_LVL_SHIFT                         6  /* GP3_LVL */
+#define WM5100_GP3_LVL_WIDTH                         1  /* GP3_LVL */
+#define WM5100_GP3_FN_MASK                      0x003F  /* GP3_FN - [5:0] */
+#define WM5100_GP3_FN_SHIFT                          0  /* GP3_FN - [5:0] */
+#define WM5100_GP3_FN_WIDTH                          6  /* GP3_FN - [5:0] */
+
+/*
+ * R3075 (0xC03) - GPIO CTRL 4
+ */
+#define WM5100_GP4_DIR                          0x8000  /* GP4_DIR */
+#define WM5100_GP4_DIR_MASK                     0x8000  /* GP4_DIR */
+#define WM5100_GP4_DIR_SHIFT                        15  /* GP4_DIR */
+#define WM5100_GP4_DIR_WIDTH                         1  /* GP4_DIR */
+#define WM5100_GP4_PU                           0x4000  /* GP4_PU */
+#define WM5100_GP4_PU_MASK                      0x4000  /* GP4_PU */
+#define WM5100_GP4_PU_SHIFT                         14  /* GP4_PU */
+#define WM5100_GP4_PU_WIDTH                          1  /* GP4_PU */
+#define WM5100_GP4_PD                           0x2000  /* GP4_PD */
+#define WM5100_GP4_PD_MASK                      0x2000  /* GP4_PD */
+#define WM5100_GP4_PD_SHIFT                         13  /* GP4_PD */
+#define WM5100_GP4_PD_WIDTH                          1  /* GP4_PD */
+#define WM5100_GP4_POL                          0x0400  /* GP4_POL */
+#define WM5100_GP4_POL_MASK                     0x0400  /* GP4_POL */
+#define WM5100_GP4_POL_SHIFT                        10  /* GP4_POL */
+#define WM5100_GP4_POL_WIDTH                         1  /* GP4_POL */
+#define WM5100_GP4_OP_CFG                       0x0200  /* GP4_OP_CFG */
+#define WM5100_GP4_OP_CFG_MASK                  0x0200  /* GP4_OP_CFG */
+#define WM5100_GP4_OP_CFG_SHIFT                      9  /* GP4_OP_CFG */
+#define WM5100_GP4_OP_CFG_WIDTH                      1  /* GP4_OP_CFG */
+#define WM5100_GP4_DB                           0x0100  /* GP4_DB */
+#define WM5100_GP4_DB_MASK                      0x0100  /* GP4_DB */
+#define WM5100_GP4_DB_SHIFT                          8  /* GP4_DB */
+#define WM5100_GP4_DB_WIDTH                          1  /* GP4_DB */
+#define WM5100_GP4_LVL                          0x0040  /* GP4_LVL */
+#define WM5100_GP4_LVL_MASK                     0x0040  /* GP4_LVL */
+#define WM5100_GP4_LVL_SHIFT                         6  /* GP4_LVL */
+#define WM5100_GP4_LVL_WIDTH                         1  /* GP4_LVL */
+#define WM5100_GP4_FN_MASK                      0x003F  /* GP4_FN - [5:0] */
+#define WM5100_GP4_FN_SHIFT                          0  /* GP4_FN - [5:0] */
+#define WM5100_GP4_FN_WIDTH                          6  /* GP4_FN - [5:0] */
+
+/*
+ * R3076 (0xC04) - GPIO CTRL 5
+ */
+#define WM5100_GP5_DIR                          0x8000  /* GP5_DIR */
+#define WM5100_GP5_DIR_MASK                     0x8000  /* GP5_DIR */
+#define WM5100_GP5_DIR_SHIFT                        15  /* GP5_DIR */
+#define WM5100_GP5_DIR_WIDTH                         1  /* GP5_DIR */
+#define WM5100_GP5_PU                           0x4000  /* GP5_PU */
+#define WM5100_GP5_PU_MASK                      0x4000  /* GP5_PU */
+#define WM5100_GP5_PU_SHIFT                         14  /* GP5_PU */
+#define WM5100_GP5_PU_WIDTH                          1  /* GP5_PU */
+#define WM5100_GP5_PD                           0x2000  /* GP5_PD */
+#define WM5100_GP5_PD_MASK                      0x2000  /* GP5_PD */
+#define WM5100_GP5_PD_SHIFT                         13  /* GP5_PD */
+#define WM5100_GP5_PD_WIDTH                          1  /* GP5_PD */
+#define WM5100_GP5_POL                          0x0400  /* GP5_POL */
+#define WM5100_GP5_POL_MASK                     0x0400  /* GP5_POL */
+#define WM5100_GP5_POL_SHIFT                        10  /* GP5_POL */
+#define WM5100_GP5_POL_WIDTH                         1  /* GP5_POL */
+#define WM5100_GP5_OP_CFG                       0x0200  /* GP5_OP_CFG */
+#define WM5100_GP5_OP_CFG_MASK                  0x0200  /* GP5_OP_CFG */
+#define WM5100_GP5_OP_CFG_SHIFT                      9  /* GP5_OP_CFG */
+#define WM5100_GP5_OP_CFG_WIDTH                      1  /* GP5_OP_CFG */
+#define WM5100_GP5_DB                           0x0100  /* GP5_DB */
+#define WM5100_GP5_DB_MASK                      0x0100  /* GP5_DB */
+#define WM5100_GP5_DB_SHIFT                          8  /* GP5_DB */
+#define WM5100_GP5_DB_WIDTH                          1  /* GP5_DB */
+#define WM5100_GP5_LVL                          0x0040  /* GP5_LVL */
+#define WM5100_GP5_LVL_MASK                     0x0040  /* GP5_LVL */
+#define WM5100_GP5_LVL_SHIFT                         6  /* GP5_LVL */
+#define WM5100_GP5_LVL_WIDTH                         1  /* GP5_LVL */
+#define WM5100_GP5_FN_MASK                      0x003F  /* GP5_FN - [5:0] */
+#define WM5100_GP5_FN_SHIFT                          0  /* GP5_FN - [5:0] */
+#define WM5100_GP5_FN_WIDTH                          6  /* GP5_FN - [5:0] */
+
+/*
+ * R3077 (0xC05) - GPIO CTRL 6
+ */
+#define WM5100_GP6_DIR                          0x8000  /* GP6_DIR */
+#define WM5100_GP6_DIR_MASK                     0x8000  /* GP6_DIR */
+#define WM5100_GP6_DIR_SHIFT                        15  /* GP6_DIR */
+#define WM5100_GP6_DIR_WIDTH                         1  /* GP6_DIR */
+#define WM5100_GP6_PU                           0x4000  /* GP6_PU */
+#define WM5100_GP6_PU_MASK                      0x4000  /* GP6_PU */
+#define WM5100_GP6_PU_SHIFT                         14  /* GP6_PU */
+#define WM5100_GP6_PU_WIDTH                          1  /* GP6_PU */
+#define WM5100_GP6_PD                           0x2000  /* GP6_PD */
+#define WM5100_GP6_PD_MASK                      0x2000  /* GP6_PD */
+#define WM5100_GP6_PD_SHIFT                         13  /* GP6_PD */
+#define WM5100_GP6_PD_WIDTH                          1  /* GP6_PD */
+#define WM5100_GP6_POL                          0x0400  /* GP6_POL */
+#define WM5100_GP6_POL_MASK                     0x0400  /* GP6_POL */
+#define WM5100_GP6_POL_SHIFT                        10  /* GP6_POL */
+#define WM5100_GP6_POL_WIDTH                         1  /* GP6_POL */
+#define WM5100_GP6_OP_CFG                       0x0200  /* GP6_OP_CFG */
+#define WM5100_GP6_OP_CFG_MASK                  0x0200  /* GP6_OP_CFG */
+#define WM5100_GP6_OP_CFG_SHIFT                      9  /* GP6_OP_CFG */
+#define WM5100_GP6_OP_CFG_WIDTH                      1  /* GP6_OP_CFG */
+#define WM5100_GP6_DB                           0x0100  /* GP6_DB */
+#define WM5100_GP6_DB_MASK                      0x0100  /* GP6_DB */
+#define WM5100_GP6_DB_SHIFT                          8  /* GP6_DB */
+#define WM5100_GP6_DB_WIDTH                          1  /* GP6_DB */
+#define WM5100_GP6_LVL                          0x0040  /* GP6_LVL */
+#define WM5100_GP6_LVL_MASK                     0x0040  /* GP6_LVL */
+#define WM5100_GP6_LVL_SHIFT                         6  /* GP6_LVL */
+#define WM5100_GP6_LVL_WIDTH                         1  /* GP6_LVL */
+#define WM5100_GP6_FN_MASK                      0x003F  /* GP6_FN - [5:0] */
+#define WM5100_GP6_FN_SHIFT                          0  /* GP6_FN - [5:0] */
+#define WM5100_GP6_FN_WIDTH                          6  /* GP6_FN - [5:0] */
+
+/*
+ * R3107 (0xC23) - Misc Pad Ctrl 1
+ */
+#define WM5100_LDO1ENA_PD                       0x8000  /* LDO1ENA_PD */
+#define WM5100_LDO1ENA_PD_MASK                  0x8000  /* LDO1ENA_PD */
+#define WM5100_LDO1ENA_PD_SHIFT                     15  /* LDO1ENA_PD */
+#define WM5100_LDO1ENA_PD_WIDTH                      1  /* LDO1ENA_PD */
+#define WM5100_MCLK2_PD                         0x2000  /* MCLK2_PD */
+#define WM5100_MCLK2_PD_MASK                    0x2000  /* MCLK2_PD */
+#define WM5100_MCLK2_PD_SHIFT                       13  /* MCLK2_PD */
+#define WM5100_MCLK2_PD_WIDTH                        1  /* MCLK2_PD */
+#define WM5100_MCLK1_PD                         0x1000  /* MCLK1_PD */
+#define WM5100_MCLK1_PD_MASK                    0x1000  /* MCLK1_PD */
+#define WM5100_MCLK1_PD_SHIFT                       12  /* MCLK1_PD */
+#define WM5100_MCLK1_PD_WIDTH                        1  /* MCLK1_PD */
+#define WM5100_RESET_PU                         0x0002  /* RESET_PU */
+#define WM5100_RESET_PU_MASK                    0x0002  /* RESET_PU */
+#define WM5100_RESET_PU_SHIFT                        1  /* RESET_PU */
+#define WM5100_RESET_PU_WIDTH                        1  /* RESET_PU */
+#define WM5100_ADDR_PD                          0x0001  /* ADDR_PD */
+#define WM5100_ADDR_PD_MASK                     0x0001  /* ADDR_PD */
+#define WM5100_ADDR_PD_SHIFT                         0  /* ADDR_PD */
+#define WM5100_ADDR_PD_WIDTH                         1  /* ADDR_PD */
+
+/*
+ * R3108 (0xC24) - Misc Pad Ctrl 2
+ */
+#define WM5100_DMICDAT4_PD                      0x0008  /* DMICDAT4_PD */
+#define WM5100_DMICDAT4_PD_MASK                 0x0008  /* DMICDAT4_PD */
+#define WM5100_DMICDAT4_PD_SHIFT                     3  /* DMICDAT4_PD */
+#define WM5100_DMICDAT4_PD_WIDTH                     1  /* DMICDAT4_PD */
+#define WM5100_DMICDAT3_PD                      0x0004  /* DMICDAT3_PD */
+#define WM5100_DMICDAT3_PD_MASK                 0x0004  /* DMICDAT3_PD */
+#define WM5100_DMICDAT3_PD_SHIFT                     2  /* DMICDAT3_PD */
+#define WM5100_DMICDAT3_PD_WIDTH                     1  /* DMICDAT3_PD */
+#define WM5100_DMICDAT2_PD                      0x0002  /* DMICDAT2_PD */
+#define WM5100_DMICDAT2_PD_MASK                 0x0002  /* DMICDAT2_PD */
+#define WM5100_DMICDAT2_PD_SHIFT                     1  /* DMICDAT2_PD */
+#define WM5100_DMICDAT2_PD_WIDTH                     1  /* DMICDAT2_PD */
+#define WM5100_DMICDAT1_PD                      0x0001  /* DMICDAT1_PD */
+#define WM5100_DMICDAT1_PD_MASK                 0x0001  /* DMICDAT1_PD */
+#define WM5100_DMICDAT1_PD_SHIFT                     0  /* DMICDAT1_PD */
+#define WM5100_DMICDAT1_PD_WIDTH                     1  /* DMICDAT1_PD */
+
+/*
+ * R3109 (0xC25) - Misc Pad Ctrl 3
+ */
+#define WM5100_AIF1RXLRCLK_PU                   0x0020  /* AIF1RXLRCLK_PU */
+#define WM5100_AIF1RXLRCLK_PU_MASK              0x0020  /* AIF1RXLRCLK_PU */
+#define WM5100_AIF1RXLRCLK_PU_SHIFT                  5  /* AIF1RXLRCLK_PU */
+#define WM5100_AIF1RXLRCLK_PU_WIDTH                  1  /* AIF1RXLRCLK_PU */
+#define WM5100_AIF1RXLRCLK_PD                   0x0010  /* AIF1RXLRCLK_PD */
+#define WM5100_AIF1RXLRCLK_PD_MASK              0x0010  /* AIF1RXLRCLK_PD */
+#define WM5100_AIF1RXLRCLK_PD_SHIFT                  4  /* AIF1RXLRCLK_PD */
+#define WM5100_AIF1RXLRCLK_PD_WIDTH                  1  /* AIF1RXLRCLK_PD */
+#define WM5100_AIF1BCLK_PU                      0x0008  /* AIF1BCLK_PU */
+#define WM5100_AIF1BCLK_PU_MASK                 0x0008  /* AIF1BCLK_PU */
+#define WM5100_AIF1BCLK_PU_SHIFT                     3  /* AIF1BCLK_PU */
+#define WM5100_AIF1BCLK_PU_WIDTH                     1  /* AIF1BCLK_PU */
+#define WM5100_AIF1BCLK_PD                      0x0004  /* AIF1BCLK_PD */
+#define WM5100_AIF1BCLK_PD_MASK                 0x0004  /* AIF1BCLK_PD */
+#define WM5100_AIF1BCLK_PD_SHIFT                     2  /* AIF1BCLK_PD */
+#define WM5100_AIF1BCLK_PD_WIDTH                     1  /* AIF1BCLK_PD */
+#define WM5100_AIF1RXDAT_PU                     0x0002  /* AIF1RXDAT_PU */
+#define WM5100_AIF1RXDAT_PU_MASK                0x0002  /* AIF1RXDAT_PU */
+#define WM5100_AIF1RXDAT_PU_SHIFT                    1  /* AIF1RXDAT_PU */
+#define WM5100_AIF1RXDAT_PU_WIDTH                    1  /* AIF1RXDAT_PU */
+#define WM5100_AIF1RXDAT_PD                     0x0001  /* AIF1RXDAT_PD */
+#define WM5100_AIF1RXDAT_PD_MASK                0x0001  /* AIF1RXDAT_PD */
+#define WM5100_AIF1RXDAT_PD_SHIFT                    0  /* AIF1RXDAT_PD */
+#define WM5100_AIF1RXDAT_PD_WIDTH                    1  /* AIF1RXDAT_PD */
+
+/*
+ * R3110 (0xC26) - Misc Pad Ctrl 4
+ */
+#define WM5100_AIF2RXLRCLK_PU                   0x0020  /* AIF2RXLRCLK_PU */
+#define WM5100_AIF2RXLRCLK_PU_MASK              0x0020  /* AIF2RXLRCLK_PU */
+#define WM5100_AIF2RXLRCLK_PU_SHIFT                  5  /* AIF2RXLRCLK_PU */
+#define WM5100_AIF2RXLRCLK_PU_WIDTH                  1  /* AIF2RXLRCLK_PU */
+#define WM5100_AIF2RXLRCLK_PD                   0x0010  /* AIF2RXLRCLK_PD */
+#define WM5100_AIF2RXLRCLK_PD_MASK              0x0010  /* AIF2RXLRCLK_PD */
+#define WM5100_AIF2RXLRCLK_PD_SHIFT                  4  /* AIF2RXLRCLK_PD */
+#define WM5100_AIF2RXLRCLK_PD_WIDTH                  1  /* AIF2RXLRCLK_PD */
+#define WM5100_AIF2BCLK_PU                      0x0008  /* AIF2BCLK_PU */
+#define WM5100_AIF2BCLK_PU_MASK                 0x0008  /* AIF2BCLK_PU */
+#define WM5100_AIF2BCLK_PU_SHIFT                     3  /* AIF2BCLK_PU */
+#define WM5100_AIF2BCLK_PU_WIDTH                     1  /* AIF2BCLK_PU */
+#define WM5100_AIF2BCLK_PD                      0x0004  /* AIF2BCLK_PD */
+#define WM5100_AIF2BCLK_PD_MASK                 0x0004  /* AIF2BCLK_PD */
+#define WM5100_AIF2BCLK_PD_SHIFT                     2  /* AIF2BCLK_PD */
+#define WM5100_AIF2BCLK_PD_WIDTH                     1  /* AIF2BCLK_PD */
+#define WM5100_AIF2RXDAT_PU                     0x0002  /* AIF2RXDAT_PU */
+#define WM5100_AIF2RXDAT_PU_MASK                0x0002  /* AIF2RXDAT_PU */
+#define WM5100_AIF2RXDAT_PU_SHIFT                    1  /* AIF2RXDAT_PU */
+#define WM5100_AIF2RXDAT_PU_WIDTH                    1  /* AIF2RXDAT_PU */
+#define WM5100_AIF2RXDAT_PD                     0x0001  /* AIF2RXDAT_PD */
+#define WM5100_AIF2RXDAT_PD_MASK                0x0001  /* AIF2RXDAT_PD */
+#define WM5100_AIF2RXDAT_PD_SHIFT                    0  /* AIF2RXDAT_PD */
+#define WM5100_AIF2RXDAT_PD_WIDTH                    1  /* AIF2RXDAT_PD */
+
+/*
+ * R3111 (0xC27) - Misc Pad Ctrl 5
+ */
+#define WM5100_AIF3RXLRCLK_PU                   0x0020  /* AIF3RXLRCLK_PU */
+#define WM5100_AIF3RXLRCLK_PU_MASK              0x0020  /* AIF3RXLRCLK_PU */
+#define WM5100_AIF3RXLRCLK_PU_SHIFT                  5  /* AIF3RXLRCLK_PU */
+#define WM5100_AIF3RXLRCLK_PU_WIDTH                  1  /* AIF3RXLRCLK_PU */
+#define WM5100_AIF3RXLRCLK_PD                   0x0010  /* AIF3RXLRCLK_PD */
+#define WM5100_AIF3RXLRCLK_PD_MASK              0x0010  /* AIF3RXLRCLK_PD */
+#define WM5100_AIF3RXLRCLK_PD_SHIFT                  4  /* AIF3RXLRCLK_PD */
+#define WM5100_AIF3RXLRCLK_PD_WIDTH                  1  /* AIF3RXLRCLK_PD */
+#define WM5100_AIF3BCLK_PU                      0x0008  /* AIF3BCLK_PU */
+#define WM5100_AIF3BCLK_PU_MASK                 0x0008  /* AIF3BCLK_PU */
+#define WM5100_AIF3BCLK_PU_SHIFT                     3  /* AIF3BCLK_PU */
+#define WM5100_AIF3BCLK_PU_WIDTH                     1  /* AIF3BCLK_PU */
+#define WM5100_AIF3BCLK_PD                      0x0004  /* AIF3BCLK_PD */
+#define WM5100_AIF3BCLK_PD_MASK                 0x0004  /* AIF3BCLK_PD */
+#define WM5100_AIF3BCLK_PD_SHIFT                     2  /* AIF3BCLK_PD */
+#define WM5100_AIF3BCLK_PD_WIDTH                     1  /* AIF3BCLK_PD */
+#define WM5100_AIF3RXDAT_PU                     0x0002  /* AIF3RXDAT_PU */
+#define WM5100_AIF3RXDAT_PU_MASK                0x0002  /* AIF3RXDAT_PU */
+#define WM5100_AIF3RXDAT_PU_SHIFT                    1  /* AIF3RXDAT_PU */
+#define WM5100_AIF3RXDAT_PU_WIDTH                    1  /* AIF3RXDAT_PU */
+#define WM5100_AIF3RXDAT_PD                     0x0001  /* AIF3RXDAT_PD */
+#define WM5100_AIF3RXDAT_PD_MASK                0x0001  /* AIF3RXDAT_PD */
+#define WM5100_AIF3RXDAT_PD_SHIFT                    0  /* AIF3RXDAT_PD */
+#define WM5100_AIF3RXDAT_PD_WIDTH                    1  /* AIF3RXDAT_PD */
+
+/*
+ * R3112 (0xC28) - Misc GPIO 1
+ */
+#define WM5100_OPCLK_SEL_MASK                   0x0003  /* OPCLK_SEL - [1:0] */
+#define WM5100_OPCLK_SEL_SHIFT                       0  /* OPCLK_SEL - [1:0] */
+#define WM5100_OPCLK_SEL_WIDTH                       2  /* OPCLK_SEL - [1:0] */
+
+/*
+ * R3328 (0xD00) - Interrupt Status 1
+ */
+#define WM5100_GP6_EINT                         0x0020  /* GP6_EINT */
+#define WM5100_GP6_EINT_MASK                    0x0020  /* GP6_EINT */
+#define WM5100_GP6_EINT_SHIFT                        5  /* GP6_EINT */
+#define WM5100_GP6_EINT_WIDTH                        1  /* GP6_EINT */
+#define WM5100_GP5_EINT                         0x0010  /* GP5_EINT */
+#define WM5100_GP5_EINT_MASK                    0x0010  /* GP5_EINT */
+#define WM5100_GP5_EINT_SHIFT                        4  /* GP5_EINT */
+#define WM5100_GP5_EINT_WIDTH                        1  /* GP5_EINT */
+#define WM5100_GP4_EINT                         0x0008  /* GP4_EINT */
+#define WM5100_GP4_EINT_MASK                    0x0008  /* GP4_EINT */
+#define WM5100_GP4_EINT_SHIFT                        3  /* GP4_EINT */
+#define WM5100_GP4_EINT_WIDTH                        1  /* GP4_EINT */
+#define WM5100_GP3_EINT                         0x0004  /* GP3_EINT */
+#define WM5100_GP3_EINT_MASK                    0x0004  /* GP3_EINT */
+#define WM5100_GP3_EINT_SHIFT                        2  /* GP3_EINT */
+#define WM5100_GP3_EINT_WIDTH                        1  /* GP3_EINT */
+#define WM5100_GP2_EINT                         0x0002  /* GP2_EINT */
+#define WM5100_GP2_EINT_MASK                    0x0002  /* GP2_EINT */
+#define WM5100_GP2_EINT_SHIFT                        1  /* GP2_EINT */
+#define WM5100_GP2_EINT_WIDTH                        1  /* GP2_EINT */
+#define WM5100_GP1_EINT                         0x0001  /* GP1_EINT */
+#define WM5100_GP1_EINT_MASK                    0x0001  /* GP1_EINT */
+#define WM5100_GP1_EINT_SHIFT                        0  /* GP1_EINT */
+#define WM5100_GP1_EINT_WIDTH                        1  /* GP1_EINT */
+
+/*
+ * R3329 (0xD01) - Interrupt Status 2
+ */
+#define WM5100_DSP_IRQ6_EINT                    0x0020  /* DSP_IRQ6_EINT */
+#define WM5100_DSP_IRQ6_EINT_MASK               0x0020  /* DSP_IRQ6_EINT */
+#define WM5100_DSP_IRQ6_EINT_SHIFT                   5  /* DSP_IRQ6_EINT */
+#define WM5100_DSP_IRQ6_EINT_WIDTH                   1  /* DSP_IRQ6_EINT */
+#define WM5100_DSP_IRQ5_EINT                    0x0010  /* DSP_IRQ5_EINT */
+#define WM5100_DSP_IRQ5_EINT_MASK               0x0010  /* DSP_IRQ5_EINT */
+#define WM5100_DSP_IRQ5_EINT_SHIFT                   4  /* DSP_IRQ5_EINT */
+#define WM5100_DSP_IRQ5_EINT_WIDTH                   1  /* DSP_IRQ5_EINT */
+#define WM5100_DSP_IRQ4_EINT                    0x0008  /* DSP_IRQ4_EINT */
+#define WM5100_DSP_IRQ4_EINT_MASK               0x0008  /* DSP_IRQ4_EINT */
+#define WM5100_DSP_IRQ4_EINT_SHIFT                   3  /* DSP_IRQ4_EINT */
+#define WM5100_DSP_IRQ4_EINT_WIDTH                   1  /* DSP_IRQ4_EINT */
+#define WM5100_DSP_IRQ3_EINT                    0x0004  /* DSP_IRQ3_EINT */
+#define WM5100_DSP_IRQ3_EINT_MASK               0x0004  /* DSP_IRQ3_EINT */
+#define WM5100_DSP_IRQ3_EINT_SHIFT                   2  /* DSP_IRQ3_EINT */
+#define WM5100_DSP_IRQ3_EINT_WIDTH                   1  /* DSP_IRQ3_EINT */
+#define WM5100_DSP_IRQ2_EINT                    0x0002  /* DSP_IRQ2_EINT */
+#define WM5100_DSP_IRQ2_EINT_MASK               0x0002  /* DSP_IRQ2_EINT */
+#define WM5100_DSP_IRQ2_EINT_SHIFT                   1  /* DSP_IRQ2_EINT */
+#define WM5100_DSP_IRQ2_EINT_WIDTH                   1  /* DSP_IRQ2_EINT */
+#define WM5100_DSP_IRQ1_EINT                    0x0001  /* DSP_IRQ1_EINT */
+#define WM5100_DSP_IRQ1_EINT_MASK               0x0001  /* DSP_IRQ1_EINT */
+#define WM5100_DSP_IRQ1_EINT_SHIFT                   0  /* DSP_IRQ1_EINT */
+#define WM5100_DSP_IRQ1_EINT_WIDTH                   1  /* DSP_IRQ1_EINT */
+
+/*
+ * R3330 (0xD02) - Interrupt Status 3
+ */
+#define WM5100_SPK_SHUTDOWN_WARN_EINT           0x8000  /* SPK_SHUTDOWN_WARN_EINT */
+#define WM5100_SPK_SHUTDOWN_WARN_EINT_MASK      0x8000  /* SPK_SHUTDOWN_WARN_EINT */
+#define WM5100_SPK_SHUTDOWN_WARN_EINT_SHIFT         15  /* SPK_SHUTDOWN_WARN_EINT */
+#define WM5100_SPK_SHUTDOWN_WARN_EINT_WIDTH          1  /* SPK_SHUTDOWN_WARN_EINT */
+#define WM5100_SPK_SHUTDOWN_EINT                0x4000  /* SPK_SHUTDOWN_EINT */
+#define WM5100_SPK_SHUTDOWN_EINT_MASK           0x4000  /* SPK_SHUTDOWN_EINT */
+#define WM5100_SPK_SHUTDOWN_EINT_SHIFT              14  /* SPK_SHUTDOWN_EINT */
+#define WM5100_SPK_SHUTDOWN_EINT_WIDTH               1  /* SPK_SHUTDOWN_EINT */
+#define WM5100_HPDET_EINT                       0x2000  /* HPDET_EINT */
+#define WM5100_HPDET_EINT_MASK                  0x2000  /* HPDET_EINT */
+#define WM5100_HPDET_EINT_SHIFT                     13  /* HPDET_EINT */
+#define WM5100_HPDET_EINT_WIDTH                      1  /* HPDET_EINT */
+#define WM5100_ACCDET_EINT                      0x1000  /* ACCDET_EINT */
+#define WM5100_ACCDET_EINT_MASK                 0x1000  /* ACCDET_EINT */
+#define WM5100_ACCDET_EINT_SHIFT                    12  /* ACCDET_EINT */
+#define WM5100_ACCDET_EINT_WIDTH                     1  /* ACCDET_EINT */
+#define WM5100_DRC_SIG_DET_EINT                 0x0200  /* DRC_SIG_DET_EINT */
+#define WM5100_DRC_SIG_DET_EINT_MASK            0x0200  /* DRC_SIG_DET_EINT */
+#define WM5100_DRC_SIG_DET_EINT_SHIFT                9  /* DRC_SIG_DET_EINT */
+#define WM5100_DRC_SIG_DET_EINT_WIDTH                1  /* DRC_SIG_DET_EINT */
+#define WM5100_ASRC2_LOCK_EINT                  0x0100  /* ASRC2_LOCK_EINT */
+#define WM5100_ASRC2_LOCK_EINT_MASK             0x0100  /* ASRC2_LOCK_EINT */
+#define WM5100_ASRC2_LOCK_EINT_SHIFT                 8  /* ASRC2_LOCK_EINT */
+#define WM5100_ASRC2_LOCK_EINT_WIDTH                 1  /* ASRC2_LOCK_EINT */
+#define WM5100_ASRC1_LOCK_EINT                  0x0080  /* ASRC1_LOCK_EINT */
+#define WM5100_ASRC1_LOCK_EINT_MASK             0x0080  /* ASRC1_LOCK_EINT */
+#define WM5100_ASRC1_LOCK_EINT_SHIFT                 7  /* ASRC1_LOCK_EINT */
+#define WM5100_ASRC1_LOCK_EINT_WIDTH                 1  /* ASRC1_LOCK_EINT */
+#define WM5100_FLL2_LOCK_EINT                   0x0008  /* FLL2_LOCK_EINT */
+#define WM5100_FLL2_LOCK_EINT_MASK              0x0008  /* FLL2_LOCK_EINT */
+#define WM5100_FLL2_LOCK_EINT_SHIFT                  3  /* FLL2_LOCK_EINT */
+#define WM5100_FLL2_LOCK_EINT_WIDTH                  1  /* FLL2_LOCK_EINT */
+#define WM5100_FLL1_LOCK_EINT                   0x0004  /* FLL1_LOCK_EINT */
+#define WM5100_FLL1_LOCK_EINT_MASK              0x0004  /* FLL1_LOCK_EINT */
+#define WM5100_FLL1_LOCK_EINT_SHIFT                  2  /* FLL1_LOCK_EINT */
+#define WM5100_FLL1_LOCK_EINT_WIDTH                  1  /* FLL1_LOCK_EINT */
+#define WM5100_CLKGEN_ERR_EINT                  0x0002  /* CLKGEN_ERR_EINT */
+#define WM5100_CLKGEN_ERR_EINT_MASK             0x0002  /* CLKGEN_ERR_EINT */
+#define WM5100_CLKGEN_ERR_EINT_SHIFT                 1  /* CLKGEN_ERR_EINT */
+#define WM5100_CLKGEN_ERR_EINT_WIDTH                 1  /* CLKGEN_ERR_EINT */
+#define WM5100_CLKGEN_ERR_ASYNC_EINT            0x0001  /* CLKGEN_ERR_ASYNC_EINT */
+#define WM5100_CLKGEN_ERR_ASYNC_EINT_MASK       0x0001  /* CLKGEN_ERR_ASYNC_EINT */
+#define WM5100_CLKGEN_ERR_ASYNC_EINT_SHIFT           0  /* CLKGEN_ERR_ASYNC_EINT */
+#define WM5100_CLKGEN_ERR_ASYNC_EINT_WIDTH           1  /* CLKGEN_ERR_ASYNC_EINT */
+
+/*
+ * R3331 (0xD03) - Interrupt Status 4
+ */
+#define WM5100_AIF3_ERR_EINT                    0x2000  /* AIF3_ERR_EINT */
+#define WM5100_AIF3_ERR_EINT_MASK               0x2000  /* AIF3_ERR_EINT */
+#define WM5100_AIF3_ERR_EINT_SHIFT                  13  /* AIF3_ERR_EINT */
+#define WM5100_AIF3_ERR_EINT_WIDTH                   1  /* AIF3_ERR_EINT */
+#define WM5100_AIF2_ERR_EINT                    0x1000  /* AIF2_ERR_EINT */
+#define WM5100_AIF2_ERR_EINT_MASK               0x1000  /* AIF2_ERR_EINT */
+#define WM5100_AIF2_ERR_EINT_SHIFT                  12  /* AIF2_ERR_EINT */
+#define WM5100_AIF2_ERR_EINT_WIDTH                   1  /* AIF2_ERR_EINT */
+#define WM5100_AIF1_ERR_EINT                    0x0800  /* AIF1_ERR_EINT */
+#define WM5100_AIF1_ERR_EINT_MASK               0x0800  /* AIF1_ERR_EINT */
+#define WM5100_AIF1_ERR_EINT_SHIFT                  11  /* AIF1_ERR_EINT */
+#define WM5100_AIF1_ERR_EINT_WIDTH                   1  /* AIF1_ERR_EINT */
+#define WM5100_CTRLIF_ERR_EINT                  0x0400  /* CTRLIF_ERR_EINT */
+#define WM5100_CTRLIF_ERR_EINT_MASK             0x0400  /* CTRLIF_ERR_EINT */
+#define WM5100_CTRLIF_ERR_EINT_SHIFT                10  /* CTRLIF_ERR_EINT */
+#define WM5100_CTRLIF_ERR_EINT_WIDTH                 1  /* CTRLIF_ERR_EINT */
+#define WM5100_ISRC2_UNDERCLOCKED_EINT          0x0200  /* ISRC2_UNDERCLOCKED_EINT */
+#define WM5100_ISRC2_UNDERCLOCKED_EINT_MASK     0x0200  /* ISRC2_UNDERCLOCKED_EINT */
+#define WM5100_ISRC2_UNDERCLOCKED_EINT_SHIFT         9  /* ISRC2_UNDERCLOCKED_EINT */
+#define WM5100_ISRC2_UNDERCLOCKED_EINT_WIDTH         1  /* ISRC2_UNDERCLOCKED_EINT */
+#define WM5100_ISRC1_UNDERCLOCKED_EINT          0x0100  /* ISRC1_UNDERCLOCKED_EINT */
+#define WM5100_ISRC1_UNDERCLOCKED_EINT_MASK     0x0100  /* ISRC1_UNDERCLOCKED_EINT */
+#define WM5100_ISRC1_UNDERCLOCKED_EINT_SHIFT         8  /* ISRC1_UNDERCLOCKED_EINT */
+#define WM5100_ISRC1_UNDERCLOCKED_EINT_WIDTH         1  /* ISRC1_UNDERCLOCKED_EINT */
+#define WM5100_FX_UNDERCLOCKED_EINT             0x0080  /* FX_UNDERCLOCKED_EINT */
+#define WM5100_FX_UNDERCLOCKED_EINT_MASK        0x0080  /* FX_UNDERCLOCKED_EINT */
+#define WM5100_FX_UNDERCLOCKED_EINT_SHIFT            7  /* FX_UNDERCLOCKED_EINT */
+#define WM5100_FX_UNDERCLOCKED_EINT_WIDTH            1  /* FX_UNDERCLOCKED_EINT */
+#define WM5100_AIF3_UNDERCLOCKED_EINT           0x0040  /* AIF3_UNDERCLOCKED_EINT */
+#define WM5100_AIF3_UNDERCLOCKED_EINT_MASK      0x0040  /* AIF3_UNDERCLOCKED_EINT */
+#define WM5100_AIF3_UNDERCLOCKED_EINT_SHIFT          6  /* AIF3_UNDERCLOCKED_EINT */
+#define WM5100_AIF3_UNDERCLOCKED_EINT_WIDTH          1  /* AIF3_UNDERCLOCKED_EINT */
+#define WM5100_AIF2_UNDERCLOCKED_EINT           0x0020  /* AIF2_UNDERCLOCKED_EINT */
+#define WM5100_AIF2_UNDERCLOCKED_EINT_MASK      0x0020  /* AIF2_UNDERCLOCKED_EINT */
+#define WM5100_AIF2_UNDERCLOCKED_EINT_SHIFT          5  /* AIF2_UNDERCLOCKED_EINT */
+#define WM5100_AIF2_UNDERCLOCKED_EINT_WIDTH          1  /* AIF2_UNDERCLOCKED_EINT */
+#define WM5100_AIF1_UNDERCLOCKED_EINT           0x0010  /* AIF1_UNDERCLOCKED_EINT */
+#define WM5100_AIF1_UNDERCLOCKED_EINT_MASK      0x0010  /* AIF1_UNDERCLOCKED_EINT */
+#define WM5100_AIF1_UNDERCLOCKED_EINT_SHIFT          4  /* AIF1_UNDERCLOCKED_EINT */
+#define WM5100_AIF1_UNDERCLOCKED_EINT_WIDTH          1  /* AIF1_UNDERCLOCKED_EINT */
+#define WM5100_ASRC_UNDERCLOCKED_EINT           0x0008  /* ASRC_UNDERCLOCKED_EINT */
+#define WM5100_ASRC_UNDERCLOCKED_EINT_MASK      0x0008  /* ASRC_UNDERCLOCKED_EINT */
+#define WM5100_ASRC_UNDERCLOCKED_EINT_SHIFT          3  /* ASRC_UNDERCLOCKED_EINT */
+#define WM5100_ASRC_UNDERCLOCKED_EINT_WIDTH          1  /* ASRC_UNDERCLOCKED_EINT */
+#define WM5100_DAC_UNDERCLOCKED_EINT            0x0004  /* DAC_UNDERCLOCKED_EINT */
+#define WM5100_DAC_UNDERCLOCKED_EINT_MASK       0x0004  /* DAC_UNDERCLOCKED_EINT */
+#define WM5100_DAC_UNDERCLOCKED_EINT_SHIFT           2  /* DAC_UNDERCLOCKED_EINT */
+#define WM5100_DAC_UNDERCLOCKED_EINT_WIDTH           1  /* DAC_UNDERCLOCKED_EINT */
+#define WM5100_ADC_UNDERCLOCKED_EINT            0x0002  /* ADC_UNDERCLOCKED_EINT */
+#define WM5100_ADC_UNDERCLOCKED_EINT_MASK       0x0002  /* ADC_UNDERCLOCKED_EINT */
+#define WM5100_ADC_UNDERCLOCKED_EINT_SHIFT           1  /* ADC_UNDERCLOCKED_EINT */
+#define WM5100_ADC_UNDERCLOCKED_EINT_WIDTH           1  /* ADC_UNDERCLOCKED_EINT */
+#define WM5100_MIXER_UNDERCLOCKED_EINT          0x0001  /* MIXER_UNDERCLOCKED_EINT */
+#define WM5100_MIXER_UNDERCLOCKED_EINT_MASK     0x0001  /* MIXER_UNDERCLOCKED_EINT */
+#define WM5100_MIXER_UNDERCLOCKED_EINT_SHIFT         0  /* MIXER_UNDERCLOCKED_EINT */
+#define WM5100_MIXER_UNDERCLOCKED_EINT_WIDTH         1  /* MIXER_UNDERCLOCKED_EINT */
+
+/*
+ * R3332 (0xD04) - Interrupt Raw Status 2
+ */
+#define WM5100_DSP_IRQ6_STS                     0x0020  /* DSP_IRQ6_STS */
+#define WM5100_DSP_IRQ6_STS_MASK                0x0020  /* DSP_IRQ6_STS */
+#define WM5100_DSP_IRQ6_STS_SHIFT                    5  /* DSP_IRQ6_STS */
+#define WM5100_DSP_IRQ6_STS_WIDTH                    1  /* DSP_IRQ6_STS */
+#define WM5100_DSP_IRQ5_STS                     0x0010  /* DSP_IRQ5_STS */
+#define WM5100_DSP_IRQ5_STS_MASK                0x0010  /* DSP_IRQ5_STS */
+#define WM5100_DSP_IRQ5_STS_SHIFT                    4  /* DSP_IRQ5_STS */
+#define WM5100_DSP_IRQ5_STS_WIDTH                    1  /* DSP_IRQ5_STS */
+#define WM5100_DSP_IRQ4_STS                     0x0008  /* DSP_IRQ4_STS */
+#define WM5100_DSP_IRQ4_STS_MASK                0x0008  /* DSP_IRQ4_STS */
+#define WM5100_DSP_IRQ4_STS_SHIFT                    3  /* DSP_IRQ4_STS */
+#define WM5100_DSP_IRQ4_STS_WIDTH                    1  /* DSP_IRQ4_STS */
+#define WM5100_DSP_IRQ3_STS                     0x0004  /* DSP_IRQ3_STS */
+#define WM5100_DSP_IRQ3_STS_MASK                0x0004  /* DSP_IRQ3_STS */
+#define WM5100_DSP_IRQ3_STS_SHIFT                    2  /* DSP_IRQ3_STS */
+#define WM5100_DSP_IRQ3_STS_WIDTH                    1  /* DSP_IRQ3_STS */
+#define WM5100_DSP_IRQ2_STS                     0x0002  /* DSP_IRQ2_STS */
+#define WM5100_DSP_IRQ2_STS_MASK                0x0002  /* DSP_IRQ2_STS */
+#define WM5100_DSP_IRQ2_STS_SHIFT                    1  /* DSP_IRQ2_STS */
+#define WM5100_DSP_IRQ2_STS_WIDTH                    1  /* DSP_IRQ2_STS */
+#define WM5100_DSP_IRQ1_STS                     0x0001  /* DSP_IRQ1_STS */
+#define WM5100_DSP_IRQ1_STS_MASK                0x0001  /* DSP_IRQ1_STS */
+#define WM5100_DSP_IRQ1_STS_SHIFT                    0  /* DSP_IRQ1_STS */
+#define WM5100_DSP_IRQ1_STS_WIDTH                    1  /* DSP_IRQ1_STS */
+
+/*
+ * R3333 (0xD05) - Interrupt Raw Status 3
+ */
+#define WM5100_SPK_SHUTDOWN_WARN_STS            0x8000  /* SPK_SHUTDOWN_WARN_STS */
+#define WM5100_SPK_SHUTDOWN_WARN_STS_MASK       0x8000  /* SPK_SHUTDOWN_WARN_STS */
+#define WM5100_SPK_SHUTDOWN_WARN_STS_SHIFT          15  /* SPK_SHUTDOWN_WARN_STS */
+#define WM5100_SPK_SHUTDOWN_WARN_STS_WIDTH           1  /* SPK_SHUTDOWN_WARN_STS */
+#define WM5100_SPK_SHUTDOWN_STS                 0x4000  /* SPK_SHUTDOWN_STS */
+#define WM5100_SPK_SHUTDOWN_STS_MASK            0x4000  /* SPK_SHUTDOWN_STS */
+#define WM5100_SPK_SHUTDOWN_STS_SHIFT               14  /* SPK_SHUTDOWN_STS */
+#define WM5100_SPK_SHUTDOWN_STS_WIDTH                1  /* SPK_SHUTDOWN_STS */
+#define WM5100_HPDET_STS                        0x2000  /* HPDET_STS */
+#define WM5100_HPDET_STS_MASK                   0x2000  /* HPDET_STS */
+#define WM5100_HPDET_STS_SHIFT                      13  /* HPDET_STS */
+#define WM5100_HPDET_STS_WIDTH                       1  /* HPDET_STS */
+#define WM5100_DRC_SID_DET_STS                  0x0200  /* DRC_SID_DET_STS */
+#define WM5100_DRC_SID_DET_STS_MASK             0x0200  /* DRC_SID_DET_STS */
+#define WM5100_DRC_SID_DET_STS_SHIFT                 9  /* DRC_SID_DET_STS */
+#define WM5100_DRC_SID_DET_STS_WIDTH                 1  /* DRC_SID_DET_STS */
+#define WM5100_ASRC2_LOCK_STS                   0x0100  /* ASRC2_LOCK_STS */
+#define WM5100_ASRC2_LOCK_STS_MASK              0x0100  /* ASRC2_LOCK_STS */
+#define WM5100_ASRC2_LOCK_STS_SHIFT                  8  /* ASRC2_LOCK_STS */
+#define WM5100_ASRC2_LOCK_STS_WIDTH                  1  /* ASRC2_LOCK_STS */
+#define WM5100_ASRC1_LOCK_STS                   0x0080  /* ASRC1_LOCK_STS */
+#define WM5100_ASRC1_LOCK_STS_MASK              0x0080  /* ASRC1_LOCK_STS */
+#define WM5100_ASRC1_LOCK_STS_SHIFT                  7  /* ASRC1_LOCK_STS */
+#define WM5100_ASRC1_LOCK_STS_WIDTH                  1  /* ASRC1_LOCK_STS */
+#define WM5100_FLL2_LOCK_STS                    0x0008  /* FLL2_LOCK_STS */
+#define WM5100_FLL2_LOCK_STS_MASK               0x0008  /* FLL2_LOCK_STS */
+#define WM5100_FLL2_LOCK_STS_SHIFT                   3  /* FLL2_LOCK_STS */
+#define WM5100_FLL2_LOCK_STS_WIDTH                   1  /* FLL2_LOCK_STS */
+#define WM5100_FLL1_LOCK_STS                    0x0004  /* FLL1_LOCK_STS */
+#define WM5100_FLL1_LOCK_STS_MASK               0x0004  /* FLL1_LOCK_STS */
+#define WM5100_FLL1_LOCK_STS_SHIFT                   2  /* FLL1_LOCK_STS */
+#define WM5100_FLL1_LOCK_STS_WIDTH                   1  /* FLL1_LOCK_STS */
+#define WM5100_CLKGEN_ERR_STS                   0x0002  /* CLKGEN_ERR_STS */
+#define WM5100_CLKGEN_ERR_STS_MASK              0x0002  /* CLKGEN_ERR_STS */
+#define WM5100_CLKGEN_ERR_STS_SHIFT                  1  /* CLKGEN_ERR_STS */
+#define WM5100_CLKGEN_ERR_STS_WIDTH                  1  /* CLKGEN_ERR_STS */
+#define WM5100_CLKGEN_ERR_ASYNC_STS             0x0001  /* CLKGEN_ERR_ASYNC_STS */
+#define WM5100_CLKGEN_ERR_ASYNC_STS_MASK        0x0001  /* CLKGEN_ERR_ASYNC_STS */
+#define WM5100_CLKGEN_ERR_ASYNC_STS_SHIFT            0  /* CLKGEN_ERR_ASYNC_STS */
+#define WM5100_CLKGEN_ERR_ASYNC_STS_WIDTH            1  /* CLKGEN_ERR_ASYNC_STS */
+
+/*
+ * R3334 (0xD06) - Interrupt Raw Status 4
+ */
+#define WM5100_AIF3_ERR_STS                     0x2000  /* AIF3_ERR_STS */
+#define WM5100_AIF3_ERR_STS_MASK                0x2000  /* AIF3_ERR_STS */
+#define WM5100_AIF3_ERR_STS_SHIFT                   13  /* AIF3_ERR_STS */
+#define WM5100_AIF3_ERR_STS_WIDTH                    1  /* AIF3_ERR_STS */
+#define WM5100_AIF2_ERR_STS                     0x1000  /* AIF2_ERR_STS */
+#define WM5100_AIF2_ERR_STS_MASK                0x1000  /* AIF2_ERR_STS */
+#define WM5100_AIF2_ERR_STS_SHIFT                   12  /* AIF2_ERR_STS */
+#define WM5100_AIF2_ERR_STS_WIDTH                    1  /* AIF2_ERR_STS */
+#define WM5100_AIF1_ERR_STS                     0x0800  /* AIF1_ERR_STS */
+#define WM5100_AIF1_ERR_STS_MASK                0x0800  /* AIF1_ERR_STS */
+#define WM5100_AIF1_ERR_STS_SHIFT                   11  /* AIF1_ERR_STS */
+#define WM5100_AIF1_ERR_STS_WIDTH                    1  /* AIF1_ERR_STS */
+#define WM5100_CTRLIF_ERR_STS                   0x0400  /* CTRLIF_ERR_STS */
+#define WM5100_CTRLIF_ERR_STS_MASK              0x0400  /* CTRLIF_ERR_STS */
+#define WM5100_CTRLIF_ERR_STS_SHIFT                 10  /* CTRLIF_ERR_STS */
+#define WM5100_CTRLIF_ERR_STS_WIDTH                  1  /* CTRLIF_ERR_STS */
+#define WM5100_ISRC2_UNDERCLOCKED_STS           0x0200  /* ISRC2_UNDERCLOCKED_STS */
+#define WM5100_ISRC2_UNDERCLOCKED_STS_MASK      0x0200  /* ISRC2_UNDERCLOCKED_STS */
+#define WM5100_ISRC2_UNDERCLOCKED_STS_SHIFT          9  /* ISRC2_UNDERCLOCKED_STS */
+#define WM5100_ISRC2_UNDERCLOCKED_STS_WIDTH          1  /* ISRC2_UNDERCLOCKED_STS */
+#define WM5100_ISRC1_UNDERCLOCKED_STS           0x0100  /* ISRC1_UNDERCLOCKED_STS */
+#define WM5100_ISRC1_UNDERCLOCKED_STS_MASK      0x0100  /* ISRC1_UNDERCLOCKED_STS */
+#define WM5100_ISRC1_UNDERCLOCKED_STS_SHIFT          8  /* ISRC1_UNDERCLOCKED_STS */
+#define WM5100_ISRC1_UNDERCLOCKED_STS_WIDTH          1  /* ISRC1_UNDERCLOCKED_STS */
+#define WM5100_FX_UNDERCLOCKED_STS              0x0080  /* FX_UNDERCLOCKED_STS */
+#define WM5100_FX_UNDERCLOCKED_STS_MASK         0x0080  /* FX_UNDERCLOCKED_STS */
+#define WM5100_FX_UNDERCLOCKED_STS_SHIFT             7  /* FX_UNDERCLOCKED_STS */
+#define WM5100_FX_UNDERCLOCKED_STS_WIDTH             1  /* FX_UNDERCLOCKED_STS */
+#define WM5100_AIF3_UNDERCLOCKED_STS            0x0040  /* AIF3_UNDERCLOCKED_STS */
+#define WM5100_AIF3_UNDERCLOCKED_STS_MASK       0x0040  /* AIF3_UNDERCLOCKED_STS */
+#define WM5100_AIF3_UNDERCLOCKED_STS_SHIFT           6  /* AIF3_UNDERCLOCKED_STS */
+#define WM5100_AIF3_UNDERCLOCKED_STS_WIDTH           1  /* AIF3_UNDERCLOCKED_STS */
+#define WM5100_AIF2_UNDERCLOCKED_STS            0x0020  /* AIF2_UNDERCLOCKED_STS */
+#define WM5100_AIF2_UNDERCLOCKED_STS_MASK       0x0020  /* AIF2_UNDERCLOCKED_STS */
+#define WM5100_AIF2_UNDERCLOCKED_STS_SHIFT           5  /* AIF2_UNDERCLOCKED_STS */
+#define WM5100_AIF2_UNDERCLOCKED_STS_WIDTH           1  /* AIF2_UNDERCLOCKED_STS */
+#define WM5100_AIF1_UNDERCLOCKED_STS            0x0010  /* AIF1_UNDERCLOCKED_STS */
+#define WM5100_AIF1_UNDERCLOCKED_STS_MASK       0x0010  /* AIF1_UNDERCLOCKED_STS */
+#define WM5100_AIF1_UNDERCLOCKED_STS_SHIFT           4  /* AIF1_UNDERCLOCKED_STS */
+#define WM5100_AIF1_UNDERCLOCKED_STS_WIDTH           1  /* AIF1_UNDERCLOCKED_STS */
+#define WM5100_ASRC_UNDERCLOCKED_STS            0x0008  /* ASRC_UNDERCLOCKED_STS */
+#define WM5100_ASRC_UNDERCLOCKED_STS_MASK       0x0008  /* ASRC_UNDERCLOCKED_STS */
+#define WM5100_ASRC_UNDERCLOCKED_STS_SHIFT           3  /* ASRC_UNDERCLOCKED_STS */
+#define WM5100_ASRC_UNDERCLOCKED_STS_WIDTH           1  /* ASRC_UNDERCLOCKED_STS */
+#define WM5100_DAC_UNDERCLOCKED_STS             0x0004  /* DAC_UNDERCLOCKED_STS */
+#define WM5100_DAC_UNDERCLOCKED_STS_MASK        0x0004  /* DAC_UNDERCLOCKED_STS */
+#define WM5100_DAC_UNDERCLOCKED_STS_SHIFT            2  /* DAC_UNDERCLOCKED_STS */
+#define WM5100_DAC_UNDERCLOCKED_STS_WIDTH            1  /* DAC_UNDERCLOCKED_STS */
+#define WM5100_ADC_UNDERCLOCKED_STS             0x0002  /* ADC_UNDERCLOCKED_STS */
+#define WM5100_ADC_UNDERCLOCKED_STS_MASK        0x0002  /* ADC_UNDERCLOCKED_STS */
+#define WM5100_ADC_UNDERCLOCKED_STS_SHIFT            1  /* ADC_UNDERCLOCKED_STS */
+#define WM5100_ADC_UNDERCLOCKED_STS_WIDTH            1  /* ADC_UNDERCLOCKED_STS */
+#define WM5100_MIXER_UNDERCLOCKED_STS           0x0001  /* MIXER_UNDERCLOCKED_STS */
+#define WM5100_MIXER_UNDERCLOCKED_STS_MASK      0x0001  /* MIXER_UNDERCLOCKED_STS */
+#define WM5100_MIXER_UNDERCLOCKED_STS_SHIFT          0  /* MIXER_UNDERCLOCKED_STS */
+#define WM5100_MIXER_UNDERCLOCKED_STS_WIDTH          1  /* MIXER_UNDERCLOCKED_STS */
+
+/*
+ * R3335 (0xD07) - Interrupt Status 1 Mask
+ */
+#define WM5100_IM_GP6_EINT                      0x0020  /* IM_GP6_EINT */
+#define WM5100_IM_GP6_EINT_MASK                 0x0020  /* IM_GP6_EINT */
+#define WM5100_IM_GP6_EINT_SHIFT                     5  /* IM_GP6_EINT */
+#define WM5100_IM_GP6_EINT_WIDTH                     1  /* IM_GP6_EINT */
+#define WM5100_IM_GP5_EINT                      0x0010  /* IM_GP5_EINT */
+#define WM5100_IM_GP5_EINT_MASK                 0x0010  /* IM_GP5_EINT */
+#define WM5100_IM_GP5_EINT_SHIFT                     4  /* IM_GP5_EINT */
+#define WM5100_IM_GP5_EINT_WIDTH                     1  /* IM_GP5_EINT */
+#define WM5100_IM_GP4_EINT                      0x0008  /* IM_GP4_EINT */
+#define WM5100_IM_GP4_EINT_MASK                 0x0008  /* IM_GP4_EINT */
+#define WM5100_IM_GP4_EINT_SHIFT                     3  /* IM_GP4_EINT */
+#define WM5100_IM_GP4_EINT_WIDTH                     1  /* IM_GP4_EINT */
+#define WM5100_IM_GP3_EINT                      0x0004  /* IM_GP3_EINT */
+#define WM5100_IM_GP3_EINT_MASK                 0x0004  /* IM_GP3_EINT */
+#define WM5100_IM_GP3_EINT_SHIFT                     2  /* IM_GP3_EINT */
+#define WM5100_IM_GP3_EINT_WIDTH                     1  /* IM_GP3_EINT */
+#define WM5100_IM_GP2_EINT                      0x0002  /* IM_GP2_EINT */
+#define WM5100_IM_GP2_EINT_MASK                 0x0002  /* IM_GP2_EINT */
+#define WM5100_IM_GP2_EINT_SHIFT                     1  /* IM_GP2_EINT */
+#define WM5100_IM_GP2_EINT_WIDTH                     1  /* IM_GP2_EINT */
+#define WM5100_IM_GP1_EINT                      0x0001  /* IM_GP1_EINT */
+#define WM5100_IM_GP1_EINT_MASK                 0x0001  /* IM_GP1_EINT */
+#define WM5100_IM_GP1_EINT_SHIFT                     0  /* IM_GP1_EINT */
+#define WM5100_IM_GP1_EINT_WIDTH                     1  /* IM_GP1_EINT */
+
+/*
+ * R3336 (0xD08) - Interrupt Status 2 Mask
+ */
+#define WM5100_IM_DSP_IRQ6_EINT                 0x0020  /* IM_DSP_IRQ6_EINT */
+#define WM5100_IM_DSP_IRQ6_EINT_MASK            0x0020  /* IM_DSP_IRQ6_EINT */
+#define WM5100_IM_DSP_IRQ6_EINT_SHIFT                5  /* IM_DSP_IRQ6_EINT */
+#define WM5100_IM_DSP_IRQ6_EINT_WIDTH                1  /* IM_DSP_IRQ6_EINT */
+#define WM5100_IM_DSP_IRQ5_EINT                 0x0010  /* IM_DSP_IRQ5_EINT */
+#define WM5100_IM_DSP_IRQ5_EINT_MASK            0x0010  /* IM_DSP_IRQ5_EINT */
+#define WM5100_IM_DSP_IRQ5_EINT_SHIFT                4  /* IM_DSP_IRQ5_EINT */
+#define WM5100_IM_DSP_IRQ5_EINT_WIDTH                1  /* IM_DSP_IRQ5_EINT */
+#define WM5100_IM_DSP_IRQ4_EINT                 0x0008  /* IM_DSP_IRQ4_EINT */
+#define WM5100_IM_DSP_IRQ4_EINT_MASK            0x0008  /* IM_DSP_IRQ4_EINT */
+#define WM5100_IM_DSP_IRQ4_EINT_SHIFT                3  /* IM_DSP_IRQ4_EINT */
+#define WM5100_IM_DSP_IRQ4_EINT_WIDTH                1  /* IM_DSP_IRQ4_EINT */
+#define WM5100_IM_DSP_IRQ3_EINT                 0x0004  /* IM_DSP_IRQ3_EINT */
+#define WM5100_IM_DSP_IRQ3_EINT_MASK            0x0004  /* IM_DSP_IRQ3_EINT */
+#define WM5100_IM_DSP_IRQ3_EINT_SHIFT                2  /* IM_DSP_IRQ3_EINT */
+#define WM5100_IM_DSP_IRQ3_EINT_WIDTH                1  /* IM_DSP_IRQ3_EINT */
+#define WM5100_IM_DSP_IRQ2_EINT                 0x0002  /* IM_DSP_IRQ2_EINT */
+#define WM5100_IM_DSP_IRQ2_EINT_MASK            0x0002  /* IM_DSP_IRQ2_EINT */
+#define WM5100_IM_DSP_IRQ2_EINT_SHIFT                1  /* IM_DSP_IRQ2_EINT */
+#define WM5100_IM_DSP_IRQ2_EINT_WIDTH                1  /* IM_DSP_IRQ2_EINT */
+#define WM5100_IM_DSP_IRQ1_EINT                 0x0001  /* IM_DSP_IRQ1_EINT */
+#define WM5100_IM_DSP_IRQ1_EINT_MASK            0x0001  /* IM_DSP_IRQ1_EINT */
+#define WM5100_IM_DSP_IRQ1_EINT_SHIFT                0  /* IM_DSP_IRQ1_EINT */
+#define WM5100_IM_DSP_IRQ1_EINT_WIDTH                1  /* IM_DSP_IRQ1_EINT */
+
+/*
+ * R3337 (0xD09) - Interrupt Status 3 Mask
+ */
+#define WM5100_IM_SPK_SHUTDOWN_WARN_EINT        0x8000  /* IM_SPK_SHUTDOWN_WARN_EINT */
+#define WM5100_IM_SPK_SHUTDOWN_WARN_EINT_MASK   0x8000  /* IM_SPK_SHUTDOWN_WARN_EINT */
+#define WM5100_IM_SPK_SHUTDOWN_WARN_EINT_SHIFT      15  /* IM_SPK_SHUTDOWN_WARN_EINT */
+#define WM5100_IM_SPK_SHUTDOWN_WARN_EINT_WIDTH       1  /* IM_SPK_SHUTDOWN_WARN_EINT */
+#define WM5100_IM_SPK_SHUTDOWN_EINT             0x4000  /* IM_SPK_SHUTDOWN_EINT */
+#define WM5100_IM_SPK_SHUTDOWN_EINT_MASK        0x4000  /* IM_SPK_SHUTDOWN_EINT */
+#define WM5100_IM_SPK_SHUTDOWN_EINT_SHIFT           14  /* IM_SPK_SHUTDOWN_EINT */
+#define WM5100_IM_SPK_SHUTDOWN_EINT_WIDTH            1  /* IM_SPK_SHUTDOWN_EINT */
+#define WM5100_IM_HPDET_EINT                    0x2000  /* IM_HPDET_EINT */
+#define WM5100_IM_HPDET_EINT_MASK               0x2000  /* IM_HPDET_EINT */
+#define WM5100_IM_HPDET_EINT_SHIFT                  13  /* IM_HPDET_EINT */
+#define WM5100_IM_HPDET_EINT_WIDTH                   1  /* IM_HPDET_EINT */
+#define WM5100_IM_ACCDET_EINT                   0x1000  /* IM_ACCDET_EINT */
+#define WM5100_IM_ACCDET_EINT_MASK              0x1000  /* IM_ACCDET_EINT */
+#define WM5100_IM_ACCDET_EINT_SHIFT                 12  /* IM_ACCDET_EINT */
+#define WM5100_IM_ACCDET_EINT_WIDTH                  1  /* IM_ACCDET_EINT */
+#define WM5100_IM_DRC_SIG_DET_EINT              0x0200  /* IM_DRC_SIG_DET_EINT */
+#define WM5100_IM_DRC_SIG_DET_EINT_MASK         0x0200  /* IM_DRC_SIG_DET_EINT */
+#define WM5100_IM_DRC_SIG_DET_EINT_SHIFT             9  /* IM_DRC_SIG_DET_EINT */
+#define WM5100_IM_DRC_SIG_DET_EINT_WIDTH             1  /* IM_DRC_SIG_DET_EINT */
+#define WM5100_IM_ASRC2_LOCK_EINT               0x0100  /* IM_ASRC2_LOCK_EINT */
+#define WM5100_IM_ASRC2_LOCK_EINT_MASK          0x0100  /* IM_ASRC2_LOCK_EINT */
+#define WM5100_IM_ASRC2_LOCK_EINT_SHIFT              8  /* IM_ASRC2_LOCK_EINT */
+#define WM5100_IM_ASRC2_LOCK_EINT_WIDTH              1  /* IM_ASRC2_LOCK_EINT */
+#define WM5100_IM_ASRC1_LOCK_EINT               0x0080  /* IM_ASRC1_LOCK_EINT */
+#define WM5100_IM_ASRC1_LOCK_EINT_MASK          0x0080  /* IM_ASRC1_LOCK_EINT */
+#define WM5100_IM_ASRC1_LOCK_EINT_SHIFT              7  /* IM_ASRC1_LOCK_EINT */
+#define WM5100_IM_ASRC1_LOCK_EINT_WIDTH              1  /* IM_ASRC1_LOCK_EINT */
+#define WM5100_IM_FLL2_LOCK_EINT                0x0008  /* IM_FLL2_LOCK_EINT */
+#define WM5100_IM_FLL2_LOCK_EINT_MASK           0x0008  /* IM_FLL2_LOCK_EINT */
+#define WM5100_IM_FLL2_LOCK_EINT_SHIFT               3  /* IM_FLL2_LOCK_EINT */
+#define WM5100_IM_FLL2_LOCK_EINT_WIDTH               1  /* IM_FLL2_LOCK_EINT */
+#define WM5100_IM_FLL1_LOCK_EINT                0x0004  /* IM_FLL1_LOCK_EINT */
+#define WM5100_IM_FLL1_LOCK_EINT_MASK           0x0004  /* IM_FLL1_LOCK_EINT */
+#define WM5100_IM_FLL1_LOCK_EINT_SHIFT               2  /* IM_FLL1_LOCK_EINT */
+#define WM5100_IM_FLL1_LOCK_EINT_WIDTH               1  /* IM_FLL1_LOCK_EINT */
+#define WM5100_IM_CLKGEN_ERR_EINT               0x0002  /* IM_CLKGEN_ERR_EINT */
+#define WM5100_IM_CLKGEN_ERR_EINT_MASK          0x0002  /* IM_CLKGEN_ERR_EINT */
+#define WM5100_IM_CLKGEN_ERR_EINT_SHIFT              1  /* IM_CLKGEN_ERR_EINT */
+#define WM5100_IM_CLKGEN_ERR_EINT_WIDTH              1  /* IM_CLKGEN_ERR_EINT */
+#define WM5100_IM_CLKGEN_ERR_ASYNC_EINT         0x0001  /* IM_CLKGEN_ERR_ASYNC_EINT */
+#define WM5100_IM_CLKGEN_ERR_ASYNC_EINT_MASK    0x0001  /* IM_CLKGEN_ERR_ASYNC_EINT */
+#define WM5100_IM_CLKGEN_ERR_ASYNC_EINT_SHIFT        0  /* IM_CLKGEN_ERR_ASYNC_EINT */
+#define WM5100_IM_CLKGEN_ERR_ASYNC_EINT_WIDTH        1  /* IM_CLKGEN_ERR_ASYNC_EINT */
+
+/*
+ * R3338 (0xD0A) - Interrupt Status 4 Mask
+ */
+#define WM5100_IM_AIF3_ERR_EINT                 0x2000  /* IM_AIF3_ERR_EINT */
+#define WM5100_IM_AIF3_ERR_EINT_MASK            0x2000  /* IM_AIF3_ERR_EINT */
+#define WM5100_IM_AIF3_ERR_EINT_SHIFT               13  /* IM_AIF3_ERR_EINT */
+#define WM5100_IM_AIF3_ERR_EINT_WIDTH                1  /* IM_AIF3_ERR_EINT */
+#define WM5100_IM_AIF2_ERR_EINT                 0x1000  /* IM_AIF2_ERR_EINT */
+#define WM5100_IM_AIF2_ERR_EINT_MASK            0x1000  /* IM_AIF2_ERR_EINT */
+#define WM5100_IM_AIF2_ERR_EINT_SHIFT               12  /* IM_AIF2_ERR_EINT */
+#define WM5100_IM_AIF2_ERR_EINT_WIDTH                1  /* IM_AIF2_ERR_EINT */
+#define WM5100_IM_AIF1_ERR_EINT                 0x0800  /* IM_AIF1_ERR_EINT */
+#define WM5100_IM_AIF1_ERR_EINT_MASK            0x0800  /* IM_AIF1_ERR_EINT */
+#define WM5100_IM_AIF1_ERR_EINT_SHIFT               11  /* IM_AIF1_ERR_EINT */
+#define WM5100_IM_AIF1_ERR_EINT_WIDTH                1  /* IM_AIF1_ERR_EINT */
+#define WM5100_IM_CTRLIF_ERR_EINT               0x0400  /* IM_CTRLIF_ERR_EINT */
+#define WM5100_IM_CTRLIF_ERR_EINT_MASK          0x0400  /* IM_CTRLIF_ERR_EINT */
+#define WM5100_IM_CTRLIF_ERR_EINT_SHIFT             10  /* IM_CTRLIF_ERR_EINT */
+#define WM5100_IM_CTRLIF_ERR_EINT_WIDTH              1  /* IM_CTRLIF_ERR_EINT */
+#define WM5100_IM_ISRC2_UNDERCLOCKED_EINT       0x0200  /* IM_ISRC2_UNDERCLOCKED_EINT */
+#define WM5100_IM_ISRC2_UNDERCLOCKED_EINT_MASK  0x0200  /* IM_ISRC2_UNDERCLOCKED_EINT */
+#define WM5100_IM_ISRC2_UNDERCLOCKED_EINT_SHIFT      9  /* IM_ISRC2_UNDERCLOCKED_EINT */
+#define WM5100_IM_ISRC2_UNDERCLOCKED_EINT_WIDTH      1  /* IM_ISRC2_UNDERCLOCKED_EINT */
+#define WM5100_IM_ISRC1_UNDERCLOCKED_EINT       0x0100  /* IM_ISRC1_UNDERCLOCKED_EINT */
+#define WM5100_IM_ISRC1_UNDERCLOCKED_EINT_MASK  0x0100  /* IM_ISRC1_UNDERCLOCKED_EINT */
+#define WM5100_IM_ISRC1_UNDERCLOCKED_EINT_SHIFT      8  /* IM_ISRC1_UNDERCLOCKED_EINT */
+#define WM5100_IM_ISRC1_UNDERCLOCKED_EINT_WIDTH      1  /* IM_ISRC1_UNDERCLOCKED_EINT */
+#define WM5100_IM_FX_UNDERCLOCKED_EINT          0x0080  /* IM_FX_UNDERCLOCKED_EINT */
+#define WM5100_IM_FX_UNDERCLOCKED_EINT_MASK     0x0080  /* IM_FX_UNDERCLOCKED_EINT */
+#define WM5100_IM_FX_UNDERCLOCKED_EINT_SHIFT         7  /* IM_FX_UNDERCLOCKED_EINT */
+#define WM5100_IM_FX_UNDERCLOCKED_EINT_WIDTH         1  /* IM_FX_UNDERCLOCKED_EINT */
+#define WM5100_IM_AIF3_UNDERCLOCKED_EINT        0x0040  /* IM_AIF3_UNDERCLOCKED_EINT */
+#define WM5100_IM_AIF3_UNDERCLOCKED_EINT_MASK   0x0040  /* IM_AIF3_UNDERCLOCKED_EINT */
+#define WM5100_IM_AIF3_UNDERCLOCKED_EINT_SHIFT       6  /* IM_AIF3_UNDERCLOCKED_EINT */
+#define WM5100_IM_AIF3_UNDERCLOCKED_EINT_WIDTH       1  /* IM_AIF3_UNDERCLOCKED_EINT */
+#define WM5100_IM_AIF2_UNDERCLOCKED_EINT        0x0020  /* IM_AIF2_UNDERCLOCKED_EINT */
+#define WM5100_IM_AIF2_UNDERCLOCKED_EINT_MASK   0x0020  /* IM_AIF2_UNDERCLOCKED_EINT */
+#define WM5100_IM_AIF2_UNDERCLOCKED_EINT_SHIFT       5  /* IM_AIF2_UNDERCLOCKED_EINT */
+#define WM5100_IM_AIF2_UNDERCLOCKED_EINT_WIDTH       1  /* IM_AIF2_UNDERCLOCKED_EINT */
+#define WM5100_IM_AIF1_UNDERCLOCKED_EINT        0x0010  /* IM_AIF1_UNDERCLOCKED_EINT */
+#define WM5100_IM_AIF1_UNDERCLOCKED_EINT_MASK   0x0010  /* IM_AIF1_UNDERCLOCKED_EINT */
+#define WM5100_IM_AIF1_UNDERCLOCKED_EINT_SHIFT       4  /* IM_AIF1_UNDERCLOCKED_EINT */
+#define WM5100_IM_AIF1_UNDERCLOCKED_EINT_WIDTH       1  /* IM_AIF1_UNDERCLOCKED_EINT */
+#define WM5100_IM_ASRC_UNDERCLOCKED_EINT        0x0008  /* IM_ASRC_UNDERCLOCKED_EINT */
+#define WM5100_IM_ASRC_UNDERCLOCKED_EINT_MASK   0x0008  /* IM_ASRC_UNDERCLOCKED_EINT */
+#define WM5100_IM_ASRC_UNDERCLOCKED_EINT_SHIFT       3  /* IM_ASRC_UNDERCLOCKED_EINT */
+#define WM5100_IM_ASRC_UNDERCLOCKED_EINT_WIDTH       1  /* IM_ASRC_UNDERCLOCKED_EINT */
+#define WM5100_IM_DAC_UNDERCLOCKED_EINT         0x0004  /* IM_DAC_UNDERCLOCKED_EINT */
+#define WM5100_IM_DAC_UNDERCLOCKED_EINT_MASK    0x0004  /* IM_DAC_UNDERCLOCKED_EINT */
+#define WM5100_IM_DAC_UNDERCLOCKED_EINT_SHIFT        2  /* IM_DAC_UNDERCLOCKED_EINT */
+#define WM5100_IM_DAC_UNDERCLOCKED_EINT_WIDTH        1  /* IM_DAC_UNDERCLOCKED_EINT */
+#define WM5100_IM_ADC_UNDERCLOCKED_EINT         0x0002  /* IM_ADC_UNDERCLOCKED_EINT */
+#define WM5100_IM_ADC_UNDERCLOCKED_EINT_MASK    0x0002  /* IM_ADC_UNDERCLOCKED_EINT */
+#define WM5100_IM_ADC_UNDERCLOCKED_EINT_SHIFT        1  /* IM_ADC_UNDERCLOCKED_EINT */
+#define WM5100_IM_ADC_UNDERCLOCKED_EINT_WIDTH        1  /* IM_ADC_UNDERCLOCKED_EINT */
+#define WM5100_IM_MIXER_UNDERCLOCKED_EINT       0x0001  /* IM_MIXER_UNDERCLOCKED_EINT */
+#define WM5100_IM_MIXER_UNDERCLOCKED_EINT_MASK  0x0001  /* IM_MIXER_UNDERCLOCKED_EINT */
+#define WM5100_IM_MIXER_UNDERCLOCKED_EINT_SHIFT      0  /* IM_MIXER_UNDERCLOCKED_EINT */
+#define WM5100_IM_MIXER_UNDERCLOCKED_EINT_WIDTH      1  /* IM_MIXER_UNDERCLOCKED_EINT */
+
+/*
+ * R3359 (0xD1F) - Interrupt Control
+ */
+#define WM5100_IM_IRQ                           0x0001  /* IM_IRQ */
+#define WM5100_IM_IRQ_MASK                      0x0001  /* IM_IRQ */
+#define WM5100_IM_IRQ_SHIFT                          0  /* IM_IRQ */
+#define WM5100_IM_IRQ_WIDTH                          1  /* IM_IRQ */
+
+/*
+ * R3360 (0xD20) - IRQ Debounce 1
+ */
+#define WM5100_SPK_SHUTDOWN_WARN_DB             0x0200  /* SPK_SHUTDOWN_WARN_DB */
+#define WM5100_SPK_SHUTDOWN_WARN_DB_MASK        0x0200  /* SPK_SHUTDOWN_WARN_DB */
+#define WM5100_SPK_SHUTDOWN_WARN_DB_SHIFT            9  /* SPK_SHUTDOWN_WARN_DB */
+#define WM5100_SPK_SHUTDOWN_WARN_DB_WIDTH            1  /* SPK_SHUTDOWN_WARN_DB */
+#define WM5100_SPK_SHUTDOWN_DB                  0x0100  /* SPK_SHUTDOWN_DB */
+#define WM5100_SPK_SHUTDOWN_DB_MASK             0x0100  /* SPK_SHUTDOWN_DB */
+#define WM5100_SPK_SHUTDOWN_DB_SHIFT                 8  /* SPK_SHUTDOWN_DB */
+#define WM5100_SPK_SHUTDOWN_DB_WIDTH                 1  /* SPK_SHUTDOWN_DB */
+#define WM5100_FLL1_LOCK_IRQ_DB                 0x0008  /* FLL1_LOCK_IRQ_DB */
+#define WM5100_FLL1_LOCK_IRQ_DB_MASK            0x0008  /* FLL1_LOCK_IRQ_DB */
+#define WM5100_FLL1_LOCK_IRQ_DB_SHIFT                3  /* FLL1_LOCK_IRQ_DB */
+#define WM5100_FLL1_LOCK_IRQ_DB_WIDTH                1  /* FLL1_LOCK_IRQ_DB */
+#define WM5100_FLL2_LOCK_IRQ_DB                 0x0004  /* FLL2_LOCK_IRQ_DB */
+#define WM5100_FLL2_LOCK_IRQ_DB_MASK            0x0004  /* FLL2_LOCK_IRQ_DB */
+#define WM5100_FLL2_LOCK_IRQ_DB_SHIFT                2  /* FLL2_LOCK_IRQ_DB */
+#define WM5100_FLL2_LOCK_IRQ_DB_WIDTH                1  /* FLL2_LOCK_IRQ_DB */
+#define WM5100_CLKGEN_ERR_IRQ_DB                0x0002  /* CLKGEN_ERR_IRQ_DB */
+#define WM5100_CLKGEN_ERR_IRQ_DB_MASK           0x0002  /* CLKGEN_ERR_IRQ_DB */
+#define WM5100_CLKGEN_ERR_IRQ_DB_SHIFT               1  /* CLKGEN_ERR_IRQ_DB */
+#define WM5100_CLKGEN_ERR_IRQ_DB_WIDTH               1  /* CLKGEN_ERR_IRQ_DB */
+#define WM5100_CLKGEN_ERR_ASYNC_IRQ_DB          0x0001  /* CLKGEN_ERR_ASYNC_IRQ_DB */
+#define WM5100_CLKGEN_ERR_ASYNC_IRQ_DB_MASK     0x0001  /* CLKGEN_ERR_ASYNC_IRQ_DB */
+#define WM5100_CLKGEN_ERR_ASYNC_IRQ_DB_SHIFT         0  /* CLKGEN_ERR_ASYNC_IRQ_DB */
+#define WM5100_CLKGEN_ERR_ASYNC_IRQ_DB_WIDTH         1  /* CLKGEN_ERR_ASYNC_IRQ_DB */
+
+/*
+ * R3361 (0xD21) - IRQ Debounce 2
+ */
+#define WM5100_AIF_ERR_DB                       0x0001  /* AIF_ERR_DB */
+#define WM5100_AIF_ERR_DB_MASK                  0x0001  /* AIF_ERR_DB */
+#define WM5100_AIF_ERR_DB_SHIFT                      0  /* AIF_ERR_DB */
+#define WM5100_AIF_ERR_DB_WIDTH                      1  /* AIF_ERR_DB */
+
+/*
+ * R3584 (0xE00) - FX_Ctrl
+ */
+#define WM5100_FX_STS_MASK                      0xFFC0  /* FX_STS - [15:6] */
+#define WM5100_FX_STS_SHIFT                          6  /* FX_STS - [15:6] */
+#define WM5100_FX_STS_WIDTH                         10  /* FX_STS - [15:6] */
+#define WM5100_FX_RATE_MASK                     0x0003  /* FX_RATE - [1:0] */
+#define WM5100_FX_RATE_SHIFT                         0  /* FX_RATE - [1:0] */
+#define WM5100_FX_RATE_WIDTH                         2  /* FX_RATE - [1:0] */
+
+/*
+ * R3600 (0xE10) - EQ1_1
+ */
+#define WM5100_EQ1_B1_GAIN_MASK                 0xF800  /* EQ1_B1_GAIN - [15:11] */
+#define WM5100_EQ1_B1_GAIN_SHIFT                    11  /* EQ1_B1_GAIN - [15:11] */
+#define WM5100_EQ1_B1_GAIN_WIDTH                     5  /* EQ1_B1_GAIN - [15:11] */
+#define WM5100_EQ1_B2_GAIN_MASK                 0x07C0  /* EQ1_B2_GAIN - [10:6] */
+#define WM5100_EQ1_B2_GAIN_SHIFT                     6  /* EQ1_B2_GAIN - [10:6] */
+#define WM5100_EQ1_B2_GAIN_WIDTH                     5  /* EQ1_B2_GAIN - [10:6] */
+#define WM5100_EQ1_B3_GAIN_MASK                 0x003E  /* EQ1_B3_GAIN - [5:1] */
+#define WM5100_EQ1_B3_GAIN_SHIFT                     1  /* EQ1_B3_GAIN - [5:1] */
+#define WM5100_EQ1_B3_GAIN_WIDTH                     5  /* EQ1_B3_GAIN - [5:1] */
+#define WM5100_EQ1_ENA                          0x0001  /* EQ1_ENA */
+#define WM5100_EQ1_ENA_MASK                     0x0001  /* EQ1_ENA */
+#define WM5100_EQ1_ENA_SHIFT                         0  /* EQ1_ENA */
+#define WM5100_EQ1_ENA_WIDTH                         1  /* EQ1_ENA */
+
+/*
+ * R3601 (0xE11) - EQ1_2
+ */
+#define WM5100_EQ1_B4_GAIN_MASK                 0xF800  /* EQ1_B4_GAIN - [15:11] */
+#define WM5100_EQ1_B4_GAIN_SHIFT                    11  /* EQ1_B4_GAIN - [15:11] */
+#define WM5100_EQ1_B4_GAIN_WIDTH                     5  /* EQ1_B4_GAIN - [15:11] */
+#define WM5100_EQ1_B5_GAIN_MASK                 0x07C0  /* EQ1_B5_GAIN - [10:6] */
+#define WM5100_EQ1_B5_GAIN_SHIFT                     6  /* EQ1_B5_GAIN - [10:6] */
+#define WM5100_EQ1_B5_GAIN_WIDTH                     5  /* EQ1_B5_GAIN - [10:6] */
+
+/*
+ * R3602 (0xE12) - EQ1_3
+ */
+#define WM5100_EQ1_B1_A_MASK                    0xFFFF  /* EQ1_B1_A - [15:0] */
+#define WM5100_EQ1_B1_A_SHIFT                        0  /* EQ1_B1_A - [15:0] */
+#define WM5100_EQ1_B1_A_WIDTH                       16  /* EQ1_B1_A - [15:0] */
+
+/*
+ * R3603 (0xE13) - EQ1_4
+ */
+#define WM5100_EQ1_B1_B_MASK                    0xFFFF  /* EQ1_B1_B - [15:0] */
+#define WM5100_EQ1_B1_B_SHIFT                        0  /* EQ1_B1_B - [15:0] */
+#define WM5100_EQ1_B1_B_WIDTH                       16  /* EQ1_B1_B - [15:0] */
+
+/*
+ * R3604 (0xE14) - EQ1_5
+ */
+#define WM5100_EQ1_B1_PG_MASK                   0xFFFF  /* EQ1_B1_PG - [15:0] */
+#define WM5100_EQ1_B1_PG_SHIFT                       0  /* EQ1_B1_PG - [15:0] */
+#define WM5100_EQ1_B1_PG_WIDTH                      16  /* EQ1_B1_PG - [15:0] */
+
+/*
+ * R3605 (0xE15) - EQ1_6
+ */
+#define WM5100_EQ1_B2_A_MASK                    0xFFFF  /* EQ1_B2_A - [15:0] */
+#define WM5100_EQ1_B2_A_SHIFT                        0  /* EQ1_B2_A - [15:0] */
+#define WM5100_EQ1_B2_A_WIDTH                       16  /* EQ1_B2_A - [15:0] */
+
+/*
+ * R3606 (0xE16) - EQ1_7
+ */
+#define WM5100_EQ1_B2_B_MASK                    0xFFFF  /* EQ1_B2_B - [15:0] */
+#define WM5100_EQ1_B2_B_SHIFT                        0  /* EQ1_B2_B - [15:0] */
+#define WM5100_EQ1_B2_B_WIDTH                       16  /* EQ1_B2_B - [15:0] */
+
+/*
+ * R3607 (0xE17) - EQ1_8
+ */
+#define WM5100_EQ1_B2_C_MASK                    0xFFFF  /* EQ1_B2_C - [15:0] */
+#define WM5100_EQ1_B2_C_SHIFT                        0  /* EQ1_B2_C - [15:0] */
+#define WM5100_EQ1_B2_C_WIDTH                       16  /* EQ1_B2_C - [15:0] */
+
+/*
+ * R3608 (0xE18) - EQ1_9
+ */
+#define WM5100_EQ1_B2_PG_MASK                   0xFFFF  /* EQ1_B2_PG - [15:0] */
+#define WM5100_EQ1_B2_PG_SHIFT                       0  /* EQ1_B2_PG - [15:0] */
+#define WM5100_EQ1_B2_PG_WIDTH                      16  /* EQ1_B2_PG - [15:0] */
+
+/*
+ * R3609 (0xE19) - EQ1_10
+ */
+#define WM5100_EQ1_B3_A_MASK                    0xFFFF  /* EQ1_B3_A - [15:0] */
+#define WM5100_EQ1_B3_A_SHIFT                        0  /* EQ1_B3_A - [15:0] */
+#define WM5100_EQ1_B3_A_WIDTH                       16  /* EQ1_B3_A - [15:0] */
+
+/*
+ * R3610 (0xE1A) - EQ1_11
+ */
+#define WM5100_EQ1_B3_B_MASK                    0xFFFF  /* EQ1_B3_B - [15:0] */
+#define WM5100_EQ1_B3_B_SHIFT                        0  /* EQ1_B3_B - [15:0] */
+#define WM5100_EQ1_B3_B_WIDTH                       16  /* EQ1_B3_B - [15:0] */
+
+/*
+ * R3611 (0xE1B) - EQ1_12
+ */
+#define WM5100_EQ1_B3_C_MASK                    0xFFFF  /* EQ1_B3_C - [15:0] */
+#define WM5100_EQ1_B3_C_SHIFT                        0  /* EQ1_B3_C - [15:0] */
+#define WM5100_EQ1_B3_C_WIDTH                       16  /* EQ1_B3_C - [15:0] */
+
+/*
+ * R3612 (0xE1C) - EQ1_13
+ */
+#define WM5100_EQ1_B3_PG_MASK                   0xFFFF  /* EQ1_B3_PG - [15:0] */
+#define WM5100_EQ1_B3_PG_SHIFT                       0  /* EQ1_B3_PG - [15:0] */
+#define WM5100_EQ1_B3_PG_WIDTH                      16  /* EQ1_B3_PG - [15:0] */
+
+/*
+ * R3613 (0xE1D) - EQ1_14
+ */
+#define WM5100_EQ1_B4_A_MASK                    0xFFFF  /* EQ1_B4_A - [15:0] */
+#define WM5100_EQ1_B4_A_SHIFT                        0  /* EQ1_B4_A - [15:0] */
+#define WM5100_EQ1_B4_A_WIDTH                       16  /* EQ1_B4_A - [15:0] */
+
+/*
+ * R3614 (0xE1E) - EQ1_15
+ */
+#define WM5100_EQ1_B4_B_MASK                    0xFFFF  /* EQ1_B4_B - [15:0] */
+#define WM5100_EQ1_B4_B_SHIFT                        0  /* EQ1_B4_B - [15:0] */
+#define WM5100_EQ1_B4_B_WIDTH                       16  /* EQ1_B4_B - [15:0] */
+
+/*
+ * R3615 (0xE1F) - EQ1_16
+ */
+#define WM5100_EQ1_B4_C_MASK                    0xFFFF  /* EQ1_B4_C - [15:0] */
+#define WM5100_EQ1_B4_C_SHIFT                        0  /* EQ1_B4_C - [15:0] */
+#define WM5100_EQ1_B4_C_WIDTH                       16  /* EQ1_B4_C - [15:0] */
+
+/*
+ * R3616 (0xE20) - EQ1_17
+ */
+#define WM5100_EQ1_B4_PG_MASK                   0xFFFF  /* EQ1_B4_PG - [15:0] */
+#define WM5100_EQ1_B4_PG_SHIFT                       0  /* EQ1_B4_PG - [15:0] */
+#define WM5100_EQ1_B4_PG_WIDTH                      16  /* EQ1_B4_PG - [15:0] */
+
+/*
+ * R3617 (0xE21) - EQ1_18
+ */
+#define WM5100_EQ1_B5_A_MASK                    0xFFFF  /* EQ1_B5_A - [15:0] */
+#define WM5100_EQ1_B5_A_SHIFT                        0  /* EQ1_B5_A - [15:0] */
+#define WM5100_EQ1_B5_A_WIDTH                       16  /* EQ1_B5_A - [15:0] */
+
+/*
+ * R3618 (0xE22) - EQ1_19
+ */
+#define WM5100_EQ1_B5_B_MASK                    0xFFFF  /* EQ1_B5_B - [15:0] */
+#define WM5100_EQ1_B5_B_SHIFT                        0  /* EQ1_B5_B - [15:0] */
+#define WM5100_EQ1_B5_B_WIDTH                       16  /* EQ1_B5_B - [15:0] */
+
+/*
+ * R3619 (0xE23) - EQ1_20
+ */
+#define WM5100_EQ1_B5_PG_MASK                   0xFFFF  /* EQ1_B5_PG - [15:0] */
+#define WM5100_EQ1_B5_PG_SHIFT                       0  /* EQ1_B5_PG - [15:0] */
+#define WM5100_EQ1_B5_PG_WIDTH                      16  /* EQ1_B5_PG - [15:0] */
+
+/*
+ * R3622 (0xE26) - EQ2_1
+ */
+#define WM5100_EQ2_B1_GAIN_MASK                 0xF800  /* EQ2_B1_GAIN - [15:11] */
+#define WM5100_EQ2_B1_GAIN_SHIFT                    11  /* EQ2_B1_GAIN - [15:11] */
+#define WM5100_EQ2_B1_GAIN_WIDTH                     5  /* EQ2_B1_GAIN - [15:11] */
+#define WM5100_EQ2_B2_GAIN_MASK                 0x07C0  /* EQ2_B2_GAIN - [10:6] */
+#define WM5100_EQ2_B2_GAIN_SHIFT                     6  /* EQ2_B2_GAIN - [10:6] */
+#define WM5100_EQ2_B2_GAIN_WIDTH                     5  /* EQ2_B2_GAIN - [10:6] */
+#define WM5100_EQ2_B3_GAIN_MASK                 0x003E  /* EQ2_B3_GAIN - [5:1] */
+#define WM5100_EQ2_B3_GAIN_SHIFT                     1  /* EQ2_B3_GAIN - [5:1] */
+#define WM5100_EQ2_B3_GAIN_WIDTH                     5  /* EQ2_B3_GAIN - [5:1] */
+#define WM5100_EQ2_ENA                          0x0001  /* EQ2_ENA */
+#define WM5100_EQ2_ENA_MASK                     0x0001  /* EQ2_ENA */
+#define WM5100_EQ2_ENA_SHIFT                         0  /* EQ2_ENA */
+#define WM5100_EQ2_ENA_WIDTH                         1  /* EQ2_ENA */
+
+/*
+ * R3623 (0xE27) - EQ2_2
+ */
+#define WM5100_EQ2_B4_GAIN_MASK                 0xF800  /* EQ2_B4_GAIN - [15:11] */
+#define WM5100_EQ2_B4_GAIN_SHIFT                    11  /* EQ2_B4_GAIN - [15:11] */
+#define WM5100_EQ2_B4_GAIN_WIDTH                     5  /* EQ2_B4_GAIN - [15:11] */
+#define WM5100_EQ2_B5_GAIN_MASK                 0x07C0  /* EQ2_B5_GAIN - [10:6] */
+#define WM5100_EQ2_B5_GAIN_SHIFT                     6  /* EQ2_B5_GAIN - [10:6] */
+#define WM5100_EQ2_B5_GAIN_WIDTH                     5  /* EQ2_B5_GAIN - [10:6] */
+
+/*
+ * R3624 (0xE28) - EQ2_3
+ */
+#define WM5100_EQ2_B1_A_MASK                    0xFFFF  /* EQ2_B1_A - [15:0] */
+#define WM5100_EQ2_B1_A_SHIFT                        0  /* EQ2_B1_A - [15:0] */
+#define WM5100_EQ2_B1_A_WIDTH                       16  /* EQ2_B1_A - [15:0] */
+
+/*
+ * R3625 (0xE29) - EQ2_4
+ */
+#define WM5100_EQ2_B1_B_MASK                    0xFFFF  /* EQ2_B1_B - [15:0] */
+#define WM5100_EQ2_B1_B_SHIFT                        0  /* EQ2_B1_B - [15:0] */
+#define WM5100_EQ2_B1_B_WIDTH                       16  /* EQ2_B1_B - [15:0] */
+
+/*
+ * R3626 (0xE2A) - EQ2_5
+ */
+#define WM5100_EQ2_B1_PG_MASK                   0xFFFF  /* EQ2_B1_PG - [15:0] */
+#define WM5100_EQ2_B1_PG_SHIFT                       0  /* EQ2_B1_PG - [15:0] */
+#define WM5100_EQ2_B1_PG_WIDTH                      16  /* EQ2_B1_PG - [15:0] */
+
+/*
+ * R3627 (0xE2B) - EQ2_6
+ */
+#define WM5100_EQ2_B2_A_MASK                    0xFFFF  /* EQ2_B2_A - [15:0] */
+#define WM5100_EQ2_B2_A_SHIFT                        0  /* EQ2_B2_A - [15:0] */
+#define WM5100_EQ2_B2_A_WIDTH                       16  /* EQ2_B2_A - [15:0] */
+
+/*
+ * R3628 (0xE2C) - EQ2_7
+ */
+#define WM5100_EQ2_B2_B_MASK                    0xFFFF  /* EQ2_B2_B - [15:0] */
+#define WM5100_EQ2_B2_B_SHIFT                        0  /* EQ2_B2_B - [15:0] */
+#define WM5100_EQ2_B2_B_WIDTH                       16  /* EQ2_B2_B - [15:0] */
+
+/*
+ * R3629 (0xE2D) - EQ2_8
+ */
+#define WM5100_EQ2_B2_C_MASK                    0xFFFF  /* EQ2_B2_C - [15:0] */
+#define WM5100_EQ2_B2_C_SHIFT                        0  /* EQ2_B2_C - [15:0] */
+#define WM5100_EQ2_B2_C_WIDTH                       16  /* EQ2_B2_C - [15:0] */
+
+/*
+ * R3630 (0xE2E) - EQ2_9
+ */
+#define WM5100_EQ2_B2_PG_MASK                   0xFFFF  /* EQ2_B2_PG - [15:0] */
+#define WM5100_EQ2_B2_PG_SHIFT                       0  /* EQ2_B2_PG - [15:0] */
+#define WM5100_EQ2_B2_PG_WIDTH                      16  /* EQ2_B2_PG - [15:0] */
+
+/*
+ * R3631 (0xE2F) - EQ2_10
+ */
+#define WM5100_EQ2_B3_A_MASK                    0xFFFF  /* EQ2_B3_A - [15:0] */
+#define WM5100_EQ2_B3_A_SHIFT                        0  /* EQ2_B3_A - [15:0] */
+#define WM5100_EQ2_B3_A_WIDTH                       16  /* EQ2_B3_A - [15:0] */
+
+/*
+ * R3632 (0xE30) - EQ2_11
+ */
+#define WM5100_EQ2_B3_B_MASK                    0xFFFF  /* EQ2_B3_B - [15:0] */
+#define WM5100_EQ2_B3_B_SHIFT                        0  /* EQ2_B3_B - [15:0] */
+#define WM5100_EQ2_B3_B_WIDTH                       16  /* EQ2_B3_B - [15:0] */
+
+/*
+ * R3633 (0xE31) - EQ2_12
+ */
+#define WM5100_EQ2_B3_C_MASK                    0xFFFF  /* EQ2_B3_C - [15:0] */
+#define WM5100_EQ2_B3_C_SHIFT                        0  /* EQ2_B3_C - [15:0] */
+#define WM5100_EQ2_B3_C_WIDTH                       16  /* EQ2_B3_C - [15:0] */
+
+/*
+ * R3634 (0xE32) - EQ2_13
+ */
+#define WM5100_EQ2_B3_PG_MASK                   0xFFFF  /* EQ2_B3_PG - [15:0] */
+#define WM5100_EQ2_B3_PG_SHIFT                       0  /* EQ2_B3_PG - [15:0] */
+#define WM5100_EQ2_B3_PG_WIDTH                      16  /* EQ2_B3_PG - [15:0] */
+
+/*
+ * R3635 (0xE33) - EQ2_14
+ */
+#define WM5100_EQ2_B4_A_MASK                    0xFFFF  /* EQ2_B4_A - [15:0] */
+#define WM5100_EQ2_B4_A_SHIFT                        0  /* EQ2_B4_A - [15:0] */
+#define WM5100_EQ2_B4_A_WIDTH                       16  /* EQ2_B4_A - [15:0] */
+
+/*
+ * R3636 (0xE34) - EQ2_15
+ */
+#define WM5100_EQ2_B4_B_MASK                    0xFFFF  /* EQ2_B4_B - [15:0] */
+#define WM5100_EQ2_B4_B_SHIFT                        0  /* EQ2_B4_B - [15:0] */
+#define WM5100_EQ2_B4_B_WIDTH                       16  /* EQ2_B4_B - [15:0] */
+
+/*
+ * R3637 (0xE35) - EQ2_16
+ */
+#define WM5100_EQ2_B4_C_MASK                    0xFFFF  /* EQ2_B4_C - [15:0] */
+#define WM5100_EQ2_B4_C_SHIFT                        0  /* EQ2_B4_C - [15:0] */
+#define WM5100_EQ2_B4_C_WIDTH                       16  /* EQ2_B4_C - [15:0] */
+
+/*
+ * R3638 (0xE36) - EQ2_17
+ */
+#define WM5100_EQ2_B4_PG_MASK                   0xFFFF  /* EQ2_B4_PG - [15:0] */
+#define WM5100_EQ2_B4_PG_SHIFT                       0  /* EQ2_B4_PG - [15:0] */
+#define WM5100_EQ2_B4_PG_WIDTH                      16  /* EQ2_B4_PG - [15:0] */
+
+/*
+ * R3639 (0xE37) - EQ2_18
+ */
+#define WM5100_EQ2_B5_A_MASK                    0xFFFF  /* EQ2_B5_A - [15:0] */
+#define WM5100_EQ2_B5_A_SHIFT                        0  /* EQ2_B5_A - [15:0] */
+#define WM5100_EQ2_B5_A_WIDTH                       16  /* EQ2_B5_A - [15:0] */
+
+/*
+ * R3640 (0xE38) - EQ2_19
+ */
+#define WM5100_EQ2_B5_B_MASK                    0xFFFF  /* EQ2_B5_B - [15:0] */
+#define WM5100_EQ2_B5_B_SHIFT                        0  /* EQ2_B5_B - [15:0] */
+#define WM5100_EQ2_B5_B_WIDTH                       16  /* EQ2_B5_B - [15:0] */
+
+/*
+ * R3641 (0xE39) - EQ2_20
+ */
+#define WM5100_EQ2_B5_PG_MASK                   0xFFFF  /* EQ2_B5_PG - [15:0] */
+#define WM5100_EQ2_B5_PG_SHIFT                       0  /* EQ2_B5_PG - [15:0] */
+#define WM5100_EQ2_B5_PG_WIDTH                      16  /* EQ2_B5_PG - [15:0] */
+
+/*
+ * R3644 (0xE3C) - EQ3_1
+ */
+#define WM5100_EQ3_B1_GAIN_MASK                 0xF800  /* EQ3_B1_GAIN - [15:11] */
+#define WM5100_EQ3_B1_GAIN_SHIFT                    11  /* EQ3_B1_GAIN - [15:11] */
+#define WM5100_EQ3_B1_GAIN_WIDTH                     5  /* EQ3_B1_GAIN - [15:11] */
+#define WM5100_EQ3_B2_GAIN_MASK                 0x07C0  /* EQ3_B2_GAIN - [10:6] */
+#define WM5100_EQ3_B2_GAIN_SHIFT                     6  /* EQ3_B2_GAIN - [10:6] */
+#define WM5100_EQ3_B2_GAIN_WIDTH                     5  /* EQ3_B2_GAIN - [10:6] */
+#define WM5100_EQ3_B3_GAIN_MASK                 0x003E  /* EQ3_B3_GAIN - [5:1] */
+#define WM5100_EQ3_B3_GAIN_SHIFT                     1  /* EQ3_B3_GAIN - [5:1] */
+#define WM5100_EQ3_B3_GAIN_WIDTH                     5  /* EQ3_B3_GAIN - [5:1] */
+#define WM5100_EQ3_ENA                          0x0001  /* EQ3_ENA */
+#define WM5100_EQ3_ENA_MASK                     0x0001  /* EQ3_ENA */
+#define WM5100_EQ3_ENA_SHIFT                         0  /* EQ3_ENA */
+#define WM5100_EQ3_ENA_WIDTH                         1  /* EQ3_ENA */
+
+/*
+ * R3645 (0xE3D) - EQ3_2
+ */
+#define WM5100_EQ3_B4_GAIN_MASK                 0xF800  /* EQ3_B4_GAIN - [15:11] */
+#define WM5100_EQ3_B4_GAIN_SHIFT                    11  /* EQ3_B4_GAIN - [15:11] */
+#define WM5100_EQ3_B4_GAIN_WIDTH                     5  /* EQ3_B4_GAIN - [15:11] */
+#define WM5100_EQ3_B5_GAIN_MASK                 0x07C0  /* EQ3_B5_GAIN - [10:6] */
+#define WM5100_EQ3_B5_GAIN_SHIFT                     6  /* EQ3_B5_GAIN - [10:6] */
+#define WM5100_EQ3_B5_GAIN_WIDTH                     5  /* EQ3_B5_GAIN - [10:6] */
+
+/*
+ * R3646 (0xE3E) - EQ3_3
+ */
+#define WM5100_EQ3_B1_A_MASK                    0xFFFF  /* EQ3_B1_A - [15:0] */
+#define WM5100_EQ3_B1_A_SHIFT                        0  /* EQ3_B1_A - [15:0] */
+#define WM5100_EQ3_B1_A_WIDTH                       16  /* EQ3_B1_A - [15:0] */
+
+/*
+ * R3647 (0xE3F) - EQ3_4
+ */
+#define WM5100_EQ3_B1_B_MASK                    0xFFFF  /* EQ3_B1_B - [15:0] */
+#define WM5100_EQ3_B1_B_SHIFT                        0  /* EQ3_B1_B - [15:0] */
+#define WM5100_EQ3_B1_B_WIDTH                       16  /* EQ3_B1_B - [15:0] */
+
+/*
+ * R3648 (0xE40) - EQ3_5
+ */
+#define WM5100_EQ3_B1_PG_MASK                   0xFFFF  /* EQ3_B1_PG - [15:0] */
+#define WM5100_EQ3_B1_PG_SHIFT                       0  /* EQ3_B1_PG - [15:0] */
+#define WM5100_EQ3_B1_PG_WIDTH                      16  /* EQ3_B1_PG - [15:0] */
+
+/*
+ * R3649 (0xE41) - EQ3_6
+ */
+#define WM5100_EQ3_B2_A_MASK                    0xFFFF  /* EQ3_B2_A - [15:0] */
+#define WM5100_EQ3_B2_A_SHIFT                        0  /* EQ3_B2_A - [15:0] */
+#define WM5100_EQ3_B2_A_WIDTH                       16  /* EQ3_B2_A - [15:0] */
+
+/*
+ * R3650 (0xE42) - EQ3_7
+ */
+#define WM5100_EQ3_B2_B_MASK                    0xFFFF  /* EQ3_B2_B - [15:0] */
+#define WM5100_EQ3_B2_B_SHIFT                        0  /* EQ3_B2_B - [15:0] */
+#define WM5100_EQ3_B2_B_WIDTH                       16  /* EQ3_B2_B - [15:0] */
+
+/*
+ * R3651 (0xE43) - EQ3_8
+ */
+#define WM5100_EQ3_B2_C_MASK                    0xFFFF  /* EQ3_B2_C - [15:0] */
+#define WM5100_EQ3_B2_C_SHIFT                        0  /* EQ3_B2_C - [15:0] */
+#define WM5100_EQ3_B2_C_WIDTH                       16  /* EQ3_B2_C - [15:0] */
+
+/*
+ * R3652 (0xE44) - EQ3_9
+ */
+#define WM5100_EQ3_B2_PG_MASK                   0xFFFF  /* EQ3_B2_PG - [15:0] */
+#define WM5100_EQ3_B2_PG_SHIFT                       0  /* EQ3_B2_PG - [15:0] */
+#define WM5100_EQ3_B2_PG_WIDTH                      16  /* EQ3_B2_PG - [15:0] */
+
+/*
+ * R3653 (0xE45) - EQ3_10
+ */
+#define WM5100_EQ3_B3_A_MASK                    0xFFFF  /* EQ3_B3_A - [15:0] */
+#define WM5100_EQ3_B3_A_SHIFT                        0  /* EQ3_B3_A - [15:0] */
+#define WM5100_EQ3_B3_A_WIDTH                       16  /* EQ3_B3_A - [15:0] */
+
+/*
+ * R3654 (0xE46) - EQ3_11
+ */
+#define WM5100_EQ3_B3_B_MASK                    0xFFFF  /* EQ3_B3_B - [15:0] */
+#define WM5100_EQ3_B3_B_SHIFT                        0  /* EQ3_B3_B - [15:0] */
+#define WM5100_EQ3_B3_B_WIDTH                       16  /* EQ3_B3_B - [15:0] */
+
+/*
+ * R3655 (0xE47) - EQ3_12
+ */
+#define WM5100_EQ3_B3_C_MASK                    0xFFFF  /* EQ3_B3_C - [15:0] */
+#define WM5100_EQ3_B3_C_SHIFT                        0  /* EQ3_B3_C - [15:0] */
+#define WM5100_EQ3_B3_C_WIDTH                       16  /* EQ3_B3_C - [15:0] */
+
+/*
+ * R3656 (0xE48) - EQ3_13
+ */
+#define WM5100_EQ3_B3_PG_MASK                   0xFFFF  /* EQ3_B3_PG - [15:0] */
+#define WM5100_EQ3_B3_PG_SHIFT                       0  /* EQ3_B3_PG - [15:0] */
+#define WM5100_EQ3_B3_PG_WIDTH                      16  /* EQ3_B3_PG - [15:0] */
+
+/*
+ * R3657 (0xE49) - EQ3_14
+ */
+#define WM5100_EQ3_B4_A_MASK                    0xFFFF  /* EQ3_B4_A - [15:0] */
+#define WM5100_EQ3_B4_A_SHIFT                        0  /* EQ3_B4_A - [15:0] */
+#define WM5100_EQ3_B4_A_WIDTH                       16  /* EQ3_B4_A - [15:0] */
+
+/*
+ * R3658 (0xE4A) - EQ3_15
+ */
+#define WM5100_EQ3_B4_B_MASK                    0xFFFF  /* EQ3_B4_B - [15:0] */
+#define WM5100_EQ3_B4_B_SHIFT                        0  /* EQ3_B4_B - [15:0] */
+#define WM5100_EQ3_B4_B_WIDTH                       16  /* EQ3_B4_B - [15:0] */
+
+/*
+ * R3659 (0xE4B) - EQ3_16
+ */
+#define WM5100_EQ3_B4_C_MASK                    0xFFFF  /* EQ3_B4_C - [15:0] */
+#define WM5100_EQ3_B4_C_SHIFT                        0  /* EQ3_B4_C - [15:0] */
+#define WM5100_EQ3_B4_C_WIDTH                       16  /* EQ3_B4_C - [15:0] */
+
+/*
+ * R3660 (0xE4C) - EQ3_17
+ */
+#define WM5100_EQ3_B4_PG_MASK                   0xFFFF  /* EQ3_B4_PG - [15:0] */
+#define WM5100_EQ3_B4_PG_SHIFT                       0  /* EQ3_B4_PG - [15:0] */
+#define WM5100_EQ3_B4_PG_WIDTH                      16  /* EQ3_B4_PG - [15:0] */
+
+/*
+ * R3661 (0xE4D) - EQ3_18
+ */
+#define WM5100_EQ3_B5_A_MASK                    0xFFFF  /* EQ3_B5_A - [15:0] */
+#define WM5100_EQ3_B5_A_SHIFT                        0  /* EQ3_B5_A - [15:0] */
+#define WM5100_EQ3_B5_A_WIDTH                       16  /* EQ3_B5_A - [15:0] */
+
+/*
+ * R3662 (0xE4E) - EQ3_19
+ */
+#define WM5100_EQ3_B5_B_MASK                    0xFFFF  /* EQ3_B5_B - [15:0] */
+#define WM5100_EQ3_B5_B_SHIFT                        0  /* EQ3_B5_B - [15:0] */
+#define WM5100_EQ3_B5_B_WIDTH                       16  /* EQ3_B5_B - [15:0] */
+
+/*
+ * R3663 (0xE4F) - EQ3_20
+ */
+#define WM5100_EQ3_B5_PG_MASK                   0xFFFF  /* EQ3_B5_PG - [15:0] */
+#define WM5100_EQ3_B5_PG_SHIFT                       0  /* EQ3_B5_PG - [15:0] */
+#define WM5100_EQ3_B5_PG_WIDTH                      16  /* EQ3_B5_PG - [15:0] */
+
+/*
+ * R3666 (0xE52) - EQ4_1
+ */
+#define WM5100_EQ4_B1_GAIN_MASK                 0xF800  /* EQ4_B1_GAIN - [15:11] */
+#define WM5100_EQ4_B1_GAIN_SHIFT                    11  /* EQ4_B1_GAIN - [15:11] */
+#define WM5100_EQ4_B1_GAIN_WIDTH                     5  /* EQ4_B1_GAIN - [15:11] */
+#define WM5100_EQ4_B2_GAIN_MASK                 0x07C0  /* EQ4_B2_GAIN - [10:6] */
+#define WM5100_EQ4_B2_GAIN_SHIFT                     6  /* EQ4_B2_GAIN - [10:6] */
+#define WM5100_EQ4_B2_GAIN_WIDTH                     5  /* EQ4_B2_GAIN - [10:6] */
+#define WM5100_EQ4_B3_GAIN_MASK                 0x003E  /* EQ4_B3_GAIN - [5:1] */
+#define WM5100_EQ4_B3_GAIN_SHIFT                     1  /* EQ4_B3_GAIN - [5:1] */
+#define WM5100_EQ4_B3_GAIN_WIDTH                     5  /* EQ4_B3_GAIN - [5:1] */
+#define WM5100_EQ4_ENA                          0x0001  /* EQ4_ENA */
+#define WM5100_EQ4_ENA_MASK                     0x0001  /* EQ4_ENA */
+#define WM5100_EQ4_ENA_SHIFT                         0  /* EQ4_ENA */
+#define WM5100_EQ4_ENA_WIDTH                         1  /* EQ4_ENA */
+
+/*
+ * R3667 (0xE53) - EQ4_2
+ */
+#define WM5100_EQ4_B4_GAIN_MASK                 0xF800  /* EQ4_B4_GAIN - [15:11] */
+#define WM5100_EQ4_B4_GAIN_SHIFT                    11  /* EQ4_B4_GAIN - [15:11] */
+#define WM5100_EQ4_B4_GAIN_WIDTH                     5  /* EQ4_B4_GAIN - [15:11] */
+#define WM5100_EQ4_B5_GAIN_MASK                 0x07C0  /* EQ4_B5_GAIN - [10:6] */
+#define WM5100_EQ4_B5_GAIN_SHIFT                     6  /* EQ4_B5_GAIN - [10:6] */
+#define WM5100_EQ4_B5_GAIN_WIDTH                     5  /* EQ4_B5_GAIN - [10:6] */
+
+/*
+ * R3668 (0xE54) - EQ4_3
+ */
+#define WM5100_EQ4_B1_A_MASK                    0xFFFF  /* EQ4_B1_A - [15:0] */
+#define WM5100_EQ4_B1_A_SHIFT                        0  /* EQ4_B1_A - [15:0] */
+#define WM5100_EQ4_B1_A_WIDTH                       16  /* EQ4_B1_A - [15:0] */
+
+/*
+ * R3669 (0xE55) - EQ4_4
+ */
+#define WM5100_EQ4_B1_B_MASK                    0xFFFF  /* EQ4_B1_B - [15:0] */
+#define WM5100_EQ4_B1_B_SHIFT                        0  /* EQ4_B1_B - [15:0] */
+#define WM5100_EQ4_B1_B_WIDTH                       16  /* EQ4_B1_B - [15:0] */
+
+/*
+ * R3670 (0xE56) - EQ4_5
+ */
+#define WM5100_EQ4_B1_PG_MASK                   0xFFFF  /* EQ4_B1_PG - [15:0] */
+#define WM5100_EQ4_B1_PG_SHIFT                       0  /* EQ4_B1_PG - [15:0] */
+#define WM5100_EQ4_B1_PG_WIDTH                      16  /* EQ4_B1_PG - [15:0] */
+
+/*
+ * R3671 (0xE57) - EQ4_6
+ */
+#define WM5100_EQ4_B2_A_MASK                    0xFFFF  /* EQ4_B2_A - [15:0] */
+#define WM5100_EQ4_B2_A_SHIFT                        0  /* EQ4_B2_A - [15:0] */
+#define WM5100_EQ4_B2_A_WIDTH                       16  /* EQ4_B2_A - [15:0] */
+
+/*
+ * R3672 (0xE58) - EQ4_7
+ */
+#define WM5100_EQ4_B2_B_MASK                    0xFFFF  /* EQ4_B2_B - [15:0] */
+#define WM5100_EQ4_B2_B_SHIFT                        0  /* EQ4_B2_B - [15:0] */
+#define WM5100_EQ4_B2_B_WIDTH                       16  /* EQ4_B2_B - [15:0] */
+
+/*
+ * R3673 (0xE59) - EQ4_8
+ */
+#define WM5100_EQ4_B2_C_MASK                    0xFFFF  /* EQ4_B2_C - [15:0] */
+#define WM5100_EQ4_B2_C_SHIFT                        0  /* EQ4_B2_C - [15:0] */
+#define WM5100_EQ4_B2_C_WIDTH                       16  /* EQ4_B2_C - [15:0] */
+
+/*
+ * R3674 (0xE5A) - EQ4_9
+ */
+#define WM5100_EQ4_B2_PG_MASK                   0xFFFF  /* EQ4_B2_PG - [15:0] */
+#define WM5100_EQ4_B2_PG_SHIFT                       0  /* EQ4_B2_PG - [15:0] */
+#define WM5100_EQ4_B2_PG_WIDTH                      16  /* EQ4_B2_PG - [15:0] */
+
+/*
+ * R3675 (0xE5B) - EQ4_10
+ */
+#define WM5100_EQ4_B3_A_MASK                    0xFFFF  /* EQ4_B3_A - [15:0] */
+#define WM5100_EQ4_B3_A_SHIFT                        0  /* EQ4_B3_A - [15:0] */
+#define WM5100_EQ4_B3_A_WIDTH                       16  /* EQ4_B3_A - [15:0] */
+
+/*
+ * R3676 (0xE5C) - EQ4_11
+ */
+#define WM5100_EQ4_B3_B_MASK                    0xFFFF  /* EQ4_B3_B - [15:0] */
+#define WM5100_EQ4_B3_B_SHIFT                        0  /* EQ4_B3_B - [15:0] */
+#define WM5100_EQ4_B3_B_WIDTH                       16  /* EQ4_B3_B - [15:0] */
+
+/*
+ * R3677 (0xE5D) - EQ4_12
+ */
+#define WM5100_EQ4_B3_C_MASK                    0xFFFF  /* EQ4_B3_C - [15:0] */
+#define WM5100_EQ4_B3_C_SHIFT                        0  /* EQ4_B3_C - [15:0] */
+#define WM5100_EQ4_B3_C_WIDTH                       16  /* EQ4_B3_C - [15:0] */
+
+/*
+ * R3678 (0xE5E) - EQ4_13
+ */
+#define WM5100_EQ4_B3_PG_MASK                   0xFFFF  /* EQ4_B3_PG - [15:0] */
+#define WM5100_EQ4_B3_PG_SHIFT                       0  /* EQ4_B3_PG - [15:0] */
+#define WM5100_EQ4_B3_PG_WIDTH                      16  /* EQ4_B3_PG - [15:0] */
+
+/*
+ * R3679 (0xE5F) - EQ4_14
+ */
+#define WM5100_EQ4_B4_A_MASK                    0xFFFF  /* EQ4_B4_A - [15:0] */
+#define WM5100_EQ4_B4_A_SHIFT                        0  /* EQ4_B4_A - [15:0] */
+#define WM5100_EQ4_B4_A_WIDTH                       16  /* EQ4_B4_A - [15:0] */
+
+/*
+ * R3680 (0xE60) - EQ4_15
+ */
+#define WM5100_EQ4_B4_B_MASK                    0xFFFF  /* EQ4_B4_B - [15:0] */
+#define WM5100_EQ4_B4_B_SHIFT                        0  /* EQ4_B4_B - [15:0] */
+#define WM5100_EQ4_B4_B_WIDTH                       16  /* EQ4_B4_B - [15:0] */
+
+/*
+ * R3681 (0xE61) - EQ4_16
+ */
+#define WM5100_EQ4_B4_C_MASK                    0xFFFF  /* EQ4_B4_C - [15:0] */
+#define WM5100_EQ4_B4_C_SHIFT                        0  /* EQ4_B4_C - [15:0] */
+#define WM5100_EQ4_B4_C_WIDTH                       16  /* EQ4_B4_C - [15:0] */
+
+/*
+ * R3682 (0xE62) - EQ4_17
+ */
+#define WM5100_EQ4_B4_PG_MASK                   0xFFFF  /* EQ4_B4_PG - [15:0] */
+#define WM5100_EQ4_B4_PG_SHIFT                       0  /* EQ4_B4_PG - [15:0] */
+#define WM5100_EQ4_B4_PG_WIDTH                      16  /* EQ4_B4_PG - [15:0] */
+
+/*
+ * R3683 (0xE63) - EQ4_18
+ */
+#define WM5100_EQ4_B5_A_MASK                    0xFFFF  /* EQ4_B5_A - [15:0] */
+#define WM5100_EQ4_B5_A_SHIFT                        0  /* EQ4_B5_A - [15:0] */
+#define WM5100_EQ4_B5_A_WIDTH                       16  /* EQ4_B5_A - [15:0] */
+
+/*
+ * R3684 (0xE64) - EQ4_19
+ */
+#define WM5100_EQ4_B5_B_MASK                    0xFFFF  /* EQ4_B5_B - [15:0] */
+#define WM5100_EQ4_B5_B_SHIFT                        0  /* EQ4_B5_B - [15:0] */
+#define WM5100_EQ4_B5_B_WIDTH                       16  /* EQ4_B5_B - [15:0] */
+
+/*
+ * R3685 (0xE65) - EQ4_20
+ */
+#define WM5100_EQ4_B5_PG_MASK                   0xFFFF  /* EQ4_B5_PG - [15:0] */
+#define WM5100_EQ4_B5_PG_SHIFT                       0  /* EQ4_B5_PG - [15:0] */
+#define WM5100_EQ4_B5_PG_WIDTH                      16  /* EQ4_B5_PG - [15:0] */
+
+/*
+ * R3712 (0xE80) - DRC1 ctrl1
+ */
+#define WM5100_DRC_SIG_DET_RMS_MASK             0xF800  /* DRC_SIG_DET_RMS - [15:11] */
+#define WM5100_DRC_SIG_DET_RMS_SHIFT                11  /* DRC_SIG_DET_RMS - [15:11] */
+#define WM5100_DRC_SIG_DET_RMS_WIDTH                 5  /* DRC_SIG_DET_RMS - [15:11] */
+#define WM5100_DRC_SIG_DET_PK_MASK              0x0600  /* DRC_SIG_DET_PK - [10:9] */
+#define WM5100_DRC_SIG_DET_PK_SHIFT                  9  /* DRC_SIG_DET_PK - [10:9] */
+#define WM5100_DRC_SIG_DET_PK_WIDTH                  2  /* DRC_SIG_DET_PK - [10:9] */
+#define WM5100_DRC_NG_ENA                       0x0100  /* DRC_NG_ENA */
+#define WM5100_DRC_NG_ENA_MASK                  0x0100  /* DRC_NG_ENA */
+#define WM5100_DRC_NG_ENA_SHIFT                      8  /* DRC_NG_ENA */
+#define WM5100_DRC_NG_ENA_WIDTH                      1  /* DRC_NG_ENA */
+#define WM5100_DRC_SIG_DET_MODE                 0x0080  /* DRC_SIG_DET_MODE */
+#define WM5100_DRC_SIG_DET_MODE_MASK            0x0080  /* DRC_SIG_DET_MODE */
+#define WM5100_DRC_SIG_DET_MODE_SHIFT                7  /* DRC_SIG_DET_MODE */
+#define WM5100_DRC_SIG_DET_MODE_WIDTH                1  /* DRC_SIG_DET_MODE */
+#define WM5100_DRC_SIG_DET                      0x0040  /* DRC_SIG_DET */
+#define WM5100_DRC_SIG_DET_MASK                 0x0040  /* DRC_SIG_DET */
+#define WM5100_DRC_SIG_DET_SHIFT                     6  /* DRC_SIG_DET */
+#define WM5100_DRC_SIG_DET_WIDTH                     1  /* DRC_SIG_DET */
+#define WM5100_DRC_KNEE2_OP_ENA                 0x0020  /* DRC_KNEE2_OP_ENA */
+#define WM5100_DRC_KNEE2_OP_ENA_MASK            0x0020  /* DRC_KNEE2_OP_ENA */
+#define WM5100_DRC_KNEE2_OP_ENA_SHIFT                5  /* DRC_KNEE2_OP_ENA */
+#define WM5100_DRC_KNEE2_OP_ENA_WIDTH                1  /* DRC_KNEE2_OP_ENA */
+#define WM5100_DRC_QR                           0x0010  /* DRC_QR */
+#define WM5100_DRC_QR_MASK                      0x0010  /* DRC_QR */
+#define WM5100_DRC_QR_SHIFT                          4  /* DRC_QR */
+#define WM5100_DRC_QR_WIDTH                          1  /* DRC_QR */
+#define WM5100_DRC_ANTICLIP                     0x0008  /* DRC_ANTICLIP */
+#define WM5100_DRC_ANTICLIP_MASK                0x0008  /* DRC_ANTICLIP */
+#define WM5100_DRC_ANTICLIP_SHIFT                    3  /* DRC_ANTICLIP */
+#define WM5100_DRC_ANTICLIP_WIDTH                    1  /* DRC_ANTICLIP */
+#define WM5100_DRCL_ENA                         0x0002  /* DRCL_ENA */
+#define WM5100_DRCL_ENA_MASK                    0x0002  /* DRCL_ENA */
+#define WM5100_DRCL_ENA_SHIFT                        1  /* DRCL_ENA */
+#define WM5100_DRCL_ENA_WIDTH                        1  /* DRCL_ENA */
+#define WM5100_DRCR_ENA                         0x0001  /* DRCR_ENA */
+#define WM5100_DRCR_ENA_MASK                    0x0001  /* DRCR_ENA */
+#define WM5100_DRCR_ENA_SHIFT                        0  /* DRCR_ENA */
+#define WM5100_DRCR_ENA_WIDTH                        1  /* DRCR_ENA */
+
+/*
+ * R3713 (0xE81) - DRC1 ctrl2
+ */
+#define WM5100_DRC_ATK_MASK                     0x1E00  /* DRC_ATK - [12:9] */
+#define WM5100_DRC_ATK_SHIFT                         9  /* DRC_ATK - [12:9] */
+#define WM5100_DRC_ATK_WIDTH                         4  /* DRC_ATK - [12:9] */
+#define WM5100_DRC_DCY_MASK                     0x01E0  /* DRC_DCY - [8:5] */
+#define WM5100_DRC_DCY_SHIFT                         5  /* DRC_DCY - [8:5] */
+#define WM5100_DRC_DCY_WIDTH                         4  /* DRC_DCY - [8:5] */
+#define WM5100_DRC_MINGAIN_MASK                 0x001C  /* DRC_MINGAIN - [4:2] */
+#define WM5100_DRC_MINGAIN_SHIFT                     2  /* DRC_MINGAIN - [4:2] */
+#define WM5100_DRC_MINGAIN_WIDTH                     3  /* DRC_MINGAIN - [4:2] */
+#define WM5100_DRC_MAXGAIN_MASK                 0x0003  /* DRC_MAXGAIN - [1:0] */
+#define WM5100_DRC_MAXGAIN_SHIFT                     0  /* DRC_MAXGAIN - [1:0] */
+#define WM5100_DRC_MAXGAIN_WIDTH                     2  /* DRC_MAXGAIN - [1:0] */
+
+/*
+ * R3714 (0xE82) - DRC1 ctrl3
+ */
+#define WM5100_DRC_NG_MINGAIN_MASK              0xF000  /* DRC_NG_MINGAIN - [15:12] */
+#define WM5100_DRC_NG_MINGAIN_SHIFT                 12  /* DRC_NG_MINGAIN - [15:12] */
+#define WM5100_DRC_NG_MINGAIN_WIDTH                  4  /* DRC_NG_MINGAIN - [15:12] */
+#define WM5100_DRC_NG_EXP_MASK                  0x0C00  /* DRC_NG_EXP - [11:10] */
+#define WM5100_DRC_NG_EXP_SHIFT                     10  /* DRC_NG_EXP - [11:10] */
+#define WM5100_DRC_NG_EXP_WIDTH                      2  /* DRC_NG_EXP - [11:10] */
+#define WM5100_DRC_QR_THR_MASK                  0x0300  /* DRC_QR_THR - [9:8] */
+#define WM5100_DRC_QR_THR_SHIFT                      8  /* DRC_QR_THR - [9:8] */
+#define WM5100_DRC_QR_THR_WIDTH                      2  /* DRC_QR_THR - [9:8] */
+#define WM5100_DRC_QR_DCY_MASK                  0x00C0  /* DRC_QR_DCY - [7:6] */
+#define WM5100_DRC_QR_DCY_SHIFT                      6  /* DRC_QR_DCY - [7:6] */
+#define WM5100_DRC_QR_DCY_WIDTH                      2  /* DRC_QR_DCY - [7:6] */
+#define WM5100_DRC_HI_COMP_MASK                 0x0038  /* DRC_HI_COMP - [5:3] */
+#define WM5100_DRC_HI_COMP_SHIFT                     3  /* DRC_HI_COMP - [5:3] */
+#define WM5100_DRC_HI_COMP_WIDTH                     3  /* DRC_HI_COMP - [5:3] */
+#define WM5100_DRC_LO_COMP_MASK                 0x0007  /* DRC_LO_COMP - [2:0] */
+#define WM5100_DRC_LO_COMP_SHIFT                     0  /* DRC_LO_COMP - [2:0] */
+#define WM5100_DRC_LO_COMP_WIDTH                     3  /* DRC_LO_COMP - [2:0] */
+
+/*
+ * R3715 (0xE83) - DRC1 ctrl4
+ */
+#define WM5100_DRC_KNEE_IP_MASK                 0x07E0  /* DRC_KNEE_IP - [10:5] */
+#define WM5100_DRC_KNEE_IP_SHIFT                     5  /* DRC_KNEE_IP - [10:5] */
+#define WM5100_DRC_KNEE_IP_WIDTH                     6  /* DRC_KNEE_IP - [10:5] */
+#define WM5100_DRC_KNEE_OP_MASK                 0x001F  /* DRC_KNEE_OP - [4:0] */
+#define WM5100_DRC_KNEE_OP_SHIFT                     0  /* DRC_KNEE_OP - [4:0] */
+#define WM5100_DRC_KNEE_OP_WIDTH                     5  /* DRC_KNEE_OP - [4:0] */
+
+/*
+ * R3716 (0xE84) - DRC1 ctrl5
+ */
+#define WM5100_DRC_KNEE2_IP_MASK                0x03E0  /* DRC_KNEE2_IP - [9:5] */
+#define WM5100_DRC_KNEE2_IP_SHIFT                    5  /* DRC_KNEE2_IP - [9:5] */
+#define WM5100_DRC_KNEE2_IP_WIDTH                    5  /* DRC_KNEE2_IP - [9:5] */
+#define WM5100_DRC_KNEE2_OP_MASK                0x001F  /* DRC_KNEE2_OP - [4:0] */
+#define WM5100_DRC_KNEE2_OP_SHIFT                    0  /* DRC_KNEE2_OP - [4:0] */
+#define WM5100_DRC_KNEE2_OP_WIDTH                    5  /* DRC_KNEE2_OP - [4:0] */
+
+/*
+ * R3776 (0xEC0) - HPLPF1_1
+ */
+#define WM5100_LHPF1_MODE                       0x0002  /* LHPF1_MODE */
+#define WM5100_LHPF1_MODE_MASK                  0x0002  /* LHPF1_MODE */
+#define WM5100_LHPF1_MODE_SHIFT                      1  /* LHPF1_MODE */
+#define WM5100_LHPF1_MODE_WIDTH                      1  /* LHPF1_MODE */
+#define WM5100_LHPF1_ENA                        0x0001  /* LHPF1_ENA */
+#define WM5100_LHPF1_ENA_MASK                   0x0001  /* LHPF1_ENA */
+#define WM5100_LHPF1_ENA_SHIFT                       0  /* LHPF1_ENA */
+#define WM5100_LHPF1_ENA_WIDTH                       1  /* LHPF1_ENA */
+
+/*
+ * R3777 (0xEC1) - HPLPF1_2
+ */
+#define WM5100_LHPF1_COEFF_MASK                 0xFFFF  /* LHPF1_COEFF - [15:0] */
+#define WM5100_LHPF1_COEFF_SHIFT                     0  /* LHPF1_COEFF - [15:0] */
+#define WM5100_LHPF1_COEFF_WIDTH                    16  /* LHPF1_COEFF - [15:0] */
+
+/*
+ * R3780 (0xEC4) - HPLPF2_1
+ */
+#define WM5100_LHPF2_MODE                       0x0002  /* LHPF2_MODE */
+#define WM5100_LHPF2_MODE_MASK                  0x0002  /* LHPF2_MODE */
+#define WM5100_LHPF2_MODE_SHIFT                      1  /* LHPF2_MODE */
+#define WM5100_LHPF2_MODE_WIDTH                      1  /* LHPF2_MODE */
+#define WM5100_LHPF2_ENA                        0x0001  /* LHPF2_ENA */
+#define WM5100_LHPF2_ENA_MASK                   0x0001  /* LHPF2_ENA */
+#define WM5100_LHPF2_ENA_SHIFT                       0  /* LHPF2_ENA */
+#define WM5100_LHPF2_ENA_WIDTH                       1  /* LHPF2_ENA */
+
+/*
+ * R3781 (0xEC5) - HPLPF2_2
+ */
+#define WM5100_LHPF2_COEFF_MASK                 0xFFFF  /* LHPF2_COEFF - [15:0] */
+#define WM5100_LHPF2_COEFF_SHIFT                     0  /* LHPF2_COEFF - [15:0] */
+#define WM5100_LHPF2_COEFF_WIDTH                    16  /* LHPF2_COEFF - [15:0] */
+
+/*
+ * R3784 (0xEC8) - HPLPF3_1
+ */
+#define WM5100_LHPF3_MODE                       0x0002  /* LHPF3_MODE */
+#define WM5100_LHPF3_MODE_MASK                  0x0002  /* LHPF3_MODE */
+#define WM5100_LHPF3_MODE_SHIFT                      1  /* LHPF3_MODE */
+#define WM5100_LHPF3_MODE_WIDTH                      1  /* LHPF3_MODE */
+#define WM5100_LHPF3_ENA                        0x0001  /* LHPF3_ENA */
+#define WM5100_LHPF3_ENA_MASK                   0x0001  /* LHPF3_ENA */
+#define WM5100_LHPF3_ENA_SHIFT                       0  /* LHPF3_ENA */
+#define WM5100_LHPF3_ENA_WIDTH                       1  /* LHPF3_ENA */
+
+/*
+ * R3785 (0xEC9) - HPLPF3_2
+ */
+#define WM5100_LHPF3_COEFF_MASK                 0xFFFF  /* LHPF3_COEFF - [15:0] */
+#define WM5100_LHPF3_COEFF_SHIFT                     0  /* LHPF3_COEFF - [15:0] */
+#define WM5100_LHPF3_COEFF_WIDTH                    16  /* LHPF3_COEFF - [15:0] */
+
+/*
+ * R3788 (0xECC) - HPLPF4_1
+ */
+#define WM5100_LHPF4_MODE                       0x0002  /* LHPF4_MODE */
+#define WM5100_LHPF4_MODE_MASK                  0x0002  /* LHPF4_MODE */
+#define WM5100_LHPF4_MODE_SHIFT                      1  /* LHPF4_MODE */
+#define WM5100_LHPF4_MODE_WIDTH                      1  /* LHPF4_MODE */
+#define WM5100_LHPF4_ENA                        0x0001  /* LHPF4_ENA */
+#define WM5100_LHPF4_ENA_MASK                   0x0001  /* LHPF4_ENA */
+#define WM5100_LHPF4_ENA_SHIFT                       0  /* LHPF4_ENA */
+#define WM5100_LHPF4_ENA_WIDTH                       1  /* LHPF4_ENA */
+
+/*
+ * R3789 (0xECD) - HPLPF4_2
+ */
+#define WM5100_LHPF4_COEFF_MASK                 0xFFFF  /* LHPF4_COEFF - [15:0] */
+#define WM5100_LHPF4_COEFF_SHIFT                     0  /* LHPF4_COEFF - [15:0] */
+#define WM5100_LHPF4_COEFF_WIDTH                    16  /* LHPF4_COEFF - [15:0] */
+
+/*
+ * R16384 (0x4000) - DSP1 DM 0
+ */
+#define WM5100_DSP1_DM_START_1_MASK             0x00FF  /* DSP1_DM_START - [7:0] */
+#define WM5100_DSP1_DM_START_1_SHIFT                 0  /* DSP1_DM_START - [7:0] */
+#define WM5100_DSP1_DM_START_1_WIDTH                 8  /* DSP1_DM_START - [7:0] */
+
+/*
+ * R16385 (0x4001) - DSP1 DM 1
+ */
+#define WM5100_DSP1_DM_START_MASK               0xFFFF  /* DSP1_DM_START - [15:0] */
+#define WM5100_DSP1_DM_START_SHIFT                   0  /* DSP1_DM_START - [15:0] */
+#define WM5100_DSP1_DM_START_WIDTH                  16  /* DSP1_DM_START - [15:0] */
+
+/*
+ * R16386 (0x4002) - DSP1 DM 2
+ */
+#define WM5100_DSP1_DM_1_1_MASK                 0x00FF  /* DSP1_DM_1 - [7:0] */
+#define WM5100_DSP1_DM_1_1_SHIFT                     0  /* DSP1_DM_1 - [7:0] */
+#define WM5100_DSP1_DM_1_1_WIDTH                     8  /* DSP1_DM_1 - [7:0] */
+
+/*
+ * R16387 (0x4003) - DSP1 DM 3
+ */
+#define WM5100_DSP1_DM_1_MASK                   0xFFFF  /* DSP1_DM_1 - [15:0] */
+#define WM5100_DSP1_DM_1_SHIFT                       0  /* DSP1_DM_1 - [15:0] */
+#define WM5100_DSP1_DM_1_WIDTH                      16  /* DSP1_DM_1 - [15:0] */
+
+/*
+ * R16892 (0x41FC) - DSP1 DM 508
+ */
+#define WM5100_DSP1_DM_254_1_MASK               0x00FF  /* DSP1_DM_254 - [7:0] */
+#define WM5100_DSP1_DM_254_1_SHIFT                   0  /* DSP1_DM_254 - [7:0] */
+#define WM5100_DSP1_DM_254_1_WIDTH                   8  /* DSP1_DM_254 - [7:0] */
+
+/*
+ * R16893 (0x41FD) - DSP1 DM 509
+ */
+#define WM5100_DSP1_DM_254_MASK                 0xFFFF  /* DSP1_DM_254 - [15:0] */
+#define WM5100_DSP1_DM_254_SHIFT                     0  /* DSP1_DM_254 - [15:0] */
+#define WM5100_DSP1_DM_254_WIDTH                    16  /* DSP1_DM_254 - [15:0] */
+
+/*
+ * R16894 (0x41FE) - DSP1 DM 510
+ */
+#define WM5100_DSP1_DM_END_1_MASK               0x00FF  /* DSP1_DM_END - [7:0] */
+#define WM5100_DSP1_DM_END_1_SHIFT                   0  /* DSP1_DM_END - [7:0] */
+#define WM5100_DSP1_DM_END_1_WIDTH                   8  /* DSP1_DM_END - [7:0] */
+
+/*
+ * R16895 (0x41FF) - DSP1 DM 511
+ */
+#define WM5100_DSP1_DM_END_MASK                 0xFFFF  /* DSP1_DM_END - [15:0] */
+#define WM5100_DSP1_DM_END_SHIFT                     0  /* DSP1_DM_END - [15:0] */
+#define WM5100_DSP1_DM_END_WIDTH                    16  /* DSP1_DM_END - [15:0] */
+
+/*
+ * R18432 (0x4800) - DSP1 PM 0
+ */
+#define WM5100_DSP1_PM_START_2_MASK             0x00FF  /* DSP1_PM_START - [7:0] */
+#define WM5100_DSP1_PM_START_2_SHIFT                 0  /* DSP1_PM_START - [7:0] */
+#define WM5100_DSP1_PM_START_2_WIDTH                 8  /* DSP1_PM_START - [7:0] */
+
+/*
+ * R18433 (0x4801) - DSP1 PM 1
+ */
+#define WM5100_DSP1_PM_START_1_MASK             0xFFFF  /* DSP1_PM_START - [15:0] */
+#define WM5100_DSP1_PM_START_1_SHIFT                 0  /* DSP1_PM_START - [15:0] */
+#define WM5100_DSP1_PM_START_1_WIDTH                16  /* DSP1_PM_START - [15:0] */
+
+/*
+ * R18434 (0x4802) - DSP1 PM 2
+ */
+#define WM5100_DSP1_PM_START_MASK               0xFFFF  /* DSP1_PM_START - [15:0] */
+#define WM5100_DSP1_PM_START_SHIFT                   0  /* DSP1_PM_START - [15:0] */
+#define WM5100_DSP1_PM_START_WIDTH                  16  /* DSP1_PM_START - [15:0] */
+
+/*
+ * R18435 (0x4803) - DSP1 PM 3
+ */
+#define WM5100_DSP1_PM_1_2_MASK                 0x00FF  /* DSP1_PM_1 - [7:0] */
+#define WM5100_DSP1_PM_1_2_SHIFT                     0  /* DSP1_PM_1 - [7:0] */
+#define WM5100_DSP1_PM_1_2_WIDTH                     8  /* DSP1_PM_1 - [7:0] */
+
+/*
+ * R18436 (0x4804) - DSP1 PM 4
+ */
+#define WM5100_DSP1_PM_1_1_MASK                 0xFFFF  /* DSP1_PM_1 - [15:0] */
+#define WM5100_DSP1_PM_1_1_SHIFT                     0  /* DSP1_PM_1 - [15:0] */
+#define WM5100_DSP1_PM_1_1_WIDTH                    16  /* DSP1_PM_1 - [15:0] */
+
+/*
+ * R18437 (0x4805) - DSP1 PM 5
+ */
+#define WM5100_DSP1_PM_1_MASK                   0xFFFF  /* DSP1_PM_1 - [15:0] */
+#define WM5100_DSP1_PM_1_SHIFT                       0  /* DSP1_PM_1 - [15:0] */
+#define WM5100_DSP1_PM_1_WIDTH                      16  /* DSP1_PM_1 - [15:0] */
+
+/*
+ * R19962 (0x4DFA) - DSP1 PM 1530
+ */
+#define WM5100_DSP1_PM_510_2_MASK               0x00FF  /* DSP1_PM_510 - [7:0] */
+#define WM5100_DSP1_PM_510_2_SHIFT                   0  /* DSP1_PM_510 - [7:0] */
+#define WM5100_DSP1_PM_510_2_WIDTH                   8  /* DSP1_PM_510 - [7:0] */
+
+/*
+ * R19963 (0x4DFB) - DSP1 PM 1531
+ */
+#define WM5100_DSP1_PM_510_1_MASK               0xFFFF  /* DSP1_PM_510 - [15:0] */
+#define WM5100_DSP1_PM_510_1_SHIFT                   0  /* DSP1_PM_510 - [15:0] */
+#define WM5100_DSP1_PM_510_1_WIDTH                  16  /* DSP1_PM_510 - [15:0] */
+
+/*
+ * R19964 (0x4DFC) - DSP1 PM 1532
+ */
+#define WM5100_DSP1_PM_510_MASK                 0xFFFF  /* DSP1_PM_510 - [15:0] */
+#define WM5100_DSP1_PM_510_SHIFT                     0  /* DSP1_PM_510 - [15:0] */
+#define WM5100_DSP1_PM_510_WIDTH                    16  /* DSP1_PM_510 - [15:0] */
+
+/*
+ * R19965 (0x4DFD) - DSP1 PM 1533
+ */
+#define WM5100_DSP1_PM_END_2_MASK               0x00FF  /* DSP1_PM_END - [7:0] */
+#define WM5100_DSP1_PM_END_2_SHIFT                   0  /* DSP1_PM_END - [7:0] */
+#define WM5100_DSP1_PM_END_2_WIDTH                   8  /* DSP1_PM_END - [7:0] */
+
+/*
+ * R19966 (0x4DFE) - DSP1 PM 1534
+ */
+#define WM5100_DSP1_PM_END_1_MASK               0xFFFF  /* DSP1_PM_END - [15:0] */
+#define WM5100_DSP1_PM_END_1_SHIFT                   0  /* DSP1_PM_END - [15:0] */
+#define WM5100_DSP1_PM_END_1_WIDTH                  16  /* DSP1_PM_END - [15:0] */
+
+/*
+ * R19967 (0x4DFF) - DSP1 PM 1535
+ */
+#define WM5100_DSP1_PM_END_MASK                 0xFFFF  /* DSP1_PM_END - [15:0] */
+#define WM5100_DSP1_PM_END_SHIFT                     0  /* DSP1_PM_END - [15:0] */
+#define WM5100_DSP1_PM_END_WIDTH                    16  /* DSP1_PM_END - [15:0] */
+
+/*
+ * R20480 (0x5000) - DSP1 ZM 0
+ */
+#define WM5100_DSP1_ZM_START_1_MASK             0x00FF  /* DSP1_ZM_START - [7:0] */
+#define WM5100_DSP1_ZM_START_1_SHIFT                 0  /* DSP1_ZM_START - [7:0] */
+#define WM5100_DSP1_ZM_START_1_WIDTH                 8  /* DSP1_ZM_START - [7:0] */
+
+/*
+ * R20481 (0x5001) - DSP1 ZM 1
+ */
+#define WM5100_DSP1_ZM_START_MASK               0xFFFF  /* DSP1_ZM_START - [15:0] */
+#define WM5100_DSP1_ZM_START_SHIFT                   0  /* DSP1_ZM_START - [15:0] */
+#define WM5100_DSP1_ZM_START_WIDTH                  16  /* DSP1_ZM_START - [15:0] */
+
+/*
+ * R20482 (0x5002) - DSP1 ZM 2
+ */
+#define WM5100_DSP1_ZM_1_1_MASK                 0x00FF  /* DSP1_ZM_1 - [7:0] */
+#define WM5100_DSP1_ZM_1_1_SHIFT                     0  /* DSP1_ZM_1 - [7:0] */
+#define WM5100_DSP1_ZM_1_1_WIDTH                     8  /* DSP1_ZM_1 - [7:0] */
+
+/*
+ * R20483 (0x5003) - DSP1 ZM 3
+ */
+#define WM5100_DSP1_ZM_1_MASK                   0xFFFF  /* DSP1_ZM_1 - [15:0] */
+#define WM5100_DSP1_ZM_1_SHIFT                       0  /* DSP1_ZM_1 - [15:0] */
+#define WM5100_DSP1_ZM_1_WIDTH                      16  /* DSP1_ZM_1 - [15:0] */
+
+/*
+ * R22524 (0x57FC) - DSP1 ZM 2044
+ */
+#define WM5100_DSP1_ZM_1022_1_MASK              0x00FF  /* DSP1_ZM_1022 - [7:0] */
+#define WM5100_DSP1_ZM_1022_1_SHIFT                  0  /* DSP1_ZM_1022 - [7:0] */
+#define WM5100_DSP1_ZM_1022_1_WIDTH                  8  /* DSP1_ZM_1022 - [7:0] */
+
+/*
+ * R22525 (0x57FD) - DSP1 ZM 2045
+ */
+#define WM5100_DSP1_ZM_1022_MASK                0xFFFF  /* DSP1_ZM_1022 - [15:0] */
+#define WM5100_DSP1_ZM_1022_SHIFT                    0  /* DSP1_ZM_1022 - [15:0] */
+#define WM5100_DSP1_ZM_1022_WIDTH                   16  /* DSP1_ZM_1022 - [15:0] */
+
+/*
+ * R22526 (0x57FE) - DSP1 ZM 2046
+ */
+#define WM5100_DSP1_ZM_END_1_MASK               0x00FF  /* DSP1_ZM_END - [7:0] */
+#define WM5100_DSP1_ZM_END_1_SHIFT                   0  /* DSP1_ZM_END - [7:0] */
+#define WM5100_DSP1_ZM_END_1_WIDTH                   8  /* DSP1_ZM_END - [7:0] */
+
+/*
+ * R22527 (0x57FF) - DSP1 ZM 2047
+ */
+#define WM5100_DSP1_ZM_END_MASK                 0xFFFF  /* DSP1_ZM_END - [15:0] */
+#define WM5100_DSP1_ZM_END_SHIFT                     0  /* DSP1_ZM_END - [15:0] */
+#define WM5100_DSP1_ZM_END_WIDTH                    16  /* DSP1_ZM_END - [15:0] */
+
+/*
+ * R24576 (0x6000) - DSP2 DM 0
+ */
+#define WM5100_DSP2_DM_START_1_MASK             0x00FF  /* DSP2_DM_START - [7:0] */
+#define WM5100_DSP2_DM_START_1_SHIFT                 0  /* DSP2_DM_START - [7:0] */
+#define WM5100_DSP2_DM_START_1_WIDTH                 8  /* DSP2_DM_START - [7:0] */
+
+/*
+ * R24577 (0x6001) - DSP2 DM 1
+ */
+#define WM5100_DSP2_DM_START_MASK               0xFFFF  /* DSP2_DM_START - [15:0] */
+#define WM5100_DSP2_DM_START_SHIFT                   0  /* DSP2_DM_START - [15:0] */
+#define WM5100_DSP2_DM_START_WIDTH                  16  /* DSP2_DM_START - [15:0] */
+
+/*
+ * R24578 (0x6002) - DSP2 DM 2
+ */
+#define WM5100_DSP2_DM_1_1_MASK                 0x00FF  /* DSP2_DM_1 - [7:0] */
+#define WM5100_DSP2_DM_1_1_SHIFT                     0  /* DSP2_DM_1 - [7:0] */
+#define WM5100_DSP2_DM_1_1_WIDTH                     8  /* DSP2_DM_1 - [7:0] */
+
+/*
+ * R24579 (0x6003) - DSP2 DM 3
+ */
+#define WM5100_DSP2_DM_1_MASK                   0xFFFF  /* DSP2_DM_1 - [15:0] */
+#define WM5100_DSP2_DM_1_SHIFT                       0  /* DSP2_DM_1 - [15:0] */
+#define WM5100_DSP2_DM_1_WIDTH                      16  /* DSP2_DM_1 - [15:0] */
+
+/*
+ * R25084 (0x61FC) - DSP2 DM 508
+ */
+#define WM5100_DSP2_DM_254_1_MASK               0x00FF  /* DSP2_DM_254 - [7:0] */
+#define WM5100_DSP2_DM_254_1_SHIFT                   0  /* DSP2_DM_254 - [7:0] */
+#define WM5100_DSP2_DM_254_1_WIDTH                   8  /* DSP2_DM_254 - [7:0] */
+
+/*
+ * R25085 (0x61FD) - DSP2 DM 509
+ */
+#define WM5100_DSP2_DM_254_MASK                 0xFFFF  /* DSP2_DM_254 - [15:0] */
+#define WM5100_DSP2_DM_254_SHIFT                     0  /* DSP2_DM_254 - [15:0] */
+#define WM5100_DSP2_DM_254_WIDTH                    16  /* DSP2_DM_254 - [15:0] */
+
+/*
+ * R25086 (0x61FE) - DSP2 DM 510
+ */
+#define WM5100_DSP2_DM_END_1_MASK               0x00FF  /* DSP2_DM_END - [7:0] */
+#define WM5100_DSP2_DM_END_1_SHIFT                   0  /* DSP2_DM_END - [7:0] */
+#define WM5100_DSP2_DM_END_1_WIDTH                   8  /* DSP2_DM_END - [7:0] */
+
+/*
+ * R25087 (0x61FF) - DSP2 DM 511
+ */
+#define WM5100_DSP2_DM_END_MASK                 0xFFFF  /* DSP2_DM_END - [15:0] */
+#define WM5100_DSP2_DM_END_SHIFT                     0  /* DSP2_DM_END - [15:0] */
+#define WM5100_DSP2_DM_END_WIDTH                    16  /* DSP2_DM_END - [15:0] */
+
+/*
+ * R26624 (0x6800) - DSP2 PM 0
+ */
+#define WM5100_DSP2_PM_START_2_MASK             0x00FF  /* DSP2_PM_START - [7:0] */
+#define WM5100_DSP2_PM_START_2_SHIFT                 0  /* DSP2_PM_START - [7:0] */
+#define WM5100_DSP2_PM_START_2_WIDTH                 8  /* DSP2_PM_START - [7:0] */
+
+/*
+ * R26625 (0x6801) - DSP2 PM 1
+ */
+#define WM5100_DSP2_PM_START_1_MASK             0xFFFF  /* DSP2_PM_START - [15:0] */
+#define WM5100_DSP2_PM_START_1_SHIFT                 0  /* DSP2_PM_START - [15:0] */
+#define WM5100_DSP2_PM_START_1_WIDTH                16  /* DSP2_PM_START - [15:0] */
+
+/*
+ * R26626 (0x6802) - DSP2 PM 2
+ */
+#define WM5100_DSP2_PM_START_MASK               0xFFFF  /* DSP2_PM_START - [15:0] */
+#define WM5100_DSP2_PM_START_SHIFT                   0  /* DSP2_PM_START - [15:0] */
+#define WM5100_DSP2_PM_START_WIDTH                  16  /* DSP2_PM_START - [15:0] */
+
+/*
+ * R26627 (0x6803) - DSP2 PM 3
+ */
+#define WM5100_DSP2_PM_1_2_MASK                 0x00FF  /* DSP2_PM_1 - [7:0] */
+#define WM5100_DSP2_PM_1_2_SHIFT                     0  /* DSP2_PM_1 - [7:0] */
+#define WM5100_DSP2_PM_1_2_WIDTH                     8  /* DSP2_PM_1 - [7:0] */
+
+/*
+ * R26628 (0x6804) - DSP2 PM 4
+ */
+#define WM5100_DSP2_PM_1_1_MASK                 0xFFFF  /* DSP2_PM_1 - [15:0] */
+#define WM5100_DSP2_PM_1_1_SHIFT                     0  /* DSP2_PM_1 - [15:0] */
+#define WM5100_DSP2_PM_1_1_WIDTH                    16  /* DSP2_PM_1 - [15:0] */
+
+/*
+ * R26629 (0x6805) - DSP2 PM 5
+ */
+#define WM5100_DSP2_PM_1_MASK                   0xFFFF  /* DSP2_PM_1 - [15:0] */
+#define WM5100_DSP2_PM_1_SHIFT                       0  /* DSP2_PM_1 - [15:0] */
+#define WM5100_DSP2_PM_1_WIDTH                      16  /* DSP2_PM_1 - [15:0] */
+
+/*
+ * R28154 (0x6DFA) - DSP2 PM 1530
+ */
+#define WM5100_DSP2_PM_510_2_MASK               0x00FF  /* DSP2_PM_510 - [7:0] */
+#define WM5100_DSP2_PM_510_2_SHIFT                   0  /* DSP2_PM_510 - [7:0] */
+#define WM5100_DSP2_PM_510_2_WIDTH                   8  /* DSP2_PM_510 - [7:0] */
+
+/*
+ * R28155 (0x6DFB) - DSP2 PM 1531
+ */
+#define WM5100_DSP2_PM_510_1_MASK               0xFFFF  /* DSP2_PM_510 - [15:0] */
+#define WM5100_DSP2_PM_510_1_SHIFT                   0  /* DSP2_PM_510 - [15:0] */
+#define WM5100_DSP2_PM_510_1_WIDTH                  16  /* DSP2_PM_510 - [15:0] */
+
+/*
+ * R28156 (0x6DFC) - DSP2 PM 1532
+ */
+#define WM5100_DSP2_PM_510_MASK                 0xFFFF  /* DSP2_PM_510 - [15:0] */
+#define WM5100_DSP2_PM_510_SHIFT                     0  /* DSP2_PM_510 - [15:0] */
+#define WM5100_DSP2_PM_510_WIDTH                    16  /* DSP2_PM_510 - [15:0] */
+
+/*
+ * R28157 (0x6DFD) - DSP2 PM 1533
+ */
+#define WM5100_DSP2_PM_END_2_MASK               0x00FF  /* DSP2_PM_END - [7:0] */
+#define WM5100_DSP2_PM_END_2_SHIFT                   0  /* DSP2_PM_END - [7:0] */
+#define WM5100_DSP2_PM_END_2_WIDTH                   8  /* DSP2_PM_END - [7:0] */
+
+/*
+ * R28158 (0x6DFE) - DSP2 PM 1534
+ */
+#define WM5100_DSP2_PM_END_1_MASK               0xFFFF  /* DSP2_PM_END - [15:0] */
+#define WM5100_DSP2_PM_END_1_SHIFT                   0  /* DSP2_PM_END - [15:0] */
+#define WM5100_DSP2_PM_END_1_WIDTH                  16  /* DSP2_PM_END - [15:0] */
+
+/*
+ * R28159 (0x6DFF) - DSP2 PM 1535
+ */
+#define WM5100_DSP2_PM_END_MASK                 0xFFFF  /* DSP2_PM_END - [15:0] */
+#define WM5100_DSP2_PM_END_SHIFT                     0  /* DSP2_PM_END - [15:0] */
+#define WM5100_DSP2_PM_END_WIDTH                    16  /* DSP2_PM_END - [15:0] */
+
+/*
+ * R28672 (0x7000) - DSP2 ZM 0
+ */
+#define WM5100_DSP2_ZM_START_1_MASK             0x00FF  /* DSP2_ZM_START - [7:0] */
+#define WM5100_DSP2_ZM_START_1_SHIFT                 0  /* DSP2_ZM_START - [7:0] */
+#define WM5100_DSP2_ZM_START_1_WIDTH                 8  /* DSP2_ZM_START - [7:0] */
+
+/*
+ * R28673 (0x7001) - DSP2 ZM 1
+ */
+#define WM5100_DSP2_ZM_START_MASK               0xFFFF  /* DSP2_ZM_START - [15:0] */
+#define WM5100_DSP2_ZM_START_SHIFT                   0  /* DSP2_ZM_START - [15:0] */
+#define WM5100_DSP2_ZM_START_WIDTH                  16  /* DSP2_ZM_START - [15:0] */
+
+/*
+ * R28674 (0x7002) - DSP2 ZM 2
+ */
+#define WM5100_DSP2_ZM_1_1_MASK                 0x00FF  /* DSP2_ZM_1 - [7:0] */
+#define WM5100_DSP2_ZM_1_1_SHIFT                     0  /* DSP2_ZM_1 - [7:0] */
+#define WM5100_DSP2_ZM_1_1_WIDTH                     8  /* DSP2_ZM_1 - [7:0] */
+
+/*
+ * R28675 (0x7003) - DSP2 ZM 3
+ */
+#define WM5100_DSP2_ZM_1_MASK                   0xFFFF  /* DSP2_ZM_1 - [15:0] */
+#define WM5100_DSP2_ZM_1_SHIFT                       0  /* DSP2_ZM_1 - [15:0] */
+#define WM5100_DSP2_ZM_1_WIDTH                      16  /* DSP2_ZM_1 - [15:0] */
+
+/*
+ * R30716 (0x77FC) - DSP2 ZM 2044
+ */
+#define WM5100_DSP2_ZM_1022_1_MASK              0x00FF  /* DSP2_ZM_1022 - [7:0] */
+#define WM5100_DSP2_ZM_1022_1_SHIFT                  0  /* DSP2_ZM_1022 - [7:0] */
+#define WM5100_DSP2_ZM_1022_1_WIDTH                  8  /* DSP2_ZM_1022 - [7:0] */
+
+/*
+ * R30717 (0x77FD) - DSP2 ZM 2045
+ */
+#define WM5100_DSP2_ZM_1022_MASK                0xFFFF  /* DSP2_ZM_1022 - [15:0] */
+#define WM5100_DSP2_ZM_1022_SHIFT                    0  /* DSP2_ZM_1022 - [15:0] */
+#define WM5100_DSP2_ZM_1022_WIDTH                   16  /* DSP2_ZM_1022 - [15:0] */
+
+/*
+ * R30718 (0x77FE) - DSP2 ZM 2046
+ */
+#define WM5100_DSP2_ZM_END_1_MASK               0x00FF  /* DSP2_ZM_END - [7:0] */
+#define WM5100_DSP2_ZM_END_1_SHIFT                   0  /* DSP2_ZM_END - [7:0] */
+#define WM5100_DSP2_ZM_END_1_WIDTH                   8  /* DSP2_ZM_END - [7:0] */
+
+/*
+ * R30719 (0x77FF) - DSP2 ZM 2047
+ */
+#define WM5100_DSP2_ZM_END_MASK                 0xFFFF  /* DSP2_ZM_END - [15:0] */
+#define WM5100_DSP2_ZM_END_SHIFT                     0  /* DSP2_ZM_END - [15:0] */
+#define WM5100_DSP2_ZM_END_WIDTH                    16  /* DSP2_ZM_END - [15:0] */
+
+/*
+ * R32768 (0x8000) - DSP3 DM 0
+ */
+#define WM5100_DSP3_DM_START_1_MASK             0x00FF  /* DSP3_DM_START - [7:0] */
+#define WM5100_DSP3_DM_START_1_SHIFT                 0  /* DSP3_DM_START - [7:0] */
+#define WM5100_DSP3_DM_START_1_WIDTH                 8  /* DSP3_DM_START - [7:0] */
+
+/*
+ * R32769 (0x8001) - DSP3 DM 1
+ */
+#define WM5100_DSP3_DM_START_MASK               0xFFFF  /* DSP3_DM_START - [15:0] */
+#define WM5100_DSP3_DM_START_SHIFT                   0  /* DSP3_DM_START - [15:0] */
+#define WM5100_DSP3_DM_START_WIDTH                  16  /* DSP3_DM_START - [15:0] */
+
+/*
+ * R32770 (0x8002) - DSP3 DM 2
+ */
+#define WM5100_DSP3_DM_1_1_MASK                 0x00FF  /* DSP3_DM_1 - [7:0] */
+#define WM5100_DSP3_DM_1_1_SHIFT                     0  /* DSP3_DM_1 - [7:0] */
+#define WM5100_DSP3_DM_1_1_WIDTH                     8  /* DSP3_DM_1 - [7:0] */
+
+/*
+ * R32771 (0x8003) - DSP3 DM 3
+ */
+#define WM5100_DSP3_DM_1_MASK                   0xFFFF  /* DSP3_DM_1 - [15:0] */
+#define WM5100_DSP3_DM_1_SHIFT                       0  /* DSP3_DM_1 - [15:0] */
+#define WM5100_DSP3_DM_1_WIDTH                      16  /* DSP3_DM_1 - [15:0] */
+
+/*
+ * R33276 (0x81FC) - DSP3 DM 508
+ */
+#define WM5100_DSP3_DM_254_1_MASK               0x00FF  /* DSP3_DM_254 - [7:0] */
+#define WM5100_DSP3_DM_254_1_SHIFT                   0  /* DSP3_DM_254 - [7:0] */
+#define WM5100_DSP3_DM_254_1_WIDTH                   8  /* DSP3_DM_254 - [7:0] */
+
+/*
+ * R33277 (0x81FD) - DSP3 DM 509
+ */
+#define WM5100_DSP3_DM_254_MASK                 0xFFFF  /* DSP3_DM_254 - [15:0] */
+#define WM5100_DSP3_DM_254_SHIFT                     0  /* DSP3_DM_254 - [15:0] */
+#define WM5100_DSP3_DM_254_WIDTH                    16  /* DSP3_DM_254 - [15:0] */
+
+/*
+ * R33278 (0x81FE) - DSP3 DM 510
+ */
+#define WM5100_DSP3_DM_END_1_MASK               0x00FF  /* DSP3_DM_END - [7:0] */
+#define WM5100_DSP3_DM_END_1_SHIFT                   0  /* DSP3_DM_END - [7:0] */
+#define WM5100_DSP3_DM_END_1_WIDTH                   8  /* DSP3_DM_END - [7:0] */
+
+/*
+ * R33279 (0x81FF) - DSP3 DM 511
+ */
+#define WM5100_DSP3_DM_END_MASK                 0xFFFF  /* DSP3_DM_END - [15:0] */
+#define WM5100_DSP3_DM_END_SHIFT                     0  /* DSP3_DM_END - [15:0] */
+#define WM5100_DSP3_DM_END_WIDTH                    16  /* DSP3_DM_END - [15:0] */
+
+/*
+ * R34816 (0x8800) - DSP3 PM 0
+ */
+#define WM5100_DSP3_PM_START_2_MASK             0x00FF  /* DSP3_PM_START - [7:0] */
+#define WM5100_DSP3_PM_START_2_SHIFT                 0  /* DSP3_PM_START - [7:0] */
+#define WM5100_DSP3_PM_START_2_WIDTH                 8  /* DSP3_PM_START - [7:0] */
+
+/*
+ * R34817 (0x8801) - DSP3 PM 1
+ */
+#define WM5100_DSP3_PM_START_1_MASK             0xFFFF  /* DSP3_PM_START - [15:0] */
+#define WM5100_DSP3_PM_START_1_SHIFT                 0  /* DSP3_PM_START - [15:0] */
+#define WM5100_DSP3_PM_START_1_WIDTH                16  /* DSP3_PM_START - [15:0] */
+
+/*
+ * R34818 (0x8802) - DSP3 PM 2
+ */
+#define WM5100_DSP3_PM_START_MASK               0xFFFF  /* DSP3_PM_START - [15:0] */
+#define WM5100_DSP3_PM_START_SHIFT                   0  /* DSP3_PM_START - [15:0] */
+#define WM5100_DSP3_PM_START_WIDTH                  16  /* DSP3_PM_START - [15:0] */
+
+/*
+ * R34819 (0x8803) - DSP3 PM 3
+ */
+#define WM5100_DSP3_PM_1_2_MASK                 0x00FF  /* DSP3_PM_1 - [7:0] */
+#define WM5100_DSP3_PM_1_2_SHIFT                     0  /* DSP3_PM_1 - [7:0] */
+#define WM5100_DSP3_PM_1_2_WIDTH                     8  /* DSP3_PM_1 - [7:0] */
+
+/*
+ * R34820 (0x8804) - DSP3 PM 4
+ */
+#define WM5100_DSP3_PM_1_1_MASK                 0xFFFF  /* DSP3_PM_1 - [15:0] */
+#define WM5100_DSP3_PM_1_1_SHIFT                     0  /* DSP3_PM_1 - [15:0] */
+#define WM5100_DSP3_PM_1_1_WIDTH                    16  /* DSP3_PM_1 - [15:0] */
+
+/*
+ * R34821 (0x8805) - DSP3 PM 5
+ */
+#define WM5100_DSP3_PM_1_MASK                   0xFFFF  /* DSP3_PM_1 - [15:0] */
+#define WM5100_DSP3_PM_1_SHIFT                       0  /* DSP3_PM_1 - [15:0] */
+#define WM5100_DSP3_PM_1_WIDTH                      16  /* DSP3_PM_1 - [15:0] */
+
+/*
+ * R36346 (0x8DFA) - DSP3 PM 1530
+ */
+#define WM5100_DSP3_PM_510_2_MASK               0x00FF  /* DSP3_PM_510 - [7:0] */
+#define WM5100_DSP3_PM_510_2_SHIFT                   0  /* DSP3_PM_510 - [7:0] */
+#define WM5100_DSP3_PM_510_2_WIDTH                   8  /* DSP3_PM_510 - [7:0] */
+
+/*
+ * R36347 (0x8DFB) - DSP3 PM 1531
+ */
+#define WM5100_DSP3_PM_510_1_MASK               0xFFFF  /* DSP3_PM_510 - [15:0] */
+#define WM5100_DSP3_PM_510_1_SHIFT                   0  /* DSP3_PM_510 - [15:0] */
+#define WM5100_DSP3_PM_510_1_WIDTH                  16  /* DSP3_PM_510 - [15:0] */
+
+/*
+ * R36348 (0x8DFC) - DSP3 PM 1532
+ */
+#define WM5100_DSP3_PM_510_MASK                 0xFFFF  /* DSP3_PM_510 - [15:0] */
+#define WM5100_DSP3_PM_510_SHIFT                     0  /* DSP3_PM_510 - [15:0] */
+#define WM5100_DSP3_PM_510_WIDTH                    16  /* DSP3_PM_510 - [15:0] */
+
+/*
+ * R36349 (0x8DFD) - DSP3 PM 1533
+ */
+#define WM5100_DSP3_PM_END_2_MASK               0x00FF  /* DSP3_PM_END - [7:0] */
+#define WM5100_DSP3_PM_END_2_SHIFT                   0  /* DSP3_PM_END - [7:0] */
+#define WM5100_DSP3_PM_END_2_WIDTH                   8  /* DSP3_PM_END - [7:0] */
+
+/*
+ * R36350 (0x8DFE) - DSP3 PM 1534
+ */
+#define WM5100_DSP3_PM_END_1_MASK               0xFFFF  /* DSP3_PM_END - [15:0] */
+#define WM5100_DSP3_PM_END_1_SHIFT                   0  /* DSP3_PM_END - [15:0] */
+#define WM5100_DSP3_PM_END_1_WIDTH                  16  /* DSP3_PM_END - [15:0] */
+
+/*
+ * R36351 (0x8DFF) - DSP3 PM 1535
+ */
+#define WM5100_DSP3_PM_END_MASK                 0xFFFF  /* DSP3_PM_END - [15:0] */
+#define WM5100_DSP3_PM_END_SHIFT                     0  /* DSP3_PM_END - [15:0] */
+#define WM5100_DSP3_PM_END_WIDTH                    16  /* DSP3_PM_END - [15:0] */
+
+/*
+ * R36864 (0x9000) - DSP3 ZM 0
+ */
+#define WM5100_DSP3_ZM_START_1_MASK             0x00FF  /* DSP3_ZM_START - [7:0] */
+#define WM5100_DSP3_ZM_START_1_SHIFT                 0  /* DSP3_ZM_START - [7:0] */
+#define WM5100_DSP3_ZM_START_1_WIDTH                 8  /* DSP3_ZM_START - [7:0] */
+
+/*
+ * R36865 (0x9001) - DSP3 ZM 1
+ */
+#define WM5100_DSP3_ZM_START_MASK               0xFFFF  /* DSP3_ZM_START - [15:0] */
+#define WM5100_DSP3_ZM_START_SHIFT                   0  /* DSP3_ZM_START - [15:0] */
+#define WM5100_DSP3_ZM_START_WIDTH                  16  /* DSP3_ZM_START - [15:0] */
+
+/*
+ * R36866 (0x9002) - DSP3 ZM 2
+ */
+#define WM5100_DSP3_ZM_1_1_MASK                 0x00FF  /* DSP3_ZM_1 - [7:0] */
+#define WM5100_DSP3_ZM_1_1_SHIFT                     0  /* DSP3_ZM_1 - [7:0] */
+#define WM5100_DSP3_ZM_1_1_WIDTH                     8  /* DSP3_ZM_1 - [7:0] */
+
+/*
+ * R36867 (0x9003) - DSP3 ZM 3
+ */
+#define WM5100_DSP3_ZM_1_MASK                   0xFFFF  /* DSP3_ZM_1 - [15:0] */
+#define WM5100_DSP3_ZM_1_SHIFT                       0  /* DSP3_ZM_1 - [15:0] */
+#define WM5100_DSP3_ZM_1_WIDTH                      16  /* DSP3_ZM_1 - [15:0] */
+
+/*
+ * R38908 (0x97FC) - DSP3 ZM 2044
+ */
+#define WM5100_DSP3_ZM_1022_1_MASK              0x00FF  /* DSP3_ZM_1022 - [7:0] */
+#define WM5100_DSP3_ZM_1022_1_SHIFT                  0  /* DSP3_ZM_1022 - [7:0] */
+#define WM5100_DSP3_ZM_1022_1_WIDTH                  8  /* DSP3_ZM_1022 - [7:0] */
+
+/*
+ * R38909 (0x97FD) - DSP3 ZM 2045
+ */
+#define WM5100_DSP3_ZM_1022_MASK                0xFFFF  /* DSP3_ZM_1022 - [15:0] */
+#define WM5100_DSP3_ZM_1022_SHIFT                    0  /* DSP3_ZM_1022 - [15:0] */
+#define WM5100_DSP3_ZM_1022_WIDTH                   16  /* DSP3_ZM_1022 - [15:0] */
+
+/*
+ * R38910 (0x97FE) - DSP3 ZM 2046
+ */
+#define WM5100_DSP3_ZM_END_1_MASK               0x00FF  /* DSP3_ZM_END - [7:0] */
+#define WM5100_DSP3_ZM_END_1_SHIFT                   0  /* DSP3_ZM_END - [7:0] */
+#define WM5100_DSP3_ZM_END_1_WIDTH                   8  /* DSP3_ZM_END - [7:0] */
+
+/*
+ * R38911 (0x97FF) - DSP3 ZM 2047
+ */
+#define WM5100_DSP3_ZM_END_MASK                 0xFFFF  /* DSP3_ZM_END - [15:0] */
+#define WM5100_DSP3_ZM_END_SHIFT                     0  /* DSP3_ZM_END - [15:0] */
+#define WM5100_DSP3_ZM_END_WIDTH                    16  /* DSP3_ZM_END - [15:0] */
+
+int wm5100_readable_register(struct snd_soc_codec *codec, unsigned int reg);
+int wm5100_volatile_register(struct snd_soc_codec *codec, unsigned int reg);
+
+extern u16 wm5100_reg_defaults[WM5100_MAX_REGISTER + 1];
+
+#endif
index 6d6dc9efe9145d0f044d4e39762f52c9a9aca2af..35f3ad83dfb6670013652772268385b75cda481a 100644 (file)
@@ -355,7 +355,7 @@ static int wm8350_put_volsw_2r_vu(struct snd_kcontrol *kcontrol,
                        return 1;
        }
 
-       ret = snd_soc_put_volsw_2r(kcontrol, ucontrol);
+       ret = snd_soc_put_volsw(kcontrol, ucontrol);
        if (ret < 0)
                return ret;
 
@@ -392,23 +392,9 @@ static int wm8350_get_volsw_2r(struct snd_kcontrol *kcontrol,
                break;
        }
 
-       return snd_soc_get_volsw_2r(kcontrol, ucontrol);
+       return snd_soc_get_volsw(kcontrol, ucontrol);
 }
 
-/* double control with volume update */
-#define SOC_WM8350_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax, \
-                               xinvert, tlv_array) \
-{      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
-       .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
-               SNDRV_CTL_ELEM_ACCESS_READWRITE | \
-               SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
-       .tlv.p = (tlv_array), \
-       .info = snd_soc_info_volsw_2r, \
-       .get = wm8350_get_volsw_2r, .put = wm8350_put_volsw_2r_vu, \
-       .private_value = (unsigned long)&(struct soc_mixer_control) \
-               {.reg = reg_left, .rreg = reg_right, .shift = xshift, \
-                .rshift = xshift, .max = xmax, .invert = xinvert}, }
-
 static const char *wm8350_deemp[] = { "None", "32kHz", "44.1kHz", "48kHz" };
 static const char *wm8350_pol[] = { "Normal", "Inv R", "Inv L", "Inv L & R" };
 static const char *wm8350_dacmutem[] = { "Normal", "Soft" };
@@ -443,26 +429,29 @@ static const unsigned int capture_sd_tlv[] = {
 static const struct snd_kcontrol_new wm8350_snd_controls[] = {
        SOC_ENUM("Playback Deemphasis", wm8350_enum[0]),
        SOC_ENUM("Playback DAC Inversion", wm8350_enum[1]),
-       SOC_WM8350_DOUBLE_R_TLV("Playback PCM Volume",
+       SOC_DOUBLE_R_EXT_TLV("Playback PCM Volume",
                                WM8350_DAC_DIGITAL_VOLUME_L,
                                WM8350_DAC_DIGITAL_VOLUME_R,
-                               0, 255, 0, dac_pcm_tlv),
+                               0, 255, 0, wm8350_get_volsw_2r,
+                               wm8350_put_volsw_2r_vu, dac_pcm_tlv),
        SOC_ENUM("Playback PCM Mute Function", wm8350_enum[2]),
        SOC_ENUM("Playback PCM Mute Speed", wm8350_enum[3]),
        SOC_ENUM("Capture PCM Filter", wm8350_enum[4]),
        SOC_ENUM("Capture PCM HP Filter", wm8350_enum[5]),
        SOC_ENUM("Capture ADC Inversion", wm8350_enum[6]),
-       SOC_WM8350_DOUBLE_R_TLV("Capture PCM Volume",
+       SOC_DOUBLE_R_EXT_TLV("Capture PCM Volume",
                                WM8350_ADC_DIGITAL_VOLUME_L,
                                WM8350_ADC_DIGITAL_VOLUME_R,
-                               0, 255, 0, adc_pcm_tlv),
+                               0, 255, 0, wm8350_get_volsw_2r,
+                               wm8350_put_volsw_2r_vu, adc_pcm_tlv),
        SOC_DOUBLE_TLV("Capture Sidetone Volume",
                       WM8350_ADC_DIVIDER,
                       8, 4, 15, 1, capture_sd_tlv),
-       SOC_WM8350_DOUBLE_R_TLV("Capture Volume",
+       SOC_DOUBLE_R_EXT_TLV("Capture Volume",
                                WM8350_LEFT_INPUT_VOLUME,
                                WM8350_RIGHT_INPUT_VOLUME,
-                               2, 63, 0, pre_amp_tlv),
+                               2, 63, 0, wm8350_get_volsw_2r,
+                               wm8350_put_volsw_2r_vu, pre_amp_tlv),
        SOC_DOUBLE_R("Capture ZC Switch",
                     WM8350_LEFT_INPUT_VOLUME,
                     WM8350_RIGHT_INPUT_VOLUME, 13, 1, 0),
@@ -490,17 +479,19 @@ static const struct snd_kcontrol_new wm8350_snd_controls[] = {
        SOC_SINGLE_TLV("Out4 Capture Volume",
                       WM8350_INPUT_MIXER_VOLUME,
                       1, 7, 0, out_mix_tlv),
-       SOC_WM8350_DOUBLE_R_TLV("Out1 Playback Volume",
+       SOC_DOUBLE_R_EXT_TLV("Out1 Playback Volume",
                                WM8350_LOUT1_VOLUME,
                                WM8350_ROUT1_VOLUME,
-                               2, 63, 0, out_pga_tlv),
+                               2, 63, 0, wm8350_get_volsw_2r,
+                               wm8350_put_volsw_2r_vu, out_pga_tlv),
        SOC_DOUBLE_R("Out1 Playback ZC Switch",
                     WM8350_LOUT1_VOLUME,
                     WM8350_ROUT1_VOLUME, 13, 1, 0),
-       SOC_WM8350_DOUBLE_R_TLV("Out2 Playback Volume",
+       SOC_DOUBLE_R_EXT_TLV("Out2 Playback Volume",
                                WM8350_LOUT2_VOLUME,
                                WM8350_ROUT2_VOLUME,
-                               2, 63, 0, out_pga_tlv),
+                               2, 63, 0, wm8350_get_volsw_2r,
+                               wm8350_put_volsw_2r_vu, out_pga_tlv),
        SOC_DOUBLE_R("Out2 Playback ZC Switch", WM8350_LOUT2_VOLUME,
                     WM8350_ROUT2_VOLUME, 13, 1, 0),
        SOC_SINGLE("Out2 Right Invert Switch", WM8350_ROUT2_VOLUME, 10, 1, 0),
index fbee556cbf35adaba1bbca26e6659cb199590c07..dc13be2a09c52b64b95aee07eb9d4061485c8b56 100644 (file)
@@ -383,7 +383,7 @@ static int inmixer_event (struct snd_soc_dapm_widget *w,
                (1 << WM8400_AINRMUX_PWR))) {
                reg |= WM8400_AINR_ENA;
        } else {
-               reg &= ~WM8400_AINL_ENA;
+               reg &= ~WM8400_AINR_ENA;
        }
        wm8400_write(w->codec, WM8400_POWER_MANAGEMENT_2, reg);
 
index db0dced7484384637f910efeaeb200211e4ce60b..07c9cc759e97706a308d0489bac40a0f0482fdd1 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/platform_device.h>
 #include <linux/spi/spi.h>
 #include <linux/slab.h>
+#include <linux/of_device.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
@@ -479,6 +480,8 @@ static int wm8510_set_bias_level(struct snd_soc_codec *codec,
                power1 |= WM8510_POWER1_BIASEN | WM8510_POWER1_BUFIOEN;
 
                if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
+                       snd_soc_cache_sync(codec);
+
                        /* Initial cap charge at VMID 5k */
                        snd_soc_write(codec, WM8510_POWER1, power1 | 0x3);
                        mdelay(100);
@@ -540,18 +543,7 @@ static int wm8510_suspend(struct snd_soc_codec *codec, pm_message_t state)
 
 static int wm8510_resume(struct snd_soc_codec *codec)
 {
-       int i;
-       u8 data[2];
-       u16 *cache = codec->reg_cache;
-
-       /* Sync reg_cache with the hardware */
-       for (i = 0; i < ARRAY_SIZE(wm8510_reg); i++) {
-               data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
-               data[1] = cache[i] & 0x00ff;
-               codec->hw_write(codec->control_data, data, 2);
-       }
        wm8510_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-
        return 0;
 }
 
@@ -598,6 +590,11 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8510 = {
        .reg_cache_default =wm8510_reg,
 };
 
+static const struct of_device_id wm8510_of_match[] = {
+       { .compatible = "wlf,wm8510" },
+       { },
+};
+
 #if defined(CONFIG_SPI_MASTER)
 static int __devinit wm8510_spi_probe(struct spi_device *spi)
 {
@@ -628,6 +625,7 @@ static struct spi_driver wm8510_spi_driver = {
        .driver = {
                .name   = "wm8510",
                .owner  = THIS_MODULE,
+               .of_match_table = wm8510_of_match,
        },
        .probe          = wm8510_spi_probe,
        .remove         = __devexit_p(wm8510_spi_remove),
@@ -671,6 +669,7 @@ static struct i2c_driver wm8510_i2c_driver = {
        .driver = {
                .name = "wm8510-codec",
                .owner = THIS_MODULE,
+               .of_match_table = wm8510_of_match,
        },
        .probe =    wm8510_i2c_probe,
        .remove =   __devexit_p(wm8510_i2c_remove),
index 4fd4d8dca0fc0af31439371fbab9040794162095..db7a6819499fa59a1597f5c93066149e08d3c2ac 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/platform_device.h>
 #include <linux/regulator/consumer.h>
 #include <linux/slab.h>
+#include <linux/of_device.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
@@ -84,7 +85,7 @@ static const char *wm8523_zd_count_text[] = {
 static const struct soc_enum wm8523_zc_count =
        SOC_ENUM_SINGLE(WM8523_ZERO_DETECT, 0, 2, wm8523_zd_count_text);
 
-static const struct snd_kcontrol_new wm8523_snd_controls[] = {
+static const struct snd_kcontrol_new wm8523_controls[] = {
 SOC_DOUBLE_R_TLV("Playback Volume", WM8523_DAC_GAINL, WM8523_DAC_GAINR,
                 0, 448, 0, dac_tlv),
 SOC_SINGLE("ZC Switch", WM8523_DAC_CTRL3, 4, 1, 0),
@@ -101,22 +102,11 @@ SND_SOC_DAPM_OUTPUT("LINEVOUTL"),
 SND_SOC_DAPM_OUTPUT("LINEVOUTR"),
 };
 
-static const struct snd_soc_dapm_route intercon[] = {
+static const struct snd_soc_dapm_route wm8523_dapm_routes[] = {
        { "LINEVOUTL", NULL, "DAC" },
        { "LINEVOUTR", NULL, "DAC" },
 };
 
-static int wm8523_add_widgets(struct snd_soc_codec *codec)
-{
-       struct snd_soc_dapm_context *dapm = &codec->dapm;
-
-       snd_soc_dapm_new_controls(dapm, wm8523_dapm_widgets,
-                                 ARRAY_SIZE(wm8523_dapm_widgets));
-       snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
-
-       return 0;
-}
-
 static struct {
        int value;
        int ratio;
@@ -416,7 +406,6 @@ static int wm8523_probe(struct snd_soc_codec *codec)
        struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
        int ret, i;
 
-       codec->hw_write = (hw_write_t)i2c_master_send;
        wm8523->rate_constraint.list = &wm8523->rate_constraint_list[0];
        wm8523->rate_constraint.count =
                ARRAY_SIZE(wm8523->rate_constraint_list);
@@ -479,10 +468,6 @@ static int wm8523_probe(struct snd_soc_codec *codec)
        /* Bias level configuration will have done an extra enable */
        regulator_bulk_disable(ARRAY_SIZE(wm8523->supplies), wm8523->supplies);
 
-       snd_soc_add_controls(codec, wm8523_snd_controls,
-                            ARRAY_SIZE(wm8523_snd_controls));
-       wm8523_add_widgets(codec);
-
        return 0;
 
 err_enable:
@@ -512,6 +497,18 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8523 = {
        .reg_word_size = sizeof(u16),
        .reg_cache_default = wm8523_reg,
        .volatile_register = wm8523_volatile_register,
+
+       .controls = wm8523_controls,
+       .num_controls = ARRAY_SIZE(wm8523_controls),
+       .dapm_widgets = wm8523_dapm_widgets,
+       .num_dapm_widgets = ARRAY_SIZE(wm8523_dapm_widgets),
+       .dapm_routes = wm8523_dapm_routes,
+       .num_dapm_routes = ARRAY_SIZE(wm8523_dapm_routes),
+};
+
+static const struct of_device_id wm8523_of_match[] = {
+       { .compatible = "wlf,wm8523" },
+       { },
 };
 
 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
@@ -551,8 +548,9 @@ MODULE_DEVICE_TABLE(i2c, wm8523_i2c_id);
 
 static struct i2c_driver wm8523_i2c_driver = {
        .driver = {
-               .name = "wm8523-codec",
+               .name = "wm8523",
                .owner = THIS_MODULE,
+               .of_match_table = wm8523_of_match,
        },
        .probe =    wm8523_i2c_probe,
        .remove =   __devexit_p(wm8523_i2c_remove),
index 4bbc0a79f01edf0139f6c1d10c587a82ff778fa9..8212b3c8bfdd90da61cfe426344c13aa6deadae8 100644 (file)
@@ -26,6 +26,7 @@
 #include <linux/platform_device.h>
 #include <linux/regulator/consumer.h>
 #include <linux/slab.h>
+#include <linux/of_device.h>
 
 #include <sound/core.h>
 #include <sound/pcm.h>
@@ -212,7 +213,7 @@ static int wm8580_out_vu(struct snd_kcontrol *kcontrol,
        reg_cache[reg] = 0;
        reg_cache[reg2] = 0;
 
-       ret = snd_soc_put_volsw_2r(kcontrol, ucontrol);
+       ret = snd_soc_put_volsw(kcontrol, ucontrol);
        if (ret < 0)
                return ret;
 
@@ -223,31 +224,19 @@ static int wm8580_out_vu(struct snd_kcontrol *kcontrol,
        return 0;
 }
 
-#define SOC_WM8580_OUT_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax, \
-                                   xinvert, tlv_array)                 \
-{      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
-       .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
-               SNDRV_CTL_ELEM_ACCESS_READWRITE,  \
-       .tlv.p = (tlv_array), \
-       .info = snd_soc_info_volsw_2r, \
-       .get = snd_soc_get_volsw_2r, .put = wm8580_out_vu, \
-       .private_value = (unsigned long)&(struct soc_mixer_control) \
-               {.reg = reg_left, .rreg = reg_right, .shift = xshift, \
-               .max = xmax, .invert = xinvert} }
-
 static const struct snd_kcontrol_new wm8580_snd_controls[] = {
-SOC_WM8580_OUT_DOUBLE_R_TLV("DAC1 Playback Volume",
-                           WM8580_DIGITAL_ATTENUATION_DACL1,
-                           WM8580_DIGITAL_ATTENUATION_DACR1,
-                           0, 0xff, 0, dac_tlv),
-SOC_WM8580_OUT_DOUBLE_R_TLV("DAC2 Playback Volume",
-                           WM8580_DIGITAL_ATTENUATION_DACL2,
-                           WM8580_DIGITAL_ATTENUATION_DACR2,
-                           0, 0xff, 0, dac_tlv),
-SOC_WM8580_OUT_DOUBLE_R_TLV("DAC3 Playback Volume",
-                           WM8580_DIGITAL_ATTENUATION_DACL3,
-                           WM8580_DIGITAL_ATTENUATION_DACR3,
-                           0, 0xff, 0, dac_tlv),
+SOC_DOUBLE_R_EXT_TLV("DAC1 Playback Volume",
+                    WM8580_DIGITAL_ATTENUATION_DACL1,
+                    WM8580_DIGITAL_ATTENUATION_DACR1,
+                    0, 0xff, 0, snd_soc_get_volsw, wm8580_out_vu, dac_tlv),
+SOC_DOUBLE_R_EXT_TLV("DAC2 Playback Volume",
+                    WM8580_DIGITAL_ATTENUATION_DACL2,
+                    WM8580_DIGITAL_ATTENUATION_DACR2,
+                    0, 0xff, 0, snd_soc_get_volsw, wm8580_out_vu, dac_tlv),
+SOC_DOUBLE_R_EXT_TLV("DAC3 Playback Volume",
+                    WM8580_DIGITAL_ATTENUATION_DACL3,
+                    WM8580_DIGITAL_ATTENUATION_DACR3,
+                    0, 0xff, 0, snd_soc_get_volsw, wm8580_out_vu, dac_tlv),
 
 SOC_SINGLE("DAC1 Deemphasis Switch", WM8580_DAC_CONTROL3, 0, 1, 0),
 SOC_SINGLE("DAC2 Deemphasis Switch", WM8580_DAC_CONTROL3, 1, 1, 0),
@@ -441,8 +430,7 @@ static int wm8580_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
        /* Always disable the PLL - it is not safe to leave it running
         * while reprogramming it.
         */
-       reg = snd_soc_read(codec, WM8580_PWRDN2);
-       snd_soc_write(codec, WM8580_PWRDN2, reg | pwr_mask);
+       snd_soc_update_bits(codec, WM8580_PWRDN2, pwr_mask, pwr_mask);
 
        if (!freq_in || !freq_out)
                return 0;
@@ -460,8 +448,7 @@ static int wm8580_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
        snd_soc_write(codec, WM8580_PLLA4 + offset, reg);
 
        /* All done, turn it on */
-       reg = snd_soc_read(codec, WM8580_PWRDN2);
-       snd_soc_write(codec, WM8580_PWRDN2, reg & ~pwr_mask);
+       snd_soc_update_bits(codec, WM8580_PWRDN2, pwr_mask, 0);
 
        return 0;
 }
@@ -759,7 +746,6 @@ static int wm8580_digital_mute(struct snd_soc_dai *codec_dai, int mute)
 static int wm8580_set_bias_level(struct snd_soc_codec *codec,
        enum snd_soc_bias_level level)
 {
-       u16 reg;
        switch (level) {
        case SND_SOC_BIAS_ON:
        case SND_SOC_BIAS_PREPARE:
@@ -768,20 +754,19 @@ static int wm8580_set_bias_level(struct snd_soc_codec *codec,
        case SND_SOC_BIAS_STANDBY:
                if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
                        /* Power up and get individual control of the DACs */
-                       reg = snd_soc_read(codec, WM8580_PWRDN1);
-                       reg &= ~(WM8580_PWRDN1_PWDN | WM8580_PWRDN1_ALLDACPD);
-                       snd_soc_write(codec, WM8580_PWRDN1, reg);
+                       snd_soc_update_bits(codec, WM8580_PWRDN1,
+                                           WM8580_PWRDN1_PWDN |
+                                           WM8580_PWRDN1_ALLDACPD, 0);
 
                        /* Make VMID high impedance */
-                       reg = snd_soc_read(codec,  WM8580_ADC_CONTROL1);
-                       reg &= ~0x100;
-                       snd_soc_write(codec, WM8580_ADC_CONTROL1, reg);
+                       snd_soc_update_bits(codec, WM8580_ADC_CONTROL1,
+                                           0x100, 0);
                }
                break;
 
        case SND_SOC_BIAS_OFF:
-               reg = snd_soc_read(codec, WM8580_PWRDN1);
-               snd_soc_write(codec, WM8580_PWRDN1, reg | WM8580_PWRDN1_PWDN);
+               snd_soc_update_bits(codec, WM8580_PWRDN1,
+                                   WM8580_PWRDN1_PWDN, WM8580_PWRDN1_PWDN);
                break;
        }
        codec->dapm.bias_level = level;
@@ -907,6 +892,11 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8580 = {
        .reg_cache_default = wm8580_reg,
 };
 
+static const struct of_device_id wm8580_of_match[] = {
+       { .compatible = "wlf,wm8580" },
+       { },
+};
+
 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
 static int wm8580_i2c_probe(struct i2c_client *i2c,
                            const struct i2c_device_id *id)
@@ -943,8 +933,9 @@ MODULE_DEVICE_TABLE(i2c, wm8580_i2c_id);
 
 static struct i2c_driver wm8580_i2c_driver = {
        .driver = {
-               .name = "wm8580-codec",
+               .name = "wm8580",
                .owner = THIS_MODULE,
+               .of_match_table = wm8580_of_match,
        },
        .probe =    wm8580_i2c_probe,
        .remove =   wm8580_i2c_remove,
index a537e4af6ae74efe7950d6a1806ee3942118a834..8d0347cf0e9a5747ca2c877a8135a012814d1d9d 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2006 Wolfson Microelectronics
  *
- * Author: Mike Arthur <linux@wolfsonmicro.com>
+ * Author: Mike Arthur <Mike.Arthur@wolfsonmicro.com>
  *
  * Based on wm8731.c by Richard Purdie
  *
@@ -21,6 +21,7 @@
 #include <linux/platform_device.h>
 #include <linux/spi/spi.h>
 #include <linux/slab.h>
+#include <linux/of_device.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
@@ -286,7 +287,6 @@ static int wm8711_set_dai_fmt(struct snd_soc_dai *codec_dai,
        return 0;
 }
 
-
 static int wm8711_set_bias_level(struct snd_soc_codec *codec,
        enum snd_soc_bias_level level)
 {
@@ -299,6 +299,9 @@ static int wm8711_set_bias_level(struct snd_soc_codec *codec,
        case SND_SOC_BIAS_PREPARE:
                break;
        case SND_SOC_BIAS_STANDBY:
+               if (codec->dapm.bias_level == SND_SOC_BIAS_OFF)
+                       snd_soc_cache_sync(codec);
+
                snd_soc_write(codec, WM8711_PWR, reg | 0x0040);
                break;
        case SND_SOC_BIAS_OFF:
@@ -345,25 +348,14 @@ static int wm8711_suspend(struct snd_soc_codec *codec, pm_message_t state)
 
 static int wm8711_resume(struct snd_soc_codec *codec)
 {
-       int i;
-       u8 data[2];
-       u16 *cache = codec->reg_cache;
-
-       /* Sync reg_cache with the hardware */
-       for (i = 0; i < ARRAY_SIZE(wm8711_reg); i++) {
-               data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
-               data[1] = cache[i] & 0x00ff;
-               codec->hw_write(codec->control_data, data, 2);
-       }
        wm8711_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-
        return 0;
 }
 
 static int wm8711_probe(struct snd_soc_codec *codec)
 {
        struct wm8711_priv *wm8711 = snd_soc_codec_get_drvdata(codec);
-       int ret, reg;
+       int ret;
 
        ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8711->bus_type);
        if (ret < 0) {
@@ -380,10 +372,8 @@ static int wm8711_probe(struct snd_soc_codec *codec)
        wm8711_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
        /* Latch the update bits */
-       reg = snd_soc_read(codec, WM8711_LOUT1V);
-       snd_soc_write(codec, WM8711_LOUT1V, reg | 0x0100);
-       reg = snd_soc_read(codec, WM8711_ROUT1V);
-       snd_soc_write(codec, WM8711_ROUT1V, reg | 0x0100);
+       snd_soc_update_bits(codec, WM8711_LOUT1V, 0x0100, 0x0100);
+       snd_soc_update_bits(codec, WM8711_ROUT1V, 0x0100, 0x0100);
 
        snd_soc_add_controls(codec, wm8711_snd_controls,
                             ARRAY_SIZE(wm8711_snd_controls));
@@ -414,6 +404,12 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8711 = {
        .num_dapm_routes = ARRAY_SIZE(wm8711_intercon),
 };
 
+static const struct of_device_id wm8711_of_match[] = {
+       { .compatible = "wlf,wm8711", },
+       { }
+};
+MODULE_DEVICE_TABLE(of, wm8711_of_match);
+
 #if defined(CONFIG_SPI_MASTER)
 static int __devinit wm8711_spi_probe(struct spi_device *spi)
 {
@@ -443,8 +439,9 @@ static int __devexit wm8711_spi_remove(struct spi_device *spi)
 
 static struct spi_driver wm8711_spi_driver = {
        .driver = {
-               .name   = "wm8711-codec",
+               .name   = "wm8711",
                .owner  = THIS_MODULE,
+               .of_match_table = wm8711_of_match,
        },
        .probe          = wm8711_spi_probe,
        .remove         = __devexit_p(wm8711_spi_remove),
@@ -487,8 +484,9 @@ MODULE_DEVICE_TABLE(i2c, wm8711_i2c_id);
 
 static struct i2c_driver wm8711_i2c_driver = {
        .driver = {
-               .name = "wm8711-codec",
+               .name = "wm8711",
                .owner = THIS_MODULE,
+               .of_match_table = wm8711_of_match,
        },
        .probe =    wm8711_i2c_probe,
        .remove =   __devexit_p(wm8711_i2c_remove),
index 86d4718d3a76055e46c1982e526855905c871ac9..04b027efd5c003df25769eb92e3ff7a74317a975 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/platform_device.h>
 #include <linux/spi/spi.h>
 #include <linux/slab.h>
+#include <linux/of_device.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
@@ -269,6 +270,12 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8728 = {
        .num_dapm_routes = ARRAY_SIZE(wm8728_intercon),
 };
 
+static const struct of_device_id wm8728_of_match[] = {
+       { .compatible = "wlf,wm8728", },
+       { }
+};
+MODULE_DEVICE_TABLE(of, wm8728_of_match);
+
 #if defined(CONFIG_SPI_MASTER)
 static int __devinit wm8728_spi_probe(struct spi_device *spi)
 {
@@ -298,8 +305,9 @@ static int __devexit wm8728_spi_remove(struct spi_device *spi)
 
 static struct spi_driver wm8728_spi_driver = {
        .driver = {
-               .name   = "wm8728-codec",
+               .name   = "wm8728",
                .owner  = THIS_MODULE,
+               .of_match_table = wm8728_of_match,
        },
        .probe          = wm8728_spi_probe,
        .remove         = __devexit_p(wm8728_spi_remove),
@@ -342,8 +350,9 @@ MODULE_DEVICE_TABLE(i2c, wm8728_i2c_id);
 
 static struct i2c_driver wm8728_i2c_driver = {
        .driver = {
-               .name = "wm8728-codec",
+               .name = "wm8728",
                .owner = THIS_MODULE,
+               .of_match_table = wm8728_of_match,
        },
        .probe =    wm8728_i2c_probe,
        .remove =   __devexit_p(wm8728_i2c_remove),
index 76b4361e9b8042c112a32b14b290304e17761604..7e5ec03f6f8dd579d1bd43413fd1d007a1989bcb 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/platform_device.h>
 #include <linux/regulator/consumer.h>
 #include <linux/spi/spi.h>
+#include <linux/of_device.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
@@ -426,9 +427,7 @@ static int wm8731_set_bias_level(struct snd_soc_codec *codec,
                                 enum snd_soc_bias_level level)
 {
        struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
-       int i, ret;
-       u8 data[2];
-       u16 *cache = codec->reg_cache;
+       int ret;
        u16 reg;
 
        switch (level) {
@@ -443,16 +442,7 @@ static int wm8731_set_bias_level(struct snd_soc_codec *codec,
                        if (ret != 0)
                                return ret;
 
-                       /* Sync reg_cache with the hardware */
-                       for (i = 0; i < ARRAY_SIZE(wm8731_reg); i++) {
-                               if (cache[i] == wm8731_reg[i])
-                                       continue;
-
-                               data[0] = (i << 1) | ((cache[i] >> 8)
-                                                     & 0x0001);
-                               data[1] = cache[i] & 0x00ff;
-                               codec->hw_write(codec->control_data, data, 2);
-                       }
+                       snd_soc_cache_sync(codec);
                }
 
                /* Clear PWROFF, gate CLKOUT, everything else as-is */
@@ -607,6 +597,13 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8731 = {
        .num_dapm_routes = ARRAY_SIZE(wm8731_intercon),
 };
 
+static const struct of_device_id wm8731_of_match[] = {
+       { .compatible = "wlf,wm8731", },
+       { }
+};
+
+MODULE_DEVICE_TABLE(of, wm8731_of_match);
+
 #if defined(CONFIG_SPI_MASTER)
 static int __devinit wm8731_spi_probe(struct spi_device *spi)
 {
@@ -638,6 +635,7 @@ static struct spi_driver wm8731_spi_driver = {
        .driver = {
                .name   = "wm8731",
                .owner  = THIS_MODULE,
+               .of_match_table = wm8731_of_match,
        },
        .probe          = wm8731_spi_probe,
        .remove         = __devexit_p(wm8731_spi_remove),
@@ -682,6 +680,7 @@ static struct i2c_driver wm8731_i2c_driver = {
        .driver = {
                .name = "wm8731",
                .owner = THIS_MODULE,
+               .of_match_table = wm8731_of_match,
        },
        .probe =    wm8731_i2c_probe,
        .remove =   __devexit_p(wm8731_i2c_remove),
index 30c67d06a9043988f1a84ed6f4780b7c2502dbc3..f6aef58845c2dc31880529cdaa9510a96735e334 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/regulator/consumer.h>
 #include <linux/spi/spi.h>
 #include <linux/slab.h>
+#include <linux/of_device.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
@@ -634,6 +635,13 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8737 = {
        .reg_cache_default = wm8737_reg,
 };
 
+static const struct of_device_id wm8737_of_match[] = {
+       { .compatible = "wlf,wm8737", },
+       { }
+};
+
+MODULE_DEVICE_TABLE(of, wm8737_of_match);
+
 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
 static __devinit int wm8737_i2c_probe(struct i2c_client *i2c,
                                      const struct i2c_device_id *id)
@@ -673,6 +681,7 @@ static struct i2c_driver wm8737_i2c_driver = {
        .driver = {
                .name = "wm8737",
                .owner = THIS_MODULE,
+               .of_match_table = wm8737_of_match,
        },
        .probe =    wm8737_i2c_probe,
        .remove =   __devexit_p(wm8737_i2c_remove),
@@ -711,6 +720,7 @@ static struct spi_driver wm8737_spi_driver = {
        .driver = {
                .name   = "wm8737",
                .owner  = THIS_MODULE,
+               .of_match_table = wm8737_of_match,
        },
        .probe          = wm8737_spi_probe,
        .remove         = __devexit_p(wm8737_spi_remove),
index 25af901fe8133029e7efe35914c07e02105e4085..57ad22aacc516dc17e18042a98712266f761afa3 100644 (file)
 #include <linux/delay.h>
 #include <linux/pm.h>
 #include <linux/i2c.h>
+#include <linux/spi/spi.h>
 #include <linux/platform_device.h>
 #include <linux/regulator/consumer.h>
 #include <linux/slab.h>
+#include <linux/of_device.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
@@ -337,10 +339,10 @@ static int wm8741_set_dai_fmt(struct snd_soc_dai *codec_dai,
                iface |= 0x0004;
                break;
        case SND_SOC_DAIFMT_DSP_A:
-               iface |= 0x0003;
+               iface |= 0x000C;
                break;
        case SND_SOC_DAIFMT_DSP_B:
-               iface |= 0x0013;
+               iface |= 0x001C;
                break;
        default:
                return -EINVAL;
@@ -402,15 +404,7 @@ static struct snd_soc_dai_driver wm8741_dai = {
 #ifdef CONFIG_PM
 static int wm8741_resume(struct snd_soc_codec *codec)
 {
-       u16 *cache = codec->reg_cache;
-       int i;
-
-       /* RESTORE REG Cache */
-       for (i = 0; i < WM8741_REGISTER_COUNT; i++) {
-               if (cache[i] == wm8741_reg_defaults[i] || WM8741_RESET == i)
-                       continue;
-               snd_soc_write(codec, i, cache[i]);
-       }
+       snd_soc_cache_sync(codec);
        return 0;
 }
 #else
@@ -422,17 +416,35 @@ static int wm8741_probe(struct snd_soc_codec *codec)
 {
        struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec);
        int ret = 0;
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(wm8741->supplies); i++)
+               wm8741->supplies[i].supply = wm8741_supply_names[i];
+
+       ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(wm8741->supplies),
+                                wm8741->supplies);
+       if (ret != 0) {
+               dev_err(codec->dev, "Failed to request supplies: %d\n", ret);
+               goto err;
+       }
+
+       ret = regulator_bulk_enable(ARRAY_SIZE(wm8741->supplies),
+                                   wm8741->supplies);
+       if (ret != 0) {
+               dev_err(codec->dev, "Failed to enable supplies: %d\n", ret);
+               goto err_get;
+       }
 
        ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8741->control_type);
        if (ret != 0) {
                dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
-               return ret;
+               goto err_enable;
        }
 
        ret = wm8741_reset(codec);
        if (ret < 0) {
                dev_err(codec->dev, "Failed to issue reset\n");
-               return ret;
+               goto err_enable;
        }
 
        /* Change some default settings - latch VU */
@@ -442,7 +454,7 @@ static int wm8741_probe(struct snd_soc_codec *codec)
                            WM8741_UPDATELM, WM8741_UPDATELM);
        snd_soc_update_bits(codec, WM8741_DACRLSB_ATTENUATION,
                            WM8741_UPDATERL, WM8741_UPDATERL);
-       snd_soc_update_bits(codec, WM8741_DACRLSB_ATTENUATION,
+       snd_soc_update_bits(codec, WM8741_DACRMSB_ATTENUATION,
                            WM8741_UPDATERM, WM8741_UPDATERM);
 
        snd_soc_add_controls(codec, wm8741_snd_controls,
@@ -451,58 +463,61 @@ static int wm8741_probe(struct snd_soc_codec *codec)
 
        dev_dbg(codec->dev, "Successful registration\n");
        return ret;
+
+err_enable:
+       regulator_bulk_disable(ARRAY_SIZE(wm8741->supplies), wm8741->supplies);
+err_get:
+       regulator_bulk_free(ARRAY_SIZE(wm8741->supplies), wm8741->supplies);
+err:
+       return ret;
+}
+
+static int wm8741_remove(struct snd_soc_codec *codec)
+{
+       struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec);
+
+       regulator_bulk_disable(ARRAY_SIZE(wm8741->supplies), wm8741->supplies);
+       regulator_bulk_free(ARRAY_SIZE(wm8741->supplies), wm8741->supplies);
+
+       return 0;
 }
 
 static struct snd_soc_codec_driver soc_codec_dev_wm8741 = {
        .probe =        wm8741_probe,
+       .remove =       wm8741_remove,
        .resume =       wm8741_resume,
        .reg_cache_size = ARRAY_SIZE(wm8741_reg_defaults),
        .reg_word_size = sizeof(u16),
        .reg_cache_default = wm8741_reg_defaults,
 };
 
+static const struct of_device_id wm8741_of_match[] = {
+       { .compatible = "wlf,wm8741", },
+       { }
+};
+MODULE_DEVICE_TABLE(of, wm8741_of_match);
+
 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
 static int wm8741_i2c_probe(struct i2c_client *i2c,
                            const struct i2c_device_id *id)
 {
        struct wm8741_priv *wm8741;
-       int ret, i;
+       int ret;
 
        wm8741 = kzalloc(sizeof(struct wm8741_priv), GFP_KERNEL);
        if (wm8741 == NULL)
                return -ENOMEM;
 
-       for (i = 0; i < ARRAY_SIZE(wm8741->supplies); i++)
-               wm8741->supplies[i].supply = wm8741_supply_names[i];
-
-       ret = regulator_bulk_get(&i2c->dev, ARRAY_SIZE(wm8741->supplies),
-                                wm8741->supplies);
-       if (ret != 0) {
-               dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret);
-               goto err;
-       }
-
-       ret = regulator_bulk_enable(ARRAY_SIZE(wm8741->supplies),
-                                   wm8741->supplies);
-       if (ret != 0) {
-               dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret);
-               goto err_get;
-       }
-
        i2c_set_clientdata(i2c, wm8741);
        wm8741->control_type = SND_SOC_I2C;
 
-       ret =  snd_soc_register_codec(&i2c->dev,
-                       &soc_codec_dev_wm8741, &wm8741_dai, 1);
-       if (ret < 0)
-               goto err_enable;
-       return ret;
+       ret = snd_soc_register_codec(&i2c->dev,
+                                    &soc_codec_dev_wm8741, &wm8741_dai, 1);
+       if (ret != 0)
+               goto err;
 
-err_enable:
-       regulator_bulk_disable(ARRAY_SIZE(wm8741->supplies), wm8741->supplies);
+       return ret;
 
-err_get:
-       regulator_bulk_free(ARRAY_SIZE(wm8741->supplies), wm8741->supplies);
 err:
        kfree(wm8741);
        return ret;
@@ -510,10 +525,7 @@ err:
 
 static int wm8741_i2c_remove(struct i2c_client *client)
 {
-       struct wm8741_priv *wm8741 = i2c_get_clientdata(client);
-
        snd_soc_unregister_codec(&client->dev);
-       regulator_bulk_free(ARRAY_SIZE(wm8741->supplies), wm8741->supplies);
        kfree(i2c_get_clientdata(client));
        return 0;
 }
@@ -526,8 +538,9 @@ MODULE_DEVICE_TABLE(i2c, wm8741_i2c_id);
 
 static struct i2c_driver wm8741_i2c_driver = {
        .driver = {
-               .name = "wm8741-codec",
+               .name = "wm8741",
                .owner = THIS_MODULE,
+               .of_match_table = wm8741_of_match,
        },
        .probe =    wm8741_i2c_probe,
        .remove =   wm8741_i2c_remove,
@@ -535,6 +548,44 @@ static struct i2c_driver wm8741_i2c_driver = {
 };
 #endif
 
+#if defined(CONFIG_SPI_MASTER)
+static int __devinit wm8741_spi_probe(struct spi_device *spi)
+{
+       struct wm8741_priv *wm8741;
+       int ret;
+
+       wm8741 = kzalloc(sizeof(struct wm8741_priv), GFP_KERNEL);
+       if (wm8741 == NULL)
+               return -ENOMEM;
+
+       wm8741->control_type = SND_SOC_SPI;
+       spi_set_drvdata(spi, wm8741);
+
+       ret = snd_soc_register_codec(&spi->dev,
+                       &soc_codec_dev_wm8741, &wm8741_dai, 1);
+       if (ret < 0)
+               kfree(wm8741);
+       return ret;
+}
+
+static int __devexit wm8741_spi_remove(struct spi_device *spi)
+{
+       snd_soc_unregister_codec(&spi->dev);
+       kfree(spi_get_drvdata(spi));
+       return 0;
+}
+
+static struct spi_driver wm8741_spi_driver = {
+       .driver = {
+               .name   = "wm8741",
+               .owner  = THIS_MODULE,
+               .of_match_table = wm8741_of_match,
+       },
+       .probe          = wm8741_spi_probe,
+       .remove         = __devexit_p(wm8741_spi_remove),
+};
+#endif /* CONFIG_SPI_MASTER */
+
 static int __init wm8741_modinit(void)
 {
        int ret = 0;
@@ -544,6 +595,13 @@ static int __init wm8741_modinit(void)
        if (ret != 0)
                pr_err("Failed to register WM8741 I2C driver: %d\n", ret);
 #endif
+#if defined(CONFIG_SPI_MASTER)
+       ret = spi_register_driver(&wm8741_spi_driver);
+       if (ret != 0) {
+               printk(KERN_ERR "Failed to register wm8741 SPI driver: %d\n",
+                      ret);
+       }
+#endif
 
        return ret;
 }
@@ -551,6 +609,9 @@ module_init(wm8741_modinit);
 
 static void __exit wm8741_exit(void)
 {
+#if defined(CONFIG_SPI_MASTER)
+       spi_unregister_driver(&wm8741_spi_driver);
+#endif
 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
        i2c_del_driver(&wm8741_i2c_driver);
 #endif
index d0003cc3bcd66cf16336bec69cc0f75b4de97a56..ca75a818070804610d0b7c0d10554e48cbf2f1bd 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/platform_device.h>
 #include <linux/spi/spi.h>
 #include <linux/slab.h>
+#include <linux/of_device.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
@@ -615,6 +616,8 @@ static int wm8750_set_bias_level(struct snd_soc_codec *codec,
                break;
        case SND_SOC_BIAS_STANDBY:
                if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
+                       snd_soc_cache_sync(codec);
+
                        /* Set VMID to 5k */
                        snd_soc_write(codec, WM8750_PWR1, pwr_reg | 0x01c1);
 
@@ -672,28 +675,14 @@ static int wm8750_suspend(struct snd_soc_codec *codec, pm_message_t state)
 
 static int wm8750_resume(struct snd_soc_codec *codec)
 {
-       int i;
-       u8 data[2];
-       u16 *cache = codec->reg_cache;
-
-       /* Sync reg_cache with the hardware */
-       for (i = 0; i < ARRAY_SIZE(wm8750_reg); i++) {
-               if (i == WM8750_RESET)
-                       continue;
-               data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
-               data[1] = cache[i] & 0x00ff;
-               codec->hw_write(codec->control_data, data, 2);
-       }
-
        wm8750_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-
        return 0;
 }
 
 static int wm8750_probe(struct snd_soc_codec *codec)
 {
        struct wm8750_priv *wm8750 = snd_soc_codec_get_drvdata(codec);
-       int reg, ret;
+       int ret;
 
        ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8750->control_type);
        if (ret < 0) {
@@ -711,22 +700,14 @@ static int wm8750_probe(struct snd_soc_codec *codec)
        wm8750_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
        /* set the update bits */
-       reg = snd_soc_read(codec, WM8750_LDAC);
-       snd_soc_write(codec, WM8750_LDAC, reg | 0x0100);
-       reg = snd_soc_read(codec, WM8750_RDAC);
-       snd_soc_write(codec, WM8750_RDAC, reg | 0x0100);
-       reg = snd_soc_read(codec, WM8750_LOUT1V);
-       snd_soc_write(codec, WM8750_LOUT1V, reg | 0x0100);
-       reg = snd_soc_read(codec, WM8750_ROUT1V);
-       snd_soc_write(codec, WM8750_ROUT1V, reg | 0x0100);
-       reg = snd_soc_read(codec, WM8750_LOUT2V);
-       snd_soc_write(codec, WM8750_LOUT2V, reg | 0x0100);
-       reg = snd_soc_read(codec, WM8750_ROUT2V);
-       snd_soc_write(codec, WM8750_ROUT2V, reg | 0x0100);
-       reg = snd_soc_read(codec, WM8750_LINVOL);
-       snd_soc_write(codec, WM8750_LINVOL, reg | 0x0100);
-       reg = snd_soc_read(codec, WM8750_RINVOL);
-       snd_soc_write(codec, WM8750_RINVOL, reg | 0x0100);
+       snd_soc_update_bits(codec, WM8750_LDAC, 0x0100, 0x0100);
+       snd_soc_update_bits(codec, WM8750_RDAC, 0x0100, 0x0100);
+       snd_soc_update_bits(codec, WM8750_LOUT1V, 0x0100, 0x0100);
+       snd_soc_update_bits(codec, WM8750_ROUT1V, 0x0100, 0x0100);
+       snd_soc_update_bits(codec, WM8750_LOUT2V, 0x0100, 0x0100);
+       snd_soc_update_bits(codec, WM8750_ROUT2V, 0x0100, 0x0100);
+       snd_soc_update_bits(codec, WM8750_LINVOL, 0x0100, 0x0100);
+       snd_soc_update_bits(codec, WM8750_RINVOL, 0x0100, 0x0100);
 
        snd_soc_add_controls(codec, wm8750_snd_controls,
                                ARRAY_SIZE(wm8750_snd_controls));
@@ -751,6 +732,13 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8750 = {
        .reg_cache_default = wm8750_reg,
 };
 
+static const struct of_device_id wm8750_of_match[] = {
+       { .compatible = "wlf,wm8750", },
+       { .compatible = "wlf,wm8987", },
+       { }
+};
+MODULE_DEVICE_TABLE(of, wm8750_of_match);
+
 #if defined(CONFIG_SPI_MASTER)
 static int __devinit wm8750_spi_probe(struct spi_device *spi)
 {
@@ -787,8 +775,9 @@ MODULE_DEVICE_TABLE(spi, wm8750_spi_ids);
 
 static struct spi_driver wm8750_spi_driver = {
        .driver = {
-               .name   = "wm8750-codec",
+               .name   = "wm8750",
                .owner  = THIS_MODULE,
+               .of_match_table = wm8750_of_match,
        },
        .id_table       = wm8750_spi_ids,
        .probe          = wm8750_spi_probe,
@@ -833,8 +822,9 @@ MODULE_DEVICE_TABLE(i2c, wm8750_i2c_id);
 
 static struct i2c_driver wm8750_i2c_driver = {
        .driver = {
-               .name = "wm8750-codec",
+               .name = "wm8750",
                .owner = THIS_MODULE,
+               .of_match_table = wm8750_of_match,
        },
        .probe =    wm8750_i2c_probe,
        .remove =   __devexit_p(wm8750_i2c_remove),
index aa091a0d81873b9f09ceeb30bf7dcd46f6d05cd1..a9504710bb692e806655e785e5f35121ecf4afc1 100644 (file)
@@ -38,6 +38,7 @@
 #include <linux/delay.h>
 #include <linux/pm.h>
 #include <linux/i2c.h>
+#include <linux/of_device.h>
 #include <linux/platform_device.h>
 #include <linux/spi/spi.h>
 #include <linux/slab.h>
@@ -1490,6 +1491,12 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8753 = {
        .reg_cache_default = wm8753_reg,
 };
 
+static const struct of_device_id wm8753_of_match[] = {
+       { .compatible = "wlf,wm8753", },
+       { }
+};
+MODULE_DEVICE_TABLE(of, wm8753_of_match);
+
 #if defined(CONFIG_SPI_MASTER)
 static int __devinit wm8753_spi_probe(struct spi_device *spi)
 {
@@ -1519,8 +1526,9 @@ static int __devexit wm8753_spi_remove(struct spi_device *spi)
 
 static struct spi_driver wm8753_spi_driver = {
        .driver = {
-               .name   = "wm8753-codec",
+               .name   = "wm8753",
                .owner  = THIS_MODULE,
+               .of_match_table = wm8753_of_match,
        },
        .probe          = wm8753_spi_probe,
        .remove         = __devexit_p(wm8753_spi_remove),
@@ -1563,8 +1571,9 @@ MODULE_DEVICE_TABLE(i2c, wm8753_i2c_id);
 
 static struct i2c_driver wm8753_i2c_driver = {
        .driver = {
-               .name = "wm8753-codec",
+               .name = "wm8753",
                .owner = THIS_MODULE,
+               .of_match_table = wm8753_of_match,
        },
        .probe =    wm8753_i2c_probe,
        .remove =   __devexit_p(wm8753_i2c_remove),
index 19b92baa9e8c480c7a07b479c95d0f94f62ef4ae..aa05e6507f844a2ac90c970e939a92efc9de0ff7 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/moduleparam.h>
 #include <linux/init.h>
 #include <linux/delay.h>
+#include <linux/of_device.h>
 #include <linux/pm.h>
 #include <linux/platform_device.h>
 #include <linux/spi/spi.h>
@@ -684,6 +685,12 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8770 = {
        .reg_cache_default = wm8770_reg_defs
 };
 
+static const struct of_device_id wm8770_of_match[] = {
+       { .compatible = "wlf,wm8770", },
+       { }
+};
+MODULE_DEVICE_TABLE(of, wm8770_of_match);
+
 #if defined(CONFIG_SPI_MASTER)
 static int __devinit wm8770_spi_probe(struct spi_device *spi)
 {
@@ -715,6 +722,7 @@ static struct spi_driver wm8770_spi_driver = {
        .driver = {
                .name = "wm8770",
                .owner = THIS_MODULE,
+               .of_match_table = wm8770_of_match,
        },
        .probe = wm8770_spi_probe,
        .remove = __devexit_p(wm8770_spi_remove)
index 8e7953b1b790161a8a394b0b10a7b7d8a160487a..bfdc52370ad02de96bd9cf1859614db91e682949 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/delay.h>
 #include <linux/pm.h>
 #include <linux/i2c.h>
+#include <linux/of_device.h>
 #include <linux/platform_device.h>
 #include <linux/spi/spi.h>
 #include <linux/slab.h>
@@ -215,8 +216,6 @@ static int wm8776_hw_params(struct snd_pcm_substream *substream,
        int ratio_shift, master;
        int i;
 
-       iface = 0;
-
        switch (dai->driver->id) {
        case WM8776_DAI_DAC:
                iface_reg = WM8776_DACIFCTRL;
@@ -232,20 +231,23 @@ static int wm8776_hw_params(struct snd_pcm_substream *substream,
                return -EINVAL;
        }
 
-
        /* Set word length */
-       switch (params_format(params)) {
-       case SNDRV_PCM_FORMAT_S16_LE:
-               break;
-       case SNDRV_PCM_FORMAT_S20_3LE:
-               iface |= 0x10;
+       switch (snd_pcm_format_width(params_format(params))) {
+       case 16:
+               iface = 0;
+       case 20:
+               iface = 0x10;
                break;
-       case SNDRV_PCM_FORMAT_S24_LE:
-               iface |= 0x20;
+       case 24:
+               iface = 0x20;
                break;
-       case SNDRV_PCM_FORMAT_S32_LE:
-               iface |= 0x30;
+       case 32:
+               iface = 0x30;
                break;
+       default:
+               dev_err(codec->dev, "Unsupported sample size: %i\n",
+                       snd_pcm_format_width(params_format(params)));
+               return -EINVAL;
        }
 
        /* Only need to set MCLK/LRCLK ratio if we're master */
@@ -306,6 +308,8 @@ static int wm8776_set_bias_level(struct snd_soc_codec *codec,
                break;
        case SND_SOC_BIAS_STANDBY:
                if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
+                       snd_soc_cache_sync(codec);
+
                        /* Disable the global powerdown; DAPM does the rest */
                        snd_soc_update_bits(codec, WM8776_PWRDOWN, 1, 0);
                }
@@ -320,11 +324,6 @@ static int wm8776_set_bias_level(struct snd_soc_codec *codec,
        return 0;
 }
 
-#define WM8776_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\
-                     SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 |\
-                     SNDRV_PCM_RATE_96000)
-
-
 #define WM8776_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
                        SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
 
@@ -349,7 +348,9 @@ static struct snd_soc_dai_driver wm8776_dai[] = {
                        .stream_name = "Playback",
                        .channels_min = 2,
                        .channels_max = 2,
-                       .rates = WM8776_RATES,
+                       .rates = SNDRV_PCM_RATE_CONTINUOUS,
+                       .rate_min = 32000,
+                       .rate_max = 192000,
                        .formats = WM8776_FORMATS,
                },
                .ops = &wm8776_dac_ops,
@@ -361,7 +362,9 @@ static struct snd_soc_dai_driver wm8776_dai[] = {
                        .stream_name = "Capture",
                        .channels_min = 2,
                        .channels_max = 2,
-                       .rates = WM8776_RATES,
+                       .rates = SNDRV_PCM_RATE_CONTINUOUS,
+                       .rate_min = 32000,
+                       .rate_max = 96000,
                        .formats = WM8776_FORMATS,
                },
                .ops = &wm8776_adc_ops,
@@ -378,21 +381,7 @@ static int wm8776_suspend(struct snd_soc_codec *codec, pm_message_t state)
 
 static int wm8776_resume(struct snd_soc_codec *codec)
 {
-       int i;
-       u8 data[2];
-       u16 *cache = codec->reg_cache;
-
-       /* Sync reg_cache with the hardware */
-       for (i = 0; i < ARRAY_SIZE(wm8776_reg); i++) {
-               if (cache[i] == wm8776_reg[i])
-                       continue;
-               data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
-               data[1] = cache[i] & 0x00ff;
-               codec->hw_write(codec->control_data, data, 2);
-       }
-
        wm8776_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-
        return 0;
 }
 #else
@@ -452,6 +441,12 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8776 = {
        .reg_cache_default = wm8776_reg,
 };
 
+static const struct of_device_id wm8776_of_match[] = {
+       { .compatible = "wlf,wm8776", },
+       { }
+};
+MODULE_DEVICE_TABLE(of, wm8776_of_match);
+
 #if defined(CONFIG_SPI_MASTER)
 static int __devinit wm8776_spi_probe(struct spi_device *spi)
 {
@@ -481,8 +476,9 @@ static int __devexit wm8776_spi_remove(struct spi_device *spi)
 
 static struct spi_driver wm8776_spi_driver = {
        .driver = {
-               .name   = "wm8776-codec",
+               .name   = "wm8776",
                .owner  = THIS_MODULE,
+               .of_match_table = wm8776_of_match,
        },
        .probe          = wm8776_spi_probe,
        .remove         = __devexit_p(wm8776_spi_remove),
@@ -525,8 +521,9 @@ MODULE_DEVICE_TABLE(i2c, wm8776_i2c_id);
 
 static struct i2c_driver wm8776_i2c_driver = {
        .driver = {
-               .name = "wm8776-codec",
+               .name = "wm8776",
                .owner = THIS_MODULE,
+               .of_match_table = wm8776_of_match,
        },
        .probe =    wm8776_i2c_probe,
        .remove =   __devexit_p(wm8776_i2c_remove),
index a2a09f85ea9903aba9012ca64e54bff43254c494..f2ced71328b0a6cc7ee073a4099fd6fd6afe5b15 100644 (file)
@@ -60,7 +60,7 @@ static struct platform_driver wm8782_codec_driver = {
                .owner = THIS_MODULE,
        },
        .probe = wm8782_probe,
-       .remove = wm8782_remove,
+       .remove = __devexit_p(wm8782_remove),
 };
 
 static int __init wm8782_init(void)
index 9a5e67c5a6bdf9f2cc7fc5a23b49a8c76a0f462e..9ee072b859751ac16b3163c0f5a33833e5eb878a 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/delay.h>
 #include <linux/pm.h>
 #include <linux/i2c.h>
+#include <linux/of_device.h>
 #include <linux/spi/spi.h>
 #include <linux/regulator/consumer.h>
 #include <linux/slab.h>
@@ -717,6 +718,12 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8804 = {
        .volatile_register = wm8804_volatile
 };
 
+static const struct of_device_id wm8804_of_match[] = {
+       { .compatible = "wlf,wm8804", },
+       { }
+};
+MODULE_DEVICE_TABLE(of, wm8804_of_match);
+
 #if defined(CONFIG_SPI_MASTER)
 static int __devinit wm8804_spi_probe(struct spi_device *spi)
 {
@@ -748,6 +755,7 @@ static struct spi_driver wm8804_spi_driver = {
        .driver = {
                .name = "wm8804",
                .owner = THIS_MODULE,
+               .of_match_table = wm8804_of_match,
        },
        .probe = wm8804_spi_probe,
        .remove = __devexit_p(wm8804_spi_remove)
@@ -792,6 +800,7 @@ static struct i2c_driver wm8804_i2c_driver = {
        .driver = {
                .name = "wm8804",
                .owner = THIS_MODULE,
+               .of_match_table = wm8804_of_match,
        },
        .probe = wm8804_i2c_probe,
        .remove = __devexit_p(wm8804_i2c_remove),
index 082040eda8a22817f1944cfcfa8af5742fa89d19..3d0dc1591eccda191057f2d957823ebb79f55b1e 100644 (file)
 
 #define WM8900_REG_CLOCKING1_BCLK_DIR   0x1
 #define WM8900_REG_CLOCKING1_MCLK_SRC   0x100
-#define WM8900_REG_CLOCKING1_BCLK_MASK  (~0x01e)
-#define WM8900_REG_CLOCKING1_OPCLK_MASK (~0x7000)
+#define WM8900_REG_CLOCKING1_BCLK_MASK  0x01e
+#define WM8900_REG_CLOCKING1_OPCLK_MASK 0x7000
 
 #define WM8900_REG_CLOCKING2_ADC_CLKDIV 0xe0
 #define WM8900_REG_CLOCKING2_DAC_CLKDIV 0x1c
 #define WM8900_REG_HPCTL1_HP_SHORT       0x08
 #define WM8900_REG_HPCTL1_HP_SHORT2      0x04
 
-#define WM8900_LRC_MASK 0xfc00
+#define WM8900_LRC_MASK 0x03ff
 
 struct wm8900_priv {
        enum snd_soc_control_type control_type;
@@ -742,26 +742,20 @@ static int wm8900_set_fll(struct snd_soc_codec *codec,
 {
        struct wm8900_priv *wm8900 = snd_soc_codec_get_drvdata(codec);
        struct _fll_div fll_div;
-       unsigned int reg;
 
        if (wm8900->fll_in == freq_in && wm8900->fll_out == freq_out)
                return 0;
 
        /* The digital side should be disabled during any change. */
-       reg = snd_soc_read(codec, WM8900_REG_POWER1);
-       snd_soc_write(codec, WM8900_REG_POWER1,
-                    reg & (~WM8900_REG_POWER1_FLL_ENA));
+       snd_soc_update_bits(codec, WM8900_REG_POWER1,
+                           WM8900_REG_POWER1_FLL_ENA, 0);
 
        /* Disable the FLL? */
        if (!freq_in || !freq_out) {
-               reg = snd_soc_read(codec, WM8900_REG_CLOCKING1);
-               snd_soc_write(codec, WM8900_REG_CLOCKING1,
-                            reg & (~WM8900_REG_CLOCKING1_MCLK_SRC));
-
-               reg = snd_soc_read(codec, WM8900_REG_FLLCTL1);
-               snd_soc_write(codec, WM8900_REG_FLLCTL1,
-                            reg & (~WM8900_REG_FLLCTL1_OSC_ENA));
-
+               snd_soc_update_bits(codec, WM8900_REG_CLOCKING1,
+                                   WM8900_REG_CLOCKING1_MCLK_SRC, 0);
+               snd_soc_update_bits(codec, WM8900_REG_FLLCTL1,
+                                   WM8900_REG_FLLCTL1_OSC_ENA, 0);
                wm8900->fll_in = freq_in;
                wm8900->fll_out = freq_out;
 
@@ -796,15 +790,14 @@ static int wm8900_set_fll(struct snd_soc_codec *codec,
        else
                snd_soc_write(codec, WM8900_REG_FLLCTL6, 0);
 
-       reg = snd_soc_read(codec, WM8900_REG_POWER1);
-       snd_soc_write(codec, WM8900_REG_POWER1,
-                    reg | WM8900_REG_POWER1_FLL_ENA);
+       snd_soc_update_bits(codec, WM8900_REG_POWER1,
+                           WM8900_REG_POWER1_FLL_ENA,
+                           WM8900_REG_POWER1_FLL_ENA);
 
 reenable:
-       reg = snd_soc_read(codec, WM8900_REG_CLOCKING1);
-       snd_soc_write(codec, WM8900_REG_CLOCKING1,
-                    reg | WM8900_REG_CLOCKING1_MCLK_SRC);
-
+       snd_soc_update_bits(codec, WM8900_REG_CLOCKING1,
+                           WM8900_REG_CLOCKING1_MCLK_SRC,
+                           WM8900_REG_CLOCKING1_MCLK_SRC);
        return 0;
 }
 
@@ -818,43 +811,35 @@ static int wm8900_set_dai_clkdiv(struct snd_soc_dai *codec_dai,
                                 int div_id, int div)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       unsigned int reg;
 
        switch (div_id) {
        case WM8900_BCLK_DIV:
-               reg = snd_soc_read(codec, WM8900_REG_CLOCKING1);
-               snd_soc_write(codec, WM8900_REG_CLOCKING1,
-                            div | (reg & WM8900_REG_CLOCKING1_BCLK_MASK));
+               snd_soc_update_bits(codec, WM8900_REG_CLOCKING1,
+                                   WM8900_REG_CLOCKING1_BCLK_MASK, div);
                break;
        case WM8900_OPCLK_DIV:
-               reg = snd_soc_read(codec, WM8900_REG_CLOCKING1);
-               snd_soc_write(codec, WM8900_REG_CLOCKING1,
-                            div | (reg & WM8900_REG_CLOCKING1_OPCLK_MASK));
+               snd_soc_update_bits(codec, WM8900_REG_CLOCKING1,
+                                   WM8900_REG_CLOCKING1_OPCLK_MASK, div);
                break;
        case WM8900_DAC_LRCLK:
-               reg = snd_soc_read(codec, WM8900_REG_AUDIO4);
-               snd_soc_write(codec, WM8900_REG_AUDIO4,
-                            div | (reg & WM8900_LRC_MASK));
+               snd_soc_update_bits(codec, WM8900_REG_AUDIO4,
+                                   WM8900_LRC_MASK, div);
                break;
        case WM8900_ADC_LRCLK:
-               reg = snd_soc_read(codec, WM8900_REG_AUDIO3);
-               snd_soc_write(codec, WM8900_REG_AUDIO3,
-                            div | (reg & WM8900_LRC_MASK));
+               snd_soc_update_bits(codec, WM8900_REG_AUDIO3,
+                                   WM8900_LRC_MASK, div);
                break;
        case WM8900_DAC_CLKDIV:
-               reg = snd_soc_read(codec, WM8900_REG_CLOCKING2);
-               snd_soc_write(codec, WM8900_REG_CLOCKING2,
-                            div | (reg & WM8900_REG_CLOCKING2_DAC_CLKDIV));
+               snd_soc_update_bits(codec, WM8900_REG_CLOCKING2,
+                                   WM8900_REG_CLOCKING2_DAC_CLKDIV, div);
                break;
        case WM8900_ADC_CLKDIV:
-               reg = snd_soc_read(codec, WM8900_REG_CLOCKING2);
-               snd_soc_write(codec, WM8900_REG_CLOCKING2,
-                            div | (reg & WM8900_REG_CLOCKING2_ADC_CLKDIV));
+               snd_soc_update_bits(codec, WM8900_REG_CLOCKING2,
+                                   WM8900_REG_CLOCKING2_ADC_CLKDIV, div);
                break;
        case WM8900_LRCLK_MODE:
-               reg = snd_soc_read(codec, WM8900_REG_DACCTRL);
-               snd_soc_write(codec, WM8900_REG_DACCTRL,
-                            div | (reg & WM8900_REG_DACCTRL_AIF_LRCLKRATE));
+               snd_soc_update_bits(codec, WM8900_REG_DACCTRL,
+                                   WM8900_REG_DACCTRL_AIF_LRCLKRATE, div);
                break;
        default:
                return -EINVAL;
@@ -1037,12 +1022,12 @@ static int wm8900_set_bias_level(struct snd_soc_codec *codec,
        switch (level) {
        case SND_SOC_BIAS_ON:
                /* Enable thermal shutdown */
-               reg = snd_soc_read(codec, WM8900_REG_GPIO);
-               snd_soc_write(codec, WM8900_REG_GPIO,
-                            reg | WM8900_REG_GPIO_TEMP_ENA);
-               reg = snd_soc_read(codec, WM8900_REG_ADDCTL);
-               snd_soc_write(codec, WM8900_REG_ADDCTL,
-                            reg | WM8900_REG_ADDCTL_TEMP_SD);
+               snd_soc_update_bits(codec, WM8900_REG_GPIO,
+                                   WM8900_REG_GPIO_TEMP_ENA,
+                                   WM8900_REG_GPIO_TEMP_ENA);
+               snd_soc_update_bits(codec, WM8900_REG_ADDCTL,
+                                   WM8900_REG_ADDCTL_TEMP_SD,
+                                   WM8900_REG_ADDCTL_TEMP_SD);
                break;
 
        case SND_SOC_BIAS_PREPARE:
@@ -1205,26 +1190,16 @@ static int wm8900_probe(struct snd_soc_codec *codec)
        wm8900_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
        /* Latch the volume update bits */
-       snd_soc_write(codec, WM8900_REG_LINVOL,
-                     snd_soc_read(codec, WM8900_REG_LINVOL) | 0x100);
-       snd_soc_write(codec, WM8900_REG_RINVOL,
-                     snd_soc_read(codec, WM8900_REG_RINVOL) | 0x100);
-       snd_soc_write(codec, WM8900_REG_LOUT1CTL,
-                     snd_soc_read(codec, WM8900_REG_LOUT1CTL) | 0x100);
-       snd_soc_write(codec, WM8900_REG_ROUT1CTL,
-                     snd_soc_read(codec, WM8900_REG_ROUT1CTL) | 0x100);
-       snd_soc_write(codec, WM8900_REG_LOUT2CTL,
-                     snd_soc_read(codec, WM8900_REG_LOUT2CTL) | 0x100);
-       snd_soc_write(codec, WM8900_REG_ROUT2CTL,
-                     snd_soc_read(codec, WM8900_REG_ROUT2CTL) | 0x100);
-       snd_soc_write(codec, WM8900_REG_LDAC_DV,
-                     snd_soc_read(codec, WM8900_REG_LDAC_DV) | 0x100);
-       snd_soc_write(codec, WM8900_REG_RDAC_DV,
-                     snd_soc_read(codec, WM8900_REG_RDAC_DV) | 0x100);
-       snd_soc_write(codec, WM8900_REG_LADC_DV,
-                     snd_soc_read(codec, WM8900_REG_LADC_DV) | 0x100);
-       snd_soc_write(codec, WM8900_REG_RADC_DV,
-                     snd_soc_read(codec, WM8900_REG_RADC_DV) | 0x100);
+       snd_soc_update_bits(codec, WM8900_REG_LINVOL, 0x100, 0x100);
+       snd_soc_update_bits(codec, WM8900_REG_RINVOL, 0x100, 0x100);
+       snd_soc_update_bits(codec, WM8900_REG_LOUT1CTL, 0x100, 0x100);
+       snd_soc_update_bits(codec, WM8900_REG_ROUT1CTL, 0x100, 0x100);
+       snd_soc_update_bits(codec, WM8900_REG_LOUT2CTL, 0x100, 0x100);
+       snd_soc_update_bits(codec, WM8900_REG_ROUT2CTL, 0x100, 0x100);
+       snd_soc_update_bits(codec, WM8900_REG_LDAC_DV, 0x100, 0x100);
+       snd_soc_update_bits(codec, WM8900_REG_RDAC_DV, 0x100, 0x100);
+       snd_soc_update_bits(codec, WM8900_REG_LADC_DV, 0x100, 0x100);
+       snd_soc_update_bits(codec, WM8900_REG_RADC_DV, 0x100, 0x100);
 
        /* Set the DAC and mixer output bias */
        snd_soc_write(codec, WM8900_REG_OUTBIASCTL, 0x81);
index b085575d4aa542ac0cc8bf9c4a1b908c2eafdfe9..9fc8f4c0a9a91acbe52f5321f60008d90371ef51 100644 (file)
@@ -50,7 +50,6 @@ static const char *wm8904_supply_names[WM8904_NUM_SUPPLIES] = {
 struct wm8904_priv {
 
        enum wm8904_type devtype;
-       void *control_data;
 
        struct regulator_bulk_data supplies[WM8904_NUM_SUPPLIES];
 
@@ -2540,7 +2539,6 @@ static __devinit int wm8904_i2c_probe(struct i2c_client *i2c,
 
        wm8904->devtype = id->driver_data;
        i2c_set_clientdata(i2c, wm8904);
-       wm8904->control_data = i2c;
        wm8904->pdata = i2c->dev.platform_data;
 
        ret = snd_soc_register_codec(&i2c->dev,
index 056daa0010f99238ce4edc1f34d0a6bfe959f655..dc5cb315085721b916cb81394433b48a47e5e218 100644 (file)
 struct wm8940_priv {
        unsigned int sysclk;
        enum snd_soc_control_type control_type;
-       void *control_data;
 };
 
+static int wm8940_volatile_register(struct snd_soc_codec *codec,
+                                   unsigned int reg)
+{
+       switch (reg) {
+       case WM8940_SOFTRESET:
+               return 1;
+       default:
+               return 0;
+       }
+}
+
 static u16 wm8940_reg_defaults[] = {
        0x8940, /* Soft Reset */
        0x0000, /* Power 1 */
@@ -460,6 +470,14 @@ static int wm8940_set_bias_level(struct snd_soc_codec *codec,
                ret = snd_soc_write(codec, WM8940_POWER1, pwr_reg | 0x1);
                break;
        case SND_SOC_BIAS_STANDBY:
+               if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
+                       ret = snd_soc_cache_sync(codec);
+                       if (ret < 0) {
+                               dev_err(codec->dev, "Failed to sync cache: %d\n", ret);
+                               return ret;
+                       }
+               }
+
                /* ensure bufioen and biasen */
                pwr_reg |= (1 << 2) | (1 << 3);
                /* set vmid to 300k for standby */
@@ -470,6 +488,8 @@ static int wm8940_set_bias_level(struct snd_soc_codec *codec,
                break;
        }
 
+       codec->dapm.bias_level = level;
+
        return ret;
 }
 
@@ -660,30 +680,8 @@ static int wm8940_suspend(struct snd_soc_codec *codec, pm_message_t state)
 
 static int wm8940_resume(struct snd_soc_codec *codec)
 {
-       int i;
-       int ret;
-       u8 data[3];
-       u16 *cache = codec->reg_cache;
-
-       /* Sync reg_cache with the hardware
-        * Could use auto incremented writes to speed this up
-        */
-       for (i = 0; i < ARRAY_SIZE(wm8940_reg_defaults); i++) {
-               data[0] = i;
-               data[1] = (cache[i] & 0xFF00) >> 8;
-               data[2] = cache[i] & 0x00FF;
-               ret = codec->hw_write(codec->control_data, data, 3);
-               if (ret < 0)
-                       goto error_ret;
-               else if (ret != 3) {
-                       ret = -EIO;
-                       goto error_ret;
-               }
-       }
-       ret = wm8940_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-
-error_ret:
-       return ret;
+       wm8940_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+       return 0;
 }
 
 static int wm8940_probe(struct snd_soc_codec *codec)
@@ -693,7 +691,6 @@ static int wm8940_probe(struct snd_soc_codec *codec)
        int ret;
        u16 reg;
 
-       codec->control_data = wm8940->control_data;
        ret = snd_soc_codec_set_cache_io(codec, 8, 16, wm8940->control_type);
        if (ret < 0) {
                dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
@@ -744,6 +741,7 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8940 = {
        .reg_cache_size = ARRAY_SIZE(wm8940_reg_defaults),
        .reg_word_size = sizeof(u16),
        .reg_cache_default = wm8940_reg_defaults,
+       .volatile_register = wm8940_volatile_register,
 };
 
 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
@@ -758,7 +756,6 @@ static __devinit int wm8940_i2c_probe(struct i2c_client *i2c,
                return -ENOMEM;
 
        i2c_set_clientdata(i2c, wm8940);
-       wm8940->control_data = i2c;
        wm8940->control_type = SND_SOC_I2C;
 
        ret = snd_soc_register_codec(&i2c->dev,
index 4393394b7bc14bc1eaf5c724ddce602779fc8c9c..2df253c185683cb0001b05e6d7c7ecd21c759147 100644 (file)
@@ -72,7 +72,6 @@ static const u16 wm8960_reg[WM8960_CACHEREGNUM] = {
 
 struct wm8960_priv {
        enum snd_soc_control_type control_type;
-       void *control_data;
        int (*set_bias_level)(struct snd_soc_codec *,
                              enum snd_soc_bias_level level);
        struct snd_soc_dapm_widget *lout1;
@@ -575,6 +574,8 @@ static int wm8960_set_bias_level_out3(struct snd_soc_codec *codec,
 
        case SND_SOC_BIAS_STANDBY:
                if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
+                       snd_soc_cache_sync(codec);
+
                        /* Enable anti-pop features */
                        snd_soc_write(codec, WM8960_APOP1,
                                      WM8960_POBCTRL | WM8960_SOFT_ST |
@@ -677,6 +678,9 @@ static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec,
                                            WM8960_VREF | WM8960_VMID_MASK, 0);
                        break;
 
+               case SND_SOC_BIAS_OFF:
+                       snd_soc_cache_sync(codec);
+                       break;
                default:
                        break;
                }
@@ -902,16 +906,6 @@ static int wm8960_suspend(struct snd_soc_codec *codec, pm_message_t state)
 static int wm8960_resume(struct snd_soc_codec *codec)
 {
        struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
-       int i;
-       u8 data[2];
-       u16 *cache = codec->reg_cache;
-
-       /* Sync reg_cache with the hardware */
-       for (i = 0; i < ARRAY_SIZE(wm8960_reg); i++) {
-               data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
-               data[1] = cache[i] & 0x00ff;
-               codec->hw_write(codec->control_data, data, 2);
-       }
 
        wm8960->set_bias_level(codec, SND_SOC_BIAS_STANDBY);
        return 0;
@@ -925,7 +919,6 @@ static int wm8960_probe(struct snd_soc_codec *codec)
        u16 reg;
 
        wm8960->set_bias_level = wm8960_set_bias_level_out3;
-       codec->control_data = wm8960->control_data;
 
        if (!pdata) {
                dev_warn(codec->dev, "No platform data supplied\n");
@@ -1015,7 +1008,6 @@ static __devinit int wm8960_i2c_probe(struct i2c_client *i2c,
 
        i2c_set_clientdata(i2c, wm8960);
        wm8960->control_type = SND_SOC_I2C;
-       wm8960->control_data = i2c;
 
        ret = snd_soc_register_codec(&i2c->dev,
                        &soc_codec_dev_wm8960, &wm8960_dai, 1);
index cdee8103d09b323efebfee47497d87dbe525f8ac..9568c8a49f962da10d62a11ad58a8143cfd8619d 100644 (file)
@@ -974,7 +974,9 @@ static int wm8961_probe(struct snd_soc_codec *codec)
        }
 
        /* This isn't volatile - readback doesn't correspond to write */
-       reg = codec->hw_read(codec, WM8961_RIGHT_INPUT_VOLUME);
+       codec->cache_bypass = 1;
+       reg = snd_soc_read(codec, WM8961_RIGHT_INPUT_VOLUME);
+       codec->cache_bypass = 0;
        dev_info(codec->dev, "WM8961 family %d revision %c\n",
                 (reg & WM8961_DEVICE_ID_MASK) >> WM8961_DEVICE_ID_SHIFT,
                 ((reg & WM8961_CHIP_REV_MASK) >> WM8961_CHIP_REV_SHIFT)
index d2c315fa1b9b8b8ed379dcce84a85511a45116f8..f60dfa16545e79ae821551b964151b997b7194a9 100644 (file)
@@ -63,6 +63,8 @@ struct wm8962_priv {
        int fll_fref;
        int fll_fout;
 
+       u16 dsp2_ena;
+
        struct delayed_work mic_work;
        struct snd_soc_jack *jack;
 
@@ -837,7 +839,7 @@ static const struct wm8962_reg_access {
        [40] = { 0x00FF, 0x01FF, 0x0000 }, /* R40    - SPKOUTL volume */
        [41] = { 0x00FF, 0x01FF, 0x0000 }, /* R41    - SPKOUTR volume */
 
-       [47] = { 0x000F, 0x0000, 0x0000 }, /* R47    - Thermal Shutdown Status */
+       [47] = { 0x000F, 0x0000, 0xFFFF }, /* R47    - Thermal Shutdown Status */
        [48] = { 0x7EC7, 0x7E07, 0xFFFF }, /* R48    - Additional Control (4) */
        [49] = { 0x00D3, 0x00D7, 0xFFFF }, /* R49    - Class D Control 1 */
        [51] = { 0x0047, 0x0047, 0x0000 }, /* R51    - Class D Control 2 */
@@ -965,7 +967,7 @@ static const struct wm8962_reg_access {
        [584] = { 0x002D, 0x002D, 0x0000 }, /* R584   - IRQ Debounce */
        [586] = { 0xC000, 0xC000, 0x0000 }, /* R586   -  MICINT Source Pol */
        [768] = { 0x0001, 0x0001, 0x0000 }, /* R768   - DSP2 Power Management */
-       [1037] = { 0x0000, 0x003F, 0x0000 }, /* R1037  - DSP2_ExecControl */
+       [1037] = { 0x0000, 0x003F, 0xFFFF }, /* R1037  - DSP2_ExecControl */
        [4096] = { 0x3FFF, 0x3FFF, 0x0000 }, /* R4096  - Write Sequencer 0 */
        [4097] = { 0x00FF, 0x00FF, 0x0000 }, /* R4097  - Write Sequencer 1 */
        [4098] = { 0x070F, 0x070F, 0x0000 }, /* R4098  - Write Sequencer 2 */
@@ -1986,6 +1988,122 @@ static const unsigned int classd_tlv[] = {
 };
 static const DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
 
+static int wm8962_dsp2_write_config(struct snd_soc_codec *codec)
+{
+       return 0;
+}
+
+static int wm8962_dsp2_set_enable(struct snd_soc_codec *codec, u16 val)
+{
+       u16 adcl = snd_soc_read(codec, WM8962_LEFT_ADC_VOLUME);
+       u16 adcr = snd_soc_read(codec, WM8962_RIGHT_ADC_VOLUME);
+       u16 dac = snd_soc_read(codec, WM8962_ADC_DAC_CONTROL_1);
+
+       /* Mute the ADCs and DACs */
+       snd_soc_write(codec, WM8962_LEFT_ADC_VOLUME, 0);
+       snd_soc_write(codec, WM8962_RIGHT_ADC_VOLUME, WM8962_ADC_VU);
+       snd_soc_update_bits(codec, WM8962_ADC_DAC_CONTROL_1,
+                           WM8962_DAC_MUTE, WM8962_DAC_MUTE);
+
+       snd_soc_write(codec, WM8962_SOUNDSTAGE_ENABLES_0, val);
+
+       /* Restore the ADCs and DACs */
+       snd_soc_write(codec, WM8962_LEFT_ADC_VOLUME, adcl);
+       snd_soc_write(codec, WM8962_RIGHT_ADC_VOLUME, adcr);
+       snd_soc_update_bits(codec, WM8962_ADC_DAC_CONTROL_1,
+                           WM8962_DAC_MUTE, dac);
+
+       return 0;
+}
+
+static int wm8962_dsp2_start(struct snd_soc_codec *codec)
+{
+       struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec);
+
+       wm8962_dsp2_write_config(codec);
+
+       snd_soc_write(codec, WM8962_DSP2_EXECCONTROL, WM8962_DSP2_RUNR);
+
+       wm8962_dsp2_set_enable(codec, wm8962->dsp2_ena);
+
+       return 0;
+}
+
+static int wm8962_dsp2_stop(struct snd_soc_codec *codec)
+{
+       wm8962_dsp2_set_enable(codec, 0);
+
+       snd_soc_write(codec, WM8962_DSP2_EXECCONTROL, WM8962_DSP2_STOP);
+
+       return 0;
+}
+
+#define WM8962_DSP2_ENABLE(xname, xshift) \
+{      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
+       .info = wm8962_dsp2_ena_info, \
+       .get = wm8962_dsp2_ena_get, .put = wm8962_dsp2_ena_put, \
+       .private_value = xshift }
+
+static int wm8962_dsp2_ena_info(struct snd_kcontrol *kcontrol,
+                               struct snd_ctl_elem_info *uinfo)
+{
+       uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
+
+       uinfo->count = 1;
+       uinfo->value.integer.min = 0;
+       uinfo->value.integer.max = 1;
+
+       return 0;
+}
+
+static int wm8962_dsp2_ena_get(struct snd_kcontrol *kcontrol,
+                              struct snd_ctl_elem_value *ucontrol)
+{
+       int shift = kcontrol->private_value;
+       struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+       struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec);
+
+       ucontrol->value.integer.value[0] = !!(wm8962->dsp2_ena & 1 << shift);
+
+       return 0;
+}
+
+static int wm8962_dsp2_ena_put(struct snd_kcontrol *kcontrol,
+                              struct snd_ctl_elem_value *ucontrol)
+{
+       int shift = kcontrol->private_value;
+       struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+       struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec);
+       int old = wm8962->dsp2_ena;
+       int ret = 0;
+       int dsp2_running = snd_soc_read(codec, WM8962_DSP2_POWER_MANAGEMENT) &
+               WM8962_DSP2_ENA;
+
+       mutex_lock(&codec->mutex);
+
+       if (ucontrol->value.integer.value[0])
+               wm8962->dsp2_ena |= 1 << shift;
+       else
+               wm8962->dsp2_ena &= ~(1 << shift);
+
+       if (wm8962->dsp2_ena == old)
+               goto out;
+
+       ret = 1;
+
+       if (dsp2_running) {
+               if (wm8962->dsp2_ena)
+                       wm8962_dsp2_set_enable(codec, wm8962->dsp2_ena);
+               else
+                       wm8962_dsp2_stop(codec);
+       }
+
+out:
+       mutex_unlock(&codec->mutex);
+
+       return ret;
+}
+
 /* The VU bits for the headphones are in a different register to the mute
  * bits and only take effect on the PGA if it is actually powered.
  */
@@ -2021,7 +2139,6 @@ static int wm8962_put_spk_sw(struct snd_kcontrol *kcontrol,
                            struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
-       u16 *reg_cache = codec->reg_cache;
        int ret;
 
        /* Apply the update (if any) */
@@ -2030,16 +2147,19 @@ static int wm8962_put_spk_sw(struct snd_kcontrol *kcontrol,
                return 0;
 
        /* If the left PGA is enabled hit that VU bit... */
-       if (reg_cache[WM8962_PWR_MGMT_2] & WM8962_SPKOUTL_PGA_ENA)
-               return snd_soc_write(codec, WM8962_SPKOUTL_VOLUME,
-                                    reg_cache[WM8962_SPKOUTL_VOLUME]);
+       ret = snd_soc_read(codec, WM8962_PWR_MGMT_2);
+       if (ret & WM8962_SPKOUTL_PGA_ENA) {
+               snd_soc_write(codec, WM8962_SPKOUTL_VOLUME,
+                             snd_soc_read(codec, WM8962_SPKOUTL_VOLUME));
+               return 1;
+       }
 
        /* ...otherwise the right.  The VU is stereo. */
-       if (reg_cache[WM8962_PWR_MGMT_2] & WM8962_SPKOUTR_PGA_ENA)
-               return snd_soc_write(codec, WM8962_SPKOUTR_VOLUME,
-                                    reg_cache[WM8962_SPKOUTR_VOLUME]);
+       if (ret & WM8962_SPKOUTR_PGA_ENA)
+               snd_soc_write(codec, WM8962_SPKOUTR_VOLUME,
+                             snd_soc_read(codec, WM8962_SPKOUTR_VOLUME));
 
-       return 0;
+       return 1;
 }
 
 static const char *cap_hpf_mode_text[] = {
@@ -2049,6 +2169,14 @@ static const char *cap_hpf_mode_text[] = {
 static const struct soc_enum cap_hpf_mode =
        SOC_ENUM_SINGLE(WM8962_ADC_DAC_CONTROL_2, 10, 2, cap_hpf_mode_text);
 
+
+static const char *cap_lhpf_mode_text[] = {
+       "LPF", "HPF"
+};
+
+static const struct soc_enum cap_lhpf_mode =
+       SOC_ENUM_SINGLE(WM8962_LHPF1, 1, 2, cap_lhpf_mode_text);
+
 static const struct snd_kcontrol_new wm8962_snd_controls[] = {
 SOC_DOUBLE("Input Mixer Switch", WM8962_INPUT_MIXER_CONTROL_1, 3, 2, 1, 1),
 
@@ -2077,6 +2205,8 @@ SOC_DOUBLE_R("Capture ZC Switch", WM8962_LEFT_INPUT_VOLUME,
 SOC_SINGLE("Capture HPF Switch", WM8962_ADC_DAC_CONTROL_1, 0, 1, 1),
 SOC_ENUM("Capture HPF Mode", cap_hpf_mode),
 SOC_SINGLE("Capture HPF Cutoff", WM8962_ADC_DAC_CONTROL_2, 7, 7, 0),
+SOC_SINGLE("Capture LHPF Switch", WM8962_LHPF1, 0, 1, 0),
+SOC_ENUM("Capture LHPF Mode", cap_lhpf_mode),
 
 SOC_DOUBLE_R_TLV("Sidetone Volume", WM8962_DAC_DSP_MIXING_1,
                 WM8962_DAC_DSP_MIXING_2, 4, 12, 0, st_tlv),
@@ -2134,6 +2264,11 @@ SOC_DOUBLE_R_TLV("EQ4 Volume", WM8962_EQ3, WM8962_EQ23,
                 WM8962_EQL_B4_GAIN_SHIFT, 31, 0, eq_tlv),
 SOC_DOUBLE_R_TLV("EQ5 Volume", WM8962_EQ3, WM8962_EQ23,
                 WM8962_EQL_B5_GAIN_SHIFT, 31, 0, eq_tlv),
+
+WM8962_DSP2_ENABLE("VSS Switch", WM8962_VSS_ENA_SHIFT),
+WM8962_DSP2_ENABLE("HPF1 Switch", WM8962_HPF1_ENA_SHIFT),
+WM8962_DSP2_ENABLE("HPF2 Switch", WM8962_HPF2_ENA_SHIFT),
+WM8962_DSP2_ENABLE("HD Bass Switch", WM8962_HDBASS_ENA_SHIFT),
 };
 
 static const struct snd_kcontrol_new wm8962_spk_mono_controls[] = {
@@ -2365,7 +2500,6 @@ static int out_pga_event(struct snd_soc_dapm_widget *w,
                         struct snd_kcontrol *kcontrol, int event)
 {
        struct snd_soc_codec *codec = w->codec;
-       u16 *reg_cache = codec->reg_cache;
        int reg;
 
        switch (w->shift) {
@@ -2388,11 +2522,36 @@ static int out_pga_event(struct snd_soc_dapm_widget *w,
 
        switch (event) {
        case SND_SOC_DAPM_POST_PMU:
-               return snd_soc_write(codec, reg, reg_cache[reg]);
+               return snd_soc_write(codec, reg, snd_soc_read(codec, reg));
+       default:
+               BUG();
+               return -EINVAL;
+       }
+}
+
+static int dsp2_event(struct snd_soc_dapm_widget *w,
+                     struct snd_kcontrol *kcontrol, int event)
+{
+       struct snd_soc_codec *codec = w->codec;
+       struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec);
+
+       switch (event) {
+       case SND_SOC_DAPM_POST_PMU:
+               if (wm8962->dsp2_ena)
+                       wm8962_dsp2_start(codec);
+               break;
+
+       case SND_SOC_DAPM_PRE_PMD:
+               if (wm8962->dsp2_ena)
+                       wm8962_dsp2_stop(codec);
+               break;
+
        default:
                BUG();
                return -EINVAL;
        }
+
+       return 0;
 }
 
 static const char *st_text[] = { "None", "Right", "Left" };
@@ -2509,7 +2668,7 @@ SND_SOC_DAPM_INPUT("IN4R"),
 SND_SOC_DAPM_INPUT("Beep"),
 SND_SOC_DAPM_INPUT("DMICDAT"),
 
-SND_SOC_DAPM_MICBIAS("MICBIAS", WM8962_PWR_MGMT_1, 1, 0),
+SND_SOC_DAPM_SUPPLY("MICBIAS", WM8962_PWR_MGMT_1, 1, 0, NULL, 0),
 
 SND_SOC_DAPM_SUPPLY("Class G", WM8962_CHARGE_PUMP_B, 0, 1, NULL, 0),
 SND_SOC_DAPM_SUPPLY("SYSCLK", WM8962_CLOCKING2, 5, 0, sysclk_event,
@@ -2517,6 +2676,9 @@ SND_SOC_DAPM_SUPPLY("SYSCLK", WM8962_CLOCKING2, 5, 0, sysclk_event,
 SND_SOC_DAPM_SUPPLY("Charge Pump", WM8962_CHARGE_PUMP_1, 0, 0, cp_event,
                    SND_SOC_DAPM_POST_PMU),
 SND_SOC_DAPM_SUPPLY("TOCLK", WM8962_ADDITIONAL_CONTROL_1, 0, 0, NULL, 0),
+SND_SOC_DAPM_SUPPLY_S("DSP2", 1, WM8962_DSP2_POWER_MANAGEMENT,
+                     WM8962_DSP2_ENA_SHIFT, 0, dsp2_event,
+                     SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
 
 SND_SOC_DAPM_MIXER("INPGAL", WM8962_LEFT_INPUT_PGA_CONTROL, 4, 0,
                   inpgal, ARRAY_SIZE(inpgal)),
@@ -2527,7 +2689,7 @@ SND_SOC_DAPM_MIXER("MIXINL", WM8962_PWR_MGMT_1, 5, 0,
 SND_SOC_DAPM_MIXER("MIXINR", WM8962_PWR_MGMT_1, 4, 0,
                   mixinr, ARRAY_SIZE(mixinr)),
 
-SND_SOC_DAPM_AIF_IN("DMIC", NULL, 0, WM8962_PWR_MGMT_1, 10, 0),
+SND_SOC_DAPM_AIF_IN("DMIC_ENA", NULL, 0, WM8962_PWR_MGMT_1, 10, 0),
 
 SND_SOC_DAPM_ADC("ADCL", "Capture", WM8962_PWR_MGMT_1, 3, 0),
 SND_SOC_DAPM_ADC("ADCR", "Capture", WM8962_PWR_MGMT_1, 2, 0),
@@ -2606,17 +2768,19 @@ static const struct snd_soc_dapm_route wm8962_intercon[] = {
 
        { "MICBIAS", NULL, "SYSCLK" },
 
-       { "DMIC", NULL, "DMICDAT" },
+       { "DMIC_ENA", NULL, "DMICDAT" },
 
        { "ADCL", NULL, "SYSCLK" },
        { "ADCL", NULL, "TOCLK" },
        { "ADCL", NULL, "MIXINL" },
-       { "ADCL", NULL, "DMIC" },
+       { "ADCL", NULL, "DMIC_ENA" },
+       { "ADCL", NULL, "DSP2" },
 
        { "ADCR", NULL, "SYSCLK" },
        { "ADCR", NULL, "TOCLK" },
        { "ADCR", NULL, "MIXINR" },
-       { "ADCR", NULL, "DMIC" },
+       { "ADCR", NULL, "DMIC_ENA" },
+       { "ADCR", NULL, "DSP2" },
 
        { "STL", "Left", "ADCL" },
        { "STL", "Right", "ADCR" },
@@ -2628,11 +2792,13 @@ static const struct snd_soc_dapm_route wm8962_intercon[] = {
        { "DACL", NULL, "TOCLK" },
        { "DACL", NULL, "Beep" },
        { "DACL", NULL, "STL" },
+       { "DACL", NULL, "DSP2" },
 
        { "DACR", NULL, "SYSCLK" },
        { "DACR", NULL, "TOCLK" },
        { "DACR", NULL, "Beep" },
        { "DACR", NULL, "STR" },
+       { "DACR", NULL, "DSP2" },
 
        { "HPMIXL", "IN4L Switch", "IN4L" },
        { "HPMIXL", "IN4R Switch", "IN4R" },
@@ -3058,9 +3224,9 @@ static int wm8962_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
        int aif0 = 0;
 
        switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
-       case SND_SOC_DAIFMT_DSP_A:
-               aif0 |= WM8962_LRCLK_INV;
        case SND_SOC_DAIFMT_DSP_B:
+               aif0 |= WM8962_LRCLK_INV | 3;
+       case SND_SOC_DAIFMT_DSP_A:
                aif0 |= 3;
 
                switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
@@ -3403,12 +3569,16 @@ static irqreturn_t wm8962_irq(int irq, void *data)
        struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec);
        int mask;
        int active;
+       int reg;
 
        mask = snd_soc_read(codec, WM8962_INTERRUPT_STATUS_2_MASK);
 
        active = snd_soc_read(codec, WM8962_INTERRUPT_STATUS_2);
        active &= ~mask;
 
+       if (!active)
+               return IRQ_NONE;
+
        /* Acknowledge the interrupts */
        snd_soc_write(codec, WM8962_INTERRUPT_STATUS_2, active);
 
@@ -3420,9 +3590,21 @@ static irqreturn_t wm8962_irq(int irq, void *data)
        if (active & WM8962_FIFOS_ERR_EINT)
                dev_err(codec->dev, "FIFO error\n");
 
-       if (active & WM8962_TEMP_SHUT_EINT)
+       if (active & WM8962_TEMP_SHUT_EINT) {
                dev_crit(codec->dev, "Thermal shutdown\n");
 
+               reg = snd_soc_read(codec, WM8962_THERMAL_SHUTDOWN_STATUS);
+
+               if (reg & WM8962_TEMP_ERR_HP)
+                       dev_crit(codec->dev, "Headphone thermal error\n");
+               if (reg & WM8962_TEMP_WARN_HP)
+                       dev_crit(codec->dev, "Headphone thermal warning\n");
+               if (reg & WM8962_TEMP_ERR_SPK)
+                       dev_crit(codec->dev, "Speaker thermal error\n");
+               if (reg & WM8962_TEMP_WARN_SPK)
+                       dev_crit(codec->dev, "Speaker thermal warning\n");
+       }
+
        if (active & (WM8962_MICSCD_EINT | WM8962_MICD_EINT)) {
                dev_dbg(codec->dev, "Microphone event detected\n");
 
index 572bb80627a478b503ab7edfa78792e79423273e..b444b297d0b2f442d9f5d1d1e1014227ce42128d 100644 (file)
@@ -546,6 +546,9 @@ static int wm8971_set_bias_level(struct snd_soc_codec *codec,
        case SND_SOC_BIAS_PREPARE:
                break;
        case SND_SOC_BIAS_STANDBY:
+               if (codec->dapm.bias_level == SND_SOC_BIAS_OFF)
+                       snd_soc_cache_sync(codec);
+
                /* mute dac and set vmid to 500k, enable VREF */
                snd_soc_write(codec, WM8971_PWR1, pwr_reg | 0x0140);
                break;
@@ -605,20 +608,8 @@ static int wm8971_suspend(struct snd_soc_codec *codec, pm_message_t state)
 
 static int wm8971_resume(struct snd_soc_codec *codec)
 {
-       int i;
-       u8 data[2];
-       u16 *cache = codec->reg_cache;
        u16 reg;
 
-       /* Sync reg_cache with the hardware */
-       for (i = 0; i < ARRAY_SIZE(wm8971_reg); i++) {
-               if (i + 1 == WM8971_RESET)
-                       continue;
-               data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
-               data[1] = cache[i] & 0x00ff;
-               codec->hw_write(codec->control_data, data, 2);
-       }
-
        wm8971_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
        /* charge wm8971 caps */
@@ -660,25 +651,14 @@ static int wm8971_probe(struct snd_soc_codec *codec)
                msecs_to_jiffies(1000));
 
        /* set the update bits */
-       reg = snd_soc_read(codec, WM8971_LDAC);
-       snd_soc_write(codec, WM8971_LDAC, reg | 0x0100);
-       reg = snd_soc_read(codec, WM8971_RDAC);
-       snd_soc_write(codec, WM8971_RDAC, reg | 0x0100);
-
-       reg = snd_soc_read(codec, WM8971_LOUT1V);
-       snd_soc_write(codec, WM8971_LOUT1V, reg | 0x0100);
-       reg = snd_soc_read(codec, WM8971_ROUT1V);
-       snd_soc_write(codec, WM8971_ROUT1V, reg | 0x0100);
-
-       reg = snd_soc_read(codec, WM8971_LOUT2V);
-       snd_soc_write(codec, WM8971_LOUT2V, reg | 0x0100);
-       reg = snd_soc_read(codec, WM8971_ROUT2V);
-       snd_soc_write(codec, WM8971_ROUT2V, reg | 0x0100);
-
-       reg = snd_soc_read(codec, WM8971_LINVOL);
-       snd_soc_write(codec, WM8971_LINVOL, reg | 0x0100);
-       reg = snd_soc_read(codec, WM8971_RINVOL);
-       snd_soc_write(codec, WM8971_RINVOL, reg | 0x0100);
+       snd_soc_update_bits(codec, WM8971_LDAC, 0x0100, 0x0100);
+       snd_soc_update_bits(codec, WM8971_RDAC, 0x0100, 0x0100);
+       snd_soc_update_bits(codec, WM8971_LOUT1V, 0x0100, 0x0100);
+       snd_soc_update_bits(codec, WM8971_ROUT1V, 0x0100, 0x0100);
+       snd_soc_update_bits(codec, WM8971_LOUT2V, 0x0100, 0x0100);
+       snd_soc_update_bits(codec, WM8971_ROUT2V, 0x0100, 0x0100);
+       snd_soc_update_bits(codec, WM8971_LINVOL, 0x0100, 0x0100);
+       snd_soc_update_bits(codec, WM8971_RINVOL, 0x0100, 0x0100);
 
        snd_soc_add_controls(codec, wm8971_snd_controls,
                                ARRAY_SIZE(wm8971_snd_controls));
index ca646a822444472d3e092f52ac1c02bbe3998775..9352f1e088d27fd4053ce7b6e6796081c1daee92 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2006-2009 Wolfson Microelectronics PLC.
  *
- * Author: Liam Girdwood <linux@wolfsonmicro.com>
+ * Author: Liam Girdwood <Liam.Girdwood@wolfsonmicro.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -530,6 +530,8 @@ static int wm8974_set_bias_level(struct snd_soc_codec *codec,
                power1 |= WM8974_POWER1_BIASEN | WM8974_POWER1_BUFIOEN;
 
                if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
+                       snd_soc_cache_sync(codec);
+
                        /* Initial cap charge at VMID 5k */
                        snd_soc_write(codec, WM8974_POWER1, power1 | 0x3);
                        mdelay(100);
@@ -589,18 +591,7 @@ static int wm8974_suspend(struct snd_soc_codec *codec, pm_message_t state)
 
 static int wm8974_resume(struct snd_soc_codec *codec)
 {
-       int i;
-       u8 data[2];
-       u16 *cache = codec->reg_cache;
-
-       /* Sync reg_cache with the hardware */
-       for (i = 0; i < ARRAY_SIZE(wm8974_reg); i++) {
-               data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
-               data[1] = cache[i] & 0x00ff;
-               codec->hw_write(codec->control_data, data, 2);
-       }
        wm8974_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-
        return 0;
 }
 
index 85e3e630e763ca841ecd51e40cd66ab7733bcf8d..41ca4d9ac20c0dff5aeb5d2666cae916237a0144 100644 (file)
@@ -52,7 +52,6 @@ static const u16 wm8978_reg[WM8978_CACHEREGNUM] = {
 /* codec private data */
 struct wm8978_priv {
        enum snd_soc_control_type control_type;
-       void *control_data;
        unsigned int f_pllout;
        unsigned int f_mclk;
        unsigned int f_256fs;
@@ -955,7 +954,6 @@ static int wm8978_probe(struct snd_soc_codec *codec)
         * default hardware setting
         */
        wm8978->sysclk = WM8978_PLL;
-       codec->control_data = wm8978->control_data;
        ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_I2C);
        if (ret < 0) {
                dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
@@ -1016,7 +1014,6 @@ static __devinit int wm8978_i2c_probe(struct i2c_client *i2c,
                return -ENOMEM;
 
        i2c_set_clientdata(i2c, wm8978);
-       wm8978->control_data = i2c;
 
        ret = snd_soc_register_codec(&i2c->dev,
                        &soc_codec_dev_wm8978, &wm8978_dai, 1);
index 17f04ec2b940d068f07b21a116f9ca9568a64fff..93ee28439be56f70dbdaec4a4689209df94f3243 100644 (file)
@@ -1007,7 +1007,7 @@ static int wm8983_probe(struct snd_soc_codec *codec)
                return ret;
        }
 
-       ret = snd_soc_write(codec, WM8983_SOFTWARE_RESET, 0x8983);
+       ret = snd_soc_write(codec, WM8983_SOFTWARE_RESET, 0);
        if (ret < 0) {
                dev_err(codec->dev, "Failed to issue reset: %d\n", ret);
                return ret;
index d7170f1381aa758084834de1f7eae0532d7e00a7..2e9eba717d1a9adb1f15fe345276699c67c26fca 100644 (file)
@@ -55,7 +55,6 @@ struct wm8988_priv {
        struct snd_pcm_hw_constraint_list *sysclk_constraints;
 };
 
-
 #define wm8988_reset(c)        snd_soc_write(c, WM8988_RESET, 0)
 
 /*
@@ -676,6 +675,8 @@ static int wm8988_set_bias_level(struct snd_soc_codec *codec,
 
        case SND_SOC_BIAS_STANDBY:
                if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
+                       snd_soc_cache_sync(codec);
+
                        /* VREF, VMID=2x5k */
                        snd_soc_write(codec, WM8988_PWR1, pwr_reg | 0x1c1);
 
@@ -736,21 +737,7 @@ static int wm8988_suspend(struct snd_soc_codec *codec, pm_message_t state)
 
 static int wm8988_resume(struct snd_soc_codec *codec)
 {
-       int i;
-       u8 data[2];
-       u16 *cache = codec->reg_cache;
-
-       /* Sync reg_cache with the hardware */
-       for (i = 0; i < WM8988_NUM_REG; i++) {
-               if (i == WM8988_RESET)
-                       continue;
-               data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
-               data[1] = cache[i] & 0x00ff;
-               codec->hw_write(codec->control_data, data, 2);
-       }
-
        wm8988_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-
        return 0;
 }
 
@@ -759,7 +746,6 @@ static int wm8988_probe(struct snd_soc_codec *codec)
        struct wm8988_priv *wm8988 = snd_soc_codec_get_drvdata(codec);
        struct snd_soc_dapm_context *dapm = &codec->dapm;
        int ret = 0;
-       u16 reg;
 
        ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8988->control_type);
        if (ret < 0) {
@@ -774,16 +760,11 @@ static int wm8988_probe(struct snd_soc_codec *codec)
        }
 
        /* set the update bits (we always update left then right) */
-       reg = snd_soc_read(codec, WM8988_RADC);
-       snd_soc_write(codec, WM8988_RADC, reg | 0x100);
-       reg = snd_soc_read(codec, WM8988_RDAC);
-       snd_soc_write(codec, WM8988_RDAC, reg | 0x0100);
-       reg = snd_soc_read(codec, WM8988_ROUT1V);
-       snd_soc_write(codec, WM8988_ROUT1V, reg | 0x0100);
-       reg = snd_soc_read(codec, WM8988_ROUT2V);
-       snd_soc_write(codec, WM8988_ROUT2V, reg | 0x0100);
-       reg = snd_soc_read(codec, WM8988_RINVOL);
-       snd_soc_write(codec, WM8988_RINVOL, reg | 0x0100);
+       snd_soc_update_bits(codec, WM8988_RADC, 0x0100, 0x0100);
+       snd_soc_update_bits(codec, WM8988_RDAC, 0x0100, 0x0100);
+       snd_soc_update_bits(codec, WM8988_ROUT1V, 0x0100, 0x0100);
+       snd_soc_update_bits(codec, WM8988_ROUT2V, 0x0100, 0x0100);
+       snd_soc_update_bits(codec, WM8988_RINVOL, 0x0100, 0x0100);
 
        wm8988_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
index 100aeee5ba96472e0a0ecb70b7f66d9c4a550d5a..d29a9622964c20d32850c6f5c0ced435af22a1a7 100644 (file)
@@ -36,10 +36,17 @@ struct wm8990_priv {
        unsigned int pcmclk;
 };
 
-/*
- * wm8990 register cache.  Note that register 0 is not included in the
- * cache.
- */
+static int wm8990_volatile_register(struct snd_soc_codec *codec,
+                                   unsigned int reg)
+{
+       switch (reg) {
+       case WM8990_RESET:
+               return 1;
+       default:
+               return 0;
+       }
+}
+
 static const u16 wm8990_reg[] = {
        0x8990,     /* R0  - Reset */
        0x0000,     /* R1  - Power Management (1) */
@@ -394,7 +401,7 @@ static int inmixer_event(struct snd_soc_dapm_widget *w,
                (1 << WM8990_AINRMUX_PWR_BIT))) {
                reg |= WM8990_AINR_ENA;
        } else {
-               reg &= ~WM8990_AINL_ENA;
+               reg &= ~WM8990_AINR_ENA;
        }
        snd_soc_write(w->codec, WM8990_POWER_MANAGEMENT_2, reg);
 
@@ -974,7 +981,6 @@ static void pll_factors(struct _pll_div *pll_div, unsigned int target,
 static int wm8990_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
                int source, unsigned int freq_in, unsigned int freq_out)
 {
-       u16 reg;
        struct snd_soc_codec *codec = codec_dai->codec;
        struct _pll_div pll_div;
 
@@ -982,13 +988,12 @@ static int wm8990_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
                pll_factors(&pll_div, freq_out * 4, freq_in);
 
                /* Turn on PLL */
-               reg = snd_soc_read(codec, WM8990_POWER_MANAGEMENT_2);
-               reg |= WM8990_PLL_ENA;
-               snd_soc_write(codec, WM8990_POWER_MANAGEMENT_2, reg);
+               snd_soc_update_bits(codec, WM8990_POWER_MANAGEMENT_2,
+                                   WM8990_PLL_ENA, WM8990_PLL_ENA);
 
                /* sysclk comes from PLL */
-               reg = snd_soc_read(codec, WM8990_CLOCKING_2);
-               snd_soc_write(codec, WM8990_CLOCKING_2, reg | WM8990_SYSCLK_SRC);
+               snd_soc_update_bits(codec, WM8990_CLOCKING_2,
+                                   WM8990_SYSCLK_SRC, WM8990_SYSCLK_SRC);
 
                /* set up N , fractional mode and pre-divisor if necessary */
                snd_soc_write(codec, WM8990_PLL1, pll_div.n | WM8990_SDM |
@@ -996,10 +1001,9 @@ static int wm8990_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
                snd_soc_write(codec, WM8990_PLL2, (u8)(pll_div.k>>8));
                snd_soc_write(codec, WM8990_PLL3, (u8)(pll_div.k & 0xFF));
        } else {
-               /* Turn on PLL */
-               reg = snd_soc_read(codec, WM8990_POWER_MANAGEMENT_2);
-               reg &= ~WM8990_PLL_ENA;
-               snd_soc_write(codec, WM8990_POWER_MANAGEMENT_2, reg);
+               /* Turn off PLL */
+               snd_soc_update_bits(codec, WM8990_POWER_MANAGEMENT_2,
+                                   WM8990_PLL_ENA, 0);
        }
        return 0;
 }
@@ -1077,28 +1081,23 @@ static int wm8990_set_dai_clkdiv(struct snd_soc_dai *codec_dai,
                int div_id, int div)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       u16 reg;
 
        switch (div_id) {
        case WM8990_MCLK_DIV:
-               reg = snd_soc_read(codec, WM8990_CLOCKING_2) &
-                       ~WM8990_MCLK_DIV_MASK;
-               snd_soc_write(codec, WM8990_CLOCKING_2, reg | div);
+               snd_soc_update_bits(codec, WM8990_CLOCKING_2,
+                                   WM8990_MCLK_DIV_MASK, div);
                break;
        case WM8990_DACCLK_DIV:
-               reg = snd_soc_read(codec, WM8990_CLOCKING_2) &
-                       ~WM8990_DAC_CLKDIV_MASK;
-               snd_soc_write(codec, WM8990_CLOCKING_2, reg | div);
+               snd_soc_update_bits(codec, WM8990_CLOCKING_2,
+                                   WM8990_DAC_CLKDIV_MASK, div);
                break;
        case WM8990_ADCCLK_DIV:
-               reg = snd_soc_read(codec, WM8990_CLOCKING_2) &
-                       ~WM8990_ADC_CLKDIV_MASK;
-               snd_soc_write(codec, WM8990_CLOCKING_2, reg | div);
+               snd_soc_update_bits(codec, WM8990_CLOCKING_2,
+                                   WM8990_ADC_CLKDIV_MASK, div);
                break;
        case WM8990_BCLK_DIV:
-               reg = snd_soc_read(codec, WM8990_CLOCKING_1) &
-                       ~WM8990_BCLK_DIV_MASK;
-               snd_soc_write(codec, WM8990_CLOCKING_1, reg | div);
+               snd_soc_update_bits(codec, WM8990_CLOCKING_1,
+                                   WM8990_BCLK_DIV_MASK, div);
                break;
        default:
                return -EINVAL;
@@ -1156,7 +1155,7 @@ static int wm8990_mute(struct snd_soc_dai *dai, int mute)
 static int wm8990_set_bias_level(struct snd_soc_codec *codec,
        enum snd_soc_bias_level level)
 {
-       u16 val;
+       int ret;
 
        switch (level) {
        case SND_SOC_BIAS_ON:
@@ -1164,13 +1163,18 @@ static int wm8990_set_bias_level(struct snd_soc_codec *codec,
 
        case SND_SOC_BIAS_PREPARE:
                /* VMID=2*50k */
-               val = snd_soc_read(codec, WM8990_POWER_MANAGEMENT_1) &
-                       ~WM8990_VMID_MODE_MASK;
-               snd_soc_write(codec, WM8990_POWER_MANAGEMENT_1, val | 0x2);
+               snd_soc_update_bits(codec, WM8990_POWER_MANAGEMENT_1,
+                                   WM8990_VMID_MODE_MASK, 0x2);
                break;
 
        case SND_SOC_BIAS_STANDBY:
                if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
+                       ret = snd_soc_cache_sync(codec);
+                       if (ret < 0) {
+                               dev_err(codec->dev, "Failed to sync cache: %d\n", ret);
+                               return ret;
+                       }
+
                        /* Enable all output discharge bits */
                        snd_soc_write(codec, WM8990_ANTIPOP1, WM8990_DIS_LLINE |
                                WM8990_DIS_RLINE | WM8990_DIS_OUT3 |
@@ -1225,9 +1229,8 @@ static int wm8990_set_bias_level(struct snd_soc_codec *codec,
                }
 
                /* VMID=2*250k */
-               val = snd_soc_read(codec, WM8990_POWER_MANAGEMENT_1) &
-                       ~WM8990_VMID_MODE_MASK;
-               snd_soc_write(codec, WM8990_POWER_MANAGEMENT_1, val | 0x4);
+               snd_soc_update_bits(codec, WM8990_POWER_MANAGEMENT_1,
+                                   WM8990_VMID_MODE_MASK, 0x4);
                break;
 
        case SND_SOC_BIAS_OFF:
@@ -1241,8 +1244,8 @@ static int wm8990_set_bias_level(struct snd_soc_codec *codec,
                        WM8990_BUFIOEN);
 
                /* mute DAC */
-               val = snd_soc_read(codec, WM8990_DAC_CTRL);
-               snd_soc_write(codec, WM8990_DAC_CTRL, val | WM8990_DAC_MUTE);
+               snd_soc_update_bits(codec, WM8990_DAC_CTRL,
+                                   WM8990_DAC_MUTE, WM8990_DAC_MUTE);
 
                /* Enable any disabled outputs */
                snd_soc_write(codec, WM8990_POWER_MANAGEMENT_1, 0x1f03);
@@ -1319,19 +1322,6 @@ static int wm8990_suspend(struct snd_soc_codec *codec, pm_message_t state)
 
 static int wm8990_resume(struct snd_soc_codec *codec)
 {
-       int i;
-       u8 data[2];
-       u16 *cache = codec->reg_cache;
-
-       /* Sync reg_cache with the hardware */
-       for (i = 0; i < ARRAY_SIZE(wm8990_reg); i++) {
-               if (i + 1 == WM8990_RESET)
-                       continue;
-               data[0] = ((i + 1) << 1) | ((cache[i] >> 8) & 0x0001);
-               data[1] = cache[i] & 0x00ff;
-               codec->hw_write(codec->control_data, data, 2);
-       }
-
        wm8990_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
        return 0;
 }
@@ -1343,7 +1333,6 @@ static int wm8990_resume(struct snd_soc_codec *codec)
 static int wm8990_probe(struct snd_soc_codec *codec)
 {
        int ret;
-       u16 reg;
 
        ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_I2C);
        if (ret < 0) {
@@ -1356,15 +1345,14 @@ static int wm8990_probe(struct snd_soc_codec *codec)
        /* charge output caps */
        wm8990_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
-       reg = snd_soc_read(codec, WM8990_AUDIO_INTERFACE_4);
-       snd_soc_write(codec, WM8990_AUDIO_INTERFACE_4, reg | WM8990_ALRCGPIO1);
+       snd_soc_update_bits(codec, WM8990_AUDIO_INTERFACE_4,
+                           WM8990_ALRCGPIO1, WM8990_ALRCGPIO1);
 
-       reg = snd_soc_read(codec, WM8990_GPIO1_GPIO2) &
-               ~WM8990_GPIO1_SEL_MASK;
-       snd_soc_write(codec, WM8990_GPIO1_GPIO2, reg | 1);
+       snd_soc_update_bits(codec, WM8990_GPIO1_GPIO2,
+                           WM8990_GPIO1_SEL_MASK, 1);
 
-       reg = snd_soc_read(codec, WM8990_POWER_MANAGEMENT_2);
-       snd_soc_write(codec, WM8990_POWER_MANAGEMENT_2, reg | WM8990_OPCLK_ENA);
+       snd_soc_update_bits(codec, WM8990_POWER_MANAGEMENT_2,
+                           WM8990_OPCLK_ENA, WM8990_OPCLK_ENA);
 
        snd_soc_write(codec, WM8990_LEFT_OUTPUT_VOLUME, 0x50 | (1<<8));
        snd_soc_write(codec, WM8990_RIGHT_OUTPUT_VOLUME, 0x50 | (1<<8));
@@ -1392,6 +1380,7 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8990 = {
        .reg_cache_size = ARRAY_SIZE(wm8990_reg),
        .reg_word_size = sizeof(u16),
        .reg_cache_default = wm8990_reg,
+       .volatile_register = wm8990_volatile_register,
 };
 
 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
index 6af23d06870f8a03d1a8a1910577d6a13fef67a3..c9ab3ba9bcedf4269f3b9d9f00a146d0a7d4a8c8 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2007-2010 Wolfson Microelectronics PLC.
  * Author: Graeme Gregory
- *         linux@wolfsonmicro.com
+ *         Graeme.Gregory@wolfsonmicro.com
  *
  *  This program is free software; you can redistribute  it and/or modify it
  *  under  the terms of  the GNU General  Public License as published by the
@@ -393,7 +393,7 @@ static int inmixer_event(struct snd_soc_dapm_widget *w,
                         (1 << WM8991_AINRMUX_PWR_BIT)))
                reg |= WM8991_AINR_ENA;
        else
-               reg &= ~WM8991_AINL_ENA;
+               reg &= ~WM8991_AINR_ENA;
 
        snd_soc_write(w->codec, WM8991_POWER_MANAGEMENT_2, reg);
        return 0;
@@ -1264,7 +1264,6 @@ static int wm8991_probe(struct snd_soc_codec *codec)
 {
        struct wm8991_priv *wm8991;
        int ret;
-       unsigned int reg;
 
        wm8991 = snd_soc_codec_get_drvdata(codec);
 
@@ -1282,19 +1281,18 @@ static int wm8991_probe(struct snd_soc_codec *codec)
 
        wm8991_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
-       reg = snd_soc_read(codec, WM8991_AUDIO_INTERFACE_4);
-       snd_soc_write(codec, WM8991_AUDIO_INTERFACE_4, reg | WM8991_ALRCGPIO1);
+       snd_soc_update_bits(codec, WM8991_AUDIO_INTERFACE_4,
+                           WM8991_ALRCGPIO1, WM8991_ALRCGPIO1);
 
-       reg = snd_soc_read(codec, WM8991_GPIO1_GPIO2) &
-             ~WM8991_GPIO1_SEL_MASK;
-       snd_soc_write(codec, WM8991_GPIO1_GPIO2, reg | 1);
+       snd_soc_update_bits(codec, WM8991_GPIO1_GPIO2,
+                           WM8991_GPIO1_SEL_MASK, 1);
 
-       reg = snd_soc_read(codec, WM8991_POWER_MANAGEMENT_1);
-       snd_soc_write(codec, WM8991_POWER_MANAGEMENT_1, reg | WM8991_VREF_ENA|
-                     WM8991_VMID_MODE_MASK);
+       snd_soc_update_bits(codec, WM8991_POWER_MANAGEMENT_1,
+                           WM8991_VREF_ENA | WM8991_VMID_MODE_MASK,
+                           WM8991_VREF_ENA | WM8991_VMID_MODE_MASK);
 
-       reg = snd_soc_read(codec, WM8991_POWER_MANAGEMENT_2);
-       snd_soc_write(codec, WM8991_POWER_MANAGEMENT_2, reg | WM8991_OPCLK_ENA);
+       snd_soc_update_bits(codec, WM8991_POWER_MANAGEMENT_2,
+                           WM8991_OPCLK_ENA, WM8991_OPCLK_ENA);
 
        snd_soc_write(codec, WM8991_DAC_CTRL, 0);
        snd_soc_write(codec, WM8991_LEFT_OUTPUT_VOLUME, 0x50 | (1<<8));
index 6e85b8869af7171882d5476137ed63004402bef1..eec8e143511665a538c6950a4f679ad217aad827 100644 (file)
@@ -847,6 +847,7 @@ SND_SOC_DAPM_SUPPLY("CLK_SYS", WM8993_BUS_CONTROL_1, 1, 0, clk_sys_event,
                    SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
 SND_SOC_DAPM_SUPPLY("TOCLK", WM8993_CLOCKING_1, 14, 0, NULL, 0),
 SND_SOC_DAPM_SUPPLY("CLK_DSP", WM8993_CLOCKING_3, 0, 0, NULL, 0),
+SND_SOC_DAPM_SUPPLY("VMID", SND_SOC_NOPM, 0, 0, NULL, 0),
 
 SND_SOC_DAPM_ADC("ADCL", NULL, WM8993_POWER_MANAGEMENT_2, 1, 0),
 SND_SOC_DAPM_ADC("ADCR", NULL, WM8993_POWER_MANAGEMENT_2, 0, 0),
@@ -880,6 +881,9 @@ SND_SOC_DAPM_PGA("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0),
 };
 
 static const struct snd_soc_dapm_route routes[] = {
+       { "MICBIAS1", NULL, "VMID" },
+       { "MICBIAS2", NULL, "VMID" },
+
        { "ADCL", NULL, "CLK_SYS" },
        { "ADCL", NULL, "CLK_DSP" },
        { "ADCR", NULL, "CLK_SYS" },
@@ -1433,7 +1437,8 @@ static int wm8993_probe(struct snd_soc_codec *codec)
        int ret, i, val;
 
        wm8993->hubs_data.hp_startup_mode = 1;
-       wm8993->hubs_data.dcs_codes = -2;
+       wm8993->hubs_data.dcs_codes_l = -2;
+       wm8993->hubs_data.dcs_codes_r = -2;
        wm8993->hubs_data.series_startup = 1;
 
        ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_I2C);
index a87adbd05ee11151535bb3231122655c0c226525..df5a8b9a250f47362cc8e03a0f65e8486d5fe188 100644 (file)
@@ -1073,8 +1073,8 @@ const struct wm8994_access_mask wm8994_access_masks[WM8994_CACHE_SIZE] = {
        { 0x0000, 0x0000 }, /* R1069 */
        { 0x0000, 0x0000 }, /* R1070 */
        { 0x0000, 0x0000 }, /* R1071 */
-       { 0x0000, 0x0000 }, /* R1072 */
-       { 0x0000, 0x0000 }, /* R1073 */
+       { 0x006F, 0x006F }, /* R1072  - AIF1 DAC1 Noise Gate */
+       { 0x006F, 0x006F }, /* R1073  - AIF1 DAC2 Noise Gate */
        { 0x0000, 0x0000 }, /* R1074 */
        { 0x0000, 0x0000 }, /* R1075 */
        { 0x0000, 0x0000 }, /* R1076 */
@@ -1329,7 +1329,7 @@ const struct wm8994_access_mask wm8994_access_masks[WM8994_CACHE_SIZE] = {
        { 0x0000, 0x0000 }, /* R1325 */
        { 0x0000, 0x0000 }, /* R1326 */
        { 0x0000, 0x0000 }, /* R1327 */
-       { 0x0000, 0x0000 }, /* R1328 */
+       { 0x006F, 0x006F }, /* R1328  - AIF2 DAC Noise Gate */
        { 0x0000, 0x0000 }, /* R1329 */
        { 0x0000, 0x0000 }, /* R1330 */
        { 0x0000, 0x0000 }, /* R1331 */
@@ -1635,8 +1635,8 @@ const u16 wm8994_reg_defaults[WM8994_CACHE_SIZE] = {
        0x0000,     /* R58    - MICBIAS */
        0x000D,     /* R59    - LDO 1 */
        0x0003,     /* R60    - LDO 2 */
-       0x0000,     /* R61 */
-       0x0000,     /* R62 */
+       0x0039,     /* R61    - MICBIAS1 */
+       0x0039,     /* R62    - MICBIAS2 */
        0x0000,     /* R63 */
        0x0000,     /* R64 */
        0x0000,     /* R65 */
@@ -2646,8 +2646,8 @@ const u16 wm8994_reg_defaults[WM8994_CACHE_SIZE] = {
        0x0000,     /* R1069 */
        0x0000,     /* R1070 */
        0x0000,     /* R1071 */
-       0x0000,     /* R1072 */
-       0x0000,     /* R1073 */
+       0x0068,     /* R1072  - AIF1 DAC1 Noise Gate */
+       0x0068,     /* R1073  - AIF1 DAC2 Noise Gate */
        0x0000,     /* R1074 */
        0x0000,     /* R1075 */
        0x0000,     /* R1076 */
@@ -2902,7 +2902,7 @@ const u16 wm8994_reg_defaults[WM8994_CACHE_SIZE] = {
        0x0000,     /* R1325 */
        0x0000,     /* R1326 */
        0x0000,     /* R1327 */
-       0x0000,     /* R1328 */
+       0x0068,     /* R1328  - AIF2 DAC Noise Gate */
        0x0000,     /* R1329 */
        0x0000,     /* R1330 */
        0x0000,     /* R1331 */
index b393f9fac97a5e75a8bc1b44cb3c6f898482cad3..6b73efd269917367293021edde0f330ee7c3b722 100644 (file)
@@ -107,6 +107,7 @@ static int wm8994_volatile(struct snd_soc_codec *codec, unsigned int reg)
        case WM8994_LDO_2:
        case WM8958_DSP2_EXECCONTROL:
        case WM8958_MIC_DETECT_3:
+       case WM8994_DC_SERVO_4E:
                return 1;
        default:
                return 0;
@@ -207,7 +208,7 @@ static int configure_aif_clock(struct snd_soc_codec *codec, int aif)
 static int configure_clock(struct snd_soc_codec *codec)
 {
        struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
-       int old, new;
+       int change, new;
 
        /* Bring up the AIF clocks first */
        configure_aif_clock(codec, 0);
@@ -228,14 +229,11 @@ static int configure_clock(struct snd_soc_codec *codec)
        else
                new = 0;
 
-       old = snd_soc_read(codec, WM8994_CLOCKING_1) & WM8994_SYSCLK_SRC;
-
-       /* If there's no change then we're done. */
-       if (old == new)
+       change = snd_soc_update_bits(codec, WM8994_CLOCKING_1,
+                                    WM8994_SYSCLK_SRC, new);
+       if (!change)
                return 0;
 
-       snd_soc_update_bits(codec, WM8994_CLOCKING_1, WM8994_SYSCLK_SRC, new);
-
        snd_soc_dapm_sync(&codec->dapm);
 
        return 0;
@@ -281,6 +279,8 @@ static const DECLARE_TLV_DB_SCALE(digital_tlv, -7200, 75, 1);
 static const DECLARE_TLV_DB_SCALE(st_tlv, -3600, 300, 0);
 static const DECLARE_TLV_DB_SCALE(wm8994_3d_tlv, -1600, 183, 0);
 static const DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
+static const DECLARE_TLV_DB_SCALE(ng_tlv, -10200, 600, 0);
+static const DECLARE_TLV_DB_SCALE(mixin_boost_tlv, 0, 900, 0);
 
 #define WM8994_DRC_SWITCH(xname, reg, shift) \
 {      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
@@ -660,8 +660,52 @@ SOC_SINGLE_TLV("AIF2 EQ5 Volume", WM8994_AIF2_EQ_GAINS_2, 6, 31, 0,
               eq_tlv),
 };
 
+static const char *wm8958_ng_text[] = {
+       "30ms", "125ms", "250ms", "500ms",
+};
+
+static const struct soc_enum wm8958_aif1dac1_ng_hold =
+       SOC_ENUM_SINGLE(WM8958_AIF1_DAC1_NOISE_GATE,
+                       WM8958_AIF1DAC1_NG_THR_SHIFT, 4, wm8958_ng_text);
+
+static const struct soc_enum wm8958_aif1dac2_ng_hold =
+       SOC_ENUM_SINGLE(WM8958_AIF1_DAC2_NOISE_GATE,
+                       WM8958_AIF1DAC2_NG_THR_SHIFT, 4, wm8958_ng_text);
+
+static const struct soc_enum wm8958_aif2dac_ng_hold =
+       SOC_ENUM_SINGLE(WM8958_AIF2_DAC_NOISE_GATE,
+                       WM8958_AIF2DAC_NG_THR_SHIFT, 4, wm8958_ng_text);
+
 static const struct snd_kcontrol_new wm8958_snd_controls[] = {
 SOC_SINGLE_TLV("AIF3 Boost Volume", WM8958_AIF3_CONTROL_2, 10, 3, 0, aif_tlv),
+
+SOC_SINGLE("AIF1DAC1 Noise Gate Switch", WM8958_AIF1_DAC1_NOISE_GATE,
+          WM8958_AIF1DAC1_NG_ENA_SHIFT, 1, 0),
+SOC_ENUM("AIF1DAC1 Noise Gate Hold Time", wm8958_aif1dac1_ng_hold),
+SOC_SINGLE_TLV("AIF1DAC1 Noise Gate Threshold Volume",
+              WM8958_AIF1_DAC1_NOISE_GATE, WM8958_AIF1DAC1_NG_THR_SHIFT,
+              7, 1, ng_tlv),
+
+SOC_SINGLE("AIF1DAC2 Noise Gate Switch", WM8958_AIF1_DAC2_NOISE_GATE,
+          WM8958_AIF1DAC2_NG_ENA_SHIFT, 1, 0),
+SOC_ENUM("AIF1DAC2 Noise Gate Hold Time", wm8958_aif1dac2_ng_hold),
+SOC_SINGLE_TLV("AIF1DAC2 Noise Gate Threshold Volume",
+              WM8958_AIF1_DAC2_NOISE_GATE, WM8958_AIF1DAC2_NG_THR_SHIFT,
+              7, 1, ng_tlv),
+
+SOC_SINGLE("AIF2DAC Noise Gate Switch", WM8958_AIF2_DAC_NOISE_GATE,
+          WM8958_AIF2DAC_NG_ENA_SHIFT, 1, 0),
+SOC_ENUM("AIF2DAC Noise Gate Hold Time", wm8958_aif2dac_ng_hold),
+SOC_SINGLE_TLV("AIF2DAC Noise Gate Threshold Volume",
+              WM8958_AIF2_DAC_NOISE_GATE, WM8958_AIF2DAC_NG_THR_SHIFT,
+              7, 1, ng_tlv),
+};
+
+static const struct snd_kcontrol_new wm1811_snd_controls[] = {
+SOC_SINGLE_TLV("MIXINL IN1LP Boost Volume", WM8994_INPUT_MIXER_1, 7, 1, 0,
+              mixin_boost_tlv),
+SOC_SINGLE_TLV("MIXINL IN1RP Boost Volume", WM8994_INPUT_MIXER_1, 8, 1, 0,
+              mixin_boost_tlv),
 };
 
 static int clk_sys_event(struct snd_soc_dapm_widget *w,
@@ -681,6 +725,97 @@ static int clk_sys_event(struct snd_soc_dapm_widget *w,
        return 0;
 }
 
+static void vmid_reference(struct snd_soc_codec *codec)
+{
+       struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+
+       wm8994->vmid_refcount++;
+
+       dev_dbg(codec->dev, "Referencing VMID, refcount is now %d\n",
+               wm8994->vmid_refcount);
+
+       if (wm8994->vmid_refcount == 1) {
+               /* Startup bias, VMID ramp & buffer */
+               snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
+                                   WM8994_STARTUP_BIAS_ENA |
+                                   WM8994_VMID_BUF_ENA |
+                                   WM8994_VMID_RAMP_MASK,
+                                   WM8994_STARTUP_BIAS_ENA |
+                                   WM8994_VMID_BUF_ENA |
+                                   (0x11 << WM8994_VMID_RAMP_SHIFT));
+
+               /* Main bias enable, VMID=2x40k */
+               snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
+                                   WM8994_BIAS_ENA |
+                                   WM8994_VMID_SEL_MASK,
+                                   WM8994_BIAS_ENA | 0x2);
+
+               msleep(20);
+       }
+}
+
+static void vmid_dereference(struct snd_soc_codec *codec)
+{
+       struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+
+       wm8994->vmid_refcount--;
+
+       dev_dbg(codec->dev, "Dereferencing VMID, refcount is now %d\n",
+               wm8994->vmid_refcount);
+
+       if (wm8994->vmid_refcount == 0) {
+               /* Switch over to startup biases */
+               snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
+                                   WM8994_BIAS_SRC |
+                                   WM8994_STARTUP_BIAS_ENA |
+                                   WM8994_VMID_BUF_ENA |
+                                   WM8994_VMID_RAMP_MASK,
+                                   WM8994_BIAS_SRC |
+                                   WM8994_STARTUP_BIAS_ENA |
+                                   WM8994_VMID_BUF_ENA |
+                                   (1 << WM8994_VMID_RAMP_SHIFT));
+
+               /* Disable main biases */
+               snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
+                                   WM8994_BIAS_ENA |
+                                   WM8994_VMID_SEL_MASK, 0);
+
+               /* Discharge line */
+               snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
+                                   WM8994_LINEOUT1_DISCH |
+                                   WM8994_LINEOUT2_DISCH,
+                                   WM8994_LINEOUT1_DISCH |
+                                   WM8994_LINEOUT2_DISCH);
+
+               msleep(5);
+
+               /* Switch off startup biases */
+               snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
+                                   WM8994_BIAS_SRC |
+                                   WM8994_STARTUP_BIAS_ENA |
+                                   WM8994_VMID_BUF_ENA |
+                                   WM8994_VMID_RAMP_MASK, 0);
+       }
+}
+
+static int vmid_event(struct snd_soc_dapm_widget *w,
+                     struct snd_kcontrol *kcontrol, int event)
+{
+       struct snd_soc_codec *codec = w->codec;
+
+       switch (event) {
+       case SND_SOC_DAPM_PRE_PMU:
+               vmid_reference(codec);
+               break;
+
+       case SND_SOC_DAPM_POST_PMD:
+               vmid_dereference(codec);
+               break;
+       }
+
+       return 0;
+}
+
 static void wm8994_update_class_w(struct snd_soc_codec *codec)
 {
        struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
@@ -1208,6 +1343,8 @@ SND_SOC_DAPM_INPUT("Clock"),
 
 SND_SOC_DAPM_SUPPLY_S("MICBIAS Supply", 1, SND_SOC_NOPM, 0, 0, micbias_ev,
                      SND_SOC_DAPM_PRE_PMU),
+SND_SOC_DAPM_SUPPLY("VMID", SND_SOC_NOPM, 0, 0, vmid_event,
+                   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
 
 SND_SOC_DAPM_SUPPLY("CLK_SYS", SND_SOC_NOPM, 0, 0, clk_sys_event,
                    SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
@@ -1282,7 +1419,7 @@ SND_SOC_DAPM_MUX("AIF2DAC Mux", SND_SOC_NOPM, 0, 0, &aif2dac_mux),
 SND_SOC_DAPM_MUX("AIF2ADC Mux", SND_SOC_NOPM, 0, 0, &aif2adc_mux),
 
 SND_SOC_DAPM_AIF_IN("AIF3DACDAT", "AIF3 Playback", 0, SND_SOC_NOPM, 0, 0),
-SND_SOC_DAPM_AIF_IN("AIF3ADCDAT", "AIF3 Capture", 0, SND_SOC_NOPM, 0, 0),
+SND_SOC_DAPM_AIF_OUT("AIF3ADCDAT", "AIF3 Capture", 0, SND_SOC_NOPM, 0, 0),
 
 SND_SOC_DAPM_SUPPLY("TOCLK", WM8994_CLOCKING_1, 4, 0, NULL, 0),
 
@@ -1525,6 +1662,8 @@ static const struct snd_soc_dapm_route wm8994_revd_intercon[] = {
 static const struct snd_soc_dapm_route wm8994_intercon[] = {
        { "AIF2DACL", NULL, "AIF2DAC Mux" },
        { "AIF2DACR", NULL, "AIF2DAC Mux" },
+       { "MICBIAS1", NULL, "VMID" },
+       { "MICBIAS2", NULL, "VMID" },
 };
 
 static const struct snd_soc_dapm_route wm8958_intercon[] = {
@@ -1629,10 +1768,12 @@ static int _wm8994_set_fll(struct snd_soc_codec *codec, int id, int src,
                          unsigned int freq_in, unsigned int freq_out)
 {
        struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+       struct wm8994 *control = codec->control_data;
        int reg_offset, ret;
        struct fll_div fll;
        u16 reg, aif1, aif2;
        unsigned long timeout;
+       bool was_enabled;
 
        aif1 = snd_soc_read(codec, WM8994_AIF1_CLOCKING_1)
                & WM8994_AIF1CLK_ENA;
@@ -1653,6 +1794,9 @@ static int _wm8994_set_fll(struct snd_soc_codec *codec, int id, int src,
                return -EINVAL;
        }
 
+       reg = snd_soc_read(codec, WM8994_FLL1_CONTROL_1 + reg_offset);
+       was_enabled = reg & WM8994_FLL1_ENA;
+
        switch (src) {
        case 0:
                /* Allow no source specification when stopping */
@@ -1719,6 +1863,21 @@ static int _wm8994_set_fll(struct snd_soc_codec *codec, int id, int src,
 
        /* Enable (with fractional mode if required) */
        if (freq_out) {
+               /* Enable VMID if we need it */
+               if (!was_enabled) {
+                       switch (control->type) {
+                       case WM8994:
+                               vmid_reference(codec);
+                               break;
+                       case WM8958:
+                               if (wm8994->revision < 1)
+                                       vmid_reference(codec);
+                               break;
+                       default:
+                               break;
+                       }
+               }
+
                if (fll.k)
                        reg = WM8994_FLL1_ENA | WM8994_FLL1_FRAC;
                else
@@ -1736,6 +1895,20 @@ static int _wm8994_set_fll(struct snd_soc_codec *codec, int id, int src,
                } else {
                        msleep(5);
                }
+       } else {
+               if (was_enabled) {
+                       switch (control->type) {
+                       case WM8994:
+                               vmid_dereference(codec);
+                               break;
+                       case WM8958:
+                               if (wm8994->revision < 1)
+                                       vmid_dereference(codec);
+                               break;
+                       default:
+                               break;
+                       }
+               }
        }
 
        wm8994->fll[id].in = freq_in;
@@ -1852,9 +2025,6 @@ static int wm8994_set_bias_level(struct snd_soc_codec *codec,
                break;
 
        case SND_SOC_BIAS_PREPARE:
-               /* VMID=2x40k */
-               snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
-                                   WM8994_VMID_SEL_MASK, 0x2);
                break;
 
        case SND_SOC_BIAS_STANDBY:
@@ -1888,6 +2058,15 @@ static int wm8994_set_bias_level(struct snd_soc_codec *codec,
                                                            WM8958_CP_DISCH);
                                }
                                break;
+
+                       case WM1811:
+                               if (wm8994->revision < 2) {
+                                       snd_soc_write(codec, 0x102, 0x3);
+                                       snd_soc_write(codec, 0x5d, 0x7e);
+                                       snd_soc_write(codec, 0x5e, 0x0);
+                                       snd_soc_write(codec, 0x102, 0x0);
+                               }
+                               break;
                        }
 
                        /* Discharge LINEOUT1 & 2 */
@@ -1896,65 +2075,13 @@ static int wm8994_set_bias_level(struct snd_soc_codec *codec,
                                            WM8994_LINEOUT2_DISCH,
                                            WM8994_LINEOUT1_DISCH |
                                            WM8994_LINEOUT2_DISCH);
-
-                       /* Startup bias, VMID ramp & buffer */
-                       snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
-                                           WM8994_STARTUP_BIAS_ENA |
-                                           WM8994_VMID_BUF_ENA |
-                                           WM8994_VMID_RAMP_MASK,
-                                           WM8994_STARTUP_BIAS_ENA |
-                                           WM8994_VMID_BUF_ENA |
-                                           (0x11 << WM8994_VMID_RAMP_SHIFT));
-
-                       /* Main bias enable, VMID=2x40k */
-                       snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
-                                           WM8994_BIAS_ENA |
-                                           WM8994_VMID_SEL_MASK,
-                                           WM8994_BIAS_ENA | 0x2);
-
-                       msleep(20);
                }
 
-               /* VMID=2x500k */
-               snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
-                                   WM8994_VMID_SEL_MASK, 0x4);
 
                break;
 
        case SND_SOC_BIAS_OFF:
                if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY) {
-                       /* Switch over to startup biases */
-                       snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
-                                           WM8994_BIAS_SRC |
-                                           WM8994_STARTUP_BIAS_ENA |
-                                           WM8994_VMID_BUF_ENA |
-                                           WM8994_VMID_RAMP_MASK,
-                                           WM8994_BIAS_SRC |
-                                           WM8994_STARTUP_BIAS_ENA |
-                                           WM8994_VMID_BUF_ENA |
-                                           (1 << WM8994_VMID_RAMP_SHIFT));
-
-                       /* Disable main biases */
-                       snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
-                                           WM8994_BIAS_ENA |
-                                           WM8994_VMID_SEL_MASK, 0);
-
-                       /* Discharge line */
-                       snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
-                                           WM8994_LINEOUT1_DISCH |
-                                           WM8994_LINEOUT2_DISCH,
-                                           WM8994_LINEOUT1_DISCH |
-                                           WM8994_LINEOUT2_DISCH);
-
-                       msleep(5);
-
-                       /* Switch off startup biases */
-                       snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
-                                           WM8994_BIAS_SRC |
-                                           WM8994_STARTUP_BIAS_ENA |
-                                           WM8994_VMID_BUF_ENA |
-                                           WM8994_VMID_RAMP_MASK, 0);
-
                        wm8994->cur_fw = NULL;
 
                        pm_runtime_put(codec->dev);
@@ -2055,10 +2182,18 @@ static int wm8994_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
 
        /* The AIF2 format configuration needs to be mirrored to AIF3
         * on WM8958 if it's in use so just do it all the time. */
-       if (control->type == WM8958 && dai->id == 2)
-               snd_soc_update_bits(codec, WM8958_AIF3_CONTROL_1,
-                                   WM8994_AIF1_LRCLK_INV |
-                                   WM8958_AIF3_FMT_MASK, aif1);
+       switch (control->type) {
+       case WM1811:
+       case WM8958:
+               if (dai->id == 2)
+                       snd_soc_update_bits(codec, WM8958_AIF3_CONTROL_1,
+                                           WM8994_AIF1_LRCLK_INV |
+                                           WM8958_AIF3_FMT_MASK, aif1);
+               break;
+
+       default:
+               break;
+       }
 
        snd_soc_update_bits(codec, aif1_reg,
                            WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV |
@@ -2100,7 +2235,6 @@ static int wm8994_hw_params(struct snd_pcm_substream *substream,
                            struct snd_soc_dai *dai)
 {
        struct snd_soc_codec *codec = dai->codec;
-       struct wm8994 *control = codec->control_data;
        struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
        int aif1_reg;
        int aif2_reg;
@@ -2143,14 +2277,6 @@ static int wm8994_hw_params(struct snd_pcm_substream *substream,
                        dev_dbg(codec->dev, "AIF2 using split LRCLK\n");
                }
                break;
-       case 3:
-               switch (control->type) {
-               case WM8958:
-                       aif1_reg = WM8958_AIF3_CONTROL_1;
-                       break;
-               default:
-                       return 0;
-               }
        default:
                return -EINVAL;
        }
@@ -2271,6 +2397,7 @@ static int wm8994_aif3_hw_params(struct snd_pcm_substream *substream,
        switch (dai->id) {
        case 3:
                switch (control->type) {
+               case WM1811:
                case WM8958:
                        aif1_reg = WM8958_AIF3_CONTROL_1;
                        break;
@@ -2311,7 +2438,7 @@ static void wm8994_aif_shutdown(struct snd_pcm_substream *substream,
                rate_reg = WM8994_AIF1_RATE;
                break;
        case 2:
-               rate_reg = WM8994_AIF1_RATE;
+               rate_reg = WM8994_AIF2_RATE;
                break;
        default:
                break;
@@ -2384,6 +2511,21 @@ static int wm8994_set_tristate(struct snd_soc_dai *codec_dai, int tristate)
        return snd_soc_update_bits(codec, reg, mask, val);
 }
 
+static int wm8994_aif2_probe(struct snd_soc_dai *dai)
+{
+       struct snd_soc_codec *codec = dai->codec;
+
+       /* Disable the pulls on the AIF if we're using it to save power. */
+       snd_soc_update_bits(codec, WM8994_GPIO_3,
+                           WM8994_GPN_PU | WM8994_GPN_PD, 0);
+       snd_soc_update_bits(codec, WM8994_GPIO_4,
+                           WM8994_GPN_PU | WM8994_GPN_PD, 0);
+       snd_soc_update_bits(codec, WM8994_GPIO_5,
+                           WM8994_GPN_PU | WM8994_GPN_PD, 0);
+
+       return 0;
+}
+
 #define WM8994_RATES SNDRV_PCM_RATE_8000_96000
 
 #define WM8994_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
@@ -2451,6 +2593,7 @@ static struct snd_soc_dai_driver wm8994_dai[] = {
                        .rates = WM8994_RATES,
                        .formats = WM8994_FORMATS,
                },
+               .probe = wm8994_aif2_probe,
                .ops = &wm8994_aif2_dai_ops,
        },
        {
@@ -2485,6 +2628,7 @@ static int wm8994_suspend(struct snd_soc_codec *codec, pm_message_t state)
        case WM8994:
                snd_soc_update_bits(codec, WM8994_MICBIAS, WM8994_MICD_ENA, 0);
                break;
+       case WM1811:
        case WM8958:
                snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
                                    WM8958_MICD_ENA, 0);
@@ -2553,6 +2697,7 @@ static int wm8994_resume(struct snd_soc_codec *codec)
                        snd_soc_update_bits(codec, WM8994_MICBIAS,
                                            WM8994_MICD_ENA, WM8994_MICD_ENA);
                break;
+       case WM1811:
        case WM8958:
                if (wm8994->jack_cb)
                        snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
@@ -2851,8 +2996,13 @@ int wm8958_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
        struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
        struct wm8994 *control = codec->control_data;
 
-       if (control->type != WM8958)
+       switch (control->type) {
+       case WM1811:
+       case WM8958:
+               break;
+       default:
                return -EINVAL;
+       }
 
        if (jack) {
                if (!cb) {
@@ -2916,6 +3066,24 @@ static irqreturn_t wm8994_fifo_error(int irq, void *data)
        return IRQ_HANDLED;
 }
 
+static irqreturn_t wm8994_temp_warn(int irq, void *data)
+{
+       struct snd_soc_codec *codec = data;
+
+       dev_err(codec->dev, "Thermal warning\n");
+
+       return IRQ_HANDLED;
+}
+
+static irqreturn_t wm8994_temp_shut(int irq, void *data)
+{
+       struct snd_soc_codec *codec = data;
+
+       dev_crit(codec->dev, "Thermal shutdown\n");
+
+       return IRQ_HANDLED;
+}
+
 static int wm8994_codec_probe(struct snd_soc_codec *codec)
 {
        struct wm8994 *control;
@@ -2972,13 +3140,14 @@ static int wm8994_codec_probe(struct snd_soc_codec *codec)
                switch (wm8994->revision) {
                case 2:
                case 3:
-                       wm8994->hubs.dcs_codes = -5;
+                       wm8994->hubs.dcs_codes_l = -5;
+                       wm8994->hubs.dcs_codes_r = -5;
                        wm8994->hubs.hp_startup_mode = 1;
                        wm8994->hubs.dcs_readback_mode = 1;
                        wm8994->hubs.series_startup = 1;
                        break;
                default:
-                       wm8994->hubs.dcs_readback_mode = 1;
+                       wm8994->hubs.dcs_readback_mode = 2;
                        break;
                }
                break;
@@ -2987,12 +3156,34 @@ static int wm8994_codec_probe(struct snd_soc_codec *codec)
                wm8994->hubs.dcs_readback_mode = 1;
                break;
 
+       case WM1811:
+               wm8994->hubs.dcs_readback_mode = 2;
+               wm8994->hubs.no_series_update = 1;
+
+               switch (wm8994->revision) {
+               case 0:
+               case 1:
+                       wm8994->hubs.dcs_codes_l = -9;
+                       wm8994->hubs.dcs_codes_r = -5;
+                       break;
+               default:
+                       break;
+               }
+
+               snd_soc_update_bits(codec, WM8994_ANALOGUE_HP_1,
+                                   WM1811_HPOUT1_ATTN, WM1811_HPOUT1_ATTN);
+               break;
+
        default:
                break;
        }
 
        wm8994_request_irq(codec->control_data, WM8994_IRQ_FIFOS_ERR,
                           wm8994_fifo_error, "FIFO error", codec);
+       wm8994_request_irq(wm8994->control_data, WM8994_IRQ_TEMP_WARN,
+                          wm8994_temp_warn, "Thermal warning", codec);
+       wm8994_request_irq(wm8994->control_data, WM8994_IRQ_TEMP_SHUT,
+                          wm8994_temp_shut, "Thermal shutdown", codec);
 
        ret = wm8994_request_irq(codec->control_data, WM8994_IRQ_DCS_DONE,
                                 wm_hubs_dcs_done, "DC servo done",
@@ -3043,6 +3234,7 @@ static int wm8994_codec_probe(struct snd_soc_codec *codec)
                break;
 
        case WM8958:
+       case WM1811:
                if (wm8994->micdet_irq) {
                        ret = request_threaded_irq(wm8994->micdet_irq, NULL,
                                                   wm8958_mic_irq,
@@ -3205,6 +3397,19 @@ static int wm8994_codec_probe(struct snd_soc_codec *codec)
                                                  ARRAY_SIZE(wm8994_dac_widgets));
                }
                break;
+
+       case WM1811:
+               snd_soc_add_controls(codec, wm8958_snd_controls,
+                                    ARRAY_SIZE(wm8958_snd_controls));
+               snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
+                                         ARRAY_SIZE(wm8958_dapm_widgets));
+               snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
+                                         ARRAY_SIZE(wm8994_lateclk_widgets));
+               snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
+                                         ARRAY_SIZE(wm8994_adc_widgets));
+               snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
+                                         ARRAY_SIZE(wm8994_dac_widgets));
+               break;
        }
                
 
@@ -3241,6 +3446,12 @@ static int wm8994_codec_probe(struct snd_soc_codec *codec)
 
                wm8958_dsp2_init(codec);
                break;
+       case WM1811:
+               snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
+                                       ARRAY_SIZE(wm8994_lateclk_intercon));
+               snd_soc_dapm_add_routes(dapm, wm8958_intercon,
+                                       ARRAY_SIZE(wm8958_intercon));
+               break;
        }
 
        return 0;
@@ -3257,6 +3468,8 @@ err_irq:
        wm8994_free_irq(codec->control_data, WM8994_IRQ_DCS_DONE,
                        &wm8994->hubs);
        wm8994_free_irq(codec->control_data, WM8994_IRQ_FIFOS_ERR, codec);
+       wm8994_free_irq(codec->control_data, WM8994_IRQ_TEMP_SHUT, codec);
+       wm8994_free_irq(codec->control_data, WM8994_IRQ_TEMP_WARN, codec);
 err:
        kfree(wm8994);
        return ret;
@@ -3279,6 +3492,8 @@ static int  wm8994_codec_remove(struct snd_soc_codec *codec)
        wm8994_free_irq(codec->control_data, WM8994_IRQ_DCS_DONE,
                        &wm8994->hubs);
        wm8994_free_irq(codec->control_data, WM8994_IRQ_FIFOS_ERR, codec);
+       wm8994_free_irq(codec->control_data, WM8994_IRQ_TEMP_SHUT, codec);
+       wm8994_free_irq(codec->control_data, WM8994_IRQ_TEMP_WARN, codec);
 
        switch (control->type) {
        case WM8994:
@@ -3292,6 +3507,7 @@ static int  wm8994_codec_remove(struct snd_soc_codec *codec)
                                wm8994);
                break;
 
+       case WM1811:
        case WM8958:
                if (wm8994->micdet_irq)
                        free_irq(wm8994->micdet_irq, wm8994);
index 1ab2266039f7ca80b023f212888c1c7f8398bf94..f4f1355efc82ec9708e24993525d65aad9b54e1b 100644 (file)
@@ -83,6 +83,8 @@ struct wm8994_priv {
        struct completion fll_locked[2];
        bool fll_locked_irq;
 
+       int vmid_refcount;
+
        int dac_rates[2];
        int lrclk_shared[2];
 
index 5ad873fda814d9e20502684c2db87ebc13407b34..78eeb21e66964be9f2457083cf4217b5ac0d5fbd 100644 (file)
@@ -485,7 +485,7 @@ static int configure_aif_clock(struct snd_soc_codec *codec, int aif)
 static int configure_clock(struct snd_soc_codec *codec)
 {
        struct wm8995_priv *wm8995;
-       int old, new;
+       int change, new;
 
        wm8995 = snd_soc_codec_get_drvdata(codec);
 
@@ -509,15 +509,11 @@ static int configure_clock(struct snd_soc_codec *codec)
        else
                new = 0;
 
-       old = snd_soc_read(codec, WM8995_CLOCKING_1) & WM8995_SYSCLK_SRC;
-
-       /* If there's no change then we're done. */
-       if (old == new)
+       change = snd_soc_update_bits(codec, WM8995_CLOCKING_1,
+                                    WM8995_SYSCLK_SRC_MASK, new);
+       if (!change)
                return 0;
 
-       snd_soc_update_bits(codec, WM8995_CLOCKING_1,
-                           WM8995_SYSCLK_SRC_MASK, new);
-
        snd_soc_dapm_sync(&codec->dapm);
 
        return 0;
@@ -1573,11 +1569,16 @@ static int wm8995_resume(struct snd_soc_codec *codec)
 static int wm8995_remove(struct snd_soc_codec *codec)
 {
        struct wm8995_priv *wm8995;
-       struct i2c_client *i2c;
+       int i;
 
-       i2c = container_of(codec->dev, struct i2c_client, dev);
        wm8995 = snd_soc_codec_get_drvdata(codec);
        wm8995_set_bias_level(codec, SND_SOC_BIAS_OFF);
+
+       for (i = 0; i < ARRAY_SIZE(wm8995->supplies); ++i)
+               regulator_unregister_notifier(wm8995->supplies[i].consumer,
+                                             &wm8995->disable_nb[i]);
+
+       regulator_bulk_free(ARRAY_SIZE(wm8995->supplies), wm8995->supplies);
        return 0;
 }
 
@@ -1642,6 +1643,7 @@ static int wm8995_probe(struct snd_soc_codec *codec)
 
        if (ret != 0x8995) {
                dev_err(codec->dev, "Invalid device ID: %#x\n", ret);
+               ret = -EINVAL;
                goto err_reg_enable;
        }
 
index 0cdb9d1056712df48689c47eba7fa440fb73debe..645c980d6b80edd81b1f0886c013c34f884346d6 100644 (file)
 #define HPOUT2L 4
 #define HPOUT2R 8
 
-#define WM8996_NUM_SUPPLIES 4
+#define WM8996_NUM_SUPPLIES 3
 static const char *wm8996_supply_names[WM8996_NUM_SUPPLIES] = {
        "DBVDD",
        "AVDD1",
        "AVDD2",
-       "CPVDD",
 };
 
 struct wm8996_priv {
@@ -71,6 +70,8 @@ struct wm8996_priv {
 
        struct regulator_bulk_data supplies[WM8996_NUM_SUPPLIES];
        struct notifier_block disable_nb[WM8996_NUM_SUPPLIES];
+       struct regulator *cpvdd;
+       int bg_ena;
 
        struct wm8996_pdata pdata;
 
@@ -112,7 +113,6 @@ static int wm8996_regulator_event_##n(struct notifier_block *nb, \
 WM8996_REGULATOR_EVENT(0)
 WM8996_REGULATOR_EVENT(1)
 WM8996_REGULATOR_EVENT(2)
-WM8996_REGULATOR_EVENT(3)
 
 static const u16 wm8996_reg[WM8996_MAX_REGISTER] = {
        [WM8996_SOFTWARE_RESET] = 0x8996,
@@ -414,6 +414,7 @@ static const DECLARE_TLV_DB_SCALE(out_digital_tlv, -1200, 150, 0);
 static const DECLARE_TLV_DB_SCALE(out_tlv, -900, 75, 0);
 static const DECLARE_TLV_DB_SCALE(spk_tlv, -900, 150, 0);
 static const DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
+static const DECLARE_TLV_DB_SCALE(threedstereo_tlv, -1600, 183, 1);
 
 static const char *sidetone_hpf_text[] = {
        "2.9kHz", "1.5kHz", "735Hz", "403Hz", "196Hz", "98Hz", "49Hz"
@@ -608,6 +609,14 @@ SOC_SINGLE("DAC High Performance Switch", WM8996_OVERSAMPLING, 0, 1, 0),
 SOC_SINGLE("DAC Soft Mute Switch", WM8996_DAC_SOFTMUTE, 1, 1, 0),
 SOC_SINGLE("DAC Slow Soft Mute Switch", WM8996_DAC_SOFTMUTE, 0, 1, 0),
 
+SOC_SINGLE("DSP1 3D Stereo Switch", WM8996_DSP1_RX_FILTERS_2, 8, 1, 0),
+SOC_SINGLE("DSP2 3D Stereo Switch", WM8996_DSP2_RX_FILTERS_2, 8, 1, 0),
+
+SOC_SINGLE_TLV("DSP1 3D Stereo Volume", WM8996_DSP1_RX_FILTERS_2, 10, 15,
+               0, threedstereo_tlv),
+SOC_SINGLE_TLV("DSP2 3D Stereo Volume", WM8996_DSP2_RX_FILTERS_2, 10, 15,
+               0, threedstereo_tlv),
+
 SOC_DOUBLE_TLV("Digital Output 1 Volume", WM8996_DAC1_HPOUT1_VOLUME, 0, 4,
               8, 0, out_digital_tlv),
 SOC_DOUBLE_TLV("Digital Output 2 Volume", WM8996_DAC2_HPOUT2_VOLUME, 0, 4,
@@ -632,6 +641,14 @@ SOC_DOUBLE_R("Speaker ZC Switch", WM8996_LEFT_PDM_SPEAKER,
 
 SOC_SINGLE("DSP1 EQ Switch", WM8996_DSP1_RX_EQ_GAINS_1, 0, 1, 0),
 SOC_SINGLE("DSP2 EQ Switch", WM8996_DSP2_RX_EQ_GAINS_1, 0, 1, 0),
+
+SOC_SINGLE("DSP1 DRC TXL Switch", WM8996_DSP1_DRC_1, 0, 1, 0),
+SOC_SINGLE("DSP1 DRC TXR Switch", WM8996_DSP1_DRC_1, 1, 1, 0),
+SOC_SINGLE("DSP1 DRC RX Switch", WM8996_DSP1_DRC_1, 2, 1, 0),
+
+SOC_SINGLE("DSP2 DRC TXL Switch", WM8996_DSP2_DRC_1, 0, 1, 0),
+SOC_SINGLE("DSP2 DRC TXR Switch", WM8996_DSP2_DRC_1, 1, 1, 0),
+SOC_SINGLE("DSP2 DRC RX Switch", WM8996_DSP2_DRC_1, 2, 1, 0),
 };
 
 static const struct snd_kcontrol_new wm8996_eq_controls[] = {
@@ -658,19 +675,75 @@ SOC_SINGLE_TLV("DSP2 EQ B5 Volume", WM8996_DSP2_RX_EQ_GAINS_2, 6, 31, 0,
               eq_tlv),
 };
 
+static void wm8996_bg_enable(struct snd_soc_codec *codec)
+{
+       struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
+
+       wm8996->bg_ena++;
+       if (wm8996->bg_ena == 1) {
+               snd_soc_update_bits(codec, WM8996_POWER_MANAGEMENT_1,
+                                   WM8996_BG_ENA, WM8996_BG_ENA);
+               msleep(2);
+       }
+}
+
+static void wm8996_bg_disable(struct snd_soc_codec *codec)
+{
+       struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
+
+       wm8996->bg_ena--;
+       if (!wm8996->bg_ena)
+               snd_soc_update_bits(codec, WM8996_POWER_MANAGEMENT_1,
+                                   WM8996_BG_ENA, 0);
+}
+
+static int bg_event(struct snd_soc_dapm_widget *w,
+                   struct snd_kcontrol *kcontrol, int event)
+{
+       struct snd_soc_codec *codec = w->codec;
+       int ret = 0;
+
+       switch (event) {
+       case SND_SOC_DAPM_PRE_PMU:
+               wm8996_bg_enable(codec);
+               break;
+       case SND_SOC_DAPM_POST_PMD:
+               wm8996_bg_disable(codec);
+               break;
+       default:
+               BUG();
+               ret = -EINVAL;
+       }
+
+       return ret;
+}
+
 static int cp_event(struct snd_soc_dapm_widget *w,
                    struct snd_kcontrol *kcontrol, int event)
 {
+       struct snd_soc_codec *codec = w->codec;
+       struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
+       int ret = 0;
+
        switch (event) {
+       case SND_SOC_DAPM_PRE_PMU:
+               ret = regulator_enable(wm8996->cpvdd);
+               if (ret != 0)
+                       dev_err(codec->dev, "Failed to enable CPVDD: %d\n",
+                               ret);
+               break;
        case SND_SOC_DAPM_POST_PMU:
                msleep(5);
                break;
+       case SND_SOC_DAPM_POST_PMD:
+               regulator_disable_deferred(wm8996->cpvdd, 20);
+               break;
        default:
                BUG();
-               return -EINVAL;
+               ret = -EINVAL;
        }
 
-       return 0;
+       return ret;
 }
 
 static int rmv_short_event(struct snd_soc_dapm_widget *w,
@@ -698,7 +771,7 @@ static void wait_for_dc_servo(struct snd_soc_codec *codec, u16 mask)
 {
        struct i2c_client *i2c = to_i2c_client(codec->dev);
        struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
-       int i, ret;
+       int ret;
        unsigned long timeout = 200;
 
        snd_soc_write(codec, WM8996_DC_SERVO_2, mask);
@@ -713,15 +786,12 @@ static void wait_for_dc_servo(struct snd_soc_codec *codec, u16 mask)
 
                } else {
                        msleep(1);
-                       if (--i) {
-                               timeout = 0;
-                               break;
-                       }
+                       timeout--;
                }
 
                ret = snd_soc_read(codec, WM8996_DC_SERVO_2);
                dev_dbg(codec->dev, "DC servo state: %x\n", ret);
-       } while (ret & mask);
+       } while (timeout && ret & mask);
 
        if (timeout == 0)
                dev_err(codec->dev, "DC servo timed out for %x\n", mask);
@@ -979,9 +1049,12 @@ SND_SOC_DAPM_SUPPLY_S("SYSCLK", 1, WM8996_AIF_CLOCKING_1, 0, 0, NULL, 0),
 SND_SOC_DAPM_SUPPLY_S("SYSDSPCLK", 2, WM8996_CLOCKING_1, 1, 0, NULL, 0),
 SND_SOC_DAPM_SUPPLY_S("AIFCLK", 2, WM8996_CLOCKING_1, 2, 0, NULL, 0),
 SND_SOC_DAPM_SUPPLY_S("Charge Pump", 2, WM8996_CHARGE_PUMP_1, 15, 0, cp_event,
-                     SND_SOC_DAPM_POST_PMU),
-
+                     SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
+SND_SOC_DAPM_SUPPLY("Bandgap", SND_SOC_NOPM, 0, 0, bg_event,
+                   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
 SND_SOC_DAPM_SUPPLY("LDO2", WM8996_POWER_MANAGEMENT_2, 1, 0, NULL, 0),
+SND_SOC_DAPM_SUPPLY("MICB1 Audio", WM8996_MICBIAS_1, 4, 1, NULL, 0),
+SND_SOC_DAPM_SUPPLY("MICB2 Audio", WM8996_MICBIAS_2, 4, 1, NULL, 0),
 SND_SOC_DAPM_MICBIAS("MICB2", WM8996_POWER_MANAGEMENT_1, 9, 0),
 SND_SOC_DAPM_MICBIAS("MICB1", WM8996_POWER_MANAGEMENT_1, 8, 0),
 
@@ -1035,14 +1108,14 @@ SND_SOC_DAPM_DAC("DAC2R", NULL, WM8996_POWER_MANAGEMENT_5, 2, 0),
 SND_SOC_DAPM_DAC("DAC1L", NULL, WM8996_POWER_MANAGEMENT_5, 1, 0),
 SND_SOC_DAPM_DAC("DAC1R", NULL, WM8996_POWER_MANAGEMENT_5, 0, 0),
 
-SND_SOC_DAPM_AIF_IN("AIF2RX1", "AIF2 Playback", 1,
+SND_SOC_DAPM_AIF_IN("AIF2RX1", "AIF2 Playback", 0,
                    WM8996_POWER_MANAGEMENT_4, 9, 0),
-SND_SOC_DAPM_AIF_IN("AIF2RX0", "AIF2 Playback", 2,
+SND_SOC_DAPM_AIF_IN("AIF2RX0", "AIF2 Playback", 1,
                    WM8996_POWER_MANAGEMENT_4, 8, 0),
 
-SND_SOC_DAPM_AIF_IN("AIF2TX1", "AIF2 Capture", 1,
+SND_SOC_DAPM_AIF_OUT("AIF2TX1", "AIF2 Capture", 0,
                    WM8996_POWER_MANAGEMENT_6, 9, 0),
-SND_SOC_DAPM_AIF_IN("AIF2TX0", "AIF2 Capture", 2,
+SND_SOC_DAPM_AIF_OUT("AIF2TX0", "AIF2 Capture", 1,
                    WM8996_POWER_MANAGEMENT_6, 8, 0),
 
 SND_SOC_DAPM_AIF_IN("AIF1RX5", "AIF1 Playback", 5,
@@ -1137,17 +1210,23 @@ static const struct snd_soc_dapm_route wm8996_dapm_routes[] = {
        { "Charge Pump", NULL, "SYSCLK" },
 
        { "MICB1", NULL, "LDO2" },
+       { "MICB1", NULL, "MICB1 Audio" },
+       { "MICB1", NULL, "Bandgap" },
        { "MICB2", NULL, "LDO2" },
+       { "MICB2", NULL, "MICB2 Audio" },
+       { "MICB2", NULL, "Bandgap" },
 
        { "IN1L PGA", NULL, "IN2LN" },
        { "IN1L PGA", NULL, "IN2LP" },
        { "IN1L PGA", NULL, "IN1LN" },
        { "IN1L PGA", NULL, "IN1LP" },
+       { "IN1L PGA", NULL, "Bandgap" },
 
        { "IN1R PGA", NULL, "IN2RN" },
        { "IN1R PGA", NULL, "IN2RP" },
        { "IN1R PGA", NULL, "IN1RN" },
        { "IN1R PGA", NULL, "IN1RP" },
+       { "IN1R PGA", NULL, "Bandgap" },
 
        { "ADCL", NULL, "IN1L PGA" },
 
@@ -1281,6 +1360,7 @@ static const struct snd_soc_dapm_route wm8996_dapm_routes[] = {
        { "DAC2R", NULL, "DAC2R Mixer" },
 
        { "HPOUT2L PGA", NULL, "Charge Pump" },
+       { "HPOUT2L PGA", NULL, "Bandgap" },
        { "HPOUT2L PGA", NULL, "DAC2L" },
        { "HPOUT2L_DLY", NULL, "HPOUT2L PGA" },
        { "HPOUT2L_DCS", NULL, "HPOUT2L_DLY" },
@@ -1288,6 +1368,7 @@ static const struct snd_soc_dapm_route wm8996_dapm_routes[] = {
        { "HPOUT2L_RMV_SHORT", NULL, "HPOUT2L_OUTP" },
 
        { "HPOUT2R PGA", NULL, "Charge Pump" },
+       { "HPOUT2R PGA", NULL, "Bandgap" },
        { "HPOUT2R PGA", NULL, "DAC2R" },
        { "HPOUT2R_DLY", NULL, "HPOUT2R PGA" },
        { "HPOUT2R_DCS", NULL, "HPOUT2R_DLY" },
@@ -1295,6 +1376,7 @@ static const struct snd_soc_dapm_route wm8996_dapm_routes[] = {
        { "HPOUT2R_RMV_SHORT", NULL, "HPOUT2R_OUTP" },
 
        { "HPOUT1L PGA", NULL, "Charge Pump" },
+       { "HPOUT1L PGA", NULL, "Bandgap" },
        { "HPOUT1L PGA", NULL, "DAC1L" },
        { "HPOUT1L_DLY", NULL, "HPOUT1L PGA" },
        { "HPOUT1L_DCS", NULL, "HPOUT1L_DLY" },
@@ -1302,6 +1384,7 @@ static const struct snd_soc_dapm_route wm8996_dapm_routes[] = {
        { "HPOUT1L_RMV_SHORT", NULL, "HPOUT1L_OUTP" },
 
        { "HPOUT1R PGA", NULL, "Charge Pump" },
+       { "HPOUT1R PGA", NULL, "Bandgap" },
        { "HPOUT1R PGA", NULL, "DAC1R" },
        { "HPOUT1R_DLY", NULL, "HPOUT1R PGA" },
        { "HPOUT1R_DCS", NULL, "HPOUT1R_DLY" },
@@ -1620,14 +1703,7 @@ static int wm8996_set_bias_level(struct snd_soc_codec *codec,
 
        switch (level) {
        case SND_SOC_BIAS_ON:
-               break;
-
        case SND_SOC_BIAS_PREPARE:
-               if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY) {
-                       snd_soc_update_bits(codec, WM8996_POWER_MANAGEMENT_1,
-                                           WM8996_BG_ENA, WM8996_BG_ENA);
-                       msleep(2);
-               }
                break;
 
        case SND_SOC_BIAS_STANDBY:
@@ -1650,9 +1726,6 @@ static int wm8996_set_bias_level(struct snd_soc_codec *codec,
                        codec->cache_only = false;
                        snd_soc_cache_sync(codec);
                }
-
-               snd_soc_update_bits(codec, WM8996_POWER_MANAGEMENT_1,
-                                   WM8996_BG_ENA, 0);
                break;
 
        case SND_SOC_BIAS_OFF:
@@ -1847,7 +1920,7 @@ static int wm8996_hw_params(struct snd_pcm_substream *substream,
        snd_soc_update_bits(codec, lrclk_reg, WM8996_AIF1RX_RATE_MASK,
                            lrclk);
        snd_soc_update_bits(codec, WM8996_AIF_CLOCKING_2,
-                           WM8996_DSP1_DIV_SHIFT << dsp_shift, dsp);
+                           WM8996_DSP1_DIV_MASK << dsp_shift, dsp);
 
        return 0;
 }
@@ -2041,7 +2114,7 @@ static int wm8996_set_fll(struct snd_soc_codec *codec, int fll_id, int source,
        struct i2c_client *i2c = to_i2c_client(codec->dev);
        struct _fll_div fll_div;
        unsigned long timeout;
-       int ret, reg;
+       int ret, reg, retry;
 
        /* Any change? */
        if (source == wm8996->fll_src && Fref == wm8996->fll_fref &&
@@ -2057,6 +2130,8 @@ static int wm8996_set_fll(struct snd_soc_codec *codec, int fll_id, int source,
                snd_soc_update_bits(codec, WM8996_FLL_CONTROL_1,
                                    WM8996_FLL_ENA, 0);
 
+               wm8996_bg_disable(codec);
+
                return 0;
        }
 
@@ -2111,6 +2186,11 @@ static int wm8996_set_fll(struct snd_soc_codec *codec, int fll_id, int source,
 
        snd_soc_write(codec, WM8996_FLL_EFS_1, fll_div.lambda);
 
+       /* Enable the bandgap if it's not already enabled */
+       ret = snd_soc_read(codec, WM8996_FLL_CONTROL_1);
+       if (!(ret & WM8996_FLL_ENA))
+               wm8996_bg_enable(codec);
+
        /* Clear any pending completions (eg, from failed startups) */
        try_wait_for_completion(&wm8996->fll_lock);
 
@@ -2128,17 +2208,29 @@ static int wm8996_set_fll(struct snd_soc_codec *codec, int fll_id, int source,
        else
                timeout = msecs_to_jiffies(2);
 
-       /* Allow substantially longer if we've actually got the IRQ */
+       /* Allow substantially longer if we've actually got the IRQ, poll
+        * at a slightly higher rate if we don't.
+        */
        if (i2c->irq)
-               timeout *= 1000;
+               timeout *= 10;
+       else
+               timeout /= 2;
 
-       ret = wait_for_completion_timeout(&wm8996->fll_lock, timeout);
+       for (retry = 0; retry < 10; retry++) {
+               ret = wait_for_completion_timeout(&wm8996->fll_lock,
+                                                 timeout);
+               if (ret != 0) {
+                       WARN_ON(!i2c->irq);
+                       break;
+               }
 
-       if (ret == 0 && i2c->irq) {
+               ret = snd_soc_read(codec, WM8996_INTERRUPT_RAW_STATUS_2);
+               if (ret & WM8996_FLL_LOCK_STS)
+                       break;
+       }
+       if (retry == 10) {
                dev_err(codec->dev, "Timed out waiting for FLL\n");
                ret = -ETIMEDOUT;
-       } else {
-               ret = 0;
        }
 
        dev_dbg(codec->dev, "FLL configured for %dHz->%dHz\n", Fref, Fout);
@@ -2297,12 +2389,94 @@ int wm8996_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
 
        /* Enable interrupts and we're off */
        snd_soc_update_bits(codec, WM8996_INTERRUPT_STATUS_2_MASK,
-                           WM8996_IM_MICD_EINT, 0);
+                           WM8996_IM_MICD_EINT | WM8996_HP_DONE_EINT, 0);
 
        return 0;
 }
 EXPORT_SYMBOL_GPL(wm8996_detect);
 
+static void wm8996_hpdet_irq(struct snd_soc_codec *codec)
+{
+       struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
+       int val, reg, report;
+
+       /* Assume headphone in error conditions; we need to report
+        * something or we stall our state machine.
+        */
+       report = SND_JACK_HEADPHONE;
+
+       reg = snd_soc_read(codec, WM8996_HEADPHONE_DETECT_2);
+       if (reg < 0) {
+               dev_err(codec->dev, "Failed to read HPDET status\n");
+               goto out;
+       }
+
+       if (!(reg & WM8996_HP_DONE)) {
+               dev_err(codec->dev, "Got HPDET IRQ but HPDET is busy\n");
+               goto out;
+       }
+
+       val = reg & WM8996_HP_LVL_MASK;
+
+       dev_dbg(codec->dev, "HPDET measured %d ohms\n", val);
+
+       /* If we've got high enough impedence then report as line,
+        * otherwise assume headphone.
+        */
+       if (val >= 126)
+               report = SND_JACK_LINEOUT;
+       else
+               report = SND_JACK_HEADPHONE;
+
+out:
+       if (wm8996->jack_mic)
+               report |= SND_JACK_MICROPHONE;
+
+       snd_soc_jack_report(wm8996->jack, report,
+                           SND_JACK_LINEOUT | SND_JACK_HEADSET);
+
+       wm8996->detecting = false;
+
+       /* If the output isn't running re-clamp it */
+       if (!(snd_soc_read(codec, WM8996_POWER_MANAGEMENT_1) &
+             (WM8996_HPOUT1L_ENA | WM8996_HPOUT1R_RMV_SHORT)))
+               snd_soc_update_bits(codec, WM8996_ANALOGUE_HP_1,
+                                   WM8996_HPOUT1L_RMV_SHORT |
+                                   WM8996_HPOUT1R_RMV_SHORT, 0);
+
+       /* Go back to looking at the microphone */
+       snd_soc_update_bits(codec, WM8996_ACCESSORY_DETECT_MODE_1,
+                           WM8996_JD_MODE_MASK, 0);
+       snd_soc_update_bits(codec, WM8996_MIC_DETECT_1, WM8996_MICD_ENA,
+                           WM8996_MICD_ENA);
+
+       snd_soc_dapm_disable_pin(&codec->dapm, "Bandgap");
+       snd_soc_dapm_sync(&codec->dapm);
+}
+
+static void wm8996_hpdet_start(struct snd_soc_codec *codec)
+{
+       /* Unclamp the output, we can't measure while we're shorting it */
+       snd_soc_update_bits(codec, WM8996_ANALOGUE_HP_1,
+                           WM8996_HPOUT1L_RMV_SHORT |
+                           WM8996_HPOUT1R_RMV_SHORT,
+                           WM8996_HPOUT1L_RMV_SHORT |
+                           WM8996_HPOUT1R_RMV_SHORT);
+
+       /* We need bandgap for HPDET */
+       snd_soc_dapm_force_enable_pin(&codec->dapm, "Bandgap");
+       snd_soc_dapm_sync(&codec->dapm);
+
+       /* Go into headphone detect left mode */
+       snd_soc_update_bits(codec, WM8996_MIC_DETECT_1, WM8996_MICD_ENA, 0);
+       snd_soc_update_bits(codec, WM8996_ACCESSORY_DETECT_MODE_1,
+                           WM8996_JD_MODE_MASK, 1);
+
+       /* Trigger a measurement */
+       snd_soc_update_bits(codec, WM8996_HEADPHONE_DETECT_1,
+                           WM8996_HP_POLL, WM8996_HP_POLL);
+}
+
 static void wm8996_micd(struct snd_soc_codec *codec)
 {
        struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
@@ -2323,28 +2497,36 @@ static void wm8996_micd(struct snd_soc_codec *codec)
                wm8996->jack_mic = false;
                wm8996->detecting = true;
                snd_soc_jack_report(wm8996->jack, 0,
-                                   SND_JACK_HEADSET | SND_JACK_BTN_0);
+                                   SND_JACK_LINEOUT | SND_JACK_HEADSET |
+                                   SND_JACK_BTN_0);
+
                snd_soc_update_bits(codec, WM8996_MIC_DETECT_1,
                                    WM8996_MICD_RATE_MASK,
                                    WM8996_MICD_RATE_MASK);
                return;
        }
 
-       /* If the measurement is very high we've got a microphone but
-        * do a little debounce to account for mechanical issues.
+       /* If the measurement is very high we've got a microphone,
+        * either we just detected one or if we already reported then
+        * we've got a button release event.
         */
        if (val & 0x400) {
-               dev_dbg(codec->dev, "Microphone detected\n");
-               snd_soc_jack_report(wm8996->jack, SND_JACK_HEADSET,
-                                   SND_JACK_HEADSET | SND_JACK_BTN_0);
-               wm8996->jack_mic = true;
-               wm8996->detecting = false;
-
-               /* Increase poll rate to give better responsiveness
-                * for buttons */
-               snd_soc_update_bits(codec, WM8996_MIC_DETECT_1,
-                                   WM8996_MICD_RATE_MASK,
-                                   5 << WM8996_MICD_RATE_SHIFT);
+               if (wm8996->detecting) {
+                       dev_dbg(codec->dev, "Microphone detected\n");
+                       wm8996->jack_mic = true;
+                       wm8996_hpdet_start(codec);
+
+                       /* Increase poll rate to give better responsiveness
+                        * for buttons */
+                       snd_soc_update_bits(codec, WM8996_MIC_DETECT_1,
+                                           WM8996_MICD_RATE_MASK,
+                                           5 << WM8996_MICD_RATE_SHIFT);
+               } else {
+                       dev_dbg(codec->dev, "Mic button up\n");
+                       snd_soc_jack_report(wm8996->jack, 0, SND_JACK_BTN_0);
+               }
+
+               return;
        }
 
        /* If we detected a lower impedence during initial startup
@@ -2376,15 +2558,11 @@ static void wm8996_micd(struct snd_soc_codec *codec)
        if (val & 0x3fc) {
                if (wm8996->jack_mic) {
                        dev_dbg(codec->dev, "Mic button detected\n");
-                       snd_soc_jack_report(wm8996->jack,
-                                           SND_JACK_HEADSET | SND_JACK_BTN_0,
-                                           SND_JACK_HEADSET | SND_JACK_BTN_0);
-               } else {
-                       dev_dbg(codec->dev, "Headphone detected\n");
-                       snd_soc_jack_report(wm8996->jack,
-                                           SND_JACK_HEADPHONE,
-                                           SND_JACK_HEADSET |
+                       snd_soc_jack_report(wm8996->jack, SND_JACK_BTN_0,
                                            SND_JACK_BTN_0);
+               } else if (wm8996->detecting) {
+                       dev_dbg(codec->dev, "Headphone detected\n");
+                       wm8996_hpdet_start(codec);
 
                        /* Increase the detection rate a bit for
                         * responsiveness.
@@ -2392,8 +2570,6 @@ static void wm8996_micd(struct snd_soc_codec *codec)
                        snd_soc_update_bits(codec, WM8996_MIC_DETECT_1,
                                            WM8996_MICD_RATE_MASK,
                                            7 << WM8996_MICD_RATE_SHIFT);
-
-                       wm8996->detecting = false;
                }
        }
 }
@@ -2412,6 +2588,9 @@ static irqreturn_t wm8996_irq(int irq, void *data)
        }
        irq_val &= ~snd_soc_read(codec, WM8996_INTERRUPT_STATUS_2_MASK);
 
+       if (!irq_val)
+               return IRQ_NONE;
+
        snd_soc_write(codec, WM8996_INTERRUPT_STATUS_2, irq_val);
 
        if (irq_val & (WM8996_DCS_DONE_01_EINT | WM8996_DCS_DONE_23_EINT)) {
@@ -2430,10 +2609,10 @@ static irqreturn_t wm8996_irq(int irq, void *data)
        if (irq_val & WM8996_MICD_EINT)
                wm8996_micd(codec);
 
-       if (irq_val)
-               return IRQ_HANDLED;
-       else
-               return IRQ_NONE;
+       if (irq_val & WM8996_HP_DONE_EINT)
+               wm8996_hpdet_irq(codec);
+
+       return IRQ_HANDLED;
 }
 
 static irqreturn_t wm8996_edge_irq(int irq, void *data)
@@ -2527,7 +2706,6 @@ static int wm8996_probe(struct snd_soc_codec *codec)
        init_completion(&wm8996->fll_lock);
 
        dapm->idle_bias_off = true;
-       dapm->bias_level = SND_SOC_BIAS_OFF;
 
        ret = snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_I2C);
        if (ret != 0) {
@@ -2548,7 +2726,13 @@ static int wm8996_probe(struct snd_soc_codec *codec)
        wm8996->disable_nb[0].notifier_call = wm8996_regulator_event_0;
        wm8996->disable_nb[1].notifier_call = wm8996_regulator_event_1;
        wm8996->disable_nb[2].notifier_call = wm8996_regulator_event_2;
-       wm8996->disable_nb[3].notifier_call = wm8996_regulator_event_3;
+
+       wm8996->cpvdd = regulator_get(&i2c->dev, "CPVDD");
+       if (IS_ERR(wm8996->cpvdd)) {
+               ret = PTR_ERR(wm8996->cpvdd);
+               dev_err(&i2c->dev, "Failed to get CPVDD: %d\n", ret);
+               goto err_get;
+       }
 
        /* This should really be moved into the regulator core */
        for (i = 0; i < ARRAY_SIZE(wm8996->supplies); i++) {
@@ -2565,7 +2749,7 @@ static int wm8996_probe(struct snd_soc_codec *codec)
                                    wm8996->supplies);
        if (ret != 0) {
                dev_err(codec->dev, "Failed to enable supplies: %d\n", ret);
-               goto err_get;
+               goto err_cpvdd;
        }
 
        if (wm8996->pdata.ldo_ena >= 0) {
@@ -2808,6 +2992,8 @@ err_enable:
                gpio_set_value_cansleep(wm8996->pdata.ldo_ena, 0);
 
        regulator_bulk_disable(ARRAY_SIZE(wm8996->supplies), wm8996->supplies);
+err_cpvdd:
+       regulator_put(wm8996->cpvdd);
 err_get:
        regulator_bulk_free(ARRAY_SIZE(wm8996->supplies), wm8996->supplies);
 err:
@@ -2831,6 +3017,7 @@ static int wm8996_remove(struct snd_soc_codec *codec)
        for (i = 0; i < ARRAY_SIZE(wm8996->supplies); i++)
                regulator_unregister_notifier(wm8996->supplies[i].consumer,
                                              &wm8996->disable_nb[i]);
+       regulator_put(wm8996->cpvdd);
        regulator_bulk_free(ARRAY_SIZE(wm8996->supplies), wm8996->supplies);
 
        return 0;
index a4691321f9b33887e4601e9634da5e15db0b081e..3cd35a02c28c7164f525f00f7375ac5ef4d6bbb1 100644 (file)
@@ -157,7 +157,6 @@ static struct {
 
 struct wm9081_priv {
        enum snd_soc_control_type control_type;
-       void *control_data;
        int sysclk_source;
        int mclk_rate;
        int sysclk_rate;
@@ -174,6 +173,7 @@ static int wm9081_volatile_register(struct snd_soc_codec *codec, unsigned int re
 {
        switch (reg) {
        case WM9081_SOFTWARE_RESET:
+       case WM9081_INTERRUPT_STATUS:
                return 1;
        default:
                return 0;
@@ -820,7 +820,7 @@ static int wm9081_set_bias_level(struct snd_soc_codec *codec,
                /* VMID 2*240k */
                reg = snd_soc_read(codec, WM9081_BIAS_CONTROL_1);
                reg &= ~WM9081_VMID_SEL_MASK;
-               reg |= 0x40;
+               reg |= 0x04;
                snd_soc_write(codec, WM9081_VMID_CONTROL, reg);
 
                /* Standby bias current on */
@@ -1120,8 +1120,8 @@ static int wm9081_digital_mute(struct snd_soc_dai *codec_dai, int mute)
        return 0;
 }
 
-static int wm9081_set_sysclk(struct snd_soc_codec *codec,
-                            int clk_id, unsigned int freq, int dir)
+static int wm9081_set_sysclk(struct snd_soc_codec *codec, int clk_id,
+                            int source, unsigned int freq, int dir)
 {
        struct wm9081_priv *wm9081 = snd_soc_codec_get_drvdata(codec);
 
@@ -1213,7 +1213,6 @@ static int wm9081_probe(struct snd_soc_codec *codec)
        int ret;
        u16 reg;
 
-       codec->control_data = wm9081->control_data;
        ret = snd_soc_codec_set_cache_io(codec, 8, 16, wm9081->control_type);
        if (ret != 0) {
                dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
@@ -1250,8 +1249,6 @@ static int wm9081_probe(struct snd_soc_codec *codec)
        snd_soc_write(codec, WM9081_ANALOGUE_SPEAKER_PGA,
                     reg | WM9081_SPKPGAZC);
 
-       snd_soc_add_controls(codec, wm9081_snd_controls,
-                            ARRAY_SIZE(wm9081_snd_controls));
        if (!wm9081->pdata.num_retune_configs) {
                dev_dbg(codec->dev,
                        "No ReTune Mobile data, using normal EQ\n");
@@ -1311,6 +1308,8 @@ static struct snd_soc_codec_driver soc_codec_dev_wm9081 = {
        .reg_cache_default = wm9081_reg_defaults,
        .volatile_register = wm9081_volatile_register,
 
+       .controls         = wm9081_snd_controls,
+       .num_controls     = ARRAY_SIZE(wm9081_snd_controls),
        .dapm_widgets     = wm9081_dapm_widgets,
        .num_dapm_widgets = ARRAY_SIZE(wm9081_dapm_widgets),
        .dapm_routes     = wm9081_audio_paths,
@@ -1330,7 +1329,6 @@ static __devinit int wm9081_i2c_probe(struct i2c_client *i2c,
 
        i2c_set_clientdata(i2c, wm9081);
        wm9081->control_type = SND_SOC_I2C;
-       wm9081->control_data = i2c;
 
        if (dev_get_platdata(&i2c->dev))
                memcpy(&wm9081->pdata, dev_get_platdata(&i2c->dev),
index 4de12203e6113508712731c1060ed4e8d39cc743..2b5252c9e37774963a55626e284878e7ff777414 100644 (file)
@@ -139,9 +139,7 @@ static const u16 wm9090_reg_defaults[] = {
 
 /* This struct is used to save the context */
 struct wm9090_priv {
-       struct mutex mutex;
        struct wm9090_platform_data pdata;
-       void *control_data;
 };
 
 static int wm9090_volatile(struct snd_soc_codec *codec, unsigned int reg)
@@ -550,10 +548,8 @@ static int wm9090_set_bias_level(struct snd_soc_codec *codec,
 
 static int wm9090_probe(struct snd_soc_codec *codec)
 {
-       struct wm9090_priv *wm9090 = snd_soc_codec_get_drvdata(codec);
        int ret;
 
-       codec->control_data = wm9090->control_data;
        ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_I2C);
        if (ret != 0) {
                dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
@@ -662,8 +658,6 @@ static int wm9090_i2c_probe(struct i2c_client *i2c,
                       sizeof(wm9090->pdata));
 
        i2c_set_clientdata(i2c, wm9090);
-       wm9090->control_data = i2c;
-       mutex_init(&wm9090->mutex);
 
        ret =  snd_soc_register_codec(&i2c->dev,
                        &soc_codec_dev_wm9090,  NULL, 0);
@@ -684,6 +678,7 @@ static int __devexit wm9090_i2c_remove(struct i2c_client *i2c)
 
 static const struct i2c_device_id wm9090_id[] = {
        { "wm9090", 0 },
+       { "wm9093", 0 },
        { }
 };
 MODULE_DEVICE_TABLE(i2c, wm9090_id);
index e763c54c55dc32d5e2b97da5c9bfcd364558adaa..84f33d4ea2cd5ec5461d0f8518c2462c3a58d544 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/pm.h>
 #include <linux/i2c.h>
 #include <linux/platform_device.h>
+#include <linux/mfd/wm8994/registers.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
@@ -116,14 +117,23 @@ static void calibrate_dc_servo(struct snd_soc_codec *codec)
 {
        struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
        s8 offset;
-       u16 reg, reg_l, reg_r, dcs_cfg;
+       u16 reg, reg_l, reg_r, dcs_cfg, dcs_reg;
+
+       switch (hubs->dcs_readback_mode) {
+       case 2:
+               dcs_reg = WM8994_DC_SERVO_4E;
+               break;
+       default:
+               dcs_reg = WM8993_DC_SERVO_3;
+               break;
+       }
 
        /* If we're using a digital only path and have a previously
         * callibrated DC servo offset stored then use that. */
        if (hubs->class_w && hubs->class_w_dcs) {
                dev_dbg(codec->dev, "Using cached DC servo offset %x\n",
                        hubs->class_w_dcs);
-               snd_soc_write(codec, WM8993_DC_SERVO_3, hubs->class_w_dcs);
+               snd_soc_write(codec, dcs_reg, hubs->class_w_dcs);
                wait_for_dc_servo(codec,
                                  WM8993_DCS_TRIG_DAC_WR_0 |
                                  WM8993_DCS_TRIG_DAC_WR_1);
@@ -154,8 +164,9 @@ static void calibrate_dc_servo(struct snd_soc_codec *codec)
                reg_r = snd_soc_read(codec, WM8993_DC_SERVO_READBACK_2)
                        & WM8993_DCS_INTEG_CHAN_1_MASK;
                break;
+       case 2:
        case 1:
-               reg = snd_soc_read(codec, WM8993_DC_SERVO_3);
+               reg = snd_soc_read(codec, dcs_reg);
                reg_r = (reg & WM8993_DCS_DAC_WR_VAL_1_MASK)
                        >> WM8993_DCS_DAC_WR_VAL_1_SHIFT;
                reg_l = reg & WM8993_DCS_DAC_WR_VAL_0_MASK;
@@ -168,24 +179,25 @@ static void calibrate_dc_servo(struct snd_soc_codec *codec)
        dev_dbg(codec->dev, "DCS input: %x %x\n", reg_l, reg_r);
 
        /* Apply correction to DC servo result */
-       if (hubs->dcs_codes) {
-               dev_dbg(codec->dev, "Applying %d code DC servo correction\n",
-                       hubs->dcs_codes);
+       if (hubs->dcs_codes_l || hubs->dcs_codes_r) {
+               dev_dbg(codec->dev,
+                       "Applying %d/%d code DC servo correction\n",
+                       hubs->dcs_codes_l, hubs->dcs_codes_r);
 
                /* HPOUT1R */
                offset = reg_r;
-               offset += hubs->dcs_codes;
+               offset += hubs->dcs_codes_r;
                dcs_cfg = (u8)offset << WM8993_DCS_DAC_WR_VAL_1_SHIFT;
 
                /* HPOUT1L */
                offset = reg_l;
-               offset += hubs->dcs_codes;
+               offset += hubs->dcs_codes_l;
                dcs_cfg |= (u8)offset;
 
                dev_dbg(codec->dev, "DCS result: %x\n", dcs_cfg);
 
                /* Do it */
-               snd_soc_write(codec, WM8993_DC_SERVO_3, dcs_cfg);
+               snd_soc_write(codec, dcs_reg, dcs_cfg);
                wait_for_dc_servo(codec,
                                  WM8993_DCS_TRIG_DAC_WR_0 |
                                  WM8993_DCS_TRIG_DAC_WR_1);
@@ -210,14 +222,14 @@ static int wm8993_put_dc_servo(struct snd_kcontrol *kcontrol,
        struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
        int ret;
 
-       ret = snd_soc_put_volsw_2r(kcontrol, ucontrol);
+       ret = snd_soc_put_volsw(kcontrol, ucontrol);
 
        /* Updating the analogue gains invalidates the DC servo cache */
        hubs->class_w_dcs = 0;
 
        /* If we're applying an offset correction then updating the
         * callibration would be likely to introduce further offsets. */
-       if (hubs->dcs_codes || hubs->no_series_update)
+       if (hubs->dcs_codes_l || hubs->dcs_codes_r || hubs->no_series_update)
                return ret;
 
        /* Only need to do this if the outputs are active */
@@ -350,19 +362,11 @@ SOC_DOUBLE_TLV("Speaker Boost Volume", WM8993_SPKOUT_BOOST, 3, 0, 7, 0,
 SOC_ENUM("Speaker Reference", speaker_ref),
 SOC_ENUM("Speaker Mode", speaker_mode),
 
-{
-       .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Headphone Volume",
-       .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |
-                SNDRV_CTL_ELEM_ACCESS_READWRITE,
-       .tlv.p = outpga_tlv,
-       .info = snd_soc_info_volsw_2r,
-       .get = snd_soc_get_volsw_2r, .put = wm8993_put_dc_servo,
-       .private_value = (unsigned long)&(struct soc_mixer_control) {
-               .reg = WM8993_LEFT_OUTPUT_VOLUME,
-               .rreg = WM8993_RIGHT_OUTPUT_VOLUME,
-               .shift = 0, .max = 63
-       },
-},
+SOC_DOUBLE_R_EXT_TLV("Headphone Volume",
+                    WM8993_LEFT_OUTPUT_VOLUME, WM8993_RIGHT_OUTPUT_VOLUME,
+                    0, 63, 0, snd_soc_get_volsw, wm8993_put_dc_servo,
+                    outpga_tlv),
+
 SOC_DOUBLE_R("Headphone Switch", WM8993_LEFT_OUTPUT_VOLUME,
             WM8993_RIGHT_OUTPUT_VOLUME, 6, 1, 0),
 SOC_DOUBLE_R("Headphone ZC Switch", WM8993_LEFT_OUTPUT_VOLUME,
@@ -699,6 +703,11 @@ static const struct snd_soc_dapm_route analogue_routes[] = {
        { "IN1L PGA", "IN1LP Switch", "IN1LP" },
        { "IN1L PGA", "IN1LN Switch", "IN1LN" },
 
+       { "IN1L PGA", NULL, "VMID" },
+       { "IN1R PGA", NULL, "VMID" },
+       { "IN2L PGA", NULL, "VMID" },
+       { "IN2R PGA", NULL, "VMID" },
+
        { "IN1R PGA", "IN1RP Switch", "IN1RP" },
        { "IN1R PGA", "IN1RN Switch", "IN1RN" },
 
@@ -716,12 +725,14 @@ static const struct snd_soc_dapm_route analogue_routes[] = {
        { "MIXINL", NULL, "Direct Voice" },
        { "MIXINL", NULL, "IN1LP" },
        { "MIXINL", NULL, "Left Output Mixer" },
+       { "MIXINL", NULL, "VMID" },
 
        { "MIXINR", "IN1R Switch", "IN1R PGA" },
        { "MIXINR", "IN2R Switch", "IN2R PGA" },
        { "MIXINR", NULL, "Direct Voice" },
        { "MIXINR", NULL, "IN1RP" },
        { "MIXINR", NULL, "Right Output Mixer" },
+       { "MIXINR", NULL, "VMID" },
 
        { "ADCL", NULL, "MIXINL" },
        { "ADCR", NULL, "MIXINR" },
@@ -752,6 +763,7 @@ static const struct snd_soc_dapm_route analogue_routes[] = {
        { "Earpiece Mixer", "Left Output Switch", "Left Output PGA" },
        { "Earpiece Mixer", "Right Output Switch", "Right Output PGA" },
 
+       { "Earpiece Driver", NULL, "VMID" },
        { "Earpiece Driver", NULL, "Earpiece Mixer" },
        { "HPOUT2N", NULL, "Earpiece Driver" },
        { "HPOUT2P", NULL, "Earpiece Driver" },
@@ -774,9 +786,11 @@ static const struct snd_soc_dapm_route analogue_routes[] = {
        { "SPKR Boost", "SPKR Switch", "SPKR" },
        { "SPKR Boost", "SPKL Switch", "SPKL" },
 
+       { "SPKL Driver", NULL, "VMID" },
        { "SPKL Driver", NULL, "SPKL Boost" },
        { "SPKL Driver", NULL, "CLK_SYS" },
 
+       { "SPKR Driver", NULL, "VMID" },
        { "SPKR Driver", NULL, "SPKR Boost" },
        { "SPKR Driver", NULL, "CLK_SYS" },
 
@@ -790,12 +804,18 @@ static const struct snd_soc_dapm_route analogue_routes[] = {
 
        { "Headphone PGA", NULL, "Left Headphone Mux" },
        { "Headphone PGA", NULL, "Right Headphone Mux" },
+       { "Headphone PGA", NULL, "VMID" },
        { "Headphone PGA", NULL, "CLK_SYS" },
        { "Headphone PGA", NULL, "Headphone Supply" },
 
        { "HPOUT1L", NULL, "Headphone PGA" },
        { "HPOUT1R", NULL, "Headphone PGA" },
 
+       { "LINEOUT1N Driver", NULL, "VMID" },
+       { "LINEOUT1P Driver", NULL, "VMID" },
+       { "LINEOUT2N Driver", NULL, "VMID" },
+       { "LINEOUT2P Driver", NULL, "VMID" },
+
        { "LINEOUT1N", NULL, "LINEOUT1N Driver" },
        { "LINEOUT1P", NULL, "LINEOUT1P Driver" },
        { "LINEOUT2N", NULL, "LINEOUT2N Driver" },
index 676b1252ab910559a07bc3738051a67e60e765c8..c674c7a502a64e1d02889edfa839522686afdf9b 100644 (file)
@@ -23,7 +23,8 @@ extern const unsigned int wm_hubs_spkmix_tlv[];
 
 /* This *must* be the first element of the codec->private_data struct */
 struct wm_hubs_data {
-       int dcs_codes;
+       int dcs_codes_l;
+       int dcs_codes_r;
        int dcs_readback_mode;
        int hp_startup_mode;
        int series_startup;
index fe7984221eb9bcad2bd027e219e15c8ba9f06360..f78c3f0f280c23e12065a1c9ad226dc981e944c3 100644 (file)
@@ -150,8 +150,6 @@ static int evm_aic3x_init(struct snd_soc_pcm_runtime *rtd)
        snd_soc_dapm_enable_pin(dapm, "Mic Jack");
        snd_soc_dapm_enable_pin(dapm, "Line In");
 
-       snd_soc_dapm_sync(dapm);
-
        return 0;
 }
 
index d0d60b8a54d4b7573841b297c8d07b78434af6a9..300e12118c0093722f1e2b5f527b8627cdbab116 100644 (file)
@@ -265,6 +265,7 @@ static int davinci_i2s_set_dai_fmt(struct snd_soc_dai *cpu_dai,
        struct davinci_mcbsp_dev *dev = snd_soc_dai_get_drvdata(cpu_dai);
        unsigned int pcr;
        unsigned int srgr;
+       bool inv_fs = false;
        /* Attention srgr is updated by hw_params! */
        srgr = DAVINCI_MCBSP_SRGR_FSGM |
                DAVINCI_MCBSP_SRGR_FPER(DEFAULT_BITPERSAMPLE * 2 - 1) |
@@ -330,7 +331,7 @@ static int davinci_i2s_set_dai_fmt(struct snd_soc_dai *cpu_dai,
                 * more empty bit clock slots between channels as the sample
                 * rate is lowered.
                 */
-               fmt ^= SND_SOC_DAIFMT_NB_IF;
+               inv_fs = true;
        case SND_SOC_DAIFMT_DSP_A:
                dev->mode = MOD_DSP_A;
                break;
@@ -394,6 +395,8 @@ static int davinci_i2s_set_dai_fmt(struct snd_soc_dai *cpu_dai,
        default:
                return -EINVAL;
        }
+       if (inv_fs == true)
+               pcr ^= (DAVINCI_MCBSP_PCR_FSXP | DAVINCI_MCBSP_PCR_FSRP);
        davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SRGR_REG, srgr);
        dev->pcr = pcr;
        davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG, pcr);
index 8566238db2a5ea7a3f807f2cb341826703167bec..7173df254a9150b0f69d527f7cd2f6ab02cfc7e3 100644 (file)
@@ -732,16 +732,19 @@ static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream,
                davinci_hw_param(dev, substream->stream);
 
        switch (params_format(params)) {
+       case SNDRV_PCM_FORMAT_U8:
        case SNDRV_PCM_FORMAT_S8:
                dma_params->data_type = 1;
                word_length = DAVINCI_AUDIO_WORD_8;
                break;
 
+       case SNDRV_PCM_FORMAT_U16_LE:
        case SNDRV_PCM_FORMAT_S16_LE:
                dma_params->data_type = 2;
                word_length = DAVINCI_AUDIO_WORD_16;
                break;
 
+       case SNDRV_PCM_FORMAT_U32_LE:
        case SNDRV_PCM_FORMAT_S32_LE:
                dma_params->data_type = 4;
                word_length = DAVINCI_AUDIO_WORD_32;
@@ -818,6 +821,13 @@ static struct snd_soc_dai_ops davinci_mcasp_dai_ops = {
 
 };
 
+#define DAVINCI_MCASP_PCM_FMTS (SNDRV_PCM_FMTBIT_S8 | \
+                               SNDRV_PCM_FMTBIT_U8 | \
+                               SNDRV_PCM_FMTBIT_S16_LE | \
+                               SNDRV_PCM_FMTBIT_U16_LE | \
+                               SNDRV_PCM_FMTBIT_S32_LE | \
+                               SNDRV_PCM_FMTBIT_U32_LE)
+
 static struct snd_soc_dai_driver davinci_mcasp_dai[] = {
        {
                .name           = "davinci-mcasp.0",
@@ -825,17 +835,13 @@ static struct snd_soc_dai_driver davinci_mcasp_dai[] = {
                        .channels_min   = 2,
                        .channels_max   = 2,
                        .rates          = DAVINCI_MCASP_RATES,
-                       .formats        = SNDRV_PCM_FMTBIT_S8 |
-                                               SNDRV_PCM_FMTBIT_S16_LE |
-                                               SNDRV_PCM_FMTBIT_S32_LE,
+                       .formats        = DAVINCI_MCASP_PCM_FMTS,
                },
                .capture        = {
                        .channels_min   = 2,
                        .channels_max   = 2,
                        .rates          = DAVINCI_MCASP_RATES,
-                       .formats        = SNDRV_PCM_FMTBIT_S8 |
-                                               SNDRV_PCM_FMTBIT_S16_LE |
-                                               SNDRV_PCM_FMTBIT_S32_LE,
+                       .formats        = DAVINCI_MCASP_PCM_FMTS,
                },
                .ops            = &davinci_mcasp_dai_ops,
 
@@ -846,7 +852,7 @@ static struct snd_soc_dai_driver davinci_mcasp_dai[] = {
                        .channels_min   = 1,
                        .channels_max   = 384,
                        .rates          = DAVINCI_MCASP_RATES,
-                       .formats        = SNDRV_PCM_FMTBIT_S16_LE,
+                       .formats        = DAVINCI_MCASP_PCM_FMTS,
                },
                .ops            = &davinci_mcasp_dai_ops,
        },
index a49e667373bcf7542854696e4c2ee63fc38249ab..d5fe08cc5db7ec83efbfcb2b8b13d6094c2bf986 100644 (file)
@@ -180,7 +180,6 @@ static void davinci_pcm_enqueue_dma(struct snd_pcm_substream *substream)
 {
        struct davinci_runtime_data *prtd = substream->runtime->private_data;
        struct snd_pcm_runtime *runtime = substream->runtime;
-       int link = prtd->asp_link[0];
        unsigned int period_size;
        unsigned int dma_offset;
        dma_addr_t dma_pos;
@@ -198,7 +197,8 @@ static void davinci_pcm_enqueue_dma(struct snd_pcm_substream *substream)
        fifo_level = prtd->params->fifo_level;
 
        pr_debug("davinci_pcm: audio_set_dma_params_play channel = %d "
-               "dma_ptr = %x period_size=%x\n", link, dma_pos, period_size);
+               "dma_ptr = %x period_size=%x\n", prtd->asp_link[0], dma_pos,
+               period_size);
 
        data_type = prtd->params->data_type;
        count = period_size / data_type;
@@ -222,17 +222,19 @@ static void davinci_pcm_enqueue_dma(struct snd_pcm_substream *substream)
        }
 
        acnt = prtd->params->acnt;
-       edma_set_src(link, src, INCR, W8BIT);
-       edma_set_dest(link, dst, INCR, W8BIT);
+       edma_set_src(prtd->asp_link[0], src, INCR, W8BIT);
+       edma_set_dest(prtd->asp_link[0], dst, INCR, W8BIT);
 
-       edma_set_src_index(link, src_bidx, src_cidx);
-       edma_set_dest_index(link, dst_bidx, dst_cidx);
+       edma_set_src_index(prtd->asp_link[0], src_bidx, src_cidx);
+       edma_set_dest_index(prtd->asp_link[0], dst_bidx, dst_cidx);
 
        if (!fifo_level)
-               edma_set_transfer_params(link, acnt, count, 1, 0, ASYNC);
+               edma_set_transfer_params(prtd->asp_link[0], acnt, count, 1, 0,
+                                                       ASYNC);
        else
-               edma_set_transfer_params(link, acnt, fifo_level, count,
-                                                       fifo_level, ABSYNC);
+               edma_set_transfer_params(prtd->asp_link[0], acnt, fifo_level,
+                                                       count, fifo_level,
+                                                       ABSYNC);
 }
 
 static void davinci_pcm_dma_irq(unsigned link, u16 ch_status, void *data)
@@ -305,7 +307,6 @@ static int ping_pong_dma_setup(struct snd_pcm_substream *substream)
        unsigned int acnt = params->acnt;
        /* divide by 2 for ping/pong */
        unsigned int ping_size = snd_pcm_lib_period_bytes(substream) >> 1;
-       int link = prtd->asp_link[1];
        unsigned int fifo_level = prtd->params->fifo_level;
        unsigned int count;
        if ((data_type == 0) || (data_type > 4)) {
@@ -316,28 +317,26 @@ static int ping_pong_dma_setup(struct snd_pcm_substream *substream)
                dma_addr_t asp_src_pong = iram_dma->addr + ping_size;
                ram_src_cidx = ping_size;
                ram_dst_cidx = -ping_size;
-               edma_set_src(link, asp_src_pong, INCR, W8BIT);
+               edma_set_src(prtd->asp_link[1], asp_src_pong, INCR, W8BIT);
 
-               link = prtd->asp_link[0];
-               edma_set_src_index(link, data_type, data_type * fifo_level);
-               link = prtd->asp_link[1];
-               edma_set_src_index(link, data_type, data_type * fifo_level);
+               edma_set_src_index(prtd->asp_link[0], data_type,
+                               data_type * fifo_level);
+               edma_set_src_index(prtd->asp_link[1], data_type,
+                               data_type * fifo_level);
 
-               link = prtd->ram_link;
-               edma_set_src(link, runtime->dma_addr, INCR, W32BIT);
+               edma_set_src(prtd->ram_link, runtime->dma_addr, INCR, W32BIT);
        } else {
                dma_addr_t asp_dst_pong = iram_dma->addr + ping_size;
                ram_src_cidx = -ping_size;
                ram_dst_cidx = ping_size;
-               edma_set_dest(link, asp_dst_pong, INCR, W8BIT);
+               edma_set_dest(prtd->asp_link[1], asp_dst_pong, INCR, W8BIT);
 
-               link = prtd->asp_link[0];
-               edma_set_dest_index(link, data_type, data_type * fifo_level);
-               link = prtd->asp_link[1];
-               edma_set_dest_index(link, data_type, data_type * fifo_level);
+               edma_set_dest_index(prtd->asp_link[0], data_type,
+                               data_type * fifo_level);
+               edma_set_dest_index(prtd->asp_link[1], data_type,
+                               data_type * fifo_level);
 
-               link = prtd->ram_link;
-               edma_set_dest(link, runtime->dma_addr, INCR, W32BIT);
+               edma_set_dest(prtd->ram_link, runtime->dma_addr, INCR, W32BIT);
        }
 
        if (!fifo_level) {
@@ -354,10 +353,9 @@ static int ping_pong_dma_setup(struct snd_pcm_substream *substream)
                                count, fifo_level, ABSYNC);
        }
 
-       link = prtd->ram_link;
-       edma_set_src_index(link, ping_size, ram_src_cidx);
-       edma_set_dest_index(link, ping_size, ram_dst_cidx);
-       edma_set_transfer_params(link, ping_size, 2,
+       edma_set_src_index(prtd->ram_link, ping_size, ram_src_cidx);
+       edma_set_dest_index(prtd->ram_link, ping_size, ram_dst_cidx);
+       edma_set_transfer_params(prtd->ram_link, ping_size, 2,
                        runtime->periods, 2, ASYNC);
 
        /* init master params */
@@ -406,32 +404,32 @@ static int request_ping_pong(struct snd_pcm_substream *substream,
 {
        dma_addr_t asp_src_ping;
        dma_addr_t asp_dst_ping;
-       int link;
+       int ret;
        struct davinci_pcm_dma_params *params = prtd->params;
 
        /* Request ram master channel */
-       link = prtd->ram_channel = edma_alloc_channel(EDMA_CHANNEL_ANY,
+       ret = prtd->ram_channel = edma_alloc_channel(EDMA_CHANNEL_ANY,
                                  davinci_pcm_dma_irq, substream,
                                  prtd->params->ram_chan_q);
-       if (link < 0)
+       if (ret < 0)
                goto exit1;
 
        /* Request ram link channel */
-       link = prtd->ram_link = edma_alloc_slot(
+       ret = prtd->ram_link = edma_alloc_slot(
                        EDMA_CTLR(prtd->ram_channel), EDMA_SLOT_ANY);
-       if (link < 0)
+       if (ret < 0)
                goto exit2;
 
-       link = prtd->asp_link[1] = edma_alloc_slot(
+       ret = prtd->asp_link[1] = edma_alloc_slot(
                        EDMA_CTLR(prtd->asp_channel), EDMA_SLOT_ANY);
-       if (link < 0)
+       if (ret < 0)
                goto exit3;
 
        prtd->ram_link2 = -1;
        if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
-               link = prtd->ram_link2 = edma_alloc_slot(
+               ret = prtd->ram_link2 = edma_alloc_slot(
                        EDMA_CTLR(prtd->ram_channel), EDMA_SLOT_ANY);
-               if (link < 0)
+               if (ret < 0)
                        goto exit4;
        }
        /* circle ping-pong buffers */
@@ -448,36 +446,33 @@ static int request_ping_pong(struct snd_pcm_substream *substream,
                asp_dst_ping = iram_dma->addr;
        }
        /* ping */
-       link = prtd->asp_link[0];
-       edma_set_src(link, asp_src_ping, INCR, W16BIT);
-       edma_set_dest(link, asp_dst_ping, INCR, W16BIT);
-       edma_set_src_index(link, 0, 0);
-       edma_set_dest_index(link, 0, 0);
+       edma_set_src(prtd->asp_link[0], asp_src_ping, INCR, W16BIT);
+       edma_set_dest(prtd->asp_link[0], asp_dst_ping, INCR, W16BIT);
+       edma_set_src_index(prtd->asp_link[0], 0, 0);
+       edma_set_dest_index(prtd->asp_link[0], 0, 0);
 
-       edma_read_slot(link, &prtd->asp_params);
+       edma_read_slot(prtd->asp_link[0], &prtd->asp_params);
        prtd->asp_params.opt &= ~(TCCMODE | EDMA_TCC(0x3f) | TCINTEN);
        prtd->asp_params.opt |= TCCHEN |
                EDMA_TCC(prtd->ram_channel & 0x3f);
-       edma_write_slot(link, &prtd->asp_params);
+       edma_write_slot(prtd->asp_link[0], &prtd->asp_params);
 
        /* pong */
-       link = prtd->asp_link[1];
-       edma_set_src(link, asp_src_ping, INCR, W16BIT);
-       edma_set_dest(link, asp_dst_ping, INCR, W16BIT);
-       edma_set_src_index(link, 0, 0);
-       edma_set_dest_index(link, 0, 0);
+       edma_set_src(prtd->asp_link[1], asp_src_ping, INCR, W16BIT);
+       edma_set_dest(prtd->asp_link[1], asp_dst_ping, INCR, W16BIT);
+       edma_set_src_index(prtd->asp_link[1], 0, 0);
+       edma_set_dest_index(prtd->asp_link[1], 0, 0);
 
-       edma_read_slot(link, &prtd->asp_params);
+       edma_read_slot(prtd->asp_link[1], &prtd->asp_params);
        prtd->asp_params.opt &= ~(TCCMODE | EDMA_TCC(0x3f));
        /* interrupt after every pong completion */
        prtd->asp_params.opt |= TCINTEN | TCCHEN |
                EDMA_TCC(prtd->ram_channel & 0x3f);
-       edma_write_slot(link, &prtd->asp_params);
+       edma_write_slot(prtd->asp_link[1], &prtd->asp_params);
 
        /* ram */
-       link = prtd->ram_link;
-       edma_set_src(link, iram_dma->addr, INCR, W32BIT);
-       edma_set_dest(link, iram_dma->addr, INCR, W32BIT);
+       edma_set_src(prtd->ram_link, iram_dma->addr, INCR, W32BIT);
+       edma_set_dest(prtd->ram_link, iram_dma->addr, INCR, W32BIT);
        pr_debug("%s: audio dma channels/slots in use for ram:%u %u %u,"
                "for asp:%u %u %u\n", __func__,
                prtd->ram_channel, prtd->ram_link, prtd->ram_link2,
@@ -494,7 +489,7 @@ exit2:
        edma_free_channel(prtd->ram_channel);
        prtd->ram_channel = -1;
 exit1:
-       return link;
+       return ret;
 }
 
 static int davinci_pcm_dma_request(struct snd_pcm_substream *substream)
@@ -502,22 +497,22 @@ static int davinci_pcm_dma_request(struct snd_pcm_substream *substream)
        struct snd_dma_buffer *iram_dma;
        struct davinci_runtime_data *prtd = substream->runtime->private_data;
        struct davinci_pcm_dma_params *params = prtd->params;
-       int link;
+       int ret;
 
        if (!params)
                return -ENODEV;
 
        /* Request asp master DMA channel */
-       link = prtd->asp_channel = edma_alloc_channel(params->channel,
+       ret = prtd->asp_channel = edma_alloc_channel(params->channel,
                        davinci_pcm_dma_irq, substream,
                        prtd->params->asp_chan_q);
-       if (link < 0)
+       if (ret < 0)
                goto exit1;
 
        /* Request asp link channels */
-       link = prtd->asp_link[0] = edma_alloc_slot(
+       ret = prtd->asp_link[0] = edma_alloc_slot(
                        EDMA_CTLR(prtd->asp_channel), EDMA_SLOT_ANY);
-       if (link < 0)
+       if (ret < 0)
                goto exit2;
 
        iram_dma = (struct snd_dma_buffer *)substream->dma_buffer.private_data;
@@ -537,17 +532,17 @@ static int davinci_pcm_dma_request(struct snd_pcm_substream *substream)
         * the buffer and its length (ccnt) ... use it as a template
         * so davinci_pcm_enqueue_dma() takes less time in IRQ.
         */
-       edma_read_slot(link, &prtd->asp_params);
+       edma_read_slot(prtd->asp_link[0], &prtd->asp_params);
        prtd->asp_params.opt |= TCINTEN |
                EDMA_TCC(EDMA_CHAN_SLOT(prtd->asp_channel));
-       prtd->asp_params.link_bcntrld = EDMA_CHAN_SLOT(link) << 5;
-       edma_write_slot(link, &prtd->asp_params);
+       prtd->asp_params.link_bcntrld = EDMA_CHAN_SLOT(prtd->asp_link[0]) << 5;
+       edma_write_slot(prtd->asp_link[0], &prtd->asp_params);
        return 0;
 exit2:
        edma_free_channel(prtd->asp_channel);
        prtd->asp_channel = -1;
 exit1:
-       return link;
+       return ret;
 }
 
 static int davinci_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
index d3aa15119d265414fdbd179c9c9f97997d28dde5..0134d4e9131c9dddff7b298eed13da3cd9b948bb 100644 (file)
 #include <mach/hardware.h>
 #include "ep93xx-pcm.h"
 
-#define edb93xx_has_audio() (machine_is_edb9301() ||   \
-                            machine_is_edb9302() ||    \
-                            machine_is_edb9302a() ||   \
-                            machine_is_edb9307a() ||   \
-                            machine_is_edb9315a())
-
 static int edb93xx_hw_params(struct snd_pcm_substream *substream,
                             struct snd_pcm_hw_params *params)
 {
@@ -94,49 +88,61 @@ static struct snd_soc_card snd_soc_edb93xx = {
        .num_links      = 1,
 };
 
-static struct platform_device *edb93xx_snd_device;
-
-static int __init edb93xx_init(void)
+static int __devinit edb93xx_probe(struct platform_device *pdev)
 {
+       struct snd_soc_card *card = &snd_soc_edb93xx;
        int ret;
 
-       if (!edb93xx_has_audio())
-               return -ENODEV;
-
        ret = ep93xx_i2s_acquire(EP93XX_SYSCON_DEVCFG_I2SONAC97,
                                 EP93XX_SYSCON_I2SCLKDIV_ORIDE |
                                 EP93XX_SYSCON_I2SCLKDIV_SPOL);
        if (ret)
                return ret;
 
-       edb93xx_snd_device = platform_device_alloc("soc-audio", -1);
-       if (!edb93xx_snd_device) {
-               ret = -ENOMEM;
-               goto free_i2s;
+       card->dev = &pdev->dev;
+
+       ret = snd_soc_register_card(card);
+       if (ret) {
+               dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
+                       ret);
+               ep93xx_i2s_release();
        }
 
-       platform_set_drvdata(edb93xx_snd_device, &snd_soc_edb93xx);
-       ret = platform_device_add(edb93xx_snd_device);
-       if (ret)
-               goto device_put;
+       return ret;
+}
 
-       return 0;
+static int __devexit edb93xx_remove(struct platform_device *pdev)
+{
+       struct snd_soc_card *card = platform_get_drvdata(pdev);
 
-device_put:
-       platform_device_put(edb93xx_snd_device);
-free_i2s:
+       snd_soc_unregister_card(card);
        ep93xx_i2s_release();
-       return ret;
+
+       return 0;
+}
+
+static struct platform_driver edb93xx_driver = {
+       .driver         = {
+               .name   = "edb93xx-audio",
+               .owner  = THIS_MODULE,
+       },
+       .probe          = edb93xx_probe,
+       .remove         = __devexit_p(edb93xx_remove),
+};
+
+static int __init edb93xx_init(void)
+{
+       return platform_driver_register(&edb93xx_driver);
 }
 module_init(edb93xx_init);
 
 static void __exit edb93xx_exit(void)
 {
-       platform_device_unregister(edb93xx_snd_device);
-       ep93xx_i2s_release();
+       platform_driver_unregister(&edb93xx_driver);
 }
 module_exit(edb93xx_exit);
 
 MODULE_AUTHOR("Alexander Sverdlin <subaparts@yandex.ru>");
 MODULE_DESCRIPTION("ALSA SoC EDB93xx");
 MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:edb93xx-audio");
index c7417c76552b50a10e45b0ff7949309e2c945850..3cd6158d83e13f486e8c564cbef8ac809b2d7af8 100644 (file)
@@ -335,7 +335,7 @@ static struct snd_soc_dai_ops ep93xx_ac97_dai_ops = {
        .trigger        = ep93xx_ac97_trigger,
 };
 
-struct snd_soc_dai_driver ep93xx_ac97_dai = {
+static struct snd_soc_dai_driver ep93xx_ac97_dai = {
        .name           = "ep93xx-ac97",
        .id             = 0,
        .ac97_control   = 1,
index 8dfd3ad84b19c8f36a1350887659b9024cba7534..d00230a591b19efc8f4df849b7dbe07cb6cb665c 100644 (file)
@@ -355,3 +355,4 @@ module_exit(ep93xx_soc_platform_exit);
 MODULE_AUTHOR("Ryan Mallon");
 MODULE_DESCRIPTION("EP93xx ALSA PCM interface");
 MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:ep93xx-pcm-audio");
index 286817946c5674c6a4536d4afda7507316e99883..968cb316d5115cf0d99bebf6d1fb1a47aef3a4e8 100644 (file)
@@ -39,53 +39,61 @@ static struct snd_soc_card snd_soc_simone = {
 };
 
 static struct platform_device *simone_snd_ac97_device;
-static struct platform_device *simone_snd_device;
 
-static int __init simone_init(void)
+static int __devinit simone_probe(struct platform_device *pdev)
 {
+       struct snd_soc_card *card = &snd_soc_simone;
        int ret;
 
-       if (!machine_is_sim_one())
-               return -ENODEV;
-
-       simone_snd_ac97_device = platform_device_alloc("ac97-codec", -1);
-       if (!simone_snd_ac97_device)
-               return -ENOMEM;
+       simone_snd_ac97_device = platform_device_register_simple("ac97-codec",
+                                                                -1, NULL, 0);
+       if (IS_ERR(simone_snd_ac97_device))
+               return PTR_ERR(simone_snd_ac97_device);
 
-       ret = platform_device_add(simone_snd_ac97_device);
-       if (ret)
-               goto fail1;
+       card->dev = &pdev->dev;
 
-       simone_snd_device = platform_device_alloc("soc-audio", -1);
-       if (!simone_snd_device) {
-               ret = -ENOMEM;
-               goto fail2;
+       ret = snd_soc_register_card(card);
+       if (ret) {
+               dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
+                       ret);
+               platform_device_unregister(simone_snd_ac97_device);
        }
 
-       platform_set_drvdata(simone_snd_device, &snd_soc_simone);
-       ret = platform_device_add(simone_snd_device);
-       if (ret)
-               goto fail3;
+       return ret;
+}
+
+static int __devexit simone_remove(struct platform_device *pdev)
+{
+       struct snd_soc_card *card = platform_get_drvdata(pdev);
+
+       snd_soc_unregister_card(card);
+       platform_device_unregister(simone_snd_ac97_device);
 
        return 0;
+}
 
-fail3:
-       platform_device_put(simone_snd_device);
-fail2:
-       platform_device_del(simone_snd_ac97_device);
-fail1:
-       platform_device_put(simone_snd_ac97_device);
-       return ret;
+static struct platform_driver simone_driver = {
+       .driver         = {
+               .name   = "simone-audio",
+               .owner  = THIS_MODULE,
+       },
+       .probe          = simone_probe,
+       .remove         = __devexit_p(simone_remove),
+};
+
+static int __init simone_init(void)
+{
+       return platform_driver_register(&simone_driver);
 }
 module_init(simone_init);
 
 static void __exit simone_exit(void)
 {
-       platform_device_unregister(simone_snd_device);
-       platform_device_unregister(simone_snd_ac97_device);
+       platform_driver_unregister(&simone_driver);
 }
 module_exit(simone_exit);
 
 MODULE_DESCRIPTION("ALSA SoC Simplemachines Sim.One");
 MODULE_AUTHOR("Mika Westerberg <mika.westerberg@iki.fi>");
 MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:simone-audio");
index c8aa8a5003ca62c84fb8909c9955e80eec765ded..f74ac54c285a8a2c7598c336b988f85612f83365 100644 (file)
@@ -104,37 +104,56 @@ static struct snd_soc_card snd_soc_snappercl15 = {
        .num_links      = 1,
 };
 
-static struct platform_device *snappercl15_snd_device;
-
-static int __init snappercl15_init(void)
+static int __devinit snappercl15_probe(struct platform_device *pdev)
 {
+       struct snd_soc_card *card = &snd_soc_snappercl15;
        int ret;
 
-       if (!machine_is_snapper_cl15())
-               return -ENODEV;
-
        ret = ep93xx_i2s_acquire(EP93XX_SYSCON_DEVCFG_I2SONAC97,
                                 EP93XX_SYSCON_I2SCLKDIV_ORIDE |
                                 EP93XX_SYSCON_I2SCLKDIV_SPOL);
        if (ret)
                return ret;
 
-       snappercl15_snd_device = platform_device_alloc("soc-audio", -1);
-       if (!snappercl15_snd_device)
-               return -ENOMEM;
-       
-       platform_set_drvdata(snappercl15_snd_device, &snd_soc_snappercl15);
-       ret = platform_device_add(snappercl15_snd_device);
-       if (ret)
-               platform_device_put(snappercl15_snd_device);
+       card->dev = &pdev->dev;
+
+       ret = snd_soc_register_card(card);
+       if (ret) {
+               dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
+                       ret);
+               ep93xx_i2s_release();
+       }
 
        return ret;
 }
 
-static void __exit snappercl15_exit(void)
+static int __devexit snappercl15_remove(struct platform_device *pdev)
 {
-       platform_device_unregister(snappercl15_snd_device);
+       struct snd_soc_card *card = platform_get_drvdata(pdev);
+
+       snd_soc_unregister_card(card);
        ep93xx_i2s_release();
+
+       return 0;
+}
+
+static struct platform_driver snappercl15_driver = {
+       .driver         = {
+               .name   = "snappercl15-audio",
+               .owner  = THIS_MODULE,
+       },
+       .probe          = snappercl15_probe,
+       .remove         = __devexit_p(snappercl15_remove),
+};
+
+static int __init snappercl15_init(void)
+{
+       return platform_driver_register(&snappercl15_driver);
+}
+
+static void __exit snappercl15_exit(void)
+{
+       platform_driver_unregister(&snappercl15_driver);
 }
 
 module_init(snappercl15_init);
@@ -143,4 +162,4 @@ module_exit(snappercl15_exit);
 MODULE_AUTHOR("Ryan Mallon");
 MODULE_DESCRIPTION("ALSA SoC Snapper CL15");
 MODULE_LICENSE("GPL");
-
+MODULE_ALIAS("platform:snappercl15-audio");
index cb50598338e92afd2d10997d220a274fd264d378..ef15402a3bc4948311c69b4b69da9ebd7055ee58 100644 (file)
@@ -297,7 +297,6 @@ static irqreturn_t fsl_dma_isr(int irq, void *dev_id)
 static int fsl_dma_new(struct snd_soc_pcm_runtime *rtd)
 {
        struct snd_card *card = rtd->card->snd_card;
-       struct snd_soc_dai *dai = rtd->cpu_dai;
        struct snd_pcm *pcm = rtd->pcm;
        static u64 fsl_dma_dmamask = DMA_BIT_MASK(36);
        int ret;
index d48afea5d93d91c5b95d718768a239683c4f05d3..0268cf989736f303a224fbd26b0db2e8bf97f2ed 100644 (file)
@@ -78,7 +78,6 @@
  * @second_stream: pointer to second stream
  * @playback: the number of playback streams opened
  * @capture: the number of capture streams opened
- * @asynchronous: 0=synchronous mode, 1=asynchronous mode
  * @cpu_dai: the CPU DAI for this device
  * @dev_attr: the sysfs device attribute structure
  * @stats: SSI statistics
@@ -90,9 +89,6 @@ struct fsl_ssi_private {
        unsigned int irq;
        struct snd_pcm_substream *first_stream;
        struct snd_pcm_substream *second_stream;
-       unsigned int playback;
-       unsigned int capture;
-       int asynchronous;
        unsigned int fifo_depth;
        struct snd_soc_dai_driver cpu_dai_drv;
        struct device_attribute dev_attr;
@@ -281,24 +277,18 @@ static int fsl_ssi_startup(struct snd_pcm_substream *substream,
                           struct snd_soc_dai *dai)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct fsl_ssi_private *ssi_private = snd_soc_dai_get_drvdata(rtd->cpu_dai);
+       struct fsl_ssi_private *ssi_private =
+               snd_soc_dai_get_drvdata(rtd->cpu_dai);
+       int synchronous = ssi_private->cpu_dai_drv.symmetric_rates;
 
        /*
         * If this is the first stream opened, then request the IRQ
         * and initialize the SSI registers.
         */
-       if (!ssi_private->playback && !ssi_private->capture) {
+       if (!ssi_private->first_stream) {
                struct ccsr_ssi __iomem *ssi = ssi_private->ssi;
-               int ret;
-
-               /* The 'name' should not have any slashes in it. */
-               ret = request_irq(ssi_private->irq, fsl_ssi_isr, 0,
-                                 ssi_private->name, ssi_private);
-               if (ret < 0) {
-                       dev_err(substream->pcm->card->dev,
-                               "could not claim irq %u\n", ssi_private->irq);
-                       return ret;
-               }
+
+               ssi_private->first_stream = substream;
 
                /*
                 * Section 16.5 of the MPC8610 reference manual says that the
@@ -316,7 +306,7 @@ static int fsl_ssi_startup(struct snd_pcm_substream *substream,
                clrsetbits_be32(&ssi->scr,
                        CCSR_SSI_SCR_I2S_MODE_MASK | CCSR_SSI_SCR_SYN,
                        CCSR_SSI_SCR_TFR_CLK_DIS | CCSR_SSI_SCR_I2S_MODE_SLAVE
-                       | (ssi_private->asynchronous ? 0 : CCSR_SSI_SCR_SYN));
+                       | (synchronous ? CCSR_SSI_SCR_SYN : 0));
 
                out_be32(&ssi->stcr,
                         CCSR_SSI_STCR_TXBIT0 | CCSR_SSI_STCR_TFEN0 |
@@ -333,7 +323,7 @@ static int fsl_ssi_startup(struct snd_pcm_substream *substream,
                 * master.
                 */
 
-               /* 4. Enable the interrupts and DMA requests */
+               /* Enable the interrupts and DMA requests */
                out_be32(&ssi->sier, SIER_FLAGS);
 
                /*
@@ -362,58 +352,47 @@ static int fsl_ssi_startup(struct snd_pcm_substream *substream,
                 * this is bad is because at this point, the PCM driver has not
                 * finished initializing the DMA controller.
                 */
-       }
+       } else {
+               if (synchronous) {
+                       struct snd_pcm_runtime *first_runtime =
+                               ssi_private->first_stream->runtime;
+                       /*
+                        * This is the second stream open, and we're in
+                        * synchronous mode, so we need to impose sample
+                        * sample size constraints. This is because STCCR is
+                        * used for playback and capture in synchronous mode,
+                        * so there's no way to specify different word
+                        * lengths.
+                        *
+                        * Note that this can cause a race condition if the
+                        * second stream is opened before the first stream is
+                        * fully initialized.  We provide some protection by
+                        * checking to make sure the first stream is
+                        * initialized, but it's not perfect.  ALSA sometimes
+                        * re-initializes the driver with a different sample
+                        * rate or size.  If the second stream is opened
+                        * before the first stream has received its final
+                        * parameters, then the second stream may be
+                        * constrained to the wrong sample rate or size.
+                        */
+                       if (!first_runtime->sample_bits) {
+                               dev_err(substream->pcm->card->dev,
+                                       "set sample size in %s stream first\n",
+                                       substream->stream ==
+                                       SNDRV_PCM_STREAM_PLAYBACK
+                                       ? "capture" : "playback");
+                               return -EAGAIN;
+                       }
 
-       if (!ssi_private->first_stream)
-               ssi_private->first_stream = substream;
-       else {
-               /* This is the second stream open, so we need to impose sample
-                * rate and maybe sample size constraints.  Note that this can
-                * cause a race condition if the second stream is opened before
-                * the first stream is fully initialized.
-                *
-                * We provide some protection by checking to make sure the first
-                * stream is initialized, but it's not perfect.  ALSA sometimes
-                * re-initializes the driver with a different sample rate or
-                * size.  If the second stream is opened before the first stream
-                * has received its final parameters, then the second stream may
-                * be constrained to the wrong sample rate or size.
-                *
-                * FIXME: This code does not handle opening and closing streams
-                * repeatedly.  If you open two streams and then close the first
-                * one, you may not be able to open another stream until you
-                * close the second one as well.
-                */
-               struct snd_pcm_runtime *first_runtime =
-                       ssi_private->first_stream->runtime;
-
-               if (!first_runtime->sample_bits) {
-                       dev_err(substream->pcm->card->dev,
-                               "set sample size in %s stream first\n",
-                               substream->stream == SNDRV_PCM_STREAM_PLAYBACK
-                               ? "capture" : "playback");
-                       return -EAGAIN;
-               }
-
-               /* If we're in synchronous mode, then we need to constrain
-                * the sample size as well.  We don't support independent sample
-                * rates in asynchronous mode.
-                */
-               if (!ssi_private->asynchronous)
                        snd_pcm_hw_constraint_minmax(substream->runtime,
                                SNDRV_PCM_HW_PARAM_SAMPLE_BITS,
                                first_runtime->sample_bits,
                                first_runtime->sample_bits);
+               }
 
                ssi_private->second_stream = substream;
        }
 
-       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
-               ssi_private->playback++;
-
-       if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
-               ssi_private->capture++;
-
        return 0;
 }
 
@@ -434,24 +413,35 @@ static int fsl_ssi_hw_params(struct snd_pcm_substream *substream,
        struct snd_pcm_hw_params *hw_params, struct snd_soc_dai *cpu_dai)
 {
        struct fsl_ssi_private *ssi_private = snd_soc_dai_get_drvdata(cpu_dai);
+       struct ccsr_ssi __iomem *ssi = ssi_private->ssi;
+       unsigned int sample_size =
+               snd_pcm_format_width(params_format(hw_params));
+       u32 wl = CCSR_SSI_SxCCR_WL(sample_size);
+       int enabled = in_be32(&ssi->scr) & CCSR_SSI_SCR_SSIEN;
 
-       if (substream == ssi_private->first_stream) {
-               struct ccsr_ssi __iomem *ssi = ssi_private->ssi;
-               unsigned int sample_size =
-                       snd_pcm_format_width(params_format(hw_params));
-               u32 wl = CCSR_SSI_SxCCR_WL(sample_size);
+       /*
+        * If we're in synchronous mode, and the SSI is already enabled,
+        * then STCCR is already set properly.
+        */
+       if (enabled && ssi_private->cpu_dai_drv.symmetric_rates)
+               return 0;
 
-               /* The SSI should always be disabled at this points (SSIEN=0) */
+       /*
+        * FIXME: The documentation says that SxCCR[WL] should not be
+        * modified while the SSI is enabled.  The only time this can
+        * happen is if we're trying to do simultaneous playback and
+        * capture in asynchronous mode.  Unfortunately, I have been enable
+        * to get that to work at all on the P1022DS.  Therefore, we don't
+        * bother to disable/enable the SSI when setting SxCCR[WL], because
+        * the SSI will stop anyway.  Maybe one day, this will get fixed.
+        */
 
-               /* In synchronous mode, the SSI uses STCCR for capture */
-               if ((substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ||
-                   !ssi_private->asynchronous)
-                       clrsetbits_be32(&ssi->stccr,
-                                       CCSR_SSI_SxCCR_WL_MASK, wl);
-               else
-                       clrsetbits_be32(&ssi->srccr,
-                                       CCSR_SSI_SxCCR_WL_MASK, wl);
-       }
+       /* In synchronous mode, the SSI uses STCCR for capture */
+       if ((substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ||
+           ssi_private->cpu_dai_drv.symmetric_rates)
+               clrsetbits_be32(&ssi->stccr, CCSR_SSI_SxCCR_WL_MASK, wl);
+       else
+               clrsetbits_be32(&ssi->srccr, CCSR_SSI_SxCCR_WL_MASK, wl);
 
        return 0;
 }
@@ -474,7 +464,6 @@ static int fsl_ssi_trigger(struct snd_pcm_substream *substream, int cmd,
 
        switch (cmd) {
        case SNDRV_PCM_TRIGGER_START:
-               clrbits32(&ssi->scr, CCSR_SSI_SCR_SSIEN);
        case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
                if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
                        setbits32(&ssi->scr,
@@ -510,27 +499,18 @@ static void fsl_ssi_shutdown(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct fsl_ssi_private *ssi_private = snd_soc_dai_get_drvdata(rtd->cpu_dai);
 
-       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
-               ssi_private->playback--;
-
-       if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
-               ssi_private->capture--;
-
        if (ssi_private->first_stream == substream)
                ssi_private->first_stream = ssi_private->second_stream;
 
        ssi_private->second_stream = NULL;
 
        /*
-        * If this is the last active substream, disable the SSI and release
-        * the IRQ.
+        * If this is the last active substream, disable the SSI.
         */
-       if (!ssi_private->playback && !ssi_private->capture) {
+       if (!ssi_private->first_stream) {
                struct ccsr_ssi __iomem *ssi = ssi_private->ssi;
 
                clrbits32(&ssi->scr, CCSR_SSI_SCR_SSIEN);
-
-               free_irq(ssi_private->irq, ssi_private);
        }
 }
 
@@ -675,22 +655,33 @@ static int __devinit fsl_ssi_probe(struct platform_device *pdev)
        ret = of_address_to_resource(np, 0, &res);
        if (ret) {
                dev_err(&pdev->dev, "could not determine device resources\n");
-               kfree(ssi_private);
-               return ret;
+               goto error_kmalloc;
        }
        ssi_private->ssi = of_iomap(np, 0);
        if (!ssi_private->ssi) {
                dev_err(&pdev->dev, "could not map device resources\n");
-               kfree(ssi_private);
-               return -ENOMEM;
+               ret = -ENOMEM;
+               goto error_kmalloc;
        }
        ssi_private->ssi_phys = res.start;
+
        ssi_private->irq = irq_of_parse_and_map(np, 0);
+       if (ssi_private->irq == NO_IRQ) {
+               dev_err(&pdev->dev, "no irq for node %s\n", np->full_name);
+               ret = -ENXIO;
+               goto error_iomap;
+       }
+
+       /* The 'name' should not have any slashes in it. */
+       ret = request_irq(ssi_private->irq, fsl_ssi_isr, 0, ssi_private->name,
+                         ssi_private);
+       if (ret < 0) {
+               dev_err(&pdev->dev, "could not claim irq %u\n", ssi_private->irq);
+               goto error_irqmap;
+       }
 
        /* Are the RX and the TX clocks locked? */
-       if (of_find_property(np, "fsl,ssi-asynchronous", NULL))
-               ssi_private->asynchronous = 1;
-       else
+       if (!of_find_property(np, "fsl,ssi-asynchronous", NULL))
                ssi_private->cpu_dai_drv.symmetric_rates = 1;
 
        /* Determine the FIFO depth. */
@@ -711,7 +702,7 @@ static int __devinit fsl_ssi_probe(struct platform_device *pdev)
        if (ret) {
                dev_err(&pdev->dev, "could not create sysfs %s file\n",
                        ssi_private->dev_attr.attr.name);
-               goto error;
+               goto error_irq;
        }
 
        /* Register with ASoC */
@@ -720,7 +711,7 @@ static int __devinit fsl_ssi_probe(struct platform_device *pdev)
        ret = snd_soc_register_dai(&pdev->dev, &ssi_private->cpu_dai_drv);
        if (ret) {
                dev_err(&pdev->dev, "failed to register DAI: %d\n", ret);
-               goto error;
+               goto error_dev;
        }
 
        /* Trigger the machine driver's probe function.  The platform driver
@@ -741,18 +732,28 @@ static int __devinit fsl_ssi_probe(struct platform_device *pdev)
        if (IS_ERR(ssi_private->pdev)) {
                ret = PTR_ERR(ssi_private->pdev);
                dev_err(&pdev->dev, "failed to register platform: %d\n", ret);
-               goto error;
+               goto error_dai;
        }
 
        return 0;
 
-error:
+error_dai:
        snd_soc_unregister_dai(&pdev->dev);
+
+error_dev:
        dev_set_drvdata(&pdev->dev, NULL);
-       if (dev_attr)
-               device_remove_file(&pdev->dev, dev_attr);
+       device_remove_file(&pdev->dev, dev_attr);
+
+error_irq:
+       free_irq(ssi_private->irq, ssi_private);
+
+error_irqmap:
        irq_dispose_mapping(ssi_private->irq);
+
+error_iomap:
        iounmap(ssi_private->ssi);
+
+error_kmalloc:
        kfree(ssi_private);
 
        return ret;
@@ -766,6 +767,9 @@ static int fsl_ssi_remove(struct platform_device *pdev)
        snd_soc_unregister_dai(&pdev->dev);
        device_remove_file(&pdev->dev, &ssi_private->dev_attr);
 
+       free_irq(ssi_private->irq, ssi_private);
+       irq_dispose_mapping(ssi_private->irq);
+
        kfree(ssi_private);
        dev_set_drvdata(&pdev->dev, NULL);
 
index 358f0baaf71b2df230295cda7ccf9f4df2fa901a..31af405bda843cc691e755cc6bb4a0afec78925f 100644 (file)
@@ -505,7 +505,7 @@ static int mpc8610_hpcd_probe(struct platform_device *pdev)
        return 0;
 
 error_sound:
-       platform_device_unregister(sound_device);
+       platform_device_put(sound_device);
 error:
        kfree(machine_data);
 error_alloc:
index fcb862eb0c73420e1c3ecb65c240e8ed2a2569f2..2c064a9824adf84d345829be5d6d80544df5c7d8 100644 (file)
@@ -267,7 +267,7 @@ static int codec_node_dev_name(struct device_node *np, char *buf, size_t len)
        if (bus < 0)
                return bus;
 
-       snprintf(buf, len, "%s-codec.%u-%04x", temp, bus, addr);
+       snprintf(buf, len, "%s.%u-%04x", temp, bus, addr);
 
        return 0;
 }
@@ -506,7 +506,7 @@ static int p1022_ds_probe(struct platform_device *pdev)
 
 error:
        if (sound_device)
-               platform_device_unregister(sound_device);
+               platform_device_put(sound_device);
 
        kfree(mdata);
 error_put:
index bb699bb55a502c041b9d47fff2f5c396c8c431c8..b133bfcc5848ea8f6ec3c7cab18772ac18bc07b9 100644 (file)
@@ -29,7 +29,7 @@ config SND_MXC_SOC_WM1133_EV1
 config SND_SOC_MX27VIS_AIC32X4
        tristate "SoC audio support for Visstrim M10 boards"
        depends on MACH_IMX27_VISSTRIM_M10
-       select SND_SOC_TVL320AIC32X4
+       select SND_SOC_TLV320AIC32X4
        select SND_MXC_SOC_MX2
        help
          Say Y if you want to add support for SoC audio on Visstrim SM10
@@ -50,6 +50,7 @@ config SND_SOC_EUKREA_TLV320
                || MACH_EUKREA_MBIMXSD25_BASEBOARD \
                || MACH_EUKREA_MBIMXSD35_BASEBOARD \
                || MACH_EUKREA_MBIMXSD51_BASEBOARD
+       depends on I2C
        select SND_SOC_TLV320AIC23
        select SND_MXC_SOC_FIQ
        help
index 7945625e0e087090d62948e0cacd14f2c792acea..8df0fae21943b64d9bb99ffd462b679592a69742 100644 (file)
@@ -240,25 +240,23 @@ static int ssi_irq = 0;
 
 static int imx_pcm_fiq_new(struct snd_soc_pcm_runtime *rtd)
 {
-       struct snd_soc_dai *dai = rtd->cpu_dai;
        struct snd_pcm *pcm = rtd->pcm;
+       struct snd_pcm_substream *substream;
        int ret;
 
        ret = imx_pcm_new(rtd);
        if (ret)
                return ret;
 
-       if (dai->driver->playback.channels_min) {
-               struct snd_pcm_substream *substream =
-                       pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
+       substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
+       if (substream) {
                struct snd_dma_buffer *buf = &substream->dma_buffer;
 
                imx_ssi_fiq_tx_buffer = (unsigned long)buf->area;
        }
 
-       if (dai->driver->capture.channels_min) {
-               struct snd_pcm_substream *substream =
-                       pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream;
+       substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream;
+       if (substream) {
                struct snd_dma_buffer *buf = &substream->dma_buffer;
 
                imx_ssi_fiq_rx_buffer = (unsigned long)buf->area;
index 10a8e2783751bee1f137d959d3931544f8862f12..4c05e2b8f4d2bf3bd09309c5e254e8bce02814b6 100644 (file)
@@ -357,8 +357,8 @@ int snd_imx_pcm_mmap(struct snd_pcm_substream *substream,
        struct snd_pcm_runtime *runtime = substream->runtime;
        int ret;
 
-       ret = dma_mmap_coherent(NULL, vma, runtime->dma_area,
-                       runtime->dma_addr, runtime->dma_bytes);
+       ret = dma_mmap_writecombine(substream->pcm->card->dev, vma,
+               runtime->dma_area, runtime->dma_addr, runtime->dma_bytes);
 
        pr_debug("%s: ret: %d %p 0x%08x 0x%08x\n", __func__, ret,
                        runtime->dma_area,
@@ -391,7 +391,6 @@ static u64 imx_pcm_dmamask = DMA_BIT_MASK(32);
 int imx_pcm_new(struct snd_soc_pcm_runtime *rtd)
 {
        struct snd_card *card = rtd->card->snd_card;
-       struct snd_soc_dai *dai = rtd->cpu_dai;
        struct snd_pcm *pcm = rtd->pcm;
        int ret = 0;
 
@@ -399,14 +398,14 @@ int imx_pcm_new(struct snd_soc_pcm_runtime *rtd)
                card->dev->dma_mask = &imx_pcm_dmamask;
        if (!card->dev->coherent_dma_mask)
                card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
-       if (dai->driver->playback.channels_min) {
+       if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
                ret = imx_pcm_preallocate_dma_buffer(pcm,
                        SNDRV_PCM_STREAM_PLAYBACK);
                if (ret)
                        goto out;
        }
 
-       if (dai->driver->capture.channels_min) {
+       if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
                ret = imx_pcm_preallocate_dma_buffer(pcm,
                        SNDRV_PCM_STREAM_CAPTURE);
                if (ret)
index 0a84cec3599e08d43d02728ee15a056fbcef03e8..1072dfb53e4772f306c9dfcb38262e6c02c8d62c 100644 (file)
@@ -218,12 +218,6 @@ struct imx_ssi {
        struct platform_device *soc_platform_pdev_fiq;
 };
 
-struct snd_soc_platform *imx_ssi_fiq_init(struct platform_device *pdev,
-               struct imx_ssi *ssi);
-void imx_ssi_fiq_exit(struct platform_device *pdev, struct imx_ssi *ssi);
-struct snd_soc_platform *imx_ssi_dma_mx2_init(struct platform_device *pdev,
-               struct imx_ssi *ssi);
-
 int snd_imx_pcm_mmap(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
 int imx_pcm_new(struct snd_soc_pcm_runtime *rtd);
 void imx_pcm_free(struct snd_pcm *pcm);
index a7c9578be983d431c44a6631a14e688a58ec9560..d1989cde9f14d0d442531066f96b2a6e9c4f3525 100644 (file)
@@ -299,7 +299,7 @@ static void jz4740_pcm_free(struct snd_pcm *pcm)
 
 static u64 jz4740_pcm_dmamask = DMA_BIT_MASK(32);
 
-int jz4740_pcm_new(struct snd_soc_pcm_runtime *rtd)
+static int jz4740_pcm_new(struct snd_soc_pcm_runtime *rtd)
 {
        struct snd_card *card = rtd->card->snd_card;
        struct snd_soc_dai *dai = rtd->cpu_dai;
index d0bcf3fcea01f4675fc635a5531c7f1f81e3cf3c..715e841c05072edeb469f1e99dc4aa60ad2821c5 100644 (file)
@@ -476,7 +476,7 @@ static __devexit int kirkwood_i2s_dev_remove(struct platform_device *pdev)
 
 static struct platform_driver kirkwood_i2s_driver = {
        .probe  = kirkwood_i2s_dev_probe,
-       .remove = kirkwood_i2s_dev_remove,
+       .remove = __devexit_p(kirkwood_i2s_dev_remove),
        .driver = {
                .name = DRV_NAME,
                .owner = THIS_MODULE,
index c8d21956ab52346dfe6a74b670eeb62cb590bdb6..c772b3cf4039f77386dbc4d77551b70a0e8a1323 100644 (file)
@@ -79,8 +79,6 @@ static int t5325_dai_init(struct snd_soc_pcm_runtime *rtd)
        snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
        snd_soc_dapm_enable_pin(dapm, "Speaker");
 
-       snd_soc_dapm_sync(dapm);
-
        return 0;
 }
 
index 429aa1be2cffa6ae8d73b3d3547373afb74fd2cd..598f48c0d8f5de74a3ee863b44c19c150e9edd0e 100644 (file)
@@ -54,9 +54,7 @@ static unsigned int   hs_switch;
 static unsigned int    lo_dac;
 
 struct mfld_mc_private {
-       struct platform_device *socdev;
        void __iomem *int_base;
-       struct snd_soc_codec *codec;
        u8 interrupt_status;
 };
 
@@ -235,7 +233,6 @@ static int mfld_init(struct snd_soc_pcm_runtime *runtime)
        /* always connected */
        snd_soc_dapm_enable_pin(dapm, "Headphones");
        snd_soc_dapm_enable_pin(dapm, "Mic");
-       snd_soc_dapm_sync(dapm);
 
        ret_val = snd_soc_add_controls(codec, mfld_snd_controls,
                                ARRAY_SIZE(mfld_snd_controls));
@@ -253,7 +250,6 @@ static int mfld_init(struct snd_soc_pcm_runtime *runtime)
        /* we dont use linein in this so set to NC */
        snd_soc_dapm_disable_pin(dapm, "LINEINL");
        snd_soc_dapm_disable_pin(dapm, "LINEINR");
-       snd_soc_dapm_sync(dapm);
 
        /* Headset and button jack detection */
        ret_val = snd_soc_jack_new(codec, "Intel(R) MID Audio Jack",
index 3e7826058efe61375b1fa938e1569cea87d7a21e..7df8c58ba50ae3ae0015e3f7cb915049a71cfb5c 100644 (file)
@@ -63,7 +63,7 @@ static struct snd_pcm_hardware sst_platform_pcm_hw = {
 };
 
 /* MFLD - MSIC */
-struct snd_soc_dai_driver sst_platform_dai[] = {
+static struct snd_soc_dai_driver sst_platform_dai[] = {
 {
        .name = "Headset-cpu-dai",
        .id = 0,
@@ -226,13 +226,18 @@ static int sst_platform_init_stream(struct snd_pcm_substream *substream)
 
 static int sst_platform_open(struct snd_pcm_substream *substream)
 {
-       struct snd_pcm_runtime *runtime;
+       struct snd_pcm_runtime *runtime = substream->runtime;
        struct sst_runtime_stream *stream;
        int ret_val = 0;
 
        pr_debug("sst_platform_open called\n");
-       runtime = substream->runtime;
-       runtime->hw = sst_platform_pcm_hw;
+
+       snd_soc_set_runtime_hwparams(substream, &sst_platform_pcm_hw);
+       ret_val = snd_pcm_hw_constraint_integer(runtime,
+                                               SNDRV_PCM_HW_PARAM_PERIODS);
+       if (ret_val < 0)
+               return ret_val;
+
        stream = kzalloc(sizeof(*stream), GFP_KERNEL);
        if (!stream)
                return -ENOMEM;
@@ -259,8 +264,8 @@ static int sst_platform_open(struct snd_pcm_substream *substream)
                return ret_val;
        }
        runtime->private_data = stream;
-       return snd_pcm_hw_constraint_integer(runtime,
-                        SNDRV_PCM_HW_PARAM_PERIODS);
+
+       return 0;
 }
 
 static int sst_platform_close(struct snd_pcm_substream *substream)
@@ -469,7 +474,7 @@ static struct platform_driver sst_platform_driver = {
 static int __init sst_soc_platform_init(void)
 {
        pr_debug("sst_soc_platform_init called\n");
-       return  platform_driver_register(&sst_platform_driver);
+       return platform_driver_register(&sst_platform_driver);
 }
 module_init(sst_soc_platform_init);
 
diff --git a/sound/soc/mxs/Kconfig b/sound/soc/mxs/Kconfig
new file mode 100644 (file)
index 0000000..e4ba8d5
--- /dev/null
@@ -0,0 +1,20 @@
+menuconfig SND_MXS_SOC
+       tristate "SoC Audio for Freescale MXS CPUs"
+       depends on ARCH_MXS
+       select SND_PCM
+       help
+         Say Y or M if you want to add support for codecs attached to
+         the MXS SAIF interface.
+
+
+if SND_MXS_SOC
+
+config SND_SOC_MXS_SGTL5000
+       tristate "SoC Audio support for i.MX boards with sgtl5000"
+       depends on I2C
+       select SND_SOC_SGTL5000
+       help
+         Say Y if you want to add support for SoC audio on an MXS board with
+         a sgtl5000 codec.
+
+endif  # SND_MXS_SOC
diff --git a/sound/soc/mxs/Makefile b/sound/soc/mxs/Makefile
new file mode 100644 (file)
index 0000000..565b5b5
--- /dev/null
@@ -0,0 +1,10 @@
+# MXS Platform Support
+snd-soc-mxs-objs := mxs-saif.o
+snd-soc-mxs-pcm-objs := mxs-pcm.o
+
+obj-$(CONFIG_SND_MXS_SOC) += snd-soc-mxs.o snd-soc-mxs-pcm.o
+
+# i.MX Machine Support
+snd-soc-mxs-sgtl5000-objs := mxs-sgtl5000.o
+
+obj-$(CONFIG_SND_SOC_MXS_SGTL5000) += snd-soc-mxs-sgtl5000.o
diff --git a/sound/soc/mxs/mxs-pcm.c b/sound/soc/mxs/mxs-pcm.c
new file mode 100644 (file)
index 0000000..dea5aa4
--- /dev/null
@@ -0,0 +1,359 @@
+/*
+ * Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved.
+ *
+ * Based on sound/soc/imx/imx-pcm-dma-mx2.c
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/dma-mapping.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/dmaengine.h>
+
+#include <sound/core.h>
+#include <sound/initval.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+
+#include <mach/dma.h>
+#include "mxs-pcm.h"
+
+static struct snd_pcm_hardware snd_mxs_hardware = {
+       .info                   = SNDRV_PCM_INFO_MMAP |
+                                 SNDRV_PCM_INFO_MMAP_VALID |
+                                 SNDRV_PCM_INFO_PAUSE |
+                                 SNDRV_PCM_INFO_RESUME |
+                                 SNDRV_PCM_INFO_INTERLEAVED,
+       .formats                = SNDRV_PCM_FMTBIT_S16_LE |
+                                 SNDRV_PCM_FMTBIT_S20_3LE |
+                                 SNDRV_PCM_FMTBIT_S24_LE,
+       .channels_min           = 2,
+       .channels_max           = 2,
+       .period_bytes_min       = 32,
+       .period_bytes_max       = 8192,
+       .periods_min            = 1,
+       .periods_max            = 52,
+       .buffer_bytes_max       = 64 * 1024,
+       .fifo_size              = 32,
+
+};
+
+static void audio_dma_irq(void *data)
+{
+       struct snd_pcm_substream *substream = (struct snd_pcm_substream *)data;
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct mxs_pcm_runtime_data *iprtd = runtime->private_data;
+
+       iprtd->offset += iprtd->period_bytes;
+       iprtd->offset %= iprtd->period_bytes * iprtd->periods;
+       snd_pcm_period_elapsed(substream);
+}
+
+static bool filter(struct dma_chan *chan, void *param)
+{
+       struct mxs_pcm_runtime_data *iprtd = param;
+       struct mxs_pcm_dma_params *dma_params = iprtd->dma_params;
+
+       if (!mxs_dma_is_apbx(chan))
+               return false;
+
+       if (chan->chan_id != dma_params->chan_num)
+               return false;
+
+       chan->private = &iprtd->dma_data;
+
+       return true;
+}
+
+static int mxs_dma_alloc(struct snd_pcm_substream *substream,
+                               struct snd_pcm_hw_params *params)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct mxs_pcm_runtime_data *iprtd = runtime->private_data;
+       dma_cap_mask_t mask;
+
+       iprtd->dma_params = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
+
+       dma_cap_zero(mask);
+       dma_cap_set(DMA_SLAVE, mask);
+       iprtd->dma_data.chan_irq = iprtd->dma_params->chan_irq;
+       iprtd->dma_chan = dma_request_channel(mask, filter, iprtd);
+       if (!iprtd->dma_chan)
+               return -EINVAL;
+
+       return 0;
+}
+
+static int snd_mxs_pcm_hw_params(struct snd_pcm_substream *substream,
+                               struct snd_pcm_hw_params *params)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct mxs_pcm_runtime_data *iprtd = runtime->private_data;
+       unsigned long dma_addr;
+       struct dma_chan *chan;
+       int ret;
+
+       ret = mxs_dma_alloc(substream, params);
+       if (ret)
+               return ret;
+       chan = iprtd->dma_chan;
+
+       iprtd->size = params_buffer_bytes(params);
+       iprtd->periods = params_periods(params);
+       iprtd->period_bytes = params_period_bytes(params);
+       iprtd->offset = 0;
+       iprtd->period_time = HZ / (params_rate(params) /
+                       params_period_size(params));
+
+       snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
+
+       dma_addr = runtime->dma_addr;
+
+       iprtd->buf = substream->dma_buffer.area;
+
+       iprtd->desc = chan->device->device_prep_dma_cyclic(chan, dma_addr,
+                       iprtd->period_bytes * iprtd->periods,
+                       iprtd->period_bytes,
+                       substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
+                       DMA_TO_DEVICE : DMA_FROM_DEVICE);
+       if (!iprtd->desc) {
+               dev_err(&chan->dev->device, "cannot prepare slave dma\n");
+               return -EINVAL;
+       }
+
+       iprtd->desc->callback = audio_dma_irq;
+       iprtd->desc->callback_param = substream;
+
+       return 0;
+}
+
+static int snd_mxs_pcm_hw_free(struct snd_pcm_substream *substream)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct mxs_pcm_runtime_data *iprtd = runtime->private_data;
+
+       if (iprtd->dma_chan) {
+               dma_release_channel(iprtd->dma_chan);
+               iprtd->dma_chan = NULL;
+       }
+
+       return 0;
+}
+
+static int snd_mxs_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct mxs_pcm_runtime_data *iprtd = runtime->private_data;
+
+       switch (cmd) {
+       case SNDRV_PCM_TRIGGER_START:
+       case SNDRV_PCM_TRIGGER_RESUME:
+       case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+               dmaengine_submit(iprtd->desc);
+
+               break;
+       case SNDRV_PCM_TRIGGER_STOP:
+       case SNDRV_PCM_TRIGGER_SUSPEND:
+       case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+               dmaengine_terminate_all(iprtd->dma_chan);
+
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static snd_pcm_uframes_t snd_mxs_pcm_pointer(
+               struct snd_pcm_substream *substream)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct mxs_pcm_runtime_data *iprtd = runtime->private_data;
+
+       return bytes_to_frames(substream->runtime, iprtd->offset);
+}
+
+static int snd_mxs_open(struct snd_pcm_substream *substream)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct mxs_pcm_runtime_data *iprtd;
+       int ret;
+
+       iprtd = kzalloc(sizeof(*iprtd), GFP_KERNEL);
+       if (iprtd == NULL)
+               return -ENOMEM;
+       runtime->private_data = iprtd;
+
+       ret = snd_pcm_hw_constraint_integer(substream->runtime,
+                       SNDRV_PCM_HW_PARAM_PERIODS);
+       if (ret < 0) {
+               kfree(iprtd);
+               return ret;
+       }
+
+       snd_soc_set_runtime_hwparams(substream, &snd_mxs_hardware);
+
+       return 0;
+}
+
+static int snd_mxs_close(struct snd_pcm_substream *substream)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct mxs_pcm_runtime_data *iprtd = runtime->private_data;
+
+       kfree(iprtd);
+
+       return 0;
+}
+
+static int snd_mxs_pcm_mmap(struct snd_pcm_substream *substream,
+               struct vm_area_struct *vma)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+
+       return dma_mmap_writecombine(substream->pcm->card->dev, vma,
+                                       runtime->dma_area,
+                                       runtime->dma_addr,
+                                       runtime->dma_bytes);
+}
+
+static struct snd_pcm_ops mxs_pcm_ops = {
+       .open           = snd_mxs_open,
+       .close          = snd_mxs_close,
+       .ioctl          = snd_pcm_lib_ioctl,
+       .hw_params      = snd_mxs_pcm_hw_params,
+       .hw_free        = snd_mxs_pcm_hw_free,
+       .trigger        = snd_mxs_pcm_trigger,
+       .pointer        = snd_mxs_pcm_pointer,
+       .mmap           = snd_mxs_pcm_mmap,
+};
+
+static int mxs_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
+{
+       struct snd_pcm_substream *substream = pcm->streams[stream].substream;
+       struct snd_dma_buffer *buf = &substream->dma_buffer;
+       size_t size = snd_mxs_hardware.buffer_bytes_max;
+
+       buf->dev.type = SNDRV_DMA_TYPE_DEV;
+       buf->dev.dev = pcm->card->dev;
+       buf->private_data = NULL;
+       buf->area = dma_alloc_writecombine(pcm->card->dev, size,
+                                          &buf->addr, GFP_KERNEL);
+       if (!buf->area)
+               return -ENOMEM;
+       buf->bytes = size;
+
+       return 0;
+}
+
+static u64 mxs_pcm_dmamask = DMA_BIT_MASK(32);
+static int mxs_pcm_new(struct snd_soc_pcm_runtime *rtd)
+{
+       struct snd_card *card = rtd->card->snd_card;
+       struct snd_pcm *pcm = rtd->pcm;
+       int ret = 0;
+
+       if (!card->dev->dma_mask)
+               card->dev->dma_mask = &mxs_pcm_dmamask;
+       if (!card->dev->coherent_dma_mask)
+               card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
+
+       if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
+               ret = mxs_pcm_preallocate_dma_buffer(pcm,
+                       SNDRV_PCM_STREAM_PLAYBACK);
+               if (ret)
+                       goto out;
+       }
+
+       if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
+               ret = mxs_pcm_preallocate_dma_buffer(pcm,
+                       SNDRV_PCM_STREAM_CAPTURE);
+               if (ret)
+                       goto out;
+       }
+
+out:
+       return ret;
+}
+
+static void mxs_pcm_free(struct snd_pcm *pcm)
+{
+       struct snd_pcm_substream *substream;
+       struct snd_dma_buffer *buf;
+       int stream;
+
+       for (stream = 0; stream < 2; stream++) {
+               substream = pcm->streams[stream].substream;
+               if (!substream)
+                       continue;
+
+               buf = &substream->dma_buffer;
+               if (!buf->area)
+                       continue;
+
+               dma_free_writecombine(pcm->card->dev, buf->bytes,
+                                     buf->area, buf->addr);
+               buf->area = NULL;
+       }
+}
+
+static struct snd_soc_platform_driver mxs_soc_platform = {
+       .ops            = &mxs_pcm_ops,
+       .pcm_new        = mxs_pcm_new,
+       .pcm_free       = mxs_pcm_free,
+};
+
+static int __devinit mxs_soc_platform_probe(struct platform_device *pdev)
+{
+       return snd_soc_register_platform(&pdev->dev, &mxs_soc_platform);
+}
+
+static int __devexit mxs_soc_platform_remove(struct platform_device *pdev)
+{
+       snd_soc_unregister_platform(&pdev->dev);
+
+       return 0;
+}
+
+static struct platform_driver mxs_pcm_driver = {
+       .driver = {
+               .name = "mxs-pcm-audio",
+               .owner = THIS_MODULE,
+       },
+       .probe = mxs_soc_platform_probe,
+       .remove = __devexit_p(mxs_soc_platform_remove),
+};
+
+static int __init snd_mxs_pcm_init(void)
+{
+       return platform_driver_register(&mxs_pcm_driver);
+}
+module_init(snd_mxs_pcm_init);
+
+static void __exit snd_mxs_pcm_exit(void)
+{
+       platform_driver_unregister(&mxs_pcm_driver);
+}
+module_exit(snd_mxs_pcm_exit);
diff --git a/sound/soc/mxs/mxs-pcm.h b/sound/soc/mxs/mxs-pcm.h
new file mode 100644 (file)
index 0000000..f55ac4f
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef _MXS_PCM_H
+#define _MXS_PCM_H
+
+#include <mach/dma.h>
+
+struct mxs_pcm_dma_params {
+       int chan_irq;
+       int chan_num;
+};
+
+struct mxs_pcm_runtime_data {
+       int period_bytes;
+       int periods;
+       int dma;
+       unsigned long offset;
+       unsigned long size;
+       void *buf;
+       int period_time;
+       struct dma_async_tx_descriptor *desc;
+       struct dma_chan *dma_chan;
+       struct mxs_dma_data dma_data;
+       struct mxs_pcm_dma_params *dma_params;
+};
+
+#endif
diff --git a/sound/soc/mxs/mxs-saif.c b/sound/soc/mxs/mxs-saif.c
new file mode 100644 (file)
index 0000000..76dc74d
--- /dev/null
@@ -0,0 +1,798 @@
+/*
+ * Copyright 2011 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/dma-mapping.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/time.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/saif.h>
+#include <mach/dma.h>
+#include <asm/mach-types.h>
+#include <mach/hardware.h>
+#include <mach/mxs.h>
+
+#include "mxs-saif.h"
+
+static struct mxs_saif *mxs_saif[2];
+
+/*
+ * SAIF is a little different with other normal SOC DAIs on clock using.
+ *
+ * For MXS, two SAIF modules are instantiated on-chip.
+ * Each SAIF has a set of clock pins and can be operating in master
+ * mode simultaneously if they are connected to different off-chip codecs.
+ * Also, one of the two SAIFs can master or drive the clock pins while the
+ * other SAIF, in slave mode, receives clocking from the master SAIF.
+ * This also means that both SAIFs must operate at the same sample rate.
+ *
+ * We abstract this as each saif has a master, the master could be
+ * himself or other saifs. In the generic saif driver, saif does not need
+ * to know the different clkmux. Saif only needs to know who is his master
+ * and operating his master to generate the proper clock rate for him.
+ * The master id is provided in mach-specific layer according to different
+ * clkmux setting.
+ */
+
+static int mxs_saif_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
+                       int clk_id, unsigned int freq, int dir)
+{
+       struct mxs_saif *saif = snd_soc_dai_get_drvdata(cpu_dai);
+
+       switch (clk_id) {
+       case MXS_SAIF_MCLK:
+               saif->mclk = freq;
+               break;
+       default:
+               return -EINVAL;
+       }
+       return 0;
+}
+
+/*
+ * Since SAIF may work on EXTMASTER mode, IOW, it's working BITCLK&LRCLK
+ * is provided by other SAIF, we provide a interface here to get its master
+ * from its master_id.
+ * Note that the master could be himself.
+ */
+static inline struct mxs_saif *mxs_saif_get_master(struct mxs_saif * saif)
+{
+       return mxs_saif[saif->master_id];
+}
+
+/*
+ * Set SAIF clock and MCLK
+ */
+static int mxs_saif_set_clk(struct mxs_saif *saif,
+                                 unsigned int mclk,
+                                 unsigned int rate)
+{
+       u32 scr;
+       int ret;
+       struct mxs_saif *master_saif;
+
+       dev_dbg(saif->dev, "mclk %d rate %d\n", mclk, rate);
+
+       /* Set master saif to generate proper clock */
+       master_saif = mxs_saif_get_master(saif);
+       if (!master_saif)
+               return -EINVAL;
+
+       dev_dbg(saif->dev, "master saif%d\n", master_saif->id);
+
+       /* Checking if can playback and capture simutaneously */
+       if (master_saif->ongoing && rate != master_saif->cur_rate) {
+               dev_err(saif->dev,
+                       "can not change clock, master saif%d(rate %d) is ongoing\n",
+                       master_saif->id, master_saif->cur_rate);
+               return -EINVAL;
+       }
+
+       scr = __raw_readl(master_saif->base + SAIF_CTRL);
+       scr &= ~BM_SAIF_CTRL_BITCLK_MULT_RATE;
+       scr &= ~BM_SAIF_CTRL_BITCLK_BASE_RATE;
+
+       /*
+        * Set SAIF clock
+        *
+        * The SAIF clock should be either 384*fs or 512*fs.
+        * If MCLK is used, the SAIF clk ratio need to match mclk ratio.
+        *  For 32x mclk, set saif clk as 512*fs.
+        *  For 48x mclk, set saif clk as 384*fs.
+        *
+        * If MCLK is not used, we just set saif clk to 512*fs.
+        */
+       if (master_saif->mclk_in_use) {
+               if (mclk % 32 == 0) {
+                       scr &= ~BM_SAIF_CTRL_BITCLK_BASE_RATE;
+                       ret = clk_set_rate(master_saif->clk, 512 * rate);
+               } else if (mclk % 48 == 0) {
+                       scr |= BM_SAIF_CTRL_BITCLK_BASE_RATE;
+                       ret = clk_set_rate(master_saif->clk, 384 * rate);
+               } else {
+                       /* SAIF MCLK should be either 32x or 48x */
+                       return -EINVAL;
+               }
+       } else {
+               ret = clk_set_rate(master_saif->clk, 512 * rate);
+               scr &= ~BM_SAIF_CTRL_BITCLK_BASE_RATE;
+       }
+
+       if (ret)
+               return ret;
+
+       master_saif->cur_rate = rate;
+
+       if (!master_saif->mclk_in_use) {
+               __raw_writel(scr, master_saif->base + SAIF_CTRL);
+               return 0;
+       }
+
+       /*
+        * Program the over-sample rate for MCLK output
+        *
+        * The available MCLK range is 32x, 48x... 512x. The rate
+        * could be from 8kHz to 192kH.
+        */
+       switch (mclk / rate) {
+       case 32:
+               scr |= BF_SAIF_CTRL_BITCLK_MULT_RATE(4);
+               break;
+       case 64:
+               scr |= BF_SAIF_CTRL_BITCLK_MULT_RATE(3);
+               break;
+       case 128:
+               scr |= BF_SAIF_CTRL_BITCLK_MULT_RATE(2);
+               break;
+       case 256:
+               scr |= BF_SAIF_CTRL_BITCLK_MULT_RATE(1);
+               break;
+       case 512:
+               scr |= BF_SAIF_CTRL_BITCLK_MULT_RATE(0);
+               break;
+       case 48:
+               scr |= BF_SAIF_CTRL_BITCLK_MULT_RATE(3);
+               break;
+       case 96:
+               scr |= BF_SAIF_CTRL_BITCLK_MULT_RATE(2);
+               break;
+       case 192:
+               scr |= BF_SAIF_CTRL_BITCLK_MULT_RATE(1);
+               break;
+       case 384:
+               scr |= BF_SAIF_CTRL_BITCLK_MULT_RATE(0);
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       __raw_writel(scr, master_saif->base + SAIF_CTRL);
+
+       return 0;
+}
+
+/*
+ * Put and disable MCLK.
+ */
+int mxs_saif_put_mclk(unsigned int saif_id)
+{
+       struct mxs_saif *saif = mxs_saif[saif_id];
+       u32 stat;
+
+       if (!saif)
+               return -EINVAL;
+
+       stat = __raw_readl(saif->base + SAIF_STAT);
+       if (stat & BM_SAIF_STAT_BUSY) {
+               dev_err(saif->dev, "error: busy\n");
+               return -EBUSY;
+       }
+
+       clk_disable(saif->clk);
+
+       /* disable MCLK output */
+       __raw_writel(BM_SAIF_CTRL_CLKGATE,
+               saif->base + SAIF_CTRL + MXS_SET_ADDR);
+       __raw_writel(BM_SAIF_CTRL_RUN,
+               saif->base + SAIF_CTRL + MXS_CLR_ADDR);
+
+       saif->mclk_in_use = 0;
+       return 0;
+}
+
+/*
+ * Get MCLK and set clock rate, then enable it
+ *
+ * This interface is used for codecs who are using MCLK provided
+ * by saif.
+ */
+int mxs_saif_get_mclk(unsigned int saif_id, unsigned int mclk,
+                                       unsigned int rate)
+{
+       struct mxs_saif *saif = mxs_saif[saif_id];
+       u32 stat;
+       int ret;
+       struct mxs_saif *master_saif;
+
+       if (!saif)
+               return -EINVAL;
+
+       /* Clear Reset */
+       __raw_writel(BM_SAIF_CTRL_SFTRST,
+               saif->base + SAIF_CTRL + MXS_CLR_ADDR);
+
+       /* FIXME: need clear clk gate for register r/w */
+       __raw_writel(BM_SAIF_CTRL_CLKGATE,
+               saif->base + SAIF_CTRL + MXS_CLR_ADDR);
+
+       master_saif = mxs_saif_get_master(saif);
+       if (saif != master_saif) {
+               dev_err(saif->dev, "can not get mclk from a non-master saif\n");
+               return -EINVAL;
+       }
+
+       stat = __raw_readl(saif->base + SAIF_STAT);
+       if (stat & BM_SAIF_STAT_BUSY) {
+               dev_err(saif->dev, "error: busy\n");
+               return -EBUSY;
+       }
+
+       saif->mclk_in_use = 1;
+       ret = mxs_saif_set_clk(saif, mclk, rate);
+       if (ret)
+               return ret;
+
+       ret = clk_enable(saif->clk);
+       if (ret)
+               return ret;
+
+       /* enable MCLK output */
+       __raw_writel(BM_SAIF_CTRL_RUN,
+               saif->base + SAIF_CTRL + MXS_SET_ADDR);
+
+       return 0;
+}
+
+/*
+ * SAIF DAI format configuration.
+ * Should only be called when port is inactive.
+ */
+static int mxs_saif_set_dai_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt)
+{
+       u32 scr, stat;
+       u32 scr0;
+       struct mxs_saif *saif = snd_soc_dai_get_drvdata(cpu_dai);
+
+       stat = __raw_readl(saif->base + SAIF_STAT);
+       if (stat & BM_SAIF_STAT_BUSY) {
+               dev_err(cpu_dai->dev, "error: busy\n");
+               return -EBUSY;
+       }
+
+       scr0 = __raw_readl(saif->base + SAIF_CTRL);
+       scr0 = scr0 & ~BM_SAIF_CTRL_BITCLK_EDGE & ~BM_SAIF_CTRL_LRCLK_POLARITY \
+               & ~BM_SAIF_CTRL_JUSTIFY & ~BM_SAIF_CTRL_DELAY;
+       scr = 0;
+
+       /* DAI mode */
+       switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+       case SND_SOC_DAIFMT_I2S:
+               /* data frame low 1clk before data */
+               scr |= BM_SAIF_CTRL_DELAY;
+               scr &= ~BM_SAIF_CTRL_LRCLK_POLARITY;
+               break;
+       case SND_SOC_DAIFMT_LEFT_J:
+               /* data frame high with data */
+               scr &= ~BM_SAIF_CTRL_DELAY;
+               scr &= ~BM_SAIF_CTRL_LRCLK_POLARITY;
+               scr &= ~BM_SAIF_CTRL_JUSTIFY;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       /* DAI clock inversion */
+       switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
+       case SND_SOC_DAIFMT_IB_IF:
+               scr |= BM_SAIF_CTRL_BITCLK_EDGE;
+               scr |= BM_SAIF_CTRL_LRCLK_POLARITY;
+               break;
+       case SND_SOC_DAIFMT_IB_NF:
+               scr |= BM_SAIF_CTRL_BITCLK_EDGE;
+               scr &= ~BM_SAIF_CTRL_LRCLK_POLARITY;
+               break;
+       case SND_SOC_DAIFMT_NB_IF:
+               scr &= ~BM_SAIF_CTRL_BITCLK_EDGE;
+               scr |= BM_SAIF_CTRL_LRCLK_POLARITY;
+               break;
+       case SND_SOC_DAIFMT_NB_NF:
+               scr &= ~BM_SAIF_CTRL_BITCLK_EDGE;
+               scr &= ~BM_SAIF_CTRL_LRCLK_POLARITY;
+               break;
+       }
+
+       /*
+        * Note: We simply just support master mode since SAIF TX can only
+        * work as master.
+        * Here the master is relative to codec side.
+        * Saif internally could be slave when working on EXTMASTER mode.
+        * We just hide this to machine driver.
+        */
+       switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
+       case SND_SOC_DAIFMT_CBS_CFS:
+               if (saif->id == saif->master_id)
+                       scr &= ~BM_SAIF_CTRL_SLAVE_MODE;
+               else
+                       scr |= BM_SAIF_CTRL_SLAVE_MODE;
+
+               __raw_writel(scr | scr0, saif->base + SAIF_CTRL);
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int mxs_saif_startup(struct snd_pcm_substream *substream,
+                          struct snd_soc_dai *cpu_dai)
+{
+       struct mxs_saif *saif = snd_soc_dai_get_drvdata(cpu_dai);
+       snd_soc_dai_set_dma_data(cpu_dai, substream, &saif->dma_param);
+
+       /* clear error status to 0 for each re-open */
+       saif->fifo_underrun = 0;
+       saif->fifo_overrun = 0;
+
+       /* Clear Reset for normal operations */
+       __raw_writel(BM_SAIF_CTRL_SFTRST,
+               saif->base + SAIF_CTRL + MXS_CLR_ADDR);
+
+       /* clear clock gate */
+       __raw_writel(BM_SAIF_CTRL_CLKGATE,
+               saif->base + SAIF_CTRL + MXS_CLR_ADDR);
+
+       return 0;
+}
+
+/*
+ * Should only be called when port is inactive.
+ * although can be called multiple times by upper layers.
+ */
+static int mxs_saif_hw_params(struct snd_pcm_substream *substream,
+                            struct snd_pcm_hw_params *params,
+                            struct snd_soc_dai *cpu_dai)
+{
+       struct mxs_saif *saif = snd_soc_dai_get_drvdata(cpu_dai);
+       u32 scr, stat;
+       int ret;
+
+       /* mclk should already be set */
+       if (!saif->mclk && saif->mclk_in_use) {
+               dev_err(cpu_dai->dev, "set mclk first\n");
+               return -EINVAL;
+       }
+
+       stat = __raw_readl(saif->base + SAIF_STAT);
+       if (stat & BM_SAIF_STAT_BUSY) {
+               dev_err(cpu_dai->dev, "error: busy\n");
+               return -EBUSY;
+       }
+
+       /*
+        * Set saif clk based on sample rate.
+        * If mclk is used, we also set mclk, if not, saif->mclk is
+        * default 0, means not used.
+        */
+       ret = mxs_saif_set_clk(saif, saif->mclk, params_rate(params));
+       if (ret) {
+               dev_err(cpu_dai->dev, "unable to get proper clk\n");
+               return ret;
+       }
+
+       scr = __raw_readl(saif->base + SAIF_CTRL);
+
+       scr &= ~BM_SAIF_CTRL_WORD_LENGTH;
+       scr &= ~BM_SAIF_CTRL_BITCLK_48XFS_ENABLE;
+       switch (params_format(params)) {
+       case SNDRV_PCM_FORMAT_S16_LE:
+               scr |= BF_SAIF_CTRL_WORD_LENGTH(0);
+               break;
+       case SNDRV_PCM_FORMAT_S20_3LE:
+               scr |= BF_SAIF_CTRL_WORD_LENGTH(4);
+               scr |= BM_SAIF_CTRL_BITCLK_48XFS_ENABLE;
+               break;
+       case SNDRV_PCM_FORMAT_S24_LE:
+               scr |= BF_SAIF_CTRL_WORD_LENGTH(8);
+               scr |= BM_SAIF_CTRL_BITCLK_48XFS_ENABLE;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       /* Tx/Rx config */
+       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+               /* enable TX mode */
+               scr &= ~BM_SAIF_CTRL_READ_MODE;
+       } else {
+               /* enable RX mode */
+               scr |= BM_SAIF_CTRL_READ_MODE;
+       }
+
+       __raw_writel(scr, saif->base + SAIF_CTRL);
+       return 0;
+}
+
+static int mxs_saif_prepare(struct snd_pcm_substream *substream,
+                          struct snd_soc_dai *cpu_dai)
+{
+       struct mxs_saif *saif = snd_soc_dai_get_drvdata(cpu_dai);
+
+       /* enable FIFO error irqs */
+       __raw_writel(BM_SAIF_CTRL_FIFO_ERROR_IRQ_EN,
+               saif->base + SAIF_CTRL + MXS_SET_ADDR);
+
+       return 0;
+}
+
+static int mxs_saif_trigger(struct snd_pcm_substream *substream, int cmd,
+                               struct snd_soc_dai *cpu_dai)
+{
+       struct mxs_saif *saif = snd_soc_dai_get_drvdata(cpu_dai);
+       struct mxs_saif *master_saif;
+       u32 delay;
+
+       master_saif = mxs_saif_get_master(saif);
+       if (!master_saif)
+               return -EINVAL;
+
+       switch (cmd) {
+       case SNDRV_PCM_TRIGGER_START:
+       case SNDRV_PCM_TRIGGER_RESUME:
+       case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+               dev_dbg(cpu_dai->dev, "start\n");
+
+               clk_enable(master_saif->clk);
+               if (!master_saif->mclk_in_use)
+                       __raw_writel(BM_SAIF_CTRL_RUN,
+                               master_saif->base + SAIF_CTRL + MXS_SET_ADDR);
+
+               /*
+                * If the saif's master is not himself, we also need to enable
+                * itself clk for its internal basic logic to work.
+                */
+               if (saif != master_saif) {
+                       clk_enable(saif->clk);
+                       __raw_writel(BM_SAIF_CTRL_RUN,
+                               saif->base + SAIF_CTRL + MXS_SET_ADDR);
+               }
+
+               if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+                       /*
+                        * write a data to saif data register to trigger
+                        * the transfer
+                        */
+                       __raw_writel(0, saif->base + SAIF_DATA);
+               } else {
+                       /*
+                        * read a data from saif data register to trigger
+                        * the receive
+                        */
+                       __raw_readl(saif->base + SAIF_DATA);
+               }
+
+               master_saif->ongoing = 1;
+
+               dev_dbg(saif->dev, "CTRL 0x%x STAT 0x%x\n",
+                       __raw_readl(saif->base + SAIF_CTRL),
+                       __raw_readl(saif->base + SAIF_STAT));
+
+               dev_dbg(master_saif->dev, "CTRL 0x%x STAT 0x%x\n",
+                       __raw_readl(master_saif->base + SAIF_CTRL),
+                       __raw_readl(master_saif->base + SAIF_STAT));
+               break;
+       case SNDRV_PCM_TRIGGER_SUSPEND:
+       case SNDRV_PCM_TRIGGER_STOP:
+       case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+               dev_dbg(cpu_dai->dev, "stop\n");
+
+               /* wait a while for the current sample to complete */
+               delay = USEC_PER_SEC / master_saif->cur_rate;
+
+               if (!master_saif->mclk_in_use) {
+                       __raw_writel(BM_SAIF_CTRL_RUN,
+                               master_saif->base + SAIF_CTRL + MXS_CLR_ADDR);
+                       udelay(delay);
+               }
+               clk_disable(master_saif->clk);
+
+               if (saif != master_saif) {
+                       __raw_writel(BM_SAIF_CTRL_RUN,
+                               saif->base + SAIF_CTRL + MXS_CLR_ADDR);
+                       udelay(delay);
+                       clk_disable(saif->clk);
+               }
+
+               master_saif->ongoing = 0;
+
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+#define MXS_SAIF_RATES         SNDRV_PCM_RATE_8000_192000
+#define MXS_SAIF_FORMATS \
+       (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
+       SNDRV_PCM_FMTBIT_S24_LE)
+
+static struct snd_soc_dai_ops mxs_saif_dai_ops = {
+       .startup = mxs_saif_startup,
+       .trigger = mxs_saif_trigger,
+       .prepare = mxs_saif_prepare,
+       .hw_params = mxs_saif_hw_params,
+       .set_sysclk = mxs_saif_set_dai_sysclk,
+       .set_fmt = mxs_saif_set_dai_fmt,
+};
+
+static int mxs_saif_dai_probe(struct snd_soc_dai *dai)
+{
+       struct mxs_saif *saif = dev_get_drvdata(dai->dev);
+
+       snd_soc_dai_set_drvdata(dai, saif);
+
+       return 0;
+}
+
+static struct snd_soc_dai_driver mxs_saif_dai = {
+       .name = "mxs-saif",
+       .probe = mxs_saif_dai_probe,
+       .playback = {
+               .channels_min = 2,
+               .channels_max = 2,
+               .rates = MXS_SAIF_RATES,
+               .formats = MXS_SAIF_FORMATS,
+       },
+       .capture = {
+               .channels_min = 2,
+               .channels_max = 2,
+               .rates = MXS_SAIF_RATES,
+               .formats = MXS_SAIF_FORMATS,
+       },
+       .ops = &mxs_saif_dai_ops,
+};
+
+static irqreturn_t mxs_saif_irq(int irq, void *dev_id)
+{
+       struct mxs_saif *saif = dev_id;
+       unsigned int stat;
+
+       stat = __raw_readl(saif->base + SAIF_STAT);
+       if (!(stat & (BM_SAIF_STAT_FIFO_UNDERFLOW_IRQ |
+                       BM_SAIF_STAT_FIFO_OVERFLOW_IRQ)))
+               return IRQ_NONE;
+
+       if (stat & BM_SAIF_STAT_FIFO_UNDERFLOW_IRQ) {
+               dev_dbg(saif->dev, "underrun!!! %d\n", ++saif->fifo_underrun);
+               __raw_writel(BM_SAIF_STAT_FIFO_UNDERFLOW_IRQ,
+                               saif->base + SAIF_STAT + MXS_CLR_ADDR);
+       }
+
+       if (stat & BM_SAIF_STAT_FIFO_OVERFLOW_IRQ) {
+               dev_dbg(saif->dev, "overrun!!! %d\n", ++saif->fifo_overrun);
+               __raw_writel(BM_SAIF_STAT_FIFO_OVERFLOW_IRQ,
+                               saif->base + SAIF_STAT + MXS_CLR_ADDR);
+       }
+
+       dev_dbg(saif->dev, "SAIF_CTRL %x SAIF_STAT %x\n",
+              __raw_readl(saif->base + SAIF_CTRL),
+              __raw_readl(saif->base + SAIF_STAT));
+
+       return IRQ_HANDLED;
+}
+
+static int mxs_saif_probe(struct platform_device *pdev)
+{
+       struct resource *iores, *dmares;
+       struct mxs_saif *saif;
+       struct mxs_saif_platform_data *pdata;
+       int ret = 0;
+
+       if (pdev->id >= ARRAY_SIZE(mxs_saif))
+               return -EINVAL;
+
+       pdata = pdev->dev.platform_data;
+       if (pdata && pdata->init) {
+               ret = pdata->init();
+               if (ret)
+                       return ret;
+       }
+
+       saif = kzalloc(sizeof(*saif), GFP_KERNEL);
+       if (!saif)
+               return -ENOMEM;
+
+       mxs_saif[pdev->id] = saif;
+       saif->id = pdev->id;
+
+       saif->master_id = saif->id;
+       if (pdata && pdata->get_master_id) {
+               saif->master_id = pdata->get_master_id(saif->id);
+               if (saif->master_id < 0 ||
+                       saif->master_id >= ARRAY_SIZE(mxs_saif))
+                       return -EINVAL;
+       }
+
+       saif->clk = clk_get(&pdev->dev, NULL);
+       if (IS_ERR(saif->clk)) {
+               ret = PTR_ERR(saif->clk);
+               dev_err(&pdev->dev, "Cannot get the clock: %d\n",
+                       ret);
+               goto failed_clk;
+       }
+
+       iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!iores) {
+               ret = -ENODEV;
+               dev_err(&pdev->dev, "failed to get io resource: %d\n",
+                       ret);
+               goto failed_get_resource;
+       }
+
+       if (!request_mem_region(iores->start, resource_size(iores),
+                               "mxs-saif")) {
+               dev_err(&pdev->dev, "request_mem_region failed\n");
+               ret = -EBUSY;
+               goto failed_get_resource;
+       }
+
+       saif->base = ioremap(iores->start, resource_size(iores));
+       if (!saif->base) {
+               dev_err(&pdev->dev, "ioremap failed\n");
+               ret = -ENODEV;
+               goto failed_ioremap;
+       }
+
+       dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0);
+       if (!dmares) {
+               ret = -ENODEV;
+               dev_err(&pdev->dev, "failed to get dma resource: %d\n",
+                       ret);
+               goto failed_ioremap;
+       }
+       saif->dma_param.chan_num = dmares->start;
+
+       saif->irq = platform_get_irq(pdev, 0);
+       if (saif->irq < 0) {
+               ret = saif->irq;
+               dev_err(&pdev->dev, "failed to get irq resource: %d\n",
+                       ret);
+               goto failed_get_irq1;
+       }
+
+       saif->dev = &pdev->dev;
+       ret = request_irq(saif->irq, mxs_saif_irq, 0, "mxs-saif", saif);
+       if (ret) {
+               dev_err(&pdev->dev, "failed to request irq\n");
+               goto failed_get_irq1;
+       }
+
+       saif->dma_param.chan_irq = platform_get_irq(pdev, 1);
+       if (saif->dma_param.chan_irq < 0) {
+               ret = saif->dma_param.chan_irq;
+               dev_err(&pdev->dev, "failed to get dma irq resource: %d\n",
+                       ret);
+               goto failed_get_irq2;
+       }
+
+       platform_set_drvdata(pdev, saif);
+
+       ret = snd_soc_register_dai(&pdev->dev, &mxs_saif_dai);
+       if (ret) {
+               dev_err(&pdev->dev, "register DAI failed\n");
+               goto failed_register;
+       }
+
+       saif->soc_platform_pdev = platform_device_alloc(
+                                       "mxs-pcm-audio", pdev->id);
+       if (!saif->soc_platform_pdev) {
+               ret = -ENOMEM;
+               goto failed_pdev_alloc;
+       }
+
+       platform_set_drvdata(saif->soc_platform_pdev, saif);
+       ret = platform_device_add(saif->soc_platform_pdev);
+       if (ret) {
+               dev_err(&pdev->dev, "failed to add soc platform device\n");
+               goto failed_pdev_add;
+       }
+
+       return 0;
+
+failed_pdev_add:
+       platform_device_put(saif->soc_platform_pdev);
+failed_pdev_alloc:
+       snd_soc_unregister_dai(&pdev->dev);
+failed_register:
+failed_get_irq2:
+       free_irq(saif->irq, saif);
+failed_get_irq1:
+       iounmap(saif->base);
+failed_ioremap:
+       release_mem_region(iores->start, resource_size(iores));
+failed_get_resource:
+       clk_put(saif->clk);
+failed_clk:
+       kfree(saif);
+
+       return ret;
+}
+
+static int __devexit mxs_saif_remove(struct platform_device *pdev)
+{
+       struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       struct mxs_saif *saif = platform_get_drvdata(pdev);
+
+       platform_device_unregister(saif->soc_platform_pdev);
+
+       snd_soc_unregister_dai(&pdev->dev);
+
+       iounmap(saif->base);
+       release_mem_region(res->start, resource_size(res));
+       free_irq(saif->irq, saif);
+
+       clk_put(saif->clk);
+       kfree(saif);
+
+       return 0;
+}
+
+static struct platform_driver mxs_saif_driver = {
+       .probe = mxs_saif_probe,
+       .remove = __devexit_p(mxs_saif_remove),
+
+       .driver = {
+               .name = "mxs-saif",
+               .owner = THIS_MODULE,
+       },
+};
+
+static int __init mxs_saif_init(void)
+{
+       return platform_driver_register(&mxs_saif_driver);
+}
+
+static void __exit mxs_saif_exit(void)
+{
+       platform_driver_unregister(&mxs_saif_driver);
+}
+
+module_init(mxs_saif_init);
+module_exit(mxs_saif_exit);
+MODULE_AUTHOR("Freescale Semiconductor, Inc.");
+MODULE_DESCRIPTION("MXS ASoC SAIF driver");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/mxs/mxs-saif.h b/sound/soc/mxs/mxs-saif.h
new file mode 100644 (file)
index 0000000..12c91e4
--- /dev/null
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+
+#ifndef _MXS_SAIF_H
+#define _MXS_SAIF_H
+
+#define SAIF_CTRL      0x0
+#define SAIF_STAT      0x10
+#define SAIF_DATA      0x20
+#define SAIF_VERSION   0X30
+
+/* SAIF_CTRL */
+#define BM_SAIF_CTRL_SFTRST            0x80000000
+#define BM_SAIF_CTRL_CLKGATE           0x40000000
+#define BP_SAIF_CTRL_BITCLK_MULT_RATE  27
+#define BM_SAIF_CTRL_BITCLK_MULT_RATE  0x38000000
+#define BF_SAIF_CTRL_BITCLK_MULT_RATE(v) \
+               (((v) << 27) & BM_SAIF_CTRL_BITCLK_MULT_RATE)
+#define BM_SAIF_CTRL_BITCLK_BASE_RATE  0x04000000
+#define BM_SAIF_CTRL_FIFO_ERROR_IRQ_EN 0x02000000
+#define BM_SAIF_CTRL_FIFO_SERVICE_IRQ_EN       0x01000000
+#define BP_SAIF_CTRL_RSRVD2            21
+#define BM_SAIF_CTRL_RSRVD2            0x00E00000
+
+#define BP_SAIF_CTRL_DMAWAIT_COUNT     16
+#define BM_SAIF_CTRL_DMAWAIT_COUNT     0x001F0000
+#define BF_SAIF_CTRL_DMAWAIT_COUNT(v) \
+               (((v) << 16) & BM_SAIF_CTRL_DMAWAIT_COUNT)
+#define BP_SAIF_CTRL_CHANNEL_NUM_SELECT 14
+#define BM_SAIF_CTRL_CHANNEL_NUM_SELECT 0x0000C000
+#define BF_SAIF_CTRL_CHANNEL_NUM_SELECT(v) \
+               (((v) << 14) & BM_SAIF_CTRL_CHANNEL_NUM_SELECT)
+#define BM_SAIF_CTRL_LRCLK_PULSE       0x00002000
+#define BM_SAIF_CTRL_BIT_ORDER         0x00001000
+#define BM_SAIF_CTRL_DELAY             0x00000800
+#define BM_SAIF_CTRL_JUSTIFY           0x00000400
+#define BM_SAIF_CTRL_LRCLK_POLARITY    0x00000200
+#define BM_SAIF_CTRL_BITCLK_EDGE       0x00000100
+#define BP_SAIF_CTRL_WORD_LENGTH       4
+#define BM_SAIF_CTRL_WORD_LENGTH       0x000000F0
+#define BF_SAIF_CTRL_WORD_LENGTH(v) \
+               (((v) << 4) & BM_SAIF_CTRL_WORD_LENGTH)
+#define BM_SAIF_CTRL_BITCLK_48XFS_ENABLE       0x00000008
+#define BM_SAIF_CTRL_SLAVE_MODE                0x00000004
+#define BM_SAIF_CTRL_READ_MODE         0x00000002
+#define BM_SAIF_CTRL_RUN               0x00000001
+
+/* SAIF_STAT */
+#define BM_SAIF_STAT_PRESENT           0x80000000
+#define BP_SAIF_STAT_RSRVD2            17
+#define BM_SAIF_STAT_RSRVD2            0x7FFE0000
+#define BF_SAIF_STAT_RSRVD2(v) \
+               (((v) << 17) & BM_SAIF_STAT_RSRVD2)
+#define BM_SAIF_STAT_DMA_PREQ          0x00010000
+#define BP_SAIF_STAT_RSRVD1            7
+#define BM_SAIF_STAT_RSRVD1            0x0000FF80
+#define BF_SAIF_STAT_RSRVD1(v) \
+               (((v) << 7) & BM_SAIF_STAT_RSRVD1)
+
+#define BM_SAIF_STAT_FIFO_UNDERFLOW_IRQ 0x00000040
+#define BM_SAIF_STAT_FIFO_OVERFLOW_IRQ 0x00000020
+#define BM_SAIF_STAT_FIFO_SERVICE_IRQ  0x00000010
+#define BP_SAIF_STAT_RSRVD0            1
+#define BM_SAIF_STAT_RSRVD0            0x0000000E
+#define BF_SAIF_STAT_RSRVD0(v) \
+               (((v) << 1) & BM_SAIF_STAT_RSRVD0)
+#define BM_SAIF_STAT_BUSY              0x00000001
+
+/* SAFI_DATA */
+#define BP_SAIF_DATA_PCM_RIGHT         16
+#define BM_SAIF_DATA_PCM_RIGHT         0xFFFF0000
+#define BF_SAIF_DATA_PCM_RIGHT(v) \
+               (((v) << 16) & BM_SAIF_DATA_PCM_RIGHT)
+#define BP_SAIF_DATA_PCM_LEFT          0
+#define BM_SAIF_DATA_PCM_LEFT          0x0000FFFF
+#define BF_SAIF_DATA_PCM_LEFT(v)       \
+               (((v) << 0) & BM_SAIF_DATA_PCM_LEFT)
+
+/* SAIF_VERSION */
+#define BP_SAIF_VERSION_MAJOR          24
+#define BM_SAIF_VERSION_MAJOR          0xFF000000
+#define BF_SAIF_VERSION_MAJOR(v) \
+               (((v) << 24) & BM_SAIF_VERSION_MAJOR)
+#define BP_SAIF_VERSION_MINOR          16
+#define BM_SAIF_VERSION_MINOR          0x00FF0000
+#define BF_SAIF_VERSION_MINOR(v) \
+               (((v) << 16) & BM_SAIF_VERSION_MINOR)
+#define BP_SAIF_VERSION_STEP           0
+#define BM_SAIF_VERSION_STEP           0x0000FFFF
+#define BF_SAIF_VERSION_STEP(v) \
+               (((v) << 0) & BM_SAIF_VERSION_STEP)
+
+#define MXS_SAIF_MCLK          0
+
+#include "mxs-pcm.h"
+
+struct mxs_saif {
+       struct device *dev;
+       struct clk *clk;
+       unsigned int mclk;
+       unsigned int mclk_in_use;
+       void __iomem *base;
+       int irq;
+       struct mxs_pcm_dma_params dma_param;
+       unsigned int id;
+       unsigned int master_id;
+       unsigned int cur_rate;
+       unsigned int ongoing;
+
+       struct platform_device *soc_platform_pdev;
+       u32 fifo_underrun;
+       u32 fifo_overrun;
+};
+
+extern int mxs_saif_put_mclk(unsigned int saif_id);
+extern int mxs_saif_get_mclk(unsigned int saif_id, unsigned int mclk,
+                                       unsigned int rate);
+#endif
diff --git a/sound/soc/mxs/mxs-sgtl5000.c b/sound/soc/mxs/mxs-sgtl5000.c
new file mode 100644 (file)
index 0000000..7fbeaec
--- /dev/null
@@ -0,0 +1,173 @@
+/*
+ * Copyright 2011 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <linux/module.h>
+#include <linux/device.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/soc.h>
+#include <sound/jack.h>
+#include <sound/soc-dapm.h>
+#include <asm/mach-types.h>
+
+#include "../codecs/sgtl5000.h"
+#include "mxs-saif.h"
+
+static int mxs_sgtl5000_hw_params(struct snd_pcm_substream *substream,
+       struct snd_pcm_hw_params *params)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_dai *codec_dai = rtd->codec_dai;
+       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+       unsigned int rate = params_rate(params);
+       u32 dai_format, mclk;
+       int ret;
+
+       /* sgtl5000 does not support 512*rate when in 96000 fs */
+       switch (rate) {
+       case 96000:
+               mclk = 256 * rate;
+               break;
+       default:
+               mclk = 512 * rate;
+               break;
+       }
+
+       /* Sgtl5000 sysclk should be >= 8MHz and <= 27M */
+       if (mclk < 8000000 || mclk > 27000000)
+               return -EINVAL;
+
+       /* Set SGTL5000's SYSCLK (provided by SAIF MCLK) */
+       ret = snd_soc_dai_set_sysclk(codec_dai, SGTL5000_SYSCLK, mclk, 0);
+       if (ret)
+               return ret;
+
+       /* The SAIF MCLK should be the same as SGTL5000_SYSCLK */
+       ret = snd_soc_dai_set_sysclk(cpu_dai, MXS_SAIF_MCLK, mclk, 0);
+       if (ret)
+               return ret;
+
+       /* set codec to slave mode */
+       dai_format = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+                       SND_SOC_DAIFMT_CBS_CFS;
+
+       /* set codec DAI configuration */
+       ret = snd_soc_dai_set_fmt(codec_dai, dai_format);
+       if (ret)
+               return ret;
+
+       /* set cpu DAI configuration */
+       ret = snd_soc_dai_set_fmt(cpu_dai, dai_format);
+       if (ret)
+               return ret;
+
+       return 0;
+}
+
+static struct snd_soc_ops mxs_sgtl5000_hifi_ops = {
+       .hw_params = mxs_sgtl5000_hw_params,
+};
+
+static struct snd_soc_dai_link mxs_sgtl5000_dai[] = {
+       {
+               .name           = "HiFi Tx",
+               .stream_name    = "HiFi Playback",
+               .codec_dai_name = "sgtl5000",
+               .codec_name     = "sgtl5000.0-000a",
+               .cpu_dai_name   = "mxs-saif.0",
+               .platform_name  = "mxs-pcm-audio.0",
+               .ops            = &mxs_sgtl5000_hifi_ops,
+       }, {
+               .name           = "HiFi Rx",
+               .stream_name    = "HiFi Capture",
+               .codec_dai_name = "sgtl5000",
+               .codec_name     = "sgtl5000.0-000a",
+               .cpu_dai_name   = "mxs-saif.1",
+               .platform_name  = "mxs-pcm-audio.1",
+               .ops            = &mxs_sgtl5000_hifi_ops,
+       },
+};
+
+static struct snd_soc_card mxs_sgtl5000 = {
+       .name           = "mxs_sgtl5000",
+       .dai_link       = mxs_sgtl5000_dai,
+       .num_links      = ARRAY_SIZE(mxs_sgtl5000_dai),
+};
+
+static int __devinit mxs_sgtl5000_probe(struct platform_device *pdev)
+{
+       struct snd_soc_card *card = &mxs_sgtl5000;
+       int ret;
+
+       /*
+        * Set an init clock(11.28Mhz) for sgtl5000 initialization(i2c r/w).
+        * The Sgtl5000 sysclk is derived from saif0 mclk and it's range
+        * should be >= 8MHz and <= 27M.
+        */
+       ret = mxs_saif_get_mclk(0, 44100 * 256, 44100);
+       if (ret)
+               return ret;
+
+       card->dev = &pdev->dev;
+       platform_set_drvdata(pdev, card);
+
+       ret = snd_soc_register_card(card);
+       if (ret) {
+               dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
+                       ret);
+               return ret;
+       }
+
+       return 0;
+}
+
+static int __devexit mxs_sgtl5000_remove(struct platform_device *pdev)
+{
+       struct snd_soc_card *card = platform_get_drvdata(pdev);
+
+       mxs_saif_put_mclk(0);
+
+       snd_soc_unregister_card(card);
+
+       return 0;
+}
+
+static struct platform_driver mxs_sgtl5000_audio_driver = {
+       .driver = {
+               .name = "mxs-sgtl5000",
+               .owner = THIS_MODULE,
+       },
+       .probe = mxs_sgtl5000_probe,
+       .remove = __devexit_p(mxs_sgtl5000_remove),
+};
+
+static int __init mxs_sgtl5000_init(void)
+{
+       return platform_driver_register(&mxs_sgtl5000_audio_driver);
+}
+module_init(mxs_sgtl5000_init);
+
+static void __exit mxs_sgtl5000_exit(void)
+{
+       platform_driver_unregister(&mxs_sgtl5000_audio_driver);
+}
+module_exit(mxs_sgtl5000_exit);
+
+MODULE_AUTHOR("Freescale Semiconductor, Inc.");
+MODULE_DESCRIPTION("MXS ALSA SoC Machine driver");
+MODULE_LICENSE("GPL");
index d589ef14e917e95648b91daede2c53eae079e6a5..ae8d6806966ba935cbbebd3ec11c5bdaa82ad8c4 100644 (file)
@@ -227,7 +227,7 @@ static int nuc900_dma_trigger(struct snd_pcm_substream *substream, int cmd)
        return ret;
 }
 
-int nuc900_dma_getposition(struct snd_pcm_substream *substream,
+static int nuc900_dma_getposition(struct snd_pcm_substream *substream,
                                        dma_addr_t *src, dma_addr_t *dst)
 {
        struct snd_pcm_runtime *runtime = substream->runtime;
@@ -268,7 +268,7 @@ static int nuc900_dma_open(struct snd_pcm_substream *substream)
        nuc900_audio = nuc900_ac97_data;
 
        if (request_irq(nuc900_audio->irq_num, nuc900_dma_interrupt,
-                       IRQF_DISABLED, "nuc900-dma", substream))
+                       0, "nuc900-dma", substream))
                return -EBUSY;
 
        runtime->private_data = nuc900_audio;
@@ -318,7 +318,6 @@ static u64 nuc900_pcm_dmamask = DMA_BIT_MASK(32);
 static int nuc900_dma_new(struct snd_soc_pcm_runtime *rtd)
 {
        struct snd_card *card = rtd->card->snd_card;
-       struct snd_soc_dai *dai = rtd->cpu_dai;
        struct snd_pcm *pcm = rtd->pcm;
 
        if (!card->dev->dma_mask)
index 59e2c8d1e38da13e334be2db1eb0143d0a501b63..052fd758722eb0cdc2db322476546228d5e534e8 100644 (file)
@@ -1,7 +1,7 @@
 # OMAP Platform Support
 snd-soc-omap-objs := omap-pcm.o
 snd-soc-omap-mcbsp-objs := omap-mcbsp.o
-snd-soc-omap-mcpdm-objs := omap-mcpdm.o mcpdm.o
+snd-soc-omap-mcpdm-objs := omap-mcpdm.o
 snd-soc-omap-hdmi-objs := omap-hdmi.o
 
 obj-$(CONFIG_SND_OMAP_SOC) += snd-soc-omap.o
index 73dde4a1adc34b9c0af6ea8a8dc617408f2ca207..8da55e916451f499aa976c2ea2341be9d7cb52dd 100644 (file)
@@ -43,26 +43,6 @@ static int am3517evm_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
        int ret;
 
-       /* Set codec DAI configuration */
-       ret = snd_soc_dai_set_fmt(codec_dai,
-                                 SND_SOC_DAIFMT_DSP_B |
-                                 SND_SOC_DAIFMT_NB_NF |
-                                 SND_SOC_DAIFMT_CBM_CFM);
-       if (ret < 0) {
-               printk(KERN_ERR "can't set codec DAI configuration\n");
-               return ret;
-       }
-
-       /* Set cpu DAI configuration */
-       ret = snd_soc_dai_set_fmt(cpu_dai,
-                                 SND_SOC_DAIFMT_DSP_B |
-                                 SND_SOC_DAIFMT_NB_NF |
-                                 SND_SOC_DAIFMT_CBM_CFM);
-       if (ret < 0) {
-               printk(KERN_ERR "can't set cpu DAI configuration\n");
-               return ret;
-       }
-
        /* Set the codec system clock for DAC and ADC */
        ret = snd_soc_dai_set_sysclk(codec_dai, 0,
                        CODEC_CLOCK, SND_SOC_CLOCK_IN);
@@ -110,28 +90,6 @@ static const struct snd_soc_dapm_route audio_map[] = {
        {"MICIN", NULL, "Mic In"},
 };
 
-static int am3517evm_aic23_init(struct snd_soc_pcm_runtime *rtd)
-{
-       struct snd_soc_codec *codec = rtd->codec;
-       struct snd_soc_dapm_context *dapm = &codec->dapm;
-
-       /* Add am3517-evm specific widgets */
-       snd_soc_dapm_new_controls(dapm, tlv320aic23_dapm_widgets,
-                                 ARRAY_SIZE(tlv320aic23_dapm_widgets));
-
-       /* Set up davinci-evm specific audio path audio_map */
-       snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
-
-       /* always connected */
-       snd_soc_dapm_enable_pin(dapm, "Line Out");
-       snd_soc_dapm_enable_pin(dapm, "Line In");
-       snd_soc_dapm_enable_pin(dapm, "Mic In");
-
-       snd_soc_dapm_sync(dapm);
-
-       return 0;
-}
-
 /* Digital audio interface glue - connects codec <--> CPU */
 static struct snd_soc_dai_link am3517evm_dai = {
        .name = "TLV320AIC23",
@@ -140,7 +98,8 @@ static struct snd_soc_dai_link am3517evm_dai = {
        .codec_dai_name = "tlv320aic23-hifi",
        .platform_name = "omap-pcm-audio",
        .codec_name = "tlv320aic23-codec.2-001a",
-       .init = am3517evm_aic23_init,
+       .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_NB_NF |
+                  SND_SOC_DAIFMT_CBM_CFM,
        .ops = &am3517evm_ops,
 };
 
@@ -149,6 +108,11 @@ static struct snd_soc_card snd_soc_am3517evm = {
        .name = "am3517evm",
        .dai_link = &am3517evm_dai,
        .num_links = 1,
+
+       .dapm_widgets = tlv320aic23_dapm_widgets,
+       .num_dapm_widgets = ARRAY_SIZE(tlv320aic23_dapm_widgets),
+       .dapm_routes = audio_map,
+       .num_dapm_routes = ARRAY_SIZE(audio_map),
 };
 
 static struct platform_device *am3517evm_snd_device;
index 0aa475f92efaac9f01ad36d7fc2d334acdc1d0df..dcb7b689a4eae468f47eea2a794dec5a0b2906cd 100644 (file)
@@ -569,7 +569,6 @@ static int ams_delta_cx20442_init(struct snd_soc_pcm_runtime *rtd)
        snd_soc_dapm_disable_pin(dapm, "Speaker");
        snd_soc_dapm_disable_pin(dapm, "AGCIN");
        snd_soc_dapm_disable_pin(dapm, "AGCOUT");
-       snd_soc_dapm_sync(dapm);
 
        /* Add virtual switch */
        ret = snd_soc_add_controls(codec, ams_delta_audio_controls,
index 0ae34702995ba6316cbe63defd1fd73d0948034f..84615a7de6adcd98ff7d808f73439a51a67df49d 100644 (file)
@@ -38,29 +38,8 @@ static int igep2_hw_params(struct snd_pcm_substream *substream,
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_dai *codec_dai = rtd->codec_dai;
-       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
        int ret;
 
-       /* Set codec DAI configuration */
-       ret = snd_soc_dai_set_fmt(codec_dai,
-                                 SND_SOC_DAIFMT_I2S |
-                                 SND_SOC_DAIFMT_NB_NF |
-                                 SND_SOC_DAIFMT_CBM_CFM);
-       if (ret < 0) {
-               printk(KERN_ERR "can't set codec DAI configuration\n");
-               return ret;
-       }
-
-       /* Set cpu DAI configuration */
-       ret = snd_soc_dai_set_fmt(cpu_dai,
-                                 SND_SOC_DAIFMT_I2S |
-                                 SND_SOC_DAIFMT_NB_NF |
-                                 SND_SOC_DAIFMT_CBM_CFM);
-       if (ret < 0) {
-               printk(KERN_ERR "can't set cpu DAI configuration\n");
-               return ret;
-       }
-
        /* Set the codec system clock for DAC and ADC */
        ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
                                            SND_SOC_CLOCK_IN);
@@ -84,6 +63,8 @@ static struct snd_soc_dai_link igep2_dai = {
        .codec_dai_name = "twl4030-hifi",
        .platform_name = "omap-pcm-audio",
        .codec_name = "twl4030-codec",
+       .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+                  SND_SOC_DAIFMT_CBM_CFM,
        .ops = &igep2_ops,
 };
 
diff --git a/sound/soc/omap/mcpdm.c b/sound/soc/omap/mcpdm.c
deleted file mode 100644 (file)
index 50e5919..0000000
+++ /dev/null
@@ -1,470 +0,0 @@
-/*
- * mcpdm.c  -- McPDM interface driver
- *
- * Author: Jorge Eduardo Candelaria <x0107209@ti.com>
- * Copyright (C) 2009 - Texas Instruments, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#include <linux/module.h>
-#include <linux/init.h>
-#include <linux/device.h>
-#include <linux/platform_device.h>
-#include <linux/wait.h>
-#include <linux/slab.h>
-#include <linux/interrupt.h>
-#include <linux/err.h>
-#include <linux/clk.h>
-#include <linux/delay.h>
-#include <linux/io.h>
-#include <linux/irq.h>
-
-#include "mcpdm.h"
-
-static struct omap_mcpdm *mcpdm;
-
-static inline void omap_mcpdm_write(u16 reg, u32 val)
-{
-       __raw_writel(val, mcpdm->io_base + reg);
-}
-
-static inline int omap_mcpdm_read(u16 reg)
-{
-       return __raw_readl(mcpdm->io_base + reg);
-}
-
-static void omap_mcpdm_reg_dump(void)
-{
-       dev_dbg(mcpdm->dev, "***********************\n");
-       dev_dbg(mcpdm->dev, "IRQSTATUS_RAW:  0x%04x\n",
-                       omap_mcpdm_read(MCPDM_IRQSTATUS_RAW));
-       dev_dbg(mcpdm->dev, "IRQSTATUS: 0x%04x\n",
-                       omap_mcpdm_read(MCPDM_IRQSTATUS));
-       dev_dbg(mcpdm->dev, "IRQENABLE_SET:  0x%04x\n",
-                       omap_mcpdm_read(MCPDM_IRQENABLE_SET));
-       dev_dbg(mcpdm->dev, "IRQENABLE_CLR:  0x%04x\n",
-                       omap_mcpdm_read(MCPDM_IRQENABLE_CLR));
-       dev_dbg(mcpdm->dev, "IRQWAKE_EN: 0x%04x\n",
-                       omap_mcpdm_read(MCPDM_IRQWAKE_EN));
-       dev_dbg(mcpdm->dev, "DMAENABLE_SET: 0x%04x\n",
-                       omap_mcpdm_read(MCPDM_DMAENABLE_SET));
-       dev_dbg(mcpdm->dev, "DMAENABLE_CLR:  0x%04x\n",
-                       omap_mcpdm_read(MCPDM_DMAENABLE_CLR));
-       dev_dbg(mcpdm->dev, "DMAWAKEEN: 0x%04x\n",
-                       omap_mcpdm_read(MCPDM_DMAWAKEEN));
-       dev_dbg(mcpdm->dev, "CTRL:      0x%04x\n",
-                       omap_mcpdm_read(MCPDM_CTRL));
-       dev_dbg(mcpdm->dev, "DN_DATA:  0x%04x\n",
-                       omap_mcpdm_read(MCPDM_DN_DATA));
-       dev_dbg(mcpdm->dev, "UP_DATA: 0x%04x\n",
-                       omap_mcpdm_read(MCPDM_UP_DATA));
-       dev_dbg(mcpdm->dev, "FIFO_CTRL_DN: 0x%04x\n",
-                       omap_mcpdm_read(MCPDM_FIFO_CTRL_DN));
-       dev_dbg(mcpdm->dev, "FIFO_CTRL_UP:  0x%04x\n",
-                       omap_mcpdm_read(MCPDM_FIFO_CTRL_UP));
-       dev_dbg(mcpdm->dev, "DN_OFFSET: 0x%04x\n",
-                       omap_mcpdm_read(MCPDM_DN_OFFSET));
-       dev_dbg(mcpdm->dev, "***********************\n");
-}
-
-/*
- * Takes the McPDM module in and out of reset state.
- * Uplink and downlink can be reset individually.
- */
-static void omap_mcpdm_reset_capture(int reset)
-{
-       int ctrl = omap_mcpdm_read(MCPDM_CTRL);
-
-       if (reset)
-               ctrl |= SW_UP_RST;
-       else
-               ctrl &= ~SW_UP_RST;
-
-       omap_mcpdm_write(MCPDM_CTRL, ctrl);
-}
-
-static void omap_mcpdm_reset_playback(int reset)
-{
-       int ctrl = omap_mcpdm_read(MCPDM_CTRL);
-
-       if (reset)
-               ctrl |= SW_DN_RST;
-       else
-               ctrl &= ~SW_DN_RST;
-
-       omap_mcpdm_write(MCPDM_CTRL, ctrl);
-}
-
-/*
- * Enables the transfer through the PDM interface to/from the Phoenix
- * codec by enabling the corresponding UP or DN channels.
- */
-void omap_mcpdm_start(int stream)
-{
-       int ctrl = omap_mcpdm_read(MCPDM_CTRL);
-
-       if (stream)
-               ctrl |= mcpdm->up_channels;
-       else
-               ctrl |= mcpdm->dn_channels;
-
-       omap_mcpdm_write(MCPDM_CTRL, ctrl);
-}
-
-/*
- * Disables the transfer through the PDM interface to/from the Phoenix
- * codec by disabling the corresponding UP or DN channels.
- */
-void omap_mcpdm_stop(int stream)
-{
-       int ctrl = omap_mcpdm_read(MCPDM_CTRL);
-
-       if (stream)
-               ctrl &= ~mcpdm->up_channels;
-       else
-               ctrl &= ~mcpdm->dn_channels;
-
-       omap_mcpdm_write(MCPDM_CTRL, ctrl);
-}
-
-/*
- * Configures McPDM uplink for audio recording.
- * This function should be called before omap_mcpdm_start.
- */
-int omap_mcpdm_capture_open(struct omap_mcpdm_link *uplink)
-{
-       int irq_mask = 0;
-       int ctrl;
-
-       if (!uplink)
-               return -EINVAL;
-
-       mcpdm->uplink = uplink;
-
-       /* Enable irq request generation */
-       irq_mask |= uplink->irq_mask & MCPDM_UPLINK_IRQ_MASK;
-       omap_mcpdm_write(MCPDM_IRQENABLE_SET, irq_mask);
-
-       /* Configure uplink threshold */
-       if (uplink->threshold > UP_THRES_MAX)
-               uplink->threshold = UP_THRES_MAX;
-
-       omap_mcpdm_write(MCPDM_FIFO_CTRL_UP, uplink->threshold);
-
-       /* Configure DMA controller */
-       omap_mcpdm_write(MCPDM_DMAENABLE_SET, DMA_UP_ENABLE);
-
-       /* Set pdm out format */
-       ctrl = omap_mcpdm_read(MCPDM_CTRL);
-       ctrl &= ~PDMOUTFORMAT;
-       ctrl |= uplink->format & PDMOUTFORMAT;
-
-       /* Uplink channels */
-       mcpdm->up_channels = uplink->channels & (PDM_UP_MASK | PDM_STATUS_MASK);
-
-       omap_mcpdm_write(MCPDM_CTRL, ctrl);
-
-       return 0;
-}
-
-/*
- * Configures McPDM downlink for audio playback.
- * This function should be called before omap_mcpdm_start.
- */
-int omap_mcpdm_playback_open(struct omap_mcpdm_link *downlink)
-{
-       int irq_mask = 0;
-       int ctrl;
-
-       if (!downlink)
-               return -EINVAL;
-
-       mcpdm->downlink = downlink;
-
-       /* Enable irq request generation */
-       irq_mask |= downlink->irq_mask & MCPDM_DOWNLINK_IRQ_MASK;
-       omap_mcpdm_write(MCPDM_IRQENABLE_SET, irq_mask);
-
-       /* Configure uplink threshold */
-       if (downlink->threshold > DN_THRES_MAX)
-               downlink->threshold = DN_THRES_MAX;
-
-       omap_mcpdm_write(MCPDM_FIFO_CTRL_DN, downlink->threshold);
-
-       /* Enable DMA request generation */
-       omap_mcpdm_write(MCPDM_DMAENABLE_SET, DMA_DN_ENABLE);
-
-       /* Set pdm out format */
-       ctrl = omap_mcpdm_read(MCPDM_CTRL);
-       ctrl &= ~PDMOUTFORMAT;
-       ctrl |= downlink->format & PDMOUTFORMAT;
-
-       /* Downlink channels */
-       mcpdm->dn_channels = downlink->channels & (PDM_DN_MASK | PDM_CMD_MASK);
-
-       omap_mcpdm_write(MCPDM_CTRL, ctrl);
-
-       return 0;
-}
-
-/*
- * Cleans McPDM uplink configuration.
- * This function should be called when the stream is closed.
- */
-int omap_mcpdm_capture_close(struct omap_mcpdm_link *uplink)
-{
-       int irq_mask = 0;
-
-       if (!uplink)
-               return -EINVAL;
-
-       /* Disable irq request generation */
-       irq_mask |= uplink->irq_mask & MCPDM_UPLINK_IRQ_MASK;
-       omap_mcpdm_write(MCPDM_IRQENABLE_CLR, irq_mask);
-
-       /* Disable DMA request generation */
-       omap_mcpdm_write(MCPDM_DMAENABLE_CLR, DMA_UP_ENABLE);
-
-       /* Clear Downlink channels */
-       mcpdm->up_channels = 0;
-
-       mcpdm->uplink = NULL;
-
-       return 0;
-}
-
-/*
- * Cleans McPDM downlink configuration.
- * This function should be called when the stream is closed.
- */
-int omap_mcpdm_playback_close(struct omap_mcpdm_link *downlink)
-{
-       int irq_mask = 0;
-
-       if (!downlink)
-               return -EINVAL;
-
-       /* Disable irq request generation */
-       irq_mask |= downlink->irq_mask & MCPDM_DOWNLINK_IRQ_MASK;
-       omap_mcpdm_write(MCPDM_IRQENABLE_CLR, irq_mask);
-
-       /* Disable DMA request generation */
-       omap_mcpdm_write(MCPDM_DMAENABLE_CLR, DMA_DN_ENABLE);
-
-       /* clear Downlink channels */
-       mcpdm->dn_channels = 0;
-
-       mcpdm->downlink = NULL;
-
-       return 0;
-}
-
-static irqreturn_t omap_mcpdm_irq_handler(int irq, void *dev_id)
-{
-       struct omap_mcpdm *mcpdm_irq = dev_id;
-       int irq_status;
-
-       irq_status = omap_mcpdm_read(MCPDM_IRQSTATUS);
-
-       /* Acknowledge irq event */
-       omap_mcpdm_write(MCPDM_IRQSTATUS, irq_status);
-
-       if (irq & MCPDM_DN_IRQ_FULL) {
-               dev_err(mcpdm_irq->dev, "DN FIFO error %x\n", irq_status);
-               omap_mcpdm_reset_playback(1);
-               omap_mcpdm_playback_open(mcpdm_irq->downlink);
-               omap_mcpdm_reset_playback(0);
-       }
-
-       if (irq & MCPDM_DN_IRQ_EMPTY) {
-               dev_err(mcpdm_irq->dev, "DN FIFO error %x\n", irq_status);
-               omap_mcpdm_reset_playback(1);
-               omap_mcpdm_playback_open(mcpdm_irq->downlink);
-               omap_mcpdm_reset_playback(0);
-       }
-
-       if (irq & MCPDM_DN_IRQ) {
-               dev_dbg(mcpdm_irq->dev, "DN write request\n");
-       }
-
-       if (irq & MCPDM_UP_IRQ_FULL) {
-               dev_err(mcpdm_irq->dev, "UP FIFO error %x\n", irq_status);
-               omap_mcpdm_reset_capture(1);
-               omap_mcpdm_capture_open(mcpdm_irq->uplink);
-               omap_mcpdm_reset_capture(0);
-       }
-
-       if (irq & MCPDM_UP_IRQ_EMPTY) {
-               dev_err(mcpdm_irq->dev, "UP FIFO error %x\n", irq_status);
-               omap_mcpdm_reset_capture(1);
-               omap_mcpdm_capture_open(mcpdm_irq->uplink);
-               omap_mcpdm_reset_capture(0);
-       }
-
-       if (irq & MCPDM_UP_IRQ) {
-               dev_dbg(mcpdm_irq->dev, "UP write request\n");
-       }
-
-       return IRQ_HANDLED;
-}
-
-int omap_mcpdm_request(void)
-{
-       int ret;
-
-       clk_enable(mcpdm->clk);
-
-       spin_lock(&mcpdm->lock);
-
-       if (!mcpdm->free) {
-               dev_err(mcpdm->dev, "McPDM interface is in use\n");
-               spin_unlock(&mcpdm->lock);
-               ret = -EBUSY;
-               goto err;
-       }
-       mcpdm->free = 0;
-
-       spin_unlock(&mcpdm->lock);
-
-       /* Disable lines while request is ongoing */
-       omap_mcpdm_write(MCPDM_CTRL, 0x00);
-
-       ret = request_irq(mcpdm->irq, omap_mcpdm_irq_handler,
-                               0, "McPDM", (void *)mcpdm);
-       if (ret) {
-               dev_err(mcpdm->dev, "Request for McPDM IRQ failed\n");
-               goto err;
-       }
-
-       return 0;
-
-err:
-       clk_disable(mcpdm->clk);
-       return ret;
-}
-
-void omap_mcpdm_free(void)
-{
-       spin_lock(&mcpdm->lock);
-       if (mcpdm->free) {
-               dev_err(mcpdm->dev, "McPDM interface is already free\n");
-               spin_unlock(&mcpdm->lock);
-               return;
-       }
-       mcpdm->free = 1;
-       spin_unlock(&mcpdm->lock);
-
-       clk_disable(mcpdm->clk);
-
-       free_irq(mcpdm->irq, (void *)mcpdm);
-}
-
-/* Enable/disable DC offset cancelation for the analog
- * headset path (PDM channels 1 and 2).
- */
-int omap_mcpdm_set_offset(int offset1, int offset2)
-{
-       int offset;
-
-       if ((offset1 > DN_OFST_MAX) || (offset2 > DN_OFST_MAX))
-               return -EINVAL;
-
-       offset = (offset1 << DN_OFST_RX1) | (offset2 << DN_OFST_RX2);
-
-       /* offset cancellation for channel 1 */
-       if (offset1)
-               offset |= DN_OFST_RX1_EN;
-       else
-               offset &= ~DN_OFST_RX1_EN;
-
-       /* offset cancellation for channel 2 */
-       if (offset2)
-               offset |= DN_OFST_RX2_EN;
-       else
-               offset &= ~DN_OFST_RX2_EN;
-
-       omap_mcpdm_write(MCPDM_DN_OFFSET, offset);
-
-       return 0;
-}
-
-int __devinit omap_mcpdm_probe(struct platform_device *pdev)
-{
-       struct resource *res;
-       int ret = 0;
-
-       mcpdm = kzalloc(sizeof(struct omap_mcpdm), GFP_KERNEL);
-       if (!mcpdm) {
-               ret = -ENOMEM;
-               goto exit;
-       }
-
-       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       if (res == NULL) {
-               dev_err(&pdev->dev, "no resource\n");
-               goto err_resource;
-       }
-
-       spin_lock_init(&mcpdm->lock);
-       mcpdm->free = 1;
-       mcpdm->io_base = ioremap(res->start, resource_size(res));
-       if (!mcpdm->io_base) {
-               ret = -ENOMEM;
-               goto err_resource;
-       }
-
-       mcpdm->irq = platform_get_irq(pdev, 0);
-
-       mcpdm->clk = clk_get(&pdev->dev, "pdm_ck");
-       if (IS_ERR(mcpdm->clk)) {
-               ret = PTR_ERR(mcpdm->clk);
-               dev_err(&pdev->dev, "unable to get pdm_ck: %d\n", ret);
-               goto err_clk;
-       }
-
-       mcpdm->dev = &pdev->dev;
-       platform_set_drvdata(pdev, mcpdm);
-
-       return 0;
-
-err_clk:
-       iounmap(mcpdm->io_base);
-err_resource:
-       kfree(mcpdm);
-exit:
-       return ret;
-}
-
-int omap_mcpdm_remove(struct platform_device *pdev)
-{
-       struct omap_mcpdm *mcpdm_ptr = platform_get_drvdata(pdev);
-
-       platform_set_drvdata(pdev, NULL);
-
-       clk_put(mcpdm_ptr->clk);
-
-       iounmap(mcpdm_ptr->io_base);
-
-       mcpdm_ptr->clk = NULL;
-       mcpdm_ptr->free = 0;
-       mcpdm_ptr->dev = NULL;
-
-       kfree(mcpdm_ptr);
-
-       return 0;
-}
-
diff --git a/sound/soc/omap/mcpdm.h b/sound/soc/omap/mcpdm.h
deleted file mode 100644 (file)
index 20c20a8..0000000
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * mcpdm.h -- Defines for McPDM driver
- *
- * Author: Jorge Eduardo Candelaria <x0107209@ti.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-/* McPDM registers */
-
-#define MCPDM_REVISION         0x00
-#define MCPDM_SYSCONFIG                0x10
-#define MCPDM_IRQSTATUS_RAW    0x24
-#define MCPDM_IRQSTATUS                0x28
-#define MCPDM_IRQENABLE_SET    0x2C
-#define MCPDM_IRQENABLE_CLR    0x30
-#define MCPDM_IRQWAKE_EN       0x34
-#define MCPDM_DMAENABLE_SET    0x38
-#define MCPDM_DMAENABLE_CLR    0x3C
-#define MCPDM_DMAWAKEEN                0x40
-#define MCPDM_CTRL             0x44
-#define MCPDM_DN_DATA          0x48
-#define MCPDM_UP_DATA          0x4C
-#define MCPDM_FIFO_CTRL_DN     0x50
-#define MCPDM_FIFO_CTRL_UP     0x54
-#define MCPDM_DN_OFFSET                0x58
-
-/*
- * MCPDM_IRQ bit fields
- * IRQSTATUS_RAW, IRQSTATUS, IRQENABLE_SET, IRQENABLE_CLR
- */
-
-#define MCPDM_DN_IRQ                   (1 << 0)
-#define MCPDM_DN_IRQ_EMPTY             (1 << 1)
-#define MCPDM_DN_IRQ_ALMST_EMPTY       (1 << 2)
-#define MCPDM_DN_IRQ_FULL              (1 << 3)
-
-#define MCPDM_UP_IRQ                   (1 << 8)
-#define MCPDM_UP_IRQ_EMPTY             (1 << 9)
-#define MCPDM_UP_IRQ_ALMST_FULL                (1 << 10)
-#define MCPDM_UP_IRQ_FULL              (1 << 11)
-
-#define MCPDM_DOWNLINK_IRQ_MASK                0x00F
-#define MCPDM_UPLINK_IRQ_MASK          0xF00
-
-/*
- * MCPDM_DMAENABLE bit fields
- */
-
-#define DMA_DN_ENABLE          0x1
-#define DMA_UP_ENABLE          0x2
-
-/*
- * MCPDM_CTRL bit fields
- */
-
-#define PDM_UP1_EN             0x0001
-#define PDM_UP2_EN             0x0002
-#define PDM_UP3_EN             0x0004
-#define PDM_DN1_EN             0x0008
-#define PDM_DN2_EN             0x0010
-#define PDM_DN3_EN             0x0020
-#define PDM_DN4_EN             0x0040
-#define PDM_DN5_EN             0x0080
-#define PDMOUTFORMAT           0x0100
-#define CMD_INT                        0x0200
-#define STATUS_INT             0x0400
-#define SW_UP_RST              0x0800
-#define SW_DN_RST              0x1000
-#define PDM_UP_MASK            0x007
-#define PDM_DN_MASK            0x0F8
-#define PDM_CMD_MASK           0x200
-#define PDM_STATUS_MASK                0x400
-
-
-#define PDMOUTFORMAT_LJUST     (0 << 8)
-#define PDMOUTFORMAT_RJUST     (1 << 8)
-
-/*
- * MCPDM_FIFO_CTRL bit fields
- */
-
-#define UP_THRES_MAX           0xF
-#define DN_THRES_MAX           0xF
-
-/*
- * MCPDM_DN_OFFSET bit fields
- */
-
-#define DN_OFST_RX1_EN         0x0001
-#define DN_OFST_RX2_EN         0x0100
-
-#define DN_OFST_RX1            1
-#define DN_OFST_RX2            9
-#define DN_OFST_MAX            0x1F
-
-#define MCPDM_UPLINK           1
-#define MCPDM_DOWNLINK         2
-
-struct omap_mcpdm_link {
-       int irq_mask;
-       int threshold;
-       int format;
-       int channels;
-};
-
-struct omap_mcpdm_platform_data {
-       unsigned long phys_base;
-       u16 irq;
-};
-
-struct omap_mcpdm {
-       struct device *dev;
-       unsigned long phys_base;
-       void __iomem *io_base;
-       u8 free;
-       int irq;
-
-       spinlock_t lock;
-       struct omap_mcpdm_platform_data *pdata;
-       struct clk *clk;
-       struct omap_mcpdm_link *downlink;
-       struct omap_mcpdm_link *uplink;
-       struct completion irq_completion;
-
-       int dn_channels;
-       int up_channels;
-};
-
-extern void omap_mcpdm_start(int stream);
-extern void omap_mcpdm_stop(int stream);
-extern int omap_mcpdm_capture_open(struct omap_mcpdm_link *uplink);
-extern int omap_mcpdm_playback_open(struct omap_mcpdm_link *downlink);
-extern int omap_mcpdm_capture_close(struct omap_mcpdm_link *uplink);
-extern int omap_mcpdm_playback_close(struct omap_mcpdm_link *downlink);
-extern int omap_mcpdm_request(void);
-extern void omap_mcpdm_free(void);
-extern int omap_mcpdm_set_offset(int offset1, int offset2);
-int __devinit omap_mcpdm_probe(struct platform_device *pdev);
-int omap_mcpdm_remove(struct platform_device *pdev);
index 62e292f49313ce8645486949f6914b5912d9e6e5..7e3c20c965c69c529d6eecef8acf0070d861c3c6 100644 (file)
@@ -115,25 +115,8 @@ static int n810_hw_params(struct snd_pcm_substream *substream,
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_dai *codec_dai = rtd->codec_dai;
-       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
        int err;
 
-       /* Set codec DAI configuration */
-       err = snd_soc_dai_set_fmt(codec_dai,
-                                        SND_SOC_DAIFMT_I2S |
-                                        SND_SOC_DAIFMT_NB_NF |
-                                        SND_SOC_DAIFMT_CBM_CFM);
-       if (err < 0)
-               return err;
-
-       /* Set cpu DAI configuration */
-       err = snd_soc_dai_set_fmt(cpu_dai,
-                                      SND_SOC_DAIFMT_I2S |
-                                      SND_SOC_DAIFMT_NB_NF |
-                                      SND_SOC_DAIFMT_CBM_CFM);
-       if (err < 0)
-               return err;
-
        /* Set the codec system clock for DAC and ADC */
        err = snd_soc_dai_set_sysclk(codec_dai, 0, 12000000,
                                            SND_SOC_CLOCK_IN);
@@ -274,7 +257,6 @@ static int n810_aic33_init(struct snd_soc_pcm_runtime *rtd)
 {
        struct snd_soc_codec *codec = rtd->codec;
        struct snd_soc_dapm_context *dapm = &codec->dapm;
-       int err;
 
        /* Not connected */
        snd_soc_dapm_nc_pin(dapm, "MONO_LOUT");
@@ -286,21 +268,6 @@ static int n810_aic33_init(struct snd_soc_pcm_runtime *rtd)
        snd_soc_dapm_nc_pin(dapm, "LINE2L");
        snd_soc_dapm_nc_pin(dapm, "LINE2R");
 
-       /* Add N810 specific controls */
-       err = snd_soc_add_controls(codec, aic33_n810_controls,
-                               ARRAY_SIZE(aic33_n810_controls));
-       if (err < 0)
-               return err;
-
-       /* Add N810 specific widgets */
-       snd_soc_dapm_new_controls(dapm, aic33_dapm_widgets,
-                                 ARRAY_SIZE(aic33_dapm_widgets));
-
-       /* Set up N810 specific audio path audio_map */
-       snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
-
-       snd_soc_dapm_sync(dapm);
-
        return 0;
 }
 
@@ -312,6 +279,8 @@ static struct snd_soc_dai_link n810_dai = {
        .platform_name = "omap-pcm-audio",
        .codec_name = "tlv320aic3x-codec.2-0018",
        .codec_dai_name = "tlv320aic3x-hifi",
+       .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+                  SND_SOC_DAIFMT_CBM_CFM,
        .init = n810_aic33_init,
        .ops = &n810_ops,
 };
@@ -321,6 +290,13 @@ static struct snd_soc_card snd_soc_n810 = {
        .name = "N810",
        .dai_link = &n810_dai,
        .num_links = 1,
+
+       .controls = aic33_n810_controls,
+       .num_controls = ARRAY_SIZE(aic33_n810_controls),
+       .dapm_widgets = aic33_dapm_widgets,
+       .num_dapm_widgets = ARRAY_SIZE(aic33_dapm_widgets),
+       .dapm_routes = audio_map,
+       .num_dapm_routes = ARRAY_SIZE(audio_map),
 };
 
 static struct platform_device *n810_snd_device;
index 478d60778453632905dd7f8e3870dc289e9ca577..4314647e735eff71a8f038263e2f0e4a640d8d24 100644 (file)
@@ -317,6 +317,10 @@ static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream,
                return 0;
        }
 
+       regs->rcr2      &= ~(RPHASE | RFRLEN2(0x7f) | RWDLEN2(7));
+       regs->xcr2      &= ~(RPHASE | XFRLEN2(0x7f) | XWDLEN2(7));
+       regs->rcr1      &= ~(RFRLEN1(0x7f) | RWDLEN1(7));
+       regs->xcr1      &= ~(XFRLEN1(0x7f) | XWDLEN1(7));
        format = mcbsp_data->fmt & SND_SOC_DAIFMT_FORMAT_MASK;
        wpf = channels = params_channels(params);
        if (channels == 2 && (format == SND_SOC_DAIFMT_I2S ||
@@ -369,6 +373,8 @@ static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream,
                framesize = wlen * channels;
 
        /* Set FS period and length in terms of bit clock periods */
+       regs->srgr2     &= ~FPER(0xfff);
+       regs->srgr1     &= ~FWID(0xff);
        switch (format) {
        case SND_SOC_DAIFMT_I2S:
        case SND_SOC_DAIFMT_LEFT_J:
@@ -398,7 +404,7 @@ static int omap_mcbsp_dai_set_dai_fmt(struct snd_soc_dai *cpu_dai,
 {
        struct omap_mcbsp_data *mcbsp_data = snd_soc_dai_get_drvdata(cpu_dai);
        struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs;
-       unsigned int temp_fmt = fmt;
+       bool inv_fs = false;
 
        if (mcbsp_data->configured)
                return 0;
@@ -430,21 +436,21 @@ static int omap_mcbsp_dai_set_dai_fmt(struct snd_soc_dai *cpu_dai,
                regs->xcr2      |= XDATDLY(0);
                regs->spcr1     |= RJUST(2);
                /* Invert FS polarity configuration */
-               temp_fmt ^= SND_SOC_DAIFMT_NB_IF;
+               inv_fs = true;
                break;
        case SND_SOC_DAIFMT_DSP_A:
                /* 1-bit data delay */
                regs->rcr2      |= RDATDLY(1);
                regs->xcr2      |= XDATDLY(1);
                /* Invert FS polarity configuration */
-               temp_fmt ^= SND_SOC_DAIFMT_NB_IF;
+               inv_fs = true;
                break;
        case SND_SOC_DAIFMT_DSP_B:
                /* 0-bit data delay */
                regs->rcr2      |= RDATDLY(0);
                regs->xcr2      |= XDATDLY(0);
                /* Invert FS polarity configuration */
-               temp_fmt ^= SND_SOC_DAIFMT_NB_IF;
+               inv_fs = true;
                break;
        default:
                /* Unsupported data format */
@@ -468,7 +474,7 @@ static int omap_mcbsp_dai_set_dai_fmt(struct snd_soc_dai *cpu_dai,
        }
 
        /* Set bit clock (CLKX/CLKR) and FS polarities */
-       switch (temp_fmt & SND_SOC_DAIFMT_INV_MASK) {
+       switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
        case SND_SOC_DAIFMT_NB_NF:
                /*
                 * Normal BCLK + FS.
@@ -489,6 +495,8 @@ static int omap_mcbsp_dai_set_dai_fmt(struct snd_soc_dai *cpu_dai,
        default:
                return -EINVAL;
        }
+       if (inv_fs == true)
+               regs->pcr0 ^= FSXP | FSRP;
 
        return 0;
 }
@@ -503,6 +511,7 @@ static int omap_mcbsp_dai_set_clkdiv(struct snd_soc_dai *cpu_dai,
                return -ENODEV;
 
        mcbsp_data->clk_div = div;
+       regs->srgr1     &= ~CLKGDV(0xff);
        regs->srgr1     |= CLKGDV(div - 1);
 
        return 0;
@@ -516,11 +525,12 @@ static int omap_mcbsp_dai_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
        struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs;
        int err = 0;
 
-       if (mcbsp_data->active)
+       if (mcbsp_data->active) {
                if (freq == mcbsp_data->in_freq)
                        return 0;
                else
                        return -EBUSY;
+       }
 
        /* The McBSP signal muxing functions are only available on McBSP1 */
        if (clk_id == OMAP_MCBSP_CLKR_SRC_CLKR ||
@@ -531,6 +541,8 @@ static int omap_mcbsp_dai_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
                        return -EINVAL;
 
        mcbsp_data->in_freq = freq;
+       regs->srgr2     &= ~CLKSM;
+       regs->pcr0      &= ~SCLKME;
 
        switch (clk_id) {
        case OMAP_MCBSP_SYSCLK_CLK:
@@ -605,8 +617,7 @@ static int mcbsp_dai_probe(struct snd_soc_dai *dai)
        return 0;
 }
 
-static struct snd_soc_dai_driver omap_mcbsp_dai =
-{
+static struct snd_soc_dai_driver omap_mcbsp_dai = {
        .probe = mcbsp_dai_probe,
        .playback = {
                .channels_min = 1,
index bed09c27e44cb9af6643f2e015d59405885b06bd..41d17067cc739a05ac085443cdbe1fd6e984593e 100644 (file)
@@ -1,11 +1,12 @@
 /*
  * omap-mcpdm.c  --  OMAP ALSA SoC DAI driver using McPDM port
  *
- * Copyright (C) 2009 Texas Instruments
+ * Copyright (C) 2009 - 2011 Texas Instruments
  *
- * Author: Misael Lopez Cruz <x0052729@ti.com>
+ * Author: Misael Lopez Cruz <misael.lopez@ti.com>
  * Contact: Jorge Eduardo Candelaria <x0107209@ti.com>
  *          Margarita Olaya <magi.olaya@ti.com>
+ *          Peter Ujfalusi <peter.ujfalusi@ti.com>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
 
 #include <linux/init.h>
 #include <linux/module.h>
-#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/interrupt.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/irq.h>
+#include <linux/slab.h>
+#include <linux/pm_runtime.h>
+
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
-#include <sound/initval.h>
 #include <sound/soc.h>
 
 #include <plat/dma.h>
-#include <plat/mcbsp.h>
-#include "mcpdm.h"
+#include <plat/omap_hwmod.h>
+#include "omap-mcpdm.h"
 #include "omap-pcm.h"
 
-struct omap_mcpdm_data {
-       struct omap_mcpdm_link *links;
-       int active;
-};
+struct omap_mcpdm {
+       struct device *dev;
+       unsigned long phys_base;
+       void __iomem *io_base;
+       int irq;
 
-static struct omap_mcpdm_link omap_mcpdm_links[] = {
-       /* downlink */
-       {
-               .irq_mask = MCPDM_DN_IRQ_EMPTY | MCPDM_DN_IRQ_FULL,
-               .threshold = 1,
-               .format = PDMOUTFORMAT_LJUST,
-       },
-       /* uplink */
-       {
-               .irq_mask = MCPDM_UP_IRQ_EMPTY | MCPDM_UP_IRQ_FULL,
-               .threshold = 1,
-               .format = PDMOUTFORMAT_LJUST,
-       },
-};
+       struct mutex mutex;
+
+       /* channel data */
+       u32 dn_channels;
+       u32 up_channels;
+
+       /* McPDM FIFO thresholds */
+       u32 dn_threshold;
+       u32 up_threshold;
 
-static struct omap_mcpdm_data mcpdm_data = {
-       .links = omap_mcpdm_links,
-       .active = 0,
+       /* McPDM dn offsets for rx1, and 2 channels */
+       u32 dn_rx_offset;
 };
 
 /*
@@ -71,88 +73,259 @@ static struct omap_pcm_dma_data omap_mcpdm_dai_dma_params[] = {
                .dma_req = OMAP44XX_DMA_MCPDM_DL,
                .data_type = OMAP_DMA_DATA_TYPE_S32,
                .sync_mode = OMAP_DMA_SYNC_PACKET,
-               .packet_size = 16,
-               .port_addr = OMAP44XX_MCPDM_L3_BASE + MCPDM_DN_DATA,
+               .port_addr = OMAP44XX_MCPDM_L3_BASE + MCPDM_REG_DN_DATA,
        },
        {
                .name = "Audio capture",
                .dma_req = OMAP44XX_DMA_MCPDM_UP,
                .data_type = OMAP_DMA_DATA_TYPE_S32,
                .sync_mode = OMAP_DMA_SYNC_PACKET,
-               .packet_size = 16,
-               .port_addr = OMAP44XX_MCPDM_L3_BASE + MCPDM_UP_DATA,
+               .port_addr = OMAP44XX_MCPDM_L3_BASE + MCPDM_REG_UP_DATA,
        },
 };
 
-static int omap_mcpdm_dai_startup(struct snd_pcm_substream *substream,
-                                 struct snd_soc_dai *dai)
+static inline void omap_mcpdm_write(struct omap_mcpdm *mcpdm, u16 reg, u32 val)
 {
-       int err = 0;
+       __raw_writel(val, mcpdm->io_base + reg);
+}
 
-       if (!dai->active)
-               err = omap_mcpdm_request();
+static inline int omap_mcpdm_read(struct omap_mcpdm *mcpdm, u16 reg)
+{
+       return __raw_readl(mcpdm->io_base + reg);
+}
 
-       return err;
+#ifdef DEBUG
+static void omap_mcpdm_reg_dump(struct omap_mcpdm *mcpdm)
+{
+       dev_dbg(mcpdm->dev, "***********************\n");
+       dev_dbg(mcpdm->dev, "IRQSTATUS_RAW:  0x%04x\n",
+                       omap_mcpdm_read(mcpdm, MCPDM_REG_IRQSTATUS_RAW));
+       dev_dbg(mcpdm->dev, "IRQSTATUS:  0x%04x\n",
+                       omap_mcpdm_read(mcpdm, MCPDM_REG_IRQSTATUS));
+       dev_dbg(mcpdm->dev, "IRQENABLE_SET:  0x%04x\n",
+                       omap_mcpdm_read(mcpdm, MCPDM_REG_IRQENABLE_SET));
+       dev_dbg(mcpdm->dev, "IRQENABLE_CLR:  0x%04x\n",
+                       omap_mcpdm_read(mcpdm, MCPDM_REG_IRQENABLE_CLR));
+       dev_dbg(mcpdm->dev, "IRQWAKE_EN: 0x%04x\n",
+                       omap_mcpdm_read(mcpdm, MCPDM_REG_IRQWAKE_EN));
+       dev_dbg(mcpdm->dev, "DMAENABLE_SET: 0x%04x\n",
+                       omap_mcpdm_read(mcpdm, MCPDM_REG_DMAENABLE_SET));
+       dev_dbg(mcpdm->dev, "DMAENABLE_CLR:  0x%04x\n",
+                       omap_mcpdm_read(mcpdm, MCPDM_REG_DMAENABLE_CLR));
+       dev_dbg(mcpdm->dev, "DMAWAKEEN:  0x%04x\n",
+                       omap_mcpdm_read(mcpdm, MCPDM_REG_DMAWAKEEN));
+       dev_dbg(mcpdm->dev, "CTRL:  0x%04x\n",
+                       omap_mcpdm_read(mcpdm, MCPDM_REG_CTRL));
+       dev_dbg(mcpdm->dev, "DN_DATA:  0x%04x\n",
+                       omap_mcpdm_read(mcpdm, MCPDM_REG_DN_DATA));
+       dev_dbg(mcpdm->dev, "UP_DATA: 0x%04x\n",
+                       omap_mcpdm_read(mcpdm, MCPDM_REG_UP_DATA));
+       dev_dbg(mcpdm->dev, "FIFO_CTRL_DN: 0x%04x\n",
+                       omap_mcpdm_read(mcpdm, MCPDM_REG_FIFO_CTRL_DN));
+       dev_dbg(mcpdm->dev, "FIFO_CTRL_UP:  0x%04x\n",
+                       omap_mcpdm_read(mcpdm, MCPDM_REG_FIFO_CTRL_UP));
+       dev_dbg(mcpdm->dev, "***********************\n");
 }
+#else
+static void omap_mcpdm_reg_dump(struct omap_mcpdm *mcpdm) {}
+#endif
 
-static void omap_mcpdm_dai_shutdown(struct snd_pcm_substream *substream,
-                                   struct snd_soc_dai *dai)
+/*
+ * Enables the transfer through the PDM interface to/from the Phoenix
+ * codec by enabling the corresponding UP or DN channels.
+ */
+static void omap_mcpdm_start(struct omap_mcpdm *mcpdm)
+{
+       u32 ctrl = omap_mcpdm_read(mcpdm, MCPDM_REG_CTRL);
+
+       ctrl |= (MCPDM_SW_DN_RST | MCPDM_SW_UP_RST);
+       omap_mcpdm_write(mcpdm, MCPDM_REG_CTRL, ctrl);
+
+       ctrl |= mcpdm->dn_channels | mcpdm->up_channels;
+       omap_mcpdm_write(mcpdm, MCPDM_REG_CTRL, ctrl);
+
+       ctrl &= ~(MCPDM_SW_DN_RST | MCPDM_SW_UP_RST);
+       omap_mcpdm_write(mcpdm, MCPDM_REG_CTRL, ctrl);
+}
+
+/*
+ * Disables the transfer through the PDM interface to/from the Phoenix
+ * codec by disabling the corresponding UP or DN channels.
+ */
+static void omap_mcpdm_stop(struct omap_mcpdm *mcpdm)
+{
+       u32 ctrl = omap_mcpdm_read(mcpdm, MCPDM_REG_CTRL);
+
+       ctrl |= (MCPDM_SW_DN_RST | MCPDM_SW_UP_RST);
+       omap_mcpdm_write(mcpdm, MCPDM_REG_CTRL, ctrl);
+
+       ctrl &= ~(mcpdm->dn_channels | mcpdm->up_channels);
+       omap_mcpdm_write(mcpdm, MCPDM_REG_CTRL, ctrl);
+
+       ctrl &= ~(MCPDM_SW_DN_RST | MCPDM_SW_UP_RST);
+       omap_mcpdm_write(mcpdm, MCPDM_REG_CTRL, ctrl);
+
+}
+
+/*
+ * Is the physical McPDM interface active.
+ */
+static inline int omap_mcpdm_active(struct omap_mcpdm *mcpdm)
+{
+       return omap_mcpdm_read(mcpdm, MCPDM_REG_CTRL) &
+                                       (MCPDM_PDM_DN_MASK | MCPDM_PDM_UP_MASK);
+}
+
+/*
+ * Configures McPDM uplink, and downlink for audio.
+ * This function should be called before omap_mcpdm_start.
+ */
+static void omap_mcpdm_open_streams(struct omap_mcpdm *mcpdm)
+{
+       omap_mcpdm_write(mcpdm, MCPDM_REG_IRQENABLE_SET,
+                       MCPDM_DN_IRQ_EMPTY | MCPDM_DN_IRQ_FULL |
+                       MCPDM_UP_IRQ_EMPTY | MCPDM_UP_IRQ_FULL);
+
+       /* Enable DN RX1/2 offset cancellation feature, if configured */
+       if (mcpdm->dn_rx_offset) {
+               u32 dn_offset = mcpdm->dn_rx_offset;
+
+               omap_mcpdm_write(mcpdm, MCPDM_REG_DN_OFFSET, dn_offset);
+               dn_offset |= (MCPDM_DN_OFST_RX1_EN | MCPDM_DN_OFST_RX2_EN);
+               omap_mcpdm_write(mcpdm, MCPDM_REG_DN_OFFSET, dn_offset);
+       }
+
+       omap_mcpdm_write(mcpdm, MCPDM_REG_FIFO_CTRL_DN, mcpdm->dn_threshold);
+       omap_mcpdm_write(mcpdm, MCPDM_REG_FIFO_CTRL_UP, mcpdm->up_threshold);
+
+       omap_mcpdm_write(mcpdm, MCPDM_REG_DMAENABLE_SET,
+                       MCPDM_DMA_DN_ENABLE | MCPDM_DMA_UP_ENABLE);
+}
+
+/*
+ * Cleans McPDM uplink, and downlink configuration.
+ * This function should be called when the stream is closed.
+ */
+static void omap_mcpdm_close_streams(struct omap_mcpdm *mcpdm)
+{
+       /* Disable irq request generation for downlink */
+       omap_mcpdm_write(mcpdm, MCPDM_REG_IRQENABLE_CLR,
+                       MCPDM_DN_IRQ_EMPTY | MCPDM_DN_IRQ_FULL);
+
+       /* Disable DMA request generation for downlink */
+       omap_mcpdm_write(mcpdm, MCPDM_REG_DMAENABLE_CLR, MCPDM_DMA_DN_ENABLE);
+
+       /* Disable irq request generation for uplink */
+       omap_mcpdm_write(mcpdm, MCPDM_REG_IRQENABLE_CLR,
+                       MCPDM_UP_IRQ_EMPTY | MCPDM_UP_IRQ_FULL);
+
+       /* Disable DMA request generation for uplink */
+       omap_mcpdm_write(mcpdm, MCPDM_REG_DMAENABLE_CLR, MCPDM_DMA_UP_ENABLE);
+
+       /* Disable RX1/2 offset cancellation */
+       if (mcpdm->dn_rx_offset)
+               omap_mcpdm_write(mcpdm, MCPDM_REG_DN_OFFSET, 0);
+}
+
+static irqreturn_t omap_mcpdm_irq_handler(int irq, void *dev_id)
+{
+       struct omap_mcpdm *mcpdm = dev_id;
+       int irq_status;
+
+       irq_status = omap_mcpdm_read(mcpdm, MCPDM_REG_IRQSTATUS);
+
+       /* Acknowledge irq event */
+       omap_mcpdm_write(mcpdm, MCPDM_REG_IRQSTATUS, irq_status);
+
+       if (irq_status & MCPDM_DN_IRQ_FULL)
+               dev_dbg(mcpdm->dev, "DN (playback) FIFO Full\n");
+
+       if (irq_status & MCPDM_DN_IRQ_EMPTY)
+               dev_dbg(mcpdm->dev, "DN (playback) FIFO Empty\n");
+
+       if (irq_status & MCPDM_DN_IRQ)
+               dev_dbg(mcpdm->dev, "DN (playback) write request\n");
+
+       if (irq_status & MCPDM_UP_IRQ_FULL)
+               dev_dbg(mcpdm->dev, "UP (capture) FIFO Full\n");
+
+       if (irq_status & MCPDM_UP_IRQ_EMPTY)
+               dev_dbg(mcpdm->dev, "UP (capture) FIFO Empty\n");
+
+       if (irq_status & MCPDM_UP_IRQ)
+               dev_dbg(mcpdm->dev, "UP (capture) write request\n");
+
+       return IRQ_HANDLED;
+}
+
+static int omap_mcpdm_dai_startup(struct snd_pcm_substream *substream,
+                                 struct snd_soc_dai *dai)
 {
-       if (!dai->active)
-               omap_mcpdm_free();
+       struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai);
+
+       mutex_lock(&mcpdm->mutex);
+
+       if (!dai->active) {
+               pm_runtime_get_sync(mcpdm->dev);
+
+               /* Enable watch dog for ES above ES 1.0 to avoid saturation */
+               if (omap_rev() != OMAP4430_REV_ES1_0) {
+                       u32 ctrl = omap_mcpdm_read(mcpdm, MCPDM_REG_CTRL);
+
+                       omap_mcpdm_write(mcpdm, MCPDM_REG_CTRL,
+                                        ctrl | MCPDM_WD_EN);
+               }
+               omap_mcpdm_open_streams(mcpdm);
+       }
+
+       mutex_unlock(&mcpdm->mutex);
+
+       return 0;
 }
 
-static int omap_mcpdm_dai_trigger(struct snd_pcm_substream *substream, int cmd,
+static void omap_mcpdm_dai_shutdown(struct snd_pcm_substream *substream,
                                  struct snd_soc_dai *dai)
 {
-       struct omap_mcpdm_data *mcpdm_priv = snd_soc_dai_get_drvdata(dai);
-       int stream = substream->stream;
-       int err = 0;
-
-       switch (cmd) {
-       case SNDRV_PCM_TRIGGER_START:
-       case SNDRV_PCM_TRIGGER_RESUME:
-       case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
-               if (!mcpdm_priv->active++)
-                       omap_mcpdm_start(stream);
-               break;
+       struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai);
 
-       case SNDRV_PCM_TRIGGER_STOP:
-       case SNDRV_PCM_TRIGGER_SUSPEND:
-       case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
-               if (!--mcpdm_priv->active)
-                       omap_mcpdm_stop(stream);
-               break;
-       default:
-               err = -EINVAL;
+       mutex_lock(&mcpdm->mutex);
+
+       if (!dai->active) {
+               if (omap_mcpdm_active(mcpdm)) {
+                       omap_mcpdm_stop(mcpdm);
+                       omap_mcpdm_close_streams(mcpdm);
+               }
+
+               if (!omap_mcpdm_active(mcpdm))
+                       pm_runtime_put_sync(mcpdm->dev);
        }
 
-       return err;
+       mutex_unlock(&mcpdm->mutex);
 }
 
 static int omap_mcpdm_dai_hw_params(struct snd_pcm_substream *substream,
                                    struct snd_pcm_hw_params *params,
                                    struct snd_soc_dai *dai)
 {
-       struct omap_mcpdm_data *mcpdm_priv = snd_soc_dai_get_drvdata(dai);
-       struct omap_mcpdm_link *mcpdm_links = mcpdm_priv->links;
+       struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai);
        int stream = substream->stream;
-       int channels, err, link_mask = 0;
-
-       snd_soc_dai_set_dma_data(dai, substream,
-                                &omap_mcpdm_dai_dma_params[stream]);
+       struct omap_pcm_dma_data *dma_data;
+       int channels;
+       int link_mask = 0;
 
        channels = params_channels(params);
        switch (channels) {
+       case 5:
+               if (stream == SNDRV_PCM_STREAM_CAPTURE)
+                       /* up to 3 channels for capture */
+                       return -EINVAL;
+               link_mask |= 1 << 4;
        case 4:
                if (stream == SNDRV_PCM_STREAM_CAPTURE)
-                       /* up to 2 channels for capture */
+                       /* up to 3 channels for capture */
                        return -EINVAL;
                link_mask |= 1 << 3;
        case 3:
-               if (stream == SNDRV_PCM_STREAM_CAPTURE)
-                       /* up to 2 channels for capture */
-                       return -EINVAL;
                link_mask |= 1 << 2;
        case 2:
                link_mask |= 1 << 1;
@@ -164,95 +337,187 @@ static int omap_mcpdm_dai_hw_params(struct snd_pcm_substream *substream,
                return -EINVAL;
        }
 
+       dma_data = &omap_mcpdm_dai_dma_params[stream];
+
+       /* Configure McPDM channels, and DMA packet size */
        if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
-               mcpdm_links[stream].channels = link_mask << 3;
-               err = omap_mcpdm_playback_open(&mcpdm_links[stream]);
+               mcpdm->dn_channels = link_mask << 3;
+               dma_data->packet_size =
+                       (MCPDM_DN_THRES_MAX - mcpdm->dn_threshold) * channels;
        } else {
-               mcpdm_links[stream].channels = link_mask << 0;
-               err = omap_mcpdm_capture_open(&mcpdm_links[stream]);
+               mcpdm->up_channels = link_mask << 0;
+               dma_data->packet_size = mcpdm->up_threshold * channels;
        }
 
-       return err;
+       snd_soc_dai_set_dma_data(dai, substream, dma_data);
+
+       return 0;
 }
 
-static int omap_mcpdm_dai_hw_free(struct snd_pcm_substream *substream,
+static int omap_mcpdm_prepare(struct snd_pcm_substream *substream,
                                  struct snd_soc_dai *dai)
 {
-       struct omap_mcpdm_data *mcpdm_priv = snd_soc_dai_get_drvdata(dai);
-       struct omap_mcpdm_link *mcpdm_links = mcpdm_priv->links;
-       int stream = substream->stream;
-       int err;
+       struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai);
 
-       if (substream->stream ==  SNDRV_PCM_STREAM_PLAYBACK)
-               err = omap_mcpdm_playback_close(&mcpdm_links[stream]);
-       else
-               err = omap_mcpdm_capture_close(&mcpdm_links[stream]);
+       if (!omap_mcpdm_active(mcpdm)) {
+               omap_mcpdm_start(mcpdm);
+               omap_mcpdm_reg_dump(mcpdm);
+       }
 
-       return err;
+       return 0;
 }
 
 static struct snd_soc_dai_ops omap_mcpdm_dai_ops = {
        .startup        = omap_mcpdm_dai_startup,
        .shutdown       = omap_mcpdm_dai_shutdown,
-       .trigger        = omap_mcpdm_dai_trigger,
        .hw_params      = omap_mcpdm_dai_hw_params,
-       .hw_free        = omap_mcpdm_dai_hw_free,
+       .prepare        = omap_mcpdm_prepare,
 };
 
-#define OMAP_MCPDM_RATES       (SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
-#define OMAP_MCPDM_FORMATS     (SNDRV_PCM_FMTBIT_S32_LE)
+static int omap_mcpdm_probe(struct snd_soc_dai *dai)
+{
+       struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai);
+       int ret;
 
-static int omap_mcpdm_dai_probe(struct snd_soc_dai *dai)
+       pm_runtime_enable(mcpdm->dev);
+
+       /* Disable lines while request is ongoing */
+       pm_runtime_get_sync(mcpdm->dev);
+       omap_mcpdm_write(mcpdm, MCPDM_REG_CTRL, 0x00);
+
+       ret = request_irq(mcpdm->irq, omap_mcpdm_irq_handler,
+                               0, "McPDM", (void *)mcpdm);
+
+       pm_runtime_put_sync(mcpdm->dev);
+
+       if (ret) {
+               dev_err(mcpdm->dev, "Request for IRQ failed\n");
+               pm_runtime_disable(mcpdm->dev);
+       }
+
+       /* Configure McPDM threshold values */
+       mcpdm->dn_threshold = 2;
+       mcpdm->up_threshold = MCPDM_UP_THRES_MAX - 3;
+       return ret;
+}
+
+static int omap_mcpdm_remove(struct snd_soc_dai *dai)
 {
-       snd_soc_dai_set_drvdata(dai, &mcpdm_data);
+       struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai);
+
+       free_irq(mcpdm->irq, (void *)mcpdm);
+       pm_runtime_disable(mcpdm->dev);
+
        return 0;
 }
 
+#define OMAP_MCPDM_RATES       (SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
+#define OMAP_MCPDM_FORMATS     SNDRV_PCM_FMTBIT_S32_LE
+
 static struct snd_soc_dai_driver omap_mcpdm_dai = {
-       .probe = omap_mcpdm_dai_probe,
+       .probe = omap_mcpdm_probe,
+       .remove = omap_mcpdm_remove,
+       .probe_order = SND_SOC_COMP_ORDER_LATE,
+       .remove_order = SND_SOC_COMP_ORDER_EARLY,
        .playback = {
                .channels_min = 1,
-               .channels_max = 4,
+               .channels_max = 5,
                .rates = OMAP_MCPDM_RATES,
                .formats = OMAP_MCPDM_FORMATS,
        },
        .capture = {
                .channels_min = 1,
-               .channels_max = 2,
+               .channels_max = 3,
                .rates = OMAP_MCPDM_RATES,
                .formats = OMAP_MCPDM_FORMATS,
        },
        .ops = &omap_mcpdm_dai_ops,
 };
 
+void omap_mcpdm_configure_dn_offsets(struct snd_soc_pcm_runtime *rtd,
+                                   u8 rx1, u8 rx2)
+{
+       struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(rtd->cpu_dai);
+
+       mcpdm->dn_rx_offset = MCPDM_DNOFST_RX1(rx1) | MCPDM_DNOFST_RX2(rx2);
+}
+EXPORT_SYMBOL_GPL(omap_mcpdm_configure_dn_offsets);
+
 static __devinit int asoc_mcpdm_probe(struct platform_device *pdev)
 {
-       int ret;
+       struct omap_mcpdm *mcpdm;
+       struct resource *res;
+       int ret = 0;
+
+       mcpdm = kzalloc(sizeof(struct omap_mcpdm), GFP_KERNEL);
+       if (!mcpdm)
+               return -ENOMEM;
+
+       platform_set_drvdata(pdev, mcpdm);
+
+       mutex_init(&mcpdm->mutex);
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (res == NULL) {
+               dev_err(&pdev->dev, "no resource\n");
+               goto err_res;
+       }
+
+       if (!request_mem_region(res->start, resource_size(res), "McPDM")) {
+               ret = -EBUSY;
+               goto err_res;
+       }
+
+       mcpdm->io_base = ioremap(res->start, resource_size(res));
+       if (!mcpdm->io_base) {
+               ret = -ENOMEM;
+               goto err_iomap;
+       }
+
+       mcpdm->irq = platform_get_irq(pdev, 0);
+       if (mcpdm->irq < 0) {
+               ret = mcpdm->irq;
+               goto err_irq;
+       }
+
+       mcpdm->dev = &pdev->dev;
 
-       ret = omap_mcpdm_probe(pdev);
-       if (ret < 0)
-               return ret;
        ret = snd_soc_register_dai(&pdev->dev, &omap_mcpdm_dai);
-       if (ret < 0)
-               omap_mcpdm_remove(pdev);
+       if (!ret)
+               return 0;
+
+err_irq:
+       iounmap(mcpdm->io_base);
+err_iomap:
+       release_mem_region(res->start, resource_size(res));
+err_res:
+       kfree(mcpdm);
        return ret;
 }
 
 static int __devexit asoc_mcpdm_remove(struct platform_device *pdev)
 {
+       struct omap_mcpdm *mcpdm = platform_get_drvdata(pdev);
+       struct resource *res;
+
        snd_soc_unregister_dai(&pdev->dev);
-       omap_mcpdm_remove(pdev);
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       iounmap(mcpdm->io_base);
+       release_mem_region(res->start, resource_size(res));
+
+       kfree(mcpdm);
        return 0;
 }
 
 static struct platform_driver asoc_mcpdm_driver = {
        .driver = {
-                       .name = "omap-mcpdm-dai",
-                       .owner = THIS_MODULE,
+               .name   = "omap-mcpdm",
+               .owner  = THIS_MODULE,
        },
 
-       .probe = asoc_mcpdm_probe,
-       .remove = __devexit_p(asoc_mcpdm_remove),
+       .probe  = asoc_mcpdm_probe,
+       .remove = __devexit_p(asoc_mcpdm_remove),
 };
 
 static int __init snd_omap_mcpdm_init(void)
@@ -267,6 +532,6 @@ static void __exit snd_omap_mcpdm_exit(void)
 }
 module_exit(snd_omap_mcpdm_exit);
 
-MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
+MODULE_AUTHOR("Misael Lopez Cruz <misael.lopez@ti.com>");
 MODULE_DESCRIPTION("OMAP PDM SoC Interface");
 MODULE_LICENSE("GPL");
diff --git a/sound/soc/omap/omap-mcpdm.h b/sound/soc/omap/omap-mcpdm.h
new file mode 100644 (file)
index 0000000..de8cf26
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * omap-mcpdm.h
+ *
+ * Copyright (C) 2009 - 2011 Texas Instruments
+ *
+ * Contact: Misael Lopez Cruz <misael.lopez@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __OMAP_MCPDM_H__
+#define __OMAP_MCPDM_H__
+
+#define MCPDM_REG_REVISION             0x00
+#define MCPDM_REG_SYSCONFIG            0x10
+#define MCPDM_REG_IRQSTATUS_RAW                0x24
+#define MCPDM_REG_IRQSTATUS            0x28
+#define MCPDM_REG_IRQENABLE_SET                0x2C
+#define MCPDM_REG_IRQENABLE_CLR                0x30
+#define MCPDM_REG_IRQWAKE_EN           0x34
+#define MCPDM_REG_DMAENABLE_SET                0x38
+#define MCPDM_REG_DMAENABLE_CLR                0x3C
+#define MCPDM_REG_DMAWAKEEN            0x40
+#define MCPDM_REG_CTRL                 0x44
+#define MCPDM_REG_DN_DATA              0x48
+#define MCPDM_REG_UP_DATA              0x4C
+#define MCPDM_REG_FIFO_CTRL_DN         0x50
+#define MCPDM_REG_FIFO_CTRL_UP         0x54
+#define MCPDM_REG_DN_OFFSET            0x58
+
+/*
+ * MCPDM_IRQ bit fields
+ * IRQSTATUS_RAW, IRQSTATUS, IRQENABLE_SET, IRQENABLE_CLR
+ */
+
+#define MCPDM_DN_IRQ                   (1 << 0)
+#define MCPDM_DN_IRQ_EMPTY             (1 << 1)
+#define MCPDM_DN_IRQ_ALMST_EMPTY       (1 << 2)
+#define MCPDM_DN_IRQ_FULL              (1 << 3)
+
+#define MCPDM_UP_IRQ                   (1 << 8)
+#define MCPDM_UP_IRQ_EMPTY             (1 << 9)
+#define MCPDM_UP_IRQ_ALMST_FULL                (1 << 10)
+#define MCPDM_UP_IRQ_FULL              (1 << 11)
+
+#define MCPDM_DOWNLINK_IRQ_MASK                0x00F
+#define MCPDM_UPLINK_IRQ_MASK          0xF00
+
+/*
+ * MCPDM_DMAENABLE bit fields
+ */
+
+#define MCPDM_DMA_DN_ENABLE            (1 << 0)
+#define MCPDM_DMA_UP_ENABLE            (1 << 1)
+
+/*
+ * MCPDM_CTRL bit fields
+ */
+
+#define MCPDM_PDM_UPLINK_EN(x)         (1 << (x - 1)) /* ch1 is at bit 0 */
+#define MCPDM_PDM_DOWNLINK_EN(x)       (1 << (x + 2)) /* ch1 is at bit 3 */
+#define MCPDM_PDMOUTFORMAT             (1 << 8)
+#define MCPDM_CMD_INT                  (1 << 9)
+#define MCPDM_STATUS_INT               (1 << 10)
+#define MCPDM_SW_UP_RST                        (1 << 11)
+#define MCPDM_SW_DN_RST                        (1 << 12)
+#define MCPDM_WD_EN                    (1 << 14)
+#define MCPDM_PDM_UP_MASK              0x7
+#define MCPDM_PDM_DN_MASK              (0x1f << 3)
+
+
+#define MCPDM_PDMOUTFORMAT_LJUST       (0 << 8)
+#define MCPDM_PDMOUTFORMAT_RJUST       (1 << 8)
+
+/*
+ * MCPDM_FIFO_CTRL bit fields
+ */
+
+#define MCPDM_UP_THRES_MAX             0xF
+#define MCPDM_DN_THRES_MAX             0xF
+
+/*
+ * MCPDM_DN_OFFSET bit fields
+ */
+
+#define MCPDM_DN_OFST_RX1_EN           (1 << 0)
+#define MCPDM_DNOFST_RX1(x)            ((x & 0x1f) << 1)
+#define MCPDM_DN_OFST_RX2_EN           (1 << 8)
+#define MCPDM_DNOFST_RX2(x)            ((x & 0x1f) << 9)
+
+void omap_mcpdm_configure_dn_offsets(struct snd_soc_pcm_runtime *rtd,
+                                   u8 rx1, u8 rx2);
+
+#endif /* End of __OMAP_MCPDM_H__ */
index 9b5c88ac35b985e7b373add9aa4ff6250f3203c1..5e37ec915de2a30e808583443a328a4220041fd3 100644 (file)
@@ -198,6 +198,14 @@ static int omap_pcm_prepare(struct snd_pcm_substream *substream)
                              OMAP_DMA_LAST_IRQ | OMAP_DMA_BLOCK_IRQ);
        else if (!substream->runtime->no_period_wakeup)
                omap_enable_dma_irq(prtd->dma_ch, OMAP_DMA_FRAME_IRQ);
+       else {
+               /*
+                * No period wakeup:
+                * we need to disable BLOCK_IRQ, which is enabled by the omap
+                * dma core at request dma time.
+                */
+               omap_disable_dma_irq(prtd->dma_ch, OMAP_DMA_BLOCK_IRQ);
+       }
 
        if (!(cpu_class_is_omap1())) {
                omap_set_dma_src_burst_mode(prtd->dma_ch,
index 0daa044698360fc0a125fc2776bccebc6288bf13..bf9ae2a6f90199bc1a8c02e245e98a7da7122097 100644 (file)
@@ -36,29 +36,8 @@ static int omap3evm_hw_params(struct snd_pcm_substream *substream,
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_dai *codec_dai = rtd->codec_dai;
-       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
        int ret;
 
-       /* Set codec DAI configuration */
-       ret = snd_soc_dai_set_fmt(codec_dai,
-                                 SND_SOC_DAIFMT_I2S |
-                                 SND_SOC_DAIFMT_NB_NF |
-                                 SND_SOC_DAIFMT_CBM_CFM);
-       if (ret < 0) {
-               printk(KERN_ERR "Can't set codec DAI configuration\n");
-               return ret;
-       }
-
-       /* Set cpu DAI configuration */
-       ret = snd_soc_dai_set_fmt(cpu_dai,
-                                 SND_SOC_DAIFMT_I2S |
-                                 SND_SOC_DAIFMT_NB_NF |
-                                 SND_SOC_DAIFMT_CBM_CFM);
-       if (ret < 0) {
-               printk(KERN_ERR "Can't set cpu DAI configuration\n");
-               return ret;
-       }
-
        /* Set the codec system clock for DAC and ADC */
        ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
                                     SND_SOC_CLOCK_IN);
@@ -82,6 +61,8 @@ static struct snd_soc_dai_link omap3evm_dai = {
        .codec_dai_name = "twl4030-hifi",
        .platform_name = "omap-pcm-audio",
        .codec_name = "twl4030-codec",
+       .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+                  SND_SOC_DAIFMT_CBM_CFM,
        .ops            = &omap3evm_ops,
 };
 
index 8047c521e318d648405b4fcce75e1f0cca4ee54f..30a75b406aea653dd2666deaad373de2d5204d79 100644 (file)
@@ -48,24 +48,8 @@ static int omap3pandora_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_dai *codec_dai = rtd->codec_dai;
        struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-       int fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
-                 SND_SOC_DAIFMT_CBS_CFS;
        int ret;
 
-       /* Set codec DAI configuration */
-       ret = snd_soc_dai_set_fmt(codec_dai, fmt);
-       if (ret < 0) {
-               pr_err(PREFIX "can't set codec DAI configuration\n");
-               return ret;
-       }
-
-       /* Set cpu DAI configuration */
-       ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
-       if (ret < 0) {
-               pr_err(PREFIX "can't set cpu DAI configuration\n");
-               return ret;
-       }
-
        /* Set the codec system clock for DAC and ADC */
        ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
                                            SND_SOC_CLOCK_IN);
@@ -189,10 +173,8 @@ static int omap3pandora_out_init(struct snd_soc_pcm_runtime *rtd)
        if (ret < 0)
                return ret;
 
-       snd_soc_dapm_add_routes(dapm, omap3pandora_out_map,
+       return snd_soc_dapm_add_routes(dapm, omap3pandora_out_map,
                ARRAY_SIZE(omap3pandora_out_map));
-
-       return snd_soc_dapm_sync(dapm);
 }
 
 static int omap3pandora_in_init(struct snd_soc_pcm_runtime *rtd)
@@ -212,10 +194,8 @@ static int omap3pandora_in_init(struct snd_soc_pcm_runtime *rtd)
        if (ret < 0)
                return ret;
 
-       snd_soc_dapm_add_routes(dapm, omap3pandora_in_map,
+       return snd_soc_dapm_add_routes(dapm, omap3pandora_in_map,
                ARRAY_SIZE(omap3pandora_in_map));
-
-       return snd_soc_dapm_sync(dapm);
 }
 
 static struct snd_soc_ops omap3pandora_ops = {
@@ -231,6 +211,8 @@ static struct snd_soc_dai_link omap3pandora_dai[] = {
                .codec_dai_name = "twl4030-hifi",
                .platform_name = "omap-pcm-audio",
                .codec_name = "twl4030-codec",
+               .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+                          SND_SOC_DAIFMT_CBS_CFS,
                .ops = &omap3pandora_ops,
                .init = omap3pandora_out_init,
        }, {
@@ -240,6 +222,8 @@ static struct snd_soc_dai_link omap3pandora_dai[] = {
                .codec_dai_name = "twl4030-hifi",
                .platform_name = "omap-pcm-audio",
                .codec_name = "twl4030-codec",
+               .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+                          SND_SOC_DAIFMT_CBS_CFS,
                .ops = &omap3pandora_ops,
                .init = omap3pandora_in_init,
        }
index 7e75e775fb4a8943eea07911aa289ac98390b7d4..db91ccaf6c97ec1bde9fd1aa8d286aead101925f 100644 (file)
@@ -55,29 +55,8 @@ static int osk_hw_params(struct snd_pcm_substream *substream,
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_dai *codec_dai = rtd->codec_dai;
-       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
        int err;
 
-       /* Set codec DAI configuration */
-       err = snd_soc_dai_set_fmt(codec_dai,
-                                 SND_SOC_DAIFMT_DSP_B |
-                                 SND_SOC_DAIFMT_NB_NF |
-                                 SND_SOC_DAIFMT_CBM_CFM);
-       if (err < 0) {
-               printk(KERN_ERR "can't set codec DAI configuration\n");
-               return err;
-       }
-
-       /* Set cpu DAI configuration */
-       err = snd_soc_dai_set_fmt(cpu_dai,
-                                 SND_SOC_DAIFMT_DSP_B |
-                                 SND_SOC_DAIFMT_NB_NF |
-                                 SND_SOC_DAIFMT_CBM_CFM);
-       if (err < 0) {
-               printk(KERN_ERR "can't set cpu DAI configuration\n");
-               return err;
-       }
-
        /* Set the codec system clock for DAC and ADC */
        err =
            snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK, SND_SOC_CLOCK_IN);
@@ -112,27 +91,6 @@ static const struct snd_soc_dapm_route audio_map[] = {
        {"MICIN", NULL, "Mic Jack"},
 };
 
-static int osk_tlv320aic23_init(struct snd_soc_pcm_runtime *rtd)
-{
-       struct snd_soc_codec *codec = rtd->codec;
-       struct snd_soc_dapm_context *dapm = &codec->dapm;
-
-       /* Add osk5912 specific widgets */
-       snd_soc_dapm_new_controls(dapm, tlv320aic23_dapm_widgets,
-                                 ARRAY_SIZE(tlv320aic23_dapm_widgets));
-
-       /* Set up osk5912 specific audio path audio_map */
-       snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
-
-       snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
-       snd_soc_dapm_enable_pin(dapm, "Line In");
-       snd_soc_dapm_enable_pin(dapm, "Mic Jack");
-
-       snd_soc_dapm_sync(dapm);
-
-       return 0;
-}
-
 /* Digital audio interface glue - connects codec <--> CPU */
 static struct snd_soc_dai_link osk_dai = {
        .name = "TLV320AIC23",
@@ -141,7 +99,8 @@ static struct snd_soc_dai_link osk_dai = {
        .codec_dai_name = "tlv320aic23-hifi",
        .platform_name = "omap-pcm-audio",
        .codec_name = "tlv320aic23-codec",
-       .init = osk_tlv320aic23_init,
+       .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_NB_NF |
+                  SND_SOC_DAIFMT_CBM_CFM,
        .ops = &osk_ops,
 };
 
@@ -150,6 +109,11 @@ static struct snd_soc_card snd_soc_card_osk = {
        .name = "OSK5912",
        .dai_link = &osk_dai,
        .num_links = 1,
+
+       .dapm_widgets = tlv320aic23_dapm_widgets,
+       .num_dapm_widgets = ARRAY_SIZE(tlv320aic23_dapm_widgets),
+       .dapm_routes = audio_map,
+       .num_dapm_routes = ARRAY_SIZE(audio_map),
 };
 
 static struct platform_device *osk_snd_device;
index bbcf380bfb56309ce0e193e2312fe47eea8f9366..739efe9e327ad31ea194963caea116dd8b5a450e 100644 (file)
@@ -38,29 +38,8 @@ static int overo_hw_params(struct snd_pcm_substream *substream,
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_dai *codec_dai = rtd->codec_dai;
-       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
        int ret;
 
-       /* Set codec DAI configuration */
-       ret = snd_soc_dai_set_fmt(codec_dai,
-                                 SND_SOC_DAIFMT_I2S |
-                                 SND_SOC_DAIFMT_NB_NF |
-                                 SND_SOC_DAIFMT_CBM_CFM);
-       if (ret < 0) {
-               printk(KERN_ERR "can't set codec DAI configuration\n");
-               return ret;
-       }
-
-       /* Set cpu DAI configuration */
-       ret = snd_soc_dai_set_fmt(cpu_dai,
-                                 SND_SOC_DAIFMT_I2S |
-                                 SND_SOC_DAIFMT_NB_NF |
-                                 SND_SOC_DAIFMT_CBM_CFM);
-       if (ret < 0) {
-               printk(KERN_ERR "can't set cpu DAI configuration\n");
-               return ret;
-       }
-
        /* Set the codec system clock for DAC and ADC */
        ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
                                            SND_SOC_CLOCK_IN);
@@ -84,6 +63,8 @@ static struct snd_soc_dai_link overo_dai = {
        .codec_dai_name = "twl4030-hifi",
        .platform_name = "omap-pcm-audio",
        .codec_name = "twl4030-codec",
+       .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+                  SND_SOC_DAIFMT_CBM_CFM,
        .ops = &overo_ops,
 };
 
index 893300a53bab5cc78ccd91aa331c4b114c91d090..a56842380c724f619e755885c9a7c63a831394ca 100644 (file)
@@ -115,24 +115,6 @@ static int rx51_hw_params(struct snd_pcm_substream *substream,
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_dai *codec_dai = rtd->codec_dai;
-       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-       int err;
-
-       /* Set codec DAI configuration */
-       err = snd_soc_dai_set_fmt(codec_dai,
-                                 SND_SOC_DAIFMT_DSP_A |
-                                 SND_SOC_DAIFMT_IB_NF |
-                                 SND_SOC_DAIFMT_CBM_CFM);
-       if (err < 0)
-               return err;
-
-       /* Set cpu DAI configuration */
-       err = snd_soc_dai_set_fmt(cpu_dai,
-                                 SND_SOC_DAIFMT_DSP_A |
-                                 SND_SOC_DAIFMT_IB_NF |
-                                 SND_SOC_DAIFMT_CBM_CFM);
-       if (err < 0)
-               return err;
 
        /* Set the codec system clock for DAC and ADC */
        return snd_soc_dai_set_sysclk(codec_dai, 0, 19200000,
@@ -335,8 +317,6 @@ static int rx51_aic34_init(struct snd_soc_pcm_runtime *rtd)
        if (err < 0)
                return err;
 
-       snd_soc_dapm_sync(dapm);
-
        /* AV jack detection */
        err = snd_soc_jack_new(codec, "AV Jack",
                               SND_JACK_HEADSET | SND_JACK_VIDEOOUT,
@@ -377,6 +357,8 @@ static struct snd_soc_dai_link rx51_dai[] = {
                .codec_dai_name = "tlv320aic3x-hifi",
                .platform_name = "omap-pcm-audio",
                .codec_name = "tlv320aic3x-codec.2-0018",
+               .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF |
+                          SND_SOC_DAIFMT_CBM_CFM,
                .init = rx51_aic34_init,
                .ops = &rx51_ops,
        },
index 9f6a758029d16a63cbcd9b8930f64e2c9baceaef..4f1969de91a70aa80ea87f7d918d53f574ac2ecf 100644 (file)
@@ -53,29 +53,8 @@ static int sdp3430_hw_params(struct snd_pcm_substream *substream,
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_dai *codec_dai = rtd->codec_dai;
-       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
        int ret;
 
-       /* Set codec DAI configuration */
-       ret = snd_soc_dai_set_fmt(codec_dai,
-                                 SND_SOC_DAIFMT_I2S |
-                                 SND_SOC_DAIFMT_NB_NF |
-                                 SND_SOC_DAIFMT_CBM_CFM);
-       if (ret < 0) {
-               printk(KERN_ERR "can't set codec DAI configuration\n");
-               return ret;
-       }
-
-       /* Set cpu DAI configuration */
-       ret = snd_soc_dai_set_fmt(cpu_dai,
-                                 SND_SOC_DAIFMT_I2S |
-                                 SND_SOC_DAIFMT_NB_NF |
-                                 SND_SOC_DAIFMT_CBM_CFM);
-       if (ret < 0) {
-               printk(KERN_ERR "can't set cpu DAI configuration\n");
-               return ret;
-       }
-
        /* Set the codec system clock for DAC and ADC */
        ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
                                            SND_SOC_CLOCK_IN);
@@ -91,49 +70,6 @@ static struct snd_soc_ops sdp3430_ops = {
        .hw_params = sdp3430_hw_params,
 };
 
-static int sdp3430_hw_voice_params(struct snd_pcm_substream *substream,
-       struct snd_pcm_hw_params *params)
-{
-       struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_dai *codec_dai = rtd->codec_dai;
-       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-       int ret;
-
-       /* Set codec DAI configuration */
-       ret = snd_soc_dai_set_fmt(codec_dai,
-                               SND_SOC_DAIFMT_DSP_A |
-                               SND_SOC_DAIFMT_IB_NF |
-                               SND_SOC_DAIFMT_CBM_CFM);
-       if (ret) {
-               printk(KERN_ERR "can't set codec DAI configuration\n");
-               return ret;
-       }
-
-       /* Set cpu DAI configuration */
-       ret = snd_soc_dai_set_fmt(cpu_dai,
-                               SND_SOC_DAIFMT_DSP_A |
-                               SND_SOC_DAIFMT_IB_NF |
-                               SND_SOC_DAIFMT_CBM_CFM);
-       if (ret < 0) {
-               printk(KERN_ERR "can't set cpu DAI configuration\n");
-               return ret;
-       }
-
-       /* Set the codec system clock for DAC and ADC */
-       ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
-                                           SND_SOC_CLOCK_IN);
-       if (ret < 0) {
-               printk(KERN_ERR "can't set codec system clock\n");
-               return ret;
-       }
-
-       return 0;
-}
-
-static struct snd_soc_ops sdp3430_voice_ops = {
-       .hw_params = sdp3430_hw_voice_params,
-};
-
 /* Headset jack */
 static struct snd_soc_jack hs_jack;
 
@@ -193,15 +129,6 @@ static int sdp3430_twl4030_init(struct snd_soc_pcm_runtime *rtd)
        struct snd_soc_dapm_context *dapm = &codec->dapm;
        int ret;
 
-       /* Add SDP3430 specific widgets */
-       ret = snd_soc_dapm_new_controls(dapm, sdp3430_twl4030_dapm_widgets,
-                               ARRAY_SIZE(sdp3430_twl4030_dapm_widgets));
-       if (ret)
-               return ret;
-
-       /* Set up SDP3430 specific audio path audio_map */
-       snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
-
        /* SDP3430 connected pins */
        snd_soc_dapm_enable_pin(dapm, "Ext Mic");
        snd_soc_dapm_enable_pin(dapm, "Ext Spk");
@@ -223,10 +150,6 @@ static int sdp3430_twl4030_init(struct snd_soc_pcm_runtime *rtd)
        snd_soc_dapm_nc_pin(dapm, "CARKITL");
        snd_soc_dapm_nc_pin(dapm, "CARKITR");
 
-       ret = snd_soc_dapm_sync(dapm);
-       if (ret)
-               return ret;
-
        /* Headset jack detection */
        ret = snd_soc_jack_new(codec, "Headset Jack",
                                SND_JACK_HEADSET, &hs_jack);
@@ -267,6 +190,8 @@ static struct snd_soc_dai_link sdp3430_dai[] = {
                .codec_dai_name = "twl4030-hifi",
                .platform_name = "omap-pcm-audio",
                .codec_name = "twl4030-codec",
+               .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+                          SND_SOC_DAIFMT_CBM_CFM,
                .init = sdp3430_twl4030_init,
                .ops = &sdp3430_ops,
        },
@@ -277,8 +202,10 @@ static struct snd_soc_dai_link sdp3430_dai[] = {
                .codec_dai_name = "twl4030-voice",
                .platform_name = "omap-pcm-audio",
                .codec_name = "twl4030-codec",
+               .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF |
+                          SND_SOC_DAIFMT_CBM_CFM,
                .init = sdp3430_twl4030_voice_init,
-               .ops = &sdp3430_voice_ops,
+               .ops = &sdp3430_ops,
        },
 };
 
@@ -287,6 +214,11 @@ static struct snd_soc_card snd_soc_sdp3430 = {
        .name = "SDP3430",
        .dai_link = sdp3430_dai,
        .num_links = ARRAY_SIZE(sdp3430_dai),
+
+       .dapm_widgets = sdp3430_twl4030_dapm_widgets,
+       .num_dapm_widgets = ARRAY_SIZE(sdp3430_twl4030_dapm_widgets),
+       .dapm_routes = audio_map,
+       .num_dapm_routes = ARRAY_SIZE(audio_map),
 };
 
 static struct platform_device *sdp3430_snd_device;
index b80efb02bfcae81ea365fce6c9f0be93a63dde28..cc3d792af5ead2d0761210eacba97811eb3135b4 100644 (file)
@@ -32,7 +32,7 @@
 #include <plat/hardware.h>
 #include <plat/mux.h>
 
-#include "mcpdm.h"
+#include "omap-mcpdm.h"
 #include "omap-pcm.h"
 #include "../codecs/twl6040.h"
 
@@ -88,7 +88,7 @@ static const struct snd_soc_dapm_widget sdp4430_twl6040_dapm_widgets[] = {
        SND_SOC_DAPM_MIC("Headset Mic", NULL),
        SND_SOC_DAPM_HP("Headset Stereophone", NULL),
        SND_SOC_DAPM_SPK("Earphone Spk", NULL),
-       SND_SOC_DAPM_INPUT("Aux/FM Stereo In"),
+       SND_SOC_DAPM_INPUT("FM Stereo In"),
 };
 
 static const struct snd_soc_dapm_route audio_map[] = {
@@ -113,36 +113,22 @@ static const struct snd_soc_dapm_route audio_map[] = {
        {"Earphone Spk", NULL, "EP"},
 
        /* Aux/FM Stereo In: AFML, AFMR */
-       {"AFML", NULL, "Aux/FM Stereo In"},
-       {"AFMR", NULL, "Aux/FM Stereo In"},
+       {"AFML", NULL, "FM Stereo In"},
+       {"AFMR", NULL, "FM Stereo In"},
 };
 
 static int sdp4430_twl6040_init(struct snd_soc_pcm_runtime *rtd)
 {
        struct snd_soc_codec *codec = rtd->codec;
-       struct snd_soc_dapm_context *dapm = &codec->dapm;
-       int ret;
-
-       /* Add SDP4430 specific widgets */
-       ret = snd_soc_dapm_new_controls(dapm, sdp4430_twl6040_dapm_widgets,
-                               ARRAY_SIZE(sdp4430_twl6040_dapm_widgets));
-       if (ret)
-               return ret;
-
-       /* Set up SDP4430 specific audio path audio_map */
-       snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
+       int ret, hs_trim;
 
-       /* SDP4430 connected pins */
-       snd_soc_dapm_enable_pin(dapm, "Ext Mic");
-       snd_soc_dapm_enable_pin(dapm, "Ext Spk");
-       snd_soc_dapm_enable_pin(dapm, "AFML");
-       snd_soc_dapm_enable_pin(dapm, "AFMR");
-       snd_soc_dapm_enable_pin(dapm, "Headset Mic");
-       snd_soc_dapm_enable_pin(dapm, "Headset Stereophone");
-
-       ret = snd_soc_dapm_sync(dapm);
-       if (ret)
-               return ret;
+       /*
+        * Configure McPDM offset cancellation based on the HSOTRIM value from
+        * twl6040.
+        */
+       hs_trim = twl6040_get_trim_value(codec, TWL6040_TRIM_HSOTRIM);
+       omap_mcpdm_configure_dn_offsets(rtd, TWL6040_HSF_TRIM_LEFT(hs_trim),
+                                       TWL6040_HSF_TRIM_RIGHT(hs_trim));
 
        /* Headset jack detection */
        ret = snd_soc_jack_new(codec, "Headset Jack",
@@ -165,8 +151,8 @@ static int sdp4430_twl6040_init(struct snd_soc_pcm_runtime *rtd)
 static struct snd_soc_dai_link sdp4430_dai = {
        .name = "TWL6040",
        .stream_name = "TWL6040",
-       .cpu_dai_name ="omap-mcpdm-dai",
-       .codec_dai_name = "twl6040-hifi",
+       .cpu_dai_name = "omap-mcpdm",
+       .codec_dai_name = "twl6040-legacy",
        .platform_name = "omap-pcm-audio",
        .codec_name = "twl6040-codec",
        .init = sdp4430_twl6040_init,
@@ -178,6 +164,11 @@ static struct snd_soc_card snd_soc_sdp4430 = {
        .name = "SDP4430",
        .dai_link = &sdp4430_dai,
        .num_links = 1,
+
+       .dapm_widgets = sdp4430_twl6040_dapm_widgets,
+       .num_dapm_widgets = ARRAY_SIZE(sdp4430_twl6040_dapm_widgets),
+       .dapm_routes = audio_map,
+       .num_dapm_routes = ARRAY_SIZE(audio_map),
 };
 
 static struct platform_device *sdp4430_snd_device;
index 9a2666ffc16c9b71b40ddf54cfc3464d217a1f62..7cf35c82368ad6548ba1104afd5aca4afe5cb2b0 100644 (file)
@@ -44,29 +44,8 @@ static int zoom2_hw_params(struct snd_pcm_substream *substream,
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_dai *codec_dai = rtd->codec_dai;
-       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
        int ret;
 
-       /* Set codec DAI configuration */
-       ret = snd_soc_dai_set_fmt(codec_dai,
-                                 SND_SOC_DAIFMT_I2S |
-                                 SND_SOC_DAIFMT_NB_NF |
-                                 SND_SOC_DAIFMT_CBM_CFM);
-       if (ret < 0) {
-               printk(KERN_ERR "can't set codec DAI configuration\n");
-               return ret;
-       }
-
-       /* Set cpu DAI configuration */
-       ret = snd_soc_dai_set_fmt(cpu_dai,
-                                 SND_SOC_DAIFMT_I2S |
-                                 SND_SOC_DAIFMT_NB_NF |
-                                 SND_SOC_DAIFMT_CBM_CFM);
-       if (ret < 0) {
-               printk(KERN_ERR "can't set cpu DAI configuration\n");
-               return ret;
-       }
-
        /* Set the codec system clock for DAC and ADC */
        ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
                                        SND_SOC_CLOCK_IN);
@@ -82,49 +61,6 @@ static struct snd_soc_ops zoom2_ops = {
        .hw_params = zoom2_hw_params,
 };
 
-static int zoom2_hw_voice_params(struct snd_pcm_substream *substream,
-                               struct snd_pcm_hw_params *params)
-{
-       struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_dai *codec_dai = rtd->codec_dai;
-       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-       int ret;
-
-       /* Set codec DAI configuration */
-       ret = snd_soc_dai_set_fmt(codec_dai,
-                               SND_SOC_DAIFMT_DSP_A |
-                               SND_SOC_DAIFMT_IB_NF |
-                               SND_SOC_DAIFMT_CBM_CFM);
-       if (ret) {
-               printk(KERN_ERR "can't set codec DAI configuration\n");
-               return ret;
-       }
-
-       /* Set cpu DAI configuration */
-       ret = snd_soc_dai_set_fmt(cpu_dai,
-                               SND_SOC_DAIFMT_DSP_A |
-                               SND_SOC_DAIFMT_IB_NF |
-                               SND_SOC_DAIFMT_CBM_CFM);
-       if (ret < 0) {
-               printk(KERN_ERR "can't set cpu DAI configuration\n");
-               return ret;
-       }
-
-       /* Set the codec system clock for DAC and ADC */
-       ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
-                                       SND_SOC_CLOCK_IN);
-       if (ret < 0) {
-               printk(KERN_ERR "can't set codec system clock\n");
-               return ret;
-       }
-
-       return 0;
-}
-
-static struct snd_soc_ops zoom2_voice_ops = {
-       .hw_params = zoom2_hw_voice_params,
-};
-
 /* Zoom2 machine DAPM */
 static const struct snd_soc_dapm_widget zoom2_twl4030_dapm_widgets[] = {
        SND_SOC_DAPM_MIC("Ext Mic", NULL),
@@ -162,23 +98,6 @@ static int zoom2_twl4030_init(struct snd_soc_pcm_runtime *rtd)
 {
        struct snd_soc_codec *codec = rtd->codec;
        struct snd_soc_dapm_context *dapm = &codec->dapm;
-       int ret;
-
-       /* Add Zoom2 specific widgets */
-       ret = snd_soc_dapm_new_controls(dapm, zoom2_twl4030_dapm_widgets,
-                               ARRAY_SIZE(zoom2_twl4030_dapm_widgets));
-       if (ret)
-               return ret;
-
-       /* Set up Zoom2 specific audio path audio_map */
-       snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
-
-       /* Zoom2 connected pins */
-       snd_soc_dapm_enable_pin(dapm, "Ext Mic");
-       snd_soc_dapm_enable_pin(dapm, "Ext Spk");
-       snd_soc_dapm_enable_pin(dapm, "Headset Mic");
-       snd_soc_dapm_enable_pin(dapm, "Headset Stereophone");
-       snd_soc_dapm_enable_pin(dapm, "Aux In");
 
        /* TWL4030 not connected pins */
        snd_soc_dapm_nc_pin(dapm, "CARKITMIC");
@@ -190,9 +109,7 @@ static int zoom2_twl4030_init(struct snd_soc_pcm_runtime *rtd)
        snd_soc_dapm_nc_pin(dapm, "CARKITL");
        snd_soc_dapm_nc_pin(dapm, "CARKITR");
 
-       ret = snd_soc_dapm_sync(dapm);
-
-       return ret;
+       return 0;
 }
 
 static int zoom2_twl4030_voice_init(struct snd_soc_pcm_runtime *rtd)
@@ -217,6 +134,8 @@ static struct snd_soc_dai_link zoom2_dai[] = {
                .codec_dai_name = "twl4030-hifi",
                .platform_name = "omap-pcm-audio",
                .codec_name = "twl4030-codec",
+               .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+                          SND_SOC_DAIFMT_CBM_CFM,
                .init = zoom2_twl4030_init,
                .ops = &zoom2_ops,
        },
@@ -227,8 +146,10 @@ static struct snd_soc_dai_link zoom2_dai[] = {
                .codec_dai_name = "twl4030-voice",
                .platform_name = "omap-pcm-audio",
                .codec_name = "twl4030-codec",
+               .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF |
+                          SND_SOC_DAIFMT_CBM_CFM,
                .init = zoom2_twl4030_voice_init,
-               .ops = &zoom2_voice_ops,
+               .ops = &zoom2_ops,
        },
 };
 
@@ -237,6 +158,11 @@ static struct snd_soc_card snd_soc_zoom2 = {
        .name = "Zoom2",
        .dai_link = zoom2_dai,
        .num_links = ARRAY_SIZE(zoom2_dai),
+
+       .dapm_widgets = zoom2_twl4030_dapm_widgets,
+       .num_dapm_widgets = ARRAY_SIZE(zoom2_twl4030_dapm_widgets),
+       .dapm_routes = audio_map,
+       .num_dapm_routes = ARRAY_SIZE(audio_map),
 };
 
 static struct platform_device *zoom2_snd_device;
index 33ebc46b45b5bfe9030ff062c30ad77d02c4f3c4..ffd2242e305f0827fb742f2c2339041d1859785f 100644 (file)
@@ -121,6 +121,7 @@ config SND_PXA2XX_SOC_PALM27X
 config SND_SOC_SAARB
        tristate "SoC Audio support for Marvell Saarb"
        depends on SND_PXA2XX_SOC && MACH_SAARB
+       select MFD_88PM860X
        select SND_PXA_SOC_SSP
        select SND_SOC_88PM860X
        help
@@ -130,6 +131,7 @@ config SND_SOC_SAARB
 config SND_SOC_TAVOREVB3
        tristate "SoC Audio support for Marvell Tavor EVB3"
        depends on SND_PXA2XX_SOC && MACH_TAVOREVB3
+       select MFD_88PM860X
        select SND_PXA_SOC_SSP
        select SND_SOC_88PM860X
        help
index 28757fb9df31d49ac5c37f63ae668a157338949c..b0e2fb720910533d442be66e68db112dbbc93dce 100644 (file)
@@ -299,7 +299,6 @@ static int corgi_wm8731_init(struct snd_soc_pcm_runtime *rtd)
        /* Set up corgi specific audio path audio_map */
        snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
 
-       snd_soc_dapm_sync(dapm);
        return 0;
 }
 
index dc65650a6fa15af240a43de9dab1dbe5e929f228..35ed7eb8cff2e6793147cd52c2acec6a9d86e6b6 100644 (file)
@@ -108,8 +108,6 @@ static int e740_ac97_init(struct snd_soc_pcm_runtime *rtd)
 
        snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
 
-       snd_soc_dapm_sync(dapm);
-
        return 0;
 }
 
index 51897fcd911b9c922f8151af161a73f1588c1131..ce5f056009a7d5770ae85d4bce9bfff73eb538b7 100644 (file)
@@ -90,8 +90,6 @@ static int e750_ac97_init(struct snd_soc_pcm_runtime *rtd)
 
        snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
 
-       snd_soc_dapm_sync(dapm);
-
        return 0;
 }
 
index 053ed208e59f00b713aac31268b0a4163c34f71b..6a8f38b6c3799800b2c283fd231f388584eeeaaf 100644 (file)
@@ -80,7 +80,6 @@ static int e800_ac97_init(struct snd_soc_pcm_runtime *rtd)
                                        ARRAY_SIZE(e800_dapm_widgets));
 
        snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
-       snd_soc_dapm_sync(dapm);
 
        return 0;
 }
index 67dcc36cd621d407df19a4fd2c5f5106dcdc5863..e79f516c400e6df35a57b41356fe3ce39882e3ca 100644 (file)
@@ -92,11 +92,10 @@ static int magician_playback_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_dai *codec_dai = rtd->codec_dai;
        struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-       unsigned int acps, acds, width, rate;
+       unsigned int acps, acds, width;
        unsigned int div4 = PXA_SSP_CLK_SCDB_4;
        int ret = 0;
 
-       rate = params_rate(params);
        width = snd_pcm_format_physical_width(params_format(params));
 
        /*
@@ -424,7 +423,6 @@ static int magician_uda1380_init(struct snd_soc_pcm_runtime *rtd)
        /* Set up magician specific audio path interconnects */
        snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
 
-       snd_soc_dapm_sync(dapm);
        return 0;
 }
 
index 38ca6759907e9d0d333c7c6f0407b9e5d3f8d260..0b8d1ee738a45ae82c2e3dc22efca0d2ab6c152a 100644 (file)
@@ -151,7 +151,6 @@ static int mioa701_wm9713_init(struct snd_soc_pcm_runtime *rtd)
        snd_soc_dapm_enable_pin(dapm, "Front Mic");
        snd_soc_dapm_enable_pin(dapm, "GSM Line In");
        snd_soc_dapm_enable_pin(dapm, "GSM Line Out");
-       snd_soc_dapm_sync(dapm);
 
        return 0;
 }
index 504e4004f004ea6a7dbc0f682d43d25d0071259b..7edc1fb71fae05288eebd25ce16d82d122c83227 100644 (file)
@@ -107,10 +107,6 @@ static int palm27x_ac97_init(struct snd_soc_pcm_runtime *rtd)
        snd_soc_dapm_nc_pin(dapm, "PHONE");
        snd_soc_dapm_nc_pin(dapm, "MIC2");
 
-       err = snd_soc_dapm_sync(dapm);
-       if (err)
-               return err;
-
        /* Jack detection API stuff */
        err = snd_soc_jack_new(codec, "Headphone Jack",
                                SND_JACK_HEADPHONE, &hs_jack);
index da3ae4316cf2b9930d46fd2cf47f01c357f4f376..4c29bc1f9cfedf10de921fd8eb338290ff0c5564 100644 (file)
@@ -265,7 +265,6 @@ static int poodle_wm8731_init(struct snd_soc_pcm_runtime *rtd)
        /* Set up poodle specific audio path audio_map */
        snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
 
-       snd_soc_dapm_sync(dapm);
        return 0;
 }
 
index 1a591f1ebfbd9431f89559be28421d8defde585c..b899a3bc8f42356cce6e9c6f1629bf0402f5706d 100644 (file)
@@ -306,8 +306,10 @@ static int __init raumfeld_audio_init(void)
                                     &snd_soc_raumfeld_connector);
 
        ret = platform_device_add(raumfeld_audio_device);
-       if (ret < 0)
+       if (ret < 0) {
+               platform_device_put(raumfeld_audio_device);
                return ret;
+       }
 
        raumfeld_enable_audio(true);
        return 0;
index 9595189fc681c4fdbb9d3a6bd1311da96d39ecdb..d9467a2c6de0ec635d0c4d9a0cc8f838b24f8f64 100644 (file)
@@ -146,10 +146,6 @@ static int saarb_pm860x_init(struct snd_soc_pcm_runtime *rtd)
        snd_soc_dapm_disable_pin(dapm, "Headset Mic 2");
        snd_soc_dapm_disable_pin(dapm, "Headset Stereophone");
 
-       ret = snd_soc_dapm_sync(dapm);
-       if (ret)
-               return ret;
-
        /* Headset jack detection */
        snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE
                        | SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2,
index b253d864868a558001dd9e6e90b0e33d739a254d..c2d6ff9b1588a63c7faed4477e944b5948da51d7 100644 (file)
@@ -301,7 +301,6 @@ static int spitz_wm8750_init(struct snd_soc_pcm_runtime *rtd)
        /* Set up spitz specific audio paths */
        snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
 
-       snd_soc_dapm_sync(dapm);
        return 0;
 }
 
@@ -312,7 +311,7 @@ static struct snd_soc_dai_link spitz_dai = {
        .cpu_dai_name = "pxa2xx-i2s",
        .codec_dai_name = "wm8750-hifi",
        .platform_name = "pxa-pcm-audio",
-       .codec_name = "wm8750-codec.0-001b",
+       .codec_name = "wm8750.0-001b",
        .init = spitz_wm8750_init,
        .ops = &spitz_ops,
 };
index f881f65ec172bb20884c2070437dbeee0d0874be..eeec892e0e0480ac07a167cfc84f626ea552121d 100644 (file)
@@ -146,10 +146,6 @@ static int evb3_pm860x_init(struct snd_soc_pcm_runtime *rtd)
        snd_soc_dapm_disable_pin(dapm, "Headset Mic 2");
        snd_soc_dapm_disable_pin(dapm, "Headset Stereophone");
 
-       ret = snd_soc_dapm_sync(dapm);
-       if (ret)
-               return ret;
-
        /* Headset jack detection */
        snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE
                        | SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2,
index 9a2351366957a20ce85579fff47f376612bce34a..620fc69ae6324507a6feab69f3ea66d33f2d5d6d 100644 (file)
@@ -211,7 +211,6 @@ static int tosa_ac97_init(struct snd_soc_pcm_runtime *rtd)
        /* set up tosa specific audio path audio_map */
        snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
 
-       snd_soc_dapm_sync(dapm);
        return 0;
 }
 
index d69d9fc32233f0f8935920fc4fb68dcb4e03f9f2..b311ffe04b71f6a0a1e87bd7470f0b50a422ecd3 100644 (file)
@@ -161,10 +161,6 @@ static int z2_wm8750_init(struct snd_soc_pcm_runtime *rtd)
        /* Set up z2 specific audio paths */
        snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
 
-       ret = snd_soc_dapm_sync(dapm);
-       if (ret)
-               goto err;
-
        /* Jack detection API stuff */
        ret = snd_soc_jack_new(codec, "Headset Jack", SND_JACK_HEADSET,
                                &hs_jack);
@@ -198,7 +194,7 @@ static struct snd_soc_dai_link z2_dai = {
        .cpu_dai_name   = "pxa2xx-i2s",
        .codec_dai_name = "wm8750-hifi",
        .platform_name = "pxa-pcm-audio",
-       .codec_name     = "wm8750-codec.0-001b",
+       .codec_name     = "wm8750.0-001b",
        .init           = z2_wm8750_init,
        .ops            = &z2_ops,
 };
index 2b8350b522329253d4d4fda27a7859f68861cc18..580aae38e502ce859e0d58978f0f0c0d0b30d4ba 100644 (file)
@@ -87,7 +87,6 @@ static int zylonite_wm9713_init(struct snd_soc_pcm_runtime *rtd)
        snd_soc_dapm_enable_pin(dapm, "Headphone");
        snd_soc_dapm_enable_pin(dapm, "Headset Earpiece");
 
-       snd_soc_dapm_sync(dapm);
        return 0;
 }
 
index 80c85fd64e1aac4311502e2688f1f64da09fbf67..55efc2bdf0bd0a4fd73f938299764222601a5014 100644 (file)
@@ -446,7 +446,6 @@ static u64 s6000_pcm_dmamask = DMA_BIT_MASK(32);
 static int s6000_pcm_new(struct snd_soc_pcm_runtime *runtime)
 {
        struct snd_card *card = runtime->card->snd_card;
-       struct snd_soc_dai *dai = runtime->cpu_dai;
        struct snd_pcm *pcm = runtime->pcm;
        struct s6000_pcm_dma_params *params;
        int res;
index 65f980ef28708689f7e554b514cbd54a8b18b3a2..53aaa69eda0365c40a909573d7cbb23901311d75 100644 (file)
@@ -63,7 +63,9 @@ config SND_SOC_SAMSUNG_SMDK_WM8580
 
 config SND_SOC_SAMSUNG_SMDK_WM8994
        tristate "SoC I2S Audio support for WM8994 on SMDK"
-       depends on SND_SOC_SAMSUNG && (MACH_SMDKV310 || MACH_SMDKC210)
+       depends on SND_SOC_SAMSUNG && (MACH_SMDKV310 || MACH_SMDKC210 || MACH_SMDK4212)
+       depends on I2C=y && GENERIC_HARDIRQS
+       select MFD_WM8994
        select SND_SOC_WM8994
        select SND_SAMSUNG_I2S
        help
@@ -150,7 +152,9 @@ config SND_SOC_SMARTQ
 config SND_SOC_GONI_AQUILA_WM8994
        tristate "SoC I2S Audio support for AQUILA/GONI - WM8994"
        depends on SND_SOC_SAMSUNG && (MACH_GONI || MACH_AQUILA)
+       depends on I2C=y && GENERIC_HARDIRQS
        select SND_SAMSUNG_I2S
+       select MFD_WM8994
        select SND_SOC_WM8994
        help
          Say Y if you want to add support for SoC audio on goni or aquila
@@ -158,7 +162,7 @@ config SND_SOC_GONI_AQUILA_WM8994
 
 config SND_SOC_SAMSUNG_SMDK_SPDIF
        tristate "SoC S/PDIF Audio support for SMDK"
-       depends on SND_SOC_SAMSUNG && (MACH_SMDKC100 || MACH_SMDKC110 || MACH_SMDKV210 || MACH_SMDKV310)
+       depends on SND_SOC_SAMSUNG && (MACH_SMDKC100 || MACH_SMDKC110 || MACH_SMDKV210 || MACH_SMDKV310 || MACH_SMDK4212)
        select SND_SAMSUNG_SPDIF
        help
          Say Y if you want to add support for SoC S/PDIF audio on the SMDK.
@@ -173,7 +177,9 @@ config SND_SOC_SMDK_WM8580_PCM
 
 config SND_SOC_SMDK_WM8994_PCM
        tristate "SoC PCM Audio support for WM8994 on SMDK"
-       depends on SND_SOC_SAMSUNG && (MACH_SMDKC210 || MACH_SMDKV310)
+       depends on SND_SOC_SAMSUNG && (MACH_SMDKC210 || MACH_SMDKV310 || MACH_SMDK4212)
+       depends on I2C=y && GENERIC_HARDIRQS
+       select MFD_WM8994
        select SND_SOC_WM8994
        select SND_SAMSUNG_PCM
        help
index f97110e72e855d1da85253ec83212f185a29e152..b5e922f469d5a0a70b9c477aa231b6b278b2eb60 100644 (file)
@@ -444,7 +444,7 @@ static __devinit int s3c_ac97_probe(struct platform_device *pdev)
        }
 
        ret = request_irq(irq_res->start, s3c_ac97_irq,
-                                       IRQF_DISABLED, "AC97", NULL);
+                                       0, "AC97", NULL);
        if (ret < 0) {
                dev_err(&pdev->dev, "ac97: interrupt request failed.\n");
                goto err4;
@@ -495,7 +495,7 @@ static __devexit int s3c_ac97_remove(struct platform_device *pdev)
 
 static struct platform_driver s3c_ac97_driver = {
        .probe  = s3c_ac97_probe,
-       .remove = s3c_ac97_remove,
+       .remove = __devexit_p(s3c_ac97_remove),
        .driver = {
                .name = "samsung-ac97",
                .owner = THIS_MODULE,
index eb6d72ed55a7d53accac1809921572ba92570d87..4a34f608e131127aa73a27618e6c5870d60c1e7e 100644 (file)
@@ -99,14 +99,6 @@ static int goni_wm8994_init(struct snd_soc_pcm_runtime *rtd)
        struct snd_soc_dapm_context *dapm = &codec->dapm;
        int ret;
 
-       /* add goni specific widgets */
-       snd_soc_dapm_new_controls(dapm, goni_dapm_widgets,
-                       ARRAY_SIZE(goni_dapm_widgets));
-
-       /* set up goni specific audio routes */
-       snd_soc_dapm_add_routes(dapm, goni_dapm_routes,
-                       ARRAY_SIZE(goni_dapm_routes));
-
        /* set endpoints to not connected */
        snd_soc_dapm_nc_pin(dapm, "IN2LP:VXRN");
        snd_soc_dapm_nc_pin(dapm, "IN2RP:VXRP");
@@ -120,8 +112,6 @@ static int goni_wm8994_init(struct snd_soc_pcm_runtime *rtd)
                snd_soc_dapm_nc_pin(dapm, "SPKOUTRP");
        }
 
-       snd_soc_dapm_sync(dapm);
-
        /* Headset jack detection */
        ret = snd_soc_jack_new(codec, "Headset Jack",
                        SND_JACK_HEADSET | SND_JACK_MECHANICAL | SND_JACK_AVOUT,
@@ -255,6 +245,11 @@ static struct snd_soc_card goni = {
        .name = "goni",
        .dai_link = goni_dai,
        .num_links = ARRAY_SIZE(goni_dai),
+
+       .dapm_widgets = goni_dapm_widgets,
+       .num_dapm_widgets = ARRAY_SIZE(goni_dapm_widgets),
+       .dapm_routes = goni_dapm_routes,
+       .num_dapm_routes = ARRAY_SIZE(goni_dapm_routes),
 };
 
 static int __init goni_init(void)
index c6c65892294e4bf8cee9829a1c6fb456e522aebd..f75a4b60cf38a9909b2713d5b0df30fc2dd02dfd 100644 (file)
@@ -182,24 +182,10 @@ static int h1940_uda1380_init(struct snd_soc_pcm_runtime *rtd)
        struct snd_soc_dapm_context *dapm = &codec->dapm;
        int err;
 
-       /* Add h1940 specific widgets */
-       err = snd_soc_dapm_new_controls(dapm, uda1380_dapm_widgets,
-                                 ARRAY_SIZE(uda1380_dapm_widgets));
-       if (err)
-               return err;
-
-       /* Set up h1940 specific audio path audio_mapnects */
-       err = snd_soc_dapm_add_routes(dapm, audio_map,
-                                     ARRAY_SIZE(audio_map));
-       if (err)
-               return err;
-
        snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
        snd_soc_dapm_enable_pin(dapm, "Speaker");
        snd_soc_dapm_enable_pin(dapm, "Mic Jack");
 
-       snd_soc_dapm_sync(dapm);
-
        snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE,
                &hp_jack);
 
@@ -230,6 +216,11 @@ static struct snd_soc_card h1940_asoc = {
        .name = "h1940",
        .dai_link = h1940_uda1380_dai,
        .num_links = ARRAY_SIZE(h1940_uda1380_dai),
+
+       .dapm_widgets = uda1380_dapm_widgets,
+       .num_dapm_widgets = ARRAY_SIZE(uda1380_dapm_widgets),
+       .dapm_routes = audio_map,
+       .num_dapm_routes = ARRAY_SIZE(audio_map),
 };
 
 static int __init h1940_init(void)
index c086b78539ee5075f14b76d99089e4abb7f0abf1..0c9ac20d222380870826e39505bea7240e837395 100644 (file)
@@ -1136,7 +1136,7 @@ static __devexit int samsung_i2s_remove(struct platform_device *pdev)
 
 static struct platform_driver samsung_i2s_driver = {
        .probe  = samsung_i2s_probe,
-       .remove = samsung_i2s_remove,
+       .remove = __devexit_p(samsung_i2s_remove),
        .driver = {
                .name = "samsung-i2s",
                .owner = THIS_MODULE,
index 14eb6ea69e7c50f71791be271f17d5fd5c33f27f..f5f7c6f822d5c4bed45cb6304b156ff09d128e28 100644 (file)
@@ -110,18 +110,6 @@ static int jive_wm8750_init(struct snd_soc_pcm_runtime *rtd)
        snd_soc_dapm_nc_pin(dapm, "OUT3");
        snd_soc_dapm_nc_pin(dapm, "MONO");
 
-       /* Add jive specific widgets */
-       err = snd_soc_dapm_new_controls(dapm, wm8750_dapm_widgets,
-                                       ARRAY_SIZE(wm8750_dapm_widgets));
-       if (err) {
-               printk(KERN_ERR "%s: failed to add widgets (%d)\n",
-                      __func__, err);
-               return err;
-       }
-
-       snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
-       snd_soc_dapm_sync(dapm);
-
        return 0;
 }
 
@@ -131,7 +119,7 @@ static struct snd_soc_dai_link jive_dai = {
        .cpu_dai_name   = "s3c2412-i2s",
        .codec_dai_name = "wm8750-hifi",
        .platform_name  = "samsung-audio",
-       .codec_name     = "wm8750-codec.0-001a",
+       .codec_name     = "wm8750.0-001a",
        .init           = jive_wm8750_init,
        .ops            = &jive_ops,
 };
@@ -141,6 +129,11 @@ static struct snd_soc_card snd_soc_machine_jive = {
        .name           = "Jive",
        .dai_link       = &jive_dai,
        .num_links      = 1,
+
+       .dapm_widgtets  = wm8750_dapm_widgets,
+       .num_dapm_widgets = ARRAY_SIZE(wm8750_dapm_widgets),
+       .dapm_routes    = audio_map,
+       .num_dapm_routes = ARRAY_SIZE(audio_map),
 };
 
 static struct platform_device *jive_snd_device;
index 16152ed086488fcc7ab15061b7a831adee42b741..7207189cd21196aa0dc574aec3bed3b88d9869e9 100644 (file)
@@ -367,8 +367,6 @@ static int neo1973_wm8753_init(struct snd_soc_pcm_runtime *rtd)
                        return ret;
        }
 
-       snd_soc_dapm_sync(dapm);
-
        return 0;
 }
 
@@ -409,8 +407,6 @@ static int neo1973_lm4857_init(struct snd_soc_dapm_context *dapm)
        snd_soc_dapm_ignore_suspend(dapm, "Handset Spk");
        snd_soc_dapm_ignore_suspend(dapm, "Headphone");
 
-       snd_soc_dapm_sync(dapm);
-
        return 0;
 }
 
index 9c7e8b48aed6a4dc2bbc76d1955a5d56025eae9b..e55d7a5c4bdc59a41127004e2295e5ed730293ff 100644 (file)
@@ -624,7 +624,7 @@ static __devexit int s3c_pcm_dev_remove(struct platform_device *pdev)
 
 static struct platform_driver s3c_pcm_driver = {
        .probe  = s3c_pcm_dev_probe,
-       .remove = s3c_pcm_dev_remove,
+       .remove = __devexit_p(s3c_pcm_dev_remove),
        .driver = {
                .name = "samsung-pcm",
                .owner = THIS_MODULE,
index bc8c1676459f781b56b28e5fbcadd9ad7732f4a4..aea7f1b24e6be5eda3ce138891a1928f649a9529 100644 (file)
@@ -90,12 +90,6 @@ static struct snd_soc_dai_link rx1950_uda1380_dai[] = {
        },
 };
 
-static struct snd_soc_card rx1950_asoc = {
-       .name = "rx1950",
-       .dai_link = rx1950_uda1380_dai,
-       .num_links = ARRAY_SIZE(rx1950_uda1380_dai),
-};
-
 /* rx1950 machine dapm widgets */
 static const struct snd_soc_dapm_widget uda1380_dapm_widgets[] = {
        SND_SOC_DAPM_HP("Headphone Jack", NULL),
@@ -117,6 +111,17 @@ static const struct snd_soc_dapm_route audio_map[] = {
        {"VINM", NULL, "Mic Jack"},
 };
 
+static struct snd_soc_card rx1950_asoc = {
+       .name = "rx1950",
+       .dai_link = rx1950_uda1380_dai,
+       .num_links = ARRAY_SIZE(rx1950_uda1380_dai),
+
+       .dapm_widgets = uda1380_dapm_widgets,
+       .num_dapm_widgets = ARRAY_SIZE(uda1380_dapm_widgets),
+       .dapm_routes = audio_map,
+       .num_dapm_routes = ARRAY_SIZE(audio_map),
+};
+
 static struct platform_device *s3c24xx_snd_device;
 
 static int rx1950_startup(struct snd_pcm_substream *substream)
@@ -220,26 +225,10 @@ static int rx1950_uda1380_init(struct snd_soc_pcm_runtime *rtd)
        struct snd_soc_dapm_context *dapm = &codec->dapm;
        int err;
 
-       /* Add rx1950 specific widgets */
-       err = snd_soc_dapm_new_controls(dapm, uda1380_dapm_widgets,
-                                 ARRAY_SIZE(uda1380_dapm_widgets));
-
-       if (err)
-               return err;
-
-       /* Set up rx1950 specific audio path audio_mapnects */
-       err = snd_soc_dapm_add_routes(dapm, audio_map,
-                                     ARRAY_SIZE(audio_map));
-
-       if (err)
-               return err;
-
        snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
        snd_soc_dapm_enable_pin(dapm, "Speaker");
        snd_soc_dapm_enable_pin(dapm, "Mic Jack");
 
-       snd_soc_dapm_sync(dapm);
-
        snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE,
                &hp_jack);
 
index 52074a2b069600875fc3f2756dc2a25e01fa9163..7a73380b3560f22af046d30af04846435f806e83 100644 (file)
@@ -16,6 +16,7 @@
  * option) any later version.
  */
 
+#include <linux/module.h>
 #include <linux/delay.h>
 #include <linux/clk.h>
 #include <linux/io.h>
index 841ab14c1100a9ca759fede04dae139402325d62..f26a8bfb2357429a01b6e6b33bab89c2ee04de49 100644 (file)
@@ -69,10 +69,10 @@ static int s3c2412_i2s_probe(struct snd_soc_dai *dai)
        s3c2412_i2s.dma_playback = &s3c2412_i2s_pcm_stereo_out;
 
        s3c2412_i2s.iis_cclk = clk_get(dai->dev, "i2sclk");
-       if (s3c2412_i2s.iis_cclk == NULL) {
+       if (IS_ERR(s3c2412_i2s.iis_cclk)) {
                pr_err("failed to get i2sclk clock\n");
                iounmap(s3c2412_i2s.regs);
-               return -ENODEV;
+               return PTR_ERR(s3c2412_i2s.iis_cclk);
        }
 
        /* Set MPLL as the source for IIS CLK */
@@ -176,7 +176,7 @@ static __devexit int s3c2412_iis_dev_remove(struct platform_device *pdev)
 
 static struct platform_driver s3c2412_iis_driver = {
        .probe  = s3c2412_iis_dev_probe,
-       .remove = s3c2412_iis_dev_remove,
+       .remove = __devexit_p(s3c2412_iis_dev_remove),
        .driver = {
                .name = "s3c2412-iis",
                .owner = THIS_MODULE,
index 63d8849d80bdc738e667201af435f2ed838a9a9e..c08117e658db748174f2b95fa2f76272abe3a93e 100644 (file)
@@ -383,10 +383,10 @@ static int s3c24xx_i2s_probe(struct snd_soc_dai *dai)
                return -ENXIO;
 
        s3c24xx_i2s.iis_clk = clk_get(dai->dev, "iis");
-       if (s3c24xx_i2s.iis_clk == NULL) {
+       if (IS_ERR(s3c24xx_i2s.iis_clk)) {
                pr_err("failed to get iis_clock\n");
                iounmap(s3c24xx_i2s.regs);
-               return -ENODEV;
+               return PTR_ERR(s3c24xx_i2s.iis_clk);
        }
        clk_enable(s3c24xx_i2s.iis_clk);
 
@@ -481,7 +481,7 @@ static __devexit int s3c24xx_iis_dev_remove(struct platform_device *pdev)
 
 static struct platform_driver s3c24xx_iis_driver = {
        .probe  = s3c24xx_iis_dev_probe,
-       .remove = s3c24xx_iis_dev_remove,
+       .remove = __devexit_p(s3c24xx_iis_dev_remove),
        .driver = {
                .name = "s3c24xx-iis",
                .owner = THIS_MODULE,
index 349566f0686b7a234aa2db7ef767a712dbc7d603..c8d525bf6122ea43f513231aab28f644681e9ae5 100644 (file)
@@ -300,7 +300,7 @@ static void detach_gpio_amp(struct s3c24xx_audio_simtec_pdata *pd)
 }
 
 #ifdef CONFIG_PM
-int simtec_audio_resume(struct device *dev)
+static int simtec_audio_resume(struct device *dev)
 {
        simtec_call_startup(pdata);
        return 0;
index ce6aef6041793b40ac1f8b494feea76ae3f14b90..6bc5a36af1d9c74ed7fe7a269a8ac269e6ba7ab5 100644 (file)
@@ -65,18 +65,12 @@ static int simtec_hermes_init(struct snd_soc_pcm_runtime *rtd)
        struct snd_soc_codec *codec = rtd->codec;
        struct snd_soc_dapm_context *dapm = &codec->dapm;
 
-       snd_soc_dapm_new_controls(dapm, dapm_widgets,
-                                 ARRAY_SIZE(dapm_widgets));
-
-       snd_soc_dapm_add_routes(dapm, base_map, ARRAY_SIZE(base_map));
-
        snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
        snd_soc_dapm_enable_pin(dapm, "Line In");
        snd_soc_dapm_enable_pin(dapm, "Line Out");
        snd_soc_dapm_enable_pin(dapm, "Mic Jack");
 
        simtec_audio_init(rtd);
-       snd_soc_dapm_sync(dapm);
 
        return 0;
 }
@@ -96,6 +90,11 @@ static struct snd_soc_card snd_soc_machine_simtec_aic33 = {
        .name           = "Simtec-Hermes",
        .dai_link       = &simtec_dai_aic33,
        .num_links      = 1,
+
+       .dapm_widgets   = dapm_widgets,
+       .num_dapm_widgets = ARRAY_SIZE(dapm_widgets),
+       .dapm_routes    = base_map,
+       .num_dapm_routes = ARRAY_SIZE(base_map),
 };
 
 static int __devinit simtec_audio_hermes_probe(struct platform_device *pd)
index a7ef7db5468734047bf32cf1b7bb1e982b1233ce..7bdda76740083c365b908320c5b4c871ff4e6582 100644 (file)
@@ -54,18 +54,12 @@ static int simtec_tlv320aic23_init(struct snd_soc_pcm_runtime *rtd)
        struct snd_soc_codec *codec = rtd->codec;
        struct snd_soc_dapm_context *dapm = &codec->dapm;
 
-       snd_soc_dapm_new_controls(dapm, dapm_widgets,
-                                 ARRAY_SIZE(dapm_widgets));
-
-       snd_soc_dapm_add_routes(dapm, base_map, ARRAY_SIZE(base_map));
-
        snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
        snd_soc_dapm_enable_pin(dapm, "Line In");
        snd_soc_dapm_enable_pin(dapm, "Line Out");
        snd_soc_dapm_enable_pin(dapm, "Mic Jack");
 
        simtec_audio_init(rtd);
-       snd_soc_dapm_sync(dapm);
 
        return 0;
 }
@@ -85,6 +79,11 @@ static struct snd_soc_card snd_soc_machine_simtec_aic23 = {
        .name           = "Simtec",
        .dai_link       = &simtec_dai_aic23,
        .num_links      = 1,
+
+       .dapm_widgets   = dapm_widgets,
+       .num_dapm_widgets = ARRAY_SIZE(dapm_widgets),
+       .dapm_routes    = base_map,
+       .num_dapm_routes = ARRAY_SIZE(base_map),
 };
 
 static int __devinit simtec_audio_tlv320aic23_probe(struct platform_device *pd)
index dc9d551f6788db05a420a0598494e947be4bcc51..65c1cfd47d8a73ae819403c3e24a5efccd5758ff 100644 (file)
@@ -66,17 +66,17 @@ static int s3c24xx_uda134x_startup(struct snd_pcm_substream *substream)
        pr_debug("%s %d\n", __func__, clk_users);
        if (clk_users == 0) {
                xtal = clk_get(&s3c24xx_uda134x_snd_device->dev, "xtal");
-               if (!xtal) {
+               if (IS_ERR(xtal)) {
                        printk(KERN_ERR "%s cannot get xtal\n", __func__);
-                       ret = -EBUSY;
+                       ret = PTR_ERR(xtal);
                } else {
                        pclk = clk_get(&s3c24xx_uda134x_snd_device->dev,
                                       "pclk");
-                       if (!pclk) {
+                       if (IS_ERR(pclk)) {
                                printk(KERN_ERR "%s cannot get pclk\n",
                                       __func__);
                                clk_put(xtal);
-                               ret = -EBUSY;
+                               ret = PTR_ERR(pclk);
                        }
                }
                if (!ret) {
index 0a2c4f22303811b55921452f783ae485fefb3bdd..6ac6bc2bcc4e4c571850209bcdb45278c4a31b56 100644 (file)
@@ -153,20 +153,6 @@ static int smartq_wm8987_init(struct snd_soc_pcm_runtime *rtd)
        struct snd_soc_dapm_context *dapm = &codec->dapm;
        int err = 0;
 
-       /* Add SmartQ specific widgets */
-       snd_soc_dapm_new_controls(dapm, wm8987_dapm_widgets,
-                                 ARRAY_SIZE(wm8987_dapm_widgets));
-
-       /* add SmartQ specific controls */
-       err = snd_soc_add_controls(codec, wm8987_smartq_controls,
-                                  ARRAY_SIZE(wm8987_smartq_controls));
-
-       if (err < 0)
-               return err;
-
-       /* setup SmartQ specific audio path */
-       snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
-
        /* set endpoints to not connected */
        snd_soc_dapm_nc_pin(dapm, "LINPUT1");
        snd_soc_dapm_nc_pin(dapm, "RINPUT1");
@@ -178,10 +164,6 @@ static int smartq_wm8987_init(struct snd_soc_pcm_runtime *rtd)
        snd_soc_dapm_enable_pin(dapm, "Internal Mic");
        snd_soc_dapm_disable_pin(dapm, "Headphone Jack");
 
-       err = snd_soc_dapm_sync(dapm);
-       if (err)
-               return err;
-
        /* Headphone jack detection */
        err = snd_soc_jack_new(codec, "Headphone Jack",
                               SND_JACK_HEADPHONE, &smartq_jack);
@@ -207,7 +189,7 @@ static struct snd_soc_dai_link smartq_dai[] = {
                .cpu_dai_name   = "samsung-i2s.0",
                .codec_dai_name = "wm8750-hifi",
                .platform_name  = "samsung-audio",
-               .codec_name     = "wm8750-codec.0-0x1a",
+               .codec_name     = "wm8750.0-0x1a",
                .init           = smartq_wm8987_init,
                .ops            = &smartq_hifi_ops,
        },
@@ -217,6 +199,13 @@ static struct snd_soc_card snd_soc_smartq = {
        .name = "SmartQ",
        .dai_link = smartq_dai,
        .num_links = ARRAY_SIZE(smartq_dai),
+
+       .dapm_widgets = wm8987_dapm_widgets,
+       .num_dapm_widgets = ARRAY_SIZE(wm8987_dapm_widgets),
+       .dapm_routes = audio_map,
+       .num_dapm_routes = ARRAY_SIZE(audio_map),
+       .controls = wm8987_smartq_controls,
+       .num_controls = ARRAY_SIZE(wm8987_smartq_controls),
 };
 
 static struct platform_device *smartq_snd_device;
index 3d26f6607aa47aa97cc6798ac0d10cb14276a0ae..8f92ffceb5cafb3b797678ea073a2fbc0a9c9647 100644 (file)
@@ -119,30 +119,24 @@ static struct snd_soc_ops smdk_ops = {
 };
 
 /* SMDK Playback widgets */
-static const struct snd_soc_dapm_widget wm8580_dapm_widgets_pbk[] = {
+static const struct snd_soc_dapm_widget smdk_wm8580_dapm_widgets[] = {
        SND_SOC_DAPM_HP("Front", NULL),
        SND_SOC_DAPM_HP("Center+Sub", NULL),
        SND_SOC_DAPM_HP("Rear", NULL),
-};
 
-/* SMDK Capture widgets */
-static const struct snd_soc_dapm_widget wm8580_dapm_widgets_cpt[] = {
        SND_SOC_DAPM_MIC("MicIn", NULL),
        SND_SOC_DAPM_LINE("LineIn", NULL),
 };
 
 /* SMDK-PAIFTX connections */
-static const struct snd_soc_dapm_route audio_map_tx[] = {
+static const struct snd_soc_dapm_route smdk_wm8580_audio_map[] = {
        /* MicIn feeds AINL */
        {"AINL", NULL, "MicIn"},
 
        /* LineIn feeds AINL/R */
        {"AINL", NULL, "LineIn"},
        {"AINR", NULL, "LineIn"},
-};
 
-/* SMDK-PAIFRX connections */
-static const struct snd_soc_dapm_route audio_map_rx[] = {
        /* Front Left/Right are fed VOUT1L/R */
        {"Front", NULL, "VOUT1L"},
        {"Front", NULL, "VOUT1R"},
@@ -161,39 +155,11 @@ static int smdk_wm8580_init_paiftx(struct snd_soc_pcm_runtime *rtd)
        struct snd_soc_codec *codec = rtd->codec;
        struct snd_soc_dapm_context *dapm = &codec->dapm;
 
-       /* Add smdk specific Capture widgets */
-       snd_soc_dapm_new_controls(dapm, wm8580_dapm_widgets_cpt,
-                                 ARRAY_SIZE(wm8580_dapm_widgets_cpt));
-
-       /* Set up PAIFTX audio path */
-       snd_soc_dapm_add_routes(dapm, audio_map_tx, ARRAY_SIZE(audio_map_tx));
-
        /* Enabling the microphone requires the fitting of a 0R
         * resistor to connect the line from the microphone jack.
         */
        snd_soc_dapm_disable_pin(dapm, "MicIn");
 
-       /* signal a DAPM event */
-       snd_soc_dapm_sync(dapm);
-
-       return 0;
-}
-
-static int smdk_wm8580_init_paifrx(struct snd_soc_pcm_runtime *rtd)
-{
-       struct snd_soc_codec *codec = rtd->codec;
-       struct snd_soc_dapm_context *dapm = &codec->dapm;
-
-       /* Add smdk specific Playback widgets */
-       snd_soc_dapm_new_controls(dapm, wm8580_dapm_widgets_pbk,
-                                 ARRAY_SIZE(wm8580_dapm_widgets_pbk));
-
-       /* Set up PAIFRX audio path */
-       snd_soc_dapm_add_routes(dapm, audio_map_rx, ARRAY_SIZE(audio_map_rx));
-
-       /* signal a DAPM event */
-       snd_soc_dapm_sync(dapm);
-
        return 0;
 }
 
@@ -210,8 +176,7 @@ static struct snd_soc_dai_link smdk_dai[] = {
                .cpu_dai_name = "samsung-i2s.0",
                .codec_dai_name = "wm8580-hifi-playback",
                .platform_name = "samsung-audio",
-               .codec_name = "wm8580-codec.0-001b",
-               .init = smdk_wm8580_init_paifrx,
+               .codec_name = "wm8580.0-001b",
                .ops = &smdk_ops,
        },
        [PRI_CAPTURE] = { /* Primary Capture i/f */
@@ -220,7 +185,7 @@ static struct snd_soc_dai_link smdk_dai[] = {
                .cpu_dai_name = "samsung-i2s.0",
                .codec_dai_name = "wm8580-hifi-capture",
                .platform_name = "samsung-audio",
-               .codec_name = "wm8580-codec.0-001b",
+               .codec_name = "wm8580.0-001b",
                .init = smdk_wm8580_init_paiftx,
                .ops = &smdk_ops,
        },
@@ -230,8 +195,7 @@ static struct snd_soc_dai_link smdk_dai[] = {
                .cpu_dai_name = "samsung-i2s.x",
                .codec_dai_name = "wm8580-hifi-playback",
                .platform_name = "samsung-audio",
-               .codec_name = "wm8580-codec.0-001b",
-               .init = smdk_wm8580_init_paifrx,
+               .codec_name = "wm8580.0-001b",
                .ops = &smdk_ops,
        },
 };
@@ -240,6 +204,11 @@ static struct snd_soc_card smdk = {
        .name = "SMDK-I2S",
        .dai_link = smdk_dai,
        .num_links = 2,
+
+       .dapm_widgets = smdk_wm8580_dapm_widgets,
+       .num_dapm_widgets = ARRAY_SIZE(smdk_wm8580_dapm_widgets),
+       .dapm_routes = smdk_wm8580_audio_map,
+       .num_dapm_routes = ARRAY_SIZE(smdk_wm8580_audio_map),
 };
 
 static struct platform_device *smdk_snd_device;
index 0d12092df164bde51c8d6f28ad6488c227c745d8..4b9c73477ce0d9e875256e4985ff78f70d5056ca 100644 (file)
@@ -127,7 +127,7 @@ static struct snd_soc_dai_link smdk_dai[] = {
                .cpu_dai_name = "samsung-pcm.0",
                .codec_dai_name = "wm8580-hifi-playback",
                .platform_name = "samsung-audio",
-               .codec_name = "wm8580-codec.0-001b",
+               .codec_name = "wm8580.0-001b",
                .ops = &smdk_wm8580_pcm_ops,
        }, {
                .name = "WM8580 PAIF PCM TX",
@@ -135,7 +135,7 @@ static struct snd_soc_dai_link smdk_dai[] = {
                .cpu_dai_name = "samsung-pcm.0",
                .codec_dai_name = "wm8580-hifi-capture",
                .platform_name = "samsung-audio",
-               .codec_name = "wm8580-codec.0-001b",
+               .codec_name = "wm8580.0-001b",
                .ops = &smdk_wm8580_pcm_ops,
        },
 };
index 45fbe2b3727fb87ffe2d36f96ae7c9964bb54044..f75e43997d5beb5b27a82f8d023eddd33311538e 100644 (file)
@@ -117,8 +117,6 @@ static int smdk_wm8994_init_paiftx(struct snd_soc_pcm_runtime *rtd)
        snd_soc_dapm_nc_pin(dapm, "IN1RP");
        snd_soc_dapm_nc_pin(dapm, "IN2RP:VXRP");
 
-       snd_soc_dapm_sync(dapm);
-
        return 0;
 }
 
index 28c491dacf7a9aca23463e15bf72c64abf0b0b2c..3122f3154bfa7295f0de3650533e8eafa4c8608b 100644 (file)
@@ -340,7 +340,7 @@ static struct snd_soc_dai_ops spdif_dai_ops = {
        .shutdown       = spdif_shutdown,
 };
 
-struct snd_soc_dai_driver samsung_spdif_dai = {
+static struct snd_soc_dai_driver samsung_spdif_dai = {
        .name = "samsung-spdif",
        .playback = {
                .stream_name = "S/PDIF Playback",
@@ -475,7 +475,7 @@ static __devexit int spdif_remove(struct platform_device *pdev)
 
 static struct platform_driver samsung_spdif_driver = {
        .probe  = spdif_probe,
-       .remove = spdif_remove,
+       .remove = __devexit_p(spdif_remove),
        .driver = {
                .name   = "samsung-spdif",
                .owner  = THIS_MODULE,
index 590e9274b06285428f25a25104e524ccddb0d304..b9e213f6cc0630f179d9b811d6b382dac6c64777 100644 (file)
@@ -125,10 +125,6 @@ static struct snd_soc_jack_pin speyside_headset_pins[] = {
                .pin = "Headset Mic",
                .mask = SND_JACK_MICROPHONE,
        },
-       {
-               .pin = "Headphone",
-               .mask = SND_JACK_HEADPHONE,
-       },
 };
 
 /* Default the headphone selection to active high */
@@ -171,7 +167,8 @@ static int speyside_wm8996_init(struct snd_soc_pcm_runtime *rtd)
        gpio_direction_output(WM8996_HPSEL_GPIO, speyside_jack_polarity);
 
        ret = snd_soc_jack_new(codec, "Headset",
-                              SND_JACK_HEADSET | SND_JACK_BTN_0,
+                              SND_JACK_LINEOUT | SND_JACK_HEADSET |
+                              SND_JACK_BTN_0,
                               &speyside_headset);
        if (ret)
                return ret;
@@ -227,7 +224,7 @@ static int speyside_wm9081_init(struct snd_soc_dapm_context *dapm)
        snd_soc_dapm_nc_pin(dapm, "LINEOUT");
 
        /* At any time the WM9081 is active it will have this clock */
-       return snd_soc_codec_set_sysclk(dapm->codec, WM9081_SYSCLK_MCLK,
+       return snd_soc_codec_set_sysclk(dapm->codec, WM9081_SYSCLK_MCLK, 0,
                                        48000 * 256, 0);
 }
 
@@ -252,6 +249,7 @@ static const struct snd_kcontrol_new controls[] = {
        SOC_DAPM_PIN_SWITCH("Main AMIC"),
        SOC_DAPM_PIN_SWITCH("WM1250 Input"),
        SOC_DAPM_PIN_SWITCH("WM1250 Output"),
+       SOC_DAPM_PIN_SWITCH("Headphone"),
 };
 
 static struct snd_soc_dapm_widget widgets[] = {
index 72535f2daaf20612c28eef1fcadc577e96cd5ba2..8a082044436e4409461129d01bc94c710b7443b1 100644 (file)
@@ -16,6 +16,8 @@
 
 #include "../codecs/wm8962.h"
 
+static int sample_rate = 44100;
+
 static int speyside_wm8962_set_bias_level(struct snd_soc_card *card,
                                          struct snd_soc_dapm_context *dapm,
                                          enum snd_soc_bias_level level)
@@ -31,13 +33,13 @@ static int speyside_wm8962_set_bias_level(struct snd_soc_card *card,
                if (dapm->bias_level == SND_SOC_BIAS_STANDBY) {
                        ret = snd_soc_dai_set_pll(codec_dai, WM8962_FLL,
                                                  WM8962_FLL_MCLK, 32768,
-                                                 44100 * 256);
+                                                 sample_rate * 512);
                        if (ret < 0)
                                pr_err("Failed to start FLL: %d\n", ret);
 
                        ret = snd_soc_dai_set_sysclk(codec_dai,
                                                     WM8962_SYSCLK_FLL,
-                                                    44100 * 256,
+                                                    sample_rate * 512,
                                                     SND_SOC_CLOCK_IN);
                        if (ret < 0) {
                                pr_err("Failed to set SYSCLK: %d\n", ret);
@@ -92,22 +94,7 @@ static int speyside_wm8962_set_bias_level_post(struct snd_soc_card *card,
 static int speyside_wm8962_hw_params(struct snd_pcm_substream *substream,
                              struct snd_pcm_hw_params *params)
 {
-       struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-       struct snd_soc_dai *codec_dai = rtd->codec_dai;
-       int ret;
-
-       ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
-                                        | SND_SOC_DAIFMT_NB_NF
-                                        | SND_SOC_DAIFMT_CBM_CFM);
-       if (ret < 0)
-               return ret;
-
-       ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
-                                        | SND_SOC_DAIFMT_NB_NF
-                                        | SND_SOC_DAIFMT_CBM_CFM);
-       if (ret < 0)
-               return ret;
+       sample_rate = params_rate(params);
 
        return 0;
 }
@@ -124,12 +111,15 @@ static struct snd_soc_dai_link speyside_wm8962_dai[] = {
                .codec_dai_name = "wm8962",
                .platform_name = "samsung-audio",
                .codec_name = "wm8962.1-001a",
+               .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
+                               | SND_SOC_DAIFMT_CBM_CFM,
                .ops = &speyside_wm8962_ops,
        },
 };
 
 static const struct snd_kcontrol_new controls[] = {
        SOC_DAPM_PIN_SWITCH("Main Speaker"),
+       SOC_DAPM_PIN_SWITCH("DMIC"),
 };
 
 static struct snd_soc_dapm_widget widgets[] = {
@@ -137,6 +127,7 @@ static struct snd_soc_dapm_widget widgets[] = {
        SND_SOC_DAPM_MIC("Headset Mic", NULL),
 
        SND_SOC_DAPM_MIC("DMIC", NULL),
+       SND_SOC_DAPM_MIC("AMIC", NULL),
 
        SND_SOC_DAPM_SPK("Main Speaker", NULL),
 };
@@ -148,12 +139,16 @@ static struct snd_soc_dapm_route audio_paths[] = {
        { "Main Speaker", NULL, "SPKOUTL" },
        { "Main Speaker", NULL, "SPKOUTR" },
 
-       { "MICBIAS", NULL, "Headset Mic" },
-       { "IN4L", NULL, "MICBIAS" },
-       { "IN4R", NULL, "MICBIAS" },
+       { "Headset Mic", NULL, "MICBIAS" },
+       { "IN4L", NULL, "Headset Mic" },
+       { "IN4R", NULL, "Headset Mic" },
+
+       { "AMIC", NULL, "MICBIAS" },
+       { "IN1L", NULL, "AMIC" },
+       { "IN1R", NULL, "AMIC" },
 
-       { "MICBIAS", NULL, "DMIC" },
-       { "DMICDAT", NULL, "MICBIAS" },
+       { "DMIC", NULL, "MICBIAS" },
+       { "DMICDAT", NULL, "DMIC" },
 };
 
 static struct snd_soc_jack speyside_wm8962_headset;
index 8e112ccffb1374df266b479dca44fb946c690883..a32fd16ad668dffe65f87e20943e5c6ec985f38b 100644 (file)
@@ -210,7 +210,7 @@ struct fsi_master {
  *             basic read write function
  */
 
-static void __fsi_reg_write(u32 reg, u32 data)
+static void __fsi_reg_write(u32 __iomem *reg, u32 data)
 {
        /* valid data area is 24bit */
        data &= 0x00ffffff;
@@ -218,12 +218,12 @@ static void __fsi_reg_write(u32 reg, u32 data)
        __raw_writel(data, reg);
 }
 
-static u32 __fsi_reg_read(u32 reg)
+static u32 __fsi_reg_read(u32 __iomem *reg)
 {
        return __raw_readl(reg);
 }
 
-static void __fsi_reg_mask_set(u32 reg, u32 mask, u32 data)
+static void __fsi_reg_mask_set(u32 __iomem *reg, u32 mask, u32 data)
 {
        u32 val = __fsi_reg_read(reg);
 
@@ -250,7 +250,7 @@ static u32 _fsi_master_read(struct fsi_master *master, u32 reg)
        unsigned long flags;
 
        spin_lock_irqsave(&master->lock, flags);
-       ret = __fsi_reg_read((u32)(master->base + reg));
+       ret = __fsi_reg_read(master->base + reg);
        spin_unlock_irqrestore(&master->lock, flags);
 
        return ret;
@@ -264,7 +264,7 @@ static void _fsi_master_mask_set(struct fsi_master *master,
        unsigned long flags;
 
        spin_lock_irqsave(&master->lock, flags);
-       __fsi_reg_mask_set((u32)(master->base + reg), mask, data);
+       __fsi_reg_mask_set(master->base + reg, mask, data);
        spin_unlock_irqrestore(&master->lock, flags);
 }
 
@@ -1285,7 +1285,7 @@ static int fsi_probe(struct platform_device *pdev)
        pm_runtime_enable(&pdev->dev);
        dev_set_drvdata(&pdev->dev, master);
 
-       ret = request_irq(irq, &fsi_interrupt, IRQF_DISABLED,
+       ret = request_irq(irq, &fsi_interrupt, 0,
                          id_entry->name, master);
        if (ret) {
                dev_err(&pdev->dev, "irq request err\n");
index 917d3ceadc9d984ca82bb8f635de98333b4f6fe5..c62ae689c4a157c4373d6957af42d16fcd4dbe29 100644 (file)
 extern struct snd_soc_dai_driver sh4_hac_dai[2];
 extern struct snd_soc_platform_driver sh7760_soc_platform;
 
-static int machine_init(struct snd_soc_pcm_runtime *rtd)
-{
-       snd_soc_dapm_sync(&rtd->codec->dapm);
-       return 0;
-}
-
 static struct snd_soc_dai_link sh7760_ac97_dai = {
        .name = "AC97",
        .stream_name = "AC97 HiFi",
@@ -33,7 +27,6 @@ static struct snd_soc_dai_link sh7760_ac97_dai = {
        .codec_dai_name = "ac97-hifi",
        .platform_name = "sh7760-pcm-audio",
        .codec_name = "ac97-codec",
-       .init = machine_init,
        .ops = NULL,
 };
 
index 05192d97b377f586e5eab56f0e38ec841d35378d..e0c621c0553b5606afab9530628c94b994f9e847 100644 (file)
@@ -342,7 +342,7 @@ static struct snd_soc_dai_ops ssi_dai_ops = {
        .set_fmt        = ssi_set_fmt,
 };
 
-struct snd_soc_dai_driver sh4_ssi_dai[] = {
+static struct snd_soc_dai_driver sh4_ssi_dai[] = {
 {
        .name                   = "ssi-dai.0",
        .playback = {
index 20b7f3b003a33d377991044fd4e2d71efba62353..143c705ac27b82fbefd61144be79089511c1bfd3 100644 (file)
@@ -548,9 +548,6 @@ static inline int snd_soc_lzo_get_blkpos(struct snd_soc_codec *codec,
 
 static inline int snd_soc_lzo_get_blksize(struct snd_soc_codec *codec)
 {
-       const struct snd_soc_codec_driver *codec_drv;
-
-       codec_drv = codec->driver;
        return DIV_ROUND_UP(codec->reg_size, snd_soc_lzo_block_count());
 }
 
@@ -868,10 +865,6 @@ static int snd_soc_flat_cache_exit(struct snd_soc_codec *codec)
 
 static int snd_soc_flat_cache_init(struct snd_soc_codec *codec)
 {
-       const struct snd_soc_codec_driver *codec_drv;
-
-       codec_drv = codec->driver;
-
        if (codec->reg_def_copy)
                codec->reg_cache = kmemdup(codec->reg_def_copy,
                                           codec->reg_size, GFP_KERNEL);
index ef69f5a0270991e7990055b109282cd6e66afa08..a5d3685a5d38049313391ddb8e174edd9c28a21b 100644 (file)
@@ -106,7 +106,7 @@ static int format_register_str(struct snd_soc_codec *codec,
        if (wordsize + regsize + 2 + 1 != len)
                return -EINVAL;
 
-       ret = snd_soc_read(codec , reg);
+       ret = snd_soc_read(codec, reg);
        if (ret < 0) {
                memset(regbuf, 'X', regsize);
                regbuf[regsize] = '\0';
@@ -144,7 +144,7 @@ static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf,
                step = codec->driver->reg_cache_step;
 
        for (i = 0; i < codec->driver->reg_cache_size; i += step) {
-               if (codec->readable_register && !codec->readable_register(codec, i))
+               if (!snd_soc_codec_readable_register(codec, i))
                        continue;
                if (codec->driver->display_register) {
                        count += codec->driver->display_register(codec, buf + count,
@@ -245,7 +245,6 @@ static ssize_t codec_reg_write_file(struct file *file,
        size_t buf_size;
        char *start = buf;
        unsigned long reg, value;
-       int step = 1;
        struct snd_soc_codec *codec = file->private_data;
 
        buf_size = min(count, (sizeof(buf)-1));
@@ -253,9 +252,6 @@ static ssize_t codec_reg_write_file(struct file *file,
                return -EFAULT;
        buf[buf_size] = 0;
 
-       if (codec->driver->reg_cache_step)
-               step = codec->driver->reg_cache_step;
-
        while (*start == ' ')
                start++;
        reg = simple_strtoul(start, &start, 16);
@@ -957,6 +953,8 @@ static int soc_probe_codec(struct snd_soc_card *card,
                snd_soc_dapm_new_controls(&codec->dapm, driver->dapm_widgets,
                                          driver->num_dapm_widgets);
 
+       codec->dapm.idle_bias_off = driver->idle_bias_off;
+
        if (driver->probe) {
                ret = driver->probe(codec);
                if (ret < 0) {
@@ -1057,6 +1055,9 @@ static int soc_post_component_init(struct snd_soc_card *card,
        }
        rtd->card = card;
 
+       /* Make sure all DAPM widgets are instantiated */
+       snd_soc_dapm_new_widgets(&codec->dapm);
+
        /* machine controls, routes and widgets are not prefixed */
        temp = codec->name_prefix;
        codec->name_prefix = NULL;
@@ -1072,9 +1073,6 @@ static int soc_post_component_init(struct snd_soc_card *card,
        }
        codec->name_prefix = temp;
 
-       /* Make sure all DAPM widgets are instantiated */
-       snd_soc_dapm_new_widgets(&codec->dapm);
-
        /* register the rtd device */
        rtd->codec = codec;
        rtd->dev.parent = card->dev;
@@ -1319,6 +1317,7 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card)
        struct snd_soc_codec *codec;
        struct snd_soc_codec_conf *codec_conf;
        enum snd_soc_compress_type compress_type;
+       struct snd_soc_dai_link *dai_link;
        int ret, i, order;
 
        mutex_lock(&card->mutex);
@@ -1431,6 +1430,28 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card)
                snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
                                        card->num_dapm_routes);
 
+       snd_soc_dapm_new_widgets(&card->dapm);
+
+       for (i = 0; i < card->num_links; i++) {
+               dai_link = &card->dai_link[i];
+
+               if (dai_link->dai_fmt) {
+                       ret = snd_soc_dai_set_fmt(card->rtd[i].codec_dai,
+                                                 dai_link->dai_fmt);
+                       if (ret != 0)
+                               dev_warn(card->rtd[i].codec_dai->dev,
+                                        "Failed to set DAI format: %d\n",
+                                        ret);
+
+                       ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai,
+                                                 dai_link->dai_fmt);
+                       if (ret != 0)
+                               dev_warn(card->rtd[i].cpu_dai->dev,
+                                        "Failed to set DAI format: %d\n",
+                                        ret);
+               }
+       }
+
        snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname),
                 "%s", card->name);
        snprintf(card->snd_card->longname, sizeof(card->snd_card->longname),
@@ -1459,6 +1480,8 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card)
                }
        }
 
+       snd_soc_dapm_new_widgets(&card->dapm);
+
        ret = snd_card_register(card->snd_card);
        if (ret < 0) {
                printk(KERN_ERR "asoc: failed to register soundcard for %s\n", card->name);
@@ -1479,6 +1502,7 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card)
 #endif
 
        card->instantiated = 1;
+       snd_soc_dapm_sync(&card->dapm);
        mutex_unlock(&card->mutex);
        return;
 
@@ -2229,7 +2253,8 @@ EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext);
  * @kcontrol: mixer control
  * @uinfo: control element information
  *
- * Callback to provide information about a single mixer control.
+ * Callback to provide information about a single mixer control, or a double
+ * mixer control that spans 2 registers.
  *
  * Returns 0 for success.
  */
@@ -2239,8 +2264,6 @@ int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
        struct soc_mixer_control *mc =
                (struct soc_mixer_control *)kcontrol->private_value;
        int platform_max;
-       unsigned int shift = mc->shift;
-       unsigned int rshift = mc->rshift;
 
        if (!mc->platform_max)
                mc->platform_max = mc->max;
@@ -2251,7 +2274,7 @@ int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
        else
                uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
 
-       uinfo->count = shift == rshift ? 1 : 2;
+       uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
        uinfo->value.integer.min = 0;
        uinfo->value.integer.max = platform_max;
        return 0;
@@ -2263,7 +2286,8 @@ EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
  * @kcontrol: mixer control
  * @ucontrol: control element information
  *
- * Callback to get the value of a single mixer control.
+ * Callback to get the value of a single mixer control, or a double mixer
+ * control that spans 2 registers.
  *
  * Returns 0 for success.
  */
@@ -2274,6 +2298,7 @@ int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
                (struct soc_mixer_control *)kcontrol->private_value;
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
        unsigned int reg = mc->reg;
+       unsigned int reg2 = mc->rreg;
        unsigned int shift = mc->shift;
        unsigned int rshift = mc->rshift;
        int max = mc->max;
@@ -2282,13 +2307,18 @@ int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
 
        ucontrol->value.integer.value[0] =
                (snd_soc_read(codec, reg) >> shift) & mask;
-       if (shift != rshift)
-               ucontrol->value.integer.value[1] =
-                       (snd_soc_read(codec, reg) >> rshift) & mask;
-       if (invert) {
+       if (invert)
                ucontrol->value.integer.value[0] =
                        max - ucontrol->value.integer.value[0];
-               if (shift != rshift)
+
+       if (snd_soc_volsw_is_stereo(mc)) {
+               if (reg == reg2)
+                       ucontrol->value.integer.value[1] =
+                               (snd_soc_read(codec, reg) >> rshift) & mask;
+               else
+                       ucontrol->value.integer.value[1] =
+                               (snd_soc_read(codec, reg2) >> shift) & mask;
+               if (invert)
                        ucontrol->value.integer.value[1] =
                                max - ucontrol->value.integer.value[1];
        }
@@ -2302,7 +2332,8 @@ EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
  * @kcontrol: mixer control
  * @ucontrol: control element information
  *
- * Callback to set the value of a single mixer control.
+ * Callback to set the value of a single mixer control, or a double mixer
+ * control that spans 2 registers.
  *
  * Returns 0 for success.
  */
@@ -2313,143 +2344,44 @@ int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
                (struct soc_mixer_control *)kcontrol->private_value;
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
        unsigned int reg = mc->reg;
+       unsigned int reg2 = mc->rreg;
        unsigned int shift = mc->shift;
        unsigned int rshift = mc->rshift;
        int max = mc->max;
        unsigned int mask = (1 << fls(max)) - 1;
        unsigned int invert = mc->invert;
-       unsigned int val, val2, val_mask;
+       int err;
+       bool type_2r = 0;
+       unsigned int val2 = 0;
+       unsigned int val, val_mask;
 
        val = (ucontrol->value.integer.value[0] & mask);
        if (invert)
                val = max - val;
        val_mask = mask << shift;
        val = val << shift;
-       if (shift != rshift) {
+       if (snd_soc_volsw_is_stereo(mc)) {
                val2 = (ucontrol->value.integer.value[1] & mask);
                if (invert)
                        val2 = max - val2;
-               val_mask |= mask << rshift;
-               val |= val2 << rshift;
-       }
-       return snd_soc_update_bits_locked(codec, reg, val_mask, val);
-}
-EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
-
-/**
- * snd_soc_info_volsw_2r - double mixer info callback
- * @kcontrol: mixer control
- * @uinfo: control element information
- *
- * Callback to provide information about a double mixer control that
- * spans 2 codec registers.
- *
- * Returns 0 for success.
- */
-int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
-       struct snd_ctl_elem_info *uinfo)
-{
-       struct soc_mixer_control *mc =
-               (struct soc_mixer_control *)kcontrol->private_value;
-       int platform_max;
-
-       if (!mc->platform_max)
-               mc->platform_max = mc->max;
-       platform_max = mc->platform_max;
-
-       if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume"))
-               uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
-       else
-               uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
-
-       uinfo->count = 2;
-       uinfo->value.integer.min = 0;
-       uinfo->value.integer.max = platform_max;
-       return 0;
-}
-EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r);
-
-/**
- * snd_soc_get_volsw_2r - double mixer get callback
- * @kcontrol: mixer control
- * @ucontrol: control element information
- *
- * Callback to get the value of a double mixer control that spans 2 registers.
- *
- * Returns 0 for success.
- */
-int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
-       struct snd_ctl_elem_value *ucontrol)
-{
-       struct soc_mixer_control *mc =
-               (struct soc_mixer_control *)kcontrol->private_value;
-       struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
-       unsigned int reg = mc->reg;
-       unsigned int reg2 = mc->rreg;
-       unsigned int shift = mc->shift;
-       int max = mc->max;
-       unsigned int mask = (1 << fls(max)) - 1;
-       unsigned int invert = mc->invert;
-
-       ucontrol->value.integer.value[0] =
-               (snd_soc_read(codec, reg) >> shift) & mask;
-       ucontrol->value.integer.value[1] =
-               (snd_soc_read(codec, reg2) >> shift) & mask;
-       if (invert) {
-               ucontrol->value.integer.value[0] =
-                       max - ucontrol->value.integer.value[0];
-               ucontrol->value.integer.value[1] =
-                       max - ucontrol->value.integer.value[1];
-       }
-
-       return 0;
-}
-EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r);
-
-/**
- * snd_soc_put_volsw_2r - double mixer set callback
- * @kcontrol: mixer control
- * @ucontrol: control element information
- *
- * Callback to set the value of a double mixer control that spans 2 registers.
- *
- * Returns 0 for success.
- */
-int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
-       struct snd_ctl_elem_value *ucontrol)
-{
-       struct soc_mixer_control *mc =
-               (struct soc_mixer_control *)kcontrol->private_value;
-       struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
-       unsigned int reg = mc->reg;
-       unsigned int reg2 = mc->rreg;
-       unsigned int shift = mc->shift;
-       int max = mc->max;
-       unsigned int mask = (1 << fls(max)) - 1;
-       unsigned int invert = mc->invert;
-       int err;
-       unsigned int val, val2, val_mask;
-
-       val_mask = mask << shift;
-       val = (ucontrol->value.integer.value[0] & mask);
-       val2 = (ucontrol->value.integer.value[1] & mask);
-
-       if (invert) {
-               val = max - val;
-               val2 = max - val2;
+               if (reg == reg2) {
+                       val_mask |= mask << rshift;
+                       val |= val2 << rshift;
+               } else {
+                       val2 = val2 << shift;
+                       type_2r = 1;
+               }
        }
-
-       val = val << shift;
-       val2 = val2 << shift;
-
        err = snd_soc_update_bits_locked(codec, reg, val_mask, val);
        if (err < 0)
                return err;
 
-       err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2);
+       if (type_2r)
+               err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2);
+
        return err;
 }
-EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r);
+EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
 
 /**
  * snd_soc_info_volsw_s8 - signed mixer info callback
@@ -2680,7 +2612,7 @@ int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
        if (dai->driver && dai->driver->ops->set_sysclk)
                return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir);
        else if (dai->codec && dai->codec->driver->set_sysclk)
-               return dai->codec->driver->set_sysclk(dai->codec, clk_id,
+               return dai->codec->driver->set_sysclk(dai->codec, clk_id, 0,
                                                      freq, dir);
        else
                return -EINVAL;
@@ -2691,16 +2623,18 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
  * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
  * @codec: CODEC
  * @clk_id: DAI specific clock ID
+ * @source: Source for the clock
  * @freq: new clock frequency in Hz
  * @dir: new clock direction - input/output.
  *
  * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
  */
 int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
-       unsigned int freq, int dir)
+                            int source, unsigned int freq, int dir)
 {
        if (codec->driver->set_sysclk)
-               return codec->driver->set_sysclk(codec, clk_id, freq, dir);
+               return codec->driver->set_sysclk(codec, clk_id, source,
+                                                freq, dir);
        else
                return -EINVAL;
 }
@@ -2895,6 +2829,7 @@ int snd_soc_register_card(struct snd_soc_card *card)
                card->rtd[i].dai_link = &card->dai_link[i];
 
        INIT_LIST_HEAD(&card->list);
+       INIT_LIST_HEAD(&card->dapm_dirty);
        card->instantiated = 0;
        mutex_init(&card->mutex);
 
@@ -3153,6 +3088,7 @@ int snd_soc_register_platform(struct device *dev,
        platform->driver = platform_drv;
        platform->dapm.dev = dev;
        platform->dapm.platform = platform;
+       platform->dapm.stream_event = platform_drv->stream_event;
 
        mutex_lock(&client_mutex);
        list_add(&platform->list, &platform_list);
@@ -3265,6 +3201,7 @@ int snd_soc_register_codec(struct device *dev,
        codec->dapm.dev = dev;
        codec->dapm.codec = codec;
        codec->dapm.seq_notifier = codec_drv->seq_notifier;
+       codec->dapm.stream_event = codec_drv->stream_event;
        codec->dev = dev;
        codec->driver = codec_drv;
        codec->num_dai = num_dai;
index d67c637557a784a2832676b814e71c0b1b7f1fc3..f42e8b9fb17db7baeabaf7152f81123773cdecd0 100644 (file)
@@ -48,6 +48,8 @@
 
 #include <trace/events/asoc.h>
 
+#define DAPM_UPDATE_STAT(widget, val) widget->dapm->card->dapm_stats.val++;
+
 /* dapm power sequences - make this per codec in the future */
 static int dapm_up_seq[] = {
        [snd_soc_dapm_pre] = 0,
@@ -117,6 +119,21 @@ static void pop_dbg(struct device *dev, u32 pop_time, const char *fmt, ...)
        kfree(buf);
 }
 
+static bool dapm_dirty_widget(struct snd_soc_dapm_widget *w)
+{
+       return !list_empty(&w->dirty);
+}
+
+void dapm_mark_dirty(struct snd_soc_dapm_widget *w, const char *reason)
+{
+       if (!dapm_dirty_widget(w)) {
+               dev_vdbg(w->dapm->dev, "Marking %s dirty due to %s\n",
+                        w->name, reason);
+               list_add_tail(&w->dirty, &w->dapm->card->dapm_dirty);
+       }
+}
+EXPORT_SYMBOL_GPL(dapm_mark_dirty);
+
 /* create a new dapm widget */
 static inline struct snd_soc_dapm_widget *dapm_cnew_widget(
        const struct snd_soc_dapm_widget *_widget)
@@ -316,7 +333,7 @@ static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
                }
        }
        break;
-       /* does not effect routing - always connected */
+       /* does not affect routing - always connected */
        case snd_soc_dapm_pga:
        case snd_soc_dapm_out_drv:
        case snd_soc_dapm_output:
@@ -328,13 +345,13 @@ static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
        case snd_soc_dapm_supply:
        case snd_soc_dapm_aif_in:
        case snd_soc_dapm_aif_out:
-               p->connect = 1;
-       break;
-       /* does effect routing - dynamically connected */
        case snd_soc_dapm_hp:
        case snd_soc_dapm_mic:
        case snd_soc_dapm_spk:
        case snd_soc_dapm_line:
+               p->connect = 1;
+       break;
+       /* does affect routing - dynamically connected */
        case snd_soc_dapm_pre:
        case snd_soc_dapm_post:
                p->connect = 0;
@@ -443,6 +460,11 @@ static int dapm_new_mixer(struct snd_soc_dapm_widget *w)
                        if (path->name != (char *)w->kcontrol_news[i].name)
                                continue;
 
+                       if (w->kcontrols[i]) {
+                               path->kcontrol = w->kcontrols[i];
+                               continue;
+                       }
+
                        wlistsize = sizeof(struct snd_soc_dapm_widget_list) +
                                    sizeof(struct snd_soc_dapm_widget *),
                        wlist = kzalloc(wlistsize, GFP_KERNEL);
@@ -579,8 +601,8 @@ static int dapm_new_mux(struct snd_soc_dapm_widget *w)
                                        name + prefix_len, prefix);
                ret = snd_ctl_add(card, kcontrol);
                if (ret < 0) {
-                       dev_err(dapm->dev,
-                               "asoc: failed to add kcontrol %s\n", w->name);
+                       dev_err(dapm->dev, "failed to add kcontrol %s: %d\n",
+                               w->name, ret);
                        kfree(wlist);
                        return ret;
                }
@@ -644,30 +666,45 @@ static int is_connected_output_ep(struct snd_soc_dapm_widget *widget)
        struct snd_soc_dapm_path *path;
        int con = 0;
 
+       if (widget->outputs >= 0)
+               return widget->outputs;
+
+       DAPM_UPDATE_STAT(widget, path_checks);
+
        if (widget->id == snd_soc_dapm_supply)
                return 0;
 
        switch (widget->id) {
        case snd_soc_dapm_adc:
        case snd_soc_dapm_aif_out:
-               if (widget->active)
-                       return snd_soc_dapm_suspend_check(widget);
+               if (widget->active) {
+                       widget->outputs = snd_soc_dapm_suspend_check(widget);
+                       return widget->outputs;
+               }
        default:
                break;
        }
 
        if (widget->connected) {
                /* connected pin ? */
-               if (widget->id == snd_soc_dapm_output && !widget->ext)
-                       return snd_soc_dapm_suspend_check(widget);
+               if (widget->id == snd_soc_dapm_output && !widget->ext) {
+                       widget->outputs = snd_soc_dapm_suspend_check(widget);
+                       return widget->outputs;
+               }
 
                /* connected jack or spk ? */
-               if (widget->id == snd_soc_dapm_hp || widget->id == snd_soc_dapm_spk ||
-                   (widget->id == snd_soc_dapm_line && !list_empty(&widget->sources)))
-                       return snd_soc_dapm_suspend_check(widget);
+               if (widget->id == snd_soc_dapm_hp ||
+                   widget->id == snd_soc_dapm_spk ||
+                   (widget->id == snd_soc_dapm_line &&
+                    !list_empty(&widget->sources))) {
+                       widget->outputs = snd_soc_dapm_suspend_check(widget);
+                       return widget->outputs;
+               }
        }
 
        list_for_each_entry(path, &widget->sinks, list_source) {
+               DAPM_UPDATE_STAT(widget, neighbour_checks);
+
                if (path->weak)
                        continue;
 
@@ -680,6 +717,8 @@ static int is_connected_output_ep(struct snd_soc_dapm_widget *widget)
                }
        }
 
+       widget->outputs = con;
+
        return con;
 }
 
@@ -692,6 +731,11 @@ static int is_connected_input_ep(struct snd_soc_dapm_widget *widget)
        struct snd_soc_dapm_path *path;
        int con = 0;
 
+       if (widget->inputs >= 0)
+               return widget->inputs;
+
+       DAPM_UPDATE_STAT(widget, path_checks);
+
        if (widget->id == snd_soc_dapm_supply)
                return 0;
 
@@ -699,28 +743,40 @@ static int is_connected_input_ep(struct snd_soc_dapm_widget *widget)
        switch (widget->id) {
        case snd_soc_dapm_dac:
        case snd_soc_dapm_aif_in:
-               if (widget->active)
-                       return snd_soc_dapm_suspend_check(widget);
+               if (widget->active) {
+                       widget->inputs = snd_soc_dapm_suspend_check(widget);
+                       return widget->inputs;
+               }
        default:
                break;
        }
 
        if (widget->connected) {
                /* connected pin ? */
-               if (widget->id == snd_soc_dapm_input && !widget->ext)
-                       return snd_soc_dapm_suspend_check(widget);
+               if (widget->id == snd_soc_dapm_input && !widget->ext) {
+                       widget->inputs = snd_soc_dapm_suspend_check(widget);
+                       return widget->inputs;
+               }
 
                /* connected VMID/Bias for lower pops */
-               if (widget->id == snd_soc_dapm_vmid)
-                       return snd_soc_dapm_suspend_check(widget);
+               if (widget->id == snd_soc_dapm_vmid) {
+                       widget->inputs = snd_soc_dapm_suspend_check(widget);
+                       return widget->inputs;
+               }
 
                /* connected jack ? */
                if (widget->id == snd_soc_dapm_mic ||
-                   (widget->id == snd_soc_dapm_line && !list_empty(&widget->sinks)))
-                       return snd_soc_dapm_suspend_check(widget);
+                   (widget->id == snd_soc_dapm_line &&
+                    !list_empty(&widget->sinks))) {
+                       widget->inputs = snd_soc_dapm_suspend_check(widget);
+                       return widget->inputs;
+               }
+
        }
 
        list_for_each_entry(path, &widget->sources, list_sink) {
+               DAPM_UPDATE_STAT(widget, neighbour_checks);
+
                if (path->weak)
                        continue;
 
@@ -733,6 +789,8 @@ static int is_connected_input_ep(struct snd_soc_dapm_widget *widget)
                }
        }
 
+       widget->inputs = con;
+
        return con;
 }
 
@@ -756,12 +814,29 @@ int dapm_reg_event(struct snd_soc_dapm_widget *w,
 }
 EXPORT_SYMBOL_GPL(dapm_reg_event);
 
+static int dapm_widget_power_check(struct snd_soc_dapm_widget *w)
+{
+       if (w->power_checked)
+               return w->new_power;
+
+       if (w->force)
+               w->new_power = 1;
+       else
+               w->new_power = w->power_check(w);
+
+       w->power_checked = true;
+
+       return w->new_power;
+}
+
 /* Generic check to see if a widget should be powered.
  */
 static int dapm_generic_check_power(struct snd_soc_dapm_widget *w)
 {
        int in, out;
 
+       DAPM_UPDATE_STAT(w, power_checks);
+
        in = is_connected_input_ep(w);
        dapm_clear_walk(w->dapm);
        out = is_connected_output_ep(w);
@@ -774,6 +849,8 @@ static int dapm_adc_check_power(struct snd_soc_dapm_widget *w)
 {
        int in;
 
+       DAPM_UPDATE_STAT(w, power_checks);
+
        if (w->active) {
                in = is_connected_input_ep(w);
                dapm_clear_walk(w->dapm);
@@ -788,6 +865,8 @@ static int dapm_dac_check_power(struct snd_soc_dapm_widget *w)
 {
        int out;
 
+       DAPM_UPDATE_STAT(w, power_checks);
+
        if (w->active) {
                out = is_connected_output_ep(w);
                dapm_clear_walk(w->dapm);
@@ -801,10 +880,13 @@ static int dapm_dac_check_power(struct snd_soc_dapm_widget *w)
 static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
 {
        struct snd_soc_dapm_path *path;
-       int power = 0;
+
+       DAPM_UPDATE_STAT(w, power_checks);
 
        /* Check if one of our outputs is connected */
        list_for_each_entry(path, &w->sinks, list_source) {
+               DAPM_UPDATE_STAT(w, neighbour_checks);
+
                if (path->weak)
                        continue;
 
@@ -815,21 +897,18 @@ static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
                if (!path->sink)
                        continue;
 
-               if (path->sink->force) {
-                       power = 1;
-                       break;
-               }
-
-               if (path->sink->power_check &&
-                   path->sink->power_check(path->sink)) {
-                       power = 1;
-                       break;
-               }
+               if (dapm_widget_power_check(path->sink))
+                       return 1;
        }
 
        dapm_clear_walk(w->dapm);
 
-       return power;
+       return 0;
+}
+
+static int dapm_always_on_check_power(struct snd_soc_dapm_widget *w)
+{
+       return 1;
 }
 
 static int dapm_seq_compare(struct snd_soc_dapm_widget *a,
@@ -1172,6 +1251,85 @@ static void dapm_post_sequence_async(void *data, async_cookie_t cookie)
        }
 }
 
+static void dapm_widget_set_peer_power(struct snd_soc_dapm_widget *peer,
+                                      bool power, bool connect)
+{
+       /* If a connection is being made or broken then that update
+        * will have marked the peer dirty, otherwise the widgets are
+        * not connected and this update has no impact. */
+       if (!connect)
+               return;
+
+       /* If the peer is already in the state we're moving to then we
+        * won't have an impact on it. */
+       if (power != peer->power)
+               dapm_mark_dirty(peer, "peer state change");
+}
+
+static void dapm_widget_set_power(struct snd_soc_dapm_widget *w, bool power,
+                                 struct list_head *up_list,
+                                 struct list_head *down_list)
+{
+       struct snd_soc_dapm_path *path;
+
+       if (w->power == power)
+               return;
+
+       trace_snd_soc_dapm_widget_power(w, power);
+
+       /* If we changed our power state perhaps our neigbours changed
+        * also.
+        */
+       list_for_each_entry(path, &w->sources, list_sink) {
+               if (path->source) {
+                       dapm_widget_set_peer_power(path->source, power,
+                                                  path->connect);
+               }
+       }
+       switch (w->id) {
+       case snd_soc_dapm_supply:
+               /* Supplies can't affect their outputs, only their inputs */
+               break;
+       default:
+               list_for_each_entry(path, &w->sinks, list_source) {
+                       if (path->sink) {
+                               dapm_widget_set_peer_power(path->sink, power,
+                                                          path->connect);
+                       }
+               }
+               break;
+       }
+
+       if (power)
+               dapm_seq_insert(w, up_list, true);
+       else
+               dapm_seq_insert(w, down_list, false);
+
+       w->power = power;
+}
+
+static void dapm_power_one_widget(struct snd_soc_dapm_widget *w,
+                                 struct list_head *up_list,
+                                 struct list_head *down_list)
+{
+       int power;
+
+       switch (w->id) {
+       case snd_soc_dapm_pre:
+               dapm_seq_insert(w, down_list, false);
+               break;
+       case snd_soc_dapm_post:
+               dapm_seq_insert(w, up_list, true);
+               break;
+
+       default:
+               power = dapm_widget_power_check(w);
+
+               dapm_widget_set_power(w, power, up_list, down_list);
+               break;
+       }
+}
+
 /*
  * Scan each dapm widget for complete audio path.
  * A complete path is a route that has valid endpoints i.e.:-
@@ -1190,7 +1348,6 @@ static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
        LIST_HEAD(down_list);
        LIST_HEAD(async_domain);
        enum snd_soc_bias_level bias;
-       int power;
 
        trace_snd_soc_dapm_start(card);
 
@@ -1203,61 +1360,47 @@ static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
                }
        }
 
-       /* Check which widgets we need to power and store them in
-        * lists indicating if they should be powered up or down.
-        */
+       memset(&card->dapm_stats, 0, sizeof(card->dapm_stats));
+
        list_for_each_entry(w, &card->widgets, list) {
-               switch (w->id) {
-               case snd_soc_dapm_pre:
-                       dapm_seq_insert(w, &down_list, false);
-                       break;
-               case snd_soc_dapm_post:
-                       dapm_seq_insert(w, &up_list, true);
-                       break;
+               w->power_checked = false;
+               w->inputs = -1;
+               w->outputs = -1;
+       }
 
-               default:
-                       if (!w->power_check)
-                               continue;
+       /* Check which widgets we need to power and store them in
+        * lists indicating if they should be powered up or down.  We
+        * only check widgets that have been flagged as dirty but note
+        * that new widgets may be added to the dirty list while we
+        * iterate.
+        */
+       list_for_each_entry(w, &card->dapm_dirty, dirty) {
+               dapm_power_one_widget(w, &up_list, &down_list);
+       }
 
-                       if (!w->force)
-                               power = w->power_check(w);
-                       else
-                               power = 1;
+       list_for_each_entry(w, &card->widgets, list) {
+               list_del_init(&w->dirty);
 
-                       if (power) {
-                               d = w->dapm;
+               if (w->power) {
+                       d = w->dapm;
 
-                               /* Supplies and micbiases only bring
-                                * the context up to STANDBY as unless
-                                * something else is active and
-                                * passing audio they generally don't
-                                * require full power.
-                                */
-                               switch (w->id) {
-                               case snd_soc_dapm_supply:
-                               case snd_soc_dapm_micbias:
-                                       if (d->target_bias_level < SND_SOC_BIAS_STANDBY)
-                                               d->target_bias_level = SND_SOC_BIAS_STANDBY;
-                                       break;
-                               default:
-                                       d->target_bias_level = SND_SOC_BIAS_ON;
-                                       break;
-                               }
+                       /* Supplies and micbiases only bring the
+                        * context up to STANDBY as unless something
+                        * else is active and passing audio they
+                        * generally don't require full power.
+                        */
+                       switch (w->id) {
+                       case snd_soc_dapm_supply:
+                       case snd_soc_dapm_micbias:
+                               if (d->target_bias_level < SND_SOC_BIAS_STANDBY)
+                                       d->target_bias_level = SND_SOC_BIAS_STANDBY;
+                               break;
+                       default:
+                               d->target_bias_level = SND_SOC_BIAS_ON;
+                               break;
                        }
-
-                       if (w->power == power)
-                               continue;
-
-                       trace_snd_soc_dapm_widget_power(w, power);
-
-                       if (power)
-                               dapm_seq_insert(w, &up_list, true);
-                       else
-                               dapm_seq_insert(w, &down_list, false);
-
-                       w->power = power;
-                       break;
                }
+
        }
 
        /* If there are no DAPM widgets then try to figure out power from the
@@ -1286,14 +1429,18 @@ static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
                }
        }
 
-       /* Force all contexts in the card to the same bias state */
+       /* Force all contexts in the card to the same bias state if
+        * they're not ground referenced.
+        */
        bias = SND_SOC_BIAS_OFF;
        list_for_each_entry(d, &card->dapm_list, list)
                if (d->target_bias_level > bias)
                        bias = d->target_bias_level;
        list_for_each_entry(d, &card->dapm_list, list)
-               d->target_bias_level = bias;
+               if (!d->idle_bias_off)
+                       d->target_bias_level = bias;
 
+       trace_snd_soc_dapm_walk_done(card);
 
        /* Run all the bias changes in parallel */
        list_for_each_entry(d, &dapm->card->dapm_list, list)
@@ -1524,14 +1671,21 @@ static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
 
                found = 1;
                /* we now need to match the string in the enum to the path */
-               if (!(strcmp(path->name, e->texts[mux])))
+               if (!(strcmp(path->name, e->texts[mux]))) {
                        path->connect = 1; /* new connection */
-               else
+                       dapm_mark_dirty(path->source, "mux connection");
+               } else {
+                       if (path->connect)
+                               dapm_mark_dirty(path->source,
+                                               "mux disconnection");
                        path->connect = 0; /* old connection must be powered down */
+               }
        }
 
-       if (found)
+       if (found) {
+               dapm_mark_dirty(widget, "mux change");
                dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
+       }
 
        return 0;
 }
@@ -1556,11 +1710,13 @@ static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
                /* found, now check type */
                found = 1;
                path->connect = connect;
-               break;
+               dapm_mark_dirty(path->source, "mixer connection");
        }
 
-       if (found)
+       if (found) {
+               dapm_mark_dirty(widget, "mixer update");
                dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
+       }
 
        return 0;
 }
@@ -1704,6 +1860,7 @@ static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm,
        w->connected = status;
        if (status == 0)
                w->force = 0;
+       dapm_mark_dirty(w, "pin configuration");
 
        return 0;
 }
@@ -1719,6 +1876,13 @@ static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm,
  */
 int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
 {
+       /*
+        * Suppress early reports (eg, jacks syncing their state) to avoid
+        * silly DAPM runs during card startup.
+        */
+       if (!dapm->card || !dapm->card->instantiated)
+               return 0;
+
        return dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
 }
 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
@@ -2004,42 +2168,18 @@ int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm)
                case snd_soc_dapm_switch:
                case snd_soc_dapm_mixer:
                case snd_soc_dapm_mixer_named_ctl:
-                       w->power_check = dapm_generic_check_power;
                        dapm_new_mixer(w);
                        break;
                case snd_soc_dapm_mux:
                case snd_soc_dapm_virt_mux:
                case snd_soc_dapm_value_mux:
-                       w->power_check = dapm_generic_check_power;
                        dapm_new_mux(w);
                        break;
-               case snd_soc_dapm_adc:
-               case snd_soc_dapm_aif_out:
-                       w->power_check = dapm_adc_check_power;
-                       break;
-               case snd_soc_dapm_dac:
-               case snd_soc_dapm_aif_in:
-                       w->power_check = dapm_dac_check_power;
-                       break;
                case snd_soc_dapm_pga:
                case snd_soc_dapm_out_drv:
-                       w->power_check = dapm_generic_check_power;
                        dapm_new_pga(w);
                        break;
-               case snd_soc_dapm_input:
-               case snd_soc_dapm_output:
-               case snd_soc_dapm_micbias:
-               case snd_soc_dapm_spk:
-               case snd_soc_dapm_hp:
-               case snd_soc_dapm_mic:
-               case snd_soc_dapm_line:
-                       w->power_check = dapm_generic_check_power;
-                       break;
-               case snd_soc_dapm_supply:
-                       w->power_check = dapm_supply_check_power;
-               case snd_soc_dapm_vmid:
-               case snd_soc_dapm_pre:
-               case snd_soc_dapm_post:
+               default:
                        break;
                }
 
@@ -2056,6 +2196,7 @@ int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm)
 
                w->new = 1;
 
+               dapm_mark_dirty(w, "new widget");
                dapm_debugfs_add_widget(w);
        }
 
@@ -2530,6 +2671,44 @@ int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
        else
                snprintf(w->name, name_len, "%s", widget->name);
 
+       switch (w->id) {
+       case snd_soc_dapm_switch:
+       case snd_soc_dapm_mixer:
+       case snd_soc_dapm_mixer_named_ctl:
+               w->power_check = dapm_generic_check_power;
+               break;
+       case snd_soc_dapm_mux:
+       case snd_soc_dapm_virt_mux:
+       case snd_soc_dapm_value_mux:
+               w->power_check = dapm_generic_check_power;
+               break;
+       case snd_soc_dapm_adc:
+       case snd_soc_dapm_aif_out:
+               w->power_check = dapm_adc_check_power;
+               break;
+       case snd_soc_dapm_dac:
+       case snd_soc_dapm_aif_in:
+               w->power_check = dapm_dac_check_power;
+               break;
+       case snd_soc_dapm_pga:
+       case snd_soc_dapm_out_drv:
+       case snd_soc_dapm_input:
+       case snd_soc_dapm_output:
+       case snd_soc_dapm_micbias:
+       case snd_soc_dapm_spk:
+       case snd_soc_dapm_hp:
+       case snd_soc_dapm_mic:
+       case snd_soc_dapm_line:
+               w->power_check = dapm_generic_check_power;
+               break;
+       case snd_soc_dapm_supply:
+               w->power_check = dapm_supply_check_power;
+               break;
+       default:
+               w->power_check = dapm_always_on_check_power;
+               break;
+       }
+
        dapm->n_widgets++;
        w->dapm = dapm;
        w->codec = dapm->codec;
@@ -2537,6 +2716,7 @@ int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
        INIT_LIST_HEAD(&w->sources);
        INIT_LIST_HEAD(&w->sinks);
        INIT_LIST_HEAD(&w->list);
+       INIT_LIST_HEAD(&w->dirty);
        list_add(&w->list, &dapm->card->widgets);
 
        /* machine layer set ups unconnected pins and insertions */
@@ -2584,9 +2764,10 @@ static void soc_dapm_stream_event(struct snd_soc_dapm_context *dapm,
        {
                if (!w->sname || w->dapm != dapm)
                        continue;
-               dev_dbg(w->dapm->dev, "widget %s\n %s stream %s event %d\n",
+               dev_vdbg(w->dapm->dev, "widget %s\n %s stream %s event %d\n",
                        w->name, w->sname, stream, event);
                if (strstr(w->sname, stream)) {
+                       dapm_mark_dirty(w, "stream event");
                        switch(event) {
                        case SND_SOC_DAPM_STREAM_START:
                                w->active = 1;
@@ -2604,6 +2785,10 @@ static void soc_dapm_stream_event(struct snd_soc_dapm_context *dapm,
        }
 
        dapm_power_widgets(dapm, event);
+
+       /* do we need to notify any clients that DAPM stream is complete */
+       if (dapm->stream_event)
+               dapm->stream_event(dapm, event);
 }
 
 /**
@@ -2672,6 +2857,7 @@ int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
        dev_dbg(w->dapm->dev, "dapm: force enable pin %s\n", pin);
        w->connected = 1;
        w->force = 1;
+       dapm_mark_dirty(w, "force enable");
 
        return 0;
 }
index a62f7dd4ba96bcd266cd98e468d3248fe87ee096..dd89933e2c723c1d4f0b8b1dce46baaefdcf29b3 100644 (file)
 
 #include <linux/i2c.h>
 #include <linux/spi/spi.h>
+#include <linux/regmap.h>
 #include <sound/soc.h>
 
 #include <trace/events/asoc.h>
 
-#ifdef CONFIG_SPI_MASTER
-static int do_spi_write(void *control, const char *data, int len)
-{
-       struct spi_device *spi = control;
-       int ret;
-
-       ret = spi_write(spi, data, len);
-       if (ret < 0)
-               return ret;
-
-       return len;
-}
-#endif
-
-static int do_hw_write(struct snd_soc_codec *codec, unsigned int reg,
-                      unsigned int value, const void *data, int len)
+#ifdef CONFIG_REGMAP
+static int hw_write(struct snd_soc_codec *codec, unsigned int reg,
+                   unsigned int value)
 {
        int ret;
 
@@ -49,13 +37,7 @@ static int do_hw_write(struct snd_soc_codec *codec, unsigned int reg,
                return 0;
        }
 
-       ret = codec->hw_write(codec->control_data, data, len);
-       if (ret == len)
-               return 0;
-       if (ret < 0)
-               return ret;
-       else
-               return -EIO;
+       return regmap_write(codec->control_data, reg, value);
 }
 
 static unsigned int hw_read(struct snd_soc_codec *codec, unsigned int reg)
@@ -69,8 +51,11 @@ static unsigned int hw_read(struct snd_soc_codec *codec, unsigned int reg)
                if (codec->cache_only)
                        return -1;
 
-               BUG_ON(!codec->hw_read);
-               return codec->hw_read(codec, reg);
+               ret = regmap_read(codec->control_data, reg, &val);
+               if (ret == 0)
+                       return val;
+               else
+                       return -1;
        }
 
        ret = snd_soc_cache_read(codec, reg, &val);
@@ -79,202 +64,18 @@ static unsigned int hw_read(struct snd_soc_codec *codec, unsigned int reg)
        return val;
 }
 
-static int snd_soc_4_12_write(struct snd_soc_codec *codec, unsigned int reg,
-                             unsigned int value)
-{
-       u16 data;
-
-       data = cpu_to_be16((reg << 12) | (value & 0xffffff));
-
-       return do_hw_write(codec, reg, value, &data, 2);
-}
-
-static int snd_soc_7_9_write(struct snd_soc_codec *codec, unsigned int reg,
-                            unsigned int value)
-{
-       u16 data;
-
-       data = cpu_to_be16((reg << 9) | (value & 0x1ff));
-
-       return do_hw_write(codec, reg, value, &data, 2);
-}
-
-static int snd_soc_8_8_write(struct snd_soc_codec *codec, unsigned int reg,
-                            unsigned int value)
-{
-       u8 data[2];
-
-       reg &= 0xff;
-       data[0] = reg;
-       data[1] = value & 0xff;
-
-       return do_hw_write(codec, reg, value, data, 2);
-}
-
-static int snd_soc_8_16_write(struct snd_soc_codec *codec, unsigned int reg,
-                             unsigned int value)
-{
-       u8 data[3];
-       u16 val = cpu_to_be16(value);
-
-       data[0] = reg;
-       memcpy(&data[1], &val, sizeof(val));
-
-       return do_hw_write(codec, reg, value, data, 3);
-}
-
-#if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE))
-static unsigned int do_i2c_read(struct snd_soc_codec *codec,
-                               void *reg, int reglen,
-                               void *data, int datalen)
-{
-       struct i2c_msg xfer[2];
-       int ret;
-       struct i2c_client *client = codec->control_data;
-
-       /* Write register */
-       xfer[0].addr = client->addr;
-       xfer[0].flags = 0;
-       xfer[0].len = reglen;
-       xfer[0].buf = reg;
-
-       /* Read data */
-       xfer[1].addr = client->addr;
-       xfer[1].flags = I2C_M_RD;
-       xfer[1].len = datalen;
-       xfer[1].buf = data;
-
-       ret = i2c_transfer(client->adapter, xfer, 2);
-       if (ret == 2)
-               return 0;
-       else if (ret < 0)
-               return ret;
-       else
-               return -EIO;
-}
-#endif
-
-#if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE))
-static unsigned int snd_soc_8_8_read_i2c(struct snd_soc_codec *codec,
-                                        unsigned int r)
-{
-       u8 reg = r;
-       u8 data;
-       int ret;
-
-       ret = do_i2c_read(codec, &reg, 1, &data, 1);
-       if (ret < 0)
-               return 0;
-       return data;
-}
-#else
-#define snd_soc_8_8_read_i2c NULL
-#endif
-
-#if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE))
-static unsigned int snd_soc_8_16_read_i2c(struct snd_soc_codec *codec,
-                                         unsigned int r)
-{
-       u8 reg = r;
-       u16 data;
-       int ret;
-
-       ret = do_i2c_read(codec, &reg, 1, &data, 2);
-       if (ret < 0)
-               return 0;
-       return (data >> 8) | ((data & 0xff) << 8);
-}
-#else
-#define snd_soc_8_16_read_i2c NULL
-#endif
-
-#if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE))
-static unsigned int snd_soc_16_8_read_i2c(struct snd_soc_codec *codec,
-                                         unsigned int r)
-{
-       u16 reg = r;
-       u8 data;
-       int ret;
-
-       ret = do_i2c_read(codec, &reg, 2, &data, 1);
-       if (ret < 0)
-               return 0;
-       return data;
-}
-#else
-#define snd_soc_16_8_read_i2c NULL
-#endif
-
-#if defined(CONFIG_SPI_MASTER)
-static unsigned int snd_soc_16_8_read_spi(struct snd_soc_codec *codec,
-                                         unsigned int r)
-{
-       struct spi_device *spi = codec->control_data;
-
-       const u16 reg = cpu_to_be16(r | 0x100);
-       u8 data;
-       int ret;
-
-       ret = spi_write_then_read(spi, &reg, 2, &data, 1);
-       if (ret < 0)
-               return 0;
-       return data;
-}
-#else
-#define snd_soc_16_8_read_spi NULL
-#endif
-
-static int snd_soc_16_8_write(struct snd_soc_codec *codec, unsigned int reg,
-                             unsigned int value)
-{
-       u8 data[3];
-       u16 rval = cpu_to_be16(reg);
-
-       memcpy(data, &rval, sizeof(rval));
-       data[2] = value;
-
-       return do_hw_write(codec, reg, value, data, 3);
-}
-
-#if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE))
-static unsigned int snd_soc_16_16_read_i2c(struct snd_soc_codec *codec,
-                                          unsigned int r)
-{
-       u16 reg = cpu_to_be16(r);
-       u16 data;
-       int ret;
-
-       ret = do_i2c_read(codec, &reg, 2, &data, 2);
-       if (ret < 0)
-               return 0;
-       return be16_to_cpu(data);
-}
-#else
-#define snd_soc_16_16_read_i2c NULL
-#endif
-
-static int snd_soc_16_16_write(struct snd_soc_codec *codec, unsigned int reg,
-                              unsigned int value)
-{
-       u16 data[2];
-
-       data[0] = cpu_to_be16(reg);
-       data[1] = cpu_to_be16(value);
-
-       return do_hw_write(codec, reg, value, data, sizeof(data));
-}
-
 /* Primitive bulk write support for soc-cache.  The data pointed to by
- * `data' needs to already be in the form the hardware expects
- * including any leading register specific data.  Any data written
- * through this function will not go through the cache as it only
- * handles writing to volatile or out of bounds registers.
+ * `data' needs to already be in the form the hardware expects.  Any
+ * data written through this function will not go through the cache as
+ * it only handles writing to volatile or out of bounds registers.
+ *
+ * This is currently only supported for devices using the regmap API
+ * wrappers.
  */
-static int snd_soc_hw_bulk_write_raw(struct snd_soc_codec *codec, unsigned int reg,
+static int snd_soc_hw_bulk_write_raw(struct snd_soc_codec *codec,
+                                    unsigned int reg,
                                     const void *data, size_t len)
 {
-       int ret;
-
        /* To ensure that we don't get out of sync with the cache, check
         * whether the base register is volatile or if we've directly asked
         * to bypass the cache.  Out of bounds registers are considered
@@ -285,68 +86,9 @@ static int snd_soc_hw_bulk_write_raw(struct snd_soc_codec *codec, unsigned int r
            && reg < codec->driver->reg_cache_size)
                return -EINVAL;
 
-       switch (codec->control_type) {
-#if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE))
-       case SND_SOC_I2C:
-               ret = i2c_master_send(to_i2c_client(codec->dev), data, len);
-               break;
-#endif
-#if defined(CONFIG_SPI_MASTER)
-       case SND_SOC_SPI:
-               ret = spi_write(to_spi_device(codec->dev), data, len);
-               break;
-#endif
-       default:
-               BUG();
-       }
-
-       if (ret == len)
-               return 0;
-       if (ret < 0)
-               return ret;
-       else
-               return -EIO;
+       return regmap_raw_write(codec->control_data, reg, data, len);
 }
 
-static struct {
-       int addr_bits;
-       int data_bits;
-       int (*write)(struct snd_soc_codec *codec, unsigned int, unsigned int);
-       unsigned int (*read)(struct snd_soc_codec *, unsigned int);
-       unsigned int (*i2c_read)(struct snd_soc_codec *, unsigned int);
-       unsigned int (*spi_read)(struct snd_soc_codec *, unsigned int);
-} io_types[] = {
-       {
-               .addr_bits = 4, .data_bits = 12,
-               .write = snd_soc_4_12_write,
-       },
-       {
-               .addr_bits = 7, .data_bits = 9,
-               .write = snd_soc_7_9_write,
-       },
-       {
-               .addr_bits = 8, .data_bits = 8,
-               .write = snd_soc_8_8_write,
-               .i2c_read = snd_soc_8_8_read_i2c,
-       },
-       {
-               .addr_bits = 8, .data_bits = 16,
-               .write = snd_soc_8_16_write,
-               .i2c_read = snd_soc_8_16_read_i2c,
-       },
-       {
-               .addr_bits = 16, .data_bits = 8,
-               .write = snd_soc_16_8_write,
-               .i2c_read = snd_soc_16_8_read_i2c,
-               .spi_read = snd_soc_16_8_read_spi,
-       },
-       {
-               .addr_bits = 16, .data_bits = 16,
-               .write = snd_soc_16_16_write,
-               .i2c_read = snd_soc_16_16_read_i2c,
-       },
-};
-
 /**
  * snd_soc_codec_set_cache_io: Set up standard I/O functions.
  *
@@ -370,50 +112,51 @@ int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
                               int addr_bits, int data_bits,
                               enum snd_soc_control_type control)
 {
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(io_types); i++)
-               if (io_types[i].addr_bits == addr_bits &&
-                   io_types[i].data_bits == data_bits)
-                       break;
-       if (i == ARRAY_SIZE(io_types)) {
-               printk(KERN_ERR
-                      "No I/O functions for %d bit address %d bit data\n",
-                      addr_bits, data_bits);
-               return -EINVAL;
-       }
+       struct regmap_config config;
 
-       codec->write = io_types[i].write;
+       memset(&config, 0, sizeof(config));
+       codec->write = hw_write;
        codec->read = hw_read;
        codec->bulk_write_raw = snd_soc_hw_bulk_write_raw;
 
+       config.reg_bits = addr_bits;
+       config.val_bits = data_bits;
+
        switch (control) {
+#if defined(CONFIG_REGMAP_I2C) || defined(CONFIG_REGMAP_I2C_MODULE)
        case SND_SOC_I2C:
-#if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE))
-               codec->hw_write = (hw_write_t)i2c_master_send;
-#endif
-               if (io_types[i].i2c_read)
-                       codec->hw_read = io_types[i].i2c_read;
-
-               codec->control_data = container_of(codec->dev,
-                                                  struct i2c_client,
-                                                  dev);
+               codec->control_data = regmap_init_i2c(to_i2c_client(codec->dev),
+                                                     &config);
                break;
+#endif
 
+#if defined(CONFIG_REGMAP_SPI) || defined(CONFIG_REGMAP_SPI_MODULE)
        case SND_SOC_SPI:
-#ifdef CONFIG_SPI_MASTER
-               codec->hw_write = do_spi_write;
+               codec->control_data = regmap_init_spi(to_spi_device(codec->dev),
+                                                     &config);
+               break;
 #endif
-               if (io_types[i].spi_read)
-                       codec->hw_read = io_types[i].spi_read;
 
-               codec->control_data = container_of(codec->dev,
-                                                  struct spi_device,
-                                                  dev);
+       case SND_SOC_REGMAP:
+               /* Device has made its own regmap arrangements */
                break;
+
+       default:
+               return -EINVAL;
        }
 
+       if (IS_ERR(codec->control_data))
+               return PTR_ERR(codec->control_data);
+
        return 0;
 }
 EXPORT_SYMBOL_GPL(snd_soc_codec_set_cache_io);
-
+#else
+int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
+                              int addr_bits, int data_bits,
+                              enum snd_soc_control_type control)
+{
+       return -ENOTSUPP;
+}
+EXPORT_SYMBOL_GPL(snd_soc_codec_set_cache_io);
+#endif
index fa31d9c2abd8fe29c615f24f64b68f33bb33004f..52db96636290372b40ddffaf15f6888bdbcc67b1 100644 (file)
@@ -188,6 +188,8 @@ int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count,
                list_add(&(pins[i].list), &jack->pins);
        }
 
+       snd_soc_dapm_new_widgets(&jack->codec->card->dapm);
+
        /* Update to reflect the last reported status; canned jack
         * implementations are likely to set their state before the
         * card has an opportunity to associate pins.
index 2879c883eebc2161d0c1ff3fdc14e764cde9ac33..ee15337353fae5f2cf16f5ab86f94d13440dc6bd 100644 (file)
 #include <sound/soc.h>
 #include <sound/initval.h>
 
-static DEFINE_MUTEX(pcm_mutex);
-
-static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream)
+static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream,
+                                       struct snd_soc_dai *soc_dai)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-       struct snd_soc_dai *codec_dai = rtd->codec_dai;
        int ret;
 
-       if (!codec_dai->driver->symmetric_rates &&
-           !cpu_dai->driver->symmetric_rates &&
+       if (!soc_dai->driver->symmetric_rates &&
            !rtd->dai_link->symmetric_rates)
                return 0;
 
@@ -45,19 +41,19 @@ static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream)
         * the second can need to get its constraints before the first has
         * picked a rate.  Complain and allow the application to carry on.
         */
-       if (!rtd->rate) {
-               dev_warn(&rtd->dev,
+       if (!soc_dai->rate) {
+               dev_warn(soc_dai->dev,
                         "Not enforcing symmetric_rates due to race\n");
                return 0;
        }
 
-       dev_dbg(&rtd->dev, "Symmetry forces %dHz rate\n", rtd->rate);
+       dev_dbg(soc_dai->dev, "Symmetry forces %dHz rate\n", soc_dai->rate);
 
        ret = snd_pcm_hw_constraint_minmax(substream->runtime,
                                           SNDRV_PCM_HW_PARAM_RATE,
-                                          rtd->rate, rtd->rate);
+                                          soc_dai->rate, soc_dai->rate);
        if (ret < 0) {
-               dev_err(&rtd->dev,
+               dev_err(soc_dai->dev,
                        "Unable to apply rate symmetry constraint: %d\n", ret);
                return ret;
        }
@@ -187,8 +183,14 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
        }
 
        /* Symmetry only applies if we've already got an active stream. */
-       if (cpu_dai->active || codec_dai->active) {
-               ret = soc_pcm_apply_symmetry(substream);
+       if (cpu_dai->active) {
+               ret = soc_pcm_apply_symmetry(substream, cpu_dai);
+               if (ret != 0)
+                       goto config_err;
+       }
+
+       if (codec_dai->active) {
+               ret = soc_pcm_apply_symmetry(substream, codec_dai);
                if (ret != 0)
                        goto config_err;
        }
@@ -290,8 +292,12 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)
        codec_dai->active--;
        codec->active--;
 
-       if (!cpu_dai->active && !codec_dai->active)
-               rtd->rate = 0;
+       /* clear the corresponding DAIs rate when inactive */
+       if (!cpu_dai->active)
+               cpu_dai->rate = 0;
+
+       if (!codec_dai->active)
+               codec_dai->rate = 0;
 
        /* Muting the DAC suppresses artifacts caused during digital
         * shutdown, for example from stopping clocks.
@@ -313,10 +319,17 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)
        cpu_dai->runtime = NULL;
 
        if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
-               /* start delayed pop wq here for playback streams */
-               codec_dai->pop_wait = 1;
-               schedule_delayed_work(&rtd->delayed_work,
-                       msecs_to_jiffies(rtd->pmdown_time));
+               if (unlikely(codec->ignore_pmdown_time)) {
+                       /* powered down playback stream now */
+                       snd_soc_dapm_stream_event(rtd,
+                               codec_dai->driver->playback.stream_name,
+                               SND_SOC_DAPM_STREAM_STOP);
+               } else {
+                       /* start delayed pop wq here for playback streams */
+                       codec_dai->pop_wait = 1;
+                       schedule_delayed_work(&rtd->delayed_work,
+                               msecs_to_jiffies(rtd->pmdown_time));
+               }
        } else {
                /* capture streams can be powered down now */
                snd_soc_dapm_stream_event(rtd,
@@ -449,7 +462,9 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
                }
        }
 
-       rtd->rate = params_rate(params);
+       /* store the rate for each DAIs */
+       cpu_dai->rate = params_rate(params);
+       codec_dai->rate = params_rate(params);
 
 out:
        mutex_unlock(&rtd->pcm_mutex);
index 9f24ef73f2cb3e689e21f0134197e41b8b0e5d7a..3b55a44146afc419c99fedd7d834dd826bd738e8 100644 (file)
@@ -212,7 +212,7 @@ err_release:
        release_mem_region(res->start, resource_size(res));
 err_free:
        kfree(das);
-       das = 0;
+       das = NULL;
 exit:
        return ret;
 }
@@ -234,7 +234,7 @@ static int __devexit tegra_das_remove(struct platform_device *pdev)
        release_mem_region(res->start, resource_size(res));
 
        kfree(das);
-       das = 0;
+       das = NULL;
 
        return 0;
 }
index f36b9969cfeceb1ca9a14054e67472ea109fbc18..6728fab8c411f05a4a7c10032ba9d0e87aa04c3b 100644 (file)
@@ -312,7 +312,7 @@ static struct snd_soc_dai_ops tegra_i2s_dai_ops = {
        .trigger        = tegra_i2s_trigger,
 };
 
-struct snd_soc_dai_driver tegra_i2s_dai[] = {
+static struct snd_soc_dai_driver tegra_i2s_dai[] = {
        {
                .name = DRV_NAME ".0",
                .probe = tegra_i2s_probe,
index c7cfd96e991ef268bd7af9a43230f8197c1e617c..436def1dfa39fee8b988fcbab0f14a74f277a438 100644 (file)
@@ -367,7 +367,7 @@ static void tegra_pcm_free(struct snd_pcm *pcm)
        tegra_pcm_deallocate_dma_buffer(pcm, SNDRV_PCM_STREAM_PLAYBACK);
 }
 
-struct snd_soc_platform_driver tegra_pcm_platform = {
+static struct snd_soc_platform_driver tegra_pcm_platform = {
        .ops            = &tegra_pcm_ops,
        .pcm_new        = tegra_pcm_new,
        .pcm_free       = tegra_pcm_free,
index abe606b0a29ea6e2ef5ab44c4d1a2c0b4dd42e04..dd11d0c63474cd6fb8b2b19fea96e4ab07c42829 100644 (file)
@@ -127,7 +127,7 @@ static int tegra_spdif_hw_params(struct snd_pcm_substream *substream,
 {
        struct device *dev = substream->pcm->card->dev;
        struct tegra_spdif *spdif = snd_soc_dai_get_drvdata(dai);
-       int ret, srate, spdifclock;
+       int ret, spdifclock;
 
        spdif->reg_ctrl &= ~TEGRA_SPDIF_CTRL_PACK;
        spdif->reg_ctrl &= ~TEGRA_SPDIF_CTRL_BIT_MODE_MASK;
@@ -140,7 +140,6 @@ static int tegra_spdif_hw_params(struct snd_pcm_substream *substream,
                return -EINVAL;
        }
 
-       srate = params_rate(params);
        switch (params_rate(params)) {
        case 32000:
                spdifclock = 4096000;
@@ -232,7 +231,7 @@ static struct snd_soc_dai_ops tegra_spdif_dai_ops = {
        .trigger        = tegra_spdif_trigger,
 };
 
-struct snd_soc_dai_driver tegra_spdif_dai = {
+static struct snd_soc_dai_driver tegra_spdif_dai = {
        .name = DRV_NAME,
        .probe = tegra_spdif_probe,
        .playback = {
index be27f1d229af9df67fd8bb2dc269e3f2337b31a0..a81cf39257bf2ff8aa68df2b7a9ef408887f0ed7 100644 (file)
@@ -339,8 +339,6 @@ static int tegra_wm8903_init(struct snd_soc_pcm_runtime *rtd)
                snd_soc_dapm_nc_pin(dapm, "LINEOUTL");
        }
 
-       snd_soc_dapm_sync(dapm);
-
        return 0;
 }
 
index 8fc07e9adf2e0e41d1d6568e60930b1c65d79023..b3a7efa6d960c75eed9f764000eea0fd1f8d46fa 100644 (file)
@@ -124,8 +124,6 @@ static int trimslice_asoc_init(struct snd_soc_pcm_runtime *rtd)
        snd_soc_dapm_nc_pin(dapm, "RHPOUT");
        snd_soc_dapm_nc_pin(dapm, "MICIN");
 
-       snd_soc_dapm_sync(dapm);
-
        return 0;
 }
 
index 743d07b82c062033f5287a85537b175ef72976d5..a4e3f5501847ec640e2851ce4a786668044405eb 100644 (file)
@@ -201,7 +201,7 @@ static int __devinit txx9aclc_ac97_dev_probe(struct platform_device *pdev)
        if (!drvdata->base)
                return -EBUSY;
        err = devm_request_irq(&pdev->dev, irq, txx9aclc_ac97_irq,
-                              IRQF_DISABLED, dev_name(&pdev->dev), drvdata);
+                              0, dev_name(&pdev->dev), drvdata);
        if (err < 0)
                return err;
 
index 6770e7166be4b77ae3427cbd3aba16b3b4694489..9b5e283af51c68e2611dadbbaeae4cd9db9a9ea6 100644 (file)
@@ -62,7 +62,7 @@ static int __exit txx9aclc_generic_remove(struct platform_device *pdev)
 }
 
 static struct platform_driver txx9aclc_generic_driver = {
-       .remove = txx9aclc_generic_remove,
+       .remove = __exit_p(txx9aclc_generic_remove),
        .driver = {
                .name = "txx9aclc-generic",
                .owner = THIS_MODULE,
index ad7d4d7d923741d7b75852857db0e1fad15d67f1..f036776380b50d6d3d1f6d452a86a4ecfee3a2c5 100644 (file)
@@ -962,7 +962,7 @@ static int __devinit snd_amd7930_create(struct snd_card *card,
        amd7930_idle(amd);
 
        if (request_irq(irq, snd_amd7930_interrupt,
-                       IRQF_DISABLED | IRQF_SHARED, "amd7930", amd)) {
+                       IRQF_SHARED, "amd7930", amd)) {
                snd_printk(KERN_ERR "amd7930-%d: Unable to grab IRQ %d\n",
                           dev, irq);
                snd_amd7930_free(amd);
index 1e3ae3327dd3a65431b4a517ab5b340dac2ee6f7..07bcfe4d18a7a9c319fdd310f92afe5e6f160414 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <linux/firmware.h>
 #include <linux/bitrev.h>
+#include <linux/kernel.h>
 
 #include "firmware.h"
 #include "chip.h"
@@ -59,21 +60,19 @@ struct ihex_record {
        unsigned int txt_offset; /* current position in txt_data */
 };
 
-static u8 usb6fire_fw_ihex_nibble(const u8 n)
-{
-       if (n >= '0' && n <= '9')
-               return n - '0';
-       else if (n >= 'A' && n <= 'F')
-               return n - ('A' - 10);
-       else if (n >= 'a' && n <= 'f')
-               return n - ('a' - 10);
-       return 0;
-}
-
 static u8 usb6fire_fw_ihex_hex(const u8 *data, u8 *crc)
 {
-       u8 val = (usb6fire_fw_ihex_nibble(data[0]) << 4) |
-                       usb6fire_fw_ihex_nibble(data[1]);
+       u8 val = 0;
+       int hval;
+
+       hval = hex_to_bin(data[0]);
+       if (hval >= 0)
+               val |= (hval << 4);
+
+       hval = hex_to_bin(data[1]);
+       if (hval >= 0)
+               val |= hval;
+
        *crc += val;
        return val;
 }
index 8beb77563da25298c547c07636a494cca2f679dd..3efc21c3d67c610250a1d6fe3705f03e2a27c58a 100644 (file)
@@ -67,6 +67,7 @@ config SND_USB_CAIAQ
            * Native Instruments Guitar Rig mobile
            * Native Instruments Traktor Kontrol X1
            * Native Instruments Traktor Kontrol S4
+           * Native Instruments Maschine Controller
 
           To compile this driver as a module, choose M here: the module
           will be called snd-usb-caiaq.
@@ -85,6 +86,7 @@ config SND_USB_CAIAQ_INPUT
           * Native Instruments Kore Controller 2
           * Native Instruments Audio Kontrol 1
           * Native Instruments Traktor Kontrol S4
+          * Native Instruments Maschine Controller
 
 config SND_USB_US122L
        tristate "Tascam US-122L USB driver"
index cf9ed66445fad6e6d9ba145bb5a0076bc140e07c..ac256dc4c6bed1d0b4d4008c58f544f50ec04085 100644 (file)
@@ -3,16 +3,16 @@
 #
 
 snd-usb-audio-objs :=  card.o \
+                       clock.o \
+                       endpoint.o \
+                       format.o \
+                       helper.o \
                        mixer.o \
                        mixer_quirks.o \
+                       pcm.o \
                        proc.o \
                        quirks.o \
-                       format.o \
-                       endpoint.o \
-                       urb.o \
-                       pcm.o \
-                       helper.o \
-                       clock.o
+                       stream.o
 
 snd-usbmidi-lib-objs := midi.o
 
index 45bc4a2dc6f0dc8065aec1a518df9a8bc59c9201..3eb605bd95038ff6e4a596484747c5887c69208f 100644 (file)
@@ -50,7 +50,8 @@ MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2},"
                         "{Native Instruments, Session I/O},"
                         "{Native Instruments, GuitarRig mobile}"
                         "{Native Instruments, Traktor Kontrol X1}"
-                        "{Native Instruments, Traktor Kontrol S4}");
+                        "{Native Instruments, Traktor Kontrol S4}"
+                        "{Native Instruments, Maschine Controller}");
 
 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-max */
 static char* id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* Id for this card */
@@ -146,6 +147,11 @@ static struct usb_device_id snd_usb_id_table[] = {
                .idVendor =     USB_VID_NATIVEINSTRUMENTS,
                .idProduct =    USB_PID_TRAKTORAUDIO2
        },
+       {
+               .match_flags =  USB_DEVICE_ID_MATCH_DEVICE,
+               .idVendor =     USB_VID_NATIVEINSTRUMENTS,
+               .idProduct =    USB_PID_MASCHINECONTROLLER
+       },
        { /* terminator */ }
 };
 
index 3f9c6339ae90fa54dd41cad9920e8d60223ddcd6..562b0bff9c417d300521ab9838b6a1af271ee368 100644 (file)
@@ -18,6 +18,7 @@
 #define USB_PID_TRAKTORKONTROLX1       0x2305
 #define USB_PID_TRAKTORKONTROLS4       0xbaff
 #define USB_PID_TRAKTORAUDIO2          0x041d
+#define USB_PID_MASCHINECONTROLLER  0x0808
 
 #define EP1_BUFSIZE 64
 #define EP4_BUFSIZE 512
index a213813487bd77b02211597a8448a9dde44d32ef..26a121b42c3c15ef93dd38ead31ad4c79d325737 100644 (file)
@@ -67,6 +67,61 @@ static unsigned short keycode_kore[] = {
        KEY_BRL_DOT5
 };
 
+#define MASCHINE_BUTTONS   (42)
+#define MASCHINE_BUTTON(X) ((X) + BTN_MISC)
+#define MASCHINE_PADS      (16)
+#define MASCHINE_PAD(X)    ((X) + ABS_PRESSURE)
+
+static unsigned short keycode_maschine[] = {
+       MASCHINE_BUTTON(40), /* mute       */
+       MASCHINE_BUTTON(39), /* solo       */
+       MASCHINE_BUTTON(38), /* select     */
+       MASCHINE_BUTTON(37), /* duplicate  */
+       MASCHINE_BUTTON(36), /* navigate   */
+       MASCHINE_BUTTON(35), /* pad mode   */
+       MASCHINE_BUTTON(34), /* pattern    */
+       MASCHINE_BUTTON(33), /* scene      */
+       KEY_RESERVED, /* spacer */
+
+       MASCHINE_BUTTON(30), /* rec        */
+       MASCHINE_BUTTON(31), /* erase      */
+       MASCHINE_BUTTON(32), /* shift      */
+       MASCHINE_BUTTON(28), /* grid       */
+       MASCHINE_BUTTON(27), /* >          */
+       MASCHINE_BUTTON(26), /* <          */
+       MASCHINE_BUTTON(25), /* restart    */
+
+       MASCHINE_BUTTON(21), /* E          */
+       MASCHINE_BUTTON(22), /* F          */
+       MASCHINE_BUTTON(23), /* G          */
+       MASCHINE_BUTTON(24), /* H          */
+       MASCHINE_BUTTON(20), /* D          */
+       MASCHINE_BUTTON(19), /* C          */
+       MASCHINE_BUTTON(18), /* B          */
+       MASCHINE_BUTTON(17), /* A          */
+
+       MASCHINE_BUTTON(0),  /* control    */
+       MASCHINE_BUTTON(2),  /* browse     */
+       MASCHINE_BUTTON(4),  /* <          */
+       MASCHINE_BUTTON(6),  /* snap       */
+       MASCHINE_BUTTON(7),  /* autowrite  */
+       MASCHINE_BUTTON(5),  /* >          */
+       MASCHINE_BUTTON(3),  /* sampling   */
+       MASCHINE_BUTTON(1),  /* step       */
+
+       MASCHINE_BUTTON(15), /* 8 softkeys */
+       MASCHINE_BUTTON(14),
+       MASCHINE_BUTTON(13),
+       MASCHINE_BUTTON(12),
+       MASCHINE_BUTTON(11),
+       MASCHINE_BUTTON(10),
+       MASCHINE_BUTTON(9),
+       MASCHINE_BUTTON(8),
+
+       MASCHINE_BUTTON(16), /* note repeat */
+       MASCHINE_BUTTON(29)  /* play        */
+};
+
 #define KONTROLX1_INPUTS       (40)
 #define KONTROLS4_BUTTONS      (12 * 8)
 #define KONTROLS4_AXIS         (46)
@@ -218,6 +273,29 @@ static void snd_caiaq_input_read_erp(struct snd_usb_caiaqdev *dev,
                input_report_abs(input_dev, ABS_HAT3Y, i);
                input_sync(input_dev);
                break;
+
+       case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER):
+               /* 4 under the left screen */
+               input_report_abs(input_dev, ABS_HAT0X, decode_erp(buf[21], buf[20]));
+               input_report_abs(input_dev, ABS_HAT0Y, decode_erp(buf[15], buf[14]));
+               input_report_abs(input_dev, ABS_HAT1X, decode_erp(buf[9],  buf[8]));
+               input_report_abs(input_dev, ABS_HAT1Y, decode_erp(buf[3],  buf[2]));
+
+               /* 4 under the right screen */
+               input_report_abs(input_dev, ABS_HAT2X, decode_erp(buf[19], buf[18]));
+               input_report_abs(input_dev, ABS_HAT2Y, decode_erp(buf[13], buf[12]));
+               input_report_abs(input_dev, ABS_HAT3X, decode_erp(buf[7],  buf[6]));
+               input_report_abs(input_dev, ABS_HAT3Y, decode_erp(buf[1],  buf[0]));
+
+               /* volume */
+               input_report_abs(input_dev, ABS_RX, decode_erp(buf[17], buf[16]));
+               /* tempo */
+               input_report_abs(input_dev, ABS_RY, decode_erp(buf[11], buf[10]));
+               /* swing */
+               input_report_abs(input_dev, ABS_RZ, decode_erp(buf[5],  buf[4]));
+
+               input_sync(input_dev);
+               break;
        }
 }
 
@@ -400,6 +478,25 @@ static void snd_usb_caiaq_tks4_dispatch(struct snd_usb_caiaqdev *dev,
        input_sync(dev->input_dev);
 }
 
+#define MASCHINE_MSGBLOCK_SIZE 2
+
+static void snd_usb_caiaq_maschine_dispatch(struct snd_usb_caiaqdev *dev,
+                                       const unsigned char *buf,
+                                       unsigned int len)
+{
+       unsigned int i, pad_id;
+       uint16_t pressure;
+
+       for (i = 0; i < MASCHINE_PADS; i++) {
+               pressure = be16_to_cpu(buf[i * 2] << 8 | buf[(i * 2) + 1]);
+               pad_id = pressure >> 12;
+
+               input_report_abs(dev->input_dev, MASCHINE_PAD(pad_id), pressure & 0xfff);
+       }
+
+       input_sync(dev->input_dev);
+}
+
 static void snd_usb_caiaq_ep4_reply_dispatch(struct urb *urb)
 {
        struct snd_usb_caiaqdev *dev = urb->context;
@@ -425,6 +522,13 @@ static void snd_usb_caiaq_ep4_reply_dispatch(struct urb *urb)
        case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4):
                snd_usb_caiaq_tks4_dispatch(dev, buf, urb->actual_length);
                break;
+
+       case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER):
+               if (urb->actual_length < (MASCHINE_PADS * MASCHINE_MSGBLOCK_SIZE))
+                       goto requeue;
+
+               snd_usb_caiaq_maschine_dispatch(dev, buf, urb->actual_length);
+               break;
        }
 
 requeue:
@@ -444,6 +548,7 @@ static int snd_usb_caiaq_input_open(struct input_dev *idev)
        switch (dev->chip.usb_id) {
        case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
        case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4):
+       case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER):
                if (usb_submit_urb(dev->ep4_in_urb, GFP_KERNEL) != 0)
                        return -EIO;
                break;
@@ -462,6 +567,7 @@ static void snd_usb_caiaq_input_close(struct input_dev *idev)
        switch (dev->chip.usb_id) {
        case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
        case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4):
+       case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER):
                usb_kill_urb(dev->ep4_in_urb);
                break;
        }
@@ -652,6 +758,50 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev)
 
                break;
 
+       case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER):
+               input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
+               input->absbit[0] = BIT_MASK(ABS_HAT0X) | BIT_MASK(ABS_HAT0Y) |
+                       BIT_MASK(ABS_HAT1X) | BIT_MASK(ABS_HAT1Y) |
+                       BIT_MASK(ABS_HAT2X) | BIT_MASK(ABS_HAT2Y) |
+                       BIT_MASK(ABS_HAT3X) | BIT_MASK(ABS_HAT3Y) |
+                       BIT_MASK(ABS_RX) | BIT_MASK(ABS_RY) |
+                       BIT_MASK(ABS_RZ);
+
+               BUILD_BUG_ON(sizeof(dev->keycode) < sizeof(keycode_maschine));
+               memcpy(dev->keycode, keycode_maschine, sizeof(keycode_maschine));
+               input->keycodemax = ARRAY_SIZE(keycode_maschine);
+
+               for (i = 0; i < MASCHINE_PADS; i++) {
+                       input->absbit[0] |= MASCHINE_PAD(i);
+                       input_set_abs_params(input, MASCHINE_PAD(i), 0, 0xfff, 5, 10);
+               }
+
+               input_set_abs_params(input, ABS_HAT0X, 0, 999, 0, 10);
+               input_set_abs_params(input, ABS_HAT0Y, 0, 999, 0, 10);
+               input_set_abs_params(input, ABS_HAT1X, 0, 999, 0, 10);
+               input_set_abs_params(input, ABS_HAT1Y, 0, 999, 0, 10);
+               input_set_abs_params(input, ABS_HAT2X, 0, 999, 0, 10);
+               input_set_abs_params(input, ABS_HAT2Y, 0, 999, 0, 10);
+               input_set_abs_params(input, ABS_HAT3X, 0, 999, 0, 10);
+               input_set_abs_params(input, ABS_HAT3Y, 0, 999, 0, 10);
+               input_set_abs_params(input, ABS_RX, 0, 999, 0, 10);
+               input_set_abs_params(input, ABS_RY, 0, 999, 0, 10);
+               input_set_abs_params(input, ABS_RZ, 0, 999, 0, 10);
+
+               dev->ep4_in_urb = usb_alloc_urb(0, GFP_KERNEL);
+               if (!dev->ep4_in_urb) {
+                       ret = -ENOMEM;
+                       goto exit_free_idev;
+               }
+
+               usb_fill_bulk_urb(dev->ep4_in_urb, usb_dev,
+                                 usb_rcvbulkpipe(usb_dev, 0x4),
+                                 dev->ep4_in_buf, EP4_BUFSIZE,
+                                 snd_usb_caiaq_ep4_reply_dispatch, dev);
+
+               snd_usb_caiaq_set_auto_msg(dev, 1, 10, 5);
+               break;
+
        default:
                /* no input methods supported on this device */
                goto exit_free_idev;
@@ -664,15 +814,17 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev)
        for (i = 0; i < input->keycodemax; i++)
                __set_bit(dev->keycode[i], input->keybit);
 
+       dev->input_dev = input;
+
        ret = input_register_device(input);
        if (ret < 0)
                goto exit_free_idev;
 
-       dev->input_dev = input;
        return 0;
 
 exit_free_idev:
        input_free_device(input);
+       dev->input_dev = NULL;
        return ret;
 }
 
@@ -688,4 +840,3 @@ void snd_usb_caiaq_input_free(struct snd_usb_caiaqdev *dev)
        input_unregister_device(dev->input_dev);
        dev->input_dev = NULL;
 }
-
index 3068f043099a8112f4117f00653da738e88a638b..05c1aae0b010bc84e30a87e8ce5e511dea071dbe 100644 (file)
@@ -65,9 +65,9 @@
 #include "helper.h"
 #include "debug.h"
 #include "pcm.h"
-#include "urb.h"
 #include "format.h"
 #include "power.h"
+#include "stream.h"
 
 MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
 MODULE_DESCRIPTION("USB Audio");
@@ -185,7 +185,7 @@ static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int int
                return -EINVAL;
        }
 
-       if (! snd_usb_parse_audio_endpoints(chip, interface)) {
+       if (! snd_usb_parse_audio_interface(chip, interface)) {
                usb_set_interface(dev, interface, 0); /* reset the current interface */
                usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L);
                return -EINVAL;
index ae4251d5abf7bc9a1b9c15dc9d5d8e947627337a..a39edcc32a93f0986c87498de66ca37206b38915 100644 (file)
@@ -94,6 +94,8 @@ struct snd_usb_substream {
        spinlock_t lock;
 
        struct snd_urb_ops ops;         /* callbacks (must be filled at init) */
+       int last_frame_number;          /* stored frame number */
+       int last_delay;                 /* stored delay */
 };
 
 struct snd_usb_stream {
index 075195e8661a0f538343bc482db9e721b51dda18..379baad3d5ad548265c06b6e97ae490f4d2a2ed2 100644 (file)
@@ -91,7 +91,7 @@ static int uac_clock_selector_get_val(struct snd_usb_audio *chip, int selector_i
                              USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
                              UAC2_CX_CLOCK_SELECTOR << 8,
                              snd_usb_ctrl_intf(chip) | (selector_id << 8),
-                             &buf, sizeof(buf), 1000);
+                             &buf, sizeof(buf));
 
        if (ret < 0)
                return ret;
@@ -118,7 +118,7 @@ static bool uac_clock_source_is_valid(struct snd_usb_audio *chip, int source_id)
                              USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
                              UAC2_CS_CONTROL_CLOCK_VALID << 8,
                              snd_usb_ctrl_intf(chip) | (source_id << 8),
-                             &data, sizeof(data), 1000);
+                             &data, sizeof(data));
 
        if (err < 0) {
                snd_printk(KERN_WARNING "%s(): cannot get clock validity for id %d\n",
@@ -222,7 +222,7 @@ static int set_sample_rate_v1(struct snd_usb_audio *chip, int iface,
        if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR,
                                   USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_OUT,
                                   UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep,
-                                  data, sizeof(data), 1000)) < 0) {
+                                  data, sizeof(data))) < 0) {
                snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d to ep %#x\n",
                           dev->devnum, iface, fmt->altsetting, rate, ep);
                return err;
@@ -231,7 +231,7 @@ static int set_sample_rate_v1(struct snd_usb_audio *chip, int iface,
        if ((err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR,
                                   USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN,
                                   UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep,
-                                  data, sizeof(data), 1000)) < 0) {
+                                  data, sizeof(data))) < 0) {
                snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq at ep %#x\n",
                           dev->devnum, iface, fmt->altsetting, ep);
                return 0; /* some devices don't support reading */
@@ -273,7 +273,7 @@ static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface,
                                   USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
                                   UAC2_CS_CONTROL_SAM_FREQ << 8,
                                   snd_usb_ctrl_intf(chip) | (clock << 8),
-                                  data, sizeof(data), 1000)) < 0) {
+                                  data, sizeof(data))) < 0) {
                snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d (v2)\n",
                           dev->devnum, iface, fmt->altsetting, rate);
                return err;
@@ -283,7 +283,7 @@ static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface,
                                   USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
                                   UAC2_CS_CONTROL_SAM_FREQ << 8,
                                   snd_usb_ctrl_intf(chip) | (clock << 8),
-                                  data, sizeof(data), 1000)) < 0) {
+                                  data, sizeof(data))) < 0) {
                snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq (v2)\n",
                           dev->devnum, iface, fmt->altsetting);
                return err;
index 7d46e482375d1dce4247f9805d81b6fc1c6568ba..81c6edecd862356324f93c110aca9b88c9c2562c 100644 (file)
  *
  */
 
+#include <linux/gfp.h>
 #include <linux/init.h>
-#include <linux/slab.h>
 #include <linux/usb.h>
 #include <linux/usb/audio.h>
-#include <linux/usb/audio-v2.h>
 
 #include <sound/core.h>
 #include <sound/pcm.h>
 
 #include "usbaudio.h"
+#include "helper.h"
 #include "card.h"
-#include "proc.h"
-#include "quirks.h"
 #include "endpoint.h"
-#include "urb.h"
 #include "pcm.h"
-#include "helper.h"
-#include "format.h"
-#include "clock.h"
 
 /*
- * free a substream
+ * convert a sampling rate into our full speed format (fs/1000 in Q16.16)
+ * this will overflow at approx 524 kHz
  */
-static void free_substream(struct snd_usb_substream *subs)
+static inline unsigned get_usb_full_speed_rate(unsigned int rate)
 {
-       struct list_head *p, *n;
-
-       if (!subs->num_formats)
-               return; /* not initialized */
-       list_for_each_safe(p, n, &subs->fmt_list) {
-               struct audioformat *fp = list_entry(p, struct audioformat, list);
-               kfree(fp->rate_table);
-               kfree(fp);
-       }
-       kfree(subs->rate_list.list);
+       return ((rate << 13) + 62) / 125;
 }
 
+/*
+ * convert a sampling rate into USB high speed format (fs/8000 in Q16.16)
+ * this will overflow at approx 4 MHz
+ */
+static inline unsigned get_usb_high_speed_rate(unsigned int rate)
+{
+       return ((rate << 10) + 62) / 125;
+}
 
 /*
- * free a usb stream instance
+ * unlink active urbs.
  */
-static void snd_usb_audio_stream_free(struct snd_usb_stream *stream)
+static int deactivate_urbs(struct snd_usb_substream *subs, int force, int can_sleep)
 {
-       free_substream(&stream->substream[0]);
-       free_substream(&stream->substream[1]);
-       list_del(&stream->list);
-       kfree(stream);
+       struct snd_usb_audio *chip = subs->stream->chip;
+       unsigned int i;
+       int async;
+
+       subs->running = 0;
+
+       if (!force && subs->stream->chip->shutdown) /* to be sure... */
+               return -EBADFD;
+
+       async = !can_sleep && chip->async_unlink;
+
+       if (!async && in_interrupt())
+               return 0;
+
+       for (i = 0; i < subs->nurbs; i++) {
+               if (test_bit(i, &subs->active_mask)) {
+                       if (!test_and_set_bit(i, &subs->unlink_mask)) {
+                               struct urb *u = subs->dataurb[i].urb;
+                               if (async)
+                                       usb_unlink_urb(u);
+                               else
+                                       usb_kill_urb(u);
+                       }
+               }
+       }
+       if (subs->syncpipe) {
+               for (i = 0; i < SYNC_URBS; i++) {
+                       if (test_bit(i+16, &subs->active_mask)) {
+                               if (!test_and_set_bit(i+16, &subs->unlink_mask)) {
+                                       struct urb *u = subs->syncurb[i].urb;
+                                       if (async)
+                                               usb_unlink_urb(u);
+                                       else
+                                               usb_kill_urb(u);
+                               }
+                       }
+               }
+       }
+       return 0;
 }
 
-static void snd_usb_audio_pcm_free(struct snd_pcm *pcm)
+
+/*
+ * release a urb data
+ */
+static void release_urb_ctx(struct snd_urb_ctx *u)
 {
-       struct snd_usb_stream *stream = pcm->private_data;
-       if (stream) {
-               stream->pcm = NULL;
-               snd_usb_audio_stream_free(stream);
+       if (u->urb) {
+               if (u->buffer_size)
+                       usb_free_coherent(u->subs->dev, u->buffer_size,
+                                       u->urb->transfer_buffer,
+                                       u->urb->transfer_dma);
+               usb_free_urb(u->urb);
+               u->urb = NULL;
        }
 }
 
+/*
+ *  wait until all urbs are processed.
+ */
+static int wait_clear_urbs(struct snd_usb_substream *subs)
+{
+       unsigned long end_time = jiffies + msecs_to_jiffies(1000);
+       unsigned int i;
+       int alive;
+
+       do {
+               alive = 0;
+               for (i = 0; i < subs->nurbs; i++) {
+                       if (test_bit(i, &subs->active_mask))
+                               alive++;
+               }
+               if (subs->syncpipe) {
+                       for (i = 0; i < SYNC_URBS; i++) {
+                               if (test_bit(i + 16, &subs->active_mask))
+                                       alive++;
+                       }
+               }
+               if (! alive)
+                       break;
+               schedule_timeout_uninterruptible(1);
+       } while (time_before(jiffies, end_time));
+       if (alive)
+               snd_printk(KERN_ERR "timeout: still %d active urbs..\n", alive);
+       return 0;
+}
 
 /*
- * add this endpoint to the chip instance.
- * if a stream with the same endpoint already exists, append to it.
- * if not, create a new pcm stream.
+ * release a substream
  */
-int snd_usb_add_audio_endpoint(struct snd_usb_audio *chip, int stream, struct audioformat *fp)
+void snd_usb_release_substream_urbs(struct snd_usb_substream *subs, int force)
 {
-       struct list_head *p;
-       struct snd_usb_stream *as;
-       struct snd_usb_substream *subs;
-       struct snd_pcm *pcm;
-       int err;
+       int i;
+
+       /* stop urbs (to be sure) */
+       deactivate_urbs(subs, force, 1);
+       wait_clear_urbs(subs);
+
+       for (i = 0; i < MAX_URBS; i++)
+               release_urb_ctx(&subs->dataurb[i]);
+       for (i = 0; i < SYNC_URBS; i++)
+               release_urb_ctx(&subs->syncurb[i]);
+       usb_free_coherent(subs->dev, SYNC_URBS * 4,
+                       subs->syncbuf, subs->sync_dma);
+       subs->syncbuf = NULL;
+       subs->nurbs = 0;
+}
 
-       list_for_each(p, &chip->pcm_list) {
-               as = list_entry(p, struct snd_usb_stream, list);
-               if (as->fmt_type != fp->fmt_type)
-                       continue;
-               subs = &as->substream[stream];
-               if (!subs->endpoint)
-                       continue;
-               if (subs->endpoint == fp->endpoint) {
-                       list_add_tail(&fp->list, &subs->fmt_list);
-                       subs->num_formats++;
-                       subs->formats |= fp->formats;
-                       return 0;
+/*
+ * complete callback from data urb
+ */
+static void snd_complete_urb(struct urb *urb)
+{
+       struct snd_urb_ctx *ctx = urb->context;
+       struct snd_usb_substream *subs = ctx->subs;
+       struct snd_pcm_substream *substream = ctx->subs->pcm_substream;
+       int err = 0;
+
+       if ((subs->running && subs->ops.retire(subs, substream->runtime, urb)) ||
+           !subs->running || /* can be stopped during retire callback */
+           (err = subs->ops.prepare(subs, substream->runtime, urb)) < 0 ||
+           (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
+               clear_bit(ctx->index, &subs->active_mask);
+               if (err < 0) {
+                       snd_printd(KERN_ERR "cannot submit urb (err = %d)\n", err);
+                       snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
                }
        }
-       /* look for an empty stream */
-       list_for_each(p, &chip->pcm_list) {
-               as = list_entry(p, struct snd_usb_stream, list);
-               if (as->fmt_type != fp->fmt_type)
-                       continue;
-               subs = &as->substream[stream];
-               if (subs->endpoint)
-                       continue;
-               err = snd_pcm_new_stream(as->pcm, stream, 1);
-               if (err < 0)
-                       return err;
-               snd_usb_init_substream(as, stream, fp);
-               return 0;
+}
+
+
+/*
+ * complete callback from sync urb
+ */
+static void snd_complete_sync_urb(struct urb *urb)
+{
+       struct snd_urb_ctx *ctx = urb->context;
+       struct snd_usb_substream *subs = ctx->subs;
+       struct snd_pcm_substream *substream = ctx->subs->pcm_substream;
+       int err = 0;
+
+       if ((subs->running && subs->ops.retire_sync(subs, substream->runtime, urb)) ||
+           !subs->running || /* can be stopped during retire callback */
+           (err = subs->ops.prepare_sync(subs, substream->runtime, urb)) < 0 ||
+           (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
+               clear_bit(ctx->index + 16, &subs->active_mask);
+               if (err < 0) {
+                       snd_printd(KERN_ERR "cannot submit sync urb (err = %d)\n", err);
+                       snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
+               }
        }
+}
+
 
-       /* create a new pcm */
-       as = kzalloc(sizeof(*as), GFP_KERNEL);
-       if (!as)
-               return -ENOMEM;
-       as->pcm_index = chip->pcm_devs;
-       as->chip = chip;
-       as->fmt_type = fp->fmt_type;
-       err = snd_pcm_new(chip->card, "USB Audio", chip->pcm_devs,
-                         stream == SNDRV_PCM_STREAM_PLAYBACK ? 1 : 0,
-                         stream == SNDRV_PCM_STREAM_PLAYBACK ? 0 : 1,
-                         &pcm);
-       if (err < 0) {
-               kfree(as);
-               return err;
+/*
+ * initialize a substream for plaback/capture
+ */
+int snd_usb_init_substream_urbs(struct snd_usb_substream *subs,
+                               unsigned int period_bytes,
+                               unsigned int rate,
+                               unsigned int frame_bits)
+{
+       unsigned int maxsize, i;
+       int is_playback = subs->direction == SNDRV_PCM_STREAM_PLAYBACK;
+       unsigned int urb_packs, total_packs, packs_per_ms;
+       struct snd_usb_audio *chip = subs->stream->chip;
+
+       /* calculate the frequency in 16.16 format */
+       if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL)
+               subs->freqn = get_usb_full_speed_rate(rate);
+       else
+               subs->freqn = get_usb_high_speed_rate(rate);
+       subs->freqm = subs->freqn;
+       subs->freqshift = INT_MIN;
+       /* calculate max. frequency */
+       if (subs->maxpacksize) {
+               /* whatever fits into a max. size packet */
+               maxsize = subs->maxpacksize;
+               subs->freqmax = (maxsize / (frame_bits >> 3))
+                               << (16 - subs->datainterval);
+       } else {
+               /* no max. packet size: just take 25% higher than nominal */
+               subs->freqmax = subs->freqn + (subs->freqn >> 2);
+               maxsize = ((subs->freqmax + 0xffff) * (frame_bits >> 3))
+                               >> (16 - subs->datainterval);
        }
-       as->pcm = pcm;
-       pcm->private_data = as;
-       pcm->private_free = snd_usb_audio_pcm_free;
-       pcm->info_flags = 0;
-       if (chip->pcm_devs > 0)
-               sprintf(pcm->name, "USB Audio #%d", chip->pcm_devs);
+       subs->phase = 0;
+
+       if (subs->fill_max)
+               subs->curpacksize = subs->maxpacksize;
        else
-               strcpy(pcm->name, "USB Audio");
+               subs->curpacksize = maxsize;
 
-       snd_usb_init_substream(as, stream, fp);
+       if (snd_usb_get_speed(subs->dev) != USB_SPEED_FULL)
+               packs_per_ms = 8 >> subs->datainterval;
+       else
+               packs_per_ms = 1;
+
+       if (is_playback) {
+               urb_packs = max(chip->nrpacks, 1);
+               urb_packs = min(urb_packs, (unsigned int)MAX_PACKS);
+       } else
+               urb_packs = 1;
+       urb_packs *= packs_per_ms;
+       if (subs->syncpipe)
+               urb_packs = min(urb_packs, 1U << subs->syncinterval);
+
+       /* decide how many packets to be used */
+       if (is_playback) {
+               unsigned int minsize, maxpacks;
+               /* determine how small a packet can be */
+               minsize = (subs->freqn >> (16 - subs->datainterval))
+                         * (frame_bits >> 3);
+               /* with sync from device, assume it can be 12% lower */
+               if (subs->syncpipe)
+                       minsize -= minsize >> 3;
+               minsize = max(minsize, 1u);
+               total_packs = (period_bytes + minsize - 1) / minsize;
+               /* we need at least two URBs for queueing */
+               if (total_packs < 2) {
+                       total_packs = 2;
+               } else {
+                       /* and we don't want too long a queue either */
+                       maxpacks = max(MAX_QUEUE * packs_per_ms, urb_packs * 2);
+                       total_packs = min(total_packs, maxpacks);
+               }
+       } else {
+               while (urb_packs > 1 && urb_packs * maxsize >= period_bytes)
+                       urb_packs >>= 1;
+               total_packs = MAX_URBS * urb_packs;
+       }
+       subs->nurbs = (total_packs + urb_packs - 1) / urb_packs;
+       if (subs->nurbs > MAX_URBS) {
+               /* too much... */
+               subs->nurbs = MAX_URBS;
+               total_packs = MAX_URBS * urb_packs;
+       } else if (subs->nurbs < 2) {
+               /* too little - we need at least two packets
+                * to ensure contiguous playback/capture
+                */
+               subs->nurbs = 2;
+       }
 
-       list_add(&as->list, &chip->pcm_list);
-       chip->pcm_devs++;
+       /* allocate and initialize data urbs */
+       for (i = 0; i < subs->nurbs; i++) {
+               struct snd_urb_ctx *u = &subs->dataurb[i];
+               u->index = i;
+               u->subs = subs;
+               u->packets = (i + 1) * total_packs / subs->nurbs
+                       - i * total_packs / subs->nurbs;
+               u->buffer_size = maxsize * u->packets;
+               if (subs->fmt_type == UAC_FORMAT_TYPE_II)
+                       u->packets++; /* for transfer delimiter */
+               u->urb = usb_alloc_urb(u->packets, GFP_KERNEL);
+               if (!u->urb)
+                       goto out_of_memory;
+               u->urb->transfer_buffer =
+                       usb_alloc_coherent(subs->dev, u->buffer_size,
+                                          GFP_KERNEL, &u->urb->transfer_dma);
+               if (!u->urb->transfer_buffer)
+                       goto out_of_memory;
+               u->urb->pipe = subs->datapipe;
+               u->urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
+               u->urb->interval = 1 << subs->datainterval;
+               u->urb->context = u;
+               u->urb->complete = snd_complete_urb;
+       }
+
+       if (subs->syncpipe) {
+               /* allocate and initialize sync urbs */
+               subs->syncbuf = usb_alloc_coherent(subs->dev, SYNC_URBS * 4,
+                                                GFP_KERNEL, &subs->sync_dma);
+               if (!subs->syncbuf)
+                       goto out_of_memory;
+               for (i = 0; i < SYNC_URBS; i++) {
+                       struct snd_urb_ctx *u = &subs->syncurb[i];
+                       u->index = i;
+                       u->subs = subs;
+                       u->packets = 1;
+                       u->urb = usb_alloc_urb(1, GFP_KERNEL);
+                       if (!u->urb)
+                               goto out_of_memory;
+                       u->urb->transfer_buffer = subs->syncbuf + i * 4;
+                       u->urb->transfer_dma = subs->sync_dma + i * 4;
+                       u->urb->transfer_buffer_length = 4;
+                       u->urb->pipe = subs->syncpipe;
+                       u->urb->transfer_flags = URB_ISO_ASAP |
+                                                URB_NO_TRANSFER_DMA_MAP;
+                       u->urb->number_of_packets = 1;
+                       u->urb->interval = 1 << subs->syncinterval;
+                       u->urb->context = u;
+                       u->urb->complete = snd_complete_sync_urb;
+               }
+       }
+       return 0;
 
-       snd_usb_proc_pcm_format_add(as);
+out_of_memory:
+       snd_usb_release_substream_urbs(subs, 0);
+       return -ENOMEM;
+}
 
+/*
+ * prepare urb for full speed capture sync pipe
+ *
+ * fill the length and offset of each urb descriptor.
+ * the fixed 10.14 frequency is passed through the pipe.
+ */
+static int prepare_capture_sync_urb(struct snd_usb_substream *subs,
+                                   struct snd_pcm_runtime *runtime,
+                                   struct urb *urb)
+{
+       unsigned char *cp = urb->transfer_buffer;
+       struct snd_urb_ctx *ctx = urb->context;
+
+       urb->dev = ctx->subs->dev; /* we need to set this at each time */
+       urb->iso_frame_desc[0].length = 3;
+       urb->iso_frame_desc[0].offset = 0;
+       cp[0] = subs->freqn >> 2;
+       cp[1] = subs->freqn >> 10;
+       cp[2] = subs->freqn >> 18;
        return 0;
 }
 
-static int parse_uac_endpoint_attributes(struct snd_usb_audio *chip,
-                                        struct usb_host_interface *alts,
-                                        int protocol, int iface_no)
+/*
+ * prepare urb for high speed capture sync pipe
+ *
+ * fill the length and offset of each urb descriptor.
+ * the fixed 12.13 frequency is passed as 16.16 through the pipe.
+ */
+static int prepare_capture_sync_urb_hs(struct snd_usb_substream *subs,
+                                      struct snd_pcm_runtime *runtime,
+                                      struct urb *urb)
 {
-       /* parsed with a v1 header here. that's ok as we only look at the
-        * header first which is the same for both versions */
-       struct uac_iso_endpoint_descriptor *csep;
-       struct usb_interface_descriptor *altsd = get_iface_desc(alts);
-       int attributes = 0;
-
-       csep = snd_usb_find_desc(alts->endpoint[0].extra, alts->endpoint[0].extralen, NULL, USB_DT_CS_ENDPOINT);
-
-       /* Creamware Noah has this descriptor after the 2nd endpoint */
-       if (!csep && altsd->bNumEndpoints >= 2)
-               csep = snd_usb_find_desc(alts->endpoint[1].extra, alts->endpoint[1].extralen, NULL, USB_DT_CS_ENDPOINT);
-
-       if (!csep || csep->bLength < 7 ||
-           csep->bDescriptorSubtype != UAC_EP_GENERAL) {
-               snd_printk(KERN_WARNING "%d:%u:%d : no or invalid"
-                          " class specific endpoint descriptor\n",
-                          chip->dev->devnum, iface_no,
-                          altsd->bAlternateSetting);
-               return 0;
-       }
+       unsigned char *cp = urb->transfer_buffer;
+       struct snd_urb_ctx *ctx = urb->context;
+
+       urb->dev = ctx->subs->dev; /* we need to set this at each time */
+       urb->iso_frame_desc[0].length = 4;
+       urb->iso_frame_desc[0].offset = 0;
+       cp[0] = subs->freqn;
+       cp[1] = subs->freqn >> 8;
+       cp[2] = subs->freqn >> 16;
+       cp[3] = subs->freqn >> 24;
+       return 0;
+}
 
-       if (protocol == UAC_VERSION_1) {
-               attributes = csep->bmAttributes;
-       } else {
-               struct uac2_iso_endpoint_descriptor *csep2 =
-                       (struct uac2_iso_endpoint_descriptor *) csep;
+/*
+ * process after capture sync complete
+ * - nothing to do
+ */
+static int retire_capture_sync_urb(struct snd_usb_substream *subs,
+                                  struct snd_pcm_runtime *runtime,
+                                  struct urb *urb)
+{
+       return 0;
+}
 
-               attributes = csep->bmAttributes & UAC_EP_CS_ATTR_FILL_MAX;
+/*
+ * prepare urb for capture data pipe
+ *
+ * fill the offset and length of each descriptor.
+ *
+ * we use a temporary buffer to write the captured data.
+ * since the length of written data is determined by host, we cannot
+ * write onto the pcm buffer directly...  the data is thus copied
+ * later at complete callback to the global buffer.
+ */
+static int prepare_capture_urb(struct snd_usb_substream *subs,
+                              struct snd_pcm_runtime *runtime,
+                              struct urb *urb)
+{
+       int i, offs;
+       struct snd_urb_ctx *ctx = urb->context;
+
+       offs = 0;
+       urb->dev = ctx->subs->dev; /* we need to set this at each time */
+       for (i = 0; i < ctx->packets; i++) {
+               urb->iso_frame_desc[i].offset = offs;
+               urb->iso_frame_desc[i].length = subs->curpacksize;
+               offs += subs->curpacksize;
+       }
+       urb->transfer_buffer_length = offs;
+       urb->number_of_packets = ctx->packets;
+       return 0;
+}
 
-               /* emulate the endpoint attributes of a v1 device */
-               if (csep2->bmControls & UAC2_CONTROL_PITCH)
-                       attributes |= UAC_EP_CS_ATTR_PITCH_CONTROL;
+/*
+ * process after capture complete
+ *
+ * copy the data from each desctiptor to the pcm buffer, and
+ * update the current position.
+ */
+static int retire_capture_urb(struct snd_usb_substream *subs,
+                             struct snd_pcm_runtime *runtime,
+                             struct urb *urb)
+{
+       unsigned long flags;
+       unsigned char *cp;
+       int i;
+       unsigned int stride, frames, bytes, oldptr;
+       int period_elapsed = 0;
+
+       stride = runtime->frame_bits >> 3;
+
+       for (i = 0; i < urb->number_of_packets; i++) {
+               cp = (unsigned char *)urb->transfer_buffer + urb->iso_frame_desc[i].offset;
+               if (urb->iso_frame_desc[i].status) {
+                       snd_printd(KERN_ERR "frame %d active: %d\n", i, urb->iso_frame_desc[i].status);
+                       // continue;
+               }
+               bytes = urb->iso_frame_desc[i].actual_length;
+               frames = bytes / stride;
+               if (!subs->txfr_quirk)
+                       bytes = frames * stride;
+               if (bytes % (runtime->sample_bits >> 3) != 0) {
+#ifdef CONFIG_SND_DEBUG_VERBOSE
+                       int oldbytes = bytes;
+#endif
+                       bytes = frames * stride;
+                       snd_printdd(KERN_ERR "Corrected urb data len. %d->%d\n",
+                                                       oldbytes, bytes);
+               }
+               /* update the current pointer */
+               spin_lock_irqsave(&subs->lock, flags);
+               oldptr = subs->hwptr_done;
+               subs->hwptr_done += bytes;
+               if (subs->hwptr_done >= runtime->buffer_size * stride)
+                       subs->hwptr_done -= runtime->buffer_size * stride;
+               frames = (bytes + (oldptr % stride)) / stride;
+               subs->transfer_done += frames;
+               if (subs->transfer_done >= runtime->period_size) {
+                       subs->transfer_done -= runtime->period_size;
+                       period_elapsed = 1;
+               }
+               spin_unlock_irqrestore(&subs->lock, flags);
+               /* copy a data chunk */
+               if (oldptr + bytes > runtime->buffer_size * stride) {
+                       unsigned int bytes1 =
+                                       runtime->buffer_size * stride - oldptr;
+                       memcpy(runtime->dma_area + oldptr, cp, bytes1);
+                       memcpy(runtime->dma_area, cp + bytes1, bytes - bytes1);
+               } else {
+                       memcpy(runtime->dma_area + oldptr, cp, bytes);
+               }
        }
+       if (period_elapsed)
+               snd_pcm_period_elapsed(subs->pcm_substream);
+       return 0;
+}
 
-       return attributes;
+/*
+ * Process after capture complete when paused.  Nothing to do.
+ */
+static int retire_paused_capture_urb(struct snd_usb_substream *subs,
+                                    struct snd_pcm_runtime *runtime,
+                                    struct urb *urb)
+{
+       return 0;
 }
 
-static struct uac2_input_terminal_descriptor *
-       snd_usb_find_input_terminal_descriptor(struct usb_host_interface *ctrl_iface,
-                                              int terminal_id)
+
+/*
+ * prepare urb for playback sync pipe
+ *
+ * set up the offset and length to receive the current frequency.
+ */
+static int prepare_playback_sync_urb(struct snd_usb_substream *subs,
+                                    struct snd_pcm_runtime *runtime,
+                                    struct urb *urb)
 {
-       struct uac2_input_terminal_descriptor *term = NULL;
+       struct snd_urb_ctx *ctx = urb->context;
+
+       urb->dev = ctx->subs->dev; /* we need to set this at each time */
+       urb->iso_frame_desc[0].length = min(4u, ctx->subs->syncmaxsize);
+       urb->iso_frame_desc[0].offset = 0;
+       return 0;
+}
 
-       while ((term = snd_usb_find_csint_desc(ctrl_iface->extra,
-                                              ctrl_iface->extralen,
-                                              term, UAC_INPUT_TERMINAL))) {
-               if (term->bTerminalID == terminal_id)
-                       return term;
+/*
+ * process after playback sync complete
+ *
+ * Full speed devices report feedback values in 10.14 format as samples per
+ * frame, high speed devices in 16.16 format as samples per microframe.
+ * Because the Audio Class 1 spec was written before USB 2.0, many high speed
+ * devices use a wrong interpretation, some others use an entirely different
+ * format.  Therefore, we cannot predict what format any particular device uses
+ * and must detect it automatically.
+ */
+static int retire_playback_sync_urb(struct snd_usb_substream *subs,
+                                   struct snd_pcm_runtime *runtime,
+                                   struct urb *urb)
+{
+       unsigned int f;
+       int shift;
+       unsigned long flags;
+
+       if (urb->iso_frame_desc[0].status != 0 ||
+           urb->iso_frame_desc[0].actual_length < 3)
+               return 0;
+
+       f = le32_to_cpup(urb->transfer_buffer);
+       if (urb->iso_frame_desc[0].actual_length == 3)
+               f &= 0x00ffffff;
+       else
+               f &= 0x0fffffff;
+       if (f == 0)
+               return 0;
+
+       if (unlikely(subs->freqshift == INT_MIN)) {
+               /*
+                * The first time we see a feedback value, determine its format
+                * by shifting it left or right until it matches the nominal
+                * frequency value.  This assumes that the feedback does not
+                * differ from the nominal value more than +50% or -25%.
+                */
+               shift = 0;
+               while (f < subs->freqn - subs->freqn / 4) {
+                       f <<= 1;
+                       shift++;
+               }
+               while (f > subs->freqn + subs->freqn / 2) {
+                       f >>= 1;
+                       shift--;
+               }
+               subs->freqshift = shift;
+       }
+       else if (subs->freqshift >= 0)
+               f <<= subs->freqshift;
+       else
+               f >>= -subs->freqshift;
+
+       if (likely(f >= subs->freqn - subs->freqn / 8 && f <= subs->freqmax)) {
+               /*
+                * If the frequency looks valid, set it.
+                * This value is referred to in prepare_playback_urb().
+                */
+               spin_lock_irqsave(&subs->lock, flags);
+               subs->freqm = f;
+               spin_unlock_irqrestore(&subs->lock, flags);
+       } else {
+               /*
+                * Out of range; maybe the shift value is wrong.
+                * Reset it so that we autodetect again the next time.
+                */
+               subs->freqshift = INT_MIN;
        }
 
-       return NULL;
+       return 0;
 }
 
-static struct uac2_output_terminal_descriptor *
-       snd_usb_find_output_terminal_descriptor(struct usb_host_interface *ctrl_iface,
-                                               int terminal_id)
+/* determine the number of frames in the next packet */
+static int snd_usb_audio_next_packet_size(struct snd_usb_substream *subs)
 {
-       struct uac2_output_terminal_descriptor *term = NULL;
-
-       while ((term = snd_usb_find_csint_desc(ctrl_iface->extra,
-                                              ctrl_iface->extralen,
-                                              term, UAC_OUTPUT_TERMINAL))) {
-               if (term->bTerminalID == terminal_id)
-                       return term;
+       if (subs->fill_max)
+               return subs->maxframesize;
+       else {
+               subs->phase = (subs->phase & 0xffff)
+                       + (subs->freqm << subs->datainterval);
+               return min(subs->phase >> 16, subs->maxframesize);
        }
+}
 
-       return NULL;
+/*
+ * Prepare urb for streaming before playback starts or when paused.
+ *
+ * We don't have any data, so we send silence.
+ */
+static int prepare_nodata_playback_urb(struct snd_usb_substream *subs,
+                                      struct snd_pcm_runtime *runtime,
+                                      struct urb *urb)
+{
+       unsigned int i, offs, counts;
+       struct snd_urb_ctx *ctx = urb->context;
+       int stride = runtime->frame_bits >> 3;
+
+       offs = 0;
+       urb->dev = ctx->subs->dev;
+       for (i = 0; i < ctx->packets; ++i) {
+               counts = snd_usb_audio_next_packet_size(subs);
+               urb->iso_frame_desc[i].offset = offs * stride;
+               urb->iso_frame_desc[i].length = counts * stride;
+               offs += counts;
+       }
+       urb->number_of_packets = ctx->packets;
+       urb->transfer_buffer_length = offs * stride;
+       memset(urb->transfer_buffer,
+              runtime->format == SNDRV_PCM_FORMAT_U8 ? 0x80 : 0,
+              offs * stride);
+       return 0;
 }
 
-int snd_usb_parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
+/*
+ * prepare urb for playback data pipe
+ *
+ * Since a URB can handle only a single linear buffer, we must use double
+ * buffering when the data to be transferred overflows the buffer boundary.
+ * To avoid inconsistencies when updating hwptr_done, we use double buffering
+ * for all URBs.
+ */
+static int prepare_playback_urb(struct snd_usb_substream *subs,
+                               struct snd_pcm_runtime *runtime,
+                               struct urb *urb)
 {
-       struct usb_device *dev;
-       struct usb_interface *iface;
-       struct usb_host_interface *alts;
-       struct usb_interface_descriptor *altsd;
-       int i, altno, err, stream;
-       int format = 0, num_channels = 0;
-       struct audioformat *fp = NULL;
-       int num, protocol, clock = 0;
-       struct uac_format_type_i_continuous_descriptor *fmt;
+       int i, stride;
+       unsigned int counts, frames, bytes;
+       unsigned long flags;
+       int period_elapsed = 0;
+       struct snd_urb_ctx *ctx = urb->context;
+
+       stride = runtime->frame_bits >> 3;
+
+       frames = 0;
+       urb->dev = ctx->subs->dev; /* we need to set this at each time */
+       urb->number_of_packets = 0;
+       spin_lock_irqsave(&subs->lock, flags);
+       for (i = 0; i < ctx->packets; i++) {
+               counts = snd_usb_audio_next_packet_size(subs);
+               /* set up descriptor */
+               urb->iso_frame_desc[i].offset = frames * stride;
+               urb->iso_frame_desc[i].length = counts * stride;
+               frames += counts;
+               urb->number_of_packets++;
+               subs->transfer_done += counts;
+               if (subs->transfer_done >= runtime->period_size) {
+                       subs->transfer_done -= runtime->period_size;
+                       period_elapsed = 1;
+                       if (subs->fmt_type == UAC_FORMAT_TYPE_II) {
+                               if (subs->transfer_done > 0) {
+                                       /* FIXME: fill-max mode is not
+                                        * supported yet */
+                                       frames -= subs->transfer_done;
+                                       counts -= subs->transfer_done;
+                                       urb->iso_frame_desc[i].length =
+                                               counts * stride;
+                                       subs->transfer_done = 0;
+                               }
+                               i++;
+                               if (i < ctx->packets) {
+                                       /* add a transfer delimiter */
+                                       urb->iso_frame_desc[i].offset =
+                                               frames * stride;
+                                       urb->iso_frame_desc[i].length = 0;
+                                       urb->number_of_packets++;
+                               }
+                               break;
+                       }
+               }
+               if (period_elapsed) /* finish at the period boundary */
+                       break;
+       }
+       bytes = frames * stride;
+       if (subs->hwptr_done + bytes > runtime->buffer_size * stride) {
+               /* err, the transferred area goes over buffer boundary. */
+               unsigned int bytes1 =
+                       runtime->buffer_size * stride - subs->hwptr_done;
+               memcpy(urb->transfer_buffer,
+                      runtime->dma_area + subs->hwptr_done, bytes1);
+               memcpy(urb->transfer_buffer + bytes1,
+                      runtime->dma_area, bytes - bytes1);
+       } else {
+               memcpy(urb->transfer_buffer,
+                      runtime->dma_area + subs->hwptr_done, bytes);
+       }
+       subs->hwptr_done += bytes;
+       if (subs->hwptr_done >= runtime->buffer_size * stride)
+               subs->hwptr_done -= runtime->buffer_size * stride;
+
+       /* update delay with exact number of samples queued */
+       runtime->delay = subs->last_delay;
+       runtime->delay += frames;
+       subs->last_delay = runtime->delay;
+
+       /* realign last_frame_number */
+       subs->last_frame_number = usb_get_current_frame_number(subs->dev);
+       subs->last_frame_number &= 0xFF; /* keep 8 LSBs */
+
+       spin_unlock_irqrestore(&subs->lock, flags);
+       urb->transfer_buffer_length = bytes;
+       if (period_elapsed)
+               snd_pcm_period_elapsed(subs->pcm_substream);
+       return 0;
+}
 
-       dev = chip->dev;
+/*
+ * process after playback data complete
+ * - decrease the delay count again
+ */
+static int retire_playback_urb(struct snd_usb_substream *subs,
+                              struct snd_pcm_runtime *runtime,
+                              struct urb *urb)
+{
+       unsigned long flags;
+       int stride = runtime->frame_bits >> 3;
+       int processed = urb->transfer_buffer_length / stride;
+       int est_delay;
 
-       /* parse the interface's altsettings */
-       iface = usb_ifnum_to_if(dev, iface_no);
+       spin_lock_irqsave(&subs->lock, flags);
 
-       num = iface->num_altsetting;
+       est_delay = snd_usb_pcm_delay(subs, runtime->rate);
+       /* update delay with exact number of samples played */
+       if (processed > subs->last_delay)
+               subs->last_delay = 0;
+       else
+               subs->last_delay -= processed;
+       runtime->delay = subs->last_delay;
 
        /*
-        * Dallas DS4201 workaround: It presents 5 altsettings, but the last
-        * one misses syncpipe, and does not produce any sound.
+        * Report when delay estimate is off by more than 2ms.
+        * The error should be lower than 2ms since the estimate relies
+        * on two reads of a counter updated every ms.
         */
-       if (chip->usb_id == USB_ID(0x04fa, 0x4201))
-               num = 4;
-
-       for (i = 0; i < num; i++) {
-               alts = &iface->altsetting[i];
-               altsd = get_iface_desc(alts);
-               protocol = altsd->bInterfaceProtocol;
-               /* skip invalid one */
-               if ((altsd->bInterfaceClass != USB_CLASS_AUDIO &&
-                    altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) ||
-                   (altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIOSTREAMING &&
-                    altsd->bInterfaceSubClass != USB_SUBCLASS_VENDOR_SPEC) ||
-                   altsd->bNumEndpoints < 1 ||
-                   le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) == 0)
-                       continue;
-               /* must be isochronous */
-               if ((get_endpoint(alts, 0)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) !=
-                   USB_ENDPOINT_XFER_ISOC)
-                       continue;
-               /* check direction */
-               stream = (get_endpoint(alts, 0)->bEndpointAddress & USB_DIR_IN) ?
-                       SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
-               altno = altsd->bAlternateSetting;
-
-               if (snd_usb_apply_interface_quirk(chip, iface_no, altno))
-                       continue;
-
-               /* get audio formats */
-               switch (protocol) {
-               default:
-                       snd_printdd(KERN_WARNING "%d:%u:%d: unknown interface protocol %#02x, assuming v1\n",
-                                   dev->devnum, iface_no, altno, protocol);
-                       protocol = UAC_VERSION_1;
-                       /* fall through */
-
-               case UAC_VERSION_1: {
-                       struct uac1_as_header_descriptor *as =
-                               snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL);
-
-                       if (!as) {
-                               snd_printk(KERN_ERR "%d:%u:%d : UAC_AS_GENERAL descriptor not found\n",
-                                          dev->devnum, iface_no, altno);
-                               continue;
-                       }
+       if (abs(est_delay - subs->last_delay) * 1000 > runtime->rate * 2)
+               snd_printk(KERN_DEBUG "delay: estimated %d, actual %d\n",
+                       est_delay, subs->last_delay);
 
-                       if (as->bLength < sizeof(*as)) {
-                               snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_AS_GENERAL desc\n",
-                                          dev->devnum, iface_no, altno);
-                               continue;
-                       }
+       spin_unlock_irqrestore(&subs->lock, flags);
+       return 0;
+}
 
-                       format = le16_to_cpu(as->wFormatTag); /* remember the format value */
-                       break;
-               }
+static const char *usb_error_string(int err)
+{
+       switch (err) {
+       case -ENODEV:
+               return "no device";
+       case -ENOENT:
+               return "endpoint not enabled";
+       case -EPIPE:
+               return "endpoint stalled";
+       case -ENOSPC:
+               return "not enough bandwidth";
+       case -ESHUTDOWN:
+               return "device disabled";
+       case -EHOSTUNREACH:
+               return "device suspended";
+       case -EINVAL:
+       case -EAGAIN:
+       case -EFBIG:
+       case -EMSGSIZE:
+               return "internal error";
+       default:
+               return "unknown error";
+       }
+}
 
-               case UAC_VERSION_2: {
-                       struct uac2_input_terminal_descriptor *input_term;
-                       struct uac2_output_terminal_descriptor *output_term;
-                       struct uac2_as_header_descriptor *as =
-                               snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL);
+/*
+ * set up and start data/sync urbs
+ */
+static int start_urbs(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime)
+{
+       unsigned int i;
+       int err;
 
-                       if (!as) {
-                               snd_printk(KERN_ERR "%d:%u:%d : UAC_AS_GENERAL descriptor not found\n",
-                                          dev->devnum, iface_no, altno);
-                               continue;
+       if (subs->stream->chip->shutdown)
+               return -EBADFD;
+
+       for (i = 0; i < subs->nurbs; i++) {
+               if (snd_BUG_ON(!subs->dataurb[i].urb))
+                       return -EINVAL;
+               if (subs->ops.prepare(subs, runtime, subs->dataurb[i].urb) < 0) {
+                       snd_printk(KERN_ERR "cannot prepare datapipe for urb %d\n", i);
+                       goto __error;
+               }
+       }
+       if (subs->syncpipe) {
+               for (i = 0; i < SYNC_URBS; i++) {
+                       if (snd_BUG_ON(!subs->syncurb[i].urb))
+                               return -EINVAL;
+                       if (subs->ops.prepare_sync(subs, runtime, subs->syncurb[i].urb) < 0) {
+                               snd_printk(KERN_ERR "cannot prepare syncpipe for urb %d\n", i);
+                               goto __error;
                        }
+               }
+       }
 
-                       if (as->bLength < sizeof(*as)) {
-                               snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_AS_GENERAL desc\n",
-                                          dev->devnum, iface_no, altno);
-                               continue;
+       subs->active_mask = 0;
+       subs->unlink_mask = 0;
+       subs->running = 1;
+       for (i = 0; i < subs->nurbs; i++) {
+               err = usb_submit_urb(subs->dataurb[i].urb, GFP_ATOMIC);
+               if (err < 0) {
+                       snd_printk(KERN_ERR "cannot submit datapipe "
+                                  "for urb %d, error %d: %s\n",
+                                  i, err, usb_error_string(err));
+                       goto __error;
+               }
+               set_bit(i, &subs->active_mask);
+       }
+       if (subs->syncpipe) {
+               for (i = 0; i < SYNC_URBS; i++) {
+                       err = usb_submit_urb(subs->syncurb[i].urb, GFP_ATOMIC);
+                       if (err < 0) {
+                               snd_printk(KERN_ERR "cannot submit syncpipe "
+                                          "for urb %d, error %d: %s\n",
+                                          i, err, usb_error_string(err));
+                               goto __error;
                        }
+                       set_bit(i + 16, &subs->active_mask);
+               }
+       }
+       return 0;
 
-                       num_channels = as->bNrChannels;
-                       format = le32_to_cpu(as->bmFormats);
+ __error:
+       // snd_pcm_stop(subs->pcm_substream, SNDRV_PCM_STATE_XRUN);
+       deactivate_urbs(subs, 0, 0);
+       return -EPIPE;
+}
 
-                       /* lookup the terminal associated to this interface
-                        * to extract the clock */
-                       input_term = snd_usb_find_input_terminal_descriptor(chip->ctrl_intf,
-                                                                           as->bTerminalLink);
-                       if (input_term) {
-                               clock = input_term->bCSourceID;
-                               break;
-                       }
 
-                       output_term = snd_usb_find_output_terminal_descriptor(chip->ctrl_intf,
-                                                                             as->bTerminalLink);
-                       if (output_term) {
-                               clock = output_term->bCSourceID;
-                               break;
-                       }
+/*
+ */
+static struct snd_urb_ops audio_urb_ops[2] = {
+       {
+               .prepare =      prepare_nodata_playback_urb,
+               .retire =       retire_playback_urb,
+               .prepare_sync = prepare_playback_sync_urb,
+               .retire_sync =  retire_playback_sync_urb,
+       },
+       {
+               .prepare =      prepare_capture_urb,
+               .retire =       retire_capture_urb,
+               .prepare_sync = prepare_capture_sync_urb,
+               .retire_sync =  retire_capture_sync_urb,
+       },
+};
 
-                       snd_printk(KERN_ERR "%d:%u:%d : bogus bTerminalLink %d\n",
-                                  dev->devnum, iface_no, altno, as->bTerminalLink);
-                       continue;
-               }
-               }
+/*
+ * initialize the substream instance.
+ */
 
-               /* get format type */
-               fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_FORMAT_TYPE);
-               if (!fmt) {
-                       snd_printk(KERN_ERR "%d:%u:%d : no UAC_FORMAT_TYPE desc\n",
-                                  dev->devnum, iface_no, altno);
-                       continue;
-               }
-               if (((protocol == UAC_VERSION_1) && (fmt->bLength < 8)) ||
-                   ((protocol == UAC_VERSION_2) && (fmt->bLength < 6))) {
-                       snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_FORMAT_TYPE desc\n",
-                                  dev->devnum, iface_no, altno);
-                       continue;
-               }
+void snd_usb_init_substream(struct snd_usb_stream *as,
+                           int stream, struct audioformat *fp)
+{
+       struct snd_usb_substream *subs = &as->substream[stream];
+
+       INIT_LIST_HEAD(&subs->fmt_list);
+       spin_lock_init(&subs->lock);
+
+       subs->stream = as;
+       subs->direction = stream;
+       subs->dev = as->chip->dev;
+       subs->txfr_quirk = as->chip->txfr_quirk;
+       subs->ops = audio_urb_ops[stream];
+       if (snd_usb_get_speed(subs->dev) >= USB_SPEED_HIGH)
+               subs->ops.prepare_sync = prepare_capture_sync_urb_hs;
+
+       snd_usb_set_pcm_ops(as->pcm, stream);
+
+       list_add_tail(&fp->list, &subs->fmt_list);
+       subs->formats |= fp->formats;
+       subs->endpoint = fp->endpoint;
+       subs->num_formats++;
+       subs->fmt_type = fp->fmt_type;
+}
 
-               /*
-                * Blue Microphones workaround: The last altsetting is identical
-                * with the previous one, except for a larger packet size, but
-                * is actually a mislabeled two-channel setting; ignore it.
-                */
-               if (fmt->bNrChannels == 1 &&
-                   fmt->bSubframeSize == 2 &&
-                   altno == 2 && num == 3 &&
-                   fp && fp->altsetting == 1 && fp->channels == 1 &&
-                   fp->formats == SNDRV_PCM_FMTBIT_S16_LE &&
-                   protocol == UAC_VERSION_1 &&
-                   le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) ==
-                                                       fp->maxpacksize * 2)
-                       continue;
-
-               fp = kzalloc(sizeof(*fp), GFP_KERNEL);
-               if (! fp) {
-                       snd_printk(KERN_ERR "cannot malloc\n");
-                       return -ENOMEM;
-               }
+int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substream, int cmd)
+{
+       struct snd_usb_substream *subs = substream->runtime->private_data;
 
-               fp->iface = iface_no;
-               fp->altsetting = altno;
-               fp->altset_idx = i;
-               fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
-               fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
-               fp->datainterval = snd_usb_parse_datainterval(chip, alts);
-               fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
-               /* num_channels is only set for v2 interfaces */
-               fp->channels = num_channels;
-               if (snd_usb_get_speed(dev) == USB_SPEED_HIGH)
-                       fp->maxpacksize = (((fp->maxpacksize >> 11) & 3) + 1)
-                                       * (fp->maxpacksize & 0x7ff);
-               fp->attributes = parse_uac_endpoint_attributes(chip, alts, protocol, iface_no);
-               fp->clock = clock;
-
-               /* some quirks for attributes here */
-
-               switch (chip->usb_id) {
-               case USB_ID(0x0a92, 0x0053): /* AudioTrak Optoplay */
-                       /* Optoplay sets the sample rate attribute although
-                        * it seems not supporting it in fact.
-                        */
-                       fp->attributes &= ~UAC_EP_CS_ATTR_SAMPLE_RATE;
-                       break;
-               case USB_ID(0x041e, 0x3020): /* Creative SB Audigy 2 NX */
-               case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
-                       /* doesn't set the sample rate attribute, but supports it */
-                       fp->attributes |= UAC_EP_CS_ATTR_SAMPLE_RATE;
-                       break;
-               case USB_ID(0x0763, 0x2001):  /* M-Audio Quattro USB */
-               case USB_ID(0x0763, 0x2012):  /* M-Audio Fast Track Pro USB */
-               case USB_ID(0x047f, 0x0ca1): /* plantronics headset */
-               case USB_ID(0x077d, 0x07af): /* Griffin iMic (note that there is
-                                               an older model 77d:223) */
-               /*
-                * plantronics headset and Griffin iMic have set adaptive-in
-                * although it's really not...
-                */
-                       fp->ep_attr &= ~USB_ENDPOINT_SYNCTYPE;
-                       if (stream == SNDRV_PCM_STREAM_PLAYBACK)
-                               fp->ep_attr |= USB_ENDPOINT_SYNC_ADAPTIVE;
-                       else
-                               fp->ep_attr |= USB_ENDPOINT_SYNC_SYNC;
-                       break;
-               }
+       switch (cmd) {
+       case SNDRV_PCM_TRIGGER_START:
+       case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+               subs->ops.prepare = prepare_playback_urb;
+               return 0;
+       case SNDRV_PCM_TRIGGER_STOP:
+               return deactivate_urbs(subs, 0, 0);
+       case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+               subs->ops.prepare = prepare_nodata_playback_urb;
+               return 0;
+       }
 
-               /* ok, let's parse further... */
-               if (snd_usb_parse_audio_format(chip, fp, format, fmt, stream, alts) < 0) {
-                       kfree(fp->rate_table);
-                       kfree(fp);
-                       fp = NULL;
-                       continue;
-               }
+       return -EINVAL;
+}
 
-               snd_printdd(KERN_INFO "%d:%u:%d: add audio endpoint %#x\n", dev->devnum, iface_no, altno, fp->endpoint);
-               err = snd_usb_add_audio_endpoint(chip, stream, fp);
-               if (err < 0) {
-                       kfree(fp->rate_table);
-                       kfree(fp);
-                       return err;
-               }
-               /* try to set the interface... */
-               usb_set_interface(chip->dev, iface_no, altno);
-               snd_usb_init_pitch(chip, iface_no, alts, fp);
-               snd_usb_init_sample_rate(chip, iface_no, alts, fp, fp->rate_max);
+int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream, int cmd)
+{
+       struct snd_usb_substream *subs = substream->runtime->private_data;
+
+       switch (cmd) {
+       case SNDRV_PCM_TRIGGER_START:
+               subs->ops.retire = retire_capture_urb;
+               return start_urbs(subs, substream->runtime);
+       case SNDRV_PCM_TRIGGER_STOP:
+               return deactivate_urbs(subs, 0, 0);
+       case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+               subs->ops.retire = retire_paused_capture_urb;
+               return 0;
+       case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+               subs->ops.retire = retire_capture_urb;
+               return 0;
        }
+
+       return -EINVAL;
+}
+
+int snd_usb_substream_prepare(struct snd_usb_substream *subs,
+                             struct snd_pcm_runtime *runtime)
+{
+       /* clear urbs (to be sure) */
+       deactivate_urbs(subs, 0, 1);
+       wait_clear_urbs(subs);
+
+       /* for playback, submit the URBs now; otherwise, the first hwptr_done
+        * updates for all URBs would happen at the same time when starting */
+       if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) {
+               subs->ops.prepare = prepare_nodata_playback_urb;
+               return start_urbs(subs, runtime);
+       }
+
        return 0;
 }
 
index 64dd0db023b2be99b268090dae9381d0fb05f289..88eb63a636eb28fa3b0fc56e05340d4be581cd72 100644 (file)
@@ -1,11 +1,21 @@
 #ifndef __USBAUDIO_ENDPOINT_H
 #define __USBAUDIO_ENDPOINT_H
 
-int snd_usb_parse_audio_endpoints(struct snd_usb_audio *chip,
-                                 int iface_no);
+void snd_usb_init_substream(struct snd_usb_stream *as,
+                           int stream,
+                           struct audioformat *fp);
 
-int snd_usb_add_audio_endpoint(struct snd_usb_audio *chip,
-                              int stream,
-                              struct audioformat *fp);
+int snd_usb_init_substream_urbs(struct snd_usb_substream *subs,
+                               unsigned int period_bytes,
+                               unsigned int rate,
+                               unsigned int frame_bits);
+
+void snd_usb_release_substream_urbs(struct snd_usb_substream *subs, int force);
+
+int snd_usb_substream_prepare(struct snd_usb_substream *subs,
+                             struct snd_pcm_runtime *runtime);
+
+int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substream, int cmd);
+int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream, int cmd);
 
 #endif /* __USBAUDIO_ENDPOINT_H */
index 8d042dce0d16a0a2d26efffe2cceb9279f0300f9..89421d176570739c6034c70a3cdd74285a5f394e 100644 (file)
@@ -286,7 +286,7 @@ static int parse_audio_format_rates_v2(struct snd_usb_audio *chip,
                              USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
                              UAC2_CS_CONTROL_SAM_FREQ << 8,
                              snd_usb_ctrl_intf(chip) | (clock << 8),
-                             tmp, sizeof(tmp), 1000);
+                             tmp, sizeof(tmp));
 
        if (ret < 0) {
                snd_printk(KERN_ERR "%s(): unable to retrieve number of sample rates (clock %d)\n",
@@ -307,7 +307,7 @@ static int parse_audio_format_rates_v2(struct snd_usb_audio *chip,
                              USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
                              UAC2_CS_CONTROL_SAM_FREQ << 8,
                              snd_usb_ctrl_intf(chip) | (clock << 8),
-                             data, data_size, 1000);
+                             data, data_size);
 
        if (ret < 0) {
                snd_printk(KERN_ERR "%s(): unable to retrieve sample rate range (clock %d)\n",
index f280c1903c25bdaa0b20e8456b6753c3dc5edcfb..9eed8f40b179dd199702c1247dd65bdd0b56ff35 100644 (file)
@@ -81,7 +81,7 @@ void *snd_usb_find_csint_desc(void *buffer, int buflen, void *after, u8 dsubtype
  */
 int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
                    __u8 requesttype, __u16 value, __u16 index, void *data,
-                   __u16 size, int timeout)
+                   __u16 size)
 {
        int err;
        void *buf = NULL;
@@ -92,7 +92,7 @@ int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
                        return -ENOMEM;
        }
        err = usb_control_msg(dev, pipe, request, requesttype,
-                             value, index, buf, size, timeout);
+                             value, index, buf, size, 1000);
        if (size > 0) {
                memcpy(data, buf, size);
                kfree(buf);
index 09bd943c43bf736c72c915ce99f41180b6be88b9..805c300dd004df4b5bc15487ab4839ec7d0ad542 100644 (file)
@@ -8,7 +8,7 @@ void *snd_usb_find_csint_desc(void *descstart, int desclen, void *after, u8 dsub
 
 int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe,
                    __u8 request, __u8 requesttype, __u16 value, __u16 index,
-                   void *data, __u16 size, int timeout);
+                   void *data, __u16 size);
 
 unsigned char snd_usb_parse_datainterval(struct snd_usb_audio *chip,
                                         struct usb_host_interface *alts);
index f9289102886ad890987a0d27739a19f1e48afdd4..e21f026d9577504fe4ac8aef70ef2bfc6eff04f3 100644 (file)
@@ -816,6 +816,22 @@ static struct usb_protocol_ops snd_usbmidi_raw_ops = {
        .output = snd_usbmidi_raw_output,
 };
 
+/*
+ * FTDI protocol: raw MIDI bytes, but input packets have two modem status bytes.
+ */
+
+static void snd_usbmidi_ftdi_input(struct snd_usb_midi_in_endpoint* ep,
+                                  uint8_t* buffer, int buffer_length)
+{
+       if (buffer_length > 2)
+               snd_usbmidi_input_data(ep, 0, buffer + 2, buffer_length - 2);
+}
+
+static struct usb_protocol_ops snd_usbmidi_ftdi_ops = {
+       .input = snd_usbmidi_ftdi_input,
+       .output = snd_usbmidi_raw_output,
+};
+
 static void snd_usbmidi_us122l_input(struct snd_usb_midi_in_endpoint *ep,
                                     uint8_t *buffer, int buffer_length)
 {
@@ -2163,6 +2179,17 @@ int snd_usbmidi_create(struct snd_card *card,
                /* endpoint 1 is input-only */
                endpoints[1].out_cables = 0;
                break;
+       case QUIRK_MIDI_FTDI:
+               umidi->usb_protocol_ops = &snd_usbmidi_ftdi_ops;
+
+               /* set baud rate to 31250 (48 MHz / 16 / 96) */
+               err = usb_control_msg(umidi->dev, usb_sndctrlpipe(umidi->dev, 0),
+                                     3, 0x40, 0x60, 0, NULL, 0, 1000);
+               if (err < 0)
+                       break;
+
+               err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
+               break;
        default:
                snd_printd(KERN_ERR "invalid quirk type %d\n", quirk->type);
                err = -ENXIO;
index cdd19d7fe500b2a6315b3023212f1313032c5999..60f65ace7474ddfcdf538ba3624c61193c6808a7 100644 (file)
@@ -296,7 +296,7 @@ static int get_ctl_value_v1(struct usb_mixer_elem_info *cval, int request, int v
                if (snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), request,
                                    USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
                                    validx, snd_usb_ctrl_intf(chip) | (cval->id << 8),
-                                   buf, val_len, 100) >= val_len) {
+                                   buf, val_len) >= val_len) {
                        *value_ret = convert_signed_value(cval, snd_usb_combine_bytes(buf, val_len));
                        snd_usb_autosuspend(cval->mixer->chip);
                        return 0;
@@ -333,7 +333,7 @@ static int get_ctl_value_v2(struct usb_mixer_elem_info *cval, int request, int v
        ret = snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), bRequest,
                              USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
                              validx, snd_usb_ctrl_intf(chip) | (cval->id << 8),
-                             buf, size, 1000);
+                             buf, size);
        snd_usb_autosuspend(chip);
 
        if (ret < 0) {
@@ -445,7 +445,7 @@ int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval,
                                    usb_sndctrlpipe(chip->dev, 0), request,
                                    USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
                                    validx, snd_usb_ctrl_intf(chip) | (cval->id << 8),
-                                   buf, val_len, 100) >= 0) {
+                                   buf, val_len) >= 0) {
                        snd_usb_autosuspend(chip);
                        return 0;
                }
@@ -881,8 +881,17 @@ static int mixer_ctl_feature_info(struct snd_kcontrol *kcontrol, struct snd_ctl_
                uinfo->value.integer.min = 0;
                uinfo->value.integer.max = 1;
        } else {
-               if (! cval->initialized)
-                       get_min_max(cval,  0);
+               if (!cval->initialized) {
+                       get_min_max(cval, 0);
+                       if (cval->initialized && cval->dBmin >= cval->dBmax) {
+                               kcontrol->vd[0].access &= 
+                                       ~(SNDRV_CTL_ELEM_ACCESS_TLV_READ |
+                                         SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK);
+                               snd_ctl_notify(cval->mixer->chip->card,
+                                              SNDRV_CTL_EVENT_MASK_INFO,
+                                              &kcontrol->id);
+                       }
+               }
                uinfo->value.integer.min = 0;
                uinfo->value.integer.max =
                        (cval->max - cval->min + cval->res - 1) / cval->res;
@@ -1250,7 +1259,7 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid, void
                                build_feature_ctl(state, _ftr, 0, i, &iterm, unitid, 0);
                }
        } else { /* UAC_VERSION_2 */
-               for (i = 0; i < 30/2; i++) {
+               for (i = 0; i < ARRAY_SIZE(audio_feature_info); i++) {
                        unsigned int ch_bits = 0;
                        unsigned int ch_read_only = 0;
 
index 3d0f4873112b17d9f5d7bfec90a87fbab2053ae6..ab125ee0b0f0e20091a13a7b354fc9f9abb69590 100644 (file)
@@ -190,18 +190,18 @@ static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
                err = snd_usb_ctl_msg(mixer->chip->dev,
                              usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
                              USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
-                             !value, 0, NULL, 0, 100);
+                             !value, 0, NULL, 0);
        /* USB X-Fi S51 Pro */
        if (mixer->chip->usb_id == USB_ID(0x041e, 0x30df))
                err = snd_usb_ctl_msg(mixer->chip->dev,
                              usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
                              USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
-                             !value, 0, NULL, 0, 100);
+                             !value, 0, NULL, 0);
        else
                err = snd_usb_ctl_msg(mixer->chip->dev,
                              usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
                              USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
-                             value, index + 2, NULL, 0, 100);
+                             value, index + 2, NULL, 0);
        if (err < 0)
                return err;
        mixer->audigy2nx_leds[index] = value;
@@ -299,7 +299,7 @@ static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
                                      usb_rcvctrlpipe(mixer->chip->dev, 0),
                                      UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS |
                                      USB_RECIP_INTERFACE, 0,
-                                     jacks[i].unitid << 8, buf, 3, 100);
+                                     jacks[i].unitid << 8, buf, 3);
                if (err == 3 && (buf[0] == 3 || buf[0] == 6))
                        snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]);
                else
@@ -332,7 +332,7 @@ static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
        err = snd_usb_ctl_msg(mixer->chip->dev,
                              usb_sndctrlpipe(mixer->chip->dev, 0), 0x08,
                              USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
-                             50, 0, &new_status, 1, 100);
+                             50, 0, &new_status, 1);
        if (err < 0)
                return err;
        mixer->xonar_u1_status = new_status;
index b8dcbf407bbbbe10bf4daf39b65d4f6e06ec65b7..0220b0f335b9ad230ebcb954ed78ab25731ca58e 100644 (file)
 #include "card.h"
 #include "quirks.h"
 #include "debug.h"
-#include "urb.h"
+#include "endpoint.h"
 #include "helper.h"
 #include "pcm.h"
 #include "clock.h"
 #include "power.h"
 
+/* return the estimated delay based on USB frame counters */
+snd_pcm_uframes_t snd_usb_pcm_delay(struct snd_usb_substream *subs,
+                                   unsigned int rate)
+{
+       int current_frame_number;
+       int frame_diff;
+       int est_delay;
+
+       current_frame_number = usb_get_current_frame_number(subs->dev);
+       /*
+        * HCD implementations use different widths, use lower 8 bits.
+        * The delay will be managed up to 256ms, which is more than
+        * enough
+        */
+       frame_diff = (current_frame_number - subs->last_frame_number) & 0xff;
+
+       /* Approximation based on number of samples per USB frame (ms),
+          some truncation for 44.1 but the estimate is good enough */
+       est_delay =  subs->last_delay - (frame_diff * rate / 1000);
+       if (est_delay < 0)
+               est_delay = 0;
+       return est_delay;
+}
+
 /*
  * return the current pcm pointer.  just based on the hwptr_done value.
  */
@@ -45,6 +69,8 @@ static snd_pcm_uframes_t snd_usb_pcm_pointer(struct snd_pcm_substream *substream
        subs = (struct snd_usb_substream *)substream->runtime->private_data;
        spin_lock(&subs->lock);
        hwptr_done = subs->hwptr_done;
+       substream->runtime->delay = snd_usb_pcm_delay(subs,
+                                               substream->runtime->rate);
        spin_unlock(&subs->lock);
        return hwptr_done / (substream->runtime->frame_bits >> 3);
 }
@@ -126,7 +152,7 @@ static int init_pitch_v1(struct snd_usb_audio *chip, int iface,
        if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR,
                                   USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT,
                                   UAC_EP_CS_ATTR_PITCH_CONTROL << 8, ep,
-                                  data, sizeof(data), 1000)) < 0) {
+                                  data, sizeof(data))) < 0) {
                snd_printk(KERN_ERR "%d:%d:%d: cannot set enable PITCH\n",
                           dev->devnum, iface, ep);
                return err;
@@ -150,7 +176,7 @@ static int init_pitch_v2(struct snd_usb_audio *chip, int iface,
        if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC2_CS_CUR,
                                   USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_OUT,
                                   UAC2_EP_CS_PITCH << 8, 0,
-                                  data, sizeof(data), 1000)) < 0) {
+                                  data, sizeof(data))) < 0) {
                snd_printk(KERN_ERR "%d:%d:%d: cannot set enable PITCH (v2)\n",
                           dev->devnum, iface, fmt->altsetting);
                return err;
@@ -417,6 +443,8 @@ static int snd_usb_pcm_prepare(struct snd_pcm_substream *substream)
        subs->hwptr_done = 0;
        subs->transfer_done = 0;
        subs->phase = 0;
+       subs->last_delay = 0;
+       subs->last_frame_number = 0;
        runtime->delay = 0;
 
        return snd_usb_substream_prepare(subs, runtime);
index ed3e283f618d11998af50f5f217f39f9397c8c97..df7a003682ad6426a3e50532cd815e8bf00a4af6 100644 (file)
@@ -1,6 +1,9 @@
 #ifndef __USBAUDIO_PCM_H
 #define __USBAUDIO_PCM_H
 
+snd_pcm_uframes_t snd_usb_pcm_delay(struct snd_usb_substream *subs,
+                                   unsigned int rate);
+
 void snd_usb_set_pcm_ops(struct snd_pcm *pcm, int stream);
 
 int snd_usb_init_pitch(struct snd_usb_audio *chip, int iface,
index a42e3ef3832d709d11b1653bc8385d20c5a8271f..b61945f3af9e594aa28b2d992239bd4f4a714c6b 100644 (file)
        .idProduct = prod, \
        .bInterfaceClass = USB_CLASS_VENDOR_SPEC
 
+/* FTDI devices */
+{
+       USB_DEVICE(0x0403, 0xb8d8),
+       .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
+               /* .vendor_name = "STARR LABS", */
+               /* .product_name = "Starr Labs MIDI USB device", */
+               .ifnum = 0,
+               .type = QUIRK_MIDI_FTDI
+       }
+},
+
 /* Creative/Toshiba Multimedia Center SB-0500 */
 {
        USB_DEVICE(0x041e, 0x3048),
@@ -1677,6 +1688,20 @@ YAMAHA_DEVICE(0x7010, "UB99"),
                }
        }
 },
+{
+       /* Added support for Roland UM-ONE which differs from UM-1 */
+       USB_DEVICE(0x0582, 0x012a),
+       .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
+               /* .vendor_name = "ROLAND", */
+               /* .product_name = "UM-ONE", */
+               .ifnum = 0,
+               .type = QUIRK_MIDI_FIXED_ENDPOINT,
+               .data = & (const struct snd_usb_midi_endpoint_info) {
+                       .out_cables = 0x0001,
+                       .in_cables  = 0x0003
+               }
+       }
+},
 {
        USB_DEVICE(0x0582, 0x011e),
        .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
index 81e07d842581771ac82d4a3107f2a54cd69663e3..2e5bc73440262a14f3e34472516aedf31ff4981a 100644 (file)
@@ -34,6 +34,7 @@
 #include "endpoint.h"
 #include "pcm.h"
 #include "clock.h"
+#include "stream.h"
 
 /*
  * handle the quirks for the contained interfaces
@@ -106,7 +107,7 @@ static int create_standard_audio_quirk(struct snd_usb_audio *chip,
 
        alts = &iface->altsetting[0];
        altsd = get_iface_desc(alts);
-       err = snd_usb_parse_audio_endpoints(chip, altsd->bInterfaceNumber);
+       err = snd_usb_parse_audio_interface(chip, altsd->bInterfaceNumber);
        if (err < 0) {
                snd_printk(KERN_ERR "cannot setup if %d: error %d\n",
                           altsd->bInterfaceNumber, err);
@@ -147,7 +148,7 @@ static int create_fixed_stream_quirk(struct snd_usb_audio *chip,
 
        stream = (fp->endpoint & USB_DIR_IN)
                ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
-       err = snd_usb_add_audio_endpoint(chip, stream, fp);
+       err = snd_usb_add_audio_stream(chip, stream, fp);
        if (err < 0) {
                kfree(fp);
                kfree(rate_table);
@@ -254,7 +255,7 @@ static int create_uaxx_quirk(struct snd_usb_audio *chip,
 
        stream = (fp->endpoint & USB_DIR_IN)
                ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
-       err = snd_usb_add_audio_endpoint(chip, stream, fp);
+       err = snd_usb_add_audio_stream(chip, stream, fp);
        if (err < 0) {
                kfree(fp);
                return err;
@@ -306,6 +307,7 @@ int snd_usb_create_quirk(struct snd_usb_audio *chip,
                [QUIRK_MIDI_EMAGIC] = create_any_midi_quirk,
                [QUIRK_MIDI_CME] = create_any_midi_quirk,
                [QUIRK_MIDI_AKAI] = create_any_midi_quirk,
+               [QUIRK_MIDI_FTDI] = create_any_midi_quirk,
                [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk,
                [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk,
                [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk,
@@ -338,7 +340,7 @@ static int snd_usb_extigy_boot_quirk(struct usb_device *dev, struct usb_interfac
                snd_printdd("sending Extigy boot sequence...\n");
                /* Send message to force it to reconnect with full interface. */
                err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev,0),
-                                     0x10, 0x43, 0x0001, 0x000a, NULL, 0, 1000);
+                                     0x10, 0x43, 0x0001, 0x000a, NULL, 0);
                if (err < 0) snd_printdd("error sending boot message: %d\n", err);
                err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
                                &dev->descriptor, sizeof(dev->descriptor));
@@ -359,11 +361,11 @@ static int snd_usb_audigy2nx_boot_quirk(struct usb_device *dev)
 
        snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), 0x2a,
                        USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER,
-                       0, 0, &buf, 1, 1000);
+                       0, 0, &buf, 1);
        if (buf == 0) {
                snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0x29,
                                USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
-                               1, 2000, NULL, 0, 1000);
+                               1, 2000, NULL, 0);
                return -ENODEV;
        }
        return 0;
@@ -406,7 +408,7 @@ static int snd_usb_cm106_write_int_reg(struct usb_device *dev, int reg, u16 valu
        buf[3] = reg;
        return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_CONFIGURATION,
                               USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_ENDPOINT,
-                              0, 0, &buf, 4, 1000);
+                              0, 0, &buf, 4);
 }
 
 static int snd_usb_cm106_boot_quirk(struct usb_device *dev)
diff --git a/sound/usb/stream.c b/sound/usb/stream.c
new file mode 100644 (file)
index 0000000..5ff8010
--- /dev/null
@@ -0,0 +1,452 @@
+/*
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ */
+
+
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/usb.h>
+#include <linux/usb/audio.h>
+#include <linux/usb/audio-v2.h>
+
+#include <sound/core.h>
+#include <sound/pcm.h>
+
+#include "usbaudio.h"
+#include "card.h"
+#include "proc.h"
+#include "quirks.h"
+#include "endpoint.h"
+#include "pcm.h"
+#include "helper.h"
+#include "format.h"
+#include "clock.h"
+#include "stream.h"
+
+/*
+ * free a substream
+ */
+static void free_substream(struct snd_usb_substream *subs)
+{
+       struct list_head *p, *n;
+
+       if (!subs->num_formats)
+               return; /* not initialized */
+       list_for_each_safe(p, n, &subs->fmt_list) {
+               struct audioformat *fp = list_entry(p, struct audioformat, list);
+               kfree(fp->rate_table);
+               kfree(fp);
+       }
+       kfree(subs->rate_list.list);
+}
+
+
+/*
+ * free a usb stream instance
+ */
+static void snd_usb_audio_stream_free(struct snd_usb_stream *stream)
+{
+       free_substream(&stream->substream[0]);
+       free_substream(&stream->substream[1]);
+       list_del(&stream->list);
+       kfree(stream);
+}
+
+static void snd_usb_audio_pcm_free(struct snd_pcm *pcm)
+{
+       struct snd_usb_stream *stream = pcm->private_data;
+       if (stream) {
+               stream->pcm = NULL;
+               snd_usb_audio_stream_free(stream);
+       }
+}
+
+
+/*
+ * add this endpoint to the chip instance.
+ * if a stream with the same endpoint already exists, append to it.
+ * if not, create a new pcm stream.
+ */
+int snd_usb_add_audio_stream(struct snd_usb_audio *chip,
+                            int stream,
+                            struct audioformat *fp)
+{
+       struct list_head *p;
+       struct snd_usb_stream *as;
+       struct snd_usb_substream *subs;
+       struct snd_pcm *pcm;
+       int err;
+
+       list_for_each(p, &chip->pcm_list) {
+               as = list_entry(p, struct snd_usb_stream, list);
+               if (as->fmt_type != fp->fmt_type)
+                       continue;
+               subs = &as->substream[stream];
+               if (!subs->endpoint)
+                       continue;
+               if (subs->endpoint == fp->endpoint) {
+                       list_add_tail(&fp->list, &subs->fmt_list);
+                       subs->num_formats++;
+                       subs->formats |= fp->formats;
+                       return 0;
+               }
+       }
+       /* look for an empty stream */
+       list_for_each(p, &chip->pcm_list) {
+               as = list_entry(p, struct snd_usb_stream, list);
+               if (as->fmt_type != fp->fmt_type)
+                       continue;
+               subs = &as->substream[stream];
+               if (subs->endpoint)
+                       continue;
+               err = snd_pcm_new_stream(as->pcm, stream, 1);
+               if (err < 0)
+                       return err;
+               snd_usb_init_substream(as, stream, fp);
+               return 0;
+       }
+
+       /* create a new pcm */
+       as = kzalloc(sizeof(*as), GFP_KERNEL);
+       if (!as)
+               return -ENOMEM;
+       as->pcm_index = chip->pcm_devs;
+       as->chip = chip;
+       as->fmt_type = fp->fmt_type;
+       err = snd_pcm_new(chip->card, "USB Audio", chip->pcm_devs,
+                         stream == SNDRV_PCM_STREAM_PLAYBACK ? 1 : 0,
+                         stream == SNDRV_PCM_STREAM_PLAYBACK ? 0 : 1,
+                         &pcm);
+       if (err < 0) {
+               kfree(as);
+               return err;
+       }
+       as->pcm = pcm;
+       pcm->private_data = as;
+       pcm->private_free = snd_usb_audio_pcm_free;
+       pcm->info_flags = 0;
+       if (chip->pcm_devs > 0)
+               sprintf(pcm->name, "USB Audio #%d", chip->pcm_devs);
+       else
+               strcpy(pcm->name, "USB Audio");
+
+       snd_usb_init_substream(as, stream, fp);
+
+       list_add(&as->list, &chip->pcm_list);
+       chip->pcm_devs++;
+
+       snd_usb_proc_pcm_format_add(as);
+
+       return 0;
+}
+
+static int parse_uac_endpoint_attributes(struct snd_usb_audio *chip,
+                                        struct usb_host_interface *alts,
+                                        int protocol, int iface_no)
+{
+       /* parsed with a v1 header here. that's ok as we only look at the
+        * header first which is the same for both versions */
+       struct uac_iso_endpoint_descriptor *csep;
+       struct usb_interface_descriptor *altsd = get_iface_desc(alts);
+       int attributes = 0;
+
+       csep = snd_usb_find_desc(alts->endpoint[0].extra, alts->endpoint[0].extralen, NULL, USB_DT_CS_ENDPOINT);
+
+       /* Creamware Noah has this descriptor after the 2nd endpoint */
+       if (!csep && altsd->bNumEndpoints >= 2)
+               csep = snd_usb_find_desc(alts->endpoint[1].extra, alts->endpoint[1].extralen, NULL, USB_DT_CS_ENDPOINT);
+
+       if (!csep || csep->bLength < 7 ||
+           csep->bDescriptorSubtype != UAC_EP_GENERAL) {
+               snd_printk(KERN_WARNING "%d:%u:%d : no or invalid"
+                          " class specific endpoint descriptor\n",
+                          chip->dev->devnum, iface_no,
+                          altsd->bAlternateSetting);
+               return 0;
+       }
+
+       if (protocol == UAC_VERSION_1) {
+               attributes = csep->bmAttributes;
+       } else {
+               struct uac2_iso_endpoint_descriptor *csep2 =
+                       (struct uac2_iso_endpoint_descriptor *) csep;
+
+               attributes = csep->bmAttributes & UAC_EP_CS_ATTR_FILL_MAX;
+
+               /* emulate the endpoint attributes of a v1 device */
+               if (csep2->bmControls & UAC2_CONTROL_PITCH)
+                       attributes |= UAC_EP_CS_ATTR_PITCH_CONTROL;
+       }
+
+       return attributes;
+}
+
+static struct uac2_input_terminal_descriptor *
+       snd_usb_find_input_terminal_descriptor(struct usb_host_interface *ctrl_iface,
+                                              int terminal_id)
+{
+       struct uac2_input_terminal_descriptor *term = NULL;
+
+       while ((term = snd_usb_find_csint_desc(ctrl_iface->extra,
+                                              ctrl_iface->extralen,
+                                              term, UAC_INPUT_TERMINAL))) {
+               if (term->bTerminalID == terminal_id)
+                       return term;
+       }
+
+       return NULL;
+}
+
+static struct uac2_output_terminal_descriptor *
+       snd_usb_find_output_terminal_descriptor(struct usb_host_interface *ctrl_iface,
+                                               int terminal_id)
+{
+       struct uac2_output_terminal_descriptor *term = NULL;
+
+       while ((term = snd_usb_find_csint_desc(ctrl_iface->extra,
+                                              ctrl_iface->extralen,
+                                              term, UAC_OUTPUT_TERMINAL))) {
+               if (term->bTerminalID == terminal_id)
+                       return term;
+       }
+
+       return NULL;
+}
+
+int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
+{
+       struct usb_device *dev;
+       struct usb_interface *iface;
+       struct usb_host_interface *alts;
+       struct usb_interface_descriptor *altsd;
+       int i, altno, err, stream;
+       int format = 0, num_channels = 0;
+       struct audioformat *fp = NULL;
+       int num, protocol, clock = 0;
+       struct uac_format_type_i_continuous_descriptor *fmt;
+
+       dev = chip->dev;
+
+       /* parse the interface's altsettings */
+       iface = usb_ifnum_to_if(dev, iface_no);
+
+       num = iface->num_altsetting;
+
+       /*
+        * Dallas DS4201 workaround: It presents 5 altsettings, but the last
+        * one misses syncpipe, and does not produce any sound.
+        */
+       if (chip->usb_id == USB_ID(0x04fa, 0x4201))
+               num = 4;
+
+       for (i = 0; i < num; i++) {
+               alts = &iface->altsetting[i];
+               altsd = get_iface_desc(alts);
+               protocol = altsd->bInterfaceProtocol;
+               /* skip invalid one */
+               if ((altsd->bInterfaceClass != USB_CLASS_AUDIO &&
+                    altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) ||
+                   (altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIOSTREAMING &&
+                    altsd->bInterfaceSubClass != USB_SUBCLASS_VENDOR_SPEC) ||
+                   altsd->bNumEndpoints < 1 ||
+                   le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) == 0)
+                       continue;
+               /* must be isochronous */
+               if ((get_endpoint(alts, 0)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) !=
+                   USB_ENDPOINT_XFER_ISOC)
+                       continue;
+               /* check direction */
+               stream = (get_endpoint(alts, 0)->bEndpointAddress & USB_DIR_IN) ?
+                       SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
+               altno = altsd->bAlternateSetting;
+
+               if (snd_usb_apply_interface_quirk(chip, iface_no, altno))
+                       continue;
+
+               /* get audio formats */
+               switch (protocol) {
+               default:
+                       snd_printdd(KERN_WARNING "%d:%u:%d: unknown interface protocol %#02x, assuming v1\n",
+                                   dev->devnum, iface_no, altno, protocol);
+                       protocol = UAC_VERSION_1;
+                       /* fall through */
+
+               case UAC_VERSION_1: {
+                       struct uac1_as_header_descriptor *as =
+                               snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL);
+
+                       if (!as) {
+                               snd_printk(KERN_ERR "%d:%u:%d : UAC_AS_GENERAL descriptor not found\n",
+                                          dev->devnum, iface_no, altno);
+                               continue;
+                       }
+
+                       if (as->bLength < sizeof(*as)) {
+                               snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_AS_GENERAL desc\n",
+                                          dev->devnum, iface_no, altno);
+                               continue;
+                       }
+
+                       format = le16_to_cpu(as->wFormatTag); /* remember the format value */
+                       break;
+               }
+
+               case UAC_VERSION_2: {
+                       struct uac2_input_terminal_descriptor *input_term;
+                       struct uac2_output_terminal_descriptor *output_term;
+                       struct uac2_as_header_descriptor *as =
+                               snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL);
+
+                       if (!as) {
+                               snd_printk(KERN_ERR "%d:%u:%d : UAC_AS_GENERAL descriptor not found\n",
+                                          dev->devnum, iface_no, altno);
+                               continue;
+                       }
+
+                       if (as->bLength < sizeof(*as)) {
+                               snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_AS_GENERAL desc\n",
+                                          dev->devnum, iface_no, altno);
+                               continue;
+                       }
+
+                       num_channels = as->bNrChannels;
+                       format = le32_to_cpu(as->bmFormats);
+
+                       /* lookup the terminal associated to this interface
+                        * to extract the clock */
+                       input_term = snd_usb_find_input_terminal_descriptor(chip->ctrl_intf,
+                                                                           as->bTerminalLink);
+                       if (input_term) {
+                               clock = input_term->bCSourceID;
+                               break;
+                       }
+
+                       output_term = snd_usb_find_output_terminal_descriptor(chip->ctrl_intf,
+                                                                             as->bTerminalLink);
+                       if (output_term) {
+                               clock = output_term->bCSourceID;
+                               break;
+                       }
+
+                       snd_printk(KERN_ERR "%d:%u:%d : bogus bTerminalLink %d\n",
+                                  dev->devnum, iface_no, altno, as->bTerminalLink);
+                       continue;
+               }
+               }
+
+               /* get format type */
+               fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_FORMAT_TYPE);
+               if (!fmt) {
+                       snd_printk(KERN_ERR "%d:%u:%d : no UAC_FORMAT_TYPE desc\n",
+                                  dev->devnum, iface_no, altno);
+                       continue;
+               }
+               if (((protocol == UAC_VERSION_1) && (fmt->bLength < 8)) ||
+                   ((protocol == UAC_VERSION_2) && (fmt->bLength < 6))) {
+                       snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_FORMAT_TYPE desc\n",
+                                  dev->devnum, iface_no, altno);
+                       continue;
+               }
+
+               /*
+                * Blue Microphones workaround: The last altsetting is identical
+                * with the previous one, except for a larger packet size, but
+                * is actually a mislabeled two-channel setting; ignore it.
+                */
+               if (fmt->bNrChannels == 1 &&
+                   fmt->bSubframeSize == 2 &&
+                   altno == 2 && num == 3 &&
+                   fp && fp->altsetting == 1 && fp->channels == 1 &&
+                   fp->formats == SNDRV_PCM_FMTBIT_S16_LE &&
+                   protocol == UAC_VERSION_1 &&
+                   le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) ==
+                                                       fp->maxpacksize * 2)
+                       continue;
+
+               fp = kzalloc(sizeof(*fp), GFP_KERNEL);
+               if (! fp) {
+                       snd_printk(KERN_ERR "cannot malloc\n");
+                       return -ENOMEM;
+               }
+
+               fp->iface = iface_no;
+               fp->altsetting = altno;
+               fp->altset_idx = i;
+               fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
+               fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
+               fp->datainterval = snd_usb_parse_datainterval(chip, alts);
+               fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
+               /* num_channels is only set for v2 interfaces */
+               fp->channels = num_channels;
+               if (snd_usb_get_speed(dev) == USB_SPEED_HIGH)
+                       fp->maxpacksize = (((fp->maxpacksize >> 11) & 3) + 1)
+                                       * (fp->maxpacksize & 0x7ff);
+               fp->attributes = parse_uac_endpoint_attributes(chip, alts, protocol, iface_no);
+               fp->clock = clock;
+
+               /* some quirks for attributes here */
+
+               switch (chip->usb_id) {
+               case USB_ID(0x0a92, 0x0053): /* AudioTrak Optoplay */
+                       /* Optoplay sets the sample rate attribute although
+                        * it seems not supporting it in fact.
+                        */
+                       fp->attributes &= ~UAC_EP_CS_ATTR_SAMPLE_RATE;
+                       break;
+               case USB_ID(0x041e, 0x3020): /* Creative SB Audigy 2 NX */
+               case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
+                       /* doesn't set the sample rate attribute, but supports it */
+                       fp->attributes |= UAC_EP_CS_ATTR_SAMPLE_RATE;
+                       break;
+               case USB_ID(0x0763, 0x2001):  /* M-Audio Quattro USB */
+               case USB_ID(0x0763, 0x2012):  /* M-Audio Fast Track Pro USB */
+               case USB_ID(0x047f, 0x0ca1): /* plantronics headset */
+               case USB_ID(0x077d, 0x07af): /* Griffin iMic (note that there is
+                                               an older model 77d:223) */
+               /*
+                * plantronics headset and Griffin iMic have set adaptive-in
+                * although it's really not...
+                */
+                       fp->ep_attr &= ~USB_ENDPOINT_SYNCTYPE;
+                       if (stream == SNDRV_PCM_STREAM_PLAYBACK)
+                               fp->ep_attr |= USB_ENDPOINT_SYNC_ADAPTIVE;
+                       else
+                               fp->ep_attr |= USB_ENDPOINT_SYNC_SYNC;
+                       break;
+               }
+
+               /* ok, let's parse further... */
+               if (snd_usb_parse_audio_format(chip, fp, format, fmt, stream, alts) < 0) {
+                       kfree(fp->rate_table);
+                       kfree(fp);
+                       fp = NULL;
+                       continue;
+               }
+
+               snd_printdd(KERN_INFO "%d:%u:%d: add audio endpoint %#x\n", dev->devnum, iface_no, altno, fp->endpoint);
+               err = snd_usb_add_audio_stream(chip, stream, fp);
+               if (err < 0) {
+                       kfree(fp->rate_table);
+                       kfree(fp);
+                       return err;
+               }
+               /* try to set the interface... */
+               usb_set_interface(chip->dev, iface_no, altno);
+               snd_usb_init_pitch(chip, iface_no, alts, fp);
+               snd_usb_init_sample_rate(chip, iface_no, alts, fp, fp->rate_max);
+       }
+       return 0;
+}
+
diff --git a/sound/usb/stream.h b/sound/usb/stream.h
new file mode 100644 (file)
index 0000000..c97f679
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef __USBAUDIO_STREAM_H
+#define __USBAUDIO_STREAM_H
+
+int snd_usb_parse_audio_interface(struct snd_usb_audio *chip,
+                                 int iface_no);
+
+int snd_usb_add_audio_stream(struct snd_usb_audio *chip,
+                            int stream,
+                            struct audioformat *fp);
+
+#endif /* __USBAUDIO_STREAM_H */
+
diff --git a/sound/usb/urb.c b/sound/usb/urb.c
deleted file mode 100644 (file)
index e184349..0000000
+++ /dev/null
@@ -1,941 +0,0 @@
-/*
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
- *
- */
-
-#include <linux/gfp.h>
-#include <linux/init.h>
-#include <linux/usb.h>
-#include <linux/usb/audio.h>
-
-#include <sound/core.h>
-#include <sound/pcm.h>
-
-#include "usbaudio.h"
-#include "helper.h"
-#include "card.h"
-#include "urb.h"
-#include "pcm.h"
-
-/*
- * convert a sampling rate into our full speed format (fs/1000 in Q16.16)
- * this will overflow at approx 524 kHz
- */
-static inline unsigned get_usb_full_speed_rate(unsigned int rate)
-{
-       return ((rate << 13) + 62) / 125;
-}
-
-/*
- * convert a sampling rate into USB high speed format (fs/8000 in Q16.16)
- * this will overflow at approx 4 MHz
- */
-static inline unsigned get_usb_high_speed_rate(unsigned int rate)
-{
-       return ((rate << 10) + 62) / 125;
-}
-
-/*
- * unlink active urbs.
- */
-static int deactivate_urbs(struct snd_usb_substream *subs, int force, int can_sleep)
-{
-       struct snd_usb_audio *chip = subs->stream->chip;
-       unsigned int i;
-       int async;
-
-       subs->running = 0;
-
-       if (!force && subs->stream->chip->shutdown) /* to be sure... */
-               return -EBADFD;
-
-       async = !can_sleep && chip->async_unlink;
-
-       if (!async && in_interrupt())
-               return 0;
-
-       for (i = 0; i < subs->nurbs; i++) {
-               if (test_bit(i, &subs->active_mask)) {
-                       if (!test_and_set_bit(i, &subs->unlink_mask)) {
-                               struct urb *u = subs->dataurb[i].urb;
-                               if (async)
-                                       usb_unlink_urb(u);
-                               else
-                                       usb_kill_urb(u);
-                       }
-               }
-       }
-       if (subs->syncpipe) {
-               for (i = 0; i < SYNC_URBS; i++) {
-                       if (test_bit(i+16, &subs->active_mask)) {
-                               if (!test_and_set_bit(i+16, &subs->unlink_mask)) {
-                                       struct urb *u = subs->syncurb[i].urb;
-                                       if (async)
-                                               usb_unlink_urb(u);
-                                       else
-                                               usb_kill_urb(u);
-                               }
-                       }
-               }
-       }
-       return 0;
-}
-
-
-/*
- * release a urb data
- */
-static void release_urb_ctx(struct snd_urb_ctx *u)
-{
-       if (u->urb) {
-               if (u->buffer_size)
-                       usb_free_coherent(u->subs->dev, u->buffer_size,
-                                       u->urb->transfer_buffer,
-                                       u->urb->transfer_dma);
-               usb_free_urb(u->urb);
-               u->urb = NULL;
-       }
-}
-
-/*
- *  wait until all urbs are processed.
- */
-static int wait_clear_urbs(struct snd_usb_substream *subs)
-{
-       unsigned long end_time = jiffies + msecs_to_jiffies(1000);
-       unsigned int i;
-       int alive;
-
-       do {
-               alive = 0;
-               for (i = 0; i < subs->nurbs; i++) {
-                       if (test_bit(i, &subs->active_mask))
-                               alive++;
-               }
-               if (subs->syncpipe) {
-                       for (i = 0; i < SYNC_URBS; i++) {
-                               if (test_bit(i + 16, &subs->active_mask))
-                                       alive++;
-                       }
-               }
-               if (! alive)
-                       break;
-               schedule_timeout_uninterruptible(1);
-       } while (time_before(jiffies, end_time));
-       if (alive)
-               snd_printk(KERN_ERR "timeout: still %d active urbs..\n", alive);
-       return 0;
-}
-
-/*
- * release a substream
- */
-void snd_usb_release_substream_urbs(struct snd_usb_substream *subs, int force)
-{
-       int i;
-
-       /* stop urbs (to be sure) */
-       deactivate_urbs(subs, force, 1);
-       wait_clear_urbs(subs);
-
-       for (i = 0; i < MAX_URBS; i++)
-               release_urb_ctx(&subs->dataurb[i]);
-       for (i = 0; i < SYNC_URBS; i++)
-               release_urb_ctx(&subs->syncurb[i]);
-       usb_free_coherent(subs->dev, SYNC_URBS * 4,
-                       subs->syncbuf, subs->sync_dma);
-       subs->syncbuf = NULL;
-       subs->nurbs = 0;
-}
-
-/*
- * complete callback from data urb
- */
-static void snd_complete_urb(struct urb *urb)
-{
-       struct snd_urb_ctx *ctx = urb->context;
-       struct snd_usb_substream *subs = ctx->subs;
-       struct snd_pcm_substream *substream = ctx->subs->pcm_substream;
-       int err = 0;
-
-       if ((subs->running && subs->ops.retire(subs, substream->runtime, urb)) ||
-           !subs->running || /* can be stopped during retire callback */
-           (err = subs->ops.prepare(subs, substream->runtime, urb)) < 0 ||
-           (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
-               clear_bit(ctx->index, &subs->active_mask);
-               if (err < 0) {
-                       snd_printd(KERN_ERR "cannot submit urb (err = %d)\n", err);
-                       snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
-               }
-       }
-}
-
-
-/*
- * complete callback from sync urb
- */
-static void snd_complete_sync_urb(struct urb *urb)
-{
-       struct snd_urb_ctx *ctx = urb->context;
-       struct snd_usb_substream *subs = ctx->subs;
-       struct snd_pcm_substream *substream = ctx->subs->pcm_substream;
-       int err = 0;
-
-       if ((subs->running && subs->ops.retire_sync(subs, substream->runtime, urb)) ||
-           !subs->running || /* can be stopped during retire callback */
-           (err = subs->ops.prepare_sync(subs, substream->runtime, urb)) < 0 ||
-           (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
-               clear_bit(ctx->index + 16, &subs->active_mask);
-               if (err < 0) {
-                       snd_printd(KERN_ERR "cannot submit sync urb (err = %d)\n", err);
-                       snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
-               }
-       }
-}
-
-
-/*
- * initialize a substream for plaback/capture
- */
-int snd_usb_init_substream_urbs(struct snd_usb_substream *subs,
-                               unsigned int period_bytes,
-                               unsigned int rate,
-                               unsigned int frame_bits)
-{
-       unsigned int maxsize, i;
-       int is_playback = subs->direction == SNDRV_PCM_STREAM_PLAYBACK;
-       unsigned int urb_packs, total_packs, packs_per_ms;
-       struct snd_usb_audio *chip = subs->stream->chip;
-
-       /* calculate the frequency in 16.16 format */
-       if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL)
-               subs->freqn = get_usb_full_speed_rate(rate);
-       else
-               subs->freqn = get_usb_high_speed_rate(rate);
-       subs->freqm = subs->freqn;
-       subs->freqshift = INT_MIN;
-       /* calculate max. frequency */
-       if (subs->maxpacksize) {
-               /* whatever fits into a max. size packet */
-               maxsize = subs->maxpacksize;
-               subs->freqmax = (maxsize / (frame_bits >> 3))
-                               << (16 - subs->datainterval);
-       } else {
-               /* no max. packet size: just take 25% higher than nominal */
-               subs->freqmax = subs->freqn + (subs->freqn >> 2);
-               maxsize = ((subs->freqmax + 0xffff) * (frame_bits >> 3))
-                               >> (16 - subs->datainterval);
-       }
-       subs->phase = 0;
-
-       if (subs->fill_max)
-               subs->curpacksize = subs->maxpacksize;
-       else
-               subs->curpacksize = maxsize;
-
-       if (snd_usb_get_speed(subs->dev) != USB_SPEED_FULL)
-               packs_per_ms = 8 >> subs->datainterval;
-       else
-               packs_per_ms = 1;
-
-       if (is_playback) {
-               urb_packs = max(chip->nrpacks, 1);
-               urb_packs = min(urb_packs, (unsigned int)MAX_PACKS);
-       } else
-               urb_packs = 1;
-       urb_packs *= packs_per_ms;
-       if (subs->syncpipe)
-               urb_packs = min(urb_packs, 1U << subs->syncinterval);
-
-       /* decide how many packets to be used */
-       if (is_playback) {
-               unsigned int minsize, maxpacks;
-               /* determine how small a packet can be */
-               minsize = (subs->freqn >> (16 - subs->datainterval))
-                         * (frame_bits >> 3);
-               /* with sync from device, assume it can be 12% lower */
-               if (subs->syncpipe)
-                       minsize -= minsize >> 3;
-               minsize = max(minsize, 1u);
-               total_packs = (period_bytes + minsize - 1) / minsize;
-               /* we need at least two URBs for queueing */
-               if (total_packs < 2) {
-                       total_packs = 2;
-               } else {
-                       /* and we don't want too long a queue either */
-                       maxpacks = max(MAX_QUEUE * packs_per_ms, urb_packs * 2);
-                       total_packs = min(total_packs, maxpacks);
-               }
-       } else {
-               while (urb_packs > 1 && urb_packs * maxsize >= period_bytes)
-                       urb_packs >>= 1;
-               total_packs = MAX_URBS * urb_packs;
-       }
-       subs->nurbs = (total_packs + urb_packs - 1) / urb_packs;
-       if (subs->nurbs > MAX_URBS) {
-               /* too much... */
-               subs->nurbs = MAX_URBS;
-               total_packs = MAX_URBS * urb_packs;
-       } else if (subs->nurbs < 2) {
-               /* too little - we need at least two packets
-                * to ensure contiguous playback/capture
-                */
-               subs->nurbs = 2;
-       }
-
-       /* allocate and initialize data urbs */
-       for (i = 0; i < subs->nurbs; i++) {
-               struct snd_urb_ctx *u = &subs->dataurb[i];
-               u->index = i;
-               u->subs = subs;
-               u->packets = (i + 1) * total_packs / subs->nurbs
-                       - i * total_packs / subs->nurbs;
-               u->buffer_size = maxsize * u->packets;
-               if (subs->fmt_type == UAC_FORMAT_TYPE_II)
-                       u->packets++; /* for transfer delimiter */
-               u->urb = usb_alloc_urb(u->packets, GFP_KERNEL);
-               if (!u->urb)
-                       goto out_of_memory;
-               u->urb->transfer_buffer =
-                       usb_alloc_coherent(subs->dev, u->buffer_size,
-                                          GFP_KERNEL, &u->urb->transfer_dma);
-               if (!u->urb->transfer_buffer)
-                       goto out_of_memory;
-               u->urb->pipe = subs->datapipe;
-               u->urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
-               u->urb->interval = 1 << subs->datainterval;
-               u->urb->context = u;
-               u->urb->complete = snd_complete_urb;
-       }
-
-       if (subs->syncpipe) {
-               /* allocate and initialize sync urbs */
-               subs->syncbuf = usb_alloc_coherent(subs->dev, SYNC_URBS * 4,
-                                                GFP_KERNEL, &subs->sync_dma);
-               if (!subs->syncbuf)
-                       goto out_of_memory;
-               for (i = 0; i < SYNC_URBS; i++) {
-                       struct snd_urb_ctx *u = &subs->syncurb[i];
-                       u->index = i;
-                       u->subs = subs;
-                       u->packets = 1;
-                       u->urb = usb_alloc_urb(1, GFP_KERNEL);
-                       if (!u->urb)
-                               goto out_of_memory;
-                       u->urb->transfer_buffer = subs->syncbuf + i * 4;
-                       u->urb->transfer_dma = subs->sync_dma + i * 4;
-                       u->urb->transfer_buffer_length = 4;
-                       u->urb->pipe = subs->syncpipe;
-                       u->urb->transfer_flags = URB_ISO_ASAP |
-                                                URB_NO_TRANSFER_DMA_MAP;
-                       u->urb->number_of_packets = 1;
-                       u->urb->interval = 1 << subs->syncinterval;
-                       u->urb->context = u;
-                       u->urb->complete = snd_complete_sync_urb;
-               }
-       }
-       return 0;
-
-out_of_memory:
-       snd_usb_release_substream_urbs(subs, 0);
-       return -ENOMEM;
-}
-
-/*
- * prepare urb for full speed capture sync pipe
- *
- * fill the length and offset of each urb descriptor.
- * the fixed 10.14 frequency is passed through the pipe.
- */
-static int prepare_capture_sync_urb(struct snd_usb_substream *subs,
-                                   struct snd_pcm_runtime *runtime,
-                                   struct urb *urb)
-{
-       unsigned char *cp = urb->transfer_buffer;
-       struct snd_urb_ctx *ctx = urb->context;
-
-       urb->dev = ctx->subs->dev; /* we need to set this at each time */
-       urb->iso_frame_desc[0].length = 3;
-       urb->iso_frame_desc[0].offset = 0;
-       cp[0] = subs->freqn >> 2;
-       cp[1] = subs->freqn >> 10;
-       cp[2] = subs->freqn >> 18;
-       return 0;
-}
-
-/*
- * prepare urb for high speed capture sync pipe
- *
- * fill the length and offset of each urb descriptor.
- * the fixed 12.13 frequency is passed as 16.16 through the pipe.
- */
-static int prepare_capture_sync_urb_hs(struct snd_usb_substream *subs,
-                                      struct snd_pcm_runtime *runtime,
-                                      struct urb *urb)
-{
-       unsigned char *cp = urb->transfer_buffer;
-       struct snd_urb_ctx *ctx = urb->context;
-
-       urb->dev = ctx->subs->dev; /* we need to set this at each time */
-       urb->iso_frame_desc[0].length = 4;
-       urb->iso_frame_desc[0].offset = 0;
-       cp[0] = subs->freqn;
-       cp[1] = subs->freqn >> 8;
-       cp[2] = subs->freqn >> 16;
-       cp[3] = subs->freqn >> 24;
-       return 0;
-}
-
-/*
- * process after capture sync complete
- * - nothing to do
- */
-static int retire_capture_sync_urb(struct snd_usb_substream *subs,
-                                  struct snd_pcm_runtime *runtime,
-                                  struct urb *urb)
-{
-       return 0;
-}
-
-/*
- * prepare urb for capture data pipe
- *
- * fill the offset and length of each descriptor.
- *
- * we use a temporary buffer to write the captured data.
- * since the length of written data is determined by host, we cannot
- * write onto the pcm buffer directly...  the data is thus copied
- * later at complete callback to the global buffer.
- */
-static int prepare_capture_urb(struct snd_usb_substream *subs,
-                              struct snd_pcm_runtime *runtime,
-                              struct urb *urb)
-{
-       int i, offs;
-       struct snd_urb_ctx *ctx = urb->context;
-
-       offs = 0;
-       urb->dev = ctx->subs->dev; /* we need to set this at each time */
-       for (i = 0; i < ctx->packets; i++) {
-               urb->iso_frame_desc[i].offset = offs;
-               urb->iso_frame_desc[i].length = subs->curpacksize;
-               offs += subs->curpacksize;
-       }
-       urb->transfer_buffer_length = offs;
-       urb->number_of_packets = ctx->packets;
-       return 0;
-}
-
-/*
- * process after capture complete
- *
- * copy the data from each desctiptor to the pcm buffer, and
- * update the current position.
- */
-static int retire_capture_urb(struct snd_usb_substream *subs,
-                             struct snd_pcm_runtime *runtime,
-                             struct urb *urb)
-{
-       unsigned long flags;
-       unsigned char *cp;
-       int i;
-       unsigned int stride, frames, bytes, oldptr;
-       int period_elapsed = 0;
-
-       stride = runtime->frame_bits >> 3;
-
-       for (i = 0; i < urb->number_of_packets; i++) {
-               cp = (unsigned char *)urb->transfer_buffer + urb->iso_frame_desc[i].offset;
-               if (urb->iso_frame_desc[i].status) {
-                       snd_printd(KERN_ERR "frame %d active: %d\n", i, urb->iso_frame_desc[i].status);
-                       // continue;
-               }
-               bytes = urb->iso_frame_desc[i].actual_length;
-               frames = bytes / stride;
-               if (!subs->txfr_quirk)
-                       bytes = frames * stride;
-               if (bytes % (runtime->sample_bits >> 3) != 0) {
-#ifdef CONFIG_SND_DEBUG_VERBOSE
-                       int oldbytes = bytes;
-#endif
-                       bytes = frames * stride;
-                       snd_printdd(KERN_ERR "Corrected urb data len. %d->%d\n",
-                                                       oldbytes, bytes);
-               }
-               /* update the current pointer */
-               spin_lock_irqsave(&subs->lock, flags);
-               oldptr = subs->hwptr_done;
-               subs->hwptr_done += bytes;
-               if (subs->hwptr_done >= runtime->buffer_size * stride)
-                       subs->hwptr_done -= runtime->buffer_size * stride;
-               frames = (bytes + (oldptr % stride)) / stride;
-               subs->transfer_done += frames;
-               if (subs->transfer_done >= runtime->period_size) {
-                       subs->transfer_done -= runtime->period_size;
-                       period_elapsed = 1;
-               }
-               spin_unlock_irqrestore(&subs->lock, flags);
-               /* copy a data chunk */
-               if (oldptr + bytes > runtime->buffer_size * stride) {
-                       unsigned int bytes1 =
-                                       runtime->buffer_size * stride - oldptr;
-                       memcpy(runtime->dma_area + oldptr, cp, bytes1);
-                       memcpy(runtime->dma_area, cp + bytes1, bytes - bytes1);
-               } else {
-                       memcpy(runtime->dma_area + oldptr, cp, bytes);
-               }
-       }
-       if (period_elapsed)
-               snd_pcm_period_elapsed(subs->pcm_substream);
-       return 0;
-}
-
-/*
- * Process after capture complete when paused.  Nothing to do.
- */
-static int retire_paused_capture_urb(struct snd_usb_substream *subs,
-                                    struct snd_pcm_runtime *runtime,
-                                    struct urb *urb)
-{
-       return 0;
-}
-
-
-/*
- * prepare urb for playback sync pipe
- *
- * set up the offset and length to receive the current frequency.
- */
-static int prepare_playback_sync_urb(struct snd_usb_substream *subs,
-                                    struct snd_pcm_runtime *runtime,
-                                    struct urb *urb)
-{
-       struct snd_urb_ctx *ctx = urb->context;
-
-       urb->dev = ctx->subs->dev; /* we need to set this at each time */
-       urb->iso_frame_desc[0].length = min(4u, ctx->subs->syncmaxsize);
-       urb->iso_frame_desc[0].offset = 0;
-       return 0;
-}
-
-/*
- * process after playback sync complete
- *
- * Full speed devices report feedback values in 10.14 format as samples per
- * frame, high speed devices in 16.16 format as samples per microframe.
- * Because the Audio Class 1 spec was written before USB 2.0, many high speed
- * devices use a wrong interpretation, some others use an entirely different
- * format.  Therefore, we cannot predict what format any particular device uses
- * and must detect it automatically.
- */
-static int retire_playback_sync_urb(struct snd_usb_substream *subs,
-                                   struct snd_pcm_runtime *runtime,
-                                   struct urb *urb)
-{
-       unsigned int f;
-       int shift;
-       unsigned long flags;
-
-       if (urb->iso_frame_desc[0].status != 0 ||
-           urb->iso_frame_desc[0].actual_length < 3)
-               return 0;
-
-       f = le32_to_cpup(urb->transfer_buffer);
-       if (urb->iso_frame_desc[0].actual_length == 3)
-               f &= 0x00ffffff;
-       else
-               f &= 0x0fffffff;
-       if (f == 0)
-               return 0;
-
-       if (unlikely(subs->freqshift == INT_MIN)) {
-               /*
-                * The first time we see a feedback value, determine its format
-                * by shifting it left or right until it matches the nominal
-                * frequency value.  This assumes that the feedback does not
-                * differ from the nominal value more than +50% or -25%.
-                */
-               shift = 0;
-               while (f < subs->freqn - subs->freqn / 4) {
-                       f <<= 1;
-                       shift++;
-               }
-               while (f > subs->freqn + subs->freqn / 2) {
-                       f >>= 1;
-                       shift--;
-               }
-               subs->freqshift = shift;
-       }
-       else if (subs->freqshift >= 0)
-               f <<= subs->freqshift;
-       else
-               f >>= -subs->freqshift;
-
-       if (likely(f >= subs->freqn - subs->freqn / 8 && f <= subs->freqmax)) {
-               /*
-                * If the frequency looks valid, set it.
-                * This value is referred to in prepare_playback_urb().
-                */
-               spin_lock_irqsave(&subs->lock, flags);
-               subs->freqm = f;
-               spin_unlock_irqrestore(&subs->lock, flags);
-       } else {
-               /*
-                * Out of range; maybe the shift value is wrong.
-                * Reset it so that we autodetect again the next time.
-                */
-               subs->freqshift = INT_MIN;
-       }
-
-       return 0;
-}
-
-/* determine the number of frames in the next packet */
-static int snd_usb_audio_next_packet_size(struct snd_usb_substream *subs)
-{
-       if (subs->fill_max)
-               return subs->maxframesize;
-       else {
-               subs->phase = (subs->phase & 0xffff)
-                       + (subs->freqm << subs->datainterval);
-               return min(subs->phase >> 16, subs->maxframesize);
-       }
-}
-
-/*
- * Prepare urb for streaming before playback starts or when paused.
- *
- * We don't have any data, so we send silence.
- */
-static int prepare_nodata_playback_urb(struct snd_usb_substream *subs,
-                                      struct snd_pcm_runtime *runtime,
-                                      struct urb *urb)
-{
-       unsigned int i, offs, counts;
-       struct snd_urb_ctx *ctx = urb->context;
-       int stride = runtime->frame_bits >> 3;
-
-       offs = 0;
-       urb->dev = ctx->subs->dev;
-       for (i = 0; i < ctx->packets; ++i) {
-               counts = snd_usb_audio_next_packet_size(subs);
-               urb->iso_frame_desc[i].offset = offs * stride;
-               urb->iso_frame_desc[i].length = counts * stride;
-               offs += counts;
-       }
-       urb->number_of_packets = ctx->packets;
-       urb->transfer_buffer_length = offs * stride;
-       memset(urb->transfer_buffer,
-              runtime->format == SNDRV_PCM_FORMAT_U8 ? 0x80 : 0,
-              offs * stride);
-       return 0;
-}
-
-/*
- * prepare urb for playback data pipe
- *
- * Since a URB can handle only a single linear buffer, we must use double
- * buffering when the data to be transferred overflows the buffer boundary.
- * To avoid inconsistencies when updating hwptr_done, we use double buffering
- * for all URBs.
- */
-static int prepare_playback_urb(struct snd_usb_substream *subs,
-                               struct snd_pcm_runtime *runtime,
-                               struct urb *urb)
-{
-       int i, stride;
-       unsigned int counts, frames, bytes;
-       unsigned long flags;
-       int period_elapsed = 0;
-       struct snd_urb_ctx *ctx = urb->context;
-
-       stride = runtime->frame_bits >> 3;
-
-       frames = 0;
-       urb->dev = ctx->subs->dev; /* we need to set this at each time */
-       urb->number_of_packets = 0;
-       spin_lock_irqsave(&subs->lock, flags);
-       for (i = 0; i < ctx->packets; i++) {
-               counts = snd_usb_audio_next_packet_size(subs);
-               /* set up descriptor */
-               urb->iso_frame_desc[i].offset = frames * stride;
-               urb->iso_frame_desc[i].length = counts * stride;
-               frames += counts;
-               urb->number_of_packets++;
-               subs->transfer_done += counts;
-               if (subs->transfer_done >= runtime->period_size) {
-                       subs->transfer_done -= runtime->period_size;
-                       period_elapsed = 1;
-                       if (subs->fmt_type == UAC_FORMAT_TYPE_II) {
-                               if (subs->transfer_done > 0) {
-                                       /* FIXME: fill-max mode is not
-                                        * supported yet */
-                                       frames -= subs->transfer_done;
-                                       counts -= subs->transfer_done;
-                                       urb->iso_frame_desc[i].length =
-                                               counts * stride;
-                                       subs->transfer_done = 0;
-                               }
-                               i++;
-                               if (i < ctx->packets) {
-                                       /* add a transfer delimiter */
-                                       urb->iso_frame_desc[i].offset =
-                                               frames * stride;
-                                       urb->iso_frame_desc[i].length = 0;
-                                       urb->number_of_packets++;
-                               }
-                               break;
-                       }
-               }
-               if (period_elapsed) /* finish at the period boundary */
-                       break;
-       }
-       bytes = frames * stride;
-       if (subs->hwptr_done + bytes > runtime->buffer_size * stride) {
-               /* err, the transferred area goes over buffer boundary. */
-               unsigned int bytes1 =
-                       runtime->buffer_size * stride - subs->hwptr_done;
-               memcpy(urb->transfer_buffer,
-                      runtime->dma_area + subs->hwptr_done, bytes1);
-               memcpy(urb->transfer_buffer + bytes1,
-                      runtime->dma_area, bytes - bytes1);
-       } else {
-               memcpy(urb->transfer_buffer,
-                      runtime->dma_area + subs->hwptr_done, bytes);
-       }
-       subs->hwptr_done += bytes;
-       if (subs->hwptr_done >= runtime->buffer_size * stride)
-               subs->hwptr_done -= runtime->buffer_size * stride;
-       runtime->delay += frames;
-       spin_unlock_irqrestore(&subs->lock, flags);
-       urb->transfer_buffer_length = bytes;
-       if (period_elapsed)
-               snd_pcm_period_elapsed(subs->pcm_substream);
-       return 0;
-}
-
-/*
- * process after playback data complete
- * - decrease the delay count again
- */
-static int retire_playback_urb(struct snd_usb_substream *subs,
-                              struct snd_pcm_runtime *runtime,
-                              struct urb *urb)
-{
-       unsigned long flags;
-       int stride = runtime->frame_bits >> 3;
-       int processed = urb->transfer_buffer_length / stride;
-
-       spin_lock_irqsave(&subs->lock, flags);
-       if (processed > runtime->delay)
-               runtime->delay = 0;
-       else
-               runtime->delay -= processed;
-       spin_unlock_irqrestore(&subs->lock, flags);
-       return 0;
-}
-
-static const char *usb_error_string(int err)
-{
-       switch (err) {
-       case -ENODEV:
-               return "no device";
-       case -ENOENT:
-               return "endpoint not enabled";
-       case -EPIPE:
-               return "endpoint stalled";
-       case -ENOSPC:
-               return "not enough bandwidth";
-       case -ESHUTDOWN:
-               return "device disabled";
-       case -EHOSTUNREACH:
-               return "device suspended";
-       case -EINVAL:
-       case -EAGAIN:
-       case -EFBIG:
-       case -EMSGSIZE:
-               return "internal error";
-       default:
-               return "unknown error";
-       }
-}
-
-/*
- * set up and start data/sync urbs
- */
-static int start_urbs(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime)
-{
-       unsigned int i;
-       int err;
-
-       if (subs->stream->chip->shutdown)
-               return -EBADFD;
-
-       for (i = 0; i < subs->nurbs; i++) {
-               if (snd_BUG_ON(!subs->dataurb[i].urb))
-                       return -EINVAL;
-               if (subs->ops.prepare(subs, runtime, subs->dataurb[i].urb) < 0) {
-                       snd_printk(KERN_ERR "cannot prepare datapipe for urb %d\n", i);
-                       goto __error;
-               }
-       }
-       if (subs->syncpipe) {
-               for (i = 0; i < SYNC_URBS; i++) {
-                       if (snd_BUG_ON(!subs->syncurb[i].urb))
-                               return -EINVAL;
-                       if (subs->ops.prepare_sync(subs, runtime, subs->syncurb[i].urb) < 0) {
-                               snd_printk(KERN_ERR "cannot prepare syncpipe for urb %d\n", i);
-                               goto __error;
-                       }
-               }
-       }
-
-       subs->active_mask = 0;
-       subs->unlink_mask = 0;
-       subs->running = 1;
-       for (i = 0; i < subs->nurbs; i++) {
-               err = usb_submit_urb(subs->dataurb[i].urb, GFP_ATOMIC);
-               if (err < 0) {
-                       snd_printk(KERN_ERR "cannot submit datapipe "
-                                  "for urb %d, error %d: %s\n",
-                                  i, err, usb_error_string(err));
-                       goto __error;
-               }
-               set_bit(i, &subs->active_mask);
-       }
-       if (subs->syncpipe) {
-               for (i = 0; i < SYNC_URBS; i++) {
-                       err = usb_submit_urb(subs->syncurb[i].urb, GFP_ATOMIC);
-                       if (err < 0) {
-                               snd_printk(KERN_ERR "cannot submit syncpipe "
-                                          "for urb %d, error %d: %s\n",
-                                          i, err, usb_error_string(err));
-                               goto __error;
-                       }
-                       set_bit(i + 16, &subs->active_mask);
-               }
-       }
-       return 0;
-
- __error:
-       // snd_pcm_stop(subs->pcm_substream, SNDRV_PCM_STATE_XRUN);
-       deactivate_urbs(subs, 0, 0);
-       return -EPIPE;
-}
-
-
-/*
- */
-static struct snd_urb_ops audio_urb_ops[2] = {
-       {
-               .prepare =      prepare_nodata_playback_urb,
-               .retire =       retire_playback_urb,
-               .prepare_sync = prepare_playback_sync_urb,
-               .retire_sync =  retire_playback_sync_urb,
-       },
-       {
-               .prepare =      prepare_capture_urb,
-               .retire =       retire_capture_urb,
-               .prepare_sync = prepare_capture_sync_urb,
-               .retire_sync =  retire_capture_sync_urb,
-       },
-};
-
-/*
- * initialize the substream instance.
- */
-
-void snd_usb_init_substream(struct snd_usb_stream *as,
-                           int stream, struct audioformat *fp)
-{
-       struct snd_usb_substream *subs = &as->substream[stream];
-
-       INIT_LIST_HEAD(&subs->fmt_list);
-       spin_lock_init(&subs->lock);
-
-       subs->stream = as;
-       subs->direction = stream;
-       subs->dev = as->chip->dev;
-       subs->txfr_quirk = as->chip->txfr_quirk;
-       subs->ops = audio_urb_ops[stream];
-       if (snd_usb_get_speed(subs->dev) >= USB_SPEED_HIGH)
-               subs->ops.prepare_sync = prepare_capture_sync_urb_hs;
-
-       snd_usb_set_pcm_ops(as->pcm, stream);
-
-       list_add_tail(&fp->list, &subs->fmt_list);
-       subs->formats |= fp->formats;
-       subs->endpoint = fp->endpoint;
-       subs->num_formats++;
-       subs->fmt_type = fp->fmt_type;
-}
-
-int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substream, int cmd)
-{
-       struct snd_usb_substream *subs = substream->runtime->private_data;
-
-       switch (cmd) {
-       case SNDRV_PCM_TRIGGER_START:
-       case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
-               subs->ops.prepare = prepare_playback_urb;
-               return 0;
-       case SNDRV_PCM_TRIGGER_STOP:
-               return deactivate_urbs(subs, 0, 0);
-       case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
-               subs->ops.prepare = prepare_nodata_playback_urb;
-               return 0;
-       }
-
-       return -EINVAL;
-}
-
-int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream, int cmd)
-{
-       struct snd_usb_substream *subs = substream->runtime->private_data;
-
-       switch (cmd) {
-       case SNDRV_PCM_TRIGGER_START:
-               subs->ops.retire = retire_capture_urb;
-               return start_urbs(subs, substream->runtime);
-       case SNDRV_PCM_TRIGGER_STOP:
-               return deactivate_urbs(subs, 0, 0);
-       case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
-               subs->ops.retire = retire_paused_capture_urb;
-               return 0;
-       case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
-               subs->ops.retire = retire_capture_urb;
-               return 0;
-       }
-
-       return -EINVAL;
-}
-
-int snd_usb_substream_prepare(struct snd_usb_substream *subs,
-                             struct snd_pcm_runtime *runtime)
-{
-       /* clear urbs (to be sure) */
-       deactivate_urbs(subs, 0, 1);
-       wait_clear_urbs(subs);
-
-       /* for playback, submit the URBs now; otherwise, the first hwptr_done
-        * updates for all URBs would happen at the same time when starting */
-       if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) {
-               subs->ops.prepare = prepare_nodata_playback_urb;
-               return start_urbs(subs, runtime);
-       }
-
-       return 0;
-}
-
diff --git a/sound/usb/urb.h b/sound/usb/urb.h
deleted file mode 100644 (file)
index 888da38..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-#ifndef __USBAUDIO_URB_H
-#define __USBAUDIO_URB_H
-
-void snd_usb_init_substream(struct snd_usb_stream *as,
-                           int stream,
-                           struct audioformat *fp);
-
-int snd_usb_init_substream_urbs(struct snd_usb_substream *subs,
-                               unsigned int period_bytes,
-                               unsigned int rate,
-                               unsigned int frame_bits);
-
-void snd_usb_release_substream_urbs(struct snd_usb_substream *subs, int force);
-
-int snd_usb_substream_prepare(struct snd_usb_substream *subs,
-                             struct snd_pcm_runtime *runtime);
-
-int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substream, int cmd);
-int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream, int cmd);
-
-#endif /* __USBAUDIO_URB_H */
index 1e79986b577749ca0ebea31aa7b5c7c46ac750b1..3e2b035779362d6adc733ba5fa8396590e98e8d6 100644 (file)
@@ -80,6 +80,7 @@ enum quirk_type {
        QUIRK_MIDI_CME,
        QUIRK_MIDI_AKAI,
        QUIRK_MIDI_US122L,
+       QUIRK_MIDI_FTDI,
        QUIRK_AUDIO_STANDARD_INTERFACE,
        QUIRK_AUDIO_FIXED_ENDPOINT,
        QUIRK_AUDIO_EDIROL_UAXX,
index eaf3a50f976947560ee9a9e4827cbe71d2879d11..3ad0925d23a9c85e39b508021ef9fcf2bbb1ad81 100644 (file)
@@ -58,8 +58,6 @@ static int find_index_from_host_irq(struct kvm_assigned_dev_kernel
 static irqreturn_t kvm_assigned_dev_thread(int irq, void *dev_id)
 {
        struct kvm_assigned_dev_kernel *assigned_dev = dev_id;
-       u32 vector;
-       int index;
 
        if (assigned_dev->irq_requested_type & KVM_DEV_IRQ_HOST_INTX) {
                spin_lock(&assigned_dev->intx_lock);
@@ -68,31 +66,35 @@ static irqreturn_t kvm_assigned_dev_thread(int irq, void *dev_id)
                spin_unlock(&assigned_dev->intx_lock);
        }
 
-       if (assigned_dev->irq_requested_type & KVM_DEV_IRQ_HOST_MSIX) {
-               index = find_index_from_host_irq(assigned_dev, irq);
-               if (index >= 0) {
-                       vector = assigned_dev->
-                                       guest_msix_entries[index].vector;
-                       kvm_set_irq(assigned_dev->kvm,
-                                   assigned_dev->irq_source_id, vector, 1);
-               }
-       } else
+       kvm_set_irq(assigned_dev->kvm, assigned_dev->irq_source_id,
+                   assigned_dev->guest_irq, 1);
+
+       return IRQ_HANDLED;
+}
+
+#ifdef __KVM_HAVE_MSIX
+static irqreturn_t kvm_assigned_dev_thread_msix(int irq, void *dev_id)
+{
+       struct kvm_assigned_dev_kernel *assigned_dev = dev_id;
+       int index = find_index_from_host_irq(assigned_dev, irq);
+       u32 vector;
+
+       if (index >= 0) {
+               vector = assigned_dev->guest_msix_entries[index].vector;
                kvm_set_irq(assigned_dev->kvm, assigned_dev->irq_source_id,
-                           assigned_dev->guest_irq, 1);
+                           vector, 1);
+       }
 
        return IRQ_HANDLED;
 }
+#endif
 
 /* Ack the irq line for an assigned device */
 static void kvm_assigned_dev_ack_irq(struct kvm_irq_ack_notifier *kian)
 {
-       struct kvm_assigned_dev_kernel *dev;
-
-       if (kian->gsi == -1)
-               return;
-
-       dev = container_of(kian, struct kvm_assigned_dev_kernel,
-                          ack_notifier);
+       struct kvm_assigned_dev_kernel *dev =
+               container_of(kian, struct kvm_assigned_dev_kernel,
+                            ack_notifier);
 
        kvm_set_irq(dev->kvm, dev->irq_source_id, dev->guest_irq, 0);
 
@@ -110,8 +112,9 @@ static void kvm_assigned_dev_ack_irq(struct kvm_irq_ack_notifier *kian)
 static void deassign_guest_irq(struct kvm *kvm,
                               struct kvm_assigned_dev_kernel *assigned_dev)
 {
-       kvm_unregister_irq_ack_notifier(kvm, &assigned_dev->ack_notifier);
-       assigned_dev->ack_notifier.gsi = -1;
+       if (assigned_dev->ack_notifier.gsi != -1)
+               kvm_unregister_irq_ack_notifier(kvm,
+                                               &assigned_dev->ack_notifier);
 
        kvm_set_irq(assigned_dev->kvm, assigned_dev->irq_source_id,
                    assigned_dev->guest_irq, 0);
@@ -143,7 +146,7 @@ static void deassign_host_irq(struct kvm *kvm,
 
                for (i = 0; i < assigned_dev->entries_nr; i++)
                        free_irq(assigned_dev->host_msix_entries[i].vector,
-                                (void *)assigned_dev);
+                                assigned_dev);
 
                assigned_dev->entries_nr = 0;
                kfree(assigned_dev->host_msix_entries);
@@ -153,7 +156,7 @@ static void deassign_host_irq(struct kvm *kvm,
                /* Deal with MSI and INTx */
                disable_irq(assigned_dev->host_irq);
 
-               free_irq(assigned_dev->host_irq, (void *)assigned_dev);
+               free_irq(assigned_dev->host_irq, assigned_dev);
 
                if (assigned_dev->irq_requested_type & KVM_DEV_IRQ_HOST_MSI)
                        pci_disable_msi(assigned_dev->dev);
@@ -239,7 +242,7 @@ static int assigned_device_enable_host_intx(struct kvm *kvm,
         * are going to be long delays in accepting, acking, etc.
         */
        if (request_threaded_irq(dev->host_irq, NULL, kvm_assigned_dev_thread,
-                                IRQF_ONESHOT, dev->irq_name, (void *)dev))
+                                IRQF_ONESHOT, dev->irq_name, dev))
                return -EIO;
        return 0;
 }
@@ -258,7 +261,7 @@ static int assigned_device_enable_host_msi(struct kvm *kvm,
 
        dev->host_irq = dev->dev->irq;
        if (request_threaded_irq(dev->host_irq, NULL, kvm_assigned_dev_thread,
-                                0, dev->irq_name, (void *)dev)) {
+                                0, dev->irq_name, dev)) {
                pci_disable_msi(dev->dev);
                return -EIO;
        }
@@ -284,8 +287,8 @@ static int assigned_device_enable_host_msix(struct kvm *kvm,
 
        for (i = 0; i < dev->entries_nr; i++) {
                r = request_threaded_irq(dev->host_msix_entries[i].vector,
-                                        NULL, kvm_assigned_dev_thread,
-                                        0, dev->irq_name, (void *)dev);
+                                        NULL, kvm_assigned_dev_thread_msix,
+                                        0, dev->irq_name, dev);
                if (r)
                        goto err;
        }
@@ -293,7 +296,7 @@ static int assigned_device_enable_host_msix(struct kvm *kvm,
        return 0;
 err:
        for (i -= 1; i >= 0; i--)
-               free_irq(dev->host_msix_entries[i].vector, (void *)dev);
+               free_irq(dev->host_msix_entries[i].vector, dev);
        pci_disable_msix(dev->dev);
        return r;
 }
@@ -406,7 +409,8 @@ static int assign_guest_irq(struct kvm *kvm,
 
        if (!r) {
                dev->irq_requested_type |= guest_irq_type;
-               kvm_register_irq_ack_notifier(kvm, &dev->ack_notifier);
+               if (dev->ack_notifier.gsi != -1)
+                       kvm_register_irq_ack_notifier(kvm, &dev->ack_notifier);
        } else
                kvm_free_irq_source_id(kvm, dev->irq_source_id);
 
index fc8487564d1f2ac3d88ccd801451248b07e623f8..a6ec206f36ba2f16f43c90680535ff6bcc45d56f 100644 (file)
@@ -24,10 +24,19 @@ static inline struct kvm_coalesced_mmio_dev *to_mmio(struct kvm_io_device *dev)
 static int coalesced_mmio_in_range(struct kvm_coalesced_mmio_dev *dev,
                                   gpa_t addr, int len)
 {
-       struct kvm_coalesced_mmio_zone *zone;
+       /* is it in a batchable area ?
+        * (addr,len) is fully included in
+        * (zone->addr, zone->size)
+        */
+
+       return (dev->zone.addr <= addr &&
+               addr + len <= dev->zone.addr + dev->zone.size);
+}
+
+static int coalesced_mmio_has_room(struct kvm_coalesced_mmio_dev *dev)
+{
        struct kvm_coalesced_mmio_ring *ring;
        unsigned avail;
-       int i;
 
        /* Are we able to batch it ? */
 
@@ -37,25 +46,12 @@ static int coalesced_mmio_in_range(struct kvm_coalesced_mmio_dev *dev,
         */
        ring = dev->kvm->coalesced_mmio_ring;
        avail = (ring->first - ring->last - 1) % KVM_COALESCED_MMIO_MAX;
-       if (avail < KVM_MAX_VCPUS) {
+       if (avail == 0) {
                /* full */
                return 0;
        }
 
-       /* is it in a batchable area ? */
-
-       for (i = 0; i < dev->nb_zones; i++) {
-               zone = &dev->zone[i];
-
-               /* (addr,len) is fully included in
-                * (zone->addr, zone->size)
-                */
-
-               if (zone->addr <= addr &&
-                   addr + len <= zone->addr + zone->size)
-                       return 1;
-       }
-       return 0;
+       return 1;
 }
 
 static int coalesced_mmio_write(struct kvm_io_device *this,
@@ -63,10 +59,16 @@ static int coalesced_mmio_write(struct kvm_io_device *this,
 {
        struct kvm_coalesced_mmio_dev *dev = to_mmio(this);
        struct kvm_coalesced_mmio_ring *ring = dev->kvm->coalesced_mmio_ring;
+
        if (!coalesced_mmio_in_range(dev, addr, len))
                return -EOPNOTSUPP;
 
-       spin_lock(&dev->lock);
+       spin_lock(&dev->kvm->ring_lock);
+
+       if (!coalesced_mmio_has_room(dev)) {
+               spin_unlock(&dev->kvm->ring_lock);
+               return -EOPNOTSUPP;
+       }
 
        /* copy data in first free entry of the ring */
 
@@ -75,7 +77,7 @@ static int coalesced_mmio_write(struct kvm_io_device *this,
        memcpy(ring->coalesced_mmio[ring->last].data, val, len);
        smp_wmb();
        ring->last = (ring->last + 1) % KVM_COALESCED_MMIO_MAX;
-       spin_unlock(&dev->lock);
+       spin_unlock(&dev->kvm->ring_lock);
        return 0;
 }
 
@@ -83,6 +85,8 @@ static void coalesced_mmio_destructor(struct kvm_io_device *this)
 {
        struct kvm_coalesced_mmio_dev *dev = to_mmio(this);
 
+       list_del(&dev->list);
+
        kfree(dev);
 }
 
@@ -93,7 +97,6 @@ static const struct kvm_io_device_ops coalesced_mmio_ops = {
 
 int kvm_coalesced_mmio_init(struct kvm *kvm)
 {
-       struct kvm_coalesced_mmio_dev *dev;
        struct page *page;
        int ret;
 
@@ -101,31 +104,18 @@ int kvm_coalesced_mmio_init(struct kvm *kvm)
        page = alloc_page(GFP_KERNEL | __GFP_ZERO);
        if (!page)
                goto out_err;
-       kvm->coalesced_mmio_ring = page_address(page);
-
-       ret = -ENOMEM;
-       dev = kzalloc(sizeof(struct kvm_coalesced_mmio_dev), GFP_KERNEL);
-       if (!dev)
-               goto out_free_page;
-       spin_lock_init(&dev->lock);
-       kvm_iodevice_init(&dev->dev, &coalesced_mmio_ops);
-       dev->kvm = kvm;
-       kvm->coalesced_mmio_dev = dev;
 
-       mutex_lock(&kvm->slots_lock);
-       ret = kvm_io_bus_register_dev(kvm, KVM_MMIO_BUS, &dev->dev);
-       mutex_unlock(&kvm->slots_lock);
-       if (ret < 0)
-               goto out_free_dev;
+       ret = 0;
+       kvm->coalesced_mmio_ring = page_address(page);
 
-       return ret;
+       /*
+        * We're using this spinlock to sync access to the coalesced ring.
+        * The list doesn't need it's own lock since device registration and
+        * unregistration should only happen when kvm->slots_lock is held.
+        */
+       spin_lock_init(&kvm->ring_lock);
+       INIT_LIST_HEAD(&kvm->coalesced_zones);
 
-out_free_dev:
-       kvm->coalesced_mmio_dev = NULL;
-       kfree(dev);
-out_free_page:
-       kvm->coalesced_mmio_ring = NULL;
-       __free_page(page);
 out_err:
        return ret;
 }
@@ -139,51 +129,50 @@ void kvm_coalesced_mmio_free(struct kvm *kvm)
 int kvm_vm_ioctl_register_coalesced_mmio(struct kvm *kvm,
                                         struct kvm_coalesced_mmio_zone *zone)
 {
-       struct kvm_coalesced_mmio_dev *dev = kvm->coalesced_mmio_dev;
+       int ret;
+       struct kvm_coalesced_mmio_dev *dev;
 
-       if (dev == NULL)
-               return -ENXIO;
+       dev = kzalloc(sizeof(struct kvm_coalesced_mmio_dev), GFP_KERNEL);
+       if (!dev)
+               return -ENOMEM;
+
+       kvm_iodevice_init(&dev->dev, &coalesced_mmio_ops);
+       dev->kvm = kvm;
+       dev->zone = *zone;
 
        mutex_lock(&kvm->slots_lock);
-       if (dev->nb_zones >= KVM_COALESCED_MMIO_ZONE_MAX) {
-               mutex_unlock(&kvm->slots_lock);
-               return -ENOBUFS;
-       }
+       ret = kvm_io_bus_register_dev(kvm, KVM_MMIO_BUS, zone->addr,
+                                     zone->size, &dev->dev);
+       if (ret < 0)
+               goto out_free_dev;
+       list_add_tail(&dev->list, &kvm->coalesced_zones);
+       mutex_unlock(&kvm->slots_lock);
 
-       dev->zone[dev->nb_zones] = *zone;
-       dev->nb_zones++;
+       return ret;
 
+out_free_dev:
        mutex_unlock(&kvm->slots_lock);
+
+       kfree(dev);
+
+       if (dev == NULL)
+               return -ENXIO;
+
        return 0;
 }
 
 int kvm_vm_ioctl_unregister_coalesced_mmio(struct kvm *kvm,
                                           struct kvm_coalesced_mmio_zone *zone)
 {
-       int i;
-       struct kvm_coalesced_mmio_dev *dev = kvm->coalesced_mmio_dev;
-       struct kvm_coalesced_mmio_zone *z;
-
-       if (dev == NULL)
-               return -ENXIO;
+       struct kvm_coalesced_mmio_dev *dev, *tmp;
 
        mutex_lock(&kvm->slots_lock);
 
-       i = dev->nb_zones;
-       while (i) {
-               z = &dev->zone[i - 1];
-
-               /* unregister all zones
-                * included in (zone->addr, zone->size)
-                */
-
-               if (zone->addr <= z->addr &&
-                   z->addr + z->size <= zone->addr + zone->size) {
-                       dev->nb_zones--;
-                       *z = dev->zone[dev->nb_zones];
+       list_for_each_entry_safe(dev, tmp, &kvm->coalesced_zones, list)
+               if (coalesced_mmio_in_range(dev, zone->addr, zone->size)) {
+                       kvm_io_bus_unregister_dev(kvm, KVM_MMIO_BUS, &dev->dev);
+                       kvm_iodevice_destructor(&dev->dev);
                }
-               i--;
-       }
 
        mutex_unlock(&kvm->slots_lock);
 
index 8a5959e3535f401482d866de6c8487e40138ea15..b280c20444d1546434e1381a52c723098d564f6c 100644 (file)
 
 #ifdef CONFIG_KVM_MMIO
 
-#define KVM_COALESCED_MMIO_ZONE_MAX 100
+#include <linux/list.h>
 
 struct kvm_coalesced_mmio_dev {
+       struct list_head list;
        struct kvm_io_device dev;
        struct kvm *kvm;
-       spinlock_t lock;
-       int nb_zones;
-       struct kvm_coalesced_mmio_zone zone[KVM_COALESCED_MMIO_ZONE_MAX];
+       struct kvm_coalesced_mmio_zone zone;
 };
 
 int kvm_coalesced_mmio_init(struct kvm *kvm);
index 73358d256fa2d0e1dca075f0947fc187faf5089d..f59c1e8de7a2e62b5977d90ab992e1c2240e80f5 100644 (file)
@@ -586,7 +586,8 @@ kvm_assign_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)
 
        kvm_iodevice_init(&p->dev, &ioeventfd_ops);
 
-       ret = kvm_io_bus_register_dev(kvm, bus_idx, &p->dev);
+       ret = kvm_io_bus_register_dev(kvm, bus_idx, p->addr, p->length,
+                                     &p->dev);
        if (ret < 0)
                goto unlock_fail;
 
index 8df1ca104a7f11ac0b78c820d9519cd2f2fe1a15..3eed61eb48675a63dd1f31b0095217ab6bc5f646 100644 (file)
@@ -394,7 +394,8 @@ int kvm_ioapic_init(struct kvm *kvm)
        kvm_iodevice_init(&ioapic->dev, &ioapic_mmio_ops);
        ioapic->kvm = kvm;
        mutex_lock(&kvm->slots_lock);
-       ret = kvm_io_bus_register_dev(kvm, KVM_MMIO_BUS, &ioapic->dev);
+       ret = kvm_io_bus_register_dev(kvm, KVM_MMIO_BUS, ioapic->base_address,
+                                     IOAPIC_MEM_LENGTH, &ioapic->dev);
        mutex_unlock(&kvm->slots_lock);
        if (ret < 0) {
                kvm->arch.vioapic = NULL;
index 967aba133a624c38dee5b61cbb9b1376b767f228..d5f3b8d1e09566037c5a48a7106d7c4c2a1c2a38 100644 (file)
@@ -232,12 +232,12 @@ int kvm_iommu_map_guest(struct kvm *kvm)
 {
        int r;
 
-       if (!iommu_found()) {
+       if (!iommu_present(&pci_bus_type)) {
                printk(KERN_ERR "%s: iommu not found\n", __func__);
                return -ENODEV;
        }
 
-       kvm->arch.iommu_domain = iommu_domain_alloc();
+       kvm->arch.iommu_domain = iommu_domain_alloc(&pci_bus_type);
        if (!kvm->arch.iommu_domain)
                return -ENOMEM;
 
index aefdda390f5e73f297897db863da1ee9e129a6a8..d9cfb782cb81a87fc5ef4f1734df1a308a55539b 100644 (file)
@@ -47,6 +47,8 @@
 #include <linux/srcu.h>
 #include <linux/hugetlb.h>
 #include <linux/slab.h>
+#include <linux/sort.h>
+#include <linux/bsearch.h>
 
 #include <asm/processor.h>
 #include <asm/io.h>
@@ -2391,24 +2393,92 @@ static void kvm_io_bus_destroy(struct kvm_io_bus *bus)
        int i;
 
        for (i = 0; i < bus->dev_count; i++) {
-               struct kvm_io_device *pos = bus->devs[i];
+               struct kvm_io_device *pos = bus->range[i].dev;
 
                kvm_iodevice_destructor(pos);
        }
        kfree(bus);
 }
 
+int kvm_io_bus_sort_cmp(const void *p1, const void *p2)
+{
+       const struct kvm_io_range *r1 = p1;
+       const struct kvm_io_range *r2 = p2;
+
+       if (r1->addr < r2->addr)
+               return -1;
+       if (r1->addr + r1->len > r2->addr + r2->len)
+               return 1;
+       return 0;
+}
+
+int kvm_io_bus_insert_dev(struct kvm_io_bus *bus, struct kvm_io_device *dev,
+                         gpa_t addr, int len)
+{
+       if (bus->dev_count == NR_IOBUS_DEVS)
+               return -ENOSPC;
+
+       bus->range[bus->dev_count++] = (struct kvm_io_range) {
+               .addr = addr,
+               .len = len,
+               .dev = dev,
+       };
+
+       sort(bus->range, bus->dev_count, sizeof(struct kvm_io_range),
+               kvm_io_bus_sort_cmp, NULL);
+
+       return 0;
+}
+
+int kvm_io_bus_get_first_dev(struct kvm_io_bus *bus,
+                            gpa_t addr, int len)
+{
+       struct kvm_io_range *range, key;
+       int off;
+
+       key = (struct kvm_io_range) {
+               .addr = addr,
+               .len = len,
+       };
+
+       range = bsearch(&key, bus->range, bus->dev_count,
+                       sizeof(struct kvm_io_range), kvm_io_bus_sort_cmp);
+       if (range == NULL)
+               return -ENOENT;
+
+       off = range - bus->range;
+
+       while (off > 0 && kvm_io_bus_sort_cmp(&key, &bus->range[off-1]) == 0)
+               off--;
+
+       return off;
+}
+
 /* kvm_io_bus_write - called under kvm->slots_lock */
 int kvm_io_bus_write(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
                     int len, const void *val)
 {
-       int i;
+       int idx;
        struct kvm_io_bus *bus;
+       struct kvm_io_range range;
+
+       range = (struct kvm_io_range) {
+               .addr = addr,
+               .len = len,
+       };
 
        bus = srcu_dereference(kvm->buses[bus_idx], &kvm->srcu);
-       for (i = 0; i < bus->dev_count; i++)
-               if (!kvm_iodevice_write(bus->devs[i], addr, len, val))
+       idx = kvm_io_bus_get_first_dev(bus, addr, len);
+       if (idx < 0)
+               return -EOPNOTSUPP;
+
+       while (idx < bus->dev_count &&
+               kvm_io_bus_sort_cmp(&range, &bus->range[idx]) == 0) {
+               if (!kvm_iodevice_write(bus->range[idx].dev, addr, len, val))
                        return 0;
+               idx++;
+       }
+
        return -EOPNOTSUPP;
 }
 
@@ -2416,19 +2486,33 @@ int kvm_io_bus_write(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
 int kvm_io_bus_read(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
                    int len, void *val)
 {
-       int i;
+       int idx;
        struct kvm_io_bus *bus;
+       struct kvm_io_range range;
+
+       range = (struct kvm_io_range) {
+               .addr = addr,
+               .len = len,
+       };
 
        bus = srcu_dereference(kvm->buses[bus_idx], &kvm->srcu);
-       for (i = 0; i < bus->dev_count; i++)
-               if (!kvm_iodevice_read(bus->devs[i], addr, len, val))
+       idx = kvm_io_bus_get_first_dev(bus, addr, len);
+       if (idx < 0)
+               return -EOPNOTSUPP;
+
+       while (idx < bus->dev_count &&
+               kvm_io_bus_sort_cmp(&range, &bus->range[idx]) == 0) {
+               if (!kvm_iodevice_read(bus->range[idx].dev, addr, len, val))
                        return 0;
+               idx++;
+       }
+
        return -EOPNOTSUPP;
 }
 
 /* Caller must hold slots_lock. */
-int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx,
-                           struct kvm_io_device *dev)
+int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
+                           int len, struct kvm_io_device *dev)
 {
        struct kvm_io_bus *new_bus, *bus;
 
@@ -2440,7 +2524,7 @@ int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx,
        if (!new_bus)
                return -ENOMEM;
        memcpy(new_bus, bus, sizeof(struct kvm_io_bus));
-       new_bus->devs[new_bus->dev_count++] = dev;
+       kvm_io_bus_insert_dev(new_bus, dev, addr, len);
        rcu_assign_pointer(kvm->buses[bus_idx], new_bus);
        synchronize_srcu_expedited(&kvm->srcu);
        kfree(bus);
@@ -2464,9 +2548,13 @@ int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx,
 
        r = -ENOENT;
        for (i = 0; i < new_bus->dev_count; i++)
-               if (new_bus->devs[i] == dev) {
+               if (new_bus->range[i].dev == dev) {
                        r = 0;
-                       new_bus->devs[i] = new_bus->devs[--new_bus->dev_count];
+                       new_bus->dev_count--;
+                       new_bus->range[i] = new_bus->range[new_bus->dev_count];
+                       sort(new_bus->range, new_bus->dev_count,
+                            sizeof(struct kvm_io_range),
+                            kvm_io_bus_sort_cmp, NULL);
                        break;
                }